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>
20 #include "cio_debug.h"
27 device_is_online(struct subchannel
*sch
)
29 struct ccw_device
*cdev
;
31 if (!sch
->dev
.driver_data
)
33 cdev
= sch
->dev
.driver_data
;
34 return (cdev
->private->state
== DEV_STATE_ONLINE
);
38 device_is_disconnected(struct subchannel
*sch
)
40 struct ccw_device
*cdev
;
42 if (!sch
->dev
.driver_data
)
44 cdev
= sch
->dev
.driver_data
;
45 return (cdev
->private->state
== DEV_STATE_DISCONNECTED
||
46 cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
);
50 device_set_disconnected(struct subchannel
*sch
)
52 struct ccw_device
*cdev
;
54 if (!sch
->dev
.driver_data
)
56 cdev
= sch
->dev
.driver_data
;
57 ccw_device_set_timeout(cdev
, 0);
58 cdev
->private->flags
.fake_irb
= 0;
59 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
62 int device_trigger_verify(struct subchannel
*sch
)
64 struct ccw_device
*cdev
;
66 cdev
= sch
->dev
.driver_data
;
67 if (!cdev
|| !cdev
->online
)
69 dev_fsm_event(cdev
, DEV_EVENT_VERIFY
);
74 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
77 ccw_device_timeout(unsigned long data
)
79 struct ccw_device
*cdev
;
81 cdev
= (struct ccw_device
*) data
;
82 spin_lock_irq(cdev
->ccwlock
);
83 dev_fsm_event(cdev
, DEV_EVENT_TIMEOUT
);
84 spin_unlock_irq(cdev
->ccwlock
);
91 ccw_device_set_timeout(struct ccw_device
*cdev
, int expires
)
94 del_timer(&cdev
->private->timer
);
97 if (timer_pending(&cdev
->private->timer
)) {
98 if (mod_timer(&cdev
->private->timer
, jiffies
+ expires
))
101 cdev
->private->timer
.function
= ccw_device_timeout
;
102 cdev
->private->timer
.data
= (unsigned long) cdev
;
103 cdev
->private->timer
.expires
= jiffies
+ expires
;
104 add_timer(&cdev
->private->timer
);
107 /* Kill any pending timers after machine check. */
109 device_kill_pending_timer(struct subchannel
*sch
)
111 struct ccw_device
*cdev
;
113 if (!sch
->dev
.driver_data
)
115 cdev
= sch
->dev
.driver_data
;
116 ccw_device_set_timeout(cdev
, 0);
120 * Cancel running i/o. This is called repeatedly since halt/clear are
121 * asynchronous operations. We do one try with cio_cancel, two tries
122 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
123 * Returns 0 if device now idle, -ENODEV for device not operational and
124 * -EBUSY if an interrupt is expected (either from halt/clear or from a
128 ccw_device_cancel_halt_clear(struct ccw_device
*cdev
)
130 struct subchannel
*sch
;
133 sch
= to_subchannel(cdev
->dev
.parent
);
134 ret
= stsch(sch
->schid
, &sch
->schib
);
135 if (ret
|| !sch
->schib
.pmcw
.dnv
)
137 if (!sch
->schib
.pmcw
.ena
|| sch
->schib
.scsw
.actl
== 0)
138 /* Not operational or no activity -> done. */
140 /* Stage 1: cancel io. */
141 if (!(sch
->schib
.scsw
.actl
& SCSW_ACTL_HALT_PEND
) &&
142 !(sch
->schib
.scsw
.actl
& SCSW_ACTL_CLEAR_PEND
)) {
143 ret
= cio_cancel(sch
);
146 /* cancel io unsuccessful. From now on it is asynchronous. */
147 cdev
->private->iretry
= 3; /* 3 halt retries. */
149 if (!(sch
->schib
.scsw
.actl
& SCSW_ACTL_CLEAR_PEND
)) {
150 /* Stage 2: halt io. */
151 if (cdev
->private->iretry
) {
152 cdev
->private->iretry
--;
155 return (ret
== 0) ? -EBUSY
: ret
;
157 /* halt io unsuccessful. */
158 cdev
->private->iretry
= 255; /* 255 clear retries. */
160 /* Stage 3: clear io. */
161 if (cdev
->private->iretry
) {
162 cdev
->private->iretry
--;
163 ret
= cio_clear (sch
);
164 return (ret
== 0) ? -EBUSY
: ret
;
166 panic("Can't stop i/o on subchannel.\n");
170 ccw_device_handle_oper(struct ccw_device
*cdev
)
172 struct subchannel
*sch
;
174 sch
= to_subchannel(cdev
->dev
.parent
);
175 cdev
->private->flags
.recog_done
= 1;
177 * Check if cu type and device type still match. If
178 * not, it is certainly another device and we have to
179 * de- and re-register. Also check here for non-matching devno.
181 if (cdev
->id
.cu_type
!= cdev
->private->senseid
.cu_type
||
182 cdev
->id
.cu_model
!= cdev
->private->senseid
.cu_model
||
183 cdev
->id
.dev_type
!= cdev
->private->senseid
.dev_type
||
184 cdev
->id
.dev_model
!= cdev
->private->senseid
.dev_model
||
185 cdev
->private->dev_id
.devno
!= sch
->schib
.pmcw
.dev
) {
186 PREPARE_WORK(&cdev
->private->kick_work
,
187 ccw_device_do_unreg_rereg
, cdev
);
188 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
191 cdev
->private->flags
.donotify
= 1;
196 * The machine won't give us any notification by machine check if a chpid has
197 * been varied online on the SE so we have to find out by magic (i. e. driving
198 * the channel subsystem to device selection and updating our path masks).
201 __recover_lost_chpids(struct subchannel
*sch
, int old_lpm
)
205 for (i
= 0; i
<8; i
++) {
207 if (!(sch
->lpm
& mask
))
211 chpid_is_actually_online(sch
->schib
.pmcw
.chpid
[i
]);
216 * Stop device recognition.
219 ccw_device_recog_done(struct ccw_device
*cdev
, int state
)
221 struct subchannel
*sch
;
222 int notify
, old_lpm
, same_dev
;
224 sch
= to_subchannel(cdev
->dev
.parent
);
226 ccw_device_set_timeout(cdev
, 0);
227 cio_disable_subchannel(sch
);
229 * Now that we tried recognition, we have performed device selection
230 * through ssch() and the path information is up to date.
233 stsch(sch
->schid
, &sch
->schib
);
234 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
235 /* Check since device may again have become not operational. */
236 if (!sch
->schib
.pmcw
.dnv
)
237 state
= DEV_STATE_NOT_OPER
;
238 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
)
239 /* Force reprobe on all chpids. */
241 if (sch
->lpm
!= old_lpm
)
242 __recover_lost_chpids(sch
, old_lpm
);
243 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
244 if (state
== DEV_STATE_NOT_OPER
) {
245 cdev
->private->flags
.recog_done
= 1;
246 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
249 /* Boxed devices don't need extra treatment. */
252 same_dev
= 0; /* Keep the compiler quiet... */
254 case DEV_STATE_NOT_OPER
:
255 CIO_DEBUG(KERN_WARNING
, 2,
256 "SenseID : unknown device %04x on subchannel "
257 "0.%x.%04x\n", cdev
->private->dev_id
.devno
,
258 sch
->schid
.ssid
, sch
->schid
.sch_no
);
260 case DEV_STATE_OFFLINE
:
261 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
262 same_dev
= ccw_device_handle_oper(cdev
);
265 /* fill out sense information */
266 memset(&cdev
->id
, 0, sizeof(cdev
->id
));
267 cdev
->id
.cu_type
= cdev
->private->senseid
.cu_type
;
268 cdev
->id
.cu_model
= cdev
->private->senseid
.cu_model
;
269 cdev
->id
.dev_type
= cdev
->private->senseid
.dev_type
;
270 cdev
->id
.dev_model
= cdev
->private->senseid
.dev_model
;
272 cdev
->private->state
= DEV_STATE_OFFLINE
;
274 /* Get device online again. */
275 ccw_device_online(cdev
);
276 wake_up(&cdev
->private->wait_q
);
280 /* Issue device info message. */
281 CIO_DEBUG(KERN_INFO
, 2, "SenseID : device 0.%x.%04x reports: "
282 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
284 cdev
->private->dev_id
.ssid
,
285 cdev
->private->dev_id
.devno
,
286 cdev
->id
.cu_type
, cdev
->id
.cu_model
,
287 cdev
->id
.dev_type
, cdev
->id
.dev_model
);
289 case DEV_STATE_BOXED
:
290 CIO_DEBUG(KERN_WARNING
, 2,
291 "SenseID : boxed device %04x on subchannel "
292 "0.%x.%04x\n", cdev
->private->dev_id
.devno
,
293 sch
->schid
.ssid
, sch
->schid
.sch_no
);
296 cdev
->private->state
= state
;
297 io_subchannel_recog_done(cdev
);
298 if (state
!= DEV_STATE_NOT_OPER
)
299 wake_up(&cdev
->private->wait_q
);
303 * Function called from device_id.c after sense id has completed.
306 ccw_device_sense_id_done(struct ccw_device
*cdev
, int err
)
310 ccw_device_recog_done(cdev
, DEV_STATE_OFFLINE
);
312 case -ETIME
: /* Sense id stopped by timeout. */
313 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
316 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
322 ccw_device_oper_notify(void *data
)
324 struct ccw_device
*cdev
;
325 struct subchannel
*sch
;
329 sch
= to_subchannel(cdev
->dev
.parent
);
330 ret
= (sch
->driver
&& sch
->driver
->notify
) ?
331 sch
->driver
->notify(&sch
->dev
, CIO_OPER
) : 0;
333 /* Driver doesn't want device back. */
334 ccw_device_do_unreg_rereg(cdev
);
336 /* Reenable channel measurements, if needed. */
338 wake_up(&cdev
->private->wait_q
);
343 * Finished with online/offline processing.
346 ccw_device_done(struct ccw_device
*cdev
, int state
)
348 struct subchannel
*sch
;
350 sch
= to_subchannel(cdev
->dev
.parent
);
352 ccw_device_set_timeout(cdev
, 0);
354 if (state
!= DEV_STATE_ONLINE
)
355 cio_disable_subchannel(sch
);
357 /* Reset device status. */
358 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
360 cdev
->private->state
= state
;
363 if (state
== DEV_STATE_BOXED
)
364 CIO_DEBUG(KERN_WARNING
, 2,
365 "Boxed device %04x on subchannel %04x\n",
366 cdev
->private->dev_id
.devno
, sch
->schid
.sch_no
);
368 if (cdev
->private->flags
.donotify
) {
369 cdev
->private->flags
.donotify
= 0;
370 PREPARE_WORK(&cdev
->private->kick_work
, ccw_device_oper_notify
,
372 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
374 wake_up(&cdev
->private->wait_q
);
376 if (css_init_done
&& state
!= DEV_STATE_ONLINE
)
377 put_device (&cdev
->dev
);
380 static inline int cmp_pgid(struct pgid
*p1
, struct pgid
*p2
)
388 return memcmp(c1
+ 1, c2
+ 1, sizeof(struct pgid
) - 1);
391 static void __ccw_device_get_common_pgid(struct ccw_device
*cdev
)
397 for (i
= 0; i
< 8; i
++) {
398 if (cdev
->private->pgid
[i
].inf
.ps
.state1
== SNID_STATE1_RESET
)
401 if (cdev
->private->pgid
[last
].inf
.ps
.state1
==
403 /* First non-zero PGID */
407 if (cmp_pgid(&cdev
->private->pgid
[i
],
408 &cdev
->private->pgid
[last
]) == 0)
409 /* Non-conflicting PGIDs */
412 /* PGID mismatch, can't pathgroup. */
413 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
414 "0.%x.%04x, can't pathgroup\n",
415 cdev
->private->dev_id
.ssid
,
416 cdev
->private->dev_id
.devno
);
417 cdev
->private->options
.pgroup
= 0;
420 if (cdev
->private->pgid
[last
].inf
.ps
.state1
==
422 /* No previous pgid found */
423 memcpy(&cdev
->private->pgid
[0], &css
[0]->global_pgid
,
424 sizeof(struct pgid
));
426 /* Use existing pgid */
427 memcpy(&cdev
->private->pgid
[0], &cdev
->private->pgid
[last
],
428 sizeof(struct pgid
));
432 * Function called from device_pgid.c after sense path ground has completed.
435 ccw_device_sense_pgid_done(struct ccw_device
*cdev
, int err
)
437 struct subchannel
*sch
;
439 sch
= to_subchannel(cdev
->dev
.parent
);
441 case -EOPNOTSUPP
: /* path grouping not supported, use nop instead. */
442 cdev
->private->options
.pgroup
= 0;
444 case 0: /* success */
445 case -EACCES
: /* partial success, some paths not operational */
446 /* Check if all pgids are equal or 0. */
447 __ccw_device_get_common_pgid(cdev
);
449 case -ETIME
: /* Sense path group id stopped by timeout. */
450 case -EUSERS
: /* device is reserved for someone else. */
451 ccw_device_done(cdev
, DEV_STATE_BOXED
);
454 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
457 /* Start Path Group verification. */
458 cdev
->private->state
= DEV_STATE_VERIFY
;
459 cdev
->private->flags
.doverify
= 0;
460 ccw_device_verify_start(cdev
);
464 * Start device recognition.
467 ccw_device_recognition(struct ccw_device
*cdev
)
469 struct subchannel
*sch
;
472 if ((cdev
->private->state
!= DEV_STATE_NOT_OPER
) &&
473 (cdev
->private->state
!= DEV_STATE_BOXED
))
475 sch
= to_subchannel(cdev
->dev
.parent
);
476 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
478 /* Couldn't enable the subchannel for i/o. Sick device. */
481 /* After 60s the device recognition is considered to have failed. */
482 ccw_device_set_timeout(cdev
, 60*HZ
);
485 * We used to start here with a sense pgid to find out whether a device
486 * is locked by someone else. Unfortunately, the sense pgid command
487 * code has other meanings on devices predating the path grouping
488 * algorithm, so we start with sense id and box the device after an
489 * timeout (or if sense pgid during path verification detects the device
490 * is locked, as may happen on newer devices).
492 cdev
->private->flags
.recog_done
= 0;
493 cdev
->private->state
= DEV_STATE_SENSE_ID
;
494 ccw_device_sense_id_start(cdev
);
499 * Handle timeout in device recognition.
502 ccw_device_recog_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
506 ret
= ccw_device_cancel_halt_clear(cdev
);
509 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
512 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
515 ccw_device_set_timeout(cdev
, 3*HZ
);
521 ccw_device_nopath_notify(void *data
)
523 struct ccw_device
*cdev
;
524 struct subchannel
*sch
;
528 sch
= to_subchannel(cdev
->dev
.parent
);
532 ret
= (sch
->driver
&& sch
->driver
->notify
) ?
533 sch
->driver
->notify(&sch
->dev
, CIO_NO_PATH
) : 0;
535 if (get_device(&sch
->dev
)) {
536 /* Driver doesn't want to keep device. */
537 cio_disable_subchannel(sch
);
538 if (get_device(&cdev
->dev
)) {
539 PREPARE_WORK(&cdev
->private->kick_work
,
540 ccw_device_call_sch_unregister
,
542 queue_work(ccw_device_work
,
543 &cdev
->private->kick_work
);
545 put_device(&sch
->dev
);
548 cio_disable_subchannel(sch
);
549 ccw_device_set_timeout(cdev
, 0);
550 cdev
->private->flags
.fake_irb
= 0;
551 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
552 wake_up(&cdev
->private->wait_q
);
557 ccw_device_verify_done(struct ccw_device
*cdev
, int err
)
559 struct subchannel
*sch
;
561 sch
= to_subchannel(cdev
->dev
.parent
);
562 /* Update schib - pom may have changed. */
563 stsch(sch
->schid
, &sch
->schib
);
564 /* Update lpm with verified path mask. */
566 /* Repeat path verification? */
567 if (cdev
->private->flags
.doverify
) {
568 cdev
->private->flags
.doverify
= 0;
569 ccw_device_verify_start(cdev
);
573 case -EOPNOTSUPP
: /* path grouping not supported, just set online. */
574 cdev
->private->options
.pgroup
= 0;
576 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
577 /* Deliver fake irb to device driver, if needed. */
578 if (cdev
->private->flags
.fake_irb
) {
579 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
580 cdev
->private->irb
.scsw
.cc
= 1;
581 cdev
->private->irb
.scsw
.fctl
= SCSW_FCTL_START_FUNC
;
582 cdev
->private->irb
.scsw
.actl
= SCSW_ACTL_START_PEND
;
583 cdev
->private->irb
.scsw
.stctl
= SCSW_STCTL_STATUS_PEND
;
584 cdev
->private->flags
.fake_irb
= 0;
586 cdev
->handler(cdev
, cdev
->private->intparm
,
587 &cdev
->private->irb
);
588 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
592 /* Reset oper notify indication after verify error. */
593 cdev
->private->flags
.donotify
= 0;
594 ccw_device_done(cdev
, DEV_STATE_BOXED
);
597 /* Reset oper notify indication after verify error. */
598 cdev
->private->flags
.donotify
= 0;
599 PREPARE_WORK(&cdev
->private->kick_work
,
600 ccw_device_nopath_notify
, cdev
);
601 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
602 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
611 ccw_device_online(struct ccw_device
*cdev
)
613 struct subchannel
*sch
;
616 if ((cdev
->private->state
!= DEV_STATE_OFFLINE
) &&
617 (cdev
->private->state
!= DEV_STATE_BOXED
))
619 sch
= to_subchannel(cdev
->dev
.parent
);
620 if (css_init_done
&& !get_device(&cdev
->dev
))
622 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
624 /* Couldn't enable the subchannel for i/o. Sick device. */
626 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
629 /* Do we want to do path grouping? */
630 if (!cdev
->private->options
.pgroup
) {
631 /* Start initial path verification. */
632 cdev
->private->state
= DEV_STATE_VERIFY
;
633 cdev
->private->flags
.doverify
= 0;
634 ccw_device_verify_start(cdev
);
637 /* Do a SensePGID first. */
638 cdev
->private->state
= DEV_STATE_SENSE_PGID
;
639 ccw_device_sense_pgid_start(cdev
);
644 ccw_device_disband_done(struct ccw_device
*cdev
, int err
)
648 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
651 ccw_device_done(cdev
, DEV_STATE_BOXED
);
654 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
663 ccw_device_offline(struct ccw_device
*cdev
)
665 struct subchannel
*sch
;
667 sch
= to_subchannel(cdev
->dev
.parent
);
668 if (stsch(sch
->schid
, &sch
->schib
) || !sch
->schib
.pmcw
.dnv
)
670 if (cdev
->private->state
!= DEV_STATE_ONLINE
) {
671 if (sch
->schib
.scsw
.actl
!= 0)
675 if (sch
->schib
.scsw
.actl
!= 0)
677 /* Are we doing path grouping? */
678 if (!cdev
->private->options
.pgroup
) {
679 /* No, set state offline immediately. */
680 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
683 /* Start Set Path Group commands. */
684 cdev
->private->state
= DEV_STATE_DISBAND_PGID
;
685 ccw_device_disband_start(cdev
);
690 * Handle timeout in device online/offline process.
693 ccw_device_onoff_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
697 ret
= ccw_device_cancel_halt_clear(cdev
);
700 ccw_device_done(cdev
, DEV_STATE_BOXED
);
703 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
706 ccw_device_set_timeout(cdev
, 3*HZ
);
711 * Handle not oper event in device recognition.
714 ccw_device_recog_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
716 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
720 * Handle not operational event while offline.
723 ccw_device_offline_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
725 struct subchannel
*sch
;
727 cdev
->private->state
= DEV_STATE_NOT_OPER
;
728 sch
= to_subchannel(cdev
->dev
.parent
);
729 if (get_device(&cdev
->dev
)) {
730 PREPARE_WORK(&cdev
->private->kick_work
,
731 ccw_device_call_sch_unregister
, cdev
);
732 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
734 wake_up(&cdev
->private->wait_q
);
738 * Handle not operational event while online.
741 ccw_device_online_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
743 struct subchannel
*sch
;
745 sch
= to_subchannel(cdev
->dev
.parent
);
746 if (sch
->driver
->notify
&&
747 sch
->driver
->notify(&sch
->dev
, sch
->lpm
? CIO_GONE
: CIO_NO_PATH
)) {
748 ccw_device_set_timeout(cdev
, 0);
749 cdev
->private->flags
.fake_irb
= 0;
750 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
751 wake_up(&cdev
->private->wait_q
);
754 cdev
->private->state
= DEV_STATE_NOT_OPER
;
755 cio_disable_subchannel(sch
);
756 if (sch
->schib
.scsw
.actl
!= 0) {
757 // FIXME: not-oper indication to device driver ?
758 ccw_device_call_handler(cdev
);
760 if (get_device(&cdev
->dev
)) {
761 PREPARE_WORK(&cdev
->private->kick_work
,
762 ccw_device_call_sch_unregister
, cdev
);
763 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
765 wake_up(&cdev
->private->wait_q
);
769 * Handle path verification event.
772 ccw_device_online_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
774 struct subchannel
*sch
;
776 if (cdev
->private->state
== DEV_STATE_W4SENSE
) {
777 cdev
->private->flags
.doverify
= 1;
780 sch
= to_subchannel(cdev
->dev
.parent
);
782 * Since we might not just be coming from an interrupt from the
783 * subchannel we have to update the schib.
785 stsch(sch
->schid
, &sch
->schib
);
787 if (sch
->schib
.scsw
.actl
!= 0 ||
788 (sch
->schib
.scsw
.stctl
& SCSW_STCTL_STATUS_PEND
) ||
789 (cdev
->private->irb
.scsw
.stctl
& SCSW_STCTL_STATUS_PEND
)) {
791 * No final status yet or final status not yet delivered
792 * to the device driver. Can't do path verfication now,
793 * delay until final status was delivered.
795 cdev
->private->flags
.doverify
= 1;
798 /* Device is idle, we can do the path verification. */
799 cdev
->private->state
= DEV_STATE_VERIFY
;
800 cdev
->private->flags
.doverify
= 0;
801 ccw_device_verify_start(cdev
);
805 * Got an interrupt for a normal io (state online).
808 ccw_device_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
812 irb
= (struct irb
*) __LC_IRB
;
813 /* Check for unsolicited interrupt. */
814 if ((irb
->scsw
.stctl
==
815 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
))
816 && (!irb
->scsw
.cc
)) {
817 if ((irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) &&
818 !irb
->esw
.esw0
.erw
.cons
) {
819 /* Unit check but no sense data. Need basic sense. */
820 if (ccw_device_do_sense(cdev
, irb
) != 0)
821 goto call_handler_unsol
;
822 memcpy(&cdev
->private->irb
, irb
, sizeof(struct irb
));
823 cdev
->private->state
= DEV_STATE_W4SENSE
;
824 cdev
->private->intparm
= 0;
829 cdev
->handler (cdev
, 0, irb
);
832 /* Accumulate status and find out if a basic sense is needed. */
833 ccw_device_accumulate_irb(cdev
, irb
);
834 if (cdev
->private->flags
.dosense
) {
835 if (ccw_device_do_sense(cdev
, irb
) == 0) {
836 cdev
->private->state
= DEV_STATE_W4SENSE
;
840 /* Call the handler. */
841 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
842 /* Start delayed path verification. */
843 ccw_device_online_verify(cdev
, 0);
847 * Got an timeout in online state.
850 ccw_device_online_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
854 ccw_device_set_timeout(cdev
, 0);
855 ret
= ccw_device_cancel_halt_clear(cdev
);
857 ccw_device_set_timeout(cdev
, 3*HZ
);
858 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
861 if (ret
== -ENODEV
) {
862 struct subchannel
*sch
;
864 sch
= to_subchannel(cdev
->dev
.parent
);
866 PREPARE_WORK(&cdev
->private->kick_work
,
867 ccw_device_nopath_notify
, cdev
);
868 queue_work(ccw_device_notify_work
,
869 &cdev
->private->kick_work
);
871 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
872 } else if (cdev
->handler
)
873 cdev
->handler(cdev
, cdev
->private->intparm
,
874 ERR_PTR(-ETIMEDOUT
));
878 * Got an interrupt for a basic sense.
881 ccw_device_w4sense(struct ccw_device
*cdev
, enum dev_event dev_event
)
885 irb
= (struct irb
*) __LC_IRB
;
886 /* Check for unsolicited interrupt. */
887 if (irb
->scsw
.stctl
==
888 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
889 if (irb
->scsw
.cc
== 1)
890 /* Basic sense hasn't started. Try again. */
891 ccw_device_do_sense(cdev
, irb
);
893 printk(KERN_INFO
"Huh? %s(%s): unsolicited "
895 __FUNCTION__
, cdev
->dev
.bus_id
);
897 cdev
->handler (cdev
, 0, irb
);
902 * Check if a halt or clear has been issued in the meanwhile. If yes,
903 * only deliver the halt/clear interrupt to the device driver as if it
904 * had killed the original request.
906 if (irb
->scsw
.fctl
& (SCSW_FCTL_CLEAR_FUNC
| SCSW_FCTL_HALT_FUNC
)) {
907 cdev
->private->flags
.dosense
= 0;
908 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
909 ccw_device_accumulate_irb(cdev
, irb
);
912 /* Add basic sense info to irb. */
913 ccw_device_accumulate_basic_sense(cdev
, irb
);
914 if (cdev
->private->flags
.dosense
) {
915 /* Another basic sense is needed. */
916 ccw_device_do_sense(cdev
, irb
);
920 cdev
->private->state
= DEV_STATE_ONLINE
;
921 /* Call the handler. */
922 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
923 /* Start delayed path verification. */
924 ccw_device_online_verify(cdev
, 0);
928 ccw_device_clear_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
932 irb
= (struct irb
*) __LC_IRB
;
933 /* Accumulate status. We don't do basic sense. */
934 ccw_device_accumulate_irb(cdev
, irb
);
935 /* Remember to clear irb to avoid residuals. */
936 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
937 /* Try to start delayed device verification. */
938 ccw_device_online_verify(cdev
, 0);
939 /* Note: Don't call handler for cio initiated clear! */
943 ccw_device_killing_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
945 struct subchannel
*sch
;
947 sch
= to_subchannel(cdev
->dev
.parent
);
948 ccw_device_set_timeout(cdev
, 0);
949 /* OK, i/o is dead now. Call interrupt handler. */
950 cdev
->private->state
= DEV_STATE_ONLINE
;
952 cdev
->handler(cdev
, cdev
->private->intparm
,
955 PREPARE_WORK(&cdev
->private->kick_work
,
956 ccw_device_nopath_notify
, cdev
);
957 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
958 } else if (cdev
->private->flags
.doverify
)
959 /* Start delayed path verification. */
960 ccw_device_online_verify(cdev
, 0);
964 ccw_device_killing_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
968 ret
= ccw_device_cancel_halt_clear(cdev
);
970 ccw_device_set_timeout(cdev
, 3*HZ
);
973 if (ret
== -ENODEV
) {
974 struct subchannel
*sch
;
976 sch
= to_subchannel(cdev
->dev
.parent
);
978 PREPARE_WORK(&cdev
->private->kick_work
,
979 ccw_device_nopath_notify
, cdev
);
980 queue_work(ccw_device_notify_work
,
981 &cdev
->private->kick_work
);
983 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
986 //FIXME: Can we get here?
987 cdev
->private->state
= DEV_STATE_ONLINE
;
989 cdev
->handler(cdev
, cdev
->private->intparm
,
993 void device_kill_io(struct subchannel
*sch
)
996 struct ccw_device
*cdev
;
998 cdev
= sch
->dev
.driver_data
;
999 ret
= ccw_device_cancel_halt_clear(cdev
);
1000 if (ret
== -EBUSY
) {
1001 ccw_device_set_timeout(cdev
, 3*HZ
);
1002 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
1005 if (ret
== -ENODEV
) {
1007 PREPARE_WORK(&cdev
->private->kick_work
,
1008 ccw_device_nopath_notify
, cdev
);
1009 queue_work(ccw_device_notify_work
,
1010 &cdev
->private->kick_work
);
1012 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
1016 cdev
->handler(cdev
, cdev
->private->intparm
,
1019 PREPARE_WORK(&cdev
->private->kick_work
,
1020 ccw_device_nopath_notify
, cdev
);
1021 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
1023 /* Start delayed path verification. */
1024 ccw_device_online_verify(cdev
, 0);
1028 ccw_device_delay_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
1030 /* Start verification after current task finished. */
1031 cdev
->private->flags
.doverify
= 1;
1035 ccw_device_stlck_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
1039 switch (dev_event
) {
1040 case DEV_EVENT_INTERRUPT
:
1041 irb
= (struct irb
*) __LC_IRB
;
1042 /* Check for unsolicited interrupt. */
1043 if ((irb
->scsw
.stctl
==
1044 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) &&
1046 /* FIXME: we should restart stlck here, but this
1047 * is extremely unlikely ... */
1050 ccw_device_accumulate_irb(cdev
, irb
);
1051 /* We don't care about basic sense etc. */
1053 default: /* timeout */
1057 wake_up(&cdev
->private->wait_q
);
1061 ccw_device_start_id(struct ccw_device
*cdev
, enum dev_event dev_event
)
1063 struct subchannel
*sch
;
1065 sch
= to_subchannel(cdev
->dev
.parent
);
1066 if (cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
) != 0)
1067 /* Couldn't enable the subchannel for i/o. Sick device. */
1070 /* After 60s the device recognition is considered to have failed. */
1071 ccw_device_set_timeout(cdev
, 60*HZ
);
1073 cdev
->private->state
= DEV_STATE_DISCONNECTED_SENSE_ID
;
1074 ccw_device_sense_id_start(cdev
);
1078 device_trigger_reprobe(struct subchannel
*sch
)
1080 struct ccw_device
*cdev
;
1082 if (!sch
->dev
.driver_data
)
1084 cdev
= sch
->dev
.driver_data
;
1085 if (cdev
->private->state
!= DEV_STATE_DISCONNECTED
)
1088 /* Update some values. */
1089 if (stsch(sch
->schid
, &sch
->schib
))
1093 * The pim, pam, pom values may not be accurate, but they are the best
1094 * we have before performing device selection :/
1096 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
1097 /* Re-set some bits in the pmcw that were lost. */
1098 sch
->schib
.pmcw
.isc
= 3;
1099 sch
->schib
.pmcw
.csense
= 1;
1100 sch
->schib
.pmcw
.ena
= 0;
1101 if ((sch
->lpm
& (sch
->lpm
- 1)) != 0)
1102 sch
->schib
.pmcw
.mp
= 1;
1103 sch
->schib
.pmcw
.intparm
= (__u32
)(unsigned long)sch
;
1104 /* We should also udate ssd info, but this has to wait. */
1105 ccw_device_start_id(cdev
, 0);
1109 ccw_device_offline_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
1111 struct subchannel
*sch
;
1113 sch
= to_subchannel(cdev
->dev
.parent
);
1115 * An interrupt in state offline means a previous disable was not
1116 * successful. Try again.
1118 cio_disable_subchannel(sch
);
1122 ccw_device_change_cmfstate(struct ccw_device
*cdev
, enum dev_event dev_event
)
1124 retry_set_schib(cdev
);
1125 cdev
->private->state
= DEV_STATE_ONLINE
;
1126 dev_fsm_event(cdev
, dev_event
);
1129 static void ccw_device_update_cmfblock(struct ccw_device
*cdev
,
1130 enum dev_event dev_event
)
1132 cmf_retry_copy_block(cdev
);
1133 cdev
->private->state
= DEV_STATE_ONLINE
;
1134 dev_fsm_event(cdev
, dev_event
);
1138 ccw_device_quiesce_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
1140 ccw_device_set_timeout(cdev
, 0);
1141 if (dev_event
== DEV_EVENT_NOTOPER
)
1142 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1144 cdev
->private->state
= DEV_STATE_OFFLINE
;
1145 wake_up(&cdev
->private->wait_q
);
1149 ccw_device_quiesce_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
1153 ret
= ccw_device_cancel_halt_clear(cdev
);
1156 cdev
->private->state
= DEV_STATE_OFFLINE
;
1157 wake_up(&cdev
->private->wait_q
);
1160 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1161 wake_up(&cdev
->private->wait_q
);
1164 ccw_device_set_timeout(cdev
, HZ
/10);
1169 * No operation action. This is used e.g. to ignore a timeout event in
1173 ccw_device_nop(struct ccw_device
*cdev
, enum dev_event dev_event
)
1178 * Bug operation action.
1181 ccw_device_bug(struct ccw_device
*cdev
, enum dev_event dev_event
)
1183 printk(KERN_EMERG
"dev_jumptable[%i][%i] == NULL\n",
1184 cdev
->private->state
, dev_event
);
1189 * device statemachine
1191 fsm_func_t
*dev_jumptable
[NR_DEV_STATES
][NR_DEV_EVENTS
] = {
1192 [DEV_STATE_NOT_OPER
] = {
1193 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1194 [DEV_EVENT_INTERRUPT
] = ccw_device_bug
,
1195 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1196 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1198 [DEV_STATE_SENSE_PGID
] = {
1199 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1200 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_pgid_irq
,
1201 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1202 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1204 [DEV_STATE_SENSE_ID
] = {
1205 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1206 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1207 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1208 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1210 [DEV_STATE_OFFLINE
] = {
1211 [DEV_EVENT_NOTOPER
] = ccw_device_offline_notoper
,
1212 [DEV_EVENT_INTERRUPT
] = ccw_device_offline_irq
,
1213 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1214 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1216 [DEV_STATE_VERIFY
] = {
1217 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1218 [DEV_EVENT_INTERRUPT
] = ccw_device_verify_irq
,
1219 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1220 [DEV_EVENT_VERIFY
] = ccw_device_delay_verify
,
1222 [DEV_STATE_ONLINE
] = {
1223 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1224 [DEV_EVENT_INTERRUPT
] = ccw_device_irq
,
1225 [DEV_EVENT_TIMEOUT
] = ccw_device_online_timeout
,
1226 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1228 [DEV_STATE_W4SENSE
] = {
1229 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1230 [DEV_EVENT_INTERRUPT
] = ccw_device_w4sense
,
1231 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1232 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1234 [DEV_STATE_DISBAND_PGID
] = {
1235 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1236 [DEV_EVENT_INTERRUPT
] = ccw_device_disband_irq
,
1237 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1238 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1240 [DEV_STATE_BOXED
] = {
1241 [DEV_EVENT_NOTOPER
] = ccw_device_offline_notoper
,
1242 [DEV_EVENT_INTERRUPT
] = ccw_device_stlck_done
,
1243 [DEV_EVENT_TIMEOUT
] = ccw_device_stlck_done
,
1244 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1246 /* states to wait for i/o completion before doing something */
1247 [DEV_STATE_CLEAR_VERIFY
] = {
1248 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1249 [DEV_EVENT_INTERRUPT
] = ccw_device_clear_verify
,
1250 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1251 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1253 [DEV_STATE_TIMEOUT_KILL
] = {
1254 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1255 [DEV_EVENT_INTERRUPT
] = ccw_device_killing_irq
,
1256 [DEV_EVENT_TIMEOUT
] = ccw_device_killing_timeout
,
1257 [DEV_EVENT_VERIFY
] = ccw_device_nop
, //FIXME
1259 [DEV_STATE_QUIESCE
] = {
1260 [DEV_EVENT_NOTOPER
] = ccw_device_quiesce_done
,
1261 [DEV_EVENT_INTERRUPT
] = ccw_device_quiesce_done
,
1262 [DEV_EVENT_TIMEOUT
] = ccw_device_quiesce_timeout
,
1263 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1265 /* special states for devices gone not operational */
1266 [DEV_STATE_DISCONNECTED
] = {
1267 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1268 [DEV_EVENT_INTERRUPT
] = ccw_device_start_id
,
1269 [DEV_EVENT_TIMEOUT
] = ccw_device_bug
,
1270 [DEV_EVENT_VERIFY
] = ccw_device_start_id
,
1272 [DEV_STATE_DISCONNECTED_SENSE_ID
] = {
1273 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1274 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1275 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1276 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1278 [DEV_STATE_CMFCHANGE
] = {
1279 [DEV_EVENT_NOTOPER
] = ccw_device_change_cmfstate
,
1280 [DEV_EVENT_INTERRUPT
] = ccw_device_change_cmfstate
,
1281 [DEV_EVENT_TIMEOUT
] = ccw_device_change_cmfstate
,
1282 [DEV_EVENT_VERIFY
] = ccw_device_change_cmfstate
,
1284 [DEV_STATE_CMFUPDATE
] = {
1285 [DEV_EVENT_NOTOPER
] = ccw_device_update_cmfblock
,
1286 [DEV_EVENT_INTERRUPT
] = ccw_device_update_cmfblock
,
1287 [DEV_EVENT_TIMEOUT
] = ccw_device_update_cmfblock
,
1288 [DEV_EVENT_VERIFY
] = ccw_device_update_cmfblock
,
1293 * io_subchannel_irq is called for "real" interrupts or for status
1294 * pending conditions on msch.
1297 io_subchannel_irq (struct device
*pdev
)
1299 struct ccw_device
*cdev
;
1301 cdev
= to_subchannel(pdev
)->dev
.driver_data
;
1303 CIO_TRACE_EVENT (3, "IRQ");
1304 CIO_TRACE_EVENT (3, pdev
->bus_id
);
1306 dev_fsm_event(cdev
, DEV_EVENT_INTERRUPT
);
1309 EXPORT_SYMBOL_GPL(ccw_device_set_timeout
);