1 // SPDX-License-Identifier: GPL-2.0
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(sch->schid, &schib);
50 printk(KERN_WARNING "cio: ccw device timeout occurred at %llx, "
51 "device information:\n", get_tod_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(struct timer_list *t)
98 struct ccw_device_private *priv = from_timer(priv, t, timer);
99 struct ccw_device *cdev = priv->cdev;
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.expires = jiffies + expires;
123 add_timer(&cdev->private->timer);
127 ccw_device_cancel_halt_clear(struct ccw_device *cdev)
129 struct subchannel *sch;
132 sch = to_subchannel(cdev->dev.parent);
133 ret = cio_cancel_halt_clear(sch, &cdev->private->iretry);
136 CIO_MSG_EVENT(0, "0.%x.%04x: could not stop I/O\n",
137 cdev->private->dev_id.ssid,
138 cdev->private->dev_id.devno);
143 void ccw_device_update_sense_data(struct ccw_device *cdev)
145 memset(&cdev->id, 0, sizeof(cdev->id));
146 cdev->id.cu_type = cdev->private->senseid.cu_type;
147 cdev->id.cu_model = cdev->private->senseid.cu_model;
148 cdev->id.dev_type = cdev->private->senseid.dev_type;
149 cdev->id.dev_model = cdev->private->senseid.dev_model;
152 int ccw_device_test_sense_data(struct ccw_device *cdev)
154 return cdev->id.cu_type == cdev->private->senseid.cu_type &&
155 cdev->id.cu_model == cdev->private->senseid.cu_model &&
156 cdev->id.dev_type == cdev->private->senseid.dev_type &&
157 cdev->id.dev_model == cdev->private->senseid.dev_model;
161 * The machine won't give us any notification by machine check if a chpid has
162 * been varied online on the SE so we have to find out by magic (i. e. driving
163 * the channel subsystem to device selection and updating our path masks).
166 __recover_lost_chpids(struct subchannel *sch, int old_lpm)
172 for (i = 0; i<8; i++) {
174 if (!(sch->lpm & mask))
178 chpid.id = sch->schib.pmcw.chpid[i];
179 if (!chp_is_registered(chpid))
180 css_schedule_eval_all();
185 * Stop device recognition.
188 ccw_device_recog_done(struct ccw_device *cdev, int state)
190 struct subchannel *sch;
193 sch = to_subchannel(cdev->dev.parent);
195 if (cio_disable_subchannel(sch))
196 state = DEV_STATE_NOT_OPER;
198 * Now that we tried recognition, we have performed device selection
199 * through ssch() and the path information is up to date.
203 /* Check since device may again have become not operational. */
204 if (cio_update_schib(sch))
205 state = DEV_STATE_NOT_OPER;
207 sch->lpm = sch->schib.pmcw.pam & sch->opm;
209 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
210 /* Force reprobe on all chpids. */
212 if (sch->lpm != old_lpm)
213 __recover_lost_chpids(sch, old_lpm);
214 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID &&
215 (state == DEV_STATE_NOT_OPER || state == DEV_STATE_BOXED)) {
216 cdev->private->flags.recog_done = 1;
217 cdev->private->state = DEV_STATE_DISCONNECTED;
218 wake_up(&cdev->private->wait_q);
221 if (cdev->private->flags.resuming) {
222 cdev->private->state = state;
223 cdev->private->flags.recog_done = 1;
224 wake_up(&cdev->private->wait_q);
228 case DEV_STATE_NOT_OPER:
230 case DEV_STATE_OFFLINE:
232 ccw_device_update_sense_data(cdev);
235 cdev->private->state = DEV_STATE_OFFLINE;
236 cdev->private->flags.recog_done = 1;
237 if (ccw_device_test_sense_data(cdev)) {
238 cdev->private->flags.donotify = 1;
239 ccw_device_online(cdev);
240 wake_up(&cdev->private->wait_q);
242 ccw_device_update_sense_data(cdev);
243 ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
246 case DEV_STATE_BOXED:
247 if (cdev->id.cu_type != 0) { /* device was recognized before */
248 cdev->private->flags.recog_done = 1;
249 cdev->private->state = DEV_STATE_BOXED;
250 wake_up(&cdev->private->wait_q);
255 cdev->private->state = state;
256 io_subchannel_recog_done(cdev);
257 wake_up(&cdev->private->wait_q);
261 * Function called from device_id.c after sense id has completed.
264 ccw_device_sense_id_done(struct ccw_device *cdev, int err)
268 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
270 case -ETIME: /* Sense id stopped by timeout. */
271 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
274 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
280 * ccw_device_notify() - inform the device's driver about an event
281 * @cdev: device for which an event occurred
282 * @event: event that occurred
285 * -%EINVAL if the device is offline or has no driver.
286 * -%EOPNOTSUPP if the device's driver has no notifier registered.
287 * %NOTIFY_OK if the driver wants to keep the device.
288 * %NOTIFY_BAD if the driver doesn't want to keep the device.
290 int ccw_device_notify(struct ccw_device *cdev, int event)
298 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
299 cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
301 if (!cdev->drv->notify) {
305 if (cdev->drv->notify(cdev, event))
313 static void ccw_device_oper_notify(struct ccw_device *cdev)
315 struct subchannel *sch = to_subchannel(cdev->dev.parent);
317 if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_OK) {
318 /* Reenable channel measurements, if needed. */
319 ccw_device_sched_todo(cdev, CDEV_TODO_ENABLE_CMF);
320 /* Save indication for new paths. */
321 cdev->private->path_new_mask = sch->vpm;
324 /* Driver doesn't want device back. */
325 ccw_device_set_notoper(cdev);
326 ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
330 * Finished with online/offline processing.
333 ccw_device_done(struct ccw_device *cdev, int state)
335 struct subchannel *sch;
337 sch = to_subchannel(cdev->dev.parent);
339 ccw_device_set_timeout(cdev, 0);
341 if (state != DEV_STATE_ONLINE)
342 cio_disable_subchannel(sch);
344 /* Reset device status. */
345 memset(&cdev->private->irb, 0, sizeof(struct irb));
347 cdev->private->state = state;
350 case DEV_STATE_BOXED:
351 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
352 cdev->private->dev_id.devno, sch->schid.sch_no);
354 ccw_device_notify(cdev, CIO_BOXED) != NOTIFY_OK)
355 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
356 cdev->private->flags.donotify = 0;
358 case DEV_STATE_NOT_OPER:
359 CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n",
360 cdev->private->dev_id.devno, sch->schid.sch_no);
361 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
362 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
364 ccw_device_set_disconnected(cdev);
365 cdev->private->flags.donotify = 0;
367 case DEV_STATE_DISCONNECTED:
368 CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel "
369 "%04x\n", cdev->private->dev_id.devno,
371 if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK) {
372 cdev->private->state = DEV_STATE_NOT_OPER;
373 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
375 ccw_device_set_disconnected(cdev);
376 cdev->private->flags.donotify = 0;
382 if (cdev->private->flags.donotify) {
383 cdev->private->flags.donotify = 0;
384 ccw_device_oper_notify(cdev);
386 wake_up(&cdev->private->wait_q);
390 * Start device recognition.
392 void ccw_device_recognition(struct ccw_device *cdev)
394 struct subchannel *sch = to_subchannel(cdev->dev.parent);
397 * We used to start here with a sense pgid to find out whether a device
398 * is locked by someone else. Unfortunately, the sense pgid command
399 * code has other meanings on devices predating the path grouping
400 * algorithm, so we start with sense id and box the device after an
401 * timeout (or if sense pgid during path verification detects the device
402 * is locked, as may happen on newer devices).
404 cdev->private->flags.recog_done = 0;
405 cdev->private->state = DEV_STATE_SENSE_ID;
406 if (cio_enable_subchannel(sch, (u32) (addr_t) sch)) {
407 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
410 ccw_device_sense_id_start(cdev);
414 * Handle events for states that use the ccw request infrastructure.
416 static void ccw_device_request_event(struct ccw_device *cdev, enum dev_event e)
419 case DEV_EVENT_NOTOPER:
420 ccw_request_notoper(cdev);
422 case DEV_EVENT_INTERRUPT:
423 ccw_request_handler(cdev);
425 case DEV_EVENT_TIMEOUT:
426 ccw_request_timeout(cdev);
433 static void ccw_device_report_path_events(struct ccw_device *cdev)
435 struct subchannel *sch = to_subchannel(cdev->dev.parent);
439 for (chp = 0, mask = 0x80; chp < 8; chp++, mask >>= 1) {
440 path_event[chp] = PE_NONE;
441 if (mask & cdev->private->path_gone_mask & ~(sch->vpm))
442 path_event[chp] |= PE_PATH_GONE;
443 if (mask & cdev->private->path_new_mask & sch->vpm)
444 path_event[chp] |= PE_PATH_AVAILABLE;
445 if (mask & cdev->private->pgid_reset_mask & sch->vpm)
446 path_event[chp] |= PE_PATHGROUP_ESTABLISHED;
448 if (cdev->online && cdev->drv->path_event)
449 cdev->drv->path_event(cdev, path_event);
452 static void ccw_device_reset_path_events(struct ccw_device *cdev)
454 cdev->private->path_gone_mask = 0;
455 cdev->private->path_new_mask = 0;
456 cdev->private->pgid_reset_mask = 0;
459 static void create_fake_irb(struct irb *irb, int type)
461 memset(irb, 0, sizeof(*irb));
462 if (type == FAKE_CMD_IRB) {
463 struct cmd_scsw *scsw = &irb->scsw.cmd;
465 scsw->fctl = SCSW_FCTL_START_FUNC;
466 scsw->actl = SCSW_ACTL_START_PEND;
467 scsw->stctl = SCSW_STCTL_STATUS_PEND;
468 } else if (type == FAKE_TM_IRB) {
469 struct tm_scsw *scsw = &irb->scsw.tm;
472 scsw->fctl = SCSW_FCTL_START_FUNC;
473 scsw->actl = SCSW_ACTL_START_PEND;
474 scsw->stctl = SCSW_STCTL_STATUS_PEND;
478 static void ccw_device_handle_broken_paths(struct ccw_device *cdev)
480 struct subchannel *sch = to_subchannel(cdev->dev.parent);
481 u8 broken_paths = (sch->schib.pmcw.pam & sch->opm) ^ sch->vpm;
483 if (broken_paths && (cdev->private->path_broken_mask != broken_paths))
484 ccw_device_schedule_recovery();
486 cdev->private->path_broken_mask = broken_paths;
489 void ccw_device_verify_done(struct ccw_device *cdev, int err)
491 struct subchannel *sch;
493 sch = to_subchannel(cdev->dev.parent);
494 /* Update schib - pom may have changed. */
495 if (cio_update_schib(sch)) {
499 /* Update lpm with verified path mask. */
501 /* Repeat path verification? */
502 if (cdev->private->flags.doverify) {
503 ccw_device_verify_start(cdev);
509 ccw_device_done(cdev, DEV_STATE_ONLINE);
510 /* Deliver fake irb to device driver, if needed. */
511 if (cdev->private->flags.fake_irb) {
512 create_fake_irb(&cdev->private->irb,
513 cdev->private->flags.fake_irb);
514 cdev->private->flags.fake_irb = 0;
516 cdev->handler(cdev, cdev->private->intparm,
517 &cdev->private->irb);
518 memset(&cdev->private->irb, 0, sizeof(struct irb));
520 ccw_device_report_path_events(cdev);
521 ccw_device_handle_broken_paths(cdev);
525 /* Reset oper notify indication after verify error. */
526 cdev->private->flags.donotify = 0;
527 ccw_device_done(cdev, DEV_STATE_BOXED);
530 /* Reset oper notify indication after verify error. */
531 cdev->private->flags.donotify = 0;
532 ccw_device_done(cdev, DEV_STATE_DISCONNECTED);
535 /* Reset oper notify indication after verify error. */
536 cdev->private->flags.donotify = 0;
537 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
540 ccw_device_reset_path_events(cdev);
547 ccw_device_online(struct ccw_device *cdev)
549 struct subchannel *sch;
552 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
553 (cdev->private->state != DEV_STATE_BOXED))
555 sch = to_subchannel(cdev->dev.parent);
556 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
558 /* Couldn't enable the subchannel for i/o. Sick device. */
560 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
563 /* Start initial path verification. */
564 cdev->private->state = DEV_STATE_VERIFY;
565 ccw_device_verify_start(cdev);
570 ccw_device_disband_done(struct ccw_device *cdev, int err)
574 ccw_device_done(cdev, DEV_STATE_OFFLINE);
577 ccw_device_done(cdev, DEV_STATE_BOXED);
580 cdev->private->flags.donotify = 0;
581 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
590 ccw_device_offline(struct ccw_device *cdev)
592 struct subchannel *sch;
594 /* Allow ccw_device_offline while disconnected. */
595 if (cdev->private->state == DEV_STATE_DISCONNECTED ||
596 cdev->private->state == DEV_STATE_NOT_OPER) {
597 cdev->private->flags.donotify = 0;
598 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
601 if (cdev->private->state == DEV_STATE_BOXED) {
602 ccw_device_done(cdev, DEV_STATE_BOXED);
605 if (ccw_device_is_orphan(cdev)) {
606 ccw_device_done(cdev, DEV_STATE_OFFLINE);
609 sch = to_subchannel(cdev->dev.parent);
610 if (cio_update_schib(sch))
612 if (scsw_actl(&sch->schib.scsw) != 0)
614 if (cdev->private->state != DEV_STATE_ONLINE)
616 /* Are we doing path grouping? */
617 if (!cdev->private->flags.pgroup) {
618 /* No, set state offline immediately. */
619 ccw_device_done(cdev, DEV_STATE_OFFLINE);
622 /* Start Set Path Group commands. */
623 cdev->private->state = DEV_STATE_DISBAND_PGID;
624 ccw_device_disband_start(cdev);
629 * Handle not operational event in non-special state.
631 static void ccw_device_generic_notoper(struct ccw_device *cdev,
632 enum dev_event dev_event)
634 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
635 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
637 ccw_device_set_disconnected(cdev);
641 * Handle path verification event in offline state.
643 static void ccw_device_offline_verify(struct ccw_device *cdev,
644 enum dev_event dev_event)
646 struct subchannel *sch = to_subchannel(cdev->dev.parent);
648 css_schedule_eval(sch->schid);
652 * Handle path verification event.
655 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
657 struct subchannel *sch;
659 if (cdev->private->state == DEV_STATE_W4SENSE) {
660 cdev->private->flags.doverify = 1;
663 sch = to_subchannel(cdev->dev.parent);
665 * Since we might not just be coming from an interrupt from the
666 * subchannel we have to update the schib.
668 if (cio_update_schib(sch)) {
669 ccw_device_verify_done(cdev, -ENODEV);
673 if (scsw_actl(&sch->schib.scsw) != 0 ||
674 (scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_STATUS_PEND) ||
675 (scsw_stctl(&cdev->private->irb.scsw) & SCSW_STCTL_STATUS_PEND)) {
677 * No final status yet or final status not yet delivered
678 * to the device driver. Can't do path verification now,
679 * delay until final status was delivered.
681 cdev->private->flags.doverify = 1;
684 /* Device is idle, we can do the path verification. */
685 cdev->private->state = DEV_STATE_VERIFY;
686 ccw_device_verify_start(cdev);
690 * Handle path verification event in boxed state.
692 static void ccw_device_boxed_verify(struct ccw_device *cdev,
693 enum dev_event dev_event)
695 struct subchannel *sch = to_subchannel(cdev->dev.parent);
698 if (cio_enable_subchannel(sch, (u32) (addr_t) sch))
699 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
701 ccw_device_online_verify(cdev, dev_event);
703 css_schedule_eval(sch->schid);
707 * Pass interrupt to device driver.
709 static int ccw_device_call_handler(struct ccw_device *cdev)
715 * we allow for the device action handler if .
716 * - we received ending status
717 * - the action handler requested to see all interrupts
718 * - we received an intermediate status
719 * - fast notification was requested (primary status)
720 * - unsolicited interrupts
722 stctl = scsw_stctl(&cdev->private->irb.scsw);
723 ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
724 (stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
725 (stctl == SCSW_STCTL_STATUS_PEND);
726 if (!ending_status &&
727 !cdev->private->options.repall &&
728 !(stctl & SCSW_STCTL_INTER_STATUS) &&
729 !(cdev->private->options.fast &&
730 (stctl & SCSW_STCTL_PRIM_STATUS)))
734 ccw_device_set_timeout(cdev, 0);
737 cdev->handler(cdev, cdev->private->intparm,
738 &cdev->private->irb);
740 memset(&cdev->private->irb, 0, sizeof(struct irb));
745 * Got an interrupt for a normal io (state online).
748 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
753 irb = this_cpu_ptr(&cio_irb);
754 is_cmd = !scsw_is_tm(&irb->scsw);
755 /* Check for unsolicited interrupt. */
756 if (!scsw_is_solicited(&irb->scsw)) {
757 if (is_cmd && (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
758 !irb->esw.esw0.erw.cons) {
759 /* Unit check but no sense data. Need basic sense. */
760 if (ccw_device_do_sense(cdev, irb) != 0)
761 goto call_handler_unsol;
762 memcpy(&cdev->private->irb, irb, sizeof(struct irb));
763 cdev->private->state = DEV_STATE_W4SENSE;
764 cdev->private->intparm = 0;
769 cdev->handler (cdev, 0, irb);
770 if (cdev->private->flags.doverify)
771 ccw_device_online_verify(cdev, 0);
774 /* Accumulate status and find out if a basic sense is needed. */
775 ccw_device_accumulate_irb(cdev, irb);
776 if (is_cmd && cdev->private->flags.dosense) {
777 if (ccw_device_do_sense(cdev, irb) == 0) {
778 cdev->private->state = DEV_STATE_W4SENSE;
782 /* Call the handler. */
783 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
784 /* Start delayed path verification. */
785 ccw_device_online_verify(cdev, 0);
789 * Got an timeout in online state.
792 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
796 ccw_device_set_timeout(cdev, 0);
797 cdev->private->iretry = 255;
798 cdev->private->async_kill_io_rc = -ETIMEDOUT;
799 ret = ccw_device_cancel_halt_clear(cdev);
801 ccw_device_set_timeout(cdev, 3*HZ);
802 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
806 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
807 else if (cdev->handler)
808 cdev->handler(cdev, cdev->private->intparm,
809 ERR_PTR(-ETIMEDOUT));
813 * Got an interrupt for a basic sense.
816 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
820 irb = this_cpu_ptr(&cio_irb);
821 /* Check for unsolicited interrupt. */
822 if (scsw_stctl(&irb->scsw) ==
823 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
824 if (scsw_cc(&irb->scsw) == 1)
825 /* Basic sense hasn't started. Try again. */
826 ccw_device_do_sense(cdev, irb);
828 CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
829 "interrupt during w4sense...\n",
830 cdev->private->dev_id.ssid,
831 cdev->private->dev_id.devno);
833 cdev->handler (cdev, 0, irb);
838 * Check if a halt or clear has been issued in the meanwhile. If yes,
839 * only deliver the halt/clear interrupt to the device driver as if it
840 * had killed the original request.
842 if (scsw_fctl(&irb->scsw) &
843 (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
844 cdev->private->flags.dosense = 0;
845 memset(&cdev->private->irb, 0, sizeof(struct irb));
846 ccw_device_accumulate_irb(cdev, irb);
849 /* Add basic sense info to irb. */
850 ccw_device_accumulate_basic_sense(cdev, irb);
851 if (cdev->private->flags.dosense) {
852 /* Another basic sense is needed. */
853 ccw_device_do_sense(cdev, irb);
857 cdev->private->state = DEV_STATE_ONLINE;
858 /* In case sensing interfered with setting the device online */
859 wake_up(&cdev->private->wait_q);
860 /* Call the handler. */
861 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
862 /* Start delayed path verification. */
863 ccw_device_online_verify(cdev, 0);
867 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
869 ccw_device_set_timeout(cdev, 0);
870 /* Start delayed path verification. */
871 ccw_device_online_verify(cdev, 0);
872 /* OK, i/o is dead now. Call interrupt handler. */
874 cdev->handler(cdev, cdev->private->intparm,
875 ERR_PTR(cdev->private->async_kill_io_rc));
879 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
883 ret = ccw_device_cancel_halt_clear(cdev);
885 ccw_device_set_timeout(cdev, 3*HZ);
888 /* Start delayed path verification. */
889 ccw_device_online_verify(cdev, 0);
891 cdev->handler(cdev, cdev->private->intparm,
892 ERR_PTR(cdev->private->async_kill_io_rc));
895 void ccw_device_kill_io(struct ccw_device *cdev)
899 ccw_device_set_timeout(cdev, 0);
900 cdev->private->iretry = 255;
901 cdev->private->async_kill_io_rc = -EIO;
902 ret = ccw_device_cancel_halt_clear(cdev);
904 ccw_device_set_timeout(cdev, 3*HZ);
905 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
908 /* Start delayed path verification. */
909 ccw_device_online_verify(cdev, 0);
911 cdev->handler(cdev, cdev->private->intparm,
916 ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
918 /* Start verification after current task finished. */
919 cdev->private->flags.doverify = 1;
923 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
925 struct subchannel *sch;
927 sch = to_subchannel(cdev->dev.parent);
928 if (cio_enable_subchannel(sch, (u32)(addr_t)sch) != 0)
929 /* Couldn't enable the subchannel for i/o. Sick device. */
931 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
932 ccw_device_sense_id_start(cdev);
935 void ccw_device_trigger_reprobe(struct ccw_device *cdev)
937 struct subchannel *sch;
939 if (cdev->private->state != DEV_STATE_DISCONNECTED)
942 sch = to_subchannel(cdev->dev.parent);
943 /* Update some values. */
944 if (cio_update_schib(sch))
947 * The pim, pam, pom values may not be accurate, but they are the best
948 * we have before performing device selection :/
950 sch->lpm = sch->schib.pmcw.pam & sch->opm;
952 * Use the initial configuration since we can't be shure that the old
955 io_subchannel_init_config(sch);
956 if (cio_commit_config(sch))
959 /* We should also udate ssd info, but this has to wait. */
960 /* Check if this is another device which appeared on the same sch. */
961 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno)
962 css_schedule_eval(sch->schid);
964 ccw_device_start_id(cdev, 0);
967 static void ccw_device_disabled_irq(struct ccw_device *cdev,
968 enum dev_event dev_event)
970 struct subchannel *sch;
972 sch = to_subchannel(cdev->dev.parent);
974 * An interrupt in a disabled state means a previous disable was not
975 * successful - should not happen, but we try to disable again.
977 cio_disable_subchannel(sch);
981 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
983 retry_set_schib(cdev);
984 cdev->private->state = DEV_STATE_ONLINE;
985 dev_fsm_event(cdev, dev_event);
988 static void ccw_device_update_cmfblock(struct ccw_device *cdev,
989 enum dev_event dev_event)
991 cmf_retry_copy_block(cdev);
992 cdev->private->state = DEV_STATE_ONLINE;
993 dev_fsm_event(cdev, dev_event);
997 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
999 ccw_device_set_timeout(cdev, 0);
1000 cdev->private->state = DEV_STATE_NOT_OPER;
1001 wake_up(&cdev->private->wait_q);
1005 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1009 ret = ccw_device_cancel_halt_clear(cdev);
1010 if (ret == -EBUSY) {
1011 ccw_device_set_timeout(cdev, HZ/10);
1013 cdev->private->state = DEV_STATE_NOT_OPER;
1014 wake_up(&cdev->private->wait_q);
1019 * No operation action. This is used e.g. to ignore a timeout event in
1023 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1028 * device statemachine
1030 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1031 [DEV_STATE_NOT_OPER] = {
1032 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1033 [DEV_EVENT_INTERRUPT] = ccw_device_disabled_irq,
1034 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1035 [DEV_EVENT_VERIFY] = ccw_device_nop,
1037 [DEV_STATE_SENSE_ID] = {
1038 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1039 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1040 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1041 [DEV_EVENT_VERIFY] = ccw_device_nop,
1043 [DEV_STATE_OFFLINE] = {
1044 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1045 [DEV_EVENT_INTERRUPT] = ccw_device_disabled_irq,
1046 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1047 [DEV_EVENT_VERIFY] = ccw_device_offline_verify,
1049 [DEV_STATE_VERIFY] = {
1050 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1051 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1052 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1053 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
1055 [DEV_STATE_ONLINE] = {
1056 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1057 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1058 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1059 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1061 [DEV_STATE_W4SENSE] = {
1062 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1063 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1064 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1065 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1067 [DEV_STATE_DISBAND_PGID] = {
1068 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1069 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1070 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1071 [DEV_EVENT_VERIFY] = ccw_device_nop,
1073 [DEV_STATE_BOXED] = {
1074 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1075 [DEV_EVENT_INTERRUPT] = ccw_device_nop,
1076 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1077 [DEV_EVENT_VERIFY] = ccw_device_boxed_verify,
1079 /* states to wait for i/o completion before doing something */
1080 [DEV_STATE_TIMEOUT_KILL] = {
1081 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1082 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1083 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1084 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1086 [DEV_STATE_QUIESCE] = {
1087 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1088 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1089 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1090 [DEV_EVENT_VERIFY] = ccw_device_nop,
1092 /* special states for devices gone not operational */
1093 [DEV_STATE_DISCONNECTED] = {
1094 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1095 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1096 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1097 [DEV_EVENT_VERIFY] = ccw_device_start_id,
1099 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1100 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1101 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1102 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1103 [DEV_EVENT_VERIFY] = ccw_device_nop,
1105 [DEV_STATE_CMFCHANGE] = {
1106 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1107 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1108 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1109 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1111 [DEV_STATE_CMFUPDATE] = {
1112 [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
1113 [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
1114 [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
1115 [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
1117 [DEV_STATE_STEAL_LOCK] = {
1118 [DEV_EVENT_NOTOPER] = ccw_device_request_event,
1119 [DEV_EVENT_INTERRUPT] = ccw_device_request_event,
1120 [DEV_EVENT_TIMEOUT] = ccw_device_request_event,
1121 [DEV_EVENT_VERIFY] = ccw_device_nop,
1125 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);