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"
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
;
63 device_set_waiting(struct subchannel
*sch
)
65 struct ccw_device
*cdev
;
67 if (!sch
->dev
.driver_data
)
69 cdev
= sch
->dev
.driver_data
;
70 ccw_device_set_timeout(cdev
, 10*HZ
);
71 cdev
->private->state
= DEV_STATE_WAIT4IO
;
75 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
78 ccw_device_timeout(unsigned long data
)
80 struct ccw_device
*cdev
;
82 cdev
= (struct ccw_device
*) data
;
83 spin_lock_irq(cdev
->ccwlock
);
84 dev_fsm_event(cdev
, DEV_EVENT_TIMEOUT
);
85 spin_unlock_irq(cdev
->ccwlock
);
92 ccw_device_set_timeout(struct ccw_device
*cdev
, int expires
)
95 del_timer(&cdev
->private->timer
);
98 if (timer_pending(&cdev
->private->timer
)) {
99 if (mod_timer(&cdev
->private->timer
, jiffies
+ expires
))
102 cdev
->private->timer
.function
= ccw_device_timeout
;
103 cdev
->private->timer
.data
= (unsigned long) cdev
;
104 cdev
->private->timer
.expires
= jiffies
+ expires
;
105 add_timer(&cdev
->private->timer
);
108 /* Kill any pending timers after machine check. */
110 device_kill_pending_timer(struct subchannel
*sch
)
112 struct ccw_device
*cdev
;
114 if (!sch
->dev
.driver_data
)
116 cdev
= sch
->dev
.driver_data
;
117 ccw_device_set_timeout(cdev
, 0);
121 * Cancel running i/o. This is called repeatedly since halt/clear are
122 * asynchronous operations. We do one try with cio_cancel, two tries
123 * with cio_halt, 255 tries with cio_clear. If everythings fails panic.
124 * Returns 0 if device now idle, -ENODEV for device not operational and
125 * -EBUSY if an interrupt is expected (either from halt/clear or from a
129 ccw_device_cancel_halt_clear(struct ccw_device
*cdev
)
131 struct subchannel
*sch
;
134 sch
= to_subchannel(cdev
->dev
.parent
);
135 ret
= stsch(sch
->irq
, &sch
->schib
);
136 if (ret
|| !sch
->schib
.pmcw
.dnv
)
138 if (!sch
->schib
.pmcw
.ena
|| sch
->schib
.scsw
.actl
== 0)
139 /* Not operational or no activity -> done. */
141 /* Stage 1: cancel io. */
142 if (!(sch
->schib
.scsw
.actl
& SCSW_ACTL_HALT_PEND
) &&
143 !(sch
->schib
.scsw
.actl
& SCSW_ACTL_CLEAR_PEND
)) {
144 ret
= cio_cancel(sch
);
147 /* cancel io unsuccessful. From now on it is asynchronous. */
148 cdev
->private->iretry
= 3; /* 3 halt retries. */
150 if (!(sch
->schib
.scsw
.actl
& SCSW_ACTL_CLEAR_PEND
)) {
151 /* Stage 2: halt io. */
152 if (cdev
->private->iretry
) {
153 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->devno
!= sch
->schib
.pmcw
.dev
) {
186 PREPARE_WORK(&cdev
->private->kick_work
,
187 ccw_device_do_unreg_rereg
, (void *)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
->irq
, &sch
->schib
);
234 sch
->lpm
= sch
->schib
.pmcw
.pim
&
235 sch
->schib
.pmcw
.pam
&
236 sch
->schib
.pmcw
.pom
&
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 %04x\n",
257 cdev
->private->devno
, sch
->irq
);
259 case DEV_STATE_OFFLINE
:
260 if (cdev
->private->state
== DEV_STATE_DISCONNECTED_SENSE_ID
) {
261 same_dev
= ccw_device_handle_oper(cdev
);
264 /* fill out sense information */
265 cdev
->id
= (struct ccw_device_id
) {
266 .cu_type
= cdev
->private->senseid
.cu_type
,
267 .cu_model
= cdev
->private->senseid
.cu_model
,
268 .dev_type
= cdev
->private->senseid
.dev_type
,
269 .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 %04x reports: "
282 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
283 "%04X/%02X\n", cdev
->private->devno
,
284 cdev
->id
.cu_type
, cdev
->id
.cu_model
,
285 cdev
->id
.dev_type
, cdev
->id
.dev_model
);
287 case DEV_STATE_BOXED
:
288 CIO_DEBUG(KERN_WARNING
, 2,
289 "SenseID : boxed device %04x on subchannel %04x\n",
290 cdev
->private->devno
, sch
->irq
);
293 cdev
->private->state
= state
;
294 io_subchannel_recog_done(cdev
);
295 if (state
!= DEV_STATE_NOT_OPER
)
296 wake_up(&cdev
->private->wait_q
);
300 * Function called from device_id.c after sense id has completed.
303 ccw_device_sense_id_done(struct ccw_device
*cdev
, int err
)
307 ccw_device_recog_done(cdev
, DEV_STATE_OFFLINE
);
309 case -ETIME
: /* Sense id stopped by timeout. */
310 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
313 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
319 ccw_device_oper_notify(void *data
)
321 struct ccw_device
*cdev
;
322 struct subchannel
*sch
;
325 cdev
= (struct ccw_device
*)data
;
326 sch
= to_subchannel(cdev
->dev
.parent
);
327 ret
= (sch
->driver
&& sch
->driver
->notify
) ?
328 sch
->driver
->notify(&sch
->dev
, CIO_OPER
) : 0;
330 /* Driver doesn't want device back. */
331 ccw_device_do_unreg_rereg((void *)cdev
);
333 wake_up(&cdev
->private->wait_q
);
337 * Finished with online/offline processing.
340 ccw_device_done(struct ccw_device
*cdev
, int state
)
342 struct subchannel
*sch
;
344 sch
= to_subchannel(cdev
->dev
.parent
);
346 if (state
!= DEV_STATE_ONLINE
)
347 cio_disable_subchannel(sch
);
349 /* Reset device status. */
350 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
352 cdev
->private->state
= state
;
355 if (state
== DEV_STATE_BOXED
)
356 CIO_DEBUG(KERN_WARNING
, 2,
357 "Boxed device %04x on subchannel %04x\n",
358 cdev
->private->devno
, sch
->irq
);
360 if (cdev
->private->flags
.donotify
) {
361 cdev
->private->flags
.donotify
= 0;
362 PREPARE_WORK(&cdev
->private->kick_work
, ccw_device_oper_notify
,
364 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
366 wake_up(&cdev
->private->wait_q
);
368 if (css_init_done
&& state
!= DEV_STATE_ONLINE
)
369 put_device (&cdev
->dev
);
373 * Function called from device_pgid.c after sense path ground has completed.
376 ccw_device_sense_pgid_done(struct ccw_device
*cdev
, int err
)
378 struct subchannel
*sch
;
380 sch
= to_subchannel(cdev
->dev
.parent
);
383 /* Start Path Group verification. */
384 sch
->vpm
= 0; /* Start with no path groups set. */
385 cdev
->private->state
= DEV_STATE_VERIFY
;
386 ccw_device_verify_start(cdev
);
388 case -ETIME
: /* Sense path group id stopped by timeout. */
389 case -EUSERS
: /* device is reserved for someone else. */
390 ccw_device_done(cdev
, DEV_STATE_BOXED
);
392 case -EOPNOTSUPP
: /* path grouping not supported, just set online. */
393 cdev
->private->options
.pgroup
= 0;
394 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
397 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
403 * Start device recognition.
406 ccw_device_recognition(struct ccw_device
*cdev
)
408 struct subchannel
*sch
;
411 if ((cdev
->private->state
!= DEV_STATE_NOT_OPER
) &&
412 (cdev
->private->state
!= DEV_STATE_BOXED
))
414 sch
= to_subchannel(cdev
->dev
.parent
);
415 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
417 /* Couldn't enable the subchannel for i/o. Sick device. */
420 /* After 60s the device recognition is considered to have failed. */
421 ccw_device_set_timeout(cdev
, 60*HZ
);
424 * We used to start here with a sense pgid to find out whether a device
425 * is locked by someone else. Unfortunately, the sense pgid command
426 * code has other meanings on devices predating the path grouping
427 * algorithm, so we start with sense id and box the device after an
428 * timeout (or if sense pgid during path verification detects the device
429 * is locked, as may happen on newer devices).
431 cdev
->private->flags
.recog_done
= 0;
432 cdev
->private->state
= DEV_STATE_SENSE_ID
;
433 ccw_device_sense_id_start(cdev
);
438 * Handle timeout in device recognition.
441 ccw_device_recog_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
445 ret
= ccw_device_cancel_halt_clear(cdev
);
448 ccw_device_recog_done(cdev
, DEV_STATE_BOXED
);
451 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
454 ccw_device_set_timeout(cdev
, 3*HZ
);
460 ccw_device_nopath_notify(void *data
)
462 struct ccw_device
*cdev
;
463 struct subchannel
*sch
;
466 cdev
= (struct ccw_device
*)data
;
467 sch
= to_subchannel(cdev
->dev
.parent
);
471 ret
= (sch
->driver
&& sch
->driver
->notify
) ?
472 sch
->driver
->notify(&sch
->dev
, CIO_NO_PATH
) : 0;
474 if (get_device(&sch
->dev
)) {
475 /* Driver doesn't want to keep device. */
476 cio_disable_subchannel(sch
);
477 if (get_device(&cdev
->dev
)) {
478 PREPARE_WORK(&cdev
->private->kick_work
,
479 ccw_device_call_sch_unregister
,
481 queue_work(ccw_device_work
,
482 &cdev
->private->kick_work
);
484 put_device(&sch
->dev
);
487 cio_disable_subchannel(sch
);
488 ccw_device_set_timeout(cdev
, 0);
489 cdev
->private->flags
.fake_irb
= 0;
490 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
491 wake_up(&cdev
->private->wait_q
);
496 ccw_device_verify_done(struct ccw_device
*cdev
, int err
)
498 cdev
->private->flags
.doverify
= 0;
500 case -EOPNOTSUPP
: /* path grouping not supported, just set online. */
501 cdev
->private->options
.pgroup
= 0;
503 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
504 /* Deliver fake irb to device driver, if needed. */
505 if (cdev
->private->flags
.fake_irb
) {
506 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
507 cdev
->private->irb
.scsw
= (struct scsw
) {
509 .fctl
= SCSW_FCTL_START_FUNC
,
510 .actl
= SCSW_ACTL_START_PEND
,
511 .stctl
= SCSW_STCTL_STATUS_PEND
,
513 cdev
->private->flags
.fake_irb
= 0;
515 cdev
->handler(cdev
, cdev
->private->intparm
,
516 &cdev
->private->irb
);
517 memset(&cdev
->private->irb
, 0, sizeof(struct irb
));
521 ccw_device_done(cdev
, DEV_STATE_BOXED
);
524 PREPARE_WORK(&cdev
->private->kick_work
,
525 ccw_device_nopath_notify
, (void *)cdev
);
526 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
527 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
536 ccw_device_online(struct ccw_device
*cdev
)
538 struct subchannel
*sch
;
541 if ((cdev
->private->state
!= DEV_STATE_OFFLINE
) &&
542 (cdev
->private->state
!= DEV_STATE_BOXED
))
544 sch
= to_subchannel(cdev
->dev
.parent
);
545 if (css_init_done
&& !get_device(&cdev
->dev
))
547 ret
= cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
);
549 /* Couldn't enable the subchannel for i/o. Sick device. */
551 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
554 /* Do we want to do path grouping? */
555 if (!cdev
->private->options
.pgroup
) {
556 /* No, set state online immediately. */
557 ccw_device_done(cdev
, DEV_STATE_ONLINE
);
560 /* Do a SensePGID first. */
561 cdev
->private->state
= DEV_STATE_SENSE_PGID
;
562 ccw_device_sense_pgid_start(cdev
);
567 ccw_device_disband_done(struct ccw_device
*cdev
, int err
)
571 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
574 ccw_device_done(cdev
, DEV_STATE_BOXED
);
577 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
586 ccw_device_offline(struct ccw_device
*cdev
)
588 struct subchannel
*sch
;
590 sch
= to_subchannel(cdev
->dev
.parent
);
591 if (stsch(sch
->irq
, &sch
->schib
) || !sch
->schib
.pmcw
.dnv
)
593 if (cdev
->private->state
!= DEV_STATE_ONLINE
) {
594 if (sch
->schib
.scsw
.actl
!= 0)
598 if (sch
->schib
.scsw
.actl
!= 0)
600 /* Are we doing path grouping? */
601 if (!cdev
->private->options
.pgroup
) {
602 /* No, set state offline immediately. */
603 ccw_device_done(cdev
, DEV_STATE_OFFLINE
);
606 /* Start Set Path Group commands. */
607 cdev
->private->state
= DEV_STATE_DISBAND_PGID
;
608 ccw_device_disband_start(cdev
);
613 * Handle timeout in device online/offline process.
616 ccw_device_onoff_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
620 ret
= ccw_device_cancel_halt_clear(cdev
);
623 ccw_device_done(cdev
, DEV_STATE_BOXED
);
626 ccw_device_done(cdev
, DEV_STATE_NOT_OPER
);
629 ccw_device_set_timeout(cdev
, 3*HZ
);
634 * Handle not oper event in device recognition.
637 ccw_device_recog_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
639 ccw_device_recog_done(cdev
, DEV_STATE_NOT_OPER
);
643 * Handle not operational event while offline.
646 ccw_device_offline_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
648 struct subchannel
*sch
;
650 cdev
->private->state
= DEV_STATE_NOT_OPER
;
651 sch
= to_subchannel(cdev
->dev
.parent
);
652 if (get_device(&cdev
->dev
)) {
653 PREPARE_WORK(&cdev
->private->kick_work
,
654 ccw_device_call_sch_unregister
, (void *)cdev
);
655 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
657 wake_up(&cdev
->private->wait_q
);
661 * Handle not operational event while online.
664 ccw_device_online_notoper(struct ccw_device
*cdev
, enum dev_event dev_event
)
666 struct subchannel
*sch
;
668 sch
= to_subchannel(cdev
->dev
.parent
);
669 if (sch
->driver
->notify
&&
670 sch
->driver
->notify(&sch
->dev
, sch
->lpm
? CIO_GONE
: CIO_NO_PATH
)) {
671 ccw_device_set_timeout(cdev
, 0);
672 cdev
->private->flags
.fake_irb
= 0;
673 cdev
->private->state
= DEV_STATE_DISCONNECTED
;
674 wake_up(&cdev
->private->wait_q
);
677 cdev
->private->state
= DEV_STATE_NOT_OPER
;
678 cio_disable_subchannel(sch
);
679 if (sch
->schib
.scsw
.actl
!= 0) {
680 // FIXME: not-oper indication to device driver ?
681 ccw_device_call_handler(cdev
);
683 if (get_device(&cdev
->dev
)) {
684 PREPARE_WORK(&cdev
->private->kick_work
,
685 ccw_device_call_sch_unregister
, (void *)cdev
);
686 queue_work(ccw_device_work
, &cdev
->private->kick_work
);
688 wake_up(&cdev
->private->wait_q
);
692 * Handle path verification event.
695 ccw_device_online_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
697 struct subchannel
*sch
;
699 if (!cdev
->private->options
.pgroup
)
701 if (cdev
->private->state
== DEV_STATE_W4SENSE
) {
702 cdev
->private->flags
.doverify
= 1;
705 sch
= to_subchannel(cdev
->dev
.parent
);
707 * Since we might not just be coming from an interrupt from the
708 * subchannel we have to update the schib.
710 stsch(sch
->irq
, &sch
->schib
);
712 if (sch
->schib
.scsw
.actl
!= 0 ||
713 (cdev
->private->irb
.scsw
.stctl
& SCSW_STCTL_STATUS_PEND
)) {
715 * No final status yet or final status not yet delivered
716 * to the device driver. Can't do path verfication now,
717 * delay until final status was delivered.
719 cdev
->private->flags
.doverify
= 1;
722 /* Device is idle, we can do the path verification. */
723 cdev
->private->state
= DEV_STATE_VERIFY
;
724 ccw_device_verify_start(cdev
);
728 * Got an interrupt for a normal io (state online).
731 ccw_device_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
735 irb
= (struct irb
*) __LC_IRB
;
736 /* Check for unsolicited interrupt. */
737 if ((irb
->scsw
.stctl
==
738 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
))
739 && (!irb
->scsw
.cc
)) {
740 if ((irb
->scsw
.dstat
& DEV_STAT_UNIT_CHECK
) &&
741 !irb
->esw
.esw0
.erw
.cons
) {
742 /* Unit check but no sense data. Need basic sense. */
743 if (ccw_device_do_sense(cdev
, irb
) != 0)
744 goto call_handler_unsol
;
745 memcpy(irb
, &cdev
->private->irb
, sizeof(struct irb
));
746 cdev
->private->state
= DEV_STATE_W4SENSE
;
747 cdev
->private->intparm
= 0;
752 cdev
->handler (cdev
, 0, irb
);
755 /* Accumulate status and find out if a basic sense is needed. */
756 ccw_device_accumulate_irb(cdev
, irb
);
757 if (cdev
->private->flags
.dosense
) {
758 if (ccw_device_do_sense(cdev
, irb
) == 0) {
759 cdev
->private->state
= DEV_STATE_W4SENSE
;
763 /* Call the handler. */
764 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
765 /* Start delayed path verification. */
766 ccw_device_online_verify(cdev
, 0);
770 * Got an timeout in online state.
773 ccw_device_online_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
777 ccw_device_set_timeout(cdev
, 0);
778 ret
= ccw_device_cancel_halt_clear(cdev
);
780 ccw_device_set_timeout(cdev
, 3*HZ
);
781 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
784 if (ret
== -ENODEV
) {
785 struct subchannel
*sch
;
787 sch
= to_subchannel(cdev
->dev
.parent
);
789 PREPARE_WORK(&cdev
->private->kick_work
,
790 ccw_device_nopath_notify
, (void *)cdev
);
791 queue_work(ccw_device_notify_work
,
792 &cdev
->private->kick_work
);
794 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
795 } else if (cdev
->handler
)
796 cdev
->handler(cdev
, cdev
->private->intparm
,
797 ERR_PTR(-ETIMEDOUT
));
801 * Got an interrupt for a basic sense.
804 ccw_device_w4sense(struct ccw_device
*cdev
, enum dev_event dev_event
)
808 irb
= (struct irb
*) __LC_IRB
;
809 /* Check for unsolicited interrupt. */
810 if (irb
->scsw
.stctl
==
811 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) {
812 if (irb
->scsw
.cc
== 1)
813 /* Basic sense hasn't started. Try again. */
814 ccw_device_do_sense(cdev
, irb
);
816 printk("Huh? %s(%s): unsolicited interrupt...\n",
817 __FUNCTION__
, cdev
->dev
.bus_id
);
819 cdev
->handler (cdev
, 0, irb
);
823 /* Add basic sense info to irb. */
824 ccw_device_accumulate_basic_sense(cdev
, irb
);
825 if (cdev
->private->flags
.dosense
) {
826 /* Another basic sense is needed. */
827 ccw_device_do_sense(cdev
, irb
);
830 cdev
->private->state
= DEV_STATE_ONLINE
;
831 /* Call the handler. */
832 if (ccw_device_call_handler(cdev
) && cdev
->private->flags
.doverify
)
833 /* Start delayed path verification. */
834 ccw_device_online_verify(cdev
, 0);
838 ccw_device_clear_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
842 irb
= (struct irb
*) __LC_IRB
;
843 /* Accumulate status. We don't do basic sense. */
844 ccw_device_accumulate_irb(cdev
, irb
);
845 /* Try to start delayed device verification. */
846 ccw_device_online_verify(cdev
, 0);
847 /* Note: Don't call handler for cio initiated clear! */
851 ccw_device_killing_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
853 struct subchannel
*sch
;
855 sch
= to_subchannel(cdev
->dev
.parent
);
856 ccw_device_set_timeout(cdev
, 0);
857 /* OK, i/o is dead now. Call interrupt handler. */
858 cdev
->private->state
= DEV_STATE_ONLINE
;
860 cdev
->handler(cdev
, cdev
->private->intparm
,
861 ERR_PTR(-ETIMEDOUT
));
863 PREPARE_WORK(&cdev
->private->kick_work
,
864 ccw_device_nopath_notify
, (void *)cdev
);
865 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
866 } else if (cdev
->private->flags
.doverify
)
867 /* Start delayed path verification. */
868 ccw_device_online_verify(cdev
, 0);
872 ccw_device_killing_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
876 ret
= ccw_device_cancel_halt_clear(cdev
);
878 ccw_device_set_timeout(cdev
, 3*HZ
);
881 if (ret
== -ENODEV
) {
882 struct subchannel
*sch
;
884 sch
= to_subchannel(cdev
->dev
.parent
);
886 PREPARE_WORK(&cdev
->private->kick_work
,
887 ccw_device_nopath_notify
, (void *)cdev
);
888 queue_work(ccw_device_notify_work
,
889 &cdev
->private->kick_work
);
891 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
894 //FIXME: Can we get here?
895 cdev
->private->state
= DEV_STATE_ONLINE
;
897 cdev
->handler(cdev
, cdev
->private->intparm
,
898 ERR_PTR(-ETIMEDOUT
));
902 ccw_device_wait4io_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
905 struct subchannel
*sch
;
907 irb
= (struct irb
*) __LC_IRB
;
909 * Accumulate status and find out if a basic sense is needed.
910 * This is fine since we have already adapted the lpm.
912 ccw_device_accumulate_irb(cdev
, irb
);
913 if (cdev
->private->flags
.dosense
) {
914 if (ccw_device_do_sense(cdev
, irb
) == 0) {
915 cdev
->private->state
= DEV_STATE_W4SENSE
;
920 /* Iff device is idle, reset timeout. */
921 sch
= to_subchannel(cdev
->dev
.parent
);
922 if (!stsch(sch
->irq
, &sch
->schib
))
923 if (sch
->schib
.scsw
.actl
== 0)
924 ccw_device_set_timeout(cdev
, 0);
925 /* Call the handler. */
926 ccw_device_call_handler(cdev
);
928 PREPARE_WORK(&cdev
->private->kick_work
,
929 ccw_device_nopath_notify
, (void *)cdev
);
930 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
931 } else if (cdev
->private->flags
.doverify
)
932 ccw_device_online_verify(cdev
, 0);
936 ccw_device_wait4io_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
939 struct subchannel
*sch
;
941 sch
= to_subchannel(cdev
->dev
.parent
);
942 ccw_device_set_timeout(cdev
, 0);
943 ret
= ccw_device_cancel_halt_clear(cdev
);
945 ccw_device_set_timeout(cdev
, 3*HZ
);
946 cdev
->private->state
= DEV_STATE_TIMEOUT_KILL
;
949 if (ret
== -ENODEV
) {
951 PREPARE_WORK(&cdev
->private->kick_work
,
952 ccw_device_nopath_notify
, (void *)cdev
);
953 queue_work(ccw_device_notify_work
,
954 &cdev
->private->kick_work
);
956 dev_fsm_event(cdev
, DEV_EVENT_NOTOPER
);
960 cdev
->handler(cdev
, cdev
->private->intparm
,
961 ERR_PTR(-ETIMEDOUT
));
963 PREPARE_WORK(&cdev
->private->kick_work
,
964 ccw_device_nopath_notify
, (void *)cdev
);
965 queue_work(ccw_device_notify_work
, &cdev
->private->kick_work
);
966 } else if (cdev
->private->flags
.doverify
)
967 /* Start delayed path verification. */
968 ccw_device_online_verify(cdev
, 0);
972 ccw_device_wait4io_verify(struct ccw_device
*cdev
, enum dev_event dev_event
)
974 /* When the I/O has terminated, we have to start verification. */
975 if (cdev
->private->options
.pgroup
)
976 cdev
->private->flags
.doverify
= 1;
980 ccw_device_stlck_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
985 case DEV_EVENT_INTERRUPT
:
986 irb
= (struct irb
*) __LC_IRB
;
987 /* Check for unsolicited interrupt. */
988 if ((irb
->scsw
.stctl
==
989 (SCSW_STCTL_STATUS_PEND
| SCSW_STCTL_ALERT_STATUS
)) &&
991 /* FIXME: we should restart stlck here, but this
992 * is extremely unlikely ... */
995 ccw_device_accumulate_irb(cdev
, irb
);
996 /* We don't care about basic sense etc. */
998 default: /* timeout */
1002 wake_up(&cdev
->private->wait_q
);
1006 ccw_device_start_id(struct ccw_device
*cdev
, enum dev_event dev_event
)
1008 struct subchannel
*sch
;
1010 sch
= to_subchannel(cdev
->dev
.parent
);
1011 if (cio_enable_subchannel(sch
, sch
->schib
.pmcw
.isc
) != 0)
1012 /* Couldn't enable the subchannel for i/o. Sick device. */
1015 /* After 60s the device recognition is considered to have failed. */
1016 ccw_device_set_timeout(cdev
, 60*HZ
);
1018 cdev
->private->state
= DEV_STATE_DISCONNECTED_SENSE_ID
;
1019 ccw_device_sense_id_start(cdev
);
1023 device_trigger_reprobe(struct subchannel
*sch
)
1025 struct ccw_device
*cdev
;
1027 if (!sch
->dev
.driver_data
)
1029 cdev
= sch
->dev
.driver_data
;
1030 if (cdev
->private->state
!= DEV_STATE_DISCONNECTED
)
1033 /* Update some values. */
1034 if (stsch(sch
->irq
, &sch
->schib
))
1038 * The pim, pam, pom values may not be accurate, but they are the best
1039 * we have before performing device selection :/
1041 sch
->lpm
= sch
->schib
.pmcw
.pim
&
1042 sch
->schib
.pmcw
.pam
&
1043 sch
->schib
.pmcw
.pom
&
1045 /* Re-set some bits in the pmcw that were lost. */
1046 sch
->schib
.pmcw
.isc
= 3;
1047 sch
->schib
.pmcw
.csense
= 1;
1048 sch
->schib
.pmcw
.ena
= 0;
1049 if ((sch
->lpm
& (sch
->lpm
- 1)) != 0)
1050 sch
->schib
.pmcw
.mp
= 1;
1051 sch
->schib
.pmcw
.intparm
= (__u32
)(unsigned long)sch
;
1052 /* We should also udate ssd info, but this has to wait. */
1053 ccw_device_start_id(cdev
, 0);
1057 ccw_device_offline_irq(struct ccw_device
*cdev
, enum dev_event dev_event
)
1059 struct subchannel
*sch
;
1061 sch
= to_subchannel(cdev
->dev
.parent
);
1063 * An interrupt in state offline means a previous disable was not
1064 * successful. Try again.
1066 cio_disable_subchannel(sch
);
1070 ccw_device_change_cmfstate(struct ccw_device
*cdev
, enum dev_event dev_event
)
1072 retry_set_schib(cdev
);
1073 cdev
->private->state
= DEV_STATE_ONLINE
;
1074 dev_fsm_event(cdev
, dev_event
);
1079 ccw_device_quiesce_done(struct ccw_device
*cdev
, enum dev_event dev_event
)
1081 ccw_device_set_timeout(cdev
, 0);
1082 if (dev_event
== DEV_EVENT_NOTOPER
)
1083 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1085 cdev
->private->state
= DEV_STATE_OFFLINE
;
1086 wake_up(&cdev
->private->wait_q
);
1090 ccw_device_quiesce_timeout(struct ccw_device
*cdev
, enum dev_event dev_event
)
1094 ret
= ccw_device_cancel_halt_clear(cdev
);
1097 cdev
->private->state
= DEV_STATE_OFFLINE
;
1098 wake_up(&cdev
->private->wait_q
);
1101 cdev
->private->state
= DEV_STATE_NOT_OPER
;
1102 wake_up(&cdev
->private->wait_q
);
1105 ccw_device_set_timeout(cdev
, HZ
/10);
1110 * No operation action. This is used e.g. to ignore a timeout event in
1114 ccw_device_nop(struct ccw_device
*cdev
, enum dev_event dev_event
)
1119 * Bug operation action.
1122 ccw_device_bug(struct ccw_device
*cdev
, enum dev_event dev_event
)
1124 printk(KERN_EMERG
"dev_jumptable[%i][%i] == NULL\n",
1125 cdev
->private->state
, dev_event
);
1130 * device statemachine
1132 fsm_func_t
*dev_jumptable
[NR_DEV_STATES
][NR_DEV_EVENTS
] = {
1133 [DEV_STATE_NOT_OPER
] = {
1134 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1135 [DEV_EVENT_INTERRUPT
] = ccw_device_bug
,
1136 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1137 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1139 [DEV_STATE_SENSE_PGID
] = {
1140 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1141 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_pgid_irq
,
1142 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1143 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1145 [DEV_STATE_SENSE_ID
] = {
1146 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1147 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1148 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1149 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1151 [DEV_STATE_OFFLINE
] = {
1152 [DEV_EVENT_NOTOPER
] = ccw_device_offline_notoper
,
1153 [DEV_EVENT_INTERRUPT
] = ccw_device_offline_irq
,
1154 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1155 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1157 [DEV_STATE_VERIFY
] = {
1158 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1159 [DEV_EVENT_INTERRUPT
] = ccw_device_verify_irq
,
1160 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1161 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1163 [DEV_STATE_ONLINE
] = {
1164 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1165 [DEV_EVENT_INTERRUPT
] = ccw_device_irq
,
1166 [DEV_EVENT_TIMEOUT
] = ccw_device_online_timeout
,
1167 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1169 [DEV_STATE_W4SENSE
] = {
1170 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1171 [DEV_EVENT_INTERRUPT
] = ccw_device_w4sense
,
1172 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1173 [DEV_EVENT_VERIFY
] = ccw_device_online_verify
,
1175 [DEV_STATE_DISBAND_PGID
] = {
1176 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1177 [DEV_EVENT_INTERRUPT
] = ccw_device_disband_irq
,
1178 [DEV_EVENT_TIMEOUT
] = ccw_device_onoff_timeout
,
1179 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1181 [DEV_STATE_BOXED
] = {
1182 [DEV_EVENT_NOTOPER
] = ccw_device_offline_notoper
,
1183 [DEV_EVENT_INTERRUPT
] = ccw_device_stlck_done
,
1184 [DEV_EVENT_TIMEOUT
] = ccw_device_stlck_done
,
1185 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1187 /* states to wait for i/o completion before doing something */
1188 [DEV_STATE_CLEAR_VERIFY
] = {
1189 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1190 [DEV_EVENT_INTERRUPT
] = ccw_device_clear_verify
,
1191 [DEV_EVENT_TIMEOUT
] = ccw_device_nop
,
1192 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1194 [DEV_STATE_TIMEOUT_KILL
] = {
1195 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1196 [DEV_EVENT_INTERRUPT
] = ccw_device_killing_irq
,
1197 [DEV_EVENT_TIMEOUT
] = ccw_device_killing_timeout
,
1198 [DEV_EVENT_VERIFY
] = ccw_device_nop
, //FIXME
1200 [DEV_STATE_WAIT4IO
] = {
1201 [DEV_EVENT_NOTOPER
] = ccw_device_online_notoper
,
1202 [DEV_EVENT_INTERRUPT
] = ccw_device_wait4io_irq
,
1203 [DEV_EVENT_TIMEOUT
] = ccw_device_wait4io_timeout
,
1204 [DEV_EVENT_VERIFY
] = ccw_device_wait4io_verify
,
1206 [DEV_STATE_QUIESCE
] = {
1207 [DEV_EVENT_NOTOPER
] = ccw_device_quiesce_done
,
1208 [DEV_EVENT_INTERRUPT
] = ccw_device_quiesce_done
,
1209 [DEV_EVENT_TIMEOUT
] = ccw_device_quiesce_timeout
,
1210 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1212 /* special states for devices gone not operational */
1213 [DEV_STATE_DISCONNECTED
] = {
1214 [DEV_EVENT_NOTOPER
] = ccw_device_nop
,
1215 [DEV_EVENT_INTERRUPT
] = ccw_device_start_id
,
1216 [DEV_EVENT_TIMEOUT
] = ccw_device_bug
,
1217 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1219 [DEV_STATE_DISCONNECTED_SENSE_ID
] = {
1220 [DEV_EVENT_NOTOPER
] = ccw_device_recog_notoper
,
1221 [DEV_EVENT_INTERRUPT
] = ccw_device_sense_id_irq
,
1222 [DEV_EVENT_TIMEOUT
] = ccw_device_recog_timeout
,
1223 [DEV_EVENT_VERIFY
] = ccw_device_nop
,
1225 [DEV_STATE_CMFCHANGE
] = {
1226 [DEV_EVENT_NOTOPER
] = ccw_device_change_cmfstate
,
1227 [DEV_EVENT_INTERRUPT
] = ccw_device_change_cmfstate
,
1228 [DEV_EVENT_TIMEOUT
] = ccw_device_change_cmfstate
,
1229 [DEV_EVENT_VERIFY
] = ccw_device_change_cmfstate
,
1234 * io_subchannel_irq is called for "real" interrupts or for status
1235 * pending conditions on msch.
1238 io_subchannel_irq (struct device
*pdev
)
1240 struct ccw_device
*cdev
;
1242 cdev
= to_subchannel(pdev
)->dev
.driver_data
;
1244 CIO_TRACE_EVENT (3, "IRQ");
1245 CIO_TRACE_EVENT (3, pdev
->bus_id
);
1247 dev_fsm_event(cdev
, DEV_EVENT_INTERRUPT
);
1250 EXPORT_SYMBOL_GPL(ccw_device_set_timeout
);