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/config.h>
13 #include <linux/init.h>
14 #include <linux/jiffies.h>
15 #include <linux/string.h>
17 #include <asm/ccwdev.h>
21 #include "cio_debug.h"
28 device_is_online(struct subchannel
*sch
)
30 struct ccw_device
*cdev
;
32 if (!sch
->dev
.driver_data
)
34 cdev
= sch
->dev
.driver_data
;
35 return (cdev
->private->state
== DEV_STATE_ONLINE
);
39 device_is_disconnected(struct subchannel
*sch
)
41 struct ccw_device
*cdev
;
43 if (!sch
->dev
.driver_data
)
45 cdev
= sch
->dev
.driver_data
;
46 return (cdev
->private->state
== DEV_STATE_DISCONNECTED
||
47 cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
);
51 device_set_disconnected(struct subchannel
*sch
)
53 struct ccw_device
*cdev
;
55 if (!sch
->dev
.driver_data
)
57 cdev
= sch
->dev
.driver_data
;
58 ccw_device_set_timeout(cdev
, 0);
59 cdev
->private->flags
.fake_irb
= 0;
60 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
64 device_set_waiting(struct subchannel
*sch
)
66 struct ccw_device
*cdev
;
68 if (!sch
->dev
.driver_data
)
70 cdev
= sch
->dev
.driver_data
;
71 ccw_device_set_timeout(cdev
, 10*HZ
);
72 cdev
->private->state
= DEV_STATE_WAIT4IO
;
76 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
79 ccw_device_timeout(unsigned long data
)
81 struct ccw_device
*cdev
;
83 cdev
= (struct ccw_device
*) data
;
84 spin_lock_irq(cdev
->ccwlock
);
85 dev_fsm_event(cdev
, DEV_EVENT_TIMEOUT
);
86 spin_unlock_irq(cdev
->ccwlock
);
93 ccw_device_set_timeout(struct ccw_device
*cdev
, int expires
)
96 del_timer(&cdev
->private->timer
);
99 if (timer_pending(&cdev
->private->timer
)) {
100 if (mod_timer(&cdev
->private->timer
, jiffies
+ expires
))
103 cdev
->private->timer
.function
= ccw_device_timeout
;
104 cdev
->private->timer
.data
= (unsigned long) cdev
;
105 cdev
->private->timer
.expires
= jiffies
+ expires
;
106 add_timer(&cdev
->private->timer
);
109 /* Kill any pending timers after machine check. */
111 device_kill_pending_timer(struct subchannel
*sch
)
113 struct ccw_device
*cdev
;
115 if (!sch
->dev
.driver_data
)
117 cdev
= sch
->dev
.driver_data
;
118 ccw_device_set_timeout(cdev
, 0);
122 * Cancel running i/o. This is called repeatedly since halt/clear are
123 * asynchronous operations. We do one try with cio_cancel, two tries
124 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
125 * Returns 0 if device now idle, -ENODEV for device not operational and
126 * -EBUSY if an interrupt is expected (either from halt/clear or from a
130 ccw_device_cancel_halt_clear(struct ccw_device
*cdev
)
132 struct subchannel
*sch
;
135 sch
= to_subchannel(cdev
->dev
.parent
);
136 ret
= stsch(sch
->schid
, &sch
->schib
);
137 if (ret
|| !sch
->schib
.pmcw
.dnv
)
139 if (!sch
->schib
.pmcw
.ena
|| sch
->schib
.scsw
.actl
== 0)
140 /* Not operational or no activity -> done. */
142 /* Stage 1: cancel io. */
143 if (!(sch
->schib
.scsw
.actl
& SCSW_ACTL_HALT_PEND
) &&
144 !(sch
->schib
.scsw
.actl
& SCSW_ACTL_CLEAR_PEND
)) {
145 ret
= cio_cancel(sch
);
148 /* cancel io unsuccessful. From now on it is asynchronous. */
149 cdev
->private->iretry
= 3; /* 3 halt retries. */
151 if (!(sch
->schib
.scsw
.actl
& SCSW_ACTL_CLEAR_PEND
)) {
152 /* Stage 2: halt io. */
153 if (cdev
->private->iretry
) {
154 cdev
->private->iretry
--;
156 return (ret
== 0) ? -EBUSY
: ret
;
158 /* halt io unsuccessful. */
159 cdev
->private->iretry
= 255; /* 255 clear retries. */
161 /* Stage 3: clear io. */
162 if (cdev
->private->iretry
) {
163 cdev
->private->iretry
--;
164 ret
= cio_clear (sch
);
165 return (ret
== 0) ? -EBUSY
: ret
;
167 panic("Can't stop i/o on subchannel.\n");
171 ccw_device_handle_oper(struct ccw_device
*cdev
)
173 struct subchannel
*sch
;
175 sch
= to_subchannel(cdev
->dev
.parent
);
176 cdev
->private->flags
.recog_done
= 1;
178 * Check if cu type and device type still match. If
179 * not, it is certainly another device and we have to
180 * de- and re-register. Also check here for non-matching devno.
182 if (cdev
->id
.cu_type
!= cdev
->private->senseid
.cu_type
||
183 cdev
->id
.cu_model
!= cdev
->private->senseid
.cu_model
||
184 cdev
->id
.dev_type
!= cdev
->private->senseid
.dev_type
||
185 cdev
->id
.dev_model
!= cdev
->private->senseid
.dev_model
||
186 cdev
->private->devno
!= sch
->schib
.pmcw
.dev
) {
187 PREPARE_WORK(&cdev
->private->kick_work
,
188 ccw_device_do_unreg_rereg
, (void *)cdev
);
189 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
192 cdev
->private->flags
.donotify
= 1;
197 * The machine won't give us any notification by machine check if a chpid has
198 * been varied online on the SE so we have to find out by magic (i. e. driving
199 * the channel subsystem to device selection and updating our path masks).
202 __recover_lost_chpids(struct subchannel
*sch
, int old_lpm
)
206 for (i
= 0; i
<8; i
++) {
208 if (!(sch
->lpm
& mask
))
212 chpid_is_actually_online(sch
->schib
.pmcw
.chpid
[i
]);
217 * Stop device recognition.
220 ccw_device_recog_done(struct ccw_device
*cdev
, int state
)
222 struct subchannel
*sch
;
223 int notify
, old_lpm
, same_dev
;
225 sch
= to_subchannel(cdev
->dev
.parent
);
227 ccw_device_set_timeout(cdev
, 0);
228 cio_disable_subchannel(sch
);
230 * Now that we tried recognition, we have performed device selection
231 * through ssch() and the path information is up to date.
234 stsch(sch
->schid
, &sch
->schib
);
235 sch
->lpm
= sch
->schib
.pmcw
.pim
&
236 sch
->schib
.pmcw
.pam
&
237 sch
->schib
.pmcw
.pom
&
239 /* Check since device may again have become not operational. */
240 if (!sch
->schib
.pmcw
.dnv
)
241 state
= DEV_STATE_NOT_OPER
;
242 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
)
243 /* Force reprobe on all chpids. */
245 if (sch
->lpm
!= old_lpm
)
246 __recover_lost_chpids(sch
, old_lpm
);
247 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
248 if (state
== DEV_STATE_NOT_OPER
) {
249 cdev
->private->flags
.recog_done
= 1;
250 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
253 /* Boxed devices don't need extra treatment. */
256 same_dev
= 0; /* Keep the compiler quiet... */
258 case DEV_STATE_NOT_OPER
:
259 CIO_DEBUG(KERN_WARNING
, 2,
260 "SenseID : unknown device %04x on subchannel "
261 "0.%x.%04x\n", cdev
->private->devno
,
262 sch
->schid
.ssid
, sch
->schid
.sch_no
);
264 case DEV_STATE_OFFLINE
:
265 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
266 same_dev
= ccw_device_handle_oper(cdev
);
269 /* fill out sense information */
270 cdev
->id
= (struct ccw_device_id
) {
271 .cu_type
= cdev
->private->senseid
.cu_type
,
272 .cu_model
= cdev
->private->senseid
.cu_model
,
273 .dev_type
= cdev
->private->senseid
.dev_type
,
274 .dev_model
= cdev
->private->senseid
.dev_model
,
277 cdev
->private->state
= DEV_STATE_OFFLINE
;
279 /* Get device online again. */
280 ccw_device_online(cdev
);
281 wake_up(&cdev
->private->wait_q
);
285 /* Issue device info message. */
286 CIO_DEBUG(KERN_INFO
, 2, "SenseID : device 0.%x.%04x reports: "
287 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
289 cdev
->private->ssid
, cdev
->private->devno
,
290 cdev
->id
.cu_type
, cdev
->id
.cu_model
,
291 cdev
->id
.dev_type
, cdev
->id
.dev_model
);
293 case DEV_STATE_BOXED
:
294 CIO_DEBUG(KERN_WARNING
, 2,
295 "SenseID : boxed device %04x on subchannel "
296 "0.%x.%04x\n", cdev
->private->devno
,
297 sch
->schid
.ssid
, sch
->schid
.sch_no
);
300 cdev
->private->state
= state
;
301 io_subchannel_recog_done(cdev
);
302 if (state
!= DEV_STATE_NOT_OPER
)
303 wake_up(&cdev
->private->wait_q
);
307 * Function called from device_id.c after sense id has completed.
310 ccw_device_sense_id_done(struct ccw_device
*cdev
, int err
)
314 ccw_device_recog_done(cdev
, DEV_STATE_OFFLINE
);
316 case -ETIME
: /* Sense id stopped by timeout. */
317 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
320 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
326 ccw_device_oper_notify(void *data
)
328 struct ccw_device
*cdev
;
329 struct subchannel
*sch
;
332 cdev
= (struct ccw_device
*)data
;
333 sch
= to_subchannel(cdev
->dev
.parent
);
334 ret
= (sch
->driver
&& sch
->driver
->notify
) ?
335 sch
->driver
->notify(&sch
->dev
, CIO_OPER
) : 0;
337 /* Driver doesn't want device back. */
338 ccw_device_do_unreg_rereg((void *)cdev
);
340 wake_up(&cdev
->private->wait_q
);
344 * Finished with online/offline processing.
347 ccw_device_done(struct ccw_device
*cdev
, int state
)
349 struct subchannel
*sch
;
351 sch
= to_subchannel(cdev
->dev
.parent
);
353 if (state
!= DEV_STATE_ONLINE
)
354 cio_disable_subchannel(sch
);
356 /* Reset device status. */
357 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
359 cdev
->private->state
= state
;
362 if (state
== DEV_STATE_BOXED
)
363 CIO_DEBUG(KERN_WARNING
, 2,
364 "Boxed device %04x on subchannel %04x\n",
365 cdev
->private->devno
, sch
->schid
.sch_no
);
367 if (cdev
->private->flags
.donotify
) {
368 cdev
->private->flags
.donotify
= 0;
369 PREPARE_WORK(&cdev
->private->kick_work
, ccw_device_oper_notify
,
371 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
373 wake_up(&cdev
->private->wait_q
);
375 if (css_init_done
&& state
!= DEV_STATE_ONLINE
)
376 put_device (&cdev
->dev
);
380 * Function called from device_pgid.c after sense path ground has completed.
383 ccw_device_sense_pgid_done(struct ccw_device
*cdev
, int err
)
385 struct subchannel
*sch
;
387 sch
= to_subchannel(cdev
->dev
.parent
);
390 /* Start Path Group verification. */
391 sch
->vpm
= 0; /* Start with no path groups set. */
392 cdev
->private->state
= DEV_STATE_VERIFY
;
393 ccw_device_verify_start(cdev
);
395 case -ETIME
: /* Sense path group id stopped by timeout. */
396 case -EUSERS
: /* device is reserved for someone else. */
397 ccw_device_done(cdev
, DEV_STATE_BOXED
);
399 case -EOPNOTSUPP
: /* path grouping not supported, just set online. */
400 cdev
->private->options
.pgroup
= 0;
401 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
404 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
410 * Start device recognition.
413 ccw_device_recognition(struct ccw_device
*cdev
)
415 struct subchannel
*sch
;
418 if ((cdev
->private->state
!= DEV_STATE_NOT_OPER
) &&
419 (cdev
->private->state
!= DEV_STATE_BOXED
))
421 sch
= to_subchannel(cdev
->dev
.parent
);
422 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
424 /* Couldn't enable the subchannel for i/o. Sick device. */
427 /* After 60s the device recognition is considered to have failed. */
428 ccw_device_set_timeout(cdev
, 60*HZ
);
431 * We used to start here with a sense pgid to find out whether a device
432 * is locked by someone else. Unfortunately, the sense pgid command
433 * code has other meanings on devices predating the path grouping
434 * algorithm, so we start with sense id and box the device after an
435 * timeout (or if sense pgid during path verification detects the device
436 * is locked, as may happen on newer devices).
438 cdev
->private->flags
.recog_done
= 0;
439 cdev
->private->state
= DEV_STATE_SENSE_ID
;
440 ccw_device_sense_id_start(cdev
);
445 * Handle timeout in device recognition.
448 ccw_device_recog_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
452 ret
= ccw_device_cancel_halt_clear(cdev
);
455 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
458 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
461 ccw_device_set_timeout(cdev
, 3*HZ
);
467 ccw_device_nopath_notify(void *data
)
469 struct ccw_device
*cdev
;
470 struct subchannel
*sch
;
473 cdev
= (struct ccw_device
*)data
;
474 sch
= to_subchannel(cdev
->dev
.parent
);
478 ret
= (sch
->driver
&& sch
->driver
->notify
) ?
479 sch
->driver
->notify(&sch
->dev
, CIO_NO_PATH
) : 0;
481 if (get_device(&sch
->dev
)) {
482 /* Driver doesn't want to keep device. */
483 cio_disable_subchannel(sch
);
484 if (get_device(&cdev
->dev
)) {
485 PREPARE_WORK(&cdev
->private->kick_work
,
486 ccw_device_call_sch_unregister
,
488 queue_work(ccw_device_work
,
489 &cdev
->private->kick_work
);
491 put_device(&sch
->dev
);
494 cio_disable_subchannel(sch
);
495 ccw_device_set_timeout(cdev
, 0);
496 cdev
->private->flags
.fake_irb
= 0;
497 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
498 wake_up(&cdev
->private->wait_q
);
503 ccw_device_verify_done(struct ccw_device
*cdev
, int err
)
505 cdev
->private->flags
.doverify
= 0;
507 case -EOPNOTSUPP
: /* path grouping not supported, just set online. */
508 cdev
->private->options
.pgroup
= 0;
510 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
511 /* Deliver fake irb to device driver, if needed. */
512 if (cdev
->private->flags
.fake_irb
) {
513 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
514 cdev
->private->irb
.scsw
= (struct scsw
) {
516 .fctl
= SCSW_FCTL_START_FUNC
,
517 .actl
= SCSW_ACTL_START_PEND
,
518 .stctl
= SCSW_STCTL_STATUS_PEND
,
520 cdev
->private->flags
.fake_irb
= 0;
522 cdev
->handler(cdev
, cdev
->private->intparm
,
523 &cdev
->private->irb
);
524 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
528 ccw_device_done(cdev
, DEV_STATE_BOXED
);
531 PREPARE_WORK(&cdev
->private->kick_work
,
532 ccw_device_nopath_notify
, (void *)cdev
);
533 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
534 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
543 ccw_device_online(struct ccw_device
*cdev
)
545 struct subchannel
*sch
;
548 if ((cdev
->private->state
!= DEV_STATE_OFFLINE
) &&
549 (cdev
->private->state
!= DEV_STATE_BOXED
))
551 sch
= to_subchannel(cdev
->dev
.parent
);
552 if (css_init_done
&& !get_device(&cdev
->dev
))
554 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
556 /* Couldn't enable the subchannel for i/o. Sick device. */
558 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
561 /* Do we want to do path grouping? */
562 if (!cdev
->private->options
.pgroup
) {
563 /* No, set state online immediately. */
564 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
567 /* Do a SensePGID first. */
568 cdev
->private->state
= DEV_STATE_SENSE_PGID
;
569 ccw_device_sense_pgid_start(cdev
);
574 ccw_device_disband_done(struct ccw_device
*cdev
, int err
)
578 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
581 ccw_device_done(cdev
, DEV_STATE_BOXED
);
584 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
593 ccw_device_offline(struct ccw_device
*cdev
)
595 struct subchannel
*sch
;
597 sch
= to_subchannel(cdev
->dev
.parent
);
598 if (stsch(sch
->schid
, &sch
->schib
) || !sch
->schib
.pmcw
.dnv
)
600 if (cdev
->private->state
!= DEV_STATE_ONLINE
) {
601 if (sch
->schib
.scsw
.actl
!= 0)
605 if (sch
->schib
.scsw
.actl
!= 0)
607 /* Are we doing path grouping? */
608 if (!cdev
->private->options
.pgroup
) {
609 /* No, set state offline immediately. */
610 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
613 /* Start Set Path Group commands. */
614 cdev
->private->state
= DEV_STATE_DISBAND_PGID
;
615 ccw_device_disband_start(cdev
);
620 * Handle timeout in device online/offline process.
623 ccw_device_onoff_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
627 ret
= ccw_device_cancel_halt_clear(cdev
);
630 ccw_device_done(cdev
, DEV_STATE_BOXED
);
633 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
636 ccw_device_set_timeout(cdev
, 3*HZ
);
641 * Handle not oper event in device recognition.
644 ccw_device_recog_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
646 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
650 * Handle not operational event while offline.
653 ccw_device_offline_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
655 struct subchannel
*sch
;
657 cdev
->private->state
= DEV_STATE_NOT_OPER
;
658 sch
= to_subchannel(cdev
->dev
.parent
);
659 if (get_device(&cdev
->dev
)) {
660 PREPARE_WORK(&cdev
->private->kick_work
,
661 ccw_device_call_sch_unregister
, (void *)cdev
);
662 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
664 wake_up(&cdev
->private->wait_q
);
668 * Handle not operational event while online.
671 ccw_device_online_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
673 struct subchannel
*sch
;
675 sch
= to_subchannel(cdev
->dev
.parent
);
676 if (sch
->driver
->notify
&&
677 sch
->driver
->notify(&sch
->dev
, sch
->lpm
? CIO_GONE
: CIO_NO_PATH
)) {
678 ccw_device_set_timeout(cdev
, 0);
679 cdev
->private->flags
.fake_irb
= 0;
680 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
681 wake_up(&cdev
->private->wait_q
);
684 cdev
->private->state
= DEV_STATE_NOT_OPER
;
685 cio_disable_subchannel(sch
);
686 if (sch
->schib
.scsw
.actl
!= 0) {
687 // FIXME: not-oper indication to device driver ?
688 ccw_device_call_handler(cdev
);
690 if (get_device(&cdev
->dev
)) {
691 PREPARE_WORK(&cdev
->private->kick_work
,
692 ccw_device_call_sch_unregister
, (void *)cdev
);
693 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
695 wake_up(&cdev
->private->wait_q
);
699 * Handle path verification event.
702 ccw_device_online_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
704 struct subchannel
*sch
;
706 if (!cdev
->private->options
.pgroup
)
708 if (cdev
->private->state
== DEV_STATE_W4SENSE
) {
709 cdev
->private->flags
.doverify
= 1;
712 sch
= to_subchannel(cdev
->dev
.parent
);
714 * Since we might not just be coming from an interrupt from the
715 * subchannel we have to update the schib.
717 stsch(sch
->schid
, &sch
->schib
);
719 if (sch
->schib
.scsw
.actl
!= 0 ||
720 (cdev
->private->irb
.scsw
.stctl
& SCSW_STCTL_STATUS_PEND
)) {
722 * No final status yet or final status not yet delivered
723 * to the device driver. Can't do path verfication now,
724 * delay until final status was delivered.
726 cdev
->private->flags
.doverify
= 1;
729 /* Device is idle, we can do the path verification. */
730 cdev
->private->state
= DEV_STATE_VERIFY
;
731 ccw_device_verify_start(cdev
);
735 * Got an interrupt for a normal io (state online).
738 ccw_device_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
742 irb
= (struct irb
*) __LC_IRB
;
743 /* Check for unsolicited interrupt. */
744 if ((irb
->scsw
.stctl
==
745 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
))
746 && (!irb
->scsw
.cc
)) {
747 if ((irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) &&
748 !irb
->esw
.esw0
.erw
.cons
) {
749 /* Unit check but no sense data. Need basic sense. */
750 if (ccw_device_do_sense(cdev
, irb
) != 0)
751 goto call_handler_unsol
;
752 memcpy(&cdev
->private->irb
, irb
, sizeof(struct irb
));
753 cdev
->private->state
= DEV_STATE_W4SENSE
;
754 cdev
->private->intparm
= 0;
759 cdev
->handler (cdev
, 0, irb
);
762 /* Accumulate status and find out if a basic sense is needed. */
763 ccw_device_accumulate_irb(cdev
, irb
);
764 if (cdev
->private->flags
.dosense
) {
765 if (ccw_device_do_sense(cdev
, irb
) == 0) {
766 cdev
->private->state
= DEV_STATE_W4SENSE
;
770 /* Call the handler. */
771 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
772 /* Start delayed path verification. */
773 ccw_device_online_verify(cdev
, 0);
777 * Got an timeout in online state.
780 ccw_device_online_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
784 ccw_device_set_timeout(cdev
, 0);
785 ret
= ccw_device_cancel_halt_clear(cdev
);
787 ccw_device_set_timeout(cdev
, 3*HZ
);
788 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
791 if (ret
== -ENODEV
) {
792 struct subchannel
*sch
;
794 sch
= to_subchannel(cdev
->dev
.parent
);
796 PREPARE_WORK(&cdev
->private->kick_work
,
797 ccw_device_nopath_notify
, (void *)cdev
);
798 queue_work(ccw_device_notify_work
,
799 &cdev
->private->kick_work
);
801 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
802 } else if (cdev
->handler
)
803 cdev
->handler(cdev
, cdev
->private->intparm
,
804 ERR_PTR(-ETIMEDOUT
));
808 * Got an interrupt for a basic sense.
811 ccw_device_w4sense(struct ccw_device
*cdev
, enum dev_event dev_event
)
815 irb
= (struct irb
*) __LC_IRB
;
816 /* Check for unsolicited interrupt. */
817 if (irb
->scsw
.stctl
==
818 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
819 if (irb
->scsw
.cc
== 1)
820 /* Basic sense hasn't started. Try again. */
821 ccw_device_do_sense(cdev
, irb
);
823 printk("Huh? %s(%s): unsolicited interrupt...\n",
824 __FUNCTION__
, cdev
->dev
.bus_id
);
826 cdev
->handler (cdev
, 0, irb
);
831 * Check if a halt or clear has been issued in the meanwhile. If yes,
832 * only deliver the halt/clear interrupt to the device driver as if it
833 * had killed the original request.
835 if (irb
->scsw
.fctl
& (SCSW_FCTL_CLEAR_FUNC
| SCSW_FCTL_HALT_FUNC
)) {
836 cdev
->private->flags
.dosense
= 0;
837 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
838 ccw_device_accumulate_irb(cdev
, irb
);
841 /* Add basic sense info to irb. */
842 ccw_device_accumulate_basic_sense(cdev
, irb
);
843 if (cdev
->private->flags
.dosense
) {
844 /* Another basic sense is needed. */
845 ccw_device_do_sense(cdev
, irb
);
849 cdev
->private->state
= DEV_STATE_ONLINE
;
850 /* Call the handler. */
851 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
852 /* Start delayed path verification. */
853 ccw_device_online_verify(cdev
, 0);
857 ccw_device_clear_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
861 irb
= (struct irb
*) __LC_IRB
;
862 /* Accumulate status. We don't do basic sense. */
863 ccw_device_accumulate_irb(cdev
, irb
);
864 /* Try to start delayed device verification. */
865 ccw_device_online_verify(cdev
, 0);
866 /* Note: Don't call handler for cio initiated clear! */
870 ccw_device_killing_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
872 struct subchannel
*sch
;
874 sch
= to_subchannel(cdev
->dev
.parent
);
875 ccw_device_set_timeout(cdev
, 0);
876 /* OK, i/o is dead now. Call interrupt handler. */
877 cdev
->private->state
= DEV_STATE_ONLINE
;
879 cdev
->handler(cdev
, cdev
->private->intparm
,
880 ERR_PTR(-ETIMEDOUT
));
882 PREPARE_WORK(&cdev
->private->kick_work
,
883 ccw_device_nopath_notify
, (void *)cdev
);
884 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
885 } else if (cdev
->private->flags
.doverify
)
886 /* Start delayed path verification. */
887 ccw_device_online_verify(cdev
, 0);
891 ccw_device_killing_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
895 ret
= ccw_device_cancel_halt_clear(cdev
);
897 ccw_device_set_timeout(cdev
, 3*HZ
);
900 if (ret
== -ENODEV
) {
901 struct subchannel
*sch
;
903 sch
= to_subchannel(cdev
->dev
.parent
);
905 PREPARE_WORK(&cdev
->private->kick_work
,
906 ccw_device_nopath_notify
, (void *)cdev
);
907 queue_work(ccw_device_notify_work
,
908 &cdev
->private->kick_work
);
910 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
913 //FIXME: Can we get here?
914 cdev
->private->state
= DEV_STATE_ONLINE
;
916 cdev
->handler(cdev
, cdev
->private->intparm
,
917 ERR_PTR(-ETIMEDOUT
));
921 ccw_device_wait4io_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
924 struct subchannel
*sch
;
926 irb
= (struct irb
*) __LC_IRB
;
928 * Accumulate status and find out if a basic sense is needed.
929 * This is fine since we have already adapted the lpm.
931 ccw_device_accumulate_irb(cdev
, irb
);
932 if (cdev
->private->flags
.dosense
) {
933 if (ccw_device_do_sense(cdev
, irb
) == 0) {
934 cdev
->private->state
= DEV_STATE_W4SENSE
;
939 /* Iff device is idle, reset timeout. */
940 sch
= to_subchannel(cdev
->dev
.parent
);
941 if (!stsch(sch
->schid
, &sch
->schib
))
942 if (sch
->schib
.scsw
.actl
== 0)
943 ccw_device_set_timeout(cdev
, 0);
944 /* Call the handler. */
945 ccw_device_call_handler(cdev
);
947 PREPARE_WORK(&cdev
->private->kick_work
,
948 ccw_device_nopath_notify
, (void *)cdev
);
949 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
950 } else if (cdev
->private->flags
.doverify
)
951 ccw_device_online_verify(cdev
, 0);
955 ccw_device_wait4io_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
958 struct subchannel
*sch
;
960 sch
= to_subchannel(cdev
->dev
.parent
);
961 ccw_device_set_timeout(cdev
, 0);
962 ret
= ccw_device_cancel_halt_clear(cdev
);
964 ccw_device_set_timeout(cdev
, 3*HZ
);
965 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
968 if (ret
== -ENODEV
) {
970 PREPARE_WORK(&cdev
->private->kick_work
,
971 ccw_device_nopath_notify
, (void *)cdev
);
972 queue_work(ccw_device_notify_work
,
973 &cdev
->private->kick_work
);
975 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
979 cdev
->handler(cdev
, cdev
->private->intparm
,
980 ERR_PTR(-ETIMEDOUT
));
982 PREPARE_WORK(&cdev
->private->kick_work
,
983 ccw_device_nopath_notify
, (void *)cdev
);
984 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
985 } else if (cdev
->private->flags
.doverify
)
986 /* Start delayed path verification. */
987 ccw_device_online_verify(cdev
, 0);
991 ccw_device_wait4io_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
993 /* When the I/O has terminated, we have to start verification. */
994 if (cdev
->private->options
.pgroup
)
995 cdev
->private->flags
.doverify
= 1;
999 ccw_device_stlck_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
1003 switch (dev_event
) {
1004 case DEV_EVENT_INTERRUPT
:
1005 irb
= (struct irb
*) __LC_IRB
;
1006 /* Check for unsolicited interrupt. */
1007 if ((irb
->scsw
.stctl
==
1008 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) &&
1010 /* FIXME: we should restart stlck here, but this
1011 * is extremely unlikely ... */
1014 ccw_device_accumulate_irb(cdev
, irb
);
1015 /* We don't care about basic sense etc. */
1017 default: /* timeout */
1021 wake_up(&cdev
->private->wait_q
);
1025 ccw_device_start_id(struct ccw_device
*cdev
, enum dev_event dev_event
)
1027 struct subchannel
*sch
;
1029 sch
= to_subchannel(cdev
->dev
.parent
);
1030 if (cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
) != 0)
1031 /* Couldn't enable the subchannel for i/o. Sick device. */
1034 /* After 60s the device recognition is considered to have failed. */
1035 ccw_device_set_timeout(cdev
, 60*HZ
);
1037 cdev
->private->state
= DEV_STATE_DISCONNECTED_SENSE_ID
;
1038 ccw_device_sense_id_start(cdev
);
1042 device_trigger_reprobe(struct subchannel
*sch
)
1044 struct ccw_device
*cdev
;
1046 if (!sch
->dev
.driver_data
)
1048 cdev
= sch
->dev
.driver_data
;
1049 if (cdev
->private->state
!= DEV_STATE_DISCONNECTED
)
1052 /* Update some values. */
1053 if (stsch(sch
->schid
, &sch
->schib
))
1057 * The pim, pam, pom values may not be accurate, but they are the best
1058 * we have before performing device selection :/
1060 sch
->lpm
= sch
->schib
.pmcw
.pim
&
1061 sch
->schib
.pmcw
.pam
&
1062 sch
->schib
.pmcw
.pom
&
1064 /* Re-set some bits in the pmcw that were lost. */
1065 sch
->schib
.pmcw
.isc
= 3;
1066 sch
->schib
.pmcw
.csense
= 1;
1067 sch
->schib
.pmcw
.ena
= 0;
1068 if ((sch
->lpm
& (sch
->lpm
- 1)) != 0)
1069 sch
->schib
.pmcw
.mp
= 1;
1070 sch
->schib
.pmcw
.intparm
= (__u32
)(unsigned long)sch
;
1071 /* We should also udate ssd info, but this has to wait. */
1072 ccw_device_start_id(cdev
, 0);
1076 ccw_device_offline_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
1078 struct subchannel
*sch
;
1080 sch
= to_subchannel(cdev
->dev
.parent
);
1082 * An interrupt in state offline means a previous disable was not
1083 * successful. Try again.
1085 cio_disable_subchannel(sch
);
1089 ccw_device_change_cmfstate(struct ccw_device
*cdev
, enum dev_event dev_event
)
1091 retry_set_schib(cdev
);
1092 cdev
->private->state
= DEV_STATE_ONLINE
;
1093 dev_fsm_event(cdev
, dev_event
);
1098 ccw_device_quiesce_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
1100 ccw_device_set_timeout(cdev
, 0);
1101 if (dev_event
== DEV_EVENT_NOTOPER
)
1102 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1104 cdev
->private->state
= DEV_STATE_OFFLINE
;
1105 wake_up(&cdev
->private->wait_q
);
1109 ccw_device_quiesce_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
1113 ret
= ccw_device_cancel_halt_clear(cdev
);
1116 cdev
->private->state
= DEV_STATE_OFFLINE
;
1117 wake_up(&cdev
->private->wait_q
);
1120 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1121 wake_up(&cdev
->private->wait_q
);
1124 ccw_device_set_timeout(cdev
, HZ
/10);
1129 * No operation action. This is used e.g. to ignore a timeout event in
1133 ccw_device_nop(struct ccw_device
*cdev
, enum dev_event dev_event
)
1138 * Bug operation action.
1141 ccw_device_bug(struct ccw_device
*cdev
, enum dev_event dev_event
)
1143 printk(KERN_EMERG
"dev_jumptable[%i][%i] == NULL\n",
1144 cdev
->private->state
, dev_event
);
1149 * device statemachine
1151 fsm_func_t
*dev_jumptable
[NR_DEV_STATES
][NR_DEV_EVENTS
] = {
1152 [DEV_STATE_NOT_OPER
] = {
1153 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1154 [DEV_EVENT_INTERRUPT
] = ccw_device_bug
,
1155 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1156 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1158 [DEV_STATE_SENSE_PGID
] = {
1159 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1160 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_pgid_irq
,
1161 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1162 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1164 [DEV_STATE_SENSE_ID
] = {
1165 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1166 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1167 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1168 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1170 [DEV_STATE_OFFLINE
] = {
1171 [DEV_EVENT_NOTOPER
] = ccw_device_offline_notoper
,
1172 [DEV_EVENT_INTERRUPT
] = ccw_device_offline_irq
,
1173 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1174 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1176 [DEV_STATE_VERIFY
] = {
1177 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1178 [DEV_EVENT_INTERRUPT
] = ccw_device_verify_irq
,
1179 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1180 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1182 [DEV_STATE_ONLINE
] = {
1183 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1184 [DEV_EVENT_INTERRUPT
] = ccw_device_irq
,
1185 [DEV_EVENT_TIMEOUT
] = ccw_device_online_timeout
,
1186 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1188 [DEV_STATE_W4SENSE
] = {
1189 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1190 [DEV_EVENT_INTERRUPT
] = ccw_device_w4sense
,
1191 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1192 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1194 [DEV_STATE_DISBAND_PGID
] = {
1195 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1196 [DEV_EVENT_INTERRUPT
] = ccw_device_disband_irq
,
1197 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1198 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1200 [DEV_STATE_BOXED
] = {
1201 [DEV_EVENT_NOTOPER
] = ccw_device_offline_notoper
,
1202 [DEV_EVENT_INTERRUPT
] = ccw_device_stlck_done
,
1203 [DEV_EVENT_TIMEOUT
] = ccw_device_stlck_done
,
1204 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1206 /* states to wait for i/o completion before doing something */
1207 [DEV_STATE_CLEAR_VERIFY
] = {
1208 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1209 [DEV_EVENT_INTERRUPT
] = ccw_device_clear_verify
,
1210 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1211 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1213 [DEV_STATE_TIMEOUT_KILL
] = {
1214 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1215 [DEV_EVENT_INTERRUPT
] = ccw_device_killing_irq
,
1216 [DEV_EVENT_TIMEOUT
] = ccw_device_killing_timeout
,
1217 [DEV_EVENT_VERIFY
] = ccw_device_nop
, //FIXME
1219 [DEV_STATE_WAIT4IO
] = {
1220 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1221 [DEV_EVENT_INTERRUPT
] = ccw_device_wait4io_irq
,
1222 [DEV_EVENT_TIMEOUT
] = ccw_device_wait4io_timeout
,
1223 [DEV_EVENT_VERIFY
] = ccw_device_wait4io_verify
,
1225 [DEV_STATE_QUIESCE
] = {
1226 [DEV_EVENT_NOTOPER
] = ccw_device_quiesce_done
,
1227 [DEV_EVENT_INTERRUPT
] = ccw_device_quiesce_done
,
1228 [DEV_EVENT_TIMEOUT
] = ccw_device_quiesce_timeout
,
1229 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1231 /* special states for devices gone not operational */
1232 [DEV_STATE_DISCONNECTED
] = {
1233 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1234 [DEV_EVENT_INTERRUPT
] = ccw_device_start_id
,
1235 [DEV_EVENT_TIMEOUT
] = ccw_device_bug
,
1236 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1238 [DEV_STATE_DISCONNECTED_SENSE_ID
] = {
1239 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1240 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1241 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1242 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1244 [DEV_STATE_CMFCHANGE
] = {
1245 [DEV_EVENT_NOTOPER
] = ccw_device_change_cmfstate
,
1246 [DEV_EVENT_INTERRUPT
] = ccw_device_change_cmfstate
,
1247 [DEV_EVENT_TIMEOUT
] = ccw_device_change_cmfstate
,
1248 [DEV_EVENT_VERIFY
] = ccw_device_change_cmfstate
,
1253 * io_subchannel_irq is called for "real" interrupts or for status
1254 * pending conditions on msch.
1257 io_subchannel_irq (struct device
*pdev
)
1259 struct ccw_device
*cdev
;
1261 cdev
= to_subchannel(pdev
)->dev
.driver_data
;
1263 CIO_TRACE_EVENT (3, "IRQ");
1264 CIO_TRACE_EVENT (3, pdev
->bus_id
);
1266 dev_fsm_event(cdev
, DEV_EVENT_INTERRUPT
);
1269 EXPORT_SYMBOL_GPL(ccw_device_set_timeout
);