2 * File...........: linux/drivers/s390/block/dasd.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
12 #include <linux/config.h>
13 #include <linux/kmod.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <linux/ctype.h>
17 #include <linux/major.h>
18 #include <linux/slab.h>
19 #include <linux/buffer_head.h>
20 #include <linux/hdreg.h>
22 #include <asm/ccwdev.h>
23 #include <asm/ebcdic.h>
24 #include <asm/idals.h>
25 #include <asm/todclk.h>
28 #define PRINTK_HEADER "dasd:"
32 * SECTION: Constant definitions to be used within this file
34 #define DASD_CHANQ_MAX_SIZE 4
37 * SECTION: exported variables of dasd.c
39 debug_info_t *dasd_debug_area;
40 struct dasd_discipline *dasd_diag_discipline_pointer;
42 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
43 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
44 " Copyright 2000 IBM Corporation");
45 MODULE_SUPPORTED_DEVICE("dasd");
46 MODULE_PARM(dasd, "1-" __MODULE_STRING(256) "s");
47 MODULE_LICENSE("GPL");
50 * SECTION: prototypes for static functions of dasd.c
52 static int dasd_alloc_queue(struct dasd_device * device);
53 static void dasd_setup_queue(struct dasd_device * device);
54 static void dasd_free_queue(struct dasd_device * device);
55 static void dasd_flush_request_queue(struct dasd_device *);
56 static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
57 static void dasd_flush_ccw_queue(struct dasd_device *, int);
58 static void dasd_tasklet(struct dasd_device *);
59 static void do_kick_device(void *data);
62 * SECTION: Operations on the device structure.
64 static wait_queue_head_t dasd_init_waitq;
67 * Allocate memory for a new device structure.
70 dasd_alloc_device(void)
72 struct dasd_device *device;
74 device = kzalloc(sizeof (struct dasd_device), GFP_ATOMIC);
76 return ERR_PTR(-ENOMEM);
77 /* open_count = 0 means device online but not in use */
78 atomic_set(&device->open_count, -1);
80 /* Get two pages for normal block device operations. */
81 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
82 if (device->ccw_mem == NULL) {
84 return ERR_PTR(-ENOMEM);
86 /* Get one page for error recovery. */
87 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
88 if (device->erp_mem == NULL) {
89 free_pages((unsigned long) device->ccw_mem, 1);
91 return ERR_PTR(-ENOMEM);
94 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
95 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
96 spin_lock_init(&device->mem_lock);
97 spin_lock_init(&device->request_queue_lock);
98 atomic_set (&device->tasklet_scheduled, 0);
99 tasklet_init(&device->tasklet,
100 (void (*)(unsigned long)) dasd_tasklet,
101 (unsigned long) device);
102 INIT_LIST_HEAD(&device->ccw_queue);
103 init_timer(&device->timer);
104 INIT_WORK(&device->kick_work, do_kick_device, device);
105 device->state = DASD_STATE_NEW;
106 device->target = DASD_STATE_NEW;
112 * Free memory of a device structure.
115 dasd_free_device(struct dasd_device *device)
117 kfree(device->private);
118 free_page((unsigned long) device->erp_mem);
119 free_pages((unsigned long) device->ccw_mem, 1);
124 * Make a new device known to the system.
127 dasd_state_new_to_known(struct dasd_device *device)
132 * As long as the device is not in state DASD_STATE_NEW we want to
133 * keep the reference count > 0.
135 dasd_get_device(device);
137 rc = dasd_alloc_queue(device);
139 dasd_put_device(device);
143 device->state = DASD_STATE_KNOWN;
148 * Let the system forget about a device.
151 dasd_state_known_to_new(struct dasd_device * device)
153 /* Disable extended error reporting for this device. */
154 dasd_eer_disable(device);
155 /* Forget the discipline information. */
156 if (device->discipline)
157 module_put(device->discipline->owner);
158 device->discipline = NULL;
159 if (device->base_discipline)
160 module_put(device->base_discipline->owner);
161 device->base_discipline = NULL;
162 device->state = DASD_STATE_NEW;
164 dasd_free_queue(device);
166 /* Give up reference we took in dasd_state_new_to_known. */
167 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)
200 dasd_gendisk_free(device);
201 dasd_flush_ccw_queue(device, 1);
202 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
203 if (device->debug_area != NULL) {
204 debug_unregister(device->debug_area);
205 device->debug_area = NULL;
207 device->state = DASD_STATE_KNOWN;
211 * Do the initial analysis. The do_analysis function may return
212 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
213 * until the discipline decides to continue the startup sequence
214 * by calling the function dasd_change_state. The eckd disciplines
215 * uses this to start a ccw that detects the format. The completion
216 * interrupt for this detection ccw uses the kernel event daemon to
217 * trigger the call to dasd_change_state. All this is done in the
218 * discipline code, see dasd_eckd.c.
219 * After the analysis ccw is done (do_analysis returned 0) the block
221 * In case the analysis returns an error, the device setup is stopped
222 * (a fake disk was already added to allow formatting).
225 dasd_state_basic_to_ready(struct dasd_device * device)
230 if (device->discipline->do_analysis != NULL)
231 rc = device->discipline->do_analysis(device);
234 device->state = DASD_STATE_UNFMT;
237 /* make disk known with correct capacity */
238 dasd_setup_queue(device);
239 set_capacity(device->gdp, device->blocks << device->s2b_shift);
240 device->state = DASD_STATE_READY;
241 rc = dasd_scan_partitions(device);
243 device->state = DASD_STATE_BASIC;
248 * Remove device from block device layer. Destroy dirty buffers.
249 * Forget format information. Check if the target level is basic
250 * and if it is create fake disk for formatting.
253 dasd_state_ready_to_basic(struct dasd_device * device)
255 dasd_flush_ccw_queue(device, 0);
256 dasd_destroy_partitions(device);
257 dasd_flush_request_queue(device);
259 device->bp_block = 0;
260 device->s2b_shift = 0;
261 device->state = DASD_STATE_BASIC;
268 dasd_state_unfmt_to_basic(struct dasd_device * device)
270 device->state = DASD_STATE_BASIC;
274 * Make the device online and schedule the bottom half to start
275 * the requeueing of requests from the linux request queue to the
279 dasd_state_ready_to_online(struct dasd_device * device)
281 device->state = DASD_STATE_ONLINE;
282 dasd_schedule_bh(device);
287 * Stop the requeueing of requests again.
290 dasd_state_online_to_ready(struct dasd_device * device)
292 device->state = DASD_STATE_READY;
296 * Device startup state changes.
299 dasd_increase_state(struct dasd_device *device)
304 if (device->state == DASD_STATE_NEW &&
305 device->target >= DASD_STATE_KNOWN)
306 rc = dasd_state_new_to_known(device);
309 device->state == DASD_STATE_KNOWN &&
310 device->target >= DASD_STATE_BASIC)
311 rc = dasd_state_known_to_basic(device);
314 device->state == DASD_STATE_BASIC &&
315 device->target >= DASD_STATE_READY)
316 rc = dasd_state_basic_to_ready(device);
319 device->state == DASD_STATE_READY &&
320 device->target >= DASD_STATE_ONLINE)
321 rc = dasd_state_ready_to_online(device);
327 * Device shutdown state changes.
330 dasd_decrease_state(struct dasd_device *device)
332 if (device->state == DASD_STATE_ONLINE &&
333 device->target <= DASD_STATE_READY)
334 dasd_state_online_to_ready(device);
336 if (device->state == DASD_STATE_READY &&
337 device->target <= DASD_STATE_BASIC)
338 dasd_state_ready_to_basic(device);
340 if (device->state == DASD_STATE_UNFMT &&
341 device->target <= DASD_STATE_BASIC)
342 dasd_state_unfmt_to_basic(device);
344 if (device->state == DASD_STATE_BASIC &&
345 device->target <= DASD_STATE_KNOWN)
346 dasd_state_basic_to_known(device);
348 if (device->state == DASD_STATE_KNOWN &&
349 device->target <= DASD_STATE_NEW)
350 dasd_state_known_to_new(device);
356 * This is the main startup/shutdown routine.
359 dasd_change_state(struct dasd_device *device)
363 if (device->state == device->target)
364 /* Already where we want to go today... */
366 if (device->state < device->target)
367 rc = dasd_increase_state(device);
369 rc = dasd_decrease_state(device);
370 if (rc && rc != -EAGAIN)
371 device->target = device->state;
373 if (device->state == device->target)
374 wake_up(&dasd_init_waitq);
378 * Kick starter for devices that did not complete the startup/shutdown
379 * procedure or were sleeping because of a pending state.
380 * dasd_kick_device will schedule a call do do_kick_device to the kernel
384 do_kick_device(void *data)
386 struct dasd_device *device;
388 device = (struct dasd_device *) data;
389 dasd_change_state(device);
390 dasd_schedule_bh(device);
391 dasd_put_device(device);
395 dasd_kick_device(struct dasd_device *device)
397 dasd_get_device(device);
398 /* queue call to dasd_kick_device to the kernel event daemon. */
399 schedule_work(&device->kick_work);
403 * Set the target state for a device and starts the state change.
406 dasd_set_target_state(struct dasd_device *device, int target)
408 /* If we are in probeonly mode stop at DASD_STATE_READY. */
409 if (dasd_probeonly && target > DASD_STATE_READY)
410 target = DASD_STATE_READY;
411 if (device->target != target) {
412 if (device->state == target)
413 wake_up(&dasd_init_waitq);
414 device->target = target;
416 if (device->state != device->target)
417 dasd_change_state(device);
421 * Enable devices with device numbers in [from..to].
424 _wait_for_device(struct dasd_device *device)
426 return (device->state == device->target);
430 dasd_enable_device(struct dasd_device *device)
432 dasd_set_target_state(device, DASD_STATE_ONLINE);
433 if (device->state <= DASD_STATE_KNOWN)
434 /* No discipline for device found. */
435 dasd_set_target_state(device, DASD_STATE_NEW);
436 /* Now wait for the devices to come up. */
437 wait_event(dasd_init_waitq, _wait_for_device(device));
441 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
443 #ifdef CONFIG_DASD_PROFILE
445 struct dasd_profile_info_t dasd_global_profile;
446 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
449 * Increments counter in global and local profiling structures.
451 #define dasd_profile_counter(value, counter, device) \
454 for (index = 0; index < 31 && value >> (2+index); index++); \
455 dasd_global_profile.counter[index]++; \
456 device->profile.counter[index]++; \
460 * Add profiling information for cqr before execution.
463 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
467 unsigned int counter;
469 if (dasd_profile_level != DASD_PROFILE_ON)
472 /* count the length of the chanq for statistics */
474 list_for_each(l, &device->ccw_queue)
477 dasd_global_profile.dasd_io_nr_req[counter]++;
478 device->profile.dasd_io_nr_req[counter]++;
482 * Add profiling information for cqr after execution.
485 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
488 long strtime, irqtime, endtime, tottime; /* in microseconds */
489 long tottimeps, sectors;
491 if (dasd_profile_level != DASD_PROFILE_ON)
494 sectors = req->nr_sectors;
495 if (!cqr->buildclk || !cqr->startclk ||
496 !cqr->stopclk || !cqr->endclk ||
500 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
501 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
502 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
503 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
504 tottimeps = tottime / sectors;
506 if (!dasd_global_profile.dasd_io_reqs)
507 memset(&dasd_global_profile, 0,
508 sizeof (struct dasd_profile_info_t));
509 dasd_global_profile.dasd_io_reqs++;
510 dasd_global_profile.dasd_io_sects += sectors;
512 if (!device->profile.dasd_io_reqs)
513 memset(&device->profile, 0,
514 sizeof (struct dasd_profile_info_t));
515 device->profile.dasd_io_reqs++;
516 device->profile.dasd_io_sects += sectors;
518 dasd_profile_counter(sectors, dasd_io_secs, device);
519 dasd_profile_counter(tottime, dasd_io_times, device);
520 dasd_profile_counter(tottimeps, dasd_io_timps, device);
521 dasd_profile_counter(strtime, dasd_io_time1, device);
522 dasd_profile_counter(irqtime, dasd_io_time2, device);
523 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
524 dasd_profile_counter(endtime, dasd_io_time3, device);
527 #define dasd_profile_start(device, cqr, req) do {} while (0)
528 #define dasd_profile_end(device, cqr, req) do {} while (0)
529 #endif /* CONFIG_DASD_PROFILE */
532 * Allocate memory for a channel program with 'cplength' channel
533 * command words and 'datasize' additional space. There are two
534 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
535 * memory and 2) dasd_smalloc_request uses the static ccw memory
536 * that gets allocated for each device.
538 struct dasd_ccw_req *
539 dasd_kmalloc_request(char *magic, int cplength, int datasize,
540 struct dasd_device * device)
542 struct dasd_ccw_req *cqr;
545 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
546 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
548 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
550 return ERR_PTR(-ENOMEM);
553 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
554 GFP_ATOMIC | GFP_DMA);
555 if (cqr->cpaddr == NULL) {
557 return ERR_PTR(-ENOMEM);
562 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
563 if (cqr->data == NULL) {
566 return ERR_PTR(-ENOMEM);
569 strncpy((char *) &cqr->magic, magic, 4);
570 ASCEBC((char *) &cqr->magic, 4);
571 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
572 dasd_get_device(device);
576 struct dasd_ccw_req *
577 dasd_smalloc_request(char *magic, int cplength, int datasize,
578 struct dasd_device * device)
581 struct dasd_ccw_req *cqr;
586 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
587 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
589 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
591 size += cplength * sizeof(struct ccw1);
594 spin_lock_irqsave(&device->mem_lock, flags);
595 cqr = (struct dasd_ccw_req *)
596 dasd_alloc_chunk(&device->ccw_chunks, size);
597 spin_unlock_irqrestore(&device->mem_lock, flags);
599 return ERR_PTR(-ENOMEM);
600 memset(cqr, 0, sizeof(struct dasd_ccw_req));
601 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
604 cqr->cpaddr = (struct ccw1 *) data;
605 data += cplength*sizeof(struct ccw1);
606 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
611 memset(cqr->data, 0, datasize);
613 strncpy((char *) &cqr->magic, magic, 4);
614 ASCEBC((char *) &cqr->magic, 4);
615 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
616 dasd_get_device(device);
621 * Free memory of a channel program. This function needs to free all the
622 * idal lists that might have been created by dasd_set_cda and the
623 * struct dasd_ccw_req itself.
626 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
631 /* Clear any idals used for the request. */
634 clear_normalized_cda(ccw);
635 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
640 dasd_put_device(device);
644 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
648 spin_lock_irqsave(&device->mem_lock, flags);
649 dasd_free_chunk(&device->ccw_chunks, cqr);
650 spin_unlock_irqrestore(&device->mem_lock, flags);
651 dasd_put_device(device);
655 * Check discipline magic in cqr.
658 dasd_check_cqr(struct dasd_ccw_req *cqr)
660 struct dasd_device *device;
664 device = cqr->device;
665 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
666 DEV_MESSAGE(KERN_WARNING, device,
667 " dasd_ccw_req 0x%08x magic doesn't match"
668 " discipline 0x%08x",
670 *(unsigned int *) device->discipline->name);
677 * Terminate the current i/o and set the request to clear_pending.
678 * Timer keeps device runnig.
679 * ccw_device_clear can fail if the i/o subsystem
683 dasd_term_IO(struct dasd_ccw_req * cqr)
685 struct dasd_device *device;
689 rc = dasd_check_cqr(cqr);
693 device = (struct dasd_device *) cqr->device;
694 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
695 rc = ccw_device_clear(device->cdev, (long) cqr);
697 case 0: /* termination successful */
699 cqr->status = DASD_CQR_CLEAR;
700 cqr->stopclk = get_clock();
701 DBF_DEV_EVENT(DBF_DEBUG, device,
702 "terminate cqr %p successful",
706 DBF_DEV_EVENT(DBF_ERR, device, "%s",
707 "device gone, retry");
710 DBF_DEV_EVENT(DBF_ERR, device, "%s",
715 DBF_DEV_EVENT(DBF_ERR, device, "%s",
716 "device busy, retry later");
719 DEV_MESSAGE(KERN_ERR, device,
720 "line %d unknown RC=%d, please "
721 "report to linux390@de.ibm.com",
728 dasd_schedule_bh(device);
733 * Start the i/o. This start_IO can fail if the channel is really busy.
734 * In that case set up a timer to start the request later.
737 dasd_start_IO(struct dasd_ccw_req * cqr)
739 struct dasd_device *device;
743 rc = dasd_check_cqr(cqr);
746 device = (struct dasd_device *) cqr->device;
747 if (cqr->retries < 0) {
748 DEV_MESSAGE(KERN_DEBUG, device,
749 "start_IO: request %p (%02x/%i) - no retry left.",
750 cqr, cqr->status, cqr->retries);
751 cqr->status = DASD_CQR_FAILED;
754 cqr->startclk = get_clock();
755 cqr->starttime = jiffies;
757 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
761 cqr->status = DASD_CQR_IN_IO;
762 DBF_DEV_EVENT(DBF_DEBUG, device,
763 "start_IO: request %p started successful",
767 DBF_DEV_EVENT(DBF_ERR, device, "%s",
768 "start_IO: device busy, retry later");
771 DBF_DEV_EVENT(DBF_ERR, device, "%s",
772 "start_IO: request timeout, retry later");
775 /* -EACCES indicates that the request used only a
776 * subset of the available pathes and all these
778 * Do a retry with all available pathes.
780 cqr->lpm = LPM_ANYPATH;
781 DBF_DEV_EVENT(DBF_ERR, device, "%s",
782 "start_IO: selected pathes gone,"
783 " retry on all pathes");
787 DBF_DEV_EVENT(DBF_ERR, device, "%s",
788 "start_IO: device gone, retry");
791 DEV_MESSAGE(KERN_ERR, device,
792 "line %d unknown RC=%d, please report"
793 " to linux390@de.ibm.com", __LINE__, rc);
801 * Timeout function for dasd devices. This is used for different purposes
802 * 1) missing interrupt handler for normal operation
803 * 2) delayed start of request where start_IO failed with -EBUSY
804 * 3) timeout for missing state change interrupts
805 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
806 * DASD_CQR_QUEUED for 2) and 3).
809 dasd_timeout_device(unsigned long ptr)
812 struct dasd_device *device;
814 device = (struct dasd_device *) ptr;
815 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
816 /* re-activate request queue */
817 device->stopped &= ~DASD_STOPPED_PENDING;
818 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
819 dasd_schedule_bh(device);
823 * Setup timeout for a device in jiffies.
826 dasd_set_timer(struct dasd_device *device, int expires)
829 if (timer_pending(&device->timer))
830 del_timer(&device->timer);
833 if (timer_pending(&device->timer)) {
834 if (mod_timer(&device->timer, jiffies + expires))
837 device->timer.function = dasd_timeout_device;
838 device->timer.data = (unsigned long) device;
839 device->timer.expires = jiffies + expires;
840 add_timer(&device->timer);
844 * Clear timeout for a device.
847 dasd_clear_timer(struct dasd_device *device)
849 if (timer_pending(&device->timer))
850 del_timer(&device->timer);
854 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
856 struct dasd_ccw_req *cqr;
857 struct dasd_device *device;
859 cqr = (struct dasd_ccw_req *) intparm;
860 if (cqr->status != DASD_CQR_IN_IO) {
862 "invalid status in handle_killed_request: "
863 "bus_id %s, status %02x",
864 cdev->dev.bus_id, cqr->status);
868 device = (struct dasd_device *) cqr->device;
869 if (device == NULL ||
870 device != dasd_device_from_cdev(cdev) ||
871 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
872 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
877 /* Schedule request to be retried. */
878 cqr->status = DASD_CQR_QUEUED;
880 dasd_clear_timer(device);
881 dasd_schedule_bh(device);
882 dasd_put_device(device);
886 dasd_handle_state_change_pending(struct dasd_device *device)
888 struct dasd_ccw_req *cqr;
889 struct list_head *l, *n;
891 /* First of all start sense subsystem status request. */
892 dasd_eer_snss(device);
894 device->stopped &= ~DASD_STOPPED_PENDING;
896 /* restart all 'running' IO on queue */
897 list_for_each_safe(l, n, &device->ccw_queue) {
898 cqr = list_entry(l, struct dasd_ccw_req, list);
899 if (cqr->status == DASD_CQR_IN_IO) {
900 cqr->status = DASD_CQR_QUEUED;
903 dasd_clear_timer(device);
904 dasd_schedule_bh(device);
908 * Interrupt handler for "normal" ssch-io based dasd devices.
911 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
914 struct dasd_ccw_req *cqr, *next;
915 struct dasd_device *device;
916 unsigned long long now;
922 switch (PTR_ERR(irb)) {
924 dasd_handle_killed_request(cdev, intparm);
927 printk(KERN_WARNING"%s(%s): request timed out\n",
928 __FUNCTION__, cdev->dev.bus_id);
929 //FIXME - dasd uses own timeout interface...
932 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
933 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
940 DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
941 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
942 (unsigned int) intparm);
944 /* first of all check for state change pending interrupt */
945 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
946 if ((irb->scsw.dstat & mask) == mask) {
947 device = dasd_device_from_cdev(cdev);
948 if (!IS_ERR(device)) {
949 dasd_handle_state_change_pending(device);
950 dasd_put_device(device);
955 cqr = (struct dasd_ccw_req *) intparm;
957 /* check for unsolicited interrupts */
960 "unsolicited interrupt received: bus_id %s",
965 device = (struct dasd_device *) cqr->device;
966 if (device == NULL ||
967 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
968 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
973 /* Check for clear pending */
974 if (cqr->status == DASD_CQR_CLEAR &&
975 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
976 cqr->status = DASD_CQR_QUEUED;
977 dasd_clear_timer(device);
978 dasd_schedule_bh(device);
982 /* check status - the request might have been killed by dyn detach */
983 if (cqr->status != DASD_CQR_IN_IO) {
985 "invalid status: bus_id %s, status %02x",
986 cdev->dev.bus_id, cqr->status);
989 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
990 ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
992 /* Find out the appropriate era_action. */
993 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
994 era = dasd_era_fatal;
995 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
996 irb->scsw.cstat == 0 &&
997 !irb->esw.esw0.erw.cons)
999 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
1000 era = dasd_era_fatal; /* don't recover this request */
1001 else if (irb->esw.esw0.erw.cons)
1002 era = device->discipline->examine_error(cqr, irb);
1004 era = dasd_era_recover;
1006 DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
1008 if (era == dasd_era_none) {
1009 cqr->status = DASD_CQR_DONE;
1011 /* Start first request on queue if possible -> fast_io. */
1012 if (cqr->list.next != &device->ccw_queue) {
1013 next = list_entry(cqr->list.next,
1014 struct dasd_ccw_req, list);
1015 if ((next->status == DASD_CQR_QUEUED) &&
1016 (!device->stopped)) {
1017 if (device->discipline->start_IO(next) == 0)
1018 expires = next->expires;
1020 DEV_MESSAGE(KERN_DEBUG, device, "%s",
1021 "Interrupt fastpath "
1025 } else { /* error */
1026 memcpy(&cqr->irb, irb, sizeof (struct irb));
1028 /* dump sense data */
1029 dasd_log_sense(cqr, irb);
1032 case dasd_era_fatal:
1033 cqr->status = DASD_CQR_FAILED;
1036 case dasd_era_recover:
1037 cqr->status = DASD_CQR_ERROR;
1044 dasd_set_timer(device, expires);
1046 dasd_clear_timer(device);
1047 dasd_schedule_bh(device);
1051 * posts the buffer_cache about a finalized request
1054 dasd_end_request(struct request *req, int uptodate)
1056 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1058 add_disk_randomness(req->rq_disk);
1059 end_that_request_last(req, uptodate);
1063 * Process finished error recovery ccw.
1066 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1068 dasd_erp_fn_t erp_fn;
1070 if (cqr->status == DASD_CQR_DONE)
1071 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1073 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1074 erp_fn = device->discipline->erp_postaction(cqr);
1079 * Process ccw request queue.
1082 __dasd_process_ccw_queue(struct dasd_device * device,
1083 struct list_head *final_queue)
1085 struct list_head *l, *n;
1086 struct dasd_ccw_req *cqr;
1087 dasd_erp_fn_t erp_fn;
1090 /* Process request with final status. */
1091 list_for_each_safe(l, n, &device->ccw_queue) {
1092 cqr = list_entry(l, struct dasd_ccw_req, list);
1093 /* Stop list processing at the first non-final request. */
1094 if (cqr->status != DASD_CQR_DONE &&
1095 cqr->status != DASD_CQR_FAILED &&
1096 cqr->status != DASD_CQR_ERROR)
1098 /* Process requests with DASD_CQR_ERROR */
1099 if (cqr->status == DASD_CQR_ERROR) {
1100 if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1101 cqr->status = DASD_CQR_FAILED;
1102 cqr->stopclk = get_clock();
1104 if (cqr->irb.esw.esw0.erw.cons) {
1105 erp_fn = device->discipline->
1109 dasd_default_erp_action(cqr);
1114 /* First of all call extended error reporting. */
1115 if (dasd_eer_enabled(device) &&
1116 cqr->status == DASD_CQR_FAILED) {
1117 dasd_eer_write(device, cqr, DASD_EER_FATALERROR);
1119 /* restart request */
1120 cqr->status = DASD_CQR_QUEUED;
1122 device->stopped |= DASD_STOPPED_QUIESCE;
1126 /* Process finished ERP request. */
1128 __dasd_process_erp(device, cqr);
1132 /* Rechain finished requests to final queue */
1133 cqr->endclk = get_clock();
1134 list_move_tail(&cqr->list, final_queue);
1139 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1141 struct request *req;
1142 struct dasd_device *device;
1145 req = (struct request *) data;
1146 device = cqr->device;
1147 dasd_profile_end(device, cqr, req);
1148 status = cqr->device->discipline->free_cp(cqr,req);
1149 spin_lock_irq(&device->request_queue_lock);
1150 dasd_end_request(req, status);
1151 spin_unlock_irq(&device->request_queue_lock);
1156 * Fetch requests from the block device queue.
1159 __dasd_process_blk_queue(struct dasd_device * device)
1161 request_queue_t *queue;
1162 struct request *req;
1163 struct dasd_ccw_req *cqr;
1166 queue = device->request_queue;
1167 /* No queue ? Then there is nothing to do. */
1172 * We requeue request from the block device queue to the ccw
1173 * queue only in two states. In state DASD_STATE_READY the
1174 * partition detection is done and we need to requeue requests
1175 * for that. State DASD_STATE_ONLINE is normal block device
1178 if (device->state != DASD_STATE_READY &&
1179 device->state != DASD_STATE_ONLINE)
1182 /* Now we try to fetch requests from the request queue */
1183 list_for_each_entry(cqr, &device->ccw_queue, list)
1184 if (cqr->status == DASD_CQR_QUEUED)
1186 while (!blk_queue_plugged(queue) &&
1187 elv_next_request(queue) &&
1188 nr_queued < DASD_CHANQ_MAX_SIZE) {
1189 req = elv_next_request(queue);
1191 if (device->features & DASD_FEATURE_READONLY &&
1192 rq_data_dir(req) == WRITE) {
1193 DBF_DEV_EVENT(DBF_ERR, device,
1194 "Rejecting write request %p",
1196 blkdev_dequeue_request(req);
1197 dasd_end_request(req, 0);
1200 if (device->stopped & DASD_STOPPED_DC_EIO) {
1201 blkdev_dequeue_request(req);
1202 dasd_end_request(req, 0);
1205 cqr = device->discipline->build_cp(device, req);
1207 if (PTR_ERR(cqr) == -ENOMEM)
1208 break; /* terminate request queue loop */
1209 DBF_DEV_EVENT(DBF_ERR, device,
1210 "CCW creation failed (rc=%ld) "
1213 blkdev_dequeue_request(req);
1214 dasd_end_request(req, 0);
1217 cqr->callback = dasd_end_request_cb;
1218 cqr->callback_data = (void *) req;
1219 cqr->status = DASD_CQR_QUEUED;
1220 blkdev_dequeue_request(req);
1221 list_add_tail(&cqr->list, &device->ccw_queue);
1222 dasd_profile_start(device, cqr, req);
1228 * Take a look at the first request on the ccw queue and check
1229 * if it reached its expire time. If so, terminate the IO.
1232 __dasd_check_expire(struct dasd_device * device)
1234 struct dasd_ccw_req *cqr;
1236 if (list_empty(&device->ccw_queue))
1238 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1239 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1240 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1241 if (device->discipline->term_IO(cqr) != 0)
1242 /* Hmpf, try again in 1/10 sec */
1243 dasd_set_timer(device, 10);
1249 * Take a look at the first request on the ccw queue and check
1250 * if it needs to be started.
1253 __dasd_start_head(struct dasd_device * device)
1255 struct dasd_ccw_req *cqr;
1258 if (list_empty(&device->ccw_queue))
1260 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1261 /* check FAILFAST */
1262 if (device->stopped & ~DASD_STOPPED_PENDING &&
1263 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1264 (!dasd_eer_enabled(device))) {
1265 cqr->status = DASD_CQR_FAILED;
1266 dasd_schedule_bh(device);
1268 if ((cqr->status == DASD_CQR_QUEUED) &&
1269 (!device->stopped)) {
1270 /* try to start the first I/O that can be started */
1271 rc = device->discipline->start_IO(cqr);
1273 dasd_set_timer(device, cqr->expires);
1274 else if (rc == -EACCES) {
1275 dasd_schedule_bh(device);
1277 /* Hmpf, try again in 1/2 sec */
1278 dasd_set_timer(device, 50);
1283 * Remove requests from the ccw queue.
1286 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1288 struct list_head flush_queue;
1289 struct list_head *l, *n;
1290 struct dasd_ccw_req *cqr;
1292 INIT_LIST_HEAD(&flush_queue);
1293 spin_lock_irq(get_ccwdev_lock(device->cdev));
1294 list_for_each_safe(l, n, &device->ccw_queue) {
1295 cqr = list_entry(l, struct dasd_ccw_req, list);
1296 /* Flush all request or only block device requests? */
1297 if (all == 0 && cqr->callback == dasd_end_request_cb)
1299 if (cqr->status == DASD_CQR_IN_IO)
1300 device->discipline->term_IO(cqr);
1301 if (cqr->status != DASD_CQR_DONE ||
1302 cqr->status != DASD_CQR_FAILED) {
1303 cqr->status = DASD_CQR_FAILED;
1304 cqr->stopclk = get_clock();
1306 /* Process finished ERP request. */
1308 __dasd_process_erp(device, cqr);
1311 /* Rechain request on device request queue */
1312 cqr->endclk = get_clock();
1313 list_move_tail(&cqr->list, &flush_queue);
1315 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1316 /* Now call the callback function of flushed requests */
1317 list_for_each_safe(l, n, &flush_queue) {
1318 cqr = list_entry(l, struct dasd_ccw_req, list);
1319 if (cqr->callback != NULL)
1320 (cqr->callback)(cqr, cqr->callback_data);
1325 * Acquire the device lock and process queues for the device.
1328 dasd_tasklet(struct dasd_device * device)
1330 struct list_head final_queue;
1331 struct list_head *l, *n;
1332 struct dasd_ccw_req *cqr;
1334 atomic_set (&device->tasklet_scheduled, 0);
1335 INIT_LIST_HEAD(&final_queue);
1336 spin_lock_irq(get_ccwdev_lock(device->cdev));
1337 /* Check expire time of first request on the ccw queue. */
1338 __dasd_check_expire(device);
1339 /* Finish off requests on ccw queue */
1340 __dasd_process_ccw_queue(device, &final_queue);
1341 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1342 /* Now call the callback function of requests with final status */
1343 list_for_each_safe(l, n, &final_queue) {
1344 cqr = list_entry(l, struct dasd_ccw_req, list);
1345 list_del_init(&cqr->list);
1346 if (cqr->callback != NULL)
1347 (cqr->callback)(cqr, cqr->callback_data);
1349 spin_lock_irq(&device->request_queue_lock);
1350 spin_lock(get_ccwdev_lock(device->cdev));
1351 /* Get new request from the block device request queue */
1352 __dasd_process_blk_queue(device);
1353 /* Now check if the head of the ccw queue needs to be started. */
1354 __dasd_start_head(device);
1355 spin_unlock(get_ccwdev_lock(device->cdev));
1356 spin_unlock_irq(&device->request_queue_lock);
1357 dasd_put_device(device);
1361 * Schedules a call to dasd_tasklet over the device tasklet.
1364 dasd_schedule_bh(struct dasd_device * device)
1366 /* Protect against rescheduling. */
1367 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
1369 dasd_get_device(device);
1370 tasklet_hi_schedule(&device->tasklet);
1374 * Queue a request to the head of the ccw_queue. Start the I/O if
1378 dasd_add_request_head(struct dasd_ccw_req *req)
1380 struct dasd_device *device;
1381 unsigned long flags;
1383 device = req->device;
1384 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1385 req->status = DASD_CQR_QUEUED;
1386 req->device = device;
1387 list_add(&req->list, &device->ccw_queue);
1388 /* let the bh start the request to keep them in order */
1389 dasd_schedule_bh(device);
1390 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1394 * Queue a request to the tail of the ccw_queue. Start the I/O if
1398 dasd_add_request_tail(struct dasd_ccw_req *req)
1400 struct dasd_device *device;
1401 unsigned long flags;
1403 device = req->device;
1404 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1405 req->status = DASD_CQR_QUEUED;
1406 req->device = device;
1407 list_add_tail(&req->list, &device->ccw_queue);
1408 /* let the bh start the request to keep them in order */
1409 dasd_schedule_bh(device);
1410 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1417 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1419 wake_up((wait_queue_head_t *) data);
1423 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1425 struct dasd_device *device;
1428 device = cqr->device;
1429 spin_lock_irq(get_ccwdev_lock(device->cdev));
1430 rc = ((cqr->status == DASD_CQR_DONE ||
1431 cqr->status == DASD_CQR_FAILED) &&
1432 list_empty(&cqr->list));
1433 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1438 * Attempts to start a special ccw queue and waits for its completion.
1441 dasd_sleep_on(struct dasd_ccw_req * cqr)
1443 wait_queue_head_t wait_q;
1444 struct dasd_device *device;
1447 device = cqr->device;
1448 spin_lock_irq(get_ccwdev_lock(device->cdev));
1450 init_waitqueue_head (&wait_q);
1451 cqr->callback = dasd_wakeup_cb;
1452 cqr->callback_data = (void *) &wait_q;
1453 cqr->status = DASD_CQR_QUEUED;
1454 list_add_tail(&cqr->list, &device->ccw_queue);
1456 /* let the bh start the request to keep them in order */
1457 dasd_schedule_bh(device);
1459 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1461 wait_event(wait_q, _wait_for_wakeup(cqr));
1463 /* Request status is either done or failed. */
1464 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1469 * Attempts to start a special ccw queue and wait interruptible
1470 * for its completion.
1473 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1475 wait_queue_head_t wait_q;
1476 struct dasd_device *device;
1479 device = cqr->device;
1480 spin_lock_irq(get_ccwdev_lock(device->cdev));
1482 init_waitqueue_head (&wait_q);
1483 cqr->callback = dasd_wakeup_cb;
1484 cqr->callback_data = (void *) &wait_q;
1485 cqr->status = DASD_CQR_QUEUED;
1486 list_add_tail(&cqr->list, &device->ccw_queue);
1488 /* let the bh start the request to keep them in order */
1489 dasd_schedule_bh(device);
1490 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1494 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1495 if (rc != -ERESTARTSYS) {
1496 /* Request is final (done or failed) */
1497 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1500 spin_lock_irq(get_ccwdev_lock(device->cdev));
1501 switch (cqr->status) {
1502 case DASD_CQR_IN_IO:
1503 /* terminate runnig cqr */
1504 if (device->discipline->term_IO) {
1506 device->discipline->term_IO(cqr);
1508 * wait (non-interruptible) for final status
1509 * because signal ist still pending
1511 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1512 wait_event(wait_q, _wait_for_wakeup(cqr));
1513 spin_lock_irq(get_ccwdev_lock(device->cdev));
1514 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1518 case DASD_CQR_QUEUED:
1520 list_del_init(&cqr->list);
1525 /* cqr with 'non-interruptable' status - just wait */
1528 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1534 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1535 * for eckd devices) the currently running request has to be terminated
1536 * and be put back to status queued, before the special request is added
1537 * to the head of the queue. Then the special request is waited on normally.
1540 _dasd_term_running_cqr(struct dasd_device *device)
1542 struct dasd_ccw_req *cqr;
1545 if (list_empty(&device->ccw_queue))
1547 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1548 rc = device->discipline->term_IO(cqr);
1550 /* termination successful */
1551 cqr->status = DASD_CQR_QUEUED;
1552 cqr->startclk = cqr->stopclk = 0;
1559 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1561 wait_queue_head_t wait_q;
1562 struct dasd_device *device;
1565 device = cqr->device;
1566 spin_lock_irq(get_ccwdev_lock(device->cdev));
1567 rc = _dasd_term_running_cqr(device);
1569 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1573 init_waitqueue_head (&wait_q);
1574 cqr->callback = dasd_wakeup_cb;
1575 cqr->callback_data = (void *) &wait_q;
1576 cqr->status = DASD_CQR_QUEUED;
1577 list_add(&cqr->list, &device->ccw_queue);
1579 /* let the bh start the request to keep them in order */
1580 dasd_schedule_bh(device);
1582 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1584 wait_event(wait_q, _wait_for_wakeup(cqr));
1586 /* Request status is either done or failed. */
1587 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1592 * Cancels a request that was started with dasd_sleep_on_req.
1593 * This is useful to timeout requests. The request will be
1594 * terminated if it is currently in i/o.
1595 * Returns 1 if the request has been terminated.
1598 dasd_cancel_req(struct dasd_ccw_req *cqr)
1600 struct dasd_device *device = cqr->device;
1601 unsigned long flags;
1605 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1606 switch (cqr->status) {
1607 case DASD_CQR_QUEUED:
1608 /* request was not started - just set to failed */
1609 cqr->status = DASD_CQR_FAILED;
1611 case DASD_CQR_IN_IO:
1612 /* request in IO - terminate IO and release again */
1613 if (device->discipline->term_IO(cqr) != 0)
1614 /* what to do if unable to terminate ??????
1616 cqr->status = DASD_CQR_FAILED;
1617 cqr->stopclk = get_clock();
1621 case DASD_CQR_FAILED:
1622 /* already finished - do nothing */
1625 DEV_MESSAGE(KERN_ALERT, device,
1626 "invalid status %02x in request",
1631 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1632 dasd_schedule_bh(device);
1637 * SECTION: Block device operations (request queue, partitions, open, release).
1641 * Dasd request queue function. Called from ll_rw_blk.c
1644 do_dasd_request(request_queue_t * queue)
1646 struct dasd_device *device;
1648 device = (struct dasd_device *) queue->queuedata;
1649 spin_lock(get_ccwdev_lock(device->cdev));
1650 /* Get new request from the block device request queue */
1651 __dasd_process_blk_queue(device);
1652 /* Now check if the head of the ccw queue needs to be started. */
1653 __dasd_start_head(device);
1654 spin_unlock(get_ccwdev_lock(device->cdev));
1658 * Allocate and initialize request queue and default I/O scheduler.
1661 dasd_alloc_queue(struct dasd_device * device)
1665 device->request_queue = blk_init_queue(do_dasd_request,
1666 &device->request_queue_lock);
1667 if (device->request_queue == NULL)
1670 device->request_queue->queuedata = device;
1672 elevator_exit(device->request_queue->elevator);
1673 rc = elevator_init(device->request_queue, "deadline");
1675 blk_cleanup_queue(device->request_queue);
1682 * Allocate and initialize request queue.
1685 dasd_setup_queue(struct dasd_device * device)
1689 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1690 max = device->discipline->max_blocks << device->s2b_shift;
1691 blk_queue_max_sectors(device->request_queue, max);
1692 blk_queue_max_phys_segments(device->request_queue, -1L);
1693 blk_queue_max_hw_segments(device->request_queue, -1L);
1694 blk_queue_max_segment_size(device->request_queue, -1L);
1695 blk_queue_segment_boundary(device->request_queue, -1L);
1696 blk_queue_ordered(device->request_queue, QUEUE_ORDERED_TAG, NULL);
1700 * Deactivate and free request queue.
1703 dasd_free_queue(struct dasd_device * device)
1705 if (device->request_queue) {
1706 blk_cleanup_queue(device->request_queue);
1707 device->request_queue = NULL;
1712 * Flush request on the request queue.
1715 dasd_flush_request_queue(struct dasd_device * device)
1717 struct request *req;
1719 if (!device->request_queue)
1722 spin_lock_irq(&device->request_queue_lock);
1723 while (!list_empty(&device->request_queue->queue_head)) {
1724 req = elv_next_request(device->request_queue);
1727 dasd_end_request(req, 0);
1728 blkdev_dequeue_request(req);
1730 spin_unlock_irq(&device->request_queue_lock);
1734 dasd_open(struct inode *inp, struct file *filp)
1736 struct gendisk *disk = inp->i_bdev->bd_disk;
1737 struct dasd_device *device = disk->private_data;
1740 atomic_inc(&device->open_count);
1741 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1746 if (!try_module_get(device->discipline->owner)) {
1751 if (dasd_probeonly) {
1752 DEV_MESSAGE(KERN_INFO, device, "%s",
1753 "No access to device due to probeonly mode");
1758 if (device->state <= DASD_STATE_BASIC) {
1759 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1760 " Cannot open unrecognized device");
1768 module_put(device->discipline->owner);
1770 atomic_dec(&device->open_count);
1775 dasd_release(struct inode *inp, struct file *filp)
1777 struct gendisk *disk = inp->i_bdev->bd_disk;
1778 struct dasd_device *device = disk->private_data;
1780 atomic_dec(&device->open_count);
1781 module_put(device->discipline->owner);
1786 * Return disk geometry.
1789 dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1791 struct dasd_device *device;
1793 device = bdev->bd_disk->private_data;
1797 if (!device->discipline ||
1798 !device->discipline->fill_geometry)
1801 device->discipline->fill_geometry(device, geo);
1802 geo->start = get_start_sect(bdev) >> device->s2b_shift;
1806 struct block_device_operations
1807 dasd_device_operations = {
1808 .owner = THIS_MODULE,
1810 .release = dasd_release,
1811 .ioctl = dasd_ioctl,
1812 .compat_ioctl = dasd_compat_ioctl,
1813 .getgeo = dasd_getgeo,
1820 #ifdef CONFIG_PROC_FS
1824 if (dasd_page_cache != NULL) {
1825 kmem_cache_destroy(dasd_page_cache);
1826 dasd_page_cache = NULL;
1828 dasd_gendisk_exit();
1830 devfs_remove("dasd");
1831 if (dasd_debug_area != NULL) {
1832 debug_unregister(dasd_debug_area);
1833 dasd_debug_area = NULL;
1838 * SECTION: common functions for ccw_driver use
1842 * Initial attempt at a probe function. this can be simplified once
1843 * the other detection code is gone.
1846 dasd_generic_probe (struct ccw_device *cdev,
1847 struct dasd_discipline *discipline)
1851 ret = dasd_add_sysfs_files(cdev);
1854 "dasd_generic_probe: could not add sysfs entries "
1855 "for %s\n", cdev->dev.bus_id);
1857 cdev->handler = &dasd_int_handler;
1864 * This will one day be called from a global not_oper handler.
1865 * It is also used by driver_unregister during module unload.
1868 dasd_generic_remove (struct ccw_device *cdev)
1870 struct dasd_device *device;
1872 cdev->handler = NULL;
1874 dasd_remove_sysfs_files(cdev);
1875 device = dasd_device_from_cdev(cdev);
1878 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1879 /* Already doing offline processing */
1880 dasd_put_device(device);
1884 * This device is removed unconditionally. Set offline
1885 * flag to prevent dasd_open from opening it while it is
1886 * no quite down yet.
1888 dasd_set_target_state(device, DASD_STATE_NEW);
1889 /* dasd_delete_device destroys the device reference. */
1890 dasd_delete_device(device);
1894 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
1895 * the device is detected for the first time and is supposed to be used
1896 * or the user has started activation through sysfs.
1899 dasd_generic_set_online (struct ccw_device *cdev,
1900 struct dasd_discipline *base_discipline)
1903 struct dasd_discipline *discipline;
1904 struct dasd_device *device;
1907 device = dasd_create_device(cdev);
1909 return PTR_ERR(device);
1911 discipline = base_discipline;
1912 if (device->features & DASD_FEATURE_USEDIAG) {
1913 if (!dasd_diag_discipline_pointer) {
1914 printk (KERN_WARNING
1915 "dasd_generic couldn't online device %s "
1916 "- discipline DIAG not available\n",
1918 dasd_delete_device(device);
1921 discipline = dasd_diag_discipline_pointer;
1923 if (!try_module_get(base_discipline->owner)) {
1924 dasd_delete_device(device);
1927 if (!try_module_get(discipline->owner)) {
1928 module_put(base_discipline->owner);
1929 dasd_delete_device(device);
1932 device->base_discipline = base_discipline;
1933 device->discipline = discipline;
1935 rc = discipline->check_device(device);
1937 printk (KERN_WARNING
1938 "dasd_generic couldn't online device %s "
1939 "with discipline %s rc=%i\n",
1940 cdev->dev.bus_id, discipline->name, rc);
1941 module_put(discipline->owner);
1942 module_put(base_discipline->owner);
1943 dasd_delete_device(device);
1947 dasd_set_target_state(device, DASD_STATE_ONLINE);
1948 if (device->state <= DASD_STATE_KNOWN) {
1949 printk (KERN_WARNING
1950 "dasd_generic discipline not found for %s\n",
1953 dasd_set_target_state(device, DASD_STATE_NEW);
1954 dasd_delete_device(device);
1956 pr_debug("dasd_generic device %s found\n",
1959 /* FIXME: we have to wait for the root device but we don't want
1960 * to wait for each single device but for all at once. */
1961 wait_event(dasd_init_waitq, _wait_for_device(device));
1963 dasd_put_device(device);
1969 dasd_generic_set_offline (struct ccw_device *cdev)
1971 struct dasd_device *device;
1974 device = dasd_device_from_cdev(cdev);
1976 return PTR_ERR(device);
1977 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1978 /* Already doing offline processing */
1979 dasd_put_device(device);
1983 * We must make sure that this device is currently not in use.
1984 * The open_count is increased for every opener, that includes
1985 * the blkdev_get in dasd_scan_partitions. We are only interested
1986 * in the other openers.
1988 max_count = device->bdev ? 0 : -1;
1989 if (atomic_read(&device->open_count) > max_count) {
1990 printk (KERN_WARNING "Can't offline dasd device with open"
1992 atomic_read(&device->open_count));
1993 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
1994 dasd_put_device(device);
1997 dasd_set_target_state(device, DASD_STATE_NEW);
1998 /* dasd_delete_device destroys the device reference. */
1999 dasd_delete_device(device);
2005 dasd_generic_notify(struct ccw_device *cdev, int event)
2007 struct dasd_device *device;
2008 struct dasd_ccw_req *cqr;
2009 unsigned long flags;
2012 device = dasd_device_from_cdev(cdev);
2015 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
2020 /* First of all call extended error reporting. */
2021 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
2023 if (device->state < DASD_STATE_BASIC)
2025 /* Device is active. We want to keep it. */
2026 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
2027 list_for_each_entry(cqr, &device->ccw_queue, list)
2028 if (cqr->status == DASD_CQR_IN_IO)
2029 cqr->status = DASD_CQR_FAILED;
2030 device->stopped |= DASD_STOPPED_DC_EIO;
2032 list_for_each_entry(cqr, &device->ccw_queue, list)
2033 if (cqr->status == DASD_CQR_IN_IO) {
2034 cqr->status = DASD_CQR_QUEUED;
2037 device->stopped |= DASD_STOPPED_DC_WAIT;
2038 dasd_set_timer(device, 0);
2040 dasd_schedule_bh(device);
2044 /* FIXME: add a sanity check. */
2045 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
2046 dasd_schedule_bh(device);
2050 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2051 dasd_put_device(device);
2056 * Automatically online either all dasd devices (dasd_autodetect) or
2057 * all devices specified with dasd= parameters.
2060 __dasd_auto_online(struct device *dev, void *data)
2062 struct ccw_device *cdev;
2064 cdev = to_ccwdev(dev);
2065 if (dasd_autodetect || dasd_busid_known(cdev->dev.bus_id) == 0)
2066 ccw_device_set_online(cdev);
2071 dasd_generic_auto_online (struct ccw_driver *dasd_discipline_driver)
2073 struct device_driver *drv;
2075 drv = get_driver(&dasd_discipline_driver->driver);
2076 driver_for_each_device(drv, NULL, NULL, __dasd_auto_online);
2086 init_waitqueue_head(&dasd_init_waitq);
2088 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2089 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long));
2090 if (dasd_debug_area == NULL) {
2094 debug_register_view(dasd_debug_area, &debug_sprintf_view);
2095 debug_set_level(dasd_debug_area, DBF_EMERG);
2097 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
2099 dasd_diag_discipline_pointer = NULL;
2101 rc = devfs_mk_dir("dasd");
2104 rc = dasd_devmap_init();
2107 rc = dasd_gendisk_init();
2113 rc = dasd_eer_init();
2116 #ifdef CONFIG_PROC_FS
2117 rc = dasd_proc_init();
2124 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2129 module_init(dasd_init);
2130 module_exit(dasd_exit);
2132 EXPORT_SYMBOL(dasd_debug_area);
2133 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2135 EXPORT_SYMBOL(dasd_add_request_head);
2136 EXPORT_SYMBOL(dasd_add_request_tail);
2137 EXPORT_SYMBOL(dasd_cancel_req);
2138 EXPORT_SYMBOL(dasd_clear_timer);
2139 EXPORT_SYMBOL(dasd_enable_device);
2140 EXPORT_SYMBOL(dasd_int_handler);
2141 EXPORT_SYMBOL(dasd_kfree_request);
2142 EXPORT_SYMBOL(dasd_kick_device);
2143 EXPORT_SYMBOL(dasd_kmalloc_request);
2144 EXPORT_SYMBOL(dasd_schedule_bh);
2145 EXPORT_SYMBOL(dasd_set_target_state);
2146 EXPORT_SYMBOL(dasd_set_timer);
2147 EXPORT_SYMBOL(dasd_sfree_request);
2148 EXPORT_SYMBOL(dasd_sleep_on);
2149 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2150 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2151 EXPORT_SYMBOL(dasd_smalloc_request);
2152 EXPORT_SYMBOL(dasd_start_IO);
2153 EXPORT_SYMBOL(dasd_term_IO);
2155 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2156 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2157 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2158 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2159 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
2160 EXPORT_SYMBOL_GPL(dasd_generic_auto_online);
2163 * Overrides for Emacs so that we follow Linus's tabbing style.
2164 * Emacs will notice this stuff at the end of the file and automatically
2165 * adjust the settings for this buffer only. This must remain at the end
2167 * ---------------------------------------------------------------------------
2170 * c-brace-imaginary-offset: 0
2171 * c-brace-offset: -4
2172 * c-argdecl-indent: 4
2173 * c-label-offset: -4
2174 * c-continued-statement-offset: 4
2175 * c-continued-brace-offset: 0
2176 * indent-tabs-mode: 1