2 * linux/drivers/block/ide-disk.c Version 1.09 April 23, 1999
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
8 * Mostly written by Mark Lord <mlord@pobox.com>
9 * and Gadi Oxman <gadio@netvision.net.il>
11 * See linux/MAINTAINERS for address of current maintainer.
13 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c.
15 * Version 1.00 move disk only code from ide.c to ide-disk.c
16 * support optional byte-swapping of all data
17 * Version 1.01 fix previous byte-swapping code
18 * Version 1.02 remove ", LBA" from drive identification msgs
19 * Version 1.03 fix display of id->buf_size for big-endian
20 * Version 1.04 add /proc configurable settings and S.M.A.R.T support
21 * Version 1.05 add capacity support for ATA3 >= 8GB
22 * Version 1.06 get boot-up messages to show full cyl count
23 * Version 1.07 disable door-locking if it fails
24 * Version 1.08 fixed CHS/LBA translations for ATA4 > 8GB,
25 * process of adding new ATA4 compliance.
26 * fixed problems in allowing fdisk to see
28 * Version 1.09 added increment of rq->sector in ide_multwrite
29 * added UDMA 3/4 reporting
32 #define IDEDISK_VERSION "1.09"
34 #undef REALLY_SLOW_IO /* most systems can safely undef this */
36 #define _IDE_DISK_C /* Tell linux/hdsmart.h it's really us */
38 #include <linux/config.h>
39 #include <linux/module.h>
40 #include <linux/types.h>
41 #include <linux/string.h>
42 #include <linux/kernel.h>
43 #include <linux/timer.h>
45 #include <linux/interrupt.h>
46 #include <linux/major.h>
47 #include <linux/errno.h>
48 #include <linux/genhd.h>
49 #include <linux/malloc.h>
50 #include <linux/delay.h>
51 #include <linux/ide.h>
53 #include <asm/byteorder.h>
55 #include <asm/uaccess.h>
58 #ifdef CONFIG_BLK_DEV_PDC4030
59 #define IS_PDC4030_DRIVE (HWIF(drive)->chipset == ide_pdc4030)
61 #define IS_PDC4030_DRIVE (0) /* auto-NULLs out pdc4030 code */
64 static void idedisk_bswap_data (void *buffer
, int wcount
)
69 *p
++ = *p
<< 8 | *p
>> 8;
70 *p
++ = *p
<< 8 | *p
>> 8;
74 static inline void idedisk_input_data (ide_drive_t
*drive
, void *buffer
, unsigned int wcount
)
76 ide_input_data(drive
, buffer
, wcount
);
78 idedisk_bswap_data(buffer
, wcount
);
81 static inline void idedisk_output_data (ide_drive_t
*drive
, void *buffer
, unsigned int wcount
)
84 idedisk_bswap_data(buffer
, wcount
);
85 ide_output_data(drive
, buffer
, wcount
);
86 idedisk_bswap_data(buffer
, wcount
);
88 ide_output_data(drive
, buffer
, wcount
);
92 * lba_capacity_is_ok() performs a sanity check on the claimed "lba_capacity"
93 * value for this drive (from its reported identification information).
95 * Returns: 1 if lba_capacity looks sensible
98 * It is called only once for each drive.
100 static int lba_capacity_is_ok (struct hd_driveid
*id
)
102 unsigned long lba_sects
, chs_sects
, head
, tail
;
105 * The ATA spec tells large drives to return
106 * C/H/S = 16383/16/63 independent of their size.
107 * Some drives can be jumpered to use 15 heads instead of 16.
109 if (id
->cyls
== 16383 && id
->sectors
== 63 &&
110 (id
->heads
== 15 || id
->heads
== 16) &&
111 id
->lba_capacity
>= 16383*63*id
->heads
)
114 lba_sects
= id
->lba_capacity
;
115 chs_sects
= id
->cyls
* id
->heads
* id
->sectors
;
117 /* perform a rough sanity check on lba_sects: within 10% is OK */
118 if ((lba_sects
- chs_sects
) < chs_sects
/10)
121 /* some drives have the word order reversed */
122 head
= ((lba_sects
>> 16) & 0xffff);
123 tail
= (lba_sects
& 0xffff);
124 lba_sects
= (head
| (tail
<< 16));
125 if ((lba_sects
- chs_sects
) < chs_sects
/10) {
126 id
->lba_capacity
= lba_sects
;
127 return 1; /* lba_capacity is (now) good */
130 return 0; /* lba_capacity value may be bad */
134 * read_intr() is the handler for disk read/multread interrupts
136 static void read_intr (ide_drive_t
*drive
)
140 unsigned int msect
, nsect
;
143 if (!OK_STAT(stat
=GET_STAT(),DATA_READY
,BAD_R_STAT
)) {
144 ide_error(drive
, "read_intr", stat
);
147 msect
= drive
->mult_count
;
150 rq
= HWGROUP(drive
)->rq
;
152 if ((nsect
= rq
->current_nr_sectors
) > msect
)
158 * PIO input can take longish times, so we drop the spinlock.
159 * On SMP, bad things might happen if syscall level code adds
160 * a new request while we do this PIO, so we just freeze all
161 * request queue handling while doing the PIO. FIXME
163 idedisk_input_data(drive
, rq
->buffer
, nsect
* SECTOR_WORDS
);
165 printk("%s: read: sectors(%ld-%ld), buffer=0x%08lx, remaining=%ld\n",
166 drive
->name
, rq
->sector
, rq
->sector
+nsect
-1,
167 (unsigned long) rq
->buffer
+(nsect
<<9), rq
->nr_sectors
-nsect
);
170 rq
->buffer
+= nsect
<<9;
172 i
= (rq
->nr_sectors
-= nsect
);
173 if ((rq
->current_nr_sectors
-= nsect
) <= 0)
174 ide_end_request(1, HWGROUP(drive
));
178 ide_set_handler (drive
, &read_intr
);
183 * write_intr() is the handler for disk write interrupts
185 static void write_intr (ide_drive_t
*drive
)
189 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
190 struct request
*rq
= hwgroup
->rq
;
193 if (OK_STAT(stat
=GET_STAT(),DRIVE_READY
,drive
->bad_wstat
)) {
195 printk("%s: write: sector %ld, buffer=0x%08lx, remaining=%ld\n",
196 drive
->name
, rq
->sector
, (unsigned long) rq
->buffer
,
199 if ((rq
->nr_sectors
== 1) ^ ((stat
& DRQ_STAT
) != 0)) {
203 i
= --rq
->nr_sectors
;
204 --rq
->current_nr_sectors
;
205 if (rq
->current_nr_sectors
<= 0)
206 ide_end_request(1, hwgroup
);
208 idedisk_output_data (drive
, rq
->buffer
, SECTOR_WORDS
);
209 ide_set_handler (drive
, &write_intr
);
217 ide_error(drive
, "write_intr", stat
);
221 * ide_multwrite() transfers a block of up to mcount sectors of data
222 * to a drive as part of a disk multiple-sector write operation.
224 void ide_multwrite (ide_drive_t
*drive
, unsigned int mcount
)
226 struct request
*rq
= &HWGROUP(drive
)->wrq
;
229 unsigned int nsect
= rq
->current_nr_sectors
;
234 idedisk_output_data(drive
, rq
->buffer
, nsect
<<7);
236 printk("%s: multwrite: sector %ld, buffer=0x%08lx, count=%d, remaining=%ld\n",
237 drive
->name
, rq
->sector
, (unsigned long) rq
->buffer
,
238 nsect
, rq
->nr_sectors
- nsect
);
240 #ifdef CONFIG_BLK_DEV_PDC4030
243 if ((rq
->nr_sectors
-= nsect
) <= 0)
245 if ((rq
->current_nr_sectors
-= nsect
) == 0) {
246 if ((rq
->bh
= rq
->bh
->b_reqnext
) != NULL
) {
247 rq
->current_nr_sectors
= rq
->bh
->b_size
>>9;
248 rq
->buffer
= rq
->bh
->b_data
;
250 panic("%s: buffer list corrupted\n", drive
->name
);
254 rq
->buffer
+= nsect
<< 9;
260 * multwrite_intr() is the handler for disk multwrite interrupts
262 static void multwrite_intr (ide_drive_t
*drive
)
266 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
267 struct request
*rq
= &hwgroup
->wrq
;
270 if (OK_STAT(stat
=GET_STAT(),DRIVE_READY
,drive
->bad_wstat
)) {
271 if (stat
& DRQ_STAT
) {
272 if (rq
->nr_sectors
) {
273 ide_multwrite(drive
, drive
->mult_count
);
274 ide_set_handler (drive
, &multwrite_intr
);
278 if (!rq
->nr_sectors
) { /* all done? */
280 for (i
= rq
->nr_sectors
; i
> 0;){
281 i
-= rq
->current_nr_sectors
;
282 ide_end_request(1, hwgroup
);
291 ide_error(drive
, "multwrite_intr", stat
);
295 * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd.
297 static void set_multmode_intr (ide_drive_t
*drive
)
299 byte stat
= GET_STAT();
302 if (OK_STAT(stat
,READY_STAT
,BAD_STAT
) || drive
->mult_req
== 0) {
304 if (OK_STAT(stat
,READY_STAT
,BAD_STAT
)) {
306 drive
->mult_count
= drive
->mult_req
;
308 drive
->mult_req
= drive
->mult_count
= 0;
309 drive
->special
.b
.recalibrate
= 1;
310 (void) ide_dump_status(drive
, "set_multmode", stat
);
315 * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd.
317 static void set_geometry_intr (ide_drive_t
*drive
)
319 byte stat
= GET_STAT();
321 if (!OK_STAT(stat
,READY_STAT
,BAD_STAT
))
322 ide_error(drive
, "set_geometry_intr", stat
);
326 * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd.
328 static void recal_intr (ide_drive_t
*drive
)
330 byte stat
= GET_STAT();
332 if (!OK_STAT(stat
,READY_STAT
,BAD_STAT
))
333 ide_error(drive
, "recal_intr", stat
);
337 * do_rw_disk() issues READ and WRITE commands to a disk,
338 * using LBA if supported, or CHS otherwise, to address sectors.
339 * It also takes care of issuing special DRIVE_CMDs.
341 static void do_rw_disk (ide_drive_t
*drive
, struct request
*rq
, unsigned long block
)
344 OUT_BYTE(drive
->ctl
,IDE_CONTROL_REG
);
345 OUT_BYTE(rq
->nr_sectors
,IDE_NSECTOR_REG
);
346 #ifdef CONFIG_BLK_DEV_PDC4030
347 if (drive
->select
.b
.lba
|| IS_PDC4030_DRIVE
) {
348 #else /* !CONFIG_BLK_DEV_PDC4030 */
349 if (drive
->select
.b
.lba
) {
350 #endif /* CONFIG_BLK_DEV_PDC4030 */
352 printk("%s: %sing: LBAsect=%ld, sectors=%ld, buffer=0x%08lx\n",
353 drive
->name
, (rq
->cmd
==READ
)?"read":"writ",
354 block
, rq
->nr_sectors
, (unsigned long) rq
->buffer
);
356 OUT_BYTE(block
,IDE_SECTOR_REG
);
357 OUT_BYTE(block
>>=8,IDE_LCYL_REG
);
358 OUT_BYTE(block
>>=8,IDE_HCYL_REG
);
359 OUT_BYTE(((block
>>8)&0x0f)|drive
->select
.all
,IDE_SELECT_REG
);
361 unsigned int sect
,head
,cyl
,track
;
362 track
= block
/ drive
->sect
;
363 sect
= block
% drive
->sect
+ 1;
364 OUT_BYTE(sect
,IDE_SECTOR_REG
);
365 head
= track
% drive
->head
;
366 cyl
= track
/ drive
->head
;
367 OUT_BYTE(cyl
,IDE_LCYL_REG
);
368 OUT_BYTE(cyl
>>8,IDE_HCYL_REG
);
369 OUT_BYTE(head
|drive
->select
.all
,IDE_SELECT_REG
);
371 printk("%s: %sing: CHS=%d/%d/%d, sectors=%ld, buffer=0x%08lx\n",
372 drive
->name
, (rq
->cmd
==READ
)?"read":"writ", cyl
,
373 head
, sect
, rq
->nr_sectors
, (unsigned long) rq
->buffer
);
376 #ifdef CONFIG_BLK_DEV_PDC4030
377 if (IS_PDC4030_DRIVE
) {
378 extern void do_pdc4030_io(ide_drive_t
*, struct request
*);
379 do_pdc4030_io (drive
, rq
);
382 #endif /* CONFIG_BLK_DEV_PDC4030 */
383 if (rq
->cmd
== READ
) {
384 #ifdef CONFIG_BLK_DEV_IDEDMA
385 if (drive
->using_dma
&& !(HWIF(drive
)->dmaproc(ide_dma_read
, drive
)))
387 #endif /* CONFIG_BLK_DEV_IDEDMA */
388 ide_set_handler(drive
, &read_intr
);
389 OUT_BYTE(drive
->mult_count
? WIN_MULTREAD
: WIN_READ
, IDE_COMMAND_REG
);
392 if (rq
->cmd
== WRITE
) {
393 #ifdef CONFIG_BLK_DEV_IDEDMA
394 if (drive
->using_dma
&& !(HWIF(drive
)->dmaproc(ide_dma_write
, drive
)))
396 #endif /* CONFIG_BLK_DEV_IDEDMA */
397 OUT_BYTE(drive
->mult_count
? WIN_MULTWRITE
: WIN_WRITE
, IDE_COMMAND_REG
);
398 if (ide_wait_stat(drive
, DATA_READY
, drive
->bad_wstat
, WAIT_DRQ
)) {
399 printk(KERN_ERR
"%s: no DRQ after issuing %s\n", drive
->name
,
400 drive
->mult_count
? "MULTWRITE" : "WRITE");
404 __cli(); /* local CPU only */
405 if (drive
->mult_count
) {
406 HWGROUP(drive
)->wrq
= *rq
; /* scratchpad */
407 ide_set_handler (drive
, &multwrite_intr
);
408 ide_multwrite(drive
, drive
->mult_count
);
410 ide_set_handler (drive
, &write_intr
);
411 idedisk_output_data(drive
, rq
->buffer
, SECTOR_WORDS
);
415 printk(KERN_ERR
"%s: bad command: %d\n", drive
->name
, rq
->cmd
);
416 ide_end_request(0, HWGROUP(drive
));
419 static int idedisk_open (struct inode
*inode
, struct file
*filp
, ide_drive_t
*drive
)
422 if (drive
->removable
&& drive
->usage
== 1) {
423 check_disk_change(inode
->i_rdev
);
425 * Ignore the return code from door_lock,
426 * since the open() has already succeeded,
427 * and the door_lock is irrelevant at this point.
429 if (drive
->doorlocking
&& ide_wait_cmd(drive
, WIN_DOORLOCK
, 0, 0, 0, NULL
))
430 drive
->doorlocking
= 0;
435 static void idedisk_release (struct inode
*inode
, struct file
*filp
, ide_drive_t
*drive
)
437 if (drive
->removable
&& !drive
->usage
) {
438 invalidate_buffers(inode
->i_rdev
);
439 if (drive
->doorlocking
&& ide_wait_cmd(drive
, WIN_DOORUNLOCK
, 0, 0, 0, NULL
))
440 drive
->doorlocking
= 0;
445 static int idedisk_media_change (ide_drive_t
*drive
)
447 return drive
->removable
; /* if removable, always assume it was changed */
451 * Compute drive->capacity, the full capacity of the drive
452 * Called with drive->id != NULL.
454 static void init_idedisk_capacity (ide_drive_t
*drive
)
456 struct hd_driveid
*id
= drive
->id
;
457 unsigned long capacity
= drive
->cyl
* drive
->head
* drive
->sect
;
459 drive
->select
.b
.lba
= 0;
461 /* Determine capacity, and use LBA if the drive properly supports it */
462 if ((id
->capability
& 2) && lba_capacity_is_ok(id
)) {
463 capacity
= id
->lba_capacity
;
464 drive
->cyl
= capacity
/ (drive
->head
* drive
->sect
);
465 drive
->select
.b
.lba
= 1;
467 drive
->capacity
= capacity
;
470 static unsigned long idedisk_capacity (ide_drive_t
*drive
)
472 return (drive
->capacity
- drive
->sect0
);
475 static void idedisk_special (ide_drive_t
*drive
)
477 special_t
*s
= &drive
->special
;
479 if (s
->b
.set_geometry
) {
480 s
->b
.set_geometry
= 0;
481 OUT_BYTE(drive
->sect
,IDE_SECTOR_REG
);
482 OUT_BYTE(drive
->cyl
,IDE_LCYL_REG
);
483 OUT_BYTE(drive
->cyl
>>8,IDE_HCYL_REG
);
484 OUT_BYTE(((drive
->head
-1)|drive
->select
.all
)&0xBF,IDE_SELECT_REG
);
485 if (!IS_PDC4030_DRIVE
)
486 ide_cmd(drive
, WIN_SPECIFY
, drive
->sect
, &set_geometry_intr
);
487 } else if (s
->b
.recalibrate
) {
488 s
->b
.recalibrate
= 0;
489 if (!IS_PDC4030_DRIVE
)
490 ide_cmd(drive
, WIN_RESTORE
, drive
->sect
, &recal_intr
);
491 } else if (s
->b
.set_multmode
) {
492 s
->b
.set_multmode
= 0;
493 if (drive
->id
&& drive
->mult_req
> drive
->id
->max_multsect
)
494 drive
->mult_req
= drive
->id
->max_multsect
;
495 if (!IS_PDC4030_DRIVE
)
496 ide_cmd(drive
, WIN_SETMULT
, drive
->mult_req
, &set_multmode_intr
);
498 int special
= s
->all
;
500 printk(KERN_ERR
"%s: bad special flag: 0x%02x\n", drive
->name
, special
);
504 static void idedisk_pre_reset (ide_drive_t
*drive
)
506 drive
->special
.all
= 0;
507 drive
->special
.b
.set_geometry
= 1;
508 drive
->special
.b
.recalibrate
= 1;
509 drive
->timeout
= WAIT_CMD
;
510 if (OK_TO_RESET_CONTROLLER
)
511 drive
->mult_count
= 0;
512 if (!drive
->keep_settings
)
514 if (drive
->mult_req
!= drive
->mult_count
)
515 drive
->special
.b
.set_multmode
= 1;
518 #ifdef CONFIG_PROC_FS
520 static int smart_enable(ide_drive_t
*drive
)
522 return ide_wait_cmd(drive
, WIN_SMART
, 0, SMART_ENABLE
, 0, NULL
);
525 static int get_smart_values(ide_drive_t
*drive
, byte
*buf
)
527 (void) smart_enable(drive
);
528 return ide_wait_cmd(drive
, WIN_SMART
, 0, SMART_READ_VALUES
, 1, buf
);
531 static int get_smart_thresholds(ide_drive_t
*drive
, byte
*buf
)
533 (void) smart_enable(drive
);
534 return ide_wait_cmd(drive
, WIN_SMART
, 0, SMART_READ_THRESHOLDS
, 1, buf
);
537 static int proc_idedisk_read_cache
538 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
540 ide_drive_t
*drive
= (ide_drive_t
*) data
;
545 len
= sprintf(out
,"%i\n", drive
->id
->buf_size
/ 2);
547 len
= sprintf(out
,"(none)\n");
548 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
551 static int proc_idedisk_read_smart_thresholds
552 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
554 ide_drive_t
*drive
= (ide_drive_t
*)data
;
557 if (!get_smart_thresholds(drive
, page
)) {
558 unsigned short *val
= ((unsigned short *)page
) + 2;
559 char *out
= ((char *)val
) + (SECTOR_WORDS
* 4);
562 out
+= sprintf(out
, "%04x%c", le16_to_cpu(*val
), (++i
& 7) ? ' ' : '\n');
564 } while (i
< (SECTOR_WORDS
* 2));
567 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
570 static int proc_idedisk_read_smart_values
571 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
573 ide_drive_t
*drive
= (ide_drive_t
*)data
;
576 if (!get_smart_values(drive
, page
)) {
577 unsigned short *val
= ((unsigned short *)page
) + 2;
578 char *out
= ((char *)val
) + (SECTOR_WORDS
* 4);
581 out
+= sprintf(out
, "%04x%c", le16_to_cpu(*val
), (++i
& 7) ? ' ' : '\n');
583 } while (i
< (SECTOR_WORDS
* 2));
586 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
589 static ide_proc_entry_t idedisk_proc
[] = {
590 { "cache", S_IFREG
|S_IRUGO
, proc_idedisk_read_cache
, NULL
},
591 { "geometry", S_IFREG
|S_IRUGO
, proc_ide_read_geometry
, NULL
},
592 { "smart_values", S_IFREG
|S_IRUSR
, proc_idedisk_read_smart_values
, NULL
},
593 { "smart_thresholds", S_IFREG
|S_IRUSR
, proc_idedisk_read_smart_thresholds
, NULL
},
594 { NULL
, 0, NULL
, NULL
}
599 #define idedisk_proc NULL
601 #endif /* CONFIG_PROC_FS */
603 static int set_multcount(ide_drive_t
*drive
, int arg
)
607 if (drive
->special
.b
.set_multmode
)
609 ide_init_drive_cmd (&rq
);
610 drive
->mult_req
= arg
;
611 drive
->special
.b
.set_multmode
= 1;
612 (void) ide_do_drive_cmd (drive
, &rq
, ide_wait
);
613 return (drive
->mult_count
== arg
) ? 0 : -EIO
;
616 static int set_nowerr(ide_drive_t
*drive
, int arg
)
620 if (ide_spin_wait_hwgroup(drive
, &flags
))
623 drive
->bad_wstat
= arg
? BAD_R_STAT
: BAD_W_STAT
;
624 spin_unlock_irqrestore(&HWGROUP(drive
)->spinlock
, flags
);
628 static void idedisk_add_settings(ide_drive_t
*drive
)
630 struct hd_driveid
*id
= drive
->id
;
631 int major
= HWIF(drive
)->major
;
632 int minor
= drive
->select
.b
.unit
<< PARTN_BITS
;
634 ide_add_setting(drive
, "bios_cyl", SETTING_RW
, -1, -1, TYPE_INT
, 0, 65535, 1, 1, &drive
->bios_cyl
, NULL
);
635 ide_add_setting(drive
, "bios_head", SETTING_RW
, -1, -1, TYPE_BYTE
, 0, 255, 1, 1, &drive
->bios_head
, NULL
);
636 ide_add_setting(drive
, "bios_sect", SETTING_RW
, -1, -1, TYPE_BYTE
, 0, 63, 1, 1, &drive
->bios_sect
, NULL
);
637 ide_add_setting(drive
, "bswap", SETTING_READ
, -1, -1, TYPE_BYTE
, 0, 1, 1, 1, &drive
->bswap
, NULL
);
638 ide_add_setting(drive
, "multcount", id
? SETTING_RW
: SETTING_READ
, HDIO_GET_MULTCOUNT
, HDIO_SET_MULTCOUNT
, TYPE_BYTE
, 0, id
? id
->max_multsect
: 0, 1, 2, &drive
->mult_count
, set_multcount
);
639 ide_add_setting(drive
, "nowerr", SETTING_RW
, HDIO_GET_NOWERR
, HDIO_SET_NOWERR
, TYPE_BYTE
, 0, 1, 1, 1, &drive
->nowerr
, set_nowerr
);
640 ide_add_setting(drive
, "breada_readahead", SETTING_RW
, BLKRAGET
, BLKRASET
, TYPE_INT
, 0, 255, 1, 2, &read_ahead
[major
], NULL
);
641 ide_add_setting(drive
, "file_readahead", SETTING_RW
, BLKFRAGET
, BLKFRASET
, TYPE_INTA
, 0, INT_MAX
, 1, 1024, &max_readahead
[major
][minor
], NULL
);
642 ide_add_setting(drive
, "max_kb_per_request", SETTING_RW
, BLKSECTGET
, BLKSECTSET
, TYPE_INTA
, 1, 255, 1, 2, &max_sectors
[major
][minor
], NULL
);
647 * IDE subdriver functions, registered with ide.c
649 static ide_driver_t idedisk_driver
= {
650 "ide-disk", /* name */
651 IDEDISK_VERSION
, /* version */
652 ide_disk
, /* media */
654 1, /* supports_dma */
655 0, /* supports_dsc_overlap */
657 do_rw_disk
, /* do_request */
658 NULL
, /* end_request */
660 idedisk_open
, /* open */
661 idedisk_release
, /* release */
662 idedisk_media_change
, /* media_change */
663 idedisk_pre_reset
, /* pre_reset */
664 idedisk_capacity
, /* capacity */
665 idedisk_special
, /* special */
666 idedisk_proc
/* proc */
669 int idedisk_init (void);
670 static ide_module_t idedisk_module
= {
677 static int idedisk_cleanup (ide_drive_t
*drive
)
679 return ide_unregister_subdriver(drive
);
682 static void idedisk_setup (ide_drive_t
*drive
)
684 struct hd_driveid
*id
= drive
->id
;
685 unsigned long capacity
;
687 idedisk_add_settings(drive
);
693 * CompactFlash cards and their brethern look just like hard drives
694 * to us, but they are removable and don't have a doorlock mechanism.
696 if (drive
->removable
&& !drive_is_flashcard(drive
)) {
698 * Removable disks (eg. SYQUEST); ignore 'WD' drives
700 if (id
->model
[0] != 'W' || id
->model
[1] != 'D') {
701 drive
->doorlocking
= 1;
705 /* Extract geometry if we did not already have one for the drive */
706 if (!drive
->cyl
|| !drive
->head
|| !drive
->sect
) {
707 drive
->cyl
= drive
->bios_cyl
= id
->cyls
;
708 drive
->head
= drive
->bios_head
= id
->heads
;
709 drive
->sect
= drive
->bios_sect
= id
->sectors
;
712 /* Handle logical geometry translation by the drive */
713 if ((id
->field_valid
& 1) && id
->cur_cyls
&&
714 id
->cur_heads
&& (id
->cur_heads
<= 16) && id
->cur_sectors
) {
715 drive
->cyl
= id
->cur_cyls
;
716 drive
->head
= id
->cur_heads
;
717 drive
->sect
= id
->cur_sectors
;
720 /* Use physical geometry if what we have still makes no sense */
721 if (drive
->head
> 16 && id
->heads
&& id
->heads
<= 16) {
722 drive
->cyl
= id
->cyls
;
723 drive
->head
= id
->heads
;
724 drive
->sect
= id
->sectors
;
727 /* calculate drive capacity, and select LBA if possible */
728 init_idedisk_capacity (drive
);
731 * if possible, give fdisk access to more of the drive,
732 * by correcting bios_cyls:
734 capacity
= idedisk_capacity (drive
);
735 if ((capacity
>= (drive
->bios_cyl
* drive
->bios_sect
* drive
->bios_head
)) &&
736 (!drive
->forced_geom
) && drive
->bios_sect
&& drive
->bios_head
)
737 drive
->bios_cyl
= (capacity
/ drive
->bios_sect
) / drive
->bios_head
;
739 #if 0 /* done instead for entire identify block in arch/ide.h stuff */
740 /* fix byte-ordering of buffer size field */
741 id
->buf_size
= le16_to_cpu(id
->buf_size
);
743 printk (KERN_INFO
"%s: %.40s, %ldMB w/%dkB Cache, CHS=%d/%d/%d",
744 drive
->name
, id
->model
,
745 capacity
/2048L, id
->buf_size
/2,
746 drive
->bios_cyl
, drive
->bios_head
, drive
->bios_sect
);
748 if (drive
->using_dma
) {
749 if ((id
->field_valid
& 4) && (id
->word93
& 0x2000) &&
750 (HWIF(drive
)->udma_four
) &&
751 (id
->dma_ultra
& (id
->dma_ultra
>> 11) & 3)) {
752 printk(", UDMA(66)"); /* UDMA BIOS-enabled! */
753 } else if ((id
->field_valid
& 4) &&
754 (id
->dma_ultra
& (id
->dma_ultra
>> 8) & 7)) {
755 printk(", UDMA(33)"); /* UDMA BIOS-enabled! */
756 } else if (id
->field_valid
& 4) {
757 printk(", (U)DMA"); /* Can be BIOS-enabled! */
764 drive
->mult_count
= 0;
765 if (id
->max_multsect
) {
766 #ifdef CONFIG_IDEDISK_MULTI_MODE
767 id
->multsect
= ((id
->max_multsect
/2) > 1) ? id
->max_multsect
: 0;
768 id
->multsect_valid
= id
->multsect
? 1 : 0;
769 drive
->mult_req
= id
->multsect_valid
? id
->max_multsect
: INITIAL_MULT_COUNT
;
770 drive
->special
.b
.set_multmode
= drive
->mult_req
? 1 : 0;
771 #else /* original, pre IDE-NFG, per request of AC */
772 drive
->mult_req
= INITIAL_MULT_COUNT
;
773 if (drive
->mult_req
> id
->max_multsect
)
774 drive
->mult_req
= id
->max_multsect
;
775 if (drive
->mult_req
|| ((id
->multsect_valid
& 1) && id
->multsect
))
776 drive
->special
.b
.set_multmode
= 1;
779 drive
->no_io_32bit
= id
->dword_io
? 1 : 0;
782 int idedisk_init (void)
788 while ((drive
= ide_scan_devices (ide_disk
, idedisk_driver
.name
, NULL
, failed
++)) != NULL
) {
789 if (ide_register_subdriver (drive
, &idedisk_driver
, IDE_SUBDRIVER_VERSION
)) {
790 printk (KERN_ERR
"ide-disk: %s: Failed to register the driver with ide.c\n", drive
->name
);
793 idedisk_setup(drive
);
794 if ((!drive
->head
|| drive
->head
> 16) && !drive
->select
.b
.lba
) {
795 printk(KERN_ERR
"%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n", drive
->name
, drive
->head
);
796 (void) idedisk_cleanup(drive
);
801 ide_register_module(&idedisk_module
);
807 int init_module (void)
809 return idedisk_init();
812 void cleanup_module (void)
817 while ((drive
= ide_scan_devices (ide_disk
, idedisk_driver
.name
, &idedisk_driver
, failed
)) != NULL
) {
818 if (idedisk_cleanup (drive
)) {
819 printk (KERN_ERR
"%s: cleanup_module() called while still busy\n", drive
->name
);
822 /* We must remove proc entries defined in this module.
823 Otherwise we oops while accessing these entries */
825 ide_remove_proc_entries(drive
->proc
, idedisk_proc
);
827 ide_unregister_module(&idedisk_module
);