1 // SPDX-License-Identifier: GPL-2.0
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * Copyright IBM Corp. 1999, 2009
11 #define KMSG_COMPONENT "dasd"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/kmod.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/ctype.h>
18 #include <linux/major.h>
19 #include <linux/slab.h>
20 #include <linux/hdreg.h>
21 #include <linux/async.h>
22 #include <linux/mutex.h>
23 #include <linux/debugfs.h>
24 #include <linux/seq_file.h>
25 #include <linux/vmalloc.h>
27 #include <asm/ccwdev.h>
28 #include <asm/ebcdic.h>
29 #include <asm/idals.h>
34 #define PRINTK_HEADER "dasd:"
38 * SECTION: Constant definitions to be used within this file
40 #define DASD_CHANQ_MAX_SIZE 4
42 #define DASD_DIAG_MOD "dasd_diag_mod"
45 * SECTION: exported variables of dasd.c
47 debug_info_t *dasd_debug_area;
48 EXPORT_SYMBOL(dasd_debug_area);
49 static struct dentry *dasd_debugfs_root_entry;
50 struct dasd_discipline *dasd_diag_discipline_pointer;
51 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
52 void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
54 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
55 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
56 " Copyright IBM Corp. 2000");
57 MODULE_LICENSE("GPL");
60 * SECTION: prototypes for static functions of dasd.c
62 static int dasd_flush_block_queue(struct dasd_block *);
63 static void dasd_device_tasklet(unsigned long);
64 static void dasd_block_tasklet(unsigned long);
65 static void do_kick_device(struct work_struct *);
66 static void do_reload_device(struct work_struct *);
67 static void do_requeue_requests(struct work_struct *);
68 static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
69 static void dasd_device_timeout(struct timer_list *);
70 static void dasd_block_timeout(struct timer_list *);
71 static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
72 static void dasd_profile_init(struct dasd_profile *, struct dentry *);
73 static void dasd_profile_exit(struct dasd_profile *);
74 static void dasd_hosts_init(struct dentry *, struct dasd_device *);
75 static void dasd_hosts_exit(struct dasd_device *);
76 static int dasd_handle_autoquiesce(struct dasd_device *, struct dasd_ccw_req *,
79 * SECTION: Operations on the device structure.
81 static wait_queue_head_t dasd_init_waitq;
82 static wait_queue_head_t dasd_flush_wq;
83 static wait_queue_head_t generic_waitq;
84 static wait_queue_head_t shutdown_waitq;
87 * Allocate memory for a new device structure.
89 struct dasd_device *dasd_alloc_device(void)
91 struct dasd_device *device;
93 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
95 return ERR_PTR(-ENOMEM);
97 /* Get two pages for normal block device operations. */
98 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
99 if (!device->ccw_mem) {
101 return ERR_PTR(-ENOMEM);
103 /* Get one page for error recovery. */
104 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
105 if (!device->erp_mem) {
106 free_pages((unsigned long) device->ccw_mem, 1);
108 return ERR_PTR(-ENOMEM);
110 /* Get two pages for ese format. */
111 device->ese_mem = (void *)__get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
112 if (!device->ese_mem) {
113 free_page((unsigned long) device->erp_mem);
114 free_pages((unsigned long) device->ccw_mem, 1);
116 return ERR_PTR(-ENOMEM);
119 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
120 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
121 dasd_init_chunklist(&device->ese_chunks, device->ese_mem, PAGE_SIZE * 2);
122 spin_lock_init(&device->mem_lock);
123 atomic_set(&device->tasklet_scheduled, 0);
124 tasklet_init(&device->tasklet, dasd_device_tasklet,
125 (unsigned long) device);
126 INIT_LIST_HEAD(&device->ccw_queue);
127 timer_setup(&device->timer, dasd_device_timeout, 0);
128 INIT_WORK(&device->kick_work, do_kick_device);
129 INIT_WORK(&device->reload_device, do_reload_device);
130 INIT_WORK(&device->requeue_requests, do_requeue_requests);
131 device->state = DASD_STATE_NEW;
132 device->target = DASD_STATE_NEW;
133 mutex_init(&device->state_mutex);
134 spin_lock_init(&device->profile.lock);
139 * Free memory of a device structure.
141 void dasd_free_device(struct dasd_device *device)
143 kfree(device->private);
144 free_pages((unsigned long) device->ese_mem, 1);
145 free_page((unsigned long) device->erp_mem);
146 free_pages((unsigned long) device->ccw_mem, 1);
151 * Allocate memory for a new device structure.
153 struct dasd_block *dasd_alloc_block(void)
155 struct dasd_block *block;
157 block = kzalloc(sizeof(*block), GFP_ATOMIC);
159 return ERR_PTR(-ENOMEM);
160 /* open_count = 0 means device online but not in use */
161 atomic_set(&block->open_count, -1);
163 atomic_set(&block->tasklet_scheduled, 0);
164 tasklet_init(&block->tasklet, dasd_block_tasklet,
165 (unsigned long) block);
166 INIT_LIST_HEAD(&block->ccw_queue);
167 spin_lock_init(&block->queue_lock);
168 INIT_LIST_HEAD(&block->format_list);
169 spin_lock_init(&block->format_lock);
170 timer_setup(&block->timer, dasd_block_timeout, 0);
171 spin_lock_init(&block->profile.lock);
175 EXPORT_SYMBOL_GPL(dasd_alloc_block);
178 * Free memory of a device structure.
180 void dasd_free_block(struct dasd_block *block)
184 EXPORT_SYMBOL_GPL(dasd_free_block);
187 * Make a new device known to the system.
189 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);
196 device->state = DASD_STATE_KNOWN;
201 * Let the system forget about a device.
203 static int dasd_state_known_to_new(struct dasd_device *device)
205 /* Disable extended error reporting for this device. */
206 dasd_eer_disable(device);
207 device->state = DASD_STATE_NEW;
209 /* Give up reference we took in dasd_state_new_to_known. */
210 dasd_put_device(device);
214 static struct dentry *dasd_debugfs_setup(const char *name,
215 struct dentry *base_dentry)
221 pde = debugfs_create_dir(name, base_dentry);
222 if (!pde || IS_ERR(pde))
228 * Request the irq line for the device.
230 static int dasd_state_known_to_basic(struct dasd_device *device)
232 struct dasd_block *block = device->block;
235 /* Allocate and register gendisk structure. */
237 rc = dasd_gendisk_alloc(block);
240 block->debugfs_dentry =
241 dasd_debugfs_setup(block->gdp->disk_name,
242 dasd_debugfs_root_entry);
243 dasd_profile_init(&block->profile, block->debugfs_dentry);
244 if (dasd_global_profile_level == DASD_PROFILE_ON)
245 dasd_profile_on(&device->block->profile);
247 device->debugfs_dentry =
248 dasd_debugfs_setup(dev_name(&device->cdev->dev),
249 dasd_debugfs_root_entry);
250 dasd_profile_init(&device->profile, device->debugfs_dentry);
251 dasd_hosts_init(device->debugfs_dentry, device);
253 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
254 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
256 debug_register_view(device->debug_area, &debug_sprintf_view);
257 debug_set_level(device->debug_area, DBF_WARNING);
258 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
260 device->state = DASD_STATE_BASIC;
266 * Release the irq line for the device. Terminate any running i/o.
268 static int dasd_state_basic_to_known(struct dasd_device *device)
272 if (device->discipline->basic_to_known) {
273 rc = device->discipline->basic_to_known(device);
279 dasd_profile_exit(&device->block->profile);
280 debugfs_remove(device->block->debugfs_dentry);
281 dasd_gendisk_free(device->block);
282 dasd_block_clear_timer(device->block);
284 rc = dasd_flush_device_queue(device);
287 dasd_device_clear_timer(device);
288 dasd_profile_exit(&device->profile);
289 dasd_hosts_exit(device);
290 debugfs_remove(device->debugfs_dentry);
291 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
292 if (device->debug_area != NULL) {
293 debug_unregister(device->debug_area);
294 device->debug_area = NULL;
296 device->state = DASD_STATE_KNOWN;
301 * Do the initial analysis. The do_analysis function may return
302 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
303 * until the discipline decides to continue the startup sequence
304 * by calling the function dasd_change_state. The eckd disciplines
305 * uses this to start a ccw that detects the format. The completion
306 * interrupt for this detection ccw uses the kernel event daemon to
307 * trigger the call to dasd_change_state. All this is done in the
308 * discipline code, see dasd_eckd.c.
309 * After the analysis ccw is done (do_analysis returned 0) the block
311 * In case the analysis returns an error, the device setup is stopped
312 * (a fake disk was already added to allow formatting).
314 static int dasd_state_basic_to_ready(struct dasd_device *device)
317 struct dasd_block *block;
318 struct gendisk *disk;
321 block = device->block;
322 /* make disk known with correct capacity */
324 if (block->base->discipline->do_analysis != NULL)
325 rc = block->base->discipline->do_analysis(block);
328 device->state = DASD_STATE_UNFMT;
329 disk = device->block->gdp;
330 kobject_uevent(&disk_to_dev(disk)->kobj,
336 if (device->discipline->setup_blk_queue)
337 device->discipline->setup_blk_queue(block);
338 set_capacity(block->gdp,
339 block->blocks << block->s2b_shift);
340 device->state = DASD_STATE_READY;
341 rc = dasd_scan_partitions(block);
343 device->state = DASD_STATE_BASIC;
347 device->state = DASD_STATE_READY;
350 if (device->discipline->basic_to_ready)
351 rc = device->discipline->basic_to_ready(device);
356 int _wait_for_empty_queues(struct dasd_device *device)
359 return list_empty(&device->ccw_queue) &&
360 list_empty(&device->block->ccw_queue);
362 return list_empty(&device->ccw_queue);
366 * Remove device from block device layer. Destroy dirty buffers.
367 * Forget format information. Check if the target level is basic
368 * and if it is create fake disk for formatting.
370 static int dasd_state_ready_to_basic(struct dasd_device *device)
374 device->state = DASD_STATE_BASIC;
376 struct dasd_block *block = device->block;
377 rc = dasd_flush_block_queue(block);
379 device->state = DASD_STATE_READY;
382 dasd_destroy_partitions(block);
385 block->s2b_shift = 0;
393 static int dasd_state_unfmt_to_basic(struct dasd_device *device)
395 device->state = DASD_STATE_BASIC;
400 * Make the device online and schedule the bottom half to start
401 * the requeueing of requests from the linux request queue to the
405 dasd_state_ready_to_online(struct dasd_device * device)
407 device->state = DASD_STATE_ONLINE;
409 dasd_schedule_block_bh(device->block);
410 if ((device->features & DASD_FEATURE_USERAW)) {
411 kobject_uevent(&disk_to_dev(device->block->gdp)->kobj,
415 disk_uevent(device->block->bdev_handle->bdev->bd_disk,
422 * Stop the requeueing of requests again.
424 static int dasd_state_online_to_ready(struct dasd_device *device)
428 if (device->discipline->online_to_ready) {
429 rc = device->discipline->online_to_ready(device);
434 device->state = DASD_STATE_READY;
435 if (device->block && !(device->features & DASD_FEATURE_USERAW))
436 disk_uevent(device->block->bdev_handle->bdev->bd_disk,
442 * Device startup state changes.
444 static int dasd_increase_state(struct dasd_device *device)
449 if (device->state == DASD_STATE_NEW &&
450 device->target >= DASD_STATE_KNOWN)
451 rc = dasd_state_new_to_known(device);
454 device->state == DASD_STATE_KNOWN &&
455 device->target >= DASD_STATE_BASIC)
456 rc = dasd_state_known_to_basic(device);
459 device->state == DASD_STATE_BASIC &&
460 device->target >= DASD_STATE_READY)
461 rc = dasd_state_basic_to_ready(device);
464 device->state == DASD_STATE_UNFMT &&
465 device->target > DASD_STATE_UNFMT)
469 device->state == DASD_STATE_READY &&
470 device->target >= DASD_STATE_ONLINE)
471 rc = dasd_state_ready_to_online(device);
477 * Device shutdown state changes.
479 static int dasd_decrease_state(struct dasd_device *device)
484 if (device->state == DASD_STATE_ONLINE &&
485 device->target <= DASD_STATE_READY)
486 rc = dasd_state_online_to_ready(device);
489 device->state == DASD_STATE_READY &&
490 device->target <= DASD_STATE_BASIC)
491 rc = dasd_state_ready_to_basic(device);
494 device->state == DASD_STATE_UNFMT &&
495 device->target <= DASD_STATE_BASIC)
496 rc = dasd_state_unfmt_to_basic(device);
499 device->state == DASD_STATE_BASIC &&
500 device->target <= DASD_STATE_KNOWN)
501 rc = dasd_state_basic_to_known(device);
504 device->state == DASD_STATE_KNOWN &&
505 device->target <= DASD_STATE_NEW)
506 rc = dasd_state_known_to_new(device);
512 * This is the main startup/shutdown routine.
514 static void dasd_change_state(struct dasd_device *device)
518 if (device->state == device->target)
519 /* Already where we want to go today... */
521 if (device->state < device->target)
522 rc = dasd_increase_state(device);
524 rc = dasd_decrease_state(device);
528 device->target = device->state;
530 /* let user-space know that the device status changed */
531 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
533 if (device->state == device->target)
534 wake_up(&dasd_init_waitq);
538 * Kick starter for devices that did not complete the startup/shutdown
539 * procedure or were sleeping because of a pending state.
540 * dasd_kick_device will schedule a call do do_kick_device to the kernel
543 static void do_kick_device(struct work_struct *work)
545 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
546 mutex_lock(&device->state_mutex);
547 dasd_change_state(device);
548 mutex_unlock(&device->state_mutex);
549 dasd_schedule_device_bh(device);
550 dasd_put_device(device);
553 void dasd_kick_device(struct dasd_device *device)
555 dasd_get_device(device);
556 /* queue call to dasd_kick_device to the kernel event daemon. */
557 if (!schedule_work(&device->kick_work))
558 dasd_put_device(device);
560 EXPORT_SYMBOL(dasd_kick_device);
563 * dasd_reload_device will schedule a call do do_reload_device to the kernel
566 static void do_reload_device(struct work_struct *work)
568 struct dasd_device *device = container_of(work, struct dasd_device,
570 device->discipline->reload(device);
571 dasd_put_device(device);
574 void dasd_reload_device(struct dasd_device *device)
576 dasd_get_device(device);
577 /* queue call to dasd_reload_device to the kernel event daemon. */
578 if (!schedule_work(&device->reload_device))
579 dasd_put_device(device);
581 EXPORT_SYMBOL(dasd_reload_device);
584 * Set the target state for a device and starts the state change.
586 void dasd_set_target_state(struct dasd_device *device, int target)
588 dasd_get_device(device);
589 mutex_lock(&device->state_mutex);
590 /* If we are in probeonly mode stop at DASD_STATE_READY. */
591 if (dasd_probeonly && target > DASD_STATE_READY)
592 target = DASD_STATE_READY;
593 if (device->target != target) {
594 if (device->state == target)
595 wake_up(&dasd_init_waitq);
596 device->target = target;
598 if (device->state != device->target)
599 dasd_change_state(device);
600 mutex_unlock(&device->state_mutex);
601 dasd_put_device(device);
605 * Enable devices with device numbers in [from..to].
607 static inline int _wait_for_device(struct dasd_device *device)
609 return (device->state == device->target);
612 void dasd_enable_device(struct dasd_device *device)
614 dasd_set_target_state(device, DASD_STATE_ONLINE);
615 if (device->state <= DASD_STATE_KNOWN)
616 /* No discipline for device found. */
617 dasd_set_target_state(device, DASD_STATE_NEW);
618 /* Now wait for the devices to come up. */
619 wait_event(dasd_init_waitq, _wait_for_device(device));
621 dasd_reload_device(device);
622 if (device->discipline->kick_validate)
623 device->discipline->kick_validate(device);
625 EXPORT_SYMBOL(dasd_enable_device);
628 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
631 unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
633 #ifdef CONFIG_DASD_PROFILE
634 struct dasd_profile dasd_global_profile = {
635 .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
637 static struct dentry *dasd_debugfs_global_entry;
640 * Add profiling information for cqr before execution.
642 static void dasd_profile_start(struct dasd_block *block,
643 struct dasd_ccw_req *cqr,
647 unsigned int counter;
648 struct dasd_device *device;
650 /* count the length of the chanq for statistics */
652 if (dasd_global_profile_level || block->profile.data)
653 list_for_each(l, &block->ccw_queue)
657 spin_lock(&dasd_global_profile.lock);
658 if (dasd_global_profile.data) {
659 dasd_global_profile.data->dasd_io_nr_req[counter]++;
660 if (rq_data_dir(req) == READ)
661 dasd_global_profile.data->dasd_read_nr_req[counter]++;
663 spin_unlock(&dasd_global_profile.lock);
665 spin_lock(&block->profile.lock);
666 if (block->profile.data) {
667 block->profile.data->dasd_io_nr_req[counter]++;
668 if (rq_data_dir(req) == READ)
669 block->profile.data->dasd_read_nr_req[counter]++;
671 spin_unlock(&block->profile.lock);
674 * We count the request for the start device, even though it may run on
675 * some other device due to error recovery. This way we make sure that
676 * we count each request only once.
678 device = cqr->startdev;
679 if (device->profile.data) {
680 counter = 1; /* request is not yet queued on the start device */
681 list_for_each(l, &device->ccw_queue)
685 spin_lock(&device->profile.lock);
686 if (device->profile.data) {
687 device->profile.data->dasd_io_nr_req[counter]++;
688 if (rq_data_dir(req) == READ)
689 device->profile.data->dasd_read_nr_req[counter]++;
691 spin_unlock(&device->profile.lock);
695 * Add profiling information for cqr after execution.
698 #define dasd_profile_counter(value, index) \
700 for (index = 0; index < 31 && value >> (2+index); index++) \
704 static void dasd_profile_end_add_data(struct dasd_profile_info *data,
717 /* in case of an overflow, reset the whole profile */
718 if (data->dasd_io_reqs == UINT_MAX) {
719 memset(data, 0, sizeof(*data));
720 ktime_get_real_ts64(&data->starttod);
722 data->dasd_io_reqs++;
723 data->dasd_io_sects += sectors;
725 data->dasd_io_alias++;
729 data->dasd_io_secs[sectors_ind]++;
730 data->dasd_io_times[tottime_ind]++;
731 data->dasd_io_timps[tottimeps_ind]++;
732 data->dasd_io_time1[strtime_ind]++;
733 data->dasd_io_time2[irqtime_ind]++;
734 data->dasd_io_time2ps[irqtimeps_ind]++;
735 data->dasd_io_time3[endtime_ind]++;
738 data->dasd_read_reqs++;
739 data->dasd_read_sects += sectors;
741 data->dasd_read_alias++;
743 data->dasd_read_tpm++;
744 data->dasd_read_secs[sectors_ind]++;
745 data->dasd_read_times[tottime_ind]++;
746 data->dasd_read_time1[strtime_ind]++;
747 data->dasd_read_time2[irqtime_ind]++;
748 data->dasd_read_time3[endtime_ind]++;
752 static void dasd_profile_end(struct dasd_block *block,
753 struct dasd_ccw_req *cqr,
756 unsigned long strtime, irqtime, endtime, tottime;
757 unsigned long tottimeps, sectors;
758 struct dasd_device *device;
759 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
760 int irqtime_ind, irqtimeps_ind, endtime_ind;
761 struct dasd_profile_info *data;
763 device = cqr->startdev;
764 if (!(dasd_global_profile_level ||
765 block->profile.data ||
766 device->profile.data))
769 sectors = blk_rq_sectors(req);
770 if (!cqr->buildclk || !cqr->startclk ||
771 !cqr->stopclk || !cqr->endclk ||
775 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
776 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
777 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
778 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
779 tottimeps = tottime / sectors;
781 dasd_profile_counter(sectors, sectors_ind);
782 dasd_profile_counter(tottime, tottime_ind);
783 dasd_profile_counter(tottimeps, tottimeps_ind);
784 dasd_profile_counter(strtime, strtime_ind);
785 dasd_profile_counter(irqtime, irqtime_ind);
786 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
787 dasd_profile_counter(endtime, endtime_ind);
789 spin_lock(&dasd_global_profile.lock);
790 if (dasd_global_profile.data) {
791 data = dasd_global_profile.data;
792 data->dasd_sum_times += tottime;
793 data->dasd_sum_time_str += strtime;
794 data->dasd_sum_time_irq += irqtime;
795 data->dasd_sum_time_end += endtime;
796 dasd_profile_end_add_data(dasd_global_profile.data,
797 cqr->startdev != block->base,
799 rq_data_dir(req) == READ,
800 sectors, sectors_ind, tottime_ind,
801 tottimeps_ind, strtime_ind,
802 irqtime_ind, irqtimeps_ind,
805 spin_unlock(&dasd_global_profile.lock);
807 spin_lock(&block->profile.lock);
808 if (block->profile.data) {
809 data = block->profile.data;
810 data->dasd_sum_times += tottime;
811 data->dasd_sum_time_str += strtime;
812 data->dasd_sum_time_irq += irqtime;
813 data->dasd_sum_time_end += endtime;
814 dasd_profile_end_add_data(block->profile.data,
815 cqr->startdev != block->base,
817 rq_data_dir(req) == READ,
818 sectors, sectors_ind, tottime_ind,
819 tottimeps_ind, strtime_ind,
820 irqtime_ind, irqtimeps_ind,
823 spin_unlock(&block->profile.lock);
825 spin_lock(&device->profile.lock);
826 if (device->profile.data) {
827 data = device->profile.data;
828 data->dasd_sum_times += tottime;
829 data->dasd_sum_time_str += strtime;
830 data->dasd_sum_time_irq += irqtime;
831 data->dasd_sum_time_end += endtime;
832 dasd_profile_end_add_data(device->profile.data,
833 cqr->startdev != block->base,
835 rq_data_dir(req) == READ,
836 sectors, sectors_ind, tottime_ind,
837 tottimeps_ind, strtime_ind,
838 irqtime_ind, irqtimeps_ind,
841 spin_unlock(&device->profile.lock);
844 void dasd_profile_reset(struct dasd_profile *profile)
846 struct dasd_profile_info *data;
848 spin_lock_bh(&profile->lock);
849 data = profile->data;
851 spin_unlock_bh(&profile->lock);
854 memset(data, 0, sizeof(*data));
855 ktime_get_real_ts64(&data->starttod);
856 spin_unlock_bh(&profile->lock);
859 int dasd_profile_on(struct dasd_profile *profile)
861 struct dasd_profile_info *data;
863 data = kzalloc(sizeof(*data), GFP_KERNEL);
866 spin_lock_bh(&profile->lock);
868 spin_unlock_bh(&profile->lock);
872 ktime_get_real_ts64(&data->starttod);
873 profile->data = data;
874 spin_unlock_bh(&profile->lock);
878 void dasd_profile_off(struct dasd_profile *profile)
880 spin_lock_bh(&profile->lock);
881 kfree(profile->data);
882 profile->data = NULL;
883 spin_unlock_bh(&profile->lock);
886 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
890 buffer = vmalloc(user_len + 1);
892 return ERR_PTR(-ENOMEM);
893 if (copy_from_user(buffer, user_buf, user_len) != 0) {
895 return ERR_PTR(-EFAULT);
897 /* got the string, now strip linefeed. */
898 if (buffer[user_len - 1] == '\n')
899 buffer[user_len - 1] = 0;
901 buffer[user_len] = 0;
905 static ssize_t dasd_stats_write(struct file *file,
906 const char __user *user_buf,
907 size_t user_len, loff_t *pos)
911 struct seq_file *m = (struct seq_file *)file->private_data;
912 struct dasd_profile *prof = m->private;
914 if (user_len > 65536)
916 buffer = dasd_get_user_string(user_buf, user_len);
918 return PTR_ERR(buffer);
920 str = skip_spaces(buffer);
922 if (strncmp(str, "reset", 5) == 0) {
923 dasd_profile_reset(prof);
924 } else if (strncmp(str, "on", 2) == 0) {
925 rc = dasd_profile_on(prof);
929 if (prof == &dasd_global_profile) {
930 dasd_profile_reset(prof);
931 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
933 } else if (strncmp(str, "off", 3) == 0) {
934 if (prof == &dasd_global_profile)
935 dasd_global_profile_level = DASD_PROFILE_OFF;
936 dasd_profile_off(prof);
944 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
948 for (i = 0; i < 32; i++)
949 seq_printf(m, "%u ", array[i]);
953 static void dasd_stats_seq_print(struct seq_file *m,
954 struct dasd_profile_info *data)
956 seq_printf(m, "start_time %lld.%09ld\n",
957 (s64)data->starttod.tv_sec, data->starttod.tv_nsec);
958 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
959 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
960 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
961 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
962 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
963 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
964 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
965 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
966 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
967 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
968 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
969 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
970 seq_puts(m, "histogram_sectors ");
971 dasd_stats_array(m, data->dasd_io_secs);
972 seq_puts(m, "histogram_io_times ");
973 dasd_stats_array(m, data->dasd_io_times);
974 seq_puts(m, "histogram_io_times_weighted ");
975 dasd_stats_array(m, data->dasd_io_timps);
976 seq_puts(m, "histogram_time_build_to_ssch ");
977 dasd_stats_array(m, data->dasd_io_time1);
978 seq_puts(m, "histogram_time_ssch_to_irq ");
979 dasd_stats_array(m, data->dasd_io_time2);
980 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
981 dasd_stats_array(m, data->dasd_io_time2ps);
982 seq_puts(m, "histogram_time_irq_to_end ");
983 dasd_stats_array(m, data->dasd_io_time3);
984 seq_puts(m, "histogram_ccw_queue_length ");
985 dasd_stats_array(m, data->dasd_io_nr_req);
986 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
987 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
988 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
989 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
990 seq_puts(m, "histogram_read_sectors ");
991 dasd_stats_array(m, data->dasd_read_secs);
992 seq_puts(m, "histogram_read_times ");
993 dasd_stats_array(m, data->dasd_read_times);
994 seq_puts(m, "histogram_read_time_build_to_ssch ");
995 dasd_stats_array(m, data->dasd_read_time1);
996 seq_puts(m, "histogram_read_time_ssch_to_irq ");
997 dasd_stats_array(m, data->dasd_read_time2);
998 seq_puts(m, "histogram_read_time_irq_to_end ");
999 dasd_stats_array(m, data->dasd_read_time3);
1000 seq_puts(m, "histogram_read_ccw_queue_length ");
1001 dasd_stats_array(m, data->dasd_read_nr_req);
1004 static int dasd_stats_show(struct seq_file *m, void *v)
1006 struct dasd_profile *profile;
1007 struct dasd_profile_info *data;
1009 profile = m->private;
1010 spin_lock_bh(&profile->lock);
1011 data = profile->data;
1013 spin_unlock_bh(&profile->lock);
1014 seq_puts(m, "disabled\n");
1017 dasd_stats_seq_print(m, data);
1018 spin_unlock_bh(&profile->lock);
1022 static int dasd_stats_open(struct inode *inode, struct file *file)
1024 struct dasd_profile *profile = inode->i_private;
1025 return single_open(file, dasd_stats_show, profile);
1028 static const struct file_operations dasd_stats_raw_fops = {
1029 .owner = THIS_MODULE,
1030 .open = dasd_stats_open,
1032 .llseek = seq_lseek,
1033 .release = single_release,
1034 .write = dasd_stats_write,
1037 static void dasd_profile_init(struct dasd_profile *profile,
1038 struct dentry *base_dentry)
1045 profile->dentry = NULL;
1046 profile->data = NULL;
1047 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1048 pde = debugfs_create_file("statistics", mode, base_dentry,
1049 profile, &dasd_stats_raw_fops);
1050 if (pde && !IS_ERR(pde))
1051 profile->dentry = pde;
1055 static void dasd_profile_exit(struct dasd_profile *profile)
1057 dasd_profile_off(profile);
1058 debugfs_remove(profile->dentry);
1059 profile->dentry = NULL;
1062 static void dasd_statistics_removeroot(void)
1064 dasd_global_profile_level = DASD_PROFILE_OFF;
1065 dasd_profile_exit(&dasd_global_profile);
1066 debugfs_remove(dasd_debugfs_global_entry);
1067 debugfs_remove(dasd_debugfs_root_entry);
1070 static void dasd_statistics_createroot(void)
1074 dasd_debugfs_root_entry = NULL;
1075 pde = debugfs_create_dir("dasd", NULL);
1076 if (!pde || IS_ERR(pde))
1078 dasd_debugfs_root_entry = pde;
1079 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1080 if (!pde || IS_ERR(pde))
1082 dasd_debugfs_global_entry = pde;
1083 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
1087 DBF_EVENT(DBF_ERR, "%s",
1088 "Creation of the dasd debugfs interface failed");
1089 dasd_statistics_removeroot();
1094 #define dasd_profile_start(block, cqr, req) do {} while (0)
1095 #define dasd_profile_end(block, cqr, req) do {} while (0)
1097 static void dasd_statistics_createroot(void)
1102 static void dasd_statistics_removeroot(void)
1107 int dasd_stats_generic_show(struct seq_file *m, void *v)
1109 seq_puts(m, "Statistics are not activated in this kernel\n");
1113 static void dasd_profile_init(struct dasd_profile *profile,
1114 struct dentry *base_dentry)
1119 static void dasd_profile_exit(struct dasd_profile *profile)
1124 int dasd_profile_on(struct dasd_profile *profile)
1129 #endif /* CONFIG_DASD_PROFILE */
1131 static int dasd_hosts_show(struct seq_file *m, void *v)
1133 struct dasd_device *device;
1134 int rc = -EOPNOTSUPP;
1136 device = m->private;
1137 dasd_get_device(device);
1139 if (device->discipline->hosts_print)
1140 rc = device->discipline->hosts_print(device, m);
1142 dasd_put_device(device);
1146 DEFINE_SHOW_ATTRIBUTE(dasd_hosts);
1148 static void dasd_hosts_exit(struct dasd_device *device)
1150 debugfs_remove(device->hosts_dentry);
1151 device->hosts_dentry = NULL;
1154 static void dasd_hosts_init(struct dentry *base_dentry,
1155 struct dasd_device *device)
1163 mode = S_IRUSR | S_IFREG;
1164 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1165 device, &dasd_hosts_fops);
1166 if (pde && !IS_ERR(pde))
1167 device->hosts_dentry = pde;
1170 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, int datasize,
1171 struct dasd_device *device,
1172 struct dasd_ccw_req *cqr)
1174 unsigned long flags;
1179 size += cplength * sizeof(struct ccw1);
1183 size += (sizeof(*cqr) + 7L) & -8L;
1185 spin_lock_irqsave(&device->mem_lock, flags);
1186 data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size);
1187 spin_unlock_irqrestore(&device->mem_lock, flags);
1189 return ERR_PTR(-ENOMEM);
1191 cqr = (void *) data;
1192 data += (sizeof(*cqr) + 7L) & -8L;
1194 memset(cqr, 0, sizeof(*cqr));
1195 cqr->mem_chunk = chunk;
1198 data += cplength * sizeof(struct ccw1);
1199 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1203 memset(cqr->data, 0, datasize);
1206 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1207 dasd_get_device(device);
1210 EXPORT_SYMBOL(dasd_smalloc_request);
1212 struct dasd_ccw_req *dasd_fmalloc_request(int magic, int cplength,
1214 struct dasd_device *device)
1216 struct dasd_ccw_req *cqr;
1217 unsigned long flags;
1221 cqr_size = (sizeof(*cqr) + 7L) & -8L;
1224 size += cplength * sizeof(struct ccw1);
1228 spin_lock_irqsave(&device->mem_lock, flags);
1229 cqr = dasd_alloc_chunk(&device->ese_chunks, size);
1230 spin_unlock_irqrestore(&device->mem_lock, flags);
1232 return ERR_PTR(-ENOMEM);
1233 memset(cqr, 0, sizeof(*cqr));
1234 data = (char *)cqr + cqr_size;
1238 data += cplength * sizeof(struct ccw1);
1239 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1244 memset(cqr->data, 0, datasize);
1248 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1249 dasd_get_device(device);
1253 EXPORT_SYMBOL(dasd_fmalloc_request);
1255 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1257 unsigned long flags;
1259 spin_lock_irqsave(&device->mem_lock, flags);
1260 dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk);
1261 spin_unlock_irqrestore(&device->mem_lock, flags);
1262 dasd_put_device(device);
1264 EXPORT_SYMBOL(dasd_sfree_request);
1266 void dasd_ffree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1268 unsigned long flags;
1270 spin_lock_irqsave(&device->mem_lock, flags);
1271 dasd_free_chunk(&device->ese_chunks, cqr);
1272 spin_unlock_irqrestore(&device->mem_lock, flags);
1273 dasd_put_device(device);
1275 EXPORT_SYMBOL(dasd_ffree_request);
1278 * Check discipline magic in cqr.
1280 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1282 struct dasd_device *device;
1286 device = cqr->startdev;
1287 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1288 DBF_DEV_EVENT(DBF_WARNING, device,
1289 " dasd_ccw_req 0x%08x magic doesn't match"
1290 " discipline 0x%08x",
1292 *(unsigned int *) device->discipline->name);
1299 * Terminate the current i/o and set the request to clear_pending.
1300 * Timer keeps device runnig.
1301 * ccw_device_clear can fail if the i/o subsystem
1304 int dasd_term_IO(struct dasd_ccw_req *cqr)
1306 struct dasd_device *device;
1308 char errorstring[ERRORLENGTH];
1311 rc = dasd_check_cqr(cqr);
1315 device = (struct dasd_device *) cqr->startdev;
1316 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1317 rc = ccw_device_clear(device->cdev, (long) cqr);
1319 case 0: /* termination successful */
1320 cqr->status = DASD_CQR_CLEAR_PENDING;
1321 cqr->stopclk = get_tod_clock();
1323 DBF_DEV_EVENT(DBF_DEBUG, device,
1324 "terminate cqr %p successful",
1328 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1329 "device gone, retry");
1333 * device not valid so no I/O could be running
1334 * handle CQR as termination successful
1336 cqr->status = DASD_CQR_CLEARED;
1337 cqr->stopclk = get_tod_clock();
1339 /* no retries for invalid devices */
1341 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1342 "EINVAL, handle as terminated");
1343 /* fake rc to success */
1347 /* internal error 10 - unknown rc*/
1348 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1349 dev_err(&device->cdev->dev, "An error occurred in the "
1350 "DASD device driver, reason=%s\n", errorstring);
1356 dasd_schedule_device_bh(device);
1359 EXPORT_SYMBOL(dasd_term_IO);
1362 * Start the i/o. This start_IO can fail if the channel is really busy.
1363 * In that case set up a timer to start the request later.
1365 int dasd_start_IO(struct dasd_ccw_req *cqr)
1367 struct dasd_device *device;
1369 char errorstring[ERRORLENGTH];
1372 rc = dasd_check_cqr(cqr);
1377 device = (struct dasd_device *) cqr->startdev;
1379 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1380 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1381 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1382 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1383 "because of stolen lock", cqr);
1384 cqr->status = DASD_CQR_ERROR;
1385 cqr->intrc = -EPERM;
1388 if (cqr->retries < 0) {
1389 /* internal error 14 - start_IO run out of retries */
1390 sprintf(errorstring, "14 %p", cqr);
1391 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1392 "device driver, reason=%s\n", errorstring);
1393 cqr->status = DASD_CQR_ERROR;
1396 cqr->startclk = get_tod_clock();
1397 cqr->starttime = jiffies;
1399 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1400 cqr->lpm &= dasd_path_get_opm(device);
1402 cqr->lpm = dasd_path_get_opm(device);
1405 * remember the amount of formatted tracks to prevent double format on
1409 cqr->trkcount = atomic_read(&cqr->block->trkcount);
1411 if (cqr->cpmode == 1) {
1412 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1413 (long) cqr, cqr->lpm);
1415 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1416 (long) cqr, cqr->lpm, 0);
1420 cqr->status = DASD_CQR_IN_IO;
1423 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1424 "start_IO: device busy, retry later");
1427 /* -EACCES indicates that the request used only a subset of the
1428 * available paths and all these paths are gone. If the lpm of
1429 * this request was only a subset of the opm (e.g. the ppm) then
1430 * we just do a retry with all available paths.
1431 * If we already use the full opm, something is amiss, and we
1432 * need a full path verification.
1434 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1435 DBF_DEV_EVENT(DBF_WARNING, device,
1436 "start_IO: selected paths gone (%x)",
1438 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1439 cqr->lpm = dasd_path_get_opm(device);
1440 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1441 "start_IO: selected paths gone,"
1442 " retry on all paths");
1444 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1445 "start_IO: all paths in opm gone,"
1446 " do path verification");
1447 dasd_generic_last_path_gone(device);
1448 dasd_path_no_path(device);
1449 dasd_path_set_tbvpm(device,
1450 ccw_device_get_path_mask(
1455 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1456 "start_IO: -ENODEV device gone, retry");
1457 /* this is equivalent to CC=3 for SSCH report this to EER */
1458 dasd_handle_autoquiesce(device, cqr, DASD_EER_STARTIO);
1461 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1462 "start_IO: -EIO device gone, retry");
1465 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1466 "start_IO: -EINVAL device currently "
1470 /* internal error 11 - unknown rc */
1471 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1472 dev_err(&device->cdev->dev,
1473 "An error occurred in the DASD device driver, "
1474 "reason=%s\n", errorstring);
1481 EXPORT_SYMBOL(dasd_start_IO);
1484 * Timeout function for dasd devices. This is used for different purposes
1485 * 1) missing interrupt handler for normal operation
1486 * 2) delayed start of request where start_IO failed with -EBUSY
1487 * 3) timeout for missing state change interrupts
1488 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1489 * DASD_CQR_QUEUED for 2) and 3).
1491 static void dasd_device_timeout(struct timer_list *t)
1493 unsigned long flags;
1494 struct dasd_device *device;
1496 device = from_timer(device, t, timer);
1497 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1498 /* re-activate request queue */
1499 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1500 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1501 dasd_schedule_device_bh(device);
1505 * Setup timeout for a device in jiffies.
1507 void dasd_device_set_timer(struct dasd_device *device, int expires)
1510 del_timer(&device->timer);
1512 mod_timer(&device->timer, jiffies + expires);
1514 EXPORT_SYMBOL(dasd_device_set_timer);
1517 * Clear timeout for a device.
1519 void dasd_device_clear_timer(struct dasd_device *device)
1521 del_timer(&device->timer);
1523 EXPORT_SYMBOL(dasd_device_clear_timer);
1525 static void dasd_handle_killed_request(struct ccw_device *cdev,
1526 unsigned long intparm)
1528 struct dasd_ccw_req *cqr;
1529 struct dasd_device *device;
1533 cqr = (struct dasd_ccw_req *) intparm;
1534 if (cqr->status != DASD_CQR_IN_IO) {
1535 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1536 "invalid status in handle_killed_request: "
1537 "%02x", cqr->status);
1541 device = dasd_device_from_cdev_locked(cdev);
1542 if (IS_ERR(device)) {
1543 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1544 "unable to get device from cdev");
1548 if (!cqr->startdev ||
1549 device != cqr->startdev ||
1550 strncmp(cqr->startdev->discipline->ebcname,
1551 (char *) &cqr->magic, 4)) {
1552 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1553 "invalid device in request");
1554 dasd_put_device(device);
1558 /* Schedule request to be retried. */
1559 cqr->status = DASD_CQR_QUEUED;
1561 dasd_device_clear_timer(device);
1562 dasd_schedule_device_bh(device);
1563 dasd_put_device(device);
1566 void dasd_generic_handle_state_change(struct dasd_device *device)
1568 /* First of all start sense subsystem status request. */
1569 dasd_eer_snss(device);
1571 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1572 dasd_schedule_device_bh(device);
1573 if (device->block) {
1574 dasd_schedule_block_bh(device->block);
1575 if (device->block->gdp)
1576 blk_mq_run_hw_queues(device->block->gdp->queue, true);
1579 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
1581 static int dasd_check_hpf_error(struct irb *irb)
1583 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1584 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1585 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1588 static int dasd_ese_needs_format(struct dasd_block *block, struct irb *irb)
1590 struct dasd_device *device = NULL;
1595 device = block->base;
1596 if (!device || !device->discipline->is_ese)
1598 if (!device->discipline->is_ese(device))
1601 sense = dasd_get_sense(irb);
1605 return !!(sense[1] & SNS1_NO_REC_FOUND) ||
1606 !!(sense[1] & SNS1_FILE_PROTECTED) ||
1607 scsw_cstat(&irb->scsw) == SCHN_STAT_INCORR_LEN;
1610 static int dasd_ese_oos_cond(u8 *sense)
1612 return sense[0] & SNS0_EQUIPMENT_CHECK &&
1613 sense[1] & SNS1_PERM_ERR &&
1614 sense[1] & SNS1_WRITE_INHIBITED &&
1619 * Interrupt handler for "normal" ssch-io based dasd devices.
1621 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1624 struct dasd_ccw_req *cqr, *next, *fcqr;
1625 struct dasd_device *device;
1627 int nrf_suppressed = 0;
1628 int fp_suppressed = 0;
1629 struct request *req;
1633 cqr = (struct dasd_ccw_req *) intparm;
1635 switch (PTR_ERR(irb)) {
1637 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1638 device = cqr->startdev;
1639 cqr->status = DASD_CQR_CLEARED;
1640 dasd_device_clear_timer(device);
1641 wake_up(&dasd_flush_wq);
1642 dasd_schedule_device_bh(device);
1647 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1648 "request timed out\n", __func__);
1651 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1652 "unknown error %ld\n", __func__,
1655 dasd_handle_killed_request(cdev, intparm);
1659 now = get_tod_clock();
1660 /* check for conditions that should be handled immediately */
1662 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1663 scsw_cstat(&irb->scsw) == 0)) {
1665 memcpy(&cqr->irb, irb, sizeof(*irb));
1666 device = dasd_device_from_cdev_locked(cdev);
1669 /* ignore unsolicited interrupts for DIAG discipline */
1670 if (device->discipline == dasd_diag_discipline_pointer) {
1671 dasd_put_device(device);
1676 * In some cases 'File Protected' or 'No Record Found' errors
1677 * might be expected and debug log messages for the
1678 * corresponding interrupts shouldn't be written then.
1679 * Check if either of the according suppress bits is set.
1681 sense = dasd_get_sense(irb);
1683 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1684 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1685 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1686 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1689 * Extent pool probably out-of-space.
1690 * Stop device and check exhaust level.
1692 if (dasd_ese_oos_cond(sense)) {
1693 dasd_generic_space_exhaust(device, cqr);
1694 device->discipline->ext_pool_exhaust(device, cqr);
1695 dasd_put_device(device);
1699 if (!(fp_suppressed || nrf_suppressed))
1700 device->discipline->dump_sense_dbf(device, irb, "int");
1702 if (device->features & DASD_FEATURE_ERPLOG)
1703 device->discipline->dump_sense(device, cqr, irb);
1704 device->discipline->check_for_device_change(device, cqr, irb);
1705 dasd_put_device(device);
1708 /* check for attention message */
1709 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1710 device = dasd_device_from_cdev_locked(cdev);
1711 if (!IS_ERR(device)) {
1712 device->discipline->check_attention(device,
1713 irb->esw.esw1.lpum);
1714 dasd_put_device(device);
1721 device = (struct dasd_device *) cqr->startdev;
1723 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1724 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1725 "invalid device in request");
1729 if (dasd_ese_needs_format(cqr->block, irb)) {
1730 req = dasd_get_callback_data(cqr);
1732 cqr->status = DASD_CQR_ERROR;
1735 if (rq_data_dir(req) == READ) {
1736 device->discipline->ese_read(cqr, irb);
1737 cqr->status = DASD_CQR_SUCCESS;
1739 dasd_device_clear_timer(device);
1740 dasd_schedule_device_bh(device);
1743 fcqr = device->discipline->ese_format(device, cqr, irb);
1745 if (PTR_ERR(fcqr) == -EINVAL) {
1746 cqr->status = DASD_CQR_ERROR;
1750 * If we can't format now, let the request go
1751 * one extra round. Maybe we can format later.
1753 cqr->status = DASD_CQR_QUEUED;
1754 dasd_schedule_device_bh(device);
1757 fcqr->status = DASD_CQR_QUEUED;
1758 cqr->status = DASD_CQR_QUEUED;
1759 list_add(&fcqr->devlist, &device->ccw_queue);
1760 dasd_schedule_device_bh(device);
1765 /* Check for clear pending */
1766 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1767 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1768 cqr->status = DASD_CQR_CLEARED;
1769 dasd_device_clear_timer(device);
1770 wake_up(&dasd_flush_wq);
1771 dasd_schedule_device_bh(device);
1775 /* check status - the request might have been killed by dyn detach */
1776 if (cqr->status != DASD_CQR_IN_IO) {
1777 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1778 "status %02x", dev_name(&cdev->dev), cqr->status);
1784 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1785 scsw_cstat(&irb->scsw) == 0) {
1786 /* request was completed successfully */
1787 cqr->status = DASD_CQR_SUCCESS;
1789 /* Start first request on queue if possible -> fast_io. */
1790 if (cqr->devlist.next != &device->ccw_queue) {
1791 next = list_entry(cqr->devlist.next,
1792 struct dasd_ccw_req, devlist);
1794 } else { /* error */
1795 /* check for HPF error
1796 * call discipline function to requeue all requests
1797 * and disable HPF accordingly
1799 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1800 device->discipline->handle_hpf_error)
1801 device->discipline->handle_hpf_error(device, irb);
1803 * If we don't want complex ERP for this request, then just
1804 * reset this and retry it in the fastpath
1806 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1808 if (cqr->lpm == dasd_path_get_opm(device))
1809 DBF_DEV_EVENT(DBF_DEBUG, device,
1810 "default ERP in fastpath "
1811 "(%i retries left)",
1813 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1814 cqr->lpm = dasd_path_get_opm(device);
1815 cqr->status = DASD_CQR_QUEUED;
1818 cqr->status = DASD_CQR_ERROR;
1820 if (next && (next->status == DASD_CQR_QUEUED) &&
1821 (!device->stopped)) {
1822 if (device->discipline->start_IO(next) == 0)
1823 expires = next->expires;
1826 dasd_device_set_timer(device, expires);
1828 dasd_device_clear_timer(device);
1829 dasd_schedule_device_bh(device);
1831 EXPORT_SYMBOL(dasd_int_handler);
1833 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1835 struct dasd_device *device;
1837 device = dasd_device_from_cdev_locked(cdev);
1841 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1842 device->state != device->target ||
1843 !device->discipline->check_for_device_change){
1844 dasd_put_device(device);
1847 if (device->discipline->dump_sense_dbf)
1848 device->discipline->dump_sense_dbf(device, irb, "uc");
1849 device->discipline->check_for_device_change(device, NULL, irb);
1850 dasd_put_device(device);
1852 return UC_TODO_RETRY;
1854 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1857 * If we have an error on a dasd_block layer request then we cancel
1858 * and return all further requests from the same dasd_block as well.
1860 static void __dasd_device_recovery(struct dasd_device *device,
1861 struct dasd_ccw_req *ref_cqr)
1863 struct list_head *l, *n;
1864 struct dasd_ccw_req *cqr;
1867 * only requeue request that came from the dasd_block layer
1869 if (!ref_cqr->block)
1872 list_for_each_safe(l, n, &device->ccw_queue) {
1873 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1874 if (cqr->status == DASD_CQR_QUEUED &&
1875 ref_cqr->block == cqr->block) {
1876 cqr->status = DASD_CQR_CLEARED;
1882 * Remove those ccw requests from the queue that need to be returned
1883 * to the upper layer.
1885 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1886 struct list_head *final_queue)
1888 struct list_head *l, *n;
1889 struct dasd_ccw_req *cqr;
1891 /* Process request with final status. */
1892 list_for_each_safe(l, n, &device->ccw_queue) {
1893 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1895 /* Skip any non-final request. */
1896 if (cqr->status == DASD_CQR_QUEUED ||
1897 cqr->status == DASD_CQR_IN_IO ||
1898 cqr->status == DASD_CQR_CLEAR_PENDING)
1900 if (cqr->status == DASD_CQR_ERROR) {
1901 __dasd_device_recovery(device, cqr);
1903 /* Rechain finished requests to final queue */
1904 list_move_tail(&cqr->devlist, final_queue);
1908 static void __dasd_process_cqr(struct dasd_device *device,
1909 struct dasd_ccw_req *cqr)
1911 char errorstring[ERRORLENGTH];
1913 switch (cqr->status) {
1914 case DASD_CQR_SUCCESS:
1915 cqr->status = DASD_CQR_DONE;
1917 case DASD_CQR_ERROR:
1918 cqr->status = DASD_CQR_NEED_ERP;
1920 case DASD_CQR_CLEARED:
1921 cqr->status = DASD_CQR_TERMINATED;
1924 /* internal error 12 - wrong cqr status*/
1925 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1926 dev_err(&device->cdev->dev,
1927 "An error occurred in the DASD device driver, "
1928 "reason=%s\n", errorstring);
1932 cqr->callback(cqr, cqr->callback_data);
1936 * the cqrs from the final queue are returned to the upper layer
1937 * by setting a dasd_block state and calling the callback function
1939 static void __dasd_device_process_final_queue(struct dasd_device *device,
1940 struct list_head *final_queue)
1942 struct list_head *l, *n;
1943 struct dasd_ccw_req *cqr;
1944 struct dasd_block *block;
1946 list_for_each_safe(l, n, final_queue) {
1947 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1948 list_del_init(&cqr->devlist);
1951 __dasd_process_cqr(device, cqr);
1953 spin_lock_bh(&block->queue_lock);
1954 __dasd_process_cqr(device, cqr);
1955 spin_unlock_bh(&block->queue_lock);
1961 * check if device should be autoquiesced due to too many timeouts
1963 static void __dasd_device_check_autoquiesce_timeout(struct dasd_device *device,
1964 struct dasd_ccw_req *cqr)
1966 if ((device->default_retries - cqr->retries) >= device->aq_timeouts)
1967 dasd_handle_autoquiesce(device, cqr, DASD_EER_TIMEOUTS);
1971 * Take a look at the first request on the ccw queue and check
1972 * if it reached its expire time. If so, terminate the IO.
1974 static void __dasd_device_check_expire(struct dasd_device *device)
1976 struct dasd_ccw_req *cqr;
1978 if (list_empty(&device->ccw_queue))
1980 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1981 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1982 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1983 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1985 * IO in safe offline processing should not
1986 * run out of retries
1990 if (device->discipline->term_IO(cqr) != 0) {
1991 /* Hmpf, try again in 5 sec */
1992 dev_err(&device->cdev->dev,
1993 "cqr %p timed out (%lus) but cannot be "
1994 "ended, retrying in 5 s\n",
1995 cqr, (cqr->expires/HZ));
1996 cqr->expires += 5*HZ;
1997 dasd_device_set_timer(device, 5*HZ);
1999 dev_err(&device->cdev->dev,
2000 "cqr %p timed out (%lus), %i retries "
2001 "remaining\n", cqr, (cqr->expires/HZ),
2004 __dasd_device_check_autoquiesce_timeout(device, cqr);
2009 * return 1 when device is not eligible for IO
2011 static int __dasd_device_is_unusable(struct dasd_device *device,
2012 struct dasd_ccw_req *cqr)
2014 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_STOPPED_NOSPC);
2016 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2017 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
2019 * dasd is being set offline
2020 * but it is no safe offline where we have to allow I/O
2024 if (device->stopped) {
2025 if (device->stopped & mask) {
2026 /* stopped and CQR will not change that. */
2029 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2030 /* CQR is not able to change device to
2034 /* CQR required to get device operational. */
2040 * Take a look at the first request on the ccw queue and check
2041 * if it needs to be started.
2043 static void __dasd_device_start_head(struct dasd_device *device)
2045 struct dasd_ccw_req *cqr;
2048 if (list_empty(&device->ccw_queue))
2050 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2051 if (cqr->status != DASD_CQR_QUEUED)
2053 /* if device is not usable return request to upper layer */
2054 if (__dasd_device_is_unusable(device, cqr)) {
2055 cqr->intrc = -EAGAIN;
2056 cqr->status = DASD_CQR_CLEARED;
2057 dasd_schedule_device_bh(device);
2061 rc = device->discipline->start_IO(cqr);
2063 dasd_device_set_timer(device, cqr->expires);
2064 else if (rc == -EACCES) {
2065 dasd_schedule_device_bh(device);
2067 /* Hmpf, try again in 1/2 sec */
2068 dasd_device_set_timer(device, 50);
2071 static void __dasd_device_check_path_events(struct dasd_device *device)
2073 __u8 tbvpm, fcsecpm;
2076 tbvpm = dasd_path_get_tbvpm(device);
2077 fcsecpm = dasd_path_get_fcsecpm(device);
2079 if (!tbvpm && !fcsecpm)
2082 if (device->stopped & ~(DASD_STOPPED_DC_WAIT))
2085 dasd_path_clear_all_verify(device);
2086 dasd_path_clear_all_fcsec(device);
2088 rc = device->discipline->pe_handler(device, tbvpm, fcsecpm);
2090 dasd_path_add_tbvpm(device, tbvpm);
2091 dasd_path_add_fcsecpm(device, fcsecpm);
2092 dasd_device_set_timer(device, 50);
2097 * Go through all request on the dasd_device request queue,
2098 * terminate them on the cdev if necessary, and return them to the
2099 * submitting layer via callback.
2101 * Make sure that all 'submitting layers' still exist when
2102 * this function is called!. In other words, when 'device' is a base
2103 * device then all block layer requests must have been removed before
2104 * via dasd_flush_block_queue.
2106 int dasd_flush_device_queue(struct dasd_device *device)
2108 struct dasd_ccw_req *cqr, *n;
2110 struct list_head flush_queue;
2112 INIT_LIST_HEAD(&flush_queue);
2113 spin_lock_irq(get_ccwdev_lock(device->cdev));
2115 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2116 /* Check status and move request to flush_queue */
2117 switch (cqr->status) {
2118 case DASD_CQR_IN_IO:
2119 rc = device->discipline->term_IO(cqr);
2121 /* unable to terminate requeust */
2122 dev_err(&device->cdev->dev,
2123 "Flushing the DASD request queue "
2124 "failed for request %p\n", cqr);
2125 /* stop flush processing */
2129 case DASD_CQR_QUEUED:
2130 cqr->stopclk = get_tod_clock();
2131 cqr->status = DASD_CQR_CLEARED;
2133 default: /* no need to modify the others */
2136 list_move_tail(&cqr->devlist, &flush_queue);
2139 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2141 * After this point all requests must be in state CLEAR_PENDING,
2142 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2143 * one of the others.
2145 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2146 wait_event(dasd_flush_wq,
2147 (cqr->status != DASD_CQR_CLEAR_PENDING));
2149 * Now set each request back to TERMINATED, DONE or NEED_ERP
2150 * and call the callback function of flushed requests
2152 __dasd_device_process_final_queue(device, &flush_queue);
2155 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2158 * Acquire the device lock and process queues for the device.
2160 static void dasd_device_tasklet(unsigned long data)
2162 struct dasd_device *device = (struct dasd_device *) data;
2163 struct list_head final_queue;
2165 atomic_set (&device->tasklet_scheduled, 0);
2166 INIT_LIST_HEAD(&final_queue);
2167 spin_lock_irq(get_ccwdev_lock(device->cdev));
2168 /* Check expire time of first request on the ccw queue. */
2169 __dasd_device_check_expire(device);
2170 /* find final requests on ccw queue */
2171 __dasd_device_process_ccw_queue(device, &final_queue);
2172 __dasd_device_check_path_events(device);
2173 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2174 /* Now call the callback function of requests with final status */
2175 __dasd_device_process_final_queue(device, &final_queue);
2176 spin_lock_irq(get_ccwdev_lock(device->cdev));
2177 /* Now check if the head of the ccw queue needs to be started. */
2178 __dasd_device_start_head(device);
2179 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2180 if (waitqueue_active(&shutdown_waitq))
2181 wake_up(&shutdown_waitq);
2182 dasd_put_device(device);
2186 * Schedules a call to dasd_tasklet over the device tasklet.
2188 void dasd_schedule_device_bh(struct dasd_device *device)
2190 /* Protect against rescheduling. */
2191 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2193 dasd_get_device(device);
2194 tasklet_hi_schedule(&device->tasklet);
2196 EXPORT_SYMBOL(dasd_schedule_device_bh);
2198 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2200 device->stopped |= bits;
2202 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2204 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2206 device->stopped &= ~bits;
2207 if (!device->stopped)
2208 wake_up(&generic_waitq);
2210 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2213 * Queue a request to the head of the device ccw_queue.
2214 * Start the I/O if possible.
2216 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2218 struct dasd_device *device;
2219 unsigned long flags;
2221 device = cqr->startdev;
2222 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2223 cqr->status = DASD_CQR_QUEUED;
2224 list_add(&cqr->devlist, &device->ccw_queue);
2225 /* let the bh start the request to keep them in order */
2226 dasd_schedule_device_bh(device);
2227 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2229 EXPORT_SYMBOL(dasd_add_request_head);
2232 * Queue a request to the tail of the device ccw_queue.
2233 * Start the I/O if possible.
2235 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2237 struct dasd_device *device;
2238 unsigned long flags;
2240 device = cqr->startdev;
2241 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2242 cqr->status = DASD_CQR_QUEUED;
2243 list_add_tail(&cqr->devlist, &device->ccw_queue);
2244 /* let the bh start the request to keep them in order */
2245 dasd_schedule_device_bh(device);
2246 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2248 EXPORT_SYMBOL(dasd_add_request_tail);
2251 * Wakeup helper for the 'sleep_on' functions.
2253 void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2255 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2256 cqr->callback_data = DASD_SLEEPON_END_TAG;
2257 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2258 wake_up(&generic_waitq);
2260 EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
2262 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2264 struct dasd_device *device;
2267 device = cqr->startdev;
2268 spin_lock_irq(get_ccwdev_lock(device->cdev));
2269 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2270 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2275 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2277 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2279 struct dasd_device *device;
2280 dasd_erp_fn_t erp_fn;
2282 if (cqr->status == DASD_CQR_FILLED)
2284 device = cqr->startdev;
2285 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2286 if (cqr->status == DASD_CQR_TERMINATED) {
2287 device->discipline->handle_terminated_request(cqr);
2290 if (cqr->status == DASD_CQR_NEED_ERP) {
2291 erp_fn = device->discipline->erp_action(cqr);
2295 if (cqr->status == DASD_CQR_FAILED)
2296 dasd_log_sense(cqr, &cqr->irb);
2298 __dasd_process_erp(device, cqr);
2305 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2307 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2308 if (cqr->refers) /* erp is not done yet */
2310 return ((cqr->status != DASD_CQR_DONE) &&
2311 (cqr->status != DASD_CQR_FAILED));
2313 return (cqr->status == DASD_CQR_FILLED);
2316 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2318 struct dasd_device *device;
2320 struct list_head ccw_queue;
2321 struct dasd_ccw_req *cqr;
2323 INIT_LIST_HEAD(&ccw_queue);
2324 maincqr->status = DASD_CQR_FILLED;
2325 device = maincqr->startdev;
2326 list_add(&maincqr->blocklist, &ccw_queue);
2327 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2328 cqr = list_first_entry(&ccw_queue,
2329 struct dasd_ccw_req, blocklist)) {
2331 if (__dasd_sleep_on_erp(cqr))
2333 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2335 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2336 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2337 cqr->status = DASD_CQR_FAILED;
2338 cqr->intrc = -EPERM;
2341 /* Non-temporary stop condition will trigger fail fast */
2342 if (device->stopped & ~DASD_STOPPED_PENDING &&
2343 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2344 !dasd_eer_enabled(device) && device->aq_mask == 0) {
2345 cqr->status = DASD_CQR_FAILED;
2346 cqr->intrc = -ENOLINK;
2350 * Don't try to start requests if device is in
2351 * offline processing, it might wait forever
2353 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2354 cqr->status = DASD_CQR_FAILED;
2355 cqr->intrc = -ENODEV;
2359 * Don't try to start requests if device is stopped
2360 * except path verification requests
2362 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2363 if (interruptible) {
2364 rc = wait_event_interruptible(
2365 generic_waitq, !(device->stopped));
2366 if (rc == -ERESTARTSYS) {
2367 cqr->status = DASD_CQR_FAILED;
2368 maincqr->intrc = rc;
2372 wait_event(generic_waitq, !(device->stopped));
2375 cqr->callback = dasd_wakeup_cb;
2377 cqr->callback_data = DASD_SLEEPON_START_TAG;
2378 dasd_add_request_tail(cqr);
2379 if (interruptible) {
2380 rc = wait_event_interruptible(
2381 generic_waitq, _wait_for_wakeup(cqr));
2382 if (rc == -ERESTARTSYS) {
2383 dasd_cancel_req(cqr);
2384 /* wait (non-interruptible) for final status */
2385 wait_event(generic_waitq,
2386 _wait_for_wakeup(cqr));
2387 cqr->status = DASD_CQR_FAILED;
2388 maincqr->intrc = rc;
2392 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2395 maincqr->endclk = get_tod_clock();
2396 if ((maincqr->status != DASD_CQR_DONE) &&
2397 (maincqr->intrc != -ERESTARTSYS))
2398 dasd_log_sense(maincqr, &maincqr->irb);
2399 if (maincqr->status == DASD_CQR_DONE)
2401 else if (maincqr->intrc)
2402 rc = maincqr->intrc;
2408 static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2410 struct dasd_ccw_req *cqr;
2412 list_for_each_entry(cqr, ccw_queue, blocklist) {
2413 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2420 static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2422 struct dasd_device *device;
2423 struct dasd_ccw_req *cqr, *n;
2428 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2429 device = cqr->startdev;
2430 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2433 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2434 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2435 cqr->status = DASD_CQR_FAILED;
2436 cqr->intrc = -EPERM;
2439 /*Non-temporary stop condition will trigger fail fast*/
2440 if (device->stopped & ~DASD_STOPPED_PENDING &&
2441 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2442 !dasd_eer_enabled(device)) {
2443 cqr->status = DASD_CQR_FAILED;
2444 cqr->intrc = -EAGAIN;
2448 /*Don't try to start requests if device is stopped*/
2449 if (interruptible) {
2450 rc = wait_event_interruptible(
2451 generic_waitq, !device->stopped);
2452 if (rc == -ERESTARTSYS) {
2453 cqr->status = DASD_CQR_FAILED;
2458 wait_event(generic_waitq, !(device->stopped));
2461 cqr->callback = dasd_wakeup_cb;
2462 cqr->callback_data = DASD_SLEEPON_START_TAG;
2463 dasd_add_request_tail(cqr);
2466 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2469 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2471 * In some cases the 'File Protected' or 'Incorrect Length'
2472 * error might be expected and error recovery would be
2473 * unnecessary in these cases. Check if the according suppress
2476 sense = dasd_get_sense(&cqr->irb);
2477 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2478 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2480 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2481 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2485 * for alias devices simplify error recovery and
2486 * return to upper layer
2487 * do not skip ERP requests
2489 if (cqr->startdev != cqr->basedev && !cqr->refers &&
2490 (cqr->status == DASD_CQR_TERMINATED ||
2491 cqr->status == DASD_CQR_NEED_ERP))
2494 /* normal recovery for basedev IO */
2495 if (__dasd_sleep_on_erp(cqr))
2496 /* handle erp first */
2504 * Queue a request to the tail of the device ccw_queue and wait for
2507 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2509 return _dasd_sleep_on(cqr, 0);
2511 EXPORT_SYMBOL(dasd_sleep_on);
2514 * Start requests from a ccw_queue and wait for their completion.
2516 int dasd_sleep_on_queue(struct list_head *ccw_queue)
2518 return _dasd_sleep_on_queue(ccw_queue, 0);
2520 EXPORT_SYMBOL(dasd_sleep_on_queue);
2523 * Start requests from a ccw_queue and wait interruptible for their completion.
2525 int dasd_sleep_on_queue_interruptible(struct list_head *ccw_queue)
2527 return _dasd_sleep_on_queue(ccw_queue, 1);
2529 EXPORT_SYMBOL(dasd_sleep_on_queue_interruptible);
2532 * Queue a request to the tail of the device ccw_queue and wait
2533 * interruptible for it's completion.
2535 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2537 return _dasd_sleep_on(cqr, 1);
2539 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2542 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2543 * for eckd devices) the currently running request has to be terminated
2544 * and be put back to status queued, before the special request is added
2545 * to the head of the queue. Then the special request is waited on normally.
2547 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2549 struct dasd_ccw_req *cqr;
2552 if (list_empty(&device->ccw_queue))
2554 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2555 rc = device->discipline->term_IO(cqr);
2558 * CQR terminated because a more important request is pending.
2559 * Undo decreasing of retry counter because this is
2560 * not an error case.
2566 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2568 struct dasd_device *device;
2571 device = cqr->startdev;
2572 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2573 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2574 cqr->status = DASD_CQR_FAILED;
2575 cqr->intrc = -EPERM;
2578 spin_lock_irq(get_ccwdev_lock(device->cdev));
2579 rc = _dasd_term_running_cqr(device);
2581 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2584 cqr->callback = dasd_wakeup_cb;
2585 cqr->callback_data = DASD_SLEEPON_START_TAG;
2586 cqr->status = DASD_CQR_QUEUED;
2588 * add new request as second
2589 * first the terminated cqr needs to be finished
2591 list_add(&cqr->devlist, device->ccw_queue.next);
2593 /* let the bh start the request to keep them in order */
2594 dasd_schedule_device_bh(device);
2596 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2598 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2600 if (cqr->status == DASD_CQR_DONE)
2602 else if (cqr->intrc)
2608 dasd_schedule_device_bh(device);
2610 dasd_schedule_block_bh(device->block);
2614 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2617 * Cancels a request that was started with dasd_sleep_on_req.
2618 * This is useful to timeout requests. The request will be
2619 * terminated if it is currently in i/o.
2620 * Returns 0 if request termination was successful
2621 * negative error code if termination failed
2622 * Cancellation of a request is an asynchronous operation! The calling
2623 * function has to wait until the request is properly returned via callback.
2625 static int __dasd_cancel_req(struct dasd_ccw_req *cqr)
2627 struct dasd_device *device = cqr->startdev;
2630 switch (cqr->status) {
2631 case DASD_CQR_QUEUED:
2632 /* request was not started - just set to cleared */
2633 cqr->status = DASD_CQR_CLEARED;
2635 case DASD_CQR_IN_IO:
2636 /* request in IO - terminate IO and release again */
2637 rc = device->discipline->term_IO(cqr);
2639 dev_err(&device->cdev->dev,
2640 "Cancelling request %p failed with rc=%d\n",
2643 cqr->stopclk = get_tod_clock();
2646 default: /* already finished or clear pending - do nothing */
2649 dasd_schedule_device_bh(device);
2653 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2655 struct dasd_device *device = cqr->startdev;
2656 unsigned long flags;
2659 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2660 rc = __dasd_cancel_req(cqr);
2661 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2666 * SECTION: Operations of the dasd_block layer.
2670 * Timeout function for dasd_block. This is used when the block layer
2671 * is waiting for something that may not come reliably, (e.g. a state
2674 static void dasd_block_timeout(struct timer_list *t)
2676 unsigned long flags;
2677 struct dasd_block *block;
2679 block = from_timer(block, t, timer);
2680 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2681 /* re-activate request queue */
2682 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2683 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2684 dasd_schedule_block_bh(block);
2685 blk_mq_run_hw_queues(block->gdp->queue, true);
2689 * Setup timeout for a dasd_block in jiffies.
2691 void dasd_block_set_timer(struct dasd_block *block, int expires)
2694 del_timer(&block->timer);
2696 mod_timer(&block->timer, jiffies + expires);
2698 EXPORT_SYMBOL(dasd_block_set_timer);
2701 * Clear timeout for a dasd_block.
2703 void dasd_block_clear_timer(struct dasd_block *block)
2705 del_timer(&block->timer);
2707 EXPORT_SYMBOL(dasd_block_clear_timer);
2710 * Process finished error recovery ccw.
2712 static void __dasd_process_erp(struct dasd_device *device,
2713 struct dasd_ccw_req *cqr)
2715 dasd_erp_fn_t erp_fn;
2717 if (cqr->status == DASD_CQR_DONE)
2718 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2720 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2721 erp_fn = device->discipline->erp_postaction(cqr);
2725 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2727 struct request *req;
2728 blk_status_t error = BLK_STS_OK;
2729 unsigned int proc_bytes;
2732 req = (struct request *) cqr->callback_data;
2733 dasd_profile_end(cqr->block, cqr, req);
2735 proc_bytes = cqr->proc_bytes;
2736 status = cqr->block->base->discipline->free_cp(cqr, req);
2738 error = errno_to_blk_status(status);
2739 else if (status == 0) {
2740 switch (cqr->intrc) {
2743 * DASD doesn't implement SCSI/NVMe reservations, but it
2744 * implements a locking scheme similar to them. We
2745 * return this error when we no longer have the lock.
2747 error = BLK_STS_RESV_CONFLICT;
2750 error = BLK_STS_TRANSPORT;
2753 error = BLK_STS_TIMEOUT;
2756 error = BLK_STS_IOERR;
2762 * We need to take care for ETIMEDOUT errors here since the
2763 * complete callback does not get called in this case.
2764 * Take care of all errors here and avoid additional code to
2765 * transfer the error value to the complete callback.
2768 blk_mq_end_request(req, error);
2769 blk_mq_run_hw_queues(req->q, true);
2772 * Partial completed requests can happen with ESE devices.
2773 * During read we might have gotten a NRF error and have to
2774 * complete a request partially.
2777 blk_update_request(req, BLK_STS_OK, proc_bytes);
2778 blk_mq_requeue_request(req, true);
2779 } else if (likely(!blk_should_fake_timeout(req->q))) {
2780 blk_mq_complete_request(req);
2786 * Process ccw request queue.
2788 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2789 struct list_head *final_queue)
2791 struct list_head *l, *n;
2792 struct dasd_ccw_req *cqr;
2793 dasd_erp_fn_t erp_fn;
2794 unsigned long flags;
2795 struct dasd_device *base = block->base;
2798 /* Process request with final status. */
2799 list_for_each_safe(l, n, &block->ccw_queue) {
2800 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2801 if (cqr->status != DASD_CQR_DONE &&
2802 cqr->status != DASD_CQR_FAILED &&
2803 cqr->status != DASD_CQR_NEED_ERP &&
2804 cqr->status != DASD_CQR_TERMINATED)
2807 if (cqr->status == DASD_CQR_TERMINATED) {
2808 base->discipline->handle_terminated_request(cqr);
2812 /* Process requests that may be recovered */
2813 if (cqr->status == DASD_CQR_NEED_ERP) {
2814 erp_fn = base->discipline->erp_action(cqr);
2815 if (IS_ERR(erp_fn(cqr)))
2820 /* log sense for fatal error */
2821 if (cqr->status == DASD_CQR_FAILED) {
2822 dasd_log_sense(cqr, &cqr->irb);
2826 * First call extended error reporting and check for autoquiesce
2828 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2829 if (cqr->status == DASD_CQR_FAILED &&
2830 dasd_handle_autoquiesce(base, cqr, DASD_EER_FATALERROR)) {
2831 cqr->status = DASD_CQR_FILLED;
2833 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
2836 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
2838 /* Process finished ERP request. */
2840 __dasd_process_erp(base, cqr);
2844 /* Rechain finished requests to final queue */
2845 cqr->endclk = get_tod_clock();
2846 list_move_tail(&cqr->blocklist, final_queue);
2850 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2852 dasd_schedule_block_bh(cqr->block);
2855 static void __dasd_block_start_head(struct dasd_block *block)
2857 struct dasd_ccw_req *cqr;
2859 if (list_empty(&block->ccw_queue))
2861 /* We allways begin with the first requests on the queue, as some
2862 * of previously started requests have to be enqueued on a
2863 * dasd_device again for error recovery.
2865 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2866 if (cqr->status != DASD_CQR_FILLED)
2868 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2869 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2870 cqr->status = DASD_CQR_FAILED;
2871 cqr->intrc = -EPERM;
2872 dasd_schedule_block_bh(block);
2875 /* Non-temporary stop condition will trigger fail fast */
2876 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2877 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2878 !dasd_eer_enabled(block->base) && block->base->aq_mask == 0) {
2879 cqr->status = DASD_CQR_FAILED;
2880 cqr->intrc = -ENOLINK;
2881 dasd_schedule_block_bh(block);
2884 /* Don't try to start requests if device is stopped */
2885 if (block->base->stopped)
2888 /* just a fail safe check, should not happen */
2890 cqr->startdev = block->base;
2892 /* make sure that the requests we submit find their way back */
2893 cqr->callback = dasd_return_cqr_cb;
2895 dasd_add_request_tail(cqr);
2900 * Central dasd_block layer routine. Takes requests from the generic
2901 * block layer request queue, creates ccw requests, enqueues them on
2902 * a dasd_device and processes ccw requests that have been returned.
2904 static void dasd_block_tasklet(unsigned long data)
2906 struct dasd_block *block = (struct dasd_block *) data;
2907 struct list_head final_queue;
2908 struct list_head *l, *n;
2909 struct dasd_ccw_req *cqr;
2910 struct dasd_queue *dq;
2912 atomic_set(&block->tasklet_scheduled, 0);
2913 INIT_LIST_HEAD(&final_queue);
2914 spin_lock_irq(&block->queue_lock);
2915 /* Finish off requests on ccw queue */
2916 __dasd_process_block_ccw_queue(block, &final_queue);
2917 spin_unlock_irq(&block->queue_lock);
2919 /* Now call the callback function of requests with final status */
2920 list_for_each_safe(l, n, &final_queue) {
2921 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2923 spin_lock_irq(&dq->lock);
2924 list_del_init(&cqr->blocklist);
2925 __dasd_cleanup_cqr(cqr);
2926 spin_unlock_irq(&dq->lock);
2929 spin_lock_irq(&block->queue_lock);
2930 /* Now check if the head of the ccw queue needs to be started. */
2931 __dasd_block_start_head(block);
2932 spin_unlock_irq(&block->queue_lock);
2934 if (waitqueue_active(&shutdown_waitq))
2935 wake_up(&shutdown_waitq);
2936 dasd_put_device(block->base);
2939 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2941 wake_up(&dasd_flush_wq);
2945 * Requeue a request back to the block request queue
2946 * only works for block requests
2948 static void _dasd_requeue_request(struct dasd_ccw_req *cqr)
2950 struct request *req;
2953 * If the request is an ERP request there is nothing to requeue.
2954 * This will be done with the remaining original request.
2958 spin_lock_irq(&cqr->dq->lock);
2959 req = (struct request *) cqr->callback_data;
2960 blk_mq_requeue_request(req, true);
2961 spin_unlock_irq(&cqr->dq->lock);
2966 static int _dasd_requests_to_flushqueue(struct dasd_block *block,
2967 struct list_head *flush_queue)
2969 struct dasd_ccw_req *cqr, *n;
2970 unsigned long flags;
2973 spin_lock_irqsave(&block->queue_lock, flags);
2976 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2977 /* if this request currently owned by a dasd_device cancel it */
2978 if (cqr->status >= DASD_CQR_QUEUED)
2979 rc = dasd_cancel_req(cqr);
2982 /* Rechain request (including erp chain) so it won't be
2983 * touched by the dasd_block_tasklet anymore.
2984 * Replace the callback so we notice when the request
2985 * is returned from the dasd_device layer.
2987 cqr->callback = _dasd_wake_block_flush_cb;
2988 for (i = 0; cqr; cqr = cqr->refers, i++)
2989 list_move_tail(&cqr->blocklist, flush_queue);
2991 /* moved more than one request - need to restart */
2994 spin_unlock_irqrestore(&block->queue_lock, flags);
3000 * Go through all request on the dasd_block request queue, cancel them
3001 * on the respective dasd_device, and return them to the generic
3004 static int dasd_flush_block_queue(struct dasd_block *block)
3006 struct dasd_ccw_req *cqr, *n;
3007 struct list_head flush_queue;
3008 unsigned long flags;
3011 INIT_LIST_HEAD(&flush_queue);
3012 rc = _dasd_requests_to_flushqueue(block, &flush_queue);
3014 /* Now call the callback function of flushed requests */
3016 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
3017 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
3018 /* Process finished ERP request. */
3020 spin_lock_bh(&block->queue_lock);
3021 __dasd_process_erp(block->base, cqr);
3022 spin_unlock_bh(&block->queue_lock);
3023 /* restart list_for_xx loop since dasd_process_erp
3024 * might remove multiple elements */
3027 /* call the callback function */
3028 spin_lock_irqsave(&cqr->dq->lock, flags);
3029 cqr->endclk = get_tod_clock();
3030 list_del_init(&cqr->blocklist);
3031 __dasd_cleanup_cqr(cqr);
3032 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3038 * Schedules a call to dasd_tasklet over the device tasklet.
3040 void dasd_schedule_block_bh(struct dasd_block *block)
3042 /* Protect against rescheduling. */
3043 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
3045 /* life cycle of block is bound to it's base device */
3046 dasd_get_device(block->base);
3047 tasklet_hi_schedule(&block->tasklet);
3049 EXPORT_SYMBOL(dasd_schedule_block_bh);
3053 * SECTION: external block device operations
3054 * (request queue handling, open, release, etc.)
3058 * Dasd request queue function. Called from ll_rw_blk.c
3060 static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
3061 const struct blk_mq_queue_data *qd)
3063 struct dasd_block *block = hctx->queue->queuedata;
3064 struct dasd_queue *dq = hctx->driver_data;
3065 struct request *req = qd->rq;
3066 struct dasd_device *basedev;
3067 struct dasd_ccw_req *cqr;
3068 blk_status_t rc = BLK_STS_OK;
3070 basedev = block->base;
3071 spin_lock_irq(&dq->lock);
3072 if (basedev->state < DASD_STATE_READY ||
3073 test_bit(DASD_FLAG_OFFLINE, &basedev->flags)) {
3074 DBF_DEV_EVENT(DBF_ERR, basedev,
3075 "device not ready for request %p", req);
3081 * if device is stopped do not fetch new requests
3082 * except failfast is active which will let requests fail
3083 * immediately in __dasd_block_start_head()
3085 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
3086 DBF_DEV_EVENT(DBF_ERR, basedev,
3087 "device stopped request %p", req);
3088 rc = BLK_STS_RESOURCE;
3092 if (basedev->features & DASD_FEATURE_READONLY &&
3093 rq_data_dir(req) == WRITE) {
3094 DBF_DEV_EVENT(DBF_ERR, basedev,
3095 "Rejecting write request %p", req);
3100 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
3101 (basedev->features & DASD_FEATURE_FAILFAST ||
3102 blk_noretry_request(req))) {
3103 DBF_DEV_EVENT(DBF_ERR, basedev,
3104 "Rejecting failfast request %p", req);
3109 cqr = basedev->discipline->build_cp(basedev, block, req);
3111 if (PTR_ERR(cqr) == -EBUSY ||
3112 PTR_ERR(cqr) == -ENOMEM ||
3113 PTR_ERR(cqr) == -EAGAIN) {
3114 rc = BLK_STS_RESOURCE;
3117 DBF_DEV_EVENT(DBF_ERR, basedev,
3118 "CCW creation failed (rc=%ld) on request %p",
3124 * Note: callback is set to dasd_return_cqr_cb in
3125 * __dasd_block_start_head to cover erp requests as well
3127 cqr->callback_data = req;
3128 cqr->status = DASD_CQR_FILLED;
3131 blk_mq_start_request(req);
3132 spin_lock(&block->queue_lock);
3133 list_add_tail(&cqr->blocklist, &block->ccw_queue);
3134 INIT_LIST_HEAD(&cqr->devlist);
3135 dasd_profile_start(block, cqr, req);
3136 dasd_schedule_block_bh(block);
3137 spin_unlock(&block->queue_lock);
3140 spin_unlock_irq(&dq->lock);
3145 * Block timeout callback, called from the block layer
3148 * BLK_EH_RESET_TIMER if the request should be left running
3149 * BLK_EH_DONE if the request is handled or terminated
3152 enum blk_eh_timer_return dasd_times_out(struct request *req)
3154 struct dasd_block *block = req->q->queuedata;
3155 struct dasd_device *device;
3156 struct dasd_ccw_req *cqr;
3157 unsigned long flags;
3160 cqr = blk_mq_rq_to_pdu(req);
3164 spin_lock_irqsave(&cqr->dq->lock, flags);
3165 device = cqr->startdev ? cqr->startdev : block->base;
3166 if (!device->blk_timeout) {
3167 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3168 return BLK_EH_RESET_TIMER;
3170 DBF_DEV_EVENT(DBF_WARNING, device,
3171 " dasd_times_out cqr %p status %x",
3174 spin_lock(&block->queue_lock);
3175 spin_lock(get_ccwdev_lock(device->cdev));
3177 cqr->intrc = -ETIMEDOUT;
3178 if (cqr->status >= DASD_CQR_QUEUED) {
3179 rc = __dasd_cancel_req(cqr);
3180 } else if (cqr->status == DASD_CQR_FILLED ||
3181 cqr->status == DASD_CQR_NEED_ERP) {
3182 cqr->status = DASD_CQR_TERMINATED;
3183 } else if (cqr->status == DASD_CQR_IN_ERP) {
3184 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3186 list_for_each_entry_safe(searchcqr, nextcqr,
3187 &block->ccw_queue, blocklist) {
3189 while (tmpcqr->refers)
3190 tmpcqr = tmpcqr->refers;
3193 /* searchcqr is an ERP request for cqr */
3194 searchcqr->retries = -1;
3195 searchcqr->intrc = -ETIMEDOUT;
3196 if (searchcqr->status >= DASD_CQR_QUEUED) {
3197 rc = __dasd_cancel_req(searchcqr);
3198 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3199 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3200 searchcqr->status = DASD_CQR_TERMINATED;
3202 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3204 * Shouldn't happen; most recent ERP
3205 * request is at the front of queue
3212 spin_unlock(get_ccwdev_lock(device->cdev));
3213 dasd_schedule_block_bh(block);
3214 spin_unlock(&block->queue_lock);
3215 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3217 return rc ? BLK_EH_RESET_TIMER : BLK_EH_DONE;
3220 static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
3223 struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
3228 spin_lock_init(&dq->lock);
3229 hctx->driver_data = dq;
3234 static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
3236 kfree(hctx->driver_data);
3237 hctx->driver_data = NULL;
3240 static void dasd_request_done(struct request *req)
3242 blk_mq_end_request(req, 0);
3243 blk_mq_run_hw_queues(req->q, true);
3246 struct blk_mq_ops dasd_mq_ops = {
3247 .queue_rq = do_dasd_request,
3248 .complete = dasd_request_done,
3249 .timeout = dasd_times_out,
3250 .init_hctx = dasd_init_hctx,
3251 .exit_hctx = dasd_exit_hctx,
3254 static int dasd_open(struct gendisk *disk, blk_mode_t mode)
3256 struct dasd_device *base;
3259 base = dasd_device_from_gendisk(disk);
3263 atomic_inc(&base->block->open_count);
3264 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
3269 if (!try_module_get(base->discipline->owner)) {
3274 if (dasd_probeonly) {
3275 dev_info(&base->cdev->dev,
3276 "Accessing the DASD failed because it is in "
3277 "probeonly mode\n");
3282 if (base->state <= DASD_STATE_BASIC) {
3283 DBF_DEV_EVENT(DBF_ERR, base, " %s",
3284 " Cannot open unrecognized device");
3288 if ((mode & BLK_OPEN_WRITE) &&
3289 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3290 (base->features & DASD_FEATURE_READONLY))) {
3294 dasd_put_device(base);
3298 module_put(base->discipline->owner);
3300 atomic_dec(&base->block->open_count);
3301 dasd_put_device(base);
3305 static void dasd_release(struct gendisk *disk)
3307 struct dasd_device *base = dasd_device_from_gendisk(disk);
3309 atomic_dec(&base->block->open_count);
3310 module_put(base->discipline->owner);
3311 dasd_put_device(base);
3316 * Return disk geometry.
3318 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3320 struct dasd_device *base;
3322 base = dasd_device_from_gendisk(bdev->bd_disk);
3326 if (!base->discipline ||
3327 !base->discipline->fill_geometry) {
3328 dasd_put_device(base);
3331 base->discipline->fill_geometry(base->block, geo);
3332 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3333 dasd_put_device(base);
3337 const struct block_device_operations
3338 dasd_device_operations = {
3339 .owner = THIS_MODULE,
3341 .release = dasd_release,
3342 .ioctl = dasd_ioctl,
3343 .compat_ioctl = dasd_ioctl,
3344 .getgeo = dasd_getgeo,
3345 .set_read_only = dasd_set_read_only,
3348 /*******************************************************************************
3349 * end of block device operations
3355 #ifdef CONFIG_PROC_FS
3359 kmem_cache_destroy(dasd_page_cache);
3360 dasd_page_cache = NULL;
3361 dasd_gendisk_exit();
3363 if (dasd_debug_area != NULL) {
3364 debug_unregister(dasd_debug_area);
3365 dasd_debug_area = NULL;
3367 dasd_statistics_removeroot();
3371 * SECTION: common functions for ccw_driver use
3375 * Is the device read-only?
3376 * Note that this function does not report the setting of the
3377 * readonly device attribute, but how it is configured in z/VM.
3379 int dasd_device_is_ro(struct dasd_device *device)
3381 struct ccw_dev_id dev_id;
3382 struct diag210 diag_data;
3387 ccw_device_get_id(device->cdev, &dev_id);
3388 memset(&diag_data, 0, sizeof(diag_data));
3389 diag_data.vrdcdvno = dev_id.devno;
3390 diag_data.vrdclen = sizeof(diag_data);
3391 rc = diag210(&diag_data);
3392 if (rc == 0 || rc == 2) {
3393 return diag_data.vrdcvfla & 0x80;
3395 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3400 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3402 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3404 struct ccw_device *cdev = data;
3407 ret = ccw_device_set_online(cdev);
3409 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3410 dev_name(&cdev->dev), ret);
3414 * Initial attempt at a probe function. this can be simplified once
3415 * the other detection code is gone.
3417 int dasd_generic_probe(struct ccw_device *cdev)
3419 cdev->handler = &dasd_int_handler;
3422 * Automatically online either all dasd devices (dasd_autodetect)
3423 * or all devices specified with dasd= parameters during
3426 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
3427 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
3428 async_schedule(dasd_generic_auto_online, cdev);
3431 EXPORT_SYMBOL_GPL(dasd_generic_probe);
3433 void dasd_generic_free_discipline(struct dasd_device *device)
3435 /* Forget the discipline information. */
3436 if (device->discipline) {
3437 if (device->discipline->uncheck_device)
3438 device->discipline->uncheck_device(device);
3439 module_put(device->discipline->owner);
3440 device->discipline = NULL;
3442 if (device->base_discipline) {
3443 module_put(device->base_discipline->owner);
3444 device->base_discipline = NULL;
3447 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3450 * This will one day be called from a global not_oper handler.
3451 * It is also used by driver_unregister during module unload.
3453 void dasd_generic_remove(struct ccw_device *cdev)
3455 struct dasd_device *device;
3456 struct dasd_block *block;
3458 device = dasd_device_from_cdev(cdev);
3462 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3463 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3464 /* Already doing offline processing */
3465 dasd_put_device(device);
3469 * This device is removed unconditionally. Set offline
3470 * flag to prevent dasd_open from opening it while it is
3471 * no quite down yet.
3473 dasd_set_target_state(device, DASD_STATE_NEW);
3474 cdev->handler = NULL;
3475 /* dasd_delete_device destroys the device reference. */
3476 block = device->block;
3477 dasd_delete_device(device);
3479 * life cycle of block is bound to device, so delete it after
3480 * device was safely removed
3483 dasd_free_block(block);
3485 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3488 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3489 * the device is detected for the first time and is supposed to be used
3490 * or the user has started activation through sysfs.
3492 int dasd_generic_set_online(struct ccw_device *cdev,
3493 struct dasd_discipline *base_discipline)
3495 struct dasd_discipline *discipline;
3496 struct dasd_device *device;
3499 /* first online clears initial online feature flag */
3500 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3501 device = dasd_create_device(cdev);
3503 return PTR_ERR(device);
3505 discipline = base_discipline;
3506 if (device->features & DASD_FEATURE_USEDIAG) {
3507 if (!dasd_diag_discipline_pointer) {
3508 /* Try to load the required module. */
3509 rc = request_module(DASD_DIAG_MOD);
3511 pr_warn("%s Setting the DASD online failed "
3512 "because the required module %s "
3513 "could not be loaded (rc=%d)\n",
3514 dev_name(&cdev->dev), DASD_DIAG_MOD,
3516 dasd_delete_device(device);
3520 /* Module init could have failed, so check again here after
3521 * request_module(). */
3522 if (!dasd_diag_discipline_pointer) {
3523 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3524 dev_name(&cdev->dev));
3525 dasd_delete_device(device);
3528 discipline = dasd_diag_discipline_pointer;
3530 if (!try_module_get(base_discipline->owner)) {
3531 dasd_delete_device(device);
3534 if (!try_module_get(discipline->owner)) {
3535 module_put(base_discipline->owner);
3536 dasd_delete_device(device);
3539 device->base_discipline = base_discipline;
3540 device->discipline = discipline;
3542 /* check_device will allocate block device if necessary */
3543 rc = discipline->check_device(device);
3545 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3546 dev_name(&cdev->dev), discipline->name, rc);
3547 module_put(discipline->owner);
3548 module_put(base_discipline->owner);
3549 dasd_delete_device(device);
3553 dasd_set_target_state(device, DASD_STATE_ONLINE);
3554 if (device->state <= DASD_STATE_KNOWN) {
3555 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3556 dev_name(&cdev->dev));
3558 dasd_set_target_state(device, DASD_STATE_NEW);
3560 dasd_free_block(device->block);
3561 dasd_delete_device(device);
3563 pr_debug("dasd_generic device %s found\n",
3564 dev_name(&cdev->dev));
3566 wait_event(dasd_init_waitq, _wait_for_device(device));
3568 dasd_put_device(device);
3571 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3573 int dasd_generic_set_offline(struct ccw_device *cdev)
3575 struct dasd_device *device;
3576 struct dasd_block *block;
3577 int max_count, open_count, rc;
3578 unsigned long flags;
3581 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3582 device = dasd_device_from_cdev_locked(cdev);
3583 if (IS_ERR(device)) {
3584 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3585 return PTR_ERR(device);
3589 * We must make sure that this device is currently not in use.
3590 * The open_count is increased for every opener, that includes
3591 * the blkdev_get in dasd_scan_partitions. We are only interested
3592 * in the other openers.
3594 if (device->block) {
3595 max_count = device->block->bdev_handle ? 0 : -1;
3596 open_count = atomic_read(&device->block->open_count);
3597 if (open_count > max_count) {
3599 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3600 dev_name(&cdev->dev), open_count);
3602 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3603 dev_name(&cdev->dev));
3610 * Test if the offline processing is already running and exit if so.
3611 * If a safe offline is being processed this could only be a normal
3612 * offline that should be able to overtake the safe offline and
3613 * cancel any I/O we do not want to wait for any longer
3615 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3616 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3617 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3624 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3627 * if safe_offline is called set safe_offline_running flag and
3628 * clear safe_offline so that a call to normal offline
3629 * can overrun safe_offline processing
3631 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3632 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3633 /* need to unlock here to wait for outstanding I/O */
3634 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3636 * If we want to set the device safe offline all IO operations
3637 * should be finished before continuing the offline process
3638 * so sync bdev first and then wait for our queues to become
3641 if (device->block && device->block->bdev_handle)
3642 bdev_mark_dead(device->block->bdev_handle->bdev, false);
3643 dasd_schedule_device_bh(device);
3644 rc = wait_event_interruptible(shutdown_waitq,
3645 _wait_for_empty_queues(device));
3650 * check if a normal offline process overtook the offline
3651 * processing in this case simply do nothing beside returning
3652 * that we got interrupted
3653 * otherwise mark safe offline as not running any longer and
3654 * continue with normal offline
3656 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3657 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3661 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3663 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3665 dasd_set_target_state(device, DASD_STATE_NEW);
3666 /* dasd_delete_device destroys the device reference. */
3667 block = device->block;
3668 dasd_delete_device(device);
3670 * life cycle of block is bound to device, so delete it after
3671 * device was safely removed
3674 dasd_free_block(block);
3679 /* interrupted by signal */
3680 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3681 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3682 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3684 dasd_put_device(device);
3685 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3688 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3690 int dasd_generic_last_path_gone(struct dasd_device *device)
3692 struct dasd_ccw_req *cqr;
3694 dev_warn(&device->cdev->dev, "No operational channel path is left "
3695 "for the device\n");
3696 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3697 /* First call extended error reporting and check for autoquiesce. */
3698 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOPATH);
3700 if (device->state < DASD_STATE_BASIC)
3702 /* Device is active. We want to keep it. */
3703 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3704 if ((cqr->status == DASD_CQR_IN_IO) ||
3705 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3706 cqr->status = DASD_CQR_QUEUED;
3709 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3710 dasd_device_clear_timer(device);
3711 dasd_schedule_device_bh(device);
3714 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3716 int dasd_generic_path_operational(struct dasd_device *device)
3718 dev_info(&device->cdev->dev, "A channel path to the device has become "
3720 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3721 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3722 dasd_schedule_device_bh(device);
3723 if (device->block) {
3724 dasd_schedule_block_bh(device->block);
3725 if (device->block->gdp)
3726 blk_mq_run_hw_queues(device->block->gdp->queue, true);
3729 if (!device->stopped)
3730 wake_up(&generic_waitq);
3734 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3736 int dasd_generic_notify(struct ccw_device *cdev, int event)
3738 struct dasd_device *device;
3741 device = dasd_device_from_cdev_locked(cdev);
3749 dasd_path_no_path(device);
3750 ret = dasd_generic_last_path_gone(device);
3754 if (dasd_path_get_opm(device))
3755 ret = dasd_generic_path_operational(device);
3758 dasd_put_device(device);
3761 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3763 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3765 struct dasd_device *device;
3766 int chp, oldopm, hpfpm, ifccpm;
3768 device = dasd_device_from_cdev_locked(cdev);
3772 oldopm = dasd_path_get_opm(device);
3773 for (chp = 0; chp < 8; chp++) {
3774 if (path_event[chp] & PE_PATH_GONE) {
3775 dasd_path_notoper(device, chp);
3777 if (path_event[chp] & PE_PATH_AVAILABLE) {
3778 dasd_path_available(device, chp);
3779 dasd_schedule_device_bh(device);
3781 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3782 if (!dasd_path_is_operational(device, chp) &&
3783 !dasd_path_need_verify(device, chp)) {
3785 * we can not establish a pathgroup on an
3786 * unavailable path, so trigger a path
3787 * verification first
3789 dasd_path_available(device, chp);
3790 dasd_schedule_device_bh(device);
3792 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3793 "Pathgroup re-established\n");
3794 if (device->discipline->kick_validate)
3795 device->discipline->kick_validate(device);
3797 if (path_event[chp] & PE_PATH_FCES_EVENT) {
3798 dasd_path_fcsec_update(device, chp);
3799 dasd_schedule_device_bh(device);
3802 hpfpm = dasd_path_get_hpfpm(device);
3803 ifccpm = dasd_path_get_ifccpm(device);
3804 if (!dasd_path_get_opm(device) && hpfpm) {
3806 * device has no operational paths but at least one path is
3807 * disabled due to HPF errors
3808 * disable HPF at all and use the path(s) again
3810 if (device->discipline->disable_hpf)
3811 device->discipline->disable_hpf(device);
3812 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3813 dasd_path_set_tbvpm(device, hpfpm);
3814 dasd_schedule_device_bh(device);
3815 dasd_schedule_requeue(device);
3816 } else if (!dasd_path_get_opm(device) && ifccpm) {
3818 * device has no operational paths but at least one path is
3819 * disabled due to IFCC errors
3820 * trigger path verification on paths with IFCC errors
3822 dasd_path_set_tbvpm(device, ifccpm);
3823 dasd_schedule_device_bh(device);
3825 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3826 dev_warn(&device->cdev->dev,
3827 "No verified channel paths remain for the device\n");
3828 DBF_DEV_EVENT(DBF_WARNING, device,
3829 "%s", "last verified path gone");
3830 /* First call extended error reporting and check for autoquiesce. */
3831 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOPATH);
3832 dasd_device_set_stop_bits(device,
3833 DASD_STOPPED_DC_WAIT);
3835 dasd_put_device(device);
3837 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3839 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3841 if (!dasd_path_get_opm(device) && lpm) {
3842 dasd_path_set_opm(device, lpm);
3843 dasd_generic_path_operational(device);
3845 dasd_path_add_opm(device, lpm);
3848 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3850 void dasd_generic_space_exhaust(struct dasd_device *device,
3851 struct dasd_ccw_req *cqr)
3853 /* First call extended error reporting and check for autoquiesce. */
3854 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOSPC);
3856 if (device->state < DASD_STATE_BASIC)
3859 if (cqr->status == DASD_CQR_IN_IO ||
3860 cqr->status == DASD_CQR_CLEAR_PENDING) {
3861 cqr->status = DASD_CQR_QUEUED;
3864 dasd_device_set_stop_bits(device, DASD_STOPPED_NOSPC);
3865 dasd_device_clear_timer(device);
3866 dasd_schedule_device_bh(device);
3868 EXPORT_SYMBOL_GPL(dasd_generic_space_exhaust);
3870 void dasd_generic_space_avail(struct dasd_device *device)
3872 dev_info(&device->cdev->dev, "Extent pool space is available\n");
3873 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "space available");
3875 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOSPC);
3876 dasd_schedule_device_bh(device);
3878 if (device->block) {
3879 dasd_schedule_block_bh(device->block);
3880 if (device->block->gdp)
3881 blk_mq_run_hw_queues(device->block->gdp->queue, true);
3883 if (!device->stopped)
3884 wake_up(&generic_waitq);
3886 EXPORT_SYMBOL_GPL(dasd_generic_space_avail);
3889 * clear active requests and requeue them to block layer if possible
3891 int dasd_generic_requeue_all_requests(struct dasd_device *device)
3893 struct dasd_block *block = device->block;
3894 struct list_head requeue_queue;
3895 struct dasd_ccw_req *cqr, *n;
3901 INIT_LIST_HEAD(&requeue_queue);
3902 rc = _dasd_requests_to_flushqueue(block, &requeue_queue);
3904 /* Now call the callback function of flushed requests */
3906 list_for_each_entry_safe(cqr, n, &requeue_queue, blocklist) {
3907 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
3908 /* Process finished ERP request. */
3910 spin_lock_bh(&block->queue_lock);
3911 __dasd_process_erp(block->base, cqr);
3912 spin_unlock_bh(&block->queue_lock);
3913 /* restart list_for_xx loop since dasd_process_erp
3914 * might remove multiple elements
3918 _dasd_requeue_request(cqr);
3919 list_del_init(&cqr->blocklist);
3920 cqr->block->base->discipline->free_cp(
3921 cqr, (struct request *) cqr->callback_data);
3923 dasd_schedule_device_bh(device);
3926 EXPORT_SYMBOL_GPL(dasd_generic_requeue_all_requests);
3928 static void do_requeue_requests(struct work_struct *work)
3930 struct dasd_device *device = container_of(work, struct dasd_device,
3932 dasd_generic_requeue_all_requests(device);
3933 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3935 dasd_schedule_block_bh(device->block);
3936 dasd_put_device(device);
3939 void dasd_schedule_requeue(struct dasd_device *device)
3941 dasd_get_device(device);
3942 /* queue call to dasd_reload_device to the kernel event daemon. */
3943 if (!schedule_work(&device->requeue_requests))
3944 dasd_put_device(device);
3946 EXPORT_SYMBOL(dasd_schedule_requeue);
3948 static int dasd_handle_autoquiesce(struct dasd_device *device,
3949 struct dasd_ccw_req *cqr,
3950 unsigned int reason)
3952 /* in any case write eer message with reason */
3953 if (dasd_eer_enabled(device))
3954 dasd_eer_write(device, cqr, reason);
3956 if (!test_bit(reason, &device->aq_mask))
3959 /* notify eer about autoquiesce */
3960 if (dasd_eer_enabled(device))
3961 dasd_eer_write(device, NULL, DASD_EER_AUTOQUIESCE);
3963 pr_info("%s: The DASD has been put in the quiesce state\n",
3964 dev_name(&device->cdev->dev));
3965 dasd_device_set_stop_bits(device, DASD_STOPPED_QUIESCE);
3967 if (device->features & DASD_FEATURE_REQUEUEQUIESCE)
3968 dasd_schedule_requeue(device);
3973 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
3974 int rdc_buffer_size,
3977 struct dasd_ccw_req *cqr;
3980 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device,
3984 /* internal error 13 - Allocating the RDC request failed*/
3985 dev_err(&device->cdev->dev,
3986 "An error occurred in the DASD device driver, "
3987 "reason=%s\n", "13");
3992 ccw->cmd_code = CCW_CMD_RDC;
3993 ccw->cda = (__u32)virt_to_phys(cqr->data);
3995 ccw->count = rdc_buffer_size;
3996 cqr->startdev = device;
3997 cqr->memdev = device;
3998 cqr->expires = 10*HZ;
4000 cqr->buildclk = get_tod_clock();
4001 cqr->status = DASD_CQR_FILLED;
4006 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4007 void *rdc_buffer, int rdc_buffer_size)
4010 struct dasd_ccw_req *cqr;
4012 cqr = dasd_generic_build_rdc(device, rdc_buffer_size, magic);
4014 return PTR_ERR(cqr);
4016 ret = dasd_sleep_on(cqr);
4018 memcpy(rdc_buffer, cqr->data, rdc_buffer_size);
4019 dasd_sfree_request(cqr, cqr->memdev);
4022 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
4025 * In command mode and transport mode we need to look for sense
4026 * data in different places. The sense data itself is allways
4027 * an array of 32 bytes, so we can unify the sense data access
4030 char *dasd_get_sense(struct irb *irb)
4032 struct tsb *tsb = NULL;
4035 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4036 if (irb->scsw.tm.tcw)
4037 tsb = tcw_get_tsb(phys_to_virt(irb->scsw.tm.tcw));
4038 if (tsb && tsb->length == 64 && tsb->flags)
4039 switch (tsb->flags & 0x07) {
4040 case 1: /* tsa_iostat */
4041 sense = tsb->tsa.iostat.sense;
4043 case 2: /* tsa_ddpc */
4044 sense = tsb->tsa.ddpc.sense;
4047 /* currently we don't use interrogate data */
4050 } else if (irb->esw.esw0.erw.cons) {
4055 EXPORT_SYMBOL_GPL(dasd_get_sense);
4057 void dasd_generic_shutdown(struct ccw_device *cdev)
4059 struct dasd_device *device;
4061 device = dasd_device_from_cdev(cdev);
4066 dasd_schedule_block_bh(device->block);
4068 dasd_schedule_device_bh(device);
4070 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4072 EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4074 static int __init dasd_init(void)
4078 init_waitqueue_head(&dasd_init_waitq);
4079 init_waitqueue_head(&dasd_flush_wq);
4080 init_waitqueue_head(&generic_waitq);
4081 init_waitqueue_head(&shutdown_waitq);
4083 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4084 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
4085 if (dasd_debug_area == NULL) {
4089 debug_register_view(dasd_debug_area, &debug_sprintf_view);
4090 debug_set_level(dasd_debug_area, DBF_WARNING);
4092 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4094 dasd_diag_discipline_pointer = NULL;
4096 dasd_statistics_createroot();
4098 rc = dasd_devmap_init();
4101 rc = dasd_gendisk_init();
4107 rc = dasd_eer_init();
4110 #ifdef CONFIG_PROC_FS
4111 rc = dasd_proc_init();
4118 pr_info("The DASD device driver could not be initialized\n");
4123 module_init(dasd_init);
4124 module_exit(dasd_exit);