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