xref: /illumos-gate/usr/src/uts/common/sys/sata/sata_defs.h (revision 2caf0dcd2abc26b477e317999994020212790d38)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SATA_DEFS_H
28 #define	_SATA_DEFS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Common ATA commands (subset)
38  */
39 #define	SATAC_DIAG		0x90    /* diagnose command */
40 #define	SATAC_RECAL		0x10	/* restore cmd, 4 bits step rate */
41 #define	SATAC_FORMAT		0x50	/* format track command */
42 #define	SATAC_SET_FEATURES	0xef	/* set features	*/
43 #define	SATAC_IDLE_IM		0xe1	/* idle immediate */
44 #define	SATAC_STANDBY_IM	0xe0	/* standby immediate */
45 #define	SATAC_DOOR_LOCK		0xde	/* door lock */
46 #define	SATAC_DOOR_UNLOCK	0xdf	/* door unlock */
47 #define	SATAC_IDLE		0xe3	/* idle	*/
48 
49 /*
50  * ATA/ATAPI disk commands (subset)
51  */
52 #define	SATAC_DEVICE_RESET	0x08    /* ATAPI device reset */
53 #define	SATAC_EJECT		0xed	/* media eject */
54 #define	SATAC_FLUSH_CACHE	0xe7	/* flush write-cache */
55 #define	SATAC_ID_DEVICE		0xec    /* IDENTIFY DEVICE */
56 #define	SATAC_ID_PACKET_DEVICE	0xa1	/* ATAPI identify packet device */
57 #define	SATAC_INIT_DEVPARMS	0x91	/* initialize device parameters */
58 #define	SATAC_PACKET		0xa0	/* ATAPI packet */
59 #define	SATAC_RDMULT		0xc4	/* read multiple w/DMA */
60 #define	SATAC_RDSEC		0x20    /* read sector */
61 #define	SATAC_RDVER		0x40	/* read verify */
62 #define	SATAC_READ_DMA		0xc8	/* read DMA */
63 #define	SATAC_SEEK		0x70    /* seek */
64 #define	SATAC_SERVICE		0xa2	/* queued/overlap service */
65 #define	SATAC_SETMULT		0xc6	/* set multiple mode */
66 #define	SATAC_WRITE_DMA		0xca	/* write (multiple) w/DMA */
67 #define	SATAC_WRMULT		0xc5	/* write multiple */
68 #define	SATAC_WRSEC		0x30    /* write sector */
69 #define	SATAC_RDSEC_EXT		0x24    /* read sector extended (LBA48) */
70 #define	SATAC_READ_DMA_EXT	0x25	/* read DMA extended (LBA48) */
71 #define	SATAC_RDMULT_EXT	0x29	/* read multiple extended (LBA48) */
72 #define	SATAC_WRSEC_EXT		0x34    /* read sector extended (LBA48) */
73 #define	SATAC_WRITE_DMA_EXT	0x35	/* read DMA extended (LBA48) */
74 #define	SATAC_WRMULT_EXT	0x39	/* read multiple extended (LBA48) */
75 
76 #define	SATAC_READ_DMA_QUEUED	0xc7	/* read DMA / may be queued */
77 #define	SATAC_READ_DMA_QUEUED_EXT 0x26	/* read DMA ext / may be queued */
78 #define	SATAC_WRITE_DMA_QUEUED	0xcc	/* read DMA / may be queued */
79 #define	SATAC_WRITE_DMA_QUEUED_EXT 0x36	/* read DMA ext / may be queued */
80 #define	SATAC_READ_PM_REG	0xe4	/* read port mult reg */
81 #define	SATAC_WRITE_PM_REG	0xe8	/* write port mult reg */
82 
83 #define	SATAC_READ_FPDMA_QUEUED	0x60	/* First-Party-DMA read queued */
84 #define	SATAC_WRITE_FPDMA_QUEUED 0x61	/* First-Party-DMA write queued */
85 
86 #define	SATAC_READ_LOG_EXT	0x2f	/* read log */
87 #define	SATA_LOG_PAGE_10	0x10	/* log page 0x10 - SATA error */
88 /*
89  * Power Managment Commands (subset)
90  */
91 #define	SATAC_CHECK_POWER_MODE	0xe5	/* check power mode */
92 
93 #define	SATA_PWRMODE_STANDBY	0	/* standby mode */
94 #define	SATA_PWRMODE_IDLE	0x80	/* idle mode */
95 #define	SATA_PWRMODE_ACTIVE	0xFF	/* active or idle mode, rev7 spec */
96 
97 
98 /*
99  * SET FEATURES Subcommands
100  */
101 #define	SATAC_SF_ENABLE_WRITE_CACHE	0x02
102 #define	SATAC_SF_TRANSFER_MODE		0x03
103 #define	SATAC_SF_DISABLE_READ_AHEAD	0x55
104 #define	SATAC_SF_DISABLE_WRITE_CACHE	0x82
105 #define	SATAC_SF_ENABLE_READ_AHEAD	0xaa
106 
107 /*
108  * SET FEATURES transfer mode values
109  */
110 #define	SATAC_TRANSFER_MODE_PIO_DEFAULT		0x00
111 #define	SATAC_TRANSFER_MODE_PIO_DISABLE_IODRY	0x01
112 #define	SATAC_TRANSFER_MODE_PIO_FLOW_CONTROL	0x08
113 #define	SATAC_TRANSFER_MODE_MULTI_WORD_DMA	0x20
114 #define	SATAC_TRANSFER_MODE_ULTRA_DMA		0x40
115 
116 /* Generic ATA definitions */
117 
118 /*
119  * Identify Device data
120  * Although bot ATA and ATAPI devices' Identify Data has the same lenght,
121  * some words have different meaning/content and/or are irrelevant for
122  * other type of device.
123  * Following is the ATA Device Identify data layout
124  */
125 typedef struct sata_id {
126 /*  					WORD				*/
127 /* 					OFFSET COMMENT			*/
128 	ushort_t  ai_config;	  /*   0  general configuration bits 	*/
129 	ushort_t  ai_fixcyls;	  /*   1  # of cylinders (obsolete)	*/
130 	ushort_t  ai_resv0;	  /*   2  # reserved			*/
131 	ushort_t  ai_heads;	  /*   3  # of heads (obsolete)		*/
132 	ushort_t  ai_trksiz;	  /*   4  # of bytes/track (retired)	*/
133 	ushort_t  ai_secsiz;	  /*   5  # of bytes/sector (retired)	*/
134 	ushort_t  ai_sectors;	  /*   6  # of sectors/track (obsolete)	*/
135 	ushort_t  ai_resv1[3];	  /*   7  "Vendor Unique"		*/
136 	char	ai_drvser[20];	  /*  10  Serial number			*/
137 	ushort_t ai_buftype;	  /*  20  Buffer type			*/
138 	ushort_t ai_bufsz;	  /*  21  Buffer size in 512 byte incr  */
139 	ushort_t ai_ecc;	  /*  22  # of ecc bytes avail on rd/wr */
140 	char	ai_fw[8];	  /*  23  Firmware revision		*/
141 	char	ai_model[40];	  /*  27  Model #			*/
142 	ushort_t ai_mult1;	  /*  47  Multiple command flags	*/
143 	ushort_t ai_dwcap;	  /*  48  Doubleword capabilities	*/
144 	ushort_t ai_cap;	  /*  49  Capabilities			*/
145 	ushort_t ai_resv2;	  /*  50  Reserved			*/
146 	ushort_t ai_piomode;	  /*  51  PIO timing mode		*/
147 	ushort_t ai_dmamode;	  /*  52  DMA timing mode		*/
148 	ushort_t ai_validinfo;	  /*  53  bit0: wds 54-58, bit1: 64-70	*/
149 	ushort_t ai_curcyls;	  /*  54  # of current cylinders	*/
150 	ushort_t ai_curheads;	  /*  55  # of current heads		*/
151 	ushort_t ai_cursectrk;	  /*  56  # of current sectors/track	*/
152 	ushort_t ai_cursccp[2];	  /*  57  current sectors capacity	*/
153 	ushort_t ai_mult2;	  /*  59  multiple sectors info		*/
154 	ushort_t ai_addrsec[2];	  /*  60  LBA only: no of addr secs	*/
155 	ushort_t ai_sworddma;	  /*  62  single word dma modes		*/
156 	ushort_t ai_dworddma;	  /*  63  double word dma modes		*/
157 	ushort_t ai_advpiomode;	  /*  64  advanced PIO modes supported	*/
158 	ushort_t ai_minmwdma;	  /*  65  min multi-word dma cycle info	*/
159 	ushort_t ai_recmwdma;	  /*  66  rec multi-word dma cycle info	*/
160 	ushort_t ai_minpio;	  /*  67  min PIO cycle info		*/
161 	ushort_t ai_minpioflow;	  /*  68  min PIO cycle info w/flow ctl */
162 	ushort_t ai_resv3[2];	  /* 69,70 reserved			*/
163 	ushort_t ai_typtime[2];	  /* 71-72 timing			*/
164 	ushort_t ai_resv4[2];	  /* 73-74 reserved			*/
165 	ushort_t ai_qdepth;	  /*  75  queue depth			*/
166 	ushort_t ai_satacap;	  /*  76  SATA capabilities		*/
167 	ushort_t ai_resv5;	  /*  77 reserved			*/
168 	ushort_t ai_satafsup;	  /*  78 SATA features supported	*/
169 	ushort_t ai_satafenbl;	  /*  79 SATA features enabled		*/
170 	ushort_t ai_majorversion; /*  80  major versions supported	*/
171 	ushort_t ai_minorversion; /*  81  minor version number supported */
172 	ushort_t ai_cmdset82;	  /*  82  command set supported		*/
173 	ushort_t ai_cmdset83;	  /*  83  more command sets supported	*/
174 	ushort_t ai_cmdset84;	  /*  84  more command sets supported	*/
175 	ushort_t ai_features85;	  /*  85 enabled features		*/
176 	ushort_t ai_features86;	  /*  86 enabled features		*/
177 	ushort_t ai_features87;	  /*  87 enabled features		*/
178 	ushort_t ai_ultradma;	  /*  88 Ultra DMA mode			*/
179 	ushort_t ai_erasetime;	  /*  89 security erase time		*/
180 	ushort_t ai_erasetimex;	  /*  90 enhanced security erase time	*/
181 	ushort_t ai_padding1[9];  /* pad through 99			*/
182 	ushort_t ai_addrsecxt[4]; /* 100 extended max LBA sector	*/
183 	ushort_t ai_padding2[22]; /* pad to 126				*/
184 	ushort_t ai_lastlun;	  /* 126 last LUN, as per SFF-8070i	*/
185 	ushort_t ai_resv6;	  /* 127 reserved			*/
186 	ushort_t ai_securestatus; /* 128 security status		*/
187 	ushort_t ai_vendor[31];	  /* 129-159 vendor specific		*/
188 	ushort_t ai_padding3[16]; /* 160 pad to 176			*/
189 	ushort_t ai_curmedser[30]; /* 176-205 current media serial number */
190 	ushort_t ai_padding4[49]; /* 206 pad to 255			*/
191 	ushort_t ai_integrity;	  /* 255 integrity word			*/
192 } sata_id_t;
193 
194 
195 /* Identify Device: general config bits  - word 0 */
196 
197 #define	SATA_ATA_TYPE_MASK	0x8001	/* ATA Device type mask */
198 #define	SATA_ATA_TYPE		0x0000	/* ATA device */
199 #define	SATA_REM_MEDIA  	0x0080 	/* Removable media */
200 
201 #define	SATA_ID_SERIAL_OFFSET	10
202 #define	SATA_ID_SERIAL_LEN	20
203 #define	SATA_ID_MODEL_OFFSET	27
204 #define	SATA_ID_MODEL_LEN	40
205 
206 /* Identify Device: common capability bits - word 49 */
207 
208 #define	SATA_DMA_SUPPORT	0x0100
209 #define	SATA_LBA_SUPPORT	0x0200
210 #define	SATA_IORDY_DISABLE	0x0400
211 #define	SATA_IORDY_SUPPORT	0x0800
212 #define	SATA_STANDBYTIMER	0x2000
213 
214 /* Identify Device: ai_validinfo (word 53) */
215 
216 #define	SATA_VALIDINFO_88	0x0004	/* word 88 supported fields valid */
217 
218 /* Identify Device: ai_majorversion (word 80) */
219 
220 #define	SATA_MAJVER_6		0x0040	/* ATA/ATAPI-6 version supported */
221 #define	SATA_MAJVER_4		0x0010	/* ATA/ATAPI-4 version supported */
222 
223 /* Identify Device: command set supported/enabled bits - words 83 and 86 */
224 
225 #define	SATA_EXT48		0x0400	/* 48 bit address feature */
226 #define	SATA_RW_DMA_QUEUED_CMD	0x0002	/* R/W DMA Queued supported */
227 #define	SATA_DWNLOAD_MCODE_CMD	0x0001	/* Download Microcode CMD supp/enbld */
228 
229 /* Identify Device: command set supported/enabled bits - words 82 and 85 */
230 
231 #define	SATA_WRITE_CACHE	0x0020	/* Write Cache supported/enabled */
232 #define	SATA_LOOK_AHEAD		0x0040	/* Look Ahead supported/enabled */
233 #define	SATA_DEVICE_RESET_CMD	0x0200	/* Device Reset CMD supported/enbld */
234 #define	SATA_READ_BUFFER_CMD	0x2000	/* Read Buffer CMD supported/enbld */
235 #define	SATA_WRITE_BUFFER_CMD	0x1000	/* Write Buffer CMD supported/enbld */
236 
237 #define	SATA_MDMA_SEL_MASK	0x0700	/* Multiword DMA selected */
238 #define	SATA_MDMA_2_SEL		0x0400	/* Multiword DMA mode 2 selected */
239 #define	SATA_MDMA_1_SEL		0x0200	/* Multiword DMA mode 1 selected */
240 #define	SATA_MDMA_0_SEL		0x0100	/* Multiword DMA mode 0 selected */
241 #define	SATA_MDMA_2_SUP		0x0004	/* Multiword DMA mode 2 supported */
242 #define	SATA_MDMA_1_SUP		0x0002	/* Multiword DMA mode 1 supported */
243 #define	SATA_MDMA_0_SUP		0x0001	/* Multiword DMA mode 0 supported */
244 
245 #define	SATA_DISK_SECTOR_SIZE	512	/* HD physical sector size */
246 
247 /* Identify Packet Device data definitions (ATAPI devices) */
248 
249 /* Identify Packet Device: general config bits  - word 0 */
250 
251 #define	SATA_ATAPI_TYPE_MASK	0xc000
252 #define	SATA_ATAPI_TYPE		0x8000 	/* ATAPI device */
253 #define	SATA_ATAPI_ID_PKT_SZ	0x0003 	/* Packet size mask */
254 #define	SATA_ATAPI_ID_PKT_12B	0x0000  /* Packet size 12 bytes */
255 #define	SATA_ATAPI_ID_PKT_16B	0x0001  /* Packet size 16 bytes */
256 #define	SATA_ATAPI_ID_DRQ_TYPE	0x0060 	/* DRQ asserted in 3ms after pkt */
257 #define	SATA_ATAPI_ID_DRQ_INTR	0x0020 	/* Obsolete in ATA/ATAPI 7 */
258 
259 #define	SATA_ATAPI_ID_DEV_TYPE	0x0f00	/* device type/command set mask */
260 #define	SATA_ATAPI_ID_DEV_SHFT	8
261 #define	SATA_ATAPI_DIRACC_DEV	0x0000	/* Direct Access device */
262 #define	SATA_ATAPI_SQACC_DEV	0x0100	/* Sequential access dev (tape ?) */
263 #define	SATA_ATAPI_CDROM_DEV	0x0500	/* CD_ROM device */
264 
265 /*
266  * Status bits from ATAPI Interrupt reason register (AT_COUNT) register
267  */
268 #define	SATA_ATAPI_I_COD	0x01	/* Command or Data */
269 #define	SATA_ATAPI_I_IO		0x02	/* IO direction */
270 #define	SATA_ATAPI_I_RELEASE	0x04	/* Release for ATAPI overlap */
271 
272 /* ATAPI feature reg definitions */
273 
274 #define	SATA_ATAPI_F_OVERLAP	0x02
275 
276 
277 /*
278  * ATAPI IDENTIFY_DRIVE capabilities word
279  */
280 
281 #define	SATA_ATAPI_ID_CAP_DMA		0x0100
282 #define	SATA_ATAPI_ID_CAP_OVERLAP	0x2000
283 
284 /*
285  * ATAPI signature bits
286  */
287 #define	SATA_ATAPI_SIG_HI	0xeb	/* in high cylinder register */
288 #define	SATA_ATAPI_SIG_LO	0x14	/* in low cylinder register */
289 
290 /* These values are pre-set for CD_ROM/DVD ? */
291 
292 #define	SATA_ATAPI_SECTOR_SIZE		2048
293 #define	SATA_ATAPI_MAX_BYTES_PER_DRQ	0xf800 /* 16 bits - 2KB  ie 62KB */
294 #define	SATA_ATAPI_HEADS		64
295 #define	SATA_ATAPI_SECTORS_PER_TRK	32
296 
297 /* SATA Capabilites bits (word 76) */
298 
299 #define	SATA_NCQ		0x100
300 #define	SATA_2_SPEED		0x004
301 #define	SATA_1_SPEED		0x002
302 
303 /* SATA Features Supported (word 78) - not used */
304 
305 /* SATA Features Enabled (word 79) - not used */
306 
307 /*
308  * Status bits from AT_STATUS register
309  */
310 #define	SATA_STATUS_BSY		0x80    /* controller busy */
311 #define	SATA_STATUS_DRDY	0x40    /* drive ready 	*/
312 #define	SATA_STATUS_DF		0x20    /* device fault	*/
313 #define	SATA_STATUS_DSC    	0x10    /* seek operation complete */
314 #define	SATA_STATUS_DRQ		0x08	/* data request */
315 #define	SATA_STATUS_CORR	0x04    /* obsolete */
316 #define	SATA_STATUS_IDX		0x02    /* obsolete */
317 #define	SATA_STATUS_ERR		0x01    /* error flag */
318 
319 /*
320  * Status bits from AT_ERROR register
321  */
322 #define	SATA_ERROR_ICRC		0x80	/* CRC data transfer error detected */
323 #define	SATA_ERROR_UNC		0x40	/* uncorrectable data error */
324 #define	SATA_ERROR_MC		0x20    /* Media change	*/
325 #define	SATA_ERROR_IDNF		0x10    /* ID/Address not found	*/
326 #define	SATA_ERROR_MCR		0x08	/* media change request	*/
327 #define	SATA_ERROR_ABORT	0x04    /* aborted command */
328 #define	SATA_ERROR_NM		0x02	/* no media */
329 #define	SATA_ERROR_EOM		0x02    /* end of media (Packet cmds) */
330 #define	SATA_ERROR_ILI		0x01    /* cmd sepcific */
331 
332 /* device_reg */
333 #define	SATA_ADH_LBA		0x40	/* addressing in LBA mode not chs */
334 
335 #ifdef	__cplusplus
336 }
337 #endif
338 
339 #endif /* _SATA_DEFS_H */
340