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