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(struct work_struct *);
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);
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(struct work_struct *work)
412 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
413 dasd_change_state(device);
414 dasd_schedule_bh(device);
415 dasd_put_device(device);
419 dasd_kick_device(struct dasd_device *device)
421 dasd_get_device(device);
422 /* queue call to dasd_kick_device to the kernel event daemon. */
423 schedule_work(&device->kick_work);
427 * Set the target state for a device and starts the state change.
430 dasd_set_target_state(struct dasd_device *device, int target)
432 /* If we are in probeonly mode stop at DASD_STATE_READY. */
433 if (dasd_probeonly && target > DASD_STATE_READY)
434 target = DASD_STATE_READY;
435 if (device->target != target) {
436 if (device->state == target)
437 wake_up(&dasd_init_waitq);
438 device->target = target;
440 if (device->state != device->target)
441 dasd_change_state(device);
445 * Enable devices with device numbers in [from..to].
448 _wait_for_device(struct dasd_device *device)
450 return (device->state == device->target);
454 dasd_enable_device(struct dasd_device *device)
456 dasd_set_target_state(device, DASD_STATE_ONLINE);
457 if (device->state <= DASD_STATE_KNOWN)
458 /* No discipline for device found. */
459 dasd_set_target_state(device, DASD_STATE_NEW);
460 /* Now wait for the devices to come up. */
461 wait_event(dasd_init_waitq, _wait_for_device(device));
465 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
467 #ifdef CONFIG_DASD_PROFILE
469 struct dasd_profile_info_t dasd_global_profile;
470 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
473 * Increments counter in global and local profiling structures.
475 #define dasd_profile_counter(value, counter, device) \
478 for (index = 0; index < 31 && value >> (2+index); index++); \
479 dasd_global_profile.counter[index]++; \
480 device->profile.counter[index]++; \
484 * Add profiling information for cqr before execution.
487 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
491 unsigned int counter;
493 if (dasd_profile_level != DASD_PROFILE_ON)
496 /* count the length of the chanq for statistics */
498 list_for_each(l, &device->ccw_queue)
501 dasd_global_profile.dasd_io_nr_req[counter]++;
502 device->profile.dasd_io_nr_req[counter]++;
506 * Add profiling information for cqr after execution.
509 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
512 long strtime, irqtime, endtime, tottime; /* in microseconds */
513 long tottimeps, sectors;
515 if (dasd_profile_level != DASD_PROFILE_ON)
518 sectors = req->nr_sectors;
519 if (!cqr->buildclk || !cqr->startclk ||
520 !cqr->stopclk || !cqr->endclk ||
524 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
525 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
526 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
527 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
528 tottimeps = tottime / sectors;
530 if (!dasd_global_profile.dasd_io_reqs)
531 memset(&dasd_global_profile, 0,
532 sizeof (struct dasd_profile_info_t));
533 dasd_global_profile.dasd_io_reqs++;
534 dasd_global_profile.dasd_io_sects += sectors;
536 if (!device->profile.dasd_io_reqs)
537 memset(&device->profile, 0,
538 sizeof (struct dasd_profile_info_t));
539 device->profile.dasd_io_reqs++;
540 device->profile.dasd_io_sects += sectors;
542 dasd_profile_counter(sectors, dasd_io_secs, device);
543 dasd_profile_counter(tottime, dasd_io_times, device);
544 dasd_profile_counter(tottimeps, dasd_io_timps, device);
545 dasd_profile_counter(strtime, dasd_io_time1, device);
546 dasd_profile_counter(irqtime, dasd_io_time2, device);
547 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
548 dasd_profile_counter(endtime, dasd_io_time3, device);
551 #define dasd_profile_start(device, cqr, req) do {} while (0)
552 #define dasd_profile_end(device, cqr, req) do {} while (0)
553 #endif /* CONFIG_DASD_PROFILE */
556 * Allocate memory for a channel program with 'cplength' channel
557 * command words and 'datasize' additional space. There are two
558 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
559 * memory and 2) dasd_smalloc_request uses the static ccw memory
560 * that gets allocated for each device.
562 struct dasd_ccw_req *
563 dasd_kmalloc_request(char *magic, int cplength, int datasize,
564 struct dasd_device * device)
566 struct dasd_ccw_req *cqr;
569 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
570 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
572 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
574 return ERR_PTR(-ENOMEM);
577 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
578 GFP_ATOMIC | GFP_DMA);
579 if (cqr->cpaddr == NULL) {
581 return ERR_PTR(-ENOMEM);
586 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
587 if (cqr->data == NULL) {
590 return ERR_PTR(-ENOMEM);
593 strncpy((char *) &cqr->magic, magic, 4);
594 ASCEBC((char *) &cqr->magic, 4);
595 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
596 dasd_get_device(device);
600 struct dasd_ccw_req *
601 dasd_smalloc_request(char *magic, int cplength, int datasize,
602 struct dasd_device * device)
605 struct dasd_ccw_req *cqr;
610 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
611 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
613 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
615 size += cplength * sizeof(struct ccw1);
618 spin_lock_irqsave(&device->mem_lock, flags);
619 cqr = (struct dasd_ccw_req *)
620 dasd_alloc_chunk(&device->ccw_chunks, size);
621 spin_unlock_irqrestore(&device->mem_lock, flags);
623 return ERR_PTR(-ENOMEM);
624 memset(cqr, 0, sizeof(struct dasd_ccw_req));
625 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
628 cqr->cpaddr = (struct ccw1 *) data;
629 data += cplength*sizeof(struct ccw1);
630 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
635 memset(cqr->data, 0, datasize);
637 strncpy((char *) &cqr->magic, magic, 4);
638 ASCEBC((char *) &cqr->magic, 4);
639 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
640 dasd_get_device(device);
645 * Free memory of a channel program. This function needs to free all the
646 * idal lists that might have been created by dasd_set_cda and the
647 * struct dasd_ccw_req itself.
650 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
655 /* Clear any idals used for the request. */
658 clear_normalized_cda(ccw);
659 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
664 dasd_put_device(device);
668 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
672 spin_lock_irqsave(&device->mem_lock, flags);
673 dasd_free_chunk(&device->ccw_chunks, cqr);
674 spin_unlock_irqrestore(&device->mem_lock, flags);
675 dasd_put_device(device);
679 * Check discipline magic in cqr.
682 dasd_check_cqr(struct dasd_ccw_req *cqr)
684 struct dasd_device *device;
688 device = cqr->device;
689 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
690 DEV_MESSAGE(KERN_WARNING, device,
691 " dasd_ccw_req 0x%08x magic doesn't match"
692 " discipline 0x%08x",
694 *(unsigned int *) device->discipline->name);
701 * Terminate the current i/o and set the request to clear_pending.
702 * Timer keeps device runnig.
703 * ccw_device_clear can fail if the i/o subsystem
707 dasd_term_IO(struct dasd_ccw_req * cqr)
709 struct dasd_device *device;
713 rc = dasd_check_cqr(cqr);
717 device = (struct dasd_device *) cqr->device;
718 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
719 rc = ccw_device_clear(device->cdev, (long) cqr);
721 case 0: /* termination successful */
723 cqr->status = DASD_CQR_CLEAR;
724 cqr->stopclk = get_clock();
726 DBF_DEV_EVENT(DBF_DEBUG, device,
727 "terminate cqr %p successful",
731 DBF_DEV_EVENT(DBF_ERR, device, "%s",
732 "device gone, retry");
735 DBF_DEV_EVENT(DBF_ERR, device, "%s",
740 DBF_DEV_EVENT(DBF_ERR, device, "%s",
741 "device busy, retry later");
744 DEV_MESSAGE(KERN_ERR, device,
745 "line %d unknown RC=%d, please "
746 "report to linux390@de.ibm.com",
753 dasd_schedule_bh(device);
758 * Start the i/o. This start_IO can fail if the channel is really busy.
759 * In that case set up a timer to start the request later.
762 dasd_start_IO(struct dasd_ccw_req * cqr)
764 struct dasd_device *device;
768 rc = dasd_check_cqr(cqr);
771 device = (struct dasd_device *) cqr->device;
772 if (cqr->retries < 0) {
773 DEV_MESSAGE(KERN_DEBUG, device,
774 "start_IO: request %p (%02x/%i) - no retry left.",
775 cqr, cqr->status, cqr->retries);
776 cqr->status = DASD_CQR_FAILED;
779 cqr->startclk = get_clock();
780 cqr->starttime = jiffies;
782 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
786 cqr->status = DASD_CQR_IN_IO;
787 DBF_DEV_EVENT(DBF_DEBUG, device,
788 "start_IO: request %p started successful",
792 DBF_DEV_EVENT(DBF_ERR, device, "%s",
793 "start_IO: device busy, retry later");
796 DBF_DEV_EVENT(DBF_ERR, device, "%s",
797 "start_IO: request timeout, retry later");
800 /* -EACCES indicates that the request used only a
801 * subset of the available pathes and all these
803 * Do a retry with all available pathes.
805 cqr->lpm = LPM_ANYPATH;
806 DBF_DEV_EVENT(DBF_ERR, device, "%s",
807 "start_IO: selected pathes gone,"
808 " retry on all pathes");
812 DBF_DEV_EVENT(DBF_ERR, device, "%s",
813 "start_IO: device gone, retry");
816 DEV_MESSAGE(KERN_ERR, device,
817 "line %d unknown RC=%d, please report"
818 " to linux390@de.ibm.com", __LINE__, rc);
826 * Timeout function for dasd devices. This is used for different purposes
827 * 1) missing interrupt handler for normal operation
828 * 2) delayed start of request where start_IO failed with -EBUSY
829 * 3) timeout for missing state change interrupts
830 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
831 * DASD_CQR_QUEUED for 2) and 3).
834 dasd_timeout_device(unsigned long ptr)
837 struct dasd_device *device;
839 device = (struct dasd_device *) ptr;
840 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
841 /* re-activate request queue */
842 device->stopped &= ~DASD_STOPPED_PENDING;
843 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
844 dasd_schedule_bh(device);
848 * Setup timeout for a device in jiffies.
851 dasd_set_timer(struct dasd_device *device, int expires)
854 if (timer_pending(&device->timer))
855 del_timer(&device->timer);
858 if (timer_pending(&device->timer)) {
859 if (mod_timer(&device->timer, jiffies + expires))
862 device->timer.function = dasd_timeout_device;
863 device->timer.data = (unsigned long) device;
864 device->timer.expires = jiffies + expires;
865 add_timer(&device->timer);
869 * Clear timeout for a device.
872 dasd_clear_timer(struct dasd_device *device)
874 if (timer_pending(&device->timer))
875 del_timer(&device->timer);
879 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
881 struct dasd_ccw_req *cqr;
882 struct dasd_device *device;
884 cqr = (struct dasd_ccw_req *) intparm;
885 if (cqr->status != DASD_CQR_IN_IO) {
887 "invalid status in handle_killed_request: "
888 "bus_id %s, status %02x",
889 cdev->dev.bus_id, cqr->status);
893 device = (struct dasd_device *) cqr->device;
894 if (device == NULL ||
895 device != dasd_device_from_cdev_locked(cdev) ||
896 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
897 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
902 /* Schedule request to be retried. */
903 cqr->status = DASD_CQR_QUEUED;
905 dasd_clear_timer(device);
906 dasd_schedule_bh(device);
907 dasd_put_device(device);
911 dasd_handle_state_change_pending(struct dasd_device *device)
913 struct dasd_ccw_req *cqr;
914 struct list_head *l, *n;
916 /* First of all start sense subsystem status request. */
917 dasd_eer_snss(device);
919 device->stopped &= ~DASD_STOPPED_PENDING;
921 /* restart all 'running' IO on queue */
922 list_for_each_safe(l, n, &device->ccw_queue) {
923 cqr = list_entry(l, struct dasd_ccw_req, list);
924 if (cqr->status == DASD_CQR_IN_IO) {
925 cqr->status = DASD_CQR_QUEUED;
928 dasd_clear_timer(device);
929 dasd_schedule_bh(device);
933 * Interrupt handler for "normal" ssch-io based dasd devices.
936 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
939 struct dasd_ccw_req *cqr, *next;
940 struct dasd_device *device;
941 unsigned long long now;
947 switch (PTR_ERR(irb)) {
949 dasd_handle_killed_request(cdev, intparm);
952 printk(KERN_WARNING"%s(%s): request timed out\n",
953 __FUNCTION__, cdev->dev.bus_id);
954 //FIXME - dasd uses own timeout interface...
957 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
958 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
965 DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
966 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
967 (unsigned int) intparm);
969 /* first of all check for state change pending interrupt */
970 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
971 if ((irb->scsw.dstat & mask) == mask) {
972 device = dasd_device_from_cdev_locked(cdev);
973 if (!IS_ERR(device)) {
974 dasd_handle_state_change_pending(device);
975 dasd_put_device(device);
980 cqr = (struct dasd_ccw_req *) intparm;
982 /* check for unsolicited interrupts */
985 "unsolicited interrupt received: bus_id %s",
990 device = (struct dasd_device *) cqr->device;
991 if (device == NULL ||
992 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
993 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
998 /* Check for clear pending */
999 if (cqr->status == DASD_CQR_CLEAR &&
1000 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
1001 cqr->status = DASD_CQR_QUEUED;
1002 dasd_clear_timer(device);
1003 wake_up(&dasd_flush_wq);
1004 dasd_schedule_bh(device);
1008 /* check status - the request might have been killed by dyn detach */
1009 if (cqr->status != DASD_CQR_IN_IO) {
1011 "invalid status: bus_id %s, status %02x",
1012 cdev->dev.bus_id, cqr->status);
1015 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
1016 ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
1018 /* Find out the appropriate era_action. */
1019 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
1020 era = dasd_era_fatal;
1021 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1022 irb->scsw.cstat == 0 &&
1023 !irb->esw.esw0.erw.cons)
1024 era = dasd_era_none;
1025 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
1026 era = dasd_era_fatal; /* don't recover this request */
1027 else if (irb->esw.esw0.erw.cons)
1028 era = device->discipline->examine_error(cqr, irb);
1030 era = dasd_era_recover;
1032 DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
1034 if (era == dasd_era_none) {
1035 cqr->status = DASD_CQR_DONE;
1037 /* Start first request on queue if possible -> fast_io. */
1038 if (cqr->list.next != &device->ccw_queue) {
1039 next = list_entry(cqr->list.next,
1040 struct dasd_ccw_req, list);
1041 if ((next->status == DASD_CQR_QUEUED) &&
1042 (!device->stopped)) {
1043 if (device->discipline->start_IO(next) == 0)
1044 expires = next->expires;
1046 DEV_MESSAGE(KERN_DEBUG, device, "%s",
1047 "Interrupt fastpath "
1051 } else { /* error */
1052 memcpy(&cqr->irb, irb, sizeof (struct irb));
1053 if (device->features & DASD_FEATURE_ERPLOG) {
1054 /* dump sense data */
1055 dasd_log_sense(cqr, irb);
1058 case dasd_era_fatal:
1059 cqr->status = DASD_CQR_FAILED;
1062 case dasd_era_recover:
1063 cqr->status = DASD_CQR_ERROR;
1070 dasd_set_timer(device, expires);
1072 dasd_clear_timer(device);
1073 dasd_schedule_bh(device);
1077 * posts the buffer_cache about a finalized request
1080 dasd_end_request(struct request *req, int uptodate)
1082 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1084 add_disk_randomness(req->rq_disk);
1085 end_that_request_last(req, uptodate);
1089 * Process finished error recovery ccw.
1092 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1094 dasd_erp_fn_t erp_fn;
1096 if (cqr->status == DASD_CQR_DONE)
1097 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1099 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1100 erp_fn = device->discipline->erp_postaction(cqr);
1105 * Process ccw request queue.
1108 __dasd_process_ccw_queue(struct dasd_device * device,
1109 struct list_head *final_queue)
1111 struct list_head *l, *n;
1112 struct dasd_ccw_req *cqr;
1113 dasd_erp_fn_t erp_fn;
1116 /* Process request with final status. */
1117 list_for_each_safe(l, n, &device->ccw_queue) {
1118 cqr = list_entry(l, struct dasd_ccw_req, list);
1119 /* Stop list processing at the first non-final request. */
1120 if (cqr->status != DASD_CQR_DONE &&
1121 cqr->status != DASD_CQR_FAILED &&
1122 cqr->status != DASD_CQR_ERROR)
1124 /* Process requests with DASD_CQR_ERROR */
1125 if (cqr->status == DASD_CQR_ERROR) {
1126 if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1127 cqr->status = DASD_CQR_FAILED;
1128 cqr->stopclk = get_clock();
1130 if (cqr->irb.esw.esw0.erw.cons) {
1131 erp_fn = device->discipline->
1135 dasd_default_erp_action(cqr);
1140 /* First of all call extended error reporting. */
1141 if (dasd_eer_enabled(device) &&
1142 cqr->status == DASD_CQR_FAILED) {
1143 dasd_eer_write(device, cqr, DASD_EER_FATALERROR);
1145 /* restart request */
1146 cqr->status = DASD_CQR_QUEUED;
1148 device->stopped |= DASD_STOPPED_QUIESCE;
1152 /* Process finished ERP request. */
1154 __dasd_process_erp(device, cqr);
1158 /* Rechain finished requests to final queue */
1159 cqr->endclk = get_clock();
1160 list_move_tail(&cqr->list, final_queue);
1165 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1167 struct request *req;
1168 struct dasd_device *device;
1171 req = (struct request *) data;
1172 device = cqr->device;
1173 dasd_profile_end(device, cqr, req);
1174 status = cqr->device->discipline->free_cp(cqr,req);
1175 spin_lock_irq(&device->request_queue_lock);
1176 dasd_end_request(req, status);
1177 spin_unlock_irq(&device->request_queue_lock);
1182 * Fetch requests from the block device queue.
1185 __dasd_process_blk_queue(struct dasd_device * device)
1187 request_queue_t *queue;
1188 struct request *req;
1189 struct dasd_ccw_req *cqr;
1192 queue = device->request_queue;
1193 /* No queue ? Then there is nothing to do. */
1198 * We requeue request from the block device queue to the ccw
1199 * queue only in two states. In state DASD_STATE_READY the
1200 * partition detection is done and we need to requeue requests
1201 * for that. State DASD_STATE_ONLINE is normal block device
1204 if (device->state != DASD_STATE_READY &&
1205 device->state != DASD_STATE_ONLINE)
1208 /* Now we try to fetch requests from the request queue */
1209 list_for_each_entry(cqr, &device->ccw_queue, list)
1210 if (cqr->status == DASD_CQR_QUEUED)
1212 while (!blk_queue_plugged(queue) &&
1213 elv_next_request(queue) &&
1214 nr_queued < DASD_CHANQ_MAX_SIZE) {
1215 req = elv_next_request(queue);
1217 if (device->features & DASD_FEATURE_READONLY &&
1218 rq_data_dir(req) == WRITE) {
1219 DBF_DEV_EVENT(DBF_ERR, device,
1220 "Rejecting write request %p",
1222 blkdev_dequeue_request(req);
1223 dasd_end_request(req, 0);
1226 if (device->stopped & DASD_STOPPED_DC_EIO) {
1227 blkdev_dequeue_request(req);
1228 dasd_end_request(req, 0);
1231 cqr = device->discipline->build_cp(device, req);
1233 if (PTR_ERR(cqr) == -ENOMEM)
1234 break; /* terminate request queue loop */
1235 DBF_DEV_EVENT(DBF_ERR, device,
1236 "CCW creation failed (rc=%ld) "
1239 blkdev_dequeue_request(req);
1240 dasd_end_request(req, 0);
1243 cqr->callback = dasd_end_request_cb;
1244 cqr->callback_data = (void *) req;
1245 cqr->status = DASD_CQR_QUEUED;
1246 blkdev_dequeue_request(req);
1247 list_add_tail(&cqr->list, &device->ccw_queue);
1248 dasd_profile_start(device, cqr, req);
1254 * Take a look at the first request on the ccw queue and check
1255 * if it reached its expire time. If so, terminate the IO.
1258 __dasd_check_expire(struct dasd_device * device)
1260 struct dasd_ccw_req *cqr;
1262 if (list_empty(&device->ccw_queue))
1264 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1265 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1266 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1267 if (device->discipline->term_IO(cqr) != 0) {
1268 /* Hmpf, try again in 5 sec */
1269 dasd_set_timer(device, 5*HZ);
1270 DEV_MESSAGE(KERN_ERR, device,
1271 "internal error - timeout (%is) expired "
1272 "for cqr %p, termination failed, "
1274 (cqr->expires/HZ), cqr);
1276 DEV_MESSAGE(KERN_ERR, device,
1277 "internal error - timeout (%is) expired "
1278 "for cqr %p (%i retries left)",
1279 (cqr->expires/HZ), cqr, cqr->retries);
1285 * Take a look at the first request on the ccw queue and check
1286 * if it needs to be started.
1289 __dasd_start_head(struct dasd_device * device)
1291 struct dasd_ccw_req *cqr;
1294 if (list_empty(&device->ccw_queue))
1296 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1297 if (cqr->status != DASD_CQR_QUEUED)
1299 /* Non-temporary stop condition will trigger fail fast */
1300 if (device->stopped & ~DASD_STOPPED_PENDING &&
1301 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1302 (!dasd_eer_enabled(device))) {
1303 cqr->status = DASD_CQR_FAILED;
1304 dasd_schedule_bh(device);
1307 /* Don't try to start requests if device is stopped */
1308 if (device->stopped)
1311 rc = device->discipline->start_IO(cqr);
1313 dasd_set_timer(device, cqr->expires);
1314 else if (rc == -EACCES) {
1315 dasd_schedule_bh(device);
1317 /* Hmpf, try again in 1/2 sec */
1318 dasd_set_timer(device, 50);
1322 _wait_for_clear(struct dasd_ccw_req *cqr)
1324 return (cqr->status == DASD_CQR_QUEUED);
1328 * Remove all requests from the ccw queue (all = '1') or only block device
1329 * requests in case all = '0'.
1330 * Take care of the erp-chain (chained via cqr->refers) and remove either
1331 * the whole erp-chain or none of the erp-requests.
1332 * If a request is currently running, term_IO is called and the request
1333 * is re-queued. Prior to removing the terminated request we need to wait
1334 * for the clear-interrupt.
1335 * In case termination is not possible we stop processing and just finishing
1336 * the already moved requests.
1339 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1341 struct dasd_ccw_req *cqr, *orig, *n;
1344 struct list_head flush_queue;
1346 INIT_LIST_HEAD(&flush_queue);
1347 spin_lock_irq(get_ccwdev_lock(device->cdev));
1350 list_for_each_entry_safe(cqr, n, &device->ccw_queue, list) {
1351 /* get original request of erp request-chain */
1352 for (orig = cqr; orig->refers != NULL; orig = orig->refers);
1354 /* Flush all request or only block device requests? */
1355 if (all == 0 && cqr->callback != dasd_end_request_cb &&
1356 orig->callback != dasd_end_request_cb) {
1359 /* Check status and move request to flush_queue */
1360 switch (cqr->status) {
1361 case DASD_CQR_IN_IO:
1362 rc = device->discipline->term_IO(cqr);
1364 /* unable to terminate requeust */
1365 DEV_MESSAGE(KERN_ERR, device,
1366 "dasd flush ccw_queue is unable "
1367 " to terminate request %p",
1369 /* stop flush processing */
1373 case DASD_CQR_QUEUED:
1374 case DASD_CQR_ERROR:
1375 /* set request to FAILED */
1376 cqr->stopclk = get_clock();
1377 cqr->status = DASD_CQR_FAILED;
1379 default: /* do not touch the others */
1382 /* Rechain request (including erp chain) */
1383 for (i = 0; cqr != NULL; cqr = cqr->refers, i++) {
1384 cqr->endclk = get_clock();
1385 list_move_tail(&cqr->list, &flush_queue);
1388 /* moved more than one request - need to restart */
1393 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1394 /* Now call the callback function of flushed requests */
1396 list_for_each_entry_safe(cqr, n, &flush_queue, list) {
1397 if (cqr->status == DASD_CQR_CLEAR) {
1398 /* wait for clear interrupt! */
1399 wait_event(dasd_flush_wq, _wait_for_clear(cqr));
1400 cqr->status = DASD_CQR_FAILED;
1402 /* Process finished ERP request. */
1404 __dasd_process_erp(device, cqr);
1405 /* restart list_for_xx loop since dasd_process_erp
1406 * might remove multiple elements */
1409 /* call the callback function */
1410 cqr->endclk = get_clock();
1411 if (cqr->callback != NULL)
1412 (cqr->callback)(cqr, cqr->callback_data);
1418 * Acquire the device lock and process queues for the device.
1421 dasd_tasklet(struct dasd_device * device)
1423 struct list_head final_queue;
1424 struct list_head *l, *n;
1425 struct dasd_ccw_req *cqr;
1427 atomic_set (&device->tasklet_scheduled, 0);
1428 INIT_LIST_HEAD(&final_queue);
1429 spin_lock_irq(get_ccwdev_lock(device->cdev));
1430 /* Check expire time of first request on the ccw queue. */
1431 __dasd_check_expire(device);
1432 /* Finish off requests on ccw queue */
1433 __dasd_process_ccw_queue(device, &final_queue);
1434 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1435 /* Now call the callback function of requests with final status */
1436 list_for_each_safe(l, n, &final_queue) {
1437 cqr = list_entry(l, struct dasd_ccw_req, list);
1438 list_del_init(&cqr->list);
1439 if (cqr->callback != NULL)
1440 (cqr->callback)(cqr, cqr->callback_data);
1442 spin_lock_irq(&device->request_queue_lock);
1443 spin_lock(get_ccwdev_lock(device->cdev));
1444 /* Get new request from the block device request queue */
1445 __dasd_process_blk_queue(device);
1446 /* Now check if the head of the ccw queue needs to be started. */
1447 __dasd_start_head(device);
1448 spin_unlock(get_ccwdev_lock(device->cdev));
1449 spin_unlock_irq(&device->request_queue_lock);
1450 dasd_put_device(device);
1454 * Schedules a call to dasd_tasklet over the device tasklet.
1457 dasd_schedule_bh(struct dasd_device * device)
1459 /* Protect against rescheduling. */
1460 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
1462 dasd_get_device(device);
1463 tasklet_hi_schedule(&device->tasklet);
1467 * Queue a request to the head of the ccw_queue. Start the I/O if
1471 dasd_add_request_head(struct dasd_ccw_req *req)
1473 struct dasd_device *device;
1474 unsigned long flags;
1476 device = req->device;
1477 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1478 req->status = DASD_CQR_QUEUED;
1479 req->device = device;
1480 list_add(&req->list, &device->ccw_queue);
1481 /* let the bh start the request to keep them in order */
1482 dasd_schedule_bh(device);
1483 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1487 * Queue a request to the tail of the ccw_queue. Start the I/O if
1491 dasd_add_request_tail(struct dasd_ccw_req *req)
1493 struct dasd_device *device;
1494 unsigned long flags;
1496 device = req->device;
1497 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1498 req->status = DASD_CQR_QUEUED;
1499 req->device = device;
1500 list_add_tail(&req->list, &device->ccw_queue);
1501 /* let the bh start the request to keep them in order */
1502 dasd_schedule_bh(device);
1503 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1510 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1512 wake_up((wait_queue_head_t *) data);
1516 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1518 struct dasd_device *device;
1521 device = cqr->device;
1522 spin_lock_irq(get_ccwdev_lock(device->cdev));
1523 rc = ((cqr->status == DASD_CQR_DONE ||
1524 cqr->status == DASD_CQR_FAILED) &&
1525 list_empty(&cqr->list));
1526 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1531 * Attempts to start a special ccw queue and waits for its completion.
1534 dasd_sleep_on(struct dasd_ccw_req * cqr)
1536 wait_queue_head_t wait_q;
1537 struct dasd_device *device;
1540 device = cqr->device;
1541 spin_lock_irq(get_ccwdev_lock(device->cdev));
1543 init_waitqueue_head (&wait_q);
1544 cqr->callback = dasd_wakeup_cb;
1545 cqr->callback_data = (void *) &wait_q;
1546 cqr->status = DASD_CQR_QUEUED;
1547 list_add_tail(&cqr->list, &device->ccw_queue);
1549 /* let the bh start the request to keep them in order */
1550 dasd_schedule_bh(device);
1552 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1554 wait_event(wait_q, _wait_for_wakeup(cqr));
1556 /* Request status is either done or failed. */
1557 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1562 * Attempts to start a special ccw queue and wait interruptible
1563 * for its completion.
1566 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1568 wait_queue_head_t wait_q;
1569 struct dasd_device *device;
1572 device = cqr->device;
1573 spin_lock_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_tail(&cqr->list, &device->ccw_queue);
1581 /* let the bh start the request to keep them in order */
1582 dasd_schedule_bh(device);
1583 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1587 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1588 if (rc != -ERESTARTSYS) {
1589 /* Request is final (done or failed) */
1590 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1593 spin_lock_irq(get_ccwdev_lock(device->cdev));
1594 switch (cqr->status) {
1595 case DASD_CQR_IN_IO:
1596 /* terminate runnig cqr */
1597 if (device->discipline->term_IO) {
1599 device->discipline->term_IO(cqr);
1600 /* wait (non-interruptible) for final status
1601 * because signal ist still pending */
1602 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1603 wait_event(wait_q, _wait_for_wakeup(cqr));
1604 spin_lock_irq(get_ccwdev_lock(device->cdev));
1605 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1609 case DASD_CQR_QUEUED:
1611 list_del_init(&cqr->list);
1616 /* cqr with 'non-interruptable' status - just wait */
1619 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1625 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1626 * for eckd devices) the currently running request has to be terminated
1627 * and be put back to status queued, before the special request is added
1628 * to the head of the queue. Then the special request is waited on normally.
1631 _dasd_term_running_cqr(struct dasd_device *device)
1633 struct dasd_ccw_req *cqr;
1635 if (list_empty(&device->ccw_queue))
1637 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1638 return device->discipline->term_IO(cqr);
1642 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1644 wait_queue_head_t wait_q;
1645 struct dasd_device *device;
1648 device = cqr->device;
1649 spin_lock_irq(get_ccwdev_lock(device->cdev));
1650 rc = _dasd_term_running_cqr(device);
1652 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1656 init_waitqueue_head (&wait_q);
1657 cqr->callback = dasd_wakeup_cb;
1658 cqr->callback_data = (void *) &wait_q;
1659 cqr->status = DASD_CQR_QUEUED;
1660 list_add(&cqr->list, &device->ccw_queue);
1662 /* let the bh start the request to keep them in order */
1663 dasd_schedule_bh(device);
1665 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1667 wait_event(wait_q, _wait_for_wakeup(cqr));
1669 /* Request status is either done or failed. */
1670 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1675 * Cancels a request that was started with dasd_sleep_on_req.
1676 * This is useful to timeout requests. The request will be
1677 * terminated if it is currently in i/o.
1678 * Returns 1 if the request has been terminated.
1681 dasd_cancel_req(struct dasd_ccw_req *cqr)
1683 struct dasd_device *device = cqr->device;
1684 unsigned long flags;
1688 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1689 switch (cqr->status) {
1690 case DASD_CQR_QUEUED:
1691 /* request was not started - just set to failed */
1692 cqr->status = DASD_CQR_FAILED;
1694 case DASD_CQR_IN_IO:
1695 /* request in IO - terminate IO and release again */
1696 if (device->discipline->term_IO(cqr) != 0)
1697 /* what to do if unable to terminate ??????
1699 cqr->status = DASD_CQR_FAILED;
1700 cqr->stopclk = get_clock();
1704 case DASD_CQR_FAILED:
1705 /* already finished - do nothing */
1708 DEV_MESSAGE(KERN_ALERT, device,
1709 "invalid status %02x in request",
1714 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1715 dasd_schedule_bh(device);
1720 * SECTION: Block device operations (request queue, partitions, open, release).
1724 * Dasd request queue function. Called from ll_rw_blk.c
1727 do_dasd_request(request_queue_t * queue)
1729 struct dasd_device *device;
1731 device = (struct dasd_device *) queue->queuedata;
1732 spin_lock(get_ccwdev_lock(device->cdev));
1733 /* Get new request from the block device request queue */
1734 __dasd_process_blk_queue(device);
1735 /* Now check if the head of the ccw queue needs to be started. */
1736 __dasd_start_head(device);
1737 spin_unlock(get_ccwdev_lock(device->cdev));
1741 * Allocate and initialize request queue and default I/O scheduler.
1744 dasd_alloc_queue(struct dasd_device * device)
1748 device->request_queue = blk_init_queue(do_dasd_request,
1749 &device->request_queue_lock);
1750 if (device->request_queue == NULL)
1753 device->request_queue->queuedata = device;
1755 elevator_exit(device->request_queue->elevator);
1756 rc = elevator_init(device->request_queue, "deadline");
1758 blk_cleanup_queue(device->request_queue);
1765 * Allocate and initialize request queue.
1768 dasd_setup_queue(struct dasd_device * device)
1772 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1773 max = device->discipline->max_blocks << device->s2b_shift;
1774 blk_queue_max_sectors(device->request_queue, max);
1775 blk_queue_max_phys_segments(device->request_queue, -1L);
1776 blk_queue_max_hw_segments(device->request_queue, -1L);
1777 blk_queue_max_segment_size(device->request_queue, -1L);
1778 blk_queue_segment_boundary(device->request_queue, -1L);
1779 blk_queue_ordered(device->request_queue, QUEUE_ORDERED_TAG, NULL);
1783 * Deactivate and free request queue.
1786 dasd_free_queue(struct dasd_device * device)
1788 if (device->request_queue) {
1789 blk_cleanup_queue(device->request_queue);
1790 device->request_queue = NULL;
1795 * Flush request on the request queue.
1798 dasd_flush_request_queue(struct dasd_device * device)
1800 struct request *req;
1802 if (!device->request_queue)
1805 spin_lock_irq(&device->request_queue_lock);
1806 while ((req = elv_next_request(device->request_queue))) {
1807 blkdev_dequeue_request(req);
1808 dasd_end_request(req, 0);
1810 spin_unlock_irq(&device->request_queue_lock);
1814 dasd_open(struct inode *inp, struct file *filp)
1816 struct gendisk *disk = inp->i_bdev->bd_disk;
1817 struct dasd_device *device = disk->private_data;
1820 atomic_inc(&device->open_count);
1821 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1826 if (!try_module_get(device->discipline->owner)) {
1831 if (dasd_probeonly) {
1832 DEV_MESSAGE(KERN_INFO, device, "%s",
1833 "No access to device due to probeonly mode");
1838 if (device->state <= DASD_STATE_BASIC) {
1839 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1840 " Cannot open unrecognized device");
1848 module_put(device->discipline->owner);
1850 atomic_dec(&device->open_count);
1855 dasd_release(struct inode *inp, struct file *filp)
1857 struct gendisk *disk = inp->i_bdev->bd_disk;
1858 struct dasd_device *device = disk->private_data;
1860 atomic_dec(&device->open_count);
1861 module_put(device->discipline->owner);
1866 * Return disk geometry.
1869 dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1871 struct dasd_device *device;
1873 device = bdev->bd_disk->private_data;
1877 if (!device->discipline ||
1878 !device->discipline->fill_geometry)
1881 device->discipline->fill_geometry(device, geo);
1882 geo->start = get_start_sect(bdev) >> device->s2b_shift;
1886 struct block_device_operations
1887 dasd_device_operations = {
1888 .owner = THIS_MODULE,
1890 .release = dasd_release,
1891 .ioctl = dasd_ioctl,
1892 .compat_ioctl = dasd_compat_ioctl,
1893 .getgeo = dasd_getgeo,
1900 #ifdef CONFIG_PROC_FS
1904 if (dasd_page_cache != NULL) {
1905 kmem_cache_destroy(dasd_page_cache);
1906 dasd_page_cache = NULL;
1908 dasd_gendisk_exit();
1910 if (dasd_debug_area != NULL) {
1911 debug_unregister(dasd_debug_area);
1912 dasd_debug_area = NULL;
1917 * SECTION: common functions for ccw_driver use
1921 * Initial attempt at a probe function. this can be simplified once
1922 * the other detection code is gone.
1925 dasd_generic_probe (struct ccw_device *cdev,
1926 struct dasd_discipline *discipline)
1930 ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
1933 "dasd_generic_probe: could not set ccw-device options "
1934 "for %s\n", cdev->dev.bus_id);
1937 ret = dasd_add_sysfs_files(cdev);
1940 "dasd_generic_probe: could not add sysfs entries "
1941 "for %s\n", cdev->dev.bus_id);
1944 cdev->handler = &dasd_int_handler;
1947 * Automatically online either all dasd devices (dasd_autodetect)
1948 * or all devices specified with dasd= parameters during
1951 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
1952 (dasd_autodetect && dasd_busid_known(cdev->dev.bus_id) != 0))
1953 ret = ccw_device_set_online(cdev);
1956 "dasd_generic_probe: could not initially online "
1957 "ccw-device %s\n", cdev->dev.bus_id);
1962 * This will one day be called from a global not_oper handler.
1963 * It is also used by driver_unregister during module unload.
1966 dasd_generic_remove (struct ccw_device *cdev)
1968 struct dasd_device *device;
1970 cdev->handler = NULL;
1972 dasd_remove_sysfs_files(cdev);
1973 device = dasd_device_from_cdev(cdev);
1976 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1977 /* Already doing offline processing */
1978 dasd_put_device(device);
1982 * This device is removed unconditionally. Set offline
1983 * flag to prevent dasd_open from opening it while it is
1984 * no quite down yet.
1986 dasd_set_target_state(device, DASD_STATE_NEW);
1987 /* dasd_delete_device destroys the device reference. */
1988 dasd_delete_device(device);
1992 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
1993 * the device is detected for the first time and is supposed to be used
1994 * or the user has started activation through sysfs.
1997 dasd_generic_set_online (struct ccw_device *cdev,
1998 struct dasd_discipline *base_discipline)
2001 struct dasd_discipline *discipline;
2002 struct dasd_device *device;
2005 /* first online clears initial online feature flag */
2006 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
2007 device = dasd_create_device(cdev);
2009 return PTR_ERR(device);
2011 discipline = base_discipline;
2012 if (device->features & DASD_FEATURE_USEDIAG) {
2013 if (!dasd_diag_discipline_pointer) {
2014 printk (KERN_WARNING
2015 "dasd_generic couldn't online device %s "
2016 "- discipline DIAG not available\n",
2018 dasd_delete_device(device);
2021 discipline = dasd_diag_discipline_pointer;
2023 if (!try_module_get(base_discipline->owner)) {
2024 dasd_delete_device(device);
2027 if (!try_module_get(discipline->owner)) {
2028 module_put(base_discipline->owner);
2029 dasd_delete_device(device);
2032 device->base_discipline = base_discipline;
2033 device->discipline = discipline;
2035 rc = discipline->check_device(device);
2037 printk (KERN_WARNING
2038 "dasd_generic couldn't online device %s "
2039 "with discipline %s rc=%i\n",
2040 cdev->dev.bus_id, discipline->name, rc);
2041 module_put(discipline->owner);
2042 module_put(base_discipline->owner);
2043 dasd_delete_device(device);
2047 dasd_set_target_state(device, DASD_STATE_ONLINE);
2048 if (device->state <= DASD_STATE_KNOWN) {
2049 printk (KERN_WARNING
2050 "dasd_generic discipline not found for %s\n",
2053 dasd_set_target_state(device, DASD_STATE_NEW);
2054 dasd_delete_device(device);
2056 pr_debug("dasd_generic device %s found\n",
2059 /* FIXME: we have to wait for the root device but we don't want
2060 * to wait for each single device but for all at once. */
2061 wait_event(dasd_init_waitq, _wait_for_device(device));
2063 dasd_put_device(device);
2069 dasd_generic_set_offline (struct ccw_device *cdev)
2071 struct dasd_device *device;
2072 int max_count, open_count;
2074 device = dasd_device_from_cdev(cdev);
2076 return PTR_ERR(device);
2077 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2078 /* Already doing offline processing */
2079 dasd_put_device(device);
2083 * We must make sure that this device is currently not in use.
2084 * The open_count is increased for every opener, that includes
2085 * the blkdev_get in dasd_scan_partitions. We are only interested
2086 * in the other openers.
2088 max_count = device->bdev ? 0 : -1;
2089 open_count = (int) atomic_read(&device->open_count);
2090 if (open_count > max_count) {
2092 printk (KERN_WARNING "Can't offline dasd device with "
2093 "open count = %i.\n",
2096 printk (KERN_WARNING "%s",
2097 "Can't offline dasd device due to internal "
2099 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
2100 dasd_put_device(device);
2103 dasd_set_target_state(device, DASD_STATE_NEW);
2104 /* dasd_delete_device destroys the device reference. */
2105 dasd_delete_device(device);
2111 dasd_generic_notify(struct ccw_device *cdev, int event)
2113 struct dasd_device *device;
2114 struct dasd_ccw_req *cqr;
2115 unsigned long flags;
2118 device = dasd_device_from_cdev(cdev);
2121 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
2126 /* First of all call extended error reporting. */
2127 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
2129 if (device->state < DASD_STATE_BASIC)
2131 /* Device is active. We want to keep it. */
2132 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
2133 list_for_each_entry(cqr, &device->ccw_queue, list)
2134 if (cqr->status == DASD_CQR_IN_IO)
2135 cqr->status = DASD_CQR_FAILED;
2136 device->stopped |= DASD_STOPPED_DC_EIO;
2138 list_for_each_entry(cqr, &device->ccw_queue, list)
2139 if (cqr->status == DASD_CQR_IN_IO) {
2140 cqr->status = DASD_CQR_QUEUED;
2143 device->stopped |= DASD_STOPPED_DC_WAIT;
2144 dasd_set_timer(device, 0);
2146 dasd_schedule_bh(device);
2150 /* FIXME: add a sanity check. */
2151 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
2152 dasd_schedule_bh(device);
2156 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2157 dasd_put_device(device);
2167 init_waitqueue_head(&dasd_init_waitq);
2168 init_waitqueue_head(&dasd_flush_wq);
2170 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2171 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long));
2172 if (dasd_debug_area == NULL) {
2176 debug_register_view(dasd_debug_area, &debug_sprintf_view);
2177 debug_set_level(dasd_debug_area, DBF_WARNING);
2179 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
2181 dasd_diag_discipline_pointer = NULL;
2183 rc = dasd_devmap_init();
2186 rc = dasd_gendisk_init();
2192 rc = dasd_eer_init();
2195 #ifdef CONFIG_PROC_FS
2196 rc = dasd_proc_init();
2203 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2208 module_init(dasd_init);
2209 module_exit(dasd_exit);
2211 EXPORT_SYMBOL(dasd_debug_area);
2212 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2214 EXPORT_SYMBOL(dasd_add_request_head);
2215 EXPORT_SYMBOL(dasd_add_request_tail);
2216 EXPORT_SYMBOL(dasd_cancel_req);
2217 EXPORT_SYMBOL(dasd_clear_timer);
2218 EXPORT_SYMBOL(dasd_enable_device);
2219 EXPORT_SYMBOL(dasd_int_handler);
2220 EXPORT_SYMBOL(dasd_kfree_request);
2221 EXPORT_SYMBOL(dasd_kick_device);
2222 EXPORT_SYMBOL(dasd_kmalloc_request);
2223 EXPORT_SYMBOL(dasd_schedule_bh);
2224 EXPORT_SYMBOL(dasd_set_target_state);
2225 EXPORT_SYMBOL(dasd_set_timer);
2226 EXPORT_SYMBOL(dasd_sfree_request);
2227 EXPORT_SYMBOL(dasd_sleep_on);
2228 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2229 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2230 EXPORT_SYMBOL(dasd_smalloc_request);
2231 EXPORT_SYMBOL(dasd_start_IO);
2232 EXPORT_SYMBOL(dasd_term_IO);
2234 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2235 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2236 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2237 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2238 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);