]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * File...........: linux/drivers/s390/block/dasd.c | |
3 | * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com> | |
4 | * Horst Hummel <Horst.Hummel@de.ibm.com> | |
5 | * Carsten Otte <Cotte@de.ibm.com> | |
6 | * Martin Schwidefsky <schwidefsky@de.ibm.com> | |
7 | * Bugreports.to..: <Linux390@de.ibm.com> | |
d41dd122 | 8 | * Copyright IBM Corp. 1999, 2009 |
1da177e4 LT |
9 | */ |
10 | ||
fc19f381 SH |
11 | #define KMSG_COMPONENT "dasd" |
12 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
13 | ||
3283942b | 14 | #include <linux/kernel_stat.h> |
1da177e4 LT |
15 | #include <linux/kmod.h> |
16 | #include <linux/init.h> | |
17 | #include <linux/interrupt.h> | |
18 | #include <linux/ctype.h> | |
19 | #include <linux/major.h> | |
20 | #include <linux/slab.h> | |
21 | #include <linux/buffer_head.h> | |
a885c8c4 | 22 | #include <linux/hdreg.h> |
f3445a1a | 23 | #include <linux/async.h> |
9eb25122 | 24 | #include <linux/mutex.h> |
1da177e4 LT |
25 | |
26 | #include <asm/ccwdev.h> | |
27 | #include <asm/ebcdic.h> | |
28 | #include <asm/idals.h> | |
f3eb5384 | 29 | #include <asm/itcw.h> |
33b62a30 | 30 | #include <asm/diag.h> |
1da177e4 LT |
31 | |
32 | /* This is ugly... */ | |
33 | #define PRINTK_HEADER "dasd:" | |
34 | ||
35 | #include "dasd_int.h" | |
36 | /* | |
37 | * SECTION: Constant definitions to be used within this file | |
38 | */ | |
39 | #define DASD_CHANQ_MAX_SIZE 4 | |
40 | ||
1c1e093c SW |
41 | #define DASD_SLEEPON_START_TAG (void *) 1 |
42 | #define DASD_SLEEPON_END_TAG (void *) 2 | |
43 | ||
1da177e4 LT |
44 | /* |
45 | * SECTION: exported variables of dasd.c | |
46 | */ | |
47 | debug_info_t *dasd_debug_area; | |
48 | struct dasd_discipline *dasd_diag_discipline_pointer; | |
2b67fc46 | 49 | void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *); |
1da177e4 LT |
50 | |
51 | MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>"); | |
52 | MODULE_DESCRIPTION("Linux on S/390 DASD device driver," | |
53 | " Copyright 2000 IBM Corporation"); | |
54 | MODULE_SUPPORTED_DEVICE("dasd"); | |
1da177e4 LT |
55 | MODULE_LICENSE("GPL"); |
56 | ||
57 | /* | |
58 | * SECTION: prototypes for static functions of dasd.c | |
59 | */ | |
8e09f215 SW |
60 | static int dasd_alloc_queue(struct dasd_block *); |
61 | static void dasd_setup_queue(struct dasd_block *); | |
62 | static void dasd_free_queue(struct dasd_block *); | |
63 | static void dasd_flush_request_queue(struct dasd_block *); | |
64 | static int dasd_flush_block_queue(struct dasd_block *); | |
65 | static void dasd_device_tasklet(struct dasd_device *); | |
66 | static void dasd_block_tasklet(struct dasd_block *); | |
4927b3f7 | 67 | static void do_kick_device(struct work_struct *); |
d41dd122 | 68 | static void do_restore_device(struct work_struct *); |
501183f2 | 69 | static void do_reload_device(struct work_struct *); |
8e09f215 | 70 | static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *); |
48cae885 SW |
71 | static void dasd_device_timeout(unsigned long); |
72 | static void dasd_block_timeout(unsigned long); | |
eb6e199b | 73 | static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *); |
1da177e4 LT |
74 | |
75 | /* | |
76 | * SECTION: Operations on the device structure. | |
77 | */ | |
78 | static wait_queue_head_t dasd_init_waitq; | |
8f61701b | 79 | static wait_queue_head_t dasd_flush_wq; |
c80ee724 | 80 | static wait_queue_head_t generic_waitq; |
1da177e4 LT |
81 | |
82 | /* | |
83 | * Allocate memory for a new device structure. | |
84 | */ | |
8e09f215 | 85 | struct dasd_device *dasd_alloc_device(void) |
1da177e4 LT |
86 | { |
87 | struct dasd_device *device; | |
88 | ||
8e09f215 SW |
89 | device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC); |
90 | if (!device) | |
1da177e4 | 91 | return ERR_PTR(-ENOMEM); |
1da177e4 LT |
92 | |
93 | /* Get two pages for normal block device operations. */ | |
94 | device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1); | |
8e09f215 | 95 | if (!device->ccw_mem) { |
1da177e4 LT |
96 | kfree(device); |
97 | return ERR_PTR(-ENOMEM); | |
98 | } | |
99 | /* Get one page for error recovery. */ | |
100 | device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA); | |
8e09f215 | 101 | if (!device->erp_mem) { |
1da177e4 LT |
102 | free_pages((unsigned long) device->ccw_mem, 1); |
103 | kfree(device); | |
104 | return ERR_PTR(-ENOMEM); | |
105 | } | |
106 | ||
107 | dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2); | |
108 | dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE); | |
109 | spin_lock_init(&device->mem_lock); | |
8e09f215 | 110 | atomic_set(&device->tasklet_scheduled, 0); |
138c014d | 111 | tasklet_init(&device->tasklet, |
8e09f215 | 112 | (void (*)(unsigned long)) dasd_device_tasklet, |
1da177e4 LT |
113 | (unsigned long) device); |
114 | INIT_LIST_HEAD(&device->ccw_queue); | |
115 | init_timer(&device->timer); | |
48cae885 SW |
116 | device->timer.function = dasd_device_timeout; |
117 | device->timer.data = (unsigned long) device; | |
4927b3f7 | 118 | INIT_WORK(&device->kick_work, do_kick_device); |
d41dd122 | 119 | INIT_WORK(&device->restore_device, do_restore_device); |
501183f2 | 120 | INIT_WORK(&device->reload_device, do_reload_device); |
1da177e4 LT |
121 | device->state = DASD_STATE_NEW; |
122 | device->target = DASD_STATE_NEW; | |
9eb25122 | 123 | mutex_init(&device->state_mutex); |
1da177e4 LT |
124 | |
125 | return device; | |
126 | } | |
127 | ||
128 | /* | |
129 | * Free memory of a device structure. | |
130 | */ | |
8e09f215 | 131 | void dasd_free_device(struct dasd_device *device) |
1da177e4 | 132 | { |
17fd682e | 133 | kfree(device->private); |
1da177e4 LT |
134 | free_page((unsigned long) device->erp_mem); |
135 | free_pages((unsigned long) device->ccw_mem, 1); | |
136 | kfree(device); | |
137 | } | |
138 | ||
8e09f215 SW |
139 | /* |
140 | * Allocate memory for a new device structure. | |
141 | */ | |
142 | struct dasd_block *dasd_alloc_block(void) | |
143 | { | |
144 | struct dasd_block *block; | |
145 | ||
146 | block = kzalloc(sizeof(*block), GFP_ATOMIC); | |
147 | if (!block) | |
148 | return ERR_PTR(-ENOMEM); | |
149 | /* open_count = 0 means device online but not in use */ | |
150 | atomic_set(&block->open_count, -1); | |
151 | ||
152 | spin_lock_init(&block->request_queue_lock); | |
153 | atomic_set(&block->tasklet_scheduled, 0); | |
154 | tasklet_init(&block->tasklet, | |
155 | (void (*)(unsigned long)) dasd_block_tasklet, | |
156 | (unsigned long) block); | |
157 | INIT_LIST_HEAD(&block->ccw_queue); | |
158 | spin_lock_init(&block->queue_lock); | |
159 | init_timer(&block->timer); | |
48cae885 SW |
160 | block->timer.function = dasd_block_timeout; |
161 | block->timer.data = (unsigned long) block; | |
8e09f215 SW |
162 | |
163 | return block; | |
164 | } | |
165 | ||
166 | /* | |
167 | * Free memory of a device structure. | |
168 | */ | |
169 | void dasd_free_block(struct dasd_block *block) | |
170 | { | |
171 | kfree(block); | |
172 | } | |
173 | ||
1da177e4 LT |
174 | /* |
175 | * Make a new device known to the system. | |
176 | */ | |
8e09f215 | 177 | static int dasd_state_new_to_known(struct dasd_device *device) |
1da177e4 LT |
178 | { |
179 | int rc; | |
180 | ||
181 | /* | |
138c014d | 182 | * As long as the device is not in state DASD_STATE_NEW we want to |
1da177e4 LT |
183 | * keep the reference count > 0. |
184 | */ | |
185 | dasd_get_device(device); | |
186 | ||
8e09f215 SW |
187 | if (device->block) { |
188 | rc = dasd_alloc_queue(device->block); | |
189 | if (rc) { | |
190 | dasd_put_device(device); | |
191 | return rc; | |
192 | } | |
1da177e4 | 193 | } |
1da177e4 LT |
194 | device->state = DASD_STATE_KNOWN; |
195 | return 0; | |
196 | } | |
197 | ||
198 | /* | |
199 | * Let the system forget about a device. | |
200 | */ | |
8e09f215 | 201 | static int dasd_state_known_to_new(struct dasd_device *device) |
1da177e4 | 202 | { |
20c64468 SW |
203 | /* Disable extended error reporting for this device. */ |
204 | dasd_eer_disable(device); | |
1da177e4 | 205 | /* Forget the discipline information. */ |
8e09f215 SW |
206 | if (device->discipline) { |
207 | if (device->discipline->uncheck_device) | |
208 | device->discipline->uncheck_device(device); | |
aa88861f | 209 | module_put(device->discipline->owner); |
8e09f215 | 210 | } |
1da177e4 | 211 | device->discipline = NULL; |
aa88861f PO |
212 | if (device->base_discipline) |
213 | module_put(device->base_discipline->owner); | |
214 | device->base_discipline = NULL; | |
1da177e4 LT |
215 | device->state = DASD_STATE_NEW; |
216 | ||
8e09f215 SW |
217 | if (device->block) |
218 | dasd_free_queue(device->block); | |
1da177e4 LT |
219 | |
220 | /* Give up reference we took in dasd_state_new_to_known. */ | |
221 | dasd_put_device(device); | |
8f61701b | 222 | return 0; |
1da177e4 LT |
223 | } |
224 | ||
225 | /* | |
226 | * Request the irq line for the device. | |
227 | */ | |
8e09f215 | 228 | static int dasd_state_known_to_basic(struct dasd_device *device) |
1da177e4 LT |
229 | { |
230 | int rc; | |
231 | ||
232 | /* Allocate and register gendisk structure. */ | |
8e09f215 SW |
233 | if (device->block) { |
234 | rc = dasd_gendisk_alloc(device->block); | |
235 | if (rc) | |
236 | return rc; | |
237 | } | |
1da177e4 | 238 | /* register 'device' debug area, used for all DBF_DEV_XXX calls */ |
fc19f381 | 239 | device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1, |
8e09f215 | 240 | 8 * sizeof(long)); |
1da177e4 | 241 | debug_register_view(device->debug_area, &debug_sprintf_view); |
b0035f12 | 242 | debug_set_level(device->debug_area, DBF_WARNING); |
1da177e4 LT |
243 | DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created"); |
244 | ||
245 | device->state = DASD_STATE_BASIC; | |
246 | return 0; | |
247 | } | |
248 | ||
249 | /* | |
250 | * Release the irq line for the device. Terminate any running i/o. | |
251 | */ | |
8e09f215 | 252 | static int dasd_state_basic_to_known(struct dasd_device *device) |
1da177e4 | 253 | { |
8f61701b | 254 | int rc; |
8e09f215 SW |
255 | if (device->block) { |
256 | dasd_gendisk_free(device->block); | |
257 | dasd_block_clear_timer(device->block); | |
258 | } | |
259 | rc = dasd_flush_device_queue(device); | |
8f61701b HH |
260 | if (rc) |
261 | return rc; | |
8e09f215 | 262 | dasd_device_clear_timer(device); |
8f61701b | 263 | |
1da177e4 LT |
264 | DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device); |
265 | if (device->debug_area != NULL) { | |
266 | debug_unregister(device->debug_area); | |
267 | device->debug_area = NULL; | |
268 | } | |
269 | device->state = DASD_STATE_KNOWN; | |
8f61701b | 270 | return 0; |
1da177e4 LT |
271 | } |
272 | ||
273 | /* | |
274 | * Do the initial analysis. The do_analysis function may return | |
275 | * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC | |
276 | * until the discipline decides to continue the startup sequence | |
277 | * by calling the function dasd_change_state. The eckd disciplines | |
278 | * uses this to start a ccw that detects the format. The completion | |
279 | * interrupt for this detection ccw uses the kernel event daemon to | |
280 | * trigger the call to dasd_change_state. All this is done in the | |
281 | * discipline code, see dasd_eckd.c. | |
90f0094d HH |
282 | * After the analysis ccw is done (do_analysis returned 0) the block |
283 | * device is setup. | |
284 | * In case the analysis returns an error, the device setup is stopped | |
285 | * (a fake disk was already added to allow formatting). | |
1da177e4 | 286 | */ |
8e09f215 | 287 | static int dasd_state_basic_to_ready(struct dasd_device *device) |
1da177e4 LT |
288 | { |
289 | int rc; | |
8e09f215 | 290 | struct dasd_block *block; |
1da177e4 LT |
291 | |
292 | rc = 0; | |
8e09f215 | 293 | block = device->block; |
90f0094d | 294 | /* make disk known with correct capacity */ |
8e09f215 SW |
295 | if (block) { |
296 | if (block->base->discipline->do_analysis != NULL) | |
297 | rc = block->base->discipline->do_analysis(block); | |
298 | if (rc) { | |
299 | if (rc != -EAGAIN) | |
300 | device->state = DASD_STATE_UNFMT; | |
301 | return rc; | |
302 | } | |
303 | dasd_setup_queue(block); | |
304 | set_capacity(block->gdp, | |
305 | block->blocks << block->s2b_shift); | |
306 | device->state = DASD_STATE_READY; | |
307 | rc = dasd_scan_partitions(block); | |
308 | if (rc) | |
309 | device->state = DASD_STATE_BASIC; | |
310 | } else { | |
311 | device->state = DASD_STATE_READY; | |
312 | } | |
90f0094d | 313 | return rc; |
1da177e4 LT |
314 | } |
315 | ||
316 | /* | |
317 | * Remove device from block device layer. Destroy dirty buffers. | |
318 | * Forget format information. Check if the target level is basic | |
319 | * and if it is create fake disk for formatting. | |
320 | */ | |
8e09f215 | 321 | static int dasd_state_ready_to_basic(struct dasd_device *device) |
1da177e4 | 322 | { |
8f61701b HH |
323 | int rc; |
324 | ||
1da177e4 | 325 | device->state = DASD_STATE_BASIC; |
8e09f215 SW |
326 | if (device->block) { |
327 | struct dasd_block *block = device->block; | |
328 | rc = dasd_flush_block_queue(block); | |
329 | if (rc) { | |
330 | device->state = DASD_STATE_READY; | |
331 | return rc; | |
332 | } | |
8e09f215 | 333 | dasd_flush_request_queue(block); |
b695adfa | 334 | dasd_destroy_partitions(block); |
8e09f215 SW |
335 | block->blocks = 0; |
336 | block->bp_block = 0; | |
337 | block->s2b_shift = 0; | |
338 | } | |
8f61701b | 339 | return 0; |
1da177e4 LT |
340 | } |
341 | ||
90f0094d HH |
342 | /* |
343 | * Back to basic. | |
344 | */ | |
8e09f215 | 345 | static int dasd_state_unfmt_to_basic(struct dasd_device *device) |
90f0094d HH |
346 | { |
347 | device->state = DASD_STATE_BASIC; | |
8f61701b | 348 | return 0; |
90f0094d HH |
349 | } |
350 | ||
1da177e4 LT |
351 | /* |
352 | * Make the device online and schedule the bottom half to start | |
353 | * the requeueing of requests from the linux request queue to the | |
354 | * ccw queue. | |
355 | */ | |
8f61701b | 356 | static int |
1da177e4 LT |
357 | dasd_state_ready_to_online(struct dasd_device * device) |
358 | { | |
8e09f215 | 359 | int rc; |
1301809b SW |
360 | struct gendisk *disk; |
361 | struct disk_part_iter piter; | |
362 | struct hd_struct *part; | |
8e09f215 SW |
363 | |
364 | if (device->discipline->ready_to_online) { | |
365 | rc = device->discipline->ready_to_online(device); | |
366 | if (rc) | |
367 | return rc; | |
368 | } | |
1da177e4 | 369 | device->state = DASD_STATE_ONLINE; |
1301809b | 370 | if (device->block) { |
8e09f215 | 371 | dasd_schedule_block_bh(device->block); |
1301809b SW |
372 | disk = device->block->bdev->bd_disk; |
373 | disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); | |
374 | while ((part = disk_part_iter_next(&piter))) | |
375 | kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE); | |
376 | disk_part_iter_exit(&piter); | |
377 | } | |
1da177e4 LT |
378 | return 0; |
379 | } | |
380 | ||
381 | /* | |
382 | * Stop the requeueing of requests again. | |
383 | */ | |
8e09f215 | 384 | static int dasd_state_online_to_ready(struct dasd_device *device) |
1da177e4 | 385 | { |
8e09f215 | 386 | int rc; |
1301809b SW |
387 | struct gendisk *disk; |
388 | struct disk_part_iter piter; | |
389 | struct hd_struct *part; | |
8e09f215 SW |
390 | |
391 | if (device->discipline->online_to_ready) { | |
392 | rc = device->discipline->online_to_ready(device); | |
393 | if (rc) | |
394 | return rc; | |
395 | } | |
1da177e4 | 396 | device->state = DASD_STATE_READY; |
1301809b SW |
397 | if (device->block) { |
398 | disk = device->block->bdev->bd_disk; | |
399 | disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); | |
400 | while ((part = disk_part_iter_next(&piter))) | |
401 | kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE); | |
402 | disk_part_iter_exit(&piter); | |
403 | } | |
8f61701b | 404 | return 0; |
1da177e4 LT |
405 | } |
406 | ||
407 | /* | |
408 | * Device startup state changes. | |
409 | */ | |
8e09f215 | 410 | static int dasd_increase_state(struct dasd_device *device) |
1da177e4 LT |
411 | { |
412 | int rc; | |
413 | ||
414 | rc = 0; | |
415 | if (device->state == DASD_STATE_NEW && | |
416 | device->target >= DASD_STATE_KNOWN) | |
417 | rc = dasd_state_new_to_known(device); | |
418 | ||
419 | if (!rc && | |
420 | device->state == DASD_STATE_KNOWN && | |
421 | device->target >= DASD_STATE_BASIC) | |
422 | rc = dasd_state_known_to_basic(device); | |
423 | ||
424 | if (!rc && | |
425 | device->state == DASD_STATE_BASIC && | |
426 | device->target >= DASD_STATE_READY) | |
427 | rc = dasd_state_basic_to_ready(device); | |
428 | ||
39ccf95e HH |
429 | if (!rc && |
430 | device->state == DASD_STATE_UNFMT && | |
431 | device->target > DASD_STATE_UNFMT) | |
432 | rc = -EPERM; | |
433 | ||
1da177e4 LT |
434 | if (!rc && |
435 | device->state == DASD_STATE_READY && | |
436 | device->target >= DASD_STATE_ONLINE) | |
437 | rc = dasd_state_ready_to_online(device); | |
438 | ||
439 | return rc; | |
440 | } | |
441 | ||
442 | /* | |
443 | * Device shutdown state changes. | |
444 | */ | |
8e09f215 | 445 | static int dasd_decrease_state(struct dasd_device *device) |
1da177e4 | 446 | { |
8f61701b HH |
447 | int rc; |
448 | ||
449 | rc = 0; | |
1da177e4 LT |
450 | if (device->state == DASD_STATE_ONLINE && |
451 | device->target <= DASD_STATE_READY) | |
8f61701b | 452 | rc = dasd_state_online_to_ready(device); |
138c014d | 453 | |
8f61701b HH |
454 | if (!rc && |
455 | device->state == DASD_STATE_READY && | |
1da177e4 | 456 | device->target <= DASD_STATE_BASIC) |
8f61701b | 457 | rc = dasd_state_ready_to_basic(device); |
90f0094d | 458 | |
8f61701b HH |
459 | if (!rc && |
460 | device->state == DASD_STATE_UNFMT && | |
90f0094d | 461 | device->target <= DASD_STATE_BASIC) |
8f61701b | 462 | rc = dasd_state_unfmt_to_basic(device); |
90f0094d | 463 | |
8f61701b HH |
464 | if (!rc && |
465 | device->state == DASD_STATE_BASIC && | |
1da177e4 | 466 | device->target <= DASD_STATE_KNOWN) |
8f61701b | 467 | rc = dasd_state_basic_to_known(device); |
138c014d | 468 | |
8f61701b HH |
469 | if (!rc && |
470 | device->state == DASD_STATE_KNOWN && | |
1da177e4 | 471 | device->target <= DASD_STATE_NEW) |
8f61701b | 472 | rc = dasd_state_known_to_new(device); |
1da177e4 | 473 | |
8f61701b | 474 | return rc; |
1da177e4 LT |
475 | } |
476 | ||
477 | /* | |
478 | * This is the main startup/shutdown routine. | |
479 | */ | |
8e09f215 | 480 | static void dasd_change_state(struct dasd_device *device) |
1da177e4 | 481 | { |
181d9522 | 482 | int rc; |
1da177e4 LT |
483 | |
484 | if (device->state == device->target) | |
485 | /* Already where we want to go today... */ | |
486 | return; | |
487 | if (device->state < device->target) | |
488 | rc = dasd_increase_state(device); | |
489 | else | |
490 | rc = dasd_decrease_state(device); | |
181d9522 SO |
491 | if (rc == -EAGAIN) |
492 | return; | |
493 | if (rc) | |
494 | device->target = device->state; | |
1da177e4 | 495 | |
9eb25122 | 496 | if (device->state == device->target) |
1da177e4 | 497 | wake_up(&dasd_init_waitq); |
4dfd5c45 HH |
498 | |
499 | /* let user-space know that the device status changed */ | |
500 | kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE); | |
1da177e4 LT |
501 | } |
502 | ||
503 | /* | |
504 | * Kick starter for devices that did not complete the startup/shutdown | |
505 | * procedure or were sleeping because of a pending state. | |
506 | * dasd_kick_device will schedule a call do do_kick_device to the kernel | |
507 | * event daemon. | |
508 | */ | |
8e09f215 | 509 | static void do_kick_device(struct work_struct *work) |
1da177e4 | 510 | { |
4927b3f7 | 511 | struct dasd_device *device = container_of(work, struct dasd_device, kick_work); |
9eb25122 | 512 | mutex_lock(&device->state_mutex); |
1da177e4 | 513 | dasd_change_state(device); |
9eb25122 | 514 | mutex_unlock(&device->state_mutex); |
8e09f215 | 515 | dasd_schedule_device_bh(device); |
1da177e4 LT |
516 | dasd_put_device(device); |
517 | } | |
518 | ||
8e09f215 | 519 | void dasd_kick_device(struct dasd_device *device) |
1da177e4 LT |
520 | { |
521 | dasd_get_device(device); | |
522 | /* queue call to dasd_kick_device to the kernel event daemon. */ | |
523 | schedule_work(&device->kick_work); | |
524 | } | |
525 | ||
501183f2 SH |
526 | /* |
527 | * dasd_reload_device will schedule a call do do_reload_device to the kernel | |
528 | * event daemon. | |
529 | */ | |
530 | static void do_reload_device(struct work_struct *work) | |
531 | { | |
532 | struct dasd_device *device = container_of(work, struct dasd_device, | |
533 | reload_device); | |
534 | device->discipline->reload(device); | |
535 | dasd_put_device(device); | |
536 | } | |
537 | ||
538 | void dasd_reload_device(struct dasd_device *device) | |
539 | { | |
540 | dasd_get_device(device); | |
541 | /* queue call to dasd_reload_device to the kernel event daemon. */ | |
542 | schedule_work(&device->reload_device); | |
543 | } | |
544 | EXPORT_SYMBOL(dasd_reload_device); | |
545 | ||
d41dd122 SH |
546 | /* |
547 | * dasd_restore_device will schedule a call do do_restore_device to the kernel | |
548 | * event daemon. | |
549 | */ | |
550 | static void do_restore_device(struct work_struct *work) | |
551 | { | |
552 | struct dasd_device *device = container_of(work, struct dasd_device, | |
553 | restore_device); | |
554 | device->cdev->drv->restore(device->cdev); | |
555 | dasd_put_device(device); | |
556 | } | |
557 | ||
558 | void dasd_restore_device(struct dasd_device *device) | |
559 | { | |
560 | dasd_get_device(device); | |
561 | /* queue call to dasd_restore_device to the kernel event daemon. */ | |
562 | schedule_work(&device->restore_device); | |
563 | } | |
564 | ||
1da177e4 LT |
565 | /* |
566 | * Set the target state for a device and starts the state change. | |
567 | */ | |
8e09f215 | 568 | void dasd_set_target_state(struct dasd_device *device, int target) |
1da177e4 | 569 | { |
f3445a1a | 570 | dasd_get_device(device); |
9eb25122 | 571 | mutex_lock(&device->state_mutex); |
1da177e4 LT |
572 | /* If we are in probeonly mode stop at DASD_STATE_READY. */ |
573 | if (dasd_probeonly && target > DASD_STATE_READY) | |
574 | target = DASD_STATE_READY; | |
575 | if (device->target != target) { | |
9eb25122 | 576 | if (device->state == target) |
1da177e4 LT |
577 | wake_up(&dasd_init_waitq); |
578 | device->target = target; | |
579 | } | |
580 | if (device->state != device->target) | |
581 | dasd_change_state(device); | |
9eb25122 SH |
582 | mutex_unlock(&device->state_mutex); |
583 | dasd_put_device(device); | |
1da177e4 LT |
584 | } |
585 | ||
586 | /* | |
587 | * Enable devices with device numbers in [from..to]. | |
588 | */ | |
8e09f215 | 589 | static inline int _wait_for_device(struct dasd_device *device) |
1da177e4 LT |
590 | { |
591 | return (device->state == device->target); | |
592 | } | |
593 | ||
8e09f215 | 594 | void dasd_enable_device(struct dasd_device *device) |
1da177e4 LT |
595 | { |
596 | dasd_set_target_state(device, DASD_STATE_ONLINE); | |
597 | if (device->state <= DASD_STATE_KNOWN) | |
598 | /* No discipline for device found. */ | |
599 | dasd_set_target_state(device, DASD_STATE_NEW); | |
600 | /* Now wait for the devices to come up. */ | |
601 | wait_event(dasd_init_waitq, _wait_for_device(device)); | |
602 | } | |
603 | ||
604 | /* | |
605 | * SECTION: device operation (interrupt handler, start i/o, term i/o ...) | |
606 | */ | |
607 | #ifdef CONFIG_DASD_PROFILE | |
608 | ||
609 | struct dasd_profile_info_t dasd_global_profile; | |
610 | unsigned int dasd_profile_level = DASD_PROFILE_OFF; | |
611 | ||
612 | /* | |
613 | * Increments counter in global and local profiling structures. | |
614 | */ | |
8e09f215 | 615 | #define dasd_profile_counter(value, counter, block) \ |
1da177e4 LT |
616 | { \ |
617 | int index; \ | |
618 | for (index = 0; index < 31 && value >> (2+index); index++); \ | |
619 | dasd_global_profile.counter[index]++; \ | |
8e09f215 | 620 | block->profile.counter[index]++; \ |
1da177e4 LT |
621 | } |
622 | ||
623 | /* | |
624 | * Add profiling information for cqr before execution. | |
625 | */ | |
8e09f215 SW |
626 | static void dasd_profile_start(struct dasd_block *block, |
627 | struct dasd_ccw_req *cqr, | |
628 | struct request *req) | |
1da177e4 LT |
629 | { |
630 | struct list_head *l; | |
631 | unsigned int counter; | |
632 | ||
633 | if (dasd_profile_level != DASD_PROFILE_ON) | |
634 | return; | |
635 | ||
636 | /* count the length of the chanq for statistics */ | |
637 | counter = 0; | |
8e09f215 | 638 | list_for_each(l, &block->ccw_queue) |
1da177e4 LT |
639 | if (++counter >= 31) |
640 | break; | |
641 | dasd_global_profile.dasd_io_nr_req[counter]++; | |
8e09f215 | 642 | block->profile.dasd_io_nr_req[counter]++; |
1da177e4 LT |
643 | } |
644 | ||
645 | /* | |
646 | * Add profiling information for cqr after execution. | |
647 | */ | |
8e09f215 SW |
648 | static void dasd_profile_end(struct dasd_block *block, |
649 | struct dasd_ccw_req *cqr, | |
650 | struct request *req) | |
1da177e4 LT |
651 | { |
652 | long strtime, irqtime, endtime, tottime; /* in microseconds */ | |
653 | long tottimeps, sectors; | |
654 | ||
655 | if (dasd_profile_level != DASD_PROFILE_ON) | |
656 | return; | |
657 | ||
83096ebf | 658 | sectors = blk_rq_sectors(req); |
1da177e4 LT |
659 | if (!cqr->buildclk || !cqr->startclk || |
660 | !cqr->stopclk || !cqr->endclk || | |
661 | !sectors) | |
662 | return; | |
663 | ||
664 | strtime = ((cqr->startclk - cqr->buildclk) >> 12); | |
665 | irqtime = ((cqr->stopclk - cqr->startclk) >> 12); | |
666 | endtime = ((cqr->endclk - cqr->stopclk) >> 12); | |
667 | tottime = ((cqr->endclk - cqr->buildclk) >> 12); | |
668 | tottimeps = tottime / sectors; | |
669 | ||
670 | if (!dasd_global_profile.dasd_io_reqs) | |
671 | memset(&dasd_global_profile, 0, | |
8e09f215 | 672 | sizeof(struct dasd_profile_info_t)); |
1da177e4 LT |
673 | dasd_global_profile.dasd_io_reqs++; |
674 | dasd_global_profile.dasd_io_sects += sectors; | |
675 | ||
8e09f215 SW |
676 | if (!block->profile.dasd_io_reqs) |
677 | memset(&block->profile, 0, | |
678 | sizeof(struct dasd_profile_info_t)); | |
679 | block->profile.dasd_io_reqs++; | |
680 | block->profile.dasd_io_sects += sectors; | |
1da177e4 | 681 | |
8e09f215 SW |
682 | dasd_profile_counter(sectors, dasd_io_secs, block); |
683 | dasd_profile_counter(tottime, dasd_io_times, block); | |
684 | dasd_profile_counter(tottimeps, dasd_io_timps, block); | |
685 | dasd_profile_counter(strtime, dasd_io_time1, block); | |
686 | dasd_profile_counter(irqtime, dasd_io_time2, block); | |
687 | dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, block); | |
688 | dasd_profile_counter(endtime, dasd_io_time3, block); | |
1da177e4 LT |
689 | } |
690 | #else | |
8e09f215 SW |
691 | #define dasd_profile_start(block, cqr, req) do {} while (0) |
692 | #define dasd_profile_end(block, cqr, req) do {} while (0) | |
1da177e4 LT |
693 | #endif /* CONFIG_DASD_PROFILE */ |
694 | ||
695 | /* | |
696 | * Allocate memory for a channel program with 'cplength' channel | |
697 | * command words and 'datasize' additional space. There are two | |
698 | * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed | |
699 | * memory and 2) dasd_smalloc_request uses the static ccw memory | |
700 | * that gets allocated for each device. | |
701 | */ | |
68b781fe | 702 | struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength, |
8e09f215 SW |
703 | int datasize, |
704 | struct dasd_device *device) | |
1da177e4 LT |
705 | { |
706 | struct dasd_ccw_req *cqr; | |
707 | ||
708 | /* Sanity checks */ | |
68b781fe | 709 | BUG_ON(datasize > PAGE_SIZE || |
7ac1e877 | 710 | (cplength*sizeof(struct ccw1)) > PAGE_SIZE); |
1da177e4 | 711 | |
88abaab4 | 712 | cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC); |
1da177e4 LT |
713 | if (cqr == NULL) |
714 | return ERR_PTR(-ENOMEM); | |
1da177e4 LT |
715 | cqr->cpaddr = NULL; |
716 | if (cplength > 0) { | |
88abaab4 | 717 | cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1), |
1da177e4 LT |
718 | GFP_ATOMIC | GFP_DMA); |
719 | if (cqr->cpaddr == NULL) { | |
720 | kfree(cqr); | |
721 | return ERR_PTR(-ENOMEM); | |
722 | } | |
1da177e4 LT |
723 | } |
724 | cqr->data = NULL; | |
725 | if (datasize > 0) { | |
88abaab4 | 726 | cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA); |
1da177e4 | 727 | if (cqr->data == NULL) { |
17fd682e | 728 | kfree(cqr->cpaddr); |
1da177e4 LT |
729 | kfree(cqr); |
730 | return ERR_PTR(-ENOMEM); | |
731 | } | |
1da177e4 | 732 | } |
68b781fe | 733 | cqr->magic = magic; |
1da177e4 LT |
734 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
735 | dasd_get_device(device); | |
736 | return cqr; | |
737 | } | |
738 | ||
68b781fe | 739 | struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, |
8e09f215 SW |
740 | int datasize, |
741 | struct dasd_device *device) | |
1da177e4 LT |
742 | { |
743 | unsigned long flags; | |
744 | struct dasd_ccw_req *cqr; | |
745 | char *data; | |
746 | int size; | |
747 | ||
1da177e4 LT |
748 | size = (sizeof(struct dasd_ccw_req) + 7L) & -8L; |
749 | if (cplength > 0) | |
750 | size += cplength * sizeof(struct ccw1); | |
751 | if (datasize > 0) | |
752 | size += datasize; | |
753 | spin_lock_irqsave(&device->mem_lock, flags); | |
754 | cqr = (struct dasd_ccw_req *) | |
755 | dasd_alloc_chunk(&device->ccw_chunks, size); | |
756 | spin_unlock_irqrestore(&device->mem_lock, flags); | |
757 | if (cqr == NULL) | |
758 | return ERR_PTR(-ENOMEM); | |
759 | memset(cqr, 0, sizeof(struct dasd_ccw_req)); | |
760 | data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L); | |
761 | cqr->cpaddr = NULL; | |
762 | if (cplength > 0) { | |
763 | cqr->cpaddr = (struct ccw1 *) data; | |
764 | data += cplength*sizeof(struct ccw1); | |
765 | memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1)); | |
766 | } | |
767 | cqr->data = NULL; | |
768 | if (datasize > 0) { | |
769 | cqr->data = data; | |
770 | memset(cqr->data, 0, datasize); | |
771 | } | |
68b781fe | 772 | cqr->magic = magic; |
1da177e4 LT |
773 | set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags); |
774 | dasd_get_device(device); | |
775 | return cqr; | |
776 | } | |
777 | ||
778 | /* | |
779 | * Free memory of a channel program. This function needs to free all the | |
780 | * idal lists that might have been created by dasd_set_cda and the | |
781 | * struct dasd_ccw_req itself. | |
782 | */ | |
8e09f215 | 783 | void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device) |
1da177e4 | 784 | { |
347a8dc3 | 785 | #ifdef CONFIG_64BIT |
1da177e4 LT |
786 | struct ccw1 *ccw; |
787 | ||
788 | /* Clear any idals used for the request. */ | |
789 | ccw = cqr->cpaddr; | |
790 | do { | |
791 | clear_normalized_cda(ccw); | |
792 | } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC)); | |
793 | #endif | |
17fd682e JJ |
794 | kfree(cqr->cpaddr); |
795 | kfree(cqr->data); | |
1da177e4 LT |
796 | kfree(cqr); |
797 | dasd_put_device(device); | |
798 | } | |
799 | ||
8e09f215 | 800 | void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device) |
1da177e4 LT |
801 | { |
802 | unsigned long flags; | |
803 | ||
804 | spin_lock_irqsave(&device->mem_lock, flags); | |
805 | dasd_free_chunk(&device->ccw_chunks, cqr); | |
806 | spin_unlock_irqrestore(&device->mem_lock, flags); | |
807 | dasd_put_device(device); | |
808 | } | |
809 | ||
810 | /* | |
811 | * Check discipline magic in cqr. | |
812 | */ | |
8e09f215 | 813 | static inline int dasd_check_cqr(struct dasd_ccw_req *cqr) |
1da177e4 LT |
814 | { |
815 | struct dasd_device *device; | |
816 | ||
817 | if (cqr == NULL) | |
818 | return -EINVAL; | |
8e09f215 | 819 | device = cqr->startdev; |
1da177e4 | 820 | if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) { |
fc19f381 | 821 | DBF_DEV_EVENT(DBF_WARNING, device, |
1da177e4 LT |
822 | " dasd_ccw_req 0x%08x magic doesn't match" |
823 | " discipline 0x%08x", | |
824 | cqr->magic, | |
825 | *(unsigned int *) device->discipline->name); | |
826 | return -EINVAL; | |
827 | } | |
828 | return 0; | |
829 | } | |
830 | ||
831 | /* | |
832 | * Terminate the current i/o and set the request to clear_pending. | |
833 | * Timer keeps device runnig. | |
834 | * ccw_device_clear can fail if the i/o subsystem | |
835 | * is in a bad mood. | |
836 | */ | |
8e09f215 | 837 | int dasd_term_IO(struct dasd_ccw_req *cqr) |
1da177e4 LT |
838 | { |
839 | struct dasd_device *device; | |
840 | int retries, rc; | |
fc19f381 | 841 | char errorstring[ERRORLENGTH]; |
1da177e4 LT |
842 | |
843 | /* Check the cqr */ | |
844 | rc = dasd_check_cqr(cqr); | |
845 | if (rc) | |
846 | return rc; | |
847 | retries = 0; | |
8e09f215 | 848 | device = (struct dasd_device *) cqr->startdev; |
1da177e4 LT |
849 | while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) { |
850 | rc = ccw_device_clear(device->cdev, (long) cqr); | |
851 | switch (rc) { | |
852 | case 0: /* termination successful */ | |
c2ba444d | 853 | cqr->retries--; |
8e09f215 | 854 | cqr->status = DASD_CQR_CLEAR_PENDING; |
1da177e4 | 855 | cqr->stopclk = get_clock(); |
8f61701b | 856 | cqr->starttime = 0; |
1da177e4 LT |
857 | DBF_DEV_EVENT(DBF_DEBUG, device, |
858 | "terminate cqr %p successful", | |
859 | cqr); | |
860 | break; | |
861 | case -ENODEV: | |
862 | DBF_DEV_EVENT(DBF_ERR, device, "%s", | |
863 | "device gone, retry"); | |
864 | break; | |
865 | case -EIO: | |
866 | DBF_DEV_EVENT(DBF_ERR, device, "%s", | |
867 | "I/O error, retry"); | |
868 | break; | |
869 | case -EINVAL: | |
870 | case -EBUSY: | |
871 | DBF_DEV_EVENT(DBF_ERR, device, "%s", | |
872 | "device busy, retry later"); | |
873 | break; | |
874 | default: | |
fc19f381 SH |
875 | /* internal error 10 - unknown rc*/ |
876 | snprintf(errorstring, ERRORLENGTH, "10 %d", rc); | |
877 | dev_err(&device->cdev->dev, "An error occurred in the " | |
878 | "DASD device driver, reason=%s\n", errorstring); | |
1da177e4 LT |
879 | BUG(); |
880 | break; | |
881 | } | |
882 | retries++; | |
883 | } | |
8e09f215 | 884 | dasd_schedule_device_bh(device); |
1da177e4 LT |
885 | return rc; |
886 | } | |
887 | ||
888 | /* | |
889 | * Start the i/o. This start_IO can fail if the channel is really busy. | |
890 | * In that case set up a timer to start the request later. | |
891 | */ | |
8e09f215 | 892 | int dasd_start_IO(struct dasd_ccw_req *cqr) |
1da177e4 LT |
893 | { |
894 | struct dasd_device *device; | |
895 | int rc; | |
fc19f381 | 896 | char errorstring[ERRORLENGTH]; |
1da177e4 LT |
897 | |
898 | /* Check the cqr */ | |
899 | rc = dasd_check_cqr(cqr); | |
6cc7f168 SW |
900 | if (rc) { |
901 | cqr->intrc = rc; | |
1da177e4 | 902 | return rc; |
6cc7f168 | 903 | } |
8e09f215 | 904 | device = (struct dasd_device *) cqr->startdev; |
5a27e60d SW |
905 | if (((cqr->block && |
906 | test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) || | |
907 | test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) && | |
908 | !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) { | |
909 | DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p " | |
910 | "because of stolen lock", cqr); | |
911 | cqr->status = DASD_CQR_ERROR; | |
912 | cqr->intrc = -EPERM; | |
913 | return -EPERM; | |
914 | } | |
1da177e4 | 915 | if (cqr->retries < 0) { |
fc19f381 SH |
916 | /* internal error 14 - start_IO run out of retries */ |
917 | sprintf(errorstring, "14 %p", cqr); | |
918 | dev_err(&device->cdev->dev, "An error occurred in the DASD " | |
919 | "device driver, reason=%s\n", errorstring); | |
8e09f215 | 920 | cqr->status = DASD_CQR_ERROR; |
1da177e4 LT |
921 | return -EIO; |
922 | } | |
923 | cqr->startclk = get_clock(); | |
924 | cqr->starttime = jiffies; | |
925 | cqr->retries--; | |
a4d26c6a SW |
926 | if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) { |
927 | cqr->lpm &= device->path_data.opm; | |
928 | if (!cqr->lpm) | |
929 | cqr->lpm = device->path_data.opm; | |
930 | } | |
f3eb5384 SW |
931 | if (cqr->cpmode == 1) { |
932 | rc = ccw_device_tm_start(device->cdev, cqr->cpaddr, | |
933 | (long) cqr, cqr->lpm); | |
934 | } else { | |
935 | rc = ccw_device_start(device->cdev, cqr->cpaddr, | |
936 | (long) cqr, cqr->lpm, 0); | |
937 | } | |
1da177e4 LT |
938 | switch (rc) { |
939 | case 0: | |
940 | cqr->status = DASD_CQR_IN_IO; | |
1da177e4 LT |
941 | break; |
942 | case -EBUSY: | |
a4d26c6a | 943 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
1da177e4 LT |
944 | "start_IO: device busy, retry later"); |
945 | break; | |
946 | case -ETIMEDOUT: | |
a4d26c6a | 947 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
1da177e4 LT |
948 | "start_IO: request timeout, retry later"); |
949 | break; | |
950 | case -EACCES: | |
a4d26c6a SW |
951 | /* -EACCES indicates that the request used only a subset of the |
952 | * available paths and all these paths are gone. If the lpm of | |
953 | * this request was only a subset of the opm (e.g. the ppm) then | |
954 | * we just do a retry with all available paths. | |
955 | * If we already use the full opm, something is amiss, and we | |
956 | * need a full path verification. | |
1da177e4 | 957 | */ |
a4d26c6a SW |
958 | if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) { |
959 | DBF_DEV_EVENT(DBF_WARNING, device, | |
960 | "start_IO: selected paths gone (%x)", | |
961 | cqr->lpm); | |
962 | } else if (cqr->lpm != device->path_data.opm) { | |
963 | cqr->lpm = device->path_data.opm; | |
964 | DBF_DEV_EVENT(DBF_DEBUG, device, "%s", | |
965 | "start_IO: selected paths gone," | |
966 | " retry on all paths"); | |
967 | } else { | |
968 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", | |
969 | "start_IO: all paths in opm gone," | |
970 | " do path verification"); | |
971 | dasd_generic_last_path_gone(device); | |
972 | device->path_data.opm = 0; | |
973 | device->path_data.ppm = 0; | |
974 | device->path_data.npm = 0; | |
975 | device->path_data.tbvpm = | |
976 | ccw_device_get_path_mask(device->cdev); | |
977 | } | |
1da177e4 LT |
978 | break; |
979 | case -ENODEV: | |
a4d26c6a | 980 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
f3eb5384 SW |
981 | "start_IO: -ENODEV device gone, retry"); |
982 | break; | |
1da177e4 | 983 | case -EIO: |
a4d26c6a | 984 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
f3eb5384 | 985 | "start_IO: -EIO device gone, retry"); |
1da177e4 | 986 | break; |
d41dd122 SH |
987 | case -EINVAL: |
988 | /* most likely caused in power management context */ | |
a4d26c6a | 989 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
d41dd122 SH |
990 | "start_IO: -EINVAL device currently " |
991 | "not accessible"); | |
992 | break; | |
1da177e4 | 993 | default: |
fc19f381 SH |
994 | /* internal error 11 - unknown rc */ |
995 | snprintf(errorstring, ERRORLENGTH, "11 %d", rc); | |
996 | dev_err(&device->cdev->dev, | |
997 | "An error occurred in the DASD device driver, " | |
998 | "reason=%s\n", errorstring); | |
1da177e4 LT |
999 | BUG(); |
1000 | break; | |
1001 | } | |
6cc7f168 | 1002 | cqr->intrc = rc; |
1da177e4 LT |
1003 | return rc; |
1004 | } | |
1005 | ||
1006 | /* | |
1007 | * Timeout function for dasd devices. This is used for different purposes | |
1008 | * 1) missing interrupt handler for normal operation | |
1009 | * 2) delayed start of request where start_IO failed with -EBUSY | |
1010 | * 3) timeout for missing state change interrupts | |
1011 | * The head of the ccw queue will have status DASD_CQR_IN_IO for 1), | |
1012 | * DASD_CQR_QUEUED for 2) and 3). | |
1013 | */ | |
8e09f215 | 1014 | static void dasd_device_timeout(unsigned long ptr) |
1da177e4 LT |
1015 | { |
1016 | unsigned long flags; | |
1017 | struct dasd_device *device; | |
1018 | ||
1019 | device = (struct dasd_device *) ptr; | |
1020 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
1021 | /* re-activate request queue */ | |
eb6e199b | 1022 | dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING); |
1da177e4 | 1023 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
8e09f215 | 1024 | dasd_schedule_device_bh(device); |
1da177e4 LT |
1025 | } |
1026 | ||
1027 | /* | |
1028 | * Setup timeout for a device in jiffies. | |
1029 | */ | |
8e09f215 | 1030 | void dasd_device_set_timer(struct dasd_device *device, int expires) |
1da177e4 | 1031 | { |
48cae885 SW |
1032 | if (expires == 0) |
1033 | del_timer(&device->timer); | |
1034 | else | |
1035 | mod_timer(&device->timer, jiffies + expires); | |
1da177e4 LT |
1036 | } |
1037 | ||
1038 | /* | |
1039 | * Clear timeout for a device. | |
1040 | */ | |
8e09f215 | 1041 | void dasd_device_clear_timer(struct dasd_device *device) |
1da177e4 | 1042 | { |
48cae885 | 1043 | del_timer(&device->timer); |
1da177e4 LT |
1044 | } |
1045 | ||
8e09f215 SW |
1046 | static void dasd_handle_killed_request(struct ccw_device *cdev, |
1047 | unsigned long intparm) | |
1da177e4 LT |
1048 | { |
1049 | struct dasd_ccw_req *cqr; | |
1050 | struct dasd_device *device; | |
1051 | ||
f16f5843 SW |
1052 | if (!intparm) |
1053 | return; | |
1da177e4 LT |
1054 | cqr = (struct dasd_ccw_req *) intparm; |
1055 | if (cqr->status != DASD_CQR_IN_IO) { | |
b8ed5dd5 SH |
1056 | DBF_EVENT_DEVID(DBF_DEBUG, cdev, |
1057 | "invalid status in handle_killed_request: " | |
1058 | "%02x", cqr->status); | |
1da177e4 LT |
1059 | return; |
1060 | } | |
1061 | ||
589c74d5 SH |
1062 | device = dasd_device_from_cdev_locked(cdev); |
1063 | if (IS_ERR(device)) { | |
1064 | DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s", | |
1065 | "unable to get device from cdev"); | |
1066 | return; | |
1067 | } | |
1068 | ||
1069 | if (!cqr->startdev || | |
1070 | device != cqr->startdev || | |
1071 | strncmp(cqr->startdev->discipline->ebcname, | |
1072 | (char *) &cqr->magic, 4)) { | |
294001a8 SH |
1073 | DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s", |
1074 | "invalid device in request"); | |
589c74d5 | 1075 | dasd_put_device(device); |
1da177e4 LT |
1076 | return; |
1077 | } | |
1078 | ||
1079 | /* Schedule request to be retried. */ | |
1080 | cqr->status = DASD_CQR_QUEUED; | |
1081 | ||
8e09f215 SW |
1082 | dasd_device_clear_timer(device); |
1083 | dasd_schedule_device_bh(device); | |
1da177e4 LT |
1084 | dasd_put_device(device); |
1085 | } | |
1086 | ||
8e09f215 | 1087 | void dasd_generic_handle_state_change(struct dasd_device *device) |
1da177e4 | 1088 | { |
20c64468 SW |
1089 | /* First of all start sense subsystem status request. */ |
1090 | dasd_eer_snss(device); | |
1091 | ||
eb6e199b | 1092 | dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING); |
8e09f215 SW |
1093 | dasd_schedule_device_bh(device); |
1094 | if (device->block) | |
1095 | dasd_schedule_block_bh(device->block); | |
1da177e4 LT |
1096 | } |
1097 | ||
1098 | /* | |
1099 | * Interrupt handler for "normal" ssch-io based dasd devices. | |
1100 | */ | |
8e09f215 SW |
1101 | void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm, |
1102 | struct irb *irb) | |
1da177e4 LT |
1103 | { |
1104 | struct dasd_ccw_req *cqr, *next; | |
1105 | struct dasd_device *device; | |
1106 | unsigned long long now; | |
1107 | int expires; | |
1da177e4 | 1108 | |
3283942b | 1109 | kstat_cpu(smp_processor_id()).irqs[IOINT_DAS]++; |
1da177e4 LT |
1110 | if (IS_ERR(irb)) { |
1111 | switch (PTR_ERR(irb)) { | |
1112 | case -EIO: | |
1da177e4 LT |
1113 | break; |
1114 | case -ETIMEDOUT: | |
b8ed5dd5 SH |
1115 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: " |
1116 | "request timed out\n", __func__); | |
1da177e4 LT |
1117 | break; |
1118 | default: | |
b8ed5dd5 SH |
1119 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: " |
1120 | "unknown error %ld\n", __func__, | |
1121 | PTR_ERR(irb)); | |
1da177e4 | 1122 | } |
f16f5843 | 1123 | dasd_handle_killed_request(cdev, intparm); |
1da177e4 LT |
1124 | return; |
1125 | } | |
1126 | ||
1127 | now = get_clock(); | |
8e09f215 | 1128 | cqr = (struct dasd_ccw_req *) intparm; |
5a27e60d SW |
1129 | /* check for conditions that should be handled immediately */ |
1130 | if (!cqr || | |
1131 | !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) && | |
1132 | scsw_cstat(&irb->scsw) == 0)) { | |
a5a0061f SW |
1133 | if (cqr) |
1134 | memcpy(&cqr->irb, irb, sizeof(*irb)); | |
a00bfd71 | 1135 | device = dasd_device_from_cdev_locked(cdev); |
56b86b61 SH |
1136 | if (IS_ERR(device)) |
1137 | return; | |
1138 | /* ignore unsolicited interrupts for DIAG discipline */ | |
1139 | if (device->discipline == dasd_diag_discipline_pointer) { | |
1da177e4 | 1140 | dasd_put_device(device); |
56b86b61 | 1141 | return; |
1da177e4 | 1142 | } |
5a27e60d SW |
1143 | device->discipline->dump_sense_dbf(device, irb, "int"); |
1144 | if (device->features & DASD_FEATURE_ERPLOG) | |
1145 | device->discipline->dump_sense(device, cqr, irb); | |
1146 | device->discipline->check_for_device_change(device, cqr, irb); | |
56b86b61 | 1147 | dasd_put_device(device); |
1da177e4 | 1148 | } |
5a27e60d SW |
1149 | if (!cqr) |
1150 | return; | |
1da177e4 | 1151 | |
8e09f215 SW |
1152 | device = (struct dasd_device *) cqr->startdev; |
1153 | if (!device || | |
1da177e4 | 1154 | strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { |
294001a8 SH |
1155 | DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s", |
1156 | "invalid device in request"); | |
1da177e4 LT |
1157 | return; |
1158 | } | |
1159 | ||
1160 | /* Check for clear pending */ | |
8e09f215 | 1161 | if (cqr->status == DASD_CQR_CLEAR_PENDING && |
f3eb5384 | 1162 | scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) { |
8e09f215 SW |
1163 | cqr->status = DASD_CQR_CLEARED; |
1164 | dasd_device_clear_timer(device); | |
8f61701b | 1165 | wake_up(&dasd_flush_wq); |
8e09f215 | 1166 | dasd_schedule_device_bh(device); |
1da177e4 LT |
1167 | return; |
1168 | } | |
1169 | ||
f3eb5384 | 1170 | /* check status - the request might have been killed by dyn detach */ |
1da177e4 | 1171 | if (cqr->status != DASD_CQR_IN_IO) { |
fc19f381 SH |
1172 | DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, " |
1173 | "status %02x", dev_name(&cdev->dev), cqr->status); | |
1da177e4 LT |
1174 | return; |
1175 | } | |
fc19f381 | 1176 | |
8e09f215 | 1177 | next = NULL; |
1da177e4 | 1178 | expires = 0; |
f3eb5384 SW |
1179 | if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) && |
1180 | scsw_cstat(&irb->scsw) == 0) { | |
8e09f215 SW |
1181 | /* request was completed successfully */ |
1182 | cqr->status = DASD_CQR_SUCCESS; | |
1da177e4 LT |
1183 | cqr->stopclk = now; |
1184 | /* Start first request on queue if possible -> fast_io. */ | |
8e09f215 SW |
1185 | if (cqr->devlist.next != &device->ccw_queue) { |
1186 | next = list_entry(cqr->devlist.next, | |
1187 | struct dasd_ccw_req, devlist); | |
1da177e4 | 1188 | } |
8e09f215 | 1189 | } else { /* error */ |
6c5f57c7 SH |
1190 | /* |
1191 | * If we don't want complex ERP for this request, then just | |
1192 | * reset this and retry it in the fastpath | |
8e09f215 | 1193 | */ |
6c5f57c7 | 1194 | if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) && |
8e09f215 | 1195 | cqr->retries > 0) { |
a4d26c6a | 1196 | if (cqr->lpm == device->path_data.opm) |
fc19f381 SH |
1197 | DBF_DEV_EVENT(DBF_DEBUG, device, |
1198 | "default ERP in fastpath " | |
1199 | "(%i retries left)", | |
1200 | cqr->retries); | |
a4d26c6a SW |
1201 | if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) |
1202 | cqr->lpm = device->path_data.opm; | |
8e09f215 SW |
1203 | cqr->status = DASD_CQR_QUEUED; |
1204 | next = cqr; | |
1205 | } else | |
1da177e4 | 1206 | cqr->status = DASD_CQR_ERROR; |
8e09f215 SW |
1207 | } |
1208 | if (next && (next->status == DASD_CQR_QUEUED) && | |
1209 | (!device->stopped)) { | |
1210 | if (device->discipline->start_IO(next) == 0) | |
1211 | expires = next->expires; | |
1da177e4 LT |
1212 | } |
1213 | if (expires != 0) | |
8e09f215 | 1214 | dasd_device_set_timer(device, expires); |
1da177e4 | 1215 | else |
8e09f215 SW |
1216 | dasd_device_clear_timer(device); |
1217 | dasd_schedule_device_bh(device); | |
1da177e4 LT |
1218 | } |
1219 | ||
a23ed009 SH |
1220 | enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb) |
1221 | { | |
1222 | struct dasd_device *device; | |
1223 | ||
1224 | device = dasd_device_from_cdev_locked(cdev); | |
1225 | ||
1226 | if (IS_ERR(device)) | |
1227 | goto out; | |
1228 | if (test_bit(DASD_FLAG_OFFLINE, &device->flags) || | |
1229 | device->state != device->target || | |
5a27e60d | 1230 | !device->discipline->check_for_device_change){ |
a23ed009 SH |
1231 | dasd_put_device(device); |
1232 | goto out; | |
1233 | } | |
5a27e60d SW |
1234 | if (device->discipline->dump_sense_dbf) |
1235 | device->discipline->dump_sense_dbf(device, irb, "uc"); | |
1236 | device->discipline->check_for_device_change(device, NULL, irb); | |
a23ed009 SH |
1237 | dasd_put_device(device); |
1238 | out: | |
1239 | return UC_TODO_RETRY; | |
1240 | } | |
1241 | EXPORT_SYMBOL_GPL(dasd_generic_uc_handler); | |
1242 | ||
1da177e4 | 1243 | /* |
8e09f215 SW |
1244 | * If we have an error on a dasd_block layer request then we cancel |
1245 | * and return all further requests from the same dasd_block as well. | |
1da177e4 | 1246 | */ |
8e09f215 SW |
1247 | static void __dasd_device_recovery(struct dasd_device *device, |
1248 | struct dasd_ccw_req *ref_cqr) | |
1da177e4 | 1249 | { |
8e09f215 SW |
1250 | struct list_head *l, *n; |
1251 | struct dasd_ccw_req *cqr; | |
1da177e4 | 1252 | |
8e09f215 SW |
1253 | /* |
1254 | * only requeue request that came from the dasd_block layer | |
1255 | */ | |
1256 | if (!ref_cqr->block) | |
1257 | return; | |
1da177e4 | 1258 | |
8e09f215 SW |
1259 | list_for_each_safe(l, n, &device->ccw_queue) { |
1260 | cqr = list_entry(l, struct dasd_ccw_req, devlist); | |
1261 | if (cqr->status == DASD_CQR_QUEUED && | |
1262 | ref_cqr->block == cqr->block) { | |
1263 | cqr->status = DASD_CQR_CLEARED; | |
1264 | } | |
1265 | } | |
1266 | }; | |
1da177e4 LT |
1267 | |
1268 | /* | |
8e09f215 SW |
1269 | * Remove those ccw requests from the queue that need to be returned |
1270 | * to the upper layer. | |
1da177e4 | 1271 | */ |
8e09f215 SW |
1272 | static void __dasd_device_process_ccw_queue(struct dasd_device *device, |
1273 | struct list_head *final_queue) | |
1da177e4 LT |
1274 | { |
1275 | struct list_head *l, *n; | |
1276 | struct dasd_ccw_req *cqr; | |
1da177e4 | 1277 | |
1da177e4 LT |
1278 | /* Process request with final status. */ |
1279 | list_for_each_safe(l, n, &device->ccw_queue) { | |
8e09f215 SW |
1280 | cqr = list_entry(l, struct dasd_ccw_req, devlist); |
1281 | ||
1da177e4 | 1282 | /* Stop list processing at the first non-final request. */ |
8e09f215 SW |
1283 | if (cqr->status == DASD_CQR_QUEUED || |
1284 | cqr->status == DASD_CQR_IN_IO || | |
1285 | cqr->status == DASD_CQR_CLEAR_PENDING) | |
1da177e4 | 1286 | break; |
1da177e4 | 1287 | if (cqr->status == DASD_CQR_ERROR) { |
8e09f215 | 1288 | __dasd_device_recovery(device, cqr); |
20c64468 | 1289 | } |
1da177e4 | 1290 | /* Rechain finished requests to final queue */ |
8e09f215 | 1291 | list_move_tail(&cqr->devlist, final_queue); |
1da177e4 LT |
1292 | } |
1293 | } | |
1294 | ||
1da177e4 | 1295 | /* |
8e09f215 SW |
1296 | * the cqrs from the final queue are returned to the upper layer |
1297 | * by setting a dasd_block state and calling the callback function | |
1da177e4 | 1298 | */ |
8e09f215 SW |
1299 | static void __dasd_device_process_final_queue(struct dasd_device *device, |
1300 | struct list_head *final_queue) | |
1da177e4 | 1301 | { |
8e09f215 | 1302 | struct list_head *l, *n; |
1da177e4 | 1303 | struct dasd_ccw_req *cqr; |
03513bcc | 1304 | struct dasd_block *block; |
c80ee724 SH |
1305 | void (*callback)(struct dasd_ccw_req *, void *data); |
1306 | void *callback_data; | |
fc19f381 | 1307 | char errorstring[ERRORLENGTH]; |
f24acd45 | 1308 | |
8e09f215 SW |
1309 | list_for_each_safe(l, n, final_queue) { |
1310 | cqr = list_entry(l, struct dasd_ccw_req, devlist); | |
1311 | list_del_init(&cqr->devlist); | |
03513bcc | 1312 | block = cqr->block; |
c80ee724 SH |
1313 | callback = cqr->callback; |
1314 | callback_data = cqr->callback_data; | |
03513bcc SW |
1315 | if (block) |
1316 | spin_lock_bh(&block->queue_lock); | |
8e09f215 SW |
1317 | switch (cqr->status) { |
1318 | case DASD_CQR_SUCCESS: | |
1319 | cqr->status = DASD_CQR_DONE; | |
1320 | break; | |
1321 | case DASD_CQR_ERROR: | |
1322 | cqr->status = DASD_CQR_NEED_ERP; | |
1323 | break; | |
1324 | case DASD_CQR_CLEARED: | |
1325 | cqr->status = DASD_CQR_TERMINATED; | |
1326 | break; | |
1327 | default: | |
fc19f381 SH |
1328 | /* internal error 12 - wrong cqr status*/ |
1329 | snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status); | |
1330 | dev_err(&device->cdev->dev, | |
1331 | "An error occurred in the DASD device driver, " | |
1332 | "reason=%s\n", errorstring); | |
8e09f215 | 1333 | BUG(); |
1da177e4 | 1334 | } |
8e09f215 | 1335 | if (cqr->callback != NULL) |
c80ee724 | 1336 | (callback)(cqr, callback_data); |
03513bcc SW |
1337 | if (block) |
1338 | spin_unlock_bh(&block->queue_lock); | |
1da177e4 LT |
1339 | } |
1340 | } | |
1341 | ||
1342 | /* | |
1343 | * Take a look at the first request on the ccw queue and check | |
1344 | * if it reached its expire time. If so, terminate the IO. | |
1345 | */ | |
8e09f215 | 1346 | static void __dasd_device_check_expire(struct dasd_device *device) |
1da177e4 LT |
1347 | { |
1348 | struct dasd_ccw_req *cqr; | |
1349 | ||
1350 | if (list_empty(&device->ccw_queue)) | |
1351 | return; | |
8e09f215 | 1352 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist); |
29145a6c HH |
1353 | if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) && |
1354 | (time_after_eq(jiffies, cqr->expires + cqr->starttime))) { | |
1355 | if (device->discipline->term_IO(cqr) != 0) { | |
1356 | /* Hmpf, try again in 5 sec */ | |
fc19f381 | 1357 | dev_err(&device->cdev->dev, |
625c94df | 1358 | "cqr %p timed out (%lus) but cannot be " |
fc19f381 SH |
1359 | "ended, retrying in 5 s\n", |
1360 | cqr, (cqr->expires/HZ)); | |
7dc1da9f SH |
1361 | cqr->expires += 5*HZ; |
1362 | dasd_device_set_timer(device, 5*HZ); | |
29145a6c | 1363 | } else { |
fc19f381 | 1364 | dev_err(&device->cdev->dev, |
625c94df | 1365 | "cqr %p timed out (%lus), %i retries " |
fc19f381 SH |
1366 | "remaining\n", cqr, (cqr->expires/HZ), |
1367 | cqr->retries); | |
1da177e4 LT |
1368 | } |
1369 | } | |
1370 | } | |
1371 | ||
1372 | /* | |
1373 | * Take a look at the first request on the ccw queue and check | |
1374 | * if it needs to be started. | |
1375 | */ | |
8e09f215 | 1376 | static void __dasd_device_start_head(struct dasd_device *device) |
1da177e4 LT |
1377 | { |
1378 | struct dasd_ccw_req *cqr; | |
1379 | int rc; | |
1380 | ||
1381 | if (list_empty(&device->ccw_queue)) | |
1382 | return; | |
8e09f215 | 1383 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist); |
25ee4cf8 PO |
1384 | if (cqr->status != DASD_CQR_QUEUED) |
1385 | return; | |
a4d26c6a SW |
1386 | /* when device is stopped, return request to previous layer |
1387 | * exception: only the disconnect or unresumed bits are set and the | |
1388 | * cqr is a path verification request | |
1389 | */ | |
1390 | if (device->stopped && | |
1391 | !(!(device->stopped & ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM)) | |
1392 | && test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))) { | |
1393 | cqr->intrc = -EAGAIN; | |
8e09f215 SW |
1394 | cqr->status = DASD_CQR_CLEARED; |
1395 | dasd_schedule_device_bh(device); | |
25ee4cf8 | 1396 | return; |
1c01b8a5 | 1397 | } |
25ee4cf8 PO |
1398 | |
1399 | rc = device->discipline->start_IO(cqr); | |
1400 | if (rc == 0) | |
8e09f215 | 1401 | dasd_device_set_timer(device, cqr->expires); |
25ee4cf8 | 1402 | else if (rc == -EACCES) { |
8e09f215 | 1403 | dasd_schedule_device_bh(device); |
25ee4cf8 PO |
1404 | } else |
1405 | /* Hmpf, try again in 1/2 sec */ | |
8e09f215 | 1406 | dasd_device_set_timer(device, 50); |
8f61701b HH |
1407 | } |
1408 | ||
a4d26c6a SW |
1409 | static void __dasd_device_check_path_events(struct dasd_device *device) |
1410 | { | |
1411 | int rc; | |
1412 | ||
1413 | if (device->path_data.tbvpm) { | |
1414 | if (device->stopped & ~(DASD_STOPPED_DC_WAIT | | |
1415 | DASD_UNRESUMED_PM)) | |
1416 | return; | |
1417 | rc = device->discipline->verify_path( | |
1418 | device, device->path_data.tbvpm); | |
1419 | if (rc) | |
1420 | dasd_device_set_timer(device, 50); | |
1421 | else | |
1422 | device->path_data.tbvpm = 0; | |
1423 | } | |
1424 | }; | |
1425 | ||
1da177e4 | 1426 | /* |
8e09f215 SW |
1427 | * Go through all request on the dasd_device request queue, |
1428 | * terminate them on the cdev if necessary, and return them to the | |
1429 | * submitting layer via callback. | |
1430 | * Note: | |
1431 | * Make sure that all 'submitting layers' still exist when | |
1432 | * this function is called!. In other words, when 'device' is a base | |
1433 | * device then all block layer requests must have been removed before | |
1434 | * via dasd_flush_block_queue. | |
1da177e4 | 1435 | */ |
8e09f215 | 1436 | int dasd_flush_device_queue(struct dasd_device *device) |
1da177e4 | 1437 | { |
8e09f215 SW |
1438 | struct dasd_ccw_req *cqr, *n; |
1439 | int rc; | |
1da177e4 | 1440 | struct list_head flush_queue; |
1da177e4 LT |
1441 | |
1442 | INIT_LIST_HEAD(&flush_queue); | |
1443 | spin_lock_irq(get_ccwdev_lock(device->cdev)); | |
8f61701b | 1444 | rc = 0; |
8e09f215 | 1445 | list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) { |
8f61701b HH |
1446 | /* Check status and move request to flush_queue */ |
1447 | switch (cqr->status) { | |
1448 | case DASD_CQR_IN_IO: | |
1449 | rc = device->discipline->term_IO(cqr); | |
1450 | if (rc) { | |
1451 | /* unable to terminate requeust */ | |
fc19f381 SH |
1452 | dev_err(&device->cdev->dev, |
1453 | "Flushing the DASD request queue " | |
1454 | "failed for request %p\n", cqr); | |
8f61701b HH |
1455 | /* stop flush processing */ |
1456 | goto finished; | |
1457 | } | |
1458 | break; | |
1459 | case DASD_CQR_QUEUED: | |
1da177e4 | 1460 | cqr->stopclk = get_clock(); |
8e09f215 | 1461 | cqr->status = DASD_CQR_CLEARED; |
8f61701b | 1462 | break; |
8e09f215 | 1463 | default: /* no need to modify the others */ |
8f61701b HH |
1464 | break; |
1465 | } | |
8e09f215 | 1466 | list_move_tail(&cqr->devlist, &flush_queue); |
8f61701b | 1467 | } |
8f61701b HH |
1468 | finished: |
1469 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); | |
8e09f215 SW |
1470 | /* |
1471 | * After this point all requests must be in state CLEAR_PENDING, | |
1472 | * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become | |
1473 | * one of the others. | |
1474 | */ | |
1475 | list_for_each_entry_safe(cqr, n, &flush_queue, devlist) | |
1476 | wait_event(dasd_flush_wq, | |
1477 | (cqr->status != DASD_CQR_CLEAR_PENDING)); | |
1478 | /* | |
1479 | * Now set each request back to TERMINATED, DONE or NEED_ERP | |
1480 | * and call the callback function of flushed requests | |
1481 | */ | |
1482 | __dasd_device_process_final_queue(device, &flush_queue); | |
8f61701b | 1483 | return rc; |
1da177e4 LT |
1484 | } |
1485 | ||
1486 | /* | |
1487 | * Acquire the device lock and process queues for the device. | |
1488 | */ | |
8e09f215 | 1489 | static void dasd_device_tasklet(struct dasd_device *device) |
1da177e4 LT |
1490 | { |
1491 | struct list_head final_queue; | |
1da177e4 LT |
1492 | |
1493 | atomic_set (&device->tasklet_scheduled, 0); | |
1494 | INIT_LIST_HEAD(&final_queue); | |
1495 | spin_lock_irq(get_ccwdev_lock(device->cdev)); | |
1496 | /* Check expire time of first request on the ccw queue. */ | |
8e09f215 SW |
1497 | __dasd_device_check_expire(device); |
1498 | /* find final requests on ccw queue */ | |
1499 | __dasd_device_process_ccw_queue(device, &final_queue); | |
a4d26c6a | 1500 | __dasd_device_check_path_events(device); |
1da177e4 LT |
1501 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
1502 | /* Now call the callback function of requests with final status */ | |
8e09f215 SW |
1503 | __dasd_device_process_final_queue(device, &final_queue); |
1504 | spin_lock_irq(get_ccwdev_lock(device->cdev)); | |
1da177e4 | 1505 | /* Now check if the head of the ccw queue needs to be started. */ |
8e09f215 SW |
1506 | __dasd_device_start_head(device); |
1507 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); | |
1da177e4 LT |
1508 | dasd_put_device(device); |
1509 | } | |
1510 | ||
1511 | /* | |
1512 | * Schedules a call to dasd_tasklet over the device tasklet. | |
1513 | */ | |
8e09f215 | 1514 | void dasd_schedule_device_bh(struct dasd_device *device) |
1da177e4 LT |
1515 | { |
1516 | /* Protect against rescheduling. */ | |
973bd993 | 1517 | if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0) |
1da177e4 LT |
1518 | return; |
1519 | dasd_get_device(device); | |
1520 | tasklet_hi_schedule(&device->tasklet); | |
1521 | } | |
1522 | ||
eb6e199b SW |
1523 | void dasd_device_set_stop_bits(struct dasd_device *device, int bits) |
1524 | { | |
1525 | device->stopped |= bits; | |
1526 | } | |
1527 | EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits); | |
1528 | ||
1529 | void dasd_device_remove_stop_bits(struct dasd_device *device, int bits) | |
1530 | { | |
1531 | device->stopped &= ~bits; | |
1532 | if (!device->stopped) | |
1533 | wake_up(&generic_waitq); | |
1534 | } | |
1535 | EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits); | |
1536 | ||
1da177e4 | 1537 | /* |
8e09f215 SW |
1538 | * Queue a request to the head of the device ccw_queue. |
1539 | * Start the I/O if possible. | |
1da177e4 | 1540 | */ |
8e09f215 | 1541 | void dasd_add_request_head(struct dasd_ccw_req *cqr) |
1da177e4 LT |
1542 | { |
1543 | struct dasd_device *device; | |
1544 | unsigned long flags; | |
1545 | ||
8e09f215 | 1546 | device = cqr->startdev; |
1da177e4 | 1547 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
8e09f215 SW |
1548 | cqr->status = DASD_CQR_QUEUED; |
1549 | list_add(&cqr->devlist, &device->ccw_queue); | |
1da177e4 | 1550 | /* let the bh start the request to keep them in order */ |
8e09f215 | 1551 | dasd_schedule_device_bh(device); |
1da177e4 LT |
1552 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
1553 | } | |
1554 | ||
1555 | /* | |
8e09f215 SW |
1556 | * Queue a request to the tail of the device ccw_queue. |
1557 | * Start the I/O if possible. | |
1da177e4 | 1558 | */ |
8e09f215 | 1559 | void dasd_add_request_tail(struct dasd_ccw_req *cqr) |
1da177e4 LT |
1560 | { |
1561 | struct dasd_device *device; | |
1562 | unsigned long flags; | |
1563 | ||
8e09f215 | 1564 | device = cqr->startdev; |
1da177e4 | 1565 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
8e09f215 SW |
1566 | cqr->status = DASD_CQR_QUEUED; |
1567 | list_add_tail(&cqr->devlist, &device->ccw_queue); | |
1da177e4 | 1568 | /* let the bh start the request to keep them in order */ |
8e09f215 | 1569 | dasd_schedule_device_bh(device); |
1da177e4 LT |
1570 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
1571 | } | |
1572 | ||
1573 | /* | |
8e09f215 | 1574 | * Wakeup helper for the 'sleep_on' functions. |
1da177e4 | 1575 | */ |
8e09f215 | 1576 | static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data) |
1da177e4 | 1577 | { |
1c1e093c SW |
1578 | spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev)); |
1579 | cqr->callback_data = DASD_SLEEPON_END_TAG; | |
1580 | spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev)); | |
1581 | wake_up(&generic_waitq); | |
1da177e4 LT |
1582 | } |
1583 | ||
8e09f215 | 1584 | static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr) |
1da177e4 LT |
1585 | { |
1586 | struct dasd_device *device; | |
1587 | int rc; | |
1588 | ||
8e09f215 | 1589 | device = cqr->startdev; |
1da177e4 | 1590 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
1c1e093c | 1591 | rc = (cqr->callback_data == DASD_SLEEPON_END_TAG); |
1da177e4 LT |
1592 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
1593 | return rc; | |
1594 | } | |
1595 | ||
1596 | /* | |
eb6e199b | 1597 | * checks if error recovery is necessary, returns 1 if yes, 0 otherwise. |
1da177e4 | 1598 | */ |
eb6e199b | 1599 | static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr) |
1da177e4 | 1600 | { |
1da177e4 | 1601 | struct dasd_device *device; |
eb6e199b | 1602 | dasd_erp_fn_t erp_fn; |
138c014d | 1603 | |
eb6e199b SW |
1604 | if (cqr->status == DASD_CQR_FILLED) |
1605 | return 0; | |
8e09f215 | 1606 | device = cqr->startdev; |
eb6e199b SW |
1607 | if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) { |
1608 | if (cqr->status == DASD_CQR_TERMINATED) { | |
1609 | device->discipline->handle_terminated_request(cqr); | |
1610 | return 1; | |
1611 | } | |
1612 | if (cqr->status == DASD_CQR_NEED_ERP) { | |
1613 | erp_fn = device->discipline->erp_action(cqr); | |
1614 | erp_fn(cqr); | |
1615 | return 1; | |
1616 | } | |
1617 | if (cqr->status == DASD_CQR_FAILED) | |
1618 | dasd_log_sense(cqr, &cqr->irb); | |
1619 | if (cqr->refers) { | |
1620 | __dasd_process_erp(device, cqr); | |
1621 | return 1; | |
1622 | } | |
1623 | } | |
1624 | return 0; | |
1625 | } | |
138c014d | 1626 | |
eb6e199b SW |
1627 | static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr) |
1628 | { | |
1629 | if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) { | |
1630 | if (cqr->refers) /* erp is not done yet */ | |
1631 | return 1; | |
1632 | return ((cqr->status != DASD_CQR_DONE) && | |
1633 | (cqr->status != DASD_CQR_FAILED)); | |
1634 | } else | |
1635 | return (cqr->status == DASD_CQR_FILLED); | |
1636 | } | |
138c014d | 1637 | |
eb6e199b SW |
1638 | static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible) |
1639 | { | |
1640 | struct dasd_device *device; | |
1641 | int rc; | |
1642 | struct list_head ccw_queue; | |
1643 | struct dasd_ccw_req *cqr; | |
1644 | ||
1645 | INIT_LIST_HEAD(&ccw_queue); | |
1646 | maincqr->status = DASD_CQR_FILLED; | |
1647 | device = maincqr->startdev; | |
1648 | list_add(&maincqr->blocklist, &ccw_queue); | |
1649 | for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr); | |
1650 | cqr = list_first_entry(&ccw_queue, | |
1651 | struct dasd_ccw_req, blocklist)) { | |
1652 | ||
1653 | if (__dasd_sleep_on_erp(cqr)) | |
1654 | continue; | |
1655 | if (cqr->status != DASD_CQR_FILLED) /* could be failed */ | |
1656 | continue; | |
5a27e60d SW |
1657 | if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) && |
1658 | !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) { | |
1659 | cqr->status = DASD_CQR_FAILED; | |
1660 | cqr->intrc = -EPERM; | |
1661 | continue; | |
1662 | } | |
eb6e199b SW |
1663 | /* Non-temporary stop condition will trigger fail fast */ |
1664 | if (device->stopped & ~DASD_STOPPED_PENDING && | |
1665 | test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && | |
1666 | (!dasd_eer_enabled(device))) { | |
1667 | cqr->status = DASD_CQR_FAILED; | |
1668 | continue; | |
1669 | } | |
eb6e199b SW |
1670 | /* Don't try to start requests if device is stopped */ |
1671 | if (interruptible) { | |
1672 | rc = wait_event_interruptible( | |
1673 | generic_waitq, !(device->stopped)); | |
1674 | if (rc == -ERESTARTSYS) { | |
1675 | cqr->status = DASD_CQR_FAILED; | |
1676 | maincqr->intrc = rc; | |
1677 | continue; | |
1678 | } | |
1679 | } else | |
1680 | wait_event(generic_waitq, !(device->stopped)); | |
1681 | ||
1682 | cqr->callback = dasd_wakeup_cb; | |
1c1e093c | 1683 | cqr->callback_data = DASD_SLEEPON_START_TAG; |
eb6e199b SW |
1684 | dasd_add_request_tail(cqr); |
1685 | if (interruptible) { | |
1686 | rc = wait_event_interruptible( | |
1687 | generic_waitq, _wait_for_wakeup(cqr)); | |
1688 | if (rc == -ERESTARTSYS) { | |
1689 | dasd_cancel_req(cqr); | |
1690 | /* wait (non-interruptible) for final status */ | |
1691 | wait_event(generic_waitq, | |
1692 | _wait_for_wakeup(cqr)); | |
1693 | cqr->status = DASD_CQR_FAILED; | |
1694 | maincqr->intrc = rc; | |
1695 | continue; | |
1696 | } | |
1697 | } else | |
1698 | wait_event(generic_waitq, _wait_for_wakeup(cqr)); | |
1699 | } | |
1700 | ||
1701 | maincqr->endclk = get_clock(); | |
1702 | if ((maincqr->status != DASD_CQR_DONE) && | |
1703 | (maincqr->intrc != -ERESTARTSYS)) | |
1704 | dasd_log_sense(maincqr, &maincqr->irb); | |
1705 | if (maincqr->status == DASD_CQR_DONE) | |
6cc7f168 | 1706 | rc = 0; |
eb6e199b SW |
1707 | else if (maincqr->intrc) |
1708 | rc = maincqr->intrc; | |
6cc7f168 SW |
1709 | else |
1710 | rc = -EIO; | |
1da177e4 LT |
1711 | return rc; |
1712 | } | |
1713 | ||
eb6e199b SW |
1714 | /* |
1715 | * Queue a request to the tail of the device ccw_queue and wait for | |
1716 | * it's completion. | |
1717 | */ | |
1718 | int dasd_sleep_on(struct dasd_ccw_req *cqr) | |
1719 | { | |
1720 | return _dasd_sleep_on(cqr, 0); | |
1721 | } | |
1722 | ||
1da177e4 | 1723 | /* |
8e09f215 SW |
1724 | * Queue a request to the tail of the device ccw_queue and wait |
1725 | * interruptible for it's completion. | |
1da177e4 | 1726 | */ |
8e09f215 | 1727 | int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr) |
1da177e4 | 1728 | { |
eb6e199b | 1729 | return _dasd_sleep_on(cqr, 1); |
1da177e4 LT |
1730 | } |
1731 | ||
1732 | /* | |
1733 | * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock | |
1734 | * for eckd devices) the currently running request has to be terminated | |
1735 | * and be put back to status queued, before the special request is added | |
1736 | * to the head of the queue. Then the special request is waited on normally. | |
1737 | */ | |
8e09f215 | 1738 | static inline int _dasd_term_running_cqr(struct dasd_device *device) |
1da177e4 LT |
1739 | { |
1740 | struct dasd_ccw_req *cqr; | |
1da177e4 LT |
1741 | |
1742 | if (list_empty(&device->ccw_queue)) | |
1743 | return 0; | |
8e09f215 | 1744 | cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist); |
8f61701b | 1745 | return device->discipline->term_IO(cqr); |
1da177e4 LT |
1746 | } |
1747 | ||
8e09f215 | 1748 | int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr) |
1da177e4 | 1749 | { |
1da177e4 LT |
1750 | struct dasd_device *device; |
1751 | int rc; | |
138c014d | 1752 | |
8e09f215 | 1753 | device = cqr->startdev; |
5a27e60d SW |
1754 | if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) && |
1755 | !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) { | |
1756 | cqr->status = DASD_CQR_FAILED; | |
1757 | cqr->intrc = -EPERM; | |
1758 | return -EIO; | |
1759 | } | |
1da177e4 LT |
1760 | spin_lock_irq(get_ccwdev_lock(device->cdev)); |
1761 | rc = _dasd_term_running_cqr(device); | |
1762 | if (rc) { | |
1763 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); | |
1764 | return rc; | |
1765 | } | |
1da177e4 | 1766 | cqr->callback = dasd_wakeup_cb; |
1c1e093c | 1767 | cqr->callback_data = DASD_SLEEPON_START_TAG; |
1da177e4 | 1768 | cqr->status = DASD_CQR_QUEUED; |
8e09f215 | 1769 | list_add(&cqr->devlist, &device->ccw_queue); |
138c014d | 1770 | |
1da177e4 | 1771 | /* let the bh start the request to keep them in order */ |
8e09f215 | 1772 | dasd_schedule_device_bh(device); |
138c014d | 1773 | |
1da177e4 LT |
1774 | spin_unlock_irq(get_ccwdev_lock(device->cdev)); |
1775 | ||
c80ee724 | 1776 | wait_event(generic_waitq, _wait_for_wakeup(cqr)); |
138c014d | 1777 | |
6cc7f168 SW |
1778 | if (cqr->status == DASD_CQR_DONE) |
1779 | rc = 0; | |
1780 | else if (cqr->intrc) | |
1781 | rc = cqr->intrc; | |
1782 | else | |
1783 | rc = -EIO; | |
1da177e4 LT |
1784 | return rc; |
1785 | } | |
1786 | ||
1787 | /* | |
1788 | * Cancels a request that was started with dasd_sleep_on_req. | |
1789 | * This is useful to timeout requests. The request will be | |
1790 | * terminated if it is currently in i/o. | |
1791 | * Returns 1 if the request has been terminated. | |
8e09f215 SW |
1792 | * 0 if there was no need to terminate the request (not started yet) |
1793 | * negative error code if termination failed | |
1794 | * Cancellation of a request is an asynchronous operation! The calling | |
1795 | * function has to wait until the request is properly returned via callback. | |
1da177e4 | 1796 | */ |
8e09f215 | 1797 | int dasd_cancel_req(struct dasd_ccw_req *cqr) |
1da177e4 | 1798 | { |
8e09f215 | 1799 | struct dasd_device *device = cqr->startdev; |
1da177e4 LT |
1800 | unsigned long flags; |
1801 | int rc; | |
1802 | ||
1803 | rc = 0; | |
1804 | spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); | |
1805 | switch (cqr->status) { | |
1806 | case DASD_CQR_QUEUED: | |
8e09f215 SW |
1807 | /* request was not started - just set to cleared */ |
1808 | cqr->status = DASD_CQR_CLEARED; | |
1da177e4 LT |
1809 | break; |
1810 | case DASD_CQR_IN_IO: | |
1811 | /* request in IO - terminate IO and release again */ | |
8e09f215 SW |
1812 | rc = device->discipline->term_IO(cqr); |
1813 | if (rc) { | |
fc19f381 SH |
1814 | dev_err(&device->cdev->dev, |
1815 | "Cancelling request %p failed with rc=%d\n", | |
1816 | cqr, rc); | |
8e09f215 SW |
1817 | } else { |
1818 | cqr->stopclk = get_clock(); | |
8e09f215 | 1819 | } |
1da177e4 | 1820 | break; |
8e09f215 | 1821 | default: /* already finished or clear pending - do nothing */ |
1da177e4 | 1822 | break; |
8e09f215 SW |
1823 | } |
1824 | spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); | |
1825 | dasd_schedule_device_bh(device); | |
1826 | return rc; | |
1827 | } | |
1828 | ||
1829 | ||
1830 | /* | |
1831 | * SECTION: Operations of the dasd_block layer. | |
1832 | */ | |
1833 | ||
1834 | /* | |
1835 | * Timeout function for dasd_block. This is used when the block layer | |
1836 | * is waiting for something that may not come reliably, (e.g. a state | |
1837 | * change interrupt) | |
1838 | */ | |
1839 | static void dasd_block_timeout(unsigned long ptr) | |
1840 | { | |
1841 | unsigned long flags; | |
1842 | struct dasd_block *block; | |
1843 | ||
1844 | block = (struct dasd_block *) ptr; | |
1845 | spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags); | |
1846 | /* re-activate request queue */ | |
eb6e199b | 1847 | dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING); |
8e09f215 SW |
1848 | spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags); |
1849 | dasd_schedule_block_bh(block); | |
1850 | } | |
1851 | ||
1852 | /* | |
1853 | * Setup timeout for a dasd_block in jiffies. | |
1854 | */ | |
1855 | void dasd_block_set_timer(struct dasd_block *block, int expires) | |
1856 | { | |
48cae885 SW |
1857 | if (expires == 0) |
1858 | del_timer(&block->timer); | |
1859 | else | |
1860 | mod_timer(&block->timer, jiffies + expires); | |
8e09f215 SW |
1861 | } |
1862 | ||
1863 | /* | |
1864 | * Clear timeout for a dasd_block. | |
1865 | */ | |
1866 | void dasd_block_clear_timer(struct dasd_block *block) | |
1867 | { | |
48cae885 | 1868 | del_timer(&block->timer); |
8e09f215 SW |
1869 | } |
1870 | ||
8e09f215 SW |
1871 | /* |
1872 | * Process finished error recovery ccw. | |
1873 | */ | |
eb6e199b SW |
1874 | static void __dasd_process_erp(struct dasd_device *device, |
1875 | struct dasd_ccw_req *cqr) | |
8e09f215 SW |
1876 | { |
1877 | dasd_erp_fn_t erp_fn; | |
8e09f215 SW |
1878 | |
1879 | if (cqr->status == DASD_CQR_DONE) | |
1880 | DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful"); | |
1881 | else | |
fc19f381 | 1882 | dev_err(&device->cdev->dev, "ERP failed for the DASD\n"); |
8e09f215 SW |
1883 | erp_fn = device->discipline->erp_postaction(cqr); |
1884 | erp_fn(cqr); | |
1885 | } | |
1da177e4 | 1886 | |
8e09f215 SW |
1887 | /* |
1888 | * Fetch requests from the block device queue. | |
1889 | */ | |
1890 | static void __dasd_process_request_queue(struct dasd_block *block) | |
1891 | { | |
1892 | struct request_queue *queue; | |
1893 | struct request *req; | |
1894 | struct dasd_ccw_req *cqr; | |
1895 | struct dasd_device *basedev; | |
1896 | unsigned long flags; | |
1897 | queue = block->request_queue; | |
1898 | basedev = block->base; | |
1899 | /* No queue ? Then there is nothing to do. */ | |
1900 | if (queue == NULL) | |
1901 | return; | |
1902 | ||
1903 | /* | |
1904 | * We requeue request from the block device queue to the ccw | |
1905 | * queue only in two states. In state DASD_STATE_READY the | |
1906 | * partition detection is done and we need to requeue requests | |
1907 | * for that. State DASD_STATE_ONLINE is normal block device | |
1908 | * operation. | |
1909 | */ | |
97f604b0 SW |
1910 | if (basedev->state < DASD_STATE_READY) { |
1911 | while ((req = blk_fetch_request(block->request_queue))) | |
1912 | __blk_end_request_all(req, -EIO); | |
8e09f215 | 1913 | return; |
97f604b0 | 1914 | } |
8e09f215 | 1915 | /* Now we try to fetch requests from the request queue */ |
9934c8c0 | 1916 | while (!blk_queue_plugged(queue) && (req = blk_peek_request(queue))) { |
8e09f215 SW |
1917 | if (basedev->features & DASD_FEATURE_READONLY && |
1918 | rq_data_dir(req) == WRITE) { | |
1919 | DBF_DEV_EVENT(DBF_ERR, basedev, | |
1920 | "Rejecting write request %p", | |
1921 | req); | |
9934c8c0 | 1922 | blk_start_request(req); |
40cbbb78 | 1923 | __blk_end_request_all(req, -EIO); |
8e09f215 SW |
1924 | continue; |
1925 | } | |
1926 | cqr = basedev->discipline->build_cp(basedev, block, req); | |
1927 | if (IS_ERR(cqr)) { | |
1928 | if (PTR_ERR(cqr) == -EBUSY) | |
1929 | break; /* normal end condition */ | |
1930 | if (PTR_ERR(cqr) == -ENOMEM) | |
1931 | break; /* terminate request queue loop */ | |
1932 | if (PTR_ERR(cqr) == -EAGAIN) { | |
1933 | /* | |
1934 | * The current request cannot be build right | |
1935 | * now, we have to try later. If this request | |
1936 | * is the head-of-queue we stop the device | |
1937 | * for 1/2 second. | |
1938 | */ | |
1939 | if (!list_empty(&block->ccw_queue)) | |
1940 | break; | |
eb6e199b SW |
1941 | spin_lock_irqsave( |
1942 | get_ccwdev_lock(basedev->cdev), flags); | |
1943 | dasd_device_set_stop_bits(basedev, | |
1944 | DASD_STOPPED_PENDING); | |
1945 | spin_unlock_irqrestore( | |
1946 | get_ccwdev_lock(basedev->cdev), flags); | |
8e09f215 SW |
1947 | dasd_block_set_timer(block, HZ/2); |
1948 | break; | |
1949 | } | |
1950 | DBF_DEV_EVENT(DBF_ERR, basedev, | |
1951 | "CCW creation failed (rc=%ld) " | |
1952 | "on request %p", | |
1953 | PTR_ERR(cqr), req); | |
9934c8c0 | 1954 | blk_start_request(req); |
40cbbb78 | 1955 | __blk_end_request_all(req, -EIO); |
8e09f215 SW |
1956 | continue; |
1957 | } | |
1958 | /* | |
1959 | * Note: callback is set to dasd_return_cqr_cb in | |
1960 | * __dasd_block_start_head to cover erp requests as well | |
1961 | */ | |
1962 | cqr->callback_data = (void *) req; | |
1963 | cqr->status = DASD_CQR_FILLED; | |
9934c8c0 | 1964 | blk_start_request(req); |
8e09f215 SW |
1965 | list_add_tail(&cqr->blocklist, &block->ccw_queue); |
1966 | dasd_profile_start(block, cqr, req); | |
1967 | } | |
1968 | } | |
1969 | ||
1970 | static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr) | |
1971 | { | |
1972 | struct request *req; | |
1973 | int status; | |
4c4e2148 | 1974 | int error = 0; |
8e09f215 SW |
1975 | |
1976 | req = (struct request *) cqr->callback_data; | |
1977 | dasd_profile_end(cqr->block, cqr, req); | |
fe6b8e76 | 1978 | status = cqr->block->base->discipline->free_cp(cqr, req); |
4c4e2148 KU |
1979 | if (status <= 0) |
1980 | error = status ? status : -EIO; | |
40cbbb78 | 1981 | __blk_end_request_all(req, error); |
8e09f215 SW |
1982 | } |
1983 | ||
1984 | /* | |
1985 | * Process ccw request queue. | |
1986 | */ | |
1987 | static void __dasd_process_block_ccw_queue(struct dasd_block *block, | |
1988 | struct list_head *final_queue) | |
1989 | { | |
1990 | struct list_head *l, *n; | |
1991 | struct dasd_ccw_req *cqr; | |
1992 | dasd_erp_fn_t erp_fn; | |
1993 | unsigned long flags; | |
1994 | struct dasd_device *base = block->base; | |
1995 | ||
1996 | restart: | |
1997 | /* Process request with final status. */ | |
1998 | list_for_each_safe(l, n, &block->ccw_queue) { | |
1999 | cqr = list_entry(l, struct dasd_ccw_req, blocklist); | |
2000 | if (cqr->status != DASD_CQR_DONE && | |
2001 | cqr->status != DASD_CQR_FAILED && | |
2002 | cqr->status != DASD_CQR_NEED_ERP && | |
2003 | cqr->status != DASD_CQR_TERMINATED) | |
2004 | continue; | |
2005 | ||
2006 | if (cqr->status == DASD_CQR_TERMINATED) { | |
2007 | base->discipline->handle_terminated_request(cqr); | |
2008 | goto restart; | |
2009 | } | |
2010 | ||
2011 | /* Process requests that may be recovered */ | |
2012 | if (cqr->status == DASD_CQR_NEED_ERP) { | |
6c5f57c7 | 2013 | erp_fn = base->discipline->erp_action(cqr); |
6a5176c4 SH |
2014 | if (IS_ERR(erp_fn(cqr))) |
2015 | continue; | |
8e09f215 SW |
2016 | goto restart; |
2017 | } | |
2018 | ||
a9cffb22 SH |
2019 | /* log sense for fatal error */ |
2020 | if (cqr->status == DASD_CQR_FAILED) { | |
2021 | dasd_log_sense(cqr, &cqr->irb); | |
2022 | } | |
2023 | ||
8e09f215 SW |
2024 | /* First of all call extended error reporting. */ |
2025 | if (dasd_eer_enabled(base) && | |
2026 | cqr->status == DASD_CQR_FAILED) { | |
2027 | dasd_eer_write(base, cqr, DASD_EER_FATALERROR); | |
2028 | ||
2029 | /* restart request */ | |
2030 | cqr->status = DASD_CQR_FILLED; | |
2031 | cqr->retries = 255; | |
2032 | spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags); | |
eb6e199b | 2033 | dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE); |
8e09f215 SW |
2034 | spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), |
2035 | flags); | |
2036 | goto restart; | |
2037 | } | |
2038 | ||
2039 | /* Process finished ERP request. */ | |
2040 | if (cqr->refers) { | |
eb6e199b | 2041 | __dasd_process_erp(base, cqr); |
8e09f215 SW |
2042 | goto restart; |
2043 | } | |
2044 | ||
2045 | /* Rechain finished requests to final queue */ | |
2046 | cqr->endclk = get_clock(); | |
2047 | list_move_tail(&cqr->blocklist, final_queue); | |
2048 | } | |
2049 | } | |
2050 | ||
2051 | static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data) | |
2052 | { | |
2053 | dasd_schedule_block_bh(cqr->block); | |
2054 | } | |
2055 | ||
2056 | static void __dasd_block_start_head(struct dasd_block *block) | |
2057 | { | |
2058 | struct dasd_ccw_req *cqr; | |
2059 | ||
2060 | if (list_empty(&block->ccw_queue)) | |
2061 | return; | |
2062 | /* We allways begin with the first requests on the queue, as some | |
2063 | * of previously started requests have to be enqueued on a | |
2064 | * dasd_device again for error recovery. | |
2065 | */ | |
2066 | list_for_each_entry(cqr, &block->ccw_queue, blocklist) { | |
2067 | if (cqr->status != DASD_CQR_FILLED) | |
2068 | continue; | |
5a27e60d SW |
2069 | if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) && |
2070 | !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) { | |
2071 | cqr->status = DASD_CQR_FAILED; | |
2072 | cqr->intrc = -EPERM; | |
2073 | dasd_schedule_block_bh(block); | |
2074 | continue; | |
2075 | } | |
8e09f215 SW |
2076 | /* Non-temporary stop condition will trigger fail fast */ |
2077 | if (block->base->stopped & ~DASD_STOPPED_PENDING && | |
2078 | test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && | |
2079 | (!dasd_eer_enabled(block->base))) { | |
2080 | cqr->status = DASD_CQR_FAILED; | |
2081 | dasd_schedule_block_bh(block); | |
2082 | continue; | |
2083 | } | |
2084 | /* Don't try to start requests if device is stopped */ | |
2085 | if (block->base->stopped) | |
2086 | return; | |
2087 | ||
2088 | /* just a fail safe check, should not happen */ | |
2089 | if (!cqr->startdev) | |
2090 | cqr->startdev = block->base; | |
2091 | ||
2092 | /* make sure that the requests we submit find their way back */ | |
2093 | cqr->callback = dasd_return_cqr_cb; | |
2094 | ||
2095 | dasd_add_request_tail(cqr); | |
2096 | } | |
2097 | } | |
2098 | ||
2099 | /* | |
2100 | * Central dasd_block layer routine. Takes requests from the generic | |
2101 | * block layer request queue, creates ccw requests, enqueues them on | |
2102 | * a dasd_device and processes ccw requests that have been returned. | |
2103 | */ | |
2104 | static void dasd_block_tasklet(struct dasd_block *block) | |
2105 | { | |
2106 | struct list_head final_queue; | |
2107 | struct list_head *l, *n; | |
2108 | struct dasd_ccw_req *cqr; | |
2109 | ||
2110 | atomic_set(&block->tasklet_scheduled, 0); | |
2111 | INIT_LIST_HEAD(&final_queue); | |
2112 | spin_lock(&block->queue_lock); | |
2113 | /* Finish off requests on ccw queue */ | |
2114 | __dasd_process_block_ccw_queue(block, &final_queue); | |
2115 | spin_unlock(&block->queue_lock); | |
2116 | /* Now call the callback function of requests with final status */ | |
2117 | spin_lock_irq(&block->request_queue_lock); | |
2118 | list_for_each_safe(l, n, &final_queue) { | |
2119 | cqr = list_entry(l, struct dasd_ccw_req, blocklist); | |
2120 | list_del_init(&cqr->blocklist); | |
2121 | __dasd_cleanup_cqr(cqr); | |
2122 | } | |
2123 | spin_lock(&block->queue_lock); | |
2124 | /* Get new request from the block device request queue */ | |
2125 | __dasd_process_request_queue(block); | |
2126 | /* Now check if the head of the ccw queue needs to be started. */ | |
2127 | __dasd_block_start_head(block); | |
2128 | spin_unlock(&block->queue_lock); | |
2129 | spin_unlock_irq(&block->request_queue_lock); | |
2130 | dasd_put_device(block->base); | |
2131 | } | |
2132 | ||
2133 | static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data) | |
2134 | { | |
2135 | wake_up(&dasd_flush_wq); | |
2136 | } | |
2137 | ||
2138 | /* | |
2139 | * Go through all request on the dasd_block request queue, cancel them | |
2140 | * on the respective dasd_device, and return them to the generic | |
2141 | * block layer. | |
2142 | */ | |
2143 | static int dasd_flush_block_queue(struct dasd_block *block) | |
2144 | { | |
2145 | struct dasd_ccw_req *cqr, *n; | |
2146 | int rc, i; | |
2147 | struct list_head flush_queue; | |
2148 | ||
2149 | INIT_LIST_HEAD(&flush_queue); | |
2150 | spin_lock_bh(&block->queue_lock); | |
2151 | rc = 0; | |
2152 | restart: | |
2153 | list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) { | |
2154 | /* if this request currently owned by a dasd_device cancel it */ | |
2155 | if (cqr->status >= DASD_CQR_QUEUED) | |
2156 | rc = dasd_cancel_req(cqr); | |
2157 | if (rc < 0) | |
2158 | break; | |
2159 | /* Rechain request (including erp chain) so it won't be | |
2160 | * touched by the dasd_block_tasklet anymore. | |
2161 | * Replace the callback so we notice when the request | |
2162 | * is returned from the dasd_device layer. | |
2163 | */ | |
2164 | cqr->callback = _dasd_wake_block_flush_cb; | |
2165 | for (i = 0; cqr != NULL; cqr = cqr->refers, i++) | |
2166 | list_move_tail(&cqr->blocklist, &flush_queue); | |
2167 | if (i > 1) | |
2168 | /* moved more than one request - need to restart */ | |
2169 | goto restart; | |
2170 | } | |
2171 | spin_unlock_bh(&block->queue_lock); | |
2172 | /* Now call the callback function of flushed requests */ | |
2173 | restart_cb: | |
2174 | list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) { | |
2175 | wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED)); | |
2176 | /* Process finished ERP request. */ | |
2177 | if (cqr->refers) { | |
0cd4bd47 | 2178 | spin_lock_bh(&block->queue_lock); |
eb6e199b | 2179 | __dasd_process_erp(block->base, cqr); |
0cd4bd47 | 2180 | spin_unlock_bh(&block->queue_lock); |
8e09f215 SW |
2181 | /* restart list_for_xx loop since dasd_process_erp |
2182 | * might remove multiple elements */ | |
2183 | goto restart_cb; | |
2184 | } | |
2185 | /* call the callback function */ | |
0cd4bd47 | 2186 | spin_lock_irq(&block->request_queue_lock); |
8e09f215 SW |
2187 | cqr->endclk = get_clock(); |
2188 | list_del_init(&cqr->blocklist); | |
2189 | __dasd_cleanup_cqr(cqr); | |
0cd4bd47 | 2190 | spin_unlock_irq(&block->request_queue_lock); |
1da177e4 | 2191 | } |
1da177e4 LT |
2192 | return rc; |
2193 | } | |
2194 | ||
2195 | /* | |
8e09f215 SW |
2196 | * Schedules a call to dasd_tasklet over the device tasklet. |
2197 | */ | |
2198 | void dasd_schedule_block_bh(struct dasd_block *block) | |
2199 | { | |
2200 | /* Protect against rescheduling. */ | |
2201 | if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0) | |
2202 | return; | |
2203 | /* life cycle of block is bound to it's base device */ | |
2204 | dasd_get_device(block->base); | |
2205 | tasklet_hi_schedule(&block->tasklet); | |
2206 | } | |
2207 | ||
2208 | ||
2209 | /* | |
2210 | * SECTION: external block device operations | |
2211 | * (request queue handling, open, release, etc.) | |
1da177e4 LT |
2212 | */ |
2213 | ||
2214 | /* | |
2215 | * Dasd request queue function. Called from ll_rw_blk.c | |
2216 | */ | |
8e09f215 | 2217 | static void do_dasd_request(struct request_queue *queue) |
1da177e4 | 2218 | { |
8e09f215 | 2219 | struct dasd_block *block; |
1da177e4 | 2220 | |
8e09f215 SW |
2221 | block = queue->queuedata; |
2222 | spin_lock(&block->queue_lock); | |
1da177e4 | 2223 | /* Get new request from the block device request queue */ |
8e09f215 | 2224 | __dasd_process_request_queue(block); |
1da177e4 | 2225 | /* Now check if the head of the ccw queue needs to be started. */ |
8e09f215 SW |
2226 | __dasd_block_start_head(block); |
2227 | spin_unlock(&block->queue_lock); | |
1da177e4 LT |
2228 | } |
2229 | ||
2230 | /* | |
2231 | * Allocate and initialize request queue and default I/O scheduler. | |
2232 | */ | |
8e09f215 | 2233 | static int dasd_alloc_queue(struct dasd_block *block) |
1da177e4 LT |
2234 | { |
2235 | int rc; | |
2236 | ||
8e09f215 SW |
2237 | block->request_queue = blk_init_queue(do_dasd_request, |
2238 | &block->request_queue_lock); | |
2239 | if (block->request_queue == NULL) | |
1da177e4 LT |
2240 | return -ENOMEM; |
2241 | ||
8e09f215 | 2242 | block->request_queue->queuedata = block; |
1da177e4 | 2243 | |
8e09f215 | 2244 | elevator_exit(block->request_queue->elevator); |
08a8a0c5 | 2245 | block->request_queue->elevator = NULL; |
8e09f215 | 2246 | rc = elevator_init(block->request_queue, "deadline"); |
1da177e4 | 2247 | if (rc) { |
8e09f215 | 2248 | blk_cleanup_queue(block->request_queue); |
1da177e4 LT |
2249 | return rc; |
2250 | } | |
2251 | return 0; | |
2252 | } | |
2253 | ||
2254 | /* | |
2255 | * Allocate and initialize request queue. | |
2256 | */ | |
8e09f215 | 2257 | static void dasd_setup_queue(struct dasd_block *block) |
1da177e4 LT |
2258 | { |
2259 | int max; | |
2260 | ||
e1defc4f | 2261 | blk_queue_logical_block_size(block->request_queue, block->bp_block); |
8e09f215 | 2262 | max = block->base->discipline->max_blocks << block->s2b_shift; |
086fa5ff | 2263 | blk_queue_max_hw_sectors(block->request_queue, max); |
8a78362c | 2264 | blk_queue_max_segments(block->request_queue, -1L); |
f3eb5384 SW |
2265 | /* with page sized segments we can translate each segement into |
2266 | * one idaw/tidaw | |
2267 | */ | |
2268 | blk_queue_max_segment_size(block->request_queue, PAGE_SIZE); | |
2269 | blk_queue_segment_boundary(block->request_queue, PAGE_SIZE - 1); | |
1da177e4 LT |
2270 | } |
2271 | ||
2272 | /* | |
2273 | * Deactivate and free request queue. | |
2274 | */ | |
8e09f215 | 2275 | static void dasd_free_queue(struct dasd_block *block) |
1da177e4 | 2276 | { |
8e09f215 SW |
2277 | if (block->request_queue) { |
2278 | blk_cleanup_queue(block->request_queue); | |
2279 | block->request_queue = NULL; | |
1da177e4 LT |
2280 | } |
2281 | } | |
2282 | ||
2283 | /* | |
2284 | * Flush request on the request queue. | |
2285 | */ | |
8e09f215 | 2286 | static void dasd_flush_request_queue(struct dasd_block *block) |
1da177e4 LT |
2287 | { |
2288 | struct request *req; | |
2289 | ||
8e09f215 | 2290 | if (!block->request_queue) |
1da177e4 | 2291 | return; |
138c014d | 2292 | |
8e09f215 | 2293 | spin_lock_irq(&block->request_queue_lock); |
9934c8c0 | 2294 | while ((req = blk_fetch_request(block->request_queue))) |
40cbbb78 | 2295 | __blk_end_request_all(req, -EIO); |
8e09f215 | 2296 | spin_unlock_irq(&block->request_queue_lock); |
1da177e4 LT |
2297 | } |
2298 | ||
57a7c0bc | 2299 | static int dasd_open(struct block_device *bdev, fmode_t mode) |
1da177e4 | 2300 | { |
57a7c0bc | 2301 | struct dasd_block *block = bdev->bd_disk->private_data; |
9eb25122 | 2302 | struct dasd_device *base; |
1da177e4 LT |
2303 | int rc; |
2304 | ||
9eb25122 SH |
2305 | if (!block) |
2306 | return -ENODEV; | |
2307 | ||
2308 | base = block->base; | |
8e09f215 SW |
2309 | atomic_inc(&block->open_count); |
2310 | if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) { | |
1da177e4 LT |
2311 | rc = -ENODEV; |
2312 | goto unlock; | |
2313 | } | |
2314 | ||
8e09f215 | 2315 | if (!try_module_get(base->discipline->owner)) { |
1da177e4 LT |
2316 | rc = -EINVAL; |
2317 | goto unlock; | |
2318 | } | |
2319 | ||
2320 | if (dasd_probeonly) { | |
fc19f381 SH |
2321 | dev_info(&base->cdev->dev, |
2322 | "Accessing the DASD failed because it is in " | |
2323 | "probeonly mode\n"); | |
1da177e4 LT |
2324 | rc = -EPERM; |
2325 | goto out; | |
2326 | } | |
2327 | ||
8e09f215 SW |
2328 | if (base->state <= DASD_STATE_BASIC) { |
2329 | DBF_DEV_EVENT(DBF_ERR, base, " %s", | |
1da177e4 LT |
2330 | " Cannot open unrecognized device"); |
2331 | rc = -ENODEV; | |
2332 | goto out; | |
2333 | } | |
2334 | ||
33b62a30 SW |
2335 | if ((mode & FMODE_WRITE) && |
2336 | (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) || | |
2337 | (base->features & DASD_FEATURE_READONLY))) { | |
2338 | rc = -EROFS; | |
2339 | goto out; | |
2340 | } | |
2341 | ||
1da177e4 LT |
2342 | return 0; |
2343 | ||
2344 | out: | |
8e09f215 | 2345 | module_put(base->discipline->owner); |
1da177e4 | 2346 | unlock: |
8e09f215 | 2347 | atomic_dec(&block->open_count); |
1da177e4 LT |
2348 | return rc; |
2349 | } | |
2350 | ||
57a7c0bc | 2351 | static int dasd_release(struct gendisk *disk, fmode_t mode) |
1da177e4 | 2352 | { |
8e09f215 | 2353 | struct dasd_block *block = disk->private_data; |
1da177e4 | 2354 | |
8e09f215 SW |
2355 | atomic_dec(&block->open_count); |
2356 | module_put(block->base->discipline->owner); | |
1da177e4 LT |
2357 | return 0; |
2358 | } | |
2359 | ||
a885c8c4 CH |
2360 | /* |
2361 | * Return disk geometry. | |
2362 | */ | |
8e09f215 | 2363 | static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
a885c8c4 | 2364 | { |
8e09f215 SW |
2365 | struct dasd_block *block; |
2366 | struct dasd_device *base; | |
a885c8c4 | 2367 | |
8e09f215 | 2368 | block = bdev->bd_disk->private_data; |
8e09f215 | 2369 | if (!block) |
a885c8c4 | 2370 | return -ENODEV; |
cf05b824 | 2371 | base = block->base; |
a885c8c4 | 2372 | |
8e09f215 SW |
2373 | if (!base->discipline || |
2374 | !base->discipline->fill_geometry) | |
a885c8c4 CH |
2375 | return -EINVAL; |
2376 | ||
8e09f215 SW |
2377 | base->discipline->fill_geometry(block, geo); |
2378 | geo->start = get_start_sect(bdev) >> block->s2b_shift; | |
a885c8c4 CH |
2379 | return 0; |
2380 | } | |
2381 | ||
83d5cde4 | 2382 | const struct block_device_operations |
1da177e4 LT |
2383 | dasd_device_operations = { |
2384 | .owner = THIS_MODULE, | |
57a7c0bc AV |
2385 | .open = dasd_open, |
2386 | .release = dasd_release, | |
0000d031 HC |
2387 | .ioctl = dasd_ioctl, |
2388 | .compat_ioctl = dasd_ioctl, | |
a885c8c4 | 2389 | .getgeo = dasd_getgeo, |
1da177e4 LT |
2390 | }; |
2391 | ||
8e09f215 SW |
2392 | /******************************************************************************* |
2393 | * end of block device operations | |
2394 | */ | |
1da177e4 LT |
2395 | |
2396 | static void | |
2397 | dasd_exit(void) | |
2398 | { | |
2399 | #ifdef CONFIG_PROC_FS | |
2400 | dasd_proc_exit(); | |
2401 | #endif | |
20c64468 | 2402 | dasd_eer_exit(); |
6bb0e010 HH |
2403 | if (dasd_page_cache != NULL) { |
2404 | kmem_cache_destroy(dasd_page_cache); | |
2405 | dasd_page_cache = NULL; | |
2406 | } | |
1da177e4 LT |
2407 | dasd_gendisk_exit(); |
2408 | dasd_devmap_exit(); | |
1da177e4 LT |
2409 | if (dasd_debug_area != NULL) { |
2410 | debug_unregister(dasd_debug_area); | |
2411 | dasd_debug_area = NULL; | |
2412 | } | |
2413 | } | |
2414 | ||
2415 | /* | |
2416 | * SECTION: common functions for ccw_driver use | |
2417 | */ | |
2418 | ||
33b62a30 SW |
2419 | /* |
2420 | * Is the device read-only? | |
2421 | * Note that this function does not report the setting of the | |
2422 | * readonly device attribute, but how it is configured in z/VM. | |
2423 | */ | |
2424 | int dasd_device_is_ro(struct dasd_device *device) | |
2425 | { | |
2426 | struct ccw_dev_id dev_id; | |
2427 | struct diag210 diag_data; | |
2428 | int rc; | |
2429 | ||
2430 | if (!MACHINE_IS_VM) | |
2431 | return 0; | |
2432 | ccw_device_get_id(device->cdev, &dev_id); | |
2433 | memset(&diag_data, 0, sizeof(diag_data)); | |
2434 | diag_data.vrdcdvno = dev_id.devno; | |
2435 | diag_data.vrdclen = sizeof(diag_data); | |
2436 | rc = diag210(&diag_data); | |
2437 | if (rc == 0 || rc == 2) { | |
2438 | return diag_data.vrdcvfla & 0x80; | |
2439 | } else { | |
2440 | DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d", | |
2441 | dev_id.devno, rc); | |
2442 | return 0; | |
2443 | } | |
2444 | } | |
2445 | EXPORT_SYMBOL_GPL(dasd_device_is_ro); | |
2446 | ||
f3445a1a CH |
2447 | static void dasd_generic_auto_online(void *data, async_cookie_t cookie) |
2448 | { | |
2449 | struct ccw_device *cdev = data; | |
2450 | int ret; | |
2451 | ||
2452 | ret = ccw_device_set_online(cdev); | |
2453 | if (ret) | |
2454 | pr_warning("%s: Setting the DASD online failed with rc=%d\n", | |
2455 | dev_name(&cdev->dev), ret); | |
f3445a1a CH |
2456 | } |
2457 | ||
1c01b8a5 HH |
2458 | /* |
2459 | * Initial attempt at a probe function. this can be simplified once | |
2460 | * the other detection code is gone. | |
2461 | */ | |
8e09f215 SW |
2462 | int dasd_generic_probe(struct ccw_device *cdev, |
2463 | struct dasd_discipline *discipline) | |
1da177e4 LT |
2464 | { |
2465 | int ret; | |
2466 | ||
2467 | ret = dasd_add_sysfs_files(cdev); | |
2468 | if (ret) { | |
b8ed5dd5 SH |
2469 | DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s", |
2470 | "dasd_generic_probe: could not add " | |
2471 | "sysfs entries"); | |
40545573 | 2472 | return ret; |
1da177e4 | 2473 | } |
40545573 | 2474 | cdev->handler = &dasd_int_handler; |
1da177e4 | 2475 | |
40545573 HH |
2476 | /* |
2477 | * Automatically online either all dasd devices (dasd_autodetect) | |
2478 | * or all devices specified with dasd= parameters during | |
2479 | * initial probe. | |
2480 | */ | |
2481 | if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) || | |
2a0217d5 | 2482 | (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0)) |
f3445a1a | 2483 | async_schedule(dasd_generic_auto_online, cdev); |
de3e0da1 | 2484 | return 0; |
1da177e4 LT |
2485 | } |
2486 | ||
1c01b8a5 HH |
2487 | /* |
2488 | * This will one day be called from a global not_oper handler. | |
2489 | * It is also used by driver_unregister during module unload. | |
2490 | */ | |
8e09f215 | 2491 | void dasd_generic_remove(struct ccw_device *cdev) |
1da177e4 LT |
2492 | { |
2493 | struct dasd_device *device; | |
8e09f215 | 2494 | struct dasd_block *block; |
1da177e4 | 2495 | |
59afda78 HH |
2496 | cdev->handler = NULL; |
2497 | ||
1da177e4 LT |
2498 | dasd_remove_sysfs_files(cdev); |
2499 | device = dasd_device_from_cdev(cdev); | |
2500 | if (IS_ERR(device)) | |
2501 | return; | |
2502 | if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) { | |
2503 | /* Already doing offline processing */ | |
2504 | dasd_put_device(device); | |
2505 | return; | |
2506 | } | |
2507 | /* | |
2508 | * This device is removed unconditionally. Set offline | |
2509 | * flag to prevent dasd_open from opening it while it is | |
2510 | * no quite down yet. | |
2511 | */ | |
2512 | dasd_set_target_state(device, DASD_STATE_NEW); | |
2513 | /* dasd_delete_device destroys the device reference. */ | |
8e09f215 SW |
2514 | block = device->block; |
2515 | device->block = NULL; | |
1da177e4 | 2516 | dasd_delete_device(device); |
8e09f215 SW |
2517 | /* |
2518 | * life cycle of block is bound to device, so delete it after | |
2519 | * device was safely removed | |
2520 | */ | |
2521 | if (block) | |
2522 | dasd_free_block(block); | |
1da177e4 LT |
2523 | } |
2524 | ||
1c01b8a5 HH |
2525 | /* |
2526 | * Activate a device. This is called from dasd_{eckd,fba}_probe() when either | |
1da177e4 | 2527 | * the device is detected for the first time and is supposed to be used |
1c01b8a5 HH |
2528 | * or the user has started activation through sysfs. |
2529 | */ | |
8e09f215 SW |
2530 | int dasd_generic_set_online(struct ccw_device *cdev, |
2531 | struct dasd_discipline *base_discipline) | |
1da177e4 | 2532 | { |
aa88861f | 2533 | struct dasd_discipline *discipline; |
1da177e4 | 2534 | struct dasd_device *device; |
c6eb7b77 | 2535 | int rc; |
f24acd45 | 2536 | |
40545573 HH |
2537 | /* first online clears initial online feature flag */ |
2538 | dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0); | |
1da177e4 LT |
2539 | device = dasd_create_device(cdev); |
2540 | if (IS_ERR(device)) | |
2541 | return PTR_ERR(device); | |
2542 | ||
aa88861f | 2543 | discipline = base_discipline; |
c6eb7b77 | 2544 | if (device->features & DASD_FEATURE_USEDIAG) { |
1da177e4 | 2545 | if (!dasd_diag_discipline_pointer) { |
fc19f381 SH |
2546 | pr_warning("%s Setting the DASD online failed because " |
2547 | "of missing DIAG discipline\n", | |
2548 | dev_name(&cdev->dev)); | |
1da177e4 LT |
2549 | dasd_delete_device(device); |
2550 | return -ENODEV; | |
2551 | } | |
2552 | discipline = dasd_diag_discipline_pointer; | |
2553 | } | |
aa88861f PO |
2554 | if (!try_module_get(base_discipline->owner)) { |
2555 | dasd_delete_device(device); | |
2556 | return -EINVAL; | |
2557 | } | |
2558 | if (!try_module_get(discipline->owner)) { | |
2559 | module_put(base_discipline->owner); | |
2560 | dasd_delete_device(device); | |
2561 | return -EINVAL; | |
2562 | } | |
2563 | device->base_discipline = base_discipline; | |
1da177e4 LT |
2564 | device->discipline = discipline; |
2565 | ||
8e09f215 | 2566 | /* check_device will allocate block device if necessary */ |
1da177e4 LT |
2567 | rc = discipline->check_device(device); |
2568 | if (rc) { | |
fc19f381 SH |
2569 | pr_warning("%s Setting the DASD online with discipline %s " |
2570 | "failed with rc=%i\n", | |
2571 | dev_name(&cdev->dev), discipline->name, rc); | |
aa88861f PO |
2572 | module_put(discipline->owner); |
2573 | module_put(base_discipline->owner); | |
1da177e4 LT |
2574 | dasd_delete_device(device); |
2575 | return rc; | |
2576 | } | |
2577 | ||
2578 | dasd_set_target_state(device, DASD_STATE_ONLINE); | |
2579 | if (device->state <= DASD_STATE_KNOWN) { | |
fc19f381 SH |
2580 | pr_warning("%s Setting the DASD online failed because of a " |
2581 | "missing discipline\n", dev_name(&cdev->dev)); | |
1da177e4 LT |
2582 | rc = -ENODEV; |
2583 | dasd_set_target_state(device, DASD_STATE_NEW); | |
8e09f215 SW |
2584 | if (device->block) |
2585 | dasd_free_block(device->block); | |
1da177e4 LT |
2586 | dasd_delete_device(device); |
2587 | } else | |
2588 | pr_debug("dasd_generic device %s found\n", | |
2a0217d5 | 2589 | dev_name(&cdev->dev)); |
589c74d5 SH |
2590 | |
2591 | wait_event(dasd_init_waitq, _wait_for_device(device)); | |
2592 | ||
1da177e4 | 2593 | dasd_put_device(device); |
1da177e4 LT |
2594 | return rc; |
2595 | } | |
2596 | ||
8e09f215 | 2597 | int dasd_generic_set_offline(struct ccw_device *cdev) |
1da177e4 LT |
2598 | { |
2599 | struct dasd_device *device; | |
8e09f215 | 2600 | struct dasd_block *block; |
dafd87aa | 2601 | int max_count, open_count; |
1da177e4 LT |
2602 | |
2603 | device = dasd_device_from_cdev(cdev); | |
2604 | if (IS_ERR(device)) | |
2605 | return PTR_ERR(device); | |
2606 | if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) { | |
2607 | /* Already doing offline processing */ | |
2608 | dasd_put_device(device); | |
2609 | return 0; | |
2610 | } | |
2611 | /* | |
2612 | * We must make sure that this device is currently not in use. | |
2613 | * The open_count is increased for every opener, that includes | |
2614 | * the blkdev_get in dasd_scan_partitions. We are only interested | |
2615 | * in the other openers. | |
2616 | */ | |
8e09f215 | 2617 | if (device->block) { |
a806170e HC |
2618 | max_count = device->block->bdev ? 0 : -1; |
2619 | open_count = atomic_read(&device->block->open_count); | |
8e09f215 SW |
2620 | if (open_count > max_count) { |
2621 | if (open_count > 0) | |
fc19f381 SH |
2622 | pr_warning("%s: The DASD cannot be set offline " |
2623 | "with open count %i\n", | |
2624 | dev_name(&cdev->dev), open_count); | |
8e09f215 | 2625 | else |
fc19f381 SH |
2626 | pr_warning("%s: The DASD cannot be set offline " |
2627 | "while it is in use\n", | |
2628 | dev_name(&cdev->dev)); | |
8e09f215 SW |
2629 | clear_bit(DASD_FLAG_OFFLINE, &device->flags); |
2630 | dasd_put_device(device); | |
2631 | return -EBUSY; | |
2632 | } | |
1da177e4 LT |
2633 | } |
2634 | dasd_set_target_state(device, DASD_STATE_NEW); | |
2635 | /* dasd_delete_device destroys the device reference. */ | |
8e09f215 SW |
2636 | block = device->block; |
2637 | device->block = NULL; | |
1da177e4 | 2638 | dasd_delete_device(device); |
8e09f215 SW |
2639 | /* |
2640 | * life cycle of block is bound to device, so delete it after | |
2641 | * device was safely removed | |
2642 | */ | |
2643 | if (block) | |
2644 | dasd_free_block(block); | |
1da177e4 LT |
2645 | return 0; |
2646 | } | |
2647 | ||
a4d26c6a SW |
2648 | int dasd_generic_last_path_gone(struct dasd_device *device) |
2649 | { | |
2650 | struct dasd_ccw_req *cqr; | |
2651 | ||
2652 | dev_warn(&device->cdev->dev, "No operational channel path is left " | |
2653 | "for the device\n"); | |
2654 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone"); | |
2655 | /* First of all call extended error reporting. */ | |
2656 | dasd_eer_write(device, NULL, DASD_EER_NOPATH); | |
2657 | ||
2658 | if (device->state < DASD_STATE_BASIC) | |
2659 | return 0; | |
2660 | /* Device is active. We want to keep it. */ | |
2661 | list_for_each_entry(cqr, &device->ccw_queue, devlist) | |
2662 | if ((cqr->status == DASD_CQR_IN_IO) || | |
2663 | (cqr->status == DASD_CQR_CLEAR_PENDING)) { | |
2664 | cqr->status = DASD_CQR_QUEUED; | |
2665 | cqr->retries++; | |
2666 | } | |
2667 | dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT); | |
2668 | dasd_device_clear_timer(device); | |
2669 | dasd_schedule_device_bh(device); | |
2670 | return 1; | |
2671 | } | |
2672 | EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone); | |
2673 | ||
2674 | int dasd_generic_path_operational(struct dasd_device *device) | |
2675 | { | |
2676 | dev_info(&device->cdev->dev, "A channel path to the device has become " | |
2677 | "operational\n"); | |
2678 | DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational"); | |
2679 | dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT); | |
2680 | if (device->stopped & DASD_UNRESUMED_PM) { | |
2681 | dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM); | |
2682 | dasd_restore_device(device); | |
2683 | return 1; | |
2684 | } | |
2685 | dasd_schedule_device_bh(device); | |
2686 | if (device->block) | |
2687 | dasd_schedule_block_bh(device->block); | |
2688 | return 1; | |
2689 | } | |
2690 | EXPORT_SYMBOL_GPL(dasd_generic_path_operational); | |
2691 | ||
8e09f215 | 2692 | int dasd_generic_notify(struct ccw_device *cdev, int event) |
1da177e4 LT |
2693 | { |
2694 | struct dasd_device *device; | |
1da177e4 LT |
2695 | int ret; |
2696 | ||
91c36919 | 2697 | device = dasd_device_from_cdev_locked(cdev); |
1da177e4 LT |
2698 | if (IS_ERR(device)) |
2699 | return 0; | |
1da177e4 LT |
2700 | ret = 0; |
2701 | switch (event) { | |
2702 | case CIO_GONE: | |
47593bfa | 2703 | case CIO_BOXED: |
1da177e4 | 2704 | case CIO_NO_PATH: |
a4d26c6a SW |
2705 | device->path_data.opm = 0; |
2706 | device->path_data.ppm = 0; | |
2707 | device->path_data.npm = 0; | |
2708 | ret = dasd_generic_last_path_gone(device); | |
1da177e4 LT |
2709 | break; |
2710 | case CIO_OPER: | |
1da177e4 | 2711 | ret = 1; |
a4d26c6a SW |
2712 | if (device->path_data.opm) |
2713 | ret = dasd_generic_path_operational(device); | |
1da177e4 LT |
2714 | break; |
2715 | } | |
1da177e4 LT |
2716 | dasd_put_device(device); |
2717 | return ret; | |
2718 | } | |
2719 | ||
a4d26c6a SW |
2720 | void dasd_generic_path_event(struct ccw_device *cdev, int *path_event) |
2721 | { | |
2722 | int chp; | |
2723 | __u8 oldopm, eventlpm; | |
2724 | struct dasd_device *device; | |
2725 | ||
2726 | device = dasd_device_from_cdev_locked(cdev); | |
2727 | if (IS_ERR(device)) | |
2728 | return; | |
2729 | for (chp = 0; chp < 8; chp++) { | |
2730 | eventlpm = 0x80 >> chp; | |
2731 | if (path_event[chp] & PE_PATH_GONE) { | |
2732 | oldopm = device->path_data.opm; | |
2733 | device->path_data.opm &= ~eventlpm; | |
2734 | device->path_data.ppm &= ~eventlpm; | |
2735 | device->path_data.npm &= ~eventlpm; | |
2736 | if (oldopm && !device->path_data.opm) | |
2737 | dasd_generic_last_path_gone(device); | |
2738 | } | |
2739 | if (path_event[chp] & PE_PATH_AVAILABLE) { | |
2740 | device->path_data.opm &= ~eventlpm; | |
2741 | device->path_data.ppm &= ~eventlpm; | |
2742 | device->path_data.npm &= ~eventlpm; | |
2743 | device->path_data.tbvpm |= eventlpm; | |
2744 | dasd_schedule_device_bh(device); | |
2745 | } | |
2746 | } | |
2747 | dasd_put_device(device); | |
2748 | } | |
2749 | EXPORT_SYMBOL_GPL(dasd_generic_path_event); | |
2750 | ||
2751 | int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm) | |
2752 | { | |
2753 | if (!device->path_data.opm && lpm) { | |
2754 | device->path_data.opm = lpm; | |
2755 | dasd_generic_path_operational(device); | |
2756 | } else | |
2757 | device->path_data.opm |= lpm; | |
2758 | return 0; | |
2759 | } | |
2760 | EXPORT_SYMBOL_GPL(dasd_generic_verify_path); | |
2761 | ||
2762 | ||
d41dd122 SH |
2763 | int dasd_generic_pm_freeze(struct ccw_device *cdev) |
2764 | { | |
2765 | struct dasd_ccw_req *cqr, *n; | |
2766 | int rc; | |
2767 | struct list_head freeze_queue; | |
2768 | struct dasd_device *device = dasd_device_from_cdev(cdev); | |
2769 | ||
2770 | if (IS_ERR(device)) | |
2771 | return PTR_ERR(device); | |
2772 | /* disallow new I/O */ | |
eb6e199b | 2773 | dasd_device_set_stop_bits(device, DASD_STOPPED_PM); |
d41dd122 SH |
2774 | /* clear active requests */ |
2775 | INIT_LIST_HEAD(&freeze_queue); | |
2776 | spin_lock_irq(get_ccwdev_lock(cdev)); | |
2777 | rc = 0; | |
2778 | list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) { | |
2779 | /* Check status and move request to flush_queue */ | |
2780 | if (cqr->status == DASD_CQR_IN_IO) { | |
2781 | rc = device->discipline->term_IO(cqr); | |
2782 | if (rc) { | |
2783 | /* unable to terminate requeust */ | |
2784 | dev_err(&device->cdev->dev, | |
2785 | "Unable to terminate request %p " | |
2786 | "on suspend\n", cqr); | |
2787 | spin_unlock_irq(get_ccwdev_lock(cdev)); | |
2788 | dasd_put_device(device); | |
2789 | return rc; | |
2790 | } | |
2791 | } | |
2792 | list_move_tail(&cqr->devlist, &freeze_queue); | |
2793 | } | |
2794 | ||
2795 | spin_unlock_irq(get_ccwdev_lock(cdev)); | |
2796 | ||
2797 | list_for_each_entry_safe(cqr, n, &freeze_queue, devlist) { | |
2798 | wait_event(dasd_flush_wq, | |
2799 | (cqr->status != DASD_CQR_CLEAR_PENDING)); | |
2800 | if (cqr->status == DASD_CQR_CLEARED) | |
2801 | cqr->status = DASD_CQR_QUEUED; | |
2802 | } | |
2803 | /* move freeze_queue to start of the ccw_queue */ | |
2804 | spin_lock_irq(get_ccwdev_lock(cdev)); | |
2805 | list_splice_tail(&freeze_queue, &device->ccw_queue); | |
2806 | spin_unlock_irq(get_ccwdev_lock(cdev)); | |
2807 | ||
2808 | if (device->discipline->freeze) | |
2809 | rc = device->discipline->freeze(device); | |
2810 | ||
2811 | dasd_put_device(device); | |
2812 | return rc; | |
2813 | } | |
2814 | EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze); | |
2815 | ||
2816 | int dasd_generic_restore_device(struct ccw_device *cdev) | |
2817 | { | |
2818 | struct dasd_device *device = dasd_device_from_cdev(cdev); | |
2819 | int rc = 0; | |
2820 | ||
2821 | if (IS_ERR(device)) | |
2822 | return PTR_ERR(device); | |
2823 | ||
e6125fba | 2824 | /* allow new IO again */ |
eb6e199b SW |
2825 | dasd_device_remove_stop_bits(device, |
2826 | (DASD_STOPPED_PM | DASD_UNRESUMED_PM)); | |
e6125fba | 2827 | |
d41dd122 | 2828 | dasd_schedule_device_bh(device); |
d41dd122 | 2829 | |
eb6e199b SW |
2830 | /* |
2831 | * call discipline restore function | |
2832 | * if device is stopped do nothing e.g. for disconnected devices | |
2833 | */ | |
2834 | if (device->discipline->restore && !(device->stopped)) | |
d41dd122 | 2835 | rc = device->discipline->restore(device); |
eb6e199b | 2836 | if (rc || device->stopped) |
e6125fba SH |
2837 | /* |
2838 | * if the resume failed for the DASD we put it in | |
2839 | * an UNRESUMED stop state | |
2840 | */ | |
2841 | device->stopped |= DASD_UNRESUMED_PM; | |
d41dd122 | 2842 | |
6fca97a9 SH |
2843 | if (device->block) |
2844 | dasd_schedule_block_bh(device->block); | |
2845 | ||
d41dd122 | 2846 | dasd_put_device(device); |
e6125fba | 2847 | return 0; |
d41dd122 SH |
2848 | } |
2849 | EXPORT_SYMBOL_GPL(dasd_generic_restore_device); | |
2850 | ||
763968e2 HC |
2851 | static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device, |
2852 | void *rdc_buffer, | |
2853 | int rdc_buffer_size, | |
68b781fe | 2854 | int magic) |
17283b56 CH |
2855 | { |
2856 | struct dasd_ccw_req *cqr; | |
2857 | struct ccw1 *ccw; | |
d9fa9441 | 2858 | unsigned long *idaw; |
17283b56 CH |
2859 | |
2860 | cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device); | |
2861 | ||
2862 | if (IS_ERR(cqr)) { | |
fc19f381 SH |
2863 | /* internal error 13 - Allocating the RDC request failed*/ |
2864 | dev_err(&device->cdev->dev, | |
2865 | "An error occurred in the DASD device driver, " | |
2866 | "reason=%s\n", "13"); | |
17283b56 CH |
2867 | return cqr; |
2868 | } | |
2869 | ||
2870 | ccw = cqr->cpaddr; | |
2871 | ccw->cmd_code = CCW_CMD_RDC; | |
d9fa9441 SH |
2872 | if (idal_is_needed(rdc_buffer, rdc_buffer_size)) { |
2873 | idaw = (unsigned long *) (cqr->data); | |
2874 | ccw->cda = (__u32)(addr_t) idaw; | |
2875 | ccw->flags = CCW_FLAG_IDA; | |
2876 | idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size); | |
2877 | } else { | |
2878 | ccw->cda = (__u32)(addr_t) rdc_buffer; | |
2879 | ccw->flags = 0; | |
2880 | } | |
17283b56 | 2881 | |
d9fa9441 | 2882 | ccw->count = rdc_buffer_size; |
8e09f215 SW |
2883 | cqr->startdev = device; |
2884 | cqr->memdev = device; | |
17283b56 | 2885 | cqr->expires = 10*HZ; |
eb6e199b | 2886 | cqr->retries = 256; |
17283b56 CH |
2887 | cqr->buildclk = get_clock(); |
2888 | cqr->status = DASD_CQR_FILLED; | |
2889 | return cqr; | |
2890 | } | |
2891 | ||
2892 | ||
68b781fe | 2893 | int dasd_generic_read_dev_chars(struct dasd_device *device, int magic, |
92636b15 | 2894 | void *rdc_buffer, int rdc_buffer_size) |
17283b56 CH |
2895 | { |
2896 | int ret; | |
2897 | struct dasd_ccw_req *cqr; | |
2898 | ||
92636b15 | 2899 | cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size, |
17283b56 CH |
2900 | magic); |
2901 | if (IS_ERR(cqr)) | |
2902 | return PTR_ERR(cqr); | |
2903 | ||
2904 | ret = dasd_sleep_on(cqr); | |
8e09f215 | 2905 | dasd_sfree_request(cqr, cqr->memdev); |
17283b56 CH |
2906 | return ret; |
2907 | } | |
aaff0f64 | 2908 | EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars); |
20c64468 | 2909 | |
f3eb5384 SW |
2910 | /* |
2911 | * In command mode and transport mode we need to look for sense | |
2912 | * data in different places. The sense data itself is allways | |
2913 | * an array of 32 bytes, so we can unify the sense data access | |
2914 | * for both modes. | |
2915 | */ | |
2916 | char *dasd_get_sense(struct irb *irb) | |
2917 | { | |
2918 | struct tsb *tsb = NULL; | |
2919 | char *sense = NULL; | |
2920 | ||
2921 | if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) { | |
2922 | if (irb->scsw.tm.tcw) | |
2923 | tsb = tcw_get_tsb((struct tcw *)(unsigned long) | |
2924 | irb->scsw.tm.tcw); | |
2925 | if (tsb && tsb->length == 64 && tsb->flags) | |
2926 | switch (tsb->flags & 0x07) { | |
2927 | case 1: /* tsa_iostat */ | |
2928 | sense = tsb->tsa.iostat.sense; | |
2929 | break; | |
2930 | case 2: /* tsa_ddpc */ | |
2931 | sense = tsb->tsa.ddpc.sense; | |
2932 | break; | |
2933 | default: | |
2934 | /* currently we don't use interrogate data */ | |
2935 | break; | |
2936 | } | |
2937 | } else if (irb->esw.esw0.erw.cons) { | |
2938 | sense = irb->ecw; | |
2939 | } | |
2940 | return sense; | |
2941 | } | |
2942 | EXPORT_SYMBOL_GPL(dasd_get_sense); | |
2943 | ||
8e09f215 | 2944 | static int __init dasd_init(void) |
1da177e4 LT |
2945 | { |
2946 | int rc; | |
2947 | ||
2948 | init_waitqueue_head(&dasd_init_waitq); | |
8f61701b | 2949 | init_waitqueue_head(&dasd_flush_wq); |
c80ee724 | 2950 | init_waitqueue_head(&generic_waitq); |
1da177e4 LT |
2951 | |
2952 | /* register 'common' DASD debug area, used for all DBF_XXX calls */ | |
361f494d | 2953 | dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long)); |
1da177e4 LT |
2954 | if (dasd_debug_area == NULL) { |
2955 | rc = -ENOMEM; | |
2956 | goto failed; | |
2957 | } | |
2958 | debug_register_view(dasd_debug_area, &debug_sprintf_view); | |
b0035f12 | 2959 | debug_set_level(dasd_debug_area, DBF_WARNING); |
1da177e4 LT |
2960 | |
2961 | DBF_EVENT(DBF_EMERG, "%s", "debug area created"); | |
2962 | ||
2963 | dasd_diag_discipline_pointer = NULL; | |
2964 | ||
1da177e4 LT |
2965 | rc = dasd_devmap_init(); |
2966 | if (rc) | |
2967 | goto failed; | |
2968 | rc = dasd_gendisk_init(); | |
2969 | if (rc) | |
2970 | goto failed; | |
2971 | rc = dasd_parse(); | |
2972 | if (rc) | |
2973 | goto failed; | |
20c64468 SW |
2974 | rc = dasd_eer_init(); |
2975 | if (rc) | |
2976 | goto failed; | |
1da177e4 LT |
2977 | #ifdef CONFIG_PROC_FS |
2978 | rc = dasd_proc_init(); | |
2979 | if (rc) | |
2980 | goto failed; | |
2981 | #endif | |
2982 | ||
2983 | return 0; | |
2984 | failed: | |
fc19f381 | 2985 | pr_info("The DASD device driver could not be initialized\n"); |
1da177e4 LT |
2986 | dasd_exit(); |
2987 | return rc; | |
2988 | } | |
2989 | ||
2990 | module_init(dasd_init); | |
2991 | module_exit(dasd_exit); | |
2992 | ||
2993 | EXPORT_SYMBOL(dasd_debug_area); | |
2994 | EXPORT_SYMBOL(dasd_diag_discipline_pointer); | |
2995 | ||
2996 | EXPORT_SYMBOL(dasd_add_request_head); | |
2997 | EXPORT_SYMBOL(dasd_add_request_tail); | |
2998 | EXPORT_SYMBOL(dasd_cancel_req); | |
8e09f215 SW |
2999 | EXPORT_SYMBOL(dasd_device_clear_timer); |
3000 | EXPORT_SYMBOL(dasd_block_clear_timer); | |
1da177e4 LT |
3001 | EXPORT_SYMBOL(dasd_enable_device); |
3002 | EXPORT_SYMBOL(dasd_int_handler); | |
3003 | EXPORT_SYMBOL(dasd_kfree_request); | |
3004 | EXPORT_SYMBOL(dasd_kick_device); | |
3005 | EXPORT_SYMBOL(dasd_kmalloc_request); | |
8e09f215 SW |
3006 | EXPORT_SYMBOL(dasd_schedule_device_bh); |
3007 | EXPORT_SYMBOL(dasd_schedule_block_bh); | |
1da177e4 | 3008 | EXPORT_SYMBOL(dasd_set_target_state); |
8e09f215 SW |
3009 | EXPORT_SYMBOL(dasd_device_set_timer); |
3010 | EXPORT_SYMBOL(dasd_block_set_timer); | |
1da177e4 LT |
3011 | EXPORT_SYMBOL(dasd_sfree_request); |
3012 | EXPORT_SYMBOL(dasd_sleep_on); | |
3013 | EXPORT_SYMBOL(dasd_sleep_on_immediatly); | |
3014 | EXPORT_SYMBOL(dasd_sleep_on_interruptible); | |
3015 | EXPORT_SYMBOL(dasd_smalloc_request); | |
3016 | EXPORT_SYMBOL(dasd_start_IO); | |
3017 | EXPORT_SYMBOL(dasd_term_IO); | |
3018 | ||
3019 | EXPORT_SYMBOL_GPL(dasd_generic_probe); | |
3020 | EXPORT_SYMBOL_GPL(dasd_generic_remove); | |
3021 | EXPORT_SYMBOL_GPL(dasd_generic_notify); | |
3022 | EXPORT_SYMBOL_GPL(dasd_generic_set_online); | |
3023 | EXPORT_SYMBOL_GPL(dasd_generic_set_offline); | |
8e09f215 SW |
3024 | EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change); |
3025 | EXPORT_SYMBOL_GPL(dasd_flush_device_queue); | |
3026 | EXPORT_SYMBOL_GPL(dasd_alloc_block); | |
3027 | EXPORT_SYMBOL_GPL(dasd_free_block); |