blob: b67620208f36e2f463b4022a2a25e897197f3067 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Cornelia Huck4ce3b302006-01-14 13:21:04 -08007 * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 */
10
11#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080013#include <linux/jiffies.h>
14#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <asm/ccwdev.h>
Cornelia Huck4c24da72005-09-03 15:58:01 -070017#include <asm/cio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
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);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800135 ret = stsch(sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 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);
Peter Oberparleiterba4ba8a2006-07-27 14:00:23 +0200155 if (ret != -EBUSY)
156 return (ret == 0) ? -EBUSY : ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 }
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;
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800234 stsch(sch->schid, &sch->schib);
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200235 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Cornelia Huck4ffa9232005-07-29 14:03:37 -0700236 /* Check since device may again have become not operational. */
237 if (!sch->schib.pmcw.dnv)
238 state = DEV_STATE_NOT_OPER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 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,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800257 "SenseID : unknown device %04x on subchannel "
258 "0.%x.%04x\n", cdev->private->devno,
259 sch->schid.ssid, sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 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 */
Heiko Carstens81388d22006-09-20 15:59:17 +0200267 memset(&cdev->id, 0, sizeof(cdev->id));
Heiko Carstens292888c2006-08-30 14:33:35 +0200268 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 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. */
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800282 CIO_DEBUG(KERN_INFO, 2, "SenseID : device 0.%x.%04x reports: "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 "CU Type/Mod = %04X/%02X, Dev Type/Mod = "
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800284 "%04X/%02X\n",
285 cdev->private->ssid, cdev->private->devno,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 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,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800291 "SenseID : boxed device %04x on subchannel "
292 "0.%x.%04x\n", cdev->private->devno,
293 sch->schid.ssid, sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 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);
Cornelia Huck94bb0632006-06-29 15:08:41 +0200335 else {
336 /* Reenable channel measurements, if needed. */
337 cmf_reenable(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 wake_up(&cdev->private->wait_q);
Cornelia Huck94bb0632006-06-29 15:08:41 +0200339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
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
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200352 ccw_device_set_timeout(cdev, 0);
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 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",
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800366 cdev->private->devno, sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
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
Cornelia Huck7e560812006-07-12 16:40:19 +0200380static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430/*
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) {
Cornelia Huck7e560812006-07-12 16:40:19 +0200440 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 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);
Cornelia Huck7e560812006-07-12 16:40:19 +0200451 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 default:
453 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
Cornelia Huck7e560812006-07-12 16:40:19 +0200454 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
Cornelia Huck7e560812006-07-12 16:40:19 +0200456 /* Start Path Group verification. */
Cornelia Huck7e560812006-07-12 16:40:19 +0200457 cdev->private->state = DEV_STATE_VERIFY;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200458 cdev->private->flags.doverify = 0;
Cornelia Huck7e560812006-07-12 16:40:19 +0200459 ccw_device_verify_start(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460}
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{
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200558 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 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));
Heiko Carstens292888c2006-08-30 14:33:35 +0200579 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 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) {
Cornelia Huck7e560812006-07-12 16:40:19 +0200626 /* Start initial path verification. */
627 cdev->private->state = DEV_STATE_VERIFY;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200628 cdev->private->flags.doverify = 0;
Cornelia Huck7e560812006-07-12 16:40:19 +0200629 ccw_device_verify_start(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 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);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800663 if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 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 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800780 stsch(sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
782 if (sch->schib.scsw.actl != 0 ||
Peter Oberparleiter65200c22006-08-07 17:00:33 +0200783 (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 (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;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200795 cdev->private->flags.doverify = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 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;
Cornelia Hucke0ec5742006-06-04 02:51:27 -0700817 memcpy(&cdev->private->irb, irb, sizeof(struct irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 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 {
888 printk("Huh? %s(%s): unsolicited interrupt...\n",
889 __FUNCTION__, cdev->dev.bus_id);
890 if (cdev->handler)
891 cdev->handler (cdev, 0, irb);
892 }
893 return;
894 }
Cornelia Huck3ba19982006-03-24 03:15:12 -0800895 /*
896 * Check if a halt or clear has been issued in the meanwhile. If yes,
897 * only deliver the halt/clear interrupt to the device driver as if it
898 * had killed the original request.
899 */
900 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
901 cdev->private->flags.dosense = 0;
902 memset(&cdev->private->irb, 0, sizeof(struct irb));
903 ccw_device_accumulate_irb(cdev, irb);
904 goto call_handler;
905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 /* Add basic sense info to irb. */
907 ccw_device_accumulate_basic_sense(cdev, irb);
908 if (cdev->private->flags.dosense) {
909 /* Another basic sense is needed. */
910 ccw_device_do_sense(cdev, irb);
911 return;
912 }
Cornelia Huck3ba19982006-03-24 03:15:12 -0800913call_handler:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 cdev->private->state = DEV_STATE_ONLINE;
915 /* Call the handler. */
916 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
917 /* Start delayed path verification. */
918 ccw_device_online_verify(cdev, 0);
919}
920
921static void
922ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
923{
924 struct irb *irb;
925
926 irb = (struct irb *) __LC_IRB;
927 /* Accumulate status. We don't do basic sense. */
928 ccw_device_accumulate_irb(cdev, irb);
Cornelia Huckb4f7b1e2006-06-29 15:03:35 +0200929 /* Remember to clear irb to avoid residuals. */
930 memset(&cdev->private->irb, 0, sizeof(struct irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 /* Try to start delayed device verification. */
932 ccw_device_online_verify(cdev, 0);
933 /* Note: Don't call handler for cio initiated clear! */
934}
935
936static void
937ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
938{
939 struct subchannel *sch;
940
941 sch = to_subchannel(cdev->dev.parent);
942 ccw_device_set_timeout(cdev, 0);
943 /* OK, i/o is dead now. Call interrupt handler. */
944 cdev->private->state = DEV_STATE_ONLINE;
945 if (cdev->handler)
946 cdev->handler(cdev, cdev->private->intparm,
947 ERR_PTR(-ETIMEDOUT));
948 if (!sch->lpm) {
949 PREPARE_WORK(&cdev->private->kick_work,
950 ccw_device_nopath_notify, (void *)cdev);
951 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
952 } else if (cdev->private->flags.doverify)
953 /* Start delayed path verification. */
954 ccw_device_online_verify(cdev, 0);
955}
956
957static void
958ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
959{
960 int ret;
961
962 ret = ccw_device_cancel_halt_clear(cdev);
963 if (ret == -EBUSY) {
964 ccw_device_set_timeout(cdev, 3*HZ);
965 return;
966 }
967 if (ret == -ENODEV) {
968 struct subchannel *sch;
969
970 sch = to_subchannel(cdev->dev.parent);
971 if (!sch->lpm) {
972 PREPARE_WORK(&cdev->private->kick_work,
973 ccw_device_nopath_notify, (void *)cdev);
974 queue_work(ccw_device_notify_work,
975 &cdev->private->kick_work);
976 } else
977 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
978 return;
979 }
980 //FIXME: Can we get here?
981 cdev->private->state = DEV_STATE_ONLINE;
982 if (cdev->handler)
983 cdev->handler(cdev, cdev->private->intparm,
984 ERR_PTR(-ETIMEDOUT));
985}
986
987static void
988ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
989{
990 struct irb *irb;
991 struct subchannel *sch;
992
993 irb = (struct irb *) __LC_IRB;
994 /*
995 * Accumulate status and find out if a basic sense is needed.
996 * This is fine since we have already adapted the lpm.
997 */
998 ccw_device_accumulate_irb(cdev, irb);
999 if (cdev->private->flags.dosense) {
1000 if (ccw_device_do_sense(cdev, irb) == 0) {
1001 cdev->private->state = DEV_STATE_W4SENSE;
1002 }
1003 return;
1004 }
1005
1006 /* Iff device is idle, reset timeout. */
1007 sch = to_subchannel(cdev->dev.parent);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001008 if (!stsch(sch->schid, &sch->schib))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 if (sch->schib.scsw.actl == 0)
1010 ccw_device_set_timeout(cdev, 0);
1011 /* Call the handler. */
1012 ccw_device_call_handler(cdev);
1013 if (!sch->lpm) {
1014 PREPARE_WORK(&cdev->private->kick_work,
1015 ccw_device_nopath_notify, (void *)cdev);
1016 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1017 } else if (cdev->private->flags.doverify)
1018 ccw_device_online_verify(cdev, 0);
1019}
1020
1021static void
1022ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1023{
1024 int ret;
1025 struct subchannel *sch;
1026
1027 sch = to_subchannel(cdev->dev.parent);
1028 ccw_device_set_timeout(cdev, 0);
1029 ret = ccw_device_cancel_halt_clear(cdev);
1030 if (ret == -EBUSY) {
1031 ccw_device_set_timeout(cdev, 3*HZ);
1032 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
1033 return;
1034 }
1035 if (ret == -ENODEV) {
1036 if (!sch->lpm) {
1037 PREPARE_WORK(&cdev->private->kick_work,
1038 ccw_device_nopath_notify, (void *)cdev);
1039 queue_work(ccw_device_notify_work,
1040 &cdev->private->kick_work);
1041 } else
1042 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1043 return;
1044 }
1045 if (cdev->handler)
1046 cdev->handler(cdev, cdev->private->intparm,
1047 ERR_PTR(-ETIMEDOUT));
1048 if (!sch->lpm) {
1049 PREPARE_WORK(&cdev->private->kick_work,
1050 ccw_device_nopath_notify, (void *)cdev);
1051 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1052 } else if (cdev->private->flags.doverify)
1053 /* Start delayed path verification. */
1054 ccw_device_online_verify(cdev, 0);
1055}
1056
1057static void
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001058ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001060 /* Start verification after current task finished. */
Cornelia Huck7e560812006-07-12 16:40:19 +02001061 cdev->private->flags.doverify = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062}
1063
1064static void
1065ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
1066{
1067 struct irb *irb;
1068
1069 switch (dev_event) {
1070 case DEV_EVENT_INTERRUPT:
1071 irb = (struct irb *) __LC_IRB;
1072 /* Check for unsolicited interrupt. */
1073 if ((irb->scsw.stctl ==
1074 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
1075 (!irb->scsw.cc))
1076 /* FIXME: we should restart stlck here, but this
1077 * is extremely unlikely ... */
1078 goto out_wakeup;
1079
1080 ccw_device_accumulate_irb(cdev, irb);
1081 /* We don't care about basic sense etc. */
1082 break;
1083 default: /* timeout */
1084 break;
1085 }
1086out_wakeup:
1087 wake_up(&cdev->private->wait_q);
1088}
1089
1090static void
1091ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
1092{
1093 struct subchannel *sch;
1094
1095 sch = to_subchannel(cdev->dev.parent);
1096 if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
1097 /* Couldn't enable the subchannel for i/o. Sick device. */
1098 return;
1099
1100 /* After 60s the device recognition is considered to have failed. */
1101 ccw_device_set_timeout(cdev, 60*HZ);
1102
1103 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
1104 ccw_device_sense_id_start(cdev);
1105}
1106
1107void
1108device_trigger_reprobe(struct subchannel *sch)
1109{
1110 struct ccw_device *cdev;
1111
1112 if (!sch->dev.driver_data)
1113 return;
1114 cdev = sch->dev.driver_data;
1115 if (cdev->private->state != DEV_STATE_DISCONNECTED)
1116 return;
1117
1118 /* Update some values. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001119 if (stsch(sch->schid, &sch->schib))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 return;
1121
1122 /*
1123 * The pim, pam, pom values may not be accurate, but they are the best
1124 * we have before performing device selection :/
1125 */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001126 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 /* Re-set some bits in the pmcw that were lost. */
1128 sch->schib.pmcw.isc = 3;
1129 sch->schib.pmcw.csense = 1;
1130 sch->schib.pmcw.ena = 0;
1131 if ((sch->lpm & (sch->lpm - 1)) != 0)
1132 sch->schib.pmcw.mp = 1;
1133 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1134 /* We should also udate ssd info, but this has to wait. */
1135 ccw_device_start_id(cdev, 0);
1136}
1137
1138static void
1139ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1140{
1141 struct subchannel *sch;
1142
1143 sch = to_subchannel(cdev->dev.parent);
1144 /*
1145 * An interrupt in state offline means a previous disable was not
1146 * successful. Try again.
1147 */
1148 cio_disable_subchannel(sch);
1149}
1150
1151static void
1152ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1153{
1154 retry_set_schib(cdev);
1155 cdev->private->state = DEV_STATE_ONLINE;
1156 dev_fsm_event(cdev, dev_event);
1157}
1158
Cornelia Huck94bb0632006-06-29 15:08:41 +02001159static void ccw_device_update_cmfblock(struct ccw_device *cdev,
1160 enum dev_event dev_event)
1161{
1162 cmf_retry_copy_block(cdev);
1163 cdev->private->state = DEV_STATE_ONLINE;
1164 dev_fsm_event(cdev, dev_event);
1165}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167static void
1168ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1169{
1170 ccw_device_set_timeout(cdev, 0);
1171 if (dev_event == DEV_EVENT_NOTOPER)
1172 cdev->private->state = DEV_STATE_NOT_OPER;
1173 else
1174 cdev->private->state = DEV_STATE_OFFLINE;
1175 wake_up(&cdev->private->wait_q);
1176}
1177
1178static void
1179ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1180{
1181 int ret;
1182
1183 ret = ccw_device_cancel_halt_clear(cdev);
1184 switch (ret) {
1185 case 0:
1186 cdev->private->state = DEV_STATE_OFFLINE;
1187 wake_up(&cdev->private->wait_q);
1188 break;
1189 case -ENODEV:
1190 cdev->private->state = DEV_STATE_NOT_OPER;
1191 wake_up(&cdev->private->wait_q);
1192 break;
1193 default:
1194 ccw_device_set_timeout(cdev, HZ/10);
1195 }
1196}
1197
1198/*
1199 * No operation action. This is used e.g. to ignore a timeout event in
1200 * state offline.
1201 */
1202static void
1203ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1204{
1205}
1206
1207/*
1208 * Bug operation action.
1209 */
1210static void
1211ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1212{
1213 printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1214 cdev->private->state, dev_event);
1215 BUG();
1216}
1217
1218/*
1219 * device statemachine
1220 */
1221fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1222 [DEV_STATE_NOT_OPER] = {
1223 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1224 [DEV_EVENT_INTERRUPT] = ccw_device_bug,
1225 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1226 [DEV_EVENT_VERIFY] = ccw_device_nop,
1227 },
1228 [DEV_STATE_SENSE_PGID] = {
1229 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1230 [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
1231 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1232 [DEV_EVENT_VERIFY] = ccw_device_nop,
1233 },
1234 [DEV_STATE_SENSE_ID] = {
1235 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1236 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1237 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1238 [DEV_EVENT_VERIFY] = ccw_device_nop,
1239 },
1240 [DEV_STATE_OFFLINE] = {
1241 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1242 [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
1243 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1244 [DEV_EVENT_VERIFY] = ccw_device_nop,
1245 },
1246 [DEV_STATE_VERIFY] = {
1247 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1248 [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
1249 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001250 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 },
1252 [DEV_STATE_ONLINE] = {
1253 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1254 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1255 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1256 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1257 },
1258 [DEV_STATE_W4SENSE] = {
1259 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1260 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1261 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1262 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1263 },
1264 [DEV_STATE_DISBAND_PGID] = {
1265 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1266 [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
1267 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1268 [DEV_EVENT_VERIFY] = ccw_device_nop,
1269 },
1270 [DEV_STATE_BOXED] = {
1271 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1272 [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
1273 [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
1274 [DEV_EVENT_VERIFY] = ccw_device_nop,
1275 },
1276 /* states to wait for i/o completion before doing something */
1277 [DEV_STATE_CLEAR_VERIFY] = {
1278 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1279 [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
1280 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1281 [DEV_EVENT_VERIFY] = ccw_device_nop,
1282 },
1283 [DEV_STATE_TIMEOUT_KILL] = {
1284 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1285 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1286 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1287 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1288 },
1289 [DEV_STATE_WAIT4IO] = {
1290 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1291 [DEV_EVENT_INTERRUPT] = ccw_device_wait4io_irq,
1292 [DEV_EVENT_TIMEOUT] = ccw_device_wait4io_timeout,
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001293 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 },
1295 [DEV_STATE_QUIESCE] = {
1296 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1297 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1298 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1299 [DEV_EVENT_VERIFY] = ccw_device_nop,
1300 },
1301 /* special states for devices gone not operational */
1302 [DEV_STATE_DISCONNECTED] = {
1303 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1304 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1305 [DEV_EVENT_TIMEOUT] = ccw_device_bug,
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001306 [DEV_EVENT_VERIFY] = ccw_device_start_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 },
1308 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1309 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1310 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1311 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1312 [DEV_EVENT_VERIFY] = ccw_device_nop,
1313 },
1314 [DEV_STATE_CMFCHANGE] = {
1315 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1316 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1317 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1318 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1319 },
Cornelia Huck94bb0632006-06-29 15:08:41 +02001320 [DEV_STATE_CMFUPDATE] = {
1321 [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
1322 [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
1323 [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
1324 [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
1325 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326};
1327
1328/*
1329 * io_subchannel_irq is called for "real" interrupts or for status
1330 * pending conditions on msch.
1331 */
1332void
1333io_subchannel_irq (struct device *pdev)
1334{
1335 struct ccw_device *cdev;
1336
1337 cdev = to_subchannel(pdev)->dev.driver_data;
1338
1339 CIO_TRACE_EVENT (3, "IRQ");
1340 CIO_TRACE_EVENT (3, pdev->bus_id);
1341 if (cdev)
1342 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1343}
1344
1345EXPORT_SYMBOL_GPL(ccw_device_set_timeout);