device_fsm.c 34 KB

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