device_fsm.c 35 KB

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