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