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