2 * drivers/s390/cio/device_fsm.c
3 * finite state machine for device handling
5 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
7 * Author(s): Cornelia Huck(cohuck@de.ibm.com)
8 * Martin Schwidefsky (schwidefsky@de.ibm.com)
11 #include <linux/module.h>
12 #include <linux/config.h>
13 #include <linux/init.h>
15 #include <asm/ccwdev.h>
19 #include "cio_debug.h"
27 device_is_disconnected(struct subchannel *sch)
29 struct ccw_device *cdev;
31 if (!sch->dev.driver_data)
33 cdev = sch->dev.driver_data;
34 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
35 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
39 device_set_disconnected(struct subchannel *sch)
41 struct ccw_device *cdev;
43 if (!sch->dev.driver_data)
45 cdev = sch->dev.driver_data;
46 ccw_device_set_timeout(cdev, 0);
47 cdev->private->state = DEV_STATE_DISCONNECTED;
51 device_set_waiting(struct subchannel *sch)
53 struct ccw_device *cdev;
55 if (!sch->dev.driver_data)
57 cdev = sch->dev.driver_data;
58 ccw_device_set_timeout(cdev, 10*HZ);
59 cdev->private->state = DEV_STATE_WAIT4IO;
63 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
66 ccw_device_timeout(unsigned long data)
68 struct ccw_device *cdev;
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);
80 ccw_device_set_timeout(struct ccw_device *cdev, int expires)
83 del_timer(&cdev->private->timer);
86 if (timer_pending(&cdev->private->timer)) {
87 if (mod_timer(&cdev->private->timer, jiffies + expires))
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);
97 * Cancel running i/o. This is called repeatedly since halt/clear are
98 * asynchronous operations. We do one try with cio_cancel, two tries
99 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
100 * Returns 0 if device now idle, -ENODEV for device not operational and
101 * -EBUSY if an interrupt is expected (either from halt/clear or from a
105 ccw_device_cancel_halt_clear(struct ccw_device *cdev)
107 struct subchannel *sch;
110 sch = to_subchannel(cdev->dev.parent);
111 ret = stsch(sch->irq, &sch->schib);
112 if (ret || !sch->schib.pmcw.dnv)
114 if (!sch->schib.pmcw.ena || sch->schib.scsw.actl == 0)
115 /* Not operational or no activity -> done. */
117 /* Stage 1: cancel io. */
118 if (!(sch->schib.scsw.actl & SCSW_ACTL_HALT_PEND) &&
119 !(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
120 ret = cio_cancel(sch);
123 /* cancel io unsuccessful. From now on it is asynchronous. */
124 cdev->private->iretry = 3; /* 3 halt retries. */
126 if (!(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
127 /* Stage 2: halt io. */
128 if (cdev->private->iretry) {
129 cdev->private->iretry--;
131 return (ret == 0) ? -EBUSY : ret;
133 /* halt io unsuccessful. */
134 cdev->private->iretry = 255; /* 255 clear retries. */
136 /* Stage 3: clear io. */
137 if (cdev->private->iretry) {
138 cdev->private->iretry--;
139 ret = cio_clear (sch);
140 return (ret == 0) ? -EBUSY : ret;
142 panic("Can't stop i/o on subchannel.\n");
146 ccw_device_handle_oper(struct ccw_device *cdev)
148 struct subchannel *sch;
150 sch = to_subchannel(cdev->dev.parent);
151 cdev->private->flags.recog_done = 1;
153 * Check if cu type and device type still match. If
154 * not, it is certainly another device and we have to
155 * de- and re-register. Also check here for non-matching devno.
157 if (cdev->id.cu_type != cdev->private->senseid.cu_type ||
158 cdev->id.cu_model != cdev->private->senseid.cu_model ||
159 cdev->id.dev_type != cdev->private->senseid.dev_type ||
160 cdev->id.dev_model != cdev->private->senseid.dev_model ||
161 cdev->private->devno != sch->schib.pmcw.dev) {
162 PREPARE_WORK(&cdev->private->kick_work,
163 ccw_device_do_unreg_rereg, (void *)cdev);
164 queue_work(ccw_device_work, &cdev->private->kick_work);
167 cdev->private->flags.donotify = 1;
168 /* Get device online again. */
169 ccw_device_online(cdev);
173 * The machine won't give us any notification by machine check if a chpid has
174 * been varied online on the SE so we have to find out by magic (i. e. driving
175 * the channel subsystem to device selection and updating our path masks).
178 __recover_lost_chpids(struct subchannel *sch, int old_lpm)
182 for (i = 0; i<8; i++) {
184 if (!(sch->lpm & mask))
188 chpid_is_actually_online(sch->schib.pmcw.chpid[i]);
193 * Stop device recognition.
196 ccw_device_recog_done(struct ccw_device *cdev, int state)
198 struct subchannel *sch;
201 sch = to_subchannel(cdev->dev.parent);
203 ccw_device_set_timeout(cdev, 0);
204 cio_disable_subchannel(sch);
206 * Now that we tried recognition, we have performed device selection
207 * through ssch() and the path information is up to date.
210 stsch(sch->irq, &sch->schib);
211 sch->lpm = sch->schib.pmcw.pim &
212 sch->schib.pmcw.pam &
213 sch->schib.pmcw.pom &
215 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
216 /* Force reprobe on all chpids. */
218 if (sch->lpm != old_lpm)
219 __recover_lost_chpids(sch, old_lpm);
220 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
221 if (state == DEV_STATE_NOT_OPER) {
222 cdev->private->flags.recog_done = 1;
223 cdev->private->state = DEV_STATE_DISCONNECTED;
226 /* Boxed devices don't need extra treatment. */
230 case DEV_STATE_NOT_OPER:
231 CIO_DEBUG(KERN_WARNING, 2,
232 "SenseID : unknown device %04x on subchannel %04x\n",
233 cdev->private->devno, sch->irq);
235 case DEV_STATE_OFFLINE:
236 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
238 else /* fill out sense information */
239 cdev->id = (struct ccw_device_id) {
240 .cu_type = cdev->private->senseid.cu_type,
241 .cu_model = cdev->private->senseid.cu_model,
242 .dev_type = cdev->private->senseid.dev_type,
243 .dev_model = cdev->private->senseid.dev_model,
245 /* Issue device info message. */
246 CIO_DEBUG(KERN_INFO, 2, "SenseID : device %04x reports: "
247 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
248 "%04X/%02X\n", cdev->private->devno,
249 cdev->id.cu_type, cdev->id.cu_model,
250 cdev->id.dev_type, cdev->id.dev_model);
252 case DEV_STATE_BOXED:
253 CIO_DEBUG(KERN_WARNING, 2,
254 "SenseID : boxed device %04x on subchannel %04x\n",
255 cdev->private->devno, sch->irq);
258 cdev->private->state = state;
259 if (notify && state == DEV_STATE_OFFLINE)
260 ccw_device_handle_oper(cdev);
262 io_subchannel_recog_done(cdev);
263 if (state != DEV_STATE_NOT_OPER)
264 wake_up(&cdev->private->wait_q);
268 * Function called from device_id.c after sense id has completed.
271 ccw_device_sense_id_done(struct ccw_device *cdev, int err)
275 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
277 case -ETIME: /* Sense id stopped by timeout. */
278 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
281 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
287 ccw_device_oper_notify(void *data)
289 struct ccw_device *cdev;
290 struct subchannel *sch;
293 cdev = (struct ccw_device *)data;
294 sch = to_subchannel(cdev->dev.parent);
295 ret = (sch->driver && sch->driver->notify) ?
296 sch->driver->notify(&sch->dev, CIO_OPER) : 0;
298 /* Driver doesn't want device back. */
299 ccw_device_do_unreg_rereg((void *)cdev);
301 wake_up(&cdev->private->wait_q);
305 * Finished with online/offline processing.
308 ccw_device_done(struct ccw_device *cdev, int state)
310 struct subchannel *sch;
312 sch = to_subchannel(cdev->dev.parent);
314 if (state != DEV_STATE_ONLINE)
315 cio_disable_subchannel(sch);
317 /* Reset device status. */
318 memset(&cdev->private->irb, 0, sizeof(struct irb));
320 cdev->private->state = state;
323 if (state == DEV_STATE_BOXED)
324 CIO_DEBUG(KERN_WARNING, 2,
325 "Boxed device %04x on subchannel %04x\n",
326 cdev->private->devno, sch->irq);
328 if (cdev->private->flags.donotify) {
329 cdev->private->flags.donotify = 0;
330 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,
332 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
334 wake_up(&cdev->private->wait_q);
336 if (css_init_done && state != DEV_STATE_ONLINE)
337 put_device (&cdev->dev);
341 * Function called from device_pgid.c after sense path ground has completed.
344 ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
346 struct subchannel *sch;
348 sch = to_subchannel(cdev->dev.parent);
351 /* Start Path Group verification. */
352 sch->vpm = 0; /* Start with no path groups set. */
353 cdev->private->state = DEV_STATE_VERIFY;
354 ccw_device_verify_start(cdev);
356 case -ETIME: /* Sense path group id stopped by timeout. */
357 case -EUSERS: /* device is reserved for someone else. */
358 ccw_device_done(cdev, DEV_STATE_BOXED);
360 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
361 cdev->private->options.pgroup = 0;
362 ccw_device_done(cdev, DEV_STATE_ONLINE);
365 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
371 * Start device recognition.
374 ccw_device_recognition(struct ccw_device *cdev)
376 struct subchannel *sch;
379 if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
380 (cdev->private->state != DEV_STATE_BOXED))
382 sch = to_subchannel(cdev->dev.parent);
383 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
385 /* Couldn't enable the subchannel for i/o. Sick device. */
388 /* After 60s the device recognition is considered to have failed. */
389 ccw_device_set_timeout(cdev, 60*HZ);
392 * We used to start here with a sense pgid to find out whether a device
393 * is locked by someone else. Unfortunately, the sense pgid command
394 * code has other meanings on devices predating the path grouping
395 * algorithm, so we start with sense id and box the device after an
396 * timeout (or if sense pgid during path verification detects the device
397 * is locked, as may happen on newer devices).
399 cdev->private->flags.recog_done = 0;
400 cdev->private->state = DEV_STATE_SENSE_ID;
401 ccw_device_sense_id_start(cdev);
406 * Handle timeout in device recognition.
409 ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
413 ret = ccw_device_cancel_halt_clear(cdev);
416 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
419 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
422 ccw_device_set_timeout(cdev, 3*HZ);
428 ccw_device_nopath_notify(void *data)
430 struct ccw_device *cdev;
431 struct subchannel *sch;
434 cdev = (struct ccw_device *)data;
435 sch = to_subchannel(cdev->dev.parent);
439 ret = (sch->driver && sch->driver->notify) ?
440 sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0;
442 if (get_device(&sch->dev)) {
443 /* Driver doesn't want to keep device. */
444 cio_disable_subchannel(sch);
445 if (get_device(&cdev->dev)) {
446 PREPARE_WORK(&cdev->private->kick_work,
447 ccw_device_call_sch_unregister,
449 queue_work(ccw_device_work,
450 &cdev->private->kick_work);
454 cio_disable_subchannel(sch);
455 ccw_device_set_timeout(cdev, 0);
456 cdev->private->state = DEV_STATE_DISCONNECTED;
457 wake_up(&cdev->private->wait_q);
462 ccw_device_verify_done(struct ccw_device *cdev, int err)
464 cdev->private->flags.doverify = 0;
466 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
467 cdev->private->options.pgroup = 0;
469 ccw_device_done(cdev, DEV_STATE_ONLINE);
472 ccw_device_done(cdev, DEV_STATE_BOXED);
475 PREPARE_WORK(&cdev->private->kick_work,
476 ccw_device_nopath_notify, (void *)cdev);
477 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
478 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
487 ccw_device_online(struct ccw_device *cdev)
489 struct subchannel *sch;
492 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
493 (cdev->private->state != DEV_STATE_BOXED))
495 sch = to_subchannel(cdev->dev.parent);
496 if (css_init_done && !get_device(&cdev->dev))
498 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
500 /* Couldn't enable the subchannel for i/o. Sick device. */
502 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
505 /* Do we want to do path grouping? */
506 if (!cdev->private->options.pgroup) {
507 /* No, set state online immediately. */
508 ccw_device_done(cdev, DEV_STATE_ONLINE);
511 /* Do a SensePGID first. */
512 cdev->private->state = DEV_STATE_SENSE_PGID;
513 ccw_device_sense_pgid_start(cdev);
518 ccw_device_disband_done(struct ccw_device *cdev, int err)
522 ccw_device_done(cdev, DEV_STATE_OFFLINE);
525 ccw_device_done(cdev, DEV_STATE_BOXED);
528 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
537 ccw_device_offline(struct ccw_device *cdev)
539 struct subchannel *sch;
541 sch = to_subchannel(cdev->dev.parent);
542 if (cdev->private->state != DEV_STATE_ONLINE) {
543 if (sch->schib.scsw.actl != 0)
547 if (sch->schib.scsw.actl != 0)
549 /* Are we doing path grouping? */
550 if (!cdev->private->options.pgroup) {
551 /* No, set state offline immediately. */
552 ccw_device_done(cdev, DEV_STATE_OFFLINE);
555 /* Start Set Path Group commands. */
556 cdev->private->state = DEV_STATE_DISBAND_PGID;
557 ccw_device_disband_start(cdev);
562 * Handle timeout in device online/offline process.
565 ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
569 ret = ccw_device_cancel_halt_clear(cdev);
572 ccw_device_done(cdev, DEV_STATE_BOXED);
575 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
578 ccw_device_set_timeout(cdev, 3*HZ);
583 * Handle not oper event in device recognition.
586 ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
588 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
592 * Handle not operational event while offline.
595 ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
597 struct subchannel *sch;
599 cdev->private->state = DEV_STATE_NOT_OPER;
600 sch = to_subchannel(cdev->dev.parent);
601 device_unregister(&sch->dev);
602 sch->schib.pmcw.intparm = 0;
604 wake_up(&cdev->private->wait_q);
608 * Handle not operational event while online.
611 ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
613 struct subchannel *sch;
615 sch = to_subchannel(cdev->dev.parent);
616 if (sch->driver->notify &&
617 sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
618 ccw_device_set_timeout(cdev, 0);
619 cdev->private->state = DEV_STATE_DISCONNECTED;
620 wake_up(&cdev->private->wait_q);
623 cdev->private->state = DEV_STATE_NOT_OPER;
624 cio_disable_subchannel(sch);
625 if (sch->schib.scsw.actl != 0) {
626 // FIXME: not-oper indication to device driver ?
627 ccw_device_call_handler(cdev);
629 device_unregister(&sch->dev);
630 sch->schib.pmcw.intparm = 0;
632 wake_up(&cdev->private->wait_q);
636 * Handle path verification event.
639 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
641 struct subchannel *sch;
643 if (!cdev->private->options.pgroup)
645 if (cdev->private->state == DEV_STATE_W4SENSE) {
646 cdev->private->flags.doverify = 1;
649 sch = to_subchannel(cdev->dev.parent);
650 if (sch->schib.scsw.actl != 0 ||
651 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
653 * No final status yet or final status not yet delivered
654 * to the device driver. Can't do path verfication now,
655 * delay until final status was delivered.
657 cdev->private->flags.doverify = 1;
660 /* Device is idle, we can do the path verification. */
661 cdev->private->state = DEV_STATE_VERIFY;
662 ccw_device_verify_start(cdev);
666 * Got an interrupt for a normal io (state online).
669 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
673 irb = (struct irb *) __LC_IRB;
674 /* Check for unsolicited interrupt. */
675 if (irb->scsw.stctl ==
676 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
678 cdev->handler (cdev, 0, irb);
681 /* Accumulate status and find out if a basic sense is needed. */
682 ccw_device_accumulate_irb(cdev, irb);
683 if (cdev->private->flags.dosense) {
684 if (ccw_device_do_sense(cdev, irb) == 0) {
685 cdev->private->state = DEV_STATE_W4SENSE;
689 /* Call the handler. */
690 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
691 /* Start delayed path verification. */
692 ccw_device_online_verify(cdev, 0);
696 * Got an timeout in online state.
699 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
703 ccw_device_set_timeout(cdev, 0);
704 ret = ccw_device_cancel_halt_clear(cdev);
706 ccw_device_set_timeout(cdev, 3*HZ);
707 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
710 if (ret == -ENODEV) {
711 struct subchannel *sch;
713 sch = to_subchannel(cdev->dev.parent);
715 PREPARE_WORK(&cdev->private->kick_work,
716 ccw_device_nopath_notify, (void *)cdev);
717 queue_work(ccw_device_notify_work,
718 &cdev->private->kick_work);
720 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
721 } else if (cdev->handler)
722 cdev->handler(cdev, cdev->private->intparm,
723 ERR_PTR(-ETIMEDOUT));
727 * Got an interrupt for a basic sense.
730 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
734 irb = (struct irb *) __LC_IRB;
735 /* Check for unsolicited interrupt. */
736 if (irb->scsw.stctl ==
737 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
739 cdev->handler (cdev, 0, irb);
740 if (irb->scsw.cc == 1)
741 /* Basic sense hasn't started. Try again. */
742 ccw_device_do_sense(cdev, irb);
745 /* Add basic sense info to irb. */
746 ccw_device_accumulate_basic_sense(cdev, irb);
747 if (cdev->private->flags.dosense) {
748 /* Another basic sense is needed. */
749 ccw_device_do_sense(cdev, irb);
752 cdev->private->state = DEV_STATE_ONLINE;
753 /* Call the handler. */
754 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
755 /* Start delayed path verification. */
756 ccw_device_online_verify(cdev, 0);
760 ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
764 irb = (struct irb *) __LC_IRB;
765 /* Check for unsolicited interrupt. */
766 if (irb->scsw.stctl ==
767 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
769 cdev->handler (cdev, 0, irb);
772 /* Accumulate status. We don't do basic sense. */
773 ccw_device_accumulate_irb(cdev, irb);
774 /* Try to start delayed device verification. */
775 ccw_device_online_verify(cdev, 0);
776 /* Note: Don't call handler for cio initiated clear! */
780 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
782 struct subchannel *sch;
784 sch = to_subchannel(cdev->dev.parent);
785 ccw_device_set_timeout(cdev, 0);
786 /* OK, i/o is dead now. Call interrupt handler. */
787 cdev->private->state = DEV_STATE_ONLINE;
789 cdev->handler(cdev, cdev->private->intparm,
790 ERR_PTR(-ETIMEDOUT));
792 PREPARE_WORK(&cdev->private->kick_work,
793 ccw_device_nopath_notify, (void *)cdev);
794 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
795 } else if (cdev->private->flags.doverify)
796 /* Start delayed path verification. */
797 ccw_device_online_verify(cdev, 0);
801 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
805 ret = ccw_device_cancel_halt_clear(cdev);
807 ccw_device_set_timeout(cdev, 3*HZ);
810 if (ret == -ENODEV) {
811 struct subchannel *sch;
813 sch = to_subchannel(cdev->dev.parent);
815 PREPARE_WORK(&cdev->private->kick_work,
816 ccw_device_nopath_notify, (void *)cdev);
817 queue_work(ccw_device_notify_work,
818 &cdev->private->kick_work);
820 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
823 //FIXME: Can we get here?
824 cdev->private->state = DEV_STATE_ONLINE;
826 cdev->handler(cdev, cdev->private->intparm,
827 ERR_PTR(-ETIMEDOUT));
831 ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
834 struct subchannel *sch;
836 irb = (struct irb *) __LC_IRB;
837 /* Check for unsolicited interrupt. */
838 if (irb->scsw.stctl ==
839 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
841 cdev->handler (cdev, 0, irb);
842 if (irb->scsw.cc == 1)
847 * Accumulate status and find out if a basic sense is needed.
848 * This is fine since we have already adapted the lpm.
850 ccw_device_accumulate_irb(cdev, irb);
851 if (cdev->private->flags.dosense) {
852 if (ccw_device_do_sense(cdev, irb) == 0) {
853 cdev->private->state = DEV_STATE_W4SENSE;
858 /* Iff device is idle, reset timeout. */
859 sch = to_subchannel(cdev->dev.parent);
860 if (!stsch(sch->irq, &sch->schib))
861 if (sch->schib.scsw.actl == 0)
862 ccw_device_set_timeout(cdev, 0);
863 /* Call the handler. */
864 ccw_device_call_handler(cdev);
866 PREPARE_WORK(&cdev->private->kick_work,
867 ccw_device_nopath_notify, (void *)cdev);
868 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
869 } else if (cdev->private->flags.doverify)
870 ccw_device_online_verify(cdev, 0);
874 ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
877 struct subchannel *sch;
879 sch = to_subchannel(cdev->dev.parent);
880 ccw_device_set_timeout(cdev, 0);
881 ret = ccw_device_cancel_halt_clear(cdev);
883 ccw_device_set_timeout(cdev, 3*HZ);
884 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
887 if (ret == -ENODEV) {
889 PREPARE_WORK(&cdev->private->kick_work,
890 ccw_device_nopath_notify, (void *)cdev);
891 queue_work(ccw_device_notify_work,
892 &cdev->private->kick_work);
894 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
898 cdev->handler(cdev, cdev->private->intparm,
899 ERR_PTR(-ETIMEDOUT));
901 PREPARE_WORK(&cdev->private->kick_work,
902 ccw_device_nopath_notify, (void *)cdev);
903 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
904 } else if (cdev->private->flags.doverify)
905 /* Start delayed path verification. */
906 ccw_device_online_verify(cdev, 0);
910 ccw_device_wait4io_verify(struct ccw_device *cdev, enum dev_event dev_event)
912 /* When the I/O has terminated, we have to start verification. */
913 if (cdev->private->options.pgroup)
914 cdev->private->flags.doverify = 1;
918 ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
923 case DEV_EVENT_INTERRUPT:
924 irb = (struct irb *) __LC_IRB;
925 /* Check for unsolicited interrupt. */
926 if (irb->scsw.stctl ==
927 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
928 /* FIXME: we should restart stlck here, but this
929 * is extremely unlikely ... */
932 ccw_device_accumulate_irb(cdev, irb);
933 /* We don't care about basic sense etc. */
935 default: /* timeout */
939 wake_up(&cdev->private->wait_q);
943 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
945 struct subchannel *sch;
947 sch = to_subchannel(cdev->dev.parent);
948 if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
949 /* Couldn't enable the subchannel for i/o. Sick device. */
952 /* After 60s the device recognition is considered to have failed. */
953 ccw_device_set_timeout(cdev, 60*HZ);
955 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
956 ccw_device_sense_id_start(cdev);
960 device_trigger_reprobe(struct subchannel *sch)
962 struct ccw_device *cdev;
965 if (!sch->dev.driver_data)
967 cdev = sch->dev.driver_data;
968 spin_lock_irqsave(&sch->lock, flags);
969 if (cdev->private->state != DEV_STATE_DISCONNECTED) {
970 spin_unlock_irqrestore(&sch->lock, flags);
973 /* Update some values. */
974 if (stsch(sch->irq, &sch->schib)) {
975 spin_unlock_irqrestore(&sch->lock, flags);
979 * The pim, pam, pom values may not be accurate, but they are the best
980 * we have before performing device selection :/
982 sch->lpm = sch->schib.pmcw.pim &
983 sch->schib.pmcw.pam &
984 sch->schib.pmcw.pom &
986 /* Re-set some bits in the pmcw that were lost. */
987 sch->schib.pmcw.isc = 3;
988 sch->schib.pmcw.csense = 1;
989 sch->schib.pmcw.ena = 0;
990 if ((sch->lpm & (sch->lpm - 1)) != 0)
991 sch->schib.pmcw.mp = 1;
992 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
993 ccw_device_start_id(cdev, 0);
994 spin_unlock_irqrestore(&sch->lock, flags);
998 ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1000 struct subchannel *sch;
1002 sch = to_subchannel(cdev->dev.parent);
1004 * An interrupt in state offline means a previous disable was not
1005 * successful. Try again.
1007 cio_disable_subchannel(sch);
1011 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1013 retry_set_schib(cdev);
1014 cdev->private->state = DEV_STATE_ONLINE;
1015 dev_fsm_event(cdev, dev_event);
1020 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1022 ccw_device_set_timeout(cdev, 0);
1023 if (dev_event == DEV_EVENT_NOTOPER)
1024 cdev->private->state = DEV_STATE_NOT_OPER;
1026 cdev->private->state = DEV_STATE_OFFLINE;
1027 wake_up(&cdev->private->wait_q);
1031 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1035 ret = ccw_device_cancel_halt_clear(cdev);
1038 cdev->private->state = DEV_STATE_OFFLINE;
1039 wake_up(&cdev->private->wait_q);
1042 cdev->private->state = DEV_STATE_NOT_OPER;
1043 wake_up(&cdev->private->wait_q);
1046 ccw_device_set_timeout(cdev, HZ/10);
1051 * No operation action. This is used e.g. to ignore a timeout event in
1055 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1060 * Bug operation action.
1063 ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1065 printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1066 cdev->private->state, dev_event);
1071 * device statemachine
1073 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1074 [DEV_STATE_NOT_OPER] = {
1075 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1076 [DEV_EVENT_INTERRUPT] = ccw_device_bug,
1077 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1078 [DEV_EVENT_VERIFY] = ccw_device_nop,
1080 [DEV_STATE_SENSE_PGID] = {
1081 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1082 [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
1083 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1084 [DEV_EVENT_VERIFY] = ccw_device_nop,
1086 [DEV_STATE_SENSE_ID] = {
1087 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1088 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1089 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1090 [DEV_EVENT_VERIFY] = ccw_device_nop,
1092 [DEV_STATE_OFFLINE] = {
1093 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1094 [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
1095 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1096 [DEV_EVENT_VERIFY] = ccw_device_nop,
1098 [DEV_STATE_VERIFY] = {
1099 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1100 [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
1101 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1102 [DEV_EVENT_VERIFY] = ccw_device_nop,
1104 [DEV_STATE_ONLINE] = {
1105 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1106 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1107 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1108 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1110 [DEV_STATE_W4SENSE] = {
1111 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1112 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1113 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1114 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1116 [DEV_STATE_DISBAND_PGID] = {
1117 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1118 [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
1119 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1120 [DEV_EVENT_VERIFY] = ccw_device_nop,
1122 [DEV_STATE_BOXED] = {
1123 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1124 [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
1125 [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
1126 [DEV_EVENT_VERIFY] = ccw_device_nop,
1128 /* states to wait for i/o completion before doing something */
1129 [DEV_STATE_CLEAR_VERIFY] = {
1130 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1131 [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
1132 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1133 [DEV_EVENT_VERIFY] = ccw_device_nop,
1135 [DEV_STATE_TIMEOUT_KILL] = {
1136 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1137 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1138 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1139 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1141 [DEV_STATE_WAIT4IO] = {
1142 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1143 [DEV_EVENT_INTERRUPT] = ccw_device_wait4io_irq,
1144 [DEV_EVENT_TIMEOUT] = ccw_device_wait4io_timeout,
1145 [DEV_EVENT_VERIFY] = ccw_device_wait4io_verify,
1147 [DEV_STATE_QUIESCE] = {
1148 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1149 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1150 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1151 [DEV_EVENT_VERIFY] = ccw_device_nop,
1153 /* special states for devices gone not operational */
1154 [DEV_STATE_DISCONNECTED] = {
1155 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1156 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1157 [DEV_EVENT_TIMEOUT] = ccw_device_bug,
1158 [DEV_EVENT_VERIFY] = ccw_device_nop,
1160 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1161 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1162 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1163 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1164 [DEV_EVENT_VERIFY] = ccw_device_nop,
1166 [DEV_STATE_CMFCHANGE] = {
1167 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1168 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1169 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1170 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1175 * io_subchannel_irq is called for "real" interrupts or for status
1176 * pending conditions on msch.
1179 io_subchannel_irq (struct device *pdev)
1181 struct ccw_device *cdev;
1183 cdev = to_subchannel(pdev)->dev.driver_data;
1185 CIO_TRACE_EVENT (3, "IRQ");
1186 CIO_TRACE_EVENT (3, pdev->bus_id);
1188 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1191 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);