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