device_fsm.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. /*
  2. * drivers/s390/cio/device_fsm.c
  3. * finite state machine for device handling
  4. *
  5. * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
  6. * IBM Corporation
  7. * Author(s): Cornelia Huck(cohuck@de.ibm.com)
  8. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  9. */
  10. #include <linux/module.h>
  11. #include <linux/config.h>
  12. #include <linux/init.h>
  13. #include <asm/ccwdev.h>
  14. #include <asm/cio.h>
  15. #include "cio.h"
  16. #include "cio_debug.h"
  17. #include "css.h"
  18. #include "device.h"
  19. #include "chsc.h"
  20. #include "ioasm.h"
  21. int
  22. device_is_online(struct subchannel *sch)
  23. {
  24. struct ccw_device *cdev;
  25. if (!sch->dev.driver_data)
  26. return 0;
  27. cdev = sch->dev.driver_data;
  28. return (cdev->private->state == DEV_STATE_ONLINE);
  29. }
  30. int
  31. device_is_disconnected(struct subchannel *sch)
  32. {
  33. struct ccw_device *cdev;
  34. if (!sch->dev.driver_data)
  35. return 0;
  36. cdev = sch->dev.driver_data;
  37. return (cdev->private->state == DEV_STATE_DISCONNECTED ||
  38. cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
  39. }
  40. void
  41. device_set_disconnected(struct subchannel *sch)
  42. {
  43. struct ccw_device *cdev;
  44. if (!sch->dev.driver_data)
  45. return;
  46. cdev = sch->dev.driver_data;
  47. ccw_device_set_timeout(cdev, 0);
  48. cdev->private->flags.fake_irb = 0;
  49. cdev->private->state = DEV_STATE_DISCONNECTED;
  50. }
  51. void
  52. device_set_waiting(struct subchannel *sch)
  53. {
  54. struct ccw_device *cdev;
  55. if (!sch->dev.driver_data)
  56. return;
  57. cdev = sch->dev.driver_data;
  58. ccw_device_set_timeout(cdev, 10*HZ);
  59. cdev->private->state = DEV_STATE_WAIT4IO;
  60. }
  61. /*
  62. * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
  63. */
  64. static void
  65. ccw_device_timeout(unsigned long data)
  66. {
  67. struct ccw_device *cdev;
  68. cdev = (struct ccw_device *) data;
  69. spin_lock_irq(cdev->ccwlock);
  70. dev_fsm_event(cdev, DEV_EVENT_TIMEOUT);
  71. spin_unlock_irq(cdev->ccwlock);
  72. }
  73. /*
  74. * Set timeout
  75. */
  76. void
  77. ccw_device_set_timeout(struct ccw_device *cdev, int expires)
  78. {
  79. if (expires == 0) {
  80. del_timer(&cdev->private->timer);
  81. return;
  82. }
  83. if (timer_pending(&cdev->private->timer)) {
  84. if (mod_timer(&cdev->private->timer, jiffies + expires))
  85. return;
  86. }
  87. cdev->private->timer.function = ccw_device_timeout;
  88. cdev->private->timer.data = (unsigned long) cdev;
  89. cdev->private->timer.expires = jiffies + expires;
  90. add_timer(&cdev->private->timer);
  91. }
  92. /* Kill any pending timers after machine check. */
  93. void
  94. device_kill_pending_timer(struct subchannel *sch)
  95. {
  96. struct ccw_device *cdev;
  97. if (!sch->dev.driver_data)
  98. return;
  99. cdev = sch->dev.driver_data;
  100. ccw_device_set_timeout(cdev, 0);
  101. }
  102. /*
  103. * Cancel running i/o. This is called repeatedly since halt/clear are
  104. * asynchronous operations. We do one try with cio_cancel, two tries
  105. * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
  106. * Returns 0 if device now idle, -ENODEV for device not operational and
  107. * -EBUSY if an interrupt is expected (either from halt/clear or from a
  108. * status pending).
  109. */
  110. int
  111. ccw_device_cancel_halt_clear(struct ccw_device *cdev)
  112. {
  113. struct subchannel *sch;
  114. int ret;
  115. sch = to_subchannel(cdev->dev.parent);
  116. ret = stsch(sch->irq, &sch->schib);
  117. if (ret || !sch->schib.pmcw.dnv)
  118. return -ENODEV;
  119. if (!sch->schib.pmcw.ena || sch->schib.scsw.actl == 0)
  120. /* Not operational or no activity -> done. */
  121. return 0;
  122. /* Stage 1: cancel io. */
  123. if (!(sch->schib.scsw.actl & SCSW_ACTL_HALT_PEND) &&
  124. !(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
  125. ret = cio_cancel(sch);
  126. if (ret != -EINVAL)
  127. return ret;
  128. /* cancel io unsuccessful. From now on it is asynchronous. */
  129. cdev->private->iretry = 3; /* 3 halt retries. */
  130. }
  131. if (!(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
  132. /* Stage 2: halt io. */
  133. if (cdev->private->iretry) {
  134. cdev->private->iretry--;
  135. ret = cio_halt(sch);
  136. return (ret == 0) ? -EBUSY : ret;
  137. }
  138. /* halt io unsuccessful. */
  139. cdev->private->iretry = 255; /* 255 clear retries. */
  140. }
  141. /* Stage 3: clear io. */
  142. if (cdev->private->iretry) {
  143. cdev->private->iretry--;
  144. ret = cio_clear (sch);
  145. return (ret == 0) ? -EBUSY : ret;
  146. }
  147. panic("Can't stop i/o on subchannel.\n");
  148. }
  149. static int
  150. ccw_device_handle_oper(struct ccw_device *cdev)
  151. {
  152. struct subchannel *sch;
  153. sch = to_subchannel(cdev->dev.parent);
  154. cdev->private->flags.recog_done = 1;
  155. /*
  156. * Check if cu type and device type still match. If
  157. * not, it is certainly another device and we have to
  158. * de- and re-register. Also check here for non-matching devno.
  159. */
  160. if (cdev->id.cu_type != cdev->private->senseid.cu_type ||
  161. cdev->id.cu_model != cdev->private->senseid.cu_model ||
  162. cdev->id.dev_type != cdev->private->senseid.dev_type ||
  163. cdev->id.dev_model != cdev->private->senseid.dev_model ||
  164. cdev->private->devno != sch->schib.pmcw.dev) {
  165. PREPARE_WORK(&cdev->private->kick_work,
  166. ccw_device_do_unreg_rereg, (void *)cdev);
  167. queue_work(ccw_device_work, &cdev->private->kick_work);
  168. return 0;
  169. }
  170. cdev->private->flags.donotify = 1;
  171. return 1;
  172. }
  173. /*
  174. * The machine won't give us any notification by machine check if a chpid has
  175. * been varied online on the SE so we have to find out by magic (i. e. driving
  176. * the channel subsystem to device selection and updating our path masks).
  177. */
  178. static inline void
  179. __recover_lost_chpids(struct subchannel *sch, int old_lpm)
  180. {
  181. int mask, i;
  182. for (i = 0; i<8; i++) {
  183. mask = 0x80 >> i;
  184. if (!(sch->lpm & mask))
  185. continue;
  186. if (old_lpm & mask)
  187. continue;
  188. chpid_is_actually_online(sch->schib.pmcw.chpid[i]);
  189. }
  190. }
  191. /*
  192. * Stop device recognition.
  193. */
  194. static void
  195. ccw_device_recog_done(struct ccw_device *cdev, int state)
  196. {
  197. struct subchannel *sch;
  198. int notify, old_lpm, same_dev;
  199. sch = to_subchannel(cdev->dev.parent);
  200. ccw_device_set_timeout(cdev, 0);
  201. cio_disable_subchannel(sch);
  202. /*
  203. * Now that we tried recognition, we have performed device selection
  204. * through ssch() and the path information is up to date.
  205. */
  206. old_lpm = sch->lpm;
  207. stsch(sch->irq, &sch->schib);
  208. sch->lpm = sch->schib.pmcw.pim &
  209. sch->schib.pmcw.pam &
  210. sch->schib.pmcw.pom &
  211. sch->opm;
  212. /* Check since device may again have become not operational. */
  213. if (!sch->schib.pmcw.dnv)
  214. state = DEV_STATE_NOT_OPER;
  215. if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
  216. /* Force reprobe on all chpids. */
  217. old_lpm = 0;
  218. if (sch->lpm != old_lpm)
  219. __recover_lost_chpids(sch, old_lpm);
  220. if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
  221. if (state == DEV_STATE_NOT_OPER) {
  222. cdev->private->flags.recog_done = 1;
  223. cdev->private->state = DEV_STATE_DISCONNECTED;
  224. return;
  225. }
  226. /* Boxed devices don't need extra treatment. */
  227. }
  228. notify = 0;
  229. same_dev = 0; /* Keep the compiler quiet... */
  230. switch (state) {
  231. case DEV_STATE_NOT_OPER:
  232. CIO_DEBUG(KERN_WARNING, 2,
  233. "SenseID : unknown device %04x on subchannel %04x\n",
  234. cdev->private->devno, sch->irq);
  235. break;
  236. case DEV_STATE_OFFLINE:
  237. if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
  238. same_dev = ccw_device_handle_oper(cdev);
  239. notify = 1;
  240. }
  241. /* fill out sense information */
  242. cdev->id = (struct ccw_device_id) {
  243. .cu_type = cdev->private->senseid.cu_type,
  244. .cu_model = cdev->private->senseid.cu_model,
  245. .dev_type = cdev->private->senseid.dev_type,
  246. .dev_model = cdev->private->senseid.dev_model,
  247. };
  248. if (notify) {
  249. cdev->private->state = DEV_STATE_OFFLINE;
  250. if (same_dev) {
  251. /* Get device online again. */
  252. ccw_device_online(cdev);
  253. wake_up(&cdev->private->wait_q);
  254. }
  255. return;
  256. }
  257. /* Issue device info message. */
  258. CIO_DEBUG(KERN_INFO, 2, "SenseID : device %04x reports: "
  259. "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
  260. "%04X/%02X\n", cdev->private->devno,
  261. cdev->id.cu_type, cdev->id.cu_model,
  262. cdev->id.dev_type, cdev->id.dev_model);
  263. break;
  264. case DEV_STATE_BOXED:
  265. CIO_DEBUG(KERN_WARNING, 2,
  266. "SenseID : boxed device %04x on subchannel %04x\n",
  267. cdev->private->devno, sch->irq);
  268. break;
  269. }
  270. cdev->private->state = state;
  271. io_subchannel_recog_done(cdev);
  272. if (state != DEV_STATE_NOT_OPER)
  273. wake_up(&cdev->private->wait_q);
  274. }
  275. /*
  276. * Function called from device_id.c after sense id has completed.
  277. */
  278. void
  279. ccw_device_sense_id_done(struct ccw_device *cdev, int err)
  280. {
  281. switch (err) {
  282. case 0:
  283. ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
  284. break;
  285. case -ETIME: /* Sense id stopped by timeout. */
  286. ccw_device_recog_done(cdev, DEV_STATE_BOXED);
  287. break;
  288. default:
  289. ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
  290. break;
  291. }
  292. }
  293. static void
  294. ccw_device_oper_notify(void *data)
  295. {
  296. struct ccw_device *cdev;
  297. struct subchannel *sch;
  298. int ret;
  299. cdev = (struct ccw_device *)data;
  300. sch = to_subchannel(cdev->dev.parent);
  301. ret = (sch->driver && sch->driver->notify) ?
  302. sch->driver->notify(&sch->dev, CIO_OPER) : 0;
  303. if (!ret)
  304. /* Driver doesn't want device back. */
  305. ccw_device_do_unreg_rereg((void *)cdev);
  306. else
  307. wake_up(&cdev->private->wait_q);
  308. }
  309. /*
  310. * Finished with online/offline processing.
  311. */
  312. static void
  313. ccw_device_done(struct ccw_device *cdev, int state)
  314. {
  315. struct subchannel *sch;
  316. sch = to_subchannel(cdev->dev.parent);
  317. if (state != DEV_STATE_ONLINE)
  318. cio_disable_subchannel(sch);
  319. /* Reset device status. */
  320. memset(&cdev->private->irb, 0, sizeof(struct irb));
  321. cdev->private->state = state;
  322. if (state == DEV_STATE_BOXED)
  323. CIO_DEBUG(KERN_WARNING, 2,
  324. "Boxed device %04x on subchannel %04x\n",
  325. cdev->private->devno, sch->irq);
  326. if (cdev->private->flags.donotify) {
  327. cdev->private->flags.donotify = 0;
  328. PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,
  329. (void *)cdev);
  330. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  331. }
  332. wake_up(&cdev->private->wait_q);
  333. if (css_init_done && state != DEV_STATE_ONLINE)
  334. put_device (&cdev->dev);
  335. }
  336. /*
  337. * Function called from device_pgid.c after sense path ground has completed.
  338. */
  339. void
  340. ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
  341. {
  342. struct subchannel *sch;
  343. sch = to_subchannel(cdev->dev.parent);
  344. switch (err) {
  345. case 0:
  346. /* Start Path Group verification. */
  347. sch->vpm = 0; /* Start with no path groups set. */
  348. cdev->private->state = DEV_STATE_VERIFY;
  349. ccw_device_verify_start(cdev);
  350. break;
  351. case -ETIME: /* Sense path group id stopped by timeout. */
  352. case -EUSERS: /* device is reserved for someone else. */
  353. ccw_device_done(cdev, DEV_STATE_BOXED);
  354. break;
  355. case -EOPNOTSUPP: /* path grouping not supported, just set online. */
  356. cdev->private->options.pgroup = 0;
  357. ccw_device_done(cdev, DEV_STATE_ONLINE);
  358. break;
  359. default:
  360. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  361. break;
  362. }
  363. }
  364. /*
  365. * Start device recognition.
  366. */
  367. int
  368. ccw_device_recognition(struct ccw_device *cdev)
  369. {
  370. struct subchannel *sch;
  371. int ret;
  372. if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
  373. (cdev->private->state != DEV_STATE_BOXED))
  374. return -EINVAL;
  375. sch = to_subchannel(cdev->dev.parent);
  376. ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
  377. if (ret != 0)
  378. /* Couldn't enable the subchannel for i/o. Sick device. */
  379. return ret;
  380. /* After 60s the device recognition is considered to have failed. */
  381. ccw_device_set_timeout(cdev, 60*HZ);
  382. /*
  383. * We used to start here with a sense pgid to find out whether a device
  384. * is locked by someone else. Unfortunately, the sense pgid command
  385. * code has other meanings on devices predating the path grouping
  386. * algorithm, so we start with sense id and box the device after an
  387. * timeout (or if sense pgid during path verification detects the device
  388. * is locked, as may happen on newer devices).
  389. */
  390. cdev->private->flags.recog_done = 0;
  391. cdev->private->state = DEV_STATE_SENSE_ID;
  392. ccw_device_sense_id_start(cdev);
  393. return 0;
  394. }
  395. /*
  396. * Handle timeout in device recognition.
  397. */
  398. static void
  399. ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  400. {
  401. int ret;
  402. ret = ccw_device_cancel_halt_clear(cdev);
  403. switch (ret) {
  404. case 0:
  405. ccw_device_recog_done(cdev, DEV_STATE_BOXED);
  406. break;
  407. case -ENODEV:
  408. ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
  409. break;
  410. default:
  411. ccw_device_set_timeout(cdev, 3*HZ);
  412. }
  413. }
  414. static void
  415. ccw_device_nopath_notify(void *data)
  416. {
  417. struct ccw_device *cdev;
  418. struct subchannel *sch;
  419. int ret;
  420. cdev = (struct ccw_device *)data;
  421. sch = to_subchannel(cdev->dev.parent);
  422. /* Extra sanity. */
  423. if (sch->lpm)
  424. return;
  425. ret = (sch->driver && sch->driver->notify) ?
  426. sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0;
  427. if (!ret) {
  428. if (get_device(&sch->dev)) {
  429. /* Driver doesn't want to keep device. */
  430. cio_disable_subchannel(sch);
  431. if (get_device(&cdev->dev)) {
  432. PREPARE_WORK(&cdev->private->kick_work,
  433. ccw_device_call_sch_unregister,
  434. (void *)cdev);
  435. queue_work(ccw_device_work,
  436. &cdev->private->kick_work);
  437. } else
  438. put_device(&sch->dev);
  439. }
  440. } else {
  441. cio_disable_subchannel(sch);
  442. ccw_device_set_timeout(cdev, 0);
  443. cdev->private->flags.fake_irb = 0;
  444. cdev->private->state = DEV_STATE_DISCONNECTED;
  445. wake_up(&cdev->private->wait_q);
  446. }
  447. }
  448. void
  449. ccw_device_verify_done(struct ccw_device *cdev, int err)
  450. {
  451. cdev->private->flags.doverify = 0;
  452. switch (err) {
  453. case -EOPNOTSUPP: /* path grouping not supported, just set online. */
  454. cdev->private->options.pgroup = 0;
  455. case 0:
  456. ccw_device_done(cdev, DEV_STATE_ONLINE);
  457. /* Deliver fake irb to device driver, if needed. */
  458. if (cdev->private->flags.fake_irb) {
  459. memset(&cdev->private->irb, 0, sizeof(struct irb));
  460. cdev->private->irb.scsw = (struct scsw) {
  461. .cc = 1,
  462. .fctl = SCSW_FCTL_START_FUNC,
  463. .actl = SCSW_ACTL_START_PEND,
  464. .stctl = SCSW_STCTL_STATUS_PEND,
  465. };
  466. cdev->private->flags.fake_irb = 0;
  467. if (cdev->handler)
  468. cdev->handler(cdev, cdev->private->intparm,
  469. &cdev->private->irb);
  470. memset(&cdev->private->irb, 0, sizeof(struct irb));
  471. }
  472. break;
  473. case -ETIME:
  474. ccw_device_done(cdev, DEV_STATE_BOXED);
  475. break;
  476. default:
  477. PREPARE_WORK(&cdev->private->kick_work,
  478. ccw_device_nopath_notify, (void *)cdev);
  479. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  480. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  481. break;
  482. }
  483. }
  484. /*
  485. * Get device online.
  486. */
  487. int
  488. ccw_device_online(struct ccw_device *cdev)
  489. {
  490. struct subchannel *sch;
  491. int ret;
  492. if ((cdev->private->state != DEV_STATE_OFFLINE) &&
  493. (cdev->private->state != DEV_STATE_BOXED))
  494. return -EINVAL;
  495. sch = to_subchannel(cdev->dev.parent);
  496. if (css_init_done && !get_device(&cdev->dev))
  497. return -ENODEV;
  498. ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
  499. if (ret != 0) {
  500. /* Couldn't enable the subchannel for i/o. Sick device. */
  501. if (ret == -ENODEV)
  502. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  503. return ret;
  504. }
  505. /* Do we want to do path grouping? */
  506. if (!cdev->private->options.pgroup) {
  507. /* No, set state online immediately. */
  508. ccw_device_done(cdev, DEV_STATE_ONLINE);
  509. return 0;
  510. }
  511. /* Do a SensePGID first. */
  512. cdev->private->state = DEV_STATE_SENSE_PGID;
  513. ccw_device_sense_pgid_start(cdev);
  514. return 0;
  515. }
  516. void
  517. ccw_device_disband_done(struct ccw_device *cdev, int err)
  518. {
  519. switch (err) {
  520. case 0:
  521. ccw_device_done(cdev, DEV_STATE_OFFLINE);
  522. break;
  523. case -ETIME:
  524. ccw_device_done(cdev, DEV_STATE_BOXED);
  525. break;
  526. default:
  527. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  528. break;
  529. }
  530. }
  531. /*
  532. * Shutdown device.
  533. */
  534. int
  535. ccw_device_offline(struct ccw_device *cdev)
  536. {
  537. struct subchannel *sch;
  538. sch = to_subchannel(cdev->dev.parent);
  539. if (stsch(sch->irq, &sch->schib) || !sch->schib.pmcw.dnv)
  540. return -ENODEV;
  541. if (cdev->private->state != DEV_STATE_ONLINE) {
  542. if (sch->schib.scsw.actl != 0)
  543. return -EBUSY;
  544. return -EINVAL;
  545. }
  546. if (sch->schib.scsw.actl != 0)
  547. return -EBUSY;
  548. /* Are we doing path grouping? */
  549. if (!cdev->private->options.pgroup) {
  550. /* No, set state offline immediately. */
  551. ccw_device_done(cdev, DEV_STATE_OFFLINE);
  552. return 0;
  553. }
  554. /* Start Set Path Group commands. */
  555. cdev->private->state = DEV_STATE_DISBAND_PGID;
  556. ccw_device_disband_start(cdev);
  557. return 0;
  558. }
  559. /*
  560. * Handle timeout in device online/offline process.
  561. */
  562. static void
  563. ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  564. {
  565. int ret;
  566. ret = ccw_device_cancel_halt_clear(cdev);
  567. switch (ret) {
  568. case 0:
  569. ccw_device_done(cdev, DEV_STATE_BOXED);
  570. break;
  571. case -ENODEV:
  572. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  573. break;
  574. default:
  575. ccw_device_set_timeout(cdev, 3*HZ);
  576. }
  577. }
  578. /*
  579. * Handle not oper event in device recognition.
  580. */
  581. static void
  582. ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
  583. {
  584. ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
  585. }
  586. /*
  587. * Handle not operational event while offline.
  588. */
  589. static void
  590. ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
  591. {
  592. struct subchannel *sch;
  593. cdev->private->state = DEV_STATE_NOT_OPER;
  594. sch = to_subchannel(cdev->dev.parent);
  595. if (get_device(&cdev->dev)) {
  596. PREPARE_WORK(&cdev->private->kick_work,
  597. ccw_device_call_sch_unregister, (void *)cdev);
  598. queue_work(ccw_device_work, &cdev->private->kick_work);
  599. }
  600. wake_up(&cdev->private->wait_q);
  601. }
  602. /*
  603. * Handle not operational event while online.
  604. */
  605. static void
  606. ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
  607. {
  608. struct subchannel *sch;
  609. sch = to_subchannel(cdev->dev.parent);
  610. if (sch->driver->notify &&
  611. sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
  612. ccw_device_set_timeout(cdev, 0);
  613. cdev->private->flags.fake_irb = 0;
  614. cdev->private->state = DEV_STATE_DISCONNECTED;
  615. wake_up(&cdev->private->wait_q);
  616. return;
  617. }
  618. cdev->private->state = DEV_STATE_NOT_OPER;
  619. cio_disable_subchannel(sch);
  620. if (sch->schib.scsw.actl != 0) {
  621. // FIXME: not-oper indication to device driver ?
  622. ccw_device_call_handler(cdev);
  623. }
  624. if (get_device(&cdev->dev)) {
  625. PREPARE_WORK(&cdev->private->kick_work,
  626. ccw_device_call_sch_unregister, (void *)cdev);
  627. queue_work(ccw_device_work, &cdev->private->kick_work);
  628. }
  629. wake_up(&cdev->private->wait_q);
  630. }
  631. /*
  632. * Handle path verification event.
  633. */
  634. static void
  635. ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
  636. {
  637. struct subchannel *sch;
  638. if (!cdev->private->options.pgroup)
  639. return;
  640. if (cdev->private->state == DEV_STATE_W4SENSE) {
  641. cdev->private->flags.doverify = 1;
  642. return;
  643. }
  644. sch = to_subchannel(cdev->dev.parent);
  645. /*
  646. * Since we might not just be coming from an interrupt from the
  647. * subchannel we have to update the schib.
  648. */
  649. stsch(sch->irq, &sch->schib);
  650. if (sch->schib.scsw.actl != 0 ||
  651. (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
  652. /*
  653. * No final status yet or final status not yet delivered
  654. * to the device driver. Can't do path verfication now,
  655. * delay until final status was delivered.
  656. */
  657. cdev->private->flags.doverify = 1;
  658. return;
  659. }
  660. /* Device is idle, we can do the path verification. */
  661. cdev->private->state = DEV_STATE_VERIFY;
  662. ccw_device_verify_start(cdev);
  663. }
  664. /*
  665. * Got an interrupt for a normal io (state online).
  666. */
  667. static void
  668. ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
  669. {
  670. struct irb *irb;
  671. irb = (struct irb *) __LC_IRB;
  672. /* Check for unsolicited interrupt. */
  673. if ((irb->scsw.stctl ==
  674. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
  675. && (!irb->scsw.cc)) {
  676. if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
  677. !irb->esw.esw0.erw.cons) {
  678. /* Unit check but no sense data. Need basic sense. */
  679. if (ccw_device_do_sense(cdev, irb) != 0)
  680. goto call_handler_unsol;
  681. memcpy(irb, &cdev->private->irb, sizeof(struct irb));
  682. cdev->private->state = DEV_STATE_W4SENSE;
  683. cdev->private->intparm = 0;
  684. return;
  685. }
  686. call_handler_unsol:
  687. if (cdev->handler)
  688. cdev->handler (cdev, 0, irb);
  689. return;
  690. }
  691. /* Accumulate status and find out if a basic sense is needed. */
  692. ccw_device_accumulate_irb(cdev, irb);
  693. if (cdev->private->flags.dosense) {
  694. if (ccw_device_do_sense(cdev, irb) == 0) {
  695. cdev->private->state = DEV_STATE_W4SENSE;
  696. }
  697. return;
  698. }
  699. /* Call the handler. */
  700. if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
  701. /* Start delayed path verification. */
  702. ccw_device_online_verify(cdev, 0);
  703. }
  704. /*
  705. * Got an timeout in online state.
  706. */
  707. static void
  708. ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  709. {
  710. int ret;
  711. ccw_device_set_timeout(cdev, 0);
  712. ret = ccw_device_cancel_halt_clear(cdev);
  713. if (ret == -EBUSY) {
  714. ccw_device_set_timeout(cdev, 3*HZ);
  715. cdev->private->state = DEV_STATE_TIMEOUT_KILL;
  716. return;
  717. }
  718. if (ret == -ENODEV) {
  719. struct subchannel *sch;
  720. sch = to_subchannel(cdev->dev.parent);
  721. if (!sch->lpm) {
  722. PREPARE_WORK(&cdev->private->kick_work,
  723. ccw_device_nopath_notify, (void *)cdev);
  724. queue_work(ccw_device_notify_work,
  725. &cdev->private->kick_work);
  726. } else
  727. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  728. } else if (cdev->handler)
  729. cdev->handler(cdev, cdev->private->intparm,
  730. ERR_PTR(-ETIMEDOUT));
  731. }
  732. /*
  733. * Got an interrupt for a basic sense.
  734. */
  735. void
  736. ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
  737. {
  738. struct irb *irb;
  739. irb = (struct irb *) __LC_IRB;
  740. /* Check for unsolicited interrupt. */
  741. if (irb->scsw.stctl ==
  742. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
  743. if (irb->scsw.cc == 1)
  744. /* Basic sense hasn't started. Try again. */
  745. ccw_device_do_sense(cdev, irb);
  746. else {
  747. printk("Huh? %s(%s): unsolicited interrupt...\n",
  748. __FUNCTION__, cdev->dev.bus_id);
  749. if (cdev->handler)
  750. cdev->handler (cdev, 0, irb);
  751. }
  752. return;
  753. }
  754. /* Add basic sense info to irb. */
  755. ccw_device_accumulate_basic_sense(cdev, irb);
  756. if (cdev->private->flags.dosense) {
  757. /* Another basic sense is needed. */
  758. ccw_device_do_sense(cdev, irb);
  759. return;
  760. }
  761. cdev->private->state = DEV_STATE_ONLINE;
  762. /* Call the handler. */
  763. if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
  764. /* Start delayed path verification. */
  765. ccw_device_online_verify(cdev, 0);
  766. }
  767. static void
  768. ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
  769. {
  770. struct irb *irb;
  771. irb = (struct irb *) __LC_IRB;
  772. /* Accumulate status. We don't do basic sense. */
  773. ccw_device_accumulate_irb(cdev, irb);
  774. /* Try to start delayed device verification. */
  775. ccw_device_online_verify(cdev, 0);
  776. /* Note: Don't call handler for cio initiated clear! */
  777. }
  778. static void
  779. ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
  780. {
  781. struct subchannel *sch;
  782. sch = to_subchannel(cdev->dev.parent);
  783. ccw_device_set_timeout(cdev, 0);
  784. /* OK, i/o is dead now. Call interrupt handler. */
  785. cdev->private->state = DEV_STATE_ONLINE;
  786. if (cdev->handler)
  787. cdev->handler(cdev, cdev->private->intparm,
  788. ERR_PTR(-ETIMEDOUT));
  789. if (!sch->lpm) {
  790. PREPARE_WORK(&cdev->private->kick_work,
  791. ccw_device_nopath_notify, (void *)cdev);
  792. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  793. } else if (cdev->private->flags.doverify)
  794. /* Start delayed path verification. */
  795. ccw_device_online_verify(cdev, 0);
  796. }
  797. static void
  798. ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  799. {
  800. int ret;
  801. ret = ccw_device_cancel_halt_clear(cdev);
  802. if (ret == -EBUSY) {
  803. ccw_device_set_timeout(cdev, 3*HZ);
  804. return;
  805. }
  806. if (ret == -ENODEV) {
  807. struct subchannel *sch;
  808. sch = to_subchannel(cdev->dev.parent);
  809. if (!sch->lpm) {
  810. PREPARE_WORK(&cdev->private->kick_work,
  811. ccw_device_nopath_notify, (void *)cdev);
  812. queue_work(ccw_device_notify_work,
  813. &cdev->private->kick_work);
  814. } else
  815. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  816. return;
  817. }
  818. //FIXME: Can we get here?
  819. cdev->private->state = DEV_STATE_ONLINE;
  820. if (cdev->handler)
  821. cdev->handler(cdev, cdev->private->intparm,
  822. ERR_PTR(-ETIMEDOUT));
  823. }
  824. static void
  825. ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
  826. {
  827. struct irb *irb;
  828. struct subchannel *sch;
  829. irb = (struct irb *) __LC_IRB;
  830. /*
  831. * Accumulate status and find out if a basic sense is needed.
  832. * This is fine since we have already adapted the lpm.
  833. */
  834. ccw_device_accumulate_irb(cdev, irb);
  835. if (cdev->private->flags.dosense) {
  836. if (ccw_device_do_sense(cdev, irb) == 0) {
  837. cdev->private->state = DEV_STATE_W4SENSE;
  838. }
  839. return;
  840. }
  841. /* Iff device is idle, reset timeout. */
  842. sch = to_subchannel(cdev->dev.parent);
  843. if (!stsch(sch->irq, &sch->schib))
  844. if (sch->schib.scsw.actl == 0)
  845. ccw_device_set_timeout(cdev, 0);
  846. /* Call the handler. */
  847. ccw_device_call_handler(cdev);
  848. if (!sch->lpm) {
  849. PREPARE_WORK(&cdev->private->kick_work,
  850. ccw_device_nopath_notify, (void *)cdev);
  851. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  852. } else if (cdev->private->flags.doverify)
  853. ccw_device_online_verify(cdev, 0);
  854. }
  855. static void
  856. ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  857. {
  858. int ret;
  859. struct subchannel *sch;
  860. sch = to_subchannel(cdev->dev.parent);
  861. ccw_device_set_timeout(cdev, 0);
  862. ret = ccw_device_cancel_halt_clear(cdev);
  863. if (ret == -EBUSY) {
  864. ccw_device_set_timeout(cdev, 3*HZ);
  865. cdev->private->state = DEV_STATE_TIMEOUT_KILL;
  866. return;
  867. }
  868. if (ret == -ENODEV) {
  869. if (!sch->lpm) {
  870. PREPARE_WORK(&cdev->private->kick_work,
  871. ccw_device_nopath_notify, (void *)cdev);
  872. queue_work(ccw_device_notify_work,
  873. &cdev->private->kick_work);
  874. } else
  875. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  876. return;
  877. }
  878. if (cdev->handler)
  879. cdev->handler(cdev, cdev->private->intparm,
  880. ERR_PTR(-ETIMEDOUT));
  881. if (!sch->lpm) {
  882. PREPARE_WORK(&cdev->private->kick_work,
  883. ccw_device_nopath_notify, (void *)cdev);
  884. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  885. } else if (cdev->private->flags.doverify)
  886. /* Start delayed path verification. */
  887. ccw_device_online_verify(cdev, 0);
  888. }
  889. static void
  890. ccw_device_wait4io_verify(struct ccw_device *cdev, enum dev_event dev_event)
  891. {
  892. /* When the I/O has terminated, we have to start verification. */
  893. if (cdev->private->options.pgroup)
  894. cdev->private->flags.doverify = 1;
  895. }
  896. static void
  897. ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
  898. {
  899. struct irb *irb;
  900. switch (dev_event) {
  901. case DEV_EVENT_INTERRUPT:
  902. irb = (struct irb *) __LC_IRB;
  903. /* Check for unsolicited interrupt. */
  904. if ((irb->scsw.stctl ==
  905. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
  906. (!irb->scsw.cc))
  907. /* FIXME: we should restart stlck here, but this
  908. * is extremely unlikely ... */
  909. goto out_wakeup;
  910. ccw_device_accumulate_irb(cdev, irb);
  911. /* We don't care about basic sense etc. */
  912. break;
  913. default: /* timeout */
  914. break;
  915. }
  916. out_wakeup:
  917. wake_up(&cdev->private->wait_q);
  918. }
  919. static void
  920. ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
  921. {
  922. struct subchannel *sch;
  923. sch = to_subchannel(cdev->dev.parent);
  924. if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
  925. /* Couldn't enable the subchannel for i/o. Sick device. */
  926. return;
  927. /* After 60s the device recognition is considered to have failed. */
  928. ccw_device_set_timeout(cdev, 60*HZ);
  929. cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
  930. ccw_device_sense_id_start(cdev);
  931. }
  932. void
  933. device_trigger_reprobe(struct subchannel *sch)
  934. {
  935. struct ccw_device *cdev;
  936. if (!sch->dev.driver_data)
  937. return;
  938. cdev = sch->dev.driver_data;
  939. if (cdev->private->state != DEV_STATE_DISCONNECTED)
  940. return;
  941. /* Update some values. */
  942. if (stsch(sch->irq, &sch->schib))
  943. return;
  944. /*
  945. * The pim, pam, pom values may not be accurate, but they are the best
  946. * we have before performing device selection :/
  947. */
  948. sch->lpm = sch->schib.pmcw.pim &
  949. sch->schib.pmcw.pam &
  950. sch->schib.pmcw.pom &
  951. sch->opm;
  952. /* Re-set some bits in the pmcw that were lost. */
  953. sch->schib.pmcw.isc = 3;
  954. sch->schib.pmcw.csense = 1;
  955. sch->schib.pmcw.ena = 0;
  956. if ((sch->lpm & (sch->lpm - 1)) != 0)
  957. sch->schib.pmcw.mp = 1;
  958. sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
  959. /* We should also udate ssd info, but this has to wait. */
  960. ccw_device_start_id(cdev, 0);
  961. }
  962. static void
  963. ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
  964. {
  965. struct subchannel *sch;
  966. sch = to_subchannel(cdev->dev.parent);
  967. /*
  968. * An interrupt in state offline means a previous disable was not
  969. * successful. Try again.
  970. */
  971. cio_disable_subchannel(sch);
  972. }
  973. static void
  974. ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
  975. {
  976. retry_set_schib(cdev);
  977. cdev->private->state = DEV_STATE_ONLINE;
  978. dev_fsm_event(cdev, dev_event);
  979. }
  980. static void
  981. ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
  982. {
  983. ccw_device_set_timeout(cdev, 0);
  984. if (dev_event == DEV_EVENT_NOTOPER)
  985. cdev->private->state = DEV_STATE_NOT_OPER;
  986. else
  987. cdev->private->state = DEV_STATE_OFFLINE;
  988. wake_up(&cdev->private->wait_q);
  989. }
  990. static void
  991. ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  992. {
  993. int ret;
  994. ret = ccw_device_cancel_halt_clear(cdev);
  995. switch (ret) {
  996. case 0:
  997. cdev->private->state = DEV_STATE_OFFLINE;
  998. wake_up(&cdev->private->wait_q);
  999. break;
  1000. case -ENODEV:
  1001. cdev->private->state = DEV_STATE_NOT_OPER;
  1002. wake_up(&cdev->private->wait_q);
  1003. break;
  1004. default:
  1005. ccw_device_set_timeout(cdev, HZ/10);
  1006. }
  1007. }
  1008. /*
  1009. * No operation action. This is used e.g. to ignore a timeout event in
  1010. * state offline.
  1011. */
  1012. static void
  1013. ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
  1014. {
  1015. }
  1016. /*
  1017. * Bug operation action.
  1018. */
  1019. static void
  1020. ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
  1021. {
  1022. printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
  1023. cdev->private->state, dev_event);
  1024. BUG();
  1025. }
  1026. /*
  1027. * device statemachine
  1028. */
  1029. fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
  1030. [DEV_STATE_NOT_OPER] = {
  1031. [DEV_EVENT_NOTOPER] = ccw_device_nop,
  1032. [DEV_EVENT_INTERRUPT] = ccw_device_bug,
  1033. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1034. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1035. },
  1036. [DEV_STATE_SENSE_PGID] = {
  1037. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1038. [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
  1039. [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
  1040. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1041. },
  1042. [DEV_STATE_SENSE_ID] = {
  1043. [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
  1044. [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
  1045. [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
  1046. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1047. },
  1048. [DEV_STATE_OFFLINE] = {
  1049. [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
  1050. [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
  1051. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1052. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1053. },
  1054. [DEV_STATE_VERIFY] = {
  1055. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1056. [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
  1057. [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
  1058. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1059. },
  1060. [DEV_STATE_ONLINE] = {
  1061. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1062. [DEV_EVENT_INTERRUPT] = ccw_device_irq,
  1063. [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
  1064. [DEV_EVENT_VERIFY] = ccw_device_online_verify,
  1065. },
  1066. [DEV_STATE_W4SENSE] = {
  1067. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1068. [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
  1069. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1070. [DEV_EVENT_VERIFY] = ccw_device_online_verify,
  1071. },
  1072. [DEV_STATE_DISBAND_PGID] = {
  1073. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1074. [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
  1075. [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
  1076. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1077. },
  1078. [DEV_STATE_BOXED] = {
  1079. [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
  1080. [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
  1081. [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
  1082. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1083. },
  1084. /* states to wait for i/o completion before doing something */
  1085. [DEV_STATE_CLEAR_VERIFY] = {
  1086. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1087. [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
  1088. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1089. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1090. },
  1091. [DEV_STATE_TIMEOUT_KILL] = {
  1092. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1093. [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
  1094. [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
  1095. [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
  1096. },
  1097. [DEV_STATE_WAIT4IO] = {
  1098. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1099. [DEV_EVENT_INTERRUPT] = ccw_device_wait4io_irq,
  1100. [DEV_EVENT_TIMEOUT] = ccw_device_wait4io_timeout,
  1101. [DEV_EVENT_VERIFY] = ccw_device_wait4io_verify,
  1102. },
  1103. [DEV_STATE_QUIESCE] = {
  1104. [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
  1105. [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
  1106. [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
  1107. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1108. },
  1109. /* special states for devices gone not operational */
  1110. [DEV_STATE_DISCONNECTED] = {
  1111. [DEV_EVENT_NOTOPER] = ccw_device_nop,
  1112. [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
  1113. [DEV_EVENT_TIMEOUT] = ccw_device_bug,
  1114. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1115. },
  1116. [DEV_STATE_DISCONNECTED_SENSE_ID] = {
  1117. [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
  1118. [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
  1119. [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
  1120. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1121. },
  1122. [DEV_STATE_CMFCHANGE] = {
  1123. [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
  1124. [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
  1125. [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
  1126. [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
  1127. },
  1128. };
  1129. /*
  1130. * io_subchannel_irq is called for "real" interrupts or for status
  1131. * pending conditions on msch.
  1132. */
  1133. void
  1134. io_subchannel_irq (struct device *pdev)
  1135. {
  1136. struct ccw_device *cdev;
  1137. cdev = to_subchannel(pdev)->dev.driver_data;
  1138. CIO_TRACE_EVENT (3, "IRQ");
  1139. CIO_TRACE_EVENT (3, pdev->bus_id);
  1140. if (cdev)
  1141. dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
  1142. }
  1143. EXPORT_SYMBOL_GPL(ccw_device_set_timeout);