1 /* $OpenBSD: scsi_all.h,v 1.27 2005/06/18 01:09:03 krw Exp $ */ 2 /* $NetBSD: scsi_all.h,v 1.10 1996/09/12 01:57:17 thorpej Exp $ */ 3 4 /* 5 * SCSI general interface description 6 */ 7 8 /* 9 * Largely written by Julian Elischer (julian@tfs.com) 10 * for TRW Financial Systems. 11 * 12 * TRW Financial Systems, in accordance with their agreement with Carnegie 13 * Mellon University, makes this software available to CMU to distribute 14 * or use in any manner that they see fit as long as this message is kept with 15 * the software. For this reason TFS also grants any other persons or 16 * organisations permission to use or modify this software. 17 * 18 * TFS supplies this software to be publicly redistributed 19 * on the understanding that TFS is not responsible for the correct 20 * functioning of this software in any circumstances. 21 * 22 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 23 */ 24 25 #ifndef _SCSI_SCSI_ALL_H 26 #define _SCSI_SCSI_ALL_H 1 27 28 /* 29 * SCSI command format 30 */ 31 32 /* 33 * Define some bits that are in ALL (or a lot of) scsi commands 34 */ 35 #define SCSI_CTL_LINK 0x01 36 #define SCSI_CTL_FLAG 0x02 37 #define SCSI_CTL_VENDOR 0xC0 38 39 40 /* 41 * Some old SCSI devices need the LUN to be set in the top 3 bits of the 42 * second byte of the CDB. 43 */ 44 #define SCSI_CMD_LUN_MASK 0xe0 45 #define SCSI_CMD_LUN_SHIFT 5 46 47 48 struct scsi_generic { 49 u_int8_t opcode; 50 u_int8_t bytes[11]; 51 }; 52 53 struct scsi_test_unit_ready { 54 u_int8_t opcode; 55 u_int8_t byte2; 56 u_int8_t unused[3]; 57 u_int8_t control; 58 }; 59 60 struct scsi_send_diag { 61 u_int8_t opcode; 62 u_int8_t byte2; 63 #define SSD_UOL 0x01 64 #define SSD_DOL 0x02 65 #define SSD_SELFTEST 0x04 66 #define SSD_PF 0x10 67 u_int8_t unused[1]; 68 u_int8_t paramlen[2]; 69 u_int8_t control; 70 }; 71 72 struct scsi_sense { 73 u_int8_t opcode; 74 u_int8_t byte2; 75 u_int8_t unused[2]; 76 u_int8_t length; 77 u_int8_t control; 78 }; 79 80 struct scsi_inquiry { 81 u_int8_t opcode; 82 u_int8_t byte2; 83 u_int8_t unused[2]; 84 u_int8_t length; 85 u_int8_t control; 86 }; 87 88 struct scsi_mode_sense { 89 u_int8_t opcode; 90 u_int8_t byte2; 91 #define SMS_DBD 0x08 /* Disable Block Descriptors */ 92 u_int8_t page; 93 #define SMS_PAGE_CODE 0x3F 94 #define SMS_PAGE_CTRL 0xC0 95 #define SMS_PAGE_CTRL_CURRENT 0x00 96 #define SMS_PAGE_CTRL_CHANGEABLE 0x40 97 #define SMS_PAGE_CTRL_DEFAULT 0x80 98 #define SMS_PAGE_CTRL_SAVED 0xC0 99 u_int8_t unused; 100 u_int8_t length; 101 u_int8_t control; 102 }; 103 104 struct scsi_mode_sense_big { 105 u_int8_t opcode; 106 u_int8_t byte2; /* same bits as small version */ 107 #define SMS_LLBAA 0x10 /* plus: Long LBA Accepted */ 108 u_int8_t page; /* same bits as small version */ 109 u_int8_t unused[4]; 110 u_int8_t length[2]; 111 u_int8_t control; 112 }; 113 114 struct scsi_mode_select { 115 u_int8_t opcode; 116 u_int8_t byte2; 117 #define SMS_SP 0x01 118 #define SMS_PF 0x10 119 u_int8_t unused[2]; 120 u_int8_t length; 121 u_int8_t control; 122 }; 123 124 struct scsi_mode_select_big { 125 u_int8_t opcode; 126 u_int8_t byte2; /* same bits as small version */ 127 u_int8_t unused[5]; 128 u_int8_t length[2]; 129 u_int8_t control; 130 }; 131 132 struct scsi_reserve { 133 u_int8_t opcode; 134 u_int8_t byte2; 135 u_int8_t unused[2]; 136 u_int8_t length; 137 u_int8_t control; 138 }; 139 140 struct scsi_release { 141 u_int8_t opcode; 142 u_int8_t byte2; 143 u_int8_t unused[2]; 144 u_int8_t length; 145 u_int8_t control; 146 }; 147 148 struct scsi_prevent { 149 u_int8_t opcode; 150 u_int8_t byte2; 151 u_int8_t unused[2]; 152 u_int8_t how; 153 u_int8_t control; 154 }; 155 #define PR_PREVENT 0x01 156 #define PR_ALLOW 0x00 157 158 /* 159 * Opcodes 160 */ 161 #define TEST_UNIT_READY 0x00 162 #define REQUEST_SENSE 0x03 163 #define INQUIRY 0x12 164 #define MODE_SELECT 0x15 165 #define RESERVE 0x16 166 #define RELEASE 0x17 167 #define MODE_SENSE 0x1a 168 #define START_STOP 0x1b 169 #define RECEIVE_DIAGNOSTIC 0x1c 170 #define SEND_DIAGNOSTIC 0x1d 171 #define PREVENT_ALLOW 0x1e 172 #define POSITION_TO_ELEMENT 0x2b 173 #define CHANGE_DEFINITION 0x40 174 #define MODE_SELECT_BIG 0x55 175 #define MODE_SENSE_BIG 0x5a 176 177 /* 178 * Sort of an extra one, for SCSI_RESET. 179 */ 180 #define GENRETRY 1 181 182 /* 183 * sense data format 184 */ 185 #define T_DIRECT 0 186 #define T_SEQUENTIAL 1 187 #define T_PRINTER 2 188 #define T_PROCESSOR 3 189 #define T_WORM 4 190 #define T_CDROM 5 191 #define T_SCANNER 6 192 #define T_OPTICAL 7 193 #define T_RDIRECT 14 194 #define T_NODEVICE 0x1F 195 196 #define T_CHANGER 8 197 #define T_COMM 9 198 #define T_ENCLOSURE 13 199 200 #define T_REMOV 1 201 #define T_FIXED 0 202 203 struct scsi_inquiry_data { 204 u_int8_t device; 205 #define SID_TYPE 0x1F 206 #define SID_QUAL 0xE0 207 #define SID_QUAL_LU_OK 0x00 208 #define SID_QUAL_LU_OFFLINE 0x20 209 #define SID_QUAL_RSVD 0x40 210 #define SID_QUAL_BAD_LU 0x60 211 u_int8_t dev_qual2; 212 #define SID_QUAL2 0x7F 213 #define SID_REMOVABLE 0x80 214 u_int8_t version; 215 #define SID_ANSII 0x07 216 #define SID_ECMA 0x38 217 #define SID_ISO 0xC0 218 u_int8_t response_format; 219 u_int8_t additional_length; 220 #define SID_INQUIRY_HDR 5 /* Bytes up to & including additional_length */ 221 #define SID_SCSI2_ALEN 31 /* Additional bytes of basic SCSI2 info */ 222 u_int8_t unused[2]; 223 u_int8_t flags; 224 #define SID_SftRe 0x01 225 #define SID_CmdQue 0x02 226 #define SID_Linked 0x08 227 #define SID_Sync 0x10 228 #define SID_WBus16 0x20 229 #define SID_WBus32 0x40 230 #define SID_RelAdr 0x80 231 char vendor[8]; 232 char product[16]; 233 char revision[4]; 234 u_int8_t extra[20]; 235 u_int8_t flags2; 236 #define SID_IUS 0x01 237 #define SID_QAS 0x02 238 #define SID_CLOCKING 0x0c /* 0 == ST only, 1 == DT only, 3 == both */ 239 u_int8_t reserved; 240 }; 241 242 struct scsi_sense_data_unextended { 243 /* 1*/ u_int8_t error_code; 244 /* 4*/ u_int8_t block[3]; 245 }; 246 247 struct scsi_sense_data { 248 /* 1*/ u_int8_t error_code; 249 #define SSD_ERRCODE 0x7F 250 #define SSD_ERRCODE_VALID 0x80 251 /* 2*/ u_int8_t segment; 252 /* 3*/ u_int8_t flags; 253 #define SSD_KEY 0x0F 254 #define SSD_ILI 0x20 255 #define SSD_EOM 0x40 256 #define SSD_FILEMARK 0x80 257 /* 7*/ u_int8_t info[4]; 258 /* 8*/ u_int8_t extra_len; 259 /*12*/ u_int8_t cmd_spec_info[4]; 260 /*13*/ u_int8_t add_sense_code; 261 /*14*/ u_int8_t add_sense_code_qual; 262 /*15*/ u_int8_t fru; 263 /*16*/ u_int8_t sense_key_spec_1; 264 #define SSD_SCS_VALID 0x80 265 #define SSD_SCS_CDB_ERROR 0x40 266 #define SSD_SCS_SEGMENT_DESC 0x20 267 #define SSD_SCS_VALID_BIT_INDEX 0x08 268 #define SSD_SCS_BIT_INDEX 0x07 269 /*17*/ u_int8_t sense_key_spec_2; 270 /*18*/ u_int8_t sense_key_spec_3; 271 /*32*/ u_int8_t extra_bytes[14]; 272 }; 273 274 #define SKEY_NO_SENSE 0x00 275 #define SKEY_RECOVERED_ERROR 0x01 276 #define SKEY_NOT_READY 0x02 277 #define SKEY_MEDIUM_ERROR 0x03 278 #define SKEY_HARDWARE_ERROR 0x04 279 #define SKEY_ILLEGAL_REQUEST 0x05 280 #define SKEY_UNIT_ATTENTION 0x06 281 #define SKEY_WRITE_PROTECT 0x07 282 #define SKEY_BLANK_CHECK 0x08 283 #define SKEY_VENDOR_UNIQUE 0x09 284 #define SKEY_COPY_ABORTED 0x0A 285 #define SKEY_ABORTED_COMMAND 0x0B 286 #define SKEY_EQUAL 0x0C 287 #define SKEY_VOLUME_OVERFLOW 0x0D 288 #define SKEY_MISCOMPARE 0x0E 289 #define SKEY_RESERVED 0x0F 290 291 struct scsi_blk_desc { 292 u_int8_t density; 293 u_int8_t nblocks[3]; 294 u_int8_t reserved; 295 u_int8_t blklen[3]; 296 }; 297 298 struct scsi_direct_blk_desc { 299 u_int8_t nblocks[4]; 300 u_int8_t density; 301 u_int8_t blklen[3]; 302 }; 303 304 struct scsi_blk_desc_big { 305 u_int8_t nblocks[8]; 306 u_int8_t density; 307 u_int8_t reserved[3]; 308 u_int8_t blklen[4]; 309 }; 310 311 struct scsi_mode_header { 312 u_int8_t data_length; /* Sense data length */ 313 u_int8_t medium_type; 314 u_int8_t dev_spec; 315 u_int8_t blk_desc_len; 316 }; 317 318 struct scsi_mode_header_big { 319 u_int8_t data_length[2]; /* Sense data length */ 320 u_int8_t medium_type; 321 u_int8_t dev_spec; 322 u_int8_t reserved; 323 #define LONGLBA 0x01 324 u_int8_t reserved2; 325 u_int8_t blk_desc_len[2]; 326 }; 327 328 struct scsi_mode_sense_buf { 329 union { 330 struct scsi_mode_header hdr; 331 struct scsi_mode_header_big hdr_big; 332 u_char buf[255]; /* 256 bytes breaks some devices. */ 333 } headers; 334 }; 335 336 /* 337 * SPI status information unit. See section 14.3.5 of SPI-3. 338 */ 339 struct scsi_status_iu_header { 340 /* 2*/ u_int8_t reserved[2]; 341 /* 3*/ u_int8_t flags; 342 #define SIU_SNSVALID 0x2 343 #define SIU_RSPVALID 0x1 344 /* 4*/ u_int8_t status; 345 /* 8*/ u_int8_t sense_length[4]; 346 /*12*/ u_int8_t pkt_failures_length[4]; 347 u_int8_t data[1]; /* <pkt failure list><sense data> OR <sense_data> */ 348 }; 349 350 #define SIU_PKTFAIL_CODE(siu) ((siu)->data[3]) 351 #define SIU_PFC_NONE 0x00 352 #define SIU_PFC_CIU_FIELDS_INVALID 0x02 353 #define SIU_PFC_TMF_NOT_SUPPORTED 0x04 354 #define SIU_PFC_TMF_FAILED 0x05 355 #define SIU_PFC_INVALID_TYPE_CODE 0x06 356 #define SIU_PFC_ILLEGAL_REQUEST 0x07 357 358 #define SIU_SENSE_LENGTH(siu) (_4btol((siu)->sense_length)) 359 #define SIU_SENSE_DATA(siu) (((siu)->flags & SIU_RSPVALID) ? \ 360 &(siu)->data[_4btol((siu)->pkt_failures_length)] : &(siu)->data[0]) 361 362 /* 363 * Values for 'Task Management Flags' field of SPI command information unit. 364 * See section 14.3.1 of SPI-3. 365 */ 366 #define SIU_TASKMGMT_NONE 0x00 367 #define SIU_TASKMGMT_ABORT_TASK 0x01 368 #define SIU_TASKMGMT_ABORT_TASK_SET 0x02 369 #define SIU_TASKMGMT_CLEAR_TASK_SET 0x04 370 #define SIU_TASKMGMT_LUN_RESET 0x08 371 #define SIU_TASKMGMT_TARGET_RESET 0x20 372 #define SIU_TASKMGMT_CLEAR_ACA 0x40 373 374 /* 375 * Status Byte 376 */ 377 #define SCSI_OK 0x00 378 #define SCSI_CHECK 0x02 379 #define SCSI_COND_MET 0x04 380 #define SCSI_BUSY 0x08 381 #define SCSI_INTERM 0x10 382 #define SCSI_INTERM_COND_MET 0x14 383 #define SCSI_RESV_CONFLICT 0x18 384 #define SCSI_TERMINATED 0x22 385 #define SCSI_QUEUE_FULL 0x28 /* Old (Pre SCSI-3) name */ 386 #define SCSI_TASKSET_FULL 0x28 /* New (SCSI-3) name */ 387 #define SCSI_ACA_ACTIVE 0x30 388 389 #endif /* _SCSI_SCSI_ALL_H */ 390