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_CACHE_PAGE 0x08
174 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
175 #define SMS_CONTROL_MODE_PAGE 0x0A
176 #define SMS_PROTO_SPECIFIC_PAGE 0x19
177 #define SMS_INFO_EXCEPTIONS_PAGE 0x1C
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
189 struct scsi_mode_sense_10
192 u_int8_t byte2; /* same bits as small version */
193 u_int8_t page; /* same bits as small version */
199 struct scsi_mode_select_6
210 struct scsi_mode_select_10
213 u_int8_t byte2; /* same bits as small version */
220 * When sending a mode select to a tape drive, the medium type must be 0.
222 struct scsi_mode_hdr_6
225 u_int8_t medium_type;
226 u_int8_t dev_specific;
227 u_int8_t block_descr_len;
230 struct scsi_mode_hdr_10
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];
239 struct scsi_mode_block_descr
241 u_int8_t density_code;
242 u_int8_t num_blocks[3];
244 u_int8_t block_len[3];
247 struct scsi_log_sense
254 #define SLS_PAGE_CODE 0x3F
255 #define SLS_ALL_PAGES_PAGE 0x00
256 #define SLS_OVERRUN_PAGE 0x01
257 #define SLS_ERROR_WRITE_PAGE 0x02
258 #define SLS_ERROR_READ_PAGE 0x03
259 #define SLS_ERROR_READREVERSE_PAGE 0x04
260 #define SLS_ERROR_VERIFY_PAGE 0x05
261 #define SLS_ERROR_NONMEDIUM_PAGE 0x06
262 #define SLS_ERROR_LASTN_PAGE 0x07
263 #define SLS_SELF_TEST_PAGE 0x10
264 #define SLS_IE_PAGE 0x2f
265 #define SLS_PAGE_CTRL_MASK 0xC0
266 #define SLS_PAGE_CTRL_THRESHOLD 0x00
267 #define SLS_PAGE_CTRL_CUMULATIVE 0x40
268 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
269 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
270 u_int8_t reserved[2];
271 u_int8_t paramptr[2];
276 struct scsi_log_select
283 /* SLS_PAGE_CTRL_MASK 0xC0 */
284 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */
285 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
286 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
287 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
288 u_int8_t reserved[4];
293 struct scsi_log_header
300 struct scsi_log_param_header {
301 u_int8_t param_code[2];
302 u_int8_t param_control;
304 #define SLP_LBIN 0x02
305 #define SLP_TMC_MASK 0x0C
306 #define SLP_TMC_ALWAYS 0x00
307 #define SLP_TMC_EQUAL 0x04
308 #define SLP_TMC_NOTEQUAL 0x08
309 #define SLP_TMC_GREATER 0x0C
317 struct scsi_control_page {
319 u_int8_t page_length;
321 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
322 u_int8_t queue_flags;
323 #define SCP_QUEUE_ALG_MASK 0xF0
324 #define SCP_QUEUE_ALG_RESTRICTED 0x00
325 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
326 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
327 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
328 u_int8_t eca_and_aen;
329 #define SCP_EECA 0x80 /*Enable Extended CA*/
330 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
331 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
332 #define SCP_EAENP 0x01 /*Error AEN Permission*/
334 u_int8_t aen_holdoff_period[2];
337 struct scsi_cache_page {
339 #define SCHP_PAGE_SAVABLE 0x80 /* Page is savable */
340 u_int8_t page_length;
341 u_int8_t cache_flags;
342 #define SCHP_FLAGS_WCE 0x04 /* Write Cache Enable */
343 #define SCHP_FLAGS_MF 0x02 /* Multiplication factor */
344 #define SCHP_FLAGS_RCD 0x01 /* Read Cache Disable */
345 u_int8_t rw_cache_policy;
346 u_int8_t dis_prefetch[2];
347 u_int8_t min_prefetch[2];
348 u_int8_t max_prefetch[2];
349 u_int8_t max_prefetch_ceil[2];
352 struct scsi_info_exceptions_page {
354 #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */
355 u_int8_t page_length;
357 #define SIEP_FLAGS_PERF 0x80
358 #define SIEP_FLAGS_EBF 0x20
359 #define SIEP_FLAGS_EWASC 0x10
360 #define SIEP_FLAGS_DEXCPT 0x08
361 #define SIEP_FLAGS_TEST 0x04
362 #define SIEP_FLAGS_EBACKERR 0x02
363 #define SIEP_FLAGS_LOGERR 0x01
365 u_int8_t interval_timer[4];
366 u_int8_t report_count[4];
369 struct scsi_proto_specific_page {
371 #define SPSP_PAGE_SAVABLE 0x80 /* Page is savable */
372 u_int8_t page_length;
374 #define SPSP_PROTO_FC 0x00
375 #define SPSP_PROTO_SPI 0x01
376 #define SPSP_PROTO_SSA 0x02
377 #define SPSP_PROTO_1394 0x03
378 #define SPSP_PROTO_RDMA 0x04
379 #define SPSP_PROTO_ISCSI 0x05
380 #define SPSP_PROTO_SAS 0x06
381 #define SPSP_PROTO_ADT 0x07
382 #define SPSP_PROTO_ATA 0x08
383 #define SPSP_PROTO_NONE 0x0f
412 #define PR_PREVENT 0x01
413 #define PR_ALLOW 0x00
415 struct scsi_sync_cache
419 u_int8_t begin_lba[4];
421 u_int8_t lb_count[2];
426 struct scsi_changedef
437 struct scsi_read_buffer
441 #define RWB_MODE 0x07
442 #define RWB_MODE_HDR_DATA 0x00
443 #define RWB_MODE_DATA 0x02
444 #define RWB_MODE_DOWNLOAD 0x04
445 #define RWB_MODE_DOWNLOAD_SAVE 0x05
452 struct scsi_write_buffer
466 /* only 5 bits are valid in the MSB address byte */
467 #define SRW_TOPADDR 0x1F
475 #define SRW10_RELADDR 0x01
476 /* EBP defined for WRITE(10) only */
477 #define SRW10_EBP 0x04
478 #define SRW10_FUA 0x08
479 #define SRW10_DPO 0x10
490 #define SRW12_RELADDR 0x01
491 #define SRW12_FUA 0x08
492 #define SRW12_DPO 0x10
503 #define SRW16_RELADDR 0x01
504 #define SRW16_FUA 0x08
505 #define SRW16_DPO 0x10
513 struct scsi_start_stop_unit
517 #define SSS_IMMED 0x01
518 u_int8_t reserved[2];
520 #define SSS_START 0x01
521 #define SSS_LOEJ 0x02
528 #define AP_MULTI 0xe0
530 #define AP_T_LEN 0x03
532 #define AP_T_DIR 0x08
533 #define AP_CK_COND 0x20
534 #define AP_OFFLINE 0x60
536 u_int8_t sector_count;
549 #define AP_EXTEND 0x01
551 u_int8_t features_ext;
553 u_int8_t sector_count_ext;
554 u_int8_t sector_count;
555 u_int8_t lba_low_ext;
557 u_int8_t lba_mid_ext;
559 u_int8_t lba_high_ext;
566 #define SC_SCSI_1 0x01
567 #define SC_SCSI_2 0x03
573 #define TEST_UNIT_READY 0x00
574 #define REQUEST_SENSE 0x03
578 #define MODE_SELECT_6 0x15
579 #define MODE_SENSE_6 0x1a
580 #define START_STOP_UNIT 0x1b
581 #define START_STOP 0x1b
584 #define RECEIVE_DIAGNOSTIC 0x1c
585 #define SEND_DIAGNOSTIC 0x1d
586 #define PREVENT_ALLOW 0x1e
587 #define READ_CAPACITY 0x25
589 #define WRITE_10 0x2a
590 #define POSITION_TO_ELEMENT 0x2b
591 #define SYNCHRONIZE_CACHE 0x35
592 #define READ_DEFECT_DATA_10 0x37
593 #define WRITE_BUFFER 0x3b
594 #define READ_BUFFER 0x3c
595 #define CHANGE_DEFINITION 0x40
596 #define LOG_SELECT 0x4c
597 #define LOG_SENSE 0x4d
598 #define MODE_SELECT_10 0x55
599 #define MODE_SENSE_10 0x5A
600 #define ATA_PASS_16 0x85
602 #define WRITE_16 0x8a
603 #define SERVICE_ACTION_IN 0x9e
604 #define REPORT_LUNS 0xA0
605 #define ATA_PASS_12 0xa1
606 #define MOVE_MEDIUM 0xa5
608 #define WRITE_12 0xaa
609 #define READ_ELEMENT_STATUS 0xb8
615 #define T_DIRECT 0x00
616 #define T_SEQUENTIAL 0x01
617 #define T_PRINTER 0x02
618 #define T_PROCESSOR 0x03
621 #define T_SCANNER 0x06
622 #define T_OPTICAL 0x07
623 #define T_CHANGER 0x08
627 #define T_STORARRAY 0x0c
628 #define T_ENCLOSURE 0x0d
633 #define T_NODEVICE 0x1f
634 #define T_ANY 0xff /* Used in Quirk table matches */
640 * This length is the initial inquiry length used by the probe code, as
641 * well as the legnth necessary for scsi_print_inquiry() to function
642 * correctly. If either use requires a different length in the future,
643 * the two values should be de-coupled.
645 #define SHORT_INQUIRY_LENGTH 36
647 struct scsi_inquiry_data
650 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
651 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
652 #define SID_QUAL_LU_CONNECTED 0x00 /*
653 * The specified peripheral device
654 * type is currently connected to
655 * logical unit. If the target cannot
656 * determine whether or not a physical
657 * device is currently connected, it
658 * shall also use this peripheral
659 * qualifier when returning the INQUIRY
660 * data. This peripheral qualifier
661 * does not mean that the device is
662 * ready for access by the initiator.
664 #define SID_QUAL_LU_OFFLINE 0x01 /*
665 * The target is capable of supporting
666 * the specified peripheral device type
667 * on this logical unit; however, the
668 * physical device is not currently
669 * connected to this logical unit.
671 #define SID_QUAL_RSVD 0x02
672 #define SID_QUAL_BAD_LU 0x03 /*
673 * The target is not capable of
674 * supporting a physical device on
675 * this logical unit. For this
676 * peripheral qualifier the peripheral
677 * device type shall be set to 1Fh to
678 * provide compatibility with previous
679 * versions of SCSI. All other
680 * peripheral device type values are
681 * reserved for this peripheral
684 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
686 #define SID_QUAL2 0x7F
687 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
689 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
691 #define SCSI_REV_CCS 1
693 #define SCSI_REV_SPC 3
694 #define SCSI_REV_SPC2 4
696 #define SID_ECMA 0x38
698 u_int8_t response_format;
699 #define SID_AENC 0x80
700 #define SID_TrmIOP 0x40
701 u_int8_t additional_length;
702 #define SID_ADDITIONAL_LENGTH(iqd) \
703 ((iqd)->additional_length + \
704 offsetof(struct scsi_inquiry_data, additional_length) + 1)
707 #define SPC2_SID_MChngr 0x08
708 #define SPC2_SID_MultiP 0x10
709 #define SPC2_SID_EncServ 0x40
710 #define SPC2_SID_BQueue 0x80
712 #define INQ_DATA_TQ_ENABLED(iqd) \
713 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \
714 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \
715 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue)))
718 #define SID_SftRe 0x01
719 #define SID_CmdQue 0x02
720 #define SID_Linked 0x08
721 #define SID_Sync 0x10
722 #define SID_WBus16 0x20
723 #define SID_WBus32 0x40
724 #define SID_RelAdr 0x80
725 #define SID_VENDOR_SIZE 8
726 char vendor[SID_VENDOR_SIZE];
727 #define SID_PRODUCT_SIZE 16
728 char product[SID_PRODUCT_SIZE];
729 #define SID_REVISION_SIZE 4
730 char revision[SID_REVISION_SIZE];
732 * The following fields were taken from SCSI Primary Commands - 2
733 * (SPC-2) Revision 14, Dated 11 November 1999
735 #define SID_VENDOR_SPECIFIC_0_SIZE 20
736 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
738 * An extension of SCSI Parallel Specific Values
740 #define SID_SPI_IUS 0x01
741 #define SID_SPI_QAS 0x02
742 #define SID_SPI_CLOCK_ST 0x00
743 #define SID_SPI_CLOCK_DT 0x04
744 #define SID_SPI_CLOCK_DT_ST 0x0C
745 #define SID_SPI_MASK 0x0F
749 * Version Descriptors, stored 2 byte values.
751 u_int8_t version1[2];
752 u_int8_t version2[2];
753 u_int8_t version3[2];
754 u_int8_t version4[2];
755 u_int8_t version5[2];
756 u_int8_t version6[2];
757 u_int8_t version7[2];
758 u_int8_t version8[2];
760 u_int8_t reserved3[22];
762 #define SID_VENDOR_SPECIFIC_1_SIZE 160
763 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
766 struct scsi_vpd_supported_page_list
770 #define SVPD_SUPPORTED_PAGE_LIST 0x00
772 u_int8_t length; /* number of VPD entries */
773 #define SVPD_SUPPORTED_PAGES_SIZE 251
774 u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE];
777 struct scsi_vpd_unit_serial_number
781 #define SVPD_UNIT_SERIAL_NUMBER 0x80
783 u_int8_t length; /* serial number length */
784 #define SVPD_SERIAL_NUM_SIZE 251
785 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
788 struct scsi_read_capacity
797 struct scsi_read_capacity_16
800 #define SRC16_SERVICE_ACTION 0x10
801 uint8_t service_action;
803 uint8_t alloc_len[4];
804 #define SRC16_PMI 0x01
805 #define SRC16_RELADR 0x02
810 struct scsi_read_capacity_data
816 struct scsi_read_capacity_data_long
822 struct scsi_report_luns
826 #define RPL_REPORT_DEFAULT 0x00
827 #define RPL_REPORT_WELLKNOWN 0x01
828 #define RPL_REPORT_ALL 0x02
829 uint8_t select_report;
830 uint8_t reserved2[3];
836 struct scsi_report_luns_data {
837 u_int8_t length[4]; /* length of LUN inventory, in bytes */
838 u_int8_t reserved[4]; /* unused */
840 * LUN inventory- we only support the type zero form for now.
846 #define RPL_LUNDATA_PERIPH_BUS_MASK 0x3f
847 #define RPL_LUNDATA_FLAT_LUN_MASK 0x3f
848 #define RPL_LUNDATA_LUN_TARG_MASK 0x3f
849 #define RPL_LUNDATA_LUN_BUS_MASK 0xe0
850 #define RPL_LUNDATA_LUN_LUN_MASK 0x1f
851 #define RPL_LUNDATA_EXT_LEN_MASK 0x30
852 #define RPL_LUNDATA_EXT_EAM_MASK 0x0f
853 #define RPL_LUNDATA_EXT_EAM_WK 0x01
854 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC 0x0f
855 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
856 #define RPL_LUNDATA_ATYP_PERIPH 0x00
857 #define RPL_LUNDATA_ATYP_FLAT 0x40
858 #define RPL_LUNDATA_ATYP_LUN 0x80
859 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0
862 struct scsi_sense_data
865 #define SSD_ERRCODE 0x7F
866 #define SSD_CURRENT_ERROR 0x70
867 #define SSD_DEFERRED_ERROR 0x71
868 #define SSD_ERRCODE_VALID 0x80
872 #define SSD_KEY_NO_SENSE 0x00
873 #define SSD_KEY_RECOVERED_ERROR 0x01
874 #define SSD_KEY_NOT_READY 0x02
875 #define SSD_KEY_MEDIUM_ERROR 0x03
876 #define SSD_KEY_HARDWARE_ERROR 0x04
877 #define SSD_KEY_ILLEGAL_REQUEST 0x05
878 #define SSD_KEY_UNIT_ATTENTION 0x06
879 #define SSD_KEY_DATA_PROTECT 0x07
880 #define SSD_KEY_BLANK_CHECK 0x08
881 #define SSD_KEY_Vendor_Specific 0x09
882 #define SSD_KEY_COPY_ABORTED 0x0a
883 #define SSD_KEY_ABORTED_COMMAND 0x0b
884 #define SSD_KEY_EQUAL 0x0c
885 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
886 #define SSD_KEY_MISCOMPARE 0x0e
887 #define SSD_KEY_RESERVED 0x0f
890 #define SSD_FILEMARK 0x80
893 u_int8_t cmd_spec_info[4];
894 u_int8_t add_sense_code;
895 u_int8_t add_sense_code_qual;
897 u_int8_t sense_key_spec[3];
898 #define SSD_SCS_VALID 0x80
899 #define SSD_FIELDPTR_CMD 0x40
900 #define SSD_BITPTR_VALID 0x08
901 #define SSD_BITPTR_VALUE 0x07
902 #define SSD_MIN_SIZE 18
903 u_int8_t extra_bytes[14];
904 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
907 struct scsi_mode_header_6
909 u_int8_t data_length; /* Sense data length */
910 u_int8_t medium_type;
912 u_int8_t blk_desc_len;
915 struct scsi_mode_header_10
917 u_int8_t data_length[2];/* Sense data length */
918 u_int8_t medium_type;
921 u_int8_t blk_desc_len[2];
924 struct scsi_mode_page_header
927 u_int8_t page_length;
930 struct scsi_mode_blk_desc
938 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
939 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
945 #define SCSI_STATUS_OK 0x00
946 #define SCSI_STATUS_CHECK_COND 0x02
947 #define SCSI_STATUS_COND_MET 0x04
948 #define SCSI_STATUS_BUSY 0x08
949 #define SCSI_STATUS_INTERMED 0x10
950 #define SCSI_STATUS_INTERMED_COND_MET 0x14
951 #define SCSI_STATUS_RESERV_CONFLICT 0x18
952 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
953 #define SCSI_STATUS_QUEUE_FULL 0x28
954 #define SCSI_STATUS_ACA_ACTIVE 0x30
955 #define SCSI_STATUS_TASK_ABORTED 0x40
957 struct scsi_inquiry_pattern {
960 #define SIP_MEDIA_REMOVABLE 0x01
961 #define SIP_MEDIA_FIXED 0x02
964 const char *revision;
967 struct scsi_static_inquiry_pattern {
970 char vendor[SID_VENDOR_SIZE+1];
971 char product[SID_PRODUCT_SIZE+1];
972 char revision[SID_REVISION_SIZE+1];
975 struct scsi_sense_quirk_entry {
976 struct scsi_inquiry_pattern inq_pat;
979 struct sense_key_table_entry *sense_key_info;
980 struct asc_table_entry *asc_info;
983 struct sense_key_table_entry {
989 struct asc_table_entry {
996 struct op_table_entry {
1002 struct scsi_op_quirk_entry {
1003 struct scsi_inquiry_pattern inq_pat;
1005 struct op_table_entry *op_table;
1009 SSS_FLAG_NONE = 0x00,
1010 SSS_FLAG_PRINT_COMMAND = 0x01
1011 } scsi_sense_string_flags;
1020 extern const char *scsi_sense_key_text[];
1025 void scsi_sense_desc(int sense_key, int asc, int ascq,
1026 struct scsi_inquiry_data *inq_data,
1027 const char **sense_key_desc, const char **asc_desc);
1028 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
1029 struct scsi_inquiry_data *inq_data,
1030 u_int32_t sense_flags);
1031 const char * scsi_status_string(struct ccb_scsiio *csio);
1033 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
1034 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
1035 scsi_sense_string_flags flags);
1036 char * scsi_sense_string(struct ccb_scsiio *csio,
1037 char *str, int str_len);
1038 void scsi_sense_print(struct ccb_scsiio *csio);
1039 int scsi_interpret_sense(union ccb *ccb,
1040 u_int32_t sense_flags,
1041 u_int32_t *relsim_flags,
1042 u_int32_t *reduction,
1044 scsi_sense_action error_action);
1046 int scsi_command_string(struct cam_device *device,
1047 struct ccb_scsiio *csio, struct sbuf *sb);
1048 int scsi_sense_sbuf(struct cam_device *device,
1049 struct ccb_scsiio *csio, struct sbuf *sb,
1050 scsi_sense_string_flags flags);
1051 char * scsi_sense_string(struct cam_device *device,
1052 struct ccb_scsiio *csio,
1053 char *str, int str_len);
1054 void scsi_sense_print(struct cam_device *device,
1055 struct ccb_scsiio *csio, FILE *ofile);
1056 int scsi_interpret_sense(struct cam_device *device,
1058 u_int32_t sense_flags,
1059 u_int32_t *relsim_flags,
1060 u_int32_t *reduction,
1062 scsi_sense_action error_action);
1063 #endif /* _KERNEL */
1065 #define SF_RETRY_UA 0x01
1066 #define SF_NO_PRINT 0x02
1067 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
1068 #define SF_PRINT_ALWAYS 0x08
1071 const char * scsi_op_desc(u_int16_t opcode,
1072 struct scsi_inquiry_data *inq_data);
1073 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
1076 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
1078 u_int scsi_calc_syncsrate(u_int period_factor);
1079 u_int scsi_calc_syncparam(u_int period);
1081 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
1082 void (*cbfcnp)(struct cam_periph *,
1084 u_int8_t tag_action,
1085 u_int8_t sense_len, u_int32_t timeout);
1087 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
1088 void (*cbfcnp)(struct cam_periph *,
1090 void *data_ptr, u_int8_t dxfer_len,
1091 u_int8_t tag_action, u_int8_t sense_len,
1094 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
1095 void (*cbfcnp)(struct cam_periph *, union ccb *),
1096 u_int8_t tag_action, u_int8_t *inq_buf,
1097 u_int32_t inq_len, int evpd, u_int8_t page_code,
1098 u_int8_t sense_len, u_int32_t timeout);
1100 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
1101 void (*cbfcnp)(struct cam_periph *,
1103 u_int8_t tag_action, int dbd,
1104 u_int8_t page_code, u_int8_t page,
1105 u_int8_t *param_buf, u_int32_t param_len,
1106 u_int8_t sense_len, u_int32_t timeout);
1108 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
1109 void (*cbfcnp)(struct cam_periph *,
1111 u_int8_t tag_action, int dbd,
1112 u_int8_t page_code, u_int8_t page,
1113 u_int8_t *param_buf, u_int32_t param_len,
1114 int minimum_cmd_size, u_int8_t sense_len,
1117 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
1118 void (*cbfcnp)(struct cam_periph *,
1120 u_int8_t tag_action, int scsi_page_fmt,
1121 int save_pages, u_int8_t *param_buf,
1122 u_int32_t param_len, u_int8_t sense_len,
1125 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
1126 void (*cbfcnp)(struct cam_periph *,
1128 u_int8_t tag_action, int scsi_page_fmt,
1129 int save_pages, u_int8_t *param_buf,
1130 u_int32_t param_len, int minimum_cmd_size,
1131 u_int8_t sense_len, u_int32_t timeout);
1133 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
1134 void (*cbfcnp)(struct cam_periph *, union ccb *),
1135 u_int8_t tag_action, u_int8_t page_code,
1136 u_int8_t page, int save_pages, int ppc,
1137 u_int32_t paramptr, u_int8_t *param_buf,
1138 u_int32_t param_len, u_int8_t sense_len,
1141 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
1142 void (*cbfcnp)(struct cam_periph *,
1143 union ccb *), u_int8_t tag_action,
1144 u_int8_t page_code, int save_pages,
1145 int pc_reset, u_int8_t *param_buf,
1146 u_int32_t param_len, u_int8_t sense_len,
1149 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
1150 void (*cbfcnp)(struct cam_periph *, union ccb *),
1151 u_int8_t tag_action, u_int8_t action,
1152 u_int8_t sense_len, u_int32_t timeout);
1154 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
1155 void (*cbfcnp)(struct cam_periph *,
1156 union ccb *), u_int8_t tag_action,
1157 struct scsi_read_capacity_data *,
1158 u_int8_t sense_len, u_int32_t timeout);
1159 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
1160 void (*cbfcnp)(struct cam_periph *,
1161 union ccb *), uint8_t tag_action,
1162 uint64_t lba, int reladr, int pmi,
1163 struct scsi_read_capacity_data_long
1164 *rcap_buf, uint8_t sense_len,
1167 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
1168 void (*cbfcnp)(struct cam_periph *,
1169 union ccb *), u_int8_t tag_action,
1170 u_int8_t select_report,
1171 struct scsi_report_luns_data *rpl_buf,
1172 u_int32_t alloc_len, u_int8_t sense_len,
1175 void scsi_synchronize_cache(struct ccb_scsiio *csio,
1177 void (*cbfcnp)(struct cam_periph *,
1178 union ccb *), u_int8_t tag_action,
1179 u_int32_t begin_lba, u_int16_t lb_count,
1180 u_int8_t sense_len, u_int32_t timeout);
1182 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
1183 void (*cbfcnp)(struct cam_periph *, union ccb *),
1184 u_int8_t tag_action, int readop, u_int8_t byte2,
1185 int minimum_cmd_size, u_int64_t lba,
1186 u_int32_t block_count, u_int8_t *data_ptr,
1187 u_int32_t dxfer_len, u_int8_t sense_len,
1190 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
1191 void (*cbfcnp)(struct cam_periph *, union ccb *),
1192 u_int8_t tag_action, int start, int load_eject,
1193 int immediate, u_int8_t sense_len, u_int32_t timeout);
1195 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
1196 int scsi_static_inquiry_match(caddr_t inqbuffer,
1197 caddr_t table_entry);
1199 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1200 int *error_code, int *sense_key,
1201 int *asc, int *ascq);
1202 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
1203 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
1204 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
1205 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
1206 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
1207 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
1208 static __inline int32_t scsi_3btol(u_int8_t *bytes);
1209 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
1210 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes);
1211 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
1212 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
1214 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1215 int *error_code, int *sense_key,
1216 int *asc, int *ascq)
1218 *error_code = sense->error_code & SSD_ERRCODE;
1219 *sense_key = sense->flags & SSD_KEY;
1220 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
1221 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
1224 static __inline void
1225 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
1228 bytes[0] = (val >> 8) & 0xff;
1229 bytes[1] = val & 0xff;
1232 static __inline void
1233 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
1236 bytes[0] = (val >> 16) & 0xff;
1237 bytes[1] = (val >> 8) & 0xff;
1238 bytes[2] = val & 0xff;
1241 static __inline void
1242 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
1245 bytes[0] = (val >> 24) & 0xff;
1246 bytes[1] = (val >> 16) & 0xff;
1247 bytes[2] = (val >> 8) & 0xff;
1248 bytes[3] = val & 0xff;
1251 static __inline void
1252 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
1255 bytes[0] = (val >> 56) & 0xff;
1256 bytes[1] = (val >> 48) & 0xff;
1257 bytes[2] = (val >> 40) & 0xff;
1258 bytes[3] = (val >> 32) & 0xff;
1259 bytes[4] = (val >> 24) & 0xff;
1260 bytes[5] = (val >> 16) & 0xff;
1261 bytes[6] = (val >> 8) & 0xff;
1262 bytes[7] = val & 0xff;
1265 static __inline u_int32_t
1266 scsi_2btoul(u_int8_t *bytes)
1270 rv = (bytes[0] << 8) |
1275 static __inline u_int32_t
1276 scsi_3btoul(u_int8_t *bytes)
1280 rv = (bytes[0] << 16) |
1286 static __inline int32_t
1287 scsi_3btol(u_int8_t *bytes)
1289 u_int32_t rc = scsi_3btoul(bytes);
1291 if (rc & 0x00800000)
1294 return (int32_t) rc;
1297 static __inline u_int32_t
1298 scsi_4btoul(u_int8_t *bytes)
1302 rv = (bytes[0] << 24) |
1309 static __inline uint64_t
1310 scsi_8btou64(uint8_t *bytes)
1314 rv = (((uint64_t)bytes[0]) << 56) |
1315 (((uint64_t)bytes[1]) << 48) |
1316 (((uint64_t)bytes[2]) << 40) |
1317 (((uint64_t)bytes[3]) << 32) |
1318 (((uint64_t)bytes[4]) << 24) |
1319 (((uint64_t)bytes[5]) << 16) |
1320 (((uint64_t)bytes[6]) << 8) |
1326 * Given the pointer to a returned mode sense buffer, return a pointer to
1327 * the start of the first mode page.
1329 static __inline void *
1330 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
1334 page_start = (void *)((u_int8_t *)&mode_header[1] +
1335 mode_header->blk_desc_len);
1340 static __inline void *
1341 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
1345 page_start = (void *)((u_int8_t *)&mode_header[1] +
1346 scsi_2btoul(mode_header->blk_desc_len));
1353 #endif /*_SCSI_SCSI_ALL_H*/