Home | History | Annotate | Line # | Download | only in ata
atavar.h revision 1.91
      1  1.91    bouyer /*	$NetBSD: atavar.h,v 1.91 2013/04/03 17:15:07 bouyer Exp $	*/
      2   1.2    bouyer 
      3   1.2    bouyer /*
      4  1.23    bouyer  * Copyright (c) 1998, 2001 Manuel Bouyer.
      5   1.2    bouyer  *
      6   1.2    bouyer  * Redistribution and use in source and binary forms, with or without
      7   1.2    bouyer  * modification, are permitted provided that the following conditions
      8   1.2    bouyer  * are met:
      9   1.2    bouyer  * 1. Redistributions of source code must retain the above copyright
     10   1.2    bouyer  *    notice, this list of conditions and the following disclaimer.
     11   1.2    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.2    bouyer  *    notice, this list of conditions and the following disclaimer in the
     13   1.2    bouyer  *    documentation and/or other materials provided with the distribution.
     14   1.2    bouyer  *
     15  1.18    bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  1.18    bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  1.18    bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  1.67     perry  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  1.18    bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  1.18    bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  1.18    bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  1.18    bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  1.18    bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  1.18    bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25   1.2    bouyer  */
     26   1.2    bouyer 
     27  1.31   thorpej #ifndef _DEV_ATA_ATAVAR_H_
     28  1.31   thorpej #define	_DEV_ATA_ATAVAR_H_
     29  1.31   thorpej 
     30  1.37   thorpej #include <sys/lock.h>
     31  1.37   thorpej #include <sys/queue.h>
     32  1.37   thorpej 
     33  1.73     itohy #include <dev/ata/ataconf.h>
     34  1.73     itohy 
     35  1.59   thorpej /* XXX For scsipi_adapter and scsipi_channel. */
     36  1.59   thorpej #include <dev/scsipi/scsipi_all.h>
     37  1.59   thorpej #include <dev/scsipi/atapiconf.h>
     38  1.59   thorpej 
     39  1.59   thorpej /*
     40  1.39   thorpej  * Description of a command to be handled by an ATA controller.  These
     41  1.39   thorpej  * commands are queued in a list.
     42  1.39   thorpej  */
     43  1.39   thorpej struct ata_xfer {
     44  1.71     perry 	volatile u_int c_flags;	/* command state flags */
     45  1.67     perry 
     46  1.39   thorpej 	/* Channel and drive that are to process the request. */
     47  1.59   thorpej 	struct ata_channel *c_chp;
     48  1.39   thorpej 	int	c_drive;
     49  1.39   thorpej 
     50  1.39   thorpej 	void	*c_cmd;			/* private request structure pointer */
     51  1.39   thorpej 	void	*c_databuf;		/* pointer to data buffer */
     52  1.39   thorpej 	int	c_bcount;		/* byte count left */
     53  1.39   thorpej 	int	c_skip;			/* bytes already transferred */
     54  1.39   thorpej 	int	c_dscpoll;		/* counter for dsc polling (ATAPI) */
     55  1.72     itohy 	int	c_lenoff;		/* offset to c_bcount (ATAPI) */
     56  1.39   thorpej 
     57  1.39   thorpej 	/* Link on the command queue. */
     58  1.39   thorpej 	TAILQ_ENTRY(ata_xfer) c_xferchain;
     59  1.39   thorpej 
     60  1.39   thorpej 	/* Low-level protocol handlers. */
     61  1.59   thorpej 	void	(*c_start)(struct ata_channel *, struct ata_xfer *);
     62  1.59   thorpej 	int	(*c_intr)(struct ata_channel *, struct ata_xfer *, int);
     63  1.59   thorpej 	void	(*c_kill_xfer)(struct ata_channel *, struct ata_xfer *, int);
     64  1.39   thorpej };
     65  1.39   thorpej 
     66  1.65    bouyer /* flags in c_flags */
     67  1.39   thorpej #define	C_ATAPI		0x0001		/* xfer is ATAPI request */
     68  1.39   thorpej #define	C_TIMEOU	0x0002		/* xfer processing timed out */
     69  1.39   thorpej #define	C_POLL		0x0004		/* command is polled */
     70  1.39   thorpej #define	C_DMA		0x0008		/* command uses DMA */
     71  1.65    bouyer #define C_WAIT		0x0010		/* can use tsleep */
     72  1.65    bouyer #define C_WAITACT	0x0020		/* wakeup when active */
     73  1.65    bouyer #define C_FREE		0x0040		/* call ata_free_xfer() asap */
     74  1.72     itohy #define C_PIOBM		0x0080		/* command uses busmastering PIO */
     75  1.39   thorpej 
     76  1.44    bouyer /* reasons for c_kill_xfer() */
     77  1.44    bouyer #define KILL_GONE 1 /* device is gone */
     78  1.44    bouyer #define KILL_RESET 2 /* xfer was reset */
     79  1.44    bouyer 
     80  1.39   thorpej /* Per-channel queue of ata_xfers.  May be shared by multiple channels. */
     81  1.39   thorpej struct ata_queue {
     82  1.46    bouyer 	TAILQ_HEAD(, ata_xfer) queue_xfer; /* queue of pending commands */
     83  1.46    bouyer 	int queue_freeze; /* freeze count for the queue */
     84  1.46    bouyer 	struct ata_xfer *active_xfer; /* active command */
     85  1.68    bouyer 	int queue_flags;	/* flags for this queue */
     86  1.68    bouyer #define QF_IDLE_WAIT   0x01    /* someone is wants the controller idle */
     87  1.39   thorpej };
     88  1.39   thorpej 
     89  1.37   thorpej /* ATA bus instance state information. */
     90  1.37   thorpej struct atabus_softc {
     91  1.76      cube 	device_t sc_dev;
     92  1.59   thorpej 	struct ata_channel *sc_chan;
     93  1.45    bouyer 	int sc_flags;
     94  1.45    bouyer #define ATABUSCF_OPEN	0x01
     95  1.37   thorpej };
     96  1.37   thorpej 
     97  1.37   thorpej /*
     98  1.37   thorpej  * A queue of atabus instances, used to ensure the same bus probe order
     99  1.37   thorpej  * for a given hardware configuration at each boot.
    100  1.37   thorpej  */
    101  1.37   thorpej struct atabus_initq {
    102  1.37   thorpej 	TAILQ_ENTRY(atabus_initq) atabus_initq;
    103  1.37   thorpej 	struct atabus_softc *atabus_sc;
    104  1.37   thorpej };
    105  1.37   thorpej 
    106  1.31   thorpej /* High-level functions and structures used by both ATA and ATAPI devices */
    107  1.33   thorpej struct ataparams;
    108  1.33   thorpej 
    109   1.2    bouyer /* Datas common to drives and controller drivers */
    110   1.2    bouyer struct ata_drive_datas {
    111  1.31   thorpej 	u_int8_t drive;		/* drive number */
    112  1.31   thorpej 	int8_t ata_vers;	/* ATA version supported */
    113  1.31   thorpej 	u_int16_t drive_flags;	/* bitmask for drives present/absent and cap */
    114  1.90    bouyer #define	ATA_DRIVE_CAP32		0x0001
    115  1.90    bouyer #define	ATA_DRIVE_DMA		0x0002
    116  1.90    bouyer #define	ATA_DRIVE_UDMA		0x0004
    117  1.90    bouyer #define	ATA_DRIVE_MODE		0x0008	/* the drive reported its mode */
    118  1.90    bouyer #define	ATA_DRIVE_RESET		0x0010	/* reset the drive state at next xfer */
    119  1.90    bouyer #define	ATA_DRIVE_WAITDRAIN	0x0020	/* device is waiting for the queue to drain */
    120  1.90    bouyer #define	ATA_DRIVE_NOSTREAM	0x0040	/* no stream methods on this drive */
    121  1.90    bouyer #define ATA_DRIVE_ATAPIDSCW	0x0080	/* needs to wait for DSC in phase_complete */
    122  1.90    bouyer 
    123  1.90    bouyer 	uint8_t drive_type;
    124  1.90    bouyer #define	ATA_DRIVET_NONE		0
    125  1.90    bouyer #define	ATA_DRIVET_ATA		1
    126  1.90    bouyer #define	ATA_DRIVET_ATAPI	2
    127  1.90    bouyer #define	ATA_DRIVET_OLD		3
    128  1.90    bouyer #define	ATA_DRIVET_PM		4
    129  1.31   thorpej 
    130  1.31   thorpej 	/*
    131  1.31   thorpej 	 * Current setting of drive's PIO, DMA and UDMA modes.
    132  1.31   thorpej 	 * Is initialised by the disks drivers at attach time, and may be
    133  1.31   thorpej 	 * changed later by the controller's code if needed
    134  1.31   thorpej 	 */
    135  1.31   thorpej 	u_int8_t PIO_mode;	/* Current setting of drive's PIO mode */
    136  1.73     itohy #if NATA_DMA
    137  1.31   thorpej 	u_int8_t DMA_mode;	/* Current setting of drive's DMA mode */
    138  1.73     itohy #if NATA_UDMA
    139  1.31   thorpej 	u_int8_t UDMA_mode;	/* Current setting of drive's UDMA mode */
    140  1.73     itohy #endif
    141  1.73     itohy #endif
    142  1.31   thorpej 
    143  1.31   thorpej 	/* Supported modes for this drive */
    144  1.31   thorpej 	u_int8_t PIO_cap;	/* supported drive's PIO mode */
    145  1.73     itohy #if NATA_DMA
    146  1.31   thorpej 	u_int8_t DMA_cap;	/* supported drive's DMA mode */
    147  1.73     itohy #if NATA_UDMA
    148  1.31   thorpej 	u_int8_t UDMA_cap;	/* supported drive's UDMA mode */
    149  1.73     itohy #endif
    150  1.73     itohy #endif
    151  1.31   thorpej 
    152  1.31   thorpej 	/*
    153  1.31   thorpej 	 * Drive state.
    154  1.31   thorpej 	 * This is reset to 0 after a channel reset.
    155  1.31   thorpej 	 */
    156  1.31   thorpej 	u_int8_t state;
    157  1.31   thorpej 
    158  1.16    bouyer #define RESET          0
    159  1.29    bouyer #define READY          1
    160   1.2    bouyer 
    161  1.73     itohy #if NATA_DMA
    162  1.31   thorpej 	/* numbers of xfers and DMA errs. Used by ata_dmaerr() */
    163  1.31   thorpej 	u_int8_t n_dmaerrs;
    164  1.31   thorpej 	u_int32_t n_xfers;
    165  1.31   thorpej 
    166  1.31   thorpej 	/* Downgrade after NERRS_MAX errors in at most NXFER xfers */
    167  1.15    bouyer #define NERRS_MAX 4
    168  1.15    bouyer #define NXFER 4000
    169  1.73     itohy #endif
    170  1.35   thorpej 
    171  1.35   thorpej 	/* Callbacks into the drive's driver. */
    172  1.35   thorpej 	void	(*drv_done)(void *);	/* transfer is done */
    173   1.9    bouyer 
    174  1.76      cube 	device_t drv_softc;	/* ATA drives softc, if any */
    175  1.31   thorpej 	void *chnl_softc;		/* channel softc */
    176   1.2    bouyer };
    177   1.2    bouyer 
    178   1.7    bouyer /* User config flags that force (or disable) the use of a mode */
    179   1.7    bouyer #define ATA_CONFIG_PIO_MODES	0x0007
    180   1.7    bouyer #define ATA_CONFIG_PIO_SET	0x0008
    181   1.7    bouyer #define ATA_CONFIG_PIO_OFF	0
    182   1.7    bouyer #define ATA_CONFIG_DMA_MODES	0x0070
    183   1.7    bouyer #define ATA_CONFIG_DMA_SET	0x0080
    184   1.7    bouyer #define ATA_CONFIG_DMA_DISABLE	0x0070
    185   1.7    bouyer #define ATA_CONFIG_DMA_OFF	4
    186   1.7    bouyer #define ATA_CONFIG_UDMA_MODES	0x0700
    187   1.7    bouyer #define ATA_CONFIG_UDMA_SET	0x0800
    188   1.7    bouyer #define ATA_CONFIG_UDMA_DISABLE	0x0700
    189   1.7    bouyer #define ATA_CONFIG_UDMA_OFF	8
    190  1.32   thorpej 
    191  1.32   thorpej /*
    192  1.32   thorpej  * Parameters/state needed by the controller to perform an ATA bio.
    193  1.32   thorpej  */
    194  1.32   thorpej struct ata_bio {
    195  1.32   thorpej 	volatile u_int16_t flags;/* cmd flags */
    196  1.91    bouyer /* 			0x0001	free, was ATA_NOSLEEP */
    197  1.32   thorpej #define	ATA_POLL	0x0002	/* poll for completion */
    198  1.32   thorpej #define	ATA_ITSDONE	0x0004	/* the transfer is as done as it gets */
    199  1.32   thorpej #define	ATA_SINGLE	0x0008	/* transfer must be done in singlesector mode */
    200  1.32   thorpej #define	ATA_LBA		0x0010	/* transfer uses LBA addressing */
    201  1.32   thorpej #define	ATA_READ	0x0020	/* transfer is a read (otherwise a write) */
    202  1.32   thorpej #define	ATA_CORR	0x0040	/* transfer had a corrected error */
    203  1.32   thorpej #define	ATA_LBA48	0x0080	/* transfer uses 48-bit LBA addressing */
    204  1.32   thorpej 	int		multi;	/* # of blocks to transfer in multi-mode */
    205  1.32   thorpej 	struct disklabel *lp;	/* pointer to drive's label info */
    206  1.32   thorpej 	daddr_t		blkno;	/* block addr */
    207  1.32   thorpej 	daddr_t		blkdone;/* number of blks transferred */
    208  1.32   thorpej 	daddr_t		nblks;	/* number of block currently transferring */
    209  1.32   thorpej 	int		nbytes;	/* number of bytes currently transferring */
    210  1.32   thorpej 	long		bcount;	/* total number of bytes */
    211  1.32   thorpej 	char		*databuf;/* data buffer address */
    212  1.32   thorpej 	volatile int	error;
    213  1.32   thorpej #define	NOERROR 	0	/* There was no error (r_error invalid) */
    214  1.32   thorpej #define	ERROR		1	/* check r_error */
    215  1.32   thorpej #define	ERR_DF		2	/* Drive fault */
    216  1.32   thorpej #define	ERR_DMA		3	/* DMA error */
    217  1.32   thorpej #define	TIMEOUT		4	/* device timed out */
    218  1.32   thorpej #define	ERR_NODEV	5	/* device has been gone */
    219  1.44    bouyer #define ERR_RESET	6	/* command was terminated by channel reset */
    220  1.32   thorpej 	u_int8_t	r_error;/* copy of error register */
    221  1.32   thorpej 	daddr_t		badsect[127];/* 126 plus trailing -1 marker */
    222  1.32   thorpej };
    223   1.2    bouyer 
    224   1.2    bouyer /*
    225  1.67     perry  * ATA/ATAPI commands description
    226   1.2    bouyer  *
    227   1.2    bouyer  * This structure defines the interface between the ATA/ATAPI device driver
    228   1.2    bouyer  * and the controller for short commands. It contains the command's parameter,
    229  1.83  jakllsch  * the length of data to read/write (if any), and a function to call upon
    230   1.2    bouyer  * completion.
    231   1.2    bouyer  * If no sleep is allowed, the driver can poll for command completion.
    232  1.83  jakllsch  * Once the command completed, if the error registered is valid, the flag
    233   1.2    bouyer  * AT_ERROR is set and the error register value is copied to r_error .
    234   1.2    bouyer  * A separate interface is needed for read/write or ATAPI packet commands
    235   1.2    bouyer  * (which need multiple interrupts per commands).
    236   1.2    bouyer  */
    237  1.49   thorpej struct ata_command {
    238  1.84  jakllsch 	/* ATA parameters */
    239  1.84  jakllsch 	uint64_t r_lba;		/* before & after */
    240  1.84  jakllsch 	uint16_t r_count;	/* before & after */
    241  1.84  jakllsch 	union {
    242  1.84  jakllsch 		uint16_t r_features; /* before */
    243  1.84  jakllsch 		uint8_t r_error; /* after */
    244  1.84  jakllsch 	};
    245  1.84  jakllsch 	union {
    246  1.84  jakllsch 		uint8_t r_command; /* before */
    247  1.84  jakllsch 		uint8_t r_status; /* after */
    248  1.84  jakllsch 	};
    249  1.84  jakllsch 	uint8_t r_device;	/* before & after */
    250  1.84  jakllsch 
    251  1.84  jakllsch 	uint8_t r_st_bmask;	/* status register mask to wait for before
    252  1.31   thorpej 				   command */
    253  1.84  jakllsch 	uint8_t r_st_pmask;	/* status register mask to wait for after
    254  1.31   thorpej 				   command */
    255  1.84  jakllsch 	volatile uint16_t flags;
    256  1.31   thorpej 
    257   1.2    bouyer #define AT_READ     0x0001 /* There is data to read */
    258   1.2    bouyer #define AT_WRITE    0x0002 /* There is data to write (excl. with AT_READ) */
    259   1.2    bouyer #define AT_WAIT     0x0008 /* wait in controller code for command completion */
    260   1.2    bouyer #define AT_POLL     0x0010 /* poll for command completion (no interrupts) */
    261   1.2    bouyer #define AT_DONE     0x0020 /* command is done */
    262  1.24    bouyer #define AT_XFDONE   0x0040 /* data xfer is done */
    263  1.24    bouyer #define AT_ERROR    0x0080 /* command is done with error */
    264  1.24    bouyer #define AT_TIMEOU   0x0100 /* command timed out */
    265  1.24    bouyer #define AT_DF       0x0200 /* Drive fault */
    266  1.44    bouyer #define AT_RESET    0x0400 /* command terminated by channel reset */
    267  1.44    bouyer #define AT_GONE     0x0800 /* command terminated because device is gone */
    268  1.44    bouyer #define AT_READREG  0x1000 /* Read registers on completion */
    269  1.84  jakllsch #define AT_LBA      0x2000 /* LBA28 */
    270  1.84  jakllsch #define AT_LBA48    0x4000 /* LBA48 */
    271  1.31   thorpej 
    272  1.31   thorpej 	int timeout;		/* timeout (in ms) */
    273  1.31   thorpej 	void *data;		/* Data buffer address */
    274  1.31   thorpej 	int bcount;		/* number of bytes to transfer */
    275  1.31   thorpej 	void (*callback)(void *); /* command to call once command completed */
    276  1.31   thorpej 	void *callback_arg;	/* argument passed to *callback() */
    277   1.2    bouyer };
    278  1.33   thorpej 
    279  1.33   thorpej /*
    280  1.33   thorpej  * ata_bustype.  The first field must be compatible with scsipi_bustype,
    281  1.33   thorpej  * as it's used for autoconfig by both ata and atapi drivers.
    282  1.33   thorpej  */
    283  1.33   thorpej struct ata_bustype {
    284  1.33   thorpej 	int	bustype_type;	/* symbolic name of type */
    285  1.33   thorpej 	int	(*ata_bio)(struct ata_drive_datas *, struct ata_bio *);
    286  1.90    bouyer 	void	(*ata_reset_drive)(struct ata_drive_datas *, int, uint32_t *);
    287  1.64   thorpej 	void	(*ata_reset_channel)(struct ata_channel *, int);
    288  1.64   thorpej /* extra flags for ata_reset_*(), in addition to AT_* */
    289  1.44    bouyer #define AT_RST_EMERG 0x10000 /* emergency - e.g. for a dump */
    290  1.44    bouyer #define	AT_RST_NOCMD 0x20000 /* XXX has to go - temporary until we have tagged queuing */
    291  1.44    bouyer 
    292  1.33   thorpej 	int	(*ata_exec_command)(struct ata_drive_datas *,
    293  1.49   thorpej 				    struct ata_command *);
    294  1.33   thorpej 
    295  1.50   thorpej #define	ATACMD_COMPLETE		0x01
    296  1.50   thorpej #define	ATACMD_QUEUED		0x02
    297  1.50   thorpej #define	ATACMD_TRY_AGAIN	0x03
    298  1.33   thorpej 
    299  1.33   thorpej 	int	(*ata_get_params)(struct ata_drive_datas *, u_int8_t,
    300  1.33   thorpej 				  struct ataparams *);
    301  1.33   thorpej 	int	(*ata_addref)(struct ata_drive_datas *);
    302  1.33   thorpej 	void	(*ata_delref)(struct ata_drive_datas *);
    303  1.33   thorpej 	void	(*ata_killpending)(struct ata_drive_datas *);
    304  1.33   thorpej };
    305  1.33   thorpej 
    306  1.33   thorpej /* bustype_type */	/* XXX XXX XXX */
    307  1.33   thorpej /* #define SCSIPI_BUSTYPE_SCSI	0 */
    308  1.33   thorpej /* #define SCSIPI_BUSTYPE_ATAPI	1 */
    309  1.33   thorpej #define	SCSIPI_BUSTYPE_ATA	2
    310  1.34   thorpej 
    311  1.34   thorpej /*
    312  1.34   thorpej  * Describe an ATA device.  Has to be compatible with scsipi_channel, so
    313  1.34   thorpej  * start with a pointer to ata_bustype.
    314  1.34   thorpej  */
    315  1.34   thorpej struct ata_device {
    316  1.34   thorpej 	const struct ata_bustype *adev_bustype;
    317  1.34   thorpej 	int adev_channel;
    318  1.34   thorpej 	int adev_openings;
    319  1.34   thorpej 	struct ata_drive_datas *adev_drv_data;
    320  1.34   thorpej };
    321  1.26     soren 
    322  1.59   thorpej /*
    323  1.59   thorpej  * Per-channel data
    324  1.59   thorpej  */
    325  1.59   thorpej struct ata_channel {
    326  1.59   thorpej 	struct callout ch_callout;	/* callout handle */
    327  1.59   thorpej 	int ch_channel;			/* location */
    328  1.60   thorpej 	struct atac_softc *ch_atac;	/* ATA controller softc */
    329  1.59   thorpej 
    330  1.59   thorpej 	/* Our state */
    331  1.59   thorpej 	volatile int ch_flags;
    332  1.59   thorpej #define ATACH_SHUTDOWN 0x02	/* channel is shutting down */
    333  1.59   thorpej #define ATACH_IRQ_WAIT 0x10	/* controller is waiting for irq */
    334  1.59   thorpej #define ATACH_DMA_WAIT 0x20	/* controller is waiting for DMA */
    335  1.72     itohy #define ATACH_PIOBM_WAIT 0x40	/* controller is waiting for busmastering PIO */
    336  1.59   thorpej #define	ATACH_DISABLED 0x80	/* channel is disabled */
    337  1.78    bouyer #define ATACH_TH_RUN   0x100	/* the kernel thread is working */
    338  1.59   thorpej #define ATACH_TH_RESET 0x200	/* someone ask the thread to reset */
    339  1.82  jakllsch #define ATACH_TH_RESCAN 0x400	/* rescan requested */
    340  1.59   thorpej 	u_int8_t ch_status;	/* copy of status register */
    341  1.59   thorpej 	u_int8_t ch_error;	/* copy of error register */
    342  1.59   thorpej 
    343  1.59   thorpej 	/* for the reset callback */
    344  1.59   thorpej 	int ch_reset_flags;
    345  1.59   thorpej 
    346  1.59   thorpej 	/* per-drive info */
    347  1.90    bouyer 	int ch_ndrives; /* number of entries in ch_drive[] */
    348  1.90    bouyer 	struct ata_drive_datas *ch_drive; /* array of ata_drive_datas */
    349  1.59   thorpej 
    350  1.79    cegger 	device_t atabus;	/* self */
    351  1.59   thorpej 
    352  1.59   thorpej 	/* ATAPI children */
    353  1.79    cegger 	device_t atapibus;
    354  1.59   thorpej 	struct scsipi_channel ch_atapi_channel;
    355  1.59   thorpej 
    356  1.59   thorpej 	/*
    357  1.59   thorpej 	 * Channel queues.  May be the same for all channels, if hw
    358  1.59   thorpej 	 * channels are not independent.
    359  1.59   thorpej 	 */
    360  1.59   thorpej 	struct ata_queue *ch_queue;
    361  1.59   thorpej 
    362  1.59   thorpej 	/* The channel kernel thread */
    363  1.74        ad 	struct lwp *ch_thread;
    364  1.90    bouyer 
    365  1.90    bouyer 	/* Number of sata PMP ports, if any */
    366  1.90    bouyer 	int ch_satapmp_nports;
    367  1.59   thorpej };
    368  1.59   thorpej 
    369  1.60   thorpej /*
    370  1.60   thorpej  * ATA controller softc.
    371  1.60   thorpej  *
    372  1.60   thorpej  * This contains a bunch of generic info that all ATA controllers need
    373  1.60   thorpej  * to have.
    374  1.60   thorpej  *
    375  1.60   thorpej  * XXX There is still some lingering wdc-centricity here.
    376  1.60   thorpej  */
    377  1.60   thorpej struct atac_softc {
    378  1.76      cube 	device_t atac_dev;		/* generic device info */
    379  1.60   thorpej 
    380  1.60   thorpej 	int	atac_cap;		/* controller capabilities */
    381  1.60   thorpej 
    382  1.60   thorpej #define	ATAC_CAP_DATA16	0x0001		/* can do 16-bit data access */
    383  1.60   thorpej #define	ATAC_CAP_DATA32	0x0002		/* can do 32-bit data access */
    384  1.60   thorpej #define	ATAC_CAP_DMA	0x0008		/* can do ATA DMA modes */
    385  1.60   thorpej #define	ATAC_CAP_UDMA	0x0010		/* can do ATA Ultra DMA modes */
    386  1.72     itohy #define	ATAC_CAP_PIOBM	0x0020		/* can do busmastering PIO transfer */
    387  1.60   thorpej #define	ATAC_CAP_ATA_NOSTREAM 0x0040	/* don't use stream funcs on ATA */
    388  1.60   thorpej #define	ATAC_CAP_ATAPI_NOSTREAM 0x0080	/* don't use stream funcs on ATAPI */
    389  1.60   thorpej #define	ATAC_CAP_NOIRQ	0x1000		/* controller never interrupts */
    390  1.60   thorpej #define	ATAC_CAP_RAID	0x4000		/* controller "supports" RAID */
    391  1.60   thorpej 
    392  1.60   thorpej 	uint8_t	atac_pio_cap;		/* highest PIO mode supported */
    393  1.73     itohy #if NATA_DMA
    394  1.60   thorpej 	uint8_t	atac_dma_cap;		/* highest DMA mode supported */
    395  1.73     itohy #if NATA_UDMA
    396  1.60   thorpej 	uint8_t	atac_udma_cap;		/* highest UDMA mode supported */
    397  1.73     itohy #endif
    398  1.73     itohy #endif
    399  1.60   thorpej 
    400  1.60   thorpej 	/* Array of pointers to channel-specific data. */
    401  1.60   thorpej 	struct ata_channel **atac_channels;
    402  1.60   thorpej 	int		     atac_nchannels;
    403  1.60   thorpej 
    404  1.62   thorpej 	const struct ata_bustype *atac_bustype_ata;
    405  1.62   thorpej 
    406  1.60   thorpej 	/*
    407  1.60   thorpej 	 * Glue between ATA and SCSIPI for the benefit of ATAPI.
    408  1.60   thorpej 	 *
    409  1.60   thorpej 	 * Note: The reference count here is used for both ATA and ATAPI
    410  1.60   thorpej 	 * devices.
    411  1.60   thorpej 	 */
    412  1.60   thorpej 	struct atapi_adapter atac_atapi_adapter;
    413  1.62   thorpej 	void (*atac_atapibus_attach)(struct atabus_softc *);
    414  1.60   thorpej 
    415  1.60   thorpej 	/* Driver callback to probe for drives. */
    416  1.60   thorpej 	void (*atac_probe)(struct ata_channel *);
    417  1.60   thorpej 
    418  1.60   thorpej 	/* Optional callbacks to lock/unlock hardware. */
    419  1.60   thorpej 	int  (*atac_claim_hw)(struct ata_channel *, int);
    420  1.60   thorpej 	void (*atac_free_hw)(struct ata_channel *);
    421  1.60   thorpej 
    422  1.60   thorpej 	/*
    423  1.60   thorpej 	 * Optional callbacks to set drive mode.  Required for anything
    424  1.60   thorpej 	 * but basic PIO operation.
    425  1.60   thorpej 	 */
    426  1.60   thorpej 	void (*atac_set_modes)(struct ata_channel *);
    427  1.60   thorpej };
    428  1.60   thorpej 
    429  1.36       lha #ifdef _KERNEL
    430  1.63   thorpej void	ata_channel_attach(struct ata_channel *);
    431  1.37   thorpej int	atabusprint(void *aux, const char *);
    432  1.37   thorpej int	ataprint(void *aux, const char *);
    433  1.36       lha 
    434  1.90    bouyer int	atabus_alloc_drives(struct ata_channel *, int);
    435  1.90    bouyer void	atabus_free_drives(struct ata_channel *);
    436  1.90    bouyer 
    437   1.2    bouyer struct ataparams;
    438  1.30   thorpej int	ata_get_params(struct ata_drive_datas *, u_int8_t, struct ataparams *);
    439  1.30   thorpej int	ata_set_mode(struct ata_drive_datas *, u_int8_t, u_int8_t);
    440   1.2    bouyer /* return code for these cmds */
    441   1.2    bouyer #define CMD_OK    0
    442   1.2    bouyer #define CMD_ERR   1
    443   1.2    bouyer #define CMD_AGAIN 2
    444  1.10    bouyer 
    445  1.54   thorpej struct ata_xfer *ata_get_xfer(int);
    446  1.59   thorpej void	ata_free_xfer(struct ata_channel *, struct ata_xfer *);
    447  1.54   thorpej #define	ATAXF_CANSLEEP	0x00
    448  1.54   thorpej #define	ATAXF_NOSLEEP	0x01
    449  1.54   thorpej 
    450  1.59   thorpej void	ata_exec_xfer(struct ata_channel *, struct ata_xfer *);
    451  1.55   thorpej void	ata_kill_pending(struct ata_drive_datas *);
    452  1.64   thorpej void	ata_reset_channel(struct ata_channel *, int);
    453  1.55   thorpej 
    454  1.59   thorpej int	ata_addref(struct ata_channel *);
    455  1.59   thorpej void	ata_delref(struct ata_channel *);
    456  1.59   thorpej void	atastart(struct ata_channel *);
    457  1.59   thorpej void	ata_print_modes(struct ata_channel *);
    458  1.73     itohy #if NATA_DMA
    459  1.52   thorpej int	ata_downgrade_mode(struct ata_drive_datas *, int);
    460  1.73     itohy #endif
    461  1.53   thorpej void	ata_probe_caps(struct ata_drive_datas *);
    462  1.51   thorpej 
    463  1.73     itohy #if NATA_DMA
    464  1.30   thorpej void	ata_dmaerr(struct ata_drive_datas *, int);
    465  1.73     itohy #endif
    466  1.68    bouyer void	ata_queue_idle(struct ata_queue *);
    467  1.91    bouyer void	ata_delay(int, const char *, int);
    468  1.37   thorpej #endif /* _KERNEL */
    469  1.31   thorpej 
    470  1.31   thorpej #endif /* _DEV_ATA_ATAVAR_H_ */
    471