device_fsm.c 35 KB

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