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 29 #ifdef _KERNEL 30 /* 31 * This is the number of seconds we wait for devices to settle after a SCSI 32 * bus reset. 33 */ 34 extern int scsi_delay; 35 #endif /* _KERNEL */ 36 37 /* 38 * SCSI command format 39 */ 40 41 /* 42 * Define dome bits that are in ALL (or a lot of) scsi commands 43 */ 44 #define SCSI_CTL_LINK 0x01 45 #define SCSI_CTL_FLAG 0x02 46 #define SCSI_CTL_VENDOR 0xC0 47 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */ 48 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */ 49 50 #define SCSI_MAX_CDBLEN 16 /* 51 * 16 byte commands are in the 52 * SCSI-3 spec 53 */ 54 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN) 55 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN" 56 #endif 57 58 /* 6byte CDBs special case 0 length to be 256 */ 59 #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len) 60 61 /* 62 * This type defines actions to be taken when a particular sense code is 63 * received. Right now, these flags are only defined to take up 16 bits, 64 * but can be expanded in the future if necessary. 65 */ 66 typedef enum { 67 SS_NOP = 0x000000, /* Do nothing */ 68 SS_RETRY = 0x010000, /* Retry the command */ 69 SS_FAIL = 0x020000, /* Bail out */ 70 SS_START = 0x030000, /* Send a Start Unit command to the device, 71 * then retry the original command. 72 */ 73 SS_TUR = 0x040000, /* Send a Test Unit Ready command to the 74 * device, then retry the original command. 75 */ 76 SS_REQSENSE = 0x050000, /* Send a RequestSense command to the 77 * device, then retry the original command. 78 */ 79 SS_MASK = 0xff0000 80 } scsi_sense_action; 81 82 typedef enum { 83 SSQ_NONE = 0x0000, 84 SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */ 85 SSQ_MANY = 0x0200, /* send lots of recovery commands */ 86 SSQ_RANGE = 0x0400, /* 87 * This table entry represents the 88 * end of a range of ASCQs that 89 * have identical error actions 90 * and text. 91 */ 92 SSQ_PRINT_SENSE = 0x0800, 93 SSQ_MASK = 0xff00 94 } scsi_sense_action_qualifier; 95 96 /* Mask for error status values */ 97 #define SS_ERRMASK 0xff 98 99 /* The default, retyable, error action */ 100 #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO 101 102 /* The retyable, error action, with table specified error code */ 103 #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE 104 105 /* Fatal error action, with table specified error code */ 106 #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE 107 108 struct scsi_generic 109 { 110 u_int8_t opcode; 111 u_int8_t bytes[11]; 112 }; 113 114 struct scsi_request_sense 115 { 116 u_int8_t opcode; 117 u_int8_t byte2; 118 u_int8_t unused[2]; 119 u_int8_t length; 120 u_int8_t control; 121 }; 122 123 struct scsi_test_unit_ready 124 { 125 u_int8_t opcode; 126 u_int8_t byte2; 127 u_int8_t unused[3]; 128 u_int8_t control; 129 }; 130 131 struct scsi_send_diag 132 { 133 u_int8_t opcode; 134 u_int8_t byte2; 135 #define SSD_UOL 0x01 136 #define SSD_DOL 0x02 137 #define SSD_SELFTEST 0x04 138 #define SSD_PF 0x10 139 u_int8_t unused[1]; 140 u_int8_t paramlen[2]; 141 u_int8_t control; 142 }; 143 144 struct scsi_sense 145 { 146 u_int8_t opcode; 147 u_int8_t byte2; 148 u_int8_t unused[2]; 149 u_int8_t length; 150 u_int8_t control; 151 }; 152 153 struct scsi_inquiry 154 { 155 u_int8_t opcode; 156 u_int8_t byte2; 157 #define SI_EVPD 0x01 158 u_int8_t page_code; 159 u_int8_t reserved; 160 u_int8_t length; 161 u_int8_t control; 162 }; 163 164 struct scsi_mode_sense_6 165 { 166 u_int8_t opcode; 167 u_int8_t byte2; 168 #define SMS_DBD 0x08 169 u_int8_t page; 170 #define SMS_PAGE_CODE 0x3F 171 #define SMS_VENDOR_SPECIFIC_PAGE 0x00 172 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02 173 #define SMS_FORMAT_DEVICE_PAGE 0x03 174 #define SMS_GEOMETRY_PAGE 0x04 175 #define SMS_CACHE_PAGE 0x08 176 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09 177 #define SMS_CONTROL_MODE_PAGE 0x0A 178 #define SMS_PROTO_SPECIFIC_PAGE 0x19 179 #define SMS_INFO_EXCEPTIONS_PAGE 0x1C 180 #define SMS_ALL_PAGES_PAGE 0x3F 181 #define SMS_PAGE_CTRL_MASK 0xC0 182 #define SMS_PAGE_CTRL_CURRENT 0x00 183 #define SMS_PAGE_CTRL_CHANGEABLE 0x40 184 #define SMS_PAGE_CTRL_DEFAULT 0x80 185 #define SMS_PAGE_CTRL_SAVED 0xC0 186 u_int8_t unused; 187 u_int8_t length; 188 u_int8_t control; 189 }; 190 191 struct scsi_mode_sense_10 192 { 193 u_int8_t opcode; 194 u_int8_t byte2; /* same bits as small version */ 195 u_int8_t page; /* same bits as small version */ 196 u_int8_t unused[4]; 197 u_int8_t length[2]; 198 u_int8_t control; 199 }; 200 201 struct scsi_mode_select_6 202 { 203 u_int8_t opcode; 204 u_int8_t byte2; 205 #define SMS_SP 0x01 206 #define SMS_PF 0x10 207 u_int8_t unused[2]; 208 u_int8_t length; 209 u_int8_t control; 210 }; 211 212 struct scsi_mode_select_10 213 { 214 u_int8_t opcode; 215 u_int8_t byte2; /* same bits as small version */ 216 u_int8_t unused[5]; 217 u_int8_t length[2]; 218 u_int8_t control; 219 }; 220 221 /* 222 * When sending a mode select to a tape drive, the medium type must be 0. 223 */ 224 struct scsi_mode_hdr_6 225 { 226 u_int8_t datalen; 227 u_int8_t medium_type; 228 u_int8_t dev_specific; 229 u_int8_t block_descr_len; 230 }; 231 232 struct scsi_mode_hdr_10 233 { 234 u_int8_t datalen[2]; 235 u_int8_t medium_type; 236 u_int8_t dev_specific; 237 u_int8_t reserved[2]; 238 u_int8_t block_descr_len[2]; 239 }; 240 241 struct scsi_mode_block_descr 242 { 243 u_int8_t density_code; 244 u_int8_t num_blocks[3]; 245 u_int8_t reserved; 246 u_int8_t block_len[3]; 247 }; 248 249 struct scsi_log_sense 250 { 251 u_int8_t opcode; 252 u_int8_t byte2; 253 #define SLS_SP 0x01 254 #define SLS_PPC 0x02 255 u_int8_t page; 256 #define SLS_PAGE_CODE 0x3F 257 #define SLS_ALL_PAGES_PAGE 0x00 258 #define SLS_OVERRUN_PAGE 0x01 259 #define SLS_ERROR_WRITE_PAGE 0x02 260 #define SLS_ERROR_READ_PAGE 0x03 261 #define SLS_ERROR_READREVERSE_PAGE 0x04 262 #define SLS_ERROR_VERIFY_PAGE 0x05 263 #define SLS_ERROR_NONMEDIUM_PAGE 0x06 264 #define SLS_ERROR_LASTN_PAGE 0x07 265 #define SLS_SELF_TEST_PAGE 0x10 266 #define SLS_IE_PAGE 0x2f 267 #define SLS_PAGE_CTRL_MASK 0xC0 268 #define SLS_PAGE_CTRL_THRESHOLD 0x00 269 #define SLS_PAGE_CTRL_CUMULATIVE 0x40 270 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 271 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 272 u_int8_t reserved[2]; 273 u_int8_t paramptr[2]; 274 u_int8_t length[2]; 275 u_int8_t control; 276 }; 277 278 struct scsi_log_select 279 { 280 u_int8_t opcode; 281 u_int8_t byte2; 282 /* SLS_SP 0x01 */ 283 #define SLS_PCR 0x02 284 u_int8_t page; 285 /* SLS_PAGE_CTRL_MASK 0xC0 */ 286 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */ 287 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */ 288 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */ 289 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */ 290 u_int8_t reserved[4]; 291 u_int8_t length[2]; 292 u_int8_t control; 293 }; 294 295 struct scsi_log_header 296 { 297 u_int8_t page; 298 u_int8_t reserved; 299 u_int8_t datalen[2]; 300 }; 301 302 struct scsi_log_param_header { 303 u_int8_t param_code[2]; 304 u_int8_t param_control; 305 #define SLP_LP 0x01 306 #define SLP_LBIN 0x02 307 #define SLP_TMC_MASK 0x0C 308 #define SLP_TMC_ALWAYS 0x00 309 #define SLP_TMC_EQUAL 0x04 310 #define SLP_TMC_NOTEQUAL 0x08 311 #define SLP_TMC_GREATER 0x0C 312 #define SLP_ETC 0x10 313 #define SLP_TSD 0x20 314 #define SLP_DS 0x40 315 #define SLP_DU 0x80 316 u_int8_t param_len; 317 }; 318 319 struct scsi_control_page { 320 u_int8_t page_code; 321 u_int8_t page_length; 322 u_int8_t rlec; 323 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/ 324 u_int8_t queue_flags; 325 #define SCP_QUEUE_ALG_MASK 0xF0 326 #define SCP_QUEUE_ALG_RESTRICTED 0x00 327 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10 328 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/ 329 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/ 330 u_int8_t eca_and_aen; 331 #define SCP_EECA 0x80 /*Enable Extended CA*/ 332 #define SCP_RAENP 0x04 /*Ready AEN Permission*/ 333 #define SCP_UAAENP 0x02 /*UA AEN Permission*/ 334 #define SCP_EAENP 0x01 /*Error AEN Permission*/ 335 u_int8_t reserved; 336 u_int8_t aen_holdoff_period[2]; 337 }; 338 339 struct scsi_cache_page { 340 u_int8_t page_code; 341 #define SCHP_PAGE_SAVABLE 0x80 /* Page is savable */ 342 u_int8_t page_length; 343 u_int8_t cache_flags; 344 #define SCHP_FLAGS_WCE 0x04 /* Write Cache Enable */ 345 #define SCHP_FLAGS_MF 0x02 /* Multiplication factor */ 346 #define SCHP_FLAGS_RCD 0x01 /* Read Cache Disable */ 347 u_int8_t rw_cache_policy; 348 u_int8_t dis_prefetch[2]; 349 u_int8_t min_prefetch[2]; 350 u_int8_t max_prefetch[2]; 351 u_int8_t max_prefetch_ceil[2]; 352 }; 353 354 struct scsi_info_exceptions_page { 355 u_int8_t page_code; 356 #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */ 357 u_int8_t page_length; 358 u_int8_t info_flags; 359 #define SIEP_FLAGS_PERF 0x80 360 #define SIEP_FLAGS_EBF 0x20 361 #define SIEP_FLAGS_EWASC 0x10 362 #define SIEP_FLAGS_DEXCPT 0x08 363 #define SIEP_FLAGS_TEST 0x04 364 #define SIEP_FLAGS_EBACKERR 0x02 365 #define SIEP_FLAGS_LOGERR 0x01 366 u_int8_t mrie; 367 u_int8_t interval_timer[4]; 368 u_int8_t report_count[4]; 369 }; 370 371 struct scsi_proto_specific_page { 372 u_int8_t page_code; 373 #define SPSP_PAGE_SAVABLE 0x80 /* Page is savable */ 374 u_int8_t page_length; 375 u_int8_t protocol; 376 #define SPSP_PROTO_FC 0x00 377 #define SPSP_PROTO_SPI 0x01 378 #define SPSP_PROTO_SSA 0x02 379 #define SPSP_PROTO_1394 0x03 380 #define SPSP_PROTO_RDMA 0x04 381 #define SPSP_PROTO_ISCSI 0x05 382 #define SPSP_PROTO_SAS 0x06 383 #define SPSP_PROTO_ADT 0x07 384 #define SPSP_PROTO_ATA 0x08 385 #define SPSP_PROTO_NONE 0x0f 386 }; 387 388 struct scsi_reserve 389 { 390 u_int8_t opcode; 391 u_int8_t byte2; 392 u_int8_t unused[2]; 393 u_int8_t length; 394 u_int8_t control; 395 }; 396 397 struct scsi_release 398 { 399 u_int8_t opcode; 400 u_int8_t byte2; 401 u_int8_t unused[2]; 402 u_int8_t length; 403 u_int8_t control; 404 }; 405 406 struct scsi_prevent 407 { 408 u_int8_t opcode; 409 u_int8_t byte2; 410 u_int8_t unused[2]; 411 u_int8_t how; 412 u_int8_t control; 413 }; 414 #define PR_PREVENT 0x01 415 #define PR_ALLOW 0x00 416 417 struct scsi_sync_cache 418 { 419 u_int8_t opcode; 420 u_int8_t byte2; 421 u_int8_t begin_lba[4]; 422 u_int8_t reserved; 423 u_int8_t lb_count[2]; 424 u_int8_t control; 425 }; 426 427 428 struct scsi_changedef 429 { 430 u_int8_t opcode; 431 u_int8_t byte2; 432 u_int8_t unused1; 433 u_int8_t how; 434 u_int8_t unused[4]; 435 u_int8_t datalen; 436 u_int8_t control; 437 }; 438 439 struct scsi_read_buffer 440 { 441 u_int8_t opcode; 442 u_int8_t byte2; 443 #define RWB_MODE 0x07 444 #define RWB_MODE_HDR_DATA 0x00 445 #define RWB_MODE_DATA 0x02 446 #define RWB_MODE_DOWNLOAD 0x04 447 #define RWB_MODE_DOWNLOAD_SAVE 0x05 448 u_int8_t buffer_id; 449 u_int8_t offset[3]; 450 u_int8_t length[3]; 451 u_int8_t control; 452 }; 453 454 struct scsi_write_buffer 455 { 456 u_int8_t opcode; 457 u_int8_t byte2; 458 u_int8_t buffer_id; 459 u_int8_t offset[3]; 460 u_int8_t length[3]; 461 u_int8_t control; 462 }; 463 464 struct scsi_rw_6 465 { 466 u_int8_t opcode; 467 u_int8_t addr[3]; 468 /* only 5 bits are valid in the MSB address byte */ 469 #define SRW_TOPADDR 0x1F 470 u_int8_t length; 471 u_int8_t control; 472 }; 473 474 struct scsi_rw_10 475 { 476 u_int8_t opcode; 477 #define SRW10_RELADDR 0x01 478 /* EBP defined for WRITE(10) only */ 479 #define SRW10_EBP 0x04 480 #define SRW10_FUA 0x08 481 #define SRW10_DPO 0x10 482 u_int8_t byte2; 483 u_int8_t addr[4]; 484 u_int8_t reserved; 485 u_int8_t length[2]; 486 u_int8_t control; 487 }; 488 489 struct scsi_rw_12 490 { 491 u_int8_t opcode; 492 #define SRW12_RELADDR 0x01 493 #define SRW12_FUA 0x08 494 #define SRW12_DPO 0x10 495 u_int8_t byte2; 496 u_int8_t addr[4]; 497 u_int8_t length[4]; 498 u_int8_t reserved; 499 u_int8_t control; 500 }; 501 502 struct scsi_rw_16 503 { 504 u_int8_t opcode; 505 #define SRW16_RELADDR 0x01 506 #define SRW16_FUA 0x08 507 #define SRW16_DPO 0x10 508 u_int8_t byte2; 509 u_int8_t addr[8]; 510 u_int8_t length[4]; 511 u_int8_t reserved; 512 u_int8_t control; 513 }; 514 515 struct scsi_start_stop_unit 516 { 517 u_int8_t opcode; 518 u_int8_t byte2; 519 #define SSS_IMMED 0x01 520 u_int8_t reserved[2]; 521 u_int8_t how; 522 #define SSS_START 0x01 523 #define SSS_LOEJ 0x02 524 u_int8_t control; 525 }; 526 527 struct ata_pass_12 { 528 u_int8_t opcode; 529 u_int8_t protocol; 530 #define AP_MULTI 0xe0 531 u_int8_t flags; 532 #define AP_T_LEN 0x03 533 #define AP_BB 0x04 534 #define AP_T_DIR 0x08 535 #define AP_CK_COND 0x20 536 #define AP_OFFLINE 0x60 537 u_int8_t features; 538 u_int8_t sector_count; 539 u_int8_t lba_low; 540 u_int8_t lba_mid; 541 u_int8_t lba_high; 542 u_int8_t device; 543 u_int8_t command; 544 u_int8_t reserved; 545 u_int8_t control; 546 }; 547 548 struct ata_pass_16 { 549 u_int8_t opcode; 550 u_int8_t protocol; 551 #define AP_EXTEND 0x01 552 u_int8_t flags; 553 u_int8_t features_ext; 554 u_int8_t features; 555 u_int8_t sector_count_ext; 556 u_int8_t sector_count; 557 u_int8_t lba_low_ext; 558 u_int8_t lba_low; 559 u_int8_t lba_mid_ext; 560 u_int8_t lba_mid; 561 u_int8_t lba_high_ext; 562 u_int8_t lba_high; 563 u_int8_t device; 564 u_int8_t command; 565 u_int8_t control; 566 }; 567 568 #define SC_SCSI_1 0x01 569 #define SC_SCSI_2 0x03 570 571 /* 572 * Opcodes 573 */ 574 575 #define TEST_UNIT_READY 0x00 576 #define REQUEST_SENSE 0x03 577 #define READ_6 0x08 578 #define WRITE_6 0x0A 579 #define INQUIRY 0x12 580 #define MODE_SELECT_6 0x15 581 #define MODE_SENSE_6 0x1A 582 #define START_STOP_UNIT 0x1B 583 #define START_STOP 0x1B 584 #define RESERVE 0x16 585 #define RELEASE 0x17 586 #define RECEIVE_DIAGNOSTIC 0x1C 587 #define SEND_DIAGNOSTIC 0x1D 588 #define PREVENT_ALLOW 0x1E 589 #define READ_CAPACITY 0x25 590 #define READ_10 0x28 591 #define WRITE_10 0x2A 592 #define POSITION_TO_ELEMENT 0x2B 593 #define SYNCHRONIZE_CACHE 0x35 594 #define READ_DEFECT_DATA_10 0x37 595 #define WRITE_BUFFER 0x3B 596 #define READ_BUFFER 0x3C 597 #define CHANGE_DEFINITION 0x40 598 #define LOG_SELECT 0x4C 599 #define LOG_SENSE 0x4D 600 #define MODE_SELECT_10 0x55 601 #define MODE_SENSE_10 0x5A 602 #define ATA_PASS_16 0x85 603 #define READ_16 0x88 604 #define WRITE_16 0x8A 605 #define SERVICE_ACTION_IN 0x9E 606 #define REPORT_LUNS 0xA0 607 #define ATA_PASS_12 0xA1 608 #define MAINTENANCE_IN 0xA3 609 #define MAINTENANCE_OUT 0xA4 610 #define MOVE_MEDIUM 0xA5 611 #define READ_12 0xA8 612 #define WRITE_12 0xAA 613 #define READ_ELEMENT_STATUS 0xB8 614 615 /* Maintenance In Service Action Codes */ 616 #define REPORT_IDENTIFYING_INFRMATION 0x05 617 #define REPORT_TARGET_PORT_GROUPS 0x0A 618 #define REPORT_ALIASES 0x0B 619 #define REPORT_SUPPORTED_OPERATION_CODES 0x0C 620 #define REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0D 621 #define REPORT_PRIORITY 0x0E 622 #define REPORT_TIMESTAMP 0x0F 623 #define MANAGEMENT_PROTOCOL_IN 0x10 624 /* Maintenance Out Service Action Codes */ 625 #define SET_IDENTIFY_INFORMATION 0x06 626 #define SET_TARGET_PORT_GROUPS 0x0A 627 #define CHANGE_ALIASES 0x0B 628 #define SET_PRIORITY 0x0E 629 #define SET_TIMESTAMP 0x0F 630 #define MANGAEMENT_PROTOCOL_OUT 0x10 631 632 /* 633 * Device Types 634 */ 635 #define T_DIRECT 0x00 636 #define T_SEQUENTIAL 0x01 637 #define T_PRINTER 0x02 638 #define T_PROCESSOR 0x03 639 #define T_WORM 0x04 640 #define T_CDROM 0x05 641 #define T_SCANNER 0x06 642 #define T_OPTICAL 0x07 643 #define T_CHANGER 0x08 644 #define T_COMM 0x09 645 #define T_ASC0 0x0a 646 #define T_ASC1 0x0b 647 #define T_STORARRAY 0x0c 648 #define T_ENCLOSURE 0x0d 649 #define T_RBC 0x0e 650 #define T_OCRW 0x0f 651 #define T_OSD 0x11 652 #define T_ADC 0x12 653 #define T_NODEVICE 0x1f 654 #define T_ANY 0xff /* Used in Quirk table matches */ 655 656 #define T_REMOV 1 657 #define T_FIXED 0 658 659 /* 660 * This length is the initial inquiry length used by the probe code, as 661 * well as the legnth necessary for scsi_print_inquiry() to function 662 * correctly. If either use requires a different length in the future, 663 * the two values should be de-coupled. 664 */ 665 #define SHORT_INQUIRY_LENGTH 36 666 667 struct scsi_inquiry_data 668 { 669 u_int8_t device; 670 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f) 671 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5) 672 #define SID_QUAL_LU_CONNECTED 0x00 /* 673 * The specified peripheral device 674 * type is currently connected to 675 * logical unit. If the target cannot 676 * determine whether or not a physical 677 * device is currently connected, it 678 * shall also use this peripheral 679 * qualifier when returning the INQUIRY 680 * data. This peripheral qualifier 681 * does not mean that the device is 682 * ready for access by the initiator. 683 */ 684 #define SID_QUAL_LU_OFFLINE 0x01 /* 685 * The target is capable of supporting 686 * the specified peripheral device type 687 * on this logical unit; however, the 688 * physical device is not currently 689 * connected to this logical unit. 690 */ 691 #define SID_QUAL_RSVD 0x02 692 #define SID_QUAL_BAD_LU 0x03 /* 693 * The target is not capable of 694 * supporting a physical device on 695 * this logical unit. For this 696 * peripheral qualifier the peripheral 697 * device type shall be set to 1Fh to 698 * provide compatibility with previous 699 * versions of SCSI. All other 700 * peripheral device type values are 701 * reserved for this peripheral 702 * qualifier. 703 */ 704 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0) 705 u_int8_t dev_qual2; 706 #define SID_QUAL2 0x7F 707 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0) 708 u_int8_t version; 709 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07) 710 #define SCSI_REV_0 0 711 #define SCSI_REV_CCS 1 712 #define SCSI_REV_2 2 713 #define SCSI_REV_SPC 3 714 #define SCSI_REV_SPC2 4 715 #define SCSI_REV_SPC3 5 716 #define SCSI_REV_SPC4 6 717 718 #define SID_ECMA 0x38 719 #define SID_ISO 0xC0 720 u_int8_t response_format; 721 #define SID_AENC 0x80 722 #define SID_TrmIOP 0x40 723 u_int8_t additional_length; 724 #define SID_ADDITIONAL_LENGTH(iqd) \ 725 ((iqd)->additional_length + \ 726 offsetof(struct scsi_inquiry_data, additional_length) + 1) 727 u_int8_t spc3_flags; 728 #define SPC3_SID_PROTECT 0x01 729 #define SPC3_SID_3PC 0x08 730 #define SPC3_SID_TPGS_MASK 0x30 731 #define SPC3_SID_TPGS_IMPLICIT 0x10 732 #define SPC3_SID_TPGS_EXPLICIT 0x20 733 #define SPC3_SID_ACC 0x40 734 #define SPC3_SID_SCCS 0x80 735 u_int8_t spc2_flags; 736 #define SPC2_SID_MChngr 0x08 737 #define SPC2_SID_MultiP 0x10 738 #define SPC2_SID_EncServ 0x40 739 #define SPC2_SID_BQueue 0x80 740 741 #define INQ_DATA_TQ_ENABLED(iqd) \ 742 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \ 743 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \ 744 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue))) 745 746 u_int8_t flags; 747 #define SID_SftRe 0x01 748 #define SID_CmdQue 0x02 749 #define SID_Linked 0x08 750 #define SID_Sync 0x10 751 #define SID_WBus16 0x20 752 #define SID_WBus32 0x40 753 #define SID_RelAdr 0x80 754 #define SID_VENDOR_SIZE 8 755 char vendor[SID_VENDOR_SIZE]; 756 #define SID_PRODUCT_SIZE 16 757 char product[SID_PRODUCT_SIZE]; 758 #define SID_REVISION_SIZE 4 759 char revision[SID_REVISION_SIZE]; 760 /* 761 * The following fields were taken from SCSI Primary Commands - 2 762 * (SPC-2) Revision 14, Dated 11 November 1999 763 */ 764 #define SID_VENDOR_SPECIFIC_0_SIZE 20 765 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE]; 766 /* 767 * An extension of SCSI Parallel Specific Values 768 */ 769 #define SID_SPI_IUS 0x01 770 #define SID_SPI_QAS 0x02 771 #define SID_SPI_CLOCK_ST 0x00 772 #define SID_SPI_CLOCK_DT 0x04 773 #define SID_SPI_CLOCK_DT_ST 0x0C 774 #define SID_SPI_MASK 0x0F 775 u_int8_t spi3data; 776 u_int8_t reserved2; 777 /* 778 * Version Descriptors, stored 2 byte values. 779 */ 780 u_int8_t version1[2]; 781 u_int8_t version2[2]; 782 u_int8_t version3[2]; 783 u_int8_t version4[2]; 784 u_int8_t version5[2]; 785 u_int8_t version6[2]; 786 u_int8_t version7[2]; 787 u_int8_t version8[2]; 788 789 u_int8_t reserved3[22]; 790 791 #define SID_VENDOR_SPECIFIC_1_SIZE 160 792 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE]; 793 }; 794 795 struct scsi_vpd_supported_page_list 796 { 797 u_int8_t device; 798 u_int8_t page_code; 799 #define SVPD_SUPPORTED_PAGE_LIST 0x00 800 #define SVPD_SUPPORTED_PAGES_HDR_LEN 4 801 u_int8_t reserved; 802 u_int8_t length; /* number of VPD entries */ 803 #define SVPD_SUPPORTED_PAGES_SIZE 251 804 u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE]; 805 }; 806 807 /* 808 * This structure is more suited to target operation, because the 809 * number of supported pages is left to the user to allocate. 810 */ 811 struct scsi_vpd_supported_pages 812 { 813 u_int8_t device; 814 u_int8_t page_code; 815 u_int8_t reserved; 816 #define SVPD_SUPPORTED_PAGES 0x00 817 u_int8_t length; 818 u_int8_t page_list[0]; 819 }; 820 821 822 struct scsi_vpd_unit_serial_number 823 { 824 u_int8_t device; 825 u_int8_t page_code; 826 #define SVPD_UNIT_SERIAL_NUMBER 0x80 827 u_int8_t reserved; 828 u_int8_t length; /* serial number length */ 829 #define SVPD_SERIAL_NUM_SIZE 251 830 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE]; 831 }; 832 833 struct scsi_vpd_device_id 834 { 835 u_int8_t device; 836 u_int8_t page_code; 837 #define SVPD_DEVICE_ID 0x83 838 #define SVPD_DEVICE_ID_MAX_SIZE 0xffff 839 #define SVPD_DEVICE_ID_HDR_LEN 4 840 #define SVPD_DEVICE_ID_DESC_HDR_LEN 4 841 u_int8_t length[2]; 842 u_int8_t desc_list[0]; 843 }; 844 845 struct scsi_vpd_id_descriptor 846 { 847 u_int8_t proto_codeset; 848 #define SCSI_PROTO_FC 0x00 849 #define SCSI_PROTO_SPI 0x01 850 #define SCSI_PROTO_SSA 0x02 851 #define SCSI_PROTO_1394 0x03 852 #define SCSI_PROTO_RDMA 0x04 853 #define SCSI_PROTO_iSCSI 0x05 854 #define SCSI_PROTO_SAS 0x06 855 #define SVPD_ID_PROTO_SHIFT 4 856 #define SVPD_ID_CODESET_BINARY 0x01 857 #define SVPD_ID_CODESET_ASCII 0x02 858 u_int8_t id_type; 859 #define SVPD_ID_PIV 0x80 860 #define SVPD_ID_ASSOC_LUN 0x00 861 #define SVPD_ID_ASSOC_PORT 0x10 862 #define SVPD_ID_ASSOC_TARGET 0x20 863 #define SVPD_ID_TYPE_VENDOR 0x00 864 #define SVPD_ID_TYPE_T10 0x01 865 #define SVPD_ID_TYPE_EUI64 0x02 866 #define SVPD_ID_TYPE_NAA 0x03 867 #define SVPD_ID_TYPE_RELTARG 0x04 868 #define SVPD_ID_TYPE_TPORTGRP 0x05 869 #define SVPD_ID_TYPE_LUNGRP 0x06 870 #define SVPD_ID_TYPE_MD5_LUN_ID 0x07 871 #define SVPD_ID_TYPE_SCSI_NAME 0x08 872 #define SVPD_ID_TYPE_MASK 0x0f 873 u_int8_t reserved; 874 u_int8_t length; 875 u_int8_t identifier[0]; 876 }; 877 878 struct scsi_vpd_id_t10 879 { 880 u_int8_t vendor[8]; 881 u_int8_t vendor_spec_id[0]; 882 }; 883 884 struct scsi_vpd_id_eui64 885 { 886 u_int8_t ieee_company_id[3]; 887 u_int8_t extension_id[5]; 888 }; 889 890 struct scsi_vpd_id_naa_basic 891 { 892 uint8_t naa; 893 /* big endian, packed: 894 uint8_t naa : 4; 895 uint8_t naa_desig : 4; 896 */ 897 #define SVPD_ID_NAA_IEEE_EXT 0x02 898 #define SVPD_ID_NAA_LOCAL_REG 0x03 899 #define SVPD_ID_NAA_IEEE_REG 0x05 900 #define SVPD_ID_NAA_IEEE_REG_EXT 0x06 901 uint8_t naa_data[0]; 902 }; 903 904 struct scsi_vpd_id_naa_ieee_extended_id 905 { 906 uint8_t naa; 907 uint8_t vendor_specific_id_a; 908 uint8_t ieee_company_id[3]; 909 uint8_t vendor_specific_id_b[4]; 910 }; 911 912 struct scsi_vpd_id_naa_local_reg 913 { 914 uint8_t naa; 915 uint8_t local_value[7]; 916 }; 917 918 struct scsi_vpd_id_naa_ieee_reg 919 { 920 uint8_t naa; 921 uint8_t reg_value[7]; 922 /* big endian, packed: 923 uint8_t naa_basic : 4; 924 uint8_t ieee_company_id_0 : 4; 925 uint8_t ieee_company_id_1[2]; 926 uint8_t ieee_company_id_2 : 4; 927 uint8_t vendor_specific_id_0 : 4; 928 uint8_t vendor_specific_id_1[4]; 929 */ 930 }; 931 932 struct scsi_vpd_id_naa_ieee_reg_extended 933 { 934 uint8_t naa; 935 uint8_t reg_value[15]; 936 /* big endian, packed: 937 uint8_t naa_basic : 4; 938 uint8_t ieee_company_id_0 : 4; 939 uint8_t ieee_company_id_1[2]; 940 uint8_t ieee_company_id_2 : 4; 941 uint8_t vendor_specific_id_0 : 4; 942 uint8_t vendor_specific_id_1[4]; 943 uint8_t vendor_specific_id_ext[8]; 944 */ 945 }; 946 947 struct scsi_vpd_id_rel_trgt_port_id 948 { 949 uint8_t obsolete[2]; 950 uint8_t rel_trgt_port_id[2]; 951 }; 952 953 struct scsi_vpd_id_trgt_port_grp_id 954 { 955 uint8_t reserved[2]; 956 uint8_t trgt_port_grp[2]; 957 }; 958 959 struct scsi_vpd_id_lun_grp_id 960 { 961 uint8_t reserved[2]; 962 uint8_t log_unit_grp[2]; 963 }; 964 965 struct scsi_vpd_id_md5_lun_id 966 { 967 uint8_t lun_id[16]; 968 }; 969 970 struct scsi_vpd_id_scsi_name 971 { 972 uint8_t name_string[256]; 973 }; 974 975 struct scsi_read_capacity 976 { 977 u_int8_t opcode; 978 u_int8_t byte2; 979 u_int8_t addr[4]; 980 u_int8_t unused[3]; 981 u_int8_t control; 982 }; 983 984 struct scsi_read_capacity_16 985 { 986 uint8_t opcode; 987 #define SRC16_SERVICE_ACTION 0x10 988 uint8_t service_action; 989 uint8_t addr[8]; 990 uint8_t alloc_len[4]; 991 #define SRC16_PMI 0x01 992 #define SRC16_RELADR 0x02 993 uint8_t reladr; 994 uint8_t control; 995 }; 996 997 struct scsi_read_capacity_data 998 { 999 u_int8_t addr[4]; 1000 u_int8_t length[4]; 1001 }; 1002 1003 struct scsi_read_capacity_data_long 1004 { 1005 uint8_t addr[8]; 1006 uint8_t length[4]; 1007 }; 1008 1009 struct scsi_report_luns 1010 { 1011 uint8_t opcode; 1012 uint8_t reserved1; 1013 #define RPL_REPORT_DEFAULT 0x00 1014 #define RPL_REPORT_WELLKNOWN 0x01 1015 #define RPL_REPORT_ALL 0x02 1016 uint8_t select_report; 1017 uint8_t reserved2[3]; 1018 uint8_t length[4]; 1019 uint8_t reserved3; 1020 uint8_t control; 1021 }; 1022 1023 struct scsi_report_luns_data { 1024 u_int8_t length[4]; /* length of LUN inventory, in bytes */ 1025 u_int8_t reserved[4]; /* unused */ 1026 /* 1027 * LUN inventory- we only support the type zero form for now. 1028 */ 1029 struct { 1030 u_int8_t lundata[8]; 1031 } luns[0]; 1032 }; 1033 #define RPL_LUNDATA_PERIPH_BUS_MASK 0x3f 1034 #define RPL_LUNDATA_FLAT_LUN_MASK 0x3f 1035 #define RPL_LUNDATA_LUN_TARG_MASK 0x3f 1036 #define RPL_LUNDATA_LUN_BUS_MASK 0xe0 1037 #define RPL_LUNDATA_LUN_LUN_MASK 0x1f 1038 #define RPL_LUNDATA_EXT_LEN_MASK 0x30 1039 #define RPL_LUNDATA_EXT_EAM_MASK 0x0f 1040 #define RPL_LUNDATA_EXT_EAM_WK 0x01 1041 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC 0x0f 1042 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */ 1043 #define RPL_LUNDATA_ATYP_PERIPH 0x00 1044 #define RPL_LUNDATA_ATYP_FLAT 0x40 1045 #define RPL_LUNDATA_ATYP_LUN 0x80 1046 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0 1047 1048 struct scsi_target_group 1049 { 1050 uint8_t opcode; 1051 uint8_t service_action; 1052 #define STG_PDF_LENGTH 0x00 1053 #define RPL_PDF_EXTENDED 0x20 1054 uint8_t reserved1[4]; 1055 uint8_t length[4]; 1056 uint8_t reserved2; 1057 uint8_t control; 1058 }; 1059 1060 struct scsi_target_port_descriptor { 1061 uint8_t reserved[2]; 1062 uint8_t relative_target_port_identifier[2]; 1063 uint8_t desc_list[]; 1064 }; 1065 1066 struct scsi_target_port_group_descriptor { 1067 uint8_t pref_state; 1068 #define TPG_PRIMARY 0x80 1069 #define TPG_ASYMMETRIC_ACCESS_STATE_MASK 0xf 1070 #define TPG_ASYMMETRIC_ACCESS_OPTIMIZED 0x0 1071 #define TPG_ASYMMETRIC_ACCESS_NONOPTIMIZED 0x1 1072 #define TPG_ASYMMETRIC_ACCESS_STANDBY 0x2 1073 #define TPG_ASYMMETRIC_ACCESS_UNAVAILABLE 0x3 1074 #define TPG_ASYMMETRIC_ACCESS_LBA_DEPENDENT 0x4 1075 #define TPG_ASYMMETRIC_ACCESS_OFFLINE 0xE 1076 #define TPG_ASYMMETRIC_ACCESS_TRANSITIONING 0xF 1077 uint8_t support; 1078 #define TPG_AO_SUP 0x01 1079 #define TPG_AN_SUP 0x02 1080 #define TPG_S_SUP 0x04 1081 #define TPG_U_SUP 0x08 1082 #define TPG_LBD_SUP 0x10 1083 #define TPG_O_SUP 0x40 1084 #define TPG_T_SUP 0x80 1085 uint8_t target_port_group[2]; 1086 uint8_t reserved; 1087 uint8_t status; 1088 uint8_t vendor_specific; 1089 uint8_t target_port_count; 1090 struct scsi_target_port_descriptor descriptors[]; 1091 }; 1092 1093 struct scsi_target_group_data { 1094 uint8_t length[4]; /* length of returned data, in bytes */ 1095 struct scsi_target_port_group_descriptor groups[]; 1096 }; 1097 1098 struct scsi_target_group_data_extended { 1099 uint8_t length[4]; /* length of returned data, in bytes */ 1100 uint8_t format_type; /* STG_PDF_LENGTH or RPL_PDF_EXTENDED */ 1101 uint8_t implicit_transition_time; 1102 uint8_t reserved[2]; 1103 struct scsi_target_port_group_descriptor groups[]; 1104 }; 1105 1106 1107 struct scsi_sense_data 1108 { 1109 u_int8_t error_code; 1110 #define SSD_ERRCODE 0x7F 1111 #define SSD_CURRENT_ERROR 0x70 1112 #define SSD_DEFERRED_ERROR 0x71 1113 #define SSD_ERRCODE_VALID 0x80 1114 u_int8_t segment; 1115 u_int8_t flags; 1116 #define SSD_KEY 0x0F 1117 #define SSD_KEY_NO_SENSE 0x00 1118 #define SSD_KEY_RECOVERED_ERROR 0x01 1119 #define SSD_KEY_NOT_READY 0x02 1120 #define SSD_KEY_MEDIUM_ERROR 0x03 1121 #define SSD_KEY_HARDWARE_ERROR 0x04 1122 #define SSD_KEY_ILLEGAL_REQUEST 0x05 1123 #define SSD_KEY_UNIT_ATTENTION 0x06 1124 #define SSD_KEY_DATA_PROTECT 0x07 1125 #define SSD_KEY_BLANK_CHECK 0x08 1126 #define SSD_KEY_Vendor_Specific 0x09 1127 #define SSD_KEY_COPY_ABORTED 0x0a 1128 #define SSD_KEY_ABORTED_COMMAND 0x0b 1129 #define SSD_KEY_EQUAL 0x0c 1130 #define SSD_KEY_VOLUME_OVERFLOW 0x0d 1131 #define SSD_KEY_MISCOMPARE 0x0e 1132 #define SSD_KEY_RESERVED 0x0f 1133 #define SSD_ILI 0x20 1134 #define SSD_EOM 0x40 1135 #define SSD_FILEMARK 0x80 1136 u_int8_t info[4]; 1137 u_int8_t extra_len; 1138 u_int8_t cmd_spec_info[4]; 1139 u_int8_t add_sense_code; 1140 u_int8_t add_sense_code_qual; 1141 u_int8_t fru; 1142 u_int8_t sense_key_spec[3]; 1143 #define SSD_SCS_VALID 0x80 1144 #define SSD_FIELDPTR_CMD 0x40 1145 #define SSD_BITPTR_VALID 0x08 1146 #define SSD_BITPTR_VALUE 0x07 1147 #define SSD_MIN_SIZE 18 1148 u_int8_t extra_bytes[14]; 1149 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data) 1150 }; 1151 1152 struct scsi_mode_header_6 1153 { 1154 u_int8_t data_length; /* Sense data length */ 1155 u_int8_t medium_type; 1156 u_int8_t dev_spec; 1157 u_int8_t blk_desc_len; 1158 }; 1159 1160 struct scsi_mode_header_10 1161 { 1162 u_int8_t data_length[2];/* Sense data length */ 1163 u_int8_t medium_type; 1164 u_int8_t dev_spec; 1165 u_int8_t unused[2]; 1166 u_int8_t blk_desc_len[2]; 1167 }; 1168 1169 struct scsi_mode_page_header 1170 { 1171 u_int8_t page_code; 1172 u_int8_t page_length; 1173 }; 1174 1175 struct scsi_mode_blk_desc 1176 { 1177 u_int8_t density; 1178 u_int8_t nblocks[3]; 1179 u_int8_t reserved; 1180 u_int8_t blklen[3]; 1181 }; 1182 1183 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */ 1184 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */ 1185 1186 1187 /* 1188 * Status Byte 1189 */ 1190 #define SCSI_STATUS_OK 0x00 1191 #define SCSI_STATUS_CHECK_COND 0x02 1192 #define SCSI_STATUS_COND_MET 0x04 1193 #define SCSI_STATUS_BUSY 0x08 1194 #define SCSI_STATUS_INTERMED 0x10 1195 #define SCSI_STATUS_INTERMED_COND_MET 0x14 1196 #define SCSI_STATUS_RESERV_CONFLICT 0x18 1197 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */ 1198 #define SCSI_STATUS_QUEUE_FULL 0x28 1199 #define SCSI_STATUS_ACA_ACTIVE 0x30 1200 #define SCSI_STATUS_TASK_ABORTED 0x40 1201 1202 struct scsi_inquiry_pattern { 1203 u_int8_t type; 1204 u_int8_t media_type; 1205 #define SIP_MEDIA_REMOVABLE 0x01 1206 #define SIP_MEDIA_FIXED 0x02 1207 const char *vendor; 1208 const char *product; 1209 const char *revision; 1210 }; 1211 1212 struct scsi_static_inquiry_pattern { 1213 u_int8_t type; 1214 u_int8_t media_type; 1215 char vendor[SID_VENDOR_SIZE+1]; 1216 char product[SID_PRODUCT_SIZE+1]; 1217 char revision[SID_REVISION_SIZE+1]; 1218 }; 1219 1220 struct scsi_sense_quirk_entry { 1221 struct scsi_inquiry_pattern inq_pat; 1222 int num_sense_keys; 1223 int num_ascs; 1224 struct sense_key_table_entry *sense_key_info; 1225 struct asc_table_entry *asc_info; 1226 }; 1227 1228 struct sense_key_table_entry { 1229 u_int8_t sense_key; 1230 u_int32_t action; 1231 const char *desc; 1232 }; 1233 1234 struct asc_table_entry { 1235 u_int8_t asc; 1236 u_int8_t ascq; 1237 u_int32_t action; 1238 const char *desc; 1239 }; 1240 1241 struct op_table_entry { 1242 u_int8_t opcode; 1243 u_int32_t opmask; 1244 const char *desc; 1245 }; 1246 1247 struct scsi_op_quirk_entry { 1248 struct scsi_inquiry_pattern inq_pat; 1249 int num_ops; 1250 struct op_table_entry *op_table; 1251 }; 1252 1253 typedef enum { 1254 SSS_FLAG_NONE = 0x00, 1255 SSS_FLAG_PRINT_COMMAND = 0x01 1256 } scsi_sense_string_flags; 1257 1258 struct ccb_scsiio; 1259 struct cam_periph; 1260 union ccb; 1261 #ifndef _KERNEL 1262 struct cam_device; 1263 #endif 1264 1265 extern const char *scsi_sense_key_text[]; 1266 1267 struct sbuf; 1268 1269 __BEGIN_DECLS 1270 void scsi_sense_desc(int sense_key, int asc, int ascq, 1271 struct scsi_inquiry_data *inq_data, 1272 const char **sense_key_desc, const char **asc_desc); 1273 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio, 1274 struct scsi_inquiry_data *inq_data, 1275 u_int32_t sense_flags); 1276 const char * scsi_status_string(struct ccb_scsiio *csio); 1277 #ifdef _KERNEL 1278 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb); 1279 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb, 1280 scsi_sense_string_flags flags); 1281 char * scsi_sense_string(struct ccb_scsiio *csio, 1282 char *str, int str_len); 1283 void scsi_sense_print(struct ccb_scsiio *csio); 1284 int scsi_interpret_sense(union ccb *ccb, 1285 u_int32_t sense_flags, 1286 u_int32_t *relsim_flags, 1287 u_int32_t *reduction, 1288 u_int32_t *timeout, 1289 scsi_sense_action error_action); 1290 #else /* _KERNEL */ 1291 int scsi_command_string(struct cam_device *device, 1292 struct ccb_scsiio *csio, struct sbuf *sb); 1293 int scsi_sense_sbuf(struct cam_device *device, 1294 struct ccb_scsiio *csio, struct sbuf *sb, 1295 scsi_sense_string_flags flags); 1296 char * scsi_sense_string(struct cam_device *device, 1297 struct ccb_scsiio *csio, 1298 char *str, int str_len); 1299 void scsi_sense_print(struct cam_device *device, 1300 struct ccb_scsiio *csio, FILE *ofile); 1301 int scsi_interpret_sense(struct cam_device *device, 1302 union ccb *ccb, 1303 u_int32_t sense_flags, 1304 u_int32_t *relsim_flags, 1305 u_int32_t *reduction, 1306 u_int32_t *timeout, 1307 scsi_sense_action error_action); 1308 #endif /* _KERNEL */ 1309 1310 #define SF_RETRY_UA 0x01 1311 #define SF_NO_PRINT 0x02 1312 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */ 1313 #define SF_PRINT_ALWAYS 0x08 1314 1315 1316 const char * scsi_op_desc(u_int16_t opcode, 1317 struct scsi_inquiry_data *inq_data); 1318 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, 1319 size_t len); 1320 1321 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data); 1322 1323 u_int scsi_calc_syncsrate(u_int period_factor); 1324 u_int scsi_calc_syncparam(u_int period); 1325 uint8_t * scsi_get_sas_addr(struct scsi_vpd_device_id *id, uint32_t len); 1326 1327 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, 1328 void (*cbfcnp)(struct cam_periph *, 1329 union ccb *), 1330 u_int8_t tag_action, 1331 u_int8_t sense_len, u_int32_t timeout); 1332 1333 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, 1334 void (*cbfcnp)(struct cam_periph *, 1335 union ccb *), 1336 void *data_ptr, u_int8_t dxfer_len, 1337 u_int8_t tag_action, u_int8_t sense_len, 1338 u_int32_t timeout); 1339 1340 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, 1341 void (*cbfcnp)(struct cam_periph *, union ccb *), 1342 u_int8_t tag_action, u_int8_t *inq_buf, 1343 u_int32_t inq_len, int evpd, u_int8_t page_code, 1344 u_int8_t sense_len, u_int32_t timeout); 1345 1346 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, 1347 void (*cbfcnp)(struct cam_periph *, 1348 union ccb *), 1349 u_int8_t tag_action, int dbd, 1350 u_int8_t page_code, u_int8_t page, 1351 u_int8_t *param_buf, u_int32_t param_len, 1352 u_int8_t sense_len, u_int32_t timeout); 1353 1354 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, 1355 void (*cbfcnp)(struct cam_periph *, 1356 union ccb *), 1357 u_int8_t tag_action, int dbd, 1358 u_int8_t page_code, u_int8_t page, 1359 u_int8_t *param_buf, u_int32_t param_len, 1360 int minimum_cmd_size, u_int8_t sense_len, 1361 u_int32_t timeout); 1362 1363 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, 1364 void (*cbfcnp)(struct cam_periph *, 1365 union ccb *), 1366 u_int8_t tag_action, int scsi_page_fmt, 1367 int save_pages, u_int8_t *param_buf, 1368 u_int32_t param_len, u_int8_t sense_len, 1369 u_int32_t timeout); 1370 1371 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries, 1372 void (*cbfcnp)(struct cam_periph *, 1373 union ccb *), 1374 u_int8_t tag_action, int scsi_page_fmt, 1375 int save_pages, u_int8_t *param_buf, 1376 u_int32_t param_len, int minimum_cmd_size, 1377 u_int8_t sense_len, u_int32_t timeout); 1378 1379 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries, 1380 void (*cbfcnp)(struct cam_periph *, union ccb *), 1381 u_int8_t tag_action, u_int8_t page_code, 1382 u_int8_t page, int save_pages, int ppc, 1383 u_int32_t paramptr, u_int8_t *param_buf, 1384 u_int32_t param_len, u_int8_t sense_len, 1385 u_int32_t timeout); 1386 1387 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries, 1388 void (*cbfcnp)(struct cam_periph *, 1389 union ccb *), u_int8_t tag_action, 1390 u_int8_t page_code, int save_pages, 1391 int pc_reset, u_int8_t *param_buf, 1392 u_int32_t param_len, u_int8_t sense_len, 1393 u_int32_t timeout); 1394 1395 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, 1396 void (*cbfcnp)(struct cam_periph *, union ccb *), 1397 u_int8_t tag_action, u_int8_t action, 1398 u_int8_t sense_len, u_int32_t timeout); 1399 1400 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, 1401 void (*cbfcnp)(struct cam_periph *, 1402 union ccb *), u_int8_t tag_action, 1403 struct scsi_read_capacity_data *, 1404 u_int8_t sense_len, u_int32_t timeout); 1405 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries, 1406 void (*cbfcnp)(struct cam_periph *, 1407 union ccb *), uint8_t tag_action, 1408 uint64_t lba, int reladr, int pmi, 1409 struct scsi_read_capacity_data_long 1410 *rcap_buf, uint8_t sense_len, 1411 uint32_t timeout); 1412 1413 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries, 1414 void (*cbfcnp)(struct cam_periph *, 1415 union ccb *), u_int8_t tag_action, 1416 u_int8_t select_report, 1417 struct scsi_report_luns_data *rpl_buf, 1418 u_int32_t alloc_len, u_int8_t sense_len, 1419 u_int32_t timeout); 1420 1421 void scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries, 1422 void (*cbfcnp)(struct cam_periph *, 1423 union ccb *), u_int8_t tag_action, 1424 u_int8_t pdf, 1425 void *buf, 1426 u_int32_t alloc_len, u_int8_t sense_len, 1427 u_int32_t timeout); 1428 1429 void scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries, 1430 void (*cbfcnp)(struct cam_periph *, 1431 union ccb *), u_int8_t tag_action, void *buf, 1432 u_int32_t alloc_len, u_int8_t sense_len, 1433 u_int32_t timeout); 1434 1435 void scsi_synchronize_cache(struct ccb_scsiio *csio, 1436 u_int32_t retries, 1437 void (*cbfcnp)(struct cam_periph *, 1438 union ccb *), u_int8_t tag_action, 1439 u_int32_t begin_lba, u_int16_t lb_count, 1440 u_int8_t sense_len, u_int32_t timeout); 1441 1442 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, 1443 void (*cbfcnp)(struct cam_periph *, union ccb *), 1444 u_int8_t tag_action, int readop, u_int8_t byte2, 1445 int minimum_cmd_size, u_int64_t lba, 1446 u_int32_t block_count, u_int8_t *data_ptr, 1447 u_int32_t dxfer_len, u_int8_t sense_len, 1448 u_int32_t timeout); 1449 1450 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, 1451 void (*cbfcnp)(struct cam_periph *, union ccb *), 1452 u_int8_t tag_action, int start, int load_eject, 1453 int immediate, u_int8_t sense_len, u_int32_t timeout); 1454 1455 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry); 1456 int scsi_static_inquiry_match(caddr_t inqbuffer, 1457 caddr_t table_entry); 1458 1459 static __inline void scsi_extract_sense(struct scsi_sense_data *sense, 1460 int *error_code, int *sense_key, 1461 int *asc, int *ascq); 1462 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes); 1463 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes); 1464 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes); 1465 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes); 1466 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes); 1467 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes); 1468 static __inline int32_t scsi_3btol(u_int8_t *bytes); 1469 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes); 1470 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes); 1471 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header); 1472 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header); 1473 1474 static __inline void scsi_extract_sense(struct scsi_sense_data *sense, 1475 int *error_code, int *sense_key, 1476 int *asc, int *ascq) 1477 { 1478 *error_code = sense->error_code & SSD_ERRCODE; 1479 *sense_key = sense->flags & SSD_KEY; 1480 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0; 1481 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0; 1482 } 1483 1484 static __inline void 1485 scsi_ulto2b(u_int32_t val, u_int8_t *bytes) 1486 { 1487 1488 bytes[0] = (val >> 8) & 0xff; 1489 bytes[1] = val & 0xff; 1490 } 1491 1492 static __inline void 1493 scsi_ulto3b(u_int32_t val, u_int8_t *bytes) 1494 { 1495 1496 bytes[0] = (val >> 16) & 0xff; 1497 bytes[1] = (val >> 8) & 0xff; 1498 bytes[2] = val & 0xff; 1499 } 1500 1501 static __inline void 1502 scsi_ulto4b(u_int32_t val, u_int8_t *bytes) 1503 { 1504 1505 bytes[0] = (val >> 24) & 0xff; 1506 bytes[1] = (val >> 16) & 0xff; 1507 bytes[2] = (val >> 8) & 0xff; 1508 bytes[3] = val & 0xff; 1509 } 1510 1511 static __inline void 1512 scsi_u64to8b(u_int64_t val, u_int8_t *bytes) 1513 { 1514 1515 bytes[0] = (val >> 56) & 0xff; 1516 bytes[1] = (val >> 48) & 0xff; 1517 bytes[2] = (val >> 40) & 0xff; 1518 bytes[3] = (val >> 32) & 0xff; 1519 bytes[4] = (val >> 24) & 0xff; 1520 bytes[5] = (val >> 16) & 0xff; 1521 bytes[6] = (val >> 8) & 0xff; 1522 bytes[7] = val & 0xff; 1523 } 1524 1525 static __inline u_int32_t 1526 scsi_2btoul(u_int8_t *bytes) 1527 { 1528 u_int32_t rv; 1529 1530 rv = (bytes[0] << 8) | 1531 bytes[1]; 1532 return (rv); 1533 } 1534 1535 static __inline u_int32_t 1536 scsi_3btoul(u_int8_t *bytes) 1537 { 1538 u_int32_t rv; 1539 1540 rv = (bytes[0] << 16) | 1541 (bytes[1] << 8) | 1542 bytes[2]; 1543 return (rv); 1544 } 1545 1546 static __inline int32_t 1547 scsi_3btol(u_int8_t *bytes) 1548 { 1549 u_int32_t rc = scsi_3btoul(bytes); 1550 1551 if (rc & 0x00800000) 1552 rc |= 0xff000000; 1553 1554 return (int32_t) rc; 1555 } 1556 1557 static __inline u_int32_t 1558 scsi_4btoul(u_int8_t *bytes) 1559 { 1560 u_int32_t rv; 1561 1562 rv = (bytes[0] << 24) | 1563 (bytes[1] << 16) | 1564 (bytes[2] << 8) | 1565 bytes[3]; 1566 return (rv); 1567 } 1568 1569 static __inline uint64_t 1570 scsi_8btou64(uint8_t *bytes) 1571 { 1572 uint64_t rv; 1573 1574 rv = (((uint64_t)bytes[0]) << 56) | 1575 (((uint64_t)bytes[1]) << 48) | 1576 (((uint64_t)bytes[2]) << 40) | 1577 (((uint64_t)bytes[3]) << 32) | 1578 (((uint64_t)bytes[4]) << 24) | 1579 (((uint64_t)bytes[5]) << 16) | 1580 (((uint64_t)bytes[6]) << 8) | 1581 bytes[7]; 1582 return (rv); 1583 } 1584 1585 /* 1586 * Given the pointer to a returned mode sense buffer, return a pointer to 1587 * the start of the first mode page. 1588 */ 1589 static __inline void * 1590 find_mode_page_6(struct scsi_mode_header_6 *mode_header) 1591 { 1592 void *page_start; 1593 1594 page_start = (void *)((u_int8_t *)&mode_header[1] + 1595 mode_header->blk_desc_len); 1596 1597 return(page_start); 1598 } 1599 1600 static __inline void * 1601 find_mode_page_10(struct scsi_mode_header_10 *mode_header) 1602 { 1603 void *page_start; 1604 1605 page_start = (void *)((u_int8_t *)&mode_header[1] + 1606 scsi_2btoul(mode_header->blk_desc_len)); 1607 1608 return(page_start); 1609 } 1610 1611 __END_DECLS 1612 1613 #endif /*_SCSI_SCSI_ALL_H*/ 1614