xref: /titanic_51/usr/src/uts/common/sys/sata/sata_defs.h (revision 13c8743e4d3cc6d9653687512c0d48d2b653513d)
166f9d5cbSmlf /*
266f9d5cbSmlf  * CDDL HEADER START
366f9d5cbSmlf  *
466f9d5cbSmlf  * The contents of this file are subject to the terms of the
566f9d5cbSmlf  * Common Development and Distribution License (the "License").
666f9d5cbSmlf  * You may not use this file except in compliance with the License.
766f9d5cbSmlf  *
866f9d5cbSmlf  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
966f9d5cbSmlf  * or http://www.opensolaris.org/os/licensing.
1066f9d5cbSmlf  * See the License for the specific language governing permissions
1166f9d5cbSmlf  * and limitations under the License.
1266f9d5cbSmlf  *
1366f9d5cbSmlf  * When distributing Covered Code, include this CDDL HEADER in each
1466f9d5cbSmlf  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1566f9d5cbSmlf  * If applicable, add the following below this CDDL HEADER, with the
1666f9d5cbSmlf  * fields enclosed by brackets "[]" replaced with your own identifying
1766f9d5cbSmlf  * information: Portions Copyright [yyyy] [name of copyright owner]
1866f9d5cbSmlf  *
1966f9d5cbSmlf  * CDDL HEADER END
2066f9d5cbSmlf  */
2166f9d5cbSmlf 
2266f9d5cbSmlf /*
23fcacecd0SPhi Tran  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24257c04ecSMarcel Telka  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
2566f9d5cbSmlf  */
2666f9d5cbSmlf 
2766f9d5cbSmlf #ifndef _SATA_DEFS_H
2866f9d5cbSmlf #define	_SATA_DEFS_H
2966f9d5cbSmlf 
3066f9d5cbSmlf #ifdef	__cplusplus
3166f9d5cbSmlf extern "C" {
3266f9d5cbSmlf #endif
3366f9d5cbSmlf 
34b8b2574eSls24207 #include <sys/scsi/generic/mode.h>
35b8b2574eSls24207 
3666f9d5cbSmlf /*
3766f9d5cbSmlf  * Common ATA commands (subset)
3866f9d5cbSmlf  */
3966f9d5cbSmlf #define	SATAC_DIAG		0x90    /* diagnose command */
4066f9d5cbSmlf #define	SATAC_RECAL		0x10	/* restore cmd, 4 bits step rate */
4166f9d5cbSmlf #define	SATAC_FORMAT		0x50	/* format track command */
4266f9d5cbSmlf #define	SATAC_SET_FEATURES	0xef	/* set features	*/
4366f9d5cbSmlf #define	SATAC_IDLE_IM		0xe1	/* idle immediate */
4466f9d5cbSmlf #define	SATAC_STANDBY_IM	0xe0	/* standby immediate */
4566f9d5cbSmlf #define	SATAC_DOOR_LOCK		0xde	/* door lock */
4666f9d5cbSmlf #define	SATAC_DOOR_UNLOCK	0xdf	/* door unlock */
4766f9d5cbSmlf #define	SATAC_IDLE		0xe3	/* idle	*/
482ee4dfc7SJane Chu #define	SATAC_STANDBY		0xe2	/* standby */
4966f9d5cbSmlf 
5066f9d5cbSmlf /*
5166f9d5cbSmlf  * ATA/ATAPI disk commands (subset)
5266f9d5cbSmlf  */
53fcacecd0SPhi Tran #define	SATAC_DSM		0x06	/* Data Set Management */
5466f9d5cbSmlf #define	SATAC_DEVICE_RESET	0x08    /* ATAPI device reset */
55a022fe3eSls24207 #define	SATAC_DOWNLOAD_MICROCODE 0x92   /* Download microcode */
5666f9d5cbSmlf #define	SATAC_EJECT		0xed	/* media eject */
5766f9d5cbSmlf #define	SATAC_FLUSH_CACHE	0xe7	/* flush write-cache */
5866f9d5cbSmlf #define	SATAC_ID_DEVICE		0xec    /* IDENTIFY DEVICE */
5966f9d5cbSmlf #define	SATAC_ID_PACKET_DEVICE	0xa1	/* ATAPI identify packet device */
6066f9d5cbSmlf #define	SATAC_INIT_DEVPARMS	0x91	/* initialize device parameters */
6166f9d5cbSmlf #define	SATAC_PACKET		0xa0	/* ATAPI packet */
6266f9d5cbSmlf #define	SATAC_RDMULT		0xc4	/* read multiple w/DMA */
6366f9d5cbSmlf #define	SATAC_RDSEC		0x20    /* read sector */
6466f9d5cbSmlf #define	SATAC_RDVER		0x40	/* read verify */
6566f9d5cbSmlf #define	SATAC_READ_DMA		0xc8	/* read DMA */
6666f9d5cbSmlf #define	SATAC_SEEK		0x70    /* seek */
6766f9d5cbSmlf #define	SATAC_SERVICE		0xa2	/* queued/overlap service */
6866f9d5cbSmlf #define	SATAC_SETMULT		0xc6	/* set multiple mode */
6966f9d5cbSmlf #define	SATAC_WRITE_DMA		0xca	/* write (multiple) w/DMA */
7066f9d5cbSmlf #define	SATAC_WRMULT		0xc5	/* write multiple */
7166f9d5cbSmlf #define	SATAC_WRSEC		0x30    /* write sector */
7266f9d5cbSmlf #define	SATAC_RDSEC_EXT		0x24    /* read sector extended (LBA48) */
7366f9d5cbSmlf #define	SATAC_READ_DMA_EXT	0x25	/* read DMA extended (LBA48) */
7466f9d5cbSmlf #define	SATAC_RDMULT_EXT	0x29	/* read multiple extended (LBA48) */
7566f9d5cbSmlf #define	SATAC_WRSEC_EXT		0x34    /* read sector extended (LBA48) */
7666f9d5cbSmlf #define	SATAC_WRITE_DMA_EXT	0x35	/* read DMA extended (LBA48) */
7766f9d5cbSmlf #define	SATAC_WRMULT_EXT	0x39	/* read multiple extended (LBA48) */
7866f9d5cbSmlf 
7966f9d5cbSmlf #define	SATAC_READ_DMA_QUEUED	0xc7	/* read DMA / may be queued */
8066f9d5cbSmlf #define	SATAC_READ_DMA_QUEUED_EXT 0x26	/* read DMA ext / may be queued */
8166f9d5cbSmlf #define	SATAC_WRITE_DMA_QUEUED	0xcc	/* read DMA / may be queued */
8266f9d5cbSmlf #define	SATAC_WRITE_DMA_QUEUED_EXT 0x36	/* read DMA ext / may be queued */
8366f9d5cbSmlf #define	SATAC_READ_PM_REG	0xe4	/* read port mult reg */
8466f9d5cbSmlf #define	SATAC_WRITE_PM_REG	0xe8	/* write port mult reg */
8566f9d5cbSmlf 
8666f9d5cbSmlf #define	SATAC_READ_FPDMA_QUEUED	0x60	/* First-Party-DMA read queued */
8766f9d5cbSmlf #define	SATAC_WRITE_FPDMA_QUEUED 0x61	/* First-Party-DMA write queued */
8866f9d5cbSmlf 
8966f9d5cbSmlf #define	SATAC_READ_LOG_EXT	0x2f	/* read log */
90c03acfcaSls24207 
91c03acfcaSls24207 #define	SATAC_SMART		0xb0	/* SMART */
92c03acfcaSls24207 
9366f9d5cbSmlf #define	SATA_LOG_PAGE_10	0x10	/* log page 0x10 - SATA error */
9466f9d5cbSmlf /*
958aa6aadbSXiao-Yu Zhang  * Port Multiplier Commands
968aa6aadbSXiao-Yu Zhang  */
978aa6aadbSXiao-Yu Zhang #define	SATAC_READ_PORTMULT	0xe4	/* read port multiplier */
988aa6aadbSXiao-Yu Zhang #define	SATAC_WRITE_PORTMULT	0xe8	/* write port multiplier */
998aa6aadbSXiao-Yu Zhang 
1008aa6aadbSXiao-Yu Zhang /*
10166f9d5cbSmlf  * Power Managment Commands (subset)
10266f9d5cbSmlf  */
10366f9d5cbSmlf #define	SATAC_CHECK_POWER_MODE	0xe5	/* check power mode */
10466f9d5cbSmlf 
10566f9d5cbSmlf #define	SATA_PWRMODE_STANDBY		0	/* standby mode */
10666f9d5cbSmlf #define	SATA_PWRMODE_IDLE		0x80	/* idle mode */
1072ee4dfc7SJane Chu #define	SATA_PWRMODE_ACTIVE_SPINDOWN	0x40	/* PM0 and spinning down */
1082ee4dfc7SJane Chu #define	SATA_PWRMODE_ACTIVE_SPINUP	0x41	/* PM0 and spinning up */
1092ee4dfc7SJane Chu #define	SATA_PWRMODE_ACTIVE		0xFF	/* active or idle mode */
11066f9d5cbSmlf 
11166f9d5cbSmlf 
11266f9d5cbSmlf /*
113c03acfcaSls24207  * SMART FEATURES Subcommands
114c03acfcaSls24207  */
115c03acfcaSls24207 #define	SATA_SMART_READ_DATA		0xd0
116c03acfcaSls24207 #define	SATA_SMART_ATTR_AUTOSAVE	0xd2
117c03acfcaSls24207 #define	SATA_SMART_EXECUTE_OFFLINE_IMM	0xd4
118c03acfcaSls24207 #define	SATA_SMART_READ_LOG		0xd5
119c03acfcaSls24207 #define	SATA_SMART_WRITE_LOG		0xd6
120c03acfcaSls24207 #define	SATA_SMART_ENABLE_OPS		0xd8
121c03acfcaSls24207 #define	SATA_SMART_DISABLE_OPS		0xd9
122c03acfcaSls24207 #define	SATA_SMART_RETURN_STATUS	0xda
123c03acfcaSls24207 
124c03acfcaSls24207 /*
12566f9d5cbSmlf  * SET FEATURES Subcommands
12666f9d5cbSmlf  */
12766f9d5cbSmlf #define	SATAC_SF_ENABLE_WRITE_CACHE	0x02
12866f9d5cbSmlf #define	SATAC_SF_TRANSFER_MODE		0x03
1292038334aSUnknown #define	SATAC_SF_DISABLE_RMSN		0x31
130b8b2574eSls24207 #define	SATAC_SF_ENABLE_ACOUSTIC	0x42
13166f9d5cbSmlf #define	SATAC_SF_DISABLE_READ_AHEAD	0x55
13266f9d5cbSmlf #define	SATAC_SF_DISABLE_WRITE_CACHE	0x82
13366f9d5cbSmlf #define	SATAC_SF_ENABLE_READ_AHEAD	0xaa
134b8b2574eSls24207 #define	SATAC_SF_DISABLE_ACOUSTIC	0xc2
1352038334aSUnknown #define	SATAC_SF_ENABLE_RMSN		0x95
13666f9d5cbSmlf 
13766f9d5cbSmlf /*
13866f9d5cbSmlf  * SET FEATURES transfer mode values
13966f9d5cbSmlf  */
14066f9d5cbSmlf #define	SATAC_TRANSFER_MODE_PIO_DEFAULT		0x00
14166f9d5cbSmlf #define	SATAC_TRANSFER_MODE_PIO_DISABLE_IODRY	0x01
14266f9d5cbSmlf #define	SATAC_TRANSFER_MODE_PIO_FLOW_CONTROL	0x08
14366f9d5cbSmlf #define	SATAC_TRANSFER_MODE_MULTI_WORD_DMA	0x20
14466f9d5cbSmlf #define	SATAC_TRANSFER_MODE_ULTRA_DMA		0x40
14566f9d5cbSmlf 
146a022fe3eSls24207 /*
147a022fe3eSls24207  * Download microcode subcommands
148a022fe3eSls24207  */
149a022fe3eSls24207 #define	SATA_DOWNLOAD_MCODE_TEMP	1	/* Revert on/ reset/pwr cycle */
150a022fe3eSls24207 #define	SATA_DOWNLOAD_MCODE_SAVE	7	/* No offset, keep mcode */
151a022fe3eSls24207 
152a022fe3eSls24207 
15366f9d5cbSmlf /* Generic ATA definitions */
15466f9d5cbSmlf 
155489f952bSls24207 #define	SATA_TAG_QUEUING_SHIFT 3
15637a077efSls24207 #define	SATA_TAG_QUEUING_MASK 0x1f
15766f9d5cbSmlf /*
15866f9d5cbSmlf  * Identify Device data
1592038334aSUnknown  * Although both ATA and ATAPI devices' Identify Data have the same length,
16066f9d5cbSmlf  * some words have different meaning/content and/or are irrelevant for
16166f9d5cbSmlf  * other type of device.
16266f9d5cbSmlf  * Following is the ATA Device Identify data layout
16366f9d5cbSmlf  */
16466f9d5cbSmlf typedef struct sata_id {
16566f9d5cbSmlf /*					WORD				  */
16666f9d5cbSmlf /*					OFFSET COMMENT			  */
16766f9d5cbSmlf 	ushort_t  ai_config;	   /*   0  general configuration bits	  */
16866f9d5cbSmlf 	ushort_t  ai_fixcyls;	   /*   1  # of cylinders (obsolete)	  */
16966f9d5cbSmlf 	ushort_t  ai_resv0;	   /*   2  # reserved			  */
17066f9d5cbSmlf 	ushort_t  ai_heads;	   /*   3  # of heads (obsolete)	  */
17166f9d5cbSmlf 	ushort_t  ai_trksiz;	   /*   4  # of bytes/track (retired)	  */
17266f9d5cbSmlf 	ushort_t  ai_secsiz;	   /*   5  # of bytes/sector (retired)	  */
17366f9d5cbSmlf 	ushort_t  ai_sectors;	   /*   6  # of sectors/track (obsolete)  */
17466f9d5cbSmlf 	ushort_t  ai_resv1[3];	   /*   7  "Vendor Unique"		  */
17566f9d5cbSmlf 	char	ai_drvser[20];	   /*  10  Serial number		  */
17666f9d5cbSmlf 	ushort_t ai_buftype;	   /*  20  Buffer type			  */
17766f9d5cbSmlf 	ushort_t ai_bufsz;	   /*  21  Buffer size in 512 byte incr   */
17866f9d5cbSmlf 	ushort_t ai_ecc;	   /*  22  # of ecc bytes avail on rd/wr  */
17966f9d5cbSmlf 	char	ai_fw[8];	   /*  23  Firmware revision		  */
18066f9d5cbSmlf 	char	ai_model[40];	   /*  27  Model #			  */
18166f9d5cbSmlf 	ushort_t ai_mult1;	   /*  47  Multiple command flags	  */
18266f9d5cbSmlf 	ushort_t ai_dwcap;	   /*  48  Doubleword capabilities	  */
18366f9d5cbSmlf 	ushort_t ai_cap;	   /*  49  Capabilities			  */
18466f9d5cbSmlf 	ushort_t ai_resv2;	   /*  50  Reserved			  */
18566f9d5cbSmlf 	ushort_t ai_piomode;	   /*  51  PIO timing mode		  */
18666f9d5cbSmlf 	ushort_t ai_dmamode;	   /*  52  DMA timing mode		  */
18766f9d5cbSmlf 	ushort_t ai_validinfo;	   /*  53  bit0: wds 54-58, bit1: 64-70	  */
18866f9d5cbSmlf 	ushort_t ai_curcyls;	   /*  54  # of current cylinders	  */
18966f9d5cbSmlf 	ushort_t ai_curheads;	   /*  55  # of current heads		  */
19066f9d5cbSmlf 	ushort_t ai_cursectrk;	   /*  56  # of current sectors/track	  */
19166f9d5cbSmlf 	ushort_t ai_cursccp[2];	   /*  57  current sectors capacity	  */
19266f9d5cbSmlf 	ushort_t ai_mult2;	   /*  59  multiple sectors info	  */
19366f9d5cbSmlf 	ushort_t ai_addrsec[2];	   /*  60  LBA only: no of addr secs	  */
1942038334aSUnknown 	ushort_t ai_dirdma;	   /*  62  valid in ATA/ATAPI7, DMADIR	  */
1952038334aSUnknown 	ushort_t ai_dworddma;	   /*  63  multi word dma modes	  */
19666f9d5cbSmlf 	ushort_t ai_advpiomode;	   /*  64  advanced PIO modes supported	  */
19766f9d5cbSmlf 	ushort_t ai_minmwdma;	   /*  65  min multi-word dma cycle info  */
19866f9d5cbSmlf 	ushort_t ai_recmwdma;	   /*  66  rec multi-word dma cycle info  */
19966f9d5cbSmlf 	ushort_t ai_minpio;	   /*  67  min PIO cycle info		  */
20066f9d5cbSmlf 	ushort_t ai_minpioflow;	   /*  68  min PIO cycle info w/flow ctl  */
201fcacecd0SPhi Tran 	ushort_t ai_addsupported;  /*  69  additional supported		  */
202fcacecd0SPhi Tran 	ushort_t ai_resv3;	   /*  70 reserved			  */
20366f9d5cbSmlf 	ushort_t ai_typtime[2];	   /* 71-72 timing			  */
20466f9d5cbSmlf 	ushort_t ai_resv4[2];	   /* 73-74 reserved			  */
20566f9d5cbSmlf 	ushort_t ai_qdepth;	   /*  75  queue depth			  */
20666f9d5cbSmlf 	ushort_t ai_satacap;	   /*  76  SATA capabilities		  */
20766f9d5cbSmlf 	ushort_t ai_resv5;	   /*  77 reserved			  */
20866f9d5cbSmlf 	ushort_t ai_satafsup;	   /*  78 SATA features supported	  */
20966f9d5cbSmlf 	ushort_t ai_satafenbl;	   /*  79 SATA features enabled		  */
21066f9d5cbSmlf 	ushort_t ai_majorversion;  /*  80  major versions supported	  */
21166f9d5cbSmlf 	ushort_t ai_minorversion;  /*  81  minor version number supported */
21266f9d5cbSmlf 	ushort_t ai_cmdset82;	   /*  82  command set supported	  */
21366f9d5cbSmlf 	ushort_t ai_cmdset83;	   /*  83  more command sets supported	  */
21466f9d5cbSmlf 	ushort_t ai_cmdset84;	   /*  84  more command sets supported	  */
21566f9d5cbSmlf 	ushort_t ai_features85;	   /*  85 enabled features		  */
21666f9d5cbSmlf 	ushort_t ai_features86;	   /*  86 enabled features		  */
21766f9d5cbSmlf 	ushort_t ai_features87;	   /*  87 enabled features		  */
21866f9d5cbSmlf 	ushort_t ai_ultradma;	   /*  88 Ultra DMA mode		  */
21966f9d5cbSmlf 	ushort_t ai_erasetime;	   /*  89 security erase time		  */
22066f9d5cbSmlf 	ushort_t ai_erasetimex;	   /*  90 enhanced security erase time	  */
221c03acfcaSls24207 	ushort_t ai_adv_pwr_mgmt;  /*  91 advanced power management time  */
222c03acfcaSls24207 	ushort_t ai_master_pwd;    /*  92 master password revision code   */
223c03acfcaSls24207 	ushort_t ai_hrdwre_reset;  /*  93 hardware reset result		  */
224c03acfcaSls24207 	ushort_t ai_acoustic;	   /*  94 accoustic management values	  */
225c03acfcaSls24207 	ushort_t ai_stream_min_sz; /*  95 stream minimum request size	  */
226c03acfcaSls24207 	ushort_t ai_stream_xfer_d; /*  96 streaming transfer time (DMA)   */
227c03acfcaSls24207 	ushort_t ai_stream_lat;    /*  97 streaming access latency	  */
228c03acfcaSls24207 	ushort_t ai_streamperf[2]; /* 98-99 streaming performance gran.   */
22966f9d5cbSmlf 	ushort_t ai_addrsecxt[4];  /* 100 extended max LBA sector	  */
230c03acfcaSls24207 	ushort_t ai_stream_xfer_p; /* 104 streaming transfer time (PIO)   */
231fcacecd0SPhi Tran 	ushort_t ai_maxcount;	   /* 105 max count of 512-byte blocks of */
232fcacecd0SPhi Tran 				    /* LBA range entries		  */
233c03acfcaSls24207 	ushort_t ai_phys_sect_sz;  /* 106 physical sector size		  */
234c03acfcaSls24207 	ushort_t ai_seek_delay;	   /* 107 inter-seek delay time (usecs)	  */
235c03acfcaSls24207 	ushort_t ai_naa_ieee_oui;  /* 108 NAA/IEEE OUI			  */
236c03acfcaSls24207 	ushort_t ai_ieee_oui_uid;  /* 109 IEEE OUT/unique id		  */
237c03acfcaSls24207 	ushort_t ai_uid_mid;	   /* 110 unique id (mid)		  */
238c03acfcaSls24207 	ushort_t ai_uid_low;	   /* 111 unique id (low)		  */
239c03acfcaSls24207 	ushort_t ai_resv_wwn[4];   /* 112-115 reserved for WWN ext.	  */
240c03acfcaSls24207 	ushort_t ai_incits;	   /* 116 reserved for INCITS TR-37-2004  */
241c03acfcaSls24207 	ushort_t ai_words_lsec[2]; /* 117-118 words per logical sector	  */
242c03acfcaSls24207 	ushort_t ai_cmdset119;	   /* 119 more command sets supported	  */
243c03acfcaSls24207 	ushort_t ai_features120;   /* 120 enabled features		  */
244fcacecd0SPhi Tran 	ushort_t ai_padding1[6];   /* pad to 126			  */
245c03acfcaSls24207 	ushort_t ai_rmsn;	   /* 127 removable media notification	  */
24666f9d5cbSmlf 	ushort_t ai_securestatus;  /* 128 security status		  */
24766f9d5cbSmlf 	ushort_t ai_vendor[31];	   /* 129-159 vendor specific		  */
248fcacecd0SPhi Tran 	ushort_t ai_padding2[8];   /* 160 pad to 168			  */
2497063fd1bSPhi Tran 	ushort_t ai_nomformfactor; /* 168 nominal form factor		  */
250fcacecd0SPhi Tran 	ushort_t ai_dsm;	   /* 169 data set management		  */
251fcacecd0SPhi Tran 	ushort_t ai_padding3[6];   /* 170 pad to 176			  */
252c03acfcaSls24207 	ushort_t ai_curmedser[30]; /* 176-205 current media serial #	  */
253c03acfcaSls24207 	ushort_t ai_sctsupport;	   /* 206 SCT command transport		  */
254fcacecd0SPhi Tran 	ushort_t ai_padding4[10];  /* 207 pad to 217			  */
2557063fd1bSPhi Tran 	ushort_t ai_medrotrate;	   /* 217 nominal media rotation rate	  */
256fcacecd0SPhi Tran 	ushort_t ai_padding5[37];  /* 218 pad to 255			  */
25766f9d5cbSmlf 	ushort_t ai_integrity;	   /* 255 integrity word		  */
25866f9d5cbSmlf } sata_id_t;
25966f9d5cbSmlf 
26066f9d5cbSmlf 
26166f9d5cbSmlf /* Identify Device: general config bits  - word 0 */
26266f9d5cbSmlf 
26366f9d5cbSmlf #define	SATA_ATA_TYPE_MASK	0x8001	/* ATA Device type mask */
26466f9d5cbSmlf #define	SATA_ATA_TYPE		0x0000	/* ATA device */
26566f9d5cbSmlf #define	SATA_REM_MEDIA		0x0080	/* Removable media */
266789ba267Spawelw #define	SATA_INCOMPLETE_DATA	0x0004	/* Incomplete Identify Device data */
2672ce278ebSying tian - Beijing China #define	SATA_CFA_TYPE		0x848a	/* CFA feature set device */
26866f9d5cbSmlf 
26966f9d5cbSmlf #define	SATA_ID_SERIAL_OFFSET	10
27066f9d5cbSmlf #define	SATA_ID_SERIAL_LEN	20
27166f9d5cbSmlf #define	SATA_ID_MODEL_OFFSET	27
27266f9d5cbSmlf #define	SATA_ID_MODEL_LEN	40
273184cd04cScth #define	SATA_ID_FW_LEN		8
2747063fd1bSPhi Tran #define	SATA_ID_BDC_LEN		0x3c
275d996f1b8SPhi Tran #define	SATA_ID_ATA_INFO_LEN	0x238
27666f9d5cbSmlf 
27766f9d5cbSmlf /* Identify Device: common capability bits - word 49 */
27866f9d5cbSmlf 
27966f9d5cbSmlf #define	SATA_DMA_SUPPORT	0x0100
28066f9d5cbSmlf #define	SATA_LBA_SUPPORT	0x0200
28166f9d5cbSmlf #define	SATA_IORDY_DISABLE	0x0400
28266f9d5cbSmlf #define	SATA_IORDY_SUPPORT	0x0800
28366f9d5cbSmlf #define	SATA_STANDBYTIMER	0x2000
28466f9d5cbSmlf 
28566f9d5cbSmlf /* Identify Device: ai_validinfo (word 53) */
28666f9d5cbSmlf 
28766f9d5cbSmlf #define	SATA_VALIDINFO_88	0x0004	/* word 88 supported fields valid */
2882038334aSUnknown #define	SATA_VALIDINFO_70_64	0x0004	/* words 70-64 fields valid */
28966f9d5cbSmlf 
290fcacecd0SPhi Tran /* Identify Device: ai_addsupported (word 69) */
291fcacecd0SPhi Tran 
292fcacecd0SPhi Tran #define	SATA_DETERMINISTIC_READ	0x4000	/* word 69 deterministic read supp. */
293fcacecd0SPhi Tran #define	SATA_READ_ZERO		0x0020	/* word 69 read zero after TRIM supp. */
294fcacecd0SPhi Tran 
29566f9d5cbSmlf /* Identify Device: ai_majorversion (word 80) */
29666f9d5cbSmlf 
2972038334aSUnknown #define	SATA_MAJVER_7		0x0080	/* ATA/ATAPI-7 version supported */
2982038334aSUnknown #define	SATA_MAJVER_654		0x0070	/* ATA/ATAPI-6,5 or 4 ver supported */
29966f9d5cbSmlf #define	SATA_MAJVER_6		0x0040	/* ATA/ATAPI-6 version supported */
3002038334aSUnknown #define	SATA_MAJVER_5		0x0020	/* ATA/ATAPI-7 version supported */
30166f9d5cbSmlf #define	SATA_MAJVER_4		0x0010	/* ATA/ATAPI-4 version supported */
30266f9d5cbSmlf 
30366f9d5cbSmlf /* Identify Device: command set supported/enabled bits - words 83 and 86 */
30466f9d5cbSmlf 
30566f9d5cbSmlf #define	SATA_EXT48		0x0400	/* 48 bit address feature */
3062038334aSUnknown #define	SATA_PWRUP_IN_STANDBY	0x0020	/* Power-up in standby mode supp/en */
3072038334aSUnknown #define	SATA_RM_STATUS_NOTIFIC	0x0010	/* Removable Media Stat Notification */
30866f9d5cbSmlf #define	SATA_RW_DMA_QUEUED_CMD	0x0002	/* R/W DMA Queued supported */
30966f9d5cbSmlf #define	SATA_DWNLOAD_MCODE_CMD	0x0001	/* Download Microcode CMD supp/enbld */
310b8b2574eSls24207 #define	SATA_ACOUSTIC_MGMT	0x0200	/* Acoustic Management features */
31166f9d5cbSmlf 
31266f9d5cbSmlf /* Identify Device: command set supported/enabled bits - words 82 and 85 */
31366f9d5cbSmlf 
314c03acfcaSls24207 #define	SATA_SMART_SUPPORTED	0x0001	/* SMART feature set is supported */
31566f9d5cbSmlf #define	SATA_WRITE_CACHE	0x0020	/* Write Cache supported/enabled */
31666f9d5cbSmlf #define	SATA_LOOK_AHEAD		0x0040	/* Look Ahead supported/enabled */
31766f9d5cbSmlf #define	SATA_DEVICE_RESET_CMD	0x0200	/* Device Reset CMD supported/enbld */
31866f9d5cbSmlf #define	SATA_READ_BUFFER_CMD	0x2000	/* Read Buffer CMD supported/enbld */
31966f9d5cbSmlf #define	SATA_WRITE_BUFFER_CMD	0x1000	/* Write Buffer CMD supported/enbld */
320c03acfcaSls24207 #define	SATA_SMART_ENABLED	0x0001	/* SMART feature set is enabled */
321c03acfcaSls24207 
322c03acfcaSls24207 /* Identify Device: command set supported/enabled bits - words 84 & 87 */
323c03acfcaSls24207 #define	SATA_SMART_SELF_TEST_SUPPORTED	0x0002	/* SMART self-test supported */
3242ee4dfc7SJane Chu /* IDLE IMMEDIATE with UNLOAD FEATURE supported */
3252ee4dfc7SJane Chu #define	SATA_IDLE_UNLOAD_SUPPORTED	0x2000
32666f9d5cbSmlf 
3270bc523e5SAlan Perry /* Identify Device: physical sector size - word 106 */
3280bc523e5SAlan Perry #define	SATA_L2PS_CHECK_BIT	0x4000	/* Set when this word valid */
3290bc523e5SAlan Perry #define	SATA_L2PS_HAS_MULT	0x2000	/* Multiple logical sectors per phys */
3300bc523e5SAlan Perry #define	SATA_L2PS_BIG_SECTORS	0x1000	/* Logical sector size > 512 */
3310bc523e5SAlan Perry #define	SATA_L2PS_EXP_MASK	0x000f	/* Logical sectors per phys exponent */
3320bc523e5SAlan Perry 
3332038334aSUnknown /* Identify (Packet) Device word 63,  ATA/ATAPI-6 & 7 */
33466f9d5cbSmlf #define	SATA_MDMA_SEL_MASK	0x0700	/* Multiword DMA selected */
33566f9d5cbSmlf #define	SATA_MDMA_2_SEL		0x0400	/* Multiword DMA mode 2 selected */
33666f9d5cbSmlf #define	SATA_MDMA_1_SEL		0x0200	/* Multiword DMA mode 1 selected */
33766f9d5cbSmlf #define	SATA_MDMA_0_SEL		0x0100	/* Multiword DMA mode 0 selected */
33866f9d5cbSmlf #define	SATA_MDMA_2_SUP		0x0004	/* Multiword DMA mode 2 supported */
33966f9d5cbSmlf #define	SATA_MDMA_1_SUP		0x0002	/* Multiword DMA mode 1 supported */
34066f9d5cbSmlf #define	SATA_MDMA_0_SUP		0x0001	/* Multiword DMA mode 0 supported */
3412038334aSUnknown #define	SATA_MDMA_SUP_MASK	0x0007	/* Multiword DMA supported */
3422038334aSUnknown 
3432038334aSUnknown /* Identify (Packet) Device Word 88 */
3442038334aSUnknown #define	SATA_UDMA_SUP_MASK		0x007f	/* UDMA modes supported */
3452038334aSUnknown #define	SATA_UDMA_SEL_MASK	0x7f00	/* UDMA modes selected */
34666f9d5cbSmlf 
347c03acfcaSls24207 /* Identify Device: command set supported/enabled bits - word 206 */
348c03acfcaSls24207 
349c03acfcaSls24207 /* All are SCT Command Transport support */
350c03acfcaSls24207 #define	SATA_SCT_CMD_TRANS_SUP		0x0001	/* anything */
351c03acfcaSls24207 #define	SATA_SCT_CMD_TRANS_LNG_SECT_SUP	0x0002	/* Long Sector Access */
352c03acfcaSls24207 #define	SATA_SCT_CMD_TRANS_WR_SAME_SUP	0x0004	/* Write Same */
353c03acfcaSls24207 #define	SATA_SCT_CMD_TRANS_ERR_RCOV_SUP	0x0008	/* Error Recovery Control */
354c03acfcaSls24207 #define	SATA_SCT_CMD_TRANS_FEAT_CTL_SUP	0x0010	/* Features Control */
355c03acfcaSls24207 #define	SATA_SCT_CMD_TRANS_DATA_TBL_SUP	0x0020	/* Data Tables supported */
356c03acfcaSls24207 
35766f9d5cbSmlf #define	SATA_DISK_SECTOR_SIZE	512	/* HD physical sector size */
35866f9d5cbSmlf 
35966f9d5cbSmlf /* Identify Packet Device data definitions (ATAPI devices) */
36066f9d5cbSmlf 
36166f9d5cbSmlf /* Identify Packet Device: general config bits  - word 0 */
36266f9d5cbSmlf 
36366f9d5cbSmlf #define	SATA_ATAPI_TYPE_MASK	0xc000
36466f9d5cbSmlf #define	SATA_ATAPI_TYPE		0x8000	/* ATAPI device */
36566f9d5cbSmlf #define	SATA_ATAPI_ID_PKT_SZ	0x0003	/* Packet size mask */
36666f9d5cbSmlf #define	SATA_ATAPI_ID_PKT_12B	0x0000  /* Packet size 12 bytes */
36766f9d5cbSmlf #define	SATA_ATAPI_ID_PKT_16B	0x0001  /* Packet size 16 bytes */
36866f9d5cbSmlf #define	SATA_ATAPI_ID_DRQ_TYPE	0x0060	/* DRQ asserted in 3ms after pkt */
36966f9d5cbSmlf #define	SATA_ATAPI_ID_DRQ_INTR	0x0020  /* Obsolete in ATA/ATAPI 7 */
37066f9d5cbSmlf 
371257c04ecSMarcel Telka #define	SATA_ATAPI_ID_DEV_TYPE	0x1f00	/* device type/command set mask */
37266f9d5cbSmlf #define	SATA_ATAPI_ID_DEV_SHFT	8
37366f9d5cbSmlf #define	SATA_ATAPI_DIRACC_DEV	0x0000	/* Direct Access device */
37466f9d5cbSmlf #define	SATA_ATAPI_SQACC_DEV	0x0100  /* Sequential access dev (tape ?) */
375257c04ecSMarcel Telka #define	SATA_ATAPI_PROC_DEV	0x0300	/* Processor device */
37666f9d5cbSmlf #define	SATA_ATAPI_CDROM_DEV	0x0500  /* CD_ROM device */
37766f9d5cbSmlf 
37866f9d5cbSmlf /*
37966f9d5cbSmlf  * Status bits from ATAPI Interrupt reason register (AT_COUNT) register
38066f9d5cbSmlf  */
38166f9d5cbSmlf #define	SATA_ATAPI_I_COD	0x01	/* Command or Data */
38266f9d5cbSmlf #define	SATA_ATAPI_I_IO		0x02	/* IO direction */
38366f9d5cbSmlf #define	SATA_ATAPI_I_RELEASE	0x04	/* Release for ATAPI overlap */
38466f9d5cbSmlf 
38566f9d5cbSmlf /* ATAPI feature reg definitions */
38666f9d5cbSmlf 
3872038334aSUnknown #define	SATA_ATAPI_F_DATA_DIR_READ 0x04	/* DMA transfer to the host */
3882038334aSUnknown #define	SATA_ATAPI_F_OVERLAP	0x02	/* Not used by Sun drivers */
3892038334aSUnknown #define	SATA_ATAPI_F_DMA	0x01	/* Packet DMA command */
39066f9d5cbSmlf 
39166f9d5cbSmlf 
3922038334aSUnknown /* ATAPI IDENTIFY_DRIVE capabilities word (49) */
3932038334aSUnknown 
3942038334aSUnknown #define	SATA_ATAPI_ID_CAP_DMA		0x0100 /* if zero, check word 62  */
3952038334aSUnknown #define	SATA_ATAPI_ID_CAP_OVERLAP	0x2000
3962038334aSUnknown 
39766f9d5cbSmlf /*
3982038334aSUnknown  * ATAPI Identify Packet Device word 62
3992038334aSUnknown  * Word 62 is not valid for ATA/ATAPI-6
4002038334aSUnknown  * Defs below are for ATA/ATAPI-7
40166f9d5cbSmlf  */
4022038334aSUnknown #define	SATA_ATAPI_ID_DMADIR_REQ	0x8000 /* DMA direction required */
4032038334aSUnknown #define	SATA_ATAPI_ID_DMA_SUP		0x0400 /* DMA is supported */
40466f9d5cbSmlf 
40566f9d5cbSmlf /*
40666f9d5cbSmlf  * ATAPI signature bits
40766f9d5cbSmlf  */
40866f9d5cbSmlf #define	SATA_ATAPI_SIG_HI	0xeb	/* in high cylinder register */
40966f9d5cbSmlf #define	SATA_ATAPI_SIG_LO	0x14	/* in low cylinder register */
41066f9d5cbSmlf 
41166f9d5cbSmlf /* These values are pre-set for CD_ROM/DVD ? */
41266f9d5cbSmlf 
41366f9d5cbSmlf #define	SATA_ATAPI_SECTOR_SIZE		2048
41466f9d5cbSmlf #define	SATA_ATAPI_MAX_BYTES_PER_DRQ	0xf800 /* 16 bits - 2KB  ie 62KB */
41566f9d5cbSmlf #define	SATA_ATAPI_HEADS		64
41666f9d5cbSmlf #define	SATA_ATAPI_SECTORS_PER_TRK	32
41766f9d5cbSmlf 
41866f9d5cbSmlf /* SATA Capabilites bits (word 76) */
41966f9d5cbSmlf 
42066f9d5cbSmlf #define	SATA_NCQ		0x100
421*13c8743eSMarcel Telka #define	SATA_3_SPEED		0x008
42266f9d5cbSmlf #define	SATA_2_SPEED		0x004
42366f9d5cbSmlf #define	SATA_1_SPEED		0x002
42466f9d5cbSmlf 
42566f9d5cbSmlf /* SATA Features Supported (word 78) - not used */
42666f9d5cbSmlf 
42766f9d5cbSmlf /* SATA Features Enabled (word 79) - not used */
42866f9d5cbSmlf 
4297095af19Sying tian - Beijing China #define	SATA_READ_AHEAD_SUPPORTED(x)	((x).ai_cmdset82 & SATA_LOOK_AHEAD)
4307095af19Sying tian - Beijing China #define	SATA_READ_AHEAD_ENABLED(x)	((x).ai_features85 & SATA_LOOK_AHEAD)
4317095af19Sying tian - Beijing China #define	SATA_WRITE_CACHE_SUPPORTED(x)	((x).ai_cmdset82 & SATA_WRITE_CACHE)
4327095af19Sying tian - Beijing China #define	SATA_WRITE_CACHE_ENABLED(x)	((x).ai_features85 & SATA_WRITE_CACHE)
4337095af19Sying tian - Beijing China #define	SATA_RM_NOTIFIC_SUPPORTED(x)	\
4347095af19Sying tian - Beijing China 	((x).ai_cmdset83 & SATA_RM_STATUS_NOTIFIC)
4357095af19Sying tian - Beijing China #define	SATA_RM_NOTIFIC_ENABLED(x)	\
4367095af19Sying tian - Beijing China 	((x).ai_features86 & SATA_RM_STATUS_NOTIFIC)
4377095af19Sying tian - Beijing China 
43866f9d5cbSmlf /*
4394e540238Sls24207  * Generic NCQ related defines
4404e540238Sls24207  */
4414e540238Sls24207 
4424e540238Sls24207 #define	NQ			0x80	/* Not a queued cmd - tag not valid */
4434e540238Sls24207 #define	NCQ_TAG_MASK		0x1f	/* NCQ command tag mask */
4444e540238Sls24207 #define	FIS_TYPE_REG_H2D	0x27	/* Reg FIS - Host to Device */
4454e540238Sls24207 #define	FIS_CMD_UPDATE		0x80
4464e540238Sls24207 /*
44766f9d5cbSmlf  * Status bits from AT_STATUS register
44866f9d5cbSmlf  */
44966f9d5cbSmlf #define	SATA_STATUS_BSY		0x80    /* controller busy */
45066f9d5cbSmlf #define	SATA_STATUS_DRDY	0x40    /* drive ready	*/
45166f9d5cbSmlf #define	SATA_STATUS_DF		0x20    /* device fault	*/
45266f9d5cbSmlf #define	SATA_STATUS_DSC		0x10    /* seek operation complete */
45366f9d5cbSmlf #define	SATA_STATUS_DRQ		0x08	/* data request */
45466f9d5cbSmlf #define	SATA_STATUS_CORR	0x04    /* obsolete */
45566f9d5cbSmlf #define	SATA_STATUS_IDX		0x02    /* obsolete */
45666f9d5cbSmlf #define	SATA_STATUS_ERR		0x01    /* error flag */
45766f9d5cbSmlf 
45866f9d5cbSmlf /*
45966f9d5cbSmlf  * Status bits from AT_ERROR register
46066f9d5cbSmlf  */
46166f9d5cbSmlf #define	SATA_ERROR_ICRC		0x80	/* CRC data transfer error detected */
46266f9d5cbSmlf #define	SATA_ERROR_UNC		0x40	/* uncorrectable data error */
46366f9d5cbSmlf #define	SATA_ERROR_MC		0x20    /* Media change	*/
46466f9d5cbSmlf #define	SATA_ERROR_IDNF		0x10    /* ID/Address not found	*/
46566f9d5cbSmlf #define	SATA_ERROR_MCR		0x08	/* media change request	*/
46666f9d5cbSmlf #define	SATA_ERROR_ABORT	0x04    /* aborted command */
46766f9d5cbSmlf #define	SATA_ERROR_NM		0x02	/* no media */
46866f9d5cbSmlf #define	SATA_ERROR_EOM		0x02    /* end of media (Packet cmds) */
46966f9d5cbSmlf #define	SATA_ERROR_ILI		0x01    /* cmd sepcific */
47066f9d5cbSmlf 
471c03acfcaSls24207 
472c03acfcaSls24207 /*
473c03acfcaSls24207  * Bits from the device control register
474c03acfcaSls24207  */
475c03acfcaSls24207 #define	SATA_DEVCTL_NIEN	0x02	/* not interrupt enabled */
476c03acfcaSls24207 #define	SATA_DEVCTL_SRST	0x04	/* software reset */
477c03acfcaSls24207 #define	SATA_DEVCTL_HOB		0x80	/* high order bit */
478c03acfcaSls24207 
47966f9d5cbSmlf /* device_reg */
48066f9d5cbSmlf #define	SATA_ADH_LBA		0x40	/* addressing in LBA mode not chs */
48166f9d5cbSmlf 
4822038334aSUnknown /* ATAPI transport version-in Inquiry data */
4832038334aSUnknown #define	SATA_ATAPI_TRANS_VERSION(inq) \
4842038334aSUnknown 	(*((uint8_t *)(inq) + 3) >> 4)
485c03acfcaSls24207 
486c03acfcaSls24207 #define	SCSI_LOG_PAGE_HDR_LEN	4	/* # bytes of a SCSI log page header */
487c03acfcaSls24207 #define	SCSI_LOG_PARAM_HDR_LEN	4	/* # byttes of a SCSI log param hdr */
488c03acfcaSls24207 
489c03acfcaSls24207 /* Number of log entries per extended selftest log block */
490c03acfcaSls24207 #define	ENTRIES_PER_EXT_SELFTEST_LOG_BLK	19
491c03acfcaSls24207 
492c03acfcaSls24207 /* Number of entries per SCSI LOG SENSE SELFTEST RESULTS page */
493c03acfcaSls24207 #define	SCSI_ENTRIES_IN_LOG_SENSE_SELFTEST_RESULTS	20
494c03acfcaSls24207 
495c03acfcaSls24207 /* Length of a SCSI LOG SENSE SELFTEST RESULTS parameter */
496c03acfcaSls24207 #define	SCSI_LOG_SENSE_SELFTEST_PARAM_LEN	0x10
497c03acfcaSls24207 
498c03acfcaSls24207 #define	DIAGNOSTIC_FAILURE_ON_COMPONENT	0x40
499c03acfcaSls24207 
500c03acfcaSls24207 #define	SCSI_COMPONENT_81	0x81
501c03acfcaSls24207 #define	SCSI_COMPONENT_82	0x82
502c03acfcaSls24207 #define	SCSI_COMPONENT_83	0x83
503c03acfcaSls24207 #define	SCSI_COMPONENT_84	0x84
504c03acfcaSls24207 #define	SCSI_COMPONENT_85	0x85
505c03acfcaSls24207 #define	SCSI_COMPONENT_86	0x86
506c03acfcaSls24207 #define	SCSI_COMPONENT_87	0x87
507c03acfcaSls24207 #define	SCSI_COMPONENT_88	0x88
508c03acfcaSls24207 
509c03acfcaSls24207 #define	SCSI_ASC_ATA_DEV_FEAT_NOT_ENABLED	0x67
510c03acfcaSls24207 #define	SCSI_ASCQ_ATA_DEV_FEAT_NOT_ENABLED	0x0b
511c03acfcaSls24207 
512c03acfcaSls24207 #define	SCSI_PREDICTED_FAILURE	0x5d
513c03acfcaSls24207 #define	SCSI_GENERAL_HD_FAILURE	0x10
514c03acfcaSls24207 
515489f952bSls24207 #define	SCSI_INFO_EXCEPTIONS_PARAM_LEN	4
516c03acfcaSls24207 
517c03acfcaSls24207 #define	READ_LOG_EXT_LOG_DIRECTORY	0
51837a077efSls24207 #define	READ_LOG_EXT_NCQ_ERROR_RECOVERY	0x10
519c03acfcaSls24207 #define	SMART_SELFTEST_LOG_PAGE		6
520c03acfcaSls24207 #define	EXT_SMART_SELFTEST_LOG_PAGE	7
52137a077efSls24207 
52237a077efSls24207 /*
52337a077efSls24207  * SATA NCQ error recovery page (0x10)
52437a077efSls24207  */
52537a077efSls24207 struct sata_ncq_error_recovery_page {
52637a077efSls24207 	uint8_t	ncq_tag;
52737a077efSls24207 	uint8_t reserved1;
52837a077efSls24207 	uint8_t ncq_status;
52937a077efSls24207 	uint8_t ncq_error;
53037a077efSls24207 	uint8_t ncq_sector_number;
53137a077efSls24207 	uint8_t ncq_cyl_low;
53237a077efSls24207 	uint8_t ncq_cyl_high;
53337a077efSls24207 	uint8_t ncq_dev_head;
53437a077efSls24207 	uint8_t ncq_sector_number_ext;
53537a077efSls24207 	uint8_t ncq_cyl_low_ext;
53637a077efSls24207 	uint8_t ncq_cyl_high_ext;
53737a077efSls24207 	uint8_t reserved2;
53837a077efSls24207 	uint8_t ncq_sector_count;
53937a077efSls24207 	uint8_t ncq_sector_count_ext;
54037a077efSls24207 	uint8_t reserved3[242];
54137a077efSls24207 	uint8_t ncq_vendor_unique[255];
54237a077efSls24207 	uint8_t ncq_checksum;
54337a077efSls24207 };
54437a077efSls24207 
5452ee4dfc7SJane Chu /* SMART attribute of Start/Stop Count */
5462ee4dfc7SJane Chu #define	SMART_START_STOP_COUNT_ID	0x4
5472ee4dfc7SJane Chu 
548c03acfcaSls24207 /*
549c03acfcaSls24207  * SMART data structures
550c03acfcaSls24207  */
551c03acfcaSls24207 struct smart_data {
552c03acfcaSls24207 	uint8_t smart_vendor_specific[362];
553c03acfcaSls24207 	uint8_t smart_offline_data_collection_status;
554c03acfcaSls24207 	uint8_t smart_selftest_exec_status;
555c03acfcaSls24207 	uint8_t smart_secs_to_complete_offline_data[2];
556c03acfcaSls24207 	uint8_t smart_vendor_specific2;
557c03acfcaSls24207 	uint8_t smart_offline_data_collection_capability;
558c03acfcaSls24207 	uint8_t smart_capability[2];
559c03acfcaSls24207 	uint8_t	smart_error_logging_capability;
560c03acfcaSls24207 	uint8_t smart_vendor_specific3;
561c03acfcaSls24207 	uint8_t smart_short_selftest_polling_time;
562c03acfcaSls24207 	uint8_t smart_extended_selftest_polling_time;
563c03acfcaSls24207 	uint8_t smart_conveyance_selftest_polling_time;
564c03acfcaSls24207 	uint8_t smart_reserved[11];
565c03acfcaSls24207 	uint8_t smart_vendor_specific4[125];
566c03acfcaSls24207 	uint8_t smart_checksum;
567c03acfcaSls24207 };
568c03acfcaSls24207 
569c03acfcaSls24207 struct smart_selftest_log_entry {
570c03acfcaSls24207 	uint8_t	smart_selftest_log_lba_low;
571c03acfcaSls24207 	uint8_t	smart_selftest_log_status;
572c03acfcaSls24207 	uint8_t	smart_selftest_log_timestamp[2];
573c03acfcaSls24207 	uint8_t smart_selftest_log_checkpoint;
574c03acfcaSls24207 	uint8_t smart_selftest_log_failing_lba[4];	/* from LSB to MSB */
575c03acfcaSls24207 	uint8_t smart_selftest_log_vendor_specific[15];
576c03acfcaSls24207 };
577c03acfcaSls24207 
578c03acfcaSls24207 #define	NUM_SMART_SELFTEST_LOG_ENTRIES	21
579c03acfcaSls24207 struct smart_selftest_log {
580c03acfcaSls24207 	uint8_t	smart_selftest_log_revision[2];
581c03acfcaSls24207 	struct	smart_selftest_log_entry
582c03acfcaSls24207 	    smart_selftest_log_entries[NUM_SMART_SELFTEST_LOG_ENTRIES];
583c03acfcaSls24207 	uint8_t	smart_selftest_log_vendor_specific[2];
584c03acfcaSls24207 	uint8_t smart_selftest_log_index;
585c03acfcaSls24207 	uint8_t smart_selftest_log_reserved[2];
586c03acfcaSls24207 	uint8_t smart_selftest_log_checksum;
587c03acfcaSls24207 };
588c03acfcaSls24207 
589c03acfcaSls24207 struct smart_ext_selftest_log_entry {
590c03acfcaSls24207 	uint8_t	smart_ext_selftest_log_lba_low;
591c03acfcaSls24207 	uint8_t smart_ext_selftest_log_status;
592c03acfcaSls24207 	uint8_t smart_ext_selftest_log_timestamp[2];
593c03acfcaSls24207 	uint8_t smart_ext_selftest_log_checkpoint;
594c03acfcaSls24207 	uint8_t smart_ext_selftest_log_failing_lba[6];
595c03acfcaSls24207 	uint8_t smart_ext_selftest_log_vendor_specific[15];
596c03acfcaSls24207 };
597c03acfcaSls24207 
598c03acfcaSls24207 struct smart_ext_selftest_log {
599c03acfcaSls24207 	uint8_t	smart_ext_selftest_log_rev;
600c03acfcaSls24207 	uint8_t	smart_ext_selftest_log_reserved;
601c03acfcaSls24207 	uint8_t	smart_ext_selftest_log_index[2];
602c03acfcaSls24207 	struct smart_ext_selftest_log_entry smart_ext_selftest_log_entries[19];
603c03acfcaSls24207 	uint8_t	smart_ext_selftest_log_vendor_specific[2];
604c03acfcaSls24207 	uint8_t	smart_ext_selftest_log_reserved2[11];
605c03acfcaSls24207 	uint8_t	smart_ext_selftest_log_checksum;
606c03acfcaSls24207 };
607c03acfcaSls24207 
608c03acfcaSls24207 struct read_log_ext_directory {
609c03acfcaSls24207 	uint8_t	read_log_ext_vers[2];	/* general purpose log version */
610489f952bSls24207 	uint8_t read_log_ext_nblks[255][2]; /* # of blks @ log addr index+1 */
611c03acfcaSls24207 };
612c03acfcaSls24207 
613c03acfcaSls24207 /*
6142ee4dfc7SJane Chu  * The definition of CONTROL byte field in SCSI command
6152ee4dfc7SJane Chu  * according to SAM 5
6162ee4dfc7SJane Chu  */
6172ee4dfc7SJane Chu #define	CTL_BYTE_VENDOR_MASK		0xc0
6182ee4dfc7SJane Chu #define	CTL_BYTE_NACA_MASK		0x04
6192ee4dfc7SJane Chu 
6202ee4dfc7SJane Chu /*
6212ee4dfc7SJane Chu  * The definition of mask in START STOP UNIT command
6222ee4dfc7SJane Chu  */
6232ee4dfc7SJane Chu #define	START_STOP_IMMED_MASK		0x01
6242ee4dfc7SJane Chu #define	START_STOP_POWER_COND_MASK	0xF0
6252ee4dfc7SJane Chu #define	START_STOP_START_MASK		0x01
6262ee4dfc7SJane Chu #define	START_STOP_LOEJ_MASK		0x02
6272ee4dfc7SJane Chu #define	START_STOP_NOFLUSH_MASK		0x04
6282ee4dfc7SJane Chu #define	START_STOP_MODIFIER_MASK	0x0f
6292ee4dfc7SJane Chu #define	START_STOP_POWER_COND_SHIFT	4
6302ee4dfc7SJane Chu 
6312ee4dfc7SJane Chu /*
632c03acfcaSls24207  * SMART specific data
6330bc523e5SAlan Perry  * These eventually need to go to a generic scsi header file
634c03acfcaSls24207  * for now they will reside here
635c03acfcaSls24207  */
63637a077efSls24207 #define	PC_CUMULATIVE_VALUES			0x01
637c03acfcaSls24207 #define	PAGE_CODE_GET_SUPPORTED_LOG_PAGES	0x00
638c03acfcaSls24207 #define	PAGE_CODE_SELF_TEST_RESULTS		0x10
639c03acfcaSls24207 #define	PAGE_CODE_INFORMATION_EXCEPTIONS	0x2f
640c03acfcaSls24207 #define	PAGE_CODE_SMART_READ_DATA		0x30
6412ee4dfc7SJane Chu #define	PAGE_CODE_START_STOP_CYCLE_COUNTER	0x0e
642c03acfcaSls24207 
643c03acfcaSls24207 
644c03acfcaSls24207 struct log_parameter {
645c03acfcaSls24207 	uint8_t param_code[2];		/* parameter dependant */
646c03acfcaSls24207 	uint8_t param_ctrl_flags;	/* see defines below */
647c03acfcaSls24207 	uint8_t param_len;		/* # of bytes following */
648c03acfcaSls24207 	uint8_t param_values[1];	/* # of bytes defined by param_len */
649c03acfcaSls24207 };
650c03acfcaSls24207 
651c03acfcaSls24207 /* param_ctrl_flag fields */
652c03acfcaSls24207 #define	LOG_CTRL_LP	0x01	/* list parameter */
653c03acfcaSls24207 #define	LOG_CTRL_LBIN	0x02	/* list is binary */
654c03acfcaSls24207 #define	LOG_CTRL_TMC	0x0c	/* threshold met criteria */
655c03acfcaSls24207 #define	LOG_CTRL_ETC	0x10	/* enable threshold comparison */
656c03acfcaSls24207 #define	LOG_CTRL_TSD	0x20	/* target save disable */
657c03acfcaSls24207 #define	LOG_CTRL_DS	0x40	/* disable save */
658c03acfcaSls24207 #define	LOG_CTRL_DU	0x80	/* disable update */
659c03acfcaSls24207 
660c03acfcaSls24207 #define	SMART_MAGIC_VAL_1	0x4f
661c03acfcaSls24207 #define	SMART_MAGIC_VAL_2	0xc2
662c03acfcaSls24207 #define	SMART_MAGIC_VAL_3	0xf4
663c03acfcaSls24207 #define	SMART_MAGIC_VAL_4	0x2c
664c03acfcaSls24207 
665c03acfcaSls24207 #define	SCT_STATUS_LOG_PAGE	0xe0
666c03acfcaSls24207 
667b8b2574eSls24207 /*
668b8b2574eSls24207  * Acoustic management
669b8b2574eSls24207  */
670b8b2574eSls24207 
671b8b2574eSls24207 struct mode_acoustic_management {
672b8b2574eSls24207 	struct mode_page	mode_page;	/* common mode page header */
673b8b2574eSls24207 	uchar_t	acoustic_manag_enable;	/* Set to 1 enable, Set 0 disable */
674b8b2574eSls24207 	uchar_t	acoustic_manag_level;	/* Acoustic management level	  */
675b8b2574eSls24207 	uchar_t	vendor_recommended_value; /* Vendor recommended value	  */
676b8b2574eSls24207 };
677b8b2574eSls24207 
678b8b2574eSls24207 #define	PAGELENGTH_DAD_MODE_ACOUSTIC_MANAGEMENT 3 /* Acoustic manag pg len */
679b8b2574eSls24207 #define	P_CNTRL_CURRENT		0
680b8b2574eSls24207 #define	P_CNTRL_CHANGEABLE	1
681b8b2574eSls24207 #define	P_CNTRL_DEFAULT		2
682b8b2574eSls24207 #define	P_CNTRL_SAVED		3
683b8b2574eSls24207 
684b8b2574eSls24207 #define	ACOUSTIC_DISABLED	0
685b8b2574eSls24207 #define	ACOUSTIC_ENABLED	1
686b8b2574eSls24207 
687b8b2574eSls24207 #define	MODEPAGE_ACOUSTIC_MANAG 0x30
688b8b2574eSls24207 
6898d483882Smlf /*
6908aa6aadbSXiao-Yu Zhang  * Port Multiplier registers' offsets
6918aa6aadbSXiao-Yu Zhang  */
6928aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_GSCR0		0x0
6938aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_GSCR1		0x1
6948aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_GSCR2		0x2
6958aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_GSCR32		0x20
6968aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_GSCR33		0x21
6978aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_GSCR64		0x40
6988aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_GSCR96		0x60
6998aa6aadbSXiao-Yu Zhang 
7008aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_PORTNUM_MASK		0xf
7018aa6aadbSXiao-Yu Zhang 
7028aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_PSCR0		0x0
7038aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_PSCR1		0x1
7048aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_PSCR2		0x2
7058aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_PSCR3		0x3
7068aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_PSCR4		0x4
7078aa6aadbSXiao-Yu Zhang 
7088aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_REG_SSTS		(SATA_PMULT_PSCR0)
7098aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_REG_SERR		(SATA_PMULT_PSCR1)
7108aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_REG_SCTL		(SATA_PMULT_PSCR2)
7118aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_REG_SACT		(SATA_PMULT_PSCR3)
7128aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_REG_SNTF		(SATA_PMULT_PSCR4)
7138aa6aadbSXiao-Yu Zhang 
7148aa6aadbSXiao-Yu Zhang /*
7158aa6aadbSXiao-Yu Zhang  * Port Multiplier capabilities
7168aa6aadbSXiao-Yu Zhang  * (Indicated by GSCR64, and enabled by GSCR96)
7178aa6aadbSXiao-Yu Zhang  */
7188aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_CAP_BIST		(1 << 0)
7198aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_CAP_PMREQ		(1 << 1)
7208aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_CAP_SSC		(1 << 2)
7218aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_CAP_SNOTIF		(1 << 3)
7228aa6aadbSXiao-Yu Zhang #define	SATA_PMULT_CAP_PHYEVENT		(1 << 4)
7238aa6aadbSXiao-Yu Zhang 
7248aa6aadbSXiao-Yu Zhang /*
7258d483882Smlf  * sstatus field definitions
7268d483882Smlf  */
7278d483882Smlf #define	SSTATUS_DET_SHIFT	0
7288d483882Smlf #define	SSTATUS_SPD_SHIFT	4
7298d483882Smlf #define	SSTATUS_IPM_SHIFT	8
7308d483882Smlf 
7318d483882Smlf #define	SSTATUS_DET	(0xf << SSTATUS_DET_SHIFT)
7328d483882Smlf #define	SSTATUS_SPD	(0xf << SSTATUS_SPD_SHIFT)
7338d483882Smlf #define	SSTATUS_IPM	(0xf << SSTATUS_IPM_SHIFT)
7348d483882Smlf 
7358d483882Smlf /*
7368d483882Smlf  * sstatus DET values
7378d483882Smlf  */
7388d483882Smlf #define	SSTATUS_DET_NODEV		0	/* No dev detected */
7398d483882Smlf #define	SSTATUS_DET_DEVPRE_NOPHYCOM	1	/* dev detected */
7408d483882Smlf #define	SSTATUS_DET_DEVPRE_PHYCOM	3	/* dev detected */
7418d483882Smlf #define	SSTATUS_DET_PHYOFFLINE		4	/* PHY is in offline */
7428d483882Smlf 
7438d483882Smlf #define	SSTATUS_GET_DET(x) \
7448d483882Smlf 	(x & SSTATUS_DET)
7458d483882Smlf 
7468d483882Smlf #define	SSTATUS_SET_DET(x, new_val) \
7478d483882Smlf 	(x = (x & ~SSTATUS_DET) | (new_val & SSTATUS_DET))
7488d483882Smlf 
749*13c8743eSMarcel Telka #define	SSTATUS_SPD_NODEV	0 /* No device present */
750*13c8743eSMarcel Telka #define	SSTATUS_SPD_GEN1	1 /* Gen 1 rate negotiated */
751*13c8743eSMarcel Telka #define	SSTATUS_SPD_GEN2	2 /* Gen 2 rate negotiated */
752*13c8743eSMarcel Telka #define	SSTATUS_SPD_GEN3	3 /* Gen 3 rate negotiated */
7538d483882Smlf 
7548d483882Smlf /*
7558d483882Smlf  * sstatus IPM values
7568d483882Smlf  */
7578d483882Smlf #define	SSTATUS_IPM_NODEV_NOPHYCOM	0x0 /* No dev, no PHY */
7588d483882Smlf #define	SSTATUS_IPM_ACTIVE		0x1 /* Interface active */
7598d483882Smlf #define	SSTATUS_IPM_POWERPARTIAL	0x2 /* partial power mgmnt */
7608d483882Smlf #define	SSTATUS_IPM_POWERSLUMBER	0x6 /* slumber power mgmt */
7618d483882Smlf 
7628d483882Smlf #define	SSTATUS_GET_IPM(x) \
7638d483882Smlf 	((x & SSTATUS_IPM) >> SSTATUS_IPM_SHIFT)
7648d483882Smlf 
7658d483882Smlf #define	SSTATUS_SET_IPM(x, new_val) \
7668d483882Smlf 	(x = (x & ~SSTATUS_IPM) | \
7678d483882Smlf 	((new_val << SSTATUS_IPM_SHIFT) & SSTATUS_IPM))
7688d483882Smlf 
7698d483882Smlf 
7708d483882Smlf /*
7718d483882Smlf  * serror register fields
7728d483882Smlf  */
7738d483882Smlf #define	SERROR_DATA_ERR_FIXED	(1 << 0) /* D integrity err */
7748d483882Smlf #define	SERROR_COMM_ERR_FIXED	(1 << 1) /* comm err recov */
7758d483882Smlf #define	SERROR_DATA_ERR		(1 << 8) /* D integrity err */
7768d483882Smlf #define	SERROR_PERSISTENT_ERR	(1 << 9)  /* norecov com err */
7778d483882Smlf #define	SERROR_PROTOCOL_ERR	(1 << 10) /* protocol err */
7788d483882Smlf #define	SERROR_INT_ERR		(1 << 11) /* internal err */
7798d483882Smlf #define	SERROR_PHY_RDY_CHG	(1 << 16) /* PHY state change */
7808d483882Smlf #define	SERROR_PHY_INT_ERR	(1 << 17) /* PHY internal err */
7818d483882Smlf #define	SERROR_COMM_WAKE	(1 << 18) /* COM wake */
7828d483882Smlf #define	SERROR_10B_TO_8B_ERR	(1 << 19) /* 10B-to-8B decode */
7838d483882Smlf #define	SERROR_DISPARITY_ERR	(1 << 20) /* disparity err */
7848d483882Smlf #define	SERROR_CRC_ERR		(1 << 21) /* CRC err */
7858d483882Smlf #define	SERROR_HANDSHAKE_ERR	(1 << 22) /* Handshake err */
7868d483882Smlf #define	SERROR_LINK_SEQ_ERR	(1 << 23) /* Link seq err */
7878d483882Smlf #define	SERROR_TRANS_ERR	(1 << 24) /* Tran state err */
7888d483882Smlf #define	SERROR_FIS_TYPE		(1 << 25) /* FIS type err */
7898d483882Smlf #define	SERROR_EXCHANGED_ERR	(1 << 26) /* Device exchanged */
7908d483882Smlf 
7918d483882Smlf /*
7928d483882Smlf  * S-Control Bridge port x register fields
7938d483882Smlf  */
7948d483882Smlf #define	SCONTROL_DET_SHIFT	0
7958d483882Smlf #define	SCONTROL_SPD_SHIFT	4
7968d483882Smlf #define	SCONTROL_IPM_SHIFT	8
7978d483882Smlf #define	SCONTROL_SPM_SHIFT	12
7988d483882Smlf 
799*13c8743eSMarcel Telka #define	SCONTROL_DET		(0xf << SCONTROL_DET_SHIFT)
800*13c8743eSMarcel Telka #define	SCONTROL_SPD		(0xf << SCONTROL_SPD_SHIFT)
801*13c8743eSMarcel Telka #define	SCONTROL_IPM		(0xf << SCONTROL_IPM_SHIFT)
802*13c8743eSMarcel Telka #define	SCONTROL_SPM		(0xf << SCONTROL_SPM_SHIFT)
8038d483882Smlf 
8048d483882Smlf #define	SCONTROL_GET_DET(x)	\
8058d483882Smlf 	(x & SCONTROL_DET)
8068d483882Smlf 
8078d483882Smlf #define	SCONTROL_SET_DET(x, new_val)    \
8088d483882Smlf 	(x = (x & ~SCONTROL_DET) | (new_val & SCONTROL_DET))
8098d483882Smlf 
8108d483882Smlf #define	SCONTROL_DET_NOACTION	0 /* Do nothing to port */
8118d483882Smlf #define	SCONTROL_DET_COMRESET	1 /* Re-initialize port */
8128d483882Smlf #define	SCONTROL_DET_DISABLE	4 /* Disable port */
8138d483882Smlf 
8148d483882Smlf #define	SCONTROL_SPD_NOLIMIT	0 /* No speed limit */
8158d483882Smlf #define	SCONTROL_SPD_GEN1	1 /* Limit Gen 1 rate */
8168d483882Smlf #define	SCONTROL_SPD_GEN2	2 /* Limit Gen 2 rate */
817*13c8743eSMarcel Telka #define	SCONTROL_SPD_GEN3	3 /* Limit Gen 3 rate */
8188d483882Smlf 
81913bcbb7aSyt160523 #define	SCONTROL_GET_IPM(x)	\
82013bcbb7aSyt160523 	((x & SCONTROL_IPM) >> SCONTROL_IPM_SHIFT)
82113bcbb7aSyt160523 
82213bcbb7aSyt160523 #define	SCONTROL_SET_IPM(x, new_val)	\
82313bcbb7aSyt160523 	(x = (x & ~SCONTROL_IPM) | \
82413bcbb7aSyt160523 	((new_val << SCONTROL_IPM_SHIFT) & SCONTROL_IPM))
82513bcbb7aSyt160523 
8268d483882Smlf #define	SCONTROL_IPM_NORESTRICT		0 /* No PM limit */
8278d483882Smlf #define	SCONTROL_IPM_DISABLE_PARTIAL	1 /* Disable partial */
8288d483882Smlf #define	SCONTROL_IPM_DISABLE_SLUMBER	2 /* Disable slumber */
8298d483882Smlf #define	SCONTROL_IPM_DISABLE_BOTH	3 /* Disable both */
8308d483882Smlf 
8318d483882Smlf #define	SCONTROL_SPM_NORESTRICT		0 /* No PM limits */
8328d483882Smlf #define	SCONTROL_SPM_DO_PARTIAL		1 /* Go to partial */
8338d483882Smlf #define	SCONTROL_SPM_DO_SLUMBER		2 /* Go to slumber */
8348d483882Smlf #define	SCONTROL_SPM_DO_ACTIVE		4 /* Go to active */
8358d483882Smlf 
83666f9d5cbSmlf #ifdef	__cplusplus
83766f9d5cbSmlf }
83866f9d5cbSmlf #endif
83966f9d5cbSmlf 
84066f9d5cbSmlf #endif /* _SATA_DEFS_H */
841