device_fsm.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  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. cdev->private->flags.donotify = 0;
  630. if (get_device(&cdev->dev)) {
  631. PREPARE_WORK(&cdev->private->kick_work,
  632. ccw_device_call_sch_unregister);
  633. queue_work(ccw_device_work, &cdev->private->kick_work);
  634. }
  635. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  636. break;
  637. }
  638. }
  639. /*
  640. * Shutdown device.
  641. */
  642. int
  643. ccw_device_offline(struct ccw_device *cdev)
  644. {
  645. struct subchannel *sch;
  646. if (ccw_device_is_orphan(cdev)) {
  647. ccw_device_done(cdev, DEV_STATE_OFFLINE);
  648. return 0;
  649. }
  650. sch = to_subchannel(cdev->dev.parent);
  651. if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
  652. return -ENODEV;
  653. if (cdev->private->state != DEV_STATE_ONLINE) {
  654. if (sch->schib.scsw.actl != 0)
  655. return -EBUSY;
  656. return -EINVAL;
  657. }
  658. if (sch->schib.scsw.actl != 0)
  659. return -EBUSY;
  660. /* Are we doing path grouping? */
  661. if (!cdev->private->options.pgroup) {
  662. /* No, set state offline immediately. */
  663. ccw_device_done(cdev, DEV_STATE_OFFLINE);
  664. return 0;
  665. }
  666. /* Start Set Path Group commands. */
  667. cdev->private->state = DEV_STATE_DISBAND_PGID;
  668. ccw_device_disband_start(cdev);
  669. return 0;
  670. }
  671. /*
  672. * Handle timeout in device online/offline process.
  673. */
  674. static void
  675. ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  676. {
  677. int ret;
  678. ret = ccw_device_cancel_halt_clear(cdev);
  679. switch (ret) {
  680. case 0:
  681. ccw_device_done(cdev, DEV_STATE_BOXED);
  682. break;
  683. case -ENODEV:
  684. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  685. break;
  686. default:
  687. ccw_device_set_timeout(cdev, 3*HZ);
  688. }
  689. }
  690. /*
  691. * Handle not oper event in device recognition.
  692. */
  693. static void
  694. ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
  695. {
  696. ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
  697. }
  698. /*
  699. * Handle not operational event while offline.
  700. */
  701. static void
  702. ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
  703. {
  704. struct subchannel *sch;
  705. cdev->private->state = DEV_STATE_NOT_OPER;
  706. sch = to_subchannel(cdev->dev.parent);
  707. if (get_device(&cdev->dev)) {
  708. PREPARE_WORK(&cdev->private->kick_work,
  709. ccw_device_call_sch_unregister);
  710. queue_work(ccw_device_work, &cdev->private->kick_work);
  711. }
  712. wake_up(&cdev->private->wait_q);
  713. }
  714. /*
  715. * Handle not operational event while online.
  716. */
  717. static void
  718. ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
  719. {
  720. struct subchannel *sch;
  721. int ret;
  722. sch = to_subchannel(cdev->dev.parent);
  723. if (sch->driver->notify) {
  724. spin_unlock_irq(cdev->ccwlock);
  725. ret = sch->driver->notify(&sch->dev,
  726. sch->lpm ? CIO_GONE : CIO_NO_PATH);
  727. spin_lock_irq(cdev->ccwlock);
  728. } else
  729. ret = 0;
  730. if (ret) {
  731. ccw_device_set_timeout(cdev, 0);
  732. cdev->private->flags.fake_irb = 0;
  733. cdev->private->state = DEV_STATE_DISCONNECTED;
  734. wake_up(&cdev->private->wait_q);
  735. return;
  736. }
  737. cdev->private->state = DEV_STATE_NOT_OPER;
  738. cio_disable_subchannel(sch);
  739. if (sch->schib.scsw.actl != 0) {
  740. // FIXME: not-oper indication to device driver ?
  741. ccw_device_call_handler(cdev);
  742. }
  743. if (get_device(&cdev->dev)) {
  744. PREPARE_WORK(&cdev->private->kick_work,
  745. ccw_device_call_sch_unregister);
  746. queue_work(ccw_device_work, &cdev->private->kick_work);
  747. }
  748. wake_up(&cdev->private->wait_q);
  749. }
  750. /*
  751. * Handle path verification event.
  752. */
  753. static void
  754. ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
  755. {
  756. struct subchannel *sch;
  757. if (cdev->private->state == DEV_STATE_W4SENSE) {
  758. cdev->private->flags.doverify = 1;
  759. return;
  760. }
  761. sch = to_subchannel(cdev->dev.parent);
  762. /*
  763. * Since we might not just be coming from an interrupt from the
  764. * subchannel we have to update the schib.
  765. */
  766. stsch(sch->schid, &sch->schib);
  767. if (sch->schib.scsw.actl != 0 ||
  768. (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
  769. (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
  770. /*
  771. * No final status yet or final status not yet delivered
  772. * to the device driver. Can't do path verfication now,
  773. * delay until final status was delivered.
  774. */
  775. cdev->private->flags.doverify = 1;
  776. return;
  777. }
  778. /* Device is idle, we can do the path verification. */
  779. cdev->private->state = DEV_STATE_VERIFY;
  780. cdev->private->flags.doverify = 0;
  781. ccw_device_verify_start(cdev);
  782. }
  783. /*
  784. * Got an interrupt for a normal io (state online).
  785. */
  786. static void
  787. ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
  788. {
  789. struct irb *irb;
  790. irb = (struct irb *) __LC_IRB;
  791. /* Check for unsolicited interrupt. */
  792. if ((irb->scsw.stctl ==
  793. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
  794. && (!irb->scsw.cc)) {
  795. if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
  796. !irb->esw.esw0.erw.cons) {
  797. /* Unit check but no sense data. Need basic sense. */
  798. if (ccw_device_do_sense(cdev, irb) != 0)
  799. goto call_handler_unsol;
  800. memcpy(&cdev->private->irb, irb, sizeof(struct irb));
  801. cdev->private->state = DEV_STATE_W4SENSE;
  802. cdev->private->intparm = 0;
  803. return;
  804. }
  805. call_handler_unsol:
  806. if (cdev->handler)
  807. cdev->handler (cdev, 0, irb);
  808. if (cdev->private->flags.doverify)
  809. ccw_device_online_verify(cdev, 0);
  810. return;
  811. }
  812. /* Accumulate status and find out if a basic sense is needed. */
  813. ccw_device_accumulate_irb(cdev, irb);
  814. if (cdev->private->flags.dosense) {
  815. if (ccw_device_do_sense(cdev, irb) == 0) {
  816. cdev->private->state = DEV_STATE_W4SENSE;
  817. }
  818. return;
  819. }
  820. /* Call the handler. */
  821. if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
  822. /* Start delayed path verification. */
  823. ccw_device_online_verify(cdev, 0);
  824. }
  825. /*
  826. * Got an timeout in online state.
  827. */
  828. static void
  829. ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  830. {
  831. int ret;
  832. ccw_device_set_timeout(cdev, 0);
  833. ret = ccw_device_cancel_halt_clear(cdev);
  834. if (ret == -EBUSY) {
  835. ccw_device_set_timeout(cdev, 3*HZ);
  836. cdev->private->state = DEV_STATE_TIMEOUT_KILL;
  837. return;
  838. }
  839. if (ret == -ENODEV) {
  840. struct subchannel *sch;
  841. sch = to_subchannel(cdev->dev.parent);
  842. if (!sch->lpm) {
  843. PREPARE_WORK(&cdev->private->kick_work,
  844. ccw_device_nopath_notify);
  845. queue_work(ccw_device_notify_work,
  846. &cdev->private->kick_work);
  847. } else
  848. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  849. } else if (cdev->handler)
  850. cdev->handler(cdev, cdev->private->intparm,
  851. ERR_PTR(-ETIMEDOUT));
  852. }
  853. /*
  854. * Got an interrupt for a basic sense.
  855. */
  856. static void
  857. ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
  858. {
  859. struct irb *irb;
  860. irb = (struct irb *) __LC_IRB;
  861. /* Check for unsolicited interrupt. */
  862. if (irb->scsw.stctl ==
  863. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
  864. if (irb->scsw.cc == 1)
  865. /* Basic sense hasn't started. Try again. */
  866. ccw_device_do_sense(cdev, irb);
  867. else {
  868. printk(KERN_INFO "Huh? %s(%s): unsolicited "
  869. "interrupt...\n",
  870. __FUNCTION__, cdev->dev.bus_id);
  871. if (cdev->handler)
  872. cdev->handler (cdev, 0, irb);
  873. }
  874. return;
  875. }
  876. /*
  877. * Check if a halt or clear has been issued in the meanwhile. If yes,
  878. * only deliver the halt/clear interrupt to the device driver as if it
  879. * had killed the original request.
  880. */
  881. if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
  882. /* Retry Basic Sense if requested. */
  883. if (cdev->private->flags.intretry) {
  884. cdev->private->flags.intretry = 0;
  885. ccw_device_do_sense(cdev, irb);
  886. return;
  887. }
  888. cdev->private->flags.dosense = 0;
  889. memset(&cdev->private->irb, 0, sizeof(struct irb));
  890. ccw_device_accumulate_irb(cdev, irb);
  891. goto call_handler;
  892. }
  893. /* Add basic sense info to irb. */
  894. ccw_device_accumulate_basic_sense(cdev, irb);
  895. if (cdev->private->flags.dosense) {
  896. /* Another basic sense is needed. */
  897. ccw_device_do_sense(cdev, irb);
  898. return;
  899. }
  900. call_handler:
  901. cdev->private->state = DEV_STATE_ONLINE;
  902. /* Call the handler. */
  903. if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
  904. /* Start delayed path verification. */
  905. ccw_device_online_verify(cdev, 0);
  906. }
  907. static void
  908. ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
  909. {
  910. struct irb *irb;
  911. irb = (struct irb *) __LC_IRB;
  912. /* Accumulate status. We don't do basic sense. */
  913. ccw_device_accumulate_irb(cdev, irb);
  914. /* Remember to clear irb to avoid residuals. */
  915. memset(&cdev->private->irb, 0, sizeof(struct irb));
  916. /* Try to start delayed device verification. */
  917. ccw_device_online_verify(cdev, 0);
  918. /* Note: Don't call handler for cio initiated clear! */
  919. }
  920. static void
  921. ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
  922. {
  923. struct subchannel *sch;
  924. sch = to_subchannel(cdev->dev.parent);
  925. ccw_device_set_timeout(cdev, 0);
  926. /* Start delayed path verification. */
  927. ccw_device_online_verify(cdev, 0);
  928. /* OK, i/o is dead now. Call interrupt handler. */
  929. if (cdev->handler)
  930. cdev->handler(cdev, cdev->private->intparm,
  931. ERR_PTR(-EIO));
  932. }
  933. static void
  934. ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  935. {
  936. int ret;
  937. ret = ccw_device_cancel_halt_clear(cdev);
  938. if (ret == -EBUSY) {
  939. ccw_device_set_timeout(cdev, 3*HZ);
  940. return;
  941. }
  942. /* Start delayed path verification. */
  943. ccw_device_online_verify(cdev, 0);
  944. if (cdev->handler)
  945. cdev->handler(cdev, cdev->private->intparm,
  946. ERR_PTR(-EIO));
  947. }
  948. void device_kill_io(struct subchannel *sch)
  949. {
  950. int ret;
  951. struct ccw_device *cdev;
  952. cdev = sch->dev.driver_data;
  953. ret = ccw_device_cancel_halt_clear(cdev);
  954. if (ret == -EBUSY) {
  955. ccw_device_set_timeout(cdev, 3*HZ);
  956. cdev->private->state = DEV_STATE_TIMEOUT_KILL;
  957. return;
  958. }
  959. /* Start delayed path verification. */
  960. ccw_device_online_verify(cdev, 0);
  961. if (cdev->handler)
  962. cdev->handler(cdev, cdev->private->intparm,
  963. ERR_PTR(-EIO));
  964. }
  965. static void
  966. ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
  967. {
  968. /* Start verification after current task finished. */
  969. cdev->private->flags.doverify = 1;
  970. }
  971. static void
  972. ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
  973. {
  974. struct irb *irb;
  975. switch (dev_event) {
  976. case DEV_EVENT_INTERRUPT:
  977. irb = (struct irb *) __LC_IRB;
  978. /* Check for unsolicited interrupt. */
  979. if ((irb->scsw.stctl ==
  980. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
  981. (!irb->scsw.cc))
  982. /* FIXME: we should restart stlck here, but this
  983. * is extremely unlikely ... */
  984. goto out_wakeup;
  985. ccw_device_accumulate_irb(cdev, irb);
  986. /* We don't care about basic sense etc. */
  987. break;
  988. default: /* timeout */
  989. break;
  990. }
  991. out_wakeup:
  992. wake_up(&cdev->private->wait_q);
  993. }
  994. static void
  995. ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
  996. {
  997. struct subchannel *sch;
  998. sch = to_subchannel(cdev->dev.parent);
  999. if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
  1000. /* Couldn't enable the subchannel for i/o. Sick device. */
  1001. return;
  1002. /* After 60s the device recognition is considered to have failed. */
  1003. ccw_device_set_timeout(cdev, 60*HZ);
  1004. cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
  1005. ccw_device_sense_id_start(cdev);
  1006. }
  1007. void
  1008. device_trigger_reprobe(struct subchannel *sch)
  1009. {
  1010. struct ccw_device *cdev;
  1011. if (!sch->dev.driver_data)
  1012. return;
  1013. cdev = sch->dev.driver_data;
  1014. if (cdev->private->state != DEV_STATE_DISCONNECTED)
  1015. return;
  1016. /* Update some values. */
  1017. if (stsch(sch->schid, &sch->schib))
  1018. return;
  1019. if (!sch->schib.pmcw.dnv)
  1020. return;
  1021. /*
  1022. * The pim, pam, pom values may not be accurate, but they are the best
  1023. * we have before performing device selection :/
  1024. */
  1025. sch->lpm = sch->schib.pmcw.pam & sch->opm;
  1026. /* Re-set some bits in the pmcw that were lost. */
  1027. sch->schib.pmcw.isc = 3;
  1028. sch->schib.pmcw.csense = 1;
  1029. sch->schib.pmcw.ena = 0;
  1030. if ((sch->lpm & (sch->lpm - 1)) != 0)
  1031. sch->schib.pmcw.mp = 1;
  1032. sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
  1033. /* We should also udate ssd info, but this has to wait. */
  1034. /* Check if this is another device which appeared on the same sch. */
  1035. if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
  1036. PREPARE_WORK(&cdev->private->kick_work,
  1037. ccw_device_move_to_orphanage);
  1038. queue_work(ccw_device_work, &cdev->private->kick_work);
  1039. } else
  1040. ccw_device_start_id(cdev, 0);
  1041. }
  1042. static void
  1043. ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
  1044. {
  1045. struct subchannel *sch;
  1046. sch = to_subchannel(cdev->dev.parent);
  1047. /*
  1048. * An interrupt in state offline means a previous disable was not
  1049. * successful. Try again.
  1050. */
  1051. cio_disable_subchannel(sch);
  1052. }
  1053. static void
  1054. ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
  1055. {
  1056. retry_set_schib(cdev);
  1057. cdev->private->state = DEV_STATE_ONLINE;
  1058. dev_fsm_event(cdev, dev_event);
  1059. }
  1060. static void ccw_device_update_cmfblock(struct ccw_device *cdev,
  1061. enum dev_event dev_event)
  1062. {
  1063. cmf_retry_copy_block(cdev);
  1064. cdev->private->state = DEV_STATE_ONLINE;
  1065. dev_fsm_event(cdev, dev_event);
  1066. }
  1067. static void
  1068. ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
  1069. {
  1070. ccw_device_set_timeout(cdev, 0);
  1071. if (dev_event == DEV_EVENT_NOTOPER)
  1072. cdev->private->state = DEV_STATE_NOT_OPER;
  1073. else
  1074. cdev->private->state = DEV_STATE_OFFLINE;
  1075. wake_up(&cdev->private->wait_q);
  1076. }
  1077. static void
  1078. ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  1079. {
  1080. int ret;
  1081. ret = ccw_device_cancel_halt_clear(cdev);
  1082. switch (ret) {
  1083. case 0:
  1084. cdev->private->state = DEV_STATE_OFFLINE;
  1085. wake_up(&cdev->private->wait_q);
  1086. break;
  1087. case -ENODEV:
  1088. cdev->private->state = DEV_STATE_NOT_OPER;
  1089. wake_up(&cdev->private->wait_q);
  1090. break;
  1091. default:
  1092. ccw_device_set_timeout(cdev, HZ/10);
  1093. }
  1094. }
  1095. /*
  1096. * No operation action. This is used e.g. to ignore a timeout event in
  1097. * state offline.
  1098. */
  1099. static void
  1100. ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
  1101. {
  1102. }
  1103. /*
  1104. * Bug operation action.
  1105. */
  1106. static void
  1107. ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
  1108. {
  1109. printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
  1110. cdev->private->state, dev_event);
  1111. BUG();
  1112. }
  1113. /*
  1114. * device statemachine
  1115. */
  1116. fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
  1117. [DEV_STATE_NOT_OPER] = {
  1118. [DEV_EVENT_NOTOPER] = ccw_device_nop,
  1119. [DEV_EVENT_INTERRUPT] = ccw_device_bug,
  1120. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1121. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1122. },
  1123. [DEV_STATE_SENSE_PGID] = {
  1124. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1125. [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
  1126. [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
  1127. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1128. },
  1129. [DEV_STATE_SENSE_ID] = {
  1130. [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
  1131. [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
  1132. [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
  1133. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1134. },
  1135. [DEV_STATE_OFFLINE] = {
  1136. [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
  1137. [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
  1138. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1139. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1140. },
  1141. [DEV_STATE_VERIFY] = {
  1142. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1143. [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
  1144. [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
  1145. [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
  1146. },
  1147. [DEV_STATE_ONLINE] = {
  1148. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1149. [DEV_EVENT_INTERRUPT] = ccw_device_irq,
  1150. [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
  1151. [DEV_EVENT_VERIFY] = ccw_device_online_verify,
  1152. },
  1153. [DEV_STATE_W4SENSE] = {
  1154. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1155. [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
  1156. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1157. [DEV_EVENT_VERIFY] = ccw_device_online_verify,
  1158. },
  1159. [DEV_STATE_DISBAND_PGID] = {
  1160. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1161. [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
  1162. [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
  1163. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1164. },
  1165. [DEV_STATE_BOXED] = {
  1166. [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
  1167. [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
  1168. [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
  1169. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1170. },
  1171. /* states to wait for i/o completion before doing something */
  1172. [DEV_STATE_CLEAR_VERIFY] = {
  1173. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1174. [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
  1175. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1176. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1177. },
  1178. [DEV_STATE_TIMEOUT_KILL] = {
  1179. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1180. [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
  1181. [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
  1182. [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
  1183. },
  1184. [DEV_STATE_QUIESCE] = {
  1185. [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
  1186. [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
  1187. [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
  1188. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1189. },
  1190. /* special states for devices gone not operational */
  1191. [DEV_STATE_DISCONNECTED] = {
  1192. [DEV_EVENT_NOTOPER] = ccw_device_nop,
  1193. [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
  1194. [DEV_EVENT_TIMEOUT] = ccw_device_bug,
  1195. [DEV_EVENT_VERIFY] = ccw_device_start_id,
  1196. },
  1197. [DEV_STATE_DISCONNECTED_SENSE_ID] = {
  1198. [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
  1199. [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
  1200. [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
  1201. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1202. },
  1203. [DEV_STATE_CMFCHANGE] = {
  1204. [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
  1205. [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
  1206. [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
  1207. [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
  1208. },
  1209. [DEV_STATE_CMFUPDATE] = {
  1210. [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
  1211. [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
  1212. [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
  1213. [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
  1214. },
  1215. };
  1216. /*
  1217. * io_subchannel_irq is called for "real" interrupts or for status
  1218. * pending conditions on msch.
  1219. */
  1220. void
  1221. io_subchannel_irq (struct device *pdev)
  1222. {
  1223. struct ccw_device *cdev;
  1224. cdev = to_subchannel(pdev)->dev.driver_data;
  1225. CIO_TRACE_EVENT (3, "IRQ");
  1226. CIO_TRACE_EVENT (3, pdev->bus_id);
  1227. if (cdev)
  1228. dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
  1229. }
  1230. EXPORT_SYMBOL_GPL(ccw_device_set_timeout);