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