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