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 device_call_nopath_notify(struct subchannel *sch)
464 struct ccw_device *cdev;
466 if (!sch->dev.driver_data)
468 cdev = sch->dev.driver_data;
469 PREPARE_WORK(&cdev->private->kick_work,
470 ccw_device_nopath_notify, (void *)cdev);
471 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
476 ccw_device_verify_done(struct ccw_device *cdev, int err)
478 cdev->private->flags.doverify = 0;
480 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
481 cdev->private->options.pgroup = 0;
483 ccw_device_done(cdev, DEV_STATE_ONLINE);
486 ccw_device_done(cdev, DEV_STATE_BOXED);
489 PREPARE_WORK(&cdev->private->kick_work,
490 ccw_device_nopath_notify, (void *)cdev);
491 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
492 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
501 ccw_device_online(struct ccw_device *cdev)
503 struct subchannel *sch;
506 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
507 (cdev->private->state != DEV_STATE_BOXED))
509 sch = to_subchannel(cdev->dev.parent);
510 if (css_init_done && !get_device(&cdev->dev))
512 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
514 /* Couldn't enable the subchannel for i/o. Sick device. */
516 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
519 /* Do we want to do path grouping? */
520 if (!cdev->private->options.pgroup) {
521 /* No, set state online immediately. */
522 ccw_device_done(cdev, DEV_STATE_ONLINE);
525 /* Do a SensePGID first. */
526 cdev->private->state = DEV_STATE_SENSE_PGID;
527 ccw_device_sense_pgid_start(cdev);
532 ccw_device_disband_done(struct ccw_device *cdev, int err)
536 ccw_device_done(cdev, DEV_STATE_OFFLINE);
539 ccw_device_done(cdev, DEV_STATE_BOXED);
542 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
551 ccw_device_offline(struct ccw_device *cdev)
553 struct subchannel *sch;
555 sch = to_subchannel(cdev->dev.parent);
556 if (cdev->private->state != DEV_STATE_ONLINE) {
557 if (sch->schib.scsw.actl != 0)
561 if (sch->schib.scsw.actl != 0)
563 /* Are we doing path grouping? */
564 if (!cdev->private->options.pgroup) {
565 /* No, set state offline immediately. */
566 ccw_device_done(cdev, DEV_STATE_OFFLINE);
569 /* Start Set Path Group commands. */
570 cdev->private->state = DEV_STATE_DISBAND_PGID;
571 ccw_device_disband_start(cdev);
576 * Handle timeout in device online/offline process.
579 ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
583 ret = ccw_device_cancel_halt_clear(cdev);
586 ccw_device_done(cdev, DEV_STATE_BOXED);
589 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
592 ccw_device_set_timeout(cdev, 3*HZ);
597 * Handle not oper event in device recognition.
600 ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
602 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
606 * Handle not operational event while offline.
609 ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
611 struct subchannel *sch;
613 cdev->private->state = DEV_STATE_NOT_OPER;
614 sch = to_subchannel(cdev->dev.parent);
615 device_unregister(&sch->dev);
616 sch->schib.pmcw.intparm = 0;
618 wake_up(&cdev->private->wait_q);
622 * Handle not operational event while online.
625 ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
627 struct subchannel *sch;
629 sch = to_subchannel(cdev->dev.parent);
630 if (sch->driver->notify &&
631 sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
632 ccw_device_set_timeout(cdev, 0);
633 cdev->private->state = DEV_STATE_DISCONNECTED;
634 wake_up(&cdev->private->wait_q);
637 cdev->private->state = DEV_STATE_NOT_OPER;
638 cio_disable_subchannel(sch);
639 if (sch->schib.scsw.actl != 0) {
640 // FIXME: not-oper indication to device driver ?
641 ccw_device_call_handler(cdev);
643 device_unregister(&sch->dev);
644 sch->schib.pmcw.intparm = 0;
646 wake_up(&cdev->private->wait_q);
650 * Handle path verification event.
653 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
655 struct subchannel *sch;
657 if (!cdev->private->options.pgroup)
659 if (cdev->private->state == DEV_STATE_W4SENSE) {
660 cdev->private->flags.doverify = 1;
663 sch = to_subchannel(cdev->dev.parent);
664 if (sch->schib.scsw.actl != 0 ||
665 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
667 * No final status yet or final status not yet delivered
668 * to the device driver. Can't do path verfication now,
669 * delay until final status was delivered.
671 cdev->private->flags.doverify = 1;
674 /* Device is idle, we can do the path verification. */
675 cdev->private->state = DEV_STATE_VERIFY;
676 ccw_device_verify_start(cdev);
680 * Got an interrupt for a normal io (state online).
683 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
687 irb = (struct irb *) __LC_IRB;
688 /* Check for unsolicited interrupt. */
689 if (irb->scsw.stctl ==
690 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
692 cdev->handler (cdev, 0, irb);
695 /* Accumulate status and find out if a basic sense is needed. */
696 ccw_device_accumulate_irb(cdev, irb);
697 if (cdev->private->flags.dosense) {
698 if (ccw_device_do_sense(cdev, irb) == 0) {
699 cdev->private->state = DEV_STATE_W4SENSE;
703 /* Call the handler. */
704 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
705 /* Start delayed path verification. */
706 ccw_device_online_verify(cdev, 0);
710 * Got an timeout in online state.
713 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
717 ccw_device_set_timeout(cdev, 0);
718 ret = ccw_device_cancel_halt_clear(cdev);
720 ccw_device_set_timeout(cdev, 3*HZ);
721 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
724 if (ret == -ENODEV) {
725 struct subchannel *sch;
727 sch = to_subchannel(cdev->dev.parent);
729 PREPARE_WORK(&cdev->private->kick_work,
730 ccw_device_nopath_notify, (void *)cdev);
731 queue_work(ccw_device_notify_work,
732 &cdev->private->kick_work);
734 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
735 } else if (cdev->handler)
736 cdev->handler(cdev, cdev->private->intparm,
737 ERR_PTR(-ETIMEDOUT));
741 * Got an interrupt for a basic sense.
744 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
748 irb = (struct irb *) __LC_IRB;
749 /* Check for unsolicited interrupt. */
750 if (irb->scsw.stctl ==
751 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
753 cdev->handler (cdev, 0, irb);
754 if (irb->scsw.cc == 1)
755 /* Basic sense hasn't started. Try again. */
756 ccw_device_do_sense(cdev, irb);
759 /* Add basic sense info to irb. */
760 ccw_device_accumulate_basic_sense(cdev, irb);
761 if (cdev->private->flags.dosense) {
762 /* Another basic sense is needed. */
763 ccw_device_do_sense(cdev, irb);
766 cdev->private->state = DEV_STATE_ONLINE;
767 /* Call the handler. */
768 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
769 /* Start delayed path verification. */
770 ccw_device_online_verify(cdev, 0);
774 ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
778 irb = (struct irb *) __LC_IRB;
779 /* Check for unsolicited interrupt. */
780 if (irb->scsw.stctl ==
781 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
783 cdev->handler (cdev, 0, irb);
786 /* Accumulate status. We don't do basic sense. */
787 ccw_device_accumulate_irb(cdev, irb);
788 /* Try to start delayed device verification. */
789 ccw_device_online_verify(cdev, 0);
790 /* Note: Don't call handler for cio initiated clear! */
794 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
796 struct subchannel *sch;
798 sch = to_subchannel(cdev->dev.parent);
799 ccw_device_set_timeout(cdev, 0);
800 /* OK, i/o is dead now. Call interrupt handler. */
801 cdev->private->state = DEV_STATE_ONLINE;
803 cdev->handler(cdev, cdev->private->intparm,
804 ERR_PTR(-ETIMEDOUT));
806 PREPARE_WORK(&cdev->private->kick_work,
807 ccw_device_nopath_notify, (void *)cdev);
808 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
809 } else if (cdev->private->flags.doverify)
810 /* Start delayed path verification. */
811 ccw_device_online_verify(cdev, 0);
815 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
819 ret = ccw_device_cancel_halt_clear(cdev);
821 ccw_device_set_timeout(cdev, 3*HZ);
824 if (ret == -ENODEV) {
825 struct subchannel *sch;
827 sch = to_subchannel(cdev->dev.parent);
829 PREPARE_WORK(&cdev->private->kick_work,
830 ccw_device_nopath_notify, (void *)cdev);
831 queue_work(ccw_device_notify_work,
832 &cdev->private->kick_work);
834 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
837 //FIXME: Can we get here?
838 cdev->private->state = DEV_STATE_ONLINE;
840 cdev->handler(cdev, cdev->private->intparm,
841 ERR_PTR(-ETIMEDOUT));
845 ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
848 struct subchannel *sch;
850 irb = (struct irb *) __LC_IRB;
851 /* Check for unsolicited interrupt. */
852 if (irb->scsw.stctl ==
853 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
855 cdev->handler (cdev, 0, irb);
856 if (irb->scsw.cc == 1)
861 * Accumulate status and find out if a basic sense is needed.
862 * This is fine since we have already adapted the lpm.
864 ccw_device_accumulate_irb(cdev, irb);
865 if (cdev->private->flags.dosense) {
866 if (ccw_device_do_sense(cdev, irb) == 0) {
867 cdev->private->state = DEV_STATE_W4SENSE;
872 /* Iff device is idle, reset timeout. */
873 sch = to_subchannel(cdev->dev.parent);
874 if (!stsch(sch->irq, &sch->schib))
875 if (sch->schib.scsw.actl == 0)
876 ccw_device_set_timeout(cdev, 0);
877 /* Call the handler. */
878 ccw_device_call_handler(cdev);
880 PREPARE_WORK(&cdev->private->kick_work,
881 ccw_device_nopath_notify, (void *)cdev);
882 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
883 } else if (cdev->private->flags.doverify)
884 ccw_device_online_verify(cdev, 0);
888 ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
891 struct subchannel *sch;
893 sch = to_subchannel(cdev->dev.parent);
894 ccw_device_set_timeout(cdev, 0);
895 ret = ccw_device_cancel_halt_clear(cdev);
897 ccw_device_set_timeout(cdev, 3*HZ);
898 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
901 if (ret == -ENODEV) {
903 PREPARE_WORK(&cdev->private->kick_work,
904 ccw_device_nopath_notify, (void *)cdev);
905 queue_work(ccw_device_notify_work,
906 &cdev->private->kick_work);
908 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
912 cdev->handler(cdev, cdev->private->intparm,
913 ERR_PTR(-ETIMEDOUT));
915 PREPARE_WORK(&cdev->private->kick_work,
916 ccw_device_nopath_notify, (void *)cdev);
917 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
918 } else if (cdev->private->flags.doverify)
919 /* Start delayed path verification. */
920 ccw_device_online_verify(cdev, 0);
924 ccw_device_wait4io_verify(struct ccw_device *cdev, enum dev_event dev_event)
926 /* When the I/O has terminated, we have to start verification. */
927 if (cdev->private->options.pgroup)
928 cdev->private->flags.doverify = 1;
932 ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
937 case DEV_EVENT_INTERRUPT:
938 irb = (struct irb *) __LC_IRB;
939 /* Check for unsolicited interrupt. */
940 if (irb->scsw.stctl ==
941 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
942 /* FIXME: we should restart stlck here, but this
943 * is extremely unlikely ... */
946 ccw_device_accumulate_irb(cdev, irb);
947 /* We don't care about basic sense etc. */
949 default: /* timeout */
953 wake_up(&cdev->private->wait_q);
957 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
959 struct subchannel *sch;
961 sch = to_subchannel(cdev->dev.parent);
962 if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
963 /* Couldn't enable the subchannel for i/o. Sick device. */
966 /* After 60s the device recognition is considered to have failed. */
967 ccw_device_set_timeout(cdev, 60*HZ);
969 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
970 ccw_device_sense_id_start(cdev);
974 device_trigger_reprobe(struct subchannel *sch)
976 struct ccw_device *cdev;
979 if (!sch->dev.driver_data)
981 cdev = sch->dev.driver_data;
982 spin_lock_irqsave(&sch->lock, flags);
983 if (cdev->private->state != DEV_STATE_DISCONNECTED) {
984 spin_unlock_irqrestore(&sch->lock, flags);
987 /* Update some values. */
988 if (stsch(sch->irq, &sch->schib)) {
989 spin_unlock_irqrestore(&sch->lock, flags);
993 * The pim, pam, pom values may not be accurate, but they are the best
994 * we have before performing device selection :/
996 sch->lpm = sch->schib.pmcw.pim &
997 sch->schib.pmcw.pam &
998 sch->schib.pmcw.pom &
1000 /* Re-set some bits in the pmcw that were lost. */
1001 sch->schib.pmcw.isc = 3;
1002 sch->schib.pmcw.csense = 1;
1003 sch->schib.pmcw.ena = 0;
1004 if ((sch->lpm & (sch->lpm - 1)) != 0)
1005 sch->schib.pmcw.mp = 1;
1006 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1007 ccw_device_start_id(cdev, 0);
1008 spin_unlock_irqrestore(&sch->lock, flags);
1012 ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1014 struct subchannel *sch;
1016 sch = to_subchannel(cdev->dev.parent);
1018 * An interrupt in state offline means a previous disable was not
1019 * successful. Try again.
1021 cio_disable_subchannel(sch);
1025 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1027 retry_set_schib(cdev);
1028 cdev->private->state = DEV_STATE_ONLINE;
1029 dev_fsm_event(cdev, dev_event);
1034 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1036 ccw_device_set_timeout(cdev, 0);
1037 if (dev_event == DEV_EVENT_NOTOPER)
1038 cdev->private->state = DEV_STATE_NOT_OPER;
1040 cdev->private->state = DEV_STATE_OFFLINE;
1041 wake_up(&cdev->private->wait_q);
1045 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1049 ret = ccw_device_cancel_halt_clear(cdev);
1052 cdev->private->state = DEV_STATE_OFFLINE;
1053 wake_up(&cdev->private->wait_q);
1056 cdev->private->state = DEV_STATE_NOT_OPER;
1057 wake_up(&cdev->private->wait_q);
1060 ccw_device_set_timeout(cdev, HZ/10);
1065 * No operation action. This is used e.g. to ignore a timeout event in
1069 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1074 * Bug operation action.
1077 ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1079 printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1080 cdev->private->state, dev_event);
1085 * device statemachine
1087 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1088 [DEV_STATE_NOT_OPER] {
1089 [DEV_EVENT_NOTOPER] ccw_device_nop,
1090 [DEV_EVENT_INTERRUPT] ccw_device_bug,
1091 [DEV_EVENT_TIMEOUT] ccw_device_nop,
1092 [DEV_EVENT_VERIFY] ccw_device_nop,
1094 [DEV_STATE_SENSE_PGID] {
1095 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1096 [DEV_EVENT_INTERRUPT] ccw_device_sense_pgid_irq,
1097 [DEV_EVENT_TIMEOUT] ccw_device_onoff_timeout,
1098 [DEV_EVENT_VERIFY] ccw_device_nop,
1100 [DEV_STATE_SENSE_ID] {
1101 [DEV_EVENT_NOTOPER] ccw_device_recog_notoper,
1102 [DEV_EVENT_INTERRUPT] ccw_device_sense_id_irq,
1103 [DEV_EVENT_TIMEOUT] ccw_device_recog_timeout,
1104 [DEV_EVENT_VERIFY] ccw_device_nop,
1106 [DEV_STATE_OFFLINE] {
1107 [DEV_EVENT_NOTOPER] ccw_device_offline_notoper,
1108 [DEV_EVENT_INTERRUPT] ccw_device_offline_irq,
1109 [DEV_EVENT_TIMEOUT] ccw_device_nop,
1110 [DEV_EVENT_VERIFY] ccw_device_nop,
1112 [DEV_STATE_VERIFY] {
1113 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1114 [DEV_EVENT_INTERRUPT] ccw_device_verify_irq,
1115 [DEV_EVENT_TIMEOUT] ccw_device_onoff_timeout,
1116 [DEV_EVENT_VERIFY] ccw_device_nop,
1118 [DEV_STATE_ONLINE] {
1119 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1120 [DEV_EVENT_INTERRUPT] ccw_device_irq,
1121 [DEV_EVENT_TIMEOUT] ccw_device_online_timeout,
1122 [DEV_EVENT_VERIFY] ccw_device_online_verify,
1124 [DEV_STATE_W4SENSE] {
1125 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1126 [DEV_EVENT_INTERRUPT] ccw_device_w4sense,
1127 [DEV_EVENT_TIMEOUT] ccw_device_nop,
1128 [DEV_EVENT_VERIFY] ccw_device_online_verify,
1130 [DEV_STATE_DISBAND_PGID] {
1131 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1132 [DEV_EVENT_INTERRUPT] ccw_device_disband_irq,
1133 [DEV_EVENT_TIMEOUT] ccw_device_onoff_timeout,
1134 [DEV_EVENT_VERIFY] ccw_device_nop,
1137 [DEV_EVENT_NOTOPER] ccw_device_offline_notoper,
1138 [DEV_EVENT_INTERRUPT] ccw_device_stlck_done,
1139 [DEV_EVENT_TIMEOUT] ccw_device_stlck_done,
1140 [DEV_EVENT_VERIFY] ccw_device_nop,
1142 /* states to wait for i/o completion before doing something */
1143 [DEV_STATE_CLEAR_VERIFY] {
1144 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1145 [DEV_EVENT_INTERRUPT] ccw_device_clear_verify,
1146 [DEV_EVENT_TIMEOUT] ccw_device_nop,
1147 [DEV_EVENT_VERIFY] ccw_device_nop,
1149 [DEV_STATE_TIMEOUT_KILL] {
1150 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1151 [DEV_EVENT_INTERRUPT] ccw_device_killing_irq,
1152 [DEV_EVENT_TIMEOUT] ccw_device_killing_timeout,
1153 [DEV_EVENT_VERIFY] ccw_device_nop, //FIXME
1155 [DEV_STATE_WAIT4IO] {
1156 [DEV_EVENT_NOTOPER] ccw_device_online_notoper,
1157 [DEV_EVENT_INTERRUPT] ccw_device_wait4io_irq,
1158 [DEV_EVENT_TIMEOUT] ccw_device_wait4io_timeout,
1159 [DEV_EVENT_VERIFY] ccw_device_wait4io_verify,
1161 [DEV_STATE_QUIESCE] {
1162 [DEV_EVENT_NOTOPER] ccw_device_quiesce_done,
1163 [DEV_EVENT_INTERRUPT] ccw_device_quiesce_done,
1164 [DEV_EVENT_TIMEOUT] ccw_device_quiesce_timeout,
1165 [DEV_EVENT_VERIFY] ccw_device_nop,
1167 /* special states for devices gone not operational */
1168 [DEV_STATE_DISCONNECTED] {
1169 [DEV_EVENT_NOTOPER] ccw_device_nop,
1170 [DEV_EVENT_INTERRUPT] ccw_device_start_id,
1171 [DEV_EVENT_TIMEOUT] ccw_device_bug,
1172 [DEV_EVENT_VERIFY] ccw_device_nop,
1174 [DEV_STATE_DISCONNECTED_SENSE_ID] {
1175 [DEV_EVENT_NOTOPER] ccw_device_recog_notoper,
1176 [DEV_EVENT_INTERRUPT] ccw_device_sense_id_irq,
1177 [DEV_EVENT_TIMEOUT] ccw_device_recog_timeout,
1178 [DEV_EVENT_VERIFY] ccw_device_nop,
1180 [DEV_STATE_CMFCHANGE] {
1181 [DEV_EVENT_NOTOPER] ccw_device_change_cmfstate,
1182 [DEV_EVENT_INTERRUPT] ccw_device_change_cmfstate,
1183 [DEV_EVENT_TIMEOUT] ccw_device_change_cmfstate,
1184 [DEV_EVENT_VERIFY] ccw_device_change_cmfstate,
1189 * io_subchannel_irq is called for "real" interrupts or for status
1190 * pending conditions on msch.
1193 io_subchannel_irq (struct device *pdev)
1195 struct ccw_device *cdev;
1197 cdev = to_subchannel(pdev)->dev.driver_data;
1199 CIO_TRACE_EVENT (3, "IRQ");
1200 CIO_TRACE_EVENT (3, pdev->bus_id);
1202 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1205 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);