device_fsm.c 36 KB

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