2 * drivers/s390/cio/device_fsm.c
3 * finite state machine for device handling
5 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
7 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
8 * Martin Schwidefsky (schwidefsky@de.ibm.com)
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/jiffies.h>
14 #include <linux/string.h>
16 #include <asm/ccwdev.h>
18 #include <asm/chpid.h>
21 #include "cio_debug.h"
28 static int timeout_log_enabled
;
31 device_is_online(struct subchannel
*sch
)
33 struct ccw_device
*cdev
;
35 if (!sch
->dev
.driver_data
)
37 cdev
= sch
->dev
.driver_data
;
38 return (cdev
->private->state
== DEV_STATE_ONLINE
);
42 device_is_disconnected(struct subchannel
*sch
)
44 struct ccw_device
*cdev
;
46 if (!sch
->dev
.driver_data
)
48 cdev
= sch
->dev
.driver_data
;
49 return (cdev
->private->state
== DEV_STATE_DISCONNECTED
||
50 cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
);
54 device_set_disconnected(struct subchannel
*sch
)
56 struct ccw_device
*cdev
;
58 if (!sch
->dev
.driver_data
)
60 cdev
= sch
->dev
.driver_data
;
61 ccw_device_set_timeout(cdev
, 0);
62 cdev
->private->flags
.fake_irb
= 0;
63 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
66 void device_set_intretry(struct subchannel
*sch
)
68 struct ccw_device
*cdev
;
70 cdev
= sch
->dev
.driver_data
;
73 cdev
->private->flags
.intretry
= 1;
76 int device_trigger_verify(struct subchannel
*sch
)
78 struct ccw_device
*cdev
;
80 cdev
= sch
->dev
.driver_data
;
81 if (!cdev
|| !cdev
->online
)
83 dev_fsm_event(cdev
, DEV_EVENT_VERIFY
);
87 static int __init
ccw_timeout_log_setup(char *unused
)
89 timeout_log_enabled
= 1;
93 __setup("ccw_timeout_log", ccw_timeout_log_setup
);
95 static void ccw_timeout_log(struct ccw_device
*cdev
)
98 struct subchannel
*sch
;
101 sch
= to_subchannel(cdev
->dev
.parent
);
102 cc
= stsch(sch
->schid
, &schib
);
104 printk(KERN_WARNING
"cio: ccw device timeout occurred at %llx, "
105 "device information:\n", get_clock());
106 printk(KERN_WARNING
"cio: orb:\n");
107 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
108 &sch
->orb
, sizeof(sch
->orb
), 0);
109 printk(KERN_WARNING
"cio: ccw device bus id: %s\n", cdev
->dev
.bus_id
);
110 printk(KERN_WARNING
"cio: subchannel bus id: %s\n", sch
->dev
.bus_id
);
111 printk(KERN_WARNING
"cio: subchannel lpm: %02x, opm: %02x, "
112 "vpm: %02x\n", sch
->lpm
, sch
->opm
, sch
->vpm
);
114 if ((void *)(addr_t
)sch
->orb
.cpa
== &sch
->sense_ccw
||
115 (void *)(addr_t
)sch
->orb
.cpa
== cdev
->private->iccws
)
116 printk(KERN_WARNING
"cio: last channel program (intern):\n");
118 printk(KERN_WARNING
"cio: last channel program:\n");
120 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
121 (void *)(addr_t
)sch
->orb
.cpa
, sizeof(struct ccw1
), 0);
122 printk(KERN_WARNING
"cio: ccw device state: %d\n",
123 cdev
->private->state
);
124 printk(KERN_WARNING
"cio: store subchannel returned: cc=%d\n", cc
);
125 printk(KERN_WARNING
"cio: schib:\n");
126 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
127 &schib
, sizeof(schib
), 0);
128 printk(KERN_WARNING
"cio: ccw device flags:\n");
129 print_hex_dump(KERN_WARNING
, "cio: ", DUMP_PREFIX_NONE
, 16, 1,
130 &cdev
->private->flags
, sizeof(cdev
->private->flags
), 0);
134 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
137 ccw_device_timeout(unsigned long data
)
139 struct ccw_device
*cdev
;
141 cdev
= (struct ccw_device
*) data
;
142 spin_lock_irq(cdev
->ccwlock
);
143 if (timeout_log_enabled
)
144 ccw_timeout_log(cdev
);
145 dev_fsm_event(cdev
, DEV_EVENT_TIMEOUT
);
146 spin_unlock_irq(cdev
->ccwlock
);
153 ccw_device_set_timeout(struct ccw_device
*cdev
, int expires
)
156 del_timer(&cdev
->private->timer
);
159 if (timer_pending(&cdev
->private->timer
)) {
160 if (mod_timer(&cdev
->private->timer
, jiffies
+ expires
))
163 cdev
->private->timer
.function
= ccw_device_timeout
;
164 cdev
->private->timer
.data
= (unsigned long) cdev
;
165 cdev
->private->timer
.expires
= jiffies
+ expires
;
166 add_timer(&cdev
->private->timer
);
169 /* Kill any pending timers after machine check. */
171 device_kill_pending_timer(struct subchannel
*sch
)
173 struct ccw_device
*cdev
;
175 if (!sch
->dev
.driver_data
)
177 cdev
= sch
->dev
.driver_data
;
178 ccw_device_set_timeout(cdev
, 0);
182 * Cancel running i/o. This is called repeatedly since halt/clear are
183 * asynchronous operations. We do one try with cio_cancel, two tries
184 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
185 * Returns 0 if device now idle, -ENODEV for device not operational and
186 * -EBUSY if an interrupt is expected (either from halt/clear or from a
190 ccw_device_cancel_halt_clear(struct ccw_device
*cdev
)
192 struct subchannel
*sch
;
195 sch
= to_subchannel(cdev
->dev
.parent
);
196 ret
= stsch(sch
->schid
, &sch
->schib
);
197 if (ret
|| !sch
->schib
.pmcw
.dnv
)
199 if (!sch
->schib
.pmcw
.ena
)
200 /* Not operational -> done. */
202 /* Stage 1: cancel io. */
203 if (!(sch
->schib
.scsw
.actl
& SCSW_ACTL_HALT_PEND
) &&
204 !(sch
->schib
.scsw
.actl
& SCSW_ACTL_CLEAR_PEND
)) {
205 ret
= cio_cancel(sch
);
208 /* cancel io unsuccessful. From now on it is asynchronous. */
209 cdev
->private->iretry
= 3; /* 3 halt retries. */
211 if (!(sch
->schib
.scsw
.actl
& SCSW_ACTL_CLEAR_PEND
)) {
212 /* Stage 2: halt io. */
213 if (cdev
->private->iretry
) {
214 cdev
->private->iretry
--;
217 return (ret
== 0) ? -EBUSY
: ret
;
219 /* halt io unsuccessful. */
220 cdev
->private->iretry
= 255; /* 255 clear retries. */
222 /* Stage 3: clear io. */
223 if (cdev
->private->iretry
) {
224 cdev
->private->iretry
--;
225 ret
= cio_clear (sch
);
226 return (ret
== 0) ? -EBUSY
: ret
;
228 panic("Can't stop i/o on subchannel.\n");
232 ccw_device_handle_oper(struct ccw_device
*cdev
)
234 struct subchannel
*sch
;
236 sch
= to_subchannel(cdev
->dev
.parent
);
237 cdev
->private->flags
.recog_done
= 1;
239 * Check if cu type and device type still match. If
240 * not, it is certainly another device and we have to
241 * de- and re-register.
243 if (cdev
->id
.cu_type
!= cdev
->private->senseid
.cu_type
||
244 cdev
->id
.cu_model
!= cdev
->private->senseid
.cu_model
||
245 cdev
->id
.dev_type
!= cdev
->private->senseid
.dev_type
||
246 cdev
->id
.dev_model
!= cdev
->private->senseid
.dev_model
) {
247 PREPARE_WORK(&cdev
->private->kick_work
,
248 ccw_device_do_unreg_rereg
);
249 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
252 cdev
->private->flags
.donotify
= 1;
257 * The machine won't give us any notification by machine check if a chpid has
258 * been varied online on the SE so we have to find out by magic (i. e. driving
259 * the channel subsystem to device selection and updating our path masks).
262 __recover_lost_chpids(struct subchannel
*sch
, int old_lpm
)
268 for (i
= 0; i
<8; i
++) {
270 if (!(sch
->lpm
& mask
))
274 chpid
.id
= sch
->schib
.pmcw
.chpid
[i
];
275 if (!chp_is_registered(chpid
))
276 css_schedule_eval_all();
281 * Stop device recognition.
284 ccw_device_recog_done(struct ccw_device
*cdev
, int state
)
286 struct subchannel
*sch
;
287 int notify
, old_lpm
, same_dev
;
289 sch
= to_subchannel(cdev
->dev
.parent
);
291 ccw_device_set_timeout(cdev
, 0);
292 cio_disable_subchannel(sch
);
294 * Now that we tried recognition, we have performed device selection
295 * through ssch() and the path information is up to date.
298 stsch(sch
->schid
, &sch
->schib
);
299 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
300 /* Check since device may again have become not operational. */
301 if (!sch
->schib
.pmcw
.dnv
)
302 state
= DEV_STATE_NOT_OPER
;
303 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
)
304 /* Force reprobe on all chpids. */
306 if (sch
->lpm
!= old_lpm
)
307 __recover_lost_chpids(sch
, old_lpm
);
308 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
309 if (state
== DEV_STATE_NOT_OPER
) {
310 cdev
->private->flags
.recog_done
= 1;
311 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
314 /* Boxed devices don't need extra treatment. */
317 same_dev
= 0; /* Keep the compiler quiet... */
319 case DEV_STATE_NOT_OPER
:
320 CIO_DEBUG(KERN_WARNING
, 2,
321 "SenseID : unknown device %04x on subchannel "
322 "0.%x.%04x\n", cdev
->private->dev_id
.devno
,
323 sch
->schid
.ssid
, sch
->schid
.sch_no
);
325 case DEV_STATE_OFFLINE
:
326 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
327 same_dev
= ccw_device_handle_oper(cdev
);
330 /* fill out sense information */
331 memset(&cdev
->id
, 0, sizeof(cdev
->id
));
332 cdev
->id
.cu_type
= cdev
->private->senseid
.cu_type
;
333 cdev
->id
.cu_model
= cdev
->private->senseid
.cu_model
;
334 cdev
->id
.dev_type
= cdev
->private->senseid
.dev_type
;
335 cdev
->id
.dev_model
= cdev
->private->senseid
.dev_model
;
337 cdev
->private->state
= DEV_STATE_OFFLINE
;
339 /* Get device online again. */
340 ccw_device_online(cdev
);
341 wake_up(&cdev
->private->wait_q
);
345 /* Issue device info message. */
346 CIO_DEBUG(KERN_INFO
, 2,
347 "SenseID : device 0.%x.%04x reports: "
348 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
350 cdev
->private->dev_id
.ssid
,
351 cdev
->private->dev_id
.devno
,
352 cdev
->id
.cu_type
, cdev
->id
.cu_model
,
353 cdev
->id
.dev_type
, cdev
->id
.dev_model
);
355 case DEV_STATE_BOXED
:
356 CIO_DEBUG(KERN_WARNING
, 2,
357 "SenseID : boxed device %04x on subchannel "
358 "0.%x.%04x\n", cdev
->private->dev_id
.devno
,
359 sch
->schid
.ssid
, sch
->schid
.sch_no
);
362 cdev
->private->state
= state
;
363 io_subchannel_recog_done(cdev
);
364 if (state
!= DEV_STATE_NOT_OPER
)
365 wake_up(&cdev
->private->wait_q
);
369 * Function called from device_id.c after sense id has completed.
372 ccw_device_sense_id_done(struct ccw_device
*cdev
, int err
)
376 ccw_device_recog_done(cdev
, DEV_STATE_OFFLINE
);
378 case -ETIME
: /* Sense id stopped by timeout. */
379 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
382 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
388 ccw_device_oper_notify(struct work_struct
*work
)
390 struct ccw_device_private
*priv
;
391 struct ccw_device
*cdev
;
392 struct subchannel
*sch
;
396 priv
= container_of(work
, struct ccw_device_private
, kick_work
);
398 spin_lock_irqsave(cdev
->ccwlock
, flags
);
399 sch
= to_subchannel(cdev
->dev
.parent
);
400 if (sch
->driver
&& sch
->driver
->notify
) {
401 spin_unlock_irqrestore(cdev
->ccwlock
, flags
);
402 ret
= sch
->driver
->notify(sch
, CIO_OPER
);
403 spin_lock_irqsave(cdev
->ccwlock
, flags
);
407 /* Reenable channel measurements, if needed. */
408 spin_unlock_irqrestore(cdev
->ccwlock
, flags
);
410 spin_lock_irqsave(cdev
->ccwlock
, flags
);
411 wake_up(&cdev
->private->wait_q
);
413 spin_unlock_irqrestore(cdev
->ccwlock
, flags
);
415 /* Driver doesn't want device back. */
416 ccw_device_do_unreg_rereg(work
);
420 * Finished with online/offline processing.
423 ccw_device_done(struct ccw_device
*cdev
, int state
)
425 struct subchannel
*sch
;
427 sch
= to_subchannel(cdev
->dev
.parent
);
429 ccw_device_set_timeout(cdev
, 0);
431 if (state
!= DEV_STATE_ONLINE
)
432 cio_disable_subchannel(sch
);
434 /* Reset device status. */
435 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
437 cdev
->private->state
= state
;
440 if (state
== DEV_STATE_BOXED
)
441 CIO_DEBUG(KERN_WARNING
, 2,
442 "Boxed device %04x on subchannel %04x\n",
443 cdev
->private->dev_id
.devno
, sch
->schid
.sch_no
);
445 if (cdev
->private->flags
.donotify
) {
446 cdev
->private->flags
.donotify
= 0;
447 PREPARE_WORK(&cdev
->private->kick_work
, ccw_device_oper_notify
);
448 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
450 wake_up(&cdev
->private->wait_q
);
452 if (css_init_done
&& state
!= DEV_STATE_ONLINE
)
453 put_device (&cdev
->dev
);
456 static int cmp_pgid(struct pgid
*p1
, struct pgid
*p2
)
464 return memcmp(c1
+ 1, c2
+ 1, sizeof(struct pgid
) - 1);
467 static void __ccw_device_get_common_pgid(struct ccw_device
*cdev
)
473 for (i
= 0; i
< 8; i
++) {
474 if (cdev
->private->pgid
[i
].inf
.ps
.state1
== SNID_STATE1_RESET
)
477 if (cdev
->private->pgid
[last
].inf
.ps
.state1
==
479 /* First non-zero PGID */
483 if (cmp_pgid(&cdev
->private->pgid
[i
],
484 &cdev
->private->pgid
[last
]) == 0)
485 /* Non-conflicting PGIDs */
488 /* PGID mismatch, can't pathgroup. */
489 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
490 "0.%x.%04x, can't pathgroup\n",
491 cdev
->private->dev_id
.ssid
,
492 cdev
->private->dev_id
.devno
);
493 cdev
->private->options
.pgroup
= 0;
496 if (cdev
->private->pgid
[last
].inf
.ps
.state1
==
498 /* No previous pgid found */
499 memcpy(&cdev
->private->pgid
[0],
500 &channel_subsystems
[0]->global_pgid
,
501 sizeof(struct pgid
));
503 /* Use existing pgid */
504 memcpy(&cdev
->private->pgid
[0], &cdev
->private->pgid
[last
],
505 sizeof(struct pgid
));
509 * Function called from device_pgid.c after sense path ground has completed.
512 ccw_device_sense_pgid_done(struct ccw_device
*cdev
, int err
)
514 struct subchannel
*sch
;
516 sch
= to_subchannel(cdev
->dev
.parent
);
518 case -EOPNOTSUPP
: /* path grouping not supported, use nop instead. */
519 cdev
->private->options
.pgroup
= 0;
521 case 0: /* success */
522 case -EACCES
: /* partial success, some paths not operational */
523 /* Check if all pgids are equal or 0. */
524 __ccw_device_get_common_pgid(cdev
);
526 case -ETIME
: /* Sense path group id stopped by timeout. */
527 case -EUSERS
: /* device is reserved for someone else. */
528 ccw_device_done(cdev
, DEV_STATE_BOXED
);
531 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
534 /* Start Path Group verification. */
535 cdev
->private->state
= DEV_STATE_VERIFY
;
536 cdev
->private->flags
.doverify
= 0;
537 ccw_device_verify_start(cdev
);
541 * Start device recognition.
544 ccw_device_recognition(struct ccw_device
*cdev
)
546 struct subchannel
*sch
;
549 if ((cdev
->private->state
!= DEV_STATE_NOT_OPER
) &&
550 (cdev
->private->state
!= DEV_STATE_BOXED
))
552 sch
= to_subchannel(cdev
->dev
.parent
);
553 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
555 /* Couldn't enable the subchannel for i/o. Sick device. */
558 /* After 60s the device recognition is considered to have failed. */
559 ccw_device_set_timeout(cdev
, 60*HZ
);
562 * We used to start here with a sense pgid to find out whether a device
563 * is locked by someone else. Unfortunately, the sense pgid command
564 * code has other meanings on devices predating the path grouping
565 * algorithm, so we start with sense id and box the device after an
566 * timeout (or if sense pgid during path verification detects the device
567 * is locked, as may happen on newer devices).
569 cdev
->private->flags
.recog_done
= 0;
570 cdev
->private->state
= DEV_STATE_SENSE_ID
;
571 ccw_device_sense_id_start(cdev
);
576 * Handle timeout in device recognition.
579 ccw_device_recog_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
583 ret
= ccw_device_cancel_halt_clear(cdev
);
586 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
589 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
592 ccw_device_set_timeout(cdev
, 3*HZ
);
598 ccw_device_verify_done(struct ccw_device
*cdev
, int err
)
600 struct subchannel
*sch
;
602 sch
= to_subchannel(cdev
->dev
.parent
);
603 /* Update schib - pom may have changed. */
604 stsch(sch
->schid
, &sch
->schib
);
605 /* Update lpm with verified path mask. */
607 /* Repeat path verification? */
608 if (cdev
->private->flags
.doverify
) {
609 cdev
->private->flags
.doverify
= 0;
610 ccw_device_verify_start(cdev
);
614 case -EOPNOTSUPP
: /* path grouping not supported, just set online. */
615 cdev
->private->options
.pgroup
= 0;
617 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
618 /* Deliver fake irb to device driver, if needed. */
619 if (cdev
->private->flags
.fake_irb
) {
620 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
621 cdev
->private->irb
.scsw
.cc
= 1;
622 cdev
->private->irb
.scsw
.fctl
= SCSW_FCTL_START_FUNC
;
623 cdev
->private->irb
.scsw
.actl
= SCSW_ACTL_START_PEND
;
624 cdev
->private->irb
.scsw
.stctl
= SCSW_STCTL_STATUS_PEND
;
625 cdev
->private->flags
.fake_irb
= 0;
627 cdev
->handler(cdev
, cdev
->private->intparm
,
628 &cdev
->private->irb
);
629 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
633 /* Reset oper notify indication after verify error. */
634 cdev
->private->flags
.donotify
= 0;
635 ccw_device_done(cdev
, DEV_STATE_BOXED
);
638 /* Reset oper notify indication after verify error. */
639 cdev
->private->flags
.donotify
= 0;
641 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
643 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
652 ccw_device_online(struct ccw_device
*cdev
)
654 struct subchannel
*sch
;
657 if ((cdev
->private->state
!= DEV_STATE_OFFLINE
) &&
658 (cdev
->private->state
!= DEV_STATE_BOXED
))
660 sch
= to_subchannel(cdev
->dev
.parent
);
661 if (css_init_done
&& !get_device(&cdev
->dev
))
663 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
665 /* Couldn't enable the subchannel for i/o. Sick device. */
667 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
670 /* Do we want to do path grouping? */
671 if (!cdev
->private->options
.pgroup
) {
672 /* Start initial path verification. */
673 cdev
->private->state
= DEV_STATE_VERIFY
;
674 cdev
->private->flags
.doverify
= 0;
675 ccw_device_verify_start(cdev
);
678 /* Do a SensePGID first. */
679 cdev
->private->state
= DEV_STATE_SENSE_PGID
;
680 ccw_device_sense_pgid_start(cdev
);
685 ccw_device_disband_done(struct ccw_device
*cdev
, int err
)
689 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
692 ccw_device_done(cdev
, DEV_STATE_BOXED
);
695 cdev
->private->flags
.donotify
= 0;
696 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
697 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
706 ccw_device_offline(struct ccw_device
*cdev
)
708 struct subchannel
*sch
;
710 if (ccw_device_is_orphan(cdev
)) {
711 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
714 sch
= to_subchannel(cdev
->dev
.parent
);
715 if (stsch(sch
->schid
, &sch
->schib
) || !sch
->schib
.pmcw
.dnv
)
717 if (cdev
->private->state
!= DEV_STATE_ONLINE
) {
718 if (sch
->schib
.scsw
.actl
!= 0)
722 if (sch
->schib
.scsw
.actl
!= 0)
724 /* Are we doing path grouping? */
725 if (!cdev
->private->options
.pgroup
) {
726 /* No, set state offline immediately. */
727 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
730 /* Start Set Path Group commands. */
731 cdev
->private->state
= DEV_STATE_DISBAND_PGID
;
732 ccw_device_disband_start(cdev
);
737 * Handle timeout in device online/offline process.
740 ccw_device_onoff_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
744 ret
= ccw_device_cancel_halt_clear(cdev
);
747 ccw_device_done(cdev
, DEV_STATE_BOXED
);
750 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
753 ccw_device_set_timeout(cdev
, 3*HZ
);
758 * Handle not oper event in device recognition.
761 ccw_device_recog_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
763 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
767 * Handle not operational event in non-special state.
769 static void ccw_device_generic_notoper(struct ccw_device
*cdev
,
770 enum dev_event dev_event
)
772 struct subchannel
*sch
;
774 cdev
->private->state
= DEV_STATE_NOT_OPER
;
775 sch
= to_subchannel(cdev
->dev
.parent
);
776 css_schedule_eval(sch
->schid
);
780 * Handle path verification event.
783 ccw_device_online_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
785 struct subchannel
*sch
;
787 if (cdev
->private->state
== DEV_STATE_W4SENSE
) {
788 cdev
->private->flags
.doverify
= 1;
791 sch
= to_subchannel(cdev
->dev
.parent
);
793 * Since we might not just be coming from an interrupt from the
794 * subchannel we have to update the schib.
796 stsch(sch
->schid
, &sch
->schib
);
798 if (sch
->schib
.scsw
.actl
!= 0 ||
799 (sch
->schib
.scsw
.stctl
& SCSW_STCTL_STATUS_PEND
) ||
800 (cdev
->private->irb
.scsw
.stctl
& SCSW_STCTL_STATUS_PEND
)) {
802 * No final status yet or final status not yet delivered
803 * to the device driver. Can't do path verfication now,
804 * delay until final status was delivered.
806 cdev
->private->flags
.doverify
= 1;
809 /* Device is idle, we can do the path verification. */
810 cdev
->private->state
= DEV_STATE_VERIFY
;
811 cdev
->private->flags
.doverify
= 0;
812 ccw_device_verify_start(cdev
);
816 * Got an interrupt for a normal io (state online).
819 ccw_device_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
823 irb
= (struct irb
*) __LC_IRB
;
824 /* Check for unsolicited interrupt. */
825 if ((irb
->scsw
.stctl
==
826 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
))
827 && (!irb
->scsw
.cc
)) {
828 if ((irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) &&
829 !irb
->esw
.esw0
.erw
.cons
) {
830 /* Unit check but no sense data. Need basic sense. */
831 if (ccw_device_do_sense(cdev
, irb
) != 0)
832 goto call_handler_unsol
;
833 memcpy(&cdev
->private->irb
, irb
, sizeof(struct irb
));
834 cdev
->private->state
= DEV_STATE_W4SENSE
;
835 cdev
->private->intparm
= 0;
840 cdev
->handler (cdev
, 0, irb
);
841 if (cdev
->private->flags
.doverify
)
842 ccw_device_online_verify(cdev
, 0);
845 /* Accumulate status and find out if a basic sense is needed. */
846 ccw_device_accumulate_irb(cdev
, irb
);
847 if (cdev
->private->flags
.dosense
) {
848 if (ccw_device_do_sense(cdev
, irb
) == 0) {
849 cdev
->private->state
= DEV_STATE_W4SENSE
;
853 /* Call the handler. */
854 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
855 /* Start delayed path verification. */
856 ccw_device_online_verify(cdev
, 0);
860 * Got an timeout in online state.
863 ccw_device_online_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
867 ccw_device_set_timeout(cdev
, 0);
868 ret
= ccw_device_cancel_halt_clear(cdev
);
870 ccw_device_set_timeout(cdev
, 3*HZ
);
871 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
875 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
876 else if (cdev
->handler
)
877 cdev
->handler(cdev
, cdev
->private->intparm
,
878 ERR_PTR(-ETIMEDOUT
));
882 * Got an interrupt for a basic sense.
885 ccw_device_w4sense(struct ccw_device
*cdev
, enum dev_event dev_event
)
889 irb
= (struct irb
*) __LC_IRB
;
890 /* Check for unsolicited interrupt. */
891 if (irb
->scsw
.stctl
==
892 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
893 if (irb
->scsw
.cc
== 1)
894 /* Basic sense hasn't started. Try again. */
895 ccw_device_do_sense(cdev
, irb
);
897 CIO_MSG_EVENT(2, "Huh? 0.%x.%04x: unsolicited "
898 "interrupt during w4sense...\n",
899 cdev
->private->dev_id
.ssid
,
900 cdev
->private->dev_id
.devno
);
902 cdev
->handler (cdev
, 0, irb
);
907 * Check if a halt or clear has been issued in the meanwhile. If yes,
908 * only deliver the halt/clear interrupt to the device driver as if it
909 * had killed the original request.
911 if (irb
->scsw
.fctl
& (SCSW_FCTL_CLEAR_FUNC
| SCSW_FCTL_HALT_FUNC
)) {
912 /* Retry Basic Sense if requested. */
913 if (cdev
->private->flags
.intretry
) {
914 cdev
->private->flags
.intretry
= 0;
915 ccw_device_do_sense(cdev
, irb
);
918 cdev
->private->flags
.dosense
= 0;
919 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
920 ccw_device_accumulate_irb(cdev
, irb
);
923 /* Add basic sense info to irb. */
924 ccw_device_accumulate_basic_sense(cdev
, irb
);
925 if (cdev
->private->flags
.dosense
) {
926 /* Another basic sense is needed. */
927 ccw_device_do_sense(cdev
, irb
);
931 cdev
->private->state
= DEV_STATE_ONLINE
;
932 /* Call the handler. */
933 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
934 /* Start delayed path verification. */
935 ccw_device_online_verify(cdev
, 0);
939 ccw_device_clear_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
943 irb
= (struct irb
*) __LC_IRB
;
944 /* Accumulate status. We don't do basic sense. */
945 ccw_device_accumulate_irb(cdev
, irb
);
946 /* Remember to clear irb to avoid residuals. */
947 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
948 /* Try to start delayed device verification. */
949 ccw_device_online_verify(cdev
, 0);
950 /* Note: Don't call handler for cio initiated clear! */
954 ccw_device_killing_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
956 struct subchannel
*sch
;
958 sch
= to_subchannel(cdev
->dev
.parent
);
959 ccw_device_set_timeout(cdev
, 0);
960 /* Start delayed path verification. */
961 ccw_device_online_verify(cdev
, 0);
962 /* OK, i/o is dead now. Call interrupt handler. */
964 cdev
->handler(cdev
, cdev
->private->intparm
,
969 ccw_device_killing_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
973 ret
= ccw_device_cancel_halt_clear(cdev
);
975 ccw_device_set_timeout(cdev
, 3*HZ
);
978 /* Start delayed path verification. */
979 ccw_device_online_verify(cdev
, 0);
981 cdev
->handler(cdev
, cdev
->private->intparm
,
985 void device_kill_io(struct subchannel
*sch
)
988 struct ccw_device
*cdev
;
990 cdev
= sch
->dev
.driver_data
;
991 ret
= ccw_device_cancel_halt_clear(cdev
);
993 ccw_device_set_timeout(cdev
, 3*HZ
);
994 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
997 /* Start delayed path verification. */
998 ccw_device_online_verify(cdev
, 0);
1000 cdev
->handler(cdev
, cdev
->private->intparm
,
1005 ccw_device_delay_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
1007 /* Start verification after current task finished. */
1008 cdev
->private->flags
.doverify
= 1;
1012 ccw_device_stlck_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
1016 switch (dev_event
) {
1017 case DEV_EVENT_INTERRUPT
:
1018 irb
= (struct irb
*) __LC_IRB
;
1019 /* Check for unsolicited interrupt. */
1020 if ((irb
->scsw
.stctl
==
1021 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) &&
1023 /* FIXME: we should restart stlck here, but this
1024 * is extremely unlikely ... */
1027 ccw_device_accumulate_irb(cdev
, irb
);
1028 /* We don't care about basic sense etc. */
1030 default: /* timeout */
1034 wake_up(&cdev
->private->wait_q
);
1038 ccw_device_start_id(struct ccw_device
*cdev
, enum dev_event dev_event
)
1040 struct subchannel
*sch
;
1042 sch
= to_subchannel(cdev
->dev
.parent
);
1043 if (cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
) != 0)
1044 /* Couldn't enable the subchannel for i/o. Sick device. */
1047 /* After 60s the device recognition is considered to have failed. */
1048 ccw_device_set_timeout(cdev
, 60*HZ
);
1050 cdev
->private->state
= DEV_STATE_DISCONNECTED_SENSE_ID
;
1051 ccw_device_sense_id_start(cdev
);
1055 device_trigger_reprobe(struct subchannel
*sch
)
1057 struct ccw_device
*cdev
;
1059 if (!sch
->dev
.driver_data
)
1061 cdev
= sch
->dev
.driver_data
;
1062 if (cdev
->private->state
!= DEV_STATE_DISCONNECTED
)
1065 /* Update some values. */
1066 if (stsch(sch
->schid
, &sch
->schib
))
1068 if (!sch
->schib
.pmcw
.dnv
)
1071 * The pim, pam, pom values may not be accurate, but they are the best
1072 * we have before performing device selection :/
1074 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
1075 /* Re-set some bits in the pmcw that were lost. */
1076 sch
->schib
.pmcw
.isc
= 3;
1077 sch
->schib
.pmcw
.csense
= 1;
1078 sch
->schib
.pmcw
.ena
= 0;
1079 if ((sch
->lpm
& (sch
->lpm
- 1)) != 0)
1080 sch
->schib
.pmcw
.mp
= 1;
1081 sch
->schib
.pmcw
.intparm
= (__u32
)(unsigned long)sch
;
1082 /* We should also udate ssd info, but this has to wait. */
1083 /* Check if this is another device which appeared on the same sch. */
1084 if (sch
->schib
.pmcw
.dev
!= cdev
->private->dev_id
.devno
) {
1085 PREPARE_WORK(&cdev
->private->kick_work
,
1086 ccw_device_move_to_orphanage
);
1087 queue_work(slow_path_wq
, &cdev
->private->kick_work
);
1089 ccw_device_start_id(cdev
, 0);
1093 ccw_device_offline_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
1095 struct subchannel
*sch
;
1097 sch
= to_subchannel(cdev
->dev
.parent
);
1099 * An interrupt in state offline means a previous disable was not
1100 * successful. Try again.
1102 cio_disable_subchannel(sch
);
1106 ccw_device_change_cmfstate(struct ccw_device
*cdev
, enum dev_event dev_event
)
1108 retry_set_schib(cdev
);
1109 cdev
->private->state
= DEV_STATE_ONLINE
;
1110 dev_fsm_event(cdev
, dev_event
);
1113 static void ccw_device_update_cmfblock(struct ccw_device
*cdev
,
1114 enum dev_event dev_event
)
1116 cmf_retry_copy_block(cdev
);
1117 cdev
->private->state
= DEV_STATE_ONLINE
;
1118 dev_fsm_event(cdev
, dev_event
);
1122 ccw_device_quiesce_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
1124 ccw_device_set_timeout(cdev
, 0);
1125 if (dev_event
== DEV_EVENT_NOTOPER
)
1126 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1128 cdev
->private->state
= DEV_STATE_OFFLINE
;
1129 wake_up(&cdev
->private->wait_q
);
1133 ccw_device_quiesce_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
1137 ret
= ccw_device_cancel_halt_clear(cdev
);
1140 cdev
->private->state
= DEV_STATE_OFFLINE
;
1141 wake_up(&cdev
->private->wait_q
);
1144 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1145 wake_up(&cdev
->private->wait_q
);
1148 ccw_device_set_timeout(cdev
, HZ
/10);
1153 * No operation action. This is used e.g. to ignore a timeout event in
1157 ccw_device_nop(struct ccw_device
*cdev
, enum dev_event dev_event
)
1162 * Bug operation action.
1165 ccw_device_bug(struct ccw_device
*cdev
, enum dev_event dev_event
)
1167 CIO_MSG_EVENT(0, "dev_jumptable[%i][%i] == NULL\n",
1168 cdev
->private->state
, dev_event
);
1173 * device statemachine
1175 fsm_func_t
*dev_jumptable
[NR_DEV_STATES
][NR_DEV_EVENTS
] = {
1176 [DEV_STATE_NOT_OPER
] = {
1177 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1178 [DEV_EVENT_INTERRUPT
] = ccw_device_bug
,
1179 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1180 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1182 [DEV_STATE_SENSE_PGID
] = {
1183 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1184 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_pgid_irq
,
1185 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1186 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1188 [DEV_STATE_SENSE_ID
] = {
1189 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1190 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1191 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1192 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1194 [DEV_STATE_OFFLINE
] = {
1195 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1196 [DEV_EVENT_INTERRUPT
] = ccw_device_offline_irq
,
1197 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1198 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1200 [DEV_STATE_VERIFY
] = {
1201 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1202 [DEV_EVENT_INTERRUPT
] = ccw_device_verify_irq
,
1203 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1204 [DEV_EVENT_VERIFY
] = ccw_device_delay_verify
,
1206 [DEV_STATE_ONLINE
] = {
1207 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1208 [DEV_EVENT_INTERRUPT
] = ccw_device_irq
,
1209 [DEV_EVENT_TIMEOUT
] = ccw_device_online_timeout
,
1210 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1212 [DEV_STATE_W4SENSE
] = {
1213 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1214 [DEV_EVENT_INTERRUPT
] = ccw_device_w4sense
,
1215 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1216 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1218 [DEV_STATE_DISBAND_PGID
] = {
1219 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1220 [DEV_EVENT_INTERRUPT
] = ccw_device_disband_irq
,
1221 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1222 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1224 [DEV_STATE_BOXED
] = {
1225 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1226 [DEV_EVENT_INTERRUPT
] = ccw_device_stlck_done
,
1227 [DEV_EVENT_TIMEOUT
] = ccw_device_stlck_done
,
1228 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1230 /* states to wait for i/o completion before doing something */
1231 [DEV_STATE_CLEAR_VERIFY
] = {
1232 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1233 [DEV_EVENT_INTERRUPT
] = ccw_device_clear_verify
,
1234 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1235 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1237 [DEV_STATE_TIMEOUT_KILL
] = {
1238 [DEV_EVENT_NOTOPER
] = ccw_device_generic_notoper
,
1239 [DEV_EVENT_INTERRUPT
] = ccw_device_killing_irq
,
1240 [DEV_EVENT_TIMEOUT
] = ccw_device_killing_timeout
,
1241 [DEV_EVENT_VERIFY
] = ccw_device_nop
, //FIXME
1243 [DEV_STATE_QUIESCE
] = {
1244 [DEV_EVENT_NOTOPER
] = ccw_device_quiesce_done
,
1245 [DEV_EVENT_INTERRUPT
] = ccw_device_quiesce_done
,
1246 [DEV_EVENT_TIMEOUT
] = ccw_device_quiesce_timeout
,
1247 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1249 /* special states for devices gone not operational */
1250 [DEV_STATE_DISCONNECTED
] = {
1251 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1252 [DEV_EVENT_INTERRUPT
] = ccw_device_start_id
,
1253 [DEV_EVENT_TIMEOUT
] = ccw_device_bug
,
1254 [DEV_EVENT_VERIFY
] = ccw_device_start_id
,
1256 [DEV_STATE_DISCONNECTED_SENSE_ID
] = {
1257 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1258 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1259 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1260 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1262 [DEV_STATE_CMFCHANGE
] = {
1263 [DEV_EVENT_NOTOPER
] = ccw_device_change_cmfstate
,
1264 [DEV_EVENT_INTERRUPT
] = ccw_device_change_cmfstate
,
1265 [DEV_EVENT_TIMEOUT
] = ccw_device_change_cmfstate
,
1266 [DEV_EVENT_VERIFY
] = ccw_device_change_cmfstate
,
1268 [DEV_STATE_CMFUPDATE
] = {
1269 [DEV_EVENT_NOTOPER
] = ccw_device_update_cmfblock
,
1270 [DEV_EVENT_INTERRUPT
] = ccw_device_update_cmfblock
,
1271 [DEV_EVENT_TIMEOUT
] = ccw_device_update_cmfblock
,
1272 [DEV_EVENT_VERIFY
] = ccw_device_update_cmfblock
,
1276 EXPORT_SYMBOL_GPL(ccw_device_set_timeout
);