css.c 18 KB

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