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)
727 spin_lock(get_ccwdev_lock(device->cdev));
728 counter = 1; /* request is not yet queued on the start device */
729 list_for_each(l, &device->ccw_queue)
732 spin_unlock(get_ccwdev_lock(device->cdev));
734 spin_lock(&device->profile.lock);
735 device->profile.data->dasd_io_nr_req[counter]++;
736 if (rq_data_dir(req) == READ)
737 device->profile.data->dasd_read_nr_req[counter]++;
738 spin_unlock(&device->profile.lock);
742 * Add profiling information for cqr after execution.
745 #define dasd_profile_counter(value, index) \
747 for (index = 0; index < 31 && value >> (2+index); index++) \
751 static void dasd_profile_end_add_data(struct dasd_profile_info *data,
764 /* in case of an overflow, reset the whole profile */
765 if (data->dasd_io_reqs == UINT_MAX) {
766 memset(data, 0, sizeof(*data));
767 getnstimeofday(&data->starttod);
769 data->dasd_io_reqs++;
770 data->dasd_io_sects += sectors;
772 data->dasd_io_alias++;
776 data->dasd_io_secs[sectors_ind]++;
777 data->dasd_io_times[tottime_ind]++;
778 data->dasd_io_timps[tottimeps_ind]++;
779 data->dasd_io_time1[strtime_ind]++;
780 data->dasd_io_time2[irqtime_ind]++;
781 data->dasd_io_time2ps[irqtimeps_ind]++;
782 data->dasd_io_time3[endtime_ind]++;
785 data->dasd_read_reqs++;
786 data->dasd_read_sects += sectors;
788 data->dasd_read_alias++;
790 data->dasd_read_tpm++;
791 data->dasd_read_secs[sectors_ind]++;
792 data->dasd_read_times[tottime_ind]++;
793 data->dasd_read_time1[strtime_ind]++;
794 data->dasd_read_time2[irqtime_ind]++;
795 data->dasd_read_time3[endtime_ind]++;
799 static void dasd_profile_end(struct dasd_block *block,
800 struct dasd_ccw_req *cqr,
803 unsigned long strtime, irqtime, endtime, tottime;
804 unsigned long tottimeps, sectors;
805 struct dasd_device *device;
806 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
807 int irqtime_ind, irqtimeps_ind, endtime_ind;
808 struct dasd_profile_info *data;
810 device = cqr->startdev;
811 if (!(dasd_global_profile_level ||
812 block->profile.data ||
813 device->profile.data))
816 sectors = blk_rq_sectors(req);
817 if (!cqr->buildclk || !cqr->startclk ||
818 !cqr->stopclk || !cqr->endclk ||
822 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
823 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
824 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
825 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
826 tottimeps = tottime / sectors;
828 dasd_profile_counter(sectors, sectors_ind);
829 dasd_profile_counter(tottime, tottime_ind);
830 dasd_profile_counter(tottimeps, tottimeps_ind);
831 dasd_profile_counter(strtime, strtime_ind);
832 dasd_profile_counter(irqtime, irqtime_ind);
833 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
834 dasd_profile_counter(endtime, endtime_ind);
836 spin_lock(&dasd_global_profile.lock);
837 if (dasd_global_profile.data) {
838 data = dasd_global_profile.data;
839 data->dasd_sum_times += tottime;
840 data->dasd_sum_time_str += strtime;
841 data->dasd_sum_time_irq += irqtime;
842 data->dasd_sum_time_end += endtime;
843 dasd_profile_end_add_data(dasd_global_profile.data,
844 cqr->startdev != block->base,
846 rq_data_dir(req) == READ,
847 sectors, sectors_ind, tottime_ind,
848 tottimeps_ind, strtime_ind,
849 irqtime_ind, irqtimeps_ind,
852 spin_unlock(&dasd_global_profile.lock);
854 spin_lock(&block->profile.lock);
855 if (block->profile.data) {
856 data = block->profile.data;
857 data->dasd_sum_times += tottime;
858 data->dasd_sum_time_str += strtime;
859 data->dasd_sum_time_irq += irqtime;
860 data->dasd_sum_time_end += endtime;
861 dasd_profile_end_add_data(block->profile.data,
862 cqr->startdev != block->base,
864 rq_data_dir(req) == READ,
865 sectors, sectors_ind, tottime_ind,
866 tottimeps_ind, strtime_ind,
867 irqtime_ind, irqtimeps_ind,
870 spin_unlock(&block->profile.lock);
872 spin_lock(&device->profile.lock);
873 if (device->profile.data) {
874 data = device->profile.data;
875 data->dasd_sum_times += tottime;
876 data->dasd_sum_time_str += strtime;
877 data->dasd_sum_time_irq += irqtime;
878 data->dasd_sum_time_end += endtime;
879 dasd_profile_end_add_data(device->profile.data,
880 cqr->startdev != block->base,
882 rq_data_dir(req) == READ,
883 sectors, sectors_ind, tottime_ind,
884 tottimeps_ind, strtime_ind,
885 irqtime_ind, irqtimeps_ind,
888 spin_unlock(&device->profile.lock);
891 void dasd_profile_reset(struct dasd_profile *profile)
893 struct dasd_profile_info *data;
895 spin_lock_bh(&profile->lock);
896 data = profile->data;
898 spin_unlock_bh(&profile->lock);
901 memset(data, 0, sizeof(*data));
902 getnstimeofday(&data->starttod);
903 spin_unlock_bh(&profile->lock);
906 int dasd_profile_on(struct dasd_profile *profile)
908 struct dasd_profile_info *data;
910 data = kzalloc(sizeof(*data), GFP_KERNEL);
913 spin_lock_bh(&profile->lock);
915 spin_unlock_bh(&profile->lock);
919 getnstimeofday(&data->starttod);
920 profile->data = data;
921 spin_unlock_bh(&profile->lock);
925 void dasd_profile_off(struct dasd_profile *profile)
927 spin_lock_bh(&profile->lock);
928 kfree(profile->data);
929 profile->data = NULL;
930 spin_unlock_bh(&profile->lock);
933 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
937 buffer = vmalloc(user_len + 1);
939 return ERR_PTR(-ENOMEM);
940 if (copy_from_user(buffer, user_buf, user_len) != 0) {
942 return ERR_PTR(-EFAULT);
944 /* got the string, now strip linefeed. */
945 if (buffer[user_len - 1] == '\n')
946 buffer[user_len - 1] = 0;
948 buffer[user_len] = 0;
952 static ssize_t dasd_stats_write(struct file *file,
953 const char __user *user_buf,
954 size_t user_len, loff_t *pos)
958 struct seq_file *m = (struct seq_file *)file->private_data;
959 struct dasd_profile *prof = m->private;
961 if (user_len > 65536)
963 buffer = dasd_get_user_string(user_buf, user_len);
965 return PTR_ERR(buffer);
967 str = skip_spaces(buffer);
969 if (strncmp(str, "reset", 5) == 0) {
970 dasd_profile_reset(prof);
971 } else if (strncmp(str, "on", 2) == 0) {
972 rc = dasd_profile_on(prof);
976 if (prof == &dasd_global_profile) {
977 dasd_profile_reset(prof);
978 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
980 } else if (strncmp(str, "off", 3) == 0) {
981 if (prof == &dasd_global_profile)
982 dasd_global_profile_level = DASD_PROFILE_OFF;
983 dasd_profile_off(prof);
991 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
995 for (i = 0; i < 32; i++)
996 seq_printf(m, "%u ", array[i]);
1000 static void dasd_stats_seq_print(struct seq_file *m,
1001 struct dasd_profile_info *data)
1003 seq_printf(m, "start_time %ld.%09ld\n",
1004 data->starttod.tv_sec, data->starttod.tv_nsec);
1005 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
1006 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
1007 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
1008 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
1009 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
1010 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
1011 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
1012 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
1013 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
1014 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
1015 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
1016 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
1017 seq_puts(m, "histogram_sectors ");
1018 dasd_stats_array(m, data->dasd_io_secs);
1019 seq_puts(m, "histogram_io_times ");
1020 dasd_stats_array(m, data->dasd_io_times);
1021 seq_puts(m, "histogram_io_times_weighted ");
1022 dasd_stats_array(m, data->dasd_io_timps);
1023 seq_puts(m, "histogram_time_build_to_ssch ");
1024 dasd_stats_array(m, data->dasd_io_time1);
1025 seq_puts(m, "histogram_time_ssch_to_irq ");
1026 dasd_stats_array(m, data->dasd_io_time2);
1027 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
1028 dasd_stats_array(m, data->dasd_io_time2ps);
1029 seq_puts(m, "histogram_time_irq_to_end ");
1030 dasd_stats_array(m, data->dasd_io_time3);
1031 seq_puts(m, "histogram_ccw_queue_length ");
1032 dasd_stats_array(m, data->dasd_io_nr_req);
1033 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
1034 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
1035 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
1036 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
1037 seq_puts(m, "histogram_read_sectors ");
1038 dasd_stats_array(m, data->dasd_read_secs);
1039 seq_puts(m, "histogram_read_times ");
1040 dasd_stats_array(m, data->dasd_read_times);
1041 seq_puts(m, "histogram_read_time_build_to_ssch ");
1042 dasd_stats_array(m, data->dasd_read_time1);
1043 seq_puts(m, "histogram_read_time_ssch_to_irq ");
1044 dasd_stats_array(m, data->dasd_read_time2);
1045 seq_puts(m, "histogram_read_time_irq_to_end ");
1046 dasd_stats_array(m, data->dasd_read_time3);
1047 seq_puts(m, "histogram_read_ccw_queue_length ");
1048 dasd_stats_array(m, data->dasd_read_nr_req);
1051 static int dasd_stats_show(struct seq_file *m, void *v)
1053 struct dasd_profile *profile;
1054 struct dasd_profile_info *data;
1056 profile = m->private;
1057 spin_lock_bh(&profile->lock);
1058 data = profile->data;
1060 spin_unlock_bh(&profile->lock);
1061 seq_puts(m, "disabled\n");
1064 dasd_stats_seq_print(m, data);
1065 spin_unlock_bh(&profile->lock);
1069 static int dasd_stats_open(struct inode *inode, struct file *file)
1071 struct dasd_profile *profile = inode->i_private;
1072 return single_open(file, dasd_stats_show, profile);
1075 static const struct file_operations dasd_stats_raw_fops = {
1076 .owner = THIS_MODULE,
1077 .open = dasd_stats_open,
1079 .llseek = seq_lseek,
1080 .release = single_release,
1081 .write = dasd_stats_write,
1084 static void dasd_profile_init(struct dasd_profile *profile,
1085 struct dentry *base_dentry)
1092 profile->dentry = NULL;
1093 profile->data = NULL;
1094 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1095 pde = debugfs_create_file("statistics", mode, base_dentry,
1096 profile, &dasd_stats_raw_fops);
1097 if (pde && !IS_ERR(pde))
1098 profile->dentry = pde;
1102 static void dasd_profile_exit(struct dasd_profile *profile)
1104 dasd_profile_off(profile);
1105 debugfs_remove(profile->dentry);
1106 profile->dentry = NULL;
1109 static void dasd_statistics_removeroot(void)
1111 dasd_global_profile_level = DASD_PROFILE_OFF;
1112 dasd_profile_exit(&dasd_global_profile);
1113 debugfs_remove(dasd_debugfs_global_entry);
1114 debugfs_remove(dasd_debugfs_root_entry);
1117 static void dasd_statistics_createroot(void)
1121 dasd_debugfs_root_entry = NULL;
1122 pde = debugfs_create_dir("dasd", NULL);
1123 if (!pde || IS_ERR(pde))
1125 dasd_debugfs_root_entry = pde;
1126 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1127 if (!pde || IS_ERR(pde))
1129 dasd_debugfs_global_entry = pde;
1130 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
1134 DBF_EVENT(DBF_ERR, "%s",
1135 "Creation of the dasd debugfs interface failed");
1136 dasd_statistics_removeroot();
1141 #define dasd_profile_start(block, cqr, req) do {} while (0)
1142 #define dasd_profile_end(block, cqr, req) do {} while (0)
1144 static void dasd_statistics_createroot(void)
1149 static void dasd_statistics_removeroot(void)
1154 int dasd_stats_generic_show(struct seq_file *m, void *v)
1156 seq_puts(m, "Statistics are not activated in this kernel\n");
1160 static void dasd_profile_init(struct dasd_profile *profile,
1161 struct dentry *base_dentry)
1166 static void dasd_profile_exit(struct dasd_profile *profile)
1171 int dasd_profile_on(struct dasd_profile *profile)
1176 #endif /* CONFIG_DASD_PROFILE */
1178 static int dasd_hosts_show(struct seq_file *m, void *v)
1180 struct dasd_device *device;
1181 int rc = -EOPNOTSUPP;
1183 device = m->private;
1184 dasd_get_device(device);
1186 if (device->discipline->hosts_print)
1187 rc = device->discipline->hosts_print(device, m);
1189 dasd_put_device(device);
1193 static int dasd_hosts_open(struct inode *inode, struct file *file)
1195 struct dasd_device *device = inode->i_private;
1197 return single_open(file, dasd_hosts_show, device);
1200 static const struct file_operations dasd_hosts_fops = {
1201 .owner = THIS_MODULE,
1202 .open = dasd_hosts_open,
1204 .llseek = seq_lseek,
1205 .release = single_release,
1208 static void dasd_hosts_exit(struct dasd_device *device)
1210 debugfs_remove(device->hosts_dentry);
1211 device->hosts_dentry = NULL;
1214 static void dasd_hosts_init(struct dentry *base_dentry,
1215 struct dasd_device *device)
1223 mode = S_IRUSR | S_IFREG;
1224 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1225 device, &dasd_hosts_fops);
1226 if (pde && !IS_ERR(pde))
1227 device->hosts_dentry = pde;
1231 * Allocate memory for a channel program with 'cplength' channel
1232 * command words and 'datasize' additional space. There are two
1233 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1234 * memory and 2) dasd_smalloc_request uses the static ccw memory
1235 * that gets allocated for each device.
1237 struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength,
1239 struct dasd_device *device)
1241 struct dasd_ccw_req *cqr;
1244 BUG_ON(datasize > PAGE_SIZE ||
1245 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
1247 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
1249 return ERR_PTR(-ENOMEM);
1252 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
1253 GFP_ATOMIC | GFP_DMA);
1254 if (cqr->cpaddr == NULL) {
1256 return ERR_PTR(-ENOMEM);
1261 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
1262 if (cqr->data == NULL) {
1265 return ERR_PTR(-ENOMEM);
1269 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1270 dasd_get_device(device);
1273 EXPORT_SYMBOL(dasd_kmalloc_request);
1275 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength,
1277 struct dasd_device *device)
1279 unsigned long flags;
1280 struct dasd_ccw_req *cqr;
1284 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
1286 size += cplength * sizeof(struct ccw1);
1289 spin_lock_irqsave(&device->mem_lock, flags);
1290 cqr = (struct dasd_ccw_req *)
1291 dasd_alloc_chunk(&device->ccw_chunks, size);
1292 spin_unlock_irqrestore(&device->mem_lock, flags);
1294 return ERR_PTR(-ENOMEM);
1295 memset(cqr, 0, sizeof(struct dasd_ccw_req));
1296 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
1299 cqr->cpaddr = (struct ccw1 *) data;
1300 data += cplength*sizeof(struct ccw1);
1301 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
1306 memset(cqr->data, 0, datasize);
1309 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1310 dasd_get_device(device);
1313 EXPORT_SYMBOL(dasd_smalloc_request);
1316 * Free memory of a channel program. This function needs to free all the
1317 * idal lists that might have been created by dasd_set_cda and the
1318 * struct dasd_ccw_req itself.
1320 void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1324 /* Clear any idals used for the request. */
1327 clear_normalized_cda(ccw);
1328 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
1332 dasd_put_device(device);
1334 EXPORT_SYMBOL(dasd_kfree_request);
1336 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1338 unsigned long flags;
1340 spin_lock_irqsave(&device->mem_lock, flags);
1341 dasd_free_chunk(&device->ccw_chunks, cqr);
1342 spin_unlock_irqrestore(&device->mem_lock, flags);
1343 dasd_put_device(device);
1345 EXPORT_SYMBOL(dasd_sfree_request);
1348 * Check discipline magic in cqr.
1350 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1352 struct dasd_device *device;
1356 device = cqr->startdev;
1357 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1358 DBF_DEV_EVENT(DBF_WARNING, device,
1359 " dasd_ccw_req 0x%08x magic doesn't match"
1360 " discipline 0x%08x",
1362 *(unsigned int *) device->discipline->name);
1369 * Terminate the current i/o and set the request to clear_pending.
1370 * Timer keeps device runnig.
1371 * ccw_device_clear can fail if the i/o subsystem
1374 int dasd_term_IO(struct dasd_ccw_req *cqr)
1376 struct dasd_device *device;
1378 char errorstring[ERRORLENGTH];
1381 rc = dasd_check_cqr(cqr);
1385 device = (struct dasd_device *) cqr->startdev;
1386 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1387 rc = ccw_device_clear(device->cdev, (long) cqr);
1389 case 0: /* termination successful */
1390 cqr->status = DASD_CQR_CLEAR_PENDING;
1391 cqr->stopclk = get_tod_clock();
1393 DBF_DEV_EVENT(DBF_DEBUG, device,
1394 "terminate cqr %p successful",
1398 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1399 "device gone, retry");
1402 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1403 "I/O error, retry");
1407 * device not valid so no I/O could be running
1408 * handle CQR as termination successful
1410 cqr->status = DASD_CQR_CLEARED;
1411 cqr->stopclk = get_tod_clock();
1413 /* no retries for invalid devices */
1415 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1416 "EINVAL, handle as terminated");
1417 /* fake rc to success */
1421 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1422 "device busy, retry later");
1425 /* internal error 10 - unknown rc*/
1426 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1427 dev_err(&device->cdev->dev, "An error occurred in the "
1428 "DASD device driver, reason=%s\n", errorstring);
1434 dasd_schedule_device_bh(device);
1437 EXPORT_SYMBOL(dasd_term_IO);
1440 * Start the i/o. This start_IO can fail if the channel is really busy.
1441 * In that case set up a timer to start the request later.
1443 int dasd_start_IO(struct dasd_ccw_req *cqr)
1445 struct dasd_device *device;
1447 char errorstring[ERRORLENGTH];
1450 rc = dasd_check_cqr(cqr);
1455 device = (struct dasd_device *) cqr->startdev;
1457 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1458 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1459 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1460 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1461 "because of stolen lock", cqr);
1462 cqr->status = DASD_CQR_ERROR;
1463 cqr->intrc = -EPERM;
1466 if (cqr->retries < 0) {
1467 /* internal error 14 - start_IO run out of retries */
1468 sprintf(errorstring, "14 %p", cqr);
1469 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1470 "device driver, reason=%s\n", errorstring);
1471 cqr->status = DASD_CQR_ERROR;
1474 cqr->startclk = get_tod_clock();
1475 cqr->starttime = jiffies;
1477 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1478 cqr->lpm &= dasd_path_get_opm(device);
1480 cqr->lpm = dasd_path_get_opm(device);
1482 if (cqr->cpmode == 1) {
1483 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1484 (long) cqr, cqr->lpm);
1486 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1487 (long) cqr, cqr->lpm, 0);
1491 cqr->status = DASD_CQR_IN_IO;
1494 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1495 "start_IO: device busy, retry later");
1498 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1499 "start_IO: request timeout, retry later");
1502 /* -EACCES indicates that the request used only a subset of the
1503 * available paths and all these paths are gone. If the lpm of
1504 * this request was only a subset of the opm (e.g. the ppm) then
1505 * we just do a retry with all available paths.
1506 * If we already use the full opm, something is amiss, and we
1507 * need a full path verification.
1509 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1510 DBF_DEV_EVENT(DBF_WARNING, device,
1511 "start_IO: selected paths gone (%x)",
1513 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1514 cqr->lpm = dasd_path_get_opm(device);
1515 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1516 "start_IO: selected paths gone,"
1517 " retry on all paths");
1519 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1520 "start_IO: all paths in opm gone,"
1521 " do path verification");
1522 dasd_generic_last_path_gone(device);
1523 dasd_path_no_path(device);
1524 dasd_path_set_tbvpm(device,
1525 ccw_device_get_path_mask(
1530 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1531 "start_IO: -ENODEV device gone, retry");
1534 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1535 "start_IO: -EIO device gone, retry");
1538 /* most likely caused in power management context */
1539 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1540 "start_IO: -EINVAL device currently "
1544 /* internal error 11 - unknown rc */
1545 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1546 dev_err(&device->cdev->dev,
1547 "An error occurred in the DASD device driver, "
1548 "reason=%s\n", errorstring);
1555 EXPORT_SYMBOL(dasd_start_IO);
1558 * Timeout function for dasd devices. This is used for different purposes
1559 * 1) missing interrupt handler for normal operation
1560 * 2) delayed start of request where start_IO failed with -EBUSY
1561 * 3) timeout for missing state change interrupts
1562 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1563 * DASD_CQR_QUEUED for 2) and 3).
1565 static void dasd_device_timeout(unsigned long ptr)
1567 unsigned long flags;
1568 struct dasd_device *device;
1570 device = (struct dasd_device *) ptr;
1571 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1572 /* re-activate request queue */
1573 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1574 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1575 dasd_schedule_device_bh(device);
1579 * Setup timeout for a device in jiffies.
1581 void dasd_device_set_timer(struct dasd_device *device, int expires)
1584 del_timer(&device->timer);
1586 mod_timer(&device->timer, jiffies + expires);
1588 EXPORT_SYMBOL(dasd_device_set_timer);
1591 * Clear timeout for a device.
1593 void dasd_device_clear_timer(struct dasd_device *device)
1595 del_timer(&device->timer);
1597 EXPORT_SYMBOL(dasd_device_clear_timer);
1599 static void dasd_handle_killed_request(struct ccw_device *cdev,
1600 unsigned long intparm)
1602 struct dasd_ccw_req *cqr;
1603 struct dasd_device *device;
1607 cqr = (struct dasd_ccw_req *) intparm;
1608 if (cqr->status != DASD_CQR_IN_IO) {
1609 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1610 "invalid status in handle_killed_request: "
1611 "%02x", cqr->status);
1615 device = dasd_device_from_cdev_locked(cdev);
1616 if (IS_ERR(device)) {
1617 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1618 "unable to get device from cdev");
1622 if (!cqr->startdev ||
1623 device != cqr->startdev ||
1624 strncmp(cqr->startdev->discipline->ebcname,
1625 (char *) &cqr->magic, 4)) {
1626 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1627 "invalid device in request");
1628 dasd_put_device(device);
1632 /* Schedule request to be retried. */
1633 cqr->status = DASD_CQR_QUEUED;
1635 dasd_device_clear_timer(device);
1636 dasd_schedule_device_bh(device);
1637 dasd_put_device(device);
1640 void dasd_generic_handle_state_change(struct dasd_device *device)
1642 /* First of all start sense subsystem status request. */
1643 dasd_eer_snss(device);
1645 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1646 dasd_schedule_device_bh(device);
1647 if (device->block) {
1648 dasd_schedule_block_bh(device->block);
1649 if (device->block->request_queue)
1650 blk_mq_run_hw_queues(device->block->request_queue,
1654 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
1656 static int dasd_check_hpf_error(struct irb *irb)
1658 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1659 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1660 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1664 * Interrupt handler for "normal" ssch-io based dasd devices.
1666 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1669 struct dasd_ccw_req *cqr, *next;
1670 struct dasd_device *device;
1672 int nrf_suppressed = 0;
1673 int fp_suppressed = 0;
1677 cqr = (struct dasd_ccw_req *) intparm;
1679 switch (PTR_ERR(irb)) {
1681 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1682 device = cqr->startdev;
1683 cqr->status = DASD_CQR_CLEARED;
1684 dasd_device_clear_timer(device);
1685 wake_up(&dasd_flush_wq);
1686 dasd_schedule_device_bh(device);
1691 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1692 "request timed out\n", __func__);
1695 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1696 "unknown error %ld\n", __func__,
1699 dasd_handle_killed_request(cdev, intparm);
1703 now = get_tod_clock();
1704 /* check for conditions that should be handled immediately */
1706 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1707 scsw_cstat(&irb->scsw) == 0)) {
1709 memcpy(&cqr->irb, irb, sizeof(*irb));
1710 device = dasd_device_from_cdev_locked(cdev);
1713 /* ignore unsolicited interrupts for DIAG discipline */
1714 if (device->discipline == dasd_diag_discipline_pointer) {
1715 dasd_put_device(device);
1720 * In some cases 'File Protected' or 'No Record Found' errors
1721 * might be expected and debug log messages for the
1722 * corresponding interrupts shouldn't be written then.
1723 * Check if either of the according suppress bits is set.
1725 sense = dasd_get_sense(irb);
1727 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1728 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1729 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1730 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1732 if (!(fp_suppressed || nrf_suppressed))
1733 device->discipline->dump_sense_dbf(device, irb, "int");
1735 if (device->features & DASD_FEATURE_ERPLOG)
1736 device->discipline->dump_sense(device, cqr, irb);
1737 device->discipline->check_for_device_change(device, cqr, irb);
1738 dasd_put_device(device);
1741 /* check for for attention message */
1742 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1743 device = dasd_device_from_cdev_locked(cdev);
1744 if (!IS_ERR(device)) {
1745 device->discipline->check_attention(device,
1746 irb->esw.esw1.lpum);
1747 dasd_put_device(device);
1754 device = (struct dasd_device *) cqr->startdev;
1756 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1757 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1758 "invalid device in request");
1762 /* Check for clear pending */
1763 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1764 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1765 cqr->status = DASD_CQR_CLEARED;
1766 dasd_device_clear_timer(device);
1767 wake_up(&dasd_flush_wq);
1768 dasd_schedule_device_bh(device);
1772 /* check status - the request might have been killed by dyn detach */
1773 if (cqr->status != DASD_CQR_IN_IO) {
1774 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1775 "status %02x", dev_name(&cdev->dev), cqr->status);
1781 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1782 scsw_cstat(&irb->scsw) == 0) {
1783 /* request was completed successfully */
1784 cqr->status = DASD_CQR_SUCCESS;
1786 /* Start first request on queue if possible -> fast_io. */
1787 if (cqr->devlist.next != &device->ccw_queue) {
1788 next = list_entry(cqr->devlist.next,
1789 struct dasd_ccw_req, devlist);
1791 } else { /* error */
1792 /* check for HPF error
1793 * call discipline function to requeue all requests
1794 * and disable HPF accordingly
1796 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1797 device->discipline->handle_hpf_error)
1798 device->discipline->handle_hpf_error(device, irb);
1800 * If we don't want complex ERP for this request, then just
1801 * reset this and retry it in the fastpath
1803 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1805 if (cqr->lpm == dasd_path_get_opm(device))
1806 DBF_DEV_EVENT(DBF_DEBUG, device,
1807 "default ERP in fastpath "
1808 "(%i retries left)",
1810 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1811 cqr->lpm = dasd_path_get_opm(device);
1812 cqr->status = DASD_CQR_QUEUED;
1815 cqr->status = DASD_CQR_ERROR;
1817 if (next && (next->status == DASD_CQR_QUEUED) &&
1818 (!device->stopped)) {
1819 if (device->discipline->start_IO(next) == 0)
1820 expires = next->expires;
1823 dasd_device_set_timer(device, expires);
1825 dasd_device_clear_timer(device);
1826 dasd_schedule_device_bh(device);
1828 EXPORT_SYMBOL(dasd_int_handler);
1830 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1832 struct dasd_device *device;
1834 device = dasd_device_from_cdev_locked(cdev);
1838 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1839 device->state != device->target ||
1840 !device->discipline->check_for_device_change){
1841 dasd_put_device(device);
1844 if (device->discipline->dump_sense_dbf)
1845 device->discipline->dump_sense_dbf(device, irb, "uc");
1846 device->discipline->check_for_device_change(device, NULL, irb);
1847 dasd_put_device(device);
1849 return UC_TODO_RETRY;
1851 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1854 * If we have an error on a dasd_block layer request then we cancel
1855 * and return all further requests from the same dasd_block as well.
1857 static void __dasd_device_recovery(struct dasd_device *device,
1858 struct dasd_ccw_req *ref_cqr)
1860 struct list_head *l, *n;
1861 struct dasd_ccw_req *cqr;
1864 * only requeue request that came from the dasd_block layer
1866 if (!ref_cqr->block)
1869 list_for_each_safe(l, n, &device->ccw_queue) {
1870 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1871 if (cqr->status == DASD_CQR_QUEUED &&
1872 ref_cqr->block == cqr->block) {
1873 cqr->status = DASD_CQR_CLEARED;
1879 * Remove those ccw requests from the queue that need to be returned
1880 * to the upper layer.
1882 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1883 struct list_head *final_queue)
1885 struct list_head *l, *n;
1886 struct dasd_ccw_req *cqr;
1888 /* Process request with final status. */
1889 list_for_each_safe(l, n, &device->ccw_queue) {
1890 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1892 /* Skip any non-final request. */
1893 if (cqr->status == DASD_CQR_QUEUED ||
1894 cqr->status == DASD_CQR_IN_IO ||
1895 cqr->status == DASD_CQR_CLEAR_PENDING)
1897 if (cqr->status == DASD_CQR_ERROR) {
1898 __dasd_device_recovery(device, cqr);
1900 /* Rechain finished requests to final queue */
1901 list_move_tail(&cqr->devlist, final_queue);
1906 * the cqrs from the final queue are returned to the upper layer
1907 * by setting a dasd_block state and calling the callback function
1909 static void __dasd_device_process_final_queue(struct dasd_device *device,
1910 struct list_head *final_queue)
1912 struct list_head *l, *n;
1913 struct dasd_ccw_req *cqr;
1914 struct dasd_block *block;
1915 void (*callback)(struct dasd_ccw_req *, void *data);
1916 void *callback_data;
1917 char errorstring[ERRORLENGTH];
1919 list_for_each_safe(l, n, final_queue) {
1920 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1921 list_del_init(&cqr->devlist);
1923 callback = cqr->callback;
1924 callback_data = cqr->callback_data;
1926 spin_lock_bh(&block->queue_lock);
1927 switch (cqr->status) {
1928 case DASD_CQR_SUCCESS:
1929 cqr->status = DASD_CQR_DONE;
1931 case DASD_CQR_ERROR:
1932 cqr->status = DASD_CQR_NEED_ERP;
1934 case DASD_CQR_CLEARED:
1935 cqr->status = DASD_CQR_TERMINATED;
1938 /* internal error 12 - wrong cqr status*/
1939 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1940 dev_err(&device->cdev->dev,
1941 "An error occurred in the DASD device driver, "
1942 "reason=%s\n", errorstring);
1945 if (cqr->callback != NULL)
1946 (callback)(cqr, callback_data);
1948 spin_unlock_bh(&block->queue_lock);
1953 * Take a look at the first request on the ccw queue and check
1954 * if it reached its expire time. If so, terminate the IO.
1956 static void __dasd_device_check_expire(struct dasd_device *device)
1958 struct dasd_ccw_req *cqr;
1960 if (list_empty(&device->ccw_queue))
1962 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1963 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1964 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1965 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1967 * IO in safe offline processing should not
1968 * run out of retries
1972 if (device->discipline->term_IO(cqr) != 0) {
1973 /* Hmpf, try again in 5 sec */
1974 dev_err(&device->cdev->dev,
1975 "cqr %p timed out (%lus) but cannot be "
1976 "ended, retrying in 5 s\n",
1977 cqr, (cqr->expires/HZ));
1978 cqr->expires += 5*HZ;
1979 dasd_device_set_timer(device, 5*HZ);
1981 dev_err(&device->cdev->dev,
1982 "cqr %p timed out (%lus), %i retries "
1983 "remaining\n", cqr, (cqr->expires/HZ),
1990 * return 1 when device is not eligible for IO
1992 static int __dasd_device_is_unusable(struct dasd_device *device,
1993 struct dasd_ccw_req *cqr)
1995 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM);
1997 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
1998 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
2000 * dasd is being set offline
2001 * but it is no safe offline where we have to allow I/O
2005 if (device->stopped) {
2006 if (device->stopped & mask) {
2007 /* stopped and CQR will not change that. */
2010 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2011 /* CQR is not able to change device to
2015 /* CQR required to get device operational. */
2021 * Take a look at the first request on the ccw queue and check
2022 * if it needs to be started.
2024 static void __dasd_device_start_head(struct dasd_device *device)
2026 struct dasd_ccw_req *cqr;
2029 if (list_empty(&device->ccw_queue))
2031 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2032 if (cqr->status != DASD_CQR_QUEUED)
2034 /* if device is not usable return request to upper layer */
2035 if (__dasd_device_is_unusable(device, cqr)) {
2036 cqr->intrc = -EAGAIN;
2037 cqr->status = DASD_CQR_CLEARED;
2038 dasd_schedule_device_bh(device);
2042 rc = device->discipline->start_IO(cqr);
2044 dasd_device_set_timer(device, cqr->expires);
2045 else if (rc == -EACCES) {
2046 dasd_schedule_device_bh(device);
2048 /* Hmpf, try again in 1/2 sec */
2049 dasd_device_set_timer(device, 50);
2052 static void __dasd_device_check_path_events(struct dasd_device *device)
2056 if (!dasd_path_get_tbvpm(device))
2059 if (device->stopped &
2060 ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM))
2062 rc = device->discipline->verify_path(device,
2063 dasd_path_get_tbvpm(device));
2065 dasd_device_set_timer(device, 50);
2067 dasd_path_clear_all_verify(device);
2071 * Go through all request on the dasd_device request queue,
2072 * terminate them on the cdev if necessary, and return them to the
2073 * submitting layer via callback.
2075 * Make sure that all 'submitting layers' still exist when
2076 * this function is called!. In other words, when 'device' is a base
2077 * device then all block layer requests must have been removed before
2078 * via dasd_flush_block_queue.
2080 int dasd_flush_device_queue(struct dasd_device *device)
2082 struct dasd_ccw_req *cqr, *n;
2084 struct list_head flush_queue;
2086 INIT_LIST_HEAD(&flush_queue);
2087 spin_lock_irq(get_ccwdev_lock(device->cdev));
2089 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2090 /* Check status and move request to flush_queue */
2091 switch (cqr->status) {
2092 case DASD_CQR_IN_IO:
2093 rc = device->discipline->term_IO(cqr);
2095 /* unable to terminate requeust */
2096 dev_err(&device->cdev->dev,
2097 "Flushing the DASD request queue "
2098 "failed for request %p\n", cqr);
2099 /* stop flush processing */
2103 case DASD_CQR_QUEUED:
2104 cqr->stopclk = get_tod_clock();
2105 cqr->status = DASD_CQR_CLEARED;
2107 default: /* no need to modify the others */
2110 list_move_tail(&cqr->devlist, &flush_queue);
2113 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2115 * After this point all requests must be in state CLEAR_PENDING,
2116 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2117 * one of the others.
2119 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2120 wait_event(dasd_flush_wq,
2121 (cqr->status != DASD_CQR_CLEAR_PENDING));
2123 * Now set each request back to TERMINATED, DONE or NEED_ERP
2124 * and call the callback function of flushed requests
2126 __dasd_device_process_final_queue(device, &flush_queue);
2129 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2132 * Acquire the device lock and process queues for the device.
2134 static void dasd_device_tasklet(struct dasd_device *device)
2136 struct list_head final_queue;
2138 atomic_set (&device->tasklet_scheduled, 0);
2139 INIT_LIST_HEAD(&final_queue);
2140 spin_lock_irq(get_ccwdev_lock(device->cdev));
2141 /* Check expire time of first request on the ccw queue. */
2142 __dasd_device_check_expire(device);
2143 /* find final requests on ccw queue */
2144 __dasd_device_process_ccw_queue(device, &final_queue);
2145 __dasd_device_check_path_events(device);
2146 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2147 /* Now call the callback function of requests with final status */
2148 __dasd_device_process_final_queue(device, &final_queue);
2149 spin_lock_irq(get_ccwdev_lock(device->cdev));
2150 /* Now check if the head of the ccw queue needs to be started. */
2151 __dasd_device_start_head(device);
2152 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2153 if (waitqueue_active(&shutdown_waitq))
2154 wake_up(&shutdown_waitq);
2155 dasd_put_device(device);
2159 * Schedules a call to dasd_tasklet over the device tasklet.
2161 void dasd_schedule_device_bh(struct dasd_device *device)
2163 /* Protect against rescheduling. */
2164 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2166 dasd_get_device(device);
2167 tasklet_hi_schedule(&device->tasklet);
2169 EXPORT_SYMBOL(dasd_schedule_device_bh);
2171 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2173 device->stopped |= bits;
2175 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2177 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2179 device->stopped &= ~bits;
2180 if (!device->stopped)
2181 wake_up(&generic_waitq);
2183 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2186 * Queue a request to the head of the device ccw_queue.
2187 * Start the I/O if possible.
2189 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2191 struct dasd_device *device;
2192 unsigned long flags;
2194 device = cqr->startdev;
2195 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2196 cqr->status = DASD_CQR_QUEUED;
2197 list_add(&cqr->devlist, &device->ccw_queue);
2198 /* let the bh start the request to keep them in order */
2199 dasd_schedule_device_bh(device);
2200 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2202 EXPORT_SYMBOL(dasd_add_request_head);
2205 * Queue a request to the tail of the device ccw_queue.
2206 * Start the I/O if possible.
2208 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2210 struct dasd_device *device;
2211 unsigned long flags;
2213 device = cqr->startdev;
2214 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2215 cqr->status = DASD_CQR_QUEUED;
2216 list_add_tail(&cqr->devlist, &device->ccw_queue);
2217 /* let the bh start the request to keep them in order */
2218 dasd_schedule_device_bh(device);
2219 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2221 EXPORT_SYMBOL(dasd_add_request_tail);
2224 * Wakeup helper for the 'sleep_on' functions.
2226 void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2228 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2229 cqr->callback_data = DASD_SLEEPON_END_TAG;
2230 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2231 wake_up(&generic_waitq);
2233 EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
2235 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2237 struct dasd_device *device;
2240 device = cqr->startdev;
2241 spin_lock_irq(get_ccwdev_lock(device->cdev));
2242 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2243 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2248 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2250 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2252 struct dasd_device *device;
2253 dasd_erp_fn_t erp_fn;
2255 if (cqr->status == DASD_CQR_FILLED)
2257 device = cqr->startdev;
2258 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2259 if (cqr->status == DASD_CQR_TERMINATED) {
2260 device->discipline->handle_terminated_request(cqr);
2263 if (cqr->status == DASD_CQR_NEED_ERP) {
2264 erp_fn = device->discipline->erp_action(cqr);
2268 if (cqr->status == DASD_CQR_FAILED)
2269 dasd_log_sense(cqr, &cqr->irb);
2271 __dasd_process_erp(device, cqr);
2278 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2280 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2281 if (cqr->refers) /* erp is not done yet */
2283 return ((cqr->status != DASD_CQR_DONE) &&
2284 (cqr->status != DASD_CQR_FAILED));
2286 return (cqr->status == DASD_CQR_FILLED);
2289 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2291 struct dasd_device *device;
2293 struct list_head ccw_queue;
2294 struct dasd_ccw_req *cqr;
2296 INIT_LIST_HEAD(&ccw_queue);
2297 maincqr->status = DASD_CQR_FILLED;
2298 device = maincqr->startdev;
2299 list_add(&maincqr->blocklist, &ccw_queue);
2300 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2301 cqr = list_first_entry(&ccw_queue,
2302 struct dasd_ccw_req, blocklist)) {
2304 if (__dasd_sleep_on_erp(cqr))
2306 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2308 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2309 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2310 cqr->status = DASD_CQR_FAILED;
2311 cqr->intrc = -EPERM;
2314 /* Non-temporary stop condition will trigger fail fast */
2315 if (device->stopped & ~DASD_STOPPED_PENDING &&
2316 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2317 (!dasd_eer_enabled(device))) {
2318 cqr->status = DASD_CQR_FAILED;
2319 cqr->intrc = -ENOLINK;
2323 * Don't try to start requests if device is in
2324 * offline processing, it might wait forever
2326 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2327 cqr->status = DASD_CQR_FAILED;
2328 cqr->intrc = -ENODEV;
2332 * Don't try to start requests if device is stopped
2333 * except path verification requests
2335 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2336 if (interruptible) {
2337 rc = wait_event_interruptible(
2338 generic_waitq, !(device->stopped));
2339 if (rc == -ERESTARTSYS) {
2340 cqr->status = DASD_CQR_FAILED;
2341 maincqr->intrc = rc;
2345 wait_event(generic_waitq, !(device->stopped));
2348 cqr->callback = dasd_wakeup_cb;
2350 cqr->callback_data = DASD_SLEEPON_START_TAG;
2351 dasd_add_request_tail(cqr);
2352 if (interruptible) {
2353 rc = wait_event_interruptible(
2354 generic_waitq, _wait_for_wakeup(cqr));
2355 if (rc == -ERESTARTSYS) {
2356 dasd_cancel_req(cqr);
2357 /* wait (non-interruptible) for final status */
2358 wait_event(generic_waitq,
2359 _wait_for_wakeup(cqr));
2360 cqr->status = DASD_CQR_FAILED;
2361 maincqr->intrc = rc;
2365 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2368 maincqr->endclk = get_tod_clock();
2369 if ((maincqr->status != DASD_CQR_DONE) &&
2370 (maincqr->intrc != -ERESTARTSYS))
2371 dasd_log_sense(maincqr, &maincqr->irb);
2372 if (maincqr->status == DASD_CQR_DONE)
2374 else if (maincqr->intrc)
2375 rc = maincqr->intrc;
2381 static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2383 struct dasd_ccw_req *cqr;
2385 list_for_each_entry(cqr, ccw_queue, blocklist) {
2386 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2393 static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2395 struct dasd_device *device;
2396 struct dasd_ccw_req *cqr, *n;
2401 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2402 device = cqr->startdev;
2403 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2406 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2407 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2408 cqr->status = DASD_CQR_FAILED;
2409 cqr->intrc = -EPERM;
2412 /*Non-temporary stop condition will trigger fail fast*/
2413 if (device->stopped & ~DASD_STOPPED_PENDING &&
2414 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2415 !dasd_eer_enabled(device)) {
2416 cqr->status = DASD_CQR_FAILED;
2417 cqr->intrc = -EAGAIN;
2421 /*Don't try to start requests if device is stopped*/
2422 if (interruptible) {
2423 rc = wait_event_interruptible(
2424 generic_waitq, !device->stopped);
2425 if (rc == -ERESTARTSYS) {
2426 cqr->status = DASD_CQR_FAILED;
2431 wait_event(generic_waitq, !(device->stopped));
2434 cqr->callback = dasd_wakeup_cb;
2435 cqr->callback_data = DASD_SLEEPON_START_TAG;
2436 dasd_add_request_tail(cqr);
2439 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2442 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2444 * In some cases the 'File Protected' or 'Incorrect Length'
2445 * error might be expected and error recovery would be
2446 * unnecessary in these cases. Check if the according suppress
2449 sense = dasd_get_sense(&cqr->irb);
2450 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2451 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2453 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2454 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2458 * for alias devices simplify error recovery and
2459 * return to upper layer
2460 * do not skip ERP requests
2462 if (cqr->startdev != cqr->basedev && !cqr->refers &&
2463 (cqr->status == DASD_CQR_TERMINATED ||
2464 cqr->status == DASD_CQR_NEED_ERP))
2467 /* normal recovery for basedev IO */
2468 if (__dasd_sleep_on_erp(cqr))
2469 /* handle erp first */
2477 * Queue a request to the tail of the device ccw_queue and wait for
2480 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2482 return _dasd_sleep_on(cqr, 0);
2484 EXPORT_SYMBOL(dasd_sleep_on);
2487 * Start requests from a ccw_queue and wait for their completion.
2489 int dasd_sleep_on_queue(struct list_head *ccw_queue)
2491 return _dasd_sleep_on_queue(ccw_queue, 0);
2493 EXPORT_SYMBOL(dasd_sleep_on_queue);
2496 * Queue a request to the tail of the device ccw_queue and wait
2497 * interruptible for it's completion.
2499 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2501 return _dasd_sleep_on(cqr, 1);
2503 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2506 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2507 * for eckd devices) the currently running request has to be terminated
2508 * and be put back to status queued, before the special request is added
2509 * to the head of the queue. Then the special request is waited on normally.
2511 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2513 struct dasd_ccw_req *cqr;
2516 if (list_empty(&device->ccw_queue))
2518 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2519 rc = device->discipline->term_IO(cqr);
2522 * CQR terminated because a more important request is pending.
2523 * Undo decreasing of retry counter because this is
2524 * not an error case.
2530 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2532 struct dasd_device *device;
2535 device = cqr->startdev;
2536 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2537 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2538 cqr->status = DASD_CQR_FAILED;
2539 cqr->intrc = -EPERM;
2542 spin_lock_irq(get_ccwdev_lock(device->cdev));
2543 rc = _dasd_term_running_cqr(device);
2545 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2548 cqr->callback = dasd_wakeup_cb;
2549 cqr->callback_data = DASD_SLEEPON_START_TAG;
2550 cqr->status = DASD_CQR_QUEUED;
2552 * add new request as second
2553 * first the terminated cqr needs to be finished
2555 list_add(&cqr->devlist, device->ccw_queue.next);
2557 /* let the bh start the request to keep them in order */
2558 dasd_schedule_device_bh(device);
2560 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2562 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2564 if (cqr->status == DASD_CQR_DONE)
2566 else if (cqr->intrc)
2572 dasd_schedule_device_bh(device);
2574 dasd_schedule_block_bh(device->block);
2578 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2581 * Cancels a request that was started with dasd_sleep_on_req.
2582 * This is useful to timeout requests. The request will be
2583 * terminated if it is currently in i/o.
2584 * Returns 0 if request termination was successful
2585 * negative error code if termination failed
2586 * Cancellation of a request is an asynchronous operation! The calling
2587 * function has to wait until the request is properly returned via callback.
2589 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2591 struct dasd_device *device = cqr->startdev;
2592 unsigned long flags;
2596 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2597 switch (cqr->status) {
2598 case DASD_CQR_QUEUED:
2599 /* request was not started - just set to cleared */
2600 cqr->status = DASD_CQR_CLEARED;
2602 case DASD_CQR_IN_IO:
2603 /* request in IO - terminate IO and release again */
2604 rc = device->discipline->term_IO(cqr);
2606 dev_err(&device->cdev->dev,
2607 "Cancelling request %p failed with rc=%d\n",
2610 cqr->stopclk = get_tod_clock();
2613 default: /* already finished or clear pending - do nothing */
2616 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2617 dasd_schedule_device_bh(device);
2620 EXPORT_SYMBOL(dasd_cancel_req);
2623 * SECTION: Operations of the dasd_block layer.
2627 * Timeout function for dasd_block. This is used when the block layer
2628 * is waiting for something that may not come reliably, (e.g. a state
2631 static void dasd_block_timeout(unsigned long ptr)
2633 unsigned long flags;
2634 struct dasd_block *block;
2636 block = (struct dasd_block *) ptr;
2637 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2638 /* re-activate request queue */
2639 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2640 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2641 dasd_schedule_block_bh(block);
2642 blk_mq_run_hw_queues(block->request_queue, true);
2646 * Setup timeout for a dasd_block in jiffies.
2648 void dasd_block_set_timer(struct dasd_block *block, int expires)
2651 del_timer(&block->timer);
2653 mod_timer(&block->timer, jiffies + expires);
2655 EXPORT_SYMBOL(dasd_block_set_timer);
2658 * Clear timeout for a dasd_block.
2660 void dasd_block_clear_timer(struct dasd_block *block)
2662 del_timer(&block->timer);
2664 EXPORT_SYMBOL(dasd_block_clear_timer);
2667 * Process finished error recovery ccw.
2669 static void __dasd_process_erp(struct dasd_device *device,
2670 struct dasd_ccw_req *cqr)
2672 dasd_erp_fn_t erp_fn;
2674 if (cqr->status == DASD_CQR_DONE)
2675 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2677 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2678 erp_fn = device->discipline->erp_postaction(cqr);
2682 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2684 struct request *req;
2685 blk_status_t error = BLK_STS_OK;
2688 req = (struct request *) cqr->callback_data;
2689 dasd_profile_end(cqr->block, cqr, req);
2691 status = cqr->block->base->discipline->free_cp(cqr, req);
2693 error = errno_to_blk_status(status);
2694 else if (status == 0) {
2695 switch (cqr->intrc) {
2697 error = BLK_STS_NEXUS;
2700 error = BLK_STS_TRANSPORT;
2703 error = BLK_STS_TIMEOUT;
2706 error = BLK_STS_IOERR;
2712 * We need to take care for ETIMEDOUT errors here since the
2713 * complete callback does not get called in this case.
2714 * Take care of all errors here and avoid additional code to
2715 * transfer the error value to the complete callback.
2718 blk_mq_end_request(req, error);
2719 blk_mq_run_hw_queues(req->q, true);
2721 blk_mq_complete_request(req);
2726 * Process ccw request queue.
2728 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2729 struct list_head *final_queue)
2731 struct list_head *l, *n;
2732 struct dasd_ccw_req *cqr;
2733 dasd_erp_fn_t erp_fn;
2734 unsigned long flags;
2735 struct dasd_device *base = block->base;
2738 /* Process request with final status. */
2739 list_for_each_safe(l, n, &block->ccw_queue) {
2740 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2741 if (cqr->status != DASD_CQR_DONE &&
2742 cqr->status != DASD_CQR_FAILED &&
2743 cqr->status != DASD_CQR_NEED_ERP &&
2744 cqr->status != DASD_CQR_TERMINATED)
2747 if (cqr->status == DASD_CQR_TERMINATED) {
2748 base->discipline->handle_terminated_request(cqr);
2752 /* Process requests that may be recovered */
2753 if (cqr->status == DASD_CQR_NEED_ERP) {
2754 erp_fn = base->discipline->erp_action(cqr);
2755 if (IS_ERR(erp_fn(cqr)))
2760 /* log sense for fatal error */
2761 if (cqr->status == DASD_CQR_FAILED) {
2762 dasd_log_sense(cqr, &cqr->irb);
2765 /* First of all call extended error reporting. */
2766 if (dasd_eer_enabled(base) &&
2767 cqr->status == DASD_CQR_FAILED) {
2768 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2770 /* restart request */
2771 cqr->status = DASD_CQR_FILLED;
2773 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2774 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
2775 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2780 /* Process finished ERP request. */
2782 __dasd_process_erp(base, cqr);
2786 /* Rechain finished requests to final queue */
2787 cqr->endclk = get_tod_clock();
2788 list_move_tail(&cqr->blocklist, final_queue);
2792 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2794 dasd_schedule_block_bh(cqr->block);
2797 static void __dasd_block_start_head(struct dasd_block *block)
2799 struct dasd_ccw_req *cqr;
2801 if (list_empty(&block->ccw_queue))
2803 /* We allways begin with the first requests on the queue, as some
2804 * of previously started requests have to be enqueued on a
2805 * dasd_device again for error recovery.
2807 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2808 if (cqr->status != DASD_CQR_FILLED)
2810 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2811 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2812 cqr->status = DASD_CQR_FAILED;
2813 cqr->intrc = -EPERM;
2814 dasd_schedule_block_bh(block);
2817 /* Non-temporary stop condition will trigger fail fast */
2818 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2819 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2820 (!dasd_eer_enabled(block->base))) {
2821 cqr->status = DASD_CQR_FAILED;
2822 cqr->intrc = -ENOLINK;
2823 dasd_schedule_block_bh(block);
2826 /* Don't try to start requests if device is stopped */
2827 if (block->base->stopped)
2830 /* just a fail safe check, should not happen */
2832 cqr->startdev = block->base;
2834 /* make sure that the requests we submit find their way back */
2835 cqr->callback = dasd_return_cqr_cb;
2837 dasd_add_request_tail(cqr);
2842 * Central dasd_block layer routine. Takes requests from the generic
2843 * block layer request queue, creates ccw requests, enqueues them on
2844 * a dasd_device and processes ccw requests that have been returned.
2846 static void dasd_block_tasklet(struct dasd_block *block)
2848 struct list_head final_queue;
2849 struct list_head *l, *n;
2850 struct dasd_ccw_req *cqr;
2851 struct dasd_queue *dq;
2853 atomic_set(&block->tasklet_scheduled, 0);
2854 INIT_LIST_HEAD(&final_queue);
2855 spin_lock_irq(&block->queue_lock);
2856 /* Finish off requests on ccw queue */
2857 __dasd_process_block_ccw_queue(block, &final_queue);
2858 spin_unlock_irq(&block->queue_lock);
2860 /* Now call the callback function of requests with final status */
2861 list_for_each_safe(l, n, &final_queue) {
2862 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2864 spin_lock_irq(&dq->lock);
2865 list_del_init(&cqr->blocklist);
2866 __dasd_cleanup_cqr(cqr);
2867 spin_unlock_irq(&dq->lock);
2870 spin_lock_irq(&block->queue_lock);
2871 /* Now check if the head of the ccw queue needs to be started. */
2872 __dasd_block_start_head(block);
2873 spin_unlock_irq(&block->queue_lock);
2875 if (waitqueue_active(&shutdown_waitq))
2876 wake_up(&shutdown_waitq);
2877 dasd_put_device(block->base);
2880 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2882 wake_up(&dasd_flush_wq);
2886 * Requeue a request back to the block request queue
2887 * only works for block requests
2889 static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
2891 struct dasd_block *block = cqr->block;
2892 struct request *req;
2897 * If the request is an ERP request there is nothing to requeue.
2898 * This will be done with the remaining original request.
2902 spin_lock_irq(&cqr->dq->lock);
2903 req = (struct request *) cqr->callback_data;
2904 blk_mq_requeue_request(req, true);
2905 spin_unlock_irq(&cqr->dq->lock);
2911 * Go through all request on the dasd_block request queue, cancel them
2912 * on the respective dasd_device, and return them to the generic
2915 static int dasd_flush_block_queue(struct dasd_block *block)
2917 struct dasd_ccw_req *cqr, *n;
2919 struct list_head flush_queue;
2920 unsigned long flags;
2922 INIT_LIST_HEAD(&flush_queue);
2923 spin_lock_bh(&block->queue_lock);
2926 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2927 /* if this request currently owned by a dasd_device cancel it */
2928 if (cqr->status >= DASD_CQR_QUEUED)
2929 rc = dasd_cancel_req(cqr);
2932 /* Rechain request (including erp chain) so it won't be
2933 * touched by the dasd_block_tasklet anymore.
2934 * Replace the callback so we notice when the request
2935 * is returned from the dasd_device layer.
2937 cqr->callback = _dasd_wake_block_flush_cb;
2938 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
2939 list_move_tail(&cqr->blocklist, &flush_queue);
2941 /* moved more than one request - need to restart */
2944 spin_unlock_bh(&block->queue_lock);
2945 /* Now call the callback function of flushed requests */
2947 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
2948 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
2949 /* Process finished ERP request. */
2951 spin_lock_bh(&block->queue_lock);
2952 __dasd_process_erp(block->base, cqr);
2953 spin_unlock_bh(&block->queue_lock);
2954 /* restart list_for_xx loop since dasd_process_erp
2955 * might remove multiple elements */
2958 /* call the callback function */
2959 spin_lock_irqsave(&cqr->dq->lock, flags);
2960 cqr->endclk = get_tod_clock();
2961 list_del_init(&cqr->blocklist);
2962 __dasd_cleanup_cqr(cqr);
2963 spin_unlock_irqrestore(&cqr->dq->lock, flags);
2969 * Schedules a call to dasd_tasklet over the device tasklet.
2971 void dasd_schedule_block_bh(struct dasd_block *block)
2973 /* Protect against rescheduling. */
2974 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
2976 /* life cycle of block is bound to it's base device */
2977 dasd_get_device(block->base);
2978 tasklet_hi_schedule(&block->tasklet);
2980 EXPORT_SYMBOL(dasd_schedule_block_bh);
2984 * SECTION: external block device operations
2985 * (request queue handling, open, release, etc.)
2989 * Dasd request queue function. Called from ll_rw_blk.c
2991 static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
2992 const struct blk_mq_queue_data *qd)
2994 struct dasd_block *block = hctx->queue->queuedata;
2995 struct dasd_queue *dq = hctx->driver_data;
2996 struct request *req = qd->rq;
2997 struct dasd_device *basedev;
2998 struct dasd_ccw_req *cqr;
2999 blk_status_t rc = BLK_STS_OK;
3001 basedev = block->base;
3002 spin_lock_irq(&dq->lock);
3003 if (basedev->state < DASD_STATE_READY ||
3004 test_bit(DASD_FLAG_OFFLINE, &basedev->flags)) {
3005 DBF_DEV_EVENT(DBF_ERR, basedev,
3006 "device not ready for request %p", req);
3012 * if device is stopped do not fetch new requests
3013 * except failfast is active which will let requests fail
3014 * immediately in __dasd_block_start_head()
3016 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
3017 DBF_DEV_EVENT(DBF_ERR, basedev,
3018 "device stopped request %p", req);
3019 rc = BLK_STS_RESOURCE;
3023 if (basedev->features & DASD_FEATURE_READONLY &&
3024 rq_data_dir(req) == WRITE) {
3025 DBF_DEV_EVENT(DBF_ERR, basedev,
3026 "Rejecting write request %p", req);
3031 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
3032 (basedev->features & DASD_FEATURE_FAILFAST ||
3033 blk_noretry_request(req))) {
3034 DBF_DEV_EVENT(DBF_ERR, basedev,
3035 "Rejecting failfast request %p", req);
3040 cqr = basedev->discipline->build_cp(basedev, block, req);
3042 if (PTR_ERR(cqr) == -EBUSY ||
3043 PTR_ERR(cqr) == -ENOMEM ||
3044 PTR_ERR(cqr) == -EAGAIN) {
3045 rc = BLK_STS_RESOURCE;
3048 DBF_DEV_EVENT(DBF_ERR, basedev,
3049 "CCW creation failed (rc=%ld) on request %p",
3055 * Note: callback is set to dasd_return_cqr_cb in
3056 * __dasd_block_start_head to cover erp requests as well
3058 cqr->callback_data = req;
3059 cqr->status = DASD_CQR_FILLED;
3061 *((struct dasd_ccw_req **) blk_mq_rq_to_pdu(req)) = cqr;
3063 blk_mq_start_request(req);
3064 spin_lock(&block->queue_lock);
3065 list_add_tail(&cqr->blocklist, &block->ccw_queue);
3066 INIT_LIST_HEAD(&cqr->devlist);
3067 dasd_profile_start(block, cqr, req);
3068 dasd_schedule_block_bh(block);
3069 spin_unlock(&block->queue_lock);
3072 spin_unlock_irq(&dq->lock);
3077 * Block timeout callback, called from the block layer
3080 * BLK_EH_RESET_TIMER if the request should be left running
3081 * BLK_EH_NOT_HANDLED if the request is handled or terminated
3084 enum blk_eh_timer_return dasd_times_out(struct request *req, bool reserved)
3086 struct dasd_block *block = req->q->queuedata;
3087 struct dasd_device *device;
3088 struct dasd_ccw_req *cqr;
3089 unsigned long flags;
3092 cqr = *((struct dasd_ccw_req **) blk_mq_rq_to_pdu(req));
3094 return BLK_EH_NOT_HANDLED;
3096 spin_lock_irqsave(&cqr->dq->lock, flags);
3097 device = cqr->startdev ? cqr->startdev : block->base;
3098 if (!device->blk_timeout) {
3099 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3100 return BLK_EH_RESET_TIMER;
3102 DBF_DEV_EVENT(DBF_WARNING, device,
3103 " dasd_times_out cqr %p status %x",
3106 spin_lock(&block->queue_lock);
3107 spin_lock(get_ccwdev_lock(device->cdev));
3109 cqr->intrc = -ETIMEDOUT;
3110 if (cqr->status >= DASD_CQR_QUEUED) {
3111 spin_unlock(get_ccwdev_lock(device->cdev));
3112 rc = dasd_cancel_req(cqr);
3113 } else if (cqr->status == DASD_CQR_FILLED ||
3114 cqr->status == DASD_CQR_NEED_ERP) {
3115 cqr->status = DASD_CQR_TERMINATED;
3116 spin_unlock(get_ccwdev_lock(device->cdev));
3117 } else if (cqr->status == DASD_CQR_IN_ERP) {
3118 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3120 list_for_each_entry_safe(searchcqr, nextcqr,
3121 &block->ccw_queue, blocklist) {
3123 while (tmpcqr->refers)
3124 tmpcqr = tmpcqr->refers;
3127 /* searchcqr is an ERP request for cqr */
3128 searchcqr->retries = -1;
3129 searchcqr->intrc = -ETIMEDOUT;
3130 if (searchcqr->status >= DASD_CQR_QUEUED) {
3131 spin_unlock(get_ccwdev_lock(device->cdev));
3132 rc = dasd_cancel_req(searchcqr);
3133 spin_lock(get_ccwdev_lock(device->cdev));
3134 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3135 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3136 searchcqr->status = DASD_CQR_TERMINATED;
3138 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3140 * Shouldn't happen; most recent ERP
3141 * request is at the front of queue
3147 spin_unlock(get_ccwdev_lock(device->cdev));
3149 dasd_schedule_block_bh(block);
3150 spin_unlock(&block->queue_lock);
3151 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3153 return rc ? BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
3156 static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
3159 struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
3164 spin_lock_init(&dq->lock);
3165 hctx->driver_data = dq;
3170 static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
3172 kfree(hctx->driver_data);
3173 hctx->driver_data = NULL;
3176 static void dasd_request_done(struct request *req)
3178 blk_mq_end_request(req, 0);
3179 blk_mq_run_hw_queues(req->q, true);
3182 static struct blk_mq_ops dasd_mq_ops = {
3183 .queue_rq = do_dasd_request,
3184 .complete = dasd_request_done,
3185 .timeout = dasd_times_out,
3186 .init_hctx = dasd_init_hctx,
3187 .exit_hctx = dasd_exit_hctx,
3191 * Allocate and initialize request queue and default I/O scheduler.
3193 static int dasd_alloc_queue(struct dasd_block *block)
3197 block->tag_set.ops = &dasd_mq_ops;
3198 block->tag_set.cmd_size = sizeof(struct dasd_ccw_req *);
3199 block->tag_set.nr_hw_queues = DASD_NR_HW_QUEUES;
3200 block->tag_set.queue_depth = DASD_MAX_LCU_DEV * DASD_REQ_PER_DEV;
3201 block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
3202 block->tag_set.numa_node = NUMA_NO_NODE;
3204 rc = blk_mq_alloc_tag_set(&block->tag_set);
3208 block->request_queue = blk_mq_init_queue(&block->tag_set);
3209 if (IS_ERR(block->request_queue))
3210 return PTR_ERR(block->request_queue);
3212 block->request_queue->queuedata = block;
3218 * Allocate and initialize request queue.
3220 static void dasd_setup_queue(struct dasd_block *block)
3222 unsigned int logical_block_size = block->bp_block;
3223 struct request_queue *q = block->request_queue;
3224 unsigned int max_bytes, max_discard_sectors;
3227 if (block->base->features & DASD_FEATURE_USERAW) {
3229 * the max_blocks value for raw_track access is 256
3230 * it is higher than the native ECKD value because we
3231 * only need one ccw per track
3232 * so the max_hw_sectors are
3233 * 2048 x 512B = 1024kB = 16 tracks
3237 max = block->base->discipline->max_blocks << block->s2b_shift;
3239 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
3240 q->limits.max_dev_sectors = max;
3241 blk_queue_logical_block_size(q, logical_block_size);
3242 blk_queue_max_hw_sectors(q, max);
3243 blk_queue_max_segments(q, USHRT_MAX);
3244 /* with page sized segments we can translate each segement into
3247 blk_queue_max_segment_size(q, PAGE_SIZE);
3248 blk_queue_segment_boundary(q, PAGE_SIZE - 1);
3250 /* Only activate blocklayer discard support for devices that support it */
3251 if (block->base->features & DASD_FEATURE_DISCARD) {
3252 q->limits.discard_granularity = logical_block_size;
3253 q->limits.discard_alignment = PAGE_SIZE;
3255 /* Calculate max_discard_sectors and make it PAGE aligned */
3256 max_bytes = USHRT_MAX * logical_block_size;
3257 max_bytes = ALIGN(max_bytes, PAGE_SIZE) - PAGE_SIZE;
3258 max_discard_sectors = max_bytes / logical_block_size;
3260 blk_queue_max_discard_sectors(q, max_discard_sectors);
3261 blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
3262 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
3267 * Deactivate and free request queue.
3269 static void dasd_free_queue(struct dasd_block *block)
3271 if (block->request_queue) {
3272 blk_cleanup_queue(block->request_queue);
3273 blk_mq_free_tag_set(&block->tag_set);
3274 block->request_queue = NULL;
3278 static int dasd_open(struct block_device *bdev, fmode_t mode)
3280 struct dasd_device *base;
3283 base = dasd_device_from_gendisk(bdev->bd_disk);
3287 atomic_inc(&base->block->open_count);
3288 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
3293 if (!try_module_get(base->discipline->owner)) {
3298 if (dasd_probeonly) {
3299 dev_info(&base->cdev->dev,
3300 "Accessing the DASD failed because it is in "
3301 "probeonly mode\n");
3306 if (base->state <= DASD_STATE_BASIC) {
3307 DBF_DEV_EVENT(DBF_ERR, base, " %s",
3308 " Cannot open unrecognized device");
3313 if ((mode & FMODE_WRITE) &&
3314 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3315 (base->features & DASD_FEATURE_READONLY))) {
3320 dasd_put_device(base);
3324 module_put(base->discipline->owner);
3326 atomic_dec(&base->block->open_count);
3327 dasd_put_device(base);
3331 static void dasd_release(struct gendisk *disk, fmode_t mode)
3333 struct dasd_device *base = dasd_device_from_gendisk(disk);
3335 atomic_dec(&base->block->open_count);
3336 module_put(base->discipline->owner);
3337 dasd_put_device(base);
3342 * Return disk geometry.
3344 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3346 struct dasd_device *base;
3348 base = dasd_device_from_gendisk(bdev->bd_disk);
3352 if (!base->discipline ||
3353 !base->discipline->fill_geometry) {
3354 dasd_put_device(base);
3357 base->discipline->fill_geometry(base->block, geo);
3358 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3359 dasd_put_device(base);
3363 const struct block_device_operations
3364 dasd_device_operations = {
3365 .owner = THIS_MODULE,
3367 .release = dasd_release,
3368 .ioctl = dasd_ioctl,
3369 .compat_ioctl = dasd_ioctl,
3370 .getgeo = dasd_getgeo,
3373 /*******************************************************************************
3374 * end of block device operations
3380 #ifdef CONFIG_PROC_FS
3384 if (dasd_page_cache != NULL) {
3385 kmem_cache_destroy(dasd_page_cache);
3386 dasd_page_cache = NULL;
3388 dasd_gendisk_exit();
3390 if (dasd_debug_area != NULL) {
3391 debug_unregister(dasd_debug_area);
3392 dasd_debug_area = NULL;
3394 dasd_statistics_removeroot();
3398 * SECTION: common functions for ccw_driver use
3402 * Is the device read-only?
3403 * Note that this function does not report the setting of the
3404 * readonly device attribute, but how it is configured in z/VM.
3406 int dasd_device_is_ro(struct dasd_device *device)
3408 struct ccw_dev_id dev_id;
3409 struct diag210 diag_data;
3414 ccw_device_get_id(device->cdev, &dev_id);
3415 memset(&diag_data, 0, sizeof(diag_data));
3416 diag_data.vrdcdvno = dev_id.devno;
3417 diag_data.vrdclen = sizeof(diag_data);
3418 rc = diag210(&diag_data);
3419 if (rc == 0 || rc == 2) {
3420 return diag_data.vrdcvfla & 0x80;
3422 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3427 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3429 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3431 struct ccw_device *cdev = data;
3434 ret = ccw_device_set_online(cdev);
3436 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3437 dev_name(&cdev->dev), ret);
3441 * Initial attempt at a probe function. this can be simplified once
3442 * the other detection code is gone.
3444 int dasd_generic_probe(struct ccw_device *cdev,
3445 struct dasd_discipline *discipline)
3449 ret = dasd_add_sysfs_files(cdev);
3451 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
3452 "dasd_generic_probe: could not add "
3456 cdev->handler = &dasd_int_handler;
3459 * Automatically online either all dasd devices (dasd_autodetect)
3460 * or all devices specified with dasd= parameters during
3463 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
3464 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
3465 async_schedule(dasd_generic_auto_online, cdev);
3468 EXPORT_SYMBOL_GPL(dasd_generic_probe);
3470 void dasd_generic_free_discipline(struct dasd_device *device)
3472 /* Forget the discipline information. */
3473 if (device->discipline) {
3474 if (device->discipline->uncheck_device)
3475 device->discipline->uncheck_device(device);
3476 module_put(device->discipline->owner);
3477 device->discipline = NULL;
3479 if (device->base_discipline) {
3480 module_put(device->base_discipline->owner);
3481 device->base_discipline = NULL;
3484 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3487 * This will one day be called from a global not_oper handler.
3488 * It is also used by driver_unregister during module unload.
3490 void dasd_generic_remove(struct ccw_device *cdev)
3492 struct dasd_device *device;
3493 struct dasd_block *block;
3495 device = dasd_device_from_cdev(cdev);
3496 if (IS_ERR(device)) {
3497 dasd_remove_sysfs_files(cdev);
3500 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3501 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3502 /* Already doing offline processing */
3503 dasd_put_device(device);
3504 dasd_remove_sysfs_files(cdev);
3508 * This device is removed unconditionally. Set offline
3509 * flag to prevent dasd_open from opening it while it is
3510 * no quite down yet.
3512 dasd_set_target_state(device, DASD_STATE_NEW);
3513 cdev->handler = NULL;
3514 /* dasd_delete_device destroys the device reference. */
3515 block = device->block;
3516 dasd_delete_device(device);
3518 * life cycle of block is bound to device, so delete it after
3519 * device was safely removed
3522 dasd_free_block(block);
3524 dasd_remove_sysfs_files(cdev);
3526 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3529 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3530 * the device is detected for the first time and is supposed to be used
3531 * or the user has started activation through sysfs.
3533 int dasd_generic_set_online(struct ccw_device *cdev,
3534 struct dasd_discipline *base_discipline)
3536 struct dasd_discipline *discipline;
3537 struct dasd_device *device;
3540 /* first online clears initial online feature flag */
3541 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3542 device = dasd_create_device(cdev);
3544 return PTR_ERR(device);
3546 discipline = base_discipline;
3547 if (device->features & DASD_FEATURE_USEDIAG) {
3548 if (!dasd_diag_discipline_pointer) {
3549 /* Try to load the required module. */
3550 rc = request_module(DASD_DIAG_MOD);
3552 pr_warn("%s Setting the DASD online failed "
3553 "because the required module %s "
3554 "could not be loaded (rc=%d)\n",
3555 dev_name(&cdev->dev), DASD_DIAG_MOD,
3557 dasd_delete_device(device);
3561 /* Module init could have failed, so check again here after
3562 * request_module(). */
3563 if (!dasd_diag_discipline_pointer) {
3564 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3565 dev_name(&cdev->dev));
3566 dasd_delete_device(device);
3569 discipline = dasd_diag_discipline_pointer;
3571 if (!try_module_get(base_discipline->owner)) {
3572 dasd_delete_device(device);
3575 if (!try_module_get(discipline->owner)) {
3576 module_put(base_discipline->owner);
3577 dasd_delete_device(device);
3580 device->base_discipline = base_discipline;
3581 device->discipline = discipline;
3583 /* check_device will allocate block device if necessary */
3584 rc = discipline->check_device(device);
3586 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3587 dev_name(&cdev->dev), discipline->name, rc);
3588 module_put(discipline->owner);
3589 module_put(base_discipline->owner);
3590 dasd_delete_device(device);
3594 dasd_set_target_state(device, DASD_STATE_ONLINE);
3595 if (device->state <= DASD_STATE_KNOWN) {
3596 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3597 dev_name(&cdev->dev));
3599 dasd_set_target_state(device, DASD_STATE_NEW);
3601 dasd_free_block(device->block);
3602 dasd_delete_device(device);
3604 pr_debug("dasd_generic device %s found\n",
3605 dev_name(&cdev->dev));
3607 wait_event(dasd_init_waitq, _wait_for_device(device));
3609 dasd_put_device(device);
3612 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3614 int dasd_generic_set_offline(struct ccw_device *cdev)
3616 struct dasd_device *device;
3617 struct dasd_block *block;
3618 int max_count, open_count, rc;
3619 unsigned long flags;
3622 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3623 device = dasd_device_from_cdev_locked(cdev);
3624 if (IS_ERR(device)) {
3625 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3626 return PTR_ERR(device);
3630 * We must make sure that this device is currently not in use.
3631 * The open_count is increased for every opener, that includes
3632 * the blkdev_get in dasd_scan_partitions. We are only interested
3633 * in the other openers.
3635 if (device->block) {
3636 max_count = device->block->bdev ? 0 : -1;
3637 open_count = atomic_read(&device->block->open_count);
3638 if (open_count > max_count) {
3640 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3641 dev_name(&cdev->dev), open_count);
3643 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3644 dev_name(&cdev->dev));
3651 * Test if the offline processing is already running and exit if so.
3652 * If a safe offline is being processed this could only be a normal
3653 * offline that should be able to overtake the safe offline and
3654 * cancel any I/O we do not want to wait for any longer
3656 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3657 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3658 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3665 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3668 * if safe_offline is called set safe_offline_running flag and
3669 * clear safe_offline so that a call to normal offline
3670 * can overrun safe_offline processing
3672 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3673 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3674 /* need to unlock here to wait for outstanding I/O */
3675 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3677 * If we want to set the device safe offline all IO operations
3678 * should be finished before continuing the offline process
3679 * so sync bdev first and then wait for our queues to become
3682 if (device->block) {
3683 rc = fsync_bdev(device->block->bdev);
3687 dasd_schedule_device_bh(device);
3688 rc = wait_event_interruptible(shutdown_waitq,
3689 _wait_for_empty_queues(device));
3694 * check if a normal offline process overtook the offline
3695 * processing in this case simply do nothing beside returning
3696 * that we got interrupted
3697 * otherwise mark safe offline as not running any longer and
3698 * continue with normal offline
3700 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3701 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3705 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3707 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3709 dasd_set_target_state(device, DASD_STATE_NEW);
3710 /* dasd_delete_device destroys the device reference. */
3711 block = device->block;
3712 dasd_delete_device(device);
3714 * life cycle of block is bound to device, so delete it after
3715 * device was safely removed
3718 dasd_free_block(block);
3723 /* interrupted by signal */
3724 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3725 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3726 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3728 dasd_put_device(device);
3729 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3732 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3734 int dasd_generic_last_path_gone(struct dasd_device *device)
3736 struct dasd_ccw_req *cqr;
3738 dev_warn(&device->cdev->dev, "No operational channel path is left "
3739 "for the device\n");
3740 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3741 /* First of all call extended error reporting. */
3742 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3744 if (device->state < DASD_STATE_BASIC)
3746 /* Device is active. We want to keep it. */
3747 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3748 if ((cqr->status == DASD_CQR_IN_IO) ||
3749 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3750 cqr->status = DASD_CQR_QUEUED;
3753 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3754 dasd_device_clear_timer(device);
3755 dasd_schedule_device_bh(device);
3758 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3760 int dasd_generic_path_operational(struct dasd_device *device)
3762 dev_info(&device->cdev->dev, "A channel path to the device has become "
3764 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3765 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3766 if (device->stopped & DASD_UNRESUMED_PM) {
3767 dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
3768 dasd_restore_device(device);
3771 dasd_schedule_device_bh(device);
3772 if (device->block) {
3773 dasd_schedule_block_bh(device->block);
3774 if (device->block->request_queue)
3775 blk_mq_run_hw_queues(device->block->request_queue,
3779 if (!device->stopped)
3780 wake_up(&generic_waitq);
3784 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3786 int dasd_generic_notify(struct ccw_device *cdev, int event)
3788 struct dasd_device *device;
3791 device = dasd_device_from_cdev_locked(cdev);
3799 dasd_path_no_path(device);
3800 ret = dasd_generic_last_path_gone(device);
3804 if (dasd_path_get_opm(device))
3805 ret = dasd_generic_path_operational(device);
3808 dasd_put_device(device);
3811 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3813 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3815 struct dasd_device *device;
3816 int chp, oldopm, hpfpm, ifccpm;
3818 device = dasd_device_from_cdev_locked(cdev);
3822 oldopm = dasd_path_get_opm(device);
3823 for (chp = 0; chp < 8; chp++) {
3824 if (path_event[chp] & PE_PATH_GONE) {
3825 dasd_path_notoper(device, chp);
3827 if (path_event[chp] & PE_PATH_AVAILABLE) {
3828 dasd_path_available(device, chp);
3829 dasd_schedule_device_bh(device);
3831 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3832 if (!dasd_path_is_operational(device, chp) &&
3833 !dasd_path_need_verify(device, chp)) {
3835 * we can not establish a pathgroup on an
3836 * unavailable path, so trigger a path
3837 * verification first
3839 dasd_path_available(device, chp);
3840 dasd_schedule_device_bh(device);
3842 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3843 "Pathgroup re-established\n");
3844 if (device->discipline->kick_validate)
3845 device->discipline->kick_validate(device);
3848 hpfpm = dasd_path_get_hpfpm(device);
3849 ifccpm = dasd_path_get_ifccpm(device);
3850 if (!dasd_path_get_opm(device) && hpfpm) {
3852 * device has no operational paths but at least one path is
3853 * disabled due to HPF errors
3854 * disable HPF at all and use the path(s) again
3856 if (device->discipline->disable_hpf)
3857 device->discipline->disable_hpf(device);
3858 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3859 dasd_path_set_tbvpm(device, hpfpm);
3860 dasd_schedule_device_bh(device);
3861 dasd_schedule_requeue(device);
3862 } else if (!dasd_path_get_opm(device) && ifccpm) {
3864 * device has no operational paths but at least one path is
3865 * disabled due to IFCC errors
3866 * trigger path verification on paths with IFCC errors
3868 dasd_path_set_tbvpm(device, ifccpm);
3869 dasd_schedule_device_bh(device);
3871 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3872 dev_warn(&device->cdev->dev,
3873 "No verified channel paths remain for the device\n");
3874 DBF_DEV_EVENT(DBF_WARNING, device,
3875 "%s", "last verified path gone");
3876 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3877 dasd_device_set_stop_bits(device,
3878 DASD_STOPPED_DC_WAIT);
3880 dasd_put_device(device);
3882 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3884 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3886 if (!dasd_path_get_opm(device) && lpm) {
3887 dasd_path_set_opm(device, lpm);
3888 dasd_generic_path_operational(device);
3890 dasd_path_add_opm(device, lpm);
3893 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3896 * clear active requests and requeue them to block layer if possible
3898 static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3900 struct list_head requeue_queue;
3901 struct dasd_ccw_req *cqr, *n;
3902 struct dasd_ccw_req *refers;
3905 INIT_LIST_HEAD(&requeue_queue);
3906 spin_lock_irq(get_ccwdev_lock(device->cdev));
3908 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3909 /* Check status and move request to flush_queue */
3910 if (cqr->status == DASD_CQR_IN_IO) {
3911 rc = device->discipline->term_IO(cqr);
3913 /* unable to terminate requeust */
3914 dev_err(&device->cdev->dev,
3915 "Unable to terminate request %p "
3916 "on suspend\n", cqr);
3917 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3918 dasd_put_device(device);
3922 list_move_tail(&cqr->devlist, &requeue_queue);
3924 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3926 list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) {
3927 wait_event(dasd_flush_wq,
3928 (cqr->status != DASD_CQR_CLEAR_PENDING));
3931 * requeue requests to blocklayer will only work
3932 * for block device requests
3934 if (_dasd_requeue_request(cqr))
3937 /* remove requests from device and block queue */
3938 list_del_init(&cqr->devlist);
3939 while (cqr->refers != NULL) {
3940 refers = cqr->refers;
3941 /* remove the request from the block queue */
3942 list_del(&cqr->blocklist);
3943 /* free the finished erp request */
3944 dasd_free_erp_request(cqr, cqr->memdev);
3949 list_del_init(&cqr->blocklist);
3950 cqr->block->base->discipline->free_cp(
3951 cqr, (struct request *) cqr->callback_data);
3955 * if requests remain then they are internal request
3956 * and go back to the device queue
3958 if (!list_empty(&requeue_queue)) {
3959 /* move freeze_queue to start of the ccw_queue */
3960 spin_lock_irq(get_ccwdev_lock(device->cdev));
3961 list_splice_tail(&requeue_queue, &device->ccw_queue);
3962 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3964 dasd_schedule_device_bh(device);
3968 static void do_requeue_requests(struct work_struct *work)
3970 struct dasd_device *device = container_of(work, struct dasd_device,
3972 dasd_generic_requeue_all_requests(device);
3973 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3975 dasd_schedule_block_bh(device->block);
3976 dasd_put_device(device);
3979 void dasd_schedule_requeue(struct dasd_device *device)
3981 dasd_get_device(device);
3982 /* queue call to dasd_reload_device to the kernel event daemon. */
3983 if (!schedule_work(&device->requeue_requests))
3984 dasd_put_device(device);
3986 EXPORT_SYMBOL(dasd_schedule_requeue);
3988 int dasd_generic_pm_freeze(struct ccw_device *cdev)
3990 struct dasd_device *device = dasd_device_from_cdev(cdev);
3993 return PTR_ERR(device);
3995 /* mark device as suspended */
3996 set_bit(DASD_FLAG_SUSPENDED, &device->flags);
3998 if (device->discipline->freeze)
3999 device->discipline->freeze(device);
4001 /* disallow new I/O */
4002 dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
4004 return dasd_generic_requeue_all_requests(device);
4006 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
4008 int dasd_generic_restore_device(struct ccw_device *cdev)
4010 struct dasd_device *device = dasd_device_from_cdev(cdev);
4014 return PTR_ERR(device);
4016 /* allow new IO again */
4017 dasd_device_remove_stop_bits(device,
4018 (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
4020 dasd_schedule_device_bh(device);
4023 * call discipline restore function
4024 * if device is stopped do nothing e.g. for disconnected devices
4026 if (device->discipline->restore && !(device->stopped))
4027 rc = device->discipline->restore(device);
4028 if (rc || device->stopped)
4030 * if the resume failed for the DASD we put it in
4031 * an UNRESUMED stop state
4033 device->stopped |= DASD_UNRESUMED_PM;
4035 if (device->block) {
4036 dasd_schedule_block_bh(device->block);
4037 if (device->block->request_queue)
4038 blk_mq_run_hw_queues(device->block->request_queue,
4042 clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
4043 dasd_put_device(device);
4046 EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
4048 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
4050 int rdc_buffer_size,
4053 struct dasd_ccw_req *cqr;
4055 unsigned long *idaw;
4057 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
4060 /* internal error 13 - Allocating the RDC request failed*/
4061 dev_err(&device->cdev->dev,
4062 "An error occurred in the DASD device driver, "
4063 "reason=%s\n", "13");
4068 ccw->cmd_code = CCW_CMD_RDC;
4069 if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
4070 idaw = (unsigned long *) (cqr->data);
4071 ccw->cda = (__u32)(addr_t) idaw;
4072 ccw->flags = CCW_FLAG_IDA;
4073 idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
4075 ccw->cda = (__u32)(addr_t) rdc_buffer;
4079 ccw->count = rdc_buffer_size;
4080 cqr->startdev = device;
4081 cqr->memdev = device;
4082 cqr->expires = 10*HZ;
4084 cqr->buildclk = get_tod_clock();
4085 cqr->status = DASD_CQR_FILLED;
4090 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4091 void *rdc_buffer, int rdc_buffer_size)
4094 struct dasd_ccw_req *cqr;
4096 cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
4099 return PTR_ERR(cqr);
4101 ret = dasd_sleep_on(cqr);
4102 dasd_sfree_request(cqr, cqr->memdev);
4105 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
4108 * In command mode and transport mode we need to look for sense
4109 * data in different places. The sense data itself is allways
4110 * an array of 32 bytes, so we can unify the sense data access
4113 char *dasd_get_sense(struct irb *irb)
4115 struct tsb *tsb = NULL;
4118 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4119 if (irb->scsw.tm.tcw)
4120 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
4122 if (tsb && tsb->length == 64 && tsb->flags)
4123 switch (tsb->flags & 0x07) {
4124 case 1: /* tsa_iostat */
4125 sense = tsb->tsa.iostat.sense;
4127 case 2: /* tsa_ddpc */
4128 sense = tsb->tsa.ddpc.sense;
4131 /* currently we don't use interrogate data */
4134 } else if (irb->esw.esw0.erw.cons) {
4139 EXPORT_SYMBOL_GPL(dasd_get_sense);
4141 void dasd_generic_shutdown(struct ccw_device *cdev)
4143 struct dasd_device *device;
4145 device = dasd_device_from_cdev(cdev);
4150 dasd_schedule_block_bh(device->block);
4152 dasd_schedule_device_bh(device);
4154 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4156 EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4158 static int __init dasd_init(void)
4162 init_waitqueue_head(&dasd_init_waitq);
4163 init_waitqueue_head(&dasd_flush_wq);
4164 init_waitqueue_head(&generic_waitq);
4165 init_waitqueue_head(&shutdown_waitq);
4167 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4168 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
4169 if (dasd_debug_area == NULL) {
4173 debug_register_view(dasd_debug_area, &debug_sprintf_view);
4174 debug_set_level(dasd_debug_area, DBF_WARNING);
4176 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4178 dasd_diag_discipline_pointer = NULL;
4180 dasd_statistics_createroot();
4182 rc = dasd_devmap_init();
4185 rc = dasd_gendisk_init();
4191 rc = dasd_eer_init();
4194 #ifdef CONFIG_PROC_FS
4195 rc = dasd_proc_init();
4202 pr_info("The DASD device driver could not be initialized\n");
4207 module_init(dasd_init);
4208 module_exit(dasd_exit);