1 /* $OpenBSD: scsi_all.h,v 1.47 2009/10/12 00:30:15 dlg 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[15]; 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 flags; 83 #define SI_EVPD 0x01 84 u_int8_t pagecode; 85 #define SI_PG_SUPPORTED 0x00 86 #define SI_PG_SERIAL 0x80 87 #define SI_PG_DEVID 0x83 88 u_int8_t length[2]; 89 u_int8_t control; 90 }; 91 92 struct scsi_mode_sense { 93 u_int8_t opcode; 94 u_int8_t byte2; 95 #define SMS_DBD 0x08 /* Disable Block Descriptors */ 96 u_int8_t page; 97 #define SMS_PAGE_CODE 0x3F 98 #define SMS_PAGE_CTRL 0xC0 99 #define SMS_PAGE_CTRL_CURRENT 0x00 100 #define SMS_PAGE_CTRL_CHANGEABLE 0x40 101 #define SMS_PAGE_CTRL_DEFAULT 0x80 102 #define SMS_PAGE_CTRL_SAVED 0xC0 103 u_int8_t unused; 104 u_int8_t length; 105 u_int8_t control; 106 }; 107 108 struct scsi_mode_sense_big { 109 u_int8_t opcode; 110 u_int8_t byte2; /* same bits as small version */ 111 #define SMS_LLBAA 0x10 /* plus: Long LBA Accepted */ 112 u_int8_t page; /* same bits as small version */ 113 u_int8_t unused[4]; 114 u_int8_t length[2]; 115 u_int8_t control; 116 }; 117 118 struct scsi_mode_select { 119 u_int8_t opcode; 120 u_int8_t byte2; 121 #define SMS_SP 0x01 122 #define SMS_PF 0x10 123 u_int8_t unused[2]; 124 u_int8_t length; 125 u_int8_t control; 126 }; 127 128 struct scsi_mode_select_big { 129 u_int8_t opcode; 130 u_int8_t byte2; /* same bits as small version */ 131 u_int8_t unused[5]; 132 u_int8_t length[2]; 133 u_int8_t control; 134 }; 135 136 struct scsi_reserve { 137 u_int8_t opcode; 138 u_int8_t byte2; 139 u_int8_t unused[2]; 140 u_int8_t length; 141 u_int8_t control; 142 }; 143 144 struct scsi_release { 145 u_int8_t opcode; 146 u_int8_t byte2; 147 u_int8_t unused[2]; 148 u_int8_t length; 149 u_int8_t control; 150 }; 151 152 struct scsi_prevent { 153 u_int8_t opcode; 154 u_int8_t byte2; 155 u_int8_t unused[2]; 156 u_int8_t how; 157 u_int8_t control; 158 }; 159 #define PR_PREVENT 0x01 160 #define PR_ALLOW 0x00 161 162 struct scsi_report_luns { 163 u_int8_t opcode; 164 u_int8_t unused; 165 u_int8_t selectreport; 166 #define REPORT_NORMAL 0x00 167 #define REPORT_WELLKNOWN 0x01 168 #define REPORT_ALL 0x02 169 u_int8_t unused2[3]; 170 u_int8_t length[4]; 171 u_int8_t unused4; 172 u_int8_t control; 173 }; 174 175 /* 176 * Opcodes 177 */ 178 #define TEST_UNIT_READY 0x00 179 #define REQUEST_SENSE 0x03 180 #define INQUIRY 0x12 181 #define MODE_SELECT 0x15 182 #define RESERVE 0x16 183 #define RELEASE 0x17 184 #define MODE_SENSE 0x1a 185 #define START_STOP 0x1b 186 #define RECEIVE_DIAGNOSTIC 0x1c 187 #define SEND_DIAGNOSTIC 0x1d 188 #define PREVENT_ALLOW 0x1e 189 #define POSITION_TO_ELEMENT 0x2b 190 #define WRITE_BUFFER 0x3b 191 #define READ_BUFFER 0x3c 192 #define CHANGE_DEFINITION 0x40 193 #define MODE_SELECT_BIG 0x55 194 #define MODE_SENSE_BIG 0x5a 195 #define REPORT_LUNS 0xa0 196 197 /* 198 * Sort of an extra one, for SCSI_RESET. 199 */ 200 #define GENRETRY 1 201 202 /* 203 * sense data format 204 */ 205 #define T_DIRECT 0 206 #define T_SEQUENTIAL 1 207 #define T_PRINTER 2 208 #define T_PROCESSOR 3 209 #define T_WORM 4 210 #define T_CDROM 5 211 #define T_SCANNER 6 212 #define T_OPTICAL 7 213 #define T_RDIRECT 14 214 #define T_NODEVICE 0x1F 215 216 #define T_CHANGER 8 217 #define T_COMM 9 218 #define T_ENCLOSURE 13 219 220 #define T_REMOV 1 221 #define T_FIXED 0 222 223 struct scsi_inquiry_data { 224 u_int8_t device; 225 #define SID_TYPE 0x1F 226 #define SID_QUAL 0xE0 227 #define SID_QUAL_LU_OK 0x00 228 #define SID_QUAL_LU_OFFLINE 0x20 229 #define SID_QUAL_RSVD 0x40 230 #define SID_QUAL_BAD_LU 0x60 231 u_int8_t dev_qual2; 232 #define SID_QUAL2 0x7F 233 #define SID_REMOVABLE 0x80 234 u_int8_t version; 235 #define SID_ANSII 0x07 236 #define SID_ECMA 0x38 237 #define SID_ISO 0xC0 238 u_int8_t response_format; 239 u_int8_t additional_length; 240 #define SID_INQUIRY_HDR 5 /* Bytes up to & including additional_length */ 241 #define SID_SCSI2_ALEN 31 /* Additional bytes of basic SCSI2 info */ 242 u_int8_t unused[2]; 243 u_int8_t flags; 244 #define SID_SftRe 0x01 245 #define SID_CmdQue 0x02 246 #define SID_Linked 0x08 247 #define SID_Sync 0x10 248 #define SID_WBus16 0x20 249 #define SID_WBus32 0x40 250 #define SID_RelAdr 0x80 251 char vendor[8]; 252 char product[16]; 253 char revision[4]; 254 u_int8_t extra[20]; 255 u_int8_t flags2; 256 #define SID_IUS 0x01 257 #define SID_QAS 0x02 258 #define SID_CLOCKING 0x0c /* 0 == ST only, 1 == DT only, 3 == both */ 259 u_int8_t reserved; 260 }; 261 262 struct scsi_vpd_hdr { 263 u_int8_t device; 264 u_int8_t page_code; 265 u_int8_t reserved; 266 u_int8_t page_length; 267 }; 268 269 struct scsi_vpd_serial { 270 struct scsi_vpd_hdr hdr; 271 char serial[32]; 272 }; 273 274 #define VPD_PROTO_ID_FC 0x0 /* Fibre Channel */ 275 #define VPD_PROTO_ID_SPI 0x1 /* Parallel SCSI */ 276 #define VPD_PROTO_ID_SSA 0x2 277 #define VPD_PROTO_ID_IEEE1394 0x3 278 #define VPD_PROTO_ID_SRP 0x4 /* SCSI RDMA Protocol */ 279 #define VPD_PROTO_ID_ISCSI 0x5 /* Internet SCSI (iSCSI) */ 280 #define VPD_PROTO_ID_SAS 0x6 /* Serial Attached SCSI */ 281 #define VPD_PROTO_ID_ADT 0x7 /* Automation/Drive Interface Transport */ 282 #define VPD_PROTO_ID_ATA 0x7 /* ATA/ATAPI */ 283 #define VPD_PROTO_ID_NONE 0xf 284 285 struct scsi_vpd_devid_hdr { 286 u_int8_t pi_code; 287 #define VPD_DEVID_PI(_f) (((_f) >> 4) & 0x0f) 288 #define VPD_DEVID_CODE(_f) (((_f) >> 0) & 0x0f) 289 #define VPD_DEVID_CODE_BINARY 0x1 290 #define VPD_DEVID_CODE_ASCII 0x2 291 #define VPD_DEVID_CODE_UTF8 0x3 292 u_int8_t flags; 293 #define VPD_DEVID_PIV 0x80 294 #define VPD_DEVID_ASSOC(_f) ((_f) & 0x30) 295 #define VPD_DEVID_ASSOC_LU 0x00 296 #define VPD_DEVID_ASSOC_PORT 0x10 297 #define VPD_DEVID_ASSOC_TARG 0x20 298 #define VPD_DEVID_TYPE(_f) ((_f) & 0x0f) 299 #define VPD_DEVID_TYPE_VENDOR 0x0 300 #define VPD_DEVID_TYPE_T10 0x1 301 #define VPD_DEVID_TYPE_EUI64 0x2 302 #define VPD_DEVID_TYPE_NAA 0x3 303 #define VPD_DEVID_TYPE_RELATIVE 0x4 304 #define VPD_DEVID_TYPE_PORT 0x5 305 #define VPD_DEVID_TYPE_LU 0x6 306 #define VPD_DEVID_TYPE_MD5 0x7 307 #define VPD_DEVID_TYPE_NAME 0x8 308 u_int8_t reserved; 309 u_int8_t len; 310 }; 311 312 struct scsi_sense_data_unextended { 313 /* 1*/ u_int8_t error_code; 314 /* 4*/ u_int8_t block[3]; 315 }; 316 317 struct scsi_sense_data { 318 /* 1*/ u_int8_t error_code; 319 #define SSD_ERRCODE_CURRENT 0x70 320 #define SSD_ERRCODE_DEFERRED 0x71 321 #define SSD_ERRCODE 0x7F 322 #define SSD_ERRCODE_VALID 0x80 323 /* 2*/ u_int8_t segment; 324 /* 3*/ u_int8_t flags; 325 #define SSD_KEY 0x0F 326 #define SSD_ILI 0x20 327 #define SSD_EOM 0x40 328 #define SSD_FILEMARK 0x80 329 /* 7*/ u_int8_t info[4]; 330 /* 8*/ u_int8_t extra_len; 331 /*12*/ u_int8_t cmd_spec_info[4]; 332 /*13*/ u_int8_t add_sense_code; 333 /*14*/ u_int8_t add_sense_code_qual; 334 /*15*/ u_int8_t fru; 335 /*16*/ u_int8_t sense_key_spec_1; 336 #define SSD_SCS_VALID 0x80 337 #define SSD_SCS_CDB_ERROR 0x40 338 #define SSD_SCS_SEGMENT_DESC 0x20 339 #define SSD_SCS_VALID_BIT_INDEX 0x08 340 #define SSD_SCS_BIT_INDEX 0x07 341 /*17*/ u_int8_t sense_key_spec_2; 342 /*18*/ u_int8_t sense_key_spec_3; 343 /*32*/ u_int8_t extra_bytes[14]; 344 }; 345 346 #define SKEY_NO_SENSE 0x00 347 #define SKEY_RECOVERED_ERROR 0x01 348 #define SKEY_NOT_READY 0x02 349 #define SKEY_MEDIUM_ERROR 0x03 350 #define SKEY_HARDWARE_ERROR 0x04 351 #define SKEY_ILLEGAL_REQUEST 0x05 352 #define SKEY_UNIT_ATTENTION 0x06 353 #define SKEY_WRITE_PROTECT 0x07 354 #define SKEY_BLANK_CHECK 0x08 355 #define SKEY_VENDOR_UNIQUE 0x09 356 #define SKEY_COPY_ABORTED 0x0A 357 #define SKEY_ABORTED_COMMAND 0x0B 358 #define SKEY_EQUAL 0x0C 359 #define SKEY_VOLUME_OVERFLOW 0x0D 360 #define SKEY_MISCOMPARE 0x0E 361 #define SKEY_RESERVED 0x0F 362 363 364 /* Additional sense code info */ 365 #define ASC_ASCQ(ssd) ((ssd->add_sense_code << 8) | ssd->add_sense_code_qual) 366 367 #define SENSE_NOT_READY_BECOMING_READY 0x0401 368 #define SENSE_NOT_READY_INIT_REQUIRED 0x0402 369 #define SENSE_NOT_READY_FORMAT 0x0404 370 #define SENSE_NOT_READY_REBUILD 0x0405 371 #define SENSE_NOT_READY_RECALC 0x0406 372 #define SENSE_NOT_READY_INPROGRESS 0x0407 373 #define SENSE_NOT_READY_LONGWRITE 0x0408 374 #define SENSE_NOT_READY_SELFTEST 0x0409 375 #define SENSE_POWER_RESET_OR_BUS 0x2900 376 #define SENSE_POWER_ON 0x2901 377 #define SENSE_BUS_RESET 0x2902 378 #define SENSE_BUS_DEVICE_RESET 0x2903 379 #define SENSE_DEVICE_INTERNAL_RESET 0x2904 380 #define SENSE_TSC_CHANGE_SE 0x2905 381 #define SENSE_TSC_CHANGE_LVD 0x2906 382 #define SENSE_IT_NEXUS_LOSS 0x2907 383 #define SENSE_BAD_MEDIUM 0x3000 384 #define SENSE_NR_MEDIUM_UNKNOWN_FORMAT 0x3001 385 #define SENSE_NR_MEDIUM_INCOMPATIBLE_FORMAT 0x3002 386 #define SENSE_NW_MEDIUM_UNKNOWN_FORMAT 0x3004 387 #define SENSE_NW_MEDIUM_INCOMPATIBLE_FORMAT 0x3005 388 #define SENSE_NF_MEDIUM_INCOMPATIBLE_FORMAT 0x3006 389 #define SENSE_NW_MEDIUM_AC_MISMATCH 0x3008 390 #define SENSE_NOMEDIUM 0x3A00 391 #define SENSE_NOMEDIUM_TCLOSED 0x3A01 392 #define SENSE_NOMEDIUM_TOPEN 0x3A02 393 #define SENSE_NOMEDIUM_LOADABLE 0x3A03 394 #define SENSE_NOMEDIUM_AUXMEM 0x3A04 395 #define SENSE_CARTRIDGE_FAULT 0x5200 396 #define SENSE_MEDIUM_REMOVAL_PREVENTED 0x5302 397 398 struct scsi_blk_desc { 399 u_int8_t density; 400 u_int8_t nblocks[3]; 401 u_int8_t reserved; 402 u_int8_t blklen[3]; 403 }; 404 405 struct scsi_direct_blk_desc { 406 u_int8_t nblocks[4]; 407 u_int8_t density; 408 u_int8_t blklen[3]; 409 }; 410 411 struct scsi_blk_desc_big { 412 u_int8_t nblocks[8]; 413 u_int8_t density; 414 u_int8_t reserved[3]; 415 u_int8_t blklen[4]; 416 }; 417 418 struct scsi_mode_header { 419 u_int8_t data_length; /* Sense data length */ 420 u_int8_t medium_type; 421 u_int8_t dev_spec; 422 u_int8_t blk_desc_len; 423 }; 424 425 struct scsi_mode_header_big { 426 u_int8_t data_length[2]; /* Sense data length */ 427 u_int8_t medium_type; 428 u_int8_t dev_spec; 429 u_int8_t reserved; 430 #define LONGLBA 0x01 431 u_int8_t reserved2; 432 u_int8_t blk_desc_len[2]; 433 }; 434 435 union scsi_mode_sense_buf { 436 struct scsi_mode_header hdr; 437 struct scsi_mode_header_big hdr_big; 438 u_char buf[254]; /* 255 & 256 bytes breaks some devices. */ 439 /* ahci doesn't like 255, various don't like */ 440 /* 256 because length must fit in 8 bits. */ 441 } __packed; /* Ensure sizeof() is 254! */ 442 443 struct scsi_report_luns_data { 444 u_int8_t length[4]; /* length of LUN inventory, in bytes */ 445 u_int8_t reserved[4]; /* unused */ 446 /* 447 * LUN inventory- we only support the type zero form for now. 448 */ 449 #define RPL_LUNDATA_SIZE 8 /* Bytes per lun */ 450 struct { 451 u_int8_t lundata[RPL_LUNDATA_SIZE]; 452 } luns[256]; /* scsi_link->luns is u_int8_t. */ 453 }; 454 #define RPL_LUNDATA_T0LUN 1 /* Type 0 LUN is in lundata[1] */ 455 456 /* 457 * SPI status information unit. See section 14.3.5 of SPI-3. 458 */ 459 struct scsi_status_iu_header { 460 /* 2*/ u_int8_t reserved[2]; 461 /* 3*/ u_int8_t flags; 462 #define SIU_SNSVALID 0x2 463 #define SIU_RSPVALID 0x1 464 /* 4*/ u_int8_t status; 465 /* 8*/ u_int8_t sense_length[4]; 466 /*12*/ u_int8_t pkt_failures_length[4]; 467 u_int8_t data[1]; /* <pkt failure list><sense data> OR <sense_data> */ 468 }; 469 470 #define SIU_PKTFAIL_CODE(siu) ((siu)->data[3]) 471 #define SIU_PFC_NONE 0x00 472 #define SIU_PFC_CIU_FIELDS_INVALID 0x02 473 #define SIU_PFC_TMF_NOT_SUPPORTED 0x04 474 #define SIU_PFC_TMF_FAILED 0x05 475 #define SIU_PFC_INVALID_TYPE_CODE 0x06 476 #define SIU_PFC_ILLEGAL_REQUEST 0x07 477 478 #define SIU_SENSE_LENGTH(siu) (_4btol((siu)->sense_length)) 479 #define SIU_SENSE_DATA(siu) (((siu)->flags & SIU_RSPVALID) ? \ 480 &(siu)->data[_4btol((siu)->pkt_failures_length)] : &(siu)->data[0]) 481 482 /* 483 * Values for 'Task Management Flags' field of SPI command information unit. 484 * See section 14.3.1 of SPI-3. 485 */ 486 #define SIU_TASKMGMT_NONE 0x00 487 #define SIU_TASKMGMT_ABORT_TASK 0x01 488 #define SIU_TASKMGMT_ABORT_TASK_SET 0x02 489 #define SIU_TASKMGMT_CLEAR_TASK_SET 0x04 490 #define SIU_TASKMGMT_LUN_RESET 0x08 491 #define SIU_TASKMGMT_TARGET_RESET 0x20 492 #define SIU_TASKMGMT_CLEAR_ACA 0x40 493 494 /* 495 * Status Byte 496 */ 497 #define SCSI_OK 0x00 498 #define SCSI_CHECK 0x02 499 #define SCSI_COND_MET 0x04 500 #define SCSI_BUSY 0x08 501 #define SCSI_INTERM 0x10 502 #define SCSI_INTERM_COND_MET 0x14 503 #define SCSI_RESV_CONFLICT 0x18 504 #define SCSI_TERMINATED 0x22 505 #define SCSI_QUEUE_FULL 0x28 /* Old (Pre SCSI-3) name */ 506 #define SCSI_TASKSET_FULL 0x28 /* New (SCSI-3) name */ 507 #define SCSI_ACA_ACTIVE 0x30 508 509 #endif /* _SCSI_SCSI_ALL_H */ 510