2 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * Copyright IBM Corp. 1999, 2009
10 #define KMSG_COMPONENT "dasd"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/kmod.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <linux/ctype.h>
17 #include <linux/major.h>
18 #include <linux/slab.h>
19 #include <linux/hdreg.h>
20 #include <linux/async.h>
21 #include <linux/mutex.h>
22 #include <linux/debugfs.h>
23 #include <linux/seq_file.h>
24 #include <linux/vmalloc.h>
26 #include <asm/ccwdev.h>
27 #include <asm/ebcdic.h>
28 #include <asm/idals.h>
33 #define PRINTK_HEADER "dasd:"
37 * SECTION: Constant definitions to be used within this file
39 #define DASD_CHANQ_MAX_SIZE 4
41 #define DASD_DIAG_MOD "dasd_diag_mod"
44 * SECTION: exported variables of dasd.c
46 debug_info_t *dasd_debug_area;
47 EXPORT_SYMBOL(dasd_debug_area);
48 static struct dentry *dasd_debugfs_root_entry;
49 struct dasd_discipline *dasd_diag_discipline_pointer;
50 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
51 void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
53 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
54 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
55 " Copyright IBM Corp. 2000");
56 MODULE_SUPPORTED_DEVICE("dasd");
57 MODULE_LICENSE("GPL");
60 * SECTION: prototypes for static functions of dasd.c
62 static int dasd_alloc_queue(struct dasd_block *);
63 static void dasd_setup_queue(struct dasd_block *);
64 static void dasd_free_queue(struct dasd_block *);
65 static int dasd_flush_block_queue(struct dasd_block *);
66 static void dasd_device_tasklet(struct dasd_device *);
67 static void dasd_block_tasklet(struct dasd_block *);
68 static void do_kick_device(struct work_struct *);
69 static void do_restore_device(struct work_struct *);
70 static void do_reload_device(struct work_struct *);
71 static void do_requeue_requests(struct work_struct *);
72 static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
73 static void dasd_device_timeout(unsigned long);
74 static void dasd_block_timeout(unsigned long);
75 static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
76 static void dasd_profile_init(struct dasd_profile *, struct dentry *);
77 static void dasd_profile_exit(struct dasd_profile *);
78 static void dasd_hosts_init(struct dentry *, struct dasd_device *);
79 static void dasd_hosts_exit(struct dasd_device *);
82 * SECTION: Operations on the device structure.
84 static wait_queue_head_t dasd_init_waitq;
85 static wait_queue_head_t dasd_flush_wq;
86 static wait_queue_head_t generic_waitq;
87 static wait_queue_head_t shutdown_waitq;
90 * Allocate memory for a new device structure.
92 struct dasd_device *dasd_alloc_device(void)
94 struct dasd_device *device;
96 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
98 return ERR_PTR(-ENOMEM);
100 /* Get two pages for normal block device operations. */
101 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
102 if (!device->ccw_mem) {
104 return ERR_PTR(-ENOMEM);
106 /* Get one page for error recovery. */
107 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
108 if (!device->erp_mem) {
109 free_pages((unsigned long) device->ccw_mem, 1);
111 return ERR_PTR(-ENOMEM);
114 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
115 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
116 spin_lock_init(&device->mem_lock);
117 atomic_set(&device->tasklet_scheduled, 0);
118 tasklet_init(&device->tasklet,
119 (void (*)(unsigned long)) dasd_device_tasklet,
120 (unsigned long) device);
121 INIT_LIST_HEAD(&device->ccw_queue);
122 init_timer(&device->timer);
123 device->timer.function = dasd_device_timeout;
124 device->timer.data = (unsigned long) device;
125 INIT_WORK(&device->kick_work, do_kick_device);
126 INIT_WORK(&device->restore_device, do_restore_device);
127 INIT_WORK(&device->reload_device, do_reload_device);
128 INIT_WORK(&device->requeue_requests, do_requeue_requests);
129 device->state = DASD_STATE_NEW;
130 device->target = DASD_STATE_NEW;
131 mutex_init(&device->state_mutex);
132 spin_lock_init(&device->profile.lock);
137 * Free memory of a device structure.
139 void dasd_free_device(struct dasd_device *device)
141 kfree(device->private);
142 free_page((unsigned long) device->erp_mem);
143 free_pages((unsigned long) device->ccw_mem, 1);
148 * Allocate memory for a new device structure.
150 struct dasd_block *dasd_alloc_block(void)
152 struct dasd_block *block;
154 block = kzalloc(sizeof(*block), GFP_ATOMIC);
156 return ERR_PTR(-ENOMEM);
157 /* open_count = 0 means device online but not in use */
158 atomic_set(&block->open_count, -1);
160 atomic_set(&block->tasklet_scheduled, 0);
161 tasklet_init(&block->tasklet,
162 (void (*)(unsigned long)) dasd_block_tasklet,
163 (unsigned long) block);
164 INIT_LIST_HEAD(&block->ccw_queue);
165 spin_lock_init(&block->queue_lock);
166 init_timer(&block->timer);
167 block->timer.function = dasd_block_timeout;
168 block->timer.data = (unsigned long) block;
169 spin_lock_init(&block->profile.lock);
173 EXPORT_SYMBOL_GPL(dasd_alloc_block);
176 * Free memory of a device structure.
178 void dasd_free_block(struct dasd_block *block)
182 EXPORT_SYMBOL_GPL(dasd_free_block);
185 * Make a new device known to the system.
187 static int dasd_state_new_to_known(struct dasd_device *device)
192 * As long as the device is not in state DASD_STATE_NEW we want to
193 * keep the reference count > 0.
195 dasd_get_device(device);
198 rc = dasd_alloc_queue(device->block);
200 dasd_put_device(device);
204 device->state = DASD_STATE_KNOWN;
209 * Let the system forget about a device.
211 static int dasd_state_known_to_new(struct dasd_device *device)
213 /* Disable extended error reporting for this device. */
214 dasd_eer_disable(device);
215 device->state = DASD_STATE_NEW;
218 dasd_free_queue(device->block);
220 /* Give up reference we took in dasd_state_new_to_known. */
221 dasd_put_device(device);
225 static struct dentry *dasd_debugfs_setup(const char *name,
226 struct dentry *base_dentry)
232 pde = debugfs_create_dir(name, base_dentry);
233 if (!pde || IS_ERR(pde))
239 * Request the irq line for the device.
241 static int dasd_state_known_to_basic(struct dasd_device *device)
243 struct dasd_block *block = device->block;
246 /* Allocate and register gendisk structure. */
248 rc = dasd_gendisk_alloc(block);
251 block->debugfs_dentry =
252 dasd_debugfs_setup(block->gdp->disk_name,
253 dasd_debugfs_root_entry);
254 dasd_profile_init(&block->profile, block->debugfs_dentry);
255 if (dasd_global_profile_level == DASD_PROFILE_ON)
256 dasd_profile_on(&device->block->profile);
258 device->debugfs_dentry =
259 dasd_debugfs_setup(dev_name(&device->cdev->dev),
260 dasd_debugfs_root_entry);
261 dasd_profile_init(&device->profile, device->debugfs_dentry);
262 dasd_hosts_init(device->debugfs_dentry, device);
264 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
265 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
267 debug_register_view(device->debug_area, &debug_sprintf_view);
268 debug_set_level(device->debug_area, DBF_WARNING);
269 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
271 device->state = DASD_STATE_BASIC;
277 * Release the irq line for the device. Terminate any running i/o.
279 static int dasd_state_basic_to_known(struct dasd_device *device)
283 if (device->discipline->basic_to_known) {
284 rc = device->discipline->basic_to_known(device);
290 dasd_profile_exit(&device->block->profile);
291 debugfs_remove(device->block->debugfs_dentry);
292 dasd_gendisk_free(device->block);
293 dasd_block_clear_timer(device->block);
295 rc = dasd_flush_device_queue(device);
298 dasd_device_clear_timer(device);
299 dasd_profile_exit(&device->profile);
300 dasd_hosts_exit(device);
301 debugfs_remove(device->debugfs_dentry);
302 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
303 if (device->debug_area != NULL) {
304 debug_unregister(device->debug_area);
305 device->debug_area = NULL;
307 device->state = DASD_STATE_KNOWN;
312 * Do the initial analysis. The do_analysis function may return
313 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
314 * until the discipline decides to continue the startup sequence
315 * by calling the function dasd_change_state. The eckd disciplines
316 * uses this to start a ccw that detects the format. The completion
317 * interrupt for this detection ccw uses the kernel event daemon to
318 * trigger the call to dasd_change_state. All this is done in the
319 * discipline code, see dasd_eckd.c.
320 * After the analysis ccw is done (do_analysis returned 0) the block
322 * In case the analysis returns an error, the device setup is stopped
323 * (a fake disk was already added to allow formatting).
325 static int dasd_state_basic_to_ready(struct dasd_device *device)
328 struct dasd_block *block;
329 struct gendisk *disk;
332 block = device->block;
333 /* make disk known with correct capacity */
335 if (block->base->discipline->do_analysis != NULL)
336 rc = block->base->discipline->do_analysis(block);
339 device->state = DASD_STATE_UNFMT;
340 disk = device->block->gdp;
341 kobject_uevent(&disk_to_dev(disk)->kobj,
347 dasd_setup_queue(block);
348 set_capacity(block->gdp,
349 block->blocks << block->s2b_shift);
350 device->state = DASD_STATE_READY;
351 rc = dasd_scan_partitions(block);
353 device->state = DASD_STATE_BASIC;
357 device->state = DASD_STATE_READY;
360 if (device->discipline->basic_to_ready)
361 rc = device->discipline->basic_to_ready(device);
366 int _wait_for_empty_queues(struct dasd_device *device)
369 return list_empty(&device->ccw_queue) &&
370 list_empty(&device->block->ccw_queue);
372 return list_empty(&device->ccw_queue);
376 * Remove device from block device layer. Destroy dirty buffers.
377 * Forget format information. Check if the target level is basic
378 * and if it is create fake disk for formatting.
380 static int dasd_state_ready_to_basic(struct dasd_device *device)
384 device->state = DASD_STATE_BASIC;
386 struct dasd_block *block = device->block;
387 rc = dasd_flush_block_queue(block);
389 device->state = DASD_STATE_READY;
392 dasd_destroy_partitions(block);
395 block->s2b_shift = 0;
403 static int dasd_state_unfmt_to_basic(struct dasd_device *device)
405 device->state = DASD_STATE_BASIC;
410 * Make the device online and schedule the bottom half to start
411 * the requeueing of requests from the linux request queue to the
415 dasd_state_ready_to_online(struct dasd_device * device)
417 struct gendisk *disk;
418 struct disk_part_iter piter;
419 struct hd_struct *part;
421 device->state = DASD_STATE_ONLINE;
423 dasd_schedule_block_bh(device->block);
424 if ((device->features & DASD_FEATURE_USERAW)) {
425 disk = device->block->gdp;
426 kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
429 disk = device->block->bdev->bd_disk;
430 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
431 while ((part = disk_part_iter_next(&piter)))
432 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
433 disk_part_iter_exit(&piter);
439 * Stop the requeueing of requests again.
441 static int dasd_state_online_to_ready(struct dasd_device *device)
444 struct gendisk *disk;
445 struct disk_part_iter piter;
446 struct hd_struct *part;
448 if (device->discipline->online_to_ready) {
449 rc = device->discipline->online_to_ready(device);
454 device->state = DASD_STATE_READY;
455 if (device->block && !(device->features & DASD_FEATURE_USERAW)) {
456 disk = device->block->bdev->bd_disk;
457 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
458 while ((part = disk_part_iter_next(&piter)))
459 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
460 disk_part_iter_exit(&piter);
466 * Device startup state changes.
468 static int dasd_increase_state(struct dasd_device *device)
473 if (device->state == DASD_STATE_NEW &&
474 device->target >= DASD_STATE_KNOWN)
475 rc = dasd_state_new_to_known(device);
478 device->state == DASD_STATE_KNOWN &&
479 device->target >= DASD_STATE_BASIC)
480 rc = dasd_state_known_to_basic(device);
483 device->state == DASD_STATE_BASIC &&
484 device->target >= DASD_STATE_READY)
485 rc = dasd_state_basic_to_ready(device);
488 device->state == DASD_STATE_UNFMT &&
489 device->target > DASD_STATE_UNFMT)
493 device->state == DASD_STATE_READY &&
494 device->target >= DASD_STATE_ONLINE)
495 rc = dasd_state_ready_to_online(device);
501 * Device shutdown state changes.
503 static int dasd_decrease_state(struct dasd_device *device)
508 if (device->state == DASD_STATE_ONLINE &&
509 device->target <= DASD_STATE_READY)
510 rc = dasd_state_online_to_ready(device);
513 device->state == DASD_STATE_READY &&
514 device->target <= DASD_STATE_BASIC)
515 rc = dasd_state_ready_to_basic(device);
518 device->state == DASD_STATE_UNFMT &&
519 device->target <= DASD_STATE_BASIC)
520 rc = dasd_state_unfmt_to_basic(device);
523 device->state == DASD_STATE_BASIC &&
524 device->target <= DASD_STATE_KNOWN)
525 rc = dasd_state_basic_to_known(device);
528 device->state == DASD_STATE_KNOWN &&
529 device->target <= DASD_STATE_NEW)
530 rc = dasd_state_known_to_new(device);
536 * This is the main startup/shutdown routine.
538 static void dasd_change_state(struct dasd_device *device)
542 if (device->state == device->target)
543 /* Already where we want to go today... */
545 if (device->state < device->target)
546 rc = dasd_increase_state(device);
548 rc = dasd_decrease_state(device);
552 device->target = device->state;
554 /* let user-space know that the device status changed */
555 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
557 if (device->state == device->target)
558 wake_up(&dasd_init_waitq);
562 * Kick starter for devices that did not complete the startup/shutdown
563 * procedure or were sleeping because of a pending state.
564 * dasd_kick_device will schedule a call do do_kick_device to the kernel
567 static void do_kick_device(struct work_struct *work)
569 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
570 mutex_lock(&device->state_mutex);
571 dasd_change_state(device);
572 mutex_unlock(&device->state_mutex);
573 dasd_schedule_device_bh(device);
574 dasd_put_device(device);
577 void dasd_kick_device(struct dasd_device *device)
579 dasd_get_device(device);
580 /* queue call to dasd_kick_device to the kernel event daemon. */
581 if (!schedule_work(&device->kick_work))
582 dasd_put_device(device);
584 EXPORT_SYMBOL(dasd_kick_device);
587 * dasd_reload_device will schedule a call do do_reload_device to the kernel
590 static void do_reload_device(struct work_struct *work)
592 struct dasd_device *device = container_of(work, struct dasd_device,
594 device->discipline->reload(device);
595 dasd_put_device(device);
598 void dasd_reload_device(struct dasd_device *device)
600 dasd_get_device(device);
601 /* queue call to dasd_reload_device to the kernel event daemon. */
602 if (!schedule_work(&device->reload_device))
603 dasd_put_device(device);
605 EXPORT_SYMBOL(dasd_reload_device);
608 * dasd_restore_device will schedule a call do do_restore_device to the kernel
611 static void do_restore_device(struct work_struct *work)
613 struct dasd_device *device = container_of(work, struct dasd_device,
615 device->cdev->drv->restore(device->cdev);
616 dasd_put_device(device);
619 void dasd_restore_device(struct dasd_device *device)
621 dasd_get_device(device);
622 /* queue call to dasd_restore_device to the kernel event daemon. */
623 if (!schedule_work(&device->restore_device))
624 dasd_put_device(device);
628 * Set the target state for a device and starts the state change.
630 void dasd_set_target_state(struct dasd_device *device, int target)
632 dasd_get_device(device);
633 mutex_lock(&device->state_mutex);
634 /* If we are in probeonly mode stop at DASD_STATE_READY. */
635 if (dasd_probeonly && target > DASD_STATE_READY)
636 target = DASD_STATE_READY;
637 if (device->target != target) {
638 if (device->state == target)
639 wake_up(&dasd_init_waitq);
640 device->target = target;
642 if (device->state != device->target)
643 dasd_change_state(device);
644 mutex_unlock(&device->state_mutex);
645 dasd_put_device(device);
647 EXPORT_SYMBOL(dasd_set_target_state);
650 * Enable devices with device numbers in [from..to].
652 static inline int _wait_for_device(struct dasd_device *device)
654 return (device->state == device->target);
657 void dasd_enable_device(struct dasd_device *device)
659 dasd_set_target_state(device, DASD_STATE_ONLINE);
660 if (device->state <= DASD_STATE_KNOWN)
661 /* No discipline for device found. */
662 dasd_set_target_state(device, DASD_STATE_NEW);
663 /* Now wait for the devices to come up. */
664 wait_event(dasd_init_waitq, _wait_for_device(device));
666 dasd_reload_device(device);
667 if (device->discipline->kick_validate)
668 device->discipline->kick_validate(device);
670 EXPORT_SYMBOL(dasd_enable_device);
673 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
676 unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
678 #ifdef CONFIG_DASD_PROFILE
679 struct dasd_profile dasd_global_profile = {
680 .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
682 static struct dentry *dasd_debugfs_global_entry;
685 * Add profiling information for cqr before execution.
687 static void dasd_profile_start(struct dasd_block *block,
688 struct dasd_ccw_req *cqr,
692 unsigned int counter;
693 struct dasd_device *device;
695 /* count the length of the chanq for statistics */
697 if (dasd_global_profile_level || block->profile.data)
698 list_for_each(l, &block->ccw_queue)
702 spin_lock(&dasd_global_profile.lock);
703 if (dasd_global_profile.data) {
704 dasd_global_profile.data->dasd_io_nr_req[counter]++;
705 if (rq_data_dir(req) == READ)
706 dasd_global_profile.data->dasd_read_nr_req[counter]++;
708 spin_unlock(&dasd_global_profile.lock);
710 spin_lock(&block->profile.lock);
711 if (block->profile.data) {
712 block->profile.data->dasd_io_nr_req[counter]++;
713 if (rq_data_dir(req) == READ)
714 block->profile.data->dasd_read_nr_req[counter]++;
716 spin_unlock(&block->profile.lock);
719 * We count the request for the start device, even though it may run on
720 * some other device due to error recovery. This way we make sure that
721 * we count each request only once.
723 device = cqr->startdev;
724 if (device->profile.data) {
725 counter = 1; /* request is not yet queued on the start device */
726 list_for_each(l, &device->ccw_queue)
730 spin_lock(&device->profile.lock);
731 if (device->profile.data) {
732 device->profile.data->dasd_io_nr_req[counter]++;
733 if (rq_data_dir(req) == READ)
734 device->profile.data->dasd_read_nr_req[counter]++;
736 spin_unlock(&device->profile.lock);
740 * Add profiling information for cqr after execution.
743 #define dasd_profile_counter(value, index) \
745 for (index = 0; index < 31 && value >> (2+index); index++) \
749 static void dasd_profile_end_add_data(struct dasd_profile_info *data,
762 /* in case of an overflow, reset the whole profile */
763 if (data->dasd_io_reqs == UINT_MAX) {
764 memset(data, 0, sizeof(*data));
765 getnstimeofday(&data->starttod);
767 data->dasd_io_reqs++;
768 data->dasd_io_sects += sectors;
770 data->dasd_io_alias++;
774 data->dasd_io_secs[sectors_ind]++;
775 data->dasd_io_times[tottime_ind]++;
776 data->dasd_io_timps[tottimeps_ind]++;
777 data->dasd_io_time1[strtime_ind]++;
778 data->dasd_io_time2[irqtime_ind]++;
779 data->dasd_io_time2ps[irqtimeps_ind]++;
780 data->dasd_io_time3[endtime_ind]++;
783 data->dasd_read_reqs++;
784 data->dasd_read_sects += sectors;
786 data->dasd_read_alias++;
788 data->dasd_read_tpm++;
789 data->dasd_read_secs[sectors_ind]++;
790 data->dasd_read_times[tottime_ind]++;
791 data->dasd_read_time1[strtime_ind]++;
792 data->dasd_read_time2[irqtime_ind]++;
793 data->dasd_read_time3[endtime_ind]++;
797 static void dasd_profile_end(struct dasd_block *block,
798 struct dasd_ccw_req *cqr,
801 unsigned long strtime, irqtime, endtime, tottime;
802 unsigned long tottimeps, sectors;
803 struct dasd_device *device;
804 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
805 int irqtime_ind, irqtimeps_ind, endtime_ind;
806 struct dasd_profile_info *data;
808 device = cqr->startdev;
809 if (!(dasd_global_profile_level ||
810 block->profile.data ||
811 device->profile.data))
814 sectors = blk_rq_sectors(req);
815 if (!cqr->buildclk || !cqr->startclk ||
816 !cqr->stopclk || !cqr->endclk ||
820 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
821 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
822 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
823 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
824 tottimeps = tottime / sectors;
826 dasd_profile_counter(sectors, sectors_ind);
827 dasd_profile_counter(tottime, tottime_ind);
828 dasd_profile_counter(tottimeps, tottimeps_ind);
829 dasd_profile_counter(strtime, strtime_ind);
830 dasd_profile_counter(irqtime, irqtime_ind);
831 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
832 dasd_profile_counter(endtime, endtime_ind);
834 spin_lock(&dasd_global_profile.lock);
835 if (dasd_global_profile.data) {
836 data = dasd_global_profile.data;
837 data->dasd_sum_times += tottime;
838 data->dasd_sum_time_str += strtime;
839 data->dasd_sum_time_irq += irqtime;
840 data->dasd_sum_time_end += endtime;
841 dasd_profile_end_add_data(dasd_global_profile.data,
842 cqr->startdev != block->base,
844 rq_data_dir(req) == READ,
845 sectors, sectors_ind, tottime_ind,
846 tottimeps_ind, strtime_ind,
847 irqtime_ind, irqtimeps_ind,
850 spin_unlock(&dasd_global_profile.lock);
852 spin_lock(&block->profile.lock);
853 if (block->profile.data) {
854 data = block->profile.data;
855 data->dasd_sum_times += tottime;
856 data->dasd_sum_time_str += strtime;
857 data->dasd_sum_time_irq += irqtime;
858 data->dasd_sum_time_end += endtime;
859 dasd_profile_end_add_data(block->profile.data,
860 cqr->startdev != block->base,
862 rq_data_dir(req) == READ,
863 sectors, sectors_ind, tottime_ind,
864 tottimeps_ind, strtime_ind,
865 irqtime_ind, irqtimeps_ind,
868 spin_unlock(&block->profile.lock);
870 spin_lock(&device->profile.lock);
871 if (device->profile.data) {
872 data = device->profile.data;
873 data->dasd_sum_times += tottime;
874 data->dasd_sum_time_str += strtime;
875 data->dasd_sum_time_irq += irqtime;
876 data->dasd_sum_time_end += endtime;
877 dasd_profile_end_add_data(device->profile.data,
878 cqr->startdev != block->base,
880 rq_data_dir(req) == READ,
881 sectors, sectors_ind, tottime_ind,
882 tottimeps_ind, strtime_ind,
883 irqtime_ind, irqtimeps_ind,
886 spin_unlock(&device->profile.lock);
889 void dasd_profile_reset(struct dasd_profile *profile)
891 struct dasd_profile_info *data;
893 spin_lock_bh(&profile->lock);
894 data = profile->data;
896 spin_unlock_bh(&profile->lock);
899 memset(data, 0, sizeof(*data));
900 getnstimeofday(&data->starttod);
901 spin_unlock_bh(&profile->lock);
904 int dasd_profile_on(struct dasd_profile *profile)
906 struct dasd_profile_info *data;
908 data = kzalloc(sizeof(*data), GFP_KERNEL);
911 spin_lock_bh(&profile->lock);
913 spin_unlock_bh(&profile->lock);
917 getnstimeofday(&data->starttod);
918 profile->data = data;
919 spin_unlock_bh(&profile->lock);
923 void dasd_profile_off(struct dasd_profile *profile)
925 spin_lock_bh(&profile->lock);
926 kfree(profile->data);
927 profile->data = NULL;
928 spin_unlock_bh(&profile->lock);
931 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
935 buffer = vmalloc(user_len + 1);
937 return ERR_PTR(-ENOMEM);
938 if (copy_from_user(buffer, user_buf, user_len) != 0) {
940 return ERR_PTR(-EFAULT);
942 /* got the string, now strip linefeed. */
943 if (buffer[user_len - 1] == '\n')
944 buffer[user_len - 1] = 0;
946 buffer[user_len] = 0;
950 static ssize_t dasd_stats_write(struct file *file,
951 const char __user *user_buf,
952 size_t user_len, loff_t *pos)
956 struct seq_file *m = (struct seq_file *)file->private_data;
957 struct dasd_profile *prof = m->private;
959 if (user_len > 65536)
961 buffer = dasd_get_user_string(user_buf, user_len);
963 return PTR_ERR(buffer);
965 str = skip_spaces(buffer);
967 if (strncmp(str, "reset", 5) == 0) {
968 dasd_profile_reset(prof);
969 } else if (strncmp(str, "on", 2) == 0) {
970 rc = dasd_profile_on(prof);
974 if (prof == &dasd_global_profile) {
975 dasd_profile_reset(prof);
976 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
978 } else if (strncmp(str, "off", 3) == 0) {
979 if (prof == &dasd_global_profile)
980 dasd_global_profile_level = DASD_PROFILE_OFF;
981 dasd_profile_off(prof);
989 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
993 for (i = 0; i < 32; i++)
994 seq_printf(m, "%u ", array[i]);
998 static void dasd_stats_seq_print(struct seq_file *m,
999 struct dasd_profile_info *data)
1001 seq_printf(m, "start_time %ld.%09ld\n",
1002 data->starttod.tv_sec, data->starttod.tv_nsec);
1003 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
1004 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
1005 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
1006 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
1007 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
1008 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
1009 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
1010 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
1011 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
1012 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
1013 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
1014 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
1015 seq_puts(m, "histogram_sectors ");
1016 dasd_stats_array(m, data->dasd_io_secs);
1017 seq_puts(m, "histogram_io_times ");
1018 dasd_stats_array(m, data->dasd_io_times);
1019 seq_puts(m, "histogram_io_times_weighted ");
1020 dasd_stats_array(m, data->dasd_io_timps);
1021 seq_puts(m, "histogram_time_build_to_ssch ");
1022 dasd_stats_array(m, data->dasd_io_time1);
1023 seq_puts(m, "histogram_time_ssch_to_irq ");
1024 dasd_stats_array(m, data->dasd_io_time2);
1025 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
1026 dasd_stats_array(m, data->dasd_io_time2ps);
1027 seq_puts(m, "histogram_time_irq_to_end ");
1028 dasd_stats_array(m, data->dasd_io_time3);
1029 seq_puts(m, "histogram_ccw_queue_length ");
1030 dasd_stats_array(m, data->dasd_io_nr_req);
1031 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
1032 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
1033 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
1034 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
1035 seq_puts(m, "histogram_read_sectors ");
1036 dasd_stats_array(m, data->dasd_read_secs);
1037 seq_puts(m, "histogram_read_times ");
1038 dasd_stats_array(m, data->dasd_read_times);
1039 seq_puts(m, "histogram_read_time_build_to_ssch ");
1040 dasd_stats_array(m, data->dasd_read_time1);
1041 seq_puts(m, "histogram_read_time_ssch_to_irq ");
1042 dasd_stats_array(m, data->dasd_read_time2);
1043 seq_puts(m, "histogram_read_time_irq_to_end ");
1044 dasd_stats_array(m, data->dasd_read_time3);
1045 seq_puts(m, "histogram_read_ccw_queue_length ");
1046 dasd_stats_array(m, data->dasd_read_nr_req);
1049 static int dasd_stats_show(struct seq_file *m, void *v)
1051 struct dasd_profile *profile;
1052 struct dasd_profile_info *data;
1054 profile = m->private;
1055 spin_lock_bh(&profile->lock);
1056 data = profile->data;
1058 spin_unlock_bh(&profile->lock);
1059 seq_puts(m, "disabled\n");
1062 dasd_stats_seq_print(m, data);
1063 spin_unlock_bh(&profile->lock);
1067 static int dasd_stats_open(struct inode *inode, struct file *file)
1069 struct dasd_profile *profile = inode->i_private;
1070 return single_open(file, dasd_stats_show, profile);
1073 static const struct file_operations dasd_stats_raw_fops = {
1074 .owner = THIS_MODULE,
1075 .open = dasd_stats_open,
1077 .llseek = seq_lseek,
1078 .release = single_release,
1079 .write = dasd_stats_write,
1082 static void dasd_profile_init(struct dasd_profile *profile,
1083 struct dentry *base_dentry)
1090 profile->dentry = NULL;
1091 profile->data = NULL;
1092 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1093 pde = debugfs_create_file("statistics", mode, base_dentry,
1094 profile, &dasd_stats_raw_fops);
1095 if (pde && !IS_ERR(pde))
1096 profile->dentry = pde;
1100 static void dasd_profile_exit(struct dasd_profile *profile)
1102 dasd_profile_off(profile);
1103 debugfs_remove(profile->dentry);
1104 profile->dentry = NULL;
1107 static void dasd_statistics_removeroot(void)
1109 dasd_global_profile_level = DASD_PROFILE_OFF;
1110 dasd_profile_exit(&dasd_global_profile);
1111 debugfs_remove(dasd_debugfs_global_entry);
1112 debugfs_remove(dasd_debugfs_root_entry);
1115 static void dasd_statistics_createroot(void)
1119 dasd_debugfs_root_entry = NULL;
1120 pde = debugfs_create_dir("dasd", NULL);
1121 if (!pde || IS_ERR(pde))
1123 dasd_debugfs_root_entry = pde;
1124 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1125 if (!pde || IS_ERR(pde))
1127 dasd_debugfs_global_entry = pde;
1128 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
1132 DBF_EVENT(DBF_ERR, "%s",
1133 "Creation of the dasd debugfs interface failed");
1134 dasd_statistics_removeroot();
1139 #define dasd_profile_start(block, cqr, req) do {} while (0)
1140 #define dasd_profile_end(block, cqr, req) do {} while (0)
1142 static void dasd_statistics_createroot(void)
1147 static void dasd_statistics_removeroot(void)
1152 int dasd_stats_generic_show(struct seq_file *m, void *v)
1154 seq_puts(m, "Statistics are not activated in this kernel\n");
1158 static void dasd_profile_init(struct dasd_profile *profile,
1159 struct dentry *base_dentry)
1164 static void dasd_profile_exit(struct dasd_profile *profile)
1169 int dasd_profile_on(struct dasd_profile *profile)
1174 #endif /* CONFIG_DASD_PROFILE */
1176 static int dasd_hosts_show(struct seq_file *m, void *v)
1178 struct dasd_device *device;
1179 int rc = -EOPNOTSUPP;
1181 device = m->private;
1182 dasd_get_device(device);
1184 if (device->discipline->hosts_print)
1185 rc = device->discipline->hosts_print(device, m);
1187 dasd_put_device(device);
1191 static int dasd_hosts_open(struct inode *inode, struct file *file)
1193 struct dasd_device *device = inode->i_private;
1195 return single_open(file, dasd_hosts_show, device);
1198 static const struct file_operations dasd_hosts_fops = {
1199 .owner = THIS_MODULE,
1200 .open = dasd_hosts_open,
1202 .llseek = seq_lseek,
1203 .release = single_release,
1206 static void dasd_hosts_exit(struct dasd_device *device)
1208 debugfs_remove(device->hosts_dentry);
1209 device->hosts_dentry = NULL;
1212 static void dasd_hosts_init(struct dentry *base_dentry,
1213 struct dasd_device *device)
1221 mode = S_IRUSR | S_IFREG;
1222 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1223 device, &dasd_hosts_fops);
1224 if (pde && !IS_ERR(pde))
1225 device->hosts_dentry = pde;
1229 * Allocate memory for a channel program with 'cplength' channel
1230 * command words and 'datasize' additional space. There are two
1231 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1232 * memory and 2) dasd_smalloc_request uses the static ccw memory
1233 * that gets allocated for each device.
1235 struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength,
1237 struct dasd_device *device)
1239 struct dasd_ccw_req *cqr;
1242 BUG_ON(datasize > PAGE_SIZE ||
1243 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
1245 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
1247 return ERR_PTR(-ENOMEM);
1250 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
1251 GFP_ATOMIC | GFP_DMA);
1252 if (cqr->cpaddr == NULL) {
1254 return ERR_PTR(-ENOMEM);
1259 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
1260 if (cqr->data == NULL) {
1263 return ERR_PTR(-ENOMEM);
1267 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1268 dasd_get_device(device);
1271 EXPORT_SYMBOL(dasd_kmalloc_request);
1273 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength,
1275 struct dasd_device *device)
1277 unsigned long flags;
1278 struct dasd_ccw_req *cqr;
1282 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
1284 size += cplength * sizeof(struct ccw1);
1287 spin_lock_irqsave(&device->mem_lock, flags);
1288 cqr = (struct dasd_ccw_req *)
1289 dasd_alloc_chunk(&device->ccw_chunks, size);
1290 spin_unlock_irqrestore(&device->mem_lock, flags);
1292 return ERR_PTR(-ENOMEM);
1293 memset(cqr, 0, sizeof(struct dasd_ccw_req));
1294 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
1297 cqr->cpaddr = (struct ccw1 *) data;
1298 data += cplength*sizeof(struct ccw1);
1299 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
1304 memset(cqr->data, 0, datasize);
1307 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1308 dasd_get_device(device);
1311 EXPORT_SYMBOL(dasd_smalloc_request);
1314 * Free memory of a channel program. This function needs to free all the
1315 * idal lists that might have been created by dasd_set_cda and the
1316 * struct dasd_ccw_req itself.
1318 void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1322 /* Clear any idals used for the request. */
1325 clear_normalized_cda(ccw);
1326 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
1330 dasd_put_device(device);
1332 EXPORT_SYMBOL(dasd_kfree_request);
1334 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1336 unsigned long flags;
1338 spin_lock_irqsave(&device->mem_lock, flags);
1339 dasd_free_chunk(&device->ccw_chunks, cqr);
1340 spin_unlock_irqrestore(&device->mem_lock, flags);
1341 dasd_put_device(device);
1343 EXPORT_SYMBOL(dasd_sfree_request);
1346 * Check discipline magic in cqr.
1348 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1350 struct dasd_device *device;
1354 device = cqr->startdev;
1355 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1356 DBF_DEV_EVENT(DBF_WARNING, device,
1357 " dasd_ccw_req 0x%08x magic doesn't match"
1358 " discipline 0x%08x",
1360 *(unsigned int *) device->discipline->name);
1367 * Terminate the current i/o and set the request to clear_pending.
1368 * Timer keeps device runnig.
1369 * ccw_device_clear can fail if the i/o subsystem
1372 int dasd_term_IO(struct dasd_ccw_req *cqr)
1374 struct dasd_device *device;
1376 char errorstring[ERRORLENGTH];
1379 rc = dasd_check_cqr(cqr);
1383 device = (struct dasd_device *) cqr->startdev;
1384 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1385 rc = ccw_device_clear(device->cdev, (long) cqr);
1387 case 0: /* termination successful */
1388 cqr->status = DASD_CQR_CLEAR_PENDING;
1389 cqr->stopclk = get_tod_clock();
1391 DBF_DEV_EVENT(DBF_DEBUG, device,
1392 "terminate cqr %p successful",
1396 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1397 "device gone, retry");
1400 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1401 "I/O error, retry");
1405 * device not valid so no I/O could be running
1406 * handle CQR as termination successful
1408 cqr->status = DASD_CQR_CLEARED;
1409 cqr->stopclk = get_tod_clock();
1411 /* no retries for invalid devices */
1413 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1414 "EINVAL, handle as terminated");
1415 /* fake rc to success */
1419 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1420 "device busy, retry later");
1423 /* internal error 10 - unknown rc*/
1424 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1425 dev_err(&device->cdev->dev, "An error occurred in the "
1426 "DASD device driver, reason=%s\n", errorstring);
1432 dasd_schedule_device_bh(device);
1435 EXPORT_SYMBOL(dasd_term_IO);
1438 * Start the i/o. This start_IO can fail if the channel is really busy.
1439 * In that case set up a timer to start the request later.
1441 int dasd_start_IO(struct dasd_ccw_req *cqr)
1443 struct dasd_device *device;
1445 char errorstring[ERRORLENGTH];
1448 rc = dasd_check_cqr(cqr);
1453 device = (struct dasd_device *) cqr->startdev;
1455 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1456 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1457 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1458 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1459 "because of stolen lock", cqr);
1460 cqr->status = DASD_CQR_ERROR;
1461 cqr->intrc = -EPERM;
1464 if (cqr->retries < 0) {
1465 /* internal error 14 - start_IO run out of retries */
1466 sprintf(errorstring, "14 %p", cqr);
1467 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1468 "device driver, reason=%s\n", errorstring);
1469 cqr->status = DASD_CQR_ERROR;
1472 cqr->startclk = get_tod_clock();
1473 cqr->starttime = jiffies;
1475 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1476 cqr->lpm &= dasd_path_get_opm(device);
1478 cqr->lpm = dasd_path_get_opm(device);
1480 if (cqr->cpmode == 1) {
1481 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1482 (long) cqr, cqr->lpm);
1484 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1485 (long) cqr, cqr->lpm, 0);
1489 cqr->status = DASD_CQR_IN_IO;
1492 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1493 "start_IO: device busy, retry later");
1496 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1497 "start_IO: request timeout, retry later");
1500 /* -EACCES indicates that the request used only a subset of the
1501 * available paths and all these paths are gone. If the lpm of
1502 * this request was only a subset of the opm (e.g. the ppm) then
1503 * we just do a retry with all available paths.
1504 * If we already use the full opm, something is amiss, and we
1505 * need a full path verification.
1507 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1508 DBF_DEV_EVENT(DBF_WARNING, device,
1509 "start_IO: selected paths gone (%x)",
1511 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1512 cqr->lpm = dasd_path_get_opm(device);
1513 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1514 "start_IO: selected paths gone,"
1515 " retry on all paths");
1517 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1518 "start_IO: all paths in opm gone,"
1519 " do path verification");
1520 dasd_generic_last_path_gone(device);
1521 dasd_path_no_path(device);
1522 dasd_path_set_tbvpm(device,
1523 ccw_device_get_path_mask(
1528 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1529 "start_IO: -ENODEV device gone, retry");
1532 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1533 "start_IO: -EIO device gone, retry");
1536 /* most likely caused in power management context */
1537 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1538 "start_IO: -EINVAL device currently "
1542 /* internal error 11 - unknown rc */
1543 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1544 dev_err(&device->cdev->dev,
1545 "An error occurred in the DASD device driver, "
1546 "reason=%s\n", errorstring);
1553 EXPORT_SYMBOL(dasd_start_IO);
1556 * Timeout function for dasd devices. This is used for different purposes
1557 * 1) missing interrupt handler for normal operation
1558 * 2) delayed start of request where start_IO failed with -EBUSY
1559 * 3) timeout for missing state change interrupts
1560 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1561 * DASD_CQR_QUEUED for 2) and 3).
1563 static void dasd_device_timeout(unsigned long ptr)
1565 unsigned long flags;
1566 struct dasd_device *device;
1568 device = (struct dasd_device *) ptr;
1569 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1570 /* re-activate request queue */
1571 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1572 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1573 dasd_schedule_device_bh(device);
1577 * Setup timeout for a device in jiffies.
1579 void dasd_device_set_timer(struct dasd_device *device, int expires)
1582 del_timer(&device->timer);
1584 mod_timer(&device->timer, jiffies + expires);
1586 EXPORT_SYMBOL(dasd_device_set_timer);
1589 * Clear timeout for a device.
1591 void dasd_device_clear_timer(struct dasd_device *device)
1593 del_timer(&device->timer);
1595 EXPORT_SYMBOL(dasd_device_clear_timer);
1597 static void dasd_handle_killed_request(struct ccw_device *cdev,
1598 unsigned long intparm)
1600 struct dasd_ccw_req *cqr;
1601 struct dasd_device *device;
1605 cqr = (struct dasd_ccw_req *) intparm;
1606 if (cqr->status != DASD_CQR_IN_IO) {
1607 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1608 "invalid status in handle_killed_request: "
1609 "%02x", cqr->status);
1613 device = dasd_device_from_cdev_locked(cdev);
1614 if (IS_ERR(device)) {
1615 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1616 "unable to get device from cdev");
1620 if (!cqr->startdev ||
1621 device != cqr->startdev ||
1622 strncmp(cqr->startdev->discipline->ebcname,
1623 (char *) &cqr->magic, 4)) {
1624 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1625 "invalid device in request");
1626 dasd_put_device(device);
1630 /* Schedule request to be retried. */
1631 cqr->status = DASD_CQR_QUEUED;
1633 dasd_device_clear_timer(device);
1634 dasd_schedule_device_bh(device);
1635 dasd_put_device(device);
1638 void dasd_generic_handle_state_change(struct dasd_device *device)
1640 /* First of all start sense subsystem status request. */
1641 dasd_eer_snss(device);
1643 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1644 dasd_schedule_device_bh(device);
1645 if (device->block) {
1646 dasd_schedule_block_bh(device->block);
1647 if (device->block->request_queue)
1648 blk_mq_run_hw_queues(device->block->request_queue,
1652 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
1654 static int dasd_check_hpf_error(struct irb *irb)
1656 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1657 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1658 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1662 * Interrupt handler for "normal" ssch-io based dasd devices.
1664 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1667 struct dasd_ccw_req *cqr, *next;
1668 struct dasd_device *device;
1670 int nrf_suppressed = 0;
1671 int fp_suppressed = 0;
1675 cqr = (struct dasd_ccw_req *) intparm;
1677 switch (PTR_ERR(irb)) {
1679 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1680 device = cqr->startdev;
1681 cqr->status = DASD_CQR_CLEARED;
1682 dasd_device_clear_timer(device);
1683 wake_up(&dasd_flush_wq);
1684 dasd_schedule_device_bh(device);
1689 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1690 "request timed out\n", __func__);
1693 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1694 "unknown error %ld\n", __func__,
1697 dasd_handle_killed_request(cdev, intparm);
1701 now = get_tod_clock();
1702 /* check for conditions that should be handled immediately */
1704 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1705 scsw_cstat(&irb->scsw) == 0)) {
1707 memcpy(&cqr->irb, irb, sizeof(*irb));
1708 device = dasd_device_from_cdev_locked(cdev);
1711 /* ignore unsolicited interrupts for DIAG discipline */
1712 if (device->discipline == dasd_diag_discipline_pointer) {
1713 dasd_put_device(device);
1718 * In some cases 'File Protected' or 'No Record Found' errors
1719 * might be expected and debug log messages for the
1720 * corresponding interrupts shouldn't be written then.
1721 * Check if either of the according suppress bits is set.
1723 sense = dasd_get_sense(irb);
1725 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1726 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1727 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1728 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1730 if (!(fp_suppressed || nrf_suppressed))
1731 device->discipline->dump_sense_dbf(device, irb, "int");
1733 if (device->features & DASD_FEATURE_ERPLOG)
1734 device->discipline->dump_sense(device, cqr, irb);
1735 device->discipline->check_for_device_change(device, cqr, irb);
1736 dasd_put_device(device);
1739 /* check for for attention message */
1740 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1741 device = dasd_device_from_cdev_locked(cdev);
1742 if (!IS_ERR(device)) {
1743 device->discipline->check_attention(device,
1744 irb->esw.esw1.lpum);
1745 dasd_put_device(device);
1752 device = (struct dasd_device *) cqr->startdev;
1754 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1755 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1756 "invalid device in request");
1760 /* Check for clear pending */
1761 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1762 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1763 cqr->status = DASD_CQR_CLEARED;
1764 dasd_device_clear_timer(device);
1765 wake_up(&dasd_flush_wq);
1766 dasd_schedule_device_bh(device);
1770 /* check status - the request might have been killed by dyn detach */
1771 if (cqr->status != DASD_CQR_IN_IO) {
1772 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1773 "status %02x", dev_name(&cdev->dev), cqr->status);
1779 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1780 scsw_cstat(&irb->scsw) == 0) {
1781 /* request was completed successfully */
1782 cqr->status = DASD_CQR_SUCCESS;
1784 /* Start first request on queue if possible -> fast_io. */
1785 if (cqr->devlist.next != &device->ccw_queue) {
1786 next = list_entry(cqr->devlist.next,
1787 struct dasd_ccw_req, devlist);
1789 } else { /* error */
1790 /* check for HPF error
1791 * call discipline function to requeue all requests
1792 * and disable HPF accordingly
1794 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1795 device->discipline->handle_hpf_error)
1796 device->discipline->handle_hpf_error(device, irb);
1798 * If we don't want complex ERP for this request, then just
1799 * reset this and retry it in the fastpath
1801 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1803 if (cqr->lpm == dasd_path_get_opm(device))
1804 DBF_DEV_EVENT(DBF_DEBUG, device,
1805 "default ERP in fastpath "
1806 "(%i retries left)",
1808 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1809 cqr->lpm = dasd_path_get_opm(device);
1810 cqr->status = DASD_CQR_QUEUED;
1813 cqr->status = DASD_CQR_ERROR;
1815 if (next && (next->status == DASD_CQR_QUEUED) &&
1816 (!device->stopped)) {
1817 if (device->discipline->start_IO(next) == 0)
1818 expires = next->expires;
1821 dasd_device_set_timer(device, expires);
1823 dasd_device_clear_timer(device);
1824 dasd_schedule_device_bh(device);
1826 EXPORT_SYMBOL(dasd_int_handler);
1828 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1830 struct dasd_device *device;
1832 device = dasd_device_from_cdev_locked(cdev);
1836 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1837 device->state != device->target ||
1838 !device->discipline->check_for_device_change){
1839 dasd_put_device(device);
1842 if (device->discipline->dump_sense_dbf)
1843 device->discipline->dump_sense_dbf(device, irb, "uc");
1844 device->discipline->check_for_device_change(device, NULL, irb);
1845 dasd_put_device(device);
1847 return UC_TODO_RETRY;
1849 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1852 * If we have an error on a dasd_block layer request then we cancel
1853 * and return all further requests from the same dasd_block as well.
1855 static void __dasd_device_recovery(struct dasd_device *device,
1856 struct dasd_ccw_req *ref_cqr)
1858 struct list_head *l, *n;
1859 struct dasd_ccw_req *cqr;
1862 * only requeue request that came from the dasd_block layer
1864 if (!ref_cqr->block)
1867 list_for_each_safe(l, n, &device->ccw_queue) {
1868 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1869 if (cqr->status == DASD_CQR_QUEUED &&
1870 ref_cqr->block == cqr->block) {
1871 cqr->status = DASD_CQR_CLEARED;
1877 * Remove those ccw requests from the queue that need to be returned
1878 * to the upper layer.
1880 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1881 struct list_head *final_queue)
1883 struct list_head *l, *n;
1884 struct dasd_ccw_req *cqr;
1886 /* Process request with final status. */
1887 list_for_each_safe(l, n, &device->ccw_queue) {
1888 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1890 /* Skip any non-final request. */
1891 if (cqr->status == DASD_CQR_QUEUED ||
1892 cqr->status == DASD_CQR_IN_IO ||
1893 cqr->status == DASD_CQR_CLEAR_PENDING)
1895 if (cqr->status == DASD_CQR_ERROR) {
1896 __dasd_device_recovery(device, cqr);
1898 /* Rechain finished requests to final queue */
1899 list_move_tail(&cqr->devlist, final_queue);
1904 * the cqrs from the final queue are returned to the upper layer
1905 * by setting a dasd_block state and calling the callback function
1907 static void __dasd_device_process_final_queue(struct dasd_device *device,
1908 struct list_head *final_queue)
1910 struct list_head *l, *n;
1911 struct dasd_ccw_req *cqr;
1912 struct dasd_block *block;
1913 void (*callback)(struct dasd_ccw_req *, void *data);
1914 void *callback_data;
1915 char errorstring[ERRORLENGTH];
1917 list_for_each_safe(l, n, final_queue) {
1918 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1919 list_del_init(&cqr->devlist);
1921 callback = cqr->callback;
1922 callback_data = cqr->callback_data;
1924 spin_lock_bh(&block->queue_lock);
1925 switch (cqr->status) {
1926 case DASD_CQR_SUCCESS:
1927 cqr->status = DASD_CQR_DONE;
1929 case DASD_CQR_ERROR:
1930 cqr->status = DASD_CQR_NEED_ERP;
1932 case DASD_CQR_CLEARED:
1933 cqr->status = DASD_CQR_TERMINATED;
1936 /* internal error 12 - wrong cqr status*/
1937 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1938 dev_err(&device->cdev->dev,
1939 "An error occurred in the DASD device driver, "
1940 "reason=%s\n", errorstring);
1943 if (cqr->callback != NULL)
1944 (callback)(cqr, callback_data);
1946 spin_unlock_bh(&block->queue_lock);
1951 * Take a look at the first request on the ccw queue and check
1952 * if it reached its expire time. If so, terminate the IO.
1954 static void __dasd_device_check_expire(struct dasd_device *device)
1956 struct dasd_ccw_req *cqr;
1958 if (list_empty(&device->ccw_queue))
1960 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1961 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1962 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1963 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1965 * IO in safe offline processing should not
1966 * run out of retries
1970 if (device->discipline->term_IO(cqr) != 0) {
1971 /* Hmpf, try again in 5 sec */
1972 dev_err(&device->cdev->dev,
1973 "cqr %p timed out (%lus) but cannot be "
1974 "ended, retrying in 5 s\n",
1975 cqr, (cqr->expires/HZ));
1976 cqr->expires += 5*HZ;
1977 dasd_device_set_timer(device, 5*HZ);
1979 dev_err(&device->cdev->dev,
1980 "cqr %p timed out (%lus), %i retries "
1981 "remaining\n", cqr, (cqr->expires/HZ),
1988 * return 1 when device is not eligible for IO
1990 static int __dasd_device_is_unusable(struct dasd_device *device,
1991 struct dasd_ccw_req *cqr)
1993 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM);
1995 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
1996 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1998 * dasd is being set offline
1999 * but it is no safe offline where we have to allow I/O
2003 if (device->stopped) {
2004 if (device->stopped & mask) {
2005 /* stopped and CQR will not change that. */
2008 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2009 /* CQR is not able to change device to
2013 /* CQR required to get device operational. */
2019 * Take a look at the first request on the ccw queue and check
2020 * if it needs to be started.
2022 static void __dasd_device_start_head(struct dasd_device *device)
2024 struct dasd_ccw_req *cqr;
2027 if (list_empty(&device->ccw_queue))
2029 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2030 if (cqr->status != DASD_CQR_QUEUED)
2032 /* if device is not usable return request to upper layer */
2033 if (__dasd_device_is_unusable(device, cqr)) {
2034 cqr->intrc = -EAGAIN;
2035 cqr->status = DASD_CQR_CLEARED;
2036 dasd_schedule_device_bh(device);
2040 rc = device->discipline->start_IO(cqr);
2042 dasd_device_set_timer(device, cqr->expires);
2043 else if (rc == -EACCES) {
2044 dasd_schedule_device_bh(device);
2046 /* Hmpf, try again in 1/2 sec */
2047 dasd_device_set_timer(device, 50);
2050 static void __dasd_device_check_path_events(struct dasd_device *device)
2054 if (!dasd_path_get_tbvpm(device))
2057 if (device->stopped &
2058 ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM))
2060 rc = device->discipline->verify_path(device,
2061 dasd_path_get_tbvpm(device));
2063 dasd_device_set_timer(device, 50);
2065 dasd_path_clear_all_verify(device);
2069 * Go through all request on the dasd_device request queue,
2070 * terminate them on the cdev if necessary, and return them to the
2071 * submitting layer via callback.
2073 * Make sure that all 'submitting layers' still exist when
2074 * this function is called!. In other words, when 'device' is a base
2075 * device then all block layer requests must have been removed before
2076 * via dasd_flush_block_queue.
2078 int dasd_flush_device_queue(struct dasd_device *device)
2080 struct dasd_ccw_req *cqr, *n;
2082 struct list_head flush_queue;
2084 INIT_LIST_HEAD(&flush_queue);
2085 spin_lock_irq(get_ccwdev_lock(device->cdev));
2087 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2088 /* Check status and move request to flush_queue */
2089 switch (cqr->status) {
2090 case DASD_CQR_IN_IO:
2091 rc = device->discipline->term_IO(cqr);
2093 /* unable to terminate requeust */
2094 dev_err(&device->cdev->dev,
2095 "Flushing the DASD request queue "
2096 "failed for request %p\n", cqr);
2097 /* stop flush processing */
2101 case DASD_CQR_QUEUED:
2102 cqr->stopclk = get_tod_clock();
2103 cqr->status = DASD_CQR_CLEARED;
2105 default: /* no need to modify the others */
2108 list_move_tail(&cqr->devlist, &flush_queue);
2111 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2113 * After this point all requests must be in state CLEAR_PENDING,
2114 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2115 * one of the others.
2117 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2118 wait_event(dasd_flush_wq,
2119 (cqr->status != DASD_CQR_CLEAR_PENDING));
2121 * Now set each request back to TERMINATED, DONE or NEED_ERP
2122 * and call the callback function of flushed requests
2124 __dasd_device_process_final_queue(device, &flush_queue);
2127 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2130 * Acquire the device lock and process queues for the device.
2132 static void dasd_device_tasklet(struct dasd_device *device)
2134 struct list_head final_queue;
2136 atomic_set (&device->tasklet_scheduled, 0);
2137 INIT_LIST_HEAD(&final_queue);
2138 spin_lock_irq(get_ccwdev_lock(device->cdev));
2139 /* Check expire time of first request on the ccw queue. */
2140 __dasd_device_check_expire(device);
2141 /* find final requests on ccw queue */
2142 __dasd_device_process_ccw_queue(device, &final_queue);
2143 __dasd_device_check_path_events(device);
2144 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2145 /* Now call the callback function of requests with final status */
2146 __dasd_device_process_final_queue(device, &final_queue);
2147 spin_lock_irq(get_ccwdev_lock(device->cdev));
2148 /* Now check if the head of the ccw queue needs to be started. */
2149 __dasd_device_start_head(device);
2150 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2151 if (waitqueue_active(&shutdown_waitq))
2152 wake_up(&shutdown_waitq);
2153 dasd_put_device(device);
2157 * Schedules a call to dasd_tasklet over the device tasklet.
2159 void dasd_schedule_device_bh(struct dasd_device *device)
2161 /* Protect against rescheduling. */
2162 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2164 dasd_get_device(device);
2165 tasklet_hi_schedule(&device->tasklet);
2167 EXPORT_SYMBOL(dasd_schedule_device_bh);
2169 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2171 device->stopped |= bits;
2173 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2175 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2177 device->stopped &= ~bits;
2178 if (!device->stopped)
2179 wake_up(&generic_waitq);
2181 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2184 * Queue a request to the head of the device ccw_queue.
2185 * Start the I/O if possible.
2187 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2189 struct dasd_device *device;
2190 unsigned long flags;
2192 device = cqr->startdev;
2193 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2194 cqr->status = DASD_CQR_QUEUED;
2195 list_add(&cqr->devlist, &device->ccw_queue);
2196 /* let the bh start the request to keep them in order */
2197 dasd_schedule_device_bh(device);
2198 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2200 EXPORT_SYMBOL(dasd_add_request_head);
2203 * Queue a request to the tail of the device ccw_queue.
2204 * Start the I/O if possible.
2206 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2208 struct dasd_device *device;
2209 unsigned long flags;
2211 device = cqr->startdev;
2212 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2213 cqr->status = DASD_CQR_QUEUED;
2214 list_add_tail(&cqr->devlist, &device->ccw_queue);
2215 /* let the bh start the request to keep them in order */
2216 dasd_schedule_device_bh(device);
2217 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2219 EXPORT_SYMBOL(dasd_add_request_tail);
2222 * Wakeup helper for the 'sleep_on' functions.
2224 void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2226 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2227 cqr->callback_data = DASD_SLEEPON_END_TAG;
2228 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2229 wake_up(&generic_waitq);
2231 EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
2233 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2235 struct dasd_device *device;
2238 device = cqr->startdev;
2239 spin_lock_irq(get_ccwdev_lock(device->cdev));
2240 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2241 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2246 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2248 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2250 struct dasd_device *device;
2251 dasd_erp_fn_t erp_fn;
2253 if (cqr->status == DASD_CQR_FILLED)
2255 device = cqr->startdev;
2256 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2257 if (cqr->status == DASD_CQR_TERMINATED) {
2258 device->discipline->handle_terminated_request(cqr);
2261 if (cqr->status == DASD_CQR_NEED_ERP) {
2262 erp_fn = device->discipline->erp_action(cqr);
2266 if (cqr->status == DASD_CQR_FAILED)
2267 dasd_log_sense(cqr, &cqr->irb);
2269 __dasd_process_erp(device, cqr);
2276 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2278 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2279 if (cqr->refers) /* erp is not done yet */
2281 return ((cqr->status != DASD_CQR_DONE) &&
2282 (cqr->status != DASD_CQR_FAILED));
2284 return (cqr->status == DASD_CQR_FILLED);
2287 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2289 struct dasd_device *device;
2291 struct list_head ccw_queue;
2292 struct dasd_ccw_req *cqr;
2294 INIT_LIST_HEAD(&ccw_queue);
2295 maincqr->status = DASD_CQR_FILLED;
2296 device = maincqr->startdev;
2297 list_add(&maincqr->blocklist, &ccw_queue);
2298 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2299 cqr = list_first_entry(&ccw_queue,
2300 struct dasd_ccw_req, blocklist)) {
2302 if (__dasd_sleep_on_erp(cqr))
2304 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2306 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2307 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2308 cqr->status = DASD_CQR_FAILED;
2309 cqr->intrc = -EPERM;
2312 /* Non-temporary stop condition will trigger fail fast */
2313 if (device->stopped & ~DASD_STOPPED_PENDING &&
2314 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2315 (!dasd_eer_enabled(device))) {
2316 cqr->status = DASD_CQR_FAILED;
2317 cqr->intrc = -ENOLINK;
2321 * Don't try to start requests if device is in
2322 * offline processing, it might wait forever
2324 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2325 cqr->status = DASD_CQR_FAILED;
2326 cqr->intrc = -ENODEV;
2330 * Don't try to start requests if device is stopped
2331 * except path verification requests
2333 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2334 if (interruptible) {
2335 rc = wait_event_interruptible(
2336 generic_waitq, !(device->stopped));
2337 if (rc == -ERESTARTSYS) {
2338 cqr->status = DASD_CQR_FAILED;
2339 maincqr->intrc = rc;
2343 wait_event(generic_waitq, !(device->stopped));
2346 cqr->callback = dasd_wakeup_cb;
2348 cqr->callback_data = DASD_SLEEPON_START_TAG;
2349 dasd_add_request_tail(cqr);
2350 if (interruptible) {
2351 rc = wait_event_interruptible(
2352 generic_waitq, _wait_for_wakeup(cqr));
2353 if (rc == -ERESTARTSYS) {
2354 dasd_cancel_req(cqr);
2355 /* wait (non-interruptible) for final status */
2356 wait_event(generic_waitq,
2357 _wait_for_wakeup(cqr));
2358 cqr->status = DASD_CQR_FAILED;
2359 maincqr->intrc = rc;
2363 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2366 maincqr->endclk = get_tod_clock();
2367 if ((maincqr->status != DASD_CQR_DONE) &&
2368 (maincqr->intrc != -ERESTARTSYS))
2369 dasd_log_sense(maincqr, &maincqr->irb);
2370 if (maincqr->status == DASD_CQR_DONE)
2372 else if (maincqr->intrc)
2373 rc = maincqr->intrc;
2379 static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2381 struct dasd_ccw_req *cqr;
2383 list_for_each_entry(cqr, ccw_queue, blocklist) {
2384 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2391 static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2393 struct dasd_device *device;
2394 struct dasd_ccw_req *cqr, *n;
2399 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2400 device = cqr->startdev;
2401 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2404 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2405 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2406 cqr->status = DASD_CQR_FAILED;
2407 cqr->intrc = -EPERM;
2410 /*Non-temporary stop condition will trigger fail fast*/
2411 if (device->stopped & ~DASD_STOPPED_PENDING &&
2412 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2413 !dasd_eer_enabled(device)) {
2414 cqr->status = DASD_CQR_FAILED;
2415 cqr->intrc = -EAGAIN;
2419 /*Don't try to start requests if device is stopped*/
2420 if (interruptible) {
2421 rc = wait_event_interruptible(
2422 generic_waitq, !device->stopped);
2423 if (rc == -ERESTARTSYS) {
2424 cqr->status = DASD_CQR_FAILED;
2429 wait_event(generic_waitq, !(device->stopped));
2432 cqr->callback = dasd_wakeup_cb;
2433 cqr->callback_data = DASD_SLEEPON_START_TAG;
2434 dasd_add_request_tail(cqr);
2437 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2440 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2442 * In some cases the 'File Protected' or 'Incorrect Length'
2443 * error might be expected and error recovery would be
2444 * unnecessary in these cases. Check if the according suppress
2447 sense = dasd_get_sense(&cqr->irb);
2448 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2449 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2451 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2452 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2456 * for alias devices simplify error recovery and
2457 * return to upper layer
2458 * do not skip ERP requests
2460 if (cqr->startdev != cqr->basedev && !cqr->refers &&
2461 (cqr->status == DASD_CQR_TERMINATED ||
2462 cqr->status == DASD_CQR_NEED_ERP))
2465 /* normal recovery for basedev IO */
2466 if (__dasd_sleep_on_erp(cqr))
2467 /* handle erp first */
2475 * Queue a request to the tail of the device ccw_queue and wait for
2478 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2480 return _dasd_sleep_on(cqr, 0);
2482 EXPORT_SYMBOL(dasd_sleep_on);
2485 * Start requests from a ccw_queue and wait for their completion.
2487 int dasd_sleep_on_queue(struct list_head *ccw_queue)
2489 return _dasd_sleep_on_queue(ccw_queue, 0);
2491 EXPORT_SYMBOL(dasd_sleep_on_queue);
2494 * Queue a request to the tail of the device ccw_queue and wait
2495 * interruptible for it's completion.
2497 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2499 return _dasd_sleep_on(cqr, 1);
2501 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2504 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2505 * for eckd devices) the currently running request has to be terminated
2506 * and be put back to status queued, before the special request is added
2507 * to the head of the queue. Then the special request is waited on normally.
2509 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2511 struct dasd_ccw_req *cqr;
2514 if (list_empty(&device->ccw_queue))
2516 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2517 rc = device->discipline->term_IO(cqr);
2520 * CQR terminated because a more important request is pending.
2521 * Undo decreasing of retry counter because this is
2522 * not an error case.
2528 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2530 struct dasd_device *device;
2533 device = cqr->startdev;
2534 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2535 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2536 cqr->status = DASD_CQR_FAILED;
2537 cqr->intrc = -EPERM;
2540 spin_lock_irq(get_ccwdev_lock(device->cdev));
2541 rc = _dasd_term_running_cqr(device);
2543 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2546 cqr->callback = dasd_wakeup_cb;
2547 cqr->callback_data = DASD_SLEEPON_START_TAG;
2548 cqr->status = DASD_CQR_QUEUED;
2550 * add new request as second
2551 * first the terminated cqr needs to be finished
2553 list_add(&cqr->devlist, device->ccw_queue.next);
2555 /* let the bh start the request to keep them in order */
2556 dasd_schedule_device_bh(device);
2558 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2560 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2562 if (cqr->status == DASD_CQR_DONE)
2564 else if (cqr->intrc)
2570 dasd_schedule_device_bh(device);
2572 dasd_schedule_block_bh(device->block);
2576 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2579 * Cancels a request that was started with dasd_sleep_on_req.
2580 * This is useful to timeout requests. The request will be
2581 * terminated if it is currently in i/o.
2582 * Returns 0 if request termination was successful
2583 * negative error code if termination failed
2584 * Cancellation of a request is an asynchronous operation! The calling
2585 * function has to wait until the request is properly returned via callback.
2587 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2589 struct dasd_device *device = cqr->startdev;
2590 unsigned long flags;
2594 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2595 switch (cqr->status) {
2596 case DASD_CQR_QUEUED:
2597 /* request was not started - just set to cleared */
2598 cqr->status = DASD_CQR_CLEARED;
2600 case DASD_CQR_IN_IO:
2601 /* request in IO - terminate IO and release again */
2602 rc = device->discipline->term_IO(cqr);
2604 dev_err(&device->cdev->dev,
2605 "Cancelling request %p failed with rc=%d\n",
2608 cqr->stopclk = get_tod_clock();
2611 default: /* already finished or clear pending - do nothing */
2614 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2615 dasd_schedule_device_bh(device);
2618 EXPORT_SYMBOL(dasd_cancel_req);
2621 * SECTION: Operations of the dasd_block layer.
2625 * Timeout function for dasd_block. This is used when the block layer
2626 * is waiting for something that may not come reliably, (e.g. a state
2629 static void dasd_block_timeout(unsigned long ptr)
2631 unsigned long flags;
2632 struct dasd_block *block;
2634 block = (struct dasd_block *) ptr;
2635 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2636 /* re-activate request queue */
2637 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2638 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2639 dasd_schedule_block_bh(block);
2640 blk_mq_run_hw_queues(block->request_queue, true);
2644 * Setup timeout for a dasd_block in jiffies.
2646 void dasd_block_set_timer(struct dasd_block *block, int expires)
2649 del_timer(&block->timer);
2651 mod_timer(&block->timer, jiffies + expires);
2653 EXPORT_SYMBOL(dasd_block_set_timer);
2656 * Clear timeout for a dasd_block.
2658 void dasd_block_clear_timer(struct dasd_block *block)
2660 del_timer(&block->timer);
2662 EXPORT_SYMBOL(dasd_block_clear_timer);
2665 * Process finished error recovery ccw.
2667 static void __dasd_process_erp(struct dasd_device *device,
2668 struct dasd_ccw_req *cqr)
2670 dasd_erp_fn_t erp_fn;
2672 if (cqr->status == DASD_CQR_DONE)
2673 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2675 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2676 erp_fn = device->discipline->erp_postaction(cqr);
2680 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2682 struct request *req;
2683 blk_status_t error = BLK_STS_OK;
2686 req = (struct request *) cqr->callback_data;
2687 dasd_profile_end(cqr->block, cqr, req);
2689 status = cqr->block->base->discipline->free_cp(cqr, req);
2691 error = errno_to_blk_status(status);
2692 else if (status == 0) {
2693 switch (cqr->intrc) {
2695 error = BLK_STS_NEXUS;
2698 error = BLK_STS_TRANSPORT;
2701 error = BLK_STS_TIMEOUT;
2704 error = BLK_STS_IOERR;
2710 * We need to take care for ETIMEDOUT errors here since the
2711 * complete callback does not get called in this case.
2712 * Take care of all errors here and avoid additional code to
2713 * transfer the error value to the complete callback.
2716 blk_mq_end_request(req, error);
2717 blk_mq_run_hw_queues(req->q, true);
2719 blk_mq_complete_request(req);
2724 * Process ccw request queue.
2726 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2727 struct list_head *final_queue)
2729 struct list_head *l, *n;
2730 struct dasd_ccw_req *cqr;
2731 dasd_erp_fn_t erp_fn;
2732 unsigned long flags;
2733 struct dasd_device *base = block->base;
2736 /* Process request with final status. */
2737 list_for_each_safe(l, n, &block->ccw_queue) {
2738 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2739 if (cqr->status != DASD_CQR_DONE &&
2740 cqr->status != DASD_CQR_FAILED &&
2741 cqr->status != DASD_CQR_NEED_ERP &&
2742 cqr->status != DASD_CQR_TERMINATED)
2745 if (cqr->status == DASD_CQR_TERMINATED) {
2746 base->discipline->handle_terminated_request(cqr);
2750 /* Process requests that may be recovered */
2751 if (cqr->status == DASD_CQR_NEED_ERP) {
2752 erp_fn = base->discipline->erp_action(cqr);
2753 if (IS_ERR(erp_fn(cqr)))
2758 /* log sense for fatal error */
2759 if (cqr->status == DASD_CQR_FAILED) {
2760 dasd_log_sense(cqr, &cqr->irb);
2763 /* First of all call extended error reporting. */
2764 if (dasd_eer_enabled(base) &&
2765 cqr->status == DASD_CQR_FAILED) {
2766 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2768 /* restart request */
2769 cqr->status = DASD_CQR_FILLED;
2771 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2772 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
2773 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2778 /* Process finished ERP request. */
2780 __dasd_process_erp(base, cqr);
2784 /* Rechain finished requests to final queue */
2785 cqr->endclk = get_tod_clock();
2786 list_move_tail(&cqr->blocklist, final_queue);
2790 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2792 dasd_schedule_block_bh(cqr->block);
2795 static void __dasd_block_start_head(struct dasd_block *block)
2797 struct dasd_ccw_req *cqr;
2799 if (list_empty(&block->ccw_queue))
2801 /* We allways begin with the first requests on the queue, as some
2802 * of previously started requests have to be enqueued on a
2803 * dasd_device again for error recovery.
2805 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2806 if (cqr->status != DASD_CQR_FILLED)
2808 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2809 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2810 cqr->status = DASD_CQR_FAILED;
2811 cqr->intrc = -EPERM;
2812 dasd_schedule_block_bh(block);
2815 /* Non-temporary stop condition will trigger fail fast */
2816 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2817 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2818 (!dasd_eer_enabled(block->base))) {
2819 cqr->status = DASD_CQR_FAILED;
2820 cqr->intrc = -ENOLINK;
2821 dasd_schedule_block_bh(block);
2824 /* Don't try to start requests if device is stopped */
2825 if (block->base->stopped)
2828 /* just a fail safe check, should not happen */
2830 cqr->startdev = block->base;
2832 /* make sure that the requests we submit find their way back */
2833 cqr->callback = dasd_return_cqr_cb;
2835 dasd_add_request_tail(cqr);
2840 * Central dasd_block layer routine. Takes requests from the generic
2841 * block layer request queue, creates ccw requests, enqueues them on
2842 * a dasd_device and processes ccw requests that have been returned.
2844 static void dasd_block_tasklet(struct dasd_block *block)
2846 struct list_head final_queue;
2847 struct list_head *l, *n;
2848 struct dasd_ccw_req *cqr;
2849 struct dasd_queue *dq;
2851 atomic_set(&block->tasklet_scheduled, 0);
2852 INIT_LIST_HEAD(&final_queue);
2853 spin_lock_irq(&block->queue_lock);
2854 /* Finish off requests on ccw queue */
2855 __dasd_process_block_ccw_queue(block, &final_queue);
2856 spin_unlock_irq(&block->queue_lock);
2858 /* Now call the callback function of requests with final status */
2859 list_for_each_safe(l, n, &final_queue) {
2860 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2862 spin_lock_irq(&dq->lock);
2863 list_del_init(&cqr->blocklist);
2864 __dasd_cleanup_cqr(cqr);
2865 spin_unlock_irq(&dq->lock);
2868 spin_lock_irq(&block->queue_lock);
2869 /* Now check if the head of the ccw queue needs to be started. */
2870 __dasd_block_start_head(block);
2871 spin_unlock_irq(&block->queue_lock);
2873 if (waitqueue_active(&shutdown_waitq))
2874 wake_up(&shutdown_waitq);
2875 dasd_put_device(block->base);
2878 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2880 wake_up(&dasd_flush_wq);
2884 * Requeue a request back to the block request queue
2885 * only works for block requests
2887 static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
2889 struct dasd_block *block = cqr->block;
2890 struct request *req;
2895 * If the request is an ERP request there is nothing to requeue.
2896 * This will be done with the remaining original request.
2900 spin_lock_irq(&cqr->dq->lock);
2901 req = (struct request *) cqr->callback_data;
2902 blk_mq_requeue_request(req, false);
2903 spin_unlock_irq(&cqr->dq->lock);
2909 * Go through all request on the dasd_block request queue, cancel them
2910 * on the respective dasd_device, and return them to the generic
2913 static int dasd_flush_block_queue(struct dasd_block *block)
2915 struct dasd_ccw_req *cqr, *n;
2917 struct list_head flush_queue;
2918 unsigned long flags;
2920 INIT_LIST_HEAD(&flush_queue);
2921 spin_lock_bh(&block->queue_lock);
2924 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2925 /* if this request currently owned by a dasd_device cancel it */
2926 if (cqr->status >= DASD_CQR_QUEUED)
2927 rc = dasd_cancel_req(cqr);
2930 /* Rechain request (including erp chain) so it won't be
2931 * touched by the dasd_block_tasklet anymore.
2932 * Replace the callback so we notice when the request
2933 * is returned from the dasd_device layer.
2935 cqr->callback = _dasd_wake_block_flush_cb;
2936 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
2937 list_move_tail(&cqr->blocklist, &flush_queue);
2939 /* moved more than one request - need to restart */
2942 spin_unlock_bh(&block->queue_lock);
2943 /* Now call the callback function of flushed requests */
2945 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
2946 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
2947 /* Process finished ERP request. */
2949 spin_lock_bh(&block->queue_lock);
2950 __dasd_process_erp(block->base, cqr);
2951 spin_unlock_bh(&block->queue_lock);
2952 /* restart list_for_xx loop since dasd_process_erp
2953 * might remove multiple elements */
2956 /* call the callback function */
2957 spin_lock_irqsave(&cqr->dq->lock, flags);
2958 cqr->endclk = get_tod_clock();
2959 list_del_init(&cqr->blocklist);
2960 __dasd_cleanup_cqr(cqr);
2961 spin_unlock_irqrestore(&cqr->dq->lock, flags);
2967 * Schedules a call to dasd_tasklet over the device tasklet.
2969 void dasd_schedule_block_bh(struct dasd_block *block)
2971 /* Protect against rescheduling. */
2972 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
2974 /* life cycle of block is bound to it's base device */
2975 dasd_get_device(block->base);
2976 tasklet_hi_schedule(&block->tasklet);
2978 EXPORT_SYMBOL(dasd_schedule_block_bh);
2982 * SECTION: external block device operations
2983 * (request queue handling, open, release, etc.)
2987 * Dasd request queue function. Called from ll_rw_blk.c
2989 static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
2990 const struct blk_mq_queue_data *qd)
2992 struct dasd_block *block = hctx->queue->queuedata;
2993 struct dasd_queue *dq = hctx->driver_data;
2994 struct request *req = qd->rq;
2995 struct dasd_device *basedev;
2996 struct dasd_ccw_req *cqr;
2997 blk_status_t rc = BLK_STS_OK;
2999 basedev = block->base;
3000 spin_lock_irq(&dq->lock);
3001 if (basedev->state < DASD_STATE_READY ||
3002 test_bit(DASD_FLAG_OFFLINE, &basedev->flags)) {
3003 DBF_DEV_EVENT(DBF_ERR, basedev,
3004 "device not ready for request %p", req);
3010 * if device is stopped do not fetch new requests
3011 * except failfast is active which will let requests fail
3012 * immediately in __dasd_block_start_head()
3014 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
3015 DBF_DEV_EVENT(DBF_ERR, basedev,
3016 "device stopped request %p", req);
3017 rc = BLK_STS_RESOURCE;
3021 if (basedev->features & DASD_FEATURE_READONLY &&
3022 rq_data_dir(req) == WRITE) {
3023 DBF_DEV_EVENT(DBF_ERR, basedev,
3024 "Rejecting write request %p", req);
3029 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
3030 (basedev->features & DASD_FEATURE_FAILFAST ||
3031 blk_noretry_request(req))) {
3032 DBF_DEV_EVENT(DBF_ERR, basedev,
3033 "Rejecting failfast request %p", req);
3038 cqr = basedev->discipline->build_cp(basedev, block, req);
3040 if (PTR_ERR(cqr) == -EBUSY ||
3041 PTR_ERR(cqr) == -ENOMEM ||
3042 PTR_ERR(cqr) == -EAGAIN) {
3043 rc = BLK_STS_RESOURCE;
3046 DBF_DEV_EVENT(DBF_ERR, basedev,
3047 "CCW creation failed (rc=%ld) on request %p",
3053 * Note: callback is set to dasd_return_cqr_cb in
3054 * __dasd_block_start_head to cover erp requests as well
3056 cqr->callback_data = req;
3057 cqr->status = DASD_CQR_FILLED;
3059 *((struct dasd_ccw_req **) blk_mq_rq_to_pdu(req)) = cqr;
3061 blk_mq_start_request(req);
3062 spin_lock(&block->queue_lock);
3063 list_add_tail(&cqr->blocklist, &block->ccw_queue);
3064 INIT_LIST_HEAD(&cqr->devlist);
3065 dasd_profile_start(block, cqr, req);
3066 dasd_schedule_block_bh(block);
3067 spin_unlock(&block->queue_lock);
3070 spin_unlock_irq(&dq->lock);
3075 * Block timeout callback, called from the block layer
3078 * BLK_EH_RESET_TIMER if the request should be left running
3079 * BLK_EH_NOT_HANDLED if the request is handled or terminated
3082 enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
3084 struct dasd_block *block = req->q->queuedata;
3085 struct dasd_device *device;
3086 struct dasd_ccw_req *cqr;
3087 unsigned long flags;
3090 cqr = *((struct dasd_ccw_req **) blk_mq_rq_to_pdu(req));
3092 return BLK_EH_NOT_HANDLED;
3094 spin_lock_irqsave(&cqr->dq->lock, flags);
3095 device = cqr->startdev ? cqr->startdev : block->base;
3096 if (!device->blk_timeout) {
3097 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3098 return BLK_EH_RESET_TIMER;
3100 DBF_DEV_EVENT(DBF_WARNING, device,
3101 " dasd_times_out cqr %p status %x",
3104 spin_lock(&block->queue_lock);
3105 spin_lock(get_ccwdev_lock(device->cdev));
3107 cqr->intrc = -ETIMEDOUT;
3108 if (cqr->status >= DASD_CQR_QUEUED) {
3109 spin_unlock(get_ccwdev_lock(device->cdev));
3110 rc = dasd_cancel_req(cqr);
3111 } else if (cqr->status == DASD_CQR_FILLED ||
3112 cqr->status == DASD_CQR_NEED_ERP) {
3113 cqr->status = DASD_CQR_TERMINATED;
3114 spin_unlock(get_ccwdev_lock(device->cdev));
3115 } else if (cqr->status == DASD_CQR_IN_ERP) {
3116 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3118 list_for_each_entry_safe(searchcqr, nextcqr,
3119 &block->ccw_queue, blocklist) {
3121 while (tmpcqr->refers)
3122 tmpcqr = tmpcqr->refers;
3125 /* searchcqr is an ERP request for cqr */
3126 searchcqr->retries = -1;
3127 searchcqr->intrc = -ETIMEDOUT;
3128 if (searchcqr->status >= DASD_CQR_QUEUED) {
3129 spin_unlock(get_ccwdev_lock(device->cdev));
3130 rc = dasd_cancel_req(searchcqr);
3131 spin_lock(get_ccwdev_lock(device->cdev));
3132 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3133 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3134 searchcqr->status = DASD_CQR_TERMINATED;
3136 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3138 * Shouldn't happen; most recent ERP
3139 * request is at the front of queue
3145 spin_unlock(get_ccwdev_lock(device->cdev));
3147 dasd_schedule_block_bh(block);
3148 spin_unlock(&block->queue_lock);
3149 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3151 return rc ? BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
3154 static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
3157 struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
3162 spin_lock_init(&dq->lock);
3163 hctx->driver_data = dq;
3168 static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
3170 kfree(hctx->driver_data);
3171 hctx->driver_data = NULL;
3174 static void dasd_request_done(struct request *req)
3176 blk_mq_end_request(req, 0);
3177 blk_mq_run_hw_queues(req->q, true);
3180 static struct blk_mq_ops dasd_mq_ops = {
3181 .queue_rq = do_dasd_request,
3182 .complete = dasd_request_done,
3183 .timeout = dasd_times_out,
3184 .init_hctx = dasd_init_hctx,
3185 .exit_hctx = dasd_exit_hctx,
3189 * Allocate and initialize request queue and default I/O scheduler.
3191 static int dasd_alloc_queue(struct dasd_block *block)
3195 block->tag_set.ops = &dasd_mq_ops;
3196 block->tag_set.cmd_size = sizeof(struct dasd_ccw_req *);
3197 block->tag_set.nr_hw_queues = DASD_NR_HW_QUEUES;
3198 block->tag_set.queue_depth = DASD_MAX_LCU_DEV * DASD_REQ_PER_DEV;
3199 block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
3200 block->tag_set.numa_node = NUMA_NO_NODE;
3202 rc = blk_mq_alloc_tag_set(&block->tag_set);
3206 block->request_queue = blk_mq_init_queue(&block->tag_set);
3207 if (IS_ERR(block->request_queue))
3208 return PTR_ERR(block->request_queue);
3210 block->request_queue->queuedata = block;
3216 * Allocate and initialize request queue.
3218 static void dasd_setup_queue(struct dasd_block *block)
3220 unsigned int logical_block_size = block->bp_block;
3221 struct request_queue *q = block->request_queue;
3222 unsigned int max_bytes, max_discard_sectors;
3225 if (block->base->features & DASD_FEATURE_USERAW) {
3227 * the max_blocks value for raw_track access is 256
3228 * it is higher than the native ECKD value because we
3229 * only need one ccw per track
3230 * so the max_hw_sectors are
3231 * 2048 x 512B = 1024kB = 16 tracks
3235 max = block->base->discipline->max_blocks << block->s2b_shift;
3237 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
3238 q->limits.max_dev_sectors = max;
3239 blk_queue_logical_block_size(q, logical_block_size);
3240 blk_queue_max_hw_sectors(q, max);
3241 blk_queue_max_segments(q, USHRT_MAX);
3242 /* with page sized segments we can translate each segement into
3245 blk_queue_max_segment_size(q, PAGE_SIZE);
3246 blk_queue_segment_boundary(q, PAGE_SIZE - 1);
3248 /* Only activate blocklayer discard support for devices that support it */
3249 if (block->base->features & DASD_FEATURE_DISCARD) {
3250 q->limits.discard_granularity = logical_block_size;
3251 q->limits.discard_alignment = PAGE_SIZE;
3253 /* Calculate max_discard_sectors and make it PAGE aligned */
3254 max_bytes = USHRT_MAX * logical_block_size;
3255 max_bytes = ALIGN(max_bytes, PAGE_SIZE) - PAGE_SIZE;
3256 max_discard_sectors = max_bytes / logical_block_size;
3258 blk_queue_max_discard_sectors(q, max_discard_sectors);
3259 blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
3260 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
3265 * Deactivate and free request queue.
3267 static void dasd_free_queue(struct dasd_block *block)
3269 if (block->request_queue) {
3270 blk_cleanup_queue(block->request_queue);
3271 blk_mq_free_tag_set(&block->tag_set);
3272 block->request_queue = NULL;
3276 static int dasd_open(struct block_device *bdev, fmode_t mode)
3278 struct dasd_device *base;
3281 base = dasd_device_from_gendisk(bdev->bd_disk);
3285 atomic_inc(&base->block->open_count);
3286 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
3291 if (!try_module_get(base->discipline->owner)) {
3296 if (dasd_probeonly) {
3297 dev_info(&base->cdev->dev,
3298 "Accessing the DASD failed because it is in "
3299 "probeonly mode\n");
3304 if (base->state <= DASD_STATE_BASIC) {
3305 DBF_DEV_EVENT(DBF_ERR, base, " %s",
3306 " Cannot open unrecognized device");
3311 if ((mode & FMODE_WRITE) &&
3312 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3313 (base->features & DASD_FEATURE_READONLY))) {
3318 dasd_put_device(base);
3322 module_put(base->discipline->owner);
3324 atomic_dec(&base->block->open_count);
3325 dasd_put_device(base);
3329 static void dasd_release(struct gendisk *disk, fmode_t mode)
3331 struct dasd_device *base = dasd_device_from_gendisk(disk);
3333 atomic_dec(&base->block->open_count);
3334 module_put(base->discipline->owner);
3335 dasd_put_device(base);
3340 * Return disk geometry.
3342 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3344 struct dasd_device *base;
3346 base = dasd_device_from_gendisk(bdev->bd_disk);
3350 if (!base->discipline ||
3351 !base->discipline->fill_geometry) {
3352 dasd_put_device(base);
3355 base->discipline->fill_geometry(base->block, geo);
3356 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3357 dasd_put_device(base);
3361 const struct block_device_operations
3362 dasd_device_operations = {
3363 .owner = THIS_MODULE,
3365 .release = dasd_release,
3366 .ioctl = dasd_ioctl,
3367 .compat_ioctl = dasd_ioctl,
3368 .getgeo = dasd_getgeo,
3371 /*******************************************************************************
3372 * end of block device operations
3378 #ifdef CONFIG_PROC_FS
3382 if (dasd_page_cache != NULL) {
3383 kmem_cache_destroy(dasd_page_cache);
3384 dasd_page_cache = NULL;
3386 dasd_gendisk_exit();
3388 if (dasd_debug_area != NULL) {
3389 debug_unregister(dasd_debug_area);
3390 dasd_debug_area = NULL;
3392 dasd_statistics_removeroot();
3396 * SECTION: common functions for ccw_driver use
3400 * Is the device read-only?
3401 * Note that this function does not report the setting of the
3402 * readonly device attribute, but how it is configured in z/VM.
3404 int dasd_device_is_ro(struct dasd_device *device)
3406 struct ccw_dev_id dev_id;
3407 struct diag210 diag_data;
3412 ccw_device_get_id(device->cdev, &dev_id);
3413 memset(&diag_data, 0, sizeof(diag_data));
3414 diag_data.vrdcdvno = dev_id.devno;
3415 diag_data.vrdclen = sizeof(diag_data);
3416 rc = diag210(&diag_data);
3417 if (rc == 0 || rc == 2) {
3418 return diag_data.vrdcvfla & 0x80;
3420 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3425 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3427 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3429 struct ccw_device *cdev = data;
3432 ret = ccw_device_set_online(cdev);
3434 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3435 dev_name(&cdev->dev), ret);
3439 * Initial attempt at a probe function. this can be simplified once
3440 * the other detection code is gone.
3442 int dasd_generic_probe(struct ccw_device *cdev,
3443 struct dasd_discipline *discipline)
3447 ret = dasd_add_sysfs_files(cdev);
3449 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
3450 "dasd_generic_probe: could not add "
3454 cdev->handler = &dasd_int_handler;
3457 * Automatically online either all dasd devices (dasd_autodetect)
3458 * or all devices specified with dasd= parameters during
3461 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
3462 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
3463 async_schedule(dasd_generic_auto_online, cdev);
3466 EXPORT_SYMBOL_GPL(dasd_generic_probe);
3468 void dasd_generic_free_discipline(struct dasd_device *device)
3470 /* Forget the discipline information. */
3471 if (device->discipline) {
3472 if (device->discipline->uncheck_device)
3473 device->discipline->uncheck_device(device);
3474 module_put(device->discipline->owner);
3475 device->discipline = NULL;
3477 if (device->base_discipline) {
3478 module_put(device->base_discipline->owner);
3479 device->base_discipline = NULL;
3482 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3485 * This will one day be called from a global not_oper handler.
3486 * It is also used by driver_unregister during module unload.
3488 void dasd_generic_remove(struct ccw_device *cdev)
3490 struct dasd_device *device;
3491 struct dasd_block *block;
3493 device = dasd_device_from_cdev(cdev);
3494 if (IS_ERR(device)) {
3495 dasd_remove_sysfs_files(cdev);
3498 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3499 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3500 /* Already doing offline processing */
3501 dasd_put_device(device);
3502 dasd_remove_sysfs_files(cdev);
3506 * This device is removed unconditionally. Set offline
3507 * flag to prevent dasd_open from opening it while it is
3508 * no quite down yet.
3510 dasd_set_target_state(device, DASD_STATE_NEW);
3511 cdev->handler = NULL;
3512 /* dasd_delete_device destroys the device reference. */
3513 block = device->block;
3514 dasd_delete_device(device);
3516 * life cycle of block is bound to device, so delete it after
3517 * device was safely removed
3520 dasd_free_block(block);
3522 dasd_remove_sysfs_files(cdev);
3524 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3527 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3528 * the device is detected for the first time and is supposed to be used
3529 * or the user has started activation through sysfs.
3531 int dasd_generic_set_online(struct ccw_device *cdev,
3532 struct dasd_discipline *base_discipline)
3534 struct dasd_discipline *discipline;
3535 struct dasd_device *device;
3538 /* first online clears initial online feature flag */
3539 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3540 device = dasd_create_device(cdev);
3542 return PTR_ERR(device);
3544 discipline = base_discipline;
3545 if (device->features & DASD_FEATURE_USEDIAG) {
3546 if (!dasd_diag_discipline_pointer) {
3547 /* Try to load the required module. */
3548 rc = request_module(DASD_DIAG_MOD);
3550 pr_warn("%s Setting the DASD online failed "
3551 "because the required module %s "
3552 "could not be loaded (rc=%d)\n",
3553 dev_name(&cdev->dev), DASD_DIAG_MOD,
3555 dasd_delete_device(device);
3559 /* Module init could have failed, so check again here after
3560 * request_module(). */
3561 if (!dasd_diag_discipline_pointer) {
3562 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3563 dev_name(&cdev->dev));
3564 dasd_delete_device(device);
3567 discipline = dasd_diag_discipline_pointer;
3569 if (!try_module_get(base_discipline->owner)) {
3570 dasd_delete_device(device);
3573 if (!try_module_get(discipline->owner)) {
3574 module_put(base_discipline->owner);
3575 dasd_delete_device(device);
3578 device->base_discipline = base_discipline;
3579 device->discipline = discipline;
3581 /* check_device will allocate block device if necessary */
3582 rc = discipline->check_device(device);
3584 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3585 dev_name(&cdev->dev), discipline->name, rc);
3586 module_put(discipline->owner);
3587 module_put(base_discipline->owner);
3588 dasd_delete_device(device);
3592 dasd_set_target_state(device, DASD_STATE_ONLINE);
3593 if (device->state <= DASD_STATE_KNOWN) {
3594 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3595 dev_name(&cdev->dev));
3597 dasd_set_target_state(device, DASD_STATE_NEW);
3599 dasd_free_block(device->block);
3600 dasd_delete_device(device);
3602 pr_debug("dasd_generic device %s found\n",
3603 dev_name(&cdev->dev));
3605 wait_event(dasd_init_waitq, _wait_for_device(device));
3607 dasd_put_device(device);
3610 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3612 int dasd_generic_set_offline(struct ccw_device *cdev)
3614 struct dasd_device *device;
3615 struct dasd_block *block;
3616 int max_count, open_count, rc;
3617 unsigned long flags;
3620 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3621 device = dasd_device_from_cdev_locked(cdev);
3622 if (IS_ERR(device)) {
3623 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3624 return PTR_ERR(device);
3628 * We must make sure that this device is currently not in use.
3629 * The open_count is increased for every opener, that includes
3630 * the blkdev_get in dasd_scan_partitions. We are only interested
3631 * in the other openers.
3633 if (device->block) {
3634 max_count = device->block->bdev ? 0 : -1;
3635 open_count = atomic_read(&device->block->open_count);
3636 if (open_count > max_count) {
3638 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3639 dev_name(&cdev->dev), open_count);
3641 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3642 dev_name(&cdev->dev));
3649 * Test if the offline processing is already running and exit if so.
3650 * If a safe offline is being processed this could only be a normal
3651 * offline that should be able to overtake the safe offline and
3652 * cancel any I/O we do not want to wait for any longer
3654 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3655 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3656 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3663 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3666 * if safe_offline is called set safe_offline_running flag and
3667 * clear safe_offline so that a call to normal offline
3668 * can overrun safe_offline processing
3670 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3671 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3672 /* need to unlock here to wait for outstanding I/O */
3673 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3675 * If we want to set the device safe offline all IO operations
3676 * should be finished before continuing the offline process
3677 * so sync bdev first and then wait for our queues to become
3680 if (device->block) {
3681 rc = fsync_bdev(device->block->bdev);
3685 dasd_schedule_device_bh(device);
3686 rc = wait_event_interruptible(shutdown_waitq,
3687 _wait_for_empty_queues(device));
3692 * check if a normal offline process overtook the offline
3693 * processing in this case simply do nothing beside returning
3694 * that we got interrupted
3695 * otherwise mark safe offline as not running any longer and
3696 * continue with normal offline
3698 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3699 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3703 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3705 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3707 dasd_set_target_state(device, DASD_STATE_NEW);
3708 /* dasd_delete_device destroys the device reference. */
3709 block = device->block;
3710 dasd_delete_device(device);
3712 * life cycle of block is bound to device, so delete it after
3713 * device was safely removed
3716 dasd_free_block(block);
3721 /* interrupted by signal */
3722 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3723 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3724 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3726 dasd_put_device(device);
3727 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3730 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3732 int dasd_generic_last_path_gone(struct dasd_device *device)
3734 struct dasd_ccw_req *cqr;
3736 dev_warn(&device->cdev->dev, "No operational channel path is left "
3737 "for the device\n");
3738 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3739 /* First of all call extended error reporting. */
3740 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3742 if (device->state < DASD_STATE_BASIC)
3744 /* Device is active. We want to keep it. */
3745 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3746 if ((cqr->status == DASD_CQR_IN_IO) ||
3747 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3748 cqr->status = DASD_CQR_QUEUED;
3751 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3752 dasd_device_clear_timer(device);
3753 dasd_schedule_device_bh(device);
3756 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3758 int dasd_generic_path_operational(struct dasd_device *device)
3760 dev_info(&device->cdev->dev, "A channel path to the device has become "
3762 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3763 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3764 if (device->stopped & DASD_UNRESUMED_PM) {
3765 dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
3766 dasd_restore_device(device);
3769 dasd_schedule_device_bh(device);
3770 if (device->block) {
3771 dasd_schedule_block_bh(device->block);
3772 if (device->block->request_queue)
3773 blk_mq_run_hw_queues(device->block->request_queue,
3777 if (!device->stopped)
3778 wake_up(&generic_waitq);
3782 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3784 int dasd_generic_notify(struct ccw_device *cdev, int event)
3786 struct dasd_device *device;
3789 device = dasd_device_from_cdev_locked(cdev);
3797 dasd_path_no_path(device);
3798 ret = dasd_generic_last_path_gone(device);
3802 if (dasd_path_get_opm(device))
3803 ret = dasd_generic_path_operational(device);
3806 dasd_put_device(device);
3809 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3811 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3813 struct dasd_device *device;
3814 int chp, oldopm, hpfpm, ifccpm;
3816 device = dasd_device_from_cdev_locked(cdev);
3820 oldopm = dasd_path_get_opm(device);
3821 for (chp = 0; chp < 8; chp++) {
3822 if (path_event[chp] & PE_PATH_GONE) {
3823 dasd_path_notoper(device, chp);
3825 if (path_event[chp] & PE_PATH_AVAILABLE) {
3826 dasd_path_available(device, chp);
3827 dasd_schedule_device_bh(device);
3829 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3830 if (!dasd_path_is_operational(device, chp) &&
3831 !dasd_path_need_verify(device, chp)) {
3833 * we can not establish a pathgroup on an
3834 * unavailable path, so trigger a path
3835 * verification first
3837 dasd_path_available(device, chp);
3838 dasd_schedule_device_bh(device);
3840 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3841 "Pathgroup re-established\n");
3842 if (device->discipline->kick_validate)
3843 device->discipline->kick_validate(device);
3846 hpfpm = dasd_path_get_hpfpm(device);
3847 ifccpm = dasd_path_get_ifccpm(device);
3848 if (!dasd_path_get_opm(device) && hpfpm) {
3850 * device has no operational paths but at least one path is
3851 * disabled due to HPF errors
3852 * disable HPF at all and use the path(s) again
3854 if (device->discipline->disable_hpf)
3855 device->discipline->disable_hpf(device);
3856 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3857 dasd_path_set_tbvpm(device, hpfpm);
3858 dasd_schedule_device_bh(device);
3859 dasd_schedule_requeue(device);
3860 } else if (!dasd_path_get_opm(device) && ifccpm) {
3862 * device has no operational paths but at least one path is
3863 * disabled due to IFCC errors
3864 * trigger path verification on paths with IFCC errors
3866 dasd_path_set_tbvpm(device, ifccpm);
3867 dasd_schedule_device_bh(device);
3869 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3870 dev_warn(&device->cdev->dev,
3871 "No verified channel paths remain for the device\n");
3872 DBF_DEV_EVENT(DBF_WARNING, device,
3873 "%s", "last verified path gone");
3874 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3875 dasd_device_set_stop_bits(device,
3876 DASD_STOPPED_DC_WAIT);
3878 dasd_put_device(device);
3880 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3882 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3884 if (!dasd_path_get_opm(device) && lpm) {
3885 dasd_path_set_opm(device, lpm);
3886 dasd_generic_path_operational(device);
3888 dasd_path_add_opm(device, lpm);
3891 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3894 * clear active requests and requeue them to block layer if possible
3896 static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3898 struct list_head requeue_queue;
3899 struct dasd_ccw_req *cqr, *n;
3900 struct dasd_ccw_req *refers;
3903 INIT_LIST_HEAD(&requeue_queue);
3904 spin_lock_irq(get_ccwdev_lock(device->cdev));
3906 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3907 /* Check status and move request to flush_queue */
3908 if (cqr->status == DASD_CQR_IN_IO) {
3909 rc = device->discipline->term_IO(cqr);
3911 /* unable to terminate requeust */
3912 dev_err(&device->cdev->dev,
3913 "Unable to terminate request %p "
3914 "on suspend\n", cqr);
3915 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3916 dasd_put_device(device);
3920 list_move_tail(&cqr->devlist, &requeue_queue);
3922 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3924 list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) {
3925 wait_event(dasd_flush_wq,
3926 (cqr->status != DASD_CQR_CLEAR_PENDING));
3929 * requeue requests to blocklayer will only work
3930 * for block device requests
3932 if (_dasd_requeue_request(cqr))
3935 /* remove requests from device and block queue */
3936 list_del_init(&cqr->devlist);
3937 while (cqr->refers != NULL) {
3938 refers = cqr->refers;
3939 /* remove the request from the block queue */
3940 list_del(&cqr->blocklist);
3941 /* free the finished erp request */
3942 dasd_free_erp_request(cqr, cqr->memdev);
3947 list_del_init(&cqr->blocklist);
3948 cqr->block->base->discipline->free_cp(
3949 cqr, (struct request *) cqr->callback_data);
3953 * if requests remain then they are internal request
3954 * and go back to the device queue
3956 if (!list_empty(&requeue_queue)) {
3957 /* move freeze_queue to start of the ccw_queue */
3958 spin_lock_irq(get_ccwdev_lock(device->cdev));
3959 list_splice_tail(&requeue_queue, &device->ccw_queue);
3960 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3962 dasd_schedule_device_bh(device);
3966 static void do_requeue_requests(struct work_struct *work)
3968 struct dasd_device *device = container_of(work, struct dasd_device,
3970 dasd_generic_requeue_all_requests(device);
3971 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3973 dasd_schedule_block_bh(device->block);
3974 dasd_put_device(device);
3977 void dasd_schedule_requeue(struct dasd_device *device)
3979 dasd_get_device(device);
3980 /* queue call to dasd_reload_device to the kernel event daemon. */
3981 if (!schedule_work(&device->requeue_requests))
3982 dasd_put_device(device);
3984 EXPORT_SYMBOL(dasd_schedule_requeue);
3986 int dasd_generic_pm_freeze(struct ccw_device *cdev)
3988 struct dasd_device *device = dasd_device_from_cdev(cdev);
3991 return PTR_ERR(device);
3993 /* mark device as suspended */
3994 set_bit(DASD_FLAG_SUSPENDED, &device->flags);
3996 if (device->discipline->freeze)
3997 device->discipline->freeze(device);
3999 /* disallow new I/O */
4000 dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
4002 return dasd_generic_requeue_all_requests(device);
4004 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
4006 int dasd_generic_restore_device(struct ccw_device *cdev)
4008 struct dasd_device *device = dasd_device_from_cdev(cdev);
4012 return PTR_ERR(device);
4014 /* allow new IO again */
4015 dasd_device_remove_stop_bits(device,
4016 (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
4018 dasd_schedule_device_bh(device);
4021 * call discipline restore function
4022 * if device is stopped do nothing e.g. for disconnected devices
4024 if (device->discipline->restore && !(device->stopped))
4025 rc = device->discipline->restore(device);
4026 if (rc || device->stopped)
4028 * if the resume failed for the DASD we put it in
4029 * an UNRESUMED stop state
4031 device->stopped |= DASD_UNRESUMED_PM;
4033 if (device->block) {
4034 dasd_schedule_block_bh(device->block);
4035 if (device->block->request_queue)
4036 blk_mq_run_hw_queues(device->block->request_queue,
4040 clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
4041 dasd_put_device(device);
4044 EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
4046 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
4048 int rdc_buffer_size,
4051 struct dasd_ccw_req *cqr;
4053 unsigned long *idaw;
4055 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
4058 /* internal error 13 - Allocating the RDC request failed*/
4059 dev_err(&device->cdev->dev,
4060 "An error occurred in the DASD device driver, "
4061 "reason=%s\n", "13");
4066 ccw->cmd_code = CCW_CMD_RDC;
4067 if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
4068 idaw = (unsigned long *) (cqr->data);
4069 ccw->cda = (__u32)(addr_t) idaw;
4070 ccw->flags = CCW_FLAG_IDA;
4071 idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
4073 ccw->cda = (__u32)(addr_t) rdc_buffer;
4077 ccw->count = rdc_buffer_size;
4078 cqr->startdev = device;
4079 cqr->memdev = device;
4080 cqr->expires = 10*HZ;
4082 cqr->buildclk = get_tod_clock();
4083 cqr->status = DASD_CQR_FILLED;
4088 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4089 void *rdc_buffer, int rdc_buffer_size)
4092 struct dasd_ccw_req *cqr;
4094 cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
4097 return PTR_ERR(cqr);
4099 ret = dasd_sleep_on(cqr);
4100 dasd_sfree_request(cqr, cqr->memdev);
4103 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
4106 * In command mode and transport mode we need to look for sense
4107 * data in different places. The sense data itself is allways
4108 * an array of 32 bytes, so we can unify the sense data access
4111 char *dasd_get_sense(struct irb *irb)
4113 struct tsb *tsb = NULL;
4116 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4117 if (irb->scsw.tm.tcw)
4118 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
4120 if (tsb && tsb->length == 64 && tsb->flags)
4121 switch (tsb->flags & 0x07) {
4122 case 1: /* tsa_iostat */
4123 sense = tsb->tsa.iostat.sense;
4125 case 2: /* tsa_ddpc */
4126 sense = tsb->tsa.ddpc.sense;
4129 /* currently we don't use interrogate data */
4132 } else if (irb->esw.esw0.erw.cons) {
4137 EXPORT_SYMBOL_GPL(dasd_get_sense);
4139 void dasd_generic_shutdown(struct ccw_device *cdev)
4141 struct dasd_device *device;
4143 device = dasd_device_from_cdev(cdev);
4148 dasd_schedule_block_bh(device->block);
4150 dasd_schedule_device_bh(device);
4152 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4154 EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4156 static int __init dasd_init(void)
4160 init_waitqueue_head(&dasd_init_waitq);
4161 init_waitqueue_head(&dasd_flush_wq);
4162 init_waitqueue_head(&generic_waitq);
4163 init_waitqueue_head(&shutdown_waitq);
4165 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4166 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
4167 if (dasd_debug_area == NULL) {
4171 debug_register_view(dasd_debug_area, &debug_sprintf_view);
4172 debug_set_level(dasd_debug_area, DBF_WARNING);
4174 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4176 dasd_diag_discipline_pointer = NULL;
4178 dasd_statistics_createroot();
4180 rc = dasd_devmap_init();
4183 rc = dasd_gendisk_init();
4189 rc = dasd_eer_init();
4192 #ifdef CONFIG_PROC_FS
4193 rc = dasd_proc_init();
4200 pr_info("The DASD device driver could not be initialized\n");
4205 module_init(dasd_init);
4206 module_exit(dasd_exit);