device_fsm.c 34 KB

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