atavar.h revision 1.28 1 1.28 bouyer /* $NetBSD: atavar.h,v 1.28 2003/10/05 17:48:49 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 * 3. All advertising materials mentioning features or use of this software
15 1.2 bouyer * must display the following acknowledgement:
16 1.25 bouyer * This product includes software developed by Manuel Bouyer.
17 1.28 bouyer * 4. The name of the author may not be used to endorse or promote products
18 1.28 bouyer * derived from this software without specific prior written permission.
19 1.2 bouyer *
20 1.18 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.18 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.18 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.18 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.18 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.18 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.18 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.18 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.18 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.18 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.2 bouyer *
31 1.2 bouyer */
32 1.2 bouyer
33 1.2 bouyer /* Hight-level functions and structures used by both ATA and ATAPI devices */
34 1.2 bouyer
35 1.2 bouyer /* Datas common to drives and controller drivers */
36 1.2 bouyer struct ata_drive_datas {
37 1.2 bouyer u_int8_t drive; /* drive number */
38 1.10 bouyer int8_t ata_vers; /* ATA version supported */
39 1.7 bouyer u_int16_t drive_flags; /* bitmask for drives present/absent and cap */
40 1.13 bouyer #define DRIVE_ATA 0x0001
41 1.13 bouyer #define DRIVE_ATAPI 0x0002
42 1.13 bouyer #define DRIVE_OLD 0x0004
43 1.13 bouyer #define DRIVE (DRIVE_ATA|DRIVE_ATAPI|DRIVE_OLD)
44 1.13 bouyer #define DRIVE_CAP32 0x0008
45 1.13 bouyer #define DRIVE_DMA 0x0010
46 1.13 bouyer #define DRIVE_UDMA 0x0020
47 1.13 bouyer #define DRIVE_MODE 0x0040 /* the drive reported its mode */
48 1.13 bouyer #define DRIVE_RESET 0x0080 /* reset the drive state at next xfer */
49 1.13 bouyer #define DRIVE_DMAERR 0x0100 /* Udma transfer had crc error, don't try DMA */
50 1.20 bouyer #define DRIVE_ATAPIST 0x0100 /* device is an ATAPI tape drive */
51 1.2 bouyer /*
52 1.2 bouyer * Current setting of drive's PIO, DMA and UDMA modes.
53 1.2 bouyer * Is initialised by the disks drivers at attach time, and may be
54 1.2 bouyer * changed later by the controller's code if needed
55 1.2 bouyer */
56 1.2 bouyer u_int8_t PIO_mode; /* Current setting of drive's PIO mode */
57 1.2 bouyer u_int8_t DMA_mode; /* Current setting of drive's DMA mode */
58 1.2 bouyer u_int8_t UDMA_mode; /* Current setting of drive's UDMA mode */
59 1.7 bouyer /* Supported modes for this drive */
60 1.7 bouyer u_int8_t PIO_cap; /* supported drive's PIO mode */
61 1.7 bouyer u_int8_t DMA_cap; /* supported drive's DMA mode */
62 1.7 bouyer u_int8_t UDMA_cap; /* supported drive's UDMA mode */
63 1.2 bouyer /*
64 1.16 bouyer * Drive state.
65 1.2 bouyer * This is reset to 0 after a channel reset.
66 1.2 bouyer */
67 1.2 bouyer u_int8_t state;
68 1.16 bouyer #define RESET 0
69 1.16 bouyer #define RECAL 1
70 1.16 bouyer #define RECAL_WAIT 2
71 1.16 bouyer #define PIOMODE 3
72 1.16 bouyer #define PIOMODE_WAIT 4
73 1.16 bouyer #define DMAMODE 5
74 1.16 bouyer #define DMAMODE_WAIT 6
75 1.16 bouyer #define GEOMETRY 7
76 1.16 bouyer #define GEOMETRY_WAIT 8
77 1.16 bouyer #define MULTIMODE 9
78 1.16 bouyer #define MULTIMODE_WAIT 10
79 1.16 bouyer #define READY 11
80 1.2 bouyer
81 1.15 bouyer /* numbers of xfers and DMA errs. Used by ata_dmaerr() */
82 1.9 bouyer u_int8_t n_dmaerrs;
83 1.15 bouyer u_int32_t n_xfers;
84 1.15 bouyer /* Downgrade after NERRS_MAX errors in at most NXFER xfers */
85 1.15 bouyer #define NERRS_MAX 4
86 1.15 bouyer #define NXFER 4000
87 1.9 bouyer
88 1.2 bouyer struct device *drv_softc; /* ATA drives softc, if any */
89 1.27 itojun void *chnl_softc; /* channel softc */
90 1.2 bouyer };
91 1.2 bouyer
92 1.7 bouyer /* User config flags that force (or disable) the use of a mode */
93 1.7 bouyer #define ATA_CONFIG_PIO_MODES 0x0007
94 1.7 bouyer #define ATA_CONFIG_PIO_SET 0x0008
95 1.7 bouyer #define ATA_CONFIG_PIO_OFF 0
96 1.7 bouyer #define ATA_CONFIG_DMA_MODES 0x0070
97 1.7 bouyer #define ATA_CONFIG_DMA_SET 0x0080
98 1.7 bouyer #define ATA_CONFIG_DMA_DISABLE 0x0070
99 1.7 bouyer #define ATA_CONFIG_DMA_OFF 4
100 1.7 bouyer #define ATA_CONFIG_UDMA_MODES 0x0700
101 1.7 bouyer #define ATA_CONFIG_UDMA_SET 0x0800
102 1.7 bouyer #define ATA_CONFIG_UDMA_DISABLE 0x0700
103 1.7 bouyer #define ATA_CONFIG_UDMA_OFF 8
104 1.2 bouyer
105 1.2 bouyer /*
106 1.2 bouyer * ATA/ATAPI commands description
107 1.2 bouyer *
108 1.2 bouyer * This structure defines the interface between the ATA/ATAPI device driver
109 1.2 bouyer * and the controller for short commands. It contains the command's parameter,
110 1.2 bouyer * the len of data's to read/write (if any), and a function to call upon
111 1.2 bouyer * completion.
112 1.2 bouyer * If no sleep is allowed, the driver can poll for command completion.
113 1.2 bouyer * Once the command completed, if the error registed is valid, the flag
114 1.2 bouyer * AT_ERROR is set and the error register value is copied to r_error .
115 1.2 bouyer * A separate interface is needed for read/write or ATAPI packet commands
116 1.2 bouyer * (which need multiple interrupts per commands).
117 1.2 bouyer */
118 1.2 bouyer struct wdc_command {
119 1.2 bouyer u_int8_t r_command; /* Parameters to upload to registers */
120 1.2 bouyer u_int8_t r_head;
121 1.2 bouyer u_int16_t r_cyl;
122 1.2 bouyer u_int8_t r_sector;
123 1.2 bouyer u_int8_t r_count;
124 1.2 bouyer u_int8_t r_precomp;
125 1.2 bouyer u_int8_t r_st_bmask; /* status register mask to wait for before command */
126 1.2 bouyer u_int8_t r_st_pmask; /* status register mask to wait for after command */
127 1.2 bouyer u_int8_t r_error; /* error register after command done */
128 1.2 bouyer volatile u_int16_t flags;
129 1.2 bouyer #define AT_READ 0x0001 /* There is data to read */
130 1.2 bouyer #define AT_WRITE 0x0002 /* There is data to write (excl. with AT_READ) */
131 1.2 bouyer #define AT_WAIT 0x0008 /* wait in controller code for command completion */
132 1.2 bouyer #define AT_POLL 0x0010 /* poll for command completion (no interrupts) */
133 1.2 bouyer #define AT_DONE 0x0020 /* command is done */
134 1.24 bouyer #define AT_XFDONE 0x0040 /* data xfer is done */
135 1.24 bouyer #define AT_ERROR 0x0080 /* command is done with error */
136 1.24 bouyer #define AT_TIMEOU 0x0100 /* command timed out */
137 1.24 bouyer #define AT_DF 0x0200 /* Drive fault */
138 1.24 bouyer #define AT_READREG 0x0400 /* Read registers on completion */
139 1.2 bouyer int timeout; /* timeout (in ms) */
140 1.2 bouyer void *data; /* Data buffer address */
141 1.2 bouyer int bcount; /* number of bytes to transfer */
142 1.27 itojun void (*callback) __P((void *)); /* command to call once command completed */
143 1.2 bouyer void *callback_arg; /* argument passed to *callback() */
144 1.2 bouyer };
145 1.26 soren
146 1.26 soren /*
147 1.26 soren * If WDSM_ATTR_ADVISORY, device exceeded intended design life period.
148 1.26 soren * If not WDSM_ATTR_ADVISORY, imminent data loss predicted.
149 1.26 soren */
150 1.26 soren #define WDSM_ATTR_ADVISORY 1
151 1.26 soren /*
152 1.26 soren * If WDSM_ATTR_COLLECTIVE, attribute only updated in off-line testing.
153 1.26 soren * If not WDSM_ATTR_COLLECTIVE, attribute updated also in on-line testing.
154 1.26 soren */
155 1.26 soren #define WDSM_ATTR_COLLECTIVE 2
156 1.26 soren
157 1.26 soren struct ata_smart_attr {
158 1.26 soren u_int8_t id; /* attribute id number */
159 1.26 soren u_int16_t flags;
160 1.26 soren u_int8_t value; /* attribute value */
161 1.26 soren u_int8_t vendor_specific[8];
162 1.26 soren } __attribute__((packed));
163 1.26 soren
164 1.26 soren struct ata_smart_attributes {
165 1.26 soren u_int16_t data_structure_revision;
166 1.26 soren struct ata_smart_attr attributes[30];
167 1.26 soren u_int8_t offline_data_collection_status;
168 1.26 soren u_int8_t self_test_exec_status;
169 1.26 soren u_int16_t total_time_to_complete_off_line;
170 1.26 soren u_int8_t vendor_specific_366;
171 1.26 soren u_int8_t offline_data_collection_capability;
172 1.26 soren u_int16_t smart_capability;
173 1.26 soren u_int8_t errorlog_capability;
174 1.26 soren u_int8_t vendor_specific_371;
175 1.26 soren u_int8_t short_test_completion_time;
176 1.26 soren u_int8_t extend_test_completion_time;
177 1.26 soren u_int8_t reserved_374_385[12];
178 1.26 soren u_int8_t vendor_specific_386_509[125];
179 1.26 soren int8_t checksum;
180 1.26 soren } __attribute__((packed));
181 1.26 soren
182 1.26 soren struct ata_smart_thresh {
183 1.26 soren u_int8_t id;
184 1.26 soren u_int8_t value;
185 1.26 soren u_int8_t reserved[10];
186 1.26 soren } __attribute__((packed));
187 1.26 soren
188 1.26 soren struct ata_smart_thresholds {
189 1.26 soren u_int16_t data_structure_revision;
190 1.26 soren struct ata_smart_thresh thresholds[30];
191 1.26 soren u_int8_t reserved[18];
192 1.26 soren u_int8_t vendor_specific[131];
193 1.26 soren int8_t checksum;
194 1.26 soren } __attribute__((packed));
195 1.2 bouyer
196 1.27 itojun int wdc_downgrade_mode __P((struct ata_drive_datas *));
197 1.2 bouyer
198 1.2 bouyer struct ataparams;
199 1.27 itojun int ata_get_params __P((struct ata_drive_datas *, u_int8_t,
200 1.2 bouyer struct ataparams *));
201 1.27 itojun int ata_set_mode __P((struct ata_drive_datas *, u_int8_t, u_int8_t));
202 1.2 bouyer /* return code for these cmds */
203 1.2 bouyer #define CMD_OK 0
204 1.2 bouyer #define CMD_ERR 1
205 1.2 bouyer #define CMD_AGAIN 2
206 1.10 bouyer
207 1.15 bouyer void ata_dmaerr __P((struct ata_drive_datas *));
208