device_fsm.c 35 KB

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