css.c 19 KB

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