2 * drivers/s390/cio/device_fsm.c
3 * finite state machine for device handling
5 * Copyright IBM Corp. 2002,2008
6 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/jiffies.h>
13 #include <linux/string.h>
15 #include <asm/ccwdev.h>
17 #include <asm/chpid.h>
20 #include "cio_debug.h"
27 static int timeout_log_enabled
;
29 static int __init
ccw_timeout_log_setup(char *unused
)
31 timeout_log_enabled
= 1;
35 __setup("ccw_timeout_log", ccw_timeout_log_setup
);
37 static void ccw_timeout_log(struct ccw_device
*cdev
)
40 struct subchannel
*sch
;
41 struct io_subchannel_private
*private;
45 sch
= to_subchannel(cdev
->dev
.parent
);
46 private = to_io_private(sch
);
48 cc
= stsch(sch
->schid
, &schib
);
50 printk(KERN_WARNING
"cio: ccw device timeout occurred at %llx, "
51 "device information:\n", get_clock());
52 printk(KERN_WARNING
"cio: orb:\n");
53 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
54 orb
, sizeof(*orb
), 0);
55 printk(KERN_WARNING
"cio: ccw device bus id: %s\n",
56 dev_name(&cdev
->dev
));
57 printk(KERN_WARNING
"cio: subchannel bus id: %s\n",
59 printk(KERN_WARNING
"cio: subchannel lpm: %02x, opm: %02x, "
60 "vpm: %02x\n", sch
->lpm
, sch
->opm
, sch
->vpm
);
63 printk(KERN_WARNING
"cio: orb indicates transport mode\n");
64 printk(KERN_WARNING
"cio: last tcw:\n");
65 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
66 (void *)(addr_t
)orb
->tm
.tcw
,
67 sizeof(struct tcw
), 0);
69 printk(KERN_WARNING
"cio: orb indicates command mode\n");
70 if ((void *)(addr_t
)orb
->cmd
.cpa
== &private->sense_ccw
||
71 (void *)(addr_t
)orb
->cmd
.cpa
== cdev
->private->iccws
)
72 printk(KERN_WARNING
"cio: last channel program "
75 printk(KERN_WARNING
"cio: last channel program:\n");
77 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
78 (void *)(addr_t
)orb
->cmd
.cpa
,
79 sizeof(struct ccw1
), 0);
81 printk(KERN_WARNING
"cio: ccw device state: %d\n",
82 cdev
->private->state
);
83 printk(KERN_WARNING
"cio: store subchannel returned: cc=%d\n", cc
);
84 printk(KERN_WARNING
"cio: schib:\n");
85 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
86 &schib
, sizeof(schib
), 0);
87 printk(KERN_WARNING
"cio: ccw device flags:\n");
88 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
89 &cdev
->private->flags
, sizeof(cdev
->private->flags
), 0);
93 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
96 ccw_device_timeout(unsigned long data
)
98 struct ccw_device
*cdev
;
100 cdev
= (struct ccw_device
*) data
;
101 spin_lock_irq(cdev
->ccwlock
);
102 if (timeout_log_enabled
)
103 ccw_timeout_log(cdev
);
104 dev_fsm_event(cdev
, DEV_EVENT_TIMEOUT
);
105 spin_unlock_irq(cdev
->ccwlock
);
112 ccw_device_set_timeout(struct ccw_device
*cdev
, int expires
)
115 del_timer(&cdev
->private->timer
);
118 if (timer_pending(&cdev
->private->timer
)) {
119 if (mod_timer(&cdev
->private->timer
, jiffies
+ expires
))
122 cdev
->private->timer
.function
= ccw_device_timeout
;
123 cdev
->private->timer
.data
= (unsigned long) cdev
;
124 cdev
->private->timer
.expires
= jiffies
+ expires
;
125 add_timer(&cdev
->private->timer
);
129 * Cancel running i/o. This is called repeatedly since halt/clear are
130 * asynchronous operations. We do one try with cio_cancel, two tries
131 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
132 * Returns 0 if device now idle, -ENODEV for device not operational and
133 * -EBUSY if an interrupt is expected (either from halt/clear or from a
137 ccw_device_cancel_halt_clear(struct ccw_device
*cdev
)
139 struct subchannel
*sch
;
142 sch
= to_subchannel(cdev
->dev
.parent
);
143 ret
= stsch(sch
->schid
, &sch
->schib
);
144 if (ret
|| !sch
->schib
.pmcw
.dnv
)
146 if (!sch
->schib
.pmcw
.ena
)
147 /* Not operational -> done. */
149 /* Stage 1: cancel io. */
150 if (!(scsw_actl(&sch
->schib
.scsw
) & SCSW_ACTL_HALT_PEND
) &&
151 !(scsw_actl(&sch
->schib
.scsw
) & SCSW_ACTL_CLEAR_PEND
)) {
152 if (!scsw_is_tm(&sch
->schib
.scsw
)) {
153 ret
= cio_cancel(sch
);
157 /* cancel io unsuccessful or not applicable (transport mode).
158 * Continue with asynchronous instructions. */
159 cdev
->private->iretry
= 3; /* 3 halt retries. */
161 if (!(scsw_actl(&sch
->schib
.scsw
) & SCSW_ACTL_CLEAR_PEND
)) {
162 /* Stage 2: halt io. */
163 if (cdev
->private->iretry
) {
164 cdev
->private->iretry
--;
167 return (ret
== 0) ? -EBUSY
: ret
;
169 /* halt io unsuccessful. */
170 cdev
->private->iretry
= 255; /* 255 clear retries. */
172 /* Stage 3: clear io. */
173 if (cdev
->private->iretry
) {
174 cdev
->private->iretry
--;
175 ret
= cio_clear (sch
);
176 return (ret
== 0) ? -EBUSY
: ret
;
178 panic("Can't stop i/o on subchannel.\n");
182 ccw_device_handle_oper(struct ccw_device
*cdev
)
184 struct subchannel
*sch
;
186 sch
= to_subchannel(cdev
->dev
.parent
);
187 cdev
->private->flags
.recog_done
= 1;
189 * Check if cu type and device type still match. If
190 * not, it is certainly another device and we have to
191 * de- and re-register.
193 if (cdev
->id
.cu_type
!= cdev
->private->senseid
.cu_type
||
194 cdev
->id
.cu_model
!= cdev
->private->senseid
.cu_model
||
195 cdev
->id
.dev_type
!= cdev
->private->senseid
.dev_type
||
196 cdev
->id
.dev_model
!= cdev
->private->senseid
.dev_model
) {
197 PREPARE_WORK(&cdev
->private->kick_work
,
198 ccw_device_do_unreg_rereg
);
199 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
202 cdev
->private->flags
.donotify
= 1;
207 * The machine won't give us any notification by machine check if a chpid has
208 * been varied online on the SE so we have to find out by magic (i. e. driving
209 * the channel subsystem to device selection and updating our path masks).
212 __recover_lost_chpids(struct subchannel
*sch
, int old_lpm
)
218 for (i
= 0; i
<8; i
++) {
220 if (!(sch
->lpm
& mask
))
224 chpid
.id
= sch
->schib
.pmcw
.chpid
[i
];
225 if (!chp_is_registered(chpid
))
226 css_schedule_eval_all();
231 * Stop device recognition.
234 ccw_device_recog_done(struct ccw_device
*cdev
, int state
)
236 struct subchannel
*sch
;
237 int notify
, old_lpm
, same_dev
;
239 sch
= to_subchannel(cdev
->dev
.parent
);
241 ccw_device_set_timeout(cdev
, 0);
242 cio_disable_subchannel(sch
);
244 * Now that we tried recognition, we have performed device selection
245 * through ssch() and the path information is up to date.
248 stsch(sch
->schid
, &sch
->schib
);
249 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
250 /* Check since device may again have become not operational. */
251 if (!sch
->schib
.pmcw
.dnv
)
252 state
= DEV_STATE_NOT_OPER
;
253 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
)
254 /* Force reprobe on all chpids. */
256 if (sch
->lpm
!= old_lpm
)
257 __recover_lost_chpids(sch
, old_lpm
);
258 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
259 if (state
== DEV_STATE_NOT_OPER
) {
260 cdev
->private->flags
.recog_done
= 1;
261 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
264 /* Boxed devices don't need extra treatment. */
267 same_dev
= 0; /* Keep the compiler quiet... */
269 case DEV_STATE_NOT_OPER
:
270 CIO_MSG_EVENT(2, "SenseID : unknown device %04x on "
271 "subchannel 0.%x.%04x\n",
272 cdev
->private->dev_id
.devno
,
273 sch
->schid
.ssid
, sch
->schid
.sch_no
);
275 case DEV_STATE_OFFLINE
:
276 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
277 same_dev
= ccw_device_handle_oper(cdev
);
280 /* fill out sense information */
281 memset(&cdev
->id
, 0, sizeof(cdev
->id
));
282 cdev
->id
.cu_type
= cdev
->private->senseid
.cu_type
;
283 cdev
->id
.cu_model
= cdev
->private->senseid
.cu_model
;
284 cdev
->id
.dev_type
= cdev
->private->senseid
.dev_type
;
285 cdev
->id
.dev_model
= cdev
->private->senseid
.dev_model
;
287 cdev
->private->state
= DEV_STATE_OFFLINE
;
289 /* Get device online again. */
290 ccw_device_online(cdev
);
291 wake_up(&cdev
->private->wait_q
);
295 /* Issue device info message. */
296 CIO_MSG_EVENT(4, "SenseID : device 0.%x.%04x reports: "
297 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
299 cdev
->private->dev_id
.ssid
,
300 cdev
->private->dev_id
.devno
,
301 cdev
->id
.cu_type
, cdev
->id
.cu_model
,
302 cdev
->id
.dev_type
, cdev
->id
.dev_model
);
304 case DEV_STATE_BOXED
:
305 CIO_MSG_EVENT(0, "SenseID : boxed device %04x on "
306 " subchannel 0.%x.%04x\n",
307 cdev
->private->dev_id
.devno
,
308 sch
->schid
.ssid
, sch
->schid
.sch_no
);
311 cdev
->private->state
= state
;
312 io_subchannel_recog_done(cdev
);
313 if (state
!= DEV_STATE_NOT_OPER
)
314 wake_up(&cdev
->private->wait_q
);
318 * Function called from device_id.c after sense id has completed.
321 ccw_device_sense_id_done(struct ccw_device
*cdev
, int err
)
325 ccw_device_recog_done(cdev
, DEV_STATE_OFFLINE
);
327 case -ETIME
: /* Sense id stopped by timeout. */
328 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
331 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
336 int ccw_device_notify(struct ccw_device
*cdev
, int event
)
342 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
343 cdev
->private->dev_id
.ssid
, cdev
->private->dev_id
.devno
,
345 return cdev
->drv
->notify
? cdev
->drv
->notify(cdev
, event
) : 0;
348 static void cmf_reenable_delayed(struct work_struct
*work
)
350 struct ccw_device_private
*priv
;
351 struct ccw_device
*cdev
;
353 priv
= container_of(work
, struct ccw_device_private
, kick_work
);
358 static void ccw_device_oper_notify(struct ccw_device
*cdev
)
360 if (ccw_device_notify(cdev
, CIO_OPER
)) {
361 /* Reenable channel measurements, if needed. */
362 PREPARE_WORK(&cdev
->private->kick_work
, cmf_reenable_delayed
);
363 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
366 /* Driver doesn't want device back. */
367 ccw_device_set_notoper(cdev
);
368 PREPARE_WORK(&cdev
->private->kick_work
, ccw_device_do_unreg_rereg
);
369 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
373 * Finished with online/offline processing.
376 ccw_device_done(struct ccw_device
*cdev
, int state
)
378 struct subchannel
*sch
;
380 sch
= to_subchannel(cdev
->dev
.parent
);
382 ccw_device_set_timeout(cdev
, 0);
384 if (state
!= DEV_STATE_ONLINE
)
385 cio_disable_subchannel(sch
);
387 /* Reset device status. */
388 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
390 cdev
->private->state
= state
;
393 if (state
== DEV_STATE_BOXED
)
394 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
395 cdev
->private->dev_id
.devno
, sch
->schid
.sch_no
);
397 if (cdev
->private->flags
.donotify
) {
398 cdev
->private->flags
.donotify
= 0;
399 ccw_device_oper_notify(cdev
);
401 wake_up(&cdev
->private->wait_q
);
404 static int cmp_pgid(struct pgid
*p1
, struct pgid
*p2
)
412 return memcmp(c1
+ 1, c2
+ 1, sizeof(struct pgid
) - 1);
415 static void __ccw_device_get_common_pgid(struct ccw_device
*cdev
)
421 for (i
= 0; i
< 8; i
++) {
422 if (cdev
->private->pgid
[i
].inf
.ps
.state1
== SNID_STATE1_RESET
)
425 if (cdev
->private->pgid
[last
].inf
.ps
.state1
==
427 /* First non-zero PGID */
431 if (cmp_pgid(&cdev
->private->pgid
[i
],
432 &cdev
->private->pgid
[last
]) == 0)
433 /* Non-conflicting PGIDs */
436 /* PGID mismatch, can't pathgroup. */
437 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
438 "0.%x.%04x, can't pathgroup\n",
439 cdev
->private->dev_id
.ssid
,
440 cdev
->private->dev_id
.devno
);
441 cdev
->private->options
.pgroup
= 0;
444 if (cdev
->private->pgid
[last
].inf
.ps
.state1
==
446 /* No previous pgid found */
447 memcpy(&cdev
->private->pgid
[0],
448 &channel_subsystems
[0]->global_pgid
,
449 sizeof(struct pgid
));
451 /* Use existing pgid */
452 memcpy(&cdev
->private->pgid
[0], &cdev
->private->pgid
[last
],
453 sizeof(struct pgid
));
457 * Function called from device_pgid.c after sense path ground has completed.
460 ccw_device_sense_pgid_done(struct ccw_device
*cdev
, int err
)
462 struct subchannel
*sch
;
464 sch
= to_subchannel(cdev
->dev
.parent
);
466 case -EOPNOTSUPP
: /* path grouping not supported, use nop instead. */
467 cdev
->private->options
.pgroup
= 0;
469 case 0: /* success */
470 case -EACCES
: /* partial success, some paths not operational */
471 /* Check if all pgids are equal or 0. */
472 __ccw_device_get_common_pgid(cdev
);
474 case -ETIME
: /* Sense path group id stopped by timeout. */
475 case -EUSERS
: /* device is reserved for someone else. */
476 ccw_device_done(cdev
, DEV_STATE_BOXED
);
479 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
482 /* Start Path Group verification. */
483 cdev
->private->state
= DEV_STATE_VERIFY
;
484 cdev
->private->flags
.doverify
= 0;
485 ccw_device_verify_start(cdev
);
489 * Start device recognition.
492 ccw_device_recognition(struct ccw_device
*cdev
)
494 struct subchannel
*sch
;
497 if ((cdev
->private->state
!= DEV_STATE_NOT_OPER
) &&
498 (cdev
->private->state
!= DEV_STATE_BOXED
))
500 sch
= to_subchannel(cdev
->dev
.parent
);
501 ret
= cio_enable_subchannel(sch
, (u32
)(addr_t
)sch
);
503 /* Couldn't enable the subchannel for i/o. Sick device. */
506 /* After 60s the device recognition is considered to have failed. */
507 ccw_device_set_timeout(cdev
, 60*HZ
);
510 * We used to start here with a sense pgid to find out whether a device
511 * is locked by someone else. Unfortunately, the sense pgid command
512 * code has other meanings on devices predating the path grouping
513 * algorithm, so we start with sense id and box the device after an
514 * timeout (or if sense pgid during path verification detects the device
515 * is locked, as may happen on newer devices).
517 cdev
->private->flags
.recog_done
= 0;
518 cdev
->private->state
= DEV_STATE_SENSE_ID
;
519 ccw_device_sense_id_start(cdev
);
524 * Handle timeout in device recognition.
527 ccw_device_recog_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
531 ret
= ccw_device_cancel_halt_clear(cdev
);
534 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
537 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
540 ccw_device_set_timeout(cdev
, 3*HZ
);
546 ccw_device_verify_done(struct ccw_device
*cdev
, int err
)
548 struct subchannel
*sch
;
550 sch
= to_subchannel(cdev
->dev
.parent
);
551 /* Update schib - pom may have changed. */
552 stsch(sch
->schid
, &sch
->schib
);
553 /* Update lpm with verified path mask. */
555 /* Repeat path verification? */
556 if (cdev
->private->flags
.doverify
) {
557 cdev
->private->flags
.doverify
= 0;
558 ccw_device_verify_start(cdev
);
562 case -EOPNOTSUPP
: /* path grouping not supported, just set online. */
563 cdev
->private->options
.pgroup
= 0;
565 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
566 /* Deliver fake irb to device driver, if needed. */
567 if (cdev
->private->flags
.fake_irb
) {
568 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
569 cdev
->private->irb
.scsw
.cmd
.cc
= 1;
570 cdev
->private->irb
.scsw
.cmd
.fctl
= SCSW_FCTL_START_FUNC
;
571 cdev
->private->irb
.scsw
.cmd
.actl
= SCSW_ACTL_START_PEND
;
572 cdev
->private->irb
.scsw
.cmd
.stctl
=
573 SCSW_STCTL_STATUS_PEND
;
574 cdev
->private->flags
.fake_irb
= 0;
576 cdev
->handler(cdev
, cdev
->private->intparm
,
577 &cdev
->private->irb
);
578 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
582 /* Reset oper notify indication after verify error. */
583 cdev
->private->flags
.donotify
= 0;
584 ccw_device_done(cdev
, DEV_STATE_BOXED
);
587 /* Reset oper notify indication after verify error. */
588 cdev
->private->flags
.donotify
= 0;
590 ccw_device_set_timeout(cdev
, 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 ret
= cio_enable_subchannel(sch
, (u32
)(addr_t
)sch
);
613 /* Couldn't enable the subchannel for i/o. Sick device. */
615 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
618 /* Do we want to do path grouping? */
619 if (!cdev
->private->options
.pgroup
) {
620 /* Start initial path verification. */
621 cdev
->private->state
= DEV_STATE_VERIFY
;
622 cdev
->private->flags
.doverify
= 0;
623 ccw_device_verify_start(cdev
);
626 /* Do a SensePGID first. */
627 cdev
->private->state
= DEV_STATE_SENSE_PGID
;
628 ccw_device_sense_pgid_start(cdev
);
633 ccw_device_disband_done(struct ccw_device
*cdev
, int err
)
637 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
640 ccw_device_done(cdev
, DEV_STATE_BOXED
);
643 cdev
->private->flags
.donotify
= 0;
644 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
645 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
654 ccw_device_offline(struct ccw_device
*cdev
)
656 struct subchannel
*sch
;
658 /* Allow ccw_device_offline while disconnected. */
659 if (cdev
->private->state
== DEV_STATE_DISCONNECTED
||
660 cdev
->private->state
== DEV_STATE_NOT_OPER
) {
661 cdev
->private->flags
.donotify
= 0;
662 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
665 if (ccw_device_is_orphan(cdev
)) {
666 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
669 sch
= to_subchannel(cdev
->dev
.parent
);
670 if (stsch(sch
->schid
, &sch
->schib
) || !sch
->schib
.pmcw
.dnv
)
672 if (scsw_actl(&sch
->schib
.scsw
) != 0)
674 if (cdev
->private->state
!= DEV_STATE_ONLINE
)
676 /* Are we doing path grouping? */
677 if (!cdev
->private->options
.pgroup
) {
678 /* No, set state offline immediately. */
679 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
682 /* Start Set Path Group commands. */
683 cdev
->private->state
= DEV_STATE_DISBAND_PGID
;
684 ccw_device_disband_start(cdev
);
689 * Handle timeout in device online/offline process.
692 ccw_device_onoff_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
696 ret
= ccw_device_cancel_halt_clear(cdev
);
699 ccw_device_done(cdev
, DEV_STATE_BOXED
);
702 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
705 ccw_device_set_timeout(cdev
, 3*HZ
);
710 * Handle not oper event in device recognition.
713 ccw_device_recog_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
715 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
719 * Handle not operational event in non-special state.
721 static void ccw_device_generic_notoper(struct ccw_device
*cdev
,
722 enum dev_event dev_event
)
724 struct subchannel
*sch
;
726 cdev
->private->state
= DEV_STATE_NOT_OPER
;
727 sch
= to_subchannel(cdev
->dev
.parent
);
728 css_schedule_eval(sch
->schid
);
732 * Handle path verification event.
735 ccw_device_online_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
737 struct subchannel
*sch
;
739 if (cdev
->private->state
== DEV_STATE_W4SENSE
) {
740 cdev
->private->flags
.doverify
= 1;
743 sch
= to_subchannel(cdev
->dev
.parent
);
745 * Since we might not just be coming from an interrupt from the
746 * subchannel we have to update the schib.
748 stsch(sch
->schid
, &sch
->schib
);
750 if (scsw_actl(&sch
->schib
.scsw
) != 0 ||
751 (scsw_stctl(&sch
->schib
.scsw
) & SCSW_STCTL_STATUS_PEND
) ||
752 (scsw_stctl(&cdev
->private->irb
.scsw
) & SCSW_STCTL_STATUS_PEND
)) {
754 * No final status yet or final status not yet delivered
755 * to the device driver. Can't do path verfication now,
756 * delay until final status was delivered.
758 cdev
->private->flags
.doverify
= 1;
761 /* Device is idle, we can do the path verification. */
762 cdev
->private->state
= DEV_STATE_VERIFY
;
763 cdev
->private->flags
.doverify
= 0;
764 ccw_device_verify_start(cdev
);
768 * Got an interrupt for a normal io (state online).
771 ccw_device_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
776 irb
= (struct irb
*) __LC_IRB
;
777 is_cmd
= !scsw_is_tm(&irb
->scsw
);
778 /* Check for unsolicited interrupt. */
779 if (!scsw_is_solicited(&irb
->scsw
)) {
780 if (is_cmd
&& (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) &&
781 !irb
->esw
.esw0
.erw
.cons
) {
782 /* Unit check but no sense data. Need basic sense. */
783 if (ccw_device_do_sense(cdev
, irb
) != 0)
784 goto call_handler_unsol
;
785 memcpy(&cdev
->private->irb
, irb
, sizeof(struct irb
));
786 cdev
->private->state
= DEV_STATE_W4SENSE
;
787 cdev
->private->intparm
= 0;
792 cdev
->handler (cdev
, 0, irb
);
793 if (cdev
->private->flags
.doverify
)
794 ccw_device_online_verify(cdev
, 0);
797 /* Accumulate status and find out if a basic sense is needed. */
798 ccw_device_accumulate_irb(cdev
, irb
);
799 if (is_cmd
&& cdev
->private->flags
.dosense
) {
800 if (ccw_device_do_sense(cdev
, irb
) == 0) {
801 cdev
->private->state
= DEV_STATE_W4SENSE
;
805 /* Call the handler. */
806 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
807 /* Start delayed path verification. */
808 ccw_device_online_verify(cdev
, 0);
812 * Got an timeout in online state.
815 ccw_device_online_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
819 ccw_device_set_timeout(cdev
, 0);
820 ret
= ccw_device_cancel_halt_clear(cdev
);
822 ccw_device_set_timeout(cdev
, 3*HZ
);
823 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
827 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
828 else if (cdev
->handler
)
829 cdev
->handler(cdev
, cdev
->private->intparm
,
830 ERR_PTR(-ETIMEDOUT
));
834 * Got an interrupt for a basic sense.
837 ccw_device_w4sense(struct ccw_device
*cdev
, enum dev_event dev_event
)
841 irb
= (struct irb
*) __LC_IRB
;
842 /* Check for unsolicited interrupt. */
843 if (scsw_stctl(&irb
->scsw
) ==
844 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
845 if (scsw_cc(&irb
->scsw
) == 1)
846 /* Basic sense hasn't started. Try again. */
847 ccw_device_do_sense(cdev
, irb
);
849 CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
850 "interrupt during w4sense...\n",
851 cdev
->private->dev_id
.ssid
,
852 cdev
->private->dev_id
.devno
);
854 cdev
->handler (cdev
, 0, irb
);
859 * Check if a halt or clear has been issued in the meanwhile. If yes,
860 * only deliver the halt/clear interrupt to the device driver as if it
861 * had killed the original request.
863 if (scsw_fctl(&irb
->scsw
) &
864 (SCSW_FCTL_CLEAR_FUNC
| SCSW_FCTL_HALT_FUNC
)) {
865 /* Retry Basic Sense if requested. */
866 if (cdev
->private->flags
.intretry
) {
867 cdev
->private->flags
.intretry
= 0;
868 ccw_device_do_sense(cdev
, irb
);
871 cdev
->private->flags
.dosense
= 0;
872 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
873 ccw_device_accumulate_irb(cdev
, irb
);
876 /* Add basic sense info to irb. */
877 ccw_device_accumulate_basic_sense(cdev
, irb
);
878 if (cdev
->private->flags
.dosense
) {
879 /* Another basic sense is needed. */
880 ccw_device_do_sense(cdev
, irb
);
884 cdev
->private->state
= DEV_STATE_ONLINE
;
885 /* Call the handler. */
886 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
887 /* Start delayed path verification. */
888 ccw_device_online_verify(cdev
, 0);
892 ccw_device_clear_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
896 irb
= (struct irb
*) __LC_IRB
;
897 /* Accumulate status. We don't do basic sense. */
898 ccw_device_accumulate_irb(cdev
, irb
);
899 /* Remember to clear irb to avoid residuals. */
900 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
901 /* Try to start delayed device verification. */
902 ccw_device_online_verify(cdev
, 0);
903 /* Note: Don't call handler for cio initiated clear! */
907 ccw_device_killing_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
909 struct subchannel
*sch
;
911 sch
= to_subchannel(cdev
->dev
.parent
);
912 ccw_device_set_timeout(cdev
, 0);
913 /* Start delayed path verification. */
914 ccw_device_online_verify(cdev
, 0);
915 /* OK, i/o is dead now. Call interrupt handler. */
917 cdev
->handler(cdev
, cdev
->private->intparm
,
922 ccw_device_killing_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
926 ret
= ccw_device_cancel_halt_clear(cdev
);
928 ccw_device_set_timeout(cdev
, 3*HZ
);
931 /* Start delayed path verification. */
932 ccw_device_online_verify(cdev
, 0);
934 cdev
->handler(cdev
, cdev
->private->intparm
,
938 void ccw_device_kill_io(struct ccw_device
*cdev
)
942 ret
= ccw_device_cancel_halt_clear(cdev
);
944 ccw_device_set_timeout(cdev
, 3*HZ
);
945 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
948 /* Start delayed path verification. */
949 ccw_device_online_verify(cdev
, 0);
951 cdev
->handler(cdev
, cdev
->private->intparm
,
956 ccw_device_delay_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
958 /* Start verification after current task finished. */
959 cdev
->private->flags
.doverify
= 1;
963 ccw_device_stlck_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
968 case DEV_EVENT_INTERRUPT
:
969 irb
= (struct irb
*) __LC_IRB
;
970 /* Check for unsolicited interrupt. */
971 if ((scsw_stctl(&irb
->scsw
) ==
972 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) &&
973 (!scsw_cc(&irb
->scsw
)))
974 /* FIXME: we should restart stlck here, but this
975 * is extremely unlikely ... */
978 ccw_device_accumulate_irb(cdev
, irb
);
979 /* We don't care about basic sense etc. */
981 default: /* timeout */
985 wake_up(&cdev
->private->wait_q
);
989 ccw_device_start_id(struct ccw_device
*cdev
, enum dev_event dev_event
)
991 struct subchannel
*sch
;
993 sch
= to_subchannel(cdev
->dev
.parent
);
994 if (cio_enable_subchannel(sch
, (u32
)(addr_t
)sch
) != 0)
995 /* Couldn't enable the subchannel for i/o. Sick device. */
998 /* After 60s the device recognition is considered to have failed. */
999 ccw_device_set_timeout(cdev
, 60*HZ
);
1001 cdev
->private->state
= DEV_STATE_DISCONNECTED_SENSE_ID
;
1002 ccw_device_sense_id_start(cdev
);
1005 void ccw_device_trigger_reprobe(struct ccw_device
*cdev
)
1007 struct subchannel
*sch
;
1009 if (cdev
->private->state
!= DEV_STATE_DISCONNECTED
)
1012 sch
= to_subchannel(cdev
->dev
.parent
);
1013 /* Update some values. */
1014 if (stsch(sch
->schid
, &sch
->schib
))
1016 if (!sch
->schib
.pmcw
.dnv
)
1019 * The pim, pam, pom values may not be accurate, but they are the best
1020 * we have before performing device selection :/
1022 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
1023 /* Re-set some bits in the pmcw that were lost. */
1024 sch
->schib
.pmcw
.csense
= 1;
1025 sch
->schib
.pmcw
.ena
= 0;
1026 if ((sch
->lpm
& (sch
->lpm
- 1)) != 0)
1027 sch
->schib
.pmcw
.mp
= 1;
1028 /* We should also udate ssd info, but this has to wait. */
1029 /* Check if this is another device which appeared on the same sch. */
1030 if (sch
->schib
.pmcw
.dev
!= cdev
->private->dev_id
.devno
) {
1031 PREPARE_WORK(&cdev
->private->kick_work
,
1032 ccw_device_move_to_orphanage
);
1033 queue_work(slow_path_wq
, &cdev
->private->kick_work
);
1035 ccw_device_start_id(cdev
, 0);
1039 ccw_device_offline_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
1041 struct subchannel
*sch
;
1043 sch
= to_subchannel(cdev
->dev
.parent
);
1045 * An interrupt in state offline means a previous disable was not
1046 * successful. Try again.
1048 cio_disable_subchannel(sch
);
1052 ccw_device_change_cmfstate(struct ccw_device
*cdev
, enum dev_event dev_event
)
1054 retry_set_schib(cdev
);
1055 cdev
->private->state
= DEV_STATE_ONLINE
;
1056 dev_fsm_event(cdev
, dev_event
);
1059 static void ccw_device_update_cmfblock(struct ccw_device
*cdev
,
1060 enum dev_event dev_event
)
1062 cmf_retry_copy_block(cdev
);
1063 cdev
->private->state
= DEV_STATE_ONLINE
;
1064 dev_fsm_event(cdev
, dev_event
);
1068 ccw_device_quiesce_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
1070 ccw_device_set_timeout(cdev
, 0);
1071 if (dev_event
== DEV_EVENT_NOTOPER
)
1072 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1074 cdev
->private->state
= DEV_STATE_OFFLINE
;
1075 wake_up(&cdev
->private->wait_q
);
1079 ccw_device_quiesce_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
1083 ret
= ccw_device_cancel_halt_clear(cdev
);
1086 cdev
->private->state
= DEV_STATE_OFFLINE
;
1087 wake_up(&cdev
->private->wait_q
);
1090 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1091 wake_up(&cdev
->private->wait_q
);
1094 ccw_device_set_timeout(cdev
, HZ
/10);
1099 * No operation action. This is used e.g. to ignore a timeout event in
1103 ccw_device_nop(struct ccw_device
*cdev
, enum dev_event dev_event
)
1108 * Bug operation action.
1111 ccw_device_bug(struct ccw_device
*cdev
, enum dev_event dev_event
)
1113 CIO_MSG_EVENT(0, "Internal state [%i][%i] not handled for device "
1114 "0.%x.%04x\n", cdev
->private->state
, dev_event
,
1115 cdev
->private->dev_id
.ssid
,
1116 cdev
->private->dev_id
.devno
);
1121 * device statemachine
1123 fsm_func_t
*dev_jumptable
[NR_DEV_STATES
][NR_DEV_EVENTS
] = {
1124 [DEV_STATE_NOT_OPER
] = {
1125 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1126 [DEV_EVENT_INTERRUPT
] = ccw_device_bug
,
1127 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1128 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1130 [DEV_STATE_SENSE_PGID
] = {
1131 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1132 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_pgid_irq
,
1133 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1134 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1136 [DEV_STATE_SENSE_ID
] = {
1137 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1138 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1139 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1140 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1142 [DEV_STATE_OFFLINE
] = {
1143 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1144 [DEV_EVENT_INTERRUPT
] = ccw_device_offline_irq
,
1145 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1146 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1148 [DEV_STATE_VERIFY
] = {
1149 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1150 [DEV_EVENT_INTERRUPT
] = ccw_device_verify_irq
,
1151 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1152 [DEV_EVENT_VERIFY
] = ccw_device_delay_verify
,
1154 [DEV_STATE_ONLINE
] = {
1155 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1156 [DEV_EVENT_INTERRUPT
] = ccw_device_irq
,
1157 [DEV_EVENT_TIMEOUT
] = ccw_device_online_timeout
,
1158 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1160 [DEV_STATE_W4SENSE
] = {
1161 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1162 [DEV_EVENT_INTERRUPT
] = ccw_device_w4sense
,
1163 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1164 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1166 [DEV_STATE_DISBAND_PGID
] = {
1167 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1168 [DEV_EVENT_INTERRUPT
] = ccw_device_disband_irq
,
1169 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1170 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1172 [DEV_STATE_BOXED
] = {
1173 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1174 [DEV_EVENT_INTERRUPT
] = ccw_device_stlck_done
,
1175 [DEV_EVENT_TIMEOUT
] = ccw_device_stlck_done
,
1176 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1178 /* states to wait for i/o completion before doing something */
1179 [DEV_STATE_CLEAR_VERIFY
] = {
1180 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1181 [DEV_EVENT_INTERRUPT
] = ccw_device_clear_verify
,
1182 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1183 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1185 [DEV_STATE_TIMEOUT_KILL
] = {
1186 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1187 [DEV_EVENT_INTERRUPT
] = ccw_device_killing_irq
,
1188 [DEV_EVENT_TIMEOUT
] = ccw_device_killing_timeout
,
1189 [DEV_EVENT_VERIFY
] = ccw_device_nop
, //FIXME
1191 [DEV_STATE_QUIESCE
] = {
1192 [DEV_EVENT_NOTOPER
] = ccw_device_quiesce_done
,
1193 [DEV_EVENT_INTERRUPT
] = ccw_device_quiesce_done
,
1194 [DEV_EVENT_TIMEOUT
] = ccw_device_quiesce_timeout
,
1195 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1197 /* special states for devices gone not operational */
1198 [DEV_STATE_DISCONNECTED
] = {
1199 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1200 [DEV_EVENT_INTERRUPT
] = ccw_device_start_id
,
1201 [DEV_EVENT_TIMEOUT
] = ccw_device_bug
,
1202 [DEV_EVENT_VERIFY
] = ccw_device_start_id
,
1204 [DEV_STATE_DISCONNECTED_SENSE_ID
] = {
1205 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1206 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1207 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1208 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1210 [DEV_STATE_CMFCHANGE
] = {
1211 [DEV_EVENT_NOTOPER
] = ccw_device_change_cmfstate
,
1212 [DEV_EVENT_INTERRUPT
] = ccw_device_change_cmfstate
,
1213 [DEV_EVENT_TIMEOUT
] = ccw_device_change_cmfstate
,
1214 [DEV_EVENT_VERIFY
] = ccw_device_change_cmfstate
,
1216 [DEV_STATE_CMFUPDATE
] = {
1217 [DEV_EVENT_NOTOPER
] = ccw_device_update_cmfblock
,
1218 [DEV_EVENT_INTERRUPT
] = ccw_device_update_cmfblock
,
1219 [DEV_EVENT_TIMEOUT
] = ccw_device_update_cmfblock
,
1220 [DEV_EVENT_VERIFY
] = ccw_device_update_cmfblock
,
1224 EXPORT_SYMBOL_GPL(ccw_device_set_timeout
);