2 * Largely written by Julian Elischer (julian@tfs.com)
3 * for TRW Financial Systems.
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.
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.
15 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
17 * $FreeBSD: src/sys/cam/scsi/scsi_all.h,v 1.14.2.5 2003/08/24 03:26:37 ken Exp $
18 * $DragonFly: src/sys/bus/cam/scsi/scsi_all.h,v 1.12 2007/12/02 03:41:58 pavalos Exp $
22 * SCSI general interface description
25 #ifndef _SCSI_SCSI_ALL_H
26 #define _SCSI_SCSI_ALL_H 1
29 #include <sys/cdefs.h>
31 #if !defined(_KERNEL) && !defined(_STDIO_H_)
32 #include <stdio.h> /* FILE for userland protos */
37 * This is the number of seconds we wait for devices to settle after a SCSI
40 extern int scsi_delay
;
48 * Define dome bits that are in ALL (or a lot of) scsi commands
50 #define SCSI_CTL_LINK 0x01
51 #define SCSI_CTL_FLAG 0x02
52 #define SCSI_CTL_VENDOR 0xC0
53 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */
54 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */
56 #define SCSI_MAX_CDBLEN 16 /*
57 * 16 byte commands are in the
60 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN)
61 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN"
64 /* 6byte CDBs special case 0 length to be 256 */
65 #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len)
68 * This type defines actions to be taken when a particular sense code is
69 * received. Right now, these flags are only defined to take up 16 bits,
70 * but can be expanded in the future if necessary.
73 SS_NOP
= 0x000000, /* Do nothing */
74 SS_RETRY
= 0x010000, /* Retry the command */
75 SS_FAIL
= 0x020000, /* Bail out */
76 SS_START
= 0x030000, /* Send a Start Unit command to the device,
77 * then retry the original command.
79 SS_TUR
= 0x040000, /* Send a Test Unit Ready command to the
80 * device, then retry the original command.
82 SS_REQSENSE
= 0x050000, /* Send a RequestSense command to the
83 * device, then retry the original command.
90 SSQ_DECREMENT_COUNT
= 0x0100, /* Decrement the retry count */
91 SSQ_MANY
= 0x0200, /* send lots of recovery commands */
92 SSQ_RANGE
= 0x0400, /*
93 * This table entry represents the
94 * end of a range of ASCQs that
95 * have identical error actions
98 SSQ_PRINT_SENSE
= 0x0800,
100 } scsi_sense_action_qualifier
;
102 /* Mask for error status values */
103 #define SS_ERRMASK 0xff
105 /* The default, retyable, error action */
106 #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
108 /* The retyable, error action, with table specified error code */
109 #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
111 /* Fatal error action, with table specified error code */
112 #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE
120 struct scsi_request_sense
129 struct scsi_test_unit_ready
137 struct scsi_send_diag
143 #define SSD_SELFTEST 0x04
146 u_int8_t paramlen
[2];
170 struct scsi_mode_sense_6
176 #define SMS_PAGE_CODE 0x3F
177 #define SMS_VENDOR_SPECIFIC_PAGE 0x00
178 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02
179 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
180 #define SMS_CONTROL_MODE_PAGE 0x0A
181 #define SMS_ALL_PAGES_PAGE 0x3F
182 #define SMS_PAGE_CTRL_MASK 0xC0
183 #define SMS_PAGE_CTRL_CURRENT 0x00
184 #define SMS_PAGE_CTRL_CHANGEABLE 0x40
185 #define SMS_PAGE_CTRL_DEFAULT 0x80
186 #define SMS_PAGE_CTRL_SAVED 0xC0
192 struct scsi_mode_sense_10
195 u_int8_t byte2
; /* same bits as small version */
196 u_int8_t page
; /* same bits as small version */
202 struct scsi_mode_select_6
213 struct scsi_mode_select_10
216 u_int8_t byte2
; /* same bits as small version */
223 * When sending a mode select to a tape drive, the medium type must be 0.
225 struct scsi_mode_hdr_6
228 u_int8_t medium_type
;
229 u_int8_t dev_specific
;
230 u_int8_t block_descr_len
;
233 struct scsi_mode_hdr_10
236 u_int8_t medium_type
;
237 u_int8_t dev_specific
;
238 u_int8_t reserved
[2];
239 u_int8_t block_descr_len
[2];
242 struct scsi_mode_block_descr
244 u_int8_t density_code
;
245 u_int8_t num_blocks
[3];
247 u_int8_t block_len
[3];
250 struct scsi_log_sense
257 #define SLS_PAGE_CODE 0x3F
258 #define SLS_ALL_PAGES_PAGE 0x00
259 #define SLS_OVERRUN_PAGE 0x01
260 #define SLS_ERROR_WRITE_PAGE 0x02
261 #define SLS_ERROR_READ_PAGE 0x03
262 #define SLS_ERROR_READREVERSE_PAGE 0x04
263 #define SLS_ERROR_VERIFY_PAGE 0x05
264 #define SLS_ERROR_NONMEDIUM_PAGE 0x06
265 #define SLS_ERROR_LASTN_PAGE 0x07
266 #define SLS_PAGE_CTRL_MASK 0xC0
267 #define SLS_PAGE_CTRL_THRESHOLD 0x00
268 #define SLS_PAGE_CTRL_CUMULATIVE 0x40
269 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
270 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
271 u_int8_t reserved
[2];
272 u_int8_t paramptr
[2];
277 struct scsi_log_select
284 /* SLS_PAGE_CTRL_MASK 0xC0 */
285 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */
286 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
287 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
288 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
289 u_int8_t reserved
[4];
294 struct scsi_log_header
301 struct scsi_log_param_header
{
302 u_int8_t param_code
[2];
303 u_int8_t param_control
;
305 #define SLP_LBIN 0x02
306 #define SLP_TMC_MASK 0x0C
307 #define SLP_TMC_ALWAYS 0x00
308 #define SLP_TMC_EQUAL 0x04
309 #define SLP_TMC_NOTEQUAL 0x08
310 #define SLP_TMC_GREATER 0x0C
318 struct scsi_control_page
{
320 u_int8_t page_length
;
322 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
323 u_int8_t queue_flags
;
324 #define SCP_QUEUE_ALG_MASK 0xF0
325 #define SCP_QUEUE_ALG_RESTRICTED 0x00
326 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
327 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
328 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
329 u_int8_t eca_and_aen
;
330 #define SCP_EECA 0x80 /*Enable Extended CA*/
331 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
332 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
333 #define SCP_EAENP 0x01 /*Error AEN Permission*/
335 u_int8_t aen_holdoff_period
[2];
364 #define PR_PREVENT 0x01
365 #define PR_ALLOW 0x00
367 struct scsi_sync_cache
371 u_int8_t begin_lba
[4];
373 u_int8_t lb_count
[2];
378 struct scsi_changedef
389 struct scsi_read_buffer
393 #define RWB_MODE 0x07
394 #define RWB_MODE_HDR_DATA 0x00
395 #define RWB_MODE_DATA 0x02
396 #define RWB_MODE_DOWNLOAD 0x04
397 #define RWB_MODE_DOWNLOAD_SAVE 0x05
404 struct scsi_write_buffer
418 /* only 5 bits are valid in the MSB address byte */
419 #define SRW_TOPADDR 0x1F
427 #define SRW10_RELADDR 0x01
428 /* EBP defined for WRITE(10) only */
429 #define SRW10_EBP 0x04
430 #define SRW10_FUA 0x08
431 #define SRW10_DPO 0x10
442 #define SRW12_RELADDR 0x01
443 #define SRW12_FUA 0x08
444 #define SRW12_DPO 0x10
455 #define SRW16_RELADDR 0x01
456 #define SRW16_FUA 0x08
457 #define SRW16_DPO 0x10
466 struct scsi_start_stop_unit
470 #define SSS_IMMED 0x01
471 u_int8_t reserved
[2];
473 #define SSS_START 0x01
474 #define SSS_LOEJ 0x02
478 #define SC_SCSI_1 0x01
479 #define SC_SCSI_2 0x03
485 #define TEST_UNIT_READY 0x00
486 #define REQUEST_SENSE 0x03
490 #define MODE_SELECT_6 0x15
491 #define MODE_SENSE_6 0x1a
492 #define START_STOP_UNIT 0x1b
493 #define START_STOP 0x1b
496 #define RECEIVE_DIAGNOSTIC 0x1c
497 #define SEND_DIAGNOSTIC 0x1d
498 #define PREVENT_ALLOW 0x1e
499 #define READ_CAPACITY 0x25
501 #define WRITE_10 0x2a
502 #define POSITION_TO_ELEMENT 0x2b
503 #define SYNCHRONIZE_CACHE 0x35
504 #define WRITE_BUFFER 0x3b
505 #define READ_BUFFER 0x3c
506 #define CHANGE_DEFINITION 0x40
507 #define LOG_SELECT 0x4c
508 #define LOG_SENSE 0x4d
509 #define MODE_SELECT_10 0x55
510 #define MODE_SENSE_10 0x5A
512 #define WRITE_16 0x8a
513 #define SERVICE_ACTION_IN 0x9e
514 #define REPORT_LUNS 0xa0
515 #define MOVE_MEDIUM 0xa5
517 #define WRITE_12 0xaa
518 #define READ_ELEMENT_STATUS 0xb8
523 #define T_DIRECT 0x00
524 #define T_SEQUENTIAL 0x01
525 #define T_PRINTER 0x02
526 #define T_PROCESSOR 0x03
529 #define T_SCANNER 0x06
530 #define T_OPTICAL 0x07
531 #define T_CHANGER 0x08
535 #define T_STORARRAY 0x0c
536 #define T_ENCLOSURE 0x0d
539 #define T_NODEVICE 0x1F
540 #define T_ANY 0xFF /* Used in Quirk table matches */
546 * This length is the initial inquiry length used by the probe code, as
547 * well as the legnth necessary for scsi_print_inquiry() to function
548 * correctly. If either use requires a different length in the future,
549 * the two values should be de-coupled.
551 #define SHORT_INQUIRY_LENGTH 36
553 struct scsi_inquiry_data
556 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
557 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
558 #define SID_QUAL_LU_CONNECTED 0x00 /*
559 * The specified peripheral device
560 * type is currently connected to
561 * logical unit. If the target cannot
562 * determine whether or not a physical
563 * device is currently connected, it
564 * shall also use this peripheral
565 * qualifier when returning the INQUIRY
566 * data. This peripheral qualifier
567 * does not mean that the device is
568 * ready for access by the initiator.
570 #define SID_QUAL_LU_OFFLINE 0x01 /*
571 * The target is capable of supporting
572 * the specified peripheral device type
573 * on this logical unit; however, the
574 * physical device is not currently
575 * connected to this logical unit.
577 #define SID_QUAL_RSVD 0x02
578 #define SID_QUAL_BAD_LU 0x03 /*
579 * The target is not capable of
580 * supporting a physical device on
581 * this logical unit. For this
582 * peripheral qualifier the peripheral
583 * device type shall be set to 1Fh to
584 * provide compatibility with previous
585 * versions of SCSI. All other
586 * peripheral device type values are
587 * reserved for this peripheral
590 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
592 #define SID_QUAL2 0x7F
593 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
595 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
597 #define SCSI_REV_CCS 1
599 #define SCSI_REV_SPC 3
600 #define SCSI_REV_SPC2 4
602 #define SID_ECMA 0x38
604 u_int8_t response_format
;
605 #define SID_AENC 0x80
606 #define SID_TrmIOP 0x40
607 u_int8_t additional_length
;
610 #define SPC2_SID_MChngr 0x08
611 #define SPC2_SID_MultiP 0x10
612 #define SPC2_SID_EncServ 0x40
613 #define SPC2_SID_BQueue 0x80
615 #define INQ_DATA_TQ_ENABLED(iqd) \
616 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \
617 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \
618 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue)))
622 #define SID_SftRe 0x01
623 #define SID_CmdQue 0x02
624 #define SID_Linked 0x08
625 #define SID_Sync 0x10
626 #define SID_WBus16 0x20
627 #define SID_WBus32 0x40
628 #define SID_RelAdr 0x80
629 #define SID_VENDOR_SIZE 8
630 char vendor
[SID_VENDOR_SIZE
];
631 #define SID_PRODUCT_SIZE 16
632 char product
[SID_PRODUCT_SIZE
];
633 #define SID_REVISION_SIZE 4
634 char revision
[SID_REVISION_SIZE
];
636 * The following fields were taken from SCSI Primary Commands - 2
637 * (SPC-2) Revision 14, Dated 11 November 1999
639 #define SID_VENDOR_SPECIFIC_0_SIZE 20
640 u_int8_t vendor_specific0
[SID_VENDOR_SPECIFIC_0_SIZE
];
642 * An extension of SCSI Parallel Specific Values
644 #define SID_SPI_IUS 0x01
645 #define SID_SPI_QAS 0x02
646 #define SID_SPI_CLOCK_ST 0x00
647 #define SID_SPI_CLOCK_DT 0x04
648 #define SID_SPI_CLOCK_DT_ST 0x0C
649 #define SID_SPI_MASK 0x0F
653 * Version Descriptors, stored 2 byte values.
655 u_int8_t version1
[2];
656 u_int8_t version2
[2];
657 u_int8_t version3
[2];
658 u_int8_t version4
[2];
659 u_int8_t version5
[2];
660 u_int8_t version6
[2];
661 u_int8_t version7
[2];
662 u_int8_t version8
[2];
664 u_int8_t reserved3
[22];
666 #define SID_VENDOR_SPECIFIC_1_SIZE 160
667 u_int8_t vendor_specific1
[SID_VENDOR_SPECIFIC_1_SIZE
];
670 struct scsi_vpd_unit_serial_number
674 #define SVPD_UNIT_SERIAL_NUMBER 0x80
676 u_int8_t length
; /* serial number length */
677 #define SVPD_SERIAL_NUM_SIZE 251
678 u_int8_t serial_num
[SVPD_SERIAL_NUM_SIZE
];
681 struct scsi_read_capacity
690 struct scsi_read_capacity_16
693 #define SRC16_SERVICE_ACTION 0x10
694 uint8_t service_action
;
696 uint8_t alloc_len
[4];
697 #define SRC16_PMI 0x01
698 #define SRC16_RELADR 0x02
703 struct scsi_read_capacity_data
709 struct scsi_read_capacity_data_long
715 struct scsi_report_luns
724 struct scsi_report_luns_data
{
725 u_int8_t length
[4]; /* length of LUN inventory, in bytes */
726 u_int8_t reserved
[4]; /* unused */
728 * LUN inventory- we only support the type zero form for now.
734 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
735 #define RPL_LUNDATA_T0LUN 1 /* @ lundata[1] */
738 struct scsi_sense_data
741 #define SSD_ERRCODE 0x7F
742 #define SSD_CURRENT_ERROR 0x70
743 #define SSD_DEFERRED_ERROR 0x71
744 #define SSD_ERRCODE_VALID 0x80
748 #define SSD_KEY_NO_SENSE 0x00
749 #define SSD_KEY_RECOVERED_ERROR 0x01
750 #define SSD_KEY_NOT_READY 0x02
751 #define SSD_KEY_MEDIUM_ERROR 0x03
752 #define SSD_KEY_HARDWARE_ERROR 0x04
753 #define SSD_KEY_ILLEGAL_REQUEST 0x05
754 #define SSD_KEY_UNIT_ATTENTION 0x06
755 #define SSD_KEY_DATA_PROTECT 0x07
756 #define SSD_KEY_BLANK_CHECK 0x08
757 #define SSD_KEY_Vendor_Specific 0x09
758 #define SSD_KEY_COPY_ABORTED 0x0a
759 #define SSD_KEY_ABORTED_COMMAND 0x0b
760 #define SSD_KEY_EQUAL 0x0c
761 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
762 #define SSD_KEY_MISCOMPARE 0x0e
763 #define SSD_KEY_RESERVED 0x0f
766 #define SSD_FILEMARK 0x80
769 u_int8_t cmd_spec_info
[4];
770 u_int8_t add_sense_code
;
771 u_int8_t add_sense_code_qual
;
773 u_int8_t sense_key_spec
[3];
774 #define SSD_SCS_VALID 0x80
775 #define SSD_FIELDPTR_CMD 0x40
776 #define SSD_BITPTR_VALID 0x08
777 #define SSD_BITPTR_VALUE 0x07
778 #define SSD_MIN_SIZE 18
779 u_int8_t extra_bytes
[14];
780 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
783 struct scsi_mode_header_6
785 u_int8_t data_length
; /* Sense data length */
786 u_int8_t medium_type
;
788 u_int8_t blk_desc_len
;
791 struct scsi_mode_header_10
793 u_int8_t data_length
[2];/* Sense data length */
794 u_int8_t medium_type
;
797 u_int8_t blk_desc_len
[2];
800 struct scsi_mode_page_header
803 u_int8_t page_length
;
806 struct scsi_mode_blk_desc
814 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
815 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
821 #define SCSI_STATUS_OK 0x00
822 #define SCSI_STATUS_CHECK_COND 0x02
823 #define SCSI_STATUS_COND_MET 0x04
824 #define SCSI_STATUS_BUSY 0x08
825 #define SCSI_STATUS_INTERMED 0x10
826 #define SCSI_STATUS_INTERMED_COND_MET 0x14
827 #define SCSI_STATUS_RESERV_CONFLICT 0x18
828 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
829 #define SCSI_STATUS_QUEUE_FULL 0x28
830 #define SCSI_STATUS_ACA_ACTIVE 0x30
831 #define SCSI_STATUS_TASK_ABORTED 0x40
833 struct scsi_inquiry_pattern
{
836 #define SIP_MEDIA_REMOVABLE 0x01
837 #define SIP_MEDIA_FIXED 0x02
840 const char *revision
;
843 struct scsi_static_inquiry_pattern
{
846 char vendor
[SID_VENDOR_SIZE
+1];
847 char product
[SID_PRODUCT_SIZE
+1];
848 char revision
[SID_REVISION_SIZE
+1];
851 struct scsi_sense_quirk_entry
{
852 struct scsi_inquiry_pattern inq_pat
;
855 struct sense_key_table_entry
*sense_key_info
;
856 struct asc_table_entry
*asc_info
;
859 struct sense_key_table_entry
{
865 struct asc_table_entry
{
872 struct op_table_entry
{
878 struct scsi_op_quirk_entry
{
879 struct scsi_inquiry_pattern inq_pat
;
881 struct op_table_entry
*op_table
;
885 SSS_FLAG_NONE
= 0x00,
886 SSS_FLAG_PRINT_COMMAND
= 0x01
887 } scsi_sense_string_flags
;
896 extern const char *scsi_sense_key_text
[];
901 void scsi_sense_desc(int sense_key
, int asc
, int ascq
,
902 struct scsi_inquiry_data
*inq_data
,
903 const char **sense_key_desc
, const char **asc_desc
);
904 scsi_sense_action
scsi_error_action(struct ccb_scsiio
* csio
,
905 struct scsi_inquiry_data
*inq_data
,
906 u_int32_t sense_flags
);
907 const char * scsi_status_string(struct ccb_scsiio
*csio
);
909 int scsi_command_string(struct ccb_scsiio
*csio
, struct sbuf
*sb
);
910 int scsi_sense_sbuf(struct ccb_scsiio
*csio
, struct sbuf
*sb
,
911 scsi_sense_string_flags flags
);
912 char * scsi_sense_string(struct ccb_scsiio
*csio
,
913 char *str
, int str_len
);
914 void scsi_sense_print(struct ccb_scsiio
*csio
);
915 int scsi_interpret_sense(union ccb
*ccb
,
916 u_int32_t sense_flags
,
917 u_int32_t
*relsim_flags
,
918 u_int32_t
*reduction
,
920 scsi_sense_action error_action
);
922 int scsi_command_string(struct cam_device
*device
,
923 struct ccb_scsiio
*csio
, struct sbuf
*sb
);
924 int scsi_sense_sbuf(struct cam_device
*device
,
925 struct ccb_scsiio
*csio
, struct sbuf
*sb
,
926 scsi_sense_string_flags flags
);
927 char * scsi_sense_string(struct cam_device
*device
,
928 struct ccb_scsiio
*csio
,
929 char *str
, int str_len
);
930 void scsi_sense_print(struct cam_device
*device
,
931 struct ccb_scsiio
*csio
, FILE *ofile
);
932 int scsi_interpret_sense(struct cam_device
*device
,
934 u_int32_t sense_flags
,
935 u_int32_t
*relsim_flags
,
936 u_int32_t
*reduction
,
938 scsi_sense_action error_action
);
941 #define SF_RETRY_UA 0x01
942 #define SF_NO_PRINT 0x02
943 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
944 #define SF_PRINT_ALWAYS 0x08
947 const char * scsi_op_desc(u_int16_t opcode
,
948 struct scsi_inquiry_data
*inq_data
);
949 char * scsi_cdb_string(u_int8_t
*cdb_ptr
, char *cdb_string
,
952 void scsi_print_inquiry(struct scsi_inquiry_data
*inq_data
);
954 u_int
scsi_calc_syncsrate(u_int period_factor
);
955 u_int
scsi_calc_syncparam(u_int period
);
957 void scsi_test_unit_ready(struct ccb_scsiio
*csio
, u_int32_t retries
,
958 void (*cbfcnp
)(struct cam_periph
*,
961 u_int8_t sense_len
, u_int32_t timeout
);
963 void scsi_request_sense(struct ccb_scsiio
*csio
, u_int32_t retries
,
964 void (*cbfcnp
)(struct cam_periph
*,
966 void *data_ptr
, u_int8_t dxfer_len
,
967 u_int8_t tag_action
, u_int8_t sense_len
,
970 void scsi_inquiry(struct ccb_scsiio
*csio
, u_int32_t retries
,
971 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
972 u_int8_t tag_action
, u_int8_t
*inq_buf
,
973 u_int32_t inq_len
, int evpd
, u_int8_t page_code
,
974 u_int8_t sense_len
, u_int32_t timeout
);
976 void scsi_mode_sense(struct ccb_scsiio
*csio
, u_int32_t retries
,
977 void (*cbfcnp
)(struct cam_periph
*,
979 u_int8_t tag_action
, int dbd
,
980 u_int8_t page_code
, u_int8_t page
,
981 u_int8_t
*param_buf
, u_int32_t param_len
,
982 u_int8_t sense_len
, u_int32_t timeout
);
983 void scsi_mode_sense_len(struct ccb_scsiio
*csio
, u_int32_t retries
,
984 void (*cbfcnp
)(struct cam_periph
*,
986 u_int8_t tag_action
, int dbd
,
987 u_int8_t page_code
, u_int8_t page
,
988 u_int8_t
*param_buf
, u_int32_t param_len
,
989 int minimum_cmd_size
, u_int8_t sense_len
,
992 void scsi_mode_select(struct ccb_scsiio
*csio
, u_int32_t retries
,
993 void (*cbfcnp
)(struct cam_periph
*,
995 u_int8_t tag_action
, int scsi_page_fmt
,
996 int save_pages
, u_int8_t
*param_buf
,
997 u_int32_t param_len
, u_int8_t sense_len
,
1000 void scsi_mode_select_len(struct ccb_scsiio
*csio
, u_int32_t retries
,
1001 void (*cbfcnp
)(struct cam_periph
*,
1003 u_int8_t tag_action
, int scsi_page_fmt
,
1004 int save_pages
, u_int8_t
*param_buf
,
1005 u_int32_t param_len
, int minimum_cmd_size
,
1006 u_int8_t sense_len
, u_int32_t timeout
);
1008 void scsi_log_sense(struct ccb_scsiio
*csio
, u_int32_t retries
,
1009 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
1010 u_int8_t tag_action
, u_int8_t page_code
,
1011 u_int8_t page
, int save_pages
, int ppc
,
1012 u_int32_t paramptr
, u_int8_t
*param_buf
,
1013 u_int32_t param_len
, u_int8_t sense_len
,
1016 void scsi_log_select(struct ccb_scsiio
*csio
, u_int32_t retries
,
1017 void (*cbfcnp
)(struct cam_periph
*,
1018 union ccb
*), u_int8_t tag_action
,
1019 u_int8_t page_code
, int save_pages
,
1020 int pc_reset
, u_int8_t
*param_buf
,
1021 u_int32_t param_len
, u_int8_t sense_len
,
1024 void scsi_prevent(struct ccb_scsiio
*csio
, u_int32_t retries
,
1025 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
1026 u_int8_t tag_action
, u_int8_t action
,
1027 u_int8_t sense_len
, u_int32_t timeout
);
1029 void scsi_read_capacity(struct ccb_scsiio
*csio
, u_int32_t retries
,
1030 void (*cbfcnp
)(struct cam_periph
*,
1031 union ccb
*), u_int8_t tag_action
,
1032 struct scsi_read_capacity_data
*,
1033 u_int8_t sense_len
, u_int32_t timeout
);
1034 void scsi_read_capacity_16(struct ccb_scsiio
*csio
, uint32_t retries
,
1035 void (*cbfcnp
)(struct cam_periph
*,
1036 union ccb
*), uint8_t tag_action
,
1037 uint64_t lba
, int reladr
, int pmi
,
1038 struct scsi_read_capacity_data_long
1039 *rcap_buf
, uint8_t sense_len
,
1042 void scsi_report_luns(struct ccb_scsiio
*csio
, u_int32_t retries
,
1043 void (*cbfcnp
)(struct cam_periph
*,
1044 union ccb
*), u_int8_t tag_action
,
1045 struct scsi_report_luns_data
*,
1046 u_int32_t alloc_len
, u_int8_t sense_len
,
1049 void scsi_synchronize_cache(struct ccb_scsiio
*csio
,
1051 void (*cbfcnp
)(struct cam_periph
*,
1052 union ccb
*), u_int8_t tag_action
,
1053 u_int32_t begin_lba
, u_int16_t lb_count
,
1054 u_int8_t sense_len
, u_int32_t timeout
);
1056 void scsi_read_write(struct ccb_scsiio
*csio
, u_int32_t retries
,
1057 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
1058 u_int8_t tag_action
, int readop
, u_int8_t byte2
,
1059 int minimum_cmd_size
, u_int64_t lba
,
1060 u_int32_t block_count
, u_int8_t
*data_ptr
,
1061 u_int32_t dxfer_len
, u_int8_t sense_len
,
1064 void scsi_start_stop(struct ccb_scsiio
*csio
, u_int32_t retries
,
1065 void (*cbfcnp
)(struct cam_periph
*, union ccb
*),
1066 u_int8_t tag_action
, int start
, int load_eject
,
1067 int immediate
, u_int8_t sense_len
, u_int32_t timeout
);
1069 int scsi_inquiry_match(caddr_t inqbuffer
, caddr_t table_entry
);
1070 int scsi_static_inquiry_match(caddr_t inqbuffer
,
1071 caddr_t table_entry
);
1073 static __inline
void scsi_extract_sense(struct scsi_sense_data
*sense
,
1074 int *error_code
, int *sense_key
,
1075 int *asc
, int *ascq
);
1076 static __inline
void scsi_ulto2b(u_int32_t val
, u_int8_t
*bytes
);
1077 static __inline
void scsi_ulto3b(u_int32_t val
, u_int8_t
*bytes
);
1078 static __inline
void scsi_ulto4b(u_int32_t val
, u_int8_t
*bytes
);
1079 static __inline
void scsi_u64to8b(u_int64_t val
, u_int8_t
*bytes
);
1080 static __inline u_int32_t
scsi_2btoul(u_int8_t
*bytes
);
1081 static __inline u_int32_t
scsi_3btoul(u_int8_t
*bytes
);
1082 static __inline
int32_t scsi_3btol(u_int8_t
*bytes
);
1083 static __inline u_int32_t
scsi_4btoul(u_int8_t
*bytes
);
1084 static __inline u_int64_t
scsi_8btou64(u_int8_t
*bytes
);
1085 static __inline
void *find_mode_page_6(struct scsi_mode_header_6
*mode_header
);
1086 static __inline
void *find_mode_page_10(struct scsi_mode_header_10
*mode_header
);
1088 static __inline
void
1089 scsi_extract_sense(struct scsi_sense_data
*sense
, int *error_code
,
1090 int *sense_key
, int *asc
, int *ascq
)
1092 *error_code
= sense
->error_code
& SSD_ERRCODE
;
1093 *sense_key
= sense
->flags
& SSD_KEY
;
1094 *asc
= (sense
->extra_len
>= 5) ? sense
->add_sense_code
: 0;
1095 *ascq
= (sense
->extra_len
>= 6) ? sense
->add_sense_code_qual
: 0;
1098 static __inline
void
1099 scsi_ulto2b(u_int32_t val
, u_int8_t
*bytes
)
1102 bytes
[0] = (val
>> 8) & 0xff;
1103 bytes
[1] = val
& 0xff;
1106 static __inline
void
1107 scsi_ulto3b(u_int32_t val
, u_int8_t
*bytes
)
1110 bytes
[0] = (val
>> 16) & 0xff;
1111 bytes
[1] = (val
>> 8) & 0xff;
1112 bytes
[2] = val
& 0xff;
1115 static __inline
void
1116 scsi_ulto4b(u_int32_t val
, u_int8_t
*bytes
)
1119 bytes
[0] = (val
>> 24) & 0xff;
1120 bytes
[1] = (val
>> 16) & 0xff;
1121 bytes
[2] = (val
>> 8) & 0xff;
1122 bytes
[3] = val
& 0xff;
1125 static __inline
void
1126 scsi_u64to8b(u_int64_t val
, u_int8_t
*bytes
)
1128 bytes
[0] = (val
>> 56) & 0xff;
1129 bytes
[1] = (val
>> 48) & 0xff;
1130 bytes
[2] = (val
>> 40) & 0xff;
1131 bytes
[3] = (val
>> 32) & 0xff;
1132 bytes
[4] = (val
>> 24) & 0xff;
1133 bytes
[5] = (val
>> 16) & 0xff;
1134 bytes
[6] = (val
>> 8) & 0xff;
1135 bytes
[7] = val
& 0xff;
1138 static __inline u_int32_t
1139 scsi_2btoul(u_int8_t
*bytes
)
1143 rv
= (bytes
[0] << 8) |
1148 static __inline
uint64_t
1149 scsi_8btou64(uint8_t *bytes
)
1153 rv
= (((uint64_t)bytes
[0]) << 56) |
1154 (((uint64_t)bytes
[1]) << 48) |
1155 (((uint64_t)bytes
[2]) << 40) |
1156 (((uint64_t)bytes
[3]) << 32) |
1157 (((uint64_t)bytes
[4]) << 24) |
1158 (((uint64_t)bytes
[5]) << 16) |
1159 (((uint64_t)bytes
[6]) << 8) |
1164 static __inline u_int32_t
1165 scsi_3btoul(u_int8_t
*bytes
)
1169 rv
= (bytes
[0] << 16) |
1175 static __inline
int32_t
1176 scsi_3btol(u_int8_t
*bytes
)
1178 u_int32_t rc
= scsi_3btoul(bytes
);
1180 if (rc
& 0x00800000)
1183 return (int32_t) rc
;
1186 static __inline u_int32_t
1187 scsi_4btoul(u_int8_t
*bytes
)
1191 rv
= (bytes
[0] << 24) |
1199 * Given the pointer to a returned mode sense buffer, return a pointer to
1200 * the start of the first mode page.
1202 static __inline
void *
1203 find_mode_page_6(struct scsi_mode_header_6
*mode_header
)
1207 page_start
= (void *)((u_int8_t
*)&mode_header
[1] +
1208 mode_header
->blk_desc_len
);
1213 static __inline
void *
1214 find_mode_page_10(struct scsi_mode_header_10
*mode_header
)
1218 page_start
= (void *)((u_int8_t
*)&mode_header
[1] +
1219 scsi_2btoul(mode_header
->blk_desc_len
));
1226 #endif /*_SCSI_SCSI_ALL_H*/