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_EMERG);
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);
207 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
208 if (device->debug_area != NULL) {
209 debug_unregister(device->debug_area);
210 device->debug_area = NULL;
212 device->state = DASD_STATE_KNOWN;
217 * Do the initial analysis. The do_analysis function may return
218 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
219 * until the discipline decides to continue the startup sequence
220 * by calling the function dasd_change_state. The eckd disciplines
221 * uses this to start a ccw that detects the format. The completion
222 * interrupt for this detection ccw uses the kernel event daemon to
223 * trigger the call to dasd_change_state. All this is done in the
224 * discipline code, see dasd_eckd.c.
225 * After the analysis ccw is done (do_analysis returned 0) the block
227 * In case the analysis returns an error, the device setup is stopped
228 * (a fake disk was already added to allow formatting).
231 dasd_state_basic_to_ready(struct dasd_device * device)
236 if (device->discipline->do_analysis != NULL)
237 rc = device->discipline->do_analysis(device);
240 device->state = DASD_STATE_UNFMT;
243 /* make disk known with correct capacity */
244 dasd_setup_queue(device);
245 set_capacity(device->gdp, device->blocks << device->s2b_shift);
246 device->state = DASD_STATE_READY;
247 rc = dasd_scan_partitions(device);
249 device->state = DASD_STATE_BASIC;
254 * Remove device from block device layer. Destroy dirty buffers.
255 * Forget format information. Check if the target level is basic
256 * and if it is create fake disk for formatting.
259 dasd_state_ready_to_basic(struct dasd_device * device)
263 rc = dasd_flush_ccw_queue(device, 0);
266 dasd_destroy_partitions(device);
267 dasd_flush_request_queue(device);
269 device->bp_block = 0;
270 device->s2b_shift = 0;
271 device->state = DASD_STATE_BASIC;
279 dasd_state_unfmt_to_basic(struct dasd_device * device)
281 device->state = DASD_STATE_BASIC;
286 * Make the device online and schedule the bottom half to start
287 * the requeueing of requests from the linux request queue to the
291 dasd_state_ready_to_online(struct dasd_device * device)
293 device->state = DASD_STATE_ONLINE;
294 dasd_schedule_bh(device);
299 * Stop the requeueing of requests again.
302 dasd_state_online_to_ready(struct dasd_device * device)
304 device->state = DASD_STATE_READY;
309 * Device startup state changes.
312 dasd_increase_state(struct dasd_device *device)
317 if (device->state == DASD_STATE_NEW &&
318 device->target >= DASD_STATE_KNOWN)
319 rc = dasd_state_new_to_known(device);
322 device->state == DASD_STATE_KNOWN &&
323 device->target >= DASD_STATE_BASIC)
324 rc = dasd_state_known_to_basic(device);
327 device->state == DASD_STATE_BASIC &&
328 device->target >= DASD_STATE_READY)
329 rc = dasd_state_basic_to_ready(device);
332 device->state == DASD_STATE_UNFMT &&
333 device->target > DASD_STATE_UNFMT)
337 device->state == DASD_STATE_READY &&
338 device->target >= DASD_STATE_ONLINE)
339 rc = dasd_state_ready_to_online(device);
345 * Device shutdown state changes.
348 dasd_decrease_state(struct dasd_device *device)
353 if (device->state == DASD_STATE_ONLINE &&
354 device->target <= DASD_STATE_READY)
355 rc = dasd_state_online_to_ready(device);
358 device->state == DASD_STATE_READY &&
359 device->target <= DASD_STATE_BASIC)
360 rc = dasd_state_ready_to_basic(device);
363 device->state == DASD_STATE_UNFMT &&
364 device->target <= DASD_STATE_BASIC)
365 rc = dasd_state_unfmt_to_basic(device);
368 device->state == DASD_STATE_BASIC &&
369 device->target <= DASD_STATE_KNOWN)
370 rc = dasd_state_basic_to_known(device);
373 device->state == DASD_STATE_KNOWN &&
374 device->target <= DASD_STATE_NEW)
375 rc = dasd_state_known_to_new(device);
381 * This is the main startup/shutdown routine.
384 dasd_change_state(struct dasd_device *device)
388 if (device->state == device->target)
389 /* Already where we want to go today... */
391 if (device->state < device->target)
392 rc = dasd_increase_state(device);
394 rc = dasd_decrease_state(device);
395 if (rc && rc != -EAGAIN)
396 device->target = device->state;
398 if (device->state == device->target)
399 wake_up(&dasd_init_waitq);
403 * Kick starter for devices that did not complete the startup/shutdown
404 * procedure or were sleeping because of a pending state.
405 * dasd_kick_device will schedule a call do do_kick_device to the kernel
409 do_kick_device(void *data)
411 struct dasd_device *device;
413 device = (struct dasd_device *) data;
414 dasd_change_state(device);
415 dasd_schedule_bh(device);
416 dasd_put_device(device);
420 dasd_kick_device(struct dasd_device *device)
422 dasd_get_device(device);
423 /* queue call to dasd_kick_device to the kernel event daemon. */
424 schedule_work(&device->kick_work);
428 * Set the target state for a device and starts the state change.
431 dasd_set_target_state(struct dasd_device *device, int target)
433 /* If we are in probeonly mode stop at DASD_STATE_READY. */
434 if (dasd_probeonly && target > DASD_STATE_READY)
435 target = DASD_STATE_READY;
436 if (device->target != target) {
437 if (device->state == target)
438 wake_up(&dasd_init_waitq);
439 device->target = target;
441 if (device->state != device->target)
442 dasd_change_state(device);
446 * Enable devices with device numbers in [from..to].
449 _wait_for_device(struct dasd_device *device)
451 return (device->state == device->target);
455 dasd_enable_device(struct dasd_device *device)
457 dasd_set_target_state(device, DASD_STATE_ONLINE);
458 if (device->state <= DASD_STATE_KNOWN)
459 /* No discipline for device found. */
460 dasd_set_target_state(device, DASD_STATE_NEW);
461 /* Now wait for the devices to come up. */
462 wait_event(dasd_init_waitq, _wait_for_device(device));
466 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
468 #ifdef CONFIG_DASD_PROFILE
470 struct dasd_profile_info_t dasd_global_profile;
471 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
474 * Increments counter in global and local profiling structures.
476 #define dasd_profile_counter(value, counter, device) \
479 for (index = 0; index < 31 && value >> (2+index); index++); \
480 dasd_global_profile.counter[index]++; \
481 device->profile.counter[index]++; \
485 * Add profiling information for cqr before execution.
488 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
492 unsigned int counter;
494 if (dasd_profile_level != DASD_PROFILE_ON)
497 /* count the length of the chanq for statistics */
499 list_for_each(l, &device->ccw_queue)
502 dasd_global_profile.dasd_io_nr_req[counter]++;
503 device->profile.dasd_io_nr_req[counter]++;
507 * Add profiling information for cqr after execution.
510 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
513 long strtime, irqtime, endtime, tottime; /* in microseconds */
514 long tottimeps, sectors;
516 if (dasd_profile_level != DASD_PROFILE_ON)
519 sectors = req->nr_sectors;
520 if (!cqr->buildclk || !cqr->startclk ||
521 !cqr->stopclk || !cqr->endclk ||
525 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
526 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
527 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
528 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
529 tottimeps = tottime / sectors;
531 if (!dasd_global_profile.dasd_io_reqs)
532 memset(&dasd_global_profile, 0,
533 sizeof (struct dasd_profile_info_t));
534 dasd_global_profile.dasd_io_reqs++;
535 dasd_global_profile.dasd_io_sects += sectors;
537 if (!device->profile.dasd_io_reqs)
538 memset(&device->profile, 0,
539 sizeof (struct dasd_profile_info_t));
540 device->profile.dasd_io_reqs++;
541 device->profile.dasd_io_sects += sectors;
543 dasd_profile_counter(sectors, dasd_io_secs, device);
544 dasd_profile_counter(tottime, dasd_io_times, device);
545 dasd_profile_counter(tottimeps, dasd_io_timps, device);
546 dasd_profile_counter(strtime, dasd_io_time1, device);
547 dasd_profile_counter(irqtime, dasd_io_time2, device);
548 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
549 dasd_profile_counter(endtime, dasd_io_time3, device);
552 #define dasd_profile_start(device, cqr, req) do {} while (0)
553 #define dasd_profile_end(device, cqr, req) do {} while (0)
554 #endif /* CONFIG_DASD_PROFILE */
557 * Allocate memory for a channel program with 'cplength' channel
558 * command words and 'datasize' additional space. There are two
559 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
560 * memory and 2) dasd_smalloc_request uses the static ccw memory
561 * that gets allocated for each device.
563 struct dasd_ccw_req *
564 dasd_kmalloc_request(char *magic, int cplength, int datasize,
565 struct dasd_device * device)
567 struct dasd_ccw_req *cqr;
570 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
571 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
573 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
575 return ERR_PTR(-ENOMEM);
578 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
579 GFP_ATOMIC | GFP_DMA);
580 if (cqr->cpaddr == NULL) {
582 return ERR_PTR(-ENOMEM);
587 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
588 if (cqr->data == NULL) {
591 return ERR_PTR(-ENOMEM);
594 strncpy((char *) &cqr->magic, magic, 4);
595 ASCEBC((char *) &cqr->magic, 4);
596 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
597 dasd_get_device(device);
601 struct dasd_ccw_req *
602 dasd_smalloc_request(char *magic, int cplength, int datasize,
603 struct dasd_device * device)
606 struct dasd_ccw_req *cqr;
611 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
612 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
614 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
616 size += cplength * sizeof(struct ccw1);
619 spin_lock_irqsave(&device->mem_lock, flags);
620 cqr = (struct dasd_ccw_req *)
621 dasd_alloc_chunk(&device->ccw_chunks, size);
622 spin_unlock_irqrestore(&device->mem_lock, flags);
624 return ERR_PTR(-ENOMEM);
625 memset(cqr, 0, sizeof(struct dasd_ccw_req));
626 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
629 cqr->cpaddr = (struct ccw1 *) data;
630 data += cplength*sizeof(struct ccw1);
631 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
636 memset(cqr->data, 0, datasize);
638 strncpy((char *) &cqr->magic, magic, 4);
639 ASCEBC((char *) &cqr->magic, 4);
640 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
641 dasd_get_device(device);
646 * Free memory of a channel program. This function needs to free all the
647 * idal lists that might have been created by dasd_set_cda and the
648 * struct dasd_ccw_req itself.
651 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
656 /* Clear any idals used for the request. */
659 clear_normalized_cda(ccw);
660 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
665 dasd_put_device(device);
669 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
673 spin_lock_irqsave(&device->mem_lock, flags);
674 dasd_free_chunk(&device->ccw_chunks, cqr);
675 spin_unlock_irqrestore(&device->mem_lock, flags);
676 dasd_put_device(device);
680 * Check discipline magic in cqr.
683 dasd_check_cqr(struct dasd_ccw_req *cqr)
685 struct dasd_device *device;
689 device = cqr->device;
690 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
691 DEV_MESSAGE(KERN_WARNING, device,
692 " dasd_ccw_req 0x%08x magic doesn't match"
693 " discipline 0x%08x",
695 *(unsigned int *) device->discipline->name);
702 * Terminate the current i/o and set the request to clear_pending.
703 * Timer keeps device runnig.
704 * ccw_device_clear can fail if the i/o subsystem
708 dasd_term_IO(struct dasd_ccw_req * cqr)
710 struct dasd_device *device;
714 rc = dasd_check_cqr(cqr);
718 device = (struct dasd_device *) cqr->device;
719 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
720 rc = ccw_device_clear(device->cdev, (long) cqr);
722 case 0: /* termination successful */
724 cqr->status = DASD_CQR_CLEAR;
725 cqr->stopclk = get_clock();
727 DBF_DEV_EVENT(DBF_DEBUG, device,
728 "terminate cqr %p successful",
732 DBF_DEV_EVENT(DBF_ERR, device, "%s",
733 "device gone, retry");
736 DBF_DEV_EVENT(DBF_ERR, device, "%s",
741 DBF_DEV_EVENT(DBF_ERR, device, "%s",
742 "device busy, retry later");
745 DEV_MESSAGE(KERN_ERR, device,
746 "line %d unknown RC=%d, please "
747 "report to linux390@de.ibm.com",
754 dasd_schedule_bh(device);
759 * Start the i/o. This start_IO can fail if the channel is really busy.
760 * In that case set up a timer to start the request later.
763 dasd_start_IO(struct dasd_ccw_req * cqr)
765 struct dasd_device *device;
769 rc = dasd_check_cqr(cqr);
772 device = (struct dasd_device *) cqr->device;
773 if (cqr->retries < 0) {
774 DEV_MESSAGE(KERN_DEBUG, device,
775 "start_IO: request %p (%02x/%i) - no retry left.",
776 cqr, cqr->status, cqr->retries);
777 cqr->status = DASD_CQR_FAILED;
780 cqr->startclk = get_clock();
781 cqr->starttime = jiffies;
783 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
787 cqr->status = DASD_CQR_IN_IO;
788 DBF_DEV_EVENT(DBF_DEBUG, device,
789 "start_IO: request %p started successful",
793 DBF_DEV_EVENT(DBF_ERR, device, "%s",
794 "start_IO: device busy, retry later");
797 DBF_DEV_EVENT(DBF_ERR, device, "%s",
798 "start_IO: request timeout, retry later");
801 /* -EACCES indicates that the request used only a
802 * subset of the available pathes and all these
804 * Do a retry with all available pathes.
806 cqr->lpm = LPM_ANYPATH;
807 DBF_DEV_EVENT(DBF_ERR, device, "%s",
808 "start_IO: selected pathes gone,"
809 " retry on all pathes");
813 DBF_DEV_EVENT(DBF_ERR, device, "%s",
814 "start_IO: device gone, retry");
817 DEV_MESSAGE(KERN_ERR, device,
818 "line %d unknown RC=%d, please report"
819 " to linux390@de.ibm.com", __LINE__, rc);
827 * Timeout function for dasd devices. This is used for different purposes
828 * 1) missing interrupt handler for normal operation
829 * 2) delayed start of request where start_IO failed with -EBUSY
830 * 3) timeout for missing state change interrupts
831 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
832 * DASD_CQR_QUEUED for 2) and 3).
835 dasd_timeout_device(unsigned long ptr)
838 struct dasd_device *device;
840 device = (struct dasd_device *) ptr;
841 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
842 /* re-activate request queue */
843 device->stopped &= ~DASD_STOPPED_PENDING;
844 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
845 dasd_schedule_bh(device);
849 * Setup timeout for a device in jiffies.
852 dasd_set_timer(struct dasd_device *device, int expires)
855 if (timer_pending(&device->timer))
856 del_timer(&device->timer);
859 if (timer_pending(&device->timer)) {
860 if (mod_timer(&device->timer, jiffies + expires))
863 device->timer.function = dasd_timeout_device;
864 device->timer.data = (unsigned long) device;
865 device->timer.expires = jiffies + expires;
866 add_timer(&device->timer);
870 * Clear timeout for a device.
873 dasd_clear_timer(struct dasd_device *device)
875 if (timer_pending(&device->timer))
876 del_timer(&device->timer);
880 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
882 struct dasd_ccw_req *cqr;
883 struct dasd_device *device;
885 cqr = (struct dasd_ccw_req *) intparm;
886 if (cqr->status != DASD_CQR_IN_IO) {
888 "invalid status in handle_killed_request: "
889 "bus_id %s, status %02x",
890 cdev->dev.bus_id, cqr->status);
894 device = (struct dasd_device *) cqr->device;
895 if (device == NULL ||
896 device != dasd_device_from_cdev_locked(cdev) ||
897 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
898 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
903 /* Schedule request to be retried. */
904 cqr->status = DASD_CQR_QUEUED;
906 dasd_clear_timer(device);
907 dasd_schedule_bh(device);
908 dasd_put_device(device);
912 dasd_handle_state_change_pending(struct dasd_device *device)
914 struct dasd_ccw_req *cqr;
915 struct list_head *l, *n;
917 /* First of all start sense subsystem status request. */
918 dasd_eer_snss(device);
920 device->stopped &= ~DASD_STOPPED_PENDING;
922 /* restart all 'running' IO on queue */
923 list_for_each_safe(l, n, &device->ccw_queue) {
924 cqr = list_entry(l, struct dasd_ccw_req, list);
925 if (cqr->status == DASD_CQR_IN_IO) {
926 cqr->status = DASD_CQR_QUEUED;
929 dasd_clear_timer(device);
930 dasd_schedule_bh(device);
934 * Interrupt handler for "normal" ssch-io based dasd devices.
937 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
940 struct dasd_ccw_req *cqr, *next;
941 struct dasd_device *device;
942 unsigned long long now;
948 switch (PTR_ERR(irb)) {
950 dasd_handle_killed_request(cdev, intparm);
953 printk(KERN_WARNING"%s(%s): request timed out\n",
954 __FUNCTION__, cdev->dev.bus_id);
955 //FIXME - dasd uses own timeout interface...
958 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
959 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
966 DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
967 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
968 (unsigned int) intparm);
970 /* first of all check for state change pending interrupt */
971 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
972 if ((irb->scsw.dstat & mask) == mask) {
973 device = dasd_device_from_cdev_locked(cdev);
974 if (!IS_ERR(device)) {
975 dasd_handle_state_change_pending(device);
976 dasd_put_device(device);
981 cqr = (struct dasd_ccw_req *) intparm;
983 /* check for unsolicited interrupts */
986 "unsolicited interrupt received: bus_id %s",
991 device = (struct dasd_device *) cqr->device;
992 if (device == NULL ||
993 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
994 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
999 /* Check for clear pending */
1000 if (cqr->status == DASD_CQR_CLEAR &&
1001 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
1002 cqr->status = DASD_CQR_QUEUED;
1003 dasd_clear_timer(device);
1004 wake_up(&dasd_flush_wq);
1005 dasd_schedule_bh(device);
1009 /* check status - the request might have been killed by dyn detach */
1010 if (cqr->status != DASD_CQR_IN_IO) {
1012 "invalid status: bus_id %s, status %02x",
1013 cdev->dev.bus_id, cqr->status);
1016 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
1017 ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
1019 /* Find out the appropriate era_action. */
1020 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
1021 era = dasd_era_fatal;
1022 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1023 irb->scsw.cstat == 0 &&
1024 !irb->esw.esw0.erw.cons)
1025 era = dasd_era_none;
1026 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
1027 era = dasd_era_fatal; /* don't recover this request */
1028 else if (irb->esw.esw0.erw.cons)
1029 era = device->discipline->examine_error(cqr, irb);
1031 era = dasd_era_recover;
1033 DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
1035 if (era == dasd_era_none) {
1036 cqr->status = DASD_CQR_DONE;
1038 /* Start first request on queue if possible -> fast_io. */
1039 if (cqr->list.next != &device->ccw_queue) {
1040 next = list_entry(cqr->list.next,
1041 struct dasd_ccw_req, list);
1042 if ((next->status == DASD_CQR_QUEUED) &&
1043 (!device->stopped)) {
1044 if (device->discipline->start_IO(next) == 0)
1045 expires = next->expires;
1047 DEV_MESSAGE(KERN_DEBUG, device, "%s",
1048 "Interrupt fastpath "
1052 } else { /* error */
1053 memcpy(&cqr->irb, irb, sizeof (struct irb));
1055 /* dump sense data */
1056 dasd_log_sense(cqr, irb);
1059 case dasd_era_fatal:
1060 cqr->status = DASD_CQR_FAILED;
1063 case dasd_era_recover:
1064 cqr->status = DASD_CQR_ERROR;
1071 dasd_set_timer(device, expires);
1073 dasd_clear_timer(device);
1074 dasd_schedule_bh(device);
1078 * posts the buffer_cache about a finalized request
1081 dasd_end_request(struct request *req, int uptodate)
1083 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1085 add_disk_randomness(req->rq_disk);
1086 end_that_request_last(req, uptodate);
1090 * Process finished error recovery ccw.
1093 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1095 dasd_erp_fn_t erp_fn;
1097 if (cqr->status == DASD_CQR_DONE)
1098 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1100 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1101 erp_fn = device->discipline->erp_postaction(cqr);
1106 * Process ccw request queue.
1109 __dasd_process_ccw_queue(struct dasd_device * device,
1110 struct list_head *final_queue)
1112 struct list_head *l, *n;
1113 struct dasd_ccw_req *cqr;
1114 dasd_erp_fn_t erp_fn;
1117 /* Process request with final status. */
1118 list_for_each_safe(l, n, &device->ccw_queue) {
1119 cqr = list_entry(l, struct dasd_ccw_req, list);
1120 /* Stop list processing at the first non-final request. */
1121 if (cqr->status != DASD_CQR_DONE &&
1122 cqr->status != DASD_CQR_FAILED &&
1123 cqr->status != DASD_CQR_ERROR)
1125 /* Process requests with DASD_CQR_ERROR */
1126 if (cqr->status == DASD_CQR_ERROR) {
1127 if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1128 cqr->status = DASD_CQR_FAILED;
1129 cqr->stopclk = get_clock();
1131 if (cqr->irb.esw.esw0.erw.cons) {
1132 erp_fn = device->discipline->
1136 dasd_default_erp_action(cqr);
1141 /* First of all call extended error reporting. */
1142 if (dasd_eer_enabled(device) &&
1143 cqr->status == DASD_CQR_FAILED) {
1144 dasd_eer_write(device, cqr, DASD_EER_FATALERROR);
1146 /* restart request */
1147 cqr->status = DASD_CQR_QUEUED;
1149 device->stopped |= DASD_STOPPED_QUIESCE;
1153 /* Process finished ERP request. */
1155 __dasd_process_erp(device, cqr);
1159 /* Rechain finished requests to final queue */
1160 cqr->endclk = get_clock();
1161 list_move_tail(&cqr->list, final_queue);
1166 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1168 struct request *req;
1169 struct dasd_device *device;
1172 req = (struct request *) data;
1173 device = cqr->device;
1174 dasd_profile_end(device, cqr, req);
1175 status = cqr->device->discipline->free_cp(cqr,req);
1176 spin_lock_irq(&device->request_queue_lock);
1177 dasd_end_request(req, status);
1178 spin_unlock_irq(&device->request_queue_lock);
1183 * Fetch requests from the block device queue.
1186 __dasd_process_blk_queue(struct dasd_device * device)
1188 request_queue_t *queue;
1189 struct request *req;
1190 struct dasd_ccw_req *cqr;
1193 queue = device->request_queue;
1194 /* No queue ? Then there is nothing to do. */
1199 * We requeue request from the block device queue to the ccw
1200 * queue only in two states. In state DASD_STATE_READY the
1201 * partition detection is done and we need to requeue requests
1202 * for that. State DASD_STATE_ONLINE is normal block device
1205 if (device->state != DASD_STATE_READY &&
1206 device->state != DASD_STATE_ONLINE)
1209 /* Now we try to fetch requests from the request queue */
1210 list_for_each_entry(cqr, &device->ccw_queue, list)
1211 if (cqr->status == DASD_CQR_QUEUED)
1213 while (!blk_queue_plugged(queue) &&
1214 elv_next_request(queue) &&
1215 nr_queued < DASD_CHANQ_MAX_SIZE) {
1216 req = elv_next_request(queue);
1218 if (device->features & DASD_FEATURE_READONLY &&
1219 rq_data_dir(req) == WRITE) {
1220 DBF_DEV_EVENT(DBF_ERR, device,
1221 "Rejecting write request %p",
1223 blkdev_dequeue_request(req);
1224 dasd_end_request(req, 0);
1227 if (device->stopped & DASD_STOPPED_DC_EIO) {
1228 blkdev_dequeue_request(req);
1229 dasd_end_request(req, 0);
1232 cqr = device->discipline->build_cp(device, req);
1234 if (PTR_ERR(cqr) == -ENOMEM)
1235 break; /* terminate request queue loop */
1236 DBF_DEV_EVENT(DBF_ERR, device,
1237 "CCW creation failed (rc=%ld) "
1240 blkdev_dequeue_request(req);
1241 dasd_end_request(req, 0);
1244 cqr->callback = dasd_end_request_cb;
1245 cqr->callback_data = (void *) req;
1246 cqr->status = DASD_CQR_QUEUED;
1247 blkdev_dequeue_request(req);
1248 list_add_tail(&cqr->list, &device->ccw_queue);
1249 dasd_profile_start(device, cqr, req);
1255 * Take a look at the first request on the ccw queue and check
1256 * if it reached its expire time. If so, terminate the IO.
1259 __dasd_check_expire(struct dasd_device * device)
1261 struct dasd_ccw_req *cqr;
1263 if (list_empty(&device->ccw_queue))
1265 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1266 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1267 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1268 DEV_MESSAGE(KERN_ERR, device,
1269 "internal error - timeout (%is) expired "
1270 "for cqr %p (%i retries left)",
1271 (cqr->expires/HZ), cqr, cqr->retries);
1272 if (device->discipline->term_IO(cqr) != 0)
1273 /* Hmpf, try again in 1/10 sec */
1274 dasd_set_timer(device, 10);
1280 * Take a look at the first request on the ccw queue and check
1281 * if it needs to be started.
1284 __dasd_start_head(struct dasd_device * device)
1286 struct dasd_ccw_req *cqr;
1289 if (list_empty(&device->ccw_queue))
1291 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1292 if (cqr->status != DASD_CQR_QUEUED)
1294 /* Non-temporary stop condition will trigger fail fast */
1295 if (device->stopped & ~DASD_STOPPED_PENDING &&
1296 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1297 (!dasd_eer_enabled(device))) {
1298 cqr->status = DASD_CQR_FAILED;
1299 dasd_schedule_bh(device);
1302 /* Don't try to start requests if device is stopped */
1303 if (device->stopped)
1306 rc = device->discipline->start_IO(cqr);
1308 dasd_set_timer(device, cqr->expires);
1309 else if (rc == -EACCES) {
1310 dasd_schedule_bh(device);
1312 /* Hmpf, try again in 1/2 sec */
1313 dasd_set_timer(device, 50);
1317 _wait_for_clear(struct dasd_ccw_req *cqr)
1319 return (cqr->status == DASD_CQR_QUEUED);
1323 * Remove all requests from the ccw queue (all = '1') or only block device
1324 * requests in case all = '0'.
1325 * Take care of the erp-chain (chained via cqr->refers) and remove either
1326 * the whole erp-chain or none of the erp-requests.
1327 * If a request is currently running, term_IO is called and the request
1328 * is re-queued. Prior to removing the terminated request we need to wait
1329 * for the clear-interrupt.
1330 * In case termination is not possible we stop processing and just finishing
1331 * the already moved requests.
1334 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1336 struct dasd_ccw_req *cqr, *orig, *n;
1339 struct list_head flush_queue;
1341 INIT_LIST_HEAD(&flush_queue);
1342 spin_lock_irq(get_ccwdev_lock(device->cdev));
1345 list_for_each_entry_safe(cqr, n, &device->ccw_queue, list) {
1346 /* get original request of erp request-chain */
1347 for (orig = cqr; orig->refers != NULL; orig = orig->refers);
1349 /* Flush all request or only block device requests? */
1350 if (all == 0 && cqr->callback != dasd_end_request_cb &&
1351 orig->callback != dasd_end_request_cb) {
1354 /* Check status and move request to flush_queue */
1355 switch (cqr->status) {
1356 case DASD_CQR_IN_IO:
1357 rc = device->discipline->term_IO(cqr);
1359 /* unable to terminate requeust */
1360 DEV_MESSAGE(KERN_ERR, device,
1361 "dasd flush ccw_queue is unable "
1362 " to terminate request %p",
1364 /* stop flush processing */
1368 case DASD_CQR_QUEUED:
1369 case DASD_CQR_ERROR:
1370 /* set request to FAILED */
1371 cqr->stopclk = get_clock();
1372 cqr->status = DASD_CQR_FAILED;
1374 default: /* do not touch the others */
1377 /* Rechain request (including erp chain) */
1378 for (i = 0; cqr != NULL; cqr = cqr->refers, i++) {
1379 cqr->endclk = get_clock();
1380 list_move_tail(&cqr->list, &flush_queue);
1383 /* moved more than one request - need to restart */
1388 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1389 /* Now call the callback function of flushed requests */
1391 list_for_each_entry_safe(cqr, n, &flush_queue, list) {
1392 if (cqr->status == DASD_CQR_CLEAR) {
1393 /* wait for clear interrupt! */
1394 wait_event(dasd_flush_wq, _wait_for_clear(cqr));
1395 cqr->status = DASD_CQR_FAILED;
1397 /* Process finished ERP request. */
1399 __dasd_process_erp(device, cqr);
1400 /* restart list_for_xx loop since dasd_process_erp
1401 * might remove multiple elements */
1404 /* call the callback function */
1405 cqr->endclk = get_clock();
1406 if (cqr->callback != NULL)
1407 (cqr->callback)(cqr, cqr->callback_data);
1413 * Acquire the device lock and process queues for the device.
1416 dasd_tasklet(struct dasd_device * device)
1418 struct list_head final_queue;
1419 struct list_head *l, *n;
1420 struct dasd_ccw_req *cqr;
1422 atomic_set (&device->tasklet_scheduled, 0);
1423 INIT_LIST_HEAD(&final_queue);
1424 spin_lock_irq(get_ccwdev_lock(device->cdev));
1425 /* Check expire time of first request on the ccw queue. */
1426 __dasd_check_expire(device);
1427 /* Finish off requests on ccw queue */
1428 __dasd_process_ccw_queue(device, &final_queue);
1429 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1430 /* Now call the callback function of requests with final status */
1431 list_for_each_safe(l, n, &final_queue) {
1432 cqr = list_entry(l, struct dasd_ccw_req, list);
1433 list_del_init(&cqr->list);
1434 if (cqr->callback != NULL)
1435 (cqr->callback)(cqr, cqr->callback_data);
1437 spin_lock_irq(&device->request_queue_lock);
1438 spin_lock(get_ccwdev_lock(device->cdev));
1439 /* Get new request from the block device request queue */
1440 __dasd_process_blk_queue(device);
1441 /* Now check if the head of the ccw queue needs to be started. */
1442 __dasd_start_head(device);
1443 spin_unlock(get_ccwdev_lock(device->cdev));
1444 spin_unlock_irq(&device->request_queue_lock);
1445 dasd_put_device(device);
1449 * Schedules a call to dasd_tasklet over the device tasklet.
1452 dasd_schedule_bh(struct dasd_device * device)
1454 /* Protect against rescheduling. */
1455 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
1457 dasd_get_device(device);
1458 tasklet_hi_schedule(&device->tasklet);
1462 * Queue a request to the head of the ccw_queue. Start the I/O if
1466 dasd_add_request_head(struct dasd_ccw_req *req)
1468 struct dasd_device *device;
1469 unsigned long flags;
1471 device = req->device;
1472 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1473 req->status = DASD_CQR_QUEUED;
1474 req->device = device;
1475 list_add(&req->list, &device->ccw_queue);
1476 /* let the bh start the request to keep them in order */
1477 dasd_schedule_bh(device);
1478 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1482 * Queue a request to the tail of the ccw_queue. Start the I/O if
1486 dasd_add_request_tail(struct dasd_ccw_req *req)
1488 struct dasd_device *device;
1489 unsigned long flags;
1491 device = req->device;
1492 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1493 req->status = DASD_CQR_QUEUED;
1494 req->device = device;
1495 list_add_tail(&req->list, &device->ccw_queue);
1496 /* let the bh start the request to keep them in order */
1497 dasd_schedule_bh(device);
1498 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1505 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1507 wake_up((wait_queue_head_t *) data);
1511 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1513 struct dasd_device *device;
1516 device = cqr->device;
1517 spin_lock_irq(get_ccwdev_lock(device->cdev));
1518 rc = ((cqr->status == DASD_CQR_DONE ||
1519 cqr->status == DASD_CQR_FAILED) &&
1520 list_empty(&cqr->list));
1521 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1526 * Attempts to start a special ccw queue and waits for its completion.
1529 dasd_sleep_on(struct dasd_ccw_req * cqr)
1531 wait_queue_head_t wait_q;
1532 struct dasd_device *device;
1535 device = cqr->device;
1536 spin_lock_irq(get_ccwdev_lock(device->cdev));
1538 init_waitqueue_head (&wait_q);
1539 cqr->callback = dasd_wakeup_cb;
1540 cqr->callback_data = (void *) &wait_q;
1541 cqr->status = DASD_CQR_QUEUED;
1542 list_add_tail(&cqr->list, &device->ccw_queue);
1544 /* let the bh start the request to keep them in order */
1545 dasd_schedule_bh(device);
1547 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1549 wait_event(wait_q, _wait_for_wakeup(cqr));
1551 /* Request status is either done or failed. */
1552 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1557 * Attempts to start a special ccw queue and wait interruptible
1558 * for its completion.
1561 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1563 wait_queue_head_t wait_q;
1564 struct dasd_device *device;
1567 device = cqr->device;
1568 spin_lock_irq(get_ccwdev_lock(device->cdev));
1570 init_waitqueue_head (&wait_q);
1571 cqr->callback = dasd_wakeup_cb;
1572 cqr->callback_data = (void *) &wait_q;
1573 cqr->status = DASD_CQR_QUEUED;
1574 list_add_tail(&cqr->list, &device->ccw_queue);
1576 /* let the bh start the request to keep them in order */
1577 dasd_schedule_bh(device);
1578 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1582 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1583 if (rc != -ERESTARTSYS) {
1584 /* Request is final (done or failed) */
1585 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1588 spin_lock_irq(get_ccwdev_lock(device->cdev));
1589 switch (cqr->status) {
1590 case DASD_CQR_IN_IO:
1591 /* terminate runnig cqr */
1592 if (device->discipline->term_IO) {
1594 device->discipline->term_IO(cqr);
1595 /* wait (non-interruptible) for final status
1596 * because signal ist still pending */
1597 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1598 wait_event(wait_q, _wait_for_wakeup(cqr));
1599 spin_lock_irq(get_ccwdev_lock(device->cdev));
1600 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1604 case DASD_CQR_QUEUED:
1606 list_del_init(&cqr->list);
1611 /* cqr with 'non-interruptable' status - just wait */
1614 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1620 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1621 * for eckd devices) the currently running request has to be terminated
1622 * and be put back to status queued, before the special request is added
1623 * to the head of the queue. Then the special request is waited on normally.
1626 _dasd_term_running_cqr(struct dasd_device *device)
1628 struct dasd_ccw_req *cqr;
1630 if (list_empty(&device->ccw_queue))
1632 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1633 return device->discipline->term_IO(cqr);
1637 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1639 wait_queue_head_t wait_q;
1640 struct dasd_device *device;
1643 device = cqr->device;
1644 spin_lock_irq(get_ccwdev_lock(device->cdev));
1645 rc = _dasd_term_running_cqr(device);
1647 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1651 init_waitqueue_head (&wait_q);
1652 cqr->callback = dasd_wakeup_cb;
1653 cqr->callback_data = (void *) &wait_q;
1654 cqr->status = DASD_CQR_QUEUED;
1655 list_add(&cqr->list, &device->ccw_queue);
1657 /* let the bh start the request to keep them in order */
1658 dasd_schedule_bh(device);
1660 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1662 wait_event(wait_q, _wait_for_wakeup(cqr));
1664 /* Request status is either done or failed. */
1665 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1670 * Cancels a request that was started with dasd_sleep_on_req.
1671 * This is useful to timeout requests. The request will be
1672 * terminated if it is currently in i/o.
1673 * Returns 1 if the request has been terminated.
1676 dasd_cancel_req(struct dasd_ccw_req *cqr)
1678 struct dasd_device *device = cqr->device;
1679 unsigned long flags;
1683 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1684 switch (cqr->status) {
1685 case DASD_CQR_QUEUED:
1686 /* request was not started - just set to failed */
1687 cqr->status = DASD_CQR_FAILED;
1689 case DASD_CQR_IN_IO:
1690 /* request in IO - terminate IO and release again */
1691 if (device->discipline->term_IO(cqr) != 0)
1692 /* what to do if unable to terminate ??????
1694 cqr->status = DASD_CQR_FAILED;
1695 cqr->stopclk = get_clock();
1699 case DASD_CQR_FAILED:
1700 /* already finished - do nothing */
1703 DEV_MESSAGE(KERN_ALERT, device,
1704 "invalid status %02x in request",
1709 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1710 dasd_schedule_bh(device);
1715 * SECTION: Block device operations (request queue, partitions, open, release).
1719 * Dasd request queue function. Called from ll_rw_blk.c
1722 do_dasd_request(request_queue_t * queue)
1724 struct dasd_device *device;
1726 device = (struct dasd_device *) queue->queuedata;
1727 spin_lock(get_ccwdev_lock(device->cdev));
1728 /* Get new request from the block device request queue */
1729 __dasd_process_blk_queue(device);
1730 /* Now check if the head of the ccw queue needs to be started. */
1731 __dasd_start_head(device);
1732 spin_unlock(get_ccwdev_lock(device->cdev));
1736 * Allocate and initialize request queue and default I/O scheduler.
1739 dasd_alloc_queue(struct dasd_device * device)
1743 device->request_queue = blk_init_queue(do_dasd_request,
1744 &device->request_queue_lock);
1745 if (device->request_queue == NULL)
1748 device->request_queue->queuedata = device;
1750 elevator_exit(device->request_queue->elevator);
1751 rc = elevator_init(device->request_queue, "deadline");
1753 blk_cleanup_queue(device->request_queue);
1760 * Allocate and initialize request queue.
1763 dasd_setup_queue(struct dasd_device * device)
1767 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1768 max = device->discipline->max_blocks << device->s2b_shift;
1769 blk_queue_max_sectors(device->request_queue, max);
1770 blk_queue_max_phys_segments(device->request_queue, -1L);
1771 blk_queue_max_hw_segments(device->request_queue, -1L);
1772 blk_queue_max_segment_size(device->request_queue, -1L);
1773 blk_queue_segment_boundary(device->request_queue, -1L);
1774 blk_queue_ordered(device->request_queue, QUEUE_ORDERED_TAG, NULL);
1778 * Deactivate and free request queue.
1781 dasd_free_queue(struct dasd_device * device)
1783 if (device->request_queue) {
1784 blk_cleanup_queue(device->request_queue);
1785 device->request_queue = NULL;
1790 * Flush request on the request queue.
1793 dasd_flush_request_queue(struct dasd_device * device)
1795 struct request *req;
1797 if (!device->request_queue)
1800 spin_lock_irq(&device->request_queue_lock);
1801 while ((req = elv_next_request(device->request_queue))) {
1802 blkdev_dequeue_request(req);
1803 dasd_end_request(req, 0);
1805 spin_unlock_irq(&device->request_queue_lock);
1809 dasd_open(struct inode *inp, struct file *filp)
1811 struct gendisk *disk = inp->i_bdev->bd_disk;
1812 struct dasd_device *device = disk->private_data;
1815 atomic_inc(&device->open_count);
1816 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1821 if (!try_module_get(device->discipline->owner)) {
1826 if (dasd_probeonly) {
1827 DEV_MESSAGE(KERN_INFO, device, "%s",
1828 "No access to device due to probeonly mode");
1833 if (device->state <= DASD_STATE_BASIC) {
1834 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1835 " Cannot open unrecognized device");
1843 module_put(device->discipline->owner);
1845 atomic_dec(&device->open_count);
1850 dasd_release(struct inode *inp, struct file *filp)
1852 struct gendisk *disk = inp->i_bdev->bd_disk;
1853 struct dasd_device *device = disk->private_data;
1855 atomic_dec(&device->open_count);
1856 module_put(device->discipline->owner);
1861 * Return disk geometry.
1864 dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1866 struct dasd_device *device;
1868 device = bdev->bd_disk->private_data;
1872 if (!device->discipline ||
1873 !device->discipline->fill_geometry)
1876 device->discipline->fill_geometry(device, geo);
1877 geo->start = get_start_sect(bdev) >> device->s2b_shift;
1881 struct block_device_operations
1882 dasd_device_operations = {
1883 .owner = THIS_MODULE,
1885 .release = dasd_release,
1886 .ioctl = dasd_ioctl,
1887 .compat_ioctl = dasd_compat_ioctl,
1888 .getgeo = dasd_getgeo,
1895 #ifdef CONFIG_PROC_FS
1899 if (dasd_page_cache != NULL) {
1900 kmem_cache_destroy(dasd_page_cache);
1901 dasd_page_cache = NULL;
1903 dasd_gendisk_exit();
1905 if (dasd_debug_area != NULL) {
1906 debug_unregister(dasd_debug_area);
1907 dasd_debug_area = NULL;
1912 * SECTION: common functions for ccw_driver use
1916 * Initial attempt at a probe function. this can be simplified once
1917 * the other detection code is gone.
1920 dasd_generic_probe (struct ccw_device *cdev,
1921 struct dasd_discipline *discipline)
1925 ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
1928 "dasd_generic_probe: could not set ccw-device options "
1929 "for %s\n", cdev->dev.bus_id);
1932 ret = dasd_add_sysfs_files(cdev);
1935 "dasd_generic_probe: could not add sysfs entries "
1936 "for %s\n", cdev->dev.bus_id);
1939 cdev->handler = &dasd_int_handler;
1942 * Automatically online either all dasd devices (dasd_autodetect)
1943 * or all devices specified with dasd= parameters during
1946 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
1947 (dasd_autodetect && dasd_busid_known(cdev->dev.bus_id) != 0))
1948 ret = ccw_device_set_online(cdev);
1951 "dasd_generic_probe: could not initially online "
1952 "ccw-device %s\n", cdev->dev.bus_id);
1957 * This will one day be called from a global not_oper handler.
1958 * It is also used by driver_unregister during module unload.
1961 dasd_generic_remove (struct ccw_device *cdev)
1963 struct dasd_device *device;
1965 cdev->handler = NULL;
1967 dasd_remove_sysfs_files(cdev);
1968 device = dasd_device_from_cdev(cdev);
1971 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1972 /* Already doing offline processing */
1973 dasd_put_device(device);
1977 * This device is removed unconditionally. Set offline
1978 * flag to prevent dasd_open from opening it while it is
1979 * no quite down yet.
1981 dasd_set_target_state(device, DASD_STATE_NEW);
1982 /* dasd_delete_device destroys the device reference. */
1983 dasd_delete_device(device);
1987 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
1988 * the device is detected for the first time and is supposed to be used
1989 * or the user has started activation through sysfs.
1992 dasd_generic_set_online (struct ccw_device *cdev,
1993 struct dasd_discipline *base_discipline)
1996 struct dasd_discipline *discipline;
1997 struct dasd_device *device;
2000 /* first online clears initial online feature flag */
2001 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
2002 device = dasd_create_device(cdev);
2004 return PTR_ERR(device);
2006 discipline = base_discipline;
2007 if (device->features & DASD_FEATURE_USEDIAG) {
2008 if (!dasd_diag_discipline_pointer) {
2009 printk (KERN_WARNING
2010 "dasd_generic couldn't online device %s "
2011 "- discipline DIAG not available\n",
2013 dasd_delete_device(device);
2016 discipline = dasd_diag_discipline_pointer;
2018 if (!try_module_get(base_discipline->owner)) {
2019 dasd_delete_device(device);
2022 if (!try_module_get(discipline->owner)) {
2023 module_put(base_discipline->owner);
2024 dasd_delete_device(device);
2027 device->base_discipline = base_discipline;
2028 device->discipline = discipline;
2030 rc = discipline->check_device(device);
2032 printk (KERN_WARNING
2033 "dasd_generic couldn't online device %s "
2034 "with discipline %s rc=%i\n",
2035 cdev->dev.bus_id, discipline->name, rc);
2036 module_put(discipline->owner);
2037 module_put(base_discipline->owner);
2038 dasd_delete_device(device);
2042 dasd_set_target_state(device, DASD_STATE_ONLINE);
2043 if (device->state <= DASD_STATE_KNOWN) {
2044 printk (KERN_WARNING
2045 "dasd_generic discipline not found for %s\n",
2048 dasd_set_target_state(device, DASD_STATE_NEW);
2049 dasd_delete_device(device);
2051 pr_debug("dasd_generic device %s found\n",
2054 /* FIXME: we have to wait for the root device but we don't want
2055 * to wait for each single device but for all at once. */
2056 wait_event(dasd_init_waitq, _wait_for_device(device));
2058 dasd_put_device(device);
2064 dasd_generic_set_offline (struct ccw_device *cdev)
2066 struct dasd_device *device;
2067 int max_count, open_count;
2069 device = dasd_device_from_cdev(cdev);
2071 return PTR_ERR(device);
2072 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2073 /* Already doing offline processing */
2074 dasd_put_device(device);
2078 * We must make sure that this device is currently not in use.
2079 * The open_count is increased for every opener, that includes
2080 * the blkdev_get in dasd_scan_partitions. We are only interested
2081 * in the other openers.
2083 max_count = device->bdev ? 0 : -1;
2084 open_count = (int) atomic_read(&device->open_count);
2085 if (open_count > max_count) {
2087 printk (KERN_WARNING "Can't offline dasd device with "
2088 "open count = %i.\n",
2091 printk (KERN_WARNING "%s",
2092 "Can't offline dasd device due to internal "
2094 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
2095 dasd_put_device(device);
2098 dasd_set_target_state(device, DASD_STATE_NEW);
2099 /* dasd_delete_device destroys the device reference. */
2100 dasd_delete_device(device);
2106 dasd_generic_notify(struct ccw_device *cdev, int event)
2108 struct dasd_device *device;
2109 struct dasd_ccw_req *cqr;
2110 unsigned long flags;
2113 device = dasd_device_from_cdev(cdev);
2116 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
2121 /* First of all call extended error reporting. */
2122 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
2124 if (device->state < DASD_STATE_BASIC)
2126 /* Device is active. We want to keep it. */
2127 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
2128 list_for_each_entry(cqr, &device->ccw_queue, list)
2129 if (cqr->status == DASD_CQR_IN_IO)
2130 cqr->status = DASD_CQR_FAILED;
2131 device->stopped |= DASD_STOPPED_DC_EIO;
2133 list_for_each_entry(cqr, &device->ccw_queue, list)
2134 if (cqr->status == DASD_CQR_IN_IO) {
2135 cqr->status = DASD_CQR_QUEUED;
2138 device->stopped |= DASD_STOPPED_DC_WAIT;
2139 dasd_set_timer(device, 0);
2141 dasd_schedule_bh(device);
2145 /* FIXME: add a sanity check. */
2146 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
2147 dasd_schedule_bh(device);
2151 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2152 dasd_put_device(device);
2162 init_waitqueue_head(&dasd_init_waitq);
2163 init_waitqueue_head(&dasd_flush_wq);
2165 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2166 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long));
2167 if (dasd_debug_area == NULL) {
2171 debug_register_view(dasd_debug_area, &debug_sprintf_view);
2172 debug_set_level(dasd_debug_area, DBF_EMERG);
2174 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
2176 dasd_diag_discipline_pointer = NULL;
2178 rc = dasd_devmap_init();
2181 rc = dasd_gendisk_init();
2187 rc = dasd_eer_init();
2190 #ifdef CONFIG_PROC_FS
2191 rc = dasd_proc_init();
2198 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2203 module_init(dasd_init);
2204 module_exit(dasd_exit);
2206 EXPORT_SYMBOL(dasd_debug_area);
2207 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2209 EXPORT_SYMBOL(dasd_add_request_head);
2210 EXPORT_SYMBOL(dasd_add_request_tail);
2211 EXPORT_SYMBOL(dasd_cancel_req);
2212 EXPORT_SYMBOL(dasd_clear_timer);
2213 EXPORT_SYMBOL(dasd_enable_device);
2214 EXPORT_SYMBOL(dasd_int_handler);
2215 EXPORT_SYMBOL(dasd_kfree_request);
2216 EXPORT_SYMBOL(dasd_kick_device);
2217 EXPORT_SYMBOL(dasd_kmalloc_request);
2218 EXPORT_SYMBOL(dasd_schedule_bh);
2219 EXPORT_SYMBOL(dasd_set_target_state);
2220 EXPORT_SYMBOL(dasd_set_timer);
2221 EXPORT_SYMBOL(dasd_sfree_request);
2222 EXPORT_SYMBOL(dasd_sleep_on);
2223 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2224 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2225 EXPORT_SYMBOL(dasd_smalloc_request);
2226 EXPORT_SYMBOL(dasd_start_IO);
2227 EXPORT_SYMBOL(dasd_term_IO);
2229 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2230 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2231 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2232 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2233 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);