chsc_sch.c 19 KB

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