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 #include <linux/kmod.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/ctype.h>
15 #include <linux/major.h>
16 #include <linux/slab.h>
17 #include <linux/hdreg.h>
18 #include <linux/async.h>
19 #include <linux/mutex.h>
20 #include <linux/debugfs.h>
21 #include <linux/seq_file.h>
22 #include <linux/vmalloc.h>
24 #include <asm/ccwdev.h>
25 #include <asm/ebcdic.h>
26 #include <asm/idals.h>
32 * SECTION: Constant definitions to be used within this file
34 #define DASD_CHANQ_MAX_SIZE 4
36 #define DASD_DIAG_MOD "dasd_diag_mod"
39 * SECTION: exported variables of dasd.c
41 debug_info_t *dasd_debug_area;
42 EXPORT_SYMBOL(dasd_debug_area);
43 static struct dentry *dasd_debugfs_root_entry;
44 struct dasd_discipline *dasd_diag_discipline_pointer;
45 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
46 void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
48 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
49 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
50 " Copyright IBM Corp. 2000");
51 MODULE_LICENSE("GPL");
54 * SECTION: prototypes for static functions of dasd.c
56 static int dasd_flush_block_queue(struct dasd_block *);
57 static void dasd_device_tasklet(unsigned long);
58 static void dasd_block_tasklet(unsigned long);
59 static void do_kick_device(struct work_struct *);
60 static void do_reload_device(struct work_struct *);
61 static void do_requeue_requests(struct work_struct *);
62 static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
63 static void dasd_device_timeout(struct timer_list *);
64 static void dasd_block_timeout(struct timer_list *);
65 static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
66 static void dasd_profile_init(struct dasd_profile *, struct dentry *);
67 static void dasd_profile_exit(struct dasd_profile *);
68 static void dasd_hosts_init(struct dentry *, struct dasd_device *);
69 static void dasd_hosts_exit(struct dasd_device *);
70 static int dasd_handle_autoquiesce(struct dasd_device *, struct dasd_ccw_req *,
73 * SECTION: Operations on the device structure.
75 static wait_queue_head_t dasd_init_waitq;
76 static wait_queue_head_t dasd_flush_wq;
77 static wait_queue_head_t generic_waitq;
78 static wait_queue_head_t shutdown_waitq;
81 * Allocate memory for a new device structure.
83 struct dasd_device *dasd_alloc_device(void)
85 struct dasd_device *device;
87 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
89 return ERR_PTR(-ENOMEM);
91 /* Get two pages for normal block device operations. */
92 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
93 if (!device->ccw_mem) {
95 return ERR_PTR(-ENOMEM);
97 /* Get one page for error recovery. */
98 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
99 if (!device->erp_mem) {
100 free_pages((unsigned long) device->ccw_mem, 1);
102 return ERR_PTR(-ENOMEM);
104 /* Get two pages for ese format. */
105 device->ese_mem = (void *)__get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
106 if (!device->ese_mem) {
107 free_page((unsigned long) device->erp_mem);
108 free_pages((unsigned long) device->ccw_mem, 1);
110 return ERR_PTR(-ENOMEM);
113 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
114 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
115 dasd_init_chunklist(&device->ese_chunks, device->ese_mem, PAGE_SIZE * 2);
116 spin_lock_init(&device->mem_lock);
117 atomic_set(&device->tasklet_scheduled, 0);
118 tasklet_init(&device->tasklet, dasd_device_tasklet,
119 (unsigned long) device);
120 INIT_LIST_HEAD(&device->ccw_queue);
121 timer_setup(&device->timer, dasd_device_timeout, 0);
122 INIT_WORK(&device->kick_work, do_kick_device);
123 INIT_WORK(&device->reload_device, do_reload_device);
124 INIT_WORK(&device->requeue_requests, do_requeue_requests);
125 device->state = DASD_STATE_NEW;
126 device->target = DASD_STATE_NEW;
127 mutex_init(&device->state_mutex);
128 spin_lock_init(&device->profile.lock);
133 * Free memory of a device structure.
135 void dasd_free_device(struct dasd_device *device)
137 kfree(device->private);
138 free_pages((unsigned long) device->ese_mem, 1);
139 free_page((unsigned long) device->erp_mem);
140 free_pages((unsigned long) device->ccw_mem, 1);
145 * Allocate memory for a new device structure.
147 struct dasd_block *dasd_alloc_block(void)
149 struct dasd_block *block;
151 block = kzalloc(sizeof(*block), GFP_ATOMIC);
153 return ERR_PTR(-ENOMEM);
154 /* open_count = 0 means device online but not in use */
155 atomic_set(&block->open_count, -1);
157 atomic_set(&block->tasklet_scheduled, 0);
158 tasklet_init(&block->tasklet, dasd_block_tasklet,
159 (unsigned long) block);
160 INIT_LIST_HEAD(&block->ccw_queue);
161 spin_lock_init(&block->queue_lock);
162 INIT_LIST_HEAD(&block->format_list);
163 spin_lock_init(&block->format_lock);
164 timer_setup(&block->timer, dasd_block_timeout, 0);
165 spin_lock_init(&block->profile.lock);
169 EXPORT_SYMBOL_GPL(dasd_alloc_block);
172 * Free memory of a device structure.
174 void dasd_free_block(struct dasd_block *block)
178 EXPORT_SYMBOL_GPL(dasd_free_block);
181 * Make a new device known to the system.
183 static int dasd_state_new_to_known(struct dasd_device *device)
186 * As long as the device is not in state DASD_STATE_NEW we want to
187 * keep the reference count > 0.
189 dasd_get_device(device);
190 device->state = DASD_STATE_KNOWN;
195 * Let the system forget about a device.
197 static int dasd_state_known_to_new(struct dasd_device *device)
199 /* Disable extended error reporting for this device. */
200 dasd_eer_disable(device);
201 device->state = DASD_STATE_NEW;
203 /* Give up reference we took in dasd_state_new_to_known. */
204 dasd_put_device(device);
208 static struct dentry *dasd_debugfs_setup(const char *name,
209 struct dentry *base_dentry)
215 pde = debugfs_create_dir(name, base_dentry);
216 if (!pde || IS_ERR(pde))
222 * Request the irq line for the device.
224 static int dasd_state_known_to_basic(struct dasd_device *device)
226 struct dasd_block *block = device->block;
229 /* Allocate and register gendisk structure. */
231 rc = dasd_gendisk_alloc(block);
234 block->debugfs_dentry =
235 dasd_debugfs_setup(block->gdp->disk_name,
236 dasd_debugfs_root_entry);
237 dasd_profile_init(&block->profile, block->debugfs_dentry);
238 if (dasd_global_profile_level == DASD_PROFILE_ON)
239 dasd_profile_on(&device->block->profile);
241 device->debugfs_dentry =
242 dasd_debugfs_setup(dev_name(&device->cdev->dev),
243 dasd_debugfs_root_entry);
244 dasd_profile_init(&device->profile, device->debugfs_dentry);
245 dasd_hosts_init(device->debugfs_dentry, device);
247 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
248 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
250 debug_register_view(device->debug_area, &debug_sprintf_view);
251 debug_set_level(device->debug_area, DBF_WARNING);
252 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
254 device->state = DASD_STATE_BASIC;
260 * Release the irq line for the device. Terminate any running i/o.
262 static int dasd_state_basic_to_known(struct dasd_device *device)
266 if (device->discipline->basic_to_known) {
267 rc = device->discipline->basic_to_known(device);
273 dasd_profile_exit(&device->block->profile);
274 debugfs_remove(device->block->debugfs_dentry);
275 dasd_gendisk_free(device->block);
276 dasd_block_clear_timer(device->block);
278 rc = dasd_flush_device_queue(device);
281 dasd_device_clear_timer(device);
282 dasd_profile_exit(&device->profile);
283 dasd_hosts_exit(device);
284 debugfs_remove(device->debugfs_dentry);
285 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
286 if (device->debug_area != NULL) {
287 debug_unregister(device->debug_area);
288 device->debug_area = NULL;
290 device->state = DASD_STATE_KNOWN;
295 * Do the initial analysis. The do_analysis function may return
296 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
297 * until the discipline decides to continue the startup sequence
298 * by calling the function dasd_change_state. The eckd disciplines
299 * uses this to start a ccw that detects the format. The completion
300 * interrupt for this detection ccw uses the kernel event daemon to
301 * trigger the call to dasd_change_state. All this is done in the
302 * discipline code, see dasd_eckd.c.
303 * After the analysis ccw is done (do_analysis returned 0) the block
305 * In case the analysis returns an error, the device setup is stopped
306 * (a fake disk was already added to allow formatting).
308 static int dasd_state_basic_to_ready(struct dasd_device *device)
310 struct dasd_block *block = device->block;
311 struct queue_limits lim;
314 /* make disk known with correct capacity */
316 device->state = DASD_STATE_READY;
320 if (block->base->discipline->do_analysis != NULL)
321 rc = block->base->discipline->do_analysis(block);
325 device->state = DASD_STATE_UNFMT;
326 kobject_uevent(&disk_to_dev(device->block->gdp)->kobj,
331 lim = queue_limits_start_update(block->gdp->queue);
332 lim.max_dev_sectors = device->discipline->max_sectors(block);
333 lim.max_hw_sectors = lim.max_dev_sectors;
334 lim.logical_block_size = block->bp_block;
336 if (device->discipline->has_discard) {
337 unsigned int max_bytes;
339 lim.discard_granularity = block->bp_block;
341 /* Calculate max_discard_sectors and make it PAGE aligned */
342 max_bytes = USHRT_MAX * block->bp_block;
343 max_bytes = ALIGN_DOWN(max_bytes, PAGE_SIZE);
345 lim.max_hw_discard_sectors = max_bytes / block->bp_block;
346 lim.max_write_zeroes_sectors = lim.max_hw_discard_sectors;
348 rc = queue_limits_commit_update(block->gdp->queue, &lim);
352 set_capacity(block->gdp, block->blocks << block->s2b_shift);
353 device->state = DASD_STATE_READY;
355 rc = dasd_scan_partitions(block);
357 device->state = DASD_STATE_BASIC;
362 if (device->discipline->basic_to_ready)
363 rc = device->discipline->basic_to_ready(device);
368 int _wait_for_empty_queues(struct dasd_device *device)
371 return list_empty(&device->ccw_queue) &&
372 list_empty(&device->block->ccw_queue);
374 return list_empty(&device->ccw_queue);
378 * Remove device from block device layer. Destroy dirty buffers.
379 * Forget format information. Check if the target level is basic
380 * and if it is create fake disk for formatting.
382 static int dasd_state_ready_to_basic(struct dasd_device *device)
386 device->state = DASD_STATE_BASIC;
388 struct dasd_block *block = device->block;
389 rc = dasd_flush_block_queue(block);
391 device->state = DASD_STATE_READY;
394 dasd_destroy_partitions(block);
397 block->s2b_shift = 0;
405 static int dasd_state_unfmt_to_basic(struct dasd_device *device)
407 device->state = DASD_STATE_BASIC;
412 * Make the device online and schedule the bottom half to start
413 * the requeueing of requests from the linux request queue to the
417 dasd_state_ready_to_online(struct dasd_device * device)
419 device->state = DASD_STATE_ONLINE;
421 dasd_schedule_block_bh(device->block);
422 if ((device->features & DASD_FEATURE_USERAW)) {
423 kobject_uevent(&disk_to_dev(device->block->gdp)->kobj,
427 disk_uevent(file_bdev(device->block->bdev_file)->bd_disk,
434 * Stop the requeueing of requests again.
436 static int dasd_state_online_to_ready(struct dasd_device *device)
440 if (device->discipline->online_to_ready) {
441 rc = device->discipline->online_to_ready(device);
446 device->state = DASD_STATE_READY;
447 if (device->block && !(device->features & DASD_FEATURE_USERAW))
448 disk_uevent(file_bdev(device->block->bdev_file)->bd_disk,
454 * Device startup state changes.
456 static int dasd_increase_state(struct dasd_device *device)
461 if (device->state == DASD_STATE_NEW &&
462 device->target >= DASD_STATE_KNOWN)
463 rc = dasd_state_new_to_known(device);
466 device->state == DASD_STATE_KNOWN &&
467 device->target >= DASD_STATE_BASIC)
468 rc = dasd_state_known_to_basic(device);
471 device->state == DASD_STATE_BASIC &&
472 device->target >= DASD_STATE_READY)
473 rc = dasd_state_basic_to_ready(device);
476 device->state == DASD_STATE_UNFMT &&
477 device->target > DASD_STATE_UNFMT)
481 device->state == DASD_STATE_READY &&
482 device->target >= DASD_STATE_ONLINE)
483 rc = dasd_state_ready_to_online(device);
489 * Device shutdown state changes.
491 static int dasd_decrease_state(struct dasd_device *device)
496 if (device->state == DASD_STATE_ONLINE &&
497 device->target <= DASD_STATE_READY)
498 rc = dasd_state_online_to_ready(device);
501 device->state == DASD_STATE_READY &&
502 device->target <= DASD_STATE_BASIC)
503 rc = dasd_state_ready_to_basic(device);
506 device->state == DASD_STATE_UNFMT &&
507 device->target <= DASD_STATE_BASIC)
508 rc = dasd_state_unfmt_to_basic(device);
511 device->state == DASD_STATE_BASIC &&
512 device->target <= DASD_STATE_KNOWN)
513 rc = dasd_state_basic_to_known(device);
516 device->state == DASD_STATE_KNOWN &&
517 device->target <= DASD_STATE_NEW)
518 rc = dasd_state_known_to_new(device);
524 * This is the main startup/shutdown routine.
526 static void dasd_change_state(struct dasd_device *device)
530 if (device->state == device->target)
531 /* Already where we want to go today... */
533 if (device->state < device->target)
534 rc = dasd_increase_state(device);
536 rc = dasd_decrease_state(device);
540 device->target = device->state;
542 /* let user-space know that the device status changed */
543 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
545 if (device->state == device->target)
546 wake_up(&dasd_init_waitq);
550 * Kick starter for devices that did not complete the startup/shutdown
551 * procedure or were sleeping because of a pending state.
552 * dasd_kick_device will schedule a call do do_kick_device to the kernel
555 static void do_kick_device(struct work_struct *work)
557 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
558 mutex_lock(&device->state_mutex);
559 dasd_change_state(device);
560 mutex_unlock(&device->state_mutex);
561 dasd_schedule_device_bh(device);
562 dasd_put_device(device);
565 void dasd_kick_device(struct dasd_device *device)
567 dasd_get_device(device);
568 /* queue call to dasd_kick_device to the kernel event daemon. */
569 if (!schedule_work(&device->kick_work))
570 dasd_put_device(device);
572 EXPORT_SYMBOL(dasd_kick_device);
575 * dasd_reload_device will schedule a call do do_reload_device to the kernel
578 static void do_reload_device(struct work_struct *work)
580 struct dasd_device *device = container_of(work, struct dasd_device,
582 device->discipline->reload(device);
583 dasd_put_device(device);
586 void dasd_reload_device(struct dasd_device *device)
588 dasd_get_device(device);
589 /* queue call to dasd_reload_device to the kernel event daemon. */
590 if (!schedule_work(&device->reload_device))
591 dasd_put_device(device);
593 EXPORT_SYMBOL(dasd_reload_device);
596 * Set the target state for a device and starts the state change.
598 void dasd_set_target_state(struct dasd_device *device, int target)
600 dasd_get_device(device);
601 mutex_lock(&device->state_mutex);
602 /* If we are in probeonly mode stop at DASD_STATE_READY. */
603 if (dasd_probeonly && target > DASD_STATE_READY)
604 target = DASD_STATE_READY;
605 if (device->target != target) {
606 if (device->state == target)
607 wake_up(&dasd_init_waitq);
608 device->target = target;
610 if (device->state != device->target)
611 dasd_change_state(device);
612 mutex_unlock(&device->state_mutex);
613 dasd_put_device(device);
617 * Enable devices with device numbers in [from..to].
619 static inline int _wait_for_device(struct dasd_device *device)
621 return (device->state == device->target);
624 void dasd_enable_device(struct dasd_device *device)
626 dasd_set_target_state(device, DASD_STATE_ONLINE);
627 if (device->state <= DASD_STATE_KNOWN)
628 /* No discipline for device found. */
629 dasd_set_target_state(device, DASD_STATE_NEW);
630 /* Now wait for the devices to come up. */
631 wait_event(dasd_init_waitq, _wait_for_device(device));
633 dasd_reload_device(device);
634 if (device->discipline->kick_validate)
635 device->discipline->kick_validate(device);
637 EXPORT_SYMBOL(dasd_enable_device);
640 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
643 unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
645 #ifdef CONFIG_DASD_PROFILE
646 struct dasd_profile dasd_global_profile = {
647 .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
649 static struct dentry *dasd_debugfs_global_entry;
652 * Add profiling information for cqr before execution.
654 static void dasd_profile_start(struct dasd_block *block,
655 struct dasd_ccw_req *cqr,
659 unsigned int counter;
660 struct dasd_device *device;
662 /* count the length of the chanq for statistics */
664 if (dasd_global_profile_level || block->profile.data)
665 list_for_each(l, &block->ccw_queue)
669 spin_lock(&dasd_global_profile.lock);
670 if (dasd_global_profile.data) {
671 dasd_global_profile.data->dasd_io_nr_req[counter]++;
672 if (rq_data_dir(req) == READ)
673 dasd_global_profile.data->dasd_read_nr_req[counter]++;
675 spin_unlock(&dasd_global_profile.lock);
677 spin_lock(&block->profile.lock);
678 if (block->profile.data) {
679 block->profile.data->dasd_io_nr_req[counter]++;
680 if (rq_data_dir(req) == READ)
681 block->profile.data->dasd_read_nr_req[counter]++;
683 spin_unlock(&block->profile.lock);
686 * We count the request for the start device, even though it may run on
687 * some other device due to error recovery. This way we make sure that
688 * we count each request only once.
690 device = cqr->startdev;
691 if (!device->profile.data)
694 spin_lock(get_ccwdev_lock(device->cdev));
695 counter = 1; /* request is not yet queued on the start device */
696 list_for_each(l, &device->ccw_queue)
699 spin_unlock(get_ccwdev_lock(device->cdev));
701 spin_lock(&device->profile.lock);
702 device->profile.data->dasd_io_nr_req[counter]++;
703 if (rq_data_dir(req) == READ)
704 device->profile.data->dasd_read_nr_req[counter]++;
705 spin_unlock(&device->profile.lock);
709 * Add profiling information for cqr after execution.
712 #define dasd_profile_counter(value, index) \
714 for (index = 0; index < 31 && value >> (2+index); index++) \
718 static void dasd_profile_end_add_data(struct dasd_profile_info *data,
731 /* in case of an overflow, reset the whole profile */
732 if (data->dasd_io_reqs == UINT_MAX) {
733 memset(data, 0, sizeof(*data));
734 ktime_get_real_ts64(&data->starttod);
736 data->dasd_io_reqs++;
737 data->dasd_io_sects += sectors;
739 data->dasd_io_alias++;
743 data->dasd_io_secs[sectors_ind]++;
744 data->dasd_io_times[tottime_ind]++;
745 data->dasd_io_timps[tottimeps_ind]++;
746 data->dasd_io_time1[strtime_ind]++;
747 data->dasd_io_time2[irqtime_ind]++;
748 data->dasd_io_time2ps[irqtimeps_ind]++;
749 data->dasd_io_time3[endtime_ind]++;
752 data->dasd_read_reqs++;
753 data->dasd_read_sects += sectors;
755 data->dasd_read_alias++;
757 data->dasd_read_tpm++;
758 data->dasd_read_secs[sectors_ind]++;
759 data->dasd_read_times[tottime_ind]++;
760 data->dasd_read_time1[strtime_ind]++;
761 data->dasd_read_time2[irqtime_ind]++;
762 data->dasd_read_time3[endtime_ind]++;
766 static void dasd_profile_end(struct dasd_block *block,
767 struct dasd_ccw_req *cqr,
770 unsigned long strtime, irqtime, endtime, tottime;
771 unsigned long tottimeps, sectors;
772 struct dasd_device *device;
773 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
774 int irqtime_ind, irqtimeps_ind, endtime_ind;
775 struct dasd_profile_info *data;
777 device = cqr->startdev;
778 if (!(dasd_global_profile_level ||
779 block->profile.data ||
780 device->profile.data))
783 sectors = blk_rq_sectors(req);
784 if (!cqr->buildclk || !cqr->startclk ||
785 !cqr->stopclk || !cqr->endclk ||
789 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
790 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
791 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
792 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
793 tottimeps = tottime / sectors;
795 dasd_profile_counter(sectors, sectors_ind);
796 dasd_profile_counter(tottime, tottime_ind);
797 dasd_profile_counter(tottimeps, tottimeps_ind);
798 dasd_profile_counter(strtime, strtime_ind);
799 dasd_profile_counter(irqtime, irqtime_ind);
800 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
801 dasd_profile_counter(endtime, endtime_ind);
803 spin_lock(&dasd_global_profile.lock);
804 if (dasd_global_profile.data) {
805 data = dasd_global_profile.data;
806 data->dasd_sum_times += tottime;
807 data->dasd_sum_time_str += strtime;
808 data->dasd_sum_time_irq += irqtime;
809 data->dasd_sum_time_end += endtime;
810 dasd_profile_end_add_data(dasd_global_profile.data,
811 cqr->startdev != block->base,
813 rq_data_dir(req) == READ,
814 sectors, sectors_ind, tottime_ind,
815 tottimeps_ind, strtime_ind,
816 irqtime_ind, irqtimeps_ind,
819 spin_unlock(&dasd_global_profile.lock);
821 spin_lock(&block->profile.lock);
822 if (block->profile.data) {
823 data = block->profile.data;
824 data->dasd_sum_times += tottime;
825 data->dasd_sum_time_str += strtime;
826 data->dasd_sum_time_irq += irqtime;
827 data->dasd_sum_time_end += endtime;
828 dasd_profile_end_add_data(block->profile.data,
829 cqr->startdev != block->base,
831 rq_data_dir(req) == READ,
832 sectors, sectors_ind, tottime_ind,
833 tottimeps_ind, strtime_ind,
834 irqtime_ind, irqtimeps_ind,
837 spin_unlock(&block->profile.lock);
839 spin_lock(&device->profile.lock);
840 if (device->profile.data) {
841 data = device->profile.data;
842 data->dasd_sum_times += tottime;
843 data->dasd_sum_time_str += strtime;
844 data->dasd_sum_time_irq += irqtime;
845 data->dasd_sum_time_end += endtime;
846 dasd_profile_end_add_data(device->profile.data,
847 cqr->startdev != block->base,
849 rq_data_dir(req) == READ,
850 sectors, sectors_ind, tottime_ind,
851 tottimeps_ind, strtime_ind,
852 irqtime_ind, irqtimeps_ind,
855 spin_unlock(&device->profile.lock);
858 void dasd_profile_reset(struct dasd_profile *profile)
860 struct dasd_profile_info *data;
862 spin_lock_bh(&profile->lock);
863 data = profile->data;
865 spin_unlock_bh(&profile->lock);
868 memset(data, 0, sizeof(*data));
869 ktime_get_real_ts64(&data->starttod);
870 spin_unlock_bh(&profile->lock);
873 int dasd_profile_on(struct dasd_profile *profile)
875 struct dasd_profile_info *data;
877 data = kzalloc(sizeof(*data), GFP_KERNEL);
880 spin_lock_bh(&profile->lock);
882 spin_unlock_bh(&profile->lock);
886 ktime_get_real_ts64(&data->starttod);
887 profile->data = data;
888 spin_unlock_bh(&profile->lock);
892 void dasd_profile_off(struct dasd_profile *profile)
894 spin_lock_bh(&profile->lock);
895 kfree(profile->data);
896 profile->data = NULL;
897 spin_unlock_bh(&profile->lock);
900 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
904 buffer = vmalloc(user_len + 1);
906 return ERR_PTR(-ENOMEM);
907 if (copy_from_user(buffer, user_buf, user_len) != 0) {
909 return ERR_PTR(-EFAULT);
911 /* got the string, now strip linefeed. */
912 if (buffer[user_len - 1] == '\n')
913 buffer[user_len - 1] = 0;
915 buffer[user_len] = 0;
919 static ssize_t dasd_stats_write(struct file *file,
920 const char __user *user_buf,
921 size_t user_len, loff_t *pos)
925 struct seq_file *m = (struct seq_file *)file->private_data;
926 struct dasd_profile *prof = m->private;
928 if (user_len > 65536)
930 buffer = dasd_get_user_string(user_buf, user_len);
932 return PTR_ERR(buffer);
934 str = skip_spaces(buffer);
936 if (strncmp(str, "reset", 5) == 0) {
937 dasd_profile_reset(prof);
938 } else if (strncmp(str, "on", 2) == 0) {
939 rc = dasd_profile_on(prof);
943 if (prof == &dasd_global_profile) {
944 dasd_profile_reset(prof);
945 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
947 } else if (strncmp(str, "off", 3) == 0) {
948 if (prof == &dasd_global_profile)
949 dasd_global_profile_level = DASD_PROFILE_OFF;
950 dasd_profile_off(prof);
958 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
962 for (i = 0; i < 32; i++)
963 seq_printf(m, "%u ", array[i]);
967 static void dasd_stats_seq_print(struct seq_file *m,
968 struct dasd_profile_info *data)
970 seq_printf(m, "start_time %lld.%09ld\n",
971 (s64)data->starttod.tv_sec, data->starttod.tv_nsec);
972 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
973 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
974 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
975 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
976 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
977 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
978 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
979 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
980 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
981 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
982 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
983 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
984 seq_puts(m, "histogram_sectors ");
985 dasd_stats_array(m, data->dasd_io_secs);
986 seq_puts(m, "histogram_io_times ");
987 dasd_stats_array(m, data->dasd_io_times);
988 seq_puts(m, "histogram_io_times_weighted ");
989 dasd_stats_array(m, data->dasd_io_timps);
990 seq_puts(m, "histogram_time_build_to_ssch ");
991 dasd_stats_array(m, data->dasd_io_time1);
992 seq_puts(m, "histogram_time_ssch_to_irq ");
993 dasd_stats_array(m, data->dasd_io_time2);
994 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
995 dasd_stats_array(m, data->dasd_io_time2ps);
996 seq_puts(m, "histogram_time_irq_to_end ");
997 dasd_stats_array(m, data->dasd_io_time3);
998 seq_puts(m, "histogram_ccw_queue_length ");
999 dasd_stats_array(m, data->dasd_io_nr_req);
1000 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
1001 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
1002 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
1003 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
1004 seq_puts(m, "histogram_read_sectors ");
1005 dasd_stats_array(m, data->dasd_read_secs);
1006 seq_puts(m, "histogram_read_times ");
1007 dasd_stats_array(m, data->dasd_read_times);
1008 seq_puts(m, "histogram_read_time_build_to_ssch ");
1009 dasd_stats_array(m, data->dasd_read_time1);
1010 seq_puts(m, "histogram_read_time_ssch_to_irq ");
1011 dasd_stats_array(m, data->dasd_read_time2);
1012 seq_puts(m, "histogram_read_time_irq_to_end ");
1013 dasd_stats_array(m, data->dasd_read_time3);
1014 seq_puts(m, "histogram_read_ccw_queue_length ");
1015 dasd_stats_array(m, data->dasd_read_nr_req);
1018 static int dasd_stats_show(struct seq_file *m, void *v)
1020 struct dasd_profile *profile;
1021 struct dasd_profile_info *data;
1023 profile = m->private;
1024 spin_lock_bh(&profile->lock);
1025 data = profile->data;
1027 spin_unlock_bh(&profile->lock);
1028 seq_puts(m, "disabled\n");
1031 dasd_stats_seq_print(m, data);
1032 spin_unlock_bh(&profile->lock);
1036 static int dasd_stats_open(struct inode *inode, struct file *file)
1038 struct dasd_profile *profile = inode->i_private;
1039 return single_open(file, dasd_stats_show, profile);
1042 static const struct file_operations dasd_stats_raw_fops = {
1043 .owner = THIS_MODULE,
1044 .open = dasd_stats_open,
1046 .llseek = seq_lseek,
1047 .release = single_release,
1048 .write = dasd_stats_write,
1051 static void dasd_profile_init(struct dasd_profile *profile,
1052 struct dentry *base_dentry)
1059 profile->dentry = NULL;
1060 profile->data = NULL;
1061 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1062 pde = debugfs_create_file("statistics", mode, base_dentry,
1063 profile, &dasd_stats_raw_fops);
1064 if (pde && !IS_ERR(pde))
1065 profile->dentry = pde;
1069 static void dasd_profile_exit(struct dasd_profile *profile)
1071 dasd_profile_off(profile);
1072 debugfs_remove(profile->dentry);
1073 profile->dentry = NULL;
1076 static void dasd_statistics_removeroot(void)
1078 dasd_global_profile_level = DASD_PROFILE_OFF;
1079 dasd_profile_exit(&dasd_global_profile);
1080 debugfs_remove(dasd_debugfs_global_entry);
1081 debugfs_remove(dasd_debugfs_root_entry);
1084 static void dasd_statistics_createroot(void)
1088 dasd_debugfs_root_entry = NULL;
1089 pde = debugfs_create_dir("dasd", NULL);
1090 if (!pde || IS_ERR(pde))
1092 dasd_debugfs_root_entry = pde;
1093 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1094 if (!pde || IS_ERR(pde))
1096 dasd_debugfs_global_entry = pde;
1097 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
1101 DBF_EVENT(DBF_ERR, "%s",
1102 "Creation of the dasd debugfs interface failed");
1103 dasd_statistics_removeroot();
1108 #define dasd_profile_start(block, cqr, req) do {} while (0)
1109 #define dasd_profile_end(block, cqr, req) do {} while (0)
1111 static void dasd_statistics_createroot(void)
1116 static void dasd_statistics_removeroot(void)
1121 static void dasd_profile_init(struct dasd_profile *profile,
1122 struct dentry *base_dentry)
1127 static void dasd_profile_exit(struct dasd_profile *profile)
1132 int dasd_profile_on(struct dasd_profile *profile)
1137 #endif /* CONFIG_DASD_PROFILE */
1139 static int dasd_hosts_show(struct seq_file *m, void *v)
1141 struct dasd_device *device;
1142 int rc = -EOPNOTSUPP;
1144 device = m->private;
1145 dasd_get_device(device);
1147 if (device->discipline->hosts_print)
1148 rc = device->discipline->hosts_print(device, m);
1150 dasd_put_device(device);
1154 DEFINE_SHOW_ATTRIBUTE(dasd_hosts);
1156 static void dasd_hosts_exit(struct dasd_device *device)
1158 debugfs_remove(device->hosts_dentry);
1159 device->hosts_dentry = NULL;
1162 static void dasd_hosts_init(struct dentry *base_dentry,
1163 struct dasd_device *device)
1171 mode = S_IRUSR | S_IFREG;
1172 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1173 device, &dasd_hosts_fops);
1174 if (pde && !IS_ERR(pde))
1175 device->hosts_dentry = pde;
1178 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength, int datasize,
1179 struct dasd_device *device,
1180 struct dasd_ccw_req *cqr)
1182 unsigned long flags;
1187 size += cplength * sizeof(struct ccw1);
1191 size += (sizeof(*cqr) + 7L) & -8L;
1193 spin_lock_irqsave(&device->mem_lock, flags);
1194 data = chunk = dasd_alloc_chunk(&device->ccw_chunks, size);
1195 spin_unlock_irqrestore(&device->mem_lock, flags);
1197 return ERR_PTR(-ENOMEM);
1199 cqr = (void *) data;
1200 data += (sizeof(*cqr) + 7L) & -8L;
1202 memset(cqr, 0, sizeof(*cqr));
1203 cqr->mem_chunk = chunk;
1206 data += cplength * sizeof(struct ccw1);
1207 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1211 memset(cqr->data, 0, datasize);
1214 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1215 dasd_get_device(device);
1218 EXPORT_SYMBOL(dasd_smalloc_request);
1220 struct dasd_ccw_req *dasd_fmalloc_request(int magic, int cplength,
1222 struct dasd_device *device)
1224 struct dasd_ccw_req *cqr;
1225 unsigned long flags;
1229 cqr_size = (sizeof(*cqr) + 7L) & -8L;
1232 size += cplength * sizeof(struct ccw1);
1236 spin_lock_irqsave(&device->mem_lock, flags);
1237 cqr = dasd_alloc_chunk(&device->ese_chunks, size);
1238 spin_unlock_irqrestore(&device->mem_lock, flags);
1240 return ERR_PTR(-ENOMEM);
1241 memset(cqr, 0, sizeof(*cqr));
1242 data = (char *)cqr + cqr_size;
1246 data += cplength * sizeof(struct ccw1);
1247 memset(cqr->cpaddr, 0, cplength * sizeof(struct ccw1));
1252 memset(cqr->data, 0, datasize);
1256 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1257 dasd_get_device(device);
1261 EXPORT_SYMBOL(dasd_fmalloc_request);
1263 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1265 unsigned long flags;
1267 spin_lock_irqsave(&device->mem_lock, flags);
1268 dasd_free_chunk(&device->ccw_chunks, cqr->mem_chunk);
1269 spin_unlock_irqrestore(&device->mem_lock, flags);
1270 dasd_put_device(device);
1272 EXPORT_SYMBOL(dasd_sfree_request);
1274 void dasd_ffree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1276 unsigned long flags;
1278 spin_lock_irqsave(&device->mem_lock, flags);
1279 dasd_free_chunk(&device->ese_chunks, cqr);
1280 spin_unlock_irqrestore(&device->mem_lock, flags);
1281 dasd_put_device(device);
1283 EXPORT_SYMBOL(dasd_ffree_request);
1286 * Check discipline magic in cqr.
1288 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1290 struct dasd_device *device;
1294 device = cqr->startdev;
1295 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1296 DBF_DEV_EVENT(DBF_WARNING, device,
1297 " dasd_ccw_req 0x%08x magic doesn't match"
1298 " discipline 0x%08x",
1300 *(unsigned int *) device->discipline->name);
1307 * Terminate the current i/o and set the request to clear_pending.
1308 * Timer keeps device runnig.
1309 * ccw_device_clear can fail if the i/o subsystem
1312 int dasd_term_IO(struct dasd_ccw_req *cqr)
1314 struct dasd_device *device;
1318 rc = dasd_check_cqr(cqr);
1322 device = (struct dasd_device *) cqr->startdev;
1323 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1324 rc = ccw_device_clear(device->cdev, (long) cqr);
1326 case 0: /* termination successful */
1327 cqr->status = DASD_CQR_CLEAR_PENDING;
1328 cqr->stopclk = get_tod_clock();
1330 DBF_DEV_EVENT(DBF_DEBUG, device,
1331 "terminate cqr %p successful",
1335 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1336 "device gone, retry");
1340 * device not valid so no I/O could be running
1341 * handle CQR as termination successful
1343 cqr->status = DASD_CQR_CLEARED;
1344 cqr->stopclk = get_tod_clock();
1346 /* no retries for invalid devices */
1348 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1349 "EINVAL, handle as terminated");
1350 /* fake rc to success */
1354 dev_err(&device->cdev->dev,
1355 "Unexpected error during request termination %d\n", rc);
1361 dasd_schedule_device_bh(device);
1364 EXPORT_SYMBOL(dasd_term_IO);
1367 * Start the i/o. This start_IO can fail if the channel is really busy.
1368 * In that case set up a timer to start the request later.
1370 int dasd_start_IO(struct dasd_ccw_req *cqr)
1372 struct dasd_device *device;
1376 rc = dasd_check_cqr(cqr);
1381 device = (struct dasd_device *) cqr->startdev;
1383 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1384 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1385 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1386 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1387 "because of stolen lock", cqr);
1388 cqr->status = DASD_CQR_ERROR;
1389 cqr->intrc = -EPERM;
1392 if (cqr->retries < 0) {
1393 dev_err(&device->cdev->dev,
1394 "Start I/O ran out of retries\n");
1395 cqr->status = DASD_CQR_ERROR;
1398 cqr->startclk = get_tod_clock();
1399 cqr->starttime = jiffies;
1401 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1402 cqr->lpm &= dasd_path_get_opm(device);
1404 cqr->lpm = dasd_path_get_opm(device);
1407 * remember the amount of formatted tracks to prevent double format on
1411 cqr->trkcount = atomic_read(&cqr->block->trkcount);
1413 if (cqr->cpmode == 1) {
1414 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1415 (long) cqr, cqr->lpm);
1417 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1418 (long) cqr, cqr->lpm, 0);
1422 cqr->status = DASD_CQR_IN_IO;
1425 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1426 "start_IO: device busy, retry later");
1429 /* -EACCES indicates that the request used only a subset of the
1430 * available paths and all these paths are gone. If the lpm of
1431 * this request was only a subset of the opm (e.g. the ppm) then
1432 * we just do a retry with all available paths.
1433 * If we already use the full opm, something is amiss, and we
1434 * need a full path verification.
1436 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1437 DBF_DEV_EVENT(DBF_WARNING, device,
1438 "start_IO: selected paths gone (%x)",
1440 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1441 cqr->lpm = dasd_path_get_opm(device);
1442 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1443 "start_IO: selected paths gone,"
1444 " retry on all paths");
1446 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1447 "start_IO: all paths in opm gone,"
1448 " do path verification");
1449 dasd_generic_last_path_gone(device);
1450 dasd_path_no_path(device);
1451 dasd_path_set_tbvpm(device,
1452 ccw_device_get_path_mask(
1457 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1458 "start_IO: -ENODEV device gone, retry");
1459 /* this is equivalent to CC=3 for SSCH report this to EER */
1460 dasd_handle_autoquiesce(device, cqr, DASD_EER_STARTIO);
1463 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1464 "start_IO: -EIO device gone, retry");
1467 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1468 "start_IO: -EINVAL device currently "
1472 dev_err(&device->cdev->dev,
1473 "Unexpected error during request start %d", rc);
1480 EXPORT_SYMBOL(dasd_start_IO);
1483 * Timeout function for dasd devices. This is used for different purposes
1484 * 1) missing interrupt handler for normal operation
1485 * 2) delayed start of request where start_IO failed with -EBUSY
1486 * 3) timeout for missing state change interrupts
1487 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1488 * DASD_CQR_QUEUED for 2) and 3).
1490 static void dasd_device_timeout(struct timer_list *t)
1492 unsigned long flags;
1493 struct dasd_device *device;
1495 device = from_timer(device, t, timer);
1496 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1497 /* re-activate request queue */
1498 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1499 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1500 dasd_schedule_device_bh(device);
1504 * Setup timeout for a device in jiffies.
1506 void dasd_device_set_timer(struct dasd_device *device, int expires)
1509 del_timer(&device->timer);
1511 mod_timer(&device->timer, jiffies + expires);
1513 EXPORT_SYMBOL(dasd_device_set_timer);
1516 * Clear timeout for a device.
1518 void dasd_device_clear_timer(struct dasd_device *device)
1520 del_timer(&device->timer);
1522 EXPORT_SYMBOL(dasd_device_clear_timer);
1524 static void dasd_handle_killed_request(struct ccw_device *cdev,
1525 unsigned long intparm)
1527 struct dasd_ccw_req *cqr;
1528 struct dasd_device *device;
1532 cqr = (struct dasd_ccw_req *) intparm;
1533 if (cqr->status != DASD_CQR_IN_IO) {
1534 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1535 "invalid status in handle_killed_request: "
1536 "%02x", cqr->status);
1540 device = dasd_device_from_cdev_locked(cdev);
1541 if (IS_ERR(device)) {
1542 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1543 "unable to get device from cdev");
1547 if (!cqr->startdev ||
1548 device != cqr->startdev ||
1549 strncmp(cqr->startdev->discipline->ebcname,
1550 (char *) &cqr->magic, 4)) {
1551 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1552 "invalid device in request");
1553 dasd_put_device(device);
1557 /* Schedule request to be retried. */
1558 cqr->status = DASD_CQR_QUEUED;
1560 dasd_device_clear_timer(device);
1561 dasd_schedule_device_bh(device);
1562 dasd_put_device(device);
1565 void dasd_generic_handle_state_change(struct dasd_device *device)
1567 /* First of all start sense subsystem status request. */
1568 dasd_eer_snss(device);
1570 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1571 dasd_schedule_device_bh(device);
1572 if (device->block) {
1573 dasd_schedule_block_bh(device->block);
1574 if (device->block->gdp)
1575 blk_mq_run_hw_queues(device->block->gdp->queue, true);
1578 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
1580 static int dasd_check_hpf_error(struct irb *irb)
1582 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1583 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1584 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1587 static int dasd_ese_needs_format(struct dasd_block *block, struct irb *irb)
1589 struct dasd_device *device = NULL;
1594 device = block->base;
1595 if (!device || !device->discipline->is_ese)
1597 if (!device->discipline->is_ese(device))
1600 sense = dasd_get_sense(irb);
1604 return !!(sense[1] & SNS1_NO_REC_FOUND) ||
1605 !!(sense[1] & SNS1_FILE_PROTECTED) ||
1606 scsw_cstat(&irb->scsw) == SCHN_STAT_INCORR_LEN;
1609 static int dasd_ese_oos_cond(u8 *sense)
1611 return sense[0] & SNS0_EQUIPMENT_CHECK &&
1612 sense[1] & SNS1_PERM_ERR &&
1613 sense[1] & SNS1_WRITE_INHIBITED &&
1618 * Interrupt handler for "normal" ssch-io based dasd devices.
1620 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1623 struct dasd_ccw_req *cqr, *next, *fcqr;
1624 struct dasd_device *device;
1626 int nrf_suppressed = 0;
1627 int fp_suppressed = 0;
1628 struct request *req;
1632 cqr = (struct dasd_ccw_req *) intparm;
1634 switch (PTR_ERR(irb)) {
1636 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1637 device = cqr->startdev;
1638 cqr->status = DASD_CQR_CLEARED;
1639 dasd_device_clear_timer(device);
1640 wake_up(&dasd_flush_wq);
1641 dasd_schedule_device_bh(device);
1646 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1647 "request timed out\n", __func__);
1650 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1651 "unknown error %ld\n", __func__,
1654 dasd_handle_killed_request(cdev, intparm);
1658 now = get_tod_clock();
1659 /* check for conditions that should be handled immediately */
1661 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1662 scsw_cstat(&irb->scsw) == 0)) {
1664 memcpy(&cqr->irb, irb, sizeof(*irb));
1665 device = dasd_device_from_cdev_locked(cdev);
1668 /* ignore unsolicited interrupts for DIAG discipline */
1669 if (device->discipline == dasd_diag_discipline_pointer) {
1670 dasd_put_device(device);
1675 * In some cases 'File Protected' or 'No Record Found' errors
1676 * might be expected and debug log messages for the
1677 * corresponding interrupts shouldn't be written then.
1678 * Check if either of the according suppress bits is set.
1680 sense = dasd_get_sense(irb);
1682 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1683 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1684 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1685 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1688 * Extent pool probably out-of-space.
1689 * Stop device and check exhaust level.
1691 if (dasd_ese_oos_cond(sense)) {
1692 dasd_generic_space_exhaust(device, cqr);
1693 device->discipline->ext_pool_exhaust(device, cqr);
1694 dasd_put_device(device);
1698 if (!(fp_suppressed || nrf_suppressed))
1699 device->discipline->dump_sense_dbf(device, irb, "int");
1701 if (device->features & DASD_FEATURE_ERPLOG)
1702 device->discipline->dump_sense(device, cqr, irb);
1703 device->discipline->check_for_device_change(device, cqr, irb);
1704 dasd_put_device(device);
1707 /* check for attention message */
1708 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1709 device = dasd_device_from_cdev_locked(cdev);
1710 if (!IS_ERR(device)) {
1711 device->discipline->check_attention(device,
1712 irb->esw.esw1.lpum);
1713 dasd_put_device(device);
1720 device = (struct dasd_device *) cqr->startdev;
1722 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1723 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1724 "invalid device in request");
1728 if (dasd_ese_needs_format(cqr->block, irb)) {
1729 req = dasd_get_callback_data(cqr);
1731 cqr->status = DASD_CQR_ERROR;
1734 if (rq_data_dir(req) == READ) {
1735 device->discipline->ese_read(cqr, irb);
1736 cqr->status = DASD_CQR_SUCCESS;
1738 dasd_device_clear_timer(device);
1739 dasd_schedule_device_bh(device);
1742 fcqr = device->discipline->ese_format(device, cqr, irb);
1744 if (PTR_ERR(fcqr) == -EINVAL) {
1745 cqr->status = DASD_CQR_ERROR;
1749 * If we can't format now, let the request go
1750 * one extra round. Maybe we can format later.
1752 cqr->status = DASD_CQR_QUEUED;
1753 dasd_schedule_device_bh(device);
1756 fcqr->status = DASD_CQR_QUEUED;
1757 cqr->status = DASD_CQR_QUEUED;
1758 list_add(&fcqr->devlist, &device->ccw_queue);
1759 dasd_schedule_device_bh(device);
1764 /* Check for clear pending */
1765 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1766 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1767 cqr->status = DASD_CQR_CLEARED;
1768 dasd_device_clear_timer(device);
1769 wake_up(&dasd_flush_wq);
1770 dasd_schedule_device_bh(device);
1774 /* check status - the request might have been killed by dyn detach */
1775 if (cqr->status != DASD_CQR_IN_IO) {
1776 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1777 "status %02x", dev_name(&cdev->dev), cqr->status);
1783 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1784 scsw_cstat(&irb->scsw) == 0) {
1785 /* request was completed successfully */
1786 cqr->status = DASD_CQR_SUCCESS;
1788 /* Start first request on queue if possible -> fast_io. */
1789 if (cqr->devlist.next != &device->ccw_queue) {
1790 next = list_entry(cqr->devlist.next,
1791 struct dasd_ccw_req, devlist);
1793 } else { /* error */
1794 /* check for HPF error
1795 * call discipline function to requeue all requests
1796 * and disable HPF accordingly
1798 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1799 device->discipline->handle_hpf_error)
1800 device->discipline->handle_hpf_error(device, irb);
1802 * If we don't want complex ERP for this request, then just
1803 * reset this and retry it in the fastpath
1805 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1807 if (cqr->lpm == dasd_path_get_opm(device))
1808 DBF_DEV_EVENT(DBF_DEBUG, device,
1809 "default ERP in fastpath "
1810 "(%i retries left)",
1812 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1813 cqr->lpm = dasd_path_get_opm(device);
1814 cqr->status = DASD_CQR_QUEUED;
1817 cqr->status = DASD_CQR_ERROR;
1819 if (next && (next->status == DASD_CQR_QUEUED) &&
1820 (!device->stopped)) {
1821 if (device->discipline->start_IO(next) == 0)
1822 expires = next->expires;
1825 dasd_device_set_timer(device, expires);
1827 dasd_device_clear_timer(device);
1828 dasd_schedule_device_bh(device);
1830 EXPORT_SYMBOL(dasd_int_handler);
1832 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1834 struct dasd_device *device;
1836 device = dasd_device_from_cdev_locked(cdev);
1840 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1841 device->state != device->target ||
1842 !device->discipline->check_for_device_change){
1843 dasd_put_device(device);
1846 if (device->discipline->dump_sense_dbf)
1847 device->discipline->dump_sense_dbf(device, irb, "uc");
1848 device->discipline->check_for_device_change(device, NULL, irb);
1849 dasd_put_device(device);
1851 return UC_TODO_RETRY;
1853 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1856 * If we have an error on a dasd_block layer request then we cancel
1857 * and return all further requests from the same dasd_block as well.
1859 static void __dasd_device_recovery(struct dasd_device *device,
1860 struct dasd_ccw_req *ref_cqr)
1862 struct list_head *l, *n;
1863 struct dasd_ccw_req *cqr;
1866 * only requeue request that came from the dasd_block layer
1868 if (!ref_cqr->block)
1871 list_for_each_safe(l, n, &device->ccw_queue) {
1872 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1873 if (cqr->status == DASD_CQR_QUEUED &&
1874 ref_cqr->block == cqr->block) {
1875 cqr->status = DASD_CQR_CLEARED;
1881 * Remove those ccw requests from the queue that need to be returned
1882 * to the upper layer.
1884 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1885 struct list_head *final_queue)
1887 struct list_head *l, *n;
1888 struct dasd_ccw_req *cqr;
1890 /* Process request with final status. */
1891 list_for_each_safe(l, n, &device->ccw_queue) {
1892 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1894 /* Skip any non-final request. */
1895 if (cqr->status == DASD_CQR_QUEUED ||
1896 cqr->status == DASD_CQR_IN_IO ||
1897 cqr->status == DASD_CQR_CLEAR_PENDING)
1899 if (cqr->status == DASD_CQR_ERROR) {
1900 __dasd_device_recovery(device, cqr);
1902 /* Rechain finished requests to final queue */
1903 list_move_tail(&cqr->devlist, final_queue);
1907 static void __dasd_process_cqr(struct dasd_device *device,
1908 struct dasd_ccw_req *cqr)
1910 switch (cqr->status) {
1911 case DASD_CQR_SUCCESS:
1912 cqr->status = DASD_CQR_DONE;
1914 case DASD_CQR_ERROR:
1915 cqr->status = DASD_CQR_NEED_ERP;
1917 case DASD_CQR_CLEARED:
1918 cqr->status = DASD_CQR_TERMINATED;
1921 dev_err(&device->cdev->dev,
1922 "Unexpected CQR status %02x", cqr->status);
1926 cqr->callback(cqr, cqr->callback_data);
1930 * the cqrs from the final queue are returned to the upper layer
1931 * by setting a dasd_block state and calling the callback function
1933 static void __dasd_device_process_final_queue(struct dasd_device *device,
1934 struct list_head *final_queue)
1936 struct list_head *l, *n;
1937 struct dasd_ccw_req *cqr;
1938 struct dasd_block *block;
1940 list_for_each_safe(l, n, final_queue) {
1941 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1942 list_del_init(&cqr->devlist);
1945 __dasd_process_cqr(device, cqr);
1947 spin_lock_bh(&block->queue_lock);
1948 __dasd_process_cqr(device, cqr);
1949 spin_unlock_bh(&block->queue_lock);
1955 * check if device should be autoquiesced due to too many timeouts
1957 static void __dasd_device_check_autoquiesce_timeout(struct dasd_device *device,
1958 struct dasd_ccw_req *cqr)
1960 if ((device->default_retries - cqr->retries) >= device->aq_timeouts)
1961 dasd_handle_autoquiesce(device, cqr, DASD_EER_TIMEOUTS);
1965 * Take a look at the first request on the ccw queue and check
1966 * if it reached its expire time. If so, terminate the IO.
1968 static void __dasd_device_check_expire(struct dasd_device *device)
1970 struct dasd_ccw_req *cqr;
1972 if (list_empty(&device->ccw_queue))
1974 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1975 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1976 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1977 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1979 * IO in safe offline processing should not
1980 * run out of retries
1984 if (device->discipline->term_IO(cqr) != 0) {
1985 /* Hmpf, try again in 5 sec */
1986 dev_err(&device->cdev->dev,
1987 "CQR timed out (%lus) but cannot be ended, retrying in 5s\n",
1988 (cqr->expires / HZ));
1989 cqr->expires += 5*HZ;
1990 dasd_device_set_timer(device, 5*HZ);
1992 dev_err(&device->cdev->dev,
1993 "CQR timed out (%lus), %i retries remaining\n",
1994 (cqr->expires / HZ), cqr->retries);
1996 __dasd_device_check_autoquiesce_timeout(device, cqr);
2001 * return 1 when device is not eligible for IO
2003 static int __dasd_device_is_unusable(struct dasd_device *device,
2004 struct dasd_ccw_req *cqr)
2006 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_STOPPED_NOSPC);
2008 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
2009 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
2011 * dasd is being set offline
2012 * but it is no safe offline where we have to allow I/O
2016 if (device->stopped) {
2017 if (device->stopped & mask) {
2018 /* stopped and CQR will not change that. */
2021 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2022 /* CQR is not able to change device to
2026 /* CQR required to get device operational. */
2032 * Take a look at the first request on the ccw queue and check
2033 * if it needs to be started.
2035 static void __dasd_device_start_head(struct dasd_device *device)
2037 struct dasd_ccw_req *cqr;
2040 if (list_empty(&device->ccw_queue))
2042 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2043 if (cqr->status != DASD_CQR_QUEUED)
2045 /* if device is not usable return request to upper layer */
2046 if (__dasd_device_is_unusable(device, cqr)) {
2047 cqr->intrc = -EAGAIN;
2048 cqr->status = DASD_CQR_CLEARED;
2049 dasd_schedule_device_bh(device);
2053 rc = device->discipline->start_IO(cqr);
2055 dasd_device_set_timer(device, cqr->expires);
2056 else if (rc == -EACCES) {
2057 dasd_schedule_device_bh(device);
2059 /* Hmpf, try again in 1/2 sec */
2060 dasd_device_set_timer(device, 50);
2063 static void __dasd_device_check_path_events(struct dasd_device *device)
2065 __u8 tbvpm, fcsecpm;
2068 tbvpm = dasd_path_get_tbvpm(device);
2069 fcsecpm = dasd_path_get_fcsecpm(device);
2071 if (!tbvpm && !fcsecpm)
2074 if (device->stopped & ~(DASD_STOPPED_DC_WAIT))
2077 dasd_path_clear_all_verify(device);
2078 dasd_path_clear_all_fcsec(device);
2080 rc = device->discipline->pe_handler(device, tbvpm, fcsecpm);
2082 dasd_path_add_tbvpm(device, tbvpm);
2083 dasd_path_add_fcsecpm(device, fcsecpm);
2084 dasd_device_set_timer(device, 50);
2089 * Go through all request on the dasd_device request queue,
2090 * terminate them on the cdev if necessary, and return them to the
2091 * submitting layer via callback.
2093 * Make sure that all 'submitting layers' still exist when
2094 * this function is called!. In other words, when 'device' is a base
2095 * device then all block layer requests must have been removed before
2096 * via dasd_flush_block_queue.
2098 int dasd_flush_device_queue(struct dasd_device *device)
2100 struct dasd_ccw_req *cqr, *n;
2102 struct list_head flush_queue;
2104 INIT_LIST_HEAD(&flush_queue);
2105 spin_lock_irq(get_ccwdev_lock(device->cdev));
2107 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2108 /* Check status and move request to flush_queue */
2109 switch (cqr->status) {
2110 case DASD_CQR_IN_IO:
2111 rc = device->discipline->term_IO(cqr);
2113 /* unable to terminate requeust */
2114 dev_err(&device->cdev->dev,
2115 "Flushing the DASD request queue failed\n");
2116 /* stop flush processing */
2120 case DASD_CQR_QUEUED:
2121 cqr->stopclk = get_tod_clock();
2122 cqr->status = DASD_CQR_CLEARED;
2124 default: /* no need to modify the others */
2127 list_move_tail(&cqr->devlist, &flush_queue);
2130 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2132 * After this point all requests must be in state CLEAR_PENDING,
2133 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2134 * one of the others.
2136 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2137 wait_event(dasd_flush_wq,
2138 (cqr->status != DASD_CQR_CLEAR_PENDING));
2140 * Now set each request back to TERMINATED, DONE or NEED_ERP
2141 * and call the callback function of flushed requests
2143 __dasd_device_process_final_queue(device, &flush_queue);
2146 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2149 * Acquire the device lock and process queues for the device.
2151 static void dasd_device_tasklet(unsigned long data)
2153 struct dasd_device *device = (struct dasd_device *) data;
2154 struct list_head final_queue;
2156 atomic_set (&device->tasklet_scheduled, 0);
2157 INIT_LIST_HEAD(&final_queue);
2158 spin_lock_irq(get_ccwdev_lock(device->cdev));
2159 /* Check expire time of first request on the ccw queue. */
2160 __dasd_device_check_expire(device);
2161 /* find final requests on ccw queue */
2162 __dasd_device_process_ccw_queue(device, &final_queue);
2163 __dasd_device_check_path_events(device);
2164 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2165 /* Now call the callback function of requests with final status */
2166 __dasd_device_process_final_queue(device, &final_queue);
2167 spin_lock_irq(get_ccwdev_lock(device->cdev));
2168 /* Now check if the head of the ccw queue needs to be started. */
2169 __dasd_device_start_head(device);
2170 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2171 if (waitqueue_active(&shutdown_waitq))
2172 wake_up(&shutdown_waitq);
2173 dasd_put_device(device);
2177 * Schedules a call to dasd_tasklet over the device tasklet.
2179 void dasd_schedule_device_bh(struct dasd_device *device)
2181 /* Protect against rescheduling. */
2182 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2184 dasd_get_device(device);
2185 tasklet_hi_schedule(&device->tasklet);
2187 EXPORT_SYMBOL(dasd_schedule_device_bh);
2189 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2191 device->stopped |= bits;
2193 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2195 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2197 device->stopped &= ~bits;
2198 if (!device->stopped)
2199 wake_up(&generic_waitq);
2201 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2204 * Queue a request to the head of the device ccw_queue.
2205 * Start the I/O if possible.
2207 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2209 struct dasd_device *device;
2210 unsigned long flags;
2212 device = cqr->startdev;
2213 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2214 cqr->status = DASD_CQR_QUEUED;
2215 list_add(&cqr->devlist, &device->ccw_queue);
2216 /* let the bh start the request to keep them in order */
2217 dasd_schedule_device_bh(device);
2218 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2220 EXPORT_SYMBOL(dasd_add_request_head);
2223 * Queue a request to the tail of the device ccw_queue.
2224 * Start the I/O if possible.
2226 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2228 struct dasd_device *device;
2229 unsigned long flags;
2231 device = cqr->startdev;
2232 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2233 cqr->status = DASD_CQR_QUEUED;
2234 list_add_tail(&cqr->devlist, &device->ccw_queue);
2235 /* let the bh start the request to keep them in order */
2236 dasd_schedule_device_bh(device);
2237 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2239 EXPORT_SYMBOL(dasd_add_request_tail);
2242 * Wakeup helper for the 'sleep_on' functions.
2244 void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2246 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2247 cqr->callback_data = DASD_SLEEPON_END_TAG;
2248 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2249 wake_up(&generic_waitq);
2251 EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
2253 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2255 struct dasd_device *device;
2258 device = cqr->startdev;
2259 spin_lock_irq(get_ccwdev_lock(device->cdev));
2260 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2261 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2266 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2268 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2270 struct dasd_device *device;
2271 dasd_erp_fn_t erp_fn;
2273 if (cqr->status == DASD_CQR_FILLED)
2275 device = cqr->startdev;
2276 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2277 if (cqr->status == DASD_CQR_TERMINATED) {
2278 device->discipline->handle_terminated_request(cqr);
2281 if (cqr->status == DASD_CQR_NEED_ERP) {
2282 erp_fn = device->discipline->erp_action(cqr);
2286 if (cqr->status == DASD_CQR_FAILED)
2287 dasd_log_sense(cqr, &cqr->irb);
2289 __dasd_process_erp(device, cqr);
2296 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2298 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2299 if (cqr->refers) /* erp is not done yet */
2301 return ((cqr->status != DASD_CQR_DONE) &&
2302 (cqr->status != DASD_CQR_FAILED));
2304 return (cqr->status == DASD_CQR_FILLED);
2307 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2309 struct dasd_device *device;
2311 struct list_head ccw_queue;
2312 struct dasd_ccw_req *cqr;
2314 INIT_LIST_HEAD(&ccw_queue);
2315 maincqr->status = DASD_CQR_FILLED;
2316 device = maincqr->startdev;
2317 list_add(&maincqr->blocklist, &ccw_queue);
2318 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2319 cqr = list_first_entry(&ccw_queue,
2320 struct dasd_ccw_req, blocklist)) {
2322 if (__dasd_sleep_on_erp(cqr))
2324 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2326 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2327 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2328 cqr->status = DASD_CQR_FAILED;
2329 cqr->intrc = -EPERM;
2332 /* Non-temporary stop condition will trigger fail fast */
2333 if (device->stopped & ~DASD_STOPPED_PENDING &&
2334 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2335 !dasd_eer_enabled(device) && device->aq_mask == 0) {
2336 cqr->status = DASD_CQR_FAILED;
2337 cqr->intrc = -ENOLINK;
2341 * Don't try to start requests if device is in
2342 * offline processing, it might wait forever
2344 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2345 cqr->status = DASD_CQR_FAILED;
2346 cqr->intrc = -ENODEV;
2350 * Don't try to start requests if device is stopped
2351 * except path verification requests
2353 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2354 if (interruptible) {
2355 rc = wait_event_interruptible(
2356 generic_waitq, !(device->stopped));
2357 if (rc == -ERESTARTSYS) {
2358 cqr->status = DASD_CQR_FAILED;
2359 maincqr->intrc = rc;
2363 wait_event(generic_waitq, !(device->stopped));
2366 cqr->callback = dasd_wakeup_cb;
2368 cqr->callback_data = DASD_SLEEPON_START_TAG;
2369 dasd_add_request_tail(cqr);
2370 if (interruptible) {
2371 rc = wait_event_interruptible(
2372 generic_waitq, _wait_for_wakeup(cqr));
2373 if (rc == -ERESTARTSYS) {
2374 dasd_cancel_req(cqr);
2375 /* wait (non-interruptible) for final status */
2376 wait_event(generic_waitq,
2377 _wait_for_wakeup(cqr));
2378 cqr->status = DASD_CQR_FAILED;
2379 maincqr->intrc = rc;
2383 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2386 maincqr->endclk = get_tod_clock();
2387 if ((maincqr->status != DASD_CQR_DONE) &&
2388 (maincqr->intrc != -ERESTARTSYS))
2389 dasd_log_sense(maincqr, &maincqr->irb);
2390 if (maincqr->status == DASD_CQR_DONE)
2392 else if (maincqr->intrc)
2393 rc = maincqr->intrc;
2399 static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2401 struct dasd_ccw_req *cqr;
2403 list_for_each_entry(cqr, ccw_queue, blocklist) {
2404 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2411 static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2413 struct dasd_device *device;
2414 struct dasd_ccw_req *cqr, *n;
2419 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2420 device = cqr->startdev;
2421 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2424 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2425 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2426 cqr->status = DASD_CQR_FAILED;
2427 cqr->intrc = -EPERM;
2430 /*Non-temporary stop condition will trigger fail fast*/
2431 if (device->stopped & ~DASD_STOPPED_PENDING &&
2432 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2433 !dasd_eer_enabled(device)) {
2434 cqr->status = DASD_CQR_FAILED;
2435 cqr->intrc = -EAGAIN;
2439 /*Don't try to start requests if device is stopped*/
2440 if (interruptible) {
2441 rc = wait_event_interruptible(
2442 generic_waitq, !device->stopped);
2443 if (rc == -ERESTARTSYS) {
2444 cqr->status = DASD_CQR_FAILED;
2449 wait_event(generic_waitq, !(device->stopped));
2452 cqr->callback = dasd_wakeup_cb;
2453 cqr->callback_data = DASD_SLEEPON_START_TAG;
2454 dasd_add_request_tail(cqr);
2457 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2460 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2462 * In some cases the 'File Protected' or 'Incorrect Length'
2463 * error might be expected and error recovery would be
2464 * unnecessary in these cases. Check if the according suppress
2467 sense = dasd_get_sense(&cqr->irb);
2468 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2469 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2471 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2472 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2476 * for alias devices simplify error recovery and
2477 * return to upper layer
2478 * do not skip ERP requests
2480 if (cqr->startdev != cqr->basedev && !cqr->refers &&
2481 (cqr->status == DASD_CQR_TERMINATED ||
2482 cqr->status == DASD_CQR_NEED_ERP))
2485 /* normal recovery for basedev IO */
2486 if (__dasd_sleep_on_erp(cqr))
2487 /* handle erp first */
2495 * Queue a request to the tail of the device ccw_queue and wait for
2498 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2500 return _dasd_sleep_on(cqr, 0);
2502 EXPORT_SYMBOL(dasd_sleep_on);
2505 * Start requests from a ccw_queue and wait for their completion.
2507 int dasd_sleep_on_queue(struct list_head *ccw_queue)
2509 return _dasd_sleep_on_queue(ccw_queue, 0);
2511 EXPORT_SYMBOL(dasd_sleep_on_queue);
2514 * Start requests from a ccw_queue and wait interruptible for their completion.
2516 int dasd_sleep_on_queue_interruptible(struct list_head *ccw_queue)
2518 return _dasd_sleep_on_queue(ccw_queue, 1);
2520 EXPORT_SYMBOL(dasd_sleep_on_queue_interruptible);
2523 * Queue a request to the tail of the device ccw_queue and wait
2524 * interruptible for it's completion.
2526 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2528 return _dasd_sleep_on(cqr, 1);
2530 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2533 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2534 * for eckd devices) the currently running request has to be terminated
2535 * and be put back to status queued, before the special request is added
2536 * to the head of the queue. Then the special request is waited on normally.
2538 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2540 struct dasd_ccw_req *cqr;
2543 if (list_empty(&device->ccw_queue))
2545 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2546 rc = device->discipline->term_IO(cqr);
2549 * CQR terminated because a more important request is pending.
2550 * Undo decreasing of retry counter because this is
2551 * not an error case.
2557 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2559 struct dasd_device *device;
2562 device = cqr->startdev;
2563 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2564 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2565 cqr->status = DASD_CQR_FAILED;
2566 cqr->intrc = -EPERM;
2569 spin_lock_irq(get_ccwdev_lock(device->cdev));
2570 rc = _dasd_term_running_cqr(device);
2572 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2575 cqr->callback = dasd_wakeup_cb;
2576 cqr->callback_data = DASD_SLEEPON_START_TAG;
2577 cqr->status = DASD_CQR_QUEUED;
2579 * add new request as second
2580 * first the terminated cqr needs to be finished
2582 list_add(&cqr->devlist, device->ccw_queue.next);
2584 /* let the bh start the request to keep them in order */
2585 dasd_schedule_device_bh(device);
2587 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2589 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2591 if (cqr->status == DASD_CQR_DONE)
2593 else if (cqr->intrc)
2599 dasd_schedule_device_bh(device);
2601 dasd_schedule_block_bh(device->block);
2605 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2608 * Cancels a request that was started with dasd_sleep_on_req.
2609 * This is useful to timeout requests. The request will be
2610 * terminated if it is currently in i/o.
2611 * Returns 0 if request termination was successful
2612 * negative error code if termination failed
2613 * Cancellation of a request is an asynchronous operation! The calling
2614 * function has to wait until the request is properly returned via callback.
2616 static int __dasd_cancel_req(struct dasd_ccw_req *cqr)
2618 struct dasd_device *device = cqr->startdev;
2621 switch (cqr->status) {
2622 case DASD_CQR_QUEUED:
2623 /* request was not started - just set to cleared */
2624 cqr->status = DASD_CQR_CLEARED;
2626 case DASD_CQR_IN_IO:
2627 /* request in IO - terminate IO and release again */
2628 rc = device->discipline->term_IO(cqr);
2630 dev_err(&device->cdev->dev,
2631 "Cancelling request failed with rc=%d\n", rc);
2633 cqr->stopclk = get_tod_clock();
2636 default: /* already finished or clear pending - do nothing */
2639 dasd_schedule_device_bh(device);
2643 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2645 struct dasd_device *device = cqr->startdev;
2646 unsigned long flags;
2649 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2650 rc = __dasd_cancel_req(cqr);
2651 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2656 * SECTION: Operations of the dasd_block layer.
2660 * Timeout function for dasd_block. This is used when the block layer
2661 * is waiting for something that may not come reliably, (e.g. a state
2664 static void dasd_block_timeout(struct timer_list *t)
2666 unsigned long flags;
2667 struct dasd_block *block;
2669 block = from_timer(block, t, timer);
2670 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2671 /* re-activate request queue */
2672 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2673 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2674 dasd_schedule_block_bh(block);
2675 blk_mq_run_hw_queues(block->gdp->queue, true);
2679 * Setup timeout for a dasd_block in jiffies.
2681 void dasd_block_set_timer(struct dasd_block *block, int expires)
2684 del_timer(&block->timer);
2686 mod_timer(&block->timer, jiffies + expires);
2688 EXPORT_SYMBOL(dasd_block_set_timer);
2691 * Clear timeout for a dasd_block.
2693 void dasd_block_clear_timer(struct dasd_block *block)
2695 del_timer(&block->timer);
2697 EXPORT_SYMBOL(dasd_block_clear_timer);
2700 * Process finished error recovery ccw.
2702 static void __dasd_process_erp(struct dasd_device *device,
2703 struct dasd_ccw_req *cqr)
2705 dasd_erp_fn_t erp_fn;
2707 if (cqr->status == DASD_CQR_DONE)
2708 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2710 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2711 erp_fn = device->discipline->erp_postaction(cqr);
2715 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2717 struct request *req;
2718 blk_status_t error = BLK_STS_OK;
2719 unsigned int proc_bytes;
2722 req = (struct request *) cqr->callback_data;
2723 dasd_profile_end(cqr->block, cqr, req);
2725 proc_bytes = cqr->proc_bytes;
2726 status = cqr->block->base->discipline->free_cp(cqr, req);
2728 error = errno_to_blk_status(status);
2729 else if (status == 0) {
2730 switch (cqr->intrc) {
2733 * DASD doesn't implement SCSI/NVMe reservations, but it
2734 * implements a locking scheme similar to them. We
2735 * return this error when we no longer have the lock.
2737 error = BLK_STS_RESV_CONFLICT;
2740 error = BLK_STS_TRANSPORT;
2743 error = BLK_STS_TIMEOUT;
2746 error = BLK_STS_IOERR;
2752 * We need to take care for ETIMEDOUT errors here since the
2753 * complete callback does not get called in this case.
2754 * Take care of all errors here and avoid additional code to
2755 * transfer the error value to the complete callback.
2758 blk_mq_end_request(req, error);
2759 blk_mq_run_hw_queues(req->q, true);
2762 * Partial completed requests can happen with ESE devices.
2763 * During read we might have gotten a NRF error and have to
2764 * complete a request partially.
2767 blk_update_request(req, BLK_STS_OK, proc_bytes);
2768 blk_mq_requeue_request(req, true);
2769 } else if (likely(!blk_should_fake_timeout(req->q))) {
2770 blk_mq_complete_request(req);
2776 * Process ccw request queue.
2778 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2779 struct list_head *final_queue)
2781 struct list_head *l, *n;
2782 struct dasd_ccw_req *cqr;
2783 dasd_erp_fn_t erp_fn;
2784 unsigned long flags;
2785 struct dasd_device *base = block->base;
2788 /* Process request with final status. */
2789 list_for_each_safe(l, n, &block->ccw_queue) {
2790 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2791 if (cqr->status != DASD_CQR_DONE &&
2792 cqr->status != DASD_CQR_FAILED &&
2793 cqr->status != DASD_CQR_NEED_ERP &&
2794 cqr->status != DASD_CQR_TERMINATED)
2797 if (cqr->status == DASD_CQR_TERMINATED) {
2798 base->discipline->handle_terminated_request(cqr);
2802 /* Process requests that may be recovered */
2803 if (cqr->status == DASD_CQR_NEED_ERP) {
2804 erp_fn = base->discipline->erp_action(cqr);
2805 if (IS_ERR(erp_fn(cqr)))
2810 /* log sense for fatal error */
2811 if (cqr->status == DASD_CQR_FAILED) {
2812 dasd_log_sense(cqr, &cqr->irb);
2816 * First call extended error reporting and check for autoquiesce
2818 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2819 if (cqr->status == DASD_CQR_FAILED &&
2820 dasd_handle_autoquiesce(base, cqr, DASD_EER_FATALERROR)) {
2821 cqr->status = DASD_CQR_FILLED;
2823 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
2826 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
2828 /* Process finished ERP request. */
2830 __dasd_process_erp(base, cqr);
2834 /* Rechain finished requests to final queue */
2835 cqr->endclk = get_tod_clock();
2836 list_move_tail(&cqr->blocklist, final_queue);
2840 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2842 dasd_schedule_block_bh(cqr->block);
2845 static void __dasd_block_start_head(struct dasd_block *block)
2847 struct dasd_ccw_req *cqr;
2849 if (list_empty(&block->ccw_queue))
2851 /* We allways begin with the first requests on the queue, as some
2852 * of previously started requests have to be enqueued on a
2853 * dasd_device again for error recovery.
2855 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2856 if (cqr->status != DASD_CQR_FILLED)
2858 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2859 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2860 cqr->status = DASD_CQR_FAILED;
2861 cqr->intrc = -EPERM;
2862 dasd_schedule_block_bh(block);
2865 /* Non-temporary stop condition will trigger fail fast */
2866 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2867 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2868 !dasd_eer_enabled(block->base) && block->base->aq_mask == 0) {
2869 cqr->status = DASD_CQR_FAILED;
2870 cqr->intrc = -ENOLINK;
2871 dasd_schedule_block_bh(block);
2874 /* Don't try to start requests if device is stopped */
2875 if (block->base->stopped)
2878 /* just a fail safe check, should not happen */
2880 cqr->startdev = block->base;
2882 /* make sure that the requests we submit find their way back */
2883 cqr->callback = dasd_return_cqr_cb;
2885 dasd_add_request_tail(cqr);
2890 * Central dasd_block layer routine. Takes requests from the generic
2891 * block layer request queue, creates ccw requests, enqueues them on
2892 * a dasd_device and processes ccw requests that have been returned.
2894 static void dasd_block_tasklet(unsigned long data)
2896 struct dasd_block *block = (struct dasd_block *) data;
2897 struct list_head final_queue;
2898 struct list_head *l, *n;
2899 struct dasd_ccw_req *cqr;
2900 struct dasd_queue *dq;
2902 atomic_set(&block->tasklet_scheduled, 0);
2903 INIT_LIST_HEAD(&final_queue);
2904 spin_lock_irq(&block->queue_lock);
2905 /* Finish off requests on ccw queue */
2906 __dasd_process_block_ccw_queue(block, &final_queue);
2907 spin_unlock_irq(&block->queue_lock);
2909 /* Now call the callback function of requests with final status */
2910 list_for_each_safe(l, n, &final_queue) {
2911 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2913 spin_lock_irq(&dq->lock);
2914 list_del_init(&cqr->blocklist);
2915 __dasd_cleanup_cqr(cqr);
2916 spin_unlock_irq(&dq->lock);
2919 spin_lock_irq(&block->queue_lock);
2920 /* Now check if the head of the ccw queue needs to be started. */
2921 __dasd_block_start_head(block);
2922 spin_unlock_irq(&block->queue_lock);
2924 if (waitqueue_active(&shutdown_waitq))
2925 wake_up(&shutdown_waitq);
2926 dasd_put_device(block->base);
2929 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2931 wake_up(&dasd_flush_wq);
2935 * Requeue a request back to the block request queue
2936 * only works for block requests
2938 static void _dasd_requeue_request(struct dasd_ccw_req *cqr)
2940 struct request *req;
2943 * If the request is an ERP request there is nothing to requeue.
2944 * This will be done with the remaining original request.
2948 spin_lock_irq(&cqr->dq->lock);
2949 req = (struct request *) cqr->callback_data;
2950 blk_mq_requeue_request(req, true);
2951 spin_unlock_irq(&cqr->dq->lock);
2956 static int _dasd_requests_to_flushqueue(struct dasd_block *block,
2957 struct list_head *flush_queue)
2959 struct dasd_ccw_req *cqr, *n;
2960 unsigned long flags;
2963 spin_lock_irqsave(&block->queue_lock, flags);
2966 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2967 /* if this request currently owned by a dasd_device cancel it */
2968 if (cqr->status >= DASD_CQR_QUEUED)
2969 rc = dasd_cancel_req(cqr);
2972 /* Rechain request (including erp chain) so it won't be
2973 * touched by the dasd_block_tasklet anymore.
2974 * Replace the callback so we notice when the request
2975 * is returned from the dasd_device layer.
2977 cqr->callback = _dasd_wake_block_flush_cb;
2978 for (i = 0; cqr; cqr = cqr->refers, i++)
2979 list_move_tail(&cqr->blocklist, flush_queue);
2981 /* moved more than one request - need to restart */
2984 spin_unlock_irqrestore(&block->queue_lock, flags);
2990 * Go through all request on the dasd_block request queue, cancel them
2991 * on the respective dasd_device, and return them to the generic
2994 static int dasd_flush_block_queue(struct dasd_block *block)
2996 struct dasd_ccw_req *cqr, *n;
2997 struct list_head flush_queue;
2998 unsigned long flags;
3001 INIT_LIST_HEAD(&flush_queue);
3002 rc = _dasd_requests_to_flushqueue(block, &flush_queue);
3004 /* Now call the callback function of flushed requests */
3006 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
3007 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
3008 /* Process finished ERP request. */
3010 spin_lock_bh(&block->queue_lock);
3011 __dasd_process_erp(block->base, cqr);
3012 spin_unlock_bh(&block->queue_lock);
3013 /* restart list_for_xx loop since dasd_process_erp
3014 * might remove multiple elements */
3017 /* call the callback function */
3018 spin_lock_irqsave(&cqr->dq->lock, flags);
3019 cqr->endclk = get_tod_clock();
3020 list_del_init(&cqr->blocklist);
3021 __dasd_cleanup_cqr(cqr);
3022 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3028 * Schedules a call to dasd_tasklet over the device tasklet.
3030 void dasd_schedule_block_bh(struct dasd_block *block)
3032 /* Protect against rescheduling. */
3033 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
3035 /* life cycle of block is bound to it's base device */
3036 dasd_get_device(block->base);
3037 tasklet_hi_schedule(&block->tasklet);
3039 EXPORT_SYMBOL(dasd_schedule_block_bh);
3043 * SECTION: external block device operations
3044 * (request queue handling, open, release, etc.)
3048 * Dasd request queue function. Called from ll_rw_blk.c
3050 static blk_status_t do_dasd_request(struct blk_mq_hw_ctx *hctx,
3051 const struct blk_mq_queue_data *qd)
3053 struct dasd_block *block = hctx->queue->queuedata;
3054 struct dasd_queue *dq = hctx->driver_data;
3055 struct request *req = qd->rq;
3056 struct dasd_device *basedev;
3057 struct dasd_ccw_req *cqr;
3058 blk_status_t rc = BLK_STS_OK;
3060 basedev = block->base;
3061 spin_lock_irq(&dq->lock);
3062 if (basedev->state < DASD_STATE_READY ||
3063 test_bit(DASD_FLAG_OFFLINE, &basedev->flags)) {
3064 DBF_DEV_EVENT(DBF_ERR, basedev,
3065 "device not ready for request %p", req);
3071 * if device is stopped do not fetch new requests
3072 * except failfast is active which will let requests fail
3073 * immediately in __dasd_block_start_head()
3075 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST)) {
3076 DBF_DEV_EVENT(DBF_ERR, basedev,
3077 "device stopped request %p", req);
3078 rc = BLK_STS_RESOURCE;
3082 if (basedev->features & DASD_FEATURE_READONLY &&
3083 rq_data_dir(req) == WRITE) {
3084 DBF_DEV_EVENT(DBF_ERR, basedev,
3085 "Rejecting write request %p", req);
3090 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
3091 (basedev->features & DASD_FEATURE_FAILFAST ||
3092 blk_noretry_request(req))) {
3093 DBF_DEV_EVENT(DBF_ERR, basedev,
3094 "Rejecting failfast request %p", req);
3099 cqr = basedev->discipline->build_cp(basedev, block, req);
3101 if (PTR_ERR(cqr) == -EBUSY ||
3102 PTR_ERR(cqr) == -ENOMEM ||
3103 PTR_ERR(cqr) == -EAGAIN) {
3104 rc = BLK_STS_RESOURCE;
3107 DBF_DEV_EVENT(DBF_ERR, basedev,
3108 "CCW creation failed (rc=%ld) on request %p",
3114 * Note: callback is set to dasd_return_cqr_cb in
3115 * __dasd_block_start_head to cover erp requests as well
3117 cqr->callback_data = req;
3118 cqr->status = DASD_CQR_FILLED;
3121 blk_mq_start_request(req);
3122 spin_lock(&block->queue_lock);
3123 list_add_tail(&cqr->blocklist, &block->ccw_queue);
3124 INIT_LIST_HEAD(&cqr->devlist);
3125 dasd_profile_start(block, cqr, req);
3126 dasd_schedule_block_bh(block);
3127 spin_unlock(&block->queue_lock);
3130 spin_unlock_irq(&dq->lock);
3135 * Block timeout callback, called from the block layer
3138 * BLK_EH_RESET_TIMER if the request should be left running
3139 * BLK_EH_DONE if the request is handled or terminated
3142 enum blk_eh_timer_return dasd_times_out(struct request *req)
3144 struct dasd_block *block = req->q->queuedata;
3145 struct dasd_device *device;
3146 struct dasd_ccw_req *cqr;
3147 unsigned long flags;
3150 cqr = blk_mq_rq_to_pdu(req);
3154 spin_lock_irqsave(&cqr->dq->lock, flags);
3155 device = cqr->startdev ? cqr->startdev : block->base;
3156 if (!device->blk_timeout) {
3157 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3158 return BLK_EH_RESET_TIMER;
3160 DBF_DEV_EVENT(DBF_WARNING, device,
3161 " dasd_times_out cqr %p status %x",
3164 spin_lock(&block->queue_lock);
3165 spin_lock(get_ccwdev_lock(device->cdev));
3167 cqr->intrc = -ETIMEDOUT;
3168 if (cqr->status >= DASD_CQR_QUEUED) {
3169 rc = __dasd_cancel_req(cqr);
3170 } else if (cqr->status == DASD_CQR_FILLED ||
3171 cqr->status == DASD_CQR_NEED_ERP) {
3172 cqr->status = DASD_CQR_TERMINATED;
3173 } else if (cqr->status == DASD_CQR_IN_ERP) {
3174 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3176 list_for_each_entry_safe(searchcqr, nextcqr,
3177 &block->ccw_queue, blocklist) {
3179 while (tmpcqr->refers)
3180 tmpcqr = tmpcqr->refers;
3183 /* searchcqr is an ERP request for cqr */
3184 searchcqr->retries = -1;
3185 searchcqr->intrc = -ETIMEDOUT;
3186 if (searchcqr->status >= DASD_CQR_QUEUED) {
3187 rc = __dasd_cancel_req(searchcqr);
3188 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3189 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3190 searchcqr->status = DASD_CQR_TERMINATED;
3192 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3194 * Shouldn't happen; most recent ERP
3195 * request is at the front of queue
3202 spin_unlock(get_ccwdev_lock(device->cdev));
3203 dasd_schedule_block_bh(block);
3204 spin_unlock(&block->queue_lock);
3205 spin_unlock_irqrestore(&cqr->dq->lock, flags);
3207 return rc ? BLK_EH_RESET_TIMER : BLK_EH_DONE;
3210 static int dasd_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
3213 struct dasd_queue *dq = kzalloc(sizeof(*dq), GFP_KERNEL);
3218 spin_lock_init(&dq->lock);
3219 hctx->driver_data = dq;
3224 static void dasd_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int idx)
3226 kfree(hctx->driver_data);
3227 hctx->driver_data = NULL;
3230 static void dasd_request_done(struct request *req)
3232 blk_mq_end_request(req, 0);
3233 blk_mq_run_hw_queues(req->q, true);
3236 struct blk_mq_ops dasd_mq_ops = {
3237 .queue_rq = do_dasd_request,
3238 .complete = dasd_request_done,
3239 .timeout = dasd_times_out,
3240 .init_hctx = dasd_init_hctx,
3241 .exit_hctx = dasd_exit_hctx,
3244 static int dasd_open(struct gendisk *disk, blk_mode_t mode)
3246 struct dasd_device *base;
3249 base = dasd_device_from_gendisk(disk);
3253 atomic_inc(&base->block->open_count);
3254 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
3259 if (!try_module_get(base->discipline->owner)) {
3264 if (dasd_probeonly) {
3265 dev_info(&base->cdev->dev,
3266 "Accessing the DASD failed because it is in "
3267 "probeonly mode\n");
3272 if (base->state <= DASD_STATE_BASIC) {
3273 DBF_DEV_EVENT(DBF_ERR, base, " %s",
3274 " Cannot open unrecognized device");
3278 if ((mode & BLK_OPEN_WRITE) &&
3279 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3280 (base->features & DASD_FEATURE_READONLY))) {
3284 dasd_put_device(base);
3288 module_put(base->discipline->owner);
3290 atomic_dec(&base->block->open_count);
3291 dasd_put_device(base);
3295 static void dasd_release(struct gendisk *disk)
3297 struct dasd_device *base = dasd_device_from_gendisk(disk);
3299 atomic_dec(&base->block->open_count);
3300 module_put(base->discipline->owner);
3301 dasd_put_device(base);
3306 * Return disk geometry.
3308 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3310 struct dasd_device *base;
3312 base = dasd_device_from_gendisk(bdev->bd_disk);
3316 if (!base->discipline ||
3317 !base->discipline->fill_geometry) {
3318 dasd_put_device(base);
3321 base->discipline->fill_geometry(base->block, geo);
3322 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3323 dasd_put_device(base);
3327 const struct block_device_operations
3328 dasd_device_operations = {
3329 .owner = THIS_MODULE,
3331 .release = dasd_release,
3332 .ioctl = dasd_ioctl,
3333 .compat_ioctl = dasd_ioctl,
3334 .getgeo = dasd_getgeo,
3335 .set_read_only = dasd_set_read_only,
3338 /*******************************************************************************
3339 * end of block device operations
3345 #ifdef CONFIG_PROC_FS
3349 kmem_cache_destroy(dasd_page_cache);
3350 dasd_page_cache = NULL;
3351 dasd_gendisk_exit();
3353 if (dasd_debug_area != NULL) {
3354 debug_unregister(dasd_debug_area);
3355 dasd_debug_area = NULL;
3357 dasd_statistics_removeroot();
3361 * SECTION: common functions for ccw_driver use
3365 * Is the device read-only?
3366 * Note that this function does not report the setting of the
3367 * readonly device attribute, but how it is configured in z/VM.
3369 int dasd_device_is_ro(struct dasd_device *device)
3371 struct ccw_dev_id dev_id;
3372 struct diag210 diag_data;
3377 ccw_device_get_id(device->cdev, &dev_id);
3378 memset(&diag_data, 0, sizeof(diag_data));
3379 diag_data.vrdcdvno = dev_id.devno;
3380 diag_data.vrdclen = sizeof(diag_data);
3381 rc = diag210(&diag_data);
3382 if (rc == 0 || rc == 2) {
3383 return diag_data.vrdcvfla & 0x80;
3385 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3390 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3392 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3394 struct ccw_device *cdev = data;
3397 ret = ccw_device_set_online(cdev);
3399 dev_warn(&cdev->dev, "Setting the DASD online failed with rc=%d\n", ret);
3403 * Initial attempt at a probe function. this can be simplified once
3404 * the other detection code is gone.
3406 int dasd_generic_probe(struct ccw_device *cdev)
3408 cdev->handler = &dasd_int_handler;
3411 * Automatically online either all dasd devices (dasd_autodetect)
3412 * or all devices specified with dasd= parameters during
3415 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
3416 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
3417 async_schedule(dasd_generic_auto_online, cdev);
3420 EXPORT_SYMBOL_GPL(dasd_generic_probe);
3422 void dasd_generic_free_discipline(struct dasd_device *device)
3424 /* Forget the discipline information. */
3425 if (device->discipline) {
3426 if (device->discipline->uncheck_device)
3427 device->discipline->uncheck_device(device);
3428 module_put(device->discipline->owner);
3429 device->discipline = NULL;
3431 if (device->base_discipline) {
3432 module_put(device->base_discipline->owner);
3433 device->base_discipline = NULL;
3436 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3439 * This will one day be called from a global not_oper handler.
3440 * It is also used by driver_unregister during module unload.
3442 void dasd_generic_remove(struct ccw_device *cdev)
3444 struct dasd_device *device;
3445 struct dasd_block *block;
3447 device = dasd_device_from_cdev(cdev);
3451 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3452 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3453 /* Already doing offline processing */
3454 dasd_put_device(device);
3458 * This device is removed unconditionally. Set offline
3459 * flag to prevent dasd_open from opening it while it is
3460 * no quite down yet.
3462 dasd_set_target_state(device, DASD_STATE_NEW);
3463 cdev->handler = NULL;
3464 /* dasd_delete_device destroys the device reference. */
3465 block = device->block;
3466 dasd_delete_device(device);
3468 * life cycle of block is bound to device, so delete it after
3469 * device was safely removed
3472 dasd_free_block(block);
3474 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3477 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3478 * the device is detected for the first time and is supposed to be used
3479 * or the user has started activation through sysfs.
3481 int dasd_generic_set_online(struct ccw_device *cdev,
3482 struct dasd_discipline *base_discipline)
3484 struct dasd_discipline *discipline;
3485 struct dasd_device *device;
3491 /* first online clears initial online feature flag */
3492 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3493 device = dasd_create_device(cdev);
3495 return PTR_ERR(device);
3497 discipline = base_discipline;
3498 if (device->features & DASD_FEATURE_USEDIAG) {
3499 if (!dasd_diag_discipline_pointer) {
3500 /* Try to load the required module. */
3501 rc = request_module(DASD_DIAG_MOD);
3503 dev_warn(dev, "Setting the DASD online failed "
3504 "because the required module %s "
3505 "could not be loaded (rc=%d)\n",
3507 dasd_delete_device(device);
3511 /* Module init could have failed, so check again here after
3512 * request_module(). */
3513 if (!dasd_diag_discipline_pointer) {
3514 dev_warn(dev, "Setting the DASD online failed because of missing DIAG discipline\n");
3515 dasd_delete_device(device);
3518 discipline = dasd_diag_discipline_pointer;
3520 if (!try_module_get(base_discipline->owner)) {
3521 dasd_delete_device(device);
3524 device->base_discipline = base_discipline;
3525 if (!try_module_get(discipline->owner)) {
3526 dasd_delete_device(device);
3529 device->discipline = discipline;
3531 /* check_device will allocate block device if necessary */
3532 rc = discipline->check_device(device);
3534 dev_warn(dev, "Setting the DASD online with discipline %s failed with rc=%i\n",
3535 discipline->name, rc);
3536 dasd_delete_device(device);
3540 dasd_set_target_state(device, DASD_STATE_ONLINE);
3541 if (device->state <= DASD_STATE_KNOWN) {
3542 dev_warn(dev, "Setting the DASD online failed because of a missing discipline\n");
3544 dasd_set_target_state(device, DASD_STATE_NEW);
3546 dasd_free_block(device->block);
3547 dasd_delete_device(device);
3549 dev_dbg(dev, "dasd_generic device found\n");
3552 wait_event(dasd_init_waitq, _wait_for_device(device));
3554 dasd_put_device(device);
3557 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3559 int dasd_generic_set_offline(struct ccw_device *cdev)
3561 int max_count, open_count, rc;
3562 struct dasd_device *device;
3563 struct dasd_block *block;
3564 unsigned long flags;
3570 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3571 device = dasd_device_from_cdev_locked(cdev);
3572 if (IS_ERR(device)) {
3573 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3574 return PTR_ERR(device);
3578 * We must make sure that this device is currently not in use.
3579 * The open_count is increased for every opener, that includes
3580 * the blkdev_get in dasd_scan_partitions. We are only interested
3581 * in the other openers.
3583 if (device->block) {
3584 max_count = device->block->bdev_file ? 0 : -1;
3585 open_count = atomic_read(&device->block->open_count);
3586 if (open_count > max_count) {
3588 dev_warn(dev, "The DASD cannot be set offline with open count %i\n",
3591 dev_warn(dev, "The DASD cannot be set offline while it is in use\n");
3598 * Test if the offline processing is already running and exit if so.
3599 * If a safe offline is being processed this could only be a normal
3600 * offline that should be able to overtake the safe offline and
3601 * cancel any I/O we do not want to wait for any longer
3603 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3604 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3605 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3612 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3615 * if safe_offline is called set safe_offline_running flag and
3616 * clear safe_offline so that a call to normal offline
3617 * can overrun safe_offline processing
3619 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3620 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3621 /* need to unlock here to wait for outstanding I/O */
3622 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3624 * If we want to set the device safe offline all IO operations
3625 * should be finished before continuing the offline process
3626 * so sync bdev first and then wait for our queues to become
3629 if (device->block && device->block->bdev_file)
3630 bdev_mark_dead(file_bdev(device->block->bdev_file), false);
3631 dasd_schedule_device_bh(device);
3632 rc = wait_event_interruptible(shutdown_waitq,
3633 _wait_for_empty_queues(device));
3638 * check if a normal offline process overtook the offline
3639 * processing in this case simply do nothing beside returning
3640 * that we got interrupted
3641 * otherwise mark safe offline as not running any longer and
3642 * continue with normal offline
3644 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3645 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3649 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3651 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3653 dasd_set_target_state(device, DASD_STATE_NEW);
3654 /* dasd_delete_device destroys the device reference. */
3655 block = device->block;
3656 dasd_delete_device(device);
3658 * life cycle of block is bound to device, so delete it after
3659 * device was safely removed
3662 dasd_free_block(block);
3667 /* interrupted by signal */
3668 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3669 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3670 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3672 dasd_put_device(device);
3673 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3676 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3678 int dasd_generic_last_path_gone(struct dasd_device *device)
3680 struct dasd_ccw_req *cqr;
3682 dev_warn(&device->cdev->dev, "No operational channel path is left "
3683 "for the device\n");
3684 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3685 /* First call extended error reporting and check for autoquiesce. */
3686 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOPATH);
3688 if (device->state < DASD_STATE_BASIC)
3690 /* Device is active. We want to keep it. */
3691 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3692 if ((cqr->status == DASD_CQR_IN_IO) ||
3693 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3694 cqr->status = DASD_CQR_QUEUED;
3697 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3698 dasd_device_clear_timer(device);
3699 dasd_schedule_device_bh(device);
3702 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3704 int dasd_generic_path_operational(struct dasd_device *device)
3706 dev_info(&device->cdev->dev, "A channel path to the device has become "
3708 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3709 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3710 dasd_schedule_device_bh(device);
3711 if (device->block) {
3712 dasd_schedule_block_bh(device->block);
3713 if (device->block->gdp)
3714 blk_mq_run_hw_queues(device->block->gdp->queue, true);
3717 if (!device->stopped)
3718 wake_up(&generic_waitq);
3722 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3724 int dasd_generic_notify(struct ccw_device *cdev, int event)
3726 struct dasd_device *device;
3729 device = dasd_device_from_cdev_locked(cdev);
3737 dasd_path_no_path(device);
3738 ret = dasd_generic_last_path_gone(device);
3742 if (dasd_path_get_opm(device))
3743 ret = dasd_generic_path_operational(device);
3746 dasd_put_device(device);
3749 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3751 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3753 struct dasd_device *device;
3754 int chp, oldopm, hpfpm, ifccpm;
3756 device = dasd_device_from_cdev_locked(cdev);
3760 oldopm = dasd_path_get_opm(device);
3761 for (chp = 0; chp < 8; chp++) {
3762 if (path_event[chp] & PE_PATH_GONE) {
3763 dasd_path_notoper(device, chp);
3765 if (path_event[chp] & PE_PATH_AVAILABLE) {
3766 dasd_path_available(device, chp);
3767 dasd_schedule_device_bh(device);
3769 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3770 if (!dasd_path_is_operational(device, chp) &&
3771 !dasd_path_need_verify(device, chp)) {
3773 * we can not establish a pathgroup on an
3774 * unavailable path, so trigger a path
3775 * verification first
3777 dasd_path_available(device, chp);
3778 dasd_schedule_device_bh(device);
3780 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3781 "Pathgroup re-established\n");
3782 if (device->discipline->kick_validate)
3783 device->discipline->kick_validate(device);
3785 if (path_event[chp] & PE_PATH_FCES_EVENT) {
3786 dasd_path_fcsec_update(device, chp);
3787 dasd_schedule_device_bh(device);
3790 hpfpm = dasd_path_get_hpfpm(device);
3791 ifccpm = dasd_path_get_ifccpm(device);
3792 if (!dasd_path_get_opm(device) && hpfpm) {
3794 * device has no operational paths but at least one path is
3795 * disabled due to HPF errors
3796 * disable HPF at all and use the path(s) again
3798 if (device->discipline->disable_hpf)
3799 device->discipline->disable_hpf(device);
3800 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3801 dasd_path_set_tbvpm(device, hpfpm);
3802 dasd_schedule_device_bh(device);
3803 dasd_schedule_requeue(device);
3804 } else if (!dasd_path_get_opm(device) && ifccpm) {
3806 * device has no operational paths but at least one path is
3807 * disabled due to IFCC errors
3808 * trigger path verification on paths with IFCC errors
3810 dasd_path_set_tbvpm(device, ifccpm);
3811 dasd_schedule_device_bh(device);
3813 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3814 dev_warn(&device->cdev->dev,
3815 "No verified channel paths remain for the device\n");
3816 DBF_DEV_EVENT(DBF_WARNING, device,
3817 "%s", "last verified path gone");
3818 /* First call extended error reporting and check for autoquiesce. */
3819 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOPATH);
3820 dasd_device_set_stop_bits(device,
3821 DASD_STOPPED_DC_WAIT);
3823 dasd_put_device(device);
3825 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3827 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3829 if (!dasd_path_get_opm(device) && lpm) {
3830 dasd_path_set_opm(device, lpm);
3831 dasd_generic_path_operational(device);
3833 dasd_path_add_opm(device, lpm);
3836 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3838 void dasd_generic_space_exhaust(struct dasd_device *device,
3839 struct dasd_ccw_req *cqr)
3841 /* First call extended error reporting and check for autoquiesce. */
3842 dasd_handle_autoquiesce(device, NULL, DASD_EER_NOSPC);
3844 if (device->state < DASD_STATE_BASIC)
3847 if (cqr->status == DASD_CQR_IN_IO ||
3848 cqr->status == DASD_CQR_CLEAR_PENDING) {
3849 cqr->status = DASD_CQR_QUEUED;
3852 dasd_device_set_stop_bits(device, DASD_STOPPED_NOSPC);
3853 dasd_device_clear_timer(device);
3854 dasd_schedule_device_bh(device);
3856 EXPORT_SYMBOL_GPL(dasd_generic_space_exhaust);
3858 void dasd_generic_space_avail(struct dasd_device *device)
3860 dev_info(&device->cdev->dev, "Extent pool space is available\n");
3861 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "space available");
3863 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOSPC);
3864 dasd_schedule_device_bh(device);
3866 if (device->block) {
3867 dasd_schedule_block_bh(device->block);
3868 if (device->block->gdp)
3869 blk_mq_run_hw_queues(device->block->gdp->queue, true);
3871 if (!device->stopped)
3872 wake_up(&generic_waitq);
3874 EXPORT_SYMBOL_GPL(dasd_generic_space_avail);
3877 * clear active requests and requeue them to block layer if possible
3879 int dasd_generic_requeue_all_requests(struct dasd_device *device)
3881 struct dasd_block *block = device->block;
3882 struct list_head requeue_queue;
3883 struct dasd_ccw_req *cqr, *n;
3889 INIT_LIST_HEAD(&requeue_queue);
3890 rc = _dasd_requests_to_flushqueue(block, &requeue_queue);
3892 /* Now call the callback function of flushed requests */
3894 list_for_each_entry_safe(cqr, n, &requeue_queue, blocklist) {
3895 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
3896 /* Process finished ERP request. */
3898 spin_lock_bh(&block->queue_lock);
3899 __dasd_process_erp(block->base, cqr);
3900 spin_unlock_bh(&block->queue_lock);
3901 /* restart list_for_xx loop since dasd_process_erp
3902 * might remove multiple elements
3906 _dasd_requeue_request(cqr);
3907 list_del_init(&cqr->blocklist);
3908 cqr->block->base->discipline->free_cp(
3909 cqr, (struct request *) cqr->callback_data);
3911 dasd_schedule_device_bh(device);
3914 EXPORT_SYMBOL_GPL(dasd_generic_requeue_all_requests);
3916 static void do_requeue_requests(struct work_struct *work)
3918 struct dasd_device *device = container_of(work, struct dasd_device,
3920 dasd_generic_requeue_all_requests(device);
3921 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3923 dasd_schedule_block_bh(device->block);
3924 dasd_put_device(device);
3927 void dasd_schedule_requeue(struct dasd_device *device)
3929 dasd_get_device(device);
3930 /* queue call to dasd_reload_device to the kernel event daemon. */
3931 if (!schedule_work(&device->requeue_requests))
3932 dasd_put_device(device);
3934 EXPORT_SYMBOL(dasd_schedule_requeue);
3936 static int dasd_handle_autoquiesce(struct dasd_device *device,
3937 struct dasd_ccw_req *cqr,
3938 unsigned int reason)
3940 /* in any case write eer message with reason */
3941 if (dasd_eer_enabled(device))
3942 dasd_eer_write(device, cqr, reason);
3944 if (!test_bit(reason, &device->aq_mask))
3947 /* notify eer about autoquiesce */
3948 if (dasd_eer_enabled(device))
3949 dasd_eer_write(device, NULL, DASD_EER_AUTOQUIESCE);
3951 dev_info(&device->cdev->dev,
3952 "The DASD has been put in the quiesce state\n");
3953 dasd_device_set_stop_bits(device, DASD_STOPPED_QUIESCE);
3955 if (device->features & DASD_FEATURE_REQUEUEQUIESCE)
3956 dasd_schedule_requeue(device);
3961 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
3962 int rdc_buffer_size,
3965 struct dasd_ccw_req *cqr;
3968 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device,
3972 DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
3973 "Could not allocate RDC request");
3978 ccw->cmd_code = CCW_CMD_RDC;
3979 ccw->cda = virt_to_dma32(cqr->data);
3981 ccw->count = rdc_buffer_size;
3982 cqr->startdev = device;
3983 cqr->memdev = device;
3984 cqr->expires = 10*HZ;
3986 cqr->buildclk = get_tod_clock();
3987 cqr->status = DASD_CQR_FILLED;
3992 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
3993 void *rdc_buffer, int rdc_buffer_size)
3996 struct dasd_ccw_req *cqr;
3998 cqr = dasd_generic_build_rdc(device, rdc_buffer_size, magic);
4000 return PTR_ERR(cqr);
4002 ret = dasd_sleep_on(cqr);
4004 memcpy(rdc_buffer, cqr->data, rdc_buffer_size);
4005 dasd_sfree_request(cqr, cqr->memdev);
4008 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
4011 * In command mode and transport mode we need to look for sense
4012 * data in different places. The sense data itself is allways
4013 * an array of 32 bytes, so we can unify the sense data access
4016 char *dasd_get_sense(struct irb *irb)
4018 struct tsb *tsb = NULL;
4021 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4022 if (irb->scsw.tm.tcw)
4023 tsb = tcw_get_tsb(dma32_to_virt(irb->scsw.tm.tcw));
4024 if (tsb && tsb->length == 64 && tsb->flags)
4025 switch (tsb->flags & 0x07) {
4026 case 1: /* tsa_iostat */
4027 sense = tsb->tsa.iostat.sense;
4029 case 2: /* tsa_ddpc */
4030 sense = tsb->tsa.ddpc.sense;
4033 /* currently we don't use interrogate data */
4036 } else if (irb->esw.esw0.erw.cons) {
4041 EXPORT_SYMBOL_GPL(dasd_get_sense);
4043 void dasd_generic_shutdown(struct ccw_device *cdev)
4045 struct dasd_device *device;
4047 device = dasd_device_from_cdev(cdev);
4052 dasd_schedule_block_bh(device->block);
4054 dasd_schedule_device_bh(device);
4056 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4058 EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4060 static int __init dasd_init(void)
4064 init_waitqueue_head(&dasd_init_waitq);
4065 init_waitqueue_head(&dasd_flush_wq);
4066 init_waitqueue_head(&generic_waitq);
4067 init_waitqueue_head(&shutdown_waitq);
4069 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4070 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
4071 if (dasd_debug_area == NULL) {
4075 debug_register_view(dasd_debug_area, &debug_sprintf_view);
4076 debug_set_level(dasd_debug_area, DBF_WARNING);
4078 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4080 dasd_diag_discipline_pointer = NULL;
4082 dasd_statistics_createroot();
4084 rc = dasd_devmap_init();
4087 rc = dasd_gendisk_init();
4093 rc = dasd_eer_init();
4096 #ifdef CONFIG_PROC_FS
4097 rc = dasd_proc_init();
4104 pr_info("The DASD device driver could not be initialized\n");
4109 module_init(dasd_init);
4110 module_exit(dasd_exit);