device_fsm.c 35 KB

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