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>
14 #include <linux/jiffies.h>
15 #include <linux/string.h>
17 #include <asm/ccwdev.h>
21 #include "cio_debug.h"
28 device_is_online(struct subchannel *sch)
30 struct ccw_device *cdev;
32 if (!sch->dev.driver_data)
34 cdev = sch->dev.driver_data;
35 return (cdev->private->state == DEV_STATE_ONLINE);
39 device_is_disconnected(struct subchannel *sch)
41 struct ccw_device *cdev;
43 if (!sch->dev.driver_data)
45 cdev = sch->dev.driver_data;
46 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
47 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
51 device_set_disconnected(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, 0);
59 cdev->private->flags.fake_irb = 0;
60 cdev->private->state = DEV_STATE_DISCONNECTED;
64 device_set_waiting(struct subchannel *sch)
66 struct ccw_device *cdev;
68 if (!sch->dev.driver_data)
70 cdev = sch->dev.driver_data;
71 ccw_device_set_timeout(cdev, 10*HZ);
72 cdev->private->state = DEV_STATE_WAIT4IO;
76 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
79 ccw_device_timeout(unsigned long data)
81 struct ccw_device *cdev;
83 cdev = (struct ccw_device *) data;
84 spin_lock_irq(cdev->ccwlock);
85 dev_fsm_event(cdev, DEV_EVENT_TIMEOUT);
86 spin_unlock_irq(cdev->ccwlock);
93 ccw_device_set_timeout(struct ccw_device *cdev, int expires)
96 del_timer(&cdev->private->timer);
99 if (timer_pending(&cdev->private->timer)) {
100 if (mod_timer(&cdev->private->timer, jiffies + expires))
103 cdev->private->timer.function = ccw_device_timeout;
104 cdev->private->timer.data = (unsigned long) cdev;
105 cdev->private->timer.expires = jiffies + expires;
106 add_timer(&cdev->private->timer);
109 /* Kill any pending timers after machine check. */
111 device_kill_pending_timer(struct subchannel *sch)
113 struct ccw_device *cdev;
115 if (!sch->dev.driver_data)
117 cdev = sch->dev.driver_data;
118 ccw_device_set_timeout(cdev, 0);
122 * Cancel running i/o. This is called repeatedly since halt/clear are
123 * asynchronous operations. We do one try with cio_cancel, two tries
124 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
125 * Returns 0 if device now idle, -ENODEV for device not operational and
126 * -EBUSY if an interrupt is expected (either from halt/clear or from a
130 ccw_device_cancel_halt_clear(struct ccw_device *cdev)
132 struct subchannel *sch;
135 sch = to_subchannel(cdev->dev.parent);
136 ret = stsch(sch->irq, &sch->schib);
137 if (ret || !sch->schib.pmcw.dnv)
139 if (!sch->schib.pmcw.ena || sch->schib.scsw.actl == 0)
140 /* Not operational or no activity -> done. */
142 /* Stage 1: cancel io. */
143 if (!(sch->schib.scsw.actl & SCSW_ACTL_HALT_PEND) &&
144 !(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
145 ret = cio_cancel(sch);
148 /* cancel io unsuccessful. From now on it is asynchronous. */
149 cdev->private->iretry = 3; /* 3 halt retries. */
151 if (!(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
152 /* Stage 2: halt io. */
153 if (cdev->private->iretry) {
154 cdev->private->iretry--;
156 return (ret == 0) ? -EBUSY : ret;
158 /* halt io unsuccessful. */
159 cdev->private->iretry = 255; /* 255 clear retries. */
161 /* Stage 3: clear io. */
162 if (cdev->private->iretry) {
163 cdev->private->iretry--;
164 ret = cio_clear (sch);
165 return (ret == 0) ? -EBUSY : ret;
167 panic("Can't stop i/o on subchannel.\n");
171 ccw_device_handle_oper(struct ccw_device *cdev)
173 struct subchannel *sch;
175 sch = to_subchannel(cdev->dev.parent);
176 cdev->private->flags.recog_done = 1;
178 * Check if cu type and device type still match. If
179 * not, it is certainly another device and we have to
180 * de- and re-register. Also check here for non-matching devno.
182 if (cdev->id.cu_type != cdev->private->senseid.cu_type ||
183 cdev->id.cu_model != cdev->private->senseid.cu_model ||
184 cdev->id.dev_type != cdev->private->senseid.dev_type ||
185 cdev->id.dev_model != cdev->private->senseid.dev_model ||
186 cdev->private->devno != sch->schib.pmcw.dev) {
187 PREPARE_WORK(&cdev->private->kick_work,
188 ccw_device_do_unreg_rereg, (void *)cdev);
189 queue_work(ccw_device_work, &cdev->private->kick_work);
192 cdev->private->flags.donotify = 1;
197 * The machine won't give us any notification by machine check if a chpid has
198 * been varied online on the SE so we have to find out by magic (i. e. driving
199 * the channel subsystem to device selection and updating our path masks).
202 __recover_lost_chpids(struct subchannel *sch, int old_lpm)
206 for (i = 0; i<8; i++) {
208 if (!(sch->lpm & mask))
212 chpid_is_actually_online(sch->schib.pmcw.chpid[i]);
217 * Stop device recognition.
220 ccw_device_recog_done(struct ccw_device *cdev, int state)
222 struct subchannel *sch;
223 int notify, old_lpm, same_dev;
225 sch = to_subchannel(cdev->dev.parent);
227 ccw_device_set_timeout(cdev, 0);
228 cio_disable_subchannel(sch);
230 * Now that we tried recognition, we have performed device selection
231 * through ssch() and the path information is up to date.
234 stsch(sch->irq, &sch->schib);
235 sch->lpm = sch->schib.pmcw.pim &
236 sch->schib.pmcw.pam &
237 sch->schib.pmcw.pom &
239 /* Check since device may again have become not operational. */
240 if (!sch->schib.pmcw.dnv)
241 state = DEV_STATE_NOT_OPER;
242 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
243 /* Force reprobe on all chpids. */
245 if (sch->lpm != old_lpm)
246 __recover_lost_chpids(sch, old_lpm);
247 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
248 if (state == DEV_STATE_NOT_OPER) {
249 cdev->private->flags.recog_done = 1;
250 cdev->private->state = DEV_STATE_DISCONNECTED;
253 /* Boxed devices don't need extra treatment. */
256 same_dev = 0; /* Keep the compiler quiet... */
258 case DEV_STATE_NOT_OPER:
259 CIO_DEBUG(KERN_WARNING, 2,
260 "SenseID : unknown device %04x on subchannel %04x\n",
261 cdev->private->devno, sch->irq);
263 case DEV_STATE_OFFLINE:
264 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
265 same_dev = ccw_device_handle_oper(cdev);
268 /* fill out sense information */
269 cdev->id = (struct ccw_device_id) {
270 .cu_type = cdev->private->senseid.cu_type,
271 .cu_model = cdev->private->senseid.cu_model,
272 .dev_type = cdev->private->senseid.dev_type,
273 .dev_model = cdev->private->senseid.dev_model,
276 cdev->private->state = DEV_STATE_OFFLINE;
278 /* Get device online again. */
279 ccw_device_online(cdev);
280 wake_up(&cdev->private->wait_q);
284 /* Issue device info message. */
285 CIO_DEBUG(KERN_INFO, 2, "SenseID : device %04x reports: "
286 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
287 "%04X/%02X\n", cdev->private->devno,
288 cdev->id.cu_type, cdev->id.cu_model,
289 cdev->id.dev_type, cdev->id.dev_model);
291 case DEV_STATE_BOXED:
292 CIO_DEBUG(KERN_WARNING, 2,
293 "SenseID : boxed device %04x on subchannel %04x\n",
294 cdev->private->devno, sch->irq);
297 cdev->private->state = state;
298 io_subchannel_recog_done(cdev);
299 if (state != DEV_STATE_NOT_OPER)
300 wake_up(&cdev->private->wait_q);
304 * Function called from device_id.c after sense id has completed.
307 ccw_device_sense_id_done(struct ccw_device *cdev, int err)
311 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
313 case -ETIME: /* Sense id stopped by timeout. */
314 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
317 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
323 ccw_device_oper_notify(void *data)
325 struct ccw_device *cdev;
326 struct subchannel *sch;
329 cdev = (struct ccw_device *)data;
330 sch = to_subchannel(cdev->dev.parent);
331 ret = (sch->driver && sch->driver->notify) ?
332 sch->driver->notify(&sch->dev, CIO_OPER) : 0;
334 /* Driver doesn't want device back. */
335 ccw_device_do_unreg_rereg((void *)cdev);
337 wake_up(&cdev->private->wait_q);
341 * Finished with online/offline processing.
344 ccw_device_done(struct ccw_device *cdev, int state)
346 struct subchannel *sch;
348 sch = to_subchannel(cdev->dev.parent);
350 if (state != DEV_STATE_ONLINE)
351 cio_disable_subchannel(sch);
353 /* Reset device status. */
354 memset(&cdev->private->irb, 0, sizeof(struct irb));
356 cdev->private->state = state;
359 if (state == DEV_STATE_BOXED)
360 CIO_DEBUG(KERN_WARNING, 2,
361 "Boxed device %04x on subchannel %04x\n",
362 cdev->private->devno, sch->irq);
364 if (cdev->private->flags.donotify) {
365 cdev->private->flags.donotify = 0;
366 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,
368 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
370 wake_up(&cdev->private->wait_q);
372 if (css_init_done && state != DEV_STATE_ONLINE)
373 put_device (&cdev->dev);
377 * Function called from device_pgid.c after sense path ground has completed.
380 ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
382 struct subchannel *sch;
384 sch = to_subchannel(cdev->dev.parent);
387 /* Start Path Group verification. */
388 sch->vpm = 0; /* Start with no path groups set. */
389 cdev->private->state = DEV_STATE_VERIFY;
390 ccw_device_verify_start(cdev);
392 case -ETIME: /* Sense path group id stopped by timeout. */
393 case -EUSERS: /* device is reserved for someone else. */
394 ccw_device_done(cdev, DEV_STATE_BOXED);
396 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
397 cdev->private->options.pgroup = 0;
398 ccw_device_done(cdev, DEV_STATE_ONLINE);
401 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
407 * Start device recognition.
410 ccw_device_recognition(struct ccw_device *cdev)
412 struct subchannel *sch;
415 if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
416 (cdev->private->state != DEV_STATE_BOXED))
418 sch = to_subchannel(cdev->dev.parent);
419 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
421 /* Couldn't enable the subchannel for i/o. Sick device. */
424 /* After 60s the device recognition is considered to have failed. */
425 ccw_device_set_timeout(cdev, 60*HZ);
428 * We used to start here with a sense pgid to find out whether a device
429 * is locked by someone else. Unfortunately, the sense pgid command
430 * code has other meanings on devices predating the path grouping
431 * algorithm, so we start with sense id and box the device after an
432 * timeout (or if sense pgid during path verification detects the device
433 * is locked, as may happen on newer devices).
435 cdev->private->flags.recog_done = 0;
436 cdev->private->state = DEV_STATE_SENSE_ID;
437 ccw_device_sense_id_start(cdev);
442 * Handle timeout in device recognition.
445 ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
449 ret = ccw_device_cancel_halt_clear(cdev);
452 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
455 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
458 ccw_device_set_timeout(cdev, 3*HZ);
464 ccw_device_nopath_notify(void *data)
466 struct ccw_device *cdev;
467 struct subchannel *sch;
470 cdev = (struct ccw_device *)data;
471 sch = to_subchannel(cdev->dev.parent);
475 ret = (sch->driver && sch->driver->notify) ?
476 sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0;
478 if (get_device(&sch->dev)) {
479 /* Driver doesn't want to keep device. */
480 cio_disable_subchannel(sch);
481 if (get_device(&cdev->dev)) {
482 PREPARE_WORK(&cdev->private->kick_work,
483 ccw_device_call_sch_unregister,
485 queue_work(ccw_device_work,
486 &cdev->private->kick_work);
488 put_device(&sch->dev);
491 cio_disable_subchannel(sch);
492 ccw_device_set_timeout(cdev, 0);
493 cdev->private->flags.fake_irb = 0;
494 cdev->private->state = DEV_STATE_DISCONNECTED;
495 wake_up(&cdev->private->wait_q);
500 ccw_device_verify_done(struct ccw_device *cdev, int err)
502 cdev->private->flags.doverify = 0;
504 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
505 cdev->private->options.pgroup = 0;
507 ccw_device_done(cdev, DEV_STATE_ONLINE);
508 /* Deliver fake irb to device driver, if needed. */
509 if (cdev->private->flags.fake_irb) {
510 memset(&cdev->private->irb, 0, sizeof(struct irb));
511 cdev->private->irb.scsw = (struct scsw) {
513 .fctl = SCSW_FCTL_START_FUNC,
514 .actl = SCSW_ACTL_START_PEND,
515 .stctl = SCSW_STCTL_STATUS_PEND,
517 cdev->private->flags.fake_irb = 0;
519 cdev->handler(cdev, cdev->private->intparm,
520 &cdev->private->irb);
521 memset(&cdev->private->irb, 0, sizeof(struct irb));
525 ccw_device_done(cdev, DEV_STATE_BOXED);
528 PREPARE_WORK(&cdev->private->kick_work,
529 ccw_device_nopath_notify, (void *)cdev);
530 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
531 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
540 ccw_device_online(struct ccw_device *cdev)
542 struct subchannel *sch;
545 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
546 (cdev->private->state != DEV_STATE_BOXED))
548 sch = to_subchannel(cdev->dev.parent);
549 if (css_init_done && !get_device(&cdev->dev))
551 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
553 /* Couldn't enable the subchannel for i/o. Sick device. */
555 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
558 /* Do we want to do path grouping? */
559 if (!cdev->private->options.pgroup) {
560 /* No, set state online immediately. */
561 ccw_device_done(cdev, DEV_STATE_ONLINE);
564 /* Do a SensePGID first. */
565 cdev->private->state = DEV_STATE_SENSE_PGID;
566 ccw_device_sense_pgid_start(cdev);
571 ccw_device_disband_done(struct ccw_device *cdev, int err)
575 ccw_device_done(cdev, DEV_STATE_OFFLINE);
578 ccw_device_done(cdev, DEV_STATE_BOXED);
581 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
590 ccw_device_offline(struct ccw_device *cdev)
592 struct subchannel *sch;
594 sch = to_subchannel(cdev->dev.parent);
595 if (stsch(sch->irq, &sch->schib) || !sch->schib.pmcw.dnv)
597 if (cdev->private->state != DEV_STATE_ONLINE) {
598 if (sch->schib.scsw.actl != 0)
602 if (sch->schib.scsw.actl != 0)
604 /* Are we doing path grouping? */
605 if (!cdev->private->options.pgroup) {
606 /* No, set state offline immediately. */
607 ccw_device_done(cdev, DEV_STATE_OFFLINE);
610 /* Start Set Path Group commands. */
611 cdev->private->state = DEV_STATE_DISBAND_PGID;
612 ccw_device_disband_start(cdev);
617 * Handle timeout in device online/offline process.
620 ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
624 ret = ccw_device_cancel_halt_clear(cdev);
627 ccw_device_done(cdev, DEV_STATE_BOXED);
630 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
633 ccw_device_set_timeout(cdev, 3*HZ);
638 * Handle not oper event in device recognition.
641 ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
643 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
647 * Handle not operational event while offline.
650 ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
652 struct subchannel *sch;
654 cdev->private->state = DEV_STATE_NOT_OPER;
655 sch = to_subchannel(cdev->dev.parent);
656 if (get_device(&cdev->dev)) {
657 PREPARE_WORK(&cdev->private->kick_work,
658 ccw_device_call_sch_unregister, (void *)cdev);
659 queue_work(ccw_device_work, &cdev->private->kick_work);
661 wake_up(&cdev->private->wait_q);
665 * Handle not operational event while online.
668 ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
670 struct subchannel *sch;
672 sch = to_subchannel(cdev->dev.parent);
673 if (sch->driver->notify &&
674 sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
675 ccw_device_set_timeout(cdev, 0);
676 cdev->private->flags.fake_irb = 0;
677 cdev->private->state = DEV_STATE_DISCONNECTED;
678 wake_up(&cdev->private->wait_q);
681 cdev->private->state = DEV_STATE_NOT_OPER;
682 cio_disable_subchannel(sch);
683 if (sch->schib.scsw.actl != 0) {
684 // FIXME: not-oper indication to device driver ?
685 ccw_device_call_handler(cdev);
687 if (get_device(&cdev->dev)) {
688 PREPARE_WORK(&cdev->private->kick_work,
689 ccw_device_call_sch_unregister, (void *)cdev);
690 queue_work(ccw_device_work, &cdev->private->kick_work);
692 wake_up(&cdev->private->wait_q);
696 * Handle path verification event.
699 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
701 struct subchannel *sch;
703 if (!cdev->private->options.pgroup)
705 if (cdev->private->state == DEV_STATE_W4SENSE) {
706 cdev->private->flags.doverify = 1;
709 sch = to_subchannel(cdev->dev.parent);
711 * Since we might not just be coming from an interrupt from the
712 * subchannel we have to update the schib.
714 stsch(sch->irq, &sch->schib);
716 if (sch->schib.scsw.actl != 0 ||
717 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
719 * No final status yet or final status not yet delivered
720 * to the device driver. Can't do path verfication now,
721 * delay until final status was delivered.
723 cdev->private->flags.doverify = 1;
726 /* Device is idle, we can do the path verification. */
727 cdev->private->state = DEV_STATE_VERIFY;
728 ccw_device_verify_start(cdev);
732 * Got an interrupt for a normal io (state online).
735 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
739 irb = (struct irb *) __LC_IRB;
740 /* Check for unsolicited interrupt. */
741 if ((irb->scsw.stctl ==
742 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
743 && (!irb->scsw.cc)) {
744 if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
745 !irb->esw.esw0.erw.cons) {
746 /* Unit check but no sense data. Need basic sense. */
747 if (ccw_device_do_sense(cdev, irb) != 0)
748 goto call_handler_unsol;
749 memcpy(irb, &cdev->private->irb, sizeof(struct irb));
750 cdev->private->state = DEV_STATE_W4SENSE;
751 cdev->private->intparm = 0;
756 cdev->handler (cdev, 0, irb);
759 /* Accumulate status and find out if a basic sense is needed. */
760 ccw_device_accumulate_irb(cdev, irb);
761 if (cdev->private->flags.dosense) {
762 if (ccw_device_do_sense(cdev, irb) == 0) {
763 cdev->private->state = DEV_STATE_W4SENSE;
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 * Got an timeout in online state.
777 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
781 ccw_device_set_timeout(cdev, 0);
782 ret = ccw_device_cancel_halt_clear(cdev);
784 ccw_device_set_timeout(cdev, 3*HZ);
785 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
788 if (ret == -ENODEV) {
789 struct subchannel *sch;
791 sch = to_subchannel(cdev->dev.parent);
793 PREPARE_WORK(&cdev->private->kick_work,
794 ccw_device_nopath_notify, (void *)cdev);
795 queue_work(ccw_device_notify_work,
796 &cdev->private->kick_work);
798 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
799 } else if (cdev->handler)
800 cdev->handler(cdev, cdev->private->intparm,
801 ERR_PTR(-ETIMEDOUT));
805 * Got an interrupt for a basic sense.
808 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
812 irb = (struct irb *) __LC_IRB;
813 /* Check for unsolicited interrupt. */
814 if (irb->scsw.stctl ==
815 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
816 if (irb->scsw.cc == 1)
817 /* Basic sense hasn't started. Try again. */
818 ccw_device_do_sense(cdev, irb);
820 printk("Huh? %s(%s): unsolicited interrupt...\n",
821 __FUNCTION__, cdev->dev.bus_id);
823 cdev->handler (cdev, 0, irb);
827 /* Add basic sense info to irb. */
828 ccw_device_accumulate_basic_sense(cdev, irb);
829 if (cdev->private->flags.dosense) {
830 /* Another basic sense is needed. */
831 ccw_device_do_sense(cdev, irb);
834 cdev->private->state = DEV_STATE_ONLINE;
835 /* Call the handler. */
836 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
837 /* Start delayed path verification. */
838 ccw_device_online_verify(cdev, 0);
842 ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
846 irb = (struct irb *) __LC_IRB;
847 /* Accumulate status. We don't do basic sense. */
848 ccw_device_accumulate_irb(cdev, irb);
849 /* Try to start delayed device verification. */
850 ccw_device_online_verify(cdev, 0);
851 /* Note: Don't call handler for cio initiated clear! */
855 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
857 struct subchannel *sch;
859 sch = to_subchannel(cdev->dev.parent);
860 ccw_device_set_timeout(cdev, 0);
861 /* OK, i/o is dead now. Call interrupt handler. */
862 cdev->private->state = DEV_STATE_ONLINE;
864 cdev->handler(cdev, cdev->private->intparm,
865 ERR_PTR(-ETIMEDOUT));
867 PREPARE_WORK(&cdev->private->kick_work,
868 ccw_device_nopath_notify, (void *)cdev);
869 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
870 } else if (cdev->private->flags.doverify)
871 /* Start delayed path verification. */
872 ccw_device_online_verify(cdev, 0);
876 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
880 ret = ccw_device_cancel_halt_clear(cdev);
882 ccw_device_set_timeout(cdev, 3*HZ);
885 if (ret == -ENODEV) {
886 struct subchannel *sch;
888 sch = to_subchannel(cdev->dev.parent);
890 PREPARE_WORK(&cdev->private->kick_work,
891 ccw_device_nopath_notify, (void *)cdev);
892 queue_work(ccw_device_notify_work,
893 &cdev->private->kick_work);
895 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
898 //FIXME: Can we get here?
899 cdev->private->state = DEV_STATE_ONLINE;
901 cdev->handler(cdev, cdev->private->intparm,
902 ERR_PTR(-ETIMEDOUT));
906 ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
909 struct subchannel *sch;
911 irb = (struct irb *) __LC_IRB;
913 * Accumulate status and find out if a basic sense is needed.
914 * This is fine since we have already adapted the lpm.
916 ccw_device_accumulate_irb(cdev, irb);
917 if (cdev->private->flags.dosense) {
918 if (ccw_device_do_sense(cdev, irb) == 0) {
919 cdev->private->state = DEV_STATE_W4SENSE;
924 /* Iff device is idle, reset timeout. */
925 sch = to_subchannel(cdev->dev.parent);
926 if (!stsch(sch->irq, &sch->schib))
927 if (sch->schib.scsw.actl == 0)
928 ccw_device_set_timeout(cdev, 0);
929 /* Call the handler. */
930 ccw_device_call_handler(cdev);
932 PREPARE_WORK(&cdev->private->kick_work,
933 ccw_device_nopath_notify, (void *)cdev);
934 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
935 } else if (cdev->private->flags.doverify)
936 ccw_device_online_verify(cdev, 0);
940 ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
943 struct subchannel *sch;
945 sch = to_subchannel(cdev->dev.parent);
946 ccw_device_set_timeout(cdev, 0);
947 ret = ccw_device_cancel_halt_clear(cdev);
949 ccw_device_set_timeout(cdev, 3*HZ);
950 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
953 if (ret == -ENODEV) {
955 PREPARE_WORK(&cdev->private->kick_work,
956 ccw_device_nopath_notify, (void *)cdev);
957 queue_work(ccw_device_notify_work,
958 &cdev->private->kick_work);
960 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
964 cdev->handler(cdev, cdev->private->intparm,
965 ERR_PTR(-ETIMEDOUT));
967 PREPARE_WORK(&cdev->private->kick_work,
968 ccw_device_nopath_notify, (void *)cdev);
969 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
970 } else if (cdev->private->flags.doverify)
971 /* Start delayed path verification. */
972 ccw_device_online_verify(cdev, 0);
976 ccw_device_wait4io_verify(struct ccw_device *cdev, enum dev_event dev_event)
978 /* When the I/O has terminated, we have to start verification. */
979 if (cdev->private->options.pgroup)
980 cdev->private->flags.doverify = 1;
984 ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
989 case DEV_EVENT_INTERRUPT:
990 irb = (struct irb *) __LC_IRB;
991 /* Check for unsolicited interrupt. */
992 if ((irb->scsw.stctl ==
993 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
995 /* FIXME: we should restart stlck here, but this
996 * is extremely unlikely ... */
999 ccw_device_accumulate_irb(cdev, irb);
1000 /* We don't care about basic sense etc. */
1002 default: /* timeout */
1006 wake_up(&cdev->private->wait_q);
1010 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
1012 struct subchannel *sch;
1014 sch = to_subchannel(cdev->dev.parent);
1015 if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
1016 /* Couldn't enable the subchannel for i/o. Sick device. */
1019 /* After 60s the device recognition is considered to have failed. */
1020 ccw_device_set_timeout(cdev, 60*HZ);
1022 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
1023 ccw_device_sense_id_start(cdev);
1027 device_trigger_reprobe(struct subchannel *sch)
1029 struct ccw_device *cdev;
1031 if (!sch->dev.driver_data)
1033 cdev = sch->dev.driver_data;
1034 if (cdev->private->state != DEV_STATE_DISCONNECTED)
1037 /* Update some values. */
1038 if (stsch(sch->irq, &sch->schib))
1042 * The pim, pam, pom values may not be accurate, but they are the best
1043 * we have before performing device selection :/
1045 sch->lpm = sch->schib.pmcw.pim &
1046 sch->schib.pmcw.pam &
1047 sch->schib.pmcw.pom &
1049 /* Re-set some bits in the pmcw that were lost. */
1050 sch->schib.pmcw.isc = 3;
1051 sch->schib.pmcw.csense = 1;
1052 sch->schib.pmcw.ena = 0;
1053 if ((sch->lpm & (sch->lpm - 1)) != 0)
1054 sch->schib.pmcw.mp = 1;
1055 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1056 /* We should also udate ssd info, but this has to wait. */
1057 ccw_device_start_id(cdev, 0);
1061 ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1063 struct subchannel *sch;
1065 sch = to_subchannel(cdev->dev.parent);
1067 * An interrupt in state offline means a previous disable was not
1068 * successful. Try again.
1070 cio_disable_subchannel(sch);
1074 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1076 retry_set_schib(cdev);
1077 cdev->private->state = DEV_STATE_ONLINE;
1078 dev_fsm_event(cdev, dev_event);
1083 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1085 ccw_device_set_timeout(cdev, 0);
1086 if (dev_event == DEV_EVENT_NOTOPER)
1087 cdev->private->state = DEV_STATE_NOT_OPER;
1089 cdev->private->state = DEV_STATE_OFFLINE;
1090 wake_up(&cdev->private->wait_q);
1094 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1098 ret = ccw_device_cancel_halt_clear(cdev);
1101 cdev->private->state = DEV_STATE_OFFLINE;
1102 wake_up(&cdev->private->wait_q);
1105 cdev->private->state = DEV_STATE_NOT_OPER;
1106 wake_up(&cdev->private->wait_q);
1109 ccw_device_set_timeout(cdev, HZ/10);
1114 * No operation action. This is used e.g. to ignore a timeout event in
1118 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1123 * Bug operation action.
1126 ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1128 printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1129 cdev->private->state, dev_event);
1134 * device statemachine
1136 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1137 [DEV_STATE_NOT_OPER] = {
1138 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1139 [DEV_EVENT_INTERRUPT] = ccw_device_bug,
1140 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1141 [DEV_EVENT_VERIFY] = ccw_device_nop,
1143 [DEV_STATE_SENSE_PGID] = {
1144 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1145 [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
1146 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1147 [DEV_EVENT_VERIFY] = ccw_device_nop,
1149 [DEV_STATE_SENSE_ID] = {
1150 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1151 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1152 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1153 [DEV_EVENT_VERIFY] = ccw_device_nop,
1155 [DEV_STATE_OFFLINE] = {
1156 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1157 [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
1158 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1159 [DEV_EVENT_VERIFY] = ccw_device_nop,
1161 [DEV_STATE_VERIFY] = {
1162 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1163 [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
1164 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1165 [DEV_EVENT_VERIFY] = ccw_device_nop,
1167 [DEV_STATE_ONLINE] = {
1168 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1169 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1170 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1171 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1173 [DEV_STATE_W4SENSE] = {
1174 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1175 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1176 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1177 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1179 [DEV_STATE_DISBAND_PGID] = {
1180 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1181 [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
1182 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1183 [DEV_EVENT_VERIFY] = ccw_device_nop,
1185 [DEV_STATE_BOXED] = {
1186 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1187 [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
1188 [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
1189 [DEV_EVENT_VERIFY] = ccw_device_nop,
1191 /* states to wait for i/o completion before doing something */
1192 [DEV_STATE_CLEAR_VERIFY] = {
1193 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1194 [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
1195 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1196 [DEV_EVENT_VERIFY] = ccw_device_nop,
1198 [DEV_STATE_TIMEOUT_KILL] = {
1199 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1200 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1201 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1202 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1204 [DEV_STATE_WAIT4IO] = {
1205 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1206 [DEV_EVENT_INTERRUPT] = ccw_device_wait4io_irq,
1207 [DEV_EVENT_TIMEOUT] = ccw_device_wait4io_timeout,
1208 [DEV_EVENT_VERIFY] = ccw_device_wait4io_verify,
1210 [DEV_STATE_QUIESCE] = {
1211 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1212 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1213 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1214 [DEV_EVENT_VERIFY] = ccw_device_nop,
1216 /* special states for devices gone not operational */
1217 [DEV_STATE_DISCONNECTED] = {
1218 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1219 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1220 [DEV_EVENT_TIMEOUT] = ccw_device_bug,
1221 [DEV_EVENT_VERIFY] = ccw_device_nop,
1223 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1224 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1225 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1226 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1227 [DEV_EVENT_VERIFY] = ccw_device_nop,
1229 [DEV_STATE_CMFCHANGE] = {
1230 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1231 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1232 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1233 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1238 * io_subchannel_irq is called for "real" interrupts or for status
1239 * pending conditions on msch.
1242 io_subchannel_irq (struct device *pdev)
1244 struct ccw_device *cdev;
1246 cdev = to_subchannel(pdev)->dev.driver_data;
1248 CIO_TRACE_EVENT (3, "IRQ");
1249 CIO_TRACE_EVENT (3, pdev->bus_id);
1251 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1254 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);