css.c 19 KB

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