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.5 1998/10/15 19:08:58 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 SCSI_REV_0 0 490 #define SCSI_REV_CCS 1 491 #define SCSI_REV_2 2 492 #define SCSI_REV_3 3 493 494 #define SID_ECMA 0x38 495 #define SID_ISO 0xC0 496 u_int8_t response_format; 497 #define SID_AENC 0x80 498 #define SID_TrmIOP 0x40 499 u_int8_t additional_length; 500 u_int8_t reserved[2]; 501 u_int8_t flags; 502 #define SID_SftRe 0x01 503 #define SID_CmdQue 0x02 504 #define SID_Linked 0x08 505 #define SID_Sync 0x10 506 #define SID_WBus16 0x20 507 #define SID_WBus32 0x40 508 #define SID_RelAdr 0x80 509 #define SID_VENDOR_SIZE 8 510 char vendor[SID_VENDOR_SIZE]; 511 #define SID_PRODUCT_SIZE 16 512 char product[SID_PRODUCT_SIZE]; 513 #define SID_REVISION_SIZE 4 514 char revision[SID_REVISION_SIZE]; 515 }; 516 517 struct scsi_vpd_unit_serial_number 518 { 519 u_int8_t device; 520 u_int8_t page_code; 521 #define SVPD_UNIT_SERIAL_NUMBER 0x80 522 u_int8_t reserved; 523 u_int8_t length; /* serial number length */ 524 #define SVPD_SERIAL_NUM_SIZE 251 525 char serial_num[SVPD_SERIAL_NUM_SIZE]; 526 }; 527 528 struct scsi_read_capacity 529 { 530 u_int8_t opcode; 531 u_int8_t byte2; 532 u_int8_t addr[4]; 533 u_int8_t unused[3]; 534 u_int8_t control; 535 }; 536 537 struct scsi_read_capacity_data 538 { 539 u_int8_t addr[4]; 540 u_int8_t length[4]; 541 }; 542 543 struct scsi_sense_data 544 { 545 u_int8_t error_code; 546 #define SSD_ERRCODE 0x7F 547 #define SSD_CURRENT_ERROR 0x70 548 #define SSD_DEFERRED_ERROR 0x71 549 #define SSD_ERRCODE_VALID 0x80 550 u_int8_t segment; 551 u_int8_t flags; 552 #define SSD_KEY 0x0F 553 #define SSD_KEY_NO_SENSE 0x00 554 #define SSD_KEY_RECOVERED_ERROR 0x01 555 #define SSD_KEY_NOT_READY 0x02 556 #define SSD_KEY_MEDIUM_ERROR 0x03 557 #define SSD_KEY_HARDWARE_ERROR 0x04 558 #define SSD_KEY_ILLEGAL_REQUEST 0x05 559 #define SSD_KEY_UNIT_ATTENTION 0x06 560 #define SSD_KEY_DATA_PROTECT 0x07 561 #define SSD_KEY_BLANK_CHECK 0x08 562 #define SSD_KEY_Vendor_Specific 0x09 563 #define SSD_KEY_COPY_ABORTED 0x0a 564 #define SSD_KEY_ABORTED_COMMAND 0x0b 565 #define SSD_KEY_EQUAL 0x0c 566 #define SSD_KEY_VOLUME_OVERFLOW 0x0d 567 #define SSD_KEY_MISCOMPARE 0x0e 568 #define SSD_KEY_RESERVED 0x0f 569 #define SSD_ILI 0x20 570 #define SSD_EOM 0x40 571 #define SSD_FILEMARK 0x80 572 u_int8_t info[4]; 573 u_int8_t extra_len; 574 u_int8_t cmd_spec_info[4]; 575 u_int8_t add_sense_code; 576 u_int8_t add_sense_code_qual; 577 u_int8_t fru; 578 u_int8_t sense_key_spec[3]; 579 #define SSD_SCS_VALID 0x80 580 #define SSD_FIELDPTR_CMD 0x40 581 #define SSD_BITPTR_VALID 0x08 582 #define SSD_BITPTR_VALUE 0x07 583 #define SSD_MIN_SIZE 18 584 u_int8_t extra_bytes[14]; 585 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data) 586 }; 587 588 struct scsi_mode_header_6 589 { 590 u_int8_t data_length; /* Sense data length */ 591 u_int8_t medium_type; 592 u_int8_t dev_spec; 593 u_int8_t blk_desc_len; 594 }; 595 596 struct scsi_mode_header_10 597 { 598 u_int8_t data_length[2];/* Sense data length */ 599 u_int8_t medium_type; 600 u_int8_t dev_spec; 601 u_int8_t unused[2]; 602 u_int8_t blk_desc_len[2]; 603 }; 604 605 struct scsi_mode_blk_desc 606 { 607 u_int8_t density; 608 u_int8_t nblocks[3]; 609 u_int8_t reserved; 610 u_int8_t blklen[3]; 611 }; 612 613 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */ 614 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */ 615 /* 616 * Status Byte 617 */ 618 #define SCSI_STATUS_OK 0x00 619 #define SCSI_STATUS_CHECK_COND 0x02 620 #define SCSI_STATUS_COND_MET 0x04 621 #define SCSI_STATUS_BUSY 0x08 622 #define SCSI_STATUS_INTERMED 0x10 623 #define SCSI_STATUS_INTERMED_COND_MET 0x14 624 #define SCSI_STATUS_RESERV_CONFLICT 0x18 625 #define SCSI_STATUS_CMD_TERMINATED 0x22 626 #define SCSI_STATUS_QUEUE_FULL 0x28 627 628 struct scsi_inquiry_pattern { 629 u_int8_t type; 630 u_int8_t media_type; 631 #define SIP_MEDIA_REMOVABLE 0x01 632 #define SIP_MEDIA_FIXED 0x02 633 const char *vendor; 634 const char *product; 635 const char *revision; 636 }; 637 638 struct scsi_static_inquiry_pattern { 639 u_int8_t type; 640 u_int8_t media_type; 641 char vendor[SID_VENDOR_SIZE+1]; 642 char product[SID_PRODUCT_SIZE+1]; 643 char revision[SID_REVISION_SIZE+1]; 644 }; 645 646 struct scsi_sense_quirk_entry { 647 struct scsi_inquiry_pattern inq_pat; 648 int num_ascs; 649 struct asc_table_entry *asc_info; 650 }; 651 652 struct asc_table_entry { 653 u_int8_t asc; 654 u_int8_t ascq; 655 u_int32_t action; 656 #if !defined(SCSI_NO_SENSE_STRINGS) 657 const char *desc; 658 #endif 659 }; 660 661 struct op_table_entry { 662 u_int8_t opcode; 663 u_int16_t opmask; 664 const char *desc; 665 }; 666 667 struct scsi_op_quirk_entry { 668 struct scsi_inquiry_pattern inq_pat; 669 int num_ops; 670 struct op_table_entry *op_table; 671 }; 672 673 674 struct ccb_scsiio; 675 struct cam_periph; 676 union ccb; 677 #ifndef KERNEL 678 struct cam_device; 679 #endif 680 681 extern const char *scsi_sense_key_text[]; 682 683 __BEGIN_DECLS 684 const char * scsi_sense_desc(int asc, int ascq, 685 struct scsi_inquiry_data *inq_data); 686 scsi_sense_action scsi_error_action(int asc, int ascq, 687 struct scsi_inquiry_data *inq_data); 688 #ifdef KERNEL 689 void scsi_sense_print(struct ccb_scsiio *csio); 690 int scsi_interpret_sense(union ccb *ccb, 691 u_int32_t sense_flags, 692 u_int32_t *relsim_flags, 693 u_int32_t *reduction, 694 u_int32_t *timeout, 695 scsi_sense_action error_action); 696 #else 697 char * scsi_sense_string(struct cam_device *device, 698 struct ccb_scsiio *csio, 699 char *str, int str_len); 700 void scsi_sense_print(struct cam_device *device, 701 struct ccb_scsiio *csio, FILE *ofile); 702 int scsi_interpret_sense(struct cam_device *device, 703 union ccb *ccb, 704 u_int32_t sense_flags, 705 u_int32_t *relsim_flags, 706 u_int32_t *reduction, 707 u_int32_t *timeout, 708 scsi_sense_action error_action); 709 #endif /* KERNEL */ 710 711 #define SF_RETRY_UA 0x01 712 #define SF_NO_PRINT 0x02 713 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */ 714 #define SF_PRINT_ALWAYS 0x08 715 716 717 const char * scsi_op_desc(u_int16_t opcode, 718 struct scsi_inquiry_data *inq_data); 719 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, 720 size_t len); 721 722 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data); 723 724 u_int scsi_calc_syncsrate(u_int period_factor); 725 u_int scsi_calc_syncparam(u_int period); 726 727 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries, 728 void (*cbfcnp)(struct cam_periph *, 729 union ccb *), 730 u_int8_t tag_action, 731 u_int8_t sense_len, u_int32_t timeout); 732 733 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries, 734 void (*cbfcnp)(struct cam_periph *, 735 union ccb *), 736 void *data_ptr, u_int8_t dxfer_len, 737 u_int8_t tag_action, u_int8_t sense_len, 738 u_int32_t timeout); 739 740 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, 741 void (*cbfcnp)(struct cam_periph *, union ccb *), 742 u_int8_t tag_action, u_int8_t *inq_buf, 743 u_int32_t inq_len, int evpd, u_int8_t page_code, 744 u_int8_t sense_len, u_int32_t timeout); 745 746 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, 747 void (*cbfcnp)(struct cam_periph *, 748 union ccb *), 749 u_int8_t tag_action, int dbd, 750 u_int8_t page_code, u_int8_t page, 751 u_int8_t *param_buf, u_int32_t param_len, 752 u_int8_t sense_len, u_int32_t timeout); 753 754 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, 755 void (*cbfcnp)(struct cam_periph *, 756 union ccb *), 757 u_int8_t tag_action, int scsi_page_fmt, 758 int save_pages, u_int8_t *param_buf, 759 u_int32_t param_len, u_int8_t sense_len, 760 u_int32_t timeout); 761 762 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries, 763 void (*cbfcnp)(struct cam_periph *, 764 union ccb *), u_int8_t tag_action, 765 struct scsi_read_capacity_data *rcap_buf, 766 u_int8_t sense_len, u_int32_t timeout); 767 768 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries, 769 void (*cbfcnp)(struct cam_periph *, union ccb *), 770 u_int8_t tag_action, u_int8_t action, 771 u_int8_t sense_len, u_int32_t timeout); 772 773 void scsi_synchronize_cache(struct ccb_scsiio *csio, 774 u_int32_t retries, 775 void (*cbfcnp)(struct cam_periph *, 776 union ccb *), u_int8_t tag_action, 777 u_int32_t begin_lba, u_int16_t lb_count, 778 u_int8_t sense_len, u_int32_t timeout); 779 780 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries, 781 void (*cbfcnp)(struct cam_periph *, union ccb *), 782 u_int8_t tag_action, int readop, u_int8_t byte2, 783 int minimum_cmd_size, u_int32_t lba, 784 u_int32_t block_count, u_int8_t *data_ptr, 785 u_int32_t dxfer_len, u_int8_t sense_len, 786 u_int32_t timeout); 787 788 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries, 789 void (*cbfcnp)(struct cam_periph *, union ccb *), 790 u_int8_t tag_action, int start, int load_eject, 791 int immediate, u_int8_t sense_len, u_int32_t timeout); 792 793 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry); 794 int scsi_static_inquiry_match(caddr_t inqbuffer, 795 caddr_t table_entry); 796 797 static __inline void scsi_extract_sense(struct scsi_sense_data *sense, 798 int *error_code, int *sense_key, 799 int *asc, int *ascq); 800 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes); 801 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes); 802 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes); 803 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes); 804 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes); 805 static __inline int32_t scsi_3btol(u_int8_t *bytes); 806 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes); 807 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header); 808 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header); 809 810 static __inline void scsi_extract_sense(struct scsi_sense_data *sense, 811 int *error_code, int *sense_key, 812 int *asc, int *ascq) 813 { 814 *error_code = sense->error_code & SSD_ERRCODE; 815 *sense_key = sense->flags & SSD_KEY; 816 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0; 817 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0; 818 } 819 820 static __inline void 821 scsi_ulto2b(u_int32_t val, u_int8_t *bytes) 822 { 823 824 bytes[0] = (val >> 8) & 0xff; 825 bytes[1] = val & 0xff; 826 } 827 828 static __inline void 829 scsi_ulto3b(u_int32_t val, u_int8_t *bytes) 830 { 831 832 bytes[0] = (val >> 16) & 0xff; 833 bytes[1] = (val >> 8) & 0xff; 834 bytes[2] = val & 0xff; 835 } 836 837 static __inline void 838 scsi_ulto4b(u_int32_t val, u_int8_t *bytes) 839 { 840 841 bytes[0] = (val >> 24) & 0xff; 842 bytes[1] = (val >> 16) & 0xff; 843 bytes[2] = (val >> 8) & 0xff; 844 bytes[3] = val & 0xff; 845 } 846 847 static __inline u_int32_t 848 scsi_2btoul(u_int8_t *bytes) 849 { 850 u_int32_t rv; 851 852 rv = (bytes[0] << 8) | 853 bytes[1]; 854 return (rv); 855 } 856 857 static __inline u_int32_t 858 scsi_3btoul(u_int8_t *bytes) 859 { 860 u_int32_t rv; 861 862 rv = (bytes[0] << 16) | 863 (bytes[1] << 8) | 864 bytes[2]; 865 return (rv); 866 } 867 868 static __inline int32_t 869 scsi_3btol(u_int8_t *bytes) 870 { 871 u_int32_t rc = scsi_3btoul(bytes); 872 873 if (rc & 0x00800000) 874 rc |= 0xff000000; 875 876 return (int32_t) rc; 877 } 878 879 static __inline u_int32_t 880 scsi_4btoul(u_int8_t *bytes) 881 { 882 u_int32_t rv; 883 884 rv = (bytes[0] << 24) | 885 (bytes[1] << 16) | 886 (bytes[2] << 8) | 887 bytes[3]; 888 return (rv); 889 } 890 891 /* 892 * Given the pointer to a returned mode sense buffer, return a pointer to 893 * the start of the first mode page. 894 */ 895 static __inline void * 896 find_mode_page_6(struct scsi_mode_header_6 *mode_header) 897 { 898 void *page_start; 899 900 page_start = (void *)((u_int8_t *)&mode_header[1] + 901 mode_header->blk_desc_len); 902 903 return(page_start); 904 } 905 906 static __inline void * 907 find_mode_page_10(struct scsi_mode_header_10 *mode_header) 908 { 909 void *page_start; 910 911 page_start = (void *)((u_int8_t *)&mode_header[1] + 912 scsi_2btoul(mode_header->blk_desc_len)); 913 914 return(page_start); 915 } 916 917 __END_DECLS 918 919 #endif /*_SCSI_SCSI_ALL_H*/ 920