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.
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 PREPARE_WORK(&cdev->private->kick_work,
162 ccw_device_do_unreg_rereg, (void *)&cdev->dev);
163 queue_work(ccw_device_work, &cdev->private->kick_work);
166 cdev->private->flags.donotify = 1;
167 /* Get device online again. */
168 ccw_device_online(cdev);
172 * The machine won't give us any notification by machine check if a chpid has
173 * been varied online on the SE so we have to find out by magic (i. e. driving
174 * the channel subsystem to device selection and updating our path masks).
177 __recover_lost_chpids(struct subchannel *sch, int old_lpm)
181 for (i = 0; i<8; i++) {
183 if (!(sch->lpm & mask))
187 chpid_is_actually_online(sch->schib.pmcw.chpid[i]);
192 * Stop device recognition.
195 ccw_device_recog_done(struct ccw_device *cdev, int state)
197 struct subchannel *sch;
200 sch = to_subchannel(cdev->dev.parent);
202 ccw_device_set_timeout(cdev, 0);
203 cio_disable_subchannel(sch);
205 * Now that we tried recognition, we have performed device selection
206 * through ssch() and the path information is up to date.
209 stsch(sch->irq, &sch->schib);
210 sch->lpm = sch->schib.pmcw.pim &
211 sch->schib.pmcw.pam &
212 sch->schib.pmcw.pom &
214 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
215 /* Force reprobe on all chpids. */
217 if (sch->lpm != old_lpm)
218 __recover_lost_chpids(sch, old_lpm);
219 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
220 if (state == DEV_STATE_NOT_OPER) {
221 cdev->private->flags.recog_done = 1;
222 cdev->private->state = DEV_STATE_DISCONNECTED;
225 /* Boxed devices don't need extra treatment. */
229 case DEV_STATE_NOT_OPER:
230 CIO_DEBUG(KERN_WARNING, 2,
231 "SenseID : unknown device %04x on subchannel %04x\n",
232 cdev->private->devno, sch->irq);
234 case DEV_STATE_OFFLINE:
235 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
237 else /* fill out sense information */
238 cdev->id = (struct ccw_device_id) {
239 .cu_type = cdev->private->senseid.cu_type,
240 .cu_model = cdev->private->senseid.cu_model,
241 .dev_type = cdev->private->senseid.dev_type,
242 .dev_model = cdev->private->senseid.dev_model,
244 /* Issue device info message. */
245 CIO_DEBUG(KERN_INFO, 2, "SenseID : device %04x reports: "
246 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
247 "%04X/%02X\n", cdev->private->devno,
248 cdev->id.cu_type, cdev->id.cu_model,
249 cdev->id.dev_type, cdev->id.dev_model);
251 case DEV_STATE_BOXED:
252 CIO_DEBUG(KERN_WARNING, 2,
253 "SenseID : boxed device %04x on subchannel %04x\n",
254 cdev->private->devno, sch->irq);
257 cdev->private->state = state;
258 if (notify && state == DEV_STATE_OFFLINE)
259 ccw_device_handle_oper(cdev);
261 io_subchannel_recog_done(cdev);
262 if (state != DEV_STATE_NOT_OPER)
263 wake_up(&cdev->private->wait_q);
267 * Function called from device_id.c after sense id has completed.
270 ccw_device_sense_id_done(struct ccw_device *cdev, int err)
274 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
276 case -ETIME: /* Sense id stopped by timeout. */
277 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
280 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
286 ccw_device_oper_notify(void *data)
288 struct ccw_device *cdev;
289 struct subchannel *sch;
292 cdev = (struct ccw_device *)data;
293 sch = to_subchannel(cdev->dev.parent);
294 ret = (sch->driver && sch->driver->notify) ?
295 sch->driver->notify(&sch->dev, CIO_OPER) : 0;
297 /* Driver doesn't want device back. */
298 ccw_device_do_unreg_rereg((void *)&cdev->dev);
300 wake_up(&cdev->private->wait_q);
304 * Finished with online/offline processing.
307 ccw_device_done(struct ccw_device *cdev, int state)
309 struct subchannel *sch;
311 sch = to_subchannel(cdev->dev.parent);
313 if (state != DEV_STATE_ONLINE)
314 cio_disable_subchannel(sch);
316 /* Reset device status. */
317 memset(&cdev->private->irb, 0, sizeof(struct irb));
319 cdev->private->state = state;
322 if (state == DEV_STATE_BOXED)
323 CIO_DEBUG(KERN_WARNING, 2,
324 "Boxed device %04x on subchannel %04x\n",
325 cdev->private->devno, sch->irq);
327 if (cdev->private->flags.donotify) {
328 cdev->private->flags.donotify = 0;
329 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,
331 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
333 wake_up(&cdev->private->wait_q);
335 if (css_init_done && state != DEV_STATE_ONLINE)
336 put_device (&cdev->dev);
340 * Function called from device_pgid.c after sense path ground has completed.
343 ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
345 struct subchannel *sch;
347 sch = to_subchannel(cdev->dev.parent);
350 /* Start Path Group verification. */
351 sch->vpm = 0; /* Start with no path groups set. */
352 cdev->private->state = DEV_STATE_VERIFY;
353 ccw_device_verify_start(cdev);
355 case -ETIME: /* Sense path group id stopped by timeout. */
356 case -EUSERS: /* device is reserved for someone else. */
357 ccw_device_done(cdev, DEV_STATE_BOXED);
359 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
360 cdev->private->options.pgroup = 0;
361 ccw_device_done(cdev, DEV_STATE_ONLINE);
364 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
370 * Start device recognition.
373 ccw_device_recognition(struct ccw_device *cdev)
375 struct subchannel *sch;
378 if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
379 (cdev->private->state != DEV_STATE_BOXED))
381 sch = to_subchannel(cdev->dev.parent);
382 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
384 /* Couldn't enable the subchannel for i/o. Sick device. */
387 /* After 60s the device recognition is considered to have failed. */
388 ccw_device_set_timeout(cdev, 60*HZ);
391 * We used to start here with a sense pgid to find out whether a device
392 * is locked by someone else. Unfortunately, the sense pgid command
393 * code has other meanings on devices predating the path grouping
394 * algorithm, so we start with sense id and box the device after an
395 * timeout (or if sense pgid during path verification detects the device
396 * is locked, as may happen on newer devices).
398 cdev->private->flags.recog_done = 0;
399 cdev->private->state = DEV_STATE_SENSE_ID;
400 ccw_device_sense_id_start(cdev);
405 * Handle timeout in device recognition.
408 ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
412 ret = ccw_device_cancel_halt_clear(cdev);
415 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
418 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
421 ccw_device_set_timeout(cdev, 3*HZ);
427 ccw_device_nopath_notify(void *data)
429 struct ccw_device *cdev;
430 struct subchannel *sch;
433 cdev = (struct ccw_device *)data;
434 sch = to_subchannel(cdev->dev.parent);
438 ret = (sch->driver && sch->driver->notify) ?
439 sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0;
441 if (get_device(&sch->dev)) {
442 /* Driver doesn't want to keep device. */
443 cio_disable_subchannel(sch);
444 if (get_device(&cdev->dev)) {
445 PREPARE_WORK(&cdev->private->kick_work,
446 ccw_device_call_sch_unregister,
448 queue_work(ccw_device_work,
449 &cdev->private->kick_work);
453 cio_disable_subchannel(sch);
454 ccw_device_set_timeout(cdev, 0);
455 cdev->private->state = DEV_STATE_DISCONNECTED;
456 wake_up(&cdev->private->wait_q);
461 device_call_nopath_notify(struct subchannel *sch)
463 struct ccw_device *cdev;
465 if (!sch->dev.driver_data)
467 cdev = sch->dev.driver_data;
468 PREPARE_WORK(&cdev->private->kick_work,
469 ccw_device_nopath_notify, (void *)cdev);
470 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
475 ccw_device_verify_done(struct ccw_device *cdev, int err)
477 cdev->private->flags.doverify = 0;
480 ccw_device_done(cdev, DEV_STATE_ONLINE);
483 ccw_device_done(cdev, DEV_STATE_BOXED);
486 PREPARE_WORK(&cdev->private->kick_work,
487 ccw_device_nopath_notify, (void *)cdev);
488 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
489 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
498 ccw_device_online(struct ccw_device *cdev)
500 struct subchannel *sch;
503 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
504 (cdev->private->state != DEV_STATE_BOXED))
506 sch = to_subchannel(cdev->dev.parent);
507 if (css_init_done && !get_device(&cdev->dev))
509 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
511 /* Couldn't enable the subchannel for i/o. Sick device. */
513 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
516 /* Do we want to do path grouping? */
517 if (!cdev->private->options.pgroup) {
518 /* No, set state online immediately. */
519 ccw_device_done(cdev, DEV_STATE_ONLINE);
522 /* Do a SensePGID first. */
523 cdev->private->state = DEV_STATE_SENSE_PGID;
524 ccw_device_sense_pgid_start(cdev);
529 ccw_device_disband_done(struct ccw_device *cdev, int err)
533 ccw_device_done(cdev, DEV_STATE_OFFLINE);
536 ccw_device_done(cdev, DEV_STATE_BOXED);
539 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
548 ccw_device_offline(struct ccw_device *cdev)
550 struct subchannel *sch;
552 sch = to_subchannel(cdev->dev.parent);
553 if (cdev->private->state != DEV_STATE_ONLINE) {
554 if (sch->schib.scsw.actl != 0)
558 if (sch->schib.scsw.actl != 0)
560 /* Are we doing path grouping? */
561 if (!cdev->private->options.pgroup) {
562 /* No, set state offline immediately. */
563 ccw_device_done(cdev, DEV_STATE_OFFLINE);
566 /* Start Set Path Group commands. */
567 cdev->private->state = DEV_STATE_DISBAND_PGID;
568 ccw_device_disband_start(cdev);
573 * Handle timeout in device online/offline process.
576 ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
580 ret = ccw_device_cancel_halt_clear(cdev);
583 ccw_device_done(cdev, DEV_STATE_BOXED);
586 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
589 ccw_device_set_timeout(cdev, 3*HZ);
594 * Handle not oper event in device recognition.
597 ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
599 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
603 * Handle not operational event while offline.
606 ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
608 struct subchannel *sch;
610 cdev->private->state = DEV_STATE_NOT_OPER;
611 sch = to_subchannel(cdev->dev.parent);
612 device_unregister(&sch->dev);
613 sch->schib.pmcw.intparm = 0;
615 wake_up(&cdev->private->wait_q);
619 * Handle not operational event while online.
622 ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
624 struct subchannel *sch;
626 sch = to_subchannel(cdev->dev.parent);
627 if (sch->driver->notify &&
628 sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
629 ccw_device_set_timeout(cdev, 0);
630 cdev->private->state = DEV_STATE_DISCONNECTED;
631 wake_up(&cdev->private->wait_q);
634 cdev->private->state = DEV_STATE_NOT_OPER;
635 cio_disable_subchannel(sch);
636 if (sch->schib.scsw.actl != 0) {
637 // FIXME: not-oper indication to device driver ?
638 ccw_device_call_handler(cdev);
640 device_unregister(&sch->dev);
641 sch->schib.pmcw.intparm = 0;
643 wake_up(&cdev->private->wait_q);
647 * Handle path verification event.
650 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
652 struct subchannel *sch;
654 if (!cdev->private->options.pgroup)
656 if (cdev->private->state == DEV_STATE_W4SENSE) {
657 cdev->private->flags.doverify = 1;
660 sch = to_subchannel(cdev->dev.parent);
661 if (sch->schib.scsw.actl != 0 ||
662 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
664 * No final status yet or final status not yet delivered
665 * to the device driver. Can't do path verfication now,
666 * delay until final status was delivered.
668 cdev->private->flags.doverify = 1;
671 /* Device is idle, we can do the path verification. */
672 cdev->private->state = DEV_STATE_VERIFY;
673 ccw_device_verify_start(cdev);
677 * Got an interrupt for a normal io (state online).
680 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
684 irb = (struct irb *) __LC_IRB;
685 /* Check for unsolicited interrupt. */
686 if (irb->scsw.stctl ==
687 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
689 cdev->handler (cdev, 0, irb);
692 /* Accumulate status and find out if a basic sense is needed. */
693 ccw_device_accumulate_irb(cdev, irb);
694 if (cdev->private->flags.dosense) {
695 if (ccw_device_do_sense(cdev, irb) == 0) {
696 cdev->private->state = DEV_STATE_W4SENSE;
700 /* Call the handler. */
701 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
702 /* Start delayed path verification. */
703 ccw_device_online_verify(cdev, 0);
707 * Got an timeout in online state.
710 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
714 ccw_device_set_timeout(cdev, 0);
715 ret = ccw_device_cancel_halt_clear(cdev);
717 ccw_device_set_timeout(cdev, 3*HZ);
718 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
721 if (ret == -ENODEV) {
722 struct subchannel *sch;
724 sch = to_subchannel(cdev->dev.parent);
726 PREPARE_WORK(&cdev->private->kick_work,
727 ccw_device_nopath_notify, (void *)cdev);
728 queue_work(ccw_device_notify_work,
729 &cdev->private->kick_work);
731 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
732 } else if (cdev->handler)
733 cdev->handler(cdev, cdev->private->intparm,
734 ERR_PTR(-ETIMEDOUT));
738 * Got an interrupt for a basic sense.
741 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
745 irb = (struct irb *) __LC_IRB;
746 /* Check for unsolicited interrupt. */
747 if (irb->scsw.stctl ==
748 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
750 cdev->handler (cdev, 0, irb);
751 if (irb->scsw.cc == 1)
752 /* Basic sense hasn't started. Try again. */
753 ccw_device_do_sense(cdev, irb);
756 /* Add basic sense info to irb. */
757 ccw_device_accumulate_basic_sense(cdev, irb);
758 if (cdev->private->flags.dosense) {
759 /* Another basic sense is needed. */
760 ccw_device_do_sense(cdev, irb);
763 cdev->private->state = DEV_STATE_ONLINE;
764 /* Call the handler. */
765 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
766 /* Start delayed path verification. */
767 ccw_device_online_verify(cdev, 0);
771 ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
775 irb = (struct irb *) __LC_IRB;
776 /* Check for unsolicited interrupt. */
777 if (irb->scsw.stctl ==
778 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
780 cdev->handler (cdev, 0, irb);
783 /* Accumulate status. We don't do basic sense. */
784 ccw_device_accumulate_irb(cdev, irb);
785 /* Try to start delayed device verification. */
786 ccw_device_online_verify(cdev, 0);
787 /* Note: Don't call handler for cio initiated clear! */
791 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
793 struct subchannel *sch;
795 sch = to_subchannel(cdev->dev.parent);
796 ccw_device_set_timeout(cdev, 0);
797 /* OK, i/o is dead now. Call interrupt handler. */
798 cdev->private->state = DEV_STATE_ONLINE;
800 cdev->handler(cdev, cdev->private->intparm,
801 ERR_PTR(-ETIMEDOUT));
803 PREPARE_WORK(&cdev->private->kick_work,
804 ccw_device_nopath_notify, (void *)cdev);
805 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
806 } else if (cdev->private->flags.doverify)
807 /* Start delayed path verification. */
808 ccw_device_online_verify(cdev, 0);
812 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
816 ret = ccw_device_cancel_halt_clear(cdev);
818 ccw_device_set_timeout(cdev, 3*HZ);
821 if (ret == -ENODEV) {
822 struct subchannel *sch;
824 sch = to_subchannel(cdev->dev.parent);
826 PREPARE_WORK(&cdev->private->kick_work,
827 ccw_device_nopath_notify, (void *)cdev);
828 queue_work(ccw_device_notify_work,
829 &cdev->private->kick_work);
831 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
834 //FIXME: Can we get here?
835 cdev->private->state = DEV_STATE_ONLINE;
837 cdev->handler(cdev, cdev->private->intparm,
838 ERR_PTR(-ETIMEDOUT));
842 ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
845 struct subchannel *sch;
847 irb = (struct irb *) __LC_IRB;
848 /* Check for unsolicited interrupt. */
849 if (irb->scsw.stctl ==
850 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
852 cdev->handler (cdev, 0, irb);
853 if (irb->scsw.cc == 1)
858 * Accumulate status and find out if a basic sense is needed.
859 * This is fine since we have already adapted the lpm.
861 ccw_device_accumulate_irb(cdev, irb);
862 if (cdev->private->flags.dosense) {
863 if (ccw_device_do_sense(cdev, irb) == 0) {
864 cdev->private->state = DEV_STATE_W4SENSE;
869 /* Iff device is idle, reset timeout. */
870 sch = to_subchannel(cdev->dev.parent);
871 if (!stsch(sch->irq, &sch->schib))
872 if (sch->schib.scsw.actl == 0)
873 ccw_device_set_timeout(cdev, 0);
874 /* Call the handler. */
875 ccw_device_call_handler(cdev);
877 PREPARE_WORK(&cdev->private->kick_work,
878 ccw_device_nopath_notify, (void *)cdev);
879 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
880 } else if (cdev->private->flags.doverify)
881 ccw_device_online_verify(cdev, 0);
885 ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
888 struct subchannel *sch;
890 sch = to_subchannel(cdev->dev.parent);
891 ccw_device_set_timeout(cdev, 0);
892 ret = ccw_device_cancel_halt_clear(cdev);
894 ccw_device_set_timeout(cdev, 3*HZ);
895 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
898 if (ret == -ENODEV) {
900 PREPARE_WORK(&cdev->private->kick_work,
901 ccw_device_nopath_notify, (void *)cdev);
902 queue_work(ccw_device_notify_work,
903 &cdev->private->kick_work);
905 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
909 cdev->handler(cdev, cdev->private->intparm,
910 ERR_PTR(-ETIMEDOUT));
912 PREPARE_WORK(&cdev->private->kick_work,
913 ccw_device_nopath_notify, (void *)cdev);
914 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
915 } else if (cdev->private->flags.doverify)
916 /* Start delayed path verification. */
917 ccw_device_online_verify(cdev, 0);
921 ccw_device_wait4io_verify(struct ccw_device *cdev, enum dev_event dev_event)
923 /* When the I/O has terminated, we have to start verification. */
924 if (cdev->private->options.pgroup)
925 cdev->private->flags.doverify = 1;
929 ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
934 case DEV_EVENT_INTERRUPT:
935 irb = (struct irb *) __LC_IRB;
936 /* Check for unsolicited interrupt. */
937 if (irb->scsw.stctl ==
938 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
939 /* FIXME: we should restart stlck here, but this
940 * is extremely unlikely ... */
943 ccw_device_accumulate_irb(cdev, irb);
944 /* We don't care about basic sense etc. */
946 default: /* timeout */
950 wake_up(&cdev->private->wait_q);
954 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
956 struct subchannel *sch;
958 sch = to_subchannel(cdev->dev.parent);
959 if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
960 /* Couldn't enable the subchannel for i/o. Sick device. */
963 /* After 60s the device recognition is considered to have failed. */
964 ccw_device_set_timeout(cdev, 60*HZ);
966 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
967 ccw_device_sense_id_start(cdev);
971 device_trigger_reprobe(struct subchannel *sch)
973 struct ccw_device *cdev;
976 if (!sch->dev.driver_data)
978 cdev = sch->dev.driver_data;
979 spin_lock_irqsave(&sch->lock, flags);
980 if (cdev->private->state != DEV_STATE_DISCONNECTED) {
981 spin_unlock_irqrestore(&sch->lock, flags);
984 /* Update some values. */
985 if (stsch(sch->irq, &sch->schib)) {
986 spin_unlock_irqrestore(&sch->lock, flags);
990 * The pim, pam, pom values may not be accurate, but they are the best
991 * we have before performing device selection :/
993 sch->lpm = sch->schib.pmcw.pim &
994 sch->schib.pmcw.pam &
995 sch->schib.pmcw.pom &
997 /* Re-set some bits in the pmcw that were lost. */
998 sch->schib.pmcw.isc = 3;
999 sch->schib.pmcw.csense = 1;
1000 sch->schib.pmcw.ena = 0;
1001 if ((sch->lpm & (sch->lpm - 1)) != 0)
1002 sch->schib.pmcw.mp = 1;
1003 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1004 ccw_device_start_id(cdev, 0);
1005 spin_unlock_irqrestore(&sch->lock, flags);
1009 ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1011 struct subchannel *sch;
1013 sch = to_subchannel(cdev->dev.parent);
1015 * An interrupt in state offline means a previous disable was not
1016 * successful. Try again.
1018 cio_disable_subchannel(sch);
1022 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1024 retry_set_schib(cdev);
1025 cdev->private->state = DEV_STATE_ONLINE;
1026 dev_fsm_event(cdev, dev_event);
1031 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1033 ccw_device_set_timeout(cdev, 0);
1034 if (dev_event == DEV_EVENT_NOTOPER)
1035 cdev->private->state = DEV_STATE_NOT_OPER;
1037 cdev->private->state = DEV_STATE_OFFLINE;
1038 wake_up(&cdev->private->wait_q);
1042 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1046 ret = ccw_device_cancel_halt_clear(cdev);
1049 cdev->private->state = DEV_STATE_OFFLINE;
1050 wake_up(&cdev->private->wait_q);
1053 cdev->private->state = DEV_STATE_NOT_OPER;
1054 wake_up(&cdev->private->wait_q);
1057 ccw_device_set_timeout(cdev, HZ/10);
1062 * No operation action. This is used e.g. to ignore a timeout event in
1066 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1071 * Bug operation action.
1074 ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1076 printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1077 cdev->private->state, dev_event);
1082 * device statemachine
1084 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1085 [DEV_STATE_NOT_OPER] {
1086 [DEV_EVENT_NOTOPER] ccw_device_nop,
1087 [DEV_EVENT_INTERRUPT] ccw_device_bug,
1088 [DEV_EVENT_TIMEOUT] ccw_device_nop,
1089 [DEV_EVENT_VERIFY] ccw_device_nop,
1091 [DEV_STATE_SENSE_PGID] {
1092 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1093 [DEV_EVENT_INTERRUPT] ccw_device_sense_pgid_irq,
1094 [DEV_EVENT_TIMEOUT] ccw_device_onoff_timeout,
1095 [DEV_EVENT_VERIFY] ccw_device_nop,
1097 [DEV_STATE_SENSE_ID] {
1098 [DEV_EVENT_NOTOPER] ccw_device_recog_notoper,
1099 [DEV_EVENT_INTERRUPT] ccw_device_sense_id_irq,
1100 [DEV_EVENT_TIMEOUT] ccw_device_recog_timeout,
1101 [DEV_EVENT_VERIFY] ccw_device_nop,
1103 [DEV_STATE_OFFLINE] {
1104 [DEV_EVENT_NOTOPER] ccw_device_offline_notoper,
1105 [DEV_EVENT_INTERRUPT] ccw_device_offline_irq,
1106 [DEV_EVENT_TIMEOUT] ccw_device_nop,
1107 [DEV_EVENT_VERIFY] ccw_device_nop,
1109 [DEV_STATE_VERIFY] {
1110 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1111 [DEV_EVENT_INTERRUPT] ccw_device_verify_irq,
1112 [DEV_EVENT_TIMEOUT] ccw_device_onoff_timeout,
1113 [DEV_EVENT_VERIFY] ccw_device_nop,
1115 [DEV_STATE_ONLINE] {
1116 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1117 [DEV_EVENT_INTERRUPT] ccw_device_irq,
1118 [DEV_EVENT_TIMEOUT] ccw_device_online_timeout,
1119 [DEV_EVENT_VERIFY] ccw_device_online_verify,
1121 [DEV_STATE_W4SENSE] {
1122 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1123 [DEV_EVENT_INTERRUPT] ccw_device_w4sense,
1124 [DEV_EVENT_TIMEOUT] ccw_device_nop,
1125 [DEV_EVENT_VERIFY] ccw_device_online_verify,
1127 [DEV_STATE_DISBAND_PGID] {
1128 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1129 [DEV_EVENT_INTERRUPT] ccw_device_disband_irq,
1130 [DEV_EVENT_TIMEOUT] ccw_device_onoff_timeout,
1131 [DEV_EVENT_VERIFY] ccw_device_nop,
1134 [DEV_EVENT_NOTOPER] ccw_device_offline_notoper,
1135 [DEV_EVENT_INTERRUPT] ccw_device_stlck_done,
1136 [DEV_EVENT_TIMEOUT] ccw_device_stlck_done,
1137 [DEV_EVENT_VERIFY] ccw_device_nop,
1139 /* states to wait for i/o completion before doing something */
1140 [DEV_STATE_CLEAR_VERIFY] {
1141 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1142 [DEV_EVENT_INTERRUPT] ccw_device_clear_verify,
1143 [DEV_EVENT_TIMEOUT] ccw_device_nop,
1144 [DEV_EVENT_VERIFY] ccw_device_nop,
1146 [DEV_STATE_TIMEOUT_KILL] {
1147 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1148 [DEV_EVENT_INTERRUPT] ccw_device_killing_irq,
1149 [DEV_EVENT_TIMEOUT] ccw_device_killing_timeout,
1150 [DEV_EVENT_VERIFY] ccw_device_nop, //FIXME
1152 [DEV_STATE_WAIT4IO] {
1153 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1154 [DEV_EVENT_INTERRUPT] ccw_device_wait4io_irq,
1155 [DEV_EVENT_TIMEOUT] ccw_device_wait4io_timeout,
1156 [DEV_EVENT_VERIFY] ccw_device_wait4io_verify,
1158 [DEV_STATE_QUIESCE] {
1159 [DEV_EVENT_NOTOPER] ccw_device_quiesce_done,
1160 [DEV_EVENT_INTERRUPT] ccw_device_quiesce_done,
1161 [DEV_EVENT_TIMEOUT] ccw_device_quiesce_timeout,
1162 [DEV_EVENT_VERIFY] ccw_device_nop,
1164 /* special states for devices gone not operational */
1165 [DEV_STATE_DISCONNECTED] {
1166 [DEV_EVENT_NOTOPER] ccw_device_nop,
1167 [DEV_EVENT_INTERRUPT] ccw_device_start_id,
1168 [DEV_EVENT_TIMEOUT] ccw_device_bug,
1169 [DEV_EVENT_VERIFY] ccw_device_nop,
1171 [DEV_STATE_DISCONNECTED_SENSE_ID] {
1172 [DEV_EVENT_NOTOPER] ccw_device_recog_notoper,
1173 [DEV_EVENT_INTERRUPT] ccw_device_sense_id_irq,
1174 [DEV_EVENT_TIMEOUT] ccw_device_recog_timeout,
1175 [DEV_EVENT_VERIFY] ccw_device_nop,
1177 [DEV_STATE_CMFCHANGE] {
1178 [DEV_EVENT_NOTOPER] ccw_device_change_cmfstate,
1179 [DEV_EVENT_INTERRUPT] ccw_device_change_cmfstate,
1180 [DEV_EVENT_TIMEOUT] ccw_device_change_cmfstate,
1181 [DEV_EVENT_VERIFY] ccw_device_change_cmfstate,
1186 * io_subchannel_irq is called for "real" interrupts or for status
1187 * pending conditions on msch.
1190 io_subchannel_irq (struct device *pdev)
1192 struct ccw_device *cdev;
1194 cdev = to_subchannel(pdev)->dev.driver_data;
1196 CIO_TRACE_EVENT (3, "IRQ");
1197 CIO_TRACE_EVENT (3, pdev->bus_id);
1199 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1202 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);