1 /*- 2 * Largely written by Julian Elischer (julian@tfs.com) 3 * for TRW Financial Systems. 4 * 5 * TRW Financial Systems, in accordance with their agreement with Carnegie 6 * Mellon University, makes this software available to CMU to distribute 7 * or use in any manner that they see fit as long as this message is kept with 8 * the software. For this reason TFS also grants any other persons or 9 * organisations permission to use or modify this software. 10 * 11 * TFS supplies this software to be publicly redistributed 12 * on the understanding that TFS is not responsible for the correct 13 * functioning of this software in any circumstances. 14 * 15 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 16 * 17 * $FreeBSD$ 18 */ 19 20 /* 21 * SCSI general interface description 22 */ 23 24 #ifndef _SCSI_SCSI_ALL_H 25 #define _SCSI_SCSI_ALL_H 1 26 27 #include <sys/cdefs.h> 28 #include <machine/stdarg.h> 29 30 #ifdef _KERNEL 31 /* 32 * This is the number of seconds we wait for devices to settle after a SCSI 33 * bus reset. 34 */ 35 extern int scsi_delay; 36 #endif /* _KERNEL */ 37 38 /* 39 * SCSI command format 40 */ 41 42 /* 43 * Define dome bits that are in ALL (or a lot of) scsi commands 44 */ 45 #define SCSI_CTL_LINK 0x01 46 #define SCSI_CTL_FLAG 0x02 47 #define SCSI_CTL_VENDOR 0xC0 48 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */ 49 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */ 50 51 #define SCSI_MAX_CDBLEN 16 /* 52 * 16 byte commands are in the 53 * SCSI-3 spec 54 */ 55 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN) 56 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN" 57 #endif 58 59 /* 6byte CDBs special case 0 length to be 256 */ 60 #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len) 61 62 /* 63 * This type defines actions to be taken when a particular sense code is 64 * received. Right now, these flags are only defined to take up 16 bits, 65 * but can be expanded in the future if necessary. 66 */ 67 typedef enum { 68 SS_NOP = 0x000000, /* Do nothing */ 69 SS_RETRY = 0x010000, /* Retry the command */ 70 SS_FAIL = 0x020000, /* Bail out */ 71 SS_START = 0x030000, /* Send a Start Unit command to the device, 72 * then retry the original command. 73 */ 74 SS_TUR = 0x040000, /* Send a Test Unit Ready command to the 75 * device, then retry the original command. 76 */ 77 SS_REQSENSE = 0x050000, /* Send a RequestSense command to the 78 * device, then retry the original command. 79 */ 80 SS_MASK = 0xff0000 81 } scsi_sense_action; 82 83 typedef enum { 84 SSQ_NONE = 0x0000, 85 SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */ 86 SSQ_MANY = 0x0200, /* send lots of recovery commands */ 87 SSQ_RANGE = 0x0400, /* 88 * This table entry represents the 89 * end of a range of ASCQs that 90 * have identical error actions 91 * and text. 92 */ 93 SSQ_PRINT_SENSE = 0x0800, 94 SSQ_MASK = 0xff00 95 } scsi_sense_action_qualifier; 96 97 /* Mask for error status values */ 98 #define SS_ERRMASK 0xff 99 100 /* The default, retyable, error action */ 101 #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO 102 103 /* The retyable, error action, with table specified error code */ 104 #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE 105 106 /* Fatal error action, with table specified error code */ 107 #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE 108 109 struct scsi_generic 110 { 111 u_int8_t opcode; 112 u_int8_t bytes[11]; 113 }; 114 115 struct scsi_request_sense 116 { 117 u_int8_t opcode; 118 u_int8_t byte2; 119 #define SRS_DESC 0x01 120 u_int8_t unused[2]; 121 u_int8_t length; 122 u_int8_t control; 123 }; 124 125 struct scsi_test_unit_ready 126 { 127 u_int8_t opcode; 128 u_int8_t byte2; 129 u_int8_t unused[3]; 130 u_int8_t control; 131 }; 132 133 struct scsi_receive_diag { 134 uint8_t opcode; 135 uint8_t byte2; 136 #define SRD_PCV 0x01 137 uint8_t page_code; 138 uint8_t length[2]; 139 uint8_t control; 140 }; 141 142 struct scsi_send_diag { 143 uint8_t opcode; 144 uint8_t byte2; 145 #define SSD_UNITOFFL 0x01 146 #define SSD_DEVOFFL 0x02 147 #define SSD_SELFTEST 0x04 148 #define SSD_PF 0x10 149 #define SSD_SELF_TEST_CODE_MASK 0xE0 150 #define SSD_SELF_TEST_CODE_SHIFT 5 151 #define SSD_SELF_TEST_CODE_NONE 0x00 152 #define SSD_SELF_TEST_CODE_BG_SHORT 0x01 153 #define SSD_SELF_TEST_CODE_BG_EXTENDED 0x02 154 #define SSD_SELF_TEST_CODE_BG_ABORT 0x04 155 #define SSD_SELF_TEST_CODE_FG_SHORT 0x05 156 #define SSD_SELF_TEST_CODE_FG_EXTENDED 0x06 157 uint8_t reserved; 158 uint8_t length[2]; 159 uint8_t control; 160 }; 161 162 struct scsi_sense 163 { 164 u_int8_t opcode; 165 u_int8_t byte2; 166 u_int8_t unused[2]; 167 u_int8_t length; 168 u_int8_t control; 169 }; 170 171 struct scsi_inquiry 172 { 173 u_int8_t opcode; 174 u_int8_t byte2; 175 #define SI_EVPD 0x01 176 #define SI_CMDDT 0x02 177 u_int8_t page_code; 178 u_int8_t reserved; 179 u_int8_t length; 180 u_int8_t control; 181 }; 182 183 struct scsi_mode_sense_6 184 { 185 u_int8_t opcode; 186 u_int8_t byte2; 187 #define SMS_DBD 0x08 188 u_int8_t page; 189 #define SMS_PAGE_CODE 0x3F 190 #define SMS_VENDOR_SPECIFIC_PAGE 0x00 191 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02 192 #define SMS_FORMAT_DEVICE_PAGE 0x03 193 #define SMS_GEOMETRY_PAGE 0x04 194 #define SMS_CACHE_PAGE 0x08 195 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09 196 #define SMS_CONTROL_MODE_PAGE 0x0A 197 #define SMS_PROTO_SPECIFIC_PAGE 0x19 198 #define SMS_INFO_EXCEPTIONS_PAGE 0x1C 199 #define SMS_ALL_PAGES_PAGE 0x3F 200 #define SMS_PAGE_CTRL_MASK 0xC0 201 #define SMS_PAGE_CTRL_CURRENT 0x00 202 #define SMS_PAGE_CTRL_CHANGEABLE 0x40 203 #define SMS_PAGE_CTRL_DEFAULT 0x80 204 #define SMS_PAGE_CTRL_SAVED 0xC0 205 u_int8_t subpage; 206 #define SMS_SUBPAGE_PAGE_0 0x00 207 #define SMS_SUBPAGE_ALL 0xff 208 u_int8_t length; 209 u_int8_t control; 210 }; 211 212 struct scsi_mode_sense_10 213 { 214 u_int8_t opcode; 215 u_int8_t byte2; /* same bits as small version */ 216 #define SMS10_LLBAA 0x10 217 u_int8_t page; /* same bits as small version */ 218 u_int8_t subpage; 219 u_int8_t unused[3]; 220 u_int8_t length[2]; 221 u_int8_t control; 222 }; 223 224 struct scsi_mode_select_6 225 { 226 u_int8_t opcode; 227 u_int8_t byte2; 228 #define SMS_SP 0x01 229 #define SMS_PF 0x10 230 u_int8_t unused[2]; 231 u_int8_t length; 232 u_int8_t control; 233 }; 234 235 struct scsi_mode_select_10 236 { 237 u_int8_t opcode; 238 u_int8_t byte2; /* same bits as small version */ 239 u_int8_t unused[5]; 240 u_int8_t length[2]; 241 u_int8_t control; 242 }; 243 244 /* 245 * When sending a mode select to a tape drive, the medium type must be 0. 246 */ 247 struct scsi_mode_hdr_6 248 { 249 u_int8_t datalen; 250 u_int8_t medium_type; 251 u_int8_t dev_specific; 252 u_int8_t block_descr_len; 253 }; 254 255 struct scsi_mode_hdr_10 256 { 257 u_int8_t datalen[2]; 258 u_int8_t medium_type; 259 u_int8_t dev_specific; 260 u_int8_t reserved[2]; 261 u_int8_t block_descr_len[2]; 262 }; 263 264 struct scsi_mode_block_descr 265 { 266 u_int8_t density_code; 267 u_int8_t num_blocks[3]; 268 u_int8_t reserved; 269 u_int8_t block_len[3]; 270 }; 271 272 struct scsi_per_res_in 273 { 274 u_int8_t opcode; 275 u_int8_t action; 276 #define SPRI_RK 0x00 277 #define SPRI_RR 0x01 278 #define SPRI_RC 0x02 279 #define SPRI_RS 0x03 280 u_int8_t reserved[5]; 281 u_int8_t length[2]; 282 u_int8_t control; 283 }; 284 285 struct scsi_per_res_in_header 286 { 287 u_int8_t generation[4]; 288 u_int8_t length[4]; 289 }; 290 291 struct scsi_per_res_key 292 { 293 u_int8_t key[8]; 294 }; 295 296 struct scsi_per_res_in_keys 297 { 298 struct scsi_per_res_in_header header; 299 struct scsi_per_res_key keys[0]; 300 }; 301 302 struct scsi_per_res_cap 303 { 304 uint8_t length[2]; 305 uint8_t flags1; 306 #define SPRI_CRH 0x10 307 #define SPRI_SIP_C 0x08 308 #define SPRI_ATP_C 0x04 309 #define SPRI_PTPL_C 0x01 310 uint8_t flags2; 311 #define SPRI_TMV 0x80 312 #define SPRI_PTPL_A 0x01 313 uint8_t type_mask[2]; 314 #define SPRI_TM_WR_EX_AR 0x8000 315 #define SPRI_TM_EX_AC_RO 0x4000 316 #define SPRI_TM_WR_EX_RO 0x2000 317 #define SPRI_TM_EX_AC 0x0800 318 #define SPRI_TM_WR_EX 0x0200 319 #define SPRI_TM_EX_AC_AR 0x0001 320 uint8_t reserved[2]; 321 }; 322 323 struct scsi_per_res_in_rsrv_data 324 { 325 uint8_t reservation[8]; 326 uint8_t obsolete1[4]; 327 uint8_t reserved; 328 uint8_t scopetype; 329 #define SPRT_WE 0x01 330 #define SPRT_EA 0x03 331 #define SPRT_WERO 0x05 332 #define SPRT_EARO 0x06 333 #define SPRT_WEAR 0x07 334 #define SPRT_EAAR 0x08 335 uint8_t obsolete2[2]; 336 }; 337 338 struct scsi_per_res_in_rsrv 339 { 340 struct scsi_per_res_in_header header; 341 struct scsi_per_res_in_rsrv_data data; 342 }; 343 344 struct scsi_per_res_out 345 { 346 u_int8_t opcode; 347 u_int8_t action; 348 #define SPRO_REGISTER 0x00 349 #define SPRO_RESERVE 0x01 350 #define SPRO_RELEASE 0x02 351 #define SPRO_CLEAR 0x03 352 #define SPRO_PREEMPT 0x04 353 #define SPRO_PRE_ABO 0x05 354 #define SPRO_REG_IGNO 0x06 355 #define SPRO_REG_MOVE 0x07 356 #define SPRO_ACTION_MASK 0x1f 357 u_int8_t scope_type; 358 #define SPR_SCOPE_MASK 0xf0 359 #define SPR_LU_SCOPE 0x00 360 #define SPR_TYPE_MASK 0x0f 361 #define SPR_TYPE_WR_EX 0x01 362 #define SPR_TYPE_EX_AC 0x03 363 #define SPR_TYPE_WR_EX_RO 0x05 364 #define SPR_TYPE_EX_AC_RO 0x06 365 #define SPR_TYPE_WR_EX_AR 0x07 366 #define SPR_TYPE_EX_AC_AR 0x08 367 u_int8_t reserved[2]; 368 u_int8_t length[4]; 369 u_int8_t control; 370 }; 371 372 struct scsi_per_res_out_parms 373 { 374 struct scsi_per_res_key res_key; 375 u_int8_t serv_act_res_key[8]; 376 u_int8_t obsolete1[4]; 377 u_int8_t flags; 378 #define SPR_SPEC_I_PT 0x08 379 #define SPR_ALL_TG_PT 0x04 380 #define SPR_APTPL 0x01 381 u_int8_t reserved1; 382 u_int8_t obsolete2[2]; 383 }; 384 385 386 struct scsi_log_sense 387 { 388 u_int8_t opcode; 389 u_int8_t byte2; 390 #define SLS_SP 0x01 391 #define SLS_PPC 0x02 392 u_int8_t page; 393 #define SLS_PAGE_CODE 0x3F 394 #define SLS_ALL_PAGES_PAGE 0x00 395 #define SLS_OVERRUN_PAGE 0x01 396 #define SLS_ERROR_WRITE_PAGE 0x02 397 #define SLS_ERROR_READ_PAGE 0x03 398 #define SLS_ERROR_READREVERSE_PAGE 0x04 399 #define SLS_ERROR_VERIFY_PAGE 0x05 400 #define SLS_ERROR_NONMEDIUM_PAGE 0x06 401 #define SLS_ERROR_LASTN_PAGE 0x07 402 #define SLS_SELF_TEST_PAGE 0x10 403 #define SLS_IE_PAGE 0x2f 404 #define SLS_PAGE_CTRL_MASK 0xC0 405 #define SLS_PAGE_CTRL_THRESHOLD 0x00 406 #define SLS_PAGE_CTRL_CUMULATIVE 0x40 407 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 408 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 409 u_int8_t reserved[2]; 410 u_int8_t paramptr[2]; 411 u_int8_t length[2]; 412 u_int8_t control; 413 }; 414 415 struct scsi_log_select 416 { 417 u_int8_t opcode; 418 u_int8_t byte2; 419 /* SLS_SP 0x01 */ 420 #define SLS_PCR 0x02 421 u_int8_t page; 422 /* SLS_PAGE_CTRL_MASK 0xC0 */ 423 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */ 424 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */ 425 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */ 426 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */ 427 u_int8_t reserved[4]; 428 u_int8_t length[2]; 429 u_int8_t control; 430 }; 431 432 struct scsi_log_header 433 { 434 u_int8_t page; 435 u_int8_t reserved; 436 u_int8_t datalen[2]; 437 }; 438 439 struct scsi_log_param_header { 440 u_int8_t param_code[2]; 441 u_int8_t param_control; 442 #define SLP_LP 0x01 443 #define SLP_LBIN 0x02 444 #define SLP_TMC_MASK 0x0C 445 #define SLP_TMC_ALWAYS 0x00 446 #define SLP_TMC_EQUAL 0x04 447 #define SLP_TMC_NOTEQUAL 0x08 448 #define SLP_TMC_GREATER 0x0C 449 #define SLP_ETC 0x10 450 #define SLP_TSD 0x20 451 #define SLP_DS 0x40 452 #define SLP_DU 0x80 453 u_int8_t param_len; 454 }; 455 456 struct scsi_control_page { 457 u_int8_t page_code; 458 u_int8_t page_length; 459 u_int8_t rlec; 460 #define SCP_RLEC 0x01 /*Report Log Exception Cond*/ 461 #define SCP_GLTSD 0x02 /*Global Logging target 462 save disable */ 463 #define SCP_DSENSE 0x04 /*Descriptor Sense */ 464 #define SCP_DPICZ 0x08 /*Disable Prot. Info Check 465 if Prot. Field is Zero */ 466 #define SCP_TMF_ONLY 0x10 /*TM Functions Only*/ 467 #define SCP_TST_MASK 0xE0 /*Task Set Type Mask*/ 468 #define SCP_TST_ONE 0x00 /*One Task Set*/ 469 #define SCP_TST_SEPARATE 0x20 /*Separate Task Sets*/ 470 u_int8_t queue_flags; 471 #define SCP_QUEUE_ALG_MASK 0xF0 472 #define SCP_QUEUE_ALG_RESTRICTED 0x00 473 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10 474 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/ 475 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/ 476 u_int8_t eca_and_aen; 477 #define SCP_EECA 0x80 /*Enable Extended CA*/ 478 #define SCP_RAENP 0x04 /*Ready AEN Permission*/ 479 #define SCP_UAAENP 0x02 /*UA AEN Permission*/ 480 #define SCP_EAENP 0x01 /*Error AEN Permission*/ 481 u_int8_t reserved; 482 u_int8_t aen_holdoff_period[2]; 483 }; 484 485 struct scsi_cache_page { 486 u_int8_t page_code; 487 #define SCHP_PAGE_SAVABLE 0x80 /* Page is savable */ 488 u_int8_t page_length; 489 u_int8_t cache_flags; 490 #define SCHP_FLAGS_WCE 0x04 /* Write Cache Enable */ 491 #define SCHP_FLAGS_MF 0x02 /* Multiplication factor */ 492 #define SCHP_FLAGS_RCD 0x01 /* Read Cache Disable */ 493 u_int8_t rw_cache_policy; 494 u_int8_t dis_prefetch[2]; 495 u_int8_t min_prefetch[2]; 496 u_int8_t max_prefetch[2]; 497 u_int8_t max_prefetch_ceil[2]; 498 }; 499 500 /* 501 * XXX KDM 502 * Updated version of the cache page, as of SBC. Update this to SBC-3 and 503 * rationalize the two. 504 */ 505 struct scsi_caching_page { 506 uint8_t page_code; 507 #define SMS_CACHING_PAGE 0x08 508 uint8_t page_length; 509 uint8_t flags1; 510 #define SCP_IC 0x80 511 #define SCP_ABPF 0x40 512 #define SCP_CAP 0x20 513 #define SCP_DISC 0x10 514 #define SCP_SIZE 0x08 515 #define SCP_WCE 0x04 516 #define SCP_MF 0x02 517 #define SCP_RCD 0x01 518 uint8_t ret_priority; 519 uint8_t disable_pf_transfer_len[2]; 520 uint8_t min_prefetch[2]; 521 uint8_t max_prefetch[2]; 522 uint8_t max_pf_ceiling[2]; 523 uint8_t flags2; 524 #define SCP_FSW 0x80 525 #define SCP_LBCSS 0x40 526 #define SCP_DRA 0x20 527 #define SCP_VS1 0x10 528 #define SCP_VS2 0x08 529 uint8_t cache_segments; 530 uint8_t cache_seg_size[2]; 531 uint8_t reserved; 532 uint8_t non_cache_seg_size[3]; 533 }; 534 535 struct scsi_info_exceptions_page { 536 u_int8_t page_code; 537 #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */ 538 u_int8_t page_length; 539 u_int8_t info_flags; 540 #define SIEP_FLAGS_PERF 0x80 541 #define SIEP_FLAGS_EBF 0x20 542 #define SIEP_FLAGS_EWASC 0x10 543 #define SIEP_FLAGS_DEXCPT 0x08 544 #define SIEP_FLAGS_TEST 0x04 545 #define SIEP_FLAGS_EBACKERR 0x02 546 #define SIEP_FLAGS_LOGERR 0x01 547 u_int8_t mrie; 548 u_int8_t interval_timer[4]; 549 u_int8_t report_count[4]; 550 }; 551 552 struct scsi_proto_specific_page { 553 u_int8_t page_code; 554 #define SPSP_PAGE_SAVABLE 0x80 /* Page is savable */ 555 u_int8_t page_length; 556 u_int8_t protocol; 557 #define SPSP_PROTO_FC 0x00 558 #define SPSP_PROTO_SPI 0x01 559 #define SPSP_PROTO_SSA 0x02 560 #define SPSP_PROTO_1394 0x03 561 #define SPSP_PROTO_RDMA 0x04 562 #define SPSP_PROTO_ISCSI 0x05 563 #define SPSP_PROTO_SAS 0x06 564 #define SPSP_PROTO_ADT 0x07 565 #define SPSP_PROTO_ATA 0x08 566 #define SPSP_PROTO_NONE 0x0f 567 }; 568 569 struct scsi_reserve 570 { 571 u_int8_t opcode; 572 u_int8_t byte2; 573 #define SR_EXTENT 0x01 574 #define SR_ID_MASK 0x0e 575 #define SR_3RDPTY 0x10 576 #define SR_LUN_MASK 0xe0 577 u_int8_t resv_id; 578 u_int8_t length[2]; 579 u_int8_t control; 580 }; 581 582 struct scsi_reserve_10 { 583 uint8_t opcode; 584 uint8_t byte2; 585 #define SR10_3RDPTY 0x10 586 #define SR10_LONGID 0x02 587 #define SR10_EXTENT 0x01 588 uint8_t resv_id; 589 uint8_t thirdparty_id; 590 uint8_t reserved[3]; 591 uint8_t length[2]; 592 uint8_t control; 593 }; 594 595 596 struct scsi_release 597 { 598 u_int8_t opcode; 599 u_int8_t byte2; 600 u_int8_t resv_id; 601 u_int8_t unused[1]; 602 u_int8_t length; 603 u_int8_t control; 604 }; 605 606 struct scsi_release_10 { 607 uint8_t opcode; 608 uint8_t byte2; 609 uint8_t resv_id; 610 uint8_t thirdparty_id; 611 uint8_t reserved[3]; 612 uint8_t length[2]; 613 uint8_t control; 614 }; 615 616 struct scsi_prevent 617 { 618 u_int8_t opcode; 619 u_int8_t byte2; 620 u_int8_t unused[2]; 621 u_int8_t how; 622 u_int8_t control; 623 }; 624 #define PR_PREVENT 0x01 625 #define PR_ALLOW 0x00 626 627 struct scsi_sync_cache 628 { 629 u_int8_t opcode; 630 u_int8_t byte2; 631 #define SSC_IMMED 0x02 632 #define SSC_RELADR 0x01 633 u_int8_t begin_lba[4]; 634 u_int8_t reserved; 635 u_int8_t lb_count[2]; 636 u_int8_t control; 637 }; 638 639 struct scsi_sync_cache_16 640 { 641 uint8_t opcode; 642 uint8_t byte2; 643 uint8_t begin_lba[8]; 644 uint8_t lb_count[4]; 645 uint8_t reserved; 646 uint8_t control; 647 }; 648 649 struct scsi_format { 650 uint8_t opcode; 651 uint8_t byte2; 652 #define SF_LONGLIST 0x20 653 #define SF_FMTDATA 0x10 654 #define SF_CMPLIST 0x08 655 #define SF_FORMAT_MASK 0x07 656 #define SF_FORMAT_BLOCK 0x00 657 #define SF_FORMAT_LONG_BLOCK 0x03 658 #define SF_FORMAT_BFI 0x04 659 #define SF_FORMAT_PHYS 0x05 660 uint8_t vendor; 661 uint8_t interleave[2]; 662 uint8_t control; 663 }; 664 665 struct scsi_format_header_short { 666 uint8_t reserved; 667 #define SF_DATA_FOV 0x80 668 #define SF_DATA_DPRY 0x40 669 #define SF_DATA_DCRT 0x20 670 #define SF_DATA_STPF 0x10 671 #define SF_DATA_IP 0x08 672 #define SF_DATA_DSP 0x04 673 #define SF_DATA_IMMED 0x02 674 #define SF_DATA_VS 0x01 675 uint8_t byte2; 676 uint8_t defect_list_len[2]; 677 }; 678 679 struct scsi_format_header_long { 680 uint8_t reserved; 681 uint8_t byte2; 682 uint8_t reserved2[2]; 683 uint8_t defect_list_len[4]; 684 }; 685 686 struct scsi_changedef 687 { 688 u_int8_t opcode; 689 u_int8_t byte2; 690 u_int8_t unused1; 691 u_int8_t how; 692 u_int8_t unused[4]; 693 u_int8_t datalen; 694 u_int8_t control; 695 }; 696 697 struct scsi_read_buffer 698 { 699 u_int8_t opcode; 700 u_int8_t byte2; 701 #define RWB_MODE 0x07 702 #define RWB_MODE_HDR_DATA 0x00 703 #define RWB_MODE_VENDOR 0x01 704 #define RWB_MODE_DATA 0x02 705 #define RWB_MODE_DOWNLOAD 0x04 706 #define RWB_MODE_DOWNLOAD_SAVE 0x05 707 u_int8_t buffer_id; 708 u_int8_t offset[3]; 709 u_int8_t length[3]; 710 u_int8_t control; 711 }; 712 713 struct scsi_write_buffer 714 { 715 u_int8_t opcode; 716 u_int8_t byte2; 717 u_int8_t buffer_id; 718 u_int8_t offset[3]; 719 u_int8_t length[3]; 720 u_int8_t control; 721 }; 722 723 struct scsi_rw_6 724 { 725 u_int8_t opcode; 726 u_int8_t addr[3]; 727 /* only 5 bits are valid in the MSB address byte */ 728 #define SRW_TOPADDR 0x1F 729 u_int8_t length; 730 u_int8_t control; 731 }; 732 733 struct scsi_rw_10 734 { 735 u_int8_t opcode; 736 #define SRW10_RELADDR 0x01 737 /* EBP defined for WRITE(10) only */ 738 #define SRW10_EBP 0x04 739 #define SRW10_FUA 0x08 740 #define SRW10_DPO 0x10 741 u_int8_t byte2; 742 u_int8_t addr[4]; 743 u_int8_t reserved; 744 u_int8_t length[2]; 745 u_int8_t control; 746 }; 747 748 struct scsi_rw_12 749 { 750 u_int8_t opcode; 751 #define SRW12_RELADDR 0x01 752 #define SRW12_FUA 0x08 753 #define SRW12_DPO 0x10 754 u_int8_t byte2; 755 u_int8_t addr[4]; 756 u_int8_t length[4]; 757 u_int8_t reserved; 758 u_int8_t control; 759 }; 760 761 struct scsi_rw_16 762 { 763 u_int8_t opcode; 764 #define SRW16_RELADDR 0x01 765 #define SRW16_FUA 0x08 766 #define SRW16_DPO 0x10 767 u_int8_t byte2; 768 u_int8_t addr[8]; 769 u_int8_t length[4]; 770 u_int8_t reserved; 771 u_int8_t control; 772 }; 773 774 struct scsi_write_verify_10 775 { 776 uint8_t opcode; 777 uint8_t byte2; 778 #define SWV_BYTCHK 0x02 779 #define SWV_DPO 0x10 780 #define SWV_WRPROECT_MASK 0xe0 781 uint8_t addr[4]; 782 uint8_t group; 783 uint8_t length[2]; 784 uint8_t control; 785 }; 786 787 struct scsi_write_verify_12 788 { 789 uint8_t opcode; 790 uint8_t byte2; 791 uint8_t addr[4]; 792 uint8_t length[4]; 793 uint8_t group; 794 uint8_t control; 795 }; 796 797 struct scsi_write_verify_16 798 { 799 uint8_t opcode; 800 uint8_t byte2; 801 uint8_t addr[8]; 802 uint8_t length[4]; 803 uint8_t group; 804 uint8_t control; 805 }; 806 807 808 struct scsi_start_stop_unit 809 { 810 u_int8_t opcode; 811 u_int8_t byte2; 812 #define SSS_IMMED 0x01 813 u_int8_t reserved[2]; 814 u_int8_t how; 815 #define SSS_START 0x01 816 #define SSS_LOEJ 0x02 817 #define SSS_PC_MASK 0xf0 818 #define SSS_PC_START_VALID 0x00 819 #define SSS_PC_ACTIVE 0x10 820 #define SSS_PC_IDLE 0x20 821 #define SSS_PC_STANDBY 0x30 822 #define SSS_PC_LU_CONTROL 0x70 823 #define SSS_PC_FORCE_IDLE_0 0xa0 824 #define SSS_PC_FORCE_STANDBY_0 0xb0 825 u_int8_t control; 826 }; 827 828 struct ata_pass_12 { 829 u_int8_t opcode; 830 u_int8_t protocol; 831 #define AP_MULTI 0xe0 832 u_int8_t flags; 833 #define AP_T_LEN 0x03 834 #define AP_BB 0x04 835 #define AP_T_DIR 0x08 836 #define AP_CK_COND 0x20 837 #define AP_OFFLINE 0x60 838 u_int8_t features; 839 u_int8_t sector_count; 840 u_int8_t lba_low; 841 u_int8_t lba_mid; 842 u_int8_t lba_high; 843 u_int8_t device; 844 u_int8_t command; 845 u_int8_t reserved; 846 u_int8_t control; 847 }; 848 849 struct scsi_maintenance_in 850 { 851 uint8_t opcode; 852 uint8_t byte2; 853 #define SERVICE_ACTION_MASK 0x1f 854 #define SA_RPRT_TRGT_GRP 0x0a 855 uint8_t reserved[4]; 856 uint8_t length[4]; 857 uint8_t reserved1; 858 uint8_t control; 859 }; 860 861 struct ata_pass_16 { 862 u_int8_t opcode; 863 u_int8_t protocol; 864 #define AP_EXTEND 0x01 865 u_int8_t flags; 866 u_int8_t features_ext; 867 u_int8_t features; 868 u_int8_t sector_count_ext; 869 u_int8_t sector_count; 870 u_int8_t lba_low_ext; 871 u_int8_t lba_low; 872 u_int8_t lba_mid_ext; 873 u_int8_t lba_mid; 874 u_int8_t lba_high_ext; 875 u_int8_t lba_high; 876 u_int8_t device; 877 u_int8_t command; 878 u_int8_t control; 879 }; 880 881 #define SC_SCSI_1 0x01 882 #define SC_SCSI_2 0x03 883 884 /* 885 * Opcodes 886 */ 887 888 #define TEST_UNIT_READY 0x00 889 #define REQUEST_SENSE 0x03 890 #define READ_6 0x08 891 #define WRITE_6 0x0A 892 #define INQUIRY 0x12 893 #define MODE_SELECT_6 0x15 894 #define MODE_SENSE_6 0x1A 895 #define START_STOP_UNIT 0x1B 896 #define START_STOP 0x1B 897 #define RESERVE 0x16 898 #define RELEASE 0x17 899 #define RECEIVE_DIAGNOSTIC 0x1C 900 #define SEND_DIAGNOSTIC 0x1D 901 #define PREVENT_ALLOW 0x1E 902 #define READ_CAPACITY 0x25 903 #define READ_10 0x28 904 #define WRITE_10 0x2A 905 #define POSITION_TO_ELEMENT 0x2B 906 #define WRITE_VERIFY_10 0x2E 907 #define SYNCHRONIZE_CACHE 0x35 908 #define READ_DEFECT_DATA_10 0x37 909 #define WRITE_BUFFER 0x3B 910 #define READ_BUFFER 0x3C 911 #define CHANGE_DEFINITION 0x40 912 #define LOG_SELECT 0x4C 913 #define LOG_SENSE 0x4D 914 #define MODE_SELECT_10 0x55 915 #define RESERVE_10 0x56 916 #define RELEASE_10 0x57 917 #define MODE_SENSE_10 0x5A 918 #define PERSISTENT_RES_IN 0x5E 919 #define PERSISTENT_RES_OUT 0x5F 920 #define ATA_PASS_16 0x85 921 #define READ_16 0x88 922 #define WRITE_16 0x8A 923 #define WRITE_VERIFY_16 0x8E 924 #define SYNCHRONIZE_CACHE_16 0x91 925 #define SERVICE_ACTION_IN 0x9E 926 #define REPORT_LUNS 0xA0 927 #define ATA_PASS_12 0xA1 928 #define MAINTENANCE_IN 0xA3 929 #define MAINTENANCE_OUT 0xA4 930 #define MOVE_MEDIUM 0xA5 931 #define READ_12 0xA8 932 #define WRITE_12 0xAA 933 #define WRITE_VERIFY_12 0xAE 934 #define READ_ELEMENT_STATUS 0xB8 935 #define READ_CD 0xBE 936 937 /* Maintenance In Service Action Codes */ 938 #define REPORT_IDENTIFYING_INFRMATION 0x05 939 #define REPORT_TARGET_PORT_GROUPS 0x0A 940 #define REPORT_ALIASES 0x0B 941 #define REPORT_SUPPORTED_OPERATION_CODES 0x0C 942 #define REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0D 943 #define REPORT_PRIORITY 0x0E 944 #define REPORT_TIMESTAMP 0x0F 945 #define MANAGEMENT_PROTOCOL_IN 0x10 946 /* Maintenance Out Service Action Codes */ 947 #define SET_IDENTIFY_INFORMATION 0x06 948 #define SET_TARGET_PORT_GROUPS 0x0A 949 #define CHANGE_ALIASES 0x0B 950 #define SET_PRIORITY 0x0E 951 #define SET_TIMESTAMP 0x0F 952 #define MANGAEMENT_PROTOCOL_OUT 0x10 953 954 /* 955 * Device Types 956 */ 957 #define T_DIRECT 0x00 958 #define T_SEQUENTIAL 0x01 959 #define T_PRINTER 0x02 960 #define T_PROCESSOR 0x03 961 #define T_WORM 0x04 962 #define T_CDROM 0x05 963 #define T_SCANNER 0x06 964 #define T_OPTICAL 0x07 965 #define T_CHANGER 0x08 966 #define T_COMM 0x09 967 #define T_ASC0 0x0a 968 #define T_ASC1 0x0b 969 #define T_STORARRAY 0x0c 970 #define T_ENCLOSURE 0x0d 971 #define T_RBC 0x0e 972 #define T_OCRW 0x0f 973 #define T_OSD 0x11 974 #define T_ADC 0x12 975 #define T_NODEVICE 0x1f 976 #define T_ANY 0xff /* Used in Quirk table matches */ 977 978 #define T_REMOV 1 979 #define T_FIXED 0 980 981 /* 982 * This length is the initial inquiry length used by the probe code, as 983 * well as the legnth necessary for scsi_print_inquiry() to function 984 * correctly. If either use requires a different length in the future, 985 * the two values should be de-coupled. 986 */ 987 #define SHORT_INQUIRY_LENGTH 36 988 989 struct scsi_inquiry_data 990 { 991 u_int8_t device; 992 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f) 993 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5) 994 #define SID_QUAL_LU_CONNECTED 0x00 /* 995 * The specified peripheral device 996 * type is currently connected to 997 * logical unit. If the target cannot 998 * determine whether or not a physical 999 * device is currently connected, it 1000 * shall also use this peripheral 1001 * qualifier when returning the INQUIRY 1002 * data. This peripheral qualifier 1003 * does not mean that the device is 1004 * ready for access by the initiator. 1005 */ 1006 #define SID_QUAL_LU_OFFLINE 0x01 /* 1007 * The target is capable of supporting 1008 * the specified peripheral device type 1009 * on this logical unit; however, the 1010 * physical device is not currently 1011 * connected to this logical unit. 1012 */ 1013 #define SID_QUAL_RSVD 0x02 1014 #define SID_QUAL_BAD_LU 0x03 /* 1015 * The target is not capable of 1016 * supporting a physical device on 1017 * this logical unit. For this 1018 * peripheral qualifier the peripheral 1019 * device type shall be set to 1Fh to 1020 * provide compatibility with previous 1021 * versions of SCSI. All other 1022 * peripheral device type values are 1023 * reserved for this peripheral 1024 * qualifier. 1025 */ 1026 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0) 1027 u_int8_t dev_qual2; 1028 #define SID_QUAL2 0x7F 1029 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0) 1030 u_int8_t version; 1031 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07) 1032 #define SCSI_REV_0 0 1033 #define SCSI_REV_CCS 1 1034 #define SCSI_REV_2 2 1035 #define SCSI_REV_SPC 3 1036 #define SCSI_REV_SPC2 4 1037 #define SCSI_REV_SPC3 5 1038 #define SCSI_REV_SPC4 6 1039 1040 #define SID_ECMA 0x38 1041 #define SID_ISO 0xC0 1042 u_int8_t response_format; 1043 #define SID_AENC 0x80 1044 #define SID_TrmIOP 0x40 1045 #define SID_NormACA 0x20 1046 #define SID_HiSup 0x10 1047 u_int8_t additional_length; 1048 #define SID_ADDITIONAL_LENGTH(iqd) \ 1049 ((iqd)->additional_length + \ 1050 __offsetof(struct scsi_inquiry_data, additional_length) + 1) 1051 u_int8_t spc3_flags; 1052 #define SPC3_SID_PROTECT 0x01 1053 #define SPC3_SID_3PC 0x08 1054 #define SPC3_SID_TPGS_MASK 0x30 1055 #define SPC3_SID_TPGS_IMPLICIT 0x10 1056 #define SPC3_SID_TPGS_EXPLICIT 0x20 1057 #define SPC3_SID_ACC 0x40 1058 #define SPC3_SID_SCCS 0x80 1059 u_int8_t spc2_flags; 1060 #define SPC2_SID_ADDR16 0x01 1061 #define SPC2_SID_MChngr 0x08 1062 #define SPC2_SID_MultiP 0x10 1063 #define SPC2_SID_EncServ 0x40 1064 #define SPC2_SID_BQueue 0x80 1065 1066 #define INQ_DATA_TQ_ENABLED(iqd) \ 1067 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \ 1068 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \ 1069 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue))) 1070 1071 u_int8_t flags; 1072 #define SID_SftRe 0x01 1073 #define SID_CmdQue 0x02 1074 #define SID_Linked 0x08 1075 #define SID_Sync 0x10 1076 #define SID_WBus16 0x20 1077 #define SID_WBus32 0x40 1078 #define SID_RelAdr 0x80 1079 #define SID_VENDOR_SIZE 8 1080 char vendor[SID_VENDOR_SIZE]; 1081 #define SID_PRODUCT_SIZE 16 1082 char product[SID_PRODUCT_SIZE]; 1083 #define SID_REVISION_SIZE 4 1084 char revision[SID_REVISION_SIZE]; 1085 /* 1086 * The following fields were taken from SCSI Primary Commands - 2 1087 * (SPC-2) Revision 14, Dated 11 November 1999 1088 */ 1089 #define SID_VENDOR_SPECIFIC_0_SIZE 20 1090 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE]; 1091 /* 1092 * An extension of SCSI Parallel Specific Values 1093 */ 1094 #define SID_SPI_IUS 0x01 1095 #define SID_SPI_QAS 0x02 1096 #define SID_SPI_CLOCK_ST 0x00 1097 #define SID_SPI_CLOCK_DT 0x04 1098 #define SID_SPI_CLOCK_DT_ST 0x0C 1099 #define SID_SPI_MASK 0x0F 1100 u_int8_t spi3data; 1101 u_int8_t reserved2; 1102 /* 1103 * Version Descriptors, stored 2 byte values. 1104 */ 1105 u_int8_t version1[2]; 1106 u_int8_t version2[2]; 1107 u_int8_t version3[2]; 1108 u_int8_t version4[2]; 1109 u_int8_t version5[2]; 1110 u_int8_t version6[2]; 1111 u_int8_t version7[2]; 1112 u_int8_t version8[2]; 1113 1114 u_int8_t reserved3[22]; 1115 1116 #define SID_VENDOR_SPECIFIC_1_SIZE 160 1117 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE]; 1118 }; 1119 1120 /* 1121 * This structure is more suited to initiator operation, because the 1122 * maximum number of supported pages is already allocated. 1123 */ 1124 struct scsi_vpd_supported_page_list 1125 { 1126 u_int8_t device; 1127 u_int8_t page_code; 1128 #define SVPD_SUPPORTED_PAGE_LIST 0x00 1129 #define SVPD_SUPPORTED_PAGES_HDR_LEN 4 1130 u_int8_t reserved; 1131 u_int8_t length; /* number of VPD entries */ 1132 #define SVPD_SUPPORTED_PAGES_SIZE 251 1133 u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE]; 1134 }; 1135 1136 /* 1137 * This structure is more suited to target operation, because the 1138 * number of supported pages is left to the user to allocate. 1139 */ 1140 struct scsi_vpd_supported_pages 1141 { 1142 u_int8_t device; 1143 u_int8_t page_code; 1144 u_int8_t reserved; 1145 #define SVPD_SUPPORTED_PAGES 0x00 1146 u_int8_t length; 1147 u_int8_t page_list[0]; 1148 }; 1149 1150 1151 struct scsi_vpd_unit_serial_number 1152 { 1153 u_int8_t device; 1154 u_int8_t page_code; 1155 #define SVPD_UNIT_SERIAL_NUMBER 0x80 1156 u_int8_t reserved; 1157 u_int8_t length; /* serial number length */ 1158 #define SVPD_SERIAL_NUM_SIZE 251 1159 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE]; 1160 }; 1161 1162 struct scsi_vpd_device_id 1163 { 1164 u_int8_t device; 1165 u_int8_t page_code; 1166 #define SVPD_DEVICE_ID 0x83 1167 #define SVPD_DEVICE_ID_MAX_SIZE 252 1168 #define SVPD_DEVICE_ID_HDR_LEN \ 1169 __offsetof(struct scsi_vpd_device_id, desc_list) 1170 u_int8_t length[2]; 1171 u_int8_t desc_list[]; 1172 }; 1173 1174 struct scsi_vpd_id_descriptor 1175 { 1176 u_int8_t proto_codeset; 1177 #define SCSI_PROTO_FC 0x00 1178 #define SCSI_PROTO_SPI 0x01 1179 #define SCSI_PROTO_SSA 0x02 1180 #define SCSI_PROTO_1394 0x03 1181 #define SCSI_PROTO_RDMA 0x04 1182 #define SCSI_PROTO_iSCSI 0x05 1183 #define SCSI_PROTO_SAS 0x06 1184 #define SVPD_ID_PROTO_SHIFT 4 1185 #define SVPD_ID_CODESET_BINARY 0x01 1186 #define SVPD_ID_CODESET_ASCII 0x02 1187 #define SVPD_ID_CODESET_MASK 0x0f 1188 u_int8_t id_type; 1189 #define SVPD_ID_PIV 0x80 1190 #define SVPD_ID_ASSOC_LUN 0x00 1191 #define SVPD_ID_ASSOC_PORT 0x10 1192 #define SVPD_ID_ASSOC_TARGET 0x20 1193 #define SVPD_ID_ASSOC_MASK 0x30 1194 #define SVPD_ID_TYPE_VENDOR 0x00 1195 #define SVPD_ID_TYPE_T10 0x01 1196 #define SVPD_ID_TYPE_EUI64 0x02 1197 #define SVPD_ID_TYPE_NAA 0x03 1198 #define SVPD_ID_TYPE_RELTARG 0x04 1199 #define SVPD_ID_TYPE_TPORTGRP 0x05 1200 #define SVPD_ID_TYPE_LUNGRP 0x06 1201 #define SVPD_ID_TYPE_MD5_LUN_ID 0x07 1202 #define SVPD_ID_TYPE_SCSI_NAME 0x08 1203 #define SVPD_ID_TYPE_MASK 0x0f 1204 u_int8_t reserved; 1205 u_int8_t length; 1206 #define SVPD_DEVICE_ID_DESC_HDR_LEN \ 1207 __offsetof(struct scsi_vpd_id_descriptor, identifier) 1208 u_int8_t identifier[]; 1209 }; 1210 1211 struct scsi_vpd_id_t10 1212 { 1213 u_int8_t vendor[8]; 1214 u_int8_t vendor_spec_id[0]; 1215 }; 1216 1217 struct scsi_vpd_id_eui64 1218 { 1219 u_int8_t ieee_company_id[3]; 1220 u_int8_t extension_id[5]; 1221 }; 1222 1223 struct scsi_vpd_id_naa_basic 1224 { 1225 uint8_t naa; 1226 /* big endian, packed: 1227 uint8_t naa : 4; 1228 uint8_t naa_desig : 4; 1229 */ 1230 #define SVPD_ID_NAA_NAA_SHIFT 4 1231 #define SVPD_ID_NAA_IEEE_EXT 0x02 1232 #define SVPD_ID_NAA_LOCAL_REG 0x03 1233 #define SVPD_ID_NAA_IEEE_REG 0x05 1234 #define SVPD_ID_NAA_IEEE_REG_EXT 0x06 1235 uint8_t naa_data[]; 1236 }; 1237 1238 struct scsi_vpd_id_naa_ieee_extended_id 1239 { 1240 uint8_t naa; 1241 uint8_t vendor_specific_id_a; 1242 uint8_t ieee_company_id[3]; 1243 uint8_t vendor_specific_id_b[4]; 1244 }; 1245 1246 struct scsi_vpd_id_naa_local_reg 1247 { 1248 uint8_t naa; 1249 uint8_t local_value[7]; 1250 }; 1251 1252 struct scsi_vpd_id_naa_ieee_reg 1253 { 1254 uint8_t naa; 1255 uint8_t reg_value[7]; 1256 /* big endian, packed: 1257 uint8_t naa_basic : 4; 1258 uint8_t ieee_company_id_0 : 4; 1259 uint8_t ieee_company_id_1[2]; 1260 uint8_t ieee_company_id_2 : 4; 1261 uint8_t vendor_specific_id_0 : 4; 1262 uint8_t vendor_specific_id_1[4]; 1263 */ 1264 }; 1265 1266 struct scsi_vpd_id_naa_ieee_reg_extended 1267 { 1268 uint8_t naa; 1269 uint8_t reg_value[15]; 1270 /* big endian, packed: 1271 uint8_t naa_basic : 4; 1272 uint8_t ieee_company_id_0 : 4; 1273 uint8_t ieee_company_id_1[2]; 1274 uint8_t ieee_company_id_2 : 4; 1275 uint8_t vendor_specific_id_0 : 4; 1276 uint8_t vendor_specific_id_1[4]; 1277 uint8_t vendor_specific_id_ext[8]; 1278 */ 1279 }; 1280 1281 struct scsi_vpd_id_rel_trgt_port_id 1282 { 1283 uint8_t obsolete[2]; 1284 uint8_t rel_trgt_port_id[2]; 1285 }; 1286 1287 struct scsi_vpd_id_trgt_port_grp_id 1288 { 1289 uint8_t reserved[2]; 1290 uint8_t trgt_port_grp[2]; 1291 }; 1292 1293 struct scsi_vpd_id_lun_grp_id 1294 { 1295 uint8_t reserved[2]; 1296 uint8_t log_unit_grp[2]; 1297 }; 1298 1299 struct scsi_vpd_id_md5_lun_id 1300 { 1301 uint8_t lun_id[16]; 1302 }; 1303 1304 struct scsi_vpd_id_scsi_name 1305 { 1306 uint8_t name_string[256]; 1307 }; 1308 1309 struct scsi_service_action_in 1310 { 1311 uint8_t opcode; 1312 uint8_t service_action; 1313 uint8_t action_dependent[13]; 1314 uint8_t control; 1315 }; 1316 1317 struct scsi_read_capacity 1318 { 1319 u_int8_t opcode; 1320 u_int8_t byte2; 1321 #define SRC_RELADR 0x01 1322 u_int8_t addr[4]; 1323 u_int8_t unused[2]; 1324 u_int8_t pmi; 1325 #define SRC_PMI 0x01 1326 u_int8_t control; 1327 }; 1328 1329 struct scsi_read_capacity_16 1330 { 1331 uint8_t opcode; 1332 #define SRC16_SERVICE_ACTION 0x10 1333 uint8_t service_action; 1334 uint8_t addr[8]; 1335 uint8_t alloc_len[4]; 1336 #define SRC16_PMI 0x01 1337 #define SRC16_RELADR 0x02 1338 uint8_t reladr; 1339 uint8_t control; 1340 }; 1341 1342 struct scsi_read_capacity_data 1343 { 1344 u_int8_t addr[4]; 1345 u_int8_t length[4]; 1346 }; 1347 1348 struct scsi_read_capacity_data_long 1349 { 1350 uint8_t addr[8]; 1351 uint8_t length[4]; 1352 }; 1353 1354 struct scsi_report_luns 1355 { 1356 uint8_t opcode; 1357 uint8_t reserved1; 1358 #define RPL_REPORT_DEFAULT 0x00 1359 #define RPL_REPORT_WELLKNOWN 0x01 1360 #define RPL_REPORT_ALL 0x02 1361 uint8_t select_report; 1362 uint8_t reserved2[3]; 1363 uint8_t length[4]; 1364 uint8_t reserved3; 1365 uint8_t control; 1366 }; 1367 1368 struct scsi_report_luns_lundata { 1369 uint8_t lundata[8]; 1370 #define RPL_LUNDATA_PERIPH_BUS_MASK 0x3f 1371 #define RPL_LUNDATA_FLAT_LUN_MASK 0x3f 1372 #define RPL_LUNDATA_FLAT_LUN_BITS 0x06 1373 #define RPL_LUNDATA_LUN_TARG_MASK 0x3f 1374 #define RPL_LUNDATA_LUN_BUS_MASK 0xe0 1375 #define RPL_LUNDATA_LUN_LUN_MASK 0x1f 1376 #define RPL_LUNDATA_EXT_LEN_MASK 0x30 1377 #define RPL_LUNDATA_EXT_EAM_MASK 0x0f 1378 #define RPL_LUNDATA_EXT_EAM_WK 0x01 1379 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC 0x0f 1380 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */ 1381 #define RPL_LUNDATA_ATYP_PERIPH 0x00 1382 #define RPL_LUNDATA_ATYP_FLAT 0x40 1383 #define RPL_LUNDATA_ATYP_LUN 0x80 1384 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0 1385 }; 1386 1387 struct scsi_report_luns_data { 1388 u_int8_t length[4]; /* length of LUN inventory, in bytes */ 1389 u_int8_t reserved[4]; /* unused */ 1390 /* 1391 * LUN inventory- we only support the type zero form for now. 1392 */ 1393 struct scsi_report_luns_lundata luns[0]; 1394 }; 1395 1396 struct scsi_target_group 1397 { 1398 uint8_t opcode; 1399 uint8_t service_action; 1400 #define STG_PDF_LENGTH 0x00 1401 #define RPL_PDF_EXTENDED 0x20 1402 uint8_t reserved1[4]; 1403 uint8_t length[4]; 1404 uint8_t reserved2; 1405 uint8_t control; 1406 }; 1407 1408 struct scsi_target_port_descriptor { 1409 uint8_t reserved[2]; 1410 uint8_t relative_target_port_identifier[2]; 1411 uint8_t desc_list[]; 1412 }; 1413 1414 struct scsi_target_port_group_descriptor { 1415 uint8_t pref_state; 1416 #define TPG_PRIMARY 0x80 1417 #define TPG_ASYMMETRIC_ACCESS_STATE_MASK 0xf 1418 #define TPG_ASYMMETRIC_ACCESS_OPTIMIZED 0x0 1419 #define TPG_ASYMMETRIC_ACCESS_NONOPTIMIZED 0x1 1420 #define TPG_ASYMMETRIC_ACCESS_STANDBY 0x2 1421 #define TPG_ASYMMETRIC_ACCESS_UNAVAILABLE 0x3 1422 #define TPG_ASYMMETRIC_ACCESS_LBA_DEPENDENT 0x4 1423 #define TPG_ASYMMETRIC_ACCESS_OFFLINE 0xE 1424 #define TPG_ASYMMETRIC_ACCESS_TRANSITIONING 0xF 1425 uint8_t support; 1426 #define TPG_AO_SUP 0x01 1427 #define TPG_AN_SUP 0x02 1428 #define TPG_S_SUP 0x04 1429 #define TPG_U_SUP 0x08 1430 #define TPG_LBD_SUP 0x10 1431 #define TPG_O_SUP 0x40 1432 #define TPG_T_SUP 0x80 1433 uint8_t target_port_group[2]; 1434 uint8_t reserved; 1435 uint8_t status; 1436 #define TPG_UNAVLBL 0 1437 #define TPG_SET_BY_STPG 0x01 1438 #define TPG_IMPLICIT 0x02 1439 uint8_t vendor_specific; 1440 uint8_t target_port_count; 1441 struct scsi_target_port_descriptor descriptors[]; 1442 }; 1443 1444 struct scsi_target_group_data { 1445 uint8_t length[4]; /* length of returned data, in bytes */ 1446 struct scsi_target_port_group_descriptor groups[]; 1447 }; 1448 1449 struct scsi_target_group_data_extended { 1450 uint8_t length[4]; /* length of returned data, in bytes */ 1451 uint8_t format_type; /* STG_PDF_LENGTH or RPL_PDF_EXTENDED */ 1452 uint8_t implicit_transition_time; 1453 uint8_t reserved[2]; 1454 struct scsi_target_port_group_descriptor groups[]; 1455 }; 1456 1457 1458 typedef enum { 1459 SSD_TYPE_NONE, 1460 SSD_TYPE_FIXED, 1461 SSD_TYPE_DESC 1462 } scsi_sense_data_type; 1463 1464 typedef enum { 1465 SSD_ELEM_NONE, 1466 SSD_ELEM_SKIP, 1467 SSD_ELEM_DESC, 1468 SSD_ELEM_SKS, 1469 SSD_ELEM_COMMAND, 1470 SSD_ELEM_INFO, 1471 SSD_ELEM_FRU, 1472 SSD_ELEM_STREAM, 1473 SSD_ELEM_MAX 1474 } scsi_sense_elem_type; 1475 1476 1477 struct scsi_sense_data 1478 { 1479 uint8_t error_code; 1480 /* 1481 * SPC-4 says that the maximum length of sense data is 252 bytes. 1482 * So this structure is exactly 252 bytes log. 1483 */ 1484 #define SSD_FULL_SIZE 252 1485 uint8_t sense_buf[SSD_FULL_SIZE - 1]; 1486 /* 1487 * XXX KDM is this still a reasonable minimum size? 1488 */ 1489 #define SSD_MIN_SIZE 18 1490 /* 1491 * Maximum value for the extra_len field in the sense data. 1492 */ 1493 #define SSD_EXTRA_MAX 244 1494 }; 1495 1496 /* 1497 * Fixed format sense data. 1498 */ 1499 struct scsi_sense_data_fixed 1500 { 1501 u_int8_t error_code; 1502 #define SSD_ERRCODE 0x7F 1503 #define SSD_CURRENT_ERROR 0x70 1504 #define SSD_DEFERRED_ERROR 0x71 1505 #define SSD_ERRCODE_VALID 0x80 1506 u_int8_t segment; 1507 u_int8_t flags; 1508 #define SSD_KEY 0x0F 1509 #define SSD_KEY_NO_SENSE 0x00 1510 #define SSD_KEY_RECOVERED_ERROR 0x01 1511 #define SSD_KEY_NOT_READY 0x02 1512 #define SSD_KEY_MEDIUM_ERROR 0x03 1513 #define SSD_KEY_HARDWARE_ERROR 0x04 1514 #define SSD_KEY_ILLEGAL_REQUEST 0x05 1515 #define SSD_KEY_UNIT_ATTENTION 0x06 1516 #define SSD_KEY_DATA_PROTECT 0x07 1517 #define SSD_KEY_BLANK_CHECK 0x08 1518 #define SSD_KEY_Vendor_Specific 0x09 1519 #define SSD_KEY_COPY_ABORTED 0x0a 1520 #define SSD_KEY_ABORTED_COMMAND 0x0b 1521 #define SSD_KEY_EQUAL 0x0c 1522 #define SSD_KEY_VOLUME_OVERFLOW 0x0d 1523 #define SSD_KEY_MISCOMPARE 0x0e 1524 #define SSD_KEY_COMPLETED 0x0f 1525 #define SSD_ILI 0x20 1526 #define SSD_EOM 0x40 1527 #define SSD_FILEMARK 0x80 1528 u_int8_t info[4]; 1529 u_int8_t extra_len; 1530 u_int8_t cmd_spec_info[4]; 1531 u_int8_t add_sense_code; 1532 u_int8_t add_sense_code_qual; 1533 u_int8_t fru; 1534 u_int8_t sense_key_spec[3]; 1535 #define SSD_SCS_VALID 0x80 1536 #define SSD_FIELDPTR_CMD 0x40 1537 #define SSD_BITPTR_VALID 0x08 1538 #define SSD_BITPTR_VALUE 0x07 1539 u_int8_t extra_bytes[14]; 1540 #define SSD_FIXED_IS_PRESENT(sense, length, field) \ 1541 ((length >= (offsetof(struct scsi_sense_data_fixed, field) + \ 1542 sizeof(sense->field))) ? 1 :0) 1543 #define SSD_FIXED_IS_FILLED(sense, field) \ 1544 ((((offsetof(struct scsi_sense_data_fixed, field) + \ 1545 sizeof(sense->field)) - \ 1546 (offsetof(struct scsi_sense_data_fixed, extra_len) + \ 1547 sizeof(sense->extra_len))) <= sense->extra_len) ? 1 : 0) 1548 }; 1549 1550 /* 1551 * Descriptor format sense data definitions. 1552 * Introduced in SPC-3. 1553 */ 1554 struct scsi_sense_data_desc 1555 { 1556 uint8_t error_code; 1557 #define SSD_DESC_CURRENT_ERROR 0x72 1558 #define SSD_DESC_DEFERRED_ERROR 0x73 1559 uint8_t sense_key; 1560 uint8_t add_sense_code; 1561 uint8_t add_sense_code_qual; 1562 uint8_t reserved[3]; 1563 /* 1564 * Note that SPC-4, section 4.5.2.1 says that the extra_len field 1565 * must be less than or equal to 244. 1566 */ 1567 uint8_t extra_len; 1568 uint8_t sense_desc[0]; 1569 #define SSD_DESC_IS_PRESENT(sense, length, field) \ 1570 ((length >= (offsetof(struct scsi_sense_data_desc, field) + \ 1571 sizeof(sense->field))) ? 1 :0) 1572 }; 1573 1574 struct scsi_sense_desc_header 1575 { 1576 uint8_t desc_type; 1577 uint8_t length; 1578 }; 1579 /* 1580 * The information provide in the Information descriptor is device type or 1581 * command specific information, and defined in a command standard. 1582 * 1583 * Note that any changes to the field names or positions in this structure, 1584 * even reserved fields, should be accompanied by an examination of the 1585 * code in ctl_set_sense() that uses them. 1586 * 1587 * Maximum descriptors allowed: 1 (as of SPC-4) 1588 */ 1589 struct scsi_sense_info 1590 { 1591 uint8_t desc_type; 1592 #define SSD_DESC_INFO 0x00 1593 uint8_t length; 1594 uint8_t byte2; 1595 #define SSD_INFO_VALID 0x80 1596 uint8_t reserved; 1597 uint8_t info[8]; 1598 }; 1599 1600 /* 1601 * Command-specific information depends on the command for which the 1602 * reported condition occured. 1603 * 1604 * Note that any changes to the field names or positions in this structure, 1605 * even reserved fields, should be accompanied by an examination of the 1606 * code in ctl_set_sense() that uses them. 1607 * 1608 * Maximum descriptors allowed: 1 (as of SPC-4) 1609 */ 1610 struct scsi_sense_command 1611 { 1612 uint8_t desc_type; 1613 #define SSD_DESC_COMMAND 0x01 1614 uint8_t length; 1615 uint8_t reserved[2]; 1616 uint8_t command_info[8]; 1617 }; 1618 1619 /* 1620 * Sense key specific descriptor. The sense key specific data format 1621 * depends on the sense key in question. 1622 * 1623 * Maximum descriptors allowed: 1 (as of SPC-4) 1624 */ 1625 struct scsi_sense_sks 1626 { 1627 uint8_t desc_type; 1628 #define SSD_DESC_SKS 0x02 1629 uint8_t length; 1630 uint8_t reserved1[2]; 1631 uint8_t sense_key_spec[3]; 1632 #define SSD_SKS_VALID 0x80 1633 uint8_t reserved2; 1634 }; 1635 1636 /* 1637 * This is used for the Illegal Request sense key (0x05) only. 1638 */ 1639 struct scsi_sense_sks_field 1640 { 1641 uint8_t byte0; 1642 #define SSD_SKS_FIELD_VALID 0x80 1643 #define SSD_SKS_FIELD_CMD 0x40 1644 #define SSD_SKS_BPV 0x08 1645 #define SSD_SKS_BIT_VALUE 0x07 1646 uint8_t field[2]; 1647 }; 1648 1649 1650 /* 1651 * This is used for the Hardware Error (0x04), Medium Error (0x03) and 1652 * Recovered Error (0x01) sense keys. 1653 */ 1654 struct scsi_sense_sks_retry 1655 { 1656 uint8_t byte0; 1657 #define SSD_SKS_RETRY_VALID 0x80 1658 uint8_t actual_retry_count[2]; 1659 }; 1660 1661 /* 1662 * Used with the NO Sense (0x00) or Not Ready (0x02) sense keys. 1663 */ 1664 struct scsi_sense_sks_progress 1665 { 1666 uint8_t byte0; 1667 #define SSD_SKS_PROGRESS_VALID 0x80 1668 uint8_t progress[2]; 1669 #define SSD_SKS_PROGRESS_DENOM 0x10000 1670 }; 1671 1672 /* 1673 * Used with the Copy Aborted (0x0a) sense key. 1674 */ 1675 struct scsi_sense_sks_segment 1676 { 1677 uint8_t byte0; 1678 #define SSD_SKS_SEGMENT_VALID 0x80 1679 #define SSD_SKS_SEGMENT_SD 0x20 1680 #define SSD_SKS_SEGMENT_BPV 0x08 1681 #define SSD_SKS_SEGMENT_BITPTR 0x07 1682 uint8_t field[2]; 1683 }; 1684 1685 /* 1686 * Used with the Unit Attention (0x06) sense key. 1687 * 1688 * This is currently used to indicate that the unit attention condition 1689 * queue has overflowed (when the overflow bit is set). 1690 */ 1691 struct scsi_sense_sks_overflow 1692 { 1693 uint8_t byte0; 1694 #define SSD_SKS_OVERFLOW_VALID 0x80 1695 #define SSD_SKS_OVERFLOW_SET 0x01 1696 uint8_t reserved[2]; 1697 }; 1698 1699 /* 1700 * This specifies which component is associated with the sense data. There 1701 * is no standard meaning for the fru value. 1702 * 1703 * Maximum descriptors allowed: 1 (as of SPC-4) 1704 */ 1705 struct scsi_sense_fru 1706 { 1707 uint8_t desc_type; 1708 #define SSD_DESC_FRU 0x03 1709 uint8_t length; 1710 uint8_t reserved; 1711 uint8_t fru; 1712 }; 1713 1714 /* 1715 * Used for Stream commands, defined in SSC-4. 1716 * 1717 * Maximum descriptors allowed: 1 (as of SPC-4) 1718 */ 1719 1720 struct scsi_sense_stream 1721 { 1722 uint8_t desc_type; 1723 #define SSD_DESC_STREAM 0x04 1724 uint8_t length; 1725 uint8_t reserved; 1726 uint8_t byte3; 1727 #define SSD_DESC_STREAM_FM 0x80 1728 #define SSD_DESC_STREAM_EOM 0x40 1729 #define SSD_DESC_STREAM_ILI 0x20 1730 }; 1731 1732 /* 1733 * Used for Block commands, defined in SBC-3. 1734 * 1735 * This is currently (as of SBC-3) only used for the Incorrect Length 1736 * Indication (ILI) bit, which says that the data length requested in the 1737 * READ LONG or WRITE LONG command did not match the length of the logical 1738 * block. 1739 * 1740 * Maximum descriptors allowed: 1 (as of SPC-4) 1741 */ 1742 struct scsi_sense_block 1743 { 1744 uint8_t desc_type; 1745 #define SSD_DESC_BLOCK 0x05 1746 uint8_t length; 1747 uint8_t reserved; 1748 uint8_t byte3; 1749 #define SSD_DESC_BLOCK_ILI 0x20 1750 }; 1751 1752 /* 1753 * Used for Object-Based Storage Devices (OSD-3). 1754 * 1755 * Maximum descriptors allowed: 1 (as of SPC-4) 1756 */ 1757 struct scsi_sense_osd_objid 1758 { 1759 uint8_t desc_type; 1760 #define SSD_DESC_OSD_OBJID 0x06 1761 uint8_t length; 1762 uint8_t reserved[6]; 1763 /* 1764 * XXX KDM provide the bit definitions here? There are a lot of 1765 * them, and we don't have an OSD driver yet. 1766 */ 1767 uint8_t not_init_cmds[4]; 1768 uint8_t completed_cmds[4]; 1769 uint8_t partition_id[8]; 1770 uint8_t object_id[8]; 1771 }; 1772 1773 /* 1774 * Used for Object-Based Storage Devices (OSD-3). 1775 * 1776 * Maximum descriptors allowed: 1 (as of SPC-4) 1777 */ 1778 struct scsi_sense_osd_integrity 1779 { 1780 uint8_t desc_type; 1781 #define SSD_DESC_OSD_INTEGRITY 0x07 1782 uint8_t length; 1783 uint8_t integ_check_val[32]; 1784 }; 1785 1786 /* 1787 * Used for Object-Based Storage Devices (OSD-3). 1788 * 1789 * Maximum descriptors allowed: 1 (as of SPC-4) 1790 */ 1791 struct scsi_sense_osd_attr_id 1792 { 1793 uint8_t desc_type; 1794 #define SSD_DESC_OSD_ATTR_ID 0x08 1795 uint8_t length; 1796 uint8_t reserved[2]; 1797 uint8_t attr_desc[0]; 1798 }; 1799 1800 /* 1801 * Used with Sense keys No Sense (0x00) and Not Ready (0x02). 1802 * 1803 * Maximum descriptors allowed: 32 (as of SPC-4) 1804 */ 1805 struct scsi_sense_progress 1806 { 1807 uint8_t desc_type; 1808 #define SSD_DESC_PROGRESS 0x0a 1809 uint8_t length; 1810 uint8_t sense_key; 1811 uint8_t add_sense_code; 1812 uint8_t add_sense_code_qual; 1813 uint8_t reserved; 1814 uint8_t progress[2]; 1815 }; 1816 1817 /* 1818 * This is typically forwarded as the result of an EXTENDED COPY command. 1819 * 1820 * Maximum descriptors allowed: 2 (as of SPC-4) 1821 */ 1822 struct scsi_sense_forwarded 1823 { 1824 uint8_t desc_type; 1825 #define SSD_DESC_FORWARDED 0x0c 1826 uint8_t length; 1827 uint8_t byte2; 1828 #define SSD_FORWARDED_FSDT 0x80 1829 #define SSD_FORWARDED_SDS_MASK 0x0f 1830 #define SSD_FORWARDED_SDS_UNK 0x00 1831 #define SSD_FORWARDED_SDS_EXSRC 0x01 1832 #define SSD_FORWARDED_SDS_EXDST 0x02 1833 }; 1834 1835 /* 1836 * Vendor-specific sense descriptor. The desc_type field will be in the 1837 * range bewteen MIN and MAX inclusive. 1838 */ 1839 struct scsi_sense_vendor 1840 { 1841 uint8_t desc_type; 1842 #define SSD_DESC_VENDOR_MIN 0x80 1843 #define SSD_DESC_VENDOR_MAX 0xff 1844 uint8_t length; 1845 uint8_t data[0]; 1846 }; 1847 1848 struct scsi_mode_header_6 1849 { 1850 u_int8_t data_length; /* Sense data length */ 1851 u_int8_t medium_type; 1852 u_int8_t dev_spec; 1853 u_int8_t blk_desc_len; 1854 }; 1855 1856 struct scsi_mode_header_10 1857 { 1858 u_int8_t data_length[2];/* Sense data length */ 1859 u_int8_t medium_type; 1860 u_int8_t dev_spec; 1861 u_int8_t unused[2]; 1862 u_int8_t blk_desc_len[2]; 1863 }; 1864 1865 struct scsi_mode_page_header 1866 { 1867 u_int8_t page_code; 1868 #define SMPH_PS 0x80 1869 #define SMPH_SPF 0x40 1870 #define SMPH_PC_MASK 0x3f 1871 u_int8_t page_length; 1872 }; 1873 1874 struct scsi_mode_page_header_sp 1875 { 1876 uint8_t page_code; 1877 uint8_t subpage; 1878 uint8_t page_length[2]; 1879 }; 1880 1881 1882 struct scsi_mode_blk_desc 1883 { 1884 u_int8_t density; 1885 u_int8_t nblocks[3]; 1886 u_int8_t reserved; 1887 u_int8_t blklen[3]; 1888 }; 1889 1890 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */ 1891 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */ 1892 1893 1894 /* 1895 * Status Byte 1896 */ 1897 #define SCSI_STATUS_OK 0x00 1898 #define SCSI_STATUS_CHECK_COND 0x02 1899 #define SCSI_STATUS_COND_MET 0x04 1900 #define SCSI_STATUS_BUSY 0x08 1901 #define SCSI_STATUS_INTERMED 0x10 1902 #define SCSI_STATUS_INTERMED_COND_MET 0x14 1903 #define SCSI_STATUS_RESERV_CONFLICT 0x18 1904 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */ 1905 #define SCSI_STATUS_QUEUE_FULL 0x28 1906 #define SCSI_STATUS_ACA_ACTIVE 0x30 1907 #define SCSI_STATUS_TASK_ABORTED 0x40 1908 1909 struct scsi_inquiry_pattern { 1910 u_int8_t type; 1911 u_int8_t media_type; 1912 #define SIP_MEDIA_REMOVABLE 0x01 1913 #define SIP_MEDIA_FIXED 0x02 1914 const char *vendor; 1915 const char *product; 1916 const char *revision; 1917 }; 1918 1919 struct scsi_static_inquiry_pattern { 1920 u_int8_t type; 1921 u_int8_t media_type; 1922 char vendor[SID_VENDOR_SIZE+1]; 1923 char product[SID_PRODUCT_SIZE+1]; 1924 char revision[SID_REVISION_SIZE+1]; 1925 }; 1926 1927 struct scsi_sense_quirk_entry { 1928 struct scsi_inquiry_pattern inq_pat; 1929 int num_sense_keys; 1930 int num_ascs; 1931 struct sense_key_table_entry *sense_key_info; 1932 struct asc_table_entry *asc_info; 1933 }; 1934 1935 struct sense_key_table_entry { 1936 u_int8_t sense_key; 1937 u_int32_t action; 1938 const char *desc; 1939 }; 1940 1941 struct asc_table_entry { 1942 u_int8_t asc; 1943 u_int8_t ascq; 1944 u_int32_t action; 1945 const char *desc; 1946 }; 1947 1948 struct op_table_entry { 1949 u_int8_t opcode; 1950 u_int32_t opmask; 1951 const char *desc; 1952 }; 1953 1954 struct scsi_op_quirk_entry { 1955 struct scsi_inquiry_pattern inq_pat; 1956 int num_ops; 1957 struct op_table_entry *op_table; 1958 }; 1959 1960 typedef enum { 1961 SSS_FLAG_NONE = 0x00, 1962 SSS_FLAG_PRINT_COMMAND = 0x01 1963 } scsi_sense_string_flags; 1964 1965 struct ccb_scsiio; 1966 struct cam_periph; 1967 union ccb; 1968 #ifndef _KERNEL 1969 struct cam_device; 1970 #endif 1971 1972 extern const char *scsi_sense_key_text[]; 1973 1974 struct sbuf; 1975 1976 __BEGIN_DECLS 1977 void scsi_sense_desc(int sense_key, int asc, int ascq, 1978 struct scsi_inquiry_data *inq_data, 1979 const char **sense_key_desc, const char **asc_desc); 1980 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio, 1981 struct scsi_inquiry_data *inq_data, 1982 u_int32_t sense_flags); 1983 const char * scsi_status_string(struct ccb_scsiio *csio); 1984 1985 void scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len, 1986 int (*iter_func)(struct scsi_sense_data_desc *sense, 1987 u_int, struct scsi_sense_desc_header *, 1988 void *), void *arg); 1989 uint8_t *scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len, 1990 uint8_t desc_type); 1991 void scsi_set_sense_data(struct scsi_sense_data *sense_data, 1992 scsi_sense_data_type sense_format, int current_error, 1993 int sense_key, int asc, int ascq, ...) ; 1994 void scsi_set_sense_data_va(struct scsi_sense_data *sense_data, 1995 scsi_sense_data_type sense_format, 1996 int current_error, int sense_key, int asc, 1997 int ascq, va_list ap); 1998 int scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len, 1999 uint8_t info_type, uint64_t *info, 2000 int64_t *signed_info); 2001 int scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len, 2002 uint8_t *sks); 2003 int scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len, 2004 struct scsi_inquiry_data *inq_data, 2005 uint8_t *block_bits); 2006 int scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len, 2007 struct scsi_inquiry_data *inq_data, 2008 uint8_t *stream_bits); 2009 void scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 2010 struct scsi_inquiry_data *inq_data, uint64_t info); 2011 void scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len, 2012 struct scsi_inquiry_data *inq_data, uint64_t csi); 2013 void scsi_progress_sbuf(struct sbuf *sb, uint16_t progress); 2014 int scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks); 2015 void scsi_fru_sbuf(struct sbuf *sb, uint64_t fru); 2016 void scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info); 2017 void scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info); 2018 void scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 2019 u_int sense_len, uint8_t *cdb, int cdb_len, 2020 struct scsi_inquiry_data *inq_data, 2021 struct scsi_sense_desc_header *header); 2022 2023 void scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 2024 u_int sense_len, uint8_t *cdb, int cdb_len, 2025 struct scsi_inquiry_data *inq_data, 2026 struct scsi_sense_desc_header *header); 2027 void scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 2028 u_int sense_len, uint8_t *cdb, int cdb_len, 2029 struct scsi_inquiry_data *inq_data, 2030 struct scsi_sense_desc_header *header); 2031 void scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 2032 u_int sense_len, uint8_t *cdb, int cdb_len, 2033 struct scsi_inquiry_data *inq_data, 2034 struct scsi_sense_desc_header *header); 2035 void scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 2036 u_int sense_len, uint8_t *cdb, int cdb_len, 2037 struct scsi_inquiry_data *inq_data, 2038 struct scsi_sense_desc_header *header); 2039 void scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 2040 u_int sense_len, uint8_t *cdb, int cdb_len, 2041 struct scsi_inquiry_data *inq_data, 2042 struct scsi_sense_desc_header *header); 2043 void scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 2044 u_int sense_len, uint8_t *cdb, int cdb_len, 2045 struct scsi_inquiry_data *inq_data, 2046 struct scsi_sense_desc_header *header); 2047 void scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 2048 u_int sense_len, uint8_t *cdb, int cdb_len, 2049 struct scsi_inquiry_data *inq_data, 2050 struct scsi_sense_desc_header *header); 2051 void scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, 2052 u_int sense_len, uint8_t *cdb, int cdb_len, 2053 struct scsi_inquiry_data *inq_data, 2054 struct scsi_sense_desc_header *header); 2055 scsi_sense_data_type scsi_sense_type(struct scsi_sense_data *sense_data); 2056 2057 void scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len, 2058 struct sbuf *sb, char *path_str, 2059 struct scsi_inquiry_data *inq_data, uint8_t *cdb, 2060 int cdb_len); 2061 2062 #ifdef _KERNEL 2063 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb); 2064 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb, 2065 scsi_sense_string_flags flags); 2066 char * scsi_sense_string(struct ccb_scsiio *csio, 2067 char *str, int str_len); 2068 void scsi_sense_print(struct ccb_scsiio *csio); 2069 int scsi_interpret_sense(union ccb *ccb, 2070 u_int32_t sense_flags, 2071 u_int32_t *relsim_flags, 2072 u_int32_t *reduction, 2073 u_int32_t *timeout, 2074 scsi_sense_action error_action); 2075 #else /* _KERNEL */ 2076 int scsi_command_string(struct cam_device *device, 2077 struct ccb_scsiio *csio, struct sbuf *sb); 2078 int scsi_sense_sbuf(struct cam_device *device, 2079 struct ccb_scsiio *csio, struct sbuf *sb, 2080 scsi_sense_string_flags flags); 2081 char * scsi_sense_string(struct cam_device *device, 2082 struct ccb_scsiio *csio, 2083 char *str, int str_len); 2084 void scsi_sense_print(struct cam_device *device, 2085 struct ccb_scsiio *csio, FILE *ofile); 2086 int scsi_interpret_sense(struct cam_device *device, 2087 union ccb *ccb, 2088 u_int32_t sense_flags, 2089 u_int32_t *relsim_flags, 2090 u_int32_t *reduction, 2091 u_int32_t *timeout, 2092 scsi_sense_action error_action); 2093 #endif /* _KERNEL */ 2094 2095 #define SF_RETRY_UA 0x01 2096 #define SF_NO_PRINT 0x02 2097 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */ 2098 #define SF_PRINT_ALWAYS 0x08 2099 2100 2101 const char * scsi_op_desc(u_int16_t opcode, 2102 struct scsi_inquiry_data *inq_data); 2103 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, 2104 size_t len); 2105 2106 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data); 2107 2108 u_int scsi_calc_syncsrate(u_int period_factor); 2109 u_int scsi_calc_syncparam(u_int period); 2110 2111 typedef int (*scsi_devid_checkfn_t)(uint8_t *); 2112 int scsi_devid_is_naa_ieee_reg(uint8_t *bufp); 2113 int scsi_devid_is_sas_target(uint8_t *bufp); 2114 uint8_t * scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t len, 2115 scsi_devid_checkfn_t ck_fn); 2116 2117 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, 2118 void (*cbfcnp)(struct cam_periph *, 2119 union ccb *), 2120 u_int8_t tag_action, 2121 u_int8_t sense_len, u_int32_t timeout); 2122 2123 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, 2124 void (*cbfcnp)(struct cam_periph *, 2125 union ccb *), 2126 void *data_ptr, u_int8_t dxfer_len, 2127 u_int8_t tag_action, u_int8_t sense_len, 2128 u_int32_t timeout); 2129 2130 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, 2131 void (*cbfcnp)(struct cam_periph *, union ccb *), 2132 u_int8_t tag_action, u_int8_t *inq_buf, 2133 u_int32_t inq_len, int evpd, u_int8_t page_code, 2134 u_int8_t sense_len, u_int32_t timeout); 2135 2136 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, 2137 void (*cbfcnp)(struct cam_periph *, 2138 union ccb *), 2139 u_int8_t tag_action, int dbd, 2140 u_int8_t page_code, u_int8_t page, 2141 u_int8_t *param_buf, u_int32_t param_len, 2142 u_int8_t sense_len, u_int32_t timeout); 2143 2144 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, 2145 void (*cbfcnp)(struct cam_periph *, 2146 union ccb *), 2147 u_int8_t tag_action, int dbd, 2148 u_int8_t page_code, u_int8_t page, 2149 u_int8_t *param_buf, u_int32_t param_len, 2150 int minimum_cmd_size, u_int8_t sense_len, 2151 u_int32_t timeout); 2152 2153 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, 2154 void (*cbfcnp)(struct cam_periph *, 2155 union ccb *), 2156 u_int8_t tag_action, int scsi_page_fmt, 2157 int save_pages, u_int8_t *param_buf, 2158 u_int32_t param_len, u_int8_t sense_len, 2159 u_int32_t timeout); 2160 2161 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries, 2162 void (*cbfcnp)(struct cam_periph *, 2163 union ccb *), 2164 u_int8_t tag_action, int scsi_page_fmt, 2165 int save_pages, u_int8_t *param_buf, 2166 u_int32_t param_len, int minimum_cmd_size, 2167 u_int8_t sense_len, u_int32_t timeout); 2168 2169 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries, 2170 void (*cbfcnp)(struct cam_periph *, union ccb *), 2171 u_int8_t tag_action, u_int8_t page_code, 2172 u_int8_t page, int save_pages, int ppc, 2173 u_int32_t paramptr, u_int8_t *param_buf, 2174 u_int32_t param_len, u_int8_t sense_len, 2175 u_int32_t timeout); 2176 2177 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries, 2178 void (*cbfcnp)(struct cam_periph *, 2179 union ccb *), u_int8_t tag_action, 2180 u_int8_t page_code, int save_pages, 2181 int pc_reset, u_int8_t *param_buf, 2182 u_int32_t param_len, u_int8_t sense_len, 2183 u_int32_t timeout); 2184 2185 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, 2186 void (*cbfcnp)(struct cam_periph *, union ccb *), 2187 u_int8_t tag_action, u_int8_t action, 2188 u_int8_t sense_len, u_int32_t timeout); 2189 2190 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, 2191 void (*cbfcnp)(struct cam_periph *, 2192 union ccb *), u_int8_t tag_action, 2193 struct scsi_read_capacity_data *, 2194 u_int8_t sense_len, u_int32_t timeout); 2195 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries, 2196 void (*cbfcnp)(struct cam_periph *, 2197 union ccb *), uint8_t tag_action, 2198 uint64_t lba, int reladr, int pmi, 2199 struct scsi_read_capacity_data_long 2200 *rcap_buf, uint8_t sense_len, 2201 uint32_t timeout); 2202 2203 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries, 2204 void (*cbfcnp)(struct cam_periph *, 2205 union ccb *), u_int8_t tag_action, 2206 u_int8_t select_report, 2207 struct scsi_report_luns_data *rpl_buf, 2208 u_int32_t alloc_len, u_int8_t sense_len, 2209 u_int32_t timeout); 2210 2211 void scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries, 2212 void (*cbfcnp)(struct cam_periph *, 2213 union ccb *), u_int8_t tag_action, 2214 u_int8_t pdf, 2215 void *buf, 2216 u_int32_t alloc_len, u_int8_t sense_len, 2217 u_int32_t timeout); 2218 2219 void scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries, 2220 void (*cbfcnp)(struct cam_periph *, 2221 union ccb *), u_int8_t tag_action, void *buf, 2222 u_int32_t alloc_len, u_int8_t sense_len, 2223 u_int32_t timeout); 2224 2225 void scsi_synchronize_cache(struct ccb_scsiio *csio, 2226 u_int32_t retries, 2227 void (*cbfcnp)(struct cam_periph *, 2228 union ccb *), u_int8_t tag_action, 2229 u_int32_t begin_lba, u_int16_t lb_count, 2230 u_int8_t sense_len, u_int32_t timeout); 2231 2232 void scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, 2233 void (*cbfcnp)(struct cam_periph *, 2234 union ccb*), 2235 uint8_t tag_action, int pcv, 2236 uint8_t page_code, uint8_t *data_ptr, 2237 uint16_t allocation_length, 2238 uint8_t sense_len, uint32_t timeout); 2239 2240 void scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries, 2241 void (*cbfcnp)(struct cam_periph *, union ccb *), 2242 uint8_t tag_action, int unit_offline, 2243 int device_offline, int self_test, int page_format, 2244 int self_test_code, uint8_t *data_ptr, 2245 uint16_t param_list_length, uint8_t sense_len, 2246 uint32_t timeout); 2247 2248 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, 2249 void (*cbfcnp)(struct cam_periph *, union ccb *), 2250 u_int8_t tag_action, int readop, u_int8_t byte2, 2251 int minimum_cmd_size, u_int64_t lba, 2252 u_int32_t block_count, u_int8_t *data_ptr, 2253 u_int32_t dxfer_len, u_int8_t sense_len, 2254 u_int32_t timeout); 2255 2256 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, 2257 void (*cbfcnp)(struct cam_periph *, union ccb *), 2258 u_int8_t tag_action, int start, int load_eject, 2259 int immediate, u_int8_t sense_len, u_int32_t timeout); 2260 2261 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry); 2262 int scsi_static_inquiry_match(caddr_t inqbuffer, 2263 caddr_t table_entry); 2264 int scsi_devid_match(uint8_t *rhs, size_t rhs_len, 2265 uint8_t *lhs, size_t lhs_len); 2266 2267 void scsi_extract_sense(struct scsi_sense_data *sense, int *error_code, 2268 int *sense_key, int *asc, int *ascq); 2269 void scsi_extract_sense_len(struct scsi_sense_data *sense, 2270 u_int sense_len, int *error_code, int *sense_key, 2271 int *asc, int *ascq, int show_errors); 2272 int scsi_get_sense_key(struct scsi_sense_data *sense, u_int sense_len, 2273 int show_errors); 2274 int scsi_get_asc(struct scsi_sense_data *sense, u_int sense_len, 2275 int show_errors); 2276 int scsi_get_ascq(struct scsi_sense_data *sense, u_int sense_len, 2277 int show_errors); 2278 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes); 2279 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes); 2280 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes); 2281 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes); 2282 static __inline uint32_t scsi_2btoul(const uint8_t *bytes); 2283 static __inline uint32_t scsi_3btoul(const uint8_t *bytes); 2284 static __inline int32_t scsi_3btol(const uint8_t *bytes); 2285 static __inline uint32_t scsi_4btoul(const uint8_t *bytes); 2286 static __inline uint64_t scsi_8btou64(const uint8_t *bytes); 2287 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header); 2288 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header); 2289 2290 static __inline void 2291 scsi_ulto2b(u_int32_t val, u_int8_t *bytes) 2292 { 2293 2294 bytes[0] = (val >> 8) & 0xff; 2295 bytes[1] = val & 0xff; 2296 } 2297 2298 static __inline void 2299 scsi_ulto3b(u_int32_t val, u_int8_t *bytes) 2300 { 2301 2302 bytes[0] = (val >> 16) & 0xff; 2303 bytes[1] = (val >> 8) & 0xff; 2304 bytes[2] = val & 0xff; 2305 } 2306 2307 static __inline void 2308 scsi_ulto4b(u_int32_t val, u_int8_t *bytes) 2309 { 2310 2311 bytes[0] = (val >> 24) & 0xff; 2312 bytes[1] = (val >> 16) & 0xff; 2313 bytes[2] = (val >> 8) & 0xff; 2314 bytes[3] = val & 0xff; 2315 } 2316 2317 static __inline void 2318 scsi_u64to8b(u_int64_t val, u_int8_t *bytes) 2319 { 2320 2321 bytes[0] = (val >> 56) & 0xff; 2322 bytes[1] = (val >> 48) & 0xff; 2323 bytes[2] = (val >> 40) & 0xff; 2324 bytes[3] = (val >> 32) & 0xff; 2325 bytes[4] = (val >> 24) & 0xff; 2326 bytes[5] = (val >> 16) & 0xff; 2327 bytes[6] = (val >> 8) & 0xff; 2328 bytes[7] = val & 0xff; 2329 } 2330 2331 static __inline uint32_t 2332 scsi_2btoul(const uint8_t *bytes) 2333 { 2334 uint32_t rv; 2335 2336 rv = (bytes[0] << 8) | 2337 bytes[1]; 2338 return (rv); 2339 } 2340 2341 static __inline uint32_t 2342 scsi_3btoul(const uint8_t *bytes) 2343 { 2344 uint32_t rv; 2345 2346 rv = (bytes[0] << 16) | 2347 (bytes[1] << 8) | 2348 bytes[2]; 2349 return (rv); 2350 } 2351 2352 static __inline int32_t 2353 scsi_3btol(const uint8_t *bytes) 2354 { 2355 uint32_t rc = scsi_3btoul(bytes); 2356 2357 if (rc & 0x00800000) 2358 rc |= 0xff000000; 2359 2360 return (int32_t) rc; 2361 } 2362 2363 static __inline uint32_t 2364 scsi_4btoul(const uint8_t *bytes) 2365 { 2366 uint32_t rv; 2367 2368 rv = (bytes[0] << 24) | 2369 (bytes[1] << 16) | 2370 (bytes[2] << 8) | 2371 bytes[3]; 2372 return (rv); 2373 } 2374 2375 static __inline uint64_t 2376 scsi_8btou64(const uint8_t *bytes) 2377 { 2378 uint64_t rv; 2379 2380 rv = (((uint64_t)bytes[0]) << 56) | 2381 (((uint64_t)bytes[1]) << 48) | 2382 (((uint64_t)bytes[2]) << 40) | 2383 (((uint64_t)bytes[3]) << 32) | 2384 (((uint64_t)bytes[4]) << 24) | 2385 (((uint64_t)bytes[5]) << 16) | 2386 (((uint64_t)bytes[6]) << 8) | 2387 bytes[7]; 2388 return (rv); 2389 } 2390 2391 /* 2392 * Given the pointer to a returned mode sense buffer, return a pointer to 2393 * the start of the first mode page. 2394 */ 2395 static __inline void * 2396 find_mode_page_6(struct scsi_mode_header_6 *mode_header) 2397 { 2398 void *page_start; 2399 2400 page_start = (void *)((u_int8_t *)&mode_header[1] + 2401 mode_header->blk_desc_len); 2402 2403 return(page_start); 2404 } 2405 2406 static __inline void * 2407 find_mode_page_10(struct scsi_mode_header_10 *mode_header) 2408 { 2409 void *page_start; 2410 2411 page_start = (void *)((u_int8_t *)&mode_header[1] + 2412 scsi_2btoul(mode_header->blk_desc_len)); 2413 2414 return(page_start); 2415 } 2416 2417 __END_DECLS 2418 2419 #endif /*_SCSI_SCSI_ALL_H*/ 2420