blob: dace46fc32e8d74e0e12657f159295f02061663f [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
352 if (state != DEV_STATE_ONLINE)
353 cio_disable_subchannel(sch);
354
355 /* Reset device status. */
356 memset(&cdev->private->irb, 0, sizeof(struct irb));
357
358 cdev->private->state = state;
359
360
361 if (state == DEV_STATE_BOXED)
362 CIO_DEBUG(KERN_WARNING, 2,
363 "Boxed device %04x on subchannel %04x\n",
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800364 cdev->private->devno, sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 if (cdev->private->flags.donotify) {
367 cdev->private->flags.donotify = 0;
368 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,
369 (void *)cdev);
370 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
371 }
372 wake_up(&cdev->private->wait_q);
373
374 if (css_init_done && state != DEV_STATE_ONLINE)
375 put_device (&cdev->dev);
376}
377
Cornelia Huck7e560812006-07-12 16:40:19 +0200378static inline int cmp_pgid(struct pgid *p1, struct pgid *p2)
379{
380 char *c1;
381 char *c2;
382
383 c1 = (char *)p1;
384 c2 = (char *)p2;
385
386 return memcmp(c1 + 1, c2 + 1, sizeof(struct pgid) - 1);
387}
388
389static void __ccw_device_get_common_pgid(struct ccw_device *cdev)
390{
391 int i;
392 int last;
393
394 last = 0;
395 for (i = 0; i < 8; i++) {
396 if (cdev->private->pgid[i].inf.ps.state1 == SNID_STATE1_RESET)
397 /* No PGID yet */
398 continue;
399 if (cdev->private->pgid[last].inf.ps.state1 ==
400 SNID_STATE1_RESET) {
401 /* First non-zero PGID */
402 last = i;
403 continue;
404 }
405 if (cmp_pgid(&cdev->private->pgid[i],
406 &cdev->private->pgid[last]) == 0)
407 /* Non-conflicting PGIDs */
408 continue;
409
410 /* PGID mismatch, can't pathgroup. */
411 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
412 "0.%x.%04x, can't pathgroup\n",
413 cdev->private->ssid, cdev->private->devno);
414 cdev->private->options.pgroup = 0;
415 return;
416 }
417 if (cdev->private->pgid[last].inf.ps.state1 ==
418 SNID_STATE1_RESET)
419 /* No previous pgid found */
420 memcpy(&cdev->private->pgid[0], &css[0]->global_pgid,
421 sizeof(struct pgid));
422 else
423 /* Use existing pgid */
424 memcpy(&cdev->private->pgid[0], &cdev->private->pgid[last],
425 sizeof(struct pgid));
426}
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428/*
429 * Function called from device_pgid.c after sense path ground has completed.
430 */
431void
432ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
433{
434 struct subchannel *sch;
435
436 sch = to_subchannel(cdev->dev.parent);
437 switch (err) {
Cornelia Huck7e560812006-07-12 16:40:19 +0200438 case -EOPNOTSUPP: /* path grouping not supported, use nop instead. */
439 cdev->private->options.pgroup = 0;
440 break;
441 case 0: /* success */
442 case -EACCES: /* partial success, some paths not operational */
443 /* Check if all pgids are equal or 0. */
444 __ccw_device_get_common_pgid(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 break;
446 case -ETIME: /* Sense path group id stopped by timeout. */
447 case -EUSERS: /* device is reserved for someone else. */
448 ccw_device_done(cdev, DEV_STATE_BOXED);
Cornelia Huck7e560812006-07-12 16:40:19 +0200449 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 default:
451 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
Cornelia Huck7e560812006-07-12 16:40:19 +0200452 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
Cornelia Huck7e560812006-07-12 16:40:19 +0200454 /* Start Path Group verification. */
Cornelia Huck7e560812006-07-12 16:40:19 +0200455 cdev->private->state = DEV_STATE_VERIFY;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200456 cdev->private->flags.doverify = 0;
Cornelia Huck7e560812006-07-12 16:40:19 +0200457 ccw_device_verify_start(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
460/*
461 * Start device recognition.
462 */
463int
464ccw_device_recognition(struct ccw_device *cdev)
465{
466 struct subchannel *sch;
467 int ret;
468
469 if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
470 (cdev->private->state != DEV_STATE_BOXED))
471 return -EINVAL;
472 sch = to_subchannel(cdev->dev.parent);
473 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
474 if (ret != 0)
475 /* Couldn't enable the subchannel for i/o. Sick device. */
476 return ret;
477
478 /* After 60s the device recognition is considered to have failed. */
479 ccw_device_set_timeout(cdev, 60*HZ);
480
481 /*
482 * We used to start here with a sense pgid to find out whether a device
483 * is locked by someone else. Unfortunately, the sense pgid command
484 * code has other meanings on devices predating the path grouping
485 * algorithm, so we start with sense id and box the device after an
486 * timeout (or if sense pgid during path verification detects the device
487 * is locked, as may happen on newer devices).
488 */
489 cdev->private->flags.recog_done = 0;
490 cdev->private->state = DEV_STATE_SENSE_ID;
491 ccw_device_sense_id_start(cdev);
492 return 0;
493}
494
495/*
496 * Handle timeout in device recognition.
497 */
498static void
499ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
500{
501 int ret;
502
503 ret = ccw_device_cancel_halt_clear(cdev);
504 switch (ret) {
505 case 0:
506 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
507 break;
508 case -ENODEV:
509 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
510 break;
511 default:
512 ccw_device_set_timeout(cdev, 3*HZ);
513 }
514}
515
516
517static void
518ccw_device_nopath_notify(void *data)
519{
520 struct ccw_device *cdev;
521 struct subchannel *sch;
522 int ret;
523
524 cdev = (struct ccw_device *)data;
525 sch = to_subchannel(cdev->dev.parent);
526 /* Extra sanity. */
527 if (sch->lpm)
528 return;
529 ret = (sch->driver && sch->driver->notify) ?
530 sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0;
531 if (!ret) {
532 if (get_device(&sch->dev)) {
533 /* Driver doesn't want to keep device. */
534 cio_disable_subchannel(sch);
535 if (get_device(&cdev->dev)) {
536 PREPARE_WORK(&cdev->private->kick_work,
537 ccw_device_call_sch_unregister,
538 (void *)cdev);
539 queue_work(ccw_device_work,
540 &cdev->private->kick_work);
541 } else
542 put_device(&sch->dev);
543 }
544 } else {
545 cio_disable_subchannel(sch);
546 ccw_device_set_timeout(cdev, 0);
547 cdev->private->flags.fake_irb = 0;
548 cdev->private->state = DEV_STATE_DISCONNECTED;
549 wake_up(&cdev->private->wait_q);
550 }
551}
552
553void
554ccw_device_verify_done(struct ccw_device *cdev, int err)
555{
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200556 struct subchannel *sch;
557
558 sch = to_subchannel(cdev->dev.parent);
559 /* Update schib - pom may have changed. */
560 stsch(sch->schid, &sch->schib);
561 /* Update lpm with verified path mask. */
562 sch->lpm = sch->vpm;
563 /* Repeat path verification? */
564 if (cdev->private->flags.doverify) {
565 cdev->private->flags.doverify = 0;
566 ccw_device_verify_start(cdev);
567 return;
568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 switch (err) {
570 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
571 cdev->private->options.pgroup = 0;
572 case 0:
573 ccw_device_done(cdev, DEV_STATE_ONLINE);
574 /* Deliver fake irb to device driver, if needed. */
575 if (cdev->private->flags.fake_irb) {
576 memset(&cdev->private->irb, 0, sizeof(struct irb));
Heiko Carstens292888c2006-08-30 14:33:35 +0200577 cdev->private->irb.scsw.cc = 1;
578 cdev->private->irb.scsw.fctl = SCSW_FCTL_START_FUNC;
579 cdev->private->irb.scsw.actl = SCSW_ACTL_START_PEND;
580 cdev->private->irb.scsw.stctl = SCSW_STCTL_STATUS_PEND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 cdev->private->flags.fake_irb = 0;
582 if (cdev->handler)
583 cdev->handler(cdev, cdev->private->intparm,
584 &cdev->private->irb);
585 memset(&cdev->private->irb, 0, sizeof(struct irb));
586 }
587 break;
588 case -ETIME:
589 ccw_device_done(cdev, DEV_STATE_BOXED);
590 break;
591 default:
592 PREPARE_WORK(&cdev->private->kick_work,
593 ccw_device_nopath_notify, (void *)cdev);
594 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
595 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
596 break;
597 }
598}
599
600/*
601 * Get device online.
602 */
603int
604ccw_device_online(struct ccw_device *cdev)
605{
606 struct subchannel *sch;
607 int ret;
608
609 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
610 (cdev->private->state != DEV_STATE_BOXED))
611 return -EINVAL;
612 sch = to_subchannel(cdev->dev.parent);
613 if (css_init_done && !get_device(&cdev->dev))
614 return -ENODEV;
615 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
616 if (ret != 0) {
617 /* Couldn't enable the subchannel for i/o. Sick device. */
618 if (ret == -ENODEV)
619 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
620 return ret;
621 }
622 /* Do we want to do path grouping? */
623 if (!cdev->private->options.pgroup) {
Cornelia Huck7e560812006-07-12 16:40:19 +0200624 /* Start initial path verification. */
625 cdev->private->state = DEV_STATE_VERIFY;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200626 cdev->private->flags.doverify = 0;
Cornelia Huck7e560812006-07-12 16:40:19 +0200627 ccw_device_verify_start(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return 0;
629 }
630 /* Do a SensePGID first. */
631 cdev->private->state = DEV_STATE_SENSE_PGID;
632 ccw_device_sense_pgid_start(cdev);
633 return 0;
634}
635
636void
637ccw_device_disband_done(struct ccw_device *cdev, int err)
638{
639 switch (err) {
640 case 0:
641 ccw_device_done(cdev, DEV_STATE_OFFLINE);
642 break;
643 case -ETIME:
644 ccw_device_done(cdev, DEV_STATE_BOXED);
645 break;
646 default:
647 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
648 break;
649 }
650}
651
652/*
653 * Shutdown device.
654 */
655int
656ccw_device_offline(struct ccw_device *cdev)
657{
658 struct subchannel *sch;
659
660 sch = to_subchannel(cdev->dev.parent);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800661 if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 return -ENODEV;
663 if (cdev->private->state != DEV_STATE_ONLINE) {
664 if (sch->schib.scsw.actl != 0)
665 return -EBUSY;
666 return -EINVAL;
667 }
668 if (sch->schib.scsw.actl != 0)
669 return -EBUSY;
670 /* Are we doing path grouping? */
671 if (!cdev->private->options.pgroup) {
672 /* No, set state offline immediately. */
673 ccw_device_done(cdev, DEV_STATE_OFFLINE);
674 return 0;
675 }
676 /* Start Set Path Group commands. */
677 cdev->private->state = DEV_STATE_DISBAND_PGID;
678 ccw_device_disband_start(cdev);
679 return 0;
680}
681
682/*
683 * Handle timeout in device online/offline process.
684 */
685static void
686ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
687{
688 int ret;
689
690 ret = ccw_device_cancel_halt_clear(cdev);
691 switch (ret) {
692 case 0:
693 ccw_device_done(cdev, DEV_STATE_BOXED);
694 break;
695 case -ENODEV:
696 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
697 break;
698 default:
699 ccw_device_set_timeout(cdev, 3*HZ);
700 }
701}
702
703/*
704 * Handle not oper event in device recognition.
705 */
706static void
707ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
708{
709 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
710}
711
712/*
713 * Handle not operational event while offline.
714 */
715static void
716ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
717{
718 struct subchannel *sch;
719
720 cdev->private->state = DEV_STATE_NOT_OPER;
721 sch = to_subchannel(cdev->dev.parent);
722 if (get_device(&cdev->dev)) {
723 PREPARE_WORK(&cdev->private->kick_work,
724 ccw_device_call_sch_unregister, (void *)cdev);
725 queue_work(ccw_device_work, &cdev->private->kick_work);
726 }
727 wake_up(&cdev->private->wait_q);
728}
729
730/*
731 * Handle not operational event while online.
732 */
733static void
734ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
735{
736 struct subchannel *sch;
737
738 sch = to_subchannel(cdev->dev.parent);
739 if (sch->driver->notify &&
740 sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
741 ccw_device_set_timeout(cdev, 0);
742 cdev->private->flags.fake_irb = 0;
743 cdev->private->state = DEV_STATE_DISCONNECTED;
744 wake_up(&cdev->private->wait_q);
745 return;
746 }
747 cdev->private->state = DEV_STATE_NOT_OPER;
748 cio_disable_subchannel(sch);
749 if (sch->schib.scsw.actl != 0) {
750 // FIXME: not-oper indication to device driver ?
751 ccw_device_call_handler(cdev);
752 }
753 if (get_device(&cdev->dev)) {
754 PREPARE_WORK(&cdev->private->kick_work,
755 ccw_device_call_sch_unregister, (void *)cdev);
756 queue_work(ccw_device_work, &cdev->private->kick_work);
757 }
758 wake_up(&cdev->private->wait_q);
759}
760
761/*
762 * Handle path verification event.
763 */
764static void
765ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
766{
767 struct subchannel *sch;
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 if (cdev->private->state == DEV_STATE_W4SENSE) {
770 cdev->private->flags.doverify = 1;
771 return;
772 }
773 sch = to_subchannel(cdev->dev.parent);
774 /*
775 * Since we might not just be coming from an interrupt from the
776 * subchannel we have to update the schib.
777 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800778 stsch(sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780 if (sch->schib.scsw.actl != 0 ||
Peter Oberparleiter65200c22006-08-07 17:00:33 +0200781 (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
783 /*
784 * No final status yet or final status not yet delivered
785 * to the device driver. Can't do path verfication now,
786 * delay until final status was delivered.
787 */
788 cdev->private->flags.doverify = 1;
789 return;
790 }
791 /* Device is idle, we can do the path verification. */
792 cdev->private->state = DEV_STATE_VERIFY;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200793 cdev->private->flags.doverify = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 ccw_device_verify_start(cdev);
795}
796
797/*
798 * Got an interrupt for a normal io (state online).
799 */
800static void
801ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
802{
803 struct irb *irb;
804
805 irb = (struct irb *) __LC_IRB;
806 /* Check for unsolicited interrupt. */
807 if ((irb->scsw.stctl ==
808 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
809 && (!irb->scsw.cc)) {
810 if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
811 !irb->esw.esw0.erw.cons) {
812 /* Unit check but no sense data. Need basic sense. */
813 if (ccw_device_do_sense(cdev, irb) != 0)
814 goto call_handler_unsol;
Cornelia Hucke0ec5742006-06-04 02:51:27 -0700815 memcpy(&cdev->private->irb, irb, sizeof(struct irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 cdev->private->state = DEV_STATE_W4SENSE;
817 cdev->private->intparm = 0;
818 return;
819 }
820call_handler_unsol:
821 if (cdev->handler)
822 cdev->handler (cdev, 0, irb);
823 return;
824 }
825 /* Accumulate status and find out if a basic sense is needed. */
826 ccw_device_accumulate_irb(cdev, irb);
827 if (cdev->private->flags.dosense) {
828 if (ccw_device_do_sense(cdev, irb) == 0) {
829 cdev->private->state = DEV_STATE_W4SENSE;
830 }
831 return;
832 }
833 /* Call the handler. */
834 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
835 /* Start delayed path verification. */
836 ccw_device_online_verify(cdev, 0);
837}
838
839/*
840 * Got an timeout in online state.
841 */
842static void
843ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
844{
845 int ret;
846
847 ccw_device_set_timeout(cdev, 0);
848 ret = ccw_device_cancel_halt_clear(cdev);
849 if (ret == -EBUSY) {
850 ccw_device_set_timeout(cdev, 3*HZ);
851 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
852 return;
853 }
854 if (ret == -ENODEV) {
855 struct subchannel *sch;
856
857 sch = to_subchannel(cdev->dev.parent);
858 if (!sch->lpm) {
859 PREPARE_WORK(&cdev->private->kick_work,
860 ccw_device_nopath_notify, (void *)cdev);
861 queue_work(ccw_device_notify_work,
862 &cdev->private->kick_work);
863 } else
864 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
865 } else if (cdev->handler)
866 cdev->handler(cdev, cdev->private->intparm,
867 ERR_PTR(-ETIMEDOUT));
868}
869
870/*
871 * Got an interrupt for a basic sense.
872 */
873void
874ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
875{
876 struct irb *irb;
877
878 irb = (struct irb *) __LC_IRB;
879 /* Check for unsolicited interrupt. */
880 if (irb->scsw.stctl ==
881 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
882 if (irb->scsw.cc == 1)
883 /* Basic sense hasn't started. Try again. */
884 ccw_device_do_sense(cdev, irb);
885 else {
886 printk("Huh? %s(%s): unsolicited interrupt...\n",
887 __FUNCTION__, cdev->dev.bus_id);
888 if (cdev->handler)
889 cdev->handler (cdev, 0, irb);
890 }
891 return;
892 }
Cornelia Huck3ba19982006-03-24 03:15:12 -0800893 /*
894 * Check if a halt or clear has been issued in the meanwhile. If yes,
895 * only deliver the halt/clear interrupt to the device driver as if it
896 * had killed the original request.
897 */
898 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
899 cdev->private->flags.dosense = 0;
900 memset(&cdev->private->irb, 0, sizeof(struct irb));
901 ccw_device_accumulate_irb(cdev, irb);
902 goto call_handler;
903 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 /* Add basic sense info to irb. */
905 ccw_device_accumulate_basic_sense(cdev, irb);
906 if (cdev->private->flags.dosense) {
907 /* Another basic sense is needed. */
908 ccw_device_do_sense(cdev, irb);
909 return;
910 }
Cornelia Huck3ba19982006-03-24 03:15:12 -0800911call_handler:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 cdev->private->state = DEV_STATE_ONLINE;
913 /* Call the handler. */
914 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
915 /* Start delayed path verification. */
916 ccw_device_online_verify(cdev, 0);
917}
918
919static void
920ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
921{
922 struct irb *irb;
923
924 irb = (struct irb *) __LC_IRB;
925 /* Accumulate status. We don't do basic sense. */
926 ccw_device_accumulate_irb(cdev, irb);
Cornelia Huckb4f7b1e2006-06-29 15:03:35 +0200927 /* Remember to clear irb to avoid residuals. */
928 memset(&cdev->private->irb, 0, sizeof(struct irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 /* Try to start delayed device verification. */
930 ccw_device_online_verify(cdev, 0);
931 /* Note: Don't call handler for cio initiated clear! */
932}
933
934static void
935ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
936{
937 struct subchannel *sch;
938
939 sch = to_subchannel(cdev->dev.parent);
940 ccw_device_set_timeout(cdev, 0);
941 /* OK, i/o is dead now. Call interrupt handler. */
942 cdev->private->state = DEV_STATE_ONLINE;
943 if (cdev->handler)
944 cdev->handler(cdev, cdev->private->intparm,
945 ERR_PTR(-ETIMEDOUT));
946 if (!sch->lpm) {
947 PREPARE_WORK(&cdev->private->kick_work,
948 ccw_device_nopath_notify, (void *)cdev);
949 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
950 } else if (cdev->private->flags.doverify)
951 /* Start delayed path verification. */
952 ccw_device_online_verify(cdev, 0);
953}
954
955static void
956ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
957{
958 int ret;
959
960 ret = ccw_device_cancel_halt_clear(cdev);
961 if (ret == -EBUSY) {
962 ccw_device_set_timeout(cdev, 3*HZ);
963 return;
964 }
965 if (ret == -ENODEV) {
966 struct subchannel *sch;
967
968 sch = to_subchannel(cdev->dev.parent);
969 if (!sch->lpm) {
970 PREPARE_WORK(&cdev->private->kick_work,
971 ccw_device_nopath_notify, (void *)cdev);
972 queue_work(ccw_device_notify_work,
973 &cdev->private->kick_work);
974 } else
975 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
976 return;
977 }
978 //FIXME: Can we get here?
979 cdev->private->state = DEV_STATE_ONLINE;
980 if (cdev->handler)
981 cdev->handler(cdev, cdev->private->intparm,
982 ERR_PTR(-ETIMEDOUT));
983}
984
985static void
986ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
987{
988 struct irb *irb;
989 struct subchannel *sch;
990
991 irb = (struct irb *) __LC_IRB;
992 /*
993 * Accumulate status and find out if a basic sense is needed.
994 * This is fine since we have already adapted the lpm.
995 */
996 ccw_device_accumulate_irb(cdev, irb);
997 if (cdev->private->flags.dosense) {
998 if (ccw_device_do_sense(cdev, irb) == 0) {
999 cdev->private->state = DEV_STATE_W4SENSE;
1000 }
1001 return;
1002 }
1003
1004 /* Iff device is idle, reset timeout. */
1005 sch = to_subchannel(cdev->dev.parent);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001006 if (!stsch(sch->schid, &sch->schib))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 if (sch->schib.scsw.actl == 0)
1008 ccw_device_set_timeout(cdev, 0);
1009 /* Call the handler. */
1010 ccw_device_call_handler(cdev);
1011 if (!sch->lpm) {
1012 PREPARE_WORK(&cdev->private->kick_work,
1013 ccw_device_nopath_notify, (void *)cdev);
1014 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1015 } else if (cdev->private->flags.doverify)
1016 ccw_device_online_verify(cdev, 0);
1017}
1018
1019static void
1020ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1021{
1022 int ret;
1023 struct subchannel *sch;
1024
1025 sch = to_subchannel(cdev->dev.parent);
1026 ccw_device_set_timeout(cdev, 0);
1027 ret = ccw_device_cancel_halt_clear(cdev);
1028 if (ret == -EBUSY) {
1029 ccw_device_set_timeout(cdev, 3*HZ);
1030 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
1031 return;
1032 }
1033 if (ret == -ENODEV) {
1034 if (!sch->lpm) {
1035 PREPARE_WORK(&cdev->private->kick_work,
1036 ccw_device_nopath_notify, (void *)cdev);
1037 queue_work(ccw_device_notify_work,
1038 &cdev->private->kick_work);
1039 } else
1040 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1041 return;
1042 }
1043 if (cdev->handler)
1044 cdev->handler(cdev, cdev->private->intparm,
1045 ERR_PTR(-ETIMEDOUT));
1046 if (!sch->lpm) {
1047 PREPARE_WORK(&cdev->private->kick_work,
1048 ccw_device_nopath_notify, (void *)cdev);
1049 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1050 } else if (cdev->private->flags.doverify)
1051 /* Start delayed path verification. */
1052 ccw_device_online_verify(cdev, 0);
1053}
1054
1055static void
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001056ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057{
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001058 /* Start verification after current task finished. */
Cornelia Huck7e560812006-07-12 16:40:19 +02001059 cdev->private->flags.doverify = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
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. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001117 if (stsch(sch->schid, &sch->schib))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 return;
1119
1120 /*
1121 * The pim, pam, pom values may not be accurate, but they are the best
1122 * we have before performing device selection :/
1123 */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001124 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 /* Re-set some bits in the pmcw that were lost. */
1126 sch->schib.pmcw.isc = 3;
1127 sch->schib.pmcw.csense = 1;
1128 sch->schib.pmcw.ena = 0;
1129 if ((sch->lpm & (sch->lpm - 1)) != 0)
1130 sch->schib.pmcw.mp = 1;
1131 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1132 /* We should also udate ssd info, but this has to wait. */
1133 ccw_device_start_id(cdev, 0);
1134}
1135
1136static void
1137ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1138{
1139 struct subchannel *sch;
1140
1141 sch = to_subchannel(cdev->dev.parent);
1142 /*
1143 * An interrupt in state offline means a previous disable was not
1144 * successful. Try again.
1145 */
1146 cio_disable_subchannel(sch);
1147}
1148
1149static void
1150ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1151{
1152 retry_set_schib(cdev);
1153 cdev->private->state = DEV_STATE_ONLINE;
1154 dev_fsm_event(cdev, dev_event);
1155}
1156
Cornelia Huck94bb0632006-06-29 15:08:41 +02001157static void ccw_device_update_cmfblock(struct ccw_device *cdev,
1158 enum dev_event dev_event)
1159{
1160 cmf_retry_copy_block(cdev);
1161 cdev->private->state = DEV_STATE_ONLINE;
1162 dev_fsm_event(cdev, dev_event);
1163}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165static void
1166ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1167{
1168 ccw_device_set_timeout(cdev, 0);
1169 if (dev_event == DEV_EVENT_NOTOPER)
1170 cdev->private->state = DEV_STATE_NOT_OPER;
1171 else
1172 cdev->private->state = DEV_STATE_OFFLINE;
1173 wake_up(&cdev->private->wait_q);
1174}
1175
1176static void
1177ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1178{
1179 int ret;
1180
1181 ret = ccw_device_cancel_halt_clear(cdev);
1182 switch (ret) {
1183 case 0:
1184 cdev->private->state = DEV_STATE_OFFLINE;
1185 wake_up(&cdev->private->wait_q);
1186 break;
1187 case -ENODEV:
1188 cdev->private->state = DEV_STATE_NOT_OPER;
1189 wake_up(&cdev->private->wait_q);
1190 break;
1191 default:
1192 ccw_device_set_timeout(cdev, HZ/10);
1193 }
1194}
1195
1196/*
1197 * No operation action. This is used e.g. to ignore a timeout event in
1198 * state offline.
1199 */
1200static void
1201ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1202{
1203}
1204
1205/*
1206 * Bug operation action.
1207 */
1208static void
1209ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1210{
1211 printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1212 cdev->private->state, dev_event);
1213 BUG();
1214}
1215
1216/*
1217 * device statemachine
1218 */
1219fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1220 [DEV_STATE_NOT_OPER] = {
1221 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1222 [DEV_EVENT_INTERRUPT] = ccw_device_bug,
1223 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1224 [DEV_EVENT_VERIFY] = ccw_device_nop,
1225 },
1226 [DEV_STATE_SENSE_PGID] = {
1227 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1228 [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
1229 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1230 [DEV_EVENT_VERIFY] = ccw_device_nop,
1231 },
1232 [DEV_STATE_SENSE_ID] = {
1233 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1234 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1235 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1236 [DEV_EVENT_VERIFY] = ccw_device_nop,
1237 },
1238 [DEV_STATE_OFFLINE] = {
1239 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1240 [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
1241 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1242 [DEV_EVENT_VERIFY] = ccw_device_nop,
1243 },
1244 [DEV_STATE_VERIFY] = {
1245 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1246 [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
1247 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001248 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 },
1250 [DEV_STATE_ONLINE] = {
1251 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1252 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1253 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1254 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1255 },
1256 [DEV_STATE_W4SENSE] = {
1257 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1258 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1259 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1260 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1261 },
1262 [DEV_STATE_DISBAND_PGID] = {
1263 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1264 [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
1265 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1266 [DEV_EVENT_VERIFY] = ccw_device_nop,
1267 },
1268 [DEV_STATE_BOXED] = {
1269 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1270 [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
1271 [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
1272 [DEV_EVENT_VERIFY] = ccw_device_nop,
1273 },
1274 /* states to wait for i/o completion before doing something */
1275 [DEV_STATE_CLEAR_VERIFY] = {
1276 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1277 [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
1278 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1279 [DEV_EVENT_VERIFY] = ccw_device_nop,
1280 },
1281 [DEV_STATE_TIMEOUT_KILL] = {
1282 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1283 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1284 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1285 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1286 },
1287 [DEV_STATE_WAIT4IO] = {
1288 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1289 [DEV_EVENT_INTERRUPT] = ccw_device_wait4io_irq,
1290 [DEV_EVENT_TIMEOUT] = ccw_device_wait4io_timeout,
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001291 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 },
1293 [DEV_STATE_QUIESCE] = {
1294 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1295 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1296 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1297 [DEV_EVENT_VERIFY] = ccw_device_nop,
1298 },
1299 /* special states for devices gone not operational */
1300 [DEV_STATE_DISCONNECTED] = {
1301 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1302 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1303 [DEV_EVENT_TIMEOUT] = ccw_device_bug,
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001304 [DEV_EVENT_VERIFY] = ccw_device_start_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 },
1306 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1307 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1308 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1309 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1310 [DEV_EVENT_VERIFY] = ccw_device_nop,
1311 },
1312 [DEV_STATE_CMFCHANGE] = {
1313 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1314 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1315 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1316 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1317 },
Cornelia Huck94bb0632006-06-29 15:08:41 +02001318 [DEV_STATE_CMFUPDATE] = {
1319 [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
1320 [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
1321 [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
1322 [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
1323 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324};
1325
1326/*
1327 * io_subchannel_irq is called for "real" interrupts or for status
1328 * pending conditions on msch.
1329 */
1330void
1331io_subchannel_irq (struct device *pdev)
1332{
1333 struct ccw_device *cdev;
1334
1335 cdev = to_subchannel(pdev)->dev.driver_data;
1336
1337 CIO_TRACE_EVENT (3, "IRQ");
1338 CIO_TRACE_EVENT (3, pdev->bus_id);
1339 if (cdev)
1340 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1341}
1342
1343EXPORT_SYMBOL_GPL(ccw_device_set_timeout);