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
21 * SCSI general interface description
24 #ifndef _SCSI_SCSI_ALL_H
25 #define _SCSI_SCSI_ALL_H 1
27 #include <sys/cdefs.h>
31 * This is the number of seconds we wait for devices to settle after a SCSI
34 extern int scsi_delay;
42 * Define dome bits that are in ALL (or a lot of) scsi commands
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 */
50 #define SCSI_MAX_CDBLEN 16 /*
51 * 16 byte commands are in the
54 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN)
55 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN"
58 /* 6byte CDBs special case 0 length to be 256 */
59 #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len)
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.
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.
73 SS_TUR = 0x040000, /* Send a Test Unit Ready command to the
74 * device, then retry the original command.
76 SS_REQSENSE = 0x050000, /* Send a RequestSense command to the
77 * device, then retry the original command.
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
92 SSQ_PRINT_SENSE = 0x0800,
94 } scsi_sense_action_qualifier;
96 /* Mask for error status values */
97 #define SS_ERRMASK 0xff
99 /* The default, retyable, error action */
100 #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
102 /* The retyable, error action, with table specified error code */
103 #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
105 /* Fatal error action, with table specified error code */
106 #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE
114 struct scsi_request_sense
123 struct scsi_test_unit_ready
131 struct scsi_send_diag
137 #define SSD_SELFTEST 0x04
140 u_int8_t paramlen[2];
164 struct scsi_mode_sense_6
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
191 struct scsi_mode_sense_10
194 u_int8_t byte2; /* same bits as small version */
195 u_int8_t page; /* same bits as small version */
201 struct scsi_mode_select_6
212 struct scsi_mode_select_10
215 u_int8_t byte2; /* same bits as small version */
222 * When sending a mode select to a tape drive, the medium type must be 0.
224 struct scsi_mode_hdr_6
227 u_int8_t medium_type;
228 u_int8_t dev_specific;
229 u_int8_t block_descr_len;
232 struct scsi_mode_hdr_10
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];
241 struct scsi_mode_block_descr
243 u_int8_t density_code;
244 u_int8_t num_blocks[3];
246 u_int8_t block_len[3];
249 struct scsi_log_sense
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];
278 struct scsi_log_select
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];
295 struct scsi_log_header
302 struct scsi_log_param_header {
303 u_int8_t param_code[2];
304 u_int8_t param_control;
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
319 struct scsi_control_page {
321 u_int8_t page_length;
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*/
336 u_int8_t aen_holdoff_period[2];
339 struct scsi_cache_page {
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];
354 struct scsi_info_exceptions_page {
356 #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */
357 u_int8_t page_length;
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
367 u_int8_t interval_timer[4];
368 u_int8_t report_count[4];
371 struct scsi_proto_specific_page {
373 #define SPSP_PAGE_SAVABLE 0x80 /* Page is savable */
374 u_int8_t page_length;
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
414 #define PR_PREVENT 0x01
415 #define PR_ALLOW 0x00
417 struct scsi_sync_cache
421 u_int8_t begin_lba[4];
423 u_int8_t lb_count[2];
428 struct scsi_changedef
439 struct scsi_read_buffer
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
454 struct scsi_write_buffer
468 /* only 5 bits are valid in the MSB address byte */
469 #define SRW_TOPADDR 0x1F
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
492 #define SRW12_RELADDR 0x01
493 #define SRW12_FUA 0x08
494 #define SRW12_DPO 0x10
505 #define SRW16_RELADDR 0x01
506 #define SRW16_FUA 0x08
507 #define SRW16_DPO 0x10
515 struct scsi_write_same_10
519 #define SWS_LBDATA 0x02
520 #define SWS_PBDATA 0x04
521 #define SWS_UNMAP 0x08
522 #define SWS_ANCHOR 0x10
529 struct scsi_write_same_16
543 #define SU_ANCHOR 0x01
550 struct scsi_start_stop_unit
554 #define SSS_IMMED 0x01
555 u_int8_t reserved[2];
557 #define SSS_START 0x01
558 #define SSS_LOEJ 0x02
565 #define AP_PROTO_HARD_RESET (0x00 << 1)
566 #define AP_PROTO_SRST (0x01 << 1)
567 #define AP_PROTO_NON_DATA (0x03 << 1)
568 #define AP_PROTO_PIO_IN (0x04 << 1)
569 #define AP_PROTO_PIO_OUT (0x05 << 1)
570 #define AP_PROTO_DMA (0x06 << 1)
571 #define AP_PROTO_DMA_QUEUED (0x07 << 1)
572 #define AP_PROTO_DEVICE_DIAG (0x08 << 1)
573 #define AP_PROTO_DEVICE_RESET (0x09 << 1)
574 #define AP_PROTO_UDMA_IN (0x10 << 1)
575 #define AP_PROTO_UDMA_OUT (0x11 << 1)
576 #define AP_PROTO_FPDMA (0x12 << 1)
577 #define AP_PROTO_RESP_INFO (0x15 << 1)
578 #define AP_MULTI 0xe0
580 #define AP_T_LEN 0x03
582 #define AP_T_DIR 0x08
583 #define AP_CK_COND 0x20
584 #define AP_OFFLINE 0x60
586 u_int8_t sector_count;
599 #define AP_EXTEND 0x01
601 #define AP_FLAG_TLEN_NO_DATA (0 << 0)
602 #define AP_FLAG_TLEN_FEAT (1 << 0)
603 #define AP_FLAG_TLEN_SECT_CNT (2 << 0)
604 #define AP_FLAG_TLEN_STPSIU (3 << 0)
605 #define AP_FLAG_BYT_BLOK_BYTES (0 << 2)
606 #define AP_FLAG_BYT_BLOK_BLOCKS (1 << 2)
607 #define AP_FLAG_TDIR_TO_DEV (0 << 3)
608 #define AP_FLAG_TDIR_FROM_DEV (1 << 3)
609 #define AP_FLAG_CHK_COND (1 << 5)
610 u_int8_t features_ext;
612 u_int8_t sector_count_ext;
613 u_int8_t sector_count;
614 u_int8_t lba_low_ext;
616 u_int8_t lba_mid_ext;
618 u_int8_t lba_high_ext;
625 #define SC_SCSI_1 0x01
626 #define SC_SCSI_2 0x03
632 #define TEST_UNIT_READY 0x00
633 #define REQUEST_SENSE 0x03
637 #define MODE_SELECT_6 0x15
638 #define MODE_SENSE_6 0x1A
639 #define START_STOP_UNIT 0x1B
640 #define START_STOP 0x1B
643 #define RECEIVE_DIAGNOSTIC 0x1C
644 #define SEND_DIAGNOSTIC 0x1D
645 #define PREVENT_ALLOW 0x1E
646 #define READ_CAPACITY 0x25
648 #define WRITE_10 0x2A
649 #define POSITION_TO_ELEMENT 0x2B
650 #define SYNCHRONIZE_CACHE 0x35
651 #define READ_DEFECT_DATA_10 0x37
652 #define WRITE_BUFFER 0x3B
653 #define READ_BUFFER 0x3C
654 #define CHANGE_DEFINITION 0x40
655 #define WRITE_SAME_10 0x41
657 #define LOG_SELECT 0x4C
658 #define LOG_SENSE 0x4D
659 #define MODE_SELECT_10 0x55
660 #define MODE_SENSE_10 0x5A
661 #define ATA_PASS_16 0x85
663 #define WRITE_16 0x8A
664 #define WRITE_SAME_16 0x93
665 #define SERVICE_ACTION_IN 0x9E
666 #define REPORT_LUNS 0xA0
667 #define ATA_PASS_12 0xA1
668 #define MAINTENANCE_IN 0xA3
669 #define MAINTENANCE_OUT 0xA4
670 #define MOVE_MEDIUM 0xA5
672 #define WRITE_12 0xAA
673 #define READ_ELEMENT_STATUS 0xB8
676 /* Maintenance In Service Action Codes */
677 #define REPORT_IDENTIFYING_INFRMATION 0x05
678 #define REPORT_TARGET_PORT_GROUPS 0x0A
679 #define REPORT_ALIASES 0x0B
680 #define REPORT_SUPPORTED_OPERATION_CODES 0x0C
681 #define REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0D
682 #define REPORT_PRIORITY 0x0E
683 #define REPORT_TIMESTAMP 0x0F
684 #define MANAGEMENT_PROTOCOL_IN 0x10
685 /* Maintenance Out Service Action Codes */
686 #define SET_IDENTIFY_INFORMATION 0x06
687 #define SET_TARGET_PORT_GROUPS 0x0A
688 #define CHANGE_ALIASES 0x0B
689 #define SET_PRIORITY 0x0E
690 #define SET_TIMESTAMP 0x0F
691 #define MANGAEMENT_PROTOCOL_OUT 0x10
696 #define T_DIRECT 0x00
697 #define T_SEQUENTIAL 0x01
698 #define T_PRINTER 0x02
699 #define T_PROCESSOR 0x03
702 #define T_SCANNER 0x06
703 #define T_OPTICAL 0x07
704 #define T_CHANGER 0x08
708 #define T_STORARRAY 0x0c
709 #define T_ENCLOSURE 0x0d
714 #define T_NODEVICE 0x1f
715 #define T_ANY 0xff /* Used in Quirk table matches */
721 * This length is the initial inquiry length used by the probe code, as
722 * well as the length necessary for scsi_print_inquiry() to function
723 * correctly. If either use requires a different length in the future,
724 * the two values should be de-coupled.
726 #define SHORT_INQUIRY_LENGTH 36
728 struct scsi_inquiry_data
731 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
732 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
733 #define SID_QUAL_LU_CONNECTED 0x00 /*
734 * The specified peripheral device
735 * type is currently connected to
736 * logical unit. If the target cannot
737 * determine whether or not a physical
738 * device is currently connected, it
739 * shall also use this peripheral
740 * qualifier when returning the INQUIRY
741 * data. This peripheral qualifier
742 * does not mean that the device is
743 * ready for access by the initiator.
745 #define SID_QUAL_LU_OFFLINE 0x01 /*
746 * The target is capable of supporting
747 * the specified peripheral device type
748 * on this logical unit; however, the
749 * physical device is not currently
750 * connected to this logical unit.
752 #define SID_QUAL_RSVD 0x02
753 #define SID_QUAL_BAD_LU 0x03 /*
754 * The target is not capable of
755 * supporting a physical device on
756 * this logical unit. For this
757 * peripheral qualifier the peripheral
758 * device type shall be set to 1Fh to
759 * provide compatibility with previous
760 * versions of SCSI. All other
761 * peripheral device type values are
762 * reserved for this peripheral
765 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
767 #define SID_QUAL2 0x7F
768 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
770 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
772 #define SCSI_REV_CCS 1
774 #define SCSI_REV_SPC 3
775 #define SCSI_REV_SPC2 4
776 #define SCSI_REV_SPC3 5
777 #define SCSI_REV_SPC4 6
779 #define SID_ECMA 0x38
781 u_int8_t response_format;
782 #define SID_AENC 0x80
783 #define SID_TrmIOP 0x40
784 u_int8_t additional_length;
785 #define SID_ADDITIONAL_LENGTH(iqd) \
786 ((iqd)->additional_length + \
787 offsetof(struct scsi_inquiry_data, additional_length) + 1)
789 #define SPC3_SID_PROTECT 0x01
790 #define SPC3_SID_3PC 0x08
791 #define SPC3_SID_TPGS_MASK 0x30
792 #define SPC3_SID_TPGS_IMPLICIT 0x10
793 #define SPC3_SID_TPGS_EXPLICIT 0x20
794 #define SPC3_SID_ACC 0x40
795 #define SPC3_SID_SCCS 0x80
797 #define SPC2_SID_MChngr 0x08
798 #define SPC2_SID_MultiP 0x10
799 #define SPC2_SID_EncServ 0x40
800 #define SPC2_SID_BQueue 0x80
802 #define INQ_DATA_TQ_ENABLED(iqd) \
803 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \
804 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \
805 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue)))
808 #define SID_SftRe 0x01
809 #define SID_CmdQue 0x02
810 #define SID_Linked 0x08
811 #define SID_Sync 0x10
812 #define SID_WBus16 0x20
813 #define SID_WBus32 0x40
814 #define SID_RelAdr 0x80
815 #define SID_VENDOR_SIZE 8
816 char vendor[SID_VENDOR_SIZE];
817 #define SID_PRODUCT_SIZE 16
818 char product[SID_PRODUCT_SIZE];
819 #define SID_REVISION_SIZE 4
820 char revision[SID_REVISION_SIZE];
822 * The following fields were taken from SCSI Primary Commands - 2
823 * (SPC-2) Revision 14, Dated 11 November 1999
825 #define SID_VENDOR_SPECIFIC_0_SIZE 20
826 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
828 * An extension of SCSI Parallel Specific Values
830 #define SID_SPI_IUS 0x01
831 #define SID_SPI_QAS 0x02
832 #define SID_SPI_CLOCK_ST 0x00
833 #define SID_SPI_CLOCK_DT 0x04
834 #define SID_SPI_CLOCK_DT_ST 0x0C
835 #define SID_SPI_MASK 0x0F
839 * Version Descriptors, stored 2 byte values.
841 u_int8_t version1[2];
842 u_int8_t version2[2];
843 u_int8_t version3[2];
844 u_int8_t version4[2];
845 u_int8_t version5[2];
846 u_int8_t version6[2];
847 u_int8_t version7[2];
848 u_int8_t version8[2];
850 u_int8_t reserved3[22];
852 #define SID_VENDOR_SPECIFIC_1_SIZE 160
853 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
856 struct scsi_vpd_supported_page_list
860 #define SVPD_SUPPORTED_PAGE_LIST 0x00
862 u_int8_t length; /* number of VPD entries */
863 #define SVPD_SUPPORTED_PAGES_SIZE 251
864 u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE];
867 struct scsi_vpd_unit_serial_number
871 #define SVPD_UNIT_SERIAL_NUMBER 0x80
873 u_int8_t length; /* serial number length */
874 #define SVPD_SERIAL_NUM_SIZE 251
875 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
878 struct scsi_read_capacity
887 struct scsi_read_capacity_16
890 #define SRC16_SERVICE_ACTION 0x10
891 uint8_t service_action;
893 uint8_t alloc_len[4];
894 #define SRC16_PMI 0x01
895 #define SRC16_RELADR 0x02
900 struct scsi_read_capacity_data
906 struct scsi_read_capacity_data_long
910 #define SRC16_PROT_EN 0x01
911 #define SRC16_P_TYPE 0x0e
913 #define SRC16_LBPPBE 0x0f
914 #define SRC16_PI_EXPONENT 0xf0
915 #define SRC16_PI_EXPONENT_SHIFT 4
917 #define SRC16_LALBA 0x3fff
918 #define SRC16_LBPRZ 0x4000
919 #define SRC16_LBPME 0x8000
920 uint8_t lalba_lbp[2];
923 struct scsi_report_luns
927 #define RPL_REPORT_DEFAULT 0x00
928 #define RPL_REPORT_WELLKNOWN 0x01
929 #define RPL_REPORT_ALL 0x02
930 uint8_t select_report;
931 uint8_t reserved2[3];
937 struct scsi_report_luns_data {
938 u_int8_t length[4]; /* length of LUN inventory, in bytes */
939 u_int8_t reserved[4]; /* unused */
941 * LUN inventory- we only support the type zero form for now.
947 #define RPL_LUNDATA_PERIPH_BUS_MASK 0x3f
948 #define RPL_LUNDATA_FLAT_LUN_MASK 0x3f
949 #define RPL_LUNDATA_LUN_TARG_MASK 0x3f
950 #define RPL_LUNDATA_LUN_BUS_MASK 0xe0
951 #define RPL_LUNDATA_LUN_LUN_MASK 0x1f
952 #define RPL_LUNDATA_EXT_LEN_MASK 0x30
953 #define RPL_LUNDATA_EXT_EAM_MASK 0x0f
954 #define RPL_LUNDATA_EXT_EAM_WK 0x01
955 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC 0x0f
956 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
957 #define RPL_LUNDATA_ATYP_PERIPH 0x00
958 #define RPL_LUNDATA_ATYP_FLAT 0x40
959 #define RPL_LUNDATA_ATYP_LUN 0x80
960 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0
962 struct scsi_target_group
965 uint8_t service_action;
966 #define STG_PDF_LENGTH 0x00
967 #define RPL_PDF_EXTENDED 0x20
968 uint8_t reserved1[4];
974 struct scsi_target_port_descriptor {
976 uint8_t relative_target_port_identifier[2];
980 struct scsi_target_port_group_descriptor {
982 #define TPG_PRIMARY 0x80
983 #define TPG_ASYMMETRIC_ACCESS_STATE_MASK 0xf
984 #define TPG_ASYMMETRIC_ACCESS_OPTIMIZED 0x0
985 #define TPG_ASYMMETRIC_ACCESS_NONOPTIMIZED 0x1
986 #define TPG_ASYMMETRIC_ACCESS_STANDBY 0x2
987 #define TPG_ASYMMETRIC_ACCESS_UNAVAILABLE 0x3
988 #define TPG_ASYMMETRIC_ACCESS_LBA_DEPENDENT 0x4
989 #define TPG_ASYMMETRIC_ACCESS_OFFLINE 0xE
990 #define TPG_ASYMMETRIC_ACCESS_TRANSITIONING 0xF
992 #define TPG_AO_SUP 0x01
993 #define TPG_AN_SUP 0x02
994 #define TPG_S_SUP 0x04
995 #define TPG_U_SUP 0x08
996 #define TPG_LBD_SUP 0x10
997 #define TPG_O_SUP 0x40
998 #define TPG_T_SUP 0x80
999 uint8_t target_port_group[2];
1002 uint8_t vendor_specific;
1003 uint8_t target_port_count;
1004 struct scsi_target_port_descriptor descriptors[];
1007 struct scsi_target_group_data {
1008 uint8_t length[4]; /* length of returned data, in bytes */
1009 struct scsi_target_port_group_descriptor groups[];
1012 struct scsi_target_group_data_extended {
1013 uint8_t length[4]; /* length of returned data, in bytes */
1014 uint8_t format_type; /* STG_PDF_LENGTH or RPL_PDF_EXTENDED */
1015 uint8_t implicit_transition_time;
1016 uint8_t reserved[2];
1017 struct scsi_target_port_group_descriptor groups[];
1021 struct scsi_sense_data
1023 u_int8_t error_code;
1024 #define SSD_ERRCODE 0x7F
1025 #define SSD_CURRENT_ERROR 0x70
1026 #define SSD_DEFERRED_ERROR 0x71
1027 #define SSD_ERRCODE_VALID 0x80
1030 #define SSD_KEY 0x0F
1031 #define SSD_KEY_NO_SENSE 0x00
1032 #define SSD_KEY_RECOVERED_ERROR 0x01
1033 #define SSD_KEY_NOT_READY 0x02
1034 #define SSD_KEY_MEDIUM_ERROR 0x03
1035 #define SSD_KEY_HARDWARE_ERROR 0x04
1036 #define SSD_KEY_ILLEGAL_REQUEST 0x05
1037 #define SSD_KEY_UNIT_ATTENTION 0x06
1038 #define SSD_KEY_DATA_PROTECT 0x07
1039 #define SSD_KEY_BLANK_CHECK 0x08
1040 #define SSD_KEY_Vendor_Specific 0x09
1041 #define SSD_KEY_COPY_ABORTED 0x0a
1042 #define SSD_KEY_ABORTED_COMMAND 0x0b
1043 #define SSD_KEY_EQUAL 0x0c
1044 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
1045 #define SSD_KEY_MISCOMPARE 0x0e
1046 #define SSD_KEY_RESERVED 0x0f
1047 #define SSD_ILI 0x20
1048 #define SSD_EOM 0x40
1049 #define SSD_FILEMARK 0x80
1052 u_int8_t cmd_spec_info[4];
1053 u_int8_t add_sense_code;
1054 u_int8_t add_sense_code_qual;
1056 u_int8_t sense_key_spec[3];
1057 #define SSD_SCS_VALID 0x80
1058 #define SSD_FIELDPTR_CMD 0x40
1059 #define SSD_BITPTR_VALID 0x08
1060 #define SSD_BITPTR_VALUE 0x07
1061 #define SSD_MIN_SIZE 18
1062 u_int8_t extra_bytes[14];
1063 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
1066 struct scsi_mode_header_6
1068 u_int8_t data_length; /* Sense data length */
1069 u_int8_t medium_type;
1071 u_int8_t blk_desc_len;
1074 struct scsi_mode_header_10
1076 u_int8_t data_length[2];/* Sense data length */
1077 u_int8_t medium_type;
1080 u_int8_t blk_desc_len[2];
1083 struct scsi_mode_page_header
1086 u_int8_t page_length;
1089 struct scsi_mode_blk_desc
1092 u_int8_t nblocks[3];
1097 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
1098 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
1104 #define SCSI_STATUS_OK 0x00
1105 #define SCSI_STATUS_CHECK_COND 0x02
1106 #define SCSI_STATUS_COND_MET 0x04
1107 #define SCSI_STATUS_BUSY 0x08
1108 #define SCSI_STATUS_INTERMED 0x10
1109 #define SCSI_STATUS_INTERMED_COND_MET 0x14
1110 #define SCSI_STATUS_RESERV_CONFLICT 0x18
1111 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
1112 #define SCSI_STATUS_QUEUE_FULL 0x28
1113 #define SCSI_STATUS_ACA_ACTIVE 0x30
1114 #define SCSI_STATUS_TASK_ABORTED 0x40
1116 struct scsi_inquiry_pattern {
1118 u_int8_t media_type;
1119 #define SIP_MEDIA_REMOVABLE 0x01
1120 #define SIP_MEDIA_FIXED 0x02
1122 const char *product;
1123 const char *revision;
1126 struct scsi_static_inquiry_pattern {
1128 u_int8_t media_type;
1129 char vendor[SID_VENDOR_SIZE+1];
1130 char product[SID_PRODUCT_SIZE+1];
1131 char revision[SID_REVISION_SIZE+1];
1134 struct scsi_sense_quirk_entry {
1135 struct scsi_inquiry_pattern inq_pat;
1138 struct sense_key_table_entry *sense_key_info;
1139 struct asc_table_entry *asc_info;
1142 struct sense_key_table_entry {
1148 struct asc_table_entry {
1155 struct op_table_entry {
1161 struct scsi_op_quirk_entry {
1162 struct scsi_inquiry_pattern inq_pat;
1164 struct op_table_entry *op_table;
1168 SSS_FLAG_NONE = 0x00,
1169 SSS_FLAG_PRINT_COMMAND = 0x01
1170 } scsi_sense_string_flags;
1179 extern const char *scsi_sense_key_text[];
1184 void scsi_sense_desc(int sense_key, int asc, int ascq,
1185 struct scsi_inquiry_data *inq_data,
1186 const char **sense_key_desc, const char **asc_desc);
1187 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
1188 struct scsi_inquiry_data *inq_data,
1189 u_int32_t sense_flags);
1190 const char * scsi_status_string(struct ccb_scsiio *csio);
1192 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
1193 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
1194 scsi_sense_string_flags flags);
1195 char * scsi_sense_string(struct ccb_scsiio *csio,
1196 char *str, int str_len);
1197 void scsi_sense_print(struct ccb_scsiio *csio);
1199 int scsi_command_string(struct cam_device *device,
1200 struct ccb_scsiio *csio, struct sbuf *sb);
1201 int scsi_sense_sbuf(struct cam_device *device,
1202 struct ccb_scsiio *csio, struct sbuf *sb,
1203 scsi_sense_string_flags flags);
1204 char * scsi_sense_string(struct cam_device *device,
1205 struct ccb_scsiio *csio,
1206 char *str, int str_len);
1207 void scsi_sense_print(struct cam_device *device,
1208 struct ccb_scsiio *csio, FILE *ofile);
1209 #endif /* _KERNEL */
1211 #define SF_RETRY_UA 0x01
1212 #define SF_NO_PRINT 0x02
1213 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
1214 #define SF_PRINT_ALWAYS 0x08
1217 const char * scsi_op_desc(u_int16_t opcode,
1218 struct scsi_inquiry_data *inq_data);
1219 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
1222 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
1224 u_int scsi_calc_syncsrate(u_int period_factor);
1225 u_int scsi_calc_syncparam(u_int period);
1227 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
1228 void (*cbfcnp)(struct cam_periph *,
1230 u_int8_t tag_action,
1231 u_int8_t sense_len, u_int32_t timeout);
1233 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
1234 void (*cbfcnp)(struct cam_periph *,
1236 void *data_ptr, u_int8_t dxfer_len,
1237 u_int8_t tag_action, u_int8_t sense_len,
1240 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
1241 void (*cbfcnp)(struct cam_periph *, union ccb *),
1242 u_int8_t tag_action, u_int8_t *inq_buf,
1243 u_int32_t inq_len, int evpd, u_int8_t page_code,
1244 u_int8_t sense_len, u_int32_t timeout);
1246 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
1247 void (*cbfcnp)(struct cam_periph *,
1249 u_int8_t tag_action, int dbd,
1250 u_int8_t page_code, u_int8_t page,
1251 u_int8_t *param_buf, u_int32_t param_len,
1252 u_int8_t sense_len, u_int32_t timeout);
1254 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
1255 void (*cbfcnp)(struct cam_periph *,
1257 u_int8_t tag_action, int dbd,
1258 u_int8_t page_code, u_int8_t page,
1259 u_int8_t *param_buf, u_int32_t param_len,
1260 int minimum_cmd_size, u_int8_t sense_len,
1263 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
1264 void (*cbfcnp)(struct cam_periph *,
1266 u_int8_t tag_action, int scsi_page_fmt,
1267 int save_pages, u_int8_t *param_buf,
1268 u_int32_t param_len, u_int8_t sense_len,
1271 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
1272 void (*cbfcnp)(struct cam_periph *,
1274 u_int8_t tag_action, int scsi_page_fmt,
1275 int save_pages, u_int8_t *param_buf,
1276 u_int32_t param_len, int minimum_cmd_size,
1277 u_int8_t sense_len, u_int32_t timeout);
1279 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
1280 void (*cbfcnp)(struct cam_periph *, union ccb *),
1281 u_int8_t tag_action, u_int8_t page_code,
1282 u_int8_t page, int save_pages, int ppc,
1283 u_int32_t paramptr, u_int8_t *param_buf,
1284 u_int32_t param_len, u_int8_t sense_len,
1287 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
1288 void (*cbfcnp)(struct cam_periph *,
1289 union ccb *), u_int8_t tag_action,
1290 u_int8_t page_code, int save_pages,
1291 int pc_reset, u_int8_t *param_buf,
1292 u_int32_t param_len, u_int8_t sense_len,
1295 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
1296 void (*cbfcnp)(struct cam_periph *, union ccb *),
1297 u_int8_t tag_action, u_int8_t action,
1298 u_int8_t sense_len, u_int32_t timeout);
1300 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
1301 void (*cbfcnp)(struct cam_periph *,
1302 union ccb *), u_int8_t tag_action,
1303 struct scsi_read_capacity_data *,
1304 u_int8_t sense_len, u_int32_t timeout);
1305 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
1306 void (*cbfcnp)(struct cam_periph *,
1307 union ccb *), uint8_t tag_action,
1308 uint64_t lba, int reladr, int pmi,
1309 struct scsi_read_capacity_data_long
1310 *rcap_buf, uint8_t sense_len,
1313 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
1314 void (*cbfcnp)(struct cam_periph *,
1315 union ccb *), u_int8_t tag_action,
1316 u_int8_t select_report,
1317 struct scsi_report_luns_data *rpl_buf,
1318 u_int32_t alloc_len, u_int8_t sense_len,
1321 void scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
1322 void (*cbfcnp)(struct cam_periph *,
1323 union ccb *), u_int8_t tag_action,
1326 u_int32_t alloc_len, u_int8_t sense_len,
1329 void scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
1330 void (*cbfcnp)(struct cam_periph *,
1331 union ccb *), u_int8_t tag_action, void *buf,
1332 u_int32_t alloc_len, u_int8_t sense_len,
1335 void scsi_synchronize_cache(struct ccb_scsiio *csio,
1337 void (*cbfcnp)(struct cam_periph *,
1338 union ccb *), u_int8_t tag_action,
1339 u_int32_t begin_lba, u_int16_t lb_count,
1340 u_int8_t sense_len, u_int32_t timeout);
1342 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
1343 void (*cbfcnp)(struct cam_periph *, union ccb *),
1344 u_int8_t tag_action, int readop, u_int8_t byte2,
1345 int minimum_cmd_size, u_int64_t lba,
1346 u_int32_t block_count, u_int8_t *data_ptr,
1347 u_int32_t dxfer_len, u_int8_t sense_len,
1350 void scsi_write_same(struct ccb_scsiio *csio, u_int32_t retries,
1351 void (*cbfcnp)(struct cam_periph *, union ccb *),
1352 u_int8_t tag_action, u_int8_t byte2,
1353 int minimum_cmd_size, u_int64_t lba,
1354 u_int32_t block_count, u_int8_t *data_ptr,
1355 u_int32_t dxfer_len, u_int8_t sense_len,
1358 void scsi_ata_pass_16(struct ccb_scsiio *csio, u_int32_t retries,
1359 void (*cbfcnp)(struct cam_periph *, union ccb *),
1360 u_int32_t flags, u_int8_t tag_action,
1361 u_int8_t protocol, u_int8_t ata_flags, u_int16_t features,
1362 u_int16_t sector_count, uint64_t lba, u_int8_t command,
1363 u_int8_t control, u_int8_t *data_ptr, u_int16_t dxfer_len,
1364 u_int8_t sense_len, u_int32_t timeout);
1366 void scsi_unmap(struct ccb_scsiio *csio, u_int32_t retries,
1367 void (*cbfcnp)(struct cam_periph *, union ccb *),
1368 u_int8_t tag_action, u_int8_t byte2,
1369 u_int8_t *data_ptr, u_int16_t dxfer_len,
1370 u_int8_t sense_len, u_int32_t timeout);
1372 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
1373 void (*cbfcnp)(struct cam_periph *, union ccb *),
1374 u_int8_t tag_action, int start, int load_eject,
1375 int immediate, u_int8_t sense_len, u_int32_t timeout);
1377 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
1378 int scsi_static_inquiry_match(caddr_t inqbuffer,
1379 caddr_t table_entry);
1381 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1382 int *error_code, int *sense_key,
1383 int *asc, int *ascq);
1384 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
1385 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
1386 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
1387 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
1388 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
1389 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
1390 static __inline int32_t scsi_3btol(u_int8_t *bytes);
1391 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
1392 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes);
1393 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
1394 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
1396 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1397 int *error_code, int *sense_key,
1398 int *asc, int *ascq)
1400 *error_code = sense->error_code & SSD_ERRCODE;
1401 *sense_key = sense->flags & SSD_KEY;
1402 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
1403 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
1406 static __inline void
1407 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
1410 bytes[0] = (val >> 8) & 0xff;
1411 bytes[1] = val & 0xff;
1414 static __inline void
1415 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
1418 bytes[0] = (val >> 16) & 0xff;
1419 bytes[1] = (val >> 8) & 0xff;
1420 bytes[2] = val & 0xff;
1423 static __inline void
1424 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
1427 bytes[0] = (val >> 24) & 0xff;
1428 bytes[1] = (val >> 16) & 0xff;
1429 bytes[2] = (val >> 8) & 0xff;
1430 bytes[3] = val & 0xff;
1433 static __inline void
1434 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
1437 bytes[0] = (val >> 56) & 0xff;
1438 bytes[1] = (val >> 48) & 0xff;
1439 bytes[2] = (val >> 40) & 0xff;
1440 bytes[3] = (val >> 32) & 0xff;
1441 bytes[4] = (val >> 24) & 0xff;
1442 bytes[5] = (val >> 16) & 0xff;
1443 bytes[6] = (val >> 8) & 0xff;
1444 bytes[7] = val & 0xff;
1447 static __inline u_int32_t
1448 scsi_2btoul(u_int8_t *bytes)
1452 rv = (bytes[0] << 8) |
1457 static __inline u_int32_t
1458 scsi_3btoul(u_int8_t *bytes)
1462 rv = (bytes[0] << 16) |
1468 static __inline int32_t
1469 scsi_3btol(u_int8_t *bytes)
1471 u_int32_t rc = scsi_3btoul(bytes);
1473 if (rc & 0x00800000)
1476 return (int32_t) rc;
1479 static __inline u_int32_t
1480 scsi_4btoul(u_int8_t *bytes)
1484 rv = (bytes[0] << 24) |
1491 static __inline uint64_t
1492 scsi_8btou64(uint8_t *bytes)
1496 rv = (((uint64_t)bytes[0]) << 56) |
1497 (((uint64_t)bytes[1]) << 48) |
1498 (((uint64_t)bytes[2]) << 40) |
1499 (((uint64_t)bytes[3]) << 32) |
1500 (((uint64_t)bytes[4]) << 24) |
1501 (((uint64_t)bytes[5]) << 16) |
1502 (((uint64_t)bytes[6]) << 8) |
1508 * Given the pointer to a returned mode sense buffer, return a pointer to
1509 * the start of the first mode page.
1511 static __inline void *
1512 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
1516 page_start = (void *)((u_int8_t *)&mode_header[1] +
1517 mode_header->blk_desc_len);
1522 static __inline void *
1523 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
1527 page_start = (void *)((u_int8_t *)&mode_header[1] +
1528 scsi_2btoul(mode_header->blk_desc_len));
1535 #endif /*_SCSI_SCSI_ALL_H*/