4 * linux/include/linux/ide.h
6 * Copyright (C) 1994-2002 Linus Torvalds & authors
9 #include <linux/config.h>
10 #include <linux/init.h>
11 #include <linux/ioport.h>
12 #include <linux/hdreg.h>
13 #include <linux/hdsmart.h>
14 #include <linux/blkdev.h>
15 #include <linux/proc_fs.h>
16 #include <linux/interrupt.h>
17 #include <linux/bitops.h>
18 #include <linux/bio.h>
19 #include <linux/device.h>
20 #include <linux/pci.h>
21 #include <asm/byteorder.h>
22 #include <asm/system.h>
23 #include <asm/hdreg.h>
25 #include <asm/semaphore.h>
30 * This is the multiple IDE interface driver, as evolved from hd.c.
31 * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
32 * There can be up to two drives per interface, as per the ATA-2 spec.
34 * Primary i/f: ide0: major=3; (hda) minor=0; (hdb) minor=64
35 * Secondary i/f: ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
36 * Tertiary i/f: ide2: major=33; (hde) minor=0; (hdf) minor=64
37 * Quaternary i/f: ide3: major=34; (hdg) minor=0; (hdh) minor=64
40 /******************************************************************************
41 * IDE driver configuration options (play with these as desired):
43 * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
45 #define REALLY_FAST_IO /* define if ide ports are perfect */
46 #define INITIAL_MULT_COUNT 0 /* off=0; on=2,4,8,16,32, etc.. */
48 #ifndef SUPPORT_SLOW_DATA_PORTS /* 1 to support slow data ports */
49 #define SUPPORT_SLOW_DATA_PORTS 1 /* 0 to reduce kernel size */
51 #ifndef SUPPORT_VLB_SYNC /* 1 to support weird 32-bit chips */
52 #define SUPPORT_VLB_SYNC 1 /* 0 to reduce kernel size */
54 #ifndef DISK_RECOVERY_TIME /* off=0; on=access_delay_time */
55 #define DISK_RECOVERY_TIME 0 /* for hardware that needs it */
57 #ifndef OK_TO_RESET_CONTROLLER /* 1 needed for good error recovery */
58 #define OK_TO_RESET_CONTROLLER 1 /* 0 for use with AH2372A/B interface */
60 #ifndef FANCY_STATUS_DUMPS /* 1 for human-readable drive errors */
61 #define FANCY_STATUS_DUMPS 1 /* 0 to reduce kernel size */
64 #ifdef CONFIG_BLK_DEV_CMD640
65 #if 0 /* change to 1 when debugging cmd640 problems */
66 void cmd640_dump_regs (void);
67 #define CMD640_DUMP_REGS cmd640_dump_regs() /* for debugging cmd640 chipset */
69 #endif /* CONFIG_BLK_DEV_CMD640 */
71 #ifndef DISABLE_IRQ_NOSYNC
72 #define DISABLE_IRQ_NOSYNC 0
76 * Used to indicate "no IRQ", should be a value that cannot be an IRQ
80 #define IDE_NO_IRQ (-1)
83 * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
85 #define IDE_DRIVE_CMD 99 /* (magic) undef to reduce kernel size*/
87 #define IDE_DRIVE_TASK 98
90 * IDE_DRIVE_TASKFILE is used to implement many features needed for raw tasks
92 #define IDE_DRIVE_TASKFILE 97
95 * "No user-serviceable parts" beyond this point :)
96 *****************************************************************************/
98 typedef unsigned char byte; /* used everywhere */
101 * Probably not wise to fiddle with these
103 #define ERROR_MAX 8 /* Max read/write errors per sector */
104 #define ERROR_RESET 3 /* Reset controller every 4th retry */
105 #define ERROR_RECAL 1 /* Recalibrate every 2nd retry */
110 #define IDE_TUNE_NOAUTO 2
111 #define IDE_TUNE_AUTO 1
112 #define IDE_TUNE_DEFAULT 0
118 #define DMA_PIO_RETRY 1 /* retrying in PIO */
121 * Ensure that various configuration flags have compatible settings
123 #ifdef REALLY_SLOW_IO
124 #undef REALLY_FAST_IO
127 #define HWIF(drive) ((ide_hwif_t *)((drive)->hwif))
128 #define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
131 * Definitions for accessing IDE controller registers
133 #define IDE_NR_PORTS (10)
135 #define IDE_DATA_OFFSET (0)
136 #define IDE_ERROR_OFFSET (1)
137 #define IDE_NSECTOR_OFFSET (2)
138 #define IDE_SECTOR_OFFSET (3)
139 #define IDE_LCYL_OFFSET (4)
140 #define IDE_HCYL_OFFSET (5)
141 #define IDE_SELECT_OFFSET (6)
142 #define IDE_STATUS_OFFSET (7)
143 #define IDE_CONTROL_OFFSET (8)
144 #define IDE_IRQ_OFFSET (9)
146 #define IDE_FEATURE_OFFSET IDE_ERROR_OFFSET
147 #define IDE_COMMAND_OFFSET IDE_STATUS_OFFSET
149 #define IDE_DATA_OFFSET_HOB (0)
150 #define IDE_ERROR_OFFSET_HOB (1)
151 #define IDE_NSECTOR_OFFSET_HOB (2)
152 #define IDE_SECTOR_OFFSET_HOB (3)
153 #define IDE_LCYL_OFFSET_HOB (4)
154 #define IDE_HCYL_OFFSET_HOB (5)
155 #define IDE_SELECT_OFFSET_HOB (6)
156 #define IDE_CONTROL_OFFSET_HOB (7)
158 #define IDE_FEATURE_OFFSET_HOB IDE_ERROR_OFFSET_HOB
160 #define IDE_DATA_REG (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
161 #define IDE_ERROR_REG (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
162 #define IDE_NSECTOR_REG (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
163 #define IDE_SECTOR_REG (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
164 #define IDE_LCYL_REG (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
165 #define IDE_HCYL_REG (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
166 #define IDE_SELECT_REG (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
167 #define IDE_STATUS_REG (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
168 #define IDE_CONTROL_REG (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
169 #define IDE_IRQ_REG (HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
171 #define IDE_DATA_REG_HOB (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
172 #define IDE_ERROR_REG_HOB (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
173 #define IDE_NSECTOR_REG_HOB (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
174 #define IDE_SECTOR_REG_HOB (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
175 #define IDE_LCYL_REG_HOB (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
176 #define IDE_HCYL_REG_HOB (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
177 #define IDE_SELECT_REG_HOB (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
178 #define IDE_STATUS_REG_HOB (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
179 #define IDE_CONTROL_REG_HOB (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
181 #define IDE_FEATURE_REG IDE_ERROR_REG
182 #define IDE_COMMAND_REG IDE_STATUS_REG
183 #define IDE_ALTSTATUS_REG IDE_CONTROL_REG
184 #define IDE_IREASON_REG IDE_NSECTOR_REG
185 #define IDE_BCOUNTL_REG IDE_LCYL_REG
186 #define IDE_BCOUNTH_REG IDE_HCYL_REG
188 #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
189 #define BAD_R_STAT (BUSY_STAT | ERR_STAT)
190 #define BAD_W_STAT (BAD_R_STAT | WRERR_STAT)
191 #define BAD_STAT (BAD_R_STAT | DRQ_STAT)
192 #define DRIVE_READY (READY_STAT | SEEK_STAT)
193 #define DATA_READY (DRQ_STAT)
195 #define BAD_CRC (ABRT_ERR | ICRC_ERR)
197 #define SATA_NR_PORTS (3) /* 16 possible ?? */
199 #define SATA_STATUS_OFFSET (0)
200 #define SATA_STATUS_REG (HWIF(drive)->sata_scr[SATA_STATUS_OFFSET])
201 #define SATA_ERROR_OFFSET (1)
202 #define SATA_ERROR_REG (HWIF(drive)->sata_scr[SATA_ERROR_OFFSET])
203 #define SATA_CONTROL_OFFSET (2)
204 #define SATA_CONTROL_REG (HWIF(drive)->sata_scr[SATA_CONTROL_OFFSET])
206 #define SATA_MISC_OFFSET (0)
207 #define SATA_MISC_REG (HWIF(drive)->sata_misc[SATA_MISC_OFFSET])
208 #define SATA_PHY_OFFSET (1)
209 #define SATA_PHY_REG (HWIF(drive)->sata_misc[SATA_PHY_OFFSET])
210 #define SATA_IEN_OFFSET (2)
211 #define SATA_IEN_REG (HWIF(drive)->sata_misc[SATA_IEN_OFFSET])
214 * Our Physical Region Descriptor (PRD) table should be large enough
215 * to handle the biggest I/O request we are likely to see. Since requests
216 * can have no more than 256 sectors, and since the typical blocksize is
217 * two or more sectors, we could get by with a limit of 128 entries here for
218 * the usual worst case. Most requests seem to include some contiguous blocks,
219 * further reducing the number of table entries required.
221 * The driver reverts to PIO mode for individual requests that exceed
222 * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling
223 * 100% of all crazy scenarios here is not necessary.
225 * As it turns out though, we must allocate a full 4KB page for this,
226 * so the two PRD tables (ide0 & ide1) will each get half of that,
227 * allowing each to have about 256 entries (8 bytes each) from this.
230 #define PRD_ENTRIES (PAGE_SIZE / (2 * PRD_BYTES))
233 * Some more useful definitions
235 #define IDE_MAJOR_NAME "hd" /* the same for all i/f; see also genhd.c */
236 #define MAJOR_NAME IDE_MAJOR_NAME
237 #define PARTN_BITS 6 /* number of minor dev bits for partitions */
238 #define PARTN_MASK ((1<<PARTN_BITS)-1) /* a useful bit mask */
239 #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
240 #define SECTOR_SIZE 512
241 #define SECTOR_WORDS (SECTOR_SIZE / 4) /* number of 32bit words per sector */
242 #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
243 #define IDE_MIN(a,b) ((a)<(b) ? (a):(b))
244 #define IDE_MAX(a,b) ((a)>(b) ? (a):(b))
247 * Timeouts for various operations:
249 #define WAIT_DRQ (5*HZ/100) /* 50msec - spec allows up to 20ms */
250 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
251 #define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */
253 #define WAIT_READY (3*HZ/100) /* 30msec - should be instantaneous */
254 #endif /* CONFIG_APM || CONFIG_APM_MODULE */
255 #define WAIT_PIDENTIFY (10*HZ) /* 10sec - should be less than 3ms (?), if all ATAPI CD is closed at boot */
256 #define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */
257 #define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */
258 #define WAIT_MIN_SLEEP (2*HZ/100) /* 20msec - minimum sleep time */
260 #define HOST(hwif,chipset) \
262 return ((hwif)->chipset == chipset) ? 1 : 0; \
266 * Check for an interrupt and acknowledge the interrupt status
269 typedef int (ide_ack_intr_t)(struct hwif_s *);
276 * hwif_chipset_t is used to keep track of the specific hardware
277 * chipset used by each IDE interface, if known.
279 typedef enum { ide_unknown, ide_generic, ide_pci,
280 ide_cmd640, ide_dtc2278, ide_ali14xx,
281 ide_qd65xx, ide_umc8672, ide_ht6560b,
282 ide_pdc4030, ide_rz1000, ide_trm290,
283 ide_cmd646, ide_cy82c693, ide_4drives,
284 ide_pmac, ide_etrax100, ide_acorn,
289 * Structure to hold all information about the location of this port
291 typedef struct hw_regs_s {
292 unsigned long io_ports[IDE_NR_PORTS]; /* task file registers */
293 int irq; /* our irq number */
294 int dma; /* our dma entry */
295 ide_ack_intr_t *ack_intr; /* acknowledge interrupt */
296 void *priv; /* interface specific data */
297 hwif_chipset_t chipset;
298 unsigned long sata_scr[SATA_NR_PORTS];
299 unsigned long sata_misc[SATA_NR_PORTS];
303 * Register new hardware with ide
305 int ide_register_hw(hw_regs_t *hw, struct hwif_s **hwifp);
308 * Set up hw_regs_t structure before calling ide_register_hw (optional)
310 void ide_setup_ports( hw_regs_t *hw,
315 ide_ack_intr_t *ack_intr,
323 /* Currently only m68k, apus and m8xx need it */
324 #ifndef IDE_ARCH_ACK_INTR
325 # define ide_ack_intr(hwif) (1)
328 /* Currently only Atari needs it */
329 #ifndef IDE_ARCH_LOCK
330 # define ide_release_lock() do {} while (0)
331 # define ide_get_lock(hdlr, data) do {} while (0)
332 #endif /* IDE_ARCH_LOCK */
335 * Now for the data we need to maintain per-drive: ide_drive_t
338 #define ide_scsi 0x21
339 #define ide_disk 0x20
340 #define ide_optical 0x7
341 #define ide_cdrom 0x5
343 #define ide_floppy 0x0
346 * Special Driver Flags
348 * set_geometry : respecify drive geometry
349 * recalibrate : seek to cyl 0
350 * set_multmode : set multmode count
351 * set_tune : tune interface for drive
352 * serviced : service command
358 #if defined(__LITTLE_ENDIAN_BITFIELD)
359 unsigned set_geometry : 1;
360 unsigned recalibrate : 1;
361 unsigned set_multmode : 1;
362 unsigned set_tune : 1;
363 unsigned serviced : 1;
364 unsigned reserved : 3;
365 #elif defined(__BIG_ENDIAN_BITFIELD)
366 unsigned reserved : 3;
367 unsigned serviced : 1;
368 unsigned set_tune : 1;
369 unsigned set_multmode : 1;
370 unsigned recalibrate : 1;
371 unsigned set_geometry : 1;
373 #error "Please fix <asm/byteorder.h>"
379 * ATA DATA Register Special.
380 * ATA NSECTOR Count Register().
381 * ATAPI Byte Count Register.
382 * Channel index ordering pairs.
387 #if defined(__LITTLE_ENDIAN_BITFIELD)
388 unsigned low :8; /* LSB */
389 unsigned high :8; /* MSB */
390 #elif defined(__BIG_ENDIAN_BITFIELD)
391 unsigned high :8; /* MSB */
392 unsigned low :8; /* LSB */
394 #error "Please fix <asm/byteorder.h>"
397 } ata_nsector_t, ata_data_t, atapi_bcount_t, ata_index_t;
400 * ATA-IDE Error Register
402 * mark : Bad address mark
403 * tzero : Couldn't find track 0
404 * abrt : Aborted Command
405 * mcr : Media Change Request
406 * id : ID field not found
407 * mce : Media Change Event
408 * ecc : Uncorrectable ECC error
414 #if defined(__LITTLE_ENDIAN_BITFIELD)
423 #elif defined(__BIG_ENDIAN_BITFIELD)
433 #error "Please fix <asm/byteorder.h>"
439 * ATA-IDE Select Register, aka Device-Head
441 * head : always zeros here
442 * unit : drive select number: 0/1
444 * lba : using LBA instead of CHS
450 #if defined(__LITTLE_ENDIAN_BITFIELD)
456 #elif defined(__BIG_ENDIAN_BITFIELD)
463 #error "Please fix <asm/byteorder.h>"
466 } select_t, ata_select_t;
469 * The ATA-IDE Status Register.
470 * The ATAPI Status Register.
472 * check : Error occurred
474 * corr : Correctable error occurred
475 * drq : Data is request by the device
476 * dsc : Disk Seek Complete : ata
477 * : Media access command finished : atapi
478 * df : Device Fault : ata
480 * drdy : Ready, Command Mode Capable : ata
481 * : Ignored for ATAPI commands : atapi
483 * : The device has access to the command block
488 #if defined(__LITTLE_ENDIAN_BITFIELD)
497 #elif defined(__BIG_ENDIAN_BITFIELD)
507 #error "Please fix <asm/byteorder.h>"
510 } ata_status_t, atapi_status_t;
513 * ATA-IDE Control Register
515 * bit0 : Should be set to zero
516 * nIEN : device INTRQ to host
517 * SRST : host soft reset bit
518 * bit3 : ATA-2 thingy, Should be set to 1
519 * reserved456 : Reserved
520 * HOB : 48-bit address ordering, High Ordered Bit
525 #if defined(__LITTLE_ENDIAN_BITFIELD)
530 unsigned reserved456 : 3;
532 #elif defined(__BIG_ENDIAN_BITFIELD)
534 unsigned reserved456 : 3;
540 #error "Please fix <asm/byteorder.h>"
546 * ATAPI Feature Register
548 * dma : Using DMA or PIO
549 * reserved321 : Reserved
550 * reserved654 : Reserved (Tag Type)
551 * reserved7 : Reserved
556 #if defined(__LITTLE_ENDIAN_BITFIELD)
558 unsigned reserved321 :3;
559 unsigned reserved654 :3;
560 unsigned reserved7 :1;
561 #elif defined(__BIG_ENDIAN_BITFIELD)
562 unsigned reserved7 :1;
563 unsigned reserved654 :3;
564 unsigned reserved321 :3;
567 #error "Please fix <asm/byteorder.h>"
573 * ATAPI Interrupt Reason Register.
575 * cod : Information transferred is command (1) or data (0)
576 * io : The device requests us to read (1) or write (0)
577 * reserved : Reserved
582 #if defined(__LITTLE_ENDIAN_BITFIELD)
585 unsigned reserved :6;
586 #elif defined(__BIG_ENDIAN_BITFIELD)
587 unsigned reserved :6;
591 #error "Please fix <asm/byteorder.h>"
597 * The ATAPI error register.
599 * ili : Illegal Length Indication
600 * eom : End Of Media Detected
601 * abrt : Aborted command - As defined by ATA
602 * mcr : Media Change Requested - As defined by ATA
603 * sense_key : Sense key of the last failed packet command
608 #if defined(__LITTLE_ENDIAN_BITFIELD)
613 unsigned sense_key :4;
614 #elif defined(__BIG_ENDIAN_BITFIELD)
615 unsigned sense_key :4;
621 #error "Please fix <asm/byteorder.h>"
627 * ATAPI floppy Drive Select Register
629 * sam_lun : Logical unit number
630 * reserved3 : Reserved
631 * drv : The responding drive will be drive 0 (0) or drive 1 (1)
632 * one5 : Should be set to 1
633 * reserved6 : Reserved
634 * one7 : Should be set to 1
639 #if defined(__LITTLE_ENDIAN_BITFIELD)
641 unsigned reserved3 :1;
644 unsigned reserved6 :1;
646 #elif defined(__BIG_ENDIAN_BITFIELD)
648 unsigned reserved6 :1;
651 unsigned reserved3 :1;
654 #error "Please fix <asm/byteorder.h>"
660 * Status returned from various ide_ functions
663 ide_stopped, /* no drive operation was started */
664 ide_started, /* a drive operation was started, handler was set */
665 ide_released, /* as ide_started, but bus also released */
669 struct ide_settings_s;
671 typedef struct ide_drive_s {
672 char name[4]; /* drive name, such as "hda" */
673 char driver_req[10]; /* requests specific driver */
675 request_queue_t *queue; /* request queue */
677 struct request *rq; /* current request */
678 struct ide_drive_s *next; /* circular list of hwgroup drives */
679 struct ide_driver_s *driver;/* (ide_driver_t *) */
680 void *driver_data; /* extra driver data */
681 struct hd_driveid *id; /* drive model identification info */
682 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
683 struct ide_settings_s *settings;/* /proc/ide/ drive settings */
684 char devfs_name[64]; /* devfs crap */
686 struct hwif_s *hwif; /* actually (ide_hwif_t *) */
688 unsigned long sleep; /* sleep until this time */
689 unsigned long service_start; /* time we started last request */
690 unsigned long service_time; /* service time of last request */
691 unsigned long timeout; /* max time to wait for irq */
693 special_t special; /* special action flags */
694 select_t select; /* basic drive/head select reg value */
696 u8 keep_settings; /* restore settings after drive reset */
697 u8 autodma; /* device can safely use dma on host */
698 u8 using_dma; /* disk is using dma for read/write */
699 u8 using_tcq; /* disk is using queueing */
700 u8 retry_pio; /* retrying dma capable host in pio */
701 u8 state; /* retry state */
702 u8 waiting_for_dma; /* dma currently in progress */
703 u8 unmask; /* okay to unmask other irqs */
704 u8 slow; /* slow data port */
705 u8 bswap; /* byte swap data */
706 u8 dsc_overlap; /* DSC overlap */
707 u8 nice1; /* give potential excess bandwidth */
709 unsigned present : 1; /* drive is physically present */
710 unsigned dead : 1; /* device ejected hint */
711 unsigned id_read : 1; /* 1=id read from disk 0 = synthetic */
712 unsigned noprobe : 1; /* from: hdx=noprobe */
713 unsigned removable : 1; /* 1 if need to do check_media_change */
714 unsigned attach : 1; /* needed for removable devices */
715 unsigned is_flash : 1; /* 1 if probed as flash */
716 unsigned forced_geom : 1; /* 1 if hdx=c,h,s was given at boot */
717 unsigned no_unmask : 1; /* disallow setting unmask bit */
718 unsigned no_io_32bit : 1; /* disallow enabling 32bit I/O */
719 unsigned nobios : 1; /* do not probe bios for drive */
720 unsigned atapi_overlap : 1; /* ATAPI overlap (not supported) */
721 unsigned nice0 : 1; /* give obvious excess bandwidth */
722 unsigned nice2 : 1; /* give a share in our own bandwidth */
723 unsigned doorlocking : 1; /* for removable only: door lock/unlock works */
724 unsigned autotune : 2; /* 0=default, 1=autotune, 2=noautotune */
725 unsigned remap_0_to_1 : 1; /* 0=noremap, 1=remap 0->1 (for EZDrive) */
726 unsigned ata_flash : 1; /* 1=present, 0=default */
727 unsigned blocked : 1; /* 1=powermanagment told us not to do anything, so sleep nicely */
728 unsigned vdma : 1; /* 1=doing PIO over DMA 0=doing normal DMA */
729 unsigned addressing; /* : 3;
732 * 2=48-bit doing 28-bit
736 u8 scsi; /* 0=default, 1=skip current ide-subdriver for ide-scsi emulation */
737 u8 quirk_list; /* considered quirky, set for a specific host */
738 u8 suspend_reset; /* drive suspend mode flag, soft-reset recovers */
739 u8 init_speed; /* transfer rate set at boot */
740 u8 pio_speed; /* unused by core, used by some drivers for fallback from DMA */
741 u8 current_speed; /* current transfer rate set */
742 u8 dn; /* now wide spread use */
743 u8 wcache; /* status of write cache */
744 u8 acoustic; /* acoustic management */
745 u8 media; /* disk, cdrom, tape, floppy, ... */
746 u8 ctl; /* "normal" value for IDE_CONTROL_REG */
747 u8 ready_stat; /* min status value for drive ready */
748 u8 mult_count; /* current multiple sector setting */
749 u8 mult_req; /* requested multiple sector setting */
750 u8 tune_req; /* requested drive tuning setting */
751 u8 io_32bit; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
752 u8 bad_wstat; /* used for ignoring WRERR_STAT */
753 u8 nowerr; /* used for ignoring WRERR_STAT */
754 u8 sect0; /* offset of first sector for DM6:DDO */
755 u8 head; /* "real" number of heads */
756 u8 sect; /* "real" sectors per track */
757 u8 bios_head; /* BIOS/fdisk/LILO number of heads */
758 u8 bios_sect; /* BIOS/fdisk/LILO sectors per track */
759 u8 queue_depth; /* max queue depth */
761 unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */
762 unsigned int cyl; /* "real" number of cyls */
763 unsigned int drive_data; /* use by tuneproc/selectproc */
764 unsigned int usage; /* current "open()" count for drive */
765 unsigned int failures; /* current failure count */
766 unsigned int max_failures; /* maximum allowed failure count */
768 u64 capacity64; /* total number of sectors */
770 int last_lun; /* last logical unit */
771 int forced_lun; /* if hdxlun was given at boot */
772 int lun; /* logical unit */
773 int crc_count; /* crc counter to reduce drive speed */
774 struct list_head list;
775 struct device gendev;
776 struct semaphore gendev_rel_sem; /* to deal with device release() */
777 struct gendisk *disk;
780 typedef struct ide_pio_ops_s {
781 void (*ata_input_data)(ide_drive_t *, void *, u32);
782 void (*ata_output_data)(ide_drive_t *, void *, u32);
784 void (*atapi_input_bytes)(ide_drive_t *, void *, u32);
785 void (*atapi_output_bytes)(ide_drive_t *, void *, u32);
788 typedef struct ide_dma_ops_s {
789 /* insert dma operations here! */
790 int (*ide_dma_read)(ide_drive_t *drive);
791 int (*ide_dma_write)(ide_drive_t *drive);
792 int (*ide_dma_begin)(ide_drive_t *drive);
793 int (*ide_dma_end)(ide_drive_t *drive);
794 int (*ide_dma_check)(ide_drive_t *drive);
795 int (*ide_dma_on)(ide_drive_t *drive);
796 int (*ide_dma_off)(ide_drive_t *drive);
797 int (*ide_dma_off_quietly)(ide_drive_t *drive);
798 int (*ide_dma_test_irq)(ide_drive_t *drive);
799 int (*ide_dma_host_on)(ide_drive_t *drive);
800 int (*ide_dma_host_off)(ide_drive_t *drive);
801 int (*ide_dma_bad_drive)(ide_drive_t *drive);
802 int (*ide_dma_good_drive)(ide_drive_t *drive);
803 int (*ide_dma_count)(ide_drive_t *drive);
804 int (*ide_dma_verbose)(ide_drive_t *drive);
805 int (*ide_dma_retune)(ide_drive_t *drive);
806 int (*ide_dma_lostirq)(ide_drive_t *drive);
807 int (*ide_dma_timeout)(ide_drive_t *drive);
808 /* dma queued operations */
809 int (*ide_dma_queued_on)(ide_drive_t *drive);
810 int (*ide_dma_queued_off)(ide_drive_t *drive);
811 ide_startstop_t (*ide_dma_queued_read)(ide_drive_t *drive);
812 ide_startstop_t (*ide_dma_queued_write)(ide_drive_t *drive);
813 ide_startstop_t (*ide_dma_queued_start)(ide_drive_t *drive);
817 * mapping stuff, prepare for highmem...
819 * temporarily mapping a (possible) highmem bio for PIO transfer
821 #ifndef CONFIG_IDE_TASKFILE_IO
823 #define ide_rq_offset(rq) \
824 (((rq)->hard_cur_sectors - (rq)->current_nr_sectors) << 9)
827 * taskfiles really should use hard_cur_sectors as well!
829 #define task_rq_offset(rq) \
830 (((rq)->nr_sectors - (rq)->current_nr_sectors) * SECTOR_SIZE)
832 static inline void *ide_map_buffer(struct request *rq, unsigned long *flags)
838 return bio_kmap_irq(rq->bio, flags) + ide_rq_offset(rq);
843 return rq->buffer + task_rq_offset(rq);
846 static inline void ide_unmap_buffer(struct request *rq, char *buffer, unsigned long *flags)
849 bio_kunmap_irq(buffer, flags);
851 #endif /* !CONFIG_IDE_TASKFILE_IO */
853 #define IDE_CHIPSET_PCI_MASK \
854 ((1<<ide_pci)|(1<<ide_cmd646)|(1<<ide_ali14xx))
855 #define IDE_CHIPSET_IS_PCI(c) ((IDE_CHIPSET_PCI_MASK >> (c)) & 1)
857 struct ide_pci_device_s;
859 typedef struct hwif_s {
860 struct hwif_s *next; /* for linked-list in ide_hwgroup_t */
861 struct hwif_s *mate; /* other hwif from same PCI chip */
862 struct hwgroup_s *hwgroup; /* actually (ide_hwgroup_t *) */
863 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
865 char name[6]; /* name of interface, eg. "ide0" */
867 /* task file registers for pata and sata */
868 unsigned long io_ports[IDE_NR_PORTS];
869 unsigned long sata_scr[SATA_NR_PORTS];
870 unsigned long sata_misc[SATA_NR_PORTS];
872 hw_regs_t hw; /* Hardware info */
873 ide_drive_t drives[MAX_DRIVES]; /* drive info */
875 u8 major; /* our major number */
876 u8 index; /* 0 for ide0; 1 for ide1; ... */
877 u8 channel; /* for dual-port chips: 0=primary, 1=secondary */
878 u8 straight8; /* Alan's straight 8 check */
879 u8 bus_state; /* power state of the IDE bus */
881 u8 atapi_dma; /* host supports atapi_dma */
886 hwif_chipset_t chipset; /* sub-module for tuning.. */
888 struct pci_dev *pci_dev; /* for pci chipsets */
889 struct ide_pci_device_s *cds; /* chipset device struct */
891 struct pnp_dev *pnp_dev; /* for PnP devices */
893 ide_startstop_t (*rw_disk)(ide_drive_t *, struct request *, sector_t);
896 ide_hwif_ops_t *hwifops;
898 /* routine is for HBA specific IDENTITY operations */
899 int (*identify)(ide_drive_t *);
900 /* routine to tune PIO mode for drives */
901 void (*tuneproc)(ide_drive_t *, u8);
902 /* routine to retune DMA modes for drives */
903 int (*speedproc)(ide_drive_t *, u8);
904 /* tweaks hardware to select drive */
905 void (*selectproc)(ide_drive_t *);
906 /* chipset polling based on hba specifics */
907 int (*reset_poll)(ide_drive_t *);
908 /* chipset specific changes to default for device-hba resets */
909 void (*pre_reset)(ide_drive_t *);
910 /* routine to reset controller after a disk reset */
911 void (*resetproc)(ide_drive_t *);
912 /* special interrupt handling for shared pci interrupts */
913 void (*intrproc)(ide_drive_t *);
914 /* special host masking for drive selection */
915 void (*maskproc)(ide_drive_t *, int);
916 /* check host's drive quirk list */
917 int (*quirkproc)(ide_drive_t *);
918 /* driver soft-power interface */
919 int (*busproc)(ide_drive_t *, int);
920 // /* host rate limiter */
921 // u8 (*ratemask)(ide_drive_t *);
922 // /* device rate limiter */
923 // u8 (*ratefilter)(ide_drive_t *, u8);
927 ide_pio_ops_t *pioops;
929 void (*ata_input_data)(ide_drive_t *, void *, u32);
930 void (*ata_output_data)(ide_drive_t *, void *, u32);
932 void (*atapi_input_bytes)(ide_drive_t *, void *, u32);
933 void (*atapi_output_bytes)(ide_drive_t *, void *, u32);
936 int (*ide_dma_read)(ide_drive_t *drive);
937 int (*ide_dma_write)(ide_drive_t *drive);
938 int (*ide_dma_begin)(ide_drive_t *drive);
939 int (*ide_dma_end)(ide_drive_t *drive);
940 int (*ide_dma_check)(ide_drive_t *drive);
941 int (*ide_dma_on)(ide_drive_t *drive);
942 int (*ide_dma_off)(ide_drive_t *drive);
943 int (*ide_dma_off_quietly)(ide_drive_t *drive);
944 int (*ide_dma_test_irq)(ide_drive_t *drive);
945 int (*ide_dma_host_on)(ide_drive_t *drive);
946 int (*ide_dma_host_off)(ide_drive_t *drive);
947 int (*ide_dma_bad_drive)(ide_drive_t *drive);
948 int (*ide_dma_good_drive)(ide_drive_t *drive);
949 int (*ide_dma_count)(ide_drive_t *drive);
950 int (*ide_dma_verbose)(ide_drive_t *drive);
951 int (*ide_dma_retune)(ide_drive_t *drive);
952 int (*ide_dma_lostirq)(ide_drive_t *drive);
953 int (*ide_dma_timeout)(ide_drive_t *drive);
955 /* dma queued operations */
956 int (*ide_dma_queued_on)(ide_drive_t *drive);
957 int (*ide_dma_queued_off)(ide_drive_t *drive);
958 ide_startstop_t (*ide_dma_queued_read)(ide_drive_t *drive);
959 ide_startstop_t (*ide_dma_queued_write)(ide_drive_t *drive);
960 ide_startstop_t (*ide_dma_queued_start)(ide_drive_t *drive);
962 void (*OUTB)(u8 addr, unsigned long port);
963 void (*OUTBSYNC)(ide_drive_t *drive, u8 addr, unsigned long port);
964 void (*OUTW)(u16 addr, unsigned long port);
965 void (*OUTL)(u32 addr, unsigned long port);
966 void (*OUTSW)(unsigned long port, void *addr, u32 count);
967 void (*OUTSL)(unsigned long port, void *addr, u32 count);
969 u8 (*INB)(unsigned long port);
970 u16 (*INW)(unsigned long port);
971 u32 (*INL)(unsigned long port);
972 void (*INSW)(unsigned long port, void *addr, u32 count);
973 void (*INSL)(unsigned long port, void *addr, u32 count);
975 /* dma physical region descriptor table (cpu view) */
976 unsigned int *dmatable_cpu;
977 /* dma physical region descriptor table (dma view) */
978 dma_addr_t dmatable_dma;
979 /* Scatter-gather list used to build the above */
980 struct scatterlist *sg_table;
981 int sg_nents; /* Current number of entries in it */
982 int sg_dma_direction; /* dma transfer direction */
983 int sg_dma_active; /* is it in use */
985 int mmio; /* hosts iomio (0), mmio (1) or custom (2) select */
986 int rqsize; /* max sectors per request */
987 int irq; /* our irq number */
988 int initializing; /* set while initializing self */
990 unsigned long dma_master; /* reference base addr dmabase */
991 unsigned long dma_base; /* base addr for dma ports */
992 unsigned long dma_command; /* dma command register */
993 unsigned long dma_vendor1; /* dma vendor 1 register */
994 unsigned long dma_status; /* dma status register */
995 unsigned long dma_vendor3; /* dma vendor 3 register */
996 unsigned long dma_prdtable; /* actual prd table address */
997 unsigned long dma_base2; /* extended base addr for dma ports */
999 unsigned dma_extra; /* extra addr for dma ports */
1000 unsigned long config_data; /* for use by chipset-specific code */
1001 unsigned long select_data; /* for use by chipset-specific code */
1002 #if (DISK_RECOVERY_TIME > 0)
1003 unsigned long last_time; /* time when previous rq was done */
1007 unsigned noprobe : 1; /* don't probe for this interface */
1008 unsigned present : 1; /* this interface exists */
1009 unsigned hold : 1; /* this interface is always present */
1010 unsigned serialized : 1; /* serialized all channel operation */
1011 unsigned sharing_irq: 1; /* 1 = sharing irq with another hwif */
1012 unsigned reset : 1; /* reset after probe */
1013 unsigned autodma : 1; /* auto-attempt using DMA at boot */
1014 unsigned udma_four : 1; /* 1=ATA-66 capable, 0=default */
1015 unsigned no_lba48 : 1; /* 1 = cannot do LBA48 */
1016 unsigned no_dsc : 1; /* 0 default, 1 dsc_overlap disabled */
1017 unsigned auto_poll : 1; /* supports nop auto-poll */
1019 struct device gendev;
1020 struct semaphore gendev_rel_sem; /* To deal with device release() */
1022 void *hwif_data; /* extra hwif data */
1026 void (*led_act)(void *data, int rw);
1030 * internal ide interrupt handler type
1032 typedef ide_startstop_t (ide_pre_handler_t)(ide_drive_t *, struct request *);
1033 typedef ide_startstop_t (ide_handler_t)(ide_drive_t *);
1034 typedef ide_startstop_t (ide_post_handler_t)(ide_drive_t *);
1035 typedef int (ide_expiry_t)(ide_drive_t *);
1037 typedef struct hwgroup_s {
1038 /* irq handler, if active */
1039 ide_startstop_t (*handler)(ide_drive_t *);
1040 /* irq handler, suspended if active */
1041 ide_startstop_t (*handler_save)(ide_drive_t *);
1042 /* BOOL: protects all fields below */
1044 /* BOOL: wake us up on timer expiry */
1048 /* ptr to current hwif in linked-list */
1051 /* for pci chipsets */
1052 struct pci_dev *pci_dev;
1053 /* chipset device struct */
1054 struct ide_pci_device_s *cds;
1056 /* current request */
1058 /* failsafe timer */
1059 struct timer_list timer;
1060 /* local copy of current write rq */
1062 /* timeout value during long polls */
1063 unsigned long poll_timeout;
1064 /* queried upon timeouts */
1065 int (*expiry)(ide_drive_t *);
1066 /* ide_system_bus_speed */
1069 unsigned char cmd_buf[4];
1072 /* structure attached to the request for IDE_TASK_CMDS */
1075 * configurable drive settings
1081 #define TYPE_SHORT 3
1083 #define SETTING_READ (1 << 0)
1084 #define SETTING_WRITE (1 << 1)
1085 #define SETTING_RW (SETTING_READ | SETTING_WRITE)
1087 typedef int (ide_procset_t)(ide_drive_t *, int);
1088 typedef struct ide_settings_s {
1101 struct ide_settings_s *next;
1104 extern struct semaphore ide_setting_sem;
1105 extern int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set);
1106 extern void ide_remove_setting(ide_drive_t *drive, char *name);
1107 extern ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name);
1108 extern int ide_read_setting(ide_drive_t *t, ide_settings_t *setting);
1109 extern int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val);
1110 extern void ide_add_generic_settings(ide_drive_t *drive);
1113 * /proc/ide interface
1118 read_proc_t *read_proc;
1119 write_proc_t *write_proc;
1122 #ifdef CONFIG_PROC_FS
1123 extern void proc_ide_create(void);
1124 extern void proc_ide_destroy(void);
1125 extern void destroy_proc_ide_device(ide_hwif_t *, ide_drive_t *);
1126 extern void destroy_proc_ide_drives(ide_hwif_t *);
1127 extern void create_proc_ide_interfaces(void);
1128 extern void ide_add_proc_entries(struct proc_dir_entry *, ide_proc_entry_t *, void *);
1129 extern void ide_remove_proc_entries(struct proc_dir_entry *, ide_proc_entry_t *);
1130 read_proc_t proc_ide_read_capacity;
1131 read_proc_t proc_ide_read_geometry;
1134 * Standard exit stuff:
1136 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
1139 if (len < count) { \
1145 *start = page + off; \
1149 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
1153 * Power Management step value (rq->pm->pm_step).
1155 * The step value starts at 0 (ide_pm_state_start_suspend) for a
1156 * suspend operation or 1000 (ide_pm_state_start_resume) for a
1159 * For each step, the core calls the subdriver start_power_step() first.
1161 * - ide_stopped : In this case, the core calls us back again unless
1162 * step have been set to ide_power_state_completed.
1163 * - ide_started : In this case, the channel is left busy until an
1164 * async event (interrupt) occurs.
1165 * Typically, start_power_step() will issue a taskfile request with
1168 * Upon reception of the interrupt, the core will call complete_power_step()
1169 * with the error code if any. This routine should update the step value
1170 * and return. It should not start a new request. The core will call
1171 * start_power_step for the new step value, unless step have been set to
1172 * ide_power_state_completed.
1174 * Subdrivers are expected to define their own additional power
1175 * steps from 1..999 for suspend and from 1001..1999 for resume,
1176 * other values are reserved for future use.
1180 ide_pm_state_completed = -1,
1181 ide_pm_state_start_suspend = 0,
1182 ide_pm_state_start_resume = 1000,
1186 * Subdrivers support.
1188 #define IDE_SUBDRIVER_VERSION 1
1190 typedef struct ide_driver_s {
1191 struct module *owner;
1193 const char *version;
1196 unsigned supports_dsc_overlap : 1;
1197 int (*cleanup)(ide_drive_t *);
1198 int (*shutdown)(ide_drive_t *);
1199 int (*flushcache)(ide_drive_t *);
1200 ide_startstop_t (*do_request)(ide_drive_t *, struct request *, sector_t);
1201 int (*end_request)(ide_drive_t *, int, int);
1202 u8 (*sense)(ide_drive_t *, const char *, u8);
1203 ide_startstop_t (*error)(ide_drive_t *, const char *, u8);
1204 ide_startstop_t (*abort)(ide_drive_t *, const char *);
1205 int (*ioctl)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
1206 void (*pre_reset)(ide_drive_t *);
1207 sector_t (*capacity)(ide_drive_t *);
1208 ide_startstop_t (*special)(ide_drive_t *);
1209 ide_proc_entry_t *proc;
1210 int (*attach)(ide_drive_t *);
1211 void (*ata_prebuilder)(ide_drive_t *);
1212 void (*atapi_prebuilder)(ide_drive_t *);
1213 ide_startstop_t (*start_power_step)(ide_drive_t *, struct request *);
1214 void (*complete_power_step)(ide_drive_t *, struct request *, u8, u8);
1215 struct device_driver gen_driver;
1216 struct list_head drives;
1217 struct list_head drivers;
1220 #define DRIVER(drive) ((drive)->driver)
1222 extern int generic_ide_ioctl(struct block_device *, unsigned, unsigned long);
1224 typedef struct ide_devices_s {
1225 char name[4]; /* hdX */
1226 unsigned attached : 1; /* native */
1227 unsigned alttached : 1; /* alternate */
1228 struct ide_devices_s *next;
1232 * ide_hwifs[] is the master data structure used to keep track
1233 * of just about everything in ide.c. Whenever possible, routines
1234 * should be using pointers to a drive (ide_drive_t *) or
1235 * pointers to a hwif (ide_hwif_t *), rather than indexing this
1236 * structure directly (the allocation/layout may change!).
1240 extern ide_hwif_t ide_hwifs[]; /* master data repository */
1241 extern int (*ide_probe)(void);
1243 extern ide_devices_t *idedisk;
1244 extern ide_devices_t *idecd;
1245 extern ide_devices_t *idefloppy;
1246 extern ide_devices_t *idetape;
1247 extern ide_devices_t *idescsi;
1250 extern int noautodma;
1252 extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs);
1255 * This is used on exit from the driver to designate the next irq handler
1256 * and also to start the safety timer.
1258 extern void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry);
1261 * This is used on exit from the driver to designate the next irq handler
1262 * and start the safety time safely and atomically from the IRQ handler
1263 * with respect to the command issue (which it also does)
1265 extern void ide_execute_command(ide_drive_t *, task_ioreg_t cmd, ide_handler_t *, unsigned int, ide_expiry_t *);
1268 * Error reporting, in human readable form (luxurious, but a memory hog).
1270 * (drive, msg, status)
1272 byte ide_dump_status (ide_drive_t *drive, const char *msg, byte stat);
1275 * ide_error() takes action based on the error returned by the controller.
1276 * The caller should return immediately after invoking this.
1278 * (drive, msg, status)
1280 ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, byte stat);
1283 * Abort a running command on the controller triggering the abort
1284 * from a host side, non error situation
1287 extern ide_startstop_t ide_abort(ide_drive_t *, const char *);
1290 * Issue a simple drive command
1291 * The drive must be selected beforehand.
1293 * (drive, command, nsector, handler)
1295 extern void ide_cmd(ide_drive_t *, u8, u8, ide_handler_t *);
1297 extern void ide_fix_driveid(struct hd_driveid *);
1299 * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
1300 * removing leading/trailing blanks and compressing internal blanks.
1301 * It is primarily used to tidy up the model name/number fields as
1302 * returned by the WIN_[P]IDENTIFY commands.
1304 * (s, bytecount, byteswap)
1306 extern void ide_fixstring(u8 *, const int, const int);
1309 * This routine busy-waits for the drive status to be not "busy".
1310 * It then checks the status for all of the "good" bits and none
1311 * of the "bad" bits, and if all is okay it returns 0. All other
1312 * cases return 1 after doing "*startstop = ide_error()", and the
1313 * caller should return the updated value of "startstop" in this case.
1314 * "startstop" is unchanged when the function returns 0;
1315 * (startstop, drive, good, bad, timeout)
1317 extern int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long);
1320 * Return the current idea about the total capacity of this drive.
1322 extern sector_t current_capacity (ide_drive_t *drive);
1325 * Start a reset operation for an IDE interface.
1326 * The caller should return immediately after invoking this.
1328 extern ide_startstop_t ide_do_reset (ide_drive_t *);
1331 * This function is intended to be used prior to invoking ide_do_drive_cmd().
1333 extern void ide_init_drive_cmd (struct request *rq);
1336 * "action" parameter type for ide_do_drive_cmd() below.
1339 ide_wait, /* insert rq at end of list, and wait for it */
1340 ide_next, /* insert rq immediately after current request */
1341 ide_preempt, /* insert rq in front of current request */
1342 ide_head_wait, /* insert rq in front of current request and wait for it */
1343 ide_end /* insert rq at end of list, but don't wait for it */
1347 * This function issues a special IDE device request
1348 * onto the request queue.
1350 * If action is ide_wait, then the rq is queued at the end of the
1351 * request queue, and the function sleeps until it has been processed.
1352 * This is for use when invoked from an ioctl handler.
1354 * If action is ide_preempt, then the rq is queued at the head of
1355 * the request queue, displacing the currently-being-processed
1356 * request and this function returns immediately without waiting
1357 * for the new rq to be completed. This is VERY DANGEROUS, and is
1358 * intended for careful use by the ATAPI tape/cdrom driver code.
1360 * If action is ide_next, then the rq is queued immediately after
1361 * the currently-being-processed-request (if any), and the function
1362 * returns without waiting for the new rq to be completed. As above,
1363 * This is VERY DANGEROUS, and is intended for careful use by the
1364 * ATAPI tape/cdrom driver code.
1366 * If action is ide_end, then the rq is queued at the end of the
1367 * request queue, and the function returns immediately without waiting
1368 * for the new rq to be completed. This is again intended for careful
1369 * use by the ATAPI tape/cdrom driver code.
1371 extern int ide_do_drive_cmd(ide_drive_t *, struct request *, ide_action_t);
1374 * Clean up after success/failure of an explicit drive cmd.
1375 * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
1376 * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_TASK_MASK).
1378 * (ide_drive_t *drive, u8 stat, u8 err)
1380 extern void ide_end_drive_cmd(ide_drive_t *, u8, u8);
1383 * Issue ATA command and wait for completion.
1384 * Use for implementing commands in kernel
1386 * (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf)
1388 extern int ide_wait_cmd(ide_drive_t *, u8, u8, u8, u8, u8 *);
1390 /* (ide_drive_t *drive, u8 *buf) */
1391 extern int ide_wait_cmd_task(ide_drive_t *, u8 *);
1393 typedef struct ide_task_s {
1395 * struct hd_drive_task_hdr tf;
1397 * struct hd_drive_hob_hdr hobf;
1398 * hob_struct_t hobf;
1400 task_ioreg_t tfRegister[8];
1401 task_ioreg_t hobRegister[8];
1402 ide_reg_valid_t tf_out_flags;
1403 ide_reg_valid_t tf_in_flags;
1406 ide_pre_handler_t *prehandler;
1407 ide_handler_t *handler;
1408 ide_post_handler_t *posthandler;
1409 struct request *rq; /* copy of request */
1410 void *special; /* valid_t generally */
1413 typedef struct pkt_task_s {
1415 * struct hd_drive_task_hdr pktf;
1416 * task_struct_t pktf;
1419 task_ioreg_t tfRegister[8];
1422 ide_handler_t *handler;
1423 struct request *rq; /* copy of request */
1427 extern inline u32 ide_read_24(ide_drive_t *);
1429 extern inline void SELECT_DRIVE(ide_drive_t *);
1430 extern inline void SELECT_INTERRUPT(ide_drive_t *);
1431 extern inline void SELECT_MASK(ide_drive_t *, int);
1432 extern inline void QUIRK_LIST(ide_drive_t *);
1434 extern void ata_input_data(ide_drive_t *, void *, u32);
1435 extern void ata_output_data(ide_drive_t *, void *, u32);
1436 extern void atapi_input_bytes(ide_drive_t *, void *, u32);
1437 extern void atapi_output_bytes(ide_drive_t *, void *, u32);
1438 extern void taskfile_input_data(ide_drive_t *, void *, u32);
1439 extern void taskfile_output_data(ide_drive_t *, void *, u32);
1441 #ifdef CONFIG_IDE_TASKFILE_IO
1443 #define IDE_PIO_IN 0
1444 #define IDE_PIO_OUT 1
1446 static inline void task_sectors(ide_drive_t *drive, struct request *rq,
1447 unsigned nsect, int rw)
1449 unsigned long flags;
1450 unsigned int bio_rq;
1454 * bio_rq flag is needed because we can call
1455 * rq_unmap_buffer() with rq->cbio == NULL
1457 bio_rq = rq->cbio ? 1 : 0;
1460 buf = rq_map_buffer(rq, &flags); /* fs request */
1462 buf = rq->buffer + blk_rq_offset(rq); /* task request */
1465 * IRQ can happen instantly after reading/writing
1466 * last sector of the datablock.
1468 process_that_request_first(rq, nsect);
1470 if (rw == IDE_PIO_OUT)
1471 taskfile_output_data(drive, buf, nsect * SECTOR_WORDS);
1473 taskfile_input_data(drive, buf, nsect * SECTOR_WORDS);
1476 rq_unmap_buffer(buf, &flags);
1478 #endif /* CONFIG_IDE_TASKFILE_IO */
1480 extern int drive_is_ready(ide_drive_t *);
1481 extern int wait_for_ready(ide_drive_t *, int /* timeout */);
1484 * taskfile io for disks for now...and builds request from ide_ioctl
1486 extern ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *);
1488 /* (ide_drive_t *drive, u8 stat, u8 err) */
1489 extern void ide_end_taskfile(ide_drive_t *, u8, u8);
1492 * Special Flagged Register Validation Caller
1494 extern ide_startstop_t flagged_taskfile(ide_drive_t *, ide_task_t *);
1496 extern ide_startstop_t set_multmode_intr(ide_drive_t *);
1497 extern ide_startstop_t set_geometry_intr(ide_drive_t *);
1498 extern ide_startstop_t recal_intr(ide_drive_t *);
1499 extern ide_startstop_t task_no_data_intr(ide_drive_t *);
1500 extern ide_startstop_t task_in_intr(ide_drive_t *);
1501 extern ide_startstop_t task_mulin_intr(ide_drive_t *);
1502 extern ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
1503 extern ide_startstop_t task_out_intr(ide_drive_t *);
1504 extern ide_startstop_t pre_task_mulout_intr(ide_drive_t *, struct request *);
1505 extern ide_startstop_t task_mulout_intr(ide_drive_t *);
1506 extern void ide_init_drive_taskfile(struct request *);
1508 extern int ide_raw_taskfile(ide_drive_t *, ide_task_t *, u8 *);
1510 extern ide_pre_handler_t * ide_pre_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1512 extern ide_handler_t * ide_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1514 extern ide_post_handler_t * ide_post_handler_parser(struct hd_drive_task_hdr *, struct hd_drive_hob_hdr *);
1516 /* Expects args is a full set of TF registers and parses the command type */
1517 extern int ide_cmd_type_parser(ide_task_t *);
1519 int ide_taskfile_ioctl(ide_drive_t *, unsigned int, unsigned long);
1520 int ide_cmd_ioctl(ide_drive_t *, unsigned int, unsigned long);
1521 int ide_task_ioctl(ide_drive_t *, unsigned int, unsigned long);
1525 #define IDEFLOPPY_PC_BUFFER_SIZE 256
1526 #define IDETAPE_PC_BUFFER_SIZE 256
1527 #define IDE_PC_BUFFER_SIZE 256
1529 typedef struct ide_packet_command_s {
1530 /* Actual packet bytes */
1532 /* On each retry, we increment retries */
1536 /* Bytes to transfer */
1537 int request_transfer;
1538 /* Bytes actually transferred */
1539 int actually_transferred;
1540 /* Size of our data buffer */
1543 struct buffer_head *bh;
1545 /* The corresponding request */
1548 /* Scatter gather table */
1549 struct scatterlist *sg;
1554 /* Pointer into the above buffer */
1555 u8 *current_position;
1556 /* Called when this packet command is completed */
1557 ide_startstop_t (*callback) (ide_drive_t *);
1558 /* Temporary buffer */
1559 u8 pc_buffer[IDE_PC_BUFFER_SIZE];
1560 /* Status/Action bit flags: long for set_bit */
1561 unsigned long flags;
1564 ide-cd orthoginal :-/
1565 struct packet_command {
1571 struct request_sense *sense;
1572 unsigned char c[12];
1577 #ifdef CONFIG_PKT_TASK_IOCTL
1578 extern int pkt_taskfile_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
1579 #endif /* CONFIG_PKT_TASK_IOCTL */
1581 extern void ide_delay_50ms(void);
1582 extern int system_bus_clock(void);
1584 extern u8 ide_auto_reduce_xfer(ide_drive_t *);
1585 extern int ide_driveid_update(ide_drive_t *);
1586 extern int ide_ata66_check(ide_drive_t *, ide_task_t *);
1587 extern int ide_config_drive_speed(ide_drive_t *, u8);
1588 extern u8 eighty_ninty_three (ide_drive_t *);
1589 extern int set_transfer(ide_drive_t *, ide_task_t *);
1590 extern int taskfile_lib_get_identify(ide_drive_t *drive, u8 *);
1592 extern int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout);
1593 ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq, sector_t block);
1596 * ide_system_bus_speed() returns what we think is the system VESA/PCI
1597 * bus speed (in MHz). This is used for calculating interface PIO timings.
1598 * The default is 40 for known PCI systems, 50 otherwise.
1599 * The "idebus=xx" parameter can be used to override this value.
1601 extern int ide_system_bus_speed(void);
1604 * ide_stall_queue() can be used by a drive to give excess bandwidth back
1605 * to the hwgroup by sleeping for timeout jiffies.
1607 extern void ide_stall_queue(ide_drive_t *drive, unsigned long timeout);
1609 extern int ide_spin_wait_hwgroup(ide_drive_t *);
1610 extern void ide_timer_expiry(unsigned long);
1611 extern irqreturn_t ide_intr(int irq, void *dev_id, struct pt_regs *regs);
1612 extern void do_ide_request(request_queue_t *);
1613 extern void ide_init_subdrivers(void);
1615 extern struct block_device_operations ide_fops[];
1616 extern ide_proc_entry_t generic_subdriver_entries[];
1618 extern int ata_attach(ide_drive_t *);
1620 extern int ideprobe_init(void);
1622 extern void ide_scan_pcibus(int scan_direction) __init;
1623 extern int ide_pci_register_driver(struct pci_driver *driver);
1624 extern void ide_pci_unregister_driver(struct pci_driver *driver);
1625 extern void ide_pci_setup_ports(struct pci_dev *dev, struct ide_pci_device_s *d, int autodma, int pciirq, ata_index_t *index);
1626 extern void ide_setup_pci_noise (struct pci_dev *dev, struct ide_pci_device_s *d);
1628 extern void default_hwif_iops(ide_hwif_t *);
1629 extern void default_hwif_mmiops(ide_hwif_t *);
1630 extern void default_hwif_transport(ide_hwif_t *);
1632 int ide_register_driver(ide_driver_t *driver);
1633 void ide_unregister_driver(ide_driver_t *driver);
1634 int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version);
1635 int ide_unregister_subdriver (ide_drive_t *drive);
1636 int ide_replace_subdriver(ide_drive_t *drive, const char *driver);
1638 #ifdef CONFIG_PROC_FS
1639 typedef struct ide_pci_host_proc_s {
1642 get_info_t *get_info;
1643 struct proc_dir_entry *parent;
1644 struct ide_pci_host_proc_s *next;
1645 } ide_pci_host_proc_t;
1647 void ide_pci_register_host_proc(ide_pci_host_proc_t *);
1648 #endif /* CONFIG_PROC_FS */
1651 #define NEVER_BOARD 0
1653 #ifdef CONFIG_BLK_DEV_OFFBOARD
1654 # define OFF_BOARD ON_BOARD
1655 #else /* CONFIG_BLK_DEV_OFFBOARD */
1656 # define OFF_BOARD NEVER_BOARD
1657 #endif /* CONFIG_BLK_DEV_OFFBOARD */
1664 typedef struct ide_pci_enablebit_s {
1665 u8 reg; /* byte pci reg holding the enable-bit */
1666 u8 mask; /* mask to isolate the enable-bit */
1667 u8 val; /* value of masked reg when "enabled" */
1668 } ide_pci_enablebit_t;
1670 typedef struct ide_pci_device_s {
1674 void (*init_setup)(struct pci_dev *, struct ide_pci_device_s *);
1675 void (*init_setup_dma)(struct pci_dev *, struct ide_pci_device_s *, ide_hwif_t *);
1676 unsigned int (*init_chipset)(struct pci_dev *, const char *);
1677 void (*init_iops)(ide_hwif_t *);
1678 void (*init_hwif)(ide_hwif_t *);
1679 void (*init_dma)(ide_hwif_t *, unsigned long);
1682 ide_pci_enablebit_t enablebits[2];
1685 struct ide_pci_device_s *next;
1686 u8 isa_ports; /* Uses ISA control ports not PCI ones */
1689 extern void ide_setup_pci_device(struct pci_dev *, ide_pci_device_t *);
1690 extern void ide_setup_pci_devices(struct pci_dev *, struct pci_dev *, ide_pci_device_t *);
1692 #define BAD_DMA_DRIVE 0
1693 #define GOOD_DMA_DRIVE 1
1695 #ifdef CONFIG_BLK_DEV_IDEDMA_PCI
1696 extern int ide_build_dmatable(ide_drive_t *, struct request *);
1697 extern void ide_destroy_dmatable(ide_drive_t *);
1698 extern ide_startstop_t ide_dma_intr(ide_drive_t *);
1699 extern int ide_release_dma(ide_hwif_t *);
1700 extern void ide_setup_dma(ide_hwif_t *, unsigned long, unsigned int);
1701 extern int ide_start_dma(ide_hwif_t *, ide_drive_t *, int);
1703 extern int __ide_dma_host_off(ide_drive_t *);
1704 extern int __ide_dma_off_quietly(ide_drive_t *);
1705 extern int __ide_dma_off(ide_drive_t *);
1706 extern int __ide_dma_host_on(ide_drive_t *);
1707 extern int __ide_dma_on(ide_drive_t *);
1708 extern int __ide_dma_check(ide_drive_t *);
1709 extern int __ide_dma_read(ide_drive_t *);
1710 extern int __ide_dma_write(ide_drive_t *);
1711 extern int __ide_dma_begin(ide_drive_t *);
1712 extern int __ide_dma_end(ide_drive_t *);
1713 extern int __ide_dma_test_irq(ide_drive_t *);
1714 extern int __ide_dma_bad_drive(ide_drive_t *);
1715 extern int __ide_dma_good_drive(ide_drive_t *);
1716 extern int __ide_dma_count(ide_drive_t *);
1717 extern int __ide_dma_verbose(ide_drive_t *);
1718 extern int __ide_dma_retune(ide_drive_t *);
1719 extern int __ide_dma_lostirq(ide_drive_t *);
1720 extern int __ide_dma_timeout(ide_drive_t *);
1722 #ifdef CONFIG_BLK_DEV_IDE_TCQ
1723 extern int __ide_dma_queued_on(ide_drive_t *drive);
1724 extern int __ide_dma_queued_off(ide_drive_t *drive);
1725 extern ide_startstop_t __ide_dma_queued_read(ide_drive_t *drive);
1726 extern ide_startstop_t __ide_dma_queued_write(ide_drive_t *drive);
1727 extern ide_startstop_t __ide_dma_queued_start(ide_drive_t *drive);
1729 static inline int __ide_dma_queued_on(ide_drive_t *drive)
1734 static inline int __ide_dma_queued_off(ide_drive_t *drive)
1741 static inline void ide_release_dma(ide_hwif_t *drive) {;}
1744 extern int ide_hwif_request_regions(ide_hwif_t *hwif);
1745 extern void ide_hwif_release_regions(ide_hwif_t* hwif);
1746 extern void ide_unregister (unsigned int index);
1748 extern int probe_hwif_init(ide_hwif_t *);
1750 static inline void *ide_get_hwifdata (ide_hwif_t * hwif)
1752 return hwif->hwif_data;
1755 static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data)
1757 hwif->hwif_data = data;
1761 extern u8 ide_dma_speed(ide_drive_t *drive, u8 mode);
1762 extern u8 ide_rate_filter(u8 mode, u8 speed);
1763 extern int ide_dma_enable(ide_drive_t *drive);
1764 extern char *ide_xfer_verbose(u8 xfer_rate);
1765 extern void ide_toggle_bounce(ide_drive_t *drive, int on);
1766 extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate);
1768 typedef struct ide_pio_timings_s {
1769 int setup_time; /* Address setup (ns) minimum */
1770 int active_time; /* Active pulse (ns) minimum */
1771 int cycle_time; /* Cycle time (ns) minimum = (setup + active + recovery) */
1772 } ide_pio_timings_t;
1774 typedef struct ide_pio_data_s {
1779 unsigned int cycle_time;
1782 extern u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d);
1783 extern const ide_pio_timings_t ide_pio_timings[6];
1786 extern spinlock_t ide_lock;
1787 extern struct semaphore ide_cfg_sem;
1789 * Structure locking:
1791 * ide_cfg_sem and ide_lock together protect changes to
1792 * ide_hwif_t->{next,hwgroup}
1795 * ide_hwgroup_t->busy: ide_lock
1796 * ide_hwgroup_t->hwif: ide_lock
1797 * ide_hwif_t->mate: constant, no locking
1798 * ide_drive_t->hwif: constant, no locking
1801 #define local_irq_set(flags) do { local_save_flags((flags)); local_irq_enable(); } while (0)
1803 #define IDE_MAX_TAG 32
1804 #ifdef CONFIG_BLK_DEV_IDE_TCQ
1805 static inline int ata_pending_commands(ide_drive_t *drive)
1807 if (drive->using_tcq)
1808 return blk_queue_tag_depth(drive->queue);
1813 static inline int ata_can_queue(ide_drive_t *drive)
1815 if (drive->using_tcq)
1816 return blk_queue_tag_queue(drive->queue);
1821 #define ata_pending_commands(drive) (0)
1822 #define ata_can_queue(drive) (1)
1825 extern struct bus_type ide_bus_type;