device_fsm.c 36 KB

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