2 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * Copyright IBM Corp. 1999, 2009
10 #define KMSG_COMPONENT "dasd"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/kmod.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <linux/ctype.h>
17 #include <linux/major.h>
18 #include <linux/slab.h>
19 #include <linux/hdreg.h>
20 #include <linux/async.h>
21 #include <linux/mutex.h>
22 #include <linux/debugfs.h>
23 #include <linux/seq_file.h>
24 #include <linux/vmalloc.h>
26 #include <asm/ccwdev.h>
27 #include <asm/ebcdic.h>
28 #include <asm/idals.h>
33 #define PRINTK_HEADER "dasd:"
37 * SECTION: Constant definitions to be used within this file
39 #define DASD_CHANQ_MAX_SIZE 4
41 #define DASD_DIAG_MOD "dasd_diag_mod"
44 * SECTION: exported variables of dasd.c
46 debug_info_t *dasd_debug_area;
47 EXPORT_SYMBOL(dasd_debug_area);
48 static struct dentry *dasd_debugfs_root_entry;
49 struct dasd_discipline *dasd_diag_discipline_pointer;
50 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
51 void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
53 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
54 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
55 " Copyright IBM Corp. 2000");
56 MODULE_SUPPORTED_DEVICE("dasd");
57 MODULE_LICENSE("GPL");
60 * SECTION: prototypes for static functions of dasd.c
62 static int dasd_alloc_queue(struct dasd_block *);
63 static void dasd_setup_queue(struct dasd_block *);
64 static void dasd_free_queue(struct dasd_block *);
65 static void dasd_flush_request_queue(struct dasd_block *);
66 static int dasd_flush_block_queue(struct dasd_block *);
67 static void dasd_device_tasklet(struct dasd_device *);
68 static void dasd_block_tasklet(struct dasd_block *);
69 static void do_kick_device(struct work_struct *);
70 static void do_restore_device(struct work_struct *);
71 static void do_reload_device(struct work_struct *);
72 static void do_requeue_requests(struct work_struct *);
73 static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
74 static void dasd_device_timeout(unsigned long);
75 static void dasd_block_timeout(unsigned long);
76 static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
77 static void dasd_profile_init(struct dasd_profile *, struct dentry *);
78 static void dasd_profile_exit(struct dasd_profile *);
79 static void dasd_hosts_init(struct dentry *, struct dasd_device *);
80 static void dasd_hosts_exit(struct dasd_device *);
83 * SECTION: Operations on the device structure.
85 static wait_queue_head_t dasd_init_waitq;
86 static wait_queue_head_t dasd_flush_wq;
87 static wait_queue_head_t generic_waitq;
88 static wait_queue_head_t shutdown_waitq;
91 * Allocate memory for a new device structure.
93 struct dasd_device *dasd_alloc_device(void)
95 struct dasd_device *device;
97 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
99 return ERR_PTR(-ENOMEM);
101 /* Get two pages for normal block device operations. */
102 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
103 if (!device->ccw_mem) {
105 return ERR_PTR(-ENOMEM);
107 /* Get one page for error recovery. */
108 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
109 if (!device->erp_mem) {
110 free_pages((unsigned long) device->ccw_mem, 1);
112 return ERR_PTR(-ENOMEM);
115 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
116 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
117 spin_lock_init(&device->mem_lock);
118 atomic_set(&device->tasklet_scheduled, 0);
119 tasklet_init(&device->tasklet,
120 (void (*)(unsigned long)) dasd_device_tasklet,
121 (unsigned long) device);
122 INIT_LIST_HEAD(&device->ccw_queue);
123 init_timer(&device->timer);
124 device->timer.function = dasd_device_timeout;
125 device->timer.data = (unsigned long) device;
126 INIT_WORK(&device->kick_work, do_kick_device);
127 INIT_WORK(&device->restore_device, do_restore_device);
128 INIT_WORK(&device->reload_device, do_reload_device);
129 INIT_WORK(&device->requeue_requests, do_requeue_requests);
130 device->state = DASD_STATE_NEW;
131 device->target = DASD_STATE_NEW;
132 mutex_init(&device->state_mutex);
133 spin_lock_init(&device->profile.lock);
138 * Free memory of a device structure.
140 void dasd_free_device(struct dasd_device *device)
142 kfree(device->private);
143 free_page((unsigned long) device->erp_mem);
144 free_pages((unsigned long) device->ccw_mem, 1);
149 * Allocate memory for a new device structure.
151 struct dasd_block *dasd_alloc_block(void)
153 struct dasd_block *block;
155 block = kzalloc(sizeof(*block), GFP_ATOMIC);
157 return ERR_PTR(-ENOMEM);
158 /* open_count = 0 means device online but not in use */
159 atomic_set(&block->open_count, -1);
161 spin_lock_init(&block->request_queue_lock);
162 atomic_set(&block->tasklet_scheduled, 0);
163 tasklet_init(&block->tasklet,
164 (void (*)(unsigned long)) dasd_block_tasklet,
165 (unsigned long) block);
166 INIT_LIST_HEAD(&block->ccw_queue);
167 spin_lock_init(&block->queue_lock);
168 init_timer(&block->timer);
169 block->timer.function = dasd_block_timeout;
170 block->timer.data = (unsigned long) block;
171 spin_lock_init(&block->profile.lock);
175 EXPORT_SYMBOL_GPL(dasd_alloc_block);
178 * Free memory of a device structure.
180 void dasd_free_block(struct dasd_block *block)
184 EXPORT_SYMBOL_GPL(dasd_free_block);
187 * Make a new device known to the system.
189 static int dasd_state_new_to_known(struct dasd_device *device)
194 * As long as the device is not in state DASD_STATE_NEW we want to
195 * keep the reference count > 0.
197 dasd_get_device(device);
200 rc = dasd_alloc_queue(device->block);
202 dasd_put_device(device);
206 device->state = DASD_STATE_KNOWN;
211 * Let the system forget about a device.
213 static int dasd_state_known_to_new(struct dasd_device *device)
215 /* Disable extended error reporting for this device. */
216 dasd_eer_disable(device);
217 device->state = DASD_STATE_NEW;
220 dasd_free_queue(device->block);
222 /* Give up reference we took in dasd_state_new_to_known. */
223 dasd_put_device(device);
227 static struct dentry *dasd_debugfs_setup(const char *name,
228 struct dentry *base_dentry)
234 pde = debugfs_create_dir(name, base_dentry);
235 if (!pde || IS_ERR(pde))
241 * Request the irq line for the device.
243 static int dasd_state_known_to_basic(struct dasd_device *device)
245 struct dasd_block *block = device->block;
248 /* Allocate and register gendisk structure. */
250 rc = dasd_gendisk_alloc(block);
253 block->debugfs_dentry =
254 dasd_debugfs_setup(block->gdp->disk_name,
255 dasd_debugfs_root_entry);
256 dasd_profile_init(&block->profile, block->debugfs_dentry);
257 if (dasd_global_profile_level == DASD_PROFILE_ON)
258 dasd_profile_on(&device->block->profile);
260 device->debugfs_dentry =
261 dasd_debugfs_setup(dev_name(&device->cdev->dev),
262 dasd_debugfs_root_entry);
263 dasd_profile_init(&device->profile, device->debugfs_dentry);
264 dasd_hosts_init(device->debugfs_dentry, device);
266 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
267 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
269 debug_register_view(device->debug_area, &debug_sprintf_view);
270 debug_set_level(device->debug_area, DBF_WARNING);
271 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
273 device->state = DASD_STATE_BASIC;
279 * Release the irq line for the device. Terminate any running i/o.
281 static int dasd_state_basic_to_known(struct dasd_device *device)
285 if (device->discipline->basic_to_known) {
286 rc = device->discipline->basic_to_known(device);
292 dasd_profile_exit(&device->block->profile);
293 debugfs_remove(device->block->debugfs_dentry);
294 dasd_gendisk_free(device->block);
295 dasd_block_clear_timer(device->block);
297 rc = dasd_flush_device_queue(device);
300 dasd_device_clear_timer(device);
301 dasd_profile_exit(&device->profile);
302 dasd_hosts_exit(device);
303 debugfs_remove(device->debugfs_dentry);
304 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
305 if (device->debug_area != NULL) {
306 debug_unregister(device->debug_area);
307 device->debug_area = NULL;
309 device->state = DASD_STATE_KNOWN;
314 * Do the initial analysis. The do_analysis function may return
315 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
316 * until the discipline decides to continue the startup sequence
317 * by calling the function dasd_change_state. The eckd disciplines
318 * uses this to start a ccw that detects the format. The completion
319 * interrupt for this detection ccw uses the kernel event daemon to
320 * trigger the call to dasd_change_state. All this is done in the
321 * discipline code, see dasd_eckd.c.
322 * After the analysis ccw is done (do_analysis returned 0) the block
324 * In case the analysis returns an error, the device setup is stopped
325 * (a fake disk was already added to allow formatting).
327 static int dasd_state_basic_to_ready(struct dasd_device *device)
330 struct dasd_block *block;
331 struct gendisk *disk;
334 block = device->block;
335 /* make disk known with correct capacity */
337 if (block->base->discipline->do_analysis != NULL)
338 rc = block->base->discipline->do_analysis(block);
341 device->state = DASD_STATE_UNFMT;
342 disk = device->block->gdp;
343 kobject_uevent(&disk_to_dev(disk)->kobj,
349 dasd_setup_queue(block);
350 set_capacity(block->gdp,
351 block->blocks << block->s2b_shift);
352 device->state = DASD_STATE_READY;
353 rc = dasd_scan_partitions(block);
355 device->state = DASD_STATE_BASIC;
359 device->state = DASD_STATE_READY;
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_flush_request_queue(block);
395 dasd_destroy_partitions(block);
398 block->s2b_shift = 0;
406 static int dasd_state_unfmt_to_basic(struct dasd_device *device)
408 device->state = DASD_STATE_BASIC;
413 * Make the device online and schedule the bottom half to start
414 * the requeueing of requests from the linux request queue to the
418 dasd_state_ready_to_online(struct dasd_device * device)
420 struct gendisk *disk;
421 struct disk_part_iter piter;
422 struct hd_struct *part;
424 device->state = DASD_STATE_ONLINE;
426 dasd_schedule_block_bh(device->block);
427 if ((device->features & DASD_FEATURE_USERAW)) {
428 disk = device->block->gdp;
429 kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
432 disk = device->block->bdev->bd_disk;
433 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
434 while ((part = disk_part_iter_next(&piter)))
435 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
436 disk_part_iter_exit(&piter);
442 * Stop the requeueing of requests again.
444 static int dasd_state_online_to_ready(struct dasd_device *device)
447 struct gendisk *disk;
448 struct disk_part_iter piter;
449 struct hd_struct *part;
451 if (device->discipline->online_to_ready) {
452 rc = device->discipline->online_to_ready(device);
457 device->state = DASD_STATE_READY;
458 if (device->block && !(device->features & DASD_FEATURE_USERAW)) {
459 disk = device->block->bdev->bd_disk;
460 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
461 while ((part = disk_part_iter_next(&piter)))
462 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
463 disk_part_iter_exit(&piter);
469 * Device startup state changes.
471 static int dasd_increase_state(struct dasd_device *device)
476 if (device->state == DASD_STATE_NEW &&
477 device->target >= DASD_STATE_KNOWN)
478 rc = dasd_state_new_to_known(device);
481 device->state == DASD_STATE_KNOWN &&
482 device->target >= DASD_STATE_BASIC)
483 rc = dasd_state_known_to_basic(device);
486 device->state == DASD_STATE_BASIC &&
487 device->target >= DASD_STATE_READY)
488 rc = dasd_state_basic_to_ready(device);
491 device->state == DASD_STATE_UNFMT &&
492 device->target > DASD_STATE_UNFMT)
496 device->state == DASD_STATE_READY &&
497 device->target >= DASD_STATE_ONLINE)
498 rc = dasd_state_ready_to_online(device);
504 * Device shutdown state changes.
506 static int dasd_decrease_state(struct dasd_device *device)
511 if (device->state == DASD_STATE_ONLINE &&
512 device->target <= DASD_STATE_READY)
513 rc = dasd_state_online_to_ready(device);
516 device->state == DASD_STATE_READY &&
517 device->target <= DASD_STATE_BASIC)
518 rc = dasd_state_ready_to_basic(device);
521 device->state == DASD_STATE_UNFMT &&
522 device->target <= DASD_STATE_BASIC)
523 rc = dasd_state_unfmt_to_basic(device);
526 device->state == DASD_STATE_BASIC &&
527 device->target <= DASD_STATE_KNOWN)
528 rc = dasd_state_basic_to_known(device);
531 device->state == DASD_STATE_KNOWN &&
532 device->target <= DASD_STATE_NEW)
533 rc = dasd_state_known_to_new(device);
539 * This is the main startup/shutdown routine.
541 static void dasd_change_state(struct dasd_device *device)
545 if (device->state == device->target)
546 /* Already where we want to go today... */
548 if (device->state < device->target)
549 rc = dasd_increase_state(device);
551 rc = dasd_decrease_state(device);
555 device->target = device->state;
557 /* let user-space know that the device status changed */
558 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
560 if (device->state == device->target)
561 wake_up(&dasd_init_waitq);
565 * Kick starter for devices that did not complete the startup/shutdown
566 * procedure or were sleeping because of a pending state.
567 * dasd_kick_device will schedule a call do do_kick_device to the kernel
570 static void do_kick_device(struct work_struct *work)
572 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
573 mutex_lock(&device->state_mutex);
574 dasd_change_state(device);
575 mutex_unlock(&device->state_mutex);
576 dasd_schedule_device_bh(device);
577 dasd_put_device(device);
580 void dasd_kick_device(struct dasd_device *device)
582 dasd_get_device(device);
583 /* queue call to dasd_kick_device to the kernel event daemon. */
584 if (!schedule_work(&device->kick_work))
585 dasd_put_device(device);
587 EXPORT_SYMBOL(dasd_kick_device);
590 * dasd_reload_device will schedule a call do do_reload_device to the kernel
593 static void do_reload_device(struct work_struct *work)
595 struct dasd_device *device = container_of(work, struct dasd_device,
597 device->discipline->reload(device);
598 dasd_put_device(device);
601 void dasd_reload_device(struct dasd_device *device)
603 dasd_get_device(device);
604 /* queue call to dasd_reload_device to the kernel event daemon. */
605 if (!schedule_work(&device->reload_device))
606 dasd_put_device(device);
608 EXPORT_SYMBOL(dasd_reload_device);
611 * dasd_restore_device will schedule a call do do_restore_device to the kernel
614 static void do_restore_device(struct work_struct *work)
616 struct dasd_device *device = container_of(work, struct dasd_device,
618 device->cdev->drv->restore(device->cdev);
619 dasd_put_device(device);
622 void dasd_restore_device(struct dasd_device *device)
624 dasd_get_device(device);
625 /* queue call to dasd_restore_device to the kernel event daemon. */
626 if (!schedule_work(&device->restore_device))
627 dasd_put_device(device);
631 * Set the target state for a device and starts the state change.
633 void dasd_set_target_state(struct dasd_device *device, int target)
635 dasd_get_device(device);
636 mutex_lock(&device->state_mutex);
637 /* If we are in probeonly mode stop at DASD_STATE_READY. */
638 if (dasd_probeonly && target > DASD_STATE_READY)
639 target = DASD_STATE_READY;
640 if (device->target != target) {
641 if (device->state == target)
642 wake_up(&dasd_init_waitq);
643 device->target = target;
645 if (device->state != device->target)
646 dasd_change_state(device);
647 mutex_unlock(&device->state_mutex);
648 dasd_put_device(device);
650 EXPORT_SYMBOL(dasd_set_target_state);
653 * Enable devices with device numbers in [from..to].
655 static inline int _wait_for_device(struct dasd_device *device)
657 return (device->state == device->target);
660 void dasd_enable_device(struct dasd_device *device)
662 dasd_set_target_state(device, DASD_STATE_ONLINE);
663 if (device->state <= DASD_STATE_KNOWN)
664 /* No discipline for device found. */
665 dasd_set_target_state(device, DASD_STATE_NEW);
666 /* Now wait for the devices to come up. */
667 wait_event(dasd_init_waitq, _wait_for_device(device));
669 dasd_reload_device(device);
670 if (device->discipline->kick_validate)
671 device->discipline->kick_validate(device);
673 EXPORT_SYMBOL(dasd_enable_device);
676 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
679 unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
681 #ifdef CONFIG_DASD_PROFILE
682 struct dasd_profile dasd_global_profile = {
683 .lock = __SPIN_LOCK_UNLOCKED(dasd_global_profile.lock),
685 static struct dentry *dasd_debugfs_global_entry;
688 * Add profiling information for cqr before execution.
690 static void dasd_profile_start(struct dasd_block *block,
691 struct dasd_ccw_req *cqr,
695 unsigned int counter;
696 struct dasd_device *device;
698 /* count the length of the chanq for statistics */
700 if (dasd_global_profile_level || block->profile.data)
701 list_for_each(l, &block->ccw_queue)
705 spin_lock(&dasd_global_profile.lock);
706 if (dasd_global_profile.data) {
707 dasd_global_profile.data->dasd_io_nr_req[counter]++;
708 if (rq_data_dir(req) == READ)
709 dasd_global_profile.data->dasd_read_nr_req[counter]++;
711 spin_unlock(&dasd_global_profile.lock);
713 spin_lock(&block->profile.lock);
714 if (block->profile.data) {
715 block->profile.data->dasd_io_nr_req[counter]++;
716 if (rq_data_dir(req) == READ)
717 block->profile.data->dasd_read_nr_req[counter]++;
719 spin_unlock(&block->profile.lock);
722 * We count the request for the start device, even though it may run on
723 * some other device due to error recovery. This way we make sure that
724 * we count each request only once.
726 device = cqr->startdev;
727 if (device->profile.data) {
728 counter = 1; /* request is not yet queued on the start device */
729 list_for_each(l, &device->ccw_queue)
733 spin_lock(&device->profile.lock);
734 if (device->profile.data) {
735 device->profile.data->dasd_io_nr_req[counter]++;
736 if (rq_data_dir(req) == READ)
737 device->profile.data->dasd_read_nr_req[counter]++;
739 spin_unlock(&device->profile.lock);
743 * Add profiling information for cqr after execution.
746 #define dasd_profile_counter(value, index) \
748 for (index = 0; index < 31 && value >> (2+index); index++) \
752 static void dasd_profile_end_add_data(struct dasd_profile_info *data,
765 /* in case of an overflow, reset the whole profile */
766 if (data->dasd_io_reqs == UINT_MAX) {
767 memset(data, 0, sizeof(*data));
768 getnstimeofday(&data->starttod);
770 data->dasd_io_reqs++;
771 data->dasd_io_sects += sectors;
773 data->dasd_io_alias++;
777 data->dasd_io_secs[sectors_ind]++;
778 data->dasd_io_times[tottime_ind]++;
779 data->dasd_io_timps[tottimeps_ind]++;
780 data->dasd_io_time1[strtime_ind]++;
781 data->dasd_io_time2[irqtime_ind]++;
782 data->dasd_io_time2ps[irqtimeps_ind]++;
783 data->dasd_io_time3[endtime_ind]++;
786 data->dasd_read_reqs++;
787 data->dasd_read_sects += sectors;
789 data->dasd_read_alias++;
791 data->dasd_read_tpm++;
792 data->dasd_read_secs[sectors_ind]++;
793 data->dasd_read_times[tottime_ind]++;
794 data->dasd_read_time1[strtime_ind]++;
795 data->dasd_read_time2[irqtime_ind]++;
796 data->dasd_read_time3[endtime_ind]++;
800 static void dasd_profile_end(struct dasd_block *block,
801 struct dasd_ccw_req *cqr,
804 long strtime, irqtime, endtime, tottime; /* in microseconds */
805 long tottimeps, sectors;
806 struct dasd_device *device;
807 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
808 int irqtime_ind, irqtimeps_ind, endtime_ind;
810 device = cqr->startdev;
811 if (!(dasd_global_profile_level ||
812 block->profile.data ||
813 device->profile.data))
816 sectors = blk_rq_sectors(req);
817 if (!cqr->buildclk || !cqr->startclk ||
818 !cqr->stopclk || !cqr->endclk ||
822 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
823 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
824 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
825 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
826 tottimeps = tottime / sectors;
828 dasd_profile_counter(sectors, sectors_ind);
829 dasd_profile_counter(tottime, tottime_ind);
830 dasd_profile_counter(tottimeps, tottimeps_ind);
831 dasd_profile_counter(strtime, strtime_ind);
832 dasd_profile_counter(irqtime, irqtime_ind);
833 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
834 dasd_profile_counter(endtime, endtime_ind);
836 spin_lock(&dasd_global_profile.lock);
837 if (dasd_global_profile.data) {
838 dasd_profile_end_add_data(dasd_global_profile.data,
839 cqr->startdev != block->base,
841 rq_data_dir(req) == READ,
842 sectors, sectors_ind, tottime_ind,
843 tottimeps_ind, strtime_ind,
844 irqtime_ind, irqtimeps_ind,
847 spin_unlock(&dasd_global_profile.lock);
849 spin_lock(&block->profile.lock);
850 if (block->profile.data)
851 dasd_profile_end_add_data(block->profile.data,
852 cqr->startdev != block->base,
854 rq_data_dir(req) == READ,
855 sectors, sectors_ind, tottime_ind,
856 tottimeps_ind, strtime_ind,
857 irqtime_ind, irqtimeps_ind,
859 spin_unlock(&block->profile.lock);
861 spin_lock(&device->profile.lock);
862 if (device->profile.data)
863 dasd_profile_end_add_data(device->profile.data,
864 cqr->startdev != block->base,
866 rq_data_dir(req) == READ,
867 sectors, sectors_ind, tottime_ind,
868 tottimeps_ind, strtime_ind,
869 irqtime_ind, irqtimeps_ind,
871 spin_unlock(&device->profile.lock);
874 void dasd_profile_reset(struct dasd_profile *profile)
876 struct dasd_profile_info *data;
878 spin_lock_bh(&profile->lock);
879 data = profile->data;
881 spin_unlock_bh(&profile->lock);
884 memset(data, 0, sizeof(*data));
885 getnstimeofday(&data->starttod);
886 spin_unlock_bh(&profile->lock);
889 int dasd_profile_on(struct dasd_profile *profile)
891 struct dasd_profile_info *data;
893 data = kzalloc(sizeof(*data), GFP_KERNEL);
896 spin_lock_bh(&profile->lock);
898 spin_unlock_bh(&profile->lock);
902 getnstimeofday(&data->starttod);
903 profile->data = data;
904 spin_unlock_bh(&profile->lock);
908 void dasd_profile_off(struct dasd_profile *profile)
910 spin_lock_bh(&profile->lock);
911 kfree(profile->data);
912 profile->data = NULL;
913 spin_unlock_bh(&profile->lock);
916 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
920 buffer = vmalloc(user_len + 1);
922 return ERR_PTR(-ENOMEM);
923 if (copy_from_user(buffer, user_buf, user_len) != 0) {
925 return ERR_PTR(-EFAULT);
927 /* got the string, now strip linefeed. */
928 if (buffer[user_len - 1] == '\n')
929 buffer[user_len - 1] = 0;
931 buffer[user_len] = 0;
935 static ssize_t dasd_stats_write(struct file *file,
936 const char __user *user_buf,
937 size_t user_len, loff_t *pos)
941 struct seq_file *m = (struct seq_file *)file->private_data;
942 struct dasd_profile *prof = m->private;
944 if (user_len > 65536)
946 buffer = dasd_get_user_string(user_buf, user_len);
948 return PTR_ERR(buffer);
950 str = skip_spaces(buffer);
952 if (strncmp(str, "reset", 5) == 0) {
953 dasd_profile_reset(prof);
954 } else if (strncmp(str, "on", 2) == 0) {
955 rc = dasd_profile_on(prof);
959 if (prof == &dasd_global_profile) {
960 dasd_profile_reset(prof);
961 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
963 } else if (strncmp(str, "off", 3) == 0) {
964 if (prof == &dasd_global_profile)
965 dasd_global_profile_level = DASD_PROFILE_OFF;
966 dasd_profile_off(prof);
974 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
978 for (i = 0; i < 32; i++)
979 seq_printf(m, "%u ", array[i]);
983 static void dasd_stats_seq_print(struct seq_file *m,
984 struct dasd_profile_info *data)
986 seq_printf(m, "start_time %ld.%09ld\n",
987 data->starttod.tv_sec, data->starttod.tv_nsec);
988 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
989 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
990 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
991 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
992 seq_puts(m, "histogram_sectors ");
993 dasd_stats_array(m, data->dasd_io_secs);
994 seq_puts(m, "histogram_io_times ");
995 dasd_stats_array(m, data->dasd_io_times);
996 seq_puts(m, "histogram_io_times_weighted ");
997 dasd_stats_array(m, data->dasd_io_timps);
998 seq_puts(m, "histogram_time_build_to_ssch ");
999 dasd_stats_array(m, data->dasd_io_time1);
1000 seq_puts(m, "histogram_time_ssch_to_irq ");
1001 dasd_stats_array(m, data->dasd_io_time2);
1002 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
1003 dasd_stats_array(m, data->dasd_io_time2ps);
1004 seq_puts(m, "histogram_time_irq_to_end ");
1005 dasd_stats_array(m, data->dasd_io_time3);
1006 seq_puts(m, "histogram_ccw_queue_length ");
1007 dasd_stats_array(m, data->dasd_io_nr_req);
1008 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
1009 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
1010 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
1011 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
1012 seq_puts(m, "histogram_read_sectors ");
1013 dasd_stats_array(m, data->dasd_read_secs);
1014 seq_puts(m, "histogram_read_times ");
1015 dasd_stats_array(m, data->dasd_read_times);
1016 seq_puts(m, "histogram_read_time_build_to_ssch ");
1017 dasd_stats_array(m, data->dasd_read_time1);
1018 seq_puts(m, "histogram_read_time_ssch_to_irq ");
1019 dasd_stats_array(m, data->dasd_read_time2);
1020 seq_puts(m, "histogram_read_time_irq_to_end ");
1021 dasd_stats_array(m, data->dasd_read_time3);
1022 seq_puts(m, "histogram_read_ccw_queue_length ");
1023 dasd_stats_array(m, data->dasd_read_nr_req);
1026 static int dasd_stats_show(struct seq_file *m, void *v)
1028 struct dasd_profile *profile;
1029 struct dasd_profile_info *data;
1031 profile = m->private;
1032 spin_lock_bh(&profile->lock);
1033 data = profile->data;
1035 spin_unlock_bh(&profile->lock);
1036 seq_puts(m, "disabled\n");
1039 dasd_stats_seq_print(m, data);
1040 spin_unlock_bh(&profile->lock);
1044 static int dasd_stats_open(struct inode *inode, struct file *file)
1046 struct dasd_profile *profile = inode->i_private;
1047 return single_open(file, dasd_stats_show, profile);
1050 static const struct file_operations dasd_stats_raw_fops = {
1051 .owner = THIS_MODULE,
1052 .open = dasd_stats_open,
1054 .llseek = seq_lseek,
1055 .release = single_release,
1056 .write = dasd_stats_write,
1059 static void dasd_profile_init(struct dasd_profile *profile,
1060 struct dentry *base_dentry)
1067 profile->dentry = NULL;
1068 profile->data = NULL;
1069 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1070 pde = debugfs_create_file("statistics", mode, base_dentry,
1071 profile, &dasd_stats_raw_fops);
1072 if (pde && !IS_ERR(pde))
1073 profile->dentry = pde;
1077 static void dasd_profile_exit(struct dasd_profile *profile)
1079 dasd_profile_off(profile);
1080 debugfs_remove(profile->dentry);
1081 profile->dentry = NULL;
1084 static void dasd_statistics_removeroot(void)
1086 dasd_global_profile_level = DASD_PROFILE_OFF;
1087 dasd_profile_exit(&dasd_global_profile);
1088 debugfs_remove(dasd_debugfs_global_entry);
1089 debugfs_remove(dasd_debugfs_root_entry);
1092 static void dasd_statistics_createroot(void)
1096 dasd_debugfs_root_entry = NULL;
1097 pde = debugfs_create_dir("dasd", NULL);
1098 if (!pde || IS_ERR(pde))
1100 dasd_debugfs_root_entry = pde;
1101 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1102 if (!pde || IS_ERR(pde))
1104 dasd_debugfs_global_entry = pde;
1105 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
1109 DBF_EVENT(DBF_ERR, "%s",
1110 "Creation of the dasd debugfs interface failed");
1111 dasd_statistics_removeroot();
1116 #define dasd_profile_start(block, cqr, req) do {} while (0)
1117 #define dasd_profile_end(block, cqr, req) do {} while (0)
1119 static void dasd_statistics_createroot(void)
1124 static void dasd_statistics_removeroot(void)
1129 int dasd_stats_generic_show(struct seq_file *m, void *v)
1131 seq_puts(m, "Statistics are not activated in this kernel\n");
1135 static void dasd_profile_init(struct dasd_profile *profile,
1136 struct dentry *base_dentry)
1141 static void dasd_profile_exit(struct dasd_profile *profile)
1146 int dasd_profile_on(struct dasd_profile *profile)
1151 #endif /* CONFIG_DASD_PROFILE */
1153 static int dasd_hosts_show(struct seq_file *m, void *v)
1155 struct dasd_device *device;
1156 int rc = -EOPNOTSUPP;
1158 device = m->private;
1159 dasd_get_device(device);
1161 if (device->discipline->hosts_print)
1162 rc = device->discipline->hosts_print(device, m);
1164 dasd_put_device(device);
1168 static int dasd_hosts_open(struct inode *inode, struct file *file)
1170 struct dasd_device *device = inode->i_private;
1172 return single_open(file, dasd_hosts_show, device);
1175 static const struct file_operations dasd_hosts_fops = {
1176 .owner = THIS_MODULE,
1177 .open = dasd_hosts_open,
1179 .llseek = seq_lseek,
1180 .release = single_release,
1183 static void dasd_hosts_exit(struct dasd_device *device)
1185 debugfs_remove(device->hosts_dentry);
1186 device->hosts_dentry = NULL;
1189 static void dasd_hosts_init(struct dentry *base_dentry,
1190 struct dasd_device *device)
1198 mode = S_IRUSR | S_IFREG;
1199 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1200 device, &dasd_hosts_fops);
1201 if (pde && !IS_ERR(pde))
1202 device->hosts_dentry = pde;
1206 * Allocate memory for a channel program with 'cplength' channel
1207 * command words and 'datasize' additional space. There are two
1208 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1209 * memory and 2) dasd_smalloc_request uses the static ccw memory
1210 * that gets allocated for each device.
1212 struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength,
1214 struct dasd_device *device)
1216 struct dasd_ccw_req *cqr;
1219 BUG_ON(datasize > PAGE_SIZE ||
1220 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
1222 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
1224 return ERR_PTR(-ENOMEM);
1227 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
1228 GFP_ATOMIC | GFP_DMA);
1229 if (cqr->cpaddr == NULL) {
1231 return ERR_PTR(-ENOMEM);
1236 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
1237 if (cqr->data == NULL) {
1240 return ERR_PTR(-ENOMEM);
1244 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1245 dasd_get_device(device);
1248 EXPORT_SYMBOL(dasd_kmalloc_request);
1250 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength,
1252 struct dasd_device *device)
1254 unsigned long flags;
1255 struct dasd_ccw_req *cqr;
1259 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
1261 size += cplength * sizeof(struct ccw1);
1264 spin_lock_irqsave(&device->mem_lock, flags);
1265 cqr = (struct dasd_ccw_req *)
1266 dasd_alloc_chunk(&device->ccw_chunks, size);
1267 spin_unlock_irqrestore(&device->mem_lock, flags);
1269 return ERR_PTR(-ENOMEM);
1270 memset(cqr, 0, sizeof(struct dasd_ccw_req));
1271 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
1274 cqr->cpaddr = (struct ccw1 *) data;
1275 data += cplength*sizeof(struct ccw1);
1276 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
1281 memset(cqr->data, 0, datasize);
1284 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1285 dasd_get_device(device);
1288 EXPORT_SYMBOL(dasd_smalloc_request);
1291 * Free memory of a channel program. This function needs to free all the
1292 * idal lists that might have been created by dasd_set_cda and the
1293 * struct dasd_ccw_req itself.
1295 void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1299 /* Clear any idals used for the request. */
1302 clear_normalized_cda(ccw);
1303 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
1307 dasd_put_device(device);
1309 EXPORT_SYMBOL(dasd_kfree_request);
1311 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1313 unsigned long flags;
1315 spin_lock_irqsave(&device->mem_lock, flags);
1316 dasd_free_chunk(&device->ccw_chunks, cqr);
1317 spin_unlock_irqrestore(&device->mem_lock, flags);
1318 dasd_put_device(device);
1320 EXPORT_SYMBOL(dasd_sfree_request);
1323 * Check discipline magic in cqr.
1325 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1327 struct dasd_device *device;
1331 device = cqr->startdev;
1332 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1333 DBF_DEV_EVENT(DBF_WARNING, device,
1334 " dasd_ccw_req 0x%08x magic doesn't match"
1335 " discipline 0x%08x",
1337 *(unsigned int *) device->discipline->name);
1344 * Terminate the current i/o and set the request to clear_pending.
1345 * Timer keeps device runnig.
1346 * ccw_device_clear can fail if the i/o subsystem
1349 int dasd_term_IO(struct dasd_ccw_req *cqr)
1351 struct dasd_device *device;
1353 char errorstring[ERRORLENGTH];
1356 rc = dasd_check_cqr(cqr);
1360 device = (struct dasd_device *) cqr->startdev;
1361 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1362 rc = ccw_device_clear(device->cdev, (long) cqr);
1364 case 0: /* termination successful */
1365 cqr->status = DASD_CQR_CLEAR_PENDING;
1366 cqr->stopclk = get_tod_clock();
1368 DBF_DEV_EVENT(DBF_DEBUG, device,
1369 "terminate cqr %p successful",
1373 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1374 "device gone, retry");
1377 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1378 "I/O error, retry");
1382 * device not valid so no I/O could be running
1383 * handle CQR as termination successful
1385 cqr->status = DASD_CQR_CLEARED;
1386 cqr->stopclk = get_tod_clock();
1388 /* no retries for invalid devices */
1390 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1391 "EINVAL, handle as terminated");
1392 /* fake rc to success */
1396 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1397 "device busy, retry later");
1400 /* internal error 10 - unknown rc*/
1401 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1402 dev_err(&device->cdev->dev, "An error occurred in the "
1403 "DASD device driver, reason=%s\n", errorstring);
1409 dasd_schedule_device_bh(device);
1412 EXPORT_SYMBOL(dasd_term_IO);
1415 * Start the i/o. This start_IO can fail if the channel is really busy.
1416 * In that case set up a timer to start the request later.
1418 int dasd_start_IO(struct dasd_ccw_req *cqr)
1420 struct dasd_device *device;
1422 char errorstring[ERRORLENGTH];
1425 rc = dasd_check_cqr(cqr);
1430 device = (struct dasd_device *) cqr->startdev;
1432 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1433 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1434 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1435 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1436 "because of stolen lock", cqr);
1437 cqr->status = DASD_CQR_ERROR;
1438 cqr->intrc = -EPERM;
1441 if (cqr->retries < 0) {
1442 /* internal error 14 - start_IO run out of retries */
1443 sprintf(errorstring, "14 %p", cqr);
1444 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1445 "device driver, reason=%s\n", errorstring);
1446 cqr->status = DASD_CQR_ERROR;
1449 cqr->startclk = get_tod_clock();
1450 cqr->starttime = jiffies;
1452 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1453 cqr->lpm &= dasd_path_get_opm(device);
1455 cqr->lpm = dasd_path_get_opm(device);
1457 if (cqr->cpmode == 1) {
1458 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1459 (long) cqr, cqr->lpm);
1461 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1462 (long) cqr, cqr->lpm, 0);
1466 cqr->status = DASD_CQR_IN_IO;
1469 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1470 "start_IO: device busy, retry later");
1473 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1474 "start_IO: request timeout, retry later");
1477 /* -EACCES indicates that the request used only a subset of the
1478 * available paths and all these paths are gone. If the lpm of
1479 * this request was only a subset of the opm (e.g. the ppm) then
1480 * we just do a retry with all available paths.
1481 * If we already use the full opm, something is amiss, and we
1482 * need a full path verification.
1484 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1485 DBF_DEV_EVENT(DBF_WARNING, device,
1486 "start_IO: selected paths gone (%x)",
1488 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1489 cqr->lpm = dasd_path_get_opm(device);
1490 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1491 "start_IO: selected paths gone,"
1492 " retry on all paths");
1494 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1495 "start_IO: all paths in opm gone,"
1496 " do path verification");
1497 dasd_generic_last_path_gone(device);
1498 dasd_path_no_path(device);
1499 dasd_path_set_tbvpm(device,
1500 ccw_device_get_path_mask(
1505 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1506 "start_IO: -ENODEV device gone, retry");
1509 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1510 "start_IO: -EIO device gone, retry");
1513 /* most likely caused in power management context */
1514 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1515 "start_IO: -EINVAL device currently "
1519 /* internal error 11 - unknown rc */
1520 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1521 dev_err(&device->cdev->dev,
1522 "An error occurred in the DASD device driver, "
1523 "reason=%s\n", errorstring);
1530 EXPORT_SYMBOL(dasd_start_IO);
1533 * Timeout function for dasd devices. This is used for different purposes
1534 * 1) missing interrupt handler for normal operation
1535 * 2) delayed start of request where start_IO failed with -EBUSY
1536 * 3) timeout for missing state change interrupts
1537 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1538 * DASD_CQR_QUEUED for 2) and 3).
1540 static void dasd_device_timeout(unsigned long ptr)
1542 unsigned long flags;
1543 struct dasd_device *device;
1545 device = (struct dasd_device *) ptr;
1546 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1547 /* re-activate request queue */
1548 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1549 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1550 dasd_schedule_device_bh(device);
1554 * Setup timeout for a device in jiffies.
1556 void dasd_device_set_timer(struct dasd_device *device, int expires)
1559 del_timer(&device->timer);
1561 mod_timer(&device->timer, jiffies + expires);
1563 EXPORT_SYMBOL(dasd_device_set_timer);
1566 * Clear timeout for a device.
1568 void dasd_device_clear_timer(struct dasd_device *device)
1570 del_timer(&device->timer);
1572 EXPORT_SYMBOL(dasd_device_clear_timer);
1574 static void dasd_handle_killed_request(struct ccw_device *cdev,
1575 unsigned long intparm)
1577 struct dasd_ccw_req *cqr;
1578 struct dasd_device *device;
1582 cqr = (struct dasd_ccw_req *) intparm;
1583 if (cqr->status != DASD_CQR_IN_IO) {
1584 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1585 "invalid status in handle_killed_request: "
1586 "%02x", cqr->status);
1590 device = dasd_device_from_cdev_locked(cdev);
1591 if (IS_ERR(device)) {
1592 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1593 "unable to get device from cdev");
1597 if (!cqr->startdev ||
1598 device != cqr->startdev ||
1599 strncmp(cqr->startdev->discipline->ebcname,
1600 (char *) &cqr->magic, 4)) {
1601 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1602 "invalid device in request");
1603 dasd_put_device(device);
1607 /* Schedule request to be retried. */
1608 cqr->status = DASD_CQR_QUEUED;
1610 dasd_device_clear_timer(device);
1611 dasd_schedule_device_bh(device);
1612 dasd_put_device(device);
1615 void dasd_generic_handle_state_change(struct dasd_device *device)
1617 /* First of all start sense subsystem status request. */
1618 dasd_eer_snss(device);
1620 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1621 dasd_schedule_device_bh(device);
1623 dasd_schedule_block_bh(device->block);
1625 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
1627 static int dasd_check_hpf_error(struct irb *irb)
1629 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1630 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1631 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1635 * Interrupt handler for "normal" ssch-io based dasd devices.
1637 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1640 struct dasd_ccw_req *cqr, *next;
1641 struct dasd_device *device;
1642 unsigned long long now;
1643 int nrf_suppressed = 0;
1644 int fp_suppressed = 0;
1648 cqr = (struct dasd_ccw_req *) intparm;
1650 switch (PTR_ERR(irb)) {
1652 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1653 device = cqr->startdev;
1654 cqr->status = DASD_CQR_CLEARED;
1655 dasd_device_clear_timer(device);
1656 wake_up(&dasd_flush_wq);
1657 dasd_schedule_device_bh(device);
1662 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1663 "request timed out\n", __func__);
1666 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1667 "unknown error %ld\n", __func__,
1670 dasd_handle_killed_request(cdev, intparm);
1674 now = get_tod_clock();
1675 /* check for conditions that should be handled immediately */
1677 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1678 scsw_cstat(&irb->scsw) == 0)) {
1680 memcpy(&cqr->irb, irb, sizeof(*irb));
1681 device = dasd_device_from_cdev_locked(cdev);
1684 /* ignore unsolicited interrupts for DIAG discipline */
1685 if (device->discipline == dasd_diag_discipline_pointer) {
1686 dasd_put_device(device);
1691 * In some cases 'File Protected' or 'No Record Found' errors
1692 * might be expected and debug log messages for the
1693 * corresponding interrupts shouldn't be written then.
1694 * Check if either of the according suppress bits is set.
1696 sense = dasd_get_sense(irb);
1698 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1699 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1700 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1701 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1703 if (!(fp_suppressed || nrf_suppressed))
1704 device->discipline->dump_sense_dbf(device, irb, "int");
1706 if (device->features & DASD_FEATURE_ERPLOG)
1707 device->discipline->dump_sense(device, cqr, irb);
1708 device->discipline->check_for_device_change(device, cqr, irb);
1709 dasd_put_device(device);
1712 /* check for for attention message */
1713 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1714 device = dasd_device_from_cdev_locked(cdev);
1715 if (!IS_ERR(device)) {
1716 device->discipline->check_attention(device,
1717 irb->esw.esw1.lpum);
1718 dasd_put_device(device);
1725 device = (struct dasd_device *) cqr->startdev;
1727 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1728 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1729 "invalid device in request");
1733 /* Check for clear pending */
1734 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1735 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1736 cqr->status = DASD_CQR_CLEARED;
1737 dasd_device_clear_timer(device);
1738 wake_up(&dasd_flush_wq);
1739 dasd_schedule_device_bh(device);
1743 /* check status - the request might have been killed by dyn detach */
1744 if (cqr->status != DASD_CQR_IN_IO) {
1745 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1746 "status %02x", dev_name(&cdev->dev), cqr->status);
1752 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1753 scsw_cstat(&irb->scsw) == 0) {
1754 /* request was completed successfully */
1755 cqr->status = DASD_CQR_SUCCESS;
1757 /* Start first request on queue if possible -> fast_io. */
1758 if (cqr->devlist.next != &device->ccw_queue) {
1759 next = list_entry(cqr->devlist.next,
1760 struct dasd_ccw_req, devlist);
1762 } else { /* error */
1763 /* check for HPF error
1764 * call discipline function to requeue all requests
1765 * and disable HPF accordingly
1767 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1768 device->discipline->handle_hpf_error)
1769 device->discipline->handle_hpf_error(device, irb);
1771 * If we don't want complex ERP for this request, then just
1772 * reset this and retry it in the fastpath
1774 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1776 if (cqr->lpm == dasd_path_get_opm(device))
1777 DBF_DEV_EVENT(DBF_DEBUG, device,
1778 "default ERP in fastpath "
1779 "(%i retries left)",
1781 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1782 cqr->lpm = dasd_path_get_opm(device);
1783 cqr->status = DASD_CQR_QUEUED;
1786 cqr->status = DASD_CQR_ERROR;
1788 if (next && (next->status == DASD_CQR_QUEUED) &&
1789 (!device->stopped)) {
1790 if (device->discipline->start_IO(next) == 0)
1791 expires = next->expires;
1794 dasd_device_set_timer(device, expires);
1796 dasd_device_clear_timer(device);
1797 dasd_schedule_device_bh(device);
1799 EXPORT_SYMBOL(dasd_int_handler);
1801 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1803 struct dasd_device *device;
1805 device = dasd_device_from_cdev_locked(cdev);
1809 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1810 device->state != device->target ||
1811 !device->discipline->check_for_device_change){
1812 dasd_put_device(device);
1815 if (device->discipline->dump_sense_dbf)
1816 device->discipline->dump_sense_dbf(device, irb, "uc");
1817 device->discipline->check_for_device_change(device, NULL, irb);
1818 dasd_put_device(device);
1820 return UC_TODO_RETRY;
1822 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1825 * If we have an error on a dasd_block layer request then we cancel
1826 * and return all further requests from the same dasd_block as well.
1828 static void __dasd_device_recovery(struct dasd_device *device,
1829 struct dasd_ccw_req *ref_cqr)
1831 struct list_head *l, *n;
1832 struct dasd_ccw_req *cqr;
1835 * only requeue request that came from the dasd_block layer
1837 if (!ref_cqr->block)
1840 list_for_each_safe(l, n, &device->ccw_queue) {
1841 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1842 if (cqr->status == DASD_CQR_QUEUED &&
1843 ref_cqr->block == cqr->block) {
1844 cqr->status = DASD_CQR_CLEARED;
1850 * Remove those ccw requests from the queue that need to be returned
1851 * to the upper layer.
1853 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1854 struct list_head *final_queue)
1856 struct list_head *l, *n;
1857 struct dasd_ccw_req *cqr;
1859 /* Process request with final status. */
1860 list_for_each_safe(l, n, &device->ccw_queue) {
1861 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1863 /* Skip any non-final request. */
1864 if (cqr->status == DASD_CQR_QUEUED ||
1865 cqr->status == DASD_CQR_IN_IO ||
1866 cqr->status == DASD_CQR_CLEAR_PENDING)
1868 if (cqr->status == DASD_CQR_ERROR) {
1869 __dasd_device_recovery(device, cqr);
1871 /* Rechain finished requests to final queue */
1872 list_move_tail(&cqr->devlist, final_queue);
1877 * the cqrs from the final queue are returned to the upper layer
1878 * by setting a dasd_block state and calling the callback function
1880 static void __dasd_device_process_final_queue(struct dasd_device *device,
1881 struct list_head *final_queue)
1883 struct list_head *l, *n;
1884 struct dasd_ccw_req *cqr;
1885 struct dasd_block *block;
1886 void (*callback)(struct dasd_ccw_req *, void *data);
1887 void *callback_data;
1888 char errorstring[ERRORLENGTH];
1890 list_for_each_safe(l, n, final_queue) {
1891 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1892 list_del_init(&cqr->devlist);
1894 callback = cqr->callback;
1895 callback_data = cqr->callback_data;
1897 spin_lock_bh(&block->queue_lock);
1898 switch (cqr->status) {
1899 case DASD_CQR_SUCCESS:
1900 cqr->status = DASD_CQR_DONE;
1902 case DASD_CQR_ERROR:
1903 cqr->status = DASD_CQR_NEED_ERP;
1905 case DASD_CQR_CLEARED:
1906 cqr->status = DASD_CQR_TERMINATED;
1909 /* internal error 12 - wrong cqr status*/
1910 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1911 dev_err(&device->cdev->dev,
1912 "An error occurred in the DASD device driver, "
1913 "reason=%s\n", errorstring);
1916 if (cqr->callback != NULL)
1917 (callback)(cqr, callback_data);
1919 spin_unlock_bh(&block->queue_lock);
1924 * Take a look at the first request on the ccw queue and check
1925 * if it reached its expire time. If so, terminate the IO.
1927 static void __dasd_device_check_expire(struct dasd_device *device)
1929 struct dasd_ccw_req *cqr;
1931 if (list_empty(&device->ccw_queue))
1933 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1934 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1935 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1936 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1938 * IO in safe offline processing should not
1939 * run out of retries
1943 if (device->discipline->term_IO(cqr) != 0) {
1944 /* Hmpf, try again in 5 sec */
1945 dev_err(&device->cdev->dev,
1946 "cqr %p timed out (%lus) but cannot be "
1947 "ended, retrying in 5 s\n",
1948 cqr, (cqr->expires/HZ));
1949 cqr->expires += 5*HZ;
1950 dasd_device_set_timer(device, 5*HZ);
1952 dev_err(&device->cdev->dev,
1953 "cqr %p timed out (%lus), %i retries "
1954 "remaining\n", cqr, (cqr->expires/HZ),
1961 * return 1 when device is not eligible for IO
1963 static int __dasd_device_is_unusable(struct dasd_device *device,
1964 struct dasd_ccw_req *cqr)
1966 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM);
1968 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
1969 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1971 * dasd is being set offline
1972 * but it is no safe offline where we have to allow I/O
1976 if (device->stopped) {
1977 if (device->stopped & mask) {
1978 /* stopped and CQR will not change that. */
1981 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1982 /* CQR is not able to change device to
1986 /* CQR required to get device operational. */
1992 * Take a look at the first request on the ccw queue and check
1993 * if it needs to be started.
1995 static void __dasd_device_start_head(struct dasd_device *device)
1997 struct dasd_ccw_req *cqr;
2000 if (list_empty(&device->ccw_queue))
2002 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2003 if (cqr->status != DASD_CQR_QUEUED)
2005 /* if device is not usable return request to upper layer */
2006 if (__dasd_device_is_unusable(device, cqr)) {
2007 cqr->intrc = -EAGAIN;
2008 cqr->status = DASD_CQR_CLEARED;
2009 dasd_schedule_device_bh(device);
2013 rc = device->discipline->start_IO(cqr);
2015 dasd_device_set_timer(device, cqr->expires);
2016 else if (rc == -EACCES) {
2017 dasd_schedule_device_bh(device);
2019 /* Hmpf, try again in 1/2 sec */
2020 dasd_device_set_timer(device, 50);
2023 static void __dasd_device_check_path_events(struct dasd_device *device)
2027 if (!dasd_path_get_tbvpm(device))
2030 if (device->stopped &
2031 ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM))
2033 rc = device->discipline->verify_path(device,
2034 dasd_path_get_tbvpm(device));
2036 dasd_device_set_timer(device, 50);
2038 dasd_path_clear_all_verify(device);
2042 * Go through all request on the dasd_device request queue,
2043 * terminate them on the cdev if necessary, and return them to the
2044 * submitting layer via callback.
2046 * Make sure that all 'submitting layers' still exist when
2047 * this function is called!. In other words, when 'device' is a base
2048 * device then all block layer requests must have been removed before
2049 * via dasd_flush_block_queue.
2051 int dasd_flush_device_queue(struct dasd_device *device)
2053 struct dasd_ccw_req *cqr, *n;
2055 struct list_head flush_queue;
2057 INIT_LIST_HEAD(&flush_queue);
2058 spin_lock_irq(get_ccwdev_lock(device->cdev));
2060 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2061 /* Check status and move request to flush_queue */
2062 switch (cqr->status) {
2063 case DASD_CQR_IN_IO:
2064 rc = device->discipline->term_IO(cqr);
2066 /* unable to terminate requeust */
2067 dev_err(&device->cdev->dev,
2068 "Flushing the DASD request queue "
2069 "failed for request %p\n", cqr);
2070 /* stop flush processing */
2074 case DASD_CQR_QUEUED:
2075 cqr->stopclk = get_tod_clock();
2076 cqr->status = DASD_CQR_CLEARED;
2078 default: /* no need to modify the others */
2081 list_move_tail(&cqr->devlist, &flush_queue);
2084 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2086 * After this point all requests must be in state CLEAR_PENDING,
2087 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2088 * one of the others.
2090 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2091 wait_event(dasd_flush_wq,
2092 (cqr->status != DASD_CQR_CLEAR_PENDING));
2094 * Now set each request back to TERMINATED, DONE or NEED_ERP
2095 * and call the callback function of flushed requests
2097 __dasd_device_process_final_queue(device, &flush_queue);
2100 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2103 * Acquire the device lock and process queues for the device.
2105 static void dasd_device_tasklet(struct dasd_device *device)
2107 struct list_head final_queue;
2109 atomic_set (&device->tasklet_scheduled, 0);
2110 INIT_LIST_HEAD(&final_queue);
2111 spin_lock_irq(get_ccwdev_lock(device->cdev));
2112 /* Check expire time of first request on the ccw queue. */
2113 __dasd_device_check_expire(device);
2114 /* find final requests on ccw queue */
2115 __dasd_device_process_ccw_queue(device, &final_queue);
2116 __dasd_device_check_path_events(device);
2117 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2118 /* Now call the callback function of requests with final status */
2119 __dasd_device_process_final_queue(device, &final_queue);
2120 spin_lock_irq(get_ccwdev_lock(device->cdev));
2121 /* Now check if the head of the ccw queue needs to be started. */
2122 __dasd_device_start_head(device);
2123 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2124 if (waitqueue_active(&shutdown_waitq))
2125 wake_up(&shutdown_waitq);
2126 dasd_put_device(device);
2130 * Schedules a call to dasd_tasklet over the device tasklet.
2132 void dasd_schedule_device_bh(struct dasd_device *device)
2134 /* Protect against rescheduling. */
2135 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2137 dasd_get_device(device);
2138 tasklet_hi_schedule(&device->tasklet);
2140 EXPORT_SYMBOL(dasd_schedule_device_bh);
2142 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2144 device->stopped |= bits;
2146 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2148 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2150 device->stopped &= ~bits;
2151 if (!device->stopped)
2152 wake_up(&generic_waitq);
2154 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2157 * Queue a request to the head of the device ccw_queue.
2158 * Start the I/O if possible.
2160 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2162 struct dasd_device *device;
2163 unsigned long flags;
2165 device = cqr->startdev;
2166 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2167 cqr->status = DASD_CQR_QUEUED;
2168 list_add(&cqr->devlist, &device->ccw_queue);
2169 /* let the bh start the request to keep them in order */
2170 dasd_schedule_device_bh(device);
2171 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2173 EXPORT_SYMBOL(dasd_add_request_head);
2176 * Queue a request to the tail of the device ccw_queue.
2177 * Start the I/O if possible.
2179 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2181 struct dasd_device *device;
2182 unsigned long flags;
2184 device = cqr->startdev;
2185 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2186 cqr->status = DASD_CQR_QUEUED;
2187 list_add_tail(&cqr->devlist, &device->ccw_queue);
2188 /* let the bh start the request to keep them in order */
2189 dasd_schedule_device_bh(device);
2190 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2192 EXPORT_SYMBOL(dasd_add_request_tail);
2195 * Wakeup helper for the 'sleep_on' functions.
2197 void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2199 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2200 cqr->callback_data = DASD_SLEEPON_END_TAG;
2201 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2202 wake_up(&generic_waitq);
2204 EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
2206 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2208 struct dasd_device *device;
2211 device = cqr->startdev;
2212 spin_lock_irq(get_ccwdev_lock(device->cdev));
2213 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2214 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2219 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2221 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2223 struct dasd_device *device;
2224 dasd_erp_fn_t erp_fn;
2226 if (cqr->status == DASD_CQR_FILLED)
2228 device = cqr->startdev;
2229 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2230 if (cqr->status == DASD_CQR_TERMINATED) {
2231 device->discipline->handle_terminated_request(cqr);
2234 if (cqr->status == DASD_CQR_NEED_ERP) {
2235 erp_fn = device->discipline->erp_action(cqr);
2239 if (cqr->status == DASD_CQR_FAILED)
2240 dasd_log_sense(cqr, &cqr->irb);
2242 __dasd_process_erp(device, cqr);
2249 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2251 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2252 if (cqr->refers) /* erp is not done yet */
2254 return ((cqr->status != DASD_CQR_DONE) &&
2255 (cqr->status != DASD_CQR_FAILED));
2257 return (cqr->status == DASD_CQR_FILLED);
2260 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2262 struct dasd_device *device;
2264 struct list_head ccw_queue;
2265 struct dasd_ccw_req *cqr;
2267 INIT_LIST_HEAD(&ccw_queue);
2268 maincqr->status = DASD_CQR_FILLED;
2269 device = maincqr->startdev;
2270 list_add(&maincqr->blocklist, &ccw_queue);
2271 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2272 cqr = list_first_entry(&ccw_queue,
2273 struct dasd_ccw_req, blocklist)) {
2275 if (__dasd_sleep_on_erp(cqr))
2277 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2279 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2280 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2281 cqr->status = DASD_CQR_FAILED;
2282 cqr->intrc = -EPERM;
2285 /* Non-temporary stop condition will trigger fail fast */
2286 if (device->stopped & ~DASD_STOPPED_PENDING &&
2287 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2288 (!dasd_eer_enabled(device))) {
2289 cqr->status = DASD_CQR_FAILED;
2290 cqr->intrc = -ENOLINK;
2294 * Don't try to start requests if device is in
2295 * offline processing, it might wait forever
2297 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2298 cqr->status = DASD_CQR_FAILED;
2299 cqr->intrc = -ENODEV;
2303 * Don't try to start requests if device is stopped
2304 * except path verification requests
2306 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2307 if (interruptible) {
2308 rc = wait_event_interruptible(
2309 generic_waitq, !(device->stopped));
2310 if (rc == -ERESTARTSYS) {
2311 cqr->status = DASD_CQR_FAILED;
2312 maincqr->intrc = rc;
2316 wait_event(generic_waitq, !(device->stopped));
2319 cqr->callback = dasd_wakeup_cb;
2321 cqr->callback_data = DASD_SLEEPON_START_TAG;
2322 dasd_add_request_tail(cqr);
2323 if (interruptible) {
2324 rc = wait_event_interruptible(
2325 generic_waitq, _wait_for_wakeup(cqr));
2326 if (rc == -ERESTARTSYS) {
2327 dasd_cancel_req(cqr);
2328 /* wait (non-interruptible) for final status */
2329 wait_event(generic_waitq,
2330 _wait_for_wakeup(cqr));
2331 cqr->status = DASD_CQR_FAILED;
2332 maincqr->intrc = rc;
2336 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2339 maincqr->endclk = get_tod_clock();
2340 if ((maincqr->status != DASD_CQR_DONE) &&
2341 (maincqr->intrc != -ERESTARTSYS))
2342 dasd_log_sense(maincqr, &maincqr->irb);
2343 if (maincqr->status == DASD_CQR_DONE)
2345 else if (maincqr->intrc)
2346 rc = maincqr->intrc;
2352 static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2354 struct dasd_ccw_req *cqr;
2356 list_for_each_entry(cqr, ccw_queue, blocklist) {
2357 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2364 static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2366 struct dasd_device *device;
2367 struct dasd_ccw_req *cqr, *n;
2372 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2373 device = cqr->startdev;
2374 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2377 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2378 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2379 cqr->status = DASD_CQR_FAILED;
2380 cqr->intrc = -EPERM;
2383 /*Non-temporary stop condition will trigger fail fast*/
2384 if (device->stopped & ~DASD_STOPPED_PENDING &&
2385 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2386 !dasd_eer_enabled(device)) {
2387 cqr->status = DASD_CQR_FAILED;
2388 cqr->intrc = -EAGAIN;
2392 /*Don't try to start requests if device is stopped*/
2393 if (interruptible) {
2394 rc = wait_event_interruptible(
2395 generic_waitq, !device->stopped);
2396 if (rc == -ERESTARTSYS) {
2397 cqr->status = DASD_CQR_FAILED;
2402 wait_event(generic_waitq, !(device->stopped));
2405 cqr->callback = dasd_wakeup_cb;
2406 cqr->callback_data = DASD_SLEEPON_START_TAG;
2407 dasd_add_request_tail(cqr);
2410 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2413 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2415 * In some cases the 'File Protected' or 'Incorrect Length'
2416 * error might be expected and error recovery would be
2417 * unnecessary in these cases. Check if the according suppress
2420 sense = dasd_get_sense(&cqr->irb);
2421 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2422 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2424 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2425 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2429 * for alias devices simplify error recovery and
2430 * return to upper layer
2431 * do not skip ERP requests
2433 if (cqr->startdev != cqr->basedev && !cqr->refers &&
2434 (cqr->status == DASD_CQR_TERMINATED ||
2435 cqr->status == DASD_CQR_NEED_ERP))
2438 /* normal recovery for basedev IO */
2439 if (__dasd_sleep_on_erp(cqr))
2440 /* handle erp first */
2448 * Queue a request to the tail of the device ccw_queue and wait for
2451 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2453 return _dasd_sleep_on(cqr, 0);
2455 EXPORT_SYMBOL(dasd_sleep_on);
2458 * Start requests from a ccw_queue and wait for their completion.
2460 int dasd_sleep_on_queue(struct list_head *ccw_queue)
2462 return _dasd_sleep_on_queue(ccw_queue, 0);
2464 EXPORT_SYMBOL(dasd_sleep_on_queue);
2467 * Queue a request to the tail of the device ccw_queue and wait
2468 * interruptible for it's completion.
2470 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2472 return _dasd_sleep_on(cqr, 1);
2474 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2477 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2478 * for eckd devices) the currently running request has to be terminated
2479 * and be put back to status queued, before the special request is added
2480 * to the head of the queue. Then the special request is waited on normally.
2482 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2484 struct dasd_ccw_req *cqr;
2487 if (list_empty(&device->ccw_queue))
2489 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2490 rc = device->discipline->term_IO(cqr);
2493 * CQR terminated because a more important request is pending.
2494 * Undo decreasing of retry counter because this is
2495 * not an error case.
2501 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2503 struct dasd_device *device;
2506 device = cqr->startdev;
2507 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2508 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2509 cqr->status = DASD_CQR_FAILED;
2510 cqr->intrc = -EPERM;
2513 spin_lock_irq(get_ccwdev_lock(device->cdev));
2514 rc = _dasd_term_running_cqr(device);
2516 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2519 cqr->callback = dasd_wakeup_cb;
2520 cqr->callback_data = DASD_SLEEPON_START_TAG;
2521 cqr->status = DASD_CQR_QUEUED;
2523 * add new request as second
2524 * first the terminated cqr needs to be finished
2526 list_add(&cqr->devlist, device->ccw_queue.next);
2528 /* let the bh start the request to keep them in order */
2529 dasd_schedule_device_bh(device);
2531 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2533 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2535 if (cqr->status == DASD_CQR_DONE)
2537 else if (cqr->intrc)
2543 dasd_schedule_device_bh(device);
2545 dasd_schedule_block_bh(device->block);
2549 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2552 * Cancels a request that was started with dasd_sleep_on_req.
2553 * This is useful to timeout requests. The request will be
2554 * terminated if it is currently in i/o.
2555 * Returns 0 if request termination was successful
2556 * negative error code if termination failed
2557 * Cancellation of a request is an asynchronous operation! The calling
2558 * function has to wait until the request is properly returned via callback.
2560 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2562 struct dasd_device *device = cqr->startdev;
2563 unsigned long flags;
2567 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2568 switch (cqr->status) {
2569 case DASD_CQR_QUEUED:
2570 /* request was not started - just set to cleared */
2571 cqr->status = DASD_CQR_CLEARED;
2572 if (cqr->callback_data == DASD_SLEEPON_START_TAG)
2573 cqr->callback_data = DASD_SLEEPON_END_TAG;
2575 case DASD_CQR_IN_IO:
2576 /* request in IO - terminate IO and release again */
2577 rc = device->discipline->term_IO(cqr);
2579 dev_err(&device->cdev->dev,
2580 "Cancelling request %p failed with rc=%d\n",
2583 cqr->stopclk = get_tod_clock();
2586 default: /* already finished or clear pending - do nothing */
2589 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2590 dasd_schedule_device_bh(device);
2593 EXPORT_SYMBOL(dasd_cancel_req);
2596 * SECTION: Operations of the dasd_block layer.
2600 * Timeout function for dasd_block. This is used when the block layer
2601 * is waiting for something that may not come reliably, (e.g. a state
2604 static void dasd_block_timeout(unsigned long ptr)
2606 unsigned long flags;
2607 struct dasd_block *block;
2609 block = (struct dasd_block *) ptr;
2610 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2611 /* re-activate request queue */
2612 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2613 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2614 dasd_schedule_block_bh(block);
2618 * Setup timeout for a dasd_block in jiffies.
2620 void dasd_block_set_timer(struct dasd_block *block, int expires)
2623 del_timer(&block->timer);
2625 mod_timer(&block->timer, jiffies + expires);
2627 EXPORT_SYMBOL(dasd_block_set_timer);
2630 * Clear timeout for a dasd_block.
2632 void dasd_block_clear_timer(struct dasd_block *block)
2634 del_timer(&block->timer);
2636 EXPORT_SYMBOL(dasd_block_clear_timer);
2639 * Process finished error recovery ccw.
2641 static void __dasd_process_erp(struct dasd_device *device,
2642 struct dasd_ccw_req *cqr)
2644 dasd_erp_fn_t erp_fn;
2646 if (cqr->status == DASD_CQR_DONE)
2647 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2649 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2650 erp_fn = device->discipline->erp_postaction(cqr);
2655 * Fetch requests from the block device queue.
2657 static void __dasd_process_request_queue(struct dasd_block *block)
2659 struct request_queue *queue;
2660 struct request *req;
2661 struct dasd_ccw_req *cqr;
2662 struct dasd_device *basedev;
2663 unsigned long flags;
2664 queue = block->request_queue;
2665 basedev = block->base;
2666 /* No queue ? Then there is nothing to do. */
2671 * We requeue request from the block device queue to the ccw
2672 * queue only in two states. In state DASD_STATE_READY the
2673 * partition detection is done and we need to requeue requests
2674 * for that. State DASD_STATE_ONLINE is normal block device
2677 if (basedev->state < DASD_STATE_READY) {
2678 while ((req = blk_fetch_request(block->request_queue)))
2679 __blk_end_request_all(req, BLK_STS_IOERR);
2684 * if device is stopped do not fetch new requests
2685 * except failfast is active which will let requests fail
2686 * immediately in __dasd_block_start_head()
2688 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST))
2691 /* Now we try to fetch requests from the request queue */
2692 while ((req = blk_peek_request(queue))) {
2693 if (basedev->features & DASD_FEATURE_READONLY &&
2694 rq_data_dir(req) == WRITE) {
2695 DBF_DEV_EVENT(DBF_ERR, basedev,
2696 "Rejecting write request %p",
2698 blk_start_request(req);
2699 __blk_end_request_all(req, BLK_STS_IOERR);
2702 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
2703 (basedev->features & DASD_FEATURE_FAILFAST ||
2704 blk_noretry_request(req))) {
2705 DBF_DEV_EVENT(DBF_ERR, basedev,
2706 "Rejecting failfast request %p",
2708 blk_start_request(req);
2709 __blk_end_request_all(req, BLK_STS_TIMEOUT);
2712 cqr = basedev->discipline->build_cp(basedev, block, req);
2714 if (PTR_ERR(cqr) == -EBUSY)
2715 break; /* normal end condition */
2716 if (PTR_ERR(cqr) == -ENOMEM)
2717 break; /* terminate request queue loop */
2718 if (PTR_ERR(cqr) == -EAGAIN) {
2720 * The current request cannot be build right
2721 * now, we have to try later. If this request
2722 * is the head-of-queue we stop the device
2725 if (!list_empty(&block->ccw_queue))
2728 get_ccwdev_lock(basedev->cdev), flags);
2729 dasd_device_set_stop_bits(basedev,
2730 DASD_STOPPED_PENDING);
2731 spin_unlock_irqrestore(
2732 get_ccwdev_lock(basedev->cdev), flags);
2733 dasd_block_set_timer(block, HZ/2);
2736 DBF_DEV_EVENT(DBF_ERR, basedev,
2737 "CCW creation failed (rc=%ld) "
2740 blk_start_request(req);
2741 __blk_end_request_all(req, BLK_STS_IOERR);
2745 * Note: callback is set to dasd_return_cqr_cb in
2746 * __dasd_block_start_head to cover erp requests as well
2748 cqr->callback_data = (void *) req;
2749 cqr->status = DASD_CQR_FILLED;
2750 req->completion_data = cqr;
2751 blk_start_request(req);
2752 list_add_tail(&cqr->blocklist, &block->ccw_queue);
2753 INIT_LIST_HEAD(&cqr->devlist);
2754 dasd_profile_start(block, cqr, req);
2758 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2760 struct request *req;
2762 blk_status_t error = BLK_STS_OK;
2764 req = (struct request *) cqr->callback_data;
2765 dasd_profile_end(cqr->block, cqr, req);
2767 status = cqr->block->base->discipline->free_cp(cqr, req);
2769 error = errno_to_blk_status(status);
2770 else if (status == 0) {
2771 switch (cqr->intrc) {
2773 error = BLK_STS_NEXUS;
2776 error = BLK_STS_TRANSPORT;
2779 error = BLK_STS_TIMEOUT;
2782 error = BLK_STS_IOERR;
2786 __blk_end_request_all(req, error);
2790 * Process ccw request queue.
2792 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2793 struct list_head *final_queue)
2795 struct list_head *l, *n;
2796 struct dasd_ccw_req *cqr;
2797 dasd_erp_fn_t erp_fn;
2798 unsigned long flags;
2799 struct dasd_device *base = block->base;
2802 /* Process request with final status. */
2803 list_for_each_safe(l, n, &block->ccw_queue) {
2804 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2805 if (cqr->status != DASD_CQR_DONE &&
2806 cqr->status != DASD_CQR_FAILED &&
2807 cqr->status != DASD_CQR_NEED_ERP &&
2808 cqr->status != DASD_CQR_TERMINATED)
2811 if (cqr->status == DASD_CQR_TERMINATED) {
2812 base->discipline->handle_terminated_request(cqr);
2816 /* Process requests that may be recovered */
2817 if (cqr->status == DASD_CQR_NEED_ERP) {
2818 erp_fn = base->discipline->erp_action(cqr);
2819 if (IS_ERR(erp_fn(cqr)))
2824 /* log sense for fatal error */
2825 if (cqr->status == DASD_CQR_FAILED) {
2826 dasd_log_sense(cqr, &cqr->irb);
2829 /* First of all call extended error reporting. */
2830 if (dasd_eer_enabled(base) &&
2831 cqr->status == DASD_CQR_FAILED) {
2832 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2834 /* restart request */
2835 cqr->status = DASD_CQR_FILLED;
2837 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2838 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
2839 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2844 /* Process finished ERP request. */
2846 __dasd_process_erp(base, cqr);
2850 /* Rechain finished requests to final queue */
2851 cqr->endclk = get_tod_clock();
2852 list_move_tail(&cqr->blocklist, final_queue);
2856 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2858 dasd_schedule_block_bh(cqr->block);
2861 static void __dasd_block_start_head(struct dasd_block *block)
2863 struct dasd_ccw_req *cqr;
2865 if (list_empty(&block->ccw_queue))
2867 /* We allways begin with the first requests on the queue, as some
2868 * of previously started requests have to be enqueued on a
2869 * dasd_device again for error recovery.
2871 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2872 if (cqr->status != DASD_CQR_FILLED)
2874 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2875 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2876 cqr->status = DASD_CQR_FAILED;
2877 cqr->intrc = -EPERM;
2878 dasd_schedule_block_bh(block);
2881 /* Non-temporary stop condition will trigger fail fast */
2882 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2883 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2884 (!dasd_eer_enabled(block->base))) {
2885 cqr->status = DASD_CQR_FAILED;
2886 cqr->intrc = -ENOLINK;
2887 dasd_schedule_block_bh(block);
2890 /* Don't try to start requests if device is stopped */
2891 if (block->base->stopped)
2894 /* just a fail safe check, should not happen */
2896 cqr->startdev = block->base;
2898 /* make sure that the requests we submit find their way back */
2899 cqr->callback = dasd_return_cqr_cb;
2901 dasd_add_request_tail(cqr);
2906 * Central dasd_block layer routine. Takes requests from the generic
2907 * block layer request queue, creates ccw requests, enqueues them on
2908 * a dasd_device and processes ccw requests that have been returned.
2910 static void dasd_block_tasklet(struct dasd_block *block)
2912 struct list_head final_queue;
2913 struct list_head *l, *n;
2914 struct dasd_ccw_req *cqr;
2916 atomic_set(&block->tasklet_scheduled, 0);
2917 INIT_LIST_HEAD(&final_queue);
2918 spin_lock(&block->queue_lock);
2919 /* Finish off requests on ccw queue */
2920 __dasd_process_block_ccw_queue(block, &final_queue);
2921 spin_unlock(&block->queue_lock);
2922 /* Now call the callback function of requests with final status */
2923 spin_lock_irq(&block->request_queue_lock);
2924 list_for_each_safe(l, n, &final_queue) {
2925 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2926 list_del_init(&cqr->blocklist);
2927 __dasd_cleanup_cqr(cqr);
2929 spin_lock(&block->queue_lock);
2930 /* Get new request from the block device request queue */
2931 __dasd_process_request_queue(block);
2932 /* Now check if the head of the ccw queue needs to be started. */
2933 __dasd_block_start_head(block);
2934 spin_unlock(&block->queue_lock);
2935 spin_unlock_irq(&block->request_queue_lock);
2936 if (waitqueue_active(&shutdown_waitq))
2937 wake_up(&shutdown_waitq);
2938 dasd_put_device(block->base);
2941 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2943 wake_up(&dasd_flush_wq);
2947 * Requeue a request back to the block request queue
2948 * only works for block requests
2950 static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
2952 struct dasd_block *block = cqr->block;
2953 struct request *req;
2954 unsigned long flags;
2958 spin_lock_irqsave(&block->request_queue_lock, flags);
2959 req = (struct request *) cqr->callback_data;
2960 blk_requeue_request(block->request_queue, req);
2961 spin_unlock_irqrestore(&block->request_queue_lock, flags);
2967 * Go through all request on the dasd_block request queue, cancel them
2968 * on the respective dasd_device, and return them to the generic
2971 static int dasd_flush_block_queue(struct dasd_block *block)
2973 struct dasd_ccw_req *cqr, *n;
2975 struct list_head flush_queue;
2977 INIT_LIST_HEAD(&flush_queue);
2978 spin_lock_bh(&block->queue_lock);
2981 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2982 /* if this request currently owned by a dasd_device cancel it */
2983 if (cqr->status >= DASD_CQR_QUEUED)
2984 rc = dasd_cancel_req(cqr);
2987 /* Rechain request (including erp chain) so it won't be
2988 * touched by the dasd_block_tasklet anymore.
2989 * Replace the callback so we notice when the request
2990 * is returned from the dasd_device layer.
2992 cqr->callback = _dasd_wake_block_flush_cb;
2993 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
2994 list_move_tail(&cqr->blocklist, &flush_queue);
2996 /* moved more than one request - need to restart */
2999 spin_unlock_bh(&block->queue_lock);
3000 /* Now call the callback function of flushed requests */
3002 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
3003 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
3004 /* Process finished ERP request. */
3006 spin_lock_bh(&block->queue_lock);
3007 __dasd_process_erp(block->base, cqr);
3008 spin_unlock_bh(&block->queue_lock);
3009 /* restart list_for_xx loop since dasd_process_erp
3010 * might remove multiple elements */
3013 /* call the callback function */
3014 spin_lock_irq(&block->request_queue_lock);
3015 cqr->endclk = get_tod_clock();
3016 list_del_init(&cqr->blocklist);
3017 __dasd_cleanup_cqr(cqr);
3018 spin_unlock_irq(&block->request_queue_lock);
3024 * Schedules a call to dasd_tasklet over the device tasklet.
3026 void dasd_schedule_block_bh(struct dasd_block *block)
3028 /* Protect against rescheduling. */
3029 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
3031 /* life cycle of block is bound to it's base device */
3032 dasd_get_device(block->base);
3033 tasklet_hi_schedule(&block->tasklet);
3035 EXPORT_SYMBOL(dasd_schedule_block_bh);
3039 * SECTION: external block device operations
3040 * (request queue handling, open, release, etc.)
3044 * Dasd request queue function. Called from ll_rw_blk.c
3046 static void do_dasd_request(struct request_queue *queue)
3048 struct dasd_block *block;
3050 block = queue->queuedata;
3051 spin_lock(&block->queue_lock);
3052 /* Get new request from the block device request queue */
3053 __dasd_process_request_queue(block);
3054 /* Now check if the head of the ccw queue needs to be started. */
3055 __dasd_block_start_head(block);
3056 spin_unlock(&block->queue_lock);
3060 * Block timeout callback, called from the block layer
3062 * request_queue lock is held on entry.
3065 * BLK_EH_RESET_TIMER if the request should be left running
3066 * BLK_EH_NOT_HANDLED if the request is handled or terminated
3069 enum blk_eh_timer_return dasd_times_out(struct request *req)
3071 struct dasd_ccw_req *cqr = req->completion_data;
3072 struct dasd_block *block = req->q->queuedata;
3073 struct dasd_device *device;
3077 return BLK_EH_NOT_HANDLED;
3079 device = cqr->startdev ? cqr->startdev : block->base;
3080 if (!device->blk_timeout)
3081 return BLK_EH_RESET_TIMER;
3082 DBF_DEV_EVENT(DBF_WARNING, device,
3083 " dasd_times_out cqr %p status %x",
3086 spin_lock(&block->queue_lock);
3087 spin_lock(get_ccwdev_lock(device->cdev));
3089 cqr->intrc = -ETIMEDOUT;
3090 if (cqr->status >= DASD_CQR_QUEUED) {
3091 spin_unlock(get_ccwdev_lock(device->cdev));
3092 rc = dasd_cancel_req(cqr);
3093 } else if (cqr->status == DASD_CQR_FILLED ||
3094 cqr->status == DASD_CQR_NEED_ERP) {
3095 cqr->status = DASD_CQR_TERMINATED;
3096 spin_unlock(get_ccwdev_lock(device->cdev));
3097 } else if (cqr->status == DASD_CQR_IN_ERP) {
3098 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3100 list_for_each_entry_safe(searchcqr, nextcqr,
3101 &block->ccw_queue, blocklist) {
3103 while (tmpcqr->refers)
3104 tmpcqr = tmpcqr->refers;
3107 /* searchcqr is an ERP request for cqr */
3108 searchcqr->retries = -1;
3109 searchcqr->intrc = -ETIMEDOUT;
3110 if (searchcqr->status >= DASD_CQR_QUEUED) {
3111 spin_unlock(get_ccwdev_lock(device->cdev));
3112 rc = dasd_cancel_req(searchcqr);
3113 spin_lock(get_ccwdev_lock(device->cdev));
3114 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3115 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3116 searchcqr->status = DASD_CQR_TERMINATED;
3118 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3120 * Shouldn't happen; most recent ERP
3121 * request is at the front of queue
3127 spin_unlock(get_ccwdev_lock(device->cdev));
3129 dasd_schedule_block_bh(block);
3130 spin_unlock(&block->queue_lock);
3132 return rc ? BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
3136 * Allocate and initialize request queue and default I/O scheduler.
3138 static int dasd_alloc_queue(struct dasd_block *block)
3140 block->request_queue = blk_init_queue(do_dasd_request,
3141 &block->request_queue_lock);
3142 if (block->request_queue == NULL)
3145 block->request_queue->queuedata = block;
3151 * Allocate and initialize request queue.
3153 static void dasd_setup_queue(struct dasd_block *block)
3155 struct request_queue *q = block->request_queue;
3158 if (block->base->features & DASD_FEATURE_USERAW) {
3160 * the max_blocks value for raw_track access is 256
3161 * it is higher than the native ECKD value because we
3162 * only need one ccw per track
3163 * so the max_hw_sectors are
3164 * 2048 x 512B = 1024kB = 16 tracks
3168 max = block->base->discipline->max_blocks << block->s2b_shift;
3170 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
3171 q->limits.max_dev_sectors = max;
3172 blk_queue_logical_block_size(q, block->bp_block);
3173 blk_queue_max_hw_sectors(q, max);
3174 blk_queue_max_segments(q, USHRT_MAX);
3175 /* with page sized segments we can translate each segement into
3178 blk_queue_max_segment_size(q, PAGE_SIZE);
3179 blk_queue_segment_boundary(q, PAGE_SIZE - 1);
3183 * Deactivate and free request queue.
3185 static void dasd_free_queue(struct dasd_block *block)
3187 if (block->request_queue) {
3188 blk_cleanup_queue(block->request_queue);
3189 block->request_queue = NULL;
3194 * Flush request on the request queue.
3196 static void dasd_flush_request_queue(struct dasd_block *block)
3198 struct request *req;
3200 if (!block->request_queue)
3203 spin_lock_irq(&block->request_queue_lock);
3204 while ((req = blk_fetch_request(block->request_queue)))
3205 __blk_end_request_all(req, BLK_STS_IOERR);
3206 spin_unlock_irq(&block->request_queue_lock);
3209 static int dasd_open(struct block_device *bdev, fmode_t mode)
3211 struct dasd_device *base;
3214 base = dasd_device_from_gendisk(bdev->bd_disk);
3218 atomic_inc(&base->block->open_count);
3219 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
3224 if (!try_module_get(base->discipline->owner)) {
3229 if (dasd_probeonly) {
3230 dev_info(&base->cdev->dev,
3231 "Accessing the DASD failed because it is in "
3232 "probeonly mode\n");
3237 if (base->state <= DASD_STATE_BASIC) {
3238 DBF_DEV_EVENT(DBF_ERR, base, " %s",
3239 " Cannot open unrecognized device");
3244 if ((mode & FMODE_WRITE) &&
3245 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3246 (base->features & DASD_FEATURE_READONLY))) {
3251 dasd_put_device(base);
3255 module_put(base->discipline->owner);
3257 atomic_dec(&base->block->open_count);
3258 dasd_put_device(base);
3262 static void dasd_release(struct gendisk *disk, fmode_t mode)
3264 struct dasd_device *base = dasd_device_from_gendisk(disk);
3266 atomic_dec(&base->block->open_count);
3267 module_put(base->discipline->owner);
3268 dasd_put_device(base);
3273 * Return disk geometry.
3275 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3277 struct dasd_device *base;
3279 base = dasd_device_from_gendisk(bdev->bd_disk);
3283 if (!base->discipline ||
3284 !base->discipline->fill_geometry) {
3285 dasd_put_device(base);
3288 base->discipline->fill_geometry(base->block, geo);
3289 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3290 dasd_put_device(base);
3294 const struct block_device_operations
3295 dasd_device_operations = {
3296 .owner = THIS_MODULE,
3298 .release = dasd_release,
3299 .ioctl = dasd_ioctl,
3300 .compat_ioctl = dasd_ioctl,
3301 .getgeo = dasd_getgeo,
3304 /*******************************************************************************
3305 * end of block device operations
3311 #ifdef CONFIG_PROC_FS
3315 if (dasd_page_cache != NULL) {
3316 kmem_cache_destroy(dasd_page_cache);
3317 dasd_page_cache = NULL;
3319 dasd_gendisk_exit();
3321 if (dasd_debug_area != NULL) {
3322 debug_unregister(dasd_debug_area);
3323 dasd_debug_area = NULL;
3325 dasd_statistics_removeroot();
3329 * SECTION: common functions for ccw_driver use
3333 * Is the device read-only?
3334 * Note that this function does not report the setting of the
3335 * readonly device attribute, but how it is configured in z/VM.
3337 int dasd_device_is_ro(struct dasd_device *device)
3339 struct ccw_dev_id dev_id;
3340 struct diag210 diag_data;
3345 ccw_device_get_id(device->cdev, &dev_id);
3346 memset(&diag_data, 0, sizeof(diag_data));
3347 diag_data.vrdcdvno = dev_id.devno;
3348 diag_data.vrdclen = sizeof(diag_data);
3349 rc = diag210(&diag_data);
3350 if (rc == 0 || rc == 2) {
3351 return diag_data.vrdcvfla & 0x80;
3353 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3358 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3360 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3362 struct ccw_device *cdev = data;
3365 ret = ccw_device_set_online(cdev);
3367 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3368 dev_name(&cdev->dev), ret);
3372 * Initial attempt at a probe function. this can be simplified once
3373 * the other detection code is gone.
3375 int dasd_generic_probe(struct ccw_device *cdev,
3376 struct dasd_discipline *discipline)
3380 ret = dasd_add_sysfs_files(cdev);
3382 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
3383 "dasd_generic_probe: could not add "
3387 cdev->handler = &dasd_int_handler;
3390 * Automatically online either all dasd devices (dasd_autodetect)
3391 * or all devices specified with dasd= parameters during
3394 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
3395 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
3396 async_schedule(dasd_generic_auto_online, cdev);
3399 EXPORT_SYMBOL_GPL(dasd_generic_probe);
3401 void dasd_generic_free_discipline(struct dasd_device *device)
3403 /* Forget the discipline information. */
3404 if (device->discipline) {
3405 if (device->discipline->uncheck_device)
3406 device->discipline->uncheck_device(device);
3407 module_put(device->discipline->owner);
3408 device->discipline = NULL;
3410 if (device->base_discipline) {
3411 module_put(device->base_discipline->owner);
3412 device->base_discipline = NULL;
3415 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3418 * This will one day be called from a global not_oper handler.
3419 * It is also used by driver_unregister during module unload.
3421 void dasd_generic_remove(struct ccw_device *cdev)
3423 struct dasd_device *device;
3424 struct dasd_block *block;
3426 cdev->handler = NULL;
3428 device = dasd_device_from_cdev(cdev);
3429 if (IS_ERR(device)) {
3430 dasd_remove_sysfs_files(cdev);
3433 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3434 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3435 /* Already doing offline processing */
3436 dasd_put_device(device);
3437 dasd_remove_sysfs_files(cdev);
3441 * This device is removed unconditionally. Set offline
3442 * flag to prevent dasd_open from opening it while it is
3443 * no quite down yet.
3445 dasd_set_target_state(device, DASD_STATE_NEW);
3446 /* dasd_delete_device destroys the device reference. */
3447 block = device->block;
3448 dasd_delete_device(device);
3450 * life cycle of block is bound to device, so delete it after
3451 * device was safely removed
3454 dasd_free_block(block);
3456 dasd_remove_sysfs_files(cdev);
3458 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3461 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3462 * the device is detected for the first time and is supposed to be used
3463 * or the user has started activation through sysfs.
3465 int dasd_generic_set_online(struct ccw_device *cdev,
3466 struct dasd_discipline *base_discipline)
3468 struct dasd_discipline *discipline;
3469 struct dasd_device *device;
3472 /* first online clears initial online feature flag */
3473 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3474 device = dasd_create_device(cdev);
3476 return PTR_ERR(device);
3478 discipline = base_discipline;
3479 if (device->features & DASD_FEATURE_USEDIAG) {
3480 if (!dasd_diag_discipline_pointer) {
3481 /* Try to load the required module. */
3482 rc = request_module(DASD_DIAG_MOD);
3484 pr_warn("%s Setting the DASD online failed "
3485 "because the required module %s "
3486 "could not be loaded (rc=%d)\n",
3487 dev_name(&cdev->dev), DASD_DIAG_MOD,
3489 dasd_delete_device(device);
3493 /* Module init could have failed, so check again here after
3494 * request_module(). */
3495 if (!dasd_diag_discipline_pointer) {
3496 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3497 dev_name(&cdev->dev));
3498 dasd_delete_device(device);
3501 discipline = dasd_diag_discipline_pointer;
3503 if (!try_module_get(base_discipline->owner)) {
3504 dasd_delete_device(device);
3507 if (!try_module_get(discipline->owner)) {
3508 module_put(base_discipline->owner);
3509 dasd_delete_device(device);
3512 device->base_discipline = base_discipline;
3513 device->discipline = discipline;
3515 /* check_device will allocate block device if necessary */
3516 rc = discipline->check_device(device);
3518 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3519 dev_name(&cdev->dev), discipline->name, rc);
3520 module_put(discipline->owner);
3521 module_put(base_discipline->owner);
3522 dasd_delete_device(device);
3526 dasd_set_target_state(device, DASD_STATE_ONLINE);
3527 if (device->state <= DASD_STATE_KNOWN) {
3528 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3529 dev_name(&cdev->dev));
3531 dasd_set_target_state(device, DASD_STATE_NEW);
3533 dasd_free_block(device->block);
3534 dasd_delete_device(device);
3536 pr_debug("dasd_generic device %s found\n",
3537 dev_name(&cdev->dev));
3539 wait_event(dasd_init_waitq, _wait_for_device(device));
3541 dasd_put_device(device);
3544 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3546 int dasd_generic_set_offline(struct ccw_device *cdev)
3548 struct dasd_device *device;
3549 struct dasd_block *block;
3550 int max_count, open_count, rc;
3551 unsigned long flags;
3554 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3555 device = dasd_device_from_cdev_locked(cdev);
3556 if (IS_ERR(device)) {
3557 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3558 return PTR_ERR(device);
3562 * We must make sure that this device is currently not in use.
3563 * The open_count is increased for every opener, that includes
3564 * the blkdev_get in dasd_scan_partitions. We are only interested
3565 * in the other openers.
3567 if (device->block) {
3568 max_count = device->block->bdev ? 0 : -1;
3569 open_count = atomic_read(&device->block->open_count);
3570 if (open_count > max_count) {
3572 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3573 dev_name(&cdev->dev), open_count);
3575 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3576 dev_name(&cdev->dev));
3583 * Test if the offline processing is already running and exit if so.
3584 * If a safe offline is being processed this could only be a normal
3585 * offline that should be able to overtake the safe offline and
3586 * cancel any I/O we do not want to wait for any longer
3588 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3589 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3590 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3597 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3600 * if safe_offline is called set safe_offline_running flag and
3601 * clear safe_offline so that a call to normal offline
3602 * can overrun safe_offline processing
3604 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3605 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3606 /* need to unlock here to wait for outstanding I/O */
3607 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3609 * If we want to set the device safe offline all IO operations
3610 * should be finished before continuing the offline process
3611 * so sync bdev first and then wait for our queues to become
3614 if (device->block) {
3615 rc = fsync_bdev(device->block->bdev);
3619 dasd_schedule_device_bh(device);
3620 rc = wait_event_interruptible(shutdown_waitq,
3621 _wait_for_empty_queues(device));
3626 * check if a normal offline process overtook the offline
3627 * processing in this case simply do nothing beside returning
3628 * that we got interrupted
3629 * otherwise mark safe offline as not running any longer and
3630 * continue with normal offline
3632 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3633 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3637 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3639 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3641 dasd_set_target_state(device, DASD_STATE_NEW);
3642 /* dasd_delete_device destroys the device reference. */
3643 block = device->block;
3644 dasd_delete_device(device);
3646 * life cycle of block is bound to device, so delete it after
3647 * device was safely removed
3650 dasd_free_block(block);
3655 /* interrupted by signal */
3656 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3657 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3658 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3660 dasd_put_device(device);
3661 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3664 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3666 int dasd_generic_last_path_gone(struct dasd_device *device)
3668 struct dasd_ccw_req *cqr;
3670 dev_warn(&device->cdev->dev, "No operational channel path is left "
3671 "for the device\n");
3672 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3673 /* First of all call extended error reporting. */
3674 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3676 if (device->state < DASD_STATE_BASIC)
3678 /* Device is active. We want to keep it. */
3679 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3680 if ((cqr->status == DASD_CQR_IN_IO) ||
3681 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3682 cqr->status = DASD_CQR_QUEUED;
3685 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3686 dasd_device_clear_timer(device);
3687 dasd_schedule_device_bh(device);
3690 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3692 int dasd_generic_path_operational(struct dasd_device *device)
3694 dev_info(&device->cdev->dev, "A channel path to the device has become "
3696 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3697 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3698 if (device->stopped & DASD_UNRESUMED_PM) {
3699 dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
3700 dasd_restore_device(device);
3703 dasd_schedule_device_bh(device);
3705 dasd_schedule_block_bh(device->block);
3707 if (!device->stopped)
3708 wake_up(&generic_waitq);
3712 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3714 int dasd_generic_notify(struct ccw_device *cdev, int event)
3716 struct dasd_device *device;
3719 device = dasd_device_from_cdev_locked(cdev);
3727 dasd_path_no_path(device);
3728 ret = dasd_generic_last_path_gone(device);
3732 if (dasd_path_get_opm(device))
3733 ret = dasd_generic_path_operational(device);
3736 dasd_put_device(device);
3739 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3741 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3743 struct dasd_device *device;
3744 int chp, oldopm, hpfpm, ifccpm;
3746 device = dasd_device_from_cdev_locked(cdev);
3750 oldopm = dasd_path_get_opm(device);
3751 for (chp = 0; chp < 8; chp++) {
3752 if (path_event[chp] & PE_PATH_GONE) {
3753 dasd_path_notoper(device, chp);
3755 if (path_event[chp] & PE_PATH_AVAILABLE) {
3756 dasd_path_available(device, chp);
3757 dasd_schedule_device_bh(device);
3759 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3760 if (!dasd_path_is_operational(device, chp) &&
3761 !dasd_path_need_verify(device, chp)) {
3763 * we can not establish a pathgroup on an
3764 * unavailable path, so trigger a path
3765 * verification first
3767 dasd_path_available(device, chp);
3768 dasd_schedule_device_bh(device);
3770 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3771 "Pathgroup re-established\n");
3772 if (device->discipline->kick_validate)
3773 device->discipline->kick_validate(device);
3776 hpfpm = dasd_path_get_hpfpm(device);
3777 ifccpm = dasd_path_get_ifccpm(device);
3778 if (!dasd_path_get_opm(device) && hpfpm) {
3780 * device has no operational paths but at least one path is
3781 * disabled due to HPF errors
3782 * disable HPF at all and use the path(s) again
3784 if (device->discipline->disable_hpf)
3785 device->discipline->disable_hpf(device);
3786 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3787 dasd_path_set_tbvpm(device, hpfpm);
3788 dasd_schedule_device_bh(device);
3789 dasd_schedule_requeue(device);
3790 } else if (!dasd_path_get_opm(device) && ifccpm) {
3792 * device has no operational paths but at least one path is
3793 * disabled due to IFCC errors
3794 * trigger path verification on paths with IFCC errors
3796 dasd_path_set_tbvpm(device, ifccpm);
3797 dasd_schedule_device_bh(device);
3799 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3800 dev_warn(&device->cdev->dev,
3801 "No verified channel paths remain for the device\n");
3802 DBF_DEV_EVENT(DBF_WARNING, device,
3803 "%s", "last verified path gone");
3804 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3805 dasd_device_set_stop_bits(device,
3806 DASD_STOPPED_DC_WAIT);
3808 dasd_put_device(device);
3810 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3812 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3814 if (!dasd_path_get_opm(device) && lpm) {
3815 dasd_path_set_opm(device, lpm);
3816 dasd_generic_path_operational(device);
3818 dasd_path_add_opm(device, lpm);
3821 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3824 * clear active requests and requeue them to block layer if possible
3826 static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3828 struct list_head requeue_queue;
3829 struct dasd_ccw_req *cqr, *n;
3830 struct dasd_ccw_req *refers;
3833 INIT_LIST_HEAD(&requeue_queue);
3834 spin_lock_irq(get_ccwdev_lock(device->cdev));
3836 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3837 /* Check status and move request to flush_queue */
3838 if (cqr->status == DASD_CQR_IN_IO) {
3839 rc = device->discipline->term_IO(cqr);
3841 /* unable to terminate requeust */
3842 dev_err(&device->cdev->dev,
3843 "Unable to terminate request %p "
3844 "on suspend\n", cqr);
3845 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3846 dasd_put_device(device);
3850 list_move_tail(&cqr->devlist, &requeue_queue);
3852 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3854 list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) {
3855 wait_event(dasd_flush_wq,
3856 (cqr->status != DASD_CQR_CLEAR_PENDING));
3858 /* mark sleepon requests as ended */
3859 if (cqr->callback_data == DASD_SLEEPON_START_TAG)
3860 cqr->callback_data = DASD_SLEEPON_END_TAG;
3862 /* remove requests from device and block queue */
3863 list_del_init(&cqr->devlist);
3864 while (cqr->refers != NULL) {
3865 refers = cqr->refers;
3866 /* remove the request from the block queue */
3867 list_del(&cqr->blocklist);
3868 /* free the finished erp request */
3869 dasd_free_erp_request(cqr, cqr->memdev);
3874 * requeue requests to blocklayer will only work
3875 * for block device requests
3877 if (_dasd_requeue_request(cqr))
3881 list_del_init(&cqr->blocklist);
3882 cqr->block->base->discipline->free_cp(
3883 cqr, (struct request *) cqr->callback_data);
3887 * if requests remain then they are internal request
3888 * and go back to the device queue
3890 if (!list_empty(&requeue_queue)) {
3891 /* move freeze_queue to start of the ccw_queue */
3892 spin_lock_irq(get_ccwdev_lock(device->cdev));
3893 list_splice_tail(&requeue_queue, &device->ccw_queue);
3894 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3896 /* wake up generic waitqueue for eventually ended sleepon requests */
3897 wake_up(&generic_waitq);
3901 static void do_requeue_requests(struct work_struct *work)
3903 struct dasd_device *device = container_of(work, struct dasd_device,
3905 dasd_generic_requeue_all_requests(device);
3906 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3908 dasd_schedule_block_bh(device->block);
3909 dasd_put_device(device);
3912 void dasd_schedule_requeue(struct dasd_device *device)
3914 dasd_get_device(device);
3915 /* queue call to dasd_reload_device to the kernel event daemon. */
3916 if (!schedule_work(&device->requeue_requests))
3917 dasd_put_device(device);
3919 EXPORT_SYMBOL(dasd_schedule_requeue);
3921 int dasd_generic_pm_freeze(struct ccw_device *cdev)
3923 struct dasd_device *device = dasd_device_from_cdev(cdev);
3927 return PTR_ERR(device);
3929 /* mark device as suspended */
3930 set_bit(DASD_FLAG_SUSPENDED, &device->flags);
3932 if (device->discipline->freeze)
3933 rc = device->discipline->freeze(device);
3935 /* disallow new I/O */
3936 dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
3938 return dasd_generic_requeue_all_requests(device);
3940 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
3942 int dasd_generic_restore_device(struct ccw_device *cdev)
3944 struct dasd_device *device = dasd_device_from_cdev(cdev);
3948 return PTR_ERR(device);
3950 /* allow new IO again */
3951 dasd_device_remove_stop_bits(device,
3952 (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
3954 dasd_schedule_device_bh(device);
3957 * call discipline restore function
3958 * if device is stopped do nothing e.g. for disconnected devices
3960 if (device->discipline->restore && !(device->stopped))
3961 rc = device->discipline->restore(device);
3962 if (rc || device->stopped)
3964 * if the resume failed for the DASD we put it in
3965 * an UNRESUMED stop state
3967 device->stopped |= DASD_UNRESUMED_PM;
3970 dasd_schedule_block_bh(device->block);
3972 clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
3973 dasd_put_device(device);
3976 EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
3978 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
3980 int rdc_buffer_size,
3983 struct dasd_ccw_req *cqr;
3985 unsigned long *idaw;
3987 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
3990 /* internal error 13 - Allocating the RDC request failed*/
3991 dev_err(&device->cdev->dev,
3992 "An error occurred in the DASD device driver, "
3993 "reason=%s\n", "13");
3998 ccw->cmd_code = CCW_CMD_RDC;
3999 if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
4000 idaw = (unsigned long *) (cqr->data);
4001 ccw->cda = (__u32)(addr_t) idaw;
4002 ccw->flags = CCW_FLAG_IDA;
4003 idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
4005 ccw->cda = (__u32)(addr_t) rdc_buffer;
4009 ccw->count = rdc_buffer_size;
4010 cqr->startdev = device;
4011 cqr->memdev = device;
4012 cqr->expires = 10*HZ;
4014 cqr->buildclk = get_tod_clock();
4015 cqr->status = DASD_CQR_FILLED;
4020 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4021 void *rdc_buffer, int rdc_buffer_size)
4024 struct dasd_ccw_req *cqr;
4026 cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
4029 return PTR_ERR(cqr);
4031 ret = dasd_sleep_on(cqr);
4032 dasd_sfree_request(cqr, cqr->memdev);
4035 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
4038 * In command mode and transport mode we need to look for sense
4039 * data in different places. The sense data itself is allways
4040 * an array of 32 bytes, so we can unify the sense data access
4043 char *dasd_get_sense(struct irb *irb)
4045 struct tsb *tsb = NULL;
4048 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4049 if (irb->scsw.tm.tcw)
4050 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
4052 if (tsb && tsb->length == 64 && tsb->flags)
4053 switch (tsb->flags & 0x07) {
4054 case 1: /* tsa_iostat */
4055 sense = tsb->tsa.iostat.sense;
4057 case 2: /* tsa_ddpc */
4058 sense = tsb->tsa.ddpc.sense;
4061 /* currently we don't use interrogate data */
4064 } else if (irb->esw.esw0.erw.cons) {
4069 EXPORT_SYMBOL_GPL(dasd_get_sense);
4071 void dasd_generic_shutdown(struct ccw_device *cdev)
4073 struct dasd_device *device;
4075 device = dasd_device_from_cdev(cdev);
4080 dasd_schedule_block_bh(device->block);
4082 dasd_schedule_device_bh(device);
4084 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4086 EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4088 static int __init dasd_init(void)
4092 init_waitqueue_head(&dasd_init_waitq);
4093 init_waitqueue_head(&dasd_flush_wq);
4094 init_waitqueue_head(&generic_waitq);
4095 init_waitqueue_head(&shutdown_waitq);
4097 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4098 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
4099 if (dasd_debug_area == NULL) {
4103 debug_register_view(dasd_debug_area, &debug_sprintf_view);
4104 debug_set_level(dasd_debug_area, DBF_WARNING);
4106 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4108 dasd_diag_discipline_pointer = NULL;
4110 dasd_statistics_createroot();
4112 rc = dasd_devmap_init();
4115 rc = dasd_gendisk_init();
4121 rc = dasd_eer_init();
4124 #ifdef CONFIG_PROC_FS
4125 rc = dasd_proc_init();
4132 pr_info("The DASD device driver could not be initialized\n");
4137 module_init(dasd_init);
4138 module_exit(dasd_exit);