1 // SPDX-License-Identifier: GPL-2.0
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * Copyright IBM Corp. 1999, 2009
11 #define KMSG_COMPONENT "dasd"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/kmod.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/ctype.h>
18 #include <linux/major.h>
19 #include <linux/slab.h>
20 #include <linux/hdreg.h>
21 #include <linux/async.h>
22 #include <linux/mutex.h>
23 #include <linux/debugfs.h>
24 #include <linux/seq_file.h>
25 #include <linux/vmalloc.h>
27 #include <asm/ccwdev.h>
28 #include <asm/ebcdic.h>
29 #include <asm/idals.h>
34 #define PRINTK_HEADER "dasd:"
38 * SECTION: Constant definitions to be used within this file
40 #define DASD_CHANQ_MAX_SIZE 4
42 #define DASD_DIAG_MOD "dasd_diag_mod"
44 static unsigned int queue_depth = 32;
45 static unsigned int nr_hw_queues = 4;
47 module_param(queue_depth, uint, 0444);
48 MODULE_PARM_DESC(queue_depth, "Default queue depth for new DASD devices");
50 module_param(nr_hw_queues, uint, 0444);
51 MODULE_PARM_DESC(nr_hw_queues, "Default number of hardware queues for new DASD devices");
54 * SECTION: exported variables of dasd.c
56 debug_info_t *dasd_debug_area;
57 EXPORT_SYMBOL(dasd_debug_area);
58 static struct dentry *dasd_debugfs_root_entry;
59 struct dasd_discipline *dasd_diag_discipline_pointer;
60 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
61 void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
63 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
64 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
65 " Copyright IBM Corp. 2000");
66 MODULE_SUPPORTED_DEVICE("dasd");
67 MODULE_LICENSE("GPL");
70 * SECTION: prototypes for static functions of dasd.c
72 static int dasd_alloc_queue(struct dasd_block *);
73 static void dasd_setup_queue(struct dasd_block *);
74 static void dasd_free_queue(struct dasd_block *);
75 static int dasd_flush_block_queue(struct dasd_block *);
76 static void dasd_device_tasklet(struct dasd_device *);
77 static void dasd_block_tasklet(struct dasd_block *);
78 static void do_kick_device(struct work_struct *);
79 static void do_restore_device(struct work_struct *);
80 static void do_reload_device(struct work_struct *);
81 static void do_requeue_requests(struct work_struct *);
82 static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
83 static void dasd_device_timeout(struct timer_list *);
84 static void dasd_block_timeout(struct timer_list *);
85 static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
86 static void dasd_profile_init(struct dasd_profile *, struct dentry *);
87 static void dasd_profile_exit(struct dasd_profile *);
88 static void dasd_hosts_init(struct dentry *, struct dasd_device *);
89 static void dasd_hosts_exit(struct dasd_device *);
92 * SECTION: Operations on the device structure.
94 static wait_queue_head_t dasd_init_waitq;
95 static wait_queue_head_t dasd_flush_wq;
96 static wait_queue_head_t generic_waitq;
97 static wait_queue_head_t shutdown_waitq;
100 * Allocate memory for a new device structure.
102 struct dasd_device *dasd_alloc_device(void)
104 struct dasd_device *device;
106 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
108 return ERR_PTR(-ENOMEM);
110 /* Get two pages for normal block device operations. */
111 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
112 if (!device->ccw_mem) {
114 return ERR_PTR(-ENOMEM);
116 /* Get one page for error recovery. */
117 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
118 if (!device->erp_mem) {
119 free_pages((unsigned long) device->ccw_mem, 1);
121 return ERR_PTR(-ENOMEM);
124 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
125 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
126 spin_lock_init(&device->mem_lock);
127 atomic_set(&device->tasklet_scheduled, 0);
128 tasklet_init(&device->tasklet,
129 (void (*)(unsigned long)) dasd_device_tasklet,
130 (unsigned long) device);
131 INIT_LIST_HEAD(&device->ccw_queue);
132 timer_setup(&device->timer, dasd_device_timeout, 0);
133 INIT_WORK(&device->kick_work, do_kick_device);
134 INIT_WORK(&device->restore_device, do_restore_device);
135 INIT_WORK(&device->reload_device, do_reload_device);
136 INIT_WORK(&device->requeue_requests, do_requeue_requests);
137 device->state = DASD_STATE_NEW;
138 device->target = DASD_STATE_NEW;
139 mutex_init(&device->state_mutex);
140 spin_lock_init(&device->profile.lock);
145 * Free memory of a device structure.
147 void dasd_free_device(struct dasd_device *device)
149 kfree(device->private);
150 free_page((unsigned long) device->erp_mem);
151 free_pages((unsigned long) device->ccw_mem, 1);
156 * Allocate memory for a new device structure.
158 struct dasd_block *dasd_alloc_block(void)
160 struct dasd_block *block;
162 block = kzalloc(sizeof(*block), GFP_ATOMIC);
164 return ERR_PTR(-ENOMEM);
165 /* open_count = 0 means device online but not in use */
166 atomic_set(&block->open_count, -1);
168 atomic_set(&block->tasklet_scheduled, 0);
169 tasklet_init(&block->tasklet,
170 (void (*)(unsigned long)) dasd_block_tasklet,
171 (unsigned long) block);
172 INIT_LIST_HEAD(&block->ccw_queue);
173 spin_lock_init(&block->queue_lock);
174 timer_setup(&block->timer, dasd_block_timeout, 0);
175 spin_lock_init(&block->profile.lock);
179 EXPORT_SYMBOL_GPL(dasd_alloc_block);
182 * Free memory of a device structure.
184 void dasd_free_block(struct dasd_block *block)
188 EXPORT_SYMBOL_GPL(dasd_free_block);
191 * Make a new device known to the system.
193 static int dasd_state_new_to_known(struct dasd_device *device)
198 * As long as the device is not in state DASD_STATE_NEW we want to
199 * keep the reference count > 0.
201 dasd_get_device(device);
204 rc = dasd_alloc_queue(device->block);
206 dasd_put_device(device);
210 device->state = DASD_STATE_KNOWN;
215 * Let the system forget about a device.
217 static int dasd_state_known_to_new(struct dasd_device *device)
219 /* Disable extended error reporting for this device. */
220 dasd_eer_disable(device);
221 device->state = DASD_STATE_NEW;
224 dasd_free_queue(device->block);
226 /* Give up reference we took in dasd_state_new_to_known. */
227 dasd_put_device(device);
231 static struct dentry *dasd_debugfs_setup(const char *name,
232 struct dentry *base_dentry)
238 pde = debugfs_create_dir(name, base_dentry);
239 if (!pde || IS_ERR(pde))
245 * Request the irq line for the device.
247 static int dasd_state_known_to_basic(struct dasd_device *device)
249 struct dasd_block *block = device->block;
252 /* Allocate and register gendisk structure. */
254 rc = dasd_gendisk_alloc(block);
257 block->debugfs_dentry =
258 dasd_debugfs_setup(block->gdp->disk_name,
259 dasd_debugfs_root_entry);
260 dasd_profile_init(&block->profile, block->debugfs_dentry);
261 if (dasd_global_profile_level == DASD_PROFILE_ON)
262 dasd_profile_on(&device->block->profile);
264 device->debugfs_dentry =
265 dasd_debugfs_setup(dev_name(&device->cdev->dev),
266 dasd_debugfs_root_entry);
267 dasd_profile_init(&device->profile, device->debugfs_dentry);
268 dasd_hosts_init(device->debugfs_dentry, device);
270 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
271 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
273 debug_register_view(device->debug_area, &debug_sprintf_view);
274 debug_set_level(device->debug_area, DBF_WARNING);
275 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
277 device->state = DASD_STATE_BASIC;
283 * Release the irq line for the device. Terminate any running i/o.
285 static int dasd_state_basic_to_known(struct dasd_device *device)
289 if (device->discipline->basic_to_known) {
290 rc = device->discipline->basic_to_known(device);
296 dasd_profile_exit(&device->block->profile);
297 debugfs_remove(device->block->debugfs_dentry);
298 dasd_gendisk_free(device->block);
299 dasd_block_clear_timer(device->block);
301 rc = dasd_flush_device_queue(device);
304 dasd_device_clear_timer(device);
305 dasd_profile_exit(&device->profile);
306 dasd_hosts_exit(device);
307 debugfs_remove(device->debugfs_dentry);
308 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
309 if (device->debug_area != NULL) {
310 debug_unregister(device->debug_area);
311 device->debug_area = NULL;
313 device->state = DASD_STATE_KNOWN;
318 * Do the initial analysis. The do_analysis function may return
319 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
320 * until the discipline decides to continue the startup sequence
321 * by calling the function dasd_change_state. The eckd disciplines
322 * uses this to start a ccw that detects the format. The completion
323 * interrupt for this detection ccw uses the kernel event daemon to
324 * trigger the call to dasd_change_state. All this is done in the
325 * discipline code, see dasd_eckd.c.
326 * After the analysis ccw is done (do_analysis returned 0) the block
328 * In case the analysis returns an error, the device setup is stopped
329 * (a fake disk was already added to allow formatting).
331 static int dasd_state_basic_to_ready(struct dasd_device *device)
334 struct dasd_block *block;
335 struct gendisk *disk;
338 block = device->block;
339 /* make disk known with correct capacity */
341 if (block->base->discipline->do_analysis != NULL)
342 rc = block->base->discipline->do_analysis(block);
345 device->state = DASD_STATE_UNFMT;
346 disk = device->block->gdp;
347 kobject_uevent(&disk_to_dev(disk)->kobj,
353 dasd_setup_queue(block);
354 set_capacity(block->gdp,
355 block->blocks << block->s2b_shift);
356 device->state = DASD_STATE_READY;
357 rc = dasd_scan_partitions(block);
359 device->state = DASD_STATE_BASIC;
363 device->state = DASD_STATE_READY;
366 if (device->discipline->basic_to_ready)
367 rc = device->discipline->basic_to_ready(device);
372 int _wait_for_empty_queues(struct dasd_device *device)
375 return list_empty(&device->ccw_queue) &&
376 list_empty(&device->block->ccw_queue);
378 return list_empty(&device->ccw_queue);
382 * Remove device from block device layer. Destroy dirty buffers.
383 * Forget format information. Check if the target level is basic
384 * and if it is create fake disk for formatting.
386 static int dasd_state_ready_to_basic(struct dasd_device *device)
390 device->state = DASD_STATE_BASIC;
392 struct dasd_block *block = device->block;
393 rc = dasd_flush_block_queue(block);
395 device->state = DASD_STATE_READY;
398 dasd_destroy_partitions(block);
401 block->s2b_shift = 0;
409 static int dasd_state_unfmt_to_basic(struct dasd_device *device)
411 device->state = DASD_STATE_BASIC;
416 * Make the device online and schedule the bottom half to start
417 * the requeueing of requests from the linux request queue to the
421 dasd_state_ready_to_online(struct dasd_device * device)
423 struct gendisk *disk;
424 struct disk_part_iter piter;
425 struct hd_struct *part;
427 device->state = DASD_STATE_ONLINE;
429 dasd_schedule_block_bh(device->block);
430 if ((device->features & DASD_FEATURE_USERAW)) {
431 disk = device->block->gdp;
432 kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
435 disk = device->block->bdev->bd_disk;
436 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
437 while ((part = disk_part_iter_next(&piter)))
438 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
439 disk_part_iter_exit(&piter);
445 * Stop the requeueing of requests again.
447 static int dasd_state_online_to_ready(struct dasd_device *device)
450 struct gendisk *disk;
451 struct disk_part_iter piter;
452 struct hd_struct *part;
454 if (device->discipline->online_to_ready) {
455 rc = device->discipline->online_to_ready(device);
460 device->state = DASD_STATE_READY;
461 if (device->block && !(device->features & DASD_FEATURE_USERAW)) {
462 disk = device->block->bdev->bd_disk;
463 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
464 while ((part = disk_part_iter_next(&piter)))
465 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
466 disk_part_iter_exit(&piter);
472 * Device startup state changes.
474 static int dasd_increase_state(struct dasd_device *device)
479 if (device->state == DASD_STATE_NEW &&
480 device->target >= DASD_STATE_KNOWN)
481 rc = dasd_state_new_to_known(device);
484 device->state == DASD_STATE_KNOWN &&
485 device->target >= DASD_STATE_BASIC)
486 rc = dasd_state_known_to_basic(device);
489 device->state == DASD_STATE_BASIC &&
490 device->target >= DASD_STATE_READY)
491 rc = dasd_state_basic_to_ready(device);
494 device->state == DASD_STATE_UNFMT &&
495 device->target > DASD_STATE_UNFMT)
499 device->state == DASD_STATE_READY &&
500 device->target >= DASD_STATE_ONLINE)
501 rc = dasd_state_ready_to_online(device);
507 * Device shutdown state changes.
509 static int dasd_decrease_state(struct dasd_device *device)
514 if (device->state == DASD_STATE_ONLINE &&
515 device->target <= DASD_STATE_READY)
516 rc = dasd_state_online_to_ready(device);
519 device->state == DASD_STATE_READY &&
520 device->target <= DASD_STATE_BASIC)
521 rc = dasd_state_ready_to_basic(device);
524 device->state == DASD_STATE_UNFMT &&
525 device->target <= DASD_STATE_BASIC)
526 rc = dasd_state_unfmt_to_basic(device);
529 device->state == DASD_STATE_BASIC &&
530 device->target <= DASD_STATE_KNOWN)
531 rc = dasd_state_basic_to_known(device);
534 device->state == DASD_STATE_KNOWN &&
535 device->target <= DASD_STATE_NEW)
536 rc = dasd_state_known_to_new(device);
542 * This is the main startup/shutdown routine.
544 static void dasd_change_state(struct dasd_device *device)
548 if (device->state == device->target)
549 /* Already where we want to go today... */
551 if (device->state < device->target)
552 rc = dasd_increase_state(device);
554 rc = dasd_decrease_state(device);
558 device->target = device->state;
560 /* let user-space know that the device status changed */
561 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
563 if (device->state == device->target)
564 wake_up(&dasd_init_waitq);
568 * Kick starter for devices that did not complete the startup/shutdown
569 * procedure or were sleeping because of a pending state.
570 * dasd_kick_device will schedule a call do do_kick_device to the kernel
573 static void do_kick_device(struct work_struct *work)
575 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
576 mutex_lock(&device->state_mutex);
577 dasd_change_state(device);
578 mutex_unlock(&device->state_mutex);
579 dasd_schedule_device_bh(device);
580 dasd_put_device(device);
583 void dasd_kick_device(struct dasd_device *device)
585 dasd_get_device(device);
586 /* queue call to dasd_kick_device to the kernel event daemon. */
587 if (!schedule_work(&device->kick_work))
588 dasd_put_device(device);
590 EXPORT_SYMBOL(dasd_kick_device);
593 * dasd_reload_device will schedule a call do do_reload_device to the kernel
596 static void do_reload_device(struct work_struct *work)
598 struct dasd_device *device = container_of(work, struct dasd_device,
600 device->discipline->reload(device);
601 dasd_put_device(device);
604 void dasd_reload_device(struct dasd_device *device)
606 dasd_get_device(device);
607 /* queue call to dasd_reload_device to the kernel event daemon. */
608 if (!schedule_work(&device->reload_device))
609 dasd_put_device(device);
611 EXPORT_SYMBOL(dasd_reload_device);
614 * dasd_restore_device will schedule a call do do_restore_device to the kernel
617 static void do_restore_device(struct work_struct *work)
619 struct dasd_device *device = container_of(work, struct dasd_device,
621 device->cdev->drv->restore(device->cdev);
622 dasd_put_device(device);
625 void dasd_restore_device(struct dasd_device *device)
627 dasd_get_device(device);
628 /* queue call to dasd_restore_device to the kernel event daemon. */
629 if (!schedule_work(&device->restore_device))
630 dasd_put_device(device);
634 * Set the target state for a device and starts the state change.
636 void dasd_set_target_state(struct dasd_device *device, int target)
638 dasd_get_device(device);
639 mutex_lock(&device->state_mutex);
640 /* If we are in probeonly mode stop at DASD_STATE_READY. */
641 if (dasd_probeonly && target > DASD_STATE_READY)
642 target = DASD_STATE_READY;
643 if (device->target != target) {
644 if (device->state == target)
645 wake_up(&dasd_init_waitq);
646 device->target = target;
648 if (device->state != device->target)
649 dasd_change_state(device);
650 mutex_unlock(&device->state_mutex);
651 dasd_put_device(device);
653 EXPORT_SYMBOL(dasd_set_target_state);
656 * Enable devices with device numbers in [from..to].
658 static inline int _wait_for_device(struct dasd_device *device)
660 return (device->state == device->target);
663 void dasd_enable_device(struct dasd_device *device)
665 dasd_set_target_state(device, DASD_STATE_ONLINE);
666 if (device->state <= DASD_STATE_KNOWN)
667 /* No discipline for device found. */
668 dasd_set_target_state(device, DASD_STATE_NEW);
669 /* Now wait for the devices to come up. */
670 wait_event(dasd_init_waitq, _wait_for_device(device));
672 dasd_reload_device(device);
673 if (device->discipline->kick_validate)
674 device->discipline->kick_validate(device);
676 EXPORT_SYMBOL(dasd_enable_device);
679 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
682 unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
684 #ifdef CONFIG_DASD_PROFILE
685 struct dasd_profile dasd_global_profile = {
686 .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
688 static struct dentry *dasd_debugfs_global_entry;
691 * Add profiling information for cqr before execution.
693 static void dasd_profile_start(struct dasd_block *block,
694 struct dasd_ccw_req *cqr,
698 unsigned int counter;
699 struct dasd_device *device;
701 /* count the length of the chanq for statistics */
703 if (dasd_global_profile_level || block->profile.data)
704 list_for_each(l, &block->ccw_queue)
708 spin_lock(&dasd_global_profile.lock);
709 if (dasd_global_profile.data) {
710 dasd_global_profile.data->dasd_io_nr_req[counter]++;
711 if (rq_data_dir(req) == READ)
712 dasd_global_profile.data->dasd_read_nr_req[counter]++;
714 spin_unlock(&dasd_global_profile.lock);
716 spin_lock(&block->profile.lock);
717 if (block->profile.data) {
718 block->profile.data->dasd_io_nr_req[counter]++;
719 if (rq_data_dir(req) == READ)
720 block->profile.data->dasd_read_nr_req[counter]++;
722 spin_unlock(&block->profile.lock);
725 * We count the request for the start device, even though it may run on
726 * some other device due to error recovery. This way we make sure that
727 * we count each request only once.
729 device = cqr->startdev;
730 if (device->profile.data) {
731 counter = 1; /* request is not yet queued on the start device */
732 list_for_each(l, &device->ccw_queue)
736 spin_lock(&device->profile.lock);
737 if (device->profile.data) {
738 device->profile.data->dasd_io_nr_req[counter]++;
739 if (rq_data_dir(req) == READ)
740 device->profile.data->dasd_read_nr_req[counter]++;
742 spin_unlock(&device->profile.lock);
746 * Add profiling information for cqr after execution.
749 #define dasd_profile_counter(value, index) \
751 for (index = 0; index < 31 && value >> (2+index); index++) \
755 static void dasd_profile_end_add_data(struct dasd_profile_info *data,
768 /* in case of an overflow, reset the whole profile */
769 if (data->dasd_io_reqs == UINT_MAX) {
770 memset(data, 0, sizeof(*data));
771 ktime_get_real_ts64(&data->starttod);
773 data->dasd_io_reqs++;
774 data->dasd_io_sects += sectors;
776 data->dasd_io_alias++;
780 data->dasd_io_secs[sectors_ind]++;
781 data->dasd_io_times[tottime_ind]++;
782 data->dasd_io_timps[tottimeps_ind]++;
783 data->dasd_io_time1[strtime_ind]++;
784 data->dasd_io_time2[irqtime_ind]++;
785 data->dasd_io_time2ps[irqtimeps_ind]++;
786 data->dasd_io_time3[endtime_ind]++;
789 data->dasd_read_reqs++;
790 data->dasd_read_sects += sectors;
792 data->dasd_read_alias++;
794 data->dasd_read_tpm++;
795 data->dasd_read_secs[sectors_ind]++;
796 data->dasd_read_times[tottime_ind]++;
797 data->dasd_read_time1[strtime_ind]++;
798 data->dasd_read_time2[irqtime_ind]++;
799 data->dasd_read_time3[endtime_ind]++;
803 static void dasd_profile_end(struct dasd_block *block,
804 struct dasd_ccw_req *cqr,
807 unsigned long strtime, irqtime, endtime, tottime;
808 unsigned long tottimeps, sectors;
809 struct dasd_device *device;
810 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
811 int irqtime_ind, irqtimeps_ind, endtime_ind;
812 struct dasd_profile_info *data;
814 device = cqr->startdev;
815 if (!(dasd_global_profile_level ||
816 block->profile.data ||
817 device->profile.data))
820 sectors = blk_rq_sectors(req);
821 if (!cqr->buildclk || !cqr->startclk ||
822 !cqr->stopclk || !cqr->endclk ||
826 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
827 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
828 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
829 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
830 tottimeps = tottime / sectors;
832 dasd_profile_counter(sectors, sectors_ind);
833 dasd_profile_counter(tottime, tottime_ind);
834 dasd_profile_counter(tottimeps, tottimeps_ind);
835 dasd_profile_counter(strtime, strtime_ind);
836 dasd_profile_counter(irqtime, irqtime_ind);
837 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
838 dasd_profile_counter(endtime, endtime_ind);
840 spin_lock(&dasd_global_profile.lock);
841 if (dasd_global_profile.data) {
842 data = dasd_global_profile.data;
843 data->dasd_sum_times += tottime;
844 data->dasd_sum_time_str += strtime;
845 data->dasd_sum_time_irq += irqtime;
846 data->dasd_sum_time_end += endtime;
847 dasd_profile_end_add_data(dasd_global_profile.data,
848 cqr->startdev != block->base,
850 rq_data_dir(req) == READ,
851 sectors, sectors_ind, tottime_ind,
852 tottimeps_ind, strtime_ind,
853 irqtime_ind, irqtimeps_ind,
856 spin_unlock(&dasd_global_profile.lock);
858 spin_lock(&block->profile.lock);
859 if (block->profile.data) {
860 data = block->profile.data;
861 data->dasd_sum_times += tottime;
862 data->dasd_sum_time_str += strtime;
863 data->dasd_sum_time_irq += irqtime;
864 data->dasd_sum_time_end += endtime;
865 dasd_profile_end_add_data(block->profile.data,
866 cqr->startdev != block->base,
868 rq_data_dir(req) == READ,
869 sectors, sectors_ind, tottime_ind,
870 tottimeps_ind, strtime_ind,
871 irqtime_ind, irqtimeps_ind,
874 spin_unlock(&block->profile.lock);
876 spin_lock(&device->profile.lock);
877 if (device->profile.data) {
878 data = device->profile.data;
879 data->dasd_sum_times += tottime;
880 data->dasd_sum_time_str += strtime;
881 data->dasd_sum_time_irq += irqtime;
882 data->dasd_sum_time_end += endtime;
883 dasd_profile_end_add_data(device->profile.data,
884 cqr->startdev != block->base,
886 rq_data_dir(req) == READ,
887 sectors, sectors_ind, tottime_ind,
888 tottimeps_ind, strtime_ind,
889 irqtime_ind, irqtimeps_ind,
892 spin_unlock(&device->profile.lock);
895 void dasd_profile_reset(struct dasd_profile *profile)
897 struct dasd_profile_info *data;
899 spin_lock_bh(&profile->lock);
900 data = profile->data;
902 spin_unlock_bh(&profile->lock);
905 memset(data, 0, sizeof(*data));
906 ktime_get_real_ts64(&data->starttod);
907 spin_unlock_bh(&profile->lock);
910 int dasd_profile_on(struct dasd_profile *profile)
912 struct dasd_profile_info *data;
914 data = kzalloc(sizeof(*data), GFP_KERNEL);
917 spin_lock_bh(&profile->lock);
919 spin_unlock_bh(&profile->lock);
923 ktime_get_real_ts64(&data->starttod);
924 profile->data = data;
925 spin_unlock_bh(&profile->lock);
929 void dasd_profile_off(struct dasd_profile *profile)
931 spin_lock_bh(&profile->lock);
932 kfree(profile->data);
933 profile->data = NULL;
934 spin_unlock_bh(&profile->lock);
937 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
941 buffer = vmalloc(user_len + 1);
943 return ERR_PTR(-ENOMEM);
944 if (copy_from_user(buffer, user_buf, user_len) != 0) {
946 return ERR_PTR(-EFAULT);
948 /* got the string, now strip linefeed. */
949 if (buffer[user_len - 1] == '\n')
950 buffer[user_len - 1] = 0;
952 buffer[user_len] = 0;
956 static ssize_t dasd_stats_write(struct file *file,
957 const char __user *user_buf,
958 size_t user_len, loff_t *pos)
962 struct seq_file *m = (struct seq_file *)file->private_data;
963 struct dasd_profile *prof = m->private;
965 if (user_len > 65536)
967 buffer = dasd_get_user_string(user_buf, user_len);
969 return PTR_ERR(buffer);
971 str = skip_spaces(buffer);
973 if (strncmp(str, "reset", 5) == 0) {
974 dasd_profile_reset(prof);
975 } else if (strncmp(str, "on", 2) == 0) {
976 rc = dasd_profile_on(prof);
980 if (prof == &dasd_global_profile) {
981 dasd_profile_reset(prof);
982 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
984 } else if (strncmp(str, "off", 3) == 0) {
985 if (prof == &dasd_global_profile)
986 dasd_global_profile_level = DASD_PROFILE_OFF;
987 dasd_profile_off(prof);
995 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
999 for (i = 0; i < 32; i++)
1000 seq_printf(m, "%u ", array[i]);
1004 static void dasd_stats_seq_print(struct seq_file *m,
1005 struct dasd_profile_info *data)
1007 seq_printf(m, "start_time %lld.%09ld\n",
1008 (s64)data->starttod.tv_sec, data->starttod.tv_nsec);
1009 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
1010 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
1011 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
1012 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
1013 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
1014 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
1015 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
1016 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
1017 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
1018 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
1019 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
1020 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
1021 seq_puts(m, "histogram_sectors ");
1022 dasd_stats_array(m, data->dasd_io_secs);
1023 seq_puts(m, "histogram_io_times ");
1024 dasd_stats_array(m, data->dasd_io_times);
1025 seq_puts(m, "histogram_io_times_weighted ");
1026 dasd_stats_array(m, data->dasd_io_timps);
1027 seq_puts(m, "histogram_time_build_to_ssch ");
1028 dasd_stats_array(m, data->dasd_io_time1);
1029 seq_puts(m, "histogram_time_ssch_to_irq ");
1030 dasd_stats_array(m, data->dasd_io_time2);
1031 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
1032 dasd_stats_array(m, data->dasd_io_time2ps);
1033 seq_puts(m, "histogram_time_irq_to_end ");
1034 dasd_stats_array(m, data->dasd_io_time3);
1035 seq_puts(m, "histogram_ccw_queue_length ");
1036 dasd_stats_array(m, data->dasd_io_nr_req);
1037 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
1038 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
1039 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
1040 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
1041 seq_puts(m, "histogram_read_sectors ");
1042 dasd_stats_array(m, data->dasd_read_secs);
1043 seq_puts(m, "histogram_read_times ");
1044 dasd_stats_array(m, data->dasd_read_times);
1045 seq_puts(m, "histogram_read_time_build_to_ssch ");
1046 dasd_stats_array(m, data->dasd_read_time1);
1047 seq_puts(m, "histogram_read_time_ssch_to_irq ");
1048 dasd_stats_array(m, data->dasd_read_time2);
1049 seq_puts(m, "histogram_read_time_irq_to_end ");
1050 dasd_stats_array(m, data->dasd_read_time3);
1051 seq_puts(m, "histogram_read_ccw_queue_length ");
1052 dasd_stats_array(m, data->dasd_read_nr_req);
1055 static int dasd_stats_show(struct seq_file *m, void *v)
1057 struct dasd_profile *profile;
1058 struct dasd_profile_info *data;
1060 profile = m->private;
1061 spin_lock_bh(&profile->lock);
1062 data = profile->data;
1064 spin_unlock_bh(&profile->lock);
1065 seq_puts(m, "disabled\n");
1068 dasd_stats_seq_print(m, data);
1069 spin_unlock_bh(&profile->lock);
1073 static int dasd_stats_open(struct inode *inode, struct file *file)
1075 struct dasd_profile *profile = inode->i_private;
1076 return single_open(file, dasd_stats_show, profile);
1079 static const struct file_operations dasd_stats_raw_fops = {
1080 .owner = THIS_MODULE,
1081 .open = dasd_stats_open,
1083 .llseek = seq_lseek,
1084 .release = single_release,
1085 .write = dasd_stats_write,
1088 static void dasd_profile_init(struct dasd_profile *profile,
1089 struct dentry *base_dentry)
1096 profile->dentry = NULL;
1097 profile->data = NULL;
1098 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1099 pde = debugfs_create_file("statistics", mode, base_dentry,
1100 profile, &dasd_stats_raw_fops);
1101 if (pde && !IS_ERR(pde))
1102 profile->dentry = pde;
1106 static void dasd_profile_exit(struct dasd_profile *profile)
1108 dasd_profile_off(profile);
1109 debugfs_remove(profile->dentry);
1110 profile->dentry = NULL;
1113 static void dasd_statistics_removeroot(void)
1115 dasd_global_profile_level = DASD_PROFILE_OFF;
1116 dasd_profile_exit(&dasd_global_profile);
1117 debugfs_remove(dasd_debugfs_global_entry);
1118 debugfs_remove(dasd_debugfs_root_entry);
1121 static void dasd_statistics_createroot(void)
1125 dasd_debugfs_root_entry = NULL;
1126 pde = debugfs_create_dir("dasd", NULL);
1127 if (!pde || IS_ERR(pde))
1129 dasd_debugfs_root_entry = pde;
1130 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1131 if (!pde || IS_ERR(pde))
1133 dasd_debugfs_global_entry = pde;
1134 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
1138 DBF_EVENT(DBF_ERR, "%s",
1139 "Creation of the dasd debugfs interface failed");
1140 dasd_statistics_removeroot();
1145 #define dasd_profile_start(block, cqr, req) do {} while (0)
1146 #define dasd_profile_end(block, cqr, req) do {} while (0)
1148 static void dasd_statistics_createroot(void)
1153 static void dasd_statistics_removeroot(void)
1158 int dasd_stats_generic_show(struct seq_file *m, void *v)
1160 seq_puts(m, "Statistics are not activated in this kernel\n");
1164 static void dasd_profile_init(struct dasd_profile *profile,
1165 struct dentry *base_dentry)
1170 static void dasd_profile_exit(struct dasd_profile *profile)
1175 int dasd_profile_on(struct dasd_profile *profile)
1180 #endif /* CONFIG_DASD_PROFILE */
1182 static int dasd_hosts_show(struct seq_file *m, void *v)
1184 struct dasd_device *device;
1185 int rc = -EOPNOTSUPP;
1187 device = m->private;
1188 dasd_get_device(device);
1190 if (device->discipline->hosts_print)
1191 rc = device->discipline->hosts_print(device, m);
1193 dasd_put_device(device);
1197 static int dasd_hosts_open(struct inode *inode, struct file *file)
1199 struct dasd_device *device = inode->i_private;
1201 return single_open(file, dasd_hosts_show, device);
1204 static const struct file_operations dasd_hosts_fops = {
1205 .owner = THIS_MODULE,
1206 .open = dasd_hosts_open,
1208 .llseek = seq_lseek,
1209 .release = single_release,
1212 static void dasd_hosts_exit(struct dasd_device *device)
1214 debugfs_remove(device->hosts_dentry);
1215 device->hosts_dentry = NULL;
1218 static void dasd_hosts_init(struct dentry *base_dentry,
1219 struct dasd_device *device)
1227 mode = S_IRUSR | S_IFREG;
1228 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1229 device, &dasd_hosts_fops);
1230 if (pde && !IS_ERR(pde))
1231 device->hosts_dentry = pde;
1234 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, int datasize,
1235 struct dasd_device *device,
1236 struct dasd_ccw_req *cqr)
1238 unsigned long flags;
1243 size += cplength * sizeof(struct ccw1);
1247 size += (sizeof(*cqr) + 7L) & -8L;
1249 spin_lock_irqsave(&device->mem_lock, flags);
1250 data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size);
1251 spin_unlock_irqrestore(&device->mem_lock, flags);
1253 return ERR_PTR(-ENOMEM);
1255 cqr = (void *) data;
1256 data += (sizeof(*cqr) + 7L) & -8L;
1258 memset(cqr, 0, sizeof(*cqr));
1259 cqr->mem_chunk = chunk;
1262 data += cplength * sizeof(struct ccw1);
1263 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1267 memset(cqr->data, 0, datasize);
1270 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1271 dasd_get_device(device);
1274 EXPORT_SYMBOL(dasd_smalloc_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);
1288 * Check discipline magic in cqr.
1290 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1292 struct dasd_device *device;
1296 device = cqr->startdev;
1297 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1298 DBF_DEV_EVENT(DBF_WARNING, device,
1299 " dasd_ccw_req 0x%08x magic doesn't match"
1300 " discipline 0x%08x",
1302 *(unsigned int *) device->discipline->name);
1309 * Terminate the current i/o and set the request to clear_pending.
1310 * Timer keeps device runnig.
1311 * ccw_device_clear can fail if the i/o subsystem
1314 int dasd_term_IO(struct dasd_ccw_req *cqr)
1316 struct dasd_device *device;
1318 char errorstring[ERRORLENGTH];
1321 rc = dasd_check_cqr(cqr);
1325 device = (struct dasd_device *) cqr->startdev;
1326 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1327 rc = ccw_device_clear(device->cdev, (long) cqr);
1329 case 0: /* termination successful */
1330 cqr->status = DASD_CQR_CLEAR_PENDING;
1331 cqr->stopclk = get_tod_clock();
1333 DBF_DEV_EVENT(DBF_DEBUG, device,
1334 "terminate cqr %p successful",
1338 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1339 "device gone, retry");
1343 * device not valid so no I/O could be running
1344 * handle CQR as termination successful
1346 cqr->status = DASD_CQR_CLEARED;
1347 cqr->stopclk = get_tod_clock();
1349 /* no retries for invalid devices */
1351 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1352 "EINVAL, handle as terminated");
1353 /* fake rc to success */
1357 /* internal error 10 - unknown rc*/
1358 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1359 dev_err(&device->cdev->dev, "An error occurred in the "
1360 "DASD device driver, reason=%s\n", errorstring);
1366 dasd_schedule_device_bh(device);
1369 EXPORT_SYMBOL(dasd_term_IO);
1372 * Start the i/o. This start_IO can fail if the channel is really busy.
1373 * In that case set up a timer to start the request later.
1375 int dasd_start_IO(struct dasd_ccw_req *cqr)
1377 struct dasd_device *device;
1379 char errorstring[ERRORLENGTH];
1382 rc = dasd_check_cqr(cqr);
1387 device = (struct dasd_device *) cqr->startdev;
1389 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1390 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1391 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1392 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1393 "because of stolen lock", cqr);
1394 cqr->status = DASD_CQR_ERROR;
1395 cqr->intrc = -EPERM;
1398 if (cqr->retries < 0) {
1399 /* internal error 14 - start_IO run out of retries */
1400 sprintf(errorstring, "14 %p", cqr);
1401 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1402 "device driver, reason=%s\n", errorstring);
1403 cqr->status = DASD_CQR_ERROR;
1406 cqr->startclk = get_tod_clock();
1407 cqr->starttime = jiffies;
1409 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1410 cqr->lpm &= dasd_path_get_opm(device);
1412 cqr->lpm = dasd_path_get_opm(device);
1414 if (cqr->cpmode == 1) {
1415 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1416 (long) cqr, cqr->lpm);
1418 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1419 (long) cqr, cqr->lpm, 0);
1423 cqr->status = DASD_CQR_IN_IO;
1426 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1427 "start_IO: device busy, retry later");
1430 /* -EACCES indicates that the request used only a subset of the
1431 * available paths and all these paths are gone. If the lpm of
1432 * this request was only a subset of the opm (e.g. the ppm) then
1433 * we just do a retry with all available paths.
1434 * If we already use the full opm, something is amiss, and we
1435 * need a full path verification.
1437 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1438 DBF_DEV_EVENT(DBF_WARNING, device,
1439 "start_IO: selected paths gone (%x)",
1441 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1442 cqr->lpm = dasd_path_get_opm(device);
1443 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1444 "start_IO: selected paths gone,"
1445 " retry on all paths");
1447 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1448 "start_IO: all paths in opm gone,"
1449 " do path verification");
1450 dasd_generic_last_path_gone(device);
1451 dasd_path_no_path(device);
1452 dasd_path_set_tbvpm(device,
1453 ccw_device_get_path_mask(
1458 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1459 "start_IO: -ENODEV device gone, retry");
1462 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1463 "start_IO: -EIO device gone, retry");
1466 /* most likely caused in power management context */
1467 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1468 "start_IO: -EINVAL device currently "
1472 /* internal error 11 - unknown rc */
1473 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1474 dev_err(&device->cdev->dev,
1475 "An error occurred in the DASD device driver, "
1476 "reason=%s\n", errorstring);
1483 EXPORT_SYMBOL(dasd_start_IO);
1486 * Timeout function for dasd devices. This is used for different purposes
1487 * 1) missing interrupt handler for normal operation
1488 * 2) delayed start of request where start_IO failed with -EBUSY
1489 * 3) timeout for missing state change interrupts
1490 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1491 * DASD_CQR_QUEUED for 2) and 3).
1493 static void dasd_device_timeout(struct timer_list *t)
1495 unsigned long flags;
1496 struct dasd_device *device;
1498 device = from_timer(device, t, timer);
1499 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1500 /* re-activate request queue */
1501 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1502 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1503 dasd_schedule_device_bh(device);
1507 * Setup timeout for a device in jiffies.
1509 void dasd_device_set_timer(struct dasd_device *device, int expires)
1512 del_timer(&device->timer);
1514 mod_timer(&device->timer, jiffies + expires);
1516 EXPORT_SYMBOL(dasd_device_set_timer);
1519 * Clear timeout for a device.
1521 void dasd_device_clear_timer(struct dasd_device *device)
1523 del_timer(&device->timer);
1525 EXPORT_SYMBOL(dasd_device_clear_timer);
1527 static void dasd_handle_killed_request(struct ccw_device *cdev,
1528 unsigned long intparm)
1530 struct dasd_ccw_req *cqr;
1531 struct dasd_device *device;
1535 cqr = (struct dasd_ccw_req *) intparm;
1536 if (cqr->status != DASD_CQR_IN_IO) {
1537 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1538 "invalid status in handle_killed_request: "
1539 "%02x", cqr->status);
1543 device = dasd_device_from_cdev_locked(cdev);
1544 if (IS_ERR(device)) {
1545 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1546 "unable to get device from cdev");
1550 if (!cqr->startdev ||
1551 device != cqr->startdev ||
1552 strncmp(cqr->startdev->discipline->ebcname,
1553 (char *) &cqr->magic, 4)) {
1554 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1555 "invalid device in request");
1556 dasd_put_device(device);
1560 /* Schedule request to be retried. */
1561 cqr->status = DASD_CQR_QUEUED;
1563 dasd_device_clear_timer(device);
1564 dasd_schedule_device_bh(device);
1565 dasd_put_device(device);
1568 void dasd_generic_handle_state_change(struct dasd_device *device)
1570 /* First of all start sense subsystem status request. */
1571 dasd_eer_snss(device);
1573 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1574 dasd_schedule_device_bh(device);
1575 if (device->block) {
1576 dasd_schedule_block_bh(device->block);
1577 if (device->block->request_queue)
1578 blk_mq_run_hw_queues(device->block->request_queue,
1582 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
1584 static int dasd_check_hpf_error(struct irb *irb)
1586 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1587 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1588 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1592 * Interrupt handler for "normal" ssch-io based dasd devices.
1594 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1597 struct dasd_ccw_req *cqr, *next;
1598 struct dasd_device *device;
1600 int nrf_suppressed = 0;
1601 int fp_suppressed = 0;
1605 cqr = (struct dasd_ccw_req *) intparm;
1607 switch (PTR_ERR(irb)) {
1609 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1610 device = cqr->startdev;
1611 cqr->status = DASD_CQR_CLEARED;
1612 dasd_device_clear_timer(device);
1613 wake_up(&dasd_flush_wq);
1614 dasd_schedule_device_bh(device);
1619 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1620 "request timed out\n", __func__);
1623 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1624 "unknown error %ld\n", __func__,
1627 dasd_handle_killed_request(cdev, intparm);
1631 now = get_tod_clock();
1632 /* check for conditions that should be handled immediately */
1634 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1635 scsw_cstat(&irb->scsw) == 0)) {
1637 memcpy(&cqr->irb, irb, sizeof(*irb));
1638 device = dasd_device_from_cdev_locked(cdev);
1641 /* ignore unsolicited interrupts for DIAG discipline */
1642 if (device->discipline == dasd_diag_discipline_pointer) {
1643 dasd_put_device(device);
1648 * In some cases 'File Protected' or 'No Record Found' errors
1649 * might be expected and debug log messages for the
1650 * corresponding interrupts shouldn't be written then.
1651 * Check if either of the according suppress bits is set.
1653 sense = dasd_get_sense(irb);
1655 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1656 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1657 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1658 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1660 if (!(fp_suppressed || nrf_suppressed))
1661 device->discipline->dump_sense_dbf(device, irb, "int");
1663 if (device->features & DASD_FEATURE_ERPLOG)
1664 device->discipline->dump_sense(device, cqr, irb);
1665 device->discipline->check_for_device_change(device, cqr, irb);
1666 dasd_put_device(device);
1669 /* check for for attention message */
1670 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1671 device = dasd_device_from_cdev_locked(cdev);
1672 if (!IS_ERR(device)) {
1673 device->discipline->check_attention(device,
1674 irb->esw.esw1.lpum);
1675 dasd_put_device(device);
1682 device = (struct dasd_device *) cqr->startdev;
1684 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1685 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1686 "invalid device in request");
1690 /* Check for clear pending */
1691 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1692 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1693 cqr->status = DASD_CQR_CLEARED;
1694 dasd_device_clear_timer(device);
1695 wake_up(&dasd_flush_wq);
1696 dasd_schedule_device_bh(device);
1700 /* check status - the request might have been killed by dyn detach */
1701 if (cqr->status != DASD_CQR_IN_IO) {
1702 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1703 "status %02x", dev_name(&cdev->dev), cqr->status);
1709 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1710 scsw_cstat(&irb->scsw) == 0) {
1711 /* request was completed successfully */
1712 cqr->status = DASD_CQR_SUCCESS;
1714 /* Start first request on queue if possible -> fast_io. */
1715 if (cqr->devlist.next != &device->ccw_queue) {
1716 next = list_entry(cqr->devlist.next,
1717 struct dasd_ccw_req, devlist);
1719 } else { /* error */
1720 /* check for HPF error
1721 * call discipline function to requeue all requests
1722 * and disable HPF accordingly
1724 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1725 device->discipline->handle_hpf_error)
1726 device->discipline->handle_hpf_error(device, irb);
1728 * If we don't want complex ERP for this request, then just
1729 * reset this and retry it in the fastpath
1731 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1733 if (cqr->lpm == dasd_path_get_opm(device))
1734 DBF_DEV_EVENT(DBF_DEBUG, device,
1735 "default ERP in fastpath "
1736 "(%i retries left)",
1738 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1739 cqr->lpm = dasd_path_get_opm(device);
1740 cqr->status = DASD_CQR_QUEUED;
1743 cqr->status = DASD_CQR_ERROR;
1745 if (next && (next->status == DASD_CQR_QUEUED) &&
1746 (!device->stopped)) {
1747 if (device->discipline->start_IO(next) == 0)
1748 expires = next->expires;
1751 dasd_device_set_timer(device, expires);
1753 dasd_device_clear_timer(device);
1754 dasd_schedule_device_bh(device);
1756 EXPORT_SYMBOL(dasd_int_handler);
1758 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1760 struct dasd_device *device;
1762 device = dasd_device_from_cdev_locked(cdev);
1766 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1767 device->state != device->target ||
1768 !device->discipline->check_for_device_change){
1769 dasd_put_device(device);
1772 if (device->discipline->dump_sense_dbf)
1773 device->discipline->dump_sense_dbf(device, irb, "uc");
1774 device->discipline->check_for_device_change(device, NULL, irb);
1775 dasd_put_device(device);
1777 return UC_TODO_RETRY;
1779 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1782 * If we have an error on a dasd_block layer request then we cancel
1783 * and return all further requests from the same dasd_block as well.
1785 static void __dasd_device_recovery(struct dasd_device *device,
1786 struct dasd_ccw_req *ref_cqr)
1788 struct list_head *l, *n;
1789 struct dasd_ccw_req *cqr;
1792 * only requeue request that came from the dasd_block layer
1794 if (!ref_cqr->block)
1797 list_for_each_safe(l, n, &device->ccw_queue) {
1798 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1799 if (cqr->status == DASD_CQR_QUEUED &&
1800 ref_cqr->block == cqr->block) {
1801 cqr->status = DASD_CQR_CLEARED;
1807 * Remove those ccw requests from the queue that need to be returned
1808 * to the upper layer.
1810 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1811 struct list_head *final_queue)
1813 struct list_head *l, *n;
1814 struct dasd_ccw_req *cqr;
1816 /* Process request with final status. */
1817 list_for_each_safe(l, n, &device->ccw_queue) {
1818 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1820 /* Skip any non-final request. */
1821 if (cqr->status == DASD_CQR_QUEUED ||
1822 cqr->status == DASD_CQR_IN_IO ||
1823 cqr->status == DASD_CQR_CLEAR_PENDING)
1825 if (cqr->status == DASD_CQR_ERROR) {
1826 __dasd_device_recovery(device, cqr);
1828 /* Rechain finished requests to final queue */
1829 list_move_tail(&cqr->devlist, final_queue);
1833 static void __dasd_process_cqr(struct dasd_device *device,
1834 struct dasd_ccw_req *cqr)
1836 char errorstring[ERRORLENGTH];
1838 switch (cqr->status) {
1839 case DASD_CQR_SUCCESS:
1840 cqr->status = DASD_CQR_DONE;
1842 case DASD_CQR_ERROR:
1843 cqr->status = DASD_CQR_NEED_ERP;
1845 case DASD_CQR_CLEARED:
1846 cqr->status = DASD_CQR_TERMINATED;
1849 /* internal error 12 - wrong cqr status*/
1850 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1851 dev_err(&device->cdev->dev,
1852 "An error occurred in the DASD device driver, "
1853 "reason=%s\n", errorstring);
1857 cqr->callback(cqr, cqr->callback_data);
1861 * the cqrs from the final queue are returned to the upper layer
1862 * by setting a dasd_block state and calling the callback function
1864 static void __dasd_device_process_final_queue(struct dasd_device *device,
1865 struct list_head *final_queue)
1867 struct list_head *l, *n;
1868 struct dasd_ccw_req *cqr;
1869 struct dasd_block *block;
1871 list_for_each_safe(l, n, final_queue) {
1872 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1873 list_del_init(&cqr->devlist);
1876 __dasd_process_cqr(device, cqr);
1878 spin_lock_bh(&block->queue_lock);
1879 __dasd_process_cqr(device, cqr);
1880 spin_unlock_bh(&block->queue_lock);
1886 * Take a look at the first request on the ccw queue and check
1887 * if it reached its expire time. If so, terminate the IO.
1889 static void __dasd_device_check_expire(struct dasd_device *device)
1891 struct dasd_ccw_req *cqr;
1893 if (list_empty(&device->ccw_queue))
1895 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1896 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1897 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1898 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1900 * IO in safe offline processing should not
1901 * run out of retries
1905 if (device->discipline->term_IO(cqr) != 0) {
1906 /* Hmpf, try again in 5 sec */
1907 dev_err(&device->cdev->dev,
1908 "cqr %p timed out (%lus) but cannot be "
1909 "ended, retrying in 5 s\n",
1910 cqr, (cqr->expires/HZ));
1911 cqr->expires += 5*HZ;
1912 dasd_device_set_timer(device, 5*HZ);
1914 dev_err(&device->cdev->dev,
1915 "cqr %p timed out (%lus), %i retries "
1916 "remaining\n", cqr, (cqr->expires/HZ),
1923 * return 1 when device is not eligible for IO
1925 static int __dasd_device_is_unusable(struct dasd_device *device,
1926 struct dasd_ccw_req *cqr)
1928 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM);
1930 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
1931 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1933 * dasd is being set offline
1934 * but it is no safe offline where we have to allow I/O
1938 if (device->stopped) {
1939 if (device->stopped & mask) {
1940 /* stopped and CQR will not change that. */
1943 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1944 /* CQR is not able to change device to
1948 /* CQR required to get device operational. */
1954 * Take a look at the first request on the ccw queue and check
1955 * if it needs to be started.
1957 static void __dasd_device_start_head(struct dasd_device *device)
1959 struct dasd_ccw_req *cqr;
1962 if (list_empty(&device->ccw_queue))
1964 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1965 if (cqr->status != DASD_CQR_QUEUED)
1967 /* if device is not usable return request to upper layer */
1968 if (__dasd_device_is_unusable(device, cqr)) {
1969 cqr->intrc = -EAGAIN;
1970 cqr->status = DASD_CQR_CLEARED;
1971 dasd_schedule_device_bh(device);
1975 rc = device->discipline->start_IO(cqr);
1977 dasd_device_set_timer(device, cqr->expires);
1978 else if (rc == -EACCES) {
1979 dasd_schedule_device_bh(device);
1981 /* Hmpf, try again in 1/2 sec */
1982 dasd_device_set_timer(device, 50);
1985 static void __dasd_device_check_path_events(struct dasd_device *device)
1989 if (!dasd_path_get_tbvpm(device))
1992 if (device->stopped &
1993 ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM))
1995 rc = device->discipline->verify_path(device,
1996 dasd_path_get_tbvpm(device));
1998 dasd_device_set_timer(device, 50);
2000 dasd_path_clear_all_verify(device);
2004 * Go through all request on the dasd_device request queue,
2005 * terminate them on the cdev if necessary, and return them to the
2006 * submitting layer via callback.
2008 * Make sure that all 'submitting layers' still exist when
2009 * this function is called!. In other words, when 'device' is a base
2010 * device then all block layer requests must have been removed before
2011 * via dasd_flush_block_queue.
2013 int dasd_flush_device_queue(struct dasd_device *device)
2015 struct dasd_ccw_req *cqr, *n;
2017 struct list_head flush_queue;
2019 INIT_LIST_HEAD(&flush_queue);
2020 spin_lock_irq(get_ccwdev_lock(device->cdev));
2022 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2023 /* Check status and move request to flush_queue */
2024 switch (cqr->status) {
2025 case DASD_CQR_IN_IO:
2026 rc = device->discipline->term_IO(cqr);
2028 /* unable to terminate requeust */
2029 dev_err(&device->cdev->dev,
2030 "Flushing the DASD request queue "
2031 "failed for request %p\n", cqr);
2032 /* stop flush processing */
2036 case DASD_CQR_QUEUED:
2037 cqr->stopclk = get_tod_clock();
2038 cqr->status = DASD_CQR_CLEARED;
2040 default: /* no need to modify the others */
2043 list_move_tail(&cqr->devlist, &flush_queue);
2046 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2048 * After this point all requests must be in state CLEAR_PENDING,
2049 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2050 * one of the others.
2052 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2053 wait_event(dasd_flush_wq,
2054 (cqr->status != DASD_CQR_CLEAR_PENDING));
2056 * Now set each request back to TERMINATED, DONE or NEED_ERP
2057 * and call the callback function of flushed requests
2059 __dasd_device_process_final_queue(device, &flush_queue);
2062 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2065 * Acquire the device lock and process queues for the device.
2067 static void dasd_device_tasklet(struct dasd_device *device)
2069 struct list_head final_queue;
2071 atomic_set (&device->tasklet_scheduled, 0);
2072 INIT_LIST_HEAD(&final_queue);
2073 spin_lock_irq(get_ccwdev_lock(device->cdev));
2074 /* Check expire time of first request on the ccw queue. */
2075 __dasd_device_check_expire(device);
2076 /* find final requests on ccw queue */
2077 __dasd_device_process_ccw_queue(device, &final_queue);
2078 __dasd_device_check_path_events(device);
2079 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2080 /* Now call the callback function of requests with final status */
2081 __dasd_device_process_final_queue(device, &final_queue);
2082 spin_lock_irq(get_ccwdev_lock(device->cdev));
2083 /* Now check if the head of the ccw queue needs to be started. */
2084 __dasd_device_start_head(device);
2085 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2086 if (waitqueue_active(&shutdown_waitq))
2087 wake_up(&shutdown_waitq);
2088 dasd_put_device(device);
2092 * Schedules a call to dasd_tasklet over the device tasklet.
2094 void dasd_schedule_device_bh(struct dasd_device *device)
2096 /* Protect against rescheduling. */
2097 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2099 dasd_get_device(device);
2100 tasklet_hi_schedule(&device->tasklet);
2102 EXPORT_SYMBOL(dasd_schedule_device_bh);
2104 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2106 device->stopped |= bits;
2108 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2110 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2112 device->stopped &= ~bits;
2113 if (!device->stopped)
2114 wake_up(&generic_waitq);
2116 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2119 * Queue a request to the head of the device ccw_queue.
2120 * Start the I/O if possible.
2122 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2124 struct dasd_device *device;
2125 unsigned long flags;
2127 device = cqr->startdev;
2128 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2129 cqr->status = DASD_CQR_QUEUED;
2130 list_add(&cqr->devlist, &device->ccw_queue);
2131 /* let the bh start the request to keep them in order */
2132 dasd_schedule_device_bh(device);
2133 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2135 EXPORT_SYMBOL(dasd_add_request_head);
2138 * Queue a request to the tail of the device ccw_queue.
2139 * Start the I/O if possible.
2141 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2143 struct dasd_device *device;
2144 unsigned long flags;
2146 device = cqr->startdev;
2147 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2148 cqr->status = DASD_CQR_QUEUED;
2149 list_add_tail(&cqr->devlist, &device->ccw_queue);
2150 /* let the bh start the request to keep them in order */
2151 dasd_schedule_device_bh(device);
2152 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2154 EXPORT_SYMBOL(dasd_add_request_tail);
2157 * Wakeup helper for the 'sleep_on' functions.
2159 void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2161 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2162 cqr->callback_data = DASD_SLEEPON_END_TAG;
2163 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2164 wake_up(&generic_waitq);
2166 EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
2168 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2170 struct dasd_device *device;
2173 device = cqr->startdev;
2174 spin_lock_irq(get_ccwdev_lock(device->cdev));
2175 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2176 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2181 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2183 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2185 struct dasd_device *device;
2186 dasd_erp_fn_t erp_fn;
2188 if (cqr->status == DASD_CQR_FILLED)
2190 device = cqr->startdev;
2191 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2192 if (cqr->status == DASD_CQR_TERMINATED) {
2193 device->discipline->handle_terminated_request(cqr);
2196 if (cqr->status == DASD_CQR_NEED_ERP) {
2197 erp_fn = device->discipline->erp_action(cqr);
2201 if (cqr->status == DASD_CQR_FAILED)
2202 dasd_log_sense(cqr, &cqr->irb);
2204 __dasd_process_erp(device, cqr);
2211 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2213 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2214 if (cqr->refers) /* erp is not done yet */
2216 return ((cqr->status != DASD_CQR_DONE) &&
2217 (cqr->status != DASD_CQR_FAILED));
2219 return (cqr->status == DASD_CQR_FILLED);
2222 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2224 struct dasd_device *device;
2226 struct list_head ccw_queue;
2227 struct dasd_ccw_req *cqr;
2229 INIT_LIST_HEAD(&ccw_queue);
2230 maincqr->status = DASD_CQR_FILLED;
2231 device = maincqr->startdev;
2232 list_add(&maincqr->blocklist, &ccw_queue);
2233 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2234 cqr = list_first_entry(&ccw_queue,
2235 struct dasd_ccw_req, blocklist)) {
2237 if (__dasd_sleep_on_erp(cqr))
2239 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2241 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2242 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2243 cqr->status = DASD_CQR_FAILED;
2244 cqr->intrc = -EPERM;
2247 /* Non-temporary stop condition will trigger fail fast */
2248 if (device->stopped & ~DASD_STOPPED_PENDING &&
2249 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2250 (!dasd_eer_enabled(device))) {
2251 cqr->status = DASD_CQR_FAILED;
2252 cqr->intrc = -ENOLINK;
2256 * Don't try to start requests if device is in
2257 * offline processing, it might wait forever
2259 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2260 cqr->status = DASD_CQR_FAILED;
2261 cqr->intrc = -ENODEV;
2265 * Don't try to start requests if device is stopped
2266 * except path verification requests
2268 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2269 if (interruptible) {
2270 rc = wait_event_interruptible(
2271 generic_waitq, !(device->stopped));
2272 if (rc == -ERESTARTSYS) {
2273 cqr->status = DASD_CQR_FAILED;
2274 maincqr->intrc = rc;
2278 wait_event(generic_waitq, !(device->stopped));
2281 cqr->callback = dasd_wakeup_cb;
2283 cqr->callback_data = DASD_SLEEPON_START_TAG;
2284 dasd_add_request_tail(cqr);
2285 if (interruptible) {
2286 rc = wait_event_interruptible(
2287 generic_waitq, _wait_for_wakeup(cqr));
2288 if (rc == -ERESTARTSYS) {
2289 dasd_cancel_req(cqr);
2290 /* wait (non-interruptible) for final status */
2291 wait_event(generic_waitq,
2292 _wait_for_wakeup(cqr));
2293 cqr->status = DASD_CQR_FAILED;
2294 maincqr->intrc = rc;
2298 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2301 maincqr->endclk = get_tod_clock();
2302 if ((maincqr->status != DASD_CQR_DONE) &&
2303 (maincqr->intrc != -ERESTARTSYS))
2304 dasd_log_sense(maincqr, &maincqr->irb);
2305 if (maincqr->status == DASD_CQR_DONE)
2307 else if (maincqr->intrc)
2308 rc = maincqr->intrc;
2314 static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2316 struct dasd_ccw_req *cqr;
2318 list_for_each_entry(cqr, ccw_queue, blocklist) {
2319 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2326 static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2328 struct dasd_device *device;
2329 struct dasd_ccw_req *cqr, *n;
2334 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2335 device = cqr->startdev;
2336 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2339 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2340 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2341 cqr->status = DASD_CQR_FAILED;
2342 cqr->intrc = -EPERM;
2345 /*Non-temporary stop condition will trigger fail fast*/
2346 if (device->stopped & ~DASD_STOPPED_PENDING &&
2347 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2348 !dasd_eer_enabled(device)) {
2349 cqr->status = DASD_CQR_FAILED;
2350 cqr->intrc = -EAGAIN;
2354 /*Don't try to start requests if device is stopped*/
2355 if (interruptible) {
2356 rc = wait_event_interruptible(
2357 generic_waitq, !device->stopped);
2358 if (rc == -ERESTARTSYS) {
2359 cqr->status = DASD_CQR_FAILED;
2364 wait_event(generic_waitq, !(device->stopped));
2367 cqr->callback = dasd_wakeup_cb;
2368 cqr->callback_data = DASD_SLEEPON_START_TAG;
2369 dasd_add_request_tail(cqr);
2372 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2375 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2377 * In some cases the 'File Protected' or 'Incorrect Length'
2378 * error might be expected and error recovery would be
2379 * unnecessary in these cases. Check if the according suppress
2382 sense = dasd_get_sense(&cqr->irb);
2383 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2384 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2386 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2387 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2391 * for alias devices simplify error recovery and
2392 * return to upper layer
2393 * do not skip ERP requests
2395 if (cqr->startdev != cqr->basedev && !cqr->refers &&
2396 (cqr->status == DASD_CQR_TERMINATED ||
2397 cqr->status == DASD_CQR_NEED_ERP))
2400 /* normal recovery for basedev IO */
2401 if (__dasd_sleep_on_erp(cqr))
2402 /* handle erp first */
2410 * Queue a request to the tail of the device ccw_queue and wait for
2413 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2415 return _dasd_sleep_on(cqr, 0);
2417 EXPORT_SYMBOL(dasd_sleep_on);
2420 * Start requests from a ccw_queue and wait for their completion.
2422 int dasd_sleep_on_queue(struct list_head *ccw_queue)
2424 return _dasd_sleep_on_queue(ccw_queue, 0);
2426 EXPORT_SYMBOL(dasd_sleep_on_queue);
2429 * Queue a request to the tail of the device ccw_queue and wait
2430 * interruptible for it's completion.
2432 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2434 return _dasd_sleep_on(cqr, 1);
2436 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2439 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2440 * for eckd devices) the currently running request has to be terminated
2441 * and be put back to status queued, before the special request is added
2442 * to the head of the queue. Then the special request is waited on normally.
2444 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2446 struct dasd_ccw_req *cqr;
2449 if (list_empty(&device->ccw_queue))
2451 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2452 rc = device->discipline->term_IO(cqr);
2455 * CQR terminated because a more important request is pending.
2456 * Undo decreasing of retry counter because this is
2457 * not an error case.
2463 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2465 struct dasd_device *device;
2468 device = cqr->startdev;
2469 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2470 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2471 cqr->status = DASD_CQR_FAILED;
2472 cqr->intrc = -EPERM;
2475 spin_lock_irq(get_ccwdev_lock(device->cdev));
2476 rc = _dasd_term_running_cqr(device);
2478 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2481 cqr->callback = dasd_wakeup_cb;
2482 cqr->callback_data = DASD_SLEEPON_START_TAG;
2483 cqr->status = DASD_CQR_QUEUED;
2485 * add new request as second
2486 * first the terminated cqr needs to be finished
2488 list_add(&cqr->devlist, device->ccw_queue.next);
2490 /* let the bh start the request to keep them in order */
2491 dasd_schedule_device_bh(device);
2493 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2495 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2497 if (cqr->status == DASD_CQR_DONE)
2499 else if (cqr->intrc)
2505 dasd_schedule_device_bh(device);
2507 dasd_schedule_block_bh(device->block);
2511 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2514 * Cancels a request that was started with dasd_sleep_on_req.
2515 * This is useful to timeout requests. The request will be
2516 * terminated if it is currently in i/o.
2517 * Returns 0 if request termination was successful
2518 * negative error code if termination failed
2519 * Cancellation of a request is an asynchronous operation! The calling
2520 * function has to wait until the request is properly returned via callback.
2522 static int __dasd_cancel_req(struct dasd_ccw_req *cqr)
2524 struct dasd_device *device = cqr->startdev;
2527 switch (cqr->status) {
2528 case DASD_CQR_QUEUED:
2529 /* request was not started - just set to cleared */
2530 cqr->status = DASD_CQR_CLEARED;
2532 case DASD_CQR_IN_IO:
2533 /* request in IO - terminate IO and release again */
2534 rc = device->discipline->term_IO(cqr);
2536 dev_err(&device->cdev->dev,
2537 "Cancelling request %p failed with rc=%d\n",
2540 cqr->stopclk = get_tod_clock();
2543 default: /* already finished or clear pending - do nothing */
2546 dasd_schedule_device_bh(device);
2550 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2552 struct dasd_device *device = cqr->startdev;
2553 unsigned long flags;
2556 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2557 rc = __dasd_cancel_req(cqr);
2558 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2563 * SECTION: Operations of the dasd_block layer.
2567 * Timeout function for dasd_block. This is used when the block layer
2568 * is waiting for something that may not come reliably, (e.g. a state
2571 static void dasd_block_timeout(struct timer_list *t)
2573 unsigned long flags;
2574 struct dasd_block *block;
2576 block = from_timer(block, t, timer);
2577 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2578 /* re-activate request queue */
2579 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2580 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2581 dasd_schedule_block_bh(block);
2582 blk_mq_run_hw_queues(block->request_queue, true);
2586 * Setup timeout for a dasd_block in jiffies.
2588 void dasd_block_set_timer(struct dasd_block *block, int expires)
2591 del_timer(&block->timer);
2593 mod_timer(&block->timer, jiffies + expires);
2595 EXPORT_SYMBOL(dasd_block_set_timer);
2598 * Clear timeout for a dasd_block.
2600 void dasd_block_clear_timer(struct dasd_block *block)
2602 del_timer(&block->timer);
2604 EXPORT_SYMBOL(dasd_block_clear_timer);
2607 * Process finished error recovery ccw.
2609 static void __dasd_process_erp(struct dasd_device *device,
2610 struct dasd_ccw_req *cqr)
2612 dasd_erp_fn_t erp_fn;
2614 if (cqr->status == DASD_CQR_DONE)
2615 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2617 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2618 erp_fn = device->discipline->erp_postaction(cqr);
2622 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2624 struct request *req;
2625 blk_status_t error = BLK_STS_OK;
2628 req = (struct request *) cqr->callback_data;
2629 dasd_profile_end(cqr->block, cqr, req);
2631 status = cqr->block->base->discipline->free_cp(cqr, req);
2633 error = errno_to_blk_status(status);
2634 else if (status == 0) {
2635 switch (cqr->intrc) {
2637 error = BLK_STS_NEXUS;
2640 error = BLK_STS_TRANSPORT;
2643 error = BLK_STS_TIMEOUT;
2646 error = BLK_STS_IOERR;
2652 * We need to take care for ETIMEDOUT errors here since the
2653 * complete callback does not get called in this case.
2654 * Take care of all errors here and avoid additional code to
2655 * transfer the error value to the complete callback.
2658 blk_mq_end_request(req, error);
2659 blk_mq_run_hw_queues(req->q, true);
2661 blk_mq_complete_request(req);
2666 * Process ccw request queue.
2668 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2669 struct list_head *final_queue)
2671 struct list_head *l, *n;
2672 struct dasd_ccw_req *cqr;
2673 dasd_erp_fn_t erp_fn;
2674 unsigned long flags;
2675 struct dasd_device *base = block->base;
2678 /* Process request with final status. */
2679 list_for_each_safe(l, n, &block->ccw_queue) {
2680 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2681 if (cqr->status != DASD_CQR_DONE &&
2682 cqr->status != DASD_CQR_FAILED &&
2683 cqr->status != DASD_CQR_NEED_ERP &&
2684 cqr->status != DASD_CQR_TERMINATED)
2687 if (cqr->status == DASD_CQR_TERMINATED) {
2688 base->discipline->handle_terminated_request(cqr);
2692 /* Process requests that may be recovered */
2693 if (cqr->status == DASD_CQR_NEED_ERP) {
2694 erp_fn = base->discipline->erp_action(cqr);
2695 if (IS_ERR(erp_fn(cqr)))
2700 /* log sense for fatal error */
2701 if (cqr->status == DASD_CQR_FAILED) {
2702 dasd_log_sense(cqr, &cqr->irb);
2705 /* First of all call extended error reporting. */
2706 if (dasd_eer_enabled(base) &&
2707 cqr->status == DASD_CQR_FAILED) {
2708 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2710 /* restart request */
2711 cqr->status = DASD_CQR_FILLED;
2713 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2714 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
2715 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2720 /* Process finished ERP request. */
2722 __dasd_process_erp(base, cqr);
2726 /* Rechain finished requests to final queue */
2727 cqr->endclk = get_tod_clock();
2728 list_move_tail(&cqr->blocklist, final_queue);
2732 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2734 dasd_schedule_block_bh(cqr->block);
2737 static void __dasd_block_start_head(struct dasd_block *block)
2739 struct dasd_ccw_req *cqr;
2741 if (list_empty(&block->ccw_queue))
2743 /* We allways begin with the first requests on the queue, as some
2744 * of previously started requests have to be enqueued on a
2745 * dasd_device again for error recovery.
2747 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2748 if (cqr->status != DASD_CQR_FILLED)
2750 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2751 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2752 cqr->status = DASD_CQR_FAILED;
2753 cqr->intrc = -EPERM;
2754 dasd_schedule_block_bh(block);
2757 /* Non-temporary stop condition will trigger fail fast */
2758 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2759 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2760 (!dasd_eer_enabled(block->base))) {
2761 cqr->status = DASD_CQR_FAILED;
2762 cqr->intrc = -ENOLINK;
2763 dasd_schedule_block_bh(block);
2766 /* Don't try to start requests if device is stopped */
2767 if (block->base->stopped)
2770 /* just a fail safe check, should not happen */
2772 cqr->startdev = block->base;
2774 /* make sure that the requests we submit find their way back */
2775 cqr->callback = dasd_return_cqr_cb;
2777 dasd_add_request_tail(cqr);
2782 * Central dasd_block layer routine. Takes requests from the generic
2783 * block layer request queue, creates ccw requests, enqueues them on
2784 * a dasd_device and processes ccw requests that have been returned.
2786 static void dasd_block_tasklet(struct dasd_block *block)
2788 struct list_head final_queue;
2789 struct list_head *l, *n;
2790 struct dasd_ccw_req *cqr;
2791 struct dasd_queue *dq;
2793 atomic_set(&block->tasklet_scheduled, 0);
2794 INIT_LIST_HEAD(&final_queue);
2795 spin_lock_irq(&block->queue_lock);
2796 /* Finish off requests on ccw queue */
2797 __dasd_process_block_ccw_queue(block, &final_queue);
2798 spin_unlock_irq(&block->queue_lock);
2800 /* Now call the callback function of requests with final status */
2801 list_for_each_safe(l, n, &final_queue) {
2802 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2804 spin_lock_irq(&dq->lock);
2805 list_del_init(&cqr->blocklist);
2806 __dasd_cleanup_cqr(cqr);
2807 spin_unlock_irq(&dq->lock);
2810 spin_lock_irq(&block->queue_lock);
2811 /* Now check if the head of the ccw queue needs to be started. */
2812 __dasd_block_start_head(block);
2813 spin_unlock_irq(&block->queue_lock);
2815 if (waitqueue_active(&shutdown_waitq))
2816 wake_up(&shutdown_waitq);
2817 dasd_put_device(block->base);
2820 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2822 wake_up(&dasd_flush_wq);
2826 * Requeue a request back to the block request queue
2827 * only works for block requests
2829 static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
2831 struct dasd_block *block = cqr->block;
2832 struct request *req;
2836 spin_lock_irq(&cqr->dq->lock);
2837 req = (struct request *) cqr->callback_data;
2838 blk_mq_requeue_request(req, false);
2839 spin_unlock_irq(&cqr->dq->lock);
2845 * Go through all request on the dasd_block request queue, cancel them
2846 * on the respective dasd_device, and return them to the generic
2849 static int dasd_flush_block_queue(struct dasd_block *block)
2851 struct dasd_ccw_req *cqr, *n;
2853 struct list_head flush_queue;
2854 unsigned long flags;
2856 INIT_LIST_HEAD(&flush_queue);
2857 spin_lock_bh(&block->queue_lock);
2860 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2861 /* if this request currently owned by a dasd_device cancel it */
2862 if (cqr->status >= DASD_CQR_QUEUED)
2863 rc = dasd_cancel_req(cqr);
2866 /* Rechain request (including erp chain) so it won't be
2867 * touched by the dasd_block_tasklet anymore.
2868 * Replace the callback so we notice when the request
2869 * is returned from the dasd_device layer.
2871 cqr->callback = _dasd_wake_block_flush_cb;
2872 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
2873 list_move_tail(&cqr->blocklist, &flush_queue);
2875 /* moved more than one request - need to restart */
2878 spin_unlock_bh(&block->queue_lock);
2879 /* Now call the callback function of flushed requests */
2881 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
2882 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
2883 /* Process finished ERP request. */
2885 spin_lock_bh(&block->queue_lock);
2886 __dasd_process_erp(block->base, cqr);
2887 spin_unlock_bh(&block->queue_lock);
2888 /* restart list_for_xx loop since dasd_process_erp
2889 * might remove multiple elements */
2892 /* call the callback function */
2893 spin_lock_irqsave(&cqr->dq->lock, flags);
2894 cqr->endclk = get_tod_clock();
2895 list_del_init(&cqr->blocklist);
2896 __dasd_cleanup_cqr(cqr);
2897 spin_unlock_irqrestore(&cqr->dq->lock, flags);
2903 * Schedules a call to dasd_tasklet over the device tasklet.
2905 void dasd_schedule_block_bh(struct dasd_block *block)
2907 /* Protect against rescheduling. */
2908 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
2910 /* life cycle of block is bound to it's base device */
2911 dasd_get_device(block->base);
2912 tasklet_hi_schedule(&block->tasklet);
2914 EXPORT_SYMBOL(dasd_schedule_block_bh);
2918 * SECTION: external block device operations
2919 * (request queue handling, open, release, etc.)
2923 * Dasd request queue function. Called from ll_rw_blk.c
2925 static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
2926 const struct blk_mq_queue_data *qd)
2928 struct dasd_block *block = hctx->queue->queuedata;
2929 struct dasd_queue *dq = hctx->driver_data;
2930 struct request *req = qd->rq;
2931 struct dasd_device *basedev;
2932 struct dasd_ccw_req *cqr;
2933 blk_status_t rc = BLK_STS_OK;
2935 basedev = block->base;
2936 spin_lock_irq(&dq->lock);
2937 if (basedev->state < DASD_STATE_READY) {
2938 DBF_DEV_EVENT(DBF_ERR, basedev,
2939 "device not ready for request %p", req);
2945 * if device is stopped do not fetch new requests
2946 * except failfast is active which will let requests fail
2947 * immediately in __dasd_block_start_head()
2949 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
2950 DBF_DEV_EVENT(DBF_ERR, basedev,
2951 "device stopped request %p", req);
2952 rc = BLK_STS_RESOURCE;
2956 if (basedev->features & DASD_FEATURE_READONLY &&
2957 rq_data_dir(req) == WRITE) {
2958 DBF_DEV_EVENT(DBF_ERR, basedev,
2959 "Rejecting write request %p", req);
2964 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
2965 (basedev->features & DASD_FEATURE_FAILFAST ||
2966 blk_noretry_request(req))) {
2967 DBF_DEV_EVENT(DBF_ERR, basedev,
2968 "Rejecting failfast request %p", req);
2973 cqr = basedev->discipline->build_cp(basedev, block, req);
2975 if (PTR_ERR(cqr) == -EBUSY ||
2976 PTR_ERR(cqr) == -ENOMEM ||
2977 PTR_ERR(cqr) == -EAGAIN) {
2978 rc = BLK_STS_RESOURCE;
2981 DBF_DEV_EVENT(DBF_ERR, basedev,
2982 "CCW creation failed (rc=%ld) on request %p",
2988 * Note: callback is set to dasd_return_cqr_cb in
2989 * __dasd_block_start_head to cover erp requests as well
2991 cqr->callback_data = req;
2992 cqr->status = DASD_CQR_FILLED;
2995 blk_mq_start_request(req);
2996 spin_lock(&block->queue_lock);
2997 list_add_tail(&cqr->blocklist, &block->ccw_queue);
2998 INIT_LIST_HEAD(&cqr->devlist);
2999 dasd_profile_start(block, cqr, req);
3000 dasd_schedule_block_bh(block);
3001 spin_unlock(&block->queue_lock);
3004 spin_unlock_irq(&dq->lock);
3009 * Block timeout callback, called from the block layer
3012 * BLK_EH_RESET_TIMER if the request should be left running
3013 * BLK_EH_DONE if the request is handled or terminated
3016 enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
3018 struct dasd_block *block = req->q->queuedata;
3019 struct dasd_device *device;
3020 struct dasd_ccw_req *cqr;
3021 unsigned long flags;
3024 cqr = blk_mq_rq_to_pdu(req);
3028 spin_lock_irqsave(&cqr->dq->lock, flags);
3029 device = cqr->startdev ? cqr->startdev : block->base;
3030 if (!device->blk_timeout) {
3031 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3032 return BLK_EH_RESET_TIMER;
3034 DBF_DEV_EVENT(DBF_WARNING, device,
3035 " dasd_times_out cqr %p status %x",
3038 spin_lock(&block->queue_lock);
3039 spin_lock(get_ccwdev_lock(device->cdev));
3041 cqr->intrc = -ETIMEDOUT;
3042 if (cqr->status >= DASD_CQR_QUEUED) {
3043 rc = __dasd_cancel_req(cqr);
3044 } else if (cqr->status == DASD_CQR_FILLED ||
3045 cqr->status == DASD_CQR_NEED_ERP) {
3046 cqr->status = DASD_CQR_TERMINATED;
3047 } else if (cqr->status == DASD_CQR_IN_ERP) {
3048 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3050 list_for_each_entry_safe(searchcqr, nextcqr,
3051 &block->ccw_queue, blocklist) {
3053 while (tmpcqr->refers)
3054 tmpcqr = tmpcqr->refers;
3057 /* searchcqr is an ERP request for cqr */
3058 searchcqr->retries = -1;
3059 searchcqr->intrc = -ETIMEDOUT;
3060 if (searchcqr->status >= DASD_CQR_QUEUED) {
3061 rc = __dasd_cancel_req(searchcqr);
3062 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3063 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3064 searchcqr->status = DASD_CQR_TERMINATED;
3066 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3068 * Shouldn't happen; most recent ERP
3069 * request is at the front of queue
3076 spin_unlock(get_ccwdev_lock(device->cdev));
3077 dasd_schedule_block_bh(block);
3078 spin_unlock(&block->queue_lock);
3079 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3081 return rc ? BLK_EH_RESET_TIMER : BLK_EH_DONE;
3084 static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
3087 struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
3092 spin_lock_init(&dq->lock);
3093 hctx->driver_data = dq;
3098 static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
3100 kfree(hctx->driver_data);
3101 hctx->driver_data = NULL;
3104 static void dasd_request_done(struct request *req)
3106 blk_mq_end_request(req, 0);
3107 blk_mq_run_hw_queues(req->q, true);
3110 static struct blk_mq_ops dasd_mq_ops = {
3111 .queue_rq = do_dasd_request,
3112 .complete = dasd_request_done,
3113 .timeout = dasd_times_out,
3114 .init_hctx = dasd_init_hctx,
3115 .exit_hctx = dasd_exit_hctx,
3119 * Allocate and initialize request queue and default I/O scheduler.
3121 static int dasd_alloc_queue(struct dasd_block *block)
3125 block->tag_set.ops = &dasd_mq_ops;
3126 block->tag_set.cmd_size = sizeof(struct dasd_ccw_req);
3127 block->tag_set.nr_hw_queues = nr_hw_queues;
3128 block->tag_set.queue_depth = queue_depth;
3129 block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
3131 rc = blk_mq_alloc_tag_set(&block->tag_set);
3135 block->request_queue = blk_mq_init_queue(&block->tag_set);
3136 if (IS_ERR(block->request_queue))
3137 return PTR_ERR(block->request_queue);
3139 block->request_queue->queuedata = block;
3145 * Allocate and initialize request queue.
3147 static void dasd_setup_queue(struct dasd_block *block)
3149 unsigned int logical_block_size = block->bp_block;
3150 struct request_queue *q = block->request_queue;
3151 unsigned int max_bytes, max_discard_sectors;
3154 if (block->base->features & DASD_FEATURE_USERAW) {
3156 * the max_blocks value for raw_track access is 256
3157 * it is higher than the native ECKD value because we
3158 * only need one ccw per track
3159 * so the max_hw_sectors are
3160 * 2048 x 512B = 1024kB = 16 tracks
3164 max = block->base->discipline->max_blocks << block->s2b_shift;
3166 blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
3167 q->limits.max_dev_sectors = max;
3168 blk_queue_logical_block_size(q, logical_block_size);
3169 blk_queue_max_hw_sectors(q, max);
3170 blk_queue_max_segments(q, USHRT_MAX);
3171 /* with page sized segments we can translate each segement into
3174 blk_queue_max_segment_size(q, PAGE_SIZE);
3175 blk_queue_segment_boundary(q, PAGE_SIZE - 1);
3177 /* Only activate blocklayer discard support for devices that support it */
3178 if (block->base->features & DASD_FEATURE_DISCARD) {
3179 q->limits.discard_granularity = logical_block_size;
3180 q->limits.discard_alignment = PAGE_SIZE;
3182 /* Calculate max_discard_sectors and make it PAGE aligned */
3183 max_bytes = USHRT_MAX * logical_block_size;
3184 max_bytes = ALIGN(max_bytes, PAGE_SIZE) - PAGE_SIZE;
3185 max_discard_sectors = max_bytes / logical_block_size;
3187 blk_queue_max_discard_sectors(q, max_discard_sectors);
3188 blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
3189 blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
3194 * Deactivate and free request queue.
3196 static void dasd_free_queue(struct dasd_block *block)
3198 if (block->request_queue) {
3199 blk_cleanup_queue(block->request_queue);
3200 blk_mq_free_tag_set(&block->tag_set);
3201 block->request_queue = NULL;
3205 static int dasd_open(struct block_device *bdev, fmode_t mode)
3207 struct dasd_device *base;
3210 base = dasd_device_from_gendisk(bdev->bd_disk);
3214 atomic_inc(&base->block->open_count);
3215 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
3220 if (!try_module_get(base->discipline->owner)) {
3225 if (dasd_probeonly) {
3226 dev_info(&base->cdev->dev,
3227 "Accessing the DASD failed because it is in "
3228 "probeonly mode\n");
3233 if (base->state <= DASD_STATE_BASIC) {
3234 DBF_DEV_EVENT(DBF_ERR, base, " %s",
3235 " Cannot open unrecognized device");
3240 if ((mode & FMODE_WRITE) &&
3241 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3242 (base->features & DASD_FEATURE_READONLY))) {
3247 dasd_put_device(base);
3251 module_put(base->discipline->owner);
3253 atomic_dec(&base->block->open_count);
3254 dasd_put_device(base);
3258 static void dasd_release(struct gendisk *disk, fmode_t mode)
3260 struct dasd_device *base = dasd_device_from_gendisk(disk);
3262 atomic_dec(&base->block->open_count);
3263 module_put(base->discipline->owner);
3264 dasd_put_device(base);
3269 * Return disk geometry.
3271 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3273 struct dasd_device *base;
3275 base = dasd_device_from_gendisk(bdev->bd_disk);
3279 if (!base->discipline ||
3280 !base->discipline->fill_geometry) {
3281 dasd_put_device(base);
3284 base->discipline->fill_geometry(base->block, geo);
3285 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3286 dasd_put_device(base);
3290 const struct block_device_operations
3291 dasd_device_operations = {
3292 .owner = THIS_MODULE,
3294 .release = dasd_release,
3295 .ioctl = dasd_ioctl,
3296 .compat_ioctl = dasd_ioctl,
3297 .getgeo = dasd_getgeo,
3300 /*******************************************************************************
3301 * end of block device operations
3307 #ifdef CONFIG_PROC_FS
3311 if (dasd_page_cache != NULL) {
3312 kmem_cache_destroy(dasd_page_cache);
3313 dasd_page_cache = NULL;
3315 dasd_gendisk_exit();
3317 if (dasd_debug_area != NULL) {
3318 debug_unregister(dasd_debug_area);
3319 dasd_debug_area = NULL;
3321 dasd_statistics_removeroot();
3325 * SECTION: common functions for ccw_driver use
3329 * Is the device read-only?
3330 * Note that this function does not report the setting of the
3331 * readonly device attribute, but how it is configured in z/VM.
3333 int dasd_device_is_ro(struct dasd_device *device)
3335 struct ccw_dev_id dev_id;
3336 struct diag210 diag_data;
3341 ccw_device_get_id(device->cdev, &dev_id);
3342 memset(&diag_data, 0, sizeof(diag_data));
3343 diag_data.vrdcdvno = dev_id.devno;
3344 diag_data.vrdclen = sizeof(diag_data);
3345 rc = diag210(&diag_data);
3346 if (rc == 0 || rc == 2) {
3347 return diag_data.vrdcvfla & 0x80;
3349 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3354 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3356 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3358 struct ccw_device *cdev = data;
3361 ret = ccw_device_set_online(cdev);
3363 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3364 dev_name(&cdev->dev), ret);
3368 * Initial attempt at a probe function. this can be simplified once
3369 * the other detection code is gone.
3371 int dasd_generic_probe(struct ccw_device *cdev,
3372 struct dasd_discipline *discipline)
3376 ret = dasd_add_sysfs_files(cdev);
3378 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
3379 "dasd_generic_probe: could not add "
3383 cdev->handler = &dasd_int_handler;
3386 * Automatically online either all dasd devices (dasd_autodetect)
3387 * or all devices specified with dasd= parameters during
3390 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
3391 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
3392 async_schedule(dasd_generic_auto_online, cdev);
3395 EXPORT_SYMBOL_GPL(dasd_generic_probe);
3397 void dasd_generic_free_discipline(struct dasd_device *device)
3399 /* Forget the discipline information. */
3400 if (device->discipline) {
3401 if (device->discipline->uncheck_device)
3402 device->discipline->uncheck_device(device);
3403 module_put(device->discipline->owner);
3404 device->discipline = NULL;
3406 if (device->base_discipline) {
3407 module_put(device->base_discipline->owner);
3408 device->base_discipline = NULL;
3411 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3414 * This will one day be called from a global not_oper handler.
3415 * It is also used by driver_unregister during module unload.
3417 void dasd_generic_remove(struct ccw_device *cdev)
3419 struct dasd_device *device;
3420 struct dasd_block *block;
3422 cdev->handler = NULL;
3424 device = dasd_device_from_cdev(cdev);
3425 if (IS_ERR(device)) {
3426 dasd_remove_sysfs_files(cdev);
3429 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3430 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3431 /* Already doing offline processing */
3432 dasd_put_device(device);
3433 dasd_remove_sysfs_files(cdev);
3437 * This device is removed unconditionally. Set offline
3438 * flag to prevent dasd_open from opening it while it is
3439 * no quite down yet.
3441 dasd_set_target_state(device, DASD_STATE_NEW);
3442 /* dasd_delete_device destroys the device reference. */
3443 block = device->block;
3444 dasd_delete_device(device);
3446 * life cycle of block is bound to device, so delete it after
3447 * device was safely removed
3450 dasd_free_block(block);
3452 dasd_remove_sysfs_files(cdev);
3454 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3457 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3458 * the device is detected for the first time and is supposed to be used
3459 * or the user has started activation through sysfs.
3461 int dasd_generic_set_online(struct ccw_device *cdev,
3462 struct dasd_discipline *base_discipline)
3464 struct dasd_discipline *discipline;
3465 struct dasd_device *device;
3468 /* first online clears initial online feature flag */
3469 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3470 device = dasd_create_device(cdev);
3472 return PTR_ERR(device);
3474 discipline = base_discipline;
3475 if (device->features & DASD_FEATURE_USEDIAG) {
3476 if (!dasd_diag_discipline_pointer) {
3477 /* Try to load the required module. */
3478 rc = request_module(DASD_DIAG_MOD);
3480 pr_warn("%s Setting the DASD online failed "
3481 "because the required module %s "
3482 "could not be loaded (rc=%d)\n",
3483 dev_name(&cdev->dev), DASD_DIAG_MOD,
3485 dasd_delete_device(device);
3489 /* Module init could have failed, so check again here after
3490 * request_module(). */
3491 if (!dasd_diag_discipline_pointer) {
3492 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3493 dev_name(&cdev->dev));
3494 dasd_delete_device(device);
3497 discipline = dasd_diag_discipline_pointer;
3499 if (!try_module_get(base_discipline->owner)) {
3500 dasd_delete_device(device);
3503 if (!try_module_get(discipline->owner)) {
3504 module_put(base_discipline->owner);
3505 dasd_delete_device(device);
3508 device->base_discipline = base_discipline;
3509 device->discipline = discipline;
3511 /* check_device will allocate block device if necessary */
3512 rc = discipline->check_device(device);
3514 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3515 dev_name(&cdev->dev), discipline->name, rc);
3516 module_put(discipline->owner);
3517 module_put(base_discipline->owner);
3518 dasd_delete_device(device);
3522 dasd_set_target_state(device, DASD_STATE_ONLINE);
3523 if (device->state <= DASD_STATE_KNOWN) {
3524 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3525 dev_name(&cdev->dev));
3527 dasd_set_target_state(device, DASD_STATE_NEW);
3529 dasd_free_block(device->block);
3530 dasd_delete_device(device);
3532 pr_debug("dasd_generic device %s found\n",
3533 dev_name(&cdev->dev));
3535 wait_event(dasd_init_waitq, _wait_for_device(device));
3537 dasd_put_device(device);
3540 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3542 int dasd_generic_set_offline(struct ccw_device *cdev)
3544 struct dasd_device *device;
3545 struct dasd_block *block;
3546 int max_count, open_count, rc;
3547 unsigned long flags;
3550 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3551 device = dasd_device_from_cdev_locked(cdev);
3552 if (IS_ERR(device)) {
3553 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3554 return PTR_ERR(device);
3558 * We must make sure that this device is currently not in use.
3559 * The open_count is increased for every opener, that includes
3560 * the blkdev_get in dasd_scan_partitions. We are only interested
3561 * in the other openers.
3563 if (device->block) {
3564 max_count = device->block->bdev ? 0 : -1;
3565 open_count = atomic_read(&device->block->open_count);
3566 if (open_count > max_count) {
3568 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3569 dev_name(&cdev->dev), open_count);
3571 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3572 dev_name(&cdev->dev));
3579 * Test if the offline processing is already running and exit if so.
3580 * If a safe offline is being processed this could only be a normal
3581 * offline that should be able to overtake the safe offline and
3582 * cancel any I/O we do not want to wait for any longer
3584 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3585 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3586 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3593 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3596 * if safe_offline is called set safe_offline_running flag and
3597 * clear safe_offline so that a call to normal offline
3598 * can overrun safe_offline processing
3600 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3601 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3602 /* need to unlock here to wait for outstanding I/O */
3603 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3605 * If we want to set the device safe offline all IO operations
3606 * should be finished before continuing the offline process
3607 * so sync bdev first and then wait for our queues to become
3610 if (device->block) {
3611 rc = fsync_bdev(device->block->bdev);
3615 dasd_schedule_device_bh(device);
3616 rc = wait_event_interruptible(shutdown_waitq,
3617 _wait_for_empty_queues(device));
3622 * check if a normal offline process overtook the offline
3623 * processing in this case simply do nothing beside returning
3624 * that we got interrupted
3625 * otherwise mark safe offline as not running any longer and
3626 * continue with normal offline
3628 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3629 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3633 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3635 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3637 dasd_set_target_state(device, DASD_STATE_NEW);
3638 /* dasd_delete_device destroys the device reference. */
3639 block = device->block;
3640 dasd_delete_device(device);
3642 * life cycle of block is bound to device, so delete it after
3643 * device was safely removed
3646 dasd_free_block(block);
3651 /* interrupted by signal */
3652 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3653 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3654 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3656 dasd_put_device(device);
3657 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3660 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3662 int dasd_generic_last_path_gone(struct dasd_device *device)
3664 struct dasd_ccw_req *cqr;
3666 dev_warn(&device->cdev->dev, "No operational channel path is left "
3667 "for the device\n");
3668 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3669 /* First of all call extended error reporting. */
3670 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3672 if (device->state < DASD_STATE_BASIC)
3674 /* Device is active. We want to keep it. */
3675 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3676 if ((cqr->status == DASD_CQR_IN_IO) ||
3677 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3678 cqr->status = DASD_CQR_QUEUED;
3681 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3682 dasd_device_clear_timer(device);
3683 dasd_schedule_device_bh(device);
3686 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3688 int dasd_generic_path_operational(struct dasd_device *device)
3690 dev_info(&device->cdev->dev, "A channel path to the device has become "
3692 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3693 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3694 if (device->stopped & DASD_UNRESUMED_PM) {
3695 dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
3696 dasd_restore_device(device);
3699 dasd_schedule_device_bh(device);
3700 if (device->block) {
3701 dasd_schedule_block_bh(device->block);
3702 if (device->block->request_queue)
3703 blk_mq_run_hw_queues(device->block->request_queue,
3707 if (!device->stopped)
3708 wake_up(&generic_waitq);
3712 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3714 int dasd_generic_notify(struct ccw_device *cdev, int event)
3716 struct dasd_device *device;
3719 device = dasd_device_from_cdev_locked(cdev);
3727 dasd_path_no_path(device);
3728 ret = dasd_generic_last_path_gone(device);
3732 if (dasd_path_get_opm(device))
3733 ret = dasd_generic_path_operational(device);
3736 dasd_put_device(device);
3739 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3741 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3743 struct dasd_device *device;
3744 int chp, oldopm, hpfpm, ifccpm;
3746 device = dasd_device_from_cdev_locked(cdev);
3750 oldopm = dasd_path_get_opm(device);
3751 for (chp = 0; chp < 8; chp++) {
3752 if (path_event[chp] & PE_PATH_GONE) {
3753 dasd_path_notoper(device, chp);
3755 if (path_event[chp] & PE_PATH_AVAILABLE) {
3756 dasd_path_available(device, chp);
3757 dasd_schedule_device_bh(device);
3759 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3760 if (!dasd_path_is_operational(device, chp) &&
3761 !dasd_path_need_verify(device, chp)) {
3763 * we can not establish a pathgroup on an
3764 * unavailable path, so trigger a path
3765 * verification first
3767 dasd_path_available(device, chp);
3768 dasd_schedule_device_bh(device);
3770 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3771 "Pathgroup re-established\n");
3772 if (device->discipline->kick_validate)
3773 device->discipline->kick_validate(device);
3776 hpfpm = dasd_path_get_hpfpm(device);
3777 ifccpm = dasd_path_get_ifccpm(device);
3778 if (!dasd_path_get_opm(device) && hpfpm) {
3780 * device has no operational paths but at least one path is
3781 * disabled due to HPF errors
3782 * disable HPF at all and use the path(s) again
3784 if (device->discipline->disable_hpf)
3785 device->discipline->disable_hpf(device);
3786 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3787 dasd_path_set_tbvpm(device, hpfpm);
3788 dasd_schedule_device_bh(device);
3789 dasd_schedule_requeue(device);
3790 } else if (!dasd_path_get_opm(device) && ifccpm) {
3792 * device has no operational paths but at least one path is
3793 * disabled due to IFCC errors
3794 * trigger path verification on paths with IFCC errors
3796 dasd_path_set_tbvpm(device, ifccpm);
3797 dasd_schedule_device_bh(device);
3799 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3800 dev_warn(&device->cdev->dev,
3801 "No verified channel paths remain for the device\n");
3802 DBF_DEV_EVENT(DBF_WARNING, device,
3803 "%s", "last verified path gone");
3804 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3805 dasd_device_set_stop_bits(device,
3806 DASD_STOPPED_DC_WAIT);
3808 dasd_put_device(device);
3810 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3812 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3814 if (!dasd_path_get_opm(device) && lpm) {
3815 dasd_path_set_opm(device, lpm);
3816 dasd_generic_path_operational(device);
3818 dasd_path_add_opm(device, lpm);
3821 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3824 * clear active requests and requeue them to block layer if possible
3826 static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3828 struct list_head requeue_queue;
3829 struct dasd_ccw_req *cqr, *n;
3830 struct dasd_ccw_req *refers;
3833 INIT_LIST_HEAD(&requeue_queue);
3834 spin_lock_irq(get_ccwdev_lock(device->cdev));
3836 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3837 /* Check status and move request to flush_queue */
3838 if (cqr->status == DASD_CQR_IN_IO) {
3839 rc = device->discipline->term_IO(cqr);
3841 /* unable to terminate requeust */
3842 dev_err(&device->cdev->dev,
3843 "Unable to terminate request %p "
3844 "on suspend\n", cqr);
3845 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3846 dasd_put_device(device);
3850 list_move_tail(&cqr->devlist, &requeue_queue);
3852 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3854 list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) {
3855 wait_event(dasd_flush_wq,
3856 (cqr->status != DASD_CQR_CLEAR_PENDING));
3859 * requeue requests to blocklayer will only work
3860 * for block device requests
3862 if (_dasd_requeue_request(cqr))
3865 /* remove requests from device and block queue */
3866 list_del_init(&cqr->devlist);
3867 while (cqr->refers != NULL) {
3868 refers = cqr->refers;
3869 /* remove the request from the block queue */
3870 list_del(&cqr->blocklist);
3871 /* free the finished erp request */
3872 dasd_free_erp_request(cqr, cqr->memdev);
3877 * _dasd_requeue_request already checked for a valid
3878 * blockdevice, no need to check again
3879 * all erp requests (cqr->refers) have a cqr->block
3880 * pointer copy from the original cqr
3882 list_del_init(&cqr->blocklist);
3883 cqr->block->base->discipline->free_cp(
3884 cqr, (struct request *) cqr->callback_data);
3888 * if requests remain then they are internal request
3889 * and go back to the device queue
3891 if (!list_empty(&requeue_queue)) {
3892 /* move freeze_queue to start of the ccw_queue */
3893 spin_lock_irq(get_ccwdev_lock(device->cdev));
3894 list_splice_tail(&requeue_queue, &device->ccw_queue);
3895 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3897 dasd_schedule_device_bh(device);
3901 static void do_requeue_requests(struct work_struct *work)
3903 struct dasd_device *device = container_of(work, struct dasd_device,
3905 dasd_generic_requeue_all_requests(device);
3906 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3908 dasd_schedule_block_bh(device->block);
3909 dasd_put_device(device);
3912 void dasd_schedule_requeue(struct dasd_device *device)
3914 dasd_get_device(device);
3915 /* queue call to dasd_reload_device to the kernel event daemon. */
3916 if (!schedule_work(&device->requeue_requests))
3917 dasd_put_device(device);
3919 EXPORT_SYMBOL(dasd_schedule_requeue);
3921 int dasd_generic_pm_freeze(struct ccw_device *cdev)
3923 struct dasd_device *device = dasd_device_from_cdev(cdev);
3926 return PTR_ERR(device);
3928 /* mark device as suspended */
3929 set_bit(DASD_FLAG_SUSPENDED, &device->flags);
3931 if (device->discipline->freeze)
3932 device->discipline->freeze(device);
3934 /* disallow new I/O */
3935 dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
3937 return dasd_generic_requeue_all_requests(device);
3939 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
3941 int dasd_generic_restore_device(struct ccw_device *cdev)
3943 struct dasd_device *device = dasd_device_from_cdev(cdev);
3947 return PTR_ERR(device);
3949 /* allow new IO again */
3950 dasd_device_remove_stop_bits(device,
3951 (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
3953 dasd_schedule_device_bh(device);
3956 * call discipline restore function
3957 * if device is stopped do nothing e.g. for disconnected devices
3959 if (device->discipline->restore && !(device->stopped))
3960 rc = device->discipline->restore(device);
3961 if (rc || device->stopped)
3963 * if the resume failed for the DASD we put it in
3964 * an UNRESUMED stop state
3966 device->stopped |= DASD_UNRESUMED_PM;
3968 if (device->block) {
3969 dasd_schedule_block_bh(device->block);
3970 if (device->block->request_queue)
3971 blk_mq_run_hw_queues(device->block->request_queue,
3975 clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
3976 dasd_put_device(device);
3979 EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
3981 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
3983 int rdc_buffer_size,
3986 struct dasd_ccw_req *cqr;
3988 unsigned long *idaw;
3990 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device,
3994 /* internal error 13 - Allocating the RDC request failed*/
3995 dev_err(&device->cdev->dev,
3996 "An error occurred in the DASD device driver, "
3997 "reason=%s\n", "13");
4002 ccw->cmd_code = CCW_CMD_RDC;
4003 if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
4004 idaw = (unsigned long *) (cqr->data);
4005 ccw->cda = (__u32)(addr_t) idaw;
4006 ccw->flags = CCW_FLAG_IDA;
4007 idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
4009 ccw->cda = (__u32)(addr_t) rdc_buffer;
4013 ccw->count = rdc_buffer_size;
4014 cqr->startdev = device;
4015 cqr->memdev = device;
4016 cqr->expires = 10*HZ;
4018 cqr->buildclk = get_tod_clock();
4019 cqr->status = DASD_CQR_FILLED;
4024 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4025 void *rdc_buffer, int rdc_buffer_size)
4028 struct dasd_ccw_req *cqr;
4030 cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
4033 return PTR_ERR(cqr);
4035 ret = dasd_sleep_on(cqr);
4036 dasd_sfree_request(cqr, cqr->memdev);
4039 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
4042 * In command mode and transport mode we need to look for sense
4043 * data in different places. The sense data itself is allways
4044 * an array of 32 bytes, so we can unify the sense data access
4047 char *dasd_get_sense(struct irb *irb)
4049 struct tsb *tsb = NULL;
4052 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4053 if (irb->scsw.tm.tcw)
4054 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
4056 if (tsb && tsb->length == 64 && tsb->flags)
4057 switch (tsb->flags & 0x07) {
4058 case 1: /* tsa_iostat */
4059 sense = tsb->tsa.iostat.sense;
4061 case 2: /* tsa_ddpc */
4062 sense = tsb->tsa.ddpc.sense;
4065 /* currently we don't use interrogate data */
4068 } else if (irb->esw.esw0.erw.cons) {
4073 EXPORT_SYMBOL_GPL(dasd_get_sense);
4075 void dasd_generic_shutdown(struct ccw_device *cdev)
4077 struct dasd_device *device;
4079 device = dasd_device_from_cdev(cdev);
4084 dasd_schedule_block_bh(device->block);
4086 dasd_schedule_device_bh(device);
4088 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4090 EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4092 static int __init dasd_init(void)
4096 init_waitqueue_head(&dasd_init_waitq);
4097 init_waitqueue_head(&dasd_flush_wq);
4098 init_waitqueue_head(&generic_waitq);
4099 init_waitqueue_head(&shutdown_waitq);
4101 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4102 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
4103 if (dasd_debug_area == NULL) {
4107 debug_register_view(dasd_debug_area, &debug_sprintf_view);
4108 debug_set_level(dasd_debug_area, DBF_WARNING);
4110 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4112 dasd_diag_discipline_pointer = NULL;
4114 dasd_statistics_createroot();
4116 rc = dasd_devmap_init();
4119 rc = dasd_gendisk_init();
4125 rc = dasd_eer_init();
4128 #ifdef CONFIG_PROC_FS
4129 rc = dasd_proc_init();
4136 pr_info("The DASD device driver could not be initialized\n");
4141 module_init(dasd_init);
4142 module_exit(dasd_exit);