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 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
12 #include <linux/config.h>
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/buffer_head.h>
20 #include <linux/hdreg.h>
22 #include <asm/ccwdev.h>
23 #include <asm/ebcdic.h>
24 #include <asm/idals.h>
25 #include <asm/todclk.h>
28 #define PRINTK_HEADER "dasd:"
32 * SECTION: Constant definitions to be used within this file
34 #define DASD_CHANQ_MAX_SIZE 4
37 * SECTION: exported variables of dasd.c
39 debug_info_t *dasd_debug_area;
40 struct dasd_discipline *dasd_diag_discipline_pointer;
42 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
43 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
44 " Copyright 2000 IBM Corporation");
45 MODULE_SUPPORTED_DEVICE("dasd");
46 MODULE_PARM(dasd, "1-" __MODULE_STRING(256) "s");
47 MODULE_LICENSE("GPL");
50 * SECTION: prototypes for static functions of dasd.c
52 static int dasd_alloc_queue(struct dasd_device * device);
53 static void dasd_setup_queue(struct dasd_device * device);
54 static void dasd_free_queue(struct dasd_device * device);
55 static void dasd_flush_request_queue(struct dasd_device *);
56 static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
57 static void dasd_flush_ccw_queue(struct dasd_device *, int);
58 static void dasd_tasklet(struct dasd_device *);
59 static void do_kick_device(void *data);
62 * SECTION: Operations on the device structure.
64 static wait_queue_head_t dasd_init_waitq;
67 * Allocate memory for a new device structure.
70 dasd_alloc_device(void)
72 struct dasd_device *device;
74 device = kmalloc(sizeof (struct dasd_device), GFP_ATOMIC);
76 return ERR_PTR(-ENOMEM);
77 memset(device, 0, sizeof (struct dasd_device));
78 /* open_count = 0 means device online but not in use */
79 atomic_set(&device->open_count, -1);
81 /* Get two pages for normal block device operations. */
82 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
83 if (device->ccw_mem == NULL) {
85 return ERR_PTR(-ENOMEM);
87 /* Get one page for error recovery. */
88 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
89 if (device->erp_mem == NULL) {
90 free_pages((unsigned long) device->ccw_mem, 1);
92 return ERR_PTR(-ENOMEM);
95 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
96 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
97 spin_lock_init(&device->mem_lock);
98 spin_lock_init(&device->request_queue_lock);
99 atomic_set (&device->tasklet_scheduled, 0);
100 tasklet_init(&device->tasklet,
101 (void (*)(unsigned long)) dasd_tasklet,
102 (unsigned long) device);
103 INIT_LIST_HEAD(&device->ccw_queue);
104 init_timer(&device->timer);
105 INIT_WORK(&device->kick_work, do_kick_device, device);
106 device->state = DASD_STATE_NEW;
107 device->target = DASD_STATE_NEW;
113 * Free memory of a device structure.
116 dasd_free_device(struct dasd_device *device)
118 kfree(device->private);
119 free_page((unsigned long) device->erp_mem);
120 free_pages((unsigned long) device->ccw_mem, 1);
125 * Make a new device known to the system.
128 dasd_state_new_to_known(struct dasd_device *device)
133 * As long as the device is not in state DASD_STATE_NEW we want to
134 * keep the reference count > 0.
136 dasd_get_device(device);
138 rc = dasd_alloc_queue(device);
140 dasd_put_device(device);
144 device->state = DASD_STATE_KNOWN;
149 * Let the system forget about a device.
152 dasd_state_known_to_new(struct dasd_device * device)
154 /* Disable extended error reporting for this device. */
155 dasd_eer_disable(device);
156 /* Forget the discipline information. */
157 if (device->discipline)
158 module_put(device->discipline->owner);
159 device->discipline = NULL;
160 if (device->base_discipline)
161 module_put(device->base_discipline->owner);
162 device->base_discipline = NULL;
163 device->state = DASD_STATE_NEW;
165 dasd_free_queue(device);
167 /* Give up reference we took in dasd_state_new_to_known. */
168 dasd_put_device(device);
172 * Request the irq line for the device.
175 dasd_state_known_to_basic(struct dasd_device * device)
179 /* Allocate and register gendisk structure. */
180 rc = dasd_gendisk_alloc(device);
184 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
185 device->debug_area = debug_register(device->cdev->dev.bus_id, 1, 2,
187 debug_register_view(device->debug_area, &debug_sprintf_view);
188 debug_set_level(device->debug_area, DBF_EMERG);
189 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
191 device->state = DASD_STATE_BASIC;
196 * Release the irq line for the device. Terminate any running i/o.
199 dasd_state_basic_to_known(struct dasd_device * device)
201 dasd_gendisk_free(device);
202 dasd_flush_ccw_queue(device, 1);
203 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
204 if (device->debug_area != NULL) {
205 debug_unregister(device->debug_area);
206 device->debug_area = NULL;
208 device->state = DASD_STATE_KNOWN;
212 * Do the initial analysis. The do_analysis function may return
213 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
214 * until the discipline decides to continue the startup sequence
215 * by calling the function dasd_change_state. The eckd disciplines
216 * uses this to start a ccw that detects the format. The completion
217 * interrupt for this detection ccw uses the kernel event daemon to
218 * trigger the call to dasd_change_state. All this is done in the
219 * discipline code, see dasd_eckd.c.
220 * After the analysis ccw is done (do_analysis returned 0) the block
222 * In case the analysis returns an error, the device setup is stopped
223 * (a fake disk was already added to allow formatting).
226 dasd_state_basic_to_ready(struct dasd_device * device)
231 if (device->discipline->do_analysis != NULL)
232 rc = device->discipline->do_analysis(device);
235 device->state = DASD_STATE_UNFMT;
238 /* make disk known with correct capacity */
239 dasd_setup_queue(device);
240 set_capacity(device->gdp, device->blocks << device->s2b_shift);
241 device->state = DASD_STATE_READY;
242 rc = dasd_scan_partitions(device);
244 device->state = DASD_STATE_BASIC;
249 * Remove device from block device layer. Destroy dirty buffers.
250 * Forget format information. Check if the target level is basic
251 * and if it is create fake disk for formatting.
254 dasd_state_ready_to_basic(struct dasd_device * device)
256 dasd_flush_ccw_queue(device, 0);
257 dasd_destroy_partitions(device);
258 dasd_flush_request_queue(device);
260 device->bp_block = 0;
261 device->s2b_shift = 0;
262 device->state = DASD_STATE_BASIC;
269 dasd_state_unfmt_to_basic(struct dasd_device * device)
271 device->state = DASD_STATE_BASIC;
275 * Make the device online and schedule the bottom half to start
276 * the requeueing of requests from the linux request queue to the
280 dasd_state_ready_to_online(struct dasd_device * device)
282 device->state = DASD_STATE_ONLINE;
283 dasd_schedule_bh(device);
288 * Stop the requeueing of requests again.
291 dasd_state_online_to_ready(struct dasd_device * device)
293 device->state = DASD_STATE_READY;
297 * Device startup state changes.
300 dasd_increase_state(struct dasd_device *device)
305 if (device->state == DASD_STATE_NEW &&
306 device->target >= DASD_STATE_KNOWN)
307 rc = dasd_state_new_to_known(device);
310 device->state == DASD_STATE_KNOWN &&
311 device->target >= DASD_STATE_BASIC)
312 rc = dasd_state_known_to_basic(device);
315 device->state == DASD_STATE_BASIC &&
316 device->target >= DASD_STATE_READY)
317 rc = dasd_state_basic_to_ready(device);
320 device->state == DASD_STATE_READY &&
321 device->target >= DASD_STATE_ONLINE)
322 rc = dasd_state_ready_to_online(device);
328 * Device shutdown state changes.
331 dasd_decrease_state(struct dasd_device *device)
333 if (device->state == DASD_STATE_ONLINE &&
334 device->target <= DASD_STATE_READY)
335 dasd_state_online_to_ready(device);
337 if (device->state == DASD_STATE_READY &&
338 device->target <= DASD_STATE_BASIC)
339 dasd_state_ready_to_basic(device);
341 if (device->state == DASD_STATE_UNFMT &&
342 device->target <= DASD_STATE_BASIC)
343 dasd_state_unfmt_to_basic(device);
345 if (device->state == DASD_STATE_BASIC &&
346 device->target <= DASD_STATE_KNOWN)
347 dasd_state_basic_to_known(device);
349 if (device->state == DASD_STATE_KNOWN &&
350 device->target <= DASD_STATE_NEW)
351 dasd_state_known_to_new(device);
357 * This is the main startup/shutdown routine.
360 dasd_change_state(struct dasd_device *device)
364 if (device->state == device->target)
365 /* Already where we want to go today... */
367 if (device->state < device->target)
368 rc = dasd_increase_state(device);
370 rc = dasd_decrease_state(device);
371 if (rc && rc != -EAGAIN)
372 device->target = device->state;
374 if (device->state == device->target)
375 wake_up(&dasd_init_waitq);
379 * Kick starter for devices that did not complete the startup/shutdown
380 * procedure or were sleeping because of a pending state.
381 * dasd_kick_device will schedule a call do do_kick_device to the kernel
385 do_kick_device(void *data)
387 struct dasd_device *device;
389 device = (struct dasd_device *) data;
390 dasd_change_state(device);
391 dasd_schedule_bh(device);
392 dasd_put_device(device);
396 dasd_kick_device(struct dasd_device *device)
398 dasd_get_device(device);
399 /* queue call to dasd_kick_device to the kernel event daemon. */
400 schedule_work(&device->kick_work);
404 * Set the target state for a device and starts the state change.
407 dasd_set_target_state(struct dasd_device *device, int target)
409 /* If we are in probeonly mode stop at DASD_STATE_READY. */
410 if (dasd_probeonly && target > DASD_STATE_READY)
411 target = DASD_STATE_READY;
412 if (device->target != target) {
413 if (device->state == target)
414 wake_up(&dasd_init_waitq);
415 device->target = target;
417 if (device->state != device->target)
418 dasd_change_state(device);
422 * Enable devices with device numbers in [from..to].
425 _wait_for_device(struct dasd_device *device)
427 return (device->state == device->target);
431 dasd_enable_device(struct dasd_device *device)
433 dasd_set_target_state(device, DASD_STATE_ONLINE);
434 if (device->state <= DASD_STATE_KNOWN)
435 /* No discipline for device found. */
436 dasd_set_target_state(device, DASD_STATE_NEW);
437 /* Now wait for the devices to come up. */
438 wait_event(dasd_init_waitq, _wait_for_device(device));
442 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
444 #ifdef CONFIG_DASD_PROFILE
446 struct dasd_profile_info_t dasd_global_profile;
447 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
450 * Increments counter in global and local profiling structures.
452 #define dasd_profile_counter(value, counter, device) \
455 for (index = 0; index < 31 && value >> (2+index); index++); \
456 dasd_global_profile.counter[index]++; \
457 device->profile.counter[index]++; \
461 * Add profiling information for cqr before execution.
464 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
468 unsigned int counter;
470 if (dasd_profile_level != DASD_PROFILE_ON)
473 /* count the length of the chanq for statistics */
475 list_for_each(l, &device->ccw_queue)
478 dasd_global_profile.dasd_io_nr_req[counter]++;
479 device->profile.dasd_io_nr_req[counter]++;
483 * Add profiling information for cqr after execution.
486 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
489 long strtime, irqtime, endtime, tottime; /* in microseconds */
490 long tottimeps, sectors;
492 if (dasd_profile_level != DASD_PROFILE_ON)
495 sectors = req->nr_sectors;
496 if (!cqr->buildclk || !cqr->startclk ||
497 !cqr->stopclk || !cqr->endclk ||
501 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
502 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
503 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
504 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
505 tottimeps = tottime / sectors;
507 if (!dasd_global_profile.dasd_io_reqs)
508 memset(&dasd_global_profile, 0,
509 sizeof (struct dasd_profile_info_t));
510 dasd_global_profile.dasd_io_reqs++;
511 dasd_global_profile.dasd_io_sects += sectors;
513 if (!device->profile.dasd_io_reqs)
514 memset(&device->profile, 0,
515 sizeof (struct dasd_profile_info_t));
516 device->profile.dasd_io_reqs++;
517 device->profile.dasd_io_sects += sectors;
519 dasd_profile_counter(sectors, dasd_io_secs, device);
520 dasd_profile_counter(tottime, dasd_io_times, device);
521 dasd_profile_counter(tottimeps, dasd_io_timps, device);
522 dasd_profile_counter(strtime, dasd_io_time1, device);
523 dasd_profile_counter(irqtime, dasd_io_time2, device);
524 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
525 dasd_profile_counter(endtime, dasd_io_time3, device);
528 #define dasd_profile_start(device, cqr, req) do {} while (0)
529 #define dasd_profile_end(device, cqr, req) do {} while (0)
530 #endif /* CONFIG_DASD_PROFILE */
533 * Allocate memory for a channel program with 'cplength' channel
534 * command words and 'datasize' additional space. There are two
535 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
536 * memory and 2) dasd_smalloc_request uses the static ccw memory
537 * that gets allocated for each device.
539 struct dasd_ccw_req *
540 dasd_kmalloc_request(char *magic, int cplength, int datasize,
541 struct dasd_device * device)
543 struct dasd_ccw_req *cqr;
546 if ( magic == NULL || datasize > PAGE_SIZE ||
547 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
550 cqr = kmalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
552 return ERR_PTR(-ENOMEM);
553 memset(cqr, 0, sizeof(struct dasd_ccw_req));
556 cqr->cpaddr = kmalloc(cplength*sizeof(struct ccw1),
557 GFP_ATOMIC | GFP_DMA);
558 if (cqr->cpaddr == NULL) {
560 return ERR_PTR(-ENOMEM);
562 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
566 cqr->data = kmalloc(datasize, GFP_ATOMIC | GFP_DMA);
567 if (cqr->data == NULL) {
570 return ERR_PTR(-ENOMEM);
572 memset(cqr->data, 0, datasize);
574 strncpy((char *) &cqr->magic, magic, 4);
575 ASCEBC((char *) &cqr->magic, 4);
576 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
577 dasd_get_device(device);
581 struct dasd_ccw_req *
582 dasd_smalloc_request(char *magic, int cplength, int datasize,
583 struct dasd_device * device)
586 struct dasd_ccw_req *cqr;
591 if ( magic == NULL || datasize > PAGE_SIZE ||
592 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
595 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
597 size += cplength * sizeof(struct ccw1);
600 spin_lock_irqsave(&device->mem_lock, flags);
601 cqr = (struct dasd_ccw_req *)
602 dasd_alloc_chunk(&device->ccw_chunks, size);
603 spin_unlock_irqrestore(&device->mem_lock, flags);
605 return ERR_PTR(-ENOMEM);
606 memset(cqr, 0, sizeof(struct dasd_ccw_req));
607 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
610 cqr->cpaddr = (struct ccw1 *) data;
611 data += cplength*sizeof(struct ccw1);
612 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
617 memset(cqr->data, 0, datasize);
619 strncpy((char *) &cqr->magic, magic, 4);
620 ASCEBC((char *) &cqr->magic, 4);
621 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
622 dasd_get_device(device);
627 * Free memory of a channel program. This function needs to free all the
628 * idal lists that might have been created by dasd_set_cda and the
629 * struct dasd_ccw_req itself.
632 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
637 /* Clear any idals used for the request. */
640 clear_normalized_cda(ccw);
641 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
646 dasd_put_device(device);
650 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
654 spin_lock_irqsave(&device->mem_lock, flags);
655 dasd_free_chunk(&device->ccw_chunks, cqr);
656 spin_unlock_irqrestore(&device->mem_lock, flags);
657 dasd_put_device(device);
661 * Check discipline magic in cqr.
664 dasd_check_cqr(struct dasd_ccw_req *cqr)
666 struct dasd_device *device;
670 device = cqr->device;
671 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
672 DEV_MESSAGE(KERN_WARNING, device,
673 " dasd_ccw_req 0x%08x magic doesn't match"
674 " discipline 0x%08x",
676 *(unsigned int *) device->discipline->name);
683 * Terminate the current i/o and set the request to clear_pending.
684 * Timer keeps device runnig.
685 * ccw_device_clear can fail if the i/o subsystem
689 dasd_term_IO(struct dasd_ccw_req * cqr)
691 struct dasd_device *device;
695 rc = dasd_check_cqr(cqr);
699 device = (struct dasd_device *) cqr->device;
700 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
701 rc = ccw_device_clear(device->cdev, (long) cqr);
703 case 0: /* termination successful */
705 cqr->status = DASD_CQR_CLEAR;
706 cqr->stopclk = get_clock();
707 DBF_DEV_EVENT(DBF_DEBUG, device,
708 "terminate cqr %p successful",
712 DBF_DEV_EVENT(DBF_ERR, device, "%s",
713 "device gone, retry");
716 DBF_DEV_EVENT(DBF_ERR, device, "%s",
721 DBF_DEV_EVENT(DBF_ERR, device, "%s",
722 "device busy, retry later");
725 DEV_MESSAGE(KERN_ERR, device,
726 "line %d unknown RC=%d, please "
727 "report to linux390@de.ibm.com",
734 dasd_schedule_bh(device);
739 * Start the i/o. This start_IO can fail if the channel is really busy.
740 * In that case set up a timer to start the request later.
743 dasd_start_IO(struct dasd_ccw_req * cqr)
745 struct dasd_device *device;
749 rc = dasd_check_cqr(cqr);
752 device = (struct dasd_device *) cqr->device;
753 if (cqr->retries < 0) {
754 DEV_MESSAGE(KERN_DEBUG, device,
755 "start_IO: request %p (%02x/%i) - no retry left.",
756 cqr, cqr->status, cqr->retries);
757 cqr->status = DASD_CQR_FAILED;
760 cqr->startclk = get_clock();
761 cqr->starttime = jiffies;
763 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
767 cqr->status = DASD_CQR_IN_IO;
768 DBF_DEV_EVENT(DBF_DEBUG, device,
769 "start_IO: request %p started successful",
773 DBF_DEV_EVENT(DBF_ERR, device, "%s",
774 "start_IO: device busy, retry later");
777 DBF_DEV_EVENT(DBF_ERR, device, "%s",
778 "start_IO: request timeout, retry later");
781 /* -EACCES indicates that the request used only a
782 * subset of the available pathes and all these
784 * Do a retry with all available pathes.
786 cqr->lpm = LPM_ANYPATH;
787 DBF_DEV_EVENT(DBF_ERR, device, "%s",
788 "start_IO: selected pathes gone,"
789 " retry on all pathes");
793 DBF_DEV_EVENT(DBF_ERR, device, "%s",
794 "start_IO: device gone, retry");
797 DEV_MESSAGE(KERN_ERR, device,
798 "line %d unknown RC=%d, please report"
799 " to linux390@de.ibm.com", __LINE__, rc);
807 * Timeout function for dasd devices. This is used for different purposes
808 * 1) missing interrupt handler for normal operation
809 * 2) delayed start of request where start_IO failed with -EBUSY
810 * 3) timeout for missing state change interrupts
811 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
812 * DASD_CQR_QUEUED for 2) and 3).
815 dasd_timeout_device(unsigned long ptr)
818 struct dasd_device *device;
820 device = (struct dasd_device *) ptr;
821 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
822 /* re-activate request queue */
823 device->stopped &= ~DASD_STOPPED_PENDING;
824 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
825 dasd_schedule_bh(device);
829 * Setup timeout for a device in jiffies.
832 dasd_set_timer(struct dasd_device *device, int expires)
835 if (timer_pending(&device->timer))
836 del_timer(&device->timer);
839 if (timer_pending(&device->timer)) {
840 if (mod_timer(&device->timer, jiffies + expires))
843 device->timer.function = dasd_timeout_device;
844 device->timer.data = (unsigned long) device;
845 device->timer.expires = jiffies + expires;
846 add_timer(&device->timer);
850 * Clear timeout for a device.
853 dasd_clear_timer(struct dasd_device *device)
855 if (timer_pending(&device->timer))
856 del_timer(&device->timer);
860 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
862 struct dasd_ccw_req *cqr;
863 struct dasd_device *device;
865 cqr = (struct dasd_ccw_req *) intparm;
866 if (cqr->status != DASD_CQR_IN_IO) {
868 "invalid status in handle_killed_request: "
869 "bus_id %s, status %02x",
870 cdev->dev.bus_id, cqr->status);
874 device = (struct dasd_device *) cqr->device;
875 if (device == NULL ||
876 device != dasd_device_from_cdev(cdev) ||
877 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
878 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
883 /* Schedule request to be retried. */
884 cqr->status = DASD_CQR_QUEUED;
886 dasd_clear_timer(device);
887 dasd_schedule_bh(device);
888 dasd_put_device(device);
892 dasd_handle_state_change_pending(struct dasd_device *device)
894 struct dasd_ccw_req *cqr;
895 struct list_head *l, *n;
897 /* First of all start sense subsystem status request. */
898 dasd_eer_snss(device);
900 device->stopped &= ~DASD_STOPPED_PENDING;
902 /* restart all 'running' IO on queue */
903 list_for_each_safe(l, n, &device->ccw_queue) {
904 cqr = list_entry(l, struct dasd_ccw_req, list);
905 if (cqr->status == DASD_CQR_IN_IO) {
906 cqr->status = DASD_CQR_QUEUED;
909 dasd_clear_timer(device);
910 dasd_schedule_bh(device);
914 * Interrupt handler for "normal" ssch-io based dasd devices.
917 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
920 struct dasd_ccw_req *cqr, *next;
921 struct dasd_device *device;
922 unsigned long long now;
928 switch (PTR_ERR(irb)) {
930 dasd_handle_killed_request(cdev, intparm);
933 printk(KERN_WARNING"%s(%s): request timed out\n",
934 __FUNCTION__, cdev->dev.bus_id);
935 //FIXME - dasd uses own timeout interface...
938 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
939 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
946 DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
947 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
948 (unsigned int) intparm);
950 /* first of all check for state change pending interrupt */
951 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
952 if ((irb->scsw.dstat & mask) == mask) {
953 device = dasd_device_from_cdev(cdev);
954 if (!IS_ERR(device)) {
955 dasd_handle_state_change_pending(device);
956 dasd_put_device(device);
961 cqr = (struct dasd_ccw_req *) intparm;
963 /* check for unsolicited interrupts */
966 "unsolicited interrupt received: bus_id %s",
971 device = (struct dasd_device *) cqr->device;
972 if (device == NULL ||
973 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
974 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
979 /* Check for clear pending */
980 if (cqr->status == DASD_CQR_CLEAR &&
981 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
982 cqr->status = DASD_CQR_QUEUED;
983 dasd_clear_timer(device);
984 dasd_schedule_bh(device);
988 /* check status - the request might have been killed by dyn detach */
989 if (cqr->status != DASD_CQR_IN_IO) {
991 "invalid status: bus_id %s, status %02x",
992 cdev->dev.bus_id, cqr->status);
995 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
996 ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
998 /* Find out the appropriate era_action. */
999 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
1000 era = dasd_era_fatal;
1001 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1002 irb->scsw.cstat == 0 &&
1003 !irb->esw.esw0.erw.cons)
1004 era = dasd_era_none;
1005 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
1006 era = dasd_era_fatal; /* don't recover this request */
1007 else if (irb->esw.esw0.erw.cons)
1008 era = device->discipline->examine_error(cqr, irb);
1010 era = dasd_era_recover;
1012 DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
1014 if (era == dasd_era_none) {
1015 cqr->status = DASD_CQR_DONE;
1017 /* Start first request on queue if possible -> fast_io. */
1018 if (cqr->list.next != &device->ccw_queue) {
1019 next = list_entry(cqr->list.next,
1020 struct dasd_ccw_req, list);
1021 if ((next->status == DASD_CQR_QUEUED) &&
1022 (!device->stopped)) {
1023 if (device->discipline->start_IO(next) == 0)
1024 expires = next->expires;
1026 DEV_MESSAGE(KERN_DEBUG, device, "%s",
1027 "Interrupt fastpath "
1031 } else { /* error */
1032 memcpy(&cqr->irb, irb, sizeof (struct irb));
1034 /* dump sense data */
1035 dasd_log_sense(cqr, irb);
1038 case dasd_era_fatal:
1039 cqr->status = DASD_CQR_FAILED;
1042 case dasd_era_recover:
1043 cqr->status = DASD_CQR_ERROR;
1050 dasd_set_timer(device, expires);
1052 dasd_clear_timer(device);
1053 dasd_schedule_bh(device);
1057 * posts the buffer_cache about a finalized request
1060 dasd_end_request(struct request *req, int uptodate)
1062 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1064 add_disk_randomness(req->rq_disk);
1065 end_that_request_last(req, uptodate);
1069 * Process finished error recovery ccw.
1072 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1074 dasd_erp_fn_t erp_fn;
1076 if (cqr->status == DASD_CQR_DONE)
1077 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1079 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1080 erp_fn = device->discipline->erp_postaction(cqr);
1085 * Process ccw request queue.
1088 __dasd_process_ccw_queue(struct dasd_device * device,
1089 struct list_head *final_queue)
1091 struct list_head *l, *n;
1092 struct dasd_ccw_req *cqr;
1093 dasd_erp_fn_t erp_fn;
1096 /* Process request with final status. */
1097 list_for_each_safe(l, n, &device->ccw_queue) {
1098 cqr = list_entry(l, struct dasd_ccw_req, list);
1099 /* Stop list processing at the first non-final request. */
1100 if (cqr->status != DASD_CQR_DONE &&
1101 cqr->status != DASD_CQR_FAILED &&
1102 cqr->status != DASD_CQR_ERROR)
1104 /* Process requests with DASD_CQR_ERROR */
1105 if (cqr->status == DASD_CQR_ERROR) {
1106 if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1107 cqr->status = DASD_CQR_FAILED;
1108 cqr->stopclk = get_clock();
1110 if (cqr->irb.esw.esw0.erw.cons) {
1111 erp_fn = device->discipline->
1115 dasd_default_erp_action(cqr);
1120 /* First of all call extended error reporting. */
1121 if (dasd_eer_enabled(device) &&
1122 cqr->status == DASD_CQR_FAILED) {
1123 dasd_eer_write(device, cqr, DASD_EER_FATALERROR);
1125 /* restart request */
1126 cqr->status = DASD_CQR_QUEUED;
1128 device->stopped |= DASD_STOPPED_QUIESCE;
1132 /* Process finished ERP request. */
1134 __dasd_process_erp(device, cqr);
1138 /* Rechain finished requests to final queue */
1139 cqr->endclk = get_clock();
1140 list_move_tail(&cqr->list, final_queue);
1145 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1147 struct request *req;
1148 struct dasd_device *device;
1151 req = (struct request *) data;
1152 device = cqr->device;
1153 dasd_profile_end(device, cqr, req);
1154 status = cqr->device->discipline->free_cp(cqr,req);
1155 spin_lock_irq(&device->request_queue_lock);
1156 dasd_end_request(req, status);
1157 spin_unlock_irq(&device->request_queue_lock);
1162 * Fetch requests from the block device queue.
1165 __dasd_process_blk_queue(struct dasd_device * device)
1167 request_queue_t *queue;
1168 struct request *req;
1169 struct dasd_ccw_req *cqr;
1172 queue = device->request_queue;
1173 /* No queue ? Then there is nothing to do. */
1178 * We requeue request from the block device queue to the ccw
1179 * queue only in two states. In state DASD_STATE_READY the
1180 * partition detection is done and we need to requeue requests
1181 * for that. State DASD_STATE_ONLINE is normal block device
1184 if (device->state != DASD_STATE_READY &&
1185 device->state != DASD_STATE_ONLINE)
1188 /* Now we try to fetch requests from the request queue */
1189 list_for_each_entry(cqr, &device->ccw_queue, list)
1190 if (cqr->status == DASD_CQR_QUEUED)
1192 while (!blk_queue_plugged(queue) &&
1193 elv_next_request(queue) &&
1194 nr_queued < DASD_CHANQ_MAX_SIZE) {
1195 req = elv_next_request(queue);
1197 if (device->features & DASD_FEATURE_READONLY &&
1198 rq_data_dir(req) == WRITE) {
1199 DBF_DEV_EVENT(DBF_ERR, device,
1200 "Rejecting write request %p",
1202 blkdev_dequeue_request(req);
1203 dasd_end_request(req, 0);
1206 if (device->stopped & DASD_STOPPED_DC_EIO) {
1207 blkdev_dequeue_request(req);
1208 dasd_end_request(req, 0);
1211 cqr = device->discipline->build_cp(device, req);
1213 if (PTR_ERR(cqr) == -ENOMEM)
1214 break; /* terminate request queue loop */
1215 DBF_DEV_EVENT(DBF_ERR, device,
1216 "CCW creation failed (rc=%ld) "
1219 blkdev_dequeue_request(req);
1220 dasd_end_request(req, 0);
1223 cqr->callback = dasd_end_request_cb;
1224 cqr->callback_data = (void *) req;
1225 cqr->status = DASD_CQR_QUEUED;
1226 blkdev_dequeue_request(req);
1227 list_add_tail(&cqr->list, &device->ccw_queue);
1228 dasd_profile_start(device, cqr, req);
1234 * Take a look at the first request on the ccw queue and check
1235 * if it reached its expire time. If so, terminate the IO.
1238 __dasd_check_expire(struct dasd_device * device)
1240 struct dasd_ccw_req *cqr;
1242 if (list_empty(&device->ccw_queue))
1244 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1245 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1246 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1247 if (device->discipline->term_IO(cqr) != 0)
1248 /* Hmpf, try again in 1/10 sec */
1249 dasd_set_timer(device, 10);
1255 * Take a look at the first request on the ccw queue and check
1256 * if it needs to be started.
1259 __dasd_start_head(struct dasd_device * device)
1261 struct dasd_ccw_req *cqr;
1264 if (list_empty(&device->ccw_queue))
1266 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1267 /* check FAILFAST */
1268 if (device->stopped & ~DASD_STOPPED_PENDING &&
1269 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1270 (!dasd_eer_enabled(device))) {
1271 cqr->status = DASD_CQR_FAILED;
1272 dasd_schedule_bh(device);
1274 if ((cqr->status == DASD_CQR_QUEUED) &&
1275 (!device->stopped)) {
1276 /* try to start the first I/O that can be started */
1277 rc = device->discipline->start_IO(cqr);
1279 dasd_set_timer(device, cqr->expires);
1280 else if (rc == -EACCES) {
1281 dasd_schedule_bh(device);
1283 /* Hmpf, try again in 1/2 sec */
1284 dasd_set_timer(device, 50);
1289 * Remove requests from the ccw queue.
1292 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1294 struct list_head flush_queue;
1295 struct list_head *l, *n;
1296 struct dasd_ccw_req *cqr;
1298 INIT_LIST_HEAD(&flush_queue);
1299 spin_lock_irq(get_ccwdev_lock(device->cdev));
1300 list_for_each_safe(l, n, &device->ccw_queue) {
1301 cqr = list_entry(l, struct dasd_ccw_req, list);
1302 /* Flush all request or only block device requests? */
1303 if (all == 0 && cqr->callback == dasd_end_request_cb)
1305 if (cqr->status == DASD_CQR_IN_IO)
1306 device->discipline->term_IO(cqr);
1307 if (cqr->status != DASD_CQR_DONE ||
1308 cqr->status != DASD_CQR_FAILED) {
1309 cqr->status = DASD_CQR_FAILED;
1310 cqr->stopclk = get_clock();
1312 /* Process finished ERP request. */
1314 __dasd_process_erp(device, cqr);
1317 /* Rechain request on device request queue */
1318 cqr->endclk = get_clock();
1319 list_move_tail(&cqr->list, &flush_queue);
1321 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1322 /* Now call the callback function of flushed requests */
1323 list_for_each_safe(l, n, &flush_queue) {
1324 cqr = list_entry(l, struct dasd_ccw_req, list);
1325 if (cqr->callback != NULL)
1326 (cqr->callback)(cqr, cqr->callback_data);
1331 * Acquire the device lock and process queues for the device.
1334 dasd_tasklet(struct dasd_device * device)
1336 struct list_head final_queue;
1337 struct list_head *l, *n;
1338 struct dasd_ccw_req *cqr;
1340 atomic_set (&device->tasklet_scheduled, 0);
1341 INIT_LIST_HEAD(&final_queue);
1342 spin_lock_irq(get_ccwdev_lock(device->cdev));
1343 /* Check expire time of first request on the ccw queue. */
1344 __dasd_check_expire(device);
1345 /* Finish off requests on ccw queue */
1346 __dasd_process_ccw_queue(device, &final_queue);
1347 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1348 /* Now call the callback function of requests with final status */
1349 list_for_each_safe(l, n, &final_queue) {
1350 cqr = list_entry(l, struct dasd_ccw_req, list);
1351 list_del_init(&cqr->list);
1352 if (cqr->callback != NULL)
1353 (cqr->callback)(cqr, cqr->callback_data);
1355 spin_lock_irq(&device->request_queue_lock);
1356 spin_lock(get_ccwdev_lock(device->cdev));
1357 /* Get new request from the block device request queue */
1358 __dasd_process_blk_queue(device);
1359 /* Now check if the head of the ccw queue needs to be started. */
1360 __dasd_start_head(device);
1361 spin_unlock(get_ccwdev_lock(device->cdev));
1362 spin_unlock_irq(&device->request_queue_lock);
1363 dasd_put_device(device);
1367 * Schedules a call to dasd_tasklet over the device tasklet.
1370 dasd_schedule_bh(struct dasd_device * device)
1372 /* Protect against rescheduling. */
1373 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
1375 dasd_get_device(device);
1376 tasklet_hi_schedule(&device->tasklet);
1380 * Queue a request to the head of the ccw_queue. Start the I/O if
1384 dasd_add_request_head(struct dasd_ccw_req *req)
1386 struct dasd_device *device;
1387 unsigned long flags;
1389 device = req->device;
1390 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1391 req->status = DASD_CQR_QUEUED;
1392 req->device = device;
1393 list_add(&req->list, &device->ccw_queue);
1394 /* let the bh start the request to keep them in order */
1395 dasd_schedule_bh(device);
1396 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1400 * Queue a request to the tail of the ccw_queue. Start the I/O if
1404 dasd_add_request_tail(struct dasd_ccw_req *req)
1406 struct dasd_device *device;
1407 unsigned long flags;
1409 device = req->device;
1410 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1411 req->status = DASD_CQR_QUEUED;
1412 req->device = device;
1413 list_add_tail(&req->list, &device->ccw_queue);
1414 /* let the bh start the request to keep them in order */
1415 dasd_schedule_bh(device);
1416 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1423 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1425 wake_up((wait_queue_head_t *) data);
1429 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1431 struct dasd_device *device;
1434 device = cqr->device;
1435 spin_lock_irq(get_ccwdev_lock(device->cdev));
1436 rc = ((cqr->status == DASD_CQR_DONE ||
1437 cqr->status == DASD_CQR_FAILED) &&
1438 list_empty(&cqr->list));
1439 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1444 * Attempts to start a special ccw queue and waits for its completion.
1447 dasd_sleep_on(struct dasd_ccw_req * cqr)
1449 wait_queue_head_t wait_q;
1450 struct dasd_device *device;
1453 device = cqr->device;
1454 spin_lock_irq(get_ccwdev_lock(device->cdev));
1456 init_waitqueue_head (&wait_q);
1457 cqr->callback = dasd_wakeup_cb;
1458 cqr->callback_data = (void *) &wait_q;
1459 cqr->status = DASD_CQR_QUEUED;
1460 list_add_tail(&cqr->list, &device->ccw_queue);
1462 /* let the bh start the request to keep them in order */
1463 dasd_schedule_bh(device);
1465 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1467 wait_event(wait_q, _wait_for_wakeup(cqr));
1469 /* Request status is either done or failed. */
1470 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1475 * Attempts to start a special ccw queue and wait interruptible
1476 * for its completion.
1479 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1481 wait_queue_head_t wait_q;
1482 struct dasd_device *device;
1485 device = cqr->device;
1486 spin_lock_irq(get_ccwdev_lock(device->cdev));
1488 init_waitqueue_head (&wait_q);
1489 cqr->callback = dasd_wakeup_cb;
1490 cqr->callback_data = (void *) &wait_q;
1491 cqr->status = DASD_CQR_QUEUED;
1492 list_add_tail(&cqr->list, &device->ccw_queue);
1494 /* let the bh start the request to keep them in order */
1495 dasd_schedule_bh(device);
1496 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1500 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1501 if (rc != -ERESTARTSYS) {
1502 /* Request is final (done or failed) */
1503 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1506 spin_lock_irq(get_ccwdev_lock(device->cdev));
1507 switch (cqr->status) {
1508 case DASD_CQR_IN_IO:
1509 /* terminate runnig cqr */
1510 if (device->discipline->term_IO) {
1512 device->discipline->term_IO(cqr);
1514 * wait (non-interruptible) for final status
1515 * because signal ist still pending
1517 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1518 wait_event(wait_q, _wait_for_wakeup(cqr));
1519 spin_lock_irq(get_ccwdev_lock(device->cdev));
1520 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1524 case DASD_CQR_QUEUED:
1526 list_del_init(&cqr->list);
1531 /* cqr with 'non-interruptable' status - just wait */
1534 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1540 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1541 * for eckd devices) the currently running request has to be terminated
1542 * and be put back to status queued, before the special request is added
1543 * to the head of the queue. Then the special request is waited on normally.
1546 _dasd_term_running_cqr(struct dasd_device *device)
1548 struct dasd_ccw_req *cqr;
1551 if (list_empty(&device->ccw_queue))
1553 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1554 rc = device->discipline->term_IO(cqr);
1556 /* termination successful */
1557 cqr->status = DASD_CQR_QUEUED;
1558 cqr->startclk = cqr->stopclk = 0;
1565 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1567 wait_queue_head_t wait_q;
1568 struct dasd_device *device;
1571 device = cqr->device;
1572 spin_lock_irq(get_ccwdev_lock(device->cdev));
1573 rc = _dasd_term_running_cqr(device);
1575 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1579 init_waitqueue_head (&wait_q);
1580 cqr->callback = dasd_wakeup_cb;
1581 cqr->callback_data = (void *) &wait_q;
1582 cqr->status = DASD_CQR_QUEUED;
1583 list_add(&cqr->list, &device->ccw_queue);
1585 /* let the bh start the request to keep them in order */
1586 dasd_schedule_bh(device);
1588 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1590 wait_event(wait_q, _wait_for_wakeup(cqr));
1592 /* Request status is either done or failed. */
1593 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1598 * Cancels a request that was started with dasd_sleep_on_req.
1599 * This is useful to timeout requests. The request will be
1600 * terminated if it is currently in i/o.
1601 * Returns 1 if the request has been terminated.
1604 dasd_cancel_req(struct dasd_ccw_req *cqr)
1606 struct dasd_device *device = cqr->device;
1607 unsigned long flags;
1611 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1612 switch (cqr->status) {
1613 case DASD_CQR_QUEUED:
1614 /* request was not started - just set to failed */
1615 cqr->status = DASD_CQR_FAILED;
1617 case DASD_CQR_IN_IO:
1618 /* request in IO - terminate IO and release again */
1619 if (device->discipline->term_IO(cqr) != 0)
1620 /* what to do if unable to terminate ??????
1622 cqr->status = DASD_CQR_FAILED;
1623 cqr->stopclk = get_clock();
1627 case DASD_CQR_FAILED:
1628 /* already finished - do nothing */
1631 DEV_MESSAGE(KERN_ALERT, device,
1632 "invalid status %02x in request",
1637 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1638 dasd_schedule_bh(device);
1643 * SECTION: Block device operations (request queue, partitions, open, release).
1647 * Dasd request queue function. Called from ll_rw_blk.c
1650 do_dasd_request(request_queue_t * queue)
1652 struct dasd_device *device;
1654 device = (struct dasd_device *) queue->queuedata;
1655 spin_lock(get_ccwdev_lock(device->cdev));
1656 /* Get new request from the block device request queue */
1657 __dasd_process_blk_queue(device);
1658 /* Now check if the head of the ccw queue needs to be started. */
1659 __dasd_start_head(device);
1660 spin_unlock(get_ccwdev_lock(device->cdev));
1664 * Allocate and initialize request queue and default I/O scheduler.
1667 dasd_alloc_queue(struct dasd_device * device)
1671 device->request_queue = blk_init_queue(do_dasd_request,
1672 &device->request_queue_lock);
1673 if (device->request_queue == NULL)
1676 device->request_queue->queuedata = device;
1678 elevator_exit(device->request_queue->elevator);
1679 rc = elevator_init(device->request_queue, "deadline");
1681 blk_cleanup_queue(device->request_queue);
1688 * Allocate and initialize request queue.
1691 dasd_setup_queue(struct dasd_device * device)
1695 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1696 max = device->discipline->max_blocks << device->s2b_shift;
1697 blk_queue_max_sectors(device->request_queue, max);
1698 blk_queue_max_phys_segments(device->request_queue, -1L);
1699 blk_queue_max_hw_segments(device->request_queue, -1L);
1700 blk_queue_max_segment_size(device->request_queue, -1L);
1701 blk_queue_segment_boundary(device->request_queue, -1L);
1702 blk_queue_ordered(device->request_queue, QUEUE_ORDERED_TAG, NULL);
1706 * Deactivate and free request queue.
1709 dasd_free_queue(struct dasd_device * device)
1711 if (device->request_queue) {
1712 blk_cleanup_queue(device->request_queue);
1713 device->request_queue = NULL;
1718 * Flush request on the request queue.
1721 dasd_flush_request_queue(struct dasd_device * device)
1723 struct request *req;
1725 if (!device->request_queue)
1728 spin_lock_irq(&device->request_queue_lock);
1729 while (!list_empty(&device->request_queue->queue_head)) {
1730 req = elv_next_request(device->request_queue);
1733 dasd_end_request(req, 0);
1734 blkdev_dequeue_request(req);
1736 spin_unlock_irq(&device->request_queue_lock);
1740 dasd_open(struct inode *inp, struct file *filp)
1742 struct gendisk *disk = inp->i_bdev->bd_disk;
1743 struct dasd_device *device = disk->private_data;
1746 atomic_inc(&device->open_count);
1747 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1752 if (!try_module_get(device->discipline->owner)) {
1757 if (dasd_probeonly) {
1758 DEV_MESSAGE(KERN_INFO, device, "%s",
1759 "No access to device due to probeonly mode");
1764 if (device->state <= DASD_STATE_BASIC) {
1765 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1766 " Cannot open unrecognized device");
1774 module_put(device->discipline->owner);
1776 atomic_dec(&device->open_count);
1781 dasd_release(struct inode *inp, struct file *filp)
1783 struct gendisk *disk = inp->i_bdev->bd_disk;
1784 struct dasd_device *device = disk->private_data;
1786 atomic_dec(&device->open_count);
1787 module_put(device->discipline->owner);
1792 * Return disk geometry.
1795 dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1797 struct dasd_device *device;
1799 device = bdev->bd_disk->private_data;
1803 if (!device->discipline ||
1804 !device->discipline->fill_geometry)
1807 device->discipline->fill_geometry(device, geo);
1808 geo->start = get_start_sect(bdev) >> device->s2b_shift;
1812 struct block_device_operations
1813 dasd_device_operations = {
1814 .owner = THIS_MODULE,
1816 .release = dasd_release,
1817 .ioctl = dasd_ioctl,
1818 .compat_ioctl = dasd_compat_ioctl,
1819 .getgeo = dasd_getgeo,
1826 #ifdef CONFIG_PROC_FS
1830 if (dasd_page_cache != NULL) {
1831 kmem_cache_destroy(dasd_page_cache);
1832 dasd_page_cache = NULL;
1834 dasd_gendisk_exit();
1836 devfs_remove("dasd");
1837 if (dasd_debug_area != NULL) {
1838 debug_unregister(dasd_debug_area);
1839 dasd_debug_area = NULL;
1844 * SECTION: common functions for ccw_driver use
1848 * Initial attempt at a probe function. this can be simplified once
1849 * the other detection code is gone.
1852 dasd_generic_probe (struct ccw_device *cdev,
1853 struct dasd_discipline *discipline)
1857 ret = dasd_add_sysfs_files(cdev);
1860 "dasd_generic_probe: could not add sysfs entries "
1861 "for %s\n", cdev->dev.bus_id);
1863 cdev->handler = &dasd_int_handler;
1870 * This will one day be called from a global not_oper handler.
1871 * It is also used by driver_unregister during module unload.
1874 dasd_generic_remove (struct ccw_device *cdev)
1876 struct dasd_device *device;
1878 cdev->handler = NULL;
1880 dasd_remove_sysfs_files(cdev);
1881 device = dasd_device_from_cdev(cdev);
1884 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1885 /* Already doing offline processing */
1886 dasd_put_device(device);
1890 * This device is removed unconditionally. Set offline
1891 * flag to prevent dasd_open from opening it while it is
1892 * no quite down yet.
1894 dasd_set_target_state(device, DASD_STATE_NEW);
1895 /* dasd_delete_device destroys the device reference. */
1896 dasd_delete_device(device);
1900 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
1901 * the device is detected for the first time and is supposed to be used
1902 * or the user has started activation through sysfs.
1905 dasd_generic_set_online (struct ccw_device *cdev,
1906 struct dasd_discipline *base_discipline)
1909 struct dasd_discipline *discipline;
1910 struct dasd_device *device;
1913 device = dasd_create_device(cdev);
1915 return PTR_ERR(device);
1917 discipline = base_discipline;
1918 if (device->features & DASD_FEATURE_USEDIAG) {
1919 if (!dasd_diag_discipline_pointer) {
1920 printk (KERN_WARNING
1921 "dasd_generic couldn't online device %s "
1922 "- discipline DIAG not available\n",
1924 dasd_delete_device(device);
1927 discipline = dasd_diag_discipline_pointer;
1929 if (!try_module_get(base_discipline->owner)) {
1930 dasd_delete_device(device);
1933 if (!try_module_get(discipline->owner)) {
1934 module_put(base_discipline->owner);
1935 dasd_delete_device(device);
1938 device->base_discipline = base_discipline;
1939 device->discipline = discipline;
1941 rc = discipline->check_device(device);
1943 printk (KERN_WARNING
1944 "dasd_generic couldn't online device %s "
1945 "with discipline %s rc=%i\n",
1946 cdev->dev.bus_id, discipline->name, rc);
1947 module_put(discipline->owner);
1948 module_put(base_discipline->owner);
1949 dasd_delete_device(device);
1953 dasd_set_target_state(device, DASD_STATE_ONLINE);
1954 if (device->state <= DASD_STATE_KNOWN) {
1955 printk (KERN_WARNING
1956 "dasd_generic discipline not found for %s\n",
1959 dasd_set_target_state(device, DASD_STATE_NEW);
1960 dasd_delete_device(device);
1962 pr_debug("dasd_generic device %s found\n",
1965 /* FIXME: we have to wait for the root device but we don't want
1966 * to wait for each single device but for all at once. */
1967 wait_event(dasd_init_waitq, _wait_for_device(device));
1969 dasd_put_device(device);
1975 dasd_generic_set_offline (struct ccw_device *cdev)
1977 struct dasd_device *device;
1980 device = dasd_device_from_cdev(cdev);
1982 return PTR_ERR(device);
1983 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1984 /* Already doing offline processing */
1985 dasd_put_device(device);
1989 * We must make sure that this device is currently not in use.
1990 * The open_count is increased for every opener, that includes
1991 * the blkdev_get in dasd_scan_partitions. We are only interested
1992 * in the other openers.
1994 max_count = device->bdev ? 0 : -1;
1995 if (atomic_read(&device->open_count) > max_count) {
1996 printk (KERN_WARNING "Can't offline dasd device with open"
1998 atomic_read(&device->open_count));
1999 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
2000 dasd_put_device(device);
2003 dasd_set_target_state(device, DASD_STATE_NEW);
2004 /* dasd_delete_device destroys the device reference. */
2005 dasd_delete_device(device);
2011 dasd_generic_notify(struct ccw_device *cdev, int event)
2013 struct dasd_device *device;
2014 struct dasd_ccw_req *cqr;
2015 unsigned long flags;
2018 device = dasd_device_from_cdev(cdev);
2021 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
2026 /* First of all call extended error reporting. */
2027 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
2029 if (device->state < DASD_STATE_BASIC)
2031 /* Device is active. We want to keep it. */
2032 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
2033 list_for_each_entry(cqr, &device->ccw_queue, list)
2034 if (cqr->status == DASD_CQR_IN_IO)
2035 cqr->status = DASD_CQR_FAILED;
2036 device->stopped |= DASD_STOPPED_DC_EIO;
2038 list_for_each_entry(cqr, &device->ccw_queue, list)
2039 if (cqr->status == DASD_CQR_IN_IO) {
2040 cqr->status = DASD_CQR_QUEUED;
2043 device->stopped |= DASD_STOPPED_DC_WAIT;
2044 dasd_set_timer(device, 0);
2046 dasd_schedule_bh(device);
2050 /* FIXME: add a sanity check. */
2051 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
2052 dasd_schedule_bh(device);
2056 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2057 dasd_put_device(device);
2062 * Automatically online either all dasd devices (dasd_autodetect) or
2063 * all devices specified with dasd= parameters.
2066 __dasd_auto_online(struct device *dev, void *data)
2068 struct ccw_device *cdev;
2070 cdev = to_ccwdev(dev);
2071 if (dasd_autodetect || dasd_busid_known(cdev->dev.bus_id) == 0)
2072 ccw_device_set_online(cdev);
2077 dasd_generic_auto_online (struct ccw_driver *dasd_discipline_driver)
2079 struct device_driver *drv;
2081 drv = get_driver(&dasd_discipline_driver->driver);
2082 driver_for_each_device(drv, NULL, NULL, __dasd_auto_online);
2092 init_waitqueue_head(&dasd_init_waitq);
2094 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2095 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long));
2096 if (dasd_debug_area == NULL) {
2100 debug_register_view(dasd_debug_area, &debug_sprintf_view);
2101 debug_set_level(dasd_debug_area, DBF_EMERG);
2103 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
2105 dasd_diag_discipline_pointer = NULL;
2107 rc = devfs_mk_dir("dasd");
2110 rc = dasd_devmap_init();
2113 rc = dasd_gendisk_init();
2119 rc = dasd_eer_init();
2122 #ifdef CONFIG_PROC_FS
2123 rc = dasd_proc_init();
2130 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2135 module_init(dasd_init);
2136 module_exit(dasd_exit);
2138 EXPORT_SYMBOL(dasd_debug_area);
2139 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2141 EXPORT_SYMBOL(dasd_add_request_head);
2142 EXPORT_SYMBOL(dasd_add_request_tail);
2143 EXPORT_SYMBOL(dasd_cancel_req);
2144 EXPORT_SYMBOL(dasd_clear_timer);
2145 EXPORT_SYMBOL(dasd_enable_device);
2146 EXPORT_SYMBOL(dasd_int_handler);
2147 EXPORT_SYMBOL(dasd_kfree_request);
2148 EXPORT_SYMBOL(dasd_kick_device);
2149 EXPORT_SYMBOL(dasd_kmalloc_request);
2150 EXPORT_SYMBOL(dasd_schedule_bh);
2151 EXPORT_SYMBOL(dasd_set_target_state);
2152 EXPORT_SYMBOL(dasd_set_timer);
2153 EXPORT_SYMBOL(dasd_sfree_request);
2154 EXPORT_SYMBOL(dasd_sleep_on);
2155 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2156 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2157 EXPORT_SYMBOL(dasd_smalloc_request);
2158 EXPORT_SYMBOL(dasd_start_IO);
2159 EXPORT_SYMBOL(dasd_term_IO);
2161 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2162 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2163 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2164 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2165 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
2166 EXPORT_SYMBOL_GPL(dasd_generic_auto_online);
2169 * Overrides for Emacs so that we follow Linus's tabbing style.
2170 * Emacs will notice this stuff at the end of the file and automatically
2171 * adjust the settings for this buffer only. This must remain at the end
2173 * ---------------------------------------------------------------------------
2176 * c-brace-imaginary-offset: 0
2177 * c-brace-offset: -4
2178 * c-argdecl-indent: 4
2179 * c-label-offset: -4
2180 * c-continued-statement-offset: 4
2181 * c-continued-brace-offset: 0
2182 * indent-tabs-mode: 1