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;
41 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
42 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
43 " Copyright 2000 IBM Corporation");
44 MODULE_SUPPORTED_DEVICE("dasd");
45 MODULE_PARM(dasd, "1-" __MODULE_STRING(256) "s");
46 MODULE_LICENSE("GPL");
49 * SECTION: prototypes for static functions of dasd.c
51 static int dasd_alloc_queue(struct dasd_device * device);
52 static void dasd_setup_queue(struct dasd_device * device);
53 static void dasd_free_queue(struct dasd_device * device);
54 static void dasd_flush_request_queue(struct dasd_device *);
55 static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
56 static void dasd_flush_ccw_queue(struct dasd_device *, int);
57 static void dasd_tasklet(struct dasd_device *);
58 static void do_kick_device(void *data);
61 * SECTION: Operations on the device structure.
63 static wait_queue_head_t dasd_init_waitq;
66 * Allocate memory for a new device structure.
69 dasd_alloc_device(void)
71 struct dasd_device *device;
73 device = kmalloc(sizeof (struct dasd_device), GFP_ATOMIC);
75 return ERR_PTR(-ENOMEM);
76 memset(device, 0, sizeof (struct dasd_device));
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)
118 kfree(device->private);
119 free_page((unsigned long) device->erp_mem);
120 free_pages((unsigned long) device->ccw_mem, 1);
125 * Make a new device known to the system.
128 dasd_state_new_to_known(struct dasd_device *device)
133 * As long as the device is not in state DASD_STATE_NEW we want to
134 * keep the reference count > 0.
136 dasd_get_device(device);
138 rc = dasd_alloc_queue(device);
140 dasd_put_device(device);
144 device->state = DASD_STATE_KNOWN;
149 * Let the system forget about a device.
152 dasd_state_known_to_new(struct dasd_device * device)
154 /* Forget the discipline information. */
155 device->discipline = NULL;
156 device->state = DASD_STATE_NEW;
158 dasd_free_queue(device);
160 /* Give up reference we took in dasd_state_new_to_known. */
161 dasd_put_device(device);
165 * Request the irq line for the device.
168 dasd_state_known_to_basic(struct dasd_device * device)
172 /* Allocate and register gendisk structure. */
173 rc = dasd_gendisk_alloc(device);
177 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
178 device->debug_area = debug_register(device->cdev->dev.bus_id, 0, 2,
180 debug_register_view(device->debug_area, &debug_sprintf_view);
181 debug_set_level(device->debug_area, DBF_ERR);
182 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
184 device->state = DASD_STATE_BASIC;
189 * Release the irq line for the device. Terminate any running i/o.
192 dasd_state_basic_to_known(struct dasd_device * device)
194 dasd_gendisk_free(device);
195 dasd_flush_ccw_queue(device, 1);
196 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
197 if (device->debug_area != NULL) {
198 debug_unregister(device->debug_area);
199 device->debug_area = NULL;
201 device->state = DASD_STATE_KNOWN;
205 * Do the initial analysis. The do_analysis function may return
206 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
207 * until the discipline decides to continue the startup sequence
208 * by calling the function dasd_change_state. The eckd disciplines
209 * uses this to start a ccw that detects the format. The completion
210 * interrupt for this detection ccw uses the kernel event daemon to
211 * trigger the call to dasd_change_state. All this is done in the
212 * discipline code, see dasd_eckd.c.
213 * After the analysis ccw is done (do_analysis returned 0 or error)
214 * the block device is setup. Either a fake disk is added to allow
215 * formatting or a proper device request queue is created.
218 dasd_state_basic_to_ready(struct dasd_device * device)
223 if (device->discipline->do_analysis != NULL)
224 rc = device->discipline->do_analysis(device);
227 dasd_setup_queue(device);
228 device->state = DASD_STATE_READY;
229 if (dasd_scan_partitions(device) != 0)
230 device->state = DASD_STATE_BASIC;
235 * Remove device from block device layer. Destroy dirty buffers.
236 * Forget format information. Check if the target level is basic
237 * and if it is create fake disk for formatting.
240 dasd_state_ready_to_basic(struct dasd_device * device)
242 dasd_flush_ccw_queue(device, 0);
243 dasd_destroy_partitions(device);
244 dasd_flush_request_queue(device);
246 device->bp_block = 0;
247 device->s2b_shift = 0;
248 device->state = DASD_STATE_BASIC;
252 * Make the device online and schedule the bottom half to start
253 * the requeueing of requests from the linux request queue to the
257 dasd_state_ready_to_online(struct dasd_device * device)
259 device->state = DASD_STATE_ONLINE;
260 dasd_schedule_bh(device);
265 * Stop the requeueing of requests again.
268 dasd_state_online_to_ready(struct dasd_device * device)
270 device->state = DASD_STATE_READY;
274 * Device startup state changes.
277 dasd_increase_state(struct dasd_device *device)
282 if (device->state == DASD_STATE_NEW &&
283 device->target >= DASD_STATE_KNOWN)
284 rc = dasd_state_new_to_known(device);
287 device->state == DASD_STATE_KNOWN &&
288 device->target >= DASD_STATE_BASIC)
289 rc = dasd_state_known_to_basic(device);
292 device->state == DASD_STATE_BASIC &&
293 device->target >= DASD_STATE_READY)
294 rc = dasd_state_basic_to_ready(device);
297 device->state == DASD_STATE_READY &&
298 device->target >= DASD_STATE_ONLINE)
299 rc = dasd_state_ready_to_online(device);
305 * Device shutdown state changes.
308 dasd_decrease_state(struct dasd_device *device)
310 if (device->state == DASD_STATE_ONLINE &&
311 device->target <= DASD_STATE_READY)
312 dasd_state_online_to_ready(device);
314 if (device->state == DASD_STATE_READY &&
315 device->target <= DASD_STATE_BASIC)
316 dasd_state_ready_to_basic(device);
318 if (device->state == DASD_STATE_BASIC &&
319 device->target <= DASD_STATE_KNOWN)
320 dasd_state_basic_to_known(device);
322 if (device->state == DASD_STATE_KNOWN &&
323 device->target <= DASD_STATE_NEW)
324 dasd_state_known_to_new(device);
330 * This is the main startup/shutdown routine.
333 dasd_change_state(struct dasd_device *device)
337 if (device->state == device->target)
338 /* Already where we want to go today... */
340 if (device->state < device->target)
341 rc = dasd_increase_state(device);
343 rc = dasd_decrease_state(device);
344 if (rc && rc != -EAGAIN)
345 device->target = device->state;
347 if (device->state == device->target)
348 wake_up(&dasd_init_waitq);
352 * Kick starter for devices that did not complete the startup/shutdown
353 * procedure or were sleeping because of a pending state.
354 * dasd_kick_device will schedule a call do do_kick_device to the kernel
358 do_kick_device(void *data)
360 struct dasd_device *device;
362 device = (struct dasd_device *) data;
363 dasd_change_state(device);
364 dasd_schedule_bh(device);
365 dasd_put_device(device);
369 dasd_kick_device(struct dasd_device *device)
371 dasd_get_device(device);
372 /* queue call to dasd_kick_device to the kernel event daemon. */
373 schedule_work(&device->kick_work);
377 * Set the target state for a device and starts the state change.
380 dasd_set_target_state(struct dasd_device *device, int target)
382 /* If we are in probeonly mode stop at DASD_STATE_READY. */
383 if (dasd_probeonly && target > DASD_STATE_READY)
384 target = DASD_STATE_READY;
385 if (device->target != target) {
386 if (device->state == target)
387 wake_up(&dasd_init_waitq);
388 device->target = target;
390 if (device->state != device->target)
391 dasd_change_state(device);
395 * Enable devices with device numbers in [from..to].
398 _wait_for_device(struct dasd_device *device)
400 return (device->state == device->target);
404 dasd_enable_device(struct dasd_device *device)
406 dasd_set_target_state(device, DASD_STATE_ONLINE);
407 if (device->state <= DASD_STATE_KNOWN)
408 /* No discipline for device found. */
409 dasd_set_target_state(device, DASD_STATE_NEW);
410 /* Now wait for the devices to come up. */
411 wait_event(dasd_init_waitq, _wait_for_device(device));
415 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
417 #ifdef CONFIG_DASD_PROFILE
419 struct dasd_profile_info_t dasd_global_profile;
420 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
423 * Increments counter in global and local profiling structures.
425 #define dasd_profile_counter(value, counter, device) \
428 for (index = 0; index < 31 && value >> (2+index); index++); \
429 dasd_global_profile.counter[index]++; \
430 device->profile.counter[index]++; \
434 * Add profiling information for cqr before execution.
437 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
441 unsigned int counter;
443 if (dasd_profile_level != DASD_PROFILE_ON)
446 /* count the length of the chanq for statistics */
448 list_for_each(l, &device->ccw_queue)
451 dasd_global_profile.dasd_io_nr_req[counter]++;
452 device->profile.dasd_io_nr_req[counter]++;
456 * Add profiling information for cqr after execution.
459 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
462 long strtime, irqtime, endtime, tottime; /* in microseconds */
463 long tottimeps, sectors;
465 if (dasd_profile_level != DASD_PROFILE_ON)
468 sectors = req->nr_sectors;
469 if (!cqr->buildclk || !cqr->startclk ||
470 !cqr->stopclk || !cqr->endclk ||
474 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
475 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
476 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
477 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
478 tottimeps = tottime / sectors;
480 if (!dasd_global_profile.dasd_io_reqs)
481 memset(&dasd_global_profile, 0,
482 sizeof (struct dasd_profile_info_t));
483 dasd_global_profile.dasd_io_reqs++;
484 dasd_global_profile.dasd_io_sects += sectors;
486 if (!device->profile.dasd_io_reqs)
487 memset(&device->profile, 0,
488 sizeof (struct dasd_profile_info_t));
489 device->profile.dasd_io_reqs++;
490 device->profile.dasd_io_sects += sectors;
492 dasd_profile_counter(sectors, dasd_io_secs, device);
493 dasd_profile_counter(tottime, dasd_io_times, device);
494 dasd_profile_counter(tottimeps, dasd_io_timps, device);
495 dasd_profile_counter(strtime, dasd_io_time1, device);
496 dasd_profile_counter(irqtime, dasd_io_time2, device);
497 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
498 dasd_profile_counter(endtime, dasd_io_time3, device);
501 #define dasd_profile_start(device, cqr, req) do {} while (0)
502 #define dasd_profile_end(device, cqr, req) do {} while (0)
503 #endif /* CONFIG_DASD_PROFILE */
506 * Allocate memory for a channel program with 'cplength' channel
507 * command words and 'datasize' additional space. There are two
508 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
509 * memory and 2) dasd_smalloc_request uses the static ccw memory
510 * that gets allocated for each device.
512 struct dasd_ccw_req *
513 dasd_kmalloc_request(char *magic, int cplength, int datasize,
514 struct dasd_device * device)
516 struct dasd_ccw_req *cqr;
519 if ( magic == NULL || datasize > PAGE_SIZE ||
520 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
522 debug_text_event ( dasd_debug_area, 1, "ALLC");
523 debug_text_event ( dasd_debug_area, 1, magic);
524 debug_int_event ( dasd_debug_area, 1, cplength);
525 debug_int_event ( dasd_debug_area, 1, datasize);
527 cqr = kmalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
529 return ERR_PTR(-ENOMEM);
530 memset(cqr, 0, sizeof(struct dasd_ccw_req));
533 cqr->cpaddr = kmalloc(cplength*sizeof(struct ccw1),
534 GFP_ATOMIC | GFP_DMA);
535 if (cqr->cpaddr == NULL) {
537 return ERR_PTR(-ENOMEM);
539 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
543 cqr->data = kmalloc(datasize, GFP_ATOMIC | GFP_DMA);
544 if (cqr->data == NULL) {
545 if (cqr->cpaddr != NULL)
548 return ERR_PTR(-ENOMEM);
550 memset(cqr->data, 0, datasize);
552 strncpy((char *) &cqr->magic, magic, 4);
553 ASCEBC((char *) &cqr->magic, 4);
554 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
555 dasd_get_device(device);
559 struct dasd_ccw_req *
560 dasd_smalloc_request(char *magic, int cplength, int datasize,
561 struct dasd_device * device)
564 struct dasd_ccw_req *cqr;
569 if ( magic == NULL || datasize > PAGE_SIZE ||
570 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
572 debug_text_event ( dasd_debug_area, 1, "ALLC");
573 debug_text_event ( dasd_debug_area, 1, magic);
574 debug_int_event ( dasd_debug_area, 1, cplength);
575 debug_int_event ( dasd_debug_area, 1, datasize);
577 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
579 size += cplength * sizeof(struct ccw1);
582 spin_lock_irqsave(&device->mem_lock, flags);
583 cqr = (struct dasd_ccw_req *)
584 dasd_alloc_chunk(&device->ccw_chunks, size);
585 spin_unlock_irqrestore(&device->mem_lock, flags);
587 return ERR_PTR(-ENOMEM);
588 memset(cqr, 0, sizeof(struct dasd_ccw_req));
589 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
592 cqr->cpaddr = (struct ccw1 *) data;
593 data += cplength*sizeof(struct ccw1);
594 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
599 memset(cqr->data, 0, datasize);
601 strncpy((char *) &cqr->magic, magic, 4);
602 ASCEBC((char *) &cqr->magic, 4);
603 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
604 dasd_get_device(device);
609 * Free memory of a channel program. This function needs to free all the
610 * idal lists that might have been created by dasd_set_cda and the
611 * struct dasd_ccw_req itself.
614 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
616 #ifdef CONFIG_ARCH_S390X
619 /* Clear any idals used for the request. */
622 clear_normalized_cda(ccw);
623 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
625 if (cqr->dstat != NULL)
627 debug_text_event ( dasd_debug_area, 1, "FREE");
628 debug_int_event ( dasd_debug_area, 1, (long) cqr);
629 if (cqr->cpaddr != NULL)
631 if (cqr->data != NULL)
634 dasd_put_device(device);
638 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
642 if (cqr->dstat != NULL)
644 debug_text_event(dasd_debug_area, 1, "FREE");
645 debug_int_event(dasd_debug_area, 1, (long) cqr);
646 spin_lock_irqsave(&device->mem_lock, flags);
647 dasd_free_chunk(&device->ccw_chunks, cqr);
648 spin_unlock_irqrestore(&device->mem_lock, flags);
649 dasd_put_device(device);
653 * Check discipline magic in cqr.
656 dasd_check_cqr(struct dasd_ccw_req *cqr)
658 struct dasd_device *device;
662 device = cqr->device;
663 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
664 DEV_MESSAGE(KERN_WARNING, device,
665 " dasd_ccw_req 0x%08x magic doesn't match"
666 " discipline 0x%08x",
668 *(unsigned int *) device->discipline->name);
675 * Terminate the current i/o and set the request to failed.
676 * ccw_device_clear can fail if the i/o subsystem
680 dasd_term_IO(struct dasd_ccw_req * cqr)
682 struct dasd_device *device;
686 rc = dasd_check_cqr(cqr);
690 device = (struct dasd_device *) cqr->device;
691 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
692 rc = ccw_device_clear(device->cdev, (long) cqr);
694 case 0: /* termination successful */
695 if (cqr->retries > 0) {
697 cqr->status = DASD_CQR_QUEUED;
699 cqr->status = DASD_CQR_FAILED;
700 cqr->stopclk = get_clock();
703 DBF_DEV_EVENT(DBF_ERR, device, "%s",
704 "device gone, retry");
707 DBF_DEV_EVENT(DBF_ERR, device, "%s",
712 DBF_DEV_EVENT(DBF_ERR, device, "%s",
713 "device busy, retry later");
716 DEV_MESSAGE(KERN_ERR, device,
717 "line %d unknown RC=%d, please "
718 "report to linux390@de.ibm.com",
725 dasd_schedule_bh(device);
730 * Start the i/o. This start_IO can fail if the channel is really busy.
731 * In that case set up a timer to start the request later.
734 dasd_start_IO(struct dasd_ccw_req * cqr)
736 struct dasd_device *device;
740 rc = dasd_check_cqr(cqr);
743 device = (struct dasd_device *) cqr->device;
744 cqr->startclk = get_clock();
745 cqr->starttime = jiffies;
746 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
750 cqr->status = DASD_CQR_IN_IO;
753 DBF_DEV_EVENT(DBF_ERR, device, "%s",
754 "start_IO: device busy, retry later");
757 DBF_DEV_EVENT(DBF_ERR, device, "%s",
758 "start_IO: request timeout, retry later");
762 DBF_DEV_EVENT(DBF_ERR, device, "%s",
763 "start_IO: device gone, retry");
766 DEV_MESSAGE(KERN_ERR, device,
767 "line %d unknown RC=%d, please report"
768 " to linux390@de.ibm.com", __LINE__, rc);
776 * Timeout function for dasd devices. This is used for different purposes
777 * 1) missing interrupt handler for normal operation
778 * 2) delayed start of request where start_IO failed with -EBUSY
779 * 3) timeout for missing state change interrupts
780 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
781 * DASD_CQR_QUEUED for 2) and 3).
784 dasd_timeout_device(unsigned long ptr)
787 struct dasd_device *device;
789 device = (struct dasd_device *) ptr;
790 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
791 /* re-activate request queue */
792 device->stopped &= ~DASD_STOPPED_PENDING;
793 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
794 dasd_schedule_bh(device);
798 * Setup timeout for a device in jiffies.
801 dasd_set_timer(struct dasd_device *device, int expires)
804 if (timer_pending(&device->timer))
805 del_timer(&device->timer);
808 if (timer_pending(&device->timer)) {
809 if (mod_timer(&device->timer, jiffies + expires))
812 device->timer.function = dasd_timeout_device;
813 device->timer.data = (unsigned long) device;
814 device->timer.expires = jiffies + expires;
815 add_timer(&device->timer);
819 * Clear timeout for a device.
822 dasd_clear_timer(struct dasd_device *device)
824 if (timer_pending(&device->timer))
825 del_timer(&device->timer);
829 * Handles the state change pending interrupt.
832 do_state_change_pending(void *data)
835 struct work_struct work;
836 struct dasd_device *device;
838 struct dasd_device *device;
839 struct dasd_ccw_req *cqr;
840 struct list_head *l, *n;
845 DBF_EVENT(DBF_NOTICE, "State change Interrupt for bus_id %s",
846 device->cdev->dev.bus_id);
847 device->stopped &= ~DASD_STOPPED_PENDING;
849 /* restart all 'running' IO on queue */
850 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
851 list_for_each_safe(l, n, &device->ccw_queue) {
852 cqr = list_entry(l, struct dasd_ccw_req, list);
853 if (cqr->status == DASD_CQR_IN_IO)
854 cqr->status = DASD_CQR_QUEUED;
856 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
857 dasd_set_timer (device, 0);
858 dasd_schedule_bh(device);
859 dasd_put_device(device);
864 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
866 struct dasd_ccw_req *cqr;
867 struct dasd_device *device;
869 cqr = (struct dasd_ccw_req *) intparm;
870 if (cqr->status != DASD_CQR_IN_IO) {
872 "invalid status in handle_killed_request: "
873 "bus_id %s, status %02x",
874 cdev->dev.bus_id, cqr->status);
878 device = (struct dasd_device *) cqr->device;
879 if (device == NULL ||
880 device != dasd_device_from_cdev(cdev) ||
881 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
882 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
887 /* Schedule request to be retried. */
888 cqr->status = DASD_CQR_QUEUED;
890 dasd_clear_timer(device);
891 dasd_schedule_bh(device);
892 dasd_put_device(device);
896 dasd_handle_state_change_pending(struct dasd_device *device)
899 struct work_struct work;
900 struct dasd_device *device;
903 p = kmalloc(sizeof(*p), GFP_ATOMIC);
905 /* No memory, let the timeout do the reactivation. */
907 INIT_WORK(&p->work, (void *) do_state_change_pending, p);
909 dasd_get_device(device);
910 schedule_work(&p->work);
914 * Interrupt handler for "normal" ssch-io based dasd devices.
917 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
920 struct dasd_ccw_req *cqr, *next;
921 struct dasd_device *device;
922 unsigned long long now;
928 switch (PTR_ERR(irb)) {
930 dasd_handle_killed_request(cdev, intparm);
933 printk(KERN_WARNING"%s(%s): request timed out\n",
934 __FUNCTION__, cdev->dev.bus_id);
935 //FIXME - dasd uses own timeout interface...
938 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
939 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
946 DBF_EVENT(DBF_DEBUG, "Interrupt: stat %02x, bus_id %s",
947 irb->scsw.dstat, cdev->dev.bus_id);
949 /* first of all check for state change pending interrupt */
950 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
951 if ((irb->scsw.dstat & mask) == mask) {
952 device = dasd_device_from_cdev(cdev);
953 if (!IS_ERR(device)) {
954 dasd_handle_state_change_pending(device);
955 dasd_put_device(device);
960 cqr = (struct dasd_ccw_req *) intparm;
962 * check status - the request might have been killed
963 * because of dyn detach
965 if (cqr->status != DASD_CQR_IN_IO) {
967 "invalid status: bus_id %s, status %02x",
968 cdev->dev.bus_id, cqr->status);
972 device = (struct dasd_device *) cqr->device;
973 if (device == NULL ||
974 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
975 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
980 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x",
981 ((irb->scsw.cstat << 8) | irb->scsw.dstat));
983 /* Find out the appropriate era_action. */
984 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
985 era = dasd_era_fatal;
986 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
987 irb->scsw.cstat == 0 &&
988 !irb->esw.esw0.erw.cons)
990 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
991 era = dasd_era_fatal; /* don't recover this request */
992 else if (irb->esw.esw0.erw.cons)
993 era = device->discipline->examine_error(cqr, irb);
995 era = dasd_era_recover;
997 DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
999 if (era == dasd_era_none) {
1000 cqr->status = DASD_CQR_DONE;
1002 /* Start first request on queue if possible -> fast_io. */
1003 if (cqr->list.next != &device->ccw_queue) {
1004 next = list_entry(cqr->list.next,
1005 struct dasd_ccw_req, list);
1006 if ((next->status == DASD_CQR_QUEUED) &&
1007 (!device->stopped)) {
1008 if (device->discipline->start_IO(next) == 0)
1009 expires = next->expires;
1011 DEV_MESSAGE(KERN_DEBUG, device, "%s",
1012 "Interrupt fastpath "
1016 } else { /* error */
1017 if (cqr->dstat == NULL)
1018 cqr->dstat = kmalloc(sizeof(struct irb), GFP_ATOMIC);
1020 memcpy(cqr->dstat, irb, sizeof (struct irb));
1022 DEV_MESSAGE(KERN_ERR, device, "%s",
1023 "no memory for dstat...ignoring");
1025 /* dump sense data */
1026 dasd_log_sense(cqr, irb);
1029 case dasd_era_fatal:
1030 cqr->status = DASD_CQR_FAILED;
1033 case dasd_era_recover:
1034 cqr->status = DASD_CQR_ERROR;
1041 dasd_set_timer(device, expires);
1043 dasd_clear_timer(device);
1044 dasd_schedule_bh(device);
1048 * posts the buffer_cache about a finalized request
1051 dasd_end_request(struct request *req, int uptodate)
1053 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1055 add_disk_randomness(req->rq_disk);
1056 end_that_request_last(req);
1060 * Process finished error recovery ccw.
1063 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1065 dasd_erp_fn_t erp_fn;
1067 if (cqr->status == DASD_CQR_DONE)
1068 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1070 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1071 erp_fn = device->discipline->erp_postaction(cqr);
1076 * Process ccw request queue.
1079 __dasd_process_ccw_queue(struct dasd_device * device,
1080 struct list_head *final_queue)
1082 struct list_head *l, *n;
1083 struct dasd_ccw_req *cqr;
1084 dasd_erp_fn_t erp_fn;
1087 /* Process request with final status. */
1088 list_for_each_safe(l, n, &device->ccw_queue) {
1089 cqr = list_entry(l, struct dasd_ccw_req, list);
1090 /* Stop list processing at the first non-final request. */
1091 if (cqr->status != DASD_CQR_DONE &&
1092 cqr->status != DASD_CQR_FAILED &&
1093 cqr->status != DASD_CQR_ERROR)
1095 /* Process requests with DASD_CQR_ERROR */
1096 if (cqr->status == DASD_CQR_ERROR) {
1098 if (cqr->dstat->scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1099 cqr->status = DASD_CQR_FAILED;
1100 cqr->stopclk = get_clock();
1102 if (cqr->dstat->esw.esw0.erw.cons) {
1103 erp_fn = device->discipline->erp_action(cqr);
1106 dasd_default_erp_action(cqr);
1110 /* Process finished ERP request. */
1112 __dasd_process_erp(device, cqr);
1116 /* Rechain finished requests to final queue */
1117 cqr->endclk = get_clock();
1118 list_move_tail(&cqr->list, final_queue);
1123 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1125 struct request *req;
1127 req = (struct request *) data;
1128 dasd_profile_end(cqr->device, cqr, req);
1129 spin_lock_irq(&cqr->device->request_queue_lock);
1130 dasd_end_request(req, (cqr->status == DASD_CQR_DONE));
1131 spin_unlock_irq(&cqr->device->request_queue_lock);
1132 dasd_sfree_request(cqr, cqr->device);
1137 * Fetch requests from the block device queue.
1140 __dasd_process_blk_queue(struct dasd_device * device)
1142 request_queue_t *queue;
1143 struct request *req;
1144 struct dasd_ccw_req *cqr;
1147 queue = device->request_queue;
1148 /* No queue ? Then there is nothing to do. */
1153 * We requeue request from the block device queue to the ccw
1154 * queue only in two states. In state DASD_STATE_READY the
1155 * partition detection is done and we need to requeue requests
1156 * for that. State DASD_STATE_ONLINE is normal block device
1159 if (device->state != DASD_STATE_READY &&
1160 device->state != DASD_STATE_ONLINE)
1163 /* Now we try to fetch requests from the request queue */
1164 list_for_each_entry(cqr, &device->ccw_queue, list)
1165 if (cqr->status == DASD_CQR_QUEUED)
1167 while (!blk_queue_plugged(queue) &&
1168 elv_next_request(queue) &&
1169 nr_queued < DASD_CHANQ_MAX_SIZE) {
1170 req = elv_next_request(queue);
1171 if (test_bit(DASD_FLAG_RO, &device->flags) &&
1172 rq_data_dir(req) == WRITE) {
1174 "(%s) Rejecting write request %p",
1175 device->cdev->dev.bus_id,
1177 blkdev_dequeue_request(req);
1178 dasd_end_request(req, 0);
1181 if (device->stopped & DASD_STOPPED_DC_EIO) {
1182 blkdev_dequeue_request(req);
1183 dasd_end_request(req, 0);
1186 cqr = device->discipline->build_cp(device, req);
1188 if (PTR_ERR(cqr) == -ENOMEM)
1189 break; /* terminate request queue loop */
1191 "(%s) CCW creation failed on request %p",
1192 device->cdev->dev.bus_id,
1194 blkdev_dequeue_request(req);
1195 dasd_end_request(req, 0);
1198 cqr->callback = dasd_end_request_cb;
1199 cqr->callback_data = (void *) req;
1200 cqr->status = DASD_CQR_QUEUED;
1201 blkdev_dequeue_request(req);
1202 list_add_tail(&cqr->list, &device->ccw_queue);
1203 dasd_profile_start(device, cqr, req);
1209 * Take a look at the first request on the ccw queue and check
1210 * if it reached its expire time. If so, terminate the IO.
1213 __dasd_check_expire(struct dasd_device * device)
1215 struct dasd_ccw_req *cqr;
1217 if (list_empty(&device->ccw_queue))
1219 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1220 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1221 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1222 if (device->discipline->term_IO(cqr) != 0)
1223 /* Hmpf, try again in 1/100 sec */
1224 dasd_set_timer(device, 1);
1230 * Take a look at the first request on the ccw queue and check
1231 * if it needs to be started.
1234 __dasd_start_head(struct dasd_device * device)
1236 struct dasd_ccw_req *cqr;
1239 if (list_empty(&device->ccw_queue))
1241 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1242 if ((cqr->status == DASD_CQR_QUEUED) &&
1243 (!device->stopped)) {
1244 /* try to start the first I/O that can be started */
1245 rc = device->discipline->start_IO(cqr);
1247 dasd_set_timer(device, cqr->expires);
1248 else if (rc == -EBUSY)
1249 /* Hmpf, try again in 1/100 sec */
1250 dasd_set_timer(device, 1);
1255 * Remove requests from the ccw queue.
1258 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1260 struct list_head flush_queue;
1261 struct list_head *l, *n;
1262 struct dasd_ccw_req *cqr;
1264 INIT_LIST_HEAD(&flush_queue);
1265 spin_lock_irq(get_ccwdev_lock(device->cdev));
1266 list_for_each_safe(l, n, &device->ccw_queue) {
1267 cqr = list_entry(l, struct dasd_ccw_req, list);
1268 /* Flush all request or only block device requests? */
1269 if (all == 0 && cqr->callback == dasd_end_request_cb)
1271 if (cqr->status == DASD_CQR_IN_IO)
1272 device->discipline->term_IO(cqr);
1273 if (cqr->status != DASD_CQR_DONE ||
1274 cqr->status != DASD_CQR_FAILED) {
1275 cqr->status = DASD_CQR_FAILED;
1276 cqr->stopclk = get_clock();
1278 /* Process finished ERP request. */
1280 __dasd_process_erp(device, cqr);
1283 /* Rechain request on device request queue */
1284 cqr->endclk = get_clock();
1285 list_move_tail(&cqr->list, &flush_queue);
1287 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1288 /* Now call the callback function of flushed requests */
1289 list_for_each_safe(l, n, &flush_queue) {
1290 cqr = list_entry(l, struct dasd_ccw_req, list);
1291 if (cqr->callback != NULL)
1292 (cqr->callback)(cqr, cqr->callback_data);
1297 * Acquire the device lock and process queues for the device.
1300 dasd_tasklet(struct dasd_device * device)
1302 struct list_head final_queue;
1303 struct list_head *l, *n;
1304 struct dasd_ccw_req *cqr;
1306 atomic_set (&device->tasklet_scheduled, 0);
1307 INIT_LIST_HEAD(&final_queue);
1308 spin_lock_irq(get_ccwdev_lock(device->cdev));
1309 /* Check expire time of first request on the ccw queue. */
1310 __dasd_check_expire(device);
1311 /* Finish off requests on ccw queue */
1312 __dasd_process_ccw_queue(device, &final_queue);
1313 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1314 /* Now call the callback function of requests with final status */
1315 list_for_each_safe(l, n, &final_queue) {
1316 cqr = list_entry(l, struct dasd_ccw_req, list);
1317 list_del(&cqr->list);
1318 if (cqr->callback != NULL)
1319 (cqr->callback)(cqr, cqr->callback_data);
1321 spin_lock_irq(&device->request_queue_lock);
1322 spin_lock(get_ccwdev_lock(device->cdev));
1323 /* Get new request from the block device request queue */
1324 __dasd_process_blk_queue(device);
1325 /* Now check if the head of the ccw queue needs to be started. */
1326 __dasd_start_head(device);
1327 spin_unlock(get_ccwdev_lock(device->cdev));
1328 spin_unlock_irq(&device->request_queue_lock);
1329 dasd_put_device(device);
1333 * Schedules a call to dasd_tasklet over the device tasklet.
1336 dasd_schedule_bh(struct dasd_device * device)
1338 /* Protect against rescheduling. */
1339 if (atomic_compare_and_swap (0, 1, &device->tasklet_scheduled))
1341 dasd_get_device(device);
1342 tasklet_hi_schedule(&device->tasklet);
1346 * Queue a request to the head of the ccw_queue. Start the I/O if
1350 dasd_add_request_head(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(&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);
1366 * Queue a request to the tail of the ccw_queue. Start the I/O if
1370 dasd_add_request_tail(struct dasd_ccw_req *req)
1372 struct dasd_device *device;
1373 unsigned long flags;
1375 device = req->device;
1376 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1377 req->status = DASD_CQR_QUEUED;
1378 req->device = device;
1379 list_add_tail(&req->list, &device->ccw_queue);
1380 /* let the bh start the request to keep them in order */
1381 dasd_schedule_bh(device);
1382 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1389 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1391 wake_up((wait_queue_head_t *) data);
1395 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1397 struct dasd_device *device;
1400 device = cqr->device;
1401 spin_lock_irq(get_ccwdev_lock(device->cdev));
1402 rc = cqr->status == DASD_CQR_DONE || cqr->status == DASD_CQR_FAILED;
1403 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1408 * Attempts to start a special ccw queue and waits for its completion.
1411 dasd_sleep_on(struct dasd_ccw_req * cqr)
1413 wait_queue_head_t wait_q;
1414 struct dasd_device *device;
1417 device = cqr->device;
1418 spin_lock_irq(get_ccwdev_lock(device->cdev));
1420 init_waitqueue_head (&wait_q);
1421 cqr->callback = dasd_wakeup_cb;
1422 cqr->callback_data = (void *) &wait_q;
1423 cqr->status = DASD_CQR_QUEUED;
1424 list_add_tail(&cqr->list, &device->ccw_queue);
1426 /* let the bh start the request to keep them in order */
1427 dasd_schedule_bh(device);
1429 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1431 wait_event(wait_q, _wait_for_wakeup(cqr));
1433 /* Request status is either done or failed. */
1434 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1439 * Attempts to start a special ccw queue and wait interruptible
1440 * for its completion.
1443 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1445 wait_queue_head_t wait_q;
1446 struct dasd_device *device;
1449 device = cqr->device;
1450 spin_lock_irq(get_ccwdev_lock(device->cdev));
1452 init_waitqueue_head (&wait_q);
1453 cqr->callback = dasd_wakeup_cb;
1454 cqr->callback_data = (void *) &wait_q;
1455 cqr->status = DASD_CQR_QUEUED;
1456 list_add_tail(&cqr->list, &device->ccw_queue);
1458 /* let the bh start the request to keep them in order */
1459 dasd_schedule_bh(device);
1460 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1464 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1465 if (rc != -ERESTARTSYS) {
1466 /* Request status is either done or failed. */
1467 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1470 spin_lock_irq(get_ccwdev_lock(device->cdev));
1471 if (cqr->status == DASD_CQR_IN_IO &&
1472 device->discipline->term_IO(cqr) == 0) {
1473 list_del(&cqr->list);
1476 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1482 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1483 * for eckd devices) the currently running request has to be terminated
1484 * and be put back to status queued, before the special request is added
1485 * to the head of the queue. Then the special request is waited on normally.
1488 _dasd_term_running_cqr(struct dasd_device *device)
1490 struct dasd_ccw_req *cqr;
1493 if (list_empty(&device->ccw_queue))
1495 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1496 rc = device->discipline->term_IO(cqr);
1498 /* termination successful */
1499 cqr->status = DASD_CQR_QUEUED;
1500 cqr->startclk = cqr->stopclk = 0;
1507 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1509 wait_queue_head_t wait_q;
1510 struct dasd_device *device;
1513 device = cqr->device;
1514 spin_lock_irq(get_ccwdev_lock(device->cdev));
1515 rc = _dasd_term_running_cqr(device);
1517 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1521 init_waitqueue_head (&wait_q);
1522 cqr->callback = dasd_wakeup_cb;
1523 cqr->callback_data = (void *) &wait_q;
1524 cqr->status = DASD_CQR_QUEUED;
1525 list_add(&cqr->list, &device->ccw_queue);
1527 /* let the bh start the request to keep them in order */
1528 dasd_schedule_bh(device);
1530 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1532 wait_event(wait_q, _wait_for_wakeup(cqr));
1534 /* Request status is either done or failed. */
1535 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1540 * Cancels a request that was started with dasd_sleep_on_req.
1541 * This is useful to timeout requests. The request will be
1542 * terminated if it is currently in i/o.
1543 * Returns 1 if the request has been terminated.
1546 dasd_cancel_req(struct dasd_ccw_req *cqr)
1548 struct dasd_device *device = cqr->device;
1549 unsigned long flags;
1553 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1554 switch (cqr->status) {
1555 case DASD_CQR_QUEUED:
1556 /* request was not started - just set to failed */
1557 cqr->status = DASD_CQR_FAILED;
1559 case DASD_CQR_IN_IO:
1560 /* request in IO - terminate IO and release again */
1561 if (device->discipline->term_IO(cqr) != 0)
1562 /* what to do if unable to terminate ??????
1564 cqr->status = DASD_CQR_FAILED;
1565 cqr->stopclk = get_clock();
1569 case DASD_CQR_FAILED:
1570 /* already finished - do nothing */
1573 DEV_MESSAGE(KERN_ALERT, device,
1574 "invalid status %02x in request",
1579 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1580 dasd_schedule_bh(device);
1585 * SECTION: Block device operations (request queue, partitions, open, release).
1589 * Dasd request queue function. Called from ll_rw_blk.c
1592 do_dasd_request(request_queue_t * queue)
1594 struct dasd_device *device;
1596 device = (struct dasd_device *) queue->queuedata;
1597 spin_lock(get_ccwdev_lock(device->cdev));
1598 /* Get new request from the block device request queue */
1599 __dasd_process_blk_queue(device);
1600 /* Now check if the head of the ccw queue needs to be started. */
1601 __dasd_start_head(device);
1602 spin_unlock(get_ccwdev_lock(device->cdev));
1606 * Allocate and initialize request queue.
1609 dasd_alloc_queue(struct dasd_device * device)
1611 device->request_queue = blk_init_queue(do_dasd_request,
1612 &device->request_queue_lock);
1613 if (device->request_queue == NULL)
1616 device->request_queue->queuedata = device;
1618 elevator_exit(device->request_queue);
1619 rc = elevator_init(device->request_queue, &elevator_noop);
1621 blk_cleanup_queue(device->request_queue);
1629 * Allocate and initialize request queue.
1632 dasd_setup_queue(struct dasd_device * device)
1636 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1637 max = device->discipline->max_blocks << device->s2b_shift;
1638 blk_queue_max_sectors(device->request_queue, max);
1639 blk_queue_max_phys_segments(device->request_queue, -1L);
1640 blk_queue_max_hw_segments(device->request_queue, -1L);
1641 blk_queue_max_segment_size(device->request_queue, -1L);
1642 blk_queue_segment_boundary(device->request_queue, -1L);
1646 * Deactivate and free request queue.
1649 dasd_free_queue(struct dasd_device * device)
1651 if (device->request_queue) {
1652 blk_cleanup_queue(device->request_queue);
1653 device->request_queue = NULL;
1658 * Flush request on the request queue.
1661 dasd_flush_request_queue(struct dasd_device * device)
1663 struct request *req;
1665 if (!device->request_queue)
1668 spin_lock_irq(&device->request_queue_lock);
1669 while (!list_empty(&device->request_queue->queue_head)) {
1670 req = elv_next_request(device->request_queue);
1673 dasd_end_request(req, 0);
1674 blkdev_dequeue_request(req);
1676 spin_unlock_irq(&device->request_queue_lock);
1680 dasd_open(struct inode *inp, struct file *filp)
1682 struct gendisk *disk = inp->i_bdev->bd_disk;
1683 struct dasd_device *device = disk->private_data;
1686 atomic_inc(&device->open_count);
1687 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1692 if (!try_module_get(device->discipline->owner)) {
1697 if (dasd_probeonly) {
1699 "No access to device %s due to probeonly mode",
1705 if (device->state < DASD_STATE_BASIC) {
1706 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1707 " Cannot open unrecognized device");
1715 module_put(device->discipline->owner);
1717 atomic_dec(&device->open_count);
1722 dasd_release(struct inode *inp, struct file *filp)
1724 struct gendisk *disk = inp->i_bdev->bd_disk;
1725 struct dasd_device *device = disk->private_data;
1727 atomic_dec(&device->open_count);
1728 module_put(device->discipline->owner);
1732 struct block_device_operations
1733 dasd_device_operations = {
1734 .owner = THIS_MODULE,
1736 .release = dasd_release,
1737 .ioctl = dasd_ioctl,
1744 #ifdef CONFIG_PROC_FS
1748 dasd_gendisk_exit();
1750 devfs_remove("dasd");
1751 if (dasd_debug_area != NULL) {
1752 debug_unregister(dasd_debug_area);
1753 dasd_debug_area = NULL;
1758 * SECTION: common functions for ccw_driver use
1761 /* initial attempt at a probe function. this can be simplified once
1762 * the other detection code is gone */
1764 dasd_generic_probe (struct ccw_device *cdev,
1765 struct dasd_discipline *discipline)
1769 ret = dasd_add_sysfs_files(cdev);
1772 "dasd_generic_probe: could not add sysfs entries "
1773 "for %s\n", cdev->dev.bus_id);
1776 cdev->handler = &dasd_int_handler;
1781 /* this will one day be called from a global not_oper handler.
1782 * It is also used by driver_unregister during module unload */
1784 dasd_generic_remove (struct ccw_device *cdev)
1786 struct dasd_device *device;
1788 dasd_remove_sysfs_files(cdev);
1789 device = dasd_device_from_cdev(cdev);
1792 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1793 /* Already doing offline processing */
1794 dasd_put_device(device);
1798 * This device is removed unconditionally. Set offline
1799 * flag to prevent dasd_open from opening it while it is
1800 * no quite down yet.
1802 dasd_set_target_state(device, DASD_STATE_NEW);
1803 /* dasd_delete_device destroys the device reference. */
1804 dasd_delete_device(device);
1807 /* activate a device. This is called from dasd_{eckd,fba}_probe() when either
1808 * the device is detected for the first time and is supposed to be used
1809 * or the user has started activation through sysfs */
1811 dasd_generic_set_online (struct ccw_device *cdev,
1812 struct dasd_discipline *discipline)
1815 struct dasd_device *device;
1818 device = dasd_create_device(cdev);
1820 return PTR_ERR(device);
1822 if (test_bit(DASD_FLAG_USE_DIAG, &device->flags)) {
1823 if (!dasd_diag_discipline_pointer) {
1824 printk (KERN_WARNING
1825 "dasd_generic couldn't online device %s "
1826 "- discipline DIAG not available\n",
1828 dasd_delete_device(device);
1831 discipline = dasd_diag_discipline_pointer;
1833 device->discipline = discipline;
1835 rc = discipline->check_device(device);
1837 printk (KERN_WARNING
1838 "dasd_generic couldn't online device %s "
1839 "with discipline %s\n",
1840 cdev->dev.bus_id, discipline->name);
1841 dasd_delete_device(device);
1845 dasd_set_target_state(device, DASD_STATE_ONLINE);
1846 if (device->state <= DASD_STATE_KNOWN) {
1847 printk (KERN_WARNING
1848 "dasd_generic discipline not found for %s\n",
1851 dasd_set_target_state(device, DASD_STATE_NEW);
1852 dasd_delete_device(device);
1854 pr_debug("dasd_generic device %s found\n",
1857 /* FIXME: we have to wait for the root device but we don't want
1858 * to wait for each single device but for all at once. */
1859 wait_event(dasd_init_waitq, _wait_for_device(device));
1861 dasd_put_device(device);
1867 dasd_generic_set_offline (struct ccw_device *cdev)
1869 struct dasd_device *device;
1872 device = dasd_device_from_cdev(cdev);
1874 return PTR_ERR(device);
1875 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1876 /* Already doing offline processing */
1877 dasd_put_device(device);
1881 * We must make sure that this device is currently not in use.
1882 * The open_count is increased for every opener, that includes
1883 * the blkdev_get in dasd_scan_partitions. We are only interested
1884 * in the other openers.
1886 max_count = device->bdev ? 0 : -1;
1887 if (atomic_read(&device->open_count) > max_count) {
1888 printk (KERN_WARNING "Can't offline dasd device with open"
1890 atomic_read(&device->open_count));
1891 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
1892 dasd_put_device(device);
1895 dasd_set_target_state(device, DASD_STATE_NEW);
1896 /* dasd_delete_device destroys the device reference. */
1897 dasd_delete_device(device);
1903 dasd_generic_notify(struct ccw_device *cdev, int event)
1905 struct dasd_device *device;
1906 struct dasd_ccw_req *cqr;
1907 unsigned long flags;
1910 device = dasd_device_from_cdev(cdev);
1913 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1918 if (device->state < DASD_STATE_BASIC)
1920 /* Device is active. We want to keep it. */
1921 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
1922 list_for_each_entry(cqr, &device->ccw_queue, list)
1923 if (cqr->status == DASD_CQR_IN_IO)
1924 cqr->status = DASD_CQR_FAILED;
1925 device->stopped |= DASD_STOPPED_DC_EIO;
1926 dasd_schedule_bh(device);
1928 list_for_each_entry(cqr, &device->ccw_queue, list)
1929 if (cqr->status == DASD_CQR_IN_IO)
1930 cqr->status = DASD_CQR_QUEUED;
1931 device->stopped |= DASD_STOPPED_DC_WAIT;
1932 dasd_set_timer(device, 0);
1937 /* FIXME: add a sanity check. */
1938 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
1939 dasd_schedule_bh(device);
1943 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
1944 dasd_put_device(device);
1949 * Automatically online either all dasd devices (dasd_autodetect) or
1950 * all devices specified with dasd= parameters.
1953 dasd_generic_auto_online (struct ccw_driver *dasd_discipline_driver)
1955 struct device_driver *drv;
1956 struct device *d, *dev;
1957 struct ccw_device *cdev;
1959 drv = get_driver(&dasd_discipline_driver->driver);
1960 down_read(&drv->bus->subsys.rwsem);
1962 list_for_each_entry(d, &drv->devices, driver_list) {
1963 dev = get_device(d);
1966 cdev = to_ccwdev(dev);
1967 if (dasd_autodetect || dasd_busid_known(cdev->dev.bus_id) == 0)
1968 ccw_device_set_online(cdev);
1971 up_read(&drv->bus->subsys.rwsem);
1980 init_waitqueue_head(&dasd_init_waitq);
1982 /* register 'common' DASD debug area, used faor all DBF_XXX calls */
1983 dasd_debug_area = debug_register("dasd", 0, 2, 8 * sizeof (long));
1984 if (dasd_debug_area == NULL) {
1988 debug_register_view(dasd_debug_area, &debug_hex_ascii_view);
1989 debug_set_level(dasd_debug_area, DBF_ERR);
1991 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
1993 rc = devfs_mk_dir("dasd");
1996 rc = dasd_devmap_init();
1999 rc = dasd_gendisk_init();
2005 rc = dasd_ioctl_init();
2008 #ifdef CONFIG_PROC_FS
2009 rc = dasd_proc_init();
2016 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2021 module_init(dasd_init);
2022 module_exit(dasd_exit);
2024 EXPORT_SYMBOL(dasd_debug_area);
2026 EXPORT_SYMBOL(dasd_add_request_head);
2027 EXPORT_SYMBOL(dasd_add_request_tail);
2028 EXPORT_SYMBOL(dasd_cancel_req);
2029 EXPORT_SYMBOL(dasd_clear_timer);
2030 EXPORT_SYMBOL(dasd_enable_device);
2031 EXPORT_SYMBOL(dasd_int_handler);
2032 EXPORT_SYMBOL(dasd_kfree_request);
2033 EXPORT_SYMBOL(dasd_kick_device);
2034 EXPORT_SYMBOL(dasd_kmalloc_request);
2035 EXPORT_SYMBOL(dasd_schedule_bh);
2036 EXPORT_SYMBOL(dasd_set_target_state);
2037 EXPORT_SYMBOL(dasd_set_timer);
2038 EXPORT_SYMBOL(dasd_sfree_request);
2039 EXPORT_SYMBOL(dasd_sleep_on);
2040 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2041 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2042 EXPORT_SYMBOL(dasd_smalloc_request);
2043 EXPORT_SYMBOL(dasd_start_IO);
2044 EXPORT_SYMBOL(dasd_term_IO);
2046 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2047 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2048 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2049 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2050 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
2051 EXPORT_SYMBOL_GPL(dasd_generic_auto_online);
2054 * Overrides for Emacs so that we follow Linus's tabbing style.
2055 * Emacs will notice this stuff at the end of the file and automatically
2056 * adjust the settings for this buffer only. This must remain at the end
2058 * ---------------------------------------------------------------------------
2061 * c-brace-imaginary-offset: 0
2062 * c-brace-offset: -4
2063 * c-argdecl-indent: 4
2064 * c-label-offset: -4
2065 * c-continued-statement-offset: 4
2066 * c-continued-brace-offset: 0
2067 * indent-tabs-mode: 1