chsc_sch.c 20 KB

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