css.c 18 KB

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