blob: 392eb33f3a9ce664a519a8c01cf55e232f5dfcc8 [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 ||
Cornelia Huck78964262006-10-11 15:31:38 +0200186 cdev->private->dev_id.devno != sch->schib.pmcw.dev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 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 "
Cornelia Huck78964262006-10-11 15:31:38 +0200258 "0.%x.%04x\n", cdev->private->dev_id.devno,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800259 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",
Cornelia Huck78964262006-10-11 15:31:38 +0200285 cdev->private->dev_id.ssid,
286 cdev->private->dev_id.devno,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 cdev->id.cu_type, cdev->id.cu_model,
288 cdev->id.dev_type, cdev->id.dev_model);
289 break;
290 case DEV_STATE_BOXED:
291 CIO_DEBUG(KERN_WARNING, 2,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800292 "SenseID : boxed device %04x on subchannel "
Cornelia Huck78964262006-10-11 15:31:38 +0200293 "0.%x.%04x\n", cdev->private->dev_id.devno,
Cornelia Huckfb6958a2006-01-06 00:19:25 -0800294 sch->schid.ssid, sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 break;
296 }
297 cdev->private->state = state;
298 io_subchannel_recog_done(cdev);
299 if (state != DEV_STATE_NOT_OPER)
300 wake_up(&cdev->private->wait_q);
301}
302
303/*
304 * Function called from device_id.c after sense id has completed.
305 */
306void
307ccw_device_sense_id_done(struct ccw_device *cdev, int err)
308{
309 switch (err) {
310 case 0:
311 ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
312 break;
313 case -ETIME: /* Sense id stopped by timeout. */
314 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
315 break;
316 default:
317 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
318 break;
319 }
320}
321
322static void
323ccw_device_oper_notify(void *data)
324{
325 struct ccw_device *cdev;
326 struct subchannel *sch;
327 int ret;
328
329 cdev = (struct ccw_device *)data;
330 sch = to_subchannel(cdev->dev.parent);
331 ret = (sch->driver && sch->driver->notify) ?
332 sch->driver->notify(&sch->dev, CIO_OPER) : 0;
333 if (!ret)
334 /* Driver doesn't want device back. */
335 ccw_device_do_unreg_rereg((void *)cdev);
Cornelia Huck94bb0632006-06-29 15:08:41 +0200336 else {
337 /* Reenable channel measurements, if needed. */
338 cmf_reenable(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 wake_up(&cdev->private->wait_q);
Cornelia Huck94bb0632006-06-29 15:08:41 +0200340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
343/*
344 * Finished with online/offline processing.
345 */
346static void
347ccw_device_done(struct ccw_device *cdev, int state)
348{
349 struct subchannel *sch;
350
351 sch = to_subchannel(cdev->dev.parent);
352
Cornelia Huckf1ee3282006-10-04 20:02:02 +0200353 ccw_device_set_timeout(cdev, 0);
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 if (state != DEV_STATE_ONLINE)
356 cio_disable_subchannel(sch);
357
358 /* Reset device status. */
359 memset(&cdev->private->irb, 0, sizeof(struct irb));
360
361 cdev->private->state = state;
362
363
364 if (state == DEV_STATE_BOXED)
365 CIO_DEBUG(KERN_WARNING, 2,
366 "Boxed device %04x on subchannel %04x\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200367 cdev->private->dev_id.devno, sch->schid.sch_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 if (cdev->private->flags.donotify) {
370 cdev->private->flags.donotify = 0;
371 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,
372 (void *)cdev);
373 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
374 }
375 wake_up(&cdev->private->wait_q);
376
377 if (css_init_done && state != DEV_STATE_ONLINE)
378 put_device (&cdev->dev);
379}
380
Cornelia Huck7e560812006-07-12 16:40:19 +0200381static inline int cmp_pgid(struct pgid *p1, struct pgid *p2)
382{
383 char *c1;
384 char *c2;
385
386 c1 = (char *)p1;
387 c2 = (char *)p2;
388
389 return memcmp(c1 + 1, c2 + 1, sizeof(struct pgid) - 1);
390}
391
392static void __ccw_device_get_common_pgid(struct ccw_device *cdev)
393{
394 int i;
395 int last;
396
397 last = 0;
398 for (i = 0; i < 8; i++) {
399 if (cdev->private->pgid[i].inf.ps.state1 == SNID_STATE1_RESET)
400 /* No PGID yet */
401 continue;
402 if (cdev->private->pgid[last].inf.ps.state1 ==
403 SNID_STATE1_RESET) {
404 /* First non-zero PGID */
405 last = i;
406 continue;
407 }
408 if (cmp_pgid(&cdev->private->pgid[i],
409 &cdev->private->pgid[last]) == 0)
410 /* Non-conflicting PGIDs */
411 continue;
412
413 /* PGID mismatch, can't pathgroup. */
414 CIO_MSG_EVENT(0, "SNID - pgid mismatch for device "
415 "0.%x.%04x, can't pathgroup\n",
Cornelia Huck78964262006-10-11 15:31:38 +0200416 cdev->private->dev_id.ssid,
417 cdev->private->dev_id.devno);
Cornelia Huck7e560812006-07-12 16:40:19 +0200418 cdev->private->options.pgroup = 0;
419 return;
420 }
421 if (cdev->private->pgid[last].inf.ps.state1 ==
422 SNID_STATE1_RESET)
423 /* No previous pgid found */
424 memcpy(&cdev->private->pgid[0], &css[0]->global_pgid,
425 sizeof(struct pgid));
426 else
427 /* Use existing pgid */
428 memcpy(&cdev->private->pgid[0], &cdev->private->pgid[last],
429 sizeof(struct pgid));
430}
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432/*
433 * Function called from device_pgid.c after sense path ground has completed.
434 */
435void
436ccw_device_sense_pgid_done(struct ccw_device *cdev, int err)
437{
438 struct subchannel *sch;
439
440 sch = to_subchannel(cdev->dev.parent);
441 switch (err) {
Cornelia Huck7e560812006-07-12 16:40:19 +0200442 case -EOPNOTSUPP: /* path grouping not supported, use nop instead. */
443 cdev->private->options.pgroup = 0;
444 break;
445 case 0: /* success */
446 case -EACCES: /* partial success, some paths not operational */
447 /* Check if all pgids are equal or 0. */
448 __ccw_device_get_common_pgid(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 break;
450 case -ETIME: /* Sense path group id stopped by timeout. */
451 case -EUSERS: /* device is reserved for someone else. */
452 ccw_device_done(cdev, DEV_STATE_BOXED);
Cornelia Huck7e560812006-07-12 16:40:19 +0200453 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 default:
455 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
Cornelia Huck7e560812006-07-12 16:40:19 +0200456 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
Cornelia Huck7e560812006-07-12 16:40:19 +0200458 /* Start Path Group verification. */
Cornelia Huck7e560812006-07-12 16:40:19 +0200459 cdev->private->state = DEV_STATE_VERIFY;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200460 cdev->private->flags.doverify = 0;
Cornelia Huck7e560812006-07-12 16:40:19 +0200461 ccw_device_verify_start(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
464/*
465 * Start device recognition.
466 */
467int
468ccw_device_recognition(struct ccw_device *cdev)
469{
470 struct subchannel *sch;
471 int ret;
472
473 if ((cdev->private->state != DEV_STATE_NOT_OPER) &&
474 (cdev->private->state != DEV_STATE_BOXED))
475 return -EINVAL;
476 sch = to_subchannel(cdev->dev.parent);
477 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
478 if (ret != 0)
479 /* Couldn't enable the subchannel for i/o. Sick device. */
480 return ret;
481
482 /* After 60s the device recognition is considered to have failed. */
483 ccw_device_set_timeout(cdev, 60*HZ);
484
485 /*
486 * We used to start here with a sense pgid to find out whether a device
487 * is locked by someone else. Unfortunately, the sense pgid command
488 * code has other meanings on devices predating the path grouping
489 * algorithm, so we start with sense id and box the device after an
490 * timeout (or if sense pgid during path verification detects the device
491 * is locked, as may happen on newer devices).
492 */
493 cdev->private->flags.recog_done = 0;
494 cdev->private->state = DEV_STATE_SENSE_ID;
495 ccw_device_sense_id_start(cdev);
496 return 0;
497}
498
499/*
500 * Handle timeout in device recognition.
501 */
502static void
503ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
504{
505 int ret;
506
507 ret = ccw_device_cancel_halt_clear(cdev);
508 switch (ret) {
509 case 0:
510 ccw_device_recog_done(cdev, DEV_STATE_BOXED);
511 break;
512 case -ENODEV:
513 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
514 break;
515 default:
516 ccw_device_set_timeout(cdev, 3*HZ);
517 }
518}
519
520
521static void
522ccw_device_nopath_notify(void *data)
523{
524 struct ccw_device *cdev;
525 struct subchannel *sch;
526 int ret;
527
528 cdev = (struct ccw_device *)data;
529 sch = to_subchannel(cdev->dev.parent);
530 /* Extra sanity. */
531 if (sch->lpm)
532 return;
533 ret = (sch->driver && sch->driver->notify) ?
534 sch->driver->notify(&sch->dev, CIO_NO_PATH) : 0;
535 if (!ret) {
536 if (get_device(&sch->dev)) {
537 /* Driver doesn't want to keep device. */
538 cio_disable_subchannel(sch);
539 if (get_device(&cdev->dev)) {
540 PREPARE_WORK(&cdev->private->kick_work,
541 ccw_device_call_sch_unregister,
542 (void *)cdev);
543 queue_work(ccw_device_work,
544 &cdev->private->kick_work);
545 } else
546 put_device(&sch->dev);
547 }
548 } else {
549 cio_disable_subchannel(sch);
550 ccw_device_set_timeout(cdev, 0);
551 cdev->private->flags.fake_irb = 0;
552 cdev->private->state = DEV_STATE_DISCONNECTED;
553 wake_up(&cdev->private->wait_q);
554 }
555}
556
557void
558ccw_device_verify_done(struct ccw_device *cdev, int err)
559{
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200560 struct subchannel *sch;
561
562 sch = to_subchannel(cdev->dev.parent);
563 /* Update schib - pom may have changed. */
564 stsch(sch->schid, &sch->schib);
565 /* Update lpm with verified path mask. */
566 sch->lpm = sch->vpm;
567 /* Repeat path verification? */
568 if (cdev->private->flags.doverify) {
569 cdev->private->flags.doverify = 0;
570 ccw_device_verify_start(cdev);
571 return;
572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 switch (err) {
574 case -EOPNOTSUPP: /* path grouping not supported, just set online. */
575 cdev->private->options.pgroup = 0;
576 case 0:
577 ccw_device_done(cdev, DEV_STATE_ONLINE);
578 /* Deliver fake irb to device driver, if needed. */
579 if (cdev->private->flags.fake_irb) {
580 memset(&cdev->private->irb, 0, sizeof(struct irb));
Heiko Carstens292888c2006-08-30 14:33:35 +0200581 cdev->private->irb.scsw.cc = 1;
582 cdev->private->irb.scsw.fctl = SCSW_FCTL_START_FUNC;
583 cdev->private->irb.scsw.actl = SCSW_ACTL_START_PEND;
584 cdev->private->irb.scsw.stctl = SCSW_STCTL_STATUS_PEND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 cdev->private->flags.fake_irb = 0;
586 if (cdev->handler)
587 cdev->handler(cdev, cdev->private->intparm,
588 &cdev->private->irb);
589 memset(&cdev->private->irb, 0, sizeof(struct irb));
590 }
591 break;
592 case -ETIME:
593 ccw_device_done(cdev, DEV_STATE_BOXED);
594 break;
595 default:
596 PREPARE_WORK(&cdev->private->kick_work,
597 ccw_device_nopath_notify, (void *)cdev);
598 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
599 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
600 break;
601 }
602}
603
604/*
605 * Get device online.
606 */
607int
608ccw_device_online(struct ccw_device *cdev)
609{
610 struct subchannel *sch;
611 int ret;
612
613 if ((cdev->private->state != DEV_STATE_OFFLINE) &&
614 (cdev->private->state != DEV_STATE_BOXED))
615 return -EINVAL;
616 sch = to_subchannel(cdev->dev.parent);
617 if (css_init_done && !get_device(&cdev->dev))
618 return -ENODEV;
619 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);
620 if (ret != 0) {
621 /* Couldn't enable the subchannel for i/o. Sick device. */
622 if (ret == -ENODEV)
623 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
624 return ret;
625 }
626 /* Do we want to do path grouping? */
627 if (!cdev->private->options.pgroup) {
Cornelia Huck7e560812006-07-12 16:40:19 +0200628 /* Start initial path verification. */
629 cdev->private->state = DEV_STATE_VERIFY;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200630 cdev->private->flags.doverify = 0;
Cornelia Huck7e560812006-07-12 16:40:19 +0200631 ccw_device_verify_start(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 return 0;
633 }
634 /* Do a SensePGID first. */
635 cdev->private->state = DEV_STATE_SENSE_PGID;
636 ccw_device_sense_pgid_start(cdev);
637 return 0;
638}
639
640void
641ccw_device_disband_done(struct ccw_device *cdev, int err)
642{
643 switch (err) {
644 case 0:
645 ccw_device_done(cdev, DEV_STATE_OFFLINE);
646 break;
647 case -ETIME:
648 ccw_device_done(cdev, DEV_STATE_BOXED);
649 break;
650 default:
651 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
652 break;
653 }
654}
655
656/*
657 * Shutdown device.
658 */
659int
660ccw_device_offline(struct ccw_device *cdev)
661{
662 struct subchannel *sch;
663
664 sch = to_subchannel(cdev->dev.parent);
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800665 if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 return -ENODEV;
667 if (cdev->private->state != DEV_STATE_ONLINE) {
668 if (sch->schib.scsw.actl != 0)
669 return -EBUSY;
670 return -EINVAL;
671 }
672 if (sch->schib.scsw.actl != 0)
673 return -EBUSY;
674 /* Are we doing path grouping? */
675 if (!cdev->private->options.pgroup) {
676 /* No, set state offline immediately. */
677 ccw_device_done(cdev, DEV_STATE_OFFLINE);
678 return 0;
679 }
680 /* Start Set Path Group commands. */
681 cdev->private->state = DEV_STATE_DISBAND_PGID;
682 ccw_device_disband_start(cdev);
683 return 0;
684}
685
686/*
687 * Handle timeout in device online/offline process.
688 */
689static void
690ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event)
691{
692 int ret;
693
694 ret = ccw_device_cancel_halt_clear(cdev);
695 switch (ret) {
696 case 0:
697 ccw_device_done(cdev, DEV_STATE_BOXED);
698 break;
699 case -ENODEV:
700 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
701 break;
702 default:
703 ccw_device_set_timeout(cdev, 3*HZ);
704 }
705}
706
707/*
708 * Handle not oper event in device recognition.
709 */
710static void
711ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event)
712{
713 ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
714}
715
716/*
717 * Handle not operational event while offline.
718 */
719static void
720ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
721{
722 struct subchannel *sch;
723
724 cdev->private->state = DEV_STATE_NOT_OPER;
725 sch = to_subchannel(cdev->dev.parent);
726 if (get_device(&cdev->dev)) {
727 PREPARE_WORK(&cdev->private->kick_work,
728 ccw_device_call_sch_unregister, (void *)cdev);
729 queue_work(ccw_device_work, &cdev->private->kick_work);
730 }
731 wake_up(&cdev->private->wait_q);
732}
733
734/*
735 * Handle not operational event while online.
736 */
737static void
738ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
739{
740 struct subchannel *sch;
741
742 sch = to_subchannel(cdev->dev.parent);
743 if (sch->driver->notify &&
744 sch->driver->notify(&sch->dev, sch->lpm ? CIO_GONE : CIO_NO_PATH)) {
745 ccw_device_set_timeout(cdev, 0);
746 cdev->private->flags.fake_irb = 0;
747 cdev->private->state = DEV_STATE_DISCONNECTED;
748 wake_up(&cdev->private->wait_q);
749 return;
750 }
751 cdev->private->state = DEV_STATE_NOT_OPER;
752 cio_disable_subchannel(sch);
753 if (sch->schib.scsw.actl != 0) {
754 // FIXME: not-oper indication to device driver ?
755 ccw_device_call_handler(cdev);
756 }
757 if (get_device(&cdev->dev)) {
758 PREPARE_WORK(&cdev->private->kick_work,
759 ccw_device_call_sch_unregister, (void *)cdev);
760 queue_work(ccw_device_work, &cdev->private->kick_work);
761 }
762 wake_up(&cdev->private->wait_q);
763}
764
765/*
766 * Handle path verification event.
767 */
768static void
769ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
770{
771 struct subchannel *sch;
772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 if (cdev->private->state == DEV_STATE_W4SENSE) {
774 cdev->private->flags.doverify = 1;
775 return;
776 }
777 sch = to_subchannel(cdev->dev.parent);
778 /*
779 * Since we might not just be coming from an interrupt from the
780 * subchannel we have to update the schib.
781 */
Cornelia Hucka8237fc2006-01-06 00:19:21 -0800782 stsch(sch->schid, &sch->schib);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
784 if (sch->schib.scsw.actl != 0 ||
Peter Oberparleiter65200c22006-08-07 17:00:33 +0200785 (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) {
787 /*
788 * No final status yet or final status not yet delivered
789 * to the device driver. Can't do path verfication now,
790 * delay until final status was delivered.
791 */
792 cdev->private->flags.doverify = 1;
793 return;
794 }
795 /* Device is idle, we can do the path verification. */
796 cdev->private->state = DEV_STATE_VERIFY;
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +0200797 cdev->private->flags.doverify = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 ccw_device_verify_start(cdev);
799}
800
801/*
802 * Got an interrupt for a normal io (state online).
803 */
804static void
805ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
806{
807 struct irb *irb;
808
809 irb = (struct irb *) __LC_IRB;
810 /* Check for unsolicited interrupt. */
811 if ((irb->scsw.stctl ==
812 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS))
813 && (!irb->scsw.cc)) {
814 if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) &&
815 !irb->esw.esw0.erw.cons) {
816 /* Unit check but no sense data. Need basic sense. */
817 if (ccw_device_do_sense(cdev, irb) != 0)
818 goto call_handler_unsol;
Cornelia Hucke0ec5742006-06-04 02:51:27 -0700819 memcpy(&cdev->private->irb, irb, sizeof(struct irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 cdev->private->state = DEV_STATE_W4SENSE;
821 cdev->private->intparm = 0;
822 return;
823 }
824call_handler_unsol:
825 if (cdev->handler)
826 cdev->handler (cdev, 0, irb);
827 return;
828 }
829 /* Accumulate status and find out if a basic sense is needed. */
830 ccw_device_accumulate_irb(cdev, irb);
831 if (cdev->private->flags.dosense) {
832 if (ccw_device_do_sense(cdev, irb) == 0) {
833 cdev->private->state = DEV_STATE_W4SENSE;
834 }
835 return;
836 }
837 /* Call the handler. */
838 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
839 /* Start delayed path verification. */
840 ccw_device_online_verify(cdev, 0);
841}
842
843/*
844 * Got an timeout in online state.
845 */
846static void
847ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
848{
849 int ret;
850
851 ccw_device_set_timeout(cdev, 0);
852 ret = ccw_device_cancel_halt_clear(cdev);
853 if (ret == -EBUSY) {
854 ccw_device_set_timeout(cdev, 3*HZ);
855 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
856 return;
857 }
858 if (ret == -ENODEV) {
859 struct subchannel *sch;
860
861 sch = to_subchannel(cdev->dev.parent);
862 if (!sch->lpm) {
863 PREPARE_WORK(&cdev->private->kick_work,
864 ccw_device_nopath_notify, (void *)cdev);
865 queue_work(ccw_device_notify_work,
866 &cdev->private->kick_work);
867 } else
868 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
869 } else if (cdev->handler)
870 cdev->handler(cdev, cdev->private->intparm,
871 ERR_PTR(-ETIMEDOUT));
872}
873
874/*
875 * Got an interrupt for a basic sense.
876 */
877void
878ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
879{
880 struct irb *irb;
881
882 irb = (struct irb *) __LC_IRB;
883 /* Check for unsolicited interrupt. */
884 if (irb->scsw.stctl ==
885 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
886 if (irb->scsw.cc == 1)
887 /* Basic sense hasn't started. Try again. */
888 ccw_device_do_sense(cdev, irb);
889 else {
Cornelia Huck08983782006-10-11 15:31:30 +0200890 printk(KERN_INFO "Huh? %s(%s): unsolicited "
891 "interrupt...\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 __FUNCTION__, cdev->dev.bus_id);
893 if (cdev->handler)
894 cdev->handler (cdev, 0, irb);
895 }
896 return;
897 }
Cornelia Huck3ba19982006-03-24 03:15:12 -0800898 /*
899 * Check if a halt or clear has been issued in the meanwhile. If yes,
900 * only deliver the halt/clear interrupt to the device driver as if it
901 * had killed the original request.
902 */
903 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
904 cdev->private->flags.dosense = 0;
905 memset(&cdev->private->irb, 0, sizeof(struct irb));
906 ccw_device_accumulate_irb(cdev, irb);
907 goto call_handler;
908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 /* Add basic sense info to irb. */
910 ccw_device_accumulate_basic_sense(cdev, irb);
911 if (cdev->private->flags.dosense) {
912 /* Another basic sense is needed. */
913 ccw_device_do_sense(cdev, irb);
914 return;
915 }
Cornelia Huck3ba19982006-03-24 03:15:12 -0800916call_handler:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 cdev->private->state = DEV_STATE_ONLINE;
918 /* Call the handler. */
919 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
920 /* Start delayed path verification. */
921 ccw_device_online_verify(cdev, 0);
922}
923
924static void
925ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event)
926{
927 struct irb *irb;
928
929 irb = (struct irb *) __LC_IRB;
930 /* Accumulate status. We don't do basic sense. */
931 ccw_device_accumulate_irb(cdev, irb);
Cornelia Huckb4f7b1e2006-06-29 15:03:35 +0200932 /* Remember to clear irb to avoid residuals. */
933 memset(&cdev->private->irb, 0, sizeof(struct irb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 /* Try to start delayed device verification. */
935 ccw_device_online_verify(cdev, 0);
936 /* Note: Don't call handler for cio initiated clear! */
937}
938
939static void
940ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
941{
942 struct subchannel *sch;
943
944 sch = to_subchannel(cdev->dev.parent);
945 ccw_device_set_timeout(cdev, 0);
946 /* OK, i/o is dead now. Call interrupt handler. */
947 cdev->private->state = DEV_STATE_ONLINE;
948 if (cdev->handler)
949 cdev->handler(cdev, cdev->private->intparm,
950 ERR_PTR(-ETIMEDOUT));
951 if (!sch->lpm) {
952 PREPARE_WORK(&cdev->private->kick_work,
953 ccw_device_nopath_notify, (void *)cdev);
954 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
955 } else if (cdev->private->flags.doverify)
956 /* Start delayed path verification. */
957 ccw_device_online_verify(cdev, 0);
958}
959
960static void
961ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
962{
963 int ret;
964
965 ret = ccw_device_cancel_halt_clear(cdev);
966 if (ret == -EBUSY) {
967 ccw_device_set_timeout(cdev, 3*HZ);
968 return;
969 }
970 if (ret == -ENODEV) {
971 struct subchannel *sch;
972
973 sch = to_subchannel(cdev->dev.parent);
974 if (!sch->lpm) {
975 PREPARE_WORK(&cdev->private->kick_work,
976 ccw_device_nopath_notify, (void *)cdev);
977 queue_work(ccw_device_notify_work,
978 &cdev->private->kick_work);
979 } else
980 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
981 return;
982 }
983 //FIXME: Can we get here?
984 cdev->private->state = DEV_STATE_ONLINE;
985 if (cdev->handler)
986 cdev->handler(cdev, cdev->private->intparm,
987 ERR_PTR(-ETIMEDOUT));
988}
989
990static void
991ccw_device_wait4io_irq(struct ccw_device *cdev, enum dev_event dev_event)
992{
993 struct irb *irb;
994 struct subchannel *sch;
995
996 irb = (struct irb *) __LC_IRB;
997 /*
998 * Accumulate status and find out if a basic sense is needed.
999 * This is fine since we have already adapted the lpm.
1000 */
1001 ccw_device_accumulate_irb(cdev, irb);
1002 if (cdev->private->flags.dosense) {
1003 if (ccw_device_do_sense(cdev, irb) == 0) {
1004 cdev->private->state = DEV_STATE_W4SENSE;
1005 }
1006 return;
1007 }
1008
1009 /* Iff device is idle, reset timeout. */
1010 sch = to_subchannel(cdev->dev.parent);
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001011 if (!stsch(sch->schid, &sch->schib))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 if (sch->schib.scsw.actl == 0)
1013 ccw_device_set_timeout(cdev, 0);
1014 /* Call the handler. */
1015 ccw_device_call_handler(cdev);
1016 if (!sch->lpm) {
1017 PREPARE_WORK(&cdev->private->kick_work,
1018 ccw_device_nopath_notify, (void *)cdev);
1019 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1020 } else if (cdev->private->flags.doverify)
1021 ccw_device_online_verify(cdev, 0);
1022}
1023
1024static void
1025ccw_device_wait4io_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1026{
1027 int ret;
1028 struct subchannel *sch;
1029
1030 sch = to_subchannel(cdev->dev.parent);
1031 ccw_device_set_timeout(cdev, 0);
1032 ret = ccw_device_cancel_halt_clear(cdev);
1033 if (ret == -EBUSY) {
1034 ccw_device_set_timeout(cdev, 3*HZ);
1035 cdev->private->state = DEV_STATE_TIMEOUT_KILL;
1036 return;
1037 }
1038 if (ret == -ENODEV) {
1039 if (!sch->lpm) {
1040 PREPARE_WORK(&cdev->private->kick_work,
1041 ccw_device_nopath_notify, (void *)cdev);
1042 queue_work(ccw_device_notify_work,
1043 &cdev->private->kick_work);
1044 } else
1045 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
1046 return;
1047 }
1048 if (cdev->handler)
1049 cdev->handler(cdev, cdev->private->intparm,
1050 ERR_PTR(-ETIMEDOUT));
1051 if (!sch->lpm) {
1052 PREPARE_WORK(&cdev->private->kick_work,
1053 ccw_device_nopath_notify, (void *)cdev);
1054 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1055 } else if (cdev->private->flags.doverify)
1056 /* Start delayed path verification. */
1057 ccw_device_online_verify(cdev, 0);
1058}
1059
1060static void
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001061ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001063 /* Start verification after current task finished. */
Cornelia Huck7e560812006-07-12 16:40:19 +02001064 cdev->private->flags.doverify = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
1067static void
1068ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event)
1069{
1070 struct irb *irb;
1071
1072 switch (dev_event) {
1073 case DEV_EVENT_INTERRUPT:
1074 irb = (struct irb *) __LC_IRB;
1075 /* Check for unsolicited interrupt. */
1076 if ((irb->scsw.stctl ==
1077 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) &&
1078 (!irb->scsw.cc))
1079 /* FIXME: we should restart stlck here, but this
1080 * is extremely unlikely ... */
1081 goto out_wakeup;
1082
1083 ccw_device_accumulate_irb(cdev, irb);
1084 /* We don't care about basic sense etc. */
1085 break;
1086 default: /* timeout */
1087 break;
1088 }
1089out_wakeup:
1090 wake_up(&cdev->private->wait_q);
1091}
1092
1093static void
1094ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
1095{
1096 struct subchannel *sch;
1097
1098 sch = to_subchannel(cdev->dev.parent);
1099 if (cio_enable_subchannel(sch, sch->schib.pmcw.isc) != 0)
1100 /* Couldn't enable the subchannel for i/o. Sick device. */
1101 return;
1102
1103 /* After 60s the device recognition is considered to have failed. */
1104 ccw_device_set_timeout(cdev, 60*HZ);
1105
1106 cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
1107 ccw_device_sense_id_start(cdev);
1108}
1109
1110void
1111device_trigger_reprobe(struct subchannel *sch)
1112{
1113 struct ccw_device *cdev;
1114
1115 if (!sch->dev.driver_data)
1116 return;
1117 cdev = sch->dev.driver_data;
1118 if (cdev->private->state != DEV_STATE_DISCONNECTED)
1119 return;
1120
1121 /* Update some values. */
Cornelia Hucka8237fc2006-01-06 00:19:21 -08001122 if (stsch(sch->schid, &sch->schib))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 return;
1124
1125 /*
1126 * The pim, pam, pom values may not be accurate, but they are the best
1127 * we have before performing device selection :/
1128 */
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001129 sch->lpm = sch->schib.pmcw.pam & sch->opm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 /* Re-set some bits in the pmcw that were lost. */
1131 sch->schib.pmcw.isc = 3;
1132 sch->schib.pmcw.csense = 1;
1133 sch->schib.pmcw.ena = 0;
1134 if ((sch->lpm & (sch->lpm - 1)) != 0)
1135 sch->schib.pmcw.mp = 1;
1136 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1137 /* We should also udate ssd info, but this has to wait. */
1138 ccw_device_start_id(cdev, 0);
1139}
1140
1141static void
1142ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event)
1143{
1144 struct subchannel *sch;
1145
1146 sch = to_subchannel(cdev->dev.parent);
1147 /*
1148 * An interrupt in state offline means a previous disable was not
1149 * successful. Try again.
1150 */
1151 cio_disable_subchannel(sch);
1152}
1153
1154static void
1155ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
1156{
1157 retry_set_schib(cdev);
1158 cdev->private->state = DEV_STATE_ONLINE;
1159 dev_fsm_event(cdev, dev_event);
1160}
1161
Cornelia Huck94bb0632006-06-29 15:08:41 +02001162static void ccw_device_update_cmfblock(struct ccw_device *cdev,
1163 enum dev_event dev_event)
1164{
1165 cmf_retry_copy_block(cdev);
1166 cdev->private->state = DEV_STATE_ONLINE;
1167 dev_fsm_event(cdev, dev_event);
1168}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170static void
1171ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
1172{
1173 ccw_device_set_timeout(cdev, 0);
1174 if (dev_event == DEV_EVENT_NOTOPER)
1175 cdev->private->state = DEV_STATE_NOT_OPER;
1176 else
1177 cdev->private->state = DEV_STATE_OFFLINE;
1178 wake_up(&cdev->private->wait_q);
1179}
1180
1181static void
1182ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
1183{
1184 int ret;
1185
1186 ret = ccw_device_cancel_halt_clear(cdev);
1187 switch (ret) {
1188 case 0:
1189 cdev->private->state = DEV_STATE_OFFLINE;
1190 wake_up(&cdev->private->wait_q);
1191 break;
1192 case -ENODEV:
1193 cdev->private->state = DEV_STATE_NOT_OPER;
1194 wake_up(&cdev->private->wait_q);
1195 break;
1196 default:
1197 ccw_device_set_timeout(cdev, HZ/10);
1198 }
1199}
1200
1201/*
1202 * No operation action. This is used e.g. to ignore a timeout event in
1203 * state offline.
1204 */
1205static void
1206ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
1207{
1208}
1209
1210/*
1211 * Bug operation action.
1212 */
1213static void
1214ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event)
1215{
1216 printk(KERN_EMERG "dev_jumptable[%i][%i] == NULL\n",
1217 cdev->private->state, dev_event);
1218 BUG();
1219}
1220
1221/*
1222 * device statemachine
1223 */
1224fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
1225 [DEV_STATE_NOT_OPER] = {
1226 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1227 [DEV_EVENT_INTERRUPT] = ccw_device_bug,
1228 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1229 [DEV_EVENT_VERIFY] = ccw_device_nop,
1230 },
1231 [DEV_STATE_SENSE_PGID] = {
1232 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1233 [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq,
1234 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1235 [DEV_EVENT_VERIFY] = ccw_device_nop,
1236 },
1237 [DEV_STATE_SENSE_ID] = {
1238 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1239 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1240 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1241 [DEV_EVENT_VERIFY] = ccw_device_nop,
1242 },
1243 [DEV_STATE_OFFLINE] = {
1244 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1245 [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq,
1246 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1247 [DEV_EVENT_VERIFY] = ccw_device_nop,
1248 },
1249 [DEV_STATE_VERIFY] = {
1250 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1251 [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq,
1252 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001253 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 },
1255 [DEV_STATE_ONLINE] = {
1256 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1257 [DEV_EVENT_INTERRUPT] = ccw_device_irq,
1258 [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout,
1259 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1260 },
1261 [DEV_STATE_W4SENSE] = {
1262 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1263 [DEV_EVENT_INTERRUPT] = ccw_device_w4sense,
1264 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1265 [DEV_EVENT_VERIFY] = ccw_device_online_verify,
1266 },
1267 [DEV_STATE_DISBAND_PGID] = {
1268 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1269 [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq,
1270 [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout,
1271 [DEV_EVENT_VERIFY] = ccw_device_nop,
1272 },
1273 [DEV_STATE_BOXED] = {
1274 [DEV_EVENT_NOTOPER] = ccw_device_offline_notoper,
1275 [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done,
1276 [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done,
1277 [DEV_EVENT_VERIFY] = ccw_device_nop,
1278 },
1279 /* states to wait for i/o completion before doing something */
1280 [DEV_STATE_CLEAR_VERIFY] = {
1281 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1282 [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify,
1283 [DEV_EVENT_TIMEOUT] = ccw_device_nop,
1284 [DEV_EVENT_VERIFY] = ccw_device_nop,
1285 },
1286 [DEV_STATE_TIMEOUT_KILL] = {
1287 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1288 [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq,
1289 [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout,
1290 [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME
1291 },
1292 [DEV_STATE_WAIT4IO] = {
1293 [DEV_EVENT_NOTOPER] = ccw_device_online_notoper,
1294 [DEV_EVENT_INTERRUPT] = ccw_device_wait4io_irq,
1295 [DEV_EVENT_TIMEOUT] = ccw_device_wait4io_timeout,
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001296 [DEV_EVENT_VERIFY] = ccw_device_delay_verify,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 },
1298 [DEV_STATE_QUIESCE] = {
1299 [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done,
1300 [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done,
1301 [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout,
1302 [DEV_EVENT_VERIFY] = ccw_device_nop,
1303 },
1304 /* special states for devices gone not operational */
1305 [DEV_STATE_DISCONNECTED] = {
1306 [DEV_EVENT_NOTOPER] = ccw_device_nop,
1307 [DEV_EVENT_INTERRUPT] = ccw_device_start_id,
1308 [DEV_EVENT_TIMEOUT] = ccw_device_bug,
Peter Oberparleiter28bdc6f2006-09-20 15:59:59 +02001309 [DEV_EVENT_VERIFY] = ccw_device_start_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 },
1311 [DEV_STATE_DISCONNECTED_SENSE_ID] = {
1312 [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper,
1313 [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq,
1314 [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout,
1315 [DEV_EVENT_VERIFY] = ccw_device_nop,
1316 },
1317 [DEV_STATE_CMFCHANGE] = {
1318 [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate,
1319 [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate,
1320 [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate,
1321 [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate,
1322 },
Cornelia Huck94bb0632006-06-29 15:08:41 +02001323 [DEV_STATE_CMFUPDATE] = {
1324 [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock,
1325 [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock,
1326 [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock,
1327 [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock,
1328 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329};
1330
1331/*
1332 * io_subchannel_irq is called for "real" interrupts or for status
1333 * pending conditions on msch.
1334 */
1335void
1336io_subchannel_irq (struct device *pdev)
1337{
1338 struct ccw_device *cdev;
1339
1340 cdev = to_subchannel(pdev)->dev.driver_data;
1341
1342 CIO_TRACE_EVENT (3, "IRQ");
1343 CIO_TRACE_EVENT (3, pdev->bus_id);
1344 if (cdev)
1345 dev_fsm_event(cdev, DEV_EVENT_INTERRUPT);
1346}
1347
1348EXPORT_SYMBOL_GPL(ccw_device_set_timeout);