device_fsm.c 34 KB

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