device_fsm.c 35 KB

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