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