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(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 ccw_device_cancel_halt_clear(struct ccw_device
*cdev
)
130 struct subchannel
*sch
;
133 sch
= to_subchannel(cdev
->dev
.parent
);
134 ret
= cio_cancel_halt_clear(sch
, &cdev
->private->iretry
);
137 CIO_MSG_EVENT(0, "0.%x.%04x: could not stop I/O\n",
138 cdev
->private->dev_id
.ssid
,
139 cdev
->private->dev_id
.devno
);
144 void ccw_device_update_sense_data(struct ccw_device
*cdev
)
146 memset(&cdev
->id
, 0, sizeof(cdev
->id
));
147 cdev
->id
.cu_type
= cdev
->private->senseid
.cu_type
;
148 cdev
->id
.cu_model
= cdev
->private->senseid
.cu_model
;
149 cdev
->id
.dev_type
= cdev
->private->senseid
.dev_type
;
150 cdev
->id
.dev_model
= cdev
->private->senseid
.dev_model
;
153 int ccw_device_test_sense_data(struct ccw_device
*cdev
)
155 return cdev
->id
.cu_type
== cdev
->private->senseid
.cu_type
&&
156 cdev
->id
.cu_model
== cdev
->private->senseid
.cu_model
&&
157 cdev
->id
.dev_type
== cdev
->private->senseid
.dev_type
&&
158 cdev
->id
.dev_model
== cdev
->private->senseid
.dev_model
;
162 * The machine won't give us any notification by machine check if a chpid has
163 * been varied online on the SE so we have to find out by magic (i. e. driving
164 * the channel subsystem to device selection and updating our path masks).
167 __recover_lost_chpids(struct subchannel
*sch
, int old_lpm
)
173 for (i
= 0; i
<8; i
++) {
175 if (!(sch
->lpm
& mask
))
179 chpid
.id
= sch
->schib
.pmcw
.chpid
[i
];
180 if (!chp_is_registered(chpid
))
181 css_schedule_eval_all();
186 * Stop device recognition.
189 ccw_device_recog_done(struct ccw_device
*cdev
, int state
)
191 struct subchannel
*sch
;
194 sch
= to_subchannel(cdev
->dev
.parent
);
196 if (cio_disable_subchannel(sch
))
197 state
= DEV_STATE_NOT_OPER
;
199 * Now that we tried recognition, we have performed device selection
200 * through ssch() and the path information is up to date.
204 /* Check since device may again have become not operational. */
205 if (cio_update_schib(sch
))
206 state
= DEV_STATE_NOT_OPER
;
208 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
210 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
)
211 /* Force reprobe on all chpids. */
213 if (sch
->lpm
!= old_lpm
)
214 __recover_lost_chpids(sch
, old_lpm
);
215 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
&&
216 (state
== DEV_STATE_NOT_OPER
|| state
== DEV_STATE_BOXED
)) {
217 cdev
->private->flags
.recog_done
= 1;
218 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
219 wake_up(&cdev
->private->wait_q
);
222 if (cdev
->private->flags
.resuming
) {
223 cdev
->private->state
= state
;
224 cdev
->private->flags
.recog_done
= 1;
225 wake_up(&cdev
->private->wait_q
);
229 case DEV_STATE_NOT_OPER
:
231 case DEV_STATE_OFFLINE
:
233 ccw_device_update_sense_data(cdev
);
236 cdev
->private->state
= DEV_STATE_OFFLINE
;
237 cdev
->private->flags
.recog_done
= 1;
238 if (ccw_device_test_sense_data(cdev
)) {
239 cdev
->private->flags
.donotify
= 1;
240 ccw_device_online(cdev
);
241 wake_up(&cdev
->private->wait_q
);
243 ccw_device_update_sense_data(cdev
);
244 ccw_device_sched_todo(cdev
, CDEV_TODO_REBIND
);
247 case DEV_STATE_BOXED
:
248 if (cdev
->id
.cu_type
!= 0) { /* device was recognized before */
249 cdev
->private->flags
.recog_done
= 1;
250 cdev
->private->state
= DEV_STATE_BOXED
;
251 wake_up(&cdev
->private->wait_q
);
256 cdev
->private->state
= state
;
257 io_subchannel_recog_done(cdev
);
258 wake_up(&cdev
->private->wait_q
);
262 * Function called from device_id.c after sense id has completed.
265 ccw_device_sense_id_done(struct ccw_device
*cdev
, int err
)
269 ccw_device_recog_done(cdev
, DEV_STATE_OFFLINE
);
271 case -ETIME
: /* Sense id stopped by timeout. */
272 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
275 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
281 * ccw_device_notify() - inform the device's driver about an event
282 * @cdev: device for which an event occurred
283 * @event: event that occurred
286 * -%EINVAL if the device is offline or has no driver.
287 * -%EOPNOTSUPP if the device's driver has no notifier registered.
288 * %NOTIFY_OK if the driver wants to keep the device.
289 * %NOTIFY_BAD if the driver doesn't want to keep the device.
291 int ccw_device_notify(struct ccw_device
*cdev
, int event
)
299 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
300 cdev
->private->dev_id
.ssid
, cdev
->private->dev_id
.devno
,
302 if (!cdev
->drv
->notify
) {
306 if (cdev
->drv
->notify(cdev
, event
))
314 static void ccw_device_oper_notify(struct ccw_device
*cdev
)
316 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
318 if (ccw_device_notify(cdev
, CIO_OPER
) == NOTIFY_OK
) {
319 /* Reenable channel measurements, if needed. */
320 ccw_device_sched_todo(cdev
, CDEV_TODO_ENABLE_CMF
);
321 /* Save indication for new paths. */
322 cdev
->private->path_new_mask
= sch
->vpm
;
325 /* Driver doesn't want device back. */
326 ccw_device_set_notoper(cdev
);
327 ccw_device_sched_todo(cdev
, CDEV_TODO_REBIND
);
331 * Finished with online/offline processing.
334 ccw_device_done(struct ccw_device
*cdev
, int state
)
336 struct subchannel
*sch
;
338 sch
= to_subchannel(cdev
->dev
.parent
);
340 ccw_device_set_timeout(cdev
, 0);
342 if (state
!= DEV_STATE_ONLINE
)
343 cio_disable_subchannel(sch
);
345 /* Reset device status. */
346 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
348 cdev
->private->state
= state
;
351 case DEV_STATE_BOXED
:
352 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
353 cdev
->private->dev_id
.devno
, sch
->schid
.sch_no
);
355 ccw_device_notify(cdev
, CIO_BOXED
) != NOTIFY_OK
)
356 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
357 cdev
->private->flags
.donotify
= 0;
359 case DEV_STATE_NOT_OPER
:
360 CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n",
361 cdev
->private->dev_id
.devno
, sch
->schid
.sch_no
);
362 if (ccw_device_notify(cdev
, CIO_GONE
) != NOTIFY_OK
)
363 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
365 ccw_device_set_disconnected(cdev
);
366 cdev
->private->flags
.donotify
= 0;
368 case DEV_STATE_DISCONNECTED
:
369 CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel "
370 "%04x\n", cdev
->private->dev_id
.devno
,
372 if (ccw_device_notify(cdev
, CIO_NO_PATH
) != NOTIFY_OK
) {
373 cdev
->private->state
= DEV_STATE_NOT_OPER
;
374 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
376 ccw_device_set_disconnected(cdev
);
377 cdev
->private->flags
.donotify
= 0;
383 if (cdev
->private->flags
.donotify
) {
384 cdev
->private->flags
.donotify
= 0;
385 ccw_device_oper_notify(cdev
);
387 wake_up(&cdev
->private->wait_q
);
391 * Start device recognition.
393 void ccw_device_recognition(struct ccw_device
*cdev
)
395 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
398 * We used to start here with a sense pgid to find out whether a device
399 * is locked by someone else. Unfortunately, the sense pgid command
400 * code has other meanings on devices predating the path grouping
401 * algorithm, so we start with sense id and box the device after an
402 * timeout (or if sense pgid during path verification detects the device
403 * is locked, as may happen on newer devices).
405 cdev
->private->flags
.recog_done
= 0;
406 cdev
->private->state
= DEV_STATE_SENSE_ID
;
407 if (cio_enable_subchannel(sch
, (u32
) (addr_t
) sch
)) {
408 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
411 ccw_device_sense_id_start(cdev
);
415 * Handle events for states that use the ccw request infrastructure.
417 static void ccw_device_request_event(struct ccw_device
*cdev
, enum dev_event e
)
420 case DEV_EVENT_NOTOPER
:
421 ccw_request_notoper(cdev
);
423 case DEV_EVENT_INTERRUPT
:
424 ccw_request_handler(cdev
);
426 case DEV_EVENT_TIMEOUT
:
427 ccw_request_timeout(cdev
);
434 static void ccw_device_report_path_events(struct ccw_device
*cdev
)
436 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
440 for (chp
= 0, mask
= 0x80; chp
< 8; chp
++, mask
>>= 1) {
441 path_event
[chp
] = PE_NONE
;
442 if (mask
& cdev
->private->path_gone_mask
& ~(sch
->vpm
))
443 path_event
[chp
] |= PE_PATH_GONE
;
444 if (mask
& cdev
->private->path_new_mask
& sch
->vpm
)
445 path_event
[chp
] |= PE_PATH_AVAILABLE
;
446 if (mask
& cdev
->private->pgid_reset_mask
& sch
->vpm
)
447 path_event
[chp
] |= PE_PATHGROUP_ESTABLISHED
;
449 if (cdev
->online
&& cdev
->drv
->path_event
)
450 cdev
->drv
->path_event(cdev
, path_event
);
453 static void ccw_device_reset_path_events(struct ccw_device
*cdev
)
455 cdev
->private->path_gone_mask
= 0;
456 cdev
->private->path_new_mask
= 0;
457 cdev
->private->pgid_reset_mask
= 0;
460 static void create_fake_irb(struct irb
*irb
, int type
)
462 memset(irb
, 0, sizeof(*irb
));
463 if (type
== FAKE_CMD_IRB
) {
464 struct cmd_scsw
*scsw
= &irb
->scsw
.cmd
;
466 scsw
->fctl
= SCSW_FCTL_START_FUNC
;
467 scsw
->actl
= SCSW_ACTL_START_PEND
;
468 scsw
->stctl
= SCSW_STCTL_STATUS_PEND
;
469 } else if (type
== FAKE_TM_IRB
) {
470 struct tm_scsw
*scsw
= &irb
->scsw
.tm
;
473 scsw
->fctl
= SCSW_FCTL_START_FUNC
;
474 scsw
->actl
= SCSW_ACTL_START_PEND
;
475 scsw
->stctl
= SCSW_STCTL_STATUS_PEND
;
479 static void ccw_device_handle_broken_paths(struct ccw_device
*cdev
)
481 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
482 u8 broken_paths
= (sch
->schib
.pmcw
.pam
& sch
->opm
) ^ sch
->vpm
;
484 if (broken_paths
&& (cdev
->private->path_broken_mask
!= broken_paths
))
485 ccw_device_schedule_recovery();
487 cdev
->private->path_broken_mask
= broken_paths
;
490 void ccw_device_verify_done(struct ccw_device
*cdev
, int err
)
492 struct subchannel
*sch
;
494 sch
= to_subchannel(cdev
->dev
.parent
);
495 /* Update schib - pom may have changed. */
496 if (cio_update_schib(sch
)) {
500 /* Update lpm with verified path mask. */
502 /* Repeat path verification? */
503 if (cdev
->private->flags
.doverify
) {
504 ccw_device_verify_start(cdev
);
510 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
511 /* Deliver fake irb to device driver, if needed. */
512 if (cdev
->private->flags
.fake_irb
) {
513 create_fake_irb(&cdev
->private->irb
,
514 cdev
->private->flags
.fake_irb
);
515 cdev
->private->flags
.fake_irb
= 0;
517 cdev
->handler(cdev
, cdev
->private->intparm
,
518 &cdev
->private->irb
);
519 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
521 ccw_device_report_path_events(cdev
);
522 ccw_device_handle_broken_paths(cdev
);
526 /* Reset oper notify indication after verify error. */
527 cdev
->private->flags
.donotify
= 0;
528 ccw_device_done(cdev
, DEV_STATE_BOXED
);
531 /* Reset oper notify indication after verify error. */
532 cdev
->private->flags
.donotify
= 0;
533 ccw_device_done(cdev
, DEV_STATE_DISCONNECTED
);
536 /* Reset oper notify indication after verify error. */
537 cdev
->private->flags
.donotify
= 0;
538 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
541 ccw_device_reset_path_events(cdev
);
548 ccw_device_online(struct ccw_device
*cdev
)
550 struct subchannel
*sch
;
553 if ((cdev
->private->state
!= DEV_STATE_OFFLINE
) &&
554 (cdev
->private->state
!= DEV_STATE_BOXED
))
556 sch
= to_subchannel(cdev
->dev
.parent
);
557 ret
= cio_enable_subchannel(sch
, (u32
)(addr_t
)sch
);
559 /* Couldn't enable the subchannel for i/o. Sick device. */
561 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
564 /* Start initial path verification. */
565 cdev
->private->state
= DEV_STATE_VERIFY
;
566 ccw_device_verify_start(cdev
);
571 ccw_device_disband_done(struct ccw_device
*cdev
, int err
)
575 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
578 ccw_device_done(cdev
, DEV_STATE_BOXED
);
581 cdev
->private->flags
.donotify
= 0;
582 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
591 ccw_device_offline(struct ccw_device
*cdev
)
593 struct subchannel
*sch
;
595 /* Allow ccw_device_offline while disconnected. */
596 if (cdev
->private->state
== DEV_STATE_DISCONNECTED
||
597 cdev
->private->state
== DEV_STATE_NOT_OPER
) {
598 cdev
->private->flags
.donotify
= 0;
599 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
602 if (cdev
->private->state
== DEV_STATE_BOXED
) {
603 ccw_device_done(cdev
, DEV_STATE_BOXED
);
606 if (ccw_device_is_orphan(cdev
)) {
607 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
610 sch
= to_subchannel(cdev
->dev
.parent
);
611 if (cio_update_schib(sch
))
613 if (scsw_actl(&sch
->schib
.scsw
) != 0)
615 if (cdev
->private->state
!= DEV_STATE_ONLINE
)
617 /* Are we doing path grouping? */
618 if (!cdev
->private->flags
.pgroup
) {
619 /* No, set state offline immediately. */
620 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
623 /* Start Set Path Group commands. */
624 cdev
->private->state
= DEV_STATE_DISBAND_PGID
;
625 ccw_device_disband_start(cdev
);
630 * Handle not operational event in non-special state.
632 static void ccw_device_generic_notoper(struct ccw_device
*cdev
,
633 enum dev_event dev_event
)
635 if (ccw_device_notify(cdev
, CIO_GONE
) != NOTIFY_OK
)
636 ccw_device_sched_todo(cdev
, CDEV_TODO_UNREG
);
638 ccw_device_set_disconnected(cdev
);
642 * Handle path verification event in offline state.
644 static void ccw_device_offline_verify(struct ccw_device
*cdev
,
645 enum dev_event dev_event
)
647 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
649 css_schedule_eval(sch
->schid
);
653 * Handle path verification event.
656 ccw_device_online_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
658 struct subchannel
*sch
;
660 if (cdev
->private->state
== DEV_STATE_W4SENSE
) {
661 cdev
->private->flags
.doverify
= 1;
664 sch
= to_subchannel(cdev
->dev
.parent
);
666 * Since we might not just be coming from an interrupt from the
667 * subchannel we have to update the schib.
669 if (cio_update_schib(sch
)) {
670 ccw_device_verify_done(cdev
, -ENODEV
);
674 if (scsw_actl(&sch
->schib
.scsw
) != 0 ||
675 (scsw_stctl(&sch
->schib
.scsw
) & SCSW_STCTL_STATUS_PEND
) ||
676 (scsw_stctl(&cdev
->private->irb
.scsw
) & SCSW_STCTL_STATUS_PEND
)) {
678 * No final status yet or final status not yet delivered
679 * to the device driver. Can't do path verification now,
680 * delay until final status was delivered.
682 cdev
->private->flags
.doverify
= 1;
685 /* Device is idle, we can do the path verification. */
686 cdev
->private->state
= DEV_STATE_VERIFY
;
687 ccw_device_verify_start(cdev
);
691 * Handle path verification event in boxed state.
693 static void ccw_device_boxed_verify(struct ccw_device
*cdev
,
694 enum dev_event dev_event
)
696 struct subchannel
*sch
= to_subchannel(cdev
->dev
.parent
);
699 if (cio_enable_subchannel(sch
, (u32
) (addr_t
) sch
))
700 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
702 ccw_device_online_verify(cdev
, dev_event
);
704 css_schedule_eval(sch
->schid
);
708 * Pass interrupt to device driver.
710 static int ccw_device_call_handler(struct ccw_device
*cdev
)
716 * we allow for the device action handler if .
717 * - we received ending status
718 * - the action handler requested to see all interrupts
719 * - we received an intermediate status
720 * - fast notification was requested (primary status)
721 * - unsolicited interrupts
723 stctl
= scsw_stctl(&cdev
->private->irb
.scsw
);
724 ending_status
= (stctl
& SCSW_STCTL_SEC_STATUS
) ||
725 (stctl
== (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)) ||
726 (stctl
== SCSW_STCTL_STATUS_PEND
);
727 if (!ending_status
&&
728 !cdev
->private->options
.repall
&&
729 !(stctl
& SCSW_STCTL_INTER_STATUS
) &&
730 !(cdev
->private->options
.fast
&&
731 (stctl
& SCSW_STCTL_PRIM_STATUS
)))
735 ccw_device_set_timeout(cdev
, 0);
738 cdev
->handler(cdev
, cdev
->private->intparm
,
739 &cdev
->private->irb
);
741 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
746 * Got an interrupt for a normal io (state online).
749 ccw_device_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
754 irb
= this_cpu_ptr(&cio_irb
);
755 is_cmd
= !scsw_is_tm(&irb
->scsw
);
756 /* Check for unsolicited interrupt. */
757 if (!scsw_is_solicited(&irb
->scsw
)) {
758 if (is_cmd
&& (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) &&
759 !irb
->esw
.esw0
.erw
.cons
) {
760 /* Unit check but no sense data. Need basic sense. */
761 if (ccw_device_do_sense(cdev
, irb
) != 0)
762 goto call_handler_unsol
;
763 memcpy(&cdev
->private->irb
, irb
, sizeof(struct irb
));
764 cdev
->private->state
= DEV_STATE_W4SENSE
;
765 cdev
->private->intparm
= 0;
770 cdev
->handler (cdev
, 0, irb
);
771 if (cdev
->private->flags
.doverify
)
772 ccw_device_online_verify(cdev
, 0);
775 /* Accumulate status and find out if a basic sense is needed. */
776 ccw_device_accumulate_irb(cdev
, irb
);
777 if (is_cmd
&& cdev
->private->flags
.dosense
) {
778 if (ccw_device_do_sense(cdev
, irb
) == 0) {
779 cdev
->private->state
= DEV_STATE_W4SENSE
;
783 /* Call the handler. */
784 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
785 /* Start delayed path verification. */
786 ccw_device_online_verify(cdev
, 0);
790 * Got an timeout in online state.
793 ccw_device_online_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
797 ccw_device_set_timeout(cdev
, 0);
798 cdev
->private->iretry
= 255;
799 ret
= ccw_device_cancel_halt_clear(cdev
);
801 ccw_device_set_timeout(cdev
, 3*HZ
);
802 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
806 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
807 else if (cdev
->handler
)
808 cdev
->handler(cdev
, cdev
->private->intparm
,
809 ERR_PTR(-ETIMEDOUT
));
813 * Got an interrupt for a basic sense.
816 ccw_device_w4sense(struct ccw_device
*cdev
, enum dev_event dev_event
)
820 irb
= this_cpu_ptr(&cio_irb
);
821 /* Check for unsolicited interrupt. */
822 if (scsw_stctl(&irb
->scsw
) ==
823 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
824 if (scsw_cc(&irb
->scsw
) == 1)
825 /* Basic sense hasn't started. Try again. */
826 ccw_device_do_sense(cdev
, irb
);
828 CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
829 "interrupt during w4sense...\n",
830 cdev
->private->dev_id
.ssid
,
831 cdev
->private->dev_id
.devno
);
833 cdev
->handler (cdev
, 0, irb
);
838 * Check if a halt or clear has been issued in the meanwhile. If yes,
839 * only deliver the halt/clear interrupt to the device driver as if it
840 * had killed the original request.
842 if (scsw_fctl(&irb
->scsw
) &
843 (SCSW_FCTL_CLEAR_FUNC
| SCSW_FCTL_HALT_FUNC
)) {
844 cdev
->private->flags
.dosense
= 0;
845 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
846 ccw_device_accumulate_irb(cdev
, irb
);
849 /* Add basic sense info to irb. */
850 ccw_device_accumulate_basic_sense(cdev
, irb
);
851 if (cdev
->private->flags
.dosense
) {
852 /* Another basic sense is needed. */
853 ccw_device_do_sense(cdev
, irb
);
857 cdev
->private->state
= DEV_STATE_ONLINE
;
858 /* In case sensing interfered with setting the device online */
859 wake_up(&cdev
->private->wait_q
);
860 /* Call the handler. */
861 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
862 /* Start delayed path verification. */
863 ccw_device_online_verify(cdev
, 0);
867 ccw_device_killing_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
869 ccw_device_set_timeout(cdev
, 0);
870 /* Start delayed path verification. */
871 ccw_device_online_verify(cdev
, 0);
872 /* OK, i/o is dead now. Call interrupt handler. */
874 cdev
->handler(cdev
, cdev
->private->intparm
,
879 ccw_device_killing_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
883 ret
= ccw_device_cancel_halt_clear(cdev
);
885 ccw_device_set_timeout(cdev
, 3*HZ
);
888 /* Start delayed path verification. */
889 ccw_device_online_verify(cdev
, 0);
891 cdev
->handler(cdev
, cdev
->private->intparm
,
895 void ccw_device_kill_io(struct ccw_device
*cdev
)
899 cdev
->private->iretry
= 255;
900 ret
= ccw_device_cancel_halt_clear(cdev
);
902 ccw_device_set_timeout(cdev
, 3*HZ
);
903 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
906 /* Start delayed path verification. */
907 ccw_device_online_verify(cdev
, 0);
909 cdev
->handler(cdev
, cdev
->private->intparm
,
914 ccw_device_delay_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
916 /* Start verification after current task finished. */
917 cdev
->private->flags
.doverify
= 1;
921 ccw_device_start_id(struct ccw_device
*cdev
, enum dev_event dev_event
)
923 struct subchannel
*sch
;
925 sch
= to_subchannel(cdev
->dev
.parent
);
926 if (cio_enable_subchannel(sch
, (u32
)(addr_t
)sch
) != 0)
927 /* Couldn't enable the subchannel for i/o. Sick device. */
929 cdev
->private->state
= DEV_STATE_DISCONNECTED_SENSE_ID
;
930 ccw_device_sense_id_start(cdev
);
933 void ccw_device_trigger_reprobe(struct ccw_device
*cdev
)
935 struct subchannel
*sch
;
937 if (cdev
->private->state
!= DEV_STATE_DISCONNECTED
)
940 sch
= to_subchannel(cdev
->dev
.parent
);
941 /* Update some values. */
942 if (cio_update_schib(sch
))
945 * The pim, pam, pom values may not be accurate, but they are the best
946 * we have before performing device selection :/
948 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
950 * Use the initial configuration since we can't be shure that the old
953 io_subchannel_init_config(sch
);
954 if (cio_commit_config(sch
))
957 /* We should also udate ssd info, but this has to wait. */
958 /* Check if this is another device which appeared on the same sch. */
959 if (sch
->schib
.pmcw
.dev
!= cdev
->private->dev_id
.devno
)
960 css_schedule_eval(sch
->schid
);
962 ccw_device_start_id(cdev
, 0);
965 static void ccw_device_disabled_irq(struct ccw_device
*cdev
,
966 enum dev_event dev_event
)
968 struct subchannel
*sch
;
970 sch
= to_subchannel(cdev
->dev
.parent
);
972 * An interrupt in a disabled state means a previous disable was not
973 * successful - should not happen, but we try to disable again.
975 cio_disable_subchannel(sch
);
979 ccw_device_change_cmfstate(struct ccw_device
*cdev
, enum dev_event dev_event
)
981 retry_set_schib(cdev
);
982 cdev
->private->state
= DEV_STATE_ONLINE
;
983 dev_fsm_event(cdev
, dev_event
);
986 static void ccw_device_update_cmfblock(struct ccw_device
*cdev
,
987 enum dev_event dev_event
)
989 cmf_retry_copy_block(cdev
);
990 cdev
->private->state
= DEV_STATE_ONLINE
;
991 dev_fsm_event(cdev
, dev_event
);
995 ccw_device_quiesce_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
997 ccw_device_set_timeout(cdev
, 0);
998 cdev
->private->state
= DEV_STATE_NOT_OPER
;
999 wake_up(&cdev
->private->wait_q
);
1003 ccw_device_quiesce_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
1007 ret
= ccw_device_cancel_halt_clear(cdev
);
1008 if (ret
== -EBUSY
) {
1009 ccw_device_set_timeout(cdev
, HZ
/10);
1011 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1012 wake_up(&cdev
->private->wait_q
);
1017 * No operation action. This is used e.g. to ignore a timeout event in
1021 ccw_device_nop(struct ccw_device
*cdev
, enum dev_event dev_event
)
1026 * device statemachine
1028 fsm_func_t
*dev_jumptable
[NR_DEV_STATES
][NR_DEV_EVENTS
] = {
1029 [DEV_STATE_NOT_OPER
] = {
1030 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1031 [DEV_EVENT_INTERRUPT
] = ccw_device_disabled_irq
,
1032 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1033 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1035 [DEV_STATE_SENSE_ID
] = {
1036 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1037 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1038 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1039 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1041 [DEV_STATE_OFFLINE
] = {
1042 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1043 [DEV_EVENT_INTERRUPT
] = ccw_device_disabled_irq
,
1044 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1045 [DEV_EVENT_VERIFY
] = ccw_device_offline_verify
,
1047 [DEV_STATE_VERIFY
] = {
1048 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1049 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1050 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1051 [DEV_EVENT_VERIFY
] = ccw_device_delay_verify
,
1053 [DEV_STATE_ONLINE
] = {
1054 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1055 [DEV_EVENT_INTERRUPT
] = ccw_device_irq
,
1056 [DEV_EVENT_TIMEOUT
] = ccw_device_online_timeout
,
1057 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1059 [DEV_STATE_W4SENSE
] = {
1060 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1061 [DEV_EVENT_INTERRUPT
] = ccw_device_w4sense
,
1062 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1063 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1065 [DEV_STATE_DISBAND_PGID
] = {
1066 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1067 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1068 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1069 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1071 [DEV_STATE_BOXED
] = {
1072 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1073 [DEV_EVENT_INTERRUPT
] = ccw_device_nop
,
1074 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1075 [DEV_EVENT_VERIFY
] = ccw_device_boxed_verify
,
1077 /* states to wait for i/o completion before doing something */
1078 [DEV_STATE_TIMEOUT_KILL
] = {
1079 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1080 [DEV_EVENT_INTERRUPT
] = ccw_device_killing_irq
,
1081 [DEV_EVENT_TIMEOUT
] = ccw_device_killing_timeout
,
1082 [DEV_EVENT_VERIFY
] = ccw_device_nop
, //FIXME
1084 [DEV_STATE_QUIESCE
] = {
1085 [DEV_EVENT_NOTOPER
] = ccw_device_quiesce_done
,
1086 [DEV_EVENT_INTERRUPT
] = ccw_device_quiesce_done
,
1087 [DEV_EVENT_TIMEOUT
] = ccw_device_quiesce_timeout
,
1088 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1090 /* special states for devices gone not operational */
1091 [DEV_STATE_DISCONNECTED
] = {
1092 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1093 [DEV_EVENT_INTERRUPT
] = ccw_device_start_id
,
1094 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1095 [DEV_EVENT_VERIFY
] = ccw_device_start_id
,
1097 [DEV_STATE_DISCONNECTED_SENSE_ID
] = {
1098 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1099 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1100 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1101 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1103 [DEV_STATE_CMFCHANGE
] = {
1104 [DEV_EVENT_NOTOPER
] = ccw_device_change_cmfstate
,
1105 [DEV_EVENT_INTERRUPT
] = ccw_device_change_cmfstate
,
1106 [DEV_EVENT_TIMEOUT
] = ccw_device_change_cmfstate
,
1107 [DEV_EVENT_VERIFY
] = ccw_device_change_cmfstate
,
1109 [DEV_STATE_CMFUPDATE
] = {
1110 [DEV_EVENT_NOTOPER
] = ccw_device_update_cmfblock
,
1111 [DEV_EVENT_INTERRUPT
] = ccw_device_update_cmfblock
,
1112 [DEV_EVENT_TIMEOUT
] = ccw_device_update_cmfblock
,
1113 [DEV_EVENT_VERIFY
] = ccw_device_update_cmfblock
,
1115 [DEV_STATE_STEAL_LOCK
] = {
1116 [DEV_EVENT_NOTOPER
] = ccw_device_request_event
,
1117 [DEV_EVENT_INTERRUPT
] = ccw_device_request_event
,
1118 [DEV_EVENT_TIMEOUT
] = ccw_device_request_event
,
1119 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1123 EXPORT_SYMBOL_GPL(ccw_device_set_timeout
);