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->bd_disk, KOBJ_CHANGE);
421 * Stop the requeueing of requests again.
423 static int dasd_state_online_to_ready(struct dasd_device *device)
427 if (device->discipline->online_to_ready) {
428 rc = device->discipline->online_to_ready(device);
433 device->state = DASD_STATE_READY;
434 if (device->block && !(device->features & DASD_FEATURE_USERAW))
435 disk_uevent(device->block->bdev->bd_disk, KOBJ_CHANGE);
440 * Device startup state changes.
442 static int dasd_increase_state(struct dasd_device *device)
447 if (device->state == DASD_STATE_NEW &&
448 device->target >= DASD_STATE_KNOWN)
449 rc = dasd_state_new_to_known(device);
452 device->state == DASD_STATE_KNOWN &&
453 device->target >= DASD_STATE_BASIC)
454 rc = dasd_state_known_to_basic(device);
457 device->state == DASD_STATE_BASIC &&
458 device->target >= DASD_STATE_READY)
459 rc = dasd_state_basic_to_ready(device);
462 device->state == DASD_STATE_UNFMT &&
463 device->target > DASD_STATE_UNFMT)
467 device->state == DASD_STATE_READY &&
468 device->target >= DASD_STATE_ONLINE)
469 rc = dasd_state_ready_to_online(device);
475 * Device shutdown state changes.
477 static int dasd_decrease_state(struct dasd_device *device)
482 if (device->state == DASD_STATE_ONLINE &&
483 device->target <= DASD_STATE_READY)
484 rc = dasd_state_online_to_ready(device);
487 device->state == DASD_STATE_READY &&
488 device->target <= DASD_STATE_BASIC)
489 rc = dasd_state_ready_to_basic(device);
492 device->state == DASD_STATE_UNFMT &&
493 device->target <= DASD_STATE_BASIC)
494 rc = dasd_state_unfmt_to_basic(device);
497 device->state == DASD_STATE_BASIC &&
498 device->target <= DASD_STATE_KNOWN)
499 rc = dasd_state_basic_to_known(device);
502 device->state == DASD_STATE_KNOWN &&
503 device->target <= DASD_STATE_NEW)
504 rc = dasd_state_known_to_new(device);
510 * This is the main startup/shutdown routine.
512 static void dasd_change_state(struct dasd_device *device)
516 if (device->state == device->target)
517 /* Already where we want to go today... */
519 if (device->state < device->target)
520 rc = dasd_increase_state(device);
522 rc = dasd_decrease_state(device);
526 device->target = device->state;
528 /* let user-space know that the device status changed */
529 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
531 if (device->state == device->target)
532 wake_up(&dasd_init_waitq);
536 * Kick starter for devices that did not complete the startup/shutdown
537 * procedure or were sleeping because of a pending state.
538 * dasd_kick_device will schedule a call do do_kick_device to the kernel
541 static void do_kick_device(struct work_struct *work)
543 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
544 mutex_lock(&device->state_mutex);
545 dasd_change_state(device);
546 mutex_unlock(&device->state_mutex);
547 dasd_schedule_device_bh(device);
548 dasd_put_device(device);
551 void dasd_kick_device(struct dasd_device *device)
553 dasd_get_device(device);
554 /* queue call to dasd_kick_device to the kernel event daemon. */
555 if (!schedule_work(&device->kick_work))
556 dasd_put_device(device);
558 EXPORT_SYMBOL(dasd_kick_device);
561 * dasd_reload_device will schedule a call do do_reload_device to the kernel
564 static void do_reload_device(struct work_struct *work)
566 struct dasd_device *device = container_of(work, struct dasd_device,
568 device->discipline->reload(device);
569 dasd_put_device(device);
572 void dasd_reload_device(struct dasd_device *device)
574 dasd_get_device(device);
575 /* queue call to dasd_reload_device to the kernel event daemon. */
576 if (!schedule_work(&device->reload_device))
577 dasd_put_device(device);
579 EXPORT_SYMBOL(dasd_reload_device);
582 * Set the target state for a device and starts the state change.
584 void dasd_set_target_state(struct dasd_device *device, int target)
586 dasd_get_device(device);
587 mutex_lock(&device->state_mutex);
588 /* If we are in probeonly mode stop at DASD_STATE_READY. */
589 if (dasd_probeonly && target > DASD_STATE_READY)
590 target = DASD_STATE_READY;
591 if (device->target != target) {
592 if (device->state == target)
593 wake_up(&dasd_init_waitq);
594 device->target = target;
596 if (device->state != device->target)
597 dasd_change_state(device);
598 mutex_unlock(&device->state_mutex);
599 dasd_put_device(device);
603 * Enable devices with device numbers in [from..to].
605 static inline int _wait_for_device(struct dasd_device *device)
607 return (device->state == device->target);
610 void dasd_enable_device(struct dasd_device *device)
612 dasd_set_target_state(device, DASD_STATE_ONLINE);
613 if (device->state <= DASD_STATE_KNOWN)
614 /* No discipline for device found. */
615 dasd_set_target_state(device, DASD_STATE_NEW);
616 /* Now wait for the devices to come up. */
617 wait_event(dasd_init_waitq, _wait_for_device(device));
619 dasd_reload_device(device);
620 if (device->discipline->kick_validate)
621 device->discipline->kick_validate(device);
623 EXPORT_SYMBOL(dasd_enable_device);
626 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
629 unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
631 #ifdef CONFIG_DASD_PROFILE
632 struct dasd_profile dasd_global_profile = {
633 .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
635 static struct dentry *dasd_debugfs_global_entry;
638 * Add profiling information for cqr before execution.
640 static void dasd_profile_start(struct dasd_block *block,
641 struct dasd_ccw_req *cqr,
645 unsigned int counter;
646 struct dasd_device *device;
648 /* count the length of the chanq for statistics */
650 if (dasd_global_profile_level || block->profile.data)
651 list_for_each(l, &block->ccw_queue)
655 spin_lock(&dasd_global_profile.lock);
656 if (dasd_global_profile.data) {
657 dasd_global_profile.data->dasd_io_nr_req[counter]++;
658 if (rq_data_dir(req) == READ)
659 dasd_global_profile.data->dasd_read_nr_req[counter]++;
661 spin_unlock(&dasd_global_profile.lock);
663 spin_lock(&block->profile.lock);
664 if (block->profile.data) {
665 block->profile.data->dasd_io_nr_req[counter]++;
666 if (rq_data_dir(req) == READ)
667 block->profile.data->dasd_read_nr_req[counter]++;
669 spin_unlock(&block->profile.lock);
672 * We count the request for the start device, even though it may run on
673 * some other device due to error recovery. This way we make sure that
674 * we count each request only once.
676 device = cqr->startdev;
677 if (device->profile.data) {
678 counter = 1; /* request is not yet queued on the start device */
679 list_for_each(l, &device->ccw_queue)
683 spin_lock(&device->profile.lock);
684 if (device->profile.data) {
685 device->profile.data->dasd_io_nr_req[counter]++;
686 if (rq_data_dir(req) == READ)
687 device->profile.data->dasd_read_nr_req[counter]++;
689 spin_unlock(&device->profile.lock);
693 * Add profiling information for cqr after execution.
696 #define dasd_profile_counter(value, index) \
698 for (index = 0; index < 31 && value >> (2+index); index++) \
702 static void dasd_profile_end_add_data(struct dasd_profile_info *data,
715 /* in case of an overflow, reset the whole profile */
716 if (data->dasd_io_reqs == UINT_MAX) {
717 memset(data, 0, sizeof(*data));
718 ktime_get_real_ts64(&data->starttod);
720 data->dasd_io_reqs++;
721 data->dasd_io_sects += sectors;
723 data->dasd_io_alias++;
727 data->dasd_io_secs[sectors_ind]++;
728 data->dasd_io_times[tottime_ind]++;
729 data->dasd_io_timps[tottimeps_ind]++;
730 data->dasd_io_time1[strtime_ind]++;
731 data->dasd_io_time2[irqtime_ind]++;
732 data->dasd_io_time2ps[irqtimeps_ind]++;
733 data->dasd_io_time3[endtime_ind]++;
736 data->dasd_read_reqs++;
737 data->dasd_read_sects += sectors;
739 data->dasd_read_alias++;
741 data->dasd_read_tpm++;
742 data->dasd_read_secs[sectors_ind]++;
743 data->dasd_read_times[tottime_ind]++;
744 data->dasd_read_time1[strtime_ind]++;
745 data->dasd_read_time2[irqtime_ind]++;
746 data->dasd_read_time3[endtime_ind]++;
750 static void dasd_profile_end(struct dasd_block *block,
751 struct dasd_ccw_req *cqr,
754 unsigned long strtime, irqtime, endtime, tottime;
755 unsigned long tottimeps, sectors;
756 struct dasd_device *device;
757 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
758 int irqtime_ind, irqtimeps_ind, endtime_ind;
759 struct dasd_profile_info *data;
761 device = cqr->startdev;
762 if (!(dasd_global_profile_level ||
763 block->profile.data ||
764 device->profile.data))
767 sectors = blk_rq_sectors(req);
768 if (!cqr->buildclk || !cqr->startclk ||
769 !cqr->stopclk || !cqr->endclk ||
773 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
774 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
775 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
776 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
777 tottimeps = tottime / sectors;
779 dasd_profile_counter(sectors, sectors_ind);
780 dasd_profile_counter(tottime, tottime_ind);
781 dasd_profile_counter(tottimeps, tottimeps_ind);
782 dasd_profile_counter(strtime, strtime_ind);
783 dasd_profile_counter(irqtime, irqtime_ind);
784 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
785 dasd_profile_counter(endtime, endtime_ind);
787 spin_lock(&dasd_global_profile.lock);
788 if (dasd_global_profile.data) {
789 data = dasd_global_profile.data;
790 data->dasd_sum_times += tottime;
791 data->dasd_sum_time_str += strtime;
792 data->dasd_sum_time_irq += irqtime;
793 data->dasd_sum_time_end += endtime;
794 dasd_profile_end_add_data(dasd_global_profile.data,
795 cqr->startdev != block->base,
797 rq_data_dir(req) == READ,
798 sectors, sectors_ind, tottime_ind,
799 tottimeps_ind, strtime_ind,
800 irqtime_ind, irqtimeps_ind,
803 spin_unlock(&dasd_global_profile.lock);
805 spin_lock(&block->profile.lock);
806 if (block->profile.data) {
807 data = block->profile.data;
808 data->dasd_sum_times += tottime;
809 data->dasd_sum_time_str += strtime;
810 data->dasd_sum_time_irq += irqtime;
811 data->dasd_sum_time_end += endtime;
812 dasd_profile_end_add_data(block->profile.data,
813 cqr->startdev != block->base,
815 rq_data_dir(req) == READ,
816 sectors, sectors_ind, tottime_ind,
817 tottimeps_ind, strtime_ind,
818 irqtime_ind, irqtimeps_ind,
821 spin_unlock(&block->profile.lock);
823 spin_lock(&device->profile.lock);
824 if (device->profile.data) {
825 data = device->profile.data;
826 data->dasd_sum_times += tottime;
827 data->dasd_sum_time_str += strtime;
828 data->dasd_sum_time_irq += irqtime;
829 data->dasd_sum_time_end += endtime;
830 dasd_profile_end_add_data(device->profile.data,
831 cqr->startdev != block->base,
833 rq_data_dir(req) == READ,
834 sectors, sectors_ind, tottime_ind,
835 tottimeps_ind, strtime_ind,
836 irqtime_ind, irqtimeps_ind,
839 spin_unlock(&device->profile.lock);
842 void dasd_profile_reset(struct dasd_profile *profile)
844 struct dasd_profile_info *data;
846 spin_lock_bh(&profile->lock);
847 data = profile->data;
849 spin_unlock_bh(&profile->lock);
852 memset(data, 0, sizeof(*data));
853 ktime_get_real_ts64(&data->starttod);
854 spin_unlock_bh(&profile->lock);
857 int dasd_profile_on(struct dasd_profile *profile)
859 struct dasd_profile_info *data;
861 data = kzalloc(sizeof(*data), GFP_KERNEL);
864 spin_lock_bh(&profile->lock);
866 spin_unlock_bh(&profile->lock);
870 ktime_get_real_ts64(&data->starttod);
871 profile->data = data;
872 spin_unlock_bh(&profile->lock);
876 void dasd_profile_off(struct dasd_profile *profile)
878 spin_lock_bh(&profile->lock);
879 kfree(profile->data);
880 profile->data = NULL;
881 spin_unlock_bh(&profile->lock);
884 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
888 buffer = vmalloc(user_len + 1);
890 return ERR_PTR(-ENOMEM);
891 if (copy_from_user(buffer, user_buf, user_len) != 0) {
893 return ERR_PTR(-EFAULT);
895 /* got the string, now strip linefeed. */
896 if (buffer[user_len - 1] == '\n')
897 buffer[user_len - 1] = 0;
899 buffer[user_len] = 0;
903 static ssize_t dasd_stats_write(struct file *file,
904 const char __user *user_buf,
905 size_t user_len, loff_t *pos)
909 struct seq_file *m = (struct seq_file *)file->private_data;
910 struct dasd_profile *prof = m->private;
912 if (user_len > 65536)
914 buffer = dasd_get_user_string(user_buf, user_len);
916 return PTR_ERR(buffer);
918 str = skip_spaces(buffer);
920 if (strncmp(str, "reset", 5) == 0) {
921 dasd_profile_reset(prof);
922 } else if (strncmp(str, "on", 2) == 0) {
923 rc = dasd_profile_on(prof);
927 if (prof == &dasd_global_profile) {
928 dasd_profile_reset(prof);
929 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
931 } else if (strncmp(str, "off", 3) == 0) {
932 if (prof == &dasd_global_profile)
933 dasd_global_profile_level = DASD_PROFILE_OFF;
934 dasd_profile_off(prof);
942 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
946 for (i = 0; i < 32; i++)
947 seq_printf(m, "%u ", array[i]);
951 static void dasd_stats_seq_print(struct seq_file *m,
952 struct dasd_profile_info *data)
954 seq_printf(m, "start_time %lld.%09ld\n",
955 (s64)data->starttod.tv_sec, data->starttod.tv_nsec);
956 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
957 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
958 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
959 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
960 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
961 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
962 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
963 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
964 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
965 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
966 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
967 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
968 seq_puts(m, "histogram_sectors ");
969 dasd_stats_array(m, data->dasd_io_secs);
970 seq_puts(m, "histogram_io_times ");
971 dasd_stats_array(m, data->dasd_io_times);
972 seq_puts(m, "histogram_io_times_weighted ");
973 dasd_stats_array(m, data->dasd_io_timps);
974 seq_puts(m, "histogram_time_build_to_ssch ");
975 dasd_stats_array(m, data->dasd_io_time1);
976 seq_puts(m, "histogram_time_ssch_to_irq ");
977 dasd_stats_array(m, data->dasd_io_time2);
978 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
979 dasd_stats_array(m, data->dasd_io_time2ps);
980 seq_puts(m, "histogram_time_irq_to_end ");
981 dasd_stats_array(m, data->dasd_io_time3);
982 seq_puts(m, "histogram_ccw_queue_length ");
983 dasd_stats_array(m, data->dasd_io_nr_req);
984 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
985 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
986 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
987 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
988 seq_puts(m, "histogram_read_sectors ");
989 dasd_stats_array(m, data->dasd_read_secs);
990 seq_puts(m, "histogram_read_times ");
991 dasd_stats_array(m, data->dasd_read_times);
992 seq_puts(m, "histogram_read_time_build_to_ssch ");
993 dasd_stats_array(m, data->dasd_read_time1);
994 seq_puts(m, "histogram_read_time_ssch_to_irq ");
995 dasd_stats_array(m, data->dasd_read_time2);
996 seq_puts(m, "histogram_read_time_irq_to_end ");
997 dasd_stats_array(m, data->dasd_read_time3);
998 seq_puts(m, "histogram_read_ccw_queue_length ");
999 dasd_stats_array(m, data->dasd_read_nr_req);
1002 static int dasd_stats_show(struct seq_file *m, void *v)
1004 struct dasd_profile *profile;
1005 struct dasd_profile_info *data;
1007 profile = m->private;
1008 spin_lock_bh(&profile->lock);
1009 data = profile->data;
1011 spin_unlock_bh(&profile->lock);
1012 seq_puts(m, "disabled\n");
1015 dasd_stats_seq_print(m, data);
1016 spin_unlock_bh(&profile->lock);
1020 static int dasd_stats_open(struct inode *inode, struct file *file)
1022 struct dasd_profile *profile = inode->i_private;
1023 return single_open(file, dasd_stats_show, profile);
1026 static const struct file_operations dasd_stats_raw_fops = {
1027 .owner = THIS_MODULE,
1028 .open = dasd_stats_open,
1030 .llseek = seq_lseek,
1031 .release = single_release,
1032 .write = dasd_stats_write,
1035 static void dasd_profile_init(struct dasd_profile *profile,
1036 struct dentry *base_dentry)
1043 profile->dentry = NULL;
1044 profile->data = NULL;
1045 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1046 pde = debugfs_create_file("statistics", mode, base_dentry,
1047 profile, &dasd_stats_raw_fops);
1048 if (pde && !IS_ERR(pde))
1049 profile->dentry = pde;
1053 static void dasd_profile_exit(struct dasd_profile *profile)
1055 dasd_profile_off(profile);
1056 debugfs_remove(profile->dentry);
1057 profile->dentry = NULL;
1060 static void dasd_statistics_removeroot(void)
1062 dasd_global_profile_level = DASD_PROFILE_OFF;
1063 dasd_profile_exit(&dasd_global_profile);
1064 debugfs_remove(dasd_debugfs_global_entry);
1065 debugfs_remove(dasd_debugfs_root_entry);
1068 static void dasd_statistics_createroot(void)
1072 dasd_debugfs_root_entry = NULL;
1073 pde = debugfs_create_dir("dasd", NULL);
1074 if (!pde || IS_ERR(pde))
1076 dasd_debugfs_root_entry = pde;
1077 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1078 if (!pde || IS_ERR(pde))
1080 dasd_debugfs_global_entry = pde;
1081 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
1085 DBF_EVENT(DBF_ERR, "%s",
1086 "Creation of the dasd debugfs interface failed");
1087 dasd_statistics_removeroot();
1092 #define dasd_profile_start(block, cqr, req) do {} while (0)
1093 #define dasd_profile_end(block, cqr, req) do {} while (0)
1095 static void dasd_statistics_createroot(void)
1100 static void dasd_statistics_removeroot(void)
1105 int dasd_stats_generic_show(struct seq_file *m, void *v)
1107 seq_puts(m, "Statistics are not activated in this kernel\n");
1111 static void dasd_profile_init(struct dasd_profile *profile,
1112 struct dentry *base_dentry)
1117 static void dasd_profile_exit(struct dasd_profile *profile)
1122 int dasd_profile_on(struct dasd_profile *profile)
1127 #endif /* CONFIG_DASD_PROFILE */
1129 static int dasd_hosts_show(struct seq_file *m, void *v)
1131 struct dasd_device *device;
1132 int rc = -EOPNOTSUPP;
1134 device = m->private;
1135 dasd_get_device(device);
1137 if (device->discipline->hosts_print)
1138 rc = device->discipline->hosts_print(device, m);
1140 dasd_put_device(device);
1144 DEFINE_SHOW_ATTRIBUTE(dasd_hosts);
1146 static void dasd_hosts_exit(struct dasd_device *device)
1148 debugfs_remove(device->hosts_dentry);
1149 device->hosts_dentry = NULL;
1152 static void dasd_hosts_init(struct dentry *base_dentry,
1153 struct dasd_device *device)
1161 mode = S_IRUSR | S_IFREG;
1162 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1163 device, &dasd_hosts_fops);
1164 if (pde && !IS_ERR(pde))
1165 device->hosts_dentry = pde;
1168 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, int datasize,
1169 struct dasd_device *device,
1170 struct dasd_ccw_req *cqr)
1172 unsigned long flags;
1177 size += cplength * sizeof(struct ccw1);
1181 size += (sizeof(*cqr) + 7L) & -8L;
1183 spin_lock_irqsave(&device->mem_lock, flags);
1184 data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size);
1185 spin_unlock_irqrestore(&device->mem_lock, flags);
1187 return ERR_PTR(-ENOMEM);
1189 cqr = (void *) data;
1190 data += (sizeof(*cqr) + 7L) & -8L;
1192 memset(cqr, 0, sizeof(*cqr));
1193 cqr->mem_chunk = chunk;
1196 data += cplength * sizeof(struct ccw1);
1197 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1201 memset(cqr->data, 0, datasize);
1204 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1205 dasd_get_device(device);
1208 EXPORT_SYMBOL(dasd_smalloc_request);
1210 struct dasd_ccw_req *dasd_fmalloc_request(int magic, int cplength,
1212 struct dasd_device *device)
1214 struct dasd_ccw_req *cqr;
1215 unsigned long flags;
1219 cqr_size = (sizeof(*cqr) + 7L) & -8L;
1222 size += cplength * sizeof(struct ccw1);
1226 spin_lock_irqsave(&device->mem_lock, flags);
1227 cqr = dasd_alloc_chunk(&device->ese_chunks, size);
1228 spin_unlock_irqrestore(&device->mem_lock, flags);
1230 return ERR_PTR(-ENOMEM);
1231 memset(cqr, 0, sizeof(*cqr));
1232 data = (char *)cqr + cqr_size;
1236 data += cplength * sizeof(struct ccw1);
1237 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1242 memset(cqr->data, 0, datasize);
1246 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1247 dasd_get_device(device);
1251 EXPORT_SYMBOL(dasd_fmalloc_request);
1253 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1255 unsigned long flags;
1257 spin_lock_irqsave(&device->mem_lock, flags);
1258 dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk);
1259 spin_unlock_irqrestore(&device->mem_lock, flags);
1260 dasd_put_device(device);
1262 EXPORT_SYMBOL(dasd_sfree_request);
1264 void dasd_ffree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1266 unsigned long flags;
1268 spin_lock_irqsave(&device->mem_lock, flags);
1269 dasd_free_chunk(&device->ese_chunks, cqr);
1270 spin_unlock_irqrestore(&device->mem_lock, flags);
1271 dasd_put_device(device);
1273 EXPORT_SYMBOL(dasd_ffree_request);
1276 * Check discipline magic in cqr.
1278 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1280 struct dasd_device *device;
1284 device = cqr->startdev;
1285 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1286 DBF_DEV_EVENT(DBF_WARNING, device,
1287 " dasd_ccw_req 0x%08x magic doesn't match"
1288 " discipline 0x%08x",
1290 *(unsigned int *) device->discipline->name);
1297 * Terminate the current i/o and set the request to clear_pending.
1298 * Timer keeps device runnig.
1299 * ccw_device_clear can fail if the i/o subsystem
1302 int dasd_term_IO(struct dasd_ccw_req *cqr)
1304 struct dasd_device *device;
1306 char errorstring[ERRORLENGTH];
1309 rc = dasd_check_cqr(cqr);
1313 device = (struct dasd_device *) cqr->startdev;
1314 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1315 rc = ccw_device_clear(device->cdev, (long) cqr);
1317 case 0: /* termination successful */
1318 cqr->status = DASD_CQR_CLEAR_PENDING;
1319 cqr->stopclk = get_tod_clock();
1321 DBF_DEV_EVENT(DBF_DEBUG, device,
1322 "terminate cqr %p successful",
1326 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1327 "device gone, retry");
1331 * device not valid so no I/O could be running
1332 * handle CQR as termination successful
1334 cqr->status = DASD_CQR_CLEARED;
1335 cqr->stopclk = get_tod_clock();
1337 /* no retries for invalid devices */
1339 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1340 "EINVAL, handle as terminated");
1341 /* fake rc to success */
1345 /* internal error 10 - unknown rc*/
1346 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1347 dev_err(&device->cdev->dev, "An error occurred in the "
1348 "DASD device driver, reason=%s\n", errorstring);
1354 dasd_schedule_device_bh(device);
1357 EXPORT_SYMBOL(dasd_term_IO);
1360 * Start the i/o. This start_IO can fail if the channel is really busy.
1361 * In that case set up a timer to start the request later.
1363 int dasd_start_IO(struct dasd_ccw_req *cqr)
1365 struct dasd_device *device;
1367 char errorstring[ERRORLENGTH];
1370 rc = dasd_check_cqr(cqr);
1375 device = (struct dasd_device *) cqr->startdev;
1377 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1378 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1379 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1380 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1381 "because of stolen lock", cqr);
1382 cqr->status = DASD_CQR_ERROR;
1383 cqr->intrc = -EPERM;
1386 if (cqr->retries < 0) {
1387 /* internal error 14 - start_IO run out of retries */
1388 sprintf(errorstring, "14 %p", cqr);
1389 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1390 "device driver, reason=%s\n", errorstring);
1391 cqr->status = DASD_CQR_ERROR;
1394 cqr->startclk = get_tod_clock();
1395 cqr->starttime = jiffies;
1397 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1398 cqr->lpm &= dasd_path_get_opm(device);
1400 cqr->lpm = dasd_path_get_opm(device);
1403 * remember the amount of formatted tracks to prevent double format on
1407 cqr->trkcount = atomic_read(&cqr->block->trkcount);
1409 if (cqr->cpmode == 1) {
1410 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1411 (long) cqr, cqr->lpm);
1413 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1414 (long) cqr, cqr->lpm, 0);
1418 cqr->status = DASD_CQR_IN_IO;
1421 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1422 "start_IO: device busy, retry later");
1425 /* -EACCES indicates that the request used only a subset of the
1426 * available paths and all these paths are gone. If the lpm of
1427 * this request was only a subset of the opm (e.g. the ppm) then
1428 * we just do a retry with all available paths.
1429 * If we already use the full opm, something is amiss, and we
1430 * need a full path verification.
1432 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1433 DBF_DEV_EVENT(DBF_WARNING, device,
1434 "start_IO: selected paths gone (%x)",
1436 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1437 cqr->lpm = dasd_path_get_opm(device);
1438 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1439 "start_IO: selected paths gone,"
1440 " retry on all paths");
1442 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1443 "start_IO: all paths in opm gone,"
1444 " do path verification");
1445 dasd_generic_last_path_gone(device);
1446 dasd_path_no_path(device);
1447 dasd_path_set_tbvpm(device,
1448 ccw_device_get_path_mask(
1453 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1454 "start_IO: -ENODEV device gone, retry");
1455 /* this is equivalent to CC=3 for SSCH report this to EER */
1456 dasd_handle_autoquiesce(device, cqr, DASD_EER_STARTIO);
1459 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1460 "start_IO: -EIO device gone, retry");
1463 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1464 "start_IO: -EINVAL device currently "
1468 /* internal error 11 - unknown rc */
1469 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1470 dev_err(&device->cdev->dev,
1471 "An error occurred in the DASD device driver, "
1472 "reason=%s\n", errorstring);
1479 EXPORT_SYMBOL(dasd_start_IO);
1482 * Timeout function for dasd devices. This is used for different purposes
1483 * 1) missing interrupt handler for normal operation
1484 * 2) delayed start of request where start_IO failed with -EBUSY
1485 * 3) timeout for missing state change interrupts
1486 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1487 * DASD_CQR_QUEUED for 2) and 3).
1489 static void dasd_device_timeout(struct timer_list *t)
1491 unsigned long flags;
1492 struct dasd_device *device;
1494 device = from_timer(device, t, timer);
1495 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1496 /* re-activate request queue */
1497 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1498 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1499 dasd_schedule_device_bh(device);
1503 * Setup timeout for a device in jiffies.
1505 void dasd_device_set_timer(struct dasd_device *device, int expires)
1508 del_timer(&device->timer);
1510 mod_timer(&device->timer, jiffies + expires);
1512 EXPORT_SYMBOL(dasd_device_set_timer);
1515 * Clear timeout for a device.
1517 void dasd_device_clear_timer(struct dasd_device *device)
1519 del_timer(&device->timer);
1521 EXPORT_SYMBOL(dasd_device_clear_timer);
1523 static void dasd_handle_killed_request(struct ccw_device *cdev,
1524 unsigned long intparm)
1526 struct dasd_ccw_req *cqr;
1527 struct dasd_device *device;
1531 cqr = (struct dasd_ccw_req *) intparm;
1532 if (cqr->status != DASD_CQR_IN_IO) {
1533 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1534 "invalid status in handle_killed_request: "
1535 "%02x", cqr->status);
1539 device = dasd_device_from_cdev_locked(cdev);
1540 if (IS_ERR(device)) {
1541 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1542 "unable to get device from cdev");
1546 if (!cqr->startdev ||
1547 device != cqr->startdev ||
1548 strncmp(cqr->startdev->discipline->ebcname,
1549 (char *) &cqr->magic, 4)) {
1550 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1551 "invalid device in request");
1552 dasd_put_device(device);
1556 /* Schedule request to be retried. */
1557 cqr->status = DASD_CQR_QUEUED;
1559 dasd_device_clear_timer(device);
1560 dasd_schedule_device_bh(device);
1561 dasd_put_device(device);
1564 void dasd_generic_handle_state_change(struct dasd_device *device)
1566 /* First of all start sense subsystem status request. */
1567 dasd_eer_snss(device);
1569 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1570 dasd_schedule_device_bh(device);
1571 if (device->block) {
1572 dasd_schedule_block_bh(device->block);
1573 if (device->block->gdp)
1574 blk_mq_run_hw_queues(device->block->gdp->queue, true);
1577 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
1579 static int dasd_check_hpf_error(struct irb *irb)
1581 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1582 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1583 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1586 static int dasd_ese_needs_format(struct dasd_block *block, struct irb *irb)
1588 struct dasd_device *device = NULL;
1593 device = block->base;
1594 if (!device || !device->discipline->is_ese)
1596 if (!device->discipline->is_ese(device))
1599 sense = dasd_get_sense(irb);
1603 return !!(sense[1] & SNS1_NO_REC_FOUND) ||
1604 !!(sense[1] & SNS1_FILE_PROTECTED) ||
1605 scsw_cstat(&irb->scsw) == SCHN_STAT_INCORR_LEN;
1608 static int dasd_ese_oos_cond(u8 *sense)
1610 return sense[0] & SNS0_EQUIPMENT_CHECK &&
1611 sense[1] & SNS1_PERM_ERR &&
1612 sense[1] & SNS1_WRITE_INHIBITED &&
1617 * Interrupt handler for "normal" ssch-io based dasd devices.
1619 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1622 struct dasd_ccw_req *cqr, *next, *fcqr;
1623 struct dasd_device *device;
1625 int nrf_suppressed = 0;
1626 int fp_suppressed = 0;
1627 struct request *req;
1631 cqr = (struct dasd_ccw_req *) intparm;
1633 switch (PTR_ERR(irb)) {
1635 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1636 device = cqr->startdev;
1637 cqr->status = DASD_CQR_CLEARED;
1638 dasd_device_clear_timer(device);
1639 wake_up(&dasd_flush_wq);
1640 dasd_schedule_device_bh(device);
1645 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1646 "request timed out\n", __func__);
1649 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1650 "unknown error %ld\n", __func__,
1653 dasd_handle_killed_request(cdev, intparm);
1657 now = get_tod_clock();
1658 /* check for conditions that should be handled immediately */
1660 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1661 scsw_cstat(&irb->scsw) == 0)) {
1663 memcpy(&cqr->irb, irb, sizeof(*irb));
1664 device = dasd_device_from_cdev_locked(cdev);
1667 /* ignore unsolicited interrupts for DIAG discipline */
1668 if (device->discipline == dasd_diag_discipline_pointer) {
1669 dasd_put_device(device);
1674 * In some cases 'File Protected' or 'No Record Found' errors
1675 * might be expected and debug log messages for the
1676 * corresponding interrupts shouldn't be written then.
1677 * Check if either of the according suppress bits is set.
1679 sense = dasd_get_sense(irb);
1681 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1682 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1683 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1684 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1687 * Extent pool probably out-of-space.
1688 * Stop device and check exhaust level.
1690 if (dasd_ese_oos_cond(sense)) {
1691 dasd_generic_space_exhaust(device, cqr);
1692 device->discipline->ext_pool_exhaust(device, cqr);
1693 dasd_put_device(device);
1697 if (!(fp_suppressed || nrf_suppressed))
1698 device->discipline->dump_sense_dbf(device, irb, "int");
1700 if (device->features & DASD_FEATURE_ERPLOG)
1701 device->discipline->dump_sense(device, cqr, irb);
1702 device->discipline->check_for_device_change(device, cqr, irb);
1703 dasd_put_device(device);
1706 /* check for attention message */
1707 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1708 device = dasd_device_from_cdev_locked(cdev);
1709 if (!IS_ERR(device)) {
1710 device->discipline->check_attention(device,
1711 irb->esw.esw1.lpum);
1712 dasd_put_device(device);
1719 device = (struct dasd_device *) cqr->startdev;
1721 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1722 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1723 "invalid device in request");
1727 if (dasd_ese_needs_format(cqr->block, irb)) {
1728 req = dasd_get_callback_data(cqr);
1730 cqr->status = DASD_CQR_ERROR;
1733 if (rq_data_dir(req) == READ) {
1734 device->discipline->ese_read(cqr, irb);
1735 cqr->status = DASD_CQR_SUCCESS;
1737 dasd_device_clear_timer(device);
1738 dasd_schedule_device_bh(device);
1741 fcqr = device->discipline->ese_format(device, cqr, irb);
1743 if (PTR_ERR(fcqr) == -EINVAL) {
1744 cqr->status = DASD_CQR_ERROR;
1748 * If we can't format now, let the request go
1749 * one extra round. Maybe we can format later.
1751 cqr->status = DASD_CQR_QUEUED;
1752 dasd_schedule_device_bh(device);
1755 fcqr->status = DASD_CQR_QUEUED;
1756 cqr->status = DASD_CQR_QUEUED;
1757 list_add(&fcqr->devlist, &device->ccw_queue);
1758 dasd_schedule_device_bh(device);
1763 /* Check for clear pending */
1764 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1765 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1766 cqr->status = DASD_CQR_CLEARED;
1767 dasd_device_clear_timer(device);
1768 wake_up(&dasd_flush_wq);
1769 dasd_schedule_device_bh(device);
1773 /* check status - the request might have been killed by dyn detach */
1774 if (cqr->status != DASD_CQR_IN_IO) {
1775 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1776 "status %02x", dev_name(&cdev->dev), cqr->status);
1782 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1783 scsw_cstat(&irb->scsw) == 0) {
1784 /* request was completed successfully */
1785 cqr->status = DASD_CQR_SUCCESS;
1787 /* Start first request on queue if possible -> fast_io. */
1788 if (cqr->devlist.next != &device->ccw_queue) {
1789 next = list_entry(cqr->devlist.next,
1790 struct dasd_ccw_req, devlist);
1792 } else { /* error */
1793 /* check for HPF error
1794 * call discipline function to requeue all requests
1795 * and disable HPF accordingly
1797 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1798 device->discipline->handle_hpf_error)
1799 device->discipline->handle_hpf_error(device, irb);
1801 * If we don't want complex ERP for this request, then just
1802 * reset this and retry it in the fastpath
1804 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1806 if (cqr->lpm == dasd_path_get_opm(device))
1807 DBF_DEV_EVENT(DBF_DEBUG, device,
1808 "default ERP in fastpath "
1809 "(%i retries left)",
1811 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1812 cqr->lpm = dasd_path_get_opm(device);
1813 cqr->status = DASD_CQR_QUEUED;
1816 cqr->status = DASD_CQR_ERROR;
1818 if (next && (next->status == DASD_CQR_QUEUED) &&
1819 (!device->stopped)) {
1820 if (device->discipline->start_IO(next) == 0)
1821 expires = next->expires;
1824 dasd_device_set_timer(device, expires);
1826 dasd_device_clear_timer(device);
1827 dasd_schedule_device_bh(device);
1829 EXPORT_SYMBOL(dasd_int_handler);
1831 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1833 struct dasd_device *device;
1835 device = dasd_device_from_cdev_locked(cdev);
1839 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1840 device->state != device->target ||
1841 !device->discipline->check_for_device_change){
1842 dasd_put_device(device);
1845 if (device->discipline->dump_sense_dbf)
1846 device->discipline->dump_sense_dbf(device, irb, "uc");
1847 device->discipline->check_for_device_change(device, NULL, irb);
1848 dasd_put_device(device);
1850 return UC_TODO_RETRY;
1852 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1855 * If we have an error on a dasd_block layer request then we cancel
1856 * and return all further requests from the same dasd_block as well.
1858 static void __dasd_device_recovery(struct dasd_device *device,
1859 struct dasd_ccw_req *ref_cqr)
1861 struct list_head *l, *n;
1862 struct dasd_ccw_req *cqr;
1865 * only requeue request that came from the dasd_block layer
1867 if (!ref_cqr->block)
1870 list_for_each_safe(l, n, &device->ccw_queue) {
1871 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1872 if (cqr->status == DASD_CQR_QUEUED &&
1873 ref_cqr->block == cqr->block) {
1874 cqr->status = DASD_CQR_CLEARED;
1880 * Remove those ccw requests from the queue that need to be returned
1881 * to the upper layer.
1883 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1884 struct list_head *final_queue)
1886 struct list_head *l, *n;
1887 struct dasd_ccw_req *cqr;
1889 /* Process request with final status. */
1890 list_for_each_safe(l, n, &device->ccw_queue) {
1891 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1893 /* Skip any non-final request. */
1894 if (cqr->status == DASD_CQR_QUEUED ||
1895 cqr->status == DASD_CQR_IN_IO ||
1896 cqr->status == DASD_CQR_CLEAR_PENDING)
1898 if (cqr->status == DASD_CQR_ERROR) {
1899 __dasd_device_recovery(device, cqr);
1901 /* Rechain finished requests to final queue */
1902 list_move_tail(&cqr->devlist, final_queue);
1906 static void __dasd_process_cqr(struct dasd_device *device,
1907 struct dasd_ccw_req *cqr)
1909 char errorstring[ERRORLENGTH];
1911 switch (cqr->status) {
1912 case DASD_CQR_SUCCESS:
1913 cqr->status = DASD_CQR_DONE;
1915 case DASD_CQR_ERROR:
1916 cqr->status = DASD_CQR_NEED_ERP;
1918 case DASD_CQR_CLEARED:
1919 cqr->status = DASD_CQR_TERMINATED;
1922 /* internal error 12 - wrong cqr status*/
1923 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1924 dev_err(&device->cdev->dev,
1925 "An error occurred in the DASD device driver, "
1926 "reason=%s\n", errorstring);
1930 cqr->callback(cqr, cqr->callback_data);
1934 * the cqrs from the final queue are returned to the upper layer
1935 * by setting a dasd_block state and calling the callback function
1937 static void __dasd_device_process_final_queue(struct dasd_device *device,
1938 struct list_head *final_queue)
1940 struct list_head *l, *n;
1941 struct dasd_ccw_req *cqr;
1942 struct dasd_block *block;
1944 list_for_each_safe(l, n, final_queue) {
1945 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1946 list_del_init(&cqr->devlist);
1949 __dasd_process_cqr(device, cqr);
1951 spin_lock_bh(&block->queue_lock);
1952 __dasd_process_cqr(device, cqr);
1953 spin_unlock_bh(&block->queue_lock);
1959 * check if device should be autoquiesced due to too many timeouts
1961 static void __dasd_device_check_autoquiesce_timeout(struct dasd_device *device,
1962 struct dasd_ccw_req *cqr)
1964 if ((device->default_retries - cqr->retries) >= device->aq_timeouts)
1965 dasd_handle_autoquiesce(device, cqr, DASD_EER_TIMEOUTS);
1969 * Take a look at the first request on the ccw queue and check
1970 * if it reached its expire time. If so, terminate the IO.
1972 static void __dasd_device_check_expire(struct dasd_device *device)
1974 struct dasd_ccw_req *cqr;
1976 if (list_empty(&device->ccw_queue))
1978 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1979 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1980 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1981 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1983 * IO in safe offline processing should not
1984 * run out of retries
1988 if (device->discipline->term_IO(cqr) != 0) {
1989 /* Hmpf, try again in 5 sec */
1990 dev_err(&device->cdev->dev,
1991 "cqr %p timed out (%lus) but cannot be "
1992 "ended, retrying in 5 s\n",
1993 cqr, (cqr->expires/HZ));
1994 cqr->expires += 5*HZ;
1995 dasd_device_set_timer(device, 5*HZ);
1997 dev_err(&device->cdev->dev,
1998 "cqr %p timed out (%lus), %i retries "
1999 "remaining\n", cqr, (cqr->expires/HZ),
2002 __dasd_device_check_autoquiesce_timeout(device, cqr);
2007 * return 1 when device is not eligible for IO
2009 static int __dasd_device_is_unusable(struct dasd_device *device,
2010 struct dasd_ccw_req *cqr)
2012 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_STOPPED_NOSPC);
2014 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2015 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
2017 * dasd is being set offline
2018 * but it is no safe offline where we have to allow I/O
2022 if (device->stopped) {
2023 if (device->stopped & mask) {
2024 /* stopped and CQR will not change that. */
2027 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2028 /* CQR is not able to change device to
2032 /* CQR required to get device operational. */
2038 * Take a look at the first request on the ccw queue and check
2039 * if it needs to be started.
2041 static void __dasd_device_start_head(struct dasd_device *device)
2043 struct dasd_ccw_req *cqr;
2046 if (list_empty(&device->ccw_queue))
2048 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2049 if (cqr->status != DASD_CQR_QUEUED)
2051 /* if device is not usable return request to upper layer */
2052 if (__dasd_device_is_unusable(device, cqr)) {
2053 cqr->intrc = -EAGAIN;
2054 cqr->status = DASD_CQR_CLEARED;
2055 dasd_schedule_device_bh(device);
2059 rc = device->discipline->start_IO(cqr);
2061 dasd_device_set_timer(device, cqr->expires);
2062 else if (rc == -EACCES) {
2063 dasd_schedule_device_bh(device);
2065 /* Hmpf, try again in 1/2 sec */
2066 dasd_device_set_timer(device, 50);
2069 static void __dasd_device_check_path_events(struct dasd_device *device)
2071 __u8 tbvpm, fcsecpm;
2074 tbvpm = dasd_path_get_tbvpm(device);
2075 fcsecpm = dasd_path_get_fcsecpm(device);
2077 if (!tbvpm && !fcsecpm)
2080 if (device->stopped & ~(DASD_STOPPED_DC_WAIT))
2083 dasd_path_clear_all_verify(device);
2084 dasd_path_clear_all_fcsec(device);
2086 rc = device->discipline->pe_handler(device, tbvpm, fcsecpm);
2088 dasd_path_add_tbvpm(device, tbvpm);
2089 dasd_path_add_fcsecpm(device, fcsecpm);
2090 dasd_device_set_timer(device, 50);
2095 * Go through all request on the dasd_device request queue,
2096 * terminate them on the cdev if necessary, and return them to the
2097 * submitting layer via callback.
2099 * Make sure that all 'submitting layers' still exist when
2100 * this function is called!. In other words, when 'device' is a base
2101 * device then all block layer requests must have been removed before
2102 * via dasd_flush_block_queue.
2104 int dasd_flush_device_queue(struct dasd_device *device)
2106 struct dasd_ccw_req *cqr, *n;
2108 struct list_head flush_queue;
2110 INIT_LIST_HEAD(&flush_queue);
2111 spin_lock_irq(get_ccwdev_lock(device->cdev));
2113 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2114 /* Check status and move request to flush_queue */
2115 switch (cqr->status) {
2116 case DASD_CQR_IN_IO:
2117 rc = device->discipline->term_IO(cqr);
2119 /* unable to terminate requeust */
2120 dev_err(&device->cdev->dev,
2121 "Flushing the DASD request queue "
2122 "failed for request %p\n", cqr);
2123 /* stop flush processing */
2127 case DASD_CQR_QUEUED:
2128 cqr->stopclk = get_tod_clock();
2129 cqr->status = DASD_CQR_CLEARED;
2131 default: /* no need to modify the others */
2134 list_move_tail(&cqr->devlist, &flush_queue);
2137 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2139 * After this point all requests must be in state CLEAR_PENDING,
2140 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2141 * one of the others.
2143 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2144 wait_event(dasd_flush_wq,
2145 (cqr->status != DASD_CQR_CLEAR_PENDING));
2147 * Now set each request back to TERMINATED, DONE or NEED_ERP
2148 * and call the callback function of flushed requests
2150 __dasd_device_process_final_queue(device, &flush_queue);
2153 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2156 * Acquire the device lock and process queues for the device.
2158 static void dasd_device_tasklet(unsigned long data)
2160 struct dasd_device *device = (struct dasd_device *) data;
2161 struct list_head final_queue;
2163 atomic_set (&device->tasklet_scheduled, 0);
2164 INIT_LIST_HEAD(&final_queue);
2165 spin_lock_irq(get_ccwdev_lock(device->cdev));
2166 /* Check expire time of first request on the ccw queue. */
2167 __dasd_device_check_expire(device);
2168 /* find final requests on ccw queue */
2169 __dasd_device_process_ccw_queue(device, &final_queue);
2170 __dasd_device_check_path_events(device);
2171 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2172 /* Now call the callback function of requests with final status */
2173 __dasd_device_process_final_queue(device, &final_queue);
2174 spin_lock_irq(get_ccwdev_lock(device->cdev));
2175 /* Now check if the head of the ccw queue needs to be started. */
2176 __dasd_device_start_head(device);
2177 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2178 if (waitqueue_active(&shutdown_waitq))
2179 wake_up(&shutdown_waitq);
2180 dasd_put_device(device);
2184 * Schedules a call to dasd_tasklet over the device tasklet.
2186 void dasd_schedule_device_bh(struct dasd_device *device)
2188 /* Protect against rescheduling. */
2189 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2191 dasd_get_device(device);
2192 tasklet_hi_schedule(&device->tasklet);
2194 EXPORT_SYMBOL(dasd_schedule_device_bh);
2196 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2198 device->stopped |= bits;
2200 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2202 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2204 device->stopped &= ~bits;
2205 if (!device->stopped)
2206 wake_up(&generic_waitq);
2208 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2211 * Queue a request to the head of the device ccw_queue.
2212 * Start the I/O if possible.
2214 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2216 struct dasd_device *device;
2217 unsigned long flags;
2219 device = cqr->startdev;
2220 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2221 cqr->status = DASD_CQR_QUEUED;
2222 list_add(&cqr->devlist, &device->ccw_queue);
2223 /* let the bh start the request to keep them in order */
2224 dasd_schedule_device_bh(device);
2225 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2227 EXPORT_SYMBOL(dasd_add_request_head);
2230 * Queue a request to the tail of the device ccw_queue.
2231 * Start the I/O if possible.
2233 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2235 struct dasd_device *device;
2236 unsigned long flags;
2238 device = cqr->startdev;
2239 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2240 cqr->status = DASD_CQR_QUEUED;
2241 list_add_tail(&cqr->devlist, &device->ccw_queue);
2242 /* let the bh start the request to keep them in order */
2243 dasd_schedule_device_bh(device);
2244 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2246 EXPORT_SYMBOL(dasd_add_request_tail);
2249 * Wakeup helper for the 'sleep_on' functions.
2251 void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2253 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2254 cqr->callback_data = DASD_SLEEPON_END_TAG;
2255 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2256 wake_up(&generic_waitq);
2258 EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
2260 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2262 struct dasd_device *device;
2265 device = cqr->startdev;
2266 spin_lock_irq(get_ccwdev_lock(device->cdev));
2267 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2268 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2273 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2275 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2277 struct dasd_device *device;
2278 dasd_erp_fn_t erp_fn;
2280 if (cqr->status == DASD_CQR_FILLED)
2282 device = cqr->startdev;
2283 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2284 if (cqr->status == DASD_CQR_TERMINATED) {
2285 device->discipline->handle_terminated_request(cqr);
2288 if (cqr->status == DASD_CQR_NEED_ERP) {
2289 erp_fn = device->discipline->erp_action(cqr);
2293 if (cqr->status == DASD_CQR_FAILED)
2294 dasd_log_sense(cqr, &cqr->irb);
2296 __dasd_process_erp(device, cqr);
2303 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2305 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2306 if (cqr->refers) /* erp is not done yet */
2308 return ((cqr->status != DASD_CQR_DONE) &&
2309 (cqr->status != DASD_CQR_FAILED));
2311 return (cqr->status == DASD_CQR_FILLED);
2314 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2316 struct dasd_device *device;
2318 struct list_head ccw_queue;
2319 struct dasd_ccw_req *cqr;
2321 INIT_LIST_HEAD(&ccw_queue);
2322 maincqr->status = DASD_CQR_FILLED;
2323 device = maincqr->startdev;
2324 list_add(&maincqr->blocklist, &ccw_queue);
2325 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2326 cqr = list_first_entry(&ccw_queue,
2327 struct dasd_ccw_req, blocklist)) {
2329 if (__dasd_sleep_on_erp(cqr))
2331 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2333 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2334 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2335 cqr->status = DASD_CQR_FAILED;
2336 cqr->intrc = -EPERM;
2339 /* Non-temporary stop condition will trigger fail fast */
2340 if (device->stopped & ~DASD_STOPPED_PENDING &&
2341 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2342 !dasd_eer_enabled(device) && device->aq_mask == 0) {
2343 cqr->status = DASD_CQR_FAILED;
2344 cqr->intrc = -ENOLINK;
2348 * Don't try to start requests if device is in
2349 * offline processing, it might wait forever
2351 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2352 cqr->status = DASD_CQR_FAILED;
2353 cqr->intrc = -ENODEV;
2357 * Don't try to start requests if device is stopped
2358 * except path verification requests
2360 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2361 if (interruptible) {
2362 rc = wait_event_interruptible(
2363 generic_waitq, !(device->stopped));
2364 if (rc == -ERESTARTSYS) {
2365 cqr->status = DASD_CQR_FAILED;
2366 maincqr->intrc = rc;
2370 wait_event(generic_waitq, !(device->stopped));
2373 cqr->callback = dasd_wakeup_cb;
2375 cqr->callback_data = DASD_SLEEPON_START_TAG;
2376 dasd_add_request_tail(cqr);
2377 if (interruptible) {
2378 rc = wait_event_interruptible(
2379 generic_waitq, _wait_for_wakeup(cqr));
2380 if (rc == -ERESTARTSYS) {
2381 dasd_cancel_req(cqr);
2382 /* wait (non-interruptible) for final status */
2383 wait_event(generic_waitq,
2384 _wait_for_wakeup(cqr));
2385 cqr->status = DASD_CQR_FAILED;
2386 maincqr->intrc = rc;
2390 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2393 maincqr->endclk = get_tod_clock();
2394 if ((maincqr->status != DASD_CQR_DONE) &&
2395 (maincqr->intrc != -ERESTARTSYS))
2396 dasd_log_sense(maincqr, &maincqr->irb);
2397 if (maincqr->status == DASD_CQR_DONE)
2399 else if (maincqr->intrc)
2400 rc = maincqr->intrc;
2406 static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2408 struct dasd_ccw_req *cqr;
2410 list_for_each_entry(cqr, ccw_queue, blocklist) {
2411 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2418 static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2420 struct dasd_device *device;
2421 struct dasd_ccw_req *cqr, *n;
2426 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2427 device = cqr->startdev;
2428 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2431 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2432 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2433 cqr->status = DASD_CQR_FAILED;
2434 cqr->intrc = -EPERM;
2437 /*Non-temporary stop condition will trigger fail fast*/
2438 if (device->stopped & ~DASD_STOPPED_PENDING &&
2439 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2440 !dasd_eer_enabled(device)) {
2441 cqr->status = DASD_CQR_FAILED;
2442 cqr->intrc = -EAGAIN;
2446 /*Don't try to start requests if device is stopped*/
2447 if (interruptible) {
2448 rc = wait_event_interruptible(
2449 generic_waitq, !device->stopped);
2450 if (rc == -ERESTARTSYS) {
2451 cqr->status = DASD_CQR_FAILED;
2456 wait_event(generic_waitq, !(device->stopped));
2459 cqr->callback = dasd_wakeup_cb;
2460 cqr->callback_data = DASD_SLEEPON_START_TAG;
2461 dasd_add_request_tail(cqr);
2464 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2467 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2469 * In some cases the 'File Protected' or 'Incorrect Length'
2470 * error might be expected and error recovery would be
2471 * unnecessary in these cases. Check if the according suppress
2474 sense = dasd_get_sense(&cqr->irb);
2475 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2476 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2478 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2479 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2483 * for alias devices simplify error recovery and
2484 * return to upper layer
2485 * do not skip ERP requests
2487 if (cqr->startdev != cqr->basedev && !cqr->refers &&
2488 (cqr->status == DASD_CQR_TERMINATED ||
2489 cqr->status == DASD_CQR_NEED_ERP))
2492 /* normal recovery for basedev IO */
2493 if (__dasd_sleep_on_erp(cqr))
2494 /* handle erp first */
2502 * Queue a request to the tail of the device ccw_queue and wait for
2505 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2507 return _dasd_sleep_on(cqr, 0);
2509 EXPORT_SYMBOL(dasd_sleep_on);
2512 * Start requests from a ccw_queue and wait for their completion.
2514 int dasd_sleep_on_queue(struct list_head *ccw_queue)
2516 return _dasd_sleep_on_queue(ccw_queue, 0);
2518 EXPORT_SYMBOL(dasd_sleep_on_queue);
2521 * Start requests from a ccw_queue and wait interruptible for their completion.
2523 int dasd_sleep_on_queue_interruptible(struct list_head *ccw_queue)
2525 return _dasd_sleep_on_queue(ccw_queue, 1);
2527 EXPORT_SYMBOL(dasd_sleep_on_queue_interruptible);
2530 * Queue a request to the tail of the device ccw_queue and wait
2531 * interruptible for it's completion.
2533 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2535 return _dasd_sleep_on(cqr, 1);
2537 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2540 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2541 * for eckd devices) the currently running request has to be terminated
2542 * and be put back to status queued, before the special request is added
2543 * to the head of the queue. Then the special request is waited on normally.
2545 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2547 struct dasd_ccw_req *cqr;
2550 if (list_empty(&device->ccw_queue))
2552 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2553 rc = device->discipline->term_IO(cqr);
2556 * CQR terminated because a more important request is pending.
2557 * Undo decreasing of retry counter because this is
2558 * not an error case.
2564 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2566 struct dasd_device *device;
2569 device = cqr->startdev;
2570 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2571 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2572 cqr->status = DASD_CQR_FAILED;
2573 cqr->intrc = -EPERM;
2576 spin_lock_irq(get_ccwdev_lock(device->cdev));
2577 rc = _dasd_term_running_cqr(device);
2579 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2582 cqr->callback = dasd_wakeup_cb;
2583 cqr->callback_data = DASD_SLEEPON_START_TAG;
2584 cqr->status = DASD_CQR_QUEUED;
2586 * add new request as second
2587 * first the terminated cqr needs to be finished
2589 list_add(&cqr->devlist, device->ccw_queue.next);
2591 /* let the bh start the request to keep them in order */
2592 dasd_schedule_device_bh(device);
2594 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2596 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2598 if (cqr->status == DASD_CQR_DONE)
2600 else if (cqr->intrc)
2606 dasd_schedule_device_bh(device);
2608 dasd_schedule_block_bh(device->block);
2612 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2615 * Cancels a request that was started with dasd_sleep_on_req.
2616 * This is useful to timeout requests. The request will be
2617 * terminated if it is currently in i/o.
2618 * Returns 0 if request termination was successful
2619 * negative error code if termination failed
2620 * Cancellation of a request is an asynchronous operation! The calling
2621 * function has to wait until the request is properly returned via callback.
2623 static int __dasd_cancel_req(struct dasd_ccw_req *cqr)
2625 struct dasd_device *device = cqr->startdev;
2628 switch (cqr->status) {
2629 case DASD_CQR_QUEUED:
2630 /* request was not started - just set to cleared */
2631 cqr->status = DASD_CQR_CLEARED;
2633 case DASD_CQR_IN_IO:
2634 /* request in IO - terminate IO and release again */
2635 rc = device->discipline->term_IO(cqr);
2637 dev_err(&device->cdev->dev,
2638 "Cancelling request %p failed with rc=%d\n",
2641 cqr->stopclk = get_tod_clock();
2644 default: /* already finished or clear pending - do nothing */
2647 dasd_schedule_device_bh(device);
2651 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2653 struct dasd_device *device = cqr->startdev;
2654 unsigned long flags;
2657 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2658 rc = __dasd_cancel_req(cqr);
2659 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2664 * SECTION: Operations of the dasd_block layer.
2668 * Timeout function for dasd_block. This is used when the block layer
2669 * is waiting for something that may not come reliably, (e.g. a state
2672 static void dasd_block_timeout(struct timer_list *t)
2674 unsigned long flags;
2675 struct dasd_block *block;
2677 block = from_timer(block, t, timer);
2678 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2679 /* re-activate request queue */
2680 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2681 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2682 dasd_schedule_block_bh(block);
2683 blk_mq_run_hw_queues(block->gdp->queue, true);
2687 * Setup timeout for a dasd_block in jiffies.
2689 void dasd_block_set_timer(struct dasd_block *block, int expires)
2692 del_timer(&block->timer);
2694 mod_timer(&block->timer, jiffies + expires);
2696 EXPORT_SYMBOL(dasd_block_set_timer);
2699 * Clear timeout for a dasd_block.
2701 void dasd_block_clear_timer(struct dasd_block *block)
2703 del_timer(&block->timer);
2705 EXPORT_SYMBOL(dasd_block_clear_timer);
2708 * Process finished error recovery ccw.
2710 static void __dasd_process_erp(struct dasd_device *device,
2711 struct dasd_ccw_req *cqr)
2713 dasd_erp_fn_t erp_fn;
2715 if (cqr->status == DASD_CQR_DONE)
2716 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2718 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2719 erp_fn = device->discipline->erp_postaction(cqr);
2723 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2725 struct request *req;
2726 blk_status_t error = BLK_STS_OK;
2727 unsigned int proc_bytes;
2730 req = (struct request *) cqr->callback_data;
2731 dasd_profile_end(cqr->block, cqr, req);
2733 proc_bytes = cqr->proc_bytes;
2734 status = cqr->block->base->discipline->free_cp(cqr, req);
2736 error = errno_to_blk_status(status);
2737 else if (status == 0) {
2738 switch (cqr->intrc) {
2741 * DASD doesn't implement SCSI/NVMe reservations, but it
2742 * implements a locking scheme similar to them. We
2743 * return this error when we no longer have the lock.
2745 error = BLK_STS_RESV_CONFLICT;
2748 error = BLK_STS_TRANSPORT;
2751 error = BLK_STS_TIMEOUT;
2754 error = BLK_STS_IOERR;
2760 * We need to take care for ETIMEDOUT errors here since the
2761 * complete callback does not get called in this case.
2762 * Take care of all errors here and avoid additional code to
2763 * transfer the error value to the complete callback.
2766 blk_mq_end_request(req, error);
2767 blk_mq_run_hw_queues(req->q, true);
2770 * Partial completed requests can happen with ESE devices.
2771 * During read we might have gotten a NRF error and have to
2772 * complete a request partially.
2775 blk_update_request(req, BLK_STS_OK, proc_bytes);
2776 blk_mq_requeue_request(req, true);
2777 } else if (likely(!blk_should_fake_timeout(req->q))) {
2778 blk_mq_complete_request(req);
2784 * Process ccw request queue.
2786 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2787 struct list_head *final_queue)
2789 struct list_head *l, *n;
2790 struct dasd_ccw_req *cqr;
2791 dasd_erp_fn_t erp_fn;
2792 unsigned long flags;
2793 struct dasd_device *base = block->base;
2796 /* Process request with final status. */
2797 list_for_each_safe(l, n, &block->ccw_queue) {
2798 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2799 if (cqr->status != DASD_CQR_DONE &&
2800 cqr->status != DASD_CQR_FAILED &&
2801 cqr->status != DASD_CQR_NEED_ERP &&
2802 cqr->status != DASD_CQR_TERMINATED)
2805 if (cqr->status == DASD_CQR_TERMINATED) {
2806 base->discipline->handle_terminated_request(cqr);
2810 /* Process requests that may be recovered */
2811 if (cqr->status == DASD_CQR_NEED_ERP) {
2812 erp_fn = base->discipline->erp_action(cqr);
2813 if (IS_ERR(erp_fn(cqr)))
2818 /* log sense for fatal error */
2819 if (cqr->status == DASD_CQR_FAILED) {
2820 dasd_log_sense(cqr, &cqr->irb);
2824 * First call extended error reporting and check for autoquiesce
2826 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2827 if (cqr->status == DASD_CQR_FAILED &&
2828 dasd_handle_autoquiesce(base, cqr, DASD_EER_FATALERROR)) {
2829 cqr->status = DASD_CQR_FILLED;
2831 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
2834 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
2836 /* Process finished ERP request. */
2838 __dasd_process_erp(base, cqr);
2842 /* Rechain finished requests to final queue */
2843 cqr->endclk = get_tod_clock();
2844 list_move_tail(&cqr->blocklist, final_queue);
2848 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2850 dasd_schedule_block_bh(cqr->block);
2853 static void __dasd_block_start_head(struct dasd_block *block)
2855 struct dasd_ccw_req *cqr;
2857 if (list_empty(&block->ccw_queue))
2859 /* We allways begin with the first requests on the queue, as some
2860 * of previously started requests have to be enqueued on a
2861 * dasd_device again for error recovery.
2863 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2864 if (cqr->status != DASD_CQR_FILLED)
2866 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2867 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2868 cqr->status = DASD_CQR_FAILED;
2869 cqr->intrc = -EPERM;
2870 dasd_schedule_block_bh(block);
2873 /* Non-temporary stop condition will trigger fail fast */
2874 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2875 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2876 !dasd_eer_enabled(block->base) && block->base->aq_mask == 0) {
2877 cqr->status = DASD_CQR_FAILED;
2878 cqr->intrc = -ENOLINK;
2879 dasd_schedule_block_bh(block);
2882 /* Don't try to start requests if device is stopped */
2883 if (block->base->stopped)
2886 /* just a fail safe check, should not happen */
2888 cqr->startdev = block->base;
2890 /* make sure that the requests we submit find their way back */
2891 cqr->callback = dasd_return_cqr_cb;
2893 dasd_add_request_tail(cqr);
2898 * Central dasd_block layer routine. Takes requests from the generic
2899 * block layer request queue, creates ccw requests, enqueues them on
2900 * a dasd_device and processes ccw requests that have been returned.
2902 static void dasd_block_tasklet(unsigned long data)
2904 struct dasd_block *block = (struct dasd_block *) data;
2905 struct list_head final_queue;
2906 struct list_head *l, *n;
2907 struct dasd_ccw_req *cqr;
2908 struct dasd_queue *dq;
2910 atomic_set(&block->tasklet_scheduled, 0);
2911 INIT_LIST_HEAD(&final_queue);
2912 spin_lock_irq(&block->queue_lock);
2913 /* Finish off requests on ccw queue */
2914 __dasd_process_block_ccw_queue(block, &final_queue);
2915 spin_unlock_irq(&block->queue_lock);
2917 /* Now call the callback function of requests with final status */
2918 list_for_each_safe(l, n, &final_queue) {
2919 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2921 spin_lock_irq(&dq->lock);
2922 list_del_init(&cqr->blocklist);
2923 __dasd_cleanup_cqr(cqr);
2924 spin_unlock_irq(&dq->lock);
2927 spin_lock_irq(&block->queue_lock);
2928 /* Now check if the head of the ccw queue needs to be started. */
2929 __dasd_block_start_head(block);
2930 spin_unlock_irq(&block->queue_lock);
2932 if (waitqueue_active(&shutdown_waitq))
2933 wake_up(&shutdown_waitq);
2934 dasd_put_device(block->base);
2937 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2939 wake_up(&dasd_flush_wq);
2943 * Requeue a request back to the block request queue
2944 * only works for block requests
2946 static void _dasd_requeue_request(struct dasd_ccw_req *cqr)
2948 struct request *req;
2951 * If the request is an ERP request there is nothing to requeue.
2952 * This will be done with the remaining original request.
2956 spin_lock_irq(&cqr->dq->lock);
2957 req = (struct request *) cqr->callback_data;
2958 blk_mq_requeue_request(req, true);
2959 spin_unlock_irq(&cqr->dq->lock);
2964 static int _dasd_requests_to_flushqueue(struct dasd_block *block,
2965 struct list_head *flush_queue)
2967 struct dasd_ccw_req *cqr, *n;
2968 unsigned long flags;
2971 spin_lock_irqsave(&block->queue_lock, flags);
2974 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2975 /* if this request currently owned by a dasd_device cancel it */
2976 if (cqr->status >= DASD_CQR_QUEUED)
2977 rc = dasd_cancel_req(cqr);
2980 /* Rechain request (including erp chain) so it won't be
2981 * touched by the dasd_block_tasklet anymore.
2982 * Replace the callback so we notice when the request
2983 * is returned from the dasd_device layer.
2985 cqr->callback = _dasd_wake_block_flush_cb;
2986 for (i = 0; cqr; cqr = cqr->refers, i++)
2987 list_move_tail(&cqr->blocklist, flush_queue);
2989 /* moved more than one request - need to restart */
2992 spin_unlock_irqrestore(&block->queue_lock, flags);
2998 * Go through all request on the dasd_block request queue, cancel them
2999 * on the respective dasd_device, and return them to the generic
3002 static int dasd_flush_block_queue(struct dasd_block *block)
3004 struct dasd_ccw_req *cqr, *n;
3005 struct list_head flush_queue;
3006 unsigned long flags;
3009 INIT_LIST_HEAD(&flush_queue);
3010 rc = _dasd_requests_to_flushqueue(block, &flush_queue);
3012 /* Now call the callback function of flushed requests */
3014 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
3015 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
3016 /* Process finished ERP request. */
3018 spin_lock_bh(&block->queue_lock);
3019 __dasd_process_erp(block->base, cqr);
3020 spin_unlock_bh(&block->queue_lock);
3021 /* restart list_for_xx loop since dasd_process_erp
3022 * might remove multiple elements */
3025 /* call the callback function */
3026 spin_lock_irqsave(&cqr->dq->lock, flags);
3027 cqr->endclk = get_tod_clock();
3028 list_del_init(&cqr->blocklist);
3029 __dasd_cleanup_cqr(cqr);
3030 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3036 * Schedules a call to dasd_tasklet over the device tasklet.
3038 void dasd_schedule_block_bh(struct dasd_block *block)
3040 /* Protect against rescheduling. */
3041 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
3043 /* life cycle of block is bound to it's base device */
3044 dasd_get_device(block->base);
3045 tasklet_hi_schedule(&block->tasklet);
3047 EXPORT_SYMBOL(dasd_schedule_block_bh);
3051 * SECTION: external block device operations
3052 * (request queue handling, open, release, etc.)
3056 * Dasd request queue function. Called from ll_rw_blk.c
3058 static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
3059 const struct blk_mq_queue_data *qd)
3061 struct dasd_block *block = hctx->queue->queuedata;
3062 struct dasd_queue *dq = hctx->driver_data;
3063 struct request *req = qd->rq;
3064 struct dasd_device *basedev;
3065 struct dasd_ccw_req *cqr;
3066 blk_status_t rc = BLK_STS_OK;
3068 basedev = block->base;
3069 spin_lock_irq(&dq->lock);
3070 if (basedev->state < DASD_STATE_READY ||
3071 test_bit(DASD_FLAG_OFFLINE, &basedev->flags)) {
3072 DBF_DEV_EVENT(DBF_ERR, basedev,
3073 "device not ready for request %p", req);
3079 * if device is stopped do not fetch new requests
3080 * except failfast is active which will let requests fail
3081 * immediately in __dasd_block_start_head()
3083 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
3084 DBF_DEV_EVENT(DBF_ERR, basedev,
3085 "device stopped request %p", req);
3086 rc = BLK_STS_RESOURCE;
3090 if (basedev->features & DASD_FEATURE_READONLY &&
3091 rq_data_dir(req) == WRITE) {
3092 DBF_DEV_EVENT(DBF_ERR, basedev,
3093 "Rejecting write request %p", req);
3098 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
3099 (basedev->features & DASD_FEATURE_FAILFAST ||
3100 blk_noretry_request(req))) {
3101 DBF_DEV_EVENT(DBF_ERR, basedev,
3102 "Rejecting failfast request %p", req);
3107 cqr = basedev->discipline->build_cp(basedev, block, req);
3109 if (PTR_ERR(cqr) == -EBUSY ||
3110 PTR_ERR(cqr) == -ENOMEM ||
3111 PTR_ERR(cqr) == -EAGAIN) {
3112 rc = BLK_STS_RESOURCE;
3115 DBF_DEV_EVENT(DBF_ERR, basedev,
3116 "CCW creation failed (rc=%ld) on request %p",
3122 * Note: callback is set to dasd_return_cqr_cb in
3123 * __dasd_block_start_head to cover erp requests as well
3125 cqr->callback_data = req;
3126 cqr->status = DASD_CQR_FILLED;
3129 blk_mq_start_request(req);
3130 spin_lock(&block->queue_lock);
3131 list_add_tail(&cqr->blocklist, &block->ccw_queue);
3132 INIT_LIST_HEAD(&cqr->devlist);
3133 dasd_profile_start(block, cqr, req);
3134 dasd_schedule_block_bh(block);
3135 spin_unlock(&block->queue_lock);
3138 spin_unlock_irq(&dq->lock);
3143 * Block timeout callback, called from the block layer
3146 * BLK_EH_RESET_TIMER if the request should be left running
3147 * BLK_EH_DONE if the request is handled or terminated
3150 enum blk_eh_timer_return dasd_times_out(struct request *req)
3152 struct dasd_block *block = req->q->queuedata;
3153 struct dasd_device *device;
3154 struct dasd_ccw_req *cqr;
3155 unsigned long flags;
3158 cqr = blk_mq_rq_to_pdu(req);
3162 spin_lock_irqsave(&cqr->dq->lock, flags);
3163 device = cqr->startdev ? cqr->startdev : block->base;
3164 if (!device->blk_timeout) {
3165 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3166 return BLK_EH_RESET_TIMER;
3168 DBF_DEV_EVENT(DBF_WARNING, device,
3169 " dasd_times_out cqr %p status %x",
3172 spin_lock(&block->queue_lock);
3173 spin_lock(get_ccwdev_lock(device->cdev));
3175 cqr->intrc = -ETIMEDOUT;
3176 if (cqr->status >= DASD_CQR_QUEUED) {
3177 rc = __dasd_cancel_req(cqr);
3178 } else if (cqr->status == DASD_CQR_FILLED ||
3179 cqr->status == DASD_CQR_NEED_ERP) {
3180 cqr->status = DASD_CQR_TERMINATED;
3181 } else if (cqr->status == DASD_CQR_IN_ERP) {
3182 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3184 list_for_each_entry_safe(searchcqr, nextcqr,
3185 &block->ccw_queue, blocklist) {
3187 while (tmpcqr->refers)
3188 tmpcqr = tmpcqr->refers;
3191 /* searchcqr is an ERP request for cqr */
3192 searchcqr->retries = -1;
3193 searchcqr->intrc = -ETIMEDOUT;
3194 if (searchcqr->status >= DASD_CQR_QUEUED) {
3195 rc = __dasd_cancel_req(searchcqr);
3196 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3197 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3198 searchcqr->status = DASD_CQR_TERMINATED;
3200 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3202 * Shouldn't happen; most recent ERP
3203 * request is at the front of queue
3210 spin_unlock(get_ccwdev_lock(device->cdev));
3211 dasd_schedule_block_bh(block);
3212 spin_unlock(&block->queue_lock);
3213 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3215 return rc ? BLK_EH_RESET_TIMER : BLK_EH_DONE;
3218 static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
3221 struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
3226 spin_lock_init(&dq->lock);
3227 hctx->driver_data = dq;
3232 static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
3234 kfree(hctx->driver_data);
3235 hctx->driver_data = NULL;
3238 static void dasd_request_done(struct request *req)
3240 blk_mq_end_request(req, 0);
3241 blk_mq_run_hw_queues(req->q, true);
3244 struct blk_mq_ops dasd_mq_ops = {
3245 .queue_rq = do_dasd_request,
3246 .complete = dasd_request_done,
3247 .timeout = dasd_times_out,
3248 .init_hctx = dasd_init_hctx,
3249 .exit_hctx = dasd_exit_hctx,
3252 static int dasd_open(struct gendisk *disk, blk_mode_t mode)
3254 struct dasd_device *base;
3257 base = dasd_device_from_gendisk(disk);
3261 atomic_inc(&base->block->open_count);
3262 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
3267 if (!try_module_get(base->discipline->owner)) {
3272 if (dasd_probeonly) {
3273 dev_info(&base->cdev->dev,
3274 "Accessing the DASD failed because it is in "
3275 "probeonly mode\n");
3280 if (base->state <= DASD_STATE_BASIC) {
3281 DBF_DEV_EVENT(DBF_ERR, base, " %s",
3282 " Cannot open unrecognized device");
3286 if ((mode & BLK_OPEN_WRITE) &&
3287 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3288 (base->features & DASD_FEATURE_READONLY))) {
3292 dasd_put_device(base);
3296 module_put(base->discipline->owner);
3298 atomic_dec(&base->block->open_count);
3299 dasd_put_device(base);
3303 static void dasd_release(struct gendisk *disk)
3305 struct dasd_device *base = dasd_device_from_gendisk(disk);
3307 atomic_dec(&base->block->open_count);
3308 module_put(base->discipline->owner);
3309 dasd_put_device(base);
3314 * Return disk geometry.
3316 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3318 struct dasd_device *base;
3320 base = dasd_device_from_gendisk(bdev->bd_disk);
3324 if (!base->discipline ||
3325 !base->discipline->fill_geometry) {
3326 dasd_put_device(base);
3329 base->discipline->fill_geometry(base->block, geo);
3330 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3331 dasd_put_device(base);
3335 const struct block_device_operations
3336 dasd_device_operations = {
3337 .owner = THIS_MODULE,
3339 .release = dasd_release,
3340 .ioctl = dasd_ioctl,
3341 .compat_ioctl = dasd_ioctl,
3342 .getgeo = dasd_getgeo,
3343 .set_read_only = dasd_set_read_only,
3346 /*******************************************************************************
3347 * end of block device operations
3353 #ifdef CONFIG_PROC_FS
3357 kmem_cache_destroy(dasd_page_cache);
3358 dasd_page_cache = NULL;
3359 dasd_gendisk_exit();
3361 if (dasd_debug_area != NULL) {
3362 debug_unregister(dasd_debug_area);
3363 dasd_debug_area = NULL;
3365 dasd_statistics_removeroot();
3369 * SECTION: common functions for ccw_driver use
3373 * Is the device read-only?
3374 * Note that this function does not report the setting of the
3375 * readonly device attribute, but how it is configured in z/VM.
3377 int dasd_device_is_ro(struct dasd_device *device)
3379 struct ccw_dev_id dev_id;
3380 struct diag210 diag_data;
3385 ccw_device_get_id(device->cdev, &dev_id);
3386 memset(&diag_data, 0, sizeof(diag_data));
3387 diag_data.vrdcdvno = dev_id.devno;
3388 diag_data.vrdclen = sizeof(diag_data);
3389 rc = diag210(&diag_data);
3390 if (rc == 0 || rc == 2) {
3391 return diag_data.vrdcvfla & 0x80;
3393 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3398 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3400 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3402 struct ccw_device *cdev = data;
3405 ret = ccw_device_set_online(cdev);
3407 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3408 dev_name(&cdev->dev), ret);
3412 * Initial attempt at a probe function. this can be simplified once
3413 * the other detection code is gone.
3415 int dasd_generic_probe(struct ccw_device *cdev)
3417 cdev->handler = &dasd_int_handler;
3420 * Automatically online either all dasd devices (dasd_autodetect)
3421 * or all devices specified with dasd= parameters during
3424 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
3425 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
3426 async_schedule(dasd_generic_auto_online, cdev);
3429 EXPORT_SYMBOL_GPL(dasd_generic_probe);
3431 void dasd_generic_free_discipline(struct dasd_device *device)
3433 /* Forget the discipline information. */
3434 if (device->discipline) {
3435 if (device->discipline->uncheck_device)
3436 device->discipline->uncheck_device(device);
3437 module_put(device->discipline->owner);
3438 device->discipline = NULL;
3440 if (device->base_discipline) {
3441 module_put(device->base_discipline->owner);
3442 device->base_discipline = NULL;
3445 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3448 * This will one day be called from a global not_oper handler.
3449 * It is also used by driver_unregister during module unload.
3451 void dasd_generic_remove(struct ccw_device *cdev)
3453 struct dasd_device *device;
3454 struct dasd_block *block;
3456 device = dasd_device_from_cdev(cdev);
3460 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3461 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3462 /* Already doing offline processing */
3463 dasd_put_device(device);
3467 * This device is removed unconditionally. Set offline
3468 * flag to prevent dasd_open from opening it while it is
3469 * no quite down yet.
3471 dasd_set_target_state(device, DASD_STATE_NEW);
3472 cdev->handler = NULL;
3473 /* dasd_delete_device destroys the device reference. */
3474 block = device->block;
3475 dasd_delete_device(device);
3477 * life cycle of block is bound to device, so delete it after
3478 * device was safely removed
3481 dasd_free_block(block);
3483 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3486 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3487 * the device is detected for the first time and is supposed to be used
3488 * or the user has started activation through sysfs.
3490 int dasd_generic_set_online(struct ccw_device *cdev,
3491 struct dasd_discipline *base_discipline)
3493 struct dasd_discipline *discipline;
3494 struct dasd_device *device;
3497 /* first online clears initial online feature flag */
3498 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3499 device = dasd_create_device(cdev);
3501 return PTR_ERR(device);
3503 discipline = base_discipline;
3504 if (device->features & DASD_FEATURE_USEDIAG) {
3505 if (!dasd_diag_discipline_pointer) {
3506 /* Try to load the required module. */
3507 rc = request_module(DASD_DIAG_MOD);
3509 pr_warn("%s Setting the DASD online failed "
3510 "because the required module %s "
3511 "could not be loaded (rc=%d)\n",
3512 dev_name(&cdev->dev), DASD_DIAG_MOD,
3514 dasd_delete_device(device);
3518 /* Module init could have failed, so check again here after
3519 * request_module(). */
3520 if (!dasd_diag_discipline_pointer) {
3521 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3522 dev_name(&cdev->dev));
3523 dasd_delete_device(device);
3526 discipline = dasd_diag_discipline_pointer;
3528 if (!try_module_get(base_discipline->owner)) {
3529 dasd_delete_device(device);
3532 if (!try_module_get(discipline->owner)) {
3533 module_put(base_discipline->owner);
3534 dasd_delete_device(device);
3537 device->base_discipline = base_discipline;
3538 device->discipline = discipline;
3540 /* check_device will allocate block device if necessary */
3541 rc = discipline->check_device(device);
3543 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3544 dev_name(&cdev->dev), discipline->name, rc);
3545 module_put(discipline->owner);
3546 module_put(base_discipline->owner);
3547 dasd_delete_device(device);
3551 dasd_set_target_state(device, DASD_STATE_ONLINE);
3552 if (device->state <= DASD_STATE_KNOWN) {
3553 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3554 dev_name(&cdev->dev));
3556 dasd_set_target_state(device, DASD_STATE_NEW);
3558 dasd_free_block(device->block);
3559 dasd_delete_device(device);
3561 pr_debug("dasd_generic device %s found\n",
3562 dev_name(&cdev->dev));
3564 wait_event(dasd_init_waitq, _wait_for_device(device));
3566 dasd_put_device(device);
3569 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3571 int dasd_generic_set_offline(struct ccw_device *cdev)
3573 struct dasd_device *device;
3574 struct dasd_block *block;
3575 int max_count, open_count, rc;
3576 unsigned long flags;
3579 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3580 device = dasd_device_from_cdev_locked(cdev);
3581 if (IS_ERR(device)) {
3582 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3583 return PTR_ERR(device);
3587 * We must make sure that this device is currently not in use.
3588 * The open_count is increased for every opener, that includes
3589 * the blkdev_get in dasd_scan_partitions. We are only interested
3590 * in the other openers.
3592 if (device->block) {
3593 max_count = device->block->bdev ? 0 : -1;
3594 open_count = atomic_read(&device->block->open_count);
3595 if (open_count > max_count) {
3597 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3598 dev_name(&cdev->dev), open_count);
3600 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3601 dev_name(&cdev->dev));
3608 * Test if the offline processing is already running and exit if so.
3609 * If a safe offline is being processed this could only be a normal
3610 * offline that should be able to overtake the safe offline and
3611 * cancel any I/O we do not want to wait for any longer
3613 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3614 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3615 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3622 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3625 * if safe_offline is called set safe_offline_running flag and
3626 * clear safe_offline so that a call to normal offline
3627 * can overrun safe_offline processing
3629 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3630 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3631 /* need to unlock here to wait for outstanding I/O */
3632 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3634 * If we want to set the device safe offline all IO operations
3635 * should be finished before continuing the offline process
3636 * so sync bdev first and then wait for our queues to become
3639 if (device->block) {
3640 rc = fsync_bdev(device->block->bdev);
3644 dasd_schedule_device_bh(device);
3645 rc = wait_event_interruptible(shutdown_waitq,
3646 _wait_for_empty_queues(device));
3651 * check if a normal offline process overtook the offline
3652 * processing in this case simply do nothing beside returning
3653 * that we got interrupted
3654 * otherwise mark safe offline as not running any longer and
3655 * continue with normal offline
3657 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3658 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3662 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3664 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3666 dasd_set_target_state(device, DASD_STATE_NEW);
3667 /* dasd_delete_device destroys the device reference. */
3668 block = device->block;
3669 dasd_delete_device(device);
3671 * life cycle of block is bound to device, so delete it after
3672 * device was safely removed
3675 dasd_free_block(block);
3680 /* interrupted by signal */
3681 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3682 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3683 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3685 dasd_put_device(device);
3686 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3689 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3691 int dasd_generic_last_path_gone(struct dasd_device *device)
3693 struct dasd_ccw_req *cqr;
3695 dev_warn(&device->cdev->dev, "No operational channel path is left "
3696 "for the device\n");
3697 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3698 /* First call extended error reporting and check for autoquiesce. */
3699 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOPATH);
3701 if (device->state < DASD_STATE_BASIC)
3703 /* Device is active. We want to keep it. */
3704 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3705 if ((cqr->status == DASD_CQR_IN_IO) ||
3706 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3707 cqr->status = DASD_CQR_QUEUED;
3710 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3711 dasd_device_clear_timer(device);
3712 dasd_schedule_device_bh(device);
3715 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3717 int dasd_generic_path_operational(struct dasd_device *device)
3719 dev_info(&device->cdev->dev, "A channel path to the device has become "
3721 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3722 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3723 dasd_schedule_device_bh(device);
3724 if (device->block) {
3725 dasd_schedule_block_bh(device->block);
3726 if (device->block->gdp)
3727 blk_mq_run_hw_queues(device->block->gdp->queue, true);
3730 if (!device->stopped)
3731 wake_up(&generic_waitq);
3735 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3737 int dasd_generic_notify(struct ccw_device *cdev, int event)
3739 struct dasd_device *device;
3742 device = dasd_device_from_cdev_locked(cdev);
3750 dasd_path_no_path(device);
3751 ret = dasd_generic_last_path_gone(device);
3755 if (dasd_path_get_opm(device))
3756 ret = dasd_generic_path_operational(device);
3759 dasd_put_device(device);
3762 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3764 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3766 struct dasd_device *device;
3767 int chp, oldopm, hpfpm, ifccpm;
3769 device = dasd_device_from_cdev_locked(cdev);
3773 oldopm = dasd_path_get_opm(device);
3774 for (chp = 0; chp < 8; chp++) {
3775 if (path_event[chp] & PE_PATH_GONE) {
3776 dasd_path_notoper(device, chp);
3778 if (path_event[chp] & PE_PATH_AVAILABLE) {
3779 dasd_path_available(device, chp);
3780 dasd_schedule_device_bh(device);
3782 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3783 if (!dasd_path_is_operational(device, chp) &&
3784 !dasd_path_need_verify(device, chp)) {
3786 * we can not establish a pathgroup on an
3787 * unavailable path, so trigger a path
3788 * verification first
3790 dasd_path_available(device, chp);
3791 dasd_schedule_device_bh(device);
3793 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3794 "Pathgroup re-established\n");
3795 if (device->discipline->kick_validate)
3796 device->discipline->kick_validate(device);
3798 if (path_event[chp] & PE_PATH_FCES_EVENT) {
3799 dasd_path_fcsec_update(device, chp);
3800 dasd_schedule_device_bh(device);
3803 hpfpm = dasd_path_get_hpfpm(device);
3804 ifccpm = dasd_path_get_ifccpm(device);
3805 if (!dasd_path_get_opm(device) && hpfpm) {
3807 * device has no operational paths but at least one path is
3808 * disabled due to HPF errors
3809 * disable HPF at all and use the path(s) again
3811 if (device->discipline->disable_hpf)
3812 device->discipline->disable_hpf(device);
3813 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3814 dasd_path_set_tbvpm(device, hpfpm);
3815 dasd_schedule_device_bh(device);
3816 dasd_schedule_requeue(device);
3817 } else if (!dasd_path_get_opm(device) && ifccpm) {
3819 * device has no operational paths but at least one path is
3820 * disabled due to IFCC errors
3821 * trigger path verification on paths with IFCC errors
3823 dasd_path_set_tbvpm(device, ifccpm);
3824 dasd_schedule_device_bh(device);
3826 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3827 dev_warn(&device->cdev->dev,
3828 "No verified channel paths remain for the device\n");
3829 DBF_DEV_EVENT(DBF_WARNING, device,
3830 "%s", "last verified path gone");
3831 /* First call extended error reporting and check for autoquiesce. */
3832 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOPATH);
3833 dasd_device_set_stop_bits(device,
3834 DASD_STOPPED_DC_WAIT);
3836 dasd_put_device(device);
3838 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3840 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3842 if (!dasd_path_get_opm(device) && lpm) {
3843 dasd_path_set_opm(device, lpm);
3844 dasd_generic_path_operational(device);
3846 dasd_path_add_opm(device, lpm);
3849 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3851 void dasd_generic_space_exhaust(struct dasd_device *device,
3852 struct dasd_ccw_req *cqr)
3854 /* First call extended error reporting and check for autoquiesce. */
3855 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOSPC);
3857 if (device->state < DASD_STATE_BASIC)
3860 if (cqr->status == DASD_CQR_IN_IO ||
3861 cqr->status == DASD_CQR_CLEAR_PENDING) {
3862 cqr->status = DASD_CQR_QUEUED;
3865 dasd_device_set_stop_bits(device, DASD_STOPPED_NOSPC);
3866 dasd_device_clear_timer(device);
3867 dasd_schedule_device_bh(device);
3869 EXPORT_SYMBOL_GPL(dasd_generic_space_exhaust);
3871 void dasd_generic_space_avail(struct dasd_device *device)
3873 dev_info(&device->cdev->dev, "Extent pool space is available\n");
3874 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "space available");
3876 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOSPC);
3877 dasd_schedule_device_bh(device);
3879 if (device->block) {
3880 dasd_schedule_block_bh(device->block);
3881 if (device->block->gdp)
3882 blk_mq_run_hw_queues(device->block->gdp->queue, true);
3884 if (!device->stopped)
3885 wake_up(&generic_waitq);
3887 EXPORT_SYMBOL_GPL(dasd_generic_space_avail);
3890 * clear active requests and requeue them to block layer if possible
3892 int dasd_generic_requeue_all_requests(struct dasd_device *device)
3894 struct dasd_block *block = device->block;
3895 struct list_head requeue_queue;
3896 struct dasd_ccw_req *cqr, *n;
3902 INIT_LIST_HEAD(&requeue_queue);
3903 rc = _dasd_requests_to_flushqueue(block, &requeue_queue);
3905 /* Now call the callback function of flushed requests */
3907 list_for_each_entry_safe(cqr, n, &requeue_queue, blocklist) {
3908 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
3909 /* Process finished ERP request. */
3911 spin_lock_bh(&block->queue_lock);
3912 __dasd_process_erp(block->base, cqr);
3913 spin_unlock_bh(&block->queue_lock);
3914 /* restart list_for_xx loop since dasd_process_erp
3915 * might remove multiple elements
3919 _dasd_requeue_request(cqr);
3920 list_del_init(&cqr->blocklist);
3921 cqr->block->base->discipline->free_cp(
3922 cqr, (struct request *) cqr->callback_data);
3924 dasd_schedule_device_bh(device);
3927 EXPORT_SYMBOL_GPL(dasd_generic_requeue_all_requests);
3929 static void do_requeue_requests(struct work_struct *work)
3931 struct dasd_device *device = container_of(work, struct dasd_device,
3933 dasd_generic_requeue_all_requests(device);
3934 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3936 dasd_schedule_block_bh(device->block);
3937 dasd_put_device(device);
3940 void dasd_schedule_requeue(struct dasd_device *device)
3942 dasd_get_device(device);
3943 /* queue call to dasd_reload_device to the kernel event daemon. */
3944 if (!schedule_work(&device->requeue_requests))
3945 dasd_put_device(device);
3947 EXPORT_SYMBOL(dasd_schedule_requeue);
3949 static int dasd_handle_autoquiesce(struct dasd_device *device,
3950 struct dasd_ccw_req *cqr,
3951 unsigned int reason)
3953 /* in any case write eer message with reason */
3954 if (dasd_eer_enabled(device))
3955 dasd_eer_write(device, cqr, reason);
3957 if (!test_bit(reason, &device->aq_mask))
3960 /* notify eer about autoquiesce */
3961 if (dasd_eer_enabled(device))
3962 dasd_eer_write(device, NULL, DASD_EER_AUTOQUIESCE);
3964 pr_info("%s: The DASD has been put in the quiesce state\n",
3965 dev_name(&device->cdev->dev));
3966 dasd_device_set_stop_bits(device, DASD_STOPPED_QUIESCE);
3968 if (device->features & DASD_FEATURE_REQUEUEQUIESCE)
3969 dasd_schedule_requeue(device);
3974 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
3975 int rdc_buffer_size,
3978 struct dasd_ccw_req *cqr;
3981 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device,
3985 /* internal error 13 - Allocating the RDC request failed*/
3986 dev_err(&device->cdev->dev,
3987 "An error occurred in the DASD device driver, "
3988 "reason=%s\n", "13");
3993 ccw->cmd_code = CCW_CMD_RDC;
3994 ccw->cda = (__u32)virt_to_phys(cqr->data);
3996 ccw->count = rdc_buffer_size;
3997 cqr->startdev = device;
3998 cqr->memdev = device;
3999 cqr->expires = 10*HZ;
4001 cqr->buildclk = get_tod_clock();
4002 cqr->status = DASD_CQR_FILLED;
4007 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4008 void *rdc_buffer, int rdc_buffer_size)
4011 struct dasd_ccw_req *cqr;
4013 cqr = dasd_generic_build_rdc(device, rdc_buffer_size, magic);
4015 return PTR_ERR(cqr);
4017 ret = dasd_sleep_on(cqr);
4019 memcpy(rdc_buffer, cqr->data, rdc_buffer_size);
4020 dasd_sfree_request(cqr, cqr->memdev);
4023 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
4026 * In command mode and transport mode we need to look for sense
4027 * data in different places. The sense data itself is allways
4028 * an array of 32 bytes, so we can unify the sense data access
4031 char *dasd_get_sense(struct irb *irb)
4033 struct tsb *tsb = NULL;
4036 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4037 if (irb->scsw.tm.tcw)
4038 tsb = tcw_get_tsb(phys_to_virt(irb->scsw.tm.tcw));
4039 if (tsb && tsb->length == 64 && tsb->flags)
4040 switch (tsb->flags & 0x07) {
4041 case 1: /* tsa_iostat */
4042 sense = tsb->tsa.iostat.sense;
4044 case 2: /* tsa_ddpc */
4045 sense = tsb->tsa.ddpc.sense;
4048 /* currently we don't use interrogate data */
4051 } else if (irb->esw.esw0.erw.cons) {
4056 EXPORT_SYMBOL_GPL(dasd_get_sense);
4058 void dasd_generic_shutdown(struct ccw_device *cdev)
4060 struct dasd_device *device;
4062 device = dasd_device_from_cdev(cdev);
4067 dasd_schedule_block_bh(device->block);
4069 dasd_schedule_device_bh(device);
4071 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4073 EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4075 static int __init dasd_init(void)
4079 init_waitqueue_head(&dasd_init_waitq);
4080 init_waitqueue_head(&dasd_flush_wq);
4081 init_waitqueue_head(&generic_waitq);
4082 init_waitqueue_head(&shutdown_waitq);
4084 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4085 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
4086 if (dasd_debug_area == NULL) {
4090 debug_register_view(dasd_debug_area, &debug_sprintf_view);
4091 debug_set_level(dasd_debug_area, DBF_WARNING);
4093 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4095 dasd_diag_discipline_pointer = NULL;
4097 dasd_statistics_createroot();
4099 rc = dasd_devmap_init();
4102 rc = dasd_gendisk_init();
4108 rc = dasd_eer_init();
4111 #ifdef CONFIG_PROC_FS
4112 rc = dasd_proc_init();
4119 pr_info("The DASD device driver could not be initialized\n");
4124 module_init(dasd_init);
4125 module_exit(dasd_exit);