css.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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 <linux/reboot.h>
  17. #include "css.h"
  18. #include "cio.h"
  19. #include "cio_debug.h"
  20. #include "ioasm.h"
  21. #include "chsc.h"
  22. #include "device.h"
  23. #include "idset.h"
  24. #include "chp.h"
  25. int css_init_done = 0;
  26. static int need_reprobe = 0;
  27. static int max_ssid = 0;
  28. struct channel_subsystem *channel_subsystems[__MAX_CSSID + 1];
  29. int css_characteristics_avail = 0;
  30. int
  31. for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
  32. {
  33. struct subchannel_id schid;
  34. int ret;
  35. init_subchannel_id(&schid);
  36. ret = -ENODEV;
  37. do {
  38. do {
  39. ret = fn(schid, data);
  40. if (ret)
  41. break;
  42. } while (schid.sch_no++ < __MAX_SUBCHANNEL);
  43. schid.sch_no = 0;
  44. } while (schid.ssid++ < max_ssid);
  45. return ret;
  46. }
  47. static struct subchannel *
  48. css_alloc_subchannel(struct subchannel_id schid)
  49. {
  50. struct subchannel *sch;
  51. int ret;
  52. sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA);
  53. if (sch == NULL)
  54. return ERR_PTR(-ENOMEM);
  55. ret = cio_validate_subchannel (sch, schid);
  56. if (ret < 0) {
  57. kfree(sch);
  58. return ERR_PTR(ret);
  59. }
  60. if (sch->st != SUBCHANNEL_TYPE_IO) {
  61. /* For now we ignore all non-io subchannels. */
  62. kfree(sch);
  63. return ERR_PTR(-EINVAL);
  64. }
  65. /*
  66. * Set intparm to subchannel address.
  67. * This is fine even on 64bit since the subchannel is always located
  68. * under 2G.
  69. */
  70. sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
  71. ret = cio_modify(sch);
  72. if (ret) {
  73. kfree(sch->lock);
  74. kfree(sch);
  75. return ERR_PTR(ret);
  76. }
  77. return sch;
  78. }
  79. static void
  80. css_free_subchannel(struct subchannel *sch)
  81. {
  82. if (sch) {
  83. /* Reset intparm to zeroes. */
  84. sch->schib.pmcw.intparm = 0;
  85. cio_modify(sch);
  86. kfree(sch->lock);
  87. kfree(sch);
  88. }
  89. }
  90. static void
  91. css_subchannel_release(struct device *dev)
  92. {
  93. struct subchannel *sch;
  94. sch = to_subchannel(dev);
  95. if (!cio_is_console(sch->schid)) {
  96. kfree(sch->lock);
  97. kfree(sch);
  98. }
  99. }
  100. static int css_sch_device_register(struct subchannel *sch)
  101. {
  102. int ret;
  103. mutex_lock(&sch->reg_mutex);
  104. ret = device_register(&sch->dev);
  105. mutex_unlock(&sch->reg_mutex);
  106. return ret;
  107. }
  108. void css_sch_device_unregister(struct subchannel *sch)
  109. {
  110. mutex_lock(&sch->reg_mutex);
  111. device_unregister(&sch->dev);
  112. mutex_unlock(&sch->reg_mutex);
  113. }
  114. static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
  115. {
  116. int i;
  117. int mask;
  118. memset(ssd, 0, sizeof(struct chsc_ssd_info));
  119. ssd->path_mask = pmcw->pim;
  120. for (i = 0; i < 8; i++) {
  121. mask = 0x80 >> i;
  122. if (pmcw->pim & mask) {
  123. chp_id_init(&ssd->chpid[i]);
  124. ssd->chpid[i].id = pmcw->chpid[i];
  125. }
  126. }
  127. }
  128. static void ssd_register_chpids(struct chsc_ssd_info *ssd)
  129. {
  130. int i;
  131. int mask;
  132. for (i = 0; i < 8; i++) {
  133. mask = 0x80 >> i;
  134. if (ssd->path_mask & mask)
  135. if (!chp_is_registered(ssd->chpid[i]))
  136. chp_new(ssd->chpid[i]);
  137. }
  138. }
  139. void css_update_ssd_info(struct subchannel *sch)
  140. {
  141. int ret;
  142. if (cio_is_console(sch->schid)) {
  143. /* Console is initialized too early for functions requiring
  144. * memory allocation. */
  145. ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
  146. } else {
  147. ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
  148. if (ret)
  149. ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
  150. ssd_register_chpids(&sch->ssd_info);
  151. }
  152. }
  153. static int css_register_subchannel(struct subchannel *sch)
  154. {
  155. int ret;
  156. /* Initialize the subchannel structure */
  157. sch->dev.parent = &channel_subsystems[0]->device;
  158. sch->dev.bus = &css_bus_type;
  159. sch->dev.release = &css_subchannel_release;
  160. sch->dev.groups = subch_attr_groups;
  161. css_update_ssd_info(sch);
  162. /* make it known to the system */
  163. ret = css_sch_device_register(sch);
  164. if (ret) {
  165. CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n",
  166. sch->schid.ssid, sch->schid.sch_no, ret);
  167. return ret;
  168. }
  169. return ret;
  170. }
  171. static int css_probe_device(struct subchannel_id schid)
  172. {
  173. int ret;
  174. struct subchannel *sch;
  175. sch = css_alloc_subchannel(schid);
  176. if (IS_ERR(sch))
  177. return PTR_ERR(sch);
  178. ret = css_register_subchannel(sch);
  179. if (ret)
  180. css_free_subchannel(sch);
  181. return ret;
  182. }
  183. static int
  184. check_subchannel(struct device * dev, void * data)
  185. {
  186. struct subchannel *sch;
  187. struct subchannel_id *schid = data;
  188. sch = to_subchannel(dev);
  189. return schid_equal(&sch->schid, schid);
  190. }
  191. struct subchannel *
  192. get_subchannel_by_schid(struct subchannel_id schid)
  193. {
  194. struct device *dev;
  195. dev = bus_find_device(&css_bus_type, NULL,
  196. &schid, check_subchannel);
  197. return dev ? to_subchannel(dev) : NULL;
  198. }
  199. static int css_get_subchannel_status(struct subchannel *sch)
  200. {
  201. struct schib schib;
  202. if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
  203. return CIO_GONE;
  204. if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
  205. return CIO_REVALIDATE;
  206. if (!sch->lpm)
  207. return CIO_NO_PATH;
  208. return CIO_OPER;
  209. }
  210. static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
  211. {
  212. int event, ret, disc;
  213. unsigned long flags;
  214. enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
  215. spin_lock_irqsave(sch->lock, flags);
  216. disc = device_is_disconnected(sch);
  217. if (disc && slow) {
  218. /* Disconnected devices are evaluated directly only.*/
  219. spin_unlock_irqrestore(sch->lock, flags);
  220. return 0;
  221. }
  222. /* No interrupt after machine check - kill pending timers. */
  223. device_kill_pending_timer(sch);
  224. if (!disc && !slow) {
  225. /* Non-disconnected devices are evaluated on the slow path. */
  226. spin_unlock_irqrestore(sch->lock, flags);
  227. return -EAGAIN;
  228. }
  229. event = css_get_subchannel_status(sch);
  230. CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
  231. sch->schid.ssid, sch->schid.sch_no, event,
  232. disc ? "disconnected" : "normal",
  233. slow ? "slow" : "fast");
  234. /* Analyze subchannel status. */
  235. action = NONE;
  236. switch (event) {
  237. case CIO_NO_PATH:
  238. if (disc) {
  239. /* Check if paths have become available. */
  240. action = REPROBE;
  241. break;
  242. }
  243. /* fall through */
  244. case CIO_GONE:
  245. /* Prevent unwanted effects when opening lock. */
  246. cio_disable_subchannel(sch);
  247. device_set_disconnected(sch);
  248. /* Ask driver what to do with device. */
  249. action = UNREGISTER;
  250. if (sch->driver && sch->driver->notify) {
  251. spin_unlock_irqrestore(sch->lock, flags);
  252. ret = sch->driver->notify(&sch->dev, event);
  253. spin_lock_irqsave(sch->lock, flags);
  254. if (ret)
  255. action = NONE;
  256. }
  257. break;
  258. case CIO_REVALIDATE:
  259. /* Device will be removed, so no notify necessary. */
  260. if (disc)
  261. /* Reprobe because immediate unregister might block. */
  262. action = REPROBE;
  263. else
  264. action = UNREGISTER_PROBE;
  265. break;
  266. case CIO_OPER:
  267. if (disc)
  268. /* Get device operational again. */
  269. action = REPROBE;
  270. break;
  271. }
  272. /* Perform action. */
  273. ret = 0;
  274. switch (action) {
  275. case UNREGISTER:
  276. case UNREGISTER_PROBE:
  277. /* Unregister device (will use subchannel lock). */
  278. spin_unlock_irqrestore(sch->lock, flags);
  279. css_sch_device_unregister(sch);
  280. spin_lock_irqsave(sch->lock, flags);
  281. /* Reset intparm to zeroes. */
  282. sch->schib.pmcw.intparm = 0;
  283. cio_modify(sch);
  284. break;
  285. case REPROBE:
  286. device_trigger_reprobe(sch);
  287. break;
  288. default:
  289. break;
  290. }
  291. spin_unlock_irqrestore(sch->lock, flags);
  292. /* Probe if necessary. */
  293. if (action == UNREGISTER_PROBE)
  294. ret = css_probe_device(sch->schid);
  295. return ret;
  296. }
  297. static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
  298. {
  299. struct schib schib;
  300. if (!slow) {
  301. /* Will be done on the slow path. */
  302. return -EAGAIN;
  303. }
  304. if (stsch_err(schid, &schib) || !schib.pmcw.dnv) {
  305. /* Unusable - ignore. */
  306. return 0;
  307. }
  308. CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, "
  309. "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER);
  310. return css_probe_device(schid);
  311. }
  312. static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
  313. {
  314. struct subchannel *sch;
  315. int ret;
  316. sch = get_subchannel_by_schid(schid);
  317. if (sch) {
  318. ret = css_evaluate_known_subchannel(sch, slow);
  319. put_device(&sch->dev);
  320. } else
  321. ret = css_evaluate_new_subchannel(schid, slow);
  322. if (ret == -EAGAIN)
  323. css_schedule_eval(schid);
  324. }
  325. static struct idset *slow_subchannel_set;
  326. static spinlock_t slow_subchannel_lock;
  327. static int __init slow_subchannel_init(void)
  328. {
  329. spin_lock_init(&slow_subchannel_lock);
  330. slow_subchannel_set = idset_sch_new();
  331. if (!slow_subchannel_set) {
  332. CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n");
  333. return -ENOMEM;
  334. }
  335. return 0;
  336. }
  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_MSG_EVENT(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. struct channel_subsystem *css;
  533. css = channel_subsystems[nr];
  534. memset(css, 0, sizeof(struct channel_subsystem));
  535. css->pseudo_subchannel =
  536. kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL);
  537. if (!css->pseudo_subchannel)
  538. return -ENOMEM;
  539. css->pseudo_subchannel->dev.parent = &css->device;
  540. css->pseudo_subchannel->dev.release = css_subchannel_release;
  541. sprintf(css->pseudo_subchannel->dev.bus_id, "defunct");
  542. ret = cio_create_sch_lock(css->pseudo_subchannel);
  543. if (ret) {
  544. kfree(css->pseudo_subchannel);
  545. return ret;
  546. }
  547. mutex_init(&css->mutex);
  548. css->valid = 1;
  549. css->cssid = nr;
  550. sprintf(css->device.bus_id, "css%x", nr);
  551. css->device.release = channel_subsystem_release;
  552. tod_high = (u32) (get_clock() >> 32);
  553. css_generate_pgid(css, tod_high);
  554. return 0;
  555. }
  556. static int css_reboot_event(struct notifier_block *this,
  557. unsigned long event,
  558. void *ptr)
  559. {
  560. int ret, i;
  561. ret = NOTIFY_DONE;
  562. for (i = 0; i <= __MAX_CSSID; i++) {
  563. struct channel_subsystem *css;
  564. css = channel_subsystems[i];
  565. if (css->cm_enabled)
  566. if (chsc_secm(css, 0))
  567. ret = NOTIFY_BAD;
  568. }
  569. return ret;
  570. }
  571. static struct notifier_block css_reboot_notifier = {
  572. .notifier_call = css_reboot_event,
  573. };
  574. /*
  575. * Now that the driver core is running, we can setup our channel subsystem.
  576. * The struct subchannel's are created during probing (except for the
  577. * static console subchannel).
  578. */
  579. static int __init
  580. init_channel_subsystem (void)
  581. {
  582. int ret, i;
  583. ret = chsc_determine_css_characteristics();
  584. if (ret == -ENOMEM)
  585. goto out; /* No need to continue. */
  586. if (ret == 0)
  587. css_characteristics_avail = 1;
  588. ret = chsc_alloc_sei_area();
  589. if (ret)
  590. goto out;
  591. ret = slow_subchannel_init();
  592. if (ret)
  593. goto out;
  594. if ((ret = bus_register(&css_bus_type)))
  595. goto out;
  596. /* Try to enable MSS. */
  597. ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
  598. switch (ret) {
  599. case 0: /* Success. */
  600. max_ssid = __MAX_SSID;
  601. break;
  602. case -ENOMEM:
  603. goto out_bus;
  604. default:
  605. max_ssid = 0;
  606. }
  607. /* Setup css structure. */
  608. for (i = 0; i <= __MAX_CSSID; i++) {
  609. struct channel_subsystem *css;
  610. css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
  611. if (!css) {
  612. ret = -ENOMEM;
  613. goto out_unregister;
  614. }
  615. channel_subsystems[i] = css;
  616. ret = setup_css(i);
  617. if (ret)
  618. goto out_free;
  619. ret = device_register(&css->device);
  620. if (ret)
  621. goto out_free_all;
  622. if (css_characteristics_avail &&
  623. css_chsc_characteristics.secm) {
  624. ret = device_create_file(&css->device,
  625. &dev_attr_cm_enable);
  626. if (ret)
  627. goto out_device;
  628. }
  629. ret = device_register(&css->pseudo_subchannel->dev);
  630. if (ret)
  631. goto out_file;
  632. }
  633. ret = register_reboot_notifier(&css_reboot_notifier);
  634. if (ret)
  635. goto out_pseudo;
  636. css_init_done = 1;
  637. ctl_set_bit(6, 28);
  638. for_each_subchannel(__init_channel_subsystem, NULL);
  639. return 0;
  640. out_pseudo:
  641. device_unregister(&channel_subsystems[i]->pseudo_subchannel->dev);
  642. out_file:
  643. device_remove_file(&channel_subsystems[i]->device,
  644. &dev_attr_cm_enable);
  645. out_device:
  646. device_unregister(&channel_subsystems[i]->device);
  647. out_free_all:
  648. kfree(channel_subsystems[i]->pseudo_subchannel->lock);
  649. kfree(channel_subsystems[i]->pseudo_subchannel);
  650. out_free:
  651. kfree(channel_subsystems[i]);
  652. out_unregister:
  653. while (i > 0) {
  654. struct channel_subsystem *css;
  655. i--;
  656. css = channel_subsystems[i];
  657. device_unregister(&css->pseudo_subchannel->dev);
  658. if (css_characteristics_avail && css_chsc_characteristics.secm)
  659. device_remove_file(&css->device,
  660. &dev_attr_cm_enable);
  661. device_unregister(&css->device);
  662. }
  663. out_bus:
  664. bus_unregister(&css_bus_type);
  665. out:
  666. chsc_free_sei_area();
  667. kfree(slow_subchannel_set);
  668. printk(KERN_WARNING"cio: failed to initialize css driver (%d)!\n",
  669. ret);
  670. return ret;
  671. }
  672. int sch_is_pseudo_sch(struct subchannel *sch)
  673. {
  674. return sch == to_css(sch->dev.parent)->pseudo_subchannel;
  675. }
  676. /*
  677. * find a driver for a subchannel. They identify by the subchannel
  678. * type with the exception that the console subchannel driver has its own
  679. * subchannel type although the device is an i/o subchannel
  680. */
  681. static int
  682. css_bus_match (struct device *dev, struct device_driver *drv)
  683. {
  684. struct subchannel *sch = container_of (dev, struct subchannel, dev);
  685. struct css_driver *driver = container_of (drv, struct css_driver, drv);
  686. if (sch->st == driver->subchannel_type)
  687. return 1;
  688. return 0;
  689. }
  690. static int
  691. css_probe (struct device *dev)
  692. {
  693. struct subchannel *sch;
  694. sch = to_subchannel(dev);
  695. sch->driver = container_of (dev->driver, struct css_driver, drv);
  696. return (sch->driver->probe ? sch->driver->probe(sch) : 0);
  697. }
  698. static int
  699. css_remove (struct device *dev)
  700. {
  701. struct subchannel *sch;
  702. sch = to_subchannel(dev);
  703. return (sch->driver->remove ? sch->driver->remove(sch) : 0);
  704. }
  705. static void
  706. css_shutdown (struct device *dev)
  707. {
  708. struct subchannel *sch;
  709. sch = to_subchannel(dev);
  710. if (sch->driver->shutdown)
  711. sch->driver->shutdown(sch);
  712. }
  713. struct bus_type css_bus_type = {
  714. .name = "css",
  715. .match = css_bus_match,
  716. .probe = css_probe,
  717. .remove = css_remove,
  718. .shutdown = css_shutdown,
  719. };
  720. subsys_initcall(init_channel_subsystem);
  721. MODULE_LICENSE("GPL");
  722. EXPORT_SYMBOL(css_bus_type);
  723. EXPORT_SYMBOL_GPL(css_characteristics_avail);