device_fsm.c 35 KB

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