chsc_sch.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. /*
  2. * Driver for s390 chsc subchannels
  3. *
  4. * Copyright IBM Corp. 2008, 2009
  5. *
  6. * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
  7. *
  8. */
  9. #include <linux/slab.h>
  10. #include <linux/device.h>
  11. #include <linux/module.h>
  12. #include <linux/uaccess.h>
  13. #include <linux/miscdevice.h>
  14. #include <asm/compat.h>
  15. #include <asm/cio.h>
  16. #include <asm/chsc.h>
  17. #include <asm/isc.h>
  18. #include "cio.h"
  19. #include "cio_debug.h"
  20. #include "css.h"
  21. #include "chsc_sch.h"
  22. #include "ioasm.h"
  23. static debug_info_t *chsc_debug_msg_id;
  24. static debug_info_t *chsc_debug_log_id;
  25. #define CHSC_MSG(imp, args...) do { \
  26. debug_sprintf_event(chsc_debug_msg_id, imp , ##args); \
  27. } while (0)
  28. #define CHSC_LOG(imp, txt) do { \
  29. debug_text_event(chsc_debug_log_id, imp , txt); \
  30. } while (0)
  31. static void CHSC_LOG_HEX(int level, void *data, int length)
  32. {
  33. while (length > 0) {
  34. debug_event(chsc_debug_log_id, level, data, length);
  35. length -= chsc_debug_log_id->buf_size;
  36. data += chsc_debug_log_id->buf_size;
  37. }
  38. }
  39. MODULE_AUTHOR("IBM Corporation");
  40. MODULE_DESCRIPTION("driver for s390 chsc subchannels");
  41. MODULE_LICENSE("GPL");
  42. static void chsc_subchannel_irq(struct subchannel *sch)
  43. {
  44. struct chsc_private *private = dev_get_drvdata(&sch->dev);
  45. struct chsc_request *request = private->request;
  46. struct irb *irb = (struct irb *)&S390_lowcore.irb;
  47. CHSC_LOG(4, "irb");
  48. CHSC_LOG_HEX(4, irb, sizeof(*irb));
  49. /* Copy irb to provided request and set done. */
  50. if (!request) {
  51. CHSC_MSG(0, "Interrupt on sch 0.%x.%04x with no request\n",
  52. sch->schid.ssid, sch->schid.sch_no);
  53. return;
  54. }
  55. private->request = NULL;
  56. memcpy(&request->irb, irb, sizeof(*irb));
  57. cio_update_schib(sch);
  58. complete(&request->completion);
  59. put_device(&sch->dev);
  60. }
  61. static int chsc_subchannel_probe(struct subchannel *sch)
  62. {
  63. struct chsc_private *private;
  64. int ret;
  65. CHSC_MSG(6, "Detected chsc subchannel 0.%x.%04x\n",
  66. sch->schid.ssid, sch->schid.sch_no);
  67. sch->isc = CHSC_SCH_ISC;
  68. private = kzalloc(sizeof(*private), GFP_KERNEL);
  69. if (!private)
  70. return -ENOMEM;
  71. dev_set_drvdata(&sch->dev, private);
  72. ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch);
  73. if (ret) {
  74. CHSC_MSG(0, "Failed to enable 0.%x.%04x: %d\n",
  75. sch->schid.ssid, sch->schid.sch_no, ret);
  76. dev_set_drvdata(&sch->dev, NULL);
  77. kfree(private);
  78. } else {
  79. if (dev_get_uevent_suppress(&sch->dev)) {
  80. dev_set_uevent_suppress(&sch->dev, 0);
  81. kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
  82. }
  83. }
  84. return ret;
  85. }
  86. static int chsc_subchannel_remove(struct subchannel *sch)
  87. {
  88. struct chsc_private *private;
  89. cio_disable_subchannel(sch);
  90. private = dev_get_drvdata(&sch->dev);
  91. dev_set_drvdata(&sch->dev, NULL);
  92. if (private->request) {
  93. complete(&private->request->completion);
  94. put_device(&sch->dev);
  95. }
  96. kfree(private);
  97. return 0;
  98. }
  99. static void chsc_subchannel_shutdown(struct subchannel *sch)
  100. {
  101. cio_disable_subchannel(sch);
  102. }
  103. static int chsc_subchannel_prepare(struct subchannel *sch)
  104. {
  105. int cc;
  106. struct schib schib;
  107. /*
  108. * Don't allow suspend while the subchannel is not idle
  109. * since we don't have a way to clear the subchannel and
  110. * cannot disable it with a request running.
  111. */
  112. cc = stsch_err(sch->schid, &schib);
  113. if (!cc && scsw_stctl(&schib.scsw))
  114. return -EAGAIN;
  115. return 0;
  116. }
  117. static int chsc_subchannel_freeze(struct subchannel *sch)
  118. {
  119. return cio_disable_subchannel(sch);
  120. }
  121. static int chsc_subchannel_restore(struct subchannel *sch)
  122. {
  123. return cio_enable_subchannel(sch, (u32)(unsigned long)sch);
  124. }
  125. static struct css_device_id chsc_subchannel_ids[] = {
  126. { .match_flags = 0x1, .type =SUBCHANNEL_TYPE_CHSC, },
  127. { /* end of list */ },
  128. };
  129. MODULE_DEVICE_TABLE(css, chsc_subchannel_ids);
  130. static struct css_driver chsc_subchannel_driver = {
  131. .owner = THIS_MODULE,
  132. .subchannel_type = chsc_subchannel_ids,
  133. .irq = chsc_subchannel_irq,
  134. .probe = chsc_subchannel_probe,
  135. .remove = chsc_subchannel_remove,
  136. .shutdown = chsc_subchannel_shutdown,
  137. .prepare = chsc_subchannel_prepare,
  138. .freeze = chsc_subchannel_freeze,
  139. .thaw = chsc_subchannel_restore,
  140. .restore = chsc_subchannel_restore,
  141. .name = "chsc_subchannel",
  142. };
  143. static int __init chsc_init_dbfs(void)
  144. {
  145. chsc_debug_msg_id = debug_register("chsc_msg", 16, 1,
  146. 16 * sizeof(long));
  147. if (!chsc_debug_msg_id)
  148. goto out;
  149. debug_register_view(chsc_debug_msg_id, &debug_sprintf_view);
  150. debug_set_level(chsc_debug_msg_id, 2);
  151. chsc_debug_log_id = debug_register("chsc_log", 16, 1, 16);
  152. if (!chsc_debug_log_id)
  153. goto out;
  154. debug_register_view(chsc_debug_log_id, &debug_hex_ascii_view);
  155. debug_set_level(chsc_debug_log_id, 2);
  156. return 0;
  157. out:
  158. if (chsc_debug_msg_id)
  159. debug_unregister(chsc_debug_msg_id);
  160. return -ENOMEM;
  161. }
  162. static void chsc_remove_dbfs(void)
  163. {
  164. debug_unregister(chsc_debug_log_id);
  165. debug_unregister(chsc_debug_msg_id);
  166. }
  167. static int __init chsc_init_sch_driver(void)
  168. {
  169. return css_driver_register(&chsc_subchannel_driver);
  170. }
  171. static void chsc_cleanup_sch_driver(void)
  172. {
  173. css_driver_unregister(&chsc_subchannel_driver);
  174. }
  175. static DEFINE_SPINLOCK(chsc_lock);
  176. static int chsc_subchannel_match_next_free(struct device *dev, void *data)
  177. {
  178. struct subchannel *sch = to_subchannel(dev);
  179. return sch->schib.pmcw.ena && !scsw_fctl(&sch->schib.scsw);
  180. }
  181. static struct subchannel *chsc_get_next_subchannel(struct subchannel *sch)
  182. {
  183. struct device *dev;
  184. dev = driver_find_device(&chsc_subchannel_driver.drv,
  185. sch ? &sch->dev : NULL, NULL,
  186. chsc_subchannel_match_next_free);
  187. return dev ? to_subchannel(dev) : NULL;
  188. }
  189. /**
  190. * chsc_async() - try to start a chsc request asynchronously
  191. * @chsc_area: request to be started
  192. * @request: request structure to associate
  193. *
  194. * Tries to start a chsc request on one of the existing chsc subchannels.
  195. * Returns:
  196. * %0 if the request was performed synchronously
  197. * %-EINPROGRESS if the request was successfully started
  198. * %-EBUSY if all chsc subchannels are busy
  199. * %-ENODEV if no chsc subchannels are available
  200. * Context:
  201. * interrupts disabled, chsc_lock held
  202. */
  203. static int chsc_async(struct chsc_async_area *chsc_area,
  204. struct chsc_request *request)
  205. {
  206. int cc;
  207. struct chsc_private *private;
  208. struct subchannel *sch = NULL;
  209. int ret = -ENODEV;
  210. char dbf[10];
  211. chsc_area->header.key = PAGE_DEFAULT_KEY >> 4;
  212. while ((sch = chsc_get_next_subchannel(sch))) {
  213. spin_lock(sch->lock);
  214. private = dev_get_drvdata(&sch->dev);
  215. if (private->request) {
  216. spin_unlock(sch->lock);
  217. ret = -EBUSY;
  218. continue;
  219. }
  220. chsc_area->header.sid = sch->schid;
  221. CHSC_LOG(2, "schid");
  222. CHSC_LOG_HEX(2, &sch->schid, sizeof(sch->schid));
  223. cc = chsc(chsc_area);
  224. sprintf(dbf, "cc:%d", cc);
  225. CHSC_LOG(2, dbf);
  226. switch (cc) {
  227. case 0:
  228. ret = 0;
  229. break;
  230. case 1:
  231. sch->schib.scsw.cmd.fctl |= SCSW_FCTL_START_FUNC;
  232. ret = -EINPROGRESS;
  233. private->request = request;
  234. break;
  235. case 2:
  236. ret = -EBUSY;
  237. break;
  238. default:
  239. ret = -ENODEV;
  240. }
  241. spin_unlock(sch->lock);
  242. CHSC_MSG(2, "chsc on 0.%x.%04x returned cc=%d\n",
  243. sch->schid.ssid, sch->schid.sch_no, cc);
  244. if (ret == -EINPROGRESS)
  245. return -EINPROGRESS;
  246. put_device(&sch->dev);
  247. if (ret == 0)
  248. return 0;
  249. }
  250. return ret;
  251. }
  252. static void chsc_log_command(struct chsc_async_area *chsc_area)
  253. {
  254. char dbf[10];
  255. sprintf(dbf, "CHSC:%x", chsc_area->header.code);
  256. CHSC_LOG(0, dbf);
  257. CHSC_LOG_HEX(0, chsc_area, 32);
  258. }
  259. static int chsc_examine_irb(struct chsc_request *request)
  260. {
  261. int backed_up;
  262. if (!(scsw_stctl(&request->irb.scsw) & SCSW_STCTL_STATUS_PEND))
  263. return -EIO;
  264. backed_up = scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHAIN_CHECK;
  265. request->irb.scsw.cmd.cstat &= ~SCHN_STAT_CHAIN_CHECK;
  266. if (scsw_cstat(&request->irb.scsw) == 0)
  267. return 0;
  268. if (!backed_up)
  269. return 0;
  270. if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROG_CHECK)
  271. return -EIO;
  272. if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROT_CHECK)
  273. return -EPERM;
  274. if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_DATA_CHK)
  275. return -EAGAIN;
  276. if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_CTRL_CHK)
  277. return -EAGAIN;
  278. return -EIO;
  279. }
  280. static int chsc_ioctl_start(void __user *user_area)
  281. {
  282. struct chsc_request *request;
  283. struct chsc_async_area *chsc_area;
  284. int ret;
  285. char dbf[10];
  286. if (!css_general_characteristics.dynio)
  287. /* It makes no sense to try. */
  288. return -EOPNOTSUPP;
  289. chsc_area = (void *)get_zeroed_page(GFP_DMA | GFP_KERNEL);
  290. if (!chsc_area)
  291. return -ENOMEM;
  292. request = kzalloc(sizeof(*request), GFP_KERNEL);
  293. if (!request) {
  294. ret = -ENOMEM;
  295. goto out_free;
  296. }
  297. init_completion(&request->completion);
  298. if (copy_from_user(chsc_area, user_area, PAGE_SIZE)) {
  299. ret = -EFAULT;
  300. goto out_free;
  301. }
  302. chsc_log_command(chsc_area);
  303. spin_lock_irq(&chsc_lock);
  304. ret = chsc_async(chsc_area, request);
  305. spin_unlock_irq(&chsc_lock);
  306. if (ret == -EINPROGRESS) {
  307. wait_for_completion(&request->completion);
  308. ret = chsc_examine_irb(request);
  309. }
  310. /* copy area back to user */
  311. if (!ret)
  312. if (copy_to_user(user_area, chsc_area, PAGE_SIZE))
  313. ret = -EFAULT;
  314. out_free:
  315. sprintf(dbf, "ret:%d", ret);
  316. CHSC_LOG(0, dbf);
  317. kfree(request);
  318. free_page((unsigned long)chsc_area);
  319. return ret;
  320. }
  321. static int chsc_ioctl_info_channel_path(void __user *user_cd)
  322. {
  323. struct chsc_chp_cd *cd;
  324. int ret, ccode;
  325. struct {
  326. struct chsc_header request;
  327. u32 : 2;
  328. u32 m : 1;
  329. u32 : 1;
  330. u32 fmt1 : 4;
  331. u32 cssid : 8;
  332. u32 : 8;
  333. u32 first_chpid : 8;
  334. u32 : 24;
  335. u32 last_chpid : 8;
  336. u32 : 32;
  337. struct chsc_header response;
  338. u8 data[PAGE_SIZE - 20];
  339. } __attribute__ ((packed)) *scpcd_area;
  340. scpcd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  341. if (!scpcd_area)
  342. return -ENOMEM;
  343. cd = kzalloc(sizeof(*cd), GFP_KERNEL);
  344. if (!cd) {
  345. ret = -ENOMEM;
  346. goto out_free;
  347. }
  348. if (copy_from_user(cd, user_cd, sizeof(*cd))) {
  349. ret = -EFAULT;
  350. goto out_free;
  351. }
  352. scpcd_area->request.length = 0x0010;
  353. scpcd_area->request.code = 0x0028;
  354. scpcd_area->m = cd->m;
  355. scpcd_area->fmt1 = cd->fmt;
  356. scpcd_area->cssid = cd->chpid.cssid;
  357. scpcd_area->first_chpid = cd->chpid.id;
  358. scpcd_area->last_chpid = cd->chpid.id;
  359. ccode = chsc(scpcd_area);
  360. if (ccode != 0) {
  361. ret = -EIO;
  362. goto out_free;
  363. }
  364. if (scpcd_area->response.code != 0x0001) {
  365. ret = -EIO;
  366. CHSC_MSG(0, "scpcd: response code=%x\n",
  367. scpcd_area->response.code);
  368. goto out_free;
  369. }
  370. memcpy(&cd->cpcb, &scpcd_area->response, scpcd_area->response.length);
  371. if (copy_to_user(user_cd, cd, sizeof(*cd)))
  372. ret = -EFAULT;
  373. else
  374. ret = 0;
  375. out_free:
  376. kfree(cd);
  377. free_page((unsigned long)scpcd_area);
  378. return ret;
  379. }
  380. static int chsc_ioctl_info_cu(void __user *user_cd)
  381. {
  382. struct chsc_cu_cd *cd;
  383. int ret, ccode;
  384. struct {
  385. struct chsc_header request;
  386. u32 : 2;
  387. u32 m : 1;
  388. u32 : 1;
  389. u32 fmt1 : 4;
  390. u32 cssid : 8;
  391. u32 : 8;
  392. u32 first_cun : 8;
  393. u32 : 24;
  394. u32 last_cun : 8;
  395. u32 : 32;
  396. struct chsc_header response;
  397. u8 data[PAGE_SIZE - 20];
  398. } __attribute__ ((packed)) *scucd_area;
  399. scucd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  400. if (!scucd_area)
  401. return -ENOMEM;
  402. cd = kzalloc(sizeof(*cd), GFP_KERNEL);
  403. if (!cd) {
  404. ret = -ENOMEM;
  405. goto out_free;
  406. }
  407. if (copy_from_user(cd, user_cd, sizeof(*cd))) {
  408. ret = -EFAULT;
  409. goto out_free;
  410. }
  411. scucd_area->request.length = 0x0010;
  412. scucd_area->request.code = 0x0028;
  413. scucd_area->m = cd->m;
  414. scucd_area->fmt1 = cd->fmt;
  415. scucd_area->cssid = cd->cssid;
  416. scucd_area->first_cun = cd->cun;
  417. scucd_area->last_cun = cd->cun;
  418. ccode = chsc(scucd_area);
  419. if (ccode != 0) {
  420. ret = -EIO;
  421. goto out_free;
  422. }
  423. if (scucd_area->response.code != 0x0001) {
  424. ret = -EIO;
  425. CHSC_MSG(0, "scucd: response code=%x\n",
  426. scucd_area->response.code);
  427. goto out_free;
  428. }
  429. memcpy(&cd->cucb, &scucd_area->response, scucd_area->response.length);
  430. if (copy_to_user(user_cd, cd, sizeof(*cd)))
  431. ret = -EFAULT;
  432. else
  433. ret = 0;
  434. out_free:
  435. kfree(cd);
  436. free_page((unsigned long)scucd_area);
  437. return ret;
  438. }
  439. static int chsc_ioctl_info_sch_cu(void __user *user_cud)
  440. {
  441. struct chsc_sch_cud *cud;
  442. int ret, ccode;
  443. struct {
  444. struct chsc_header request;
  445. u32 : 2;
  446. u32 m : 1;
  447. u32 : 5;
  448. u32 fmt1 : 4;
  449. u32 : 2;
  450. u32 ssid : 2;
  451. u32 first_sch : 16;
  452. u32 : 8;
  453. u32 cssid : 8;
  454. u32 last_sch : 16;
  455. u32 : 32;
  456. struct chsc_header response;
  457. u8 data[PAGE_SIZE - 20];
  458. } __attribute__ ((packed)) *sscud_area;
  459. sscud_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  460. if (!sscud_area)
  461. return -ENOMEM;
  462. cud = kzalloc(sizeof(*cud), GFP_KERNEL);
  463. if (!cud) {
  464. ret = -ENOMEM;
  465. goto out_free;
  466. }
  467. if (copy_from_user(cud, user_cud, sizeof(*cud))) {
  468. ret = -EFAULT;
  469. goto out_free;
  470. }
  471. sscud_area->request.length = 0x0010;
  472. sscud_area->request.code = 0x0006;
  473. sscud_area->m = cud->schid.m;
  474. sscud_area->fmt1 = cud->fmt;
  475. sscud_area->ssid = cud->schid.ssid;
  476. sscud_area->first_sch = cud->schid.sch_no;
  477. sscud_area->cssid = cud->schid.cssid;
  478. sscud_area->last_sch = cud->schid.sch_no;
  479. ccode = chsc(sscud_area);
  480. if (ccode != 0) {
  481. ret = -EIO;
  482. goto out_free;
  483. }
  484. if (sscud_area->response.code != 0x0001) {
  485. ret = -EIO;
  486. CHSC_MSG(0, "sscud: response code=%x\n",
  487. sscud_area->response.code);
  488. goto out_free;
  489. }
  490. memcpy(&cud->scub, &sscud_area->response, sscud_area->response.length);
  491. if (copy_to_user(user_cud, cud, sizeof(*cud)))
  492. ret = -EFAULT;
  493. else
  494. ret = 0;
  495. out_free:
  496. kfree(cud);
  497. free_page((unsigned long)sscud_area);
  498. return ret;
  499. }
  500. static int chsc_ioctl_conf_info(void __user *user_ci)
  501. {
  502. struct chsc_conf_info *ci;
  503. int ret, ccode;
  504. struct {
  505. struct chsc_header request;
  506. u32 : 2;
  507. u32 m : 1;
  508. u32 : 1;
  509. u32 fmt1 : 4;
  510. u32 cssid : 8;
  511. u32 : 6;
  512. u32 ssid : 2;
  513. u32 : 8;
  514. u64 : 64;
  515. struct chsc_header response;
  516. u8 data[PAGE_SIZE - 20];
  517. } __attribute__ ((packed)) *sci_area;
  518. sci_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  519. if (!sci_area)
  520. return -ENOMEM;
  521. ci = kzalloc(sizeof(*ci), GFP_KERNEL);
  522. if (!ci) {
  523. ret = -ENOMEM;
  524. goto out_free;
  525. }
  526. if (copy_from_user(ci, user_ci, sizeof(*ci))) {
  527. ret = -EFAULT;
  528. goto out_free;
  529. }
  530. sci_area->request.length = 0x0010;
  531. sci_area->request.code = 0x0012;
  532. sci_area->m = ci->id.m;
  533. sci_area->fmt1 = ci->fmt;
  534. sci_area->cssid = ci->id.cssid;
  535. sci_area->ssid = ci->id.ssid;
  536. ccode = chsc(sci_area);
  537. if (ccode != 0) {
  538. ret = -EIO;
  539. goto out_free;
  540. }
  541. if (sci_area->response.code != 0x0001) {
  542. ret = -EIO;
  543. CHSC_MSG(0, "sci: response code=%x\n",
  544. sci_area->response.code);
  545. goto out_free;
  546. }
  547. memcpy(&ci->scid, &sci_area->response, sci_area->response.length);
  548. if (copy_to_user(user_ci, ci, sizeof(*ci)))
  549. ret = -EFAULT;
  550. else
  551. ret = 0;
  552. out_free:
  553. kfree(ci);
  554. free_page((unsigned long)sci_area);
  555. return ret;
  556. }
  557. static int chsc_ioctl_conf_comp_list(void __user *user_ccl)
  558. {
  559. struct chsc_comp_list *ccl;
  560. int ret, ccode;
  561. struct {
  562. struct chsc_header request;
  563. u32 ctype : 8;
  564. u32 : 4;
  565. u32 fmt : 4;
  566. u32 : 16;
  567. u64 : 64;
  568. u32 list_parm[2];
  569. u64 : 64;
  570. struct chsc_header response;
  571. u8 data[PAGE_SIZE - 36];
  572. } __attribute__ ((packed)) *sccl_area;
  573. struct {
  574. u32 m : 1;
  575. u32 : 31;
  576. u32 cssid : 8;
  577. u32 : 16;
  578. u32 chpid : 8;
  579. } __attribute__ ((packed)) *chpid_parm;
  580. struct {
  581. u32 f_cssid : 8;
  582. u32 l_cssid : 8;
  583. u32 : 16;
  584. u32 res;
  585. } __attribute__ ((packed)) *cssids_parm;
  586. sccl_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  587. if (!sccl_area)
  588. return -ENOMEM;
  589. ccl = kzalloc(sizeof(*ccl), GFP_KERNEL);
  590. if (!ccl) {
  591. ret = -ENOMEM;
  592. goto out_free;
  593. }
  594. if (copy_from_user(ccl, user_ccl, sizeof(*ccl))) {
  595. ret = -EFAULT;
  596. goto out_free;
  597. }
  598. sccl_area->request.length = 0x0020;
  599. sccl_area->request.code = 0x0030;
  600. sccl_area->fmt = ccl->req.fmt;
  601. sccl_area->ctype = ccl->req.ctype;
  602. switch (sccl_area->ctype) {
  603. case CCL_CU_ON_CHP:
  604. case CCL_IOP_CHP:
  605. chpid_parm = (void *)&sccl_area->list_parm;
  606. chpid_parm->m = ccl->req.chpid.m;
  607. chpid_parm->cssid = ccl->req.chpid.chp.cssid;
  608. chpid_parm->chpid = ccl->req.chpid.chp.id;
  609. break;
  610. case CCL_CSS_IMG:
  611. case CCL_CSS_IMG_CONF_CHAR:
  612. cssids_parm = (void *)&sccl_area->list_parm;
  613. cssids_parm->f_cssid = ccl->req.cssids.f_cssid;
  614. cssids_parm->l_cssid = ccl->req.cssids.l_cssid;
  615. break;
  616. }
  617. ccode = chsc(sccl_area);
  618. if (ccode != 0) {
  619. ret = -EIO;
  620. goto out_free;
  621. }
  622. if (sccl_area->response.code != 0x0001) {
  623. ret = -EIO;
  624. CHSC_MSG(0, "sccl: response code=%x\n",
  625. sccl_area->response.code);
  626. goto out_free;
  627. }
  628. memcpy(&ccl->sccl, &sccl_area->response, sccl_area->response.length);
  629. if (copy_to_user(user_ccl, ccl, sizeof(*ccl)))
  630. ret = -EFAULT;
  631. else
  632. ret = 0;
  633. out_free:
  634. kfree(ccl);
  635. free_page((unsigned long)sccl_area);
  636. return ret;
  637. }
  638. static int chsc_ioctl_chpd(void __user *user_chpd)
  639. {
  640. struct chsc_scpd *scpd_area;
  641. struct chsc_cpd_info *chpd;
  642. int ret;
  643. chpd = kzalloc(sizeof(*chpd), GFP_KERNEL);
  644. scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  645. if (!scpd_area || !chpd) {
  646. ret = -ENOMEM;
  647. goto out_free;
  648. }
  649. if (copy_from_user(chpd, user_chpd, sizeof(*chpd))) {
  650. ret = -EFAULT;
  651. goto out_free;
  652. }
  653. ret = chsc_determine_channel_path_desc(chpd->chpid, chpd->fmt,
  654. chpd->rfmt, chpd->c, chpd->m,
  655. scpd_area);
  656. if (ret)
  657. goto out_free;
  658. memcpy(&chpd->chpdb, &scpd_area->response, scpd_area->response.length);
  659. if (copy_to_user(user_chpd, chpd, sizeof(*chpd)))
  660. ret = -EFAULT;
  661. out_free:
  662. kfree(chpd);
  663. free_page((unsigned long)scpd_area);
  664. return ret;
  665. }
  666. static int chsc_ioctl_dcal(void __user *user_dcal)
  667. {
  668. struct chsc_dcal *dcal;
  669. int ret, ccode;
  670. struct {
  671. struct chsc_header request;
  672. u32 atype : 8;
  673. u32 : 4;
  674. u32 fmt : 4;
  675. u32 : 16;
  676. u32 res0[2];
  677. u32 list_parm[2];
  678. u32 res1[2];
  679. struct chsc_header response;
  680. u8 data[PAGE_SIZE - 36];
  681. } __attribute__ ((packed)) *sdcal_area;
  682. sdcal_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
  683. if (!sdcal_area)
  684. return -ENOMEM;
  685. dcal = kzalloc(sizeof(*dcal), GFP_KERNEL);
  686. if (!dcal) {
  687. ret = -ENOMEM;
  688. goto out_free;
  689. }
  690. if (copy_from_user(dcal, user_dcal, sizeof(*dcal))) {
  691. ret = -EFAULT;
  692. goto out_free;
  693. }
  694. sdcal_area->request.length = 0x0020;
  695. sdcal_area->request.code = 0x0034;
  696. sdcal_area->atype = dcal->req.atype;
  697. sdcal_area->fmt = dcal->req.fmt;
  698. memcpy(&sdcal_area->list_parm, &dcal->req.list_parm,
  699. sizeof(sdcal_area->list_parm));
  700. ccode = chsc(sdcal_area);
  701. if (ccode != 0) {
  702. ret = -EIO;
  703. goto out_free;
  704. }
  705. if (sdcal_area->response.code != 0x0001) {
  706. ret = -EIO;
  707. CHSC_MSG(0, "sdcal: response code=%x\n",
  708. sdcal_area->response.code);
  709. goto out_free;
  710. }
  711. memcpy(&dcal->sdcal, &sdcal_area->response,
  712. sdcal_area->response.length);
  713. if (copy_to_user(user_dcal, dcal, sizeof(*dcal)))
  714. ret = -EFAULT;
  715. else
  716. ret = 0;
  717. out_free:
  718. kfree(dcal);
  719. free_page((unsigned long)sdcal_area);
  720. return ret;
  721. }
  722. static long chsc_ioctl(struct file *filp, unsigned int cmd,
  723. unsigned long arg)
  724. {
  725. void __user *argp;
  726. CHSC_MSG(2, "chsc_ioctl called, cmd=%x\n", cmd);
  727. if (is_compat_task())
  728. argp = compat_ptr(arg);
  729. else
  730. argp = (void __user *)arg;
  731. switch (cmd) {
  732. case CHSC_START:
  733. return chsc_ioctl_start(argp);
  734. case CHSC_INFO_CHANNEL_PATH:
  735. return chsc_ioctl_info_channel_path(argp);
  736. case CHSC_INFO_CU:
  737. return chsc_ioctl_info_cu(argp);
  738. case CHSC_INFO_SCH_CU:
  739. return chsc_ioctl_info_sch_cu(argp);
  740. case CHSC_INFO_CI:
  741. return chsc_ioctl_conf_info(argp);
  742. case CHSC_INFO_CCL:
  743. return chsc_ioctl_conf_comp_list(argp);
  744. case CHSC_INFO_CPD:
  745. return chsc_ioctl_chpd(argp);
  746. case CHSC_INFO_DCAL:
  747. return chsc_ioctl_dcal(argp);
  748. default: /* unknown ioctl number */
  749. return -ENOIOCTLCMD;
  750. }
  751. }
  752. static const struct file_operations chsc_fops = {
  753. .owner = THIS_MODULE,
  754. .open = nonseekable_open,
  755. .unlocked_ioctl = chsc_ioctl,
  756. .compat_ioctl = chsc_ioctl,
  757. .llseek = no_llseek,
  758. };
  759. static struct miscdevice chsc_misc_device = {
  760. .minor = MISC_DYNAMIC_MINOR,
  761. .name = "chsc",
  762. .fops = &chsc_fops,
  763. };
  764. static int __init chsc_misc_init(void)
  765. {
  766. return misc_register(&chsc_misc_device);
  767. }
  768. static void chsc_misc_cleanup(void)
  769. {
  770. misc_deregister(&chsc_misc_device);
  771. }
  772. static int __init chsc_sch_init(void)
  773. {
  774. int ret;
  775. ret = chsc_init_dbfs();
  776. if (ret)
  777. return ret;
  778. isc_register(CHSC_SCH_ISC);
  779. ret = chsc_init_sch_driver();
  780. if (ret)
  781. goto out_dbf;
  782. ret = chsc_misc_init();
  783. if (ret)
  784. goto out_driver;
  785. return ret;
  786. out_driver:
  787. chsc_cleanup_sch_driver();
  788. out_dbf:
  789. isc_unregister(CHSC_SCH_ISC);
  790. chsc_remove_dbfs();
  791. return ret;
  792. }
  793. static void __exit chsc_sch_exit(void)
  794. {
  795. chsc_misc_cleanup();
  796. chsc_cleanup_sch_driver();
  797. isc_unregister(CHSC_SCH_ISC);
  798. chsc_remove_dbfs();
  799. }
  800. module_init(chsc_sch_init);
  801. module_exit(chsc_sch_exit);