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