xref: /freebsd/sys/dev/pms/RefTisa/tisa/sassata/sata/host/sat.h (revision 640235e2c2ba32947f7c59d168437ffa1280f1e6)
1 /*******************************************************************************
2 *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3 *
4 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
5 *that the following conditions are met:
6 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7 *following disclaimer.
8 *2. Redistributions in binary form must reproduce the above copyright notice,
9 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
10 *with the distribution.
11 *
12 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20 *
21 * $FreeBSD$
22 *
23 ********************************************************************************/
24 /*******************************************************************************/
25 /** \file
26  *
27  *
28  * The file defines the constants, data structure, and functions defined by SAT
29  * layer.
30  *
31  */
32 
33 #ifndef  __SAT_H__
34 #define __SAT_H__
35 
36 /*
37  * ATA Command code
38  */
39 #define SAT_READ_FPDMA_QUEUED                 0x60
40 #define SAT_READ_DMA_EXT                      0x25
41 #define SAT_READ_DMA                          0xC8
42 #define SAT_WRITE_FPDMA_QUEUED                0x61
43 #define SAT_WRITE_DMA_EXT                     0x35
44 #define SAT_WRITE_DMA_FUA_EXT                 0x3D
45 #define SAT_WRITE_DMA                         0xCA
46 #define SAT_CHECK_POWER_MODE                  0xE5
47 #define SAT_READ_LOG_EXT                      0x2F
48 #define SAT_READ_VERIFY_SECTORS               0x40
49 #define SAT_READ_VERIFY_SECTORS_EXT           0x42
50 #define SAT_SMART                             0xB0
51 #define SAT_SMART_EXEUTE_OFF_LINE_IMMEDIATE   0xD4
52 #define SAT_SMART_RETURN_STATUS               0xDA
53 #define SAT_SMART_READ_LOG                    0xD5
54 #define SAT_SMART_ENABLE_OPERATIONS           0xD8
55 #define SAT_SMART_DISABLE_OPERATIONS          0xD9
56 #define SAT_FLUSH_CACHE                       0xE7
57 #define SAT_FLUSH_CACHE_EXT                   0xEA
58 #define SAT_STANDBY                           0xE2
59 #define SAT_MEDIA_EJECT                       0xED
60 #define SAT_WRITE_SECTORS                     0x30
61 #define SAT_WRITE_SECTORS_EXT                 0x34
62 #define SAT_READ_SECTORS                      0x20
63 #define SAT_READ_SECTORS_EXT                  0x24
64 #define SAT_GET_MEDIA_STATUS                  0xDA
65 #define SAT_SET_FEATURES                      0xEF
66 #define SAT_IDENTIFY_DEVICE                   0xEC
67 #define SAT_READ_BUFFER                       0xE4
68 #define SAT_WRITE_BUFFER                      0xE8
69 /*
70  * ATAPI Command code
71 */
72 #define SAT_IDENTIFY_PACKET_DEVICE            0xA1
73 #define SAT_PACKET                            0xA0
74 #define SAT_DEVICE_RESET                      0x08
75 #define SAT_EXECUTE_DEVICE_DIAGNOSTIC         0x90
76 /*
77  * ATA Status Register Mask
78  */
79 #define ERR_ATA_STATUS_MASK                   0x01    /* Error/check bit  */
80 #define DRQ_ATA_STATUS_MASK                   0x08    /* Data Request bit */
81 #define DF_ATA_STATUS_MASK                    0x20    /* Device Fault bit */
82 #define DRDY_ATA_STATUS_MASK                  0x40    /* Device Ready bit */
83 #define BSY_ATA_STATUS_MASK                   0x80    /* Busy bit         */
84 
85 /*
86  * ATA Error Register Mask
87  */
88 #define NM_ATA_ERROR_MASK                     0x02    /* No media present bit         */
89 #define ABRT_ATA_ERROR_MASK                   0x04    /* Command aborted bit          */
90 #define MCR_ATA_ERROR_MASK                    0x08    /* Media change request bit     */
91 #define IDNF_ATA_ERROR_MASK                   0x10    /* Address not found bit        */
92 #define MC_ATA_ERROR_MASK                     0x20    /* Media has changed bit        */
93 #define UNC_ATA_ERROR_MASK                    0x40    /* Uncorrectable data error bit */
94 #define ICRC_ATA_ERROR_MASK                   0x80    /* Interface CRC error bit      */
95 
96 
97 
98 
99 /*
100  *  transfer length and LBA limit 2^28 See identify device data word 61:60
101  *  ATA spec p125
102  *  7 zeros
103  */
104 #define SAT_TR_LBA_LIMIT                      0x10000000
105 
106 /*
107  *  transfer length and LBA limit 2^48 See identify device data word 61:60
108  *  ATA spec p125
109  *  12 zeros
110  */
111 #define SAT_EXT_TR_LBA_LIMIT                  0x1000000000000
112 
113 
114 /*
115  * ATA command type. This is for setting LBA, Sector Count
116  */
117 #define SAT_NON_EXT_TYPE                      0
118 #define SAT_EXT_TYPE                          1
119 #define SAT_FP_TYPE                           2
120 
121 
122 /*
123  * Report LUNs response data.
124  */
125 typedef struct scsiReportLun_s
126 {
127   bit8              len[4];
128   bit32             reserved;
129   tiLUN_t           lunList[1];
130 } scsiReportLun_t;
131 
132 /* Inquiry vendor string */
133 #define AG_SAT_VENDOR_ID_STRING               "ATA     "
134 
135 /*
136  * Simple form of SATA Identify Device Data, similar definition is defined by
137  * LL Layer as agsaSATAIdentifyData_t.
138  */
139 typedef struct satSimpleSATAIdentifyData_s
140 {
141   bit16   word[256];
142 } satSimpleSATAIdentifyData_t;
143 
144 
145 /*
146  * READ LOG EXT page 10h
147  */
148 typedef struct satReadLogExtPage10h_s
149 {
150   bit8   byte[512];
151 } satReadLogExtPage10h_t;
152 
153 /*
154  * READ LOG EXT Extended Self-test log
155  * ATA Table27 p196
156  */
157 typedef struct satReadLogExtSelfTest_s
158 {
159   bit8   byte[512];
160 } satReadLogExtSelfTest_t;
161 
162 /*
163  * SMART READ LOG Self-test log
164  * ATA Table60 p296
165  */
166 typedef struct satSmartReadLogSelfTest_s
167 {
168   bit8   byte[512];
169 } satSmartReadLogSelfTest_t;
170 
171 
172 /*
173  * Flag definition for satIntFlag field in satInternalIo_t.
174  */
175 
176 /* Original NCQ I/O already completed, so at the completion of READ LOG EXT
177  *  page 10h, ignore the TAG tranaltion to get the failed I/O
178  */
179 #define AG_SAT_INT_IO_FLAG_ORG_IO_COMPLETED   0x00000001
180 
181 #define INQUIRY_SUPPORTED_VPD_PAGE             0x00
182 #define INQUIRY_UNIT_SERIAL_NUMBER_VPD_PAGE    0x80
183 #define INQUIRY_DEVICE_IDENTIFICATION_VPD_PAGE 0x83
184 #define INQUIRY_ATA_INFORMATION_VPD_PAGE       0x89
185 
186 #define MODESENSE_CONTROL_PAGE                            0x0A
187 #define MODESENSE_READ_WRITE_ERROR_RECOVERY_PAGE          0x01
188 #define MODESENSE_CACHING                                 0x08
189 #define MODESENSE_INFORMATION_EXCEPTION_CONTROL_PAGE      0x1C
190 #define MODESENSE_RETURN_ALL_PAGES                        0x3F
191 #define MODESENSE_VENDOR_SPECIFIC_PAGE                    0x00
192 
193 #define MODESELECT_CONTROL_PAGE                           0x0A
194 #define MODESELECT_READ_WRITE_ERROR_RECOVERY_PAGE         0x01
195 #define MODESELECT_CACHING                                0x08
196 #define MODESELECT_INFORMATION_EXCEPTION_CONTROL_PAGE     0x1C
197 #define MODESELECT_RETURN_ALL_PAGES                       0x3F
198 #define MODESELECT_VENDOR_SPECIFIC_PAGE                   0x00
199 
200 #define LOGSENSE_SUPPORTED_LOG_PAGES                      0x00
201 #define LOGSENSE_SELFTEST_RESULTS_PAGE                    0x10
202 #define LOGSENSE_INFORMATION_EXCEPTIONS_PAGE              0x2F
203 
204 
205 /*
206  *  Bit mask definition
207  */
208 #define SCSI_EVPD_MASK               0x01
209 #define SCSI_IMMED_MASK              0x01
210 #define SCSI_NACA_MASK               0x04
211 #define SCSI_LINK_MASK               0x01
212 #define SCSI_PF_MASK                 0x10
213 #define SCSI_DEVOFFL_MASK            0x02
214 #define SCSI_UNITOFFL_MASK           0x01
215 #define SCSI_START_MASK              0x01
216 #define SCSI_LOEJ_MASK               0x02
217 #define SCSI_NM_MASK                 0x02
218 #define SCSI_FLUSH_CACHE_IMMED_MASK              0x02
219 #define SCSI_FUA_NV_MASK                         0x02
220 #define SCSI_VERIFY_BYTCHK_MASK                  0x02
221 #define SCSI_FORMAT_UNIT_IMMED_MASK              0x02
222 #define SCSI_FORMAT_UNIT_FOV_MASK                0x80
223 #define SCSI_FORMAT_UNIT_DCRT_MASK               0x20
224 #define SCSI_FORMAT_UNIT_IP_MASK                 0x08
225 #define SCSI_WRITE_SAME_LBDATA_MASK              0x02
226 #define SCSI_WRITE_SAME_PBDATA_MASK              0x04
227 #define SCSI_SYNC_CACHE_IMMED_MASK               0x02
228 #define SCSI_WRITE_N_VERIFY_BYTCHK_MASK          0x02
229 #define SCSI_SEND_DIAGNOSTIC_SELFTEST_MASK       0x04
230 #define SCSI_FORMAT_UNIT_DEFECT_LIST_FORMAT_MASK 0x07
231 #define SCSI_FORMAT_UNIT_FMTDATA_MASK            0x10
232 #define SCSI_FORMAT_UNIT_DCRT_MASK               0x20
233 #define SCSI_FORMAT_UNIT_CMPLIST_MASK            0x08
234 #define SCSI_FORMAT_UNIT_LONGLIST_MASK           0x20
235 #define SCSI_READ10_FUA_MASK                     0x08
236 #define SCSI_READ12_FUA_MASK                     0x08
237 #define SCSI_READ16_FUA_MASK                     0x08
238 #define SCSI_WRITE10_FUA_MASK                    0x08
239 #define SCSI_WRITE12_FUA_MASK                    0x08
240 #define SCSI_WRITE16_FUA_MASK                    0x08
241 #define SCSI_READ_CAPACITY10_PMI_MASK            0x01
242 #define SCSI_READ_CAPACITY16_PMI_MASK            0x01
243 #define SCSI_MODE_SENSE6_PC_MASK                 0xC0
244 #define SCSI_MODE_SENSE6_PAGE_CODE_MASK          0x3F
245 #define SCSI_MODE_SENSE10_PC_MASK                0xC0
246 #define SCSI_MODE_SENSE10_LLBAA_MASK             0x10
247 #define SCSI_MODE_SENSE10_PAGE_CODE_MASK         0x3F
248 #define SCSI_SEND_DIAGNOSTIC_TEST_CODE_MASK      0xE0
249 #define SCSI_LOG_SENSE_PAGE_CODE_MASK            0x3F
250 #define SCSI_MODE_SELECT6_PF_MASK                0x10
251 #define SCSI_MODE_SELECT6_AWRE_MASK              0x80
252 #define SCSI_MODE_SELECT6_RC_MASK                0x10
253 #define SCSI_MODE_SELECT6_EER_MASK               0x08
254 #define SCSI_MODE_SELECT6_PER_MASK               0x04
255 #define SCSI_MODE_SELECT6_DTE_MASK               0x02
256 #define SCSI_MODE_SELECT6_DCR_MASK               0x01
257 #define SCSI_MODE_SELECT6_WCE_MASK               0x04
258 #define SCSI_MODE_SELECT6_DRA_MASK               0x20
259 #define SCSI_MODE_SELECT6_PERF_MASK              0x80
260 #define SCSI_MODE_SELECT6_TEST_MASK              0x04
261 #define SCSI_MODE_SELECT6_DEXCPT_MASK            0x08
262 #define SCSI_MODE_SELECT10_PF_MASK               0x10
263 #define SCSI_MODE_SELECT10_LONGLBA_MASK          0x01
264 #define SCSI_MODE_SELECT10_AWRE_MASK             0x80
265 #define SCSI_MODE_SELECT10_RC_MASK               0x10
266 #define SCSI_MODE_SELECT10_EER_MASK              0x08
267 #define SCSI_MODE_SELECT10_PER_MASK              0x04
268 #define SCSI_MODE_SELECT10_DTE_MASK              0x02
269 #define SCSI_MODE_SELECT10_DCR_MASK              0x01
270 #define SCSI_MODE_SELECT10_WCE_MASK              0x04
271 #define SCSI_MODE_SELECT10_DRA_MASK              0x20
272 #define SCSI_MODE_SELECT10_PERF_MASK             0x80
273 #define SCSI_MODE_SELECT10_TEST_MASK             0x04
274 #define SCSI_MODE_SELECT10_DEXCPT_MASK           0x08
275 #define SCSI_WRITE_N_VERIFY10_FUA_MASK           0x08
276 #define SCSI_REQUEST_SENSE_DESC_MASK             0x01
277 #define SCSI_READ_BUFFER_MODE_MASK               0x1F
278 
279 #define ATA_REMOVABLE_MEDIA_DEVICE_MASK          0x80
280 #define SCSI_REASSIGN_BLOCKS_LONGLIST_MASK       0x01
281 #define SCSI_REASSIGN_BLOCKS_LONGLBA_MASK        0x02
282 
283 
284 #define SENSE_DATA_LENGTH                        0x12 /* 18 */
285 #define SELFTEST_RESULTS_LOG_PAGE_LENGTH         404
286 #define INFORMATION_EXCEPTIONS_LOG_PAGE_LENGTH   11
287 #define ZERO_MEDIA_SERIAL_NUMBER_LENGTH          8
288 
289 #define LOG_SENSE_0 0
290 #define LOG_SENSE_1 1
291 #define LOG_SENSE_2 2
292 
293 #define READ_BUFFER_DATA_MODE                    0x02
294 #define READ_BUFFER_DESCRIPTOR_MODE              0x03
295 #define READ_BUFFER_DESCRIPTOR_MODE_DATA_LEN     0x04
296 
297 #define WRITE_BUFFER_DATA_MODE                   0x02
298 #define WRITE_BUFFER_DL_MICROCODE_SAVE_MODE      0x05
299 
300 /* bit mask */
301 #define BIT0_MASK                                0x01
302 #define BIT1_MASK                                0x02
303 #define BIT2_MASK                                0x04
304 #define BIT3_MASK                                0x08
305 #define BIT4_MASK                                0x10
306 #define BIT5_MASK                                0x20
307 #define BIT6_MASK                                0x40
308 #define BIT7_MASK                                0x80
309 
310 #define MODE_SENSE6_RETURN_ALL_PAGES_LEN         68
311 #define MODE_SENSE6_CONTROL_PAGE_LEN             24
312 #define MODE_SENSE6_READ_WRITE_ERROR_RECOVERY_PAGE_LEN 24
313 #define MODE_SENSE6_CACHING_LEN                  32
314 #define MODE_SENSE6_INFORMATION_EXCEPTION_CONTROL_PAGE_LEN 24
315 
316 
317 #define MODE_SENSE10_RETURN_ALL_PAGES_LEN         68 + 4
318 #define MODE_SENSE10_CONTROL_PAGE_LEN             24 + 4
319 #define MODE_SENSE10_READ_WRITE_ERROR_RECOVERY_PAGE_LEN 24 + 4
320 #define MODE_SENSE10_CACHING_LEN                  32 + 4
321 #define MODE_SENSE10_INFORMATION_EXCEPTION_CONTROL_PAGE_LEN 24 + 4
322 
323 #define MODE_SENSE10_RETURN_ALL_PAGES_LLBAA_LEN         68 + 4 + 8
324 #define MODE_SENSE10_CONTROL_PAGE_LLBAA_LEN             24 + 4 + 8
325 #define MODE_SENSE10_READ_WRITE_ERROR_RECOVERY_PAGE_LLBAA_LEN 24 + 4 + 8
326 #define MODE_SENSE10_CACHING_LLBAA_LEN                  32 + 4 + 8
327 #define MODE_SENSE10_INFORMATION_EXCEPTION_CONTROL_PAGE_LLBAA_LEN 24 + 4 + 8
328 
329 #endif  /*__SAT_H__ */
330