[S390] monwriter kzalloc size.
[linux-block.git] / drivers / s390 / cio / device_fsm.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/s390/cio/device_fsm.c
3 * finite state machine for device handling
4 *
5 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
6 * IBM Corporation
4ce3b30c 7 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
1da177e4
LT
8 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 */
10
11#include <linux/module.h>
1da177e4 12#include <linux/init.h>
4e57b681
TS
13#include <linux/jiffies.h>
14#include <linux/string.h>
1da177e4
LT
15
16#include <asm/ccwdev.h>
4c24da79 17#include <asm/cio.h>
1da177e4
LT
18
19#include "cio.h"
20#include "cio_debug.h"
21#include "css.h"
22#include "device.h"
23#include "chsc.h"
24#include "ioasm.h"
1da177e4
LT
25
26int
27device_is_online(struct subchannel *sch)
28{
29 struct ccw_device *cdev;
30
31 if (!sch->dev.driver_data)
32 return 0;
33 cdev = sch->dev.driver_data;
34 return (cdev->private->state == DEV_STATE_ONLINE);
35}
36
37int
38device_is_disconnected(struct subchannel *sch)
39{
40 struct ccw_device *cdev;
41
42 if (!sch->dev.driver_data)
43 return 0;
44 cdev = sch->dev.driver_data;
45 return (cdev->private->state == DEV_STATE_DISCONNECTED ||
46 cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);
47}
48
49void
50device_set_disconnected(struct subchannel *sch)
51{
52 struct ccw_device *cdev;
53
54 if (!sch->dev.driver_data)
55 return;
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;
60}
61
62void
63device_set_waiting(struct subchannel *sch)
64{
65 struct ccw_device *cdev;
66
67 if (!sch->dev.driver_data)
68 return;
69 cdev = sch->dev.driver_data;
70 ccw_device_set_timeout(cdev, 10*HZ);
71 cdev->private->state = DEV_STATE_WAIT4IO;
72}
73
74/*
75 * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
76 */
77static void
78ccw_device_timeout(unsigned long data)
79{
80 struct ccw_device *cdev;
81
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);
86}
87
88/*
89 * Set timeout
90 */
91void
92ccw_device_set_timeout(struct ccw_device *cdev, int expires)
93{
94 if (expires == 0) {
95 del_timer(&cdev->private->timer);
96 return;
97 }
98 if (timer_pending(&cdev->private->timer)) {
99 if (mod_timer(&cdev->private->timer, jiffies + expires))
100 return;
101 }
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);
106}
107
108/* Kill any pending timers after machine check. */
109void
110device_kill_pending_timer(struct subchannel *sch)
111{
112 struct ccw_device *cdev;
113
114 if (!sch->dev.driver_data)
115 return;
116 cdev = sch->dev.driver_data;
117 ccw_device_set_timeout(cdev, 0);
118}
119
120/*
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
126 * status pending).
127 */
128int
129ccw_device_cancel_halt_clear(struct ccw_device *cdev)
130{
131 struct subchannel *sch;
132 int ret;
133
134 sch = to_subchannel(cdev->dev.parent);
a8237fc4 135 ret = stsch(sch->schid, &sch->schib);
1da177e4
LT
136 if (ret || !sch->schib.pmcw.dnv)
137 return -ENODEV;
138 if (!sch->schib.pmcw.ena || sch->schib.scsw.actl == 0)
139 /* Not operational or no activity -> done. */
140 return 0;
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);
145 if (ret != -EINVAL)
146 return ret;
147 /* cancel io unsuccessful. From now on it is asynchronous. */
148 cdev->private->iretry = 3; /* 3 halt retries. */
149 }
150 if (!(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {
151 /* Stage 2: halt io. */
152 if (cdev->private->iretry) {
153 cdev->private->iretry--;
154 ret = cio_halt(sch);
ba4ba8a6
PO
155 if (ret != -EBUSY)
156 return (ret == 0) ? -EBUSY : ret;
1da177e4
LT
157 }
158 /* halt io unsuccessful. */
159 cdev->private->iretry = 255; /* 255 clear retries. */
160 }
161 /* Stage 3: clear io. */
162 if (cdev->private->iretry) {
163 cdev->private->iretry--;
164 ret = cio_clear (sch);
165 return (ret == 0) ? -EBUSY : ret;
166 }
167 panic("Can't stop i/o on subchannel.\n");
168}
169
170static int
171ccw_device_handle_oper(struct ccw_device *cdev)
172{
173 struct subchannel *sch;
174
175 sch = to_subchannel(cdev->dev.parent);
176 cdev->private->flags.recog_done = 1;
177 /*
178 * Check if cu type and device type still match. If
179 * not, it is certainly another device and we have to
180 * de- and re-register. Also check here for non-matching devno.
181 */
182 if (cdev->id.cu_type != cdev->private->senseid.cu_type ||
183 cdev->id.cu_model != cdev->private->senseid.cu_model ||
184 cdev->id.dev_type != cdev->private->senseid.dev_type ||
185 cdev->id.dev_model != cdev->private->senseid.dev_model ||
186 cdev->private->devno != sch->schib.pmcw.dev) {
187 PREPARE_WORK(&cdev->private->kick_work,
188 ccw_device_do_unreg_rereg, (void *)cdev);
189 queue_work(ccw_device_work, &cdev->private->kick_work);
190 return 0;
191 }
192 cdev->private->flags.donotify = 1;
193 return 1;
194}
195
196/*
197 * The machine won't give us any notification by machine check if a chpid has
198 * been varied online on the SE so we have to find out by magic (i. e. driving
199 * the channel subsystem to device selection and updating our path masks).
200 */
201static inline void
202__recover_lost_chpids(struct subchannel *sch, int old_lpm)
203{
204 int mask, i;
205
206 for (i = 0; i<8; i++) {
207 mask = 0x80 >> i;
208 if (!(sch->lpm & mask))
209 continue;
210 if (old_lpm & mask)
211 continue;
212 chpid_is_actually_online(sch->schib.pmcw.chpid[i]);
213 }
214}
215
216/*
217 * Stop device recognition.
218 */
219static void
220ccw_device_recog_done(struct ccw_device *cdev, int state)
221{
222 struct subchannel *sch;
223 int notify, old_lpm, same_dev;
224
225 sch = to_subchannel(cdev->dev.parent);
226
227 ccw_device_set_timeout(cdev, 0);
228 cio_disable_subchannel(sch);
229 /*
230 * Now that we tried recognition, we have performed device selection
231 * through ssch() and the path information is up to date.
232 */
233 old_lpm = sch->lpm;
a8237fc4 234 stsch(sch->schid, &sch->schib);
28bdc6f6 235 sch->lpm = sch->schib.pmcw.pam & sch->opm;
4ffa9234
CH
236 /* Check since device may again have become not operational. */
237 if (!sch->schib.pmcw.dnv)
238 state = DEV_STATE_NOT_OPER;
1da177e4
LT
239 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
240 /* Force reprobe on all chpids. */
241 old_lpm = 0;
242 if (sch->lpm != old_lpm)
243 __recover_lost_chpids(sch, old_lpm);
244 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
245 if (state == DEV_STATE_NOT_OPER) {
246 cdev->private->flags.recog_done = 1;
247 cdev->private->state = DEV_STATE_DISCONNECTED;
248 return;
249 }
250 /* Boxed devices don't need extra treatment. */
251 }
252 notify = 0;
253 same_dev = 0; /* Keep the compiler quiet... */
254 switch (state) {
255 case DEV_STATE_NOT_OPER:
256 CIO_DEBUG(KERN_WARNING, 2,
fb6958a5
CH
257 "SenseID : unknown device %04x on subchannel "
258 "0.%x.%04x\n", cdev->private->devno,
259 sch->schid.ssid, sch->schid.sch_no);
1da177e4
LT
260 break;
261 case DEV_STATE_OFFLINE:
262 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {
263 same_dev = ccw_device_handle_oper(cdev);
264 notify = 1;
265 }
266 /* fill out sense information */
81388d2a 267 memset(&cdev->id, 0, sizeof(cdev->id));
292888c8
HC
268 cdev->id.cu_type = cdev->private->senseid.cu_type;
269 cdev->id.cu_model = cdev->private->senseid.cu_model;
270 cdev->id.dev_type = cdev->private->senseid.dev_type;
271 cdev->id.dev_model = cdev->private->senseid.dev_model;
1da177e4
LT
272 if (notify) {
273 cdev->private->state = DEV_STATE_OFFLINE;
274 if (same_dev) {
275 /* Get device online again. */
276 ccw_device_online(cdev);
277 wake_up(&cdev->private->wait_q);
278 }
279 return;
280 }
281 /* Issue device info message. */
fb6958a5 282 CIO_DEBUG(KERN_INFO, 2, "SenseID : device 0.%x.%04x reports: "
1da177e4 283 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
fb6958a5
CH
284 "%04X/%02X\n",
285 cdev->private->ssid, cdev->private->devno,
1da177e4
LT
286 cdev->id.cu_type, cdev->id.cu_model,
287 cdev->id.dev_type, cdev->id.dev_model);
288 break;
289 case DEV_STATE_BOXED:
290 CIO_DEBUG(KERN_WARNING, 2,
fb6958a5
CH
291 "SenseID : boxed device %04x on subchannel "
292 "0.%x.%04x\n", cdev->private->devno,
293 sch->schid.ssid, sch->schid.sch_no);
1da177e4
LT
294 break;
295 }
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);
300}
301
302/*
303 * Function called from device_id.c after sense id has completed.
304 */
305void
306ccw_device_sense_id_done(struct ccw_device *cdev, int err)
307{
308 switch (err) {
309 case 0:
310 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
311 break;
312 case -ETIME: /* Sense id stopped by timeout. */
313 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
314 break;
315 default:
316 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
317 break;
318 }
319}
320
321static void
322ccw_device_oper_notify(void *data)
323{
324 struct ccw_device *cdev;
325 struct subchannel *sch;
326 int ret;
327
328 cdev = (struct ccw_device *)data;
329 sch = to_subchannel(cdev->dev.parent);
330 ret = (sch->driver && sch->driver->notify) ?
331 sch->driver->notify(&sch->dev, CIO_OPER) : 0;
332 if (!ret)
333 /* Driver doesn't want device back. */
334 ccw_device_do_unreg_rereg((void *)cdev);
94bb0633
CH
335 else {
336 /* Reenable channel measurements, if needed. */
337 cmf_reenable(cdev);
1da177e4 338 wake_up(&cdev->private->wait_q);
94bb0633 339 }
1da177e4
LT
340}
341
342/*
343 * Finished with online/offline processing.
344 */
345static void
346ccw_device_done(struct ccw_device *cdev, int state)
347{
348 struct subchannel *sch;
349
350 sch = to_subchannel(cdev->dev.parent);
351
f1ee3281
CH
352 ccw_device_set_timeout(cdev, 0);
353
1da177e4
LT
354 if (state != DEV_STATE_ONLINE)
355 cio_disable_subchannel(sch);
356
357 /* Reset device status. */
358 memset(&cdev->private->irb, 0, sizeof(struct irb));
359
360 cdev->private->state = state;
361
362
363 if (state == DEV_STATE_BOXED)
364 CIO_DEBUG(KERN_WARNING, 2,
365 "Boxed device %04x on subchannel %04x\n",
a8237fc4 366 cdev->private->devno, sch->schid.sch_no);
1da177e4
LT
367
368 if (cdev->private->flags.donotify) {
369 cdev->private->flags.donotify = 0;
370 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,
371 (void *)cdev);
372 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
373 }
374 wake_up(&cdev->private->wait_q);
375
376 if (css_init_done && state != DEV_STATE_ONLINE)
377 put_device (&cdev->dev);
378}
379
7e560814
CH
380static inline int cmp_pgid(struct pgid *p1, struct pgid *p2)
381{
382 char *c1;
383 char *c2;
384
385 c1 = (char *)p1;
386 c2 = (char *)p2;
387
388 return memcmp(c1 + 1, c2 + 1, sizeof(struct pgid) - 1);
389}
390
391static void __ccw_device_get_common_pgid(struct ccw_device *cdev)
392{
393 int i;
394 int last;
395
396 last = 0;
397 for (i = 0; i < 8; i++) {
398 if (cdev->private->pgid[i].inf.ps.state1 == SNID_STATE1_RESET)
399 /* No PGID yet */
400 continue;
401 if (cdev->private->pgid[last].inf.ps.state1 ==
402 SNID_STATE1_RESET) {
403 /* First non-zero PGID */
404 last = i;
405 continue;
406 }
407 if (cmp_pgid(&cdev->private->pgid[i],
408 &cdev->private->pgid[last]) == 0)
409 /* Non-conflicting PGIDs */
410 continue;
411
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->ssid, cdev->private->devno);
416 cdev->private->options.pgroup = 0;
417 return;
418 }
419 if (cdev->private->pgid[last].inf.ps.state1 ==
420 SNID_STATE1_RESET)
421 /* No previous pgid found */
422 memcpy(&cdev->private->pgid[0], &css[0]->global_pgid,
423 sizeof(struct pgid));
424 else
425 /* Use existing pgid */
426 memcpy(&cdev->private->pgid[0], &cdev->private->pgid[last],
427 sizeof(struct pgid));
428}
429
1da177e4
LT
430/*
431 * Function called from device_pgid.c after sense path ground has completed.
432 */
433void
434ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
435{
436 struct subchannel *sch;
437
438 sch = to_subchannel(cdev->dev.parent);
439 switch (err) {
7e560814
CH
440 case -EOPNOTSUPP: /* path grouping not supported, use nop instead. */
441 cdev->private->options.pgroup = 0;
442 break;
443 case 0: /* success */
444 case -EACCES: /* partial success, some paths not operational */
445 /* Check if all pgids are equal or 0. */
446 __ccw_device_get_common_pgid(cdev);
1da177e4
LT
447 break;
448 case -ETIME: /* Sense path group id stopped by timeout. */
449 case -EUSERS: /* device is reserved for someone else. */
450 ccw_device_done(cdev, DEV_STATE_BOXED);
7e560814 451 return;
1da177e4
LT
452 default:
453 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
7e560814 454 return;
1da177e4 455 }
7e560814 456 /* Start Path Group verification. */
7e560814 457 cdev->private->state = DEV_STATE_VERIFY;
28bdc6f6 458 cdev->private->flags.doverify = 0;
7e560814 459 ccw_device_verify_start(cdev);
1da177e4
LT
460}
461
462/*
463 * Start device recognition.
464 */
465int
466ccw_device_recognition(struct ccw_device *cdev)
467{
468 struct subchannel *sch;
469 int ret;
470
471 if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
472 (cdev->private->state != DEV_STATE_BOXED))
473 return -EINVAL;
474 sch = to_subchannel(cdev->dev.parent);
475 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
476 if (ret != 0)
477 /* Couldn't enable the subchannel for i/o. Sick device. */
478 return ret;
479
480 /* After 60s the device recognition is considered to have failed. */
481 ccw_device_set_timeout(cdev, 60*HZ);
482
483 /*
484 * We used to start here with a sense pgid to find out whether a device
485 * is locked by someone else. Unfortunately, the sense pgid command
486 * code has other meanings on devices predating the path grouping
487 * algorithm, so we start with sense id and box the device after an
488 * timeout (or if sense pgid during path verification detects the device
489 * is locked, as may happen on newer devices).
490 */
491 cdev->private->flags.recog_done = 0;
492 cdev->private->state = DEV_STATE_SENSE_ID;
493 ccw_device_sense_id_start(cdev);
494 return 0;
495}
496
497/*
498 * Handle timeout in device recognition.
499 */
500static void
501ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
502{
503 int ret;
504
505 ret = ccw_device_cancel_halt_clear(cdev);
506 switch (ret) {
507 case 0:
508 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
509 break;
510 case -ENODEV:
511 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
512 break;
513 default:
514 ccw_device_set_timeout(cdev, 3*HZ);
515 }
516}
517
518
519static void
520ccw_device_nopath_notify(void *data)
521{
522 struct ccw_device *cdev;
523 struct subchannel *sch;
524 int ret;
525
526 cdev = (struct ccw_device *)data;
527 sch = to_subchannel(cdev->dev.parent);
528 /* Extra sanity. */
529 if (sch->lpm)
530 return;
531 ret = (sch->driver && sch->driver->notify) ?
532 sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0;
533 if (!ret) {
534 if (get_device(&sch->dev)) {
535 /* Driver doesn't want to keep device. */
536 cio_disable_subchannel(sch);
537 if (get_device(&cdev->dev)) {
538 PREPARE_WORK(&cdev->private->kick_work,
539 ccw_device_call_sch_unregister,
540 (void *)cdev);
541 queue_work(ccw_device_work,
542 &cdev->private->kick_work);
543 } else
544 put_device(&sch->dev);
545 }
546 } else {
547 cio_disable_subchannel(sch);
548 ccw_device_set_timeout(cdev, 0);
549 cdev->private->flags.fake_irb = 0;
550 cdev->private->state = DEV_STATE_DISCONNECTED;
551 wake_up(&cdev->private->wait_q);
552 }
553}
554
555void
556ccw_device_verify_done(struct ccw_device *cdev, int err)
557{
28bdc6f6
PO
558 struct subchannel *sch;
559
560 sch = to_subchannel(cdev->dev.parent);
561 /* Update schib - pom may have changed. */
562 stsch(sch->schid, &sch->schib);
563 /* Update lpm with verified path mask. */
564 sch->lpm = sch->vpm;
565 /* Repeat path verification? */
566 if (cdev->private->flags.doverify) {
567 cdev->private->flags.doverify = 0;
568 ccw_device_verify_start(cdev);
569 return;
570 }
1da177e4
LT
571 switch (err) {
572 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
573 cdev->private->options.pgroup = 0;
574 case 0:
575 ccw_device_done(cdev, DEV_STATE_ONLINE);
576 /* Deliver fake irb to device driver, if needed. */
577 if (cdev->private->flags.fake_irb) {
578 memset(&cdev->private->irb, 0, sizeof(struct irb));
292888c8
HC
579 cdev->private->irb.scsw.cc = 1;
580 cdev->private->irb.scsw.fctl = SCSW_FCTL_START_FUNC;
581 cdev->private->irb.scsw.actl = SCSW_ACTL_START_PEND;
582 cdev->private->irb.scsw.stctl = SCSW_STCTL_STATUS_PEND;
1da177e4
LT
583 cdev->private->flags.fake_irb = 0;
584 if (cdev->handler)
585 cdev->handler(cdev, cdev->private->intparm,
586 &cdev->private->irb);
587 memset(&cdev->private->irb, 0, sizeof(struct irb));
588 }
589 break;
590 case -ETIME:
591 ccw_device_done(cdev, DEV_STATE_BOXED);
592 break;
593 default:
594 PREPARE_WORK(&cdev->private->kick_work,
595 ccw_device_nopath_notify, (void *)cdev);
596 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
597 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
598 break;
599 }
600}
601
602/*
603 * Get device online.
604 */
605int
606ccw_device_online(struct ccw_device *cdev)
607{
608 struct subchannel *sch;
609 int ret;
610
611 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
612 (cdev->private->state != DEV_STATE_BOXED))
613 return -EINVAL;
614 sch = to_subchannel(cdev->dev.parent);
615 if (css_init_done && !get_device(&cdev->dev))
616 return -ENODEV;
617 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
618 if (ret != 0) {
619 /* Couldn't enable the subchannel for i/o. Sick device. */
620 if (ret == -ENODEV)
621 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
622 return ret;
623 }
624 /* Do we want to do path grouping? */
625 if (!cdev->private->options.pgroup) {
7e560814
CH
626 /* Start initial path verification. */
627 cdev->private->state = DEV_STATE_VERIFY;
28bdc6f6 628 cdev->private->flags.doverify = 0;
7e560814 629 ccw_device_verify_start(cdev);
1da177e4
LT
630 return 0;
631 }
632 /* Do a SensePGID first. */
633 cdev->private->state = DEV_STATE_SENSE_PGID;
634 ccw_device_sense_pgid_start(cdev);
635 return 0;
636}
637
638void
639ccw_device_disband_done(struct ccw_device *cdev, int err)
640{
641 switch (err) {
642 case 0:
643 ccw_device_done(cdev, DEV_STATE_OFFLINE);
644 break;
645 case -ETIME:
646 ccw_device_done(cdev, DEV_STATE_BOXED);
647 break;
648 default:
649 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
650 break;
651 }
652}
653
654/*
655 * Shutdown device.
656 */
657int
658ccw_device_offline(struct ccw_device *cdev)
659{
660 struct subchannel *sch;
661
662 sch = to_subchannel(cdev->dev.parent);
a8237fc4 663 if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
1da177e4
LT
664 return -ENODEV;
665 if (cdev->private->state != DEV_STATE_ONLINE) {
666 if (sch->schib.scsw.actl != 0)
667 return -EBUSY;
668 return -EINVAL;
669 }
670 if (sch->schib.scsw.actl != 0)
671 return -EBUSY;
672 /* Are we doing path grouping? */
673 if (!cdev->private->options.pgroup) {
674 /* No, set state offline immediately. */
675 ccw_device_done(cdev, DEV_STATE_OFFLINE);
676 return 0;
677 }
678 /* Start Set Path Group commands. */
679 cdev->private->state = DEV_STATE_DISBAND_PGID;
680 ccw_device_disband_start(cdev);
681 return 0;
682}
683
684/*
685 * Handle timeout in device online/offline process.
686 */
687static void
688ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
689{
690 int ret;
691
692 ret = ccw_device_cancel_halt_clear(cdev);
693 switch (ret) {
694 case 0:
695 ccw_device_done(cdev, DEV_STATE_BOXED);
696 break;
697 case -ENODEV:
698 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
699 break;
700 default:
701 ccw_device_set_timeout(cdev, 3*HZ);
702 }
703}
704
705/*
706 * Handle not oper event in device recognition.
707 */
708static void
709ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
710{
711 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
712}
713
714/*
715 * Handle not operational event while offline.
716 */
717static void
718ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
719{
720 struct subchannel *sch;
721
722 cdev->private->state = DEV_STATE_NOT_OPER;
723 sch = to_subchannel(cdev->dev.parent);
724 if (get_device(&cdev->dev)) {
725 PREPARE_WORK(&cdev->private->kick_work,
726 ccw_device_call_sch_unregister, (void *)cdev);
727 queue_work(ccw_device_work, &cdev->private->kick_work);
728 }
729 wake_up(&cdev->private->wait_q);
730}
731
732/*
733 * Handle not operational event while online.
734 */
735static void
736ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
737{
738 struct subchannel *sch;
739
740 sch = to_subchannel(cdev->dev.parent);
741 if (sch->driver->notify &&
742 sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
743 ccw_device_set_timeout(cdev, 0);
744 cdev->private->flags.fake_irb = 0;
745 cdev->private->state = DEV_STATE_DISCONNECTED;
746 wake_up(&cdev->private->wait_q);
747 return;
748 }
749 cdev->private->state = DEV_STATE_NOT_OPER;
750 cio_disable_subchannel(sch);
751 if (sch->schib.scsw.actl != 0) {
752 // FIXME: not-oper indication to device driver ?
753 ccw_device_call_handler(cdev);
754 }
755 if (get_device(&cdev->dev)) {
756 PREPARE_WORK(&cdev->private->kick_work,
757 ccw_device_call_sch_unregister, (void *)cdev);
758 queue_work(ccw_device_work, &cdev->private->kick_work);
759 }
760 wake_up(&cdev->private->wait_q);
761}
762
763/*
764 * Handle path verification event.
765 */
766static void
767ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
768{
769 struct subchannel *sch;
770
1da177e4
LT
771 if (cdev->private->state == DEV_STATE_W4SENSE) {
772 cdev->private->flags.doverify = 1;
773 return;
774 }
775 sch = to_subchannel(cdev->dev.parent);
776 /*
777 * Since we might not just be coming from an interrupt from the
778 * subchannel we have to update the schib.
779 */
a8237fc4 780 stsch(sch->schid, &sch->schib);
1da177e4
LT
781
782 if (sch->schib.scsw.actl != 0 ||
65200c29 783 (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
1da177e4
LT
784 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
785 /*
786 * No final status yet or final status not yet delivered
787 * to the device driver. Can't do path verfication now,
788 * delay until final status was delivered.
789 */
790 cdev->private->flags.doverify = 1;
791 return;
792 }
793 /* Device is idle, we can do the path verification. */
794 cdev->private->state = DEV_STATE_VERIFY;
28bdc6f6 795 cdev->private->flags.doverify = 0;
1da177e4
LT
796 ccw_device_verify_start(cdev);
797}
798
799/*
800 * Got an interrupt for a normal io (state online).
801 */
802static void
803ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
804{
805 struct irb *irb;
806
807 irb = (struct irb *) __LC_IRB;
808 /* Check for unsolicited interrupt. */
809 if ((irb->scsw.stctl ==
810 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
811 && (!irb->scsw.cc)) {
812 if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
813 !irb->esw.esw0.erw.cons) {
814 /* Unit check but no sense data. Need basic sense. */
815 if (ccw_device_do_sense(cdev, irb) != 0)
816 goto call_handler_unsol;
e0ec5749 817 memcpy(&cdev->private->irb, irb, sizeof(struct irb));
1da177e4
LT
818 cdev->private->state = DEV_STATE_W4SENSE;
819 cdev->private->intparm = 0;
820 return;
821 }
822call_handler_unsol:
823 if (cdev->handler)
824 cdev->handler (cdev, 0, irb);
825 return;
826 }
827 /* Accumulate status and find out if a basic sense is needed. */
828 ccw_device_accumulate_irb(cdev, irb);
829 if (cdev->private->flags.dosense) {
830 if (ccw_device_do_sense(cdev, irb) == 0) {
831 cdev->private->state = DEV_STATE_W4SENSE;
832 }
833 return;
834 }
835 /* Call the handler. */
836 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
837 /* Start delayed path verification. */
838 ccw_device_online_verify(cdev, 0);
839}
840
841/*
842 * Got an timeout in online state.
843 */
844static void
845ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
846{
847 int ret;
848
849 ccw_device_set_timeout(cdev, 0);
850 ret = ccw_device_cancel_halt_clear(cdev);
851 if (ret == -EBUSY) {
852 ccw_device_set_timeout(cdev, 3*HZ);
853 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
854 return;
855 }
856 if (ret == -ENODEV) {
857 struct subchannel *sch;
858
859 sch = to_subchannel(cdev->dev.parent);
860 if (!sch->lpm) {
861 PREPARE_WORK(&cdev->private->kick_work,
862 ccw_device_nopath_notify, (void *)cdev);
863 queue_work(ccw_device_notify_work,
864 &cdev->private->kick_work);
865 } else
866 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
867 } else if (cdev->handler)
868 cdev->handler(cdev, cdev->private->intparm,
869 ERR_PTR(-ETIMEDOUT));
870}
871
872/*
873 * Got an interrupt for a basic sense.
874 */
875void
876ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
877{
878 struct irb *irb;
879
880 irb = (struct irb *) __LC_IRB;
881 /* Check for unsolicited interrupt. */
882 if (irb->scsw.stctl ==
883 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
884 if (irb->scsw.cc == 1)
885 /* Basic sense hasn't started. Try again. */
886 ccw_device_do_sense(cdev, irb);
887 else {
08983787
CH
888 printk(KERN_INFO "Huh? %s(%s): unsolicited "
889 "interrupt...\n",
1da177e4
LT
890 __FUNCTION__, cdev->dev.bus_id);
891 if (cdev->handler)
892 cdev->handler (cdev, 0, irb);
893 }
894 return;
895 }
3ba1998e
CH
896 /*
897 * Check if a halt or clear has been issued in the meanwhile. If yes,
898 * only deliver the halt/clear interrupt to the device driver as if it
899 * had killed the original request.
900 */
901 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
902 cdev->private->flags.dosense = 0;
903 memset(&cdev->private->irb, 0, sizeof(struct irb));
904 ccw_device_accumulate_irb(cdev, irb);
905 goto call_handler;
906 }
1da177e4
LT
907 /* Add basic sense info to irb. */
908 ccw_device_accumulate_basic_sense(cdev, irb);
909 if (cdev->private->flags.dosense) {
910 /* Another basic sense is needed. */
911 ccw_device_do_sense(cdev, irb);
912 return;
913 }
3ba1998e 914call_handler:
1da177e4
LT
915 cdev->private->state = DEV_STATE_ONLINE;
916 /* Call the handler. */
917 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
918 /* Start delayed path verification. */
919 ccw_device_online_verify(cdev, 0);
920}
921
922static void
923ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
924{
925 struct irb *irb;
926
927 irb = (struct irb *) __LC_IRB;
928 /* Accumulate status. We don't do basic sense. */
929 ccw_device_accumulate_irb(cdev, irb);
b4f7b1ee
CH
930 /* Remember to clear irb to avoid residuals. */
931 memset(&cdev->private->irb, 0, sizeof(struct irb));
1da177e4
LT
932 /* Try to start delayed device verification. */
933 ccw_device_online_verify(cdev, 0);
934 /* Note: Don't call handler for cio initiated clear! */
935}
936
937static void
938ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
939{
940 struct subchannel *sch;
941
942 sch = to_subchannel(cdev->dev.parent);
943 ccw_device_set_timeout(cdev, 0);
944 /* OK, i/o is dead now. Call interrupt handler. */
945 cdev->private->state = DEV_STATE_ONLINE;
946 if (cdev->handler)
947 cdev->handler(cdev, cdev->private->intparm,
948 ERR_PTR(-ETIMEDOUT));
949 if (!sch->lpm) {
950 PREPARE_WORK(&cdev->private->kick_work,
951 ccw_device_nopath_notify, (void *)cdev);
952 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
953 } else if (cdev->private->flags.doverify)
954 /* Start delayed path verification. */
955 ccw_device_online_verify(cdev, 0);
956}
957
958static void
959ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
960{
961 int ret;
962
963 ret = ccw_device_cancel_halt_clear(cdev);
964 if (ret == -EBUSY) {
965 ccw_device_set_timeout(cdev, 3*HZ);
966 return;
967 }
968 if (ret == -ENODEV) {
969 struct subchannel *sch;
970
971 sch = to_subchannel(cdev->dev.parent);
972 if (!sch->lpm) {
973 PREPARE_WORK(&cdev->private->kick_work,
974 ccw_device_nopath_notify, (void *)cdev);
975 queue_work(ccw_device_notify_work,
976 &cdev->private->kick_work);
977 } else
978 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
979 return;
980 }
981 //FIXME: Can we get here?
982 cdev->private->state = DEV_STATE_ONLINE;
983 if (cdev->handler)
984 cdev->handler(cdev, cdev->private->intparm,
985 ERR_PTR(-ETIMEDOUT));
986}
987
988static void
989ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
990{
991 struct irb *irb;
992 struct subchannel *sch;
993
994 irb = (struct irb *) __LC_IRB;
995 /*
996 * Accumulate status and find out if a basic sense is needed.
997 * This is fine since we have already adapted the lpm.
998 */
999 ccw_device_accumulate_irb(cdev, irb);
1000 if (cdev->private->flags.dosense) {
1001 if (ccw_device_do_sense(cdev, irb) == 0) {
1002 cdev->private->state = DEV_STATE_W4SENSE;
1003 }
1004 return;
1005 }
1006
1007 /* Iff device is idle, reset timeout. */
1008 sch = to_subchannel(cdev->dev.parent);
a8237fc4 1009 if (!stsch(sch->schid, &sch->schib))
1da177e4
LT
1010 if (sch->schib.scsw.actl == 0)
1011 ccw_device_set_timeout(cdev, 0);
1012 /* Call the handler. */
1013 ccw_device_call_handler(cdev);
1014 if (!sch->lpm) {
1015 PREPARE_WORK(&cdev->private->kick_work,
1016 ccw_device_nopath_notify, (void *)cdev);
1017 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1018 } else if (cdev->private->flags.doverify)
1019 ccw_device_online_verify(cdev, 0);
1020}
1021
1022static void
1023ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1024{
1025 int ret;
1026 struct subchannel *sch;
1027
1028 sch = to_subchannel(cdev->dev.parent);
1029 ccw_device_set_timeout(cdev, 0);
1030 ret = ccw_device_cancel_halt_clear(cdev);
1031 if (ret == -EBUSY) {
1032 ccw_device_set_timeout(cdev, 3*HZ);
1033 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
1034 return;
1035 }
1036 if (ret == -ENODEV) {
1037 if (!sch->lpm) {
1038 PREPARE_WORK(&cdev->private->kick_work,
1039 ccw_device_nopath_notify, (void *)cdev);
1040 queue_work(ccw_device_notify_work,
1041 &cdev->private->kick_work);
1042 } else
1043 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1044 return;
1045 }
1046 if (cdev->handler)
1047 cdev->handler(cdev, cdev->private->intparm,
1048 ERR_PTR(-ETIMEDOUT));
1049 if (!sch->lpm) {
1050 PREPARE_WORK(&cdev->private->kick_work,
1051 ccw_device_nopath_notify, (void *)cdev);
1052 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1053 } else if (cdev->private->flags.doverify)
1054 /* Start delayed path verification. */
1055 ccw_device_online_verify(cdev, 0);
1056}
1057
1058static void
28bdc6f6 1059ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
1da177e4 1060{
28bdc6f6 1061 /* Start verification after current task finished. */
7e560814 1062 cdev->private->flags.doverify = 1;
1da177e4
LT
1063}
1064
1065static void
1066ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
1067{
1068 struct irb *irb;
1069
1070 switch (dev_event) {
1071 case DEV_EVENT_INTERRUPT:
1072 irb = (struct irb *) __LC_IRB;
1073 /* Check for unsolicited interrupt. */
1074 if ((irb->scsw.stctl ==
1075 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
1076 (!irb->scsw.cc))
1077 /* FIXME: we should restart stlck here, but this
1078 * is extremely unlikely ... */
1079 goto out_wakeup;
1080
1081 ccw_device_accumulate_irb(cdev, irb);
1082 /* We don't care about basic sense etc. */
1083 break;
1084 default: /* timeout */
1085 break;
1086 }
1087out_wakeup:
1088 wake_up(&cdev->private->wait_q);
1089}
1090
1091static void
1092ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
1093{
1094 struct subchannel *sch;
1095
1096 sch = to_subchannel(cdev->dev.parent);
1097 if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
1098 /* Couldn't enable the subchannel for i/o. Sick device. */
1099 return;
1100
1101 /* After 60s the device recognition is considered to have failed. */
1102 ccw_device_set_timeout(cdev, 60*HZ);
1103
1104 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
1105 ccw_device_sense_id_start(cdev);
1106}
1107
1108void
1109device_trigger_reprobe(struct subchannel *sch)
1110{
1111 struct ccw_device *cdev;
1112
1113 if (!sch->dev.driver_data)
1114 return;
1115 cdev = sch->dev.driver_data;
1116 if (cdev->private->state != DEV_STATE_DISCONNECTED)
1117 return;
1118
1119 /* Update some values. */
a8237fc4 1120 if (stsch(sch->schid, &sch->schib))
1da177e4
LT
1121 return;
1122
1123 /*
1124 * The pim, pam, pom values may not be accurate, but they are the best
1125 * we have before performing device selection :/
1126 */
28bdc6f6 1127 sch->lpm = sch->schib.pmcw.pam & sch->opm;
1da177e4
LT
1128 /* Re-set some bits in the pmcw that were lost. */
1129 sch->schib.pmcw.isc = 3;
1130 sch->schib.pmcw.csense = 1;
1131 sch->schib.pmcw.ena = 0;
1132 if ((sch->lpm & (sch->lpm - 1)) != 0)
1133 sch->schib.pmcw.mp = 1;
1134 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1135 /* We should also udate ssd info, but this has to wait. */
1136 ccw_device_start_id(cdev, 0);
1137}
1138
1139static void
1140ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1141{
1142 struct subchannel *sch;
1143
1144 sch = to_subchannel(cdev->dev.parent);
1145 /*
1146 * An interrupt in state offline means a previous disable was not
1147 * successful. Try again.
1148 */
1149 cio_disable_subchannel(sch);
1150}
1151
1152static void
1153ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1154{
1155 retry_set_schib(cdev);
1156 cdev->private->state = DEV_STATE_ONLINE;
1157 dev_fsm_event(cdev, dev_event);
1158}
1159
94bb0633
CH
1160static void ccw_device_update_cmfblock(struct ccw_device *cdev,
1161 enum dev_event dev_event)
1162{
1163 cmf_retry_copy_block(cdev);
1164 cdev->private->state = DEV_STATE_ONLINE;
1165 dev_fsm_event(cdev, dev_event);
1166}
1da177e4
LT
1167
1168static void
1169ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1170{
1171 ccw_device_set_timeout(cdev, 0);
1172 if (dev_event == DEV_EVENT_NOTOPER)
1173 cdev->private->state = DEV_STATE_NOT_OPER;
1174 else
1175 cdev->private->state = DEV_STATE_OFFLINE;
1176 wake_up(&cdev->private->wait_q);
1177}
1178
1179static void
1180ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1181{
1182 int ret;
1183
1184 ret = ccw_device_cancel_halt_clear(cdev);
1185 switch (ret) {
1186 case 0:
1187 cdev->private->state = DEV_STATE_OFFLINE;
1188 wake_up(&cdev->private->wait_q);
1189 break;
1190 case -ENODEV:
1191 cdev->private->state = DEV_STATE_NOT_OPER;
1192 wake_up(&cdev->private->wait_q);
1193 break;
1194 default:
1195 ccw_device_set_timeout(cdev, HZ/10);
1196 }
1197}
1198
1199/*
1200 * No operation action. This is used e.g. to ignore a timeout event in
1201 * state offline.
1202 */
1203static void
1204ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1205{
1206}
1207
1208/*
1209 * Bug operation action.
1210 */
1211static void
1212ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1213{
1214 printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1215 cdev->private->state, dev_event);
1216 BUG();
1217}
1218
1219/*
1220 * device statemachine
1221 */
1222fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1223 [DEV_STATE_NOT_OPER] = {
1224 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1225 [DEV_EVENT_INTERRUPT] = ccw_device_bug,
1226 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1227 [DEV_EVENT_VERIFY] = ccw_device_nop,
1228 },
1229 [DEV_STATE_SENSE_PGID] = {
1230 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1231 [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
1232 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1233 [DEV_EVENT_VERIFY] = ccw_device_nop,
1234 },
1235 [DEV_STATE_SENSE_ID] = {
1236 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1237 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1238 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1239 [DEV_EVENT_VERIFY] = ccw_device_nop,
1240 },
1241 [DEV_STATE_OFFLINE] = {
1242 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1243 [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
1244 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1245 [DEV_EVENT_VERIFY] = ccw_device_nop,
1246 },
1247 [DEV_STATE_VERIFY] = {
1248 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1249 [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
1250 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
28bdc6f6 1251 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
1da177e4
LT
1252 },
1253 [DEV_STATE_ONLINE] = {
1254 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1255 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1256 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1257 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1258 },
1259 [DEV_STATE_W4SENSE] = {
1260 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1261 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1262 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1263 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1264 },
1265 [DEV_STATE_DISBAND_PGID] = {
1266 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1267 [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
1268 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1269 [DEV_EVENT_VERIFY] = ccw_device_nop,
1270 },
1271 [DEV_STATE_BOXED] = {
1272 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1273 [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
1274 [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
1275 [DEV_EVENT_VERIFY] = ccw_device_nop,
1276 },
1277 /* states to wait for i/o completion before doing something */
1278 [DEV_STATE_CLEAR_VERIFY] = {
1279 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1280 [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
1281 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1282 [DEV_EVENT_VERIFY] = ccw_device_nop,
1283 },
1284 [DEV_STATE_TIMEOUT_KILL] = {
1285 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1286 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1287 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1288 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1289 },
1290 [DEV_STATE_WAIT4IO] = {
1291 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1292 [DEV_EVENT_INTERRUPT] = ccw_device_wait4io_irq,
1293 [DEV_EVENT_TIMEOUT] = ccw_device_wait4io_timeout,
28bdc6f6 1294 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
1da177e4
LT
1295 },
1296 [DEV_STATE_QUIESCE] = {
1297 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1298 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1299 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1300 [DEV_EVENT_VERIFY] = ccw_device_nop,
1301 },
1302 /* special states for devices gone not operational */
1303 [DEV_STATE_DISCONNECTED] = {
1304 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1305 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1306 [DEV_EVENT_TIMEOUT] = ccw_device_bug,
28bdc6f6 1307 [DEV_EVENT_VERIFY] = ccw_device_start_id,
1da177e4
LT
1308 },
1309 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1310 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1311 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1312 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1313 [DEV_EVENT_VERIFY] = ccw_device_nop,
1314 },
1315 [DEV_STATE_CMFCHANGE] = {
1316 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1317 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1318 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1319 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1320 },
94bb0633
CH
1321 [DEV_STATE_CMFUPDATE] = {
1322 [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
1323 [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
1324 [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
1325 [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
1326 },
1da177e4
LT
1327};
1328
1329/*
1330 * io_subchannel_irq is called for "real" interrupts or for status
1331 * pending conditions on msch.
1332 */
1333void
1334io_subchannel_irq (struct device *pdev)
1335{
1336 struct ccw_device *cdev;
1337
1338 cdev = to_subchannel(pdev)->dev.driver_data;
1339
1340 CIO_TRACE_EVENT (3, "IRQ");
1341 CIO_TRACE_EVENT (3, pdev->bus_id);
1342 if (cdev)
1343 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1344}
1345
1346EXPORT_SYMBOL_GPL(ccw_device_set_timeout);