css.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  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. int
  170. css_probe_device(struct subchannel_id schid)
  171. {
  172. int ret;
  173. struct subchannel *sch;
  174. sch = css_alloc_subchannel(schid);
  175. if (IS_ERR(sch))
  176. return PTR_ERR(sch);
  177. ret = css_register_subchannel(sch);
  178. if (ret)
  179. css_free_subchannel(sch);
  180. return ret;
  181. }
  182. static int
  183. check_subchannel(struct device * dev, void * data)
  184. {
  185. struct subchannel *sch;
  186. struct subchannel_id *schid = data;
  187. sch = to_subchannel(dev);
  188. return schid_equal(&sch->schid, schid);
  189. }
  190. struct subchannel *
  191. get_subchannel_by_schid(struct subchannel_id schid)
  192. {
  193. struct device *dev;
  194. dev = bus_find_device(&css_bus_type, NULL,
  195. &schid, check_subchannel);
  196. return dev ? to_subchannel(dev) : NULL;
  197. }
  198. static int css_get_subchannel_status(struct subchannel *sch)
  199. {
  200. struct schib schib;
  201. if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
  202. return CIO_GONE;
  203. if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
  204. return CIO_REVALIDATE;
  205. if (!sch->lpm)
  206. return CIO_NO_PATH;
  207. return CIO_OPER;
  208. }
  209. static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
  210. {
  211. int event, ret, disc;
  212. unsigned long flags;
  213. enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
  214. spin_lock_irqsave(sch->lock, flags);
  215. disc = device_is_disconnected(sch);
  216. if (disc && slow) {
  217. /* Disconnected devices are evaluated directly only.*/
  218. spin_unlock_irqrestore(sch->lock, flags);
  219. return 0;
  220. }
  221. /* No interrupt after machine check - kill pending timers. */
  222. device_kill_pending_timer(sch);
  223. if (!disc && !slow) {
  224. /* Non-disconnected devices are evaluated on the slow path. */
  225. spin_unlock_irqrestore(sch->lock, flags);
  226. return -EAGAIN;
  227. }
  228. event = css_get_subchannel_status(sch);
  229. CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
  230. sch->schid.ssid, sch->schid.sch_no, event,
  231. disc ? "disconnected" : "normal",
  232. slow ? "slow" : "fast");
  233. /* Analyze subchannel status. */
  234. action = NONE;
  235. switch (event) {
  236. case CIO_NO_PATH:
  237. if (disc) {
  238. /* Check if paths have become available. */
  239. action = REPROBE;
  240. break;
  241. }
  242. /* fall through */
  243. case CIO_GONE:
  244. /* Prevent unwanted effects when opening lock. */
  245. cio_disable_subchannel(sch);
  246. device_set_disconnected(sch);
  247. /* Ask driver what to do with device. */
  248. action = UNREGISTER;
  249. if (sch->driver && sch->driver->notify) {
  250. spin_unlock_irqrestore(sch->lock, flags);
  251. ret = sch->driver->notify(&sch->dev, event);
  252. spin_lock_irqsave(sch->lock, flags);
  253. if (ret)
  254. action = NONE;
  255. }
  256. break;
  257. case CIO_REVALIDATE:
  258. /* Device will be removed, so no notify necessary. */
  259. if (disc)
  260. /* Reprobe because immediate unregister might block. */
  261. action = REPROBE;
  262. else
  263. action = UNREGISTER_PROBE;
  264. break;
  265. case CIO_OPER:
  266. if (disc)
  267. /* Get device operational again. */
  268. action = REPROBE;
  269. break;
  270. }
  271. /* Perform action. */
  272. ret = 0;
  273. switch (action) {
  274. case UNREGISTER:
  275. case UNREGISTER_PROBE:
  276. /* Unregister device (will use subchannel lock). */
  277. spin_unlock_irqrestore(sch->lock, flags);
  278. css_sch_device_unregister(sch);
  279. spin_lock_irqsave(sch->lock, flags);
  280. /* Reset intparm to zeroes. */
  281. sch->schib.pmcw.intparm = 0;
  282. cio_modify(sch);
  283. break;
  284. case REPROBE:
  285. device_trigger_reprobe(sch);
  286. break;
  287. default:
  288. break;
  289. }
  290. spin_unlock_irqrestore(sch->lock, flags);
  291. /* Probe if necessary. */
  292. if (action == UNREGISTER_PROBE)
  293. ret = css_probe_device(sch->schid);
  294. return ret;
  295. }
  296. static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
  297. {
  298. struct schib schib;
  299. if (!slow) {
  300. /* Will be done on the slow path. */
  301. return -EAGAIN;
  302. }
  303. if (stsch_err(schid, &schib) || !schib.pmcw.dnv) {
  304. /* Unusable - ignore. */
  305. return 0;
  306. }
  307. CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, "
  308. "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER);
  309. return css_probe_device(schid);
  310. }
  311. static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
  312. {
  313. struct subchannel *sch;
  314. int ret;
  315. sch = get_subchannel_by_schid(schid);
  316. if (sch) {
  317. ret = css_evaluate_known_subchannel(sch, slow);
  318. put_device(&sch->dev);
  319. } else
  320. ret = css_evaluate_new_subchannel(schid, slow);
  321. if (ret == -EAGAIN)
  322. css_schedule_eval(schid);
  323. }
  324. static struct idset *slow_subchannel_set;
  325. static spinlock_t slow_subchannel_lock;
  326. static int __init slow_subchannel_init(void)
  327. {
  328. spin_lock_init(&slow_subchannel_lock);
  329. slow_subchannel_set = idset_sch_new();
  330. if (!slow_subchannel_set) {
  331. printk(KERN_WARNING "cio: could not allocate slow subchannel "
  332. "set\n");
  333. return -ENOMEM;
  334. }
  335. return 0;
  336. }
  337. subsys_initcall(slow_subchannel_init);
  338. static void css_slow_path_func(struct work_struct *unused)
  339. {
  340. struct subchannel_id schid;
  341. CIO_TRACE_EVENT(4, "slowpath");
  342. spin_lock_irq(&slow_subchannel_lock);
  343. init_subchannel_id(&schid);
  344. while (idset_sch_get_first(slow_subchannel_set, &schid)) {
  345. idset_sch_del(slow_subchannel_set, schid);
  346. spin_unlock_irq(&slow_subchannel_lock);
  347. css_evaluate_subchannel(schid, 1);
  348. spin_lock_irq(&slow_subchannel_lock);
  349. }
  350. spin_unlock_irq(&slow_subchannel_lock);
  351. }
  352. static DECLARE_WORK(slow_path_work, css_slow_path_func);
  353. struct workqueue_struct *slow_path_wq;
  354. void css_schedule_eval(struct subchannel_id schid)
  355. {
  356. unsigned long flags;
  357. spin_lock_irqsave(&slow_subchannel_lock, flags);
  358. idset_sch_add(slow_subchannel_set, schid);
  359. queue_work(slow_path_wq, &slow_path_work);
  360. spin_unlock_irqrestore(&slow_subchannel_lock, flags);
  361. }
  362. void css_schedule_eval_all(void)
  363. {
  364. unsigned long flags;
  365. spin_lock_irqsave(&slow_subchannel_lock, flags);
  366. idset_fill(slow_subchannel_set);
  367. queue_work(slow_path_wq, &slow_path_work);
  368. spin_unlock_irqrestore(&slow_subchannel_lock, flags);
  369. }
  370. /* Reprobe subchannel if unregistered. */
  371. static int reprobe_subchannel(struct subchannel_id schid, void *data)
  372. {
  373. struct subchannel *sch;
  374. int ret;
  375. CIO_DEBUG(KERN_INFO, 6, "cio: reprobe 0.%x.%04x\n",
  376. schid.ssid, schid.sch_no);
  377. if (need_reprobe)
  378. return -EAGAIN;
  379. sch = get_subchannel_by_schid(schid);
  380. if (sch) {
  381. /* Already known. */
  382. put_device(&sch->dev);
  383. return 0;
  384. }
  385. ret = css_probe_device(schid);
  386. switch (ret) {
  387. case 0:
  388. break;
  389. case -ENXIO:
  390. case -ENOMEM:
  391. /* These should abort looping */
  392. break;
  393. default:
  394. ret = 0;
  395. }
  396. return ret;
  397. }
  398. /* Work function used to reprobe all unregistered subchannels. */
  399. static void reprobe_all(struct work_struct *unused)
  400. {
  401. int ret;
  402. CIO_MSG_EVENT(2, "reprobe start\n");
  403. need_reprobe = 0;
  404. /* Make sure initial subchannel scan is done. */
  405. wait_event(ccw_device_init_wq,
  406. atomic_read(&ccw_device_init_count) == 0);
  407. ret = for_each_subchannel(reprobe_subchannel, NULL);
  408. CIO_MSG_EVENT(2, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
  409. need_reprobe);
  410. }
  411. static DECLARE_WORK(css_reprobe_work, reprobe_all);
  412. /* Schedule reprobing of all unregistered subchannels. */
  413. void css_schedule_reprobe(void)
  414. {
  415. need_reprobe = 1;
  416. queue_work(ccw_device_work, &css_reprobe_work);
  417. }
  418. EXPORT_SYMBOL_GPL(css_schedule_reprobe);
  419. /*
  420. * Called from the machine check handler for subchannel report words.
  421. */
  422. void css_process_crw(int rsid1, int rsid2)
  423. {
  424. struct subchannel_id mchk_schid;
  425. CIO_CRW_EVENT(2, "source is subchannel %04X, subsystem id %x\n",
  426. rsid1, rsid2);
  427. init_subchannel_id(&mchk_schid);
  428. mchk_schid.sch_no = rsid1;
  429. if (rsid2 != 0)
  430. mchk_schid.ssid = (rsid2 >> 8) & 3;
  431. /*
  432. * Since we are always presented with IPI in the CRW, we have to
  433. * use stsch() to find out if the subchannel in question has come
  434. * or gone.
  435. */
  436. css_evaluate_subchannel(mchk_schid, 0);
  437. }
  438. static int __init
  439. __init_channel_subsystem(struct subchannel_id schid, void *data)
  440. {
  441. struct subchannel *sch;
  442. int ret;
  443. if (cio_is_console(schid))
  444. sch = cio_get_console_subchannel();
  445. else {
  446. sch = css_alloc_subchannel(schid);
  447. if (IS_ERR(sch))
  448. ret = PTR_ERR(sch);
  449. else
  450. ret = 0;
  451. switch (ret) {
  452. case 0:
  453. break;
  454. case -ENOMEM:
  455. panic("Out of memory in init_channel_subsystem\n");
  456. /* -ENXIO: no more subchannels. */
  457. case -ENXIO:
  458. return ret;
  459. /* -EIO: this subchannel set not supported. */
  460. case -EIO:
  461. return ret;
  462. default:
  463. return 0;
  464. }
  465. }
  466. /*
  467. * We register ALL valid subchannels in ioinfo, even those
  468. * that have been present before init_channel_subsystem.
  469. * These subchannels can't have been registered yet (kmalloc
  470. * not working) so we do it now. This is true e.g. for the
  471. * console subchannel.
  472. */
  473. css_register_subchannel(sch);
  474. return 0;
  475. }
  476. static void __init
  477. css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
  478. {
  479. if (css_characteristics_avail && css_general_characteristics.mcss) {
  480. css->global_pgid.pgid_high.ext_cssid.version = 0x80;
  481. css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
  482. } else {
  483. #ifdef CONFIG_SMP
  484. css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id();
  485. #else
  486. css->global_pgid.pgid_high.cpu_addr = 0;
  487. #endif
  488. }
  489. css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident;
  490. css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine;
  491. css->global_pgid.tod_high = tod_high;
  492. }
  493. static void
  494. channel_subsystem_release(struct device *dev)
  495. {
  496. struct channel_subsystem *css;
  497. css = to_css(dev);
  498. mutex_destroy(&css->mutex);
  499. kfree(css);
  500. }
  501. static ssize_t
  502. css_cm_enable_show(struct device *dev, struct device_attribute *attr,
  503. char *buf)
  504. {
  505. struct channel_subsystem *css = to_css(dev);
  506. if (!css)
  507. return 0;
  508. return sprintf(buf, "%x\n", css->cm_enabled);
  509. }
  510. static ssize_t
  511. css_cm_enable_store(struct device *dev, struct device_attribute *attr,
  512. const char *buf, size_t count)
  513. {
  514. struct channel_subsystem *css = to_css(dev);
  515. int ret;
  516. switch (buf[0]) {
  517. case '0':
  518. ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
  519. break;
  520. case '1':
  521. ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
  522. break;
  523. default:
  524. ret = -EINVAL;
  525. }
  526. return ret < 0 ? ret : count;
  527. }
  528. static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
  529. static int __init setup_css(int nr)
  530. {
  531. u32 tod_high;
  532. int ret;
  533. memset(css[nr], 0, sizeof(struct channel_subsystem));
  534. css[nr]->pseudo_subchannel =
  535. kzalloc(sizeof(*css[nr]->pseudo_subchannel), GFP_KERNEL);
  536. if (!css[nr]->pseudo_subchannel)
  537. return -ENOMEM;
  538. css[nr]->pseudo_subchannel->dev.parent = &css[nr]->device;
  539. css[nr]->pseudo_subchannel->dev.release = css_subchannel_release;
  540. sprintf(css[nr]->pseudo_subchannel->dev.bus_id, "defunct");
  541. ret = cio_create_sch_lock(css[nr]->pseudo_subchannel);
  542. if (ret) {
  543. kfree(css[nr]->pseudo_subchannel);
  544. return ret;
  545. }
  546. mutex_init(&css[nr]->mutex);
  547. css[nr]->valid = 1;
  548. css[nr]->cssid = nr;
  549. sprintf(css[nr]->device.bus_id, "css%x", nr);
  550. css[nr]->device.release = channel_subsystem_release;
  551. tod_high = (u32) (get_clock() >> 32);
  552. css_generate_pgid(css[nr], tod_high);
  553. return 0;
  554. }
  555. /*
  556. * Now that the driver core is running, we can setup our channel subsystem.
  557. * The struct subchannel's are created during probing (except for the
  558. * static console subchannel).
  559. */
  560. static int __init
  561. init_channel_subsystem (void)
  562. {
  563. int ret, i;
  564. if (chsc_determine_css_characteristics() == 0)
  565. css_characteristics_avail = 1;
  566. if ((ret = bus_register(&css_bus_type)))
  567. goto out;
  568. /* Try to enable MSS. */
  569. ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
  570. switch (ret) {
  571. case 0: /* Success. */
  572. max_ssid = __MAX_SSID;
  573. break;
  574. case -ENOMEM:
  575. goto out_bus;
  576. default:
  577. max_ssid = 0;
  578. }
  579. /* Setup css structure. */
  580. for (i = 0; i <= __MAX_CSSID; i++) {
  581. css[i] = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
  582. if (!css[i]) {
  583. ret = -ENOMEM;
  584. goto out_unregister;
  585. }
  586. ret = setup_css(i);
  587. if (ret)
  588. goto out_free;
  589. ret = device_register(&css[i]->device);
  590. if (ret)
  591. goto out_free_all;
  592. if (css_characteristics_avail &&
  593. css_chsc_characteristics.secm) {
  594. ret = device_create_file(&css[i]->device,
  595. &dev_attr_cm_enable);
  596. if (ret)
  597. goto out_device;
  598. }
  599. ret = device_register(&css[i]->pseudo_subchannel->dev);
  600. if (ret)
  601. goto out_file;
  602. }
  603. css_init_done = 1;
  604. ctl_set_bit(6, 28);
  605. for_each_subchannel(__init_channel_subsystem, NULL);
  606. return 0;
  607. out_file:
  608. device_remove_file(&css[i]->device, &dev_attr_cm_enable);
  609. out_device:
  610. device_unregister(&css[i]->device);
  611. out_free_all:
  612. kfree(css[i]->pseudo_subchannel->lock);
  613. kfree(css[i]->pseudo_subchannel);
  614. out_free:
  615. kfree(css[i]);
  616. out_unregister:
  617. while (i > 0) {
  618. i--;
  619. device_unregister(&css[i]->pseudo_subchannel->dev);
  620. if (css_characteristics_avail && css_chsc_characteristics.secm)
  621. device_remove_file(&css[i]->device,
  622. &dev_attr_cm_enable);
  623. device_unregister(&css[i]->device);
  624. }
  625. out_bus:
  626. bus_unregister(&css_bus_type);
  627. out:
  628. return ret;
  629. }
  630. int sch_is_pseudo_sch(struct subchannel *sch)
  631. {
  632. return sch == to_css(sch->dev.parent)->pseudo_subchannel;
  633. }
  634. /*
  635. * find a driver for a subchannel. They identify by the subchannel
  636. * type with the exception that the console subchannel driver has its own
  637. * subchannel type although the device is an i/o subchannel
  638. */
  639. static int
  640. css_bus_match (struct device *dev, struct device_driver *drv)
  641. {
  642. struct subchannel *sch = container_of (dev, struct subchannel, dev);
  643. struct css_driver *driver = container_of (drv, struct css_driver, drv);
  644. if (sch->st == driver->subchannel_type)
  645. return 1;
  646. return 0;
  647. }
  648. static int
  649. css_probe (struct device *dev)
  650. {
  651. struct subchannel *sch;
  652. sch = to_subchannel(dev);
  653. sch->driver = container_of (dev->driver, struct css_driver, drv);
  654. return (sch->driver->probe ? sch->driver->probe(sch) : 0);
  655. }
  656. static int
  657. css_remove (struct device *dev)
  658. {
  659. struct subchannel *sch;
  660. sch = to_subchannel(dev);
  661. return (sch->driver->remove ? sch->driver->remove(sch) : 0);
  662. }
  663. static void
  664. css_shutdown (struct device *dev)
  665. {
  666. struct subchannel *sch;
  667. sch = to_subchannel(dev);
  668. if (sch->driver->shutdown)
  669. sch->driver->shutdown(sch);
  670. }
  671. struct bus_type css_bus_type = {
  672. .name = "css",
  673. .match = css_bus_match,
  674. .probe = css_probe,
  675. .remove = css_remove,
  676. .shutdown = css_shutdown,
  677. };
  678. subsys_initcall(init_channel_subsystem);
  679. MODULE_LICENSE("GPL");
  680. EXPORT_SYMBOL(css_bus_type);
  681. EXPORT_SYMBOL_GPL(css_characteristics_avail);