device_fsm.c 34 KB

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