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 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");
181 ccw_device_handle_oper(struct ccw_device *cdev)
183 struct subchannel *sch;
185 sch = to_subchannel(cdev->dev.parent);
186 cdev->private->flags.recog_done = 1;
188 * Check if cu type and device type still match. If
189 * not, it is certainly another device and we have to
190 * de- and re-register.
192 if (cdev->id.cu_type != cdev->private->senseid.cu_type ||
193 cdev->id.cu_model != cdev->private->senseid.cu_model ||
194 cdev->id.dev_type != cdev->private->senseid.dev_type ||
195 cdev->id.dev_model != cdev->private->senseid.dev_model) {
196 PREPARE_WORK(&cdev->private->kick_work,
197 ccw_device_do_unbind_bind);
198 queue_work(ccw_device_work, &cdev->private->kick_work);
201 cdev->private->flags.donotify = 1;
206 * The machine won't give us any notification by machine check if a chpid has
207 * been varied online on the SE so we have to find out by magic (i. e. driving
208 * the channel subsystem to device selection and updating our path masks).
211 __recover_lost_chpids(struct subchannel *sch, int old_lpm)
217 for (i = 0; i<8; i++) {
219 if (!(sch->lpm & mask))
223 chpid.id = sch->schib.pmcw.chpid[i];
224 if (!chp_is_registered(chpid))
225 css_schedule_eval_all();
230 * Stop device recognition.
233 ccw_device_recog_done(struct ccw_device *cdev, int state)
235 struct subchannel *sch;
236 int notify, old_lpm, same_dev;
238 sch = to_subchannel(cdev->dev.parent);
240 ccw_device_set_timeout(cdev, 0);
241 cio_disable_subchannel(sch);
243 * Now that we tried recognition, we have performed device selection
244 * through ssch() and the path information is up to date.
248 /* Check since device may again have become not operational. */
249 if (cio_update_schib(sch))
250 state = DEV_STATE_NOT_OPER;
252 sch->lpm = sch->schib.pmcw.pam & sch->opm;
254 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
255 /* Force reprobe on all chpids. */
257 if (sch->lpm != old_lpm)
258 __recover_lost_chpids(sch, old_lpm);
259 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID &&
260 (state == DEV_STATE_NOT_OPER || state == DEV_STATE_BOXED)) {
261 cdev->private->flags.recog_done = 1;
262 cdev->private->state = DEV_STATE_DISCONNECTED;
263 wake_up(&cdev->private->wait_q);
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:
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);
309 if (cdev->id.cu_type != 0) { /* device was recognized before */
310 cdev->private->flags.recog_done = 1;
311 cdev->private->state = DEV_STATE_BOXED;
312 wake_up(&cdev->private->wait_q);
317 cdev->private->state = state;
318 io_subchannel_recog_done(cdev);
319 wake_up(&cdev->private->wait_q);
323 * Function called from device_id.c after sense id has completed.
326 ccw_device_sense_id_done(struct ccw_device *cdev, int err)
330 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
332 case -ETIME: /* Sense id stopped by timeout. */
333 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
336 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
341 int ccw_device_notify(struct ccw_device *cdev, int event)
347 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
348 cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
350 return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
353 static void cmf_reenable_delayed(struct work_struct *work)
355 struct ccw_device_private *priv;
356 struct ccw_device *cdev;
358 priv = container_of(work, struct ccw_device_private, kick_work);
363 static void ccw_device_oper_notify(struct ccw_device *cdev)
365 if (ccw_device_notify(cdev, CIO_OPER)) {
366 /* Reenable channel measurements, if needed. */
367 PREPARE_WORK(&cdev->private->kick_work, cmf_reenable_delayed);
368 queue_work(ccw_device_work, &cdev->private->kick_work);
371 /* Driver doesn't want device back. */
372 ccw_device_set_notoper(cdev);
373 PREPARE_WORK(&cdev->private->kick_work, ccw_device_do_unbind_bind);
374 queue_work(ccw_device_work, &cdev->private->kick_work);
378 * Finished with online/offline processing.
381 ccw_device_done(struct ccw_device *cdev, int state)
383 struct subchannel *sch;
385 sch = to_subchannel(cdev->dev.parent);
387 ccw_device_set_timeout(cdev, 0);
389 if (state != DEV_STATE_ONLINE)
390 cio_disable_subchannel(sch);
392 /* Reset device status. */
393 memset(&cdev->private->irb, 0, sizeof(struct irb));
395 cdev->private->state = state;
397 if (state == DEV_STATE_BOXED) {
398 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
399 cdev->private->dev_id.devno, sch->schid.sch_no);
400 if (cdev->online && !ccw_device_notify(cdev, CIO_BOXED))
401 ccw_device_schedule_sch_unregister(cdev);
402 cdev->private->flags.donotify = 0;
405 if (cdev->private->flags.donotify) {
406 cdev->private->flags.donotify = 0;
407 ccw_device_oper_notify(cdev);
409 wake_up(&cdev->private->wait_q);
412 static int cmp_pgid(struct pgid *p1, struct pgid *p2)
420 return memcmp(c1 + 1, c2 + 1, sizeof(struct pgid) - 1);
423 static void __ccw_device_get_common_pgid(struct ccw_device *cdev)
429 for (i = 0; i < 8; i++) {
430 if (cdev->private->pgid[i].inf.ps.state1 == SNID_STATE1_RESET)
433 if (cdev->private->pgid[last].inf.ps.state1 ==
435 /* First non-zero PGID */
439 if (cmp_pgid(&cdev->private->pgid[i],
440 &cdev->private->pgid[last]) == 0)
441 /* Non-conflicting PGIDs */
444 /* PGID mismatch, can't pathgroup. */
445 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
446 "0.%x.%04x, can't pathgroup\n",
447 cdev->private->dev_id.ssid,
448 cdev->private->dev_id.devno);
449 cdev->private->options.pgroup = 0;
452 if (cdev->private->pgid[last].inf.ps.state1 ==
454 /* No previous pgid found */
455 memcpy(&cdev->private->pgid[0],
456 &channel_subsystems[0]->global_pgid,
457 sizeof(struct pgid));
459 /* Use existing pgid */
460 memcpy(&cdev->private->pgid[0], &cdev->private->pgid[last],
461 sizeof(struct pgid));
465 * Function called from device_pgid.c after sense path ground has completed.
468 ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
470 struct subchannel *sch;
472 sch = to_subchannel(cdev->dev.parent);
474 case -EOPNOTSUPP: /* path grouping not supported, use nop instead. */
475 cdev->private->options.pgroup = 0;
477 case 0: /* success */
478 case -EACCES: /* partial success, some paths not operational */
479 /* Check if all pgids are equal or 0. */
480 __ccw_device_get_common_pgid(cdev);
482 case -ETIME: /* Sense path group id stopped by timeout. */
483 case -EUSERS: /* device is reserved for someone else. */
484 ccw_device_done(cdev, DEV_STATE_BOXED);
487 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
490 /* Start Path Group verification. */
491 cdev->private->state = DEV_STATE_VERIFY;
492 cdev->private->flags.doverify = 0;
493 ccw_device_verify_start(cdev);
497 * Start device recognition.
500 ccw_device_recognition(struct ccw_device *cdev)
502 struct subchannel *sch;
505 if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
506 (cdev->private->state != DEV_STATE_BOXED))
508 sch = to_subchannel(cdev->dev.parent);
509 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
511 /* Couldn't enable the subchannel for i/o. Sick device. */
514 /* After 60s the device recognition is considered to have failed. */
515 ccw_device_set_timeout(cdev, 60*HZ);
518 * We used to start here with a sense pgid to find out whether a device
519 * is locked by someone else. Unfortunately, the sense pgid command
520 * code has other meanings on devices predating the path grouping
521 * algorithm, so we start with sense id and box the device after an
522 * timeout (or if sense pgid during path verification detects the device
523 * is locked, as may happen on newer devices).
525 cdev->private->flags.recog_done = 0;
526 cdev->private->state = DEV_STATE_SENSE_ID;
527 ccw_device_sense_id_start(cdev);
532 * Handle timeout in device recognition.
535 ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
539 ret = ccw_device_cancel_halt_clear(cdev);
542 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
545 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
548 ccw_device_set_timeout(cdev, 3*HZ);
554 ccw_device_verify_done(struct ccw_device *cdev, int err)
556 struct subchannel *sch;
558 sch = to_subchannel(cdev->dev.parent);
559 /* Update schib - pom may have changed. */
560 if (cio_update_schib(sch)) {
561 cdev->private->flags.donotify = 0;
562 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
565 /* Update lpm with verified path mask. */
567 /* Repeat path verification? */
568 if (cdev->private->flags.doverify) {
569 cdev->private->flags.doverify = 0;
570 ccw_device_verify_start(cdev);
574 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
575 cdev->private->options.pgroup = 0;
577 ccw_device_done(cdev, DEV_STATE_ONLINE);
578 /* Deliver fake irb to device driver, if needed. */
579 if (cdev->private->flags.fake_irb) {
580 memset(&cdev->private->irb, 0, sizeof(struct irb));
581 cdev->private->irb.scsw.cmd.cc = 1;
582 cdev->private->irb.scsw.cmd.fctl = SCSW_FCTL_START_FUNC;
583 cdev->private->irb.scsw.cmd.actl = SCSW_ACTL_START_PEND;
584 cdev->private->irb.scsw.cmd.stctl =
585 SCSW_STCTL_STATUS_PEND;
586 cdev->private->flags.fake_irb = 0;
588 cdev->handler(cdev, cdev->private->intparm,
589 &cdev->private->irb);
590 memset(&cdev->private->irb, 0, sizeof(struct irb));
594 /* Reset oper notify indication after verify error. */
595 cdev->private->flags.donotify = 0;
596 ccw_device_done(cdev, DEV_STATE_BOXED);
599 /* Reset oper notify indication after verify error. */
600 cdev->private->flags.donotify = 0;
602 ccw_device_set_timeout(cdev, 0);
603 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
605 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
614 ccw_device_online(struct ccw_device *cdev)
616 struct subchannel *sch;
619 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
620 (cdev->private->state != DEV_STATE_BOXED))
622 sch = to_subchannel(cdev->dev.parent);
623 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
625 /* Couldn't enable the subchannel for i/o. Sick device. */
627 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
630 /* Do we want to do path grouping? */
631 if (!cdev->private->options.pgroup) {
632 /* Start initial path verification. */
633 cdev->private->state = DEV_STATE_VERIFY;
634 cdev->private->flags.doverify = 0;
635 ccw_device_verify_start(cdev);
638 /* Do a SensePGID first. */
639 cdev->private->state = DEV_STATE_SENSE_PGID;
640 ccw_device_sense_pgid_start(cdev);
645 ccw_device_disband_done(struct ccw_device *cdev, int err)
649 ccw_device_done(cdev, DEV_STATE_OFFLINE);
652 ccw_device_done(cdev, DEV_STATE_BOXED);
655 cdev->private->flags.donotify = 0;
656 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
657 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
666 ccw_device_offline(struct ccw_device *cdev)
668 struct subchannel *sch;
670 /* Allow ccw_device_offline while disconnected. */
671 if (cdev->private->state == DEV_STATE_DISCONNECTED ||
672 cdev->private->state == DEV_STATE_NOT_OPER) {
673 cdev->private->flags.donotify = 0;
674 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
677 if (ccw_device_is_orphan(cdev)) {
678 ccw_device_done(cdev, DEV_STATE_OFFLINE);
681 sch = to_subchannel(cdev->dev.parent);
682 if (cio_update_schib(sch))
684 if (scsw_actl(&sch->schib.scsw) != 0)
686 if (cdev->private->state != DEV_STATE_ONLINE)
688 /* Are we doing path grouping? */
689 if (!cdev->private->options.pgroup) {
690 /* No, set state offline immediately. */
691 ccw_device_done(cdev, DEV_STATE_OFFLINE);
694 /* Start Set Path Group commands. */
695 cdev->private->state = DEV_STATE_DISBAND_PGID;
696 ccw_device_disband_start(cdev);
701 * Handle timeout in device online/offline process.
704 ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
708 ret = ccw_device_cancel_halt_clear(cdev);
711 ccw_device_done(cdev, DEV_STATE_BOXED);
714 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
717 ccw_device_set_timeout(cdev, 3*HZ);
722 * Handle not oper event in device recognition.
725 ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
727 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
731 * Handle not operational event in non-special state.
733 static void ccw_device_generic_notoper(struct ccw_device *cdev,
734 enum dev_event dev_event)
736 struct subchannel *sch;
738 ccw_device_set_notoper(cdev);
739 sch = to_subchannel(cdev->dev.parent);
740 css_schedule_eval(sch->schid);
744 * Handle path verification event.
747 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
749 struct subchannel *sch;
751 if (cdev->private->state == DEV_STATE_W4SENSE) {
752 cdev->private->flags.doverify = 1;
755 sch = to_subchannel(cdev->dev.parent);
757 * Since we might not just be coming from an interrupt from the
758 * subchannel we have to update the schib.
760 if (cio_update_schib(sch)) {
761 ccw_device_verify_done(cdev, -ENODEV);
765 if (scsw_actl(&sch->schib.scsw) != 0 ||
766 (scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_STATUS_PEND) ||
767 (scsw_stctl(&cdev->private->irb.scsw) & SCSW_STCTL_STATUS_PEND)) {
769 * No final status yet or final status not yet delivered
770 * to the device driver. Can't do path verfication now,
771 * delay until final status was delivered.
773 cdev->private->flags.doverify = 1;
776 /* Device is idle, we can do the path verification. */
777 cdev->private->state = DEV_STATE_VERIFY;
778 cdev->private->flags.doverify = 0;
779 ccw_device_verify_start(cdev);
783 * Got an interrupt for a normal io (state online).
786 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
791 irb = (struct irb *) __LC_IRB;
792 is_cmd = !scsw_is_tm(&irb->scsw);
793 /* Check for unsolicited interrupt. */
794 if (!scsw_is_solicited(&irb->scsw)) {
795 if (is_cmd && (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
796 !irb->esw.esw0.erw.cons) {
797 /* Unit check but no sense data. Need basic sense. */
798 if (ccw_device_do_sense(cdev, irb) != 0)
799 goto call_handler_unsol;
800 memcpy(&cdev->private->irb, irb, sizeof(struct irb));
801 cdev->private->state = DEV_STATE_W4SENSE;
802 cdev->private->intparm = 0;
807 cdev->handler (cdev, 0, irb);
808 if (cdev->private->flags.doverify)
809 ccw_device_online_verify(cdev, 0);
812 /* Accumulate status and find out if a basic sense is needed. */
813 ccw_device_accumulate_irb(cdev, irb);
814 if (is_cmd && cdev->private->flags.dosense) {
815 if (ccw_device_do_sense(cdev, irb) == 0) {
816 cdev->private->state = DEV_STATE_W4SENSE;
820 /* Call the handler. */
821 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
822 /* Start delayed path verification. */
823 ccw_device_online_verify(cdev, 0);
827 * Got an timeout in online state.
830 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
834 ccw_device_set_timeout(cdev, 0);
835 ret = ccw_device_cancel_halt_clear(cdev);
837 ccw_device_set_timeout(cdev, 3*HZ);
838 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
842 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
843 else if (cdev->handler)
844 cdev->handler(cdev, cdev->private->intparm,
845 ERR_PTR(-ETIMEDOUT));
849 * Got an interrupt for a basic sense.
852 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
856 irb = (struct irb *) __LC_IRB;
857 /* Check for unsolicited interrupt. */
858 if (scsw_stctl(&irb->scsw) ==
859 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
860 if (scsw_cc(&irb->scsw) == 1)
861 /* Basic sense hasn't started. Try again. */
862 ccw_device_do_sense(cdev, irb);
864 CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
865 "interrupt during w4sense...\n",
866 cdev->private->dev_id.ssid,
867 cdev->private->dev_id.devno);
869 cdev->handler (cdev, 0, irb);
874 * Check if a halt or clear has been issued in the meanwhile. If yes,
875 * only deliver the halt/clear interrupt to the device driver as if it
876 * had killed the original request.
878 if (scsw_fctl(&irb->scsw) &
879 (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
880 /* Retry Basic Sense if requested. */
881 if (cdev->private->flags.intretry) {
882 cdev->private->flags.intretry = 0;
883 ccw_device_do_sense(cdev, irb);
886 cdev->private->flags.dosense = 0;
887 memset(&cdev->private->irb, 0, sizeof(struct irb));
888 ccw_device_accumulate_irb(cdev, irb);
891 /* Add basic sense info to irb. */
892 ccw_device_accumulate_basic_sense(cdev, irb);
893 if (cdev->private->flags.dosense) {
894 /* Another basic sense is needed. */
895 ccw_device_do_sense(cdev, irb);
899 cdev->private->state = DEV_STATE_ONLINE;
900 /* Call the handler. */
901 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
902 /* Start delayed path verification. */
903 ccw_device_online_verify(cdev, 0);
907 ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
911 irb = (struct irb *) __LC_IRB;
912 /* Accumulate status. We don't do basic sense. */
913 ccw_device_accumulate_irb(cdev, irb);
914 /* Remember to clear irb to avoid residuals. */
915 memset(&cdev->private->irb, 0, sizeof(struct irb));
916 /* Try to start delayed device verification. */
917 ccw_device_online_verify(cdev, 0);
918 /* Note: Don't call handler for cio initiated clear! */
922 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
924 struct subchannel *sch;
926 sch = to_subchannel(cdev->dev.parent);
927 ccw_device_set_timeout(cdev, 0);
928 /* Start delayed path verification. */
929 ccw_device_online_verify(cdev, 0);
930 /* OK, i/o is dead now. Call interrupt handler. */
932 cdev->handler(cdev, cdev->private->intparm,
937 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
941 ret = ccw_device_cancel_halt_clear(cdev);
943 ccw_device_set_timeout(cdev, 3*HZ);
946 /* Start delayed path verification. */
947 ccw_device_online_verify(cdev, 0);
949 cdev->handler(cdev, cdev->private->intparm,
953 void ccw_device_kill_io(struct ccw_device *cdev)
957 ret = ccw_device_cancel_halt_clear(cdev);
959 ccw_device_set_timeout(cdev, 3*HZ);
960 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
963 /* Start delayed path verification. */
964 ccw_device_online_verify(cdev, 0);
966 cdev->handler(cdev, cdev->private->intparm,
971 ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
973 /* Start verification after current task finished. */
974 cdev->private->flags.doverify = 1;
978 ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
983 case DEV_EVENT_INTERRUPT:
984 irb = (struct irb *) __LC_IRB;
985 /* Check for unsolicited interrupt. */
986 if ((scsw_stctl(&irb->scsw) ==
987 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
988 (!scsw_cc(&irb->scsw)))
989 /* FIXME: we should restart stlck here, but this
990 * is extremely unlikely ... */
993 ccw_device_accumulate_irb(cdev, irb);
994 /* We don't care about basic sense etc. */
996 default: /* timeout */
1000 wake_up(&cdev->private->wait_q);
1004 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
1006 struct subchannel *sch;
1008 sch = to_subchannel(cdev->dev.parent);
1009 if (cio_enable_subchannel(sch, (u32)(addr_t)sch) != 0)
1010 /* Couldn't enable the subchannel for i/o. Sick device. */
1013 /* After 60s the device recognition is considered to have failed. */
1014 ccw_device_set_timeout(cdev, 60*HZ);
1016 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
1017 ccw_device_sense_id_start(cdev);
1020 void ccw_device_trigger_reprobe(struct ccw_device *cdev)
1022 struct subchannel *sch;
1024 if (cdev->private->state != DEV_STATE_DISCONNECTED)
1027 sch = to_subchannel(cdev->dev.parent);
1028 /* Update some values. */
1029 if (cio_update_schib(sch))
1032 * The pim, pam, pom values may not be accurate, but they are the best
1033 * we have before performing device selection :/
1035 sch->lpm = sch->schib.pmcw.pam & sch->opm;
1037 * Use the initial configuration since we can't be shure that the old
1040 io_subchannel_init_config(sch);
1041 if (cio_commit_config(sch))
1044 /* We should also udate ssd info, but this has to wait. */
1045 /* Check if this is another device which appeared on the same sch. */
1046 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
1047 PREPARE_WORK(&cdev->private->kick_work,
1048 ccw_device_move_to_orphanage);
1049 queue_work(slow_path_wq, &cdev->private->kick_work);
1051 ccw_device_start_id(cdev, 0);
1055 ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1057 struct subchannel *sch;
1059 sch = to_subchannel(cdev->dev.parent);
1061 * An interrupt in state offline means a previous disable was not
1062 * successful - should not happen, but we try to disable again.
1064 cio_disable_subchannel(sch);
1068 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1070 retry_set_schib(cdev);
1071 cdev->private->state = DEV_STATE_ONLINE;
1072 dev_fsm_event(cdev, dev_event);
1075 static void ccw_device_update_cmfblock(struct ccw_device *cdev,
1076 enum dev_event dev_event)
1078 cmf_retry_copy_block(cdev);
1079 cdev->private->state = DEV_STATE_ONLINE;
1080 dev_fsm_event(cdev, dev_event);
1084 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1086 ccw_device_set_timeout(cdev, 0);
1087 if (dev_event == DEV_EVENT_NOTOPER)
1088 cdev->private->state = DEV_STATE_NOT_OPER;
1090 cdev->private->state = DEV_STATE_OFFLINE;
1091 wake_up(&cdev->private->wait_q);
1095 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1099 ret = ccw_device_cancel_halt_clear(cdev);
1102 cdev->private->state = DEV_STATE_OFFLINE;
1103 wake_up(&cdev->private->wait_q);
1106 cdev->private->state = DEV_STATE_NOT_OPER;
1107 wake_up(&cdev->private->wait_q);
1110 ccw_device_set_timeout(cdev, HZ/10);
1115 * No operation action. This is used e.g. to ignore a timeout event in
1119 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1124 * Bug operation action.
1127 ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1129 CIO_MSG_EVENT(0, "Internal state [%i][%i] not handled for device "
1130 "0.%x.%04x\n", cdev->private->state, dev_event,
1131 cdev->private->dev_id.ssid,
1132 cdev->private->dev_id.devno);
1137 * device statemachine
1139 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1140 [DEV_STATE_NOT_OPER] = {
1141 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1142 [DEV_EVENT_INTERRUPT] = ccw_device_bug,
1143 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1144 [DEV_EVENT_VERIFY] = ccw_device_nop,
1146 [DEV_STATE_SENSE_PGID] = {
1147 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1148 [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
1149 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1150 [DEV_EVENT_VERIFY] = ccw_device_nop,
1152 [DEV_STATE_SENSE_ID] = {
1153 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1154 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1155 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1156 [DEV_EVENT_VERIFY] = ccw_device_nop,
1158 [DEV_STATE_OFFLINE] = {
1159 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1160 [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
1161 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1162 [DEV_EVENT_VERIFY] = ccw_device_nop,
1164 [DEV_STATE_VERIFY] = {
1165 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1166 [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
1167 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1168 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
1170 [DEV_STATE_ONLINE] = {
1171 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1172 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1173 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1174 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1176 [DEV_STATE_W4SENSE] = {
1177 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1178 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1179 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1180 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1182 [DEV_STATE_DISBAND_PGID] = {
1183 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1184 [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
1185 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1186 [DEV_EVENT_VERIFY] = ccw_device_nop,
1188 [DEV_STATE_BOXED] = {
1189 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1190 [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
1191 [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
1192 [DEV_EVENT_VERIFY] = ccw_device_nop,
1194 /* states to wait for i/o completion before doing something */
1195 [DEV_STATE_CLEAR_VERIFY] = {
1196 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1197 [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
1198 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1199 [DEV_EVENT_VERIFY] = ccw_device_nop,
1201 [DEV_STATE_TIMEOUT_KILL] = {
1202 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1203 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1204 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1205 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1207 [DEV_STATE_QUIESCE] = {
1208 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1209 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1210 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1211 [DEV_EVENT_VERIFY] = ccw_device_nop,
1213 /* special states for devices gone not operational */
1214 [DEV_STATE_DISCONNECTED] = {
1215 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1216 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1217 [DEV_EVENT_TIMEOUT] = ccw_device_bug,
1218 [DEV_EVENT_VERIFY] = ccw_device_start_id,
1220 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1221 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1222 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1223 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1224 [DEV_EVENT_VERIFY] = ccw_device_nop,
1226 [DEV_STATE_CMFCHANGE] = {
1227 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1228 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1229 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1230 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1232 [DEV_STATE_CMFUPDATE] = {
1233 [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
1234 [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
1235 [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
1236 [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
1240 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);