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
13 #include <linux/config.h>
14 #include <linux/kmod.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/ctype.h>
18 #include <linux/major.h>
19 #include <linux/slab.h>
20 #include <linux/buffer_head.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 = kmalloc(sizeof (struct dasd_device), GFP_ATOMIC);
76 return ERR_PTR(-ENOMEM);
77 memset(device, 0, sizeof (struct dasd_device));
78 /* open_count = 0 means device online but not in use */
79 atomic_set(&device->open_count, -1);
81 /* Get two pages for normal block device operations. */
82 device->ccw_mem = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA, 1);
83 if (device->ccw_mem == NULL) {
85 return ERR_PTR(-ENOMEM);
87 /* Get one page for error recovery. */
88 device->erp_mem = (void *) get_zeroed_page(GFP_ATOMIC | GFP_DMA);
89 if (device->erp_mem == NULL) {
90 free_pages((unsigned long) device->ccw_mem, 1);
92 return ERR_PTR(-ENOMEM);
95 dasd_init_chunklist(&device->ccw_chunks, device->ccw_mem, PAGE_SIZE*2);
96 dasd_init_chunklist(&device->erp_chunks, device->erp_mem, PAGE_SIZE);
97 spin_lock_init(&device->mem_lock);
98 spin_lock_init(&device->request_queue_lock);
99 atomic_set (&device->tasklet_scheduled, 0);
100 tasklet_init(&device->tasklet,
101 (void (*)(unsigned long)) dasd_tasklet,
102 (unsigned long) device);
103 INIT_LIST_HEAD(&device->ccw_queue);
104 init_timer(&device->timer);
105 INIT_WORK(&device->kick_work, do_kick_device, device);
106 device->state = DASD_STATE_NEW;
107 device->target = DASD_STATE_NEW;
113 * Free memory of a device structure.
116 dasd_free_device(struct dasd_device *device)
119 kfree(device->private);
120 free_page((unsigned long) device->erp_mem);
121 free_pages((unsigned long) device->ccw_mem, 1);
126 * Make a new device known to the system.
129 dasd_state_new_to_known(struct dasd_device *device)
134 * As long as the device is not in state DASD_STATE_NEW we want to
135 * keep the reference count > 0.
137 dasd_get_device(device);
139 rc = dasd_alloc_queue(device);
141 dasd_put_device(device);
145 device->state = DASD_STATE_KNOWN;
150 * Let the system forget about a device.
153 dasd_state_known_to_new(struct dasd_device * device)
155 /* Forget the discipline information. */
156 device->discipline = NULL;
157 device->state = DASD_STATE_NEW;
159 dasd_free_queue(device);
161 /* Give up reference we took in dasd_state_new_to_known. */
162 dasd_put_device(device);
166 * Request the irq line for the device.
169 dasd_state_known_to_basic(struct dasd_device * device)
173 /* Allocate and register gendisk structure. */
174 rc = dasd_gendisk_alloc(device);
178 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
179 device->debug_area = debug_register(device->cdev->dev.bus_id, 0, 2,
181 debug_register_view(device->debug_area, &debug_sprintf_view);
182 debug_set_level(device->debug_area, DBF_ERR);
183 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
185 device->state = DASD_STATE_BASIC;
190 * Release the irq line for the device. Terminate any running i/o.
193 dasd_state_basic_to_known(struct dasd_device * device)
195 dasd_gendisk_free(device);
196 dasd_flush_ccw_queue(device, 1);
197 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
198 if (device->debug_area != NULL) {
199 debug_unregister(device->debug_area);
200 device->debug_area = NULL;
202 device->state = DASD_STATE_KNOWN;
206 * Do the initial analysis. The do_analysis function may return
207 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
208 * until the discipline decides to continue the startup sequence
209 * by calling the function dasd_change_state. The eckd disciplines
210 * uses this to start a ccw that detects the format. The completion
211 * interrupt for this detection ccw uses the kernel event daemon to
212 * trigger the call to dasd_change_state. All this is done in the
213 * discipline code, see dasd_eckd.c.
214 * After the analysis ccw is done (do_analysis returned 0 or error)
215 * the block device is setup. Either a fake disk is added to allow
216 * formatting or a proper device request queue is created.
219 dasd_state_basic_to_ready(struct dasd_device * device)
224 if (device->discipline->do_analysis != NULL)
225 rc = device->discipline->do_analysis(device);
228 dasd_setup_queue(device);
229 device->state = DASD_STATE_READY;
230 if (dasd_scan_partitions(device) != 0)
231 device->state = DASD_STATE_BASIC;
236 * Remove device from block device layer. Destroy dirty buffers.
237 * Forget format information. Check if the target level is basic
238 * and if it is create fake disk for formatting.
241 dasd_state_ready_to_basic(struct dasd_device * device)
243 dasd_flush_ccw_queue(device, 0);
244 dasd_destroy_partitions(device);
245 dasd_flush_request_queue(device);
247 device->bp_block = 0;
248 device->s2b_shift = 0;
249 device->state = DASD_STATE_BASIC;
253 * Make the device online and schedule the bottom half to start
254 * the requeueing of requests from the linux request queue to the
258 dasd_state_ready_to_online(struct dasd_device * device)
260 device->state = DASD_STATE_ONLINE;
261 dasd_schedule_bh(device);
266 * Stop the requeueing of requests again.
269 dasd_state_online_to_ready(struct dasd_device * device)
271 device->state = DASD_STATE_READY;
275 * Device startup state changes.
278 dasd_increase_state(struct dasd_device *device)
283 if (device->state == DASD_STATE_NEW &&
284 device->target >= DASD_STATE_KNOWN)
285 rc = dasd_state_new_to_known(device);
288 device->state == DASD_STATE_KNOWN &&
289 device->target >= DASD_STATE_BASIC)
290 rc = dasd_state_known_to_basic(device);
293 device->state == DASD_STATE_BASIC &&
294 device->target >= DASD_STATE_READY)
295 rc = dasd_state_basic_to_ready(device);
298 device->state == DASD_STATE_READY &&
299 device->target >= DASD_STATE_ONLINE)
300 rc = dasd_state_ready_to_online(device);
306 * Device shutdown state changes.
309 dasd_decrease_state(struct dasd_device *device)
311 if (device->state == DASD_STATE_ONLINE &&
312 device->target <= DASD_STATE_READY)
313 dasd_state_online_to_ready(device);
315 if (device->state == DASD_STATE_READY &&
316 device->target <= DASD_STATE_BASIC)
317 dasd_state_ready_to_basic(device);
319 if (device->state == DASD_STATE_BASIC &&
320 device->target <= DASD_STATE_KNOWN)
321 dasd_state_basic_to_known(device);
323 if (device->state == DASD_STATE_KNOWN &&
324 device->target <= DASD_STATE_NEW)
325 dasd_state_known_to_new(device);
331 * This is the main startup/shutdown routine.
334 dasd_change_state(struct dasd_device *device)
338 if (device->state == device->target)
339 /* Already where we want to go today... */
341 if (device->state < device->target)
342 rc = dasd_increase_state(device);
344 rc = dasd_decrease_state(device);
345 if (rc && rc != -EAGAIN)
346 device->target = device->state;
348 if (device->state == device->target)
349 wake_up(&dasd_init_waitq);
353 * Kick starter for devices that did not complete the startup/shutdown
354 * procedure or were sleeping because of a pending state.
355 * dasd_kick_device will schedule a call do do_kick_device to the kernel
359 do_kick_device(void *data)
361 struct dasd_device *device;
363 device = (struct dasd_device *) data;
364 dasd_change_state(device);
365 dasd_schedule_bh(device);
366 dasd_put_device(device);
370 dasd_kick_device(struct dasd_device *device)
372 dasd_get_device(device);
373 /* queue call to dasd_kick_device to the kernel event daemon. */
374 schedule_work(&device->kick_work);
378 * Set the target state for a device and starts the state change.
381 dasd_set_target_state(struct dasd_device *device, int target)
383 /* If we are in probeonly mode stop at DASD_STATE_READY. */
384 if (dasd_probeonly && target > DASD_STATE_READY)
385 target = DASD_STATE_READY;
386 if (device->target != target) {
387 if (device->state == target)
388 wake_up(&dasd_init_waitq);
389 device->target = target;
391 if (device->state != device->target)
392 dasd_change_state(device);
396 * Enable devices with device numbers in [from..to].
399 _wait_for_device(struct dasd_device *device)
401 return (device->state == device->target);
405 dasd_enable_device(struct dasd_device *device)
407 dasd_set_target_state(device, DASD_STATE_ONLINE);
408 if (device->state <= DASD_STATE_KNOWN)
409 /* No discipline for device found. */
410 dasd_set_target_state(device, DASD_STATE_NEW);
411 /* Now wait for the devices to come up. */
412 wait_event(dasd_init_waitq, _wait_for_device(device));
416 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
418 #ifdef CONFIG_DASD_PROFILE
420 struct dasd_profile_info_t dasd_global_profile;
421 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
424 * Increments counter in global and local profiling structures.
426 #define dasd_profile_counter(value, counter, device) \
429 for (index = 0; index < 31 && value >> (2+index); index++); \
430 dasd_global_profile.counter[index]++; \
431 device->profile.counter[index]++; \
435 * Add profiling information for cqr before execution.
438 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
442 unsigned int counter;
444 if (dasd_profile_level != DASD_PROFILE_ON)
447 /* count the length of the chanq for statistics */
449 list_for_each(l, &device->ccw_queue)
452 dasd_global_profile.dasd_io_nr_req[counter]++;
453 device->profile.dasd_io_nr_req[counter]++;
457 * Add profiling information for cqr after execution.
460 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
463 long strtime, irqtime, endtime, tottime; /* in microseconds */
464 long tottimeps, sectors;
466 if (dasd_profile_level != DASD_PROFILE_ON)
469 sectors = req->nr_sectors;
470 if (!cqr->buildclk || !cqr->startclk ||
471 !cqr->stopclk || !cqr->endclk ||
475 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
476 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
477 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
478 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
479 tottimeps = tottime / sectors;
481 if (!dasd_global_profile.dasd_io_reqs)
482 memset(&dasd_global_profile, 0,
483 sizeof (struct dasd_profile_info_t));
484 dasd_global_profile.dasd_io_reqs++;
485 dasd_global_profile.dasd_io_sects += sectors;
487 if (!device->profile.dasd_io_reqs)
488 memset(&device->profile, 0,
489 sizeof (struct dasd_profile_info_t));
490 device->profile.dasd_io_reqs++;
491 device->profile.dasd_io_sects += sectors;
493 dasd_profile_counter(sectors, dasd_io_secs, device);
494 dasd_profile_counter(tottime, dasd_io_times, device);
495 dasd_profile_counter(tottimeps, dasd_io_timps, device);
496 dasd_profile_counter(strtime, dasd_io_time1, device);
497 dasd_profile_counter(irqtime, dasd_io_time2, device);
498 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
499 dasd_profile_counter(endtime, dasd_io_time3, device);
502 #define dasd_profile_start(device, cqr, req) do {} while (0)
503 #define dasd_profile_end(device, cqr, req) do {} while (0)
504 #endif /* CONFIG_DASD_PROFILE */
507 * Allocate memory for a channel program with 'cplength' channel
508 * command words and 'datasize' additional space. There are two
509 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
510 * memory and 2) dasd_smalloc_request uses the static ccw memory
511 * that gets allocated for each device.
513 struct dasd_ccw_req *
514 dasd_kmalloc_request(char *magic, int cplength, int datasize,
515 struct dasd_device * device)
517 struct dasd_ccw_req *cqr;
520 if ( magic == NULL || datasize > PAGE_SIZE ||
521 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
523 debug_text_event ( dasd_debug_area, 1, "ALLC");
524 debug_text_event ( dasd_debug_area, 1, magic);
525 debug_int_event ( dasd_debug_area, 1, cplength);
526 debug_int_event ( dasd_debug_area, 1, datasize);
528 cqr = kmalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
530 return ERR_PTR(-ENOMEM);
531 memset(cqr, 0, sizeof(struct dasd_ccw_req));
534 cqr->cpaddr = kmalloc(cplength*sizeof(struct ccw1),
535 GFP_ATOMIC | GFP_DMA);
536 if (cqr->cpaddr == NULL) {
538 return ERR_PTR(-ENOMEM);
540 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
544 cqr->data = kmalloc(datasize, GFP_ATOMIC | GFP_DMA);
545 if (cqr->data == NULL) {
546 if (cqr->cpaddr != NULL)
549 return ERR_PTR(-ENOMEM);
551 memset(cqr->data, 0, datasize);
553 strncpy((char *) &cqr->magic, magic, 4);
554 ASCEBC((char *) &cqr->magic, 4);
555 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
556 dasd_get_device(device);
560 struct dasd_ccw_req *
561 dasd_smalloc_request(char *magic, int cplength, int datasize,
562 struct dasd_device * device)
565 struct dasd_ccw_req *cqr;
570 if ( magic == NULL || datasize > PAGE_SIZE ||
571 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
573 debug_text_event ( dasd_debug_area, 1, "ALLC");
574 debug_text_event ( dasd_debug_area, 1, magic);
575 debug_int_event ( dasd_debug_area, 1, cplength);
576 debug_int_event ( dasd_debug_area, 1, datasize);
578 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
580 size += cplength * sizeof(struct ccw1);
583 spin_lock_irqsave(&device->mem_lock, flags);
584 cqr = (struct dasd_ccw_req *)
585 dasd_alloc_chunk(&device->ccw_chunks, size);
586 spin_unlock_irqrestore(&device->mem_lock, flags);
588 return ERR_PTR(-ENOMEM);
589 memset(cqr, 0, sizeof(struct dasd_ccw_req));
590 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
593 cqr->cpaddr = (struct ccw1 *) data;
594 data += cplength*sizeof(struct ccw1);
595 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
600 memset(cqr->data, 0, datasize);
602 strncpy((char *) &cqr->magic, magic, 4);
603 ASCEBC((char *) &cqr->magic, 4);
604 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
605 dasd_get_device(device);
610 * Free memory of a channel program. This function needs to free all the
611 * idal lists that might have been created by dasd_set_cda and the
612 * struct dasd_ccw_req itself.
615 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
617 #ifdef CONFIG_ARCH_S390X
620 /* Clear any idals used for the request. */
623 clear_normalized_cda(ccw);
624 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
626 debug_text_event ( dasd_debug_area, 1, "FREE");
627 debug_int_event ( dasd_debug_area, 1, (long) cqr);
628 if (cqr->cpaddr != NULL)
630 if (cqr->data != NULL)
633 dasd_put_device(device);
637 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
641 debug_text_event(dasd_debug_area, 1, "FREE");
642 debug_int_event(dasd_debug_area, 1, (long) cqr);
643 spin_lock_irqsave(&device->mem_lock, flags);
644 dasd_free_chunk(&device->ccw_chunks, cqr);
645 spin_unlock_irqrestore(&device->mem_lock, flags);
646 dasd_put_device(device);
650 * Check discipline magic in cqr.
653 dasd_check_cqr(struct dasd_ccw_req *cqr)
655 struct dasd_device *device;
659 device = cqr->device;
660 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
661 DEV_MESSAGE(KERN_WARNING, device,
662 " dasd_ccw_req 0x%08x magic doesn't match"
663 " discipline 0x%08x",
665 *(unsigned int *) device->discipline->name);
672 * Terminate the current i/o and set the request to clear_pending.
673 * Timer keeps device runnig.
674 * ccw_device_clear can fail if the i/o subsystem
678 dasd_term_IO(struct dasd_ccw_req * cqr)
680 struct dasd_device *device;
684 rc = dasd_check_cqr(cqr);
688 device = (struct dasd_device *) cqr->device;
689 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
690 rc = ccw_device_clear(device->cdev, (long) cqr);
692 case 0: /* termination successful */
693 if (cqr->retries > 0) {
695 cqr->status = DASD_CQR_CLEAR;
697 cqr->status = DASD_CQR_FAILED;
698 cqr->stopclk = get_clock();
701 DBF_DEV_EVENT(DBF_ERR, device, "%s",
702 "device gone, retry");
705 DBF_DEV_EVENT(DBF_ERR, device, "%s",
710 DBF_DEV_EVENT(DBF_ERR, device, "%s",
711 "device busy, retry later");
714 DEV_MESSAGE(KERN_ERR, device,
715 "line %d unknown RC=%d, please "
716 "report to linux390@de.ibm.com",
723 dasd_schedule_bh(device);
728 * Start the i/o. This start_IO can fail if the channel is really busy.
729 * In that case set up a timer to start the request later.
732 dasd_start_IO(struct dasd_ccw_req * cqr)
734 struct dasd_device *device;
738 rc = dasd_check_cqr(cqr);
741 device = (struct dasd_device *) cqr->device;
742 if (cqr->retries < 0) {
743 DEV_MESSAGE(KERN_DEBUG, device,
744 "start_IO: request %p (%02x/%i) - no retry left.",
745 cqr, cqr->status, cqr->retries);
746 cqr->status = DASD_CQR_FAILED;
749 cqr->startclk = get_clock();
750 cqr->starttime = jiffies;
752 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
756 cqr->status = DASD_CQR_IN_IO;
759 DBF_DEV_EVENT(DBF_ERR, device, "%s",
760 "start_IO: device busy, retry later");
763 DBF_DEV_EVENT(DBF_ERR, device, "%s",
764 "start_IO: request timeout, retry later");
768 DBF_DEV_EVENT(DBF_ERR, device, "%s",
769 "start_IO: device gone, retry");
772 DEV_MESSAGE(KERN_ERR, device,
773 "line %d unknown RC=%d, please report"
774 " to linux390@de.ibm.com", __LINE__, rc);
782 * Timeout function for dasd devices. This is used for different purposes
783 * 1) missing interrupt handler for normal operation
784 * 2) delayed start of request where start_IO failed with -EBUSY
785 * 3) timeout for missing state change interrupts
786 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
787 * DASD_CQR_QUEUED for 2) and 3).
790 dasd_timeout_device(unsigned long ptr)
793 struct dasd_device *device;
795 device = (struct dasd_device *) ptr;
796 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
797 /* re-activate request queue */
798 device->stopped &= ~DASD_STOPPED_PENDING;
799 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
800 dasd_schedule_bh(device);
804 * Setup timeout for a device in jiffies.
807 dasd_set_timer(struct dasd_device *device, int expires)
810 if (timer_pending(&device->timer))
811 del_timer(&device->timer);
814 if (timer_pending(&device->timer)) {
815 if (mod_timer(&device->timer, jiffies + expires))
818 device->timer.function = dasd_timeout_device;
819 device->timer.data = (unsigned long) device;
820 device->timer.expires = jiffies + expires;
821 add_timer(&device->timer);
825 * Clear timeout for a device.
828 dasd_clear_timer(struct dasd_device *device)
830 if (timer_pending(&device->timer))
831 del_timer(&device->timer);
835 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
837 struct dasd_ccw_req *cqr;
838 struct dasd_device *device;
840 cqr = (struct dasd_ccw_req *) intparm;
841 if (cqr->status != DASD_CQR_IN_IO) {
843 "invalid status in handle_killed_request: "
844 "bus_id %s, status %02x",
845 cdev->dev.bus_id, cqr->status);
849 device = (struct dasd_device *) cqr->device;
850 if (device == NULL ||
851 device != dasd_device_from_cdev(cdev) ||
852 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
853 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
858 /* Schedule request to be retried. */
859 cqr->status = DASD_CQR_QUEUED;
861 dasd_clear_timer(device);
862 dasd_schedule_bh(device);
863 dasd_put_device(device);
867 dasd_handle_state_change_pending(struct dasd_device *device)
869 struct dasd_ccw_req *cqr;
870 struct list_head *l, *n;
872 device->stopped &= ~DASD_STOPPED_PENDING;
874 /* restart all 'running' IO on queue */
875 list_for_each_safe(l, n, &device->ccw_queue) {
876 cqr = list_entry(l, struct dasd_ccw_req, list);
877 if (cqr->status == DASD_CQR_IN_IO) {
878 cqr->status = DASD_CQR_QUEUED;
881 dasd_clear_timer(device);
882 dasd_schedule_bh(device);
886 * Interrupt handler for "normal" ssch-io based dasd devices.
889 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
892 struct dasd_ccw_req *cqr, *next;
893 struct dasd_device *device;
894 unsigned long long now;
900 switch (PTR_ERR(irb)) {
902 dasd_handle_killed_request(cdev, intparm);
905 printk(KERN_WARNING"%s(%s): request timed out\n",
906 __FUNCTION__, cdev->dev.bus_id);
907 //FIXME - dasd uses own timeout interface...
910 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
911 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
918 DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
919 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
920 (unsigned int) intparm);
922 /* first of all check for state change pending interrupt */
923 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
924 if ((irb->scsw.dstat & mask) == mask) {
925 device = dasd_device_from_cdev(cdev);
926 if (!IS_ERR(device)) {
927 dasd_handle_state_change_pending(device);
928 dasd_put_device(device);
933 cqr = (struct dasd_ccw_req *) intparm;
935 /* check for unsolicited interrupts */
938 "unsolicited interrupt received: bus_id %s",
943 device = (struct dasd_device *) cqr->device;
944 if (device == NULL ||
945 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
946 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
951 /* Check for clear pending */
952 if (cqr->status == DASD_CQR_CLEAR &&
953 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
954 cqr->status = DASD_CQR_QUEUED;
955 dasd_clear_timer(device);
956 dasd_schedule_bh(device);
960 /* check status - the request might have been killed by dyn detach */
961 if (cqr->status != DASD_CQR_IN_IO) {
963 "invalid status: bus_id %s, status %02x",
964 cdev->dev.bus_id, cqr->status);
967 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x",
968 ((irb->scsw.cstat << 8) | irb->scsw.dstat));
970 /* Find out the appropriate era_action. */
971 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
972 era = dasd_era_fatal;
973 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
974 irb->scsw.cstat == 0 &&
975 !irb->esw.esw0.erw.cons)
977 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
978 era = dasd_era_fatal; /* don't recover this request */
979 else if (irb->esw.esw0.erw.cons)
980 era = device->discipline->examine_error(cqr, irb);
982 era = dasd_era_recover;
984 DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
986 if (era == dasd_era_none) {
987 cqr->status = DASD_CQR_DONE;
989 /* Start first request on queue if possible -> fast_io. */
990 if (cqr->list.next != &device->ccw_queue) {
991 next = list_entry(cqr->list.next,
992 struct dasd_ccw_req, list);
993 if ((next->status == DASD_CQR_QUEUED) &&
994 (!device->stopped)) {
995 if (device->discipline->start_IO(next) == 0)
996 expires = next->expires;
998 DEV_MESSAGE(KERN_DEBUG, device, "%s",
999 "Interrupt fastpath "
1003 } else { /* error */
1004 memcpy(&cqr->irb, irb, sizeof (struct irb));
1006 /* dump sense data */
1007 dasd_log_sense(cqr, irb);
1010 case dasd_era_fatal:
1011 cqr->status = DASD_CQR_FAILED;
1014 case dasd_era_recover:
1015 cqr->status = DASD_CQR_ERROR;
1022 dasd_set_timer(device, expires);
1024 dasd_clear_timer(device);
1025 dasd_schedule_bh(device);
1029 * posts the buffer_cache about a finalized request
1032 dasd_end_request(struct request *req, int uptodate)
1034 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1036 add_disk_randomness(req->rq_disk);
1037 end_that_request_last(req);
1041 * Process finished error recovery ccw.
1044 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1046 dasd_erp_fn_t erp_fn;
1048 if (cqr->status == DASD_CQR_DONE)
1049 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1051 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1052 erp_fn = device->discipline->erp_postaction(cqr);
1057 * Process ccw request queue.
1060 __dasd_process_ccw_queue(struct dasd_device * device,
1061 struct list_head *final_queue)
1063 struct list_head *l, *n;
1064 struct dasd_ccw_req *cqr;
1065 dasd_erp_fn_t erp_fn;
1068 /* Process request with final status. */
1069 list_for_each_safe(l, n, &device->ccw_queue) {
1070 cqr = list_entry(l, struct dasd_ccw_req, list);
1071 /* Stop list processing at the first non-final request. */
1072 if (cqr->status != DASD_CQR_DONE &&
1073 cqr->status != DASD_CQR_FAILED &&
1074 cqr->status != DASD_CQR_ERROR)
1076 /* Process requests with DASD_CQR_ERROR */
1077 if (cqr->status == DASD_CQR_ERROR) {
1078 if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1079 cqr->status = DASD_CQR_FAILED;
1080 cqr->stopclk = get_clock();
1082 if (cqr->irb.esw.esw0.erw.cons) {
1083 erp_fn = device->discipline->erp_action(cqr);
1086 dasd_default_erp_action(cqr);
1090 /* Process finished ERP request. */
1092 __dasd_process_erp(device, cqr);
1096 /* Rechain finished requests to final queue */
1097 cqr->endclk = get_clock();
1098 list_move_tail(&cqr->list, final_queue);
1103 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1105 struct request *req;
1107 req = (struct request *) data;
1108 dasd_profile_end(cqr->device, cqr, req);
1109 spin_lock_irq(&cqr->device->request_queue_lock);
1110 dasd_end_request(req, (cqr->status == DASD_CQR_DONE));
1111 spin_unlock_irq(&cqr->device->request_queue_lock);
1112 dasd_sfree_request(cqr, cqr->device);
1117 * Fetch requests from the block device queue.
1120 __dasd_process_blk_queue(struct dasd_device * device)
1122 request_queue_t *queue;
1123 struct request *req;
1124 struct dasd_ccw_req *cqr;
1127 queue = device->request_queue;
1128 /* No queue ? Then there is nothing to do. */
1133 * We requeue request from the block device queue to the ccw
1134 * queue only in two states. In state DASD_STATE_READY the
1135 * partition detection is done and we need to requeue requests
1136 * for that. State DASD_STATE_ONLINE is normal block device
1139 if (device->state != DASD_STATE_READY &&
1140 device->state != DASD_STATE_ONLINE)
1143 /* Now we try to fetch requests from the request queue */
1144 list_for_each_entry(cqr, &device->ccw_queue, list)
1145 if (cqr->status == DASD_CQR_QUEUED)
1147 while (!blk_queue_plugged(queue) &&
1148 elv_next_request(queue) &&
1149 nr_queued < DASD_CHANQ_MAX_SIZE) {
1150 req = elv_next_request(queue);
1151 if (test_bit(DASD_FLAG_RO, &device->flags) &&
1152 rq_data_dir(req) == WRITE) {
1154 "(%s) Rejecting write request %p",
1155 device->cdev->dev.bus_id,
1157 blkdev_dequeue_request(req);
1158 dasd_end_request(req, 0);
1161 if (device->stopped & DASD_STOPPED_DC_EIO) {
1162 blkdev_dequeue_request(req);
1163 dasd_end_request(req, 0);
1166 cqr = device->discipline->build_cp(device, req);
1168 if (PTR_ERR(cqr) == -ENOMEM)
1169 break; /* terminate request queue loop */
1171 "(%s) CCW creation failed on request %p",
1172 device->cdev->dev.bus_id,
1174 blkdev_dequeue_request(req);
1175 dasd_end_request(req, 0);
1178 cqr->callback = dasd_end_request_cb;
1179 cqr->callback_data = (void *) req;
1180 cqr->status = DASD_CQR_QUEUED;
1181 blkdev_dequeue_request(req);
1182 list_add_tail(&cqr->list, &device->ccw_queue);
1183 dasd_profile_start(device, cqr, req);
1189 * Take a look at the first request on the ccw queue and check
1190 * if it reached its expire time. If so, terminate the IO.
1193 __dasd_check_expire(struct dasd_device * device)
1195 struct dasd_ccw_req *cqr;
1197 if (list_empty(&device->ccw_queue))
1199 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1200 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1201 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1202 if (device->discipline->term_IO(cqr) != 0)
1203 /* Hmpf, try again in 1/10 sec */
1204 dasd_set_timer(device, 10);
1210 * Take a look at the first request on the ccw queue and check
1211 * if it needs to be started.
1214 __dasd_start_head(struct dasd_device * device)
1216 struct dasd_ccw_req *cqr;
1219 if (list_empty(&device->ccw_queue))
1221 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1222 if ((cqr->status == DASD_CQR_QUEUED) &&
1223 (!device->stopped)) {
1224 /* try to start the first I/O that can be started */
1225 rc = device->discipline->start_IO(cqr);
1227 dasd_set_timer(device, cqr->expires);
1229 /* Hmpf, try again in 1/2 sec */
1230 dasd_set_timer(device, 50);
1235 * Remove requests from the ccw queue.
1238 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1240 struct list_head flush_queue;
1241 struct list_head *l, *n;
1242 struct dasd_ccw_req *cqr;
1244 INIT_LIST_HEAD(&flush_queue);
1245 spin_lock_irq(get_ccwdev_lock(device->cdev));
1246 list_for_each_safe(l, n, &device->ccw_queue) {
1247 cqr = list_entry(l, struct dasd_ccw_req, list);
1248 /* Flush all request or only block device requests? */
1249 if (all == 0 && cqr->callback == dasd_end_request_cb)
1251 if (cqr->status == DASD_CQR_IN_IO)
1252 device->discipline->term_IO(cqr);
1253 if (cqr->status != DASD_CQR_DONE ||
1254 cqr->status != DASD_CQR_FAILED) {
1255 cqr->status = DASD_CQR_FAILED;
1256 cqr->stopclk = get_clock();
1258 /* Process finished ERP request. */
1260 __dasd_process_erp(device, cqr);
1263 /* Rechain request on device request queue */
1264 cqr->endclk = get_clock();
1265 list_move_tail(&cqr->list, &flush_queue);
1267 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1268 /* Now call the callback function of flushed requests */
1269 list_for_each_safe(l, n, &flush_queue) {
1270 cqr = list_entry(l, struct dasd_ccw_req, list);
1271 if (cqr->callback != NULL)
1272 (cqr->callback)(cqr, cqr->callback_data);
1277 * Acquire the device lock and process queues for the device.
1280 dasd_tasklet(struct dasd_device * device)
1282 struct list_head final_queue;
1283 struct list_head *l, *n;
1284 struct dasd_ccw_req *cqr;
1286 atomic_set (&device->tasklet_scheduled, 0);
1287 INIT_LIST_HEAD(&final_queue);
1288 spin_lock_irq(get_ccwdev_lock(device->cdev));
1289 /* Check expire time of first request on the ccw queue. */
1290 __dasd_check_expire(device);
1291 /* Finish off requests on ccw queue */
1292 __dasd_process_ccw_queue(device, &final_queue);
1293 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1294 /* Now call the callback function of requests with final status */
1295 list_for_each_safe(l, n, &final_queue) {
1296 cqr = list_entry(l, struct dasd_ccw_req, list);
1297 list_del(&cqr->list);
1298 if (cqr->callback != NULL)
1299 (cqr->callback)(cqr, cqr->callback_data);
1301 spin_lock_irq(&device->request_queue_lock);
1302 spin_lock(get_ccwdev_lock(device->cdev));
1303 /* Get new request from the block device request queue */
1304 __dasd_process_blk_queue(device);
1305 /* Now check if the head of the ccw queue needs to be started. */
1306 __dasd_start_head(device);
1307 spin_unlock(get_ccwdev_lock(device->cdev));
1308 spin_unlock_irq(&device->request_queue_lock);
1309 dasd_put_device(device);
1313 * Schedules a call to dasd_tasklet over the device tasklet.
1316 dasd_schedule_bh(struct dasd_device * device)
1318 /* Protect against rescheduling. */
1319 if (atomic_compare_and_swap (0, 1, &device->tasklet_scheduled))
1321 dasd_get_device(device);
1322 tasklet_hi_schedule(&device->tasklet);
1326 * Queue a request to the head of the ccw_queue. Start the I/O if
1330 dasd_add_request_head(struct dasd_ccw_req *req)
1332 struct dasd_device *device;
1333 unsigned long flags;
1335 device = req->device;
1336 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1337 req->status = DASD_CQR_QUEUED;
1338 req->device = device;
1339 list_add(&req->list, &device->ccw_queue);
1340 /* let the bh start the request to keep them in order */
1341 dasd_schedule_bh(device);
1342 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1346 * Queue a request to the tail of the ccw_queue. Start the I/O if
1350 dasd_add_request_tail(struct dasd_ccw_req *req)
1352 struct dasd_device *device;
1353 unsigned long flags;
1355 device = req->device;
1356 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1357 req->status = DASD_CQR_QUEUED;
1358 req->device = device;
1359 list_add_tail(&req->list, &device->ccw_queue);
1360 /* let the bh start the request to keep them in order */
1361 dasd_schedule_bh(device);
1362 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1369 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1371 wake_up((wait_queue_head_t *) data);
1375 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1377 struct dasd_device *device;
1380 device = cqr->device;
1381 spin_lock_irq(get_ccwdev_lock(device->cdev));
1382 rc = cqr->status == DASD_CQR_DONE || cqr->status == DASD_CQR_FAILED;
1383 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1388 * Attempts to start a special ccw queue and waits for its completion.
1391 dasd_sleep_on(struct dasd_ccw_req * cqr)
1393 wait_queue_head_t wait_q;
1394 struct dasd_device *device;
1397 device = cqr->device;
1398 spin_lock_irq(get_ccwdev_lock(device->cdev));
1400 init_waitqueue_head (&wait_q);
1401 cqr->callback = dasd_wakeup_cb;
1402 cqr->callback_data = (void *) &wait_q;
1403 cqr->status = DASD_CQR_QUEUED;
1404 list_add_tail(&cqr->list, &device->ccw_queue);
1406 /* let the bh start the request to keep them in order */
1407 dasd_schedule_bh(device);
1409 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1411 wait_event(wait_q, _wait_for_wakeup(cqr));
1413 /* Request status is either done or failed. */
1414 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1419 * Attempts to start a special ccw queue and wait interruptible
1420 * for its completion.
1423 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1425 wait_queue_head_t wait_q;
1426 struct dasd_device *device;
1429 device = cqr->device;
1430 spin_lock_irq(get_ccwdev_lock(device->cdev));
1432 init_waitqueue_head (&wait_q);
1433 cqr->callback = dasd_wakeup_cb;
1434 cqr->callback_data = (void *) &wait_q;
1435 cqr->status = DASD_CQR_QUEUED;
1436 list_add_tail(&cqr->list, &device->ccw_queue);
1438 /* let the bh start the request to keep them in order */
1439 dasd_schedule_bh(device);
1440 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1444 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1445 if (rc != -ERESTARTSYS) {
1446 /* Request status is either done or failed. */
1447 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1450 spin_lock_irq(get_ccwdev_lock(device->cdev));
1451 if (cqr->status == DASD_CQR_IN_IO &&
1452 device->discipline->term_IO(cqr) == 0) {
1453 list_del(&cqr->list);
1456 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1462 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1463 * for eckd devices) the currently running request has to be terminated
1464 * and be put back to status queued, before the special request is added
1465 * to the head of the queue. Then the special request is waited on normally.
1468 _dasd_term_running_cqr(struct dasd_device *device)
1470 struct dasd_ccw_req *cqr;
1473 if (list_empty(&device->ccw_queue))
1475 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1476 rc = device->discipline->term_IO(cqr);
1478 /* termination successful */
1479 cqr->status = DASD_CQR_QUEUED;
1480 cqr->startclk = cqr->stopclk = 0;
1487 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1489 wait_queue_head_t wait_q;
1490 struct dasd_device *device;
1493 device = cqr->device;
1494 spin_lock_irq(get_ccwdev_lock(device->cdev));
1495 rc = _dasd_term_running_cqr(device);
1497 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1501 init_waitqueue_head (&wait_q);
1502 cqr->callback = dasd_wakeup_cb;
1503 cqr->callback_data = (void *) &wait_q;
1504 cqr->status = DASD_CQR_QUEUED;
1505 list_add(&cqr->list, &device->ccw_queue);
1507 /* let the bh start the request to keep them in order */
1508 dasd_schedule_bh(device);
1510 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1512 wait_event(wait_q, _wait_for_wakeup(cqr));
1514 /* Request status is either done or failed. */
1515 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1520 * Cancels a request that was started with dasd_sleep_on_req.
1521 * This is useful to timeout requests. The request will be
1522 * terminated if it is currently in i/o.
1523 * Returns 1 if the request has been terminated.
1526 dasd_cancel_req(struct dasd_ccw_req *cqr)
1528 struct dasd_device *device = cqr->device;
1529 unsigned long flags;
1533 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1534 switch (cqr->status) {
1535 case DASD_CQR_QUEUED:
1536 /* request was not started - just set to failed */
1537 cqr->status = DASD_CQR_FAILED;
1539 case DASD_CQR_IN_IO:
1540 /* request in IO - terminate IO and release again */
1541 if (device->discipline->term_IO(cqr) != 0)
1542 /* what to do if unable to terminate ??????
1544 cqr->status = DASD_CQR_FAILED;
1545 cqr->stopclk = get_clock();
1549 case DASD_CQR_FAILED:
1550 /* already finished - do nothing */
1553 DEV_MESSAGE(KERN_ALERT, device,
1554 "invalid status %02x in request",
1559 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1560 dasd_schedule_bh(device);
1565 * SECTION: Block device operations (request queue, partitions, open, release).
1569 * Dasd request queue function. Called from ll_rw_blk.c
1572 do_dasd_request(request_queue_t * queue)
1574 struct dasd_device *device;
1576 device = (struct dasd_device *) queue->queuedata;
1577 spin_lock(get_ccwdev_lock(device->cdev));
1578 /* Get new request from the block device request queue */
1579 __dasd_process_blk_queue(device);
1580 /* Now check if the head of the ccw queue needs to be started. */
1581 __dasd_start_head(device);
1582 spin_unlock(get_ccwdev_lock(device->cdev));
1586 * Allocate and initialize request queue.
1589 dasd_alloc_queue(struct dasd_device * device)
1591 device->request_queue = blk_init_queue(do_dasd_request,
1592 &device->request_queue_lock);
1593 if (device->request_queue == NULL)
1596 device->request_queue->queuedata = device;
1598 elevator_exit(device->request_queue);
1599 rc = elevator_init(device->request_queue, &elevator_noop);
1601 blk_cleanup_queue(device->request_queue);
1609 * Allocate and initialize request queue.
1612 dasd_setup_queue(struct dasd_device * device)
1616 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1617 max = device->discipline->max_blocks << device->s2b_shift;
1618 blk_queue_max_sectors(device->request_queue, max);
1619 blk_queue_max_phys_segments(device->request_queue, -1L);
1620 blk_queue_max_hw_segments(device->request_queue, -1L);
1621 blk_queue_max_segment_size(device->request_queue, -1L);
1622 blk_queue_segment_boundary(device->request_queue, -1L);
1626 * Deactivate and free request queue.
1629 dasd_free_queue(struct dasd_device * device)
1631 if (device->request_queue) {
1632 blk_cleanup_queue(device->request_queue);
1633 device->request_queue = NULL;
1638 * Flush request on the request queue.
1641 dasd_flush_request_queue(struct dasd_device * device)
1643 struct request *req;
1645 if (!device->request_queue)
1648 spin_lock_irq(&device->request_queue_lock);
1649 while (!list_empty(&device->request_queue->queue_head)) {
1650 req = elv_next_request(device->request_queue);
1653 dasd_end_request(req, 0);
1654 blkdev_dequeue_request(req);
1656 spin_unlock_irq(&device->request_queue_lock);
1660 dasd_open(struct inode *inp, struct file *filp)
1662 struct gendisk *disk = inp->i_bdev->bd_disk;
1663 struct dasd_device *device = disk->private_data;
1666 atomic_inc(&device->open_count);
1667 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1672 if (!try_module_get(device->discipline->owner)) {
1677 if (dasd_probeonly) {
1679 "No access to device %s due to probeonly mode",
1685 if (device->state < DASD_STATE_BASIC) {
1686 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1687 " Cannot open unrecognized device");
1695 module_put(device->discipline->owner);
1697 atomic_dec(&device->open_count);
1702 dasd_release(struct inode *inp, struct file *filp)
1704 struct gendisk *disk = inp->i_bdev->bd_disk;
1705 struct dasd_device *device = disk->private_data;
1707 atomic_dec(&device->open_count);
1708 module_put(device->discipline->owner);
1712 struct block_device_operations
1713 dasd_device_operations = {
1714 .owner = THIS_MODULE,
1716 .release = dasd_release,
1717 .ioctl = dasd_ioctl,
1724 #ifdef CONFIG_PROC_FS
1728 dasd_gendisk_exit();
1730 devfs_remove("dasd");
1731 if (dasd_debug_area != NULL) {
1732 debug_unregister(dasd_debug_area);
1733 dasd_debug_area = NULL;
1738 * SECTION: common functions for ccw_driver use
1741 /* initial attempt at a probe function. this can be simplified once
1742 * the other detection code is gone */
1744 dasd_generic_probe (struct ccw_device *cdev,
1745 struct dasd_discipline *discipline)
1749 ret = dasd_add_sysfs_files(cdev);
1752 "dasd_generic_probe: could not add sysfs entries "
1753 "for %s\n", cdev->dev.bus_id);
1756 cdev->handler = &dasd_int_handler;
1761 /* this will one day be called from a global not_oper handler.
1762 * It is also used by driver_unregister during module unload */
1764 dasd_generic_remove (struct ccw_device *cdev)
1766 struct dasd_device *device;
1768 dasd_remove_sysfs_files(cdev);
1769 device = dasd_device_from_cdev(cdev);
1772 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1773 /* Already doing offline processing */
1774 dasd_put_device(device);
1778 * This device is removed unconditionally. Set offline
1779 * flag to prevent dasd_open from opening it while it is
1780 * no quite down yet.
1782 dasd_set_target_state(device, DASD_STATE_NEW);
1783 /* dasd_delete_device destroys the device reference. */
1784 dasd_delete_device(device);
1787 /* activate a device. This is called from dasd_{eckd,fba}_probe() when either
1788 * the device is detected for the first time and is supposed to be used
1789 * or the user has started activation through sysfs */
1791 dasd_generic_set_online (struct ccw_device *cdev,
1792 struct dasd_discipline *discipline)
1795 struct dasd_device *device;
1798 device = dasd_create_device(cdev);
1800 return PTR_ERR(device);
1802 if (test_bit(DASD_FLAG_USE_DIAG, &device->flags)) {
1803 if (!dasd_diag_discipline_pointer) {
1804 printk (KERN_WARNING
1805 "dasd_generic couldn't online device %s "
1806 "- discipline DIAG not available\n",
1808 dasd_delete_device(device);
1811 discipline = dasd_diag_discipline_pointer;
1813 device->discipline = discipline;
1815 rc = discipline->check_device(device);
1817 printk (KERN_WARNING
1818 "dasd_generic couldn't online device %s "
1819 "with discipline %s\n",
1820 cdev->dev.bus_id, discipline->name);
1821 dasd_delete_device(device);
1825 dasd_set_target_state(device, DASD_STATE_ONLINE);
1826 if (device->state <= DASD_STATE_KNOWN) {
1827 printk (KERN_WARNING
1828 "dasd_generic discipline not found for %s\n",
1831 dasd_set_target_state(device, DASD_STATE_NEW);
1832 dasd_delete_device(device);
1834 pr_debug("dasd_generic device %s found\n",
1837 /* FIXME: we have to wait for the root device but we don't want
1838 * to wait for each single device but for all at once. */
1839 wait_event(dasd_init_waitq, _wait_for_device(device));
1841 dasd_put_device(device);
1847 dasd_generic_set_offline (struct ccw_device *cdev)
1849 struct dasd_device *device;
1852 device = dasd_device_from_cdev(cdev);
1854 return PTR_ERR(device);
1855 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1856 /* Already doing offline processing */
1857 dasd_put_device(device);
1861 * We must make sure that this device is currently not in use.
1862 * The open_count is increased for every opener, that includes
1863 * the blkdev_get in dasd_scan_partitions. We are only interested
1864 * in the other openers.
1866 max_count = device->bdev ? 0 : -1;
1867 if (atomic_read(&device->open_count) > max_count) {
1868 printk (KERN_WARNING "Can't offline dasd device with open"
1870 atomic_read(&device->open_count));
1871 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
1872 dasd_put_device(device);
1875 dasd_set_target_state(device, DASD_STATE_NEW);
1876 /* dasd_delete_device destroys the device reference. */
1877 dasd_delete_device(device);
1883 dasd_generic_notify(struct ccw_device *cdev, int event)
1885 struct dasd_device *device;
1886 struct dasd_ccw_req *cqr;
1887 unsigned long flags;
1890 device = dasd_device_from_cdev(cdev);
1893 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1898 if (device->state < DASD_STATE_BASIC)
1900 /* Device is active. We want to keep it. */
1901 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
1902 list_for_each_entry(cqr, &device->ccw_queue, list)
1903 if (cqr->status == DASD_CQR_IN_IO)
1904 cqr->status = DASD_CQR_FAILED;
1905 device->stopped |= DASD_STOPPED_DC_EIO;
1906 dasd_schedule_bh(device);
1908 list_for_each_entry(cqr, &device->ccw_queue, list)
1909 if (cqr->status == DASD_CQR_IN_IO)
1910 cqr->status = DASD_CQR_QUEUED;
1911 device->stopped |= DASD_STOPPED_DC_WAIT;
1912 dasd_set_timer(device, 0);
1917 /* FIXME: add a sanity check. */
1918 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
1919 dasd_schedule_bh(device);
1923 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1924 dasd_put_device(device);
1929 * Automatically online either all dasd devices (dasd_autodetect) or
1930 * all devices specified with dasd= parameters.
1933 dasd_generic_auto_online (struct ccw_driver *dasd_discipline_driver)
1935 struct device_driver *drv;
1936 struct device *d, *dev;
1937 struct ccw_device *cdev;
1939 drv = get_driver(&dasd_discipline_driver->driver);
1940 down_read(&drv->bus->subsys.rwsem);
1942 list_for_each_entry(d, &drv->devices, driver_list) {
1943 dev = get_device(d);
1946 cdev = to_ccwdev(dev);
1947 if (dasd_autodetect || dasd_busid_known(cdev->dev.bus_id) == 0)
1948 ccw_device_set_online(cdev);
1951 up_read(&drv->bus->subsys.rwsem);
1960 init_waitqueue_head(&dasd_init_waitq);
1962 /* register 'common' DASD debug area, used for all DBF_XXX calls */
1963 dasd_debug_area = debug_register("dasd", 0, 2, 8 * sizeof (long));
1964 if (dasd_debug_area == NULL) {
1968 debug_register_view(dasd_debug_area, &debug_hex_ascii_view);
1969 debug_set_level(dasd_debug_area, DBF_ERR);
1971 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
1973 dasd_diag_discipline_pointer = NULL;
1975 rc = devfs_mk_dir("dasd");
1978 rc = dasd_devmap_init();
1981 rc = dasd_gendisk_init();
1987 rc = dasd_ioctl_init();
1990 #ifdef CONFIG_PROC_FS
1991 rc = dasd_proc_init();
1998 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2003 module_init(dasd_init);
2004 module_exit(dasd_exit);
2006 EXPORT_SYMBOL(dasd_debug_area);
2007 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2009 EXPORT_SYMBOL(dasd_add_request_head);
2010 EXPORT_SYMBOL(dasd_add_request_tail);
2011 EXPORT_SYMBOL(dasd_cancel_req);
2012 EXPORT_SYMBOL(dasd_clear_timer);
2013 EXPORT_SYMBOL(dasd_enable_device);
2014 EXPORT_SYMBOL(dasd_int_handler);
2015 EXPORT_SYMBOL(dasd_kfree_request);
2016 EXPORT_SYMBOL(dasd_kick_device);
2017 EXPORT_SYMBOL(dasd_kmalloc_request);
2018 EXPORT_SYMBOL(dasd_schedule_bh);
2019 EXPORT_SYMBOL(dasd_set_target_state);
2020 EXPORT_SYMBOL(dasd_set_timer);
2021 EXPORT_SYMBOL(dasd_sfree_request);
2022 EXPORT_SYMBOL(dasd_sleep_on);
2023 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2024 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2025 EXPORT_SYMBOL(dasd_smalloc_request);
2026 EXPORT_SYMBOL(dasd_start_IO);
2027 EXPORT_SYMBOL(dasd_term_IO);
2029 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2030 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2031 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2032 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2033 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
2034 EXPORT_SYMBOL_GPL(dasd_generic_auto_online);
2037 * Overrides for Emacs so that we follow Linus's tabbing style.
2038 * Emacs will notice this stuff at the end of the file and automatically
2039 * adjust the settings for this buffer only. This must remain at the end
2041 * ---------------------------------------------------------------------------
2044 * c-brace-imaginary-offset: 0
2045 * c-brace-offset: -4
2046 * c-argdecl-indent: 4
2047 * c-label-offset: -4
2048 * c-continued-statement-offset: 4
2049 * c-continued-brace-offset: 0
2050 * indent-tabs-mode: 1