css.c 18 KB

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