2 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * Copyright IBM Corp. 1999, 2009
10 #define KMSG_COMPONENT "dasd"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/kmod.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <linux/ctype.h>
17 #include <linux/major.h>
18 #include <linux/slab.h>
19 #include <linux/hdreg.h>
20 #include <linux/async.h>
21 #include <linux/mutex.h>
22 #include <linux/debugfs.h>
23 #include <linux/seq_file.h>
24 #include <linux/vmalloc.h>
26 #include <asm/ccwdev.h>
27 #include <asm/ebcdic.h>
28 #include <asm/idals.h>
33 #define PRINTK_HEADER "dasd:"
37 * SECTION: Constant definitions to be used within this file
39 #define DASD_CHANQ_MAX_SIZE 4
41 #define DASD_DIAG_MOD "dasd_diag_mod"
44 * SECTION: exported variables of dasd.c
46 debug_info_t
*dasd_debug_area
;
47 EXPORT_SYMBOL(dasd_debug_area
);
48 static struct dentry
*dasd_debugfs_root_entry
;
49 struct dasd_discipline
*dasd_diag_discipline_pointer
;
50 EXPORT_SYMBOL(dasd_diag_discipline_pointer
);
51 void dasd_int_handler(struct ccw_device
*, unsigned long, struct irb
*);
53 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
54 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
55 " Copyright IBM Corp. 2000");
56 MODULE_SUPPORTED_DEVICE("dasd");
57 MODULE_LICENSE("GPL");
60 * SECTION: prototypes for static functions of dasd.c
62 static int dasd_alloc_queue(struct dasd_block
*);
63 static void dasd_setup_queue(struct dasd_block
*);
64 static void dasd_free_queue(struct dasd_block
*);
65 static int dasd_flush_block_queue(struct dasd_block
*);
66 static void dasd_device_tasklet(struct dasd_device
*);
67 static void dasd_block_tasklet(struct dasd_block
*);
68 static void do_kick_device(struct work_struct
*);
69 static void do_restore_device(struct work_struct
*);
70 static void do_reload_device(struct work_struct
*);
71 static void do_requeue_requests(struct work_struct
*);
72 static void dasd_return_cqr_cb(struct dasd_ccw_req
*, void *);
73 static void dasd_device_timeout(struct timer_list
*);
74 static void dasd_block_timeout(struct timer_list
*);
75 static void __dasd_process_erp(struct dasd_device
*, struct dasd_ccw_req
*);
76 static void dasd_profile_init(struct dasd_profile
*, struct dentry
*);
77 static void dasd_profile_exit(struct dasd_profile
*);
78 static void dasd_hosts_init(struct dentry
*, struct dasd_device
*);
79 static void dasd_hosts_exit(struct dasd_device
*);
82 * SECTION: Operations on the device structure.
84 static wait_queue_head_t dasd_init_waitq
;
85 static wait_queue_head_t dasd_flush_wq
;
86 static wait_queue_head_t generic_waitq
;
87 static wait_queue_head_t shutdown_waitq
;
90 * Allocate memory for a new device structure.
92 struct dasd_device
*dasd_alloc_device(void)
94 struct dasd_device
*device
;
96 device
= kzalloc(sizeof(struct dasd_device
), GFP_ATOMIC
);
98 return ERR_PTR(-ENOMEM
);
100 /* Get two pages for normal block device operations. */
101 device
->ccw_mem
= (void *) __get_free_pages(GFP_ATOMIC
| GFP_DMA
, 1);
102 if (!device
->ccw_mem
) {
104 return ERR_PTR(-ENOMEM
);
106 /* Get one page for error recovery. */
107 device
->erp_mem
= (void *) get_zeroed_page(GFP_ATOMIC
| GFP_DMA
);
108 if (!device
->erp_mem
) {
109 free_pages((unsigned long) device
->ccw_mem
, 1);
111 return ERR_PTR(-ENOMEM
);
114 dasd_init_chunklist(&device
->ccw_chunks
, device
->ccw_mem
, PAGE_SIZE
*2);
115 dasd_init_chunklist(&device
->erp_chunks
, device
->erp_mem
, PAGE_SIZE
);
116 spin_lock_init(&device
->mem_lock
);
117 atomic_set(&device
->tasklet_scheduled
, 0);
118 tasklet_init(&device
->tasklet
,
119 (void (*)(unsigned long)) dasd_device_tasklet
,
120 (unsigned long) device
);
121 INIT_LIST_HEAD(&device
->ccw_queue
);
122 timer_setup(&device
->timer
, dasd_device_timeout
, 0);
123 INIT_WORK(&device
->kick_work
, do_kick_device
);
124 INIT_WORK(&device
->restore_device
, do_restore_device
);
125 INIT_WORK(&device
->reload_device
, do_reload_device
);
126 INIT_WORK(&device
->requeue_requests
, do_requeue_requests
);
127 device
->state
= DASD_STATE_NEW
;
128 device
->target
= DASD_STATE_NEW
;
129 mutex_init(&device
->state_mutex
);
130 spin_lock_init(&device
->profile
.lock
);
135 * Free memory of a device structure.
137 void dasd_free_device(struct dasd_device
*device
)
139 kfree(device
->private);
140 free_page((unsigned long) device
->erp_mem
);
141 free_pages((unsigned long) device
->ccw_mem
, 1);
146 * Allocate memory for a new device structure.
148 struct dasd_block
*dasd_alloc_block(void)
150 struct dasd_block
*block
;
152 block
= kzalloc(sizeof(*block
), GFP_ATOMIC
);
154 return ERR_PTR(-ENOMEM
);
155 /* open_count = 0 means device online but not in use */
156 atomic_set(&block
->open_count
, -1);
158 atomic_set(&block
->tasklet_scheduled
, 0);
159 tasklet_init(&block
->tasklet
,
160 (void (*)(unsigned long)) dasd_block_tasklet
,
161 (unsigned long) block
);
162 INIT_LIST_HEAD(&block
->ccw_queue
);
163 spin_lock_init(&block
->queue_lock
);
164 timer_setup(&block
->timer
, dasd_block_timeout
, 0);
165 spin_lock_init(&block
->profile
.lock
);
169 EXPORT_SYMBOL_GPL(dasd_alloc_block
);
172 * Free memory of a device structure.
174 void dasd_free_block(struct dasd_block
*block
)
178 EXPORT_SYMBOL_GPL(dasd_free_block
);
181 * Make a new device known to the system.
183 static int dasd_state_new_to_known(struct dasd_device
*device
)
188 * As long as the device is not in state DASD_STATE_NEW we want to
189 * keep the reference count > 0.
191 dasd_get_device(device
);
194 rc
= dasd_alloc_queue(device
->block
);
196 dasd_put_device(device
);
200 device
->state
= DASD_STATE_KNOWN
;
205 * Let the system forget about a device.
207 static int dasd_state_known_to_new(struct dasd_device
*device
)
209 /* Disable extended error reporting for this device. */
210 dasd_eer_disable(device
);
211 device
->state
= DASD_STATE_NEW
;
214 dasd_free_queue(device
->block
);
216 /* Give up reference we took in dasd_state_new_to_known. */
217 dasd_put_device(device
);
221 static struct dentry
*dasd_debugfs_setup(const char *name
,
222 struct dentry
*base_dentry
)
228 pde
= debugfs_create_dir(name
, base_dentry
);
229 if (!pde
|| IS_ERR(pde
))
235 * Request the irq line for the device.
237 static int dasd_state_known_to_basic(struct dasd_device
*device
)
239 struct dasd_block
*block
= device
->block
;
242 /* Allocate and register gendisk structure. */
244 rc
= dasd_gendisk_alloc(block
);
247 block
->debugfs_dentry
=
248 dasd_debugfs_setup(block
->gdp
->disk_name
,
249 dasd_debugfs_root_entry
);
250 dasd_profile_init(&block
->profile
, block
->debugfs_dentry
);
251 if (dasd_global_profile_level
== DASD_PROFILE_ON
)
252 dasd_profile_on(&device
->block
->profile
);
254 device
->debugfs_dentry
=
255 dasd_debugfs_setup(dev_name(&device
->cdev
->dev
),
256 dasd_debugfs_root_entry
);
257 dasd_profile_init(&device
->profile
, device
->debugfs_dentry
);
258 dasd_hosts_init(device
->debugfs_dentry
, device
);
260 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
261 device
->debug_area
= debug_register(dev_name(&device
->cdev
->dev
), 4, 1,
263 debug_register_view(device
->debug_area
, &debug_sprintf_view
);
264 debug_set_level(device
->debug_area
, DBF_WARNING
);
265 DBF_DEV_EVENT(DBF_EMERG
, device
, "%s", "debug area created");
267 device
->state
= DASD_STATE_BASIC
;
273 * Release the irq line for the device. Terminate any running i/o.
275 static int dasd_state_basic_to_known(struct dasd_device
*device
)
279 if (device
->discipline
->basic_to_known
) {
280 rc
= device
->discipline
->basic_to_known(device
);
286 dasd_profile_exit(&device
->block
->profile
);
287 debugfs_remove(device
->block
->debugfs_dentry
);
288 dasd_gendisk_free(device
->block
);
289 dasd_block_clear_timer(device
->block
);
291 rc
= dasd_flush_device_queue(device
);
294 dasd_device_clear_timer(device
);
295 dasd_profile_exit(&device
->profile
);
296 dasd_hosts_exit(device
);
297 debugfs_remove(device
->debugfs_dentry
);
298 DBF_DEV_EVENT(DBF_EMERG
, device
, "%p debug area deleted", device
);
299 if (device
->debug_area
!= NULL
) {
300 debug_unregister(device
->debug_area
);
301 device
->debug_area
= NULL
;
303 device
->state
= DASD_STATE_KNOWN
;
308 * Do the initial analysis. The do_analysis function may return
309 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
310 * until the discipline decides to continue the startup sequence
311 * by calling the function dasd_change_state. The eckd disciplines
312 * uses this to start a ccw that detects the format. The completion
313 * interrupt for this detection ccw uses the kernel event daemon to
314 * trigger the call to dasd_change_state. All this is done in the
315 * discipline code, see dasd_eckd.c.
316 * After the analysis ccw is done (do_analysis returned 0) the block
318 * In case the analysis returns an error, the device setup is stopped
319 * (a fake disk was already added to allow formatting).
321 static int dasd_state_basic_to_ready(struct dasd_device
*device
)
324 struct dasd_block
*block
;
325 struct gendisk
*disk
;
328 block
= device
->block
;
329 /* make disk known with correct capacity */
331 if (block
->base
->discipline
->do_analysis
!= NULL
)
332 rc
= block
->base
->discipline
->do_analysis(block
);
335 device
->state
= DASD_STATE_UNFMT
;
336 disk
= device
->block
->gdp
;
337 kobject_uevent(&disk_to_dev(disk
)->kobj
,
343 dasd_setup_queue(block
);
344 set_capacity(block
->gdp
,
345 block
->blocks
<< block
->s2b_shift
);
346 device
->state
= DASD_STATE_READY
;
347 rc
= dasd_scan_partitions(block
);
349 device
->state
= DASD_STATE_BASIC
;
353 device
->state
= DASD_STATE_READY
;
356 if (device
->discipline
->basic_to_ready
)
357 rc
= device
->discipline
->basic_to_ready(device
);
362 int _wait_for_empty_queues(struct dasd_device
*device
)
365 return list_empty(&device
->ccw_queue
) &&
366 list_empty(&device
->block
->ccw_queue
);
368 return list_empty(&device
->ccw_queue
);
372 * Remove device from block device layer. Destroy dirty buffers.
373 * Forget format information. Check if the target level is basic
374 * and if it is create fake disk for formatting.
376 static int dasd_state_ready_to_basic(struct dasd_device
*device
)
380 device
->state
= DASD_STATE_BASIC
;
382 struct dasd_block
*block
= device
->block
;
383 rc
= dasd_flush_block_queue(block
);
385 device
->state
= DASD_STATE_READY
;
388 dasd_destroy_partitions(block
);
391 block
->s2b_shift
= 0;
399 static int dasd_state_unfmt_to_basic(struct dasd_device
*device
)
401 device
->state
= DASD_STATE_BASIC
;
406 * Make the device online and schedule the bottom half to start
407 * the requeueing of requests from the linux request queue to the
411 dasd_state_ready_to_online(struct dasd_device
* device
)
413 struct gendisk
*disk
;
414 struct disk_part_iter piter
;
415 struct hd_struct
*part
;
417 device
->state
= DASD_STATE_ONLINE
;
419 dasd_schedule_block_bh(device
->block
);
420 if ((device
->features
& DASD_FEATURE_USERAW
)) {
421 disk
= device
->block
->gdp
;
422 kobject_uevent(&disk_to_dev(disk
)->kobj
, KOBJ_CHANGE
);
425 disk
= device
->block
->bdev
->bd_disk
;
426 disk_part_iter_init(&piter
, disk
, DISK_PITER_INCL_PART0
);
427 while ((part
= disk_part_iter_next(&piter
)))
428 kobject_uevent(&part_to_dev(part
)->kobj
, KOBJ_CHANGE
);
429 disk_part_iter_exit(&piter
);
435 * Stop the requeueing of requests again.
437 static int dasd_state_online_to_ready(struct dasd_device
*device
)
440 struct gendisk
*disk
;
441 struct disk_part_iter piter
;
442 struct hd_struct
*part
;
444 if (device
->discipline
->online_to_ready
) {
445 rc
= device
->discipline
->online_to_ready(device
);
450 device
->state
= DASD_STATE_READY
;
451 if (device
->block
&& !(device
->features
& DASD_FEATURE_USERAW
)) {
452 disk
= device
->block
->bdev
->bd_disk
;
453 disk_part_iter_init(&piter
, disk
, DISK_PITER_INCL_PART0
);
454 while ((part
= disk_part_iter_next(&piter
)))
455 kobject_uevent(&part_to_dev(part
)->kobj
, KOBJ_CHANGE
);
456 disk_part_iter_exit(&piter
);
462 * Device startup state changes.
464 static int dasd_increase_state(struct dasd_device
*device
)
469 if (device
->state
== DASD_STATE_NEW
&&
470 device
->target
>= DASD_STATE_KNOWN
)
471 rc
= dasd_state_new_to_known(device
);
474 device
->state
== DASD_STATE_KNOWN
&&
475 device
->target
>= DASD_STATE_BASIC
)
476 rc
= dasd_state_known_to_basic(device
);
479 device
->state
== DASD_STATE_BASIC
&&
480 device
->target
>= DASD_STATE_READY
)
481 rc
= dasd_state_basic_to_ready(device
);
484 device
->state
== DASD_STATE_UNFMT
&&
485 device
->target
> DASD_STATE_UNFMT
)
489 device
->state
== DASD_STATE_READY
&&
490 device
->target
>= DASD_STATE_ONLINE
)
491 rc
= dasd_state_ready_to_online(device
);
497 * Device shutdown state changes.
499 static int dasd_decrease_state(struct dasd_device
*device
)
504 if (device
->state
== DASD_STATE_ONLINE
&&
505 device
->target
<= DASD_STATE_READY
)
506 rc
= dasd_state_online_to_ready(device
);
509 device
->state
== DASD_STATE_READY
&&
510 device
->target
<= DASD_STATE_BASIC
)
511 rc
= dasd_state_ready_to_basic(device
);
514 device
->state
== DASD_STATE_UNFMT
&&
515 device
->target
<= DASD_STATE_BASIC
)
516 rc
= dasd_state_unfmt_to_basic(device
);
519 device
->state
== DASD_STATE_BASIC
&&
520 device
->target
<= DASD_STATE_KNOWN
)
521 rc
= dasd_state_basic_to_known(device
);
524 device
->state
== DASD_STATE_KNOWN
&&
525 device
->target
<= DASD_STATE_NEW
)
526 rc
= dasd_state_known_to_new(device
);
532 * This is the main startup/shutdown routine.
534 static void dasd_change_state(struct dasd_device
*device
)
538 if (device
->state
== device
->target
)
539 /* Already where we want to go today... */
541 if (device
->state
< device
->target
)
542 rc
= dasd_increase_state(device
);
544 rc
= dasd_decrease_state(device
);
548 device
->target
= device
->state
;
550 /* let user-space know that the device status changed */
551 kobject_uevent(&device
->cdev
->dev
.kobj
, KOBJ_CHANGE
);
553 if (device
->state
== device
->target
)
554 wake_up(&dasd_init_waitq
);
558 * Kick starter for devices that did not complete the startup/shutdown
559 * procedure or were sleeping because of a pending state.
560 * dasd_kick_device will schedule a call do do_kick_device to the kernel
563 static void do_kick_device(struct work_struct
*work
)
565 struct dasd_device
*device
= container_of(work
, struct dasd_device
, kick_work
);
566 mutex_lock(&device
->state_mutex
);
567 dasd_change_state(device
);
568 mutex_unlock(&device
->state_mutex
);
569 dasd_schedule_device_bh(device
);
570 dasd_put_device(device
);
573 void dasd_kick_device(struct dasd_device
*device
)
575 dasd_get_device(device
);
576 /* queue call to dasd_kick_device to the kernel event daemon. */
577 if (!schedule_work(&device
->kick_work
))
578 dasd_put_device(device
);
580 EXPORT_SYMBOL(dasd_kick_device
);
583 * dasd_reload_device will schedule a call do do_reload_device to the kernel
586 static void do_reload_device(struct work_struct
*work
)
588 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
590 device
->discipline
->reload(device
);
591 dasd_put_device(device
);
594 void dasd_reload_device(struct dasd_device
*device
)
596 dasd_get_device(device
);
597 /* queue call to dasd_reload_device to the kernel event daemon. */
598 if (!schedule_work(&device
->reload_device
))
599 dasd_put_device(device
);
601 EXPORT_SYMBOL(dasd_reload_device
);
604 * dasd_restore_device will schedule a call do do_restore_device to the kernel
607 static void do_restore_device(struct work_struct
*work
)
609 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
611 device
->cdev
->drv
->restore(device
->cdev
);
612 dasd_put_device(device
);
615 void dasd_restore_device(struct dasd_device
*device
)
617 dasd_get_device(device
);
618 /* queue call to dasd_restore_device to the kernel event daemon. */
619 if (!schedule_work(&device
->restore_device
))
620 dasd_put_device(device
);
624 * Set the target state for a device and starts the state change.
626 void dasd_set_target_state(struct dasd_device
*device
, int target
)
628 dasd_get_device(device
);
629 mutex_lock(&device
->state_mutex
);
630 /* If we are in probeonly mode stop at DASD_STATE_READY. */
631 if (dasd_probeonly
&& target
> DASD_STATE_READY
)
632 target
= DASD_STATE_READY
;
633 if (device
->target
!= target
) {
634 if (device
->state
== target
)
635 wake_up(&dasd_init_waitq
);
636 device
->target
= target
;
638 if (device
->state
!= device
->target
)
639 dasd_change_state(device
);
640 mutex_unlock(&device
->state_mutex
);
641 dasd_put_device(device
);
643 EXPORT_SYMBOL(dasd_set_target_state
);
646 * Enable devices with device numbers in [from..to].
648 static inline int _wait_for_device(struct dasd_device
*device
)
650 return (device
->state
== device
->target
);
653 void dasd_enable_device(struct dasd_device
*device
)
655 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
656 if (device
->state
<= DASD_STATE_KNOWN
)
657 /* No discipline for device found. */
658 dasd_set_target_state(device
, DASD_STATE_NEW
);
659 /* Now wait for the devices to come up. */
660 wait_event(dasd_init_waitq
, _wait_for_device(device
));
662 dasd_reload_device(device
);
663 if (device
->discipline
->kick_validate
)
664 device
->discipline
->kick_validate(device
);
666 EXPORT_SYMBOL(dasd_enable_device
);
669 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
672 unsigned int dasd_global_profile_level
= DASD_PROFILE_OFF
;
674 #ifdef CONFIG_DASD_PROFILE
675 struct dasd_profile dasd_global_profile
= {
676 .lock
= __SPIN_LOCK_UNLOCKED(dasd_global_profile
.lock
),
678 static struct dentry
*dasd_debugfs_global_entry
;
681 * Add profiling information for cqr before execution.
683 static void dasd_profile_start(struct dasd_block
*block
,
684 struct dasd_ccw_req
*cqr
,
688 unsigned int counter
;
689 struct dasd_device
*device
;
691 /* count the length of the chanq for statistics */
693 if (dasd_global_profile_level
|| block
->profile
.data
)
694 list_for_each(l
, &block
->ccw_queue
)
698 spin_lock(&dasd_global_profile
.lock
);
699 if (dasd_global_profile
.data
) {
700 dasd_global_profile
.data
->dasd_io_nr_req
[counter
]++;
701 if (rq_data_dir(req
) == READ
)
702 dasd_global_profile
.data
->dasd_read_nr_req
[counter
]++;
704 spin_unlock(&dasd_global_profile
.lock
);
706 spin_lock(&block
->profile
.lock
);
707 if (block
->profile
.data
) {
708 block
->profile
.data
->dasd_io_nr_req
[counter
]++;
709 if (rq_data_dir(req
) == READ
)
710 block
->profile
.data
->dasd_read_nr_req
[counter
]++;
712 spin_unlock(&block
->profile
.lock
);
715 * We count the request for the start device, even though it may run on
716 * some other device due to error recovery. This way we make sure that
717 * we count each request only once.
719 device
= cqr
->startdev
;
720 if (device
->profile
.data
) {
721 counter
= 1; /* request is not yet queued on the start device */
722 list_for_each(l
, &device
->ccw_queue
)
726 spin_lock(&device
->profile
.lock
);
727 if (device
->profile
.data
) {
728 device
->profile
.data
->dasd_io_nr_req
[counter
]++;
729 if (rq_data_dir(req
) == READ
)
730 device
->profile
.data
->dasd_read_nr_req
[counter
]++;
732 spin_unlock(&device
->profile
.lock
);
736 * Add profiling information for cqr after execution.
739 #define dasd_profile_counter(value, index) \
741 for (index = 0; index < 31 && value >> (2+index); index++) \
745 static void dasd_profile_end_add_data(struct dasd_profile_info
*data
,
758 /* in case of an overflow, reset the whole profile */
759 if (data
->dasd_io_reqs
== UINT_MAX
) {
760 memset(data
, 0, sizeof(*data
));
761 getnstimeofday(&data
->starttod
);
763 data
->dasd_io_reqs
++;
764 data
->dasd_io_sects
+= sectors
;
766 data
->dasd_io_alias
++;
770 data
->dasd_io_secs
[sectors_ind
]++;
771 data
->dasd_io_times
[tottime_ind
]++;
772 data
->dasd_io_timps
[tottimeps_ind
]++;
773 data
->dasd_io_time1
[strtime_ind
]++;
774 data
->dasd_io_time2
[irqtime_ind
]++;
775 data
->dasd_io_time2ps
[irqtimeps_ind
]++;
776 data
->dasd_io_time3
[endtime_ind
]++;
779 data
->dasd_read_reqs
++;
780 data
->dasd_read_sects
+= sectors
;
782 data
->dasd_read_alias
++;
784 data
->dasd_read_tpm
++;
785 data
->dasd_read_secs
[sectors_ind
]++;
786 data
->dasd_read_times
[tottime_ind
]++;
787 data
->dasd_read_time1
[strtime_ind
]++;
788 data
->dasd_read_time2
[irqtime_ind
]++;
789 data
->dasd_read_time3
[endtime_ind
]++;
793 static void dasd_profile_end(struct dasd_block
*block
,
794 struct dasd_ccw_req
*cqr
,
797 unsigned long strtime
, irqtime
, endtime
, tottime
;
798 unsigned long tottimeps
, sectors
;
799 struct dasd_device
*device
;
800 int sectors_ind
, tottime_ind
, tottimeps_ind
, strtime_ind
;
801 int irqtime_ind
, irqtimeps_ind
, endtime_ind
;
802 struct dasd_profile_info
*data
;
804 device
= cqr
->startdev
;
805 if (!(dasd_global_profile_level
||
806 block
->profile
.data
||
807 device
->profile
.data
))
810 sectors
= blk_rq_sectors(req
);
811 if (!cqr
->buildclk
|| !cqr
->startclk
||
812 !cqr
->stopclk
|| !cqr
->endclk
||
816 strtime
= ((cqr
->startclk
- cqr
->buildclk
) >> 12);
817 irqtime
= ((cqr
->stopclk
- cqr
->startclk
) >> 12);
818 endtime
= ((cqr
->endclk
- cqr
->stopclk
) >> 12);
819 tottime
= ((cqr
->endclk
- cqr
->buildclk
) >> 12);
820 tottimeps
= tottime
/ sectors
;
822 dasd_profile_counter(sectors
, sectors_ind
);
823 dasd_profile_counter(tottime
, tottime_ind
);
824 dasd_profile_counter(tottimeps
, tottimeps_ind
);
825 dasd_profile_counter(strtime
, strtime_ind
);
826 dasd_profile_counter(irqtime
, irqtime_ind
);
827 dasd_profile_counter(irqtime
/ sectors
, irqtimeps_ind
);
828 dasd_profile_counter(endtime
, endtime_ind
);
830 spin_lock(&dasd_global_profile
.lock
);
831 if (dasd_global_profile
.data
) {
832 data
= dasd_global_profile
.data
;
833 data
->dasd_sum_times
+= tottime
;
834 data
->dasd_sum_time_str
+= strtime
;
835 data
->dasd_sum_time_irq
+= irqtime
;
836 data
->dasd_sum_time_end
+= endtime
;
837 dasd_profile_end_add_data(dasd_global_profile
.data
,
838 cqr
->startdev
!= block
->base
,
840 rq_data_dir(req
) == READ
,
841 sectors
, sectors_ind
, tottime_ind
,
842 tottimeps_ind
, strtime_ind
,
843 irqtime_ind
, irqtimeps_ind
,
846 spin_unlock(&dasd_global_profile
.lock
);
848 spin_lock(&block
->profile
.lock
);
849 if (block
->profile
.data
) {
850 data
= block
->profile
.data
;
851 data
->dasd_sum_times
+= tottime
;
852 data
->dasd_sum_time_str
+= strtime
;
853 data
->dasd_sum_time_irq
+= irqtime
;
854 data
->dasd_sum_time_end
+= endtime
;
855 dasd_profile_end_add_data(block
->profile
.data
,
856 cqr
->startdev
!= block
->base
,
858 rq_data_dir(req
) == READ
,
859 sectors
, sectors_ind
, tottime_ind
,
860 tottimeps_ind
, strtime_ind
,
861 irqtime_ind
, irqtimeps_ind
,
864 spin_unlock(&block
->profile
.lock
);
866 spin_lock(&device
->profile
.lock
);
867 if (device
->profile
.data
) {
868 data
= device
->profile
.data
;
869 data
->dasd_sum_times
+= tottime
;
870 data
->dasd_sum_time_str
+= strtime
;
871 data
->dasd_sum_time_irq
+= irqtime
;
872 data
->dasd_sum_time_end
+= endtime
;
873 dasd_profile_end_add_data(device
->profile
.data
,
874 cqr
->startdev
!= block
->base
,
876 rq_data_dir(req
) == READ
,
877 sectors
, sectors_ind
, tottime_ind
,
878 tottimeps_ind
, strtime_ind
,
879 irqtime_ind
, irqtimeps_ind
,
882 spin_unlock(&device
->profile
.lock
);
885 void dasd_profile_reset(struct dasd_profile
*profile
)
887 struct dasd_profile_info
*data
;
889 spin_lock_bh(&profile
->lock
);
890 data
= profile
->data
;
892 spin_unlock_bh(&profile
->lock
);
895 memset(data
, 0, sizeof(*data
));
896 getnstimeofday(&data
->starttod
);
897 spin_unlock_bh(&profile
->lock
);
900 int dasd_profile_on(struct dasd_profile
*profile
)
902 struct dasd_profile_info
*data
;
904 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
907 spin_lock_bh(&profile
->lock
);
909 spin_unlock_bh(&profile
->lock
);
913 getnstimeofday(&data
->starttod
);
914 profile
->data
= data
;
915 spin_unlock_bh(&profile
->lock
);
919 void dasd_profile_off(struct dasd_profile
*profile
)
921 spin_lock_bh(&profile
->lock
);
922 kfree(profile
->data
);
923 profile
->data
= NULL
;
924 spin_unlock_bh(&profile
->lock
);
927 char *dasd_get_user_string(const char __user
*user_buf
, size_t user_len
)
931 buffer
= vmalloc(user_len
+ 1);
933 return ERR_PTR(-ENOMEM
);
934 if (copy_from_user(buffer
, user_buf
, user_len
) != 0) {
936 return ERR_PTR(-EFAULT
);
938 /* got the string, now strip linefeed. */
939 if (buffer
[user_len
- 1] == '\n')
940 buffer
[user_len
- 1] = 0;
942 buffer
[user_len
] = 0;
946 static ssize_t
dasd_stats_write(struct file
*file
,
947 const char __user
*user_buf
,
948 size_t user_len
, loff_t
*pos
)
952 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
953 struct dasd_profile
*prof
= m
->private;
955 if (user_len
> 65536)
957 buffer
= dasd_get_user_string(user_buf
, user_len
);
959 return PTR_ERR(buffer
);
961 str
= skip_spaces(buffer
);
963 if (strncmp(str
, "reset", 5) == 0) {
964 dasd_profile_reset(prof
);
965 } else if (strncmp(str
, "on", 2) == 0) {
966 rc
= dasd_profile_on(prof
);
970 if (prof
== &dasd_global_profile
) {
971 dasd_profile_reset(prof
);
972 dasd_global_profile_level
= DASD_PROFILE_GLOBAL_ONLY
;
974 } else if (strncmp(str
, "off", 3) == 0) {
975 if (prof
== &dasd_global_profile
)
976 dasd_global_profile_level
= DASD_PROFILE_OFF
;
977 dasd_profile_off(prof
);
985 static void dasd_stats_array(struct seq_file
*m
, unsigned int *array
)
989 for (i
= 0; i
< 32; i
++)
990 seq_printf(m
, "%u ", array
[i
]);
994 static void dasd_stats_seq_print(struct seq_file
*m
,
995 struct dasd_profile_info
*data
)
997 seq_printf(m
, "start_time %ld.%09ld\n",
998 data
->starttod
.tv_sec
, data
->starttod
.tv_nsec
);
999 seq_printf(m
, "total_requests %u\n", data
->dasd_io_reqs
);
1000 seq_printf(m
, "total_sectors %u\n", data
->dasd_io_sects
);
1001 seq_printf(m
, "total_pav %u\n", data
->dasd_io_alias
);
1002 seq_printf(m
, "total_hpf %u\n", data
->dasd_io_tpm
);
1003 seq_printf(m
, "avg_total %lu\n", data
->dasd_io_reqs
?
1004 data
->dasd_sum_times
/ data
->dasd_io_reqs
: 0UL);
1005 seq_printf(m
, "avg_build_to_ssch %lu\n", data
->dasd_io_reqs
?
1006 data
->dasd_sum_time_str
/ data
->dasd_io_reqs
: 0UL);
1007 seq_printf(m
, "avg_ssch_to_irq %lu\n", data
->dasd_io_reqs
?
1008 data
->dasd_sum_time_irq
/ data
->dasd_io_reqs
: 0UL);
1009 seq_printf(m
, "avg_irq_to_end %lu\n", data
->dasd_io_reqs
?
1010 data
->dasd_sum_time_end
/ data
->dasd_io_reqs
: 0UL);
1011 seq_puts(m
, "histogram_sectors ");
1012 dasd_stats_array(m
, data
->dasd_io_secs
);
1013 seq_puts(m
, "histogram_io_times ");
1014 dasd_stats_array(m
, data
->dasd_io_times
);
1015 seq_puts(m
, "histogram_io_times_weighted ");
1016 dasd_stats_array(m
, data
->dasd_io_timps
);
1017 seq_puts(m
, "histogram_time_build_to_ssch ");
1018 dasd_stats_array(m
, data
->dasd_io_time1
);
1019 seq_puts(m
, "histogram_time_ssch_to_irq ");
1020 dasd_stats_array(m
, data
->dasd_io_time2
);
1021 seq_puts(m
, "histogram_time_ssch_to_irq_weighted ");
1022 dasd_stats_array(m
, data
->dasd_io_time2ps
);
1023 seq_puts(m
, "histogram_time_irq_to_end ");
1024 dasd_stats_array(m
, data
->dasd_io_time3
);
1025 seq_puts(m
, "histogram_ccw_queue_length ");
1026 dasd_stats_array(m
, data
->dasd_io_nr_req
);
1027 seq_printf(m
, "total_read_requests %u\n", data
->dasd_read_reqs
);
1028 seq_printf(m
, "total_read_sectors %u\n", data
->dasd_read_sects
);
1029 seq_printf(m
, "total_read_pav %u\n", data
->dasd_read_alias
);
1030 seq_printf(m
, "total_read_hpf %u\n", data
->dasd_read_tpm
);
1031 seq_puts(m
, "histogram_read_sectors ");
1032 dasd_stats_array(m
, data
->dasd_read_secs
);
1033 seq_puts(m
, "histogram_read_times ");
1034 dasd_stats_array(m
, data
->dasd_read_times
);
1035 seq_puts(m
, "histogram_read_time_build_to_ssch ");
1036 dasd_stats_array(m
, data
->dasd_read_time1
);
1037 seq_puts(m
, "histogram_read_time_ssch_to_irq ");
1038 dasd_stats_array(m
, data
->dasd_read_time2
);
1039 seq_puts(m
, "histogram_read_time_irq_to_end ");
1040 dasd_stats_array(m
, data
->dasd_read_time3
);
1041 seq_puts(m
, "histogram_read_ccw_queue_length ");
1042 dasd_stats_array(m
, data
->dasd_read_nr_req
);
1045 static int dasd_stats_show(struct seq_file
*m
, void *v
)
1047 struct dasd_profile
*profile
;
1048 struct dasd_profile_info
*data
;
1050 profile
= m
->private;
1051 spin_lock_bh(&profile
->lock
);
1052 data
= profile
->data
;
1054 spin_unlock_bh(&profile
->lock
);
1055 seq_puts(m
, "disabled\n");
1058 dasd_stats_seq_print(m
, data
);
1059 spin_unlock_bh(&profile
->lock
);
1063 static int dasd_stats_open(struct inode
*inode
, struct file
*file
)
1065 struct dasd_profile
*profile
= inode
->i_private
;
1066 return single_open(file
, dasd_stats_show
, profile
);
1069 static const struct file_operations dasd_stats_raw_fops
= {
1070 .owner
= THIS_MODULE
,
1071 .open
= dasd_stats_open
,
1073 .llseek
= seq_lseek
,
1074 .release
= single_release
,
1075 .write
= dasd_stats_write
,
1078 static void dasd_profile_init(struct dasd_profile
*profile
,
1079 struct dentry
*base_dentry
)
1086 profile
->dentry
= NULL
;
1087 profile
->data
= NULL
;
1088 mode
= (S_IRUSR
| S_IWUSR
| S_IFREG
);
1089 pde
= debugfs_create_file("statistics", mode
, base_dentry
,
1090 profile
, &dasd_stats_raw_fops
);
1091 if (pde
&& !IS_ERR(pde
))
1092 profile
->dentry
= pde
;
1096 static void dasd_profile_exit(struct dasd_profile
*profile
)
1098 dasd_profile_off(profile
);
1099 debugfs_remove(profile
->dentry
);
1100 profile
->dentry
= NULL
;
1103 static void dasd_statistics_removeroot(void)
1105 dasd_global_profile_level
= DASD_PROFILE_OFF
;
1106 dasd_profile_exit(&dasd_global_profile
);
1107 debugfs_remove(dasd_debugfs_global_entry
);
1108 debugfs_remove(dasd_debugfs_root_entry
);
1111 static void dasd_statistics_createroot(void)
1115 dasd_debugfs_root_entry
= NULL
;
1116 pde
= debugfs_create_dir("dasd", NULL
);
1117 if (!pde
|| IS_ERR(pde
))
1119 dasd_debugfs_root_entry
= pde
;
1120 pde
= debugfs_create_dir("global", dasd_debugfs_root_entry
);
1121 if (!pde
|| IS_ERR(pde
))
1123 dasd_debugfs_global_entry
= pde
;
1124 dasd_profile_init(&dasd_global_profile
, dasd_debugfs_global_entry
);
1128 DBF_EVENT(DBF_ERR
, "%s",
1129 "Creation of the dasd debugfs interface failed");
1130 dasd_statistics_removeroot();
1135 #define dasd_profile_start(block, cqr, req) do {} while (0)
1136 #define dasd_profile_end(block, cqr, req) do {} while (0)
1138 static void dasd_statistics_createroot(void)
1143 static void dasd_statistics_removeroot(void)
1148 int dasd_stats_generic_show(struct seq_file
*m
, void *v
)
1150 seq_puts(m
, "Statistics are not activated in this kernel\n");
1154 static void dasd_profile_init(struct dasd_profile
*profile
,
1155 struct dentry
*base_dentry
)
1160 static void dasd_profile_exit(struct dasd_profile
*profile
)
1165 int dasd_profile_on(struct dasd_profile
*profile
)
1170 #endif /* CONFIG_DASD_PROFILE */
1172 static int dasd_hosts_show(struct seq_file
*m
, void *v
)
1174 struct dasd_device
*device
;
1175 int rc
= -EOPNOTSUPP
;
1177 device
= m
->private;
1178 dasd_get_device(device
);
1180 if (device
->discipline
->hosts_print
)
1181 rc
= device
->discipline
->hosts_print(device
, m
);
1183 dasd_put_device(device
);
1187 static int dasd_hosts_open(struct inode
*inode
, struct file
*file
)
1189 struct dasd_device
*device
= inode
->i_private
;
1191 return single_open(file
, dasd_hosts_show
, device
);
1194 static const struct file_operations dasd_hosts_fops
= {
1195 .owner
= THIS_MODULE
,
1196 .open
= dasd_hosts_open
,
1198 .llseek
= seq_lseek
,
1199 .release
= single_release
,
1202 static void dasd_hosts_exit(struct dasd_device
*device
)
1204 debugfs_remove(device
->hosts_dentry
);
1205 device
->hosts_dentry
= NULL
;
1208 static void dasd_hosts_init(struct dentry
*base_dentry
,
1209 struct dasd_device
*device
)
1217 mode
= S_IRUSR
| S_IFREG
;
1218 pde
= debugfs_create_file("host_access_list", mode
, base_dentry
,
1219 device
, &dasd_hosts_fops
);
1220 if (pde
&& !IS_ERR(pde
))
1221 device
->hosts_dentry
= pde
;
1225 * Allocate memory for a channel program with 'cplength' channel
1226 * command words and 'datasize' additional space. There are two
1227 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1228 * memory and 2) dasd_smalloc_request uses the static ccw memory
1229 * that gets allocated for each device.
1231 struct dasd_ccw_req
*dasd_kmalloc_request(int magic
, int cplength
,
1233 struct dasd_device
*device
)
1235 struct dasd_ccw_req
*cqr
;
1238 BUG_ON(datasize
> PAGE_SIZE
||
1239 (cplength
*sizeof(struct ccw1
)) > PAGE_SIZE
);
1241 cqr
= kzalloc(sizeof(struct dasd_ccw_req
), GFP_ATOMIC
);
1243 return ERR_PTR(-ENOMEM
);
1246 cqr
->cpaddr
= kcalloc(cplength
, sizeof(struct ccw1
),
1247 GFP_ATOMIC
| GFP_DMA
);
1248 if (cqr
->cpaddr
== NULL
) {
1250 return ERR_PTR(-ENOMEM
);
1255 cqr
->data
= kzalloc(datasize
, GFP_ATOMIC
| GFP_DMA
);
1256 if (cqr
->data
== NULL
) {
1259 return ERR_PTR(-ENOMEM
);
1263 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1264 dasd_get_device(device
);
1267 EXPORT_SYMBOL(dasd_kmalloc_request
);
1269 struct dasd_ccw_req
*dasd_smalloc_request(int magic
, int cplength
,
1271 struct dasd_device
*device
)
1273 unsigned long flags
;
1274 struct dasd_ccw_req
*cqr
;
1278 size
= (sizeof(struct dasd_ccw_req
) + 7L) & -8L;
1280 size
+= cplength
* sizeof(struct ccw1
);
1283 spin_lock_irqsave(&device
->mem_lock
, flags
);
1284 cqr
= (struct dasd_ccw_req
*)
1285 dasd_alloc_chunk(&device
->ccw_chunks
, size
);
1286 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
1288 return ERR_PTR(-ENOMEM
);
1289 memset(cqr
, 0, sizeof(struct dasd_ccw_req
));
1290 data
= (char *) cqr
+ ((sizeof(struct dasd_ccw_req
) + 7L) & -8L);
1293 cqr
->cpaddr
= (struct ccw1
*) data
;
1294 data
+= cplength
*sizeof(struct ccw1
);
1295 memset(cqr
->cpaddr
, 0, cplength
*sizeof(struct ccw1
));
1300 memset(cqr
->data
, 0, datasize
);
1303 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
1304 dasd_get_device(device
);
1307 EXPORT_SYMBOL(dasd_smalloc_request
);
1310 * Free memory of a channel program. This function needs to free all the
1311 * idal lists that might have been created by dasd_set_cda and the
1312 * struct dasd_ccw_req itself.
1314 void dasd_kfree_request(struct dasd_ccw_req
*cqr
, struct dasd_device
*device
)
1318 /* Clear any idals used for the request. */
1321 clear_normalized_cda(ccw
);
1322 } while (ccw
++->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
));
1326 dasd_put_device(device
);
1328 EXPORT_SYMBOL(dasd_kfree_request
);
1330 void dasd_sfree_request(struct dasd_ccw_req
*cqr
, struct dasd_device
*device
)
1332 unsigned long flags
;
1334 spin_lock_irqsave(&device
->mem_lock
, flags
);
1335 dasd_free_chunk(&device
->ccw_chunks
, cqr
);
1336 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
1337 dasd_put_device(device
);
1339 EXPORT_SYMBOL(dasd_sfree_request
);
1342 * Check discipline magic in cqr.
1344 static inline int dasd_check_cqr(struct dasd_ccw_req
*cqr
)
1346 struct dasd_device
*device
;
1350 device
= cqr
->startdev
;
1351 if (strncmp((char *) &cqr
->magic
, device
->discipline
->ebcname
, 4)) {
1352 DBF_DEV_EVENT(DBF_WARNING
, device
,
1353 " dasd_ccw_req 0x%08x magic doesn't match"
1354 " discipline 0x%08x",
1356 *(unsigned int *) device
->discipline
->name
);
1363 * Terminate the current i/o and set the request to clear_pending.
1364 * Timer keeps device runnig.
1365 * ccw_device_clear can fail if the i/o subsystem
1368 int dasd_term_IO(struct dasd_ccw_req
*cqr
)
1370 struct dasd_device
*device
;
1372 char errorstring
[ERRORLENGTH
];
1375 rc
= dasd_check_cqr(cqr
);
1379 device
= (struct dasd_device
*) cqr
->startdev
;
1380 while ((retries
< 5) && (cqr
->status
== DASD_CQR_IN_IO
)) {
1381 rc
= ccw_device_clear(device
->cdev
, (long) cqr
);
1383 case 0: /* termination successful */
1384 cqr
->status
= DASD_CQR_CLEAR_PENDING
;
1385 cqr
->stopclk
= get_tod_clock();
1387 DBF_DEV_EVENT(DBF_DEBUG
, device
,
1388 "terminate cqr %p successful",
1392 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1393 "device gone, retry");
1396 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1397 "I/O error, retry");
1401 * device not valid so no I/O could be running
1402 * handle CQR as termination successful
1404 cqr
->status
= DASD_CQR_CLEARED
;
1405 cqr
->stopclk
= get_tod_clock();
1407 /* no retries for invalid devices */
1409 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1410 "EINVAL, handle as terminated");
1411 /* fake rc to success */
1415 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
1416 "device busy, retry later");
1419 /* internal error 10 - unknown rc*/
1420 snprintf(errorstring
, ERRORLENGTH
, "10 %d", rc
);
1421 dev_err(&device
->cdev
->dev
, "An error occurred in the "
1422 "DASD device driver, reason=%s\n", errorstring
);
1428 dasd_schedule_device_bh(device
);
1431 EXPORT_SYMBOL(dasd_term_IO
);
1434 * Start the i/o. This start_IO can fail if the channel is really busy.
1435 * In that case set up a timer to start the request later.
1437 int dasd_start_IO(struct dasd_ccw_req
*cqr
)
1439 struct dasd_device
*device
;
1441 char errorstring
[ERRORLENGTH
];
1444 rc
= dasd_check_cqr(cqr
);
1449 device
= (struct dasd_device
*) cqr
->startdev
;
1451 test_bit(DASD_FLAG_LOCK_STOLEN
, &cqr
->block
->base
->flags
)) ||
1452 test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
)) &&
1453 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
1454 DBF_DEV_EVENT(DBF_DEBUG
, device
, "start_IO: return request %p "
1455 "because of stolen lock", cqr
);
1456 cqr
->status
= DASD_CQR_ERROR
;
1457 cqr
->intrc
= -EPERM
;
1460 if (cqr
->retries
< 0) {
1461 /* internal error 14 - start_IO run out of retries */
1462 sprintf(errorstring
, "14 %p", cqr
);
1463 dev_err(&device
->cdev
->dev
, "An error occurred in the DASD "
1464 "device driver, reason=%s\n", errorstring
);
1465 cqr
->status
= DASD_CQR_ERROR
;
1468 cqr
->startclk
= get_tod_clock();
1469 cqr
->starttime
= jiffies
;
1471 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1472 cqr
->lpm
&= dasd_path_get_opm(device
);
1474 cqr
->lpm
= dasd_path_get_opm(device
);
1476 if (cqr
->cpmode
== 1) {
1477 rc
= ccw_device_tm_start(device
->cdev
, cqr
->cpaddr
,
1478 (long) cqr
, cqr
->lpm
);
1480 rc
= ccw_device_start(device
->cdev
, cqr
->cpaddr
,
1481 (long) cqr
, cqr
->lpm
, 0);
1485 cqr
->status
= DASD_CQR_IN_IO
;
1488 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1489 "start_IO: device busy, retry later");
1492 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1493 "start_IO: request timeout, retry later");
1496 /* -EACCES indicates that the request used only a subset of the
1497 * available paths and all these paths are gone. If the lpm of
1498 * this request was only a subset of the opm (e.g. the ppm) then
1499 * we just do a retry with all available paths.
1500 * If we already use the full opm, something is amiss, and we
1501 * need a full path verification.
1503 if (test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
1504 DBF_DEV_EVENT(DBF_WARNING
, device
,
1505 "start_IO: selected paths gone (%x)",
1507 } else if (cqr
->lpm
!= dasd_path_get_opm(device
)) {
1508 cqr
->lpm
= dasd_path_get_opm(device
);
1509 DBF_DEV_EVENT(DBF_DEBUG
, device
, "%s",
1510 "start_IO: selected paths gone,"
1511 " retry on all paths");
1513 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1514 "start_IO: all paths in opm gone,"
1515 " do path verification");
1516 dasd_generic_last_path_gone(device
);
1517 dasd_path_no_path(device
);
1518 dasd_path_set_tbvpm(device
,
1519 ccw_device_get_path_mask(
1524 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1525 "start_IO: -ENODEV device gone, retry");
1528 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1529 "start_IO: -EIO device gone, retry");
1532 /* most likely caused in power management context */
1533 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
1534 "start_IO: -EINVAL device currently "
1538 /* internal error 11 - unknown rc */
1539 snprintf(errorstring
, ERRORLENGTH
, "11 %d", rc
);
1540 dev_err(&device
->cdev
->dev
,
1541 "An error occurred in the DASD device driver, "
1542 "reason=%s\n", errorstring
);
1549 EXPORT_SYMBOL(dasd_start_IO
);
1552 * Timeout function for dasd devices. This is used for different purposes
1553 * 1) missing interrupt handler for normal operation
1554 * 2) delayed start of request where start_IO failed with -EBUSY
1555 * 3) timeout for missing state change interrupts
1556 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1557 * DASD_CQR_QUEUED for 2) and 3).
1559 static void dasd_device_timeout(struct timer_list
*t
)
1561 unsigned long flags
;
1562 struct dasd_device
*device
;
1564 device
= from_timer(device
, t
, timer
);
1565 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1566 /* re-activate request queue */
1567 dasd_device_remove_stop_bits(device
, DASD_STOPPED_PENDING
);
1568 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1569 dasd_schedule_device_bh(device
);
1573 * Setup timeout for a device in jiffies.
1575 void dasd_device_set_timer(struct dasd_device
*device
, int expires
)
1578 del_timer(&device
->timer
);
1580 mod_timer(&device
->timer
, jiffies
+ expires
);
1582 EXPORT_SYMBOL(dasd_device_set_timer
);
1585 * Clear timeout for a device.
1587 void dasd_device_clear_timer(struct dasd_device
*device
)
1589 del_timer(&device
->timer
);
1591 EXPORT_SYMBOL(dasd_device_clear_timer
);
1593 static void dasd_handle_killed_request(struct ccw_device
*cdev
,
1594 unsigned long intparm
)
1596 struct dasd_ccw_req
*cqr
;
1597 struct dasd_device
*device
;
1601 cqr
= (struct dasd_ccw_req
*) intparm
;
1602 if (cqr
->status
!= DASD_CQR_IN_IO
) {
1603 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
,
1604 "invalid status in handle_killed_request: "
1605 "%02x", cqr
->status
);
1609 device
= dasd_device_from_cdev_locked(cdev
);
1610 if (IS_ERR(device
)) {
1611 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1612 "unable to get device from cdev");
1616 if (!cqr
->startdev
||
1617 device
!= cqr
->startdev
||
1618 strncmp(cqr
->startdev
->discipline
->ebcname
,
1619 (char *) &cqr
->magic
, 4)) {
1620 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1621 "invalid device in request");
1622 dasd_put_device(device
);
1626 /* Schedule request to be retried. */
1627 cqr
->status
= DASD_CQR_QUEUED
;
1629 dasd_device_clear_timer(device
);
1630 dasd_schedule_device_bh(device
);
1631 dasd_put_device(device
);
1634 void dasd_generic_handle_state_change(struct dasd_device
*device
)
1636 /* First of all start sense subsystem status request. */
1637 dasd_eer_snss(device
);
1639 dasd_device_remove_stop_bits(device
, DASD_STOPPED_PENDING
);
1640 dasd_schedule_device_bh(device
);
1641 if (device
->block
) {
1642 dasd_schedule_block_bh(device
->block
);
1643 if (device
->block
->request_queue
)
1644 blk_mq_run_hw_queues(device
->block
->request_queue
,
1648 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change
);
1650 static int dasd_check_hpf_error(struct irb
*irb
)
1652 return (scsw_tm_is_valid_schxs(&irb
->scsw
) &&
1653 (irb
->scsw
.tm
.sesq
== SCSW_SESQ_DEV_NOFCX
||
1654 irb
->scsw
.tm
.sesq
== SCSW_SESQ_PATH_NOFCX
));
1658 * Interrupt handler for "normal" ssch-io based dasd devices.
1660 void dasd_int_handler(struct ccw_device
*cdev
, unsigned long intparm
,
1663 struct dasd_ccw_req
*cqr
, *next
;
1664 struct dasd_device
*device
;
1666 int nrf_suppressed
= 0;
1667 int fp_suppressed
= 0;
1671 cqr
= (struct dasd_ccw_req
*) intparm
;
1673 switch (PTR_ERR(irb
)) {
1675 if (cqr
&& cqr
->status
== DASD_CQR_CLEAR_PENDING
) {
1676 device
= cqr
->startdev
;
1677 cqr
->status
= DASD_CQR_CLEARED
;
1678 dasd_device_clear_timer(device
);
1679 wake_up(&dasd_flush_wq
);
1680 dasd_schedule_device_bh(device
);
1685 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s: "
1686 "request timed out\n", __func__
);
1689 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s: "
1690 "unknown error %ld\n", __func__
,
1693 dasd_handle_killed_request(cdev
, intparm
);
1697 now
= get_tod_clock();
1698 /* check for conditions that should be handled immediately */
1700 !(scsw_dstat(&irb
->scsw
) == (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
) &&
1701 scsw_cstat(&irb
->scsw
) == 0)) {
1703 memcpy(&cqr
->irb
, irb
, sizeof(*irb
));
1704 device
= dasd_device_from_cdev_locked(cdev
);
1707 /* ignore unsolicited interrupts for DIAG discipline */
1708 if (device
->discipline
== dasd_diag_discipline_pointer
) {
1709 dasd_put_device(device
);
1714 * In some cases 'File Protected' or 'No Record Found' errors
1715 * might be expected and debug log messages for the
1716 * corresponding interrupts shouldn't be written then.
1717 * Check if either of the according suppress bits is set.
1719 sense
= dasd_get_sense(irb
);
1721 fp_suppressed
= (sense
[1] & SNS1_FILE_PROTECTED
) &&
1722 test_bit(DASD_CQR_SUPPRESS_FP
, &cqr
->flags
);
1723 nrf_suppressed
= (sense
[1] & SNS1_NO_REC_FOUND
) &&
1724 test_bit(DASD_CQR_SUPPRESS_NRF
, &cqr
->flags
);
1726 if (!(fp_suppressed
|| nrf_suppressed
))
1727 device
->discipline
->dump_sense_dbf(device
, irb
, "int");
1729 if (device
->features
& DASD_FEATURE_ERPLOG
)
1730 device
->discipline
->dump_sense(device
, cqr
, irb
);
1731 device
->discipline
->check_for_device_change(device
, cqr
, irb
);
1732 dasd_put_device(device
);
1735 /* check for for attention message */
1736 if (scsw_dstat(&irb
->scsw
) & DEV_STAT_ATTENTION
) {
1737 device
= dasd_device_from_cdev_locked(cdev
);
1738 if (!IS_ERR(device
)) {
1739 device
->discipline
->check_attention(device
,
1740 irb
->esw
.esw1
.lpum
);
1741 dasd_put_device(device
);
1748 device
= (struct dasd_device
*) cqr
->startdev
;
1750 strncmp(device
->discipline
->ebcname
, (char *) &cqr
->magic
, 4)) {
1751 DBF_EVENT_DEVID(DBF_DEBUG
, cdev
, "%s",
1752 "invalid device in request");
1756 /* Check for clear pending */
1757 if (cqr
->status
== DASD_CQR_CLEAR_PENDING
&&
1758 scsw_fctl(&irb
->scsw
) & SCSW_FCTL_CLEAR_FUNC
) {
1759 cqr
->status
= DASD_CQR_CLEARED
;
1760 dasd_device_clear_timer(device
);
1761 wake_up(&dasd_flush_wq
);
1762 dasd_schedule_device_bh(device
);
1766 /* check status - the request might have been killed by dyn detach */
1767 if (cqr
->status
!= DASD_CQR_IN_IO
) {
1768 DBF_DEV_EVENT(DBF_DEBUG
, device
, "invalid status: bus_id %s, "
1769 "status %02x", dev_name(&cdev
->dev
), cqr
->status
);
1775 if (scsw_dstat(&irb
->scsw
) == (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
) &&
1776 scsw_cstat(&irb
->scsw
) == 0) {
1777 /* request was completed successfully */
1778 cqr
->status
= DASD_CQR_SUCCESS
;
1780 /* Start first request on queue if possible -> fast_io. */
1781 if (cqr
->devlist
.next
!= &device
->ccw_queue
) {
1782 next
= list_entry(cqr
->devlist
.next
,
1783 struct dasd_ccw_req
, devlist
);
1785 } else { /* error */
1786 /* check for HPF error
1787 * call discipline function to requeue all requests
1788 * and disable HPF accordingly
1790 if (cqr
->cpmode
&& dasd_check_hpf_error(irb
) &&
1791 device
->discipline
->handle_hpf_error
)
1792 device
->discipline
->handle_hpf_error(device
, irb
);
1794 * If we don't want complex ERP for this request, then just
1795 * reset this and retry it in the fastpath
1797 if (!test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
) &&
1799 if (cqr
->lpm
== dasd_path_get_opm(device
))
1800 DBF_DEV_EVENT(DBF_DEBUG
, device
,
1801 "default ERP in fastpath "
1802 "(%i retries left)",
1804 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
))
1805 cqr
->lpm
= dasd_path_get_opm(device
);
1806 cqr
->status
= DASD_CQR_QUEUED
;
1809 cqr
->status
= DASD_CQR_ERROR
;
1811 if (next
&& (next
->status
== DASD_CQR_QUEUED
) &&
1812 (!device
->stopped
)) {
1813 if (device
->discipline
->start_IO(next
) == 0)
1814 expires
= next
->expires
;
1817 dasd_device_set_timer(device
, expires
);
1819 dasd_device_clear_timer(device
);
1820 dasd_schedule_device_bh(device
);
1822 EXPORT_SYMBOL(dasd_int_handler
);
1824 enum uc_todo
dasd_generic_uc_handler(struct ccw_device
*cdev
, struct irb
*irb
)
1826 struct dasd_device
*device
;
1828 device
= dasd_device_from_cdev_locked(cdev
);
1832 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) ||
1833 device
->state
!= device
->target
||
1834 !device
->discipline
->check_for_device_change
){
1835 dasd_put_device(device
);
1838 if (device
->discipline
->dump_sense_dbf
)
1839 device
->discipline
->dump_sense_dbf(device
, irb
, "uc");
1840 device
->discipline
->check_for_device_change(device
, NULL
, irb
);
1841 dasd_put_device(device
);
1843 return UC_TODO_RETRY
;
1845 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler
);
1848 * If we have an error on a dasd_block layer request then we cancel
1849 * and return all further requests from the same dasd_block as well.
1851 static void __dasd_device_recovery(struct dasd_device
*device
,
1852 struct dasd_ccw_req
*ref_cqr
)
1854 struct list_head
*l
, *n
;
1855 struct dasd_ccw_req
*cqr
;
1858 * only requeue request that came from the dasd_block layer
1860 if (!ref_cqr
->block
)
1863 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1864 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1865 if (cqr
->status
== DASD_CQR_QUEUED
&&
1866 ref_cqr
->block
== cqr
->block
) {
1867 cqr
->status
= DASD_CQR_CLEARED
;
1873 * Remove those ccw requests from the queue that need to be returned
1874 * to the upper layer.
1876 static void __dasd_device_process_ccw_queue(struct dasd_device
*device
,
1877 struct list_head
*final_queue
)
1879 struct list_head
*l
, *n
;
1880 struct dasd_ccw_req
*cqr
;
1882 /* Process request with final status. */
1883 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1884 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1886 /* Skip any non-final request. */
1887 if (cqr
->status
== DASD_CQR_QUEUED
||
1888 cqr
->status
== DASD_CQR_IN_IO
||
1889 cqr
->status
== DASD_CQR_CLEAR_PENDING
)
1891 if (cqr
->status
== DASD_CQR_ERROR
) {
1892 __dasd_device_recovery(device
, cqr
);
1894 /* Rechain finished requests to final queue */
1895 list_move_tail(&cqr
->devlist
, final_queue
);
1900 * the cqrs from the final queue are returned to the upper layer
1901 * by setting a dasd_block state and calling the callback function
1903 static void __dasd_device_process_final_queue(struct dasd_device
*device
,
1904 struct list_head
*final_queue
)
1906 struct list_head
*l
, *n
;
1907 struct dasd_ccw_req
*cqr
;
1908 struct dasd_block
*block
;
1909 void (*callback
)(struct dasd_ccw_req
*, void *data
);
1910 void *callback_data
;
1911 char errorstring
[ERRORLENGTH
];
1913 list_for_each_safe(l
, n
, final_queue
) {
1914 cqr
= list_entry(l
, struct dasd_ccw_req
, devlist
);
1915 list_del_init(&cqr
->devlist
);
1917 callback
= cqr
->callback
;
1918 callback_data
= cqr
->callback_data
;
1920 spin_lock_bh(&block
->queue_lock
);
1921 switch (cqr
->status
) {
1922 case DASD_CQR_SUCCESS
:
1923 cqr
->status
= DASD_CQR_DONE
;
1925 case DASD_CQR_ERROR
:
1926 cqr
->status
= DASD_CQR_NEED_ERP
;
1928 case DASD_CQR_CLEARED
:
1929 cqr
->status
= DASD_CQR_TERMINATED
;
1932 /* internal error 12 - wrong cqr status*/
1933 snprintf(errorstring
, ERRORLENGTH
, "12 %p %x02", cqr
, cqr
->status
);
1934 dev_err(&device
->cdev
->dev
,
1935 "An error occurred in the DASD device driver, "
1936 "reason=%s\n", errorstring
);
1939 if (cqr
->callback
!= NULL
)
1940 (callback
)(cqr
, callback_data
);
1942 spin_unlock_bh(&block
->queue_lock
);
1947 * Take a look at the first request on the ccw queue and check
1948 * if it reached its expire time. If so, terminate the IO.
1950 static void __dasd_device_check_expire(struct dasd_device
*device
)
1952 struct dasd_ccw_req
*cqr
;
1954 if (list_empty(&device
->ccw_queue
))
1956 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
1957 if ((cqr
->status
== DASD_CQR_IN_IO
&& cqr
->expires
!= 0) &&
1958 (time_after_eq(jiffies
, cqr
->expires
+ cqr
->starttime
))) {
1959 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
1961 * IO in safe offline processing should not
1962 * run out of retries
1966 if (device
->discipline
->term_IO(cqr
) != 0) {
1967 /* Hmpf, try again in 5 sec */
1968 dev_err(&device
->cdev
->dev
,
1969 "cqr %p timed out (%lus) but cannot be "
1970 "ended, retrying in 5 s\n",
1971 cqr
, (cqr
->expires
/HZ
));
1972 cqr
->expires
+= 5*HZ
;
1973 dasd_device_set_timer(device
, 5*HZ
);
1975 dev_err(&device
->cdev
->dev
,
1976 "cqr %p timed out (%lus), %i retries "
1977 "remaining\n", cqr
, (cqr
->expires
/HZ
),
1984 * return 1 when device is not eligible for IO
1986 static int __dasd_device_is_unusable(struct dasd_device
*device
,
1987 struct dasd_ccw_req
*cqr
)
1989 int mask
= ~(DASD_STOPPED_DC_WAIT
| DASD_UNRESUMED_PM
);
1991 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
1992 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
1994 * dasd is being set offline
1995 * but it is no safe offline where we have to allow I/O
1999 if (device
->stopped
) {
2000 if (device
->stopped
& mask
) {
2001 /* stopped and CQR will not change that. */
2004 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
2005 /* CQR is not able to change device to
2009 /* CQR required to get device operational. */
2015 * Take a look at the first request on the ccw queue and check
2016 * if it needs to be started.
2018 static void __dasd_device_start_head(struct dasd_device
*device
)
2020 struct dasd_ccw_req
*cqr
;
2023 if (list_empty(&device
->ccw_queue
))
2025 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
2026 if (cqr
->status
!= DASD_CQR_QUEUED
)
2028 /* if device is not usable return request to upper layer */
2029 if (__dasd_device_is_unusable(device
, cqr
)) {
2030 cqr
->intrc
= -EAGAIN
;
2031 cqr
->status
= DASD_CQR_CLEARED
;
2032 dasd_schedule_device_bh(device
);
2036 rc
= device
->discipline
->start_IO(cqr
);
2038 dasd_device_set_timer(device
, cqr
->expires
);
2039 else if (rc
== -EACCES
) {
2040 dasd_schedule_device_bh(device
);
2042 /* Hmpf, try again in 1/2 sec */
2043 dasd_device_set_timer(device
, 50);
2046 static void __dasd_device_check_path_events(struct dasd_device
*device
)
2050 if (!dasd_path_get_tbvpm(device
))
2053 if (device
->stopped
&
2054 ~(DASD_STOPPED_DC_WAIT
| DASD_UNRESUMED_PM
))
2056 rc
= device
->discipline
->verify_path(device
,
2057 dasd_path_get_tbvpm(device
));
2059 dasd_device_set_timer(device
, 50);
2061 dasd_path_clear_all_verify(device
);
2065 * Go through all request on the dasd_device request queue,
2066 * terminate them on the cdev if necessary, and return them to the
2067 * submitting layer via callback.
2069 * Make sure that all 'submitting layers' still exist when
2070 * this function is called!. In other words, when 'device' is a base
2071 * device then all block layer requests must have been removed before
2072 * via dasd_flush_block_queue.
2074 int dasd_flush_device_queue(struct dasd_device
*device
)
2076 struct dasd_ccw_req
*cqr
, *n
;
2078 struct list_head flush_queue
;
2080 INIT_LIST_HEAD(&flush_queue
);
2081 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2083 list_for_each_entry_safe(cqr
, n
, &device
->ccw_queue
, devlist
) {
2084 /* Check status and move request to flush_queue */
2085 switch (cqr
->status
) {
2086 case DASD_CQR_IN_IO
:
2087 rc
= device
->discipline
->term_IO(cqr
);
2089 /* unable to terminate requeust */
2090 dev_err(&device
->cdev
->dev
,
2091 "Flushing the DASD request queue "
2092 "failed for request %p\n", cqr
);
2093 /* stop flush processing */
2097 case DASD_CQR_QUEUED
:
2098 cqr
->stopclk
= get_tod_clock();
2099 cqr
->status
= DASD_CQR_CLEARED
;
2101 default: /* no need to modify the others */
2104 list_move_tail(&cqr
->devlist
, &flush_queue
);
2107 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2109 * After this point all requests must be in state CLEAR_PENDING,
2110 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2111 * one of the others.
2113 list_for_each_entry_safe(cqr
, n
, &flush_queue
, devlist
)
2114 wait_event(dasd_flush_wq
,
2115 (cqr
->status
!= DASD_CQR_CLEAR_PENDING
));
2117 * Now set each request back to TERMINATED, DONE or NEED_ERP
2118 * and call the callback function of flushed requests
2120 __dasd_device_process_final_queue(device
, &flush_queue
);
2123 EXPORT_SYMBOL_GPL(dasd_flush_device_queue
);
2126 * Acquire the device lock and process queues for the device.
2128 static void dasd_device_tasklet(struct dasd_device
*device
)
2130 struct list_head final_queue
;
2132 atomic_set (&device
->tasklet_scheduled
, 0);
2133 INIT_LIST_HEAD(&final_queue
);
2134 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2135 /* Check expire time of first request on the ccw queue. */
2136 __dasd_device_check_expire(device
);
2137 /* find final requests on ccw queue */
2138 __dasd_device_process_ccw_queue(device
, &final_queue
);
2139 __dasd_device_check_path_events(device
);
2140 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2141 /* Now call the callback function of requests with final status */
2142 __dasd_device_process_final_queue(device
, &final_queue
);
2143 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2144 /* Now check if the head of the ccw queue needs to be started. */
2145 __dasd_device_start_head(device
);
2146 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2147 if (waitqueue_active(&shutdown_waitq
))
2148 wake_up(&shutdown_waitq
);
2149 dasd_put_device(device
);
2153 * Schedules a call to dasd_tasklet over the device tasklet.
2155 void dasd_schedule_device_bh(struct dasd_device
*device
)
2157 /* Protect against rescheduling. */
2158 if (atomic_cmpxchg (&device
->tasklet_scheduled
, 0, 1) != 0)
2160 dasd_get_device(device
);
2161 tasklet_hi_schedule(&device
->tasklet
);
2163 EXPORT_SYMBOL(dasd_schedule_device_bh
);
2165 void dasd_device_set_stop_bits(struct dasd_device
*device
, int bits
)
2167 device
->stopped
|= bits
;
2169 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits
);
2171 void dasd_device_remove_stop_bits(struct dasd_device
*device
, int bits
)
2173 device
->stopped
&= ~bits
;
2174 if (!device
->stopped
)
2175 wake_up(&generic_waitq
);
2177 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits
);
2180 * Queue a request to the head of the device ccw_queue.
2181 * Start the I/O if possible.
2183 void dasd_add_request_head(struct dasd_ccw_req
*cqr
)
2185 struct dasd_device
*device
;
2186 unsigned long flags
;
2188 device
= cqr
->startdev
;
2189 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2190 cqr
->status
= DASD_CQR_QUEUED
;
2191 list_add(&cqr
->devlist
, &device
->ccw_queue
);
2192 /* let the bh start the request to keep them in order */
2193 dasd_schedule_device_bh(device
);
2194 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2196 EXPORT_SYMBOL(dasd_add_request_head
);
2199 * Queue a request to the tail of the device ccw_queue.
2200 * Start the I/O if possible.
2202 void dasd_add_request_tail(struct dasd_ccw_req
*cqr
)
2204 struct dasd_device
*device
;
2205 unsigned long flags
;
2207 device
= cqr
->startdev
;
2208 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2209 cqr
->status
= DASD_CQR_QUEUED
;
2210 list_add_tail(&cqr
->devlist
, &device
->ccw_queue
);
2211 /* let the bh start the request to keep them in order */
2212 dasd_schedule_device_bh(device
);
2213 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2215 EXPORT_SYMBOL(dasd_add_request_tail
);
2218 * Wakeup helper for the 'sleep_on' functions.
2220 void dasd_wakeup_cb(struct dasd_ccw_req
*cqr
, void *data
)
2222 spin_lock_irq(get_ccwdev_lock(cqr
->startdev
->cdev
));
2223 cqr
->callback_data
= DASD_SLEEPON_END_TAG
;
2224 spin_unlock_irq(get_ccwdev_lock(cqr
->startdev
->cdev
));
2225 wake_up(&generic_waitq
);
2227 EXPORT_SYMBOL_GPL(dasd_wakeup_cb
);
2229 static inline int _wait_for_wakeup(struct dasd_ccw_req
*cqr
)
2231 struct dasd_device
*device
;
2234 device
= cqr
->startdev
;
2235 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2236 rc
= (cqr
->callback_data
== DASD_SLEEPON_END_TAG
);
2237 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2242 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2244 static int __dasd_sleep_on_erp(struct dasd_ccw_req
*cqr
)
2246 struct dasd_device
*device
;
2247 dasd_erp_fn_t erp_fn
;
2249 if (cqr
->status
== DASD_CQR_FILLED
)
2251 device
= cqr
->startdev
;
2252 if (test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
)) {
2253 if (cqr
->status
== DASD_CQR_TERMINATED
) {
2254 device
->discipline
->handle_terminated_request(cqr
);
2257 if (cqr
->status
== DASD_CQR_NEED_ERP
) {
2258 erp_fn
= device
->discipline
->erp_action(cqr
);
2262 if (cqr
->status
== DASD_CQR_FAILED
)
2263 dasd_log_sense(cqr
, &cqr
->irb
);
2265 __dasd_process_erp(device
, cqr
);
2272 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req
*cqr
)
2274 if (test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
)) {
2275 if (cqr
->refers
) /* erp is not done yet */
2277 return ((cqr
->status
!= DASD_CQR_DONE
) &&
2278 (cqr
->status
!= DASD_CQR_FAILED
));
2280 return (cqr
->status
== DASD_CQR_FILLED
);
2283 static int _dasd_sleep_on(struct dasd_ccw_req
*maincqr
, int interruptible
)
2285 struct dasd_device
*device
;
2287 struct list_head ccw_queue
;
2288 struct dasd_ccw_req
*cqr
;
2290 INIT_LIST_HEAD(&ccw_queue
);
2291 maincqr
->status
= DASD_CQR_FILLED
;
2292 device
= maincqr
->startdev
;
2293 list_add(&maincqr
->blocklist
, &ccw_queue
);
2294 for (cqr
= maincqr
; __dasd_sleep_on_loop_condition(cqr
);
2295 cqr
= list_first_entry(&ccw_queue
,
2296 struct dasd_ccw_req
, blocklist
)) {
2298 if (__dasd_sleep_on_erp(cqr
))
2300 if (cqr
->status
!= DASD_CQR_FILLED
) /* could be failed */
2302 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2303 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2304 cqr
->status
= DASD_CQR_FAILED
;
2305 cqr
->intrc
= -EPERM
;
2308 /* Non-temporary stop condition will trigger fail fast */
2309 if (device
->stopped
& ~DASD_STOPPED_PENDING
&&
2310 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2311 (!dasd_eer_enabled(device
))) {
2312 cqr
->status
= DASD_CQR_FAILED
;
2313 cqr
->intrc
= -ENOLINK
;
2317 * Don't try to start requests if device is in
2318 * offline processing, it might wait forever
2320 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
2321 cqr
->status
= DASD_CQR_FAILED
;
2322 cqr
->intrc
= -ENODEV
;
2326 * Don't try to start requests if device is stopped
2327 * except path verification requests
2329 if (!test_bit(DASD_CQR_VERIFY_PATH
, &cqr
->flags
)) {
2330 if (interruptible
) {
2331 rc
= wait_event_interruptible(
2332 generic_waitq
, !(device
->stopped
));
2333 if (rc
== -ERESTARTSYS
) {
2334 cqr
->status
= DASD_CQR_FAILED
;
2335 maincqr
->intrc
= rc
;
2339 wait_event(generic_waitq
, !(device
->stopped
));
2342 cqr
->callback
= dasd_wakeup_cb
;
2344 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2345 dasd_add_request_tail(cqr
);
2346 if (interruptible
) {
2347 rc
= wait_event_interruptible(
2348 generic_waitq
, _wait_for_wakeup(cqr
));
2349 if (rc
== -ERESTARTSYS
) {
2350 dasd_cancel_req(cqr
);
2351 /* wait (non-interruptible) for final status */
2352 wait_event(generic_waitq
,
2353 _wait_for_wakeup(cqr
));
2354 cqr
->status
= DASD_CQR_FAILED
;
2355 maincqr
->intrc
= rc
;
2359 wait_event(generic_waitq
, _wait_for_wakeup(cqr
));
2362 maincqr
->endclk
= get_tod_clock();
2363 if ((maincqr
->status
!= DASD_CQR_DONE
) &&
2364 (maincqr
->intrc
!= -ERESTARTSYS
))
2365 dasd_log_sense(maincqr
, &maincqr
->irb
);
2366 if (maincqr
->status
== DASD_CQR_DONE
)
2368 else if (maincqr
->intrc
)
2369 rc
= maincqr
->intrc
;
2375 static inline int _wait_for_wakeup_queue(struct list_head
*ccw_queue
)
2377 struct dasd_ccw_req
*cqr
;
2379 list_for_each_entry(cqr
, ccw_queue
, blocklist
) {
2380 if (cqr
->callback_data
!= DASD_SLEEPON_END_TAG
)
2387 static int _dasd_sleep_on_queue(struct list_head
*ccw_queue
, int interruptible
)
2389 struct dasd_device
*device
;
2390 struct dasd_ccw_req
*cqr
, *n
;
2395 list_for_each_entry_safe(cqr
, n
, ccw_queue
, blocklist
) {
2396 device
= cqr
->startdev
;
2397 if (cqr
->status
!= DASD_CQR_FILLED
) /*could be failed*/
2400 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2401 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2402 cqr
->status
= DASD_CQR_FAILED
;
2403 cqr
->intrc
= -EPERM
;
2406 /*Non-temporary stop condition will trigger fail fast*/
2407 if (device
->stopped
& ~DASD_STOPPED_PENDING
&&
2408 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2409 !dasd_eer_enabled(device
)) {
2410 cqr
->status
= DASD_CQR_FAILED
;
2411 cqr
->intrc
= -EAGAIN
;
2415 /*Don't try to start requests if device is stopped*/
2416 if (interruptible
) {
2417 rc
= wait_event_interruptible(
2418 generic_waitq
, !device
->stopped
);
2419 if (rc
== -ERESTARTSYS
) {
2420 cqr
->status
= DASD_CQR_FAILED
;
2425 wait_event(generic_waitq
, !(device
->stopped
));
2428 cqr
->callback
= dasd_wakeup_cb
;
2429 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2430 dasd_add_request_tail(cqr
);
2433 wait_event(generic_waitq
, _wait_for_wakeup_queue(ccw_queue
));
2436 list_for_each_entry_safe(cqr
, n
, ccw_queue
, blocklist
) {
2438 * In some cases the 'File Protected' or 'Incorrect Length'
2439 * error might be expected and error recovery would be
2440 * unnecessary in these cases. Check if the according suppress
2443 sense
= dasd_get_sense(&cqr
->irb
);
2444 if (sense
&& sense
[1] & SNS1_FILE_PROTECTED
&&
2445 test_bit(DASD_CQR_SUPPRESS_FP
, &cqr
->flags
))
2447 if (scsw_cstat(&cqr
->irb
.scsw
) == 0x40 &&
2448 test_bit(DASD_CQR_SUPPRESS_IL
, &cqr
->flags
))
2452 * for alias devices simplify error recovery and
2453 * return to upper layer
2454 * do not skip ERP requests
2456 if (cqr
->startdev
!= cqr
->basedev
&& !cqr
->refers
&&
2457 (cqr
->status
== DASD_CQR_TERMINATED
||
2458 cqr
->status
== DASD_CQR_NEED_ERP
))
2461 /* normal recovery for basedev IO */
2462 if (__dasd_sleep_on_erp(cqr
))
2463 /* handle erp first */
2471 * Queue a request to the tail of the device ccw_queue and wait for
2474 int dasd_sleep_on(struct dasd_ccw_req
*cqr
)
2476 return _dasd_sleep_on(cqr
, 0);
2478 EXPORT_SYMBOL(dasd_sleep_on
);
2481 * Start requests from a ccw_queue and wait for their completion.
2483 int dasd_sleep_on_queue(struct list_head
*ccw_queue
)
2485 return _dasd_sleep_on_queue(ccw_queue
, 0);
2487 EXPORT_SYMBOL(dasd_sleep_on_queue
);
2490 * Queue a request to the tail of the device ccw_queue and wait
2491 * interruptible for it's completion.
2493 int dasd_sleep_on_interruptible(struct dasd_ccw_req
*cqr
)
2495 return _dasd_sleep_on(cqr
, 1);
2497 EXPORT_SYMBOL(dasd_sleep_on_interruptible
);
2500 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2501 * for eckd devices) the currently running request has to be terminated
2502 * and be put back to status queued, before the special request is added
2503 * to the head of the queue. Then the special request is waited on normally.
2505 static inline int _dasd_term_running_cqr(struct dasd_device
*device
)
2507 struct dasd_ccw_req
*cqr
;
2510 if (list_empty(&device
->ccw_queue
))
2512 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, devlist
);
2513 rc
= device
->discipline
->term_IO(cqr
);
2516 * CQR terminated because a more important request is pending.
2517 * Undo decreasing of retry counter because this is
2518 * not an error case.
2524 int dasd_sleep_on_immediatly(struct dasd_ccw_req
*cqr
)
2526 struct dasd_device
*device
;
2529 device
= cqr
->startdev
;
2530 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &device
->flags
) &&
2531 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2532 cqr
->status
= DASD_CQR_FAILED
;
2533 cqr
->intrc
= -EPERM
;
2536 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
2537 rc
= _dasd_term_running_cqr(device
);
2539 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2542 cqr
->callback
= dasd_wakeup_cb
;
2543 cqr
->callback_data
= DASD_SLEEPON_START_TAG
;
2544 cqr
->status
= DASD_CQR_QUEUED
;
2546 * add new request as second
2547 * first the terminated cqr needs to be finished
2549 list_add(&cqr
->devlist
, device
->ccw_queue
.next
);
2551 /* let the bh start the request to keep them in order */
2552 dasd_schedule_device_bh(device
);
2554 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
2556 wait_event(generic_waitq
, _wait_for_wakeup(cqr
));
2558 if (cqr
->status
== DASD_CQR_DONE
)
2560 else if (cqr
->intrc
)
2566 dasd_schedule_device_bh(device
);
2568 dasd_schedule_block_bh(device
->block
);
2572 EXPORT_SYMBOL(dasd_sleep_on_immediatly
);
2575 * Cancels a request that was started with dasd_sleep_on_req.
2576 * This is useful to timeout requests. The request will be
2577 * terminated if it is currently in i/o.
2578 * Returns 0 if request termination was successful
2579 * negative error code if termination failed
2580 * Cancellation of a request is an asynchronous operation! The calling
2581 * function has to wait until the request is properly returned via callback.
2583 int dasd_cancel_req(struct dasd_ccw_req
*cqr
)
2585 struct dasd_device
*device
= cqr
->startdev
;
2586 unsigned long flags
;
2590 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
2591 switch (cqr
->status
) {
2592 case DASD_CQR_QUEUED
:
2593 /* request was not started - just set to cleared */
2594 cqr
->status
= DASD_CQR_CLEARED
;
2595 if (cqr
->callback_data
== DASD_SLEEPON_START_TAG
)
2596 cqr
->callback_data
= DASD_SLEEPON_END_TAG
;
2598 case DASD_CQR_IN_IO
:
2599 /* request in IO - terminate IO and release again */
2600 rc
= device
->discipline
->term_IO(cqr
);
2602 dev_err(&device
->cdev
->dev
,
2603 "Cancelling request %p failed with rc=%d\n",
2606 cqr
->stopclk
= get_tod_clock();
2609 default: /* already finished or clear pending - do nothing */
2612 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
2613 dasd_schedule_device_bh(device
);
2616 EXPORT_SYMBOL(dasd_cancel_req
);
2619 * SECTION: Operations of the dasd_block layer.
2623 * Timeout function for dasd_block. This is used when the block layer
2624 * is waiting for something that may not come reliably, (e.g. a state
2627 static void dasd_block_timeout(struct timer_list
*t
)
2629 unsigned long flags
;
2630 struct dasd_block
*block
;
2632 block
= from_timer(block
, t
, timer
);
2633 spin_lock_irqsave(get_ccwdev_lock(block
->base
->cdev
), flags
);
2634 /* re-activate request queue */
2635 dasd_device_remove_stop_bits(block
->base
, DASD_STOPPED_PENDING
);
2636 spin_unlock_irqrestore(get_ccwdev_lock(block
->base
->cdev
), flags
);
2637 dasd_schedule_block_bh(block
);
2638 blk_mq_run_hw_queues(block
->request_queue
, true);
2642 * Setup timeout for a dasd_block in jiffies.
2644 void dasd_block_set_timer(struct dasd_block
*block
, int expires
)
2647 del_timer(&block
->timer
);
2649 mod_timer(&block
->timer
, jiffies
+ expires
);
2651 EXPORT_SYMBOL(dasd_block_set_timer
);
2654 * Clear timeout for a dasd_block.
2656 void dasd_block_clear_timer(struct dasd_block
*block
)
2658 del_timer(&block
->timer
);
2660 EXPORT_SYMBOL(dasd_block_clear_timer
);
2663 * Process finished error recovery ccw.
2665 static void __dasd_process_erp(struct dasd_device
*device
,
2666 struct dasd_ccw_req
*cqr
)
2668 dasd_erp_fn_t erp_fn
;
2670 if (cqr
->status
== DASD_CQR_DONE
)
2671 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s", "ERP successful");
2673 dev_err(&device
->cdev
->dev
, "ERP failed for the DASD\n");
2674 erp_fn
= device
->discipline
->erp_postaction(cqr
);
2678 static void __dasd_cleanup_cqr(struct dasd_ccw_req
*cqr
)
2680 struct request
*req
;
2681 blk_status_t error
= BLK_STS_OK
;
2684 req
= (struct request
*) cqr
->callback_data
;
2685 dasd_profile_end(cqr
->block
, cqr
, req
);
2687 status
= cqr
->block
->base
->discipline
->free_cp(cqr
, req
);
2689 error
= errno_to_blk_status(status
);
2690 else if (status
== 0) {
2691 switch (cqr
->intrc
) {
2693 error
= BLK_STS_NEXUS
;
2696 error
= BLK_STS_TRANSPORT
;
2699 error
= BLK_STS_TIMEOUT
;
2702 error
= BLK_STS_IOERR
;
2708 * We need to take care for ETIMEDOUT errors here since the
2709 * complete callback does not get called in this case.
2710 * Take care of all errors here and avoid additional code to
2711 * transfer the error value to the complete callback.
2714 blk_mq_end_request(req
, error
);
2715 blk_mq_run_hw_queues(req
->q
, true);
2717 blk_mq_complete_request(req
);
2722 * Process ccw request queue.
2724 static void __dasd_process_block_ccw_queue(struct dasd_block
*block
,
2725 struct list_head
*final_queue
)
2727 struct list_head
*l
, *n
;
2728 struct dasd_ccw_req
*cqr
;
2729 dasd_erp_fn_t erp_fn
;
2730 unsigned long flags
;
2731 struct dasd_device
*base
= block
->base
;
2734 /* Process request with final status. */
2735 list_for_each_safe(l
, n
, &block
->ccw_queue
) {
2736 cqr
= list_entry(l
, struct dasd_ccw_req
, blocklist
);
2737 if (cqr
->status
!= DASD_CQR_DONE
&&
2738 cqr
->status
!= DASD_CQR_FAILED
&&
2739 cqr
->status
!= DASD_CQR_NEED_ERP
&&
2740 cqr
->status
!= DASD_CQR_TERMINATED
)
2743 if (cqr
->status
== DASD_CQR_TERMINATED
) {
2744 base
->discipline
->handle_terminated_request(cqr
);
2748 /* Process requests that may be recovered */
2749 if (cqr
->status
== DASD_CQR_NEED_ERP
) {
2750 erp_fn
= base
->discipline
->erp_action(cqr
);
2751 if (IS_ERR(erp_fn(cqr
)))
2756 /* log sense for fatal error */
2757 if (cqr
->status
== DASD_CQR_FAILED
) {
2758 dasd_log_sense(cqr
, &cqr
->irb
);
2761 /* First of all call extended error reporting. */
2762 if (dasd_eer_enabled(base
) &&
2763 cqr
->status
== DASD_CQR_FAILED
) {
2764 dasd_eer_write(base
, cqr
, DASD_EER_FATALERROR
);
2766 /* restart request */
2767 cqr
->status
= DASD_CQR_FILLED
;
2769 spin_lock_irqsave(get_ccwdev_lock(base
->cdev
), flags
);
2770 dasd_device_set_stop_bits(base
, DASD_STOPPED_QUIESCE
);
2771 spin_unlock_irqrestore(get_ccwdev_lock(base
->cdev
),
2776 /* Process finished ERP request. */
2778 __dasd_process_erp(base
, cqr
);
2782 /* Rechain finished requests to final queue */
2783 cqr
->endclk
= get_tod_clock();
2784 list_move_tail(&cqr
->blocklist
, final_queue
);
2788 static void dasd_return_cqr_cb(struct dasd_ccw_req
*cqr
, void *data
)
2790 dasd_schedule_block_bh(cqr
->block
);
2793 static void __dasd_block_start_head(struct dasd_block
*block
)
2795 struct dasd_ccw_req
*cqr
;
2797 if (list_empty(&block
->ccw_queue
))
2799 /* We allways begin with the first requests on the queue, as some
2800 * of previously started requests have to be enqueued on a
2801 * dasd_device again for error recovery.
2803 list_for_each_entry(cqr
, &block
->ccw_queue
, blocklist
) {
2804 if (cqr
->status
!= DASD_CQR_FILLED
)
2806 if (test_bit(DASD_FLAG_LOCK_STOLEN
, &block
->base
->flags
) &&
2807 !test_bit(DASD_CQR_ALLOW_SLOCK
, &cqr
->flags
)) {
2808 cqr
->status
= DASD_CQR_FAILED
;
2809 cqr
->intrc
= -EPERM
;
2810 dasd_schedule_block_bh(block
);
2813 /* Non-temporary stop condition will trigger fail fast */
2814 if (block
->base
->stopped
& ~DASD_STOPPED_PENDING
&&
2815 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
2816 (!dasd_eer_enabled(block
->base
))) {
2817 cqr
->status
= DASD_CQR_FAILED
;
2818 cqr
->intrc
= -ENOLINK
;
2819 dasd_schedule_block_bh(block
);
2822 /* Don't try to start requests if device is stopped */
2823 if (block
->base
->stopped
)
2826 /* just a fail safe check, should not happen */
2828 cqr
->startdev
= block
->base
;
2830 /* make sure that the requests we submit find their way back */
2831 cqr
->callback
= dasd_return_cqr_cb
;
2833 dasd_add_request_tail(cqr
);
2838 * Central dasd_block layer routine. Takes requests from the generic
2839 * block layer request queue, creates ccw requests, enqueues them on
2840 * a dasd_device and processes ccw requests that have been returned.
2842 static void dasd_block_tasklet(struct dasd_block
*block
)
2844 struct list_head final_queue
;
2845 struct list_head
*l
, *n
;
2846 struct dasd_ccw_req
*cqr
;
2847 struct dasd_queue
*dq
;
2849 atomic_set(&block
->tasklet_scheduled
, 0);
2850 INIT_LIST_HEAD(&final_queue
);
2851 spin_lock_irq(&block
->queue_lock
);
2852 /* Finish off requests on ccw queue */
2853 __dasd_process_block_ccw_queue(block
, &final_queue
);
2854 spin_unlock_irq(&block
->queue_lock
);
2856 /* Now call the callback function of requests with final status */
2857 list_for_each_safe(l
, n
, &final_queue
) {
2858 cqr
= list_entry(l
, struct dasd_ccw_req
, blocklist
);
2860 spin_lock_irq(&dq
->lock
);
2861 list_del_init(&cqr
->blocklist
);
2862 __dasd_cleanup_cqr(cqr
);
2863 spin_unlock_irq(&dq
->lock
);
2866 spin_lock_irq(&block
->queue_lock
);
2867 /* Now check if the head of the ccw queue needs to be started. */
2868 __dasd_block_start_head(block
);
2869 spin_unlock_irq(&block
->queue_lock
);
2871 if (waitqueue_active(&shutdown_waitq
))
2872 wake_up(&shutdown_waitq
);
2873 dasd_put_device(block
->base
);
2876 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req
*cqr
, void *data
)
2878 wake_up(&dasd_flush_wq
);
2882 * Requeue a request back to the block request queue
2883 * only works for block requests
2885 static int _dasd_requeue_request(struct dasd_ccw_req
*cqr
)
2887 struct dasd_block
*block
= cqr
->block
;
2888 struct request
*req
;
2892 spin_lock_irq(&cqr
->dq
->lock
);
2893 req
= (struct request
*) cqr
->callback_data
;
2894 blk_mq_requeue_request(req
, false);
2895 spin_unlock_irq(&cqr
->dq
->lock
);
2901 * Go through all request on the dasd_block request queue, cancel them
2902 * on the respective dasd_device, and return them to the generic
2905 static int dasd_flush_block_queue(struct dasd_block
*block
)
2907 struct dasd_ccw_req
*cqr
, *n
;
2909 struct list_head flush_queue
;
2910 unsigned long flags
;
2912 INIT_LIST_HEAD(&flush_queue
);
2913 spin_lock_bh(&block
->queue_lock
);
2916 list_for_each_entry_safe(cqr
, n
, &block
->ccw_queue
, blocklist
) {
2917 /* if this request currently owned by a dasd_device cancel it */
2918 if (cqr
->status
>= DASD_CQR_QUEUED
)
2919 rc
= dasd_cancel_req(cqr
);
2922 /* Rechain request (including erp chain) so it won't be
2923 * touched by the dasd_block_tasklet anymore.
2924 * Replace the callback so we notice when the request
2925 * is returned from the dasd_device layer.
2927 cqr
->callback
= _dasd_wake_block_flush_cb
;
2928 for (i
= 0; cqr
!= NULL
; cqr
= cqr
->refers
, i
++)
2929 list_move_tail(&cqr
->blocklist
, &flush_queue
);
2931 /* moved more than one request - need to restart */
2934 spin_unlock_bh(&block
->queue_lock
);
2935 /* Now call the callback function of flushed requests */
2937 list_for_each_entry_safe(cqr
, n
, &flush_queue
, blocklist
) {
2938 wait_event(dasd_flush_wq
, (cqr
->status
< DASD_CQR_QUEUED
));
2939 /* Process finished ERP request. */
2941 spin_lock_bh(&block
->queue_lock
);
2942 __dasd_process_erp(block
->base
, cqr
);
2943 spin_unlock_bh(&block
->queue_lock
);
2944 /* restart list_for_xx loop since dasd_process_erp
2945 * might remove multiple elements */
2948 /* call the callback function */
2949 spin_lock_irqsave(&cqr
->dq
->lock
, flags
);
2950 cqr
->endclk
= get_tod_clock();
2951 list_del_init(&cqr
->blocklist
);
2952 __dasd_cleanup_cqr(cqr
);
2953 spin_unlock_irqrestore(&cqr
->dq
->lock
, flags
);
2959 * Schedules a call to dasd_tasklet over the device tasklet.
2961 void dasd_schedule_block_bh(struct dasd_block
*block
)
2963 /* Protect against rescheduling. */
2964 if (atomic_cmpxchg(&block
->tasklet_scheduled
, 0, 1) != 0)
2966 /* life cycle of block is bound to it's base device */
2967 dasd_get_device(block
->base
);
2968 tasklet_hi_schedule(&block
->tasklet
);
2970 EXPORT_SYMBOL(dasd_schedule_block_bh
);
2974 * SECTION: external block device operations
2975 * (request queue handling, open, release, etc.)
2979 * Dasd request queue function. Called from ll_rw_blk.c
2981 static blk_status_t
do_dasd_request(struct blk_mq_hw_ctx
*hctx
,
2982 const struct blk_mq_queue_data
*qd
)
2984 struct dasd_block
*block
= hctx
->queue
->queuedata
;
2985 struct dasd_queue
*dq
= hctx
->driver_data
;
2986 struct request
*req
= qd
->rq
;
2987 struct dasd_device
*basedev
;
2988 struct dasd_ccw_req
*cqr
;
2989 blk_status_t rc
= BLK_STS_OK
;
2991 basedev
= block
->base
;
2992 spin_lock_irq(&dq
->lock
);
2993 if (basedev
->state
< DASD_STATE_READY
) {
2994 DBF_DEV_EVENT(DBF_ERR
, basedev
,
2995 "device not ready for request %p", req
);
3001 * if device is stopped do not fetch new requests
3002 * except failfast is active which will let requests fail
3003 * immediately in __dasd_block_start_head()
3005 if (basedev
->stopped
&& !(basedev
->features
& DASD_FEATURE_FAILFAST
)) {
3006 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3007 "device stopped request %p", req
);
3008 rc
= BLK_STS_RESOURCE
;
3012 if (basedev
->features
& DASD_FEATURE_READONLY
&&
3013 rq_data_dir(req
) == WRITE
) {
3014 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3015 "Rejecting write request %p", req
);
3020 if (test_bit(DASD_FLAG_ABORTALL
, &basedev
->flags
) &&
3021 (basedev
->features
& DASD_FEATURE_FAILFAST
||
3022 blk_noretry_request(req
))) {
3023 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3024 "Rejecting failfast request %p", req
);
3029 cqr
= basedev
->discipline
->build_cp(basedev
, block
, req
);
3031 if (PTR_ERR(cqr
) == -EBUSY
||
3032 PTR_ERR(cqr
) == -ENOMEM
||
3033 PTR_ERR(cqr
) == -EAGAIN
) {
3034 rc
= BLK_STS_RESOURCE
;
3037 DBF_DEV_EVENT(DBF_ERR
, basedev
,
3038 "CCW creation failed (rc=%ld) on request %p",
3044 * Note: callback is set to dasd_return_cqr_cb in
3045 * __dasd_block_start_head to cover erp requests as well
3047 cqr
->callback_data
= req
;
3048 cqr
->status
= DASD_CQR_FILLED
;
3050 req
->completion_data
= cqr
;
3051 blk_mq_start_request(req
);
3052 spin_lock(&block
->queue_lock
);
3053 list_add_tail(&cqr
->blocklist
, &block
->ccw_queue
);
3054 INIT_LIST_HEAD(&cqr
->devlist
);
3055 dasd_profile_start(block
, cqr
, req
);
3056 dasd_schedule_block_bh(block
);
3057 spin_unlock(&block
->queue_lock
);
3060 spin_unlock_irq(&dq
->lock
);
3065 * Block timeout callback, called from the block layer
3068 * BLK_EH_RESET_TIMER if the request should be left running
3069 * BLK_EH_NOT_HANDLED if the request is handled or terminated
3072 enum blk_eh_timer_return
dasd_times_out(struct request
*req
, bool reserved
)
3074 struct dasd_ccw_req
*cqr
= req
->completion_data
;
3075 struct dasd_block
*block
= req
->q
->queuedata
;
3076 struct dasd_device
*device
;
3077 unsigned long flags
;
3081 return BLK_EH_NOT_HANDLED
;
3083 spin_lock_irqsave(&cqr
->dq
->lock
, flags
);
3084 device
= cqr
->startdev
? cqr
->startdev
: block
->base
;
3085 if (!device
->blk_timeout
) {
3086 spin_unlock_irqrestore(&cqr
->dq
->lock
, flags
);
3087 return BLK_EH_RESET_TIMER
;
3089 DBF_DEV_EVENT(DBF_WARNING
, device
,
3090 " dasd_times_out cqr %p status %x",
3093 spin_lock(&block
->queue_lock
);
3094 spin_lock(get_ccwdev_lock(device
->cdev
));
3096 cqr
->intrc
= -ETIMEDOUT
;
3097 if (cqr
->status
>= DASD_CQR_QUEUED
) {
3098 spin_unlock(get_ccwdev_lock(device
->cdev
));
3099 rc
= dasd_cancel_req(cqr
);
3100 } else if (cqr
->status
== DASD_CQR_FILLED
||
3101 cqr
->status
== DASD_CQR_NEED_ERP
) {
3102 cqr
->status
= DASD_CQR_TERMINATED
;
3103 spin_unlock(get_ccwdev_lock(device
->cdev
));
3104 } else if (cqr
->status
== DASD_CQR_IN_ERP
) {
3105 struct dasd_ccw_req
*searchcqr
, *nextcqr
, *tmpcqr
;
3107 list_for_each_entry_safe(searchcqr
, nextcqr
,
3108 &block
->ccw_queue
, blocklist
) {
3110 while (tmpcqr
->refers
)
3111 tmpcqr
= tmpcqr
->refers
;
3114 /* searchcqr is an ERP request for cqr */
3115 searchcqr
->retries
= -1;
3116 searchcqr
->intrc
= -ETIMEDOUT
;
3117 if (searchcqr
->status
>= DASD_CQR_QUEUED
) {
3118 spin_unlock(get_ccwdev_lock(device
->cdev
));
3119 rc
= dasd_cancel_req(searchcqr
);
3120 spin_lock(get_ccwdev_lock(device
->cdev
));
3121 } else if ((searchcqr
->status
== DASD_CQR_FILLED
) ||
3122 (searchcqr
->status
== DASD_CQR_NEED_ERP
)) {
3123 searchcqr
->status
= DASD_CQR_TERMINATED
;
3125 } else if (searchcqr
->status
== DASD_CQR_IN_ERP
) {
3127 * Shouldn't happen; most recent ERP
3128 * request is at the front of queue
3134 spin_unlock(get_ccwdev_lock(device
->cdev
));
3136 dasd_schedule_block_bh(block
);
3137 spin_unlock(&block
->queue_lock
);
3138 spin_unlock_irqrestore(&cqr
->dq
->lock
, flags
);
3140 return rc
? BLK_EH_RESET_TIMER
: BLK_EH_NOT_HANDLED
;
3143 static int dasd_init_hctx(struct blk_mq_hw_ctx
*hctx
, void *data
,
3146 struct dasd_queue
*dq
= kzalloc(sizeof(*dq
), GFP_KERNEL
);
3151 spin_lock_init(&dq
->lock
);
3152 hctx
->driver_data
= dq
;
3157 static void dasd_exit_hctx(struct blk_mq_hw_ctx
*hctx
, unsigned int idx
)
3159 kfree(hctx
->driver_data
);
3160 hctx
->driver_data
= NULL
;
3163 static void dasd_request_done(struct request
*req
)
3165 blk_mq_end_request(req
, 0);
3166 blk_mq_run_hw_queues(req
->q
, true);
3169 static struct blk_mq_ops dasd_mq_ops
= {
3170 .queue_rq
= do_dasd_request
,
3171 .complete
= dasd_request_done
,
3172 .timeout
= dasd_times_out
,
3173 .init_hctx
= dasd_init_hctx
,
3174 .exit_hctx
= dasd_exit_hctx
,
3178 * Allocate and initialize request queue and default I/O scheduler.
3180 static int dasd_alloc_queue(struct dasd_block
*block
)
3184 block
->tag_set
.ops
= &dasd_mq_ops
;
3185 block
->tag_set
.nr_hw_queues
= DASD_NR_HW_QUEUES
;
3186 block
->tag_set
.queue_depth
= DASD_MAX_LCU_DEV
* DASD_REQ_PER_DEV
;
3187 block
->tag_set
.flags
= BLK_MQ_F_SHOULD_MERGE
;
3189 rc
= blk_mq_alloc_tag_set(&block
->tag_set
);
3193 block
->request_queue
= blk_mq_init_queue(&block
->tag_set
);
3194 if (IS_ERR(block
->request_queue
))
3195 return PTR_ERR(block
->request_queue
);
3197 block
->request_queue
->queuedata
= block
;
3203 * Allocate and initialize request queue.
3205 static void dasd_setup_queue(struct dasd_block
*block
)
3207 unsigned int logical_block_size
= block
->bp_block
;
3208 struct request_queue
*q
= block
->request_queue
;
3209 unsigned int max_bytes
, max_discard_sectors
;
3212 if (block
->base
->features
& DASD_FEATURE_USERAW
) {
3214 * the max_blocks value for raw_track access is 256
3215 * it is higher than the native ECKD value because we
3216 * only need one ccw per track
3217 * so the max_hw_sectors are
3218 * 2048 x 512B = 1024kB = 16 tracks
3222 max
= block
->base
->discipline
->max_blocks
<< block
->s2b_shift
;
3224 queue_flag_set_unlocked(QUEUE_FLAG_NONROT
, q
);
3225 q
->limits
.max_dev_sectors
= max
;
3226 blk_queue_logical_block_size(q
, logical_block_size
);
3227 blk_queue_max_hw_sectors(q
, max
);
3228 blk_queue_max_segments(q
, USHRT_MAX
);
3229 /* with page sized segments we can translate each segement into
3232 blk_queue_max_segment_size(q
, PAGE_SIZE
);
3233 blk_queue_segment_boundary(q
, PAGE_SIZE
- 1);
3235 /* Only activate blocklayer discard support for devices that support it */
3236 if (block
->base
->features
& DASD_FEATURE_DISCARD
) {
3237 q
->limits
.discard_granularity
= logical_block_size
;
3238 q
->limits
.discard_alignment
= PAGE_SIZE
;
3240 /* Calculate max_discard_sectors and make it PAGE aligned */
3241 max_bytes
= USHRT_MAX
* logical_block_size
;
3242 max_bytes
= ALIGN(max_bytes
, PAGE_SIZE
) - PAGE_SIZE
;
3243 max_discard_sectors
= max_bytes
/ logical_block_size
;
3245 blk_queue_max_discard_sectors(q
, max_discard_sectors
);
3246 blk_queue_max_write_zeroes_sectors(q
, max_discard_sectors
);
3247 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD
, q
);
3252 * Deactivate and free request queue.
3254 static void dasd_free_queue(struct dasd_block
*block
)
3256 if (block
->request_queue
) {
3257 blk_cleanup_queue(block
->request_queue
);
3258 blk_mq_free_tag_set(&block
->tag_set
);
3259 block
->request_queue
= NULL
;
3263 static int dasd_open(struct block_device
*bdev
, fmode_t mode
)
3265 struct dasd_device
*base
;
3268 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
3272 atomic_inc(&base
->block
->open_count
);
3273 if (test_bit(DASD_FLAG_OFFLINE
, &base
->flags
)) {
3278 if (!try_module_get(base
->discipline
->owner
)) {
3283 if (dasd_probeonly
) {
3284 dev_info(&base
->cdev
->dev
,
3285 "Accessing the DASD failed because it is in "
3286 "probeonly mode\n");
3291 if (base
->state
<= DASD_STATE_BASIC
) {
3292 DBF_DEV_EVENT(DBF_ERR
, base
, " %s",
3293 " Cannot open unrecognized device");
3298 if ((mode
& FMODE_WRITE
) &&
3299 (test_bit(DASD_FLAG_DEVICE_RO
, &base
->flags
) ||
3300 (base
->features
& DASD_FEATURE_READONLY
))) {
3305 dasd_put_device(base
);
3309 module_put(base
->discipline
->owner
);
3311 atomic_dec(&base
->block
->open_count
);
3312 dasd_put_device(base
);
3316 static void dasd_release(struct gendisk
*disk
, fmode_t mode
)
3318 struct dasd_device
*base
= dasd_device_from_gendisk(disk
);
3320 atomic_dec(&base
->block
->open_count
);
3321 module_put(base
->discipline
->owner
);
3322 dasd_put_device(base
);
3327 * Return disk geometry.
3329 static int dasd_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
3331 struct dasd_device
*base
;
3333 base
= dasd_device_from_gendisk(bdev
->bd_disk
);
3337 if (!base
->discipline
||
3338 !base
->discipline
->fill_geometry
) {
3339 dasd_put_device(base
);
3342 base
->discipline
->fill_geometry(base
->block
, geo
);
3343 geo
->start
= get_start_sect(bdev
) >> base
->block
->s2b_shift
;
3344 dasd_put_device(base
);
3348 const struct block_device_operations
3349 dasd_device_operations
= {
3350 .owner
= THIS_MODULE
,
3352 .release
= dasd_release
,
3353 .ioctl
= dasd_ioctl
,
3354 .compat_ioctl
= dasd_ioctl
,
3355 .getgeo
= dasd_getgeo
,
3358 /*******************************************************************************
3359 * end of block device operations
3365 #ifdef CONFIG_PROC_FS
3369 if (dasd_page_cache
!= NULL
) {
3370 kmem_cache_destroy(dasd_page_cache
);
3371 dasd_page_cache
= NULL
;
3373 dasd_gendisk_exit();
3375 if (dasd_debug_area
!= NULL
) {
3376 debug_unregister(dasd_debug_area
);
3377 dasd_debug_area
= NULL
;
3379 dasd_statistics_removeroot();
3383 * SECTION: common functions for ccw_driver use
3387 * Is the device read-only?
3388 * Note that this function does not report the setting of the
3389 * readonly device attribute, but how it is configured in z/VM.
3391 int dasd_device_is_ro(struct dasd_device
*device
)
3393 struct ccw_dev_id dev_id
;
3394 struct diag210 diag_data
;
3399 ccw_device_get_id(device
->cdev
, &dev_id
);
3400 memset(&diag_data
, 0, sizeof(diag_data
));
3401 diag_data
.vrdcdvno
= dev_id
.devno
;
3402 diag_data
.vrdclen
= sizeof(diag_data
);
3403 rc
= diag210(&diag_data
);
3404 if (rc
== 0 || rc
== 2) {
3405 return diag_data
.vrdcvfla
& 0x80;
3407 DBF_EVENT(DBF_WARNING
, "diag210 failed for dev=%04x with rc=%d",
3412 EXPORT_SYMBOL_GPL(dasd_device_is_ro
);
3414 static void dasd_generic_auto_online(void *data
, async_cookie_t cookie
)
3416 struct ccw_device
*cdev
= data
;
3419 ret
= ccw_device_set_online(cdev
);
3421 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3422 dev_name(&cdev
->dev
), ret
);
3426 * Initial attempt at a probe function. this can be simplified once
3427 * the other detection code is gone.
3429 int dasd_generic_probe(struct ccw_device
*cdev
,
3430 struct dasd_discipline
*discipline
)
3434 ret
= dasd_add_sysfs_files(cdev
);
3436 DBF_EVENT_DEVID(DBF_WARNING
, cdev
, "%s",
3437 "dasd_generic_probe: could not add "
3441 cdev
->handler
= &dasd_int_handler
;
3444 * Automatically online either all dasd devices (dasd_autodetect)
3445 * or all devices specified with dasd= parameters during
3448 if ((dasd_get_feature(cdev
, DASD_FEATURE_INITIAL_ONLINE
) > 0 ) ||
3449 (dasd_autodetect
&& dasd_busid_known(dev_name(&cdev
->dev
)) != 0))
3450 async_schedule(dasd_generic_auto_online
, cdev
);
3453 EXPORT_SYMBOL_GPL(dasd_generic_probe
);
3455 void dasd_generic_free_discipline(struct dasd_device
*device
)
3457 /* Forget the discipline information. */
3458 if (device
->discipline
) {
3459 if (device
->discipline
->uncheck_device
)
3460 device
->discipline
->uncheck_device(device
);
3461 module_put(device
->discipline
->owner
);
3462 device
->discipline
= NULL
;
3464 if (device
->base_discipline
) {
3465 module_put(device
->base_discipline
->owner
);
3466 device
->base_discipline
= NULL
;
3469 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline
);
3472 * This will one day be called from a global not_oper handler.
3473 * It is also used by driver_unregister during module unload.
3475 void dasd_generic_remove(struct ccw_device
*cdev
)
3477 struct dasd_device
*device
;
3478 struct dasd_block
*block
;
3480 cdev
->handler
= NULL
;
3482 device
= dasd_device_from_cdev(cdev
);
3483 if (IS_ERR(device
)) {
3484 dasd_remove_sysfs_files(cdev
);
3487 if (test_and_set_bit(DASD_FLAG_OFFLINE
, &device
->flags
) &&
3488 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3489 /* Already doing offline processing */
3490 dasd_put_device(device
);
3491 dasd_remove_sysfs_files(cdev
);
3495 * This device is removed unconditionally. Set offline
3496 * flag to prevent dasd_open from opening it while it is
3497 * no quite down yet.
3499 dasd_set_target_state(device
, DASD_STATE_NEW
);
3500 /* dasd_delete_device destroys the device reference. */
3501 block
= device
->block
;
3502 dasd_delete_device(device
);
3504 * life cycle of block is bound to device, so delete it after
3505 * device was safely removed
3508 dasd_free_block(block
);
3510 dasd_remove_sysfs_files(cdev
);
3512 EXPORT_SYMBOL_GPL(dasd_generic_remove
);
3515 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3516 * the device is detected for the first time and is supposed to be used
3517 * or the user has started activation through sysfs.
3519 int dasd_generic_set_online(struct ccw_device
*cdev
,
3520 struct dasd_discipline
*base_discipline
)
3522 struct dasd_discipline
*discipline
;
3523 struct dasd_device
*device
;
3526 /* first online clears initial online feature flag */
3527 dasd_set_feature(cdev
, DASD_FEATURE_INITIAL_ONLINE
, 0);
3528 device
= dasd_create_device(cdev
);
3530 return PTR_ERR(device
);
3532 discipline
= base_discipline
;
3533 if (device
->features
& DASD_FEATURE_USEDIAG
) {
3534 if (!dasd_diag_discipline_pointer
) {
3535 /* Try to load the required module. */
3536 rc
= request_module(DASD_DIAG_MOD
);
3538 pr_warn("%s Setting the DASD online failed "
3539 "because the required module %s "
3540 "could not be loaded (rc=%d)\n",
3541 dev_name(&cdev
->dev
), DASD_DIAG_MOD
,
3543 dasd_delete_device(device
);
3547 /* Module init could have failed, so check again here after
3548 * request_module(). */
3549 if (!dasd_diag_discipline_pointer
) {
3550 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3551 dev_name(&cdev
->dev
));
3552 dasd_delete_device(device
);
3555 discipline
= dasd_diag_discipline_pointer
;
3557 if (!try_module_get(base_discipline
->owner
)) {
3558 dasd_delete_device(device
);
3561 if (!try_module_get(discipline
->owner
)) {
3562 module_put(base_discipline
->owner
);
3563 dasd_delete_device(device
);
3566 device
->base_discipline
= base_discipline
;
3567 device
->discipline
= discipline
;
3569 /* check_device will allocate block device if necessary */
3570 rc
= discipline
->check_device(device
);
3572 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3573 dev_name(&cdev
->dev
), discipline
->name
, rc
);
3574 module_put(discipline
->owner
);
3575 module_put(base_discipline
->owner
);
3576 dasd_delete_device(device
);
3580 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
3581 if (device
->state
<= DASD_STATE_KNOWN
) {
3582 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3583 dev_name(&cdev
->dev
));
3585 dasd_set_target_state(device
, DASD_STATE_NEW
);
3587 dasd_free_block(device
->block
);
3588 dasd_delete_device(device
);
3590 pr_debug("dasd_generic device %s found\n",
3591 dev_name(&cdev
->dev
));
3593 wait_event(dasd_init_waitq
, _wait_for_device(device
));
3595 dasd_put_device(device
);
3598 EXPORT_SYMBOL_GPL(dasd_generic_set_online
);
3600 int dasd_generic_set_offline(struct ccw_device
*cdev
)
3602 struct dasd_device
*device
;
3603 struct dasd_block
*block
;
3604 int max_count
, open_count
, rc
;
3605 unsigned long flags
;
3608 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
3609 device
= dasd_device_from_cdev_locked(cdev
);
3610 if (IS_ERR(device
)) {
3611 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3612 return PTR_ERR(device
);
3616 * We must make sure that this device is currently not in use.
3617 * The open_count is increased for every opener, that includes
3618 * the blkdev_get in dasd_scan_partitions. We are only interested
3619 * in the other openers.
3621 if (device
->block
) {
3622 max_count
= device
->block
->bdev
? 0 : -1;
3623 open_count
= atomic_read(&device
->block
->open_count
);
3624 if (open_count
> max_count
) {
3626 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3627 dev_name(&cdev
->dev
), open_count
);
3629 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3630 dev_name(&cdev
->dev
));
3637 * Test if the offline processing is already running and exit if so.
3638 * If a safe offline is being processed this could only be a normal
3639 * offline that should be able to overtake the safe offline and
3640 * cancel any I/O we do not want to wait for any longer
3642 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
3643 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3644 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
,
3651 set_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
3654 * if safe_offline is called set safe_offline_running flag and
3655 * clear safe_offline so that a call to normal offline
3656 * can overrun safe_offline processing
3658 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE
, &device
->flags
) &&
3659 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3660 /* need to unlock here to wait for outstanding I/O */
3661 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3663 * If we want to set the device safe offline all IO operations
3664 * should be finished before continuing the offline process
3665 * so sync bdev first and then wait for our queues to become
3668 if (device
->block
) {
3669 rc
= fsync_bdev(device
->block
->bdev
);
3673 dasd_schedule_device_bh(device
);
3674 rc
= wait_event_interruptible(shutdown_waitq
,
3675 _wait_for_empty_queues(device
));
3680 * check if a normal offline process overtook the offline
3681 * processing in this case simply do nothing beside returning
3682 * that we got interrupted
3683 * otherwise mark safe offline as not running any longer and
3684 * continue with normal offline
3686 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
3687 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
)) {
3691 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
);
3693 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3695 dasd_set_target_state(device
, DASD_STATE_NEW
);
3696 /* dasd_delete_device destroys the device reference. */
3697 block
= device
->block
;
3698 dasd_delete_device(device
);
3700 * life cycle of block is bound to device, so delete it after
3701 * device was safely removed
3704 dasd_free_block(block
);
3709 /* interrupted by signal */
3710 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
3711 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING
, &device
->flags
);
3712 clear_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
3714 dasd_put_device(device
);
3715 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
3718 EXPORT_SYMBOL_GPL(dasd_generic_set_offline
);
3720 int dasd_generic_last_path_gone(struct dasd_device
*device
)
3722 struct dasd_ccw_req
*cqr
;
3724 dev_warn(&device
->cdev
->dev
, "No operational channel path is left "
3725 "for the device\n");
3726 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s", "last path gone");
3727 /* First of all call extended error reporting. */
3728 dasd_eer_write(device
, NULL
, DASD_EER_NOPATH
);
3730 if (device
->state
< DASD_STATE_BASIC
)
3732 /* Device is active. We want to keep it. */
3733 list_for_each_entry(cqr
, &device
->ccw_queue
, devlist
)
3734 if ((cqr
->status
== DASD_CQR_IN_IO
) ||
3735 (cqr
->status
== DASD_CQR_CLEAR_PENDING
)) {
3736 cqr
->status
= DASD_CQR_QUEUED
;
3739 dasd_device_set_stop_bits(device
, DASD_STOPPED_DC_WAIT
);
3740 dasd_device_clear_timer(device
);
3741 dasd_schedule_device_bh(device
);
3744 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone
);
3746 int dasd_generic_path_operational(struct dasd_device
*device
)
3748 dev_info(&device
->cdev
->dev
, "A channel path to the device has become "
3750 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s", "path operational");
3751 dasd_device_remove_stop_bits(device
, DASD_STOPPED_DC_WAIT
);
3752 if (device
->stopped
& DASD_UNRESUMED_PM
) {
3753 dasd_device_remove_stop_bits(device
, DASD_UNRESUMED_PM
);
3754 dasd_restore_device(device
);
3757 dasd_schedule_device_bh(device
);
3758 if (device
->block
) {
3759 dasd_schedule_block_bh(device
->block
);
3760 if (device
->block
->request_queue
)
3761 blk_mq_run_hw_queues(device
->block
->request_queue
,
3765 if (!device
->stopped
)
3766 wake_up(&generic_waitq
);
3770 EXPORT_SYMBOL_GPL(dasd_generic_path_operational
);
3772 int dasd_generic_notify(struct ccw_device
*cdev
, int event
)
3774 struct dasd_device
*device
;
3777 device
= dasd_device_from_cdev_locked(cdev
);
3785 dasd_path_no_path(device
);
3786 ret
= dasd_generic_last_path_gone(device
);
3790 if (dasd_path_get_opm(device
))
3791 ret
= dasd_generic_path_operational(device
);
3794 dasd_put_device(device
);
3797 EXPORT_SYMBOL_GPL(dasd_generic_notify
);
3799 void dasd_generic_path_event(struct ccw_device
*cdev
, int *path_event
)
3801 struct dasd_device
*device
;
3802 int chp
, oldopm
, hpfpm
, ifccpm
;
3804 device
= dasd_device_from_cdev_locked(cdev
);
3808 oldopm
= dasd_path_get_opm(device
);
3809 for (chp
= 0; chp
< 8; chp
++) {
3810 if (path_event
[chp
] & PE_PATH_GONE
) {
3811 dasd_path_notoper(device
, chp
);
3813 if (path_event
[chp
] & PE_PATH_AVAILABLE
) {
3814 dasd_path_available(device
, chp
);
3815 dasd_schedule_device_bh(device
);
3817 if (path_event
[chp
] & PE_PATHGROUP_ESTABLISHED
) {
3818 if (!dasd_path_is_operational(device
, chp
) &&
3819 !dasd_path_need_verify(device
, chp
)) {
3821 * we can not establish a pathgroup on an
3822 * unavailable path, so trigger a path
3823 * verification first
3825 dasd_path_available(device
, chp
);
3826 dasd_schedule_device_bh(device
);
3828 DBF_DEV_EVENT(DBF_WARNING
, device
, "%s",
3829 "Pathgroup re-established\n");
3830 if (device
->discipline
->kick_validate
)
3831 device
->discipline
->kick_validate(device
);
3834 hpfpm
= dasd_path_get_hpfpm(device
);
3835 ifccpm
= dasd_path_get_ifccpm(device
);
3836 if (!dasd_path_get_opm(device
) && hpfpm
) {
3838 * device has no operational paths but at least one path is
3839 * disabled due to HPF errors
3840 * disable HPF at all and use the path(s) again
3842 if (device
->discipline
->disable_hpf
)
3843 device
->discipline
->disable_hpf(device
);
3844 dasd_device_set_stop_bits(device
, DASD_STOPPED_NOT_ACC
);
3845 dasd_path_set_tbvpm(device
, hpfpm
);
3846 dasd_schedule_device_bh(device
);
3847 dasd_schedule_requeue(device
);
3848 } else if (!dasd_path_get_opm(device
) && ifccpm
) {
3850 * device has no operational paths but at least one path is
3851 * disabled due to IFCC errors
3852 * trigger path verification on paths with IFCC errors
3854 dasd_path_set_tbvpm(device
, ifccpm
);
3855 dasd_schedule_device_bh(device
);
3857 if (oldopm
&& !dasd_path_get_opm(device
) && !hpfpm
&& !ifccpm
) {
3858 dev_warn(&device
->cdev
->dev
,
3859 "No verified channel paths remain for the device\n");
3860 DBF_DEV_EVENT(DBF_WARNING
, device
,
3861 "%s", "last verified path gone");
3862 dasd_eer_write(device
, NULL
, DASD_EER_NOPATH
);
3863 dasd_device_set_stop_bits(device
,
3864 DASD_STOPPED_DC_WAIT
);
3866 dasd_put_device(device
);
3868 EXPORT_SYMBOL_GPL(dasd_generic_path_event
);
3870 int dasd_generic_verify_path(struct dasd_device
*device
, __u8 lpm
)
3872 if (!dasd_path_get_opm(device
) && lpm
) {
3873 dasd_path_set_opm(device
, lpm
);
3874 dasd_generic_path_operational(device
);
3876 dasd_path_add_opm(device
, lpm
);
3879 EXPORT_SYMBOL_GPL(dasd_generic_verify_path
);
3882 * clear active requests and requeue them to block layer if possible
3884 static int dasd_generic_requeue_all_requests(struct dasd_device
*device
)
3886 struct list_head requeue_queue
;
3887 struct dasd_ccw_req
*cqr
, *n
;
3888 struct dasd_ccw_req
*refers
;
3891 INIT_LIST_HEAD(&requeue_queue
);
3892 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
3894 list_for_each_entry_safe(cqr
, n
, &device
->ccw_queue
, devlist
) {
3895 /* Check status and move request to flush_queue */
3896 if (cqr
->status
== DASD_CQR_IN_IO
) {
3897 rc
= device
->discipline
->term_IO(cqr
);
3899 /* unable to terminate requeust */
3900 dev_err(&device
->cdev
->dev
,
3901 "Unable to terminate request %p "
3902 "on suspend\n", cqr
);
3903 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
3904 dasd_put_device(device
);
3908 list_move_tail(&cqr
->devlist
, &requeue_queue
);
3910 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
3912 list_for_each_entry_safe(cqr
, n
, &requeue_queue
, devlist
) {
3913 wait_event(dasd_flush_wq
,
3914 (cqr
->status
!= DASD_CQR_CLEAR_PENDING
));
3916 /* mark sleepon requests as ended */
3917 if (cqr
->callback_data
== DASD_SLEEPON_START_TAG
)
3918 cqr
->callback_data
= DASD_SLEEPON_END_TAG
;
3920 /* remove requests from device and block queue */
3921 list_del_init(&cqr
->devlist
);
3922 while (cqr
->refers
!= NULL
) {
3923 refers
= cqr
->refers
;
3924 /* remove the request from the block queue */
3925 list_del(&cqr
->blocklist
);
3926 /* free the finished erp request */
3927 dasd_free_erp_request(cqr
, cqr
->memdev
);
3932 * requeue requests to blocklayer will only work
3933 * for block device requests
3935 if (_dasd_requeue_request(cqr
))
3939 list_del_init(&cqr
->blocklist
);
3940 cqr
->block
->base
->discipline
->free_cp(
3941 cqr
, (struct request
*) cqr
->callback_data
);
3945 * if requests remain then they are internal request
3946 * and go back to the device queue
3948 if (!list_empty(&requeue_queue
)) {
3949 /* move freeze_queue to start of the ccw_queue */
3950 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
3951 list_splice_tail(&requeue_queue
, &device
->ccw_queue
);
3952 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
3954 /* wake up generic waitqueue for eventually ended sleepon requests */
3955 wake_up(&generic_waitq
);
3959 static void do_requeue_requests(struct work_struct
*work
)
3961 struct dasd_device
*device
= container_of(work
, struct dasd_device
,
3963 dasd_generic_requeue_all_requests(device
);
3964 dasd_device_remove_stop_bits(device
, DASD_STOPPED_NOT_ACC
);
3966 dasd_schedule_block_bh(device
->block
);
3967 dasd_put_device(device
);
3970 void dasd_schedule_requeue(struct dasd_device
*device
)
3972 dasd_get_device(device
);
3973 /* queue call to dasd_reload_device to the kernel event daemon. */
3974 if (!schedule_work(&device
->requeue_requests
))
3975 dasd_put_device(device
);
3977 EXPORT_SYMBOL(dasd_schedule_requeue
);
3979 int dasd_generic_pm_freeze(struct ccw_device
*cdev
)
3981 struct dasd_device
*device
= dasd_device_from_cdev(cdev
);
3984 return PTR_ERR(device
);
3986 /* mark device as suspended */
3987 set_bit(DASD_FLAG_SUSPENDED
, &device
->flags
);
3989 if (device
->discipline
->freeze
)
3990 device
->discipline
->freeze(device
);
3992 /* disallow new I/O */
3993 dasd_device_set_stop_bits(device
, DASD_STOPPED_PM
);
3995 return dasd_generic_requeue_all_requests(device
);
3997 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze
);
3999 int dasd_generic_restore_device(struct ccw_device
*cdev
)
4001 struct dasd_device
*device
= dasd_device_from_cdev(cdev
);
4005 return PTR_ERR(device
);
4007 /* allow new IO again */
4008 dasd_device_remove_stop_bits(device
,
4009 (DASD_STOPPED_PM
| DASD_UNRESUMED_PM
));
4011 dasd_schedule_device_bh(device
);
4014 * call discipline restore function
4015 * if device is stopped do nothing e.g. for disconnected devices
4017 if (device
->discipline
->restore
&& !(device
->stopped
))
4018 rc
= device
->discipline
->restore(device
);
4019 if (rc
|| device
->stopped
)
4021 * if the resume failed for the DASD we put it in
4022 * an UNRESUMED stop state
4024 device
->stopped
|= DASD_UNRESUMED_PM
;
4026 if (device
->block
) {
4027 dasd_schedule_block_bh(device
->block
);
4028 if (device
->block
->request_queue
)
4029 blk_mq_run_hw_queues(device
->block
->request_queue
,
4033 clear_bit(DASD_FLAG_SUSPENDED
, &device
->flags
);
4034 dasd_put_device(device
);
4037 EXPORT_SYMBOL_GPL(dasd_generic_restore_device
);
4039 static struct dasd_ccw_req
*dasd_generic_build_rdc(struct dasd_device
*device
,
4041 int rdc_buffer_size
,
4044 struct dasd_ccw_req
*cqr
;
4046 unsigned long *idaw
;
4048 cqr
= dasd_smalloc_request(magic
, 1 /* RDC */, rdc_buffer_size
, device
);
4051 /* internal error 13 - Allocating the RDC request failed*/
4052 dev_err(&device
->cdev
->dev
,
4053 "An error occurred in the DASD device driver, "
4054 "reason=%s\n", "13");
4059 ccw
->cmd_code
= CCW_CMD_RDC
;
4060 if (idal_is_needed(rdc_buffer
, rdc_buffer_size
)) {
4061 idaw
= (unsigned long *) (cqr
->data
);
4062 ccw
->cda
= (__u32
)(addr_t
) idaw
;
4063 ccw
->flags
= CCW_FLAG_IDA
;
4064 idaw
= idal_create_words(idaw
, rdc_buffer
, rdc_buffer_size
);
4066 ccw
->cda
= (__u32
)(addr_t
) rdc_buffer
;
4070 ccw
->count
= rdc_buffer_size
;
4071 cqr
->startdev
= device
;
4072 cqr
->memdev
= device
;
4073 cqr
->expires
= 10*HZ
;
4075 cqr
->buildclk
= get_tod_clock();
4076 cqr
->status
= DASD_CQR_FILLED
;
4081 int dasd_generic_read_dev_chars(struct dasd_device
*device
, int magic
,
4082 void *rdc_buffer
, int rdc_buffer_size
)
4085 struct dasd_ccw_req
*cqr
;
4087 cqr
= dasd_generic_build_rdc(device
, rdc_buffer
, rdc_buffer_size
,
4090 return PTR_ERR(cqr
);
4092 ret
= dasd_sleep_on(cqr
);
4093 dasd_sfree_request(cqr
, cqr
->memdev
);
4096 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars
);
4099 * In command mode and transport mode we need to look for sense
4100 * data in different places. The sense data itself is allways
4101 * an array of 32 bytes, so we can unify the sense data access
4104 char *dasd_get_sense(struct irb
*irb
)
4106 struct tsb
*tsb
= NULL
;
4109 if (scsw_is_tm(&irb
->scsw
) && (irb
->scsw
.tm
.fcxs
== 0x01)) {
4110 if (irb
->scsw
.tm
.tcw
)
4111 tsb
= tcw_get_tsb((struct tcw
*)(unsigned long)
4113 if (tsb
&& tsb
->length
== 64 && tsb
->flags
)
4114 switch (tsb
->flags
& 0x07) {
4115 case 1: /* tsa_iostat */
4116 sense
= tsb
->tsa
.iostat
.sense
;
4118 case 2: /* tsa_ddpc */
4119 sense
= tsb
->tsa
.ddpc
.sense
;
4122 /* currently we don't use interrogate data */
4125 } else if (irb
->esw
.esw0
.erw
.cons
) {
4130 EXPORT_SYMBOL_GPL(dasd_get_sense
);
4132 void dasd_generic_shutdown(struct ccw_device
*cdev
)
4134 struct dasd_device
*device
;
4136 device
= dasd_device_from_cdev(cdev
);
4141 dasd_schedule_block_bh(device
->block
);
4143 dasd_schedule_device_bh(device
);
4145 wait_event(shutdown_waitq
, _wait_for_empty_queues(device
));
4147 EXPORT_SYMBOL_GPL(dasd_generic_shutdown
);
4149 static int __init
dasd_init(void)
4153 init_waitqueue_head(&dasd_init_waitq
);
4154 init_waitqueue_head(&dasd_flush_wq
);
4155 init_waitqueue_head(&generic_waitq
);
4156 init_waitqueue_head(&shutdown_waitq
);
4158 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4159 dasd_debug_area
= debug_register("dasd", 1, 1, 8 * sizeof(long));
4160 if (dasd_debug_area
== NULL
) {
4164 debug_register_view(dasd_debug_area
, &debug_sprintf_view
);
4165 debug_set_level(dasd_debug_area
, DBF_WARNING
);
4167 DBF_EVENT(DBF_EMERG
, "%s", "debug area created");
4169 dasd_diag_discipline_pointer
= NULL
;
4171 dasd_statistics_createroot();
4173 rc
= dasd_devmap_init();
4176 rc
= dasd_gendisk_init();
4182 rc
= dasd_eer_init();
4185 #ifdef CONFIG_PROC_FS
4186 rc
= dasd_proc_init();
4193 pr_info("The DASD device driver could not be initialized\n");
4198 module_init(dasd_init
);
4199 module_exit(dasd_exit
);