xref: /illumos-gate/usr/src/uts/common/sys/sata/sata_defs.h (revision 9fb67ea305c66b6a297583b9b0db6796b0dfe497)
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 2010 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 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/scsi/generic/mode.h>
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 #define	SATAC_STANDBY		0xe2	/* standby */
49 
50 /*
51  * ATA/ATAPI disk commands (subset)
52  */
53 #define	SATAC_DEVICE_RESET	0x08    /* ATAPI device reset */
54 #define	SATAC_DOWNLOAD_MICROCODE 0x92   /* Download microcode */
55 #define	SATAC_EJECT		0xed	/* media eject */
56 #define	SATAC_FLUSH_CACHE	0xe7	/* flush write-cache */
57 #define	SATAC_ID_DEVICE		0xec    /* IDENTIFY DEVICE */
58 #define	SATAC_ID_PACKET_DEVICE	0xa1	/* ATAPI identify packet device */
59 #define	SATAC_INIT_DEVPARMS	0x91	/* initialize device parameters */
60 #define	SATAC_PACKET		0xa0	/* ATAPI packet */
61 #define	SATAC_RDMULT		0xc4	/* read multiple w/DMA */
62 #define	SATAC_RDSEC		0x20    /* read sector */
63 #define	SATAC_RDVER		0x40	/* read verify */
64 #define	SATAC_READ_DMA		0xc8	/* read DMA */
65 #define	SATAC_SEEK		0x70    /* seek */
66 #define	SATAC_SERVICE		0xa2	/* queued/overlap service */
67 #define	SATAC_SETMULT		0xc6	/* set multiple mode */
68 #define	SATAC_WRITE_DMA		0xca	/* write (multiple) w/DMA */
69 #define	SATAC_WRMULT		0xc5	/* write multiple */
70 #define	SATAC_WRSEC		0x30    /* write sector */
71 #define	SATAC_RDSEC_EXT		0x24    /* read sector extended (LBA48) */
72 #define	SATAC_READ_DMA_EXT	0x25	/* read DMA extended (LBA48) */
73 #define	SATAC_RDMULT_EXT	0x29	/* read multiple extended (LBA48) */
74 #define	SATAC_WRSEC_EXT		0x34    /* read sector extended (LBA48) */
75 #define	SATAC_WRITE_DMA_EXT	0x35	/* read DMA extended (LBA48) */
76 #define	SATAC_WRMULT_EXT	0x39	/* read multiple extended (LBA48) */
77 
78 #define	SATAC_READ_DMA_QUEUED	0xc7	/* read DMA / may be queued */
79 #define	SATAC_READ_DMA_QUEUED_EXT 0x26	/* read DMA ext / may be queued */
80 #define	SATAC_WRITE_DMA_QUEUED	0xcc	/* read DMA / may be queued */
81 #define	SATAC_WRITE_DMA_QUEUED_EXT 0x36	/* read DMA ext / may be queued */
82 #define	SATAC_READ_PM_REG	0xe4	/* read port mult reg */
83 #define	SATAC_WRITE_PM_REG	0xe8	/* write port mult reg */
84 
85 #define	SATAC_READ_FPDMA_QUEUED	0x60	/* First-Party-DMA read queued */
86 #define	SATAC_WRITE_FPDMA_QUEUED 0x61	/* First-Party-DMA write queued */
87 
88 #define	SATAC_READ_LOG_EXT	0x2f	/* read log */
89 
90 #define	SATAC_SMART		0xb0	/* SMART */
91 
92 #define	SATA_LOG_PAGE_10	0x10	/* log page 0x10 - SATA error */
93 /*
94  * Port Multiplier Commands
95  */
96 #define	SATAC_READ_PORTMULT	0xe4	/* read port multiplier */
97 #define	SATAC_WRITE_PORTMULT	0xe8	/* write port multiplier */
98 
99 /*
100  * Power Managment Commands (subset)
101  */
102 #define	SATAC_CHECK_POWER_MODE	0xe5	/* check power mode */
103 
104 #define	SATA_PWRMODE_STANDBY		0	/* standby mode */
105 #define	SATA_PWRMODE_IDLE		0x80	/* idle mode */
106 #define	SATA_PWRMODE_ACTIVE_SPINDOWN	0x40	/* PM0 and spinning down */
107 #define	SATA_PWRMODE_ACTIVE_SPINUP	0x41	/* PM0 and spinning up */
108 #define	SATA_PWRMODE_ACTIVE		0xFF	/* active or idle mode */
109 
110 
111 /*
112  * SMART FEATURES Subcommands
113  */
114 #define	SATA_SMART_READ_DATA		0xd0
115 #define	SATA_SMART_ATTR_AUTOSAVE	0xd2
116 #define	SATA_SMART_EXECUTE_OFFLINE_IMM	0xd4
117 #define	SATA_SMART_READ_LOG		0xd5
118 #define	SATA_SMART_WRITE_LOG		0xd6
119 #define	SATA_SMART_ENABLE_OPS		0xd8
120 #define	SATA_SMART_DISABLE_OPS		0xd9
121 #define	SATA_SMART_RETURN_STATUS	0xda
122 
123 /*
124  * SET FEATURES Subcommands
125  */
126 #define	SATAC_SF_ENABLE_WRITE_CACHE	0x02
127 #define	SATAC_SF_TRANSFER_MODE		0x03
128 #define	SATAC_SF_DISABLE_RMSN		0x31
129 #define	SATAC_SF_ENABLE_ACOUSTIC	0x42
130 #define	SATAC_SF_DISABLE_READ_AHEAD	0x55
131 #define	SATAC_SF_DISABLE_WRITE_CACHE	0x82
132 #define	SATAC_SF_ENABLE_READ_AHEAD	0xaa
133 #define	SATAC_SF_DISABLE_ACOUSTIC	0xc2
134 #define	SATAC_SF_ENABLE_RMSN		0x95
135 
136 /*
137  * SET FEATURES transfer mode values
138  */
139 #define	SATAC_TRANSFER_MODE_PIO_DEFAULT		0x00
140 #define	SATAC_TRANSFER_MODE_PIO_DISABLE_IODRY	0x01
141 #define	SATAC_TRANSFER_MODE_PIO_FLOW_CONTROL	0x08
142 #define	SATAC_TRANSFER_MODE_MULTI_WORD_DMA	0x20
143 #define	SATAC_TRANSFER_MODE_ULTRA_DMA		0x40
144 
145 /*
146  * Download microcode subcommands
147  */
148 #define	SATA_DOWNLOAD_MCODE_TEMP	1	/* Revert on/ reset/pwr cycle */
149 #define	SATA_DOWNLOAD_MCODE_SAVE	7	/* No offset, keep mcode */
150 
151 
152 /* Generic ATA definitions */
153 
154 #define	SATA_TAG_QUEUING_SHIFT 3
155 #define	SATA_TAG_QUEUING_MASK 0x1f
156 /*
157  * Identify Device data
158  * Although both ATA and ATAPI devices' Identify Data have the same length,
159  * some words have different meaning/content and/or are irrelevant for
160  * other type of device.
161  * Following is the ATA Device Identify data layout
162  */
163 typedef struct sata_id {
164 /*					WORD				  */
165 /*					OFFSET COMMENT			  */
166 	ushort_t  ai_config;	   /*   0  general configuration bits	  */
167 	ushort_t  ai_fixcyls;	   /*   1  # of cylinders (obsolete)	  */
168 	ushort_t  ai_resv0;	   /*   2  # reserved			  */
169 	ushort_t  ai_heads;	   /*   3  # of heads (obsolete)	  */
170 	ushort_t  ai_trksiz;	   /*   4  # of bytes/track (retired)	  */
171 	ushort_t  ai_secsiz;	   /*   5  # of bytes/sector (retired)	  */
172 	ushort_t  ai_sectors;	   /*   6  # of sectors/track (obsolete)  */
173 	ushort_t  ai_resv1[3];	   /*   7  "Vendor Unique"		  */
174 	char	ai_drvser[20];	   /*  10  Serial number		  */
175 	ushort_t ai_buftype;	   /*  20  Buffer type			  */
176 	ushort_t ai_bufsz;	   /*  21  Buffer size in 512 byte incr   */
177 	ushort_t ai_ecc;	   /*  22  # of ecc bytes avail on rd/wr  */
178 	char	ai_fw[8];	   /*  23  Firmware revision		  */
179 	char	ai_model[40];	   /*  27  Model #			  */
180 	ushort_t ai_mult1;	   /*  47  Multiple command flags	  */
181 	ushort_t ai_dwcap;	   /*  48  Doubleword capabilities	  */
182 	ushort_t ai_cap;	   /*  49  Capabilities			  */
183 	ushort_t ai_resv2;	   /*  50  Reserved			  */
184 	ushort_t ai_piomode;	   /*  51  PIO timing mode		  */
185 	ushort_t ai_dmamode;	   /*  52  DMA timing mode		  */
186 	ushort_t ai_validinfo;	   /*  53  bit0: wds 54-58, bit1: 64-70	  */
187 	ushort_t ai_curcyls;	   /*  54  # of current cylinders	  */
188 	ushort_t ai_curheads;	   /*  55  # of current heads		  */
189 	ushort_t ai_cursectrk;	   /*  56  # of current sectors/track	  */
190 	ushort_t ai_cursccp[2];	   /*  57  current sectors capacity	  */
191 	ushort_t ai_mult2;	   /*  59  multiple sectors info	  */
192 	ushort_t ai_addrsec[2];	   /*  60  LBA only: no of addr secs	  */
193 	ushort_t ai_dirdma;	   /*  62  valid in ATA/ATAPI7, DMADIR	  */
194 	ushort_t ai_dworddma;	   /*  63  multi word dma modes	  */
195 	ushort_t ai_advpiomode;	   /*  64  advanced PIO modes supported	  */
196 	ushort_t ai_minmwdma;	   /*  65  min multi-word dma cycle info  */
197 	ushort_t ai_recmwdma;	   /*  66  rec multi-word dma cycle info  */
198 	ushort_t ai_minpio;	   /*  67  min PIO cycle info		  */
199 	ushort_t ai_minpioflow;	   /*  68  min PIO cycle info w/flow ctl  */
200 	ushort_t ai_resv3[2];	   /* 69,70 reserved			  */
201 	ushort_t ai_typtime[2];	   /* 71-72 timing			  */
202 	ushort_t ai_resv4[2];	   /* 73-74 reserved			  */
203 	ushort_t ai_qdepth;	   /*  75  queue depth			  */
204 	ushort_t ai_satacap;	   /*  76  SATA capabilities		  */
205 	ushort_t ai_resv5;	   /*  77 reserved			  */
206 	ushort_t ai_satafsup;	   /*  78 SATA features supported	  */
207 	ushort_t ai_satafenbl;	   /*  79 SATA features enabled		  */
208 	ushort_t ai_majorversion;  /*  80  major versions supported	  */
209 	ushort_t ai_minorversion;  /*  81  minor version number supported */
210 	ushort_t ai_cmdset82;	   /*  82  command set supported	  */
211 	ushort_t ai_cmdset83;	   /*  83  more command sets supported	  */
212 	ushort_t ai_cmdset84;	   /*  84  more command sets supported	  */
213 	ushort_t ai_features85;	   /*  85 enabled features		  */
214 	ushort_t ai_features86;	   /*  86 enabled features		  */
215 	ushort_t ai_features87;	   /*  87 enabled features		  */
216 	ushort_t ai_ultradma;	   /*  88 Ultra DMA mode		  */
217 	ushort_t ai_erasetime;	   /*  89 security erase time		  */
218 	ushort_t ai_erasetimex;	   /*  90 enhanced security erase time	  */
219 	ushort_t ai_adv_pwr_mgmt;  /*  91 advanced power management time  */
220 	ushort_t ai_master_pwd;    /*  92 master password revision code   */
221 	ushort_t ai_hrdwre_reset;  /*  93 hardware reset result		  */
222 	ushort_t ai_acoustic;	   /*  94 accoustic management values	  */
223 	ushort_t ai_stream_min_sz; /*  95 stream minimum request size	  */
224 	ushort_t ai_stream_xfer_d; /*  96 streaming transfer time (DMA)   */
225 	ushort_t ai_stream_lat;    /*  97 streaming access latency	  */
226 	ushort_t ai_streamperf[2]; /* 98-99 streaming performance gran.   */
227 	ushort_t ai_addrsecxt[4];  /* 100 extended max LBA sector	  */
228 	ushort_t ai_stream_xfer_p; /* 104 streaming transfer time (PIO)   */
229 	ushort_t ai_padding1;	   /* 105 pad				  */
230 	ushort_t ai_phys_sect_sz;  /* 106 physical sector size		  */
231 	ushort_t ai_seek_delay;	   /* 107 inter-seek delay time (usecs)	  */
232 	ushort_t ai_naa_ieee_oui;  /* 108 NAA/IEEE OUI			  */
233 	ushort_t ai_ieee_oui_uid;  /* 109 IEEE OUT/unique id		  */
234 	ushort_t ai_uid_mid;	   /* 110 unique id (mid)		  */
235 	ushort_t ai_uid_low;	   /* 111 unique id (low)		  */
236 	ushort_t ai_resv_wwn[4];   /* 112-115 reserved for WWN ext.	  */
237 	ushort_t ai_incits;	   /* 116 reserved for INCITS TR-37-2004  */
238 	ushort_t ai_words_lsec[2]; /* 117-118 words per logical sector	  */
239 	ushort_t ai_cmdset119;	   /* 119 more command sets supported	  */
240 	ushort_t ai_features120;   /* 120 enabled features		  */
241 	ushort_t ai_padding2[6];   /* pad to 126			  */
242 	ushort_t ai_rmsn;	   /* 127 removable media notification	  */
243 	ushort_t ai_securestatus;  /* 128 security status		  */
244 	ushort_t ai_vendor[31];	   /* 129-159 vendor specific		  */
245 	ushort_t ai_padding3[8];   /* 160 pad to 168			  */
246 	ushort_t ai_nomformfactor; /* 168 nominal form factor		  */
247 	ushort_t ai_padding4[7];   /* 169 pad to 176			  */
248 	ushort_t ai_curmedser[30]; /* 176-205 current media serial #	  */
249 	ushort_t ai_sctsupport;	   /* 206 SCT command transport		  */
250 	ushort_t ai_padding5[10];  /* 207 pad to 217			  */
251 	ushort_t ai_medrotrate;	   /* 217 nominal media rotation rate	  */
252 	ushort_t ai_padding6[37];  /* 218 pad to 255			  */
253 	ushort_t ai_integrity;	   /* 255 integrity word		  */
254 } sata_id_t;
255 
256 
257 /* Identify Device: general config bits  - word 0 */
258 
259 #define	SATA_ATA_TYPE_MASK	0x8001	/* ATA Device type mask */
260 #define	SATA_ATA_TYPE		0x0000	/* ATA device */
261 #define	SATA_REM_MEDIA		0x0080	/* Removable media */
262 #define	SATA_INCOMPLETE_DATA	0x0004	/* Incomplete Identify Device data */
263 #define	SATA_CFA_TYPE		0x848a	/* CFA feature set device */
264 
265 #define	SATA_ID_SERIAL_OFFSET	10
266 #define	SATA_ID_SERIAL_LEN	20
267 #define	SATA_ID_MODEL_OFFSET	27
268 #define	SATA_ID_MODEL_LEN	40
269 #define	SATA_ID_FW_LEN		8
270 #define	SATA_ID_BDC_LEN		0x3c
271 
272 /* Identify Device: common capability bits - word 49 */
273 
274 #define	SATA_DMA_SUPPORT	0x0100
275 #define	SATA_LBA_SUPPORT	0x0200
276 #define	SATA_IORDY_DISABLE	0x0400
277 #define	SATA_IORDY_SUPPORT	0x0800
278 #define	SATA_STANDBYTIMER	0x2000
279 
280 /* Identify Device: ai_validinfo (word 53) */
281 
282 #define	SATA_VALIDINFO_88	0x0004	/* word 88 supported fields valid */
283 #define	SATA_VALIDINFO_70_64	0x0004	/* words 70-64 fields valid */
284 
285 /* Identify Device: ai_majorversion (word 80) */
286 
287 #define	SATA_MAJVER_7		0x0080	/* ATA/ATAPI-7 version supported */
288 #define	SATA_MAJVER_654		0x0070	/* ATA/ATAPI-6,5 or 4 ver supported */
289 #define	SATA_MAJVER_6		0x0040	/* ATA/ATAPI-6 version supported */
290 #define	SATA_MAJVER_5		0x0020	/* ATA/ATAPI-7 version supported */
291 #define	SATA_MAJVER_4		0x0010	/* ATA/ATAPI-4 version supported */
292 
293 /* Identify Device: command set supported/enabled bits - words 83 and 86 */
294 
295 #define	SATA_EXT48		0x0400	/* 48 bit address feature */
296 #define	SATA_PWRUP_IN_STANDBY	0x0020	/* Power-up in standby mode supp/en */
297 #define	SATA_RM_STATUS_NOTIFIC	0x0010	/* Removable Media Stat Notification */
298 #define	SATA_RW_DMA_QUEUED_CMD	0x0002	/* R/W DMA Queued supported */
299 #define	SATA_DWNLOAD_MCODE_CMD	0x0001	/* Download Microcode CMD supp/enbld */
300 #define	SATA_ACOUSTIC_MGMT	0x0200	/* Acoustic Management features */
301 
302 /* Identify Device: command set supported/enabled bits - words 82 and 85 */
303 
304 #define	SATA_SMART_SUPPORTED	0x0001	/* SMART feature set is supported */
305 #define	SATA_WRITE_CACHE	0x0020	/* Write Cache supported/enabled */
306 #define	SATA_LOOK_AHEAD		0x0040	/* Look Ahead supported/enabled */
307 #define	SATA_DEVICE_RESET_CMD	0x0200	/* Device Reset CMD supported/enbld */
308 #define	SATA_READ_BUFFER_CMD	0x2000	/* Read Buffer CMD supported/enbld */
309 #define	SATA_WRITE_BUFFER_CMD	0x1000	/* Write Buffer CMD supported/enbld */
310 #define	SATA_SMART_ENABLED	0x0001	/* SMART feature set is enabled */
311 
312 /* Identify Device: command set supported/enabled bits - words 84 & 87 */
313 #define	SATA_SMART_SELF_TEST_SUPPORTED	0x0002	/* SMART self-test supported */
314 /* IDLE IMMEDIATE with UNLOAD FEATURE supported */
315 #define	SATA_IDLE_UNLOAD_SUPPORTED	0x2000
316 
317 /* Identify (Packet) Device word 63,  ATA/ATAPI-6 & 7 */
318 #define	SATA_MDMA_SEL_MASK	0x0700	/* Multiword DMA selected */
319 #define	SATA_MDMA_2_SEL		0x0400	/* Multiword DMA mode 2 selected */
320 #define	SATA_MDMA_1_SEL		0x0200	/* Multiword DMA mode 1 selected */
321 #define	SATA_MDMA_0_SEL		0x0100	/* Multiword DMA mode 0 selected */
322 #define	SATA_MDMA_2_SUP		0x0004	/* Multiword DMA mode 2 supported */
323 #define	SATA_MDMA_1_SUP		0x0002	/* Multiword DMA mode 1 supported */
324 #define	SATA_MDMA_0_SUP		0x0001	/* Multiword DMA mode 0 supported */
325 #define	SATA_MDMA_SUP_MASK	0x0007	/* Multiword DMA supported */
326 
327 /* Identify (Packet) Device Word 88 */
328 #define	SATA_UDMA_SUP_MASK		0x007f	/* UDMA modes supported */
329 #define	SATA_UDMA_SEL_MASK	0x7f00	/* UDMA modes selected */
330 
331 /* Identify Device: command set supported/enabled bits - word 206 */
332 
333 /* All are SCT Command Transport support */
334 #define	SATA_SCT_CMD_TRANS_SUP		0x0001	/* anything */
335 #define	SATA_SCT_CMD_TRANS_LNG_SECT_SUP	0x0002	/* Long Sector Access */
336 #define	SATA_SCT_CMD_TRANS_WR_SAME_SUP	0x0004	/* Write Same */
337 #define	SATA_SCT_CMD_TRANS_ERR_RCOV_SUP	0x0008	/* Error Recovery Control */
338 #define	SATA_SCT_CMD_TRANS_FEAT_CTL_SUP	0x0010	/* Features Control */
339 #define	SATA_SCT_CMD_TRANS_DATA_TBL_SUP	0x0020	/* Data Tables supported */
340 
341 #define	SATA_DISK_SECTOR_SIZE	512	/* HD physical sector size */
342 
343 /* Identify Packet Device data definitions (ATAPI devices) */
344 
345 /* Identify Packet Device: general config bits  - word 0 */
346 
347 #define	SATA_ATAPI_TYPE_MASK	0xc000
348 #define	SATA_ATAPI_TYPE		0x8000	/* ATAPI device */
349 #define	SATA_ATAPI_ID_PKT_SZ	0x0003	/* Packet size mask */
350 #define	SATA_ATAPI_ID_PKT_12B	0x0000  /* Packet size 12 bytes */
351 #define	SATA_ATAPI_ID_PKT_16B	0x0001  /* Packet size 16 bytes */
352 #define	SATA_ATAPI_ID_DRQ_TYPE	0x0060	/* DRQ asserted in 3ms after pkt */
353 #define	SATA_ATAPI_ID_DRQ_INTR	0x0020  /* Obsolete in ATA/ATAPI 7 */
354 
355 #define	SATA_ATAPI_ID_DEV_TYPE	0x0f00	/* device type/command set mask */
356 #define	SATA_ATAPI_ID_DEV_SHFT	8
357 #define	SATA_ATAPI_DIRACC_DEV	0x0000	/* Direct Access device */
358 #define	SATA_ATAPI_SQACC_DEV	0x0100  /* Sequential access dev (tape ?) */
359 #define	SATA_ATAPI_CDROM_DEV	0x0500  /* CD_ROM device */
360 
361 /*
362  * Status bits from ATAPI Interrupt reason register (AT_COUNT) register
363  */
364 #define	SATA_ATAPI_I_COD	0x01	/* Command or Data */
365 #define	SATA_ATAPI_I_IO		0x02	/* IO direction */
366 #define	SATA_ATAPI_I_RELEASE	0x04	/* Release for ATAPI overlap */
367 
368 /* ATAPI feature reg definitions */
369 
370 #define	SATA_ATAPI_F_DATA_DIR_READ 0x04	/* DMA transfer to the host */
371 #define	SATA_ATAPI_F_OVERLAP	0x02	/* Not used by Sun drivers */
372 #define	SATA_ATAPI_F_DMA	0x01	/* Packet DMA command */
373 
374 
375 /* ATAPI IDENTIFY_DRIVE capabilities word (49) */
376 
377 #define	SATA_ATAPI_ID_CAP_DMA		0x0100 /* if zero, check word 62  */
378 #define	SATA_ATAPI_ID_CAP_OVERLAP	0x2000
379 
380 /*
381  * ATAPI Identify Packet Device word 62
382  * Word 62 is not valid for ATA/ATAPI-6
383  * Defs below are for ATA/ATAPI-7
384  */
385 #define	SATA_ATAPI_ID_DMADIR_REQ	0x8000 /* DMA direction required */
386 #define	SATA_ATAPI_ID_DMA_SUP		0x0400 /* DMA is supported */
387 
388 /*
389  * ATAPI signature bits
390  */
391 #define	SATA_ATAPI_SIG_HI	0xeb	/* in high cylinder register */
392 #define	SATA_ATAPI_SIG_LO	0x14	/* in low cylinder register */
393 
394 /* These values are pre-set for CD_ROM/DVD ? */
395 
396 #define	SATA_ATAPI_SECTOR_SIZE		2048
397 #define	SATA_ATAPI_MAX_BYTES_PER_DRQ	0xf800 /* 16 bits - 2KB  ie 62KB */
398 #define	SATA_ATAPI_HEADS		64
399 #define	SATA_ATAPI_SECTORS_PER_TRK	32
400 
401 /* SATA Capabilites bits (word 76) */
402 
403 #define	SATA_NCQ		0x100
404 #define	SATA_2_SPEED		0x004
405 #define	SATA_1_SPEED		0x002
406 
407 /* SATA Features Supported (word 78) - not used */
408 
409 /* SATA Features Enabled (word 79) - not used */
410 
411 #define	SATA_READ_AHEAD_SUPPORTED(x)	((x).ai_cmdset82 & SATA_LOOK_AHEAD)
412 #define	SATA_READ_AHEAD_ENABLED(x)	((x).ai_features85 & SATA_LOOK_AHEAD)
413 #define	SATA_WRITE_CACHE_SUPPORTED(x)	((x).ai_cmdset82 & SATA_WRITE_CACHE)
414 #define	SATA_WRITE_CACHE_ENABLED(x)	((x).ai_features85 & SATA_WRITE_CACHE)
415 #define	SATA_RM_NOTIFIC_SUPPORTED(x)	\
416 	((x).ai_cmdset83 & SATA_RM_STATUS_NOTIFIC)
417 #define	SATA_RM_NOTIFIC_ENABLED(x)	\
418 	((x).ai_features86 & SATA_RM_STATUS_NOTIFIC)
419 
420 /*
421  * Generic NCQ related defines
422  */
423 
424 #define	NQ			0x80	/* Not a queued cmd - tag not valid */
425 #define	NCQ_TAG_MASK		0x1f	/* NCQ command tag mask */
426 #define	FIS_TYPE_REG_H2D	0x27	/* Reg FIS - Host to Device */
427 #define	FIS_CMD_UPDATE		0x80
428 /*
429  * Status bits from AT_STATUS register
430  */
431 #define	SATA_STATUS_BSY		0x80    /* controller busy */
432 #define	SATA_STATUS_DRDY	0x40    /* drive ready	*/
433 #define	SATA_STATUS_DF		0x20    /* device fault	*/
434 #define	SATA_STATUS_DSC		0x10    /* seek operation complete */
435 #define	SATA_STATUS_DRQ		0x08	/* data request */
436 #define	SATA_STATUS_CORR	0x04    /* obsolete */
437 #define	SATA_STATUS_IDX		0x02    /* obsolete */
438 #define	SATA_STATUS_ERR		0x01    /* error flag */
439 
440 /*
441  * Status bits from AT_ERROR register
442  */
443 #define	SATA_ERROR_ICRC		0x80	/* CRC data transfer error detected */
444 #define	SATA_ERROR_UNC		0x40	/* uncorrectable data error */
445 #define	SATA_ERROR_MC		0x20    /* Media change	*/
446 #define	SATA_ERROR_IDNF		0x10    /* ID/Address not found	*/
447 #define	SATA_ERROR_MCR		0x08	/* media change request	*/
448 #define	SATA_ERROR_ABORT	0x04    /* aborted command */
449 #define	SATA_ERROR_NM		0x02	/* no media */
450 #define	SATA_ERROR_EOM		0x02    /* end of media (Packet cmds) */
451 #define	SATA_ERROR_ILI		0x01    /* cmd sepcific */
452 
453 
454 /*
455  * Bits from the device control register
456  */
457 #define	SATA_DEVCTL_NIEN	0x02	/* not interrupt enabled */
458 #define	SATA_DEVCTL_SRST	0x04	/* software reset */
459 #define	SATA_DEVCTL_HOB		0x80	/* high order bit */
460 
461 /* device_reg */
462 #define	SATA_ADH_LBA		0x40	/* addressing in LBA mode not chs */
463 
464 /* ATAPI transport version-in Inquiry data */
465 #define	SATA_ATAPI_TRANS_VERSION(inq) \
466 	(*((uint8_t *)(inq) + 3) >> 4)
467 
468 #define	SCSI_LOG_PAGE_HDR_LEN	4	/* # bytes of a SCSI log page header */
469 #define	SCSI_LOG_PARAM_HDR_LEN	4	/* # byttes of a SCSI log param hdr */
470 
471 /* Number of log entries per extended selftest log block */
472 #define	ENTRIES_PER_EXT_SELFTEST_LOG_BLK	19
473 
474 /* Number of entries per SCSI LOG SENSE SELFTEST RESULTS page */
475 #define	SCSI_ENTRIES_IN_LOG_SENSE_SELFTEST_RESULTS	20
476 
477 /* Length of a SCSI LOG SENSE SELFTEST RESULTS parameter */
478 #define	SCSI_LOG_SENSE_SELFTEST_PARAM_LEN	0x10
479 
480 #define	DIAGNOSTIC_FAILURE_ON_COMPONENT	0x40
481 
482 #define	SCSI_COMPONENT_81	0x81
483 #define	SCSI_COMPONENT_82	0x82
484 #define	SCSI_COMPONENT_83	0x83
485 #define	SCSI_COMPONENT_84	0x84
486 #define	SCSI_COMPONENT_85	0x85
487 #define	SCSI_COMPONENT_86	0x86
488 #define	SCSI_COMPONENT_87	0x87
489 #define	SCSI_COMPONENT_88	0x88
490 
491 #define	SCSI_ASC_ATA_DEV_FEAT_NOT_ENABLED	0x67
492 #define	SCSI_ASCQ_ATA_DEV_FEAT_NOT_ENABLED	0x0b
493 
494 #define	SCSI_PREDICTED_FAILURE	0x5d
495 #define	SCSI_GENERAL_HD_FAILURE	0x10
496 
497 #define	SCSI_INFO_EXCEPTIONS_PARAM_LEN	4
498 
499 #define	READ_LOG_EXT_LOG_DIRECTORY	0
500 #define	READ_LOG_EXT_NCQ_ERROR_RECOVERY	0x10
501 #define	SMART_SELFTEST_LOG_PAGE		6
502 #define	EXT_SMART_SELFTEST_LOG_PAGE	7
503 
504 /*
505  * SATA NCQ error recovery page (0x10)
506  */
507 struct sata_ncq_error_recovery_page {
508 	uint8_t	ncq_tag;
509 	uint8_t reserved1;
510 	uint8_t ncq_status;
511 	uint8_t ncq_error;
512 	uint8_t ncq_sector_number;
513 	uint8_t ncq_cyl_low;
514 	uint8_t ncq_cyl_high;
515 	uint8_t ncq_dev_head;
516 	uint8_t ncq_sector_number_ext;
517 	uint8_t ncq_cyl_low_ext;
518 	uint8_t ncq_cyl_high_ext;
519 	uint8_t reserved2;
520 	uint8_t ncq_sector_count;
521 	uint8_t ncq_sector_count_ext;
522 	uint8_t reserved3[242];
523 	uint8_t ncq_vendor_unique[255];
524 	uint8_t ncq_checksum;
525 };
526 
527 /* SMART attribute of Start/Stop Count */
528 #define	SMART_START_STOP_COUNT_ID	0x4
529 
530 /*
531  * SMART data structures
532  */
533 struct smart_data {
534 	uint8_t smart_vendor_specific[362];
535 	uint8_t smart_offline_data_collection_status;
536 	uint8_t smart_selftest_exec_status;
537 	uint8_t smart_secs_to_complete_offline_data[2];
538 	uint8_t smart_vendor_specific2;
539 	uint8_t smart_offline_data_collection_capability;
540 	uint8_t smart_capability[2];
541 	uint8_t	smart_error_logging_capability;
542 	uint8_t smart_vendor_specific3;
543 	uint8_t smart_short_selftest_polling_time;
544 	uint8_t smart_extended_selftest_polling_time;
545 	uint8_t smart_conveyance_selftest_polling_time;
546 	uint8_t smart_reserved[11];
547 	uint8_t smart_vendor_specific4[125];
548 	uint8_t smart_checksum;
549 };
550 
551 struct smart_selftest_log_entry {
552 	uint8_t	smart_selftest_log_lba_low;
553 	uint8_t	smart_selftest_log_status;
554 	uint8_t	smart_selftest_log_timestamp[2];
555 	uint8_t smart_selftest_log_checkpoint;
556 	uint8_t smart_selftest_log_failing_lba[4];	/* from LSB to MSB */
557 	uint8_t smart_selftest_log_vendor_specific[15];
558 };
559 
560 #define	NUM_SMART_SELFTEST_LOG_ENTRIES	21
561 struct smart_selftest_log {
562 	uint8_t	smart_selftest_log_revision[2];
563 	struct	smart_selftest_log_entry
564 	    smart_selftest_log_entries[NUM_SMART_SELFTEST_LOG_ENTRIES];
565 	uint8_t	smart_selftest_log_vendor_specific[2];
566 	uint8_t smart_selftest_log_index;
567 	uint8_t smart_selftest_log_reserved[2];
568 	uint8_t smart_selftest_log_checksum;
569 };
570 
571 struct smart_ext_selftest_log_entry {
572 	uint8_t	smart_ext_selftest_log_lba_low;
573 	uint8_t smart_ext_selftest_log_status;
574 	uint8_t smart_ext_selftest_log_timestamp[2];
575 	uint8_t smart_ext_selftest_log_checkpoint;
576 	uint8_t smart_ext_selftest_log_failing_lba[6];
577 	uint8_t smart_ext_selftest_log_vendor_specific[15];
578 };
579 
580 struct smart_ext_selftest_log {
581 	uint8_t	smart_ext_selftest_log_rev;
582 	uint8_t	smart_ext_selftest_log_reserved;
583 	uint8_t	smart_ext_selftest_log_index[2];
584 	struct smart_ext_selftest_log_entry smart_ext_selftest_log_entries[19];
585 	uint8_t	smart_ext_selftest_log_vendor_specific[2];
586 	uint8_t	smart_ext_selftest_log_reserved2[11];
587 	uint8_t	smart_ext_selftest_log_checksum;
588 };
589 
590 struct read_log_ext_directory {
591 	uint8_t	read_log_ext_vers[2];	/* general purpose log version */
592 	uint8_t read_log_ext_nblks[255][2]; /* # of blks @ log addr index+1 */
593 };
594 
595 /*
596  * The definition of CONTROL byte field in SCSI command
597  * according to SAM 5
598  */
599 #define	CTL_BYTE_VENDOR_MASK		0xc0
600 #define	CTL_BYTE_NACA_MASK		0x04
601 
602 /*
603  * The definition of mask in START STOP UNIT command
604  */
605 #define	START_STOP_IMMED_MASK		0x01
606 #define	START_STOP_POWER_COND_MASK	0xF0
607 #define	START_STOP_START_MASK		0x01
608 #define	START_STOP_LOEJ_MASK		0x02
609 #define	START_STOP_NOFLUSH_MASK		0x04
610 #define	START_STOP_MODIFIER_MASK	0x0f
611 #define	START_STOP_POWER_COND_SHIFT	4
612 
613 /*
614  * SMART specific data
615  * These eventually need to go to a generic scsi hearder file
616  * for now they will reside here
617  */
618 #define	PC_CUMULATIVE_VALUES			0x01
619 #define	PAGE_CODE_GET_SUPPORTED_LOG_PAGES	0x00
620 #define	PAGE_CODE_SELF_TEST_RESULTS		0x10
621 #define	PAGE_CODE_INFORMATION_EXCEPTIONS	0x2f
622 #define	PAGE_CODE_SMART_READ_DATA		0x30
623 #define	PAGE_CODE_START_STOP_CYCLE_COUNTER	0x0e
624 
625 
626 struct log_parameter {
627 	uint8_t param_code[2];		/* parameter dependant */
628 	uint8_t param_ctrl_flags;	/* see defines below */
629 	uint8_t param_len;		/* # of bytes following */
630 	uint8_t param_values[1];	/* # of bytes defined by param_len */
631 };
632 
633 /* param_ctrl_flag fields */
634 #define	LOG_CTRL_LP	0x01	/* list parameter */
635 #define	LOG_CTRL_LBIN	0x02	/* list is binary */
636 #define	LOG_CTRL_TMC	0x0c	/* threshold met criteria */
637 #define	LOG_CTRL_ETC	0x10	/* enable threshold comparison */
638 #define	LOG_CTRL_TSD	0x20	/* target save disable */
639 #define	LOG_CTRL_DS	0x40	/* disable save */
640 #define	LOG_CTRL_DU	0x80	/* disable update */
641 
642 #define	SMART_MAGIC_VAL_1	0x4f
643 #define	SMART_MAGIC_VAL_2	0xc2
644 #define	SMART_MAGIC_VAL_3	0xf4
645 #define	SMART_MAGIC_VAL_4	0x2c
646 
647 #define	SCT_STATUS_LOG_PAGE	0xe0
648 
649 /*
650  * Acoustic management
651  */
652 
653 struct mode_acoustic_management {
654 	struct mode_page	mode_page;	/* common mode page header */
655 	uchar_t	acoustic_manag_enable;	/* Set to 1 enable, Set 0 disable */
656 	uchar_t	acoustic_manag_level;	/* Acoustic management level	  */
657 	uchar_t	vendor_recommended_value; /* Vendor recommended value	  */
658 };
659 
660 #define	PAGELENGTH_DAD_MODE_ACOUSTIC_MANAGEMENT 3 /* Acoustic manag pg len */
661 #define	P_CNTRL_CURRENT		0
662 #define	P_CNTRL_CHANGEABLE	1
663 #define	P_CNTRL_DEFAULT		2
664 #define	P_CNTRL_SAVED		3
665 
666 #define	ACOUSTIC_DISABLED	0
667 #define	ACOUSTIC_ENABLED	1
668 
669 #define	MODEPAGE_ACOUSTIC_MANAG 0x30
670 
671 /*
672  * Port Multiplier registers' offsets
673  */
674 #define	SATA_PMULT_GSCR0		0x0
675 #define	SATA_PMULT_GSCR1		0x1
676 #define	SATA_PMULT_GSCR2		0x2
677 #define	SATA_PMULT_GSCR32		0x20
678 #define	SATA_PMULT_GSCR33		0x21
679 #define	SATA_PMULT_GSCR64		0x40
680 #define	SATA_PMULT_GSCR96		0x60
681 
682 #define	SATA_PMULT_PORTNUM_MASK		0xf
683 
684 #define	SATA_PMULT_PSCR0		0x0
685 #define	SATA_PMULT_PSCR1		0x1
686 #define	SATA_PMULT_PSCR2		0x2
687 #define	SATA_PMULT_PSCR3		0x3
688 #define	SATA_PMULT_PSCR4		0x4
689 
690 #define	SATA_PMULT_REG_SSTS		(SATA_PMULT_PSCR0)
691 #define	SATA_PMULT_REG_SERR		(SATA_PMULT_PSCR1)
692 #define	SATA_PMULT_REG_SCTL		(SATA_PMULT_PSCR2)
693 #define	SATA_PMULT_REG_SACT		(SATA_PMULT_PSCR3)
694 #define	SATA_PMULT_REG_SNTF		(SATA_PMULT_PSCR4)
695 
696 /*
697  * Port Multiplier capabilities
698  * (Indicated by GSCR64, and enabled by GSCR96)
699  */
700 #define	SATA_PMULT_CAP_BIST		(1 << 0)
701 #define	SATA_PMULT_CAP_PMREQ		(1 << 1)
702 #define	SATA_PMULT_CAP_SSC		(1 << 2)
703 #define	SATA_PMULT_CAP_SNOTIF		(1 << 3)
704 #define	SATA_PMULT_CAP_PHYEVENT		(1 << 4)
705 
706 /*
707  * sstatus field definitions
708  */
709 #define	SSTATUS_DET_SHIFT	0
710 #define	SSTATUS_SPD_SHIFT	4
711 #define	SSTATUS_IPM_SHIFT	8
712 
713 #define	SSTATUS_DET	(0xf << SSTATUS_DET_SHIFT)
714 #define	SSTATUS_SPD	(0xf << SSTATUS_SPD_SHIFT)
715 #define	SSTATUS_IPM	(0xf << SSTATUS_IPM_SHIFT)
716 
717 /*
718  * sstatus DET values
719  */
720 #define	SSTATUS_DET_NODEV		0	/* No dev detected */
721 #define	SSTATUS_DET_DEVPRE_NOPHYCOM	1	/* dev detected */
722 #define	SSTATUS_DET_DEVPRE_PHYCOM	3	/* dev detected */
723 #define	SSTATUS_DET_PHYOFFLINE		4	/* PHY is in offline */
724 
725 #define	SSTATUS_GET_DET(x) \
726 	(x & SSTATUS_DET)
727 
728 #define	SSTATUS_SET_DET(x, new_val) \
729 	(x = (x & ~SSTATUS_DET) | (new_val & SSTATUS_DET))
730 
731 #define	SSTATUS_SPD_NOLIMIT	0 /* No speed limit */
732 #define	SSTATUS_SPD_GEN1	1 /* Limit Gen 1 rate */
733 #define	SSTATUS_SPD_GEN2	2 /* Limit Gen 2 rate */
734 
735 /*
736  * sstatus IPM values
737  */
738 #define	SSTATUS_IPM_NODEV_NOPHYCOM	0x0 /* No dev, no PHY */
739 #define	SSTATUS_IPM_ACTIVE		0x1 /* Interface active */
740 #define	SSTATUS_IPM_POWERPARTIAL	0x2 /* partial power mgmnt */
741 #define	SSTATUS_IPM_POWERSLUMBER	0x6 /* slumber power mgmt */
742 
743 #define	SSTATUS_GET_IPM(x) \
744 	((x & SSTATUS_IPM) >> SSTATUS_IPM_SHIFT)
745 
746 #define	SSTATUS_SET_IPM(x, new_val) \
747 	(x = (x & ~SSTATUS_IPM) | \
748 	((new_val << SSTATUS_IPM_SHIFT) & SSTATUS_IPM))
749 
750 
751 /*
752  * serror register fields
753  */
754 #define	SERROR_DATA_ERR_FIXED	(1 << 0) /* D integrity err */
755 #define	SERROR_COMM_ERR_FIXED	(1 << 1) /* comm err recov */
756 #define	SERROR_DATA_ERR		(1 << 8) /* D integrity err */
757 #define	SERROR_PERSISTENT_ERR	(1 << 9)  /* norecov com err */
758 #define	SERROR_PROTOCOL_ERR	(1 << 10) /* protocol err */
759 #define	SERROR_INT_ERR		(1 << 11) /* internal err */
760 #define	SERROR_PHY_RDY_CHG	(1 << 16) /* PHY state change */
761 #define	SERROR_PHY_INT_ERR	(1 << 17) /* PHY internal err */
762 #define	SERROR_COMM_WAKE	(1 << 18) /* COM wake */
763 #define	SERROR_10B_TO_8B_ERR	(1 << 19) /* 10B-to-8B decode */
764 #define	SERROR_DISPARITY_ERR	(1 << 20) /* disparity err */
765 #define	SERROR_CRC_ERR		(1 << 21) /* CRC err */
766 #define	SERROR_HANDSHAKE_ERR	(1 << 22) /* Handshake err */
767 #define	SERROR_LINK_SEQ_ERR	(1 << 23) /* Link seq err */
768 #define	SERROR_TRANS_ERR	(1 << 24) /* Tran state err */
769 #define	SERROR_FIS_TYPE		(1 << 25) /* FIS type err */
770 #define	SERROR_EXCHANGED_ERR	(1 << 26) /* Device exchanged */
771 
772 /*
773  * S-Control Bridge port x register fields
774  */
775 #define	SCONTROL_DET_SHIFT	0
776 #define	SCONTROL_SPD_SHIFT	4
777 #define	SCONTROL_IPM_SHIFT	8
778 #define	SCONTROL_SPM_SHIFT	12
779 
780 #define	SCONTROL_DET		(0xf << SSTATUS_DET_SHIFT)
781 #define	SCONTROL_SPD		(0xf << SSTATUS_SPD_SHIFT)
782 #define	SCONTROL_IPM		(0xf << SSTATUS_IPM_SHIFT)
783 #define	SCONTROL_SPM		(0xf << SSTATUS_SPM_SHIFT)
784 
785 #define	SCONTROL_GET_DET(x)	\
786 	(x & SCONTROL_DET)
787 
788 #define	SCONTROL_SET_DET(x, new_val)    \
789 	(x = (x & ~SCONTROL_DET) | (new_val & SCONTROL_DET))
790 
791 #define	SCONTROL_DET_NOACTION	0 /* Do nothing to port */
792 #define	SCONTROL_DET_COMRESET	1 /* Re-initialize port */
793 #define	SCONTROL_DET_DISABLE	4 /* Disable port */
794 
795 #define	SCONTROL_SPD_NOLIMIT	0 /* No speed limit */
796 #define	SCONTROL_SPD_GEN1	1 /* Limit Gen 1 rate */
797 #define	SCONTROL_SPD_GEN2	2 /* Limit Gen 2 rate */
798 
799 #define	SCONTROL_GET_IPM(x)	\
800 	((x & SCONTROL_IPM) >> SCONTROL_IPM_SHIFT)
801 
802 #define	SCONTROL_SET_IPM(x, new_val)	\
803 	(x = (x & ~SCONTROL_IPM) | \
804 	((new_val << SCONTROL_IPM_SHIFT) & SCONTROL_IPM))
805 
806 #define	SCONTROL_IPM_NORESTRICT		0 /* No PM limit */
807 #define	SCONTROL_IPM_DISABLE_PARTIAL	1 /* Disable partial */
808 #define	SCONTROL_IPM_DISABLE_SLUMBER	2 /* Disable slumber */
809 #define	SCONTROL_IPM_DISABLE_BOTH	3 /* Disable both */
810 
811 #define	SCONTROL_SPM_NORESTRICT		0 /* No PM limits */
812 #define	SCONTROL_SPM_DO_PARTIAL		1 /* Go to partial */
813 #define	SCONTROL_SPM_DO_SLUMBER		2 /* Go to slumber */
814 #define	SCONTROL_SPM_DO_ACTIVE		4 /* Go to active */
815 
816 #ifdef	__cplusplus
817 }
818 #endif
819 
820 #endif /* _SATA_DEFS_H */
821