chsc_sch.c 19 KB

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