css.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. static 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. CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
  164. sch->schid.ssid, sch->schid.sch_no, ret);
  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. CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
  331. return -ENOMEM;
  332. }
  333. return 0;
  334. }
  335. static void css_slow_path_func(struct work_struct *unused)
  336. {
  337. struct subchannel_id schid;
  338. CIO_TRACE_EVENT(4, "slowpath");
  339. spin_lock_irq(&slow_subchannel_lock);
  340. init_subchannel_id(&schid);
  341. while (idset_sch_get_first(slow_subchannel_set, &schid)) {
  342. idset_sch_del(slow_subchannel_set, schid);
  343. spin_unlock_irq(&slow_subchannel_lock);
  344. css_evaluate_subchannel(schid, 1);
  345. spin_lock_irq(&slow_subchannel_lock);
  346. }
  347. spin_unlock_irq(&slow_subchannel_lock);
  348. }
  349. static DECLARE_WORK(slow_path_work, css_slow_path_func);
  350. struct workqueue_struct *slow_path_wq;
  351. void css_schedule_eval(struct subchannel_id schid)
  352. {
  353. unsigned long flags;
  354. spin_lock_irqsave(&slow_subchannel_lock, flags);
  355. idset_sch_add(slow_subchannel_set, schid);
  356. queue_work(slow_path_wq, &slow_path_work);
  357. spin_unlock_irqrestore(&slow_subchannel_lock, flags);
  358. }
  359. void css_schedule_eval_all(void)
  360. {
  361. unsigned long flags;
  362. spin_lock_irqsave(&slow_subchannel_lock, flags);
  363. idset_fill(slow_subchannel_set);
  364. queue_work(slow_path_wq, &slow_path_work);
  365. spin_unlock_irqrestore(&slow_subchannel_lock, flags);
  366. }
  367. /* Reprobe subchannel if unregistered. */
  368. static int reprobe_subchannel(struct subchannel_id schid, void *data)
  369. {
  370. struct subchannel *sch;
  371. int ret;
  372. CIO_MSG_EVENT(6, "cio: reprobe 0.%x.%04x\n",
  373. schid.ssid, schid.sch_no);
  374. if (need_reprobe)
  375. return -EAGAIN;
  376. sch = get_subchannel_by_schid(schid);
  377. if (sch) {
  378. /* Already known. */
  379. put_device(&sch->dev);
  380. return 0;
  381. }
  382. ret = css_probe_device(schid);
  383. switch (ret) {
  384. case 0:
  385. break;
  386. case -ENXIO:
  387. case -ENOMEM:
  388. /* These should abort looping */
  389. break;
  390. default:
  391. ret = 0;
  392. }
  393. return ret;
  394. }
  395. /* Work function used to reprobe all unregistered subchannels. */
  396. static void reprobe_all(struct work_struct *unused)
  397. {
  398. int ret;
  399. CIO_MSG_EVENT(2, "reprobe start\n");
  400. need_reprobe = 0;
  401. /* Make sure initial subchannel scan is done. */
  402. wait_event(ccw_device_init_wq,
  403. atomic_read(&ccw_device_init_count) == 0);
  404. ret = for_each_subchannel(reprobe_subchannel, NULL);
  405. CIO_MSG_EVENT(2, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
  406. need_reprobe);
  407. }
  408. static DECLARE_WORK(css_reprobe_work, reprobe_all);
  409. /* Schedule reprobing of all unregistered subchannels. */
  410. void css_schedule_reprobe(void)
  411. {
  412. need_reprobe = 1;
  413. queue_work(ccw_device_work, &css_reprobe_work);
  414. }
  415. EXPORT_SYMBOL_GPL(css_schedule_reprobe);
  416. /*
  417. * Called from the machine check handler for subchannel report words.
  418. */
  419. void css_process_crw(int rsid1, int rsid2)
  420. {
  421. struct subchannel_id mchk_schid;
  422. CIO_CRW_EVENT(2, "source is subchannel %04X, subsystem id %x\n",
  423. rsid1, rsid2);
  424. init_subchannel_id(&mchk_schid);
  425. mchk_schid.sch_no = rsid1;
  426. if (rsid2 != 0)
  427. mchk_schid.ssid = (rsid2 >> 8) & 3;
  428. /*
  429. * Since we are always presented with IPI in the CRW, we have to
  430. * use stsch() to find out if the subchannel in question has come
  431. * or gone.
  432. */
  433. css_evaluate_subchannel(mchk_schid, 0);
  434. }
  435. static int __init
  436. __init_channel_subsystem(struct subchannel_id schid, void *data)
  437. {
  438. struct subchannel *sch;
  439. int ret;
  440. if (cio_is_console(schid))
  441. sch = cio_get_console_subchannel();
  442. else {
  443. sch = css_alloc_subchannel(schid);
  444. if (IS_ERR(sch))
  445. ret = PTR_ERR(sch);
  446. else
  447. ret = 0;
  448. switch (ret) {
  449. case 0:
  450. break;
  451. case -ENOMEM:
  452. panic("Out of memory in init_channel_subsystem\n");
  453. /* -ENXIO: no more subchannels. */
  454. case -ENXIO:
  455. return ret;
  456. /* -EIO: this subchannel set not supported. */
  457. case -EIO:
  458. return ret;
  459. default:
  460. return 0;
  461. }
  462. }
  463. /*
  464. * We register ALL valid subchannels in ioinfo, even those
  465. * that have been present before init_channel_subsystem.
  466. * These subchannels can't have been registered yet (kmalloc
  467. * not working) so we do it now. This is true e.g. for the
  468. * console subchannel.
  469. */
  470. css_register_subchannel(sch);
  471. return 0;
  472. }
  473. static void __init
  474. css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
  475. {
  476. if (css_characteristics_avail && css_general_characteristics.mcss) {
  477. css->global_pgid.pgid_high.ext_cssid.version = 0x80;
  478. css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
  479. } else {
  480. #ifdef CONFIG_SMP
  481. css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id();
  482. #else
  483. css->global_pgid.pgid_high.cpu_addr = 0;
  484. #endif
  485. }
  486. css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident;
  487. css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine;
  488. css->global_pgid.tod_high = tod_high;
  489. }
  490. static void
  491. channel_subsystem_release(struct device *dev)
  492. {
  493. struct channel_subsystem *css;
  494. css = to_css(dev);
  495. mutex_destroy(&css->mutex);
  496. kfree(css);
  497. }
  498. static ssize_t
  499. css_cm_enable_show(struct device *dev, struct device_attribute *attr,
  500. char *buf)
  501. {
  502. struct channel_subsystem *css = to_css(dev);
  503. if (!css)
  504. return 0;
  505. return sprintf(buf, "%x\n", css->cm_enabled);
  506. }
  507. static ssize_t
  508. css_cm_enable_store(struct device *dev, struct device_attribute *attr,
  509. const char *buf, size_t count)
  510. {
  511. struct channel_subsystem *css = to_css(dev);
  512. int ret;
  513. switch (buf[0]) {
  514. case '0':
  515. ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
  516. break;
  517. case '1':
  518. ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
  519. break;
  520. default:
  521. ret = -EINVAL;
  522. }
  523. return ret < 0 ? ret : count;
  524. }
  525. static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
  526. static int __init setup_css(int nr)
  527. {
  528. u32 tod_high;
  529. int ret;
  530. memset(css[nr], 0, sizeof(struct channel_subsystem));
  531. css[nr]->pseudo_subchannel =
  532. kzalloc(sizeof(*css[nr]->pseudo_subchannel), GFP_KERNEL);
  533. if (!css[nr]->pseudo_subchannel)
  534. return -ENOMEM;
  535. css[nr]->pseudo_subchannel->dev.parent = &css[nr]->device;
  536. css[nr]->pseudo_subchannel->dev.release = css_subchannel_release;
  537. sprintf(css[nr]->pseudo_subchannel->dev.bus_id, "defunct");
  538. ret = cio_create_sch_lock(css[nr]->pseudo_subchannel);
  539. if (ret) {
  540. kfree(css[nr]->pseudo_subchannel);
  541. return ret;
  542. }
  543. mutex_init(&css[nr]->mutex);
  544. css[nr]->valid = 1;
  545. css[nr]->cssid = nr;
  546. sprintf(css[nr]->device.bus_id, "css%x", nr);
  547. css[nr]->device.release = channel_subsystem_release;
  548. tod_high = (u32) (get_clock() >> 32);
  549. css_generate_pgid(css[nr], tod_high);
  550. return 0;
  551. }
  552. /*
  553. * Now that the driver core is running, we can setup our channel subsystem.
  554. * The struct subchannel's are created during probing (except for the
  555. * static console subchannel).
  556. */
  557. static int __init
  558. init_channel_subsystem (void)
  559. {
  560. int ret, i;
  561. ret = chsc_determine_css_characteristics();
  562. if (ret == -ENOMEM)
  563. goto out; /* No need to continue. */
  564. if (ret == 0)
  565. css_characteristics_avail = 1;
  566. ret = chsc_alloc_sei_area();
  567. if (ret)
  568. goto out;
  569. ret = slow_subchannel_init();
  570. if (ret)
  571. goto out;
  572. if ((ret = bus_register(&css_bus_type)))
  573. goto out;
  574. /* Try to enable MSS. */
  575. ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
  576. switch (ret) {
  577. case 0: /* Success. */
  578. max_ssid = __MAX_SSID;
  579. break;
  580. case -ENOMEM:
  581. goto out_bus;
  582. default:
  583. max_ssid = 0;
  584. }
  585. /* Setup css structure. */
  586. for (i = 0; i <= __MAX_CSSID; i++) {
  587. css[i] = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
  588. if (!css[i]) {
  589. ret = -ENOMEM;
  590. goto out_unregister;
  591. }
  592. ret = setup_css(i);
  593. if (ret)
  594. goto out_free;
  595. ret = device_register(&css[i]->device);
  596. if (ret)
  597. goto out_free_all;
  598. if (css_characteristics_avail &&
  599. css_chsc_characteristics.secm) {
  600. ret = device_create_file(&css[i]->device,
  601. &dev_attr_cm_enable);
  602. if (ret)
  603. goto out_device;
  604. }
  605. ret = device_register(&css[i]->pseudo_subchannel->dev);
  606. if (ret)
  607. goto out_file;
  608. }
  609. css_init_done = 1;
  610. ctl_set_bit(6, 28);
  611. for_each_subchannel(__init_channel_subsystem, NULL);
  612. return 0;
  613. out_file:
  614. device_remove_file(&css[i]->device, &dev_attr_cm_enable);
  615. out_device:
  616. device_unregister(&css[i]->device);
  617. out_free_all:
  618. kfree(css[i]->pseudo_subchannel->lock);
  619. kfree(css[i]->pseudo_subchannel);
  620. out_free:
  621. kfree(css[i]);
  622. out_unregister:
  623. while (i > 0) {
  624. i--;
  625. device_unregister(&css[i]->pseudo_subchannel->dev);
  626. if (css_characteristics_avail && css_chsc_characteristics.secm)
  627. device_remove_file(&css[i]->device,
  628. &dev_attr_cm_enable);
  629. device_unregister(&css[i]->device);
  630. }
  631. out_bus:
  632. bus_unregister(&css_bus_type);
  633. out:
  634. chsc_free_sei_area();
  635. kfree(slow_subchannel_set);
  636. printk(KERN_WARNING"cio: failed to initialize css driver (%d)!\n",
  637. ret);
  638. return ret;
  639. }
  640. int sch_is_pseudo_sch(struct subchannel *sch)
  641. {
  642. return sch == to_css(sch->dev.parent)->pseudo_subchannel;
  643. }
  644. /*
  645. * find a driver for a subchannel. They identify by the subchannel
  646. * type with the exception that the console subchannel driver has its own
  647. * subchannel type although the device is an i/o subchannel
  648. */
  649. static int
  650. css_bus_match (struct device *dev, struct device_driver *drv)
  651. {
  652. struct subchannel *sch = container_of (dev, struct subchannel, dev);
  653. struct css_driver *driver = container_of (drv, struct css_driver, drv);
  654. if (sch->st == driver->subchannel_type)
  655. return 1;
  656. return 0;
  657. }
  658. static int
  659. css_probe (struct device *dev)
  660. {
  661. struct subchannel *sch;
  662. sch = to_subchannel(dev);
  663. sch->driver = container_of (dev->driver, struct css_driver, drv);
  664. return (sch->driver->probe ? sch->driver->probe(sch) : 0);
  665. }
  666. static int
  667. css_remove (struct device *dev)
  668. {
  669. struct subchannel *sch;
  670. sch = to_subchannel(dev);
  671. return (sch->driver->remove ? sch->driver->remove(sch) : 0);
  672. }
  673. static void
  674. css_shutdown (struct device *dev)
  675. {
  676. struct subchannel *sch;
  677. sch = to_subchannel(dev);
  678. if (sch->driver->shutdown)
  679. sch->driver->shutdown(sch);
  680. }
  681. struct bus_type css_bus_type = {
  682. .name = "css",
  683. .match = css_bus_match,
  684. .probe = css_probe,
  685. .remove = css_remove,
  686. .shutdown = css_shutdown,
  687. };
  688. subsys_initcall(init_channel_subsystem);
  689. MODULE_LICENSE("GPL");
  690. EXPORT_SYMBOL(css_bus_type);
  691. EXPORT_SYMBOL_GPL(css_characteristics_avail);