1 /* 2 * Copyright (c) 2003-2005 by Siarzhuk Zharski <imker@gmx.li> 3 * Distributed under the terms of the BSD License. 4 * 5 */ 6 7 /** definitions for SCSI commands, structures etc. */ 8 9 #ifndef _SCSI_COMMANDS_H_ 10 #define _SCSI_COMMANDS_H_ 11 12 /* References: 13 * http://www.t10.org/ftp/t10/drafts/rbc/rbc-r10a.pdf 14 * http://www.t10.org/ftp/t10/drafts/rbc/rbc-a101.pdf 15 * http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf 16 * http://www.t10.org/ftp/t10/drafts/cam/cam-r12b.pdf 17 * http://www.qic.org/html/standards/15x.x/qic157d.pdf 18 * 19 * http://www.usb.org/developers/data/devclass/usbmass-ufi10.pdf 20 */ 21 22 #define CAM_DIR_MASK (CAM_DIR_IN | CAM_DIR_OUT | CAM_DIR_NONE ) 23 24 /* SCSI status defines */ 25 #define SCSI_STATUS_OK 0x00 26 #define SCSI_STATUS_CHECK_CONDITION 0x02 27 28 /* SCSI command opcodes */ 29 #define READ_6 0x08 30 #define WRITE_6 0x0a 31 #define READ_10 0x28 32 #define WRITE_10 0x2a 33 #define MODE_SELECT_6 0x15 34 #define MODE_SENSE_6 0x1a 35 #define MODE_SELECT_10 0x55 36 #define MODE_SENSE_10 0x5a 37 #define READ_CAPACITY 0x25 38 #define TEST_UNIT_READY 0x00 39 #define START_STOP_UNIT 0x1b 40 41 /* come from UFI specs */ 42 #define FORMAT_UNIT 0x04 43 #define INQUIRY 0x12 44 /*#define START_STOP_UNIT 0x1b 45 #define MODE_SELECT 0x55 46 #define MODE_SENSE 0x5a */ 47 #define PREVENT_ALLOW_MEDIA_REMOVAL 0x1e 48 #define READ_10 0x28 49 #define READ_12 0xa8 50 /*#define READ_CAPACITY 0x25*/ 51 #define READ_FORMAT_CAPACITY 0x23 52 #define REQUEST_SENSE 0x03 53 #define REZERO_UNIT 0x01 54 #define SEEK_10 0x2b 55 #define SEND_DIAGNOSTICS 0x1d 56 /*#define TEST_UNIT_READY 0x00*/ 57 #define VERIFY 0x2f 58 #define WRITE_10 0x2a 59 #define WRITE_12 0xaa 60 #define WRITE_AND_VERIFY 0x2e 61 /* end of UFI commands*/ 62 63 /* come from ATAPI specs*/ 64 /*#define FORMAT_UNIT 0x04 65 #define INQUIRY 0x12 66 #define MODE_SELECT 0x55 67 #define MODE_SENSE 0x5a 68 #define PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e 69 #define READ_10 0x28 70 #define READ_12 0xa8 71 #define READ_CAPACITY 0x25 72 #define READ_FORMAT_CAPACITIES 0x23 73 #define REQUEST_SENSE 0x03 74 #define SEEK 0x2b 75 #define START_STOP_UNIT 0x1b 76 #define TEST_UNIT_READY 0x00 77 #define VERIFY 0x2f 78 #define WRITE_10 0x2a 79 #define WRITE_12 0xaa 80 #define WRITE_AND_VEIRIFY 0x2e */ 81 #define PAUSE_RESUME 0x4b 82 #define PLAY_AUDIO 0x45 83 #define PLAY_AUDIO_MSF 0x47 84 #define REWIND 0x01 85 #define PLAY_AUDIO_TRACK 0x48 86 87 /* end of ATAPI commands*/ 88 89 /* come from MMC2 specs */ 90 #define READ_BUFFER 0x3c 91 #define READ_SUBCHANNEL 0x42 92 #define READ_TOC 0x43 93 #define READ_HEADER 0x44 94 #define READ_DISK_INFO 0x51 95 #define READ_TRACK_INFO 0x52 96 #define SEND_OPC 0x54 97 #define READ_MASTER_CUE 0x59 98 #define CLOSE_TR_SESSION 0x5b 99 #define READ_BUFFER_CAP 0x5c 100 #define SEND_CUE_SHEET 0x5d 101 #define BLANK 0xa1 102 #define EXCHANGE_MEDIUM 0xa6 103 #define READ_DVD_STRUCTURE 0xad 104 #define DVD_REPORT_KEY 0xa4 105 #define DVD_SEND_KEY 0xa3 106 #define SET_CD_SPEED 0xbb 107 #define GET_CONFIGURATION 0x46 108 /* end of MMC2 specs */ 109 110 /* come from RBC specs */ 111 /*#define FORMAT_UNIT 0x04 112 #define INQUIRY 0x12 113 #define MODE_SELECT_6 0x15 114 #define MODE_SENSE_6 0x1a*/ 115 #define PERSISTENT_RESERVE_IN 0x5e 116 #define PERSISTENT_RESERVE_OUT 0x5f 117 /*#define PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e 118 #define READ_10 0x28 119 #define READ_CAPACITY 0x25*/ 120 #define RELEASE_6 0x17 121 /*#define REQUEST_SENSE 0x03*/ 122 #define RESERVE_6 0x16 123 /*#define START_STOP_UNIT 0x1b*/ 124 #define SYNCHRONIZE_CACHE 0x35 125 /*#define TEST_UNIT_READY 0x00 126 #define VERIFY_10 0x2f 127 #define WRITE_10 0x2a*/ 128 #define WRITE_BUFFER 0x3b 129 /* end of RBC commands */ 130 131 /* come from QIC-157 specvs */ 132 #define ERASE 0x19 133 /*#define INQUIRY 0x12*/ 134 #define LOAD_UNLOAD 0x1b 135 #define LOCATE 0x2b 136 #define LOG_SELECT 0x4c 137 #define LOG_SENSE 0x4d 138 /*#define MODE_SELECT 0x15 139 #define MODE_SENSE 0x1a 140 #define READ 0x08*/ 141 #define READ_POSITION 0x34 142 /*#define REQUEST_SENSE 0x03*/ 143 #define REWIND 0x01 144 #define SPACE 0x11 145 /*#define TEST_UNIT_READY 0x00 146 #define WRITE 0x0a*/ 147 #define WRITE_FILEMARK 0x10 148 /* end of QIC-157 */ 149 150 /* SCSI commands layout*/ 151 /* generic commands layout*/ 152 typedef struct{ 153 uint8 opcode; 154 uint8 bytes[11]; 155 }scsi_cmd_generic; 156 /* six-bytes command*/ 157 typedef struct{ 158 uint8 opcode; 159 uint8 addr[3]; 160 #define CMD_GEN_6_ADDR 0x1f /* mask used for addr field*/ 161 #define CMD_LUN 0xE0 /* mask used for LUN */ 162 #define CMD_LUN_SHIFT 0x05 /* shift for LUN */ 163 uint8 len; 164 uint8 ctrl; 165 }scsi_cmd_generic_6; 166 /* ten-bytes command*/ 167 typedef struct{ 168 uint8 opcode; 169 uint8 byte2; 170 uint8 addr[4]; 171 uint8 reserved; 172 uint8 len[2]; 173 uint8 ctrl; 174 }scsi_cmd_generic_10; 175 /* twelve-bytes command*/ 176 typedef struct{ 177 uint8 opcode; 178 uint8 byte2; 179 uint8 addr[4]; 180 uint8 len[4]; 181 uint8 reserved; 182 uint8 ctrl; 183 }scsi_cmd_generic_12; 184 /* READ_6 / WRITE_6 */ 185 typedef scsi_cmd_generic_6 scsi_cmd_rw_6; 186 /* READ_10 / WRITE_10 */ 187 typedef struct{ 188 uint8 opcode; 189 uint8 byte2; 190 #define CMD_RW_10_RELADDR 0x01 191 #define CMD_RW_10_FUA 0x08 192 #define CMD_RW_10_DPO 0x10 193 uint8 addr[4]; 194 uint8 reserved; 195 uint8 len[2]; 196 uint8 ctrl; 197 }scsi_cmd_rw_10; 198 /* MODE_SELECT_6 */ 199 typedef struct{ 200 uint8 opcode; 201 uint8 byte2; 202 #define CMD_MSEL_6_SP 0x01 203 #define CMD_MSEL_6_PF 0x10 204 uint8 reserved[2]; 205 uint8 len; 206 uint8 ctrl; 207 }scsi_cmd_mode_select_6; 208 /* MODE_SELECT_10 */ 209 typedef struct{ 210 uint8 opcode; 211 uint8 byte2; 212 #define CMD_MSEL_10_SP 0x01 213 #define CMD_MSEL_10_PF 0x10 214 uint8 reserved[5]; 215 uint8 len[2]; 216 uint8 ctrl; 217 }scsi_cmd_mode_select_10; 218 /* MODE_SENSE_6 */ 219 typedef struct{ 220 uint8 opcode; 221 uint8 byte2; 222 #define CMD_MSENSE_6_DBD 0x08 223 uint8 byte3; 224 #define CMD_MSENSE_6_PC 0x0c 225 uint8 reserved; 226 uint8 len; 227 uint8 ctrl; 228 }scsi_cmd_mode_sense_6; 229 typedef struct{ 230 uint8 mode_data_len; 231 uint8 medium_type; 232 uint8 device_spec_params; 233 uint8 block_descr_len; 234 }scsi_mode_param_header_6; 235 /* MODE_SENSE_10 */ 236 typedef struct{ 237 uint8 opcode; 238 uint8 byte2; 239 #define CMD_MSENSE_10_DBD 0x08 240 uint8 byte3; 241 #define CMD_MSENSE_10_PC 0x0c 242 uint8 reserved[4]; 243 uint8 len[2]; 244 uint8 ctrl; 245 }scsi_cmd_mode_sense_10; 246 typedef struct{ 247 uint8 mode_data_len[2]; 248 uint8 medium_type; 249 uint8 device_spec_params; 250 uint8 reserved1; 251 uint8 reserved2; 252 uint8 block_descr_len[2]; 253 }scsi_mode_param_header_10; 254 /* TEST_UNIT_READY */ 255 typedef struct{ 256 uint8 opcode; 257 uint8 byte2; 258 uint8 reserved[3]; 259 uint8 ctrl; 260 }scsi_cmd_test_unit_ready; 261 /* START_STOP_UNIT */ 262 typedef struct{ 263 uint8 opcode; 264 uint8 byte2; 265 #define CMD_SSU_IMMED 0x01 266 uint8 reserved[2]; 267 uint8 start_loej; 268 #define CMD_SSU_LOEJ 0x02 269 #define CMD_SSU_START 0x01 270 uint8 ctrl; 271 }scsi_cmd_start_stop_unit; 272 273 /* SCSI REQUEST SENSE data. See 8.2.14*/ 274 typedef struct _scsi_sense_data{ 275 uint8 error_code; 276 #define SSD_ERRCODE 0x7F 277 #define SSD_CURRENT_ERROR 0x70 278 #define SSD_DEFERRED_ERROR 0x71 279 #define SSD_ERRCODE_VALID 0x80 280 uint8 segment; 281 uint8 flags; 282 #define SSD_KEY 0x0F 283 #define SSD_KEY_NO_SENSE 0x00 284 #define SSD_KEY_RECOVERED_ERROR 0x01 285 #define SSD_KEY_NOT_READY 0x02 286 #define SSD_KEY_MEDIUM_ERROR 0x03 287 #define SSD_KEY_HARDWARE_ERROR 0x04 288 #define SSD_KEY_ILLEGAL_REQUEST 0x05 289 #define SSD_KEY_UNIT_ATTENTION 0x06 290 #define SSD_KEY_DATA_PROTECT 0x07 291 #define SSD_KEY_BLANK_CHECK 0x08 292 #define SSD_KEY_Vendor_Specific 0x09 293 #define SSD_KEY_COPY_ABORTED 0x0a 294 #define SSD_KEY_ABORTED_COMMAND 0x0b 295 #define SSD_KEY_EQUAL 0x0c 296 #define SSD_KEY_VOLUME_OVERFLOW 0x0d 297 #define SSD_KEY_MISCOMPARE 0x0e 298 #define SSD_KEY_RESERVED 0x0f 299 #define SSD_ILI 0x20 300 #define SSD_EOM 0x40 301 #define SSD_FILEMARK 0x80 302 uint8 info[4]; 303 uint8 extra_len; 304 uint8 cmd_spec_info[4]; 305 uint8 add_sense_code; 306 uint8 add_sense_code_qual; 307 uint8 fru; 308 uint8 sense_key_spec[3]; 309 #define SSD_SCS_VALID 0x80 310 #define SSD_FIELDPTR_CMD 0x40 311 #define SSD_BITPTR_VALID 0x08 312 #define SSD_BITPTR_VALUE 0x07 313 #define SSD_MIN_SIZE 18 314 uint8 extra_bytes[14]; 315 #define SSD_FULL_SIZE sizeof(struct _scsi_sense_data) 316 }scsi_sense_data; 317 318 #endif /*_SCSI_COMMANDS_H_*/ 319