2 * File...........: linux/drivers/s390/block/dasd.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * Copyright IBM Corp. 1999, 2009
11 #define KMSG_COMPONENT "dasd"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/kernel_stat.h>
15 #include <linux/kmod.h>
16 #include <linux/init.h>
17 #include <linux/interrupt.h>
18 #include <linux/ctype.h>
19 #include <linux/major.h>
20 #include <linux/slab.h>
21 #include <linux/buffer_head.h>
22 #include <linux/hdreg.h>
23 #include <linux/async.h>
24 #include <linux/mutex.h>
25 #include <linux/debugfs.h>
26 #include <linux/seq_file.h>
28 #include <asm/ccwdev.h>
29 #include <asm/ebcdic.h>
30 #include <asm/idals.h>
35 #define PRINTK_HEADER "dasd:"
39 * SECTION: Constant definitions to be used within this file
41 #define DASD_CHANQ_MAX_SIZE 4
43 #define DASD_SLEEPON_START_TAG (void *) 1
44 #define DASD_SLEEPON_END_TAG (void *) 2
47 * SECTION: exported variables of dasd.c
49 debug_info_t *dasd_debug_area;
50 static struct dentry *dasd_debugfs_root_entry;
51 struct dasd_discipline *dasd_diag_discipline_pointer;
52 void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
54 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
55 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
56 " Copyright 2000 IBM Corporation");
57 MODULE_SUPPORTED_DEVICE("dasd");
58 MODULE_LICENSE("GPL");
61 * SECTION: prototypes for static functions of dasd.c
63 static int dasd_alloc_queue(struct dasd_block *);
64 static void dasd_setup_queue(struct dasd_block *);
65 static void dasd_free_queue(struct dasd_block *);
66 static void dasd_flush_request_queue(struct dasd_block *);
67 static int dasd_flush_block_queue(struct dasd_block *);
68 static void dasd_device_tasklet(struct dasd_device *);
69 static void dasd_block_tasklet(struct dasd_block *);
70 static void do_kick_device(struct work_struct *);
71 static void do_restore_device(struct work_struct *);
72 static void do_reload_device(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 *);
81 * SECTION: Operations on the device structure.
83 static wait_queue_head_t dasd_init_waitq;
84 static wait_queue_head_t dasd_flush_wq;
85 static wait_queue_head_t generic_waitq;
88 * Allocate memory for a new device structure.
90 struct dasd_device *dasd_alloc_device(void)
92 struct dasd_device *device;
94 device = kzalloc(sizeof(struct dasd_device), GFP_ATOMIC);
96 return ERR_PTR(-ENOMEM);
98 /* Get two pages for normal block device operations. */
99 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
100 if (!device->ccw_mem) {
102 return ERR_PTR(-ENOMEM);
104 /* Get one page for error recovery. */
105 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
106 if (!device->erp_mem) {
107 free_pages((unsigned long) device->ccw_mem, 1);
109 return ERR_PTR(-ENOMEM);
112 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
113 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
114 spin_lock_init(&device->mem_lock);
115 atomic_set(&device->tasklet_scheduled, 0);
116 tasklet_init(&device->tasklet,
117 (void (*)(unsigned long)) dasd_device_tasklet,
118 (unsigned long) device);
119 INIT_LIST_HEAD(&device->ccw_queue);
120 init_timer(&device->timer);
121 device->timer.function = dasd_device_timeout;
122 device->timer.data = (unsigned long) device;
123 INIT_WORK(&device->kick_work, do_kick_device);
124 INIT_WORK(&device->restore_device, do_restore_device);
125 INIT_WORK(&device->reload_device, do_reload_device);
126 device->state = DASD_STATE_NEW;
127 device->target = DASD_STATE_NEW;
128 mutex_init(&device->state_mutex);
129 spin_lock_init(&device->profile.lock);
134 * Free memory of a device structure.
136 void dasd_free_device(struct dasd_device *device)
138 kfree(device->private);
139 free_page((unsigned long) device->erp_mem);
140 free_pages((unsigned long) device->ccw_mem, 1);
145 * Allocate memory for a new device structure.
147 struct dasd_block *dasd_alloc_block(void)
149 struct dasd_block *block;
151 block = kzalloc(sizeof(*block), GFP_ATOMIC);
153 return ERR_PTR(-ENOMEM);
154 /* open_count = 0 means device online but not in use */
155 atomic_set(&block->open_count, -1);
157 spin_lock_init(&block->request_queue_lock);
158 atomic_set(&block->tasklet_scheduled, 0);
159 tasklet_init(&block->tasklet,
160 (void (*)(unsigned long)) dasd_block_tasklet,
161 (unsigned long) block);
162 INIT_LIST_HEAD(&block->ccw_queue);
163 spin_lock_init(&block->queue_lock);
164 init_timer(&block->timer);
165 block->timer.function = dasd_block_timeout;
166 block->timer.data = (unsigned long) block;
167 spin_lock_init(&block->profile.lock);
173 * Free memory of a device structure.
175 void dasd_free_block(struct dasd_block *block)
181 * Make a new device known to the system.
183 static int dasd_state_new_to_known(struct dasd_device *device)
188 * As long as the device is not in state DASD_STATE_NEW we want to
189 * keep the reference count > 0.
191 dasd_get_device(device);
194 rc = dasd_alloc_queue(device->block);
196 dasd_put_device(device);
200 device->state = DASD_STATE_KNOWN;
205 * Let the system forget about a device.
207 static int dasd_state_known_to_new(struct dasd_device *device)
209 /* Disable extended error reporting for this device. */
210 dasd_eer_disable(device);
211 /* Forget the discipline information. */
212 if (device->discipline) {
213 if (device->discipline->uncheck_device)
214 device->discipline->uncheck_device(device);
215 module_put(device->discipline->owner);
217 device->discipline = NULL;
218 if (device->base_discipline)
219 module_put(device->base_discipline->owner);
220 device->base_discipline = NULL;
221 device->state = DASD_STATE_NEW;
224 dasd_free_queue(device->block);
226 /* Give up reference we took in dasd_state_new_to_known. */
227 dasd_put_device(device);
231 static struct dentry *dasd_debugfs_setup(const char *name,
232 struct dentry *base_dentry)
238 pde = debugfs_create_dir(name, base_dentry);
239 if (!pde || IS_ERR(pde))
245 * Request the irq line for the device.
247 static int dasd_state_known_to_basic(struct dasd_device *device)
249 struct dasd_block *block = device->block;
252 /* Allocate and register gendisk structure. */
254 rc = dasd_gendisk_alloc(block);
257 block->debugfs_dentry =
258 dasd_debugfs_setup(block->gdp->disk_name,
259 dasd_debugfs_root_entry);
260 dasd_profile_init(&block->profile, block->debugfs_dentry);
261 if (dasd_global_profile_level == DASD_PROFILE_ON)
262 dasd_profile_on(&device->block->profile);
264 device->debugfs_dentry =
265 dasd_debugfs_setup(dev_name(&device->cdev->dev),
266 dasd_debugfs_root_entry);
267 dasd_profile_init(&device->profile, device->debugfs_dentry);
269 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
270 device->debug_area = debug_register(dev_name(&device->cdev->dev), 4, 1,
272 debug_register_view(device->debug_area, &debug_sprintf_view);
273 debug_set_level(device->debug_area, DBF_WARNING);
274 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
276 device->state = DASD_STATE_BASIC;
281 * Release the irq line for the device. Terminate any running i/o.
283 static int dasd_state_basic_to_known(struct dasd_device *device)
287 dasd_profile_exit(&device->block->profile);
288 if (device->block->debugfs_dentry)
289 debugfs_remove(device->block->debugfs_dentry);
290 dasd_gendisk_free(device->block);
291 dasd_block_clear_timer(device->block);
293 rc = dasd_flush_device_queue(device);
296 dasd_device_clear_timer(device);
297 dasd_profile_exit(&device->profile);
298 if (device->debugfs_dentry)
299 debugfs_remove(device->debugfs_dentry);
301 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
302 if (device->debug_area != NULL) {
303 debug_unregister(device->debug_area);
304 device->debug_area = NULL;
306 device->state = DASD_STATE_KNOWN;
311 * Do the initial analysis. The do_analysis function may return
312 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
313 * until the discipline decides to continue the startup sequence
314 * by calling the function dasd_change_state. The eckd disciplines
315 * uses this to start a ccw that detects the format. The completion
316 * interrupt for this detection ccw uses the kernel event daemon to
317 * trigger the call to dasd_change_state. All this is done in the
318 * discipline code, see dasd_eckd.c.
319 * After the analysis ccw is done (do_analysis returned 0) the block
321 * In case the analysis returns an error, the device setup is stopped
322 * (a fake disk was already added to allow formatting).
324 static int dasd_state_basic_to_ready(struct dasd_device *device)
327 struct dasd_block *block;
330 block = device->block;
331 /* make disk known with correct capacity */
333 if (block->base->discipline->do_analysis != NULL)
334 rc = block->base->discipline->do_analysis(block);
337 device->state = DASD_STATE_UNFMT;
340 dasd_setup_queue(block);
341 set_capacity(block->gdp,
342 block->blocks << block->s2b_shift);
343 device->state = DASD_STATE_READY;
344 rc = dasd_scan_partitions(block);
346 device->state = DASD_STATE_BASIC;
348 device->state = DASD_STATE_READY;
354 * Remove device from block device layer. Destroy dirty buffers.
355 * Forget format information. Check if the target level is basic
356 * and if it is create fake disk for formatting.
358 static int dasd_state_ready_to_basic(struct dasd_device *device)
362 device->state = DASD_STATE_BASIC;
364 struct dasd_block *block = device->block;
365 rc = dasd_flush_block_queue(block);
367 device->state = DASD_STATE_READY;
370 dasd_flush_request_queue(block);
371 dasd_destroy_partitions(block);
374 block->s2b_shift = 0;
382 static int dasd_state_unfmt_to_basic(struct dasd_device *device)
384 device->state = DASD_STATE_BASIC;
389 * Make the device online and schedule the bottom half to start
390 * the requeueing of requests from the linux request queue to the
394 dasd_state_ready_to_online(struct dasd_device * device)
397 struct gendisk *disk;
398 struct disk_part_iter piter;
399 struct hd_struct *part;
401 if (device->discipline->ready_to_online) {
402 rc = device->discipline->ready_to_online(device);
406 device->state = DASD_STATE_ONLINE;
408 dasd_schedule_block_bh(device->block);
409 if ((device->features & DASD_FEATURE_USERAW)) {
410 disk = device->block->gdp;
411 kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
414 disk = device->block->bdev->bd_disk;
415 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
416 while ((part = disk_part_iter_next(&piter)))
417 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
418 disk_part_iter_exit(&piter);
424 * Stop the requeueing of requests again.
426 static int dasd_state_online_to_ready(struct dasd_device *device)
429 struct gendisk *disk;
430 struct disk_part_iter piter;
431 struct hd_struct *part;
433 if (device->discipline->online_to_ready) {
434 rc = device->discipline->online_to_ready(device);
438 device->state = DASD_STATE_READY;
439 if (device->block && !(device->features & DASD_FEATURE_USERAW)) {
440 disk = device->block->bdev->bd_disk;
441 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
442 while ((part = disk_part_iter_next(&piter)))
443 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
444 disk_part_iter_exit(&piter);
450 * Device startup state changes.
452 static int dasd_increase_state(struct dasd_device *device)
457 if (device->state == DASD_STATE_NEW &&
458 device->target >= DASD_STATE_KNOWN)
459 rc = dasd_state_new_to_known(device);
462 device->state == DASD_STATE_KNOWN &&
463 device->target >= DASD_STATE_BASIC)
464 rc = dasd_state_known_to_basic(device);
467 device->state == DASD_STATE_BASIC &&
468 device->target >= DASD_STATE_READY)
469 rc = dasd_state_basic_to_ready(device);
472 device->state == DASD_STATE_UNFMT &&
473 device->target > DASD_STATE_UNFMT)
477 device->state == DASD_STATE_READY &&
478 device->target >= DASD_STATE_ONLINE)
479 rc = dasd_state_ready_to_online(device);
485 * Device shutdown state changes.
487 static int dasd_decrease_state(struct dasd_device *device)
492 if (device->state == DASD_STATE_ONLINE &&
493 device->target <= DASD_STATE_READY)
494 rc = dasd_state_online_to_ready(device);
497 device->state == DASD_STATE_READY &&
498 device->target <= DASD_STATE_BASIC)
499 rc = dasd_state_ready_to_basic(device);
502 device->state == DASD_STATE_UNFMT &&
503 device->target <= DASD_STATE_BASIC)
504 rc = dasd_state_unfmt_to_basic(device);
507 device->state == DASD_STATE_BASIC &&
508 device->target <= DASD_STATE_KNOWN)
509 rc = dasd_state_basic_to_known(device);
512 device->state == DASD_STATE_KNOWN &&
513 device->target <= DASD_STATE_NEW)
514 rc = dasd_state_known_to_new(device);
520 * This is the main startup/shutdown routine.
522 static void dasd_change_state(struct dasd_device *device)
526 if (device->state == device->target)
527 /* Already where we want to go today... */
529 if (device->state < device->target)
530 rc = dasd_increase_state(device);
532 rc = dasd_decrease_state(device);
536 device->target = device->state;
538 if (device->state == device->target)
539 wake_up(&dasd_init_waitq);
541 /* let user-space know that the device status changed */
542 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
546 * Kick starter for devices that did not complete the startup/shutdown
547 * procedure or were sleeping because of a pending state.
548 * dasd_kick_device will schedule a call do do_kick_device to the kernel
551 static void do_kick_device(struct work_struct *work)
553 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
554 mutex_lock(&device->state_mutex);
555 dasd_change_state(device);
556 mutex_unlock(&device->state_mutex);
557 dasd_schedule_device_bh(device);
558 dasd_put_device(device);
561 void dasd_kick_device(struct dasd_device *device)
563 dasd_get_device(device);
564 /* queue call to dasd_kick_device to the kernel event daemon. */
565 schedule_work(&device->kick_work);
569 * dasd_reload_device will schedule a call do do_reload_device to the kernel
572 static void do_reload_device(struct work_struct *work)
574 struct dasd_device *device = container_of(work, struct dasd_device,
576 device->discipline->reload(device);
577 dasd_put_device(device);
580 void dasd_reload_device(struct dasd_device *device)
582 dasd_get_device(device);
583 /* queue call to dasd_reload_device to the kernel event daemon. */
584 schedule_work(&device->reload_device);
586 EXPORT_SYMBOL(dasd_reload_device);
589 * dasd_restore_device will schedule a call do do_restore_device to the kernel
592 static void do_restore_device(struct work_struct *work)
594 struct dasd_device *device = container_of(work, struct dasd_device,
596 device->cdev->drv->restore(device->cdev);
597 dasd_put_device(device);
600 void dasd_restore_device(struct dasd_device *device)
602 dasd_get_device(device);
603 /* queue call to dasd_restore_device to the kernel event daemon. */
604 schedule_work(&device->restore_device);
608 * Set the target state for a device and starts the state change.
610 void dasd_set_target_state(struct dasd_device *device, int target)
612 dasd_get_device(device);
613 mutex_lock(&device->state_mutex);
614 /* If we are in probeonly mode stop at DASD_STATE_READY. */
615 if (dasd_probeonly && target > DASD_STATE_READY)
616 target = DASD_STATE_READY;
617 if (device->target != target) {
618 if (device->state == target)
619 wake_up(&dasd_init_waitq);
620 device->target = target;
622 if (device->state != device->target)
623 dasd_change_state(device);
624 mutex_unlock(&device->state_mutex);
625 dasd_put_device(device);
629 * Enable devices with device numbers in [from..to].
631 static inline int _wait_for_device(struct dasd_device *device)
633 return (device->state == device->target);
636 void dasd_enable_device(struct dasd_device *device)
638 dasd_set_target_state(device, DASD_STATE_ONLINE);
639 if (device->state <= DASD_STATE_KNOWN)
640 /* No discipline for device found. */
641 dasd_set_target_state(device, DASD_STATE_NEW);
642 /* Now wait for the devices to come up. */
643 wait_event(dasd_init_waitq, _wait_for_device(device));
647 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
650 unsigned int dasd_global_profile_level = DASD_PROFILE_OFF;
652 #ifdef CONFIG_DASD_PROFILE
653 struct dasd_profile_info dasd_global_profile_data;
654 static struct dentry *dasd_global_profile_dentry;
655 static struct dentry *dasd_debugfs_global_entry;
658 * Add profiling information for cqr before execution.
660 static void dasd_profile_start(struct dasd_block *block,
661 struct dasd_ccw_req *cqr,
665 unsigned int counter;
666 struct dasd_device *device;
668 /* count the length of the chanq for statistics */
670 if (dasd_global_profile_level || block->profile.data)
671 list_for_each(l, &block->ccw_queue)
675 if (dasd_global_profile_level) {
676 dasd_global_profile_data.dasd_io_nr_req[counter]++;
677 if (rq_data_dir(req) == READ)
678 dasd_global_profile_data.dasd_read_nr_req[counter]++;
681 spin_lock(&block->profile.lock);
682 if (block->profile.data)
683 block->profile.data->dasd_io_nr_req[counter]++;
684 if (rq_data_dir(req) == READ)
685 block->profile.data->dasd_read_nr_req[counter]++;
686 spin_unlock(&block->profile.lock);
689 * We count the request for the start device, even though it may run on
690 * some other device due to error recovery. This way we make sure that
691 * we count each request only once.
693 device = cqr->startdev;
694 if (device->profile.data) {
695 counter = 1; /* request is not yet queued on the start device */
696 list_for_each(l, &device->ccw_queue)
700 spin_lock(&device->profile.lock);
701 if (device->profile.data) {
702 device->profile.data->dasd_io_nr_req[counter]++;
703 if (rq_data_dir(req) == READ)
704 device->profile.data->dasd_read_nr_req[counter]++;
706 spin_unlock(&device->profile.lock);
710 * Add profiling information for cqr after execution.
713 #define dasd_profile_counter(value, index) \
715 for (index = 0; index < 31 && value >> (2+index); index++) \
719 static void dasd_profile_end_add_data(struct dasd_profile_info *data,
732 /* in case of an overflow, reset the whole profile */
733 if (data->dasd_io_reqs == UINT_MAX) {
734 memset(data, 0, sizeof(*data));
735 getnstimeofday(&data->starttod);
737 data->dasd_io_reqs++;
738 data->dasd_io_sects += sectors;
740 data->dasd_io_alias++;
744 data->dasd_io_secs[sectors_ind]++;
745 data->dasd_io_times[tottime_ind]++;
746 data->dasd_io_timps[tottimeps_ind]++;
747 data->dasd_io_time1[strtime_ind]++;
748 data->dasd_io_time2[irqtime_ind]++;
749 data->dasd_io_time2ps[irqtimeps_ind]++;
750 data->dasd_io_time3[endtime_ind]++;
753 data->dasd_read_reqs++;
754 data->dasd_read_sects += sectors;
756 data->dasd_read_alias++;
758 data->dasd_read_tpm++;
759 data->dasd_read_secs[sectors_ind]++;
760 data->dasd_read_times[tottime_ind]++;
761 data->dasd_read_time1[strtime_ind]++;
762 data->dasd_read_time2[irqtime_ind]++;
763 data->dasd_read_time3[endtime_ind]++;
767 static void dasd_profile_end(struct dasd_block *block,
768 struct dasd_ccw_req *cqr,
771 long strtime, irqtime, endtime, tottime; /* in microseconds */
772 long tottimeps, sectors;
773 struct dasd_device *device;
774 int sectors_ind, tottime_ind, tottimeps_ind, strtime_ind;
775 int irqtime_ind, irqtimeps_ind, endtime_ind;
777 device = cqr->startdev;
778 if (!(dasd_global_profile_level ||
779 block->profile.data ||
780 device->profile.data))
783 sectors = blk_rq_sectors(req);
784 if (!cqr->buildclk || !cqr->startclk ||
785 !cqr->stopclk || !cqr->endclk ||
789 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
790 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
791 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
792 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
793 tottimeps = tottime / sectors;
795 dasd_profile_counter(sectors, sectors_ind);
796 dasd_profile_counter(tottime, tottime_ind);
797 dasd_profile_counter(tottimeps, tottimeps_ind);
798 dasd_profile_counter(strtime, strtime_ind);
799 dasd_profile_counter(irqtime, irqtime_ind);
800 dasd_profile_counter(irqtime / sectors, irqtimeps_ind);
801 dasd_profile_counter(endtime, endtime_ind);
803 if (dasd_global_profile_level) {
804 dasd_profile_end_add_data(&dasd_global_profile_data,
805 cqr->startdev != block->base,
807 rq_data_dir(req) == READ,
808 sectors, sectors_ind, tottime_ind,
809 tottimeps_ind, strtime_ind,
810 irqtime_ind, irqtimeps_ind,
814 spin_lock(&block->profile.lock);
815 if (block->profile.data)
816 dasd_profile_end_add_data(block->profile.data,
817 cqr->startdev != block->base,
819 rq_data_dir(req) == READ,
820 sectors, sectors_ind, tottime_ind,
821 tottimeps_ind, strtime_ind,
822 irqtime_ind, irqtimeps_ind,
824 spin_unlock(&block->profile.lock);
826 spin_lock(&device->profile.lock);
827 if (device->profile.data)
828 dasd_profile_end_add_data(device->profile.data,
829 cqr->startdev != block->base,
831 rq_data_dir(req) == READ,
832 sectors, sectors_ind, tottime_ind,
833 tottimeps_ind, strtime_ind,
834 irqtime_ind, irqtimeps_ind,
836 spin_unlock(&device->profile.lock);
839 void dasd_profile_reset(struct dasd_profile *profile)
841 struct dasd_profile_info *data;
843 spin_lock_bh(&profile->lock);
844 data = profile->data;
846 spin_unlock_bh(&profile->lock);
849 memset(data, 0, sizeof(*data));
850 getnstimeofday(&data->starttod);
851 spin_unlock_bh(&profile->lock);
854 void dasd_global_profile_reset(void)
856 memset(&dasd_global_profile_data, 0, sizeof(dasd_global_profile_data));
857 getnstimeofday(&dasd_global_profile_data.starttod);
860 int dasd_profile_on(struct dasd_profile *profile)
862 struct dasd_profile_info *data;
864 data = kzalloc(sizeof(*data), GFP_KERNEL);
867 spin_lock_bh(&profile->lock);
869 spin_unlock_bh(&profile->lock);
873 getnstimeofday(&data->starttod);
874 profile->data = data;
875 spin_unlock_bh(&profile->lock);
879 void dasd_profile_off(struct dasd_profile *profile)
881 spin_lock_bh(&profile->lock);
882 kfree(profile->data);
883 profile->data = NULL;
884 spin_unlock_bh(&profile->lock);
887 char *dasd_get_user_string(const char __user *user_buf, size_t user_len)
891 buffer = kmalloc(user_len + 1, GFP_KERNEL);
893 return ERR_PTR(-ENOMEM);
894 if (copy_from_user(buffer, user_buf, user_len) != 0) {
896 return ERR_PTR(-EFAULT);
898 /* got the string, now strip linefeed. */
899 if (buffer[user_len - 1] == '\n')
900 buffer[user_len - 1] = 0;
902 buffer[user_len] = 0;
906 static ssize_t dasd_stats_write(struct file *file,
907 const char __user *user_buf,
908 size_t user_len, loff_t *pos)
912 struct seq_file *m = (struct seq_file *)file->private_data;
913 struct dasd_profile *prof = m->private;
915 if (user_len > 65536)
917 buffer = dasd_get_user_string(user_buf, user_len);
919 return PTR_ERR(buffer);
921 str = skip_spaces(buffer);
923 if (strncmp(str, "reset", 5) == 0) {
924 dasd_profile_reset(prof);
925 } else if (strncmp(str, "on", 2) == 0) {
926 rc = dasd_profile_on(prof);
929 } else if (strncmp(str, "off", 3) == 0) {
930 dasd_profile_off(prof);
937 static void dasd_stats_array(struct seq_file *m, unsigned int *array)
941 for (i = 0; i < 32; i++)
942 seq_printf(m, "%u ", array[i]);
946 static void dasd_stats_seq_print(struct seq_file *m,
947 struct dasd_profile_info *data)
949 seq_printf(m, "start_time %ld.%09ld\n",
950 data->starttod.tv_sec, data->starttod.tv_nsec);
951 seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
952 seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
953 seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
954 seq_printf(m, "total_hpf %u\n", data->dasd_io_tpm);
955 seq_printf(m, "histogram_sectors ");
956 dasd_stats_array(m, data->dasd_io_secs);
957 seq_printf(m, "histogram_io_times ");
958 dasd_stats_array(m, data->dasd_io_times);
959 seq_printf(m, "histogram_io_times_weighted ");
960 dasd_stats_array(m, data->dasd_io_timps);
961 seq_printf(m, "histogram_time_build_to_ssch ");
962 dasd_stats_array(m, data->dasd_io_time1);
963 seq_printf(m, "histogram_time_ssch_to_irq ");
964 dasd_stats_array(m, data->dasd_io_time2);
965 seq_printf(m, "histogram_time_ssch_to_irq_weighted ");
966 dasd_stats_array(m, data->dasd_io_time2ps);
967 seq_printf(m, "histogram_time_irq_to_end ");
968 dasd_stats_array(m, data->dasd_io_time3);
969 seq_printf(m, "histogram_ccw_queue_length ");
970 dasd_stats_array(m, data->dasd_io_nr_req);
971 seq_printf(m, "total_read_requests %u\n", data->dasd_read_reqs);
972 seq_printf(m, "total_read_sectors %u\n", data->dasd_read_sects);
973 seq_printf(m, "total_read_pav %u\n", data->dasd_read_alias);
974 seq_printf(m, "total_read_hpf %u\n", data->dasd_read_tpm);
975 seq_printf(m, "histogram_read_sectors ");
976 dasd_stats_array(m, data->dasd_read_secs);
977 seq_printf(m, "histogram_read_times ");
978 dasd_stats_array(m, data->dasd_read_times);
979 seq_printf(m, "histogram_read_time_build_to_ssch ");
980 dasd_stats_array(m, data->dasd_read_time1);
981 seq_printf(m, "histogram_read_time_ssch_to_irq ");
982 dasd_stats_array(m, data->dasd_read_time2);
983 seq_printf(m, "histogram_read_time_irq_to_end ");
984 dasd_stats_array(m, data->dasd_read_time3);
985 seq_printf(m, "histogram_read_ccw_queue_length ");
986 dasd_stats_array(m, data->dasd_read_nr_req);
989 static int dasd_stats_show(struct seq_file *m, void *v)
991 struct dasd_profile *profile;
992 struct dasd_profile_info *data;
994 profile = m->private;
995 spin_lock_bh(&profile->lock);
996 data = profile->data;
998 spin_unlock_bh(&profile->lock);
999 seq_printf(m, "disabled\n");
1002 dasd_stats_seq_print(m, data);
1003 spin_unlock_bh(&profile->lock);
1007 static int dasd_stats_open(struct inode *inode, struct file *file)
1009 struct dasd_profile *profile = inode->i_private;
1010 return single_open(file, dasd_stats_show, profile);
1013 static const struct file_operations dasd_stats_raw_fops = {
1014 .owner = THIS_MODULE,
1015 .open = dasd_stats_open,
1017 .llseek = seq_lseek,
1018 .release = single_release,
1019 .write = dasd_stats_write,
1022 static ssize_t dasd_stats_global_write(struct file *file,
1023 const char __user *user_buf,
1024 size_t user_len, loff_t *pos)
1029 if (user_len > 65536)
1031 buffer = dasd_get_user_string(user_buf, user_len);
1033 return PTR_ERR(buffer);
1034 str = skip_spaces(buffer);
1036 if (strncmp(str, "reset", 5) == 0) {
1037 dasd_global_profile_reset();
1038 } else if (strncmp(str, "on", 2) == 0) {
1039 dasd_global_profile_reset();
1040 dasd_global_profile_level = DASD_PROFILE_GLOBAL_ONLY;
1041 } else if (strncmp(str, "off", 3) == 0) {
1042 dasd_global_profile_level = DASD_PROFILE_OFF;
1049 static int dasd_stats_global_show(struct seq_file *m, void *v)
1051 if (!dasd_global_profile_level) {
1052 seq_printf(m, "disabled\n");
1055 dasd_stats_seq_print(m, &dasd_global_profile_data);
1059 static int dasd_stats_global_open(struct inode *inode, struct file *file)
1061 return single_open(file, dasd_stats_global_show, NULL);
1064 static const struct file_operations dasd_stats_global_fops = {
1065 .owner = THIS_MODULE,
1066 .open = dasd_stats_global_open,
1068 .llseek = seq_lseek,
1069 .release = single_release,
1070 .write = dasd_stats_global_write,
1073 static void dasd_profile_init(struct dasd_profile *profile,
1074 struct dentry *base_dentry)
1081 profile->dentry = NULL;
1082 profile->data = NULL;
1083 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1084 pde = debugfs_create_file("statistics", mode, base_dentry,
1085 profile, &dasd_stats_raw_fops);
1086 if (pde && !IS_ERR(pde))
1087 profile->dentry = pde;
1091 static void dasd_profile_exit(struct dasd_profile *profile)
1093 dasd_profile_off(profile);
1094 if (profile->dentry) {
1095 debugfs_remove(profile->dentry);
1096 profile->dentry = NULL;
1100 static void dasd_statistics_removeroot(void)
1102 dasd_global_profile_level = DASD_PROFILE_OFF;
1103 if (dasd_global_profile_dentry) {
1104 debugfs_remove(dasd_global_profile_dentry);
1105 dasd_global_profile_dentry = NULL;
1107 if (dasd_debugfs_global_entry)
1108 debugfs_remove(dasd_debugfs_global_entry);
1109 if (dasd_debugfs_root_entry)
1110 debugfs_remove(dasd_debugfs_root_entry);
1113 static void dasd_statistics_createroot(void)
1118 dasd_debugfs_root_entry = NULL;
1119 dasd_debugfs_global_entry = NULL;
1120 dasd_global_profile_dentry = NULL;
1121 pde = debugfs_create_dir("dasd", NULL);
1122 if (!pde || IS_ERR(pde))
1124 dasd_debugfs_root_entry = pde;
1125 pde = debugfs_create_dir("global", dasd_debugfs_root_entry);
1126 if (!pde || IS_ERR(pde))
1128 dasd_debugfs_global_entry = pde;
1130 mode = (S_IRUSR | S_IWUSR | S_IFREG);
1131 pde = debugfs_create_file("statistics", mode, dasd_debugfs_global_entry,
1132 NULL, &dasd_stats_global_fops);
1133 if (!pde || IS_ERR(pde))
1135 dasd_global_profile_dentry = pde;
1139 DBF_EVENT(DBF_ERR, "%s",
1140 "Creation of the dasd debugfs interface failed");
1141 dasd_statistics_removeroot();
1146 #define dasd_profile_start(block, cqr, req) do {} while (0)
1147 #define dasd_profile_end(block, cqr, req) do {} while (0)
1149 static void dasd_statistics_createroot(void)
1154 static void dasd_statistics_removeroot(void)
1159 int dasd_stats_generic_show(struct seq_file *m, void *v)
1161 seq_printf(m, "Statistics are not activated in this kernel\n");
1165 static void dasd_profile_init(struct dasd_profile *profile,
1166 struct dentry *base_dentry)
1171 static void dasd_profile_exit(struct dasd_profile *profile)
1176 int dasd_profile_on(struct dasd_profile *profile)
1181 #endif /* CONFIG_DASD_PROFILE */
1184 * Allocate memory for a channel program with 'cplength' channel
1185 * command words and 'datasize' additional space. There are two
1186 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
1187 * memory and 2) dasd_smalloc_request uses the static ccw memory
1188 * that gets allocated for each device.
1190 struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength,
1192 struct dasd_device *device)
1194 struct dasd_ccw_req *cqr;
1197 BUG_ON(datasize > PAGE_SIZE ||
1198 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
1200 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
1202 return ERR_PTR(-ENOMEM);
1205 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
1206 GFP_ATOMIC | GFP_DMA);
1207 if (cqr->cpaddr == NULL) {
1209 return ERR_PTR(-ENOMEM);
1214 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
1215 if (cqr->data == NULL) {
1218 return ERR_PTR(-ENOMEM);
1222 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1223 dasd_get_device(device);
1227 struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength,
1229 struct dasd_device *device)
1231 unsigned long flags;
1232 struct dasd_ccw_req *cqr;
1236 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
1238 size += cplength * sizeof(struct ccw1);
1241 spin_lock_irqsave(&device->mem_lock, flags);
1242 cqr = (struct dasd_ccw_req *)
1243 dasd_alloc_chunk(&device->ccw_chunks, size);
1244 spin_unlock_irqrestore(&device->mem_lock, flags);
1246 return ERR_PTR(-ENOMEM);
1247 memset(cqr, 0, sizeof(struct dasd_ccw_req));
1248 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
1251 cqr->cpaddr = (struct ccw1 *) data;
1252 data += cplength*sizeof(struct ccw1);
1253 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
1258 memset(cqr->data, 0, datasize);
1261 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
1262 dasd_get_device(device);
1267 * Free memory of a channel program. This function needs to free all the
1268 * idal lists that might have been created by dasd_set_cda and the
1269 * struct dasd_ccw_req itself.
1271 void dasd_kfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1276 /* Clear any idals used for the request. */
1279 clear_normalized_cda(ccw);
1280 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
1285 dasd_put_device(device);
1288 void dasd_sfree_request(struct dasd_ccw_req *cqr, struct dasd_device *device)
1290 unsigned long flags;
1292 spin_lock_irqsave(&device->mem_lock, flags);
1293 dasd_free_chunk(&device->ccw_chunks, cqr);
1294 spin_unlock_irqrestore(&device->mem_lock, flags);
1295 dasd_put_device(device);
1299 * Check discipline magic in cqr.
1301 static inline int dasd_check_cqr(struct dasd_ccw_req *cqr)
1303 struct dasd_device *device;
1307 device = cqr->startdev;
1308 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
1309 DBF_DEV_EVENT(DBF_WARNING, device,
1310 " dasd_ccw_req 0x%08x magic doesn't match"
1311 " discipline 0x%08x",
1313 *(unsigned int *) device->discipline->name);
1320 * Terminate the current i/o and set the request to clear_pending.
1321 * Timer keeps device runnig.
1322 * ccw_device_clear can fail if the i/o subsystem
1325 int dasd_term_IO(struct dasd_ccw_req *cqr)
1327 struct dasd_device *device;
1329 char errorstring[ERRORLENGTH];
1332 rc = dasd_check_cqr(cqr);
1336 device = (struct dasd_device *) cqr->startdev;
1337 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
1338 rc = ccw_device_clear(device->cdev, (long) cqr);
1340 case 0: /* termination successful */
1341 cqr->status = DASD_CQR_CLEAR_PENDING;
1342 cqr->stopclk = get_clock();
1344 DBF_DEV_EVENT(DBF_DEBUG, device,
1345 "terminate cqr %p successful",
1349 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1350 "device gone, retry");
1353 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1354 "I/O error, retry");
1358 DBF_DEV_EVENT(DBF_ERR, device, "%s",
1359 "device busy, retry later");
1362 /* internal error 10 - unknown rc*/
1363 snprintf(errorstring, ERRORLENGTH, "10 %d", rc);
1364 dev_err(&device->cdev->dev, "An error occurred in the "
1365 "DASD device driver, reason=%s\n", errorstring);
1371 dasd_schedule_device_bh(device);
1376 * Start the i/o. This start_IO can fail if the channel is really busy.
1377 * In that case set up a timer to start the request later.
1379 int dasd_start_IO(struct dasd_ccw_req *cqr)
1381 struct dasd_device *device;
1383 char errorstring[ERRORLENGTH];
1386 rc = dasd_check_cqr(cqr);
1391 device = (struct dasd_device *) cqr->startdev;
1393 test_bit(DASD_FLAG_LOCK_STOLEN, &cqr->block->base->flags)) ||
1394 test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags)) &&
1395 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
1396 DBF_DEV_EVENT(DBF_DEBUG, device, "start_IO: return request %p "
1397 "because of stolen lock", cqr);
1398 cqr->status = DASD_CQR_ERROR;
1399 cqr->intrc = -EPERM;
1402 if (cqr->retries < 0) {
1403 /* internal error 14 - start_IO run out of retries */
1404 sprintf(errorstring, "14 %p", cqr);
1405 dev_err(&device->cdev->dev, "An error occurred in the DASD "
1406 "device driver, reason=%s\n", errorstring);
1407 cqr->status = DASD_CQR_ERROR;
1410 cqr->startclk = get_clock();
1411 cqr->starttime = jiffies;
1413 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1414 cqr->lpm &= device->path_data.opm;
1416 cqr->lpm = device->path_data.opm;
1418 if (cqr->cpmode == 1) {
1419 rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
1420 (long) cqr, cqr->lpm);
1422 rc = ccw_device_start(device->cdev, cqr->cpaddr,
1423 (long) cqr, cqr->lpm, 0);
1427 cqr->status = DASD_CQR_IN_IO;
1430 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1431 "start_IO: device busy, retry later");
1434 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1435 "start_IO: request timeout, retry later");
1438 /* -EACCES indicates that the request used only a subset of the
1439 * available paths and all these paths are gone. If the lpm of
1440 * this request was only a subset of the opm (e.g. the ppm) then
1441 * we just do a retry with all available paths.
1442 * If we already use the full opm, something is amiss, and we
1443 * need a full path verification.
1445 if (test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags)) {
1446 DBF_DEV_EVENT(DBF_WARNING, device,
1447 "start_IO: selected paths gone (%x)",
1449 } else if (cqr->lpm != device->path_data.opm) {
1450 cqr->lpm = device->path_data.opm;
1451 DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
1452 "start_IO: selected paths gone,"
1453 " retry on all paths");
1455 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1456 "start_IO: all paths in opm gone,"
1457 " do path verification");
1458 dasd_generic_last_path_gone(device);
1459 device->path_data.opm = 0;
1460 device->path_data.ppm = 0;
1461 device->path_data.npm = 0;
1462 device->path_data.tbvpm =
1463 ccw_device_get_path_mask(device->cdev);
1467 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1468 "start_IO: -ENODEV device gone, retry");
1471 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1472 "start_IO: -EIO device gone, retry");
1475 /* most likely caused in power management context */
1476 DBF_DEV_EVENT(DBF_WARNING, device, "%s",
1477 "start_IO: -EINVAL device currently "
1481 /* internal error 11 - unknown rc */
1482 snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
1483 dev_err(&device->cdev->dev,
1484 "An error occurred in the DASD device driver, "
1485 "reason=%s\n", errorstring);
1494 * Timeout function for dasd devices. This is used for different purposes
1495 * 1) missing interrupt handler for normal operation
1496 * 2) delayed start of request where start_IO failed with -EBUSY
1497 * 3) timeout for missing state change interrupts
1498 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
1499 * DASD_CQR_QUEUED for 2) and 3).
1501 static void dasd_device_timeout(unsigned long ptr)
1503 unsigned long flags;
1504 struct dasd_device *device;
1506 device = (struct dasd_device *) ptr;
1507 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1508 /* re-activate request queue */
1509 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1510 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1511 dasd_schedule_device_bh(device);
1515 * Setup timeout for a device in jiffies.
1517 void dasd_device_set_timer(struct dasd_device *device, int expires)
1520 del_timer(&device->timer);
1522 mod_timer(&device->timer, jiffies + expires);
1526 * Clear timeout for a device.
1528 void dasd_device_clear_timer(struct dasd_device *device)
1530 del_timer(&device->timer);
1533 static void dasd_handle_killed_request(struct ccw_device *cdev,
1534 unsigned long intparm)
1536 struct dasd_ccw_req *cqr;
1537 struct dasd_device *device;
1541 cqr = (struct dasd_ccw_req *) intparm;
1542 if (cqr->status != DASD_CQR_IN_IO) {
1543 DBF_EVENT_DEVID(DBF_DEBUG, cdev,
1544 "invalid status in handle_killed_request: "
1545 "%02x", cqr->status);
1549 device = dasd_device_from_cdev_locked(cdev);
1550 if (IS_ERR(device)) {
1551 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1552 "unable to get device from cdev");
1556 if (!cqr->startdev ||
1557 device != cqr->startdev ||
1558 strncmp(cqr->startdev->discipline->ebcname,
1559 (char *) &cqr->magic, 4)) {
1560 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1561 "invalid device in request");
1562 dasd_put_device(device);
1566 /* Schedule request to be retried. */
1567 cqr->status = DASD_CQR_QUEUED;
1569 dasd_device_clear_timer(device);
1570 dasd_schedule_device_bh(device);
1571 dasd_put_device(device);
1574 void dasd_generic_handle_state_change(struct dasd_device *device)
1576 /* First of all start sense subsystem status request. */
1577 dasd_eer_snss(device);
1579 dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
1580 dasd_schedule_device_bh(device);
1582 dasd_schedule_block_bh(device->block);
1586 * Interrupt handler for "normal" ssch-io based dasd devices.
1588 void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1591 struct dasd_ccw_req *cqr, *next;
1592 struct dasd_device *device;
1593 unsigned long long now;
1596 kstat_cpu(smp_processor_id()).irqs[IOINT_DAS]++;
1598 switch (PTR_ERR(irb)) {
1602 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1603 "request timed out\n", __func__);
1606 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
1607 "unknown error %ld\n", __func__,
1610 dasd_handle_killed_request(cdev, intparm);
1615 cqr = (struct dasd_ccw_req *) intparm;
1616 /* check for conditions that should be handled immediately */
1618 !(scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1619 scsw_cstat(&irb->scsw) == 0)) {
1621 memcpy(&cqr->irb, irb, sizeof(*irb));
1622 device = dasd_device_from_cdev_locked(cdev);
1625 /* ignore unsolicited interrupts for DIAG discipline */
1626 if (device->discipline == dasd_diag_discipline_pointer) {
1627 dasd_put_device(device);
1630 device->discipline->dump_sense_dbf(device, irb, "int");
1631 if (device->features & DASD_FEATURE_ERPLOG)
1632 device->discipline->dump_sense(device, cqr, irb);
1633 device->discipline->check_for_device_change(device, cqr, irb);
1634 dasd_put_device(device);
1639 device = (struct dasd_device *) cqr->startdev;
1641 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
1642 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1643 "invalid device in request");
1647 /* Check for clear pending */
1648 if (cqr->status == DASD_CQR_CLEAR_PENDING &&
1649 scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) {
1650 cqr->status = DASD_CQR_CLEARED;
1651 dasd_device_clear_timer(device);
1652 wake_up(&dasd_flush_wq);
1653 dasd_schedule_device_bh(device);
1657 /* check status - the request might have been killed by dyn detach */
1658 if (cqr->status != DASD_CQR_IN_IO) {
1659 DBF_DEV_EVENT(DBF_DEBUG, device, "invalid status: bus_id %s, "
1660 "status %02x", dev_name(&cdev->dev), cqr->status);
1666 if (scsw_dstat(&irb->scsw) == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1667 scsw_cstat(&irb->scsw) == 0) {
1668 /* request was completed successfully */
1669 cqr->status = DASD_CQR_SUCCESS;
1671 /* Start first request on queue if possible -> fast_io. */
1672 if (cqr->devlist.next != &device->ccw_queue) {
1673 next = list_entry(cqr->devlist.next,
1674 struct dasd_ccw_req, devlist);
1676 } else { /* error */
1678 * If we don't want complex ERP for this request, then just
1679 * reset this and retry it in the fastpath
1681 if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags) &&
1683 if (cqr->lpm == device->path_data.opm)
1684 DBF_DEV_EVENT(DBF_DEBUG, device,
1685 "default ERP in fastpath "
1686 "(%i retries left)",
1688 if (!test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))
1689 cqr->lpm = device->path_data.opm;
1690 cqr->status = DASD_CQR_QUEUED;
1693 cqr->status = DASD_CQR_ERROR;
1695 if (next && (next->status == DASD_CQR_QUEUED) &&
1696 (!device->stopped)) {
1697 if (device->discipline->start_IO(next) == 0)
1698 expires = next->expires;
1701 dasd_device_set_timer(device, expires);
1703 dasd_device_clear_timer(device);
1704 dasd_schedule_device_bh(device);
1707 enum uc_todo dasd_generic_uc_handler(struct ccw_device *cdev, struct irb *irb)
1709 struct dasd_device *device;
1711 device = dasd_device_from_cdev_locked(cdev);
1715 if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
1716 device->state != device->target ||
1717 !device->discipline->check_for_device_change){
1718 dasd_put_device(device);
1721 if (device->discipline->dump_sense_dbf)
1722 device->discipline->dump_sense_dbf(device, irb, "uc");
1723 device->discipline->check_for_device_change(device, NULL, irb);
1724 dasd_put_device(device);
1726 return UC_TODO_RETRY;
1728 EXPORT_SYMBOL_GPL(dasd_generic_uc_handler);
1731 * If we have an error on a dasd_block layer request then we cancel
1732 * and return all further requests from the same dasd_block as well.
1734 static void __dasd_device_recovery(struct dasd_device *device,
1735 struct dasd_ccw_req *ref_cqr)
1737 struct list_head *l, *n;
1738 struct dasd_ccw_req *cqr;
1741 * only requeue request that came from the dasd_block layer
1743 if (!ref_cqr->block)
1746 list_for_each_safe(l, n, &device->ccw_queue) {
1747 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1748 if (cqr->status == DASD_CQR_QUEUED &&
1749 ref_cqr->block == cqr->block) {
1750 cqr->status = DASD_CQR_CLEARED;
1756 * Remove those ccw requests from the queue that need to be returned
1757 * to the upper layer.
1759 static void __dasd_device_process_ccw_queue(struct dasd_device *device,
1760 struct list_head *final_queue)
1762 struct list_head *l, *n;
1763 struct dasd_ccw_req *cqr;
1765 /* Process request with final status. */
1766 list_for_each_safe(l, n, &device->ccw_queue) {
1767 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1769 /* Stop list processing at the first non-final request. */
1770 if (cqr->status == DASD_CQR_QUEUED ||
1771 cqr->status == DASD_CQR_IN_IO ||
1772 cqr->status == DASD_CQR_CLEAR_PENDING)
1774 if (cqr->status == DASD_CQR_ERROR) {
1775 __dasd_device_recovery(device, cqr);
1777 /* Rechain finished requests to final queue */
1778 list_move_tail(&cqr->devlist, final_queue);
1783 * the cqrs from the final queue are returned to the upper layer
1784 * by setting a dasd_block state and calling the callback function
1786 static void __dasd_device_process_final_queue(struct dasd_device *device,
1787 struct list_head *final_queue)
1789 struct list_head *l, *n;
1790 struct dasd_ccw_req *cqr;
1791 struct dasd_block *block;
1792 void (*callback)(struct dasd_ccw_req *, void *data);
1793 void *callback_data;
1794 char errorstring[ERRORLENGTH];
1796 list_for_each_safe(l, n, final_queue) {
1797 cqr = list_entry(l, struct dasd_ccw_req, devlist);
1798 list_del_init(&cqr->devlist);
1800 callback = cqr->callback;
1801 callback_data = cqr->callback_data;
1803 spin_lock_bh(&block->queue_lock);
1804 switch (cqr->status) {
1805 case DASD_CQR_SUCCESS:
1806 cqr->status = DASD_CQR_DONE;
1808 case DASD_CQR_ERROR:
1809 cqr->status = DASD_CQR_NEED_ERP;
1811 case DASD_CQR_CLEARED:
1812 cqr->status = DASD_CQR_TERMINATED;
1815 /* internal error 12 - wrong cqr status*/
1816 snprintf(errorstring, ERRORLENGTH, "12 %p %x02", cqr, cqr->status);
1817 dev_err(&device->cdev->dev,
1818 "An error occurred in the DASD device driver, "
1819 "reason=%s\n", errorstring);
1822 if (cqr->callback != NULL)
1823 (callback)(cqr, callback_data);
1825 spin_unlock_bh(&block->queue_lock);
1830 * Take a look at the first request on the ccw queue and check
1831 * if it reached its expire time. If so, terminate the IO.
1833 static void __dasd_device_check_expire(struct dasd_device *device)
1835 struct dasd_ccw_req *cqr;
1837 if (list_empty(&device->ccw_queue))
1839 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1840 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1841 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1842 if (device->discipline->term_IO(cqr) != 0) {
1843 /* Hmpf, try again in 5 sec */
1844 dev_err(&device->cdev->dev,
1845 "cqr %p timed out (%lus) but cannot be "
1846 "ended, retrying in 5 s\n",
1847 cqr, (cqr->expires/HZ));
1848 cqr->expires += 5*HZ;
1849 dasd_device_set_timer(device, 5*HZ);
1851 dev_err(&device->cdev->dev,
1852 "cqr %p timed out (%lus), %i retries "
1853 "remaining\n", cqr, (cqr->expires/HZ),
1860 * Take a look at the first request on the ccw queue and check
1861 * if it needs to be started.
1863 static void __dasd_device_start_head(struct dasd_device *device)
1865 struct dasd_ccw_req *cqr;
1868 if (list_empty(&device->ccw_queue))
1870 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
1871 if (cqr->status != DASD_CQR_QUEUED)
1873 /* when device is stopped, return request to previous layer
1874 * exception: only the disconnect or unresumed bits are set and the
1875 * cqr is a path verification request
1877 if (device->stopped &&
1878 !(!(device->stopped & ~(DASD_STOPPED_DC_WAIT | DASD_UNRESUMED_PM))
1879 && test_bit(DASD_CQR_VERIFY_PATH, &cqr->flags))) {
1880 cqr->intrc = -EAGAIN;
1881 cqr->status = DASD_CQR_CLEARED;
1882 dasd_schedule_device_bh(device);
1886 rc = device->discipline->start_IO(cqr);
1888 dasd_device_set_timer(device, cqr->expires);
1889 else if (rc == -EACCES) {
1890 dasd_schedule_device_bh(device);
1892 /* Hmpf, try again in 1/2 sec */
1893 dasd_device_set_timer(device, 50);
1896 static void __dasd_device_check_path_events(struct dasd_device *device)
1900 if (device->path_data.tbvpm) {
1901 if (device->stopped & ~(DASD_STOPPED_DC_WAIT |
1904 rc = device->discipline->verify_path(
1905 device, device->path_data.tbvpm);
1907 dasd_device_set_timer(device, 50);
1909 device->path_data.tbvpm = 0;
1914 * Go through all request on the dasd_device request queue,
1915 * terminate them on the cdev if necessary, and return them to the
1916 * submitting layer via callback.
1918 * Make sure that all 'submitting layers' still exist when
1919 * this function is called!. In other words, when 'device' is a base
1920 * device then all block layer requests must have been removed before
1921 * via dasd_flush_block_queue.
1923 int dasd_flush_device_queue(struct dasd_device *device)
1925 struct dasd_ccw_req *cqr, *n;
1927 struct list_head flush_queue;
1929 INIT_LIST_HEAD(&flush_queue);
1930 spin_lock_irq(get_ccwdev_lock(device->cdev));
1932 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
1933 /* Check status and move request to flush_queue */
1934 switch (cqr->status) {
1935 case DASD_CQR_IN_IO:
1936 rc = device->discipline->term_IO(cqr);
1938 /* unable to terminate requeust */
1939 dev_err(&device->cdev->dev,
1940 "Flushing the DASD request queue "
1941 "failed for request %p\n", cqr);
1942 /* stop flush processing */
1946 case DASD_CQR_QUEUED:
1947 cqr->stopclk = get_clock();
1948 cqr->status = DASD_CQR_CLEARED;
1950 default: /* no need to modify the others */
1953 list_move_tail(&cqr->devlist, &flush_queue);
1956 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1958 * After this point all requests must be in state CLEAR_PENDING,
1959 * CLEARED, SUCCESS or ERROR. Now wait for CLEAR_PENDING to become
1960 * one of the others.
1962 list_for_each_entry_safe(cqr, n, &flush_queue, devlist)
1963 wait_event(dasd_flush_wq,
1964 (cqr->status != DASD_CQR_CLEAR_PENDING));
1966 * Now set each request back to TERMINATED, DONE or NEED_ERP
1967 * and call the callback function of flushed requests
1969 __dasd_device_process_final_queue(device, &flush_queue);
1974 * Acquire the device lock and process queues for the device.
1976 static void dasd_device_tasklet(struct dasd_device *device)
1978 struct list_head final_queue;
1980 atomic_set (&device->tasklet_scheduled, 0);
1981 INIT_LIST_HEAD(&final_queue);
1982 spin_lock_irq(get_ccwdev_lock(device->cdev));
1983 /* Check expire time of first request on the ccw queue. */
1984 __dasd_device_check_expire(device);
1985 /* find final requests on ccw queue */
1986 __dasd_device_process_ccw_queue(device, &final_queue);
1987 __dasd_device_check_path_events(device);
1988 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1989 /* Now call the callback function of requests with final status */
1990 __dasd_device_process_final_queue(device, &final_queue);
1991 spin_lock_irq(get_ccwdev_lock(device->cdev));
1992 /* Now check if the head of the ccw queue needs to be started. */
1993 __dasd_device_start_head(device);
1994 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1995 dasd_put_device(device);
1999 * Schedules a call to dasd_tasklet over the device tasklet.
2001 void dasd_schedule_device_bh(struct dasd_device *device)
2003 /* Protect against rescheduling. */
2004 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
2006 dasd_get_device(device);
2007 tasklet_hi_schedule(&device->tasklet);
2010 void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
2012 device->stopped |= bits;
2014 EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
2016 void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
2018 device->stopped &= ~bits;
2019 if (!device->stopped)
2020 wake_up(&generic_waitq);
2022 EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
2025 * Queue a request to the head of the device ccw_queue.
2026 * Start the I/O if possible.
2028 void dasd_add_request_head(struct dasd_ccw_req *cqr)
2030 struct dasd_device *device;
2031 unsigned long flags;
2033 device = cqr->startdev;
2034 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2035 cqr->status = DASD_CQR_QUEUED;
2036 list_add(&cqr->devlist, &device->ccw_queue);
2037 /* let the bh start the request to keep them in order */
2038 dasd_schedule_device_bh(device);
2039 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2043 * Queue a request to the tail of the device ccw_queue.
2044 * Start the I/O if possible.
2046 void dasd_add_request_tail(struct dasd_ccw_req *cqr)
2048 struct dasd_device *device;
2049 unsigned long flags;
2051 device = cqr->startdev;
2052 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2053 cqr->status = DASD_CQR_QUEUED;
2054 list_add_tail(&cqr->devlist, &device->ccw_queue);
2055 /* let the bh start the request to keep them in order */
2056 dasd_schedule_device_bh(device);
2057 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2061 * Wakeup helper for the 'sleep_on' functions.
2063 static void dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
2065 spin_lock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2066 cqr->callback_data = DASD_SLEEPON_END_TAG;
2067 spin_unlock_irq(get_ccwdev_lock(cqr->startdev->cdev));
2068 wake_up(&generic_waitq);
2071 static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
2073 struct dasd_device *device;
2076 device = cqr->startdev;
2077 spin_lock_irq(get_ccwdev_lock(device->cdev));
2078 rc = (cqr->callback_data == DASD_SLEEPON_END_TAG);
2079 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2084 * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
2086 static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
2088 struct dasd_device *device;
2089 dasd_erp_fn_t erp_fn;
2091 if (cqr->status == DASD_CQR_FILLED)
2093 device = cqr->startdev;
2094 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2095 if (cqr->status == DASD_CQR_TERMINATED) {
2096 device->discipline->handle_terminated_request(cqr);
2099 if (cqr->status == DASD_CQR_NEED_ERP) {
2100 erp_fn = device->discipline->erp_action(cqr);
2104 if (cqr->status == DASD_CQR_FAILED)
2105 dasd_log_sense(cqr, &cqr->irb);
2107 __dasd_process_erp(device, cqr);
2114 static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
2116 if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
2117 if (cqr->refers) /* erp is not done yet */
2119 return ((cqr->status != DASD_CQR_DONE) &&
2120 (cqr->status != DASD_CQR_FAILED));
2122 return (cqr->status == DASD_CQR_FILLED);
2125 static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
2127 struct dasd_device *device;
2129 struct list_head ccw_queue;
2130 struct dasd_ccw_req *cqr;
2132 INIT_LIST_HEAD(&ccw_queue);
2133 maincqr->status = DASD_CQR_FILLED;
2134 device = maincqr->startdev;
2135 list_add(&maincqr->blocklist, &ccw_queue);
2136 for (cqr = maincqr; __dasd_sleep_on_loop_condition(cqr);
2137 cqr = list_first_entry(&ccw_queue,
2138 struct dasd_ccw_req, blocklist)) {
2140 if (__dasd_sleep_on_erp(cqr))
2142 if (cqr->status != DASD_CQR_FILLED) /* could be failed */
2144 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2145 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2146 cqr->status = DASD_CQR_FAILED;
2147 cqr->intrc = -EPERM;
2150 /* Non-temporary stop condition will trigger fail fast */
2151 if (device->stopped & ~DASD_STOPPED_PENDING &&
2152 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2153 (!dasd_eer_enabled(device))) {
2154 cqr->status = DASD_CQR_FAILED;
2157 /* Don't try to start requests if device is stopped */
2158 if (interruptible) {
2159 rc = wait_event_interruptible(
2160 generic_waitq, !(device->stopped));
2161 if (rc == -ERESTARTSYS) {
2162 cqr->status = DASD_CQR_FAILED;
2163 maincqr->intrc = rc;
2167 wait_event(generic_waitq, !(device->stopped));
2169 cqr->callback = dasd_wakeup_cb;
2170 cqr->callback_data = DASD_SLEEPON_START_TAG;
2171 dasd_add_request_tail(cqr);
2172 if (interruptible) {
2173 rc = wait_event_interruptible(
2174 generic_waitq, _wait_for_wakeup(cqr));
2175 if (rc == -ERESTARTSYS) {
2176 dasd_cancel_req(cqr);
2177 /* wait (non-interruptible) for final status */
2178 wait_event(generic_waitq,
2179 _wait_for_wakeup(cqr));
2180 cqr->status = DASD_CQR_FAILED;
2181 maincqr->intrc = rc;
2185 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2188 maincqr->endclk = get_clock();
2189 if ((maincqr->status != DASD_CQR_DONE) &&
2190 (maincqr->intrc != -ERESTARTSYS))
2191 dasd_log_sense(maincqr, &maincqr->irb);
2192 if (maincqr->status == DASD_CQR_DONE)
2194 else if (maincqr->intrc)
2195 rc = maincqr->intrc;
2202 * Queue a request to the tail of the device ccw_queue and wait for
2205 int dasd_sleep_on(struct dasd_ccw_req *cqr)
2207 return _dasd_sleep_on(cqr, 0);
2211 * Queue a request to the tail of the device ccw_queue and wait
2212 * interruptible for it's completion.
2214 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
2216 return _dasd_sleep_on(cqr, 1);
2220 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
2221 * for eckd devices) the currently running request has to be terminated
2222 * and be put back to status queued, before the special request is added
2223 * to the head of the queue. Then the special request is waited on normally.
2225 static inline int _dasd_term_running_cqr(struct dasd_device *device)
2227 struct dasd_ccw_req *cqr;
2230 if (list_empty(&device->ccw_queue))
2232 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, devlist);
2233 rc = device->discipline->term_IO(cqr);
2236 * CQR terminated because a more important request is pending.
2237 * Undo decreasing of retry counter because this is
2238 * not an error case.
2244 int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
2246 struct dasd_device *device;
2249 device = cqr->startdev;
2250 if (test_bit(DASD_FLAG_LOCK_STOLEN, &device->flags) &&
2251 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2252 cqr->status = DASD_CQR_FAILED;
2253 cqr->intrc = -EPERM;
2256 spin_lock_irq(get_ccwdev_lock(device->cdev));
2257 rc = _dasd_term_running_cqr(device);
2259 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2262 cqr->callback = dasd_wakeup_cb;
2263 cqr->callback_data = DASD_SLEEPON_START_TAG;
2264 cqr->status = DASD_CQR_QUEUED;
2265 list_add(&cqr->devlist, &device->ccw_queue);
2267 /* let the bh start the request to keep them in order */
2268 dasd_schedule_device_bh(device);
2270 spin_unlock_irq(get_ccwdev_lock(device->cdev));
2272 wait_event(generic_waitq, _wait_for_wakeup(cqr));
2274 if (cqr->status == DASD_CQR_DONE)
2276 else if (cqr->intrc)
2284 * Cancels a request that was started with dasd_sleep_on_req.
2285 * This is useful to timeout requests. The request will be
2286 * terminated if it is currently in i/o.
2287 * Returns 1 if the request has been terminated.
2288 * 0 if there was no need to terminate the request (not started yet)
2289 * negative error code if termination failed
2290 * Cancellation of a request is an asynchronous operation! The calling
2291 * function has to wait until the request is properly returned via callback.
2293 int dasd_cancel_req(struct dasd_ccw_req *cqr)
2295 struct dasd_device *device = cqr->startdev;
2296 unsigned long flags;
2300 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
2301 switch (cqr->status) {
2302 case DASD_CQR_QUEUED:
2303 /* request was not started - just set to cleared */
2304 cqr->status = DASD_CQR_CLEARED;
2306 case DASD_CQR_IN_IO:
2307 /* request in IO - terminate IO and release again */
2308 rc = device->discipline->term_IO(cqr);
2310 dev_err(&device->cdev->dev,
2311 "Cancelling request %p failed with rc=%d\n",
2314 cqr->stopclk = get_clock();
2317 default: /* already finished or clear pending - do nothing */
2320 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
2321 dasd_schedule_device_bh(device);
2327 * SECTION: Operations of the dasd_block layer.
2331 * Timeout function for dasd_block. This is used when the block layer
2332 * is waiting for something that may not come reliably, (e.g. a state
2335 static void dasd_block_timeout(unsigned long ptr)
2337 unsigned long flags;
2338 struct dasd_block *block;
2340 block = (struct dasd_block *) ptr;
2341 spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
2342 /* re-activate request queue */
2343 dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
2344 spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
2345 dasd_schedule_block_bh(block);
2349 * Setup timeout for a dasd_block in jiffies.
2351 void dasd_block_set_timer(struct dasd_block *block, int expires)
2354 del_timer(&block->timer);
2356 mod_timer(&block->timer, jiffies + expires);
2360 * Clear timeout for a dasd_block.
2362 void dasd_block_clear_timer(struct dasd_block *block)
2364 del_timer(&block->timer);
2368 * Process finished error recovery ccw.
2370 static void __dasd_process_erp(struct dasd_device *device,
2371 struct dasd_ccw_req *cqr)
2373 dasd_erp_fn_t erp_fn;
2375 if (cqr->status == DASD_CQR_DONE)
2376 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
2378 dev_err(&device->cdev->dev, "ERP failed for the DASD\n");
2379 erp_fn = device->discipline->erp_postaction(cqr);
2384 * Fetch requests from the block device queue.
2386 static void __dasd_process_request_queue(struct dasd_block *block)
2388 struct request_queue *queue;
2389 struct request *req;
2390 struct dasd_ccw_req *cqr;
2391 struct dasd_device *basedev;
2392 unsigned long flags;
2393 queue = block->request_queue;
2394 basedev = block->base;
2395 /* No queue ? Then there is nothing to do. */
2400 * We requeue request from the block device queue to the ccw
2401 * queue only in two states. In state DASD_STATE_READY the
2402 * partition detection is done and we need to requeue requests
2403 * for that. State DASD_STATE_ONLINE is normal block device
2406 if (basedev->state < DASD_STATE_READY) {
2407 while ((req = blk_fetch_request(block->request_queue)))
2408 __blk_end_request_all(req, -EIO);
2411 /* Now we try to fetch requests from the request queue */
2412 while ((req = blk_peek_request(queue))) {
2413 if (basedev->features & DASD_FEATURE_READONLY &&
2414 rq_data_dir(req) == WRITE) {
2415 DBF_DEV_EVENT(DBF_ERR, basedev,
2416 "Rejecting write request %p",
2418 blk_start_request(req);
2419 __blk_end_request_all(req, -EIO);
2422 cqr = basedev->discipline->build_cp(basedev, block, req);
2424 if (PTR_ERR(cqr) == -EBUSY)
2425 break; /* normal end condition */
2426 if (PTR_ERR(cqr) == -ENOMEM)
2427 break; /* terminate request queue loop */
2428 if (PTR_ERR(cqr) == -EAGAIN) {
2430 * The current request cannot be build right
2431 * now, we have to try later. If this request
2432 * is the head-of-queue we stop the device
2435 if (!list_empty(&block->ccw_queue))
2438 get_ccwdev_lock(basedev->cdev), flags);
2439 dasd_device_set_stop_bits(basedev,
2440 DASD_STOPPED_PENDING);
2441 spin_unlock_irqrestore(
2442 get_ccwdev_lock(basedev->cdev), flags);
2443 dasd_block_set_timer(block, HZ/2);
2446 DBF_DEV_EVENT(DBF_ERR, basedev,
2447 "CCW creation failed (rc=%ld) "
2450 blk_start_request(req);
2451 __blk_end_request_all(req, -EIO);
2455 * Note: callback is set to dasd_return_cqr_cb in
2456 * __dasd_block_start_head to cover erp requests as well
2458 cqr->callback_data = (void *) req;
2459 cqr->status = DASD_CQR_FILLED;
2460 blk_start_request(req);
2461 list_add_tail(&cqr->blocklist, &block->ccw_queue);
2462 dasd_profile_start(block, cqr, req);
2466 static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
2468 struct request *req;
2472 req = (struct request *) cqr->callback_data;
2473 dasd_profile_end(cqr->block, cqr, req);
2474 status = cqr->block->base->discipline->free_cp(cqr, req);
2476 error = status ? status : -EIO;
2477 __blk_end_request_all(req, error);
2481 * Process ccw request queue.
2483 static void __dasd_process_block_ccw_queue(struct dasd_block *block,
2484 struct list_head *final_queue)
2486 struct list_head *l, *n;
2487 struct dasd_ccw_req *cqr;
2488 dasd_erp_fn_t erp_fn;
2489 unsigned long flags;
2490 struct dasd_device *base = block->base;
2493 /* Process request with final status. */
2494 list_for_each_safe(l, n, &block->ccw_queue) {
2495 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2496 if (cqr->status != DASD_CQR_DONE &&
2497 cqr->status != DASD_CQR_FAILED &&
2498 cqr->status != DASD_CQR_NEED_ERP &&
2499 cqr->status != DASD_CQR_TERMINATED)
2502 if (cqr->status == DASD_CQR_TERMINATED) {
2503 base->discipline->handle_terminated_request(cqr);
2507 /* Process requests that may be recovered */
2508 if (cqr->status == DASD_CQR_NEED_ERP) {
2509 erp_fn = base->discipline->erp_action(cqr);
2510 if (IS_ERR(erp_fn(cqr)))
2515 /* log sense for fatal error */
2516 if (cqr->status == DASD_CQR_FAILED) {
2517 dasd_log_sense(cqr, &cqr->irb);
2520 /* First of all call extended error reporting. */
2521 if (dasd_eer_enabled(base) &&
2522 cqr->status == DASD_CQR_FAILED) {
2523 dasd_eer_write(base, cqr, DASD_EER_FATALERROR);
2525 /* restart request */
2526 cqr->status = DASD_CQR_FILLED;
2528 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
2529 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
2530 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
2535 /* Process finished ERP request. */
2537 __dasd_process_erp(base, cqr);
2541 /* Rechain finished requests to final queue */
2542 cqr->endclk = get_clock();
2543 list_move_tail(&cqr->blocklist, final_queue);
2547 static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
2549 dasd_schedule_block_bh(cqr->block);
2552 static void __dasd_block_start_head(struct dasd_block *block)
2554 struct dasd_ccw_req *cqr;
2556 if (list_empty(&block->ccw_queue))
2558 /* We allways begin with the first requests on the queue, as some
2559 * of previously started requests have to be enqueued on a
2560 * dasd_device again for error recovery.
2562 list_for_each_entry(cqr, &block->ccw_queue, blocklist) {
2563 if (cqr->status != DASD_CQR_FILLED)
2565 if (test_bit(DASD_FLAG_LOCK_STOLEN, &block->base->flags) &&
2566 !test_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags)) {
2567 cqr->status = DASD_CQR_FAILED;
2568 cqr->intrc = -EPERM;
2569 dasd_schedule_block_bh(block);
2572 /* Non-temporary stop condition will trigger fail fast */
2573 if (block->base->stopped & ~DASD_STOPPED_PENDING &&
2574 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
2575 (!dasd_eer_enabled(block->base))) {
2576 cqr->status = DASD_CQR_FAILED;
2577 dasd_schedule_block_bh(block);
2580 /* Don't try to start requests if device is stopped */
2581 if (block->base->stopped)
2584 /* just a fail safe check, should not happen */
2586 cqr->startdev = block->base;
2588 /* make sure that the requests we submit find their way back */
2589 cqr->callback = dasd_return_cqr_cb;
2591 dasd_add_request_tail(cqr);
2596 * Central dasd_block layer routine. Takes requests from the generic
2597 * block layer request queue, creates ccw requests, enqueues them on
2598 * a dasd_device and processes ccw requests that have been returned.
2600 static void dasd_block_tasklet(struct dasd_block *block)
2602 struct list_head final_queue;
2603 struct list_head *l, *n;
2604 struct dasd_ccw_req *cqr;
2606 atomic_set(&block->tasklet_scheduled, 0);
2607 INIT_LIST_HEAD(&final_queue);
2608 spin_lock(&block->queue_lock);
2609 /* Finish off requests on ccw queue */
2610 __dasd_process_block_ccw_queue(block, &final_queue);
2611 spin_unlock(&block->queue_lock);
2612 /* Now call the callback function of requests with final status */
2613 spin_lock_irq(&block->request_queue_lock);
2614 list_for_each_safe(l, n, &final_queue) {
2615 cqr = list_entry(l, struct dasd_ccw_req, blocklist);
2616 list_del_init(&cqr->blocklist);
2617 __dasd_cleanup_cqr(cqr);
2619 spin_lock(&block->queue_lock);
2620 /* Get new request from the block device request queue */
2621 __dasd_process_request_queue(block);
2622 /* Now check if the head of the ccw queue needs to be started. */
2623 __dasd_block_start_head(block);
2624 spin_unlock(&block->queue_lock);
2625 spin_unlock_irq(&block->request_queue_lock);
2626 dasd_put_device(block->base);
2629 static void _dasd_wake_block_flush_cb(struct dasd_ccw_req *cqr, void *data)
2631 wake_up(&dasd_flush_wq);
2635 * Go through all request on the dasd_block request queue, cancel them
2636 * on the respective dasd_device, and return them to the generic
2639 static int dasd_flush_block_queue(struct dasd_block *block)
2641 struct dasd_ccw_req *cqr, *n;
2643 struct list_head flush_queue;
2645 INIT_LIST_HEAD(&flush_queue);
2646 spin_lock_bh(&block->queue_lock);
2649 list_for_each_entry_safe(cqr, n, &block->ccw_queue, blocklist) {
2650 /* if this request currently owned by a dasd_device cancel it */
2651 if (cqr->status >= DASD_CQR_QUEUED)
2652 rc = dasd_cancel_req(cqr);
2655 /* Rechain request (including erp chain) so it won't be
2656 * touched by the dasd_block_tasklet anymore.
2657 * Replace the callback so we notice when the request
2658 * is returned from the dasd_device layer.
2660 cqr->callback = _dasd_wake_block_flush_cb;
2661 for (i = 0; cqr != NULL; cqr = cqr->refers, i++)
2662 list_move_tail(&cqr->blocklist, &flush_queue);
2664 /* moved more than one request - need to restart */
2667 spin_unlock_bh(&block->queue_lock);
2668 /* Now call the callback function of flushed requests */
2670 list_for_each_entry_safe(cqr, n, &flush_queue, blocklist) {
2671 wait_event(dasd_flush_wq, (cqr->status < DASD_CQR_QUEUED));
2672 /* Process finished ERP request. */
2674 spin_lock_bh(&block->queue_lock);
2675 __dasd_process_erp(block->base, cqr);
2676 spin_unlock_bh(&block->queue_lock);
2677 /* restart list_for_xx loop since dasd_process_erp
2678 * might remove multiple elements */
2681 /* call the callback function */
2682 spin_lock_irq(&block->request_queue_lock);
2683 cqr->endclk = get_clock();
2684 list_del_init(&cqr->blocklist);
2685 __dasd_cleanup_cqr(cqr);
2686 spin_unlock_irq(&block->request_queue_lock);
2692 * Schedules a call to dasd_tasklet over the device tasklet.
2694 void dasd_schedule_block_bh(struct dasd_block *block)
2696 /* Protect against rescheduling. */
2697 if (atomic_cmpxchg(&block->tasklet_scheduled, 0, 1) != 0)
2699 /* life cycle of block is bound to it's base device */
2700 dasd_get_device(block->base);
2701 tasklet_hi_schedule(&block->tasklet);
2706 * SECTION: external block device operations
2707 * (request queue handling, open, release, etc.)
2711 * Dasd request queue function. Called from ll_rw_blk.c
2713 static void do_dasd_request(struct request_queue *queue)
2715 struct dasd_block *block;
2717 block = queue->queuedata;
2718 spin_lock(&block->queue_lock);
2719 /* Get new request from the block device request queue */
2720 __dasd_process_request_queue(block);
2721 /* Now check if the head of the ccw queue needs to be started. */
2722 __dasd_block_start_head(block);
2723 spin_unlock(&block->queue_lock);
2727 * Allocate and initialize request queue and default I/O scheduler.
2729 static int dasd_alloc_queue(struct dasd_block *block)
2733 block->request_queue = blk_init_queue(do_dasd_request,
2734 &block->request_queue_lock);
2735 if (block->request_queue == NULL)
2738 block->request_queue->queuedata = block;
2740 elevator_exit(block->request_queue->elevator);
2741 block->request_queue->elevator = NULL;
2742 rc = elevator_init(block->request_queue, "deadline");
2744 blk_cleanup_queue(block->request_queue);
2751 * Allocate and initialize request queue.
2753 static void dasd_setup_queue(struct dasd_block *block)
2757 if (block->base->features & DASD_FEATURE_USERAW) {
2759 * the max_blocks value for raw_track access is 256
2760 * it is higher than the native ECKD value because we
2761 * only need one ccw per track
2762 * so the max_hw_sectors are
2763 * 2048 x 512B = 1024kB = 16 tracks
2767 max = block->base->discipline->max_blocks << block->s2b_shift;
2769 blk_queue_logical_block_size(block->request_queue,
2771 blk_queue_max_hw_sectors(block->request_queue, max);
2772 blk_queue_max_segments(block->request_queue, -1L);
2773 /* with page sized segments we can translate each segement into
2776 blk_queue_max_segment_size(block->request_queue, PAGE_SIZE);
2777 blk_queue_segment_boundary(block->request_queue, PAGE_SIZE - 1);
2781 * Deactivate and free request queue.
2783 static void dasd_free_queue(struct dasd_block *block)
2785 if (block->request_queue) {
2786 blk_cleanup_queue(block->request_queue);
2787 block->request_queue = NULL;
2792 * Flush request on the request queue.
2794 static void dasd_flush_request_queue(struct dasd_block *block)
2796 struct request *req;
2798 if (!block->request_queue)
2801 spin_lock_irq(&block->request_queue_lock);
2802 while ((req = blk_fetch_request(block->request_queue)))
2803 __blk_end_request_all(req, -EIO);
2804 spin_unlock_irq(&block->request_queue_lock);
2807 static int dasd_open(struct block_device *bdev, fmode_t mode)
2809 struct dasd_device *base;
2812 base = dasd_device_from_gendisk(bdev->bd_disk);
2816 atomic_inc(&base->block->open_count);
2817 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
2822 if (!try_module_get(base->discipline->owner)) {
2827 if (dasd_probeonly) {
2828 dev_info(&base->cdev->dev,
2829 "Accessing the DASD failed because it is in "
2830 "probeonly mode\n");
2835 if (base->state <= DASD_STATE_BASIC) {
2836 DBF_DEV_EVENT(DBF_ERR, base, " %s",
2837 " Cannot open unrecognized device");
2842 if ((mode & FMODE_WRITE) &&
2843 (test_bit(DASD_FLAG_DEVICE_RO, &base->flags) ||
2844 (base->features & DASD_FEATURE_READONLY))) {
2849 dasd_put_device(base);
2853 module_put(base->discipline->owner);
2855 atomic_dec(&base->block->open_count);
2856 dasd_put_device(base);
2860 static int dasd_release(struct gendisk *disk, fmode_t mode)
2862 struct dasd_device *base;
2864 base = dasd_device_from_gendisk(disk);
2868 atomic_dec(&base->block->open_count);
2869 module_put(base->discipline->owner);
2870 dasd_put_device(base);
2875 * Return disk geometry.
2877 static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
2879 struct dasd_device *base;
2881 base = dasd_device_from_gendisk(bdev->bd_disk);
2885 if (!base->discipline ||
2886 !base->discipline->fill_geometry) {
2887 dasd_put_device(base);
2890 base->discipline->fill_geometry(base->block, geo);
2891 geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
2892 dasd_put_device(base);
2896 const struct block_device_operations
2897 dasd_device_operations = {
2898 .owner = THIS_MODULE,
2900 .release = dasd_release,
2901 .ioctl = dasd_ioctl,
2902 .compat_ioctl = dasd_ioctl,
2903 .getgeo = dasd_getgeo,
2906 /*******************************************************************************
2907 * end of block device operations
2913 #ifdef CONFIG_PROC_FS
2917 if (dasd_page_cache != NULL) {
2918 kmem_cache_destroy(dasd_page_cache);
2919 dasd_page_cache = NULL;
2921 dasd_gendisk_exit();
2923 if (dasd_debug_area != NULL) {
2924 debug_unregister(dasd_debug_area);
2925 dasd_debug_area = NULL;
2927 dasd_statistics_removeroot();
2931 * SECTION: common functions for ccw_driver use
2935 * Is the device read-only?
2936 * Note that this function does not report the setting of the
2937 * readonly device attribute, but how it is configured in z/VM.
2939 int dasd_device_is_ro(struct dasd_device *device)
2941 struct ccw_dev_id dev_id;
2942 struct diag210 diag_data;
2947 ccw_device_get_id(device->cdev, &dev_id);
2948 memset(&diag_data, 0, sizeof(diag_data));
2949 diag_data.vrdcdvno = dev_id.devno;
2950 diag_data.vrdclen = sizeof(diag_data);
2951 rc = diag210(&diag_data);
2952 if (rc == 0 || rc == 2) {
2953 return diag_data.vrdcvfla & 0x80;
2955 DBF_EVENT(DBF_WARNING, "diag210 failed for dev=%04x with rc=%d",
2960 EXPORT_SYMBOL_GPL(dasd_device_is_ro);
2962 static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
2964 struct ccw_device *cdev = data;
2967 ret = ccw_device_set_online(cdev);
2969 pr_warning("%s: Setting the DASD online failed with rc=%d\n",
2970 dev_name(&cdev->dev), ret);
2974 * Initial attempt at a probe function. this can be simplified once
2975 * the other detection code is gone.
2977 int dasd_generic_probe(struct ccw_device *cdev,
2978 struct dasd_discipline *discipline)
2982 ret = dasd_add_sysfs_files(cdev);
2984 DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
2985 "dasd_generic_probe: could not add "
2989 cdev->handler = &dasd_int_handler;
2992 * Automatically online either all dasd devices (dasd_autodetect)
2993 * or all devices specified with dasd= parameters during
2996 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
2997 (dasd_autodetect && dasd_busid_known(dev_name(&cdev->dev)) != 0))
2998 async_schedule(dasd_generic_auto_online, cdev);
3003 * This will one day be called from a global not_oper handler.
3004 * It is also used by driver_unregister during module unload.
3006 void dasd_generic_remove(struct ccw_device *cdev)
3008 struct dasd_device *device;
3009 struct dasd_block *block;
3011 cdev->handler = NULL;
3013 dasd_remove_sysfs_files(cdev);
3014 device = dasd_device_from_cdev(cdev);
3017 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3018 /* Already doing offline processing */
3019 dasd_put_device(device);
3023 * This device is removed unconditionally. Set offline
3024 * flag to prevent dasd_open from opening it while it is
3025 * no quite down yet.
3027 dasd_set_target_state(device, DASD_STATE_NEW);
3028 /* dasd_delete_device destroys the device reference. */
3029 block = device->block;
3030 dasd_delete_device(device);
3032 * life cycle of block is bound to device, so delete it after
3033 * device was safely removed
3036 dasd_free_block(block);
3040 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
3041 * the device is detected for the first time and is supposed to be used
3042 * or the user has started activation through sysfs.
3044 int dasd_generic_set_online(struct ccw_device *cdev,
3045 struct dasd_discipline *base_discipline)
3047 struct dasd_discipline *discipline;
3048 struct dasd_device *device;
3051 /* first online clears initial online feature flag */
3052 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
3053 device = dasd_create_device(cdev);
3055 return PTR_ERR(device);
3057 discipline = base_discipline;
3058 if (device->features & DASD_FEATURE_USEDIAG) {
3059 if (!dasd_diag_discipline_pointer) {
3060 pr_warning("%s Setting the DASD online failed because "
3061 "of missing DIAG discipline\n",
3062 dev_name(&cdev->dev));
3063 dasd_delete_device(device);
3066 discipline = dasd_diag_discipline_pointer;
3068 if (!try_module_get(base_discipline->owner)) {
3069 dasd_delete_device(device);
3072 if (!try_module_get(discipline->owner)) {
3073 module_put(base_discipline->owner);
3074 dasd_delete_device(device);
3077 device->base_discipline = base_discipline;
3078 device->discipline = discipline;
3080 /* check_device will allocate block device if necessary */
3081 rc = discipline->check_device(device);
3083 pr_warning("%s Setting the DASD online with discipline %s "
3084 "failed with rc=%i\n",
3085 dev_name(&cdev->dev), discipline->name, rc);
3086 module_put(discipline->owner);
3087 module_put(base_discipline->owner);
3088 dasd_delete_device(device);
3092 dasd_set_target_state(device, DASD_STATE_ONLINE);
3093 if (device->state <= DASD_STATE_KNOWN) {
3094 pr_warning("%s Setting the DASD online failed because of a "
3095 "missing discipline\n", dev_name(&cdev->dev));
3097 dasd_set_target_state(device, DASD_STATE_NEW);
3099 dasd_free_block(device->block);
3100 dasd_delete_device(device);
3102 pr_debug("dasd_generic device %s found\n",
3103 dev_name(&cdev->dev));
3105 wait_event(dasd_init_waitq, _wait_for_device(device));
3107 dasd_put_device(device);
3111 int dasd_generic_set_offline(struct ccw_device *cdev)
3113 struct dasd_device *device;
3114 struct dasd_block *block;
3115 int max_count, open_count;
3117 device = dasd_device_from_cdev(cdev);
3119 return PTR_ERR(device);
3120 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
3121 /* Already doing offline processing */
3122 dasd_put_device(device);
3126 * We must make sure that this device is currently not in use.
3127 * The open_count is increased for every opener, that includes
3128 * the blkdev_get in dasd_scan_partitions. We are only interested
3129 * in the other openers.
3131 if (device->block) {
3132 max_count = device->block->bdev ? 0 : -1;
3133 open_count = atomic_read(&device->block->open_count);
3134 if (open_count > max_count) {
3136 pr_warning("%s: The DASD cannot be set offline "
3137 "with open count %i\n",
3138 dev_name(&cdev->dev), open_count);
3140 pr_warning("%s: The DASD cannot be set offline "
3141 "while it is in use\n",
3142 dev_name(&cdev->dev));
3143 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
3144 dasd_put_device(device);
3148 dasd_set_target_state(device, DASD_STATE_NEW);
3149 /* dasd_delete_device destroys the device reference. */
3150 block = device->block;
3151 dasd_delete_device(device);
3153 * life cycle of block is bound to device, so delete it after
3154 * device was safely removed
3157 dasd_free_block(block);
3161 int dasd_generic_last_path_gone(struct dasd_device *device)
3163 struct dasd_ccw_req *cqr;
3165 dev_warn(&device->cdev->dev, "No operational channel path is left "
3166 "for the device\n");
3167 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "last path gone");
3168 /* First of all call extended error reporting. */
3169 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
3171 if (device->state < DASD_STATE_BASIC)
3173 /* Device is active. We want to keep it. */
3174 list_for_each_entry(cqr, &device->ccw_queue, devlist)
3175 if ((cqr->status == DASD_CQR_IN_IO) ||
3176 (cqr->status == DASD_CQR_CLEAR_PENDING)) {
3177 cqr->status = DASD_CQR_QUEUED;
3180 dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
3181 dasd_device_clear_timer(device);
3182 dasd_schedule_device_bh(device);
3185 EXPORT_SYMBOL_GPL(dasd_generic_last_path_gone);
3187 int dasd_generic_path_operational(struct dasd_device *device)
3189 dev_info(&device->cdev->dev, "A channel path to the device has become "
3191 DBF_DEV_EVENT(DBF_WARNING, device, "%s", "path operational");
3192 dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
3193 if (device->stopped & DASD_UNRESUMED_PM) {
3194 dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
3195 dasd_restore_device(device);
3198 dasd_schedule_device_bh(device);
3200 dasd_schedule_block_bh(device->block);
3203 EXPORT_SYMBOL_GPL(dasd_generic_path_operational);
3205 int dasd_generic_notify(struct ccw_device *cdev, int event)
3207 struct dasd_device *device;
3210 device = dasd_device_from_cdev_locked(cdev);
3218 device->path_data.opm = 0;
3219 device->path_data.ppm = 0;
3220 device->path_data.npm = 0;
3221 ret = dasd_generic_last_path_gone(device);
3225 if (device->path_data.opm)
3226 ret = dasd_generic_path_operational(device);
3229 dasd_put_device(device);
3233 void dasd_generic_path_event(struct ccw_device *cdev, int *path_event)
3236 __u8 oldopm, eventlpm;
3237 struct dasd_device *device;
3239 device = dasd_device_from_cdev_locked(cdev);
3242 for (chp = 0; chp < 8; chp++) {
3243 eventlpm = 0x80 >> chp;
3244 if (path_event[chp] & PE_PATH_GONE) {
3245 oldopm = device->path_data.opm;
3246 device->path_data.opm &= ~eventlpm;
3247 device->path_data.ppm &= ~eventlpm;
3248 device->path_data.npm &= ~eventlpm;
3249 if (oldopm && !device->path_data.opm)
3250 dasd_generic_last_path_gone(device);
3252 if (path_event[chp] & PE_PATH_AVAILABLE) {
3253 device->path_data.opm &= ~eventlpm;
3254 device->path_data.ppm &= ~eventlpm;
3255 device->path_data.npm &= ~eventlpm;
3256 device->path_data.tbvpm |= eventlpm;
3257 dasd_schedule_device_bh(device);
3260 dasd_put_device(device);
3262 EXPORT_SYMBOL_GPL(dasd_generic_path_event);
3264 int dasd_generic_verify_path(struct dasd_device *device, __u8 lpm)
3266 if (!device->path_data.opm && lpm) {
3267 device->path_data.opm = lpm;
3268 dasd_generic_path_operational(device);
3270 device->path_data.opm |= lpm;
3273 EXPORT_SYMBOL_GPL(dasd_generic_verify_path);
3276 int dasd_generic_pm_freeze(struct ccw_device *cdev)
3278 struct dasd_ccw_req *cqr, *n;
3280 struct list_head freeze_queue;
3281 struct dasd_device *device = dasd_device_from_cdev(cdev);
3284 return PTR_ERR(device);
3286 if (device->discipline->freeze)
3287 rc = device->discipline->freeze(device);
3289 /* disallow new I/O */
3290 dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
3291 /* clear active requests */
3292 INIT_LIST_HEAD(&freeze_queue);
3293 spin_lock_irq(get_ccwdev_lock(cdev));
3295 list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
3296 /* Check status and move request to flush_queue */
3297 if (cqr->status == DASD_CQR_IN_IO) {
3298 rc = device->discipline->term_IO(cqr);
3300 /* unable to terminate requeust */
3301 dev_err(&device->cdev->dev,
3302 "Unable to terminate request %p "
3303 "on suspend\n", cqr);
3304 spin_unlock_irq(get_ccwdev_lock(cdev));
3305 dasd_put_device(device);
3309 list_move_tail(&cqr->devlist, &freeze_queue);
3312 spin_unlock_irq(get_ccwdev_lock(cdev));
3314 list_for_each_entry_safe(cqr, n, &freeze_queue, devlist) {
3315 wait_event(dasd_flush_wq,
3316 (cqr->status != DASD_CQR_CLEAR_PENDING));
3317 if (cqr->status == DASD_CQR_CLEARED)
3318 cqr->status = DASD_CQR_QUEUED;
3320 /* move freeze_queue to start of the ccw_queue */
3321 spin_lock_irq(get_ccwdev_lock(cdev));
3322 list_splice_tail(&freeze_queue, &device->ccw_queue);
3323 spin_unlock_irq(get_ccwdev_lock(cdev));
3325 dasd_put_device(device);
3328 EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
3330 int dasd_generic_restore_device(struct ccw_device *cdev)
3332 struct dasd_device *device = dasd_device_from_cdev(cdev);
3336 return PTR_ERR(device);
3338 /* allow new IO again */
3339 dasd_device_remove_stop_bits(device,
3340 (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
3342 dasd_schedule_device_bh(device);
3345 * call discipline restore function
3346 * if device is stopped do nothing e.g. for disconnected devices
3348 if (device->discipline->restore && !(device->stopped))
3349 rc = device->discipline->restore(device);
3350 if (rc || device->stopped)
3352 * if the resume failed for the DASD we put it in
3353 * an UNRESUMED stop state
3355 device->stopped |= DASD_UNRESUMED_PM;
3358 dasd_schedule_block_bh(device->block);
3360 dasd_put_device(device);
3363 EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
3365 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
3367 int rdc_buffer_size,
3370 struct dasd_ccw_req *cqr;
3372 unsigned long *idaw;
3374 cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
3377 /* internal error 13 - Allocating the RDC request failed*/
3378 dev_err(&device->cdev->dev,
3379 "An error occurred in the DASD device driver, "
3380 "reason=%s\n", "13");
3385 ccw->cmd_code = CCW_CMD_RDC;
3386 if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
3387 idaw = (unsigned long *) (cqr->data);
3388 ccw->cda = (__u32)(addr_t) idaw;
3389 ccw->flags = CCW_FLAG_IDA;
3390 idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
3392 ccw->cda = (__u32)(addr_t) rdc_buffer;
3396 ccw->count = rdc_buffer_size;
3397 cqr->startdev = device;
3398 cqr->memdev = device;
3399 cqr->expires = 10*HZ;
3401 cqr->buildclk = get_clock();
3402 cqr->status = DASD_CQR_FILLED;
3407 int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
3408 void *rdc_buffer, int rdc_buffer_size)
3411 struct dasd_ccw_req *cqr;
3413 cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
3416 return PTR_ERR(cqr);
3418 ret = dasd_sleep_on(cqr);
3419 dasd_sfree_request(cqr, cqr->memdev);
3422 EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
3425 * In command mode and transport mode we need to look for sense
3426 * data in different places. The sense data itself is allways
3427 * an array of 32 bytes, so we can unify the sense data access
3430 char *dasd_get_sense(struct irb *irb)
3432 struct tsb *tsb = NULL;
3435 if (scsw_is_tm(&irb->scsw) && (irb->scsw.tm.fcxs == 0x01)) {
3436 if (irb->scsw.tm.tcw)
3437 tsb = tcw_get_tsb((struct tcw *)(unsigned long)
3439 if (tsb && tsb->length == 64 && tsb->flags)
3440 switch (tsb->flags & 0x07) {
3441 case 1: /* tsa_iostat */
3442 sense = tsb->tsa.iostat.sense;
3444 case 2: /* tsa_ddpc */
3445 sense = tsb->tsa.ddpc.sense;
3448 /* currently we don't use interrogate data */
3451 } else if (irb->esw.esw0.erw.cons) {
3456 EXPORT_SYMBOL_GPL(dasd_get_sense);
3458 static int __init dasd_init(void)
3462 init_waitqueue_head(&dasd_init_waitq);
3463 init_waitqueue_head(&dasd_flush_wq);
3464 init_waitqueue_head(&generic_waitq);
3466 /* register 'common' DASD debug area, used for all DBF_XXX calls */
3467 dasd_debug_area = debug_register("dasd", 1, 1, 8 * sizeof(long));
3468 if (dasd_debug_area == NULL) {
3472 debug_register_view(dasd_debug_area, &debug_sprintf_view);
3473 debug_set_level(dasd_debug_area, DBF_WARNING);
3475 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
3477 dasd_diag_discipline_pointer = NULL;
3479 dasd_statistics_createroot();
3481 rc = dasd_devmap_init();
3484 rc = dasd_gendisk_init();
3490 rc = dasd_eer_init();
3493 #ifdef CONFIG_PROC_FS
3494 rc = dasd_proc_init();
3501 pr_info("The DASD device driver could not be initialized\n");
3506 module_init(dasd_init);
3507 module_exit(dasd_exit);
3509 EXPORT_SYMBOL(dasd_debug_area);
3510 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
3512 EXPORT_SYMBOL(dasd_add_request_head);
3513 EXPORT_SYMBOL(dasd_add_request_tail);
3514 EXPORT_SYMBOL(dasd_cancel_req);
3515 EXPORT_SYMBOL(dasd_device_clear_timer);
3516 EXPORT_SYMBOL(dasd_block_clear_timer);
3517 EXPORT_SYMBOL(dasd_enable_device);
3518 EXPORT_SYMBOL(dasd_int_handler);
3519 EXPORT_SYMBOL(dasd_kfree_request);
3520 EXPORT_SYMBOL(dasd_kick_device);
3521 EXPORT_SYMBOL(dasd_kmalloc_request);
3522 EXPORT_SYMBOL(dasd_schedule_device_bh);
3523 EXPORT_SYMBOL(dasd_schedule_block_bh);
3524 EXPORT_SYMBOL(dasd_set_target_state);
3525 EXPORT_SYMBOL(dasd_device_set_timer);
3526 EXPORT_SYMBOL(dasd_block_set_timer);
3527 EXPORT_SYMBOL(dasd_sfree_request);
3528 EXPORT_SYMBOL(dasd_sleep_on);
3529 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
3530 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
3531 EXPORT_SYMBOL(dasd_smalloc_request);
3532 EXPORT_SYMBOL(dasd_start_IO);
3533 EXPORT_SYMBOL(dasd_term_IO);
3535 EXPORT_SYMBOL_GPL(dasd_generic_probe);
3536 EXPORT_SYMBOL_GPL(dasd_generic_remove);
3537 EXPORT_SYMBOL_GPL(dasd_generic_notify);
3538 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
3539 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
3540 EXPORT_SYMBOL_GPL(dasd_generic_handle_state_change);
3541 EXPORT_SYMBOL_GPL(dasd_flush_device_queue);
3542 EXPORT_SYMBOL_GPL(dasd_alloc_block);
3543 EXPORT_SYMBOL_GPL(dasd_free_block);