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