device_fsm.c 35 KB

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