css.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. /*
  2. * drivers/s390/cio/css.c
  3. * driver for channel subsystem
  4. *
  5. * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
  6. * IBM Corporation
  7. * Author(s): Arnd Bergmann (arndb@de.ibm.com)
  8. * Cornelia Huck (cornelia.huck@de.ibm.com)
  9. */
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/device.h>
  13. #include <linux/slab.h>
  14. #include <linux/errno.h>
  15. #include <linux/list.h>
  16. #include "css.h"
  17. #include "cio.h"
  18. #include "cio_debug.h"
  19. #include "ioasm.h"
  20. #include "chsc.h"
  21. #include "device.h"
  22. #include "idset.h"
  23. #include "chp.h"
  24. int css_init_done = 0;
  25. static int need_reprobe = 0;
  26. static int max_ssid = 0;
  27. struct channel_subsystem *css[__MAX_CSSID + 1];
  28. int css_characteristics_avail = 0;
  29. int
  30. for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
  31. {
  32. struct subchannel_id schid;
  33. int ret;
  34. init_subchannel_id(&schid);
  35. ret = -ENODEV;
  36. do {
  37. do {
  38. ret = fn(schid, data);
  39. if (ret)
  40. break;
  41. } while (schid.sch_no++ < __MAX_SUBCHANNEL);
  42. schid.sch_no = 0;
  43. } while (schid.ssid++ < max_ssid);
  44. return ret;
  45. }
  46. static struct subchannel *
  47. css_alloc_subchannel(struct subchannel_id schid)
  48. {
  49. struct subchannel *sch;
  50. int ret;
  51. sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA);
  52. if (sch == NULL)
  53. return ERR_PTR(-ENOMEM);
  54. ret = cio_validate_subchannel (sch, schid);
  55. if (ret < 0) {
  56. kfree(sch);
  57. return ERR_PTR(ret);
  58. }
  59. if (sch->st != SUBCHANNEL_TYPE_IO) {
  60. /* For now we ignore all non-io subchannels. */
  61. kfree(sch);
  62. return ERR_PTR(-EINVAL);
  63. }
  64. /*
  65. * Set intparm to subchannel address.
  66. * This is fine even on 64bit since the subchannel is always located
  67. * under 2G.
  68. */
  69. sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
  70. ret = cio_modify(sch);
  71. if (ret) {
  72. kfree(sch);
  73. return ERR_PTR(ret);
  74. }
  75. return sch;
  76. }
  77. static void
  78. css_free_subchannel(struct subchannel *sch)
  79. {
  80. if (sch) {
  81. /* Reset intparm to zeroes. */
  82. sch->schib.pmcw.intparm = 0;
  83. cio_modify(sch);
  84. kfree(sch->lock);
  85. kfree(sch);
  86. }
  87. }
  88. static void
  89. css_subchannel_release(struct device *dev)
  90. {
  91. struct subchannel *sch;
  92. sch = to_subchannel(dev);
  93. if (!cio_is_console(sch->schid)) {
  94. kfree(sch->lock);
  95. kfree(sch);
  96. }
  97. }
  98. int css_sch_device_register(struct subchannel *sch)
  99. {
  100. int ret;
  101. mutex_lock(&sch->reg_mutex);
  102. ret = device_register(&sch->dev);
  103. mutex_unlock(&sch->reg_mutex);
  104. return ret;
  105. }
  106. void css_sch_device_unregister(struct subchannel *sch)
  107. {
  108. mutex_lock(&sch->reg_mutex);
  109. device_unregister(&sch->dev);
  110. mutex_unlock(&sch->reg_mutex);
  111. }
  112. static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
  113. {
  114. int i;
  115. int mask;
  116. memset(ssd, 0, sizeof(struct chsc_ssd_info));
  117. ssd->path_mask = pmcw->pim;
  118. for (i = 0; i < 8; i++) {
  119. mask = 0x80 >> i;
  120. if (pmcw->pim & mask) {
  121. chp_id_init(&ssd->chpid[i]);
  122. ssd->chpid[i].id = pmcw->chpid[i];
  123. }
  124. }
  125. }
  126. static void ssd_register_chpids(struct chsc_ssd_info *ssd)
  127. {
  128. int i;
  129. int mask;
  130. for (i = 0; i < 8; i++) {
  131. mask = 0x80 >> i;
  132. if (ssd->path_mask & mask)
  133. if (!chp_is_registered(ssd->chpid[i]))
  134. chp_new(ssd->chpid[i]);
  135. }
  136. }
  137. void css_update_ssd_info(struct subchannel *sch)
  138. {
  139. int ret;
  140. if (cio_is_console(sch->schid)) {
  141. /* Console is initialized too early for functions requiring
  142. * memory allocation. */
  143. ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
  144. } else {
  145. ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
  146. if (ret)
  147. ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
  148. ssd_register_chpids(&sch->ssd_info);
  149. }
  150. }
  151. static int css_register_subchannel(struct subchannel *sch)
  152. {
  153. int ret;
  154. /* Initialize the subchannel structure */
  155. sch->dev.parent = &css[0]->device;
  156. sch->dev.bus = &css_bus_type;
  157. sch->dev.release = &css_subchannel_release;
  158. sch->dev.groups = subch_attr_groups;
  159. css_update_ssd_info(sch);
  160. /* make it known to the system */
  161. ret = css_sch_device_register(sch);
  162. if (ret) {
  163. printk (KERN_WARNING "%s: could not register %s\n",
  164. __func__, sch->dev.bus_id);
  165. return ret;
  166. }
  167. return ret;
  168. }
  169. static int css_probe_device(struct subchannel_id schid)
  170. {
  171. int ret;
  172. struct subchannel *sch;
  173. sch = css_alloc_subchannel(schid);
  174. if (IS_ERR(sch))
  175. return PTR_ERR(sch);
  176. ret = css_register_subchannel(sch);
  177. if (ret)
  178. css_free_subchannel(sch);
  179. return ret;
  180. }
  181. static int
  182. check_subchannel(struct device * dev, void * data)
  183. {
  184. struct subchannel *sch;
  185. struct subchannel_id *schid = data;
  186. sch = to_subchannel(dev);
  187. return schid_equal(&sch->schid, schid);
  188. }
  189. struct subchannel *
  190. get_subchannel_by_schid(struct subchannel_id schid)
  191. {
  192. struct device *dev;
  193. dev = bus_find_device(&css_bus_type, NULL,
  194. &schid, check_subchannel);
  195. return dev ? to_subchannel(dev) : NULL;
  196. }
  197. static int css_get_subchannel_status(struct subchannel *sch)
  198. {
  199. struct schib schib;
  200. if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
  201. return CIO_GONE;
  202. if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
  203. return CIO_REVALIDATE;
  204. if (!sch->lpm)
  205. return CIO_NO_PATH;
  206. return CIO_OPER;
  207. }
  208. static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
  209. {
  210. int event, ret, disc;
  211. unsigned long flags;
  212. enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
  213. spin_lock_irqsave(sch->lock, flags);
  214. disc = device_is_disconnected(sch);
  215. if (disc && slow) {
  216. /* Disconnected devices are evaluated directly only.*/
  217. spin_unlock_irqrestore(sch->lock, flags);
  218. return 0;
  219. }
  220. /* No interrupt after machine check - kill pending timers. */
  221. device_kill_pending_timer(sch);
  222. if (!disc && !slow) {
  223. /* Non-disconnected devices are evaluated on the slow path. */
  224. spin_unlock_irqrestore(sch->lock, flags);
  225. return -EAGAIN;
  226. }
  227. event = css_get_subchannel_status(sch);
  228. CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
  229. sch->schid.ssid, sch->schid.sch_no, event,
  230. disc ? "disconnected" : "normal",
  231. slow ? "slow" : "fast");
  232. /* Analyze subchannel status. */
  233. action = NONE;
  234. switch (event) {
  235. case CIO_NO_PATH:
  236. if (disc) {
  237. /* Check if paths have become available. */
  238. action = REPROBE;
  239. break;
  240. }
  241. /* fall through */
  242. case CIO_GONE:
  243. /* Prevent unwanted effects when opening lock. */
  244. cio_disable_subchannel(sch);
  245. device_set_disconnected(sch);
  246. /* Ask driver what to do with device. */
  247. action = UNREGISTER;
  248. if (sch->driver && sch->driver->notify) {
  249. spin_unlock_irqrestore(sch->lock, flags);
  250. ret = sch->driver->notify(&sch->dev, event);
  251. spin_lock_irqsave(sch->lock, flags);
  252. if (ret)
  253. action = NONE;
  254. }
  255. break;
  256. case CIO_REVALIDATE:
  257. /* Device will be removed, so no notify necessary. */
  258. if (disc)
  259. /* Reprobe because immediate unregister might block. */
  260. action = REPROBE;
  261. else
  262. action = UNREGISTER_PROBE;
  263. break;
  264. case CIO_OPER:
  265. if (disc)
  266. /* Get device operational again. */
  267. action = REPROBE;
  268. break;
  269. }
  270. /* Perform action. */
  271. ret = 0;
  272. switch (action) {
  273. case UNREGISTER:
  274. case UNREGISTER_PROBE:
  275. /* Unregister device (will use subchannel lock). */
  276. spin_unlock_irqrestore(sch->lock, flags);
  277. css_sch_device_unregister(sch);
  278. spin_lock_irqsave(sch->lock, flags);
  279. /* Reset intparm to zeroes. */
  280. sch->schib.pmcw.intparm = 0;
  281. cio_modify(sch);
  282. break;
  283. case REPROBE:
  284. device_trigger_reprobe(sch);
  285. break;
  286. default:
  287. break;
  288. }
  289. spin_unlock_irqrestore(sch->lock, flags);
  290. /* Probe if necessary. */
  291. if (action == UNREGISTER_PROBE)
  292. ret = css_probe_device(sch->schid);
  293. return ret;
  294. }
  295. static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
  296. {
  297. struct schib schib;
  298. if (!slow) {
  299. /* Will be done on the slow path. */
  300. return -EAGAIN;
  301. }
  302. if (stsch_err(schid, &schib) || !schib.pmcw.dnv) {
  303. /* Unusable - ignore. */
  304. return 0;
  305. }
  306. CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, "
  307. "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER);
  308. return css_probe_device(schid);
  309. }
  310. static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
  311. {
  312. struct subchannel *sch;
  313. int ret;
  314. sch = get_subchannel_by_schid(schid);
  315. if (sch) {
  316. ret = css_evaluate_known_subchannel(sch, slow);
  317. put_device(&sch->dev);
  318. } else
  319. ret = css_evaluate_new_subchannel(schid, slow);
  320. if (ret == -EAGAIN)
  321. css_schedule_eval(schid);
  322. }
  323. static struct idset *slow_subchannel_set;
  324. static spinlock_t slow_subchannel_lock;
  325. static int __init slow_subchannel_init(void)
  326. {
  327. spin_lock_init(&slow_subchannel_lock);
  328. slow_subchannel_set = idset_sch_new();
  329. if (!slow_subchannel_set) {
  330. printk(KERN_WARNING "cio: could not allocate slow subchannel "
  331. "set\n");
  332. return -ENOMEM;
  333. }
  334. return 0;
  335. }
  336. subsys_initcall(slow_subchannel_init);
  337. static void css_slow_path_func(struct work_struct *unused)
  338. {
  339. struct subchannel_id schid;
  340. CIO_TRACE_EVENT(4, "slowpath");
  341. spin_lock_irq(&slow_subchannel_lock);
  342. init_subchannel_id(&schid);
  343. while (idset_sch_get_first(slow_subchannel_set, &schid)) {
  344. idset_sch_del(slow_subchannel_set, schid);
  345. spin_unlock_irq(&slow_subchannel_lock);
  346. css_evaluate_subchannel(schid, 1);
  347. spin_lock_irq(&slow_subchannel_lock);
  348. }
  349. spin_unlock_irq(&slow_subchannel_lock);
  350. }
  351. static DECLARE_WORK(slow_path_work, css_slow_path_func);
  352. struct workqueue_struct *slow_path_wq;
  353. void css_schedule_eval(struct subchannel_id schid)
  354. {
  355. unsigned long flags;
  356. spin_lock_irqsave(&slow_subchannel_lock, flags);
  357. idset_sch_add(slow_subchannel_set, schid);
  358. queue_work(slow_path_wq, &slow_path_work);
  359. spin_unlock_irqrestore(&slow_subchannel_lock, flags);
  360. }
  361. void css_schedule_eval_all(void)
  362. {
  363. unsigned long flags;
  364. spin_lock_irqsave(&slow_subchannel_lock, flags);
  365. idset_fill(slow_subchannel_set);
  366. queue_work(slow_path_wq, &slow_path_work);
  367. spin_unlock_irqrestore(&slow_subchannel_lock, flags);
  368. }
  369. /* Reprobe subchannel if unregistered. */
  370. static int reprobe_subchannel(struct subchannel_id schid, void *data)
  371. {
  372. struct subchannel *sch;
  373. int ret;
  374. CIO_DEBUG(KERN_INFO, 6, "cio: reprobe 0.%x.%04x\n",
  375. schid.ssid, schid.sch_no);
  376. if (need_reprobe)
  377. return -EAGAIN;
  378. sch = get_subchannel_by_schid(schid);
  379. if (sch) {
  380. /* Already known. */
  381. put_device(&sch->dev);
  382. return 0;
  383. }
  384. ret = css_probe_device(schid);
  385. switch (ret) {
  386. case 0:
  387. break;
  388. case -ENXIO:
  389. case -ENOMEM:
  390. /* These should abort looping */
  391. break;
  392. default:
  393. ret = 0;
  394. }
  395. return ret;
  396. }
  397. /* Work function used to reprobe all unregistered subchannels. */
  398. static void reprobe_all(struct work_struct *unused)
  399. {
  400. int ret;
  401. CIO_MSG_EVENT(2, "reprobe start\n");
  402. need_reprobe = 0;
  403. /* Make sure initial subchannel scan is done. */
  404. wait_event(ccw_device_init_wq,
  405. atomic_read(&ccw_device_init_count) == 0);
  406. ret = for_each_subchannel(reprobe_subchannel, NULL);
  407. CIO_MSG_EVENT(2, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
  408. need_reprobe);
  409. }
  410. static DECLARE_WORK(css_reprobe_work, reprobe_all);
  411. /* Schedule reprobing of all unregistered subchannels. */
  412. void css_schedule_reprobe(void)
  413. {
  414. need_reprobe = 1;
  415. queue_work(ccw_device_work, &css_reprobe_work);
  416. }
  417. EXPORT_SYMBOL_GPL(css_schedule_reprobe);
  418. /*
  419. * Called from the machine check handler for subchannel report words.
  420. */
  421. void css_process_crw(int rsid1, int rsid2)
  422. {
  423. struct subchannel_id mchk_schid;
  424. CIO_CRW_EVENT(2, "source is subchannel %04X, subsystem id %x\n",
  425. rsid1, rsid2);
  426. init_subchannel_id(&mchk_schid);
  427. mchk_schid.sch_no = rsid1;
  428. if (rsid2 != 0)
  429. mchk_schid.ssid = (rsid2 >> 8) & 3;
  430. /*
  431. * Since we are always presented with IPI in the CRW, we have to
  432. * use stsch() to find out if the subchannel in question has come
  433. * or gone.
  434. */
  435. css_evaluate_subchannel(mchk_schid, 0);
  436. }
  437. static int __init
  438. __init_channel_subsystem(struct subchannel_id schid, void *data)
  439. {
  440. struct subchannel *sch;
  441. int ret;
  442. if (cio_is_console(schid))
  443. sch = cio_get_console_subchannel();
  444. else {
  445. sch = css_alloc_subchannel(schid);
  446. if (IS_ERR(sch))
  447. ret = PTR_ERR(sch);
  448. else
  449. ret = 0;
  450. switch (ret) {
  451. case 0:
  452. break;
  453. case -ENOMEM:
  454. panic("Out of memory in init_channel_subsystem\n");
  455. /* -ENXIO: no more subchannels. */
  456. case -ENXIO:
  457. return ret;
  458. /* -EIO: this subchannel set not supported. */
  459. case -EIO:
  460. return ret;
  461. default:
  462. return 0;
  463. }
  464. }
  465. /*
  466. * We register ALL valid subchannels in ioinfo, even those
  467. * that have been present before init_channel_subsystem.
  468. * These subchannels can't have been registered yet (kmalloc
  469. * not working) so we do it now. This is true e.g. for the
  470. * console subchannel.
  471. */
  472. css_register_subchannel(sch);
  473. return 0;
  474. }
  475. static void __init
  476. css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
  477. {
  478. if (css_characteristics_avail && css_general_characteristics.mcss) {
  479. css->global_pgid.pgid_high.ext_cssid.version = 0x80;
  480. css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
  481. } else {
  482. #ifdef CONFIG_SMP
  483. css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id();
  484. #else
  485. css->global_pgid.pgid_high.cpu_addr = 0;
  486. #endif
  487. }
  488. css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident;
  489. css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine;
  490. css->global_pgid.tod_high = tod_high;
  491. }
  492. static void
  493. channel_subsystem_release(struct device *dev)
  494. {
  495. struct channel_subsystem *css;
  496. css = to_css(dev);
  497. mutex_destroy(&css->mutex);
  498. kfree(css);
  499. }
  500. static ssize_t
  501. css_cm_enable_show(struct device *dev, struct device_attribute *attr,
  502. char *buf)
  503. {
  504. struct channel_subsystem *css = to_css(dev);
  505. if (!css)
  506. return 0;
  507. return sprintf(buf, "%x\n", css->cm_enabled);
  508. }
  509. static ssize_t
  510. css_cm_enable_store(struct device *dev, struct device_attribute *attr,
  511. const char *buf, size_t count)
  512. {
  513. struct channel_subsystem *css = to_css(dev);
  514. int ret;
  515. switch (buf[0]) {
  516. case '0':
  517. ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
  518. break;
  519. case '1':
  520. ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
  521. break;
  522. default:
  523. ret = -EINVAL;
  524. }
  525. return ret < 0 ? ret : count;
  526. }
  527. static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
  528. static int __init setup_css(int nr)
  529. {
  530. u32 tod_high;
  531. int ret;
  532. memset(css[nr], 0, sizeof(struct channel_subsystem));
  533. css[nr]->pseudo_subchannel =
  534. kzalloc(sizeof(*css[nr]->pseudo_subchannel), GFP_KERNEL);
  535. if (!css[nr]->pseudo_subchannel)
  536. return -ENOMEM;
  537. css[nr]->pseudo_subchannel->dev.parent = &css[nr]->device;
  538. css[nr]->pseudo_subchannel->dev.release = css_subchannel_release;
  539. sprintf(css[nr]->pseudo_subchannel->dev.bus_id, "defunct");
  540. ret = cio_create_sch_lock(css[nr]->pseudo_subchannel);
  541. if (ret) {
  542. kfree(css[nr]->pseudo_subchannel);
  543. return ret;
  544. }
  545. mutex_init(&css[nr]->mutex);
  546. css[nr]->valid = 1;
  547. css[nr]->cssid = nr;
  548. sprintf(css[nr]->device.bus_id, "css%x", nr);
  549. css[nr]->device.release = channel_subsystem_release;
  550. tod_high = (u32) (get_clock() >> 32);
  551. css_generate_pgid(css[nr], tod_high);
  552. return 0;
  553. }
  554. /*
  555. * Now that the driver core is running, we can setup our channel subsystem.
  556. * The struct subchannel's are created during probing (except for the
  557. * static console subchannel).
  558. */
  559. static int __init
  560. init_channel_subsystem (void)
  561. {
  562. int ret, i;
  563. if (chsc_determine_css_characteristics() == 0)
  564. css_characteristics_avail = 1;
  565. if ((ret = bus_register(&css_bus_type)))
  566. goto out;
  567. /* Try to enable MSS. */
  568. ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
  569. switch (ret) {
  570. case 0: /* Success. */
  571. max_ssid = __MAX_SSID;
  572. break;
  573. case -ENOMEM:
  574. goto out_bus;
  575. default:
  576. max_ssid = 0;
  577. }
  578. /* Setup css structure. */
  579. for (i = 0; i <= __MAX_CSSID; i++) {
  580. css[i] = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
  581. if (!css[i]) {
  582. ret = -ENOMEM;
  583. goto out_unregister;
  584. }
  585. ret = setup_css(i);
  586. if (ret)
  587. goto out_free;
  588. ret = device_register(&css[i]->device);
  589. if (ret)
  590. goto out_free_all;
  591. if (css_characteristics_avail &&
  592. css_chsc_characteristics.secm) {
  593. ret = device_create_file(&css[i]->device,
  594. &dev_attr_cm_enable);
  595. if (ret)
  596. goto out_device;
  597. }
  598. ret = device_register(&css[i]->pseudo_subchannel->dev);
  599. if (ret)
  600. goto out_file;
  601. }
  602. css_init_done = 1;
  603. ctl_set_bit(6, 28);
  604. for_each_subchannel(__init_channel_subsystem, NULL);
  605. return 0;
  606. out_file:
  607. device_remove_file(&css[i]->device, &dev_attr_cm_enable);
  608. out_device:
  609. device_unregister(&css[i]->device);
  610. out_free_all:
  611. kfree(css[i]->pseudo_subchannel->lock);
  612. kfree(css[i]->pseudo_subchannel);
  613. out_free:
  614. kfree(css[i]);
  615. out_unregister:
  616. while (i > 0) {
  617. i--;
  618. device_unregister(&css[i]->pseudo_subchannel->dev);
  619. if (css_characteristics_avail && css_chsc_characteristics.secm)
  620. device_remove_file(&css[i]->device,
  621. &dev_attr_cm_enable);
  622. device_unregister(&css[i]->device);
  623. }
  624. out_bus:
  625. bus_unregister(&css_bus_type);
  626. out:
  627. return ret;
  628. }
  629. int sch_is_pseudo_sch(struct subchannel *sch)
  630. {
  631. return sch == to_css(sch->dev.parent)->pseudo_subchannel;
  632. }
  633. /*
  634. * find a driver for a subchannel. They identify by the subchannel
  635. * type with the exception that the console subchannel driver has its own
  636. * subchannel type although the device is an i/o subchannel
  637. */
  638. static int
  639. css_bus_match (struct device *dev, struct device_driver *drv)
  640. {
  641. struct subchannel *sch = container_of (dev, struct subchannel, dev);
  642. struct css_driver *driver = container_of (drv, struct css_driver, drv);
  643. if (sch->st == driver->subchannel_type)
  644. return 1;
  645. return 0;
  646. }
  647. static int
  648. css_probe (struct device *dev)
  649. {
  650. struct subchannel *sch;
  651. sch = to_subchannel(dev);
  652. sch->driver = container_of (dev->driver, struct css_driver, drv);
  653. return (sch->driver->probe ? sch->driver->probe(sch) : 0);
  654. }
  655. static int
  656. css_remove (struct device *dev)
  657. {
  658. struct subchannel *sch;
  659. sch = to_subchannel(dev);
  660. return (sch->driver->remove ? sch->driver->remove(sch) : 0);
  661. }
  662. static void
  663. css_shutdown (struct device *dev)
  664. {
  665. struct subchannel *sch;
  666. sch = to_subchannel(dev);
  667. if (sch->driver->shutdown)
  668. sch->driver->shutdown(sch);
  669. }
  670. struct bus_type css_bus_type = {
  671. .name = "css",
  672. .match = css_bus_match,
  673. .probe = css_probe,
  674. .remove = css_remove,
  675. .shutdown = css_shutdown,
  676. };
  677. subsys_initcall(init_channel_subsystem);
  678. MODULE_LICENSE("GPL");
  679. EXPORT_SYMBOL(css_bus_type);
  680. EXPORT_SYMBOL_GPL(css_characteristics_avail);