1285809Sscottl/******************************************************************************* 2285809Sscottl*Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved. 3285809Sscottl* 4285809Sscottl*Redistribution and use in source and binary forms, with or without modification, are permitted provided 5285809Sscottl*that the following conditions are met: 6285809Sscottl*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the 7285809Sscottl*following disclaimer. 8285809Sscottl*2. Redistributions in binary form must reproduce the above copyright notice, 9285809Sscottl*this list of conditions and the following disclaimer in the documentation and/or other materials provided 10285809Sscottl*with the distribution. 11285809Sscottl* 12285809Sscottl*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED 13285809Sscottl*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14285809Sscottl*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 15285809Sscottl*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 16285809Sscottl*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 17285809Sscottl*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 18285809Sscottl*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 19285809Sscottl*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 20285809Sscottl* 21285809Sscottl* $FreeBSD$ 22285809Sscottl* 23285809Sscottl********************************************************************************/ 24285809Sscottl/*******************************************************************************/ 25285809Sscottl/** \file 26285809Sscottl * 27285809Sscottl * 28285809Sscottl * The file defines the constants, data structure, and functions defined by SAT 29285809Sscottl * layer. 30285809Sscottl * 31285809Sscottl */ 32285809Sscottl 33285809Sscottl#ifndef __SAT_H__ 34285809Sscottl#define __SAT_H__ 35285809Sscottl 36285809Sscottl/* 37285809Sscottl * ATA Command code 38285809Sscottl */ 39285809Sscottl#define SAT_READ_FPDMA_QUEUED 0x60 40285809Sscottl#define SAT_READ_DMA_EXT 0x25 41285809Sscottl#define SAT_READ_DMA 0xC8 42285809Sscottl#define SAT_WRITE_FPDMA_QUEUED 0x61 43285809Sscottl#define SAT_WRITE_DMA_EXT 0x35 44285809Sscottl#define SAT_WRITE_DMA_FUA_EXT 0x3D 45285809Sscottl#define SAT_WRITE_DMA 0xCA 46285809Sscottl#define SAT_CHECK_POWER_MODE 0xE5 47285809Sscottl#define SAT_READ_LOG_EXT 0x2F 48285809Sscottl#define SAT_READ_VERIFY_SECTORS 0x40 49285809Sscottl#define SAT_READ_VERIFY_SECTORS_EXT 0x42 50285809Sscottl#define SAT_SMART 0xB0 51285809Sscottl#define SAT_SMART_EXEUTE_OFF_LINE_IMMEDIATE 0xD4 52285809Sscottl#define SAT_SMART_RETURN_STATUS 0xDA 53285809Sscottl#define SAT_SMART_READ_LOG 0xD5 54285809Sscottl#define SAT_SMART_ENABLE_OPERATIONS 0xD8 55285809Sscottl#define SAT_SMART_DISABLE_OPERATIONS 0xD9 56285809Sscottl#define SAT_FLUSH_CACHE 0xE7 57285809Sscottl#define SAT_FLUSH_CACHE_EXT 0xEA 58285809Sscottl#define SAT_STANDBY 0xE2 59285809Sscottl#define SAT_MEDIA_EJECT 0xED 60285809Sscottl#define SAT_WRITE_SECTORS 0x30 61285809Sscottl#define SAT_WRITE_SECTORS_EXT 0x34 62285809Sscottl#define SAT_READ_SECTORS 0x20 63285809Sscottl#define SAT_READ_SECTORS_EXT 0x24 64285809Sscottl#define SAT_GET_MEDIA_STATUS 0xDA 65285809Sscottl#define SAT_SET_FEATURES 0xEF 66285809Sscottl#define SAT_IDENTIFY_DEVICE 0xEC 67285809Sscottl#define SAT_READ_BUFFER 0xE4 68285809Sscottl#define SAT_WRITE_BUFFER 0xE8 69285809Sscottl/* 70285809Sscottl * ATAPI Command code 71285809Sscottl*/ 72285809Sscottl#define SAT_IDENTIFY_PACKET_DEVICE 0xA1 73285809Sscottl#define SAT_PACKET 0xA0 74285809Sscottl#define SAT_DEVICE_RESET 0x08 75285809Sscottl#define SAT_EXECUTE_DEVICE_DIAGNOSTIC 0x90 76285809Sscottl/* 77285809Sscottl * ATA Status Register Mask 78285809Sscottl */ 79285809Sscottl#define ERR_ATA_STATUS_MASK 0x01 /* Error/check bit */ 80285809Sscottl#define DRQ_ATA_STATUS_MASK 0x08 /* Data Request bit */ 81285809Sscottl#define DF_ATA_STATUS_MASK 0x20 /* Device Fault bit */ 82285809Sscottl#define DRDY_ATA_STATUS_MASK 0x40 /* Device Ready bit */ 83285809Sscottl#define BSY_ATA_STATUS_MASK 0x80 /* Busy bit */ 84285809Sscottl 85285809Sscottl/* 86285809Sscottl * ATA Error Register Mask 87285809Sscottl */ 88285809Sscottl#define NM_ATA_ERROR_MASK 0x02 /* No media present bit */ 89285809Sscottl#define ABRT_ATA_ERROR_MASK 0x04 /* Command aborted bit */ 90285809Sscottl#define MCR_ATA_ERROR_MASK 0x08 /* Media change request bit */ 91285809Sscottl#define IDNF_ATA_ERROR_MASK 0x10 /* Address not found bit */ 92285809Sscottl#define MC_ATA_ERROR_MASK 0x20 /* Media has changed bit */ 93285809Sscottl#define UNC_ATA_ERROR_MASK 0x40 /* Uncorrectable data error bit */ 94285809Sscottl#define ICRC_ATA_ERROR_MASK 0x80 /* Interface CRC error bit */ 95285809Sscottl 96285809Sscottl 97285809Sscottl 98285809Sscottl 99285809Sscottl/* 100285809Sscottl * transfer length and LBA limit 2^28 See identify device data word 61:60 101285809Sscottl * ATA spec p125 102285809Sscottl * 7 zeros 103285809Sscottl */ 104285809Sscottl#define SAT_TR_LBA_LIMIT 0x10000000 105285809Sscottl 106285809Sscottl/* 107285809Sscottl * transfer length and LBA limit 2^48 See identify device data word 61:60 108285809Sscottl * ATA spec p125 109285809Sscottl * 12 zeros 110285809Sscottl */ 111285809Sscottl#define SAT_EXT_TR_LBA_LIMIT 0x1000000000000 112285809Sscottl 113285809Sscottl 114285809Sscottl/* 115285809Sscottl * ATA command type. This is for setting LBA, Sector Count 116285809Sscottl */ 117285809Sscottl#define SAT_NON_EXT_TYPE 0 118285809Sscottl#define SAT_EXT_TYPE 1 119285809Sscottl#define SAT_FP_TYPE 2 120285809Sscottl 121285809Sscottl 122285809Sscottl/* 123285809Sscottl * Report LUNs response data. 124285809Sscottl */ 125285809Sscottltypedef struct scsiReportLun_s 126285809Sscottl{ 127285809Sscottl bit8 len[4]; 128285809Sscottl bit32 reserved; 129285809Sscottl tiLUN_t lunList[1]; 130285809Sscottl} scsiReportLun_t; 131285809Sscottl 132285809Sscottl/* Inquiry vendor string */ 133285809Sscottl#define AG_SAT_VENDOR_ID_STRING "ATA " 134285809Sscottl 135285809Sscottl/* 136285809Sscottl * Simple form of SATA Identify Device Data, similar definition is defined by 137285809Sscottl * LL Layer as agsaSATAIdentifyData_t. 138285809Sscottl */ 139285809Sscottltypedef struct satSimpleSATAIdentifyData_s 140285809Sscottl{ 141285809Sscottl bit16 word[256]; 142285809Sscottl} satSimpleSATAIdentifyData_t; 143285809Sscottl 144285809Sscottl 145285809Sscottl/* 146285809Sscottl * READ LOG EXT page 10h 147285809Sscottl */ 148285809Sscottltypedef struct satReadLogExtPage10h_s 149285809Sscottl{ 150285809Sscottl bit8 byte[512]; 151285809Sscottl} satReadLogExtPage10h_t; 152285809Sscottl 153285809Sscottl/* 154285809Sscottl * READ LOG EXT Extended Self-test log 155285809Sscottl * ATA Table27 p196 156285809Sscottl */ 157285809Sscottltypedef struct satReadLogExtSelfTest_s 158285809Sscottl{ 159285809Sscottl bit8 byte[512]; 160285809Sscottl} satReadLogExtSelfTest_t; 161285809Sscottl 162285809Sscottl/* 163285809Sscottl * SMART READ LOG Self-test log 164285809Sscottl * ATA Table60 p296 165285809Sscottl */ 166285809Sscottltypedef struct satSmartReadLogSelfTest_s 167285809Sscottl{ 168285809Sscottl bit8 byte[512]; 169285809Sscottl} satSmartReadLogSelfTest_t; 170285809Sscottl 171285809Sscottl 172285809Sscottl/* 173285809Sscottl * Flag definition for satIntFlag field in satInternalIo_t. 174285809Sscottl */ 175285809Sscottl 176285809Sscottl/* Original NCQ I/O already completed, so at the completion of READ LOG EXT 177285809Sscottl * page 10h, ignore the TAG tranaltion to get the failed I/O 178285809Sscottl */ 179285809Sscottl#define AG_SAT_INT_IO_FLAG_ORG_IO_COMPLETED 0x00000001 180285809Sscottl 181285809Sscottl#define INQUIRY_SUPPORTED_VPD_PAGE 0x00 182285809Sscottl#define INQUIRY_UNIT_SERIAL_NUMBER_VPD_PAGE 0x80 183285809Sscottl#define INQUIRY_DEVICE_IDENTIFICATION_VPD_PAGE 0x83 184285809Sscottl#define INQUIRY_ATA_INFORMATION_VPD_PAGE 0x89 185285809Sscottl 186285809Sscottl#define MODESENSE_CONTROL_PAGE 0x0A 187285809Sscottl#define MODESENSE_READ_WRITE_ERROR_RECOVERY_PAGE 0x01 188285809Sscottl#define MODESENSE_CACHING 0x08 189285809Sscottl#define MODESENSE_INFORMATION_EXCEPTION_CONTROL_PAGE 0x1C 190285809Sscottl#define MODESENSE_RETURN_ALL_PAGES 0x3F 191285809Sscottl#define MODESENSE_VENDOR_SPECIFIC_PAGE 0x00 192285809Sscottl 193285809Sscottl#define MODESELECT_CONTROL_PAGE 0x0A 194285809Sscottl#define MODESELECT_READ_WRITE_ERROR_RECOVERY_PAGE 0x01 195285809Sscottl#define MODESELECT_CACHING 0x08 196285809Sscottl#define MODESELECT_INFORMATION_EXCEPTION_CONTROL_PAGE 0x1C 197285809Sscottl#define MODESELECT_RETURN_ALL_PAGES 0x3F 198285809Sscottl#define MODESELECT_VENDOR_SPECIFIC_PAGE 0x00 199285809Sscottl 200285809Sscottl#define LOGSENSE_SUPPORTED_LOG_PAGES 0x00 201285809Sscottl#define LOGSENSE_SELFTEST_RESULTS_PAGE 0x10 202285809Sscottl#define LOGSENSE_INFORMATION_EXCEPTIONS_PAGE 0x2F 203285809Sscottl 204285809Sscottl 205285809Sscottl/* 206285809Sscottl * Bit mask definition 207285809Sscottl */ 208285809Sscottl#define SCSI_EVPD_MASK 0x01 209285809Sscottl#define SCSI_IMMED_MASK 0x01 210285809Sscottl#define SCSI_NACA_MASK 0x04 211285809Sscottl#define SCSI_LINK_MASK 0x01 212285809Sscottl#define SCSI_PF_MASK 0x10 213285809Sscottl#define SCSI_DEVOFFL_MASK 0x02 214285809Sscottl#define SCSI_UNITOFFL_MASK 0x01 215285809Sscottl#define SCSI_START_MASK 0x01 216285809Sscottl#define SCSI_LOEJ_MASK 0x02 217285809Sscottl#define SCSI_NM_MASK 0x02 218285809Sscottl#define SCSI_FLUSH_CACHE_IMMED_MASK 0x02 219285809Sscottl#define SCSI_FUA_NV_MASK 0x02 220285809Sscottl#define SCSI_VERIFY_BYTCHK_MASK 0x02 221285809Sscottl#define SCSI_FORMAT_UNIT_IMMED_MASK 0x02 222285809Sscottl#define SCSI_FORMAT_UNIT_FOV_MASK 0x80 223285809Sscottl#define SCSI_FORMAT_UNIT_DCRT_MASK 0x20 224285809Sscottl#define SCSI_FORMAT_UNIT_IP_MASK 0x08 225285809Sscottl#define SCSI_WRITE_SAME_LBDATA_MASK 0x02 226285809Sscottl#define SCSI_WRITE_SAME_PBDATA_MASK 0x04 227285809Sscottl#define SCSI_SYNC_CACHE_IMMED_MASK 0x02 228285809Sscottl#define SCSI_WRITE_N_VERIFY_BYTCHK_MASK 0x02 229285809Sscottl#define SCSI_SEND_DIAGNOSTIC_SELFTEST_MASK 0x04 230285809Sscottl#define SCSI_FORMAT_UNIT_DEFECT_LIST_FORMAT_MASK 0x07 231285809Sscottl#define SCSI_FORMAT_UNIT_FMTDATA_MASK 0x10 232285809Sscottl#define SCSI_FORMAT_UNIT_DCRT_MASK 0x20 233285809Sscottl#define SCSI_FORMAT_UNIT_CMPLIST_MASK 0x08 234285809Sscottl#define SCSI_FORMAT_UNIT_LONGLIST_MASK 0x20 235285809Sscottl#define SCSI_READ10_FUA_MASK 0x08 236285809Sscottl#define SCSI_READ12_FUA_MASK 0x08 237285809Sscottl#define SCSI_READ16_FUA_MASK 0x08 238285809Sscottl#define SCSI_WRITE10_FUA_MASK 0x08 239285809Sscottl#define SCSI_WRITE12_FUA_MASK 0x08 240285809Sscottl#define SCSI_WRITE16_FUA_MASK 0x08 241285809Sscottl#define SCSI_READ_CAPACITY10_PMI_MASK 0x01 242285809Sscottl#define SCSI_READ_CAPACITY16_PMI_MASK 0x01 243285809Sscottl#define SCSI_MODE_SENSE6_PC_MASK 0xC0 244285809Sscottl#define SCSI_MODE_SENSE6_PAGE_CODE_MASK 0x3F 245285809Sscottl#define SCSI_MODE_SENSE10_PC_MASK 0xC0 246285809Sscottl#define SCSI_MODE_SENSE10_LLBAA_MASK 0x10 247285809Sscottl#define SCSI_MODE_SENSE10_PAGE_CODE_MASK 0x3F 248285809Sscottl#define SCSI_SEND_DIAGNOSTIC_TEST_CODE_MASK 0xE0 249285809Sscottl#define SCSI_LOG_SENSE_PAGE_CODE_MASK 0x3F 250285809Sscottl#define SCSI_MODE_SELECT6_PF_MASK 0x10 251285809Sscottl#define SCSI_MODE_SELECT6_AWRE_MASK 0x80 252285809Sscottl#define SCSI_MODE_SELECT6_RC_MASK 0x10 253285809Sscottl#define SCSI_MODE_SELECT6_EER_MASK 0x08 254285809Sscottl#define SCSI_MODE_SELECT6_PER_MASK 0x04 255285809Sscottl#define SCSI_MODE_SELECT6_DTE_MASK 0x02 256285809Sscottl#define SCSI_MODE_SELECT6_DCR_MASK 0x01 257285809Sscottl#define SCSI_MODE_SELECT6_WCE_MASK 0x04 258285809Sscottl#define SCSI_MODE_SELECT6_DRA_MASK 0x20 259285809Sscottl#define SCSI_MODE_SELECT6_PERF_MASK 0x80 260285809Sscottl#define SCSI_MODE_SELECT6_TEST_MASK 0x04 261285809Sscottl#define SCSI_MODE_SELECT6_DEXCPT_MASK 0x08 262285809Sscottl#define SCSI_MODE_SELECT10_PF_MASK 0x10 263285809Sscottl#define SCSI_MODE_SELECT10_LONGLBA_MASK 0x01 264285809Sscottl#define SCSI_MODE_SELECT10_AWRE_MASK 0x80 265285809Sscottl#define SCSI_MODE_SELECT10_RC_MASK 0x10 266285809Sscottl#define SCSI_MODE_SELECT10_EER_MASK 0x08 267285809Sscottl#define SCSI_MODE_SELECT10_PER_MASK 0x04 268285809Sscottl#define SCSI_MODE_SELECT10_DTE_MASK 0x02 269285809Sscottl#define SCSI_MODE_SELECT10_DCR_MASK 0x01 270285809Sscottl#define SCSI_MODE_SELECT10_WCE_MASK 0x04 271285809Sscottl#define SCSI_MODE_SELECT10_DRA_MASK 0x20 272285809Sscottl#define SCSI_MODE_SELECT10_PERF_MASK 0x80 273285809Sscottl#define SCSI_MODE_SELECT10_TEST_MASK 0x04 274285809Sscottl#define SCSI_MODE_SELECT10_DEXCPT_MASK 0x08 275285809Sscottl#define SCSI_WRITE_N_VERIFY10_FUA_MASK 0x08 276285809Sscottl#define SCSI_REQUEST_SENSE_DESC_MASK 0x01 277285809Sscottl#define SCSI_READ_BUFFER_MODE_MASK 0x1F 278285809Sscottl 279285809Sscottl#define ATA_REMOVABLE_MEDIA_DEVICE_MASK 0x80 280285809Sscottl#define SCSI_REASSIGN_BLOCKS_LONGLIST_MASK 0x01 281285809Sscottl#define SCSI_REASSIGN_BLOCKS_LONGLBA_MASK 0x02 282285809Sscottl 283285809Sscottl 284285809Sscottl#define SENSE_DATA_LENGTH 0x12 /* 18 */ 285285809Sscottl#define SELFTEST_RESULTS_LOG_PAGE_LENGTH 404 286285809Sscottl#define INFORMATION_EXCEPTIONS_LOG_PAGE_LENGTH 11 287285809Sscottl#define ZERO_MEDIA_SERIAL_NUMBER_LENGTH 8 288285809Sscottl 289285809Sscottl#define LOG_SENSE_0 0 290285809Sscottl#define LOG_SENSE_1 1 291285809Sscottl#define LOG_SENSE_2 2 292285809Sscottl 293285809Sscottl#define READ_BUFFER_DATA_MODE 0x02 294285809Sscottl#define READ_BUFFER_DESCRIPTOR_MODE 0x03 295285809Sscottl#define READ_BUFFER_DESCRIPTOR_MODE_DATA_LEN 0x04 296285809Sscottl 297285809Sscottl#define WRITE_BUFFER_DATA_MODE 0x02 298285809Sscottl#define WRITE_BUFFER_DL_MICROCODE_SAVE_MODE 0x05 299285809Sscottl 300285809Sscottl/* bit mask */ 301285809Sscottl#define BIT0_MASK 0x01 302285809Sscottl#define BIT1_MASK 0x02 303285809Sscottl#define BIT2_MASK 0x04 304285809Sscottl#define BIT3_MASK 0x08 305285809Sscottl#define BIT4_MASK 0x10 306285809Sscottl#define BIT5_MASK 0x20 307285809Sscottl#define BIT6_MASK 0x40 308285809Sscottl#define BIT7_MASK 0x80 309285809Sscottl 310285809Sscottl#define MODE_SENSE6_RETURN_ALL_PAGES_LEN 68 311285809Sscottl#define MODE_SENSE6_CONTROL_PAGE_LEN 24 312285809Sscottl#define MODE_SENSE6_READ_WRITE_ERROR_RECOVERY_PAGE_LEN 24 313285809Sscottl#define MODE_SENSE6_CACHING_LEN 32 314285809Sscottl#define MODE_SENSE6_INFORMATION_EXCEPTION_CONTROL_PAGE_LEN 24 315285809Sscottl 316285809Sscottl 317285809Sscottl#define MODE_SENSE10_RETURN_ALL_PAGES_LEN 68 + 4 318285809Sscottl#define MODE_SENSE10_CONTROL_PAGE_LEN 24 + 4 319285809Sscottl#define MODE_SENSE10_READ_WRITE_ERROR_RECOVERY_PAGE_LEN 24 + 4 320285809Sscottl#define MODE_SENSE10_CACHING_LEN 32 + 4 321285809Sscottl#define MODE_SENSE10_INFORMATION_EXCEPTION_CONTROL_PAGE_LEN 24 + 4 322285809Sscottl 323285809Sscottl#define MODE_SENSE10_RETURN_ALL_PAGES_LLBAA_LEN 68 + 4 + 8 324285809Sscottl#define MODE_SENSE10_CONTROL_PAGE_LLBAA_LEN 24 + 4 + 8 325285809Sscottl#define MODE_SENSE10_READ_WRITE_ERROR_RECOVERY_PAGE_LLBAA_LEN 24 + 4 + 8 326285809Sscottl#define MODE_SENSE10_CACHING_LLBAA_LEN 32 + 4 + 8 327285809Sscottl#define MODE_SENSE10_INFORMATION_EXCEPTION_CONTROL_PAGE_LLBAA_LEN 24 + 4 + 8 328285809Sscottl 329285809Sscottl#endif /*__SAT_H__ */ 330