device.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  1. /*
  2. * drivers/s390/cio/device.c
  3. * bus driver for ccw devices
  4. *
  5. * Copyright IBM Corp. 2002,2008
  6. * Author(s): Arnd Bergmann (arndb@de.ibm.com)
  7. * Cornelia Huck (cornelia.huck@de.ibm.com)
  8. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  9. */
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/errno.h>
  14. #include <linux/err.h>
  15. #include <linux/slab.h>
  16. #include <linux/list.h>
  17. #include <linux/device.h>
  18. #include <linux/workqueue.h>
  19. #include <linux/timer.h>
  20. #include <asm/ccwdev.h>
  21. #include <asm/cio.h>
  22. #include <asm/param.h> /* HZ */
  23. #include <asm/cmb.h>
  24. #include <asm/isc.h>
  25. #include "chp.h"
  26. #include "cio.h"
  27. #include "cio_debug.h"
  28. #include "css.h"
  29. #include "device.h"
  30. #include "ioasm.h"
  31. #include "io_sch.h"
  32. #include "blacklist.h"
  33. static struct timer_list recovery_timer;
  34. static DEFINE_SPINLOCK(recovery_lock);
  35. static int recovery_phase;
  36. static const unsigned long recovery_delay[] = { 3, 30, 300 };
  37. /******************* bus type handling ***********************/
  38. /* The Linux driver model distinguishes between a bus type and
  39. * the bus itself. Of course we only have one channel
  40. * subsystem driver and one channel system per machine, but
  41. * we still use the abstraction. T.R. says it's a good idea. */
  42. static int
  43. ccw_bus_match (struct device * dev, struct device_driver * drv)
  44. {
  45. struct ccw_device *cdev = to_ccwdev(dev);
  46. struct ccw_driver *cdrv = to_ccwdrv(drv);
  47. const struct ccw_device_id *ids = cdrv->ids, *found;
  48. if (!ids)
  49. return 0;
  50. found = ccw_device_id_match(ids, &cdev->id);
  51. if (!found)
  52. return 0;
  53. cdev->id.driver_info = found->driver_info;
  54. return 1;
  55. }
  56. /* Store modalias string delimited by prefix/suffix string into buffer with
  57. * specified size. Return length of resulting string (excluding trailing '\0')
  58. * even if string doesn't fit buffer (snprintf semantics). */
  59. static int snprint_alias(char *buf, size_t size,
  60. struct ccw_device_id *id, const char *suffix)
  61. {
  62. int len;
  63. len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model);
  64. if (len > size)
  65. return len;
  66. buf += len;
  67. size -= len;
  68. if (id->dev_type != 0)
  69. len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type,
  70. id->dev_model, suffix);
  71. else
  72. len += snprintf(buf, size, "dtdm%s", suffix);
  73. return len;
  74. }
  75. /* Set up environment variables for ccw device uevent. Return 0 on success,
  76. * non-zero otherwise. */
  77. static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env)
  78. {
  79. struct ccw_device *cdev = to_ccwdev(dev);
  80. struct ccw_device_id *id = &(cdev->id);
  81. int ret;
  82. char modalias_buf[30];
  83. /* CU_TYPE= */
  84. ret = add_uevent_var(env, "CU_TYPE=%04X", id->cu_type);
  85. if (ret)
  86. return ret;
  87. /* CU_MODEL= */
  88. ret = add_uevent_var(env, "CU_MODEL=%02X", id->cu_model);
  89. if (ret)
  90. return ret;
  91. /* The next two can be zero, that's ok for us */
  92. /* DEV_TYPE= */
  93. ret = add_uevent_var(env, "DEV_TYPE=%04X", id->dev_type);
  94. if (ret)
  95. return ret;
  96. /* DEV_MODEL= */
  97. ret = add_uevent_var(env, "DEV_MODEL=%02X", id->dev_model);
  98. if (ret)
  99. return ret;
  100. /* MODALIAS= */
  101. snprint_alias(modalias_buf, sizeof(modalias_buf), id, "");
  102. ret = add_uevent_var(env, "MODALIAS=%s", modalias_buf);
  103. return ret;
  104. }
  105. struct bus_type ccw_bus_type;
  106. static void io_subchannel_irq(struct subchannel *);
  107. static int io_subchannel_probe(struct subchannel *);
  108. static int io_subchannel_remove(struct subchannel *);
  109. static void io_subchannel_shutdown(struct subchannel *);
  110. static int io_subchannel_sch_event(struct subchannel *, int);
  111. static int io_subchannel_chp_event(struct subchannel *, struct chp_link *,
  112. int);
  113. static struct css_device_id io_subchannel_ids[] = {
  114. { .match_flags = 0x1, .type = SUBCHANNEL_TYPE_IO, },
  115. { /* end of list */ },
  116. };
  117. MODULE_DEVICE_TABLE(css, io_subchannel_ids);
  118. static struct css_driver io_subchannel_driver = {
  119. .owner = THIS_MODULE,
  120. .subchannel_type = io_subchannel_ids,
  121. .name = "io_subchannel",
  122. .irq = io_subchannel_irq,
  123. .sch_event = io_subchannel_sch_event,
  124. .chp_event = io_subchannel_chp_event,
  125. .probe = io_subchannel_probe,
  126. .remove = io_subchannel_remove,
  127. .shutdown = io_subchannel_shutdown,
  128. };
  129. struct workqueue_struct *ccw_device_work;
  130. wait_queue_head_t ccw_device_init_wq;
  131. atomic_t ccw_device_init_count;
  132. static void recovery_func(unsigned long data);
  133. static int __init
  134. init_ccw_bus_type (void)
  135. {
  136. int ret;
  137. init_waitqueue_head(&ccw_device_init_wq);
  138. atomic_set(&ccw_device_init_count, 0);
  139. setup_timer(&recovery_timer, recovery_func, 0);
  140. ccw_device_work = create_singlethread_workqueue("cio");
  141. if (!ccw_device_work)
  142. return -ENOMEM; /* FIXME: better errno ? */
  143. slow_path_wq = create_singlethread_workqueue("kslowcrw");
  144. if (!slow_path_wq) {
  145. ret = -ENOMEM; /* FIXME: better errno ? */
  146. goto out_err;
  147. }
  148. if ((ret = bus_register (&ccw_bus_type)))
  149. goto out_err;
  150. ret = css_driver_register(&io_subchannel_driver);
  151. if (ret)
  152. goto out_err;
  153. wait_event(ccw_device_init_wq,
  154. atomic_read(&ccw_device_init_count) == 0);
  155. flush_workqueue(ccw_device_work);
  156. return 0;
  157. out_err:
  158. if (ccw_device_work)
  159. destroy_workqueue(ccw_device_work);
  160. if (slow_path_wq)
  161. destroy_workqueue(slow_path_wq);
  162. return ret;
  163. }
  164. static void __exit
  165. cleanup_ccw_bus_type (void)
  166. {
  167. css_driver_unregister(&io_subchannel_driver);
  168. bus_unregister(&ccw_bus_type);
  169. destroy_workqueue(ccw_device_work);
  170. }
  171. subsys_initcall(init_ccw_bus_type);
  172. module_exit(cleanup_ccw_bus_type);
  173. /************************ device handling **************************/
  174. /*
  175. * A ccw_device has some interfaces in sysfs in addition to the
  176. * standard ones.
  177. * The following entries are designed to export the information which
  178. * resided in 2.4 in /proc/subchannels. Subchannel and device number
  179. * are obvious, so they don't have an entry :)
  180. * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
  181. */
  182. static ssize_t
  183. chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
  184. {
  185. struct subchannel *sch = to_subchannel(dev);
  186. struct chsc_ssd_info *ssd = &sch->ssd_info;
  187. ssize_t ret = 0;
  188. int chp;
  189. int mask;
  190. for (chp = 0; chp < 8; chp++) {
  191. mask = 0x80 >> chp;
  192. if (ssd->path_mask & mask)
  193. ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
  194. else
  195. ret += sprintf(buf + ret, "00 ");
  196. }
  197. ret += sprintf (buf+ret, "\n");
  198. return min((ssize_t)PAGE_SIZE, ret);
  199. }
  200. static ssize_t
  201. pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
  202. {
  203. struct subchannel *sch = to_subchannel(dev);
  204. struct pmcw *pmcw = &sch->schib.pmcw;
  205. return sprintf (buf, "%02x %02x %02x\n",
  206. pmcw->pim, pmcw->pam, pmcw->pom);
  207. }
  208. static ssize_t
  209. devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
  210. {
  211. struct ccw_device *cdev = to_ccwdev(dev);
  212. struct ccw_device_id *id = &(cdev->id);
  213. if (id->dev_type != 0)
  214. return sprintf(buf, "%04x/%02x\n",
  215. id->dev_type, id->dev_model);
  216. else
  217. return sprintf(buf, "n/a\n");
  218. }
  219. static ssize_t
  220. cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
  221. {
  222. struct ccw_device *cdev = to_ccwdev(dev);
  223. struct ccw_device_id *id = &(cdev->id);
  224. return sprintf(buf, "%04x/%02x\n",
  225. id->cu_type, id->cu_model);
  226. }
  227. static ssize_t
  228. modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
  229. {
  230. struct ccw_device *cdev = to_ccwdev(dev);
  231. struct ccw_device_id *id = &(cdev->id);
  232. int len;
  233. len = snprint_alias(buf, PAGE_SIZE, id, "\n");
  234. return len > PAGE_SIZE ? PAGE_SIZE : len;
  235. }
  236. static ssize_t
  237. online_show (struct device *dev, struct device_attribute *attr, char *buf)
  238. {
  239. struct ccw_device *cdev = to_ccwdev(dev);
  240. return sprintf(buf, cdev->online ? "1\n" : "0\n");
  241. }
  242. int ccw_device_is_orphan(struct ccw_device *cdev)
  243. {
  244. return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
  245. }
  246. static void ccw_device_unregister(struct ccw_device *cdev)
  247. {
  248. if (test_and_clear_bit(1, &cdev->private->registered))
  249. device_del(&cdev->dev);
  250. }
  251. static void ccw_device_remove_orphan_cb(struct work_struct *work)
  252. {
  253. struct ccw_device_private *priv;
  254. struct ccw_device *cdev;
  255. priv = container_of(work, struct ccw_device_private, kick_work);
  256. cdev = priv->cdev;
  257. ccw_device_unregister(cdev);
  258. put_device(&cdev->dev);
  259. /* Release cdev reference for workqueue processing. */
  260. put_device(&cdev->dev);
  261. }
  262. static void ccw_device_call_sch_unregister(struct work_struct *work);
  263. static void
  264. ccw_device_remove_disconnected(struct ccw_device *cdev)
  265. {
  266. unsigned long flags;
  267. /*
  268. * Forced offline in disconnected state means
  269. * 'throw away device'.
  270. */
  271. /* Get cdev reference for workqueue processing. */
  272. if (!get_device(&cdev->dev))
  273. return;
  274. if (ccw_device_is_orphan(cdev)) {
  275. /*
  276. * Deregister ccw device.
  277. * Unfortunately, we cannot do this directly from the
  278. * attribute method.
  279. */
  280. spin_lock_irqsave(cdev->ccwlock, flags);
  281. cdev->private->state = DEV_STATE_NOT_OPER;
  282. spin_unlock_irqrestore(cdev->ccwlock, flags);
  283. PREPARE_WORK(&cdev->private->kick_work,
  284. ccw_device_remove_orphan_cb);
  285. } else
  286. /* Deregister subchannel, which will kill the ccw device. */
  287. PREPARE_WORK(&cdev->private->kick_work,
  288. ccw_device_call_sch_unregister);
  289. queue_work(slow_path_wq, &cdev->private->kick_work);
  290. }
  291. /**
  292. * ccw_device_set_offline() - disable a ccw device for I/O
  293. * @cdev: target ccw device
  294. *
  295. * This function calls the driver's set_offline() function for @cdev, if
  296. * given, and then disables @cdev.
  297. * Returns:
  298. * %0 on success and a negative error value on failure.
  299. * Context:
  300. * enabled, ccw device lock not held
  301. */
  302. int ccw_device_set_offline(struct ccw_device *cdev)
  303. {
  304. int ret;
  305. if (!cdev)
  306. return -ENODEV;
  307. if (!cdev->online || !cdev->drv)
  308. return -EINVAL;
  309. if (cdev->drv->set_offline) {
  310. ret = cdev->drv->set_offline(cdev);
  311. if (ret != 0)
  312. return ret;
  313. }
  314. cdev->online = 0;
  315. spin_lock_irq(cdev->ccwlock);
  316. ret = ccw_device_offline(cdev);
  317. if (ret == -ENODEV) {
  318. if (cdev->private->state != DEV_STATE_NOT_OPER) {
  319. cdev->private->state = DEV_STATE_OFFLINE;
  320. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  321. }
  322. spin_unlock_irq(cdev->ccwlock);
  323. return ret;
  324. }
  325. spin_unlock_irq(cdev->ccwlock);
  326. if (ret == 0)
  327. wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
  328. else {
  329. CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
  330. "device 0.%x.%04x\n",
  331. ret, cdev->private->dev_id.ssid,
  332. cdev->private->dev_id.devno);
  333. cdev->online = 1;
  334. }
  335. return ret;
  336. }
  337. /**
  338. * ccw_device_set_online() - enable a ccw device for I/O
  339. * @cdev: target ccw device
  340. *
  341. * This function first enables @cdev and then calls the driver's set_online()
  342. * function for @cdev, if given. If set_online() returns an error, @cdev is
  343. * disabled again.
  344. * Returns:
  345. * %0 on success and a negative error value on failure.
  346. * Context:
  347. * enabled, ccw device lock not held
  348. */
  349. int ccw_device_set_online(struct ccw_device *cdev)
  350. {
  351. int ret;
  352. if (!cdev)
  353. return -ENODEV;
  354. if (cdev->online || !cdev->drv)
  355. return -EINVAL;
  356. spin_lock_irq(cdev->ccwlock);
  357. ret = ccw_device_online(cdev);
  358. spin_unlock_irq(cdev->ccwlock);
  359. if (ret == 0)
  360. wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
  361. else {
  362. CIO_MSG_EVENT(0, "ccw_device_online returned %d, "
  363. "device 0.%x.%04x\n",
  364. ret, cdev->private->dev_id.ssid,
  365. cdev->private->dev_id.devno);
  366. return ret;
  367. }
  368. if (cdev->private->state != DEV_STATE_ONLINE)
  369. return -ENODEV;
  370. if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
  371. cdev->online = 1;
  372. return 0;
  373. }
  374. spin_lock_irq(cdev->ccwlock);
  375. ret = ccw_device_offline(cdev);
  376. spin_unlock_irq(cdev->ccwlock);
  377. if (ret == 0)
  378. wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
  379. else
  380. CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
  381. "device 0.%x.%04x\n",
  382. ret, cdev->private->dev_id.ssid,
  383. cdev->private->dev_id.devno);
  384. return (ret == 0) ? -ENODEV : ret;
  385. }
  386. static void online_store_handle_offline(struct ccw_device *cdev)
  387. {
  388. if (cdev->private->state == DEV_STATE_DISCONNECTED)
  389. ccw_device_remove_disconnected(cdev);
  390. else if (cdev->drv && cdev->drv->set_offline)
  391. ccw_device_set_offline(cdev);
  392. }
  393. static int online_store_recog_and_online(struct ccw_device *cdev)
  394. {
  395. int ret;
  396. /* Do device recognition, if needed. */
  397. if (cdev->id.cu_type == 0) {
  398. ret = ccw_device_recognition(cdev);
  399. if (ret) {
  400. CIO_MSG_EVENT(0, "Couldn't start recognition "
  401. "for device 0.%x.%04x (ret=%d)\n",
  402. cdev->private->dev_id.ssid,
  403. cdev->private->dev_id.devno, ret);
  404. return ret;
  405. }
  406. wait_event(cdev->private->wait_q,
  407. cdev->private->flags.recog_done);
  408. }
  409. if (cdev->drv && cdev->drv->set_online)
  410. ccw_device_set_online(cdev);
  411. return 0;
  412. }
  413. static int online_store_handle_online(struct ccw_device *cdev, int force)
  414. {
  415. int ret;
  416. ret = online_store_recog_and_online(cdev);
  417. if (ret)
  418. return ret;
  419. if (force && cdev->private->state == DEV_STATE_BOXED) {
  420. ret = ccw_device_stlck(cdev);
  421. if (ret)
  422. return ret;
  423. if (cdev->id.cu_type == 0)
  424. cdev->private->state = DEV_STATE_NOT_OPER;
  425. online_store_recog_and_online(cdev);
  426. }
  427. return 0;
  428. }
  429. static ssize_t online_store (struct device *dev, struct device_attribute *attr,
  430. const char *buf, size_t count)
  431. {
  432. struct ccw_device *cdev = to_ccwdev(dev);
  433. int force, ret;
  434. unsigned long i;
  435. if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
  436. return -EAGAIN;
  437. if (cdev->drv && !try_module_get(cdev->drv->owner)) {
  438. atomic_set(&cdev->private->onoff, 0);
  439. return -EINVAL;
  440. }
  441. if (!strncmp(buf, "force\n", count)) {
  442. force = 1;
  443. i = 1;
  444. ret = 0;
  445. } else {
  446. force = 0;
  447. ret = strict_strtoul(buf, 16, &i);
  448. }
  449. if (ret)
  450. goto out;
  451. switch (i) {
  452. case 0:
  453. online_store_handle_offline(cdev);
  454. ret = count;
  455. break;
  456. case 1:
  457. ret = online_store_handle_online(cdev, force);
  458. if (!ret)
  459. ret = count;
  460. break;
  461. default:
  462. ret = -EINVAL;
  463. }
  464. out:
  465. if (cdev->drv)
  466. module_put(cdev->drv->owner);
  467. atomic_set(&cdev->private->onoff, 0);
  468. return ret;
  469. }
  470. static ssize_t
  471. available_show (struct device *dev, struct device_attribute *attr, char *buf)
  472. {
  473. struct ccw_device *cdev = to_ccwdev(dev);
  474. struct subchannel *sch;
  475. if (ccw_device_is_orphan(cdev))
  476. return sprintf(buf, "no device\n");
  477. switch (cdev->private->state) {
  478. case DEV_STATE_BOXED:
  479. return sprintf(buf, "boxed\n");
  480. case DEV_STATE_DISCONNECTED:
  481. case DEV_STATE_DISCONNECTED_SENSE_ID:
  482. case DEV_STATE_NOT_OPER:
  483. sch = to_subchannel(dev->parent);
  484. if (!sch->lpm)
  485. return sprintf(buf, "no path\n");
  486. else
  487. return sprintf(buf, "no device\n");
  488. default:
  489. /* All other states considered fine. */
  490. return sprintf(buf, "good\n");
  491. }
  492. }
  493. static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
  494. static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
  495. static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
  496. static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
  497. static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
  498. static DEVICE_ATTR(online, 0644, online_show, online_store);
  499. static DEVICE_ATTR(availability, 0444, available_show, NULL);
  500. static struct attribute *io_subchannel_attrs[] = {
  501. &dev_attr_chpids.attr,
  502. &dev_attr_pimpampom.attr,
  503. NULL,
  504. };
  505. static struct attribute_group io_subchannel_attr_group = {
  506. .attrs = io_subchannel_attrs,
  507. };
  508. static struct attribute * ccwdev_attrs[] = {
  509. &dev_attr_devtype.attr,
  510. &dev_attr_cutype.attr,
  511. &dev_attr_modalias.attr,
  512. &dev_attr_online.attr,
  513. &dev_attr_cmb_enable.attr,
  514. &dev_attr_availability.attr,
  515. NULL,
  516. };
  517. static struct attribute_group ccwdev_attr_group = {
  518. .attrs = ccwdev_attrs,
  519. };
  520. static struct attribute_group *ccwdev_attr_groups[] = {
  521. &ccwdev_attr_group,
  522. NULL,
  523. };
  524. /* this is a simple abstraction for device_register that sets the
  525. * correct bus type and adds the bus specific files */
  526. static int ccw_device_register(struct ccw_device *cdev)
  527. {
  528. struct device *dev = &cdev->dev;
  529. int ret;
  530. dev->bus = &ccw_bus_type;
  531. if ((ret = device_add(dev)))
  532. return ret;
  533. set_bit(1, &cdev->private->registered);
  534. return ret;
  535. }
  536. struct match_data {
  537. struct ccw_dev_id dev_id;
  538. struct ccw_device * sibling;
  539. };
  540. static int
  541. match_devno(struct device * dev, void * data)
  542. {
  543. struct match_data * d = data;
  544. struct ccw_device * cdev;
  545. cdev = to_ccwdev(dev);
  546. if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
  547. !ccw_device_is_orphan(cdev) &&
  548. ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) &&
  549. (cdev != d->sibling))
  550. return 1;
  551. return 0;
  552. }
  553. static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id,
  554. struct ccw_device *sibling)
  555. {
  556. struct device *dev;
  557. struct match_data data;
  558. data.dev_id = *dev_id;
  559. data.sibling = sibling;
  560. dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
  561. return dev ? to_ccwdev(dev) : NULL;
  562. }
  563. static int match_orphan(struct device *dev, void *data)
  564. {
  565. struct ccw_dev_id *dev_id;
  566. struct ccw_device *cdev;
  567. dev_id = data;
  568. cdev = to_ccwdev(dev);
  569. return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
  570. }
  571. static struct ccw_device *
  572. get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css,
  573. struct ccw_dev_id *dev_id)
  574. {
  575. struct device *dev;
  576. dev = device_find_child(&css->pseudo_subchannel->dev, dev_id,
  577. match_orphan);
  578. return dev ? to_ccwdev(dev) : NULL;
  579. }
  580. static void
  581. ccw_device_add_changed(struct work_struct *work)
  582. {
  583. struct ccw_device_private *priv;
  584. struct ccw_device *cdev;
  585. priv = container_of(work, struct ccw_device_private, kick_work);
  586. cdev = priv->cdev;
  587. if (device_add(&cdev->dev)) {
  588. put_device(&cdev->dev);
  589. return;
  590. }
  591. set_bit(1, &cdev->private->registered);
  592. }
  593. void ccw_device_do_unreg_rereg(struct work_struct *work)
  594. {
  595. struct ccw_device_private *priv;
  596. struct ccw_device *cdev;
  597. struct subchannel *sch;
  598. priv = container_of(work, struct ccw_device_private, kick_work);
  599. cdev = priv->cdev;
  600. sch = to_subchannel(cdev->dev.parent);
  601. ccw_device_unregister(cdev);
  602. PREPARE_WORK(&cdev->private->kick_work,
  603. ccw_device_add_changed);
  604. queue_work(ccw_device_work, &cdev->private->kick_work);
  605. }
  606. static void
  607. ccw_device_release(struct device *dev)
  608. {
  609. struct ccw_device *cdev;
  610. cdev = to_ccwdev(dev);
  611. kfree(cdev->private);
  612. kfree(cdev);
  613. }
  614. static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
  615. {
  616. struct ccw_device *cdev;
  617. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  618. if (cdev) {
  619. cdev->private = kzalloc(sizeof(struct ccw_device_private),
  620. GFP_KERNEL | GFP_DMA);
  621. if (cdev->private)
  622. return cdev;
  623. }
  624. kfree(cdev);
  625. return ERR_PTR(-ENOMEM);
  626. }
  627. static int io_subchannel_initialize_dev(struct subchannel *sch,
  628. struct ccw_device *cdev)
  629. {
  630. cdev->private->cdev = cdev;
  631. atomic_set(&cdev->private->onoff, 0);
  632. cdev->dev.parent = &sch->dev;
  633. cdev->dev.release = ccw_device_release;
  634. INIT_WORK(&cdev->private->kick_work, NULL);
  635. cdev->dev.groups = ccwdev_attr_groups;
  636. /* Do first half of device_register. */
  637. device_initialize(&cdev->dev);
  638. if (!get_device(&sch->dev)) {
  639. if (cdev->dev.release)
  640. cdev->dev.release(&cdev->dev);
  641. return -ENODEV;
  642. }
  643. return 0;
  644. }
  645. static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
  646. {
  647. struct ccw_device *cdev;
  648. int ret;
  649. cdev = io_subchannel_allocate_dev(sch);
  650. if (!IS_ERR(cdev)) {
  651. ret = io_subchannel_initialize_dev(sch, cdev);
  652. if (ret) {
  653. kfree(cdev);
  654. cdev = ERR_PTR(ret);
  655. }
  656. }
  657. return cdev;
  658. }
  659. static int io_subchannel_recog(struct ccw_device *, struct subchannel *);
  660. static void sch_attach_device(struct subchannel *sch,
  661. struct ccw_device *cdev)
  662. {
  663. css_update_ssd_info(sch);
  664. spin_lock_irq(sch->lock);
  665. sch_set_cdev(sch, cdev);
  666. cdev->private->schid = sch->schid;
  667. cdev->ccwlock = sch->lock;
  668. ccw_device_trigger_reprobe(cdev);
  669. spin_unlock_irq(sch->lock);
  670. }
  671. static void sch_attach_disconnected_device(struct subchannel *sch,
  672. struct ccw_device *cdev)
  673. {
  674. struct subchannel *other_sch;
  675. int ret;
  676. other_sch = to_subchannel(get_device(cdev->dev.parent));
  677. ret = device_move(&cdev->dev, &sch->dev);
  678. if (ret) {
  679. CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed "
  680. "(ret=%d)!\n", cdev->private->dev_id.ssid,
  681. cdev->private->dev_id.devno, ret);
  682. put_device(&other_sch->dev);
  683. return;
  684. }
  685. sch_set_cdev(other_sch, NULL);
  686. /* No need to keep a subchannel without ccw device around. */
  687. css_sch_device_unregister(other_sch);
  688. put_device(&other_sch->dev);
  689. sch_attach_device(sch, cdev);
  690. }
  691. static void sch_attach_orphaned_device(struct subchannel *sch,
  692. struct ccw_device *cdev)
  693. {
  694. int ret;
  695. /* Try to move the ccw device to its new subchannel. */
  696. ret = device_move(&cdev->dev, &sch->dev);
  697. if (ret) {
  698. CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
  699. "failed (ret=%d)!\n",
  700. cdev->private->dev_id.ssid,
  701. cdev->private->dev_id.devno, ret);
  702. return;
  703. }
  704. sch_attach_device(sch, cdev);
  705. }
  706. static void sch_create_and_recog_new_device(struct subchannel *sch)
  707. {
  708. struct ccw_device *cdev;
  709. /* Need to allocate a new ccw device. */
  710. cdev = io_subchannel_create_ccwdev(sch);
  711. if (IS_ERR(cdev)) {
  712. /* OK, we did everything we could... */
  713. css_sch_device_unregister(sch);
  714. return;
  715. }
  716. spin_lock_irq(sch->lock);
  717. sch_set_cdev(sch, cdev);
  718. spin_unlock_irq(sch->lock);
  719. /* Start recognition for the new ccw device. */
  720. if (io_subchannel_recog(cdev, sch)) {
  721. spin_lock_irq(sch->lock);
  722. sch_set_cdev(sch, NULL);
  723. spin_unlock_irq(sch->lock);
  724. if (cdev->dev.release)
  725. cdev->dev.release(&cdev->dev);
  726. css_sch_device_unregister(sch);
  727. }
  728. }
  729. void ccw_device_move_to_orphanage(struct work_struct *work)
  730. {
  731. struct ccw_device_private *priv;
  732. struct ccw_device *cdev;
  733. struct ccw_device *replacing_cdev;
  734. struct subchannel *sch;
  735. int ret;
  736. struct channel_subsystem *css;
  737. struct ccw_dev_id dev_id;
  738. priv = container_of(work, struct ccw_device_private, kick_work);
  739. cdev = priv->cdev;
  740. sch = to_subchannel(cdev->dev.parent);
  741. css = to_css(sch->dev.parent);
  742. dev_id.devno = sch->schib.pmcw.dev;
  743. dev_id.ssid = sch->schid.ssid;
  744. /*
  745. * Move the orphaned ccw device to the orphanage so the replacing
  746. * ccw device can take its place on the subchannel.
  747. */
  748. ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev);
  749. if (ret) {
  750. CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
  751. "(ret=%d)!\n", cdev->private->dev_id.ssid,
  752. cdev->private->dev_id.devno, ret);
  753. return;
  754. }
  755. cdev->ccwlock = css->pseudo_subchannel->lock;
  756. /*
  757. * Search for the replacing ccw device
  758. * - among the disconnected devices
  759. * - in the orphanage
  760. */
  761. replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
  762. if (replacing_cdev) {
  763. sch_attach_disconnected_device(sch, replacing_cdev);
  764. /* Release reference from get_disc_ccwdev_by_dev_id() */
  765. put_device(&cdev->dev);
  766. return;
  767. }
  768. replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
  769. if (replacing_cdev) {
  770. sch_attach_orphaned_device(sch, replacing_cdev);
  771. /* Release reference from get_orphaned_ccwdev_by_dev_id() */
  772. put_device(&cdev->dev);
  773. return;
  774. }
  775. sch_create_and_recog_new_device(sch);
  776. }
  777. /*
  778. * Register recognized device.
  779. */
  780. static void
  781. io_subchannel_register(struct work_struct *work)
  782. {
  783. struct ccw_device_private *priv;
  784. struct ccw_device *cdev;
  785. struct subchannel *sch;
  786. int ret;
  787. unsigned long flags;
  788. priv = container_of(work, struct ccw_device_private, kick_work);
  789. cdev = priv->cdev;
  790. sch = to_subchannel(cdev->dev.parent);
  791. css_update_ssd_info(sch);
  792. /*
  793. * io_subchannel_register() will also be called after device
  794. * recognition has been done for a boxed device (which will already
  795. * be registered). We need to reprobe since we may now have sense id
  796. * information.
  797. */
  798. if (klist_node_attached(&cdev->dev.knode_parent)) {
  799. if (!cdev->drv) {
  800. ret = device_reprobe(&cdev->dev);
  801. if (ret)
  802. /* We can't do much here. */
  803. CIO_MSG_EVENT(0, "device_reprobe() returned"
  804. " %d for 0.%x.%04x\n", ret,
  805. cdev->private->dev_id.ssid,
  806. cdev->private->dev_id.devno);
  807. }
  808. goto out;
  809. }
  810. /*
  811. * Now we know this subchannel will stay, we can throw
  812. * our delayed uevent.
  813. */
  814. sch->dev.uevent_suppress = 0;
  815. kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
  816. /* make it known to the system */
  817. ret = ccw_device_register(cdev);
  818. if (ret) {
  819. CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
  820. cdev->private->dev_id.ssid,
  821. cdev->private->dev_id.devno, ret);
  822. put_device(&cdev->dev);
  823. spin_lock_irqsave(sch->lock, flags);
  824. sch_set_cdev(sch, NULL);
  825. spin_unlock_irqrestore(sch->lock, flags);
  826. kfree (cdev->private);
  827. kfree (cdev);
  828. put_device(&sch->dev);
  829. if (atomic_dec_and_test(&ccw_device_init_count))
  830. wake_up(&ccw_device_init_wq);
  831. return;
  832. }
  833. put_device(&cdev->dev);
  834. out:
  835. cdev->private->flags.recog_done = 1;
  836. put_device(&sch->dev);
  837. wake_up(&cdev->private->wait_q);
  838. if (atomic_dec_and_test(&ccw_device_init_count))
  839. wake_up(&ccw_device_init_wq);
  840. }
  841. static void ccw_device_call_sch_unregister(struct work_struct *work)
  842. {
  843. struct ccw_device_private *priv;
  844. struct ccw_device *cdev;
  845. struct subchannel *sch;
  846. priv = container_of(work, struct ccw_device_private, kick_work);
  847. cdev = priv->cdev;
  848. /* Get subchannel reference for local processing. */
  849. if (!get_device(cdev->dev.parent))
  850. return;
  851. sch = to_subchannel(cdev->dev.parent);
  852. css_sch_device_unregister(sch);
  853. /* Reset intparm to zeroes. */
  854. sch->schib.pmcw.intparm = 0;
  855. cio_modify(sch);
  856. /* Release cdev reference for workqueue processing.*/
  857. put_device(&cdev->dev);
  858. /* Release subchannel reference for local processing. */
  859. put_device(&sch->dev);
  860. }
  861. /*
  862. * subchannel recognition done. Called from the state machine.
  863. */
  864. void
  865. io_subchannel_recog_done(struct ccw_device *cdev)
  866. {
  867. struct subchannel *sch;
  868. if (css_init_done == 0) {
  869. cdev->private->flags.recog_done = 1;
  870. return;
  871. }
  872. switch (cdev->private->state) {
  873. case DEV_STATE_NOT_OPER:
  874. cdev->private->flags.recog_done = 1;
  875. /* Remove device found not operational. */
  876. if (!get_device(&cdev->dev))
  877. break;
  878. sch = to_subchannel(cdev->dev.parent);
  879. PREPARE_WORK(&cdev->private->kick_work,
  880. ccw_device_call_sch_unregister);
  881. queue_work(slow_path_wq, &cdev->private->kick_work);
  882. /* Release subchannel reference for asynchronous recognition. */
  883. put_device(&sch->dev);
  884. if (atomic_dec_and_test(&ccw_device_init_count))
  885. wake_up(&ccw_device_init_wq);
  886. break;
  887. case DEV_STATE_BOXED:
  888. /* Device did not respond in time. */
  889. case DEV_STATE_OFFLINE:
  890. /*
  891. * We can't register the device in interrupt context so
  892. * we schedule a work item.
  893. */
  894. if (!get_device(&cdev->dev))
  895. break;
  896. PREPARE_WORK(&cdev->private->kick_work,
  897. io_subchannel_register);
  898. queue_work(slow_path_wq, &cdev->private->kick_work);
  899. break;
  900. }
  901. }
  902. static int
  903. io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
  904. {
  905. int rc;
  906. struct ccw_device_private *priv;
  907. sch_set_cdev(sch, cdev);
  908. cdev->ccwlock = sch->lock;
  909. /* Init private data. */
  910. priv = cdev->private;
  911. priv->dev_id.devno = sch->schib.pmcw.dev;
  912. priv->dev_id.ssid = sch->schid.ssid;
  913. priv->schid = sch->schid;
  914. priv->state = DEV_STATE_NOT_OPER;
  915. INIT_LIST_HEAD(&priv->cmb_list);
  916. init_waitqueue_head(&priv->wait_q);
  917. init_timer(&priv->timer);
  918. /* Set an initial name for the device. */
  919. if (cio_is_console(sch->schid))
  920. cdev->dev.init_name = cio_get_console_cdev_name(sch);
  921. else
  922. dev_set_name(&cdev->dev, "0.%x.%04x",
  923. sch->schid.ssid, sch->schib.pmcw.dev);
  924. /* Increase counter of devices currently in recognition. */
  925. atomic_inc(&ccw_device_init_count);
  926. /* Start async. device sensing. */
  927. spin_lock_irq(sch->lock);
  928. rc = ccw_device_recognition(cdev);
  929. spin_unlock_irq(sch->lock);
  930. if (rc) {
  931. if (atomic_dec_and_test(&ccw_device_init_count))
  932. wake_up(&ccw_device_init_wq);
  933. }
  934. return rc;
  935. }
  936. static void ccw_device_move_to_sch(struct work_struct *work)
  937. {
  938. struct ccw_device_private *priv;
  939. int rc;
  940. struct subchannel *sch;
  941. struct ccw_device *cdev;
  942. struct subchannel *former_parent;
  943. priv = container_of(work, struct ccw_device_private, kick_work);
  944. sch = priv->sch;
  945. cdev = priv->cdev;
  946. former_parent = ccw_device_is_orphan(cdev) ?
  947. NULL : to_subchannel(get_device(cdev->dev.parent));
  948. mutex_lock(&sch->reg_mutex);
  949. /* Try to move the ccw device to its new subchannel. */
  950. rc = device_move(&cdev->dev, &sch->dev);
  951. mutex_unlock(&sch->reg_mutex);
  952. if (rc) {
  953. CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel "
  954. "0.%x.%04x failed (ret=%d)!\n",
  955. cdev->private->dev_id.ssid,
  956. cdev->private->dev_id.devno, sch->schid.ssid,
  957. sch->schid.sch_no, rc);
  958. css_sch_device_unregister(sch);
  959. goto out;
  960. }
  961. if (former_parent) {
  962. spin_lock_irq(former_parent->lock);
  963. sch_set_cdev(former_parent, NULL);
  964. spin_unlock_irq(former_parent->lock);
  965. css_sch_device_unregister(former_parent);
  966. /* Reset intparm to zeroes. */
  967. former_parent->schib.pmcw.intparm = 0;
  968. cio_modify(former_parent);
  969. }
  970. sch_attach_device(sch, cdev);
  971. out:
  972. if (former_parent)
  973. put_device(&former_parent->dev);
  974. put_device(&cdev->dev);
  975. }
  976. static void io_subchannel_irq(struct subchannel *sch)
  977. {
  978. struct ccw_device *cdev;
  979. cdev = sch_get_cdev(sch);
  980. CIO_TRACE_EVENT(3, "IRQ");
  981. CIO_TRACE_EVENT(3, dev_name(&sch->dev));
  982. if (cdev)
  983. dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
  984. }
  985. static void io_subchannel_init_fields(struct subchannel *sch)
  986. {
  987. if (cio_is_console(sch->schid))
  988. sch->opm = 0xff;
  989. else
  990. sch->opm = chp_get_sch_opm(sch);
  991. sch->lpm = sch->schib.pmcw.pam & sch->opm;
  992. sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
  993. CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
  994. " - PIM = %02X, PAM = %02X, POM = %02X\n",
  995. sch->schib.pmcw.dev, sch->schid.ssid,
  996. sch->schid.sch_no, sch->schib.pmcw.pim,
  997. sch->schib.pmcw.pam, sch->schib.pmcw.pom);
  998. /* Initially set up some fields in the pmcw. */
  999. sch->schib.pmcw.ena = 0;
  1000. sch->schib.pmcw.csense = 1; /* concurrent sense */
  1001. if ((sch->lpm & (sch->lpm - 1)) != 0)
  1002. sch->schib.pmcw.mp = 1; /* multipath mode */
  1003. /* clean up possible residual cmf stuff */
  1004. sch->schib.pmcw.mme = 0;
  1005. sch->schib.pmcw.mbfc = 0;
  1006. sch->schib.pmcw.mbi = 0;
  1007. sch->schib.mba = 0;
  1008. }
  1009. static int io_subchannel_probe(struct subchannel *sch)
  1010. {
  1011. struct ccw_device *cdev;
  1012. int rc;
  1013. unsigned long flags;
  1014. struct ccw_dev_id dev_id;
  1015. cdev = sch_get_cdev(sch);
  1016. if (cdev) {
  1017. rc = sysfs_create_group(&sch->dev.kobj,
  1018. &io_subchannel_attr_group);
  1019. if (rc)
  1020. CIO_MSG_EVENT(0, "Failed to create io subchannel "
  1021. "attributes for subchannel "
  1022. "0.%x.%04x (rc=%d)\n",
  1023. sch->schid.ssid, sch->schid.sch_no, rc);
  1024. /*
  1025. * This subchannel already has an associated ccw_device.
  1026. * Throw the delayed uevent for the subchannel, register
  1027. * the ccw_device and exit. This happens for all early
  1028. * devices, e.g. the console.
  1029. */
  1030. sch->dev.uevent_suppress = 0;
  1031. kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
  1032. cdev->dev.groups = ccwdev_attr_groups;
  1033. device_initialize(&cdev->dev);
  1034. ccw_device_register(cdev);
  1035. /*
  1036. * Check if the device is already online. If it is
  1037. * the reference count needs to be corrected
  1038. * (see ccw_device_online and css_init_done for the
  1039. * ugly details).
  1040. */
  1041. if (cdev->private->state != DEV_STATE_NOT_OPER &&
  1042. cdev->private->state != DEV_STATE_OFFLINE &&
  1043. cdev->private->state != DEV_STATE_BOXED)
  1044. get_device(&cdev->dev);
  1045. return 0;
  1046. }
  1047. io_subchannel_init_fields(sch);
  1048. /*
  1049. * First check if a fitting device may be found amongst the
  1050. * disconnected devices or in the orphanage.
  1051. */
  1052. dev_id.devno = sch->schib.pmcw.dev;
  1053. dev_id.ssid = sch->schid.ssid;
  1054. rc = sysfs_create_group(&sch->dev.kobj,
  1055. &io_subchannel_attr_group);
  1056. if (rc)
  1057. return rc;
  1058. /* Allocate I/O subchannel private data. */
  1059. sch->private = kzalloc(sizeof(struct io_subchannel_private),
  1060. GFP_KERNEL | GFP_DMA);
  1061. if (!sch->private) {
  1062. rc = -ENOMEM;
  1063. goto out_err;
  1064. }
  1065. cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
  1066. if (!cdev)
  1067. cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
  1068. &dev_id);
  1069. if (cdev) {
  1070. /*
  1071. * Schedule moving the device until when we have a registered
  1072. * subchannel to move to and succeed the probe. We can
  1073. * unregister later again, when the probe is through.
  1074. */
  1075. cdev->private->sch = sch;
  1076. PREPARE_WORK(&cdev->private->kick_work,
  1077. ccw_device_move_to_sch);
  1078. queue_work(slow_path_wq, &cdev->private->kick_work);
  1079. return 0;
  1080. }
  1081. cdev = io_subchannel_create_ccwdev(sch);
  1082. if (IS_ERR(cdev)) {
  1083. rc = PTR_ERR(cdev);
  1084. goto out_err;
  1085. }
  1086. rc = io_subchannel_recog(cdev, sch);
  1087. if (rc) {
  1088. spin_lock_irqsave(sch->lock, flags);
  1089. sch_set_cdev(sch, NULL);
  1090. spin_unlock_irqrestore(sch->lock, flags);
  1091. if (cdev->dev.release)
  1092. cdev->dev.release(&cdev->dev);
  1093. goto out_err;
  1094. }
  1095. return 0;
  1096. out_err:
  1097. kfree(sch->private);
  1098. sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
  1099. return rc;
  1100. }
  1101. static int
  1102. io_subchannel_remove (struct subchannel *sch)
  1103. {
  1104. struct ccw_device *cdev;
  1105. unsigned long flags;
  1106. cdev = sch_get_cdev(sch);
  1107. if (!cdev)
  1108. return 0;
  1109. /* Set ccw device to not operational and drop reference. */
  1110. spin_lock_irqsave(cdev->ccwlock, flags);
  1111. sch_set_cdev(sch, NULL);
  1112. cdev->private->state = DEV_STATE_NOT_OPER;
  1113. spin_unlock_irqrestore(cdev->ccwlock, flags);
  1114. ccw_device_unregister(cdev);
  1115. put_device(&cdev->dev);
  1116. kfree(sch->private);
  1117. sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
  1118. return 0;
  1119. }
  1120. static int io_subchannel_notify(struct subchannel *sch, int event)
  1121. {
  1122. struct ccw_device *cdev;
  1123. cdev = sch_get_cdev(sch);
  1124. if (!cdev)
  1125. return 0;
  1126. return ccw_device_notify(cdev, event);
  1127. }
  1128. static void io_subchannel_verify(struct subchannel *sch)
  1129. {
  1130. struct ccw_device *cdev;
  1131. cdev = sch_get_cdev(sch);
  1132. if (cdev)
  1133. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1134. }
  1135. static int check_for_io_on_path(struct subchannel *sch, int mask)
  1136. {
  1137. int cc;
  1138. cc = stsch(sch->schid, &sch->schib);
  1139. if (cc)
  1140. return 0;
  1141. if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask)
  1142. return 1;
  1143. return 0;
  1144. }
  1145. static void terminate_internal_io(struct subchannel *sch,
  1146. struct ccw_device *cdev)
  1147. {
  1148. if (cio_clear(sch)) {
  1149. /* Recheck device in case clear failed. */
  1150. sch->lpm = 0;
  1151. if (cdev->online)
  1152. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1153. else
  1154. css_schedule_eval(sch->schid);
  1155. return;
  1156. }
  1157. cdev->private->state = DEV_STATE_CLEAR_VERIFY;
  1158. /* Request retry of internal operation. */
  1159. cdev->private->flags.intretry = 1;
  1160. /* Call handler. */
  1161. if (cdev->handler)
  1162. cdev->handler(cdev, cdev->private->intparm,
  1163. ERR_PTR(-EIO));
  1164. }
  1165. static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
  1166. {
  1167. struct ccw_device *cdev;
  1168. cdev = sch_get_cdev(sch);
  1169. if (!cdev)
  1170. return;
  1171. if (check_for_io_on_path(sch, mask)) {
  1172. if (cdev->private->state == DEV_STATE_ONLINE)
  1173. ccw_device_kill_io(cdev);
  1174. else {
  1175. terminate_internal_io(sch, cdev);
  1176. /* Re-start path verification. */
  1177. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1178. }
  1179. } else
  1180. /* trigger path verification. */
  1181. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1182. }
  1183. static int io_subchannel_chp_event(struct subchannel *sch,
  1184. struct chp_link *link, int event)
  1185. {
  1186. int mask;
  1187. mask = chp_ssd_get_mask(&sch->ssd_info, link);
  1188. if (!mask)
  1189. return 0;
  1190. switch (event) {
  1191. case CHP_VARY_OFF:
  1192. sch->opm &= ~mask;
  1193. sch->lpm &= ~mask;
  1194. io_subchannel_terminate_path(sch, mask);
  1195. break;
  1196. case CHP_VARY_ON:
  1197. sch->opm |= mask;
  1198. sch->lpm |= mask;
  1199. io_subchannel_verify(sch);
  1200. break;
  1201. case CHP_OFFLINE:
  1202. if (stsch(sch->schid, &sch->schib))
  1203. return -ENXIO;
  1204. if (!css_sch_is_valid(&sch->schib))
  1205. return -ENODEV;
  1206. io_subchannel_terminate_path(sch, mask);
  1207. break;
  1208. case CHP_ONLINE:
  1209. if (stsch(sch->schid, &sch->schib))
  1210. return -ENXIO;
  1211. sch->lpm |= mask & sch->opm;
  1212. io_subchannel_verify(sch);
  1213. break;
  1214. }
  1215. return 0;
  1216. }
  1217. static void
  1218. io_subchannel_shutdown(struct subchannel *sch)
  1219. {
  1220. struct ccw_device *cdev;
  1221. int ret;
  1222. cdev = sch_get_cdev(sch);
  1223. if (cio_is_console(sch->schid))
  1224. return;
  1225. if (!sch->schib.pmcw.ena)
  1226. /* Nothing to do. */
  1227. return;
  1228. ret = cio_disable_subchannel(sch);
  1229. if (ret != -EBUSY)
  1230. /* Subchannel is disabled, we're done. */
  1231. return;
  1232. cdev->private->state = DEV_STATE_QUIESCE;
  1233. if (cdev->handler)
  1234. cdev->handler(cdev, cdev->private->intparm,
  1235. ERR_PTR(-EIO));
  1236. ret = ccw_device_cancel_halt_clear(cdev);
  1237. if (ret == -EBUSY) {
  1238. ccw_device_set_timeout(cdev, HZ/10);
  1239. wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
  1240. }
  1241. cio_disable_subchannel(sch);
  1242. }
  1243. static int io_subchannel_get_status(struct subchannel *sch)
  1244. {
  1245. struct schib schib;
  1246. if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
  1247. return CIO_GONE;
  1248. if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
  1249. return CIO_REVALIDATE;
  1250. if (!sch->lpm)
  1251. return CIO_NO_PATH;
  1252. return CIO_OPER;
  1253. }
  1254. static int device_is_disconnected(struct ccw_device *cdev)
  1255. {
  1256. if (!cdev)
  1257. return 0;
  1258. return (cdev->private->state == DEV_STATE_DISCONNECTED ||
  1259. cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
  1260. }
  1261. static int recovery_check(struct device *dev, void *data)
  1262. {
  1263. struct ccw_device *cdev = to_ccwdev(dev);
  1264. int *redo = data;
  1265. spin_lock_irq(cdev->ccwlock);
  1266. switch (cdev->private->state) {
  1267. case DEV_STATE_DISCONNECTED:
  1268. CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
  1269. cdev->private->dev_id.ssid,
  1270. cdev->private->dev_id.devno);
  1271. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1272. *redo = 1;
  1273. break;
  1274. case DEV_STATE_DISCONNECTED_SENSE_ID:
  1275. *redo = 1;
  1276. break;
  1277. }
  1278. spin_unlock_irq(cdev->ccwlock);
  1279. return 0;
  1280. }
  1281. static void recovery_work_func(struct work_struct *unused)
  1282. {
  1283. int redo = 0;
  1284. bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
  1285. if (redo) {
  1286. spin_lock_irq(&recovery_lock);
  1287. if (!timer_pending(&recovery_timer)) {
  1288. if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
  1289. recovery_phase++;
  1290. mod_timer(&recovery_timer, jiffies +
  1291. recovery_delay[recovery_phase] * HZ);
  1292. }
  1293. spin_unlock_irq(&recovery_lock);
  1294. } else
  1295. CIO_MSG_EVENT(4, "recovery: end\n");
  1296. }
  1297. static DECLARE_WORK(recovery_work, recovery_work_func);
  1298. static void recovery_func(unsigned long data)
  1299. {
  1300. /*
  1301. * We can't do our recovery in softirq context and it's not
  1302. * performance critical, so we schedule it.
  1303. */
  1304. schedule_work(&recovery_work);
  1305. }
  1306. static void ccw_device_schedule_recovery(void)
  1307. {
  1308. unsigned long flags;
  1309. CIO_MSG_EVENT(4, "recovery: schedule\n");
  1310. spin_lock_irqsave(&recovery_lock, flags);
  1311. if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
  1312. recovery_phase = 0;
  1313. mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
  1314. }
  1315. spin_unlock_irqrestore(&recovery_lock, flags);
  1316. }
  1317. static int purge_fn(struct device *dev, void *data)
  1318. {
  1319. struct ccw_device *cdev = to_ccwdev(dev);
  1320. struct ccw_device_private *priv = cdev->private;
  1321. int unreg;
  1322. spin_lock_irq(cdev->ccwlock);
  1323. unreg = is_blacklisted(priv->dev_id.ssid, priv->dev_id.devno) &&
  1324. (priv->state == DEV_STATE_OFFLINE);
  1325. spin_unlock_irq(cdev->ccwlock);
  1326. if (!unreg)
  1327. goto out;
  1328. if (!get_device(&cdev->dev))
  1329. goto out;
  1330. CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", priv->dev_id.ssid,
  1331. priv->dev_id.devno);
  1332. PREPARE_WORK(&cdev->private->kick_work, ccw_device_call_sch_unregister);
  1333. queue_work(slow_path_wq, &cdev->private->kick_work);
  1334. out:
  1335. /* Abort loop in case of pending signal. */
  1336. if (signal_pending(current))
  1337. return -EINTR;
  1338. return 0;
  1339. }
  1340. /**
  1341. * ccw_purge_blacklisted - purge unused, blacklisted devices
  1342. *
  1343. * Unregister all ccw devices that are offline and on the blacklist.
  1344. */
  1345. int ccw_purge_blacklisted(void)
  1346. {
  1347. CIO_MSG_EVENT(2, "ccw: purging blacklisted devices\n");
  1348. bus_for_each_dev(&ccw_bus_type, NULL, NULL, purge_fn);
  1349. return 0;
  1350. }
  1351. static void device_set_disconnected(struct ccw_device *cdev)
  1352. {
  1353. if (!cdev)
  1354. return;
  1355. ccw_device_set_timeout(cdev, 0);
  1356. cdev->private->flags.fake_irb = 0;
  1357. cdev->private->state = DEV_STATE_DISCONNECTED;
  1358. if (cdev->online)
  1359. ccw_device_schedule_recovery();
  1360. }
  1361. void ccw_device_set_notoper(struct ccw_device *cdev)
  1362. {
  1363. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  1364. CIO_TRACE_EVENT(2, "notoper");
  1365. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  1366. ccw_device_set_timeout(cdev, 0);
  1367. cio_disable_subchannel(sch);
  1368. cdev->private->state = DEV_STATE_NOT_OPER;
  1369. }
  1370. static int io_subchannel_sch_event(struct subchannel *sch, int slow)
  1371. {
  1372. int event, ret, disc;
  1373. unsigned long flags;
  1374. enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE, DISC } action;
  1375. struct ccw_device *cdev;
  1376. spin_lock_irqsave(sch->lock, flags);
  1377. cdev = sch_get_cdev(sch);
  1378. disc = device_is_disconnected(cdev);
  1379. if (disc && slow) {
  1380. /* Disconnected devices are evaluated directly only.*/
  1381. spin_unlock_irqrestore(sch->lock, flags);
  1382. return 0;
  1383. }
  1384. /* No interrupt after machine check - kill pending timers. */
  1385. if (cdev)
  1386. ccw_device_set_timeout(cdev, 0);
  1387. if (!disc && !slow) {
  1388. /* Non-disconnected devices are evaluated on the slow path. */
  1389. spin_unlock_irqrestore(sch->lock, flags);
  1390. return -EAGAIN;
  1391. }
  1392. event = io_subchannel_get_status(sch);
  1393. CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
  1394. sch->schid.ssid, sch->schid.sch_no, event,
  1395. disc ? "disconnected" : "normal",
  1396. slow ? "slow" : "fast");
  1397. /* Analyze subchannel status. */
  1398. action = NONE;
  1399. switch (event) {
  1400. case CIO_NO_PATH:
  1401. if (disc) {
  1402. /* Check if paths have become available. */
  1403. action = REPROBE;
  1404. break;
  1405. }
  1406. /* fall through */
  1407. case CIO_GONE:
  1408. /* Ask driver what to do with device. */
  1409. if (io_subchannel_notify(sch, event))
  1410. action = DISC;
  1411. else
  1412. action = UNREGISTER;
  1413. break;
  1414. case CIO_REVALIDATE:
  1415. /* Device will be removed, so no notify necessary. */
  1416. if (disc)
  1417. /* Reprobe because immediate unregister might block. */
  1418. action = REPROBE;
  1419. else
  1420. action = UNREGISTER_PROBE;
  1421. break;
  1422. case CIO_OPER:
  1423. if (disc)
  1424. /* Get device operational again. */
  1425. action = REPROBE;
  1426. break;
  1427. }
  1428. /* Perform action. */
  1429. ret = 0;
  1430. switch (action) {
  1431. case UNREGISTER:
  1432. case UNREGISTER_PROBE:
  1433. ccw_device_set_notoper(cdev);
  1434. /* Unregister device (will use subchannel lock). */
  1435. spin_unlock_irqrestore(sch->lock, flags);
  1436. css_sch_device_unregister(sch);
  1437. spin_lock_irqsave(sch->lock, flags);
  1438. /* Reset intparm to zeroes. */
  1439. sch->schib.pmcw.intparm = 0;
  1440. cio_modify(sch);
  1441. break;
  1442. case REPROBE:
  1443. ccw_device_trigger_reprobe(cdev);
  1444. break;
  1445. case DISC:
  1446. device_set_disconnected(cdev);
  1447. break;
  1448. default:
  1449. break;
  1450. }
  1451. spin_unlock_irqrestore(sch->lock, flags);
  1452. /* Probe if necessary. */
  1453. if (action == UNREGISTER_PROBE)
  1454. ret = css_probe_device(sch->schid);
  1455. return ret;
  1456. }
  1457. #ifdef CONFIG_CCW_CONSOLE
  1458. static struct ccw_device console_cdev;
  1459. static char console_cdev_name[10] = "0.x.xxxx";
  1460. static struct ccw_device_private console_private;
  1461. static int console_cdev_in_use;
  1462. static DEFINE_SPINLOCK(ccw_console_lock);
  1463. spinlock_t * cio_get_console_lock(void)
  1464. {
  1465. return &ccw_console_lock;
  1466. }
  1467. static int ccw_device_console_enable(struct ccw_device *cdev,
  1468. struct subchannel *sch)
  1469. {
  1470. int rc;
  1471. /* Attach subchannel private data. */
  1472. sch->private = cio_get_console_priv();
  1473. memset(sch->private, 0, sizeof(struct io_subchannel_private));
  1474. io_subchannel_init_fields(sch);
  1475. sch->driver = &io_subchannel_driver;
  1476. /* Initialize the ccw_device structure. */
  1477. cdev->dev.parent= &sch->dev;
  1478. rc = io_subchannel_recog(cdev, sch);
  1479. if (rc)
  1480. return rc;
  1481. /* Now wait for the async. recognition to come to an end. */
  1482. spin_lock_irq(cdev->ccwlock);
  1483. while (!dev_fsm_final_state(cdev))
  1484. wait_cons_dev();
  1485. rc = -EIO;
  1486. if (cdev->private->state != DEV_STATE_OFFLINE)
  1487. goto out_unlock;
  1488. ccw_device_online(cdev);
  1489. while (!dev_fsm_final_state(cdev))
  1490. wait_cons_dev();
  1491. if (cdev->private->state != DEV_STATE_ONLINE)
  1492. goto out_unlock;
  1493. rc = 0;
  1494. out_unlock:
  1495. spin_unlock_irq(cdev->ccwlock);
  1496. return 0;
  1497. }
  1498. struct ccw_device *
  1499. ccw_device_probe_console(void)
  1500. {
  1501. struct subchannel *sch;
  1502. int ret;
  1503. if (xchg(&console_cdev_in_use, 1) != 0)
  1504. return ERR_PTR(-EBUSY);
  1505. sch = cio_probe_console();
  1506. if (IS_ERR(sch)) {
  1507. console_cdev_in_use = 0;
  1508. return (void *) sch;
  1509. }
  1510. memset(&console_cdev, 0, sizeof(struct ccw_device));
  1511. memset(&console_private, 0, sizeof(struct ccw_device_private));
  1512. console_cdev.private = &console_private;
  1513. console_private.cdev = &console_cdev;
  1514. ret = ccw_device_console_enable(&console_cdev, sch);
  1515. if (ret) {
  1516. cio_release_console();
  1517. console_cdev_in_use = 0;
  1518. return ERR_PTR(ret);
  1519. }
  1520. console_cdev.online = 1;
  1521. return &console_cdev;
  1522. }
  1523. const char *cio_get_console_cdev_name(struct subchannel *sch)
  1524. {
  1525. snprintf(console_cdev_name, 10, "0.%x.%04x",
  1526. sch->schid.ssid, sch->schib.pmcw.dev);
  1527. return (const char *)console_cdev_name;
  1528. }
  1529. #endif
  1530. /*
  1531. * get ccw_device matching the busid, but only if owned by cdrv
  1532. */
  1533. static int
  1534. __ccwdev_check_busid(struct device *dev, void *id)
  1535. {
  1536. char *bus_id;
  1537. bus_id = id;
  1538. return (strncmp(bus_id, dev_name(dev), BUS_ID_SIZE) == 0);
  1539. }
  1540. /**
  1541. * get_ccwdev_by_busid() - obtain device from a bus id
  1542. * @cdrv: driver the device is owned by
  1543. * @bus_id: bus id of the device to be searched
  1544. *
  1545. * This function searches all devices owned by @cdrv for a device with a bus
  1546. * id matching @bus_id.
  1547. * Returns:
  1548. * If a match is found, its reference count of the found device is increased
  1549. * and it is returned; else %NULL is returned.
  1550. */
  1551. struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
  1552. const char *bus_id)
  1553. {
  1554. struct device *dev;
  1555. struct device_driver *drv;
  1556. drv = get_driver(&cdrv->driver);
  1557. if (!drv)
  1558. return NULL;
  1559. dev = driver_find_device(drv, NULL, (void *)bus_id,
  1560. __ccwdev_check_busid);
  1561. put_driver(drv);
  1562. return dev ? to_ccwdev(dev) : NULL;
  1563. }
  1564. /************************** device driver handling ************************/
  1565. /* This is the implementation of the ccw_driver class. The probe, remove
  1566. * and release methods are initially very similar to the device_driver
  1567. * implementations, with the difference that they have ccw_device
  1568. * arguments.
  1569. *
  1570. * A ccw driver also contains the information that is needed for
  1571. * device matching.
  1572. */
  1573. static int
  1574. ccw_device_probe (struct device *dev)
  1575. {
  1576. struct ccw_device *cdev = to_ccwdev(dev);
  1577. struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
  1578. int ret;
  1579. cdev->drv = cdrv; /* to let the driver call _set_online */
  1580. ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
  1581. if (ret) {
  1582. cdev->drv = NULL;
  1583. return ret;
  1584. }
  1585. return 0;
  1586. }
  1587. static int
  1588. ccw_device_remove (struct device *dev)
  1589. {
  1590. struct ccw_device *cdev = to_ccwdev(dev);
  1591. struct ccw_driver *cdrv = cdev->drv;
  1592. int ret;
  1593. if (cdrv->remove)
  1594. cdrv->remove(cdev);
  1595. if (cdev->online) {
  1596. cdev->online = 0;
  1597. spin_lock_irq(cdev->ccwlock);
  1598. ret = ccw_device_offline(cdev);
  1599. spin_unlock_irq(cdev->ccwlock);
  1600. if (ret == 0)
  1601. wait_event(cdev->private->wait_q,
  1602. dev_fsm_final_state(cdev));
  1603. else
  1604. CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
  1605. "device 0.%x.%04x\n",
  1606. ret, cdev->private->dev_id.ssid,
  1607. cdev->private->dev_id.devno);
  1608. }
  1609. ccw_device_set_timeout(cdev, 0);
  1610. cdev->drv = NULL;
  1611. return 0;
  1612. }
  1613. static void ccw_device_shutdown(struct device *dev)
  1614. {
  1615. struct ccw_device *cdev;
  1616. cdev = to_ccwdev(dev);
  1617. if (cdev->drv && cdev->drv->shutdown)
  1618. cdev->drv->shutdown(cdev);
  1619. disable_cmf(cdev);
  1620. }
  1621. struct bus_type ccw_bus_type = {
  1622. .name = "ccw",
  1623. .match = ccw_bus_match,
  1624. .uevent = ccw_uevent,
  1625. .probe = ccw_device_probe,
  1626. .remove = ccw_device_remove,
  1627. .shutdown = ccw_device_shutdown,
  1628. };
  1629. /**
  1630. * ccw_driver_register() - register a ccw driver
  1631. * @cdriver: driver to be registered
  1632. *
  1633. * This function is mainly a wrapper around driver_register().
  1634. * Returns:
  1635. * %0 on success and a negative error value on failure.
  1636. */
  1637. int ccw_driver_register(struct ccw_driver *cdriver)
  1638. {
  1639. struct device_driver *drv = &cdriver->driver;
  1640. drv->bus = &ccw_bus_type;
  1641. drv->name = cdriver->name;
  1642. drv->owner = cdriver->owner;
  1643. return driver_register(drv);
  1644. }
  1645. /**
  1646. * ccw_driver_unregister() - deregister a ccw driver
  1647. * @cdriver: driver to be deregistered
  1648. *
  1649. * This function is mainly a wrapper around driver_unregister().
  1650. */
  1651. void ccw_driver_unregister(struct ccw_driver *cdriver)
  1652. {
  1653. driver_unregister(&cdriver->driver);
  1654. }
  1655. /* Helper func for qdio. */
  1656. struct subchannel_id
  1657. ccw_device_get_subchannel_id(struct ccw_device *cdev)
  1658. {
  1659. struct subchannel *sch;
  1660. sch = to_subchannel(cdev->dev.parent);
  1661. return sch->schid;
  1662. }
  1663. MODULE_LICENSE("GPL");
  1664. EXPORT_SYMBOL(ccw_device_set_online);
  1665. EXPORT_SYMBOL(ccw_device_set_offline);
  1666. EXPORT_SYMBOL(ccw_driver_register);
  1667. EXPORT_SYMBOL(ccw_driver_unregister);
  1668. EXPORT_SYMBOL(get_ccwdev_by_busid);
  1669. EXPORT_SYMBOL(ccw_bus_type);
  1670. EXPORT_SYMBOL(ccw_device_work);
  1671. EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);