device_fsm.c 35 KB

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