device_fsm.c 35 KB

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