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_err(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 /* Function was unsuccessful */
178 CIO_MSG_EVENT(0, "0.%x.%04x: could not stop I/O\n",
179 cdev
->private->dev_id
.ssid
, cdev
->private->dev_id
.devno
);
183 void ccw_device_update_sense_data(struct ccw_device
*cdev
)
185 memset(&cdev
->id
, 0, sizeof(cdev
->id
));
186 cdev
->id
.cu_type
= cdev
->private->senseid
.cu_type
;
187 cdev
->id
.cu_model
= cdev
->private->senseid
.cu_model
;
188 cdev
->id
.dev_type
= cdev
->private->senseid
.dev_type
;
189 cdev
->id
.dev_model
= cdev
->private->senseid
.dev_model
;
192 int ccw_device_test_sense_data(struct ccw_device
*cdev
)
194 return cdev
->id
.cu_type
== cdev
->private->senseid
.cu_type
&&
195 cdev
->id
.cu_model
== cdev
->private->senseid
.cu_model
&&
196 cdev
->id
.dev_type
== cdev
->private->senseid
.dev_type
&&
197 cdev
->id
.dev_model
== cdev
->private->senseid
.dev_model
;
201 * The machine won't give us any notification by machine check if a chpid has
202 * been varied online on the SE so we have to find out by magic (i. e. driving
203 * the channel subsystem to device selection and updating our path masks).
206 __recover_lost_chpids(struct subchannel
*sch
, int old_lpm
)
212 for (i
= 0; i
<8; i
++) {
214 if (!(sch
->lpm
& mask
))
218 chpid
.id
= sch
->schib
.pmcw
.chpid
[i
];
219 if (!chp_is_registered(chpid
))
220 css_schedule_eval_all();
225 * Stop device recognition.
228 ccw_device_recog_done(struct ccw_device
*cdev
, int state
)
230 struct subchannel
*sch
;
233 sch
= to_subchannel(cdev
->dev
.parent
);
235 if (cio_disable_subchannel(sch
))
236 state
= DEV_STATE_NOT_OPER
;
238 * Now that we tried recognition, we have performed device selection
239 * through ssch() and the path information is up to date.
243 /* Check since device may again have become not operational. */
244 if (cio_update_schib(sch
))
245 state
= DEV_STATE_NOT_OPER
;
247 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
249 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
)
250 /* Force reprobe on all chpids. */
252 if (sch
->lpm
!= old_lpm
)
253 __recover_lost_chpids(sch
, old_lpm
);
254 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
&&
255 (state
== DEV_STATE_NOT_OPER
|| state
== DEV_STATE_BOXED
)) {
256 cdev
->private->flags
.recog_done
= 1;
257 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
258 wake_up(&cdev
->private->wait_q
);
261 if (cdev
->private->flags
.resuming
) {
262 cdev
->private->state
= state
;
263 cdev
->private->flags
.recog_done
= 1;
264 wake_up(&cdev
->private->wait_q
);
268 case DEV_STATE_NOT_OPER
:
270 case DEV_STATE_OFFLINE
:
272 ccw_device_update_sense_data(cdev
);
275 cdev
->private->state
= DEV_STATE_OFFLINE
;
276 cdev
->private->flags
.recog_done
= 1;
277 if (ccw_device_test_sense_data(cdev
)) {
278 cdev
->private->flags
.donotify
= 1;
279 ccw_device_online(cdev
);
280 wake_up(&cdev
->private->wait_q
);
282 ccw_device_update_sense_data(cdev
);
283 ccw_device_sched_todo(cdev
, CDEV_TODO_REBIND
);
286 case DEV_STATE_BOXED
:
287 if (cdev
->id
.cu_type
!= 0) { /* device was recognized before */
288 cdev
->private->flags
.recog_done
= 1;
289 cdev
->private->state
= DEV_STATE_BOXED
;
290 wake_up(&cdev
->private->wait_q
);
295 cdev
->private->state
= state
;
296 io_subchannel_recog_done(cdev
);
297 wake_up(&cdev
->private->wait_q
);
301 * Function called from device_id.c after sense id has completed.
304 ccw_device_sense_id_done(struct ccw_device
*cdev
, int err
)
308 ccw_device_recog_done(cdev
, DEV_STATE_OFFLINE
);
310 case -ETIME
: /* Sense id stopped by timeout. */
311 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
314 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
320 * ccw_device_notify() - inform the device's driver about an event
321 * @cdev: device for which an event occurred
322 * @event: event that occurred
325 * -%EINVAL if the device is offline or has no driver.
326 * -%EOPNOTSUPP if the device's driver has no notifier registered.
327 * %NOTIFY_OK if the driver wants to keep the device.
328 * %NOTIFY_BAD if the driver doesn't want to keep the device.
330 int ccw_device_notify(struct ccw_device
*cdev
, int event
)
338 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
339 cdev
->private->dev_id
.ssid
, cdev
->private->dev_id
.devno
,
341 if (!cdev
->drv
->notify
) {
345 if (cdev
->drv
->notify(cdev
, event
))
353 static void ccw_device_oper_notify(struct ccw_device
*cdev
)
355 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
357 if (ccw_device_notify(cdev
, CIO_OPER
) == NOTIFY_OK
) {
358 /* Reenable channel measurements, if needed. */
359 ccw_device_sched_todo(cdev
, CDEV_TODO_ENABLE_CMF
);
360 /* Save indication for new paths. */
361 cdev
->private->path_new_mask
= sch
->vpm
;
364 /* Driver doesn't want device back. */
365 ccw_device_set_notoper(cdev
);
366 ccw_device_sched_todo(cdev
, CDEV_TODO_REBIND
);
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 case DEV_STATE_BOXED
:
391 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
392 cdev
->private->dev_id
.devno
, sch
->schid
.sch_no
);
394 ccw_device_notify(cdev
, CIO_BOXED
) != NOTIFY_OK
)
395 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
396 cdev
->private->flags
.donotify
= 0;
398 case DEV_STATE_NOT_OPER
:
399 CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n",
400 cdev
->private->dev_id
.devno
, sch
->schid
.sch_no
);
401 if (ccw_device_notify(cdev
, CIO_GONE
) != NOTIFY_OK
)
402 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
404 ccw_device_set_disconnected(cdev
);
405 cdev
->private->flags
.donotify
= 0;
407 case DEV_STATE_DISCONNECTED
:
408 CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel "
409 "%04x\n", cdev
->private->dev_id
.devno
,
411 if (ccw_device_notify(cdev
, CIO_NO_PATH
) != NOTIFY_OK
) {
412 cdev
->private->state
= DEV_STATE_NOT_OPER
;
413 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
415 ccw_device_set_disconnected(cdev
);
416 cdev
->private->flags
.donotify
= 0;
422 if (cdev
->private->flags
.donotify
) {
423 cdev
->private->flags
.donotify
= 0;
424 ccw_device_oper_notify(cdev
);
426 wake_up(&cdev
->private->wait_q
);
430 * Start device recognition.
432 void ccw_device_recognition(struct ccw_device
*cdev
)
434 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
437 * We used to start here with a sense pgid to find out whether a device
438 * is locked by someone else. Unfortunately, the sense pgid command
439 * code has other meanings on devices predating the path grouping
440 * algorithm, so we start with sense id and box the device after an
441 * timeout (or if sense pgid during path verification detects the device
442 * is locked, as may happen on newer devices).
444 cdev
->private->flags
.recog_done
= 0;
445 cdev
->private->state
= DEV_STATE_SENSE_ID
;
446 if (cio_enable_subchannel(sch
, (u32
) (addr_t
) sch
)) {
447 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
450 ccw_device_sense_id_start(cdev
);
454 * Handle events for states that use the ccw request infrastructure.
456 static void ccw_device_request_event(struct ccw_device
*cdev
, enum dev_event e
)
459 case DEV_EVENT_NOTOPER
:
460 ccw_request_notoper(cdev
);
462 case DEV_EVENT_INTERRUPT
:
463 ccw_request_handler(cdev
);
465 case DEV_EVENT_TIMEOUT
:
466 ccw_request_timeout(cdev
);
473 static void ccw_device_report_path_events(struct ccw_device
*cdev
)
475 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
479 for (chp
= 0, mask
= 0x80; chp
< 8; chp
++, mask
>>= 1) {
480 path_event
[chp
] = PE_NONE
;
481 if (mask
& cdev
->private->path_gone_mask
& ~(sch
->vpm
))
482 path_event
[chp
] |= PE_PATH_GONE
;
483 if (mask
& cdev
->private->path_new_mask
& sch
->vpm
)
484 path_event
[chp
] |= PE_PATH_AVAILABLE
;
485 if (mask
& cdev
->private->pgid_reset_mask
& sch
->vpm
)
486 path_event
[chp
] |= PE_PATHGROUP_ESTABLISHED
;
488 if (cdev
->online
&& cdev
->drv
->path_event
)
489 cdev
->drv
->path_event(cdev
, path_event
);
492 static void ccw_device_reset_path_events(struct ccw_device
*cdev
)
494 cdev
->private->path_gone_mask
= 0;
495 cdev
->private->path_new_mask
= 0;
496 cdev
->private->pgid_reset_mask
= 0;
499 static void create_fake_irb(struct irb
*irb
, int type
)
501 memset(irb
, 0, sizeof(*irb
));
502 if (type
== FAKE_CMD_IRB
) {
503 struct cmd_scsw
*scsw
= &irb
->scsw
.cmd
;
505 scsw
->fctl
= SCSW_FCTL_START_FUNC
;
506 scsw
->actl
= SCSW_ACTL_START_PEND
;
507 scsw
->stctl
= SCSW_STCTL_STATUS_PEND
;
508 } else if (type
== FAKE_TM_IRB
) {
509 struct tm_scsw
*scsw
= &irb
->scsw
.tm
;
512 scsw
->fctl
= SCSW_FCTL_START_FUNC
;
513 scsw
->actl
= SCSW_ACTL_START_PEND
;
514 scsw
->stctl
= SCSW_STCTL_STATUS_PEND
;
518 void ccw_device_verify_done(struct ccw_device
*cdev
, int err
)
520 struct subchannel
*sch
;
522 sch
= to_subchannel(cdev
->dev
.parent
);
523 /* Update schib - pom may have changed. */
524 if (cio_update_schib(sch
)) {
528 /* Update lpm with verified path mask. */
530 /* Repeat path verification? */
531 if (cdev
->private->flags
.doverify
) {
532 ccw_device_verify_start(cdev
);
538 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
539 /* Deliver fake irb to device driver, if needed. */
540 if (cdev
->private->flags
.fake_irb
) {
541 create_fake_irb(&cdev
->private->irb
,
542 cdev
->private->flags
.fake_irb
);
543 cdev
->private->flags
.fake_irb
= 0;
545 cdev
->handler(cdev
, cdev
->private->intparm
,
546 &cdev
->private->irb
);
547 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
549 ccw_device_report_path_events(cdev
);
553 /* Reset oper notify indication after verify error. */
554 cdev
->private->flags
.donotify
= 0;
555 ccw_device_done(cdev
, DEV_STATE_BOXED
);
558 /* Reset oper notify indication after verify error. */
559 cdev
->private->flags
.donotify
= 0;
560 ccw_device_done(cdev
, DEV_STATE_DISCONNECTED
);
563 /* Reset oper notify indication after verify error. */
564 cdev
->private->flags
.donotify
= 0;
565 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
568 ccw_device_reset_path_events(cdev
);
575 ccw_device_online(struct ccw_device
*cdev
)
577 struct subchannel
*sch
;
580 if ((cdev
->private->state
!= DEV_STATE_OFFLINE
) &&
581 (cdev
->private->state
!= DEV_STATE_BOXED
))
583 sch
= to_subchannel(cdev
->dev
.parent
);
584 ret
= cio_enable_subchannel(sch
, (u32
)(addr_t
)sch
);
586 /* Couldn't enable the subchannel for i/o. Sick device. */
588 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
591 /* Start initial path verification. */
592 cdev
->private->state
= DEV_STATE_VERIFY
;
593 ccw_device_verify_start(cdev
);
598 ccw_device_disband_done(struct ccw_device
*cdev
, int err
)
602 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
605 ccw_device_done(cdev
, DEV_STATE_BOXED
);
608 cdev
->private->flags
.donotify
= 0;
609 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
618 ccw_device_offline(struct ccw_device
*cdev
)
620 struct subchannel
*sch
;
622 /* Allow ccw_device_offline while disconnected. */
623 if (cdev
->private->state
== DEV_STATE_DISCONNECTED
||
624 cdev
->private->state
== DEV_STATE_NOT_OPER
) {
625 cdev
->private->flags
.donotify
= 0;
626 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
629 if (cdev
->private->state
== DEV_STATE_BOXED
) {
630 ccw_device_done(cdev
, DEV_STATE_BOXED
);
633 if (ccw_device_is_orphan(cdev
)) {
634 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
637 sch
= to_subchannel(cdev
->dev
.parent
);
638 if (cio_update_schib(sch
))
640 if (scsw_actl(&sch
->schib
.scsw
) != 0)
642 if (cdev
->private->state
!= DEV_STATE_ONLINE
)
644 /* Are we doing path grouping? */
645 if (!cdev
->private->flags
.pgroup
) {
646 /* No, set state offline immediately. */
647 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
650 /* Start Set Path Group commands. */
651 cdev
->private->state
= DEV_STATE_DISBAND_PGID
;
652 ccw_device_disband_start(cdev
);
657 * Handle not operational event in non-special state.
659 static void ccw_device_generic_notoper(struct ccw_device
*cdev
,
660 enum dev_event dev_event
)
662 if (ccw_device_notify(cdev
, CIO_GONE
) != NOTIFY_OK
)
663 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
665 ccw_device_set_disconnected(cdev
);
669 * Handle path verification event in offline state.
671 static void ccw_device_offline_verify(struct ccw_device
*cdev
,
672 enum dev_event dev_event
)
674 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
676 css_schedule_eval(sch
->schid
);
680 * Handle path verification event.
683 ccw_device_online_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
685 struct subchannel
*sch
;
687 if (cdev
->private->state
== DEV_STATE_W4SENSE
) {
688 cdev
->private->flags
.doverify
= 1;
691 sch
= to_subchannel(cdev
->dev
.parent
);
693 * Since we might not just be coming from an interrupt from the
694 * subchannel we have to update the schib.
696 if (cio_update_schib(sch
)) {
697 ccw_device_verify_done(cdev
, -ENODEV
);
701 if (scsw_actl(&sch
->schib
.scsw
) != 0 ||
702 (scsw_stctl(&sch
->schib
.scsw
) & SCSW_STCTL_STATUS_PEND
) ||
703 (scsw_stctl(&cdev
->private->irb
.scsw
) & SCSW_STCTL_STATUS_PEND
)) {
705 * No final status yet or final status not yet delivered
706 * to the device driver. Can't do path verification now,
707 * delay until final status was delivered.
709 cdev
->private->flags
.doverify
= 1;
712 /* Device is idle, we can do the path verification. */
713 cdev
->private->state
= DEV_STATE_VERIFY
;
714 ccw_device_verify_start(cdev
);
718 * Handle path verification event in boxed state.
720 static void ccw_device_boxed_verify(struct ccw_device
*cdev
,
721 enum dev_event dev_event
)
723 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
726 if (cio_enable_subchannel(sch
, (u32
) (addr_t
) sch
))
727 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
729 ccw_device_online_verify(cdev
, dev_event
);
731 css_schedule_eval(sch
->schid
);
735 * Got an interrupt for a normal io (state online).
738 ccw_device_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
743 irb
= (struct irb
*)&S390_lowcore
.irb
;
744 is_cmd
= !scsw_is_tm(&irb
->scsw
);
745 /* Check for unsolicited interrupt. */
746 if (!scsw_is_solicited(&irb
->scsw
)) {
747 if (is_cmd
&& (irb
->scsw
.cmd
.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
);
760 if (cdev
->private->flags
.doverify
)
761 ccw_device_online_verify(cdev
, 0);
764 /* Accumulate status and find out if a basic sense is needed. */
765 ccw_device_accumulate_irb(cdev
, irb
);
766 if (is_cmd
&& cdev
->private->flags
.dosense
) {
767 if (ccw_device_do_sense(cdev
, irb
) == 0) {
768 cdev
->private->state
= DEV_STATE_W4SENSE
;
772 /* Call the handler. */
773 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
774 /* Start delayed path verification. */
775 ccw_device_online_verify(cdev
, 0);
779 * Got an timeout in online state.
782 ccw_device_online_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
786 ccw_device_set_timeout(cdev
, 0);
787 cdev
->private->iretry
= 255;
788 ret
= ccw_device_cancel_halt_clear(cdev
);
790 ccw_device_set_timeout(cdev
, 3*HZ
);
791 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
795 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
796 else if (cdev
->handler
)
797 cdev
->handler(cdev
, cdev
->private->intparm
,
798 ERR_PTR(-ETIMEDOUT
));
802 * Got an interrupt for a basic sense.
805 ccw_device_w4sense(struct ccw_device
*cdev
, enum dev_event dev_event
)
809 irb
= (struct irb
*)&S390_lowcore
.irb
;
810 /* Check for unsolicited interrupt. */
811 if (scsw_stctl(&irb
->scsw
) ==
812 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
813 if (scsw_cc(&irb
->scsw
) == 1)
814 /* Basic sense hasn't started. Try again. */
815 ccw_device_do_sense(cdev
, irb
);
817 CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
818 "interrupt during w4sense...\n",
819 cdev
->private->dev_id
.ssid
,
820 cdev
->private->dev_id
.devno
);
822 cdev
->handler (cdev
, 0, irb
);
827 * Check if a halt or clear has been issued in the meanwhile. If yes,
828 * only deliver the halt/clear interrupt to the device driver as if it
829 * had killed the original request.
831 if (scsw_fctl(&irb
->scsw
) &
832 (SCSW_FCTL_CLEAR_FUNC
| SCSW_FCTL_HALT_FUNC
)) {
833 cdev
->private->flags
.dosense
= 0;
834 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
835 ccw_device_accumulate_irb(cdev
, irb
);
838 /* Add basic sense info to irb. */
839 ccw_device_accumulate_basic_sense(cdev
, irb
);
840 if (cdev
->private->flags
.dosense
) {
841 /* Another basic sense is needed. */
842 ccw_device_do_sense(cdev
, irb
);
846 cdev
->private->state
= DEV_STATE_ONLINE
;
847 /* In case sensing interfered with setting the device online */
848 wake_up(&cdev
->private->wait_q
);
849 /* Call the handler. */
850 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
851 /* Start delayed path verification. */
852 ccw_device_online_verify(cdev
, 0);
856 ccw_device_killing_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
858 ccw_device_set_timeout(cdev
, 0);
859 /* Start delayed path verification. */
860 ccw_device_online_verify(cdev
, 0);
861 /* OK, i/o is dead now. Call interrupt handler. */
863 cdev
->handler(cdev
, cdev
->private->intparm
,
868 ccw_device_killing_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
872 ret
= ccw_device_cancel_halt_clear(cdev
);
874 ccw_device_set_timeout(cdev
, 3*HZ
);
877 /* Start delayed path verification. */
878 ccw_device_online_verify(cdev
, 0);
880 cdev
->handler(cdev
, cdev
->private->intparm
,
884 void ccw_device_kill_io(struct ccw_device
*cdev
)
888 cdev
->private->iretry
= 255;
889 ret
= ccw_device_cancel_halt_clear(cdev
);
891 ccw_device_set_timeout(cdev
, 3*HZ
);
892 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
895 /* Start delayed path verification. */
896 ccw_device_online_verify(cdev
, 0);
898 cdev
->handler(cdev
, cdev
->private->intparm
,
903 ccw_device_delay_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
905 /* Start verification after current task finished. */
906 cdev
->private->flags
.doverify
= 1;
910 ccw_device_start_id(struct ccw_device
*cdev
, enum dev_event dev_event
)
912 struct subchannel
*sch
;
914 sch
= to_subchannel(cdev
->dev
.parent
);
915 if (cio_enable_subchannel(sch
, (u32
)(addr_t
)sch
) != 0)
916 /* Couldn't enable the subchannel for i/o. Sick device. */
918 cdev
->private->state
= DEV_STATE_DISCONNECTED_SENSE_ID
;
919 ccw_device_sense_id_start(cdev
);
922 void ccw_device_trigger_reprobe(struct ccw_device
*cdev
)
924 struct subchannel
*sch
;
926 if (cdev
->private->state
!= DEV_STATE_DISCONNECTED
)
929 sch
= to_subchannel(cdev
->dev
.parent
);
930 /* Update some values. */
931 if (cio_update_schib(sch
))
934 * The pim, pam, pom values may not be accurate, but they are the best
935 * we have before performing device selection :/
937 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
939 * Use the initial configuration since we can't be shure that the old
942 io_subchannel_init_config(sch
);
943 if (cio_commit_config(sch
))
946 /* We should also udate ssd info, but this has to wait. */
947 /* Check if this is another device which appeared on the same sch. */
948 if (sch
->schib
.pmcw
.dev
!= cdev
->private->dev_id
.devno
)
949 css_schedule_eval(sch
->schid
);
951 ccw_device_start_id(cdev
, 0);
954 static void ccw_device_disabled_irq(struct ccw_device
*cdev
,
955 enum dev_event dev_event
)
957 struct subchannel
*sch
;
959 sch
= to_subchannel(cdev
->dev
.parent
);
961 * An interrupt in a disabled state means a previous disable was not
962 * successful - should not happen, but we try to disable again.
964 cio_disable_subchannel(sch
);
968 ccw_device_change_cmfstate(struct ccw_device
*cdev
, enum dev_event dev_event
)
970 retry_set_schib(cdev
);
971 cdev
->private->state
= DEV_STATE_ONLINE
;
972 dev_fsm_event(cdev
, dev_event
);
975 static void ccw_device_update_cmfblock(struct ccw_device
*cdev
,
976 enum dev_event dev_event
)
978 cmf_retry_copy_block(cdev
);
979 cdev
->private->state
= DEV_STATE_ONLINE
;
980 dev_fsm_event(cdev
, dev_event
);
984 ccw_device_quiesce_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
986 ccw_device_set_timeout(cdev
, 0);
987 cdev
->private->state
= DEV_STATE_NOT_OPER
;
988 wake_up(&cdev
->private->wait_q
);
992 ccw_device_quiesce_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
996 ret
= ccw_device_cancel_halt_clear(cdev
);
998 ccw_device_set_timeout(cdev
, HZ
/10);
1000 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1001 wake_up(&cdev
->private->wait_q
);
1006 * No operation action. This is used e.g. to ignore a timeout event in
1010 ccw_device_nop(struct ccw_device
*cdev
, enum dev_event dev_event
)
1015 * device statemachine
1017 fsm_func_t
*dev_jumptable
[NR_DEV_STATES
][NR_DEV_EVENTS
] = {
1018 [DEV_STATE_NOT_OPER
] = {
1019 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1020 [DEV_EVENT_INTERRUPT
] = ccw_device_disabled_irq
,
1021 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1022 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1024 [DEV_STATE_SENSE_PGID
] = {
1025 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1026 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1027 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1028 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1030 [DEV_STATE_SENSE_ID
] = {
1031 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1032 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1033 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1034 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1036 [DEV_STATE_OFFLINE
] = {
1037 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1038 [DEV_EVENT_INTERRUPT
] = ccw_device_disabled_irq
,
1039 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1040 [DEV_EVENT_VERIFY
] = ccw_device_offline_verify
,
1042 [DEV_STATE_VERIFY
] = {
1043 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1044 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1045 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1046 [DEV_EVENT_VERIFY
] = ccw_device_delay_verify
,
1048 [DEV_STATE_ONLINE
] = {
1049 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1050 [DEV_EVENT_INTERRUPT
] = ccw_device_irq
,
1051 [DEV_EVENT_TIMEOUT
] = ccw_device_online_timeout
,
1052 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1054 [DEV_STATE_W4SENSE
] = {
1055 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1056 [DEV_EVENT_INTERRUPT
] = ccw_device_w4sense
,
1057 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1058 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1060 [DEV_STATE_DISBAND_PGID
] = {
1061 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1062 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1063 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1064 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1066 [DEV_STATE_BOXED
] = {
1067 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1068 [DEV_EVENT_INTERRUPT
] = ccw_device_nop
,
1069 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1070 [DEV_EVENT_VERIFY
] = ccw_device_boxed_verify
,
1072 /* states to wait for i/o completion before doing something */
1073 [DEV_STATE_TIMEOUT_KILL
] = {
1074 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1075 [DEV_EVENT_INTERRUPT
] = ccw_device_killing_irq
,
1076 [DEV_EVENT_TIMEOUT
] = ccw_device_killing_timeout
,
1077 [DEV_EVENT_VERIFY
] = ccw_device_nop
, //FIXME
1079 [DEV_STATE_QUIESCE
] = {
1080 [DEV_EVENT_NOTOPER
] = ccw_device_quiesce_done
,
1081 [DEV_EVENT_INTERRUPT
] = ccw_device_quiesce_done
,
1082 [DEV_EVENT_TIMEOUT
] = ccw_device_quiesce_timeout
,
1083 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1085 /* special states for devices gone not operational */
1086 [DEV_STATE_DISCONNECTED
] = {
1087 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1088 [DEV_EVENT_INTERRUPT
] = ccw_device_start_id
,
1089 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1090 [DEV_EVENT_VERIFY
] = ccw_device_start_id
,
1092 [DEV_STATE_DISCONNECTED_SENSE_ID
] = {
1093 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1094 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1095 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1096 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1098 [DEV_STATE_CMFCHANGE
] = {
1099 [DEV_EVENT_NOTOPER
] = ccw_device_change_cmfstate
,
1100 [DEV_EVENT_INTERRUPT
] = ccw_device_change_cmfstate
,
1101 [DEV_EVENT_TIMEOUT
] = ccw_device_change_cmfstate
,
1102 [DEV_EVENT_VERIFY
] = ccw_device_change_cmfstate
,
1104 [DEV_STATE_CMFUPDATE
] = {
1105 [DEV_EVENT_NOTOPER
] = ccw_device_update_cmfblock
,
1106 [DEV_EVENT_INTERRUPT
] = ccw_device_update_cmfblock
,
1107 [DEV_EVENT_TIMEOUT
] = ccw_device_update_cmfblock
,
1108 [DEV_EVENT_VERIFY
] = ccw_device_update_cmfblock
,
1110 [DEV_STATE_STEAL_LOCK
] = {
1111 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1112 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1113 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1114 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1118 EXPORT_SYMBOL_GPL(ccw_device_set_timeout
);