2 * drivers/s390/cio/device_fsm.c
3 * finite state machine for device handling
5 * Copyright IBM Corp. 2002,2008
6 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/jiffies.h>
13 #include <linux/string.h>
15 #include <asm/ccwdev.h>
17 #include <asm/chpid.h>
20 #include "cio_debug.h"
27 static int timeout_log_enabled;
29 static int __init ccw_timeout_log_setup(char *unused)
31 timeout_log_enabled = 1;
35 __setup("ccw_timeout_log", ccw_timeout_log_setup);
37 static void ccw_timeout_log(struct ccw_device *cdev)
40 struct subchannel *sch;
41 struct io_subchannel_private *private;
45 sch = to_subchannel(cdev->dev.parent);
46 private = to_io_private(sch);
48 cc = stsch_err(sch->schid, &schib);
50 printk(KERN_WARNING "cio: ccw device timeout occurred at %llx, "
51 "device information:\n", get_clock());
52 printk(KERN_WARNING "cio: orb:\n");
53 print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
54 orb, sizeof(*orb), 0);
55 printk(KERN_WARNING "cio: ccw device bus id: %s\n",
56 dev_name(&cdev->dev));
57 printk(KERN_WARNING "cio: subchannel bus id: %s\n",
59 printk(KERN_WARNING "cio: subchannel lpm: %02x, opm: %02x, "
60 "vpm: %02x\n", sch->lpm, sch->opm, sch->vpm);
63 printk(KERN_WARNING "cio: orb indicates transport mode\n");
64 printk(KERN_WARNING "cio: last tcw:\n");
65 print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
66 (void *)(addr_t)orb->tm.tcw,
67 sizeof(struct tcw), 0);
69 printk(KERN_WARNING "cio: orb indicates command mode\n");
70 if ((void *)(addr_t)orb->cmd.cpa == &private->sense_ccw ||
71 (void *)(addr_t)orb->cmd.cpa == cdev->private->iccws)
72 printk(KERN_WARNING "cio: last channel program "
75 printk(KERN_WARNING "cio: last channel program:\n");
77 print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
78 (void *)(addr_t)orb->cmd.cpa,
79 sizeof(struct ccw1), 0);
81 printk(KERN_WARNING "cio: ccw device state: %d\n",
82 cdev->private->state);
83 printk(KERN_WARNING "cio: store subchannel returned: cc=%d\n", cc);
84 printk(KERN_WARNING "cio: schib:\n");
85 print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
86 &schib, sizeof(schib), 0);
87 printk(KERN_WARNING "cio: ccw device flags:\n");
88 print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1,
89 &cdev->private->flags, sizeof(cdev->private->flags), 0);
93 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
96 ccw_device_timeout(unsigned long data)
98 struct ccw_device *cdev;
100 cdev = (struct ccw_device *) data;
101 spin_lock_irq(cdev->ccwlock);
102 if (timeout_log_enabled)
103 ccw_timeout_log(cdev);
104 dev_fsm_event(cdev, DEV_EVENT_TIMEOUT);
105 spin_unlock_irq(cdev->ccwlock);
112 ccw_device_set_timeout(struct ccw_device *cdev, int expires)
115 del_timer(&cdev->private->timer);
118 if (timer_pending(&cdev->private->timer)) {
119 if (mod_timer(&cdev->private->timer, jiffies + expires))
122 cdev->private->timer.function = ccw_device_timeout;
123 cdev->private->timer.data = (unsigned long) cdev;
124 cdev->private->timer.expires = jiffies + expires;
125 add_timer(&cdev->private->timer);
129 * Cancel running i/o. This is called repeatedly since halt/clear are
130 * asynchronous operations. We do one try with cio_cancel, two tries
131 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
132 * Returns 0 if device now idle, -ENODEV for device not operational and
133 * -EBUSY if an interrupt is expected (either from halt/clear or from a
137 ccw_device_cancel_halt_clear(struct ccw_device *cdev)
139 struct subchannel *sch;
142 sch = to_subchannel(cdev->dev.parent);
143 if (cio_update_schib(sch))
145 if (!sch->schib.pmcw.ena)
146 /* Not operational -> done. */
148 /* Stage 1: cancel io. */
149 if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_HALT_PEND) &&
150 !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
151 if (!scsw_is_tm(&sch->schib.scsw)) {
152 ret = cio_cancel(sch);
156 /* cancel io unsuccessful or not applicable (transport mode).
157 * Continue with asynchronous instructions. */
158 cdev->private->iretry = 3; /* 3 halt retries. */
160 if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
161 /* Stage 2: halt io. */
162 if (cdev->private->iretry) {
163 cdev->private->iretry--;
166 return (ret == 0) ? -EBUSY : ret;
168 /* halt io unsuccessful. */
169 cdev->private->iretry = 255; /* 255 clear retries. */
171 /* Stage 3: clear io. */
172 if (cdev->private->iretry) {
173 cdev->private->iretry--;
174 ret = cio_clear (sch);
175 return (ret == 0) ? -EBUSY : ret;
177 panic("Can't stop i/o on subchannel.\n");
180 void ccw_device_update_sense_data(struct ccw_device *cdev)
182 memset(&cdev->id, 0, sizeof(cdev->id));
183 cdev->id.cu_type = cdev->private->senseid.cu_type;
184 cdev->id.cu_model = cdev->private->senseid.cu_model;
185 cdev->id.dev_type = cdev->private->senseid.dev_type;
186 cdev->id.dev_model = cdev->private->senseid.dev_model;
189 int ccw_device_test_sense_data(struct ccw_device *cdev)
191 return cdev->id.cu_type == cdev->private->senseid.cu_type &&
192 cdev->id.cu_model == cdev->private->senseid.cu_model &&
193 cdev->id.dev_type == cdev->private->senseid.dev_type &&
194 cdev->id.dev_model == cdev->private->senseid.dev_model;
198 * The machine won't give us any notification by machine check if a chpid has
199 * been varied online on the SE so we have to find out by magic (i. e. driving
200 * the channel subsystem to device selection and updating our path masks).
203 __recover_lost_chpids(struct subchannel *sch, int old_lpm)
209 for (i = 0; i<8; i++) {
211 if (!(sch->lpm & mask))
215 chpid.id = sch->schib.pmcw.chpid[i];
216 if (!chp_is_registered(chpid))
217 css_schedule_eval_all();
222 * Stop device recognition.
225 ccw_device_recog_done(struct ccw_device *cdev, int state)
227 struct subchannel *sch;
230 sch = to_subchannel(cdev->dev.parent);
232 if (cio_disable_subchannel(sch))
233 state = DEV_STATE_NOT_OPER;
235 * Now that we tried recognition, we have performed device selection
236 * through ssch() and the path information is up to date.
240 /* Check since device may again have become not operational. */
241 if (cio_update_schib(sch))
242 state = DEV_STATE_NOT_OPER;
244 sch->lpm = sch->schib.pmcw.pam & sch->opm;
246 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
247 /* Force reprobe on all chpids. */
249 if (sch->lpm != old_lpm)
250 __recover_lost_chpids(sch, old_lpm);
251 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID &&
252 (state == DEV_STATE_NOT_OPER || state == DEV_STATE_BOXED)) {
253 cdev->private->flags.recog_done = 1;
254 cdev->private->state = DEV_STATE_DISCONNECTED;
255 wake_up(&cdev->private->wait_q);
258 if (cdev->private->flags.resuming) {
259 cdev->private->state = state;
260 cdev->private->flags.recog_done = 1;
261 wake_up(&cdev->private->wait_q);
265 case DEV_STATE_NOT_OPER:
267 case DEV_STATE_OFFLINE:
269 ccw_device_update_sense_data(cdev);
272 cdev->private->state = DEV_STATE_OFFLINE;
273 cdev->private->flags.recog_done = 1;
274 if (ccw_device_test_sense_data(cdev)) {
275 cdev->private->flags.donotify = 1;
276 ccw_device_online(cdev);
277 wake_up(&cdev->private->wait_q);
279 ccw_device_update_sense_data(cdev);
280 ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
283 case DEV_STATE_BOXED:
284 if (cdev->id.cu_type != 0) { /* device was recognized before */
285 cdev->private->flags.recog_done = 1;
286 cdev->private->state = DEV_STATE_BOXED;
287 wake_up(&cdev->private->wait_q);
292 cdev->private->state = state;
293 io_subchannel_recog_done(cdev);
294 wake_up(&cdev->private->wait_q);
298 * Function called from device_id.c after sense id has completed.
301 ccw_device_sense_id_done(struct ccw_device *cdev, int err)
305 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
307 case -ETIME: /* Sense id stopped by timeout. */
308 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
311 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
317 * ccw_device_notify() - inform the device's driver about an event
318 * @cdev: device for which an event occured
319 * @event: event that occurred
322 * -%EINVAL if the device is offline or has no driver.
323 * -%EOPNOTSUPP if the device's driver has no notifier registered.
324 * %NOTIFY_OK if the driver wants to keep the device.
325 * %NOTIFY_BAD if the driver doesn't want to keep the device.
327 int ccw_device_notify(struct ccw_device *cdev, int event)
335 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
336 cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
338 if (!cdev->drv->notify) {
342 if (cdev->drv->notify(cdev, event))
350 static void ccw_device_oper_notify(struct ccw_device *cdev)
352 struct subchannel *sch = to_subchannel(cdev->dev.parent);
354 if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_OK) {
355 /* Reenable channel measurements, if needed. */
356 ccw_device_sched_todo(cdev, CDEV_TODO_ENABLE_CMF);
357 /* Save indication for new paths. */
358 cdev->private->path_new_mask = sch->vpm;
361 /* Driver doesn't want device back. */
362 ccw_device_set_notoper(cdev);
363 ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
367 * Finished with online/offline processing.
370 ccw_device_done(struct ccw_device *cdev, int state)
372 struct subchannel *sch;
374 sch = to_subchannel(cdev->dev.parent);
376 ccw_device_set_timeout(cdev, 0);
378 if (state != DEV_STATE_ONLINE)
379 cio_disable_subchannel(sch);
381 /* Reset device status. */
382 memset(&cdev->private->irb, 0, sizeof(struct irb));
384 cdev->private->state = state;
387 case DEV_STATE_BOXED:
388 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
389 cdev->private->dev_id.devno, sch->schid.sch_no);
391 ccw_device_notify(cdev, CIO_BOXED) != NOTIFY_OK)
392 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
393 cdev->private->flags.donotify = 0;
395 case DEV_STATE_NOT_OPER:
396 CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n",
397 cdev->private->dev_id.devno, sch->schid.sch_no);
398 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
399 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
401 ccw_device_set_disconnected(cdev);
402 cdev->private->flags.donotify = 0;
404 case DEV_STATE_DISCONNECTED:
405 CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel "
406 "%04x\n", cdev->private->dev_id.devno,
408 if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK)
409 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
411 ccw_device_set_disconnected(cdev);
412 cdev->private->flags.donotify = 0;
418 if (cdev->private->flags.donotify) {
419 cdev->private->flags.donotify = 0;
420 ccw_device_oper_notify(cdev);
422 wake_up(&cdev->private->wait_q);
426 * Start device recognition.
428 void ccw_device_recognition(struct ccw_device *cdev)
430 struct subchannel *sch = to_subchannel(cdev->dev.parent);
433 * We used to start here with a sense pgid to find out whether a device
434 * is locked by someone else. Unfortunately, the sense pgid command
435 * code has other meanings on devices predating the path grouping
436 * algorithm, so we start with sense id and box the device after an
437 * timeout (or if sense pgid during path verification detects the device
438 * is locked, as may happen on newer devices).
440 cdev->private->flags.recog_done = 0;
441 cdev->private->state = DEV_STATE_SENSE_ID;
442 if (cio_enable_subchannel(sch, (u32) (addr_t) sch)) {
443 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
446 ccw_device_sense_id_start(cdev);
450 * Handle events for states that use the ccw request infrastructure.
452 static void ccw_device_request_event(struct ccw_device *cdev, enum dev_event e)
455 case DEV_EVENT_NOTOPER:
456 ccw_request_notoper(cdev);
458 case DEV_EVENT_INTERRUPT:
459 ccw_request_handler(cdev);
461 case DEV_EVENT_TIMEOUT:
462 ccw_request_timeout(cdev);
469 static void ccw_device_report_path_events(struct ccw_device *cdev)
471 struct subchannel *sch = to_subchannel(cdev->dev.parent);
475 for (chp = 0, mask = 0x80; chp < 8; chp++, mask >>= 1) {
476 path_event[chp] = PE_NONE;
477 if (mask & cdev->private->path_gone_mask & ~(sch->vpm))
478 path_event[chp] |= PE_PATH_GONE;
479 if (mask & cdev->private->path_new_mask & sch->vpm)
480 path_event[chp] |= PE_PATH_AVAILABLE;
481 if (mask & cdev->private->pgid_reset_mask & sch->vpm)
482 path_event[chp] |= PE_PATHGROUP_ESTABLISHED;
484 if (cdev->online && cdev->drv->path_event)
485 cdev->drv->path_event(cdev, path_event);
488 static void ccw_device_reset_path_events(struct ccw_device *cdev)
490 cdev->private->path_gone_mask = 0;
491 cdev->private->path_new_mask = 0;
492 cdev->private->pgid_reset_mask = 0;
496 ccw_device_verify_done(struct ccw_device *cdev, int err)
498 struct subchannel *sch;
500 sch = to_subchannel(cdev->dev.parent);
501 /* Update schib - pom may have changed. */
502 if (cio_update_schib(sch)) {
506 /* Update lpm with verified path mask. */
508 /* Repeat path verification? */
509 if (cdev->private->flags.doverify) {
510 ccw_device_verify_start(cdev);
516 ccw_device_done(cdev, DEV_STATE_ONLINE);
517 /* Deliver fake irb to device driver, if needed. */
518 if (cdev->private->flags.fake_irb) {
519 memset(&cdev->private->irb, 0, sizeof(struct irb));
520 cdev->private->irb.scsw.cmd.cc = 1;
521 cdev->private->irb.scsw.cmd.fctl = SCSW_FCTL_START_FUNC;
522 cdev->private->irb.scsw.cmd.actl = SCSW_ACTL_START_PEND;
523 cdev->private->irb.scsw.cmd.stctl =
524 SCSW_STCTL_STATUS_PEND;
525 cdev->private->flags.fake_irb = 0;
527 cdev->handler(cdev, cdev->private->intparm,
528 &cdev->private->irb);
529 memset(&cdev->private->irb, 0, sizeof(struct irb));
531 ccw_device_report_path_events(cdev);
535 /* Reset oper notify indication after verify error. */
536 cdev->private->flags.donotify = 0;
537 ccw_device_done(cdev, DEV_STATE_BOXED);
540 /* Reset oper notify indication after verify error. */
541 cdev->private->flags.donotify = 0;
542 ccw_device_done(cdev, DEV_STATE_DISCONNECTED);
545 /* Reset oper notify indication after verify error. */
546 cdev->private->flags.donotify = 0;
547 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
550 ccw_device_reset_path_events(cdev);
557 ccw_device_online(struct ccw_device *cdev)
559 struct subchannel *sch;
562 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
563 (cdev->private->state != DEV_STATE_BOXED))
565 sch = to_subchannel(cdev->dev.parent);
566 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
568 /* Couldn't enable the subchannel for i/o. Sick device. */
570 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
573 /* Start initial path verification. */
574 cdev->private->state = DEV_STATE_VERIFY;
575 ccw_device_verify_start(cdev);
580 ccw_device_disband_done(struct ccw_device *cdev, int err)
584 ccw_device_done(cdev, DEV_STATE_OFFLINE);
587 ccw_device_done(cdev, DEV_STATE_BOXED);
590 cdev->private->flags.donotify = 0;
591 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
600 ccw_device_offline(struct ccw_device *cdev)
602 struct subchannel *sch;
604 /* Allow ccw_device_offline while disconnected. */
605 if (cdev->private->state == DEV_STATE_DISCONNECTED ||
606 cdev->private->state == DEV_STATE_NOT_OPER) {
607 cdev->private->flags.donotify = 0;
608 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
611 if (cdev->private->state == DEV_STATE_BOXED) {
612 ccw_device_done(cdev, DEV_STATE_BOXED);
615 if (ccw_device_is_orphan(cdev)) {
616 ccw_device_done(cdev, DEV_STATE_OFFLINE);
619 sch = to_subchannel(cdev->dev.parent);
620 if (cio_update_schib(sch))
622 if (scsw_actl(&sch->schib.scsw) != 0)
624 if (cdev->private->state != DEV_STATE_ONLINE)
626 /* Are we doing path grouping? */
627 if (!cdev->private->flags.pgroup) {
628 /* No, set state offline immediately. */
629 ccw_device_done(cdev, DEV_STATE_OFFLINE);
632 /* Start Set Path Group commands. */
633 cdev->private->state = DEV_STATE_DISBAND_PGID;
634 ccw_device_disband_start(cdev);
639 * Handle not operational event in non-special state.
641 static void ccw_device_generic_notoper(struct ccw_device *cdev,
642 enum dev_event dev_event)
644 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
645 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
647 ccw_device_set_disconnected(cdev);
651 * Handle path verification event in offline state.
653 static void ccw_device_offline_verify(struct ccw_device *cdev,
654 enum dev_event dev_event)
656 struct subchannel *sch = to_subchannel(cdev->dev.parent);
658 css_schedule_eval(sch->schid);
662 * Handle path verification event.
665 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
667 struct subchannel *sch;
669 if (cdev->private->state == DEV_STATE_W4SENSE) {
670 cdev->private->flags.doverify = 1;
673 sch = to_subchannel(cdev->dev.parent);
675 * Since we might not just be coming from an interrupt from the
676 * subchannel we have to update the schib.
678 if (cio_update_schib(sch)) {
679 ccw_device_verify_done(cdev, -ENODEV);
683 if (scsw_actl(&sch->schib.scsw) != 0 ||
684 (scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_STATUS_PEND) ||
685 (scsw_stctl(&cdev->private->irb.scsw) & SCSW_STCTL_STATUS_PEND)) {
687 * No final status yet or final status not yet delivered
688 * to the device driver. Can't do path verfication now,
689 * delay until final status was delivered.
691 cdev->private->flags.doverify = 1;
694 /* Device is idle, we can do the path verification. */
695 cdev->private->state = DEV_STATE_VERIFY;
696 ccw_device_verify_start(cdev);
700 * Handle path verification event in boxed state.
702 static void ccw_device_boxed_verify(struct ccw_device *cdev,
703 enum dev_event dev_event)
705 struct subchannel *sch = to_subchannel(cdev->dev.parent);
708 if (cio_enable_subchannel(sch, (u32) (addr_t) sch))
709 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
711 ccw_device_online_verify(cdev, dev_event);
713 css_schedule_eval(sch->schid);
717 * Got an interrupt for a normal io (state online).
720 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
725 irb = (struct irb *)&S390_lowcore.irb;
726 is_cmd = !scsw_is_tm(&irb->scsw);
727 /* Check for unsolicited interrupt. */
728 if (!scsw_is_solicited(&irb->scsw)) {
729 if (is_cmd && (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
730 !irb->esw.esw0.erw.cons) {
731 /* Unit check but no sense data. Need basic sense. */
732 if (ccw_device_do_sense(cdev, irb) != 0)
733 goto call_handler_unsol;
734 memcpy(&cdev->private->irb, irb, sizeof(struct irb));
735 cdev->private->state = DEV_STATE_W4SENSE;
736 cdev->private->intparm = 0;
741 cdev->handler (cdev, 0, irb);
742 if (cdev->private->flags.doverify)
743 ccw_device_online_verify(cdev, 0);
746 /* Accumulate status and find out if a basic sense is needed. */
747 ccw_device_accumulate_irb(cdev, irb);
748 if (is_cmd && cdev->private->flags.dosense) {
749 if (ccw_device_do_sense(cdev, irb) == 0) {
750 cdev->private->state = DEV_STATE_W4SENSE;
754 /* Call the handler. */
755 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
756 /* Start delayed path verification. */
757 ccw_device_online_verify(cdev, 0);
761 * Got an timeout in online state.
764 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
768 ccw_device_set_timeout(cdev, 0);
769 ret = ccw_device_cancel_halt_clear(cdev);
771 ccw_device_set_timeout(cdev, 3*HZ);
772 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
776 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
777 else if (cdev->handler)
778 cdev->handler(cdev, cdev->private->intparm,
779 ERR_PTR(-ETIMEDOUT));
783 * Got an interrupt for a basic sense.
786 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
790 irb = (struct irb *)&S390_lowcore.irb;
791 /* Check for unsolicited interrupt. */
792 if (scsw_stctl(&irb->scsw) ==
793 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
794 if (scsw_cc(&irb->scsw) == 1)
795 /* Basic sense hasn't started. Try again. */
796 ccw_device_do_sense(cdev, irb);
798 CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
799 "interrupt during w4sense...\n",
800 cdev->private->dev_id.ssid,
801 cdev->private->dev_id.devno);
803 cdev->handler (cdev, 0, irb);
808 * Check if a halt or clear has been issued in the meanwhile. If yes,
809 * only deliver the halt/clear interrupt to the device driver as if it
810 * had killed the original request.
812 if (scsw_fctl(&irb->scsw) &
813 (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
814 cdev->private->flags.dosense = 0;
815 memset(&cdev->private->irb, 0, sizeof(struct irb));
816 ccw_device_accumulate_irb(cdev, irb);
819 /* Add basic sense info to irb. */
820 ccw_device_accumulate_basic_sense(cdev, irb);
821 if (cdev->private->flags.dosense) {
822 /* Another basic sense is needed. */
823 ccw_device_do_sense(cdev, irb);
827 cdev->private->state = DEV_STATE_ONLINE;
828 /* In case sensing interfered with setting the device online */
829 wake_up(&cdev->private->wait_q);
830 /* Call the handler. */
831 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
832 /* Start delayed path verification. */
833 ccw_device_online_verify(cdev, 0);
837 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
839 struct subchannel *sch;
841 sch = to_subchannel(cdev->dev.parent);
842 ccw_device_set_timeout(cdev, 0);
843 /* Start delayed path verification. */
844 ccw_device_online_verify(cdev, 0);
845 /* OK, i/o is dead now. Call interrupt handler. */
847 cdev->handler(cdev, cdev->private->intparm,
852 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
856 ret = ccw_device_cancel_halt_clear(cdev);
858 ccw_device_set_timeout(cdev, 3*HZ);
861 /* Start delayed path verification. */
862 ccw_device_online_verify(cdev, 0);
864 cdev->handler(cdev, cdev->private->intparm,
868 void ccw_device_kill_io(struct ccw_device *cdev)
872 ret = ccw_device_cancel_halt_clear(cdev);
874 ccw_device_set_timeout(cdev, 3*HZ);
875 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
878 /* Start delayed path verification. */
879 ccw_device_online_verify(cdev, 0);
881 cdev->handler(cdev, cdev->private->intparm,
886 ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
888 /* Start verification after current task finished. */
889 cdev->private->flags.doverify = 1;
893 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
895 struct subchannel *sch;
897 sch = to_subchannel(cdev->dev.parent);
898 if (cio_enable_subchannel(sch, (u32)(addr_t)sch) != 0)
899 /* Couldn't enable the subchannel for i/o. Sick device. */
901 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
902 ccw_device_sense_id_start(cdev);
905 void ccw_device_trigger_reprobe(struct ccw_device *cdev)
907 struct subchannel *sch;
909 if (cdev->private->state != DEV_STATE_DISCONNECTED)
912 sch = to_subchannel(cdev->dev.parent);
913 /* Update some values. */
914 if (cio_update_schib(sch))
917 * The pim, pam, pom values may not be accurate, but they are the best
918 * we have before performing device selection :/
920 sch->lpm = sch->schib.pmcw.pam & sch->opm;
922 * Use the initial configuration since we can't be shure that the old
925 io_subchannel_init_config(sch);
926 if (cio_commit_config(sch))
929 /* We should also udate ssd info, but this has to wait. */
930 /* Check if this is another device which appeared on the same sch. */
931 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno)
932 css_schedule_eval(sch->schid);
934 ccw_device_start_id(cdev, 0);
937 static void ccw_device_disabled_irq(struct ccw_device *cdev,
938 enum dev_event dev_event)
940 struct subchannel *sch;
942 sch = to_subchannel(cdev->dev.parent);
944 * An interrupt in a disabled state means a previous disable was not
945 * successful - should not happen, but we try to disable again.
947 cio_disable_subchannel(sch);
951 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
953 retry_set_schib(cdev);
954 cdev->private->state = DEV_STATE_ONLINE;
955 dev_fsm_event(cdev, dev_event);
958 static void ccw_device_update_cmfblock(struct ccw_device *cdev,
959 enum dev_event dev_event)
961 cmf_retry_copy_block(cdev);
962 cdev->private->state = DEV_STATE_ONLINE;
963 dev_fsm_event(cdev, dev_event);
967 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
969 ccw_device_set_timeout(cdev, 0);
970 cdev->private->state = DEV_STATE_NOT_OPER;
971 wake_up(&cdev->private->wait_q);
975 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
979 ret = ccw_device_cancel_halt_clear(cdev);
981 ccw_device_set_timeout(cdev, HZ/10);
983 cdev->private->state = DEV_STATE_NOT_OPER;
984 wake_up(&cdev->private->wait_q);
989 * No operation action. This is used e.g. to ignore a timeout event in
993 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
998 * device statemachine
1000 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1001 [DEV_STATE_NOT_OPER] = {
1002 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1003 [DEV_EVENT_INTERRUPT] = ccw_device_disabled_irq,
1004 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1005 [DEV_EVENT_VERIFY] = ccw_device_nop,
1007 [DEV_STATE_SENSE_PGID] = {
1008 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1009 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1010 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1011 [DEV_EVENT_VERIFY] = ccw_device_nop,
1013 [DEV_STATE_SENSE_ID] = {
1014 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1015 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1016 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1017 [DEV_EVENT_VERIFY] = ccw_device_nop,
1019 [DEV_STATE_OFFLINE] = {
1020 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1021 [DEV_EVENT_INTERRUPT] = ccw_device_disabled_irq,
1022 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1023 [DEV_EVENT_VERIFY] = ccw_device_offline_verify,
1025 [DEV_STATE_VERIFY] = {
1026 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1027 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1028 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1029 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
1031 [DEV_STATE_ONLINE] = {
1032 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1033 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1034 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1035 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1037 [DEV_STATE_W4SENSE] = {
1038 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1039 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1040 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1041 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1043 [DEV_STATE_DISBAND_PGID] = {
1044 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1045 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1046 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1047 [DEV_EVENT_VERIFY] = ccw_device_nop,
1049 [DEV_STATE_BOXED] = {
1050 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1051 [DEV_EVENT_INTERRUPT] = ccw_device_nop,
1052 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1053 [DEV_EVENT_VERIFY] = ccw_device_boxed_verify,
1055 /* states to wait for i/o completion before doing something */
1056 [DEV_STATE_TIMEOUT_KILL] = {
1057 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1058 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1059 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1060 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1062 [DEV_STATE_QUIESCE] = {
1063 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1064 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1065 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1066 [DEV_EVENT_VERIFY] = ccw_device_nop,
1068 /* special states for devices gone not operational */
1069 [DEV_STATE_DISCONNECTED] = {
1070 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1071 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1072 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1073 [DEV_EVENT_VERIFY] = ccw_device_start_id,
1075 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1076 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1077 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1078 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1079 [DEV_EVENT_VERIFY] = ccw_device_nop,
1081 [DEV_STATE_CMFCHANGE] = {
1082 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1083 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1084 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1085 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1087 [DEV_STATE_CMFUPDATE] = {
1088 [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
1089 [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
1090 [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
1091 [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
1093 [DEV_STATE_STEAL_LOCK] = {
1094 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1095 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1096 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1097 [DEV_EVENT_VERIFY] = ccw_device_nop,
1101 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);