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_LICENSE("GPL");
49 * SECTION: prototypes for static functions of dasd.c
51 static int dasd_alloc_queue(struct dasd_device * device);
52 static void dasd_setup_queue(struct dasd_device * device);
53 static void dasd_free_queue(struct dasd_device * device);
54 static void dasd_flush_request_queue(struct dasd_device *);
55 static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
56 static void dasd_flush_ccw_queue(struct dasd_device *, int);
57 static void dasd_tasklet(struct dasd_device *);
58 static void do_kick_device(void *data);
61 * SECTION: Operations on the device structure.
63 static wait_queue_head_t dasd_init_waitq;
66 * Allocate memory for a new device structure.
69 dasd_alloc_device(void)
71 struct dasd_device *device;
73 device = kzalloc(sizeof (struct dasd_device), GFP_ATOMIC);
75 return ERR_PTR(-ENOMEM);
76 /* open_count = 0 means device online but not in use */
77 atomic_set(&device->open_count, -1);
79 /* Get two pages for normal block device operations. */
80 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
81 if (device->ccw_mem == NULL) {
83 return ERR_PTR(-ENOMEM);
85 /* Get one page for error recovery. */
86 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
87 if (device->erp_mem == NULL) {
88 free_pages((unsigned long) device->ccw_mem, 1);
90 return ERR_PTR(-ENOMEM);
93 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
94 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
95 spin_lock_init(&device->mem_lock);
96 spin_lock_init(&device->request_queue_lock);
97 atomic_set (&device->tasklet_scheduled, 0);
98 tasklet_init(&device->tasklet,
99 (void (*)(unsigned long)) dasd_tasklet,
100 (unsigned long) device);
101 INIT_LIST_HEAD(&device->ccw_queue);
102 init_timer(&device->timer);
103 INIT_WORK(&device->kick_work, do_kick_device, device);
104 device->state = DASD_STATE_NEW;
105 device->target = DASD_STATE_NEW;
111 * Free memory of a device structure.
114 dasd_free_device(struct dasd_device *device)
116 kfree(device->private);
117 free_page((unsigned long) device->erp_mem);
118 free_pages((unsigned long) device->ccw_mem, 1);
123 * Make a new device known to the system.
126 dasd_state_new_to_known(struct dasd_device *device)
131 * As long as the device is not in state DASD_STATE_NEW we want to
132 * keep the reference count > 0.
134 dasd_get_device(device);
136 rc = dasd_alloc_queue(device);
138 dasd_put_device(device);
142 device->state = DASD_STATE_KNOWN;
147 * Let the system forget about a device.
150 dasd_state_known_to_new(struct dasd_device * device)
152 /* Disable extended error reporting for this device. */
153 dasd_eer_disable(device);
154 /* Forget the discipline information. */
155 if (device->discipline)
156 module_put(device->discipline->owner);
157 device->discipline = NULL;
158 if (device->base_discipline)
159 module_put(device->base_discipline->owner);
160 device->base_discipline = NULL;
161 device->state = DASD_STATE_NEW;
163 dasd_free_queue(device);
165 /* Give up reference we took in dasd_state_new_to_known. */
166 dasd_put_device(device);
170 * Request the irq line for the device.
173 dasd_state_known_to_basic(struct dasd_device * device)
177 /* Allocate and register gendisk structure. */
178 rc = dasd_gendisk_alloc(device);
182 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
183 device->debug_area = debug_register(device->cdev->dev.bus_id, 1, 2,
185 debug_register_view(device->debug_area, &debug_sprintf_view);
186 debug_set_level(device->debug_area, DBF_EMERG);
187 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
189 device->state = DASD_STATE_BASIC;
194 * Release the irq line for the device. Terminate any running i/o.
197 dasd_state_basic_to_known(struct dasd_device * device)
199 dasd_gendisk_free(device);
200 dasd_flush_ccw_queue(device, 1);
201 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
202 if (device->debug_area != NULL) {
203 debug_unregister(device->debug_area);
204 device->debug_area = NULL;
206 device->state = DASD_STATE_KNOWN;
210 * Do the initial analysis. The do_analysis function may return
211 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
212 * until the discipline decides to continue the startup sequence
213 * by calling the function dasd_change_state. The eckd disciplines
214 * uses this to start a ccw that detects the format. The completion
215 * interrupt for this detection ccw uses the kernel event daemon to
216 * trigger the call to dasd_change_state. All this is done in the
217 * discipline code, see dasd_eckd.c.
218 * After the analysis ccw is done (do_analysis returned 0) the block
220 * In case the analysis returns an error, the device setup is stopped
221 * (a fake disk was already added to allow formatting).
224 dasd_state_basic_to_ready(struct dasd_device * device)
229 if (device->discipline->do_analysis != NULL)
230 rc = device->discipline->do_analysis(device);
233 device->state = DASD_STATE_UNFMT;
236 /* make disk known with correct capacity */
237 dasd_setup_queue(device);
238 set_capacity(device->gdp, device->blocks << device->s2b_shift);
239 device->state = DASD_STATE_READY;
240 rc = dasd_scan_partitions(device);
242 device->state = DASD_STATE_BASIC;
247 * Remove device from block device layer. Destroy dirty buffers.
248 * Forget format information. Check if the target level is basic
249 * and if it is create fake disk for formatting.
252 dasd_state_ready_to_basic(struct dasd_device * device)
254 dasd_flush_ccw_queue(device, 0);
255 dasd_destroy_partitions(device);
256 dasd_flush_request_queue(device);
258 device->bp_block = 0;
259 device->s2b_shift = 0;
260 device->state = DASD_STATE_BASIC;
267 dasd_state_unfmt_to_basic(struct dasd_device * device)
269 device->state = DASD_STATE_BASIC;
273 * Make the device online and schedule the bottom half to start
274 * the requeueing of requests from the linux request queue to the
278 dasd_state_ready_to_online(struct dasd_device * device)
280 device->state = DASD_STATE_ONLINE;
281 dasd_schedule_bh(device);
286 * Stop the requeueing of requests again.
289 dasd_state_online_to_ready(struct dasd_device * device)
291 device->state = DASD_STATE_READY;
295 * Device startup state changes.
298 dasd_increase_state(struct dasd_device *device)
303 if (device->state == DASD_STATE_NEW &&
304 device->target >= DASD_STATE_KNOWN)
305 rc = dasd_state_new_to_known(device);
308 device->state == DASD_STATE_KNOWN &&
309 device->target >= DASD_STATE_BASIC)
310 rc = dasd_state_known_to_basic(device);
313 device->state == DASD_STATE_BASIC &&
314 device->target >= DASD_STATE_READY)
315 rc = dasd_state_basic_to_ready(device);
318 device->state == DASD_STATE_READY &&
319 device->target >= DASD_STATE_ONLINE)
320 rc = dasd_state_ready_to_online(device);
326 * Device shutdown state changes.
329 dasd_decrease_state(struct dasd_device *device)
331 if (device->state == DASD_STATE_ONLINE &&
332 device->target <= DASD_STATE_READY)
333 dasd_state_online_to_ready(device);
335 if (device->state == DASD_STATE_READY &&
336 device->target <= DASD_STATE_BASIC)
337 dasd_state_ready_to_basic(device);
339 if (device->state == DASD_STATE_UNFMT &&
340 device->target <= DASD_STATE_BASIC)
341 dasd_state_unfmt_to_basic(device);
343 if (device->state == DASD_STATE_BASIC &&
344 device->target <= DASD_STATE_KNOWN)
345 dasd_state_basic_to_known(device);
347 if (device->state == DASD_STATE_KNOWN &&
348 device->target <= DASD_STATE_NEW)
349 dasd_state_known_to_new(device);
355 * This is the main startup/shutdown routine.
358 dasd_change_state(struct dasd_device *device)
362 if (device->state == device->target)
363 /* Already where we want to go today... */
365 if (device->state < device->target)
366 rc = dasd_increase_state(device);
368 rc = dasd_decrease_state(device);
369 if (rc && rc != -EAGAIN)
370 device->target = device->state;
372 if (device->state == device->target)
373 wake_up(&dasd_init_waitq);
377 * Kick starter for devices that did not complete the startup/shutdown
378 * procedure or were sleeping because of a pending state.
379 * dasd_kick_device will schedule a call do do_kick_device to the kernel
383 do_kick_device(void *data)
385 struct dasd_device *device;
387 device = (struct dasd_device *) data;
388 dasd_change_state(device);
389 dasd_schedule_bh(device);
390 dasd_put_device(device);
394 dasd_kick_device(struct dasd_device *device)
396 dasd_get_device(device);
397 /* queue call to dasd_kick_device to the kernel event daemon. */
398 schedule_work(&device->kick_work);
402 * Set the target state for a device and starts the state change.
405 dasd_set_target_state(struct dasd_device *device, int target)
407 /* If we are in probeonly mode stop at DASD_STATE_READY. */
408 if (dasd_probeonly && target > DASD_STATE_READY)
409 target = DASD_STATE_READY;
410 if (device->target != target) {
411 if (device->state == target)
412 wake_up(&dasd_init_waitq);
413 device->target = target;
415 if (device->state != device->target)
416 dasd_change_state(device);
420 * Enable devices with device numbers in [from..to].
423 _wait_for_device(struct dasd_device *device)
425 return (device->state == device->target);
429 dasd_enable_device(struct dasd_device *device)
431 dasd_set_target_state(device, DASD_STATE_ONLINE);
432 if (device->state <= DASD_STATE_KNOWN)
433 /* No discipline for device found. */
434 dasd_set_target_state(device, DASD_STATE_NEW);
435 /* Now wait for the devices to come up. */
436 wait_event(dasd_init_waitq, _wait_for_device(device));
440 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
442 #ifdef CONFIG_DASD_PROFILE
444 struct dasd_profile_info_t dasd_global_profile;
445 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
448 * Increments counter in global and local profiling structures.
450 #define dasd_profile_counter(value, counter, device) \
453 for (index = 0; index < 31 && value >> (2+index); index++); \
454 dasd_global_profile.counter[index]++; \
455 device->profile.counter[index]++; \
459 * Add profiling information for cqr before execution.
462 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
466 unsigned int counter;
468 if (dasd_profile_level != DASD_PROFILE_ON)
471 /* count the length of the chanq for statistics */
473 list_for_each(l, &device->ccw_queue)
476 dasd_global_profile.dasd_io_nr_req[counter]++;
477 device->profile.dasd_io_nr_req[counter]++;
481 * Add profiling information for cqr after execution.
484 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
487 long strtime, irqtime, endtime, tottime; /* in microseconds */
488 long tottimeps, sectors;
490 if (dasd_profile_level != DASD_PROFILE_ON)
493 sectors = req->nr_sectors;
494 if (!cqr->buildclk || !cqr->startclk ||
495 !cqr->stopclk || !cqr->endclk ||
499 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
500 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
501 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
502 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
503 tottimeps = tottime / sectors;
505 if (!dasd_global_profile.dasd_io_reqs)
506 memset(&dasd_global_profile, 0,
507 sizeof (struct dasd_profile_info_t));
508 dasd_global_profile.dasd_io_reqs++;
509 dasd_global_profile.dasd_io_sects += sectors;
511 if (!device->profile.dasd_io_reqs)
512 memset(&device->profile, 0,
513 sizeof (struct dasd_profile_info_t));
514 device->profile.dasd_io_reqs++;
515 device->profile.dasd_io_sects += sectors;
517 dasd_profile_counter(sectors, dasd_io_secs, device);
518 dasd_profile_counter(tottime, dasd_io_times, device);
519 dasd_profile_counter(tottimeps, dasd_io_timps, device);
520 dasd_profile_counter(strtime, dasd_io_time1, device);
521 dasd_profile_counter(irqtime, dasd_io_time2, device);
522 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
523 dasd_profile_counter(endtime, dasd_io_time3, device);
526 #define dasd_profile_start(device, cqr, req) do {} while (0)
527 #define dasd_profile_end(device, cqr, req) do {} while (0)
528 #endif /* CONFIG_DASD_PROFILE */
531 * Allocate memory for a channel program with 'cplength' channel
532 * command words and 'datasize' additional space. There are two
533 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
534 * memory and 2) dasd_smalloc_request uses the static ccw memory
535 * that gets allocated for each device.
537 struct dasd_ccw_req *
538 dasd_kmalloc_request(char *magic, int cplength, int datasize,
539 struct dasd_device * device)
541 struct dasd_ccw_req *cqr;
544 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
545 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
547 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
549 return ERR_PTR(-ENOMEM);
552 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
553 GFP_ATOMIC | GFP_DMA);
554 if (cqr->cpaddr == NULL) {
556 return ERR_PTR(-ENOMEM);
561 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
562 if (cqr->data == NULL) {
565 return ERR_PTR(-ENOMEM);
568 strncpy((char *) &cqr->magic, magic, 4);
569 ASCEBC((char *) &cqr->magic, 4);
570 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
571 dasd_get_device(device);
575 struct dasd_ccw_req *
576 dasd_smalloc_request(char *magic, int cplength, int datasize,
577 struct dasd_device * device)
580 struct dasd_ccw_req *cqr;
585 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
586 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
588 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
590 size += cplength * sizeof(struct ccw1);
593 spin_lock_irqsave(&device->mem_lock, flags);
594 cqr = (struct dasd_ccw_req *)
595 dasd_alloc_chunk(&device->ccw_chunks, size);
596 spin_unlock_irqrestore(&device->mem_lock, flags);
598 return ERR_PTR(-ENOMEM);
599 memset(cqr, 0, sizeof(struct dasd_ccw_req));
600 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
603 cqr->cpaddr = (struct ccw1 *) data;
604 data += cplength*sizeof(struct ccw1);
605 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
610 memset(cqr->data, 0, datasize);
612 strncpy((char *) &cqr->magic, magic, 4);
613 ASCEBC((char *) &cqr->magic, 4);
614 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
615 dasd_get_device(device);
620 * Free memory of a channel program. This function needs to free all the
621 * idal lists that might have been created by dasd_set_cda and the
622 * struct dasd_ccw_req itself.
625 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
630 /* Clear any idals used for the request. */
633 clear_normalized_cda(ccw);
634 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
639 dasd_put_device(device);
643 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
647 spin_lock_irqsave(&device->mem_lock, flags);
648 dasd_free_chunk(&device->ccw_chunks, cqr);
649 spin_unlock_irqrestore(&device->mem_lock, flags);
650 dasd_put_device(device);
654 * Check discipline magic in cqr.
657 dasd_check_cqr(struct dasd_ccw_req *cqr)
659 struct dasd_device *device;
663 device = cqr->device;
664 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
665 DEV_MESSAGE(KERN_WARNING, device,
666 " dasd_ccw_req 0x%08x magic doesn't match"
667 " discipline 0x%08x",
669 *(unsigned int *) device->discipline->name);
676 * Terminate the current i/o and set the request to clear_pending.
677 * Timer keeps device runnig.
678 * ccw_device_clear can fail if the i/o subsystem
682 dasd_term_IO(struct dasd_ccw_req * cqr)
684 struct dasd_device *device;
688 rc = dasd_check_cqr(cqr);
692 device = (struct dasd_device *) cqr->device;
693 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
694 rc = ccw_device_clear(device->cdev, (long) cqr);
696 case 0: /* termination successful */
698 cqr->status = DASD_CQR_CLEAR;
699 cqr->stopclk = get_clock();
700 DBF_DEV_EVENT(DBF_DEBUG, device,
701 "terminate cqr %p successful",
705 DBF_DEV_EVENT(DBF_ERR, device, "%s",
706 "device gone, retry");
709 DBF_DEV_EVENT(DBF_ERR, device, "%s",
714 DBF_DEV_EVENT(DBF_ERR, device, "%s",
715 "device busy, retry later");
718 DEV_MESSAGE(KERN_ERR, device,
719 "line %d unknown RC=%d, please "
720 "report to linux390@de.ibm.com",
727 dasd_schedule_bh(device);
732 * Start the i/o. This start_IO can fail if the channel is really busy.
733 * In that case set up a timer to start the request later.
736 dasd_start_IO(struct dasd_ccw_req * cqr)
738 struct dasd_device *device;
742 rc = dasd_check_cqr(cqr);
745 device = (struct dasd_device *) cqr->device;
746 if (cqr->retries < 0) {
747 DEV_MESSAGE(KERN_DEBUG, device,
748 "start_IO: request %p (%02x/%i) - no retry left.",
749 cqr, cqr->status, cqr->retries);
750 cqr->status = DASD_CQR_FAILED;
753 cqr->startclk = get_clock();
754 cqr->starttime = jiffies;
756 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
760 cqr->status = DASD_CQR_IN_IO;
761 DBF_DEV_EVENT(DBF_DEBUG, device,
762 "start_IO: request %p started successful",
766 DBF_DEV_EVENT(DBF_ERR, device, "%s",
767 "start_IO: device busy, retry later");
770 DBF_DEV_EVENT(DBF_ERR, device, "%s",
771 "start_IO: request timeout, retry later");
774 /* -EACCES indicates that the request used only a
775 * subset of the available pathes and all these
777 * Do a retry with all available pathes.
779 cqr->lpm = LPM_ANYPATH;
780 DBF_DEV_EVENT(DBF_ERR, device, "%s",
781 "start_IO: selected pathes gone,"
782 " retry on all pathes");
786 DBF_DEV_EVENT(DBF_ERR, device, "%s",
787 "start_IO: device gone, retry");
790 DEV_MESSAGE(KERN_ERR, device,
791 "line %d unknown RC=%d, please report"
792 " to linux390@de.ibm.com", __LINE__, rc);
800 * Timeout function for dasd devices. This is used for different purposes
801 * 1) missing interrupt handler for normal operation
802 * 2) delayed start of request where start_IO failed with -EBUSY
803 * 3) timeout for missing state change interrupts
804 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
805 * DASD_CQR_QUEUED for 2) and 3).
808 dasd_timeout_device(unsigned long ptr)
811 struct dasd_device *device;
813 device = (struct dasd_device *) ptr;
814 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
815 /* re-activate request queue */
816 device->stopped &= ~DASD_STOPPED_PENDING;
817 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
818 dasd_schedule_bh(device);
822 * Setup timeout for a device in jiffies.
825 dasd_set_timer(struct dasd_device *device, int expires)
828 if (timer_pending(&device->timer))
829 del_timer(&device->timer);
832 if (timer_pending(&device->timer)) {
833 if (mod_timer(&device->timer, jiffies + expires))
836 device->timer.function = dasd_timeout_device;
837 device->timer.data = (unsigned long) device;
838 device->timer.expires = jiffies + expires;
839 add_timer(&device->timer);
843 * Clear timeout for a device.
846 dasd_clear_timer(struct dasd_device *device)
848 if (timer_pending(&device->timer))
849 del_timer(&device->timer);
853 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
855 struct dasd_ccw_req *cqr;
856 struct dasd_device *device;
858 cqr = (struct dasd_ccw_req *) intparm;
859 if (cqr->status != DASD_CQR_IN_IO) {
861 "invalid status in handle_killed_request: "
862 "bus_id %s, status %02x",
863 cdev->dev.bus_id, cqr->status);
867 device = (struct dasd_device *) cqr->device;
868 if (device == NULL ||
869 device != dasd_device_from_cdev(cdev) ||
870 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
871 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
876 /* Schedule request to be retried. */
877 cqr->status = DASD_CQR_QUEUED;
879 dasd_clear_timer(device);
880 dasd_schedule_bh(device);
881 dasd_put_device(device);
885 dasd_handle_state_change_pending(struct dasd_device *device)
887 struct dasd_ccw_req *cqr;
888 struct list_head *l, *n;
890 /* First of all start sense subsystem status request. */
891 dasd_eer_snss(device);
893 device->stopped &= ~DASD_STOPPED_PENDING;
895 /* restart all 'running' IO on queue */
896 list_for_each_safe(l, n, &device->ccw_queue) {
897 cqr = list_entry(l, struct dasd_ccw_req, list);
898 if (cqr->status == DASD_CQR_IN_IO) {
899 cqr->status = DASD_CQR_QUEUED;
902 dasd_clear_timer(device);
903 dasd_schedule_bh(device);
907 * Interrupt handler for "normal" ssch-io based dasd devices.
910 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
913 struct dasd_ccw_req *cqr, *next;
914 struct dasd_device *device;
915 unsigned long long now;
921 switch (PTR_ERR(irb)) {
923 dasd_handle_killed_request(cdev, intparm);
926 printk(KERN_WARNING"%s(%s): request timed out\n",
927 __FUNCTION__, cdev->dev.bus_id);
928 //FIXME - dasd uses own timeout interface...
931 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
932 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
939 DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
940 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
941 (unsigned int) intparm);
943 /* first of all check for state change pending interrupt */
944 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
945 if ((irb->scsw.dstat & mask) == mask) {
946 device = dasd_device_from_cdev(cdev);
947 if (!IS_ERR(device)) {
948 dasd_handle_state_change_pending(device);
949 dasd_put_device(device);
954 cqr = (struct dasd_ccw_req *) intparm;
956 /* check for unsolicited interrupts */
959 "unsolicited interrupt received: bus_id %s",
964 device = (struct dasd_device *) cqr->device;
965 if (device == NULL ||
966 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
967 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
972 /* Check for clear pending */
973 if (cqr->status == DASD_CQR_CLEAR &&
974 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
975 cqr->status = DASD_CQR_QUEUED;
976 dasd_clear_timer(device);
977 dasd_schedule_bh(device);
981 /* check status - the request might have been killed by dyn detach */
982 if (cqr->status != DASD_CQR_IN_IO) {
984 "invalid status: bus_id %s, status %02x",
985 cdev->dev.bus_id, cqr->status);
988 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
989 ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
991 /* Find out the appropriate era_action. */
992 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
993 era = dasd_era_fatal;
994 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
995 irb->scsw.cstat == 0 &&
996 !irb->esw.esw0.erw.cons)
998 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
999 era = dasd_era_fatal; /* don't recover this request */
1000 else if (irb->esw.esw0.erw.cons)
1001 era = device->discipline->examine_error(cqr, irb);
1003 era = dasd_era_recover;
1005 DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
1007 if (era == dasd_era_none) {
1008 cqr->status = DASD_CQR_DONE;
1010 /* Start first request on queue if possible -> fast_io. */
1011 if (cqr->list.next != &device->ccw_queue) {
1012 next = list_entry(cqr->list.next,
1013 struct dasd_ccw_req, list);
1014 if ((next->status == DASD_CQR_QUEUED) &&
1015 (!device->stopped)) {
1016 if (device->discipline->start_IO(next) == 0)
1017 expires = next->expires;
1019 DEV_MESSAGE(KERN_DEBUG, device, "%s",
1020 "Interrupt fastpath "
1024 } else { /* error */
1025 memcpy(&cqr->irb, irb, sizeof (struct irb));
1027 /* dump sense data */
1028 dasd_log_sense(cqr, irb);
1031 case dasd_era_fatal:
1032 cqr->status = DASD_CQR_FAILED;
1035 case dasd_era_recover:
1036 cqr->status = DASD_CQR_ERROR;
1043 dasd_set_timer(device, expires);
1045 dasd_clear_timer(device);
1046 dasd_schedule_bh(device);
1050 * posts the buffer_cache about a finalized request
1053 dasd_end_request(struct request *req, int uptodate)
1055 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1057 add_disk_randomness(req->rq_disk);
1058 end_that_request_last(req, uptodate);
1062 * Process finished error recovery ccw.
1065 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1067 dasd_erp_fn_t erp_fn;
1069 if (cqr->status == DASD_CQR_DONE)
1070 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1072 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1073 erp_fn = device->discipline->erp_postaction(cqr);
1078 * Process ccw request queue.
1081 __dasd_process_ccw_queue(struct dasd_device * device,
1082 struct list_head *final_queue)
1084 struct list_head *l, *n;
1085 struct dasd_ccw_req *cqr;
1086 dasd_erp_fn_t erp_fn;
1089 /* Process request with final status. */
1090 list_for_each_safe(l, n, &device->ccw_queue) {
1091 cqr = list_entry(l, struct dasd_ccw_req, list);
1092 /* Stop list processing at the first non-final request. */
1093 if (cqr->status != DASD_CQR_DONE &&
1094 cqr->status != DASD_CQR_FAILED &&
1095 cqr->status != DASD_CQR_ERROR)
1097 /* Process requests with DASD_CQR_ERROR */
1098 if (cqr->status == DASD_CQR_ERROR) {
1099 if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1100 cqr->status = DASD_CQR_FAILED;
1101 cqr->stopclk = get_clock();
1103 if (cqr->irb.esw.esw0.erw.cons) {
1104 erp_fn = device->discipline->
1108 dasd_default_erp_action(cqr);
1113 /* First of all call extended error reporting. */
1114 if (dasd_eer_enabled(device) &&
1115 cqr->status == DASD_CQR_FAILED) {
1116 dasd_eer_write(device, cqr, DASD_EER_FATALERROR);
1118 /* restart request */
1119 cqr->status = DASD_CQR_QUEUED;
1121 device->stopped |= DASD_STOPPED_QUIESCE;
1125 /* Process finished ERP request. */
1127 __dasd_process_erp(device, cqr);
1131 /* Rechain finished requests to final queue */
1132 cqr->endclk = get_clock();
1133 list_move_tail(&cqr->list, final_queue);
1138 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1140 struct request *req;
1141 struct dasd_device *device;
1144 req = (struct request *) data;
1145 device = cqr->device;
1146 dasd_profile_end(device, cqr, req);
1147 status = cqr->device->discipline->free_cp(cqr,req);
1148 spin_lock_irq(&device->request_queue_lock);
1149 dasd_end_request(req, status);
1150 spin_unlock_irq(&device->request_queue_lock);
1155 * Fetch requests from the block device queue.
1158 __dasd_process_blk_queue(struct dasd_device * device)
1160 request_queue_t *queue;
1161 struct request *req;
1162 struct dasd_ccw_req *cqr;
1165 queue = device->request_queue;
1166 /* No queue ? Then there is nothing to do. */
1171 * We requeue request from the block device queue to the ccw
1172 * queue only in two states. In state DASD_STATE_READY the
1173 * partition detection is done and we need to requeue requests
1174 * for that. State DASD_STATE_ONLINE is normal block device
1177 if (device->state != DASD_STATE_READY &&
1178 device->state != DASD_STATE_ONLINE)
1181 /* Now we try to fetch requests from the request queue */
1182 list_for_each_entry(cqr, &device->ccw_queue, list)
1183 if (cqr->status == DASD_CQR_QUEUED)
1185 while (!blk_queue_plugged(queue) &&
1186 elv_next_request(queue) &&
1187 nr_queued < DASD_CHANQ_MAX_SIZE) {
1188 req = elv_next_request(queue);
1190 if (device->features & DASD_FEATURE_READONLY &&
1191 rq_data_dir(req) == WRITE) {
1192 DBF_DEV_EVENT(DBF_ERR, device,
1193 "Rejecting write request %p",
1195 blkdev_dequeue_request(req);
1196 dasd_end_request(req, 0);
1199 if (device->stopped & DASD_STOPPED_DC_EIO) {
1200 blkdev_dequeue_request(req);
1201 dasd_end_request(req, 0);
1204 cqr = device->discipline->build_cp(device, req);
1206 if (PTR_ERR(cqr) == -ENOMEM)
1207 break; /* terminate request queue loop */
1208 DBF_DEV_EVENT(DBF_ERR, device,
1209 "CCW creation failed (rc=%ld) "
1212 blkdev_dequeue_request(req);
1213 dasd_end_request(req, 0);
1216 cqr->callback = dasd_end_request_cb;
1217 cqr->callback_data = (void *) req;
1218 cqr->status = DASD_CQR_QUEUED;
1219 blkdev_dequeue_request(req);
1220 list_add_tail(&cqr->list, &device->ccw_queue);
1221 dasd_profile_start(device, cqr, req);
1227 * Take a look at the first request on the ccw queue and check
1228 * if it reached its expire time. If so, terminate the IO.
1231 __dasd_check_expire(struct dasd_device * device)
1233 struct dasd_ccw_req *cqr;
1235 if (list_empty(&device->ccw_queue))
1237 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1238 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1239 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1240 if (device->discipline->term_IO(cqr) != 0)
1241 /* Hmpf, try again in 1/10 sec */
1242 dasd_set_timer(device, 10);
1248 * Take a look at the first request on the ccw queue and check
1249 * if it needs to be started.
1252 __dasd_start_head(struct dasd_device * device)
1254 struct dasd_ccw_req *cqr;
1257 if (list_empty(&device->ccw_queue))
1259 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1260 if (cqr->status != DASD_CQR_QUEUED)
1262 /* Non-temporary stop condition will trigger fail fast */
1263 if (device->stopped & ~DASD_STOPPED_PENDING &&
1264 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1265 (!dasd_eer_enabled(device))) {
1266 cqr->status = DASD_CQR_FAILED;
1267 dasd_schedule_bh(device);
1270 /* Don't try to start requests if device is stopped */
1271 if (device->stopped)
1274 rc = device->discipline->start_IO(cqr);
1276 dasd_set_timer(device, cqr->expires);
1277 else if (rc == -EACCES) {
1278 dasd_schedule_bh(device);
1280 /* Hmpf, try again in 1/2 sec */
1281 dasd_set_timer(device, 50);
1285 * Remove requests from the ccw queue.
1288 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1290 struct list_head flush_queue;
1291 struct list_head *l, *n;
1292 struct dasd_ccw_req *cqr;
1294 INIT_LIST_HEAD(&flush_queue);
1295 spin_lock_irq(get_ccwdev_lock(device->cdev));
1296 list_for_each_safe(l, n, &device->ccw_queue) {
1297 cqr = list_entry(l, struct dasd_ccw_req, list);
1298 /* Flush all request or only block device requests? */
1299 if (all == 0 && cqr->callback == dasd_end_request_cb)
1301 if (cqr->status == DASD_CQR_IN_IO)
1302 device->discipline->term_IO(cqr);
1303 if (cqr->status != DASD_CQR_DONE ||
1304 cqr->status != DASD_CQR_FAILED) {
1305 cqr->status = DASD_CQR_FAILED;
1306 cqr->stopclk = get_clock();
1308 /* Process finished ERP request. */
1310 __dasd_process_erp(device, cqr);
1313 /* Rechain request on device request queue */
1314 cqr->endclk = get_clock();
1315 list_move_tail(&cqr->list, &flush_queue);
1317 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1318 /* Now call the callback function of flushed requests */
1319 list_for_each_safe(l, n, &flush_queue) {
1320 cqr = list_entry(l, struct dasd_ccw_req, list);
1321 if (cqr->callback != NULL)
1322 (cqr->callback)(cqr, cqr->callback_data);
1327 * Acquire the device lock and process queues for the device.
1330 dasd_tasklet(struct dasd_device * device)
1332 struct list_head final_queue;
1333 struct list_head *l, *n;
1334 struct dasd_ccw_req *cqr;
1336 atomic_set (&device->tasklet_scheduled, 0);
1337 INIT_LIST_HEAD(&final_queue);
1338 spin_lock_irq(get_ccwdev_lock(device->cdev));
1339 /* Check expire time of first request on the ccw queue. */
1340 __dasd_check_expire(device);
1341 /* Finish off requests on ccw queue */
1342 __dasd_process_ccw_queue(device, &final_queue);
1343 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1344 /* Now call the callback function of requests with final status */
1345 list_for_each_safe(l, n, &final_queue) {
1346 cqr = list_entry(l, struct dasd_ccw_req, list);
1347 list_del_init(&cqr->list);
1348 if (cqr->callback != NULL)
1349 (cqr->callback)(cqr, cqr->callback_data);
1351 spin_lock_irq(&device->request_queue_lock);
1352 spin_lock(get_ccwdev_lock(device->cdev));
1353 /* Get new request from the block device request queue */
1354 __dasd_process_blk_queue(device);
1355 /* Now check if the head of the ccw queue needs to be started. */
1356 __dasd_start_head(device);
1357 spin_unlock(get_ccwdev_lock(device->cdev));
1358 spin_unlock_irq(&device->request_queue_lock);
1359 dasd_put_device(device);
1363 * Schedules a call to dasd_tasklet over the device tasklet.
1366 dasd_schedule_bh(struct dasd_device * device)
1368 /* Protect against rescheduling. */
1369 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
1371 dasd_get_device(device);
1372 tasklet_hi_schedule(&device->tasklet);
1376 * Queue a request to the head of the ccw_queue. Start the I/O if
1380 dasd_add_request_head(struct dasd_ccw_req *req)
1382 struct dasd_device *device;
1383 unsigned long flags;
1385 device = req->device;
1386 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1387 req->status = DASD_CQR_QUEUED;
1388 req->device = device;
1389 list_add(&req->list, &device->ccw_queue);
1390 /* let the bh start the request to keep them in order */
1391 dasd_schedule_bh(device);
1392 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1396 * Queue a request to the tail of the ccw_queue. Start the I/O if
1400 dasd_add_request_tail(struct dasd_ccw_req *req)
1402 struct dasd_device *device;
1403 unsigned long flags;
1405 device = req->device;
1406 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1407 req->status = DASD_CQR_QUEUED;
1408 req->device = device;
1409 list_add_tail(&req->list, &device->ccw_queue);
1410 /* let the bh start the request to keep them in order */
1411 dasd_schedule_bh(device);
1412 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1419 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1421 wake_up((wait_queue_head_t *) data);
1425 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1427 struct dasd_device *device;
1430 device = cqr->device;
1431 spin_lock_irq(get_ccwdev_lock(device->cdev));
1432 rc = ((cqr->status == DASD_CQR_DONE ||
1433 cqr->status == DASD_CQR_FAILED) &&
1434 list_empty(&cqr->list));
1435 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1440 * Attempts to start a special ccw queue and waits for its completion.
1443 dasd_sleep_on(struct dasd_ccw_req * cqr)
1445 wait_queue_head_t wait_q;
1446 struct dasd_device *device;
1449 device = cqr->device;
1450 spin_lock_irq(get_ccwdev_lock(device->cdev));
1452 init_waitqueue_head (&wait_q);
1453 cqr->callback = dasd_wakeup_cb;
1454 cqr->callback_data = (void *) &wait_q;
1455 cqr->status = DASD_CQR_QUEUED;
1456 list_add_tail(&cqr->list, &device->ccw_queue);
1458 /* let the bh start the request to keep them in order */
1459 dasd_schedule_bh(device);
1461 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1463 wait_event(wait_q, _wait_for_wakeup(cqr));
1465 /* Request status is either done or failed. */
1466 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1471 * Attempts to start a special ccw queue and wait interruptible
1472 * for its completion.
1475 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1477 wait_queue_head_t wait_q;
1478 struct dasd_device *device;
1481 device = cqr->device;
1482 spin_lock_irq(get_ccwdev_lock(device->cdev));
1484 init_waitqueue_head (&wait_q);
1485 cqr->callback = dasd_wakeup_cb;
1486 cqr->callback_data = (void *) &wait_q;
1487 cqr->status = DASD_CQR_QUEUED;
1488 list_add_tail(&cqr->list, &device->ccw_queue);
1490 /* let the bh start the request to keep them in order */
1491 dasd_schedule_bh(device);
1492 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1496 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1497 if (rc != -ERESTARTSYS) {
1498 /* Request is final (done or failed) */
1499 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1502 spin_lock_irq(get_ccwdev_lock(device->cdev));
1503 switch (cqr->status) {
1504 case DASD_CQR_IN_IO:
1505 /* terminate runnig cqr */
1506 if (device->discipline->term_IO) {
1508 device->discipline->term_IO(cqr);
1510 * wait (non-interruptible) for final status
1511 * because signal ist still pending
1513 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1514 wait_event(wait_q, _wait_for_wakeup(cqr));
1515 spin_lock_irq(get_ccwdev_lock(device->cdev));
1516 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1520 case DASD_CQR_QUEUED:
1522 list_del_init(&cqr->list);
1527 /* cqr with 'non-interruptable' status - just wait */
1530 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1536 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1537 * for eckd devices) the currently running request has to be terminated
1538 * and be put back to status queued, before the special request is added
1539 * to the head of the queue. Then the special request is waited on normally.
1542 _dasd_term_running_cqr(struct dasd_device *device)
1544 struct dasd_ccw_req *cqr;
1547 if (list_empty(&device->ccw_queue))
1549 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1550 rc = device->discipline->term_IO(cqr);
1552 /* termination successful */
1553 cqr->status = DASD_CQR_QUEUED;
1554 cqr->startclk = cqr->stopclk = 0;
1561 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1563 wait_queue_head_t wait_q;
1564 struct dasd_device *device;
1567 device = cqr->device;
1568 spin_lock_irq(get_ccwdev_lock(device->cdev));
1569 rc = _dasd_term_running_cqr(device);
1571 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1575 init_waitqueue_head (&wait_q);
1576 cqr->callback = dasd_wakeup_cb;
1577 cqr->callback_data = (void *) &wait_q;
1578 cqr->status = DASD_CQR_QUEUED;
1579 list_add(&cqr->list, &device->ccw_queue);
1581 /* let the bh start the request to keep them in order */
1582 dasd_schedule_bh(device);
1584 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1586 wait_event(wait_q, _wait_for_wakeup(cqr));
1588 /* Request status is either done or failed. */
1589 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1594 * Cancels a request that was started with dasd_sleep_on_req.
1595 * This is useful to timeout requests. The request will be
1596 * terminated if it is currently in i/o.
1597 * Returns 1 if the request has been terminated.
1600 dasd_cancel_req(struct dasd_ccw_req *cqr)
1602 struct dasd_device *device = cqr->device;
1603 unsigned long flags;
1607 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1608 switch (cqr->status) {
1609 case DASD_CQR_QUEUED:
1610 /* request was not started - just set to failed */
1611 cqr->status = DASD_CQR_FAILED;
1613 case DASD_CQR_IN_IO:
1614 /* request in IO - terminate IO and release again */
1615 if (device->discipline->term_IO(cqr) != 0)
1616 /* what to do if unable to terminate ??????
1618 cqr->status = DASD_CQR_FAILED;
1619 cqr->stopclk = get_clock();
1623 case DASD_CQR_FAILED:
1624 /* already finished - do nothing */
1627 DEV_MESSAGE(KERN_ALERT, device,
1628 "invalid status %02x in request",
1633 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1634 dasd_schedule_bh(device);
1639 * SECTION: Block device operations (request queue, partitions, open, release).
1643 * Dasd request queue function. Called from ll_rw_blk.c
1646 do_dasd_request(request_queue_t * queue)
1648 struct dasd_device *device;
1650 device = (struct dasd_device *) queue->queuedata;
1651 spin_lock(get_ccwdev_lock(device->cdev));
1652 /* Get new request from the block device request queue */
1653 __dasd_process_blk_queue(device);
1654 /* Now check if the head of the ccw queue needs to be started. */
1655 __dasd_start_head(device);
1656 spin_unlock(get_ccwdev_lock(device->cdev));
1660 * Allocate and initialize request queue and default I/O scheduler.
1663 dasd_alloc_queue(struct dasd_device * device)
1667 device->request_queue = blk_init_queue(do_dasd_request,
1668 &device->request_queue_lock);
1669 if (device->request_queue == NULL)
1672 device->request_queue->queuedata = device;
1674 elevator_exit(device->request_queue->elevator);
1675 rc = elevator_init(device->request_queue, "deadline");
1677 blk_cleanup_queue(device->request_queue);
1684 * Allocate and initialize request queue.
1687 dasd_setup_queue(struct dasd_device * device)
1691 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1692 max = device->discipline->max_blocks << device->s2b_shift;
1693 blk_queue_max_sectors(device->request_queue, max);
1694 blk_queue_max_phys_segments(device->request_queue, -1L);
1695 blk_queue_max_hw_segments(device->request_queue, -1L);
1696 blk_queue_max_segment_size(device->request_queue, -1L);
1697 blk_queue_segment_boundary(device->request_queue, -1L);
1698 blk_queue_ordered(device->request_queue, QUEUE_ORDERED_TAG, NULL);
1702 * Deactivate and free request queue.
1705 dasd_free_queue(struct dasd_device * device)
1707 if (device->request_queue) {
1708 blk_cleanup_queue(device->request_queue);
1709 device->request_queue = NULL;
1714 * Flush request on the request queue.
1717 dasd_flush_request_queue(struct dasd_device * device)
1719 struct request *req;
1721 if (!device->request_queue)
1724 spin_lock_irq(&device->request_queue_lock);
1725 while (!list_empty(&device->request_queue->queue_head)) {
1726 req = elv_next_request(device->request_queue);
1729 dasd_end_request(req, 0);
1730 blkdev_dequeue_request(req);
1732 spin_unlock_irq(&device->request_queue_lock);
1736 dasd_open(struct inode *inp, struct file *filp)
1738 struct gendisk *disk = inp->i_bdev->bd_disk;
1739 struct dasd_device *device = disk->private_data;
1742 atomic_inc(&device->open_count);
1743 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1748 if (!try_module_get(device->discipline->owner)) {
1753 if (dasd_probeonly) {
1754 DEV_MESSAGE(KERN_INFO, device, "%s",
1755 "No access to device due to probeonly mode");
1760 if (device->state <= DASD_STATE_BASIC) {
1761 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1762 " Cannot open unrecognized device");
1770 module_put(device->discipline->owner);
1772 atomic_dec(&device->open_count);
1777 dasd_release(struct inode *inp, struct file *filp)
1779 struct gendisk *disk = inp->i_bdev->bd_disk;
1780 struct dasd_device *device = disk->private_data;
1782 atomic_dec(&device->open_count);
1783 module_put(device->discipline->owner);
1788 * Return disk geometry.
1791 dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1793 struct dasd_device *device;
1795 device = bdev->bd_disk->private_data;
1799 if (!device->discipline ||
1800 !device->discipline->fill_geometry)
1803 device->discipline->fill_geometry(device, geo);
1804 geo->start = get_start_sect(bdev) >> device->s2b_shift;
1808 struct block_device_operations
1809 dasd_device_operations = {
1810 .owner = THIS_MODULE,
1812 .release = dasd_release,
1813 .ioctl = dasd_ioctl,
1814 .compat_ioctl = dasd_compat_ioctl,
1815 .getgeo = dasd_getgeo,
1822 #ifdef CONFIG_PROC_FS
1826 if (dasd_page_cache != NULL) {
1827 kmem_cache_destroy(dasd_page_cache);
1828 dasd_page_cache = NULL;
1830 dasd_gendisk_exit();
1832 devfs_remove("dasd");
1833 if (dasd_debug_area != NULL) {
1834 debug_unregister(dasd_debug_area);
1835 dasd_debug_area = NULL;
1840 * SECTION: common functions for ccw_driver use
1844 * Initial attempt at a probe function. this can be simplified once
1845 * the other detection code is gone.
1848 dasd_generic_probe (struct ccw_device *cdev,
1849 struct dasd_discipline *discipline)
1853 ret = dasd_add_sysfs_files(cdev);
1856 "dasd_generic_probe: could not add sysfs entries "
1857 "for %s\n", cdev->dev.bus_id);
1859 cdev->handler = &dasd_int_handler;
1866 * This will one day be called from a global not_oper handler.
1867 * It is also used by driver_unregister during module unload.
1870 dasd_generic_remove (struct ccw_device *cdev)
1872 struct dasd_device *device;
1874 cdev->handler = NULL;
1876 dasd_remove_sysfs_files(cdev);
1877 device = dasd_device_from_cdev(cdev);
1880 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1881 /* Already doing offline processing */
1882 dasd_put_device(device);
1886 * This device is removed unconditionally. Set offline
1887 * flag to prevent dasd_open from opening it while it is
1888 * no quite down yet.
1890 dasd_set_target_state(device, DASD_STATE_NEW);
1891 /* dasd_delete_device destroys the device reference. */
1892 dasd_delete_device(device);
1896 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
1897 * the device is detected for the first time and is supposed to be used
1898 * or the user has started activation through sysfs.
1901 dasd_generic_set_online (struct ccw_device *cdev,
1902 struct dasd_discipline *base_discipline)
1905 struct dasd_discipline *discipline;
1906 struct dasd_device *device;
1909 device = dasd_create_device(cdev);
1911 return PTR_ERR(device);
1913 discipline = base_discipline;
1914 if (device->features & DASD_FEATURE_USEDIAG) {
1915 if (!dasd_diag_discipline_pointer) {
1916 printk (KERN_WARNING
1917 "dasd_generic couldn't online device %s "
1918 "- discipline DIAG not available\n",
1920 dasd_delete_device(device);
1923 discipline = dasd_diag_discipline_pointer;
1925 if (!try_module_get(base_discipline->owner)) {
1926 dasd_delete_device(device);
1929 if (!try_module_get(discipline->owner)) {
1930 module_put(base_discipline->owner);
1931 dasd_delete_device(device);
1934 device->base_discipline = base_discipline;
1935 device->discipline = discipline;
1937 rc = discipline->check_device(device);
1939 printk (KERN_WARNING
1940 "dasd_generic couldn't online device %s "
1941 "with discipline %s rc=%i\n",
1942 cdev->dev.bus_id, discipline->name, rc);
1943 module_put(discipline->owner);
1944 module_put(base_discipline->owner);
1945 dasd_delete_device(device);
1949 dasd_set_target_state(device, DASD_STATE_ONLINE);
1950 if (device->state <= DASD_STATE_KNOWN) {
1951 printk (KERN_WARNING
1952 "dasd_generic discipline not found for %s\n",
1955 dasd_set_target_state(device, DASD_STATE_NEW);
1956 dasd_delete_device(device);
1958 pr_debug("dasd_generic device %s found\n",
1961 /* FIXME: we have to wait for the root device but we don't want
1962 * to wait for each single device but for all at once. */
1963 wait_event(dasd_init_waitq, _wait_for_device(device));
1965 dasd_put_device(device);
1971 dasd_generic_set_offline (struct ccw_device *cdev)
1973 struct dasd_device *device;
1974 int max_count, open_count;
1976 device = dasd_device_from_cdev(cdev);
1978 return PTR_ERR(device);
1979 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1980 /* Already doing offline processing */
1981 dasd_put_device(device);
1985 * We must make sure that this device is currently not in use.
1986 * The open_count is increased for every opener, that includes
1987 * the blkdev_get in dasd_scan_partitions. We are only interested
1988 * in the other openers.
1990 max_count = device->bdev ? 0 : -1;
1991 open_count = (int) atomic_read(&device->open_count);
1992 if (open_count > max_count) {
1994 printk (KERN_WARNING "Can't offline dasd device with "
1995 "open count = %i.\n",
1998 printk (KERN_WARNING "%s",
1999 "Can't offline dasd device due to internal "
2001 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
2002 dasd_put_device(device);
2005 dasd_set_target_state(device, DASD_STATE_NEW);
2006 /* dasd_delete_device destroys the device reference. */
2007 dasd_delete_device(device);
2013 dasd_generic_notify(struct ccw_device *cdev, int event)
2015 struct dasd_device *device;
2016 struct dasd_ccw_req *cqr;
2017 unsigned long flags;
2020 device = dasd_device_from_cdev(cdev);
2023 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
2028 /* First of all call extended error reporting. */
2029 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
2031 if (device->state < DASD_STATE_BASIC)
2033 /* Device is active. We want to keep it. */
2034 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
2035 list_for_each_entry(cqr, &device->ccw_queue, list)
2036 if (cqr->status == DASD_CQR_IN_IO)
2037 cqr->status = DASD_CQR_FAILED;
2038 device->stopped |= DASD_STOPPED_DC_EIO;
2040 list_for_each_entry(cqr, &device->ccw_queue, list)
2041 if (cqr->status == DASD_CQR_IN_IO) {
2042 cqr->status = DASD_CQR_QUEUED;
2045 device->stopped |= DASD_STOPPED_DC_WAIT;
2046 dasd_set_timer(device, 0);
2048 dasd_schedule_bh(device);
2052 /* FIXME: add a sanity check. */
2053 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
2054 dasd_schedule_bh(device);
2058 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2059 dasd_put_device(device);
2064 * Automatically online either all dasd devices (dasd_autodetect) or
2065 * all devices specified with dasd= parameters.
2068 __dasd_auto_online(struct device *dev, void *data)
2070 struct ccw_device *cdev;
2072 cdev = to_ccwdev(dev);
2073 if (dasd_autodetect || dasd_busid_known(cdev->dev.bus_id) == 0)
2074 ccw_device_set_online(cdev);
2079 dasd_generic_auto_online (struct ccw_driver *dasd_discipline_driver)
2081 struct device_driver *drv;
2083 drv = get_driver(&dasd_discipline_driver->driver);
2084 driver_for_each_device(drv, NULL, NULL, __dasd_auto_online);
2094 init_waitqueue_head(&dasd_init_waitq);
2096 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2097 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long));
2098 if (dasd_debug_area == NULL) {
2102 debug_register_view(dasd_debug_area, &debug_sprintf_view);
2103 debug_set_level(dasd_debug_area, DBF_EMERG);
2105 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
2107 dasd_diag_discipline_pointer = NULL;
2109 rc = devfs_mk_dir("dasd");
2112 rc = dasd_devmap_init();
2115 rc = dasd_gendisk_init();
2121 rc = dasd_eer_init();
2124 #ifdef CONFIG_PROC_FS
2125 rc = dasd_proc_init();
2132 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2137 module_init(dasd_init);
2138 module_exit(dasd_exit);
2140 EXPORT_SYMBOL(dasd_debug_area);
2141 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2143 EXPORT_SYMBOL(dasd_add_request_head);
2144 EXPORT_SYMBOL(dasd_add_request_tail);
2145 EXPORT_SYMBOL(dasd_cancel_req);
2146 EXPORT_SYMBOL(dasd_clear_timer);
2147 EXPORT_SYMBOL(dasd_enable_device);
2148 EXPORT_SYMBOL(dasd_int_handler);
2149 EXPORT_SYMBOL(dasd_kfree_request);
2150 EXPORT_SYMBOL(dasd_kick_device);
2151 EXPORT_SYMBOL(dasd_kmalloc_request);
2152 EXPORT_SYMBOL(dasd_schedule_bh);
2153 EXPORT_SYMBOL(dasd_set_target_state);
2154 EXPORT_SYMBOL(dasd_set_timer);
2155 EXPORT_SYMBOL(dasd_sfree_request);
2156 EXPORT_SYMBOL(dasd_sleep_on);
2157 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2158 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2159 EXPORT_SYMBOL(dasd_smalloc_request);
2160 EXPORT_SYMBOL(dasd_start_IO);
2161 EXPORT_SYMBOL(dasd_term_IO);
2163 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2164 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2165 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2166 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2167 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
2168 EXPORT_SYMBOL_GPL(dasd_generic_auto_online);
2171 * Overrides for Emacs so that we follow Linus's tabbing style.
2172 * Emacs will notice this stuff at the end of the file and automatically
2173 * adjust the settings for this buffer only. This must remain at the end
2175 * ---------------------------------------------------------------------------
2178 * c-brace-imaginary-offset: 0
2179 * c-brace-offset: -4
2180 * c-argdecl-indent: 4
2181 * c-label-offset: -4
2182 * c-continued-statement-offset: 4
2183 * c-continued-brace-offset: 0
2184 * indent-tabs-mode: 1