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(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 ret = stsch(sch->schid, &sch->schib);
144 if (ret || !sch->schib.pmcw.dnv)
146 if (!sch->schib.pmcw.ena)
147 /* Not operational -> done. */
149 /* Stage 1: cancel io. */
150 if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_HALT_PEND) &&
151 !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
152 if (!scsw_is_tm(&sch->schib.scsw)) {
153 ret = cio_cancel(sch);
157 /* cancel io unsuccessful or not applicable (transport mode).
158 * Continue with asynchronous instructions. */
159 cdev->private->iretry = 3; /* 3 halt retries. */
161 if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
162 /* Stage 2: halt io. */
163 if (cdev->private->iretry) {
164 cdev->private->iretry--;
167 return (ret == 0) ? -EBUSY : ret;
169 /* halt io unsuccessful. */
170 cdev->private->iretry = 255; /* 255 clear retries. */
172 /* Stage 3: clear io. */
173 if (cdev->private->iretry) {
174 cdev->private->iretry--;
175 ret = cio_clear (sch);
176 return (ret == 0) ? -EBUSY : ret;
178 panic("Can't stop i/o on subchannel.\n");
182 ccw_device_handle_oper(struct ccw_device *cdev)
184 struct subchannel *sch;
186 sch = to_subchannel(cdev->dev.parent);
187 cdev->private->flags.recog_done = 1;
189 * Check if cu type and device type still match. If
190 * not, it is certainly another device and we have to
191 * de- and re-register.
193 if (cdev->id.cu_type != cdev->private->senseid.cu_type ||
194 cdev->id.cu_model != cdev->private->senseid.cu_model ||
195 cdev->id.dev_type != cdev->private->senseid.dev_type ||
196 cdev->id.dev_model != cdev->private->senseid.dev_model) {
197 PREPARE_WORK(&cdev->private->kick_work,
198 ccw_device_do_unreg_rereg);
199 queue_work(ccw_device_work, &cdev->private->kick_work);
202 cdev->private->flags.donotify = 1;
207 * The machine won't give us any notification by machine check if a chpid has
208 * been varied online on the SE so we have to find out by magic (i. e. driving
209 * the channel subsystem to device selection and updating our path masks).
212 __recover_lost_chpids(struct subchannel *sch, int old_lpm)
218 for (i = 0; i<8; i++) {
220 if (!(sch->lpm & mask))
224 chpid.id = sch->schib.pmcw.chpid[i];
225 if (!chp_is_registered(chpid))
226 css_schedule_eval_all();
231 * Stop device recognition.
234 ccw_device_recog_done(struct ccw_device *cdev, int state)
236 struct subchannel *sch;
237 int notify, old_lpm, same_dev;
239 sch = to_subchannel(cdev->dev.parent);
241 ccw_device_set_timeout(cdev, 0);
242 cio_disable_subchannel(sch);
244 * Now that we tried recognition, we have performed device selection
245 * through ssch() and the path information is up to date.
248 stsch(sch->schid, &sch->schib);
249 sch->lpm = sch->schib.pmcw.pam & sch->opm;
250 /* Check since device may again have become not operational. */
251 if (!sch->schib.pmcw.dnv)
252 state = DEV_STATE_NOT_OPER;
253 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
254 /* Force reprobe on all chpids. */
256 if (sch->lpm != old_lpm)
257 __recover_lost_chpids(sch, old_lpm);
258 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
259 if (state == DEV_STATE_NOT_OPER) {
260 cdev->private->flags.recog_done = 1;
261 cdev->private->state = DEV_STATE_DISCONNECTED;
264 /* Boxed devices don't need extra treatment. */
267 same_dev = 0; /* Keep the compiler quiet... */
269 case DEV_STATE_NOT_OPER:
270 CIO_MSG_EVENT(2, "SenseID : unknown device %04x on "
271 "subchannel 0.%x.%04x\n",
272 cdev->private->dev_id.devno,
273 sch->schid.ssid, sch->schid.sch_no);
275 case DEV_STATE_OFFLINE:
276 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
277 same_dev = ccw_device_handle_oper(cdev);
280 /* fill out sense information */
281 memset(&cdev->id, 0, sizeof(cdev->id));
282 cdev->id.cu_type = cdev->private->senseid.cu_type;
283 cdev->id.cu_model = cdev->private->senseid.cu_model;
284 cdev->id.dev_type = cdev->private->senseid.dev_type;
285 cdev->id.dev_model = cdev->private->senseid.dev_model;
287 cdev->private->state = DEV_STATE_OFFLINE;
289 /* Get device online again. */
290 ccw_device_online(cdev);
291 wake_up(&cdev->private->wait_q);
295 /* Issue device info message. */
296 CIO_MSG_EVENT(4, "SenseID : device 0.%x.%04x reports: "
297 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
299 cdev->private->dev_id.ssid,
300 cdev->private->dev_id.devno,
301 cdev->id.cu_type, cdev->id.cu_model,
302 cdev->id.dev_type, cdev->id.dev_model);
304 case DEV_STATE_BOXED:
305 CIO_MSG_EVENT(0, "SenseID : boxed device %04x on "
306 " subchannel 0.%x.%04x\n",
307 cdev->private->dev_id.devno,
308 sch->schid.ssid, sch->schid.sch_no);
311 cdev->private->state = state;
312 io_subchannel_recog_done(cdev);
313 if (state != DEV_STATE_NOT_OPER)
314 wake_up(&cdev->private->wait_q);
318 * Function called from device_id.c after sense id has completed.
321 ccw_device_sense_id_done(struct ccw_device *cdev, int err)
325 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
327 case -ETIME: /* Sense id stopped by timeout. */
328 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
331 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
336 int ccw_device_notify(struct ccw_device *cdev, int event)
342 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
343 cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
345 return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
348 static void cmf_reenable_delayed(struct work_struct *work)
350 struct ccw_device_private *priv;
351 struct ccw_device *cdev;
353 priv = container_of(work, struct ccw_device_private, kick_work);
358 static void ccw_device_oper_notify(struct ccw_device *cdev)
360 if (ccw_device_notify(cdev, CIO_OPER)) {
361 /* Reenable channel measurements, if needed. */
362 PREPARE_WORK(&cdev->private->kick_work, cmf_reenable_delayed);
363 queue_work(ccw_device_work, &cdev->private->kick_work);
366 /* Driver doesn't want device back. */
367 ccw_device_set_notoper(cdev);
368 PREPARE_WORK(&cdev->private->kick_work, ccw_device_do_unreg_rereg);
369 queue_work(ccw_device_work, &cdev->private->kick_work);
373 * Finished with online/offline processing.
376 ccw_device_done(struct ccw_device *cdev, int state)
378 struct subchannel *sch;
380 sch = to_subchannel(cdev->dev.parent);
382 ccw_device_set_timeout(cdev, 0);
384 if (state != DEV_STATE_ONLINE)
385 cio_disable_subchannel(sch);
387 /* Reset device status. */
388 memset(&cdev->private->irb, 0, sizeof(struct irb));
390 cdev->private->state = state;
393 if (state == DEV_STATE_BOXED)
394 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
395 cdev->private->dev_id.devno, sch->schid.sch_no);
397 if (cdev->private->flags.donotify) {
398 cdev->private->flags.donotify = 0;
399 ccw_device_oper_notify(cdev);
401 wake_up(&cdev->private->wait_q);
403 if (css_init_done && state != DEV_STATE_ONLINE)
404 put_device (&cdev->dev);
407 static int cmp_pgid(struct pgid *p1, struct pgid *p2)
415 return memcmp(c1 + 1, c2 + 1, sizeof(struct pgid) - 1);
418 static void __ccw_device_get_common_pgid(struct ccw_device *cdev)
424 for (i = 0; i < 8; i++) {
425 if (cdev->private->pgid[i].inf.ps.state1 == SNID_STATE1_RESET)
428 if (cdev->private->pgid[last].inf.ps.state1 ==
430 /* First non-zero PGID */
434 if (cmp_pgid(&cdev->private->pgid[i],
435 &cdev->private->pgid[last]) == 0)
436 /* Non-conflicting PGIDs */
439 /* PGID mismatch, can't pathgroup. */
440 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
441 "0.%x.%04x, can't pathgroup\n",
442 cdev->private->dev_id.ssid,
443 cdev->private->dev_id.devno);
444 cdev->private->options.pgroup = 0;
447 if (cdev->private->pgid[last].inf.ps.state1 ==
449 /* No previous pgid found */
450 memcpy(&cdev->private->pgid[0],
451 &channel_subsystems[0]->global_pgid,
452 sizeof(struct pgid));
454 /* Use existing pgid */
455 memcpy(&cdev->private->pgid[0], &cdev->private->pgid[last],
456 sizeof(struct pgid));
460 * Function called from device_pgid.c after sense path ground has completed.
463 ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
465 struct subchannel *sch;
467 sch = to_subchannel(cdev->dev.parent);
469 case -EOPNOTSUPP: /* path grouping not supported, use nop instead. */
470 cdev->private->options.pgroup = 0;
472 case 0: /* success */
473 case -EACCES: /* partial success, some paths not operational */
474 /* Check if all pgids are equal or 0. */
475 __ccw_device_get_common_pgid(cdev);
477 case -ETIME: /* Sense path group id stopped by timeout. */
478 case -EUSERS: /* device is reserved for someone else. */
479 ccw_device_done(cdev, DEV_STATE_BOXED);
482 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
485 /* Start Path Group verification. */
486 cdev->private->state = DEV_STATE_VERIFY;
487 cdev->private->flags.doverify = 0;
488 ccw_device_verify_start(cdev);
492 * Start device recognition.
495 ccw_device_recognition(struct ccw_device *cdev)
497 struct subchannel *sch;
500 if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
501 (cdev->private->state != DEV_STATE_BOXED))
503 sch = to_subchannel(cdev->dev.parent);
504 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
506 /* Couldn't enable the subchannel for i/o. Sick device. */
509 /* After 60s the device recognition is considered to have failed. */
510 ccw_device_set_timeout(cdev, 60*HZ);
513 * We used to start here with a sense pgid to find out whether a device
514 * is locked by someone else. Unfortunately, the sense pgid command
515 * code has other meanings on devices predating the path grouping
516 * algorithm, so we start with sense id and box the device after an
517 * timeout (or if sense pgid during path verification detects the device
518 * is locked, as may happen on newer devices).
520 cdev->private->flags.recog_done = 0;
521 cdev->private->state = DEV_STATE_SENSE_ID;
522 ccw_device_sense_id_start(cdev);
527 * Handle timeout in device recognition.
530 ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
534 ret = ccw_device_cancel_halt_clear(cdev);
537 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
540 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
543 ccw_device_set_timeout(cdev, 3*HZ);
549 ccw_device_verify_done(struct ccw_device *cdev, int err)
551 struct subchannel *sch;
553 sch = to_subchannel(cdev->dev.parent);
554 /* Update schib - pom may have changed. */
555 stsch(sch->schid, &sch->schib);
556 /* Update lpm with verified path mask. */
558 /* Repeat path verification? */
559 if (cdev->private->flags.doverify) {
560 cdev->private->flags.doverify = 0;
561 ccw_device_verify_start(cdev);
565 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
566 cdev->private->options.pgroup = 0;
568 ccw_device_done(cdev, DEV_STATE_ONLINE);
569 /* Deliver fake irb to device driver, if needed. */
570 if (cdev->private->flags.fake_irb) {
571 memset(&cdev->private->irb, 0, sizeof(struct irb));
572 cdev->private->irb.scsw.cmd.cc = 1;
573 cdev->private->irb.scsw.cmd.fctl = SCSW_FCTL_START_FUNC;
574 cdev->private->irb.scsw.cmd.actl = SCSW_ACTL_START_PEND;
575 cdev->private->irb.scsw.cmd.stctl =
576 SCSW_STCTL_STATUS_PEND;
577 cdev->private->flags.fake_irb = 0;
579 cdev->handler(cdev, cdev->private->intparm,
580 &cdev->private->irb);
581 memset(&cdev->private->irb, 0, sizeof(struct irb));
585 /* Reset oper notify indication after verify error. */
586 cdev->private->flags.donotify = 0;
587 ccw_device_done(cdev, DEV_STATE_BOXED);
590 /* Reset oper notify indication after verify error. */
591 cdev->private->flags.donotify = 0;
593 ccw_device_set_timeout(cdev, 0);
594 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
596 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
605 ccw_device_online(struct ccw_device *cdev)
607 struct subchannel *sch;
610 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
611 (cdev->private->state != DEV_STATE_BOXED))
613 sch = to_subchannel(cdev->dev.parent);
614 if (css_init_done && !get_device(&cdev->dev))
616 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
618 /* Couldn't enable the subchannel for i/o. Sick device. */
620 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
623 /* Do we want to do path grouping? */
624 if (!cdev->private->options.pgroup) {
625 /* Start initial path verification. */
626 cdev->private->state = DEV_STATE_VERIFY;
627 cdev->private->flags.doverify = 0;
628 ccw_device_verify_start(cdev);
631 /* Do a SensePGID first. */
632 cdev->private->state = DEV_STATE_SENSE_PGID;
633 ccw_device_sense_pgid_start(cdev);
638 ccw_device_disband_done(struct ccw_device *cdev, int err)
642 ccw_device_done(cdev, DEV_STATE_OFFLINE);
645 ccw_device_done(cdev, DEV_STATE_BOXED);
648 cdev->private->flags.donotify = 0;
649 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
650 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
659 ccw_device_offline(struct ccw_device *cdev)
661 struct subchannel *sch;
663 /* Allow ccw_device_offline while disconnected. */
664 if (cdev->private->state == DEV_STATE_DISCONNECTED ||
665 cdev->private->state == DEV_STATE_NOT_OPER) {
666 cdev->private->flags.donotify = 0;
667 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
670 if (ccw_device_is_orphan(cdev)) {
671 ccw_device_done(cdev, DEV_STATE_OFFLINE);
674 sch = to_subchannel(cdev->dev.parent);
675 if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
677 if (scsw_actl(&sch->schib.scsw) != 0)
679 if (cdev->private->state != DEV_STATE_ONLINE)
681 /* Are we doing path grouping? */
682 if (!cdev->private->options.pgroup) {
683 /* No, set state offline immediately. */
684 ccw_device_done(cdev, DEV_STATE_OFFLINE);
687 /* Start Set Path Group commands. */
688 cdev->private->state = DEV_STATE_DISBAND_PGID;
689 ccw_device_disband_start(cdev);
694 * Handle timeout in device online/offline process.
697 ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
701 ret = ccw_device_cancel_halt_clear(cdev);
704 ccw_device_done(cdev, DEV_STATE_BOXED);
707 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
710 ccw_device_set_timeout(cdev, 3*HZ);
715 * Handle not oper event in device recognition.
718 ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
720 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
724 * Handle not operational event in non-special state.
726 static void ccw_device_generic_notoper(struct ccw_device *cdev,
727 enum dev_event dev_event)
729 struct subchannel *sch;
731 cdev->private->state = DEV_STATE_NOT_OPER;
732 sch = to_subchannel(cdev->dev.parent);
733 css_schedule_eval(sch->schid);
737 * Handle path verification event.
740 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
742 struct subchannel *sch;
744 if (cdev->private->state == DEV_STATE_W4SENSE) {
745 cdev->private->flags.doverify = 1;
748 sch = to_subchannel(cdev->dev.parent);
750 * Since we might not just be coming from an interrupt from the
751 * subchannel we have to update the schib.
753 stsch(sch->schid, &sch->schib);
755 if (scsw_actl(&sch->schib.scsw) != 0 ||
756 (scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_STATUS_PEND) ||
757 (scsw_stctl(&cdev->private->irb.scsw) & SCSW_STCTL_STATUS_PEND)) {
759 * No final status yet or final status not yet delivered
760 * to the device driver. Can't do path verfication now,
761 * delay until final status was delivered.
763 cdev->private->flags.doverify = 1;
766 /* Device is idle, we can do the path verification. */
767 cdev->private->state = DEV_STATE_VERIFY;
768 cdev->private->flags.doverify = 0;
769 ccw_device_verify_start(cdev);
773 * Got an interrupt for a normal io (state online).
776 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
781 irb = (struct irb *) __LC_IRB;
782 is_cmd = !scsw_is_tm(&irb->scsw);
783 /* Check for unsolicited interrupt. */
784 if (!scsw_is_solicited(&irb->scsw)) {
785 if (is_cmd && (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
786 !irb->esw.esw0.erw.cons) {
787 /* Unit check but no sense data. Need basic sense. */
788 if (ccw_device_do_sense(cdev, irb) != 0)
789 goto call_handler_unsol;
790 memcpy(&cdev->private->irb, irb, sizeof(struct irb));
791 cdev->private->state = DEV_STATE_W4SENSE;
792 cdev->private->intparm = 0;
797 cdev->handler (cdev, 0, irb);
798 if (cdev->private->flags.doverify)
799 ccw_device_online_verify(cdev, 0);
802 /* Accumulate status and find out if a basic sense is needed. */
803 ccw_device_accumulate_irb(cdev, irb);
804 if (is_cmd && cdev->private->flags.dosense) {
805 if (ccw_device_do_sense(cdev, irb) == 0) {
806 cdev->private->state = DEV_STATE_W4SENSE;
810 /* Call the handler. */
811 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
812 /* Start delayed path verification. */
813 ccw_device_online_verify(cdev, 0);
817 * Got an timeout in online state.
820 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
824 ccw_device_set_timeout(cdev, 0);
825 ret = ccw_device_cancel_halt_clear(cdev);
827 ccw_device_set_timeout(cdev, 3*HZ);
828 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
832 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
833 else if (cdev->handler)
834 cdev->handler(cdev, cdev->private->intparm,
835 ERR_PTR(-ETIMEDOUT));
839 * Got an interrupt for a basic sense.
842 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
846 irb = (struct irb *) __LC_IRB;
847 /* Check for unsolicited interrupt. */
848 if (scsw_stctl(&irb->scsw) ==
849 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
850 if (scsw_cc(&irb->scsw) == 1)
851 /* Basic sense hasn't started. Try again. */
852 ccw_device_do_sense(cdev, irb);
854 CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
855 "interrupt during w4sense...\n",
856 cdev->private->dev_id.ssid,
857 cdev->private->dev_id.devno);
859 cdev->handler (cdev, 0, irb);
864 * Check if a halt or clear has been issued in the meanwhile. If yes,
865 * only deliver the halt/clear interrupt to the device driver as if it
866 * had killed the original request.
868 if (scsw_fctl(&irb->scsw) &
869 (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
870 /* Retry Basic Sense if requested. */
871 if (cdev->private->flags.intretry) {
872 cdev->private->flags.intretry = 0;
873 ccw_device_do_sense(cdev, irb);
876 cdev->private->flags.dosense = 0;
877 memset(&cdev->private->irb, 0, sizeof(struct irb));
878 ccw_device_accumulate_irb(cdev, irb);
881 /* Add basic sense info to irb. */
882 ccw_device_accumulate_basic_sense(cdev, irb);
883 if (cdev->private->flags.dosense) {
884 /* Another basic sense is needed. */
885 ccw_device_do_sense(cdev, irb);
889 cdev->private->state = DEV_STATE_ONLINE;
890 /* Call the handler. */
891 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
892 /* Start delayed path verification. */
893 ccw_device_online_verify(cdev, 0);
897 ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
901 irb = (struct irb *) __LC_IRB;
902 /* Accumulate status. We don't do basic sense. */
903 ccw_device_accumulate_irb(cdev, irb);
904 /* Remember to clear irb to avoid residuals. */
905 memset(&cdev->private->irb, 0, sizeof(struct irb));
906 /* Try to start delayed device verification. */
907 ccw_device_online_verify(cdev, 0);
908 /* Note: Don't call handler for cio initiated clear! */
912 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
914 struct subchannel *sch;
916 sch = to_subchannel(cdev->dev.parent);
917 ccw_device_set_timeout(cdev, 0);
918 /* Start delayed path verification. */
919 ccw_device_online_verify(cdev, 0);
920 /* OK, i/o is dead now. Call interrupt handler. */
922 cdev->handler(cdev, cdev->private->intparm,
927 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
931 ret = ccw_device_cancel_halt_clear(cdev);
933 ccw_device_set_timeout(cdev, 3*HZ);
936 /* Start delayed path verification. */
937 ccw_device_online_verify(cdev, 0);
939 cdev->handler(cdev, cdev->private->intparm,
943 void ccw_device_kill_io(struct ccw_device *cdev)
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 /* Start delayed path verification. */
954 ccw_device_online_verify(cdev, 0);
956 cdev->handler(cdev, cdev->private->intparm,
961 ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
963 /* Start verification after current task finished. */
964 cdev->private->flags.doverify = 1;
968 ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
973 case DEV_EVENT_INTERRUPT:
974 irb = (struct irb *) __LC_IRB;
975 /* Check for unsolicited interrupt. */
976 if ((scsw_stctl(&irb->scsw) ==
977 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
978 (!scsw_cc(&irb->scsw)))
979 /* FIXME: we should restart stlck here, but this
980 * is extremely unlikely ... */
983 ccw_device_accumulate_irb(cdev, irb);
984 /* We don't care about basic sense etc. */
986 default: /* timeout */
990 wake_up(&cdev->private->wait_q);
994 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
996 struct subchannel *sch;
998 sch = to_subchannel(cdev->dev.parent);
999 if (cio_enable_subchannel(sch, (u32)(addr_t)sch) != 0)
1000 /* Couldn't enable the subchannel for i/o. Sick device. */
1003 /* After 60s the device recognition is considered to have failed. */
1004 ccw_device_set_timeout(cdev, 60*HZ);
1006 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
1007 ccw_device_sense_id_start(cdev);
1010 void ccw_device_trigger_reprobe(struct ccw_device *cdev)
1012 struct subchannel *sch;
1014 if (cdev->private->state != DEV_STATE_DISCONNECTED)
1017 sch = to_subchannel(cdev->dev.parent);
1018 /* Update some values. */
1019 if (stsch(sch->schid, &sch->schib))
1021 if (!sch->schib.pmcw.dnv)
1024 * The pim, pam, pom values may not be accurate, but they are the best
1025 * we have before performing device selection :/
1027 sch->lpm = sch->schib.pmcw.pam & sch->opm;
1028 /* Re-set some bits in the pmcw that were lost. */
1029 sch->schib.pmcw.csense = 1;
1030 sch->schib.pmcw.ena = 0;
1031 if ((sch->lpm & (sch->lpm - 1)) != 0)
1032 sch->schib.pmcw.mp = 1;
1033 /* We should also udate ssd info, but this has to wait. */
1034 /* Check if this is another device which appeared on the same sch. */
1035 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
1036 PREPARE_WORK(&cdev->private->kick_work,
1037 ccw_device_move_to_orphanage);
1038 queue_work(slow_path_wq, &cdev->private->kick_work);
1040 ccw_device_start_id(cdev, 0);
1044 ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1046 struct subchannel *sch;
1048 sch = to_subchannel(cdev->dev.parent);
1050 * An interrupt in state offline means a previous disable was not
1051 * successful. Try again.
1053 cio_disable_subchannel(sch);
1057 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1059 retry_set_schib(cdev);
1060 cdev->private->state = DEV_STATE_ONLINE;
1061 dev_fsm_event(cdev, dev_event);
1064 static void ccw_device_update_cmfblock(struct ccw_device *cdev,
1065 enum dev_event dev_event)
1067 cmf_retry_copy_block(cdev);
1068 cdev->private->state = DEV_STATE_ONLINE;
1069 dev_fsm_event(cdev, dev_event);
1073 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1075 ccw_device_set_timeout(cdev, 0);
1076 if (dev_event == DEV_EVENT_NOTOPER)
1077 cdev->private->state = DEV_STATE_NOT_OPER;
1079 cdev->private->state = DEV_STATE_OFFLINE;
1080 wake_up(&cdev->private->wait_q);
1084 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1088 ret = ccw_device_cancel_halt_clear(cdev);
1091 cdev->private->state = DEV_STATE_OFFLINE;
1092 wake_up(&cdev->private->wait_q);
1095 cdev->private->state = DEV_STATE_NOT_OPER;
1096 wake_up(&cdev->private->wait_q);
1099 ccw_device_set_timeout(cdev, HZ/10);
1104 * No operation action. This is used e.g. to ignore a timeout event in
1108 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1113 * Bug operation action.
1116 ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1118 CIO_MSG_EVENT(0, "Internal state [%i][%i] not handled for device "
1119 "0.%x.%04x\n", cdev->private->state, dev_event,
1120 cdev->private->dev_id.ssid,
1121 cdev->private->dev_id.devno);
1126 * device statemachine
1128 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1129 [DEV_STATE_NOT_OPER] = {
1130 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1131 [DEV_EVENT_INTERRUPT] = ccw_device_bug,
1132 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1133 [DEV_EVENT_VERIFY] = ccw_device_nop,
1135 [DEV_STATE_SENSE_PGID] = {
1136 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1137 [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
1138 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1139 [DEV_EVENT_VERIFY] = ccw_device_nop,
1141 [DEV_STATE_SENSE_ID] = {
1142 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1143 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1144 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1145 [DEV_EVENT_VERIFY] = ccw_device_nop,
1147 [DEV_STATE_OFFLINE] = {
1148 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1149 [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
1150 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1151 [DEV_EVENT_VERIFY] = ccw_device_nop,
1153 [DEV_STATE_VERIFY] = {
1154 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1155 [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
1156 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1157 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
1159 [DEV_STATE_ONLINE] = {
1160 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1161 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1162 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1163 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1165 [DEV_STATE_W4SENSE] = {
1166 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1167 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1168 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1169 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1171 [DEV_STATE_DISBAND_PGID] = {
1172 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1173 [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
1174 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1175 [DEV_EVENT_VERIFY] = ccw_device_nop,
1177 [DEV_STATE_BOXED] = {
1178 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1179 [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
1180 [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
1181 [DEV_EVENT_VERIFY] = ccw_device_nop,
1183 /* states to wait for i/o completion before doing something */
1184 [DEV_STATE_CLEAR_VERIFY] = {
1185 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1186 [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
1187 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1188 [DEV_EVENT_VERIFY] = ccw_device_nop,
1190 [DEV_STATE_TIMEOUT_KILL] = {
1191 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1192 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1193 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1194 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1196 [DEV_STATE_QUIESCE] = {
1197 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1198 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1199 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1200 [DEV_EVENT_VERIFY] = ccw_device_nop,
1202 /* special states for devices gone not operational */
1203 [DEV_STATE_DISCONNECTED] = {
1204 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1205 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1206 [DEV_EVENT_TIMEOUT] = ccw_device_bug,
1207 [DEV_EVENT_VERIFY] = ccw_device_start_id,
1209 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1210 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1211 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1212 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1213 [DEV_EVENT_VERIFY] = ccw_device_nop,
1215 [DEV_STATE_CMFCHANGE] = {
1216 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1217 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1218 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1219 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1221 [DEV_STATE_CMFUPDATE] = {
1222 [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
1223 [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
1224 [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
1225 [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
1229 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);