device_fsm.c 35 KB

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