device_fsm.c 36 KB

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