00001
00041 #ifndef SCSI_SPC_PROTOCOL_H_INCLUDED
00042 #define SCSI_SPC_PROTOCOL_H_INCLUDED
00043
00044 #define SCSI_CMD_TEST_UNIT_READY 0x00
00045 #define SCSI_CMD_REQUEST_SENSE 0x03
00046 #define SCSI_CMD_INQUIRY 0x12
00047 #define SCSI_CMD_MODE_SELECT6 0x15
00048 #define SCSI_CMD_MODE_SENSE6 0x1a
00049 #define SCSI_CMD_SEND_DIAGNOSTIC 0x1d
00050 #define SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
00051 #define SCSI_CMD_MODE_SENSE10 0x5a
00052 #define SCSI_CMD_REPORT_LUNS 0xa0
00053
00054
00055 #define SCSI_INQ_REQ_EVPD 0x01 //!< Enable Vital Product Data
00056
00057 COMPILER_PACK_SET(1);
00058
00062 struct scsi_inquiry_data {
00063 uint8_t pq_pdt;
00064 #define SCSI_INQ_PQ_CONNECTED 0x00 //!< Peripheral connected
00065 #define SCSI_INQ_PQ_NOT_CONN 0x20 //!< Peripheral not connected
00066 #define SCSI_INQ_PQ_NOT_SUPP 0x60 //!< Peripheral not supported
00067 #define SCSI_INQ_DT_DIR_ACCESS 0x00 //!< Direct Access (SBC)
00068 #define SCSI_INQ_DT_SEQ_ACCESS 0x01 //!< Sequential Access
00069 #define SCSI_INQ_DT_PRINTER 0x02 //!< Printer
00070 #define SCSI_INQ_DT_PROCESSOR 0x03 //!< Processor device
00071 #define SCSI_INQ_DT_WRITE_ONCE 0x04 //!< Write-once device
00072 #define SCSI_INQ_DT_CD_DVD 0x05 //!< CD/DVD device
00073 #define SCSI_INQ_DT_OPTICAL 0x07 //!< Optical Memory
00074 #define SCSI_INQ_DT_MC 0x08 //!< Medium Changer
00075 #define SCSI_INQ_DT_ARRAY 0x0c //!< Storage Array Controller
00076 #define SCSI_INQ_DT_ENCLOSURE 0x0d //!< Enclosure Services
00077 #define SCSI_INQ_DT_RBC 0x0e //!< Simplified Direct Access
00078 #define SCSI_INQ_DT_OCRW 0x0f //!< Optical card reader/writer
00079 #define SCSI_INQ_DT_BCC 0x10 //!< Bridge Controller Commands
00080 #define SCSI_INQ_DT_OSD 0x11 //!< Object-based Storage
00081 #define SCSI_INQ_DT_NONE 0x1f //!< No Peripheral
00082 uint8_t flags1;
00083 #define SCSI_INQ_RMB 0x80 //!< Removable Medium
00084 uint8_t version;
00085 #define SCSI_INQ_VER_NONE 0x00 //!< No standards conformance
00086 #define SCSI_INQ_VER_SPC 0x03 //!< SCSI Primary Commands
00087 #define SCSI_INQ_VER_SPC2 0x04 //!< SCSI Primary Commands - 2
00088 #define SCSI_INQ_VER_SPC3 0x05 //!< SCSI Primary Commands - 3
00089 #define SCSI_INQ_VER_SPC4 0x06 //!< SCSI Primary Commands - 4
00090 uint8_t flags3;
00091 #define SCSI_INQ_NORMACA 0x20 //!< Normal ACA Supported
00092 #define SCSI_INQ_HISUP 0x10 //!< Hierarchial LUN addressing
00093 #define SCSI_INQ_RSP_SPC2 0x02 //!< SPC-2 / SPC-3 response format
00094 uint8_t addl_len;
00095 #define SCSI_INQ_ADDL_LEN(tot) ((tot) - 5) //!< Total length is \a tot
00096 uint8_t flags5;
00097 #define SCSI_INQ_SCCS 0x80
00098 uint8_t flags6;
00099 #define SCSI_INQ_BQUE 0x80
00100 #define SCSI_INQ_ENCSERV 0x40
00101 #define SCSI_INQ_MULTIP 0x10
00102 #define SCSI_INQ_MCHGR 0x08
00103 #define SCSI_INQ_ADDR16 0x01
00104 uint8_t flags7;
00105 #define SCSI_INQ_WBUS16 0x20
00106 #define SCSI_INQ_SYNC 0x10
00107 #define SCSI_INQ_LINKED 0x08
00108 #define SCSI_INQ_CMDQUE 0x02
00109 uint8_t vendor_id[8];
00110 uint8_t product_id[16];
00111 uint8_t product_rev[4];
00112 };
00113
00114 COMPILER_PACK_RESET();
00115
00116
00117 enum scsi_vpd_page_code {
00118 SCSI_VPD_SUPPORTED_PAGES = 0x00,
00119 SCSI_VPD_UNIT_SERIAL_NUMBER = 0x80,
00120 SCSI_VPD_DEVICE_IDENTIFICATION = 0x83,
00121 };
00122 #define SCSI_VPD_HEADER_SIZE 4
00123
00124
00125 #define SCSI_VPD_ID_HEADER_SIZE 4
00126
00127 #define SCSI_VPD_CODE_SET_BINARY 1
00128 #define SCSI_VPD_CODE_SET_ASCII 2
00129 #define SCSI_VPD_CODE_SET_UTF8 3
00130
00131 #define SCSI_VPD_ID_TYPE_T10 1
00132
00133
00134 #define SCSI_SENSE_VALID 0x80
00135 #define SCSI_SENSE_CURRENT 0x70
00136 #define SCSI_SENSE_DEFERRED 0x71
00137
00138
00139 #define SCSI_SENSE_FILEMARK 0x80
00140 #define SCSI_SENSE_EOM 0x40
00141 #define SCSI_SENSE_ILI 0x20
00142 #define SCSI_SENSE_KEY(x) (x)
00143
00144
00145 #define SCSI_SENSE_ADDL_LEN(total_len) ((total_len) - 8)
00146
00147
00148 #define SCSI_SENSE_SKSV 0x80
00149
00150
00151 enum scsi_sense_key {
00152 SCSI_SK_NO_SENSE = 0x0,
00153 SCSI_SK_RECOVERED_ERROR = 0x1,
00154 SCSI_SK_NOT_READY = 0x2,
00155 SCSI_SK_MEDIUM_ERROR = 0x3,
00156 SCSI_SK_HARDWARE_ERROR = 0x4,
00157 SCSI_SK_ILLEGAL_REQUEST = 0x5,
00158 SCSI_SK_UNIT_ATTENTION = 0x6,
00159 SCSI_SK_DATA_PROTECT = 0x7,
00160 SCSI_SK_BLANK_CHECK = 0x8,
00161 SCSI_SK_VENDOR_SPECIFIC = 0x9,
00162 SCSI_SK_COPY_ABORTED = 0xa,
00163 SCSI_SK_ABORTED_COMMAND = 0xb,
00164 SCSI_SK_VOLUME_OVERFLOW = 0xd,
00165 SCSI_SK_MISCOMPARE = 0xe,
00166 };
00167
00168
00169 enum scsi_asc_ascq {
00170 SCSI_ASC_NO_ADDITIONAL_SENSE_INFO = 0x0000,
00171 SCSI_ASC_LU_NOT_READY_REBUILD_IN_PROGRESS = 0x0405,
00172 SCSI_ASC_WRITE_ERROR = 0x0c00,
00173 SCSI_ASC_UNRECOVERED_READ_ERROR = 0x1100,
00174 SCSI_ASC_INVALID_COMMAND_OPERATION_CODE = 0x2000,
00175 SCSI_ASC_INVALID_FIELD_IN_CDB = 0x2400,
00176 SCSI_ASC_MEDIUM_NOT_PRESENT = 0x3a00,
00177 SCSI_ASC_INTERNAL_TARGET_FAILURE = 0x4400,
00178 };
00179
00180
00181
00182 enum scsi_spc_mode_page_code {
00183 SCSI_MS_PAGE_VENDOR_SPEC = 0x00,
00184 SCSI_MS_PAGE_ALL = 0x3f,
00185 };
00186
00187 enum scsi_spc_mode_sense_pc {
00188 SCSI_MS_PC_CURRENT = 0,
00189 SCSI_MS_PC_CHANGEABLE = 1,
00190 SCSI_MS_PC_DEFAULT = 2,
00191 SCSI_MS_PC_SAVED = 3,
00192 };
00193
00194 static inline bool scsi_mode_sense_dbd_is_set(const uint8_t *cdb)
00195 {
00196 return (cdb[1] >> 3) & 1;
00197 }
00198
00199 static inline uint8_t scsi_mode_sense_get_page_code(const uint8_t *cdb)
00200 {
00201 return cdb[2] & 0x3f;
00202 }
00203
00204 static inline uint8_t scsi_mode_sense_get_pc(const uint8_t *cdb)
00205 {
00206 return cdb[2] >> 6;
00207 }
00208
00213 struct scsi_mode_param_header6 {
00214 uint8_t mode_data_length;
00215 uint8_t medium_type;
00216 uint8_t device_specific_parameter;
00217 uint8_t block_descriptor_length;
00218 };
00219
00224 struct scsi_mode_param_header10 {
00225 be16_t mode_data_length;
00226 uint8_t medium_type;
00227 uint8_t device_specific_parameter;
00228 uint8_t flags4;
00229 uint8_t reserved;
00230 be16_t block_descriptor_length;
00231 };
00232
00236 struct scsi_mode_page_0_header {
00237 uint8_t page_code;
00238 #define SCSI_PAGE_CODE_PS (1 << 7) //!< Parameters Saveable
00239 #define SCSI_PAGE_CODE_SPF (1 << 6) //!< SubPage Format
00240 uint8_t page_length;
00241 #define SCSI_MS_PAGE_LEN(total) ((total) - 2)
00242 };
00243
00244 #endif