File: /usr/src/linux/include/linux/ide.h

1     #ifndef _IDE_H
2     #define _IDE_H
3     /*
4      *  linux/include/linux/ide.h
5      *
6      *  Copyright (C) 1994-1998  Linus Torvalds & authors
7      */
8     
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/devfs_fs_kernel.h>
17     #include <asm/hdreg.h>
18     
19     /*
20      * This is the multiple IDE interface driver, as evolved from hd.c.
21      * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
22      * There can be up to two drives per interface, as per the ATA-2 spec.
23      *
24      * Primary i/f:    ide0: major=3;  (hda)         minor=0; (hdb)         minor=64
25      * Secondary i/f:  ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
26      * Tertiary i/f:   ide2: major=33; (hde)         minor=0; (hdf)         minor=64
27      * Quaternary i/f: ide3: major=34; (hdg)         minor=0; (hdh)         minor=64
28      */
29     
30     /******************************************************************************
31      * IDE driver configuration options (play with these as desired):
32      *
33      * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
34      */
35     #undef REALLY_FAST_IO			/* define if ide ports are perfect */
36     #define INITIAL_MULT_COUNT	0	/* off=0; on=2,4,8,16,32, etc.. */
37     
38     #ifndef SUPPORT_SLOW_DATA_PORTS		/* 1 to support slow data ports */
39     #define SUPPORT_SLOW_DATA_PORTS	1	/* 0 to reduce kernel size */
40     #endif
41     #ifndef SUPPORT_VLB_SYNC		/* 1 to support weird 32-bit chips */
42     #define SUPPORT_VLB_SYNC	1	/* 0 to reduce kernel size */
43     #endif
44     #ifndef DISK_RECOVERY_TIME		/* off=0; on=access_delay_time */
45     #define DISK_RECOVERY_TIME	0	/*  for hardware that needs it */
46     #endif
47     #ifndef OK_TO_RESET_CONTROLLER		/* 1 needed for good error recovery */
48     #define OK_TO_RESET_CONTROLLER	1	/* 0 for use with AH2372A/B interface */
49     #endif
50     #ifndef FANCY_STATUS_DUMPS		/* 1 for human-readable drive errors */
51     #define FANCY_STATUS_DUMPS	1	/* 0 to reduce kernel size */
52     #endif
53     
54     #ifdef CONFIG_BLK_DEV_CMD640
55     #if 0	/* change to 1 when debugging cmd640 problems */
56     void cmd640_dump_regs (void);
57     #define CMD640_DUMP_REGS cmd640_dump_regs() /* for debugging cmd640 chipset */
58     #endif
59     #endif  /* CONFIG_BLK_DEV_CMD640 */
60     
61     #ifndef DISABLE_IRQ_NOSYNC
62     #define DISABLE_IRQ_NOSYNC	0
63     #endif
64     
65     /*
66      * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
67      */
68     #define IDE_DRIVE_CMD		99	/* (magic) undef to reduce kernel size*/
69     
70     /*
71      * IDE_DRIVE_TASK is used to implement many features needed for raw tasks
72      */
73     #define IDE_DRIVE_TASK		98
74     #define IDE_DRIVE_CMD_AEB	98
75     
76     /*
77      *  "No user-serviceable parts" beyond this point  :)
78      *****************************************************************************/
79     
80     typedef unsigned char	byte;	/* used everywhere */
81     
82     /*
83      * Probably not wise to fiddle with these
84      */
85     #define ERROR_MAX	8	/* Max read/write errors per sector */
86     #define ERROR_RESET	3	/* Reset controller every 4th retry */
87     #define ERROR_RECAL	1	/* Recalibrate every 2nd retry */
88     
89     /*
90      * state flags
91      */
92     #define DMA_PIO_RETRY	1	/* retrying in PIO */
93     
94     /*
95      * Ensure that various configuration flags have compatible settings
96      */
97     #ifdef REALLY_SLOW_IO
98     #undef REALLY_FAST_IO
99     #endif
100     
101     #define HWIF(drive)		((ide_hwif_t *)((drive)->hwif))
102     #define HWGROUP(drive)		((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
103     
104     /*
105      * Definitions for accessing IDE controller registers
106      */
107     #define IDE_NR_PORTS		(10)
108     
109     #define IDE_DATA_OFFSET		(0)
110     #define IDE_ERROR_OFFSET	(1)
111     #define IDE_NSECTOR_OFFSET	(2)
112     #define IDE_SECTOR_OFFSET	(3)
113     #define IDE_LCYL_OFFSET		(4)
114     #define IDE_HCYL_OFFSET		(5)
115     #define IDE_SELECT_OFFSET	(6)
116     #define IDE_STATUS_OFFSET	(7)
117     #define IDE_CONTROL_OFFSET	(8)
118     #define IDE_IRQ_OFFSET		(9)
119     
120     #define IDE_FEATURE_OFFSET	IDE_ERROR_OFFSET
121     #define IDE_COMMAND_OFFSET	IDE_STATUS_OFFSET
122     
123     #define IDE_DATA_REG		(HWIF(drive)->io_ports[IDE_DATA_OFFSET])
124     #define IDE_ERROR_REG		(HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
125     #define IDE_NSECTOR_REG		(HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
126     #define IDE_SECTOR_REG		(HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
127     #define IDE_LCYL_REG		(HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
128     #define IDE_HCYL_REG		(HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
129     #define IDE_SELECT_REG		(HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
130     #define IDE_STATUS_REG		(HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
131     #define IDE_CONTROL_REG		(HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
132     #define IDE_IRQ_REG		(HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
133     
134     #define IDE_FEATURE_REG		IDE_ERROR_REG
135     #define IDE_COMMAND_REG		IDE_STATUS_REG
136     #define IDE_ALTSTATUS_REG	IDE_CONTROL_REG
137     #define IDE_IREASON_REG		IDE_NSECTOR_REG
138     #define IDE_BCOUNTL_REG		IDE_LCYL_REG
139     #define IDE_BCOUNTH_REG		IDE_HCYL_REG
140     
141     #define GET_ERR()		IN_BYTE(IDE_ERROR_REG)
142     #define GET_STAT()		IN_BYTE(IDE_STATUS_REG)
143     #define GET_ALTSTAT()		IN_BYTE(IDE_CONTROL_REG)
144     #define OK_STAT(stat,good,bad)	(((stat)&((good)|(bad)))==(good))
145     #define BAD_R_STAT		(BUSY_STAT   | ERR_STAT)
146     #define BAD_W_STAT		(BAD_R_STAT  | WRERR_STAT)
147     #define BAD_STAT		(BAD_R_STAT  | DRQ_STAT)
148     #define DRIVE_READY		(READY_STAT  | SEEK_STAT)
149     #define DATA_READY		(DRQ_STAT)
150     
151     /*
152      * Some more useful definitions
153      */
154     #define IDE_MAJOR_NAME	"hd"	/* the same for all i/f; see also genhd.c */
155     #define MAJOR_NAME	IDE_MAJOR_NAME
156     #define PARTN_BITS	6	/* number of minor dev bits for partitions */
157     #define PARTN_MASK	((1<<PARTN_BITS)-1)	/* a useful bit mask */
158     #define MAX_DRIVES	2	/* per interface; 2 assumed by lots of code */
159     #define SECTOR_WORDS	(512 / 4)	/* number of 32bit words per sector */
160     #define IDE_LARGE_SEEK(b1,b2,t)	(((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
161     #define IDE_MIN(a,b)	((a)<(b) ? (a):(b))
162     #define IDE_MAX(a,b)	((a)>(b) ? (a):(b))
163     
164     /*
165      * Timeouts for various operations:
166      */
167     #define WAIT_DRQ	(5*HZ/100)	/* 50msec - spec allows up to 20ms */
168     #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
169     #define WAIT_READY	(5*HZ)		/* 5sec - some laptops are very slow */
170     #else
171     #define WAIT_READY	(3*HZ/100)	/* 30msec - should be instantaneous */
172     #endif /* CONFIG_APM || CONFIG_APM_MODULE */
173     #define WAIT_PIDENTIFY	(10*HZ)	/* 10sec  - should be less than 3ms (?)
174     				            if all ATAPI CD is closed at boot */
175     #define WAIT_WORSTCASE	(30*HZ)	/* 30sec  - worst case when spinning up */
176     #define WAIT_CMD	(10*HZ)	/* 10sec  - maximum wait for an IRQ to happen */
177     #define WAIT_MIN_SLEEP	(2*HZ/100)	/* 20msec - minimum sleep time */
178     
179     #define SELECT_DRIVE(hwif,drive)				\
180     {								\
181     	if (hwif->selectproc)					\
182     		hwif->selectproc(drive);			\
183     	OUT_BYTE((drive)->select.all, hwif->io_ports[IDE_SELECT_OFFSET]); \
184     }
185     
186     #define SELECT_INTERRUPT(hwif,drive)				\
187     {								\
188     	if (hwif->intrproc)					\
189     		hwif->intrproc(drive);				\
190     	else							\
191     		OUT_BYTE((drive)->ctl|2, hwif->io_ports[IDE_CONTROL_OFFSET]);	\
192     }
193     
194     #define SELECT_MASK(hwif,drive,mask)				\
195     {								\
196     	if (hwif->maskproc)					\
197     		hwif->maskproc(drive,mask);			\
198     }
199     
200     #define SELECT_READ_WRITE(hwif,drive,func)			\
201     {								\
202     	if (hwif->rwproc)					\
203     		hwif->rwproc(drive,func);			\
204     }
205     
206     #define QUIRK_LIST(hwif,drive)					\
207     {								\
208     	if (hwif->quirkproc)					\
209     		(drive)->quirk_list = hwif->quirkproc(drive);	\
210     }
211     
212     #define IDE_DEBUG(lineno) \
213     	printk("%s,%s,line=%d\n", __FILE__, __FUNCTION__, (lineno))
214     
215     /*
216      * Check for an interrupt and acknowledge the interrupt status
217      */
218     struct hwif_s;
219     typedef int (ide_ack_intr_t)(struct hwif_s *);
220     
221     #ifndef NO_DMA
222     #define NO_DMA  255
223     #endif
224     
225     /*
226      * Structure to hold all information about the location of this port
227      */
228     typedef struct hw_regs_s {
229     	ide_ioreg_t	io_ports[IDE_NR_PORTS];	/* task file registers */
230     	int		irq;			/* our irq number */
231     	int		dma;			/* our dma entry */
232     	ide_ack_intr_t	*ack_intr;		/* acknowledge interrupt */
233     	void		*priv;			/* interface specific data */
234     } hw_regs_t;
235     
236     /*
237      * Register new hardware with ide
238      */
239     int ide_register_hw(hw_regs_t *hw, struct hwif_s **hwifp);
240     
241     /*
242      * Set up hw_regs_t structure before calling ide_register_hw (optional)
243      */
244     void ide_setup_ports(	hw_regs_t *hw,
245     			ide_ioreg_t base,
246     			int *offsets,
247     			ide_ioreg_t ctrl,
248     			ide_ioreg_t intr,
249     			ide_ack_intr_t *ack_intr,
250     			int irq);
251     
252     #include <asm/ide.h>
253     
254     /*
255      * If the arch-dependant ide.h did not declare/define any OUT_BYTE
256      * or IN_BYTE functions, we make some defaults here.
257      */
258     
259     #ifndef HAVE_ARCH_OUT_BYTE
260     #ifdef REALLY_FAST_IO
261     #define OUT_BYTE(b,p)          outb((b),(p))
262     #else
263     #define OUT_BYTE(b,p)          outb_p((b),(p))
264     #endif
265     #endif
266     
267     #ifndef HAVE_ARCH_IN_BYTE
268     #ifdef REALLY_FAST_IO
269     #define IN_BYTE(p)             (byte)inb_p(p)
270     #else
271     #define IN_BYTE(p)             (byte)inb(p)
272     #endif
273     #endif
274     
275     /*
276      * Now for the data we need to maintain per-drive:  ide_drive_t
277      */
278     
279     #define ide_scsi	0x21
280     #define ide_disk	0x20
281     #define ide_optical	0x7
282     #define ide_cdrom	0x5
283     #define ide_tape	0x1
284     #define ide_floppy	0x0
285     
286     typedef union {
287     	unsigned all			: 8;	/* all of the bits together */
288     	struct {
289     		unsigned set_geometry	: 1;	/* respecify drive geometry */
290     		unsigned recalibrate	: 1;	/* seek to cyl 0      */
291     		unsigned set_multmode	: 1;	/* set multmode count */
292     		unsigned set_tune	: 1;	/* tune interface for drive */
293     		unsigned reserved	: 4;	/* unused */
294     	} b;
295     } special_t;
296     
297     typedef struct ide_drive_s {
298     	request_queue_t		 queue;	/* request queue */
299     	struct ide_drive_s 	*next;	/* circular list of hwgroup drives */
300     	unsigned long sleep;		/* sleep until this time */
301     	unsigned long service_start;	/* time we started last request */
302     	unsigned long service_time;	/* service time of last request */
303     	unsigned long timeout;		/* max time to wait for irq */
304     	special_t	special;	/* special action flags */
305     	byte     keep_settings;		/* restore settings after drive reset */
306     	byte     using_dma;		/* disk is using dma for read/write */
307     	byte	 retry_pio;		/* retrying dma capable host in pio */
308     	byte	 state;			/* retry state */
309     	byte     waiting_for_dma;	/* dma currently in progress */
310     	byte     unmask;		/* flag: okay to unmask other irqs */
311     	byte     slow;			/* flag: slow data port */
312     	byte     bswap;			/* flag: byte swap data */
313     	byte     dsc_overlap;		/* flag: DSC overlap */
314     	byte     nice1;			/* flag: give potential excess bandwidth */
315     	unsigned present	: 1;	/* drive is physically present */
316     	unsigned noprobe 	: 1;	/* from:  hdx=noprobe */
317     	unsigned busy		: 1;	/* currently doing revalidate_disk() */
318     	unsigned removable	: 1;	/* 1 if need to do check_media_change */
319     	unsigned forced_geom	: 1;	/* 1 if hdx=c,h,s was given at boot */
320     	unsigned no_unmask	: 1;	/* disallow setting unmask bit */
321     	unsigned no_io_32bit	: 1;	/* disallow enabling 32bit I/O */
322     	unsigned nobios		: 1;	/* flag: do not probe bios for drive */
323     	unsigned revalidate	: 1;	/* request revalidation */
324     	unsigned atapi_overlap	: 1;	/* flag: ATAPI overlap (not supported) */
325     	unsigned nice0		: 1;	/* flag: give obvious excess bandwidth */
326     	unsigned nice2		: 1;	/* flag: give a share in our own bandwidth */
327     	unsigned doorlocking	: 1;	/* flag: for removable only: door lock/unlock works */
328     	unsigned autotune	: 2;	/* 1=autotune, 2=noautotune, 0=default */
329     	unsigned remap_0_to_1	: 2;	/* 0=remap if ezdrive, 1=remap, 2=noremap */
330     	unsigned ata_flash	: 1;	/* 1=present, 0=default */
331     	byte		scsi;		/* 0=default, 1=skip current ide-subdriver for ide-scsi emulation */
332     	byte		media;		/* disk, cdrom, tape, floppy, ... */
333     	select_t	select;		/* basic drive/head select reg value */
334     	byte		ctl;		/* "normal" value for IDE_CONTROL_REG */
335     	byte		ready_stat;	/* min status value for drive ready */
336     	byte		mult_count;	/* current multiple sector setting */
337     	byte 		mult_req;	/* requested multiple sector setting */
338     	byte 		tune_req;	/* requested drive tuning setting */
339     	byte		io_32bit;	/* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
340     	byte		bad_wstat;	/* used for ignoring WRERR_STAT */
341     	byte		nowerr;		/* used for ignoring WRERR_STAT */
342     	byte		sect0;		/* offset of first sector for DM6:DDO */
343     	byte 		usage;		/* current "open()" count for drive */
344     	byte 		head;		/* "real" number of heads */
345     	byte		sect;		/* "real" sectors per track */
346     	byte		bios_head;	/* BIOS/fdisk/LILO number of heads */
347     	byte		bios_sect;	/* BIOS/fdisk/LILO sectors per track */
348     	unsigned int	bios_cyl;	/* BIOS/fdisk/LILO number of cyls */
349     	unsigned int	cyl;		/* "real" number of cyls */
350     	unsigned long	capacity;	/* total number of sectors */
351     	unsigned int	drive_data;	/* for use by tuneproc/selectproc as needed */
352     	void		  *hwif;	/* actually (ide_hwif_t *) */
353     	wait_queue_head_t wqueue;	/* used to wait for drive in open() */
354     	struct hd_driveid *id;		/* drive model identification info */
355     	struct hd_struct  *part;	/* drive partition table */
356     	char		name[4];	/* drive name, such as "hda" */
357     	void 		*driver;	/* (ide_driver_t *) */
358     	void		*driver_data;	/* extra driver data */
359     	devfs_handle_t	de;		/* directory for device */
360     	struct proc_dir_entry *proc;	/* /proc/ide/ directory entry */
361     	void		*settings;	/* /proc/ide/ drive settings */
362     	char		driver_req[10];	/* requests specific driver */
363     	int		last_lun;	/* last logical unit */
364     	int		forced_lun;	/* if hdxlun was given at boot */
365     	int		lun;		/* logical unit */
366     	int		crc_count;	/* crc counter to reduce drive speed */
367     	byte		quirk_list;	/* drive is considered quirky if set for a specific host */
368     	byte		suspend_reset;	/* drive suspend mode flag, soft-reset recovers */
369     	byte		init_speed;	/* transfer rate set at boot */
370     	byte		current_speed;	/* current transfer rate set */
371     	byte		dn;		/* now wide spread use */
372     	unsigned int	failures;	/* current failure count */
373     	unsigned int	max_failures;	/* maximum allowed failure count */
374     } ide_drive_t;
375     
376     /*
377      * An ide_dmaproc_t() initiates/aborts DMA read/write operations on a drive.
378      *
379      * The caller is assumed to have selected the drive and programmed the drive's
380      * sector address using CHS or LBA.  All that remains is to prepare for DMA
381      * and then issue the actual read/write DMA/PIO command to the drive.
382      *
383      * Returns 0 if all went well.
384      * Returns 1 if DMA read/write could not be started, in which case the caller
385      * should either try again later, or revert to PIO for the current request.
386      */
387     typedef enum {	ide_dma_read,	ide_dma_write,		ide_dma_begin,
388     		ide_dma_end,	ide_dma_check,		ide_dma_on,
389     		ide_dma_off,	ide_dma_off_quietly,	ide_dma_test_irq,
390     		ide_dma_bad_drive,			ide_dma_good_drive,
391     		ide_dma_verbose,			ide_dma_retune,
392     		ide_dma_lostirq,			ide_dma_timeout
393     } ide_dma_action_t;
394     
395     typedef int (ide_dmaproc_t)(ide_dma_action_t, ide_drive_t *);
396     
397     /*
398      * An ide_ideproc_t() performs CPU-polled transfers to/from a drive.
399      * Arguments are: the drive, the buffer pointer, and the length (in bytes or
400      * words depending on if it's an IDE or ATAPI call).
401      *
402      * If it is not defined for a controller, standard-code is used from ide.c.
403      *
404      * Controllers which are not memory-mapped in the standard way need to 
405      * override that mechanism using this function to work.
406      *
407      */
408     typedef enum { ideproc_ide_input_data,    ideproc_ide_output_data,
409     	       ideproc_atapi_input_bytes, ideproc_atapi_output_bytes
410     } ide_ide_action_t;
411     
412     typedef void (ide_ideproc_t)(ide_ide_action_t, ide_drive_t *, void *, unsigned int);
413     
414     /*
415      * An ide_tuneproc_t() is used to set the speed of an IDE interface
416      * to a particular PIO mode.  The "byte" parameter is used
417      * to select the PIO mode by number (0,1,2,3,4,5), and a value of 255
418      * indicates that the interface driver should "auto-tune" the PIO mode
419      * according to the drive capabilities in drive->id;
420      *
421      * Not all interface types support tuning, and not all of those
422      * support all possible PIO settings.  They may silently ignore
423      * or round values as they see fit.
424      */
425     typedef void (ide_tuneproc_t) (ide_drive_t *, byte);
426     typedef int (ide_speedproc_t) (ide_drive_t *, byte);
427     
428     /*
429      * This is used to provide support for strange interfaces
430      */
431     typedef void (ide_selectproc_t) (ide_drive_t *);
432     typedef void (ide_resetproc_t) (ide_drive_t *);
433     typedef int (ide_quirkproc_t) (ide_drive_t *);
434     typedef void (ide_intrproc_t) (ide_drive_t *);
435     typedef void (ide_maskproc_t) (ide_drive_t *, int);
436     typedef void (ide_rw_proc_t) (ide_drive_t *, ide_dma_action_t);
437     
438     /*
439      * ide soft-power support
440      */
441     typedef int (ide_busproc_t) (struct hwif_s *, int);
442     
443     /*
444      * hwif_chipset_t is used to keep track of the specific hardware
445      * chipset used by each IDE interface, if known.
446      */
447     typedef enum {	ide_unknown,	ide_generic,	ide_pci,
448     		ide_cmd640,	ide_dtc2278,	ide_ali14xx,
449     		ide_qd65xx,	ide_umc8672,	ide_ht6560b,
450     		ide_pdc4030,	ide_rz1000,	ide_trm290,
451     		ide_cmd646,	ide_cy82c693,	ide_4drives,
452     		ide_pmac,       ide_etrax100
453     } hwif_chipset_t;
454     
455     #define IDE_CHIPSET_PCI_MASK	\
456         ((1<<ide_pci)|(1<<ide_cmd646)|(1<<ide_ali14xx))
457     #define IDE_CHIPSET_IS_PCI(c)	((IDE_CHIPSET_PCI_MASK >> (c)) & 1)
458     
459     #ifdef CONFIG_BLK_DEV_IDEPCI
460     typedef struct ide_pci_devid_s {
461     	unsigned short	vid;
462     	unsigned short	did;
463     } ide_pci_devid_t;
464     
465     #define IDE_PCI_DEVID_NULL	((ide_pci_devid_t){0,0})
466     #define IDE_PCI_DEVID_EQ(a,b)	(a.vid == b.vid && a.did == b.did)
467     #endif /* CONFIG_BLK_DEV_IDEPCI */
468     
469     typedef struct hwif_s {
470     	struct hwif_s	*next;		/* for linked-list in ide_hwgroup_t */
471     	void		*hwgroup;	/* actually (ide_hwgroup_t *) */
472     	ide_ioreg_t	io_ports[IDE_NR_PORTS];	/* task file registers */
473     	hw_regs_t	hw;		/* Hardware info */
474     	ide_drive_t	drives[MAX_DRIVES];	/* drive info */
475     	struct gendisk	*gd;		/* gendisk structure */
476     	ide_tuneproc_t	*tuneproc;	/* routine to tune PIO mode for drives */
477     	ide_speedproc_t	*speedproc;	/* routine to retune DMA modes for drives */
478     	ide_selectproc_t *selectproc;	/* tweaks hardware to select drive */
479     	ide_resetproc_t	*resetproc;	/* routine to reset controller after a disk reset */
480     	ide_intrproc_t	*intrproc;	/* special interrupt handling for shared pci interrupts */
481     	ide_maskproc_t	*maskproc;	/* special host masking for drive selection */
482     	ide_quirkproc_t	*quirkproc;	/* check host's drive quirk list */
483     	ide_rw_proc_t	*rwproc;	/* adjust timing based upon rq->cmd direction */
484     	ide_ideproc_t   *ideproc;       /* CPU-polled transfer routine */
485     	ide_dmaproc_t	*dmaproc;	/* dma read/write/abort routine */
486     	unsigned int	*dmatable_cpu;	/* dma physical region descriptor table (cpu view) */
487     	dma_addr_t	dmatable_dma;	/* dma physical region descriptor table (dma view) */
488     	struct scatterlist *sg_table;	/* Scatter-gather list used to build the above */
489     	int sg_nents;			/* Current number of entries in it */
490     	int sg_dma_direction;		/* dma transfer direction */
491     	int sg_dma_active;		/* is it in use */
492     	struct hwif_s	*mate;		/* other hwif from same PCI chip */
493     	unsigned long	dma_base;	/* base addr for dma ports */
494     	unsigned	dma_extra;	/* extra addr for dma ports */
495     	unsigned long	config_data;	/* for use by chipset-specific code */
496     	unsigned long	select_data;	/* for use by chipset-specific code */
497     	struct proc_dir_entry *proc;	/* /proc/ide/ directory entry */
498     	int		irq;		/* our irq number */
499     	byte		major;		/* our major number */
500     	char 		name[6];	/* name of interface, eg. "ide0" */
501     	byte		index;		/* 0 for ide0; 1 for ide1; ... */
502     	hwif_chipset_t	chipset;	/* sub-module for tuning.. */
503     	unsigned	noprobe    : 1;	/* don't probe for this interface */
504     	unsigned	present    : 1;	/* this interface exists */
505     	unsigned	serialized : 1;	/* serialized operation with mate hwif */
506     	unsigned	sharing_irq: 1;	/* 1 = sharing irq with another hwif */
507     	unsigned	reset      : 1;	/* reset after probe */
508     	unsigned	autodma    : 1;	/* automatically try to enable DMA at boot */
509     	unsigned	udma_four  : 1;	/* 1=ATA-66 capable, 0=default */
510     	byte		channel;	/* for dual-port chips: 0=primary, 1=secondary */
511     #ifdef CONFIG_BLK_DEV_IDEPCI
512     	struct pci_dev	*pci_dev;	/* for pci chipsets */
513     	ide_pci_devid_t	pci_devid;	/* for pci chipsets: {VID,DID} */
514     #endif /* CONFIG_BLK_DEV_IDEPCI */
515     #if (DISK_RECOVERY_TIME > 0)
516     	unsigned long	last_time;	/* time when previous rq was done */
517     #endif
518     	byte		straight8;	/* Alan's straight 8 check */
519     	void		*hwif_data;	/* extra hwif data */
520     	ide_busproc_t	*busproc;	/* driver soft-power interface */
521     	byte		bus_state;	/* power state of the IDE bus */
522     } ide_hwif_t;
523     
524     
525     /*
526      * Status returned from various ide_ functions
527      */
528     typedef enum {
529     	ide_stopped,	/* no drive operation was started */
530     	ide_started	/* a drive operation was started, and a handler was set */
531     } ide_startstop_t;
532     
533     /*
534      *  internal ide interrupt handler type
535      */
536     typedef ide_startstop_t (ide_handler_t)(ide_drive_t *);
537     
538     /*
539      * when ide_timer_expiry fires, invoke a handler of this type
540      * to decide what to do.
541      */
542     typedef int (ide_expiry_t)(ide_drive_t *);
543     
544     typedef struct hwgroup_s {
545     	ide_handler_t		*handler;/* irq handler, if active */
546     	volatile int		busy;	/* BOOL: protects all fields below */
547     	int			sleeping; /* BOOL: wake us up on timer expiry */
548     	ide_drive_t		*drive;	/* current drive */
549     	ide_hwif_t		*hwif;	/* ptr to current hwif in linked-list */
550     	struct request		*rq;	/* current request */
551     	struct timer_list	timer;	/* failsafe timer */
552     	struct request		wrq;	/* local copy of current write rq */
553     	unsigned long		poll_timeout;	/* timeout value during long polls */
554     	ide_expiry_t		*expiry;	/* queried upon timeouts */
555     } ide_hwgroup_t;
556     
557     /*
558      * configurable drive settings
559      */
560     
561     #define TYPE_INT	0
562     #define TYPE_INTA	1
563     #define TYPE_BYTE	2
564     #define TYPE_SHORT	3
565     
566     #define SETTING_READ	(1 << 0)
567     #define SETTING_WRITE	(1 << 1)
568     #define SETTING_RW	(SETTING_READ | SETTING_WRITE)
569     
570     typedef int (ide_procset_t)(ide_drive_t *, int);
571     typedef struct ide_settings_s {
572     	char			*name;
573     	int			rw;
574     	int			read_ioctl;
575     	int			write_ioctl;
576     	int			data_type;
577     	int			min;
578     	int			max;
579     	int			mul_factor;
580     	int			div_factor;
581     	void			*data;
582     	ide_procset_t		*set;
583     	int			auto_remove;
584     	struct ide_settings_s	*next;
585     } ide_settings_t;
586     
587     void 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);
588     void ide_remove_setting(ide_drive_t *drive, char *name);
589     ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name);
590     int ide_read_setting(ide_drive_t *t, ide_settings_t *setting);
591     int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val);
592     void ide_add_generic_settings(ide_drive_t *drive);
593     
594     /*
595      * /proc/ide interface
596      */
597     typedef struct {
598     	const char	*name;
599     	mode_t		mode;
600     	read_proc_t	*read_proc;
601     	write_proc_t	*write_proc;
602     } ide_proc_entry_t;
603     
604     #ifdef CONFIG_PROC_FS
605     void proc_ide_create(void);
606     void proc_ide_destroy(void);
607     void destroy_proc_ide_drives(ide_hwif_t *);
608     void create_proc_ide_interfaces(void);
609     void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data);
610     void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p);
611     read_proc_t proc_ide_read_capacity;
612     read_proc_t proc_ide_read_geometry;
613     
614     /*
615      * Standard exit stuff:
616      */
617     #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
618     {					\
619     	len -= off;			\
620     	if (len < count) {		\
621     		*eof = 1;		\
622     		if (len <= 0)		\
623     			return 0;	\
624     	} else				\
625     		len = count;		\
626     	*start = page + off;		\
627     	return len;			\
628     }
629     #else
630     #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
631     #endif
632     
633     /*
634      * Subdrivers support.
635      */
636     #define IDE_SUBDRIVER_VERSION	1
637     
638     typedef int		(ide_cleanup_proc)(ide_drive_t *);
639     typedef ide_startstop_t	(ide_do_request_proc)(ide_drive_t *, struct request *, unsigned long);
640     typedef void		(ide_end_request_proc)(byte, ide_hwgroup_t *);
641     typedef int		(ide_ioctl_proc)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
642     typedef int		(ide_open_proc)(struct inode *, struct file *, ide_drive_t *);
643     typedef void		(ide_release_proc)(struct inode *, struct file *, ide_drive_t *);
644     typedef int		(ide_check_media_change_proc)(ide_drive_t *);
645     typedef void		(ide_revalidate_proc)(ide_drive_t *);
646     typedef void		(ide_pre_reset_proc)(ide_drive_t *);
647     typedef unsigned long	(ide_capacity_proc)(ide_drive_t *);
648     typedef ide_startstop_t	(ide_special_proc)(ide_drive_t *);
649     typedef void		(ide_setting_proc)(ide_drive_t *);
650     typedef int		(ide_driver_reinit_proc)(ide_drive_t *);
651     
652     typedef struct ide_driver_s {
653     	const char			*name;
654     	const char			*version;
655     	byte				media;
656     	unsigned busy			: 1;
657     	unsigned supports_dma		: 1;
658     	unsigned supports_dsc_overlap	: 1;
659     	ide_cleanup_proc		*cleanup;
660     	ide_do_request_proc		*do_request;
661     	ide_end_request_proc		*end_request;
662     	ide_ioctl_proc			*ioctl;
663     	ide_open_proc			*open;
664     	ide_release_proc		*release;
665     	ide_check_media_change_proc	*media_change;
666     	ide_revalidate_proc		*revalidate;
667     	ide_pre_reset_proc		*pre_reset;
668     	ide_capacity_proc		*capacity;
669     	ide_special_proc		*special;
670     	ide_proc_entry_t		*proc;
671     	ide_driver_reinit_proc		*driver_reinit;
672     } ide_driver_t;
673     
674     #define DRIVER(drive)		((ide_driver_t *)((drive)->driver))
675     
676     /*
677      * IDE modules.
678      */
679     #define IDE_CHIPSET_MODULE		0	/* not supported yet */
680     #define IDE_PROBE_MODULE		1
681     #define IDE_DRIVER_MODULE		2
682     
683     typedef int	(ide_module_init_proc)(void);
684     
685     typedef struct ide_module_s {
686     	int				type;
687     	ide_module_init_proc		*init;
688     	void				*info;
689     	struct ide_module_s		*next;
690     } ide_module_t;
691     
692     /*
693      * ide_hwifs[] is the master data structure used to keep track
694      * of just about everything in ide.c.  Whenever possible, routines
695      * should be using pointers to a drive (ide_drive_t *) or
696      * pointers to a hwif (ide_hwif_t *), rather than indexing this
697      * structure directly (the allocation/layout may change!).
698      *
699      */
700     #ifndef _IDE_C
701     extern	ide_hwif_t	ide_hwifs[];		/* master data repository */
702     extern	ide_module_t	*ide_modules;
703     extern	ide_module_t	*ide_probe;
704     #endif
705     extern int noautodma;
706     
707     /*
708      * We need blk.h, but we replace its end_request by our own version.
709      */
710     #define IDE_DRIVER		/* Toggle some magic bits in blk.h */
711     #define LOCAL_END_REQUEST	/* Don't generate end_request in blk.h */
712     #include <linux/blk.h>
713     
714     void ide_end_request(byte uptodate, ide_hwgroup_t *hwgroup);
715     
716     /*
717      * This is used for (nearly) all data transfers from/to the IDE interface
718      * FIXME for 2.5, to a pointer pass verses memcpy........
719      */
720     void ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
721     void ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
722     
723     /*
724      * This is used for (nearly) all ATAPI data transfers from/to the IDE interface
725      * FIXME for 2.5, to a pointer pass verses memcpy........
726      */
727     void atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
728     void atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
729     
730     /*
731      * This is used on exit from the driver, to designate the next irq handler
732      * and also to start the safety timer.
733      */
734     void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry);
735     
736     /*
737      * Error reporting, in human readable form (luxurious, but a memory hog).
738      */
739     byte ide_dump_status (ide_drive_t *drive, const char *msg, byte stat);
740     
741     /*
742      * ide_error() takes action based on the error returned by the controller.
743      * The caller should return immediately after invoking this.
744      */
745     ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, byte stat);
746     
747     /*
748      * Issue a simple drive command
749      * The drive must be selected beforehand.
750      */
751     void ide_cmd(ide_drive_t *drive, byte cmd, byte nsect, ide_handler_t *handler);
752     
753     /*
754      * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
755      * removing leading/trailing blanks and compressing internal blanks.
756      * It is primarily used to tidy up the model name/number fields as
757      * returned by the WIN_[P]IDENTIFY commands.
758      */
759     void ide_fixstring (byte *s, const int bytecount, const int byteswap);
760     
761     /*
762      * This routine busy-waits for the drive status to be not "busy".
763      * It then checks the status for all of the "good" bits and none
764      * of the "bad" bits, and if all is okay it returns 0.  All other
765      * cases return 1 after doing "*startstop = ide_error()", and the
766      * caller should return the updated value of "startstop" in this case.
767      * "startstop" is unchanged when the function returns 0;
768      */
769     int ide_wait_stat (ide_startstop_t *startstop, ide_drive_t *drive, byte good, byte bad, unsigned long timeout);
770     
771     int ide_wait_noerr (ide_drive_t *drive, byte good, byte bad, unsigned long timeout);
772     
773     /*
774      * This routine is called from the partition-table code in genhd.c
775      * to "convert" a drive to a logical geometry with fewer than 1024 cyls.
776      */
777     int ide_xlate_1024 (kdev_t, int, int, const char *);
778     
779     /*
780      * Convert kdev_t structure into ide_drive_t * one.
781      */
782     ide_drive_t *get_info_ptr (kdev_t i_rdev);
783     
784     /*
785      * Return the current idea about the total capacity of this drive.
786      */
787     unsigned long current_capacity (ide_drive_t *drive);
788     
789     /*
790      * Start a reset operation for an IDE interface.
791      * The caller should return immediately after invoking this.
792      */
793     ide_startstop_t ide_do_reset (ide_drive_t *);
794     
795     /*
796      * Re-Start an operation for an IDE interface.
797      * The caller should return immediately after invoking this.
798      */
799     ide_startstop_t restart_request (ide_drive_t *);
800     
801     /*
802      * This function is intended to be used prior to invoking ide_do_drive_cmd().
803      */
804     void ide_init_drive_cmd (struct request *rq);
805     
806     /*
807      * "action" parameter type for ide_do_drive_cmd() below.
808      */
809     typedef enum {
810     	ide_wait,	/* insert rq at end of list, and wait for it */
811     	ide_next,	/* insert rq immediately after current request */
812     	ide_preempt,	/* insert rq in front of current request */
813     	ide_end		/* insert rq at end of list, but don't wait for it */
814     } ide_action_t;
815     
816     /*
817      * This function issues a special IDE device request
818      * onto the request queue.
819      *
820      * If action is ide_wait, then the rq is queued at the end of the
821      * request queue, and the function sleeps until it has been processed.
822      * This is for use when invoked from an ioctl handler.
823      *
824      * If action is ide_preempt, then the rq is queued at the head of
825      * the request queue, displacing the currently-being-processed
826      * request and this function returns immediately without waiting
827      * for the new rq to be completed.  This is VERY DANGEROUS, and is
828      * intended for careful use by the ATAPI tape/cdrom driver code.
829      *
830      * If action is ide_next, then the rq is queued immediately after
831      * the currently-being-processed-request (if any), and the function
832      * returns without waiting for the new rq to be completed.  As above,
833      * This is VERY DANGEROUS, and is intended for careful use by the
834      * ATAPI tape/cdrom driver code.
835      *
836      * If action is ide_end, then the rq is queued at the end of the
837      * request queue, and the function returns immediately without waiting
838      * for the new rq to be completed. This is again intended for careful
839      * use by the ATAPI tape/cdrom driver code.
840      */
841     int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action);
842     
843     /*
844      * Clean up after success/failure of an explicit drive cmd.
845      * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
846      */
847     void ide_end_drive_cmd (ide_drive_t *drive, byte stat, byte err);
848     
849     /*
850      * Issue ATA command and wait for completion.
851      */
852     int ide_wait_cmd (ide_drive_t *drive, int cmd, int nsect, int feature, int sectors, byte *buf);
853     int ide_wait_cmd_task (ide_drive_t *drive, byte *buf);
854     
855     void ide_delay_50ms (void);
856     int system_bus_clock(void);
857     
858     byte ide_auto_reduce_xfer (ide_drive_t *drive);
859     int ide_driveid_update (ide_drive_t *drive);
860     int ide_ata66_check (ide_drive_t *drive, byte cmd, byte nsect, byte feature);
861     int ide_config_drive_speed (ide_drive_t *drive, byte speed);
862     byte eighty_ninty_three (ide_drive_t *drive);
863     int set_transfer (ide_drive_t *drive, byte cmd, byte nsect, byte feature);
864     
865     /*
866      * ide_system_bus_speed() returns what we think is the system VESA/PCI
867      * bus speed (in MHz).  This is used for calculating interface PIO timings.
868      * The default is 40 for known PCI systems, 50 otherwise.
869      * The "idebus=xx" parameter can be used to override this value.
870      */
871     int ide_system_bus_speed (void);
872     
873     /*
874      * ide_multwrite() transfers a block of up to mcount sectors of data
875      * to a drive as part of a disk multwrite operation.
876      */
877     int ide_multwrite (ide_drive_t *drive, unsigned int mcount);
878     
879     /*
880      * ide_stall_queue() can be used by a drive to give excess bandwidth back
881      * to the hwgroup by sleeping for timeout jiffies.
882      */
883     void ide_stall_queue (ide_drive_t *drive, unsigned long timeout);
884     
885     /*
886      * ide_get_queue() returns the queue which corresponds to a given device.
887      */
888     request_queue_t *ide_get_queue (kdev_t dev);
889     
890     /*
891      * CompactFlash cards and their brethern pretend to be removable hard disks,
892      * but they never have a slave unit, and they don't have doorlock mechanisms.
893      * This test catches them, and is invoked elsewhere when setting appropriate config bits.
894      */
895     int drive_is_flashcard (ide_drive_t *drive);
896     
897     int ide_spin_wait_hwgroup (ide_drive_t *drive);
898     void ide_timer_expiry (unsigned long data);
899     void ide_intr (int irq, void *dev_id, struct pt_regs *regs);
900     void do_ide_request (request_queue_t * q);
901     void ide_init_subdrivers (void);
902     
903     #ifndef _IDE_C
904     extern struct block_device_operations ide_fops[];
905     extern ide_proc_entry_t generic_subdriver_entries[];
906     #endif
907     
908     #ifdef _IDE_C
909     #ifdef CONFIG_BLK_DEV_IDE
910     int ideprobe_init (void);
911     #endif /* CONFIG_BLK_DEV_IDE */
912     #ifdef CONFIG_BLK_DEV_IDEDISK
913     int idedisk_init (void);
914     #endif /* CONFIG_BLK_DEV_IDEDISK */
915     #ifdef CONFIG_BLK_DEV_IDECD
916     int ide_cdrom_init (void);
917     #endif /* CONFIG_BLK_DEV_IDECD */
918     #ifdef CONFIG_BLK_DEV_IDETAPE
919     int idetape_init (void);
920     #endif /* CONFIG_BLK_DEV_IDETAPE */
921     #ifdef CONFIG_BLK_DEV_IDEFLOPPY
922     int idefloppy_init (void);
923     #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
924     #ifdef CONFIG_BLK_DEV_IDESCSI
925     int idescsi_init (void);
926     #endif /* CONFIG_BLK_DEV_IDESCSI */
927     #endif /* _IDE_C */
928     
929     int ide_register_module (ide_module_t *module);
930     void ide_unregister_module (ide_module_t *module);
931     ide_drive_t *ide_scan_devices (byte media, const char *name, ide_driver_t *driver, int n);
932     int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version);
933     int ide_unregister_subdriver (ide_drive_t *drive);
934     int ide_replace_subdriver(ide_drive_t *drive, const char *driver);
935     
936     #ifdef CONFIG_BLK_DEV_IDEPCI
937     #define ON_BOARD		1
938     #define NEVER_BOARD		0
939     #ifdef CONFIG_BLK_DEV_OFFBOARD
940     #  define OFF_BOARD		ON_BOARD
941     #else /* CONFIG_BLK_DEV_OFFBOARD */
942     #  define OFF_BOARD		NEVER_BOARD
943     #endif /* CONFIG_BLK_DEV_OFFBOARD */
944     
945     unsigned long ide_find_free_region (unsigned short size) __init;
946     void ide_scan_pcibus (int scan_direction) __init;
947     #endif
948     #ifdef CONFIG_BLK_DEV_IDEDMA
949     #define BAD_DMA_DRIVE		0
950     #define GOOD_DMA_DRIVE		1
951     int ide_build_dmatable (ide_drive_t *drive, ide_dma_action_t func);
952     void ide_destroy_dmatable (ide_drive_t *drive);
953     ide_startstop_t ide_dma_intr (ide_drive_t *drive);
954     int check_drive_lists (ide_drive_t *drive, int good_bad);
955     int report_drive_dmaing (ide_drive_t *drive);
956     int ide_dmaproc (ide_dma_action_t func, ide_drive_t *drive);
957     int ide_release_dma (ide_hwif_t *hwif);
958     void ide_setup_dma (ide_hwif_t *hwif, unsigned long dmabase, unsigned int num_ports) __init;
959     unsigned long ide_get_or_set_dma_base (ide_hwif_t *hwif, int extra, const char *name) __init;
960     #endif
961     
962     void hwif_unregister (ide_hwif_t *hwif);
963     
964     #endif /* _IDE_H */
965