device_fsm.c 36 KB

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