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