device.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  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. return;
  765. }
  766. replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
  767. if (replacing_cdev) {
  768. sch_attach_orphaned_device(sch, replacing_cdev);
  769. return;
  770. }
  771. sch_create_and_recog_new_device(sch);
  772. }
  773. /*
  774. * Register recognized device.
  775. */
  776. static void
  777. io_subchannel_register(struct work_struct *work)
  778. {
  779. struct ccw_device_private *priv;
  780. struct ccw_device *cdev;
  781. struct subchannel *sch;
  782. int ret;
  783. unsigned long flags;
  784. priv = container_of(work, struct ccw_device_private, kick_work);
  785. cdev = priv->cdev;
  786. sch = to_subchannel(cdev->dev.parent);
  787. css_update_ssd_info(sch);
  788. /*
  789. * io_subchannel_register() will also be called after device
  790. * recognition has been done for a boxed device (which will already
  791. * be registered). We need to reprobe since we may now have sense id
  792. * information.
  793. */
  794. if (klist_node_attached(&cdev->dev.knode_parent)) {
  795. if (!cdev->drv) {
  796. ret = device_reprobe(&cdev->dev);
  797. if (ret)
  798. /* We can't do much here. */
  799. CIO_MSG_EVENT(0, "device_reprobe() returned"
  800. " %d for 0.%x.%04x\n", ret,
  801. cdev->private->dev_id.ssid,
  802. cdev->private->dev_id.devno);
  803. }
  804. goto out;
  805. }
  806. /*
  807. * Now we know this subchannel will stay, we can throw
  808. * our delayed uevent.
  809. */
  810. sch->dev.uevent_suppress = 0;
  811. kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
  812. /* make it known to the system */
  813. ret = ccw_device_register(cdev);
  814. if (ret) {
  815. CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n",
  816. cdev->private->dev_id.ssid,
  817. cdev->private->dev_id.devno, ret);
  818. put_device(&cdev->dev);
  819. spin_lock_irqsave(sch->lock, flags);
  820. sch_set_cdev(sch, NULL);
  821. spin_unlock_irqrestore(sch->lock, flags);
  822. kfree (cdev->private);
  823. kfree (cdev);
  824. put_device(&sch->dev);
  825. if (atomic_dec_and_test(&ccw_device_init_count))
  826. wake_up(&ccw_device_init_wq);
  827. return;
  828. }
  829. put_device(&cdev->dev);
  830. out:
  831. cdev->private->flags.recog_done = 1;
  832. put_device(&sch->dev);
  833. wake_up(&cdev->private->wait_q);
  834. if (atomic_dec_and_test(&ccw_device_init_count))
  835. wake_up(&ccw_device_init_wq);
  836. }
  837. static void ccw_device_call_sch_unregister(struct work_struct *work)
  838. {
  839. struct ccw_device_private *priv;
  840. struct ccw_device *cdev;
  841. struct subchannel *sch;
  842. priv = container_of(work, struct ccw_device_private, kick_work);
  843. cdev = priv->cdev;
  844. /* Get subchannel reference for local processing. */
  845. if (!get_device(cdev->dev.parent))
  846. return;
  847. sch = to_subchannel(cdev->dev.parent);
  848. css_sch_device_unregister(sch);
  849. /* Reset intparm to zeroes. */
  850. sch->schib.pmcw.intparm = 0;
  851. cio_modify(sch);
  852. /* Release cdev reference for workqueue processing.*/
  853. put_device(&cdev->dev);
  854. /* Release subchannel reference for local processing. */
  855. put_device(&sch->dev);
  856. }
  857. /*
  858. * subchannel recognition done. Called from the state machine.
  859. */
  860. void
  861. io_subchannel_recog_done(struct ccw_device *cdev)
  862. {
  863. struct subchannel *sch;
  864. if (css_init_done == 0) {
  865. cdev->private->flags.recog_done = 1;
  866. return;
  867. }
  868. switch (cdev->private->state) {
  869. case DEV_STATE_NOT_OPER:
  870. cdev->private->flags.recog_done = 1;
  871. /* Remove device found not operational. */
  872. if (!get_device(&cdev->dev))
  873. break;
  874. sch = to_subchannel(cdev->dev.parent);
  875. PREPARE_WORK(&cdev->private->kick_work,
  876. ccw_device_call_sch_unregister);
  877. queue_work(slow_path_wq, &cdev->private->kick_work);
  878. /* Release subchannel reference for asynchronous recognition. */
  879. put_device(&sch->dev);
  880. if (atomic_dec_and_test(&ccw_device_init_count))
  881. wake_up(&ccw_device_init_wq);
  882. break;
  883. case DEV_STATE_BOXED:
  884. /* Device did not respond in time. */
  885. case DEV_STATE_OFFLINE:
  886. /*
  887. * We can't register the device in interrupt context so
  888. * we schedule a work item.
  889. */
  890. if (!get_device(&cdev->dev))
  891. break;
  892. PREPARE_WORK(&cdev->private->kick_work,
  893. io_subchannel_register);
  894. queue_work(slow_path_wq, &cdev->private->kick_work);
  895. break;
  896. }
  897. }
  898. static int
  899. io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
  900. {
  901. int rc;
  902. struct ccw_device_private *priv;
  903. sch_set_cdev(sch, cdev);
  904. cdev->ccwlock = sch->lock;
  905. /* Init private data. */
  906. priv = cdev->private;
  907. priv->dev_id.devno = sch->schib.pmcw.dev;
  908. priv->dev_id.ssid = sch->schid.ssid;
  909. priv->schid = sch->schid;
  910. priv->state = DEV_STATE_NOT_OPER;
  911. INIT_LIST_HEAD(&priv->cmb_list);
  912. init_waitqueue_head(&priv->wait_q);
  913. init_timer(&priv->timer);
  914. /* Set an initial name for the device. */
  915. snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x",
  916. sch->schid.ssid, sch->schib.pmcw.dev);
  917. /* Increase counter of devices currently in recognition. */
  918. atomic_inc(&ccw_device_init_count);
  919. /* Start async. device sensing. */
  920. spin_lock_irq(sch->lock);
  921. rc = ccw_device_recognition(cdev);
  922. spin_unlock_irq(sch->lock);
  923. if (rc) {
  924. if (atomic_dec_and_test(&ccw_device_init_count))
  925. wake_up(&ccw_device_init_wq);
  926. }
  927. return rc;
  928. }
  929. static void ccw_device_move_to_sch(struct work_struct *work)
  930. {
  931. struct ccw_device_private *priv;
  932. int rc;
  933. struct subchannel *sch;
  934. struct ccw_device *cdev;
  935. struct subchannel *former_parent;
  936. priv = container_of(work, struct ccw_device_private, kick_work);
  937. sch = priv->sch;
  938. cdev = priv->cdev;
  939. former_parent = ccw_device_is_orphan(cdev) ?
  940. NULL : to_subchannel(get_device(cdev->dev.parent));
  941. mutex_lock(&sch->reg_mutex);
  942. /* Try to move the ccw device to its new subchannel. */
  943. rc = device_move(&cdev->dev, &sch->dev);
  944. mutex_unlock(&sch->reg_mutex);
  945. if (rc) {
  946. CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel "
  947. "0.%x.%04x failed (ret=%d)!\n",
  948. cdev->private->dev_id.ssid,
  949. cdev->private->dev_id.devno, sch->schid.ssid,
  950. sch->schid.sch_no, rc);
  951. css_sch_device_unregister(sch);
  952. goto out;
  953. }
  954. if (former_parent) {
  955. spin_lock_irq(former_parent->lock);
  956. sch_set_cdev(former_parent, NULL);
  957. spin_unlock_irq(former_parent->lock);
  958. css_sch_device_unregister(former_parent);
  959. /* Reset intparm to zeroes. */
  960. former_parent->schib.pmcw.intparm = 0;
  961. cio_modify(former_parent);
  962. }
  963. sch_attach_device(sch, cdev);
  964. out:
  965. if (former_parent)
  966. put_device(&former_parent->dev);
  967. put_device(&cdev->dev);
  968. }
  969. static void io_subchannel_irq(struct subchannel *sch)
  970. {
  971. struct ccw_device *cdev;
  972. cdev = sch_get_cdev(sch);
  973. CIO_TRACE_EVENT(3, "IRQ");
  974. CIO_TRACE_EVENT(3, dev_name(&sch->dev));
  975. if (cdev)
  976. dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
  977. }
  978. static void io_subchannel_init_fields(struct subchannel *sch)
  979. {
  980. if (cio_is_console(sch->schid))
  981. sch->opm = 0xff;
  982. else
  983. sch->opm = chp_get_sch_opm(sch);
  984. sch->lpm = sch->schib.pmcw.pam & sch->opm;
  985. sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC;
  986. CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X"
  987. " - PIM = %02X, PAM = %02X, POM = %02X\n",
  988. sch->schib.pmcw.dev, sch->schid.ssid,
  989. sch->schid.sch_no, sch->schib.pmcw.pim,
  990. sch->schib.pmcw.pam, sch->schib.pmcw.pom);
  991. /* Initially set up some fields in the pmcw. */
  992. sch->schib.pmcw.ena = 0;
  993. sch->schib.pmcw.csense = 1; /* concurrent sense */
  994. if ((sch->lpm & (sch->lpm - 1)) != 0)
  995. sch->schib.pmcw.mp = 1; /* multipath mode */
  996. /* clean up possible residual cmf stuff */
  997. sch->schib.pmcw.mme = 0;
  998. sch->schib.pmcw.mbfc = 0;
  999. sch->schib.pmcw.mbi = 0;
  1000. sch->schib.mba = 0;
  1001. }
  1002. static int io_subchannel_probe(struct subchannel *sch)
  1003. {
  1004. struct ccw_device *cdev;
  1005. int rc;
  1006. unsigned long flags;
  1007. struct ccw_dev_id dev_id;
  1008. cdev = sch_get_cdev(sch);
  1009. if (cdev) {
  1010. rc = sysfs_create_group(&sch->dev.kobj,
  1011. &io_subchannel_attr_group);
  1012. if (rc)
  1013. CIO_MSG_EVENT(0, "Failed to create io subchannel "
  1014. "attributes for subchannel "
  1015. "0.%x.%04x (rc=%d)\n",
  1016. sch->schid.ssid, sch->schid.sch_no, rc);
  1017. /*
  1018. * This subchannel already has an associated ccw_device.
  1019. * Throw the delayed uevent for the subchannel, register
  1020. * the ccw_device and exit. This happens for all early
  1021. * devices, e.g. the console.
  1022. */
  1023. sch->dev.uevent_suppress = 0;
  1024. kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
  1025. cdev->dev.groups = ccwdev_attr_groups;
  1026. device_initialize(&cdev->dev);
  1027. ccw_device_register(cdev);
  1028. /*
  1029. * Check if the device is already online. If it is
  1030. * the reference count needs to be corrected
  1031. * (see ccw_device_online and css_init_done for the
  1032. * ugly details).
  1033. */
  1034. if (cdev->private->state != DEV_STATE_NOT_OPER &&
  1035. cdev->private->state != DEV_STATE_OFFLINE &&
  1036. cdev->private->state != DEV_STATE_BOXED)
  1037. get_device(&cdev->dev);
  1038. return 0;
  1039. }
  1040. io_subchannel_init_fields(sch);
  1041. /*
  1042. * First check if a fitting device may be found amongst the
  1043. * disconnected devices or in the orphanage.
  1044. */
  1045. dev_id.devno = sch->schib.pmcw.dev;
  1046. dev_id.ssid = sch->schid.ssid;
  1047. rc = sysfs_create_group(&sch->dev.kobj,
  1048. &io_subchannel_attr_group);
  1049. if (rc)
  1050. return rc;
  1051. /* Allocate I/O subchannel private data. */
  1052. sch->private = kzalloc(sizeof(struct io_subchannel_private),
  1053. GFP_KERNEL | GFP_DMA);
  1054. if (!sch->private) {
  1055. rc = -ENOMEM;
  1056. goto out_err;
  1057. }
  1058. cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
  1059. if (!cdev)
  1060. cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
  1061. &dev_id);
  1062. if (cdev) {
  1063. /*
  1064. * Schedule moving the device until when we have a registered
  1065. * subchannel to move to and succeed the probe. We can
  1066. * unregister later again, when the probe is through.
  1067. */
  1068. cdev->private->sch = sch;
  1069. PREPARE_WORK(&cdev->private->kick_work,
  1070. ccw_device_move_to_sch);
  1071. queue_work(slow_path_wq, &cdev->private->kick_work);
  1072. return 0;
  1073. }
  1074. cdev = io_subchannel_create_ccwdev(sch);
  1075. if (IS_ERR(cdev)) {
  1076. rc = PTR_ERR(cdev);
  1077. goto out_err;
  1078. }
  1079. rc = io_subchannel_recog(cdev, sch);
  1080. if (rc) {
  1081. spin_lock_irqsave(sch->lock, flags);
  1082. sch_set_cdev(sch, NULL);
  1083. spin_unlock_irqrestore(sch->lock, flags);
  1084. if (cdev->dev.release)
  1085. cdev->dev.release(&cdev->dev);
  1086. goto out_err;
  1087. }
  1088. return 0;
  1089. out_err:
  1090. kfree(sch->private);
  1091. sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
  1092. return rc;
  1093. }
  1094. static int
  1095. io_subchannel_remove (struct subchannel *sch)
  1096. {
  1097. struct ccw_device *cdev;
  1098. unsigned long flags;
  1099. cdev = sch_get_cdev(sch);
  1100. if (!cdev)
  1101. return 0;
  1102. /* Set ccw device to not operational and drop reference. */
  1103. spin_lock_irqsave(cdev->ccwlock, flags);
  1104. sch_set_cdev(sch, NULL);
  1105. cdev->private->state = DEV_STATE_NOT_OPER;
  1106. spin_unlock_irqrestore(cdev->ccwlock, flags);
  1107. ccw_device_unregister(cdev);
  1108. put_device(&cdev->dev);
  1109. kfree(sch->private);
  1110. sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group);
  1111. return 0;
  1112. }
  1113. static int io_subchannel_notify(struct subchannel *sch, int event)
  1114. {
  1115. struct ccw_device *cdev;
  1116. cdev = sch_get_cdev(sch);
  1117. if (!cdev)
  1118. return 0;
  1119. return ccw_device_notify(cdev, event);
  1120. }
  1121. static void io_subchannel_verify(struct subchannel *sch)
  1122. {
  1123. struct ccw_device *cdev;
  1124. cdev = sch_get_cdev(sch);
  1125. if (cdev)
  1126. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1127. }
  1128. static int check_for_io_on_path(struct subchannel *sch, int mask)
  1129. {
  1130. int cc;
  1131. cc = stsch(sch->schid, &sch->schib);
  1132. if (cc)
  1133. return 0;
  1134. if (scsw_actl(&sch->schib.scsw) && sch->schib.pmcw.lpum == mask)
  1135. return 1;
  1136. return 0;
  1137. }
  1138. static void terminate_internal_io(struct subchannel *sch,
  1139. struct ccw_device *cdev)
  1140. {
  1141. if (cio_clear(sch)) {
  1142. /* Recheck device in case clear failed. */
  1143. sch->lpm = 0;
  1144. if (cdev->online)
  1145. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1146. else
  1147. css_schedule_eval(sch->schid);
  1148. return;
  1149. }
  1150. cdev->private->state = DEV_STATE_CLEAR_VERIFY;
  1151. /* Request retry of internal operation. */
  1152. cdev->private->flags.intretry = 1;
  1153. /* Call handler. */
  1154. if (cdev->handler)
  1155. cdev->handler(cdev, cdev->private->intparm,
  1156. ERR_PTR(-EIO));
  1157. }
  1158. static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask)
  1159. {
  1160. struct ccw_device *cdev;
  1161. cdev = sch_get_cdev(sch);
  1162. if (!cdev)
  1163. return;
  1164. if (check_for_io_on_path(sch, mask)) {
  1165. if (cdev->private->state == DEV_STATE_ONLINE)
  1166. ccw_device_kill_io(cdev);
  1167. else {
  1168. terminate_internal_io(sch, cdev);
  1169. /* Re-start path verification. */
  1170. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1171. }
  1172. } else
  1173. /* trigger path verification. */
  1174. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1175. }
  1176. static int io_subchannel_chp_event(struct subchannel *sch,
  1177. struct chp_link *link, int event)
  1178. {
  1179. int mask;
  1180. mask = chp_ssd_get_mask(&sch->ssd_info, link);
  1181. if (!mask)
  1182. return 0;
  1183. switch (event) {
  1184. case CHP_VARY_OFF:
  1185. sch->opm &= ~mask;
  1186. sch->lpm &= ~mask;
  1187. io_subchannel_terminate_path(sch, mask);
  1188. break;
  1189. case CHP_VARY_ON:
  1190. sch->opm |= mask;
  1191. sch->lpm |= mask;
  1192. io_subchannel_verify(sch);
  1193. break;
  1194. case CHP_OFFLINE:
  1195. if (stsch(sch->schid, &sch->schib))
  1196. return -ENXIO;
  1197. if (!css_sch_is_valid(&sch->schib))
  1198. return -ENODEV;
  1199. io_subchannel_terminate_path(sch, mask);
  1200. break;
  1201. case CHP_ONLINE:
  1202. if (stsch(sch->schid, &sch->schib))
  1203. return -ENXIO;
  1204. sch->lpm |= mask & sch->opm;
  1205. io_subchannel_verify(sch);
  1206. break;
  1207. }
  1208. return 0;
  1209. }
  1210. static void
  1211. io_subchannel_shutdown(struct subchannel *sch)
  1212. {
  1213. struct ccw_device *cdev;
  1214. int ret;
  1215. cdev = sch_get_cdev(sch);
  1216. if (cio_is_console(sch->schid))
  1217. return;
  1218. if (!sch->schib.pmcw.ena)
  1219. /* Nothing to do. */
  1220. return;
  1221. ret = cio_disable_subchannel(sch);
  1222. if (ret != -EBUSY)
  1223. /* Subchannel is disabled, we're done. */
  1224. return;
  1225. cdev->private->state = DEV_STATE_QUIESCE;
  1226. if (cdev->handler)
  1227. cdev->handler(cdev, cdev->private->intparm,
  1228. ERR_PTR(-EIO));
  1229. ret = ccw_device_cancel_halt_clear(cdev);
  1230. if (ret == -EBUSY) {
  1231. ccw_device_set_timeout(cdev, HZ/10);
  1232. wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
  1233. }
  1234. cio_disable_subchannel(sch);
  1235. }
  1236. static int io_subchannel_get_status(struct subchannel *sch)
  1237. {
  1238. struct schib schib;
  1239. if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
  1240. return CIO_GONE;
  1241. if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
  1242. return CIO_REVALIDATE;
  1243. if (!sch->lpm)
  1244. return CIO_NO_PATH;
  1245. return CIO_OPER;
  1246. }
  1247. static int device_is_disconnected(struct ccw_device *cdev)
  1248. {
  1249. if (!cdev)
  1250. return 0;
  1251. return (cdev->private->state == DEV_STATE_DISCONNECTED ||
  1252. cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
  1253. }
  1254. static int recovery_check(struct device *dev, void *data)
  1255. {
  1256. struct ccw_device *cdev = to_ccwdev(dev);
  1257. int *redo = data;
  1258. spin_lock_irq(cdev->ccwlock);
  1259. switch (cdev->private->state) {
  1260. case DEV_STATE_DISCONNECTED:
  1261. CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n",
  1262. cdev->private->dev_id.ssid,
  1263. cdev->private->dev_id.devno);
  1264. dev_fsm_event(cdev, DEV_EVENT_VERIFY);
  1265. *redo = 1;
  1266. break;
  1267. case DEV_STATE_DISCONNECTED_SENSE_ID:
  1268. *redo = 1;
  1269. break;
  1270. }
  1271. spin_unlock_irq(cdev->ccwlock);
  1272. return 0;
  1273. }
  1274. static void recovery_work_func(struct work_struct *unused)
  1275. {
  1276. int redo = 0;
  1277. bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check);
  1278. if (redo) {
  1279. spin_lock_irq(&recovery_lock);
  1280. if (!timer_pending(&recovery_timer)) {
  1281. if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1)
  1282. recovery_phase++;
  1283. mod_timer(&recovery_timer, jiffies +
  1284. recovery_delay[recovery_phase] * HZ);
  1285. }
  1286. spin_unlock_irq(&recovery_lock);
  1287. } else
  1288. CIO_MSG_EVENT(4, "recovery: end\n");
  1289. }
  1290. static DECLARE_WORK(recovery_work, recovery_work_func);
  1291. static void recovery_func(unsigned long data)
  1292. {
  1293. /*
  1294. * We can't do our recovery in softirq context and it's not
  1295. * performance critical, so we schedule it.
  1296. */
  1297. schedule_work(&recovery_work);
  1298. }
  1299. static void ccw_device_schedule_recovery(void)
  1300. {
  1301. unsigned long flags;
  1302. CIO_MSG_EVENT(4, "recovery: schedule\n");
  1303. spin_lock_irqsave(&recovery_lock, flags);
  1304. if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) {
  1305. recovery_phase = 0;
  1306. mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ);
  1307. }
  1308. spin_unlock_irqrestore(&recovery_lock, flags);
  1309. }
  1310. static int purge_fn(struct device *dev, void *data)
  1311. {
  1312. struct ccw_device *cdev = to_ccwdev(dev);
  1313. struct ccw_device_private *priv = cdev->private;
  1314. int unreg;
  1315. spin_lock_irq(cdev->ccwlock);
  1316. unreg = is_blacklisted(priv->dev_id.ssid, priv->dev_id.devno) &&
  1317. (priv->state == DEV_STATE_OFFLINE);
  1318. spin_unlock_irq(cdev->ccwlock);
  1319. if (!unreg)
  1320. goto out;
  1321. if (!get_device(&cdev->dev))
  1322. goto out;
  1323. CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", priv->dev_id.ssid,
  1324. priv->dev_id.devno);
  1325. PREPARE_WORK(&cdev->private->kick_work, ccw_device_call_sch_unregister);
  1326. queue_work(slow_path_wq, &cdev->private->kick_work);
  1327. out:
  1328. /* Abort loop in case of pending signal. */
  1329. if (signal_pending(current))
  1330. return -EINTR;
  1331. return 0;
  1332. }
  1333. /**
  1334. * ccw_purge_blacklisted - purge unused, blacklisted devices
  1335. *
  1336. * Unregister all ccw devices that are offline and on the blacklist.
  1337. */
  1338. int ccw_purge_blacklisted(void)
  1339. {
  1340. CIO_MSG_EVENT(2, "ccw: purging blacklisted devices\n");
  1341. bus_for_each_dev(&ccw_bus_type, NULL, NULL, purge_fn);
  1342. return 0;
  1343. }
  1344. static void device_set_disconnected(struct ccw_device *cdev)
  1345. {
  1346. if (!cdev)
  1347. return;
  1348. ccw_device_set_timeout(cdev, 0);
  1349. cdev->private->flags.fake_irb = 0;
  1350. cdev->private->state = DEV_STATE_DISCONNECTED;
  1351. if (cdev->online)
  1352. ccw_device_schedule_recovery();
  1353. }
  1354. void ccw_device_set_notoper(struct ccw_device *cdev)
  1355. {
  1356. struct subchannel *sch = to_subchannel(cdev->dev.parent);
  1357. CIO_TRACE_EVENT(2, "notoper");
  1358. CIO_TRACE_EVENT(2, sch->dev.bus_id);
  1359. ccw_device_set_timeout(cdev, 0);
  1360. cio_disable_subchannel(sch);
  1361. cdev->private->state = DEV_STATE_NOT_OPER;
  1362. }
  1363. static int io_subchannel_sch_event(struct subchannel *sch, int slow)
  1364. {
  1365. int event, ret, disc;
  1366. unsigned long flags;
  1367. enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE, DISC } action;
  1368. struct ccw_device *cdev;
  1369. spin_lock_irqsave(sch->lock, flags);
  1370. cdev = sch_get_cdev(sch);
  1371. disc = device_is_disconnected(cdev);
  1372. if (disc && slow) {
  1373. /* Disconnected devices are evaluated directly only.*/
  1374. spin_unlock_irqrestore(sch->lock, flags);
  1375. return 0;
  1376. }
  1377. /* No interrupt after machine check - kill pending timers. */
  1378. if (cdev)
  1379. ccw_device_set_timeout(cdev, 0);
  1380. if (!disc && !slow) {
  1381. /* Non-disconnected devices are evaluated on the slow path. */
  1382. spin_unlock_irqrestore(sch->lock, flags);
  1383. return -EAGAIN;
  1384. }
  1385. event = io_subchannel_get_status(sch);
  1386. CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
  1387. sch->schid.ssid, sch->schid.sch_no, event,
  1388. disc ? "disconnected" : "normal",
  1389. slow ? "slow" : "fast");
  1390. /* Analyze subchannel status. */
  1391. action = NONE;
  1392. switch (event) {
  1393. case CIO_NO_PATH:
  1394. if (disc) {
  1395. /* Check if paths have become available. */
  1396. action = REPROBE;
  1397. break;
  1398. }
  1399. /* fall through */
  1400. case CIO_GONE:
  1401. /* Ask driver what to do with device. */
  1402. if (io_subchannel_notify(sch, event))
  1403. action = DISC;
  1404. else
  1405. action = UNREGISTER;
  1406. break;
  1407. case CIO_REVALIDATE:
  1408. /* Device will be removed, so no notify necessary. */
  1409. if (disc)
  1410. /* Reprobe because immediate unregister might block. */
  1411. action = REPROBE;
  1412. else
  1413. action = UNREGISTER_PROBE;
  1414. break;
  1415. case CIO_OPER:
  1416. if (disc)
  1417. /* Get device operational again. */
  1418. action = REPROBE;
  1419. break;
  1420. }
  1421. /* Perform action. */
  1422. ret = 0;
  1423. switch (action) {
  1424. case UNREGISTER:
  1425. case UNREGISTER_PROBE:
  1426. ccw_device_set_notoper(cdev);
  1427. /* Unregister device (will use subchannel lock). */
  1428. spin_unlock_irqrestore(sch->lock, flags);
  1429. css_sch_device_unregister(sch);
  1430. spin_lock_irqsave(sch->lock, flags);
  1431. /* Reset intparm to zeroes. */
  1432. sch->schib.pmcw.intparm = 0;
  1433. cio_modify(sch);
  1434. break;
  1435. case REPROBE:
  1436. ccw_device_trigger_reprobe(cdev);
  1437. break;
  1438. case DISC:
  1439. device_set_disconnected(cdev);
  1440. break;
  1441. default:
  1442. break;
  1443. }
  1444. spin_unlock_irqrestore(sch->lock, flags);
  1445. /* Probe if necessary. */
  1446. if (action == UNREGISTER_PROBE)
  1447. ret = css_probe_device(sch->schid);
  1448. return ret;
  1449. }
  1450. #ifdef CONFIG_CCW_CONSOLE
  1451. static struct ccw_device console_cdev;
  1452. static struct ccw_device_private console_private;
  1453. static int console_cdev_in_use;
  1454. static DEFINE_SPINLOCK(ccw_console_lock);
  1455. spinlock_t * cio_get_console_lock(void)
  1456. {
  1457. return &ccw_console_lock;
  1458. }
  1459. static int ccw_device_console_enable(struct ccw_device *cdev,
  1460. struct subchannel *sch)
  1461. {
  1462. int rc;
  1463. /* Attach subchannel private data. */
  1464. sch->private = cio_get_console_priv();
  1465. memset(sch->private, 0, sizeof(struct io_subchannel_private));
  1466. io_subchannel_init_fields(sch);
  1467. sch->driver = &io_subchannel_driver;
  1468. /* Initialize the ccw_device structure. */
  1469. cdev->dev.parent= &sch->dev;
  1470. rc = io_subchannel_recog(cdev, sch);
  1471. if (rc)
  1472. return rc;
  1473. /* Now wait for the async. recognition to come to an end. */
  1474. spin_lock_irq(cdev->ccwlock);
  1475. while (!dev_fsm_final_state(cdev))
  1476. wait_cons_dev();
  1477. rc = -EIO;
  1478. if (cdev->private->state != DEV_STATE_OFFLINE)
  1479. goto out_unlock;
  1480. ccw_device_online(cdev);
  1481. while (!dev_fsm_final_state(cdev))
  1482. wait_cons_dev();
  1483. if (cdev->private->state != DEV_STATE_ONLINE)
  1484. goto out_unlock;
  1485. rc = 0;
  1486. out_unlock:
  1487. spin_unlock_irq(cdev->ccwlock);
  1488. return 0;
  1489. }
  1490. struct ccw_device *
  1491. ccw_device_probe_console(void)
  1492. {
  1493. struct subchannel *sch;
  1494. int ret;
  1495. if (xchg(&console_cdev_in_use, 1) != 0)
  1496. return ERR_PTR(-EBUSY);
  1497. sch = cio_probe_console();
  1498. if (IS_ERR(sch)) {
  1499. console_cdev_in_use = 0;
  1500. return (void *) sch;
  1501. }
  1502. memset(&console_cdev, 0, sizeof(struct ccw_device));
  1503. memset(&console_private, 0, sizeof(struct ccw_device_private));
  1504. console_cdev.private = &console_private;
  1505. console_private.cdev = &console_cdev;
  1506. ret = ccw_device_console_enable(&console_cdev, sch);
  1507. if (ret) {
  1508. cio_release_console();
  1509. console_cdev_in_use = 0;
  1510. return ERR_PTR(ret);
  1511. }
  1512. console_cdev.online = 1;
  1513. return &console_cdev;
  1514. }
  1515. #endif
  1516. /*
  1517. * get ccw_device matching the busid, but only if owned by cdrv
  1518. */
  1519. static int
  1520. __ccwdev_check_busid(struct device *dev, void *id)
  1521. {
  1522. char *bus_id;
  1523. bus_id = id;
  1524. return (strncmp(bus_id, dev_name(dev), BUS_ID_SIZE) == 0);
  1525. }
  1526. /**
  1527. * get_ccwdev_by_busid() - obtain device from a bus id
  1528. * @cdrv: driver the device is owned by
  1529. * @bus_id: bus id of the device to be searched
  1530. *
  1531. * This function searches all devices owned by @cdrv for a device with a bus
  1532. * id matching @bus_id.
  1533. * Returns:
  1534. * If a match is found, its reference count of the found device is increased
  1535. * and it is returned; else %NULL is returned.
  1536. */
  1537. struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
  1538. const char *bus_id)
  1539. {
  1540. struct device *dev;
  1541. struct device_driver *drv;
  1542. drv = get_driver(&cdrv->driver);
  1543. if (!drv)
  1544. return NULL;
  1545. dev = driver_find_device(drv, NULL, (void *)bus_id,
  1546. __ccwdev_check_busid);
  1547. put_driver(drv);
  1548. return dev ? to_ccwdev(dev) : NULL;
  1549. }
  1550. /************************** device driver handling ************************/
  1551. /* This is the implementation of the ccw_driver class. The probe, remove
  1552. * and release methods are initially very similar to the device_driver
  1553. * implementations, with the difference that they have ccw_device
  1554. * arguments.
  1555. *
  1556. * A ccw driver also contains the information that is needed for
  1557. * device matching.
  1558. */
  1559. static int
  1560. ccw_device_probe (struct device *dev)
  1561. {
  1562. struct ccw_device *cdev = to_ccwdev(dev);
  1563. struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
  1564. int ret;
  1565. cdev->drv = cdrv; /* to let the driver call _set_online */
  1566. ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
  1567. if (ret) {
  1568. cdev->drv = NULL;
  1569. return ret;
  1570. }
  1571. return 0;
  1572. }
  1573. static int
  1574. ccw_device_remove (struct device *dev)
  1575. {
  1576. struct ccw_device *cdev = to_ccwdev(dev);
  1577. struct ccw_driver *cdrv = cdev->drv;
  1578. int ret;
  1579. if (cdrv->remove)
  1580. cdrv->remove(cdev);
  1581. if (cdev->online) {
  1582. cdev->online = 0;
  1583. spin_lock_irq(cdev->ccwlock);
  1584. ret = ccw_device_offline(cdev);
  1585. spin_unlock_irq(cdev->ccwlock);
  1586. if (ret == 0)
  1587. wait_event(cdev->private->wait_q,
  1588. dev_fsm_final_state(cdev));
  1589. else
  1590. CIO_MSG_EVENT(0, "ccw_device_offline returned %d, "
  1591. "device 0.%x.%04x\n",
  1592. ret, cdev->private->dev_id.ssid,
  1593. cdev->private->dev_id.devno);
  1594. }
  1595. ccw_device_set_timeout(cdev, 0);
  1596. cdev->drv = NULL;
  1597. return 0;
  1598. }
  1599. static void ccw_device_shutdown(struct device *dev)
  1600. {
  1601. struct ccw_device *cdev;
  1602. cdev = to_ccwdev(dev);
  1603. if (cdev->drv && cdev->drv->shutdown)
  1604. cdev->drv->shutdown(cdev);
  1605. disable_cmf(cdev);
  1606. }
  1607. struct bus_type ccw_bus_type = {
  1608. .name = "ccw",
  1609. .match = ccw_bus_match,
  1610. .uevent = ccw_uevent,
  1611. .probe = ccw_device_probe,
  1612. .remove = ccw_device_remove,
  1613. .shutdown = ccw_device_shutdown,
  1614. };
  1615. /**
  1616. * ccw_driver_register() - register a ccw driver
  1617. * @cdriver: driver to be registered
  1618. *
  1619. * This function is mainly a wrapper around driver_register().
  1620. * Returns:
  1621. * %0 on success and a negative error value on failure.
  1622. */
  1623. int ccw_driver_register(struct ccw_driver *cdriver)
  1624. {
  1625. struct device_driver *drv = &cdriver->driver;
  1626. drv->bus = &ccw_bus_type;
  1627. drv->name = cdriver->name;
  1628. drv->owner = cdriver->owner;
  1629. return driver_register(drv);
  1630. }
  1631. /**
  1632. * ccw_driver_unregister() - deregister a ccw driver
  1633. * @cdriver: driver to be deregistered
  1634. *
  1635. * This function is mainly a wrapper around driver_unregister().
  1636. */
  1637. void ccw_driver_unregister(struct ccw_driver *cdriver)
  1638. {
  1639. driver_unregister(&cdriver->driver);
  1640. }
  1641. /* Helper func for qdio. */
  1642. struct subchannel_id
  1643. ccw_device_get_subchannel_id(struct ccw_device *cdev)
  1644. {
  1645. struct subchannel *sch;
  1646. sch = to_subchannel(cdev->dev.parent);
  1647. return sch->schid;
  1648. }
  1649. MODULE_LICENSE("GPL");
  1650. EXPORT_SYMBOL(ccw_device_set_online);
  1651. EXPORT_SYMBOL(ccw_device_set_offline);
  1652. EXPORT_SYMBOL(ccw_driver_register);
  1653. EXPORT_SYMBOL(ccw_driver_unregister);
  1654. EXPORT_SYMBOL(get_ccwdev_by_busid);
  1655. EXPORT_SYMBOL(ccw_bus_type);
  1656. EXPORT_SYMBOL(ccw_device_work);
  1657. EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);