1 // SPDX-License-Identifier: GPL-2.0
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * Copyright IBM Corp. 1999, 2009
11 #define KMSG_COMPONENT "dasd"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/kmod.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/ctype.h>
18 #include <linux/major.h>
19 #include <linux/slab.h>
20 #include <linux/hdreg.h>
21 #include <linux/async.h>
22 #include <linux/mutex.h>
23 #include <linux/debugfs.h>
24 #include <linux/seq_file.h>
25 #include <linux/vmalloc.h>
27 #include <asm/ccwdev.h>
28 #include <asm/ebcdic.h>
29 #include <asm/idals.h>
34 #define PRINTK_HEADER "dasd:"
38 * SECTION: Constant definitions to be used within this file
40 #define DASD_CHANQ_MAX_SIZE 4
42 #define DASD_DIAG_MOD "dasd_diag_mod"
44 static unsigned int queue_depth = 32;
45 static unsigned int nr_hw_queues = 4;
47 module_param(queue_depth, uint, 0444);
48 MODULE_PARM_DESC(queue_depth, "Default queue depth for new DASD devices");
50 module_param(nr_hw_queues, uint, 0444);
51 MODULE_PARM_DESC(nr_hw_queues, "Default number of hardware queues for new DASD devices");
54 * SECTION: exported variables of dasd.c
56 debug_info_t *dasd_debug_area;
57 EXPORT_SYMBOL(dasd_debug_area);
58 static struct dentry *dasd_debugfs_root_entry;
59 struct dasd_discipline *dasd_diag_discipline_pointer;
60 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
61 void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
63 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
64 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
65 " Copyright IBM Corp. 2000");
66 MODULE_LICENSE("GPL");
69 * SECTION: prototypes for static functions of dasd.c
71 static int dasd_alloc_queue(struct dasd_block *);
72 static void dasd_free_queue(struct dasd_block *);
73 static int dasd_flush_block_queue(struct dasd_block *);
74 static void dasd_device_tasklet(unsigned long);
75 static void dasd_block_tasklet(unsigned long);
76 static void do_kick_device(struct work_struct *);
77 static void do_reload_device(struct work_struct *);
78 static void do_requeue_requests(struct work_struct *);
79 static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
80 static void dasd_device_timeout(struct timer_list *);
81 static void dasd_block_timeout(struct timer_list *);
82 static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
83 static void dasd_profile_init(struct dasd_profile *, struct dentry *);
84 static void dasd_profile_exit(struct dasd_profile *);
85 static void dasd_hosts_init(struct dentry *, struct dasd_device *);
86 static void dasd_hosts_exit(struct dasd_device *);
89 * SECTION: Operations on the device structure.
91 static wait_queue_head_t dasd_init_waitq;
92 static wait_queue_head_t dasd_flush_wq;
93 static wait_queue_head_t generic_waitq;
94 static wait_queue_head_t shutdown_waitq;
97 * Allocate memory for a new device structure.
99 struct dasd_device *dasd_alloc_device(void)
101 struct dasd_device *device;
103 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
105 return ERR_PTR(-ENOMEM);
107 /* Get two pages for normal block device operations. */
108 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
109 if (!device->ccw_mem) {
111 return ERR_PTR(-ENOMEM);
113 /* Get one page for error recovery. */
114 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
115 if (!device->erp_mem) {
116 free_pages((unsigned long) device->ccw_mem, 1);
118 return ERR_PTR(-ENOMEM);
120 /* Get two pages for ese format. */
121 device->ese_mem = (void *)__get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
122 if (!device->ese_mem) {
123 free_page((unsigned long) device->erp_mem);
124 free_pages((unsigned long) device->ccw_mem, 1);
126 return ERR_PTR(-ENOMEM);
129 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
130 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
131 dasd_init_chunklist(&device->ese_chunks, device->ese_mem, PAGE_SIZE * 2);
132 spin_lock_init(&device->mem_lock);
133 atomic_set(&device->tasklet_scheduled, 0);
134 tasklet_init(&device->tasklet, dasd_device_tasklet,
135 (unsigned long) device);
136 INIT_LIST_HEAD(&device->ccw_queue);
137 timer_setup(&device->timer, dasd_device_timeout, 0);
138 INIT_WORK(&device->kick_work, do_kick_device);
139 INIT_WORK(&device->reload_device, do_reload_device);
140 INIT_WORK(&device->requeue_requests, do_requeue_requests);
141 device->state = DASD_STATE_NEW;
142 device->target = DASD_STATE_NEW;
143 mutex_init(&device->state_mutex);
144 spin_lock_init(&device->profile.lock);
149 * Free memory of a device structure.
151 void dasd_free_device(struct dasd_device *device)
153 kfree(device->private);
154 free_pages((unsigned long) device->ese_mem, 1);
155 free_page((unsigned long) device->erp_mem);
156 free_pages((unsigned long) device->ccw_mem, 1);
161 * Allocate memory for a new device structure.
163 struct dasd_block *dasd_alloc_block(void)
165 struct dasd_block *block;
167 block = kzalloc(sizeof(*block), GFP_ATOMIC);
169 return ERR_PTR(-ENOMEM);
170 /* open_count = 0 means device online but not in use */
171 atomic_set(&block->open_count, -1);
173 atomic_set(&block->tasklet_scheduled, 0);
174 tasklet_init(&block->tasklet, dasd_block_tasklet,
175 (unsigned long) block);
176 INIT_LIST_HEAD(&block->ccw_queue);
177 spin_lock_init(&block->queue_lock);
178 INIT_LIST_HEAD(&block->format_list);
179 spin_lock_init(&block->format_lock);
180 timer_setup(&block->timer, dasd_block_timeout, 0);
181 spin_lock_init(&block->profile.lock);
185 EXPORT_SYMBOL_GPL(dasd_alloc_block);
188 * Free memory of a device structure.
190 void dasd_free_block(struct dasd_block *block)
194 EXPORT_SYMBOL_GPL(dasd_free_block);
197 * Make a new device known to the system.
199 static int dasd_state_new_to_known(struct dasd_device *device)
204 * As long as the device is not in state DASD_STATE_NEW we want to
205 * keep the reference count > 0.
207 dasd_get_device(device);
210 rc = dasd_alloc_queue(device->block);
212 dasd_put_device(device);
216 device->state = DASD_STATE_KNOWN;
221 * Let the system forget about a device.
223 static int dasd_state_known_to_new(struct dasd_device *device)
225 /* Disable extended error reporting for this device. */
226 dasd_eer_disable(device);
227 device->state = DASD_STATE_NEW;
230 dasd_free_queue(device->block);
232 /* Give up reference we took in dasd_state_new_to_known. */
233 dasd_put_device(device);
237 static struct dentry *dasd_debugfs_setup(const char *name,
238 struct dentry *base_dentry)
244 pde = debugfs_create_dir(name, base_dentry);
245 if (!pde || IS_ERR(pde))
251 * Request the irq line for the device.
253 static int dasd_state_known_to_basic(struct dasd_device *device)
255 struct dasd_block *block = device->block;
258 /* Allocate and register gendisk structure. */
260 rc = dasd_gendisk_alloc(block);
263 block->debugfs_dentry =
264 dasd_debugfs_setup(block->gdp->disk_name,
265 dasd_debugfs_root_entry);
266 dasd_profile_init(&block->profile, block->debugfs_dentry);
267 if (dasd_global_profile_level == DASD_PROFILE_ON)
268 dasd_profile_on(&device->block->profile);
270 device->debugfs_dentry =
271 dasd_debugfs_setup(dev_name(&device->cdev->dev),
272 dasd_debugfs_root_entry);
273 dasd_profile_init(&device->profile, device->debugfs_dentry);
274 dasd_hosts_init(device->debugfs_dentry, device);
276 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
277 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
279 debug_register_view(device->debug_area, &debug_sprintf_view);
280 debug_set_level(device->debug_area, DBF_WARNING);
281 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
283 device->state = DASD_STATE_BASIC;
289 * Release the irq line for the device. Terminate any running i/o.
291 static int dasd_state_basic_to_known(struct dasd_device *device)
295 if (device->discipline->basic_to_known) {
296 rc = device->discipline->basic_to_known(device);
302 dasd_profile_exit(&device->block->profile);
303 debugfs_remove(device->block->debugfs_dentry);
304 dasd_gendisk_free(device->block);
305 dasd_block_clear_timer(device->block);
307 rc = dasd_flush_device_queue(device);
310 dasd_device_clear_timer(device);
311 dasd_profile_exit(&device->profile);
312 dasd_hosts_exit(device);
313 debugfs_remove(device->debugfs_dentry);
314 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
315 if (device->debug_area != NULL) {
316 debug_unregister(device->debug_area);
317 device->debug_area = NULL;
319 device->state = DASD_STATE_KNOWN;
324 * Do the initial analysis. The do_analysis function may return
325 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
326 * until the discipline decides to continue the startup sequence
327 * by calling the function dasd_change_state. The eckd disciplines
328 * uses this to start a ccw that detects the format. The completion
329 * interrupt for this detection ccw uses the kernel event daemon to
330 * trigger the call to dasd_change_state. All this is done in the
331 * discipline code, see dasd_eckd.c.
332 * After the analysis ccw is done (do_analysis returned 0) the block
334 * In case the analysis returns an error, the device setup is stopped
335 * (a fake disk was already added to allow formatting).
337 static int dasd_state_basic_to_ready(struct dasd_device *device)
340 struct dasd_block *block;
341 struct gendisk *disk;
344 block = device->block;
345 /* make disk known with correct capacity */
347 if (block->base->discipline->do_analysis != NULL)
348 rc = block->base->discipline->do_analysis(block);
351 device->state = DASD_STATE_UNFMT;
352 disk = device->block->gdp;
353 kobject_uevent(&disk_to_dev(disk)->kobj,
359 if (device->discipline->setup_blk_queue)
360 device->discipline->setup_blk_queue(block);
361 set_capacity(block->gdp,
362 block->blocks << block->s2b_shift);
363 device->state = DASD_STATE_READY;
364 rc = dasd_scan_partitions(block);
366 device->state = DASD_STATE_BASIC;
370 device->state = DASD_STATE_READY;
373 if (device->discipline->basic_to_ready)
374 rc = device->discipline->basic_to_ready(device);
379 int _wait_for_empty_queues(struct dasd_device *device)
382 return list_empty(&device->ccw_queue) &&
383 list_empty(&device->block->ccw_queue);
385 return list_empty(&device->ccw_queue);
389 * Remove device from block device layer. Destroy dirty buffers.
390 * Forget format information. Check if the target level is basic
391 * and if it is create fake disk for formatting.
393 static int dasd_state_ready_to_basic(struct dasd_device *device)
397 device->state = DASD_STATE_BASIC;
399 struct dasd_block *block = device->block;
400 rc = dasd_flush_block_queue(block);
402 device->state = DASD_STATE_READY;
405 dasd_destroy_partitions(block);
408 block->s2b_shift = 0;
416 static int dasd_state_unfmt_to_basic(struct dasd_device *device)
418 device->state = DASD_STATE_BASIC;
423 * Make the device online and schedule the bottom half to start
424 * the requeueing of requests from the linux request queue to the
428 dasd_state_ready_to_online(struct dasd_device * device)
430 device->state = DASD_STATE_ONLINE;
432 dasd_schedule_block_bh(device->block);
433 if ((device->features & DASD_FEATURE_USERAW)) {
434 kobject_uevent(&disk_to_dev(device->block->gdp)->kobj,
438 disk_uevent(device->block->bdev->bd_disk, KOBJ_CHANGE);
444 * Stop the requeueing of requests again.
446 static int dasd_state_online_to_ready(struct dasd_device *device)
450 if (device->discipline->online_to_ready) {
451 rc = device->discipline->online_to_ready(device);
456 device->state = DASD_STATE_READY;
457 if (device->block && !(device->features & DASD_FEATURE_USERAW))
458 disk_uevent(device->block->bdev->bd_disk, KOBJ_CHANGE);
463 * Device startup state changes.
465 static int dasd_increase_state(struct dasd_device *device)
470 if (device->state == DASD_STATE_NEW &&
471 device->target >= DASD_STATE_KNOWN)
472 rc = dasd_state_new_to_known(device);
475 device->state == DASD_STATE_KNOWN &&
476 device->target >= DASD_STATE_BASIC)
477 rc = dasd_state_known_to_basic(device);
480 device->state == DASD_STATE_BASIC &&
481 device->target >= DASD_STATE_READY)
482 rc = dasd_state_basic_to_ready(device);
485 device->state == DASD_STATE_UNFMT &&
486 device->target > DASD_STATE_UNFMT)
490 device->state == DASD_STATE_READY &&
491 device->target >= DASD_STATE_ONLINE)
492 rc = dasd_state_ready_to_online(device);
498 * Device shutdown state changes.
500 static int dasd_decrease_state(struct dasd_device *device)
505 if (device->state == DASD_STATE_ONLINE &&
506 device->target <= DASD_STATE_READY)
507 rc = dasd_state_online_to_ready(device);
510 device->state == DASD_STATE_READY &&
511 device->target <= DASD_STATE_BASIC)
512 rc = dasd_state_ready_to_basic(device);
515 device->state == DASD_STATE_UNFMT &&
516 device->target <= DASD_STATE_BASIC)
517 rc = dasd_state_unfmt_to_basic(device);
520 device->state == DASD_STATE_BASIC &&
521 device->target <= DASD_STATE_KNOWN)
522 rc = dasd_state_basic_to_known(device);
525 device->state == DASD_STATE_KNOWN &&
526 device->target <= DASD_STATE_NEW)
527 rc = dasd_state_known_to_new(device);
533 * This is the main startup/shutdown routine.
535 static void dasd_change_state(struct dasd_device *device)
539 if (device->state == device->target)
540 /* Already where we want to go today... */
542 if (device->state < device->target)
543 rc = dasd_increase_state(device);
545 rc = dasd_decrease_state(device);
549 device->target = device->state;
551 /* let user-space know that the device status changed */
552 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
554 if (device->state == device->target)
555 wake_up(&dasd_init_waitq);
559 * Kick starter for devices that did not complete the startup/shutdown
560 * procedure or were sleeping because of a pending state.
561 * dasd_kick_device will schedule a call do do_kick_device to the kernel
564 static void do_kick_device(struct work_struct *work)
566 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
567 mutex_lock(&device->state_mutex);
568 dasd_change_state(device);
569 mutex_unlock(&device->state_mutex);
570 dasd_schedule_device_bh(device);
571 dasd_put_device(device);
574 void dasd_kick_device(struct dasd_device *device)
576 dasd_get_device(device);
577 /* queue call to dasd_kick_device to the kernel event daemon. */
578 if (!schedule_work(&device->kick_work))
579 dasd_put_device(device);
581 EXPORT_SYMBOL(dasd_kick_device);
584 * dasd_reload_device will schedule a call do do_reload_device to the kernel
587 static void do_reload_device(struct work_struct *work)
589 struct dasd_device *device = container_of(work, struct dasd_device,
591 device->discipline->reload(device);
592 dasd_put_device(device);
595 void dasd_reload_device(struct dasd_device *device)
597 dasd_get_device(device);
598 /* queue call to dasd_reload_device to the kernel event daemon. */
599 if (!schedule_work(&device->reload_device))
600 dasd_put_device(device);
602 EXPORT_SYMBOL(dasd_reload_device);
605 * Set the target state for a device and starts the state change.
607 void dasd_set_target_state(struct dasd_device *device, int target)
609 dasd_get_device(device);
610 mutex_lock(&device->state_mutex);
611 /* If we are in probeonly mode stop at DASD_STATE_READY. */
612 if (dasd_probeonly && target > DASD_STATE_READY)
613 target = DASD_STATE_READY;
614 if (device->target != target) {
615 if (device->state == target)
616 wake_up(&dasd_init_waitq);
617 device->target = target;
619 if (device->state != device->target)
620 dasd_change_state(device);
621 mutex_unlock(&device->state_mutex);
622 dasd_put_device(device);
626 * Enable devices with device numbers in [from..to].
628 static inline int _wait_for_device(struct dasd_device *device)
630 return (device->state == device->target);
633 void dasd_enable_device(struct dasd_device *device)
635 dasd_set_target_state(device, DASD_STATE_ONLINE);
636 if (device->state <= DASD_STATE_KNOWN)
637 /* No discipline for device found. */
638 dasd_set_target_state(device, DASD_STATE_NEW);
639 /* Now wait for the devices to come up. */
640 wait_event(dasd_init_waitq, _wait_for_device(device));
642 dasd_reload_device(device);
643 if (device->discipline->kick_validate)
644 device->discipline->kick_validate(device);
646 EXPORT_SYMBOL(dasd_enable_device);
649 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
652 unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
654 #ifdef CONFIG_DASD_PROFILE
655 struct dasd_profile dasd_global_profile = {
656 .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
658 static struct dentry *dasd_debugfs_global_entry;
661 * Add profiling information for cqr before execution.
663 static void dasd_profile_start(struct dasd_block *block,
664 struct dasd_ccw_req *cqr,
668 unsigned int counter;
669 struct dasd_device *device;
671 /* count the length of the chanq for statistics */
673 if (dasd_global_profile_level || block->profile.data)
674 list_for_each(l, &block->ccw_queue)
678 spin_lock(&dasd_global_profile.lock);
679 if (dasd_global_profile.data) {
680 dasd_global_profile.data->dasd_io_nr_req[counter]++;
681 if (rq_data_dir(req) == READ)
682 dasd_global_profile.data->dasd_read_nr_req[counter]++;
684 spin_unlock(&dasd_global_profile.lock);
686 spin_lock(&block->profile.lock);
687 if (block->profile.data) {
688 block->profile.data->dasd_io_nr_req[counter]++;
689 if (rq_data_dir(req) == READ)
690 block->profile.data->dasd_read_nr_req[counter]++;
692 spin_unlock(&block->profile.lock);
695 * We count the request for the start device, even though it may run on
696 * some other device due to error recovery. This way we make sure that
697 * we count each request only once.
699 device = cqr->startdev;
700 if (device->profile.data) {
701 counter = 1; /* request is not yet queued on the start device */
702 list_for_each(l, &device->ccw_queue)
706 spin_lock(&device->profile.lock);
707 if (device->profile.data) {
708 device->profile.data->dasd_io_nr_req[counter]++;
709 if (rq_data_dir(req) == READ)
710 device->profile.data->dasd_read_nr_req[counter]++;
712 spin_unlock(&device->profile.lock);
716 * Add profiling information for cqr after execution.
719 #define dasd_profile_counter(value, index) \
721 for (index = 0; index < 31 && value >> (2+index); index++) \
725 static void dasd_profile_end_add_data(struct dasd_profile_info *data,
738 /* in case of an overflow, reset the whole profile */
739 if (data->dasd_io_reqs == UINT_MAX) {
740 memset(data, 0, sizeof(*data));
741 ktime_get_real_ts64(&data->starttod);
743 data->dasd_io_reqs++;
744 data->dasd_io_sects += sectors;
746 data->dasd_io_alias++;
750 data->dasd_io_secs[sectors_ind]++;
751 data->dasd_io_times[tottime_ind]++;
752 data->dasd_io_timps[tottimeps_ind]++;
753 data->dasd_io_time1[strtime_ind]++;
754 data->dasd_io_time2[irqtime_ind]++;
755 data->dasd_io_time2ps[irqtimeps_ind]++;
756 data->dasd_io_time3[endtime_ind]++;
759 data->dasd_read_reqs++;
760 data->dasd_read_sects += sectors;
762 data->dasd_read_alias++;
764 data->dasd_read_tpm++;
765 data->dasd_read_secs[sectors_ind]++;
766 data->dasd_read_times[tottime_ind]++;
767 data->dasd_read_time1[strtime_ind]++;
768 data->dasd_read_time2[irqtime_ind]++;
769 data->dasd_read_time3[endtime_ind]++;
773 static void dasd_profile_end(struct dasd_block *block,
774 struct dasd_ccw_req *cqr,
777 unsigned long strtime, irqtime, endtime, tottime;
778 unsigned long tottimeps, sectors;
779 struct dasd_device *device;
780 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
781 int irqtime_ind, irqtimeps_ind, endtime_ind;
782 struct dasd_profile_info *data;
784 device = cqr->startdev;
785 if (!(dasd_global_profile_level ||
786 block->profile.data ||
787 device->profile.data))
790 sectors = blk_rq_sectors(req);
791 if (!cqr->buildclk || !cqr->startclk ||
792 !cqr->stopclk || !cqr->endclk ||
796 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
797 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
798 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
799 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
800 tottimeps = tottime / sectors;
802 dasd_profile_counter(sectors, sectors_ind);
803 dasd_profile_counter(tottime, tottime_ind);
804 dasd_profile_counter(tottimeps, tottimeps_ind);
805 dasd_profile_counter(strtime, strtime_ind);
806 dasd_profile_counter(irqtime, irqtime_ind);
807 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
808 dasd_profile_counter(endtime, endtime_ind);
810 spin_lock(&dasd_global_profile.lock);
811 if (dasd_global_profile.data) {
812 data = dasd_global_profile.data;
813 data->dasd_sum_times += tottime;
814 data->dasd_sum_time_str += strtime;
815 data->dasd_sum_time_irq += irqtime;
816 data->dasd_sum_time_end += endtime;
817 dasd_profile_end_add_data(dasd_global_profile.data,
818 cqr->startdev != block->base,
820 rq_data_dir(req) == READ,
821 sectors, sectors_ind, tottime_ind,
822 tottimeps_ind, strtime_ind,
823 irqtime_ind, irqtimeps_ind,
826 spin_unlock(&dasd_global_profile.lock);
828 spin_lock(&block->profile.lock);
829 if (block->profile.data) {
830 data = block->profile.data;
831 data->dasd_sum_times += tottime;
832 data->dasd_sum_time_str += strtime;
833 data->dasd_sum_time_irq += irqtime;
834 data->dasd_sum_time_end += endtime;
835 dasd_profile_end_add_data(block->profile.data,
836 cqr->startdev != block->base,
838 rq_data_dir(req) == READ,
839 sectors, sectors_ind, tottime_ind,
840 tottimeps_ind, strtime_ind,
841 irqtime_ind, irqtimeps_ind,
844 spin_unlock(&block->profile.lock);
846 spin_lock(&device->profile.lock);
847 if (device->profile.data) {
848 data = device->profile.data;
849 data->dasd_sum_times += tottime;
850 data->dasd_sum_time_str += strtime;
851 data->dasd_sum_time_irq += irqtime;
852 data->dasd_sum_time_end += endtime;
853 dasd_profile_end_add_data(device->profile.data,
854 cqr->startdev != block->base,
856 rq_data_dir(req) == READ,
857 sectors, sectors_ind, tottime_ind,
858 tottimeps_ind, strtime_ind,
859 irqtime_ind, irqtimeps_ind,
862 spin_unlock(&device->profile.lock);
865 void dasd_profile_reset(struct dasd_profile *profile)
867 struct dasd_profile_info *data;
869 spin_lock_bh(&profile->lock);
870 data = profile->data;
872 spin_unlock_bh(&profile->lock);
875 memset(data, 0, sizeof(*data));
876 ktime_get_real_ts64(&data->starttod);
877 spin_unlock_bh(&profile->lock);
880 int dasd_profile_on(struct dasd_profile *profile)
882 struct dasd_profile_info *data;
884 data = kzalloc(sizeof(*data), GFP_KERNEL);
887 spin_lock_bh(&profile->lock);
889 spin_unlock_bh(&profile->lock);
893 ktime_get_real_ts64(&data->starttod);
894 profile->data = data;
895 spin_unlock_bh(&profile->lock);
899 void dasd_profile_off(struct dasd_profile *profile)
901 spin_lock_bh(&profile->lock);
902 kfree(profile->data);
903 profile->data = NULL;
904 spin_unlock_bh(&profile->lock);
907 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
911 buffer = vmalloc(user_len + 1);
913 return ERR_PTR(-ENOMEM);
914 if (copy_from_user(buffer, user_buf, user_len) != 0) {
916 return ERR_PTR(-EFAULT);
918 /* got the string, now strip linefeed. */
919 if (buffer[user_len - 1] == '\n')
920 buffer[user_len - 1] = 0;
922 buffer[user_len] = 0;
926 static ssize_t dasd_stats_write(struct file *file,
927 const char __user *user_buf,
928 size_t user_len, loff_t *pos)
932 struct seq_file *m = (struct seq_file *)file->private_data;
933 struct dasd_profile *prof = m->private;
935 if (user_len > 65536)
937 buffer = dasd_get_user_string(user_buf, user_len);
939 return PTR_ERR(buffer);
941 str = skip_spaces(buffer);
943 if (strncmp(str, "reset", 5) == 0) {
944 dasd_profile_reset(prof);
945 } else if (strncmp(str, "on", 2) == 0) {
946 rc = dasd_profile_on(prof);
950 if (prof == &dasd_global_profile) {
951 dasd_profile_reset(prof);
952 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
954 } else if (strncmp(str, "off", 3) == 0) {
955 if (prof == &dasd_global_profile)
956 dasd_global_profile_level = DASD_PROFILE_OFF;
957 dasd_profile_off(prof);
965 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
969 for (i = 0; i < 32; i++)
970 seq_printf(m, "%u ", array[i]);
974 static void dasd_stats_seq_print(struct seq_file *m,
975 struct dasd_profile_info *data)
977 seq_printf(m, "start_time %lld.%09ld\n",
978 (s64)data->starttod.tv_sec, data->starttod.tv_nsec);
979 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
980 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
981 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
982 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
983 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
984 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
985 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
986 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
987 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
988 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
989 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
990 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
991 seq_puts(m, "histogram_sectors ");
992 dasd_stats_array(m, data->dasd_io_secs);
993 seq_puts(m, "histogram_io_times ");
994 dasd_stats_array(m, data->dasd_io_times);
995 seq_puts(m, "histogram_io_times_weighted ");
996 dasd_stats_array(m, data->dasd_io_timps);
997 seq_puts(m, "histogram_time_build_to_ssch ");
998 dasd_stats_array(m, data->dasd_io_time1);
999 seq_puts(m, "histogram_time_ssch_to_irq ");
1000 dasd_stats_array(m, data->dasd_io_time2);
1001 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
1002 dasd_stats_array(m, data->dasd_io_time2ps);
1003 seq_puts(m, "histogram_time_irq_to_end ");
1004 dasd_stats_array(m, data->dasd_io_time3);
1005 seq_puts(m, "histogram_ccw_queue_length ");
1006 dasd_stats_array(m, data->dasd_io_nr_req);
1007 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
1008 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
1009 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
1010 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
1011 seq_puts(m, "histogram_read_sectors ");
1012 dasd_stats_array(m, data->dasd_read_secs);
1013 seq_puts(m, "histogram_read_times ");
1014 dasd_stats_array(m, data->dasd_read_times);
1015 seq_puts(m, "histogram_read_time_build_to_ssch ");
1016 dasd_stats_array(m, data->dasd_read_time1);
1017 seq_puts(m, "histogram_read_time_ssch_to_irq ");
1018 dasd_stats_array(m, data->dasd_read_time2);
1019 seq_puts(m, "histogram_read_time_irq_to_end ");
1020 dasd_stats_array(m, data->dasd_read_time3);
1021 seq_puts(m, "histogram_read_ccw_queue_length ");
1022 dasd_stats_array(m, data->dasd_read_nr_req);
1025 static int dasd_stats_show(struct seq_file *m, void *v)
1027 struct dasd_profile *profile;
1028 struct dasd_profile_info *data;
1030 profile = m->private;
1031 spin_lock_bh(&profile->lock);
1032 data = profile->data;
1034 spin_unlock_bh(&profile->lock);
1035 seq_puts(m, "disabled\n");
1038 dasd_stats_seq_print(m, data);
1039 spin_unlock_bh(&profile->lock);
1043 static int dasd_stats_open(struct inode *inode, struct file *file)
1045 struct dasd_profile *profile = inode->i_private;
1046 return single_open(file, dasd_stats_show, profile);
1049 static const struct file_operations dasd_stats_raw_fops = {
1050 .owner = THIS_MODULE,
1051 .open = dasd_stats_open,
1053 .llseek = seq_lseek,
1054 .release = single_release,
1055 .write = dasd_stats_write,
1058 static void dasd_profile_init(struct dasd_profile *profile,
1059 struct dentry *base_dentry)
1066 profile->dentry = NULL;
1067 profile->data = NULL;
1068 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1069 pde = debugfs_create_file("statistics", mode, base_dentry,
1070 profile, &dasd_stats_raw_fops);
1071 if (pde && !IS_ERR(pde))
1072 profile->dentry = pde;
1076 static void dasd_profile_exit(struct dasd_profile *profile)
1078 dasd_profile_off(profile);
1079 debugfs_remove(profile->dentry);
1080 profile->dentry = NULL;
1083 static void dasd_statistics_removeroot(void)
1085 dasd_global_profile_level = DASD_PROFILE_OFF;
1086 dasd_profile_exit(&dasd_global_profile);
1087 debugfs_remove(dasd_debugfs_global_entry);
1088 debugfs_remove(dasd_debugfs_root_entry);
1091 static void dasd_statistics_createroot(void)
1095 dasd_debugfs_root_entry = NULL;
1096 pde = debugfs_create_dir("dasd", NULL);
1097 if (!pde || IS_ERR(pde))
1099 dasd_debugfs_root_entry = pde;
1100 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1101 if (!pde || IS_ERR(pde))
1103 dasd_debugfs_global_entry = pde;
1104 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
1108 DBF_EVENT(DBF_ERR, "%s",
1109 "Creation of the dasd debugfs interface failed");
1110 dasd_statistics_removeroot();
1115 #define dasd_profile_start(block, cqr, req) do {} while (0)
1116 #define dasd_profile_end(block, cqr, req) do {} while (0)
1118 static void dasd_statistics_createroot(void)
1123 static void dasd_statistics_removeroot(void)
1128 int dasd_stats_generic_show(struct seq_file *m, void *v)
1130 seq_puts(m, "Statistics are not activated in this kernel\n");
1134 static void dasd_profile_init(struct dasd_profile *profile,
1135 struct dentry *base_dentry)
1140 static void dasd_profile_exit(struct dasd_profile *profile)
1145 int dasd_profile_on(struct dasd_profile *profile)
1150 #endif /* CONFIG_DASD_PROFILE */
1152 static int dasd_hosts_show(struct seq_file *m, void *v)
1154 struct dasd_device *device;
1155 int rc = -EOPNOTSUPP;
1157 device = m->private;
1158 dasd_get_device(device);
1160 if (device->discipline->hosts_print)
1161 rc = device->discipline->hosts_print(device, m);
1163 dasd_put_device(device);
1167 DEFINE_SHOW_ATTRIBUTE(dasd_hosts);
1169 static void dasd_hosts_exit(struct dasd_device *device)
1171 debugfs_remove(device->hosts_dentry);
1172 device->hosts_dentry = NULL;
1175 static void dasd_hosts_init(struct dentry *base_dentry,
1176 struct dasd_device *device)
1184 mode = S_IRUSR | S_IFREG;
1185 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1186 device, &dasd_hosts_fops);
1187 if (pde && !IS_ERR(pde))
1188 device->hosts_dentry = pde;
1191 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, int datasize,
1192 struct dasd_device *device,
1193 struct dasd_ccw_req *cqr)
1195 unsigned long flags;
1200 size += cplength * sizeof(struct ccw1);
1204 size += (sizeof(*cqr) + 7L) & -8L;
1206 spin_lock_irqsave(&device->mem_lock, flags);
1207 data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size);
1208 spin_unlock_irqrestore(&device->mem_lock, flags);
1210 return ERR_PTR(-ENOMEM);
1212 cqr = (void *) data;
1213 data += (sizeof(*cqr) + 7L) & -8L;
1215 memset(cqr, 0, sizeof(*cqr));
1216 cqr->mem_chunk = chunk;
1219 data += cplength * sizeof(struct ccw1);
1220 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1224 memset(cqr->data, 0, datasize);
1227 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1228 dasd_get_device(device);
1231 EXPORT_SYMBOL(dasd_smalloc_request);
1233 struct dasd_ccw_req *dasd_fmalloc_request(int magic, int cplength,
1235 struct dasd_device *device)
1237 struct dasd_ccw_req *cqr;
1238 unsigned long flags;
1242 cqr_size = (sizeof(*cqr) + 7L) & -8L;
1245 size += cplength * sizeof(struct ccw1);
1249 spin_lock_irqsave(&device->mem_lock, flags);
1250 cqr = dasd_alloc_chunk(&device->ese_chunks, size);
1251 spin_unlock_irqrestore(&device->mem_lock, flags);
1253 return ERR_PTR(-ENOMEM);
1254 memset(cqr, 0, sizeof(*cqr));
1255 data = (char *)cqr + cqr_size;
1259 data += cplength * sizeof(struct ccw1);
1260 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1265 memset(cqr->data, 0, datasize);
1269 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1270 dasd_get_device(device);
1274 EXPORT_SYMBOL(dasd_fmalloc_request);
1276 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1278 unsigned long flags;
1280 spin_lock_irqsave(&device->mem_lock, flags);
1281 dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk);
1282 spin_unlock_irqrestore(&device->mem_lock, flags);
1283 dasd_put_device(device);
1285 EXPORT_SYMBOL(dasd_sfree_request);
1287 void dasd_ffree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1289 unsigned long flags;
1291 spin_lock_irqsave(&device->mem_lock, flags);
1292 dasd_free_chunk(&device->ese_chunks, cqr);
1293 spin_unlock_irqrestore(&device->mem_lock, flags);
1294 dasd_put_device(device);
1296 EXPORT_SYMBOL(dasd_ffree_request);
1299 * Check discipline magic in cqr.
1301 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1303 struct dasd_device *device;
1307 device = cqr->startdev;
1308 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1309 DBF_DEV_EVENT(DBF_WARNING, device,
1310 " dasd_ccw_req 0x%08x magic doesn't match"
1311 " discipline 0x%08x",
1313 *(unsigned int *) device->discipline->name);
1320 * Terminate the current i/o and set the request to clear_pending.
1321 * Timer keeps device runnig.
1322 * ccw_device_clear can fail if the i/o subsystem
1325 int dasd_term_IO(struct dasd_ccw_req *cqr)
1327 struct dasd_device *device;
1329 char errorstring[ERRORLENGTH];
1332 rc = dasd_check_cqr(cqr);
1336 device = (struct dasd_device *) cqr->startdev;
1337 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1338 rc = ccw_device_clear(device->cdev, (long) cqr);
1340 case 0: /* termination successful */
1341 cqr->status = DASD_CQR_CLEAR_PENDING;
1342 cqr->stopclk = get_tod_clock();
1344 DBF_DEV_EVENT(DBF_DEBUG, device,
1345 "terminate cqr %p successful",
1349 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1350 "device gone, retry");
1354 * device not valid so no I/O could be running
1355 * handle CQR as termination successful
1357 cqr->status = DASD_CQR_CLEARED;
1358 cqr->stopclk = get_tod_clock();
1360 /* no retries for invalid devices */
1362 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1363 "EINVAL, handle as terminated");
1364 /* fake rc to success */
1368 /* internal error 10 - unknown rc*/
1369 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1370 dev_err(&device->cdev->dev, "An error occurred in the "
1371 "DASD device driver, reason=%s\n", errorstring);
1377 dasd_schedule_device_bh(device);
1380 EXPORT_SYMBOL(dasd_term_IO);
1383 * Start the i/o. This start_IO can fail if the channel is really busy.
1384 * In that case set up a timer to start the request later.
1386 int dasd_start_IO(struct dasd_ccw_req *cqr)
1388 struct dasd_device *device;
1390 char errorstring[ERRORLENGTH];
1393 rc = dasd_check_cqr(cqr);
1398 device = (struct dasd_device *) cqr->startdev;
1400 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1401 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1402 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1403 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1404 "because of stolen lock", cqr);
1405 cqr->status = DASD_CQR_ERROR;
1406 cqr->intrc = -EPERM;
1409 if (cqr->retries < 0) {
1410 /* internal error 14 - start_IO run out of retries */
1411 sprintf(errorstring, "14 %p", cqr);
1412 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1413 "device driver, reason=%s\n", errorstring);
1414 cqr->status = DASD_CQR_ERROR;
1417 cqr->startclk = get_tod_clock();
1418 cqr->starttime = jiffies;
1420 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1421 cqr->lpm &= dasd_path_get_opm(device);
1423 cqr->lpm = dasd_path_get_opm(device);
1425 if (cqr->cpmode == 1) {
1426 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1427 (long) cqr, cqr->lpm);
1429 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1430 (long) cqr, cqr->lpm, 0);
1434 cqr->status = DASD_CQR_IN_IO;
1437 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1438 "start_IO: device busy, retry later");
1441 /* -EACCES indicates that the request used only a subset of the
1442 * available paths and all these paths are gone. If the lpm of
1443 * this request was only a subset of the opm (e.g. the ppm) then
1444 * we just do a retry with all available paths.
1445 * If we already use the full opm, something is amiss, and we
1446 * need a full path verification.
1448 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1449 DBF_DEV_EVENT(DBF_WARNING, device,
1450 "start_IO: selected paths gone (%x)",
1452 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1453 cqr->lpm = dasd_path_get_opm(device);
1454 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1455 "start_IO: selected paths gone,"
1456 " retry on all paths");
1458 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1459 "start_IO: all paths in opm gone,"
1460 " do path verification");
1461 dasd_generic_last_path_gone(device);
1462 dasd_path_no_path(device);
1463 dasd_path_set_tbvpm(device,
1464 ccw_device_get_path_mask(
1469 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1470 "start_IO: -ENODEV device gone, retry");
1473 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1474 "start_IO: -EIO device gone, retry");
1477 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1478 "start_IO: -EINVAL device currently "
1482 /* internal error 11 - unknown rc */
1483 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1484 dev_err(&device->cdev->dev,
1485 "An error occurred in the DASD device driver, "
1486 "reason=%s\n", errorstring);
1493 EXPORT_SYMBOL(dasd_start_IO);
1496 * Timeout function for dasd devices. This is used for different purposes
1497 * 1) missing interrupt handler for normal operation
1498 * 2) delayed start of request where start_IO failed with -EBUSY
1499 * 3) timeout for missing state change interrupts
1500 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1501 * DASD_CQR_QUEUED for 2) and 3).
1503 static void dasd_device_timeout(struct timer_list *t)
1505 unsigned long flags;
1506 struct dasd_device *device;
1508 device = from_timer(device, t, timer);
1509 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1510 /* re-activate request queue */
1511 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1512 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1513 dasd_schedule_device_bh(device);
1517 * Setup timeout for a device in jiffies.
1519 void dasd_device_set_timer(struct dasd_device *device, int expires)
1522 del_timer(&device->timer);
1524 mod_timer(&device->timer, jiffies + expires);
1526 EXPORT_SYMBOL(dasd_device_set_timer);
1529 * Clear timeout for a device.
1531 void dasd_device_clear_timer(struct dasd_device *device)
1533 del_timer(&device->timer);
1535 EXPORT_SYMBOL(dasd_device_clear_timer);
1537 static void dasd_handle_killed_request(struct ccw_device *cdev,
1538 unsigned long intparm)
1540 struct dasd_ccw_req *cqr;
1541 struct dasd_device *device;
1545 cqr = (struct dasd_ccw_req *) intparm;
1546 if (cqr->status != DASD_CQR_IN_IO) {
1547 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1548 "invalid status in handle_killed_request: "
1549 "%02x", cqr->status);
1553 device = dasd_device_from_cdev_locked(cdev);
1554 if (IS_ERR(device)) {
1555 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1556 "unable to get device from cdev");
1560 if (!cqr->startdev ||
1561 device != cqr->startdev ||
1562 strncmp(cqr->startdev->discipline->ebcname,
1563 (char *) &cqr->magic, 4)) {
1564 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1565 "invalid device in request");
1566 dasd_put_device(device);
1570 /* Schedule request to be retried. */
1571 cqr->status = DASD_CQR_QUEUED;
1573 dasd_device_clear_timer(device);
1574 dasd_schedule_device_bh(device);
1575 dasd_put_device(device);
1578 void dasd_generic_handle_state_change(struct dasd_device *device)
1580 /* First of all start sense subsystem status request. */
1581 dasd_eer_snss(device);
1583 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1584 dasd_schedule_device_bh(device);
1585 if (device->block) {
1586 dasd_schedule_block_bh(device->block);
1587 if (device->block->request_queue)
1588 blk_mq_run_hw_queues(device->block->request_queue,
1592 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
1594 static int dasd_check_hpf_error(struct irb *irb)
1596 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1597 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1598 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1601 static int dasd_ese_needs_format(struct dasd_block *block, struct irb *irb)
1603 struct dasd_device *device = NULL;
1608 device = block->base;
1609 if (!device || !device->discipline->is_ese)
1611 if (!device->discipline->is_ese(device))
1614 sense = dasd_get_sense(irb);
1618 return !!(sense[1] & SNS1_NO_REC_FOUND) ||
1619 !!(sense[1] & SNS1_FILE_PROTECTED) ||
1620 scsw_cstat(&irb->scsw) == SCHN_STAT_INCORR_LEN;
1623 static int dasd_ese_oos_cond(u8 *sense)
1625 return sense[0] & SNS0_EQUIPMENT_CHECK &&
1626 sense[1] & SNS1_PERM_ERR &&
1627 sense[1] & SNS1_WRITE_INHIBITED &&
1632 * Interrupt handler for "normal" ssch-io based dasd devices.
1634 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1637 struct dasd_ccw_req *cqr, *next, *fcqr;
1638 struct dasd_device *device;
1640 int nrf_suppressed = 0;
1641 int fp_suppressed = 0;
1645 cqr = (struct dasd_ccw_req *) intparm;
1647 switch (PTR_ERR(irb)) {
1649 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1650 device = cqr->startdev;
1651 cqr->status = DASD_CQR_CLEARED;
1652 dasd_device_clear_timer(device);
1653 wake_up(&dasd_flush_wq);
1654 dasd_schedule_device_bh(device);
1659 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1660 "request timed out\n", __func__);
1663 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1664 "unknown error %ld\n", __func__,
1667 dasd_handle_killed_request(cdev, intparm);
1671 now = get_tod_clock();
1672 /* check for conditions that should be handled immediately */
1674 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1675 scsw_cstat(&irb->scsw) == 0)) {
1677 memcpy(&cqr->irb, irb, sizeof(*irb));
1678 device = dasd_device_from_cdev_locked(cdev);
1681 /* ignore unsolicited interrupts for DIAG discipline */
1682 if (device->discipline == dasd_diag_discipline_pointer) {
1683 dasd_put_device(device);
1688 * In some cases 'File Protected' or 'No Record Found' errors
1689 * might be expected and debug log messages for the
1690 * corresponding interrupts shouldn't be written then.
1691 * Check if either of the according suppress bits is set.
1693 sense = dasd_get_sense(irb);
1695 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1696 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1697 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1698 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1701 * Extent pool probably out-of-space.
1702 * Stop device and check exhaust level.
1704 if (dasd_ese_oos_cond(sense)) {
1705 dasd_generic_space_exhaust(device, cqr);
1706 device->discipline->ext_pool_exhaust(device, cqr);
1707 dasd_put_device(device);
1711 if (!(fp_suppressed || nrf_suppressed))
1712 device->discipline->dump_sense_dbf(device, irb, "int");
1714 if (device->features & DASD_FEATURE_ERPLOG)
1715 device->discipline->dump_sense(device, cqr, irb);
1716 device->discipline->check_for_device_change(device, cqr, irb);
1717 dasd_put_device(device);
1720 /* check for for attention message */
1721 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1722 device = dasd_device_from_cdev_locked(cdev);
1723 if (!IS_ERR(device)) {
1724 device->discipline->check_attention(device,
1725 irb->esw.esw1.lpum);
1726 dasd_put_device(device);
1733 device = (struct dasd_device *) cqr->startdev;
1735 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1736 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1737 "invalid device in request");
1741 if (dasd_ese_needs_format(cqr->block, irb)) {
1742 if (rq_data_dir((struct request *)cqr->callback_data) == READ) {
1743 device->discipline->ese_read(cqr, irb);
1744 cqr->status = DASD_CQR_SUCCESS;
1746 dasd_device_clear_timer(device);
1747 dasd_schedule_device_bh(device);
1750 fcqr = device->discipline->ese_format(device, cqr, irb);
1752 if (PTR_ERR(fcqr) == -EINVAL) {
1753 cqr->status = DASD_CQR_ERROR;
1757 * If we can't format now, let the request go
1758 * one extra round. Maybe we can format later.
1760 cqr->status = DASD_CQR_QUEUED;
1761 dasd_schedule_device_bh(device);
1764 fcqr->status = DASD_CQR_QUEUED;
1765 cqr->status = DASD_CQR_QUEUED;
1766 list_add(&fcqr->devlist, &device->ccw_queue);
1767 dasd_schedule_device_bh(device);
1772 /* Check for clear pending */
1773 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1774 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1775 cqr->status = DASD_CQR_CLEARED;
1776 dasd_device_clear_timer(device);
1777 wake_up(&dasd_flush_wq);
1778 dasd_schedule_device_bh(device);
1782 /* check status - the request might have been killed by dyn detach */
1783 if (cqr->status != DASD_CQR_IN_IO) {
1784 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1785 "status %02x", dev_name(&cdev->dev), cqr->status);
1791 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1792 scsw_cstat(&irb->scsw) == 0) {
1793 /* request was completed successfully */
1794 cqr->status = DASD_CQR_SUCCESS;
1796 /* Start first request on queue if possible -> fast_io. */
1797 if (cqr->devlist.next != &device->ccw_queue) {
1798 next = list_entry(cqr->devlist.next,
1799 struct dasd_ccw_req, devlist);
1801 } else { /* error */
1802 /* check for HPF error
1803 * call discipline function to requeue all requests
1804 * and disable HPF accordingly
1806 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1807 device->discipline->handle_hpf_error)
1808 device->discipline->handle_hpf_error(device, irb);
1810 * If we don't want complex ERP for this request, then just
1811 * reset this and retry it in the fastpath
1813 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1815 if (cqr->lpm == dasd_path_get_opm(device))
1816 DBF_DEV_EVENT(DBF_DEBUG, device,
1817 "default ERP in fastpath "
1818 "(%i retries left)",
1820 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1821 cqr->lpm = dasd_path_get_opm(device);
1822 cqr->status = DASD_CQR_QUEUED;
1825 cqr->status = DASD_CQR_ERROR;
1827 if (next && (next->status == DASD_CQR_QUEUED) &&
1828 (!device->stopped)) {
1829 if (device->discipline->start_IO(next) == 0)
1830 expires = next->expires;
1833 dasd_device_set_timer(device, expires);
1835 dasd_device_clear_timer(device);
1836 dasd_schedule_device_bh(device);
1838 EXPORT_SYMBOL(dasd_int_handler);
1840 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1842 struct dasd_device *device;
1844 device = dasd_device_from_cdev_locked(cdev);
1848 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1849 device->state != device->target ||
1850 !device->discipline->check_for_device_change){
1851 dasd_put_device(device);
1854 if (device->discipline->dump_sense_dbf)
1855 device->discipline->dump_sense_dbf(device, irb, "uc");
1856 device->discipline->check_for_device_change(device, NULL, irb);
1857 dasd_put_device(device);
1859 return UC_TODO_RETRY;
1861 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1864 * If we have an error on a dasd_block layer request then we cancel
1865 * and return all further requests from the same dasd_block as well.
1867 static void __dasd_device_recovery(struct dasd_device *device,
1868 struct dasd_ccw_req *ref_cqr)
1870 struct list_head *l, *n;
1871 struct dasd_ccw_req *cqr;
1874 * only requeue request that came from the dasd_block layer
1876 if (!ref_cqr->block)
1879 list_for_each_safe(l, n, &device->ccw_queue) {
1880 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1881 if (cqr->status == DASD_CQR_QUEUED &&
1882 ref_cqr->block == cqr->block) {
1883 cqr->status = DASD_CQR_CLEARED;
1889 * Remove those ccw requests from the queue that need to be returned
1890 * to the upper layer.
1892 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1893 struct list_head *final_queue)
1895 struct list_head *l, *n;
1896 struct dasd_ccw_req *cqr;
1898 /* Process request with final status. */
1899 list_for_each_safe(l, n, &device->ccw_queue) {
1900 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1902 /* Skip any non-final request. */
1903 if (cqr->status == DASD_CQR_QUEUED ||
1904 cqr->status == DASD_CQR_IN_IO ||
1905 cqr->status == DASD_CQR_CLEAR_PENDING)
1907 if (cqr->status == DASD_CQR_ERROR) {
1908 __dasd_device_recovery(device, cqr);
1910 /* Rechain finished requests to final queue */
1911 list_move_tail(&cqr->devlist, final_queue);
1915 static void __dasd_process_cqr(struct dasd_device *device,
1916 struct dasd_ccw_req *cqr)
1918 char errorstring[ERRORLENGTH];
1920 switch (cqr->status) {
1921 case DASD_CQR_SUCCESS:
1922 cqr->status = DASD_CQR_DONE;
1924 case DASD_CQR_ERROR:
1925 cqr->status = DASD_CQR_NEED_ERP;
1927 case DASD_CQR_CLEARED:
1928 cqr->status = DASD_CQR_TERMINATED;
1931 /* internal error 12 - wrong cqr status*/
1932 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1933 dev_err(&device->cdev->dev,
1934 "An error occurred in the DASD device driver, "
1935 "reason=%s\n", errorstring);
1939 cqr->callback(cqr, cqr->callback_data);
1943 * the cqrs from the final queue are returned to the upper layer
1944 * by setting a dasd_block state and calling the callback function
1946 static void __dasd_device_process_final_queue(struct dasd_device *device,
1947 struct list_head *final_queue)
1949 struct list_head *l, *n;
1950 struct dasd_ccw_req *cqr;
1951 struct dasd_block *block;
1953 list_for_each_safe(l, n, final_queue) {
1954 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1955 list_del_init(&cqr->devlist);
1958 __dasd_process_cqr(device, cqr);
1960 spin_lock_bh(&block->queue_lock);
1961 __dasd_process_cqr(device, cqr);
1962 spin_unlock_bh(&block->queue_lock);
1968 * Take a look at the first request on the ccw queue and check
1969 * if it reached its expire time. If so, terminate the IO.
1971 static void __dasd_device_check_expire(struct dasd_device *device)
1973 struct dasd_ccw_req *cqr;
1975 if (list_empty(&device->ccw_queue))
1977 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1978 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1979 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1980 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1982 * IO in safe offline processing should not
1983 * run out of retries
1987 if (device->discipline->term_IO(cqr) != 0) {
1988 /* Hmpf, try again in 5 sec */
1989 dev_err(&device->cdev->dev,
1990 "cqr %p timed out (%lus) but cannot be "
1991 "ended, retrying in 5 s\n",
1992 cqr, (cqr->expires/HZ));
1993 cqr->expires += 5*HZ;
1994 dasd_device_set_timer(device, 5*HZ);
1996 dev_err(&device->cdev->dev,
1997 "cqr %p timed out (%lus), %i retries "
1998 "remaining\n", cqr, (cqr->expires/HZ),
2005 * return 1 when device is not eligible for IO
2007 static int __dasd_device_is_unusable(struct dasd_device *device,
2008 struct dasd_ccw_req *cqr)
2010 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_STOPPED_NOSPC);
2012 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2013 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
2015 * dasd is being set offline
2016 * but it is no safe offline where we have to allow I/O
2020 if (device->stopped) {
2021 if (device->stopped & mask) {
2022 /* stopped and CQR will not change that. */
2025 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2026 /* CQR is not able to change device to
2030 /* CQR required to get device operational. */
2036 * Take a look at the first request on the ccw queue and check
2037 * if it needs to be started.
2039 static void __dasd_device_start_head(struct dasd_device *device)
2041 struct dasd_ccw_req *cqr;
2044 if (list_empty(&device->ccw_queue))
2046 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2047 if (cqr->status != DASD_CQR_QUEUED)
2049 /* if device is not usable return request to upper layer */
2050 if (__dasd_device_is_unusable(device, cqr)) {
2051 cqr->intrc = -EAGAIN;
2052 cqr->status = DASD_CQR_CLEARED;
2053 dasd_schedule_device_bh(device);
2057 rc = device->discipline->start_IO(cqr);
2059 dasd_device_set_timer(device, cqr->expires);
2060 else if (rc == -EACCES) {
2061 dasd_schedule_device_bh(device);
2063 /* Hmpf, try again in 1/2 sec */
2064 dasd_device_set_timer(device, 50);
2067 static void __dasd_device_check_path_events(struct dasd_device *device)
2069 __u8 tbvpm, fcsecpm;
2072 tbvpm = dasd_path_get_tbvpm(device);
2073 fcsecpm = dasd_path_get_fcsecpm(device);
2075 if (!tbvpm && !fcsecpm)
2078 if (device->stopped & ~(DASD_STOPPED_DC_WAIT))
2080 rc = device->discipline->pe_handler(device, tbvpm, fcsecpm);
2082 dasd_device_set_timer(device, 50);
2084 dasd_path_clear_all_verify(device);
2085 dasd_path_clear_all_fcsec(device);
2090 * Go through all request on the dasd_device request queue,
2091 * terminate them on the cdev if necessary, and return them to the
2092 * submitting layer via callback.
2094 * Make sure that all 'submitting layers' still exist when
2095 * this function is called!. In other words, when 'device' is a base
2096 * device then all block layer requests must have been removed before
2097 * via dasd_flush_block_queue.
2099 int dasd_flush_device_queue(struct dasd_device *device)
2101 struct dasd_ccw_req *cqr, *n;
2103 struct list_head flush_queue;
2105 INIT_LIST_HEAD(&flush_queue);
2106 spin_lock_irq(get_ccwdev_lock(device->cdev));
2108 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2109 /* Check status and move request to flush_queue */
2110 switch (cqr->status) {
2111 case DASD_CQR_IN_IO:
2112 rc = device->discipline->term_IO(cqr);
2114 /* unable to terminate requeust */
2115 dev_err(&device->cdev->dev,
2116 "Flushing the DASD request queue "
2117 "failed for request %p\n", cqr);
2118 /* stop flush processing */
2122 case DASD_CQR_QUEUED:
2123 cqr->stopclk = get_tod_clock();
2124 cqr->status = DASD_CQR_CLEARED;
2126 default: /* no need to modify the others */
2129 list_move_tail(&cqr->devlist, &flush_queue);
2132 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2134 * After this point all requests must be in state CLEAR_PENDING,
2135 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2136 * one of the others.
2138 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2139 wait_event(dasd_flush_wq,
2140 (cqr->status != DASD_CQR_CLEAR_PENDING));
2142 * Now set each request back to TERMINATED, DONE or NEED_ERP
2143 * and call the callback function of flushed requests
2145 __dasd_device_process_final_queue(device, &flush_queue);
2148 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2151 * Acquire the device lock and process queues for the device.
2153 static void dasd_device_tasklet(unsigned long data)
2155 struct dasd_device *device = (struct dasd_device *) data;
2156 struct list_head final_queue;
2158 atomic_set (&device->tasklet_scheduled, 0);
2159 INIT_LIST_HEAD(&final_queue);
2160 spin_lock_irq(get_ccwdev_lock(device->cdev));
2161 /* Check expire time of first request on the ccw queue. */
2162 __dasd_device_check_expire(device);
2163 /* find final requests on ccw queue */
2164 __dasd_device_process_ccw_queue(device, &final_queue);
2165 __dasd_device_check_path_events(device);
2166 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2167 /* Now call the callback function of requests with final status */
2168 __dasd_device_process_final_queue(device, &final_queue);
2169 spin_lock_irq(get_ccwdev_lock(device->cdev));
2170 /* Now check if the head of the ccw queue needs to be started. */
2171 __dasd_device_start_head(device);
2172 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2173 if (waitqueue_active(&shutdown_waitq))
2174 wake_up(&shutdown_waitq);
2175 dasd_put_device(device);
2179 * Schedules a call to dasd_tasklet over the device tasklet.
2181 void dasd_schedule_device_bh(struct dasd_device *device)
2183 /* Protect against rescheduling. */
2184 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2186 dasd_get_device(device);
2187 tasklet_hi_schedule(&device->tasklet);
2189 EXPORT_SYMBOL(dasd_schedule_device_bh);
2191 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2193 device->stopped |= bits;
2195 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2197 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2199 device->stopped &= ~bits;
2200 if (!device->stopped)
2201 wake_up(&generic_waitq);
2203 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2206 * Queue a request to the head of the device ccw_queue.
2207 * Start the I/O if possible.
2209 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2211 struct dasd_device *device;
2212 unsigned long flags;
2214 device = cqr->startdev;
2215 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2216 cqr->status = DASD_CQR_QUEUED;
2217 list_add(&cqr->devlist, &device->ccw_queue);
2218 /* let the bh start the request to keep them in order */
2219 dasd_schedule_device_bh(device);
2220 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2222 EXPORT_SYMBOL(dasd_add_request_head);
2225 * Queue a request to the tail of the device ccw_queue.
2226 * Start the I/O if possible.
2228 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2230 struct dasd_device *device;
2231 unsigned long flags;
2233 device = cqr->startdev;
2234 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2235 cqr->status = DASD_CQR_QUEUED;
2236 list_add_tail(&cqr->devlist, &device->ccw_queue);
2237 /* let the bh start the request to keep them in order */
2238 dasd_schedule_device_bh(device);
2239 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2241 EXPORT_SYMBOL(dasd_add_request_tail);
2244 * Wakeup helper for the 'sleep_on' functions.
2246 void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2248 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2249 cqr->callback_data = DASD_SLEEPON_END_TAG;
2250 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2251 wake_up(&generic_waitq);
2253 EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
2255 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2257 struct dasd_device *device;
2260 device = cqr->startdev;
2261 spin_lock_irq(get_ccwdev_lock(device->cdev));
2262 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2263 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2268 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2270 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2272 struct dasd_device *device;
2273 dasd_erp_fn_t erp_fn;
2275 if (cqr->status == DASD_CQR_FILLED)
2277 device = cqr->startdev;
2278 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2279 if (cqr->status == DASD_CQR_TERMINATED) {
2280 device->discipline->handle_terminated_request(cqr);
2283 if (cqr->status == DASD_CQR_NEED_ERP) {
2284 erp_fn = device->discipline->erp_action(cqr);
2288 if (cqr->status == DASD_CQR_FAILED)
2289 dasd_log_sense(cqr, &cqr->irb);
2291 __dasd_process_erp(device, cqr);
2298 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2300 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2301 if (cqr->refers) /* erp is not done yet */
2303 return ((cqr->status != DASD_CQR_DONE) &&
2304 (cqr->status != DASD_CQR_FAILED));
2306 return (cqr->status == DASD_CQR_FILLED);
2309 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2311 struct dasd_device *device;
2313 struct list_head ccw_queue;
2314 struct dasd_ccw_req *cqr;
2316 INIT_LIST_HEAD(&ccw_queue);
2317 maincqr->status = DASD_CQR_FILLED;
2318 device = maincqr->startdev;
2319 list_add(&maincqr->blocklist, &ccw_queue);
2320 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2321 cqr = list_first_entry(&ccw_queue,
2322 struct dasd_ccw_req, blocklist)) {
2324 if (__dasd_sleep_on_erp(cqr))
2326 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2328 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2329 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2330 cqr->status = DASD_CQR_FAILED;
2331 cqr->intrc = -EPERM;
2334 /* Non-temporary stop condition will trigger fail fast */
2335 if (device->stopped & ~DASD_STOPPED_PENDING &&
2336 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2337 (!dasd_eer_enabled(device))) {
2338 cqr->status = DASD_CQR_FAILED;
2339 cqr->intrc = -ENOLINK;
2343 * Don't try to start requests if device is in
2344 * offline processing, it might wait forever
2346 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2347 cqr->status = DASD_CQR_FAILED;
2348 cqr->intrc = -ENODEV;
2352 * Don't try to start requests if device is stopped
2353 * except path verification requests
2355 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2356 if (interruptible) {
2357 rc = wait_event_interruptible(
2358 generic_waitq, !(device->stopped));
2359 if (rc == -ERESTARTSYS) {
2360 cqr->status = DASD_CQR_FAILED;
2361 maincqr->intrc = rc;
2365 wait_event(generic_waitq, !(device->stopped));
2368 cqr->callback = dasd_wakeup_cb;
2370 cqr->callback_data = DASD_SLEEPON_START_TAG;
2371 dasd_add_request_tail(cqr);
2372 if (interruptible) {
2373 rc = wait_event_interruptible(
2374 generic_waitq, _wait_for_wakeup(cqr));
2375 if (rc == -ERESTARTSYS) {
2376 dasd_cancel_req(cqr);
2377 /* wait (non-interruptible) for final status */
2378 wait_event(generic_waitq,
2379 _wait_for_wakeup(cqr));
2380 cqr->status = DASD_CQR_FAILED;
2381 maincqr->intrc = rc;
2385 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2388 maincqr->endclk = get_tod_clock();
2389 if ((maincqr->status != DASD_CQR_DONE) &&
2390 (maincqr->intrc != -ERESTARTSYS))
2391 dasd_log_sense(maincqr, &maincqr->irb);
2392 if (maincqr->status == DASD_CQR_DONE)
2394 else if (maincqr->intrc)
2395 rc = maincqr->intrc;
2401 static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2403 struct dasd_ccw_req *cqr;
2405 list_for_each_entry(cqr, ccw_queue, blocklist) {
2406 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2413 static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2415 struct dasd_device *device;
2416 struct dasd_ccw_req *cqr, *n;
2421 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2422 device = cqr->startdev;
2423 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2426 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2427 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2428 cqr->status = DASD_CQR_FAILED;
2429 cqr->intrc = -EPERM;
2432 /*Non-temporary stop condition will trigger fail fast*/
2433 if (device->stopped & ~DASD_STOPPED_PENDING &&
2434 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2435 !dasd_eer_enabled(device)) {
2436 cqr->status = DASD_CQR_FAILED;
2437 cqr->intrc = -EAGAIN;
2441 /*Don't try to start requests if device is stopped*/
2442 if (interruptible) {
2443 rc = wait_event_interruptible(
2444 generic_waitq, !device->stopped);
2445 if (rc == -ERESTARTSYS) {
2446 cqr->status = DASD_CQR_FAILED;
2451 wait_event(generic_waitq, !(device->stopped));
2454 cqr->callback = dasd_wakeup_cb;
2455 cqr->callback_data = DASD_SLEEPON_START_TAG;
2456 dasd_add_request_tail(cqr);
2459 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2462 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2464 * In some cases the 'File Protected' or 'Incorrect Length'
2465 * error might be expected and error recovery would be
2466 * unnecessary in these cases. Check if the according suppress
2469 sense = dasd_get_sense(&cqr->irb);
2470 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2471 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2473 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2474 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2478 * for alias devices simplify error recovery and
2479 * return to upper layer
2480 * do not skip ERP requests
2482 if (cqr->startdev != cqr->basedev && !cqr->refers &&
2483 (cqr->status == DASD_CQR_TERMINATED ||
2484 cqr->status == DASD_CQR_NEED_ERP))
2487 /* normal recovery for basedev IO */
2488 if (__dasd_sleep_on_erp(cqr))
2489 /* handle erp first */
2497 * Queue a request to the tail of the device ccw_queue and wait for
2500 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2502 return _dasd_sleep_on(cqr, 0);
2504 EXPORT_SYMBOL(dasd_sleep_on);
2507 * Start requests from a ccw_queue and wait for their completion.
2509 int dasd_sleep_on_queue(struct list_head *ccw_queue)
2511 return _dasd_sleep_on_queue(ccw_queue, 0);
2513 EXPORT_SYMBOL(dasd_sleep_on_queue);
2516 * Start requests from a ccw_queue and wait interruptible for their completion.
2518 int dasd_sleep_on_queue_interruptible(struct list_head *ccw_queue)
2520 return _dasd_sleep_on_queue(ccw_queue, 1);
2522 EXPORT_SYMBOL(dasd_sleep_on_queue_interruptible);
2525 * Queue a request to the tail of the device ccw_queue and wait
2526 * interruptible for it's completion.
2528 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2530 return _dasd_sleep_on(cqr, 1);
2532 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2535 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2536 * for eckd devices) the currently running request has to be terminated
2537 * and be put back to status queued, before the special request is added
2538 * to the head of the queue. Then the special request is waited on normally.
2540 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2542 struct dasd_ccw_req *cqr;
2545 if (list_empty(&device->ccw_queue))
2547 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2548 rc = device->discipline->term_IO(cqr);
2551 * CQR terminated because a more important request is pending.
2552 * Undo decreasing of retry counter because this is
2553 * not an error case.
2559 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2561 struct dasd_device *device;
2564 device = cqr->startdev;
2565 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2566 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2567 cqr->status = DASD_CQR_FAILED;
2568 cqr->intrc = -EPERM;
2571 spin_lock_irq(get_ccwdev_lock(device->cdev));
2572 rc = _dasd_term_running_cqr(device);
2574 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2577 cqr->callback = dasd_wakeup_cb;
2578 cqr->callback_data = DASD_SLEEPON_START_TAG;
2579 cqr->status = DASD_CQR_QUEUED;
2581 * add new request as second
2582 * first the terminated cqr needs to be finished
2584 list_add(&cqr->devlist, device->ccw_queue.next);
2586 /* let the bh start the request to keep them in order */
2587 dasd_schedule_device_bh(device);
2589 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2591 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2593 if (cqr->status == DASD_CQR_DONE)
2595 else if (cqr->intrc)
2601 dasd_schedule_device_bh(device);
2603 dasd_schedule_block_bh(device->block);
2607 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2610 * Cancels a request that was started with dasd_sleep_on_req.
2611 * This is useful to timeout requests. The request will be
2612 * terminated if it is currently in i/o.
2613 * Returns 0 if request termination was successful
2614 * negative error code if termination failed
2615 * Cancellation of a request is an asynchronous operation! The calling
2616 * function has to wait until the request is properly returned via callback.
2618 static int __dasd_cancel_req(struct dasd_ccw_req *cqr)
2620 struct dasd_device *device = cqr->startdev;
2623 switch (cqr->status) {
2624 case DASD_CQR_QUEUED:
2625 /* request was not started - just set to cleared */
2626 cqr->status = DASD_CQR_CLEARED;
2628 case DASD_CQR_IN_IO:
2629 /* request in IO - terminate IO and release again */
2630 rc = device->discipline->term_IO(cqr);
2632 dev_err(&device->cdev->dev,
2633 "Cancelling request %p failed with rc=%d\n",
2636 cqr->stopclk = get_tod_clock();
2639 default: /* already finished or clear pending - do nothing */
2642 dasd_schedule_device_bh(device);
2646 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2648 struct dasd_device *device = cqr->startdev;
2649 unsigned long flags;
2652 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2653 rc = __dasd_cancel_req(cqr);
2654 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2659 * SECTION: Operations of the dasd_block layer.
2663 * Timeout function for dasd_block. This is used when the block layer
2664 * is waiting for something that may not come reliably, (e.g. a state
2667 static void dasd_block_timeout(struct timer_list *t)
2669 unsigned long flags;
2670 struct dasd_block *block;
2672 block = from_timer(block, t, timer);
2673 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2674 /* re-activate request queue */
2675 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2676 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2677 dasd_schedule_block_bh(block);
2678 blk_mq_run_hw_queues(block->request_queue, true);
2682 * Setup timeout for a dasd_block in jiffies.
2684 void dasd_block_set_timer(struct dasd_block *block, int expires)
2687 del_timer(&block->timer);
2689 mod_timer(&block->timer, jiffies + expires);
2691 EXPORT_SYMBOL(dasd_block_set_timer);
2694 * Clear timeout for a dasd_block.
2696 void dasd_block_clear_timer(struct dasd_block *block)
2698 del_timer(&block->timer);
2700 EXPORT_SYMBOL(dasd_block_clear_timer);
2703 * Process finished error recovery ccw.
2705 static void __dasd_process_erp(struct dasd_device *device,
2706 struct dasd_ccw_req *cqr)
2708 dasd_erp_fn_t erp_fn;
2710 if (cqr->status == DASD_CQR_DONE)
2711 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2713 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2714 erp_fn = device->discipline->erp_postaction(cqr);
2718 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2720 struct request *req;
2721 blk_status_t error = BLK_STS_OK;
2722 unsigned int proc_bytes;
2725 req = (struct request *) cqr->callback_data;
2726 dasd_profile_end(cqr->block, cqr, req);
2728 proc_bytes = cqr->proc_bytes;
2729 status = cqr->block->base->discipline->free_cp(cqr, req);
2731 error = errno_to_blk_status(status);
2732 else if (status == 0) {
2733 switch (cqr->intrc) {
2735 error = BLK_STS_NEXUS;
2738 error = BLK_STS_TRANSPORT;
2741 error = BLK_STS_TIMEOUT;
2744 error = BLK_STS_IOERR;
2750 * We need to take care for ETIMEDOUT errors here since the
2751 * complete callback does not get called in this case.
2752 * Take care of all errors here and avoid additional code to
2753 * transfer the error value to the complete callback.
2756 blk_mq_end_request(req, error);
2757 blk_mq_run_hw_queues(req->q, true);
2760 * Partial completed requests can happen with ESE devices.
2761 * During read we might have gotten a NRF error and have to
2762 * complete a request partially.
2765 blk_update_request(req, BLK_STS_OK,
2766 blk_rq_bytes(req) - proc_bytes);
2767 blk_mq_requeue_request(req, true);
2768 } else if (likely(!blk_should_fake_timeout(req->q))) {
2769 blk_mq_complete_request(req);
2775 * Process ccw request queue.
2777 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2778 struct list_head *final_queue)
2780 struct list_head *l, *n;
2781 struct dasd_ccw_req *cqr;
2782 dasd_erp_fn_t erp_fn;
2783 unsigned long flags;
2784 struct dasd_device *base = block->base;
2787 /* Process request with final status. */
2788 list_for_each_safe(l, n, &block->ccw_queue) {
2789 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2790 if (cqr->status != DASD_CQR_DONE &&
2791 cqr->status != DASD_CQR_FAILED &&
2792 cqr->status != DASD_CQR_NEED_ERP &&
2793 cqr->status != DASD_CQR_TERMINATED)
2796 if (cqr->status == DASD_CQR_TERMINATED) {
2797 base->discipline->handle_terminated_request(cqr);
2801 /* Process requests that may be recovered */
2802 if (cqr->status == DASD_CQR_NEED_ERP) {
2803 erp_fn = base->discipline->erp_action(cqr);
2804 if (IS_ERR(erp_fn(cqr)))
2809 /* log sense for fatal error */
2810 if (cqr->status == DASD_CQR_FAILED) {
2811 dasd_log_sense(cqr, &cqr->irb);
2814 /* First of all call extended error reporting. */
2815 if (dasd_eer_enabled(base) &&
2816 cqr->status == DASD_CQR_FAILED) {
2817 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2819 /* restart request */
2820 cqr->status = DASD_CQR_FILLED;
2822 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2823 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
2824 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2829 /* Process finished ERP request. */
2831 __dasd_process_erp(base, cqr);
2835 /* Rechain finished requests to final queue */
2836 cqr->endclk = get_tod_clock();
2837 list_move_tail(&cqr->blocklist, final_queue);
2841 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2843 dasd_schedule_block_bh(cqr->block);
2846 static void __dasd_block_start_head(struct dasd_block *block)
2848 struct dasd_ccw_req *cqr;
2850 if (list_empty(&block->ccw_queue))
2852 /* We allways begin with the first requests on the queue, as some
2853 * of previously started requests have to be enqueued on a
2854 * dasd_device again for error recovery.
2856 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2857 if (cqr->status != DASD_CQR_FILLED)
2859 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2860 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2861 cqr->status = DASD_CQR_FAILED;
2862 cqr->intrc = -EPERM;
2863 dasd_schedule_block_bh(block);
2866 /* Non-temporary stop condition will trigger fail fast */
2867 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2868 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2869 (!dasd_eer_enabled(block->base))) {
2870 cqr->status = DASD_CQR_FAILED;
2871 cqr->intrc = -ENOLINK;
2872 dasd_schedule_block_bh(block);
2875 /* Don't try to start requests if device is stopped */
2876 if (block->base->stopped)
2879 /* just a fail safe check, should not happen */
2881 cqr->startdev = block->base;
2883 /* make sure that the requests we submit find their way back */
2884 cqr->callback = dasd_return_cqr_cb;
2886 dasd_add_request_tail(cqr);
2891 * Central dasd_block layer routine. Takes requests from the generic
2892 * block layer request queue, creates ccw requests, enqueues them on
2893 * a dasd_device and processes ccw requests that have been returned.
2895 static void dasd_block_tasklet(unsigned long data)
2897 struct dasd_block *block = (struct dasd_block *) data;
2898 struct list_head final_queue;
2899 struct list_head *l, *n;
2900 struct dasd_ccw_req *cqr;
2901 struct dasd_queue *dq;
2903 atomic_set(&block->tasklet_scheduled, 0);
2904 INIT_LIST_HEAD(&final_queue);
2905 spin_lock_irq(&block->queue_lock);
2906 /* Finish off requests on ccw queue */
2907 __dasd_process_block_ccw_queue(block, &final_queue);
2908 spin_unlock_irq(&block->queue_lock);
2910 /* Now call the callback function of requests with final status */
2911 list_for_each_safe(l, n, &final_queue) {
2912 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2914 spin_lock_irq(&dq->lock);
2915 list_del_init(&cqr->blocklist);
2916 __dasd_cleanup_cqr(cqr);
2917 spin_unlock_irq(&dq->lock);
2920 spin_lock_irq(&block->queue_lock);
2921 /* Now check if the head of the ccw queue needs to be started. */
2922 __dasd_block_start_head(block);
2923 spin_unlock_irq(&block->queue_lock);
2925 if (waitqueue_active(&shutdown_waitq))
2926 wake_up(&shutdown_waitq);
2927 dasd_put_device(block->base);
2930 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2932 wake_up(&dasd_flush_wq);
2936 * Requeue a request back to the block request queue
2937 * only works for block requests
2939 static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
2941 struct dasd_block *block = cqr->block;
2942 struct request *req;
2947 * If the request is an ERP request there is nothing to requeue.
2948 * This will be done with the remaining original request.
2952 spin_lock_irq(&cqr->dq->lock);
2953 req = (struct request *) cqr->callback_data;
2954 blk_mq_requeue_request(req, false);
2955 spin_unlock_irq(&cqr->dq->lock);
2961 * Go through all request on the dasd_block request queue, cancel them
2962 * on the respective dasd_device, and return them to the generic
2965 static int dasd_flush_block_queue(struct dasd_block *block)
2967 struct dasd_ccw_req *cqr, *n;
2969 struct list_head flush_queue;
2970 unsigned long flags;
2972 INIT_LIST_HEAD(&flush_queue);
2973 spin_lock_bh(&block->queue_lock);
2976 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2977 /* if this request currently owned by a dasd_device cancel it */
2978 if (cqr->status >= DASD_CQR_QUEUED)
2979 rc = dasd_cancel_req(cqr);
2982 /* Rechain request (including erp chain) so it won't be
2983 * touched by the dasd_block_tasklet anymore.
2984 * Replace the callback so we notice when the request
2985 * is returned from the dasd_device layer.
2987 cqr->callback = _dasd_wake_block_flush_cb;
2988 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
2989 list_move_tail(&cqr->blocklist, &flush_queue);
2991 /* moved more than one request - need to restart */
2994 spin_unlock_bh(&block->queue_lock);
2995 /* Now call the callback function of flushed requests */
2997 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
2998 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
2999 /* Process finished ERP request. */
3001 spin_lock_bh(&block->queue_lock);
3002 __dasd_process_erp(block->base, cqr);
3003 spin_unlock_bh(&block->queue_lock);
3004 /* restart list_for_xx loop since dasd_process_erp
3005 * might remove multiple elements */
3008 /* call the callback function */
3009 spin_lock_irqsave(&cqr->dq->lock, flags);
3010 cqr->endclk = get_tod_clock();
3011 list_del_init(&cqr->blocklist);
3012 __dasd_cleanup_cqr(cqr);
3013 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3019 * Schedules a call to dasd_tasklet over the device tasklet.
3021 void dasd_schedule_block_bh(struct dasd_block *block)
3023 /* Protect against rescheduling. */
3024 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
3026 /* life cycle of block is bound to it's base device */
3027 dasd_get_device(block->base);
3028 tasklet_hi_schedule(&block->tasklet);
3030 EXPORT_SYMBOL(dasd_schedule_block_bh);
3034 * SECTION: external block device operations
3035 * (request queue handling, open, release, etc.)
3039 * Dasd request queue function. Called from ll_rw_blk.c
3041 static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
3042 const struct blk_mq_queue_data *qd)
3044 struct dasd_block *block = hctx->queue->queuedata;
3045 struct dasd_queue *dq = hctx->driver_data;
3046 struct request *req = qd->rq;
3047 struct dasd_device *basedev;
3048 struct dasd_ccw_req *cqr;
3049 blk_status_t rc = BLK_STS_OK;
3051 basedev = block->base;
3052 spin_lock_irq(&dq->lock);
3053 if (basedev->state < DASD_STATE_READY ||
3054 test_bit(DASD_FLAG_OFFLINE, &basedev->flags)) {
3055 DBF_DEV_EVENT(DBF_ERR, basedev,
3056 "device not ready for request %p", req);
3062 * if device is stopped do not fetch new requests
3063 * except failfast is active which will let requests fail
3064 * immediately in __dasd_block_start_head()
3066 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
3067 DBF_DEV_EVENT(DBF_ERR, basedev,
3068 "device stopped request %p", req);
3069 rc = BLK_STS_RESOURCE;
3073 if (basedev->features & DASD_FEATURE_READONLY &&
3074 rq_data_dir(req) == WRITE) {
3075 DBF_DEV_EVENT(DBF_ERR, basedev,
3076 "Rejecting write request %p", req);
3081 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
3082 (basedev->features & DASD_FEATURE_FAILFAST ||
3083 blk_noretry_request(req))) {
3084 DBF_DEV_EVENT(DBF_ERR, basedev,
3085 "Rejecting failfast request %p", req);
3090 cqr = basedev->discipline->build_cp(basedev, block, req);
3092 if (PTR_ERR(cqr) == -EBUSY ||
3093 PTR_ERR(cqr) == -ENOMEM ||
3094 PTR_ERR(cqr) == -EAGAIN) {
3095 rc = BLK_STS_RESOURCE;
3098 DBF_DEV_EVENT(DBF_ERR, basedev,
3099 "CCW creation failed (rc=%ld) on request %p",
3105 * Note: callback is set to dasd_return_cqr_cb in
3106 * __dasd_block_start_head to cover erp requests as well
3108 cqr->callback_data = req;
3109 cqr->status = DASD_CQR_FILLED;
3112 blk_mq_start_request(req);
3113 spin_lock(&block->queue_lock);
3114 list_add_tail(&cqr->blocklist, &block->ccw_queue);
3115 INIT_LIST_HEAD(&cqr->devlist);
3116 dasd_profile_start(block, cqr, req);
3117 dasd_schedule_block_bh(block);
3118 spin_unlock(&block->queue_lock);
3121 spin_unlock_irq(&dq->lock);
3126 * Block timeout callback, called from the block layer
3129 * BLK_EH_RESET_TIMER if the request should be left running
3130 * BLK_EH_DONE if the request is handled or terminated
3133 enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
3135 struct dasd_block *block = req->q->queuedata;
3136 struct dasd_device *device;
3137 struct dasd_ccw_req *cqr;
3138 unsigned long flags;
3141 cqr = blk_mq_rq_to_pdu(req);
3145 spin_lock_irqsave(&cqr->dq->lock, flags);
3146 device = cqr->startdev ? cqr->startdev : block->base;
3147 if (!device->blk_timeout) {
3148 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3149 return BLK_EH_RESET_TIMER;
3151 DBF_DEV_EVENT(DBF_WARNING, device,
3152 " dasd_times_out cqr %p status %x",
3155 spin_lock(&block->queue_lock);
3156 spin_lock(get_ccwdev_lock(device->cdev));
3158 cqr->intrc = -ETIMEDOUT;
3159 if (cqr->status >= DASD_CQR_QUEUED) {
3160 rc = __dasd_cancel_req(cqr);
3161 } else if (cqr->status == DASD_CQR_FILLED ||
3162 cqr->status == DASD_CQR_NEED_ERP) {
3163 cqr->status = DASD_CQR_TERMINATED;
3164 } else if (cqr->status == DASD_CQR_IN_ERP) {
3165 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3167 list_for_each_entry_safe(searchcqr, nextcqr,
3168 &block->ccw_queue, blocklist) {
3170 while (tmpcqr->refers)
3171 tmpcqr = tmpcqr->refers;
3174 /* searchcqr is an ERP request for cqr */
3175 searchcqr->retries = -1;
3176 searchcqr->intrc = -ETIMEDOUT;
3177 if (searchcqr->status >= DASD_CQR_QUEUED) {
3178 rc = __dasd_cancel_req(searchcqr);
3179 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3180 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3181 searchcqr->status = DASD_CQR_TERMINATED;
3183 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3185 * Shouldn't happen; most recent ERP
3186 * request is at the front of queue
3193 spin_unlock(get_ccwdev_lock(device->cdev));
3194 dasd_schedule_block_bh(block);
3195 spin_unlock(&block->queue_lock);
3196 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3198 return rc ? BLK_EH_RESET_TIMER : BLK_EH_DONE;
3201 static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
3204 struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
3209 spin_lock_init(&dq->lock);
3210 hctx->driver_data = dq;
3215 static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
3217 kfree(hctx->driver_data);
3218 hctx->driver_data = NULL;
3221 static void dasd_request_done(struct request *req)
3223 blk_mq_end_request(req, 0);
3224 blk_mq_run_hw_queues(req->q, true);
3227 static struct blk_mq_ops dasd_mq_ops = {
3228 .queue_rq = do_dasd_request,
3229 .complete = dasd_request_done,
3230 .timeout = dasd_times_out,
3231 .init_hctx = dasd_init_hctx,
3232 .exit_hctx = dasd_exit_hctx,
3236 * Allocate and initialize request queue and default I/O scheduler.
3238 static int dasd_alloc_queue(struct dasd_block *block)
3242 block->tag_set.ops = &dasd_mq_ops;
3243 block->tag_set.cmd_size = sizeof(struct dasd_ccw_req);
3244 block->tag_set.nr_hw_queues = nr_hw_queues;
3245 block->tag_set.queue_depth = queue_depth;
3246 block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
3247 block->tag_set.numa_node = NUMA_NO_NODE;
3249 rc = blk_mq_alloc_tag_set(&block->tag_set);
3253 block->request_queue = blk_mq_init_queue(&block->tag_set);
3254 if (IS_ERR(block->request_queue))
3255 return PTR_ERR(block->request_queue);
3257 block->request_queue->queuedata = block;
3263 * Deactivate and free request queue.
3265 static void dasd_free_queue(struct dasd_block *block)
3267 if (block->request_queue) {
3268 blk_cleanup_queue(block->request_queue);
3269 blk_mq_free_tag_set(&block->tag_set);
3270 block->request_queue = NULL;
3274 static int dasd_open(struct block_device *bdev, fmode_t mode)
3276 struct dasd_device *base;
3279 base = dasd_device_from_gendisk(bdev->bd_disk);
3283 atomic_inc(&base->block->open_count);
3284 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
3289 if (!try_module_get(base->discipline->owner)) {
3294 if (dasd_probeonly) {
3295 dev_info(&base->cdev->dev,
3296 "Accessing the DASD failed because it is in "
3297 "probeonly mode\n");
3302 if (base->state <= DASD_STATE_BASIC) {
3303 DBF_DEV_EVENT(DBF_ERR, base, " %s",
3304 " Cannot open unrecognized device");
3309 if ((mode & FMODE_WRITE) &&
3310 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3311 (base->features & DASD_FEATURE_READONLY))) {
3316 dasd_put_device(base);
3320 module_put(base->discipline->owner);
3322 atomic_dec(&base->block->open_count);
3323 dasd_put_device(base);
3327 static void dasd_release(struct gendisk *disk, fmode_t mode)
3329 struct dasd_device *base = dasd_device_from_gendisk(disk);
3331 atomic_dec(&base->block->open_count);
3332 module_put(base->discipline->owner);
3333 dasd_put_device(base);
3338 * Return disk geometry.
3340 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3342 struct dasd_device *base;
3344 base = dasd_device_from_gendisk(bdev->bd_disk);
3348 if (!base->discipline ||
3349 !base->discipline->fill_geometry) {
3350 dasd_put_device(base);
3353 base->discipline->fill_geometry(base->block, geo);
3354 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3355 dasd_put_device(base);
3359 const struct block_device_operations
3360 dasd_device_operations = {
3361 .owner = THIS_MODULE,
3363 .release = dasd_release,
3364 .ioctl = dasd_ioctl,
3365 .compat_ioctl = dasd_ioctl,
3366 .getgeo = dasd_getgeo,
3367 .set_read_only = dasd_set_read_only,
3370 /*******************************************************************************
3371 * end of block device operations
3377 #ifdef CONFIG_PROC_FS
3381 kmem_cache_destroy(dasd_page_cache);
3382 dasd_page_cache = NULL;
3383 dasd_gendisk_exit();
3385 if (dasd_debug_area != NULL) {
3386 debug_unregister(dasd_debug_area);
3387 dasd_debug_area = NULL;
3389 dasd_statistics_removeroot();
3393 * SECTION: common functions for ccw_driver use
3397 * Is the device read-only?
3398 * Note that this function does not report the setting of the
3399 * readonly device attribute, but how it is configured in z/VM.
3401 int dasd_device_is_ro(struct dasd_device *device)
3403 struct ccw_dev_id dev_id;
3404 struct diag210 diag_data;
3409 ccw_device_get_id(device->cdev, &dev_id);
3410 memset(&diag_data, 0, sizeof(diag_data));
3411 diag_data.vrdcdvno = dev_id.devno;
3412 diag_data.vrdclen = sizeof(diag_data);
3413 rc = diag210(&diag_data);
3414 if (rc == 0 || rc == 2) {
3415 return diag_data.vrdcvfla & 0x80;
3417 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3422 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3424 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3426 struct ccw_device *cdev = data;
3429 ret = ccw_device_set_online(cdev);
3431 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3432 dev_name(&cdev->dev), ret);
3436 * Initial attempt at a probe function. this can be simplified once
3437 * the other detection code is gone.
3439 int dasd_generic_probe(struct ccw_device *cdev)
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 device = dasd_device_from_cdev(cdev);
3484 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3485 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3486 /* Already doing offline processing */
3487 dasd_put_device(device);
3491 * This device is removed unconditionally. Set offline
3492 * flag to prevent dasd_open from opening it while it is
3493 * no quite down yet.
3495 dasd_set_target_state(device, DASD_STATE_NEW);
3496 cdev->handler = NULL;
3497 /* dasd_delete_device destroys the device reference. */
3498 block = device->block;
3499 dasd_delete_device(device);
3501 * life cycle of block is bound to device, so delete it after
3502 * device was safely removed
3505 dasd_free_block(block);
3507 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3510 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3511 * the device is detected for the first time and is supposed to be used
3512 * or the user has started activation through sysfs.
3514 int dasd_generic_set_online(struct ccw_device *cdev,
3515 struct dasd_discipline *base_discipline)
3517 struct dasd_discipline *discipline;
3518 struct dasd_device *device;
3521 /* first online clears initial online feature flag */
3522 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3523 device = dasd_create_device(cdev);
3525 return PTR_ERR(device);
3527 discipline = base_discipline;
3528 if (device->features & DASD_FEATURE_USEDIAG) {
3529 if (!dasd_diag_discipline_pointer) {
3530 /* Try to load the required module. */
3531 rc = request_module(DASD_DIAG_MOD);
3533 pr_warn("%s Setting the DASD online failed "
3534 "because the required module %s "
3535 "could not be loaded (rc=%d)\n",
3536 dev_name(&cdev->dev), DASD_DIAG_MOD,
3538 dasd_delete_device(device);
3542 /* Module init could have failed, so check again here after
3543 * request_module(). */
3544 if (!dasd_diag_discipline_pointer) {
3545 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3546 dev_name(&cdev->dev));
3547 dasd_delete_device(device);
3550 discipline = dasd_diag_discipline_pointer;
3552 if (!try_module_get(base_discipline->owner)) {
3553 dasd_delete_device(device);
3556 if (!try_module_get(discipline->owner)) {
3557 module_put(base_discipline->owner);
3558 dasd_delete_device(device);
3561 device->base_discipline = base_discipline;
3562 device->discipline = discipline;
3564 /* check_device will allocate block device if necessary */
3565 rc = discipline->check_device(device);
3567 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3568 dev_name(&cdev->dev), discipline->name, rc);
3569 module_put(discipline->owner);
3570 module_put(base_discipline->owner);
3571 dasd_delete_device(device);
3575 dasd_set_target_state(device, DASD_STATE_ONLINE);
3576 if (device->state <= DASD_STATE_KNOWN) {
3577 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3578 dev_name(&cdev->dev));
3580 dasd_set_target_state(device, DASD_STATE_NEW);
3582 dasd_free_block(device->block);
3583 dasd_delete_device(device);
3585 pr_debug("dasd_generic device %s found\n",
3586 dev_name(&cdev->dev));
3588 wait_event(dasd_init_waitq, _wait_for_device(device));
3590 dasd_put_device(device);
3593 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3595 int dasd_generic_set_offline(struct ccw_device *cdev)
3597 struct dasd_device *device;
3598 struct dasd_block *block;
3599 int max_count, open_count, rc;
3600 unsigned long flags;
3603 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3604 device = dasd_device_from_cdev_locked(cdev);
3605 if (IS_ERR(device)) {
3606 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3607 return PTR_ERR(device);
3611 * We must make sure that this device is currently not in use.
3612 * The open_count is increased for every opener, that includes
3613 * the blkdev_get in dasd_scan_partitions. We are only interested
3614 * in the other openers.
3616 if (device->block) {
3617 max_count = device->block->bdev ? 0 : -1;
3618 open_count = atomic_read(&device->block->open_count);
3619 if (open_count > max_count) {
3621 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3622 dev_name(&cdev->dev), open_count);
3624 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3625 dev_name(&cdev->dev));
3632 * Test if the offline processing is already running and exit if so.
3633 * If a safe offline is being processed this could only be a normal
3634 * offline that should be able to overtake the safe offline and
3635 * cancel any I/O we do not want to wait for any longer
3637 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3638 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3639 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3646 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3649 * if safe_offline is called set safe_offline_running flag and
3650 * clear safe_offline so that a call to normal offline
3651 * can overrun safe_offline processing
3653 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3654 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3655 /* need to unlock here to wait for outstanding I/O */
3656 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3658 * If we want to set the device safe offline all IO operations
3659 * should be finished before continuing the offline process
3660 * so sync bdev first and then wait for our queues to become
3663 if (device->block) {
3664 rc = fsync_bdev(device->block->bdev);
3668 dasd_schedule_device_bh(device);
3669 rc = wait_event_interruptible(shutdown_waitq,
3670 _wait_for_empty_queues(device));
3675 * check if a normal offline process overtook the offline
3676 * processing in this case simply do nothing beside returning
3677 * that we got interrupted
3678 * otherwise mark safe offline as not running any longer and
3679 * continue with normal offline
3681 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3682 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3686 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3688 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3690 dasd_set_target_state(device, DASD_STATE_NEW);
3691 /* dasd_delete_device destroys the device reference. */
3692 block = device->block;
3693 dasd_delete_device(device);
3695 * life cycle of block is bound to device, so delete it after
3696 * device was safely removed
3699 dasd_free_block(block);
3704 /* interrupted by signal */
3705 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3706 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3707 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3709 dasd_put_device(device);
3710 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3713 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3715 int dasd_generic_last_path_gone(struct dasd_device *device)
3717 struct dasd_ccw_req *cqr;
3719 dev_warn(&device->cdev->dev, "No operational channel path is left "
3720 "for the device\n");
3721 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3722 /* First of all call extended error reporting. */
3723 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3725 if (device->state < DASD_STATE_BASIC)
3727 /* Device is active. We want to keep it. */
3728 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3729 if ((cqr->status == DASD_CQR_IN_IO) ||
3730 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3731 cqr->status = DASD_CQR_QUEUED;
3734 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3735 dasd_device_clear_timer(device);
3736 dasd_schedule_device_bh(device);
3739 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3741 int dasd_generic_path_operational(struct dasd_device *device)
3743 dev_info(&device->cdev->dev, "A channel path to the device has become "
3745 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3746 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3747 dasd_schedule_device_bh(device);
3748 if (device->block) {
3749 dasd_schedule_block_bh(device->block);
3750 if (device->block->request_queue)
3751 blk_mq_run_hw_queues(device->block->request_queue,
3755 if (!device->stopped)
3756 wake_up(&generic_waitq);
3760 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3762 int dasd_generic_notify(struct ccw_device *cdev, int event)
3764 struct dasd_device *device;
3767 device = dasd_device_from_cdev_locked(cdev);
3775 dasd_path_no_path(device);
3776 ret = dasd_generic_last_path_gone(device);
3780 if (dasd_path_get_opm(device))
3781 ret = dasd_generic_path_operational(device);
3784 dasd_put_device(device);
3787 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3789 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3791 struct dasd_device *device;
3792 int chp, oldopm, hpfpm, ifccpm;
3794 device = dasd_device_from_cdev_locked(cdev);
3798 oldopm = dasd_path_get_opm(device);
3799 for (chp = 0; chp < 8; chp++) {
3800 if (path_event[chp] & PE_PATH_GONE) {
3801 dasd_path_notoper(device, chp);
3803 if (path_event[chp] & PE_PATH_AVAILABLE) {
3804 dasd_path_available(device, chp);
3805 dasd_schedule_device_bh(device);
3807 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3808 if (!dasd_path_is_operational(device, chp) &&
3809 !dasd_path_need_verify(device, chp)) {
3811 * we can not establish a pathgroup on an
3812 * unavailable path, so trigger a path
3813 * verification first
3815 dasd_path_available(device, chp);
3816 dasd_schedule_device_bh(device);
3818 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3819 "Pathgroup re-established\n");
3820 if (device->discipline->kick_validate)
3821 device->discipline->kick_validate(device);
3823 if (path_event[chp] & PE_PATH_FCES_EVENT) {
3824 dasd_path_fcsec_update(device, chp);
3825 dasd_schedule_device_bh(device);
3828 hpfpm = dasd_path_get_hpfpm(device);
3829 ifccpm = dasd_path_get_ifccpm(device);
3830 if (!dasd_path_get_opm(device) && hpfpm) {
3832 * device has no operational paths but at least one path is
3833 * disabled due to HPF errors
3834 * disable HPF at all and use the path(s) again
3836 if (device->discipline->disable_hpf)
3837 device->discipline->disable_hpf(device);
3838 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3839 dasd_path_set_tbvpm(device, hpfpm);
3840 dasd_schedule_device_bh(device);
3841 dasd_schedule_requeue(device);
3842 } else if (!dasd_path_get_opm(device) && ifccpm) {
3844 * device has no operational paths but at least one path is
3845 * disabled due to IFCC errors
3846 * trigger path verification on paths with IFCC errors
3848 dasd_path_set_tbvpm(device, ifccpm);
3849 dasd_schedule_device_bh(device);
3851 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3852 dev_warn(&device->cdev->dev,
3853 "No verified channel paths remain for the device\n");
3854 DBF_DEV_EVENT(DBF_WARNING, device,
3855 "%s", "last verified path gone");
3856 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3857 dasd_device_set_stop_bits(device,
3858 DASD_STOPPED_DC_WAIT);
3860 dasd_put_device(device);
3862 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3864 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3866 if (!dasd_path_get_opm(device) && lpm) {
3867 dasd_path_set_opm(device, lpm);
3868 dasd_generic_path_operational(device);
3870 dasd_path_add_opm(device, lpm);
3873 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3875 void dasd_generic_space_exhaust(struct dasd_device *device,
3876 struct dasd_ccw_req *cqr)
3878 dasd_eer_write(device, NULL, DASD_EER_NOSPC);
3880 if (device->state < DASD_STATE_BASIC)
3883 if (cqr->status == DASD_CQR_IN_IO ||
3884 cqr->status == DASD_CQR_CLEAR_PENDING) {
3885 cqr->status = DASD_CQR_QUEUED;
3888 dasd_device_set_stop_bits(device, DASD_STOPPED_NOSPC);
3889 dasd_device_clear_timer(device);
3890 dasd_schedule_device_bh(device);
3892 EXPORT_SYMBOL_GPL(dasd_generic_space_exhaust);
3894 void dasd_generic_space_avail(struct dasd_device *device)
3896 dev_info(&device->cdev->dev, "Extent pool space is available\n");
3897 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "space available");
3899 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOSPC);
3900 dasd_schedule_device_bh(device);
3902 if (device->block) {
3903 dasd_schedule_block_bh(device->block);
3904 if (device->block->request_queue)
3905 blk_mq_run_hw_queues(device->block->request_queue, true);
3907 if (!device->stopped)
3908 wake_up(&generic_waitq);
3910 EXPORT_SYMBOL_GPL(dasd_generic_space_avail);
3913 * clear active requests and requeue them to block layer if possible
3915 static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3917 struct list_head requeue_queue;
3918 struct dasd_ccw_req *cqr, *n;
3919 struct dasd_ccw_req *refers;
3922 INIT_LIST_HEAD(&requeue_queue);
3923 spin_lock_irq(get_ccwdev_lock(device->cdev));
3925 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3926 /* Check status and move request to flush_queue */
3927 if (cqr->status == DASD_CQR_IN_IO) {
3928 rc = device->discipline->term_IO(cqr);
3930 /* unable to terminate requeust */
3931 dev_err(&device->cdev->dev,
3932 "Unable to terminate request %p "
3933 "on suspend\n", cqr);
3934 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3935 dasd_put_device(device);
3939 list_move_tail(&cqr->devlist, &requeue_queue);
3941 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3943 list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) {
3944 wait_event(dasd_flush_wq,
3945 (cqr->status != DASD_CQR_CLEAR_PENDING));
3948 * requeue requests to blocklayer will only work
3949 * for block device requests
3951 if (_dasd_requeue_request(cqr))
3954 /* remove requests from device and block queue */
3955 list_del_init(&cqr->devlist);
3956 while (cqr->refers != NULL) {
3957 refers = cqr->refers;
3958 /* remove the request from the block queue */
3959 list_del(&cqr->blocklist);
3960 /* free the finished erp request */
3961 dasd_free_erp_request(cqr, cqr->memdev);
3966 * _dasd_requeue_request already checked for a valid
3967 * blockdevice, no need to check again
3968 * all erp requests (cqr->refers) have a cqr->block
3969 * pointer copy from the original cqr
3971 list_del_init(&cqr->blocklist);
3972 cqr->block->base->discipline->free_cp(
3973 cqr, (struct request *) cqr->callback_data);
3977 * if requests remain then they are internal request
3978 * and go back to the device queue
3980 if (!list_empty(&requeue_queue)) {
3981 /* move freeze_queue to start of the ccw_queue */
3982 spin_lock_irq(get_ccwdev_lock(device->cdev));
3983 list_splice_tail(&requeue_queue, &device->ccw_queue);
3984 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3986 dasd_schedule_device_bh(device);
3990 static void do_requeue_requests(struct work_struct *work)
3992 struct dasd_device *device = container_of(work, struct dasd_device,
3994 dasd_generic_requeue_all_requests(device);
3995 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3997 dasd_schedule_block_bh(device->block);
3998 dasd_put_device(device);
4001 void dasd_schedule_requeue(struct dasd_device *device)
4003 dasd_get_device(device);
4004 /* queue call to dasd_reload_device to the kernel event daemon. */
4005 if (!schedule_work(&device->requeue_requests))
4006 dasd_put_device(device);
4008 EXPORT_SYMBOL(dasd_schedule_requeue);
4010 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
4011 int rdc_buffer_size,
4014 struct dasd_ccw_req *cqr;
4017 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device,
4021 /* internal error 13 - Allocating the RDC request failed*/
4022 dev_err(&device->cdev->dev,
4023 "An error occurred in the DASD device driver, "
4024 "reason=%s\n", "13");
4029 ccw->cmd_code = CCW_CMD_RDC;
4030 ccw->cda = (__u32)(addr_t) cqr->data;
4032 ccw->count = rdc_buffer_size;
4033 cqr->startdev = device;
4034 cqr->memdev = device;
4035 cqr->expires = 10*HZ;
4037 cqr->buildclk = get_tod_clock();
4038 cqr->status = DASD_CQR_FILLED;
4043 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4044 void *rdc_buffer, int rdc_buffer_size)
4047 struct dasd_ccw_req *cqr;
4049 cqr = dasd_generic_build_rdc(device, rdc_buffer_size, magic);
4051 return PTR_ERR(cqr);
4053 ret = dasd_sleep_on(cqr);
4055 memcpy(rdc_buffer, cqr->data, rdc_buffer_size);
4056 dasd_sfree_request(cqr, cqr->memdev);
4059 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
4062 * In command mode and transport mode we need to look for sense
4063 * data in different places. The sense data itself is allways
4064 * an array of 32 bytes, so we can unify the sense data access
4067 char *dasd_get_sense(struct irb *irb)
4069 struct tsb *tsb = NULL;
4072 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4073 if (irb->scsw.tm.tcw)
4074 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
4076 if (tsb && tsb->length == 64 && tsb->flags)
4077 switch (tsb->flags & 0x07) {
4078 case 1: /* tsa_iostat */
4079 sense = tsb->tsa.iostat.sense;
4081 case 2: /* tsa_ddpc */
4082 sense = tsb->tsa.ddpc.sense;
4085 /* currently we don't use interrogate data */
4088 } else if (irb->esw.esw0.erw.cons) {
4093 EXPORT_SYMBOL_GPL(dasd_get_sense);
4095 void dasd_generic_shutdown(struct ccw_device *cdev)
4097 struct dasd_device *device;
4099 device = dasd_device_from_cdev(cdev);
4104 dasd_schedule_block_bh(device->block);
4106 dasd_schedule_device_bh(device);
4108 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4110 EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4112 static int __init dasd_init(void)
4116 init_waitqueue_head(&dasd_init_waitq);
4117 init_waitqueue_head(&dasd_flush_wq);
4118 init_waitqueue_head(&generic_waitq);
4119 init_waitqueue_head(&shutdown_waitq);
4121 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4122 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
4123 if (dasd_debug_area == NULL) {
4127 debug_register_view(dasd_debug_area, &debug_sprintf_view);
4128 debug_set_level(dasd_debug_area, DBF_WARNING);
4130 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4132 dasd_diag_discipline_pointer = NULL;
4134 dasd_statistics_createroot();
4136 rc = dasd_devmap_init();
4139 rc = dasd_gendisk_init();
4145 rc = dasd_eer_init();
4148 #ifdef CONFIG_PROC_FS
4149 rc = dasd_proc_init();
4156 pr_info("The DASD device driver could not be initialized\n");
4161 module_init(dasd_init);
4162 module_exit(dasd_exit);