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 unsigned long strtime, irqtime, endtime, tottime;
805 unsigned 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;
809 struct dasd_profile_info *data;
811 device = cqr->startdev;
812 if (!(dasd_global_profile_level ||
813 block->profile.data ||
814 device->profile.data))
817 sectors = blk_rq_sectors(req);
818 if (!cqr->buildclk || !cqr->startclk ||
819 !cqr->stopclk || !cqr->endclk ||
823 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
824 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
825 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
826 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
827 tottimeps = tottime / sectors;
829 dasd_profile_counter(sectors, sectors_ind);
830 dasd_profile_counter(tottime, tottime_ind);
831 dasd_profile_counter(tottimeps, tottimeps_ind);
832 dasd_profile_counter(strtime, strtime_ind);
833 dasd_profile_counter(irqtime, irqtime_ind);
834 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
835 dasd_profile_counter(endtime, endtime_ind);
837 spin_lock(&dasd_global_profile.lock);
838 if (dasd_global_profile.data) {
839 data = dasd_global_profile.data;
840 data->dasd_sum_times += tottime;
841 data->dasd_sum_time_str += strtime;
842 data->dasd_sum_time_irq += irqtime;
843 data->dasd_sum_time_end += endtime;
844 dasd_profile_end_add_data(dasd_global_profile.data,
845 cqr->startdev != block->base,
847 rq_data_dir(req) == READ,
848 sectors, sectors_ind, tottime_ind,
849 tottimeps_ind, strtime_ind,
850 irqtime_ind, irqtimeps_ind,
853 spin_unlock(&dasd_global_profile.lock);
855 spin_lock(&block->profile.lock);
856 if (block->profile.data) {
857 data = block->profile.data;
858 data->dasd_sum_times += tottime;
859 data->dasd_sum_time_str += strtime;
860 data->dasd_sum_time_irq += irqtime;
861 data->dasd_sum_time_end += endtime;
862 dasd_profile_end_add_data(block->profile.data,
863 cqr->startdev != block->base,
865 rq_data_dir(req) == READ,
866 sectors, sectors_ind, tottime_ind,
867 tottimeps_ind, strtime_ind,
868 irqtime_ind, irqtimeps_ind,
871 spin_unlock(&block->profile.lock);
873 spin_lock(&device->profile.lock);
874 if (device->profile.data) {
875 data = device->profile.data;
876 data->dasd_sum_times += tottime;
877 data->dasd_sum_time_str += strtime;
878 data->dasd_sum_time_irq += irqtime;
879 data->dasd_sum_time_end += endtime;
880 dasd_profile_end_add_data(device->profile.data,
881 cqr->startdev != block->base,
883 rq_data_dir(req) == READ,
884 sectors, sectors_ind, tottime_ind,
885 tottimeps_ind, strtime_ind,
886 irqtime_ind, irqtimeps_ind,
889 spin_unlock(&device->profile.lock);
892 void dasd_profile_reset(struct dasd_profile *profile)
894 struct dasd_profile_info *data;
896 spin_lock_bh(&profile->lock);
897 data = profile->data;
899 spin_unlock_bh(&profile->lock);
902 memset(data, 0, sizeof(*data));
903 getnstimeofday(&data->starttod);
904 spin_unlock_bh(&profile->lock);
907 int dasd_profile_on(struct dasd_profile *profile)
909 struct dasd_profile_info *data;
911 data = kzalloc(sizeof(*data), GFP_KERNEL);
914 spin_lock_bh(&profile->lock);
916 spin_unlock_bh(&profile->lock);
920 getnstimeofday(&data->starttod);
921 profile->data = data;
922 spin_unlock_bh(&profile->lock);
926 void dasd_profile_off(struct dasd_profile *profile)
928 spin_lock_bh(&profile->lock);
929 kfree(profile->data);
930 profile->data = NULL;
931 spin_unlock_bh(&profile->lock);
934 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
938 buffer = vmalloc(user_len + 1);
940 return ERR_PTR(-ENOMEM);
941 if (copy_from_user(buffer, user_buf, user_len) != 0) {
943 return ERR_PTR(-EFAULT);
945 /* got the string, now strip linefeed. */
946 if (buffer[user_len - 1] == '\n')
947 buffer[user_len - 1] = 0;
949 buffer[user_len] = 0;
953 static ssize_t dasd_stats_write(struct file *file,
954 const char __user *user_buf,
955 size_t user_len, loff_t *pos)
959 struct seq_file *m = (struct seq_file *)file->private_data;
960 struct dasd_profile *prof = m->private;
962 if (user_len > 65536)
964 buffer = dasd_get_user_string(user_buf, user_len);
966 return PTR_ERR(buffer);
968 str = skip_spaces(buffer);
970 if (strncmp(str, "reset", 5) == 0) {
971 dasd_profile_reset(prof);
972 } else if (strncmp(str, "on", 2) == 0) {
973 rc = dasd_profile_on(prof);
977 if (prof == &dasd_global_profile) {
978 dasd_profile_reset(prof);
979 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
981 } else if (strncmp(str, "off", 3) == 0) {
982 if (prof == &dasd_global_profile)
983 dasd_global_profile_level = DASD_PROFILE_OFF;
984 dasd_profile_off(prof);
992 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
996 for (i = 0; i < 32; i++)
997 seq_printf(m, "%u ", array[i]);
1001 static void dasd_stats_seq_print(struct seq_file *m,
1002 struct dasd_profile_info *data)
1004 seq_printf(m, "start_time %ld.%09ld\n",
1005 data->starttod.tv_sec, data->starttod.tv_nsec);
1006 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
1007 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
1008 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
1009 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
1010 seq_printf(m, "avg_total %lu\n", data->dasd_io_reqs ?
1011 data->dasd_sum_times / data->dasd_io_reqs : 0UL);
1012 seq_printf(m, "avg_build_to_ssch %lu\n", data->dasd_io_reqs ?
1013 data->dasd_sum_time_str / data->dasd_io_reqs : 0UL);
1014 seq_printf(m, "avg_ssch_to_irq %lu\n", data->dasd_io_reqs ?
1015 data->dasd_sum_time_irq / data->dasd_io_reqs : 0UL);
1016 seq_printf(m, "avg_irq_to_end %lu\n", data->dasd_io_reqs ?
1017 data->dasd_sum_time_end / data->dasd_io_reqs : 0UL);
1018 seq_puts(m, "histogram_sectors ");
1019 dasd_stats_array(m, data->dasd_io_secs);
1020 seq_puts(m, "histogram_io_times ");
1021 dasd_stats_array(m, data->dasd_io_times);
1022 seq_puts(m, "histogram_io_times_weighted ");
1023 dasd_stats_array(m, data->dasd_io_timps);
1024 seq_puts(m, "histogram_time_build_to_ssch ");
1025 dasd_stats_array(m, data->dasd_io_time1);
1026 seq_puts(m, "histogram_time_ssch_to_irq ");
1027 dasd_stats_array(m, data->dasd_io_time2);
1028 seq_puts(m, "histogram_time_ssch_to_irq_weighted ");
1029 dasd_stats_array(m, data->dasd_io_time2ps);
1030 seq_puts(m, "histogram_time_irq_to_end ");
1031 dasd_stats_array(m, data->dasd_io_time3);
1032 seq_puts(m, "histogram_ccw_queue_length ");
1033 dasd_stats_array(m, data->dasd_io_nr_req);
1034 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
1035 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
1036 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
1037 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
1038 seq_puts(m, "histogram_read_sectors ");
1039 dasd_stats_array(m, data->dasd_read_secs);
1040 seq_puts(m, "histogram_read_times ");
1041 dasd_stats_array(m, data->dasd_read_times);
1042 seq_puts(m, "histogram_read_time_build_to_ssch ");
1043 dasd_stats_array(m, data->dasd_read_time1);
1044 seq_puts(m, "histogram_read_time_ssch_to_irq ");
1045 dasd_stats_array(m, data->dasd_read_time2);
1046 seq_puts(m, "histogram_read_time_irq_to_end ");
1047 dasd_stats_array(m, data->dasd_read_time3);
1048 seq_puts(m, "histogram_read_ccw_queue_length ");
1049 dasd_stats_array(m, data->dasd_read_nr_req);
1052 static int dasd_stats_show(struct seq_file *m, void *v)
1054 struct dasd_profile *profile;
1055 struct dasd_profile_info *data;
1057 profile = m->private;
1058 spin_lock_bh(&profile->lock);
1059 data = profile->data;
1061 spin_unlock_bh(&profile->lock);
1062 seq_puts(m, "disabled\n");
1065 dasd_stats_seq_print(m, data);
1066 spin_unlock_bh(&profile->lock);
1070 static int dasd_stats_open(struct inode *inode, struct file *file)
1072 struct dasd_profile *profile = inode->i_private;
1073 return single_open(file, dasd_stats_show, profile);
1076 static const struct file_operations dasd_stats_raw_fops = {
1077 .owner = THIS_MODULE,
1078 .open = dasd_stats_open,
1080 .llseek = seq_lseek,
1081 .release = single_release,
1082 .write = dasd_stats_write,
1085 static void dasd_profile_init(struct dasd_profile *profile,
1086 struct dentry *base_dentry)
1093 profile->dentry = NULL;
1094 profile->data = NULL;
1095 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1096 pde = debugfs_create_file("statistics", mode, base_dentry,
1097 profile, &dasd_stats_raw_fops);
1098 if (pde && !IS_ERR(pde))
1099 profile->dentry = pde;
1103 static void dasd_profile_exit(struct dasd_profile *profile)
1105 dasd_profile_off(profile);
1106 debugfs_remove(profile->dentry);
1107 profile->dentry = NULL;
1110 static void dasd_statistics_removeroot(void)
1112 dasd_global_profile_level = DASD_PROFILE_OFF;
1113 dasd_profile_exit(&dasd_global_profile);
1114 debugfs_remove(dasd_debugfs_global_entry);
1115 debugfs_remove(dasd_debugfs_root_entry);
1118 static void dasd_statistics_createroot(void)
1122 dasd_debugfs_root_entry = NULL;
1123 pde = debugfs_create_dir("dasd", NULL);
1124 if (!pde || IS_ERR(pde))
1126 dasd_debugfs_root_entry = pde;
1127 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1128 if (!pde || IS_ERR(pde))
1130 dasd_debugfs_global_entry = pde;
1131 dasd_profile_init(&dasd_global_profile, dasd_debugfs_global_entry);
1135 DBF_EVENT(DBF_ERR, "%s",
1136 "Creation of the dasd debugfs interface failed");
1137 dasd_statistics_removeroot();
1142 #define dasd_profile_start(block, cqr, req) do {} while (0)
1143 #define dasd_profile_end(block, cqr, req) do {} while (0)
1145 static void dasd_statistics_createroot(void)
1150 static void dasd_statistics_removeroot(void)
1155 int dasd_stats_generic_show(struct seq_file *m, void *v)
1157 seq_puts(m, "Statistics are not activated in this kernel\n");
1161 static void dasd_profile_init(struct dasd_profile *profile,
1162 struct dentry *base_dentry)
1167 static void dasd_profile_exit(struct dasd_profile *profile)
1172 int dasd_profile_on(struct dasd_profile *profile)
1177 #endif /* CONFIG_DASD_PROFILE */
1179 static int dasd_hosts_show(struct seq_file *m, void *v)
1181 struct dasd_device *device;
1182 int rc = -EOPNOTSUPP;
1184 device = m->private;
1185 dasd_get_device(device);
1187 if (device->discipline->hosts_print)
1188 rc = device->discipline->hosts_print(device, m);
1190 dasd_put_device(device);
1194 static int dasd_hosts_open(struct inode *inode, struct file *file)
1196 struct dasd_device *device = inode->i_private;
1198 return single_open(file, dasd_hosts_show, device);
1201 static const struct file_operations dasd_hosts_fops = {
1202 .owner = THIS_MODULE,
1203 .open = dasd_hosts_open,
1205 .llseek = seq_lseek,
1206 .release = single_release,
1209 static void dasd_hosts_exit(struct dasd_device *device)
1211 debugfs_remove(device->hosts_dentry);
1212 device->hosts_dentry = NULL;
1215 static void dasd_hosts_init(struct dentry *base_dentry,
1216 struct dasd_device *device)
1224 mode = S_IRUSR | S_IFREG;
1225 pde = debugfs_create_file("host_access_list", mode, base_dentry,
1226 device, &dasd_hosts_fops);
1227 if (pde && !IS_ERR(pde))
1228 device->hosts_dentry = pde;
1232 * Allocate memory for a channel program with 'cplength' channel
1233 * command words and 'datasize' additional space. There are two
1234 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1235 * memory and 2) dasd_smalloc_request uses the static ccw memory
1236 * that gets allocated for each device.
1238 struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength,
1240 struct dasd_device *device)
1242 struct dasd_ccw_req *cqr;
1245 BUG_ON(datasize > PAGE_SIZE ||
1246 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
1248 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
1250 return ERR_PTR(-ENOMEM);
1253 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
1254 GFP_ATOMIC | GFP_DMA);
1255 if (cqr->cpaddr == NULL) {
1257 return ERR_PTR(-ENOMEM);
1262 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
1263 if (cqr->data == NULL) {
1266 return ERR_PTR(-ENOMEM);
1270 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1271 dasd_get_device(device);
1274 EXPORT_SYMBOL(dasd_kmalloc_request);
1276 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength,
1278 struct dasd_device *device)
1280 unsigned long flags;
1281 struct dasd_ccw_req *cqr;
1285 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
1287 size += cplength * sizeof(struct ccw1);
1290 spin_lock_irqsave(&device->mem_lock, flags);
1291 cqr = (struct dasd_ccw_req *)
1292 dasd_alloc_chunk(&device->ccw_chunks, size);
1293 spin_unlock_irqrestore(&device->mem_lock, flags);
1295 return ERR_PTR(-ENOMEM);
1296 memset(cqr, 0, sizeof(struct dasd_ccw_req));
1297 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
1300 cqr->cpaddr = (struct ccw1 *) data;
1301 data += cplength*sizeof(struct ccw1);
1302 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
1307 memset(cqr->data, 0, datasize);
1310 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1311 dasd_get_device(device);
1314 EXPORT_SYMBOL(dasd_smalloc_request);
1317 * Free memory of a channel program. This function needs to free all the
1318 * idal lists that might have been created by dasd_set_cda and the
1319 * struct dasd_ccw_req itself.
1321 void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1325 /* Clear any idals used for the request. */
1328 clear_normalized_cda(ccw);
1329 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
1333 dasd_put_device(device);
1335 EXPORT_SYMBOL(dasd_kfree_request);
1337 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1339 unsigned long flags;
1341 spin_lock_irqsave(&device->mem_lock, flags);
1342 dasd_free_chunk(&device->ccw_chunks, cqr);
1343 spin_unlock_irqrestore(&device->mem_lock, flags);
1344 dasd_put_device(device);
1346 EXPORT_SYMBOL(dasd_sfree_request);
1349 * Check discipline magic in cqr.
1351 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1353 struct dasd_device *device;
1357 device = cqr->startdev;
1358 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1359 DBF_DEV_EVENT(DBF_WARNING, device,
1360 " dasd_ccw_req 0x%08x magic doesn't match"
1361 " discipline 0x%08x",
1363 *(unsigned int *) device->discipline->name);
1370 * Terminate the current i/o and set the request to clear_pending.
1371 * Timer keeps device runnig.
1372 * ccw_device_clear can fail if the i/o subsystem
1375 int dasd_term_IO(struct dasd_ccw_req *cqr)
1377 struct dasd_device *device;
1379 char errorstring[ERRORLENGTH];
1382 rc = dasd_check_cqr(cqr);
1386 device = (struct dasd_device *) cqr->startdev;
1387 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1388 rc = ccw_device_clear(device->cdev, (long) cqr);
1390 case 0: /* termination successful */
1391 cqr->status = DASD_CQR_CLEAR_PENDING;
1392 cqr->stopclk = get_tod_clock();
1394 DBF_DEV_EVENT(DBF_DEBUG, device,
1395 "terminate cqr %p successful",
1399 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1400 "device gone, retry");
1403 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1404 "I/O error, retry");
1408 * device not valid so no I/O could be running
1409 * handle CQR as termination successful
1411 cqr->status = DASD_CQR_CLEARED;
1412 cqr->stopclk = get_tod_clock();
1414 /* no retries for invalid devices */
1416 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1417 "EINVAL, handle as terminated");
1418 /* fake rc to success */
1422 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1423 "device busy, retry later");
1426 /* internal error 10 - unknown rc*/
1427 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1428 dev_err(&device->cdev->dev, "An error occurred in the "
1429 "DASD device driver, reason=%s\n", errorstring);
1435 dasd_schedule_device_bh(device);
1438 EXPORT_SYMBOL(dasd_term_IO);
1441 * Start the i/o. This start_IO can fail if the channel is really busy.
1442 * In that case set up a timer to start the request later.
1444 int dasd_start_IO(struct dasd_ccw_req *cqr)
1446 struct dasd_device *device;
1448 char errorstring[ERRORLENGTH];
1451 rc = dasd_check_cqr(cqr);
1456 device = (struct dasd_device *) cqr->startdev;
1458 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1459 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1460 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1461 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1462 "because of stolen lock", cqr);
1463 cqr->status = DASD_CQR_ERROR;
1464 cqr->intrc = -EPERM;
1467 if (cqr->retries < 0) {
1468 /* internal error 14 - start_IO run out of retries */
1469 sprintf(errorstring, "14 %p", cqr);
1470 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1471 "device driver, reason=%s\n", errorstring);
1472 cqr->status = DASD_CQR_ERROR;
1475 cqr->startclk = get_tod_clock();
1476 cqr->starttime = jiffies;
1478 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1479 cqr->lpm &= dasd_path_get_opm(device);
1481 cqr->lpm = dasd_path_get_opm(device);
1483 if (cqr->cpmode == 1) {
1484 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1485 (long) cqr, cqr->lpm);
1487 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1488 (long) cqr, cqr->lpm, 0);
1492 cqr->status = DASD_CQR_IN_IO;
1495 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1496 "start_IO: device busy, retry later");
1499 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1500 "start_IO: request timeout, retry later");
1503 /* -EACCES indicates that the request used only a subset of the
1504 * available paths and all these paths are gone. If the lpm of
1505 * this request was only a subset of the opm (e.g. the ppm) then
1506 * we just do a retry with all available paths.
1507 * If we already use the full opm, something is amiss, and we
1508 * need a full path verification.
1510 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1511 DBF_DEV_EVENT(DBF_WARNING, device,
1512 "start_IO: selected paths gone (%x)",
1514 } else if (cqr->lpm != dasd_path_get_opm(device)) {
1515 cqr->lpm = dasd_path_get_opm(device);
1516 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1517 "start_IO: selected paths gone,"
1518 " retry on all paths");
1520 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1521 "start_IO: all paths in opm gone,"
1522 " do path verification");
1523 dasd_generic_last_path_gone(device);
1524 dasd_path_no_path(device);
1525 dasd_path_set_tbvpm(device,
1526 ccw_device_get_path_mask(
1531 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1532 "start_IO: -ENODEV device gone, retry");
1535 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1536 "start_IO: -EIO device gone, retry");
1539 /* most likely caused in power management context */
1540 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1541 "start_IO: -EINVAL device currently "
1545 /* internal error 11 - unknown rc */
1546 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1547 dev_err(&device->cdev->dev,
1548 "An error occurred in the DASD device driver, "
1549 "reason=%s\n", errorstring);
1556 EXPORT_SYMBOL(dasd_start_IO);
1559 * Timeout function for dasd devices. This is used for different purposes
1560 * 1) missing interrupt handler for normal operation
1561 * 2) delayed start of request where start_IO failed with -EBUSY
1562 * 3) timeout for missing state change interrupts
1563 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1564 * DASD_CQR_QUEUED for 2) and 3).
1566 static void dasd_device_timeout(unsigned long ptr)
1568 unsigned long flags;
1569 struct dasd_device *device;
1571 device = (struct dasd_device *) ptr;
1572 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1573 /* re-activate request queue */
1574 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1575 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1576 dasd_schedule_device_bh(device);
1580 * Setup timeout for a device in jiffies.
1582 void dasd_device_set_timer(struct dasd_device *device, int expires)
1585 del_timer(&device->timer);
1587 mod_timer(&device->timer, jiffies + expires);
1589 EXPORT_SYMBOL(dasd_device_set_timer);
1592 * Clear timeout for a device.
1594 void dasd_device_clear_timer(struct dasd_device *device)
1596 del_timer(&device->timer);
1598 EXPORT_SYMBOL(dasd_device_clear_timer);
1600 static void dasd_handle_killed_request(struct ccw_device *cdev,
1601 unsigned long intparm)
1603 struct dasd_ccw_req *cqr;
1604 struct dasd_device *device;
1608 cqr = (struct dasd_ccw_req *) intparm;
1609 if (cqr->status != DASD_CQR_IN_IO) {
1610 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1611 "invalid status in handle_killed_request: "
1612 "%02x", cqr->status);
1616 device = dasd_device_from_cdev_locked(cdev);
1617 if (IS_ERR(device)) {
1618 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1619 "unable to get device from cdev");
1623 if (!cqr->startdev ||
1624 device != cqr->startdev ||
1625 strncmp(cqr->startdev->discipline->ebcname,
1626 (char *) &cqr->magic, 4)) {
1627 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1628 "invalid device in request");
1629 dasd_put_device(device);
1633 /* Schedule request to be retried. */
1634 cqr->status = DASD_CQR_QUEUED;
1636 dasd_device_clear_timer(device);
1637 dasd_schedule_device_bh(device);
1638 dasd_put_device(device);
1641 void dasd_generic_handle_state_change(struct dasd_device *device)
1643 /* First of all start sense subsystem status request. */
1644 dasd_eer_snss(device);
1646 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1647 dasd_schedule_device_bh(device);
1649 dasd_schedule_block_bh(device->block);
1651 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
1653 static int dasd_check_hpf_error(struct irb *irb)
1655 return (scsw_tm_is_valid_schxs(&irb->scsw) &&
1656 (irb->scsw.tm.sesq == SCSW_SESQ_DEV_NOFCX ||
1657 irb->scsw.tm.sesq == SCSW_SESQ_PATH_NOFCX));
1661 * Interrupt handler for "normal" ssch-io based dasd devices.
1663 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1666 struct dasd_ccw_req *cqr, *next;
1667 struct dasd_device *device;
1669 int nrf_suppressed = 0;
1670 int fp_suppressed = 0;
1674 cqr = (struct dasd_ccw_req *) intparm;
1676 switch (PTR_ERR(irb)) {
1678 if (cqr && cqr->status == DASD_CQR_CLEAR_PENDING) {
1679 device = cqr->startdev;
1680 cqr->status = DASD_CQR_CLEARED;
1681 dasd_device_clear_timer(device);
1682 wake_up(&dasd_flush_wq);
1683 dasd_schedule_device_bh(device);
1688 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1689 "request timed out\n", __func__);
1692 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1693 "unknown error %ld\n", __func__,
1696 dasd_handle_killed_request(cdev, intparm);
1700 now = get_tod_clock();
1701 /* check for conditions that should be handled immediately */
1703 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1704 scsw_cstat(&irb->scsw) == 0)) {
1706 memcpy(&cqr->irb, irb, sizeof(*irb));
1707 device = dasd_device_from_cdev_locked(cdev);
1710 /* ignore unsolicited interrupts for DIAG discipline */
1711 if (device->discipline == dasd_diag_discipline_pointer) {
1712 dasd_put_device(device);
1717 * In some cases 'File Protected' or 'No Record Found' errors
1718 * might be expected and debug log messages for the
1719 * corresponding interrupts shouldn't be written then.
1720 * Check if either of the according suppress bits is set.
1722 sense = dasd_get_sense(irb);
1724 fp_suppressed = (sense[1] & SNS1_FILE_PROTECTED) &&
1725 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
1726 nrf_suppressed = (sense[1] & SNS1_NO_REC_FOUND) &&
1727 test_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
1729 if (!(fp_suppressed || nrf_suppressed))
1730 device->discipline->dump_sense_dbf(device, irb, "int");
1732 if (device->features & DASD_FEATURE_ERPLOG)
1733 device->discipline->dump_sense(device, cqr, irb);
1734 device->discipline->check_for_device_change(device, cqr, irb);
1735 dasd_put_device(device);
1738 /* check for for attention message */
1739 if (scsw_dstat(&irb->scsw) & DEV_STAT_ATTENTION) {
1740 device = dasd_device_from_cdev_locked(cdev);
1741 if (!IS_ERR(device)) {
1742 device->discipline->check_attention(device,
1743 irb->esw.esw1.lpum);
1744 dasd_put_device(device);
1751 device = (struct dasd_device *) cqr->startdev;
1753 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1754 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1755 "invalid device in request");
1759 /* Check for clear pending */
1760 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1761 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1762 cqr->status = DASD_CQR_CLEARED;
1763 dasd_device_clear_timer(device);
1764 wake_up(&dasd_flush_wq);
1765 dasd_schedule_device_bh(device);
1769 /* check status - the request might have been killed by dyn detach */
1770 if (cqr->status != DASD_CQR_IN_IO) {
1771 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1772 "status %02x", dev_name(&cdev->dev), cqr->status);
1778 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1779 scsw_cstat(&irb->scsw) == 0) {
1780 /* request was completed successfully */
1781 cqr->status = DASD_CQR_SUCCESS;
1783 /* Start first request on queue if possible -> fast_io. */
1784 if (cqr->devlist.next != &device->ccw_queue) {
1785 next = list_entry(cqr->devlist.next,
1786 struct dasd_ccw_req, devlist);
1788 } else { /* error */
1789 /* check for HPF error
1790 * call discipline function to requeue all requests
1791 * and disable HPF accordingly
1793 if (cqr->cpmode && dasd_check_hpf_error(irb) &&
1794 device->discipline->handle_hpf_error)
1795 device->discipline->handle_hpf_error(device, irb);
1797 * If we don't want complex ERP for this request, then just
1798 * reset this and retry it in the fastpath
1800 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1802 if (cqr->lpm == dasd_path_get_opm(device))
1803 DBF_DEV_EVENT(DBF_DEBUG, device,
1804 "default ERP in fastpath "
1805 "(%i retries left)",
1807 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1808 cqr->lpm = dasd_path_get_opm(device);
1809 cqr->status = DASD_CQR_QUEUED;
1812 cqr->status = DASD_CQR_ERROR;
1814 if (next && (next->status == DASD_CQR_QUEUED) &&
1815 (!device->stopped)) {
1816 if (device->discipline->start_IO(next) == 0)
1817 expires = next->expires;
1820 dasd_device_set_timer(device, expires);
1822 dasd_device_clear_timer(device);
1823 dasd_schedule_device_bh(device);
1825 EXPORT_SYMBOL(dasd_int_handler);
1827 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1829 struct dasd_device *device;
1831 device = dasd_device_from_cdev_locked(cdev);
1835 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1836 device->state != device->target ||
1837 !device->discipline->check_for_device_change){
1838 dasd_put_device(device);
1841 if (device->discipline->dump_sense_dbf)
1842 device->discipline->dump_sense_dbf(device, irb, "uc");
1843 device->discipline->check_for_device_change(device, NULL, irb);
1844 dasd_put_device(device);
1846 return UC_TODO_RETRY;
1848 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1851 * If we have an error on a dasd_block layer request then we cancel
1852 * and return all further requests from the same dasd_block as well.
1854 static void __dasd_device_recovery(struct dasd_device *device,
1855 struct dasd_ccw_req *ref_cqr)
1857 struct list_head *l, *n;
1858 struct dasd_ccw_req *cqr;
1861 * only requeue request that came from the dasd_block layer
1863 if (!ref_cqr->block)
1866 list_for_each_safe(l, n, &device->ccw_queue) {
1867 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1868 if (cqr->status == DASD_CQR_QUEUED &&
1869 ref_cqr->block == cqr->block) {
1870 cqr->status = DASD_CQR_CLEARED;
1876 * Remove those ccw requests from the queue that need to be returned
1877 * to the upper layer.
1879 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1880 struct list_head *final_queue)
1882 struct list_head *l, *n;
1883 struct dasd_ccw_req *cqr;
1885 /* Process request with final status. */
1886 list_for_each_safe(l, n, &device->ccw_queue) {
1887 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1889 /* Skip any non-final request. */
1890 if (cqr->status == DASD_CQR_QUEUED ||
1891 cqr->status == DASD_CQR_IN_IO ||
1892 cqr->status == DASD_CQR_CLEAR_PENDING)
1894 if (cqr->status == DASD_CQR_ERROR) {
1895 __dasd_device_recovery(device, cqr);
1897 /* Rechain finished requests to final queue */
1898 list_move_tail(&cqr->devlist, final_queue);
1903 * the cqrs from the final queue are returned to the upper layer
1904 * by setting a dasd_block state and calling the callback function
1906 static void __dasd_device_process_final_queue(struct dasd_device *device,
1907 struct list_head *final_queue)
1909 struct list_head *l, *n;
1910 struct dasd_ccw_req *cqr;
1911 struct dasd_block *block;
1912 void (*callback)(struct dasd_ccw_req *, void *data);
1913 void *callback_data;
1914 char errorstring[ERRORLENGTH];
1916 list_for_each_safe(l, n, final_queue) {
1917 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1918 list_del_init(&cqr->devlist);
1920 callback = cqr->callback;
1921 callback_data = cqr->callback_data;
1923 spin_lock_bh(&block->queue_lock);
1924 switch (cqr->status) {
1925 case DASD_CQR_SUCCESS:
1926 cqr->status = DASD_CQR_DONE;
1928 case DASD_CQR_ERROR:
1929 cqr->status = DASD_CQR_NEED_ERP;
1931 case DASD_CQR_CLEARED:
1932 cqr->status = DASD_CQR_TERMINATED;
1935 /* internal error 12 - wrong cqr status*/
1936 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1937 dev_err(&device->cdev->dev,
1938 "An error occurred in the DASD device driver, "
1939 "reason=%s\n", errorstring);
1942 if (cqr->callback != NULL)
1943 (callback)(cqr, callback_data);
1945 spin_unlock_bh(&block->queue_lock);
1950 * Take a look at the first request on the ccw queue and check
1951 * if it reached its expire time. If so, terminate the IO.
1953 static void __dasd_device_check_expire(struct dasd_device *device)
1955 struct dasd_ccw_req *cqr;
1957 if (list_empty(&device->ccw_queue))
1959 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1960 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1961 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1962 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1964 * IO in safe offline processing should not
1965 * run out of retries
1969 if (device->discipline->term_IO(cqr) != 0) {
1970 /* Hmpf, try again in 5 sec */
1971 dev_err(&device->cdev->dev,
1972 "cqr %p timed out (%lus) but cannot be "
1973 "ended, retrying in 5 s\n",
1974 cqr, (cqr->expires/HZ));
1975 cqr->expires += 5*HZ;
1976 dasd_device_set_timer(device, 5*HZ);
1978 dev_err(&device->cdev->dev,
1979 "cqr %p timed out (%lus), %i retries "
1980 "remaining\n", cqr, (cqr->expires/HZ),
1987 * return 1 when device is not eligible for IO
1989 static int __dasd_device_is_unusable(struct dasd_device *device,
1990 struct dasd_ccw_req *cqr)
1992 int mask = ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM);
1994 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
1995 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
1997 * dasd is being set offline
1998 * but it is no safe offline where we have to allow I/O
2002 if (device->stopped) {
2003 if (device->stopped & mask) {
2004 /* stopped and CQR will not change that. */
2007 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2008 /* CQR is not able to change device to
2012 /* CQR required to get device operational. */
2018 * Take a look at the first request on the ccw queue and check
2019 * if it needs to be started.
2021 static void __dasd_device_start_head(struct dasd_device *device)
2023 struct dasd_ccw_req *cqr;
2026 if (list_empty(&device->ccw_queue))
2028 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2029 if (cqr->status != DASD_CQR_QUEUED)
2031 /* if device is not usable return request to upper layer */
2032 if (__dasd_device_is_unusable(device, cqr)) {
2033 cqr->intrc = -EAGAIN;
2034 cqr->status = DASD_CQR_CLEARED;
2035 dasd_schedule_device_bh(device);
2039 rc = device->discipline->start_IO(cqr);
2041 dasd_device_set_timer(device, cqr->expires);
2042 else if (rc == -EACCES) {
2043 dasd_schedule_device_bh(device);
2045 /* Hmpf, try again in 1/2 sec */
2046 dasd_device_set_timer(device, 50);
2049 static void __dasd_device_check_path_events(struct dasd_device *device)
2053 if (!dasd_path_get_tbvpm(device))
2056 if (device->stopped &
2057 ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM))
2059 rc = device->discipline->verify_path(device,
2060 dasd_path_get_tbvpm(device));
2062 dasd_device_set_timer(device, 50);
2064 dasd_path_clear_all_verify(device);
2068 * Go through all request on the dasd_device request queue,
2069 * terminate them on the cdev if necessary, and return them to the
2070 * submitting layer via callback.
2072 * Make sure that all 'submitting layers' still exist when
2073 * this function is called!. In other words, when 'device' is a base
2074 * device then all block layer requests must have been removed before
2075 * via dasd_flush_block_queue.
2077 int dasd_flush_device_queue(struct dasd_device *device)
2079 struct dasd_ccw_req *cqr, *n;
2081 struct list_head flush_queue;
2083 INIT_LIST_HEAD(&flush_queue);
2084 spin_lock_irq(get_ccwdev_lock(device->cdev));
2086 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
2087 /* Check status and move request to flush_queue */
2088 switch (cqr->status) {
2089 case DASD_CQR_IN_IO:
2090 rc = device->discipline->term_IO(cqr);
2092 /* unable to terminate requeust */
2093 dev_err(&device->cdev->dev,
2094 "Flushing the DASD request queue "
2095 "failed for request %p\n", cqr);
2096 /* stop flush processing */
2100 case DASD_CQR_QUEUED:
2101 cqr->stopclk = get_tod_clock();
2102 cqr->status = DASD_CQR_CLEARED;
2104 default: /* no need to modify the others */
2107 list_move_tail(&cqr->devlist, &flush_queue);
2110 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2112 * After this point all requests must be in state CLEAR_PENDING,
2113 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
2114 * one of the others.
2116 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
2117 wait_event(dasd_flush_wq,
2118 (cqr->status != DASD_CQR_CLEAR_PENDING));
2120 * Now set each request back to TERMINATED, DONE or NEED_ERP
2121 * and call the callback function of flushed requests
2123 __dasd_device_process_final_queue(device, &flush_queue);
2126 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
2129 * Acquire the device lock and process queues for the device.
2131 static void dasd_device_tasklet(struct dasd_device *device)
2133 struct list_head final_queue;
2135 atomic_set (&device->tasklet_scheduled, 0);
2136 INIT_LIST_HEAD(&final_queue);
2137 spin_lock_irq(get_ccwdev_lock(device->cdev));
2138 /* Check expire time of first request on the ccw queue. */
2139 __dasd_device_check_expire(device);
2140 /* find final requests on ccw queue */
2141 __dasd_device_process_ccw_queue(device, &final_queue);
2142 __dasd_device_check_path_events(device);
2143 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2144 /* Now call the callback function of requests with final status */
2145 __dasd_device_process_final_queue(device, &final_queue);
2146 spin_lock_irq(get_ccwdev_lock(device->cdev));
2147 /* Now check if the head of the ccw queue needs to be started. */
2148 __dasd_device_start_head(device);
2149 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2150 if (waitqueue_active(&shutdown_waitq))
2151 wake_up(&shutdown_waitq);
2152 dasd_put_device(device);
2156 * Schedules a call to dasd_tasklet over the device tasklet.
2158 void dasd_schedule_device_bh(struct dasd_device *device)
2160 /* Protect against rescheduling. */
2161 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2163 dasd_get_device(device);
2164 tasklet_hi_schedule(&device->tasklet);
2166 EXPORT_SYMBOL(dasd_schedule_device_bh);
2168 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2170 device->stopped |= bits;
2172 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2174 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2176 device->stopped &= ~bits;
2177 if (!device->stopped)
2178 wake_up(&generic_waitq);
2180 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2183 * Queue a request to the head of the device ccw_queue.
2184 * Start the I/O if possible.
2186 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2188 struct dasd_device *device;
2189 unsigned long flags;
2191 device = cqr->startdev;
2192 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2193 cqr->status = DASD_CQR_QUEUED;
2194 list_add(&cqr->devlist, &device->ccw_queue);
2195 /* let the bh start the request to keep them in order */
2196 dasd_schedule_device_bh(device);
2197 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2199 EXPORT_SYMBOL(dasd_add_request_head);
2202 * Queue a request to the tail of the device ccw_queue.
2203 * Start the I/O if possible.
2205 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2207 struct dasd_device *device;
2208 unsigned long flags;
2210 device = cqr->startdev;
2211 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2212 cqr->status = DASD_CQR_QUEUED;
2213 list_add_tail(&cqr->devlist, &device->ccw_queue);
2214 /* let the bh start the request to keep them in order */
2215 dasd_schedule_device_bh(device);
2216 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2218 EXPORT_SYMBOL(dasd_add_request_tail);
2221 * Wakeup helper for the 'sleep_on' functions.
2223 void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2225 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2226 cqr->callback_data = DASD_SLEEPON_END_TAG;
2227 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2228 wake_up(&generic_waitq);
2230 EXPORT_SYMBOL_GPL(dasd_wakeup_cb);
2232 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2234 struct dasd_device *device;
2237 device = cqr->startdev;
2238 spin_lock_irq(get_ccwdev_lock(device->cdev));
2239 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2240 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2245 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2247 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2249 struct dasd_device *device;
2250 dasd_erp_fn_t erp_fn;
2252 if (cqr->status == DASD_CQR_FILLED)
2254 device = cqr->startdev;
2255 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2256 if (cqr->status == DASD_CQR_TERMINATED) {
2257 device->discipline->handle_terminated_request(cqr);
2260 if (cqr->status == DASD_CQR_NEED_ERP) {
2261 erp_fn = device->discipline->erp_action(cqr);
2265 if (cqr->status == DASD_CQR_FAILED)
2266 dasd_log_sense(cqr, &cqr->irb);
2268 __dasd_process_erp(device, cqr);
2275 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2277 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2278 if (cqr->refers) /* erp is not done yet */
2280 return ((cqr->status != DASD_CQR_DONE) &&
2281 (cqr->status != DASD_CQR_FAILED));
2283 return (cqr->status == DASD_CQR_FILLED);
2286 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2288 struct dasd_device *device;
2290 struct list_head ccw_queue;
2291 struct dasd_ccw_req *cqr;
2293 INIT_LIST_HEAD(&ccw_queue);
2294 maincqr->status = DASD_CQR_FILLED;
2295 device = maincqr->startdev;
2296 list_add(&maincqr->blocklist, &ccw_queue);
2297 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2298 cqr = list_first_entry(&ccw_queue,
2299 struct dasd_ccw_req, blocklist)) {
2301 if (__dasd_sleep_on_erp(cqr))
2303 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2305 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2306 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2307 cqr->status = DASD_CQR_FAILED;
2308 cqr->intrc = -EPERM;
2311 /* Non-temporary stop condition will trigger fail fast */
2312 if (device->stopped & ~DASD_STOPPED_PENDING &&
2313 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2314 (!dasd_eer_enabled(device))) {
2315 cqr->status = DASD_CQR_FAILED;
2316 cqr->intrc = -ENOLINK;
2320 * Don't try to start requests if device is in
2321 * offline processing, it might wait forever
2323 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2324 cqr->status = DASD_CQR_FAILED;
2325 cqr->intrc = -ENODEV;
2329 * Don't try to start requests if device is stopped
2330 * except path verification requests
2332 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
2333 if (interruptible) {
2334 rc = wait_event_interruptible(
2335 generic_waitq, !(device->stopped));
2336 if (rc == -ERESTARTSYS) {
2337 cqr->status = DASD_CQR_FAILED;
2338 maincqr->intrc = rc;
2342 wait_event(generic_waitq, !(device->stopped));
2345 cqr->callback = dasd_wakeup_cb;
2347 cqr->callback_data = DASD_SLEEPON_START_TAG;
2348 dasd_add_request_tail(cqr);
2349 if (interruptible) {
2350 rc = wait_event_interruptible(
2351 generic_waitq, _wait_for_wakeup(cqr));
2352 if (rc == -ERESTARTSYS) {
2353 dasd_cancel_req(cqr);
2354 /* wait (non-interruptible) for final status */
2355 wait_event(generic_waitq,
2356 _wait_for_wakeup(cqr));
2357 cqr->status = DASD_CQR_FAILED;
2358 maincqr->intrc = rc;
2362 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2365 maincqr->endclk = get_tod_clock();
2366 if ((maincqr->status != DASD_CQR_DONE) &&
2367 (maincqr->intrc != -ERESTARTSYS))
2368 dasd_log_sense(maincqr, &maincqr->irb);
2369 if (maincqr->status == DASD_CQR_DONE)
2371 else if (maincqr->intrc)
2372 rc = maincqr->intrc;
2378 static inline int _wait_for_wakeup_queue(struct list_head *ccw_queue)
2380 struct dasd_ccw_req *cqr;
2382 list_for_each_entry(cqr, ccw_queue, blocklist) {
2383 if (cqr->callback_data != DASD_SLEEPON_END_TAG)
2390 static int _dasd_sleep_on_queue(struct list_head *ccw_queue, int interruptible)
2392 struct dasd_device *device;
2393 struct dasd_ccw_req *cqr, *n;
2398 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2399 device = cqr->startdev;
2400 if (cqr->status != DASD_CQR_FILLED) /*could be failed*/
2403 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2404 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2405 cqr->status = DASD_CQR_FAILED;
2406 cqr->intrc = -EPERM;
2409 /*Non-temporary stop condition will trigger fail fast*/
2410 if (device->stopped & ~DASD_STOPPED_PENDING &&
2411 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2412 !dasd_eer_enabled(device)) {
2413 cqr->status = DASD_CQR_FAILED;
2414 cqr->intrc = -EAGAIN;
2418 /*Don't try to start requests if device is stopped*/
2419 if (interruptible) {
2420 rc = wait_event_interruptible(
2421 generic_waitq, !device->stopped);
2422 if (rc == -ERESTARTSYS) {
2423 cqr->status = DASD_CQR_FAILED;
2428 wait_event(generic_waitq, !(device->stopped));
2431 cqr->callback = dasd_wakeup_cb;
2432 cqr->callback_data = DASD_SLEEPON_START_TAG;
2433 dasd_add_request_tail(cqr);
2436 wait_event(generic_waitq, _wait_for_wakeup_queue(ccw_queue));
2439 list_for_each_entry_safe(cqr, n, ccw_queue, blocklist) {
2441 * In some cases the 'File Protected' or 'Incorrect Length'
2442 * error might be expected and error recovery would be
2443 * unnecessary in these cases. Check if the according suppress
2446 sense = dasd_get_sense(&cqr->irb);
2447 if (sense && sense[1] & SNS1_FILE_PROTECTED &&
2448 test_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags))
2450 if (scsw_cstat(&cqr->irb.scsw) == 0x40 &&
2451 test_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags))
2455 * for alias devices simplify error recovery and
2456 * return to upper layer
2457 * do not skip ERP requests
2459 if (cqr->startdev != cqr->basedev && !cqr->refers &&
2460 (cqr->status == DASD_CQR_TERMINATED ||
2461 cqr->status == DASD_CQR_NEED_ERP))
2464 /* normal recovery for basedev IO */
2465 if (__dasd_sleep_on_erp(cqr))
2466 /* handle erp first */
2474 * Queue a request to the tail of the device ccw_queue and wait for
2477 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2479 return _dasd_sleep_on(cqr, 0);
2481 EXPORT_SYMBOL(dasd_sleep_on);
2484 * Start requests from a ccw_queue and wait for their completion.
2486 int dasd_sleep_on_queue(struct list_head *ccw_queue)
2488 return _dasd_sleep_on_queue(ccw_queue, 0);
2490 EXPORT_SYMBOL(dasd_sleep_on_queue);
2493 * Queue a request to the tail of the device ccw_queue and wait
2494 * interruptible for it's completion.
2496 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2498 return _dasd_sleep_on(cqr, 1);
2500 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2503 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2504 * for eckd devices) the currently running request has to be terminated
2505 * and be put back to status queued, before the special request is added
2506 * to the head of the queue. Then the special request is waited on normally.
2508 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2510 struct dasd_ccw_req *cqr;
2513 if (list_empty(&device->ccw_queue))
2515 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2516 rc = device->discipline->term_IO(cqr);
2519 * CQR terminated because a more important request is pending.
2520 * Undo decreasing of retry counter because this is
2521 * not an error case.
2527 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2529 struct dasd_device *device;
2532 device = cqr->startdev;
2533 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2534 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2535 cqr->status = DASD_CQR_FAILED;
2536 cqr->intrc = -EPERM;
2539 spin_lock_irq(get_ccwdev_lock(device->cdev));
2540 rc = _dasd_term_running_cqr(device);
2542 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2545 cqr->callback = dasd_wakeup_cb;
2546 cqr->callback_data = DASD_SLEEPON_START_TAG;
2547 cqr->status = DASD_CQR_QUEUED;
2549 * add new request as second
2550 * first the terminated cqr needs to be finished
2552 list_add(&cqr->devlist, device->ccw_queue.next);
2554 /* let the bh start the request to keep them in order */
2555 dasd_schedule_device_bh(device);
2557 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2559 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2561 if (cqr->status == DASD_CQR_DONE)
2563 else if (cqr->intrc)
2569 dasd_schedule_device_bh(device);
2571 dasd_schedule_block_bh(device->block);
2575 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2578 * Cancels a request that was started with dasd_sleep_on_req.
2579 * This is useful to timeout requests. The request will be
2580 * terminated if it is currently in i/o.
2581 * Returns 0 if request termination was successful
2582 * negative error code if termination failed
2583 * Cancellation of a request is an asynchronous operation! The calling
2584 * function has to wait until the request is properly returned via callback.
2586 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2588 struct dasd_device *device = cqr->startdev;
2589 unsigned long flags;
2593 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2594 switch (cqr->status) {
2595 case DASD_CQR_QUEUED:
2596 /* request was not started - just set to cleared */
2597 cqr->status = DASD_CQR_CLEARED;
2598 if (cqr->callback_data == DASD_SLEEPON_START_TAG)
2599 cqr->callback_data = DASD_SLEEPON_END_TAG;
2601 case DASD_CQR_IN_IO:
2602 /* request in IO - terminate IO and release again */
2603 rc = device->discipline->term_IO(cqr);
2605 dev_err(&device->cdev->dev,
2606 "Cancelling request %p failed with rc=%d\n",
2609 cqr->stopclk = get_tod_clock();
2612 default: /* already finished or clear pending - do nothing */
2615 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2616 dasd_schedule_device_bh(device);
2619 EXPORT_SYMBOL(dasd_cancel_req);
2622 * SECTION: Operations of the dasd_block layer.
2626 * Timeout function for dasd_block. This is used when the block layer
2627 * is waiting for something that may not come reliably, (e.g. a state
2630 static void dasd_block_timeout(unsigned long ptr)
2632 unsigned long flags;
2633 struct dasd_block *block;
2635 block = (struct dasd_block *) ptr;
2636 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2637 /* re-activate request queue */
2638 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2639 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2640 dasd_schedule_block_bh(block);
2644 * Setup timeout for a dasd_block in jiffies.
2646 void dasd_block_set_timer(struct dasd_block *block, int expires)
2649 del_timer(&block->timer);
2651 mod_timer(&block->timer, jiffies + expires);
2653 EXPORT_SYMBOL(dasd_block_set_timer);
2656 * Clear timeout for a dasd_block.
2658 void dasd_block_clear_timer(struct dasd_block *block)
2660 del_timer(&block->timer);
2662 EXPORT_SYMBOL(dasd_block_clear_timer);
2665 * Process finished error recovery ccw.
2667 static void __dasd_process_erp(struct dasd_device *device,
2668 struct dasd_ccw_req *cqr)
2670 dasd_erp_fn_t erp_fn;
2672 if (cqr->status == DASD_CQR_DONE)
2673 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2675 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2676 erp_fn = device->discipline->erp_postaction(cqr);
2681 * Fetch requests from the block device queue.
2683 static void __dasd_process_request_queue(struct dasd_block *block)
2685 struct request_queue *queue;
2686 struct request *req;
2687 struct dasd_ccw_req *cqr;
2688 struct dasd_device *basedev;
2689 unsigned long flags;
2690 queue = block->request_queue;
2691 basedev = block->base;
2692 /* No queue ? Then there is nothing to do. */
2697 * We requeue request from the block device queue to the ccw
2698 * queue only in two states. In state DASD_STATE_READY the
2699 * partition detection is done and we need to requeue requests
2700 * for that. State DASD_STATE_ONLINE is normal block device
2703 if (basedev->state < DASD_STATE_READY) {
2704 while ((req = blk_fetch_request(block->request_queue)))
2705 __blk_end_request_all(req, BLK_STS_IOERR);
2710 * if device is stopped do not fetch new requests
2711 * except failfast is active which will let requests fail
2712 * immediately in __dasd_block_start_head()
2714 if (basedev->stopped && !(basedev->features & DASD_FEATURE_FAILFAST))
2717 /* Now we try to fetch requests from the request queue */
2718 while ((req = blk_peek_request(queue))) {
2719 if (basedev->features & DASD_FEATURE_READONLY &&
2720 rq_data_dir(req) == WRITE) {
2721 DBF_DEV_EVENT(DBF_ERR, basedev,
2722 "Rejecting write request %p",
2724 blk_start_request(req);
2725 __blk_end_request_all(req, BLK_STS_IOERR);
2728 if (test_bit(DASD_FLAG_ABORTALL, &basedev->flags) &&
2729 (basedev->features & DASD_FEATURE_FAILFAST ||
2730 blk_noretry_request(req))) {
2731 DBF_DEV_EVENT(DBF_ERR, basedev,
2732 "Rejecting failfast request %p",
2734 blk_start_request(req);
2735 __blk_end_request_all(req, BLK_STS_TIMEOUT);
2738 cqr = basedev->discipline->build_cp(basedev, block, req);
2740 if (PTR_ERR(cqr) == -EBUSY)
2741 break; /* normal end condition */
2742 if (PTR_ERR(cqr) == -ENOMEM)
2743 break; /* terminate request queue loop */
2744 if (PTR_ERR(cqr) == -EAGAIN) {
2746 * The current request cannot be build right
2747 * now, we have to try later. If this request
2748 * is the head-of-queue we stop the device
2751 if (!list_empty(&block->ccw_queue))
2754 get_ccwdev_lock(basedev->cdev), flags);
2755 dasd_device_set_stop_bits(basedev,
2756 DASD_STOPPED_PENDING);
2757 spin_unlock_irqrestore(
2758 get_ccwdev_lock(basedev->cdev), flags);
2759 dasd_block_set_timer(block, HZ/2);
2762 DBF_DEV_EVENT(DBF_ERR, basedev,
2763 "CCW creation failed (rc=%ld) "
2766 blk_start_request(req);
2767 __blk_end_request_all(req, BLK_STS_IOERR);
2771 * Note: callback is set to dasd_return_cqr_cb in
2772 * __dasd_block_start_head to cover erp requests as well
2774 cqr->callback_data = (void *) req;
2775 cqr->status = DASD_CQR_FILLED;
2776 req->completion_data = cqr;
2777 blk_start_request(req);
2778 list_add_tail(&cqr->blocklist, &block->ccw_queue);
2779 INIT_LIST_HEAD(&cqr->devlist);
2780 dasd_profile_start(block, cqr, req);
2784 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2786 struct request *req;
2788 blk_status_t error = BLK_STS_OK;
2790 req = (struct request *) cqr->callback_data;
2791 dasd_profile_end(cqr->block, cqr, req);
2793 status = cqr->block->base->discipline->free_cp(cqr, req);
2795 error = errno_to_blk_status(status);
2796 else if (status == 0) {
2797 switch (cqr->intrc) {
2799 error = BLK_STS_NEXUS;
2802 error = BLK_STS_TRANSPORT;
2805 error = BLK_STS_TIMEOUT;
2808 error = BLK_STS_IOERR;
2812 __blk_end_request_all(req, error);
2816 * Process ccw request queue.
2818 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2819 struct list_head *final_queue)
2821 struct list_head *l, *n;
2822 struct dasd_ccw_req *cqr;
2823 dasd_erp_fn_t erp_fn;
2824 unsigned long flags;
2825 struct dasd_device *base = block->base;
2828 /* Process request with final status. */
2829 list_for_each_safe(l, n, &block->ccw_queue) {
2830 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2831 if (cqr->status != DASD_CQR_DONE &&
2832 cqr->status != DASD_CQR_FAILED &&
2833 cqr->status != DASD_CQR_NEED_ERP &&
2834 cqr->status != DASD_CQR_TERMINATED)
2837 if (cqr->status == DASD_CQR_TERMINATED) {
2838 base->discipline->handle_terminated_request(cqr);
2842 /* Process requests that may be recovered */
2843 if (cqr->status == DASD_CQR_NEED_ERP) {
2844 erp_fn = base->discipline->erp_action(cqr);
2845 if (IS_ERR(erp_fn(cqr)))
2850 /* log sense for fatal error */
2851 if (cqr->status == DASD_CQR_FAILED) {
2852 dasd_log_sense(cqr, &cqr->irb);
2855 /* First of all call extended error reporting. */
2856 if (dasd_eer_enabled(base) &&
2857 cqr->status == DASD_CQR_FAILED) {
2858 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2860 /* restart request */
2861 cqr->status = DASD_CQR_FILLED;
2863 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2864 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
2865 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2870 /* Process finished ERP request. */
2872 __dasd_process_erp(base, cqr);
2876 /* Rechain finished requests to final queue */
2877 cqr->endclk = get_tod_clock();
2878 list_move_tail(&cqr->blocklist, final_queue);
2882 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2884 dasd_schedule_block_bh(cqr->block);
2887 static void __dasd_block_start_head(struct dasd_block *block)
2889 struct dasd_ccw_req *cqr;
2891 if (list_empty(&block->ccw_queue))
2893 /* We allways begin with the first requests on the queue, as some
2894 * of previously started requests have to be enqueued on a
2895 * dasd_device again for error recovery.
2897 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2898 if (cqr->status != DASD_CQR_FILLED)
2900 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2901 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2902 cqr->status = DASD_CQR_FAILED;
2903 cqr->intrc = -EPERM;
2904 dasd_schedule_block_bh(block);
2907 /* Non-temporary stop condition will trigger fail fast */
2908 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2909 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2910 (!dasd_eer_enabled(block->base))) {
2911 cqr->status = DASD_CQR_FAILED;
2912 cqr->intrc = -ENOLINK;
2913 dasd_schedule_block_bh(block);
2916 /* Don't try to start requests if device is stopped */
2917 if (block->base->stopped)
2920 /* just a fail safe check, should not happen */
2922 cqr->startdev = block->base;
2924 /* make sure that the requests we submit find their way back */
2925 cqr->callback = dasd_return_cqr_cb;
2927 dasd_add_request_tail(cqr);
2932 * Central dasd_block layer routine. Takes requests from the generic
2933 * block layer request queue, creates ccw requests, enqueues them on
2934 * a dasd_device and processes ccw requests that have been returned.
2936 static void dasd_block_tasklet(struct dasd_block *block)
2938 struct list_head final_queue;
2939 struct list_head *l, *n;
2940 struct dasd_ccw_req *cqr;
2942 atomic_set(&block->tasklet_scheduled, 0);
2943 INIT_LIST_HEAD(&final_queue);
2944 spin_lock(&block->queue_lock);
2945 /* Finish off requests on ccw queue */
2946 __dasd_process_block_ccw_queue(block, &final_queue);
2947 spin_unlock(&block->queue_lock);
2948 /* Now call the callback function of requests with final status */
2949 spin_lock_irq(&block->request_queue_lock);
2950 list_for_each_safe(l, n, &final_queue) {
2951 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2952 list_del_init(&cqr->blocklist);
2953 __dasd_cleanup_cqr(cqr);
2955 spin_lock(&block->queue_lock);
2956 /* Get new request from the block device request queue */
2957 __dasd_process_request_queue(block);
2958 /* Now check if the head of the ccw queue needs to be started. */
2959 __dasd_block_start_head(block);
2960 spin_unlock(&block->queue_lock);
2961 spin_unlock_irq(&block->request_queue_lock);
2962 if (waitqueue_active(&shutdown_waitq))
2963 wake_up(&shutdown_waitq);
2964 dasd_put_device(block->base);
2967 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2969 wake_up(&dasd_flush_wq);
2973 * Requeue a request back to the block request queue
2974 * only works for block requests
2976 static int _dasd_requeue_request(struct dasd_ccw_req *cqr)
2978 struct dasd_block *block = cqr->block;
2979 struct request *req;
2980 unsigned long flags;
2984 spin_lock_irqsave(&block->request_queue_lock, flags);
2985 req = (struct request *) cqr->callback_data;
2986 blk_requeue_request(block->request_queue, req);
2987 spin_unlock_irqrestore(&block->request_queue_lock, flags);
2993 * Go through all request on the dasd_block request queue, cancel them
2994 * on the respective dasd_device, and return them to the generic
2997 static int dasd_flush_block_queue(struct dasd_block *block)
2999 struct dasd_ccw_req *cqr, *n;
3001 struct list_head flush_queue;
3003 INIT_LIST_HEAD(&flush_queue);
3004 spin_lock_bh(&block->queue_lock);
3007 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
3008 /* if this request currently owned by a dasd_device cancel it */
3009 if (cqr->status >= DASD_CQR_QUEUED)
3010 rc = dasd_cancel_req(cqr);
3013 /* Rechain request (including erp chain) so it won't be
3014 * touched by the dasd_block_tasklet anymore.
3015 * Replace the callback so we notice when the request
3016 * is returned from the dasd_device layer.
3018 cqr->callback = _dasd_wake_block_flush_cb;
3019 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
3020 list_move_tail(&cqr->blocklist, &flush_queue);
3022 /* moved more than one request - need to restart */
3025 spin_unlock_bh(&block->queue_lock);
3026 /* Now call the callback function of flushed requests */
3028 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
3029 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
3030 /* Process finished ERP request. */
3032 spin_lock_bh(&block->queue_lock);
3033 __dasd_process_erp(block->base, cqr);
3034 spin_unlock_bh(&block->queue_lock);
3035 /* restart list_for_xx loop since dasd_process_erp
3036 * might remove multiple elements */
3039 /* call the callback function */
3040 spin_lock_irq(&block->request_queue_lock);
3041 cqr->endclk = get_tod_clock();
3042 list_del_init(&cqr->blocklist);
3043 __dasd_cleanup_cqr(cqr);
3044 spin_unlock_irq(&block->request_queue_lock);
3050 * Schedules a call to dasd_tasklet over the device tasklet.
3052 void dasd_schedule_block_bh(struct dasd_block *block)
3054 /* Protect against rescheduling. */
3055 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
3057 /* life cycle of block is bound to it's base device */
3058 dasd_get_device(block->base);
3059 tasklet_hi_schedule(&block->tasklet);
3061 EXPORT_SYMBOL(dasd_schedule_block_bh);
3065 * SECTION: external block device operations
3066 * (request queue handling, open, release, etc.)
3070 * Dasd request queue function. Called from ll_rw_blk.c
3072 static void do_dasd_request(struct request_queue *queue)
3074 struct dasd_block *block;
3076 block = queue->queuedata;
3077 spin_lock(&block->queue_lock);
3078 /* Get new request from the block device request queue */
3079 __dasd_process_request_queue(block);
3080 /* Now check if the head of the ccw queue needs to be started. */
3081 __dasd_block_start_head(block);
3082 spin_unlock(&block->queue_lock);
3086 * Block timeout callback, called from the block layer
3088 * request_queue lock is held on entry.
3091 * BLK_EH_RESET_TIMER if the request should be left running
3092 * BLK_EH_NOT_HANDLED if the request is handled or terminated
3095 enum blk_eh_timer_return dasd_times_out(struct request *req)
3097 struct dasd_ccw_req *cqr = req->completion_data;
3098 struct dasd_block *block = req->q->queuedata;
3099 struct dasd_device *device;
3103 return BLK_EH_NOT_HANDLED;
3105 device = cqr->startdev ? cqr->startdev : block->base;
3106 if (!device->blk_timeout)
3107 return BLK_EH_RESET_TIMER;
3108 DBF_DEV_EVENT(DBF_WARNING, device,
3109 " dasd_times_out cqr %p status %x",
3112 spin_lock(&block->queue_lock);
3113 spin_lock(get_ccwdev_lock(device->cdev));
3115 cqr->intrc = -ETIMEDOUT;
3116 if (cqr->status >= DASD_CQR_QUEUED) {
3117 spin_unlock(get_ccwdev_lock(device->cdev));
3118 rc = dasd_cancel_req(cqr);
3119 } else if (cqr->status == DASD_CQR_FILLED ||
3120 cqr->status == DASD_CQR_NEED_ERP) {
3121 cqr->status = DASD_CQR_TERMINATED;
3122 spin_unlock(get_ccwdev_lock(device->cdev));
3123 } else if (cqr->status == DASD_CQR_IN_ERP) {
3124 struct dasd_ccw_req *searchcqr, *nextcqr, *tmpcqr;
3126 list_for_each_entry_safe(searchcqr, nextcqr,
3127 &block->ccw_queue, blocklist) {
3129 while (tmpcqr->refers)
3130 tmpcqr = tmpcqr->refers;
3133 /* searchcqr is an ERP request for cqr */
3134 searchcqr->retries = -1;
3135 searchcqr->intrc = -ETIMEDOUT;
3136 if (searchcqr->status >= DASD_CQR_QUEUED) {
3137 spin_unlock(get_ccwdev_lock(device->cdev));
3138 rc = dasd_cancel_req(searchcqr);
3139 spin_lock(get_ccwdev_lock(device->cdev));
3140 } else if ((searchcqr->status == DASD_CQR_FILLED) ||
3141 (searchcqr->status == DASD_CQR_NEED_ERP)) {
3142 searchcqr->status = DASD_CQR_TERMINATED;
3144 } else if (searchcqr->status == DASD_CQR_IN_ERP) {
3146 * Shouldn't happen; most recent ERP
3147 * request is at the front of queue
3153 spin_unlock(get_ccwdev_lock(device->cdev));
3155 dasd_schedule_block_bh(block);
3156 spin_unlock(&block->queue_lock);
3158 return rc ? BLK_EH_RESET_TIMER : BLK_EH_NOT_HANDLED;
3162 * Allocate and initialize request queue and default I/O scheduler.
3164 static int dasd_alloc_queue(struct dasd_block *block)
3166 block->request_queue = blk_init_queue(do_dasd_request,
3167 &block->request_queue_lock);
3168 if (block->request_queue == NULL)
3171 block->request_queue->queuedata = block;
3177 * Allocate and initialize request queue.
3179 static void dasd_setup_queue(struct dasd_block *block)
3181 unsigned int logical_block_size = block->bp_block;
3182 struct request_queue *q = block->request_queue;
3183 unsigned int max_bytes, max_discard_sectors;
3186 if (block->base->features & DASD_FEATURE_USERAW) {
3188 * the max_blocks value for raw_track access is 256
3189 * it is higher than the native ECKD value because we
3190 * only need one ccw per track
3191 * so the max_hw_sectors are
3192 * 2048 x 512B = 1024kB = 16 tracks
3196 max = block->base->discipline->max_blocks << block->s2b_shift;
3198 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
3199 q->limits.max_dev_sectors = max;
3200 blk_queue_logical_block_size(q, logical_block_size);
3201 blk_queue_max_hw_sectors(q, max);
3202 blk_queue_max_segments(q, USHRT_MAX);
3203 /* with page sized segments we can translate each segement into
3206 blk_queue_max_segment_size(q, PAGE_SIZE);
3207 blk_queue_segment_boundary(q, PAGE_SIZE - 1);
3209 /* Only activate blocklayer discard support for devices that support it */
3210 if (block->base->features & DASD_FEATURE_DISCARD) {
3211 q->limits.discard_granularity = logical_block_size;
3212 q->limits.discard_alignment = PAGE_SIZE;
3214 /* Calculate max_discard_sectors and make it PAGE aligned */
3215 max_bytes = USHRT_MAX * logical_block_size;
3216 max_bytes = ALIGN(max_bytes, PAGE_SIZE) - PAGE_SIZE;
3217 max_discard_sectors = max_bytes / logical_block_size;
3219 blk_queue_max_discard_sectors(q, max_discard_sectors);
3220 blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
3221 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
3226 * Deactivate and free request queue.
3228 static void dasd_free_queue(struct dasd_block *block)
3230 if (block->request_queue) {
3231 blk_cleanup_queue(block->request_queue);
3232 block->request_queue = NULL;
3237 * Flush request on the request queue.
3239 static void dasd_flush_request_queue(struct dasd_block *block)
3241 struct request *req;
3243 if (!block->request_queue)
3246 spin_lock_irq(&block->request_queue_lock);
3247 while ((req = blk_fetch_request(block->request_queue)))
3248 __blk_end_request_all(req, BLK_STS_IOERR);
3249 spin_unlock_irq(&block->request_queue_lock);
3252 static int dasd_open(struct block_device *bdev, fmode_t mode)
3254 struct dasd_device *base;
3257 base = dasd_device_from_gendisk(bdev->bd_disk);
3261 atomic_inc(&base->block->open_count);
3262 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
3267 if (!try_module_get(base->discipline->owner)) {
3272 if (dasd_probeonly) {
3273 dev_info(&base->cdev->dev,
3274 "Accessing the DASD failed because it is in "
3275 "probeonly mode\n");
3280 if (base->state <= DASD_STATE_BASIC) {
3281 DBF_DEV_EVENT(DBF_ERR, base, " %s",
3282 " Cannot open unrecognized device");
3287 if ((mode & FMODE_WRITE) &&
3288 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
3289 (base->features & DASD_FEATURE_READONLY))) {
3294 dasd_put_device(base);
3298 module_put(base->discipline->owner);
3300 atomic_dec(&base->block->open_count);
3301 dasd_put_device(base);
3305 static void dasd_release(struct gendisk *disk, fmode_t mode)
3307 struct dasd_device *base = dasd_device_from_gendisk(disk);
3309 atomic_dec(&base->block->open_count);
3310 module_put(base->discipline->owner);
3311 dasd_put_device(base);
3316 * Return disk geometry.
3318 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3320 struct dasd_device *base;
3322 base = dasd_device_from_gendisk(bdev->bd_disk);
3326 if (!base->discipline ||
3327 !base->discipline->fill_geometry) {
3328 dasd_put_device(base);
3331 base->discipline->fill_geometry(base->block, geo);
3332 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
3333 dasd_put_device(base);
3337 const struct block_device_operations
3338 dasd_device_operations = {
3339 .owner = THIS_MODULE,
3341 .release = dasd_release,
3342 .ioctl = dasd_ioctl,
3343 .compat_ioctl = dasd_ioctl,
3344 .getgeo = dasd_getgeo,
3347 /*******************************************************************************
3348 * end of block device operations
3354 #ifdef CONFIG_PROC_FS
3358 if (dasd_page_cache != NULL) {
3359 kmem_cache_destroy(dasd_page_cache);
3360 dasd_page_cache = NULL;
3362 dasd_gendisk_exit();
3364 if (dasd_debug_area != NULL) {
3365 debug_unregister(dasd_debug_area);
3366 dasd_debug_area = NULL;
3368 dasd_statistics_removeroot();
3372 * SECTION: common functions for ccw_driver use
3376 * Is the device read-only?
3377 * Note that this function does not report the setting of the
3378 * readonly device attribute, but how it is configured in z/VM.
3380 int dasd_device_is_ro(struct dasd_device *device)
3382 struct ccw_dev_id dev_id;
3383 struct diag210 diag_data;
3388 ccw_device_get_id(device->cdev, &dev_id);
3389 memset(&diag_data, 0, sizeof(diag_data));
3390 diag_data.vrdcdvno = dev_id.devno;
3391 diag_data.vrdclen = sizeof(diag_data);
3392 rc = diag210(&diag_data);
3393 if (rc == 0 || rc == 2) {
3394 return diag_data.vrdcvfla & 0x80;
3396 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
3401 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
3403 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
3405 struct ccw_device *cdev = data;
3408 ret = ccw_device_set_online(cdev);
3410 pr_warn("%s: Setting the DASD online failed with rc=%d\n",
3411 dev_name(&cdev->dev), ret);
3415 * Initial attempt at a probe function. this can be simplified once
3416 * the other detection code is gone.
3418 int dasd_generic_probe(struct ccw_device *cdev,
3419 struct dasd_discipline *discipline)
3423 ret = dasd_add_sysfs_files(cdev);
3425 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
3426 "dasd_generic_probe: could not add "
3430 cdev->handler = &dasd_int_handler;
3433 * Automatically online either all dasd devices (dasd_autodetect)
3434 * or all devices specified with dasd= parameters during
3437 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
3438 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
3439 async_schedule(dasd_generic_auto_online, cdev);
3442 EXPORT_SYMBOL_GPL(dasd_generic_probe);
3444 void dasd_generic_free_discipline(struct dasd_device *device)
3446 /* Forget the discipline information. */
3447 if (device->discipline) {
3448 if (device->discipline->uncheck_device)
3449 device->discipline->uncheck_device(device);
3450 module_put(device->discipline->owner);
3451 device->discipline = NULL;
3453 if (device->base_discipline) {
3454 module_put(device->base_discipline->owner);
3455 device->base_discipline = NULL;
3458 EXPORT_SYMBOL_GPL(dasd_generic_free_discipline);
3461 * This will one day be called from a global not_oper handler.
3462 * It is also used by driver_unregister during module unload.
3464 void dasd_generic_remove(struct ccw_device *cdev)
3466 struct dasd_device *device;
3467 struct dasd_block *block;
3469 cdev->handler = NULL;
3471 device = dasd_device_from_cdev(cdev);
3472 if (IS_ERR(device)) {
3473 dasd_remove_sysfs_files(cdev);
3476 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags) &&
3477 !test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3478 /* Already doing offline processing */
3479 dasd_put_device(device);
3480 dasd_remove_sysfs_files(cdev);
3484 * This device is removed unconditionally. Set offline
3485 * flag to prevent dasd_open from opening it while it is
3486 * no quite down yet.
3488 dasd_set_target_state(device, DASD_STATE_NEW);
3489 /* dasd_delete_device destroys the device reference. */
3490 block = device->block;
3491 dasd_delete_device(device);
3493 * life cycle of block is bound to device, so delete it after
3494 * device was safely removed
3497 dasd_free_block(block);
3499 dasd_remove_sysfs_files(cdev);
3501 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3504 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3505 * the device is detected for the first time and is supposed to be used
3506 * or the user has started activation through sysfs.
3508 int dasd_generic_set_online(struct ccw_device *cdev,
3509 struct dasd_discipline *base_discipline)
3511 struct dasd_discipline *discipline;
3512 struct dasd_device *device;
3515 /* first online clears initial online feature flag */
3516 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3517 device = dasd_create_device(cdev);
3519 return PTR_ERR(device);
3521 discipline = base_discipline;
3522 if (device->features & DASD_FEATURE_USEDIAG) {
3523 if (!dasd_diag_discipline_pointer) {
3524 /* Try to load the required module. */
3525 rc = request_module(DASD_DIAG_MOD);
3527 pr_warn("%s Setting the DASD online failed "
3528 "because the required module %s "
3529 "could not be loaded (rc=%d)\n",
3530 dev_name(&cdev->dev), DASD_DIAG_MOD,
3532 dasd_delete_device(device);
3536 /* Module init could have failed, so check again here after
3537 * request_module(). */
3538 if (!dasd_diag_discipline_pointer) {
3539 pr_warn("%s Setting the DASD online failed because of missing DIAG discipline\n",
3540 dev_name(&cdev->dev));
3541 dasd_delete_device(device);
3544 discipline = dasd_diag_discipline_pointer;
3546 if (!try_module_get(base_discipline->owner)) {
3547 dasd_delete_device(device);
3550 if (!try_module_get(discipline->owner)) {
3551 module_put(base_discipline->owner);
3552 dasd_delete_device(device);
3555 device->base_discipline = base_discipline;
3556 device->discipline = discipline;
3558 /* check_device will allocate block device if necessary */
3559 rc = discipline->check_device(device);
3561 pr_warn("%s Setting the DASD online with discipline %s failed with rc=%i\n",
3562 dev_name(&cdev->dev), discipline->name, rc);
3563 module_put(discipline->owner);
3564 module_put(base_discipline->owner);
3565 dasd_delete_device(device);
3569 dasd_set_target_state(device, DASD_STATE_ONLINE);
3570 if (device->state <= DASD_STATE_KNOWN) {
3571 pr_warn("%s Setting the DASD online failed because of a missing discipline\n",
3572 dev_name(&cdev->dev));
3574 dasd_set_target_state(device, DASD_STATE_NEW);
3576 dasd_free_block(device->block);
3577 dasd_delete_device(device);
3579 pr_debug("dasd_generic device %s found\n",
3580 dev_name(&cdev->dev));
3582 wait_event(dasd_init_waitq, _wait_for_device(device));
3584 dasd_put_device(device);
3587 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3589 int dasd_generic_set_offline(struct ccw_device *cdev)
3591 struct dasd_device *device;
3592 struct dasd_block *block;
3593 int max_count, open_count, rc;
3594 unsigned long flags;
3597 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3598 device = dasd_device_from_cdev_locked(cdev);
3599 if (IS_ERR(device)) {
3600 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3601 return PTR_ERR(device);
3605 * We must make sure that this device is currently not in use.
3606 * The open_count is increased for every opener, that includes
3607 * the blkdev_get in dasd_scan_partitions. We are only interested
3608 * in the other openers.
3610 if (device->block) {
3611 max_count = device->block->bdev ? 0 : -1;
3612 open_count = atomic_read(&device->block->open_count);
3613 if (open_count > max_count) {
3615 pr_warn("%s: The DASD cannot be set offline with open count %i\n",
3616 dev_name(&cdev->dev), open_count);
3618 pr_warn("%s: The DASD cannot be set offline while it is in use\n",
3619 dev_name(&cdev->dev));
3626 * Test if the offline processing is already running and exit if so.
3627 * If a safe offline is being processed this could only be a normal
3628 * offline that should be able to overtake the safe offline and
3629 * cancel any I/O we do not want to wait for any longer
3631 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3632 if (test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3633 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING,
3640 set_bit(DASD_FLAG_OFFLINE, &device->flags);
3643 * if safe_offline is called set safe_offline_running flag and
3644 * clear safe_offline so that a call to normal offline
3645 * can overrun safe_offline processing
3647 if (test_and_clear_bit(DASD_FLAG_SAFE_OFFLINE, &device->flags) &&
3648 !test_and_set_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3649 /* need to unlock here to wait for outstanding I/O */
3650 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3652 * If we want to set the device safe offline all IO operations
3653 * should be finished before continuing the offline process
3654 * so sync bdev first and then wait for our queues to become
3657 if (device->block) {
3658 rc = fsync_bdev(device->block->bdev);
3662 dasd_schedule_device_bh(device);
3663 rc = wait_event_interruptible(shutdown_waitq,
3664 _wait_for_empty_queues(device));
3669 * check if a normal offline process overtook the offline
3670 * processing in this case simply do nothing beside returning
3671 * that we got interrupted
3672 * otherwise mark safe offline as not running any longer and
3673 * continue with normal offline
3675 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3676 if (!test_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags)) {
3680 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3682 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3684 dasd_set_target_state(device, DASD_STATE_NEW);
3685 /* dasd_delete_device destroys the device reference. */
3686 block = device->block;
3687 dasd_delete_device(device);
3689 * life cycle of block is bound to device, so delete it after
3690 * device was safely removed
3693 dasd_free_block(block);
3698 /* interrupted by signal */
3699 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
3700 clear_bit(DASD_FLAG_SAFE_OFFLINE_RUNNING, &device->flags);
3701 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3703 dasd_put_device(device);
3704 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
3707 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3709 int dasd_generic_last_path_gone(struct dasd_device *device)
3711 struct dasd_ccw_req *cqr;
3713 dev_warn(&device->cdev->dev, "No operational channel path is left "
3714 "for the device\n");
3715 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3716 /* First of all call extended error reporting. */
3717 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3719 if (device->state < DASD_STATE_BASIC)
3721 /* Device is active. We want to keep it. */
3722 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3723 if ((cqr->status == DASD_CQR_IN_IO) ||
3724 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3725 cqr->status = DASD_CQR_QUEUED;
3728 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3729 dasd_device_clear_timer(device);
3730 dasd_schedule_device_bh(device);
3733 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3735 int dasd_generic_path_operational(struct dasd_device *device)
3737 dev_info(&device->cdev->dev, "A channel path to the device has become "
3739 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3740 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3741 if (device->stopped & DASD_UNRESUMED_PM) {
3742 dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
3743 dasd_restore_device(device);
3746 dasd_schedule_device_bh(device);
3748 dasd_schedule_block_bh(device->block);
3750 if (!device->stopped)
3751 wake_up(&generic_waitq);
3755 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3757 int dasd_generic_notify(struct ccw_device *cdev, int event)
3759 struct dasd_device *device;
3762 device = dasd_device_from_cdev_locked(cdev);
3770 dasd_path_no_path(device);
3771 ret = dasd_generic_last_path_gone(device);
3775 if (dasd_path_get_opm(device))
3776 ret = dasd_generic_path_operational(device);
3779 dasd_put_device(device);
3782 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3784 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3786 struct dasd_device *device;
3787 int chp, oldopm, hpfpm, ifccpm;
3789 device = dasd_device_from_cdev_locked(cdev);
3793 oldopm = dasd_path_get_opm(device);
3794 for (chp = 0; chp < 8; chp++) {
3795 if (path_event[chp] & PE_PATH_GONE) {
3796 dasd_path_notoper(device, chp);
3798 if (path_event[chp] & PE_PATH_AVAILABLE) {
3799 dasd_path_available(device, chp);
3800 dasd_schedule_device_bh(device);
3802 if (path_event[chp] & PE_PATHGROUP_ESTABLISHED) {
3803 if (!dasd_path_is_operational(device, chp) &&
3804 !dasd_path_need_verify(device, chp)) {
3806 * we can not establish a pathgroup on an
3807 * unavailable path, so trigger a path
3808 * verification first
3810 dasd_path_available(device, chp);
3811 dasd_schedule_device_bh(device);
3813 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
3814 "Pathgroup re-established\n");
3815 if (device->discipline->kick_validate)
3816 device->discipline->kick_validate(device);
3819 hpfpm = dasd_path_get_hpfpm(device);
3820 ifccpm = dasd_path_get_ifccpm(device);
3821 if (!dasd_path_get_opm(device) && hpfpm) {
3823 * device has no operational paths but at least one path is
3824 * disabled due to HPF errors
3825 * disable HPF at all and use the path(s) again
3827 if (device->discipline->disable_hpf)
3828 device->discipline->disable_hpf(device);
3829 dasd_device_set_stop_bits(device, DASD_STOPPED_NOT_ACC);
3830 dasd_path_set_tbvpm(device, hpfpm);
3831 dasd_schedule_device_bh(device);
3832 dasd_schedule_requeue(device);
3833 } else if (!dasd_path_get_opm(device) && ifccpm) {
3835 * device has no operational paths but at least one path is
3836 * disabled due to IFCC errors
3837 * trigger path verification on paths with IFCC errors
3839 dasd_path_set_tbvpm(device, ifccpm);
3840 dasd_schedule_device_bh(device);
3842 if (oldopm && !dasd_path_get_opm(device) && !hpfpm && !ifccpm) {
3843 dev_warn(&device->cdev->dev,
3844 "No verified channel paths remain for the device\n");
3845 DBF_DEV_EVENT(DBF_WARNING, device,
3846 "%s", "last verified path gone");
3847 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3848 dasd_device_set_stop_bits(device,
3849 DASD_STOPPED_DC_WAIT);
3851 dasd_put_device(device);
3853 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3855 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3857 if (!dasd_path_get_opm(device) && lpm) {
3858 dasd_path_set_opm(device, lpm);
3859 dasd_generic_path_operational(device);
3861 dasd_path_add_opm(device, lpm);
3864 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3867 * clear active requests and requeue them to block layer if possible
3869 static int dasd_generic_requeue_all_requests(struct dasd_device *device)
3871 struct list_head requeue_queue;
3872 struct dasd_ccw_req *cqr, *n;
3873 struct dasd_ccw_req *refers;
3876 INIT_LIST_HEAD(&requeue_queue);
3877 spin_lock_irq(get_ccwdev_lock(device->cdev));
3879 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3880 /* Check status and move request to flush_queue */
3881 if (cqr->status == DASD_CQR_IN_IO) {
3882 rc = device->discipline->term_IO(cqr);
3884 /* unable to terminate requeust */
3885 dev_err(&device->cdev->dev,
3886 "Unable to terminate request %p "
3887 "on suspend\n", cqr);
3888 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3889 dasd_put_device(device);
3893 list_move_tail(&cqr->devlist, &requeue_queue);
3895 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3897 list_for_each_entry_safe(cqr, n, &requeue_queue, devlist) {
3898 wait_event(dasd_flush_wq,
3899 (cqr->status != DASD_CQR_CLEAR_PENDING));
3901 /* mark sleepon requests as ended */
3902 if (cqr->callback_data == DASD_SLEEPON_START_TAG)
3903 cqr->callback_data = DASD_SLEEPON_END_TAG;
3905 /* remove requests from device and block queue */
3906 list_del_init(&cqr->devlist);
3907 while (cqr->refers != NULL) {
3908 refers = cqr->refers;
3909 /* remove the request from the block queue */
3910 list_del(&cqr->blocklist);
3911 /* free the finished erp request */
3912 dasd_free_erp_request(cqr, cqr->memdev);
3917 * requeue requests to blocklayer will only work
3918 * for block device requests
3920 if (_dasd_requeue_request(cqr))
3924 list_del_init(&cqr->blocklist);
3925 cqr->block->base->discipline->free_cp(
3926 cqr, (struct request *) cqr->callback_data);
3930 * if requests remain then they are internal request
3931 * and go back to the device queue
3933 if (!list_empty(&requeue_queue)) {
3934 /* move freeze_queue to start of the ccw_queue */
3935 spin_lock_irq(get_ccwdev_lock(device->cdev));
3936 list_splice_tail(&requeue_queue, &device->ccw_queue);
3937 spin_unlock_irq(get_ccwdev_lock(device->cdev));
3939 /* wake up generic waitqueue for eventually ended sleepon requests */
3940 wake_up(&generic_waitq);
3944 static void do_requeue_requests(struct work_struct *work)
3946 struct dasd_device *device = container_of(work, struct dasd_device,
3948 dasd_generic_requeue_all_requests(device);
3949 dasd_device_remove_stop_bits(device, DASD_STOPPED_NOT_ACC);
3951 dasd_schedule_block_bh(device->block);
3952 dasd_put_device(device);
3955 void dasd_schedule_requeue(struct dasd_device *device)
3957 dasd_get_device(device);
3958 /* queue call to dasd_reload_device to the kernel event daemon. */
3959 if (!schedule_work(&device->requeue_requests))
3960 dasd_put_device(device);
3962 EXPORT_SYMBOL(dasd_schedule_requeue);
3964 int dasd_generic_pm_freeze(struct ccw_device *cdev)
3966 struct dasd_device *device = dasd_device_from_cdev(cdev);
3969 return PTR_ERR(device);
3971 /* mark device as suspended */
3972 set_bit(DASD_FLAG_SUSPENDED, &device->flags);
3974 if (device->discipline->freeze)
3975 device->discipline->freeze(device);
3977 /* disallow new I/O */
3978 dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
3980 return dasd_generic_requeue_all_requests(device);
3982 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
3984 int dasd_generic_restore_device(struct ccw_device *cdev)
3986 struct dasd_device *device = dasd_device_from_cdev(cdev);
3990 return PTR_ERR(device);
3992 /* allow new IO again */
3993 dasd_device_remove_stop_bits(device,
3994 (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
3996 dasd_schedule_device_bh(device);
3999 * call discipline restore function
4000 * if device is stopped do nothing e.g. for disconnected devices
4002 if (device->discipline->restore && !(device->stopped))
4003 rc = device->discipline->restore(device);
4004 if (rc || device->stopped)
4006 * if the resume failed for the DASD we put it in
4007 * an UNRESUMED stop state
4009 device->stopped |= DASD_UNRESUMED_PM;
4012 dasd_schedule_block_bh(device->block);
4014 clear_bit(DASD_FLAG_SUSPENDED, &device->flags);
4015 dasd_put_device(device);
4018 EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
4020 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
4022 int rdc_buffer_size,
4025 struct dasd_ccw_req *cqr;
4027 unsigned long *idaw;
4029 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
4032 /* internal error 13 - Allocating the RDC request failed*/
4033 dev_err(&device->cdev->dev,
4034 "An error occurred in the DASD device driver, "
4035 "reason=%s\n", "13");
4040 ccw->cmd_code = CCW_CMD_RDC;
4041 if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
4042 idaw = (unsigned long *) (cqr->data);
4043 ccw->cda = (__u32)(addr_t) idaw;
4044 ccw->flags = CCW_FLAG_IDA;
4045 idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
4047 ccw->cda = (__u32)(addr_t) rdc_buffer;
4051 ccw->count = rdc_buffer_size;
4052 cqr->startdev = device;
4053 cqr->memdev = device;
4054 cqr->expires = 10*HZ;
4056 cqr->buildclk = get_tod_clock();
4057 cqr->status = DASD_CQR_FILLED;
4062 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
4063 void *rdc_buffer, int rdc_buffer_size)
4066 struct dasd_ccw_req *cqr;
4068 cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
4071 return PTR_ERR(cqr);
4073 ret = dasd_sleep_on(cqr);
4074 dasd_sfree_request(cqr, cqr->memdev);
4077 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
4080 * In command mode and transport mode we need to look for sense
4081 * data in different places. The sense data itself is allways
4082 * an array of 32 bytes, so we can unify the sense data access
4085 char *dasd_get_sense(struct irb *irb)
4087 struct tsb *tsb = NULL;
4090 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
4091 if (irb->scsw.tm.tcw)
4092 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
4094 if (tsb && tsb->length == 64 && tsb->flags)
4095 switch (tsb->flags & 0x07) {
4096 case 1: /* tsa_iostat */
4097 sense = tsb->tsa.iostat.sense;
4099 case 2: /* tsa_ddpc */
4100 sense = tsb->tsa.ddpc.sense;
4103 /* currently we don't use interrogate data */
4106 } else if (irb->esw.esw0.erw.cons) {
4111 EXPORT_SYMBOL_GPL(dasd_get_sense);
4113 void dasd_generic_shutdown(struct ccw_device *cdev)
4115 struct dasd_device *device;
4117 device = dasd_device_from_cdev(cdev);
4122 dasd_schedule_block_bh(device->block);
4124 dasd_schedule_device_bh(device);
4126 wait_event(shutdown_waitq, _wait_for_empty_queues(device));
4128 EXPORT_SYMBOL_GPL(dasd_generic_shutdown);
4130 static int __init dasd_init(void)
4134 init_waitqueue_head(&dasd_init_waitq);
4135 init_waitqueue_head(&dasd_flush_wq);
4136 init_waitqueue_head(&generic_waitq);
4137 init_waitqueue_head(&shutdown_waitq);
4139 /* register 'common' DASD debug area, used for all DBF_XXX calls */
4140 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
4141 if (dasd_debug_area == NULL) {
4145 debug_register_view(dasd_debug_area, &debug_sprintf_view);
4146 debug_set_level(dasd_debug_area, DBF_WARNING);
4148 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
4150 dasd_diag_discipline_pointer = NULL;
4152 dasd_statistics_createroot();
4154 rc = dasd_devmap_init();
4157 rc = dasd_gendisk_init();
4163 rc = dasd_eer_init();
4166 #ifdef CONFIG_PROC_FS
4167 rc = dasd_proc_init();
4174 pr_info("The DASD device driver could not be initialized\n");
4179 module_init(dasd_init);
4180 module_exit(dasd_exit);