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