2 * File...........: linux/drivers/s390/block/dasd.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
12 #include <linux/config.h>
13 #include <linux/kmod.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <linux/ctype.h>
17 #include <linux/major.h>
18 #include <linux/slab.h>
19 #include <linux/buffer_head.h>
20 #include <linux/hdreg.h>
22 #include <asm/ccwdev.h>
23 #include <asm/ebcdic.h>
24 #include <asm/idals.h>
25 #include <asm/todclk.h>
28 #define PRINTK_HEADER "dasd:"
32 * SECTION: Constant definitions to be used within this file
34 #define DASD_CHANQ_MAX_SIZE 4
37 * SECTION: exported variables of dasd.c
39 debug_info_t *dasd_debug_area;
40 struct dasd_discipline *dasd_diag_discipline_pointer;
42 MODULE_AUTHOR("Holger Smolinski <Holger.Smolinski@de.ibm.com>");
43 MODULE_DESCRIPTION("Linux on S/390 DASD device driver,"
44 " Copyright 2000 IBM Corporation");
45 MODULE_SUPPORTED_DEVICE("dasd");
46 MODULE_PARM(dasd, "1-" __MODULE_STRING(256) "s");
47 MODULE_LICENSE("GPL");
50 * SECTION: prototypes for static functions of dasd.c
52 static int dasd_alloc_queue(struct dasd_device * device);
53 static void dasd_setup_queue(struct dasd_device * device);
54 static void dasd_free_queue(struct dasd_device * device);
55 static void dasd_flush_request_queue(struct dasd_device *);
56 static void dasd_int_handler(struct ccw_device *, unsigned long, struct irb *);
57 static void dasd_flush_ccw_queue(struct dasd_device *, int);
58 static void dasd_tasklet(struct dasd_device *);
59 static void do_kick_device(void *data);
62 * SECTION: Operations on the device structure.
64 static wait_queue_head_t dasd_init_waitq;
67 * Allocate memory for a new device structure.
70 dasd_alloc_device(void)
72 struct dasd_device *device;
74 device = 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)
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 if (device->discipline)
156 module_put(device->discipline->owner);
157 device->discipline = NULL;
158 if (device->base_discipline)
159 module_put(device->base_discipline->owner);
160 device->base_discipline = NULL;
161 device->state = DASD_STATE_NEW;
163 dasd_free_queue(device);
165 /* Give up reference we took in dasd_state_new_to_known. */
166 dasd_put_device(device);
170 * Request the irq line for the device.
173 dasd_state_known_to_basic(struct dasd_device * device)
177 /* Allocate and register gendisk structure. */
178 rc = dasd_gendisk_alloc(device);
182 /* register 'device' debug area, used for all DBF_DEV_XXX calls */
183 device->debug_area = debug_register(device->cdev->dev.bus_id, 1, 2,
185 debug_register_view(device->debug_area, &debug_sprintf_view);
186 debug_set_level(device->debug_area, DBF_EMERG);
187 DBF_DEV_EVENT(DBF_EMERG, device, "%s", "debug area created");
189 device->state = DASD_STATE_BASIC;
194 * Release the irq line for the device. Terminate any running i/o.
197 dasd_state_basic_to_known(struct dasd_device * device)
199 dasd_gendisk_free(device);
200 dasd_flush_ccw_queue(device, 1);
201 DBF_DEV_EVENT(DBF_EMERG, device, "%p debug area deleted", device);
202 if (device->debug_area != NULL) {
203 debug_unregister(device->debug_area);
204 device->debug_area = NULL;
206 device->state = DASD_STATE_KNOWN;
210 * Do the initial analysis. The do_analysis function may return
211 * -EAGAIN in which case the device keeps the state DASD_STATE_BASIC
212 * until the discipline decides to continue the startup sequence
213 * by calling the function dasd_change_state. The eckd disciplines
214 * uses this to start a ccw that detects the format. The completion
215 * interrupt for this detection ccw uses the kernel event daemon to
216 * trigger the call to dasd_change_state. All this is done in the
217 * discipline code, see dasd_eckd.c.
218 * After the analysis ccw is done (do_analysis returned 0 or error)
219 * the block device is setup. Either a fake disk is added to allow
220 * formatting or a proper device request queue is created.
223 dasd_state_basic_to_ready(struct dasd_device * device)
228 if (device->discipline->do_analysis != NULL)
229 rc = device->discipline->do_analysis(device);
232 dasd_setup_queue(device);
233 device->state = DASD_STATE_READY;
234 if (dasd_scan_partitions(device) != 0)
235 device->state = DASD_STATE_BASIC;
240 * Remove device from block device layer. Destroy dirty buffers.
241 * Forget format information. Check if the target level is basic
242 * and if it is create fake disk for formatting.
245 dasd_state_ready_to_basic(struct dasd_device * device)
247 dasd_flush_ccw_queue(device, 0);
248 dasd_destroy_partitions(device);
249 dasd_flush_request_queue(device);
251 device->bp_block = 0;
252 device->s2b_shift = 0;
253 device->state = DASD_STATE_BASIC;
257 * Make the device online and schedule the bottom half to start
258 * the requeueing of requests from the linux request queue to the
262 dasd_state_ready_to_online(struct dasd_device * device)
264 device->state = DASD_STATE_ONLINE;
265 dasd_schedule_bh(device);
270 * Stop the requeueing of requests again.
273 dasd_state_online_to_ready(struct dasd_device * device)
275 device->state = DASD_STATE_READY;
279 * Device startup state changes.
282 dasd_increase_state(struct dasd_device *device)
287 if (device->state == DASD_STATE_NEW &&
288 device->target >= DASD_STATE_KNOWN)
289 rc = dasd_state_new_to_known(device);
292 device->state == DASD_STATE_KNOWN &&
293 device->target >= DASD_STATE_BASIC)
294 rc = dasd_state_known_to_basic(device);
297 device->state == DASD_STATE_BASIC &&
298 device->target >= DASD_STATE_READY)
299 rc = dasd_state_basic_to_ready(device);
302 device->state == DASD_STATE_READY &&
303 device->target >= DASD_STATE_ONLINE)
304 rc = dasd_state_ready_to_online(device);
310 * Device shutdown state changes.
313 dasd_decrease_state(struct dasd_device *device)
315 if (device->state == DASD_STATE_ONLINE &&
316 device->target <= DASD_STATE_READY)
317 dasd_state_online_to_ready(device);
319 if (device->state == DASD_STATE_READY &&
320 device->target <= DASD_STATE_BASIC)
321 dasd_state_ready_to_basic(device);
323 if (device->state == DASD_STATE_BASIC &&
324 device->target <= DASD_STATE_KNOWN)
325 dasd_state_basic_to_known(device);
327 if (device->state == DASD_STATE_KNOWN &&
328 device->target <= DASD_STATE_NEW)
329 dasd_state_known_to_new(device);
335 * This is the main startup/shutdown routine.
338 dasd_change_state(struct dasd_device *device)
342 if (device->state == device->target)
343 /* Already where we want to go today... */
345 if (device->state < device->target)
346 rc = dasd_increase_state(device);
348 rc = dasd_decrease_state(device);
349 if (rc && rc != -EAGAIN)
350 device->target = device->state;
352 if (device->state == device->target)
353 wake_up(&dasd_init_waitq);
357 * Kick starter for devices that did not complete the startup/shutdown
358 * procedure or were sleeping because of a pending state.
359 * dasd_kick_device will schedule a call do do_kick_device to the kernel
363 do_kick_device(void *data)
365 struct dasd_device *device;
367 device = (struct dasd_device *) data;
368 dasd_change_state(device);
369 dasd_schedule_bh(device);
370 dasd_put_device(device);
374 dasd_kick_device(struct dasd_device *device)
376 dasd_get_device(device);
377 /* queue call to dasd_kick_device to the kernel event daemon. */
378 schedule_work(&device->kick_work);
382 * Set the target state for a device and starts the state change.
385 dasd_set_target_state(struct dasd_device *device, int target)
387 /* If we are in probeonly mode stop at DASD_STATE_READY. */
388 if (dasd_probeonly && target > DASD_STATE_READY)
389 target = DASD_STATE_READY;
390 if (device->target != target) {
391 if (device->state == target)
392 wake_up(&dasd_init_waitq);
393 device->target = target;
395 if (device->state != device->target)
396 dasd_change_state(device);
400 * Enable devices with device numbers in [from..to].
403 _wait_for_device(struct dasd_device *device)
405 return (device->state == device->target);
409 dasd_enable_device(struct dasd_device *device)
411 dasd_set_target_state(device, DASD_STATE_ONLINE);
412 if (device->state <= DASD_STATE_KNOWN)
413 /* No discipline for device found. */
414 dasd_set_target_state(device, DASD_STATE_NEW);
415 /* Now wait for the devices to come up. */
416 wait_event(dasd_init_waitq, _wait_for_device(device));
420 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
422 #ifdef CONFIG_DASD_PROFILE
424 struct dasd_profile_info_t dasd_global_profile;
425 unsigned int dasd_profile_level = DASD_PROFILE_OFF;
428 * Increments counter in global and local profiling structures.
430 #define dasd_profile_counter(value, counter, device) \
433 for (index = 0; index < 31 && value >> (2+index); index++); \
434 dasd_global_profile.counter[index]++; \
435 device->profile.counter[index]++; \
439 * Add profiling information for cqr before execution.
442 dasd_profile_start(struct dasd_device *device, struct dasd_ccw_req * cqr,
446 unsigned int counter;
448 if (dasd_profile_level != DASD_PROFILE_ON)
451 /* count the length of the chanq for statistics */
453 list_for_each(l, &device->ccw_queue)
456 dasd_global_profile.dasd_io_nr_req[counter]++;
457 device->profile.dasd_io_nr_req[counter]++;
461 * Add profiling information for cqr after execution.
464 dasd_profile_end(struct dasd_device *device, struct dasd_ccw_req * cqr,
467 long strtime, irqtime, endtime, tottime; /* in microseconds */
468 long tottimeps, sectors;
470 if (dasd_profile_level != DASD_PROFILE_ON)
473 sectors = req->nr_sectors;
474 if (!cqr->buildclk || !cqr->startclk ||
475 !cqr->stopclk || !cqr->endclk ||
479 strtime = ((cqr->startclk - cqr->buildclk) >> 12);
480 irqtime = ((cqr->stopclk - cqr->startclk) >> 12);
481 endtime = ((cqr->endclk - cqr->stopclk) >> 12);
482 tottime = ((cqr->endclk - cqr->buildclk) >> 12);
483 tottimeps = tottime / sectors;
485 if (!dasd_global_profile.dasd_io_reqs)
486 memset(&dasd_global_profile, 0,
487 sizeof (struct dasd_profile_info_t));
488 dasd_global_profile.dasd_io_reqs++;
489 dasd_global_profile.dasd_io_sects += sectors;
491 if (!device->profile.dasd_io_reqs)
492 memset(&device->profile, 0,
493 sizeof (struct dasd_profile_info_t));
494 device->profile.dasd_io_reqs++;
495 device->profile.dasd_io_sects += sectors;
497 dasd_profile_counter(sectors, dasd_io_secs, device);
498 dasd_profile_counter(tottime, dasd_io_times, device);
499 dasd_profile_counter(tottimeps, dasd_io_timps, device);
500 dasd_profile_counter(strtime, dasd_io_time1, device);
501 dasd_profile_counter(irqtime, dasd_io_time2, device);
502 dasd_profile_counter(irqtime / sectors, dasd_io_time2ps, device);
503 dasd_profile_counter(endtime, dasd_io_time3, device);
506 #define dasd_profile_start(device, cqr, req) do {} while (0)
507 #define dasd_profile_end(device, cqr, req) do {} while (0)
508 #endif /* CONFIG_DASD_PROFILE */
511 * Allocate memory for a channel program with 'cplength' channel
512 * command words and 'datasize' additional space. There are two
513 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
514 * memory and 2) dasd_smalloc_request uses the static ccw memory
515 * that gets allocated for each device.
517 struct dasd_ccw_req *
518 dasd_kmalloc_request(char *magic, int cplength, int datasize,
519 struct dasd_device * device)
521 struct dasd_ccw_req *cqr;
524 if ( magic == NULL || datasize > PAGE_SIZE ||
525 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
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) {
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)
573 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
575 size += cplength * sizeof(struct ccw1);
578 spin_lock_irqsave(&device->mem_lock, flags);
579 cqr = (struct dasd_ccw_req *)
580 dasd_alloc_chunk(&device->ccw_chunks, size);
581 spin_unlock_irqrestore(&device->mem_lock, flags);
583 return ERR_PTR(-ENOMEM);
584 memset(cqr, 0, sizeof(struct dasd_ccw_req));
585 data = (char *) cqr + ((sizeof(struct dasd_ccw_req) + 7L) & -8L);
588 cqr->cpaddr = (struct ccw1 *) data;
589 data += cplength*sizeof(struct ccw1);
590 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
595 memset(cqr->data, 0, datasize);
597 strncpy((char *) &cqr->magic, magic, 4);
598 ASCEBC((char *) &cqr->magic, 4);
599 set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
600 dasd_get_device(device);
605 * Free memory of a channel program. This function needs to free all the
606 * idal lists that might have been created by dasd_set_cda and the
607 * struct dasd_ccw_req itself.
610 dasd_kfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
615 /* Clear any idals used for the request. */
618 clear_normalized_cda(ccw);
619 } while (ccw++->flags & (CCW_FLAG_CC | CCW_FLAG_DC));
624 dasd_put_device(device);
628 dasd_sfree_request(struct dasd_ccw_req * cqr, struct dasd_device * device)
632 spin_lock_irqsave(&device->mem_lock, flags);
633 dasd_free_chunk(&device->ccw_chunks, cqr);
634 spin_unlock_irqrestore(&device->mem_lock, flags);
635 dasd_put_device(device);
639 * Check discipline magic in cqr.
642 dasd_check_cqr(struct dasd_ccw_req *cqr)
644 struct dasd_device *device;
648 device = cqr->device;
649 if (strncmp((char *) &cqr->magic, device->discipline->ebcname, 4)) {
650 DEV_MESSAGE(KERN_WARNING, device,
651 " dasd_ccw_req 0x%08x magic doesn't match"
652 " discipline 0x%08x",
654 *(unsigned int *) device->discipline->name);
661 * Terminate the current i/o and set the request to clear_pending.
662 * Timer keeps device runnig.
663 * ccw_device_clear can fail if the i/o subsystem
667 dasd_term_IO(struct dasd_ccw_req * cqr)
669 struct dasd_device *device;
673 rc = dasd_check_cqr(cqr);
677 device = (struct dasd_device *) cqr->device;
678 while ((retries < 5) && (cqr->status == DASD_CQR_IN_IO)) {
679 rc = ccw_device_clear(device->cdev, (long) cqr);
681 case 0: /* termination successful */
683 cqr->status = DASD_CQR_CLEAR;
684 cqr->stopclk = get_clock();
685 DBF_DEV_EVENT(DBF_DEBUG, device,
686 "terminate cqr %p successful",
690 DBF_DEV_EVENT(DBF_ERR, device, "%s",
691 "device gone, retry");
694 DBF_DEV_EVENT(DBF_ERR, device, "%s",
699 DBF_DEV_EVENT(DBF_ERR, device, "%s",
700 "device busy, retry later");
703 DEV_MESSAGE(KERN_ERR, device,
704 "line %d unknown RC=%d, please "
705 "report to linux390@de.ibm.com",
712 dasd_schedule_bh(device);
717 * Start the i/o. This start_IO can fail if the channel is really busy.
718 * In that case set up a timer to start the request later.
721 dasd_start_IO(struct dasd_ccw_req * cqr)
723 struct dasd_device *device;
727 rc = dasd_check_cqr(cqr);
730 device = (struct dasd_device *) cqr->device;
731 if (cqr->retries < 0) {
732 DEV_MESSAGE(KERN_DEBUG, device,
733 "start_IO: request %p (%02x/%i) - no retry left.",
734 cqr, cqr->status, cqr->retries);
735 cqr->status = DASD_CQR_FAILED;
738 cqr->startclk = get_clock();
739 cqr->starttime = jiffies;
741 rc = ccw_device_start(device->cdev, cqr->cpaddr, (long) cqr,
745 cqr->status = DASD_CQR_IN_IO;
746 DBF_DEV_EVENT(DBF_DEBUG, device,
747 "start_IO: request %p started successful",
751 DBF_DEV_EVENT(DBF_ERR, device, "%s",
752 "start_IO: device busy, retry later");
755 DBF_DEV_EVENT(DBF_ERR, device, "%s",
756 "start_IO: request timeout, retry later");
759 /* -EACCES indicates that the request used only a
760 * subset of the available pathes and all these
762 * Do a retry with all available pathes.
764 cqr->lpm = LPM_ANYPATH;
765 DBF_DEV_EVENT(DBF_ERR, device, "%s",
766 "start_IO: selected pathes gone,"
767 " retry on all pathes");
771 DBF_DEV_EVENT(DBF_ERR, device, "%s",
772 "start_IO: device gone, retry");
775 DEV_MESSAGE(KERN_ERR, device,
776 "line %d unknown RC=%d, please report"
777 " to linux390@de.ibm.com", __LINE__, rc);
785 * Timeout function for dasd devices. This is used for different purposes
786 * 1) missing interrupt handler for normal operation
787 * 2) delayed start of request where start_IO failed with -EBUSY
788 * 3) timeout for missing state change interrupts
789 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
790 * DASD_CQR_QUEUED for 2) and 3).
793 dasd_timeout_device(unsigned long ptr)
796 struct dasd_device *device;
798 device = (struct dasd_device *) ptr;
799 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
800 /* re-activate request queue */
801 device->stopped &= ~DASD_STOPPED_PENDING;
802 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
803 dasd_schedule_bh(device);
807 * Setup timeout for a device in jiffies.
810 dasd_set_timer(struct dasd_device *device, int expires)
813 if (timer_pending(&device->timer))
814 del_timer(&device->timer);
817 if (timer_pending(&device->timer)) {
818 if (mod_timer(&device->timer, jiffies + expires))
821 device->timer.function = dasd_timeout_device;
822 device->timer.data = (unsigned long) device;
823 device->timer.expires = jiffies + expires;
824 add_timer(&device->timer);
828 * Clear timeout for a device.
831 dasd_clear_timer(struct dasd_device *device)
833 if (timer_pending(&device->timer))
834 del_timer(&device->timer);
838 dasd_handle_killed_request(struct ccw_device *cdev, unsigned long intparm)
840 struct dasd_ccw_req *cqr;
841 struct dasd_device *device;
843 cqr = (struct dasd_ccw_req *) intparm;
844 if (cqr->status != DASD_CQR_IN_IO) {
846 "invalid status in handle_killed_request: "
847 "bus_id %s, status %02x",
848 cdev->dev.bus_id, cqr->status);
852 device = (struct dasd_device *) cqr->device;
853 if (device == NULL ||
854 device != dasd_device_from_cdev(cdev) ||
855 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
856 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
861 /* Schedule request to be retried. */
862 cqr->status = DASD_CQR_QUEUED;
864 dasd_clear_timer(device);
865 dasd_schedule_bh(device);
866 dasd_put_device(device);
870 dasd_handle_state_change_pending(struct dasd_device *device)
872 struct dasd_ccw_req *cqr;
873 struct list_head *l, *n;
875 device->stopped &= ~DASD_STOPPED_PENDING;
877 /* restart all 'running' IO on queue */
878 list_for_each_safe(l, n, &device->ccw_queue) {
879 cqr = list_entry(l, struct dasd_ccw_req, list);
880 if (cqr->status == DASD_CQR_IN_IO) {
881 cqr->status = DASD_CQR_QUEUED;
884 dasd_clear_timer(device);
885 dasd_schedule_bh(device);
889 * Interrupt handler for "normal" ssch-io based dasd devices.
892 dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
895 struct dasd_ccw_req *cqr, *next;
896 struct dasd_device *device;
897 unsigned long long now;
903 switch (PTR_ERR(irb)) {
905 dasd_handle_killed_request(cdev, intparm);
908 printk(KERN_WARNING"%s(%s): request timed out\n",
909 __FUNCTION__, cdev->dev.bus_id);
910 //FIXME - dasd uses own timeout interface...
913 printk(KERN_WARNING"%s(%s): unknown error %ld\n",
914 __FUNCTION__, cdev->dev.bus_id, PTR_ERR(irb));
921 DBF_EVENT(DBF_ERR, "Interrupt: bus_id %s CS/DS %04x ip %08x",
922 cdev->dev.bus_id, ((irb->scsw.cstat<<8)|irb->scsw.dstat),
923 (unsigned int) intparm);
925 /* first of all check for state change pending interrupt */
926 mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
927 if ((irb->scsw.dstat & mask) == mask) {
928 device = dasd_device_from_cdev(cdev);
929 if (!IS_ERR(device)) {
930 dasd_handle_state_change_pending(device);
931 dasd_put_device(device);
936 cqr = (struct dasd_ccw_req *) intparm;
938 /* check for unsolicited interrupts */
941 "unsolicited interrupt received: bus_id %s",
946 device = (struct dasd_device *) cqr->device;
947 if (device == NULL ||
948 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
949 MESSAGE(KERN_DEBUG, "invalid device in request: bus_id %s",
954 /* Check for clear pending */
955 if (cqr->status == DASD_CQR_CLEAR &&
956 irb->scsw.fctl & SCSW_FCTL_CLEAR_FUNC) {
957 cqr->status = DASD_CQR_QUEUED;
958 dasd_clear_timer(device);
959 dasd_schedule_bh(device);
963 /* check status - the request might have been killed by dyn detach */
964 if (cqr->status != DASD_CQR_IN_IO) {
966 "invalid status: bus_id %s, status %02x",
967 cdev->dev.bus_id, cqr->status);
970 DBF_DEV_EVENT(DBF_DEBUG, device, "Int: CS/DS 0x%04x for cqr %p",
971 ((irb->scsw.cstat << 8) | irb->scsw.dstat), cqr);
973 /* Find out the appropriate era_action. */
974 if (irb->scsw.fctl & SCSW_FCTL_HALT_FUNC)
975 era = dasd_era_fatal;
976 else if (irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END) &&
977 irb->scsw.cstat == 0 &&
978 !irb->esw.esw0.erw.cons)
980 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags))
981 era = dasd_era_fatal; /* don't recover this request */
982 else if (irb->esw.esw0.erw.cons)
983 era = device->discipline->examine_error(cqr, irb);
985 era = dasd_era_recover;
987 DBF_DEV_EVENT(DBF_DEBUG, device, "era_code %d", era);
989 if (era == dasd_era_none) {
990 cqr->status = DASD_CQR_DONE;
992 /* Start first request on queue if possible -> fast_io. */
993 if (cqr->list.next != &device->ccw_queue) {
994 next = list_entry(cqr->list.next,
995 struct dasd_ccw_req, list);
996 if ((next->status == DASD_CQR_QUEUED) &&
997 (!device->stopped)) {
998 if (device->discipline->start_IO(next) == 0)
999 expires = next->expires;
1001 DEV_MESSAGE(KERN_DEBUG, device, "%s",
1002 "Interrupt fastpath "
1006 } else { /* error */
1007 memcpy(&cqr->irb, irb, sizeof (struct irb));
1009 /* dump sense data */
1010 dasd_log_sense(cqr, irb);
1013 case dasd_era_fatal:
1014 cqr->status = DASD_CQR_FAILED;
1017 case dasd_era_recover:
1018 cqr->status = DASD_CQR_ERROR;
1025 dasd_set_timer(device, expires);
1027 dasd_clear_timer(device);
1028 dasd_schedule_bh(device);
1032 * posts the buffer_cache about a finalized request
1035 dasd_end_request(struct request *req, int uptodate)
1037 if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
1039 add_disk_randomness(req->rq_disk);
1040 end_that_request_last(req, uptodate);
1044 * Process finished error recovery ccw.
1047 __dasd_process_erp(struct dasd_device *device, struct dasd_ccw_req *cqr)
1049 dasd_erp_fn_t erp_fn;
1051 if (cqr->status == DASD_CQR_DONE)
1052 DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
1054 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP unsuccessful");
1055 erp_fn = device->discipline->erp_postaction(cqr);
1060 * Process ccw request queue.
1063 __dasd_process_ccw_queue(struct dasd_device * device,
1064 struct list_head *final_queue)
1066 struct list_head *l, *n;
1067 struct dasd_ccw_req *cqr;
1068 dasd_erp_fn_t erp_fn;
1071 /* Process request with final status. */
1072 list_for_each_safe(l, n, &device->ccw_queue) {
1073 cqr = list_entry(l, struct dasd_ccw_req, list);
1074 /* Stop list processing at the first non-final request. */
1075 if (cqr->status != DASD_CQR_DONE &&
1076 cqr->status != DASD_CQR_FAILED &&
1077 cqr->status != DASD_CQR_ERROR)
1079 /* Process requests with DASD_CQR_ERROR */
1080 if (cqr->status == DASD_CQR_ERROR) {
1081 if (cqr->irb.scsw.fctl & SCSW_FCTL_HALT_FUNC) {
1082 cqr->status = DASD_CQR_FAILED;
1083 cqr->stopclk = get_clock();
1085 if (cqr->irb.esw.esw0.erw.cons) {
1086 erp_fn = device->discipline->
1090 dasd_default_erp_action(cqr);
1094 /* Process finished ERP request. */
1096 __dasd_process_erp(device, cqr);
1100 /* Rechain finished requests to final queue */
1101 cqr->endclk = get_clock();
1102 list_move_tail(&cqr->list, final_queue);
1107 dasd_end_request_cb(struct dasd_ccw_req * cqr, void *data)
1109 struct request *req;
1110 struct dasd_device *device;
1113 req = (struct request *) data;
1114 device = cqr->device;
1115 dasd_profile_end(device, cqr, req);
1116 status = cqr->device->discipline->free_cp(cqr,req);
1117 spin_lock_irq(&device->request_queue_lock);
1118 dasd_end_request(req, status);
1119 spin_unlock_irq(&device->request_queue_lock);
1124 * Fetch requests from the block device queue.
1127 __dasd_process_blk_queue(struct dasd_device * device)
1129 request_queue_t *queue;
1130 struct request *req;
1131 struct dasd_ccw_req *cqr;
1134 queue = device->request_queue;
1135 /* No queue ? Then there is nothing to do. */
1140 * We requeue request from the block device queue to the ccw
1141 * queue only in two states. In state DASD_STATE_READY the
1142 * partition detection is done and we need to requeue requests
1143 * for that. State DASD_STATE_ONLINE is normal block device
1146 if (device->state != DASD_STATE_READY &&
1147 device->state != DASD_STATE_ONLINE)
1150 /* Now we try to fetch requests from the request queue */
1151 list_for_each_entry(cqr, &device->ccw_queue, list)
1152 if (cqr->status == DASD_CQR_QUEUED)
1154 while (!blk_queue_plugged(queue) &&
1155 elv_next_request(queue) &&
1156 nr_queued < DASD_CHANQ_MAX_SIZE) {
1157 req = elv_next_request(queue);
1159 if (device->features & DASD_FEATURE_READONLY &&
1160 rq_data_dir(req) == WRITE) {
1161 DBF_DEV_EVENT(DBF_ERR, device,
1162 "Rejecting write request %p",
1164 blkdev_dequeue_request(req);
1165 dasd_end_request(req, 0);
1168 if (device->stopped & DASD_STOPPED_DC_EIO) {
1169 blkdev_dequeue_request(req);
1170 dasd_end_request(req, 0);
1173 cqr = device->discipline->build_cp(device, req);
1175 if (PTR_ERR(cqr) == -ENOMEM)
1176 break; /* terminate request queue loop */
1177 DBF_DEV_EVENT(DBF_ERR, device,
1178 "CCW creation failed (rc=%ld) "
1181 blkdev_dequeue_request(req);
1182 dasd_end_request(req, 0);
1185 cqr->callback = dasd_end_request_cb;
1186 cqr->callback_data = (void *) req;
1187 cqr->status = DASD_CQR_QUEUED;
1188 blkdev_dequeue_request(req);
1189 list_add_tail(&cqr->list, &device->ccw_queue);
1190 dasd_profile_start(device, cqr, req);
1196 * Take a look at the first request on the ccw queue and check
1197 * if it reached its expire time. If so, terminate the IO.
1200 __dasd_check_expire(struct dasd_device * device)
1202 struct dasd_ccw_req *cqr;
1204 if (list_empty(&device->ccw_queue))
1206 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1207 if (cqr->status == DASD_CQR_IN_IO && cqr->expires != 0) {
1208 if (time_after_eq(jiffies, cqr->expires + cqr->starttime)) {
1209 if (device->discipline->term_IO(cqr) != 0)
1210 /* Hmpf, try again in 1/10 sec */
1211 dasd_set_timer(device, 10);
1217 * Take a look at the first request on the ccw queue and check
1218 * if it needs to be started.
1221 __dasd_start_head(struct dasd_device * device)
1223 struct dasd_ccw_req *cqr;
1226 if (list_empty(&device->ccw_queue))
1228 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1229 /* check FAILFAST */
1230 if (device->stopped & ~DASD_STOPPED_PENDING &&
1231 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags)) {
1232 cqr->status = DASD_CQR_FAILED;
1233 dasd_schedule_bh(device);
1235 if ((cqr->status == DASD_CQR_QUEUED) &&
1236 (!device->stopped)) {
1237 /* try to start the first I/O that can be started */
1238 rc = device->discipline->start_IO(cqr);
1240 dasd_set_timer(device, cqr->expires);
1241 else if (rc == -EACCES) {
1242 dasd_schedule_bh(device);
1244 /* Hmpf, try again in 1/2 sec */
1245 dasd_set_timer(device, 50);
1250 * Remove requests from the ccw queue.
1253 dasd_flush_ccw_queue(struct dasd_device * device, int all)
1255 struct list_head flush_queue;
1256 struct list_head *l, *n;
1257 struct dasd_ccw_req *cqr;
1259 INIT_LIST_HEAD(&flush_queue);
1260 spin_lock_irq(get_ccwdev_lock(device->cdev));
1261 list_for_each_safe(l, n, &device->ccw_queue) {
1262 cqr = list_entry(l, struct dasd_ccw_req, list);
1263 /* Flush all request or only block device requests? */
1264 if (all == 0 && cqr->callback == dasd_end_request_cb)
1266 if (cqr->status == DASD_CQR_IN_IO)
1267 device->discipline->term_IO(cqr);
1268 if (cqr->status != DASD_CQR_DONE ||
1269 cqr->status != DASD_CQR_FAILED) {
1270 cqr->status = DASD_CQR_FAILED;
1271 cqr->stopclk = get_clock();
1273 /* Process finished ERP request. */
1275 __dasd_process_erp(device, cqr);
1278 /* Rechain request on device request queue */
1279 cqr->endclk = get_clock();
1280 list_move_tail(&cqr->list, &flush_queue);
1282 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1283 /* Now call the callback function of flushed requests */
1284 list_for_each_safe(l, n, &flush_queue) {
1285 cqr = list_entry(l, struct dasd_ccw_req, list);
1286 if (cqr->callback != NULL)
1287 (cqr->callback)(cqr, cqr->callback_data);
1292 * Acquire the device lock and process queues for the device.
1295 dasd_tasklet(struct dasd_device * device)
1297 struct list_head final_queue;
1298 struct list_head *l, *n;
1299 struct dasd_ccw_req *cqr;
1301 atomic_set (&device->tasklet_scheduled, 0);
1302 INIT_LIST_HEAD(&final_queue);
1303 spin_lock_irq(get_ccwdev_lock(device->cdev));
1304 /* Check expire time of first request on the ccw queue. */
1305 __dasd_check_expire(device);
1306 /* Finish off requests on ccw queue */
1307 __dasd_process_ccw_queue(device, &final_queue);
1308 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1309 /* Now call the callback function of requests with final status */
1310 list_for_each_safe(l, n, &final_queue) {
1311 cqr = list_entry(l, struct dasd_ccw_req, list);
1312 list_del_init(&cqr->list);
1313 if (cqr->callback != NULL)
1314 (cqr->callback)(cqr, cqr->callback_data);
1316 spin_lock_irq(&device->request_queue_lock);
1317 spin_lock(get_ccwdev_lock(device->cdev));
1318 /* Get new request from the block device request queue */
1319 __dasd_process_blk_queue(device);
1320 /* Now check if the head of the ccw queue needs to be started. */
1321 __dasd_start_head(device);
1322 spin_unlock(get_ccwdev_lock(device->cdev));
1323 spin_unlock_irq(&device->request_queue_lock);
1324 dasd_put_device(device);
1328 * Schedules a call to dasd_tasklet over the device tasklet.
1331 dasd_schedule_bh(struct dasd_device * device)
1333 /* Protect against rescheduling. */
1334 if (atomic_cmpxchg (&device->tasklet_scheduled, 0, 1) != 0)
1336 dasd_get_device(device);
1337 tasklet_hi_schedule(&device->tasklet);
1341 * Queue a request to the head of the ccw_queue. Start the I/O if
1345 dasd_add_request_head(struct dasd_ccw_req *req)
1347 struct dasd_device *device;
1348 unsigned long flags;
1350 device = req->device;
1351 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1352 req->status = DASD_CQR_QUEUED;
1353 req->device = device;
1354 list_add(&req->list, &device->ccw_queue);
1355 /* let the bh start the request to keep them in order */
1356 dasd_schedule_bh(device);
1357 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1361 * Queue a request to the tail of the ccw_queue. Start the I/O if
1365 dasd_add_request_tail(struct dasd_ccw_req *req)
1367 struct dasd_device *device;
1368 unsigned long flags;
1370 device = req->device;
1371 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1372 req->status = DASD_CQR_QUEUED;
1373 req->device = device;
1374 list_add_tail(&req->list, &device->ccw_queue);
1375 /* let the bh start the request to keep them in order */
1376 dasd_schedule_bh(device);
1377 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1384 dasd_wakeup_cb(struct dasd_ccw_req *cqr, void *data)
1386 wake_up((wait_queue_head_t *) data);
1390 _wait_for_wakeup(struct dasd_ccw_req *cqr)
1392 struct dasd_device *device;
1395 device = cqr->device;
1396 spin_lock_irq(get_ccwdev_lock(device->cdev));
1397 rc = ((cqr->status == DASD_CQR_DONE ||
1398 cqr->status == DASD_CQR_FAILED) &&
1399 list_empty(&cqr->list));
1400 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1405 * Attempts to start a special ccw queue and waits for its completion.
1408 dasd_sleep_on(struct dasd_ccw_req * cqr)
1410 wait_queue_head_t wait_q;
1411 struct dasd_device *device;
1414 device = cqr->device;
1415 spin_lock_irq(get_ccwdev_lock(device->cdev));
1417 init_waitqueue_head (&wait_q);
1418 cqr->callback = dasd_wakeup_cb;
1419 cqr->callback_data = (void *) &wait_q;
1420 cqr->status = DASD_CQR_QUEUED;
1421 list_add_tail(&cqr->list, &device->ccw_queue);
1423 /* let the bh start the request to keep them in order */
1424 dasd_schedule_bh(device);
1426 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1428 wait_event(wait_q, _wait_for_wakeup(cqr));
1430 /* Request status is either done or failed. */
1431 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1436 * Attempts to start a special ccw queue and wait interruptible
1437 * for its completion.
1440 dasd_sleep_on_interruptible(struct dasd_ccw_req * cqr)
1442 wait_queue_head_t wait_q;
1443 struct dasd_device *device;
1446 device = cqr->device;
1447 spin_lock_irq(get_ccwdev_lock(device->cdev));
1449 init_waitqueue_head (&wait_q);
1450 cqr->callback = dasd_wakeup_cb;
1451 cqr->callback_data = (void *) &wait_q;
1452 cqr->status = DASD_CQR_QUEUED;
1453 list_add_tail(&cqr->list, &device->ccw_queue);
1455 /* let the bh start the request to keep them in order */
1456 dasd_schedule_bh(device);
1457 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1461 rc = wait_event_interruptible(wait_q, _wait_for_wakeup(cqr));
1462 if (rc != -ERESTARTSYS) {
1463 /* Request is final (done or failed) */
1464 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1467 spin_lock_irq(get_ccwdev_lock(device->cdev));
1468 switch (cqr->status) {
1469 case DASD_CQR_IN_IO:
1470 /* terminate runnig cqr */
1471 if (device->discipline->term_IO) {
1473 device->discipline->term_IO(cqr);
1475 * wait (non-interruptible) for final status
1476 * because signal ist still pending
1478 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1479 wait_event(wait_q, _wait_for_wakeup(cqr));
1480 spin_lock_irq(get_ccwdev_lock(device->cdev));
1481 rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
1485 case DASD_CQR_QUEUED:
1487 list_del_init(&cqr->list);
1492 /* cqr with 'non-interruptable' status - just wait */
1495 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1501 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1502 * for eckd devices) the currently running request has to be terminated
1503 * and be put back to status queued, before the special request is added
1504 * to the head of the queue. Then the special request is waited on normally.
1507 _dasd_term_running_cqr(struct dasd_device *device)
1509 struct dasd_ccw_req *cqr;
1512 if (list_empty(&device->ccw_queue))
1514 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1515 rc = device->discipline->term_IO(cqr);
1517 /* termination successful */
1518 cqr->status = DASD_CQR_QUEUED;
1519 cqr->startclk = cqr->stopclk = 0;
1526 dasd_sleep_on_immediatly(struct dasd_ccw_req * cqr)
1528 wait_queue_head_t wait_q;
1529 struct dasd_device *device;
1532 device = cqr->device;
1533 spin_lock_irq(get_ccwdev_lock(device->cdev));
1534 rc = _dasd_term_running_cqr(device);
1536 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1540 init_waitqueue_head (&wait_q);
1541 cqr->callback = dasd_wakeup_cb;
1542 cqr->callback_data = (void *) &wait_q;
1543 cqr->status = DASD_CQR_QUEUED;
1544 list_add(&cqr->list, &device->ccw_queue);
1546 /* let the bh start the request to keep them in order */
1547 dasd_schedule_bh(device);
1549 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1551 wait_event(wait_q, _wait_for_wakeup(cqr));
1553 /* Request status is either done or failed. */
1554 rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
1559 * Cancels a request that was started with dasd_sleep_on_req.
1560 * This is useful to timeout requests. The request will be
1561 * terminated if it is currently in i/o.
1562 * Returns 1 if the request has been terminated.
1565 dasd_cancel_req(struct dasd_ccw_req *cqr)
1567 struct dasd_device *device = cqr->device;
1568 unsigned long flags;
1572 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
1573 switch (cqr->status) {
1574 case DASD_CQR_QUEUED:
1575 /* request was not started - just set to failed */
1576 cqr->status = DASD_CQR_FAILED;
1578 case DASD_CQR_IN_IO:
1579 /* request in IO - terminate IO and release again */
1580 if (device->discipline->term_IO(cqr) != 0)
1581 /* what to do if unable to terminate ??????
1583 cqr->status = DASD_CQR_FAILED;
1584 cqr->stopclk = get_clock();
1588 case DASD_CQR_FAILED:
1589 /* already finished - do nothing */
1592 DEV_MESSAGE(KERN_ALERT, device,
1593 "invalid status %02x in request",
1598 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
1599 dasd_schedule_bh(device);
1604 * SECTION: Block device operations (request queue, partitions, open, release).
1608 * Dasd request queue function. Called from ll_rw_blk.c
1611 do_dasd_request(request_queue_t * queue)
1613 struct dasd_device *device;
1615 device = (struct dasd_device *) queue->queuedata;
1616 spin_lock(get_ccwdev_lock(device->cdev));
1617 /* Get new request from the block device request queue */
1618 __dasd_process_blk_queue(device);
1619 /* Now check if the head of the ccw queue needs to be started. */
1620 __dasd_start_head(device);
1621 spin_unlock(get_ccwdev_lock(device->cdev));
1625 * Allocate and initialize request queue and default I/O scheduler.
1628 dasd_alloc_queue(struct dasd_device * device)
1632 device->request_queue = blk_init_queue(do_dasd_request,
1633 &device->request_queue_lock);
1634 if (device->request_queue == NULL)
1637 device->request_queue->queuedata = device;
1639 elevator_exit(device->request_queue->elevator);
1640 rc = elevator_init(device->request_queue, "deadline");
1642 blk_cleanup_queue(device->request_queue);
1649 * Allocate and initialize request queue.
1652 dasd_setup_queue(struct dasd_device * device)
1656 blk_queue_hardsect_size(device->request_queue, device->bp_block);
1657 max = device->discipline->max_blocks << device->s2b_shift;
1658 blk_queue_max_sectors(device->request_queue, max);
1659 blk_queue_max_phys_segments(device->request_queue, -1L);
1660 blk_queue_max_hw_segments(device->request_queue, -1L);
1661 blk_queue_max_segment_size(device->request_queue, -1L);
1662 blk_queue_segment_boundary(device->request_queue, -1L);
1663 blk_queue_ordered(device->request_queue, QUEUE_ORDERED_TAG, NULL);
1667 * Deactivate and free request queue.
1670 dasd_free_queue(struct dasd_device * device)
1672 if (device->request_queue) {
1673 blk_cleanup_queue(device->request_queue);
1674 device->request_queue = NULL;
1679 * Flush request on the request queue.
1682 dasd_flush_request_queue(struct dasd_device * device)
1684 struct request *req;
1686 if (!device->request_queue)
1689 spin_lock_irq(&device->request_queue_lock);
1690 while (!list_empty(&device->request_queue->queue_head)) {
1691 req = elv_next_request(device->request_queue);
1694 dasd_end_request(req, 0);
1695 blkdev_dequeue_request(req);
1697 spin_unlock_irq(&device->request_queue_lock);
1701 dasd_open(struct inode *inp, struct file *filp)
1703 struct gendisk *disk = inp->i_bdev->bd_disk;
1704 struct dasd_device *device = disk->private_data;
1707 atomic_inc(&device->open_count);
1708 if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1713 if (!try_module_get(device->discipline->owner)) {
1718 if (dasd_probeonly) {
1719 DEV_MESSAGE(KERN_INFO, device, "%s",
1720 "No access to device due to probeonly mode");
1725 if (device->state < DASD_STATE_BASIC) {
1726 DBF_DEV_EVENT(DBF_ERR, device, " %s",
1727 " Cannot open unrecognized device");
1735 module_put(device->discipline->owner);
1737 atomic_dec(&device->open_count);
1742 dasd_release(struct inode *inp, struct file *filp)
1744 struct gendisk *disk = inp->i_bdev->bd_disk;
1745 struct dasd_device *device = disk->private_data;
1747 atomic_dec(&device->open_count);
1748 module_put(device->discipline->owner);
1753 * Return disk geometry.
1756 dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1758 struct dasd_device *device;
1760 device = bdev->bd_disk->private_data;
1764 if (!device->discipline ||
1765 !device->discipline->fill_geometry)
1768 device->discipline->fill_geometry(device, geo);
1769 geo->start = get_start_sect(bdev) >> device->s2b_shift;
1773 struct block_device_operations
1774 dasd_device_operations = {
1775 .owner = THIS_MODULE,
1777 .release = dasd_release,
1778 .ioctl = dasd_ioctl,
1779 .compat_ioctl = dasd_compat_ioctl,
1780 .getgeo = dasd_getgeo,
1787 #ifdef CONFIG_PROC_FS
1791 if (dasd_page_cache != NULL) {
1792 kmem_cache_destroy(dasd_page_cache);
1793 dasd_page_cache = NULL;
1795 dasd_gendisk_exit();
1797 devfs_remove("dasd");
1798 if (dasd_debug_area != NULL) {
1799 debug_unregister(dasd_debug_area);
1800 dasd_debug_area = NULL;
1805 * SECTION: common functions for ccw_driver use
1809 * Initial attempt at a probe function. this can be simplified once
1810 * the other detection code is gone.
1813 dasd_generic_probe (struct ccw_device *cdev,
1814 struct dasd_discipline *discipline)
1818 ret = dasd_add_sysfs_files(cdev);
1821 "dasd_generic_probe: could not add sysfs entries "
1822 "for %s\n", cdev->dev.bus_id);
1824 cdev->handler = &dasd_int_handler;
1831 * This will one day be called from a global not_oper handler.
1832 * It is also used by driver_unregister during module unload.
1835 dasd_generic_remove (struct ccw_device *cdev)
1837 struct dasd_device *device;
1839 cdev->handler = NULL;
1841 dasd_remove_sysfs_files(cdev);
1842 device = dasd_device_from_cdev(cdev);
1845 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1846 /* Already doing offline processing */
1847 dasd_put_device(device);
1851 * This device is removed unconditionally. Set offline
1852 * flag to prevent dasd_open from opening it while it is
1853 * no quite down yet.
1855 dasd_set_target_state(device, DASD_STATE_NEW);
1856 /* dasd_delete_device destroys the device reference. */
1857 dasd_delete_device(device);
1861 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
1862 * the device is detected for the first time and is supposed to be used
1863 * or the user has started activation through sysfs.
1866 dasd_generic_set_online (struct ccw_device *cdev,
1867 struct dasd_discipline *base_discipline)
1870 struct dasd_discipline *discipline;
1871 struct dasd_device *device;
1874 device = dasd_create_device(cdev);
1876 return PTR_ERR(device);
1878 discipline = base_discipline;
1879 if (device->features & DASD_FEATURE_USEDIAG) {
1880 if (!dasd_diag_discipline_pointer) {
1881 printk (KERN_WARNING
1882 "dasd_generic couldn't online device %s "
1883 "- discipline DIAG not available\n",
1885 dasd_delete_device(device);
1888 discipline = dasd_diag_discipline_pointer;
1890 if (!try_module_get(base_discipline->owner)) {
1891 dasd_delete_device(device);
1894 if (!try_module_get(discipline->owner)) {
1895 module_put(base_discipline->owner);
1896 dasd_delete_device(device);
1899 device->base_discipline = base_discipline;
1900 device->discipline = discipline;
1902 rc = discipline->check_device(device);
1904 printk (KERN_WARNING
1905 "dasd_generic couldn't online device %s "
1906 "with discipline %s rc=%i\n",
1907 cdev->dev.bus_id, discipline->name, rc);
1908 module_put(discipline->owner);
1909 module_put(base_discipline->owner);
1910 dasd_delete_device(device);
1914 dasd_set_target_state(device, DASD_STATE_ONLINE);
1915 if (device->state <= DASD_STATE_KNOWN) {
1916 printk (KERN_WARNING
1917 "dasd_generic discipline not found for %s\n",
1920 dasd_set_target_state(device, DASD_STATE_NEW);
1921 dasd_delete_device(device);
1923 pr_debug("dasd_generic device %s found\n",
1926 /* FIXME: we have to wait for the root device but we don't want
1927 * to wait for each single device but for all at once. */
1928 wait_event(dasd_init_waitq, _wait_for_device(device));
1930 dasd_put_device(device);
1936 dasd_generic_set_offline (struct ccw_device *cdev)
1938 struct dasd_device *device;
1941 device = dasd_device_from_cdev(cdev);
1943 return PTR_ERR(device);
1944 if (test_and_set_bit(DASD_FLAG_OFFLINE, &device->flags)) {
1945 /* Already doing offline processing */
1946 dasd_put_device(device);
1950 * We must make sure that this device is currently not in use.
1951 * The open_count is increased for every opener, that includes
1952 * the blkdev_get in dasd_scan_partitions. We are only interested
1953 * in the other openers.
1955 max_count = device->bdev ? 0 : -1;
1956 if (atomic_read(&device->open_count) > max_count) {
1957 printk (KERN_WARNING "Can't offline dasd device with open"
1959 atomic_read(&device->open_count));
1960 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
1961 dasd_put_device(device);
1964 dasd_set_target_state(device, DASD_STATE_NEW);
1965 /* dasd_delete_device destroys the device reference. */
1966 dasd_delete_device(device);
1972 dasd_generic_notify(struct ccw_device *cdev, int event)
1974 struct dasd_device *device;
1975 struct dasd_ccw_req *cqr;
1976 unsigned long flags;
1979 device = dasd_device_from_cdev(cdev);
1982 spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
1987 if (device->state < DASD_STATE_BASIC)
1989 /* Device is active. We want to keep it. */
1990 if (test_bit(DASD_FLAG_DSC_ERROR, &device->flags)) {
1991 list_for_each_entry(cqr, &device->ccw_queue, list)
1992 if (cqr->status == DASD_CQR_IN_IO)
1993 cqr->status = DASD_CQR_FAILED;
1994 device->stopped |= DASD_STOPPED_DC_EIO;
1996 list_for_each_entry(cqr, &device->ccw_queue, list)
1997 if (cqr->status == DASD_CQR_IN_IO) {
1998 cqr->status = DASD_CQR_QUEUED;
2001 device->stopped |= DASD_STOPPED_DC_WAIT;
2002 dasd_set_timer(device, 0);
2004 dasd_schedule_bh(device);
2008 /* FIXME: add a sanity check. */
2009 device->stopped &= ~(DASD_STOPPED_DC_WAIT|DASD_STOPPED_DC_EIO);
2010 dasd_schedule_bh(device);
2014 spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
2015 dasd_put_device(device);
2020 * Automatically online either all dasd devices (dasd_autodetect) or
2021 * all devices specified with dasd= parameters.
2024 __dasd_auto_online(struct device *dev, void *data)
2026 struct ccw_device *cdev;
2028 cdev = to_ccwdev(dev);
2029 if (dasd_autodetect || dasd_busid_known(cdev->dev.bus_id) == 0)
2030 ccw_device_set_online(cdev);
2035 dasd_generic_auto_online (struct ccw_driver *dasd_discipline_driver)
2037 struct device_driver *drv;
2039 drv = get_driver(&dasd_discipline_driver->driver);
2040 driver_for_each_device(drv, NULL, NULL, __dasd_auto_online);
2049 init_waitqueue_head(&dasd_init_waitq);
2051 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2052 dasd_debug_area = debug_register("dasd", 1, 2, 8 * sizeof (long));
2053 if (dasd_debug_area == NULL) {
2057 debug_register_view(dasd_debug_area, &debug_sprintf_view);
2058 debug_set_level(dasd_debug_area, DBF_EMERG);
2060 DBF_EVENT(DBF_EMERG, "%s", "debug area created");
2062 dasd_diag_discipline_pointer = NULL;
2064 rc = devfs_mk_dir("dasd");
2067 rc = dasd_devmap_init();
2070 rc = dasd_gendisk_init();
2076 rc = dasd_ioctl_init();
2079 #ifdef CONFIG_PROC_FS
2080 rc = dasd_proc_init();
2087 MESSAGE(KERN_INFO, "%s", "initialization not performed due to errors");
2092 module_init(dasd_init);
2093 module_exit(dasd_exit);
2095 EXPORT_SYMBOL(dasd_debug_area);
2096 EXPORT_SYMBOL(dasd_diag_discipline_pointer);
2098 EXPORT_SYMBOL(dasd_add_request_head);
2099 EXPORT_SYMBOL(dasd_add_request_tail);
2100 EXPORT_SYMBOL(dasd_cancel_req);
2101 EXPORT_SYMBOL(dasd_clear_timer);
2102 EXPORT_SYMBOL(dasd_enable_device);
2103 EXPORT_SYMBOL(dasd_int_handler);
2104 EXPORT_SYMBOL(dasd_kfree_request);
2105 EXPORT_SYMBOL(dasd_kick_device);
2106 EXPORT_SYMBOL(dasd_kmalloc_request);
2107 EXPORT_SYMBOL(dasd_schedule_bh);
2108 EXPORT_SYMBOL(dasd_set_target_state);
2109 EXPORT_SYMBOL(dasd_set_timer);
2110 EXPORT_SYMBOL(dasd_sfree_request);
2111 EXPORT_SYMBOL(dasd_sleep_on);
2112 EXPORT_SYMBOL(dasd_sleep_on_immediatly);
2113 EXPORT_SYMBOL(dasd_sleep_on_interruptible);
2114 EXPORT_SYMBOL(dasd_smalloc_request);
2115 EXPORT_SYMBOL(dasd_start_IO);
2116 EXPORT_SYMBOL(dasd_term_IO);
2118 EXPORT_SYMBOL_GPL(dasd_generic_probe);
2119 EXPORT_SYMBOL_GPL(dasd_generic_remove);
2120 EXPORT_SYMBOL_GPL(dasd_generic_notify);
2121 EXPORT_SYMBOL_GPL(dasd_generic_set_online);
2122 EXPORT_SYMBOL_GPL(dasd_generic_set_offline);
2123 EXPORT_SYMBOL_GPL(dasd_generic_auto_online);
2126 * Overrides for Emacs so that we follow Linus's tabbing style.
2127 * Emacs will notice this stuff at the end of the file and automatically
2128 * adjust the settings for this buffer only. This must remain at the end
2130 * ---------------------------------------------------------------------------
2133 * c-brace-imaginary-offset: 0
2134 * c-brace-offset: -4
2135 * c-argdecl-indent: 4
2136 * c-label-offset: -4
2137 * c-continued-statement-offset: 4
2138 * c-continued-brace-offset: 0
2139 * indent-tabs-mode: 1