1 // SPDX-License-Identifier: GPL-2.0
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * Copyright IBM Corp. 1999, 2009
11 #define KMSG_COMPONENT "dasd"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/kmod.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/ctype.h>
18 #include <linux/major.h>
19 #include <linux/slab.h>
20 #include <linux/hdreg.h>
21 #include <linux/async.h>
22 #include <linux/mutex.h>
23 #include <linux/debugfs.h>
24 #include <linux/seq_file.h>
25 #include <linux/vmalloc.h>
27 #include <asm/ccwdev.h>
28 #include <asm/ebcdic.h>
29 #include <asm/idals.h>
34 #define PRINTK_HEADER "dasd:"
38 * SECTION: Constant definitions to be used within this file
40 #define DASD_CHANQ_MAX_SIZE 4
42 #define DASD_DIAG_MOD "dasd_diag_mod"
45 * SECTION: exported variables of dasd.c
47 debug_info_t
*dasd_debug_area
;
48 EXPORT_SYMBOL(dasd_debug_area
);
49 static struct dentry
*dasd_debugfs_root_entry
;
50 struct dasd_discipline
*dasd_diag_discipline_pointer
;
51 EXPORT_SYMBOL(dasd_diag_discipline_pointer
);
52 void dasd_int_handler(struct ccw_device
*, unsigned long, struct irb
*);
54 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
55 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
56 " Copyright IBM Corp. 2000");
57 MODULE_SUPPORTED_DEVICE("dasd");
58 MODULE_LICENSE("GPL");
61 * SECTION: prototypes for static functions of dasd.c
63 static int dasd_alloc_queue(struct dasd_block
*);
64 static void dasd_setup_queue(struct dasd_block
*);
65 static void dasd_free_queue(struct dasd_block
*);
66 static int dasd_flush_block_queue(struct dasd_block
*);
67 static void dasd_device_tasklet(struct dasd_device
*);
68 static void dasd_block_tasklet(struct dasd_block
*);
69 static void do_kick_device(struct work_struct
*);
70 static void do_restore_device(struct work_struct
*);
71 static void do_reload_device(struct work_struct
*);
72 static void do_requeue_requests(struct work_struct
*);
73 static void dasd_return_cqr_cb(struct dasd_ccw_req
*, void *);
74 static void dasd_device_timeout(struct timer_list
*);
75 static void dasd_block_timeout(struct timer_list
*);
76 static void __dasd_process_erp(struct dasd_device
*, struct dasd_ccw_req
*);
77 static void dasd_profile_init(struct dasd_profile
*, struct dentry
*);
78 static void dasd_profile_exit(struct dasd_profile
*);
79 static void dasd_hosts_init(struct dentry
*, struct dasd_device
*);
80 static void dasd_hosts_exit(struct dasd_device
*);
83 * SECTION: Operations on the device structure.
85 static wait_queue_head_t dasd_init_waitq
;
86 static wait_queue_head_t dasd_flush_wq
;
87 static wait_queue_head_t generic_waitq
;
88 static wait_queue_head_t shutdown_waitq
;
91 * Allocate memory for a new device structure.
93 struct dasd_device
*dasd_alloc_device(void)
95 struct dasd_device
*device
;
97 device
= kzalloc(sizeof(struct dasd_device
), GFP_ATOMIC
);
99 return ERR_PTR(-ENOMEM
);
101 /* Get two pages for normal block device operations. */
102 device
->ccw_mem
= (void *) __get_free_pages(GFP_ATOMIC
| GFP_DMA
, 1);
103 if (!device
->ccw_mem
) {
105 return ERR_PTR(-ENOMEM
);
107 /* Get one page for error recovery. */
108 device
->erp_mem
= (void *) get_zeroed_page(GFP_ATOMIC
| GFP_DMA
);
109 if (!device
->erp_mem
) {
110 free_pages((unsigned long) device
->ccw_mem
, 1);
112 return ERR_PTR(-ENOMEM
);
115 dasd_init_chunklist(&device
->ccw_chunks
, device
->ccw_mem
, PAGE_SIZE
*2);
116 dasd_init_chunklist(&device
->erp_chunks
, device
->erp_mem
, PAGE_SIZE
);
117 spin_lock_init(&device
->mem_lock
);
118 atomic_set(&device
->tasklet_scheduled
, 0);
119 tasklet_init(&device
->tasklet
,
120 (void (*)(unsigned long)) dasd_device_tasklet
,
121 (unsigned long) device
);
122 INIT_LIST_HEAD(&device
->ccw_queue
);
123 timer_setup(&device
->timer
, dasd_device_timeout
, 0);
124 INIT_WORK(&device
->kick_work
, do_kick_device
);
125 INIT_WORK(&device
->restore_device
, do_restore_device
);
126 INIT_WORK(&device
->reload_device
, do_reload_device
);
127 INIT_WORK(&device
->requeue_requests
, do_requeue_requests
);
128 device
->state
= DASD_STATE_NEW
;
129 device
->target
= DASD_STATE_NEW
;
130 mutex_init(&device
->state_mutex
);
131 spin_lock_init(&device
->profile
.lock
);
136 * Free memory of a device structure.
138 void dasd_free_device(struct dasd_device
*device
)
140 kfree(device
->private);
141 free_page((unsigned long) device
->erp_mem
);
142 free_pages((unsigned long) device
->ccw_mem
, 1);
147 * Allocate memory for a new device structure.
149 struct dasd_block
*dasd_alloc_block(void)
151 struct dasd_block
*block
;
153 block
= kzalloc(sizeof(*block
), GFP_ATOMIC
);
155 return ERR_PTR(-ENOMEM
);
156 /* open_count = 0 means device online but not in use */
157 atomic_set(&block
->open_count
, -1);
159 atomic_set(&block
->tasklet_scheduled
, 0);
160 tasklet_init(&block
->tasklet
,
161 (void (*)(unsigned long)) dasd_block_tasklet
,
162 (unsigned long) block
);
163 INIT_LIST_HEAD(&block
->ccw_queue
);
164 spin_lock_init(&block
->queue_lock
);
165 timer_setup(&block
->timer
, dasd_block_timeout
, 0);
166 spin_lock_init(&block
->profile
.lock
);
170 EXPORT_SYMBOL_GPL(dasd_alloc_block
);
173 * Free memory of a device structure.
175 void dasd_free_block(struct dasd_block
*block
)
179 EXPORT_SYMBOL_GPL(dasd_free_block
);
182 * Make a new device known to the system.
184 static int dasd_state_new_to_known(struct dasd_device
*device
)
189 * As long as the device is not in state DASD_STATE_NEW we want to
190 * keep the reference count > 0.
192 dasd_get_device(device
);
195 rc
= dasd_alloc_queue(device
->block
);
197 dasd_put_device(device
);
201 device
->state
= DASD_STATE_KNOWN
;
206 * Let the system forget about a device.
208 static int dasd_state_known_to_new(struct dasd_device
*device
)
210 /* Disable extended error reporting for this device. */
211 dasd_eer_disable(device
);
212 device
->state
= DASD_STATE_NEW
;
215 dasd_free_queue(device
->block
);
217 /* Give up reference we took in dasd_state_new_to_known. */
218 dasd_put_device(device
);
222 static struct dentry
*dasd_debugfs_setup(const char *name
,
223 struct dentry
*base_dentry
)
229 pde
= debugfs_create_dir(name
, base_dentry
);
230 if (!pde
|| IS_ERR(pde
))
236 * Request the irq line for the device.
238 static int dasd_state_known_to_basic(struct dasd_device
*device
)
240 struct dasd_block
*block
= device
->block
;
243 /* Allocate and register gendisk structure. */
245 rc
= dasd_gendisk_alloc(block
);
248 block
->debugfs_dentry
=
249 dasd_debugfs_setup(block
->gdp
->disk_name
,
250 dasd_debugfs_root_entry
);
251 dasd_profile_init(&block
->profile
, block
->debugfs_dentry
);
252 if (dasd_global_profile_level
== DASD_PROFILE_ON
)
253 dasd_profile_on(&device
->block
->profile
);
255 device
->debugfs_dentry
=
256 dasd_debugfs_setup(dev_name(&device
->cdev
->dev
),
257 dasd_debugfs_root_entry
);
258 dasd_profile_init(&device
->profile
, device
->debugfs_dentry
);
259 dasd_hosts_init(device
->debugfs_dentry
, device
);
261 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
262 device
->debug_area
= debug_register(dev_name(&device
->cdev
->dev
), 4, 1,
264 debug_register_view(device
->debug_area
, &debug_sprintf_view
);
265 debug_set_level(device
->debug_area
, DBF_WARNING
);
266 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s", "debug area created");
268 device
->state
= DASD_STATE_BASIC
;
274 * Release the irq line for the device. Terminate any running i/o.
276 static int dasd_state_basic_to_known(struct dasd_device
*device
)
280 if (device
->discipline
->basic_to_known
) {
281 rc
= device
->discipline
->basic_to_known(device
);
287 dasd_profile_exit(&device
->block
->profile
);
288 debugfs_remove(device
->block
->debugfs_dentry
);
289 dasd_gendisk_free(device
->block
);
290 dasd_block_clear_timer(device
->block
);
292 rc
= dasd_flush_device_queue(device
);
295 dasd_device_clear_timer(device
);
296 dasd_profile_exit(&device
->profile
);
297 dasd_hosts_exit(device
);
298 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
;
326 struct gendisk
*disk
;
329 block
= device
->block
;
330 /* make disk known with correct capacity */
332 if (block
->base
->discipline
->do_analysis
!= NULL
)
333 rc
= block
->base
->discipline
->do_analysis(block
);
336 device
->state
= DASD_STATE_UNFMT
;
337 disk
= device
->block
->gdp
;
338 kobject_uevent(&disk_to_dev(disk
)->kobj
,
344 dasd_setup_queue(block
);
345 set_capacity(block
->gdp
,
346 block
->blocks
<< block
->s2b_shift
);
347 device
->state
= DASD_STATE_READY
;
348 rc
= dasd_scan_partitions(block
);
350 device
->state
= DASD_STATE_BASIC
;
354 device
->state
= DASD_STATE_READY
;
357 if (device
->discipline
->basic_to_ready
)
358 rc
= device
->discipline
->basic_to_ready(device
);
363 int _wait_for_empty_queues(struct dasd_device
*device
)
366 return list_empty(&device
->ccw_queue
) &&
367 list_empty(&device
->block
->ccw_queue
);
369 return list_empty(&device
->ccw_queue
);
373 * Remove device from block device layer. Destroy dirty buffers.
374 * Forget format information. Check if the target level is basic
375 * and if it is create fake disk for formatting.
377 static int dasd_state_ready_to_basic(struct dasd_device
*device
)
381 device
->state
= DASD_STATE_BASIC
;
383 struct dasd_block
*block
= device
->block
;
384 rc
= dasd_flush_block_queue(block
);
386 device
->state
= DASD_STATE_READY
;
389 dasd_destroy_partitions(block
);
392 block
->s2b_shift
= 0;
400 static int dasd_state_unfmt_to_basic(struct dasd_device
*device
)
402 device
->state
= DASD_STATE_BASIC
;
407 * Make the device online and schedule the bottom half to start
408 * the requeueing of requests from the linux request queue to the
412 dasd_state_ready_to_online(struct dasd_device
* device
)
414 struct gendisk
*disk
;
415 struct disk_part_iter piter
;
416 struct hd_struct
*part
;
418 device
->state
= DASD_STATE_ONLINE
;
420 dasd_schedule_block_bh(device
->block
);
421 if ((device
->features
& DASD_FEATURE_USERAW
)) {
422 disk
= device
->block
->gdp
;
423 kobject_uevent(&disk_to_dev(disk
)->kobj
, KOBJ_CHANGE
);
426 disk
= device
->block
->bdev
->bd_disk
;
427 disk_part_iter_init(&piter
, disk
, DISK_PITER_INCL_PART0
);
428 while ((part
= disk_part_iter_next(&piter
)))
429 kobject_uevent(&part_to_dev(part
)->kobj
, KOBJ_CHANGE
);
430 disk_part_iter_exit(&piter
);
436 * Stop the requeueing of requests again.
438 static int dasd_state_online_to_ready(struct dasd_device
*device
)
441 struct gendisk
*disk
;
442 struct disk_part_iter piter
;
443 struct hd_struct
*part
;
445 if (device
->discipline
->online_to_ready
) {
446 rc
= device
->discipline
->online_to_ready(device
);
451 device
->state
= DASD_STATE_READY
;
452 if (device
->block
&& !(device
->features
& DASD_FEATURE_USERAW
)) {
453 disk
= device
->block
->bdev
->bd_disk
;
454 disk_part_iter_init(&piter
, disk
, DISK_PITER_INCL_PART0
);
455 while ((part
= disk_part_iter_next(&piter
)))
456 kobject_uevent(&part_to_dev(part
)->kobj
, KOBJ_CHANGE
);
457 disk_part_iter_exit(&piter
);
463 * Device startup state changes.
465 static int dasd_increase_state(struct dasd_device
*device
)
470 if (device
->state
== DASD_STATE_NEW
&&
471 device
->target
>= DASD_STATE_KNOWN
)
472 rc
= dasd_state_new_to_known(device
);
475 device
->state
== DASD_STATE_KNOWN
&&
476 device
->target
>= DASD_STATE_BASIC
)
477 rc
= dasd_state_known_to_basic(device
);
480 device
->state
== DASD_STATE_BASIC
&&
481 device
->target
>= DASD_STATE_READY
)
482 rc
= dasd_state_basic_to_ready(device
);
485 device
->state
== DASD_STATE_UNFMT
&&
486 device
->target
> DASD_STATE_UNFMT
)
490 device
->state
== DASD_STATE_READY
&&
491 device
->target
>= DASD_STATE_ONLINE
)
492 rc
= dasd_state_ready_to_online(device
);
498 * Device shutdown state changes.
500 static int dasd_decrease_state(struct dasd_device
*device
)
505 if (device
->state
== DASD_STATE_ONLINE
&&
506 device
->target
<= DASD_STATE_READY
)
507 rc
= dasd_state_online_to_ready(device
);
510 device
->state
== DASD_STATE_READY
&&
511 device
->target
<= DASD_STATE_BASIC
)
512 rc
= dasd_state_ready_to_basic(device
);
515 device
->state
== DASD_STATE_UNFMT
&&
516 device
->target
<= DASD_STATE_BASIC
)
517 rc
= dasd_state_unfmt_to_basic(device
);
520 device
->state
== DASD_STATE_BASIC
&&
521 device
->target
<= DASD_STATE_KNOWN
)
522 rc
= dasd_state_basic_to_known(device
);
525 device
->state
== DASD_STATE_KNOWN
&&
526 device
->target
<= DASD_STATE_NEW
)
527 rc
= dasd_state_known_to_new(device
);
533 * This is the main startup/shutdown routine.
535 static void dasd_change_state(struct dasd_device
*device
)
539 if (device
->state
== device
->target
)
540 /* Already where we want to go today... */
542 if (device
->state
< device
->target
)
543 rc
= dasd_increase_state(device
);
545 rc
= dasd_decrease_state(device
);
549 device
->target
= device
->state
;
551 /* let user-space know that the device status changed */
552 kobject_uevent(&device
->cdev
->dev
.kobj
, KOBJ_CHANGE
);
554 if (device
->state
== device
->target
)
555 wake_up(&dasd_init_waitq
);
559 * Kick starter for devices that did not complete the startup/shutdown
560 * procedure or were sleeping because of a pending state.
561 * dasd_kick_device will schedule a call do do_kick_device to the kernel
564 static void do_kick_device(struct work_struct
*work
)
566 struct dasd_device
*device
= container_of(work
, struct dasd_device
, kick_work
);
567 mutex_lock(&device
->state_mutex
);
568 dasd_change_state(device
);
569 mutex_unlock(&device
->state_mutex
);
570 dasd_schedule_device_bh(device
);
571 dasd_put_device(device
);
574 void dasd_kick_device(struct dasd_device
*device
)
576 dasd_get_device(device
);
577 /* queue call to dasd_kick_device to the kernel event daemon. */
578 if (!schedule_work(&device
->kick_work
))
579 dasd_put_device(device
);
581 EXPORT_SYMBOL(dasd_kick_device
);
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 if (!schedule_work(&device
->reload_device
))
600 dasd_put_device(device
);
602 EXPORT_SYMBOL(dasd_reload_device
);
605 * dasd_restore_device will schedule a call do do_restore_device to the kernel
608 static void do_restore_device(struct work_struct
*work
)
610 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
612 device
->cdev
->drv
->restore(device
->cdev
);
613 dasd_put_device(device
);
616 void dasd_restore_device(struct dasd_device
*device
)
618 dasd_get_device(device
);
619 /* queue call to dasd_restore_device to the kernel event daemon. */
620 if (!schedule_work(&device
->restore_device
))
621 dasd_put_device(device
);
625 * Set the target state for a device and starts the state change.
627 void dasd_set_target_state(struct dasd_device
*device
, int target
)
629 dasd_get_device(device
);
630 mutex_lock(&device
->state_mutex
);
631 /* If we are in probeonly mode stop at DASD_STATE_READY. */
632 if (dasd_probeonly
&& target
> DASD_STATE_READY
)
633 target
= DASD_STATE_READY
;
634 if (device
->target
!= target
) {
635 if (device
->state
== target
)
636 wake_up(&dasd_init_waitq
);
637 device
->target
= target
;
639 if (device
->state
!= device
->target
)
640 dasd_change_state(device
);
641 mutex_unlock(&device
->state_mutex
);
642 dasd_put_device(device
);
644 EXPORT_SYMBOL(dasd_set_target_state
);
647 * Enable devices with device numbers in [from..to].
649 static inline int _wait_for_device(struct dasd_device
*device
)
651 return (device
->state
== device
->target
);
654 void dasd_enable_device(struct dasd_device
*device
)
656 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
657 if (device
->state
<= DASD_STATE_KNOWN
)
658 /* No discipline for device found. */
659 dasd_set_target_state(device
, DASD_STATE_NEW
);
660 /* Now wait for the devices to come up. */
661 wait_event(dasd_init_waitq
, _wait_for_device(device
));
663 dasd_reload_device(device
);
664 if (device
->discipline
->kick_validate
)
665 device
->discipline
->kick_validate(device
);
667 EXPORT_SYMBOL(dasd_enable_device
);
670 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
673 unsigned int dasd_global_profile_level
= DASD_PROFILE_OFF
;
675 #ifdef CONFIG_DASD_PROFILE
676 struct dasd_profile dasd_global_profile
= {
677 .lock
= __SPIN_LOCK_UNLOCKED(dasd_global_profile
.lock
),
679 static struct dentry
*dasd_debugfs_global_entry
;
682 * Add profiling information for cqr before execution.
684 static void dasd_profile_start(struct dasd_block
*block
,
685 struct dasd_ccw_req
*cqr
,
689 unsigned int counter
;
690 struct dasd_device
*device
;
692 /* count the length of the chanq for statistics */
694 if (dasd_global_profile_level
|| block
->profile
.data
)
695 list_for_each(l
, &block
->ccw_queue
)
699 spin_lock(&dasd_global_profile
.lock
);
700 if (dasd_global_profile
.data
) {
701 dasd_global_profile
.data
->dasd_io_nr_req
[counter
]++;
702 if (rq_data_dir(req
) == READ
)
703 dasd_global_profile
.data
->dasd_read_nr_req
[counter
]++;
705 spin_unlock(&dasd_global_profile
.lock
);
707 spin_lock(&block
->profile
.lock
);
708 if (block
->profile
.data
) {
709 block
->profile
.data
->dasd_io_nr_req
[counter
]++;
710 if (rq_data_dir(req
) == READ
)
711 block
->profile
.data
->dasd_read_nr_req
[counter
]++;
713 spin_unlock(&block
->profile
.lock
);
716 * We count the request for the start device, even though it may run on
717 * some other device due to error recovery. This way we make sure that
718 * we count each request only once.
720 device
= cqr
->startdev
;
721 if (device
->profile
.data
) {
722 counter
= 1; /* request is not yet queued on the start device */
723 list_for_each(l
, &device
->ccw_queue
)
727 spin_lock(&device
->profile
.lock
);
728 if (device
->profile
.data
) {
729 device
->profile
.data
->dasd_io_nr_req
[counter
]++;
730 if (rq_data_dir(req
) == READ
)
731 device
->profile
.data
->dasd_read_nr_req
[counter
]++;
733 spin_unlock(&device
->profile
.lock
);
737 * Add profiling information for cqr after execution.
740 #define dasd_profile_counter(value, index) \
742 for (index = 0; index < 31 && value >> (2+index); index++) \
746 static void dasd_profile_end_add_data(struct dasd_profile_info
*data
,
759 /* in case of an overflow, reset the whole profile */
760 if (data
->dasd_io_reqs
== UINT_MAX
) {
761 memset(data
, 0, sizeof(*data
));
762 ktime_get_real_ts64(&data
->starttod
);
764 data
->dasd_io_reqs
++;
765 data
->dasd_io_sects
+= sectors
;
767 data
->dasd_io_alias
++;
771 data
->dasd_io_secs
[sectors_ind
]++;
772 data
->dasd_io_times
[tottime_ind
]++;
773 data
->dasd_io_timps
[tottimeps_ind
]++;
774 data
->dasd_io_time1
[strtime_ind
]++;
775 data
->dasd_io_time2
[irqtime_ind
]++;
776 data
->dasd_io_time2ps
[irqtimeps_ind
]++;
777 data
->dasd_io_time3
[endtime_ind
]++;
780 data
->dasd_read_reqs
++;
781 data
->dasd_read_sects
+= sectors
;
783 data
->dasd_read_alias
++;
785 data
->dasd_read_tpm
++;
786 data
->dasd_read_secs
[sectors_ind
]++;
787 data
->dasd_read_times
[tottime_ind
]++;
788 data
->dasd_read_time1
[strtime_ind
]++;
789 data
->dasd_read_time2
[irqtime_ind
]++;
790 data
->dasd_read_time3
[endtime_ind
]++;
794 static void dasd_profile_end(struct dasd_block
*block
,
795 struct dasd_ccw_req
*cqr
,
798 unsigned long strtime
, irqtime
, endtime
, tottime
;
799 unsigned long tottimeps
, sectors
;
800 struct dasd_device
*device
;
801 int sectors_ind
, tottime_ind
, tottimeps_ind
, strtime_ind
;
802 int irqtime_ind
, irqtimeps_ind
, endtime_ind
;
803 struct dasd_profile_info
*data
;
805 device
= cqr
->startdev
;
806 if (!(dasd_global_profile_level
||
807 block
->profile
.data
||
808 device
->profile
.data
))
811 sectors
= blk_rq_sectors(req
);
812 if (!cqr
->buildclk
|| !cqr
->startclk
||
813 !cqr
->stopclk
|| !cqr
->endclk
||
817 strtime
= ((cqr
->startclk
- cqr
->buildclk
) >> 12);
818 irqtime
= ((cqr
->stopclk
- cqr
->startclk
) >> 12);
819 endtime
= ((cqr
->endclk
- cqr
->stopclk
) >> 12);
820 tottime
= ((cqr
->endclk
- cqr
->buildclk
) >> 12);
821 tottimeps
= tottime
/ sectors
;
823 dasd_profile_counter(sectors
, sectors_ind
);
824 dasd_profile_counter(tottime
, tottime_ind
);
825 dasd_profile_counter(tottimeps
, tottimeps_ind
);
826 dasd_profile_counter(strtime
, strtime_ind
);
827 dasd_profile_counter(irqtime
, irqtime_ind
);
828 dasd_profile_counter(irqtime
/ sectors
, irqtimeps_ind
);
829 dasd_profile_counter(endtime
, endtime_ind
);
831 spin_lock(&dasd_global_profile
.lock
);
832 if (dasd_global_profile
.data
) {
833 data
= dasd_global_profile
.data
;
834 data
->dasd_sum_times
+= tottime
;
835 data
->dasd_sum_time_str
+= strtime
;
836 data
->dasd_sum_time_irq
+= irqtime
;
837 data
->dasd_sum_time_end
+= endtime
;
838 dasd_profile_end_add_data(dasd_global_profile
.data
,
839 cqr
->startdev
!= block
->base
,
841 rq_data_dir(req
) == READ
,
842 sectors
, sectors_ind
, tottime_ind
,
843 tottimeps_ind
, strtime_ind
,
844 irqtime_ind
, irqtimeps_ind
,
847 spin_unlock(&dasd_global_profile
.lock
);
849 spin_lock(&block
->profile
.lock
);
850 if (block
->profile
.data
) {
851 data
= block
->profile
.data
;
852 data
->dasd_sum_times
+= tottime
;
853 data
->dasd_sum_time_str
+= strtime
;
854 data
->dasd_sum_time_irq
+= irqtime
;
855 data
->dasd_sum_time_end
+= endtime
;
856 dasd_profile_end_add_data(block
->profile
.data
,
857 cqr
->startdev
!= block
->base
,
859 rq_data_dir(req
) == READ
,
860 sectors
, sectors_ind
, tottime_ind
,
861 tottimeps_ind
, strtime_ind
,
862 irqtime_ind
, irqtimeps_ind
,
865 spin_unlock(&block
->profile
.lock
);
867 spin_lock(&device
->profile
.lock
);
868 if (device
->profile
.data
) {
869 data
= device
->profile
.data
;
870 data
->dasd_sum_times
+= tottime
;
871 data
->dasd_sum_time_str
+= strtime
;
872 data
->dasd_sum_time_irq
+= irqtime
;
873 data
->dasd_sum_time_end
+= endtime
;
874 dasd_profile_end_add_data(device
->profile
.data
,
875 cqr
->startdev
!= block
->base
,
877 rq_data_dir(req
) == READ
,
878 sectors
, sectors_ind
, tottime_ind
,
879 tottimeps_ind
, strtime_ind
,
880 irqtime_ind
, irqtimeps_ind
,
883 spin_unlock(&device
->profile
.lock
);
886 void dasd_profile_reset(struct dasd_profile
*profile
)
888 struct dasd_profile_info
*data
;
890 spin_lock_bh(&profile
->lock
);
891 data
= profile
->data
;
893 spin_unlock_bh(&profile
->lock
);
896 memset(data
, 0, sizeof(*data
));
897 ktime_get_real_ts64(&data
->starttod
);
898 spin_unlock_bh(&profile
->lock
);
901 int dasd_profile_on(struct dasd_profile
*profile
)
903 struct dasd_profile_info
*data
;
905 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
908 spin_lock_bh(&profile
->lock
);
910 spin_unlock_bh(&profile
->lock
);
914 ktime_get_real_ts64(&data
->starttod
);
915 profile
->data
= data
;
916 spin_unlock_bh(&profile
->lock
);
920 void dasd_profile_off(struct dasd_profile
*profile
)
922 spin_lock_bh(&profile
->lock
);
923 kfree(profile
->data
);
924 profile
->data
= NULL
;
925 spin_unlock_bh(&profile
->lock
);
928 char *dasd_get_user_string(const char __user
*user_buf
, size_t user_len
)
932 buffer
= vmalloc(user_len
+ 1);
934 return ERR_PTR(-ENOMEM
);
935 if (copy_from_user(buffer
, user_buf
, user_len
) != 0) {
937 return ERR_PTR(-EFAULT
);
939 /* got the string, now strip linefeed. */
940 if (buffer
[user_len
- 1] == '\n')
941 buffer
[user_len
- 1] = 0;
943 buffer
[user_len
] = 0;
947 static ssize_t
dasd_stats_write(struct file
*file
,
948 const char __user
*user_buf
,
949 size_t user_len
, loff_t
*pos
)
953 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
954 struct dasd_profile
*prof
= m
->private;
956 if (user_len
> 65536)
958 buffer
= dasd_get_user_string(user_buf
, user_len
);
960 return PTR_ERR(buffer
);
962 str
= skip_spaces(buffer
);
964 if (strncmp(str
, "reset", 5) == 0) {
965 dasd_profile_reset(prof
);
966 } else if (strncmp(str
, "on", 2) == 0) {
967 rc
= dasd_profile_on(prof
);
971 if (prof
== &dasd_global_profile
) {
972 dasd_profile_reset(prof
);
973 dasd_global_profile_level
= DASD_PROFILE_GLOBAL_ONLY
;
975 } else if (strncmp(str
, "off", 3) == 0) {
976 if (prof
== &dasd_global_profile
)
977 dasd_global_profile_level
= DASD_PROFILE_OFF
;
978 dasd_profile_off(prof
);
986 static void dasd_stats_array(struct seq_file
*m
, unsigned int *array
)
990 for (i
= 0; i
< 32; i
++)
991 seq_printf(m
, "%u ", array
[i
]);
995 static void dasd_stats_seq_print(struct seq_file
*m
,
996 struct dasd_profile_info
*data
)
998 seq_printf(m
, "start_time %lld.%09ld\n",
999 (s64
)data
->starttod
.tv_sec
, data
->starttod
.tv_nsec
);
1000 seq_printf(m
, "total_requests %u\n", data
->dasd_io_reqs
);
1001 seq_printf(m
, "total_sectors %u\n", data
->dasd_io_sects
);
1002 seq_printf(m
, "total_pav %u\n", data
->dasd_io_alias
);
1003 seq_printf(m
, "total_hpf %u\n", data
->dasd_io_tpm
);
1004 seq_printf(m
, "avg_total %lu\n", data
->dasd_io_reqs
?
1005 data
->dasd_sum_times
/ data
->dasd_io_reqs
: 0UL);
1006 seq_printf(m
, "avg_build_to_ssch %lu\n", data
->dasd_io_reqs
?
1007 data
->dasd_sum_time_str
/ data
->dasd_io_reqs
: 0UL);
1008 seq_printf(m
, "avg_ssch_to_irq %lu\n", data
->dasd_io_reqs
?
1009 data
->dasd_sum_time_irq
/ data
->dasd_io_reqs
: 0UL);
1010 seq_printf(m
, "avg_irq_to_end %lu\n", data
->dasd_io_reqs
?
1011 data
->dasd_sum_time_end
/ data
->dasd_io_reqs
: 0UL);
1012 seq_puts(m
, "histogram_sectors ");
1013 dasd_stats_array(m
, data
->dasd_io_secs
);
1014 seq_puts(m
, "histogram_io_times ");
1015 dasd_stats_array(m
, data
->dasd_io_times
);
1016 seq_puts(m
, "histogram_io_times_weighted ");
1017 dasd_stats_array(m
, data
->dasd_io_timps
);
1018 seq_puts(m
, "histogram_time_build_to_ssch ");
1019 dasd_stats_array(m
, data
->dasd_io_time1
);
1020 seq_puts(m
, "histogram_time_ssch_to_irq ");
1021 dasd_stats_array(m
, data
->dasd_io_time2
);
1022 seq_puts(m
, "histogram_time_ssch_to_irq_weighted ");
1023 dasd_stats_array(m
, data
->dasd_io_time2ps
);
1024 seq_puts(m
, "histogram_time_irq_to_end ");
1025 dasd_stats_array(m
, data
->dasd_io_time3
);
1026 seq_puts(m
, "histogram_ccw_queue_length ");
1027 dasd_stats_array(m
, data
->dasd_io_nr_req
);
1028 seq_printf(m
, "total_read_requests %u\n", data
->dasd_read_reqs
);
1029 seq_printf(m
, "total_read_sectors %u\n", data
->dasd_read_sects
);
1030 seq_printf(m
, "total_read_pav %u\n", data
->dasd_read_alias
);
1031 seq_printf(m
, "total_read_hpf %u\n", data
->dasd_read_tpm
);
1032 seq_puts(m
, "histogram_read_sectors ");
1033 dasd_stats_array(m
, data
->dasd_read_secs
);
1034 seq_puts(m
, "histogram_read_times ");
1035 dasd_stats_array(m
, data
->dasd_read_times
);
1036 seq_puts(m
, "histogram_read_time_build_to_ssch ");
1037 dasd_stats_array(m
, data
->dasd_read_time1
);
1038 seq_puts(m
, "histogram_read_time_ssch_to_irq ");
1039 dasd_stats_array(m
, data
->dasd_read_time2
);
1040 seq_puts(m
, "histogram_read_time_irq_to_end ");
1041 dasd_stats_array(m
, data
->dasd_read_time3
);
1042 seq_puts(m
, "histogram_read_ccw_queue_length ");
1043 dasd_stats_array(m
, data
->dasd_read_nr_req
);
1046 static int dasd_stats_show(struct seq_file
*m
, void *v
)
1048 struct dasd_profile
*profile
;
1049 struct dasd_profile_info
*data
;
1051 profile
= m
->private;
1052 spin_lock_bh(&profile
->lock
);
1053 data
= profile
->data
;
1055 spin_unlock_bh(&profile
->lock
);
1056 seq_puts(m
, "disabled\n");
1059 dasd_stats_seq_print(m
, data
);
1060 spin_unlock_bh(&profile
->lock
);
1064 static int dasd_stats_open(struct inode
*inode
, struct file
*file
)
1066 struct dasd_profile
*profile
= inode
->i_private
;
1067 return single_open(file
, dasd_stats_show
, profile
);
1070 static const struct file_operations dasd_stats_raw_fops
= {
1071 .owner
= THIS_MODULE
,
1072 .open
= dasd_stats_open
,
1074 .llseek
= seq_lseek
,
1075 .release
= single_release
,
1076 .write
= dasd_stats_write
,
1079 static void dasd_profile_init(struct dasd_profile
*profile
,
1080 struct dentry
*base_dentry
)
1087 profile
->dentry
= NULL
;
1088 profile
->data
= NULL
;
1089 mode
= (S_IRUSR
| S_IWUSR
| S_IFREG
);
1090 pde
= debugfs_create_file("statistics", mode
, base_dentry
,
1091 profile
, &dasd_stats_raw_fops
);
1092 if (pde
&& !IS_ERR(pde
))
1093 profile
->dentry
= pde
;
1097 static void dasd_profile_exit(struct dasd_profile
*profile
)
1099 dasd_profile_off(profile
);
1100 debugfs_remove(profile
->dentry
);
1101 profile
->dentry
= NULL
;
1104 static void dasd_statistics_removeroot(void)
1106 dasd_global_profile_level
= DASD_PROFILE_OFF
;
1107 dasd_profile_exit(&dasd_global_profile
);
1108 debugfs_remove(dasd_debugfs_global_entry
);
1109 debugfs_remove(dasd_debugfs_root_entry
);
1112 static void dasd_statistics_createroot(void)
1116 dasd_debugfs_root_entry
= NULL
;
1117 pde
= debugfs_create_dir("dasd", NULL
);
1118 if (!pde
|| IS_ERR(pde
))
1120 dasd_debugfs_root_entry
= pde
;
1121 pde
= debugfs_create_dir("global", dasd_debugfs_root_entry
);
1122 if (!pde
|| IS_ERR(pde
))
1124 dasd_debugfs_global_entry
= pde
;
1125 dasd_profile_init(&dasd_global_profile
, dasd_debugfs_global_entry
);
1129 DBF_EVENT(DBF_ERR
, "%s",
1130 "Creation of the dasd debugfs interface failed");
1131 dasd_statistics_removeroot();
1136 #define dasd_profile_start(block, cqr, req) do {} while (0)
1137 #define dasd_profile_end(block, cqr, req) do {} while (0)
1139 static void dasd_statistics_createroot(void)
1144 static void dasd_statistics_removeroot(void)
1149 int dasd_stats_generic_show(struct seq_file
*m
, void *v
)
1151 seq_puts(m
, "Statistics are not activated in this kernel\n");
1155 static void dasd_profile_init(struct dasd_profile
*profile
,
1156 struct dentry
*base_dentry
)
1161 static void dasd_profile_exit(struct dasd_profile
*profile
)
1166 int dasd_profile_on(struct dasd_profile
*profile
)
1171 #endif /* CONFIG_DASD_PROFILE */
1173 static int dasd_hosts_show(struct seq_file
*m
, void *v
)
1175 struct dasd_device
*device
;
1176 int rc
= -EOPNOTSUPP
;
1178 device
= m
->private;
1179 dasd_get_device(device
);
1181 if (device
->discipline
->hosts_print
)
1182 rc
= device
->discipline
->hosts_print(device
, m
);
1184 dasd_put_device(device
);
1188 static int dasd_hosts_open(struct inode
*inode
, struct file
*file
)
1190 struct dasd_device
*device
= inode
->i_private
;
1192 return single_open(file
, dasd_hosts_show
, device
);
1195 static const struct file_operations dasd_hosts_fops
= {
1196 .owner
= THIS_MODULE
,
1197 .open
= dasd_hosts_open
,
1199 .llseek
= seq_lseek
,
1200 .release
= single_release
,
1203 static void dasd_hosts_exit(struct dasd_device
*device
)
1205 debugfs_remove(device
->hosts_dentry
);
1206 device
->hosts_dentry
= NULL
;
1209 static void dasd_hosts_init(struct dentry
*base_dentry
,
1210 struct dasd_device
*device
)
1218 mode
= S_IRUSR
| S_IFREG
;
1219 pde
= debugfs_create_file("host_access_list", mode
, base_dentry
,
1220 device
, &dasd_hosts_fops
);
1221 if (pde
&& !IS_ERR(pde
))
1222 device
->hosts_dentry
= pde
;
1226 * Allocate memory for a channel program with 'cplength' channel
1227 * command words and 'datasize' additional space. There are two
1228 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1229 * memory and 2) dasd_smalloc_request uses the static ccw memory
1230 * that gets allocated for each device.
1232 struct dasd_ccw_req
*dasd_kmalloc_request(int magic
, int cplength
,
1234 struct dasd_device
*device
)
1236 struct dasd_ccw_req
*cqr
;
1239 BUG_ON(datasize
> PAGE_SIZE
||
1240 (cplength
*sizeof(struct ccw1
)) > PAGE_SIZE
);
1242 cqr
= kzalloc(sizeof(struct dasd_ccw_req
), GFP_ATOMIC
);
1244 return ERR_PTR(-ENOMEM
);
1247 cqr
->cpaddr
= kcalloc(cplength
, sizeof(struct ccw1
),
1248 GFP_ATOMIC
| GFP_DMA
);
1249 if (cqr
->cpaddr
== NULL
) {
1251 return ERR_PTR(-ENOMEM
);
1256 cqr
->data
= kzalloc(datasize
, GFP_ATOMIC
| GFP_DMA
);
1257 if (cqr
->data
== NULL
) {
1260 return ERR_PTR(-ENOMEM
);
1264 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1265 dasd_get_device(device
);
1268 EXPORT_SYMBOL(dasd_kmalloc_request
);
1270 struct dasd_ccw_req
*dasd_smalloc_request(int magic
, int cplength
,
1272 struct dasd_device
*device
)
1274 unsigned long flags
;
1275 struct dasd_ccw_req
*cqr
;
1279 size
= (sizeof(struct dasd_ccw_req
) + 7L) & -8L;
1281 size
+= cplength
* sizeof(struct ccw1
);
1284 spin_lock_irqsave(&device
->mem_lock
, flags
);
1285 cqr
= (struct dasd_ccw_req
*)
1286 dasd_alloc_chunk(&device
->ccw_chunks
, size
);
1287 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
1289 return ERR_PTR(-ENOMEM
);
1290 memset(cqr
, 0, sizeof(struct dasd_ccw_req
));
1291 data
= (char *) cqr
+ ((sizeof(struct dasd_ccw_req
) + 7L) & -8L);
1294 cqr
->cpaddr
= (struct ccw1
*) data
;
1295 data
+= cplength
*sizeof(struct ccw1
);
1296 memset(cqr
->cpaddr
, 0, cplength
*sizeof(struct ccw1
));
1301 memset(cqr
->data
, 0, datasize
);
1304 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1305 dasd_get_device(device
);
1308 EXPORT_SYMBOL(dasd_smalloc_request
);
1311 * Free memory of a channel program. This function needs to free all the
1312 * idal lists that might have been created by dasd_set_cda and the
1313 * struct dasd_ccw_req itself.
1315 void dasd_kfree_request(struct dasd_ccw_req
*cqr
, struct dasd_device
*device
)
1319 /* Clear any idals used for the request. */
1322 clear_normalized_cda(ccw
);
1323 } while (ccw
++->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
));
1327 dasd_put_device(device
);
1329 EXPORT_SYMBOL(dasd_kfree_request
);
1331 void dasd_sfree_request(struct dasd_ccw_req
*cqr
, struct dasd_device
*device
)
1333 unsigned long flags
;
1335 spin_lock_irqsave(&device
->mem_lock
, flags
);
1336 dasd_free_chunk(&device
->ccw_chunks
, cqr
);
1337 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
1338 dasd_put_device(device
);
1340 EXPORT_SYMBOL(dasd_sfree_request
);
1343 * Check discipline magic in cqr.
1345 static inline int dasd_check_cqr(struct dasd_ccw_req
*cqr
)
1347 struct dasd_device
*device
;
1351 device
= cqr
->startdev
;
1352 if (strncmp((char *) &cqr
->magic
, device
->discipline
->ebcname
, 4)) {
1353 DBF_DEV_EVENT(DBF_WARNING
, device
,
1354 " dasd_ccw_req 0x%08x magic doesn't match"
1355 " discipline 0x%08x",
1357 *(unsigned int *) device
->discipline
->name
);
1364 * Terminate the current i/o and set the request to clear_pending.
1365 * Timer keeps device runnig.
1366 * ccw_device_clear can fail if the i/o subsystem
1369 int dasd_term_IO(struct dasd_ccw_req
*cqr
)
1371 struct dasd_device
*device
;
1373 char errorstring
[ERRORLENGTH
];
1376 rc
= dasd_check_cqr(cqr
);
1380 device
= (struct dasd_device
*) cqr
->startdev
;
1381 while ((retries
< 5) && (cqr
->status
== DASD_CQR_IN_IO
)) {
1382 rc
= ccw_device_clear(device
->cdev
, (long) cqr
);
1384 case 0: /* termination successful */
1385 cqr
->status
= DASD_CQR_CLEAR_PENDING
;
1386 cqr
->stopclk
= get_tod_clock();
1388 DBF_DEV_EVENT(DBF_DEBUG
, device
,
1389 "terminate cqr %p successful",
1393 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1394 "device gone, retry");
1398 * device not valid so no I/O could be running
1399 * handle CQR as termination successful
1401 cqr
->status
= DASD_CQR_CLEARED
;
1402 cqr
->stopclk
= get_tod_clock();
1404 /* no retries for invalid devices */
1406 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1407 "EINVAL, handle as terminated");
1408 /* fake rc to success */
1412 /* internal error 10 - unknown rc*/
1413 snprintf(errorstring
, ERRORLENGTH
, "10 %d", rc
);
1414 dev_err(&device
->cdev
->dev
, "An error occurred in the "
1415 "DASD device driver, reason=%s\n", errorstring
);
1421 dasd_schedule_device_bh(device
);
1424 EXPORT_SYMBOL(dasd_term_IO
);
1427 * Start the i/o. This start_IO can fail if the channel is really busy.
1428 * In that case set up a timer to start the request later.
1430 int dasd_start_IO(struct dasd_ccw_req
*cqr
)
1432 struct dasd_device
*device
;
1434 char errorstring
[ERRORLENGTH
];
1437 rc
= dasd_check_cqr(cqr
);
1442 device
= (struct dasd_device
*) cqr
->startdev
;
1444 test_bit(DASD_FLAG_LOCK_STOLEN
, &cqr
->block
->base
->flags
)) ||
1445 test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
)) &&
1446 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
1447 DBF_DEV_EVENT(DBF_DEBUG
, device
, "start_IO: return request %p "
1448 "because of stolen lock", cqr
);
1449 cqr
->status
= DASD_CQR_ERROR
;
1450 cqr
->intrc
= -EPERM
;
1453 if (cqr
->retries
< 0) {
1454 /* internal error 14 - start_IO run out of retries */
1455 sprintf(errorstring
, "14 %p", cqr
);
1456 dev_err(&device
->cdev
->dev
, "An error occurred in the DASD "
1457 "device driver, reason=%s\n", errorstring
);
1458 cqr
->status
= DASD_CQR_ERROR
;
1461 cqr
->startclk
= get_tod_clock();
1462 cqr
->starttime
= jiffies
;
1464 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1465 cqr
->lpm
&= dasd_path_get_opm(device
);
1467 cqr
->lpm
= dasd_path_get_opm(device
);
1469 if (cqr
->cpmode
== 1) {
1470 rc
= ccw_device_tm_start(device
->cdev
, cqr
->cpaddr
,
1471 (long) cqr
, cqr
->lpm
);
1473 rc
= ccw_device_start(device
->cdev
, cqr
->cpaddr
,
1474 (long) cqr
, cqr
->lpm
, 0);
1478 cqr
->status
= DASD_CQR_IN_IO
;
1481 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1482 "start_IO: device busy, retry later");
1485 /* -EACCES indicates that the request used only a subset of the
1486 * available paths and all these paths are gone. If the lpm of
1487 * this request was only a subset of the opm (e.g. the ppm) then
1488 * we just do a retry with all available paths.
1489 * If we already use the full opm, something is amiss, and we
1490 * need a full path verification.
1492 if (test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1493 DBF_DEV_EVENT(DBF_WARNING
, device
,
1494 "start_IO: selected paths gone (%x)",
1496 } else if (cqr
->lpm
!= dasd_path_get_opm(device
)) {
1497 cqr
->lpm
= dasd_path_get_opm(device
);
1498 DBF_DEV_EVENT(DBF_DEBUG
, device
, "%s",
1499 "start_IO: selected paths gone,"
1500 " retry on all paths");
1502 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1503 "start_IO: all paths in opm gone,"
1504 " do path verification");
1505 dasd_generic_last_path_gone(device
);
1506 dasd_path_no_path(device
);
1507 dasd_path_set_tbvpm(device
,
1508 ccw_device_get_path_mask(
1513 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1514 "start_IO: -ENODEV device gone, retry");
1517 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1518 "start_IO: -EIO device gone, retry");
1521 /* most likely caused in power management context */
1522 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1523 "start_IO: -EINVAL device currently "
1527 /* internal error 11 - unknown rc */
1528 snprintf(errorstring
, ERRORLENGTH
, "11 %d", rc
);
1529 dev_err(&device
->cdev
->dev
,
1530 "An error occurred in the DASD device driver, "
1531 "reason=%s\n", errorstring
);
1538 EXPORT_SYMBOL(dasd_start_IO
);
1541 * Timeout function for dasd devices. This is used for different purposes
1542 * 1) missing interrupt handler for normal operation
1543 * 2) delayed start of request where start_IO failed with -EBUSY
1544 * 3) timeout for missing state change interrupts
1545 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1546 * DASD_CQR_QUEUED for 2) and 3).
1548 static void dasd_device_timeout(struct timer_list
*t
)
1550 unsigned long flags
;
1551 struct dasd_device
*device
;
1553 device
= from_timer(device
, t
, timer
);
1554 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1555 /* re-activate request queue */
1556 dasd_device_remove_stop_bits(device
, DASD_STOPPED_PENDING
);
1557 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1558 dasd_schedule_device_bh(device
);
1562 * Setup timeout for a device in jiffies.
1564 void dasd_device_set_timer(struct dasd_device
*device
, int expires
)
1567 del_timer(&device
->timer
);
1569 mod_timer(&device
->timer
, jiffies
+ expires
);
1571 EXPORT_SYMBOL(dasd_device_set_timer
);
1574 * Clear timeout for a device.
1576 void dasd_device_clear_timer(struct dasd_device
*device
)
1578 del_timer(&device
->timer
);
1580 EXPORT_SYMBOL(dasd_device_clear_timer
);
1582 static void dasd_handle_killed_request(struct ccw_device
*cdev
,
1583 unsigned long intparm
)
1585 struct dasd_ccw_req
*cqr
;
1586 struct dasd_device
*device
;
1590 cqr
= (struct dasd_ccw_req
*) intparm
;
1591 if (cqr
->status
!= DASD_CQR_IN_IO
) {
1592 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
,
1593 "invalid status in handle_killed_request: "
1594 "%02x", cqr
->status
);
1598 device
= dasd_device_from_cdev_locked(cdev
);
1599 if (IS_ERR(device
)) {
1600 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1601 "unable to get device from cdev");
1605 if (!cqr
->startdev
||
1606 device
!= cqr
->startdev
||
1607 strncmp(cqr
->startdev
->discipline
->ebcname
,
1608 (char *) &cqr
->magic
, 4)) {
1609 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1610 "invalid device in request");
1611 dasd_put_device(device
);
1615 /* Schedule request to be retried. */
1616 cqr
->status
= DASD_CQR_QUEUED
;
1618 dasd_device_clear_timer(device
);
1619 dasd_schedule_device_bh(device
);
1620 dasd_put_device(device
);
1623 void dasd_generic_handle_state_change(struct dasd_device
*device
)
1625 /* First of all start sense subsystem status request. */
1626 dasd_eer_snss(device
);
1628 dasd_device_remove_stop_bits(device
, DASD_STOPPED_PENDING
);
1629 dasd_schedule_device_bh(device
);
1630 if (device
->block
) {
1631 dasd_schedule_block_bh(device
->block
);
1632 if (device
->block
->request_queue
)
1633 blk_mq_run_hw_queues(device
->block
->request_queue
,
1637 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change
);
1639 static int dasd_check_hpf_error(struct irb
*irb
)
1641 return (scsw_tm_is_valid_schxs(&irb
->scsw
) &&
1642 (irb
->scsw
.tm
.sesq
== SCSW_SESQ_DEV_NOFCX
||
1643 irb
->scsw
.tm
.sesq
== SCSW_SESQ_PATH_NOFCX
));
1647 * Interrupt handler for "normal" ssch-io based dasd devices.
1649 void dasd_int_handler(struct ccw_device
*cdev
, unsigned long intparm
,
1652 struct dasd_ccw_req
*cqr
, *next
;
1653 struct dasd_device
*device
;
1655 int nrf_suppressed
= 0;
1656 int fp_suppressed
= 0;
1660 cqr
= (struct dasd_ccw_req
*) intparm
;
1662 switch (PTR_ERR(irb
)) {
1664 if (cqr
&& cqr
->status
== DASD_CQR_CLEAR_PENDING
) {
1665 device
= cqr
->startdev
;
1666 cqr
->status
= DASD_CQR_CLEARED
;
1667 dasd_device_clear_timer(device
);
1668 wake_up(&dasd_flush_wq
);
1669 dasd_schedule_device_bh(device
);
1674 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s: "
1675 "request timed out\n", __func__
);
1678 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s: "
1679 "unknown error %ld\n", __func__
,
1682 dasd_handle_killed_request(cdev
, intparm
);
1686 now
= get_tod_clock();
1687 /* check for conditions that should be handled immediately */
1689 !(scsw_dstat(&irb
->scsw
) == (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
) &&
1690 scsw_cstat(&irb
->scsw
) == 0)) {
1692 memcpy(&cqr
->irb
, irb
, sizeof(*irb
));
1693 device
= dasd_device_from_cdev_locked(cdev
);
1696 /* ignore unsolicited interrupts for DIAG discipline */
1697 if (device
->discipline
== dasd_diag_discipline_pointer
) {
1698 dasd_put_device(device
);
1703 * In some cases 'File Protected' or 'No Record Found' errors
1704 * might be expected and debug log messages for the
1705 * corresponding interrupts shouldn't be written then.
1706 * Check if either of the according suppress bits is set.
1708 sense
= dasd_get_sense(irb
);
1710 fp_suppressed
= (sense
[1] & SNS1_FILE_PROTECTED
) &&
1711 test_bit(DASD_CQR_SUPPRESS_FP
, &cqr
->flags
);
1712 nrf_suppressed
= (sense
[1] & SNS1_NO_REC_FOUND
) &&
1713 test_bit(DASD_CQR_SUPPRESS_NRF
, &cqr
->flags
);
1715 if (!(fp_suppressed
|| nrf_suppressed
))
1716 device
->discipline
->dump_sense_dbf(device
, irb
, "int");
1718 if (device
->features
& DASD_FEATURE_ERPLOG
)
1719 device
->discipline
->dump_sense(device
, cqr
, irb
);
1720 device
->discipline
->check_for_device_change(device
, cqr
, irb
);
1721 dasd_put_device(device
);
1724 /* check for for attention message */
1725 if (scsw_dstat(&irb
->scsw
) & DEV_STAT_ATTENTION
) {
1726 device
= dasd_device_from_cdev_locked(cdev
);
1727 if (!IS_ERR(device
)) {
1728 device
->discipline
->check_attention(device
,
1729 irb
->esw
.esw1
.lpum
);
1730 dasd_put_device(device
);
1737 device
= (struct dasd_device
*) cqr
->startdev
;
1739 strncmp(device
->discipline
->ebcname
, (char *) &cqr
->magic
, 4)) {
1740 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1741 "invalid device in request");
1745 /* Check for clear pending */
1746 if (cqr
->status
== DASD_CQR_CLEAR_PENDING
&&
1747 scsw_fctl(&irb
->scsw
) & SCSW_FCTL_CLEAR_FUNC
) {
1748 cqr
->status
= DASD_CQR_CLEARED
;
1749 dasd_device_clear_timer(device
);
1750 wake_up(&dasd_flush_wq
);
1751 dasd_schedule_device_bh(device
);
1755 /* check status - the request might have been killed by dyn detach */
1756 if (cqr
->status
!= DASD_CQR_IN_IO
) {
1757 DBF_DEV_EVENT(DBF_DEBUG
, device
, "invalid status: bus_id %s, "
1758 "status %02x", dev_name(&cdev
->dev
), cqr
->status
);
1764 if (scsw_dstat(&irb
->scsw
) == (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
) &&
1765 scsw_cstat(&irb
->scsw
) == 0) {
1766 /* request was completed successfully */
1767 cqr
->status
= DASD_CQR_SUCCESS
;
1769 /* Start first request on queue if possible -> fast_io. */
1770 if (cqr
->devlist
.next
!= &device
->ccw_queue
) {
1771 next
= list_entry(cqr
->devlist
.next
,
1772 struct dasd_ccw_req
, devlist
);
1774 } else { /* error */
1775 /* check for HPF error
1776 * call discipline function to requeue all requests
1777 * and disable HPF accordingly
1779 if (cqr
->cpmode
&& dasd_check_hpf_error(irb
) &&
1780 device
->discipline
->handle_hpf_error
)
1781 device
->discipline
->handle_hpf_error(device
, irb
);
1783 * If we don't want complex ERP for this request, then just
1784 * reset this and retry it in the fastpath
1786 if (!test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
) &&
1788 if (cqr
->lpm
== dasd_path_get_opm(device
))
1789 DBF_DEV_EVENT(DBF_DEBUG
, device
,
1790 "default ERP in fastpath "
1791 "(%i retries left)",
1793 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
))
1794 cqr
->lpm
= dasd_path_get_opm(device
);
1795 cqr
->status
= DASD_CQR_QUEUED
;
1798 cqr
->status
= DASD_CQR_ERROR
;
1800 if (next
&& (next
->status
== DASD_CQR_QUEUED
) &&
1801 (!device
->stopped
)) {
1802 if (device
->discipline
->start_IO(next
) == 0)
1803 expires
= next
->expires
;
1806 dasd_device_set_timer(device
, expires
);
1808 dasd_device_clear_timer(device
);
1809 dasd_schedule_device_bh(device
);
1811 EXPORT_SYMBOL(dasd_int_handler
);
1813 enum uc_todo
dasd_generic_uc_handler(struct ccw_device
*cdev
, struct irb
*irb
)
1815 struct dasd_device
*device
;
1817 device
= dasd_device_from_cdev_locked(cdev
);
1821 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
1822 device
->state
!= device
->target
||
1823 !device
->discipline
->check_for_device_change
){
1824 dasd_put_device(device
);
1827 if (device
->discipline
->dump_sense_dbf
)
1828 device
->discipline
->dump_sense_dbf(device
, irb
, "uc");
1829 device
->discipline
->check_for_device_change(device
, NULL
, irb
);
1830 dasd_put_device(device
);
1832 return UC_TODO_RETRY
;
1834 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler
);
1837 * If we have an error on a dasd_block layer request then we cancel
1838 * and return all further requests from the same dasd_block as well.
1840 static void __dasd_device_recovery(struct dasd_device
*device
,
1841 struct dasd_ccw_req
*ref_cqr
)
1843 struct list_head
*l
, *n
;
1844 struct dasd_ccw_req
*cqr
;
1847 * only requeue request that came from the dasd_block layer
1849 if (!ref_cqr
->block
)
1852 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1853 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1854 if (cqr
->status
== DASD_CQR_QUEUED
&&
1855 ref_cqr
->block
== cqr
->block
) {
1856 cqr
->status
= DASD_CQR_CLEARED
;
1862 * Remove those ccw requests from the queue that need to be returned
1863 * to the upper layer.
1865 static void __dasd_device_process_ccw_queue(struct dasd_device
*device
,
1866 struct list_head
*final_queue
)
1868 struct list_head
*l
, *n
;
1869 struct dasd_ccw_req
*cqr
;
1871 /* Process request with final status. */
1872 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1873 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1875 /* Skip any non-final request. */
1876 if (cqr
->status
== DASD_CQR_QUEUED
||
1877 cqr
->status
== DASD_CQR_IN_IO
||
1878 cqr
->status
== DASD_CQR_CLEAR_PENDING
)
1880 if (cqr
->status
== DASD_CQR_ERROR
) {
1881 __dasd_device_recovery(device
, cqr
);
1883 /* Rechain finished requests to final queue */
1884 list_move_tail(&cqr
->devlist
, final_queue
);
1889 * the cqrs from the final queue are returned to the upper layer
1890 * by setting a dasd_block state and calling the callback function
1892 static void __dasd_device_process_final_queue(struct dasd_device
*device
,
1893 struct list_head
*final_queue
)
1895 struct list_head
*l
, *n
;
1896 struct dasd_ccw_req
*cqr
;
1897 struct dasd_block
*block
;
1898 void (*callback
)(struct dasd_ccw_req
*, void *data
);
1899 void *callback_data
;
1900 char errorstring
[ERRORLENGTH
];
1902 list_for_each_safe(l
, n
, final_queue
) {
1903 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1904 list_del_init(&cqr
->devlist
);
1906 callback
= cqr
->callback
;
1907 callback_data
= cqr
->callback_data
;
1909 spin_lock_bh(&block
->queue_lock
);
1910 switch (cqr
->status
) {
1911 case DASD_CQR_SUCCESS
:
1912 cqr
->status
= DASD_CQR_DONE
;
1914 case DASD_CQR_ERROR
:
1915 cqr
->status
= DASD_CQR_NEED_ERP
;
1917 case DASD_CQR_CLEARED
:
1918 cqr
->status
= DASD_CQR_TERMINATED
;
1921 /* internal error 12 - wrong cqr status*/
1922 snprintf(errorstring
, ERRORLENGTH
, "12 %p %x02", cqr
, cqr
->status
);
1923 dev_err(&device
->cdev
->dev
,
1924 "An error occurred in the DASD device driver, "
1925 "reason=%s\n", errorstring
);
1928 if (cqr
->callback
!= NULL
)
1929 (callback
)(cqr
, callback_data
);
1931 spin_unlock_bh(&block
->queue_lock
);
1936 * Take a look at the first request on the ccw queue and check
1937 * if it reached its expire time. If so, terminate the IO.
1939 static void __dasd_device_check_expire(struct dasd_device
*device
)
1941 struct dasd_ccw_req
*cqr
;
1943 if (list_empty(&device
->ccw_queue
))
1945 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
1946 if ((cqr
->status
== DASD_CQR_IN_IO
&& cqr
->expires
!= 0) &&
1947 (time_after_eq(jiffies
, cqr
->expires
+ cqr
->starttime
))) {
1948 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
1950 * IO in safe offline processing should not
1951 * run out of retries
1955 if (device
->discipline
->term_IO(cqr
) != 0) {
1956 /* Hmpf, try again in 5 sec */
1957 dev_err(&device
->cdev
->dev
,
1958 "cqr %p timed out (%lus) but cannot be "
1959 "ended, retrying in 5 s\n",
1960 cqr
, (cqr
->expires
/HZ
));
1961 cqr
->expires
+= 5*HZ
;
1962 dasd_device_set_timer(device
, 5*HZ
);
1964 dev_err(&device
->cdev
->dev
,
1965 "cqr %p timed out (%lus), %i retries "
1966 "remaining\n", cqr
, (cqr
->expires
/HZ
),
1973 * return 1 when device is not eligible for IO
1975 static int __dasd_device_is_unusable(struct dasd_device
*device
,
1976 struct dasd_ccw_req
*cqr
)
1978 int mask
= ~(DASD_STOPPED_DC_WAIT
| DASD_UNRESUMED_PM
);
1980 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
1981 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
1983 * dasd is being set offline
1984 * but it is no safe offline where we have to allow I/O
1988 if (device
->stopped
) {
1989 if (device
->stopped
& mask
) {
1990 /* stopped and CQR will not change that. */
1993 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1994 /* CQR is not able to change device to
1998 /* CQR required to get device operational. */
2004 * Take a look at the first request on the ccw queue and check
2005 * if it needs to be started.
2007 static void __dasd_device_start_head(struct dasd_device
*device
)
2009 struct dasd_ccw_req
*cqr
;
2012 if (list_empty(&device
->ccw_queue
))
2014 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
2015 if (cqr
->status
!= DASD_CQR_QUEUED
)
2017 /* if device is not usable return request to upper layer */
2018 if (__dasd_device_is_unusable(device
, cqr
)) {
2019 cqr
->intrc
= -EAGAIN
;
2020 cqr
->status
= DASD_CQR_CLEARED
;
2021 dasd_schedule_device_bh(device
);
2025 rc
= device
->discipline
->start_IO(cqr
);
2027 dasd_device_set_timer(device
, cqr
->expires
);
2028 else if (rc
== -EACCES
) {
2029 dasd_schedule_device_bh(device
);
2031 /* Hmpf, try again in 1/2 sec */
2032 dasd_device_set_timer(device
, 50);
2035 static void __dasd_device_check_path_events(struct dasd_device
*device
)
2039 if (!dasd_path_get_tbvpm(device
))
2042 if (device
->stopped
&
2043 ~(DASD_STOPPED_DC_WAIT
| DASD_UNRESUMED_PM
))
2045 rc
= device
->discipline
->verify_path(device
,
2046 dasd_path_get_tbvpm(device
));
2048 dasd_device_set_timer(device
, 50);
2050 dasd_path_clear_all_verify(device
);
2054 * Go through all request on the dasd_device request queue,
2055 * terminate them on the cdev if necessary, and return them to the
2056 * submitting layer via callback.
2058 * Make sure that all 'submitting layers' still exist when
2059 * this function is called!. In other words, when 'device' is a base
2060 * device then all block layer requests must have been removed before
2061 * via dasd_flush_block_queue.
2063 int dasd_flush_device_queue(struct dasd_device
*device
)
2065 struct dasd_ccw_req
*cqr
, *n
;
2067 struct list_head flush_queue
;
2069 INIT_LIST_HEAD(&flush_queue
);
2070 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2072 list_for_each_entry_safe(cqr
, n
, &device
->ccw_queue
, devlist
) {
2073 /* Check status and move request to flush_queue */
2074 switch (cqr
->status
) {
2075 case DASD_CQR_IN_IO
:
2076 rc
= device
->discipline
->term_IO(cqr
);
2078 /* unable to terminate requeust */
2079 dev_err(&device
->cdev
->dev
,
2080 "Flushing the DASD request queue "
2081 "failed for request %p\n", cqr
);
2082 /* stop flush processing */
2086 case DASD_CQR_QUEUED
:
2087 cqr
->stopclk
= get_tod_clock();
2088 cqr
->status
= DASD_CQR_CLEARED
;
2090 default: /* no need to modify the others */
2093 list_move_tail(&cqr
->devlist
, &flush_queue
);
2096 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2098 * After this point all requests must be in state CLEAR_PENDING,
2099 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2100 * one of the others.
2102 list_for_each_entry_safe(cqr
, n
, &flush_queue
, devlist
)
2103 wait_event(dasd_flush_wq
,
2104 (cqr
->status
!= DASD_CQR_CLEAR_PENDING
));
2106 * Now set each request back to TERMINATED, DONE or NEED_ERP
2107 * and call the callback function of flushed requests
2109 __dasd_device_process_final_queue(device
, &flush_queue
);
2112 EXPORT_SYMBOL_GPL(dasd_flush_device_queue
);
2115 * Acquire the device lock and process queues for the device.
2117 static void dasd_device_tasklet(struct dasd_device
*device
)
2119 struct list_head final_queue
;
2121 atomic_set (&device
->tasklet_scheduled
, 0);
2122 INIT_LIST_HEAD(&final_queue
);
2123 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2124 /* Check expire time of first request on the ccw queue. */
2125 __dasd_device_check_expire(device
);
2126 /* find final requests on ccw queue */
2127 __dasd_device_process_ccw_queue(device
, &final_queue
);
2128 __dasd_device_check_path_events(device
);
2129 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2130 /* Now call the callback function of requests with final status */
2131 __dasd_device_process_final_queue(device
, &final_queue
);
2132 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2133 /* Now check if the head of the ccw queue needs to be started. */
2134 __dasd_device_start_head(device
);
2135 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2136 if (waitqueue_active(&shutdown_waitq
))
2137 wake_up(&shutdown_waitq
);
2138 dasd_put_device(device
);
2142 * Schedules a call to dasd_tasklet over the device tasklet.
2144 void dasd_schedule_device_bh(struct dasd_device
*device
)
2146 /* Protect against rescheduling. */
2147 if (atomic_cmpxchg (&device
->tasklet_scheduled
, 0, 1) != 0)
2149 dasd_get_device(device
);
2150 tasklet_hi_schedule(&device
->tasklet
);
2152 EXPORT_SYMBOL(dasd_schedule_device_bh
);
2154 void dasd_device_set_stop_bits(struct dasd_device
*device
, int bits
)
2156 device
->stopped
|= bits
;
2158 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits
);
2160 void dasd_device_remove_stop_bits(struct dasd_device
*device
, int bits
)
2162 device
->stopped
&= ~bits
;
2163 if (!device
->stopped
)
2164 wake_up(&generic_waitq
);
2166 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits
);
2169 * Queue a request to the head of the device ccw_queue.
2170 * Start the I/O if possible.
2172 void dasd_add_request_head(struct dasd_ccw_req
*cqr
)
2174 struct dasd_device
*device
;
2175 unsigned long flags
;
2177 device
= cqr
->startdev
;
2178 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2179 cqr
->status
= DASD_CQR_QUEUED
;
2180 list_add(&cqr
->devlist
, &device
->ccw_queue
);
2181 /* let the bh start the request to keep them in order */
2182 dasd_schedule_device_bh(device
);
2183 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2185 EXPORT_SYMBOL(dasd_add_request_head
);
2188 * Queue a request to the tail of the device ccw_queue.
2189 * Start the I/O if possible.
2191 void dasd_add_request_tail(struct dasd_ccw_req
*cqr
)
2193 struct dasd_device
*device
;
2194 unsigned long flags
;
2196 device
= cqr
->startdev
;
2197 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2198 cqr
->status
= DASD_CQR_QUEUED
;
2199 list_add_tail(&cqr
->devlist
, &device
->ccw_queue
);
2200 /* let the bh start the request to keep them in order */
2201 dasd_schedule_device_bh(device
);
2202 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2204 EXPORT_SYMBOL(dasd_add_request_tail
);
2207 * Wakeup helper for the 'sleep_on' functions.
2209 void dasd_wakeup_cb(struct dasd_ccw_req
*cqr
, void *data
)
2211 spin_lock_irq(get_ccwdev_lock(cqr
->startdev
->cdev
));
2212 cqr
->callback_data
= DASD_SLEEPON_END_TAG
;
2213 spin_unlock_irq(get_ccwdev_lock(cqr
->startdev
->cdev
));
2214 wake_up(&generic_waitq
);
2216 EXPORT_SYMBOL_GPL(dasd_wakeup_cb
);
2218 static inline int _wait_for_wakeup(struct dasd_ccw_req
*cqr
)
2220 struct dasd_device
*device
;
2223 device
= cqr
->startdev
;
2224 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2225 rc
= (cqr
->callback_data
== DASD_SLEEPON_END_TAG
);
2226 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2231 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2233 static int __dasd_sleep_on_erp(struct dasd_ccw_req
*cqr
)
2235 struct dasd_device
*device
;
2236 dasd_erp_fn_t erp_fn
;
2238 if (cqr
->status
== DASD_CQR_FILLED
)
2240 device
= cqr
->startdev
;
2241 if (test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
)) {
2242 if (cqr
->status
== DASD_CQR_TERMINATED
) {
2243 device
->discipline
->handle_terminated_request(cqr
);
2246 if (cqr
->status
== DASD_CQR_NEED_ERP
) {
2247 erp_fn
= device
->discipline
->erp_action(cqr
);
2251 if (cqr
->status
== DASD_CQR_FAILED
)
2252 dasd_log_sense(cqr
, &cqr
->irb
);
2254 __dasd_process_erp(device
, cqr
);
2261 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req
*cqr
)
2263 if (test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
)) {
2264 if (cqr
->refers
) /* erp is not done yet */
2266 return ((cqr
->status
!= DASD_CQR_DONE
) &&
2267 (cqr
->status
!= DASD_CQR_FAILED
));
2269 return (cqr
->status
== DASD_CQR_FILLED
);
2272 static int _dasd_sleep_on(struct dasd_ccw_req
*maincqr
, int interruptible
)
2274 struct dasd_device
*device
;
2276 struct list_head ccw_queue
;
2277 struct dasd_ccw_req
*cqr
;
2279 INIT_LIST_HEAD(&ccw_queue
);
2280 maincqr
->status
= DASD_CQR_FILLED
;
2281 device
= maincqr
->startdev
;
2282 list_add(&maincqr
->blocklist
, &ccw_queue
);
2283 for (cqr
= maincqr
; __dasd_sleep_on_loop_condition(cqr
);
2284 cqr
= list_first_entry(&ccw_queue
,
2285 struct dasd_ccw_req
, blocklist
)) {
2287 if (__dasd_sleep_on_erp(cqr
))
2289 if (cqr
->status
!= DASD_CQR_FILLED
) /* could be failed */
2291 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2292 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2293 cqr
->status
= DASD_CQR_FAILED
;
2294 cqr
->intrc
= -EPERM
;
2297 /* Non-temporary stop condition will trigger fail fast */
2298 if (device
->stopped
& ~DASD_STOPPED_PENDING
&&
2299 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2300 (!dasd_eer_enabled(device
))) {
2301 cqr
->status
= DASD_CQR_FAILED
;
2302 cqr
->intrc
= -ENOLINK
;
2306 * Don't try to start requests if device is in
2307 * offline processing, it might wait forever
2309 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
2310 cqr
->status
= DASD_CQR_FAILED
;
2311 cqr
->intrc
= -ENODEV
;
2315 * Don't try to start requests if device is stopped
2316 * except path verification requests
2318 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
2319 if (interruptible
) {
2320 rc
= wait_event_interruptible(
2321 generic_waitq
, !(device
->stopped
));
2322 if (rc
== -ERESTARTSYS
) {
2323 cqr
->status
= DASD_CQR_FAILED
;
2324 maincqr
->intrc
= rc
;
2328 wait_event(generic_waitq
, !(device
->stopped
));
2331 cqr
->callback
= dasd_wakeup_cb
;
2333 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2334 dasd_add_request_tail(cqr
);
2335 if (interruptible
) {
2336 rc
= wait_event_interruptible(
2337 generic_waitq
, _wait_for_wakeup(cqr
));
2338 if (rc
== -ERESTARTSYS
) {
2339 dasd_cancel_req(cqr
);
2340 /* wait (non-interruptible) for final status */
2341 wait_event(generic_waitq
,
2342 _wait_for_wakeup(cqr
));
2343 cqr
->status
= DASD_CQR_FAILED
;
2344 maincqr
->intrc
= rc
;
2348 wait_event(generic_waitq
, _wait_for_wakeup(cqr
));
2351 maincqr
->endclk
= get_tod_clock();
2352 if ((maincqr
->status
!= DASD_CQR_DONE
) &&
2353 (maincqr
->intrc
!= -ERESTARTSYS
))
2354 dasd_log_sense(maincqr
, &maincqr
->irb
);
2355 if (maincqr
->status
== DASD_CQR_DONE
)
2357 else if (maincqr
->intrc
)
2358 rc
= maincqr
->intrc
;
2364 static inline int _wait_for_wakeup_queue(struct list_head
*ccw_queue
)
2366 struct dasd_ccw_req
*cqr
;
2368 list_for_each_entry(cqr
, ccw_queue
, blocklist
) {
2369 if (cqr
->callback_data
!= DASD_SLEEPON_END_TAG
)
2376 static int _dasd_sleep_on_queue(struct list_head
*ccw_queue
, int interruptible
)
2378 struct dasd_device
*device
;
2379 struct dasd_ccw_req
*cqr
, *n
;
2384 list_for_each_entry_safe(cqr
, n
, ccw_queue
, blocklist
) {
2385 device
= cqr
->startdev
;
2386 if (cqr
->status
!= DASD_CQR_FILLED
) /*could be failed*/
2389 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2390 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2391 cqr
->status
= DASD_CQR_FAILED
;
2392 cqr
->intrc
= -EPERM
;
2395 /*Non-temporary stop condition will trigger fail fast*/
2396 if (device
->stopped
& ~DASD_STOPPED_PENDING
&&
2397 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2398 !dasd_eer_enabled(device
)) {
2399 cqr
->status
= DASD_CQR_FAILED
;
2400 cqr
->intrc
= -EAGAIN
;
2404 /*Don't try to start requests if device is stopped*/
2405 if (interruptible
) {
2406 rc
= wait_event_interruptible(
2407 generic_waitq
, !device
->stopped
);
2408 if (rc
== -ERESTARTSYS
) {
2409 cqr
->status
= DASD_CQR_FAILED
;
2414 wait_event(generic_waitq
, !(device
->stopped
));
2417 cqr
->callback
= dasd_wakeup_cb
;
2418 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2419 dasd_add_request_tail(cqr
);
2422 wait_event(generic_waitq
, _wait_for_wakeup_queue(ccw_queue
));
2425 list_for_each_entry_safe(cqr
, n
, ccw_queue
, blocklist
) {
2427 * In some cases the 'File Protected' or 'Incorrect Length'
2428 * error might be expected and error recovery would be
2429 * unnecessary in these cases. Check if the according suppress
2432 sense
= dasd_get_sense(&cqr
->irb
);
2433 if (sense
&& sense
[1] & SNS1_FILE_PROTECTED
&&
2434 test_bit(DASD_CQR_SUPPRESS_FP
, &cqr
->flags
))
2436 if (scsw_cstat(&cqr
->irb
.scsw
) == 0x40 &&
2437 test_bit(DASD_CQR_SUPPRESS_IL
, &cqr
->flags
))
2441 * for alias devices simplify error recovery and
2442 * return to upper layer
2443 * do not skip ERP requests
2445 if (cqr
->startdev
!= cqr
->basedev
&& !cqr
->refers
&&
2446 (cqr
->status
== DASD_CQR_TERMINATED
||
2447 cqr
->status
== DASD_CQR_NEED_ERP
))
2450 /* normal recovery for basedev IO */
2451 if (__dasd_sleep_on_erp(cqr
))
2452 /* handle erp first */
2460 * Queue a request to the tail of the device ccw_queue and wait for
2463 int dasd_sleep_on(struct dasd_ccw_req
*cqr
)
2465 return _dasd_sleep_on(cqr
, 0);
2467 EXPORT_SYMBOL(dasd_sleep_on
);
2470 * Start requests from a ccw_queue and wait for their completion.
2472 int dasd_sleep_on_queue(struct list_head
*ccw_queue
)
2474 return _dasd_sleep_on_queue(ccw_queue
, 0);
2476 EXPORT_SYMBOL(dasd_sleep_on_queue
);
2479 * Queue a request to the tail of the device ccw_queue and wait
2480 * interruptible for it's completion.
2482 int dasd_sleep_on_interruptible(struct dasd_ccw_req
*cqr
)
2484 return _dasd_sleep_on(cqr
, 1);
2486 EXPORT_SYMBOL(dasd_sleep_on_interruptible
);
2489 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2490 * for eckd devices) the currently running request has to be terminated
2491 * and be put back to status queued, before the special request is added
2492 * to the head of the queue. Then the special request is waited on normally.
2494 static inline int _dasd_term_running_cqr(struct dasd_device
*device
)
2496 struct dasd_ccw_req
*cqr
;
2499 if (list_empty(&device
->ccw_queue
))
2501 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
2502 rc
= device
->discipline
->term_IO(cqr
);
2505 * CQR terminated because a more important request is pending.
2506 * Undo decreasing of retry counter because this is
2507 * not an error case.
2513 int dasd_sleep_on_immediatly(struct dasd_ccw_req
*cqr
)
2515 struct dasd_device
*device
;
2518 device
= cqr
->startdev
;
2519 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2520 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2521 cqr
->status
= DASD_CQR_FAILED
;
2522 cqr
->intrc
= -EPERM
;
2525 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2526 rc
= _dasd_term_running_cqr(device
);
2528 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2531 cqr
->callback
= dasd_wakeup_cb
;
2532 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2533 cqr
->status
= DASD_CQR_QUEUED
;
2535 * add new request as second
2536 * first the terminated cqr needs to be finished
2538 list_add(&cqr
->devlist
, device
->ccw_queue
.next
);
2540 /* let the bh start the request to keep them in order */
2541 dasd_schedule_device_bh(device
);
2543 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2545 wait_event(generic_waitq
, _wait_for_wakeup(cqr
));
2547 if (cqr
->status
== DASD_CQR_DONE
)
2549 else if (cqr
->intrc
)
2555 dasd_schedule_device_bh(device
);
2557 dasd_schedule_block_bh(device
->block
);
2561 EXPORT_SYMBOL(dasd_sleep_on_immediatly
);
2564 * Cancels a request that was started with dasd_sleep_on_req.
2565 * This is useful to timeout requests. The request will be
2566 * terminated if it is currently in i/o.
2567 * Returns 0 if request termination was successful
2568 * negative error code if termination failed
2569 * Cancellation of a request is an asynchronous operation! The calling
2570 * function has to wait until the request is properly returned via callback.
2572 int dasd_cancel_req(struct dasd_ccw_req
*cqr
)
2574 struct dasd_device
*device
= cqr
->startdev
;
2575 unsigned long flags
;
2579 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2580 switch (cqr
->status
) {
2581 case DASD_CQR_QUEUED
:
2582 /* request was not started - just set to cleared */
2583 cqr
->status
= DASD_CQR_CLEARED
;
2585 case DASD_CQR_IN_IO
:
2586 /* request in IO - terminate IO and release again */
2587 rc
= device
->discipline
->term_IO(cqr
);
2589 dev_err(&device
->cdev
->dev
,
2590 "Cancelling request %p failed with rc=%d\n",
2593 cqr
->stopclk
= get_tod_clock();
2596 default: /* already finished or clear pending - do nothing */
2599 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2600 dasd_schedule_device_bh(device
);
2603 EXPORT_SYMBOL(dasd_cancel_req
);
2606 * SECTION: Operations of the dasd_block layer.
2610 * Timeout function for dasd_block. This is used when the block layer
2611 * is waiting for something that may not come reliably, (e.g. a state
2614 static void dasd_block_timeout(struct timer_list
*t
)
2616 unsigned long flags
;
2617 struct dasd_block
*block
;
2619 block
= from_timer(block
, t
, timer
);
2620 spin_lock_irqsave(get_ccwdev_lock(block
->base
->cdev
), flags
);
2621 /* re-activate request queue */
2622 dasd_device_remove_stop_bits(block
->base
, DASD_STOPPED_PENDING
);
2623 spin_unlock_irqrestore(get_ccwdev_lock(block
->base
->cdev
), flags
);
2624 dasd_schedule_block_bh(block
);
2625 blk_mq_run_hw_queues(block
->request_queue
, true);
2629 * Setup timeout for a dasd_block in jiffies.
2631 void dasd_block_set_timer(struct dasd_block
*block
, int expires
)
2634 del_timer(&block
->timer
);
2636 mod_timer(&block
->timer
, jiffies
+ expires
);
2638 EXPORT_SYMBOL(dasd_block_set_timer
);
2641 * Clear timeout for a dasd_block.
2643 void dasd_block_clear_timer(struct dasd_block
*block
)
2645 del_timer(&block
->timer
);
2647 EXPORT_SYMBOL(dasd_block_clear_timer
);
2650 * Process finished error recovery ccw.
2652 static void __dasd_process_erp(struct dasd_device
*device
,
2653 struct dasd_ccw_req
*cqr
)
2655 dasd_erp_fn_t erp_fn
;
2657 if (cqr
->status
== DASD_CQR_DONE
)
2658 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s", "ERP successful");
2660 dev_err(&device
->cdev
->dev
, "ERP failed for the DASD\n");
2661 erp_fn
= device
->discipline
->erp_postaction(cqr
);
2665 static void __dasd_cleanup_cqr(struct dasd_ccw_req
*cqr
)
2667 struct request
*req
;
2668 blk_status_t error
= BLK_STS_OK
;
2671 req
= (struct request
*) cqr
->callback_data
;
2672 dasd_profile_end(cqr
->block
, cqr
, req
);
2674 status
= cqr
->block
->base
->discipline
->free_cp(cqr
, req
);
2676 error
= errno_to_blk_status(status
);
2677 else if (status
== 0) {
2678 switch (cqr
->intrc
) {
2680 error
= BLK_STS_NEXUS
;
2683 error
= BLK_STS_TRANSPORT
;
2686 error
= BLK_STS_TIMEOUT
;
2689 error
= BLK_STS_IOERR
;
2695 * We need to take care for ETIMEDOUT errors here since the
2696 * complete callback does not get called in this case.
2697 * Take care of all errors here and avoid additional code to
2698 * transfer the error value to the complete callback.
2701 blk_mq_end_request(req
, error
);
2702 blk_mq_run_hw_queues(req
->q
, true);
2704 blk_mq_complete_request(req
);
2709 * Process ccw request queue.
2711 static void __dasd_process_block_ccw_queue(struct dasd_block
*block
,
2712 struct list_head
*final_queue
)
2714 struct list_head
*l
, *n
;
2715 struct dasd_ccw_req
*cqr
;
2716 dasd_erp_fn_t erp_fn
;
2717 unsigned long flags
;
2718 struct dasd_device
*base
= block
->base
;
2721 /* Process request with final status. */
2722 list_for_each_safe(l
, n
, &block
->ccw_queue
) {
2723 cqr
= list_entry(l
, struct dasd_ccw_req
, blocklist
);
2724 if (cqr
->status
!= DASD_CQR_DONE
&&
2725 cqr
->status
!= DASD_CQR_FAILED
&&
2726 cqr
->status
!= DASD_CQR_NEED_ERP
&&
2727 cqr
->status
!= DASD_CQR_TERMINATED
)
2730 if (cqr
->status
== DASD_CQR_TERMINATED
) {
2731 base
->discipline
->handle_terminated_request(cqr
);
2735 /* Process requests that may be recovered */
2736 if (cqr
->status
== DASD_CQR_NEED_ERP
) {
2737 erp_fn
= base
->discipline
->erp_action(cqr
);
2738 if (IS_ERR(erp_fn(cqr
)))
2743 /* log sense for fatal error */
2744 if (cqr
->status
== DASD_CQR_FAILED
) {
2745 dasd_log_sense(cqr
, &cqr
->irb
);
2748 /* First of all call extended error reporting. */
2749 if (dasd_eer_enabled(base
) &&
2750 cqr
->status
== DASD_CQR_FAILED
) {
2751 dasd_eer_write(base
, cqr
, DASD_EER_FATALERROR
);
2753 /* restart request */
2754 cqr
->status
= DASD_CQR_FILLED
;
2756 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
2757 dasd_device_set_stop_bits(base
, DASD_STOPPED_QUIESCE
);
2758 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
),
2763 /* Process finished ERP request. */
2765 __dasd_process_erp(base
, cqr
);
2769 /* Rechain finished requests to final queue */
2770 cqr
->endclk
= get_tod_clock();
2771 list_move_tail(&cqr
->blocklist
, final_queue
);
2775 static void dasd_return_cqr_cb(struct dasd_ccw_req
*cqr
, void *data
)
2777 dasd_schedule_block_bh(cqr
->block
);
2780 static void __dasd_block_start_head(struct dasd_block
*block
)
2782 struct dasd_ccw_req
*cqr
;
2784 if (list_empty(&block
->ccw_queue
))
2786 /* We allways begin with the first requests on the queue, as some
2787 * of previously started requests have to be enqueued on a
2788 * dasd_device again for error recovery.
2790 list_for_each_entry(cqr
, &block
->ccw_queue
, blocklist
) {
2791 if (cqr
->status
!= DASD_CQR_FILLED
)
2793 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &block
->base
->flags
) &&
2794 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2795 cqr
->status
= DASD_CQR_FAILED
;
2796 cqr
->intrc
= -EPERM
;
2797 dasd_schedule_block_bh(block
);
2800 /* Non-temporary stop condition will trigger fail fast */
2801 if (block
->base
->stopped
& ~DASD_STOPPED_PENDING
&&
2802 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2803 (!dasd_eer_enabled(block
->base
))) {
2804 cqr
->status
= DASD_CQR_FAILED
;
2805 cqr
->intrc
= -ENOLINK
;
2806 dasd_schedule_block_bh(block
);
2809 /* Don't try to start requests if device is stopped */
2810 if (block
->base
->stopped
)
2813 /* just a fail safe check, should not happen */
2815 cqr
->startdev
= block
->base
;
2817 /* make sure that the requests we submit find their way back */
2818 cqr
->callback
= dasd_return_cqr_cb
;
2820 dasd_add_request_tail(cqr
);
2825 * Central dasd_block layer routine. Takes requests from the generic
2826 * block layer request queue, creates ccw requests, enqueues them on
2827 * a dasd_device and processes ccw requests that have been returned.
2829 static void dasd_block_tasklet(struct dasd_block
*block
)
2831 struct list_head final_queue
;
2832 struct list_head
*l
, *n
;
2833 struct dasd_ccw_req
*cqr
;
2834 struct dasd_queue
*dq
;
2836 atomic_set(&block
->tasklet_scheduled
, 0);
2837 INIT_LIST_HEAD(&final_queue
);
2838 spin_lock_irq(&block
->queue_lock
);
2839 /* Finish off requests on ccw queue */
2840 __dasd_process_block_ccw_queue(block
, &final_queue
);
2841 spin_unlock_irq(&block
->queue_lock
);
2843 /* Now call the callback function of requests with final status */
2844 list_for_each_safe(l
, n
, &final_queue
) {
2845 cqr
= list_entry(l
, struct dasd_ccw_req
, blocklist
);
2847 spin_lock_irq(&dq
->lock
);
2848 list_del_init(&cqr
->blocklist
);
2849 __dasd_cleanup_cqr(cqr
);
2850 spin_unlock_irq(&dq
->lock
);
2853 spin_lock_irq(&block
->queue_lock
);
2854 /* Now check if the head of the ccw queue needs to be started. */
2855 __dasd_block_start_head(block
);
2856 spin_unlock_irq(&block
->queue_lock
);
2858 if (waitqueue_active(&shutdown_waitq
))
2859 wake_up(&shutdown_waitq
);
2860 dasd_put_device(block
->base
);
2863 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req
*cqr
, void *data
)
2865 wake_up(&dasd_flush_wq
);
2869 * Requeue a request back to the block request queue
2870 * only works for block requests
2872 static int _dasd_requeue_request(struct dasd_ccw_req
*cqr
)
2874 struct dasd_block
*block
= cqr
->block
;
2875 struct request
*req
;
2879 spin_lock_irq(&cqr
->dq
->lock
);
2880 req
= (struct request
*) cqr
->callback_data
;
2881 blk_mq_requeue_request(req
, false);
2882 spin_unlock_irq(&cqr
->dq
->lock
);
2888 * Go through all request on the dasd_block request queue, cancel them
2889 * on the respective dasd_device, and return them to the generic
2892 static int dasd_flush_block_queue(struct dasd_block
*block
)
2894 struct dasd_ccw_req
*cqr
, *n
;
2896 struct list_head flush_queue
;
2897 unsigned long flags
;
2899 INIT_LIST_HEAD(&flush_queue
);
2900 spin_lock_bh(&block
->queue_lock
);
2903 list_for_each_entry_safe(cqr
, n
, &block
->ccw_queue
, blocklist
) {
2904 /* if this request currently owned by a dasd_device cancel it */
2905 if (cqr
->status
>= DASD_CQR_QUEUED
)
2906 rc
= dasd_cancel_req(cqr
);
2909 /* Rechain request (including erp chain) so it won't be
2910 * touched by the dasd_block_tasklet anymore.
2911 * Replace the callback so we notice when the request
2912 * is returned from the dasd_device layer.
2914 cqr
->callback
= _dasd_wake_block_flush_cb
;
2915 for (i
= 0; cqr
!= NULL
; cqr
= cqr
->refers
, i
++)
2916 list_move_tail(&cqr
->blocklist
, &flush_queue
);
2918 /* moved more than one request - need to restart */
2921 spin_unlock_bh(&block
->queue_lock
);
2922 /* Now call the callback function of flushed requests */
2924 list_for_each_entry_safe(cqr
, n
, &flush_queue
, blocklist
) {
2925 wait_event(dasd_flush_wq
, (cqr
->status
< DASD_CQR_QUEUED
));
2926 /* Process finished ERP request. */
2928 spin_lock_bh(&block
->queue_lock
);
2929 __dasd_process_erp(block
->base
, cqr
);
2930 spin_unlock_bh(&block
->queue_lock
);
2931 /* restart list_for_xx loop since dasd_process_erp
2932 * might remove multiple elements */
2935 /* call the callback function */
2936 spin_lock_irqsave(&cqr
->dq
->lock
, flags
);
2937 cqr
->endclk
= get_tod_clock();
2938 list_del_init(&cqr
->blocklist
);
2939 __dasd_cleanup_cqr(cqr
);
2940 spin_unlock_irqrestore(&cqr
->dq
->lock
, flags
);
2946 * Schedules a call to dasd_tasklet over the device tasklet.
2948 void dasd_schedule_block_bh(struct dasd_block
*block
)
2950 /* Protect against rescheduling. */
2951 if (atomic_cmpxchg(&block
->tasklet_scheduled
, 0, 1) != 0)
2953 /* life cycle of block is bound to it's base device */
2954 dasd_get_device(block
->base
);
2955 tasklet_hi_schedule(&block
->tasklet
);
2957 EXPORT_SYMBOL(dasd_schedule_block_bh
);
2961 * SECTION: external block device operations
2962 * (request queue handling, open, release, etc.)
2966 * Dasd request queue function. Called from ll_rw_blk.c
2968 static blk_status_t
do_dasd_request(struct blk_mq_hw_ctx
*hctx
,
2969 const struct blk_mq_queue_data
*qd
)
2971 struct dasd_block
*block
= hctx
->queue
->queuedata
;
2972 struct dasd_queue
*dq
= hctx
->driver_data
;
2973 struct request
*req
= qd
->rq
;
2974 struct dasd_device
*basedev
;
2975 struct dasd_ccw_req
*cqr
;
2976 blk_status_t rc
= BLK_STS_OK
;
2978 basedev
= block
->base
;
2979 spin_lock_irq(&dq
->lock
);
2980 if (basedev
->state
< DASD_STATE_READY
) {
2981 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2982 "device not ready for request %p", req
);
2988 * if device is stopped do not fetch new requests
2989 * except failfast is active which will let requests fail
2990 * immediately in __dasd_block_start_head()
2992 if (basedev
->stopped
&& !(basedev
->features
& DASD_FEATURE_FAILFAST
)) {
2993 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2994 "device stopped request %p", req
);
2995 rc
= BLK_STS_RESOURCE
;
2999 if (basedev
->features
& DASD_FEATURE_READONLY
&&
3000 rq_data_dir(req
) == WRITE
) {
3001 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3002 "Rejecting write request %p", req
);
3007 if (test_bit(DASD_FLAG_ABORTALL
, &basedev
->flags
) &&
3008 (basedev
->features
& DASD_FEATURE_FAILFAST
||
3009 blk_noretry_request(req
))) {
3010 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3011 "Rejecting failfast request %p", req
);
3016 cqr
= basedev
->discipline
->build_cp(basedev
, block
, req
);
3018 if (PTR_ERR(cqr
) == -EBUSY
||
3019 PTR_ERR(cqr
) == -ENOMEM
||
3020 PTR_ERR(cqr
) == -EAGAIN
) {
3021 rc
= BLK_STS_RESOURCE
;
3024 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3025 "CCW creation failed (rc=%ld) on request %p",
3031 * Note: callback is set to dasd_return_cqr_cb in
3032 * __dasd_block_start_head to cover erp requests as well
3034 cqr
->callback_data
= req
;
3035 cqr
->status
= DASD_CQR_FILLED
;
3037 req
->completion_data
= cqr
;
3038 blk_mq_start_request(req
);
3039 spin_lock(&block
->queue_lock
);
3040 list_add_tail(&cqr
->blocklist
, &block
->ccw_queue
);
3041 INIT_LIST_HEAD(&cqr
->devlist
);
3042 dasd_profile_start(block
, cqr
, req
);
3043 dasd_schedule_block_bh(block
);
3044 spin_unlock(&block
->queue_lock
);
3047 spin_unlock_irq(&dq
->lock
);
3052 * Block timeout callback, called from the block layer
3055 * BLK_EH_RESET_TIMER if the request should be left running
3056 * BLK_EH_NOT_HANDLED if the request is handled or terminated
3059 enum blk_eh_timer_return
dasd_times_out(struct request
*req
, bool reserved
)
3061 struct dasd_ccw_req
*cqr
= req
->completion_data
;
3062 struct dasd_block
*block
= req
->q
->queuedata
;
3063 struct dasd_device
*device
;
3064 unsigned long flags
;
3068 return BLK_EH_NOT_HANDLED
;
3070 spin_lock_irqsave(&cqr
->dq
->lock
, flags
);
3071 device
= cqr
->startdev
? cqr
->startdev
: block
->base
;
3072 if (!device
->blk_timeout
) {
3073 spin_unlock_irqrestore(&cqr
->dq
->lock
, flags
);
3074 return BLK_EH_RESET_TIMER
;
3076 DBF_DEV_EVENT(DBF_WARNING
, device
,
3077 " dasd_times_out cqr %p status %x",
3080 spin_lock(&block
->queue_lock
);
3081 spin_lock(get_ccwdev_lock(device
->cdev
));
3083 cqr
->intrc
= -ETIMEDOUT
;
3084 if (cqr
->status
>= DASD_CQR_QUEUED
) {
3085 spin_unlock(get_ccwdev_lock(device
->cdev
));
3086 rc
= dasd_cancel_req(cqr
);
3087 } else if (cqr
->status
== DASD_CQR_FILLED
||
3088 cqr
->status
== DASD_CQR_NEED_ERP
) {
3089 cqr
->status
= DASD_CQR_TERMINATED
;
3090 spin_unlock(get_ccwdev_lock(device
->cdev
));
3091 } else if (cqr
->status
== DASD_CQR_IN_ERP
) {
3092 struct dasd_ccw_req
*searchcqr
, *nextcqr
, *tmpcqr
;
3094 list_for_each_entry_safe(searchcqr
, nextcqr
,
3095 &block
->ccw_queue
, blocklist
) {
3097 while (tmpcqr
->refers
)
3098 tmpcqr
= tmpcqr
->refers
;
3101 /* searchcqr is an ERP request for cqr */
3102 searchcqr
->retries
= -1;
3103 searchcqr
->intrc
= -ETIMEDOUT
;
3104 if (searchcqr
->status
>= DASD_CQR_QUEUED
) {
3105 spin_unlock(get_ccwdev_lock(device
->cdev
));
3106 rc
= dasd_cancel_req(searchcqr
);
3107 spin_lock(get_ccwdev_lock(device
->cdev
));
3108 } else if ((searchcqr
->status
== DASD_CQR_FILLED
) ||
3109 (searchcqr
->status
== DASD_CQR_NEED_ERP
)) {
3110 searchcqr
->status
= DASD_CQR_TERMINATED
;
3112 } else if (searchcqr
->status
== DASD_CQR_IN_ERP
) {
3114 * Shouldn't happen; most recent ERP
3115 * request is at the front of queue
3121 spin_unlock(get_ccwdev_lock(device
->cdev
));
3123 dasd_schedule_block_bh(block
);
3124 spin_unlock(&block
->queue_lock
);
3125 spin_unlock_irqrestore(&cqr
->dq
->lock
, flags
);
3127 return rc
? BLK_EH_RESET_TIMER
: BLK_EH_NOT_HANDLED
;
3130 static int dasd_init_hctx(struct blk_mq_hw_ctx
*hctx
, void *data
,
3133 struct dasd_queue
*dq
= kzalloc(sizeof(*dq
), GFP_KERNEL
);
3138 spin_lock_init(&dq
->lock
);
3139 hctx
->driver_data
= dq
;
3144 static void dasd_exit_hctx(struct blk_mq_hw_ctx
*hctx
, unsigned int idx
)
3146 kfree(hctx
->driver_data
);
3147 hctx
->driver_data
= NULL
;
3150 static void dasd_request_done(struct request
*req
)
3152 blk_mq_end_request(req
, 0);
3153 blk_mq_run_hw_queues(req
->q
, true);
3156 static struct blk_mq_ops dasd_mq_ops
= {
3157 .queue_rq
= do_dasd_request
,
3158 .complete
= dasd_request_done
,
3159 .timeout
= dasd_times_out
,
3160 .init_hctx
= dasd_init_hctx
,
3161 .exit_hctx
= dasd_exit_hctx
,
3165 * Allocate and initialize request queue and default I/O scheduler.
3167 static int dasd_alloc_queue(struct dasd_block
*block
)
3171 block
->tag_set
.ops
= &dasd_mq_ops
;
3172 block
->tag_set
.nr_hw_queues
= DASD_NR_HW_QUEUES
;
3173 block
->tag_set
.queue_depth
= DASD_MAX_LCU_DEV
* DASD_REQ_PER_DEV
;
3174 block
->tag_set
.flags
= BLK_MQ_F_SHOULD_MERGE
;
3176 rc
= blk_mq_alloc_tag_set(&block
->tag_set
);
3180 block
->request_queue
= blk_mq_init_queue(&block
->tag_set
);
3181 if (IS_ERR(block
->request_queue
))
3182 return PTR_ERR(block
->request_queue
);
3184 block
->request_queue
->queuedata
= block
;
3190 * Allocate and initialize request queue.
3192 static void dasd_setup_queue(struct dasd_block
*block
)
3194 unsigned int logical_block_size
= block
->bp_block
;
3195 struct request_queue
*q
= block
->request_queue
;
3196 unsigned int max_bytes
, max_discard_sectors
;
3199 if (block
->base
->features
& DASD_FEATURE_USERAW
) {
3201 * the max_blocks value for raw_track access is 256
3202 * it is higher than the native ECKD value because we
3203 * only need one ccw per track
3204 * so the max_hw_sectors are
3205 * 2048 x 512B = 1024kB = 16 tracks
3209 max
= block
->base
->discipline
->max_blocks
<< block
->s2b_shift
;
3211 queue_flag_set_unlocked(QUEUE_FLAG_NONROT
, q
);
3212 q
->limits
.max_dev_sectors
= max
;
3213 blk_queue_logical_block_size(q
, logical_block_size
);
3214 blk_queue_max_hw_sectors(q
, max
);
3215 blk_queue_max_segments(q
, USHRT_MAX
);
3216 /* with page sized segments we can translate each segement into
3219 blk_queue_max_segment_size(q
, PAGE_SIZE
);
3220 blk_queue_segment_boundary(q
, PAGE_SIZE
- 1);
3222 /* Only activate blocklayer discard support for devices that support it */
3223 if (block
->base
->features
& DASD_FEATURE_DISCARD
) {
3224 q
->limits
.discard_granularity
= logical_block_size
;
3225 q
->limits
.discard_alignment
= PAGE_SIZE
;
3227 /* Calculate max_discard_sectors and make it PAGE aligned */
3228 max_bytes
= USHRT_MAX
* logical_block_size
;
3229 max_bytes
= ALIGN(max_bytes
, PAGE_SIZE
) - PAGE_SIZE
;
3230 max_discard_sectors
= max_bytes
/ logical_block_size
;
3232 blk_queue_max_discard_sectors(q
, max_discard_sectors
);
3233 blk_queue_max_write_zeroes_sectors(q
, max_discard_sectors
);
3234 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD
, q
);
3239 * Deactivate and free request queue.
3241 static void dasd_free_queue(struct dasd_block
*block
)
3243 if (block
->request_queue
) {
3244 blk_cleanup_queue(block
->request_queue
);
3245 blk_mq_free_tag_set(&block
->tag_set
);
3246 block
->request_queue
= NULL
;
3250 static int dasd_open(struct block_device
*bdev
, fmode_t mode
)
3252 struct dasd_device
*base
;
3255 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
3259 atomic_inc(&base
->block
->open_count
);
3260 if (test_bit(DASD_FLAG_OFFLINE
, &base
->flags
)) {
3265 if (!try_module_get(base
->discipline
->owner
)) {
3270 if (dasd_probeonly
) {
3271 dev_info(&base
->cdev
->dev
,
3272 "Accessing the DASD failed because it is in "
3273 "probeonly mode\n");
3278 if (base
->state
<= DASD_STATE_BASIC
) {
3279 DBF_DEV_EVENT(DBF_ERR
, base
, " %s",
3280 " Cannot open unrecognized device");
3285 if ((mode
& FMODE_WRITE
) &&
3286 (test_bit(DASD_FLAG_DEVICE_RO
, &base
->flags
) ||
3287 (base
->features
& DASD_FEATURE_READONLY
))) {
3292 dasd_put_device(base
);
3296 module_put(base
->discipline
->owner
);
3298 atomic_dec(&base
->block
->open_count
);
3299 dasd_put_device(base
);
3303 static void dasd_release(struct gendisk
*disk
, fmode_t mode
)
3305 struct dasd_device
*base
= dasd_device_from_gendisk(disk
);
3307 atomic_dec(&base
->block
->open_count
);
3308 module_put(base
->discipline
->owner
);
3309 dasd_put_device(base
);
3314 * Return disk geometry.
3316 static int dasd_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
3318 struct dasd_device
*base
;
3320 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
3324 if (!base
->discipline
||
3325 !base
->discipline
->fill_geometry
) {
3326 dasd_put_device(base
);
3329 base
->discipline
->fill_geometry(base
->block
, geo
);
3330 geo
->start
= get_start_sect(bdev
) >> base
->block
->s2b_shift
;
3331 dasd_put_device(base
);
3335 const struct block_device_operations
3336 dasd_device_operations
= {
3337 .owner
= THIS_MODULE
,
3339 .release
= dasd_release
,
3340 .ioctl
= dasd_ioctl
,
3341 .compat_ioctl
= dasd_ioctl
,
3342 .getgeo
= dasd_getgeo
,
3345 /*******************************************************************************
3346 * end of block device operations
3352 #ifdef CONFIG_PROC_FS
3356 if (dasd_page_cache
!= NULL
) {
3357 kmem_cache_destroy(dasd_page_cache
);
3358 dasd_page_cache
= NULL
;
3360 dasd_gendisk_exit();
3362 if (dasd_debug_area
!= NULL
) {
3363 debug_unregister(dasd_debug_area
);
3364 dasd_debug_area
= NULL
;
3366 dasd_statistics_removeroot();
3370 * SECTION: common functions for ccw_driver use
3374 * Is the device read-only?
3375 * Note that this function does not report the setting of the
3376 * readonly device attribute, but how it is configured in z/VM.
3378 int dasd_device_is_ro(struct dasd_device
*device
)
3380 struct ccw_dev_id dev_id
;
3381 struct diag210 diag_data
;
3386 ccw_device_get_id(device
->cdev
, &dev_id
);
3387 memset(&diag_data
, 0, sizeof(diag_data
));
3388 diag_data
.vrdcdvno
= dev_id
.devno
;
3389 diag_data
.vrdclen
= sizeof(diag_data
);
3390 rc
= diag210(&diag_data
);
3391 if (rc
== 0 || rc
== 2) {
3392 return diag_data
.vrdcvfla
& 0x80;
3394 DBF_EVENT(DBF_WARNING
, "diag210 failed for dev=%04x with rc=%d",
3399 EXPORT_SYMBOL_GPL(dasd_device_is_ro
);
3401 static void dasd_generic_auto_online(void *data
, async_cookie_t cookie
)
3403 struct ccw_device
*cdev
= data
;
3406 ret
= ccw_device_set_online(cdev
);
3408 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3409 dev_name(&cdev
->dev
), ret
);
3413 * Initial attempt at a probe function. this can be simplified once
3414 * the other detection code is gone.
3416 int dasd_generic_probe(struct ccw_device
*cdev
,
3417 struct dasd_discipline
*discipline
)
3421 ret
= dasd_add_sysfs_files(cdev
);
3423 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s",
3424 "dasd_generic_probe: could not add "
3428 cdev
->handler
= &dasd_int_handler
;
3431 * Automatically online either all dasd devices (dasd_autodetect)
3432 * or all devices specified with dasd= parameters during
3435 if ((dasd_get_feature(cdev
, DASD_FEATURE_INITIAL_ONLINE
) > 0 ) ||
3436 (dasd_autodetect
&& dasd_busid_known(dev_name(&cdev
->dev
)) != 0))
3437 async_schedule(dasd_generic_auto_online
, cdev
);
3440 EXPORT_SYMBOL_GPL(dasd_generic_probe
);
3442 void dasd_generic_free_discipline(struct dasd_device
*device
)
3444 /* Forget the discipline information. */
3445 if (device
->discipline
) {
3446 if (device
->discipline
->uncheck_device
)
3447 device
->discipline
->uncheck_device(device
);
3448 module_put(device
->discipline
->owner
);
3449 device
->discipline
= NULL
;
3451 if (device
->base_discipline
) {
3452 module_put(device
->base_discipline
->owner
);
3453 device
->base_discipline
= NULL
;
3456 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline
);
3459 * This will one day be called from a global not_oper handler.
3460 * It is also used by driver_unregister during module unload.
3462 void dasd_generic_remove(struct ccw_device
*cdev
)
3464 struct dasd_device
*device
;
3465 struct dasd_block
*block
;
3467 cdev
->handler
= NULL
;
3469 device
= dasd_device_from_cdev(cdev
);
3470 if (IS_ERR(device
)) {
3471 dasd_remove_sysfs_files(cdev
);
3474 if (test_and_set_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
3475 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3476 /* Already doing offline processing */
3477 dasd_put_device(device
);
3478 dasd_remove_sysfs_files(cdev
);
3482 * This device is removed unconditionally. Set offline
3483 * flag to prevent dasd_open from opening it while it is
3484 * no quite down yet.
3486 dasd_set_target_state(device
, DASD_STATE_NEW
);
3487 /* dasd_delete_device destroys the device reference. */
3488 block
= device
->block
;
3489 dasd_delete_device(device
);
3491 * life cycle of block is bound to device, so delete it after
3492 * device was safely removed
3495 dasd_free_block(block
);
3497 dasd_remove_sysfs_files(cdev
);
3499 EXPORT_SYMBOL_GPL(dasd_generic_remove
);
3502 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3503 * the device is detected for the first time and is supposed to be used
3504 * or the user has started activation through sysfs.
3506 int dasd_generic_set_online(struct ccw_device
*cdev
,
3507 struct dasd_discipline
*base_discipline
)
3509 struct dasd_discipline
*discipline
;
3510 struct dasd_device
*device
;
3513 /* first online clears initial online feature flag */
3514 dasd_set_feature(cdev
, DASD_FEATURE_INITIAL_ONLINE
, 0);
3515 device
= dasd_create_device(cdev
);
3517 return PTR_ERR(device
);
3519 discipline
= base_discipline
;
3520 if (device
->features
& DASD_FEATURE_USEDIAG
) {
3521 if (!dasd_diag_discipline_pointer
) {
3522 /* Try to load the required module. */
3523 rc
= request_module(DASD_DIAG_MOD
);
3525 pr_warn("%s Setting the DASD online failed "
3526 "because the required module %s "
3527 "could not be loaded (rc=%d)\n",
3528 dev_name(&cdev
->dev
), DASD_DIAG_MOD
,
3530 dasd_delete_device(device
);
3534 /* Module init could have failed, so check again here after
3535 * request_module(). */
3536 if (!dasd_diag_discipline_pointer
) {
3537 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3538 dev_name(&cdev
->dev
));
3539 dasd_delete_device(device
);
3542 discipline
= dasd_diag_discipline_pointer
;
3544 if (!try_module_get(base_discipline
->owner
)) {
3545 dasd_delete_device(device
);
3548 if (!try_module_get(discipline
->owner
)) {
3549 module_put(base_discipline
->owner
);
3550 dasd_delete_device(device
);
3553 device
->base_discipline
= base_discipline
;
3554 device
->discipline
= discipline
;
3556 /* check_device will allocate block device if necessary */
3557 rc
= discipline
->check_device(device
);
3559 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3560 dev_name(&cdev
->dev
), discipline
->name
, rc
);
3561 module_put(discipline
->owner
);
3562 module_put(base_discipline
->owner
);
3563 dasd_delete_device(device
);
3567 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
3568 if (device
->state
<= DASD_STATE_KNOWN
) {
3569 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3570 dev_name(&cdev
->dev
));
3572 dasd_set_target_state(device
, DASD_STATE_NEW
);
3574 dasd_free_block(device
->block
);
3575 dasd_delete_device(device
);
3577 pr_debug("dasd_generic device %s found\n",
3578 dev_name(&cdev
->dev
));
3580 wait_event(dasd_init_waitq
, _wait_for_device(device
));
3582 dasd_put_device(device
);
3585 EXPORT_SYMBOL_GPL(dasd_generic_set_online
);
3587 int dasd_generic_set_offline(struct ccw_device
*cdev
)
3589 struct dasd_device
*device
;
3590 struct dasd_block
*block
;
3591 int max_count
, open_count
, rc
;
3592 unsigned long flags
;
3595 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
3596 device
= dasd_device_from_cdev_locked(cdev
);
3597 if (IS_ERR(device
)) {
3598 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3599 return PTR_ERR(device
);
3603 * We must make sure that this device is currently not in use.
3604 * The open_count is increased for every opener, that includes
3605 * the blkdev_get in dasd_scan_partitions. We are only interested
3606 * in the other openers.
3608 if (device
->block
) {
3609 max_count
= device
->block
->bdev
? 0 : -1;
3610 open_count
= atomic_read(&device
->block
->open_count
);
3611 if (open_count
> max_count
) {
3613 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3614 dev_name(&cdev
->dev
), open_count
);
3616 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3617 dev_name(&cdev
->dev
));
3624 * Test if the offline processing is already running and exit if so.
3625 * If a safe offline is being processed this could only be a normal
3626 * offline that should be able to overtake the safe offline and
3627 * cancel any I/O we do not want to wait for any longer
3629 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
3630 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3631 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
,
3638 set_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
3641 * if safe_offline is called set safe_offline_running flag and
3642 * clear safe_offline so that a call to normal offline
3643 * can overrun safe_offline processing
3645 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE
, &device
->flags
) &&
3646 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3647 /* need to unlock here to wait for outstanding I/O */
3648 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3650 * If we want to set the device safe offline all IO operations
3651 * should be finished before continuing the offline process
3652 * so sync bdev first and then wait for our queues to become
3655 if (device
->block
) {
3656 rc
= fsync_bdev(device
->block
->bdev
);
3660 dasd_schedule_device_bh(device
);
3661 rc
= wait_event_interruptible(shutdown_waitq
,
3662 _wait_for_empty_queues(device
));
3667 * check if a normal offline process overtook the offline
3668 * processing in this case simply do nothing beside returning
3669 * that we got interrupted
3670 * otherwise mark safe offline as not running any longer and
3671 * continue with normal offline
3673 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
3674 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3678 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
);
3680 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3682 dasd_set_target_state(device
, DASD_STATE_NEW
);
3683 /* dasd_delete_device destroys the device reference. */
3684 block
= device
->block
;
3685 dasd_delete_device(device
);
3687 * life cycle of block is bound to device, so delete it after
3688 * device was safely removed
3691 dasd_free_block(block
);
3696 /* interrupted by signal */
3697 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
3698 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
);
3699 clear_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
3701 dasd_put_device(device
);
3702 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3705 EXPORT_SYMBOL_GPL(dasd_generic_set_offline
);
3707 int dasd_generic_last_path_gone(struct dasd_device
*device
)
3709 struct dasd_ccw_req
*cqr
;
3711 dev_warn(&device
->cdev
->dev
, "No operational channel path is left "
3712 "for the device\n");
3713 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s", "last path gone");
3714 /* First of all call extended error reporting. */
3715 dasd_eer_write(device
, NULL
, DASD_EER_NOPATH
);
3717 if (device
->state
< DASD_STATE_BASIC
)
3719 /* Device is active. We want to keep it. */
3720 list_for_each_entry(cqr
, &device
->ccw_queue
, devlist
)
3721 if ((cqr
->status
== DASD_CQR_IN_IO
) ||
3722 (cqr
->status
== DASD_CQR_CLEAR_PENDING
)) {
3723 cqr
->status
= DASD_CQR_QUEUED
;
3726 dasd_device_set_stop_bits(device
, DASD_STOPPED_DC_WAIT
);
3727 dasd_device_clear_timer(device
);
3728 dasd_schedule_device_bh(device
);
3731 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone
);
3733 int dasd_generic_path_operational(struct dasd_device
*device
)
3735 dev_info(&device
->cdev
->dev
, "A channel path to the device has become "
3737 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s", "path operational");
3738 dasd_device_remove_stop_bits(device
, DASD_STOPPED_DC_WAIT
);
3739 if (device
->stopped
& DASD_UNRESUMED_PM
) {
3740 dasd_device_remove_stop_bits(device
, DASD_UNRESUMED_PM
);
3741 dasd_restore_device(device
);
3744 dasd_schedule_device_bh(device
);
3745 if (device
->block
) {
3746 dasd_schedule_block_bh(device
->block
);
3747 if (device
->block
->request_queue
)
3748 blk_mq_run_hw_queues(device
->block
->request_queue
,
3752 if (!device
->stopped
)
3753 wake_up(&generic_waitq
);
3757 EXPORT_SYMBOL_GPL(dasd_generic_path_operational
);
3759 int dasd_generic_notify(struct ccw_device
*cdev
, int event
)
3761 struct dasd_device
*device
;
3764 device
= dasd_device_from_cdev_locked(cdev
);
3772 dasd_path_no_path(device
);
3773 ret
= dasd_generic_last_path_gone(device
);
3777 if (dasd_path_get_opm(device
))
3778 ret
= dasd_generic_path_operational(device
);
3781 dasd_put_device(device
);
3784 EXPORT_SYMBOL_GPL(dasd_generic_notify
);
3786 void dasd_generic_path_event(struct ccw_device
*cdev
, int *path_event
)
3788 struct dasd_device
*device
;
3789 int chp
, oldopm
, hpfpm
, ifccpm
;
3791 device
= dasd_device_from_cdev_locked(cdev
);
3795 oldopm
= dasd_path_get_opm(device
);
3796 for (chp
= 0; chp
< 8; chp
++) {
3797 if (path_event
[chp
] & PE_PATH_GONE
) {
3798 dasd_path_notoper(device
, chp
);
3800 if (path_event
[chp
] & PE_PATH_AVAILABLE
) {
3801 dasd_path_available(device
, chp
);
3802 dasd_schedule_device_bh(device
);
3804 if (path_event
[chp
] & PE_PATHGROUP_ESTABLISHED
) {
3805 if (!dasd_path_is_operational(device
, chp
) &&
3806 !dasd_path_need_verify(device
, chp
)) {
3808 * we can not establish a pathgroup on an
3809 * unavailable path, so trigger a path
3810 * verification first
3812 dasd_path_available(device
, chp
);
3813 dasd_schedule_device_bh(device
);
3815 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3816 "Pathgroup re-established\n");
3817 if (device
->discipline
->kick_validate
)
3818 device
->discipline
->kick_validate(device
);
3821 hpfpm
= dasd_path_get_hpfpm(device
);
3822 ifccpm
= dasd_path_get_ifccpm(device
);
3823 if (!dasd_path_get_opm(device
) && hpfpm
) {
3825 * device has no operational paths but at least one path is
3826 * disabled due to HPF errors
3827 * disable HPF at all and use the path(s) again
3829 if (device
->discipline
->disable_hpf
)
3830 device
->discipline
->disable_hpf(device
);
3831 dasd_device_set_stop_bits(device
, DASD_STOPPED_NOT_ACC
);
3832 dasd_path_set_tbvpm(device
, hpfpm
);
3833 dasd_schedule_device_bh(device
);
3834 dasd_schedule_requeue(device
);
3835 } else if (!dasd_path_get_opm(device
) && ifccpm
) {
3837 * device has no operational paths but at least one path is
3838 * disabled due to IFCC errors
3839 * trigger path verification on paths with IFCC errors
3841 dasd_path_set_tbvpm(device
, ifccpm
);
3842 dasd_schedule_device_bh(device
);
3844 if (oldopm
&& !dasd_path_get_opm(device
) && !hpfpm
&& !ifccpm
) {
3845 dev_warn(&device
->cdev
->dev
,
3846 "No verified channel paths remain for the device\n");
3847 DBF_DEV_EVENT(DBF_WARNING
, device
,
3848 "%s", "last verified path gone");
3849 dasd_eer_write(device
, NULL
, DASD_EER_NOPATH
);
3850 dasd_device_set_stop_bits(device
,
3851 DASD_STOPPED_DC_WAIT
);
3853 dasd_put_device(device
);
3855 EXPORT_SYMBOL_GPL(dasd_generic_path_event
);
3857 int dasd_generic_verify_path(struct dasd_device
*device
, __u8 lpm
)
3859 if (!dasd_path_get_opm(device
) && lpm
) {
3860 dasd_path_set_opm(device
, lpm
);
3861 dasd_generic_path_operational(device
);
3863 dasd_path_add_opm(device
, lpm
);
3866 EXPORT_SYMBOL_GPL(dasd_generic_verify_path
);
3869 * clear active requests and requeue them to block layer if possible
3871 static int dasd_generic_requeue_all_requests(struct dasd_device
*device
)
3873 struct list_head requeue_queue
;
3874 struct dasd_ccw_req
*cqr
, *n
;
3875 struct dasd_ccw_req
*refers
;
3878 INIT_LIST_HEAD(&requeue_queue
);
3879 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
3881 list_for_each_entry_safe(cqr
, n
, &device
->ccw_queue
, devlist
) {
3882 /* Check status and move request to flush_queue */
3883 if (cqr
->status
== DASD_CQR_IN_IO
) {
3884 rc
= device
->discipline
->term_IO(cqr
);
3886 /* unable to terminate requeust */
3887 dev_err(&device
->cdev
->dev
,
3888 "Unable to terminate request %p "
3889 "on suspend\n", cqr
);
3890 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
3891 dasd_put_device(device
);
3895 list_move_tail(&cqr
->devlist
, &requeue_queue
);
3897 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
3899 list_for_each_entry_safe(cqr
, n
, &requeue_queue
, devlist
) {
3900 wait_event(dasd_flush_wq
,
3901 (cqr
->status
!= DASD_CQR_CLEAR_PENDING
));
3904 * requeue requests to blocklayer will only work
3905 * for block device requests
3907 if (_dasd_requeue_request(cqr
))
3910 /* remove requests from device and block queue */
3911 list_del_init(&cqr
->devlist
);
3912 while (cqr
->refers
!= NULL
) {
3913 refers
= cqr
->refers
;
3914 /* remove the request from the block queue */
3915 list_del(&cqr
->blocklist
);
3916 /* free the finished erp request */
3917 dasd_free_erp_request(cqr
, cqr
->memdev
);
3922 list_del_init(&cqr
->blocklist
);
3923 cqr
->block
->base
->discipline
->free_cp(
3924 cqr
, (struct request
*) cqr
->callback_data
);
3928 * if requests remain then they are internal request
3929 * and go back to the device queue
3931 if (!list_empty(&requeue_queue
)) {
3932 /* move freeze_queue to start of the ccw_queue */
3933 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
3934 list_splice_tail(&requeue_queue
, &device
->ccw_queue
);
3935 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
3937 dasd_schedule_device_bh(device
);
3941 static void do_requeue_requests(struct work_struct
*work
)
3943 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
3945 dasd_generic_requeue_all_requests(device
);
3946 dasd_device_remove_stop_bits(device
, DASD_STOPPED_NOT_ACC
);
3948 dasd_schedule_block_bh(device
->block
);
3949 dasd_put_device(device
);
3952 void dasd_schedule_requeue(struct dasd_device
*device
)
3954 dasd_get_device(device
);
3955 /* queue call to dasd_reload_device to the kernel event daemon. */
3956 if (!schedule_work(&device
->requeue_requests
))
3957 dasd_put_device(device
);
3959 EXPORT_SYMBOL(dasd_schedule_requeue
);
3961 int dasd_generic_pm_freeze(struct ccw_device
*cdev
)
3963 struct dasd_device
*device
= dasd_device_from_cdev(cdev
);
3966 return PTR_ERR(device
);
3968 /* mark device as suspended */
3969 set_bit(DASD_FLAG_SUSPENDED
, &device
->flags
);
3971 if (device
->discipline
->freeze
)
3972 device
->discipline
->freeze(device
);
3974 /* disallow new I/O */
3975 dasd_device_set_stop_bits(device
, DASD_STOPPED_PM
);
3977 return dasd_generic_requeue_all_requests(device
);
3979 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze
);
3981 int dasd_generic_restore_device(struct ccw_device
*cdev
)
3983 struct dasd_device
*device
= dasd_device_from_cdev(cdev
);
3987 return PTR_ERR(device
);
3989 /* allow new IO again */
3990 dasd_device_remove_stop_bits(device
,
3991 (DASD_STOPPED_PM
| DASD_UNRESUMED_PM
));
3993 dasd_schedule_device_bh(device
);
3996 * call discipline restore function
3997 * if device is stopped do nothing e.g. for disconnected devices
3999 if (device
->discipline
->restore
&& !(device
->stopped
))
4000 rc
= device
->discipline
->restore(device
);
4001 if (rc
|| device
->stopped
)
4003 * if the resume failed for the DASD we put it in
4004 * an UNRESUMED stop state
4006 device
->stopped
|= DASD_UNRESUMED_PM
;
4008 if (device
->block
) {
4009 dasd_schedule_block_bh(device
->block
);
4010 if (device
->block
->request_queue
)
4011 blk_mq_run_hw_queues(device
->block
->request_queue
,
4015 clear_bit(DASD_FLAG_SUSPENDED
, &device
->flags
);
4016 dasd_put_device(device
);
4019 EXPORT_SYMBOL_GPL(dasd_generic_restore_device
);
4021 static struct dasd_ccw_req
*dasd_generic_build_rdc(struct dasd_device
*device
,
4023 int rdc_buffer_size
,
4026 struct dasd_ccw_req
*cqr
;
4028 unsigned long *idaw
;
4030 cqr
= dasd_smalloc_request(magic
, 1 /* RDC */, rdc_buffer_size
, device
);
4033 /* internal error 13 - Allocating the RDC request failed*/
4034 dev_err(&device
->cdev
->dev
,
4035 "An error occurred in the DASD device driver, "
4036 "reason=%s\n", "13");
4041 ccw
->cmd_code
= CCW_CMD_RDC
;
4042 if (idal_is_needed(rdc_buffer
, rdc_buffer_size
)) {
4043 idaw
= (unsigned long *) (cqr
->data
);
4044 ccw
->cda
= (__u32
)(addr_t
) idaw
;
4045 ccw
->flags
= CCW_FLAG_IDA
;
4046 idaw
= idal_create_words(idaw
, rdc_buffer
, rdc_buffer_size
);
4048 ccw
->cda
= (__u32
)(addr_t
) rdc_buffer
;
4052 ccw
->count
= rdc_buffer_size
;
4053 cqr
->startdev
= device
;
4054 cqr
->memdev
= device
;
4055 cqr
->expires
= 10*HZ
;
4057 cqr
->buildclk
= get_tod_clock();
4058 cqr
->status
= DASD_CQR_FILLED
;
4063 int dasd_generic_read_dev_chars(struct dasd_device
*device
, int magic
,
4064 void *rdc_buffer
, int rdc_buffer_size
)
4067 struct dasd_ccw_req
*cqr
;
4069 cqr
= dasd_generic_build_rdc(device
, rdc_buffer
, rdc_buffer_size
,
4072 return PTR_ERR(cqr
);
4074 ret
= dasd_sleep_on(cqr
);
4075 dasd_sfree_request(cqr
, cqr
->memdev
);
4078 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars
);
4081 * In command mode and transport mode we need to look for sense
4082 * data in different places. The sense data itself is allways
4083 * an array of 32 bytes, so we can unify the sense data access
4086 char *dasd_get_sense(struct irb
*irb
)
4088 struct tsb
*tsb
= NULL
;
4091 if (scsw_is_tm(&irb
->scsw
) && (irb
->scsw
.tm
.fcxs
== 0x01)) {
4092 if (irb
->scsw
.tm
.tcw
)
4093 tsb
= tcw_get_tsb((struct tcw
*)(unsigned long)
4095 if (tsb
&& tsb
->length
== 64 && tsb
->flags
)
4096 switch (tsb
->flags
& 0x07) {
4097 case 1: /* tsa_iostat */
4098 sense
= tsb
->tsa
.iostat
.sense
;
4100 case 2: /* tsa_ddpc */
4101 sense
= tsb
->tsa
.ddpc
.sense
;
4104 /* currently we don't use interrogate data */
4107 } else if (irb
->esw
.esw0
.erw
.cons
) {
4112 EXPORT_SYMBOL_GPL(dasd_get_sense
);
4114 void dasd_generic_shutdown(struct ccw_device
*cdev
)
4116 struct dasd_device
*device
;
4118 device
= dasd_device_from_cdev(cdev
);
4123 dasd_schedule_block_bh(device
->block
);
4125 dasd_schedule_device_bh(device
);
4127 wait_event(shutdown_waitq
, _wait_for_empty_queues(device
));
4129 EXPORT_SYMBOL_GPL(dasd_generic_shutdown
);
4131 static int __init
dasd_init(void)
4135 init_waitqueue_head(&dasd_init_waitq
);
4136 init_waitqueue_head(&dasd_flush_wq
);
4137 init_waitqueue_head(&generic_waitq
);
4138 init_waitqueue_head(&shutdown_waitq
);
4140 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4141 dasd_debug_area
= debug_register("dasd", 1, 1, 8 * sizeof(long));
4142 if (dasd_debug_area
== NULL
) {
4146 debug_register_view(dasd_debug_area
, &debug_sprintf_view
);
4147 debug_set_level(dasd_debug_area
, DBF_WARNING
);
4149 DBF_EVENT(DBF_EMERG
, "%s", "debug area created");
4151 dasd_diag_discipline_pointer
= NULL
;
4153 dasd_statistics_createroot();
4155 rc
= dasd_devmap_init();
4158 rc
= dasd_gendisk_init();
4164 rc
= dasd_eer_init();
4167 #ifdef CONFIG_PROC_FS
4168 rc
= dasd_proc_init();
4175 pr_info("The DASD device driver could not be initialized\n");
4180 module_init(dasd_init
);
4181 module_exit(dasd_exit
);