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_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
= kzalloc(sizeof (struct dasd_device
), GFP_ATOMIC
);
75 return ERR_PTR(-ENOMEM
);
76 /* open_count = 0 means device online but not in use */
77 atomic_set(&device
->open_count
, -1);
79 /* Get two pages for normal block device operations. */
80 device
->ccw_mem
= (void *) __get_free_pages(GFP_ATOMIC
| GFP_DMA
, 1);
81 if (device
->ccw_mem
== NULL
) {
83 return ERR_PTR(-ENOMEM
);
85 /* Get one page for error recovery. */
86 device
->erp_mem
= (void *) get_zeroed_page(GFP_ATOMIC
| GFP_DMA
);
87 if (device
->erp_mem
== NULL
) {
88 free_pages((unsigned long) device
->ccw_mem
, 1);
90 return ERR_PTR(-ENOMEM
);
93 dasd_init_chunklist(&device
->ccw_chunks
, device
->ccw_mem
, PAGE_SIZE
*2);
94 dasd_init_chunklist(&device
->erp_chunks
, device
->erp_mem
, PAGE_SIZE
);
95 spin_lock_init(&device
->mem_lock
);
96 spin_lock_init(&device
->request_queue_lock
);
97 atomic_set (&device
->tasklet_scheduled
, 0);
98 tasklet_init(&device
->tasklet
,
99 (void (*)(unsigned long)) dasd_tasklet
,
100 (unsigned long) device
);
101 INIT_LIST_HEAD(&device
->ccw_queue
);
102 init_timer(&device
->timer
);
103 INIT_WORK(&device
->kick_work
, do_kick_device
, device
);
104 device
->state
= DASD_STATE_NEW
;
105 device
->target
= DASD_STATE_NEW
;
111 * Free memory of a device structure.
114 dasd_free_device(struct dasd_device
*device
)
116 kfree(device
->private);
117 free_page((unsigned long) device
->erp_mem
);
118 free_pages((unsigned long) device
->ccw_mem
, 1);
123 * Make a new device known to the system.
126 dasd_state_new_to_known(struct dasd_device
*device
)
131 * As long as the device is not in state DASD_STATE_NEW we want to
132 * keep the reference count > 0.
134 dasd_get_device(device
);
136 rc
= dasd_alloc_queue(device
);
138 dasd_put_device(device
);
142 device
->state
= DASD_STATE_KNOWN
;
147 * Let the system forget about a device.
150 dasd_state_known_to_new(struct dasd_device
* device
)
152 /* Disable extended error reporting for this device. */
153 dasd_eer_disable(device
);
154 /* Forget the discipline information. */
155 if (device
->discipline
)
156 module_put(device
->discipline
->owner
);
157 device
->discipline
= NULL
;
158 if (device
->base_discipline
)
159 module_put(device
->base_discipline
->owner
);
160 device
->base_discipline
= NULL
;
161 device
->state
= DASD_STATE_NEW
;
163 dasd_free_queue(device
);
165 /* Give up reference we took in dasd_state_new_to_known. */
166 dasd_put_device(device
);
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) the block
220 * In case the analysis returns an error, the device setup is stopped
221 * (a fake disk was already added to allow formatting).
224 dasd_state_basic_to_ready(struct dasd_device
* device
)
229 if (device
->discipline
->do_analysis
!= NULL
)
230 rc
= device
->discipline
->do_analysis(device
);
233 device
->state
= DASD_STATE_UNFMT
;
236 /* make disk known with correct capacity */
237 dasd_setup_queue(device
);
238 set_capacity(device
->gdp
, device
->blocks
<< device
->s2b_shift
);
239 device
->state
= DASD_STATE_READY
;
240 rc
= dasd_scan_partitions(device
);
242 device
->state
= DASD_STATE_BASIC
;
247 * Remove device from block device layer. Destroy dirty buffers.
248 * Forget format information. Check if the target level is basic
249 * and if it is create fake disk for formatting.
252 dasd_state_ready_to_basic(struct dasd_device
* device
)
254 dasd_flush_ccw_queue(device
, 0);
255 dasd_destroy_partitions(device
);
256 dasd_flush_request_queue(device
);
258 device
->bp_block
= 0;
259 device
->s2b_shift
= 0;
260 device
->state
= DASD_STATE_BASIC
;
267 dasd_state_unfmt_to_basic(struct dasd_device
* device
)
269 device
->state
= DASD_STATE_BASIC
;
273 * Make the device online and schedule the bottom half to start
274 * the requeueing of requests from the linux request queue to the
278 dasd_state_ready_to_online(struct dasd_device
* device
)
280 device
->state
= DASD_STATE_ONLINE
;
281 dasd_schedule_bh(device
);
286 * Stop the requeueing of requests again.
289 dasd_state_online_to_ready(struct dasd_device
* device
)
291 device
->state
= DASD_STATE_READY
;
295 * Device startup state changes.
298 dasd_increase_state(struct dasd_device
*device
)
303 if (device
->state
== DASD_STATE_NEW
&&
304 device
->target
>= DASD_STATE_KNOWN
)
305 rc
= dasd_state_new_to_known(device
);
308 device
->state
== DASD_STATE_KNOWN
&&
309 device
->target
>= DASD_STATE_BASIC
)
310 rc
= dasd_state_known_to_basic(device
);
313 device
->state
== DASD_STATE_BASIC
&&
314 device
->target
>= DASD_STATE_READY
)
315 rc
= dasd_state_basic_to_ready(device
);
318 device
->state
== DASD_STATE_UNFMT
&&
319 device
->target
> DASD_STATE_UNFMT
)
323 device
->state
== DASD_STATE_READY
&&
324 device
->target
>= DASD_STATE_ONLINE
)
325 rc
= dasd_state_ready_to_online(device
);
331 * Device shutdown state changes.
334 dasd_decrease_state(struct dasd_device
*device
)
336 if (device
->state
== DASD_STATE_ONLINE
&&
337 device
->target
<= DASD_STATE_READY
)
338 dasd_state_online_to_ready(device
);
340 if (device
->state
== DASD_STATE_READY
&&
341 device
->target
<= DASD_STATE_BASIC
)
342 dasd_state_ready_to_basic(device
);
344 if (device
->state
== DASD_STATE_UNFMT
&&
345 device
->target
<= DASD_STATE_BASIC
)
346 dasd_state_unfmt_to_basic(device
);
348 if (device
->state
== DASD_STATE_BASIC
&&
349 device
->target
<= DASD_STATE_KNOWN
)
350 dasd_state_basic_to_known(device
);
352 if (device
->state
== DASD_STATE_KNOWN
&&
353 device
->target
<= DASD_STATE_NEW
)
354 dasd_state_known_to_new(device
);
360 * This is the main startup/shutdown routine.
363 dasd_change_state(struct dasd_device
*device
)
367 if (device
->state
== device
->target
)
368 /* Already where we want to go today... */
370 if (device
->state
< device
->target
)
371 rc
= dasd_increase_state(device
);
373 rc
= dasd_decrease_state(device
);
374 if (rc
&& rc
!= -EAGAIN
)
375 device
->target
= device
->state
;
377 if (device
->state
== device
->target
)
378 wake_up(&dasd_init_waitq
);
382 * Kick starter for devices that did not complete the startup/shutdown
383 * procedure or were sleeping because of a pending state.
384 * dasd_kick_device will schedule a call do do_kick_device to the kernel
388 do_kick_device(void *data
)
390 struct dasd_device
*device
;
392 device
= (struct dasd_device
*) data
;
393 dasd_change_state(device
);
394 dasd_schedule_bh(device
);
395 dasd_put_device(device
);
399 dasd_kick_device(struct dasd_device
*device
)
401 dasd_get_device(device
);
402 /* queue call to dasd_kick_device to the kernel event daemon. */
403 schedule_work(&device
->kick_work
);
407 * Set the target state for a device and starts the state change.
410 dasd_set_target_state(struct dasd_device
*device
, int target
)
412 /* If we are in probeonly mode stop at DASD_STATE_READY. */
413 if (dasd_probeonly
&& target
> DASD_STATE_READY
)
414 target
= DASD_STATE_READY
;
415 if (device
->target
!= target
) {
416 if (device
->state
== target
)
417 wake_up(&dasd_init_waitq
);
418 device
->target
= target
;
420 if (device
->state
!= device
->target
)
421 dasd_change_state(device
);
425 * Enable devices with device numbers in [from..to].
428 _wait_for_device(struct dasd_device
*device
)
430 return (device
->state
== device
->target
);
434 dasd_enable_device(struct dasd_device
*device
)
436 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
437 if (device
->state
<= DASD_STATE_KNOWN
)
438 /* No discipline for device found. */
439 dasd_set_target_state(device
, DASD_STATE_NEW
);
440 /* Now wait for the devices to come up. */
441 wait_event(dasd_init_waitq
, _wait_for_device(device
));
445 * SECTION: device operation (interrupt handler, start i/o, term i/o ...)
447 #ifdef CONFIG_DASD_PROFILE
449 struct dasd_profile_info_t dasd_global_profile
;
450 unsigned int dasd_profile_level
= DASD_PROFILE_OFF
;
453 * Increments counter in global and local profiling structures.
455 #define dasd_profile_counter(value, counter, device) \
458 for (index = 0; index < 31 && value >> (2+index); index++); \
459 dasd_global_profile.counter[index]++; \
460 device->profile.counter[index]++; \
464 * Add profiling information for cqr before execution.
467 dasd_profile_start(struct dasd_device
*device
, struct dasd_ccw_req
* cqr
,
471 unsigned int counter
;
473 if (dasd_profile_level
!= DASD_PROFILE_ON
)
476 /* count the length of the chanq for statistics */
478 list_for_each(l
, &device
->ccw_queue
)
481 dasd_global_profile
.dasd_io_nr_req
[counter
]++;
482 device
->profile
.dasd_io_nr_req
[counter
]++;
486 * Add profiling information for cqr after execution.
489 dasd_profile_end(struct dasd_device
*device
, struct dasd_ccw_req
* cqr
,
492 long strtime
, irqtime
, endtime
, tottime
; /* in microseconds */
493 long tottimeps
, sectors
;
495 if (dasd_profile_level
!= DASD_PROFILE_ON
)
498 sectors
= req
->nr_sectors
;
499 if (!cqr
->buildclk
|| !cqr
->startclk
||
500 !cqr
->stopclk
|| !cqr
->endclk
||
504 strtime
= ((cqr
->startclk
- cqr
->buildclk
) >> 12);
505 irqtime
= ((cqr
->stopclk
- cqr
->startclk
) >> 12);
506 endtime
= ((cqr
->endclk
- cqr
->stopclk
) >> 12);
507 tottime
= ((cqr
->endclk
- cqr
->buildclk
) >> 12);
508 tottimeps
= tottime
/ sectors
;
510 if (!dasd_global_profile
.dasd_io_reqs
)
511 memset(&dasd_global_profile
, 0,
512 sizeof (struct dasd_profile_info_t
));
513 dasd_global_profile
.dasd_io_reqs
++;
514 dasd_global_profile
.dasd_io_sects
+= sectors
;
516 if (!device
->profile
.dasd_io_reqs
)
517 memset(&device
->profile
, 0,
518 sizeof (struct dasd_profile_info_t
));
519 device
->profile
.dasd_io_reqs
++;
520 device
->profile
.dasd_io_sects
+= sectors
;
522 dasd_profile_counter(sectors
, dasd_io_secs
, device
);
523 dasd_profile_counter(tottime
, dasd_io_times
, device
);
524 dasd_profile_counter(tottimeps
, dasd_io_timps
, device
);
525 dasd_profile_counter(strtime
, dasd_io_time1
, device
);
526 dasd_profile_counter(irqtime
, dasd_io_time2
, device
);
527 dasd_profile_counter(irqtime
/ sectors
, dasd_io_time2ps
, device
);
528 dasd_profile_counter(endtime
, dasd_io_time3
, device
);
531 #define dasd_profile_start(device, cqr, req) do {} while (0)
532 #define dasd_profile_end(device, cqr, req) do {} while (0)
533 #endif /* CONFIG_DASD_PROFILE */
536 * Allocate memory for a channel program with 'cplength' channel
537 * command words and 'datasize' additional space. There are two
538 * variantes: 1) dasd_kmalloc_request uses kmalloc to get the needed
539 * memory and 2) dasd_smalloc_request uses the static ccw memory
540 * that gets allocated for each device.
542 struct dasd_ccw_req
*
543 dasd_kmalloc_request(char *magic
, int cplength
, int datasize
,
544 struct dasd_device
* device
)
546 struct dasd_ccw_req
*cqr
;
549 BUG_ON( magic
== NULL
|| datasize
> PAGE_SIZE
||
550 (cplength
*sizeof(struct ccw1
)) > PAGE_SIZE
);
552 cqr
= kzalloc(sizeof(struct dasd_ccw_req
), GFP_ATOMIC
);
554 return ERR_PTR(-ENOMEM
);
557 cqr
->cpaddr
= kcalloc(cplength
, sizeof(struct ccw1
),
558 GFP_ATOMIC
| GFP_DMA
);
559 if (cqr
->cpaddr
== NULL
) {
561 return ERR_PTR(-ENOMEM
);
566 cqr
->data
= kzalloc(datasize
, GFP_ATOMIC
| GFP_DMA
);
567 if (cqr
->data
== NULL
) {
570 return ERR_PTR(-ENOMEM
);
573 strncpy((char *) &cqr
->magic
, magic
, 4);
574 ASCEBC((char *) &cqr
->magic
, 4);
575 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
576 dasd_get_device(device
);
580 struct dasd_ccw_req
*
581 dasd_smalloc_request(char *magic
, int cplength
, int datasize
,
582 struct dasd_device
* device
)
585 struct dasd_ccw_req
*cqr
;
590 BUG_ON( magic
== NULL
|| datasize
> PAGE_SIZE
||
591 (cplength
*sizeof(struct ccw1
)) > PAGE_SIZE
);
593 size
= (sizeof(struct dasd_ccw_req
) + 7L) & -8L;
595 size
+= cplength
* sizeof(struct ccw1
);
598 spin_lock_irqsave(&device
->mem_lock
, flags
);
599 cqr
= (struct dasd_ccw_req
*)
600 dasd_alloc_chunk(&device
->ccw_chunks
, size
);
601 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
603 return ERR_PTR(-ENOMEM
);
604 memset(cqr
, 0, sizeof(struct dasd_ccw_req
));
605 data
= (char *) cqr
+ ((sizeof(struct dasd_ccw_req
) + 7L) & -8L);
608 cqr
->cpaddr
= (struct ccw1
*) data
;
609 data
+= cplength
*sizeof(struct ccw1
);
610 memset(cqr
->cpaddr
, 0, cplength
*sizeof(struct ccw1
));
615 memset(cqr
->data
, 0, datasize
);
617 strncpy((char *) &cqr
->magic
, magic
, 4);
618 ASCEBC((char *) &cqr
->magic
, 4);
619 set_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
);
620 dasd_get_device(device
);
625 * Free memory of a channel program. This function needs to free all the
626 * idal lists that might have been created by dasd_set_cda and the
627 * struct dasd_ccw_req itself.
630 dasd_kfree_request(struct dasd_ccw_req
* cqr
, struct dasd_device
* device
)
635 /* Clear any idals used for the request. */
638 clear_normalized_cda(ccw
);
639 } while (ccw
++->flags
& (CCW_FLAG_CC
| CCW_FLAG_DC
));
644 dasd_put_device(device
);
648 dasd_sfree_request(struct dasd_ccw_req
* cqr
, struct dasd_device
* device
)
652 spin_lock_irqsave(&device
->mem_lock
, flags
);
653 dasd_free_chunk(&device
->ccw_chunks
, cqr
);
654 spin_unlock_irqrestore(&device
->mem_lock
, flags
);
655 dasd_put_device(device
);
659 * Check discipline magic in cqr.
662 dasd_check_cqr(struct dasd_ccw_req
*cqr
)
664 struct dasd_device
*device
;
668 device
= cqr
->device
;
669 if (strncmp((char *) &cqr
->magic
, device
->discipline
->ebcname
, 4)) {
670 DEV_MESSAGE(KERN_WARNING
, device
,
671 " dasd_ccw_req 0x%08x magic doesn't match"
672 " discipline 0x%08x",
674 *(unsigned int *) device
->discipline
->name
);
681 * Terminate the current i/o and set the request to clear_pending.
682 * Timer keeps device runnig.
683 * ccw_device_clear can fail if the i/o subsystem
687 dasd_term_IO(struct dasd_ccw_req
* cqr
)
689 struct dasd_device
*device
;
693 rc
= dasd_check_cqr(cqr
);
697 device
= (struct dasd_device
*) cqr
->device
;
698 while ((retries
< 5) && (cqr
->status
== DASD_CQR_IN_IO
)) {
699 rc
= ccw_device_clear(device
->cdev
, (long) cqr
);
701 case 0: /* termination successful */
703 cqr
->status
= DASD_CQR_CLEAR
;
704 cqr
->stopclk
= get_clock();
705 DBF_DEV_EVENT(DBF_DEBUG
, device
,
706 "terminate cqr %p successful",
710 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
711 "device gone, retry");
714 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
719 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
720 "device busy, retry later");
723 DEV_MESSAGE(KERN_ERR
, device
,
724 "line %d unknown RC=%d, please "
725 "report to linux390@de.ibm.com",
732 dasd_schedule_bh(device
);
737 * Start the i/o. This start_IO can fail if the channel is really busy.
738 * In that case set up a timer to start the request later.
741 dasd_start_IO(struct dasd_ccw_req
* cqr
)
743 struct dasd_device
*device
;
747 rc
= dasd_check_cqr(cqr
);
750 device
= (struct dasd_device
*) cqr
->device
;
751 if (cqr
->retries
< 0) {
752 DEV_MESSAGE(KERN_DEBUG
, device
,
753 "start_IO: request %p (%02x/%i) - no retry left.",
754 cqr
, cqr
->status
, cqr
->retries
);
755 cqr
->status
= DASD_CQR_FAILED
;
758 cqr
->startclk
= get_clock();
759 cqr
->starttime
= jiffies
;
761 rc
= ccw_device_start(device
->cdev
, cqr
->cpaddr
, (long) cqr
,
765 cqr
->status
= DASD_CQR_IN_IO
;
766 DBF_DEV_EVENT(DBF_DEBUG
, device
,
767 "start_IO: request %p started successful",
771 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
772 "start_IO: device busy, retry later");
775 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
776 "start_IO: request timeout, retry later");
779 /* -EACCES indicates that the request used only a
780 * subset of the available pathes and all these
782 * Do a retry with all available pathes.
784 cqr
->lpm
= LPM_ANYPATH
;
785 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
786 "start_IO: selected pathes gone,"
787 " retry on all pathes");
791 DBF_DEV_EVENT(DBF_ERR
, device
, "%s",
792 "start_IO: device gone, retry");
795 DEV_MESSAGE(KERN_ERR
, device
,
796 "line %d unknown RC=%d, please report"
797 " to linux390@de.ibm.com", __LINE__
, rc
);
805 * Timeout function for dasd devices. This is used for different purposes
806 * 1) missing interrupt handler for normal operation
807 * 2) delayed start of request where start_IO failed with -EBUSY
808 * 3) timeout for missing state change interrupts
809 * The head of the ccw queue will have status DASD_CQR_IN_IO for 1),
810 * DASD_CQR_QUEUED for 2) and 3).
813 dasd_timeout_device(unsigned long ptr
)
816 struct dasd_device
*device
;
818 device
= (struct dasd_device
*) ptr
;
819 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
820 /* re-activate request queue */
821 device
->stopped
&= ~DASD_STOPPED_PENDING
;
822 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
823 dasd_schedule_bh(device
);
827 * Setup timeout for a device in jiffies.
830 dasd_set_timer(struct dasd_device
*device
, int expires
)
833 if (timer_pending(&device
->timer
))
834 del_timer(&device
->timer
);
837 if (timer_pending(&device
->timer
)) {
838 if (mod_timer(&device
->timer
, jiffies
+ expires
))
841 device
->timer
.function
= dasd_timeout_device
;
842 device
->timer
.data
= (unsigned long) device
;
843 device
->timer
.expires
= jiffies
+ expires
;
844 add_timer(&device
->timer
);
848 * Clear timeout for a device.
851 dasd_clear_timer(struct dasd_device
*device
)
853 if (timer_pending(&device
->timer
))
854 del_timer(&device
->timer
);
858 dasd_handle_killed_request(struct ccw_device
*cdev
, unsigned long intparm
)
860 struct dasd_ccw_req
*cqr
;
861 struct dasd_device
*device
;
863 cqr
= (struct dasd_ccw_req
*) intparm
;
864 if (cqr
->status
!= DASD_CQR_IN_IO
) {
866 "invalid status in handle_killed_request: "
867 "bus_id %s, status %02x",
868 cdev
->dev
.bus_id
, cqr
->status
);
872 device
= (struct dasd_device
*) cqr
->device
;
873 if (device
== NULL
||
874 device
!= dasd_device_from_cdev(cdev
) ||
875 strncmp(device
->discipline
->ebcname
, (char *) &cqr
->magic
, 4)) {
876 MESSAGE(KERN_DEBUG
, "invalid device in request: bus_id %s",
881 /* Schedule request to be retried. */
882 cqr
->status
= DASD_CQR_QUEUED
;
884 dasd_clear_timer(device
);
885 dasd_schedule_bh(device
);
886 dasd_put_device(device
);
890 dasd_handle_state_change_pending(struct dasd_device
*device
)
892 struct dasd_ccw_req
*cqr
;
893 struct list_head
*l
, *n
;
895 /* First of all start sense subsystem status request. */
896 dasd_eer_snss(device
);
898 device
->stopped
&= ~DASD_STOPPED_PENDING
;
900 /* restart all 'running' IO on queue */
901 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
902 cqr
= list_entry(l
, struct dasd_ccw_req
, list
);
903 if (cqr
->status
== DASD_CQR_IN_IO
) {
904 cqr
->status
= DASD_CQR_QUEUED
;
907 dasd_clear_timer(device
);
908 dasd_schedule_bh(device
);
912 * Interrupt handler for "normal" ssch-io based dasd devices.
915 dasd_int_handler(struct ccw_device
*cdev
, unsigned long intparm
,
918 struct dasd_ccw_req
*cqr
, *next
;
919 struct dasd_device
*device
;
920 unsigned long long now
;
926 switch (PTR_ERR(irb
)) {
928 dasd_handle_killed_request(cdev
, intparm
);
931 printk(KERN_WARNING
"%s(%s): request timed out\n",
932 __FUNCTION__
, cdev
->dev
.bus_id
);
933 //FIXME - dasd uses own timeout interface...
936 printk(KERN_WARNING
"%s(%s): unknown error %ld\n",
937 __FUNCTION__
, cdev
->dev
.bus_id
, PTR_ERR(irb
));
944 DBF_EVENT(DBF_ERR
, "Interrupt: bus_id %s CS/DS %04x ip %08x",
945 cdev
->dev
.bus_id
, ((irb
->scsw
.cstat
<<8)|irb
->scsw
.dstat
),
946 (unsigned int) intparm
);
948 /* first of all check for state change pending interrupt */
949 mask
= DEV_STAT_ATTENTION
| DEV_STAT_DEV_END
| DEV_STAT_UNIT_EXCEP
;
950 if ((irb
->scsw
.dstat
& mask
) == mask
) {
951 device
= dasd_device_from_cdev(cdev
);
952 if (!IS_ERR(device
)) {
953 dasd_handle_state_change_pending(device
);
954 dasd_put_device(device
);
959 cqr
= (struct dasd_ccw_req
*) intparm
;
961 /* check for unsolicited interrupts */
964 "unsolicited interrupt received: bus_id %s",
969 device
= (struct dasd_device
*) cqr
->device
;
970 if (device
== NULL
||
971 strncmp(device
->discipline
->ebcname
, (char *) &cqr
->magic
, 4)) {
972 MESSAGE(KERN_DEBUG
, "invalid device in request: bus_id %s",
977 /* Check for clear pending */
978 if (cqr
->status
== DASD_CQR_CLEAR
&&
979 irb
->scsw
.fctl
& SCSW_FCTL_CLEAR_FUNC
) {
980 cqr
->status
= DASD_CQR_QUEUED
;
981 dasd_clear_timer(device
);
982 dasd_schedule_bh(device
);
986 /* check status - the request might have been killed by dyn detach */
987 if (cqr
->status
!= DASD_CQR_IN_IO
) {
989 "invalid status: bus_id %s, status %02x",
990 cdev
->dev
.bus_id
, cqr
->status
);
993 DBF_DEV_EVENT(DBF_DEBUG
, device
, "Int: CS/DS 0x%04x for cqr %p",
994 ((irb
->scsw
.cstat
<< 8) | irb
->scsw
.dstat
), cqr
);
996 /* Find out the appropriate era_action. */
997 if (irb
->scsw
.fctl
& SCSW_FCTL_HALT_FUNC
)
998 era
= dasd_era_fatal
;
999 else if (irb
->scsw
.dstat
== (DEV_STAT_CHN_END
| DEV_STAT_DEV_END
) &&
1000 irb
->scsw
.cstat
== 0 &&
1001 !irb
->esw
.esw0
.erw
.cons
)
1002 era
= dasd_era_none
;
1003 else if (!test_bit(DASD_CQR_FLAGS_USE_ERP
, &cqr
->flags
))
1004 era
= dasd_era_fatal
; /* don't recover this request */
1005 else if (irb
->esw
.esw0
.erw
.cons
)
1006 era
= device
->discipline
->examine_error(cqr
, irb
);
1008 era
= dasd_era_recover
;
1010 DBF_DEV_EVENT(DBF_DEBUG
, device
, "era_code %d", era
);
1012 if (era
== dasd_era_none
) {
1013 cqr
->status
= DASD_CQR_DONE
;
1015 /* Start first request on queue if possible -> fast_io. */
1016 if (cqr
->list
.next
!= &device
->ccw_queue
) {
1017 next
= list_entry(cqr
->list
.next
,
1018 struct dasd_ccw_req
, list
);
1019 if ((next
->status
== DASD_CQR_QUEUED
) &&
1020 (!device
->stopped
)) {
1021 if (device
->discipline
->start_IO(next
) == 0)
1022 expires
= next
->expires
;
1024 DEV_MESSAGE(KERN_DEBUG
, device
, "%s",
1025 "Interrupt fastpath "
1029 } else { /* error */
1030 memcpy(&cqr
->irb
, irb
, sizeof (struct irb
));
1032 /* dump sense data */
1033 dasd_log_sense(cqr
, irb
);
1036 case dasd_era_fatal
:
1037 cqr
->status
= DASD_CQR_FAILED
;
1040 case dasd_era_recover
:
1041 cqr
->status
= DASD_CQR_ERROR
;
1048 dasd_set_timer(device
, expires
);
1050 dasd_clear_timer(device
);
1051 dasd_schedule_bh(device
);
1055 * posts the buffer_cache about a finalized request
1058 dasd_end_request(struct request
*req
, int uptodate
)
1060 if (end_that_request_first(req
, uptodate
, req
->hard_nr_sectors
))
1062 add_disk_randomness(req
->rq_disk
);
1063 end_that_request_last(req
, uptodate
);
1067 * Process finished error recovery ccw.
1070 __dasd_process_erp(struct dasd_device
*device
, struct dasd_ccw_req
*cqr
)
1072 dasd_erp_fn_t erp_fn
;
1074 if (cqr
->status
== DASD_CQR_DONE
)
1075 DBF_DEV_EVENT(DBF_NOTICE
, device
, "%s", "ERP successful");
1077 DEV_MESSAGE(KERN_ERR
, device
, "%s", "ERP unsuccessful");
1078 erp_fn
= device
->discipline
->erp_postaction(cqr
);
1083 * Process ccw request queue.
1086 __dasd_process_ccw_queue(struct dasd_device
* device
,
1087 struct list_head
*final_queue
)
1089 struct list_head
*l
, *n
;
1090 struct dasd_ccw_req
*cqr
;
1091 dasd_erp_fn_t erp_fn
;
1094 /* Process request with final status. */
1095 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1096 cqr
= list_entry(l
, struct dasd_ccw_req
, list
);
1097 /* Stop list processing at the first non-final request. */
1098 if (cqr
->status
!= DASD_CQR_DONE
&&
1099 cqr
->status
!= DASD_CQR_FAILED
&&
1100 cqr
->status
!= DASD_CQR_ERROR
)
1102 /* Process requests with DASD_CQR_ERROR */
1103 if (cqr
->status
== DASD_CQR_ERROR
) {
1104 if (cqr
->irb
.scsw
.fctl
& SCSW_FCTL_HALT_FUNC
) {
1105 cqr
->status
= DASD_CQR_FAILED
;
1106 cqr
->stopclk
= get_clock();
1108 if (cqr
->irb
.esw
.esw0
.erw
.cons
) {
1109 erp_fn
= device
->discipline
->
1113 dasd_default_erp_action(cqr
);
1118 /* First of all call extended error reporting. */
1119 if (dasd_eer_enabled(device
) &&
1120 cqr
->status
== DASD_CQR_FAILED
) {
1121 dasd_eer_write(device
, cqr
, DASD_EER_FATALERROR
);
1123 /* restart request */
1124 cqr
->status
= DASD_CQR_QUEUED
;
1126 device
->stopped
|= DASD_STOPPED_QUIESCE
;
1130 /* Process finished ERP request. */
1132 __dasd_process_erp(device
, cqr
);
1136 /* Rechain finished requests to final queue */
1137 cqr
->endclk
= get_clock();
1138 list_move_tail(&cqr
->list
, final_queue
);
1143 dasd_end_request_cb(struct dasd_ccw_req
* cqr
, void *data
)
1145 struct request
*req
;
1146 struct dasd_device
*device
;
1149 req
= (struct request
*) data
;
1150 device
= cqr
->device
;
1151 dasd_profile_end(device
, cqr
, req
);
1152 status
= cqr
->device
->discipline
->free_cp(cqr
,req
);
1153 spin_lock_irq(&device
->request_queue_lock
);
1154 dasd_end_request(req
, status
);
1155 spin_unlock_irq(&device
->request_queue_lock
);
1160 * Fetch requests from the block device queue.
1163 __dasd_process_blk_queue(struct dasd_device
* device
)
1165 request_queue_t
*queue
;
1166 struct request
*req
;
1167 struct dasd_ccw_req
*cqr
;
1170 queue
= device
->request_queue
;
1171 /* No queue ? Then there is nothing to do. */
1176 * We requeue request from the block device queue to the ccw
1177 * queue only in two states. In state DASD_STATE_READY the
1178 * partition detection is done and we need to requeue requests
1179 * for that. State DASD_STATE_ONLINE is normal block device
1182 if (device
->state
!= DASD_STATE_READY
&&
1183 device
->state
!= DASD_STATE_ONLINE
)
1186 /* Now we try to fetch requests from the request queue */
1187 list_for_each_entry(cqr
, &device
->ccw_queue
, list
)
1188 if (cqr
->status
== DASD_CQR_QUEUED
)
1190 while (!blk_queue_plugged(queue
) &&
1191 elv_next_request(queue
) &&
1192 nr_queued
< DASD_CHANQ_MAX_SIZE
) {
1193 req
= elv_next_request(queue
);
1195 if (device
->features
& DASD_FEATURE_READONLY
&&
1196 rq_data_dir(req
) == WRITE
) {
1197 DBF_DEV_EVENT(DBF_ERR
, device
,
1198 "Rejecting write request %p",
1200 blkdev_dequeue_request(req
);
1201 dasd_end_request(req
, 0);
1204 if (device
->stopped
& DASD_STOPPED_DC_EIO
) {
1205 blkdev_dequeue_request(req
);
1206 dasd_end_request(req
, 0);
1209 cqr
= device
->discipline
->build_cp(device
, req
);
1211 if (PTR_ERR(cqr
) == -ENOMEM
)
1212 break; /* terminate request queue loop */
1213 DBF_DEV_EVENT(DBF_ERR
, device
,
1214 "CCW creation failed (rc=%ld) "
1217 blkdev_dequeue_request(req
);
1218 dasd_end_request(req
, 0);
1221 cqr
->callback
= dasd_end_request_cb
;
1222 cqr
->callback_data
= (void *) req
;
1223 cqr
->status
= DASD_CQR_QUEUED
;
1224 blkdev_dequeue_request(req
);
1225 list_add_tail(&cqr
->list
, &device
->ccw_queue
);
1226 dasd_profile_start(device
, cqr
, req
);
1232 * Take a look at the first request on the ccw queue and check
1233 * if it reached its expire time. If so, terminate the IO.
1236 __dasd_check_expire(struct dasd_device
* device
)
1238 struct dasd_ccw_req
*cqr
;
1240 if (list_empty(&device
->ccw_queue
))
1242 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, list
);
1243 if (cqr
->status
== DASD_CQR_IN_IO
&& cqr
->expires
!= 0) {
1244 if (time_after_eq(jiffies
, cqr
->expires
+ cqr
->starttime
)) {
1245 if (device
->discipline
->term_IO(cqr
) != 0)
1246 /* Hmpf, try again in 1/10 sec */
1247 dasd_set_timer(device
, 10);
1253 * Take a look at the first request on the ccw queue and check
1254 * if it needs to be started.
1257 __dasd_start_head(struct dasd_device
* device
)
1259 struct dasd_ccw_req
*cqr
;
1262 if (list_empty(&device
->ccw_queue
))
1264 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, list
);
1265 if (cqr
->status
!= DASD_CQR_QUEUED
)
1267 /* Non-temporary stop condition will trigger fail fast */
1268 if (device
->stopped
& ~DASD_STOPPED_PENDING
&&
1269 test_bit(DASD_CQR_FLAGS_FAILFAST
, &cqr
->flags
) &&
1270 (!dasd_eer_enabled(device
))) {
1271 cqr
->status
= DASD_CQR_FAILED
;
1272 dasd_schedule_bh(device
);
1275 /* Don't try to start requests if device is stopped */
1276 if (device
->stopped
)
1279 rc
= device
->discipline
->start_IO(cqr
);
1281 dasd_set_timer(device
, cqr
->expires
);
1282 else if (rc
== -EACCES
) {
1283 dasd_schedule_bh(device
);
1285 /* Hmpf, try again in 1/2 sec */
1286 dasd_set_timer(device
, 50);
1290 * Remove requests from the ccw queue.
1293 dasd_flush_ccw_queue(struct dasd_device
* device
, int all
)
1295 struct list_head flush_queue
;
1296 struct list_head
*l
, *n
;
1297 struct dasd_ccw_req
*cqr
;
1299 INIT_LIST_HEAD(&flush_queue
);
1300 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
1301 list_for_each_safe(l
, n
, &device
->ccw_queue
) {
1302 cqr
= list_entry(l
, struct dasd_ccw_req
, list
);
1303 /* Flush all request or only block device requests? */
1304 if (all
== 0 && cqr
->callback
== dasd_end_request_cb
)
1306 if (cqr
->status
== DASD_CQR_IN_IO
)
1307 device
->discipline
->term_IO(cqr
);
1308 if (cqr
->status
!= DASD_CQR_DONE
||
1309 cqr
->status
!= DASD_CQR_FAILED
) {
1310 cqr
->status
= DASD_CQR_FAILED
;
1311 cqr
->stopclk
= get_clock();
1313 /* Process finished ERP request. */
1315 __dasd_process_erp(device
, cqr
);
1318 /* Rechain request on device request queue */
1319 cqr
->endclk
= get_clock();
1320 list_move_tail(&cqr
->list
, &flush_queue
);
1322 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1323 /* Now call the callback function of flushed requests */
1324 list_for_each_safe(l
, n
, &flush_queue
) {
1325 cqr
= list_entry(l
, struct dasd_ccw_req
, list
);
1326 if (cqr
->callback
!= NULL
)
1327 (cqr
->callback
)(cqr
, cqr
->callback_data
);
1332 * Acquire the device lock and process queues for the device.
1335 dasd_tasklet(struct dasd_device
* device
)
1337 struct list_head final_queue
;
1338 struct list_head
*l
, *n
;
1339 struct dasd_ccw_req
*cqr
;
1341 atomic_set (&device
->tasklet_scheduled
, 0);
1342 INIT_LIST_HEAD(&final_queue
);
1343 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
1344 /* Check expire time of first request on the ccw queue. */
1345 __dasd_check_expire(device
);
1346 /* Finish off requests on ccw queue */
1347 __dasd_process_ccw_queue(device
, &final_queue
);
1348 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1349 /* Now call the callback function of requests with final status */
1350 list_for_each_safe(l
, n
, &final_queue
) {
1351 cqr
= list_entry(l
, struct dasd_ccw_req
, list
);
1352 list_del_init(&cqr
->list
);
1353 if (cqr
->callback
!= NULL
)
1354 (cqr
->callback
)(cqr
, cqr
->callback_data
);
1356 spin_lock_irq(&device
->request_queue_lock
);
1357 spin_lock(get_ccwdev_lock(device
->cdev
));
1358 /* Get new request from the block device request queue */
1359 __dasd_process_blk_queue(device
);
1360 /* Now check if the head of the ccw queue needs to be started. */
1361 __dasd_start_head(device
);
1362 spin_unlock(get_ccwdev_lock(device
->cdev
));
1363 spin_unlock_irq(&device
->request_queue_lock
);
1364 dasd_put_device(device
);
1368 * Schedules a call to dasd_tasklet over the device tasklet.
1371 dasd_schedule_bh(struct dasd_device
* device
)
1373 /* Protect against rescheduling. */
1374 if (atomic_cmpxchg (&device
->tasklet_scheduled
, 0, 1) != 0)
1376 dasd_get_device(device
);
1377 tasklet_hi_schedule(&device
->tasklet
);
1381 * Queue a request to the head of the ccw_queue. Start the I/O if
1385 dasd_add_request_head(struct dasd_ccw_req
*req
)
1387 struct dasd_device
*device
;
1388 unsigned long flags
;
1390 device
= req
->device
;
1391 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1392 req
->status
= DASD_CQR_QUEUED
;
1393 req
->device
= device
;
1394 list_add(&req
->list
, &device
->ccw_queue
);
1395 /* let the bh start the request to keep them in order */
1396 dasd_schedule_bh(device
);
1397 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1401 * Queue a request to the tail of the ccw_queue. Start the I/O if
1405 dasd_add_request_tail(struct dasd_ccw_req
*req
)
1407 struct dasd_device
*device
;
1408 unsigned long flags
;
1410 device
= req
->device
;
1411 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1412 req
->status
= DASD_CQR_QUEUED
;
1413 req
->device
= device
;
1414 list_add_tail(&req
->list
, &device
->ccw_queue
);
1415 /* let the bh start the request to keep them in order */
1416 dasd_schedule_bh(device
);
1417 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1424 dasd_wakeup_cb(struct dasd_ccw_req
*cqr
, void *data
)
1426 wake_up((wait_queue_head_t
*) data
);
1430 _wait_for_wakeup(struct dasd_ccw_req
*cqr
)
1432 struct dasd_device
*device
;
1435 device
= cqr
->device
;
1436 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
1437 rc
= ((cqr
->status
== DASD_CQR_DONE
||
1438 cqr
->status
== DASD_CQR_FAILED
) &&
1439 list_empty(&cqr
->list
));
1440 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1445 * Attempts to start a special ccw queue and waits for its completion.
1448 dasd_sleep_on(struct dasd_ccw_req
* cqr
)
1450 wait_queue_head_t wait_q
;
1451 struct dasd_device
*device
;
1454 device
= cqr
->device
;
1455 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
1457 init_waitqueue_head (&wait_q
);
1458 cqr
->callback
= dasd_wakeup_cb
;
1459 cqr
->callback_data
= (void *) &wait_q
;
1460 cqr
->status
= DASD_CQR_QUEUED
;
1461 list_add_tail(&cqr
->list
, &device
->ccw_queue
);
1463 /* let the bh start the request to keep them in order */
1464 dasd_schedule_bh(device
);
1466 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1468 wait_event(wait_q
, _wait_for_wakeup(cqr
));
1470 /* Request status is either done or failed. */
1471 rc
= (cqr
->status
== DASD_CQR_FAILED
) ? -EIO
: 0;
1476 * Attempts to start a special ccw queue and wait interruptible
1477 * for its completion.
1480 dasd_sleep_on_interruptible(struct dasd_ccw_req
* cqr
)
1482 wait_queue_head_t wait_q
;
1483 struct dasd_device
*device
;
1486 device
= cqr
->device
;
1487 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
1489 init_waitqueue_head (&wait_q
);
1490 cqr
->callback
= dasd_wakeup_cb
;
1491 cqr
->callback_data
= (void *) &wait_q
;
1492 cqr
->status
= DASD_CQR_QUEUED
;
1493 list_add_tail(&cqr
->list
, &device
->ccw_queue
);
1495 /* let the bh start the request to keep them in order */
1496 dasd_schedule_bh(device
);
1497 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1501 rc
= wait_event_interruptible(wait_q
, _wait_for_wakeup(cqr
));
1502 if (rc
!= -ERESTARTSYS
) {
1503 /* Request is final (done or failed) */
1504 rc
= (cqr
->status
== DASD_CQR_DONE
) ? 0 : -EIO
;
1507 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
1508 switch (cqr
->status
) {
1509 case DASD_CQR_IN_IO
:
1510 /* terminate runnig cqr */
1511 if (device
->discipline
->term_IO
) {
1513 device
->discipline
->term_IO(cqr
);
1515 * wait (non-interruptible) for final status
1516 * because signal ist still pending
1518 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1519 wait_event(wait_q
, _wait_for_wakeup(cqr
));
1520 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
1521 rc
= (cqr
->status
== DASD_CQR_DONE
) ? 0 : -EIO
;
1525 case DASD_CQR_QUEUED
:
1527 list_del_init(&cqr
->list
);
1532 /* cqr with 'non-interruptable' status - just wait */
1535 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1541 * Whoa nelly now it gets really hairy. For some functions (e.g. steal lock
1542 * for eckd devices) the currently running request has to be terminated
1543 * and be put back to status queued, before the special request is added
1544 * to the head of the queue. Then the special request is waited on normally.
1547 _dasd_term_running_cqr(struct dasd_device
*device
)
1549 struct dasd_ccw_req
*cqr
;
1552 if (list_empty(&device
->ccw_queue
))
1554 cqr
= list_entry(device
->ccw_queue
.next
, struct dasd_ccw_req
, list
);
1555 rc
= device
->discipline
->term_IO(cqr
);
1557 /* termination successful */
1558 cqr
->status
= DASD_CQR_QUEUED
;
1559 cqr
->startclk
= cqr
->stopclk
= 0;
1566 dasd_sleep_on_immediatly(struct dasd_ccw_req
* cqr
)
1568 wait_queue_head_t wait_q
;
1569 struct dasd_device
*device
;
1572 device
= cqr
->device
;
1573 spin_lock_irq(get_ccwdev_lock(device
->cdev
));
1574 rc
= _dasd_term_running_cqr(device
);
1576 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1580 init_waitqueue_head (&wait_q
);
1581 cqr
->callback
= dasd_wakeup_cb
;
1582 cqr
->callback_data
= (void *) &wait_q
;
1583 cqr
->status
= DASD_CQR_QUEUED
;
1584 list_add(&cqr
->list
, &device
->ccw_queue
);
1586 /* let the bh start the request to keep them in order */
1587 dasd_schedule_bh(device
);
1589 spin_unlock_irq(get_ccwdev_lock(device
->cdev
));
1591 wait_event(wait_q
, _wait_for_wakeup(cqr
));
1593 /* Request status is either done or failed. */
1594 rc
= (cqr
->status
== DASD_CQR_FAILED
) ? -EIO
: 0;
1599 * Cancels a request that was started with dasd_sleep_on_req.
1600 * This is useful to timeout requests. The request will be
1601 * terminated if it is currently in i/o.
1602 * Returns 1 if the request has been terminated.
1605 dasd_cancel_req(struct dasd_ccw_req
*cqr
)
1607 struct dasd_device
*device
= cqr
->device
;
1608 unsigned long flags
;
1612 spin_lock_irqsave(get_ccwdev_lock(device
->cdev
), flags
);
1613 switch (cqr
->status
) {
1614 case DASD_CQR_QUEUED
:
1615 /* request was not started - just set to failed */
1616 cqr
->status
= DASD_CQR_FAILED
;
1618 case DASD_CQR_IN_IO
:
1619 /* request in IO - terminate IO and release again */
1620 if (device
->discipline
->term_IO(cqr
) != 0)
1621 /* what to do if unable to terminate ??????
1623 cqr
->status
= DASD_CQR_FAILED
;
1624 cqr
->stopclk
= get_clock();
1628 case DASD_CQR_FAILED
:
1629 /* already finished - do nothing */
1632 DEV_MESSAGE(KERN_ALERT
, device
,
1633 "invalid status %02x in request",
1638 spin_unlock_irqrestore(get_ccwdev_lock(device
->cdev
), flags
);
1639 dasd_schedule_bh(device
);
1644 * SECTION: Block device operations (request queue, partitions, open, release).
1648 * Dasd request queue function. Called from ll_rw_blk.c
1651 do_dasd_request(request_queue_t
* queue
)
1653 struct dasd_device
*device
;
1655 device
= (struct dasd_device
*) queue
->queuedata
;
1656 spin_lock(get_ccwdev_lock(device
->cdev
));
1657 /* Get new request from the block device request queue */
1658 __dasd_process_blk_queue(device
);
1659 /* Now check if the head of the ccw queue needs to be started. */
1660 __dasd_start_head(device
);
1661 spin_unlock(get_ccwdev_lock(device
->cdev
));
1665 * Allocate and initialize request queue and default I/O scheduler.
1668 dasd_alloc_queue(struct dasd_device
* device
)
1672 device
->request_queue
= blk_init_queue(do_dasd_request
,
1673 &device
->request_queue_lock
);
1674 if (device
->request_queue
== NULL
)
1677 device
->request_queue
->queuedata
= device
;
1679 elevator_exit(device
->request_queue
->elevator
);
1680 rc
= elevator_init(device
->request_queue
, "deadline");
1682 blk_cleanup_queue(device
->request_queue
);
1689 * Allocate and initialize request queue.
1692 dasd_setup_queue(struct dasd_device
* device
)
1696 blk_queue_hardsect_size(device
->request_queue
, device
->bp_block
);
1697 max
= device
->discipline
->max_blocks
<< device
->s2b_shift
;
1698 blk_queue_max_sectors(device
->request_queue
, max
);
1699 blk_queue_max_phys_segments(device
->request_queue
, -1L);
1700 blk_queue_max_hw_segments(device
->request_queue
, -1L);
1701 blk_queue_max_segment_size(device
->request_queue
, -1L);
1702 blk_queue_segment_boundary(device
->request_queue
, -1L);
1703 blk_queue_ordered(device
->request_queue
, QUEUE_ORDERED_TAG
, NULL
);
1707 * Deactivate and free request queue.
1710 dasd_free_queue(struct dasd_device
* device
)
1712 if (device
->request_queue
) {
1713 blk_cleanup_queue(device
->request_queue
);
1714 device
->request_queue
= NULL
;
1719 * Flush request on the request queue.
1722 dasd_flush_request_queue(struct dasd_device
* device
)
1724 struct request
*req
;
1726 if (!device
->request_queue
)
1729 spin_lock_irq(&device
->request_queue_lock
);
1730 while (!list_empty(&device
->request_queue
->queue_head
)) {
1731 req
= elv_next_request(device
->request_queue
);
1734 dasd_end_request(req
, 0);
1735 blkdev_dequeue_request(req
);
1737 spin_unlock_irq(&device
->request_queue_lock
);
1741 dasd_open(struct inode
*inp
, struct file
*filp
)
1743 struct gendisk
*disk
= inp
->i_bdev
->bd_disk
;
1744 struct dasd_device
*device
= disk
->private_data
;
1747 atomic_inc(&device
->open_count
);
1748 if (test_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
1753 if (!try_module_get(device
->discipline
->owner
)) {
1758 if (dasd_probeonly
) {
1759 DEV_MESSAGE(KERN_INFO
, device
, "%s",
1760 "No access to device due to probeonly mode");
1765 if (device
->state
<= DASD_STATE_BASIC
) {
1766 DBF_DEV_EVENT(DBF_ERR
, device
, " %s",
1767 " Cannot open unrecognized device");
1775 module_put(device
->discipline
->owner
);
1777 atomic_dec(&device
->open_count
);
1782 dasd_release(struct inode
*inp
, struct file
*filp
)
1784 struct gendisk
*disk
= inp
->i_bdev
->bd_disk
;
1785 struct dasd_device
*device
= disk
->private_data
;
1787 atomic_dec(&device
->open_count
);
1788 module_put(device
->discipline
->owner
);
1793 * Return disk geometry.
1796 dasd_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
1798 struct dasd_device
*device
;
1800 device
= bdev
->bd_disk
->private_data
;
1804 if (!device
->discipline
||
1805 !device
->discipline
->fill_geometry
)
1808 device
->discipline
->fill_geometry(device
, geo
);
1809 geo
->start
= get_start_sect(bdev
) >> device
->s2b_shift
;
1813 struct block_device_operations
1814 dasd_device_operations
= {
1815 .owner
= THIS_MODULE
,
1817 .release
= dasd_release
,
1818 .ioctl
= dasd_ioctl
,
1819 .compat_ioctl
= dasd_compat_ioctl
,
1820 .getgeo
= dasd_getgeo
,
1827 #ifdef CONFIG_PROC_FS
1831 if (dasd_page_cache
!= NULL
) {
1832 kmem_cache_destroy(dasd_page_cache
);
1833 dasd_page_cache
= NULL
;
1835 dasd_gendisk_exit();
1837 devfs_remove("dasd");
1838 if (dasd_debug_area
!= NULL
) {
1839 debug_unregister(dasd_debug_area
);
1840 dasd_debug_area
= NULL
;
1845 * SECTION: common functions for ccw_driver use
1849 * Initial attempt at a probe function. this can be simplified once
1850 * the other detection code is gone.
1853 dasd_generic_probe (struct ccw_device
*cdev
,
1854 struct dasd_discipline
*discipline
)
1858 ret
= dasd_add_sysfs_files(cdev
);
1861 "dasd_generic_probe: could not add sysfs entries "
1862 "for %s\n", cdev
->dev
.bus_id
);
1864 cdev
->handler
= &dasd_int_handler
;
1871 * This will one day be called from a global not_oper handler.
1872 * It is also used by driver_unregister during module unload.
1875 dasd_generic_remove (struct ccw_device
*cdev
)
1877 struct dasd_device
*device
;
1879 cdev
->handler
= NULL
;
1881 dasd_remove_sysfs_files(cdev
);
1882 device
= dasd_device_from_cdev(cdev
);
1885 if (test_and_set_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
1886 /* Already doing offline processing */
1887 dasd_put_device(device
);
1891 * This device is removed unconditionally. Set offline
1892 * flag to prevent dasd_open from opening it while it is
1893 * no quite down yet.
1895 dasd_set_target_state(device
, DASD_STATE_NEW
);
1896 /* dasd_delete_device destroys the device reference. */
1897 dasd_delete_device(device
);
1901 * Activate a device. This is called from dasd_{eckd,fba}_probe() when either
1902 * the device is detected for the first time and is supposed to be used
1903 * or the user has started activation through sysfs.
1906 dasd_generic_set_online (struct ccw_device
*cdev
,
1907 struct dasd_discipline
*base_discipline
)
1910 struct dasd_discipline
*discipline
;
1911 struct dasd_device
*device
;
1914 device
= dasd_create_device(cdev
);
1916 return PTR_ERR(device
);
1918 discipline
= base_discipline
;
1919 if (device
->features
& DASD_FEATURE_USEDIAG
) {
1920 if (!dasd_diag_discipline_pointer
) {
1921 printk (KERN_WARNING
1922 "dasd_generic couldn't online device %s "
1923 "- discipline DIAG not available\n",
1925 dasd_delete_device(device
);
1928 discipline
= dasd_diag_discipline_pointer
;
1930 if (!try_module_get(base_discipline
->owner
)) {
1931 dasd_delete_device(device
);
1934 if (!try_module_get(discipline
->owner
)) {
1935 module_put(base_discipline
->owner
);
1936 dasd_delete_device(device
);
1939 device
->base_discipline
= base_discipline
;
1940 device
->discipline
= discipline
;
1942 rc
= discipline
->check_device(device
);
1944 printk (KERN_WARNING
1945 "dasd_generic couldn't online device %s "
1946 "with discipline %s rc=%i\n",
1947 cdev
->dev
.bus_id
, discipline
->name
, rc
);
1948 module_put(discipline
->owner
);
1949 module_put(base_discipline
->owner
);
1950 dasd_delete_device(device
);
1954 dasd_set_target_state(device
, DASD_STATE_ONLINE
);
1955 if (device
->state
<= DASD_STATE_KNOWN
) {
1956 printk (KERN_WARNING
1957 "dasd_generic discipline not found for %s\n",
1960 dasd_set_target_state(device
, DASD_STATE_NEW
);
1961 dasd_delete_device(device
);
1963 pr_debug("dasd_generic device %s found\n",
1966 /* FIXME: we have to wait for the root device but we don't want
1967 * to wait for each single device but for all at once. */
1968 wait_event(dasd_init_waitq
, _wait_for_device(device
));
1970 dasd_put_device(device
);
1976 dasd_generic_set_offline (struct ccw_device
*cdev
)
1978 struct dasd_device
*device
;
1979 int max_count
, open_count
;
1981 device
= dasd_device_from_cdev(cdev
);
1983 return PTR_ERR(device
);
1984 if (test_and_set_bit(DASD_FLAG_OFFLINE
, &device
->flags
)) {
1985 /* Already doing offline processing */
1986 dasd_put_device(device
);
1990 * We must make sure that this device is currently not in use.
1991 * The open_count is increased for every opener, that includes
1992 * the blkdev_get in dasd_scan_partitions. We are only interested
1993 * in the other openers.
1995 max_count
= device
->bdev
? 0 : -1;
1996 open_count
= (int) atomic_read(&device
->open_count
);
1997 if (open_count
> max_count
) {
1999 printk (KERN_WARNING
"Can't offline dasd device with "
2000 "open count = %i.\n",
2003 printk (KERN_WARNING
"%s",
2004 "Can't offline dasd device due to internal "
2006 clear_bit(DASD_FLAG_OFFLINE
, &device
->flags
);
2007 dasd_put_device(device
);
2010 dasd_set_target_state(device
, DASD_STATE_NEW
);
2011 /* dasd_delete_device destroys the device reference. */
2012 dasd_delete_device(device
);
2018 dasd_generic_notify(struct ccw_device
*cdev
, int event
)
2020 struct dasd_device
*device
;
2021 struct dasd_ccw_req
*cqr
;
2022 unsigned long flags
;
2025 device
= dasd_device_from_cdev(cdev
);
2028 spin_lock_irqsave(get_ccwdev_lock(cdev
), flags
);
2033 /* First of all call extended error reporting. */
2034 dasd_eer_write(device
, NULL
, DASD_EER_NOPATH
);
2036 if (device
->state
< DASD_STATE_BASIC
)
2038 /* Device is active. We want to keep it. */
2039 if (test_bit(DASD_FLAG_DSC_ERROR
, &device
->flags
)) {
2040 list_for_each_entry(cqr
, &device
->ccw_queue
, list
)
2041 if (cqr
->status
== DASD_CQR_IN_IO
)
2042 cqr
->status
= DASD_CQR_FAILED
;
2043 device
->stopped
|= DASD_STOPPED_DC_EIO
;
2045 list_for_each_entry(cqr
, &device
->ccw_queue
, list
)
2046 if (cqr
->status
== DASD_CQR_IN_IO
) {
2047 cqr
->status
= DASD_CQR_QUEUED
;
2050 device
->stopped
|= DASD_STOPPED_DC_WAIT
;
2051 dasd_set_timer(device
, 0);
2053 dasd_schedule_bh(device
);
2057 /* FIXME: add a sanity check. */
2058 device
->stopped
&= ~(DASD_STOPPED_DC_WAIT
|DASD_STOPPED_DC_EIO
);
2059 dasd_schedule_bh(device
);
2063 spin_unlock_irqrestore(get_ccwdev_lock(cdev
), flags
);
2064 dasd_put_device(device
);
2069 * Automatically online either all dasd devices (dasd_autodetect) or
2070 * all devices specified with dasd= parameters.
2073 __dasd_auto_online(struct device
*dev
, void *data
)
2075 struct ccw_device
*cdev
;
2077 cdev
= to_ccwdev(dev
);
2078 if (dasd_autodetect
|| dasd_busid_known(cdev
->dev
.bus_id
) == 0)
2079 ccw_device_set_online(cdev
);
2084 dasd_generic_auto_online (struct ccw_driver
*dasd_discipline_driver
)
2086 struct device_driver
*drv
;
2088 drv
= get_driver(&dasd_discipline_driver
->driver
);
2089 driver_for_each_device(drv
, NULL
, NULL
, __dasd_auto_online
);
2099 init_waitqueue_head(&dasd_init_waitq
);
2101 /* register 'common' DASD debug area, used for all DBF_XXX calls */
2102 dasd_debug_area
= debug_register("dasd", 1, 2, 8 * sizeof (long));
2103 if (dasd_debug_area
== NULL
) {
2107 debug_register_view(dasd_debug_area
, &debug_sprintf_view
);
2108 debug_set_level(dasd_debug_area
, DBF_EMERG
);
2110 DBF_EVENT(DBF_EMERG
, "%s", "debug area created");
2112 dasd_diag_discipline_pointer
= NULL
;
2114 rc
= devfs_mk_dir("dasd");
2117 rc
= dasd_devmap_init();
2120 rc
= dasd_gendisk_init();
2126 rc
= dasd_eer_init();
2129 #ifdef CONFIG_PROC_FS
2130 rc
= dasd_proc_init();
2137 MESSAGE(KERN_INFO
, "%s", "initialization not performed due to errors");
2142 module_init(dasd_init
);
2143 module_exit(dasd_exit
);
2145 EXPORT_SYMBOL(dasd_debug_area
);
2146 EXPORT_SYMBOL(dasd_diag_discipline_pointer
);
2148 EXPORT_SYMBOL(dasd_add_request_head
);
2149 EXPORT_SYMBOL(dasd_add_request_tail
);
2150 EXPORT_SYMBOL(dasd_cancel_req
);
2151 EXPORT_SYMBOL(dasd_clear_timer
);
2152 EXPORT_SYMBOL(dasd_enable_device
);
2153 EXPORT_SYMBOL(dasd_int_handler
);
2154 EXPORT_SYMBOL(dasd_kfree_request
);
2155 EXPORT_SYMBOL(dasd_kick_device
);
2156 EXPORT_SYMBOL(dasd_kmalloc_request
);
2157 EXPORT_SYMBOL(dasd_schedule_bh
);
2158 EXPORT_SYMBOL(dasd_set_target_state
);
2159 EXPORT_SYMBOL(dasd_set_timer
);
2160 EXPORT_SYMBOL(dasd_sfree_request
);
2161 EXPORT_SYMBOL(dasd_sleep_on
);
2162 EXPORT_SYMBOL(dasd_sleep_on_immediatly
);
2163 EXPORT_SYMBOL(dasd_sleep_on_interruptible
);
2164 EXPORT_SYMBOL(dasd_smalloc_request
);
2165 EXPORT_SYMBOL(dasd_start_IO
);
2166 EXPORT_SYMBOL(dasd_term_IO
);
2168 EXPORT_SYMBOL_GPL(dasd_generic_probe
);
2169 EXPORT_SYMBOL_GPL(dasd_generic_remove
);
2170 EXPORT_SYMBOL_GPL(dasd_generic_notify
);
2171 EXPORT_SYMBOL_GPL(dasd_generic_set_online
);
2172 EXPORT_SYMBOL_GPL(dasd_generic_set_offline
);
2173 EXPORT_SYMBOL_GPL(dasd_generic_auto_online
);
2176 * Overrides for Emacs so that we follow Linus's tabbing style.
2177 * Emacs will notice this stuff at the end of the file and automatically
2178 * adjust the settings for this buffer only. This must remain at the end
2180 * ---------------------------------------------------------------------------
2183 * c-brace-imaginary-offset: 0
2184 * c-brace-offset: -4
2185 * c-argdecl-indent: 4
2186 * c-label-offset: -4
2187 * c-continued-statement-offset: 4
2188 * c-continued-brace-offset: 0
2189 * indent-tabs-mode: 1