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>
7 * Copyright IBM Corp. 1999, 2009
10 #define KMSG_COMPONENT "dasd"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
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>
19 #include <linux/hdreg.h>
20 #include <linux/async.h>
21 #include <linux/mutex.h>
22 #include <linux/debugfs.h>
23 #include <linux/seq_file.h>
24 #include <linux/vmalloc.h>
26 #include <asm/ccwdev.h>
27 #include <asm/ebcdic.h>
28 #include <asm/idals.h>
33 #define PRINTK_HEADER "dasd:"
37 * SECTION: Constant definitions to be used within this file
39 #define DASD_CHANQ_MAX_SIZE 4
42 * SECTION: exported variables of dasd.c
44 debug_info_t
*dasd_debug_area
;
45 static struct dentry
*dasd_debugfs_root_entry
;
46 struct dasd_discipline
*dasd_diag_discipline_pointer
;
47 void dasd_int_handler(struct ccw_device
*, unsigned long, struct irb
*);
49 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
50 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
51 " Copyright IBM Corp. 2000");
52 MODULE_SUPPORTED_DEVICE("dasd");
53 MODULE_LICENSE("GPL");
56 * SECTION: prototypes for static functions of dasd.c
58 static int dasd_alloc_queue(struct dasd_block
*);
59 static void dasd_setup_queue(struct dasd_block
*);
60 static void dasd_free_queue(struct dasd_block
*);
61 static void dasd_flush_request_queue(struct dasd_block
*);
62 static int dasd_flush_block_queue(struct dasd_block
*);
63 static void dasd_device_tasklet(struct dasd_device
*);
64 static void dasd_block_tasklet(struct dasd_block
*);
65 static void do_kick_device(struct work_struct
*);
66 static void do_restore_device(struct work_struct
*);
67 static void do_reload_device(struct work_struct
*);
68 static void dasd_return_cqr_cb(struct dasd_ccw_req
*, void *);
69 static void dasd_device_timeout(unsigned long);
70 static void dasd_block_timeout(unsigned long);
71 static void __dasd_process_erp(struct dasd_device
*, struct dasd_ccw_req
*);
72 static void dasd_profile_init(struct dasd_profile
*, struct dentry
*);
73 static void dasd_profile_exit(struct dasd_profile
*);
76 * SECTION: Operations on the device structure.
78 static wait_queue_head_t dasd_init_waitq
;
79 static wait_queue_head_t dasd_flush_wq
;
80 static wait_queue_head_t generic_waitq
;
81 static wait_queue_head_t shutdown_waitq
;
84 * Allocate memory for a new device structure.
86 struct dasd_device
*dasd_alloc_device(void)
88 struct dasd_device
*device
;
90 device
= kzalloc(sizeof(struct dasd_device
), GFP_ATOMIC
);
92 return ERR_PTR(-ENOMEM
);
94 /* Get two pages for normal block device operations. */
95 device
->ccw_mem
= (void *) __get_free_pages(GFP_ATOMIC
| GFP_DMA
, 1);
96 if (!device
->ccw_mem
) {
98 return ERR_PTR(-ENOMEM
);
100 /* Get one page for error recovery. */
101 device
->erp_mem
= (void *) get_zeroed_page(GFP_ATOMIC
| GFP_DMA
);
102 if (!device
->erp_mem
) {
103 free_pages((unsigned long) device
->ccw_mem
, 1);
105 return ERR_PTR(-ENOMEM
);
108 dasd_init_chunklist(&device
->ccw_chunks
, device
->ccw_mem
, PAGE_SIZE
*2);
109 dasd_init_chunklist(&device
->erp_chunks
, device
->erp_mem
, PAGE_SIZE
);
110 spin_lock_init(&device
->mem_lock
);
111 atomic_set(&device
->tasklet_scheduled
, 0);
112 tasklet_init(&device
->tasklet
,
113 (void (*)(unsigned long)) dasd_device_tasklet
,
114 (unsigned long) device
);
115 INIT_LIST_HEAD(&device
->ccw_queue
);
116 init_timer(&device
->timer
);
117 device
->timer
.function
= dasd_device_timeout
;
118 device
->timer
.data
= (unsigned long) device
;
119 INIT_WORK(&device
->kick_work
, do_kick_device
);
120 INIT_WORK(&device
->restore_device
, do_restore_device
);
121 INIT_WORK(&device
->reload_device
, do_reload_device
);
122 device
->state
= DASD_STATE_NEW
;
123 device
->target
= DASD_STATE_NEW
;
124 mutex_init(&device
->state_mutex
);
125 spin_lock_init(&device
->profile
.lock
);
130 * Free memory of a device structure.
132 void dasd_free_device(struct dasd_device
*device
)
134 kfree(device
->private);
135 free_page((unsigned long) device
->erp_mem
);
136 free_pages((unsigned long) device
->ccw_mem
, 1);
141 * Allocate memory for a new device structure.
143 struct dasd_block
*dasd_alloc_block(void)
145 struct dasd_block
*block
;
147 block
= kzalloc(sizeof(*block
), GFP_ATOMIC
);
149 return ERR_PTR(-ENOMEM
);
150 /* open_count = 0 means device online but not in use */
151 atomic_set(&block
->open_count
, -1);
153 spin_lock_init(&block
->request_queue_lock
);
154 atomic_set(&block
->tasklet_scheduled
, 0);
155 tasklet_init(&block
->tasklet
,
156 (void (*)(unsigned long)) dasd_block_tasklet
,
157 (unsigned long) block
);
158 INIT_LIST_HEAD(&block
->ccw_queue
);
159 spin_lock_init(&block
->queue_lock
);
160 init_timer(&block
->timer
);
161 block
->timer
.function
= dasd_block_timeout
;
162 block
->timer
.data
= (unsigned long) block
;
163 spin_lock_init(&block
->profile
.lock
);
169 * Free memory of a device structure.
171 void dasd_free_block(struct dasd_block
*block
)
177 * Make a new device known to the system.
179 static int dasd_state_new_to_known(struct dasd_device
*device
)
184 * As long as the device is not in state DASD_STATE_NEW we want to
185 * keep the reference count > 0.
187 dasd_get_device(device
);
190 rc
= dasd_alloc_queue(device
->block
);
192 dasd_put_device(device
);
196 device
->state
= DASD_STATE_KNOWN
;
201 * Let the system forget about a device.
203 static int dasd_state_known_to_new(struct dasd_device
*device
)
205 /* Disable extended error reporting for this device. */
206 dasd_eer_disable(device
);
207 /* Forget the discipline information. */
208 if (device
->discipline
) {
209 if (device
->discipline
->uncheck_device
)
210 device
->discipline
->uncheck_device(device
);
211 module_put(device
->discipline
->owner
);
213 device
->discipline
= NULL
;
214 if (device
->base_discipline
)
215 module_put(device
->base_discipline
->owner
);
216 device
->base_discipline
= NULL
;
217 device
->state
= DASD_STATE_NEW
;
220 dasd_free_queue(device
->block
);
222 /* Give up reference we took in dasd_state_new_to_known. */
223 dasd_put_device(device
);
227 static struct dentry
*dasd_debugfs_setup(const char *name
,
228 struct dentry
*base_dentry
)
234 pde
= debugfs_create_dir(name
, base_dentry
);
235 if (!pde
|| IS_ERR(pde
))
241 * Request the irq line for the device.
243 static int dasd_state_known_to_basic(struct dasd_device
*device
)
245 struct dasd_block
*block
= device
->block
;
248 /* Allocate and register gendisk structure. */
250 rc
= dasd_gendisk_alloc(block
);
253 block
->debugfs_dentry
=
254 dasd_debugfs_setup(block
->gdp
->disk_name
,
255 dasd_debugfs_root_entry
);
256 dasd_profile_init(&block
->profile
, block
->debugfs_dentry
);
257 if (dasd_global_profile_level
== DASD_PROFILE_ON
)
258 dasd_profile_on(&device
->block
->profile
);
260 device
->debugfs_dentry
=
261 dasd_debugfs_setup(dev_name(&device
->cdev
->dev
),
262 dasd_debugfs_root_entry
);
263 dasd_profile_init(&device
->profile
, device
->debugfs_dentry
);
265 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
266 device
->debug_area
= debug_register(dev_name(&device
->cdev
->dev
), 4, 1,
268 debug_register_view(device
->debug_area
, &debug_sprintf_view
);
269 debug_set_level(device
->debug_area
, DBF_WARNING
);
270 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s", "debug area created");
272 device
->state
= DASD_STATE_BASIC
;
278 * Release the irq line for the device. Terminate any running i/o.
280 static int dasd_state_basic_to_known(struct dasd_device
*device
)
285 dasd_profile_exit(&device
->block
->profile
);
286 if (device
->block
->debugfs_dentry
)
287 debugfs_remove(device
->block
->debugfs_dentry
);
288 dasd_gendisk_free(device
->block
);
289 dasd_block_clear_timer(device
->block
);
291 rc
= dasd_flush_device_queue(device
);
294 dasd_device_clear_timer(device
);
295 dasd_profile_exit(&device
->profile
);
296 if (device
->debugfs_dentry
)
297 debugfs_remove(device
->debugfs_dentry
);
299 DBF_DEV_EVENT(DBF_EMERG
, device
, "%p debug area deleted", device
);
300 if (device
->debug_area
!= NULL
) {
301 debug_unregister(device
->debug_area
);
302 device
->debug_area
= NULL
;
304 device
->state
= DASD_STATE_KNOWN
;
309 * Do the initial analysis. The do_analysis function may return
310 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
311 * until the discipline decides to continue the startup sequence
312 * by calling the function dasd_change_state. The eckd disciplines
313 * uses this to start a ccw that detects the format. The completion
314 * interrupt for this detection ccw uses the kernel event daemon to
315 * trigger the call to dasd_change_state. All this is done in the
316 * discipline code, see dasd_eckd.c.
317 * After the analysis ccw is done (do_analysis returned 0) the block
319 * In case the analysis returns an error, the device setup is stopped
320 * (a fake disk was already added to allow formatting).
322 static int dasd_state_basic_to_ready(struct dasd_device
*device
)
325 struct dasd_block
*block
;
328 block
= device
->block
;
329 /* make disk known with correct capacity */
331 if (block
->base
->discipline
->do_analysis
!= NULL
)
332 rc
= block
->base
->discipline
->do_analysis(block
);
335 device
->state
= DASD_STATE_UNFMT
;
340 dasd_setup_queue(block
);
341 set_capacity(block
->gdp
,
342 block
->blocks
<< block
->s2b_shift
);
343 device
->state
= DASD_STATE_READY
;
344 rc
= dasd_scan_partitions(block
);
346 device
->state
= DASD_STATE_BASIC
;
350 device
->state
= DASD_STATE_READY
;
353 if (device
->discipline
->basic_to_ready
)
354 rc
= device
->discipline
->basic_to_ready(device
);
359 int _wait_for_empty_queues(struct dasd_device
*device
)
362 return list_empty(&device
->ccw_queue
) &&
363 list_empty(&device
->block
->ccw_queue
);
365 return list_empty(&device
->ccw_queue
);
369 * Remove device from block device layer. Destroy dirty buffers.
370 * Forget format information. Check if the target level is basic
371 * and if it is create fake disk for formatting.
373 static int dasd_state_ready_to_basic(struct dasd_device
*device
)
377 if (device
->discipline
->ready_to_basic
) {
378 rc
= device
->discipline
->ready_to_basic(device
);
382 device
->state
= DASD_STATE_BASIC
;
384 struct dasd_block
*block
= device
->block
;
385 rc
= dasd_flush_block_queue(block
);
387 device
->state
= DASD_STATE_READY
;
390 dasd_flush_request_queue(block
);
391 dasd_destroy_partitions(block
);
394 block
->s2b_shift
= 0;
402 static int dasd_state_unfmt_to_basic(struct dasd_device
*device
)
404 device
->state
= DASD_STATE_BASIC
;
409 * Make the device online and schedule the bottom half to start
410 * the requeueing of requests from the linux request queue to the
414 dasd_state_ready_to_online(struct dasd_device
* device
)
416 struct gendisk
*disk
;
417 struct disk_part_iter piter
;
418 struct hd_struct
*part
;
420 device
->state
= DASD_STATE_ONLINE
;
422 dasd_schedule_block_bh(device
->block
);
423 if ((device
->features
& DASD_FEATURE_USERAW
)) {
424 disk
= device
->block
->gdp
;
425 kobject_uevent(&disk_to_dev(disk
)->kobj
, KOBJ_CHANGE
);
428 disk
= device
->block
->bdev
->bd_disk
;
429 disk_part_iter_init(&piter
, disk
, DISK_PITER_INCL_PART0
);
430 while ((part
= disk_part_iter_next(&piter
)))
431 kobject_uevent(&part_to_dev(part
)->kobj
, KOBJ_CHANGE
);
432 disk_part_iter_exit(&piter
);
438 * Stop the requeueing of requests again.
440 static int dasd_state_online_to_ready(struct dasd_device
*device
)
443 struct gendisk
*disk
;
444 struct disk_part_iter piter
;
445 struct hd_struct
*part
;
447 if (device
->discipline
->online_to_ready
) {
448 rc
= device
->discipline
->online_to_ready(device
);
453 device
->state
= DASD_STATE_READY
;
454 if (device
->block
&& !(device
->features
& DASD_FEATURE_USERAW
)) {
455 disk
= device
->block
->bdev
->bd_disk
;
456 disk_part_iter_init(&piter
, disk
, DISK_PITER_INCL_PART0
);
457 while ((part
= disk_part_iter_next(&piter
)))
458 kobject_uevent(&part_to_dev(part
)->kobj
, KOBJ_CHANGE
);
459 disk_part_iter_exit(&piter
);
465 * Device startup state changes.
467 static int dasd_increase_state(struct dasd_device
*device
)
472 if (device
->state
== DASD_STATE_NEW
&&
473 device
->target
>= DASD_STATE_KNOWN
)
474 rc
= dasd_state_new_to_known(device
);
477 device
->state
== DASD_STATE_KNOWN
&&
478 device
->target
>= DASD_STATE_BASIC
)
479 rc
= dasd_state_known_to_basic(device
);
482 device
->state
== DASD_STATE_BASIC
&&
483 device
->target
>= DASD_STATE_READY
)
484 rc
= dasd_state_basic_to_ready(device
);
487 device
->state
== DASD_STATE_UNFMT
&&
488 device
->target
> DASD_STATE_UNFMT
)
492 device
->state
== DASD_STATE_READY
&&
493 device
->target
>= DASD_STATE_ONLINE
)
494 rc
= dasd_state_ready_to_online(device
);
500 * Device shutdown state changes.
502 static int dasd_decrease_state(struct dasd_device
*device
)
507 if (device
->state
== DASD_STATE_ONLINE
&&
508 device
->target
<= DASD_STATE_READY
)
509 rc
= dasd_state_online_to_ready(device
);
512 device
->state
== DASD_STATE_READY
&&
513 device
->target
<= DASD_STATE_BASIC
)
514 rc
= dasd_state_ready_to_basic(device
);
517 device
->state
== DASD_STATE_UNFMT
&&
518 device
->target
<= DASD_STATE_BASIC
)
519 rc
= dasd_state_unfmt_to_basic(device
);
522 device
->state
== DASD_STATE_BASIC
&&
523 device
->target
<= DASD_STATE_KNOWN
)
524 rc
= dasd_state_basic_to_known(device
);
527 device
->state
== DASD_STATE_KNOWN
&&
528 device
->target
<= DASD_STATE_NEW
)
529 rc
= dasd_state_known_to_new(device
);
535 * This is the main startup/shutdown routine.
537 static void dasd_change_state(struct dasd_device
*device
)
541 if (device
->state
== device
->target
)
542 /* Already where we want to go today... */
544 if (device
->state
< device
->target
)
545 rc
= dasd_increase_state(device
);
547 rc
= dasd_decrease_state(device
);
551 device
->target
= device
->state
;
553 /* let user-space know that the device status changed */
554 kobject_uevent(&device
->cdev
->dev
.kobj
, KOBJ_CHANGE
);
556 if (device
->state
== device
->target
)
557 wake_up(&dasd_init_waitq
);
561 * Kick starter for devices that did not complete the startup/shutdown
562 * procedure or were sleeping because of a pending state.
563 * dasd_kick_device will schedule a call do do_kick_device to the kernel
566 static void do_kick_device(struct work_struct
*work
)
568 struct dasd_device
*device
= container_of(work
, struct dasd_device
, kick_work
);
569 mutex_lock(&device
->state_mutex
);
570 dasd_change_state(device
);
571 mutex_unlock(&device
->state_mutex
);
572 dasd_schedule_device_bh(device
);
573 dasd_put_device(device
);
576 void dasd_kick_device(struct dasd_device
*device
)
578 dasd_get_device(device
);
579 /* queue call to dasd_kick_device to the kernel event daemon. */
580 schedule_work(&device
->kick_work
);
584 * dasd_reload_device will schedule a call do do_reload_device to the kernel
587 static void do_reload_device(struct work_struct
*work
)
589 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
591 device
->discipline
->reload(device
);
592 dasd_put_device(device
);
595 void dasd_reload_device(struct dasd_device
*device
)
597 dasd_get_device(device
);
598 /* queue call to dasd_reload_device to the kernel event daemon. */
599 schedule_work(&device
->reload_device
);
601 EXPORT_SYMBOL(dasd_reload_device
);
604 * dasd_restore_device will schedule a call do do_restore_device to the kernel
607 static void do_restore_device(struct work_struct
*work
)
609 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
611 device
->cdev
->drv
->restore(device
->cdev
);
612 dasd_put_device(device
);
615 void dasd_restore_device(struct dasd_device
*device
)
617 dasd_get_device(device
);
618 /* queue call to dasd_restore_device to the kernel event daemon. */
619 schedule_work(&device
->restore_device
);
623 * Set the target state for a device and starts the state change.
625 void dasd_set_target_state(struct dasd_device
*device
, int target
)
627 dasd_get_device(device
);
628 mutex_lock(&device
->state_mutex
);
629 /* If we are in probeonly mode stop at DASD_STATE_READY. */
630 if (dasd_probeonly
&& target
> DASD_STATE_READY
)
631 target
= DASD_STATE_READY
;
632 if (device
->target
!= target
) {
633 if (device
->state
== target
)
634 wake_up(&dasd_init_waitq
);
635 device
->target
= target
;
637 if (device
->state
!= device
->target
)
638 dasd_change_state(device
);
639 mutex_unlock(&device
->state_mutex
);
640 dasd_put_device(device
);
644 * Enable devices with device numbers in [from..to].
646 static inline int _wait_for_device(struct dasd_device
*device
)
648 return (device
->state
== device
->target
);
651 void dasd_enable_device(struct dasd_device
*device
)
653 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
654 if (device
->state
<= DASD_STATE_KNOWN
)
655 /* No discipline for device found. */
656 dasd_set_target_state(device
, DASD_STATE_NEW
);
657 /* Now wait for the devices to come up. */
658 wait_event(dasd_init_waitq
, _wait_for_device(device
));
660 dasd_reload_device(device
);
661 if (device
->discipline
->kick_validate
)
662 device
->discipline
->kick_validate(device
);
666 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
669 unsigned int dasd_global_profile_level
= DASD_PROFILE_OFF
;
671 #ifdef CONFIG_DASD_PROFILE
672 struct dasd_profile_info dasd_global_profile_data
;
673 static struct dentry
*dasd_global_profile_dentry
;
674 static struct dentry
*dasd_debugfs_global_entry
;
677 * Add profiling information for cqr before execution.
679 static void dasd_profile_start(struct dasd_block
*block
,
680 struct dasd_ccw_req
*cqr
,
684 unsigned int counter
;
685 struct dasd_device
*device
;
687 /* count the length of the chanq for statistics */
689 if (dasd_global_profile_level
|| block
->profile
.data
)
690 list_for_each(l
, &block
->ccw_queue
)
694 if (dasd_global_profile_level
) {
695 dasd_global_profile_data
.dasd_io_nr_req
[counter
]++;
696 if (rq_data_dir(req
) == READ
)
697 dasd_global_profile_data
.dasd_read_nr_req
[counter
]++;
700 spin_lock(&block
->profile
.lock
);
701 if (block
->profile
.data
) {
702 block
->profile
.data
->dasd_io_nr_req
[counter
]++;
703 if (rq_data_dir(req
) == READ
)
704 block
->profile
.data
->dasd_read_nr_req
[counter
]++;
706 spin_unlock(&block
->profile
.lock
);
709 * We count the request for the start device, even though it may run on
710 * some other device due to error recovery. This way we make sure that
711 * we count each request only once.
713 device
= cqr
->startdev
;
714 if (device
->profile
.data
) {
715 counter
= 1; /* request is not yet queued on the start device */
716 list_for_each(l
, &device
->ccw_queue
)
720 spin_lock(&device
->profile
.lock
);
721 if (device
->profile
.data
) {
722 device
->profile
.data
->dasd_io_nr_req
[counter
]++;
723 if (rq_data_dir(req
) == READ
)
724 device
->profile
.data
->dasd_read_nr_req
[counter
]++;
726 spin_unlock(&device
->profile
.lock
);
730 * Add profiling information for cqr after execution.
733 #define dasd_profile_counter(value, index) \
735 for (index = 0; index < 31 && value >> (2+index); index++) \
739 static void dasd_profile_end_add_data(struct dasd_profile_info
*data
,
752 /* in case of an overflow, reset the whole profile */
753 if (data
->dasd_io_reqs
== UINT_MAX
) {
754 memset(data
, 0, sizeof(*data
));
755 getnstimeofday(&data
->starttod
);
757 data
->dasd_io_reqs
++;
758 data
->dasd_io_sects
+= sectors
;
760 data
->dasd_io_alias
++;
764 data
->dasd_io_secs
[sectors_ind
]++;
765 data
->dasd_io_times
[tottime_ind
]++;
766 data
->dasd_io_timps
[tottimeps_ind
]++;
767 data
->dasd_io_time1
[strtime_ind
]++;
768 data
->dasd_io_time2
[irqtime_ind
]++;
769 data
->dasd_io_time2ps
[irqtimeps_ind
]++;
770 data
->dasd_io_time3
[endtime_ind
]++;
773 data
->dasd_read_reqs
++;
774 data
->dasd_read_sects
+= sectors
;
776 data
->dasd_read_alias
++;
778 data
->dasd_read_tpm
++;
779 data
->dasd_read_secs
[sectors_ind
]++;
780 data
->dasd_read_times
[tottime_ind
]++;
781 data
->dasd_read_time1
[strtime_ind
]++;
782 data
->dasd_read_time2
[irqtime_ind
]++;
783 data
->dasd_read_time3
[endtime_ind
]++;
787 static void dasd_profile_end(struct dasd_block
*block
,
788 struct dasd_ccw_req
*cqr
,
791 long strtime
, irqtime
, endtime
, tottime
; /* in microseconds */
792 long tottimeps
, sectors
;
793 struct dasd_device
*device
;
794 int sectors_ind
, tottime_ind
, tottimeps_ind
, strtime_ind
;
795 int irqtime_ind
, irqtimeps_ind
, endtime_ind
;
797 device
= cqr
->startdev
;
798 if (!(dasd_global_profile_level
||
799 block
->profile
.data
||
800 device
->profile
.data
))
803 sectors
= blk_rq_sectors(req
);
804 if (!cqr
->buildclk
|| !cqr
->startclk
||
805 !cqr
->stopclk
|| !cqr
->endclk
||
809 strtime
= ((cqr
->startclk
- cqr
->buildclk
) >> 12);
810 irqtime
= ((cqr
->stopclk
- cqr
->startclk
) >> 12);
811 endtime
= ((cqr
->endclk
- cqr
->stopclk
) >> 12);
812 tottime
= ((cqr
->endclk
- cqr
->buildclk
) >> 12);
813 tottimeps
= tottime
/ sectors
;
815 dasd_profile_counter(sectors
, sectors_ind
);
816 dasd_profile_counter(tottime
, tottime_ind
);
817 dasd_profile_counter(tottimeps
, tottimeps_ind
);
818 dasd_profile_counter(strtime
, strtime_ind
);
819 dasd_profile_counter(irqtime
, irqtime_ind
);
820 dasd_profile_counter(irqtime
/ sectors
, irqtimeps_ind
);
821 dasd_profile_counter(endtime
, endtime_ind
);
823 if (dasd_global_profile_level
) {
824 dasd_profile_end_add_data(&dasd_global_profile_data
,
825 cqr
->startdev
!= block
->base
,
827 rq_data_dir(req
) == READ
,
828 sectors
, sectors_ind
, tottime_ind
,
829 tottimeps_ind
, strtime_ind
,
830 irqtime_ind
, irqtimeps_ind
,
834 spin_lock(&block
->profile
.lock
);
835 if (block
->profile
.data
)
836 dasd_profile_end_add_data(block
->profile
.data
,
837 cqr
->startdev
!= block
->base
,
839 rq_data_dir(req
) == READ
,
840 sectors
, sectors_ind
, tottime_ind
,
841 tottimeps_ind
, strtime_ind
,
842 irqtime_ind
, irqtimeps_ind
,
844 spin_unlock(&block
->profile
.lock
);
846 spin_lock(&device
->profile
.lock
);
847 if (device
->profile
.data
)
848 dasd_profile_end_add_data(device
->profile
.data
,
849 cqr
->startdev
!= block
->base
,
851 rq_data_dir(req
) == READ
,
852 sectors
, sectors_ind
, tottime_ind
,
853 tottimeps_ind
, strtime_ind
,
854 irqtime_ind
, irqtimeps_ind
,
856 spin_unlock(&device
->profile
.lock
);
859 void dasd_profile_reset(struct dasd_profile
*profile
)
861 struct dasd_profile_info
*data
;
863 spin_lock_bh(&profile
->lock
);
864 data
= profile
->data
;
866 spin_unlock_bh(&profile
->lock
);
869 memset(data
, 0, sizeof(*data
));
870 getnstimeofday(&data
->starttod
);
871 spin_unlock_bh(&profile
->lock
);
874 void dasd_global_profile_reset(void)
876 memset(&dasd_global_profile_data
, 0, sizeof(dasd_global_profile_data
));
877 getnstimeofday(&dasd_global_profile_data
.starttod
);
880 int dasd_profile_on(struct dasd_profile
*profile
)
882 struct dasd_profile_info
*data
;
884 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
887 spin_lock_bh(&profile
->lock
);
889 spin_unlock_bh(&profile
->lock
);
893 getnstimeofday(&data
->starttod
);
894 profile
->data
= data
;
895 spin_unlock_bh(&profile
->lock
);
899 void dasd_profile_off(struct dasd_profile
*profile
)
901 spin_lock_bh(&profile
->lock
);
902 kfree(profile
->data
);
903 profile
->data
= NULL
;
904 spin_unlock_bh(&profile
->lock
);
907 char *dasd_get_user_string(const char __user
*user_buf
, size_t user_len
)
911 buffer
= vmalloc(user_len
+ 1);
913 return ERR_PTR(-ENOMEM
);
914 if (copy_from_user(buffer
, user_buf
, user_len
) != 0) {
916 return ERR_PTR(-EFAULT
);
918 /* got the string, now strip linefeed. */
919 if (buffer
[user_len
- 1] == '\n')
920 buffer
[user_len
- 1] = 0;
922 buffer
[user_len
] = 0;
926 static ssize_t
dasd_stats_write(struct file
*file
,
927 const char __user
*user_buf
,
928 size_t user_len
, loff_t
*pos
)
932 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
933 struct dasd_profile
*prof
= m
->private;
935 if (user_len
> 65536)
937 buffer
= dasd_get_user_string(user_buf
, user_len
);
939 return PTR_ERR(buffer
);
941 str
= skip_spaces(buffer
);
943 if (strncmp(str
, "reset", 5) == 0) {
944 dasd_profile_reset(prof
);
945 } else if (strncmp(str
, "on", 2) == 0) {
946 rc
= dasd_profile_on(prof
);
949 } else if (strncmp(str
, "off", 3) == 0) {
950 dasd_profile_off(prof
);
957 static void dasd_stats_array(struct seq_file
*m
, unsigned int *array
)
961 for (i
= 0; i
< 32; i
++)
962 seq_printf(m
, "%u ", array
[i
]);
966 static void dasd_stats_seq_print(struct seq_file
*m
,
967 struct dasd_profile_info
*data
)
969 seq_printf(m
, "start_time %ld.%09ld\n",
970 data
->starttod
.tv_sec
, data
->starttod
.tv_nsec
);
971 seq_printf(m
, "total_requests %u\n", data
->dasd_io_reqs
);
972 seq_printf(m
, "total_sectors %u\n", data
->dasd_io_sects
);
973 seq_printf(m
, "total_pav %u\n", data
->dasd_io_alias
);
974 seq_printf(m
, "total_hpf %u\n", data
->dasd_io_tpm
);
975 seq_printf(m
, "histogram_sectors ");
976 dasd_stats_array(m
, data
->dasd_io_secs
);
977 seq_printf(m
, "histogram_io_times ");
978 dasd_stats_array(m
, data
->dasd_io_times
);
979 seq_printf(m
, "histogram_io_times_weighted ");
980 dasd_stats_array(m
, data
->dasd_io_timps
);
981 seq_printf(m
, "histogram_time_build_to_ssch ");
982 dasd_stats_array(m
, data
->dasd_io_time1
);
983 seq_printf(m
, "histogram_time_ssch_to_irq ");
984 dasd_stats_array(m
, data
->dasd_io_time2
);
985 seq_printf(m
, "histogram_time_ssch_to_irq_weighted ");
986 dasd_stats_array(m
, data
->dasd_io_time2ps
);
987 seq_printf(m
, "histogram_time_irq_to_end ");
988 dasd_stats_array(m
, data
->dasd_io_time3
);
989 seq_printf(m
, "histogram_ccw_queue_length ");
990 dasd_stats_array(m
, data
->dasd_io_nr_req
);
991 seq_printf(m
, "total_read_requests %u\n", data
->dasd_read_reqs
);
992 seq_printf(m
, "total_read_sectors %u\n", data
->dasd_read_sects
);
993 seq_printf(m
, "total_read_pav %u\n", data
->dasd_read_alias
);
994 seq_printf(m
, "total_read_hpf %u\n", data
->dasd_read_tpm
);
995 seq_printf(m
, "histogram_read_sectors ");
996 dasd_stats_array(m
, data
->dasd_read_secs
);
997 seq_printf(m
, "histogram_read_times ");
998 dasd_stats_array(m
, data
->dasd_read_times
);
999 seq_printf(m
, "histogram_read_time_build_to_ssch ");
1000 dasd_stats_array(m
, data
->dasd_read_time1
);
1001 seq_printf(m
, "histogram_read_time_ssch_to_irq ");
1002 dasd_stats_array(m
, data
->dasd_read_time2
);
1003 seq_printf(m
, "histogram_read_time_irq_to_end ");
1004 dasd_stats_array(m
, data
->dasd_read_time3
);
1005 seq_printf(m
, "histogram_read_ccw_queue_length ");
1006 dasd_stats_array(m
, data
->dasd_read_nr_req
);
1009 static int dasd_stats_show(struct seq_file
*m
, void *v
)
1011 struct dasd_profile
*profile
;
1012 struct dasd_profile_info
*data
;
1014 profile
= m
->private;
1015 spin_lock_bh(&profile
->lock
);
1016 data
= profile
->data
;
1018 spin_unlock_bh(&profile
->lock
);
1019 seq_printf(m
, "disabled\n");
1022 dasd_stats_seq_print(m
, data
);
1023 spin_unlock_bh(&profile
->lock
);
1027 static int dasd_stats_open(struct inode
*inode
, struct file
*file
)
1029 struct dasd_profile
*profile
= inode
->i_private
;
1030 return single_open(file
, dasd_stats_show
, profile
);
1033 static const struct file_operations dasd_stats_raw_fops
= {
1034 .owner
= THIS_MODULE
,
1035 .open
= dasd_stats_open
,
1037 .llseek
= seq_lseek
,
1038 .release
= single_release
,
1039 .write
= dasd_stats_write
,
1042 static ssize_t
dasd_stats_global_write(struct file
*file
,
1043 const char __user
*user_buf
,
1044 size_t user_len
, loff_t
*pos
)
1049 if (user_len
> 65536)
1051 buffer
= dasd_get_user_string(user_buf
, user_len
);
1053 return PTR_ERR(buffer
);
1054 str
= skip_spaces(buffer
);
1056 if (strncmp(str
, "reset", 5) == 0) {
1057 dasd_global_profile_reset();
1058 } else if (strncmp(str
, "on", 2) == 0) {
1059 dasd_global_profile_reset();
1060 dasd_global_profile_level
= DASD_PROFILE_GLOBAL_ONLY
;
1061 } else if (strncmp(str
, "off", 3) == 0) {
1062 dasd_global_profile_level
= DASD_PROFILE_OFF
;
1069 static int dasd_stats_global_show(struct seq_file
*m
, void *v
)
1071 if (!dasd_global_profile_level
) {
1072 seq_printf(m
, "disabled\n");
1075 dasd_stats_seq_print(m
, &dasd_global_profile_data
);
1079 static int dasd_stats_global_open(struct inode
*inode
, struct file
*file
)
1081 return single_open(file
, dasd_stats_global_show
, NULL
);
1084 static const struct file_operations dasd_stats_global_fops
= {
1085 .owner
= THIS_MODULE
,
1086 .open
= dasd_stats_global_open
,
1088 .llseek
= seq_lseek
,
1089 .release
= single_release
,
1090 .write
= dasd_stats_global_write
,
1093 static void dasd_profile_init(struct dasd_profile
*profile
,
1094 struct dentry
*base_dentry
)
1101 profile
->dentry
= NULL
;
1102 profile
->data
= NULL
;
1103 mode
= (S_IRUSR
| S_IWUSR
| S_IFREG
);
1104 pde
= debugfs_create_file("statistics", mode
, base_dentry
,
1105 profile
, &dasd_stats_raw_fops
);
1106 if (pde
&& !IS_ERR(pde
))
1107 profile
->dentry
= pde
;
1111 static void dasd_profile_exit(struct dasd_profile
*profile
)
1113 dasd_profile_off(profile
);
1114 if (profile
->dentry
) {
1115 debugfs_remove(profile
->dentry
);
1116 profile
->dentry
= NULL
;
1120 static void dasd_statistics_removeroot(void)
1122 dasd_global_profile_level
= DASD_PROFILE_OFF
;
1123 if (dasd_global_profile_dentry
) {
1124 debugfs_remove(dasd_global_profile_dentry
);
1125 dasd_global_profile_dentry
= NULL
;
1127 if (dasd_debugfs_global_entry
)
1128 debugfs_remove(dasd_debugfs_global_entry
);
1129 if (dasd_debugfs_root_entry
)
1130 debugfs_remove(dasd_debugfs_root_entry
);
1133 static void dasd_statistics_createroot(void)
1138 dasd_debugfs_root_entry
= NULL
;
1139 dasd_debugfs_global_entry
= NULL
;
1140 dasd_global_profile_dentry
= NULL
;
1141 pde
= debugfs_create_dir("dasd", NULL
);
1142 if (!pde
|| IS_ERR(pde
))
1144 dasd_debugfs_root_entry
= pde
;
1145 pde
= debugfs_create_dir("global", dasd_debugfs_root_entry
);
1146 if (!pde
|| IS_ERR(pde
))
1148 dasd_debugfs_global_entry
= pde
;
1150 mode
= (S_IRUSR
| S_IWUSR
| S_IFREG
);
1151 pde
= debugfs_create_file("statistics", mode
, dasd_debugfs_global_entry
,
1152 NULL
, &dasd_stats_global_fops
);
1153 if (!pde
|| IS_ERR(pde
))
1155 dasd_global_profile_dentry
= pde
;
1159 DBF_EVENT(DBF_ERR
, "%s",
1160 "Creation of the dasd debugfs interface failed");
1161 dasd_statistics_removeroot();
1166 #define dasd_profile_start(block, cqr, req) do {} while (0)
1167 #define dasd_profile_end(block, cqr, req) do {} while (0)
1169 static void dasd_statistics_createroot(void)
1174 static void dasd_statistics_removeroot(void)
1179 int dasd_stats_generic_show(struct seq_file
*m
, void *v
)
1181 seq_printf(m
, "Statistics are not activated in this kernel\n");
1185 static void dasd_profile_init(struct dasd_profile
*profile
,
1186 struct dentry
*base_dentry
)
1191 static void dasd_profile_exit(struct dasd_profile
*profile
)
1196 int dasd_profile_on(struct dasd_profile
*profile
)
1201 #endif /* CONFIG_DASD_PROFILE */
1204 * Allocate memory for a channel program with 'cplength' channel
1205 * command words and 'datasize' additional space. There are two
1206 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1207 * memory and 2) dasd_smalloc_request uses the static ccw memory
1208 * that gets allocated for each device.
1210 struct dasd_ccw_req
*dasd_kmalloc_request(int magic
, int cplength
,
1212 struct dasd_device
*device
)
1214 struct dasd_ccw_req
*cqr
;
1217 BUG_ON(datasize
> PAGE_SIZE
||
1218 (cplength
*sizeof(struct ccw1
)) > PAGE_SIZE
);
1220 cqr
= kzalloc(sizeof(struct dasd_ccw_req
), GFP_ATOMIC
);
1222 return ERR_PTR(-ENOMEM
);
1225 cqr
->cpaddr
= kcalloc(cplength
, sizeof(struct ccw1
),
1226 GFP_ATOMIC
| GFP_DMA
);
1227 if (cqr
->cpaddr
== NULL
) {
1229 return ERR_PTR(-ENOMEM
);
1234 cqr
->data
= kzalloc(datasize
, GFP_ATOMIC
| GFP_DMA
);
1235 if (cqr
->data
== NULL
) {
1238 return ERR_PTR(-ENOMEM
);
1242 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1243 dasd_get_device(device
);
1247 struct dasd_ccw_req
*dasd_smalloc_request(int magic
, int cplength
,
1249 struct dasd_device
*device
)
1251 unsigned long flags
;
1252 struct dasd_ccw_req
*cqr
;
1256 size
= (sizeof(struct dasd_ccw_req
) + 7L) & -8L;
1258 size
+= cplength
* sizeof(struct ccw1
);
1261 spin_lock_irqsave(&device
->mem_lock
, flags
);
1262 cqr
= (struct dasd_ccw_req
*)
1263 dasd_alloc_chunk(&device
->ccw_chunks
, size
);
1264 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
1266 return ERR_PTR(-ENOMEM
);
1267 memset(cqr
, 0, sizeof(struct dasd_ccw_req
));
1268 data
= (char *) cqr
+ ((sizeof(struct dasd_ccw_req
) + 7L) & -8L);
1271 cqr
->cpaddr
= (struct ccw1
*) data
;
1272 data
+= cplength
*sizeof(struct ccw1
);
1273 memset(cqr
->cpaddr
, 0, cplength
*sizeof(struct ccw1
));
1278 memset(cqr
->data
, 0, datasize
);
1281 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1282 dasd_get_device(device
);
1287 * Free memory of a channel program. This function needs to free all the
1288 * idal lists that might have been created by dasd_set_cda and the
1289 * struct dasd_ccw_req itself.
1291 void dasd_kfree_request(struct dasd_ccw_req
*cqr
, struct dasd_device
*device
)
1296 /* Clear any idals used for the request. */
1299 clear_normalized_cda(ccw
);
1300 } while (ccw
++->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
));
1305 dasd_put_device(device
);
1308 void dasd_sfree_request(struct dasd_ccw_req
*cqr
, struct dasd_device
*device
)
1310 unsigned long flags
;
1312 spin_lock_irqsave(&device
->mem_lock
, flags
);
1313 dasd_free_chunk(&device
->ccw_chunks
, cqr
);
1314 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
1315 dasd_put_device(device
);
1319 * Check discipline magic in cqr.
1321 static inline int dasd_check_cqr(struct dasd_ccw_req
*cqr
)
1323 struct dasd_device
*device
;
1327 device
= cqr
->startdev
;
1328 if (strncmp((char *) &cqr
->magic
, device
->discipline
->ebcname
, 4)) {
1329 DBF_DEV_EVENT(DBF_WARNING
, device
,
1330 " dasd_ccw_req 0x%08x magic doesn't match"
1331 " discipline 0x%08x",
1333 *(unsigned int *) device
->discipline
->name
);
1340 * Terminate the current i/o and set the request to clear_pending.
1341 * Timer keeps device runnig.
1342 * ccw_device_clear can fail if the i/o subsystem
1345 int dasd_term_IO(struct dasd_ccw_req
*cqr
)
1347 struct dasd_device
*device
;
1349 char errorstring
[ERRORLENGTH
];
1352 rc
= dasd_check_cqr(cqr
);
1356 device
= (struct dasd_device
*) cqr
->startdev
;
1357 while ((retries
< 5) && (cqr
->status
== DASD_CQR_IN_IO
)) {
1358 rc
= ccw_device_clear(device
->cdev
, (long) cqr
);
1360 case 0: /* termination successful */
1361 cqr
->status
= DASD_CQR_CLEAR_PENDING
;
1362 cqr
->stopclk
= get_tod_clock();
1364 DBF_DEV_EVENT(DBF_DEBUG
, device
,
1365 "terminate cqr %p successful",
1369 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1370 "device gone, retry");
1373 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1374 "I/O error, retry");
1378 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1379 "device busy, retry later");
1382 /* internal error 10 - unknown rc*/
1383 snprintf(errorstring
, ERRORLENGTH
, "10 %d", rc
);
1384 dev_err(&device
->cdev
->dev
, "An error occurred in the "
1385 "DASD device driver, reason=%s\n", errorstring
);
1391 dasd_schedule_device_bh(device
);
1396 * Start the i/o. This start_IO can fail if the channel is really busy.
1397 * In that case set up a timer to start the request later.
1399 int dasd_start_IO(struct dasd_ccw_req
*cqr
)
1401 struct dasd_device
*device
;
1403 char errorstring
[ERRORLENGTH
];
1406 rc
= dasd_check_cqr(cqr
);
1411 device
= (struct dasd_device
*) cqr
->startdev
;
1413 test_bit(DASD_FLAG_LOCK_STOLEN
, &cqr
->block
->base
->flags
)) ||
1414 test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
)) &&
1415 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
1416 DBF_DEV_EVENT(DBF_DEBUG
, device
, "start_IO: return request %p "
1417 "because of stolen lock", cqr
);
1418 cqr
->status
= DASD_CQR_ERROR
;
1419 cqr
->intrc
= -EPERM
;
1422 if (cqr
->retries
< 0) {
1423 /* internal error 14 - start_IO run out of retries */
1424 sprintf(errorstring
, "14 %p", cqr
);
1425 dev_err(&device
->cdev
->dev
, "An error occurred in the DASD "
1426 "device driver, reason=%s\n", errorstring
);
1427 cqr
->status
= DASD_CQR_ERROR
;
1430 cqr
->startclk
= get_tod_clock();
1431 cqr
->starttime
= jiffies
;
1433 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1434 cqr
->lpm
&= device
->path_data
.opm
;
1436 cqr
->lpm
= device
->path_data
.opm
;
1438 if (cqr
->cpmode
== 1) {
1439 rc
= ccw_device_tm_start(device
->cdev
, cqr
->cpaddr
,
1440 (long) cqr
, cqr
->lpm
);
1442 rc
= ccw_device_start(device
->cdev
, cqr
->cpaddr
,
1443 (long) cqr
, cqr
->lpm
, 0);
1447 cqr
->status
= DASD_CQR_IN_IO
;
1450 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1451 "start_IO: device busy, retry later");
1454 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1455 "start_IO: request timeout, retry later");
1458 /* -EACCES indicates that the request used only a subset of the
1459 * available paths and all these paths are gone. If the lpm of
1460 * this request was only a subset of the opm (e.g. the ppm) then
1461 * we just do a retry with all available paths.
1462 * If we already use the full opm, something is amiss, and we
1463 * need a full path verification.
1465 if (test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1466 DBF_DEV_EVENT(DBF_WARNING
, device
,
1467 "start_IO: selected paths gone (%x)",
1469 } else if (cqr
->lpm
!= device
->path_data
.opm
) {
1470 cqr
->lpm
= device
->path_data
.opm
;
1471 DBF_DEV_EVENT(DBF_DEBUG
, device
, "%s",
1472 "start_IO: selected paths gone,"
1473 " retry on all paths");
1475 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1476 "start_IO: all paths in opm gone,"
1477 " do path verification");
1478 dasd_generic_last_path_gone(device
);
1479 device
->path_data
.opm
= 0;
1480 device
->path_data
.ppm
= 0;
1481 device
->path_data
.npm
= 0;
1482 device
->path_data
.tbvpm
=
1483 ccw_device_get_path_mask(device
->cdev
);
1487 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1488 "start_IO: -ENODEV device gone, retry");
1491 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1492 "start_IO: -EIO device gone, retry");
1495 /* most likely caused in power management context */
1496 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1497 "start_IO: -EINVAL device currently "
1501 /* internal error 11 - unknown rc */
1502 snprintf(errorstring
, ERRORLENGTH
, "11 %d", rc
);
1503 dev_err(&device
->cdev
->dev
,
1504 "An error occurred in the DASD device driver, "
1505 "reason=%s\n", errorstring
);
1514 * Timeout function for dasd devices. This is used for different purposes
1515 * 1) missing interrupt handler for normal operation
1516 * 2) delayed start of request where start_IO failed with -EBUSY
1517 * 3) timeout for missing state change interrupts
1518 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1519 * DASD_CQR_QUEUED for 2) and 3).
1521 static void dasd_device_timeout(unsigned long ptr
)
1523 unsigned long flags
;
1524 struct dasd_device
*device
;
1526 device
= (struct dasd_device
*) ptr
;
1527 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1528 /* re-activate request queue */
1529 dasd_device_remove_stop_bits(device
, DASD_STOPPED_PENDING
);
1530 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1531 dasd_schedule_device_bh(device
);
1535 * Setup timeout for a device in jiffies.
1537 void dasd_device_set_timer(struct dasd_device
*device
, int expires
)
1540 del_timer(&device
->timer
);
1542 mod_timer(&device
->timer
, jiffies
+ expires
);
1546 * Clear timeout for a device.
1548 void dasd_device_clear_timer(struct dasd_device
*device
)
1550 del_timer(&device
->timer
);
1553 static void dasd_handle_killed_request(struct ccw_device
*cdev
,
1554 unsigned long intparm
)
1556 struct dasd_ccw_req
*cqr
;
1557 struct dasd_device
*device
;
1561 cqr
= (struct dasd_ccw_req
*) intparm
;
1562 if (cqr
->status
!= DASD_CQR_IN_IO
) {
1563 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
,
1564 "invalid status in handle_killed_request: "
1565 "%02x", cqr
->status
);
1569 device
= dasd_device_from_cdev_locked(cdev
);
1570 if (IS_ERR(device
)) {
1571 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1572 "unable to get device from cdev");
1576 if (!cqr
->startdev
||
1577 device
!= cqr
->startdev
||
1578 strncmp(cqr
->startdev
->discipline
->ebcname
,
1579 (char *) &cqr
->magic
, 4)) {
1580 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1581 "invalid device in request");
1582 dasd_put_device(device
);
1586 /* Schedule request to be retried. */
1587 cqr
->status
= DASD_CQR_QUEUED
;
1589 dasd_device_clear_timer(device
);
1590 dasd_schedule_device_bh(device
);
1591 dasd_put_device(device
);
1594 void dasd_generic_handle_state_change(struct dasd_device
*device
)
1596 /* First of all start sense subsystem status request. */
1597 dasd_eer_snss(device
);
1599 dasd_device_remove_stop_bits(device
, DASD_STOPPED_PENDING
);
1600 dasd_schedule_device_bh(device
);
1602 dasd_schedule_block_bh(device
->block
);
1606 * Interrupt handler for "normal" ssch-io based dasd devices.
1608 void dasd_int_handler(struct ccw_device
*cdev
, unsigned long intparm
,
1611 struct dasd_ccw_req
*cqr
, *next
;
1612 struct dasd_device
*device
;
1613 unsigned long long now
;
1617 switch (PTR_ERR(irb
)) {
1621 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s: "
1622 "request timed out\n", __func__
);
1625 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s: "
1626 "unknown error %ld\n", __func__
,
1629 dasd_handle_killed_request(cdev
, intparm
);
1633 now
= get_tod_clock();
1634 cqr
= (struct dasd_ccw_req
*) intparm
;
1635 /* check for conditions that should be handled immediately */
1637 !(scsw_dstat(&irb
->scsw
) == (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
) &&
1638 scsw_cstat(&irb
->scsw
) == 0)) {
1640 memcpy(&cqr
->irb
, irb
, sizeof(*irb
));
1641 device
= dasd_device_from_cdev_locked(cdev
);
1644 /* ignore unsolicited interrupts for DIAG discipline */
1645 if (device
->discipline
== dasd_diag_discipline_pointer
) {
1646 dasd_put_device(device
);
1649 device
->discipline
->dump_sense_dbf(device
, irb
, "int");
1650 if (device
->features
& DASD_FEATURE_ERPLOG
)
1651 device
->discipline
->dump_sense(device
, cqr
, irb
);
1652 device
->discipline
->check_for_device_change(device
, cqr
, irb
);
1653 dasd_put_device(device
);
1658 device
= (struct dasd_device
*) cqr
->startdev
;
1660 strncmp(device
->discipline
->ebcname
, (char *) &cqr
->magic
, 4)) {
1661 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1662 "invalid device in request");
1666 /* Check for clear pending */
1667 if (cqr
->status
== DASD_CQR_CLEAR_PENDING
&&
1668 scsw_fctl(&irb
->scsw
) & SCSW_FCTL_CLEAR_FUNC
) {
1669 cqr
->status
= DASD_CQR_CLEARED
;
1670 dasd_device_clear_timer(device
);
1671 wake_up(&dasd_flush_wq
);
1672 dasd_schedule_device_bh(device
);
1676 /* check status - the request might have been killed by dyn detach */
1677 if (cqr
->status
!= DASD_CQR_IN_IO
) {
1678 DBF_DEV_EVENT(DBF_DEBUG
, device
, "invalid status: bus_id %s, "
1679 "status %02x", dev_name(&cdev
->dev
), cqr
->status
);
1685 if (scsw_dstat(&irb
->scsw
) == (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
) &&
1686 scsw_cstat(&irb
->scsw
) == 0) {
1687 /* request was completed successfully */
1688 cqr
->status
= DASD_CQR_SUCCESS
;
1690 /* Start first request on queue if possible -> fast_io. */
1691 if (cqr
->devlist
.next
!= &device
->ccw_queue
) {
1692 next
= list_entry(cqr
->devlist
.next
,
1693 struct dasd_ccw_req
, devlist
);
1695 } else { /* error */
1697 * If we don't want complex ERP for this request, then just
1698 * reset this and retry it in the fastpath
1700 if (!test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
) &&
1702 if (cqr
->lpm
== device
->path_data
.opm
)
1703 DBF_DEV_EVENT(DBF_DEBUG
, device
,
1704 "default ERP in fastpath "
1705 "(%i retries left)",
1707 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
))
1708 cqr
->lpm
= device
->path_data
.opm
;
1709 cqr
->status
= DASD_CQR_QUEUED
;
1712 cqr
->status
= DASD_CQR_ERROR
;
1714 if (next
&& (next
->status
== DASD_CQR_QUEUED
) &&
1715 (!device
->stopped
)) {
1716 if (device
->discipline
->start_IO(next
) == 0)
1717 expires
= next
->expires
;
1720 dasd_device_set_timer(device
, expires
);
1722 dasd_device_clear_timer(device
);
1723 dasd_schedule_device_bh(device
);
1726 enum uc_todo
dasd_generic_uc_handler(struct ccw_device
*cdev
, struct irb
*irb
)
1728 struct dasd_device
*device
;
1730 device
= dasd_device_from_cdev_locked(cdev
);
1734 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
1735 device
->state
!= device
->target
||
1736 !device
->discipline
->check_for_device_change
){
1737 dasd_put_device(device
);
1740 if (device
->discipline
->dump_sense_dbf
)
1741 device
->discipline
->dump_sense_dbf(device
, irb
, "uc");
1742 device
->discipline
->check_for_device_change(device
, NULL
, irb
);
1743 dasd_put_device(device
);
1745 return UC_TODO_RETRY
;
1747 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler
);
1750 * If we have an error on a dasd_block layer request then we cancel
1751 * and return all further requests from the same dasd_block as well.
1753 static void __dasd_device_recovery(struct dasd_device
*device
,
1754 struct dasd_ccw_req
*ref_cqr
)
1756 struct list_head
*l
, *n
;
1757 struct dasd_ccw_req
*cqr
;
1760 * only requeue request that came from the dasd_block layer
1762 if (!ref_cqr
->block
)
1765 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1766 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1767 if (cqr
->status
== DASD_CQR_QUEUED
&&
1768 ref_cqr
->block
== cqr
->block
) {
1769 cqr
->status
= DASD_CQR_CLEARED
;
1775 * Remove those ccw requests from the queue that need to be returned
1776 * to the upper layer.
1778 static void __dasd_device_process_ccw_queue(struct dasd_device
*device
,
1779 struct list_head
*final_queue
)
1781 struct list_head
*l
, *n
;
1782 struct dasd_ccw_req
*cqr
;
1784 /* Process request with final status. */
1785 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1786 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1788 /* Skip any non-final request. */
1789 if (cqr
->status
== DASD_CQR_QUEUED
||
1790 cqr
->status
== DASD_CQR_IN_IO
||
1791 cqr
->status
== DASD_CQR_CLEAR_PENDING
)
1793 if (cqr
->status
== DASD_CQR_ERROR
) {
1794 __dasd_device_recovery(device
, cqr
);
1796 /* Rechain finished requests to final queue */
1797 list_move_tail(&cqr
->devlist
, final_queue
);
1802 * the cqrs from the final queue are returned to the upper layer
1803 * by setting a dasd_block state and calling the callback function
1805 static void __dasd_device_process_final_queue(struct dasd_device
*device
,
1806 struct list_head
*final_queue
)
1808 struct list_head
*l
, *n
;
1809 struct dasd_ccw_req
*cqr
;
1810 struct dasd_block
*block
;
1811 void (*callback
)(struct dasd_ccw_req
*, void *data
);
1812 void *callback_data
;
1813 char errorstring
[ERRORLENGTH
];
1815 list_for_each_safe(l
, n
, final_queue
) {
1816 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1817 list_del_init(&cqr
->devlist
);
1819 callback
= cqr
->callback
;
1820 callback_data
= cqr
->callback_data
;
1822 spin_lock_bh(&block
->queue_lock
);
1823 switch (cqr
->status
) {
1824 case DASD_CQR_SUCCESS
:
1825 cqr
->status
= DASD_CQR_DONE
;
1827 case DASD_CQR_ERROR
:
1828 cqr
->status
= DASD_CQR_NEED_ERP
;
1830 case DASD_CQR_CLEARED
:
1831 cqr
->status
= DASD_CQR_TERMINATED
;
1834 /* internal error 12 - wrong cqr status*/
1835 snprintf(errorstring
, ERRORLENGTH
, "12 %p %x02", cqr
, cqr
->status
);
1836 dev_err(&device
->cdev
->dev
,
1837 "An error occurred in the DASD device driver, "
1838 "reason=%s\n", errorstring
);
1841 if (cqr
->callback
!= NULL
)
1842 (callback
)(cqr
, callback_data
);
1844 spin_unlock_bh(&block
->queue_lock
);
1849 * Take a look at the first request on the ccw queue and check
1850 * if it reached its expire time. If so, terminate the IO.
1852 static void __dasd_device_check_expire(struct dasd_device
*device
)
1854 struct dasd_ccw_req
*cqr
;
1856 if (list_empty(&device
->ccw_queue
))
1858 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
1859 if ((cqr
->status
== DASD_CQR_IN_IO
&& cqr
->expires
!= 0) &&
1860 (time_after_eq(jiffies
, cqr
->expires
+ cqr
->starttime
))) {
1861 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
1863 * IO in safe offline processing should not
1864 * run out of retries
1868 if (device
->discipline
->term_IO(cqr
) != 0) {
1869 /* Hmpf, try again in 5 sec */
1870 dev_err(&device
->cdev
->dev
,
1871 "cqr %p timed out (%lus) but cannot be "
1872 "ended, retrying in 5 s\n",
1873 cqr
, (cqr
->expires
/HZ
));
1874 cqr
->expires
+= 5*HZ
;
1875 dasd_device_set_timer(device
, 5*HZ
);
1877 dev_err(&device
->cdev
->dev
,
1878 "cqr %p timed out (%lus), %i retries "
1879 "remaining\n", cqr
, (cqr
->expires
/HZ
),
1886 * Take a look at the first request on the ccw queue and check
1887 * if it needs to be started.
1889 static void __dasd_device_start_head(struct dasd_device
*device
)
1891 struct dasd_ccw_req
*cqr
;
1894 if (list_empty(&device
->ccw_queue
))
1896 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
1897 if (cqr
->status
!= DASD_CQR_QUEUED
)
1899 /* when device is stopped, return request to previous layer
1900 * exception: only the disconnect or unresumed bits are set and the
1901 * cqr is a path verification request
1903 if (device
->stopped
&&
1904 !(!(device
->stopped
& ~(DASD_STOPPED_DC_WAIT
| DASD_UNRESUMED_PM
))
1905 && test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
))) {
1906 cqr
->intrc
= -EAGAIN
;
1907 cqr
->status
= DASD_CQR_CLEARED
;
1908 dasd_schedule_device_bh(device
);
1912 rc
= device
->discipline
->start_IO(cqr
);
1914 dasd_device_set_timer(device
, cqr
->expires
);
1915 else if (rc
== -EACCES
) {
1916 dasd_schedule_device_bh(device
);
1918 /* Hmpf, try again in 1/2 sec */
1919 dasd_device_set_timer(device
, 50);
1922 static void __dasd_device_check_path_events(struct dasd_device
*device
)
1926 if (device
->path_data
.tbvpm
) {
1927 if (device
->stopped
& ~(DASD_STOPPED_DC_WAIT
|
1930 rc
= device
->discipline
->verify_path(
1931 device
, device
->path_data
.tbvpm
);
1933 dasd_device_set_timer(device
, 50);
1935 device
->path_data
.tbvpm
= 0;
1940 * Go through all request on the dasd_device request queue,
1941 * terminate them on the cdev if necessary, and return them to the
1942 * submitting layer via callback.
1944 * Make sure that all 'submitting layers' still exist when
1945 * this function is called!. In other words, when 'device' is a base
1946 * device then all block layer requests must have been removed before
1947 * via dasd_flush_block_queue.
1949 int dasd_flush_device_queue(struct dasd_device
*device
)
1951 struct dasd_ccw_req
*cqr
, *n
;
1953 struct list_head flush_queue
;
1955 INIT_LIST_HEAD(&flush_queue
);
1956 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
1958 list_for_each_entry_safe(cqr
, n
, &device
->ccw_queue
, devlist
) {
1959 /* Check status and move request to flush_queue */
1960 switch (cqr
->status
) {
1961 case DASD_CQR_IN_IO
:
1962 rc
= device
->discipline
->term_IO(cqr
);
1964 /* unable to terminate requeust */
1965 dev_err(&device
->cdev
->dev
,
1966 "Flushing the DASD request queue "
1967 "failed for request %p\n", cqr
);
1968 /* stop flush processing */
1972 case DASD_CQR_QUEUED
:
1973 cqr
->stopclk
= get_tod_clock();
1974 cqr
->status
= DASD_CQR_CLEARED
;
1976 default: /* no need to modify the others */
1979 list_move_tail(&cqr
->devlist
, &flush_queue
);
1982 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1984 * After this point all requests must be in state CLEAR_PENDING,
1985 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
1986 * one of the others.
1988 list_for_each_entry_safe(cqr
, n
, &flush_queue
, devlist
)
1989 wait_event(dasd_flush_wq
,
1990 (cqr
->status
!= DASD_CQR_CLEAR_PENDING
));
1992 * Now set each request back to TERMINATED, DONE or NEED_ERP
1993 * and call the callback function of flushed requests
1995 __dasd_device_process_final_queue(device
, &flush_queue
);
2000 * Acquire the device lock and process queues for the device.
2002 static void dasd_device_tasklet(struct dasd_device
*device
)
2004 struct list_head final_queue
;
2006 atomic_set (&device
->tasklet_scheduled
, 0);
2007 INIT_LIST_HEAD(&final_queue
);
2008 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2009 /* Check expire time of first request on the ccw queue. */
2010 __dasd_device_check_expire(device
);
2011 /* find final requests on ccw queue */
2012 __dasd_device_process_ccw_queue(device
, &final_queue
);
2013 __dasd_device_check_path_events(device
);
2014 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2015 /* Now call the callback function of requests with final status */
2016 __dasd_device_process_final_queue(device
, &final_queue
);
2017 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2018 /* Now check if the head of the ccw queue needs to be started. */
2019 __dasd_device_start_head(device
);
2020 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2021 if (waitqueue_active(&shutdown_waitq
))
2022 wake_up(&shutdown_waitq
);
2023 dasd_put_device(device
);
2027 * Schedules a call to dasd_tasklet over the device tasklet.
2029 void dasd_schedule_device_bh(struct dasd_device
*device
)
2031 /* Protect against rescheduling. */
2032 if (atomic_cmpxchg (&device
->tasklet_scheduled
, 0, 1) != 0)
2034 dasd_get_device(device
);
2035 tasklet_hi_schedule(&device
->tasklet
);
2038 void dasd_device_set_stop_bits(struct dasd_device
*device
, int bits
)
2040 device
->stopped
|= bits
;
2042 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits
);
2044 void dasd_device_remove_stop_bits(struct dasd_device
*device
, int bits
)
2046 device
->stopped
&= ~bits
;
2047 if (!device
->stopped
)
2048 wake_up(&generic_waitq
);
2050 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits
);
2053 * Queue a request to the head of the device ccw_queue.
2054 * Start the I/O if possible.
2056 void dasd_add_request_head(struct dasd_ccw_req
*cqr
)
2058 struct dasd_device
*device
;
2059 unsigned long flags
;
2061 device
= cqr
->startdev
;
2062 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2063 cqr
->status
= DASD_CQR_QUEUED
;
2064 list_add(&cqr
->devlist
, &device
->ccw_queue
);
2065 /* let the bh start the request to keep them in order */
2066 dasd_schedule_device_bh(device
);
2067 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2071 * Queue a request to the tail of the device ccw_queue.
2072 * Start the I/O if possible.
2074 void dasd_add_request_tail(struct dasd_ccw_req
*cqr
)
2076 struct dasd_device
*device
;
2077 unsigned long flags
;
2079 device
= cqr
->startdev
;
2080 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2081 cqr
->status
= DASD_CQR_QUEUED
;
2082 list_add_tail(&cqr
->devlist
, &device
->ccw_queue
);
2083 /* let the bh start the request to keep them in order */
2084 dasd_schedule_device_bh(device
);
2085 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2089 * Wakeup helper for the 'sleep_on' functions.
2091 void dasd_wakeup_cb(struct dasd_ccw_req
*cqr
, void *data
)
2093 spin_lock_irq(get_ccwdev_lock(cqr
->startdev
->cdev
));
2094 cqr
->callback_data
= DASD_SLEEPON_END_TAG
;
2095 spin_unlock_irq(get_ccwdev_lock(cqr
->startdev
->cdev
));
2096 wake_up(&generic_waitq
);
2098 EXPORT_SYMBOL_GPL(dasd_wakeup_cb
);
2100 static inline int _wait_for_wakeup(struct dasd_ccw_req
*cqr
)
2102 struct dasd_device
*device
;
2105 device
= cqr
->startdev
;
2106 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2107 rc
= (cqr
->callback_data
== DASD_SLEEPON_END_TAG
);
2108 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2113 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2115 static int __dasd_sleep_on_erp(struct dasd_ccw_req
*cqr
)
2117 struct dasd_device
*device
;
2118 dasd_erp_fn_t erp_fn
;
2120 if (cqr
->status
== DASD_CQR_FILLED
)
2122 device
= cqr
->startdev
;
2123 if (test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
)) {
2124 if (cqr
->status
== DASD_CQR_TERMINATED
) {
2125 device
->discipline
->handle_terminated_request(cqr
);
2128 if (cqr
->status
== DASD_CQR_NEED_ERP
) {
2129 erp_fn
= device
->discipline
->erp_action(cqr
);
2133 if (cqr
->status
== DASD_CQR_FAILED
)
2134 dasd_log_sense(cqr
, &cqr
->irb
);
2136 __dasd_process_erp(device
, cqr
);
2143 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req
*cqr
)
2145 if (test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
)) {
2146 if (cqr
->refers
) /* erp is not done yet */
2148 return ((cqr
->status
!= DASD_CQR_DONE
) &&
2149 (cqr
->status
!= DASD_CQR_FAILED
));
2151 return (cqr
->status
== DASD_CQR_FILLED
);
2154 static int _dasd_sleep_on(struct dasd_ccw_req
*maincqr
, int interruptible
)
2156 struct dasd_device
*device
;
2158 struct list_head ccw_queue
;
2159 struct dasd_ccw_req
*cqr
;
2161 INIT_LIST_HEAD(&ccw_queue
);
2162 maincqr
->status
= DASD_CQR_FILLED
;
2163 device
= maincqr
->startdev
;
2164 list_add(&maincqr
->blocklist
, &ccw_queue
);
2165 for (cqr
= maincqr
; __dasd_sleep_on_loop_condition(cqr
);
2166 cqr
= list_first_entry(&ccw_queue
,
2167 struct dasd_ccw_req
, blocklist
)) {
2169 if (__dasd_sleep_on_erp(cqr
))
2171 if (cqr
->status
!= DASD_CQR_FILLED
) /* could be failed */
2173 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2174 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2175 cqr
->status
= DASD_CQR_FAILED
;
2176 cqr
->intrc
= -EPERM
;
2179 /* Non-temporary stop condition will trigger fail fast */
2180 if (device
->stopped
& ~DASD_STOPPED_PENDING
&&
2181 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2182 (!dasd_eer_enabled(device
))) {
2183 cqr
->status
= DASD_CQR_FAILED
;
2184 cqr
->intrc
= -ENOLINK
;
2187 /* Don't try to start requests if device is stopped */
2188 if (interruptible
) {
2189 rc
= wait_event_interruptible(
2190 generic_waitq
, !(device
->stopped
));
2191 if (rc
== -ERESTARTSYS
) {
2192 cqr
->status
= DASD_CQR_FAILED
;
2193 maincqr
->intrc
= rc
;
2197 wait_event(generic_waitq
, !(device
->stopped
));
2200 cqr
->callback
= dasd_wakeup_cb
;
2202 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2203 dasd_add_request_tail(cqr
);
2204 if (interruptible
) {
2205 rc
= wait_event_interruptible(
2206 generic_waitq
, _wait_for_wakeup(cqr
));
2207 if (rc
== -ERESTARTSYS
) {
2208 dasd_cancel_req(cqr
);
2209 /* wait (non-interruptible) for final status */
2210 wait_event(generic_waitq
,
2211 _wait_for_wakeup(cqr
));
2212 cqr
->status
= DASD_CQR_FAILED
;
2213 maincqr
->intrc
= rc
;
2217 wait_event(generic_waitq
, _wait_for_wakeup(cqr
));
2220 maincqr
->endclk
= get_tod_clock();
2221 if ((maincqr
->status
!= DASD_CQR_DONE
) &&
2222 (maincqr
->intrc
!= -ERESTARTSYS
))
2223 dasd_log_sense(maincqr
, &maincqr
->irb
);
2224 if (maincqr
->status
== DASD_CQR_DONE
)
2226 else if (maincqr
->intrc
)
2227 rc
= maincqr
->intrc
;
2233 static inline int _wait_for_wakeup_queue(struct list_head
*ccw_queue
)
2235 struct dasd_ccw_req
*cqr
;
2237 list_for_each_entry(cqr
, ccw_queue
, blocklist
) {
2238 if (cqr
->callback_data
!= DASD_SLEEPON_END_TAG
)
2245 static int _dasd_sleep_on_queue(struct list_head
*ccw_queue
, int interruptible
)
2247 struct dasd_device
*device
;
2249 struct dasd_ccw_req
*cqr
, *n
;
2252 list_for_each_entry_safe(cqr
, n
, ccw_queue
, blocklist
) {
2253 device
= cqr
->startdev
;
2254 if (cqr
->status
!= DASD_CQR_FILLED
) /*could be failed*/
2257 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2258 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2259 cqr
->status
= DASD_CQR_FAILED
;
2260 cqr
->intrc
= -EPERM
;
2263 /*Non-temporary stop condition will trigger fail fast*/
2264 if (device
->stopped
& ~DASD_STOPPED_PENDING
&&
2265 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2266 !dasd_eer_enabled(device
)) {
2267 cqr
->status
= DASD_CQR_FAILED
;
2268 cqr
->intrc
= -EAGAIN
;
2272 /*Don't try to start requests if device is stopped*/
2273 if (interruptible
) {
2274 rc
= wait_event_interruptible(
2275 generic_waitq
, !device
->stopped
);
2276 if (rc
== -ERESTARTSYS
) {
2277 cqr
->status
= DASD_CQR_FAILED
;
2282 wait_event(generic_waitq
, !(device
->stopped
));
2285 cqr
->callback
= dasd_wakeup_cb
;
2286 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2287 dasd_add_request_tail(cqr
);
2290 wait_event(generic_waitq
, _wait_for_wakeup_queue(ccw_queue
));
2293 list_for_each_entry_safe(cqr
, n
, ccw_queue
, blocklist
) {
2294 if (__dasd_sleep_on_erp(cqr
))
2305 * Queue a request to the tail of the device ccw_queue and wait for
2308 int dasd_sleep_on(struct dasd_ccw_req
*cqr
)
2310 return _dasd_sleep_on(cqr
, 0);
2314 * Start requests from a ccw_queue and wait for their completion.
2316 int dasd_sleep_on_queue(struct list_head
*ccw_queue
)
2318 return _dasd_sleep_on_queue(ccw_queue
, 0);
2320 EXPORT_SYMBOL(dasd_sleep_on_queue
);
2323 * Queue a request to the tail of the device ccw_queue and wait
2324 * interruptible for it's completion.
2326 int dasd_sleep_on_interruptible(struct dasd_ccw_req
*cqr
)
2328 return _dasd_sleep_on(cqr
, 1);
2332 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2333 * for eckd devices) the currently running request has to be terminated
2334 * and be put back to status queued, before the special request is added
2335 * to the head of the queue. Then the special request is waited on normally.
2337 static inline int _dasd_term_running_cqr(struct dasd_device
*device
)
2339 struct dasd_ccw_req
*cqr
;
2342 if (list_empty(&device
->ccw_queue
))
2344 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
2345 rc
= device
->discipline
->term_IO(cqr
);
2348 * CQR terminated because a more important request is pending.
2349 * Undo decreasing of retry counter because this is
2350 * not an error case.
2356 int dasd_sleep_on_immediatly(struct dasd_ccw_req
*cqr
)
2358 struct dasd_device
*device
;
2361 device
= cqr
->startdev
;
2362 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2363 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2364 cqr
->status
= DASD_CQR_FAILED
;
2365 cqr
->intrc
= -EPERM
;
2368 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2369 rc
= _dasd_term_running_cqr(device
);
2371 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2374 cqr
->callback
= dasd_wakeup_cb
;
2375 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2376 cqr
->status
= DASD_CQR_QUEUED
;
2378 * add new request as second
2379 * first the terminated cqr needs to be finished
2381 list_add(&cqr
->devlist
, device
->ccw_queue
.next
);
2383 /* let the bh start the request to keep them in order */
2384 dasd_schedule_device_bh(device
);
2386 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2388 wait_event(generic_waitq
, _wait_for_wakeup(cqr
));
2390 if (cqr
->status
== DASD_CQR_DONE
)
2392 else if (cqr
->intrc
)
2398 dasd_schedule_device_bh(device
);
2400 dasd_schedule_block_bh(device
->block
);
2406 * Cancels a request that was started with dasd_sleep_on_req.
2407 * This is useful to timeout requests. The request will be
2408 * terminated if it is currently in i/o.
2409 * Returns 0 if request termination was successful
2410 * negative error code if termination failed
2411 * Cancellation of a request is an asynchronous operation! The calling
2412 * function has to wait until the request is properly returned via callback.
2414 int dasd_cancel_req(struct dasd_ccw_req
*cqr
)
2416 struct dasd_device
*device
= cqr
->startdev
;
2417 unsigned long flags
;
2421 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2422 switch (cqr
->status
) {
2423 case DASD_CQR_QUEUED
:
2424 /* request was not started - just set to cleared */
2425 cqr
->status
= DASD_CQR_CLEARED
;
2427 case DASD_CQR_IN_IO
:
2428 /* request in IO - terminate IO and release again */
2429 rc
= device
->discipline
->term_IO(cqr
);
2431 dev_err(&device
->cdev
->dev
,
2432 "Cancelling request %p failed with rc=%d\n",
2435 cqr
->stopclk
= get_tod_clock();
2438 default: /* already finished or clear pending - do nothing */
2441 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2442 dasd_schedule_device_bh(device
);
2447 * SECTION: Operations of the dasd_block layer.
2451 * Timeout function for dasd_block. This is used when the block layer
2452 * is waiting for something that may not come reliably, (e.g. a state
2455 static void dasd_block_timeout(unsigned long ptr
)
2457 unsigned long flags
;
2458 struct dasd_block
*block
;
2460 block
= (struct dasd_block
*) ptr
;
2461 spin_lock_irqsave(get_ccwdev_lock(block
->base
->cdev
), flags
);
2462 /* re-activate request queue */
2463 dasd_device_remove_stop_bits(block
->base
, DASD_STOPPED_PENDING
);
2464 spin_unlock_irqrestore(get_ccwdev_lock(block
->base
->cdev
), flags
);
2465 dasd_schedule_block_bh(block
);
2469 * Setup timeout for a dasd_block in jiffies.
2471 void dasd_block_set_timer(struct dasd_block
*block
, int expires
)
2474 del_timer(&block
->timer
);
2476 mod_timer(&block
->timer
, jiffies
+ expires
);
2480 * Clear timeout for a dasd_block.
2482 void dasd_block_clear_timer(struct dasd_block
*block
)
2484 del_timer(&block
->timer
);
2488 * Process finished error recovery ccw.
2490 static void __dasd_process_erp(struct dasd_device
*device
,
2491 struct dasd_ccw_req
*cqr
)
2493 dasd_erp_fn_t erp_fn
;
2495 if (cqr
->status
== DASD_CQR_DONE
)
2496 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s", "ERP successful");
2498 dev_err(&device
->cdev
->dev
, "ERP failed for the DASD\n");
2499 erp_fn
= device
->discipline
->erp_postaction(cqr
);
2504 * Fetch requests from the block device queue.
2506 static void __dasd_process_request_queue(struct dasd_block
*block
)
2508 struct request_queue
*queue
;
2509 struct request
*req
;
2510 struct dasd_ccw_req
*cqr
;
2511 struct dasd_device
*basedev
;
2512 unsigned long flags
;
2513 queue
= block
->request_queue
;
2514 basedev
= block
->base
;
2515 /* No queue ? Then there is nothing to do. */
2520 * We requeue request from the block device queue to the ccw
2521 * queue only in two states. In state DASD_STATE_READY the
2522 * partition detection is done and we need to requeue requests
2523 * for that. State DASD_STATE_ONLINE is normal block device
2526 if (basedev
->state
< DASD_STATE_READY
) {
2527 while ((req
= blk_fetch_request(block
->request_queue
)))
2528 __blk_end_request_all(req
, -EIO
);
2531 /* Now we try to fetch requests from the request queue */
2532 while ((req
= blk_peek_request(queue
))) {
2533 if (basedev
->features
& DASD_FEATURE_READONLY
&&
2534 rq_data_dir(req
) == WRITE
) {
2535 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2536 "Rejecting write request %p",
2538 blk_start_request(req
);
2539 __blk_end_request_all(req
, -EIO
);
2542 if (test_bit(DASD_FLAG_ABORTALL
, &basedev
->flags
) &&
2543 (basedev
->features
& DASD_FEATURE_FAILFAST
||
2544 blk_noretry_request(req
))) {
2545 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2546 "Rejecting failfast request %p",
2548 blk_start_request(req
);
2549 __blk_end_request_all(req
, -ETIMEDOUT
);
2552 cqr
= basedev
->discipline
->build_cp(basedev
, block
, req
);
2554 if (PTR_ERR(cqr
) == -EBUSY
)
2555 break; /* normal end condition */
2556 if (PTR_ERR(cqr
) == -ENOMEM
)
2557 break; /* terminate request queue loop */
2558 if (PTR_ERR(cqr
) == -EAGAIN
) {
2560 * The current request cannot be build right
2561 * now, we have to try later. If this request
2562 * is the head-of-queue we stop the device
2565 if (!list_empty(&block
->ccw_queue
))
2568 get_ccwdev_lock(basedev
->cdev
), flags
);
2569 dasd_device_set_stop_bits(basedev
,
2570 DASD_STOPPED_PENDING
);
2571 spin_unlock_irqrestore(
2572 get_ccwdev_lock(basedev
->cdev
), flags
);
2573 dasd_block_set_timer(block
, HZ
/2);
2576 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2577 "CCW creation failed (rc=%ld) "
2580 blk_start_request(req
);
2581 __blk_end_request_all(req
, -EIO
);
2585 * Note: callback is set to dasd_return_cqr_cb in
2586 * __dasd_block_start_head to cover erp requests as well
2588 cqr
->callback_data
= (void *) req
;
2589 cqr
->status
= DASD_CQR_FILLED
;
2590 req
->completion_data
= cqr
;
2591 blk_start_request(req
);
2592 list_add_tail(&cqr
->blocklist
, &block
->ccw_queue
);
2593 INIT_LIST_HEAD(&cqr
->devlist
);
2594 dasd_profile_start(block
, cqr
, req
);
2598 static void __dasd_cleanup_cqr(struct dasd_ccw_req
*cqr
)
2600 struct request
*req
;
2604 req
= (struct request
*) cqr
->callback_data
;
2605 dasd_profile_end(cqr
->block
, cqr
, req
);
2606 status
= cqr
->block
->base
->discipline
->free_cp(cqr
, req
);
2609 else if (status
== 0) {
2610 if (cqr
->intrc
== -EPERM
)
2612 else if (cqr
->intrc
== -ENOLINK
||
2613 cqr
->intrc
== -ETIMEDOUT
)
2618 __blk_end_request_all(req
, error
);
2622 * Process ccw request queue.
2624 static void __dasd_process_block_ccw_queue(struct dasd_block
*block
,
2625 struct list_head
*final_queue
)
2627 struct list_head
*l
, *n
;
2628 struct dasd_ccw_req
*cqr
;
2629 dasd_erp_fn_t erp_fn
;
2630 unsigned long flags
;
2631 struct dasd_device
*base
= block
->base
;
2634 /* Process request with final status. */
2635 list_for_each_safe(l
, n
, &block
->ccw_queue
) {
2636 cqr
= list_entry(l
, struct dasd_ccw_req
, blocklist
);
2637 if (cqr
->status
!= DASD_CQR_DONE
&&
2638 cqr
->status
!= DASD_CQR_FAILED
&&
2639 cqr
->status
!= DASD_CQR_NEED_ERP
&&
2640 cqr
->status
!= DASD_CQR_TERMINATED
)
2643 if (cqr
->status
== DASD_CQR_TERMINATED
) {
2644 base
->discipline
->handle_terminated_request(cqr
);
2648 /* Process requests that may be recovered */
2649 if (cqr
->status
== DASD_CQR_NEED_ERP
) {
2650 erp_fn
= base
->discipline
->erp_action(cqr
);
2651 if (IS_ERR(erp_fn(cqr
)))
2656 /* log sense for fatal error */
2657 if (cqr
->status
== DASD_CQR_FAILED
) {
2658 dasd_log_sense(cqr
, &cqr
->irb
);
2661 /* First of all call extended error reporting. */
2662 if (dasd_eer_enabled(base
) &&
2663 cqr
->status
== DASD_CQR_FAILED
) {
2664 dasd_eer_write(base
, cqr
, DASD_EER_FATALERROR
);
2666 /* restart request */
2667 cqr
->status
= DASD_CQR_FILLED
;
2669 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
2670 dasd_device_set_stop_bits(base
, DASD_STOPPED_QUIESCE
);
2671 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
),
2676 /* Process finished ERP request. */
2678 __dasd_process_erp(base
, cqr
);
2682 /* Rechain finished requests to final queue */
2683 cqr
->endclk
= get_tod_clock();
2684 list_move_tail(&cqr
->blocklist
, final_queue
);
2688 static void dasd_return_cqr_cb(struct dasd_ccw_req
*cqr
, void *data
)
2690 dasd_schedule_block_bh(cqr
->block
);
2693 static void __dasd_block_start_head(struct dasd_block
*block
)
2695 struct dasd_ccw_req
*cqr
;
2697 if (list_empty(&block
->ccw_queue
))
2699 /* We allways begin with the first requests on the queue, as some
2700 * of previously started requests have to be enqueued on a
2701 * dasd_device again for error recovery.
2703 list_for_each_entry(cqr
, &block
->ccw_queue
, blocklist
) {
2704 if (cqr
->status
!= DASD_CQR_FILLED
)
2706 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &block
->base
->flags
) &&
2707 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2708 cqr
->status
= DASD_CQR_FAILED
;
2709 cqr
->intrc
= -EPERM
;
2710 dasd_schedule_block_bh(block
);
2713 /* Non-temporary stop condition will trigger fail fast */
2714 if (block
->base
->stopped
& ~DASD_STOPPED_PENDING
&&
2715 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2716 (!dasd_eer_enabled(block
->base
))) {
2717 cqr
->status
= DASD_CQR_FAILED
;
2718 cqr
->intrc
= -ENOLINK
;
2719 dasd_schedule_block_bh(block
);
2722 /* Don't try to start requests if device is stopped */
2723 if (block
->base
->stopped
)
2726 /* just a fail safe check, should not happen */
2728 cqr
->startdev
= block
->base
;
2730 /* make sure that the requests we submit find their way back */
2731 cqr
->callback
= dasd_return_cqr_cb
;
2733 dasd_add_request_tail(cqr
);
2738 * Central dasd_block layer routine. Takes requests from the generic
2739 * block layer request queue, creates ccw requests, enqueues them on
2740 * a dasd_device and processes ccw requests that have been returned.
2742 static void dasd_block_tasklet(struct dasd_block
*block
)
2744 struct list_head final_queue
;
2745 struct list_head
*l
, *n
;
2746 struct dasd_ccw_req
*cqr
;
2748 atomic_set(&block
->tasklet_scheduled
, 0);
2749 INIT_LIST_HEAD(&final_queue
);
2750 spin_lock(&block
->queue_lock
);
2751 /* Finish off requests on ccw queue */
2752 __dasd_process_block_ccw_queue(block
, &final_queue
);
2753 spin_unlock(&block
->queue_lock
);
2754 /* Now call the callback function of requests with final status */
2755 spin_lock_irq(&block
->request_queue_lock
);
2756 list_for_each_safe(l
, n
, &final_queue
) {
2757 cqr
= list_entry(l
, struct dasd_ccw_req
, blocklist
);
2758 list_del_init(&cqr
->blocklist
);
2759 __dasd_cleanup_cqr(cqr
);
2761 spin_lock(&block
->queue_lock
);
2762 /* Get new request from the block device request queue */
2763 __dasd_process_request_queue(block
);
2764 /* Now check if the head of the ccw queue needs to be started. */
2765 __dasd_block_start_head(block
);
2766 spin_unlock(&block
->queue_lock
);
2767 spin_unlock_irq(&block
->request_queue_lock
);
2768 if (waitqueue_active(&shutdown_waitq
))
2769 wake_up(&shutdown_waitq
);
2770 dasd_put_device(block
->base
);
2773 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req
*cqr
, void *data
)
2775 wake_up(&dasd_flush_wq
);
2779 * Requeue a request back to the block request queue
2780 * only works for block requests
2782 static int _dasd_requeue_request(struct dasd_ccw_req
*cqr
)
2784 struct dasd_block
*block
= cqr
->block
;
2785 struct request
*req
;
2786 unsigned long flags
;
2790 spin_lock_irqsave(&block
->queue_lock
, flags
);
2791 req
= (struct request
*) cqr
->callback_data
;
2792 blk_requeue_request(block
->request_queue
, req
);
2793 spin_unlock_irqrestore(&block
->queue_lock
, flags
);
2799 * Go through all request on the dasd_block request queue, cancel them
2800 * on the respective dasd_device, and return them to the generic
2803 static int dasd_flush_block_queue(struct dasd_block
*block
)
2805 struct dasd_ccw_req
*cqr
, *n
;
2807 struct list_head flush_queue
;
2809 INIT_LIST_HEAD(&flush_queue
);
2810 spin_lock_bh(&block
->queue_lock
);
2813 list_for_each_entry_safe(cqr
, n
, &block
->ccw_queue
, blocklist
) {
2814 /* if this request currently owned by a dasd_device cancel it */
2815 if (cqr
->status
>= DASD_CQR_QUEUED
)
2816 rc
= dasd_cancel_req(cqr
);
2819 /* Rechain request (including erp chain) so it won't be
2820 * touched by the dasd_block_tasklet anymore.
2821 * Replace the callback so we notice when the request
2822 * is returned from the dasd_device layer.
2824 cqr
->callback
= _dasd_wake_block_flush_cb
;
2825 for (i
= 0; cqr
!= NULL
; cqr
= cqr
->refers
, i
++)
2826 list_move_tail(&cqr
->blocklist
, &flush_queue
);
2828 /* moved more than one request - need to restart */
2831 spin_unlock_bh(&block
->queue_lock
);
2832 /* Now call the callback function of flushed requests */
2834 list_for_each_entry_safe(cqr
, n
, &flush_queue
, blocklist
) {
2835 wait_event(dasd_flush_wq
, (cqr
->status
< DASD_CQR_QUEUED
));
2836 /* Process finished ERP request. */
2838 spin_lock_bh(&block
->queue_lock
);
2839 __dasd_process_erp(block
->base
, cqr
);
2840 spin_unlock_bh(&block
->queue_lock
);
2841 /* restart list_for_xx loop since dasd_process_erp
2842 * might remove multiple elements */
2845 /* call the callback function */
2846 spin_lock_irq(&block
->request_queue_lock
);
2847 cqr
->endclk
= get_tod_clock();
2848 list_del_init(&cqr
->blocklist
);
2849 __dasd_cleanup_cqr(cqr
);
2850 spin_unlock_irq(&block
->request_queue_lock
);
2856 * Schedules a call to dasd_tasklet over the device tasklet.
2858 void dasd_schedule_block_bh(struct dasd_block
*block
)
2860 /* Protect against rescheduling. */
2861 if (atomic_cmpxchg(&block
->tasklet_scheduled
, 0, 1) != 0)
2863 /* life cycle of block is bound to it's base device */
2864 dasd_get_device(block
->base
);
2865 tasklet_hi_schedule(&block
->tasklet
);
2870 * SECTION: external block device operations
2871 * (request queue handling, open, release, etc.)
2875 * Dasd request queue function. Called from ll_rw_blk.c
2877 static void do_dasd_request(struct request_queue
*queue
)
2879 struct dasd_block
*block
;
2881 block
= queue
->queuedata
;
2882 spin_lock(&block
->queue_lock
);
2883 /* Get new request from the block device request queue */
2884 __dasd_process_request_queue(block
);
2885 /* Now check if the head of the ccw queue needs to be started. */
2886 __dasd_block_start_head(block
);
2887 spin_unlock(&block
->queue_lock
);
2891 * Block timeout callback, called from the block layer
2893 * request_queue lock is held on entry.
2896 * BLK_EH_RESET_TIMER if the request should be left running
2897 * BLK_EH_NOT_HANDLED if the request is handled or terminated
2900 enum blk_eh_timer_return
dasd_times_out(struct request
*req
)
2902 struct dasd_ccw_req
*cqr
= req
->completion_data
;
2903 struct dasd_block
*block
= req
->q
->queuedata
;
2904 struct dasd_device
*device
;
2908 return BLK_EH_NOT_HANDLED
;
2910 device
= cqr
->startdev
? cqr
->startdev
: block
->base
;
2911 if (!device
->blk_timeout
)
2912 return BLK_EH_RESET_TIMER
;
2913 DBF_DEV_EVENT(DBF_WARNING
, device
,
2914 " dasd_times_out cqr %p status %x",
2917 spin_lock(&block
->queue_lock
);
2918 spin_lock(get_ccwdev_lock(device
->cdev
));
2920 cqr
->intrc
= -ETIMEDOUT
;
2921 if (cqr
->status
>= DASD_CQR_QUEUED
) {
2922 spin_unlock(get_ccwdev_lock(device
->cdev
));
2923 rc
= dasd_cancel_req(cqr
);
2924 } else if (cqr
->status
== DASD_CQR_FILLED
||
2925 cqr
->status
== DASD_CQR_NEED_ERP
) {
2926 cqr
->status
= DASD_CQR_TERMINATED
;
2927 spin_unlock(get_ccwdev_lock(device
->cdev
));
2928 } else if (cqr
->status
== DASD_CQR_IN_ERP
) {
2929 struct dasd_ccw_req
*searchcqr
, *nextcqr
, *tmpcqr
;
2931 list_for_each_entry_safe(searchcqr
, nextcqr
,
2932 &block
->ccw_queue
, blocklist
) {
2934 while (tmpcqr
->refers
)
2935 tmpcqr
= tmpcqr
->refers
;
2938 /* searchcqr is an ERP request for cqr */
2939 searchcqr
->retries
= -1;
2940 searchcqr
->intrc
= -ETIMEDOUT
;
2941 if (searchcqr
->status
>= DASD_CQR_QUEUED
) {
2942 spin_unlock(get_ccwdev_lock(device
->cdev
));
2943 rc
= dasd_cancel_req(searchcqr
);
2944 spin_lock(get_ccwdev_lock(device
->cdev
));
2945 } else if ((searchcqr
->status
== DASD_CQR_FILLED
) ||
2946 (searchcqr
->status
== DASD_CQR_NEED_ERP
)) {
2947 searchcqr
->status
= DASD_CQR_TERMINATED
;
2949 } else if (searchcqr
->status
== DASD_CQR_IN_ERP
) {
2951 * Shouldn't happen; most recent ERP
2952 * request is at the front of queue
2958 spin_unlock(get_ccwdev_lock(device
->cdev
));
2960 dasd_schedule_block_bh(block
);
2961 spin_unlock(&block
->queue_lock
);
2963 return rc
? BLK_EH_RESET_TIMER
: BLK_EH_NOT_HANDLED
;
2967 * Allocate and initialize request queue and default I/O scheduler.
2969 static int dasd_alloc_queue(struct dasd_block
*block
)
2973 block
->request_queue
= blk_init_queue(do_dasd_request
,
2974 &block
->request_queue_lock
);
2975 if (block
->request_queue
== NULL
)
2978 block
->request_queue
->queuedata
= block
;
2980 elevator_exit(block
->request_queue
->elevator
);
2981 block
->request_queue
->elevator
= NULL
;
2982 mutex_lock(&block
->request_queue
->sysfs_lock
);
2983 rc
= elevator_init(block
->request_queue
, "deadline");
2985 blk_cleanup_queue(block
->request_queue
);
2986 mutex_unlock(&block
->request_queue
->sysfs_lock
);
2991 * Allocate and initialize request queue.
2993 static void dasd_setup_queue(struct dasd_block
*block
)
2997 if (block
->base
->features
& DASD_FEATURE_USERAW
) {
2999 * the max_blocks value for raw_track access is 256
3000 * it is higher than the native ECKD value because we
3001 * only need one ccw per track
3002 * so the max_hw_sectors are
3003 * 2048 x 512B = 1024kB = 16 tracks
3007 max
= block
->base
->discipline
->max_blocks
<< block
->s2b_shift
;
3009 blk_queue_logical_block_size(block
->request_queue
,
3011 blk_queue_max_hw_sectors(block
->request_queue
, max
);
3012 blk_queue_max_segments(block
->request_queue
, -1L);
3013 /* with page sized segments we can translate each segement into
3016 blk_queue_max_segment_size(block
->request_queue
, PAGE_SIZE
);
3017 blk_queue_segment_boundary(block
->request_queue
, PAGE_SIZE
- 1);
3021 * Deactivate and free request queue.
3023 static void dasd_free_queue(struct dasd_block
*block
)
3025 if (block
->request_queue
) {
3026 blk_cleanup_queue(block
->request_queue
);
3027 block
->request_queue
= NULL
;
3032 * Flush request on the request queue.
3034 static void dasd_flush_request_queue(struct dasd_block
*block
)
3036 struct request
*req
;
3038 if (!block
->request_queue
)
3041 spin_lock_irq(&block
->request_queue_lock
);
3042 while ((req
= blk_fetch_request(block
->request_queue
)))
3043 __blk_end_request_all(req
, -EIO
);
3044 spin_unlock_irq(&block
->request_queue_lock
);
3047 static int dasd_open(struct block_device
*bdev
, fmode_t mode
)
3049 struct dasd_device
*base
;
3052 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
3056 atomic_inc(&base
->block
->open_count
);
3057 if (test_bit(DASD_FLAG_OFFLINE
, &base
->flags
)) {
3062 if (!try_module_get(base
->discipline
->owner
)) {
3067 if (dasd_probeonly
) {
3068 dev_info(&base
->cdev
->dev
,
3069 "Accessing the DASD failed because it is in "
3070 "probeonly mode\n");
3075 if (base
->state
<= DASD_STATE_BASIC
) {
3076 DBF_DEV_EVENT(DBF_ERR
, base
, " %s",
3077 " Cannot open unrecognized device");
3082 if ((mode
& FMODE_WRITE
) &&
3083 (test_bit(DASD_FLAG_DEVICE_RO
, &base
->flags
) ||
3084 (base
->features
& DASD_FEATURE_READONLY
))) {
3089 dasd_put_device(base
);
3093 module_put(base
->discipline
->owner
);
3095 atomic_dec(&base
->block
->open_count
);
3096 dasd_put_device(base
);
3100 static void dasd_release(struct gendisk
*disk
, fmode_t mode
)
3102 struct dasd_device
*base
= dasd_device_from_gendisk(disk
);
3104 atomic_dec(&base
->block
->open_count
);
3105 module_put(base
->discipline
->owner
);
3106 dasd_put_device(base
);
3111 * Return disk geometry.
3113 static int dasd_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
3115 struct dasd_device
*base
;
3117 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
3121 if (!base
->discipline
||
3122 !base
->discipline
->fill_geometry
) {
3123 dasd_put_device(base
);
3126 base
->discipline
->fill_geometry(base
->block
, geo
);
3127 geo
->start
= get_start_sect(bdev
) >> base
->block
->s2b_shift
;
3128 dasd_put_device(base
);
3132 const struct block_device_operations
3133 dasd_device_operations
= {
3134 .owner
= THIS_MODULE
,
3136 .release
= dasd_release
,
3137 .ioctl
= dasd_ioctl
,
3138 .compat_ioctl
= dasd_ioctl
,
3139 .getgeo
= dasd_getgeo
,
3142 /*******************************************************************************
3143 * end of block device operations
3149 #ifdef CONFIG_PROC_FS
3153 if (dasd_page_cache
!= NULL
) {
3154 kmem_cache_destroy(dasd_page_cache
);
3155 dasd_page_cache
= NULL
;
3157 dasd_gendisk_exit();
3159 if (dasd_debug_area
!= NULL
) {
3160 debug_unregister(dasd_debug_area
);
3161 dasd_debug_area
= NULL
;
3163 dasd_statistics_removeroot();
3167 * SECTION: common functions for ccw_driver use
3171 * Is the device read-only?
3172 * Note that this function does not report the setting of the
3173 * readonly device attribute, but how it is configured in z/VM.
3175 int dasd_device_is_ro(struct dasd_device
*device
)
3177 struct ccw_dev_id dev_id
;
3178 struct diag210 diag_data
;
3183 ccw_device_get_id(device
->cdev
, &dev_id
);
3184 memset(&diag_data
, 0, sizeof(diag_data
));
3185 diag_data
.vrdcdvno
= dev_id
.devno
;
3186 diag_data
.vrdclen
= sizeof(diag_data
);
3187 rc
= diag210(&diag_data
);
3188 if (rc
== 0 || rc
== 2) {
3189 return diag_data
.vrdcvfla
& 0x80;
3191 DBF_EVENT(DBF_WARNING
, "diag210 failed for dev=%04x with rc=%d",
3196 EXPORT_SYMBOL_GPL(dasd_device_is_ro
);
3198 static void dasd_generic_auto_online(void *data
, async_cookie_t cookie
)
3200 struct ccw_device
*cdev
= data
;
3203 ret
= ccw_device_set_online(cdev
);
3205 pr_warning("%s: Setting the DASD online failed with rc=%d\n",
3206 dev_name(&cdev
->dev
), ret
);
3210 * Initial attempt at a probe function. this can be simplified once
3211 * the other detection code is gone.
3213 int dasd_generic_probe(struct ccw_device
*cdev
,
3214 struct dasd_discipline
*discipline
)
3218 ret
= dasd_add_sysfs_files(cdev
);
3220 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s",
3221 "dasd_generic_probe: could not add "
3225 cdev
->handler
= &dasd_int_handler
;
3228 * Automatically online either all dasd devices (dasd_autodetect)
3229 * or all devices specified with dasd= parameters during
3232 if ((dasd_get_feature(cdev
, DASD_FEATURE_INITIAL_ONLINE
) > 0 ) ||
3233 (dasd_autodetect
&& dasd_busid_known(dev_name(&cdev
->dev
)) != 0))
3234 async_schedule(dasd_generic_auto_online
, cdev
);
3239 * This will one day be called from a global not_oper handler.
3240 * It is also used by driver_unregister during module unload.
3242 void dasd_generic_remove(struct ccw_device
*cdev
)
3244 struct dasd_device
*device
;
3245 struct dasd_block
*block
;
3247 cdev
->handler
= NULL
;
3249 device
= dasd_device_from_cdev(cdev
);
3250 if (IS_ERR(device
)) {
3251 dasd_remove_sysfs_files(cdev
);
3254 if (test_and_set_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
3255 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3256 /* Already doing offline processing */
3257 dasd_put_device(device
);
3258 dasd_remove_sysfs_files(cdev
);
3262 * This device is removed unconditionally. Set offline
3263 * flag to prevent dasd_open from opening it while it is
3264 * no quite down yet.
3266 dasd_set_target_state(device
, DASD_STATE_NEW
);
3267 /* dasd_delete_device destroys the device reference. */
3268 block
= device
->block
;
3269 dasd_delete_device(device
);
3271 * life cycle of block is bound to device, so delete it after
3272 * device was safely removed
3275 dasd_free_block(block
);
3277 dasd_remove_sysfs_files(cdev
);
3281 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3282 * the device is detected for the first time and is supposed to be used
3283 * or the user has started activation through sysfs.
3285 int dasd_generic_set_online(struct ccw_device
*cdev
,
3286 struct dasd_discipline
*base_discipline
)
3288 struct dasd_discipline
*discipline
;
3289 struct dasd_device
*device
;
3292 /* first online clears initial online feature flag */
3293 dasd_set_feature(cdev
, DASD_FEATURE_INITIAL_ONLINE
, 0);
3294 device
= dasd_create_device(cdev
);
3296 return PTR_ERR(device
);
3298 discipline
= base_discipline
;
3299 if (device
->features
& DASD_FEATURE_USEDIAG
) {
3300 if (!dasd_diag_discipline_pointer
) {
3301 pr_warning("%s Setting the DASD online failed because "
3302 "of missing DIAG discipline\n",
3303 dev_name(&cdev
->dev
));
3304 dasd_delete_device(device
);
3307 discipline
= dasd_diag_discipline_pointer
;
3309 if (!try_module_get(base_discipline
->owner
)) {
3310 dasd_delete_device(device
);
3313 if (!try_module_get(discipline
->owner
)) {
3314 module_put(base_discipline
->owner
);
3315 dasd_delete_device(device
);
3318 device
->base_discipline
= base_discipline
;
3319 device
->discipline
= discipline
;
3321 /* check_device will allocate block device if necessary */
3322 rc
= discipline
->check_device(device
);
3324 pr_warning("%s Setting the DASD online with discipline %s "
3325 "failed with rc=%i\n",
3326 dev_name(&cdev
->dev
), discipline
->name
, rc
);
3327 module_put(discipline
->owner
);
3328 module_put(base_discipline
->owner
);
3329 dasd_delete_device(device
);
3333 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
3334 if (device
->state
<= DASD_STATE_KNOWN
) {
3335 pr_warning("%s Setting the DASD online failed because of a "
3336 "missing discipline\n", dev_name(&cdev
->dev
));
3338 dasd_set_target_state(device
, DASD_STATE_NEW
);
3340 dasd_free_block(device
->block
);
3341 dasd_delete_device(device
);
3343 pr_debug("dasd_generic device %s found\n",
3344 dev_name(&cdev
->dev
));
3346 wait_event(dasd_init_waitq
, _wait_for_device(device
));
3348 dasd_put_device(device
);
3352 int dasd_generic_set_offline(struct ccw_device
*cdev
)
3354 struct dasd_device
*device
;
3355 struct dasd_block
*block
;
3356 int max_count
, open_count
, rc
;
3359 device
= dasd_device_from_cdev(cdev
);
3361 return PTR_ERR(device
);
3364 * We must make sure that this device is currently not in use.
3365 * The open_count is increased for every opener, that includes
3366 * the blkdev_get in dasd_scan_partitions. We are only interested
3367 * in the other openers.
3369 if (device
->block
) {
3370 max_count
= device
->block
->bdev
? 0 : -1;
3371 open_count
= atomic_read(&device
->block
->open_count
);
3372 if (open_count
> max_count
) {
3374 pr_warning("%s: The DASD cannot be set offline "
3375 "with open count %i\n",
3376 dev_name(&cdev
->dev
), open_count
);
3378 pr_warning("%s: The DASD cannot be set offline "
3379 "while it is in use\n",
3380 dev_name(&cdev
->dev
));
3381 clear_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
3382 dasd_put_device(device
);
3387 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3389 * safe offline already running
3390 * could only be called by normal offline so safe_offline flag
3391 * needs to be removed to run normal offline and kill all I/O
3393 if (test_and_set_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
3394 /* Already doing normal offline processing */
3395 dasd_put_device(device
);
3398 clear_bit(DASD_FLAG_SAFE_OFFLINE
, &device
->flags
);
3401 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
3402 /* Already doing offline processing */
3403 dasd_put_device(device
);
3408 * if safe_offline called set safe_offline_running flag and
3409 * clear safe_offline so that a call to normal offline
3410 * can overrun safe_offline processing
3412 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE
, &device
->flags
) &&
3413 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3415 * If we want to set the device safe offline all IO operations
3416 * should be finished before continuing the offline process
3417 * so sync bdev first and then wait for our queues to become
3420 /* sync blockdev and partitions */
3421 rc
= fsync_bdev(device
->block
->bdev
);
3425 /* schedule device tasklet and wait for completion */
3426 dasd_schedule_device_bh(device
);
3427 rc
= wait_event_interruptible(shutdown_waitq
,
3428 _wait_for_empty_queues(device
));
3433 set_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
3434 dasd_set_target_state(device
, DASD_STATE_NEW
);
3435 /* dasd_delete_device destroys the device reference. */
3436 block
= device
->block
;
3437 dasd_delete_device(device
);
3439 * life cycle of block is bound to device, so delete it after
3440 * device was safely removed
3443 dasd_free_block(block
);
3447 /* interrupted by signal */
3448 clear_bit(DASD_FLAG_SAFE_OFFLINE
, &device
->flags
);
3449 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
);
3450 clear_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
3451 dasd_put_device(device
);
3455 int dasd_generic_last_path_gone(struct dasd_device
*device
)
3457 struct dasd_ccw_req
*cqr
;
3459 dev_warn(&device
->cdev
->dev
, "No operational channel path is left "
3460 "for the device\n");
3461 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s", "last path gone");
3462 /* First of all call extended error reporting. */
3463 dasd_eer_write(device
, NULL
, DASD_EER_NOPATH
);
3465 if (device
->state
< DASD_STATE_BASIC
)
3467 /* Device is active. We want to keep it. */
3468 list_for_each_entry(cqr
, &device
->ccw_queue
, devlist
)
3469 if ((cqr
->status
== DASD_CQR_IN_IO
) ||
3470 (cqr
->status
== DASD_CQR_CLEAR_PENDING
)) {
3471 cqr
->status
= DASD_CQR_QUEUED
;
3474 dasd_device_set_stop_bits(device
, DASD_STOPPED_DC_WAIT
);
3475 dasd_device_clear_timer(device
);
3476 dasd_schedule_device_bh(device
);
3479 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone
);
3481 int dasd_generic_path_operational(struct dasd_device
*device
)
3483 dev_info(&device
->cdev
->dev
, "A channel path to the device has become "
3485 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s", "path operational");
3486 dasd_device_remove_stop_bits(device
, DASD_STOPPED_DC_WAIT
);
3487 if (device
->stopped
& DASD_UNRESUMED_PM
) {
3488 dasd_device_remove_stop_bits(device
, DASD_UNRESUMED_PM
);
3489 dasd_restore_device(device
);
3492 dasd_schedule_device_bh(device
);
3494 dasd_schedule_block_bh(device
->block
);
3497 EXPORT_SYMBOL_GPL(dasd_generic_path_operational
);
3499 int dasd_generic_notify(struct ccw_device
*cdev
, int event
)
3501 struct dasd_device
*device
;
3504 device
= dasd_device_from_cdev_locked(cdev
);
3512 device
->path_data
.opm
= 0;
3513 device
->path_data
.ppm
= 0;
3514 device
->path_data
.npm
= 0;
3515 ret
= dasd_generic_last_path_gone(device
);
3519 if (device
->path_data
.opm
)
3520 ret
= dasd_generic_path_operational(device
);
3523 dasd_put_device(device
);
3527 void dasd_generic_path_event(struct ccw_device
*cdev
, int *path_event
)
3530 __u8 oldopm
, eventlpm
;
3531 struct dasd_device
*device
;
3533 device
= dasd_device_from_cdev_locked(cdev
);
3536 for (chp
= 0; chp
< 8; chp
++) {
3537 eventlpm
= 0x80 >> chp
;
3538 if (path_event
[chp
] & PE_PATH_GONE
) {
3539 oldopm
= device
->path_data
.opm
;
3540 device
->path_data
.opm
&= ~eventlpm
;
3541 device
->path_data
.ppm
&= ~eventlpm
;
3542 device
->path_data
.npm
&= ~eventlpm
;
3543 if (oldopm
&& !device
->path_data
.opm
) {
3544 dev_warn(&device
->cdev
->dev
,
3545 "No verified channel paths remain "
3546 "for the device\n");
3547 DBF_DEV_EVENT(DBF_WARNING
, device
,
3548 "%s", "last verified path gone");
3549 dasd_eer_write(device
, NULL
, DASD_EER_NOPATH
);
3550 dasd_device_set_stop_bits(device
,
3551 DASD_STOPPED_DC_WAIT
);
3554 if (path_event
[chp
] & PE_PATH_AVAILABLE
) {
3555 device
->path_data
.opm
&= ~eventlpm
;
3556 device
->path_data
.ppm
&= ~eventlpm
;
3557 device
->path_data
.npm
&= ~eventlpm
;
3558 device
->path_data
.tbvpm
|= eventlpm
;
3559 dasd_schedule_device_bh(device
);
3561 if (path_event
[chp
] & PE_PATHGROUP_ESTABLISHED
) {
3562 if (!(device
->path_data
.opm
& eventlpm
) &&
3563 !(device
->path_data
.tbvpm
& eventlpm
)) {
3565 * we can not establish a pathgroup on an
3566 * unavailable path, so trigger a path
3567 * verification first
3569 device
->path_data
.tbvpm
|= eventlpm
;
3570 dasd_schedule_device_bh(device
);
3572 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3573 "Pathgroup re-established\n");
3574 if (device
->discipline
->kick_validate
)
3575 device
->discipline
->kick_validate(device
);
3578 dasd_put_device(device
);
3580 EXPORT_SYMBOL_GPL(dasd_generic_path_event
);
3582 int dasd_generic_verify_path(struct dasd_device
*device
, __u8 lpm
)
3584 if (!device
->path_data
.opm
&& lpm
) {
3585 device
->path_data
.opm
= lpm
;
3586 dasd_generic_path_operational(device
);
3588 device
->path_data
.opm
|= lpm
;
3591 EXPORT_SYMBOL_GPL(dasd_generic_verify_path
);
3594 int dasd_generic_pm_freeze(struct ccw_device
*cdev
)
3596 struct dasd_device
*device
= dasd_device_from_cdev(cdev
);
3597 struct list_head freeze_queue
;
3598 struct dasd_ccw_req
*cqr
, *n
;
3599 struct dasd_ccw_req
*refers
;
3603 return PTR_ERR(device
);
3605 /* mark device as suspended */
3606 set_bit(DASD_FLAG_SUSPENDED
, &device
->flags
);
3608 if (device
->discipline
->freeze
)
3609 rc
= device
->discipline
->freeze(device
);
3611 /* disallow new I/O */
3612 dasd_device_set_stop_bits(device
, DASD_STOPPED_PM
);
3614 /* clear active requests and requeue them to block layer if possible */
3615 INIT_LIST_HEAD(&freeze_queue
);
3616 spin_lock_irq(get_ccwdev_lock(cdev
));
3618 list_for_each_entry_safe(cqr
, n
, &device
->ccw_queue
, devlist
) {
3619 /* Check status and move request to flush_queue */
3620 if (cqr
->status
== DASD_CQR_IN_IO
) {
3621 rc
= device
->discipline
->term_IO(cqr
);
3623 /* unable to terminate requeust */
3624 dev_err(&device
->cdev
->dev
,
3625 "Unable to terminate request %p "
3626 "on suspend\n", cqr
);
3627 spin_unlock_irq(get_ccwdev_lock(cdev
));
3628 dasd_put_device(device
);
3632 list_move_tail(&cqr
->devlist
, &freeze_queue
);
3634 spin_unlock_irq(get_ccwdev_lock(cdev
));
3636 list_for_each_entry_safe(cqr
, n
, &freeze_queue
, devlist
) {
3637 wait_event(dasd_flush_wq
,
3638 (cqr
->status
!= DASD_CQR_CLEAR_PENDING
));
3639 if (cqr
->status
== DASD_CQR_CLEARED
)
3640 cqr
->status
= DASD_CQR_QUEUED
;
3642 /* requeue requests to blocklayer will only work for
3643 block device requests */
3644 if (_dasd_requeue_request(cqr
))
3647 /* remove requests from device and block queue */
3648 list_del_init(&cqr
->devlist
);
3649 while (cqr
->refers
!= NULL
) {
3650 refers
= cqr
->refers
;
3651 /* remove the request from the block queue */
3652 list_del(&cqr
->blocklist
);
3653 /* free the finished erp request */
3654 dasd_free_erp_request(cqr
, cqr
->memdev
);
3658 list_del_init(&cqr
->blocklist
);
3659 cqr
->block
->base
->discipline
->free_cp(
3660 cqr
, (struct request
*) cqr
->callback_data
);
3664 * if requests remain then they are internal request
3665 * and go back to the device queue
3667 if (!list_empty(&freeze_queue
)) {
3668 /* move freeze_queue to start of the ccw_queue */
3669 spin_lock_irq(get_ccwdev_lock(cdev
));
3670 list_splice_tail(&freeze_queue
, &device
->ccw_queue
);
3671 spin_unlock_irq(get_ccwdev_lock(cdev
));
3673 dasd_put_device(device
);
3676 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze
);
3678 int dasd_generic_restore_device(struct ccw_device
*cdev
)
3680 struct dasd_device
*device
= dasd_device_from_cdev(cdev
);
3684 return PTR_ERR(device
);
3686 /* allow new IO again */
3687 dasd_device_remove_stop_bits(device
,
3688 (DASD_STOPPED_PM
| DASD_UNRESUMED_PM
));
3690 dasd_schedule_device_bh(device
);
3693 * call discipline restore function
3694 * if device is stopped do nothing e.g. for disconnected devices
3696 if (device
->discipline
->restore
&& !(device
->stopped
))
3697 rc
= device
->discipline
->restore(device
);
3698 if (rc
|| device
->stopped
)
3700 * if the resume failed for the DASD we put it in
3701 * an UNRESUMED stop state
3703 device
->stopped
|= DASD_UNRESUMED_PM
;
3706 dasd_schedule_block_bh(device
->block
);
3708 clear_bit(DASD_FLAG_SUSPENDED
, &device
->flags
);
3709 dasd_put_device(device
);
3712 EXPORT_SYMBOL_GPL(dasd_generic_restore_device
);
3714 static struct dasd_ccw_req
*dasd_generic_build_rdc(struct dasd_device
*device
,
3716 int rdc_buffer_size
,
3719 struct dasd_ccw_req
*cqr
;
3721 unsigned long *idaw
;
3723 cqr
= dasd_smalloc_request(magic
, 1 /* RDC */, rdc_buffer_size
, device
);
3726 /* internal error 13 - Allocating the RDC request failed*/
3727 dev_err(&device
->cdev
->dev
,
3728 "An error occurred in the DASD device driver, "
3729 "reason=%s\n", "13");
3734 ccw
->cmd_code
= CCW_CMD_RDC
;
3735 if (idal_is_needed(rdc_buffer
, rdc_buffer_size
)) {
3736 idaw
= (unsigned long *) (cqr
->data
);
3737 ccw
->cda
= (__u32
)(addr_t
) idaw
;
3738 ccw
->flags
= CCW_FLAG_IDA
;
3739 idaw
= idal_create_words(idaw
, rdc_buffer
, rdc_buffer_size
);
3741 ccw
->cda
= (__u32
)(addr_t
) rdc_buffer
;
3745 ccw
->count
= rdc_buffer_size
;
3746 cqr
->startdev
= device
;
3747 cqr
->memdev
= device
;
3748 cqr
->expires
= 10*HZ
;
3750 cqr
->buildclk
= get_tod_clock();
3751 cqr
->status
= DASD_CQR_FILLED
;
3756 int dasd_generic_read_dev_chars(struct dasd_device
*device
, int magic
,
3757 void *rdc_buffer
, int rdc_buffer_size
)
3760 struct dasd_ccw_req
*cqr
;
3762 cqr
= dasd_generic_build_rdc(device
, rdc_buffer
, rdc_buffer_size
,
3765 return PTR_ERR(cqr
);
3767 ret
= dasd_sleep_on(cqr
);
3768 dasd_sfree_request(cqr
, cqr
->memdev
);
3771 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars
);
3774 * In command mode and transport mode we need to look for sense
3775 * data in different places. The sense data itself is allways
3776 * an array of 32 bytes, so we can unify the sense data access
3779 char *dasd_get_sense(struct irb
*irb
)
3781 struct tsb
*tsb
= NULL
;
3784 if (scsw_is_tm(&irb
->scsw
) && (irb
->scsw
.tm
.fcxs
== 0x01)) {
3785 if (irb
->scsw
.tm
.tcw
)
3786 tsb
= tcw_get_tsb((struct tcw
*)(unsigned long)
3788 if (tsb
&& tsb
->length
== 64 && tsb
->flags
)
3789 switch (tsb
->flags
& 0x07) {
3790 case 1: /* tsa_iostat */
3791 sense
= tsb
->tsa
.iostat
.sense
;
3793 case 2: /* tsa_ddpc */
3794 sense
= tsb
->tsa
.ddpc
.sense
;
3797 /* currently we don't use interrogate data */
3800 } else if (irb
->esw
.esw0
.erw
.cons
) {
3805 EXPORT_SYMBOL_GPL(dasd_get_sense
);
3807 void dasd_generic_shutdown(struct ccw_device
*cdev
)
3809 struct dasd_device
*device
;
3811 device
= dasd_device_from_cdev(cdev
);
3816 dasd_schedule_block_bh(device
->block
);
3818 dasd_schedule_device_bh(device
);
3820 wait_event(shutdown_waitq
, _wait_for_empty_queues(device
));
3822 EXPORT_SYMBOL_GPL(dasd_generic_shutdown
);
3824 static int __init
dasd_init(void)
3828 init_waitqueue_head(&dasd_init_waitq
);
3829 init_waitqueue_head(&dasd_flush_wq
);
3830 init_waitqueue_head(&generic_waitq
);
3831 init_waitqueue_head(&shutdown_waitq
);
3833 /* register 'common' DASD debug area, used for all DBF_XXX calls */
3834 dasd_debug_area
= debug_register("dasd", 1, 1, 8 * sizeof(long));
3835 if (dasd_debug_area
== NULL
) {
3839 debug_register_view(dasd_debug_area
, &debug_sprintf_view
);
3840 debug_set_level(dasd_debug_area
, DBF_WARNING
);
3842 DBF_EVENT(DBF_EMERG
, "%s", "debug area created");
3844 dasd_diag_discipline_pointer
= NULL
;
3846 dasd_statistics_createroot();
3848 rc
= dasd_devmap_init();
3851 rc
= dasd_gendisk_init();
3857 rc
= dasd_eer_init();
3860 #ifdef CONFIG_PROC_FS
3861 rc
= dasd_proc_init();
3868 pr_info("The DASD device driver could not be initialized\n");
3873 module_init(dasd_init
);
3874 module_exit(dasd_exit
);
3876 EXPORT_SYMBOL(dasd_debug_area
);
3877 EXPORT_SYMBOL(dasd_diag_discipline_pointer
);
3879 EXPORT_SYMBOL(dasd_add_request_head
);
3880 EXPORT_SYMBOL(dasd_add_request_tail
);
3881 EXPORT_SYMBOL(dasd_cancel_req
);
3882 EXPORT_SYMBOL(dasd_device_clear_timer
);
3883 EXPORT_SYMBOL(dasd_block_clear_timer
);
3884 EXPORT_SYMBOL(dasd_enable_device
);
3885 EXPORT_SYMBOL(dasd_int_handler
);
3886 EXPORT_SYMBOL(dasd_kfree_request
);
3887 EXPORT_SYMBOL(dasd_kick_device
);
3888 EXPORT_SYMBOL(dasd_kmalloc_request
);
3889 EXPORT_SYMBOL(dasd_schedule_device_bh
);
3890 EXPORT_SYMBOL(dasd_schedule_block_bh
);
3891 EXPORT_SYMBOL(dasd_set_target_state
);
3892 EXPORT_SYMBOL(dasd_device_set_timer
);
3893 EXPORT_SYMBOL(dasd_block_set_timer
);
3894 EXPORT_SYMBOL(dasd_sfree_request
);
3895 EXPORT_SYMBOL(dasd_sleep_on
);
3896 EXPORT_SYMBOL(dasd_sleep_on_immediatly
);
3897 EXPORT_SYMBOL(dasd_sleep_on_interruptible
);
3898 EXPORT_SYMBOL(dasd_smalloc_request
);
3899 EXPORT_SYMBOL(dasd_start_IO
);
3900 EXPORT_SYMBOL(dasd_term_IO
);
3902 EXPORT_SYMBOL_GPL(dasd_generic_probe
);
3903 EXPORT_SYMBOL_GPL(dasd_generic_remove
);
3904 EXPORT_SYMBOL_GPL(dasd_generic_notify
);
3905 EXPORT_SYMBOL_GPL(dasd_generic_set_online
);
3906 EXPORT_SYMBOL_GPL(dasd_generic_set_offline
);
3907 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change
);
3908 EXPORT_SYMBOL_GPL(dasd_flush_device_queue
);
3909 EXPORT_SYMBOL_GPL(dasd_alloc_block
);
3910 EXPORT_SYMBOL_GPL(dasd_free_block
);