Merge branch 'mainline' into upstream-linus
[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         if (state != DEV_STATE_ONLINE)
353                 cio_disable_subchannel(sch);
354
355         /* Reset device status. */
356         memset(&cdev->private->irb, 0, sizeof(struct irb));
357
358         cdev->private->state = state;
359
360
361         if (state == DEV_STATE_BOXED)
362                 CIO_DEBUG(KERN_WARNING, 2,
363                           "Boxed device %04x on subchannel %04x\n",
364                           cdev->private->devno, sch->schid.sch_no);
365
366         if (cdev->private->flags.donotify) {
367                 cdev->private->flags.donotify = 0;
368                 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,
369                              (void *)cdev);
370                 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
371         }
372         wake_up(&cdev->private->wait_q);
373
374         if (css_init_done && state != DEV_STATE_ONLINE)
375                 put_device (&cdev->dev);
376 }
377
378 static inline int cmp_pgid(struct pgid *p1, struct pgid *p2)
379 {
380         char *c1;
381         char *c2;
382
383         c1 = (char *)p1;
384         c2 = (char *)p2;
385
386         return memcmp(c1 + 1, c2 + 1, sizeof(struct pgid) - 1);
387 }
388
389 static void __ccw_device_get_common_pgid(struct ccw_device *cdev)
390 {
391         int i;
392         int last;
393
394         last = 0;
395         for (i = 0; i < 8; i++) {
396                 if (cdev->private->pgid[i].inf.ps.state1 == SNID_STATE1_RESET)
397                         /* No PGID yet */
398                         continue;
399                 if (cdev->private->pgid[last].inf.ps.state1 ==
400                     SNID_STATE1_RESET) {
401                         /* First non-zero PGID */
402                         last = i;
403                         continue;
404                 }
405                 if (cmp_pgid(&cdev->private->pgid[i],
406                              &cdev->private->pgid[last]) == 0)
407                         /* Non-conflicting PGIDs */
408                         continue;
409
410                 /* PGID mismatch, can't pathgroup. */
411                 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
412                               "0.%x.%04x, can't pathgroup\n",
413                               cdev->private->ssid, cdev->private->devno);
414                 cdev->private->options.pgroup = 0;
415                 return;
416         }
417         if (cdev->private->pgid[last].inf.ps.state1 ==
418             SNID_STATE1_RESET)
419                 /* No previous pgid found */
420                 memcpy(&cdev->private->pgid[0], &css[0]->global_pgid,
421                        sizeof(struct pgid));
422         else
423                 /* Use existing pgid */
424                 memcpy(&cdev->private->pgid[0], &cdev->private->pgid[last],
425                        sizeof(struct pgid));
426 }
427
428 /*
429  * Function called from device_pgid.c after sense path ground has completed.
430  */
431 void
432 ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
433 {
434         struct subchannel *sch;
435
436         sch = to_subchannel(cdev->dev.parent);
437         switch (err) {
438         case -EOPNOTSUPP: /* path grouping not supported, use nop instead. */
439                 cdev->private->options.pgroup = 0;
440                 break;
441         case 0: /* success */
442         case -EACCES: /* partial success, some paths not operational */
443                 /* Check if all pgids are equal or 0. */
444                 __ccw_device_get_common_pgid(cdev);
445                 break;
446         case -ETIME:            /* Sense path group id stopped by timeout. */
447         case -EUSERS:           /* device is reserved for someone else. */
448                 ccw_device_done(cdev, DEV_STATE_BOXED);
449                 return;
450         default:
451                 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
452                 return;
453         }
454         /* Start Path Group verification. */
455         cdev->private->state = DEV_STATE_VERIFY;
456         cdev->private->flags.doverify = 0;
457         ccw_device_verify_start(cdev);
458 }
459
460 /*
461  * Start device recognition.
462  */
463 int
464 ccw_device_recognition(struct ccw_device *cdev)
465 {
466         struct subchannel *sch;
467         int ret;
468
469         if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
470             (cdev->private->state != DEV_STATE_BOXED))
471                 return -EINVAL;
472         sch = to_subchannel(cdev->dev.parent);
473         ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
474         if (ret != 0)
475                 /* Couldn't enable the subchannel for i/o. Sick device. */
476                 return ret;
477
478         /* After 60s the device recognition is considered to have failed. */
479         ccw_device_set_timeout(cdev, 60*HZ);
480
481         /*
482          * We used to start here with a sense pgid to find out whether a device
483          * is locked by someone else. Unfortunately, the sense pgid command
484          * code has other meanings on devices predating the path grouping
485          * algorithm, so we start with sense id and box the device after an
486          * timeout (or if sense pgid during path verification detects the device
487          * is locked, as may happen on newer devices).
488          */
489         cdev->private->flags.recog_done = 0;
490         cdev->private->state = DEV_STATE_SENSE_ID;
491         ccw_device_sense_id_start(cdev);
492         return 0;
493 }
494
495 /*
496  * Handle timeout in device recognition.
497  */
498 static void
499 ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
500 {
501         int ret;
502
503         ret = ccw_device_cancel_halt_clear(cdev);
504         switch (ret) {
505         case 0:
506                 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
507                 break;
508         case -ENODEV:
509                 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
510                 break;
511         default:
512                 ccw_device_set_timeout(cdev, 3*HZ);
513         }
514 }
515
516
517 static void
518 ccw_device_nopath_notify(void *data)
519 {
520         struct ccw_device *cdev;
521         struct subchannel *sch;
522         int ret;
523
524         cdev = (struct ccw_device *)data;
525         sch = to_subchannel(cdev->dev.parent);
526         /* Extra sanity. */
527         if (sch->lpm)
528                 return;
529         ret = (sch->driver && sch->driver->notify) ?
530                 sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0;
531         if (!ret) {
532                 if (get_device(&sch->dev)) {
533                         /* Driver doesn't want to keep device. */
534                         cio_disable_subchannel(sch);
535                         if (get_device(&cdev->dev)) {
536                                 PREPARE_WORK(&cdev->private->kick_work,
537                                              ccw_device_call_sch_unregister,
538                                              (void *)cdev);
539                                 queue_work(ccw_device_work,
540                                            &cdev->private->kick_work);
541                         } else
542                                 put_device(&sch->dev);
543                 }
544         } else {
545                 cio_disable_subchannel(sch);
546                 ccw_device_set_timeout(cdev, 0);
547                 cdev->private->flags.fake_irb = 0;
548                 cdev->private->state = DEV_STATE_DISCONNECTED;
549                 wake_up(&cdev->private->wait_q);
550         }
551 }
552
553 void
554 ccw_device_verify_done(struct ccw_device *cdev, int err)
555 {
556         struct subchannel *sch;
557
558         sch = to_subchannel(cdev->dev.parent);
559         /* Update schib - pom may have changed. */
560         stsch(sch->schid, &sch->schib);
561         /* Update lpm with verified path mask. */
562         sch->lpm = sch->vpm;
563         /* Repeat path verification? */
564         if (cdev->private->flags.doverify) {
565                 cdev->private->flags.doverify = 0;
566                 ccw_device_verify_start(cdev);
567                 return;
568         }
569         switch (err) {
570         case -EOPNOTSUPP: /* path grouping not supported, just set online. */
571                 cdev->private->options.pgroup = 0;
572         case 0:
573                 ccw_device_done(cdev, DEV_STATE_ONLINE);
574                 /* Deliver fake irb to device driver, if needed. */
575                 if (cdev->private->flags.fake_irb) {
576                         memset(&cdev->private->irb, 0, sizeof(struct irb));
577                         cdev->private->irb.scsw.cc = 1;
578                         cdev->private->irb.scsw.fctl = SCSW_FCTL_START_FUNC;
579                         cdev->private->irb.scsw.actl = SCSW_ACTL_START_PEND;
580                         cdev->private->irb.scsw.stctl = SCSW_STCTL_STATUS_PEND;
581                         cdev->private->flags.fake_irb = 0;
582                         if (cdev->handler)
583                                 cdev->handler(cdev, cdev->private->intparm,
584                                               &cdev->private->irb);
585                         memset(&cdev->private->irb, 0, sizeof(struct irb));
586                 }
587                 break;
588         case -ETIME:
589                 ccw_device_done(cdev, DEV_STATE_BOXED);
590                 break;
591         default:
592                 PREPARE_WORK(&cdev->private->kick_work,
593                              ccw_device_nopath_notify, (void *)cdev);
594                 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
595                 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
596                 break;
597         }
598 }
599
600 /*
601  * Get device online.
602  */
603 int
604 ccw_device_online(struct ccw_device *cdev)
605 {
606         struct subchannel *sch;
607         int ret;
608
609         if ((cdev->private->state != DEV_STATE_OFFLINE) &&
610             (cdev->private->state != DEV_STATE_BOXED))
611                 return -EINVAL;
612         sch = to_subchannel(cdev->dev.parent);
613         if (css_init_done && !get_device(&cdev->dev))
614                 return -ENODEV;
615         ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
616         if (ret != 0) {
617                 /* Couldn't enable the subchannel for i/o. Sick device. */
618                 if (ret == -ENODEV)
619                         dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
620                 return ret;
621         }
622         /* Do we want to do path grouping? */
623         if (!cdev->private->options.pgroup) {
624                 /* Start initial path verification. */
625                 cdev->private->state = DEV_STATE_VERIFY;
626                 cdev->private->flags.doverify = 0;
627                 ccw_device_verify_start(cdev);
628                 return 0;
629         }
630         /* Do a SensePGID first. */
631         cdev->private->state = DEV_STATE_SENSE_PGID;
632         ccw_device_sense_pgid_start(cdev);
633         return 0;
634 }
635
636 void
637 ccw_device_disband_done(struct ccw_device *cdev, int err)
638 {
639         switch (err) {
640         case 0:
641                 ccw_device_done(cdev, DEV_STATE_OFFLINE);
642                 break;
643         case -ETIME:
644                 ccw_device_done(cdev, DEV_STATE_BOXED);
645                 break;
646         default:
647                 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
648                 break;
649         }
650 }
651
652 /*
653  * Shutdown device.
654  */
655 int
656 ccw_device_offline(struct ccw_device *cdev)
657 {
658         struct subchannel *sch;
659
660         sch = to_subchannel(cdev->dev.parent);
661         if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
662                 return -ENODEV;
663         if (cdev->private->state != DEV_STATE_ONLINE) {
664                 if (sch->schib.scsw.actl != 0)
665                         return -EBUSY;
666                 return -EINVAL;
667         }
668         if (sch->schib.scsw.actl != 0)
669                 return -EBUSY;
670         /* Are we doing path grouping? */
671         if (!cdev->private->options.pgroup) {
672                 /* No, set state offline immediately. */
673                 ccw_device_done(cdev, DEV_STATE_OFFLINE);
674                 return 0;
675         }
676         /* Start Set Path Group commands. */
677         cdev->private->state = DEV_STATE_DISBAND_PGID;
678         ccw_device_disband_start(cdev);
679         return 0;
680 }
681
682 /*
683  * Handle timeout in device online/offline process.
684  */
685 static void
686 ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
687 {
688         int ret;
689
690         ret = ccw_device_cancel_halt_clear(cdev);
691         switch (ret) {
692         case 0:
693                 ccw_device_done(cdev, DEV_STATE_BOXED);
694                 break;
695         case -ENODEV:
696                 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
697                 break;
698         default:
699                 ccw_device_set_timeout(cdev, 3*HZ);
700         }
701 }
702
703 /*
704  * Handle not oper event in device recognition.
705  */
706 static void
707 ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
708 {
709         ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
710 }
711
712 /*
713  * Handle not operational event while offline.
714  */
715 static void
716 ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
717 {
718         struct subchannel *sch;
719
720         cdev->private->state = DEV_STATE_NOT_OPER;
721         sch = to_subchannel(cdev->dev.parent);
722         if (get_device(&cdev->dev)) {
723                 PREPARE_WORK(&cdev->private->kick_work,
724                              ccw_device_call_sch_unregister, (void *)cdev);
725                 queue_work(ccw_device_work, &cdev->private->kick_work);
726         }
727         wake_up(&cdev->private->wait_q);
728 }
729
730 /*
731  * Handle not operational event while online.
732  */
733 static void
734 ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
735 {
736         struct subchannel *sch;
737
738         sch = to_subchannel(cdev->dev.parent);
739         if (sch->driver->notify &&
740             sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
741                         ccw_device_set_timeout(cdev, 0);
742                         cdev->private->flags.fake_irb = 0;
743                         cdev->private->state = DEV_STATE_DISCONNECTED;
744                         wake_up(&cdev->private->wait_q);
745                         return;
746         }
747         cdev->private->state = DEV_STATE_NOT_OPER;
748         cio_disable_subchannel(sch);
749         if (sch->schib.scsw.actl != 0) {
750                 // FIXME: not-oper indication to device driver ?
751                 ccw_device_call_handler(cdev);
752         }
753         if (get_device(&cdev->dev)) {
754                 PREPARE_WORK(&cdev->private->kick_work,
755                              ccw_device_call_sch_unregister, (void *)cdev);
756                 queue_work(ccw_device_work, &cdev->private->kick_work);
757         }
758         wake_up(&cdev->private->wait_q);
759 }
760
761 /*
762  * Handle path verification event.
763  */
764 static void
765 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
766 {
767         struct subchannel *sch;
768
769         if (cdev->private->state == DEV_STATE_W4SENSE) {
770                 cdev->private->flags.doverify = 1;
771                 return;
772         }
773         sch = to_subchannel(cdev->dev.parent);
774         /*
775          * Since we might not just be coming from an interrupt from the
776          * subchannel we have to update the schib.
777          */
778         stsch(sch->schid, &sch->schib);
779
780         if (sch->schib.scsw.actl != 0 ||
781             (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
782             (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
783                 /*
784                  * No final status yet or final status not yet delivered
785                  * to the device driver. Can't do path verfication now,
786                  * delay until final status was delivered.
787                  */
788                 cdev->private->flags.doverify = 1;
789                 return;
790         }
791         /* Device is idle, we can do the path verification. */
792         cdev->private->state = DEV_STATE_VERIFY;
793         cdev->private->flags.doverify = 0;
794         ccw_device_verify_start(cdev);
795 }
796
797 /*
798  * Got an interrupt for a normal io (state online).
799  */
800 static void
801 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
802 {
803         struct irb *irb;
804
805         irb = (struct irb *) __LC_IRB;
806         /* Check for unsolicited interrupt. */
807         if ((irb->scsw.stctl ==
808                         (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
809             && (!irb->scsw.cc)) {
810                 if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
811                     !irb->esw.esw0.erw.cons) {
812                         /* Unit check but no sense data. Need basic sense. */
813                         if (ccw_device_do_sense(cdev, irb) != 0)
814                                 goto call_handler_unsol;
815                         memcpy(&cdev->private->irb, irb, sizeof(struct irb));
816                         cdev->private->state = DEV_STATE_W4SENSE;
817                         cdev->private->intparm = 0;
818                         return;
819                 }
820 call_handler_unsol:
821                 if (cdev->handler)
822                         cdev->handler (cdev, 0, irb);
823                 return;
824         }
825         /* Accumulate status and find out if a basic sense is needed. */
826         ccw_device_accumulate_irb(cdev, irb);
827         if (cdev->private->flags.dosense) {
828                 if (ccw_device_do_sense(cdev, irb) == 0) {
829                         cdev->private->state = DEV_STATE_W4SENSE;
830                 }
831                 return;
832         }
833         /* Call the handler. */
834         if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
835                 /* Start delayed path verification. */
836                 ccw_device_online_verify(cdev, 0);
837 }
838
839 /*
840  * Got an timeout in online state.
841  */
842 static void
843 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
844 {
845         int ret;
846
847         ccw_device_set_timeout(cdev, 0);
848         ret = ccw_device_cancel_halt_clear(cdev);
849         if (ret == -EBUSY) {
850                 ccw_device_set_timeout(cdev, 3*HZ);
851                 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
852                 return;
853         }
854         if (ret == -ENODEV) {
855                 struct subchannel *sch;
856
857                 sch = to_subchannel(cdev->dev.parent);
858                 if (!sch->lpm) {
859                         PREPARE_WORK(&cdev->private->kick_work,
860                                      ccw_device_nopath_notify, (void *)cdev);
861                         queue_work(ccw_device_notify_work,
862                                    &cdev->private->kick_work);
863                 } else
864                         dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
865         } else if (cdev->handler)
866                 cdev->handler(cdev, cdev->private->intparm,
867                               ERR_PTR(-ETIMEDOUT));
868 }
869
870 /*
871  * Got an interrupt for a basic sense.
872  */
873 void
874 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
875 {
876         struct irb *irb;
877
878         irb = (struct irb *) __LC_IRB;
879         /* Check for unsolicited interrupt. */
880         if (irb->scsw.stctl ==
881                         (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
882                 if (irb->scsw.cc == 1)
883                         /* Basic sense hasn't started. Try again. */
884                         ccw_device_do_sense(cdev, irb);
885                 else {
886                         printk("Huh? %s(%s): unsolicited interrupt...\n",
887                                __FUNCTION__, cdev->dev.bus_id);
888                         if (cdev->handler)
889                                 cdev->handler (cdev, 0, irb);
890                 }
891                 return;
892         }
893         /*
894          * Check if a halt or clear has been issued in the meanwhile. If yes,
895          * only deliver the halt/clear interrupt to the device driver as if it
896          * had killed the original request.
897          */
898         if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
899                 cdev->private->flags.dosense = 0;
900                 memset(&cdev->private->irb, 0, sizeof(struct irb));
901                 ccw_device_accumulate_irb(cdev, irb);
902                 goto call_handler;
903         }
904         /* Add basic sense info to irb. */
905         ccw_device_accumulate_basic_sense(cdev, irb);
906         if (cdev->private->flags.dosense) {
907                 /* Another basic sense is needed. */
908                 ccw_device_do_sense(cdev, irb);
909                 return;
910         }
911 call_handler:
912         cdev->private->state = DEV_STATE_ONLINE;
913         /* Call the handler. */
914         if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
915                 /* Start delayed path verification. */
916                 ccw_device_online_verify(cdev, 0);
917 }
918
919 static void
920 ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
921 {
922         struct irb *irb;
923
924         irb = (struct irb *) __LC_IRB;
925         /* Accumulate status. We don't do basic sense. */
926         ccw_device_accumulate_irb(cdev, irb);
927         /* Remember to clear irb to avoid residuals. */
928         memset(&cdev->private->irb, 0, sizeof(struct irb));
929         /* Try to start delayed device verification. */
930         ccw_device_online_verify(cdev, 0);
931         /* Note: Don't call handler for cio initiated clear! */
932 }
933
934 static void
935 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
936 {
937         struct subchannel *sch;
938
939         sch = to_subchannel(cdev->dev.parent);
940         ccw_device_set_timeout(cdev, 0);
941         /* OK, i/o is dead now. Call interrupt handler. */
942         cdev->private->state = DEV_STATE_ONLINE;
943         if (cdev->handler)
944                 cdev->handler(cdev, cdev->private->intparm,
945                               ERR_PTR(-ETIMEDOUT));
946         if (!sch->lpm) {
947                 PREPARE_WORK(&cdev->private->kick_work,
948                              ccw_device_nopath_notify, (void *)cdev);
949                 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
950         } else if (cdev->private->flags.doverify)
951                 /* Start delayed path verification. */
952                 ccw_device_online_verify(cdev, 0);
953 }
954
955 static void
956 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
957 {
958         int ret;
959
960         ret = ccw_device_cancel_halt_clear(cdev);
961         if (ret == -EBUSY) {
962                 ccw_device_set_timeout(cdev, 3*HZ);
963                 return;
964         }
965         if (ret == -ENODEV) {
966                 struct subchannel *sch;
967
968                 sch = to_subchannel(cdev->dev.parent);
969                 if (!sch->lpm) {
970                         PREPARE_WORK(&cdev->private->kick_work,
971                                      ccw_device_nopath_notify, (void *)cdev);
972                         queue_work(ccw_device_notify_work,
973                                    &cdev->private->kick_work);
974                 } else
975                         dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
976                 return;
977         }
978         //FIXME: Can we get here?
979         cdev->private->state = DEV_STATE_ONLINE;
980         if (cdev->handler)
981                 cdev->handler(cdev, cdev->private->intparm,
982                               ERR_PTR(-ETIMEDOUT));
983 }
984
985 static void
986 ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
987 {
988         struct irb *irb;
989         struct subchannel *sch;
990
991         irb = (struct irb *) __LC_IRB;
992         /*
993          * Accumulate status and find out if a basic sense is needed.
994          * This is fine since we have already adapted the lpm.
995          */
996         ccw_device_accumulate_irb(cdev, irb);
997         if (cdev->private->flags.dosense) {
998                 if (ccw_device_do_sense(cdev, irb) == 0) {
999                         cdev->private->state = DEV_STATE_W4SENSE;
1000                 }
1001                 return;
1002         }
1003
1004         /* Iff device is idle, reset timeout. */
1005         sch = to_subchannel(cdev->dev.parent);
1006         if (!stsch(sch->schid, &sch->schib))
1007                 if (sch->schib.scsw.actl == 0)
1008                         ccw_device_set_timeout(cdev, 0);
1009         /* Call the handler. */
1010         ccw_device_call_handler(cdev);
1011         if (!sch->lpm) {
1012                 PREPARE_WORK(&cdev->private->kick_work,
1013                              ccw_device_nopath_notify, (void *)cdev);
1014                 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1015         } else if (cdev->private->flags.doverify)
1016                 ccw_device_online_verify(cdev, 0);
1017 }
1018
1019 static void
1020 ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1021 {
1022         int ret;
1023         struct subchannel *sch;
1024
1025         sch = to_subchannel(cdev->dev.parent);
1026         ccw_device_set_timeout(cdev, 0);
1027         ret = ccw_device_cancel_halt_clear(cdev);
1028         if (ret == -EBUSY) {
1029                 ccw_device_set_timeout(cdev, 3*HZ);
1030                 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
1031                 return;
1032         }
1033         if (ret == -ENODEV) {
1034                 if (!sch->lpm) {
1035                         PREPARE_WORK(&cdev->private->kick_work,
1036                                      ccw_device_nopath_notify, (void *)cdev);
1037                         queue_work(ccw_device_notify_work,
1038                                    &cdev->private->kick_work);
1039                 } else
1040                         dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1041                 return;
1042         }
1043         if (cdev->handler)
1044                 cdev->handler(cdev, cdev->private->intparm,
1045                               ERR_PTR(-ETIMEDOUT));
1046         if (!sch->lpm) {
1047                 PREPARE_WORK(&cdev->private->kick_work,
1048                              ccw_device_nopath_notify, (void *)cdev);
1049                 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1050         } else if (cdev->private->flags.doverify)
1051                 /* Start delayed path verification. */
1052                 ccw_device_online_verify(cdev, 0);
1053 }
1054
1055 static void
1056 ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
1057 {
1058         /* Start verification after current task finished. */
1059         cdev->private->flags.doverify = 1;
1060 }
1061
1062 static void
1063 ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
1064 {
1065         struct irb *irb;
1066
1067         switch (dev_event) {
1068         case DEV_EVENT_INTERRUPT:
1069                 irb = (struct irb *) __LC_IRB;
1070                 /* Check for unsolicited interrupt. */
1071                 if ((irb->scsw.stctl ==
1072                      (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
1073                     (!irb->scsw.cc))
1074                         /* FIXME: we should restart stlck here, but this
1075                          * is extremely unlikely ... */
1076                         goto out_wakeup;
1077
1078                 ccw_device_accumulate_irb(cdev, irb);
1079                 /* We don't care about basic sense etc. */
1080                 break;
1081         default: /* timeout */
1082                 break;
1083         }
1084 out_wakeup:
1085         wake_up(&cdev->private->wait_q);
1086 }
1087
1088 static void
1089 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
1090 {
1091         struct subchannel *sch;
1092
1093         sch = to_subchannel(cdev->dev.parent);
1094         if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
1095                 /* Couldn't enable the subchannel for i/o. Sick device. */
1096                 return;
1097
1098         /* After 60s the device recognition is considered to have failed. */
1099         ccw_device_set_timeout(cdev, 60*HZ);
1100
1101         cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
1102         ccw_device_sense_id_start(cdev);
1103 }
1104
1105 void
1106 device_trigger_reprobe(struct subchannel *sch)
1107 {
1108         struct ccw_device *cdev;
1109
1110         if (!sch->dev.driver_data)
1111                 return;
1112         cdev = sch->dev.driver_data;
1113         if (cdev->private->state != DEV_STATE_DISCONNECTED)
1114                 return;
1115
1116         /* Update some values. */
1117         if (stsch(sch->schid, &sch->schib))
1118                 return;
1119
1120         /*
1121          * The pim, pam, pom values may not be accurate, but they are the best
1122          * we have before performing device selection :/
1123          */
1124         sch->lpm = sch->schib.pmcw.pam & sch->opm;
1125         /* Re-set some bits in the pmcw that were lost. */
1126         sch->schib.pmcw.isc = 3;
1127         sch->schib.pmcw.csense = 1;
1128         sch->schib.pmcw.ena = 0;
1129         if ((sch->lpm & (sch->lpm - 1)) != 0)
1130                 sch->schib.pmcw.mp = 1;
1131         sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1132         /* We should also udate ssd info, but this has to wait. */
1133         ccw_device_start_id(cdev, 0);
1134 }
1135
1136 static void
1137 ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1138 {
1139         struct subchannel *sch;
1140
1141         sch = to_subchannel(cdev->dev.parent);
1142         /*
1143          * An interrupt in state offline means a previous disable was not
1144          * successful. Try again.
1145          */
1146         cio_disable_subchannel(sch);
1147 }
1148
1149 static void
1150 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1151 {
1152         retry_set_schib(cdev);
1153         cdev->private->state = DEV_STATE_ONLINE;
1154         dev_fsm_event(cdev, dev_event);
1155 }
1156
1157 static void ccw_device_update_cmfblock(struct ccw_device *cdev,
1158                                        enum dev_event dev_event)
1159 {
1160         cmf_retry_copy_block(cdev);
1161         cdev->private->state = DEV_STATE_ONLINE;
1162         dev_fsm_event(cdev, dev_event);
1163 }
1164
1165 static void
1166 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1167 {
1168         ccw_device_set_timeout(cdev, 0);
1169         if (dev_event == DEV_EVENT_NOTOPER)
1170                 cdev->private->state = DEV_STATE_NOT_OPER;
1171         else
1172                 cdev->private->state = DEV_STATE_OFFLINE;
1173         wake_up(&cdev->private->wait_q);
1174 }
1175
1176 static void
1177 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1178 {
1179         int ret;
1180
1181         ret = ccw_device_cancel_halt_clear(cdev);
1182         switch (ret) {
1183         case 0:
1184                 cdev->private->state = DEV_STATE_OFFLINE;
1185                 wake_up(&cdev->private->wait_q);
1186                 break;
1187         case -ENODEV:
1188                 cdev->private->state = DEV_STATE_NOT_OPER;
1189                 wake_up(&cdev->private->wait_q);
1190                 break;
1191         default:
1192                 ccw_device_set_timeout(cdev, HZ/10);
1193         }
1194 }
1195
1196 /*
1197  * No operation action. This is used e.g. to ignore a timeout event in
1198  * state offline.
1199  */
1200 static void
1201 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1202 {
1203 }
1204
1205 /*
1206  * Bug operation action. 
1207  */
1208 static void
1209 ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1210 {
1211         printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1212                cdev->private->state, dev_event);
1213         BUG();
1214 }
1215
1216 /*
1217  * device statemachine
1218  */
1219 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1220         [DEV_STATE_NOT_OPER] = {
1221                 [DEV_EVENT_NOTOPER]     = ccw_device_nop,
1222                 [DEV_EVENT_INTERRUPT]   = ccw_device_bug,
1223                 [DEV_EVENT_TIMEOUT]     = ccw_device_nop,
1224                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1225         },
1226         [DEV_STATE_SENSE_PGID] = {
1227                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1228                 [DEV_EVENT_INTERRUPT]   = ccw_device_sense_pgid_irq,
1229                 [DEV_EVENT_TIMEOUT]     = ccw_device_onoff_timeout,
1230                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1231         },
1232         [DEV_STATE_SENSE_ID] = {
1233                 [DEV_EVENT_NOTOPER]     = ccw_device_recog_notoper,
1234                 [DEV_EVENT_INTERRUPT]   = ccw_device_sense_id_irq,
1235                 [DEV_EVENT_TIMEOUT]     = ccw_device_recog_timeout,
1236                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1237         },
1238         [DEV_STATE_OFFLINE] = {
1239                 [DEV_EVENT_NOTOPER]     = ccw_device_offline_notoper,
1240                 [DEV_EVENT_INTERRUPT]   = ccw_device_offline_irq,
1241                 [DEV_EVENT_TIMEOUT]     = ccw_device_nop,
1242                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1243         },
1244         [DEV_STATE_VERIFY] = {
1245                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1246                 [DEV_EVENT_INTERRUPT]   = ccw_device_verify_irq,
1247                 [DEV_EVENT_TIMEOUT]     = ccw_device_onoff_timeout,
1248                 [DEV_EVENT_VERIFY]      = ccw_device_delay_verify,
1249         },
1250         [DEV_STATE_ONLINE] = {
1251                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1252                 [DEV_EVENT_INTERRUPT]   = ccw_device_irq,
1253                 [DEV_EVENT_TIMEOUT]     = ccw_device_online_timeout,
1254                 [DEV_EVENT_VERIFY]      = ccw_device_online_verify,
1255         },
1256         [DEV_STATE_W4SENSE] = {
1257                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1258                 [DEV_EVENT_INTERRUPT]   = ccw_device_w4sense,
1259                 [DEV_EVENT_TIMEOUT]     = ccw_device_nop,
1260                 [DEV_EVENT_VERIFY]      = ccw_device_online_verify,
1261         },
1262         [DEV_STATE_DISBAND_PGID] = {
1263                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1264                 [DEV_EVENT_INTERRUPT]   = ccw_device_disband_irq,
1265                 [DEV_EVENT_TIMEOUT]     = ccw_device_onoff_timeout,
1266                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1267         },
1268         [DEV_STATE_BOXED] = {
1269                 [DEV_EVENT_NOTOPER]     = ccw_device_offline_notoper,
1270                 [DEV_EVENT_INTERRUPT]   = ccw_device_stlck_done,
1271                 [DEV_EVENT_TIMEOUT]     = ccw_device_stlck_done,
1272                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1273         },
1274         /* states to wait for i/o completion before doing something */
1275         [DEV_STATE_CLEAR_VERIFY] = {
1276                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1277                 [DEV_EVENT_INTERRUPT]   = ccw_device_clear_verify,
1278                 [DEV_EVENT_TIMEOUT]     = ccw_device_nop,
1279                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1280         },
1281         [DEV_STATE_TIMEOUT_KILL] = {
1282                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1283                 [DEV_EVENT_INTERRUPT]   = ccw_device_killing_irq,
1284                 [DEV_EVENT_TIMEOUT]     = ccw_device_killing_timeout,
1285                 [DEV_EVENT_VERIFY]      = ccw_device_nop, //FIXME
1286         },
1287         [DEV_STATE_WAIT4IO] = {
1288                 [DEV_EVENT_NOTOPER]     = ccw_device_online_notoper,
1289                 [DEV_EVENT_INTERRUPT]   = ccw_device_wait4io_irq,
1290                 [DEV_EVENT_TIMEOUT]     = ccw_device_wait4io_timeout,
1291                 [DEV_EVENT_VERIFY]      = ccw_device_delay_verify,
1292         },
1293         [DEV_STATE_QUIESCE] = {
1294                 [DEV_EVENT_NOTOPER]     = ccw_device_quiesce_done,
1295                 [DEV_EVENT_INTERRUPT]   = ccw_device_quiesce_done,
1296                 [DEV_EVENT_TIMEOUT]     = ccw_device_quiesce_timeout,
1297                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1298         },
1299         /* special states for devices gone not operational */
1300         [DEV_STATE_DISCONNECTED] = {
1301                 [DEV_EVENT_NOTOPER]     = ccw_device_nop,
1302                 [DEV_EVENT_INTERRUPT]   = ccw_device_start_id,
1303                 [DEV_EVENT_TIMEOUT]     = ccw_device_bug,
1304                 [DEV_EVENT_VERIFY]      = ccw_device_start_id,
1305         },
1306         [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1307                 [DEV_EVENT_NOTOPER]     = ccw_device_recog_notoper,
1308                 [DEV_EVENT_INTERRUPT]   = ccw_device_sense_id_irq,
1309                 [DEV_EVENT_TIMEOUT]     = ccw_device_recog_timeout,
1310                 [DEV_EVENT_VERIFY]      = ccw_device_nop,
1311         },
1312         [DEV_STATE_CMFCHANGE] = {
1313                 [DEV_EVENT_NOTOPER]     = ccw_device_change_cmfstate,
1314                 [DEV_EVENT_INTERRUPT]   = ccw_device_change_cmfstate,
1315                 [DEV_EVENT_TIMEOUT]     = ccw_device_change_cmfstate,
1316                 [DEV_EVENT_VERIFY]      = ccw_device_change_cmfstate,
1317         },
1318         [DEV_STATE_CMFUPDATE] = {
1319                 [DEV_EVENT_NOTOPER]     = ccw_device_update_cmfblock,
1320                 [DEV_EVENT_INTERRUPT]   = ccw_device_update_cmfblock,
1321                 [DEV_EVENT_TIMEOUT]     = ccw_device_update_cmfblock,
1322                 [DEV_EVENT_VERIFY]      = ccw_device_update_cmfblock,
1323         },
1324 };
1325
1326 /*
1327  * io_subchannel_irq is called for "real" interrupts or for status
1328  * pending conditions on msch.
1329  */
1330 void
1331 io_subchannel_irq (struct device *pdev)
1332 {
1333         struct ccw_device *cdev;
1334
1335         cdev = to_subchannel(pdev)->dev.driver_data;
1336
1337         CIO_TRACE_EVENT (3, "IRQ");
1338         CIO_TRACE_EVENT (3, pdev->bus_id);
1339         if (cdev)
1340                 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1341 }
1342
1343 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);