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