Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee13...
[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
63 device_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  */
77 static void
78 ccw_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  */
91 void
92 ccw_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. */
109 void
110 device_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  */
128 int
129 ccw_device_cancel_halt_clear(struct ccw_device *cdev)
130 {
131         struct subchannel *sch;
132         int ret;
133
134         sch = to_subchannel(cdev->dev.parent);
135         ret = stsch(sch->schid, &sch->schib);
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);
155                         if (ret != -EBUSY)
156                                 return (ret == 0) ? -EBUSY : ret;
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
170 static int
171 ccw_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  */
201 static 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  */
219 static void
220 ccw_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;
234         stsch(sch->schid, &sch->schib);
235         sch->lpm = sch->schib.pmcw.pam & sch->opm;
236         /* Check since device may again have become not operational. */
237         if (!sch->schib.pmcw.dnv)
238                 state = DEV_STATE_NOT_OPER;
239         if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
240                 /* Force reprobe on all chpids. */
241                 old_lpm = 0;
242         if (sch->lpm != old_lpm)
243                 __recover_lost_chpids(sch, old_lpm);
244         if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
245                 if (state == DEV_STATE_NOT_OPER) {
246                         cdev->private->flags.recog_done = 1;
247                         cdev->private->state = DEV_STATE_DISCONNECTED;
248                         return;
249                 }
250                 /* Boxed devices don't need extra treatment. */
251         }
252         notify = 0;
253         same_dev = 0; /* Keep the compiler quiet... */
254         switch (state) {
255         case DEV_STATE_NOT_OPER:
256                 CIO_DEBUG(KERN_WARNING, 2,
257                           "SenseID : unknown device %04x on subchannel "
258                           "0.%x.%04x\n", cdev->private->devno,
259                           sch->schid.ssid, sch->schid.sch_no);
260                 break;
261         case DEV_STATE_OFFLINE:
262                 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
263                         same_dev = ccw_device_handle_oper(cdev);
264                         notify = 1;
265                 }
266                 /* fill out sense information */
267                 memset(&cdev->id, 0, sizeof(cdev->id));
268                 cdev->id.cu_type   = cdev->private->senseid.cu_type;
269                 cdev->id.cu_model  = cdev->private->senseid.cu_model;
270                 cdev->id.dev_type  = cdev->private->senseid.dev_type;
271                 cdev->id.dev_model = cdev->private->senseid.dev_model;
272                 if (notify) {
273                         cdev->private->state = DEV_STATE_OFFLINE;
274                         if (same_dev) {
275                                 /* Get device online again. */
276                                 ccw_device_online(cdev);
277                                 wake_up(&cdev->private->wait_q);
278                         }
279                         return;
280                 }
281                 /* Issue device info message. */
282                 CIO_DEBUG(KERN_INFO, 2, "SenseID : device 0.%x.%04x reports: "
283                           "CU  Type/Mod = %04X/%02X, Dev Type/Mod = "
284                           "%04X/%02X\n",
285                           cdev->private->ssid, cdev->private->devno,
286                           cdev->id.cu_type, cdev->id.cu_model,
287                           cdev->id.dev_type, cdev->id.dev_model);
288                 break;
289         case DEV_STATE_BOXED:
290                 CIO_DEBUG(KERN_WARNING, 2,
291                           "SenseID : boxed device %04x on subchannel "
292                           "0.%x.%04x\n", cdev->private->devno,
293                           sch->schid.ssid, sch->schid.sch_no);
294                 break;
295         }
296         cdev->private->state = state;
297         io_subchannel_recog_done(cdev);
298         if (state != DEV_STATE_NOT_OPER)
299                 wake_up(&cdev->private->wait_q);
300 }
301
302 /*
303  * Function called from device_id.c after sense id has completed.
304  */
305 void
306 ccw_device_sense_id_done(struct ccw_device *cdev, int err)
307 {
308         switch (err) {
309         case 0:
310                 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
311                 break;
312         case -ETIME:            /* Sense id stopped by timeout. */
313                 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
314                 break;
315         default:
316                 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
317                 break;
318         }
319 }
320
321 static void
322 ccw_device_oper_notify(void *data)
323 {
324         struct ccw_device *cdev;
325         struct subchannel *sch;
326         int ret;
327
328         cdev = (struct ccw_device *)data;
329         sch = to_subchannel(cdev->dev.parent);
330         ret = (sch->driver && sch->driver->notify) ?
331                 sch->driver->notify(&sch->dev, CIO_OPER) : 0;
332         if (!ret)
333                 /* Driver doesn't want device back. */
334                 ccw_device_do_unreg_rereg((void *)cdev);
335         else {
336                 /* Reenable channel measurements, if needed. */
337                 cmf_reenable(cdev);
338                 wake_up(&cdev->private->wait_q);
339         }
340 }
341
342 /*
343  * Finished with online/offline processing.
344  */
345 static void
346 ccw_device_done(struct ccw_device *cdev, int state)
347 {
348         struct subchannel *sch;
349
350         sch = to_subchannel(cdev->dev.parent);
351
352         ccw_device_set_timeout(cdev, 0);
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",
366                           cdev->private->devno, sch->schid.sch_no);
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
380 static 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
391 static 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
430 /*
431  * Function called from device_pgid.c after sense path ground has completed.
432  */
433 void
434 ccw_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) {
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);
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);
451                 return;
452         default:
453                 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
454                 return;
455         }
456         /* Start Path Group verification. */
457         cdev->private->state = DEV_STATE_VERIFY;
458         cdev->private->flags.doverify = 0;
459         ccw_device_verify_start(cdev);
460 }
461
462 /*
463  * Start device recognition.
464  */
465 int
466 ccw_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  */
500 static void
501 ccw_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
519 static void
520 ccw_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
555 void
556 ccw_device_verify_done(struct ccw_device *cdev, int err)
557 {
558         struct subchannel *sch;
559
560         sch = to_subchannel(cdev->dev.parent);
561         /* Update schib - pom may have changed. */
562         stsch(sch->schid, &sch->schib);
563         /* Update lpm with verified path mask. */
564         sch->lpm = sch->vpm;
565         /* Repeat path verification? */
566         if (cdev->private->flags.doverify) {
567                 cdev->private->flags.doverify = 0;
568                 ccw_device_verify_start(cdev);
569                 return;
570         }
571         switch (err) {
572         case -EOPNOTSUPP: /* path grouping not supported, just set online. */
573                 cdev->private->options.pgroup = 0;
574         case 0:
575                 ccw_device_done(cdev, DEV_STATE_ONLINE);
576                 /* Deliver fake irb to device driver, if needed. */
577                 if (cdev->private->flags.fake_irb) {
578                         memset(&cdev->private->irb, 0, sizeof(struct irb));
579                         cdev->private->irb.scsw.cc = 1;
580                         cdev->private->irb.scsw.fctl = SCSW_FCTL_START_FUNC;
581                         cdev->private->irb.scsw.actl = SCSW_ACTL_START_PEND;
582                         cdev->private->irb.scsw.stctl = SCSW_STCTL_STATUS_PEND;
583                         cdev->private->flags.fake_irb = 0;
584                         if (cdev->handler)
585                                 cdev->handler(cdev, cdev->private->intparm,
586                                               &cdev->private->irb);
587                         memset(&cdev->private->irb, 0, sizeof(struct irb));
588                 }
589                 break;
590         case -ETIME:
591                 ccw_device_done(cdev, DEV_STATE_BOXED);
592                 break;
593         default:
594                 PREPARE_WORK(&cdev->private->kick_work,
595                              ccw_device_nopath_notify, (void *)cdev);
596                 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
597                 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
598                 break;
599         }
600 }
601
602 /*
603  * Get device online.
604  */
605 int
606 ccw_device_online(struct ccw_device *cdev)
607 {
608         struct subchannel *sch;
609         int ret;
610
611         if ((cdev->private->state != DEV_STATE_OFFLINE) &&
612             (cdev->private->state != DEV_STATE_BOXED))
613                 return -EINVAL;
614         sch = to_subchannel(cdev->dev.parent);
615         if (css_init_done && !get_device(&cdev->dev))
616                 return -ENODEV;
617         ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
618         if (ret != 0) {
619                 /* Couldn't enable the subchannel for i/o. Sick device. */
620                 if (ret == -ENODEV)
621                         dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
622                 return ret;
623         }
624         /* Do we want to do path grouping? */
625         if (!cdev->private->options.pgroup) {
626                 /* Start initial path verification. */
627                 cdev->private->state = DEV_STATE_VERIFY;
628                 cdev->private->flags.doverify = 0;
629                 ccw_device_verify_start(cdev);
630                 return 0;
631         }
632         /* Do a SensePGID first. */
633         cdev->private->state = DEV_STATE_SENSE_PGID;
634         ccw_device_sense_pgid_start(cdev);
635         return 0;
636 }
637
638 void
639 ccw_device_disband_done(struct ccw_device *cdev, int err)
640 {
641         switch (err) {
642         case 0:
643                 ccw_device_done(cdev, DEV_STATE_OFFLINE);
644                 break;
645         case -ETIME:
646                 ccw_device_done(cdev, DEV_STATE_BOXED);
647                 break;
648         default:
649                 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
650                 break;
651         }
652 }
653
654 /*
655  * Shutdown device.
656  */
657 int
658 ccw_device_offline(struct ccw_device *cdev)
659 {
660         struct subchannel *sch;
661
662         sch = to_subchannel(cdev->dev.parent);
663         if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
664                 return -ENODEV;
665         if (cdev->private->state != DEV_STATE_ONLINE) {
666                 if (sch->schib.scsw.actl != 0)
667                         return -EBUSY;
668                 return -EINVAL;
669         }
670         if (sch->schib.scsw.actl != 0)
671                 return -EBUSY;
672         /* Are we doing path grouping? */
673         if (!cdev->private->options.pgroup) {
674                 /* No, set state offline immediately. */
675                 ccw_device_done(cdev, DEV_STATE_OFFLINE);
676                 return 0;
677         }
678         /* Start Set Path Group commands. */
679         cdev->private->state = DEV_STATE_DISBAND_PGID;
680         ccw_device_disband_start(cdev);
681         return 0;
682 }
683
684 /*
685  * Handle timeout in device online/offline process.
686  */
687 static void
688 ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
689 {
690         int ret;
691
692         ret = ccw_device_cancel_halt_clear(cdev);
693         switch (ret) {
694         case 0:
695                 ccw_device_done(cdev, DEV_STATE_BOXED);
696                 break;
697         case -ENODEV:
698                 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
699                 break;
700         default:
701                 ccw_device_set_timeout(cdev, 3*HZ);
702         }
703 }
704
705 /*
706  * Handle not oper event in device recognition.
707  */
708 static void
709 ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
710 {
711         ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
712 }
713
714 /*
715  * Handle not operational event while offline.
716  */
717 static void
718 ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
719 {
720         struct subchannel *sch;
721
722         cdev->private->state = DEV_STATE_NOT_OPER;
723         sch = to_subchannel(cdev->dev.parent);
724         if (get_device(&cdev->dev)) {
725                 PREPARE_WORK(&cdev->private->kick_work,
726                              ccw_device_call_sch_unregister, (void *)cdev);
727                 queue_work(ccw_device_work, &cdev->private->kick_work);
728         }
729         wake_up(&cdev->private->wait_q);
730 }
731
732 /*
733  * Handle not operational event while online.
734  */
735 static void
736 ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
737 {
738         struct subchannel *sch;
739
740         sch = to_subchannel(cdev->dev.parent);
741         if (sch->driver->notify &&
742             sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
743                         ccw_device_set_timeout(cdev, 0);
744                         cdev->private->flags.fake_irb = 0;
745                         cdev->private->state = DEV_STATE_DISCONNECTED;
746                         wake_up(&cdev->private->wait_q);
747                         return;
748         }
749         cdev->private->state = DEV_STATE_NOT_OPER;
750         cio_disable_subchannel(sch);
751         if (sch->schib.scsw.actl != 0) {
752                 // FIXME: not-oper indication to device driver ?
753                 ccw_device_call_handler(cdev);
754         }
755         if (get_device(&cdev->dev)) {
756                 PREPARE_WORK(&cdev->private->kick_work,
757                              ccw_device_call_sch_unregister, (void *)cdev);
758                 queue_work(ccw_device_work, &cdev->private->kick_work);
759         }
760         wake_up(&cdev->private->wait_q);
761 }
762
763 /*
764  * Handle path verification event.
765  */
766 static void
767 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
768 {
769         struct subchannel *sch;
770
771         if (cdev->private->state == DEV_STATE_W4SENSE) {
772                 cdev->private->flags.doverify = 1;
773                 return;
774         }
775         sch = to_subchannel(cdev->dev.parent);
776         /*
777          * Since we might not just be coming from an interrupt from the
778          * subchannel we have to update the schib.
779          */
780         stsch(sch->schid, &sch->schib);
781
782         if (sch->schib.scsw.actl != 0 ||
783             (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
784             (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
785                 /*
786                  * No final status yet or final status not yet delivered
787                  * to the device driver. Can't do path verfication now,
788                  * delay until final status was delivered.
789                  */
790                 cdev->private->flags.doverify = 1;
791                 return;
792         }
793         /* Device is idle, we can do the path verification. */
794         cdev->private->state = DEV_STATE_VERIFY;
795         cdev->private->flags.doverify = 0;
796         ccw_device_verify_start(cdev);
797 }
798
799 /*
800  * Got an interrupt for a normal io (state online).
801  */
802 static void
803 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
804 {
805         struct irb *irb;
806
807         irb = (struct irb *) __LC_IRB;
808         /* Check for unsolicited interrupt. */
809         if ((irb->scsw.stctl ==
810                         (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
811             && (!irb->scsw.cc)) {
812                 if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
813                     !irb->esw.esw0.erw.cons) {
814                         /* Unit check but no sense data. Need basic sense. */
815                         if (ccw_device_do_sense(cdev, irb) != 0)
816                                 goto call_handler_unsol;
817                         memcpy(&cdev->private->irb, irb, sizeof(struct irb));
818                         cdev->private->state = DEV_STATE_W4SENSE;
819                         cdev->private->intparm = 0;
820                         return;
821                 }
822 call_handler_unsol:
823                 if (cdev->handler)
824                         cdev->handler (cdev, 0, irb);
825                 return;
826         }
827         /* Accumulate status and find out if a basic sense is needed. */
828         ccw_device_accumulate_irb(cdev, irb);
829         if (cdev->private->flags.dosense) {
830                 if (ccw_device_do_sense(cdev, irb) == 0) {
831                         cdev->private->state = DEV_STATE_W4SENSE;
832                 }
833                 return;
834         }
835         /* Call the handler. */
836         if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
837                 /* Start delayed path verification. */
838                 ccw_device_online_verify(cdev, 0);
839 }
840
841 /*
842  * Got an timeout in online state.
843  */
844 static void
845 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
846 {
847         int ret;
848
849         ccw_device_set_timeout(cdev, 0);
850         ret = ccw_device_cancel_halt_clear(cdev);
851         if (ret == -EBUSY) {
852                 ccw_device_set_timeout(cdev, 3*HZ);
853                 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
854                 return;
855         }
856         if (ret == -ENODEV) {
857                 struct subchannel *sch;
858
859                 sch = to_subchannel(cdev->dev.parent);
860                 if (!sch->lpm) {
861                         PREPARE_WORK(&cdev->private->kick_work,
862                                      ccw_device_nopath_notify, (void *)cdev);
863                         queue_work(ccw_device_notify_work,
864                                    &cdev->private->kick_work);
865                 } else
866                         dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
867         } else if (cdev->handler)
868                 cdev->handler(cdev, cdev->private->intparm,
869                               ERR_PTR(-ETIMEDOUT));
870 }
871
872 /*
873  * Got an interrupt for a basic sense.
874  */
875 void
876 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
877 {
878         struct irb *irb;
879
880         irb = (struct irb *) __LC_IRB;
881         /* Check for unsolicited interrupt. */
882         if (irb->scsw.stctl ==
883                         (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
884                 if (irb->scsw.cc == 1)
885                         /* Basic sense hasn't started. Try again. */
886                         ccw_device_do_sense(cdev, irb);
887                 else {
888                         printk("Huh? %s(%s): unsolicited interrupt...\n",
889                                __FUNCTION__, cdev->dev.bus_id);
890                         if (cdev->handler)
891                                 cdev->handler (cdev, 0, irb);
892                 }
893                 return;
894         }
895         /*
896          * Check if a halt or clear has been issued in the meanwhile. If yes,
897          * only deliver the halt/clear interrupt to the device driver as if it
898          * had killed the original request.
899          */
900         if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
901                 cdev->private->flags.dosense = 0;
902                 memset(&cdev->private->irb, 0, sizeof(struct irb));
903                 ccw_device_accumulate_irb(cdev, irb);
904                 goto call_handler;
905         }
906         /* Add basic sense info to irb. */
907         ccw_device_accumulate_basic_sense(cdev, irb);
908         if (cdev->private->flags.dosense) {
909                 /* Another basic sense is needed. */
910                 ccw_device_do_sense(cdev, irb);
911                 return;
912         }
913 call_handler:
914         cdev->private->state = DEV_STATE_ONLINE;
915         /* Call the handler. */
916         if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
917                 /* Start delayed path verification. */
918                 ccw_device_online_verify(cdev, 0);
919 }
920
921 static void
922 ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
923 {
924         struct irb *irb;
925
926         irb = (struct irb *) __LC_IRB;
927         /* Accumulate status. We don't do basic sense. */
928         ccw_device_accumulate_irb(cdev, irb);
929         /* Remember to clear irb to avoid residuals. */
930         memset(&cdev->private->irb, 0, sizeof(struct irb));
931         /* Try to start delayed device verification. */
932         ccw_device_online_verify(cdev, 0);
933         /* Note: Don't call handler for cio initiated clear! */
934 }
935
936 static void
937 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
938 {
939         struct subchannel *sch;
940
941         sch = to_subchannel(cdev->dev.parent);
942         ccw_device_set_timeout(cdev, 0);
943         /* OK, i/o is dead now. Call interrupt handler. */
944         cdev->private->state = DEV_STATE_ONLINE;
945         if (cdev->handler)
946                 cdev->handler(cdev, cdev->private->intparm,
947                               ERR_PTR(-ETIMEDOUT));
948         if (!sch->lpm) {
949                 PREPARE_WORK(&cdev->private->kick_work,
950                              ccw_device_nopath_notify, (void *)cdev);
951                 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
952         } else if (cdev->private->flags.doverify)
953                 /* Start delayed path verification. */
954                 ccw_device_online_verify(cdev, 0);
955 }
956
957 static void
958 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
959 {
960         int ret;
961
962         ret = ccw_device_cancel_halt_clear(cdev);
963         if (ret == -EBUSY) {
964                 ccw_device_set_timeout(cdev, 3*HZ);
965                 return;
966         }
967         if (ret == -ENODEV) {
968                 struct subchannel *sch;
969
970                 sch = to_subchannel(cdev->dev.parent);
971                 if (!sch->lpm) {
972                         PREPARE_WORK(&cdev->private->kick_work,
973                                      ccw_device_nopath_notify, (void *)cdev);
974                         queue_work(ccw_device_notify_work,
975                                    &cdev->private->kick_work);
976                 } else
977                         dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
978                 return;
979         }
980         //FIXME: Can we get here?
981         cdev->private->state = DEV_STATE_ONLINE;
982         if (cdev->handler)
983                 cdev->handler(cdev, cdev->private->intparm,
984                               ERR_PTR(-ETIMEDOUT));
985 }
986
987 static void
988 ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
989 {
990         struct irb *irb;
991         struct subchannel *sch;
992
993         irb = (struct irb *) __LC_IRB;
994         /*
995          * Accumulate status and find out if a basic sense is needed.
996          * This is fine since we have already adapted the lpm.
997          */
998         ccw_device_accumulate_irb(cdev, irb);
999         if (cdev->private->flags.dosense) {
1000                 if (ccw_device_do_sense(cdev, irb) == 0) {
1001                         cdev->private->state = DEV_STATE_W4SENSE;
1002                 }
1003                 return;
1004         }
1005
1006         /* Iff device is idle, reset timeout. */
1007         sch = to_subchannel(cdev->dev.parent);
1008         if (!stsch(sch->schid, &sch->schib))
1009                 if (sch->schib.scsw.actl == 0)
1010                         ccw_device_set_timeout(cdev, 0);
1011         /* Call the handler. */
1012         ccw_device_call_handler(cdev);
1013         if (!sch->lpm) {
1014                 PREPARE_WORK(&cdev->private->kick_work,
1015                              ccw_device_nopath_notify, (void *)cdev);
1016                 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1017         } else if (cdev->private->flags.doverify)
1018                 ccw_device_online_verify(cdev, 0);
1019 }
1020
1021 static void
1022 ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1023 {
1024         int ret;
1025         struct subchannel *sch;
1026
1027         sch = to_subchannel(cdev->dev.parent);
1028         ccw_device_set_timeout(cdev, 0);
1029         ret = ccw_device_cancel_halt_clear(cdev);
1030         if (ret == -EBUSY) {
1031                 ccw_device_set_timeout(cdev, 3*HZ);
1032                 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
1033                 return;
1034         }
1035         if (ret == -ENODEV) {
1036                 if (!sch->lpm) {
1037                         PREPARE_WORK(&cdev->private->kick_work,
1038                                      ccw_device_nopath_notify, (void *)cdev);
1039                         queue_work(ccw_device_notify_work,
1040                                    &cdev->private->kick_work);
1041                 } else
1042                         dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1043                 return;
1044         }
1045         if (cdev->handler)
1046                 cdev->handler(cdev, cdev->private->intparm,
1047                               ERR_PTR(-ETIMEDOUT));
1048         if (!sch->lpm) {
1049                 PREPARE_WORK(&cdev->private->kick_work,
1050                              ccw_device_nopath_notify, (void *)cdev);
1051                 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1052         } else if (cdev->private->flags.doverify)
1053                 /* Start delayed path verification. */
1054                 ccw_device_online_verify(cdev, 0);
1055 }
1056
1057 static void
1058 ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
1059 {
1060         /* Start verification after current task finished. */
1061         cdev->private->flags.doverify = 1;
1062 }
1063
1064 static void
1065 ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
1066 {
1067         struct irb *irb;
1068
1069         switch (dev_event) {
1070         case DEV_EVENT_INTERRUPT:
1071                 irb = (struct irb *) __LC_IRB;
1072                 /* Check for unsolicited interrupt. */
1073                 if ((irb->scsw.stctl ==
1074                      (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
1075                     (!irb->scsw.cc))
1076                         /* FIXME: we should restart stlck here, but this
1077                          * is extremely unlikely ... */
1078                         goto out_wakeup;
1079
1080                 ccw_device_accumulate_irb(cdev, irb);
1081                 /* We don't care about basic sense etc. */
1082                 break;
1083         default: /* timeout */
1084                 break;
1085         }
1086 out_wakeup:
1087         wake_up(&cdev->private->wait_q);
1088 }
1089
1090 static void
1091 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
1092 {
1093         struct subchannel *sch;
1094
1095         sch = to_subchannel(cdev->dev.parent);
1096         if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
1097                 /* Couldn't enable the subchannel for i/o. Sick device. */
1098                 return;
1099
1100         /* After 60s the device recognition is considered to have failed. */
1101         ccw_device_set_timeout(cdev, 60*HZ);
1102
1103         cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
1104         ccw_device_sense_id_start(cdev);
1105 }
1106
1107 void
1108 device_trigger_reprobe(struct subchannel *sch)
1109 {
1110         struct ccw_device *cdev;
1111
1112         if (!sch->dev.driver_data)
1113                 return;
1114         cdev = sch->dev.driver_data;
1115         if (cdev->private->state != DEV_STATE_DISCONNECTED)
1116                 return;
1117
1118         /* Update some values. */
1119         if (stsch(sch->schid, &sch->schib))
1120                 return;
1121
1122         /*
1123          * The pim, pam, pom values may not be accurate, but they are the best
1124          * we have before performing device selection :/
1125          */
1126         sch->lpm = sch->schib.pmcw.pam & sch->opm;
1127         /* Re-set some bits in the pmcw that were lost. */
1128         sch->schib.pmcw.isc = 3;
1129         sch->schib.pmcw.csense = 1;
1130         sch->schib.pmcw.ena = 0;
1131         if ((sch->lpm & (sch->lpm - 1)) != 0)
1132                 sch->schib.pmcw.mp = 1;
1133         sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1134         /* We should also udate ssd info, but this has to wait. */
1135         ccw_device_start_id(cdev, 0);
1136 }
1137
1138 static void
1139 ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1140 {
1141         struct subchannel *sch;
1142
1143         sch = to_subchannel(cdev->dev.parent);
1144         /*
1145          * An interrupt in state offline means a previous disable was not
1146          * successful. Try again.
1147          */
1148         cio_disable_subchannel(sch);
1149 }
1150
1151 static void
1152 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1153 {
1154         retry_set_schib(cdev);
1155         cdev->private->state = DEV_STATE_ONLINE;
1156         dev_fsm_event(cdev, dev_event);
1157 }
1158
1159 static void ccw_device_update_cmfblock(struct ccw_device *cdev,
1160                                        enum dev_event dev_event)
1161 {
1162         cmf_retry_copy_block(cdev);
1163         cdev->private->state = DEV_STATE_ONLINE;
1164         dev_fsm_event(cdev, dev_event);
1165 }
1166
1167 static void
1168 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1169 {
1170         ccw_device_set_timeout(cdev, 0);
1171         if (dev_event == DEV_EVENT_NOTOPER)
1172                 cdev->private->state = DEV_STATE_NOT_OPER;
1173         else
1174                 cdev->private->state = DEV_STATE_OFFLINE;
1175         wake_up(&cdev->private->wait_q);
1176 }
1177
1178 static void
1179 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1180 {
1181         int ret;
1182
1183         ret = ccw_device_cancel_halt_clear(cdev);
1184         switch (ret) {
1185         case 0:
1186                 cdev->private->state = DEV_STATE_OFFLINE;
1187                 wake_up(&cdev->private->wait_q);
1188                 break;
1189         case -ENODEV:
1190                 cdev->private->state = DEV_STATE_NOT_OPER;
1191                 wake_up(&cdev->private->wait_q);
1192                 break;
1193         default:
1194                 ccw_device_set_timeout(cdev, HZ/10);
1195         }
1196 }
1197
1198 /*
1199  * No operation action. This is used e.g. to ignore a timeout event in
1200  * state offline.
1201  */
1202 static void
1203 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1204 {
1205 }
1206
1207 /*
1208  * Bug operation action. 
1209  */
1210 static void
1211 ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1212 {
1213         printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1214                cdev->private->state, dev_event);
1215         BUG();
1216 }
1217
1218 /*
1219  * device statemachine
1220  */
1221 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1222         [DEV_STATE_NOT_OPER] = {
1223                 [DEV_EVENT_NOTOPER]     = ccw_device_nop,
1224                 [DEV_EVENT_INTERRUPT]   = ccw_device_bug,
1225                 [DEV_EVENT_TIMEOUT]     = ccw_device_nop,
1226                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1227         },
1228         [DEV_STATE_SENSE_PGID] = {
1229                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1230                 [DEV_EVENT_INTERRUPT]   = ccw_device_sense_pgid_irq,
1231                 [DEV_EVENT_TIMEOUT]     = ccw_device_onoff_timeout,
1232                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1233         },
1234         [DEV_STATE_SENSE_ID] = {
1235                 [DEV_EVENT_NOTOPER]     = ccw_device_recog_notoper,
1236                 [DEV_EVENT_INTERRUPT]   = ccw_device_sense_id_irq,
1237                 [DEV_EVENT_TIMEOUT]     = ccw_device_recog_timeout,
1238                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1239         },
1240         [DEV_STATE_OFFLINE] = {
1241                 [DEV_EVENT_NOTOPER]     = ccw_device_offline_notoper,
1242                 [DEV_EVENT_INTERRUPT]   = ccw_device_offline_irq,
1243                 [DEV_EVENT_TIMEOUT]     = ccw_device_nop,
1244                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1245         },
1246         [DEV_STATE_VERIFY] = {
1247                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1248                 [DEV_EVENT_INTERRUPT]   = ccw_device_verify_irq,
1249                 [DEV_EVENT_TIMEOUT]     = ccw_device_onoff_timeout,
1250                 [DEV_EVENT_VERIFY]      = ccw_device_delay_verify,
1251         },
1252         [DEV_STATE_ONLINE] = {
1253                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1254                 [DEV_EVENT_INTERRUPT]   = ccw_device_irq,
1255                 [DEV_EVENT_TIMEOUT]     = ccw_device_online_timeout,
1256                 [DEV_EVENT_VERIFY]      = ccw_device_online_verify,
1257         },
1258         [DEV_STATE_W4SENSE] = {
1259                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1260                 [DEV_EVENT_INTERRUPT]   = ccw_device_w4sense,
1261                 [DEV_EVENT_TIMEOUT]     = ccw_device_nop,
1262                 [DEV_EVENT_VERIFY]      = ccw_device_online_verify,
1263         },
1264         [DEV_STATE_DISBAND_PGID] = {
1265                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1266                 [DEV_EVENT_INTERRUPT]   = ccw_device_disband_irq,
1267                 [DEV_EVENT_TIMEOUT]     = ccw_device_onoff_timeout,
1268                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1269         },
1270         [DEV_STATE_BOXED] = {
1271                 [DEV_EVENT_NOTOPER]     = ccw_device_offline_notoper,
1272                 [DEV_EVENT_INTERRUPT]   = ccw_device_stlck_done,
1273                 [DEV_EVENT_TIMEOUT]     = ccw_device_stlck_done,
1274                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1275         },
1276         /* states to wait for i/o completion before doing something */
1277         [DEV_STATE_CLEAR_VERIFY] = {
1278                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1279                 [DEV_EVENT_INTERRUPT]   = ccw_device_clear_verify,
1280                 [DEV_EVENT_TIMEOUT]     = ccw_device_nop,
1281                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1282         },
1283         [DEV_STATE_TIMEOUT_KILL] = {
1284                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1285                 [DEV_EVENT_INTERRUPT]   = ccw_device_killing_irq,
1286                 [DEV_EVENT_TIMEOUT]     = ccw_device_killing_timeout,
1287                 [DEV_EVENT_VERIFY]      = ccw_device_nop, //FIXME
1288         },
1289         [DEV_STATE_WAIT4IO] = {
1290                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1291                 [DEV_EVENT_INTERRUPT]   = ccw_device_wait4io_irq,
1292                 [DEV_EVENT_TIMEOUT]     = ccw_device_wait4io_timeout,
1293                 [DEV_EVENT_VERIFY]      = ccw_device_delay_verify,
1294         },
1295         [DEV_STATE_QUIESCE] = {
1296                 [DEV_EVENT_NOTOPER]     = ccw_device_quiesce_done,
1297                 [DEV_EVENT_INTERRUPT]   = ccw_device_quiesce_done,
1298                 [DEV_EVENT_TIMEOUT]     = ccw_device_quiesce_timeout,
1299                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1300         },
1301         /* special states for devices gone not operational */
1302         [DEV_STATE_DISCONNECTED] = {
1303                 [DEV_EVENT_NOTOPER]     = ccw_device_nop,
1304                 [DEV_EVENT_INTERRUPT]   = ccw_device_start_id,
1305                 [DEV_EVENT_TIMEOUT]     = ccw_device_bug,
1306                 [DEV_EVENT_VERIFY]      = ccw_device_start_id,
1307         },
1308         [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1309                 [DEV_EVENT_NOTOPER]     = ccw_device_recog_notoper,
1310                 [DEV_EVENT_INTERRUPT]   = ccw_device_sense_id_irq,
1311                 [DEV_EVENT_TIMEOUT]     = ccw_device_recog_timeout,
1312                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1313         },
1314         [DEV_STATE_CMFCHANGE] = {
1315                 [DEV_EVENT_NOTOPER]     = ccw_device_change_cmfstate,
1316                 [DEV_EVENT_INTERRUPT]   = ccw_device_change_cmfstate,
1317                 [DEV_EVENT_TIMEOUT]     = ccw_device_change_cmfstate,
1318                 [DEV_EVENT_VERIFY]      = ccw_device_change_cmfstate,
1319         },
1320         [DEV_STATE_CMFUPDATE] = {
1321                 [DEV_EVENT_NOTOPER]     = ccw_device_update_cmfblock,
1322                 [DEV_EVENT_INTERRUPT]   = ccw_device_update_cmfblock,
1323                 [DEV_EVENT_TIMEOUT]     = ccw_device_update_cmfblock,
1324                 [DEV_EVENT_VERIFY]      = ccw_device_update_cmfblock,
1325         },
1326 };
1327
1328 /*
1329  * io_subchannel_irq is called for "real" interrupts or for status
1330  * pending conditions on msch.
1331  */
1332 void
1333 io_subchannel_irq (struct device *pdev)
1334 {
1335         struct ccw_device *cdev;
1336
1337         cdev = to_subchannel(pdev)->dev.driver_data;
1338
1339         CIO_TRACE_EVENT (3, "IRQ");
1340         CIO_TRACE_EVENT (3, pdev->bus_id);
1341         if (cdev)
1342                 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1343 }
1344
1345 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);