device_fsm.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  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(cohuck@de.ibm.com)
  8. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  9. */
  10. #include <linux/module.h>
  11. #include <linux/config.h>
  12. #include <linux/init.h>
  13. #include <asm/ccwdev.h>
  14. #include <asm/qdio.h>
  15. #include "cio.h"
  16. #include "cio_debug.h"
  17. #include "css.h"
  18. #include "device.h"
  19. #include "chsc.h"
  20. #include "ioasm.h"
  21. #include "qdio.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->irq, &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->irq, &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 %04x\n",
  235. cdev->private->devno, sch->irq);
  236. break;
  237. case DEV_STATE_OFFLINE:
  238. if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
  239. same_dev = ccw_device_handle_oper(cdev);
  240. notify = 1;
  241. }
  242. /* fill out sense information */
  243. cdev->id = (struct ccw_device_id) {
  244. .cu_type = cdev->private->senseid.cu_type,
  245. .cu_model = cdev->private->senseid.cu_model,
  246. .dev_type = cdev->private->senseid.dev_type,
  247. .dev_model = cdev->private->senseid.dev_model,
  248. };
  249. if (notify) {
  250. cdev->private->state = DEV_STATE_OFFLINE;
  251. if (same_dev) {
  252. /* Get device online again. */
  253. ccw_device_online(cdev);
  254. wake_up(&cdev->private->wait_q);
  255. }
  256. return;
  257. }
  258. /* Issue device info message. */
  259. CIO_DEBUG(KERN_INFO, 2, "SenseID : device %04x reports: "
  260. "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
  261. "%04X/%02X\n", cdev->private->devno,
  262. cdev->id.cu_type, cdev->id.cu_model,
  263. cdev->id.dev_type, cdev->id.dev_model);
  264. break;
  265. case DEV_STATE_BOXED:
  266. CIO_DEBUG(KERN_WARNING, 2,
  267. "SenseID : boxed device %04x on subchannel %04x\n",
  268. cdev->private->devno, sch->irq);
  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. wake_up(&cdev->private->wait_q);
  309. }
  310. /*
  311. * Finished with online/offline processing.
  312. */
  313. static void
  314. ccw_device_done(struct ccw_device *cdev, int state)
  315. {
  316. struct subchannel *sch;
  317. sch = to_subchannel(cdev->dev.parent);
  318. if (state != DEV_STATE_ONLINE)
  319. cio_disable_subchannel(sch);
  320. /* Reset device status. */
  321. memset(&cdev->private->irb, 0, sizeof(struct irb));
  322. cdev->private->state = state;
  323. if (state == DEV_STATE_BOXED)
  324. CIO_DEBUG(KERN_WARNING, 2,
  325. "Boxed device %04x on subchannel %04x\n",
  326. cdev->private->devno, sch->irq);
  327. if (cdev->private->flags.donotify) {
  328. cdev->private->flags.donotify = 0;
  329. PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,
  330. (void *)cdev);
  331. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  332. }
  333. wake_up(&cdev->private->wait_q);
  334. if (css_init_done && state != DEV_STATE_ONLINE)
  335. put_device (&cdev->dev);
  336. }
  337. /*
  338. * Function called from device_pgid.c after sense path ground has completed.
  339. */
  340. void
  341. ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
  342. {
  343. struct subchannel *sch;
  344. sch = to_subchannel(cdev->dev.parent);
  345. switch (err) {
  346. case 0:
  347. /* Start Path Group verification. */
  348. sch->vpm = 0; /* Start with no path groups set. */
  349. cdev->private->state = DEV_STATE_VERIFY;
  350. ccw_device_verify_start(cdev);
  351. break;
  352. case -ETIME: /* Sense path group id stopped by timeout. */
  353. case -EUSERS: /* device is reserved for someone else. */
  354. ccw_device_done(cdev, DEV_STATE_BOXED);
  355. break;
  356. case -EOPNOTSUPP: /* path grouping not supported, just set online. */
  357. cdev->private->options.pgroup = 0;
  358. ccw_device_done(cdev, DEV_STATE_ONLINE);
  359. break;
  360. default:
  361. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  362. break;
  363. }
  364. }
  365. /*
  366. * Start device recognition.
  367. */
  368. int
  369. ccw_device_recognition(struct ccw_device *cdev)
  370. {
  371. struct subchannel *sch;
  372. int ret;
  373. if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
  374. (cdev->private->state != DEV_STATE_BOXED))
  375. return -EINVAL;
  376. sch = to_subchannel(cdev->dev.parent);
  377. ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
  378. if (ret != 0)
  379. /* Couldn't enable the subchannel for i/o. Sick device. */
  380. return ret;
  381. /* After 60s the device recognition is considered to have failed. */
  382. ccw_device_set_timeout(cdev, 60*HZ);
  383. /*
  384. * We used to start here with a sense pgid to find out whether a device
  385. * is locked by someone else. Unfortunately, the sense pgid command
  386. * code has other meanings on devices predating the path grouping
  387. * algorithm, so we start with sense id and box the device after an
  388. * timeout (or if sense pgid during path verification detects the device
  389. * is locked, as may happen on newer devices).
  390. */
  391. cdev->private->flags.recog_done = 0;
  392. cdev->private->state = DEV_STATE_SENSE_ID;
  393. ccw_device_sense_id_start(cdev);
  394. return 0;
  395. }
  396. /*
  397. * Handle timeout in device recognition.
  398. */
  399. static void
  400. ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  401. {
  402. int ret;
  403. ret = ccw_device_cancel_halt_clear(cdev);
  404. switch (ret) {
  405. case 0:
  406. ccw_device_recog_done(cdev, DEV_STATE_BOXED);
  407. break;
  408. case -ENODEV:
  409. ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
  410. break;
  411. default:
  412. ccw_device_set_timeout(cdev, 3*HZ);
  413. }
  414. }
  415. static void
  416. ccw_device_nopath_notify(void *data)
  417. {
  418. struct ccw_device *cdev;
  419. struct subchannel *sch;
  420. int ret;
  421. cdev = (struct ccw_device *)data;
  422. sch = to_subchannel(cdev->dev.parent);
  423. /* Extra sanity. */
  424. if (sch->lpm)
  425. return;
  426. ret = (sch->driver && sch->driver->notify) ?
  427. sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0;
  428. if (!ret) {
  429. if (get_device(&sch->dev)) {
  430. /* Driver doesn't want to keep device. */
  431. cio_disable_subchannel(sch);
  432. if (get_device(&cdev->dev)) {
  433. PREPARE_WORK(&cdev->private->kick_work,
  434. ccw_device_call_sch_unregister,
  435. (void *)cdev);
  436. queue_work(ccw_device_work,
  437. &cdev->private->kick_work);
  438. } else
  439. put_device(&sch->dev);
  440. }
  441. } else {
  442. cio_disable_subchannel(sch);
  443. ccw_device_set_timeout(cdev, 0);
  444. cdev->private->flags.fake_irb = 0;
  445. cdev->private->state = DEV_STATE_DISCONNECTED;
  446. wake_up(&cdev->private->wait_q);
  447. }
  448. }
  449. void
  450. ccw_device_verify_done(struct ccw_device *cdev, int err)
  451. {
  452. cdev->private->flags.doverify = 0;
  453. switch (err) {
  454. case -EOPNOTSUPP: /* path grouping not supported, just set online. */
  455. cdev->private->options.pgroup = 0;
  456. case 0:
  457. ccw_device_done(cdev, DEV_STATE_ONLINE);
  458. /* Deliver fake irb to device driver, if needed. */
  459. if (cdev->private->flags.fake_irb) {
  460. memset(&cdev->private->irb, 0, sizeof(struct irb));
  461. cdev->private->irb.scsw = (struct scsw) {
  462. .cc = 1,
  463. .fctl = SCSW_FCTL_START_FUNC,
  464. .actl = SCSW_ACTL_START_PEND,
  465. .stctl = SCSW_STCTL_STATUS_PEND,
  466. };
  467. cdev->private->flags.fake_irb = 0;
  468. if (cdev->handler)
  469. cdev->handler(cdev, cdev->private->intparm,
  470. &cdev->private->irb);
  471. memset(&cdev->private->irb, 0, sizeof(struct irb));
  472. }
  473. break;
  474. case -ETIME:
  475. ccw_device_done(cdev, DEV_STATE_BOXED);
  476. break;
  477. default:
  478. PREPARE_WORK(&cdev->private->kick_work,
  479. ccw_device_nopath_notify, (void *)cdev);
  480. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  481. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  482. break;
  483. }
  484. }
  485. /*
  486. * Get device online.
  487. */
  488. int
  489. ccw_device_online(struct ccw_device *cdev)
  490. {
  491. struct subchannel *sch;
  492. int ret;
  493. if ((cdev->private->state != DEV_STATE_OFFLINE) &&
  494. (cdev->private->state != DEV_STATE_BOXED))
  495. return -EINVAL;
  496. sch = to_subchannel(cdev->dev.parent);
  497. if (css_init_done && !get_device(&cdev->dev))
  498. return -ENODEV;
  499. ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
  500. if (ret != 0) {
  501. /* Couldn't enable the subchannel for i/o. Sick device. */
  502. if (ret == -ENODEV)
  503. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  504. return ret;
  505. }
  506. /* Do we want to do path grouping? */
  507. if (!cdev->private->options.pgroup) {
  508. /* No, set state online immediately. */
  509. ccw_device_done(cdev, DEV_STATE_ONLINE);
  510. return 0;
  511. }
  512. /* Do a SensePGID first. */
  513. cdev->private->state = DEV_STATE_SENSE_PGID;
  514. ccw_device_sense_pgid_start(cdev);
  515. return 0;
  516. }
  517. void
  518. ccw_device_disband_done(struct ccw_device *cdev, int err)
  519. {
  520. switch (err) {
  521. case 0:
  522. ccw_device_done(cdev, DEV_STATE_OFFLINE);
  523. break;
  524. case -ETIME:
  525. ccw_device_done(cdev, DEV_STATE_BOXED);
  526. break;
  527. default:
  528. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  529. break;
  530. }
  531. }
  532. /*
  533. * Shutdown device.
  534. */
  535. int
  536. ccw_device_offline(struct ccw_device *cdev)
  537. {
  538. struct subchannel *sch;
  539. sch = to_subchannel(cdev->dev.parent);
  540. if (stsch(sch->irq, &sch->schib) || !sch->schib.pmcw.dnv)
  541. return -ENODEV;
  542. if (cdev->private->state != DEV_STATE_ONLINE) {
  543. if (sch->schib.scsw.actl != 0)
  544. return -EBUSY;
  545. return -EINVAL;
  546. }
  547. if (sch->schib.scsw.actl != 0)
  548. return -EBUSY;
  549. /* Are we doing path grouping? */
  550. if (!cdev->private->options.pgroup) {
  551. /* No, set state offline immediately. */
  552. ccw_device_done(cdev, DEV_STATE_OFFLINE);
  553. return 0;
  554. }
  555. /* Start Set Path Group commands. */
  556. cdev->private->state = DEV_STATE_DISBAND_PGID;
  557. ccw_device_disband_start(cdev);
  558. return 0;
  559. }
  560. /*
  561. * Handle timeout in device online/offline process.
  562. */
  563. static void
  564. ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  565. {
  566. int ret;
  567. ret = ccw_device_cancel_halt_clear(cdev);
  568. switch (ret) {
  569. case 0:
  570. ccw_device_done(cdev, DEV_STATE_BOXED);
  571. break;
  572. case -ENODEV:
  573. ccw_device_done(cdev, DEV_STATE_NOT_OPER);
  574. break;
  575. default:
  576. ccw_device_set_timeout(cdev, 3*HZ);
  577. }
  578. }
  579. /*
  580. * Handle not oper event in device recognition.
  581. */
  582. static void
  583. ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
  584. {
  585. ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
  586. }
  587. /*
  588. * Handle not operational event while offline.
  589. */
  590. static void
  591. ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
  592. {
  593. struct subchannel *sch;
  594. cdev->private->state = DEV_STATE_NOT_OPER;
  595. sch = to_subchannel(cdev->dev.parent);
  596. if (get_device(&cdev->dev)) {
  597. PREPARE_WORK(&cdev->private->kick_work,
  598. ccw_device_call_sch_unregister, (void *)cdev);
  599. queue_work(ccw_device_work, &cdev->private->kick_work);
  600. }
  601. wake_up(&cdev->private->wait_q);
  602. }
  603. /*
  604. * Handle not operational event while online.
  605. */
  606. static void
  607. ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
  608. {
  609. struct subchannel *sch;
  610. sch = to_subchannel(cdev->dev.parent);
  611. if (sch->driver->notify &&
  612. sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
  613. ccw_device_set_timeout(cdev, 0);
  614. cdev->private->flags.fake_irb = 0;
  615. cdev->private->state = DEV_STATE_DISCONNECTED;
  616. wake_up(&cdev->private->wait_q);
  617. return;
  618. }
  619. cdev->private->state = DEV_STATE_NOT_OPER;
  620. cio_disable_subchannel(sch);
  621. if (sch->schib.scsw.actl != 0) {
  622. // FIXME: not-oper indication to device driver ?
  623. ccw_device_call_handler(cdev);
  624. }
  625. if (get_device(&cdev->dev)) {
  626. PREPARE_WORK(&cdev->private->kick_work,
  627. ccw_device_call_sch_unregister, (void *)cdev);
  628. queue_work(ccw_device_work, &cdev->private->kick_work);
  629. }
  630. wake_up(&cdev->private->wait_q);
  631. }
  632. /*
  633. * Handle path verification event.
  634. */
  635. static void
  636. ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
  637. {
  638. struct subchannel *sch;
  639. if (!cdev->private->options.pgroup)
  640. return;
  641. if (cdev->private->state == DEV_STATE_W4SENSE) {
  642. cdev->private->flags.doverify = 1;
  643. return;
  644. }
  645. sch = to_subchannel(cdev->dev.parent);
  646. /*
  647. * Since we might not just be coming from an interrupt from the
  648. * subchannel we have to update the schib.
  649. */
  650. stsch(sch->irq, &sch->schib);
  651. if (sch->schib.scsw.actl != 0 ||
  652. (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
  653. /*
  654. * No final status yet or final status not yet delivered
  655. * to the device driver. Can't do path verfication now,
  656. * delay until final status was delivered.
  657. */
  658. cdev->private->flags.doverify = 1;
  659. return;
  660. }
  661. /* Device is idle, we can do the path verification. */
  662. cdev->private->state = DEV_STATE_VERIFY;
  663. ccw_device_verify_start(cdev);
  664. }
  665. /*
  666. * Got an interrupt for a normal io (state online).
  667. */
  668. static void
  669. ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
  670. {
  671. struct irb *irb;
  672. irb = (struct irb *) __LC_IRB;
  673. /* Check for unsolicited interrupt. */
  674. if ((irb->scsw.stctl ==
  675. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
  676. && (!irb->scsw.cc)) {
  677. if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
  678. !irb->esw.esw0.erw.cons) {
  679. /* Unit check but no sense data. Need basic sense. */
  680. if (ccw_device_do_sense(cdev, irb) != 0)
  681. goto call_handler_unsol;
  682. memcpy(irb, &cdev->private->irb, sizeof(struct irb));
  683. cdev->private->state = DEV_STATE_W4SENSE;
  684. cdev->private->intparm = 0;
  685. return;
  686. }
  687. call_handler_unsol:
  688. if (cdev->handler)
  689. cdev->handler (cdev, 0, irb);
  690. return;
  691. }
  692. /* Accumulate status and find out if a basic sense is needed. */
  693. ccw_device_accumulate_irb(cdev, irb);
  694. if (cdev->private->flags.dosense) {
  695. if (ccw_device_do_sense(cdev, irb) == 0) {
  696. cdev->private->state = DEV_STATE_W4SENSE;
  697. }
  698. return;
  699. }
  700. /* Call the handler. */
  701. if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
  702. /* Start delayed path verification. */
  703. ccw_device_online_verify(cdev, 0);
  704. }
  705. /*
  706. * Got an timeout in online state.
  707. */
  708. static void
  709. ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  710. {
  711. int ret;
  712. ccw_device_set_timeout(cdev, 0);
  713. ret = ccw_device_cancel_halt_clear(cdev);
  714. if (ret == -EBUSY) {
  715. ccw_device_set_timeout(cdev, 3*HZ);
  716. cdev->private->state = DEV_STATE_TIMEOUT_KILL;
  717. return;
  718. }
  719. if (ret == -ENODEV) {
  720. struct subchannel *sch;
  721. sch = to_subchannel(cdev->dev.parent);
  722. if (!sch->lpm) {
  723. PREPARE_WORK(&cdev->private->kick_work,
  724. ccw_device_nopath_notify, (void *)cdev);
  725. queue_work(ccw_device_notify_work,
  726. &cdev->private->kick_work);
  727. } else
  728. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  729. } else if (cdev->handler)
  730. cdev->handler(cdev, cdev->private->intparm,
  731. ERR_PTR(-ETIMEDOUT));
  732. }
  733. /*
  734. * Got an interrupt for a basic sense.
  735. */
  736. void
  737. ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
  738. {
  739. struct irb *irb;
  740. irb = (struct irb *) __LC_IRB;
  741. /* Check for unsolicited interrupt. */
  742. if (irb->scsw.stctl ==
  743. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
  744. if (irb->scsw.cc == 1)
  745. /* Basic sense hasn't started. Try again. */
  746. ccw_device_do_sense(cdev, irb);
  747. else {
  748. printk("Huh? %s(%s): unsolicited interrupt...\n",
  749. __FUNCTION__, cdev->dev.bus_id);
  750. if (cdev->handler)
  751. cdev->handler (cdev, 0, irb);
  752. }
  753. return;
  754. }
  755. /* Add basic sense info to irb. */
  756. ccw_device_accumulate_basic_sense(cdev, irb);
  757. if (cdev->private->flags.dosense) {
  758. /* Another basic sense is needed. */
  759. ccw_device_do_sense(cdev, irb);
  760. return;
  761. }
  762. cdev->private->state = DEV_STATE_ONLINE;
  763. /* Call the handler. */
  764. if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
  765. /* Start delayed path verification. */
  766. ccw_device_online_verify(cdev, 0);
  767. }
  768. static void
  769. ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
  770. {
  771. struct irb *irb;
  772. irb = (struct irb *) __LC_IRB;
  773. /* Accumulate status. We don't do basic sense. */
  774. ccw_device_accumulate_irb(cdev, irb);
  775. /* Try to start delayed device verification. */
  776. ccw_device_online_verify(cdev, 0);
  777. /* Note: Don't call handler for cio initiated clear! */
  778. }
  779. static void
  780. ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
  781. {
  782. struct subchannel *sch;
  783. sch = to_subchannel(cdev->dev.parent);
  784. ccw_device_set_timeout(cdev, 0);
  785. /* OK, i/o is dead now. Call interrupt handler. */
  786. cdev->private->state = DEV_STATE_ONLINE;
  787. if (cdev->handler)
  788. cdev->handler(cdev, cdev->private->intparm,
  789. ERR_PTR(-ETIMEDOUT));
  790. if (!sch->lpm) {
  791. PREPARE_WORK(&cdev->private->kick_work,
  792. ccw_device_nopath_notify, (void *)cdev);
  793. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  794. } else if (cdev->private->flags.doverify)
  795. /* Start delayed path verification. */
  796. ccw_device_online_verify(cdev, 0);
  797. }
  798. static void
  799. ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  800. {
  801. int ret;
  802. ret = ccw_device_cancel_halt_clear(cdev);
  803. if (ret == -EBUSY) {
  804. ccw_device_set_timeout(cdev, 3*HZ);
  805. return;
  806. }
  807. if (ret == -ENODEV) {
  808. struct subchannel *sch;
  809. sch = to_subchannel(cdev->dev.parent);
  810. if (!sch->lpm) {
  811. PREPARE_WORK(&cdev->private->kick_work,
  812. ccw_device_nopath_notify, (void *)cdev);
  813. queue_work(ccw_device_notify_work,
  814. &cdev->private->kick_work);
  815. } else
  816. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  817. return;
  818. }
  819. //FIXME: Can we get here?
  820. cdev->private->state = DEV_STATE_ONLINE;
  821. if (cdev->handler)
  822. cdev->handler(cdev, cdev->private->intparm,
  823. ERR_PTR(-ETIMEDOUT));
  824. }
  825. static void
  826. ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
  827. {
  828. struct irb *irb;
  829. struct subchannel *sch;
  830. irb = (struct irb *) __LC_IRB;
  831. /*
  832. * Accumulate status and find out if a basic sense is needed.
  833. * This is fine since we have already adapted the lpm.
  834. */
  835. ccw_device_accumulate_irb(cdev, irb);
  836. if (cdev->private->flags.dosense) {
  837. if (ccw_device_do_sense(cdev, irb) == 0) {
  838. cdev->private->state = DEV_STATE_W4SENSE;
  839. }
  840. return;
  841. }
  842. /* Iff device is idle, reset timeout. */
  843. sch = to_subchannel(cdev->dev.parent);
  844. if (!stsch(sch->irq, &sch->schib))
  845. if (sch->schib.scsw.actl == 0)
  846. ccw_device_set_timeout(cdev, 0);
  847. /* Call the handler. */
  848. ccw_device_call_handler(cdev);
  849. if (!sch->lpm) {
  850. PREPARE_WORK(&cdev->private->kick_work,
  851. ccw_device_nopath_notify, (void *)cdev);
  852. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  853. } else if (cdev->private->flags.doverify)
  854. ccw_device_online_verify(cdev, 0);
  855. }
  856. static void
  857. ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  858. {
  859. int ret;
  860. struct subchannel *sch;
  861. sch = to_subchannel(cdev->dev.parent);
  862. ccw_device_set_timeout(cdev, 0);
  863. ret = ccw_device_cancel_halt_clear(cdev);
  864. if (ret == -EBUSY) {
  865. ccw_device_set_timeout(cdev, 3*HZ);
  866. cdev->private->state = DEV_STATE_TIMEOUT_KILL;
  867. return;
  868. }
  869. if (ret == -ENODEV) {
  870. if (!sch->lpm) {
  871. PREPARE_WORK(&cdev->private->kick_work,
  872. ccw_device_nopath_notify, (void *)cdev);
  873. queue_work(ccw_device_notify_work,
  874. &cdev->private->kick_work);
  875. } else
  876. dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
  877. return;
  878. }
  879. if (cdev->handler)
  880. cdev->handler(cdev, cdev->private->intparm,
  881. ERR_PTR(-ETIMEDOUT));
  882. if (!sch->lpm) {
  883. PREPARE_WORK(&cdev->private->kick_work,
  884. ccw_device_nopath_notify, (void *)cdev);
  885. queue_work(ccw_device_notify_work, &cdev->private->kick_work);
  886. } else if (cdev->private->flags.doverify)
  887. /* Start delayed path verification. */
  888. ccw_device_online_verify(cdev, 0);
  889. }
  890. static void
  891. ccw_device_wait4io_verify(struct ccw_device *cdev, enum dev_event dev_event)
  892. {
  893. /* When the I/O has terminated, we have to start verification. */
  894. if (cdev->private->options.pgroup)
  895. cdev->private->flags.doverify = 1;
  896. }
  897. static void
  898. ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
  899. {
  900. struct irb *irb;
  901. switch (dev_event) {
  902. case DEV_EVENT_INTERRUPT:
  903. irb = (struct irb *) __LC_IRB;
  904. /* Check for unsolicited interrupt. */
  905. if ((irb->scsw.stctl ==
  906. (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
  907. (!irb->scsw.cc))
  908. /* FIXME: we should restart stlck here, but this
  909. * is extremely unlikely ... */
  910. goto out_wakeup;
  911. ccw_device_accumulate_irb(cdev, irb);
  912. /* We don't care about basic sense etc. */
  913. break;
  914. default: /* timeout */
  915. break;
  916. }
  917. out_wakeup:
  918. wake_up(&cdev->private->wait_q);
  919. }
  920. static void
  921. ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
  922. {
  923. struct subchannel *sch;
  924. sch = to_subchannel(cdev->dev.parent);
  925. if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
  926. /* Couldn't enable the subchannel for i/o. Sick device. */
  927. return;
  928. /* After 60s the device recognition is considered to have failed. */
  929. ccw_device_set_timeout(cdev, 60*HZ);
  930. cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
  931. ccw_device_sense_id_start(cdev);
  932. }
  933. void
  934. device_trigger_reprobe(struct subchannel *sch)
  935. {
  936. struct ccw_device *cdev;
  937. if (!sch->dev.driver_data)
  938. return;
  939. cdev = sch->dev.driver_data;
  940. if (cdev->private->state != DEV_STATE_DISCONNECTED)
  941. return;
  942. /* Update some values. */
  943. if (stsch(sch->irq, &sch->schib))
  944. return;
  945. /*
  946. * The pim, pam, pom values may not be accurate, but they are the best
  947. * we have before performing device selection :/
  948. */
  949. sch->lpm = sch->schib.pmcw.pim &
  950. sch->schib.pmcw.pam &
  951. sch->schib.pmcw.pom &
  952. sch->opm;
  953. /* Re-set some bits in the pmcw that were lost. */
  954. sch->schib.pmcw.isc = 3;
  955. sch->schib.pmcw.csense = 1;
  956. sch->schib.pmcw.ena = 0;
  957. if ((sch->lpm & (sch->lpm - 1)) != 0)
  958. sch->schib.pmcw.mp = 1;
  959. sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
  960. /* We should also udate ssd info, but this has to wait. */
  961. ccw_device_start_id(cdev, 0);
  962. }
  963. static void
  964. ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
  965. {
  966. struct subchannel *sch;
  967. sch = to_subchannel(cdev->dev.parent);
  968. /*
  969. * An interrupt in state offline means a previous disable was not
  970. * successful. Try again.
  971. */
  972. cio_disable_subchannel(sch);
  973. }
  974. static void
  975. ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
  976. {
  977. retry_set_schib(cdev);
  978. cdev->private->state = DEV_STATE_ONLINE;
  979. dev_fsm_event(cdev, dev_event);
  980. }
  981. static void
  982. ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
  983. {
  984. ccw_device_set_timeout(cdev, 0);
  985. if (dev_event == DEV_EVENT_NOTOPER)
  986. cdev->private->state = DEV_STATE_NOT_OPER;
  987. else
  988. cdev->private->state = DEV_STATE_OFFLINE;
  989. wake_up(&cdev->private->wait_q);
  990. }
  991. static void
  992. ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
  993. {
  994. int ret;
  995. ret = ccw_device_cancel_halt_clear(cdev);
  996. switch (ret) {
  997. case 0:
  998. cdev->private->state = DEV_STATE_OFFLINE;
  999. wake_up(&cdev->private->wait_q);
  1000. break;
  1001. case -ENODEV:
  1002. cdev->private->state = DEV_STATE_NOT_OPER;
  1003. wake_up(&cdev->private->wait_q);
  1004. break;
  1005. default:
  1006. ccw_device_set_timeout(cdev, HZ/10);
  1007. }
  1008. }
  1009. /*
  1010. * No operation action. This is used e.g. to ignore a timeout event in
  1011. * state offline.
  1012. */
  1013. static void
  1014. ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
  1015. {
  1016. }
  1017. /*
  1018. * Bug operation action.
  1019. */
  1020. static void
  1021. ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
  1022. {
  1023. printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
  1024. cdev->private->state, dev_event);
  1025. BUG();
  1026. }
  1027. /*
  1028. * device statemachine
  1029. */
  1030. fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
  1031. [DEV_STATE_NOT_OPER] = {
  1032. [DEV_EVENT_NOTOPER] = ccw_device_nop,
  1033. [DEV_EVENT_INTERRUPT] = ccw_device_bug,
  1034. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1035. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1036. },
  1037. [DEV_STATE_SENSE_PGID] = {
  1038. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1039. [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
  1040. [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
  1041. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1042. },
  1043. [DEV_STATE_SENSE_ID] = {
  1044. [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
  1045. [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
  1046. [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
  1047. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1048. },
  1049. [DEV_STATE_OFFLINE] = {
  1050. [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
  1051. [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
  1052. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1053. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1054. },
  1055. [DEV_STATE_VERIFY] = {
  1056. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1057. [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
  1058. [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
  1059. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1060. },
  1061. [DEV_STATE_ONLINE] = {
  1062. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1063. [DEV_EVENT_INTERRUPT] = ccw_device_irq,
  1064. [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
  1065. [DEV_EVENT_VERIFY] = ccw_device_online_verify,
  1066. },
  1067. [DEV_STATE_W4SENSE] = {
  1068. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1069. [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
  1070. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1071. [DEV_EVENT_VERIFY] = ccw_device_online_verify,
  1072. },
  1073. [DEV_STATE_DISBAND_PGID] = {
  1074. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1075. [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
  1076. [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
  1077. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1078. },
  1079. [DEV_STATE_BOXED] = {
  1080. [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
  1081. [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
  1082. [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
  1083. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1084. },
  1085. /* states to wait for i/o completion before doing something */
  1086. [DEV_STATE_CLEAR_VERIFY] = {
  1087. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1088. [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
  1089. [DEV_EVENT_TIMEOUT] = ccw_device_nop,
  1090. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1091. },
  1092. [DEV_STATE_TIMEOUT_KILL] = {
  1093. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1094. [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
  1095. [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
  1096. [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
  1097. },
  1098. [DEV_STATE_WAIT4IO] = {
  1099. [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
  1100. [DEV_EVENT_INTERRUPT] = ccw_device_wait4io_irq,
  1101. [DEV_EVENT_TIMEOUT] = ccw_device_wait4io_timeout,
  1102. [DEV_EVENT_VERIFY] = ccw_device_wait4io_verify,
  1103. },
  1104. [DEV_STATE_QUIESCE] = {
  1105. [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
  1106. [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
  1107. [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
  1108. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1109. },
  1110. /* special states for devices gone not operational */
  1111. [DEV_STATE_DISCONNECTED] = {
  1112. [DEV_EVENT_NOTOPER] = ccw_device_nop,
  1113. [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
  1114. [DEV_EVENT_TIMEOUT] = ccw_device_bug,
  1115. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1116. },
  1117. [DEV_STATE_DISCONNECTED_SENSE_ID] = {
  1118. [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
  1119. [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
  1120. [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
  1121. [DEV_EVENT_VERIFY] = ccw_device_nop,
  1122. },
  1123. [DEV_STATE_CMFCHANGE] = {
  1124. [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
  1125. [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
  1126. [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
  1127. [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
  1128. },
  1129. };
  1130. /*
  1131. * io_subchannel_irq is called for "real" interrupts or for status
  1132. * pending conditions on msch.
  1133. */
  1134. void
  1135. io_subchannel_irq (struct device *pdev)
  1136. {
  1137. struct ccw_device *cdev;
  1138. cdev = to_subchannel(pdev)->dev.driver_data;
  1139. CIO_TRACE_EVENT (3, "IRQ");
  1140. CIO_TRACE_EVENT (3, pdev->bus_id);
  1141. if (cdev)
  1142. dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
  1143. }
  1144. EXPORT_SYMBOL_GPL(ccw_device_set_timeout);