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/kmod.h>
13 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/ctype.h>
16 #include <linux/major.h>
17 #include <linux/slab.h>
18 #include <linux/buffer_head.h>
19 #include <linux/hdreg.h>
21 #include <asm/ccwdev.h>
22 #include <asm/ebcdic.h>
23 #include <asm/idals.h>
24 #include <asm/todclk.h>
27 #define PRINTK_HEADER "dasd:"
31 * SECTION: Constant definitions to be used within this file
33 #define DASD_CHANQ_MAX_SIZE 4
36 * SECTION: exported variables of dasd.c
38 debug_info_t *dasd_debug_area;
39 struct dasd_discipline *dasd_diag_discipline_pointer;
41 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
42 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
43 " Copyright 2000 IBM Corporation");
44 MODULE_SUPPORTED_DEVICE("dasd");
45 MODULE_LICENSE("GPL");
48 * SECTION: prototypes for static functions of dasd.c
50 static int dasd_alloc_queue(struct dasd_device * device);
51 static void dasd_setup_queue(struct dasd_device * device);
52 static void dasd_free_queue(struct dasd_device * device);
53 static void dasd_flush_request_queue(struct dasd_device *);
54 static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
55 static int dasd_flush_ccw_queue(struct dasd_device *, int);
56 static void dasd_tasklet(struct dasd_device *);
57 static void do_kick_device(void *data);
60 * SECTION: Operations on the device structure.
62 static wait_queue_head_t dasd_init_waitq;
63 static wait_queue_head_t dasd_flush_wq;
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);
171 * Request the irq line for the device.
174 dasd_state_known_to_basic(struct dasd_device * device)
178 /* Allocate and register gendisk structure. */
179 rc = dasd_gendisk_alloc(device);
183 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
184 device->debug_area = debug_register(device->cdev->dev.bus_id, 1, 2,
186 debug_register_view(device->debug_area, &debug_sprintf_view);
187 debug_set_level(device->debug_area, DBF_WARNING);
188 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
190 device->state = DASD_STATE_BASIC;
195 * Release the irq line for the device. Terminate any running i/o.
198 dasd_state_basic_to_known(struct dasd_device * device)
202 dasd_gendisk_free(device);
203 rc = dasd_flush_ccw_queue(device, 1);
206 dasd_clear_timer(device);
208 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
209 if (device->debug_area != NULL) {
210 debug_unregister(device->debug_area);
211 device->debug_area = NULL;
213 device->state = DASD_STATE_KNOWN;
218 * Do the initial analysis. The do_analysis function may return
219 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
220 * until the discipline decides to continue the startup sequence
221 * by calling the function dasd_change_state. The eckd disciplines
222 * uses this to start a ccw that detects the format. The completion
223 * interrupt for this detection ccw uses the kernel event daemon to
224 * trigger the call to dasd_change_state. All this is done in the
225 * discipline code, see dasd_eckd.c.
226 * After the analysis ccw is done (do_analysis returned 0) the block
228 * In case the analysis returns an error, the device setup is stopped
229 * (a fake disk was already added to allow formatting).
232 dasd_state_basic_to_ready(struct dasd_device * device)
237 if (device->discipline->do_analysis != NULL)
238 rc = device->discipline->do_analysis(device);
241 device->state = DASD_STATE_UNFMT;
244 /* make disk known with correct capacity */
245 dasd_setup_queue(device);
246 set_capacity(device->gdp, device->blocks << device->s2b_shift);
247 device->state = DASD_STATE_READY;
248 rc = dasd_scan_partitions(device);
250 device->state = DASD_STATE_BASIC;
255 * Remove device from block device layer. Destroy dirty buffers.
256 * Forget format information. Check if the target level is basic
257 * and if it is create fake disk for formatting.
260 dasd_state_ready_to_basic(struct dasd_device * device)
264 rc = dasd_flush_ccw_queue(device, 0);
267 dasd_destroy_partitions(device);
268 dasd_flush_request_queue(device);
270 device->bp_block = 0;
271 device->s2b_shift = 0;
272 device->state = DASD_STATE_BASIC;
280 dasd_state_unfmt_to_basic(struct dasd_device * device)
282 device->state = DASD_STATE_BASIC;
287 * Make the device online and schedule the bottom half to start
288 * the requeueing of requests from the linux request queue to the
292 dasd_state_ready_to_online(struct dasd_device * device)
294 device->state = DASD_STATE_ONLINE;
295 dasd_schedule_bh(device);
300 * Stop the requeueing of requests again.
303 dasd_state_online_to_ready(struct dasd_device * device)
305 device->state = DASD_STATE_READY;
310 * Device startup state changes.
313 dasd_increase_state(struct dasd_device *device)
318 if (device->state == DASD_STATE_NEW &&
319 device->target >= DASD_STATE_KNOWN)
320 rc = dasd_state_new_to_known(device);
323 device->state == DASD_STATE_KNOWN &&
324 device->target >= DASD_STATE_BASIC)
325 rc = dasd_state_known_to_basic(device);
328 device->state == DASD_STATE_BASIC &&
329 device->target >= DASD_STATE_READY)
330 rc = dasd_state_basic_to_ready(device);
333 device->state == DASD_STATE_UNFMT &&
334 device->target > DASD_STATE_UNFMT)
338 device->state == DASD_STATE_READY &&
339 device->target >= DASD_STATE_ONLINE)
340 rc = dasd_state_ready_to_online(device);
346 * Device shutdown state changes.
349 dasd_decrease_state(struct dasd_device *device)
354 if (device->state == DASD_STATE_ONLINE &&
355 device->target <= DASD_STATE_READY)
356 rc = dasd_state_online_to_ready(device);
359 device->state == DASD_STATE_READY &&
360 device->target <= DASD_STATE_BASIC)
361 rc = dasd_state_ready_to_basic(device);
364 device->state == DASD_STATE_UNFMT &&
365 device->target <= DASD_STATE_BASIC)
366 rc = dasd_state_unfmt_to_basic(device);
369 device->state == DASD_STATE_BASIC &&
370 device->target <= DASD_STATE_KNOWN)
371 rc = dasd_state_basic_to_known(device);
374 device->state == DASD_STATE_KNOWN &&
375 device->target <= DASD_STATE_NEW)
376 rc = dasd_state_known_to_new(device);
382 * This is the main startup/shutdown routine.
385 dasd_change_state(struct dasd_device *device)
389 if (device->state == device->target)
390 /* Already where we want to go today... */
392 if (device->state < device->target)
393 rc = dasd_increase_state(device);
395 rc = dasd_decrease_state(device);
396 if (rc && rc != -EAGAIN)
397 device->target = device->state;
399 if (device->state == device->target)
400 wake_up(&dasd_init_waitq);
404 * Kick starter for devices that did not complete the startup/shutdown
405 * procedure or were sleeping because of a pending state.
406 * dasd_kick_device will schedule a call do do_kick_device to the kernel
410 do_kick_device(void *data)
412 struct dasd_device *device;
414 device = (struct dasd_device *) data;
415 dasd_change_state(device);
416 dasd_schedule_bh(device);
417 dasd_put_device(device);
421 dasd_kick_device(struct dasd_device *device)
423 dasd_get_device(device);
424 /* queue call to dasd_kick_device to the kernel event daemon. */
425 schedule_work(&device->kick_work);
429 * Set the target state for a device and starts the state change.
432 dasd_set_target_state(struct dasd_device *device, int target)
434 /* If we are in probeonly mode stop at DASD_STATE_READY. */
435 if (dasd_probeonly && target > DASD_STATE_READY)
436 target = DASD_STATE_READY;
437 if (device->target != target) {
438 if (device->state == target)
439 wake_up(&dasd_init_waitq);
440 device->target = target;
442 if (device->state != device->target)
443 dasd_change_state(device);
447 * Enable devices with device numbers in [from..to].
450 _wait_for_device(struct dasd_device *device)
452 return (device->state == device->target);
456 dasd_enable_device(struct dasd_device *device)
458 dasd_set_target_state(device, DASD_STATE_ONLINE);
459 if (device->state <= DASD_STATE_KNOWN)
460 /* No discipline for device found. */
461 dasd_set_target_state(device, DASD_STATE_NEW);
462 /* Now wait for the devices to come up. */
463 wait_event(dasd_init_waitq, _wait_for_device(device));
467 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
469 #ifdef CONFIG_DASD_PROFILE
471 struct dasd_profile_info_t dasd_global_profile;
472 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
475 * Increments counter in global and local profiling structures.
477 #define dasd_profile_counter(value, counter, device) \
480 for (index = 0; index < 31 && value >> (2+index); index++); \
481 dasd_global_profile.counter[index]++; \
482 device->profile.counter[index]++; \
486 * Add profiling information for cqr before execution.
489 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
493 unsigned int counter;
495 if (dasd_profile_level != DASD_PROFILE_ON)
498 /* count the length of the chanq for statistics */
500 list_for_each(l, &device->ccw_queue)
503 dasd_global_profile.dasd_io_nr_req[counter]++;
504 device->profile.dasd_io_nr_req[counter]++;
508 * Add profiling information for cqr after execution.
511 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
514 long strtime, irqtime, endtime, tottime; /* in microseconds */
515 long tottimeps, sectors;
517 if (dasd_profile_level != DASD_PROFILE_ON)
520 sectors = req->nr_sectors;
521 if (!cqr->buildclk || !cqr->startclk ||
522 !cqr->stopclk || !cqr->endclk ||
526 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
527 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
528 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
529 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
530 tottimeps = tottime / sectors;
532 if (!dasd_global_profile.dasd_io_reqs)
533 memset(&dasd_global_profile, 0,
534 sizeof (struct dasd_profile_info_t));
535 dasd_global_profile.dasd_io_reqs++;
536 dasd_global_profile.dasd_io_sects += sectors;
538 if (!device->profile.dasd_io_reqs)
539 memset(&device->profile, 0,
540 sizeof (struct dasd_profile_info_t));
541 device->profile.dasd_io_reqs++;
542 device->profile.dasd_io_sects += sectors;
544 dasd_profile_counter(sectors, dasd_io_secs, device);
545 dasd_profile_counter(tottime, dasd_io_times, device);
546 dasd_profile_counter(tottimeps, dasd_io_timps, device);
547 dasd_profile_counter(strtime, dasd_io_time1, device);
548 dasd_profile_counter(irqtime, dasd_io_time2, device);
549 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
550 dasd_profile_counter(endtime, dasd_io_time3, device);
553 #define dasd_profile_start(device, cqr, req) do {} while (0)
554 #define dasd_profile_end(device, cqr, req) do {} while (0)
555 #endif /* CONFIG_DASD_PROFILE */
558 * Allocate memory for a channel program with 'cplength' channel
559 * command words and 'datasize' additional space. There are two
560 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
561 * memory and 2) dasd_smalloc_request uses the static ccw memory
562 * that gets allocated for each device.
564 struct dasd_ccw_req *
565 dasd_kmalloc_request(char *magic, int cplength, int datasize,
566 struct dasd_device * device)
568 struct dasd_ccw_req *cqr;
571 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
572 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
574 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
576 return ERR_PTR(-ENOMEM);
579 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
580 GFP_ATOMIC | GFP_DMA);
581 if (cqr->cpaddr == NULL) {
583 return ERR_PTR(-ENOMEM);
588 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
589 if (cqr->data == NULL) {
592 return ERR_PTR(-ENOMEM);
595 strncpy((char *) &cqr->magic, magic, 4);
596 ASCEBC((char *) &cqr->magic, 4);
597 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
598 dasd_get_device(device);
602 struct dasd_ccw_req *
603 dasd_smalloc_request(char *magic, int cplength, int datasize,
604 struct dasd_device * device)
607 struct dasd_ccw_req *cqr;
612 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
613 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
615 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
617 size += cplength * sizeof(struct ccw1);
620 spin_lock_irqsave(&device->mem_lock, flags);
621 cqr = (struct dasd_ccw_req *)
622 dasd_alloc_chunk(&device->ccw_chunks, size);
623 spin_unlock_irqrestore(&device->mem_lock, flags);
625 return ERR_PTR(-ENOMEM);
626 memset(cqr, 0, sizeof(struct dasd_ccw_req));
627 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
630 cqr->cpaddr = (struct ccw1 *) data;
631 data += cplength*sizeof(struct ccw1);
632 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
637 memset(cqr->data, 0, datasize);
639 strncpy((char *) &cqr->magic, magic, 4);
640 ASCEBC((char *) &cqr->magic, 4);
641 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
642 dasd_get_device(device);
647 * Free memory of a channel program. This function needs to free all the
648 * idal lists that might have been created by dasd_set_cda and the
649 * struct dasd_ccw_req itself.
652 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
657 /* Clear any idals used for the request. */
660 clear_normalized_cda(ccw);
661 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
666 dasd_put_device(device);
670 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
674 spin_lock_irqsave(&device->mem_lock, flags);
675 dasd_free_chunk(&device->ccw_chunks, cqr);
676 spin_unlock_irqrestore(&device->mem_lock, flags);
677 dasd_put_device(device);
681 * Check discipline magic in cqr.
684 dasd_check_cqr(struct dasd_ccw_req *cqr)
686 struct dasd_device *device;
690 device = cqr->device;
691 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
692 DEV_MESSAGE(KERN_WARNING, device,
693 " dasd_ccw_req 0x%08x magic doesn't match"
694 " discipline 0x%08x",
696 *(unsigned int *) device->discipline->name);
703 * Terminate the current i/o and set the request to clear_pending.
704 * Timer keeps device runnig.
705 * ccw_device_clear can fail if the i/o subsystem
709 dasd_term_IO(struct dasd_ccw_req * cqr)
711 struct dasd_device *device;
715 rc = dasd_check_cqr(cqr);
719 device = (struct dasd_device *) cqr->device;
720 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
721 rc = ccw_device_clear(device->cdev, (long) cqr);
723 case 0: /* termination successful */
725 cqr->status = DASD_CQR_CLEAR;
726 cqr->stopclk = get_clock();
728 DBF_DEV_EVENT(DBF_DEBUG, device,
729 "terminate cqr %p successful",
733 DBF_DEV_EVENT(DBF_ERR, device, "%s",
734 "device gone, retry");
737 DBF_DEV_EVENT(DBF_ERR, device, "%s",
742 DBF_DEV_EVENT(DBF_ERR, device, "%s",
743 "device busy, retry later");
746 DEV_MESSAGE(KERN_ERR, device,
747 "line %d unknown RC=%d, please "
748 "report to linux390@de.ibm.com",
755 dasd_schedule_bh(device);
760 * Start the i/o. This start_IO can fail if the channel is really busy.
761 * In that case set up a timer to start the request later.
764 dasd_start_IO(struct dasd_ccw_req * cqr)
766 struct dasd_device *device;
770 rc = dasd_check_cqr(cqr);
773 device = (struct dasd_device *) cqr->device;
774 if (cqr->retries < 0) {
775 DEV_MESSAGE(KERN_DEBUG, device,
776 "start_IO: request %p (%02x/%i) - no retry left.",
777 cqr, cqr->status, cqr->retries);
778 cqr->status = DASD_CQR_FAILED;
781 cqr->startclk = get_clock();
782 cqr->starttime = jiffies;
784 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
788 cqr->status = DASD_CQR_IN_IO;
789 DBF_DEV_EVENT(DBF_DEBUG, device,
790 "start_IO: request %p started successful",
794 DBF_DEV_EVENT(DBF_ERR, device, "%s",
795 "start_IO: device busy, retry later");
798 DBF_DEV_EVENT(DBF_ERR, device, "%s",
799 "start_IO: request timeout, retry later");
802 /* -EACCES indicates that the request used only a
803 * subset of the available pathes and all these
805 * Do a retry with all available pathes.
807 cqr->lpm = LPM_ANYPATH;
808 DBF_DEV_EVENT(DBF_ERR, device, "%s",
809 "start_IO: selected pathes gone,"
810 " retry on all pathes");
814 DBF_DEV_EVENT(DBF_ERR, device, "%s",
815 "start_IO: device gone, retry");
818 DEV_MESSAGE(KERN_ERR, device,
819 "line %d unknown RC=%d, please report"
820 " to linux390@de.ibm.com", __LINE__, rc);
828 * Timeout function for dasd devices. This is used for different purposes
829 * 1) missing interrupt handler for normal operation
830 * 2) delayed start of request where start_IO failed with -EBUSY
831 * 3) timeout for missing state change interrupts
832 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
833 * DASD_CQR_QUEUED for 2) and 3).
836 dasd_timeout_device(unsigned long ptr)
839 struct dasd_device *device;
841 device = (struct dasd_device *) ptr;
842 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
843 /* re-activate request queue */
844 device->stopped &= ~DASD_STOPPED_PENDING;
845 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
846 dasd_schedule_bh(device);
850 * Setup timeout for a device in jiffies.
853 dasd_set_timer(struct dasd_device *device, int expires)
856 if (timer_pending(&device->timer))
857 del_timer(&device->timer);
860 if (timer_pending(&device->timer)) {
861 if (mod_timer(&device->timer, jiffies + expires))
864 device->timer.function = dasd_timeout_device;
865 device->timer.data = (unsigned long) device;
866 device->timer.expires = jiffies + expires;
867 add_timer(&device->timer);
871 * Clear timeout for a device.
874 dasd_clear_timer(struct dasd_device *device)
876 if (timer_pending(&device->timer))
877 del_timer(&device->timer);
881 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
883 struct dasd_ccw_req *cqr;
884 struct dasd_device *device;
886 cqr = (struct dasd_ccw_req *) intparm;
887 if (cqr->status != DASD_CQR_IN_IO) {
889 "invalid status in handle_killed_request: "
890 "bus_id %s, status %02x",
891 cdev->dev.bus_id, cqr->status);
895 device = (struct dasd_device *) cqr->device;
896 if (device == NULL ||
897 device != dasd_device_from_cdev_locked(cdev) ||
898 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
899 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
904 /* Schedule request to be retried. */
905 cqr->status = DASD_CQR_QUEUED;
907 dasd_clear_timer(device);
908 dasd_schedule_bh(device);
909 dasd_put_device(device);
913 dasd_handle_state_change_pending(struct dasd_device *device)
915 struct dasd_ccw_req *cqr;
916 struct list_head *l, *n;
918 /* First of all start sense subsystem status request. */
919 dasd_eer_snss(device);
921 device->stopped &= ~DASD_STOPPED_PENDING;
923 /* restart all 'running' IO on queue */
924 list_for_each_safe(l, n, &device->ccw_queue) {
925 cqr = list_entry(l, struct dasd_ccw_req, list);
926 if (cqr->status == DASD_CQR_IN_IO) {
927 cqr->status = DASD_CQR_QUEUED;
930 dasd_clear_timer(device);
931 dasd_schedule_bh(device);
935 * Interrupt handler for "normal" ssch-io based dasd devices.
938 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
941 struct dasd_ccw_req *cqr, *next;
942 struct dasd_device *device;
943 unsigned long long now;
949 switch (PTR_ERR(irb)) {
951 dasd_handle_killed_request(cdev, intparm);
954 printk(KERN_WARNING"%s(%s): request timed out\n",
955 __FUNCTION__, cdev->dev.bus_id);
956 //FIXME - dasd uses own timeout interface...
959 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
960 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
967 DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
968 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
969 (unsigned int) intparm);
971 /* first of all check for state change pending interrupt */
972 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
973 if ((irb->scsw.dstat & mask) == mask) {
974 device = dasd_device_from_cdev_locked(cdev);
975 if (!IS_ERR(device)) {
976 dasd_handle_state_change_pending(device);
977 dasd_put_device(device);
982 cqr = (struct dasd_ccw_req *) intparm;
984 /* check for unsolicited interrupts */
987 "unsolicited interrupt received: bus_id %s",
992 device = (struct dasd_device *) cqr->device;
993 if (device == NULL ||
994 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
995 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
1000 /* Check for clear pending */
1001 if (cqr->status == DASD_CQR_CLEAR &&
1002 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
1003 cqr->status = DASD_CQR_QUEUED;
1004 dasd_clear_timer(device);
1005 wake_up(&dasd_flush_wq);
1006 dasd_schedule_bh(device);
1010 /* check status - the request might have been killed by dyn detach */
1011 if (cqr->status != DASD_CQR_IN_IO) {
1013 "invalid status: bus_id %s, status %02x",
1014 cdev->dev.bus_id, cqr->status);
1017 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
1018 ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
1020 /* Find out the appropriate era_action. */
1021 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
1022 era = dasd_era_fatal;
1023 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1024 irb->scsw.cstat == 0 &&
1025 !irb->esw.esw0.erw.cons)
1026 era = dasd_era_none;
1027 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
1028 era = dasd_era_fatal; /* don't recover this request */
1029 else if (irb->esw.esw0.erw.cons)
1030 era = device->discipline->examine_error(cqr, irb);
1032 era = dasd_era_recover;
1034 DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
1036 if (era == dasd_era_none) {
1037 cqr->status = DASD_CQR_DONE;
1039 /* Start first request on queue if possible -> fast_io. */
1040 if (cqr->list.next != &device->ccw_queue) {
1041 next = list_entry(cqr->list.next,
1042 struct dasd_ccw_req, list);
1043 if ((next->status == DASD_CQR_QUEUED) &&
1044 (!device->stopped)) {
1045 if (device->discipline->start_IO(next) == 0)
1046 expires = next->expires;
1048 DEV_MESSAGE(KERN_DEBUG, device, "%s",
1049 "Interrupt fastpath "
1053 } else { /* error */
1054 memcpy(&cqr->irb, irb, sizeof (struct irb));
1056 /* dump sense data */
1057 dasd_log_sense(cqr, irb);
1060 case dasd_era_fatal:
1061 cqr->status = DASD_CQR_FAILED;
1064 case dasd_era_recover:
1065 cqr->status = DASD_CQR_ERROR;
1072 dasd_set_timer(device, expires);
1074 dasd_clear_timer(device);
1075 dasd_schedule_bh(device);
1079 * posts the buffer_cache about a finalized request
1082 dasd_end_request(struct request *req, int uptodate)
1084 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1086 add_disk_randomness(req->rq_disk);
1087 end_that_request_last(req, uptodate);
1091 * Process finished error recovery ccw.
1094 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1096 dasd_erp_fn_t erp_fn;
1098 if (cqr->status == DASD_CQR_DONE)
1099 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1101 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1102 erp_fn = device->discipline->erp_postaction(cqr);
1107 * Process ccw request queue.
1110 __dasd_process_ccw_queue(struct dasd_device * device,
1111 struct list_head *final_queue)
1113 struct list_head *l, *n;
1114 struct dasd_ccw_req *cqr;
1115 dasd_erp_fn_t erp_fn;
1118 /* Process request with final status. */
1119 list_for_each_safe(l, n, &device->ccw_queue) {
1120 cqr = list_entry(l, struct dasd_ccw_req, list);
1121 /* Stop list processing at the first non-final request. */
1122 if (cqr->status != DASD_CQR_DONE &&
1123 cqr->status != DASD_CQR_FAILED &&
1124 cqr->status != DASD_CQR_ERROR)
1126 /* Process requests with DASD_CQR_ERROR */
1127 if (cqr->status == DASD_CQR_ERROR) {
1128 if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1129 cqr->status = DASD_CQR_FAILED;
1130 cqr->stopclk = get_clock();
1132 if (cqr->irb.esw.esw0.erw.cons) {
1133 erp_fn = device->discipline->
1137 dasd_default_erp_action(cqr);
1142 /* First of all call extended error reporting. */
1143 if (dasd_eer_enabled(device) &&
1144 cqr->status == DASD_CQR_FAILED) {
1145 dasd_eer_write(device, cqr, DASD_EER_FATALERROR);
1147 /* restart request */
1148 cqr->status = DASD_CQR_QUEUED;
1150 device->stopped |= DASD_STOPPED_QUIESCE;
1154 /* Process finished ERP request. */
1156 __dasd_process_erp(device, cqr);
1160 /* Rechain finished requests to final queue */
1161 cqr->endclk = get_clock();
1162 list_move_tail(&cqr->list, final_queue);
1167 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1169 struct request *req;
1170 struct dasd_device *device;
1173 req = (struct request *) data;
1174 device = cqr->device;
1175 dasd_profile_end(device, cqr, req);
1176 status = cqr->device->discipline->free_cp(cqr,req);
1177 spin_lock_irq(&device->request_queue_lock);
1178 dasd_end_request(req, status);
1179 spin_unlock_irq(&device->request_queue_lock);
1184 * Fetch requests from the block device queue.
1187 __dasd_process_blk_queue(struct dasd_device * device)
1189 request_queue_t *queue;
1190 struct request *req;
1191 struct dasd_ccw_req *cqr;
1194 queue = device->request_queue;
1195 /* No queue ? Then there is nothing to do. */
1200 * We requeue request from the block device queue to the ccw
1201 * queue only in two states. In state DASD_STATE_READY the
1202 * partition detection is done and we need to requeue requests
1203 * for that. State DASD_STATE_ONLINE is normal block device
1206 if (device->state != DASD_STATE_READY &&
1207 device->state != DASD_STATE_ONLINE)
1210 /* Now we try to fetch requests from the request queue */
1211 list_for_each_entry(cqr, &device->ccw_queue, list)
1212 if (cqr->status == DASD_CQR_QUEUED)
1214 while (!blk_queue_plugged(queue) &&
1215 elv_next_request(queue) &&
1216 nr_queued < DASD_CHANQ_MAX_SIZE) {
1217 req = elv_next_request(queue);
1219 if (device->features & DASD_FEATURE_READONLY &&
1220 rq_data_dir(req) == WRITE) {
1221 DBF_DEV_EVENT(DBF_ERR, device,
1222 "Rejecting write request %p",
1224 blkdev_dequeue_request(req);
1225 dasd_end_request(req, 0);
1228 if (device->stopped & DASD_STOPPED_DC_EIO) {
1229 blkdev_dequeue_request(req);
1230 dasd_end_request(req, 0);
1233 cqr = device->discipline->build_cp(device, req);
1235 if (PTR_ERR(cqr) == -ENOMEM)
1236 break; /* terminate request queue loop */
1237 DBF_DEV_EVENT(DBF_ERR, device,
1238 "CCW creation failed (rc=%ld) "
1241 blkdev_dequeue_request(req);
1242 dasd_end_request(req, 0);
1245 cqr->callback = dasd_end_request_cb;
1246 cqr->callback_data = (void *) req;
1247 cqr->status = DASD_CQR_QUEUED;
1248 blkdev_dequeue_request(req);
1249 list_add_tail(&cqr->list, &device->ccw_queue);
1250 dasd_profile_start(device, cqr, req);
1256 * Take a look at the first request on the ccw queue and check
1257 * if it reached its expire time. If so, terminate the IO.
1260 __dasd_check_expire(struct dasd_device * device)
1262 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 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1268 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1269 DEV_MESSAGE(KERN_ERR, device,
1270 "internal error - timeout (%is) expired "
1271 "for cqr %p (%i retries left)",
1272 (cqr->expires/HZ), cqr, cqr->retries);
1273 if (device->discipline->term_IO(cqr) != 0)
1274 /* Hmpf, try again in 1/10 sec */
1275 dasd_set_timer(device, 10);
1281 * Take a look at the first request on the ccw queue and check
1282 * if it needs to be started.
1285 __dasd_start_head(struct dasd_device * device)
1287 struct dasd_ccw_req *cqr;
1290 if (list_empty(&device->ccw_queue))
1292 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1293 if (cqr->status != DASD_CQR_QUEUED)
1295 /* Non-temporary stop condition will trigger fail fast */
1296 if (device->stopped & ~DASD_STOPPED_PENDING &&
1297 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1298 (!dasd_eer_enabled(device))) {
1299 cqr->status = DASD_CQR_FAILED;
1300 dasd_schedule_bh(device);
1303 /* Don't try to start requests if device is stopped */
1304 if (device->stopped)
1307 rc = device->discipline->start_IO(cqr);
1309 dasd_set_timer(device, cqr->expires);
1310 else if (rc == -EACCES) {
1311 dasd_schedule_bh(device);
1313 /* Hmpf, try again in 1/2 sec */
1314 dasd_set_timer(device, 50);
1318 _wait_for_clear(struct dasd_ccw_req *cqr)
1320 return (cqr->status == DASD_CQR_QUEUED);
1324 * Remove all requests from the ccw queue (all = '1') or only block device
1325 * requests in case all = '0'.
1326 * Take care of the erp-chain (chained via cqr->refers) and remove either
1327 * the whole erp-chain or none of the erp-requests.
1328 * If a request is currently running, term_IO is called and the request
1329 * is re-queued. Prior to removing the terminated request we need to wait
1330 * for the clear-interrupt.
1331 * In case termination is not possible we stop processing and just finishing
1332 * the already moved requests.
1335 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1337 struct dasd_ccw_req *cqr, *orig, *n;
1340 struct list_head flush_queue;
1342 INIT_LIST_HEAD(&flush_queue);
1343 spin_lock_irq(get_ccwdev_lock(device->cdev));
1346 list_for_each_entry_safe(cqr, n, &device->ccw_queue, list) {
1347 /* get original request of erp request-chain */
1348 for (orig = cqr; orig->refers != NULL; orig = orig->refers);
1350 /* Flush all request or only block device requests? */
1351 if (all == 0 && cqr->callback != dasd_end_request_cb &&
1352 orig->callback != dasd_end_request_cb) {
1355 /* Check status and move request to flush_queue */
1356 switch (cqr->status) {
1357 case DASD_CQR_IN_IO:
1358 rc = device->discipline->term_IO(cqr);
1360 /* unable to terminate requeust */
1361 DEV_MESSAGE(KERN_ERR, device,
1362 "dasd flush ccw_queue is unable "
1363 " to terminate request %p",
1365 /* stop flush processing */
1369 case DASD_CQR_QUEUED:
1370 case DASD_CQR_ERROR:
1371 /* set request to FAILED */
1372 cqr->stopclk = get_clock();
1373 cqr->status = DASD_CQR_FAILED;
1375 default: /* do not touch the others */
1378 /* Rechain request (including erp chain) */
1379 for (i = 0; cqr != NULL; cqr = cqr->refers, i++) {
1380 cqr->endclk = get_clock();
1381 list_move_tail(&cqr->list, &flush_queue);
1384 /* moved more than one request - need to restart */
1389 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1390 /* Now call the callback function of flushed requests */
1392 list_for_each_entry_safe(cqr, n, &flush_queue, list) {
1393 if (cqr->status == DASD_CQR_CLEAR) {
1394 /* wait for clear interrupt! */
1395 wait_event(dasd_flush_wq, _wait_for_clear(cqr));
1396 cqr->status = DASD_CQR_FAILED;
1398 /* Process finished ERP request. */
1400 __dasd_process_erp(device, cqr);
1401 /* restart list_for_xx loop since dasd_process_erp
1402 * might remove multiple elements */
1405 /* call the callback function */
1406 cqr->endclk = get_clock();
1407 if (cqr->callback != NULL)
1408 (cqr->callback)(cqr, cqr->callback_data);
1414 * Acquire the device lock and process queues for the device.
1417 dasd_tasklet(struct dasd_device * device)
1419 struct list_head final_queue;
1420 struct list_head *l, *n;
1421 struct dasd_ccw_req *cqr;
1423 atomic_set (&device->tasklet_scheduled, 0);
1424 INIT_LIST_HEAD(&final_queue);
1425 spin_lock_irq(get_ccwdev_lock(device->cdev));
1426 /* Check expire time of first request on the ccw queue. */
1427 __dasd_check_expire(device);
1428 /* Finish off requests on ccw queue */
1429 __dasd_process_ccw_queue(device, &final_queue);
1430 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1431 /* Now call the callback function of requests with final status */
1432 list_for_each_safe(l, n, &final_queue) {
1433 cqr = list_entry(l, struct dasd_ccw_req, list);
1434 list_del_init(&cqr->list);
1435 if (cqr->callback != NULL)
1436 (cqr->callback)(cqr, cqr->callback_data);
1438 spin_lock_irq(&device->request_queue_lock);
1439 spin_lock(get_ccwdev_lock(device->cdev));
1440 /* Get new request from the block device request queue */
1441 __dasd_process_blk_queue(device);
1442 /* Now check if the head of the ccw queue needs to be started. */
1443 __dasd_start_head(device);
1444 spin_unlock(get_ccwdev_lock(device->cdev));
1445 spin_unlock_irq(&device->request_queue_lock);
1446 dasd_put_device(device);
1450 * Schedules a call to dasd_tasklet over the device tasklet.
1453 dasd_schedule_bh(struct dasd_device * device)
1455 /* Protect against rescheduling. */
1456 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
1458 dasd_get_device(device);
1459 tasklet_hi_schedule(&device->tasklet);
1463 * Queue a request to the head of the ccw_queue. Start the I/O if
1467 dasd_add_request_head(struct dasd_ccw_req *req)
1469 struct dasd_device *device;
1470 unsigned long flags;
1472 device = req->device;
1473 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1474 req->status = DASD_CQR_QUEUED;
1475 req->device = device;
1476 list_add(&req->list, &device->ccw_queue);
1477 /* let the bh start the request to keep them in order */
1478 dasd_schedule_bh(device);
1479 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1483 * Queue a request to the tail of the ccw_queue. Start the I/O if
1487 dasd_add_request_tail(struct dasd_ccw_req *req)
1489 struct dasd_device *device;
1490 unsigned long flags;
1492 device = req->device;
1493 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1494 req->status = DASD_CQR_QUEUED;
1495 req->device = device;
1496 list_add_tail(&req->list, &device->ccw_queue);
1497 /* let the bh start the request to keep them in order */
1498 dasd_schedule_bh(device);
1499 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1506 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1508 wake_up((wait_queue_head_t *) data);
1512 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1514 struct dasd_device *device;
1517 device = cqr->device;
1518 spin_lock_irq(get_ccwdev_lock(device->cdev));
1519 rc = ((cqr->status == DASD_CQR_DONE ||
1520 cqr->status == DASD_CQR_FAILED) &&
1521 list_empty(&cqr->list));
1522 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1527 * Attempts to start a special ccw queue and waits for its completion.
1530 dasd_sleep_on(struct dasd_ccw_req * cqr)
1532 wait_queue_head_t wait_q;
1533 struct dasd_device *device;
1536 device = cqr->device;
1537 spin_lock_irq(get_ccwdev_lock(device->cdev));
1539 init_waitqueue_head (&wait_q);
1540 cqr->callback = dasd_wakeup_cb;
1541 cqr->callback_data = (void *) &wait_q;
1542 cqr->status = DASD_CQR_QUEUED;
1543 list_add_tail(&cqr->list, &device->ccw_queue);
1545 /* let the bh start the request to keep them in order */
1546 dasd_schedule_bh(device);
1548 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1550 wait_event(wait_q, _wait_for_wakeup(cqr));
1552 /* Request status is either done or failed. */
1553 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1558 * Attempts to start a special ccw queue and wait interruptible
1559 * for its completion.
1562 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1564 wait_queue_head_t wait_q;
1565 struct dasd_device *device;
1568 device = cqr->device;
1569 spin_lock_irq(get_ccwdev_lock(device->cdev));
1571 init_waitqueue_head (&wait_q);
1572 cqr->callback = dasd_wakeup_cb;
1573 cqr->callback_data = (void *) &wait_q;
1574 cqr->status = DASD_CQR_QUEUED;
1575 list_add_tail(&cqr->list, &device->ccw_queue);
1577 /* let the bh start the request to keep them in order */
1578 dasd_schedule_bh(device);
1579 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1583 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1584 if (rc != -ERESTARTSYS) {
1585 /* Request is final (done or failed) */
1586 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1589 spin_lock_irq(get_ccwdev_lock(device->cdev));
1590 switch (cqr->status) {
1591 case DASD_CQR_IN_IO:
1592 /* terminate runnig cqr */
1593 if (device->discipline->term_IO) {
1595 device->discipline->term_IO(cqr);
1596 /* wait (non-interruptible) for final status
1597 * because signal ist still pending */
1598 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1599 wait_event(wait_q, _wait_for_wakeup(cqr));
1600 spin_lock_irq(get_ccwdev_lock(device->cdev));
1601 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1605 case DASD_CQR_QUEUED:
1607 list_del_init(&cqr->list);
1612 /* cqr with 'non-interruptable' status - just wait */
1615 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1621 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1622 * for eckd devices) the currently running request has to be terminated
1623 * and be put back to status queued, before the special request is added
1624 * to the head of the queue. Then the special request is waited on normally.
1627 _dasd_term_running_cqr(struct dasd_device *device)
1629 struct dasd_ccw_req *cqr;
1631 if (list_empty(&device->ccw_queue))
1633 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1634 return device->discipline->term_IO(cqr);
1638 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1640 wait_queue_head_t wait_q;
1641 struct dasd_device *device;
1644 device = cqr->device;
1645 spin_lock_irq(get_ccwdev_lock(device->cdev));
1646 rc = _dasd_term_running_cqr(device);
1648 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1652 init_waitqueue_head (&wait_q);
1653 cqr->callback = dasd_wakeup_cb;
1654 cqr->callback_data = (void *) &wait_q;
1655 cqr->status = DASD_CQR_QUEUED;
1656 list_add(&cqr->list, &device->ccw_queue);
1658 /* let the bh start the request to keep them in order */
1659 dasd_schedule_bh(device);
1661 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1663 wait_event(wait_q, _wait_for_wakeup(cqr));
1665 /* Request status is either done or failed. */
1666 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1671 * Cancels a request that was started with dasd_sleep_on_req.
1672 * This is useful to timeout requests. The request will be
1673 * terminated if it is currently in i/o.
1674 * Returns 1 if the request has been terminated.
1677 dasd_cancel_req(struct dasd_ccw_req *cqr)
1679 struct dasd_device *device = cqr->device;
1680 unsigned long flags;
1684 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1685 switch (cqr->status) {
1686 case DASD_CQR_QUEUED:
1687 /* request was not started - just set to failed */
1688 cqr->status = DASD_CQR_FAILED;
1690 case DASD_CQR_IN_IO:
1691 /* request in IO - terminate IO and release again */
1692 if (device->discipline->term_IO(cqr) != 0)
1693 /* what to do if unable to terminate ??????
1695 cqr->status = DASD_CQR_FAILED;
1696 cqr->stopclk = get_clock();
1700 case DASD_CQR_FAILED:
1701 /* already finished - do nothing */
1704 DEV_MESSAGE(KERN_ALERT, device,
1705 "invalid status %02x in request",
1710 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1711 dasd_schedule_bh(device);
1716 * SECTION: Block device operations (request queue, partitions, open, release).
1720 * Dasd request queue function. Called from ll_rw_blk.c
1723 do_dasd_request(request_queue_t * queue)
1725 struct dasd_device *device;
1727 device = (struct dasd_device *) queue->queuedata;
1728 spin_lock(get_ccwdev_lock(device->cdev));
1729 /* Get new request from the block device request queue */
1730 __dasd_process_blk_queue(device);
1731 /* Now check if the head of the ccw queue needs to be started. */
1732 __dasd_start_head(device);
1733 spin_unlock(get_ccwdev_lock(device->cdev));
1737 * Allocate and initialize request queue and default I/O scheduler.
1740 dasd_alloc_queue(struct dasd_device * device)
1744 device->request_queue = blk_init_queue(do_dasd_request,
1745 &device->request_queue_lock);
1746 if (device->request_queue == NULL)
1749 device->request_queue->queuedata = device;
1751 elevator_exit(device->request_queue->elevator);
1752 rc = elevator_init(device->request_queue, "deadline");
1754 blk_cleanup_queue(device->request_queue);
1761 * Allocate and initialize request queue.
1764 dasd_setup_queue(struct dasd_device * device)
1768 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1769 max = device->discipline->max_blocks << device->s2b_shift;
1770 blk_queue_max_sectors(device->request_queue, max);
1771 blk_queue_max_phys_segments(device->request_queue, -1L);
1772 blk_queue_max_hw_segments(device->request_queue, -1L);
1773 blk_queue_max_segment_size(device->request_queue, -1L);
1774 blk_queue_segment_boundary(device->request_queue, -1L);
1775 blk_queue_ordered(device->request_queue, QUEUE_ORDERED_TAG, NULL);
1779 * Deactivate and free request queue.
1782 dasd_free_queue(struct dasd_device * device)
1784 if (device->request_queue) {
1785 blk_cleanup_queue(device->request_queue);
1786 device->request_queue = NULL;
1791 * Flush request on the request queue.
1794 dasd_flush_request_queue(struct dasd_device * device)
1796 struct request *req;
1798 if (!device->request_queue)
1801 spin_lock_irq(&device->request_queue_lock);
1802 while ((req = elv_next_request(device->request_queue))) {
1803 blkdev_dequeue_request(req);
1804 dasd_end_request(req, 0);
1806 spin_unlock_irq(&device->request_queue_lock);
1810 dasd_open(struct inode *inp, struct file *filp)
1812 struct gendisk *disk = inp->i_bdev->bd_disk;
1813 struct dasd_device *device = disk->private_data;
1816 atomic_inc(&device->open_count);
1817 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1822 if (!try_module_get(device->discipline->owner)) {
1827 if (dasd_probeonly) {
1828 DEV_MESSAGE(KERN_INFO, device, "%s",
1829 "No access to device due to probeonly mode");
1834 if (device->state <= DASD_STATE_BASIC) {
1835 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1836 " Cannot open unrecognized device");
1844 module_put(device->discipline->owner);
1846 atomic_dec(&device->open_count);
1851 dasd_release(struct inode *inp, struct file *filp)
1853 struct gendisk *disk = inp->i_bdev->bd_disk;
1854 struct dasd_device *device = disk->private_data;
1856 atomic_dec(&device->open_count);
1857 module_put(device->discipline->owner);
1862 * Return disk geometry.
1865 dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1867 struct dasd_device *device;
1869 device = bdev->bd_disk->private_data;
1873 if (!device->discipline ||
1874 !device->discipline->fill_geometry)
1877 device->discipline->fill_geometry(device, geo);
1878 geo->start = get_start_sect(bdev) >> device->s2b_shift;
1882 struct block_device_operations
1883 dasd_device_operations = {
1884 .owner = THIS_MODULE,
1886 .release = dasd_release,
1887 .ioctl = dasd_ioctl,
1888 .compat_ioctl = dasd_compat_ioctl,
1889 .getgeo = dasd_getgeo,
1896 #ifdef CONFIG_PROC_FS
1900 if (dasd_page_cache != NULL) {
1901 kmem_cache_destroy(dasd_page_cache);
1902 dasd_page_cache = NULL;
1904 dasd_gendisk_exit();
1906 if (dasd_debug_area != NULL) {
1907 debug_unregister(dasd_debug_area);
1908 dasd_debug_area = NULL;
1913 * SECTION: common functions for ccw_driver use
1917 * Initial attempt at a probe function. this can be simplified once
1918 * the other detection code is gone.
1921 dasd_generic_probe (struct ccw_device *cdev,
1922 struct dasd_discipline *discipline)
1926 ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
1929 "dasd_generic_probe: could not set ccw-device options "
1930 "for %s\n", cdev->dev.bus_id);
1933 ret = dasd_add_sysfs_files(cdev);
1936 "dasd_generic_probe: could not add sysfs entries "
1937 "for %s\n", cdev->dev.bus_id);
1940 cdev->handler = &dasd_int_handler;
1943 * Automatically online either all dasd devices (dasd_autodetect)
1944 * or all devices specified with dasd= parameters during
1947 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
1948 (dasd_autodetect && dasd_busid_known(cdev->dev.bus_id) != 0))
1949 ret = ccw_device_set_online(cdev);
1952 "dasd_generic_probe: could not initially online "
1953 "ccw-device %s\n", cdev->dev.bus_id);
1958 * This will one day be called from a global not_oper handler.
1959 * It is also used by driver_unregister during module unload.
1962 dasd_generic_remove (struct ccw_device *cdev)
1964 struct dasd_device *device;
1966 cdev->handler = NULL;
1968 dasd_remove_sysfs_files(cdev);
1969 device = dasd_device_from_cdev(cdev);
1972 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1973 /* Already doing offline processing */
1974 dasd_put_device(device);
1978 * This device is removed unconditionally. Set offline
1979 * flag to prevent dasd_open from opening it while it is
1980 * no quite down yet.
1982 dasd_set_target_state(device, DASD_STATE_NEW);
1983 /* dasd_delete_device destroys the device reference. */
1984 dasd_delete_device(device);
1988 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
1989 * the device is detected for the first time and is supposed to be used
1990 * or the user has started activation through sysfs.
1993 dasd_generic_set_online (struct ccw_device *cdev,
1994 struct dasd_discipline *base_discipline)
1997 struct dasd_discipline *discipline;
1998 struct dasd_device *device;
2001 /* first online clears initial online feature flag */
2002 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
2003 device = dasd_create_device(cdev);
2005 return PTR_ERR(device);
2007 discipline = base_discipline;
2008 if (device->features & DASD_FEATURE_USEDIAG) {
2009 if (!dasd_diag_discipline_pointer) {
2010 printk (KERN_WARNING
2011 "dasd_generic couldn't online device %s "
2012 "- discipline DIAG not available\n",
2014 dasd_delete_device(device);
2017 discipline = dasd_diag_discipline_pointer;
2019 if (!try_module_get(base_discipline->owner)) {
2020 dasd_delete_device(device);
2023 if (!try_module_get(discipline->owner)) {
2024 module_put(base_discipline->owner);
2025 dasd_delete_device(device);
2028 device->base_discipline = base_discipline;
2029 device->discipline = discipline;
2031 rc = discipline->check_device(device);
2033 printk (KERN_WARNING
2034 "dasd_generic couldn't online device %s "
2035 "with discipline %s rc=%i\n",
2036 cdev->dev.bus_id, discipline->name, rc);
2037 module_put(discipline->owner);
2038 module_put(base_discipline->owner);
2039 dasd_delete_device(device);
2043 dasd_set_target_state(device, DASD_STATE_ONLINE);
2044 if (device->state <= DASD_STATE_KNOWN) {
2045 printk (KERN_WARNING
2046 "dasd_generic discipline not found for %s\n",
2049 dasd_set_target_state(device, DASD_STATE_NEW);
2050 dasd_delete_device(device);
2052 pr_debug("dasd_generic device %s found\n",
2055 /* FIXME: we have to wait for the root device but we don't want
2056 * to wait for each single device but for all at once. */
2057 wait_event(dasd_init_waitq, _wait_for_device(device));
2059 dasd_put_device(device);
2065 dasd_generic_set_offline (struct ccw_device *cdev)
2067 struct dasd_device *device;
2068 int max_count, open_count;
2070 device = dasd_device_from_cdev(cdev);
2072 return PTR_ERR(device);
2073 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2074 /* Already doing offline processing */
2075 dasd_put_device(device);
2079 * We must make sure that this device is currently not in use.
2080 * The open_count is increased for every opener, that includes
2081 * the blkdev_get in dasd_scan_partitions. We are only interested
2082 * in the other openers.
2084 max_count = device->bdev ? 0 : -1;
2085 open_count = (int) atomic_read(&device->open_count);
2086 if (open_count > max_count) {
2088 printk (KERN_WARNING "Can't offline dasd device with "
2089 "open count = %i.\n",
2092 printk (KERN_WARNING "%s",
2093 "Can't offline dasd device due to internal "
2095 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
2096 dasd_put_device(device);
2099 dasd_set_target_state(device, DASD_STATE_NEW);
2100 /* dasd_delete_device destroys the device reference. */
2101 dasd_delete_device(device);
2107 dasd_generic_notify(struct ccw_device *cdev, int event)
2109 struct dasd_device *device;
2110 struct dasd_ccw_req *cqr;
2111 unsigned long flags;
2114 device = dasd_device_from_cdev(cdev);
2117 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
2122 /* First of all call extended error reporting. */
2123 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
2125 if (device->state < DASD_STATE_BASIC)
2127 /* Device is active. We want to keep it. */
2128 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
2129 list_for_each_entry(cqr, &device->ccw_queue, list)
2130 if (cqr->status == DASD_CQR_IN_IO)
2131 cqr->status = DASD_CQR_FAILED;
2132 device->stopped |= DASD_STOPPED_DC_EIO;
2134 list_for_each_entry(cqr, &device->ccw_queue, list)
2135 if (cqr->status == DASD_CQR_IN_IO) {
2136 cqr->status = DASD_CQR_QUEUED;
2139 device->stopped |= DASD_STOPPED_DC_WAIT;
2140 dasd_set_timer(device, 0);
2142 dasd_schedule_bh(device);
2146 /* FIXME: add a sanity check. */
2147 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
2148 dasd_schedule_bh(device);
2152 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2153 dasd_put_device(device);
2163 init_waitqueue_head(&dasd_init_waitq);
2164 init_waitqueue_head(&dasd_flush_wq);
2166 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2167 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long));
2168 if (dasd_debug_area == NULL) {
2172 debug_register_view(dasd_debug_area, &debug_sprintf_view);
2173 debug_set_level(dasd_debug_area, DBF_WARNING);
2175 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
2177 dasd_diag_discipline_pointer = NULL;
2179 rc = dasd_devmap_init();
2182 rc = dasd_gendisk_init();
2188 rc = dasd_eer_init();
2191 #ifdef CONFIG_PROC_FS
2192 rc = dasd_proc_init();
2199 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2204 module_init(dasd_init);
2205 module_exit(dasd_exit);
2207 EXPORT_SYMBOL(dasd_debug_area);
2208 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2210 EXPORT_SYMBOL(dasd_add_request_head);
2211 EXPORT_SYMBOL(dasd_add_request_tail);
2212 EXPORT_SYMBOL(dasd_cancel_req);
2213 EXPORT_SYMBOL(dasd_clear_timer);
2214 EXPORT_SYMBOL(dasd_enable_device);
2215 EXPORT_SYMBOL(dasd_int_handler);
2216 EXPORT_SYMBOL(dasd_kfree_request);
2217 EXPORT_SYMBOL(dasd_kick_device);
2218 EXPORT_SYMBOL(dasd_kmalloc_request);
2219 EXPORT_SYMBOL(dasd_schedule_bh);
2220 EXPORT_SYMBOL(dasd_set_target_state);
2221 EXPORT_SYMBOL(dasd_set_timer);
2222 EXPORT_SYMBOL(dasd_sfree_request);
2223 EXPORT_SYMBOL(dasd_sleep_on);
2224 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2225 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2226 EXPORT_SYMBOL(dasd_smalloc_request);
2227 EXPORT_SYMBOL(dasd_start_IO);
2228 EXPORT_SYMBOL(dasd_term_IO);
2230 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2231 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2232 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2233 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2234 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);