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;
40 void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
42 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
43 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
44 " Copyright 2000 IBM Corporation");
45 MODULE_SUPPORTED_DEVICE("dasd");
46 MODULE_LICENSE("GPL");
49 * SECTION: prototypes for static functions of dasd.c
51 static int dasd_alloc_queue(struct dasd_device * device);
52 static void dasd_setup_queue(struct dasd_device * device);
53 static void dasd_free_queue(struct dasd_device * device);
54 static void dasd_flush_request_queue(struct dasd_device *);
55 static 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);
402 /* let user-space know that the device status changed */
403 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
407 * Kick starter for devices that did not complete the startup/shutdown
408 * procedure or were sleeping because of a pending state.
409 * dasd_kick_device will schedule a call do do_kick_device to the kernel
413 do_kick_device(struct work_struct *work)
415 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
416 dasd_change_state(device);
417 dasd_schedule_bh(device);
418 dasd_put_device(device);
422 dasd_kick_device(struct dasd_device *device)
424 dasd_get_device(device);
425 /* queue call to dasd_kick_device to the kernel event daemon. */
426 schedule_work(&device->kick_work);
430 * Set the target state for a device and starts the state change.
433 dasd_set_target_state(struct dasd_device *device, int target)
435 /* If we are in probeonly mode stop at DASD_STATE_READY. */
436 if (dasd_probeonly && target > DASD_STATE_READY)
437 target = DASD_STATE_READY;
438 if (device->target != target) {
439 if (device->state == target)
440 wake_up(&dasd_init_waitq);
441 device->target = target;
443 if (device->state != device->target)
444 dasd_change_state(device);
448 * Enable devices with device numbers in [from..to].
451 _wait_for_device(struct dasd_device *device)
453 return (device->state == device->target);
457 dasd_enable_device(struct dasd_device *device)
459 dasd_set_target_state(device, DASD_STATE_ONLINE);
460 if (device->state <= DASD_STATE_KNOWN)
461 /* No discipline for device found. */
462 dasd_set_target_state(device, DASD_STATE_NEW);
463 /* Now wait for the devices to come up. */
464 wait_event(dasd_init_waitq, _wait_for_device(device));
468 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
470 #ifdef CONFIG_DASD_PROFILE
472 struct dasd_profile_info_t dasd_global_profile;
473 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
476 * Increments counter in global and local profiling structures.
478 #define dasd_profile_counter(value, counter, device) \
481 for (index = 0; index < 31 && value >> (2+index); index++); \
482 dasd_global_profile.counter[index]++; \
483 device->profile.counter[index]++; \
487 * Add profiling information for cqr before execution.
490 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
494 unsigned int counter;
496 if (dasd_profile_level != DASD_PROFILE_ON)
499 /* count the length of the chanq for statistics */
501 list_for_each(l, &device->ccw_queue)
504 dasd_global_profile.dasd_io_nr_req[counter]++;
505 device->profile.dasd_io_nr_req[counter]++;
509 * Add profiling information for cqr after execution.
512 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
515 long strtime, irqtime, endtime, tottime; /* in microseconds */
516 long tottimeps, sectors;
518 if (dasd_profile_level != DASD_PROFILE_ON)
521 sectors = req->nr_sectors;
522 if (!cqr->buildclk || !cqr->startclk ||
523 !cqr->stopclk || !cqr->endclk ||
527 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
528 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
529 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
530 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
531 tottimeps = tottime / sectors;
533 if (!dasd_global_profile.dasd_io_reqs)
534 memset(&dasd_global_profile, 0,
535 sizeof (struct dasd_profile_info_t));
536 dasd_global_profile.dasd_io_reqs++;
537 dasd_global_profile.dasd_io_sects += sectors;
539 if (!device->profile.dasd_io_reqs)
540 memset(&device->profile, 0,
541 sizeof (struct dasd_profile_info_t));
542 device->profile.dasd_io_reqs++;
543 device->profile.dasd_io_sects += sectors;
545 dasd_profile_counter(sectors, dasd_io_secs, device);
546 dasd_profile_counter(tottime, dasd_io_times, device);
547 dasd_profile_counter(tottimeps, dasd_io_timps, device);
548 dasd_profile_counter(strtime, dasd_io_time1, device);
549 dasd_profile_counter(irqtime, dasd_io_time2, device);
550 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
551 dasd_profile_counter(endtime, dasd_io_time3, device);
554 #define dasd_profile_start(device, cqr, req) do {} while (0)
555 #define dasd_profile_end(device, cqr, req) do {} while (0)
556 #endif /* CONFIG_DASD_PROFILE */
559 * Allocate memory for a channel program with 'cplength' channel
560 * command words and 'datasize' additional space. There are two
561 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
562 * memory and 2) dasd_smalloc_request uses the static ccw memory
563 * that gets allocated for each device.
565 struct dasd_ccw_req *
566 dasd_kmalloc_request(char *magic, int cplength, int datasize,
567 struct dasd_device * device)
569 struct dasd_ccw_req *cqr;
572 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
573 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
575 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
577 return ERR_PTR(-ENOMEM);
580 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
581 GFP_ATOMIC | GFP_DMA);
582 if (cqr->cpaddr == NULL) {
584 return ERR_PTR(-ENOMEM);
589 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
590 if (cqr->data == NULL) {
593 return ERR_PTR(-ENOMEM);
596 strncpy((char *) &cqr->magic, magic, 4);
597 ASCEBC((char *) &cqr->magic, 4);
598 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
599 dasd_get_device(device);
603 struct dasd_ccw_req *
604 dasd_smalloc_request(char *magic, int cplength, int datasize,
605 struct dasd_device * device)
608 struct dasd_ccw_req *cqr;
613 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
614 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
616 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
618 size += cplength * sizeof(struct ccw1);
621 spin_lock_irqsave(&device->mem_lock, flags);
622 cqr = (struct dasd_ccw_req *)
623 dasd_alloc_chunk(&device->ccw_chunks, size);
624 spin_unlock_irqrestore(&device->mem_lock, flags);
626 return ERR_PTR(-ENOMEM);
627 memset(cqr, 0, sizeof(struct dasd_ccw_req));
628 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
631 cqr->cpaddr = (struct ccw1 *) data;
632 data += cplength*sizeof(struct ccw1);
633 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
638 memset(cqr->data, 0, datasize);
640 strncpy((char *) &cqr->magic, magic, 4);
641 ASCEBC((char *) &cqr->magic, 4);
642 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
643 dasd_get_device(device);
648 * Free memory of a channel program. This function needs to free all the
649 * idal lists that might have been created by dasd_set_cda and the
650 * struct dasd_ccw_req itself.
653 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
658 /* Clear any idals used for the request. */
661 clear_normalized_cda(ccw);
662 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
667 dasd_put_device(device);
671 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
675 spin_lock_irqsave(&device->mem_lock, flags);
676 dasd_free_chunk(&device->ccw_chunks, cqr);
677 spin_unlock_irqrestore(&device->mem_lock, flags);
678 dasd_put_device(device);
682 * Check discipline magic in cqr.
685 dasd_check_cqr(struct dasd_ccw_req *cqr)
687 struct dasd_device *device;
691 device = cqr->device;
692 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
693 DEV_MESSAGE(KERN_WARNING, device,
694 " dasd_ccw_req 0x%08x magic doesn't match"
695 " discipline 0x%08x",
697 *(unsigned int *) device->discipline->name);
704 * Terminate the current i/o and set the request to clear_pending.
705 * Timer keeps device runnig.
706 * ccw_device_clear can fail if the i/o subsystem
710 dasd_term_IO(struct dasd_ccw_req * cqr)
712 struct dasd_device *device;
716 rc = dasd_check_cqr(cqr);
720 device = (struct dasd_device *) cqr->device;
721 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
722 rc = ccw_device_clear(device->cdev, (long) cqr);
724 case 0: /* termination successful */
726 cqr->status = DASD_CQR_CLEAR;
727 cqr->stopclk = get_clock();
729 DBF_DEV_EVENT(DBF_DEBUG, device,
730 "terminate cqr %p successful",
734 DBF_DEV_EVENT(DBF_ERR, device, "%s",
735 "device gone, retry");
738 DBF_DEV_EVENT(DBF_ERR, device, "%s",
743 DBF_DEV_EVENT(DBF_ERR, device, "%s",
744 "device busy, retry later");
747 DEV_MESSAGE(KERN_ERR, device,
748 "line %d unknown RC=%d, please "
749 "report to linux390@de.ibm.com",
756 dasd_schedule_bh(device);
761 * Start the i/o. This start_IO can fail if the channel is really busy.
762 * In that case set up a timer to start the request later.
765 dasd_start_IO(struct dasd_ccw_req * cqr)
767 struct dasd_device *device;
771 rc = dasd_check_cqr(cqr);
774 device = (struct dasd_device *) cqr->device;
775 if (cqr->retries < 0) {
776 DEV_MESSAGE(KERN_DEBUG, device,
777 "start_IO: request %p (%02x/%i) - no retry left.",
778 cqr, cqr->status, cqr->retries);
779 cqr->status = DASD_CQR_FAILED;
782 cqr->startclk = get_clock();
783 cqr->starttime = jiffies;
785 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
789 cqr->status = DASD_CQR_IN_IO;
790 DBF_DEV_EVENT(DBF_DEBUG, device,
791 "start_IO: request %p started successful",
795 DBF_DEV_EVENT(DBF_ERR, device, "%s",
796 "start_IO: device busy, retry later");
799 DBF_DEV_EVENT(DBF_ERR, device, "%s",
800 "start_IO: request timeout, retry later");
803 /* -EACCES indicates that the request used only a
804 * subset of the available pathes and all these
806 * Do a retry with all available pathes.
808 cqr->lpm = LPM_ANYPATH;
809 DBF_DEV_EVENT(DBF_ERR, device, "%s",
810 "start_IO: selected pathes gone,"
811 " retry on all pathes");
815 DBF_DEV_EVENT(DBF_ERR, device, "%s",
816 "start_IO: device gone, retry");
819 DEV_MESSAGE(KERN_ERR, device,
820 "line %d unknown RC=%d, please report"
821 " to linux390@de.ibm.com", __LINE__, rc);
829 * Timeout function for dasd devices. This is used for different purposes
830 * 1) missing interrupt handler for normal operation
831 * 2) delayed start of request where start_IO failed with -EBUSY
832 * 3) timeout for missing state change interrupts
833 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
834 * DASD_CQR_QUEUED for 2) and 3).
837 dasd_timeout_device(unsigned long ptr)
840 struct dasd_device *device;
842 device = (struct dasd_device *) ptr;
843 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
844 /* re-activate request queue */
845 device->stopped &= ~DASD_STOPPED_PENDING;
846 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
847 dasd_schedule_bh(device);
851 * Setup timeout for a device in jiffies.
854 dasd_set_timer(struct dasd_device *device, int expires)
857 if (timer_pending(&device->timer))
858 del_timer(&device->timer);
861 if (timer_pending(&device->timer)) {
862 if (mod_timer(&device->timer, jiffies + expires))
865 device->timer.function = dasd_timeout_device;
866 device->timer.data = (unsigned long) device;
867 device->timer.expires = jiffies + expires;
868 add_timer(&device->timer);
872 * Clear timeout for a device.
875 dasd_clear_timer(struct dasd_device *device)
877 if (timer_pending(&device->timer))
878 del_timer(&device->timer);
882 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
884 struct dasd_ccw_req *cqr;
885 struct dasd_device *device;
887 cqr = (struct dasd_ccw_req *) intparm;
888 if (cqr->status != DASD_CQR_IN_IO) {
890 "invalid status in handle_killed_request: "
891 "bus_id %s, status %02x",
892 cdev->dev.bus_id, cqr->status);
896 device = (struct dasd_device *) cqr->device;
897 if (device == NULL ||
898 device != dasd_device_from_cdev_locked(cdev) ||
899 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
900 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
905 /* Schedule request to be retried. */
906 cqr->status = DASD_CQR_QUEUED;
908 dasd_clear_timer(device);
909 dasd_schedule_bh(device);
910 dasd_put_device(device);
914 dasd_handle_state_change_pending(struct dasd_device *device)
916 struct dasd_ccw_req *cqr;
917 struct list_head *l, *n;
919 /* First of all start sense subsystem status request. */
920 dasd_eer_snss(device);
922 device->stopped &= ~DASD_STOPPED_PENDING;
924 /* restart all 'running' IO on queue */
925 list_for_each_safe(l, n, &device->ccw_queue) {
926 cqr = list_entry(l, struct dasd_ccw_req, list);
927 if (cqr->status == DASD_CQR_IN_IO) {
928 cqr->status = DASD_CQR_QUEUED;
931 dasd_clear_timer(device);
932 dasd_schedule_bh(device);
936 * Interrupt handler for "normal" ssch-io based dasd devices.
939 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
942 struct dasd_ccw_req *cqr, *next;
943 struct dasd_device *device;
944 unsigned long long now;
950 switch (PTR_ERR(irb)) {
952 dasd_handle_killed_request(cdev, intparm);
955 printk(KERN_WARNING"%s(%s): request timed out\n",
956 __FUNCTION__, cdev->dev.bus_id);
957 //FIXME - dasd uses own timeout interface...
960 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
961 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
968 DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
969 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
970 (unsigned int) intparm);
972 /* first of all check for state change pending interrupt */
973 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
974 if ((irb->scsw.dstat & mask) == mask) {
975 device = dasd_device_from_cdev_locked(cdev);
976 if (!IS_ERR(device)) {
977 dasd_handle_state_change_pending(device);
978 dasd_put_device(device);
983 cqr = (struct dasd_ccw_req *) intparm;
985 /* check for unsolicited interrupts */
988 "unsolicited interrupt received: bus_id %s",
993 device = (struct dasd_device *) cqr->device;
994 if (device == NULL ||
995 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
996 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
1001 /* Check for clear pending */
1002 if (cqr->status == DASD_CQR_CLEAR &&
1003 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
1004 cqr->status = DASD_CQR_QUEUED;
1005 dasd_clear_timer(device);
1006 wake_up(&dasd_flush_wq);
1007 dasd_schedule_bh(device);
1011 /* check status - the request might have been killed by dyn detach */
1012 if (cqr->status != DASD_CQR_IN_IO) {
1014 "invalid status: bus_id %s, status %02x",
1015 cdev->dev.bus_id, cqr->status);
1018 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
1019 ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
1021 /* Find out the appropriate era_action. */
1022 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
1023 era = dasd_era_fatal;
1024 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
1025 irb->scsw.cstat == 0 &&
1026 !irb->esw.esw0.erw.cons)
1027 era = dasd_era_none;
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));
1054 if (device->features & DASD_FEATURE_ERPLOG) {
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 test_bit(DASD_CQR_FLAGS_USE_ERP,
1134 erp_fn = device->discipline->
1138 dasd_default_erp_action(cqr);
1143 /* First of all call extended error reporting. */
1144 if (dasd_eer_enabled(device) &&
1145 cqr->status == DASD_CQR_FAILED) {
1146 dasd_eer_write(device, cqr, DASD_EER_FATALERROR);
1148 /* restart request */
1149 cqr->status = DASD_CQR_QUEUED;
1151 device->stopped |= DASD_STOPPED_QUIESCE;
1155 /* Process finished ERP request. */
1157 __dasd_process_erp(device, cqr);
1161 /* Rechain finished requests to final queue */
1162 cqr->endclk = get_clock();
1163 list_move_tail(&cqr->list, final_queue);
1168 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1170 struct request *req;
1171 struct dasd_device *device;
1174 req = (struct request *) data;
1175 device = cqr->device;
1176 dasd_profile_end(device, cqr, req);
1177 status = cqr->device->discipline->free_cp(cqr,req);
1178 spin_lock_irq(&device->request_queue_lock);
1179 dasd_end_request(req, status);
1180 spin_unlock_irq(&device->request_queue_lock);
1185 * Fetch requests from the block device queue.
1188 __dasd_process_blk_queue(struct dasd_device * device)
1190 request_queue_t *queue;
1191 struct request *req;
1192 struct dasd_ccw_req *cqr;
1195 queue = device->request_queue;
1196 /* No queue ? Then there is nothing to do. */
1201 * We requeue request from the block device queue to the ccw
1202 * queue only in two states. In state DASD_STATE_READY the
1203 * partition detection is done and we need to requeue requests
1204 * for that. State DASD_STATE_ONLINE is normal block device
1207 if (device->state != DASD_STATE_READY &&
1208 device->state != DASD_STATE_ONLINE)
1211 /* Now we try to fetch requests from the request queue */
1212 list_for_each_entry(cqr, &device->ccw_queue, list)
1213 if (cqr->status == DASD_CQR_QUEUED)
1215 while (!blk_queue_plugged(queue) &&
1216 elv_next_request(queue) &&
1217 nr_queued < DASD_CHANQ_MAX_SIZE) {
1218 req = elv_next_request(queue);
1220 if (device->features & DASD_FEATURE_READONLY &&
1221 rq_data_dir(req) == WRITE) {
1222 DBF_DEV_EVENT(DBF_ERR, device,
1223 "Rejecting write request %p",
1225 blkdev_dequeue_request(req);
1226 dasd_end_request(req, 0);
1229 if (device->stopped & DASD_STOPPED_DC_EIO) {
1230 blkdev_dequeue_request(req);
1231 dasd_end_request(req, 0);
1234 cqr = device->discipline->build_cp(device, req);
1236 if (PTR_ERR(cqr) == -ENOMEM)
1237 break; /* terminate request queue loop */
1238 if (PTR_ERR(cqr) == -EAGAIN) {
1240 * The current request cannot be build right
1241 * now, we have to try later. If this request
1242 * is the head-of-queue we stop the device
1245 if (!list_empty(&device->ccw_queue))
1247 device->stopped |= DASD_STOPPED_PENDING;
1248 dasd_set_timer(device, HZ/2);
1251 DBF_DEV_EVENT(DBF_ERR, device,
1252 "CCW creation failed (rc=%ld) "
1255 blkdev_dequeue_request(req);
1256 dasd_end_request(req, 0);
1259 cqr->callback = dasd_end_request_cb;
1260 cqr->callback_data = (void *) req;
1261 cqr->status = DASD_CQR_QUEUED;
1262 blkdev_dequeue_request(req);
1263 list_add_tail(&cqr->list, &device->ccw_queue);
1264 dasd_profile_start(device, cqr, req);
1270 * Take a look at the first request on the ccw queue and check
1271 * if it reached its expire time. If so, terminate the IO.
1274 __dasd_check_expire(struct dasd_device * device)
1276 struct dasd_ccw_req *cqr;
1278 if (list_empty(&device->ccw_queue))
1280 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1281 if ((cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) &&
1282 (time_after_eq(jiffies, cqr->expires + cqr->starttime))) {
1283 if (device->discipline->term_IO(cqr) != 0) {
1284 /* Hmpf, try again in 5 sec */
1285 dasd_set_timer(device, 5*HZ);
1286 DEV_MESSAGE(KERN_ERR, device,
1287 "internal error - timeout (%is) expired "
1288 "for cqr %p, termination failed, "
1290 (cqr->expires/HZ), cqr);
1292 DEV_MESSAGE(KERN_ERR, device,
1293 "internal error - timeout (%is) expired "
1294 "for cqr %p (%i retries left)",
1295 (cqr->expires/HZ), cqr, cqr->retries);
1301 * Take a look at the first request on the ccw queue and check
1302 * if it needs to be started.
1305 __dasd_start_head(struct dasd_device * device)
1307 struct dasd_ccw_req *cqr;
1310 if (list_empty(&device->ccw_queue))
1312 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1313 if (cqr->status != DASD_CQR_QUEUED)
1315 /* Non-temporary stop condition will trigger fail fast */
1316 if (device->stopped & ~DASD_STOPPED_PENDING &&
1317 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1318 (!dasd_eer_enabled(device))) {
1319 cqr->status = DASD_CQR_FAILED;
1320 dasd_schedule_bh(device);
1323 /* Don't try to start requests if device is stopped */
1324 if (device->stopped)
1327 rc = device->discipline->start_IO(cqr);
1329 dasd_set_timer(device, cqr->expires);
1330 else if (rc == -EACCES) {
1331 dasd_schedule_bh(device);
1333 /* Hmpf, try again in 1/2 sec */
1334 dasd_set_timer(device, 50);
1338 _wait_for_clear(struct dasd_ccw_req *cqr)
1340 return (cqr->status == DASD_CQR_QUEUED);
1344 * Remove all requests from the ccw queue (all = '1') or only block device
1345 * requests in case all = '0'.
1346 * Take care of the erp-chain (chained via cqr->refers) and remove either
1347 * the whole erp-chain or none of the erp-requests.
1348 * If a request is currently running, term_IO is called and the request
1349 * is re-queued. Prior to removing the terminated request we need to wait
1350 * for the clear-interrupt.
1351 * In case termination is not possible we stop processing and just finishing
1352 * the already moved requests.
1355 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1357 struct dasd_ccw_req *cqr, *orig, *n;
1360 struct list_head flush_queue;
1362 INIT_LIST_HEAD(&flush_queue);
1363 spin_lock_irq(get_ccwdev_lock(device->cdev));
1366 list_for_each_entry_safe(cqr, n, &device->ccw_queue, list) {
1367 /* get original request of erp request-chain */
1368 for (orig = cqr; orig->refers != NULL; orig = orig->refers);
1370 /* Flush all request or only block device requests? */
1371 if (all == 0 && cqr->callback != dasd_end_request_cb &&
1372 orig->callback != dasd_end_request_cb) {
1375 /* Check status and move request to flush_queue */
1376 switch (cqr->status) {
1377 case DASD_CQR_IN_IO:
1378 rc = device->discipline->term_IO(cqr);
1380 /* unable to terminate requeust */
1381 DEV_MESSAGE(KERN_ERR, device,
1382 "dasd flush ccw_queue is unable "
1383 " to terminate request %p",
1385 /* stop flush processing */
1389 case DASD_CQR_QUEUED:
1390 case DASD_CQR_ERROR:
1391 /* set request to FAILED */
1392 cqr->stopclk = get_clock();
1393 cqr->status = DASD_CQR_FAILED;
1395 default: /* do not touch the others */
1398 /* Rechain request (including erp chain) */
1399 for (i = 0; cqr != NULL; cqr = cqr->refers, i++) {
1400 cqr->endclk = get_clock();
1401 list_move_tail(&cqr->list, &flush_queue);
1404 /* moved more than one request - need to restart */
1409 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1410 /* Now call the callback function of flushed requests */
1412 list_for_each_entry_safe(cqr, n, &flush_queue, list) {
1413 if (cqr->status == DASD_CQR_CLEAR) {
1414 /* wait for clear interrupt! */
1415 wait_event(dasd_flush_wq, _wait_for_clear(cqr));
1416 cqr->status = DASD_CQR_FAILED;
1418 /* Process finished ERP request. */
1420 __dasd_process_erp(device, cqr);
1421 /* restart list_for_xx loop since dasd_process_erp
1422 * might remove multiple elements */
1425 /* call the callback function */
1426 cqr->endclk = get_clock();
1427 if (cqr->callback != NULL)
1428 (cqr->callback)(cqr, cqr->callback_data);
1434 * Acquire the device lock and process queues for the device.
1437 dasd_tasklet(struct dasd_device * device)
1439 struct list_head final_queue;
1440 struct list_head *l, *n;
1441 struct dasd_ccw_req *cqr;
1443 atomic_set (&device->tasklet_scheduled, 0);
1444 INIT_LIST_HEAD(&final_queue);
1445 spin_lock_irq(get_ccwdev_lock(device->cdev));
1446 /* Check expire time of first request on the ccw queue. */
1447 __dasd_check_expire(device);
1448 /* Finish off requests on ccw queue */
1449 __dasd_process_ccw_queue(device, &final_queue);
1450 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1451 /* Now call the callback function of requests with final status */
1452 list_for_each_safe(l, n, &final_queue) {
1453 cqr = list_entry(l, struct dasd_ccw_req, list);
1454 list_del_init(&cqr->list);
1455 if (cqr->callback != NULL)
1456 (cqr->callback)(cqr, cqr->callback_data);
1458 spin_lock_irq(&device->request_queue_lock);
1459 spin_lock(get_ccwdev_lock(device->cdev));
1460 /* Get new request from the block device request queue */
1461 __dasd_process_blk_queue(device);
1462 /* Now check if the head of the ccw queue needs to be started. */
1463 __dasd_start_head(device);
1464 spin_unlock(get_ccwdev_lock(device->cdev));
1465 spin_unlock_irq(&device->request_queue_lock);
1466 dasd_put_device(device);
1470 * Schedules a call to dasd_tasklet over the device tasklet.
1473 dasd_schedule_bh(struct dasd_device * device)
1475 /* Protect against rescheduling. */
1476 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
1478 dasd_get_device(device);
1479 tasklet_hi_schedule(&device->tasklet);
1483 * Queue a request to the head of the ccw_queue. Start the I/O if
1487 dasd_add_request_head(struct dasd_ccw_req *req)
1489 struct dasd_device *device;
1490 unsigned long flags;
1492 device = req->device;
1493 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1494 req->status = DASD_CQR_QUEUED;
1495 req->device = device;
1496 list_add(&req->list, &device->ccw_queue);
1497 /* let the bh start the request to keep them in order */
1498 dasd_schedule_bh(device);
1499 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1503 * Queue a request to the tail of the ccw_queue. Start the I/O if
1507 dasd_add_request_tail(struct dasd_ccw_req *req)
1509 struct dasd_device *device;
1510 unsigned long flags;
1512 device = req->device;
1513 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1514 req->status = DASD_CQR_QUEUED;
1515 req->device = device;
1516 list_add_tail(&req->list, &device->ccw_queue);
1517 /* let the bh start the request to keep them in order */
1518 dasd_schedule_bh(device);
1519 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1526 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1528 wake_up((wait_queue_head_t *) data);
1532 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1534 struct dasd_device *device;
1537 device = cqr->device;
1538 spin_lock_irq(get_ccwdev_lock(device->cdev));
1539 rc = ((cqr->status == DASD_CQR_DONE ||
1540 cqr->status == DASD_CQR_FAILED) &&
1541 list_empty(&cqr->list));
1542 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1547 * Attempts to start a special ccw queue and waits for its completion.
1550 dasd_sleep_on(struct dasd_ccw_req * cqr)
1552 wait_queue_head_t wait_q;
1553 struct dasd_device *device;
1556 device = cqr->device;
1557 spin_lock_irq(get_ccwdev_lock(device->cdev));
1559 init_waitqueue_head (&wait_q);
1560 cqr->callback = dasd_wakeup_cb;
1561 cqr->callback_data = (void *) &wait_q;
1562 cqr->status = DASD_CQR_QUEUED;
1563 list_add_tail(&cqr->list, &device->ccw_queue);
1565 /* let the bh start the request to keep them in order */
1566 dasd_schedule_bh(device);
1568 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1570 wait_event(wait_q, _wait_for_wakeup(cqr));
1572 /* Request status is either done or failed. */
1573 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1578 * Attempts to start a special ccw queue and wait interruptible
1579 * for its completion.
1582 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1584 wait_queue_head_t wait_q;
1585 struct dasd_device *device;
1588 device = cqr->device;
1589 spin_lock_irq(get_ccwdev_lock(device->cdev));
1591 init_waitqueue_head (&wait_q);
1592 cqr->callback = dasd_wakeup_cb;
1593 cqr->callback_data = (void *) &wait_q;
1594 cqr->status = DASD_CQR_QUEUED;
1595 list_add_tail(&cqr->list, &device->ccw_queue);
1597 /* let the bh start the request to keep them in order */
1598 dasd_schedule_bh(device);
1599 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1603 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1604 if (rc != -ERESTARTSYS) {
1605 /* Request is final (done or failed) */
1606 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1609 spin_lock_irq(get_ccwdev_lock(device->cdev));
1610 switch (cqr->status) {
1611 case DASD_CQR_IN_IO:
1612 /* terminate runnig cqr */
1613 if (device->discipline->term_IO) {
1615 device->discipline->term_IO(cqr);
1616 /* wait (non-interruptible) for final status
1617 * because signal ist still pending */
1618 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1619 wait_event(wait_q, _wait_for_wakeup(cqr));
1620 spin_lock_irq(get_ccwdev_lock(device->cdev));
1621 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1625 case DASD_CQR_QUEUED:
1627 list_del_init(&cqr->list);
1632 /* cqr with 'non-interruptable' status - just wait */
1635 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1641 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1642 * for eckd devices) the currently running request has to be terminated
1643 * and be put back to status queued, before the special request is added
1644 * to the head of the queue. Then the special request is waited on normally.
1647 _dasd_term_running_cqr(struct dasd_device *device)
1649 struct dasd_ccw_req *cqr;
1651 if (list_empty(&device->ccw_queue))
1653 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1654 return device->discipline->term_IO(cqr);
1658 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1660 wait_queue_head_t wait_q;
1661 struct dasd_device *device;
1664 device = cqr->device;
1665 spin_lock_irq(get_ccwdev_lock(device->cdev));
1666 rc = _dasd_term_running_cqr(device);
1668 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1672 init_waitqueue_head (&wait_q);
1673 cqr->callback = dasd_wakeup_cb;
1674 cqr->callback_data = (void *) &wait_q;
1675 cqr->status = DASD_CQR_QUEUED;
1676 list_add(&cqr->list, &device->ccw_queue);
1678 /* let the bh start the request to keep them in order */
1679 dasd_schedule_bh(device);
1681 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1683 wait_event(wait_q, _wait_for_wakeup(cqr));
1685 /* Request status is either done or failed. */
1686 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1691 * Cancels a request that was started with dasd_sleep_on_req.
1692 * This is useful to timeout requests. The request will be
1693 * terminated if it is currently in i/o.
1694 * Returns 1 if the request has been terminated.
1697 dasd_cancel_req(struct dasd_ccw_req *cqr)
1699 struct dasd_device *device = cqr->device;
1700 unsigned long flags;
1704 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1705 switch (cqr->status) {
1706 case DASD_CQR_QUEUED:
1707 /* request was not started - just set to failed */
1708 cqr->status = DASD_CQR_FAILED;
1710 case DASD_CQR_IN_IO:
1711 /* request in IO - terminate IO and release again */
1712 if (device->discipline->term_IO(cqr) != 0)
1713 /* what to do if unable to terminate ??????
1715 cqr->status = DASD_CQR_FAILED;
1716 cqr->stopclk = get_clock();
1720 case DASD_CQR_FAILED:
1721 /* already finished - do nothing */
1724 DEV_MESSAGE(KERN_ALERT, device,
1725 "invalid status %02x in request",
1730 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1731 dasd_schedule_bh(device);
1736 * SECTION: Block device operations (request queue, partitions, open, release).
1740 * Dasd request queue function. Called from ll_rw_blk.c
1743 do_dasd_request(request_queue_t * queue)
1745 struct dasd_device *device;
1747 device = (struct dasd_device *) queue->queuedata;
1748 spin_lock(get_ccwdev_lock(device->cdev));
1749 /* Get new request from the block device request queue */
1750 __dasd_process_blk_queue(device);
1751 /* Now check if the head of the ccw queue needs to be started. */
1752 __dasd_start_head(device);
1753 spin_unlock(get_ccwdev_lock(device->cdev));
1757 * Allocate and initialize request queue and default I/O scheduler.
1760 dasd_alloc_queue(struct dasd_device * device)
1764 device->request_queue = blk_init_queue(do_dasd_request,
1765 &device->request_queue_lock);
1766 if (device->request_queue == NULL)
1769 device->request_queue->queuedata = device;
1771 elevator_exit(device->request_queue->elevator);
1772 rc = elevator_init(device->request_queue, "deadline");
1774 blk_cleanup_queue(device->request_queue);
1781 * Allocate and initialize request queue.
1784 dasd_setup_queue(struct dasd_device * device)
1788 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1789 max = device->discipline->max_blocks << device->s2b_shift;
1790 blk_queue_max_sectors(device->request_queue, max);
1791 blk_queue_max_phys_segments(device->request_queue, -1L);
1792 blk_queue_max_hw_segments(device->request_queue, -1L);
1793 blk_queue_max_segment_size(device->request_queue, -1L);
1794 blk_queue_segment_boundary(device->request_queue, -1L);
1795 blk_queue_ordered(device->request_queue, QUEUE_ORDERED_TAG, NULL);
1799 * Deactivate and free request queue.
1802 dasd_free_queue(struct dasd_device * device)
1804 if (device->request_queue) {
1805 blk_cleanup_queue(device->request_queue);
1806 device->request_queue = NULL;
1811 * Flush request on the request queue.
1814 dasd_flush_request_queue(struct dasd_device * device)
1816 struct request *req;
1818 if (!device->request_queue)
1821 spin_lock_irq(&device->request_queue_lock);
1822 while ((req = elv_next_request(device->request_queue))) {
1823 blkdev_dequeue_request(req);
1824 dasd_end_request(req, 0);
1826 spin_unlock_irq(&device->request_queue_lock);
1830 dasd_open(struct inode *inp, struct file *filp)
1832 struct gendisk *disk = inp->i_bdev->bd_disk;
1833 struct dasd_device *device = disk->private_data;
1836 atomic_inc(&device->open_count);
1837 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1842 if (!try_module_get(device->discipline->owner)) {
1847 if (dasd_probeonly) {
1848 DEV_MESSAGE(KERN_INFO, device, "%s",
1849 "No access to device due to probeonly mode");
1854 if (device->state <= DASD_STATE_BASIC) {
1855 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1856 " Cannot open unrecognized device");
1864 module_put(device->discipline->owner);
1866 atomic_dec(&device->open_count);
1871 dasd_release(struct inode *inp, struct file *filp)
1873 struct gendisk *disk = inp->i_bdev->bd_disk;
1874 struct dasd_device *device = disk->private_data;
1876 atomic_dec(&device->open_count);
1877 module_put(device->discipline->owner);
1882 * Return disk geometry.
1885 dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1887 struct dasd_device *device;
1889 device = bdev->bd_disk->private_data;
1893 if (!device->discipline ||
1894 !device->discipline->fill_geometry)
1897 device->discipline->fill_geometry(device, geo);
1898 geo->start = get_start_sect(bdev) >> device->s2b_shift;
1902 struct block_device_operations
1903 dasd_device_operations = {
1904 .owner = THIS_MODULE,
1906 .release = dasd_release,
1907 .ioctl = dasd_ioctl,
1908 .compat_ioctl = dasd_compat_ioctl,
1909 .getgeo = dasd_getgeo,
1916 #ifdef CONFIG_PROC_FS
1920 if (dasd_page_cache != NULL) {
1921 kmem_cache_destroy(dasd_page_cache);
1922 dasd_page_cache = NULL;
1924 dasd_gendisk_exit();
1926 if (dasd_debug_area != NULL) {
1927 debug_unregister(dasd_debug_area);
1928 dasd_debug_area = NULL;
1933 * SECTION: common functions for ccw_driver use
1937 * Initial attempt at a probe function. this can be simplified once
1938 * the other detection code is gone.
1941 dasd_generic_probe (struct ccw_device *cdev,
1942 struct dasd_discipline *discipline)
1946 ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
1949 "dasd_generic_probe: could not set ccw-device options "
1950 "for %s\n", cdev->dev.bus_id);
1953 ret = dasd_add_sysfs_files(cdev);
1956 "dasd_generic_probe: could not add sysfs entries "
1957 "for %s\n", cdev->dev.bus_id);
1960 cdev->handler = &dasd_int_handler;
1963 * Automatically online either all dasd devices (dasd_autodetect)
1964 * or all devices specified with dasd= parameters during
1967 if ((dasd_get_feature(cdev, DASD_FEATURE_INITIAL_ONLINE) > 0 ) ||
1968 (dasd_autodetect && dasd_busid_known(cdev->dev.bus_id) != 0))
1969 ret = ccw_device_set_online(cdev);
1972 "dasd_generic_probe: could not initially online "
1973 "ccw-device %s\n", cdev->dev.bus_id);
1978 * This will one day be called from a global not_oper handler.
1979 * It is also used by driver_unregister during module unload.
1982 dasd_generic_remove (struct ccw_device *cdev)
1984 struct dasd_device *device;
1986 cdev->handler = NULL;
1988 dasd_remove_sysfs_files(cdev);
1989 device = dasd_device_from_cdev(cdev);
1992 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1993 /* Already doing offline processing */
1994 dasd_put_device(device);
1998 * This device is removed unconditionally. Set offline
1999 * flag to prevent dasd_open from opening it while it is
2000 * no quite down yet.
2002 dasd_set_target_state(device, DASD_STATE_NEW);
2003 /* dasd_delete_device destroys the device reference. */
2004 dasd_delete_device(device);
2008 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
2009 * the device is detected for the first time and is supposed to be used
2010 * or the user has started activation through sysfs.
2013 dasd_generic_set_online (struct ccw_device *cdev,
2014 struct dasd_discipline *base_discipline)
2017 struct dasd_discipline *discipline;
2018 struct dasd_device *device;
2021 /* first online clears initial online feature flag */
2022 dasd_set_feature(cdev, DASD_FEATURE_INITIAL_ONLINE, 0);
2023 device = dasd_create_device(cdev);
2025 return PTR_ERR(device);
2027 discipline = base_discipline;
2028 if (device->features & DASD_FEATURE_USEDIAG) {
2029 if (!dasd_diag_discipline_pointer) {
2030 printk (KERN_WARNING
2031 "dasd_generic couldn't online device %s "
2032 "- discipline DIAG not available\n",
2034 dasd_delete_device(device);
2037 discipline = dasd_diag_discipline_pointer;
2039 if (!try_module_get(base_discipline->owner)) {
2040 dasd_delete_device(device);
2043 if (!try_module_get(discipline->owner)) {
2044 module_put(base_discipline->owner);
2045 dasd_delete_device(device);
2048 device->base_discipline = base_discipline;
2049 device->discipline = discipline;
2051 rc = discipline->check_device(device);
2053 printk (KERN_WARNING
2054 "dasd_generic couldn't online device %s "
2055 "with discipline %s rc=%i\n",
2056 cdev->dev.bus_id, discipline->name, rc);
2057 module_put(discipline->owner);
2058 module_put(base_discipline->owner);
2059 dasd_delete_device(device);
2063 dasd_set_target_state(device, DASD_STATE_ONLINE);
2064 if (device->state <= DASD_STATE_KNOWN) {
2065 printk (KERN_WARNING
2066 "dasd_generic discipline not found for %s\n",
2069 dasd_set_target_state(device, DASD_STATE_NEW);
2070 dasd_delete_device(device);
2072 pr_debug("dasd_generic device %s found\n",
2075 /* FIXME: we have to wait for the root device but we don't want
2076 * to wait for each single device but for all at once. */
2077 wait_event(dasd_init_waitq, _wait_for_device(device));
2079 dasd_put_device(device);
2085 dasd_generic_set_offline (struct ccw_device *cdev)
2087 struct dasd_device *device;
2088 int max_count, open_count;
2090 device = dasd_device_from_cdev(cdev);
2092 return PTR_ERR(device);
2093 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
2094 /* Already doing offline processing */
2095 dasd_put_device(device);
2099 * We must make sure that this device is currently not in use.
2100 * The open_count is increased for every opener, that includes
2101 * the blkdev_get in dasd_scan_partitions. We are only interested
2102 * in the other openers.
2104 max_count = device->bdev ? 0 : -1;
2105 open_count = (int) atomic_read(&device->open_count);
2106 if (open_count > max_count) {
2108 printk (KERN_WARNING "Can't offline dasd device with "
2109 "open count = %i.\n",
2112 printk (KERN_WARNING "%s",
2113 "Can't offline dasd device due to internal "
2115 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
2116 dasd_put_device(device);
2119 dasd_set_target_state(device, DASD_STATE_NEW);
2120 /* dasd_delete_device destroys the device reference. */
2121 dasd_delete_device(device);
2127 dasd_generic_notify(struct ccw_device *cdev, int event)
2129 struct dasd_device *device;
2130 struct dasd_ccw_req *cqr;
2131 unsigned long flags;
2134 device = dasd_device_from_cdev(cdev);
2137 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
2142 /* First of all call extended error reporting. */
2143 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
2145 if (device->state < DASD_STATE_BASIC)
2147 /* Device is active. We want to keep it. */
2148 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
2149 list_for_each_entry(cqr, &device->ccw_queue, list)
2150 if (cqr->status == DASD_CQR_IN_IO)
2151 cqr->status = DASD_CQR_FAILED;
2152 device->stopped |= DASD_STOPPED_DC_EIO;
2154 list_for_each_entry(cqr, &device->ccw_queue, list)
2155 if (cqr->status == DASD_CQR_IN_IO) {
2156 cqr->status = DASD_CQR_QUEUED;
2159 device->stopped |= DASD_STOPPED_DC_WAIT;
2160 dasd_set_timer(device, 0);
2162 dasd_schedule_bh(device);
2166 /* FIXME: add a sanity check. */
2167 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
2168 dasd_schedule_bh(device);
2172 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2173 dasd_put_device(device);
2183 init_waitqueue_head(&dasd_init_waitq);
2184 init_waitqueue_head(&dasd_flush_wq);
2186 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2187 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long));
2188 if (dasd_debug_area == NULL) {
2192 debug_register_view(dasd_debug_area, &debug_sprintf_view);
2193 debug_set_level(dasd_debug_area, DBF_WARNING);
2195 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
2197 dasd_diag_discipline_pointer = NULL;
2199 rc = dasd_devmap_init();
2202 rc = dasd_gendisk_init();
2208 rc = dasd_eer_init();
2211 #ifdef CONFIG_PROC_FS
2212 rc = dasd_proc_init();
2219 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2224 module_init(dasd_init);
2225 module_exit(dasd_exit);
2227 EXPORT_SYMBOL(dasd_debug_area);
2228 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2230 EXPORT_SYMBOL(dasd_add_request_head);
2231 EXPORT_SYMBOL(dasd_add_request_tail);
2232 EXPORT_SYMBOL(dasd_cancel_req);
2233 EXPORT_SYMBOL(dasd_clear_timer);
2234 EXPORT_SYMBOL(dasd_enable_device);
2235 EXPORT_SYMBOL(dasd_int_handler);
2236 EXPORT_SYMBOL(dasd_kfree_request);
2237 EXPORT_SYMBOL(dasd_kick_device);
2238 EXPORT_SYMBOL(dasd_kmalloc_request);
2239 EXPORT_SYMBOL(dasd_schedule_bh);
2240 EXPORT_SYMBOL(dasd_set_target_state);
2241 EXPORT_SYMBOL(dasd_set_timer);
2242 EXPORT_SYMBOL(dasd_sfree_request);
2243 EXPORT_SYMBOL(dasd_sleep_on);
2244 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2245 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2246 EXPORT_SYMBOL(dasd_smalloc_request);
2247 EXPORT_SYMBOL(dasd_start_IO);
2248 EXPORT_SYMBOL(dasd_term_IO);
2250 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2251 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2252 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2253 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2254 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);