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