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"
44 static unsigned int queue_depth
= 32;
45 static unsigned int nr_hw_queues
= 4;
47 module_param(queue_depth
, uint
, 0444);
48 MODULE_PARM_DESC(queue_depth
, "Default queue depth for new DASD devices");
50 module_param(nr_hw_queues
, uint
, 0444);
51 MODULE_PARM_DESC(nr_hw_queues
, "Default number of hardware queues for new DASD devices");
54 * SECTION: exported variables of dasd.c
56 debug_info_t
*dasd_debug_area
;
57 EXPORT_SYMBOL(dasd_debug_area
);
58 static struct dentry
*dasd_debugfs_root_entry
;
59 struct dasd_discipline
*dasd_diag_discipline_pointer
;
60 EXPORT_SYMBOL(dasd_diag_discipline_pointer
);
61 void dasd_int_handler(struct ccw_device
*, unsigned long, struct irb
*);
63 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
64 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
65 " Copyright IBM Corp. 2000");
66 MODULE_SUPPORTED_DEVICE("dasd");
67 MODULE_LICENSE("GPL");
70 * SECTION: prototypes for static functions of dasd.c
72 static int dasd_alloc_queue(struct dasd_block
*);
73 static void dasd_setup_queue(struct dasd_block
*);
74 static void dasd_free_queue(struct dasd_block
*);
75 static int dasd_flush_block_queue(struct dasd_block
*);
76 static void dasd_device_tasklet(unsigned long);
77 static void dasd_block_tasklet(unsigned long);
78 static void do_kick_device(struct work_struct
*);
79 static void do_restore_device(struct work_struct
*);
80 static void do_reload_device(struct work_struct
*);
81 static void do_requeue_requests(struct work_struct
*);
82 static void dasd_return_cqr_cb(struct dasd_ccw_req
*, void *);
83 static void dasd_device_timeout(struct timer_list
*);
84 static void dasd_block_timeout(struct timer_list
*);
85 static void __dasd_process_erp(struct dasd_device
*, struct dasd_ccw_req
*);
86 static void dasd_profile_init(struct dasd_profile
*, struct dentry
*);
87 static void dasd_profile_exit(struct dasd_profile
*);
88 static void dasd_hosts_init(struct dentry
*, struct dasd_device
*);
89 static void dasd_hosts_exit(struct dasd_device
*);
92 * SECTION: Operations on the device structure.
94 static wait_queue_head_t dasd_init_waitq
;
95 static wait_queue_head_t dasd_flush_wq
;
96 static wait_queue_head_t generic_waitq
;
97 static wait_queue_head_t shutdown_waitq
;
100 * Allocate memory for a new device structure.
102 struct dasd_device
*dasd_alloc_device(void)
104 struct dasd_device
*device
;
106 device
= kzalloc(sizeof(struct dasd_device
), GFP_ATOMIC
);
108 return ERR_PTR(-ENOMEM
);
110 /* Get two pages for normal block device operations. */
111 device
->ccw_mem
= (void *) __get_free_pages(GFP_ATOMIC
| GFP_DMA
, 1);
112 if (!device
->ccw_mem
) {
114 return ERR_PTR(-ENOMEM
);
116 /* Get one page for error recovery. */
117 device
->erp_mem
= (void *) get_zeroed_page(GFP_ATOMIC
| GFP_DMA
);
118 if (!device
->erp_mem
) {
119 free_pages((unsigned long) device
->ccw_mem
, 1);
121 return ERR_PTR(-ENOMEM
);
124 dasd_init_chunklist(&device
->ccw_chunks
, device
->ccw_mem
, PAGE_SIZE
*2);
125 dasd_init_chunklist(&device
->erp_chunks
, device
->erp_mem
, PAGE_SIZE
);
126 spin_lock_init(&device
->mem_lock
);
127 atomic_set(&device
->tasklet_scheduled
, 0);
128 tasklet_init(&device
->tasklet
, dasd_device_tasklet
,
129 (unsigned long) device
);
130 INIT_LIST_HEAD(&device
->ccw_queue
);
131 timer_setup(&device
->timer
, dasd_device_timeout
, 0);
132 INIT_WORK(&device
->kick_work
, do_kick_device
);
133 INIT_WORK(&device
->restore_device
, do_restore_device
);
134 INIT_WORK(&device
->reload_device
, do_reload_device
);
135 INIT_WORK(&device
->requeue_requests
, do_requeue_requests
);
136 device
->state
= DASD_STATE_NEW
;
137 device
->target
= DASD_STATE_NEW
;
138 mutex_init(&device
->state_mutex
);
139 spin_lock_init(&device
->profile
.lock
);
144 * Free memory of a device structure.
146 void dasd_free_device(struct dasd_device
*device
)
148 kfree(device
->private);
149 free_page((unsigned long) device
->erp_mem
);
150 free_pages((unsigned long) device
->ccw_mem
, 1);
155 * Allocate memory for a new device structure.
157 struct dasd_block
*dasd_alloc_block(void)
159 struct dasd_block
*block
;
161 block
= kzalloc(sizeof(*block
), GFP_ATOMIC
);
163 return ERR_PTR(-ENOMEM
);
164 /* open_count = 0 means device online but not in use */
165 atomic_set(&block
->open_count
, -1);
167 atomic_set(&block
->tasklet_scheduled
, 0);
168 tasklet_init(&block
->tasklet
, dasd_block_tasklet
,
169 (unsigned long) block
);
170 INIT_LIST_HEAD(&block
->ccw_queue
);
171 spin_lock_init(&block
->queue_lock
);
172 timer_setup(&block
->timer
, dasd_block_timeout
, 0);
173 spin_lock_init(&block
->profile
.lock
);
177 EXPORT_SYMBOL_GPL(dasd_alloc_block
);
180 * Free memory of a device structure.
182 void dasd_free_block(struct dasd_block
*block
)
186 EXPORT_SYMBOL_GPL(dasd_free_block
);
189 * Make a new device known to the system.
191 static int dasd_state_new_to_known(struct dasd_device
*device
)
196 * As long as the device is not in state DASD_STATE_NEW we want to
197 * keep the reference count > 0.
199 dasd_get_device(device
);
202 rc
= dasd_alloc_queue(device
->block
);
204 dasd_put_device(device
);
208 device
->state
= DASD_STATE_KNOWN
;
213 * Let the system forget about a device.
215 static int dasd_state_known_to_new(struct dasd_device
*device
)
217 /* Disable extended error reporting for this device. */
218 dasd_eer_disable(device
);
219 device
->state
= DASD_STATE_NEW
;
222 dasd_free_queue(device
->block
);
224 /* Give up reference we took in dasd_state_new_to_known. */
225 dasd_put_device(device
);
229 static struct dentry
*dasd_debugfs_setup(const char *name
,
230 struct dentry
*base_dentry
)
236 pde
= debugfs_create_dir(name
, base_dentry
);
237 if (!pde
|| IS_ERR(pde
))
243 * Request the irq line for the device.
245 static int dasd_state_known_to_basic(struct dasd_device
*device
)
247 struct dasd_block
*block
= device
->block
;
250 /* Allocate and register gendisk structure. */
252 rc
= dasd_gendisk_alloc(block
);
255 block
->debugfs_dentry
=
256 dasd_debugfs_setup(block
->gdp
->disk_name
,
257 dasd_debugfs_root_entry
);
258 dasd_profile_init(&block
->profile
, block
->debugfs_dentry
);
259 if (dasd_global_profile_level
== DASD_PROFILE_ON
)
260 dasd_profile_on(&device
->block
->profile
);
262 device
->debugfs_dentry
=
263 dasd_debugfs_setup(dev_name(&device
->cdev
->dev
),
264 dasd_debugfs_root_entry
);
265 dasd_profile_init(&device
->profile
, device
->debugfs_dentry
);
266 dasd_hosts_init(device
->debugfs_dentry
, device
);
268 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
269 device
->debug_area
= debug_register(dev_name(&device
->cdev
->dev
), 4, 1,
271 debug_register_view(device
->debug_area
, &debug_sprintf_view
);
272 debug_set_level(device
->debug_area
, DBF_WARNING
);
273 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s", "debug area created");
275 device
->state
= DASD_STATE_BASIC
;
281 * Release the irq line for the device. Terminate any running i/o.
283 static int dasd_state_basic_to_known(struct dasd_device
*device
)
287 if (device
->discipline
->basic_to_known
) {
288 rc
= device
->discipline
->basic_to_known(device
);
294 dasd_profile_exit(&device
->block
->profile
);
295 debugfs_remove(device
->block
->debugfs_dentry
);
296 dasd_gendisk_free(device
->block
);
297 dasd_block_clear_timer(device
->block
);
299 rc
= dasd_flush_device_queue(device
);
302 dasd_device_clear_timer(device
);
303 dasd_profile_exit(&device
->profile
);
304 dasd_hosts_exit(device
);
305 debugfs_remove(device
->debugfs_dentry
);
306 DBF_DEV_EVENT(DBF_EMERG
, device
, "%p debug area deleted", device
);
307 if (device
->debug_area
!= NULL
) {
308 debug_unregister(device
->debug_area
);
309 device
->debug_area
= NULL
;
311 device
->state
= DASD_STATE_KNOWN
;
316 * Do the initial analysis. The do_analysis function may return
317 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
318 * until the discipline decides to continue the startup sequence
319 * by calling the function dasd_change_state. The eckd disciplines
320 * uses this to start a ccw that detects the format. The completion
321 * interrupt for this detection ccw uses the kernel event daemon to
322 * trigger the call to dasd_change_state. All this is done in the
323 * discipline code, see dasd_eckd.c.
324 * After the analysis ccw is done (do_analysis returned 0) the block
326 * In case the analysis returns an error, the device setup is stopped
327 * (a fake disk was already added to allow formatting).
329 static int dasd_state_basic_to_ready(struct dasd_device
*device
)
332 struct dasd_block
*block
;
333 struct gendisk
*disk
;
336 block
= device
->block
;
337 /* make disk known with correct capacity */
339 if (block
->base
->discipline
->do_analysis
!= NULL
)
340 rc
= block
->base
->discipline
->do_analysis(block
);
343 device
->state
= DASD_STATE_UNFMT
;
344 disk
= device
->block
->gdp
;
345 kobject_uevent(&disk_to_dev(disk
)->kobj
,
351 dasd_setup_queue(block
);
352 set_capacity(block
->gdp
,
353 block
->blocks
<< block
->s2b_shift
);
354 device
->state
= DASD_STATE_READY
;
355 rc
= dasd_scan_partitions(block
);
357 device
->state
= DASD_STATE_BASIC
;
361 device
->state
= DASD_STATE_READY
;
364 if (device
->discipline
->basic_to_ready
)
365 rc
= device
->discipline
->basic_to_ready(device
);
370 int _wait_for_empty_queues(struct dasd_device
*device
)
373 return list_empty(&device
->ccw_queue
) &&
374 list_empty(&device
->block
->ccw_queue
);
376 return list_empty(&device
->ccw_queue
);
380 * Remove device from block device layer. Destroy dirty buffers.
381 * Forget format information. Check if the target level is basic
382 * and if it is create fake disk for formatting.
384 static int dasd_state_ready_to_basic(struct dasd_device
*device
)
388 device
->state
= DASD_STATE_BASIC
;
390 struct dasd_block
*block
= device
->block
;
391 rc
= dasd_flush_block_queue(block
);
393 device
->state
= DASD_STATE_READY
;
396 dasd_destroy_partitions(block
);
399 block
->s2b_shift
= 0;
407 static int dasd_state_unfmt_to_basic(struct dasd_device
*device
)
409 device
->state
= DASD_STATE_BASIC
;
414 * Make the device online and schedule the bottom half to start
415 * the requeueing of requests from the linux request queue to the
419 dasd_state_ready_to_online(struct dasd_device
* device
)
421 struct gendisk
*disk
;
422 struct disk_part_iter piter
;
423 struct hd_struct
*part
;
425 device
->state
= DASD_STATE_ONLINE
;
427 dasd_schedule_block_bh(device
->block
);
428 if ((device
->features
& DASD_FEATURE_USERAW
)) {
429 disk
= device
->block
->gdp
;
430 kobject_uevent(&disk_to_dev(disk
)->kobj
, KOBJ_CHANGE
);
433 disk
= device
->block
->bdev
->bd_disk
;
434 disk_part_iter_init(&piter
, disk
, DISK_PITER_INCL_PART0
);
435 while ((part
= disk_part_iter_next(&piter
)))
436 kobject_uevent(&part_to_dev(part
)->kobj
, KOBJ_CHANGE
);
437 disk_part_iter_exit(&piter
);
443 * Stop the requeueing of requests again.
445 static int dasd_state_online_to_ready(struct dasd_device
*device
)
448 struct gendisk
*disk
;
449 struct disk_part_iter piter
;
450 struct hd_struct
*part
;
452 if (device
->discipline
->online_to_ready
) {
453 rc
= device
->discipline
->online_to_ready(device
);
458 device
->state
= DASD_STATE_READY
;
459 if (device
->block
&& !(device
->features
& DASD_FEATURE_USERAW
)) {
460 disk
= device
->block
->bdev
->bd_disk
;
461 disk_part_iter_init(&piter
, disk
, DISK_PITER_INCL_PART0
);
462 while ((part
= disk_part_iter_next(&piter
)))
463 kobject_uevent(&part_to_dev(part
)->kobj
, KOBJ_CHANGE
);
464 disk_part_iter_exit(&piter
);
470 * Device startup state changes.
472 static int dasd_increase_state(struct dasd_device
*device
)
477 if (device
->state
== DASD_STATE_NEW
&&
478 device
->target
>= DASD_STATE_KNOWN
)
479 rc
= dasd_state_new_to_known(device
);
482 device
->state
== DASD_STATE_KNOWN
&&
483 device
->target
>= DASD_STATE_BASIC
)
484 rc
= dasd_state_known_to_basic(device
);
487 device
->state
== DASD_STATE_BASIC
&&
488 device
->target
>= DASD_STATE_READY
)
489 rc
= dasd_state_basic_to_ready(device
);
492 device
->state
== DASD_STATE_UNFMT
&&
493 device
->target
> DASD_STATE_UNFMT
)
497 device
->state
== DASD_STATE_READY
&&
498 device
->target
>= DASD_STATE_ONLINE
)
499 rc
= dasd_state_ready_to_online(device
);
505 * Device shutdown state changes.
507 static int dasd_decrease_state(struct dasd_device
*device
)
512 if (device
->state
== DASD_STATE_ONLINE
&&
513 device
->target
<= DASD_STATE_READY
)
514 rc
= dasd_state_online_to_ready(device
);
517 device
->state
== DASD_STATE_READY
&&
518 device
->target
<= DASD_STATE_BASIC
)
519 rc
= dasd_state_ready_to_basic(device
);
522 device
->state
== DASD_STATE_UNFMT
&&
523 device
->target
<= DASD_STATE_BASIC
)
524 rc
= dasd_state_unfmt_to_basic(device
);
527 device
->state
== DASD_STATE_BASIC
&&
528 device
->target
<= DASD_STATE_KNOWN
)
529 rc
= dasd_state_basic_to_known(device
);
532 device
->state
== DASD_STATE_KNOWN
&&
533 device
->target
<= DASD_STATE_NEW
)
534 rc
= dasd_state_known_to_new(device
);
540 * This is the main startup/shutdown routine.
542 static void dasd_change_state(struct dasd_device
*device
)
546 if (device
->state
== device
->target
)
547 /* Already where we want to go today... */
549 if (device
->state
< device
->target
)
550 rc
= dasd_increase_state(device
);
552 rc
= dasd_decrease_state(device
);
556 device
->target
= device
->state
;
558 /* let user-space know that the device status changed */
559 kobject_uevent(&device
->cdev
->dev
.kobj
, KOBJ_CHANGE
);
561 if (device
->state
== device
->target
)
562 wake_up(&dasd_init_waitq
);
566 * Kick starter for devices that did not complete the startup/shutdown
567 * procedure or were sleeping because of a pending state.
568 * dasd_kick_device will schedule a call do do_kick_device to the kernel
571 static void do_kick_device(struct work_struct
*work
)
573 struct dasd_device
*device
= container_of(work
, struct dasd_device
, kick_work
);
574 mutex_lock(&device
->state_mutex
);
575 dasd_change_state(device
);
576 mutex_unlock(&device
->state_mutex
);
577 dasd_schedule_device_bh(device
);
578 dasd_put_device(device
);
581 void dasd_kick_device(struct dasd_device
*device
)
583 dasd_get_device(device
);
584 /* queue call to dasd_kick_device to the kernel event daemon. */
585 if (!schedule_work(&device
->kick_work
))
586 dasd_put_device(device
);
588 EXPORT_SYMBOL(dasd_kick_device
);
591 * dasd_reload_device will schedule a call do do_reload_device to the kernel
594 static void do_reload_device(struct work_struct
*work
)
596 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
598 device
->discipline
->reload(device
);
599 dasd_put_device(device
);
602 void dasd_reload_device(struct dasd_device
*device
)
604 dasd_get_device(device
);
605 /* queue call to dasd_reload_device to the kernel event daemon. */
606 if (!schedule_work(&device
->reload_device
))
607 dasd_put_device(device
);
609 EXPORT_SYMBOL(dasd_reload_device
);
612 * dasd_restore_device will schedule a call do do_restore_device to the kernel
615 static void do_restore_device(struct work_struct
*work
)
617 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
619 device
->cdev
->drv
->restore(device
->cdev
);
620 dasd_put_device(device
);
623 void dasd_restore_device(struct dasd_device
*device
)
625 dasd_get_device(device
);
626 /* queue call to dasd_restore_device to the kernel event daemon. */
627 if (!schedule_work(&device
->restore_device
))
628 dasd_put_device(device
);
632 * Set the target state for a device and starts the state change.
634 void dasd_set_target_state(struct dasd_device
*device
, int target
)
636 dasd_get_device(device
);
637 mutex_lock(&device
->state_mutex
);
638 /* If we are in probeonly mode stop at DASD_STATE_READY. */
639 if (dasd_probeonly
&& target
> DASD_STATE_READY
)
640 target
= DASD_STATE_READY
;
641 if (device
->target
!= target
) {
642 if (device
->state
== target
)
643 wake_up(&dasd_init_waitq
);
644 device
->target
= target
;
646 if (device
->state
!= device
->target
)
647 dasd_change_state(device
);
648 mutex_unlock(&device
->state_mutex
);
649 dasd_put_device(device
);
651 EXPORT_SYMBOL(dasd_set_target_state
);
654 * Enable devices with device numbers in [from..to].
656 static inline int _wait_for_device(struct dasd_device
*device
)
658 return (device
->state
== device
->target
);
661 void dasd_enable_device(struct dasd_device
*device
)
663 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
664 if (device
->state
<= DASD_STATE_KNOWN
)
665 /* No discipline for device found. */
666 dasd_set_target_state(device
, DASD_STATE_NEW
);
667 /* Now wait for the devices to come up. */
668 wait_event(dasd_init_waitq
, _wait_for_device(device
));
670 dasd_reload_device(device
);
671 if (device
->discipline
->kick_validate
)
672 device
->discipline
->kick_validate(device
);
674 EXPORT_SYMBOL(dasd_enable_device
);
677 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
680 unsigned int dasd_global_profile_level
= DASD_PROFILE_OFF
;
682 #ifdef CONFIG_DASD_PROFILE
683 struct dasd_profile dasd_global_profile
= {
684 .lock
= __SPIN_LOCK_UNLOCKED(dasd_global_profile
.lock
),
686 static struct dentry
*dasd_debugfs_global_entry
;
689 * Add profiling information for cqr before execution.
691 static void dasd_profile_start(struct dasd_block
*block
,
692 struct dasd_ccw_req
*cqr
,
696 unsigned int counter
;
697 struct dasd_device
*device
;
699 /* count the length of the chanq for statistics */
701 if (dasd_global_profile_level
|| block
->profile
.data
)
702 list_for_each(l
, &block
->ccw_queue
)
706 spin_lock(&dasd_global_profile
.lock
);
707 if (dasd_global_profile
.data
) {
708 dasd_global_profile
.data
->dasd_io_nr_req
[counter
]++;
709 if (rq_data_dir(req
) == READ
)
710 dasd_global_profile
.data
->dasd_read_nr_req
[counter
]++;
712 spin_unlock(&dasd_global_profile
.lock
);
714 spin_lock(&block
->profile
.lock
);
715 if (block
->profile
.data
) {
716 block
->profile
.data
->dasd_io_nr_req
[counter
]++;
717 if (rq_data_dir(req
) == READ
)
718 block
->profile
.data
->dasd_read_nr_req
[counter
]++;
720 spin_unlock(&block
->profile
.lock
);
723 * We count the request for the start device, even though it may run on
724 * some other device due to error recovery. This way we make sure that
725 * we count each request only once.
727 device
= cqr
->startdev
;
728 if (device
->profile
.data
) {
729 counter
= 1; /* request is not yet queued on the start device */
730 list_for_each(l
, &device
->ccw_queue
)
734 spin_lock(&device
->profile
.lock
);
735 if (device
->profile
.data
) {
736 device
->profile
.data
->dasd_io_nr_req
[counter
]++;
737 if (rq_data_dir(req
) == READ
)
738 device
->profile
.data
->dasd_read_nr_req
[counter
]++;
740 spin_unlock(&device
->profile
.lock
);
744 * Add profiling information for cqr after execution.
747 #define dasd_profile_counter(value, index) \
749 for (index = 0; index < 31 && value >> (2+index); index++) \
753 static void dasd_profile_end_add_data(struct dasd_profile_info
*data
,
766 /* in case of an overflow, reset the whole profile */
767 if (data
->dasd_io_reqs
== UINT_MAX
) {
768 memset(data
, 0, sizeof(*data
));
769 ktime_get_real_ts64(&data
->starttod
);
771 data
->dasd_io_reqs
++;
772 data
->dasd_io_sects
+= sectors
;
774 data
->dasd_io_alias
++;
778 data
->dasd_io_secs
[sectors_ind
]++;
779 data
->dasd_io_times
[tottime_ind
]++;
780 data
->dasd_io_timps
[tottimeps_ind
]++;
781 data
->dasd_io_time1
[strtime_ind
]++;
782 data
->dasd_io_time2
[irqtime_ind
]++;
783 data
->dasd_io_time2ps
[irqtimeps_ind
]++;
784 data
->dasd_io_time3
[endtime_ind
]++;
787 data
->dasd_read_reqs
++;
788 data
->dasd_read_sects
+= sectors
;
790 data
->dasd_read_alias
++;
792 data
->dasd_read_tpm
++;
793 data
->dasd_read_secs
[sectors_ind
]++;
794 data
->dasd_read_times
[tottime_ind
]++;
795 data
->dasd_read_time1
[strtime_ind
]++;
796 data
->dasd_read_time2
[irqtime_ind
]++;
797 data
->dasd_read_time3
[endtime_ind
]++;
801 static void dasd_profile_end(struct dasd_block
*block
,
802 struct dasd_ccw_req
*cqr
,
805 unsigned long strtime
, irqtime
, endtime
, tottime
;
806 unsigned long tottimeps
, sectors
;
807 struct dasd_device
*device
;
808 int sectors_ind
, tottime_ind
, tottimeps_ind
, strtime_ind
;
809 int irqtime_ind
, irqtimeps_ind
, endtime_ind
;
810 struct dasd_profile_info
*data
;
812 device
= cqr
->startdev
;
813 if (!(dasd_global_profile_level
||
814 block
->profile
.data
||
815 device
->profile
.data
))
818 sectors
= blk_rq_sectors(req
);
819 if (!cqr
->buildclk
|| !cqr
->startclk
||
820 !cqr
->stopclk
|| !cqr
->endclk
||
824 strtime
= ((cqr
->startclk
- cqr
->buildclk
) >> 12);
825 irqtime
= ((cqr
->stopclk
- cqr
->startclk
) >> 12);
826 endtime
= ((cqr
->endclk
- cqr
->stopclk
) >> 12);
827 tottime
= ((cqr
->endclk
- cqr
->buildclk
) >> 12);
828 tottimeps
= tottime
/ sectors
;
830 dasd_profile_counter(sectors
, sectors_ind
);
831 dasd_profile_counter(tottime
, tottime_ind
);
832 dasd_profile_counter(tottimeps
, tottimeps_ind
);
833 dasd_profile_counter(strtime
, strtime_ind
);
834 dasd_profile_counter(irqtime
, irqtime_ind
);
835 dasd_profile_counter(irqtime
/ sectors
, irqtimeps_ind
);
836 dasd_profile_counter(endtime
, endtime_ind
);
838 spin_lock(&dasd_global_profile
.lock
);
839 if (dasd_global_profile
.data
) {
840 data
= dasd_global_profile
.data
;
841 data
->dasd_sum_times
+= tottime
;
842 data
->dasd_sum_time_str
+= strtime
;
843 data
->dasd_sum_time_irq
+= irqtime
;
844 data
->dasd_sum_time_end
+= endtime
;
845 dasd_profile_end_add_data(dasd_global_profile
.data
,
846 cqr
->startdev
!= block
->base
,
848 rq_data_dir(req
) == READ
,
849 sectors
, sectors_ind
, tottime_ind
,
850 tottimeps_ind
, strtime_ind
,
851 irqtime_ind
, irqtimeps_ind
,
854 spin_unlock(&dasd_global_profile
.lock
);
856 spin_lock(&block
->profile
.lock
);
857 if (block
->profile
.data
) {
858 data
= block
->profile
.data
;
859 data
->dasd_sum_times
+= tottime
;
860 data
->dasd_sum_time_str
+= strtime
;
861 data
->dasd_sum_time_irq
+= irqtime
;
862 data
->dasd_sum_time_end
+= endtime
;
863 dasd_profile_end_add_data(block
->profile
.data
,
864 cqr
->startdev
!= block
->base
,
866 rq_data_dir(req
) == READ
,
867 sectors
, sectors_ind
, tottime_ind
,
868 tottimeps_ind
, strtime_ind
,
869 irqtime_ind
, irqtimeps_ind
,
872 spin_unlock(&block
->profile
.lock
);
874 spin_lock(&device
->profile
.lock
);
875 if (device
->profile
.data
) {
876 data
= device
->profile
.data
;
877 data
->dasd_sum_times
+= tottime
;
878 data
->dasd_sum_time_str
+= strtime
;
879 data
->dasd_sum_time_irq
+= irqtime
;
880 data
->dasd_sum_time_end
+= endtime
;
881 dasd_profile_end_add_data(device
->profile
.data
,
882 cqr
->startdev
!= block
->base
,
884 rq_data_dir(req
) == READ
,
885 sectors
, sectors_ind
, tottime_ind
,
886 tottimeps_ind
, strtime_ind
,
887 irqtime_ind
, irqtimeps_ind
,
890 spin_unlock(&device
->profile
.lock
);
893 void dasd_profile_reset(struct dasd_profile
*profile
)
895 struct dasd_profile_info
*data
;
897 spin_lock_bh(&profile
->lock
);
898 data
= profile
->data
;
900 spin_unlock_bh(&profile
->lock
);
903 memset(data
, 0, sizeof(*data
));
904 ktime_get_real_ts64(&data
->starttod
);
905 spin_unlock_bh(&profile
->lock
);
908 int dasd_profile_on(struct dasd_profile
*profile
)
910 struct dasd_profile_info
*data
;
912 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
915 spin_lock_bh(&profile
->lock
);
917 spin_unlock_bh(&profile
->lock
);
921 ktime_get_real_ts64(&data
->starttod
);
922 profile
->data
= data
;
923 spin_unlock_bh(&profile
->lock
);
927 void dasd_profile_off(struct dasd_profile
*profile
)
929 spin_lock_bh(&profile
->lock
);
930 kfree(profile
->data
);
931 profile
->data
= NULL
;
932 spin_unlock_bh(&profile
->lock
);
935 char *dasd_get_user_string(const char __user
*user_buf
, size_t user_len
)
939 buffer
= vmalloc(user_len
+ 1);
941 return ERR_PTR(-ENOMEM
);
942 if (copy_from_user(buffer
, user_buf
, user_len
) != 0) {
944 return ERR_PTR(-EFAULT
);
946 /* got the string, now strip linefeed. */
947 if (buffer
[user_len
- 1] == '\n')
948 buffer
[user_len
- 1] = 0;
950 buffer
[user_len
] = 0;
954 static ssize_t
dasd_stats_write(struct file
*file
,
955 const char __user
*user_buf
,
956 size_t user_len
, loff_t
*pos
)
960 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
961 struct dasd_profile
*prof
= m
->private;
963 if (user_len
> 65536)
965 buffer
= dasd_get_user_string(user_buf
, user_len
);
967 return PTR_ERR(buffer
);
969 str
= skip_spaces(buffer
);
971 if (strncmp(str
, "reset", 5) == 0) {
972 dasd_profile_reset(prof
);
973 } else if (strncmp(str
, "on", 2) == 0) {
974 rc
= dasd_profile_on(prof
);
978 if (prof
== &dasd_global_profile
) {
979 dasd_profile_reset(prof
);
980 dasd_global_profile_level
= DASD_PROFILE_GLOBAL_ONLY
;
982 } else if (strncmp(str
, "off", 3) == 0) {
983 if (prof
== &dasd_global_profile
)
984 dasd_global_profile_level
= DASD_PROFILE_OFF
;
985 dasd_profile_off(prof
);
993 static void dasd_stats_array(struct seq_file
*m
, unsigned int *array
)
997 for (i
= 0; i
< 32; i
++)
998 seq_printf(m
, "%u ", array
[i
]);
1002 static void dasd_stats_seq_print(struct seq_file
*m
,
1003 struct dasd_profile_info
*data
)
1005 seq_printf(m
, "start_time %lld.%09ld\n",
1006 (s64
)data
->starttod
.tv_sec
, data
->starttod
.tv_nsec
);
1007 seq_printf(m
, "total_requests %u\n", data
->dasd_io_reqs
);
1008 seq_printf(m
, "total_sectors %u\n", data
->dasd_io_sects
);
1009 seq_printf(m
, "total_pav %u\n", data
->dasd_io_alias
);
1010 seq_printf(m
, "total_hpf %u\n", data
->dasd_io_tpm
);
1011 seq_printf(m
, "avg_total %lu\n", data
->dasd_io_reqs
?
1012 data
->dasd_sum_times
/ data
->dasd_io_reqs
: 0UL);
1013 seq_printf(m
, "avg_build_to_ssch %lu\n", data
->dasd_io_reqs
?
1014 data
->dasd_sum_time_str
/ data
->dasd_io_reqs
: 0UL);
1015 seq_printf(m
, "avg_ssch_to_irq %lu\n", data
->dasd_io_reqs
?
1016 data
->dasd_sum_time_irq
/ data
->dasd_io_reqs
: 0UL);
1017 seq_printf(m
, "avg_irq_to_end %lu\n", data
->dasd_io_reqs
?
1018 data
->dasd_sum_time_end
/ data
->dasd_io_reqs
: 0UL);
1019 seq_puts(m
, "histogram_sectors ");
1020 dasd_stats_array(m
, data
->dasd_io_secs
);
1021 seq_puts(m
, "histogram_io_times ");
1022 dasd_stats_array(m
, data
->dasd_io_times
);
1023 seq_puts(m
, "histogram_io_times_weighted ");
1024 dasd_stats_array(m
, data
->dasd_io_timps
);
1025 seq_puts(m
, "histogram_time_build_to_ssch ");
1026 dasd_stats_array(m
, data
->dasd_io_time1
);
1027 seq_puts(m
, "histogram_time_ssch_to_irq ");
1028 dasd_stats_array(m
, data
->dasd_io_time2
);
1029 seq_puts(m
, "histogram_time_ssch_to_irq_weighted ");
1030 dasd_stats_array(m
, data
->dasd_io_time2ps
);
1031 seq_puts(m
, "histogram_time_irq_to_end ");
1032 dasd_stats_array(m
, data
->dasd_io_time3
);
1033 seq_puts(m
, "histogram_ccw_queue_length ");
1034 dasd_stats_array(m
, data
->dasd_io_nr_req
);
1035 seq_printf(m
, "total_read_requests %u\n", data
->dasd_read_reqs
);
1036 seq_printf(m
, "total_read_sectors %u\n", data
->dasd_read_sects
);
1037 seq_printf(m
, "total_read_pav %u\n", data
->dasd_read_alias
);
1038 seq_printf(m
, "total_read_hpf %u\n", data
->dasd_read_tpm
);
1039 seq_puts(m
, "histogram_read_sectors ");
1040 dasd_stats_array(m
, data
->dasd_read_secs
);
1041 seq_puts(m
, "histogram_read_times ");
1042 dasd_stats_array(m
, data
->dasd_read_times
);
1043 seq_puts(m
, "histogram_read_time_build_to_ssch ");
1044 dasd_stats_array(m
, data
->dasd_read_time1
);
1045 seq_puts(m
, "histogram_read_time_ssch_to_irq ");
1046 dasd_stats_array(m
, data
->dasd_read_time2
);
1047 seq_puts(m
, "histogram_read_time_irq_to_end ");
1048 dasd_stats_array(m
, data
->dasd_read_time3
);
1049 seq_puts(m
, "histogram_read_ccw_queue_length ");
1050 dasd_stats_array(m
, data
->dasd_read_nr_req
);
1053 static int dasd_stats_show(struct seq_file
*m
, void *v
)
1055 struct dasd_profile
*profile
;
1056 struct dasd_profile_info
*data
;
1058 profile
= m
->private;
1059 spin_lock_bh(&profile
->lock
);
1060 data
= profile
->data
;
1062 spin_unlock_bh(&profile
->lock
);
1063 seq_puts(m
, "disabled\n");
1066 dasd_stats_seq_print(m
, data
);
1067 spin_unlock_bh(&profile
->lock
);
1071 static int dasd_stats_open(struct inode
*inode
, struct file
*file
)
1073 struct dasd_profile
*profile
= inode
->i_private
;
1074 return single_open(file
, dasd_stats_show
, profile
);
1077 static const struct file_operations dasd_stats_raw_fops
= {
1078 .owner
= THIS_MODULE
,
1079 .open
= dasd_stats_open
,
1081 .llseek
= seq_lseek
,
1082 .release
= single_release
,
1083 .write
= dasd_stats_write
,
1086 static void dasd_profile_init(struct dasd_profile
*profile
,
1087 struct dentry
*base_dentry
)
1094 profile
->dentry
= NULL
;
1095 profile
->data
= NULL
;
1096 mode
= (S_IRUSR
| S_IWUSR
| S_IFREG
);
1097 pde
= debugfs_create_file("statistics", mode
, base_dentry
,
1098 profile
, &dasd_stats_raw_fops
);
1099 if (pde
&& !IS_ERR(pde
))
1100 profile
->dentry
= pde
;
1104 static void dasd_profile_exit(struct dasd_profile
*profile
)
1106 dasd_profile_off(profile
);
1107 debugfs_remove(profile
->dentry
);
1108 profile
->dentry
= NULL
;
1111 static void dasd_statistics_removeroot(void)
1113 dasd_global_profile_level
= DASD_PROFILE_OFF
;
1114 dasd_profile_exit(&dasd_global_profile
);
1115 debugfs_remove(dasd_debugfs_global_entry
);
1116 debugfs_remove(dasd_debugfs_root_entry
);
1119 static void dasd_statistics_createroot(void)
1123 dasd_debugfs_root_entry
= NULL
;
1124 pde
= debugfs_create_dir("dasd", NULL
);
1125 if (!pde
|| IS_ERR(pde
))
1127 dasd_debugfs_root_entry
= pde
;
1128 pde
= debugfs_create_dir("global", dasd_debugfs_root_entry
);
1129 if (!pde
|| IS_ERR(pde
))
1131 dasd_debugfs_global_entry
= pde
;
1132 dasd_profile_init(&dasd_global_profile
, dasd_debugfs_global_entry
);
1136 DBF_EVENT(DBF_ERR
, "%s",
1137 "Creation of the dasd debugfs interface failed");
1138 dasd_statistics_removeroot();
1143 #define dasd_profile_start(block, cqr, req) do {} while (0)
1144 #define dasd_profile_end(block, cqr, req) do {} while (0)
1146 static void dasd_statistics_createroot(void)
1151 static void dasd_statistics_removeroot(void)
1156 int dasd_stats_generic_show(struct seq_file
*m
, void *v
)
1158 seq_puts(m
, "Statistics are not activated in this kernel\n");
1162 static void dasd_profile_init(struct dasd_profile
*profile
,
1163 struct dentry
*base_dentry
)
1168 static void dasd_profile_exit(struct dasd_profile
*profile
)
1173 int dasd_profile_on(struct dasd_profile
*profile
)
1178 #endif /* CONFIG_DASD_PROFILE */
1180 static int dasd_hosts_show(struct seq_file
*m
, void *v
)
1182 struct dasd_device
*device
;
1183 int rc
= -EOPNOTSUPP
;
1185 device
= m
->private;
1186 dasd_get_device(device
);
1188 if (device
->discipline
->hosts_print
)
1189 rc
= device
->discipline
->hosts_print(device
, m
);
1191 dasd_put_device(device
);
1195 static int dasd_hosts_open(struct inode
*inode
, struct file
*file
)
1197 struct dasd_device
*device
= inode
->i_private
;
1199 return single_open(file
, dasd_hosts_show
, device
);
1202 static const struct file_operations dasd_hosts_fops
= {
1203 .owner
= THIS_MODULE
,
1204 .open
= dasd_hosts_open
,
1206 .llseek
= seq_lseek
,
1207 .release
= single_release
,
1210 static void dasd_hosts_exit(struct dasd_device
*device
)
1212 debugfs_remove(device
->hosts_dentry
);
1213 device
->hosts_dentry
= NULL
;
1216 static void dasd_hosts_init(struct dentry
*base_dentry
,
1217 struct dasd_device
*device
)
1225 mode
= S_IRUSR
| S_IFREG
;
1226 pde
= debugfs_create_file("host_access_list", mode
, base_dentry
,
1227 device
, &dasd_hosts_fops
);
1228 if (pde
&& !IS_ERR(pde
))
1229 device
->hosts_dentry
= pde
;
1232 struct dasd_ccw_req
*dasd_smalloc_request(int magic
, int cplength
, int datasize
,
1233 struct dasd_device
*device
,
1234 struct dasd_ccw_req
*cqr
)
1236 unsigned long flags
;
1241 size
+= cplength
* sizeof(struct ccw1
);
1245 size
+= (sizeof(*cqr
) + 7L) & -8L;
1247 spin_lock_irqsave(&device
->mem_lock
, flags
);
1248 data
= chunk
= dasd_alloc_chunk(&device
->ccw_chunks
, size
);
1249 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
1251 return ERR_PTR(-ENOMEM
);
1253 cqr
= (void *) data
;
1254 data
+= (sizeof(*cqr
) + 7L) & -8L;
1256 memset(cqr
, 0, sizeof(*cqr
));
1257 cqr
->mem_chunk
= chunk
;
1260 data
+= cplength
* sizeof(struct ccw1
);
1261 memset(cqr
->cpaddr
, 0, cplength
* sizeof(struct ccw1
));
1265 memset(cqr
->data
, 0, datasize
);
1268 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1269 dasd_get_device(device
);
1272 EXPORT_SYMBOL(dasd_smalloc_request
);
1274 void dasd_sfree_request(struct dasd_ccw_req
*cqr
, struct dasd_device
*device
)
1276 unsigned long flags
;
1278 spin_lock_irqsave(&device
->mem_lock
, flags
);
1279 dasd_free_chunk(&device
->ccw_chunks
, cqr
->mem_chunk
);
1280 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
1281 dasd_put_device(device
);
1283 EXPORT_SYMBOL(dasd_sfree_request
);
1286 * Check discipline magic in cqr.
1288 static inline int dasd_check_cqr(struct dasd_ccw_req
*cqr
)
1290 struct dasd_device
*device
;
1294 device
= cqr
->startdev
;
1295 if (strncmp((char *) &cqr
->magic
, device
->discipline
->ebcname
, 4)) {
1296 DBF_DEV_EVENT(DBF_WARNING
, device
,
1297 " dasd_ccw_req 0x%08x magic doesn't match"
1298 " discipline 0x%08x",
1300 *(unsigned int *) device
->discipline
->name
);
1307 * Terminate the current i/o and set the request to clear_pending.
1308 * Timer keeps device runnig.
1309 * ccw_device_clear can fail if the i/o subsystem
1312 int dasd_term_IO(struct dasd_ccw_req
*cqr
)
1314 struct dasd_device
*device
;
1316 char errorstring
[ERRORLENGTH
];
1319 rc
= dasd_check_cqr(cqr
);
1323 device
= (struct dasd_device
*) cqr
->startdev
;
1324 while ((retries
< 5) && (cqr
->status
== DASD_CQR_IN_IO
)) {
1325 rc
= ccw_device_clear(device
->cdev
, (long) cqr
);
1327 case 0: /* termination successful */
1328 cqr
->status
= DASD_CQR_CLEAR_PENDING
;
1329 cqr
->stopclk
= get_tod_clock();
1331 DBF_DEV_EVENT(DBF_DEBUG
, device
,
1332 "terminate cqr %p successful",
1336 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1337 "device gone, retry");
1341 * device not valid so no I/O could be running
1342 * handle CQR as termination successful
1344 cqr
->status
= DASD_CQR_CLEARED
;
1345 cqr
->stopclk
= get_tod_clock();
1347 /* no retries for invalid devices */
1349 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1350 "EINVAL, handle as terminated");
1351 /* fake rc to success */
1355 /* internal error 10 - unknown rc*/
1356 snprintf(errorstring
, ERRORLENGTH
, "10 %d", rc
);
1357 dev_err(&device
->cdev
->dev
, "An error occurred in the "
1358 "DASD device driver, reason=%s\n", errorstring
);
1364 dasd_schedule_device_bh(device
);
1367 EXPORT_SYMBOL(dasd_term_IO
);
1370 * Start the i/o. This start_IO can fail if the channel is really busy.
1371 * In that case set up a timer to start the request later.
1373 int dasd_start_IO(struct dasd_ccw_req
*cqr
)
1375 struct dasd_device
*device
;
1377 char errorstring
[ERRORLENGTH
];
1380 rc
= dasd_check_cqr(cqr
);
1385 device
= (struct dasd_device
*) cqr
->startdev
;
1387 test_bit(DASD_FLAG_LOCK_STOLEN
, &cqr
->block
->base
->flags
)) ||
1388 test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
)) &&
1389 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
1390 DBF_DEV_EVENT(DBF_DEBUG
, device
, "start_IO: return request %p "
1391 "because of stolen lock", cqr
);
1392 cqr
->status
= DASD_CQR_ERROR
;
1393 cqr
->intrc
= -EPERM
;
1396 if (cqr
->retries
< 0) {
1397 /* internal error 14 - start_IO run out of retries */
1398 sprintf(errorstring
, "14 %p", cqr
);
1399 dev_err(&device
->cdev
->dev
, "An error occurred in the DASD "
1400 "device driver, reason=%s\n", errorstring
);
1401 cqr
->status
= DASD_CQR_ERROR
;
1404 cqr
->startclk
= get_tod_clock();
1405 cqr
->starttime
= jiffies
;
1407 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1408 cqr
->lpm
&= dasd_path_get_opm(device
);
1410 cqr
->lpm
= dasd_path_get_opm(device
);
1412 if (cqr
->cpmode
== 1) {
1413 rc
= ccw_device_tm_start(device
->cdev
, cqr
->cpaddr
,
1414 (long) cqr
, cqr
->lpm
);
1416 rc
= ccw_device_start(device
->cdev
, cqr
->cpaddr
,
1417 (long) cqr
, cqr
->lpm
, 0);
1421 cqr
->status
= DASD_CQR_IN_IO
;
1424 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1425 "start_IO: device busy, retry later");
1428 /* -EACCES indicates that the request used only a subset of the
1429 * available paths and all these paths are gone. If the lpm of
1430 * this request was only a subset of the opm (e.g. the ppm) then
1431 * we just do a retry with all available paths.
1432 * If we already use the full opm, something is amiss, and we
1433 * need a full path verification.
1435 if (test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1436 DBF_DEV_EVENT(DBF_WARNING
, device
,
1437 "start_IO: selected paths gone (%x)",
1439 } else if (cqr
->lpm
!= dasd_path_get_opm(device
)) {
1440 cqr
->lpm
= dasd_path_get_opm(device
);
1441 DBF_DEV_EVENT(DBF_DEBUG
, device
, "%s",
1442 "start_IO: selected paths gone,"
1443 " retry on all paths");
1445 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1446 "start_IO: all paths in opm gone,"
1447 " do path verification");
1448 dasd_generic_last_path_gone(device
);
1449 dasd_path_no_path(device
);
1450 dasd_path_set_tbvpm(device
,
1451 ccw_device_get_path_mask(
1456 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1457 "start_IO: -ENODEV device gone, retry");
1460 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1461 "start_IO: -EIO device gone, retry");
1464 /* most likely caused in power management context */
1465 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1466 "start_IO: -EINVAL device currently "
1470 /* internal error 11 - unknown rc */
1471 snprintf(errorstring
, ERRORLENGTH
, "11 %d", rc
);
1472 dev_err(&device
->cdev
->dev
,
1473 "An error occurred in the DASD device driver, "
1474 "reason=%s\n", errorstring
);
1481 EXPORT_SYMBOL(dasd_start_IO
);
1484 * Timeout function for dasd devices. This is used for different purposes
1485 * 1) missing interrupt handler for normal operation
1486 * 2) delayed start of request where start_IO failed with -EBUSY
1487 * 3) timeout for missing state change interrupts
1488 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1489 * DASD_CQR_QUEUED for 2) and 3).
1491 static void dasd_device_timeout(struct timer_list
*t
)
1493 unsigned long flags
;
1494 struct dasd_device
*device
;
1496 device
= from_timer(device
, t
, timer
);
1497 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1498 /* re-activate request queue */
1499 dasd_device_remove_stop_bits(device
, DASD_STOPPED_PENDING
);
1500 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1501 dasd_schedule_device_bh(device
);
1505 * Setup timeout for a device in jiffies.
1507 void dasd_device_set_timer(struct dasd_device
*device
, int expires
)
1510 del_timer(&device
->timer
);
1512 mod_timer(&device
->timer
, jiffies
+ expires
);
1514 EXPORT_SYMBOL(dasd_device_set_timer
);
1517 * Clear timeout for a device.
1519 void dasd_device_clear_timer(struct dasd_device
*device
)
1521 del_timer(&device
->timer
);
1523 EXPORT_SYMBOL(dasd_device_clear_timer
);
1525 static void dasd_handle_killed_request(struct ccw_device
*cdev
,
1526 unsigned long intparm
)
1528 struct dasd_ccw_req
*cqr
;
1529 struct dasd_device
*device
;
1533 cqr
= (struct dasd_ccw_req
*) intparm
;
1534 if (cqr
->status
!= DASD_CQR_IN_IO
) {
1535 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
,
1536 "invalid status in handle_killed_request: "
1537 "%02x", cqr
->status
);
1541 device
= dasd_device_from_cdev_locked(cdev
);
1542 if (IS_ERR(device
)) {
1543 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1544 "unable to get device from cdev");
1548 if (!cqr
->startdev
||
1549 device
!= cqr
->startdev
||
1550 strncmp(cqr
->startdev
->discipline
->ebcname
,
1551 (char *) &cqr
->magic
, 4)) {
1552 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1553 "invalid device in request");
1554 dasd_put_device(device
);
1558 /* Schedule request to be retried. */
1559 cqr
->status
= DASD_CQR_QUEUED
;
1561 dasd_device_clear_timer(device
);
1562 dasd_schedule_device_bh(device
);
1563 dasd_put_device(device
);
1566 void dasd_generic_handle_state_change(struct dasd_device
*device
)
1568 /* First of all start sense subsystem status request. */
1569 dasd_eer_snss(device
);
1571 dasd_device_remove_stop_bits(device
, DASD_STOPPED_PENDING
);
1572 dasd_schedule_device_bh(device
);
1573 if (device
->block
) {
1574 dasd_schedule_block_bh(device
->block
);
1575 if (device
->block
->request_queue
)
1576 blk_mq_run_hw_queues(device
->block
->request_queue
,
1580 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change
);
1582 static int dasd_check_hpf_error(struct irb
*irb
)
1584 return (scsw_tm_is_valid_schxs(&irb
->scsw
) &&
1585 (irb
->scsw
.tm
.sesq
== SCSW_SESQ_DEV_NOFCX
||
1586 irb
->scsw
.tm
.sesq
== SCSW_SESQ_PATH_NOFCX
));
1590 * Interrupt handler for "normal" ssch-io based dasd devices.
1592 void dasd_int_handler(struct ccw_device
*cdev
, unsigned long intparm
,
1595 struct dasd_ccw_req
*cqr
, *next
;
1596 struct dasd_device
*device
;
1598 int nrf_suppressed
= 0;
1599 int fp_suppressed
= 0;
1603 cqr
= (struct dasd_ccw_req
*) intparm
;
1605 switch (PTR_ERR(irb
)) {
1607 if (cqr
&& cqr
->status
== DASD_CQR_CLEAR_PENDING
) {
1608 device
= cqr
->startdev
;
1609 cqr
->status
= DASD_CQR_CLEARED
;
1610 dasd_device_clear_timer(device
);
1611 wake_up(&dasd_flush_wq
);
1612 dasd_schedule_device_bh(device
);
1617 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s: "
1618 "request timed out\n", __func__
);
1621 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s: "
1622 "unknown error %ld\n", __func__
,
1625 dasd_handle_killed_request(cdev
, intparm
);
1629 now
= get_tod_clock();
1630 /* check for conditions that should be handled immediately */
1632 !(scsw_dstat(&irb
->scsw
) == (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
) &&
1633 scsw_cstat(&irb
->scsw
) == 0)) {
1635 memcpy(&cqr
->irb
, irb
, sizeof(*irb
));
1636 device
= dasd_device_from_cdev_locked(cdev
);
1639 /* ignore unsolicited interrupts for DIAG discipline */
1640 if (device
->discipline
== dasd_diag_discipline_pointer
) {
1641 dasd_put_device(device
);
1646 * In some cases 'File Protected' or 'No Record Found' errors
1647 * might be expected and debug log messages for the
1648 * corresponding interrupts shouldn't be written then.
1649 * Check if either of the according suppress bits is set.
1651 sense
= dasd_get_sense(irb
);
1653 fp_suppressed
= (sense
[1] & SNS1_FILE_PROTECTED
) &&
1654 test_bit(DASD_CQR_SUPPRESS_FP
, &cqr
->flags
);
1655 nrf_suppressed
= (sense
[1] & SNS1_NO_REC_FOUND
) &&
1656 test_bit(DASD_CQR_SUPPRESS_NRF
, &cqr
->flags
);
1658 if (!(fp_suppressed
|| nrf_suppressed
))
1659 device
->discipline
->dump_sense_dbf(device
, irb
, "int");
1661 if (device
->features
& DASD_FEATURE_ERPLOG
)
1662 device
->discipline
->dump_sense(device
, cqr
, irb
);
1663 device
->discipline
->check_for_device_change(device
, cqr
, irb
);
1664 dasd_put_device(device
);
1667 /* check for for attention message */
1668 if (scsw_dstat(&irb
->scsw
) & DEV_STAT_ATTENTION
) {
1669 device
= dasd_device_from_cdev_locked(cdev
);
1670 if (!IS_ERR(device
)) {
1671 device
->discipline
->check_attention(device
,
1672 irb
->esw
.esw1
.lpum
);
1673 dasd_put_device(device
);
1680 device
= (struct dasd_device
*) cqr
->startdev
;
1682 strncmp(device
->discipline
->ebcname
, (char *) &cqr
->magic
, 4)) {
1683 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1684 "invalid device in request");
1688 /* Check for clear pending */
1689 if (cqr
->status
== DASD_CQR_CLEAR_PENDING
&&
1690 scsw_fctl(&irb
->scsw
) & SCSW_FCTL_CLEAR_FUNC
) {
1691 cqr
->status
= DASD_CQR_CLEARED
;
1692 dasd_device_clear_timer(device
);
1693 wake_up(&dasd_flush_wq
);
1694 dasd_schedule_device_bh(device
);
1698 /* check status - the request might have been killed by dyn detach */
1699 if (cqr
->status
!= DASD_CQR_IN_IO
) {
1700 DBF_DEV_EVENT(DBF_DEBUG
, device
, "invalid status: bus_id %s, "
1701 "status %02x", dev_name(&cdev
->dev
), cqr
->status
);
1707 if (scsw_dstat(&irb
->scsw
) == (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
) &&
1708 scsw_cstat(&irb
->scsw
) == 0) {
1709 /* request was completed successfully */
1710 cqr
->status
= DASD_CQR_SUCCESS
;
1712 /* Start first request on queue if possible -> fast_io. */
1713 if (cqr
->devlist
.next
!= &device
->ccw_queue
) {
1714 next
= list_entry(cqr
->devlist
.next
,
1715 struct dasd_ccw_req
, devlist
);
1717 } else { /* error */
1718 /* check for HPF error
1719 * call discipline function to requeue all requests
1720 * and disable HPF accordingly
1722 if (cqr
->cpmode
&& dasd_check_hpf_error(irb
) &&
1723 device
->discipline
->handle_hpf_error
)
1724 device
->discipline
->handle_hpf_error(device
, irb
);
1726 * If we don't want complex ERP for this request, then just
1727 * reset this and retry it in the fastpath
1729 if (!test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
) &&
1731 if (cqr
->lpm
== dasd_path_get_opm(device
))
1732 DBF_DEV_EVENT(DBF_DEBUG
, device
,
1733 "default ERP in fastpath "
1734 "(%i retries left)",
1736 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
))
1737 cqr
->lpm
= dasd_path_get_opm(device
);
1738 cqr
->status
= DASD_CQR_QUEUED
;
1741 cqr
->status
= DASD_CQR_ERROR
;
1743 if (next
&& (next
->status
== DASD_CQR_QUEUED
) &&
1744 (!device
->stopped
)) {
1745 if (device
->discipline
->start_IO(next
) == 0)
1746 expires
= next
->expires
;
1749 dasd_device_set_timer(device
, expires
);
1751 dasd_device_clear_timer(device
);
1752 dasd_schedule_device_bh(device
);
1754 EXPORT_SYMBOL(dasd_int_handler
);
1756 enum uc_todo
dasd_generic_uc_handler(struct ccw_device
*cdev
, struct irb
*irb
)
1758 struct dasd_device
*device
;
1760 device
= dasd_device_from_cdev_locked(cdev
);
1764 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
1765 device
->state
!= device
->target
||
1766 !device
->discipline
->check_for_device_change
){
1767 dasd_put_device(device
);
1770 if (device
->discipline
->dump_sense_dbf
)
1771 device
->discipline
->dump_sense_dbf(device
, irb
, "uc");
1772 device
->discipline
->check_for_device_change(device
, NULL
, irb
);
1773 dasd_put_device(device
);
1775 return UC_TODO_RETRY
;
1777 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler
);
1780 * If we have an error on a dasd_block layer request then we cancel
1781 * and return all further requests from the same dasd_block as well.
1783 static void __dasd_device_recovery(struct dasd_device
*device
,
1784 struct dasd_ccw_req
*ref_cqr
)
1786 struct list_head
*l
, *n
;
1787 struct dasd_ccw_req
*cqr
;
1790 * only requeue request that came from the dasd_block layer
1792 if (!ref_cqr
->block
)
1795 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1796 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1797 if (cqr
->status
== DASD_CQR_QUEUED
&&
1798 ref_cqr
->block
== cqr
->block
) {
1799 cqr
->status
= DASD_CQR_CLEARED
;
1805 * Remove those ccw requests from the queue that need to be returned
1806 * to the upper layer.
1808 static void __dasd_device_process_ccw_queue(struct dasd_device
*device
,
1809 struct list_head
*final_queue
)
1811 struct list_head
*l
, *n
;
1812 struct dasd_ccw_req
*cqr
;
1814 /* Process request with final status. */
1815 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1816 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1818 /* Skip any non-final request. */
1819 if (cqr
->status
== DASD_CQR_QUEUED
||
1820 cqr
->status
== DASD_CQR_IN_IO
||
1821 cqr
->status
== DASD_CQR_CLEAR_PENDING
)
1823 if (cqr
->status
== DASD_CQR_ERROR
) {
1824 __dasd_device_recovery(device
, cqr
);
1826 /* Rechain finished requests to final queue */
1827 list_move_tail(&cqr
->devlist
, final_queue
);
1831 static void __dasd_process_cqr(struct dasd_device
*device
,
1832 struct dasd_ccw_req
*cqr
)
1834 char errorstring
[ERRORLENGTH
];
1836 switch (cqr
->status
) {
1837 case DASD_CQR_SUCCESS
:
1838 cqr
->status
= DASD_CQR_DONE
;
1840 case DASD_CQR_ERROR
:
1841 cqr
->status
= DASD_CQR_NEED_ERP
;
1843 case DASD_CQR_CLEARED
:
1844 cqr
->status
= DASD_CQR_TERMINATED
;
1847 /* internal error 12 - wrong cqr status*/
1848 snprintf(errorstring
, ERRORLENGTH
, "12 %p %x02", cqr
, cqr
->status
);
1849 dev_err(&device
->cdev
->dev
,
1850 "An error occurred in the DASD device driver, "
1851 "reason=%s\n", errorstring
);
1855 cqr
->callback(cqr
, cqr
->callback_data
);
1859 * the cqrs from the final queue are returned to the upper layer
1860 * by setting a dasd_block state and calling the callback function
1862 static void __dasd_device_process_final_queue(struct dasd_device
*device
,
1863 struct list_head
*final_queue
)
1865 struct list_head
*l
, *n
;
1866 struct dasd_ccw_req
*cqr
;
1867 struct dasd_block
*block
;
1869 list_for_each_safe(l
, n
, final_queue
) {
1870 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1871 list_del_init(&cqr
->devlist
);
1874 __dasd_process_cqr(device
, cqr
);
1876 spin_lock_bh(&block
->queue_lock
);
1877 __dasd_process_cqr(device
, cqr
);
1878 spin_unlock_bh(&block
->queue_lock
);
1884 * Take a look at the first request on the ccw queue and check
1885 * if it reached its expire time. If so, terminate the IO.
1887 static void __dasd_device_check_expire(struct dasd_device
*device
)
1889 struct dasd_ccw_req
*cqr
;
1891 if (list_empty(&device
->ccw_queue
))
1893 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
1894 if ((cqr
->status
== DASD_CQR_IN_IO
&& cqr
->expires
!= 0) &&
1895 (time_after_eq(jiffies
, cqr
->expires
+ cqr
->starttime
))) {
1896 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
1898 * IO in safe offline processing should not
1899 * run out of retries
1903 if (device
->discipline
->term_IO(cqr
) != 0) {
1904 /* Hmpf, try again in 5 sec */
1905 dev_err(&device
->cdev
->dev
,
1906 "cqr %p timed out (%lus) but cannot be "
1907 "ended, retrying in 5 s\n",
1908 cqr
, (cqr
->expires
/HZ
));
1909 cqr
->expires
+= 5*HZ
;
1910 dasd_device_set_timer(device
, 5*HZ
);
1912 dev_err(&device
->cdev
->dev
,
1913 "cqr %p timed out (%lus), %i retries "
1914 "remaining\n", cqr
, (cqr
->expires
/HZ
),
1921 * return 1 when device is not eligible for IO
1923 static int __dasd_device_is_unusable(struct dasd_device
*device
,
1924 struct dasd_ccw_req
*cqr
)
1926 int mask
= ~(DASD_STOPPED_DC_WAIT
| DASD_UNRESUMED_PM
);
1928 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
1929 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
1931 * dasd is being set offline
1932 * but it is no safe offline where we have to allow I/O
1936 if (device
->stopped
) {
1937 if (device
->stopped
& mask
) {
1938 /* stopped and CQR will not change that. */
1941 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1942 /* CQR is not able to change device to
1946 /* CQR required to get device operational. */
1952 * Take a look at the first request on the ccw queue and check
1953 * if it needs to be started.
1955 static void __dasd_device_start_head(struct dasd_device
*device
)
1957 struct dasd_ccw_req
*cqr
;
1960 if (list_empty(&device
->ccw_queue
))
1962 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
1963 if (cqr
->status
!= DASD_CQR_QUEUED
)
1965 /* if device is not usable return request to upper layer */
1966 if (__dasd_device_is_unusable(device
, cqr
)) {
1967 cqr
->intrc
= -EAGAIN
;
1968 cqr
->status
= DASD_CQR_CLEARED
;
1969 dasd_schedule_device_bh(device
);
1973 rc
= device
->discipline
->start_IO(cqr
);
1975 dasd_device_set_timer(device
, cqr
->expires
);
1976 else if (rc
== -EACCES
) {
1977 dasd_schedule_device_bh(device
);
1979 /* Hmpf, try again in 1/2 sec */
1980 dasd_device_set_timer(device
, 50);
1983 static void __dasd_device_check_path_events(struct dasd_device
*device
)
1987 if (!dasd_path_get_tbvpm(device
))
1990 if (device
->stopped
&
1991 ~(DASD_STOPPED_DC_WAIT
| DASD_UNRESUMED_PM
))
1993 rc
= device
->discipline
->verify_path(device
,
1994 dasd_path_get_tbvpm(device
));
1996 dasd_device_set_timer(device
, 50);
1998 dasd_path_clear_all_verify(device
);
2002 * Go through all request on the dasd_device request queue,
2003 * terminate them on the cdev if necessary, and return them to the
2004 * submitting layer via callback.
2006 * Make sure that all 'submitting layers' still exist when
2007 * this function is called!. In other words, when 'device' is a base
2008 * device then all block layer requests must have been removed before
2009 * via dasd_flush_block_queue.
2011 int dasd_flush_device_queue(struct dasd_device
*device
)
2013 struct dasd_ccw_req
*cqr
, *n
;
2015 struct list_head flush_queue
;
2017 INIT_LIST_HEAD(&flush_queue
);
2018 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2020 list_for_each_entry_safe(cqr
, n
, &device
->ccw_queue
, devlist
) {
2021 /* Check status and move request to flush_queue */
2022 switch (cqr
->status
) {
2023 case DASD_CQR_IN_IO
:
2024 rc
= device
->discipline
->term_IO(cqr
);
2026 /* unable to terminate requeust */
2027 dev_err(&device
->cdev
->dev
,
2028 "Flushing the DASD request queue "
2029 "failed for request %p\n", cqr
);
2030 /* stop flush processing */
2034 case DASD_CQR_QUEUED
:
2035 cqr
->stopclk
= get_tod_clock();
2036 cqr
->status
= DASD_CQR_CLEARED
;
2038 default: /* no need to modify the others */
2041 list_move_tail(&cqr
->devlist
, &flush_queue
);
2044 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2046 * After this point all requests must be in state CLEAR_PENDING,
2047 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2048 * one of the others.
2050 list_for_each_entry_safe(cqr
, n
, &flush_queue
, devlist
)
2051 wait_event(dasd_flush_wq
,
2052 (cqr
->status
!= DASD_CQR_CLEAR_PENDING
));
2054 * Now set each request back to TERMINATED, DONE or NEED_ERP
2055 * and call the callback function of flushed requests
2057 __dasd_device_process_final_queue(device
, &flush_queue
);
2060 EXPORT_SYMBOL_GPL(dasd_flush_device_queue
);
2063 * Acquire the device lock and process queues for the device.
2065 static void dasd_device_tasklet(unsigned long data
)
2067 struct dasd_device
*device
= (struct dasd_device
*) data
;
2068 struct list_head final_queue
;
2070 atomic_set (&device
->tasklet_scheduled
, 0);
2071 INIT_LIST_HEAD(&final_queue
);
2072 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2073 /* Check expire time of first request on the ccw queue. */
2074 __dasd_device_check_expire(device
);
2075 /* find final requests on ccw queue */
2076 __dasd_device_process_ccw_queue(device
, &final_queue
);
2077 __dasd_device_check_path_events(device
);
2078 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2079 /* Now call the callback function of requests with final status */
2080 __dasd_device_process_final_queue(device
, &final_queue
);
2081 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2082 /* Now check if the head of the ccw queue needs to be started. */
2083 __dasd_device_start_head(device
);
2084 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2085 if (waitqueue_active(&shutdown_waitq
))
2086 wake_up(&shutdown_waitq
);
2087 dasd_put_device(device
);
2091 * Schedules a call to dasd_tasklet over the device tasklet.
2093 void dasd_schedule_device_bh(struct dasd_device
*device
)
2095 /* Protect against rescheduling. */
2096 if (atomic_cmpxchg (&device
->tasklet_scheduled
, 0, 1) != 0)
2098 dasd_get_device(device
);
2099 tasklet_hi_schedule(&device
->tasklet
);
2101 EXPORT_SYMBOL(dasd_schedule_device_bh
);
2103 void dasd_device_set_stop_bits(struct dasd_device
*device
, int bits
)
2105 device
->stopped
|= bits
;
2107 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits
);
2109 void dasd_device_remove_stop_bits(struct dasd_device
*device
, int bits
)
2111 device
->stopped
&= ~bits
;
2112 if (!device
->stopped
)
2113 wake_up(&generic_waitq
);
2115 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits
);
2118 * Queue a request to the head of the device ccw_queue.
2119 * Start the I/O if possible.
2121 void dasd_add_request_head(struct dasd_ccw_req
*cqr
)
2123 struct dasd_device
*device
;
2124 unsigned long flags
;
2126 device
= cqr
->startdev
;
2127 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2128 cqr
->status
= DASD_CQR_QUEUED
;
2129 list_add(&cqr
->devlist
, &device
->ccw_queue
);
2130 /* let the bh start the request to keep them in order */
2131 dasd_schedule_device_bh(device
);
2132 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2134 EXPORT_SYMBOL(dasd_add_request_head
);
2137 * Queue a request to the tail of the device ccw_queue.
2138 * Start the I/O if possible.
2140 void dasd_add_request_tail(struct dasd_ccw_req
*cqr
)
2142 struct dasd_device
*device
;
2143 unsigned long flags
;
2145 device
= cqr
->startdev
;
2146 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2147 cqr
->status
= DASD_CQR_QUEUED
;
2148 list_add_tail(&cqr
->devlist
, &device
->ccw_queue
);
2149 /* let the bh start the request to keep them in order */
2150 dasd_schedule_device_bh(device
);
2151 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2153 EXPORT_SYMBOL(dasd_add_request_tail
);
2156 * Wakeup helper for the 'sleep_on' functions.
2158 void dasd_wakeup_cb(struct dasd_ccw_req
*cqr
, void *data
)
2160 spin_lock_irq(get_ccwdev_lock(cqr
->startdev
->cdev
));
2161 cqr
->callback_data
= DASD_SLEEPON_END_TAG
;
2162 spin_unlock_irq(get_ccwdev_lock(cqr
->startdev
->cdev
));
2163 wake_up(&generic_waitq
);
2165 EXPORT_SYMBOL_GPL(dasd_wakeup_cb
);
2167 static inline int _wait_for_wakeup(struct dasd_ccw_req
*cqr
)
2169 struct dasd_device
*device
;
2172 device
= cqr
->startdev
;
2173 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2174 rc
= (cqr
->callback_data
== DASD_SLEEPON_END_TAG
);
2175 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2180 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2182 static int __dasd_sleep_on_erp(struct dasd_ccw_req
*cqr
)
2184 struct dasd_device
*device
;
2185 dasd_erp_fn_t erp_fn
;
2187 if (cqr
->status
== DASD_CQR_FILLED
)
2189 device
= cqr
->startdev
;
2190 if (test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
)) {
2191 if (cqr
->status
== DASD_CQR_TERMINATED
) {
2192 device
->discipline
->handle_terminated_request(cqr
);
2195 if (cqr
->status
== DASD_CQR_NEED_ERP
) {
2196 erp_fn
= device
->discipline
->erp_action(cqr
);
2200 if (cqr
->status
== DASD_CQR_FAILED
)
2201 dasd_log_sense(cqr
, &cqr
->irb
);
2203 __dasd_process_erp(device
, cqr
);
2210 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req
*cqr
)
2212 if (test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
)) {
2213 if (cqr
->refers
) /* erp is not done yet */
2215 return ((cqr
->status
!= DASD_CQR_DONE
) &&
2216 (cqr
->status
!= DASD_CQR_FAILED
));
2218 return (cqr
->status
== DASD_CQR_FILLED
);
2221 static int _dasd_sleep_on(struct dasd_ccw_req
*maincqr
, int interruptible
)
2223 struct dasd_device
*device
;
2225 struct list_head ccw_queue
;
2226 struct dasd_ccw_req
*cqr
;
2228 INIT_LIST_HEAD(&ccw_queue
);
2229 maincqr
->status
= DASD_CQR_FILLED
;
2230 device
= maincqr
->startdev
;
2231 list_add(&maincqr
->blocklist
, &ccw_queue
);
2232 for (cqr
= maincqr
; __dasd_sleep_on_loop_condition(cqr
);
2233 cqr
= list_first_entry(&ccw_queue
,
2234 struct dasd_ccw_req
, blocklist
)) {
2236 if (__dasd_sleep_on_erp(cqr
))
2238 if (cqr
->status
!= DASD_CQR_FILLED
) /* could be failed */
2240 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2241 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2242 cqr
->status
= DASD_CQR_FAILED
;
2243 cqr
->intrc
= -EPERM
;
2246 /* Non-temporary stop condition will trigger fail fast */
2247 if (device
->stopped
& ~DASD_STOPPED_PENDING
&&
2248 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2249 (!dasd_eer_enabled(device
))) {
2250 cqr
->status
= DASD_CQR_FAILED
;
2251 cqr
->intrc
= -ENOLINK
;
2255 * Don't try to start requests if device is in
2256 * offline processing, it might wait forever
2258 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
2259 cqr
->status
= DASD_CQR_FAILED
;
2260 cqr
->intrc
= -ENODEV
;
2264 * Don't try to start requests if device is stopped
2265 * except path verification requests
2267 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
2268 if (interruptible
) {
2269 rc
= wait_event_interruptible(
2270 generic_waitq
, !(device
->stopped
));
2271 if (rc
== -ERESTARTSYS
) {
2272 cqr
->status
= DASD_CQR_FAILED
;
2273 maincqr
->intrc
= rc
;
2277 wait_event(generic_waitq
, !(device
->stopped
));
2280 cqr
->callback
= dasd_wakeup_cb
;
2282 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2283 dasd_add_request_tail(cqr
);
2284 if (interruptible
) {
2285 rc
= wait_event_interruptible(
2286 generic_waitq
, _wait_for_wakeup(cqr
));
2287 if (rc
== -ERESTARTSYS
) {
2288 dasd_cancel_req(cqr
);
2289 /* wait (non-interruptible) for final status */
2290 wait_event(generic_waitq
,
2291 _wait_for_wakeup(cqr
));
2292 cqr
->status
= DASD_CQR_FAILED
;
2293 maincqr
->intrc
= rc
;
2297 wait_event(generic_waitq
, _wait_for_wakeup(cqr
));
2300 maincqr
->endclk
= get_tod_clock();
2301 if ((maincqr
->status
!= DASD_CQR_DONE
) &&
2302 (maincqr
->intrc
!= -ERESTARTSYS
))
2303 dasd_log_sense(maincqr
, &maincqr
->irb
);
2304 if (maincqr
->status
== DASD_CQR_DONE
)
2306 else if (maincqr
->intrc
)
2307 rc
= maincqr
->intrc
;
2313 static inline int _wait_for_wakeup_queue(struct list_head
*ccw_queue
)
2315 struct dasd_ccw_req
*cqr
;
2317 list_for_each_entry(cqr
, ccw_queue
, blocklist
) {
2318 if (cqr
->callback_data
!= DASD_SLEEPON_END_TAG
)
2325 static int _dasd_sleep_on_queue(struct list_head
*ccw_queue
, int interruptible
)
2327 struct dasd_device
*device
;
2328 struct dasd_ccw_req
*cqr
, *n
;
2333 list_for_each_entry_safe(cqr
, n
, ccw_queue
, blocklist
) {
2334 device
= cqr
->startdev
;
2335 if (cqr
->status
!= DASD_CQR_FILLED
) /*could be failed*/
2338 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2339 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2340 cqr
->status
= DASD_CQR_FAILED
;
2341 cqr
->intrc
= -EPERM
;
2344 /*Non-temporary stop condition will trigger fail fast*/
2345 if (device
->stopped
& ~DASD_STOPPED_PENDING
&&
2346 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2347 !dasd_eer_enabled(device
)) {
2348 cqr
->status
= DASD_CQR_FAILED
;
2349 cqr
->intrc
= -EAGAIN
;
2353 /*Don't try to start requests if device is stopped*/
2354 if (interruptible
) {
2355 rc
= wait_event_interruptible(
2356 generic_waitq
, !device
->stopped
);
2357 if (rc
== -ERESTARTSYS
) {
2358 cqr
->status
= DASD_CQR_FAILED
;
2363 wait_event(generic_waitq
, !(device
->stopped
));
2366 cqr
->callback
= dasd_wakeup_cb
;
2367 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2368 dasd_add_request_tail(cqr
);
2371 wait_event(generic_waitq
, _wait_for_wakeup_queue(ccw_queue
));
2374 list_for_each_entry_safe(cqr
, n
, ccw_queue
, blocklist
) {
2376 * In some cases the 'File Protected' or 'Incorrect Length'
2377 * error might be expected and error recovery would be
2378 * unnecessary in these cases. Check if the according suppress
2381 sense
= dasd_get_sense(&cqr
->irb
);
2382 if (sense
&& sense
[1] & SNS1_FILE_PROTECTED
&&
2383 test_bit(DASD_CQR_SUPPRESS_FP
, &cqr
->flags
))
2385 if (scsw_cstat(&cqr
->irb
.scsw
) == 0x40 &&
2386 test_bit(DASD_CQR_SUPPRESS_IL
, &cqr
->flags
))
2390 * for alias devices simplify error recovery and
2391 * return to upper layer
2392 * do not skip ERP requests
2394 if (cqr
->startdev
!= cqr
->basedev
&& !cqr
->refers
&&
2395 (cqr
->status
== DASD_CQR_TERMINATED
||
2396 cqr
->status
== DASD_CQR_NEED_ERP
))
2399 /* normal recovery for basedev IO */
2400 if (__dasd_sleep_on_erp(cqr
))
2401 /* handle erp first */
2409 * Queue a request to the tail of the device ccw_queue and wait for
2412 int dasd_sleep_on(struct dasd_ccw_req
*cqr
)
2414 return _dasd_sleep_on(cqr
, 0);
2416 EXPORT_SYMBOL(dasd_sleep_on
);
2419 * Start requests from a ccw_queue and wait for their completion.
2421 int dasd_sleep_on_queue(struct list_head
*ccw_queue
)
2423 return _dasd_sleep_on_queue(ccw_queue
, 0);
2425 EXPORT_SYMBOL(dasd_sleep_on_queue
);
2428 * Queue a request to the tail of the device ccw_queue and wait
2429 * interruptible for it's completion.
2431 int dasd_sleep_on_interruptible(struct dasd_ccw_req
*cqr
)
2433 return _dasd_sleep_on(cqr
, 1);
2435 EXPORT_SYMBOL(dasd_sleep_on_interruptible
);
2438 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2439 * for eckd devices) the currently running request has to be terminated
2440 * and be put back to status queued, before the special request is added
2441 * to the head of the queue. Then the special request is waited on normally.
2443 static inline int _dasd_term_running_cqr(struct dasd_device
*device
)
2445 struct dasd_ccw_req
*cqr
;
2448 if (list_empty(&device
->ccw_queue
))
2450 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
2451 rc
= device
->discipline
->term_IO(cqr
);
2454 * CQR terminated because a more important request is pending.
2455 * Undo decreasing of retry counter because this is
2456 * not an error case.
2462 int dasd_sleep_on_immediatly(struct dasd_ccw_req
*cqr
)
2464 struct dasd_device
*device
;
2467 device
= cqr
->startdev
;
2468 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2469 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2470 cqr
->status
= DASD_CQR_FAILED
;
2471 cqr
->intrc
= -EPERM
;
2474 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2475 rc
= _dasd_term_running_cqr(device
);
2477 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2480 cqr
->callback
= dasd_wakeup_cb
;
2481 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2482 cqr
->status
= DASD_CQR_QUEUED
;
2484 * add new request as second
2485 * first the terminated cqr needs to be finished
2487 list_add(&cqr
->devlist
, device
->ccw_queue
.next
);
2489 /* let the bh start the request to keep them in order */
2490 dasd_schedule_device_bh(device
);
2492 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2494 wait_event(generic_waitq
, _wait_for_wakeup(cqr
));
2496 if (cqr
->status
== DASD_CQR_DONE
)
2498 else if (cqr
->intrc
)
2504 dasd_schedule_device_bh(device
);
2506 dasd_schedule_block_bh(device
->block
);
2510 EXPORT_SYMBOL(dasd_sleep_on_immediatly
);
2513 * Cancels a request that was started with dasd_sleep_on_req.
2514 * This is useful to timeout requests. The request will be
2515 * terminated if it is currently in i/o.
2516 * Returns 0 if request termination was successful
2517 * negative error code if termination failed
2518 * Cancellation of a request is an asynchronous operation! The calling
2519 * function has to wait until the request is properly returned via callback.
2521 static int __dasd_cancel_req(struct dasd_ccw_req
*cqr
)
2523 struct dasd_device
*device
= cqr
->startdev
;
2526 switch (cqr
->status
) {
2527 case DASD_CQR_QUEUED
:
2528 /* request was not started - just set to cleared */
2529 cqr
->status
= DASD_CQR_CLEARED
;
2531 case DASD_CQR_IN_IO
:
2532 /* request in IO - terminate IO and release again */
2533 rc
= device
->discipline
->term_IO(cqr
);
2535 dev_err(&device
->cdev
->dev
,
2536 "Cancelling request %p failed with rc=%d\n",
2539 cqr
->stopclk
= get_tod_clock();
2542 default: /* already finished or clear pending - do nothing */
2545 dasd_schedule_device_bh(device
);
2549 int dasd_cancel_req(struct dasd_ccw_req
*cqr
)
2551 struct dasd_device
*device
= cqr
->startdev
;
2552 unsigned long flags
;
2555 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2556 rc
= __dasd_cancel_req(cqr
);
2557 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2562 * SECTION: Operations of the dasd_block layer.
2566 * Timeout function for dasd_block. This is used when the block layer
2567 * is waiting for something that may not come reliably, (e.g. a state
2570 static void dasd_block_timeout(struct timer_list
*t
)
2572 unsigned long flags
;
2573 struct dasd_block
*block
;
2575 block
= from_timer(block
, t
, timer
);
2576 spin_lock_irqsave(get_ccwdev_lock(block
->base
->cdev
), flags
);
2577 /* re-activate request queue */
2578 dasd_device_remove_stop_bits(block
->base
, DASD_STOPPED_PENDING
);
2579 spin_unlock_irqrestore(get_ccwdev_lock(block
->base
->cdev
), flags
);
2580 dasd_schedule_block_bh(block
);
2581 blk_mq_run_hw_queues(block
->request_queue
, true);
2585 * Setup timeout for a dasd_block in jiffies.
2587 void dasd_block_set_timer(struct dasd_block
*block
, int expires
)
2590 del_timer(&block
->timer
);
2592 mod_timer(&block
->timer
, jiffies
+ expires
);
2594 EXPORT_SYMBOL(dasd_block_set_timer
);
2597 * Clear timeout for a dasd_block.
2599 void dasd_block_clear_timer(struct dasd_block
*block
)
2601 del_timer(&block
->timer
);
2603 EXPORT_SYMBOL(dasd_block_clear_timer
);
2606 * Process finished error recovery ccw.
2608 static void __dasd_process_erp(struct dasd_device
*device
,
2609 struct dasd_ccw_req
*cqr
)
2611 dasd_erp_fn_t erp_fn
;
2613 if (cqr
->status
== DASD_CQR_DONE
)
2614 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s", "ERP successful");
2616 dev_err(&device
->cdev
->dev
, "ERP failed for the DASD\n");
2617 erp_fn
= device
->discipline
->erp_postaction(cqr
);
2621 static void __dasd_cleanup_cqr(struct dasd_ccw_req
*cqr
)
2623 struct request
*req
;
2624 blk_status_t error
= BLK_STS_OK
;
2627 req
= (struct request
*) cqr
->callback_data
;
2628 dasd_profile_end(cqr
->block
, cqr
, req
);
2630 status
= cqr
->block
->base
->discipline
->free_cp(cqr
, req
);
2632 error
= errno_to_blk_status(status
);
2633 else if (status
== 0) {
2634 switch (cqr
->intrc
) {
2636 error
= BLK_STS_NEXUS
;
2639 error
= BLK_STS_TRANSPORT
;
2642 error
= BLK_STS_TIMEOUT
;
2645 error
= BLK_STS_IOERR
;
2651 * We need to take care for ETIMEDOUT errors here since the
2652 * complete callback does not get called in this case.
2653 * Take care of all errors here and avoid additional code to
2654 * transfer the error value to the complete callback.
2657 blk_mq_end_request(req
, error
);
2658 blk_mq_run_hw_queues(req
->q
, true);
2660 blk_mq_complete_request(req
);
2665 * Process ccw request queue.
2667 static void __dasd_process_block_ccw_queue(struct dasd_block
*block
,
2668 struct list_head
*final_queue
)
2670 struct list_head
*l
, *n
;
2671 struct dasd_ccw_req
*cqr
;
2672 dasd_erp_fn_t erp_fn
;
2673 unsigned long flags
;
2674 struct dasd_device
*base
= block
->base
;
2677 /* Process request with final status. */
2678 list_for_each_safe(l
, n
, &block
->ccw_queue
) {
2679 cqr
= list_entry(l
, struct dasd_ccw_req
, blocklist
);
2680 if (cqr
->status
!= DASD_CQR_DONE
&&
2681 cqr
->status
!= DASD_CQR_FAILED
&&
2682 cqr
->status
!= DASD_CQR_NEED_ERP
&&
2683 cqr
->status
!= DASD_CQR_TERMINATED
)
2686 if (cqr
->status
== DASD_CQR_TERMINATED
) {
2687 base
->discipline
->handle_terminated_request(cqr
);
2691 /* Process requests that may be recovered */
2692 if (cqr
->status
== DASD_CQR_NEED_ERP
) {
2693 erp_fn
= base
->discipline
->erp_action(cqr
);
2694 if (IS_ERR(erp_fn(cqr
)))
2699 /* log sense for fatal error */
2700 if (cqr
->status
== DASD_CQR_FAILED
) {
2701 dasd_log_sense(cqr
, &cqr
->irb
);
2704 /* First of all call extended error reporting. */
2705 if (dasd_eer_enabled(base
) &&
2706 cqr
->status
== DASD_CQR_FAILED
) {
2707 dasd_eer_write(base
, cqr
, DASD_EER_FATALERROR
);
2709 /* restart request */
2710 cqr
->status
= DASD_CQR_FILLED
;
2712 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
2713 dasd_device_set_stop_bits(base
, DASD_STOPPED_QUIESCE
);
2714 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
),
2719 /* Process finished ERP request. */
2721 __dasd_process_erp(base
, cqr
);
2725 /* Rechain finished requests to final queue */
2726 cqr
->endclk
= get_tod_clock();
2727 list_move_tail(&cqr
->blocklist
, final_queue
);
2731 static void dasd_return_cqr_cb(struct dasd_ccw_req
*cqr
, void *data
)
2733 dasd_schedule_block_bh(cqr
->block
);
2736 static void __dasd_block_start_head(struct dasd_block
*block
)
2738 struct dasd_ccw_req
*cqr
;
2740 if (list_empty(&block
->ccw_queue
))
2742 /* We allways begin with the first requests on the queue, as some
2743 * of previously started requests have to be enqueued on a
2744 * dasd_device again for error recovery.
2746 list_for_each_entry(cqr
, &block
->ccw_queue
, blocklist
) {
2747 if (cqr
->status
!= DASD_CQR_FILLED
)
2749 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &block
->base
->flags
) &&
2750 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2751 cqr
->status
= DASD_CQR_FAILED
;
2752 cqr
->intrc
= -EPERM
;
2753 dasd_schedule_block_bh(block
);
2756 /* Non-temporary stop condition will trigger fail fast */
2757 if (block
->base
->stopped
& ~DASD_STOPPED_PENDING
&&
2758 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2759 (!dasd_eer_enabled(block
->base
))) {
2760 cqr
->status
= DASD_CQR_FAILED
;
2761 cqr
->intrc
= -ENOLINK
;
2762 dasd_schedule_block_bh(block
);
2765 /* Don't try to start requests if device is stopped */
2766 if (block
->base
->stopped
)
2769 /* just a fail safe check, should not happen */
2771 cqr
->startdev
= block
->base
;
2773 /* make sure that the requests we submit find their way back */
2774 cqr
->callback
= dasd_return_cqr_cb
;
2776 dasd_add_request_tail(cqr
);
2781 * Central dasd_block layer routine. Takes requests from the generic
2782 * block layer request queue, creates ccw requests, enqueues them on
2783 * a dasd_device and processes ccw requests that have been returned.
2785 static void dasd_block_tasklet(unsigned long data
)
2787 struct dasd_block
*block
= (struct dasd_block
*) data
;
2788 struct list_head final_queue
;
2789 struct list_head
*l
, *n
;
2790 struct dasd_ccw_req
*cqr
;
2791 struct dasd_queue
*dq
;
2793 atomic_set(&block
->tasklet_scheduled
, 0);
2794 INIT_LIST_HEAD(&final_queue
);
2795 spin_lock_irq(&block
->queue_lock
);
2796 /* Finish off requests on ccw queue */
2797 __dasd_process_block_ccw_queue(block
, &final_queue
);
2798 spin_unlock_irq(&block
->queue_lock
);
2800 /* Now call the callback function of requests with final status */
2801 list_for_each_safe(l
, n
, &final_queue
) {
2802 cqr
= list_entry(l
, struct dasd_ccw_req
, blocklist
);
2804 spin_lock_irq(&dq
->lock
);
2805 list_del_init(&cqr
->blocklist
);
2806 __dasd_cleanup_cqr(cqr
);
2807 spin_unlock_irq(&dq
->lock
);
2810 spin_lock_irq(&block
->queue_lock
);
2811 /* Now check if the head of the ccw queue needs to be started. */
2812 __dasd_block_start_head(block
);
2813 spin_unlock_irq(&block
->queue_lock
);
2815 if (waitqueue_active(&shutdown_waitq
))
2816 wake_up(&shutdown_waitq
);
2817 dasd_put_device(block
->base
);
2820 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req
*cqr
, void *data
)
2822 wake_up(&dasd_flush_wq
);
2826 * Requeue a request back to the block request queue
2827 * only works for block requests
2829 static int _dasd_requeue_request(struct dasd_ccw_req
*cqr
)
2831 struct dasd_block
*block
= cqr
->block
;
2832 struct request
*req
;
2836 spin_lock_irq(&cqr
->dq
->lock
);
2837 req
= (struct request
*) cqr
->callback_data
;
2838 blk_mq_requeue_request(req
, false);
2839 spin_unlock_irq(&cqr
->dq
->lock
);
2845 * Go through all request on the dasd_block request queue, cancel them
2846 * on the respective dasd_device, and return them to the generic
2849 static int dasd_flush_block_queue(struct dasd_block
*block
)
2851 struct dasd_ccw_req
*cqr
, *n
;
2853 struct list_head flush_queue
;
2854 unsigned long flags
;
2856 INIT_LIST_HEAD(&flush_queue
);
2857 spin_lock_bh(&block
->queue_lock
);
2860 list_for_each_entry_safe(cqr
, n
, &block
->ccw_queue
, blocklist
) {
2861 /* if this request currently owned by a dasd_device cancel it */
2862 if (cqr
->status
>= DASD_CQR_QUEUED
)
2863 rc
= dasd_cancel_req(cqr
);
2866 /* Rechain request (including erp chain) so it won't be
2867 * touched by the dasd_block_tasklet anymore.
2868 * Replace the callback so we notice when the request
2869 * is returned from the dasd_device layer.
2871 cqr
->callback
= _dasd_wake_block_flush_cb
;
2872 for (i
= 0; cqr
!= NULL
; cqr
= cqr
->refers
, i
++)
2873 list_move_tail(&cqr
->blocklist
, &flush_queue
);
2875 /* moved more than one request - need to restart */
2878 spin_unlock_bh(&block
->queue_lock
);
2879 /* Now call the callback function of flushed requests */
2881 list_for_each_entry_safe(cqr
, n
, &flush_queue
, blocklist
) {
2882 wait_event(dasd_flush_wq
, (cqr
->status
< DASD_CQR_QUEUED
));
2883 /* Process finished ERP request. */
2885 spin_lock_bh(&block
->queue_lock
);
2886 __dasd_process_erp(block
->base
, cqr
);
2887 spin_unlock_bh(&block
->queue_lock
);
2888 /* restart list_for_xx loop since dasd_process_erp
2889 * might remove multiple elements */
2892 /* call the callback function */
2893 spin_lock_irqsave(&cqr
->dq
->lock
, flags
);
2894 cqr
->endclk
= get_tod_clock();
2895 list_del_init(&cqr
->blocklist
);
2896 __dasd_cleanup_cqr(cqr
);
2897 spin_unlock_irqrestore(&cqr
->dq
->lock
, flags
);
2903 * Schedules a call to dasd_tasklet over the device tasklet.
2905 void dasd_schedule_block_bh(struct dasd_block
*block
)
2907 /* Protect against rescheduling. */
2908 if (atomic_cmpxchg(&block
->tasklet_scheduled
, 0, 1) != 0)
2910 /* life cycle of block is bound to it's base device */
2911 dasd_get_device(block
->base
);
2912 tasklet_hi_schedule(&block
->tasklet
);
2914 EXPORT_SYMBOL(dasd_schedule_block_bh
);
2918 * SECTION: external block device operations
2919 * (request queue handling, open, release, etc.)
2923 * Dasd request queue function. Called from ll_rw_blk.c
2925 static blk_status_t
do_dasd_request(struct blk_mq_hw_ctx
*hctx
,
2926 const struct blk_mq_queue_data
*qd
)
2928 struct dasd_block
*block
= hctx
->queue
->queuedata
;
2929 struct dasd_queue
*dq
= hctx
->driver_data
;
2930 struct request
*req
= qd
->rq
;
2931 struct dasd_device
*basedev
;
2932 struct dasd_ccw_req
*cqr
;
2933 blk_status_t rc
= BLK_STS_OK
;
2935 basedev
= block
->base
;
2936 spin_lock_irq(&dq
->lock
);
2937 if (basedev
->state
< DASD_STATE_READY
) {
2938 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2939 "device not ready for request %p", req
);
2945 * if device is stopped do not fetch new requests
2946 * except failfast is active which will let requests fail
2947 * immediately in __dasd_block_start_head()
2949 if (basedev
->stopped
&& !(basedev
->features
& DASD_FEATURE_FAILFAST
)) {
2950 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2951 "device stopped request %p", req
);
2952 rc
= BLK_STS_RESOURCE
;
2956 if (basedev
->features
& DASD_FEATURE_READONLY
&&
2957 rq_data_dir(req
) == WRITE
) {
2958 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2959 "Rejecting write request %p", req
);
2964 if (test_bit(DASD_FLAG_ABORTALL
, &basedev
->flags
) &&
2965 (basedev
->features
& DASD_FEATURE_FAILFAST
||
2966 blk_noretry_request(req
))) {
2967 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2968 "Rejecting failfast request %p", req
);
2973 cqr
= basedev
->discipline
->build_cp(basedev
, block
, req
);
2975 if (PTR_ERR(cqr
) == -EBUSY
||
2976 PTR_ERR(cqr
) == -ENOMEM
||
2977 PTR_ERR(cqr
) == -EAGAIN
) {
2978 rc
= BLK_STS_RESOURCE
;
2981 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2982 "CCW creation failed (rc=%ld) on request %p",
2988 * Note: callback is set to dasd_return_cqr_cb in
2989 * __dasd_block_start_head to cover erp requests as well
2991 cqr
->callback_data
= req
;
2992 cqr
->status
= DASD_CQR_FILLED
;
2995 blk_mq_start_request(req
);
2996 spin_lock(&block
->queue_lock
);
2997 list_add_tail(&cqr
->blocklist
, &block
->ccw_queue
);
2998 INIT_LIST_HEAD(&cqr
->devlist
);
2999 dasd_profile_start(block
, cqr
, req
);
3000 dasd_schedule_block_bh(block
);
3001 spin_unlock(&block
->queue_lock
);
3004 spin_unlock_irq(&dq
->lock
);
3009 * Block timeout callback, called from the block layer
3012 * BLK_EH_RESET_TIMER if the request should be left running
3013 * BLK_EH_DONE if the request is handled or terminated
3016 enum blk_eh_timer_return
dasd_times_out(struct request
*req
, bool reserved
)
3018 struct dasd_block
*block
= req
->q
->queuedata
;
3019 struct dasd_device
*device
;
3020 struct dasd_ccw_req
*cqr
;
3021 unsigned long flags
;
3024 cqr
= blk_mq_rq_to_pdu(req
);
3028 spin_lock_irqsave(&cqr
->dq
->lock
, flags
);
3029 device
= cqr
->startdev
? cqr
->startdev
: block
->base
;
3030 if (!device
->blk_timeout
) {
3031 spin_unlock_irqrestore(&cqr
->dq
->lock
, flags
);
3032 return BLK_EH_RESET_TIMER
;
3034 DBF_DEV_EVENT(DBF_WARNING
, device
,
3035 " dasd_times_out cqr %p status %x",
3038 spin_lock(&block
->queue_lock
);
3039 spin_lock(get_ccwdev_lock(device
->cdev
));
3041 cqr
->intrc
= -ETIMEDOUT
;
3042 if (cqr
->status
>= DASD_CQR_QUEUED
) {
3043 rc
= __dasd_cancel_req(cqr
);
3044 } else if (cqr
->status
== DASD_CQR_FILLED
||
3045 cqr
->status
== DASD_CQR_NEED_ERP
) {
3046 cqr
->status
= DASD_CQR_TERMINATED
;
3047 } else if (cqr
->status
== DASD_CQR_IN_ERP
) {
3048 struct dasd_ccw_req
*searchcqr
, *nextcqr
, *tmpcqr
;
3050 list_for_each_entry_safe(searchcqr
, nextcqr
,
3051 &block
->ccw_queue
, blocklist
) {
3053 while (tmpcqr
->refers
)
3054 tmpcqr
= tmpcqr
->refers
;
3057 /* searchcqr is an ERP request for cqr */
3058 searchcqr
->retries
= -1;
3059 searchcqr
->intrc
= -ETIMEDOUT
;
3060 if (searchcqr
->status
>= DASD_CQR_QUEUED
) {
3061 rc
= __dasd_cancel_req(searchcqr
);
3062 } else if ((searchcqr
->status
== DASD_CQR_FILLED
) ||
3063 (searchcqr
->status
== DASD_CQR_NEED_ERP
)) {
3064 searchcqr
->status
= DASD_CQR_TERMINATED
;
3066 } else if (searchcqr
->status
== DASD_CQR_IN_ERP
) {
3068 * Shouldn't happen; most recent ERP
3069 * request is at the front of queue
3076 spin_unlock(get_ccwdev_lock(device
->cdev
));
3077 dasd_schedule_block_bh(block
);
3078 spin_unlock(&block
->queue_lock
);
3079 spin_unlock_irqrestore(&cqr
->dq
->lock
, flags
);
3081 return rc
? BLK_EH_RESET_TIMER
: BLK_EH_DONE
;
3084 static int dasd_init_hctx(struct blk_mq_hw_ctx
*hctx
, void *data
,
3087 struct dasd_queue
*dq
= kzalloc(sizeof(*dq
), GFP_KERNEL
);
3092 spin_lock_init(&dq
->lock
);
3093 hctx
->driver_data
= dq
;
3098 static void dasd_exit_hctx(struct blk_mq_hw_ctx
*hctx
, unsigned int idx
)
3100 kfree(hctx
->driver_data
);
3101 hctx
->driver_data
= NULL
;
3104 static void dasd_request_done(struct request
*req
)
3106 blk_mq_end_request(req
, 0);
3107 blk_mq_run_hw_queues(req
->q
, true);
3110 static struct blk_mq_ops dasd_mq_ops
= {
3111 .queue_rq
= do_dasd_request
,
3112 .complete
= dasd_request_done
,
3113 .timeout
= dasd_times_out
,
3114 .init_hctx
= dasd_init_hctx
,
3115 .exit_hctx
= dasd_exit_hctx
,
3119 * Allocate and initialize request queue and default I/O scheduler.
3121 static int dasd_alloc_queue(struct dasd_block
*block
)
3125 block
->tag_set
.ops
= &dasd_mq_ops
;
3126 block
->tag_set
.cmd_size
= sizeof(struct dasd_ccw_req
);
3127 block
->tag_set
.nr_hw_queues
= nr_hw_queues
;
3128 block
->tag_set
.queue_depth
= queue_depth
;
3129 block
->tag_set
.flags
= BLK_MQ_F_SHOULD_MERGE
;
3130 block
->tag_set
.numa_node
= NUMA_NO_NODE
;
3132 rc
= blk_mq_alloc_tag_set(&block
->tag_set
);
3136 block
->request_queue
= blk_mq_init_queue(&block
->tag_set
);
3137 if (IS_ERR(block
->request_queue
))
3138 return PTR_ERR(block
->request_queue
);
3140 block
->request_queue
->queuedata
= block
;
3146 * Allocate and initialize request queue.
3148 static void dasd_setup_queue(struct dasd_block
*block
)
3150 unsigned int logical_block_size
= block
->bp_block
;
3151 struct request_queue
*q
= block
->request_queue
;
3152 unsigned int max_bytes
, max_discard_sectors
;
3155 if (block
->base
->features
& DASD_FEATURE_USERAW
) {
3157 * the max_blocks value for raw_track access is 256
3158 * it is higher than the native ECKD value because we
3159 * only need one ccw per track
3160 * so the max_hw_sectors are
3161 * 2048 x 512B = 1024kB = 16 tracks
3165 max
= block
->base
->discipline
->max_blocks
<< block
->s2b_shift
;
3167 blk_queue_flag_set(QUEUE_FLAG_NONROT
, q
);
3168 q
->limits
.max_dev_sectors
= max
;
3169 blk_queue_logical_block_size(q
, logical_block_size
);
3170 blk_queue_max_hw_sectors(q
, max
);
3171 blk_queue_max_segments(q
, USHRT_MAX
);
3172 /* with page sized segments we can translate each segement into
3175 blk_queue_max_segment_size(q
, PAGE_SIZE
);
3176 blk_queue_segment_boundary(q
, PAGE_SIZE
- 1);
3178 /* Only activate blocklayer discard support for devices that support it */
3179 if (block
->base
->features
& DASD_FEATURE_DISCARD
) {
3180 q
->limits
.discard_granularity
= logical_block_size
;
3181 q
->limits
.discard_alignment
= PAGE_SIZE
;
3183 /* Calculate max_discard_sectors and make it PAGE aligned */
3184 max_bytes
= USHRT_MAX
* logical_block_size
;
3185 max_bytes
= ALIGN(max_bytes
, PAGE_SIZE
) - PAGE_SIZE
;
3186 max_discard_sectors
= max_bytes
/ logical_block_size
;
3188 blk_queue_max_discard_sectors(q
, max_discard_sectors
);
3189 blk_queue_max_write_zeroes_sectors(q
, max_discard_sectors
);
3190 blk_queue_flag_set(QUEUE_FLAG_DISCARD
, q
);
3195 * Deactivate and free request queue.
3197 static void dasd_free_queue(struct dasd_block
*block
)
3199 if (block
->request_queue
) {
3200 blk_cleanup_queue(block
->request_queue
);
3201 blk_mq_free_tag_set(&block
->tag_set
);
3202 block
->request_queue
= NULL
;
3206 static int dasd_open(struct block_device
*bdev
, fmode_t mode
)
3208 struct dasd_device
*base
;
3211 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
3215 atomic_inc(&base
->block
->open_count
);
3216 if (test_bit(DASD_FLAG_OFFLINE
, &base
->flags
)) {
3221 if (!try_module_get(base
->discipline
->owner
)) {
3226 if (dasd_probeonly
) {
3227 dev_info(&base
->cdev
->dev
,
3228 "Accessing the DASD failed because it is in "
3229 "probeonly mode\n");
3234 if (base
->state
<= DASD_STATE_BASIC
) {
3235 DBF_DEV_EVENT(DBF_ERR
, base
, " %s",
3236 " Cannot open unrecognized device");
3241 if ((mode
& FMODE_WRITE
) &&
3242 (test_bit(DASD_FLAG_DEVICE_RO
, &base
->flags
) ||
3243 (base
->features
& DASD_FEATURE_READONLY
))) {
3248 dasd_put_device(base
);
3252 module_put(base
->discipline
->owner
);
3254 atomic_dec(&base
->block
->open_count
);
3255 dasd_put_device(base
);
3259 static void dasd_release(struct gendisk
*disk
, fmode_t mode
)
3261 struct dasd_device
*base
= dasd_device_from_gendisk(disk
);
3263 atomic_dec(&base
->block
->open_count
);
3264 module_put(base
->discipline
->owner
);
3265 dasd_put_device(base
);
3270 * Return disk geometry.
3272 static int dasd_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
3274 struct dasd_device
*base
;
3276 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
3280 if (!base
->discipline
||
3281 !base
->discipline
->fill_geometry
) {
3282 dasd_put_device(base
);
3285 base
->discipline
->fill_geometry(base
->block
, geo
);
3286 geo
->start
= get_start_sect(bdev
) >> base
->block
->s2b_shift
;
3287 dasd_put_device(base
);
3291 const struct block_device_operations
3292 dasd_device_operations
= {
3293 .owner
= THIS_MODULE
,
3295 .release
= dasd_release
,
3296 .ioctl
= dasd_ioctl
,
3297 .compat_ioctl
= dasd_ioctl
,
3298 .getgeo
= dasd_getgeo
,
3301 /*******************************************************************************
3302 * end of block device operations
3308 #ifdef CONFIG_PROC_FS
3312 if (dasd_page_cache
!= NULL
) {
3313 kmem_cache_destroy(dasd_page_cache
);
3314 dasd_page_cache
= NULL
;
3316 dasd_gendisk_exit();
3318 if (dasd_debug_area
!= NULL
) {
3319 debug_unregister(dasd_debug_area
);
3320 dasd_debug_area
= NULL
;
3322 dasd_statistics_removeroot();
3326 * SECTION: common functions for ccw_driver use
3330 * Is the device read-only?
3331 * Note that this function does not report the setting of the
3332 * readonly device attribute, but how it is configured in z/VM.
3334 int dasd_device_is_ro(struct dasd_device
*device
)
3336 struct ccw_dev_id dev_id
;
3337 struct diag210 diag_data
;
3342 ccw_device_get_id(device
->cdev
, &dev_id
);
3343 memset(&diag_data
, 0, sizeof(diag_data
));
3344 diag_data
.vrdcdvno
= dev_id
.devno
;
3345 diag_data
.vrdclen
= sizeof(diag_data
);
3346 rc
= diag210(&diag_data
);
3347 if (rc
== 0 || rc
== 2) {
3348 return diag_data
.vrdcvfla
& 0x80;
3350 DBF_EVENT(DBF_WARNING
, "diag210 failed for dev=%04x with rc=%d",
3355 EXPORT_SYMBOL_GPL(dasd_device_is_ro
);
3357 static void dasd_generic_auto_online(void *data
, async_cookie_t cookie
)
3359 struct ccw_device
*cdev
= data
;
3362 ret
= ccw_device_set_online(cdev
);
3364 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3365 dev_name(&cdev
->dev
), ret
);
3369 * Initial attempt at a probe function. this can be simplified once
3370 * the other detection code is gone.
3372 int dasd_generic_probe(struct ccw_device
*cdev
,
3373 struct dasd_discipline
*discipline
)
3377 ret
= dasd_add_sysfs_files(cdev
);
3379 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s",
3380 "dasd_generic_probe: could not add "
3384 cdev
->handler
= &dasd_int_handler
;
3387 * Automatically online either all dasd devices (dasd_autodetect)
3388 * or all devices specified with dasd= parameters during
3391 if ((dasd_get_feature(cdev
, DASD_FEATURE_INITIAL_ONLINE
) > 0 ) ||
3392 (dasd_autodetect
&& dasd_busid_known(dev_name(&cdev
->dev
)) != 0))
3393 async_schedule(dasd_generic_auto_online
, cdev
);
3396 EXPORT_SYMBOL_GPL(dasd_generic_probe
);
3398 void dasd_generic_free_discipline(struct dasd_device
*device
)
3400 /* Forget the discipline information. */
3401 if (device
->discipline
) {
3402 if (device
->discipline
->uncheck_device
)
3403 device
->discipline
->uncheck_device(device
);
3404 module_put(device
->discipline
->owner
);
3405 device
->discipline
= NULL
;
3407 if (device
->base_discipline
) {
3408 module_put(device
->base_discipline
->owner
);
3409 device
->base_discipline
= NULL
;
3412 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline
);
3415 * This will one day be called from a global not_oper handler.
3416 * It is also used by driver_unregister during module unload.
3418 void dasd_generic_remove(struct ccw_device
*cdev
)
3420 struct dasd_device
*device
;
3421 struct dasd_block
*block
;
3423 cdev
->handler
= NULL
;
3425 device
= dasd_device_from_cdev(cdev
);
3426 if (IS_ERR(device
)) {
3427 dasd_remove_sysfs_files(cdev
);
3430 if (test_and_set_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
3431 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3432 /* Already doing offline processing */
3433 dasd_put_device(device
);
3434 dasd_remove_sysfs_files(cdev
);
3438 * This device is removed unconditionally. Set offline
3439 * flag to prevent dasd_open from opening it while it is
3440 * no quite down yet.
3442 dasd_set_target_state(device
, DASD_STATE_NEW
);
3443 /* dasd_delete_device destroys the device reference. */
3444 block
= device
->block
;
3445 dasd_delete_device(device
);
3447 * life cycle of block is bound to device, so delete it after
3448 * device was safely removed
3451 dasd_free_block(block
);
3453 dasd_remove_sysfs_files(cdev
);
3455 EXPORT_SYMBOL_GPL(dasd_generic_remove
);
3458 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3459 * the device is detected for the first time and is supposed to be used
3460 * or the user has started activation through sysfs.
3462 int dasd_generic_set_online(struct ccw_device
*cdev
,
3463 struct dasd_discipline
*base_discipline
)
3465 struct dasd_discipline
*discipline
;
3466 struct dasd_device
*device
;
3469 /* first online clears initial online feature flag */
3470 dasd_set_feature(cdev
, DASD_FEATURE_INITIAL_ONLINE
, 0);
3471 device
= dasd_create_device(cdev
);
3473 return PTR_ERR(device
);
3475 discipline
= base_discipline
;
3476 if (device
->features
& DASD_FEATURE_USEDIAG
) {
3477 if (!dasd_diag_discipline_pointer
) {
3478 /* Try to load the required module. */
3479 rc
= request_module(DASD_DIAG_MOD
);
3481 pr_warn("%s Setting the DASD online failed "
3482 "because the required module %s "
3483 "could not be loaded (rc=%d)\n",
3484 dev_name(&cdev
->dev
), DASD_DIAG_MOD
,
3486 dasd_delete_device(device
);
3490 /* Module init could have failed, so check again here after
3491 * request_module(). */
3492 if (!dasd_diag_discipline_pointer
) {
3493 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3494 dev_name(&cdev
->dev
));
3495 dasd_delete_device(device
);
3498 discipline
= dasd_diag_discipline_pointer
;
3500 if (!try_module_get(base_discipline
->owner
)) {
3501 dasd_delete_device(device
);
3504 if (!try_module_get(discipline
->owner
)) {
3505 module_put(base_discipline
->owner
);
3506 dasd_delete_device(device
);
3509 device
->base_discipline
= base_discipline
;
3510 device
->discipline
= discipline
;
3512 /* check_device will allocate block device if necessary */
3513 rc
= discipline
->check_device(device
);
3515 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3516 dev_name(&cdev
->dev
), discipline
->name
, rc
);
3517 module_put(discipline
->owner
);
3518 module_put(base_discipline
->owner
);
3519 dasd_delete_device(device
);
3523 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
3524 if (device
->state
<= DASD_STATE_KNOWN
) {
3525 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3526 dev_name(&cdev
->dev
));
3528 dasd_set_target_state(device
, DASD_STATE_NEW
);
3530 dasd_free_block(device
->block
);
3531 dasd_delete_device(device
);
3533 pr_debug("dasd_generic device %s found\n",
3534 dev_name(&cdev
->dev
));
3536 wait_event(dasd_init_waitq
, _wait_for_device(device
));
3538 dasd_put_device(device
);
3541 EXPORT_SYMBOL_GPL(dasd_generic_set_online
);
3543 int dasd_generic_set_offline(struct ccw_device
*cdev
)
3545 struct dasd_device
*device
;
3546 struct dasd_block
*block
;
3547 int max_count
, open_count
, rc
;
3548 unsigned long flags
;
3551 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
3552 device
= dasd_device_from_cdev_locked(cdev
);
3553 if (IS_ERR(device
)) {
3554 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3555 return PTR_ERR(device
);
3559 * We must make sure that this device is currently not in use.
3560 * The open_count is increased for every opener, that includes
3561 * the blkdev_get in dasd_scan_partitions. We are only interested
3562 * in the other openers.
3564 if (device
->block
) {
3565 max_count
= device
->block
->bdev
? 0 : -1;
3566 open_count
= atomic_read(&device
->block
->open_count
);
3567 if (open_count
> max_count
) {
3569 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3570 dev_name(&cdev
->dev
), open_count
);
3572 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3573 dev_name(&cdev
->dev
));
3580 * Test if the offline processing is already running and exit if so.
3581 * If a safe offline is being processed this could only be a normal
3582 * offline that should be able to overtake the safe offline and
3583 * cancel any I/O we do not want to wait for any longer
3585 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
3586 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3587 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
,
3594 set_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
3597 * if safe_offline is called set safe_offline_running flag and
3598 * clear safe_offline so that a call to normal offline
3599 * can overrun safe_offline processing
3601 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE
, &device
->flags
) &&
3602 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3603 /* need to unlock here to wait for outstanding I/O */
3604 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3606 * If we want to set the device safe offline all IO operations
3607 * should be finished before continuing the offline process
3608 * so sync bdev first and then wait for our queues to become
3611 if (device
->block
) {
3612 rc
= fsync_bdev(device
->block
->bdev
);
3616 dasd_schedule_device_bh(device
);
3617 rc
= wait_event_interruptible(shutdown_waitq
,
3618 _wait_for_empty_queues(device
));
3623 * check if a normal offline process overtook the offline
3624 * processing in this case simply do nothing beside returning
3625 * that we got interrupted
3626 * otherwise mark safe offline as not running any longer and
3627 * continue with normal offline
3629 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
3630 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3634 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
);
3636 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3638 dasd_set_target_state(device
, DASD_STATE_NEW
);
3639 /* dasd_delete_device destroys the device reference. */
3640 block
= device
->block
;
3641 dasd_delete_device(device
);
3643 * life cycle of block is bound to device, so delete it after
3644 * device was safely removed
3647 dasd_free_block(block
);
3652 /* interrupted by signal */
3653 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
3654 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
);
3655 clear_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
3657 dasd_put_device(device
);
3658 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3661 EXPORT_SYMBOL_GPL(dasd_generic_set_offline
);
3663 int dasd_generic_last_path_gone(struct dasd_device
*device
)
3665 struct dasd_ccw_req
*cqr
;
3667 dev_warn(&device
->cdev
->dev
, "No operational channel path is left "
3668 "for the device\n");
3669 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s", "last path gone");
3670 /* First of all call extended error reporting. */
3671 dasd_eer_write(device
, NULL
, DASD_EER_NOPATH
);
3673 if (device
->state
< DASD_STATE_BASIC
)
3675 /* Device is active. We want to keep it. */
3676 list_for_each_entry(cqr
, &device
->ccw_queue
, devlist
)
3677 if ((cqr
->status
== DASD_CQR_IN_IO
) ||
3678 (cqr
->status
== DASD_CQR_CLEAR_PENDING
)) {
3679 cqr
->status
= DASD_CQR_QUEUED
;
3682 dasd_device_set_stop_bits(device
, DASD_STOPPED_DC_WAIT
);
3683 dasd_device_clear_timer(device
);
3684 dasd_schedule_device_bh(device
);
3687 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone
);
3689 int dasd_generic_path_operational(struct dasd_device
*device
)
3691 dev_info(&device
->cdev
->dev
, "A channel path to the device has become "
3693 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s", "path operational");
3694 dasd_device_remove_stop_bits(device
, DASD_STOPPED_DC_WAIT
);
3695 if (device
->stopped
& DASD_UNRESUMED_PM
) {
3696 dasd_device_remove_stop_bits(device
, DASD_UNRESUMED_PM
);
3697 dasd_restore_device(device
);
3700 dasd_schedule_device_bh(device
);
3701 if (device
->block
) {
3702 dasd_schedule_block_bh(device
->block
);
3703 if (device
->block
->request_queue
)
3704 blk_mq_run_hw_queues(device
->block
->request_queue
,
3708 if (!device
->stopped
)
3709 wake_up(&generic_waitq
);
3713 EXPORT_SYMBOL_GPL(dasd_generic_path_operational
);
3715 int dasd_generic_notify(struct ccw_device
*cdev
, int event
)
3717 struct dasd_device
*device
;
3720 device
= dasd_device_from_cdev_locked(cdev
);
3728 dasd_path_no_path(device
);
3729 ret
= dasd_generic_last_path_gone(device
);
3733 if (dasd_path_get_opm(device
))
3734 ret
= dasd_generic_path_operational(device
);
3737 dasd_put_device(device
);
3740 EXPORT_SYMBOL_GPL(dasd_generic_notify
);
3742 void dasd_generic_path_event(struct ccw_device
*cdev
, int *path_event
)
3744 struct dasd_device
*device
;
3745 int chp
, oldopm
, hpfpm
, ifccpm
;
3747 device
= dasd_device_from_cdev_locked(cdev
);
3751 oldopm
= dasd_path_get_opm(device
);
3752 for (chp
= 0; chp
< 8; chp
++) {
3753 if (path_event
[chp
] & PE_PATH_GONE
) {
3754 dasd_path_notoper(device
, chp
);
3756 if (path_event
[chp
] & PE_PATH_AVAILABLE
) {
3757 dasd_path_available(device
, chp
);
3758 dasd_schedule_device_bh(device
);
3760 if (path_event
[chp
] & PE_PATHGROUP_ESTABLISHED
) {
3761 if (!dasd_path_is_operational(device
, chp
) &&
3762 !dasd_path_need_verify(device
, chp
)) {
3764 * we can not establish a pathgroup on an
3765 * unavailable path, so trigger a path
3766 * verification first
3768 dasd_path_available(device
, chp
);
3769 dasd_schedule_device_bh(device
);
3771 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3772 "Pathgroup re-established\n");
3773 if (device
->discipline
->kick_validate
)
3774 device
->discipline
->kick_validate(device
);
3777 hpfpm
= dasd_path_get_hpfpm(device
);
3778 ifccpm
= dasd_path_get_ifccpm(device
);
3779 if (!dasd_path_get_opm(device
) && hpfpm
) {
3781 * device has no operational paths but at least one path is
3782 * disabled due to HPF errors
3783 * disable HPF at all and use the path(s) again
3785 if (device
->discipline
->disable_hpf
)
3786 device
->discipline
->disable_hpf(device
);
3787 dasd_device_set_stop_bits(device
, DASD_STOPPED_NOT_ACC
);
3788 dasd_path_set_tbvpm(device
, hpfpm
);
3789 dasd_schedule_device_bh(device
);
3790 dasd_schedule_requeue(device
);
3791 } else if (!dasd_path_get_opm(device
) && ifccpm
) {
3793 * device has no operational paths but at least one path is
3794 * disabled due to IFCC errors
3795 * trigger path verification on paths with IFCC errors
3797 dasd_path_set_tbvpm(device
, ifccpm
);
3798 dasd_schedule_device_bh(device
);
3800 if (oldopm
&& !dasd_path_get_opm(device
) && !hpfpm
&& !ifccpm
) {
3801 dev_warn(&device
->cdev
->dev
,
3802 "No verified channel paths remain for the device\n");
3803 DBF_DEV_EVENT(DBF_WARNING
, device
,
3804 "%s", "last verified path gone");
3805 dasd_eer_write(device
, NULL
, DASD_EER_NOPATH
);
3806 dasd_device_set_stop_bits(device
,
3807 DASD_STOPPED_DC_WAIT
);
3809 dasd_put_device(device
);
3811 EXPORT_SYMBOL_GPL(dasd_generic_path_event
);
3813 int dasd_generic_verify_path(struct dasd_device
*device
, __u8 lpm
)
3815 if (!dasd_path_get_opm(device
) && lpm
) {
3816 dasd_path_set_opm(device
, lpm
);
3817 dasd_generic_path_operational(device
);
3819 dasd_path_add_opm(device
, lpm
);
3822 EXPORT_SYMBOL_GPL(dasd_generic_verify_path
);
3825 * clear active requests and requeue them to block layer if possible
3827 static int dasd_generic_requeue_all_requests(struct dasd_device
*device
)
3829 struct list_head requeue_queue
;
3830 struct dasd_ccw_req
*cqr
, *n
;
3831 struct dasd_ccw_req
*refers
;
3834 INIT_LIST_HEAD(&requeue_queue
);
3835 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
3837 list_for_each_entry_safe(cqr
, n
, &device
->ccw_queue
, devlist
) {
3838 /* Check status and move request to flush_queue */
3839 if (cqr
->status
== DASD_CQR_IN_IO
) {
3840 rc
= device
->discipline
->term_IO(cqr
);
3842 /* unable to terminate requeust */
3843 dev_err(&device
->cdev
->dev
,
3844 "Unable to terminate request %p "
3845 "on suspend\n", cqr
);
3846 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
3847 dasd_put_device(device
);
3851 list_move_tail(&cqr
->devlist
, &requeue_queue
);
3853 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
3855 list_for_each_entry_safe(cqr
, n
, &requeue_queue
, devlist
) {
3856 wait_event(dasd_flush_wq
,
3857 (cqr
->status
!= DASD_CQR_CLEAR_PENDING
));
3860 * requeue requests to blocklayer will only work
3861 * for block device requests
3863 if (_dasd_requeue_request(cqr
))
3866 /* remove requests from device and block queue */
3867 list_del_init(&cqr
->devlist
);
3868 while (cqr
->refers
!= NULL
) {
3869 refers
= cqr
->refers
;
3870 /* remove the request from the block queue */
3871 list_del(&cqr
->blocklist
);
3872 /* free the finished erp request */
3873 dasd_free_erp_request(cqr
, cqr
->memdev
);
3878 * _dasd_requeue_request already checked for a valid
3879 * blockdevice, no need to check again
3880 * all erp requests (cqr->refers) have a cqr->block
3881 * pointer copy from the original cqr
3883 list_del_init(&cqr
->blocklist
);
3884 cqr
->block
->base
->discipline
->free_cp(
3885 cqr
, (struct request
*) cqr
->callback_data
);
3889 * if requests remain then they are internal request
3890 * and go back to the device queue
3892 if (!list_empty(&requeue_queue
)) {
3893 /* move freeze_queue to start of the ccw_queue */
3894 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
3895 list_splice_tail(&requeue_queue
, &device
->ccw_queue
);
3896 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
3898 dasd_schedule_device_bh(device
);
3902 static void do_requeue_requests(struct work_struct
*work
)
3904 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
3906 dasd_generic_requeue_all_requests(device
);
3907 dasd_device_remove_stop_bits(device
, DASD_STOPPED_NOT_ACC
);
3909 dasd_schedule_block_bh(device
->block
);
3910 dasd_put_device(device
);
3913 void dasd_schedule_requeue(struct dasd_device
*device
)
3915 dasd_get_device(device
);
3916 /* queue call to dasd_reload_device to the kernel event daemon. */
3917 if (!schedule_work(&device
->requeue_requests
))
3918 dasd_put_device(device
);
3920 EXPORT_SYMBOL(dasd_schedule_requeue
);
3922 int dasd_generic_pm_freeze(struct ccw_device
*cdev
)
3924 struct dasd_device
*device
= dasd_device_from_cdev(cdev
);
3927 return PTR_ERR(device
);
3929 /* mark device as suspended */
3930 set_bit(DASD_FLAG_SUSPENDED
, &device
->flags
);
3932 if (device
->discipline
->freeze
)
3933 device
->discipline
->freeze(device
);
3935 /* disallow new I/O */
3936 dasd_device_set_stop_bits(device
, DASD_STOPPED_PM
);
3938 return dasd_generic_requeue_all_requests(device
);
3940 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze
);
3942 int dasd_generic_restore_device(struct ccw_device
*cdev
)
3944 struct dasd_device
*device
= dasd_device_from_cdev(cdev
);
3948 return PTR_ERR(device
);
3950 /* allow new IO again */
3951 dasd_device_remove_stop_bits(device
,
3952 (DASD_STOPPED_PM
| DASD_UNRESUMED_PM
));
3954 dasd_schedule_device_bh(device
);
3957 * call discipline restore function
3958 * if device is stopped do nothing e.g. for disconnected devices
3960 if (device
->discipline
->restore
&& !(device
->stopped
))
3961 rc
= device
->discipline
->restore(device
);
3962 if (rc
|| device
->stopped
)
3964 * if the resume failed for the DASD we put it in
3965 * an UNRESUMED stop state
3967 device
->stopped
|= DASD_UNRESUMED_PM
;
3969 if (device
->block
) {
3970 dasd_schedule_block_bh(device
->block
);
3971 if (device
->block
->request_queue
)
3972 blk_mq_run_hw_queues(device
->block
->request_queue
,
3976 clear_bit(DASD_FLAG_SUSPENDED
, &device
->flags
);
3977 dasd_put_device(device
);
3980 EXPORT_SYMBOL_GPL(dasd_generic_restore_device
);
3982 static struct dasd_ccw_req
*dasd_generic_build_rdc(struct dasd_device
*device
,
3984 int rdc_buffer_size
,
3987 struct dasd_ccw_req
*cqr
;
3989 unsigned long *idaw
;
3991 cqr
= dasd_smalloc_request(magic
, 1 /* RDC */, rdc_buffer_size
, device
,
3995 /* internal error 13 - Allocating the RDC request failed*/
3996 dev_err(&device
->cdev
->dev
,
3997 "An error occurred in the DASD device driver, "
3998 "reason=%s\n", "13");
4003 ccw
->cmd_code
= CCW_CMD_RDC
;
4004 if (idal_is_needed(rdc_buffer
, rdc_buffer_size
)) {
4005 idaw
= (unsigned long *) (cqr
->data
);
4006 ccw
->cda
= (__u32
)(addr_t
) idaw
;
4007 ccw
->flags
= CCW_FLAG_IDA
;
4008 idaw
= idal_create_words(idaw
, rdc_buffer
, rdc_buffer_size
);
4010 ccw
->cda
= (__u32
)(addr_t
) rdc_buffer
;
4014 ccw
->count
= rdc_buffer_size
;
4015 cqr
->startdev
= device
;
4016 cqr
->memdev
= device
;
4017 cqr
->expires
= 10*HZ
;
4019 cqr
->buildclk
= get_tod_clock();
4020 cqr
->status
= DASD_CQR_FILLED
;
4025 int dasd_generic_read_dev_chars(struct dasd_device
*device
, int magic
,
4026 void *rdc_buffer
, int rdc_buffer_size
)
4029 struct dasd_ccw_req
*cqr
;
4031 cqr
= dasd_generic_build_rdc(device
, rdc_buffer
, rdc_buffer_size
,
4034 return PTR_ERR(cqr
);
4036 ret
= dasd_sleep_on(cqr
);
4037 dasd_sfree_request(cqr
, cqr
->memdev
);
4040 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars
);
4043 * In command mode and transport mode we need to look for sense
4044 * data in different places. The sense data itself is allways
4045 * an array of 32 bytes, so we can unify the sense data access
4048 char *dasd_get_sense(struct irb
*irb
)
4050 struct tsb
*tsb
= NULL
;
4053 if (scsw_is_tm(&irb
->scsw
) && (irb
->scsw
.tm
.fcxs
== 0x01)) {
4054 if (irb
->scsw
.tm
.tcw
)
4055 tsb
= tcw_get_tsb((struct tcw
*)(unsigned long)
4057 if (tsb
&& tsb
->length
== 64 && tsb
->flags
)
4058 switch (tsb
->flags
& 0x07) {
4059 case 1: /* tsa_iostat */
4060 sense
= tsb
->tsa
.iostat
.sense
;
4062 case 2: /* tsa_ddpc */
4063 sense
= tsb
->tsa
.ddpc
.sense
;
4066 /* currently we don't use interrogate data */
4069 } else if (irb
->esw
.esw0
.erw
.cons
) {
4074 EXPORT_SYMBOL_GPL(dasd_get_sense
);
4076 void dasd_generic_shutdown(struct ccw_device
*cdev
)
4078 struct dasd_device
*device
;
4080 device
= dasd_device_from_cdev(cdev
);
4085 dasd_schedule_block_bh(device
->block
);
4087 dasd_schedule_device_bh(device
);
4089 wait_event(shutdown_waitq
, _wait_for_empty_queues(device
));
4091 EXPORT_SYMBOL_GPL(dasd_generic_shutdown
);
4093 static int __init
dasd_init(void)
4097 init_waitqueue_head(&dasd_init_waitq
);
4098 init_waitqueue_head(&dasd_flush_wq
);
4099 init_waitqueue_head(&generic_waitq
);
4100 init_waitqueue_head(&shutdown_waitq
);
4102 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4103 dasd_debug_area
= debug_register("dasd", 1, 1, 8 * sizeof(long));
4104 if (dasd_debug_area
== NULL
) {
4108 debug_register_view(dasd_debug_area
, &debug_sprintf_view
);
4109 debug_set_level(dasd_debug_area
, DBF_WARNING
);
4111 DBF_EVENT(DBF_EMERG
, "%s", "debug area created");
4113 dasd_diag_discipline_pointer
= NULL
;
4115 dasd_statistics_createroot();
4117 rc
= dasd_devmap_init();
4120 rc
= dasd_gendisk_init();
4126 rc
= dasd_eer_init();
4129 #ifdef CONFIG_PROC_FS
4130 rc
= dasd_proc_init();
4137 pr_info("The DASD device driver could not be initialized\n");
4142 module_init(dasd_init
);
4143 module_exit(dasd_exit
);