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(cohuck@de.ibm.com)
8 * Martin Schwidefsky (schwidefsky@de.ibm.com)
11 #include <linux/module.h>
12 #include <linux/config.h>
13 #include <linux/init.h>
15 #include <asm/ccwdev.h>
19 #include "cio_debug.h"
26 device_is_online(struct subchannel
*sch
)
28 struct ccw_device
*cdev
;
30 if (!sch
->dev
.driver_data
)
32 cdev
= sch
->dev
.driver_data
;
33 return (cdev
->private->state
== DEV_STATE_ONLINE
);
37 device_is_disconnected(struct subchannel
*sch
)
39 struct ccw_device
*cdev
;
41 if (!sch
->dev
.driver_data
)
43 cdev
= sch
->dev
.driver_data
;
44 return (cdev
->private->state
== DEV_STATE_DISCONNECTED
||
45 cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
);
49 device_set_disconnected(struct subchannel
*sch
)
51 struct ccw_device
*cdev
;
53 if (!sch
->dev
.driver_data
)
55 cdev
= sch
->dev
.driver_data
;
56 ccw_device_set_timeout(cdev
, 0);
57 cdev
->private->flags
.fake_irb
= 0;
58 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
62 device_set_waiting(struct subchannel
*sch
)
64 struct ccw_device
*cdev
;
66 if (!sch
->dev
.driver_data
)
68 cdev
= sch
->dev
.driver_data
;
69 ccw_device_set_timeout(cdev
, 10*HZ
);
70 cdev
->private->state
= DEV_STATE_WAIT4IO
;
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
->irq
, &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
--;
154 return (ret
== 0) ? -EBUSY
: ret
;
156 /* halt io unsuccessful. */
157 cdev
->private->iretry
= 255; /* 255 clear retries. */
159 /* Stage 3: clear io. */
160 if (cdev
->private->iretry
) {
161 cdev
->private->iretry
--;
162 ret
= cio_clear (sch
);
163 return (ret
== 0) ? -EBUSY
: ret
;
165 panic("Can't stop i/o on subchannel.\n");
169 ccw_device_handle_oper(struct ccw_device
*cdev
)
171 struct subchannel
*sch
;
173 sch
= to_subchannel(cdev
->dev
.parent
);
174 cdev
->private->flags
.recog_done
= 1;
176 * Check if cu type and device type still match. If
177 * not, it is certainly another device and we have to
178 * de- and re-register. Also check here for non-matching devno.
180 if (cdev
->id
.cu_type
!= cdev
->private->senseid
.cu_type
||
181 cdev
->id
.cu_model
!= cdev
->private->senseid
.cu_model
||
182 cdev
->id
.dev_type
!= cdev
->private->senseid
.dev_type
||
183 cdev
->id
.dev_model
!= cdev
->private->senseid
.dev_model
||
184 cdev
->private->devno
!= sch
->schib
.pmcw
.dev
) {
185 PREPARE_WORK(&cdev
->private->kick_work
,
186 ccw_device_do_unreg_rereg
, (void *)cdev
);
187 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
190 cdev
->private->flags
.donotify
= 1;
195 * The machine won't give us any notification by machine check if a chpid has
196 * been varied online on the SE so we have to find out by magic (i. e. driving
197 * the channel subsystem to device selection and updating our path masks).
200 __recover_lost_chpids(struct subchannel
*sch
, int old_lpm
)
204 for (i
= 0; i
<8; i
++) {
206 if (!(sch
->lpm
& mask
))
210 chpid_is_actually_online(sch
->schib
.pmcw
.chpid
[i
]);
215 * Stop device recognition.
218 ccw_device_recog_done(struct ccw_device
*cdev
, int state
)
220 struct subchannel
*sch
;
221 int notify
, old_lpm
, same_dev
;
223 sch
= to_subchannel(cdev
->dev
.parent
);
225 ccw_device_set_timeout(cdev
, 0);
226 cio_disable_subchannel(sch
);
228 * Now that we tried recognition, we have performed device selection
229 * through ssch() and the path information is up to date.
232 stsch(sch
->irq
, &sch
->schib
);
233 sch
->lpm
= sch
->schib
.pmcw
.pim
&
234 sch
->schib
.pmcw
.pam
&
235 sch
->schib
.pmcw
.pom
&
237 /* Check since device may again have become not operational. */
238 if (!sch
->schib
.pmcw
.dnv
)
239 state
= DEV_STATE_NOT_OPER
;
240 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
)
241 /* Force reprobe on all chpids. */
243 if (sch
->lpm
!= old_lpm
)
244 __recover_lost_chpids(sch
, old_lpm
);
245 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
246 if (state
== DEV_STATE_NOT_OPER
) {
247 cdev
->private->flags
.recog_done
= 1;
248 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
251 /* Boxed devices don't need extra treatment. */
254 same_dev
= 0; /* Keep the compiler quiet... */
256 case DEV_STATE_NOT_OPER
:
257 CIO_DEBUG(KERN_WARNING
, 2,
258 "SenseID : unknown device %04x on subchannel %04x\n",
259 cdev
->private->devno
, sch
->irq
);
261 case DEV_STATE_OFFLINE
:
262 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
263 same_dev
= ccw_device_handle_oper(cdev
);
266 /* fill out sense information */
267 cdev
->id
= (struct ccw_device_id
) {
268 .cu_type
= cdev
->private->senseid
.cu_type
,
269 .cu_model
= cdev
->private->senseid
.cu_model
,
270 .dev_type
= cdev
->private->senseid
.dev_type
,
271 .dev_model
= cdev
->private->senseid
.dev_model
,
274 cdev
->private->state
= DEV_STATE_OFFLINE
;
276 /* Get device online again. */
277 ccw_device_online(cdev
);
278 wake_up(&cdev
->private->wait_q
);
282 /* Issue device info message. */
283 CIO_DEBUG(KERN_INFO
, 2, "SenseID : device %04x reports: "
284 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
285 "%04X/%02X\n", cdev
->private->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 %04x\n",
292 cdev
->private->devno
, sch
->irq
);
295 cdev
->private->state
= state
;
296 io_subchannel_recog_done(cdev
);
297 if (state
!= DEV_STATE_NOT_OPER
)
298 wake_up(&cdev
->private->wait_q
);
302 * Function called from device_id.c after sense id has completed.
305 ccw_device_sense_id_done(struct ccw_device
*cdev
, int err
)
309 ccw_device_recog_done(cdev
, DEV_STATE_OFFLINE
);
311 case -ETIME
: /* Sense id stopped by timeout. */
312 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
315 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
321 ccw_device_oper_notify(void *data
)
323 struct ccw_device
*cdev
;
324 struct subchannel
*sch
;
327 cdev
= (struct ccw_device
*)data
;
328 sch
= to_subchannel(cdev
->dev
.parent
);
329 ret
= (sch
->driver
&& sch
->driver
->notify
) ?
330 sch
->driver
->notify(&sch
->dev
, CIO_OPER
) : 0;
332 /* Driver doesn't want device back. */
333 ccw_device_do_unreg_rereg((void *)cdev
);
335 wake_up(&cdev
->private->wait_q
);
339 * Finished with online/offline processing.
342 ccw_device_done(struct ccw_device
*cdev
, int state
)
344 struct subchannel
*sch
;
346 sch
= to_subchannel(cdev
->dev
.parent
);
348 if (state
!= DEV_STATE_ONLINE
)
349 cio_disable_subchannel(sch
);
351 /* Reset device status. */
352 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
354 cdev
->private->state
= state
;
357 if (state
== DEV_STATE_BOXED
)
358 CIO_DEBUG(KERN_WARNING
, 2,
359 "Boxed device %04x on subchannel %04x\n",
360 cdev
->private->devno
, sch
->irq
);
362 if (cdev
->private->flags
.donotify
) {
363 cdev
->private->flags
.donotify
= 0;
364 PREPARE_WORK(&cdev
->private->kick_work
, ccw_device_oper_notify
,
366 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
368 wake_up(&cdev
->private->wait_q
);
370 if (css_init_done
&& state
!= DEV_STATE_ONLINE
)
371 put_device (&cdev
->dev
);
375 * Function called from device_pgid.c after sense path ground has completed.
378 ccw_device_sense_pgid_done(struct ccw_device
*cdev
, int err
)
380 struct subchannel
*sch
;
382 sch
= to_subchannel(cdev
->dev
.parent
);
385 /* Start Path Group verification. */
386 sch
->vpm
= 0; /* Start with no path groups set. */
387 cdev
->private->state
= DEV_STATE_VERIFY
;
388 ccw_device_verify_start(cdev
);
390 case -ETIME
: /* Sense path group id stopped by timeout. */
391 case -EUSERS
: /* device is reserved for someone else. */
392 ccw_device_done(cdev
, DEV_STATE_BOXED
);
394 case -EOPNOTSUPP
: /* path grouping not supported, just set online. */
395 cdev
->private->options
.pgroup
= 0;
396 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
399 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
405 * Start device recognition.
408 ccw_device_recognition(struct ccw_device
*cdev
)
410 struct subchannel
*sch
;
413 if ((cdev
->private->state
!= DEV_STATE_NOT_OPER
) &&
414 (cdev
->private->state
!= DEV_STATE_BOXED
))
416 sch
= to_subchannel(cdev
->dev
.parent
);
417 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
419 /* Couldn't enable the subchannel for i/o. Sick device. */
422 /* After 60s the device recognition is considered to have failed. */
423 ccw_device_set_timeout(cdev
, 60*HZ
);
426 * We used to start here with a sense pgid to find out whether a device
427 * is locked by someone else. Unfortunately, the sense pgid command
428 * code has other meanings on devices predating the path grouping
429 * algorithm, so we start with sense id and box the device after an
430 * timeout (or if sense pgid during path verification detects the device
431 * is locked, as may happen on newer devices).
433 cdev
->private->flags
.recog_done
= 0;
434 cdev
->private->state
= DEV_STATE_SENSE_ID
;
435 ccw_device_sense_id_start(cdev
);
440 * Handle timeout in device recognition.
443 ccw_device_recog_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
447 ret
= ccw_device_cancel_halt_clear(cdev
);
450 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
453 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
456 ccw_device_set_timeout(cdev
, 3*HZ
);
462 ccw_device_nopath_notify(void *data
)
464 struct ccw_device
*cdev
;
465 struct subchannel
*sch
;
468 cdev
= (struct ccw_device
*)data
;
469 sch
= to_subchannel(cdev
->dev
.parent
);
473 ret
= (sch
->driver
&& sch
->driver
->notify
) ?
474 sch
->driver
->notify(&sch
->dev
, CIO_NO_PATH
) : 0;
476 if (get_device(&sch
->dev
)) {
477 /* Driver doesn't want to keep device. */
478 cio_disable_subchannel(sch
);
479 if (get_device(&cdev
->dev
)) {
480 PREPARE_WORK(&cdev
->private->kick_work
,
481 ccw_device_call_sch_unregister
,
483 queue_work(ccw_device_work
,
484 &cdev
->private->kick_work
);
486 put_device(&sch
->dev
);
489 cio_disable_subchannel(sch
);
490 ccw_device_set_timeout(cdev
, 0);
491 cdev
->private->flags
.fake_irb
= 0;
492 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
493 wake_up(&cdev
->private->wait_q
);
498 ccw_device_verify_done(struct ccw_device
*cdev
, int err
)
500 cdev
->private->flags
.doverify
= 0;
502 case -EOPNOTSUPP
: /* path grouping not supported, just set online. */
503 cdev
->private->options
.pgroup
= 0;
505 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
506 /* Deliver fake irb to device driver, if needed. */
507 if (cdev
->private->flags
.fake_irb
) {
508 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
509 cdev
->private->irb
.scsw
= (struct scsw
) {
511 .fctl
= SCSW_FCTL_START_FUNC
,
512 .actl
= SCSW_ACTL_START_PEND
,
513 .stctl
= SCSW_STCTL_STATUS_PEND
,
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
));
523 ccw_device_done(cdev
, DEV_STATE_BOXED
);
526 PREPARE_WORK(&cdev
->private->kick_work
,
527 ccw_device_nopath_notify
, (void *)cdev
);
528 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
529 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
538 ccw_device_online(struct ccw_device
*cdev
)
540 struct subchannel
*sch
;
543 if ((cdev
->private->state
!= DEV_STATE_OFFLINE
) &&
544 (cdev
->private->state
!= DEV_STATE_BOXED
))
546 sch
= to_subchannel(cdev
->dev
.parent
);
547 if (css_init_done
&& !get_device(&cdev
->dev
))
549 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
551 /* Couldn't enable the subchannel for i/o. Sick device. */
553 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
556 /* Do we want to do path grouping? */
557 if (!cdev
->private->options
.pgroup
) {
558 /* No, set state online immediately. */
559 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
562 /* Do a SensePGID first. */
563 cdev
->private->state
= DEV_STATE_SENSE_PGID
;
564 ccw_device_sense_pgid_start(cdev
);
569 ccw_device_disband_done(struct ccw_device
*cdev
, int err
)
573 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
576 ccw_device_done(cdev
, DEV_STATE_BOXED
);
579 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
588 ccw_device_offline(struct ccw_device
*cdev
)
590 struct subchannel
*sch
;
592 sch
= to_subchannel(cdev
->dev
.parent
);
593 if (stsch(sch
->irq
, &sch
->schib
) || !sch
->schib
.pmcw
.dnv
)
595 if (cdev
->private->state
!= DEV_STATE_ONLINE
) {
596 if (sch
->schib
.scsw
.actl
!= 0)
600 if (sch
->schib
.scsw
.actl
!= 0)
602 /* Are we doing path grouping? */
603 if (!cdev
->private->options
.pgroup
) {
604 /* No, set state offline immediately. */
605 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
608 /* Start Set Path Group commands. */
609 cdev
->private->state
= DEV_STATE_DISBAND_PGID
;
610 ccw_device_disband_start(cdev
);
615 * Handle timeout in device online/offline process.
618 ccw_device_onoff_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
622 ret
= ccw_device_cancel_halt_clear(cdev
);
625 ccw_device_done(cdev
, DEV_STATE_BOXED
);
628 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
631 ccw_device_set_timeout(cdev
, 3*HZ
);
636 * Handle not oper event in device recognition.
639 ccw_device_recog_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
641 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
645 * Handle not operational event while offline.
648 ccw_device_offline_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
650 struct subchannel
*sch
;
652 cdev
->private->state
= DEV_STATE_NOT_OPER
;
653 sch
= to_subchannel(cdev
->dev
.parent
);
654 if (get_device(&cdev
->dev
)) {
655 PREPARE_WORK(&cdev
->private->kick_work
,
656 ccw_device_call_sch_unregister
, (void *)cdev
);
657 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
659 wake_up(&cdev
->private->wait_q
);
663 * Handle not operational event while online.
666 ccw_device_online_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
668 struct subchannel
*sch
;
670 sch
= to_subchannel(cdev
->dev
.parent
);
671 if (sch
->driver
->notify
&&
672 sch
->driver
->notify(&sch
->dev
, sch
->lpm
? CIO_GONE
: CIO_NO_PATH
)) {
673 ccw_device_set_timeout(cdev
, 0);
674 cdev
->private->flags
.fake_irb
= 0;
675 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
676 wake_up(&cdev
->private->wait_q
);
679 cdev
->private->state
= DEV_STATE_NOT_OPER
;
680 cio_disable_subchannel(sch
);
681 if (sch
->schib
.scsw
.actl
!= 0) {
682 // FIXME: not-oper indication to device driver ?
683 ccw_device_call_handler(cdev
);
685 if (get_device(&cdev
->dev
)) {
686 PREPARE_WORK(&cdev
->private->kick_work
,
687 ccw_device_call_sch_unregister
, (void *)cdev
);
688 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
690 wake_up(&cdev
->private->wait_q
);
694 * Handle path verification event.
697 ccw_device_online_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
699 struct subchannel
*sch
;
701 if (!cdev
->private->options
.pgroup
)
703 if (cdev
->private->state
== DEV_STATE_W4SENSE
) {
704 cdev
->private->flags
.doverify
= 1;
707 sch
= to_subchannel(cdev
->dev
.parent
);
709 * Since we might not just be coming from an interrupt from the
710 * subchannel we have to update the schib.
712 stsch(sch
->irq
, &sch
->schib
);
714 if (sch
->schib
.scsw
.actl
!= 0 ||
715 (cdev
->private->irb
.scsw
.stctl
& SCSW_STCTL_STATUS_PEND
)) {
717 * No final status yet or final status not yet delivered
718 * to the device driver. Can't do path verfication now,
719 * delay until final status was delivered.
721 cdev
->private->flags
.doverify
= 1;
724 /* Device is idle, we can do the path verification. */
725 cdev
->private->state
= DEV_STATE_VERIFY
;
726 ccw_device_verify_start(cdev
);
730 * Got an interrupt for a normal io (state online).
733 ccw_device_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
737 irb
= (struct irb
*) __LC_IRB
;
738 /* Check for unsolicited interrupt. */
739 if ((irb
->scsw
.stctl
==
740 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
))
741 && (!irb
->scsw
.cc
)) {
742 if ((irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) &&
743 !irb
->esw
.esw0
.erw
.cons
) {
744 /* Unit check but no sense data. Need basic sense. */
745 if (ccw_device_do_sense(cdev
, irb
) != 0)
746 goto call_handler_unsol
;
747 memcpy(irb
, &cdev
->private->irb
, sizeof(struct irb
));
748 cdev
->private->state
= DEV_STATE_W4SENSE
;
749 cdev
->private->intparm
= 0;
754 cdev
->handler (cdev
, 0, irb
);
757 /* Accumulate status and find out if a basic sense is needed. */
758 ccw_device_accumulate_irb(cdev
, irb
);
759 if (cdev
->private->flags
.dosense
) {
760 if (ccw_device_do_sense(cdev
, irb
) == 0) {
761 cdev
->private->state
= DEV_STATE_W4SENSE
;
765 /* Call the handler. */
766 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
767 /* Start delayed path verification. */
768 ccw_device_online_verify(cdev
, 0);
772 * Got an timeout in online state.
775 ccw_device_online_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
779 ccw_device_set_timeout(cdev
, 0);
780 ret
= ccw_device_cancel_halt_clear(cdev
);
782 ccw_device_set_timeout(cdev
, 3*HZ
);
783 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
786 if (ret
== -ENODEV
) {
787 struct subchannel
*sch
;
789 sch
= to_subchannel(cdev
->dev
.parent
);
791 PREPARE_WORK(&cdev
->private->kick_work
,
792 ccw_device_nopath_notify
, (void *)cdev
);
793 queue_work(ccw_device_notify_work
,
794 &cdev
->private->kick_work
);
796 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
797 } else if (cdev
->handler
)
798 cdev
->handler(cdev
, cdev
->private->intparm
,
799 ERR_PTR(-ETIMEDOUT
));
803 * Got an interrupt for a basic sense.
806 ccw_device_w4sense(struct ccw_device
*cdev
, enum dev_event dev_event
)
810 irb
= (struct irb
*) __LC_IRB
;
811 /* Check for unsolicited interrupt. */
812 if (irb
->scsw
.stctl
==
813 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
814 if (irb
->scsw
.cc
== 1)
815 /* Basic sense hasn't started. Try again. */
816 ccw_device_do_sense(cdev
, irb
);
818 printk("Huh? %s(%s): unsolicited interrupt...\n",
819 __FUNCTION__
, cdev
->dev
.bus_id
);
821 cdev
->handler (cdev
, 0, irb
);
825 /* Add basic sense info to irb. */
826 ccw_device_accumulate_basic_sense(cdev
, irb
);
827 if (cdev
->private->flags
.dosense
) {
828 /* Another basic sense is needed. */
829 ccw_device_do_sense(cdev
, irb
);
832 cdev
->private->state
= DEV_STATE_ONLINE
;
833 /* Call the handler. */
834 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
835 /* Start delayed path verification. */
836 ccw_device_online_verify(cdev
, 0);
840 ccw_device_clear_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
844 irb
= (struct irb
*) __LC_IRB
;
845 /* Accumulate status. We don't do basic sense. */
846 ccw_device_accumulate_irb(cdev
, irb
);
847 /* Try to start delayed device verification. */
848 ccw_device_online_verify(cdev
, 0);
849 /* Note: Don't call handler for cio initiated clear! */
853 ccw_device_killing_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
855 struct subchannel
*sch
;
857 sch
= to_subchannel(cdev
->dev
.parent
);
858 ccw_device_set_timeout(cdev
, 0);
859 /* OK, i/o is dead now. Call interrupt handler. */
860 cdev
->private->state
= DEV_STATE_ONLINE
;
862 cdev
->handler(cdev
, cdev
->private->intparm
,
863 ERR_PTR(-ETIMEDOUT
));
865 PREPARE_WORK(&cdev
->private->kick_work
,
866 ccw_device_nopath_notify
, (void *)cdev
);
867 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
868 } else if (cdev
->private->flags
.doverify
)
869 /* Start delayed path verification. */
870 ccw_device_online_verify(cdev
, 0);
874 ccw_device_killing_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
878 ret
= ccw_device_cancel_halt_clear(cdev
);
880 ccw_device_set_timeout(cdev
, 3*HZ
);
883 if (ret
== -ENODEV
) {
884 struct subchannel
*sch
;
886 sch
= to_subchannel(cdev
->dev
.parent
);
888 PREPARE_WORK(&cdev
->private->kick_work
,
889 ccw_device_nopath_notify
, (void *)cdev
);
890 queue_work(ccw_device_notify_work
,
891 &cdev
->private->kick_work
);
893 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
896 //FIXME: Can we get here?
897 cdev
->private->state
= DEV_STATE_ONLINE
;
899 cdev
->handler(cdev
, cdev
->private->intparm
,
900 ERR_PTR(-ETIMEDOUT
));
904 ccw_device_wait4io_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
907 struct subchannel
*sch
;
909 irb
= (struct irb
*) __LC_IRB
;
911 * Accumulate status and find out if a basic sense is needed.
912 * This is fine since we have already adapted the lpm.
914 ccw_device_accumulate_irb(cdev
, irb
);
915 if (cdev
->private->flags
.dosense
) {
916 if (ccw_device_do_sense(cdev
, irb
) == 0) {
917 cdev
->private->state
= DEV_STATE_W4SENSE
;
922 /* Iff device is idle, reset timeout. */
923 sch
= to_subchannel(cdev
->dev
.parent
);
924 if (!stsch(sch
->irq
, &sch
->schib
))
925 if (sch
->schib
.scsw
.actl
== 0)
926 ccw_device_set_timeout(cdev
, 0);
927 /* Call the handler. */
928 ccw_device_call_handler(cdev
);
930 PREPARE_WORK(&cdev
->private->kick_work
,
931 ccw_device_nopath_notify
, (void *)cdev
);
932 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
933 } else if (cdev
->private->flags
.doverify
)
934 ccw_device_online_verify(cdev
, 0);
938 ccw_device_wait4io_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
941 struct subchannel
*sch
;
943 sch
= to_subchannel(cdev
->dev
.parent
);
944 ccw_device_set_timeout(cdev
, 0);
945 ret
= ccw_device_cancel_halt_clear(cdev
);
947 ccw_device_set_timeout(cdev
, 3*HZ
);
948 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
951 if (ret
== -ENODEV
) {
953 PREPARE_WORK(&cdev
->private->kick_work
,
954 ccw_device_nopath_notify
, (void *)cdev
);
955 queue_work(ccw_device_notify_work
,
956 &cdev
->private->kick_work
);
958 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
962 cdev
->handler(cdev
, cdev
->private->intparm
,
963 ERR_PTR(-ETIMEDOUT
));
965 PREPARE_WORK(&cdev
->private->kick_work
,
966 ccw_device_nopath_notify
, (void *)cdev
);
967 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
968 } else if (cdev
->private->flags
.doverify
)
969 /* Start delayed path verification. */
970 ccw_device_online_verify(cdev
, 0);
974 ccw_device_wait4io_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
976 /* When the I/O has terminated, we have to start verification. */
977 if (cdev
->private->options
.pgroup
)
978 cdev
->private->flags
.doverify
= 1;
982 ccw_device_stlck_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
987 case DEV_EVENT_INTERRUPT
:
988 irb
= (struct irb
*) __LC_IRB
;
989 /* Check for unsolicited interrupt. */
990 if ((irb
->scsw
.stctl
==
991 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) &&
993 /* FIXME: we should restart stlck here, but this
994 * is extremely unlikely ... */
997 ccw_device_accumulate_irb(cdev
, irb
);
998 /* We don't care about basic sense etc. */
1000 default: /* timeout */
1004 wake_up(&cdev
->private->wait_q
);
1008 ccw_device_start_id(struct ccw_device
*cdev
, enum dev_event dev_event
)
1010 struct subchannel
*sch
;
1012 sch
= to_subchannel(cdev
->dev
.parent
);
1013 if (cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
) != 0)
1014 /* Couldn't enable the subchannel for i/o. Sick device. */
1017 /* After 60s the device recognition is considered to have failed. */
1018 ccw_device_set_timeout(cdev
, 60*HZ
);
1020 cdev
->private->state
= DEV_STATE_DISCONNECTED_SENSE_ID
;
1021 ccw_device_sense_id_start(cdev
);
1025 device_trigger_reprobe(struct subchannel
*sch
)
1027 struct ccw_device
*cdev
;
1029 if (!sch
->dev
.driver_data
)
1031 cdev
= sch
->dev
.driver_data
;
1032 if (cdev
->private->state
!= DEV_STATE_DISCONNECTED
)
1035 /* Update some values. */
1036 if (stsch(sch
->irq
, &sch
->schib
))
1040 * The pim, pam, pom values may not be accurate, but they are the best
1041 * we have before performing device selection :/
1043 sch
->lpm
= sch
->schib
.pmcw
.pim
&
1044 sch
->schib
.pmcw
.pam
&
1045 sch
->schib
.pmcw
.pom
&
1047 /* Re-set some bits in the pmcw that were lost. */
1048 sch
->schib
.pmcw
.isc
= 3;
1049 sch
->schib
.pmcw
.csense
= 1;
1050 sch
->schib
.pmcw
.ena
= 0;
1051 if ((sch
->lpm
& (sch
->lpm
- 1)) != 0)
1052 sch
->schib
.pmcw
.mp
= 1;
1053 sch
->schib
.pmcw
.intparm
= (__u32
)(unsigned long)sch
;
1054 /* We should also udate ssd info, but this has to wait. */
1055 ccw_device_start_id(cdev
, 0);
1059 ccw_device_offline_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
1061 struct subchannel
*sch
;
1063 sch
= to_subchannel(cdev
->dev
.parent
);
1065 * An interrupt in state offline means a previous disable was not
1066 * successful. Try again.
1068 cio_disable_subchannel(sch
);
1072 ccw_device_change_cmfstate(struct ccw_device
*cdev
, enum dev_event dev_event
)
1074 retry_set_schib(cdev
);
1075 cdev
->private->state
= DEV_STATE_ONLINE
;
1076 dev_fsm_event(cdev
, dev_event
);
1081 ccw_device_quiesce_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
1083 ccw_device_set_timeout(cdev
, 0);
1084 if (dev_event
== DEV_EVENT_NOTOPER
)
1085 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1087 cdev
->private->state
= DEV_STATE_OFFLINE
;
1088 wake_up(&cdev
->private->wait_q
);
1092 ccw_device_quiesce_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
1096 ret
= ccw_device_cancel_halt_clear(cdev
);
1099 cdev
->private->state
= DEV_STATE_OFFLINE
;
1100 wake_up(&cdev
->private->wait_q
);
1103 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1104 wake_up(&cdev
->private->wait_q
);
1107 ccw_device_set_timeout(cdev
, HZ
/10);
1112 * No operation action. This is used e.g. to ignore a timeout event in
1116 ccw_device_nop(struct ccw_device
*cdev
, enum dev_event dev_event
)
1121 * Bug operation action.
1124 ccw_device_bug(struct ccw_device
*cdev
, enum dev_event dev_event
)
1126 printk(KERN_EMERG
"dev_jumptable[%i][%i] == NULL\n",
1127 cdev
->private->state
, dev_event
);
1132 * device statemachine
1134 fsm_func_t
*dev_jumptable
[NR_DEV_STATES
][NR_DEV_EVENTS
] = {
1135 [DEV_STATE_NOT_OPER
] = {
1136 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1137 [DEV_EVENT_INTERRUPT
] = ccw_device_bug
,
1138 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1139 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1141 [DEV_STATE_SENSE_PGID
] = {
1142 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1143 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_pgid_irq
,
1144 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1145 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1147 [DEV_STATE_SENSE_ID
] = {
1148 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1149 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1150 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1151 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1153 [DEV_STATE_OFFLINE
] = {
1154 [DEV_EVENT_NOTOPER
] = ccw_device_offline_notoper
,
1155 [DEV_EVENT_INTERRUPT
] = ccw_device_offline_irq
,
1156 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1157 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1159 [DEV_STATE_VERIFY
] = {
1160 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1161 [DEV_EVENT_INTERRUPT
] = ccw_device_verify_irq
,
1162 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1163 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1165 [DEV_STATE_ONLINE
] = {
1166 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1167 [DEV_EVENT_INTERRUPT
] = ccw_device_irq
,
1168 [DEV_EVENT_TIMEOUT
] = ccw_device_online_timeout
,
1169 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1171 [DEV_STATE_W4SENSE
] = {
1172 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1173 [DEV_EVENT_INTERRUPT
] = ccw_device_w4sense
,
1174 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1175 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1177 [DEV_STATE_DISBAND_PGID
] = {
1178 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1179 [DEV_EVENT_INTERRUPT
] = ccw_device_disband_irq
,
1180 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1181 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1183 [DEV_STATE_BOXED
] = {
1184 [DEV_EVENT_NOTOPER
] = ccw_device_offline_notoper
,
1185 [DEV_EVENT_INTERRUPT
] = ccw_device_stlck_done
,
1186 [DEV_EVENT_TIMEOUT
] = ccw_device_stlck_done
,
1187 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1189 /* states to wait for i/o completion before doing something */
1190 [DEV_STATE_CLEAR_VERIFY
] = {
1191 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1192 [DEV_EVENT_INTERRUPT
] = ccw_device_clear_verify
,
1193 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1194 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1196 [DEV_STATE_TIMEOUT_KILL
] = {
1197 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1198 [DEV_EVENT_INTERRUPT
] = ccw_device_killing_irq
,
1199 [DEV_EVENT_TIMEOUT
] = ccw_device_killing_timeout
,
1200 [DEV_EVENT_VERIFY
] = ccw_device_nop
, //FIXME
1202 [DEV_STATE_WAIT4IO
] = {
1203 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1204 [DEV_EVENT_INTERRUPT
] = ccw_device_wait4io_irq
,
1205 [DEV_EVENT_TIMEOUT
] = ccw_device_wait4io_timeout
,
1206 [DEV_EVENT_VERIFY
] = ccw_device_wait4io_verify
,
1208 [DEV_STATE_QUIESCE
] = {
1209 [DEV_EVENT_NOTOPER
] = ccw_device_quiesce_done
,
1210 [DEV_EVENT_INTERRUPT
] = ccw_device_quiesce_done
,
1211 [DEV_EVENT_TIMEOUT
] = ccw_device_quiesce_timeout
,
1212 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1214 /* special states for devices gone not operational */
1215 [DEV_STATE_DISCONNECTED
] = {
1216 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1217 [DEV_EVENT_INTERRUPT
] = ccw_device_start_id
,
1218 [DEV_EVENT_TIMEOUT
] = ccw_device_bug
,
1219 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1221 [DEV_STATE_DISCONNECTED_SENSE_ID
] = {
1222 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1223 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1224 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1225 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1227 [DEV_STATE_CMFCHANGE
] = {
1228 [DEV_EVENT_NOTOPER
] = ccw_device_change_cmfstate
,
1229 [DEV_EVENT_INTERRUPT
] = ccw_device_change_cmfstate
,
1230 [DEV_EVENT_TIMEOUT
] = ccw_device_change_cmfstate
,
1231 [DEV_EVENT_VERIFY
] = ccw_device_change_cmfstate
,
1236 * io_subchannel_irq is called for "real" interrupts or for status
1237 * pending conditions on msch.
1240 io_subchannel_irq (struct device
*pdev
)
1242 struct ccw_device
*cdev
;
1244 cdev
= to_subchannel(pdev
)->dev
.driver_data
;
1246 CIO_TRACE_EVENT (3, "IRQ");
1247 CIO_TRACE_EVENT (3, pdev
->bus_id
);
1249 dev_fsm_event(cdev
, DEV_EVENT_INTERRUPT
);
1252 EXPORT_SYMBOL_GPL(ccw_device_set_timeout
);