device_fsm.c 33 KB

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