device_fsm.c 35 KB

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