device_fsm.c 34 KB

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