2 * drivers/s390/cio/device_fsm.c
3 * finite state machine for device handling
5 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
7 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
8 * Martin Schwidefsky (schwidefsky@de.ibm.com)
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/jiffies.h>
14 #include <linux/string.h>
16 #include <asm/ccwdev.h>
18 #include <asm/chpid.h>
21 #include "cio_debug.h"
29 device_is_online(struct subchannel *sch)
31 struct ccw_device *cdev;
33 if (!sch->dev.driver_data)
35 cdev = sch->dev.driver_data;
36 return (cdev->private->state == DEV_STATE_ONLINE);
40 device_is_disconnected(struct subchannel *sch)
42 struct ccw_device *cdev;
44 if (!sch->dev.driver_data)
46 cdev = sch->dev.driver_data;
47 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
48 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
52 device_set_disconnected(struct subchannel *sch)
54 struct ccw_device *cdev;
56 if (!sch->dev.driver_data)
58 cdev = sch->dev.driver_data;
59 ccw_device_set_timeout(cdev, 0);
60 cdev->private->flags.fake_irb = 0;
61 cdev->private->state = DEV_STATE_DISCONNECTED;
64 void device_set_intretry(struct subchannel *sch)
66 struct ccw_device *cdev;
68 cdev = sch->dev.driver_data;
71 cdev->private->flags.intretry = 1;
74 int device_trigger_verify(struct subchannel *sch)
76 struct ccw_device *cdev;
78 cdev = sch->dev.driver_data;
79 if (!cdev || !cdev->online)
81 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
86 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
89 ccw_device_timeout(unsigned long data)
91 struct ccw_device *cdev;
93 cdev = (struct ccw_device *) data;
94 spin_lock_irq(cdev->ccwlock);
95 dev_fsm_event(cdev, DEV_EVENT_TIMEOUT);
96 spin_unlock_irq(cdev->ccwlock);
103 ccw_device_set_timeout(struct ccw_device *cdev, int expires)
106 del_timer(&cdev->private->timer);
109 if (timer_pending(&cdev->private->timer)) {
110 if (mod_timer(&cdev->private->timer, jiffies + expires))
113 cdev->private->timer.function = ccw_device_timeout;
114 cdev->private->timer.data = (unsigned long) cdev;
115 cdev->private->timer.expires = jiffies + expires;
116 add_timer(&cdev->private->timer);
119 /* Kill any pending timers after machine check. */
121 device_kill_pending_timer(struct subchannel *sch)
123 struct ccw_device *cdev;
125 if (!sch->dev.driver_data)
127 cdev = sch->dev.driver_data;
128 ccw_device_set_timeout(cdev, 0);
132 * Cancel running i/o. This is called repeatedly since halt/clear are
133 * asynchronous operations. We do one try with cio_cancel, two tries
134 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
135 * Returns 0 if device now idle, -ENODEV for device not operational and
136 * -EBUSY if an interrupt is expected (either from halt/clear or from a
140 ccw_device_cancel_halt_clear(struct ccw_device *cdev)
142 struct subchannel *sch;
145 sch = to_subchannel(cdev->dev.parent);
146 ret = stsch(sch->schid, &sch->schib);
147 if (ret || !sch->schib.pmcw.dnv)
149 if (!sch->schib.pmcw.ena)
150 /* Not operational -> done. */
152 /* Stage 1: cancel io. */
153 if (!(sch->schib.scsw.actl & SCSW_ACTL_HALT_PEND) &&
154 !(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
155 ret = cio_cancel(sch);
158 /* cancel io unsuccessful. From now on it is asynchronous. */
159 cdev->private->iretry = 3; /* 3 halt retries. */
161 if (!(sch->schib.scsw.actl & 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_DEBUG(KERN_WARNING, 2,
271 "cio: SenseID : unknown device %04x on subchannel "
272 "0.%x.%04x\n", 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_DEBUG(KERN_INFO, 2,
297 "cio: SenseID : device 0.%x.%04x reports: "
298 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
300 cdev->private->dev_id.ssid,
301 cdev->private->dev_id.devno,
302 cdev->id.cu_type, cdev->id.cu_model,
303 cdev->id.dev_type, cdev->id.dev_model);
305 case DEV_STATE_BOXED:
306 CIO_DEBUG(KERN_WARNING, 2,
307 "cio: SenseID : boxed device %04x on subchannel "
308 "0.%x.%04x\n", cdev->private->dev_id.devno,
309 sch->schid.ssid, sch->schid.sch_no);
312 cdev->private->state = state;
313 io_subchannel_recog_done(cdev);
314 if (state != DEV_STATE_NOT_OPER)
315 wake_up(&cdev->private->wait_q);
319 * Function called from device_id.c after sense id has completed.
322 ccw_device_sense_id_done(struct ccw_device *cdev, int err)
326 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
328 case -ETIME: /* Sense id stopped by timeout. */
329 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
332 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
338 ccw_device_oper_notify(struct work_struct *work)
340 struct ccw_device_private *priv;
341 struct ccw_device *cdev;
342 struct subchannel *sch;
346 priv = container_of(work, struct ccw_device_private, kick_work);
348 spin_lock_irqsave(cdev->ccwlock, flags);
349 sch = to_subchannel(cdev->dev.parent);
350 if (sch->driver && sch->driver->notify) {
351 spin_unlock_irqrestore(cdev->ccwlock, flags);
352 ret = sch->driver->notify(&sch->dev, CIO_OPER);
353 spin_lock_irqsave(cdev->ccwlock, flags);
357 /* Reenable channel measurements, if needed. */
358 spin_unlock_irqrestore(cdev->ccwlock, flags);
360 spin_lock_irqsave(cdev->ccwlock, flags);
361 wake_up(&cdev->private->wait_q);
363 spin_unlock_irqrestore(cdev->ccwlock, flags);
365 /* Driver doesn't want device back. */
366 ccw_device_do_unreg_rereg(work);
370 * Finished with online/offline processing.
373 ccw_device_done(struct ccw_device *cdev, int state)
375 struct subchannel *sch;
377 sch = to_subchannel(cdev->dev.parent);
379 ccw_device_set_timeout(cdev, 0);
381 if (state != DEV_STATE_ONLINE)
382 cio_disable_subchannel(sch);
384 /* Reset device status. */
385 memset(&cdev->private->irb, 0, sizeof(struct irb));
387 cdev->private->state = state;
390 if (state == DEV_STATE_BOXED)
391 CIO_DEBUG(KERN_WARNING, 2,
392 "cio: Boxed device %04x on subchannel %04x\n",
393 cdev->private->dev_id.devno, sch->schid.sch_no);
395 if (cdev->private->flags.donotify) {
396 cdev->private->flags.donotify = 0;
397 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify);
398 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
400 wake_up(&cdev->private->wait_q);
402 if (css_init_done && state != DEV_STATE_ONLINE)
403 put_device (&cdev->dev);
406 static int cmp_pgid(struct pgid *p1, struct pgid *p2)
414 return memcmp(c1 + 1, c2 + 1, sizeof(struct pgid) - 1);
417 static void __ccw_device_get_common_pgid(struct ccw_device *cdev)
423 for (i = 0; i < 8; i++) {
424 if (cdev->private->pgid[i].inf.ps.state1 == SNID_STATE1_RESET)
427 if (cdev->private->pgid[last].inf.ps.state1 ==
429 /* First non-zero PGID */
433 if (cmp_pgid(&cdev->private->pgid[i],
434 &cdev->private->pgid[last]) == 0)
435 /* Non-conflicting PGIDs */
438 /* PGID mismatch, can't pathgroup. */
439 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
440 "0.%x.%04x, can't pathgroup\n",
441 cdev->private->dev_id.ssid,
442 cdev->private->dev_id.devno);
443 cdev->private->options.pgroup = 0;
446 if (cdev->private->pgid[last].inf.ps.state1 ==
448 /* No previous pgid found */
449 memcpy(&cdev->private->pgid[0],
450 &channel_subsystems[0]->global_pgid,
451 sizeof(struct pgid));
453 /* Use existing pgid */
454 memcpy(&cdev->private->pgid[0], &cdev->private->pgid[last],
455 sizeof(struct pgid));
459 * Function called from device_pgid.c after sense path ground has completed.
462 ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
464 struct subchannel *sch;
466 sch = to_subchannel(cdev->dev.parent);
468 case -EOPNOTSUPP: /* path grouping not supported, use nop instead. */
469 cdev->private->options.pgroup = 0;
471 case 0: /* success */
472 case -EACCES: /* partial success, some paths not operational */
473 /* Check if all pgids are equal or 0. */
474 __ccw_device_get_common_pgid(cdev);
476 case -ETIME: /* Sense path group id stopped by timeout. */
477 case -EUSERS: /* device is reserved for someone else. */
478 ccw_device_done(cdev, DEV_STATE_BOXED);
481 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
484 /* Start Path Group verification. */
485 cdev->private->state = DEV_STATE_VERIFY;
486 cdev->private->flags.doverify = 0;
487 ccw_device_verify_start(cdev);
491 * Start device recognition.
494 ccw_device_recognition(struct ccw_device *cdev)
496 struct subchannel *sch;
499 if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
500 (cdev->private->state != DEV_STATE_BOXED))
502 sch = to_subchannel(cdev->dev.parent);
503 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
505 /* Couldn't enable the subchannel for i/o. Sick device. */
508 /* After 60s the device recognition is considered to have failed. */
509 ccw_device_set_timeout(cdev, 60*HZ);
512 * We used to start here with a sense pgid to find out whether a device
513 * is locked by someone else. Unfortunately, the sense pgid command
514 * code has other meanings on devices predating the path grouping
515 * algorithm, so we start with sense id and box the device after an
516 * timeout (or if sense pgid during path verification detects the device
517 * is locked, as may happen on newer devices).
519 cdev->private->flags.recog_done = 0;
520 cdev->private->state = DEV_STATE_SENSE_ID;
521 ccw_device_sense_id_start(cdev);
526 * Handle timeout in device recognition.
529 ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
533 ret = ccw_device_cancel_halt_clear(cdev);
536 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
539 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
542 ccw_device_set_timeout(cdev, 3*HZ);
548 ccw_device_verify_done(struct ccw_device *cdev, int err)
550 struct subchannel *sch;
552 sch = to_subchannel(cdev->dev.parent);
553 /* Update schib - pom may have changed. */
554 stsch(sch->schid, &sch->schib);
555 /* Update lpm with verified path mask. */
557 /* Repeat path verification? */
558 if (cdev->private->flags.doverify) {
559 cdev->private->flags.doverify = 0;
560 ccw_device_verify_start(cdev);
564 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
565 cdev->private->options.pgroup = 0;
567 ccw_device_done(cdev, DEV_STATE_ONLINE);
568 /* Deliver fake irb to device driver, if needed. */
569 if (cdev->private->flags.fake_irb) {
570 memset(&cdev->private->irb, 0, sizeof(struct irb));
571 cdev->private->irb.scsw.cc = 1;
572 cdev->private->irb.scsw.fctl = SCSW_FCTL_START_FUNC;
573 cdev->private->irb.scsw.actl = SCSW_ACTL_START_PEND;
574 cdev->private->irb.scsw.stctl = SCSW_STCTL_STATUS_PEND;
575 cdev->private->flags.fake_irb = 0;
577 cdev->handler(cdev, cdev->private->intparm,
578 &cdev->private->irb);
579 memset(&cdev->private->irb, 0, sizeof(struct irb));
583 /* Reset oper notify indication after verify error. */
584 cdev->private->flags.donotify = 0;
585 ccw_device_done(cdev, DEV_STATE_BOXED);
588 /* Reset oper notify indication after verify error. */
589 cdev->private->flags.donotify = 0;
591 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
593 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
602 ccw_device_online(struct ccw_device *cdev)
604 struct subchannel *sch;
607 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
608 (cdev->private->state != DEV_STATE_BOXED))
610 sch = to_subchannel(cdev->dev.parent);
611 if (css_init_done && !get_device(&cdev->dev))
613 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
615 /* Couldn't enable the subchannel for i/o. Sick device. */
617 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
620 /* Do we want to do path grouping? */
621 if (!cdev->private->options.pgroup) {
622 /* Start initial path verification. */
623 cdev->private->state = DEV_STATE_VERIFY;
624 cdev->private->flags.doverify = 0;
625 ccw_device_verify_start(cdev);
628 /* Do a SensePGID first. */
629 cdev->private->state = DEV_STATE_SENSE_PGID;
630 ccw_device_sense_pgid_start(cdev);
635 ccw_device_disband_done(struct ccw_device *cdev, int err)
639 ccw_device_done(cdev, DEV_STATE_OFFLINE);
642 ccw_device_done(cdev, DEV_STATE_BOXED);
645 cdev->private->flags.donotify = 0;
646 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
647 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
656 ccw_device_offline(struct ccw_device *cdev)
658 struct subchannel *sch;
660 if (ccw_device_is_orphan(cdev)) {
661 ccw_device_done(cdev, DEV_STATE_OFFLINE);
664 sch = to_subchannel(cdev->dev.parent);
665 if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
667 if (cdev->private->state != DEV_STATE_ONLINE) {
668 if (sch->schib.scsw.actl != 0)
672 if (sch->schib.scsw.actl != 0)
674 /* Are we doing path grouping? */
675 if (!cdev->private->options.pgroup) {
676 /* No, set state offline immediately. */
677 ccw_device_done(cdev, DEV_STATE_OFFLINE);
680 /* Start Set Path Group commands. */
681 cdev->private->state = DEV_STATE_DISBAND_PGID;
682 ccw_device_disband_start(cdev);
687 * Handle timeout in device online/offline process.
690 ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
694 ret = ccw_device_cancel_halt_clear(cdev);
697 ccw_device_done(cdev, DEV_STATE_BOXED);
700 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
703 ccw_device_set_timeout(cdev, 3*HZ);
708 * Handle not oper event in device recognition.
711 ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
713 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
717 * Handle not operational event in non-special state.
719 static void ccw_device_generic_notoper(struct ccw_device *cdev,
720 enum dev_event dev_event)
722 struct subchannel *sch;
724 cdev->private->state = DEV_STATE_NOT_OPER;
725 sch = to_subchannel(cdev->dev.parent);
726 css_schedule_eval(sch->schid);
730 * Handle path verification event.
733 ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
735 struct subchannel *sch;
737 if (cdev->private->state == DEV_STATE_W4SENSE) {
738 cdev->private->flags.doverify = 1;
741 sch = to_subchannel(cdev->dev.parent);
743 * Since we might not just be coming from an interrupt from the
744 * subchannel we have to update the schib.
746 stsch(sch->schid, &sch->schib);
748 if (sch->schib.scsw.actl != 0 ||
749 (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
750 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
752 * No final status yet or final status not yet delivered
753 * to the device driver. Can't do path verfication now,
754 * delay until final status was delivered.
756 cdev->private->flags.doverify = 1;
759 /* Device is idle, we can do the path verification. */
760 cdev->private->state = DEV_STATE_VERIFY;
761 cdev->private->flags.doverify = 0;
762 ccw_device_verify_start(cdev);
766 * Got an interrupt for a normal io (state online).
769 ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
773 irb = (struct irb *) __LC_IRB;
774 /* Check for unsolicited interrupt. */
775 if ((irb->scsw.stctl ==
776 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
777 && (!irb->scsw.cc)) {
778 if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
779 !irb->esw.esw0.erw.cons) {
780 /* Unit check but no sense data. Need basic sense. */
781 if (ccw_device_do_sense(cdev, irb) != 0)
782 goto call_handler_unsol;
783 memcpy(&cdev->private->irb, irb, sizeof(struct irb));
784 cdev->private->state = DEV_STATE_W4SENSE;
785 cdev->private->intparm = 0;
790 cdev->handler (cdev, 0, irb);
791 if (cdev->private->flags.doverify)
792 ccw_device_online_verify(cdev, 0);
795 /* Accumulate status and find out if a basic sense is needed. */
796 ccw_device_accumulate_irb(cdev, irb);
797 if (cdev->private->flags.dosense) {
798 if (ccw_device_do_sense(cdev, irb) == 0) {
799 cdev->private->state = DEV_STATE_W4SENSE;
803 /* Call the handler. */
804 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
805 /* Start delayed path verification. */
806 ccw_device_online_verify(cdev, 0);
810 * Got an timeout in online state.
813 ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
817 ccw_device_set_timeout(cdev, 0);
818 ret = ccw_device_cancel_halt_clear(cdev);
820 ccw_device_set_timeout(cdev, 3*HZ);
821 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
825 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
826 else if (cdev->handler)
827 cdev->handler(cdev, cdev->private->intparm,
828 ERR_PTR(-ETIMEDOUT));
832 * Got an interrupt for a basic sense.
835 ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
839 irb = (struct irb *) __LC_IRB;
840 /* Check for unsolicited interrupt. */
841 if (irb->scsw.stctl ==
842 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
843 if (irb->scsw.cc == 1)
844 /* Basic sense hasn't started. Try again. */
845 ccw_device_do_sense(cdev, irb);
847 CIO_MSG_EVENT(2, "Huh? 0.%x.%04x: unsolicited "
848 "interrupt during w4sense...\n",
849 cdev->private->dev_id.ssid,
850 cdev->private->dev_id.devno);
852 cdev->handler (cdev, 0, irb);
857 * Check if a halt or clear has been issued in the meanwhile. If yes,
858 * only deliver the halt/clear interrupt to the device driver as if it
859 * had killed the original request.
861 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
862 /* Retry Basic Sense if requested. */
863 if (cdev->private->flags.intretry) {
864 cdev->private->flags.intretry = 0;
865 ccw_device_do_sense(cdev, irb);
868 cdev->private->flags.dosense = 0;
869 memset(&cdev->private->irb, 0, sizeof(struct irb));
870 ccw_device_accumulate_irb(cdev, irb);
873 /* Add basic sense info to irb. */
874 ccw_device_accumulate_basic_sense(cdev, irb);
875 if (cdev->private->flags.dosense) {
876 /* Another basic sense is needed. */
877 ccw_device_do_sense(cdev, irb);
881 cdev->private->state = DEV_STATE_ONLINE;
882 /* Call the handler. */
883 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
884 /* Start delayed path verification. */
885 ccw_device_online_verify(cdev, 0);
889 ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
893 irb = (struct irb *) __LC_IRB;
894 /* Accumulate status. We don't do basic sense. */
895 ccw_device_accumulate_irb(cdev, irb);
896 /* Remember to clear irb to avoid residuals. */
897 memset(&cdev->private->irb, 0, sizeof(struct irb));
898 /* Try to start delayed device verification. */
899 ccw_device_online_verify(cdev, 0);
900 /* Note: Don't call handler for cio initiated clear! */
904 ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
906 struct subchannel *sch;
908 sch = to_subchannel(cdev->dev.parent);
909 ccw_device_set_timeout(cdev, 0);
910 /* Start delayed path verification. */
911 ccw_device_online_verify(cdev, 0);
912 /* OK, i/o is dead now. Call interrupt handler. */
914 cdev->handler(cdev, cdev->private->intparm,
919 ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
923 ret = ccw_device_cancel_halt_clear(cdev);
925 ccw_device_set_timeout(cdev, 3*HZ);
928 /* Start delayed path verification. */
929 ccw_device_online_verify(cdev, 0);
931 cdev->handler(cdev, cdev->private->intparm,
935 void device_kill_io(struct subchannel *sch)
938 struct ccw_device *cdev;
940 cdev = sch->dev.driver_data;
941 ret = ccw_device_cancel_halt_clear(cdev);
943 ccw_device_set_timeout(cdev, 3*HZ);
944 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
947 /* Start delayed path verification. */
948 ccw_device_online_verify(cdev, 0);
950 cdev->handler(cdev, cdev->private->intparm,
955 ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
957 /* Start verification after current task finished. */
958 cdev->private->flags.doverify = 1;
962 ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
967 case DEV_EVENT_INTERRUPT:
968 irb = (struct irb *) __LC_IRB;
969 /* Check for unsolicited interrupt. */
970 if ((irb->scsw.stctl ==
971 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
973 /* FIXME: we should restart stlck here, but this
974 * is extremely unlikely ... */
977 ccw_device_accumulate_irb(cdev, irb);
978 /* We don't care about basic sense etc. */
980 default: /* timeout */
984 wake_up(&cdev->private->wait_q);
988 ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
990 struct subchannel *sch;
992 sch = to_subchannel(cdev->dev.parent);
993 if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
994 /* Couldn't enable the subchannel for i/o. Sick device. */
997 /* After 60s the device recognition is considered to have failed. */
998 ccw_device_set_timeout(cdev, 60*HZ);
1000 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
1001 ccw_device_sense_id_start(cdev);
1005 device_trigger_reprobe(struct subchannel *sch)
1007 struct ccw_device *cdev;
1009 if (!sch->dev.driver_data)
1011 cdev = sch->dev.driver_data;
1012 if (cdev->private->state != DEV_STATE_DISCONNECTED)
1015 /* Update some values. */
1016 if (stsch(sch->schid, &sch->schib))
1018 if (!sch->schib.pmcw.dnv)
1021 * The pim, pam, pom values may not be accurate, but they are the best
1022 * we have before performing device selection :/
1024 sch->lpm = sch->schib.pmcw.pam & sch->opm;
1025 /* Re-set some bits in the pmcw that were lost. */
1026 sch->schib.pmcw.isc = 3;
1027 sch->schib.pmcw.csense = 1;
1028 sch->schib.pmcw.ena = 0;
1029 if ((sch->lpm & (sch->lpm - 1)) != 0)
1030 sch->schib.pmcw.mp = 1;
1031 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1032 /* We should also udate ssd info, but this has to wait. */
1033 /* Check if this is another device which appeared on the same sch. */
1034 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
1035 PREPARE_WORK(&cdev->private->kick_work,
1036 ccw_device_move_to_orphanage);
1037 queue_work(slow_path_wq, &cdev->private->kick_work);
1039 ccw_device_start_id(cdev, 0);
1043 ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1045 struct subchannel *sch;
1047 sch = to_subchannel(cdev->dev.parent);
1049 * An interrupt in state offline means a previous disable was not
1050 * successful. Try again.
1052 cio_disable_subchannel(sch);
1056 ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1058 retry_set_schib(cdev);
1059 cdev->private->state = DEV_STATE_ONLINE;
1060 dev_fsm_event(cdev, dev_event);
1063 static void ccw_device_update_cmfblock(struct ccw_device *cdev,
1064 enum dev_event dev_event)
1066 cmf_retry_copy_block(cdev);
1067 cdev->private->state = DEV_STATE_ONLINE;
1068 dev_fsm_event(cdev, dev_event);
1072 ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1074 ccw_device_set_timeout(cdev, 0);
1075 if (dev_event == DEV_EVENT_NOTOPER)
1076 cdev->private->state = DEV_STATE_NOT_OPER;
1078 cdev->private->state = DEV_STATE_OFFLINE;
1079 wake_up(&cdev->private->wait_q);
1083 ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1087 ret = ccw_device_cancel_halt_clear(cdev);
1090 cdev->private->state = DEV_STATE_OFFLINE;
1091 wake_up(&cdev->private->wait_q);
1094 cdev->private->state = DEV_STATE_NOT_OPER;
1095 wake_up(&cdev->private->wait_q);
1098 ccw_device_set_timeout(cdev, HZ/10);
1103 * No operation action. This is used e.g. to ignore a timeout event in
1107 ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1112 * Bug operation action.
1115 ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1117 CIO_MSG_EVENT(0, "dev_jumptable[%i][%i] == NULL\n",
1118 cdev->private->state, dev_event);
1123 * device statemachine
1125 fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1126 [DEV_STATE_NOT_OPER] = {
1127 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1128 [DEV_EVENT_INTERRUPT] = ccw_device_bug,
1129 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1130 [DEV_EVENT_VERIFY] = ccw_device_nop,
1132 [DEV_STATE_SENSE_PGID] = {
1133 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1134 [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
1135 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1136 [DEV_EVENT_VERIFY] = ccw_device_nop,
1138 [DEV_STATE_SENSE_ID] = {
1139 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1140 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1141 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1142 [DEV_EVENT_VERIFY] = ccw_device_nop,
1144 [DEV_STATE_OFFLINE] = {
1145 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1146 [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
1147 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1148 [DEV_EVENT_VERIFY] = ccw_device_nop,
1150 [DEV_STATE_VERIFY] = {
1151 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1152 [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
1153 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1154 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
1156 [DEV_STATE_ONLINE] = {
1157 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1158 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1159 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1160 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1162 [DEV_STATE_W4SENSE] = {
1163 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1164 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1165 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1166 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1168 [DEV_STATE_DISBAND_PGID] = {
1169 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1170 [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
1171 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1172 [DEV_EVENT_VERIFY] = ccw_device_nop,
1174 [DEV_STATE_BOXED] = {
1175 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1176 [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
1177 [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
1178 [DEV_EVENT_VERIFY] = ccw_device_nop,
1180 /* states to wait for i/o completion before doing something */
1181 [DEV_STATE_CLEAR_VERIFY] = {
1182 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1183 [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
1184 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1185 [DEV_EVENT_VERIFY] = ccw_device_nop,
1187 [DEV_STATE_TIMEOUT_KILL] = {
1188 [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper,
1189 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1190 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1191 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1193 [DEV_STATE_QUIESCE] = {
1194 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1195 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1196 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1197 [DEV_EVENT_VERIFY] = ccw_device_nop,
1199 /* special states for devices gone not operational */
1200 [DEV_STATE_DISCONNECTED] = {
1201 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1202 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1203 [DEV_EVENT_TIMEOUT] = ccw_device_bug,
1204 [DEV_EVENT_VERIFY] = ccw_device_start_id,
1206 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1207 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1208 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1209 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1210 [DEV_EVENT_VERIFY] = ccw_device_nop,
1212 [DEV_STATE_CMFCHANGE] = {
1213 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1214 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1215 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1216 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1218 [DEV_STATE_CMFUPDATE] = {
1219 [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
1220 [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
1221 [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
1222 [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
1227 * io_subchannel_irq is called for "real" interrupts or for status
1228 * pending conditions on msch.
1231 io_subchannel_irq (struct device *pdev)
1233 struct ccw_device *cdev;
1235 cdev = to_subchannel(pdev)->dev.driver_data;
1237 CIO_TRACE_EVENT (3, "IRQ");
1238 CIO_TRACE_EVENT (3, pdev->bus_id);
1240 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1243 EXPORT_SYMBOL_GPL(ccw_device_set_timeout);