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