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 * $Id: scsi_all.h,v 1.4 1998/10/02 05:25:49 ken Exp $ 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 /* 30 * SCSI command format 31 */ 32 33 /* 34 * Define dome bits that are in ALL (or a lot of) scsi commands 35 */ 36 #define SCSI_CTL_LINK 0x01 37 #define SCSI_CTL_FLAG 0x02 38 #define SCSI_CTL_VENDOR 0xC0 39 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */ 40 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */ 41 42 #define SCSI_MAX_CDBLEN 16 /* 43 * 16 byte commands are in the 44 * SCSI-3 spec 45 */ 46 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN) 47 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN" 48 #endif 49 50 /* 51 * This type defines actions to be taken when a particular sense code is 52 * received. Right now, these flags are only defined to take up 16 bits, 53 * but can be expanded in the future if necessary. 54 */ 55 typedef enum { 56 SS_NOP = 0x000000, /* Do nothing */ 57 SS_RETRY = 0x010000, /* Retry the command */ 58 SS_FAIL = 0x020000, /* Bail out */ 59 SS_START = 0x030000, /* Send a Start Unit command to the device, 60 * then retry the original command. 61 */ 62 SS_TUR = 0x040000, /* Send a Test Unit Ready command to the 63 * device, then retry the original command. 64 */ 65 SS_MANUAL = 0x050000, /* 66 * This error must be handled manually, 67 * i.e. the code must look at the asc and 68 * ascq values and determine the proper 69 * course of action. 70 */ 71 SS_TURSTART = 0x060000, /* 72 * Send a Test Unit Ready command to the 73 * device, and if that fails, send a start 74 * unit. 75 */ 76 SS_MASK = 0xff0000 77 } scsi_sense_action; 78 79 typedef enum { 80 SSQ_NONE = 0x0000, 81 SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */ 82 SSQ_MANY = 0x0200, /* send lots of recovery commands */ 83 SSQ_RANGE = 0x0400, /* 84 * Yes, this is a hack. Basically, 85 * if this flag is set then it 86 * represents an ascq range. The 87 * "correct" way to implement the 88 * ranges might be to add a special 89 * field to the sense code table, 90 * but that would take up a lot of 91 * additional space. This solution 92 * isn't as elegant, but is more 93 * space efficient. 94 */ 95 SSQ_PRINT_SENSE = 0x0800, 96 SSQ_MASK = 0xff00 97 } scsi_sense_action_qualifier; 98 99 /* Mask for error status values */ 100 #define SS_ERRMASK 0xff 101 102 /* The default error action */ 103 #define SS_DEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO 104 105 /* Default error action, without an error return value */ 106 #define SS_NEDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE 107 108 /* Default error action, without sense printing or an error return value */ 109 #define SS_NEPDEF SS_RETRY|SSQ_DECREMENT_COUNT 110 111 struct scsi_generic 112 { 113 u_int8_t opcode; 114 u_int8_t bytes[11]; 115 }; 116 117 struct scsi_request_sense 118 { 119 u_int8_t opcode; 120 u_int8_t byte2; 121 u_int8_t unused[2]; 122 u_int8_t length; 123 u_int8_t control; 124 }; 125 126 struct scsi_test_unit_ready 127 { 128 u_int8_t opcode; 129 u_int8_t byte2; 130 u_int8_t unused[3]; 131 u_int8_t control; 132 }; 133 134 struct scsi_send_diag 135 { 136 u_int8_t opcode; 137 u_int8_t byte2; 138 #define SSD_UOL 0x01 139 #define SSD_DOL 0x02 140 #define SSD_SELFTEST 0x04 141 #define SSD_PF 0x10 142 u_int8_t unused[1]; 143 u_int8_t paramlen[2]; 144 u_int8_t control; 145 }; 146 147 struct scsi_sense 148 { 149 u_int8_t opcode; 150 u_int8_t byte2; 151 u_int8_t unused[2]; 152 u_int8_t length; 153 u_int8_t control; 154 }; 155 156 struct scsi_inquiry 157 { 158 u_int8_t opcode; 159 u_int8_t byte2; 160 #define SI_EVPD 0x01 161 u_int8_t page_code; 162 u_int8_t reserved; 163 u_int8_t length; 164 u_int8_t control; 165 }; 166 167 struct scsi_mode_sense_6 168 { 169 u_int8_t opcode; 170 u_int8_t byte2; 171 #define SMS_DBD 0x08 172 u_int8_t page; 173 #define SMS_PAGE_CODE 0x3F 174 #define SMS_VENDOR_SPECIFIC_PAGE 0x00 175 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02 176 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09 177 #define SMS_CONTROL_MODE_PAGE 0x0A 178 #define SMS_ALL_PAGES_PAGE 0x3F 179 #define SMS_PAGE_CTRL_MASK 0xC0 180 #define SMS_PAGE_CTRL_CURRENT 0x00 181 #define SMS_PAGE_CTRL_CHANGEABLE 0x40 182 #define SMS_PAGE_CTRL_DEFAULT 0x80 183 #define SMS_PAGE_CTRL_SAVED 0xC0 184 u_int8_t unused; 185 u_int8_t length; 186 u_int8_t control; 187 }; 188 189 struct scsi_mode_sense_10 190 { 191 u_int8_t opcode; 192 u_int8_t byte2; /* same bits as small version */ 193 u_int8_t page; /* same bits as small version */ 194 u_int8_t unused[4]; 195 u_int8_t length[2]; 196 u_int8_t control; 197 }; 198 199 struct scsi_mode_select_6 200 { 201 u_int8_t opcode; 202 u_int8_t byte2; 203 #define SMS_SP 0x01 204 #define SMS_PF 0x10 205 u_int8_t unused[2]; 206 u_int8_t length; 207 u_int8_t control; 208 }; 209 210 struct scsi_mode_select_10 211 { 212 u_int8_t opcode; 213 u_int8_t byte2; /* same bits as small version */ 214 u_int8_t unused[5]; 215 u_int8_t length[2]; 216 u_int8_t control; 217 }; 218 219 /* 220 * When sending a mode select to a tape drive, the medium type must be 0. 221 */ 222 struct scsi_mode_hdr_6 223 { 224 u_int8_t datalen; 225 u_int8_t medium_type; 226 u_int8_t dev_specific; 227 u_int8_t block_descr_len; 228 }; 229 230 struct scsi_mode_hdr_10 231 { 232 u_int8_t datalen[2]; 233 u_int8_t medium_type; 234 u_int8_t dev_specific; 235 u_int8_t reserved[2]; 236 u_int8_t block_descr_len[2]; 237 }; 238 239 struct scsi_mode_block_descr 240 { 241 u_int8_t density_code; 242 u_int8_t num_blocks[3]; 243 u_int8_t reserved; 244 u_int8_t block_len[3]; 245 }; 246 247 struct scsi_control_page { 248 u_int8_t page_code; 249 u_int8_t page_length; 250 u_int8_t rlec; 251 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/ 252 u_int8_t queue_flags; 253 #define SCP_QUEUE_ALG_MASK 0xF0 254 #define SCP_QUEUE_ALG_RESTRICTED 0x00 255 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10 256 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/ 257 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/ 258 u_int8_t eca_and_aen; 259 #define SCP_EECA 0x80 /*Enable Extended CA*/ 260 #define SCP_RAENP 0x04 /*Ready AEN Permission*/ 261 #define SCP_UAAENP 0x02 /*UA AEN Permission*/ 262 #define SCP_EAENP 0x01 /*Error AEN Permission*/ 263 u_int8_t reserved; 264 u_int8_t aen_holdoff_period[2]; 265 }; 266 267 struct scsi_reserve 268 { 269 u_int8_t opcode; 270 u_int8_t byte2; 271 u_int8_t unused[2]; 272 u_int8_t length; 273 u_int8_t control; 274 }; 275 276 struct scsi_release 277 { 278 u_int8_t opcode; 279 u_int8_t byte2; 280 u_int8_t unused[2]; 281 u_int8_t length; 282 u_int8_t control; 283 }; 284 285 struct scsi_prevent 286 { 287 u_int8_t opcode; 288 u_int8_t byte2; 289 u_int8_t unused[2]; 290 u_int8_t how; 291 u_int8_t control; 292 }; 293 #define PR_PREVENT 0x01 294 #define PR_ALLOW 0x00 295 296 struct scsi_sync_cache 297 { 298 u_int8_t opcode; 299 u_int8_t byte2; 300 u_int8_t begin_lba[4]; 301 u_int8_t reserved; 302 u_int8_t lb_count[2]; 303 u_int8_t control; 304 }; 305 306 307 struct scsi_changedef 308 { 309 u_int8_t opcode; 310 u_int8_t byte2; 311 u_int8_t unused1; 312 u_int8_t how; 313 u_int8_t unused[4]; 314 u_int8_t datalen; 315 u_int8_t control; 316 }; 317 318 struct scsi_read_buffer 319 { 320 u_int8_t opcode; 321 u_int8_t byte2; 322 #define RWB_MODE 0x07 323 #define RWB_MODE_HDR_DATA 0x00 324 #define RWB_MODE_DATA 0x02 325 #define RWB_MODE_DOWNLOAD 0x04 326 #define RWB_MODE_DOWNLOAD_SAVE 0x05 327 u_int8_t buffer_id; 328 u_int8_t offset[3]; 329 u_int8_t length[3]; 330 u_int8_t control; 331 }; 332 333 struct scsi_write_buffer 334 { 335 u_int8_t opcode; 336 u_int8_t byte2; 337 u_int8_t buffer_id; 338 u_int8_t offset[3]; 339 u_int8_t length[3]; 340 u_int8_t control; 341 }; 342 343 struct scsi_rw_6 344 { 345 u_int8_t opcode; 346 u_int8_t addr[3]; 347 /* only 5 bits are valid in the MSB address byte */ 348 #define SRW_TOPADDR 0x1F 349 u_int8_t length; 350 u_int8_t control; 351 }; 352 353 struct scsi_rw_10 354 { 355 u_int8_t opcode; 356 #define SRW10_RELADDR 0x01 357 #define SRW10_FUA 0x08 358 #define SRW10_DPO 0x10 359 u_int8_t byte2; 360 u_int8_t addr[4]; 361 u_int8_t reserved; 362 u_int8_t length[2]; 363 u_int8_t control; 364 }; 365 366 struct scsi_rw_12 367 { 368 u_int8_t opcode; 369 #define SRW12_RELADDR 0x01 370 #define SRW12_FUA 0x08 371 #define SRW12_DPO 0x10 372 u_int8_t byte2; 373 u_int8_t addr[4]; 374 u_int8_t reserved; 375 u_int8_t length[4]; 376 u_int8_t control; 377 }; 378 379 struct scsi_start_stop_unit 380 { 381 u_int8_t opcode; 382 u_int8_t byte2; 383 #define SSS_IMMED 0x01 384 u_int8_t reserved[2]; 385 u_int8_t how; 386 #define SSS_START 0x01 387 #define SSS_LOEJ 0x02 388 u_int8_t control; 389 }; 390 391 #define SC_SCSI_1 0x01 392 #define SC_SCSI_2 0x03 393 394 /* 395 * Opcodes 396 */ 397 398 #define TEST_UNIT_READY 0x00 399 #define REQUEST_SENSE 0x03 400 #define READ_6 0x08 401 #define WRITE_6 0x0a 402 #define INQUIRY 0x12 403 #define MODE_SELECT_6 0x15 404 #define MODE_SENSE_6 0x1a 405 #define START_STOP_UNIT 0x1b 406 #define START_STOP 0x1b 407 #define RESERVE 0x16 408 #define RELEASE 0x17 409 #define PREVENT_ALLOW 0x1e 410 #define READ_CAPACITY 0x25 411 #define READ_10 0x28 412 #define WRITE_10 0x2a 413 #define POSITION_TO_ELEMENT 0x2b 414 #define SYNCHRONIZE_CACHE 0x35 415 #define WRITE_BUFFER 0x3b 416 #define READ_BUFFER 0x3c 417 #define CHANGE_DEFINITION 0x40 418 #define MODE_SELECT_10 0x55 419 #define MODE_SENSE_10 0x5A 420 #define MOVE_MEDIUM 0xa5 421 #define READ_12 0xa8 422 #define WRITE_12 0xaa 423 #define READ_ELEMENT_STATUS 0xb8 424 425 426 /* 427 * Device Types 428 */ 429 #define T_DIRECT 0x00 430 #define T_SEQUENTIAL 0x01 431 #define T_PRINTER 0x02 432 #define T_PROCESSOR 0x03 433 #define T_WORM 0x04 434 #define T_CDROM 0x05 435 #define T_SCANNER 0x06 436 #define T_OPTICAL 0x07 437 #define T_CHANGER 0x08 438 #define T_COMM 0x09 439 #define T_ASC0 0x0a 440 #define T_ASC1 0x0b 441 #define T_STORARRAY 0x0c 442 #define T_ENCLOSURE 0x0d 443 #define T_NODEVICE 0x1F 444 #define T_ANY 0xFF /* Used in Quirk table matches */ 445 446 #define T_REMOV 1 447 #define T_FIXED 0 448 449 struct scsi_inquiry_data 450 { 451 u_int8_t device; 452 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f) 453 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5) 454 #define SID_QUAL_LU_CONNECTED 0x00 /* The specified peripheral device 455 * type is currently connected to 456 * logical unit. If the target cannot 457 * determine whether or not a physical 458 * device is currently connected, it 459 * shall also use this peripheral 460 * qualifier when returning the INQUIRY 461 * data. This peripheral qualifier 462 * does not mean that the device is 463 * ready for access by the initiator. 464 */ 465 #define SID_QUAL_LU_OFFLINE 0x01 /* The target is capable of supporting 466 * the specified peripheral device type 467 * on this logical unit; however, the 468 * physical device is not currently 469 * connected to this logical unit. 470 */ 471 #define SID_QUAL_RSVD 0x02 472 #define SID_QUAL_BAD_LU 0x03 /* The target is not capable of 473 * supporting a physical device on 474 * this logical unit. For this 475 * peripheral qualifier the peripheral 476 * device type shall be set to 1Fh to 477 * provide compatibility with previous 478 * versions of SCSI. All other 479 * peripheral device type values are 480 * reserved for this peripheral 481 * qualifier. 482 */ 483 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0) 484 u_int8_t dev_qual2; 485 #define SID_QUAL2 0x7F 486 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0) 487 u_int8_t version; 488 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07) 489 #define SID_ECMA 0x38 490 #define SID_ISO 0xC0 491 u_int8_t response_format; 492 #define SID_AENC 0x80 493 #define SID_TrmIOP 0x40 494 u_int8_t additional_length; 495 u_int8_t reserved[2]; 496 u_int8_t flags; 497 #define SID_SftRe 0x01 498 #define SID_CmdQue 0x02 499 #define SID_Linked 0x08 500 #define SID_Sync 0x10 501 #define SID_WBus16 0x20 502 #define SID_WBus32 0x40 503 #define SID_RelAdr 0x80 504 #define SID_VENDOR_SIZE 8 505 char vendor[SID_VENDOR_SIZE]; 506 #define SID_PRODUCT_SIZE 16 507 char product[SID_PRODUCT_SIZE]; 508 #define SID_REVISION_SIZE 4 509 char revision[SID_REVISION_SIZE]; 510 }; 511 512 struct scsi_vpd_unit_serial_number 513 { 514 u_int8_t device; 515 u_int8_t page_code; 516 #define SVPD_UNIT_SERIAL_NUMBER 0x80 517 u_int8_t reserved; 518 u_int8_t length; /* serial number length */ 519 #define SVPD_SERIAL_NUM_SIZE 251 520 char serial_num[SVPD_SERIAL_NUM_SIZE]; 521 }; 522 523 struct scsi_read_capacity 524 { 525 u_int8_t opcode; 526 u_int8_t byte2; 527 u_int8_t addr[4]; 528 u_int8_t unused[3]; 529 u_int8_t control; 530 }; 531 532 struct scsi_read_capacity_data 533 { 534 u_int8_t addr[4]; 535 u_int8_t length[4]; 536 }; 537 538 struct scsi_sense_data 539 { 540 u_int8_t error_code; 541 #define SSD_ERRCODE 0x7F 542 #define SSD_CURRENT_ERROR 0x70 543 #define SSD_DEFERRED_ERROR 0x71 544 #define SSD_ERRCODE_VALID 0x80 545 u_int8_t segment; 546 u_int8_t flags; 547 #define SSD_KEY 0x0F 548 #define SSD_KEY_NO_SENSE 0x00 549 #define SSD_KEY_RECOVERED_ERROR 0x01 550 #define SSD_KEY_NOT_READY 0x02 551 #define SSD_KEY_MEDIUM_ERROR 0x03 552 #define SSD_KEY_HARDWARE_ERROR 0x04 553 #define SSD_KEY_ILLEGAL_REQUEST 0x05 554 #define SSD_KEY_UNIT_ATTENTION 0x06 555 #define SSD_KEY_DATA_PROTECT 0x07 556 #define SSD_KEY_BLANK_CHECK 0x08 557 #define SSD_KEY_Vendor_Specific 0x09 558 #define SSD_KEY_COPY_ABORTED 0x0a 559 #define SSD_KEY_ABORTED_COMMAND 0x0b 560 #define SSD_KEY_EQUAL 0x0c 561 #define SSD_KEY_VOLUME_OVERFLOW 0x0d 562 #define SSD_KEY_MISCOMPARE 0x0e 563 #define SSD_KEY_RESERVED 0x0f 564 #define SSD_ILI 0x20 565 #define SSD_EOM 0x40 566 #define SSD_FILEMARK 0x80 567 u_int8_t info[4]; 568 u_int8_t extra_len; 569 u_int8_t cmd_spec_info[4]; 570 u_int8_t add_sense_code; 571 u_int8_t add_sense_code_qual; 572 u_int8_t fru; 573 u_int8_t sense_key_spec[3]; 574 #define SSD_SCS_VALID 0x80 575 #define SSD_FIELDPTR_CMD 0x40 576 #define SSD_BITPTR_VALID 0x08 577 #define SSD_BITPTR_VALUE 0x07 578 #define SSD_MIN_SIZE 18 579 u_int8_t extra_bytes[14]; 580 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data) 581 }; 582 583 struct scsi_mode_header_6 584 { 585 u_int8_t data_length; /* Sense data length */ 586 u_int8_t medium_type; 587 u_int8_t dev_spec; 588 u_int8_t blk_desc_len; 589 }; 590 591 struct scsi_mode_header_10 592 { 593 u_int8_t data_length[2];/* Sense data length */ 594 u_int8_t medium_type; 595 u_int8_t dev_spec; 596 u_int8_t unused[2]; 597 u_int8_t blk_desc_len[2]; 598 }; 599 600 struct scsi_mode_blk_desc 601 { 602 u_int8_t density; 603 u_int8_t nblocks[3]; 604 u_int8_t reserved; 605 u_int8_t blklen[3]; 606 }; 607 608 /* 609 * Status Byte 610 */ 611 #define SCSI_STATUS_OK 0x00 612 #define SCSI_STATUS_CHECK_COND 0x02 613 #define SCSI_STATUS_COND_MET 0x04 614 #define SCSI_STATUS_BUSY 0x08 615 #define SCSI_STATUS_INTERMED 0x10 616 #define SCSI_STATUS_INTERMED_COND_MET 0x14 617 #define SCSI_STATUS_RESERV_CONFLICT 0x18 618 #define SCSI_STATUS_CMD_TERMINATED 0x22 619 #define SCSI_STATUS_QUEUE_FULL 0x28 620 621 struct scsi_inquiry_pattern { 622 u_int8_t type; 623 u_int8_t media_type; 624 #define SIP_MEDIA_REMOVABLE 0x01 625 #define SIP_MEDIA_FIXED 0x02 626 const char *vendor; 627 const char *product; 628 const char *revision; 629 }; 630 631 struct scsi_static_inquiry_pattern { 632 u_int8_t type; 633 u_int8_t media_type; 634 char vendor[SID_VENDOR_SIZE+1]; 635 char product[SID_PRODUCT_SIZE+1]; 636 char revision[SID_REVISION_SIZE+1]; 637 }; 638 639 struct scsi_sense_quirk_entry { 640 struct scsi_inquiry_pattern inq_pat; 641 int num_ascs; 642 struct asc_table_entry *asc_info; 643 }; 644 645 struct asc_table_entry { 646 u_int8_t asc; 647 u_int8_t ascq; 648 u_int32_t action; 649 #if !defined(SCSI_NO_SENSE_STRINGS) 650 const char *desc; 651 #endif 652 }; 653 654 struct op_table_entry { 655 u_int8_t opcode; 656 u_int16_t opmask; 657 const char *desc; 658 }; 659 660 struct scsi_op_quirk_entry { 661 struct scsi_inquiry_pattern inq_pat; 662 int num_ops; 663 struct op_table_entry *op_table; 664 }; 665 666 667 struct ccb_scsiio; 668 struct cam_periph; 669 union ccb; 670 #ifndef KERNEL 671 struct cam_device; 672 #endif 673 674 extern const char *scsi_sense_key_text[]; 675 676 __BEGIN_DECLS 677 const char * scsi_sense_desc(int asc, int ascq, 678 struct scsi_inquiry_data *inq_data); 679 scsi_sense_action scsi_error_action(int asc, int ascq, 680 struct scsi_inquiry_data *inq_data); 681 #ifdef KERNEL 682 void scsi_sense_print(struct ccb_scsiio *csio); 683 int scsi_interpret_sense(union ccb *ccb, 684 u_int32_t sense_flags, 685 u_int32_t *relsim_flags, 686 u_int32_t *reduction, 687 u_int32_t *timeout, 688 scsi_sense_action error_action); 689 #else 690 char * scsi_sense_string(struct cam_device *device, 691 struct ccb_scsiio *csio, 692 char *str, int str_len); 693 void scsi_sense_print(struct cam_device *device, 694 struct ccb_scsiio *csio, FILE *ofile); 695 int scsi_interpret_sense(struct cam_device *device, 696 union ccb *ccb, 697 u_int32_t sense_flags, 698 u_int32_t *relsim_flags, 699 u_int32_t *reduction, 700 u_int32_t *timeout, 701 scsi_sense_action error_action); 702 #endif /* KERNEL */ 703 704 #define SF_RETRY_UA 0x01 705 #define SF_NO_PRINT 0x02 706 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */ 707 #define SF_PRINT_ALWAYS 0x08 708 709 710 const char * scsi_op_desc(u_int16_t opcode, 711 struct scsi_inquiry_data *inq_data); 712 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, 713 size_t len); 714 715 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data); 716 717 u_int scsi_calc_syncsrate(u_int period_factor); 718 u_int scsi_calc_syncparam(u_int period); 719 720 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, 721 void (*cbfcnp)(struct cam_periph *, 722 union ccb *), 723 u_int8_t tag_action, 724 u_int8_t sense_len, u_int32_t timeout); 725 726 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, 727 void (*cbfcnp)(struct cam_periph *, 728 union ccb *), 729 void *data_ptr, u_int8_t dxfer_len, 730 u_int8_t tag_action, u_int8_t sense_len, 731 u_int32_t timeout); 732 733 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, 734 void (*cbfcnp)(struct cam_periph *, union ccb *), 735 u_int8_t tag_action, u_int8_t *inq_buf, 736 u_int32_t inq_len, int evpd, u_int8_t page_code, 737 u_int8_t sense_len, u_int32_t timeout); 738 739 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, 740 void (*cbfcnp)(struct cam_periph *, 741 union ccb *), 742 u_int8_t tag_action, int dbd, 743 u_int8_t page_code, u_int8_t page, 744 u_int8_t *param_buf, u_int32_t param_len, 745 u_int8_t sense_len, u_int32_t timeout); 746 747 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, 748 void (*cbfcnp)(struct cam_periph *, 749 union ccb *), 750 u_int8_t tag_action, int scsi_page_fmt, 751 int save_pages, u_int8_t *param_buf, 752 u_int32_t param_len, u_int8_t sense_len, 753 u_int32_t timeout); 754 755 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, 756 void (*cbfcnp)(struct cam_periph *, 757 union ccb *), u_int8_t tag_action, 758 struct scsi_read_capacity_data *rcap_buf, 759 u_int8_t sense_len, u_int32_t timeout); 760 761 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, 762 void (*cbfcnp)(struct cam_periph *, union ccb *), 763 u_int8_t tag_action, u_int8_t action, 764 u_int8_t sense_len, u_int32_t timeout); 765 766 void scsi_synchronize_cache(struct ccb_scsiio *csio, 767 u_int32_t retries, 768 void (*cbfcnp)(struct cam_periph *, 769 union ccb *), u_int8_t tag_action, 770 u_int32_t begin_lba, u_int16_t lb_count, 771 u_int8_t sense_len, u_int32_t timeout); 772 773 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, 774 void (*cbfcnp)(struct cam_periph *, union ccb *), 775 u_int8_t tag_action, int readop, u_int8_t byte2, 776 int minimum_cmd_size, u_int32_t lba, 777 u_int32_t block_count, u_int8_t *data_ptr, 778 u_int32_t dxfer_len, u_int8_t sense_len, 779 u_int32_t timeout); 780 781 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, 782 void (*cbfcnp)(struct cam_periph *, union ccb *), 783 u_int8_t tag_action, int start, int load_eject, 784 int immediate, u_int8_t sense_len, u_int32_t timeout); 785 786 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry); 787 int scsi_static_inquiry_match(caddr_t inqbuffer, 788 caddr_t table_entry); 789 790 static __inline void scsi_extract_sense(struct scsi_sense_data *sense, 791 int *error_code, int *sense_key, 792 int *asc, int *ascq); 793 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes); 794 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes); 795 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes); 796 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes); 797 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes); 798 static __inline int32_t scsi_3btol(u_int8_t *bytes); 799 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes); 800 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header); 801 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header); 802 803 static __inline void scsi_extract_sense(struct scsi_sense_data *sense, 804 int *error_code, int *sense_key, 805 int *asc, int *ascq) 806 { 807 *error_code = sense->error_code & SSD_ERRCODE; 808 *sense_key = sense->flags & SSD_KEY; 809 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0; 810 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0; 811 } 812 813 static __inline void 814 scsi_ulto2b(u_int32_t val, u_int8_t *bytes) 815 { 816 817 bytes[0] = (val >> 8) & 0xff; 818 bytes[1] = val & 0xff; 819 } 820 821 static __inline void 822 scsi_ulto3b(u_int32_t val, u_int8_t *bytes) 823 { 824 825 bytes[0] = (val >> 16) & 0xff; 826 bytes[1] = (val >> 8) & 0xff; 827 bytes[2] = val & 0xff; 828 } 829 830 static __inline void 831 scsi_ulto4b(u_int32_t val, u_int8_t *bytes) 832 { 833 834 bytes[0] = (val >> 24) & 0xff; 835 bytes[1] = (val >> 16) & 0xff; 836 bytes[2] = (val >> 8) & 0xff; 837 bytes[3] = val & 0xff; 838 } 839 840 static __inline u_int32_t 841 scsi_2btoul(u_int8_t *bytes) 842 { 843 u_int32_t rv; 844 845 rv = (bytes[0] << 8) | 846 bytes[1]; 847 return (rv); 848 } 849 850 static __inline u_int32_t 851 scsi_3btoul(u_int8_t *bytes) 852 { 853 u_int32_t rv; 854 855 rv = (bytes[0] << 16) | 856 (bytes[1] << 8) | 857 bytes[2]; 858 return (rv); 859 } 860 861 static __inline int32_t 862 scsi_3btol(u_int8_t *bytes) 863 { 864 u_int32_t rc = scsi_3btoul(bytes); 865 866 if (rc & 0x00800000) 867 rc |= 0xff000000; 868 869 return (int32_t) rc; 870 } 871 872 static __inline u_int32_t 873 scsi_4btoul(u_int8_t *bytes) 874 { 875 u_int32_t rv; 876 877 rv = (bytes[0] << 24) | 878 (bytes[1] << 16) | 879 (bytes[2] << 8) | 880 bytes[3]; 881 return (rv); 882 } 883 884 /* 885 * Given the pointer to a returned mode sense buffer, return a pointer to 886 * the start of the first mode page. 887 */ 888 static __inline void * 889 find_mode_page_6(struct scsi_mode_header_6 *mode_header) 890 { 891 void *page_start; 892 893 page_start = (void *)((u_int8_t *)&mode_header[1] + 894 mode_header->blk_desc_len); 895 896 return(page_start); 897 } 898 899 static __inline void * 900 find_mode_page_10(struct scsi_mode_header_10 *mode_header) 901 { 902 void *page_start; 903 904 page_start = (void *)((u_int8_t *)&mode_header[1] + 905 scsi_2btoul(mode_header->blk_desc_len)); 906 907 return(page_start); 908 } 909 910 __END_DECLS 911 912 #endif /*_SCSI_SCSI_ALL_H*/ 913