device_fsm.c 35 KB

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