2 * finite state machine for device handling
4 * Copyright IBM Corp. 2002, 2008
5 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
6 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/jiffies.h>
12 #include <linux/string.h>
14 #include <asm/ccwdev.h>
16 #include <asm/chpid.h>
19 #include "cio_debug.h"
26 static int timeout_log_enabled
;
28 static int __init
ccw_timeout_log_setup(char *unused
)
30 timeout_log_enabled
= 1;
34 __setup("ccw_timeout_log", ccw_timeout_log_setup
);
36 static void ccw_timeout_log(struct ccw_device
*cdev
)
39 struct subchannel
*sch
;
40 struct io_subchannel_private
*private;
44 sch
= to_subchannel(cdev
->dev
.parent
);
45 private = to_io_private(sch
);
47 cc
= stsch_err(sch
->schid
, &schib
);
49 printk(KERN_WARNING
"cio: ccw device timeout occurred at %llx, "
50 "device information:\n", get_tod_clock());
51 printk(KERN_WARNING
"cio: orb:\n");
52 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
53 orb
, sizeof(*orb
), 0);
54 printk(KERN_WARNING
"cio: ccw device bus id: %s\n",
55 dev_name(&cdev
->dev
));
56 printk(KERN_WARNING
"cio: subchannel bus id: %s\n",
58 printk(KERN_WARNING
"cio: subchannel lpm: %02x, opm: %02x, "
59 "vpm: %02x\n", sch
->lpm
, sch
->opm
, sch
->vpm
);
62 printk(KERN_WARNING
"cio: orb indicates transport mode\n");
63 printk(KERN_WARNING
"cio: last tcw:\n");
64 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
65 (void *)(addr_t
)orb
->tm
.tcw
,
66 sizeof(struct tcw
), 0);
68 printk(KERN_WARNING
"cio: orb indicates command mode\n");
69 if ((void *)(addr_t
)orb
->cmd
.cpa
== &private->sense_ccw
||
70 (void *)(addr_t
)orb
->cmd
.cpa
== cdev
->private->iccws
)
71 printk(KERN_WARNING
"cio: last channel program "
74 printk(KERN_WARNING
"cio: last channel program:\n");
76 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
77 (void *)(addr_t
)orb
->cmd
.cpa
,
78 sizeof(struct ccw1
), 0);
80 printk(KERN_WARNING
"cio: ccw device state: %d\n",
81 cdev
->private->state
);
82 printk(KERN_WARNING
"cio: store subchannel returned: cc=%d\n", cc
);
83 printk(KERN_WARNING
"cio: schib:\n");
84 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
85 &schib
, sizeof(schib
), 0);
86 printk(KERN_WARNING
"cio: ccw device flags:\n");
87 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
88 &cdev
->private->flags
, sizeof(cdev
->private->flags
), 0);
92 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
95 ccw_device_timeout(unsigned long data
)
97 struct ccw_device
*cdev
;
99 cdev
= (struct ccw_device
*) data
;
100 spin_lock_irq(cdev
->ccwlock
);
101 if (timeout_log_enabled
)
102 ccw_timeout_log(cdev
);
103 dev_fsm_event(cdev
, DEV_EVENT_TIMEOUT
);
104 spin_unlock_irq(cdev
->ccwlock
);
111 ccw_device_set_timeout(struct ccw_device
*cdev
, int expires
)
114 del_timer(&cdev
->private->timer
);
117 if (timer_pending(&cdev
->private->timer
)) {
118 if (mod_timer(&cdev
->private->timer
, jiffies
+ expires
))
121 cdev
->private->timer
.function
= ccw_device_timeout
;
122 cdev
->private->timer
.data
= (unsigned long) cdev
;
123 cdev
->private->timer
.expires
= jiffies
+ expires
;
124 add_timer(&cdev
->private->timer
);
128 * Cancel running i/o. This is called repeatedly since halt/clear are
129 * asynchronous operations. We do one try with cio_cancel, two tries
130 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
131 * Returns 0 if device now idle, -ENODEV for device not operational and
132 * -EBUSY if an interrupt is expected (either from halt/clear or from a
136 ccw_device_cancel_halt_clear(struct ccw_device
*cdev
)
138 struct subchannel
*sch
;
141 sch
= to_subchannel(cdev
->dev
.parent
);
142 if (cio_update_schib(sch
))
144 if (!sch
->schib
.pmcw
.ena
)
145 /* Not operational -> done. */
147 /* Stage 1: cancel io. */
148 if (!(scsw_actl(&sch
->schib
.scsw
) & SCSW_ACTL_HALT_PEND
) &&
149 !(scsw_actl(&sch
->schib
.scsw
) & SCSW_ACTL_CLEAR_PEND
)) {
150 if (!scsw_is_tm(&sch
->schib
.scsw
)) {
151 ret
= cio_cancel(sch
);
155 /* cancel io unsuccessful or not applicable (transport mode).
156 * Continue with asynchronous instructions. */
157 cdev
->private->iretry
= 3; /* 3 halt retries. */
159 if (!(scsw_actl(&sch
->schib
.scsw
) & SCSW_ACTL_CLEAR_PEND
)) {
160 /* Stage 2: halt io. */
161 if (cdev
->private->iretry
) {
162 cdev
->private->iretry
--;
165 return (ret
== 0) ? -EBUSY
: ret
;
167 /* halt io unsuccessful. */
168 cdev
->private->iretry
= 255; /* 255 clear retries. */
170 /* Stage 3: clear io. */
171 if (cdev
->private->iretry
) {
172 cdev
->private->iretry
--;
173 ret
= cio_clear (sch
);
174 return (ret
== 0) ? -EBUSY
: ret
;
176 /* Function was unsuccessful */
177 CIO_MSG_EVENT(0, "0.%x.%04x: could not stop I/O\n",
178 cdev
->private->dev_id
.ssid
, cdev
->private->dev_id
.devno
);
182 void ccw_device_update_sense_data(struct ccw_device
*cdev
)
184 memset(&cdev
->id
, 0, sizeof(cdev
->id
));
185 cdev
->id
.cu_type
= cdev
->private->senseid
.cu_type
;
186 cdev
->id
.cu_model
= cdev
->private->senseid
.cu_model
;
187 cdev
->id
.dev_type
= cdev
->private->senseid
.dev_type
;
188 cdev
->id
.dev_model
= cdev
->private->senseid
.dev_model
;
191 int ccw_device_test_sense_data(struct ccw_device
*cdev
)
193 return 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
;
200 * The machine won't give us any notification by machine check if a chpid has
201 * been varied online on the SE so we have to find out by magic (i. e. driving
202 * the channel subsystem to device selection and updating our path masks).
205 __recover_lost_chpids(struct subchannel
*sch
, int old_lpm
)
211 for (i
= 0; i
<8; i
++) {
213 if (!(sch
->lpm
& mask
))
217 chpid
.id
= sch
->schib
.pmcw
.chpid
[i
];
218 if (!chp_is_registered(chpid
))
219 css_schedule_eval_all();
224 * Stop device recognition.
227 ccw_device_recog_done(struct ccw_device
*cdev
, int state
)
229 struct subchannel
*sch
;
232 sch
= to_subchannel(cdev
->dev
.parent
);
234 if (cio_disable_subchannel(sch
))
235 state
= DEV_STATE_NOT_OPER
;
237 * Now that we tried recognition, we have performed device selection
238 * through ssch() and the path information is up to date.
242 /* Check since device may again have become not operational. */
243 if (cio_update_schib(sch
))
244 state
= DEV_STATE_NOT_OPER
;
246 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
248 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
)
249 /* Force reprobe on all chpids. */
251 if (sch
->lpm
!= old_lpm
)
252 __recover_lost_chpids(sch
, old_lpm
);
253 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
&&
254 (state
== DEV_STATE_NOT_OPER
|| state
== DEV_STATE_BOXED
)) {
255 cdev
->private->flags
.recog_done
= 1;
256 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
257 wake_up(&cdev
->private->wait_q
);
260 if (cdev
->private->flags
.resuming
) {
261 cdev
->private->state
= state
;
262 cdev
->private->flags
.recog_done
= 1;
263 wake_up(&cdev
->private->wait_q
);
267 case DEV_STATE_NOT_OPER
:
269 case DEV_STATE_OFFLINE
:
271 ccw_device_update_sense_data(cdev
);
274 cdev
->private->state
= DEV_STATE_OFFLINE
;
275 cdev
->private->flags
.recog_done
= 1;
276 if (ccw_device_test_sense_data(cdev
)) {
277 cdev
->private->flags
.donotify
= 1;
278 ccw_device_online(cdev
);
279 wake_up(&cdev
->private->wait_q
);
281 ccw_device_update_sense_data(cdev
);
282 ccw_device_sched_todo(cdev
, CDEV_TODO_REBIND
);
285 case DEV_STATE_BOXED
:
286 if (cdev
->id
.cu_type
!= 0) { /* device was recognized before */
287 cdev
->private->flags
.recog_done
= 1;
288 cdev
->private->state
= DEV_STATE_BOXED
;
289 wake_up(&cdev
->private->wait_q
);
294 cdev
->private->state
= state
;
295 io_subchannel_recog_done(cdev
);
296 wake_up(&cdev
->private->wait_q
);
300 * Function called from device_id.c after sense id has completed.
303 ccw_device_sense_id_done(struct ccw_device
*cdev
, int err
)
307 ccw_device_recog_done(cdev
, DEV_STATE_OFFLINE
);
309 case -ETIME
: /* Sense id stopped by timeout. */
310 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
313 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
319 * ccw_device_notify() - inform the device's driver about an event
320 * @cdev: device for which an event occurred
321 * @event: event that occurred
324 * -%EINVAL if the device is offline or has no driver.
325 * -%EOPNOTSUPP if the device's driver has no notifier registered.
326 * %NOTIFY_OK if the driver wants to keep the device.
327 * %NOTIFY_BAD if the driver doesn't want to keep the device.
329 int ccw_device_notify(struct ccw_device
*cdev
, int event
)
337 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
338 cdev
->private->dev_id
.ssid
, cdev
->private->dev_id
.devno
,
340 if (!cdev
->drv
->notify
) {
344 if (cdev
->drv
->notify(cdev
, event
))
352 static void ccw_device_oper_notify(struct ccw_device
*cdev
)
354 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
356 if (ccw_device_notify(cdev
, CIO_OPER
) == NOTIFY_OK
) {
357 /* Reenable channel measurements, if needed. */
358 ccw_device_sched_todo(cdev
, CDEV_TODO_ENABLE_CMF
);
359 /* Save indication for new paths. */
360 cdev
->private->path_new_mask
= sch
->vpm
;
363 /* Driver doesn't want device back. */
364 ccw_device_set_notoper(cdev
);
365 ccw_device_sched_todo(cdev
, CDEV_TODO_REBIND
);
369 * Finished with online/offline processing.
372 ccw_device_done(struct ccw_device
*cdev
, int state
)
374 struct subchannel
*sch
;
376 sch
= to_subchannel(cdev
->dev
.parent
);
378 ccw_device_set_timeout(cdev
, 0);
380 if (state
!= DEV_STATE_ONLINE
)
381 cio_disable_subchannel(sch
);
383 /* Reset device status. */
384 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
386 cdev
->private->state
= state
;
389 case DEV_STATE_BOXED
:
390 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
391 cdev
->private->dev_id
.devno
, sch
->schid
.sch_no
);
393 ccw_device_notify(cdev
, CIO_BOXED
) != NOTIFY_OK
)
394 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
395 cdev
->private->flags
.donotify
= 0;
397 case DEV_STATE_NOT_OPER
:
398 CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n",
399 cdev
->private->dev_id
.devno
, sch
->schid
.sch_no
);
400 if (ccw_device_notify(cdev
, CIO_GONE
) != NOTIFY_OK
)
401 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
403 ccw_device_set_disconnected(cdev
);
404 cdev
->private->flags
.donotify
= 0;
406 case DEV_STATE_DISCONNECTED
:
407 CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel "
408 "%04x\n", cdev
->private->dev_id
.devno
,
410 if (ccw_device_notify(cdev
, CIO_NO_PATH
) != NOTIFY_OK
) {
411 cdev
->private->state
= DEV_STATE_NOT_OPER
;
412 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
414 ccw_device_set_disconnected(cdev
);
415 cdev
->private->flags
.donotify
= 0;
421 if (cdev
->private->flags
.donotify
) {
422 cdev
->private->flags
.donotify
= 0;
423 ccw_device_oper_notify(cdev
);
425 wake_up(&cdev
->private->wait_q
);
429 * Start device recognition.
431 void ccw_device_recognition(struct ccw_device
*cdev
)
433 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
436 * We used to start here with a sense pgid to find out whether a device
437 * is locked by someone else. Unfortunately, the sense pgid command
438 * code has other meanings on devices predating the path grouping
439 * algorithm, so we start with sense id and box the device after an
440 * timeout (or if sense pgid during path verification detects the device
441 * is locked, as may happen on newer devices).
443 cdev
->private->flags
.recog_done
= 0;
444 cdev
->private->state
= DEV_STATE_SENSE_ID
;
445 if (cio_enable_subchannel(sch
, (u32
) (addr_t
) sch
)) {
446 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
449 ccw_device_sense_id_start(cdev
);
453 * Handle events for states that use the ccw request infrastructure.
455 static void ccw_device_request_event(struct ccw_device
*cdev
, enum dev_event e
)
458 case DEV_EVENT_NOTOPER
:
459 ccw_request_notoper(cdev
);
461 case DEV_EVENT_INTERRUPT
:
462 ccw_request_handler(cdev
);
464 case DEV_EVENT_TIMEOUT
:
465 ccw_request_timeout(cdev
);
472 static void ccw_device_report_path_events(struct ccw_device
*cdev
)
474 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
478 for (chp
= 0, mask
= 0x80; chp
< 8; chp
++, mask
>>= 1) {
479 path_event
[chp
] = PE_NONE
;
480 if (mask
& cdev
->private->path_gone_mask
& ~(sch
->vpm
))
481 path_event
[chp
] |= PE_PATH_GONE
;
482 if (mask
& cdev
->private->path_new_mask
& sch
->vpm
)
483 path_event
[chp
] |= PE_PATH_AVAILABLE
;
484 if (mask
& cdev
->private->pgid_reset_mask
& sch
->vpm
)
485 path_event
[chp
] |= PE_PATHGROUP_ESTABLISHED
;
487 if (cdev
->online
&& cdev
->drv
->path_event
)
488 cdev
->drv
->path_event(cdev
, path_event
);
491 static void ccw_device_reset_path_events(struct ccw_device
*cdev
)
493 cdev
->private->path_gone_mask
= 0;
494 cdev
->private->path_new_mask
= 0;
495 cdev
->private->pgid_reset_mask
= 0;
498 static void create_fake_irb(struct irb
*irb
, int type
)
500 memset(irb
, 0, sizeof(*irb
));
501 if (type
== FAKE_CMD_IRB
) {
502 struct cmd_scsw
*scsw
= &irb
->scsw
.cmd
;
504 scsw
->fctl
= SCSW_FCTL_START_FUNC
;
505 scsw
->actl
= SCSW_ACTL_START_PEND
;
506 scsw
->stctl
= SCSW_STCTL_STATUS_PEND
;
507 } else if (type
== FAKE_TM_IRB
) {
508 struct tm_scsw
*scsw
= &irb
->scsw
.tm
;
511 scsw
->fctl
= SCSW_FCTL_START_FUNC
;
512 scsw
->actl
= SCSW_ACTL_START_PEND
;
513 scsw
->stctl
= SCSW_STCTL_STATUS_PEND
;
517 void ccw_device_verify_done(struct ccw_device
*cdev
, int err
)
519 struct subchannel
*sch
;
521 sch
= to_subchannel(cdev
->dev
.parent
);
522 /* Update schib - pom may have changed. */
523 if (cio_update_schib(sch
)) {
527 /* Update lpm with verified path mask. */
529 /* Repeat path verification? */
530 if (cdev
->private->flags
.doverify
) {
531 ccw_device_verify_start(cdev
);
537 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
538 /* Deliver fake irb to device driver, if needed. */
539 if (cdev
->private->flags
.fake_irb
) {
540 create_fake_irb(&cdev
->private->irb
,
541 cdev
->private->flags
.fake_irb
);
542 cdev
->private->flags
.fake_irb
= 0;
544 cdev
->handler(cdev
, cdev
->private->intparm
,
545 &cdev
->private->irb
);
546 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
548 ccw_device_report_path_events(cdev
);
552 /* Reset oper notify indication after verify error. */
553 cdev
->private->flags
.donotify
= 0;
554 ccw_device_done(cdev
, DEV_STATE_BOXED
);
557 /* Reset oper notify indication after verify error. */
558 cdev
->private->flags
.donotify
= 0;
559 ccw_device_done(cdev
, DEV_STATE_DISCONNECTED
);
562 /* Reset oper notify indication after verify error. */
563 cdev
->private->flags
.donotify
= 0;
564 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
567 ccw_device_reset_path_events(cdev
);
574 ccw_device_online(struct ccw_device
*cdev
)
576 struct subchannel
*sch
;
579 if ((cdev
->private->state
!= DEV_STATE_OFFLINE
) &&
580 (cdev
->private->state
!= DEV_STATE_BOXED
))
582 sch
= to_subchannel(cdev
->dev
.parent
);
583 ret
= cio_enable_subchannel(sch
, (u32
)(addr_t
)sch
);
585 /* Couldn't enable the subchannel for i/o. Sick device. */
587 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
590 /* Start initial path verification. */
591 cdev
->private->state
= DEV_STATE_VERIFY
;
592 ccw_device_verify_start(cdev
);
597 ccw_device_disband_done(struct ccw_device
*cdev
, int err
)
601 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
604 ccw_device_done(cdev
, DEV_STATE_BOXED
);
607 cdev
->private->flags
.donotify
= 0;
608 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
617 ccw_device_offline(struct ccw_device
*cdev
)
619 struct subchannel
*sch
;
621 /* Allow ccw_device_offline while disconnected. */
622 if (cdev
->private->state
== DEV_STATE_DISCONNECTED
||
623 cdev
->private->state
== DEV_STATE_NOT_OPER
) {
624 cdev
->private->flags
.donotify
= 0;
625 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
628 if (cdev
->private->state
== DEV_STATE_BOXED
) {
629 ccw_device_done(cdev
, DEV_STATE_BOXED
);
632 if (ccw_device_is_orphan(cdev
)) {
633 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
636 sch
= to_subchannel(cdev
->dev
.parent
);
637 if (cio_update_schib(sch
))
639 if (scsw_actl(&sch
->schib
.scsw
) != 0)
641 if (cdev
->private->state
!= DEV_STATE_ONLINE
)
643 /* Are we doing path grouping? */
644 if (!cdev
->private->flags
.pgroup
) {
645 /* No, set state offline immediately. */
646 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
649 /* Start Set Path Group commands. */
650 cdev
->private->state
= DEV_STATE_DISBAND_PGID
;
651 ccw_device_disband_start(cdev
);
656 * Handle not operational event in non-special state.
658 static void ccw_device_generic_notoper(struct ccw_device
*cdev
,
659 enum dev_event dev_event
)
661 if (ccw_device_notify(cdev
, CIO_GONE
) != NOTIFY_OK
)
662 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
664 ccw_device_set_disconnected(cdev
);
668 * Handle path verification event in offline state.
670 static void ccw_device_offline_verify(struct ccw_device
*cdev
,
671 enum dev_event dev_event
)
673 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
675 css_schedule_eval(sch
->schid
);
679 * Handle path verification event.
682 ccw_device_online_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
684 struct subchannel
*sch
;
686 if (cdev
->private->state
== DEV_STATE_W4SENSE
) {
687 cdev
->private->flags
.doverify
= 1;
690 sch
= to_subchannel(cdev
->dev
.parent
);
692 * Since we might not just be coming from an interrupt from the
693 * subchannel we have to update the schib.
695 if (cio_update_schib(sch
)) {
696 ccw_device_verify_done(cdev
, -ENODEV
);
700 if (scsw_actl(&sch
->schib
.scsw
) != 0 ||
701 (scsw_stctl(&sch
->schib
.scsw
) & SCSW_STCTL_STATUS_PEND
) ||
702 (scsw_stctl(&cdev
->private->irb
.scsw
) & SCSW_STCTL_STATUS_PEND
)) {
704 * No final status yet or final status not yet delivered
705 * to the device driver. Can't do path verification now,
706 * delay until final status was delivered.
708 cdev
->private->flags
.doverify
= 1;
711 /* Device is idle, we can do the path verification. */
712 cdev
->private->state
= DEV_STATE_VERIFY
;
713 ccw_device_verify_start(cdev
);
717 * Handle path verification event in boxed state.
719 static void ccw_device_boxed_verify(struct ccw_device
*cdev
,
720 enum dev_event dev_event
)
722 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
725 if (cio_enable_subchannel(sch
, (u32
) (addr_t
) sch
))
726 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
728 ccw_device_online_verify(cdev
, dev_event
);
730 css_schedule_eval(sch
->schid
);
734 * Got an interrupt for a normal io (state online).
737 ccw_device_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
742 irb
= this_cpu_ptr(&cio_irb
);
743 is_cmd
= !scsw_is_tm(&irb
->scsw
);
744 /* Check for unsolicited interrupt. */
745 if (!scsw_is_solicited(&irb
->scsw
)) {
746 if (is_cmd
&& (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) &&
747 !irb
->esw
.esw0
.erw
.cons
) {
748 /* Unit check but no sense data. Need basic sense. */
749 if (ccw_device_do_sense(cdev
, irb
) != 0)
750 goto call_handler_unsol
;
751 memcpy(&cdev
->private->irb
, irb
, sizeof(struct irb
));
752 cdev
->private->state
= DEV_STATE_W4SENSE
;
753 cdev
->private->intparm
= 0;
758 cdev
->handler (cdev
, 0, irb
);
759 if (cdev
->private->flags
.doverify
)
760 ccw_device_online_verify(cdev
, 0);
763 /* Accumulate status and find out if a basic sense is needed. */
764 ccw_device_accumulate_irb(cdev
, irb
);
765 if (is_cmd
&& cdev
->private->flags
.dosense
) {
766 if (ccw_device_do_sense(cdev
, irb
) == 0) {
767 cdev
->private->state
= DEV_STATE_W4SENSE
;
771 /* Call the handler. */
772 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
773 /* Start delayed path verification. */
774 ccw_device_online_verify(cdev
, 0);
778 * Got an timeout in online state.
781 ccw_device_online_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
785 ccw_device_set_timeout(cdev
, 0);
786 cdev
->private->iretry
= 255;
787 ret
= ccw_device_cancel_halt_clear(cdev
);
789 ccw_device_set_timeout(cdev
, 3*HZ
);
790 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
794 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
795 else if (cdev
->handler
)
796 cdev
->handler(cdev
, cdev
->private->intparm
,
797 ERR_PTR(-ETIMEDOUT
));
801 * Got an interrupt for a basic sense.
804 ccw_device_w4sense(struct ccw_device
*cdev
, enum dev_event dev_event
)
808 irb
= this_cpu_ptr(&cio_irb
);
809 /* Check for unsolicited interrupt. */
810 if (scsw_stctl(&irb
->scsw
) ==
811 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
812 if (scsw_cc(&irb
->scsw
) == 1)
813 /* Basic sense hasn't started. Try again. */
814 ccw_device_do_sense(cdev
, irb
);
816 CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
817 "interrupt during w4sense...\n",
818 cdev
->private->dev_id
.ssid
,
819 cdev
->private->dev_id
.devno
);
821 cdev
->handler (cdev
, 0, irb
);
826 * Check if a halt or clear has been issued in the meanwhile. If yes,
827 * only deliver the halt/clear interrupt to the device driver as if it
828 * had killed the original request.
830 if (scsw_fctl(&irb
->scsw
) &
831 (SCSW_FCTL_CLEAR_FUNC
| SCSW_FCTL_HALT_FUNC
)) {
832 cdev
->private->flags
.dosense
= 0;
833 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
834 ccw_device_accumulate_irb(cdev
, irb
);
837 /* Add basic sense info to irb. */
838 ccw_device_accumulate_basic_sense(cdev
, irb
);
839 if (cdev
->private->flags
.dosense
) {
840 /* Another basic sense is needed. */
841 ccw_device_do_sense(cdev
, irb
);
845 cdev
->private->state
= DEV_STATE_ONLINE
;
846 /* In case sensing interfered with setting the device online */
847 wake_up(&cdev
->private->wait_q
);
848 /* Call the handler. */
849 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
850 /* Start delayed path verification. */
851 ccw_device_online_verify(cdev
, 0);
855 ccw_device_killing_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
857 ccw_device_set_timeout(cdev
, 0);
858 /* Start delayed path verification. */
859 ccw_device_online_verify(cdev
, 0);
860 /* OK, i/o is dead now. Call interrupt handler. */
862 cdev
->handler(cdev
, cdev
->private->intparm
,
867 ccw_device_killing_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
871 ret
= ccw_device_cancel_halt_clear(cdev
);
873 ccw_device_set_timeout(cdev
, 3*HZ
);
876 /* Start delayed path verification. */
877 ccw_device_online_verify(cdev
, 0);
879 cdev
->handler(cdev
, cdev
->private->intparm
,
883 void ccw_device_kill_io(struct ccw_device
*cdev
)
887 cdev
->private->iretry
= 255;
888 ret
= ccw_device_cancel_halt_clear(cdev
);
890 ccw_device_set_timeout(cdev
, 3*HZ
);
891 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
894 /* Start delayed path verification. */
895 ccw_device_online_verify(cdev
, 0);
897 cdev
->handler(cdev
, cdev
->private->intparm
,
902 ccw_device_delay_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
904 /* Start verification after current task finished. */
905 cdev
->private->flags
.doverify
= 1;
909 ccw_device_start_id(struct ccw_device
*cdev
, enum dev_event dev_event
)
911 struct subchannel
*sch
;
913 sch
= to_subchannel(cdev
->dev
.parent
);
914 if (cio_enable_subchannel(sch
, (u32
)(addr_t
)sch
) != 0)
915 /* Couldn't enable the subchannel for i/o. Sick device. */
917 cdev
->private->state
= DEV_STATE_DISCONNECTED_SENSE_ID
;
918 ccw_device_sense_id_start(cdev
);
921 void ccw_device_trigger_reprobe(struct ccw_device
*cdev
)
923 struct subchannel
*sch
;
925 if (cdev
->private->state
!= DEV_STATE_DISCONNECTED
)
928 sch
= to_subchannel(cdev
->dev
.parent
);
929 /* Update some values. */
930 if (cio_update_schib(sch
))
933 * The pim, pam, pom values may not be accurate, but they are the best
934 * we have before performing device selection :/
936 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
938 * Use the initial configuration since we can't be shure that the old
941 io_subchannel_init_config(sch
);
942 if (cio_commit_config(sch
))
945 /* We should also udate ssd info, but this has to wait. */
946 /* Check if this is another device which appeared on the same sch. */
947 if (sch
->schib
.pmcw
.dev
!= cdev
->private->dev_id
.devno
)
948 css_schedule_eval(sch
->schid
);
950 ccw_device_start_id(cdev
, 0);
953 static void ccw_device_disabled_irq(struct ccw_device
*cdev
,
954 enum dev_event dev_event
)
956 struct subchannel
*sch
;
958 sch
= to_subchannel(cdev
->dev
.parent
);
960 * An interrupt in a disabled state means a previous disable was not
961 * successful - should not happen, but we try to disable again.
963 cio_disable_subchannel(sch
);
967 ccw_device_change_cmfstate(struct ccw_device
*cdev
, enum dev_event dev_event
)
969 retry_set_schib(cdev
);
970 cdev
->private->state
= DEV_STATE_ONLINE
;
971 dev_fsm_event(cdev
, dev_event
);
974 static void ccw_device_update_cmfblock(struct ccw_device
*cdev
,
975 enum dev_event dev_event
)
977 cmf_retry_copy_block(cdev
);
978 cdev
->private->state
= DEV_STATE_ONLINE
;
979 dev_fsm_event(cdev
, dev_event
);
983 ccw_device_quiesce_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
985 ccw_device_set_timeout(cdev
, 0);
986 cdev
->private->state
= DEV_STATE_NOT_OPER
;
987 wake_up(&cdev
->private->wait_q
);
991 ccw_device_quiesce_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
995 ret
= ccw_device_cancel_halt_clear(cdev
);
997 ccw_device_set_timeout(cdev
, HZ
/10);
999 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1000 wake_up(&cdev
->private->wait_q
);
1005 * No operation action. This is used e.g. to ignore a timeout event in
1009 ccw_device_nop(struct ccw_device
*cdev
, enum dev_event dev_event
)
1014 * device statemachine
1016 fsm_func_t
*dev_jumptable
[NR_DEV_STATES
][NR_DEV_EVENTS
] = {
1017 [DEV_STATE_NOT_OPER
] = {
1018 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1019 [DEV_EVENT_INTERRUPT
] = ccw_device_disabled_irq
,
1020 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1021 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1023 [DEV_STATE_SENSE_PGID
] = {
1024 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1025 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1026 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1027 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1029 [DEV_STATE_SENSE_ID
] = {
1030 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1031 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1032 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1033 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1035 [DEV_STATE_OFFLINE
] = {
1036 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1037 [DEV_EVENT_INTERRUPT
] = ccw_device_disabled_irq
,
1038 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1039 [DEV_EVENT_VERIFY
] = ccw_device_offline_verify
,
1041 [DEV_STATE_VERIFY
] = {
1042 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1043 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1044 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1045 [DEV_EVENT_VERIFY
] = ccw_device_delay_verify
,
1047 [DEV_STATE_ONLINE
] = {
1048 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1049 [DEV_EVENT_INTERRUPT
] = ccw_device_irq
,
1050 [DEV_EVENT_TIMEOUT
] = ccw_device_online_timeout
,
1051 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1053 [DEV_STATE_W4SENSE
] = {
1054 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1055 [DEV_EVENT_INTERRUPT
] = ccw_device_w4sense
,
1056 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1057 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1059 [DEV_STATE_DISBAND_PGID
] = {
1060 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1061 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1062 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1063 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1065 [DEV_STATE_BOXED
] = {
1066 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1067 [DEV_EVENT_INTERRUPT
] = ccw_device_nop
,
1068 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1069 [DEV_EVENT_VERIFY
] = ccw_device_boxed_verify
,
1071 /* states to wait for i/o completion before doing something */
1072 [DEV_STATE_TIMEOUT_KILL
] = {
1073 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1074 [DEV_EVENT_INTERRUPT
] = ccw_device_killing_irq
,
1075 [DEV_EVENT_TIMEOUT
] = ccw_device_killing_timeout
,
1076 [DEV_EVENT_VERIFY
] = ccw_device_nop
, //FIXME
1078 [DEV_STATE_QUIESCE
] = {
1079 [DEV_EVENT_NOTOPER
] = ccw_device_quiesce_done
,
1080 [DEV_EVENT_INTERRUPT
] = ccw_device_quiesce_done
,
1081 [DEV_EVENT_TIMEOUT
] = ccw_device_quiesce_timeout
,
1082 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1084 /* special states for devices gone not operational */
1085 [DEV_STATE_DISCONNECTED
] = {
1086 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1087 [DEV_EVENT_INTERRUPT
] = ccw_device_start_id
,
1088 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1089 [DEV_EVENT_VERIFY
] = ccw_device_start_id
,
1091 [DEV_STATE_DISCONNECTED_SENSE_ID
] = {
1092 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1093 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1094 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1095 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1097 [DEV_STATE_CMFCHANGE
] = {
1098 [DEV_EVENT_NOTOPER
] = ccw_device_change_cmfstate
,
1099 [DEV_EVENT_INTERRUPT
] = ccw_device_change_cmfstate
,
1100 [DEV_EVENT_TIMEOUT
] = ccw_device_change_cmfstate
,
1101 [DEV_EVENT_VERIFY
] = ccw_device_change_cmfstate
,
1103 [DEV_STATE_CMFUPDATE
] = {
1104 [DEV_EVENT_NOTOPER
] = ccw_device_update_cmfblock
,
1105 [DEV_EVENT_INTERRUPT
] = ccw_device_update_cmfblock
,
1106 [DEV_EVENT_TIMEOUT
] = ccw_device_update_cmfblock
,
1107 [DEV_EVENT_VERIFY
] = ccw_device_update_cmfblock
,
1109 [DEV_STATE_STEAL_LOCK
] = {
1110 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1111 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1112 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1113 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1117 EXPORT_SYMBOL_GPL(ccw_device_set_timeout
);