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_start_stop_unit
519 #define SSS_IMMED 0x01
520 u_int8_t reserved[2];
522 #define SSS_START 0x01
523 #define SSS_LOEJ 0x02
530 #define AP_MULTI 0xe0
532 #define AP_T_LEN 0x03
534 #define AP_T_DIR 0x08
535 #define AP_CK_COND 0x20
536 #define AP_OFFLINE 0x60
538 u_int8_t sector_count;
551 #define AP_EXTEND 0x01
553 u_int8_t features_ext;
555 u_int8_t sector_count_ext;
556 u_int8_t sector_count;
557 u_int8_t lba_low_ext;
559 u_int8_t lba_mid_ext;
561 u_int8_t lba_high_ext;
568 #define SC_SCSI_1 0x01
569 #define SC_SCSI_2 0x03
575 #define TEST_UNIT_READY 0x00
576 #define REQUEST_SENSE 0x03
580 #define MODE_SELECT_6 0x15
581 #define MODE_SENSE_6 0x1a
582 #define START_STOP_UNIT 0x1b
583 #define START_STOP 0x1b
586 #define RECEIVE_DIAGNOSTIC 0x1c
587 #define SEND_DIAGNOSTIC 0x1d
588 #define PREVENT_ALLOW 0x1e
589 #define READ_CAPACITY 0x25
591 #define WRITE_10 0x2a
592 #define POSITION_TO_ELEMENT 0x2b
593 #define SYNCHRONIZE_CACHE 0x35
594 #define READ_DEFECT_DATA_10 0x37
595 #define WRITE_BUFFER 0x3b
596 #define READ_BUFFER 0x3c
597 #define CHANGE_DEFINITION 0x40
598 #define LOG_SELECT 0x4c
599 #define LOG_SENSE 0x4d
600 #define MODE_SELECT_10 0x55
601 #define MODE_SENSE_10 0x5A
602 #define ATA_PASS_16 0x85
604 #define WRITE_16 0x8a
605 #define SERVICE_ACTION_IN 0x9e
606 #define REPORT_LUNS 0xA0
607 #define ATA_PASS_12 0xa1
608 #define MOVE_MEDIUM 0xa5
610 #define WRITE_12 0xaa
611 #define READ_ELEMENT_STATUS 0xb8
617 #define T_DIRECT 0x00
618 #define T_SEQUENTIAL 0x01
619 #define T_PRINTER 0x02
620 #define T_PROCESSOR 0x03
623 #define T_SCANNER 0x06
624 #define T_OPTICAL 0x07
625 #define T_CHANGER 0x08
629 #define T_STORARRAY 0x0c
630 #define T_ENCLOSURE 0x0d
635 #define T_NODEVICE 0x1f
636 #define T_ANY 0xff /* Used in Quirk table matches */
642 * This length is the initial inquiry length used by the probe code, as
643 * well as the legnth necessary for scsi_print_inquiry() to function
644 * correctly. If either use requires a different length in the future,
645 * the two values should be de-coupled.
647 #define SHORT_INQUIRY_LENGTH 36
649 struct scsi_inquiry_data
652 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
653 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
654 #define SID_QUAL_LU_CONNECTED 0x00 /*
655 * The specified peripheral device
656 * type is currently connected to
657 * logical unit. If the target cannot
658 * determine whether or not a physical
659 * device is currently connected, it
660 * shall also use this peripheral
661 * qualifier when returning the INQUIRY
662 * data. This peripheral qualifier
663 * does not mean that the device is
664 * ready for access by the initiator.
666 #define SID_QUAL_LU_OFFLINE 0x01 /*
667 * The target is capable of supporting
668 * the specified peripheral device type
669 * on this logical unit; however, the
670 * physical device is not currently
671 * connected to this logical unit.
673 #define SID_QUAL_RSVD 0x02
674 #define SID_QUAL_BAD_LU 0x03 /*
675 * The target is not capable of
676 * supporting a physical device on
677 * this logical unit. For this
678 * peripheral qualifier the peripheral
679 * device type shall be set to 1Fh to
680 * provide compatibility with previous
681 * versions of SCSI. All other
682 * peripheral device type values are
683 * reserved for this peripheral
686 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
688 #define SID_QUAL2 0x7F
689 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
691 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
693 #define SCSI_REV_CCS 1
695 #define SCSI_REV_SPC 3
696 #define SCSI_REV_SPC2 4
698 #define SID_ECMA 0x38
700 u_int8_t response_format;
701 #define SID_AENC 0x80
702 #define SID_TrmIOP 0x40
703 u_int8_t additional_length;
704 #define SID_ADDITIONAL_LENGTH(iqd) \
705 ((iqd)->additional_length + \
706 offsetof(struct scsi_inquiry_data, additional_length) + 1)
709 #define SPC2_SID_MChngr 0x08
710 #define SPC2_SID_MultiP 0x10
711 #define SPC2_SID_EncServ 0x40
712 #define SPC2_SID_BQueue 0x80
714 #define INQ_DATA_TQ_ENABLED(iqd) \
715 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \
716 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \
717 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue)))
720 #define SID_SftRe 0x01
721 #define SID_CmdQue 0x02
722 #define SID_Linked 0x08
723 #define SID_Sync 0x10
724 #define SID_WBus16 0x20
725 #define SID_WBus32 0x40
726 #define SID_RelAdr 0x80
727 #define SID_VENDOR_SIZE 8
728 char vendor[SID_VENDOR_SIZE];
729 #define SID_PRODUCT_SIZE 16
730 char product[SID_PRODUCT_SIZE];
731 #define SID_REVISION_SIZE 4
732 char revision[SID_REVISION_SIZE];
734 * The following fields were taken from SCSI Primary Commands - 2
735 * (SPC-2) Revision 14, Dated 11 November 1999
737 #define SID_VENDOR_SPECIFIC_0_SIZE 20
738 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
740 * An extension of SCSI Parallel Specific Values
742 #define SID_SPI_IUS 0x01
743 #define SID_SPI_QAS 0x02
744 #define SID_SPI_CLOCK_ST 0x00
745 #define SID_SPI_CLOCK_DT 0x04
746 #define SID_SPI_CLOCK_DT_ST 0x0C
747 #define SID_SPI_MASK 0x0F
751 * Version Descriptors, stored 2 byte values.
753 u_int8_t version1[2];
754 u_int8_t version2[2];
755 u_int8_t version3[2];
756 u_int8_t version4[2];
757 u_int8_t version5[2];
758 u_int8_t version6[2];
759 u_int8_t version7[2];
760 u_int8_t version8[2];
762 u_int8_t reserved3[22];
764 #define SID_VENDOR_SPECIFIC_1_SIZE 160
765 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
768 struct scsi_vpd_supported_page_list
772 #define SVPD_SUPPORTED_PAGE_LIST 0x00
774 u_int8_t length; /* number of VPD entries */
775 #define SVPD_SUPPORTED_PAGES_SIZE 251
776 u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE];
779 struct scsi_vpd_unit_serial_number
783 #define SVPD_UNIT_SERIAL_NUMBER 0x80
785 u_int8_t length; /* serial number length */
786 #define SVPD_SERIAL_NUM_SIZE 251
787 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
790 struct scsi_read_capacity
799 struct scsi_read_capacity_16
802 #define SRC16_SERVICE_ACTION 0x10
803 uint8_t service_action;
805 uint8_t alloc_len[4];
806 #define SRC16_PMI 0x01
807 #define SRC16_RELADR 0x02
812 struct scsi_read_capacity_data
818 struct scsi_read_capacity_data_long
824 struct scsi_report_luns
828 #define RPL_REPORT_DEFAULT 0x00
829 #define RPL_REPORT_WELLKNOWN 0x01
830 #define RPL_REPORT_ALL 0x02
831 uint8_t select_report;
832 uint8_t reserved2[3];
838 struct scsi_report_luns_data {
839 u_int8_t length[4]; /* length of LUN inventory, in bytes */
840 u_int8_t reserved[4]; /* unused */
842 * LUN inventory- we only support the type zero form for now.
848 #define RPL_LUNDATA_PERIPH_BUS_MASK 0x3f
849 #define RPL_LUNDATA_FLAT_LUN_MASK 0x3f
850 #define RPL_LUNDATA_LUN_TARG_MASK 0x3f
851 #define RPL_LUNDATA_LUN_BUS_MASK 0xe0
852 #define RPL_LUNDATA_LUN_LUN_MASK 0x1f
853 #define RPL_LUNDATA_EXT_LEN_MASK 0x30
854 #define RPL_LUNDATA_EXT_EAM_MASK 0x0f
855 #define RPL_LUNDATA_EXT_EAM_WK 0x01
856 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC 0x0f
857 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
858 #define RPL_LUNDATA_ATYP_PERIPH 0x00
859 #define RPL_LUNDATA_ATYP_FLAT 0x40
860 #define RPL_LUNDATA_ATYP_LUN 0x80
861 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0
864 struct scsi_sense_data
867 #define SSD_ERRCODE 0x7F
868 #define SSD_CURRENT_ERROR 0x70
869 #define SSD_DEFERRED_ERROR 0x71
870 #define SSD_ERRCODE_VALID 0x80
874 #define SSD_KEY_NO_SENSE 0x00
875 #define SSD_KEY_RECOVERED_ERROR 0x01
876 #define SSD_KEY_NOT_READY 0x02
877 #define SSD_KEY_MEDIUM_ERROR 0x03
878 #define SSD_KEY_HARDWARE_ERROR 0x04
879 #define SSD_KEY_ILLEGAL_REQUEST 0x05
880 #define SSD_KEY_UNIT_ATTENTION 0x06
881 #define SSD_KEY_DATA_PROTECT 0x07
882 #define SSD_KEY_BLANK_CHECK 0x08
883 #define SSD_KEY_Vendor_Specific 0x09
884 #define SSD_KEY_COPY_ABORTED 0x0a
885 #define SSD_KEY_ABORTED_COMMAND 0x0b
886 #define SSD_KEY_EQUAL 0x0c
887 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
888 #define SSD_KEY_MISCOMPARE 0x0e
889 #define SSD_KEY_RESERVED 0x0f
892 #define SSD_FILEMARK 0x80
895 u_int8_t cmd_spec_info[4];
896 u_int8_t add_sense_code;
897 u_int8_t add_sense_code_qual;
899 u_int8_t sense_key_spec[3];
900 #define SSD_SCS_VALID 0x80
901 #define SSD_FIELDPTR_CMD 0x40
902 #define SSD_BITPTR_VALID 0x08
903 #define SSD_BITPTR_VALUE 0x07
904 #define SSD_MIN_SIZE 18
905 u_int8_t extra_bytes[14];
906 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
909 struct scsi_mode_header_6
911 u_int8_t data_length; /* Sense data length */
912 u_int8_t medium_type;
914 u_int8_t blk_desc_len;
917 struct scsi_mode_header_10
919 u_int8_t data_length[2];/* Sense data length */
920 u_int8_t medium_type;
923 u_int8_t blk_desc_len[2];
926 struct scsi_mode_page_header
929 u_int8_t page_length;
932 struct scsi_mode_blk_desc
940 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
941 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
947 #define SCSI_STATUS_OK 0x00
948 #define SCSI_STATUS_CHECK_COND 0x02
949 #define SCSI_STATUS_COND_MET 0x04
950 #define SCSI_STATUS_BUSY 0x08
951 #define SCSI_STATUS_INTERMED 0x10
952 #define SCSI_STATUS_INTERMED_COND_MET 0x14
953 #define SCSI_STATUS_RESERV_CONFLICT 0x18
954 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
955 #define SCSI_STATUS_QUEUE_FULL 0x28
956 #define SCSI_STATUS_ACA_ACTIVE 0x30
957 #define SCSI_STATUS_TASK_ABORTED 0x40
959 struct scsi_inquiry_pattern {
962 #define SIP_MEDIA_REMOVABLE 0x01
963 #define SIP_MEDIA_FIXED 0x02
966 const char *revision;
969 struct scsi_static_inquiry_pattern {
972 char vendor[SID_VENDOR_SIZE+1];
973 char product[SID_PRODUCT_SIZE+1];
974 char revision[SID_REVISION_SIZE+1];
977 struct scsi_sense_quirk_entry {
978 struct scsi_inquiry_pattern inq_pat;
981 struct sense_key_table_entry *sense_key_info;
982 struct asc_table_entry *asc_info;
985 struct sense_key_table_entry {
991 struct asc_table_entry {
998 struct op_table_entry {
1004 struct scsi_op_quirk_entry {
1005 struct scsi_inquiry_pattern inq_pat;
1007 struct op_table_entry *op_table;
1011 SSS_FLAG_NONE = 0x00,
1012 SSS_FLAG_PRINT_COMMAND = 0x01
1013 } scsi_sense_string_flags;
1022 extern const char *scsi_sense_key_text[];
1027 void scsi_sense_desc(int sense_key, int asc, int ascq,
1028 struct scsi_inquiry_data *inq_data,
1029 const char **sense_key_desc, const char **asc_desc);
1030 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
1031 struct scsi_inquiry_data *inq_data,
1032 u_int32_t sense_flags);
1033 const char * scsi_status_string(struct ccb_scsiio *csio);
1035 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
1036 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
1037 scsi_sense_string_flags flags);
1038 char * scsi_sense_string(struct ccb_scsiio *csio,
1039 char *str, int str_len);
1040 void scsi_sense_print(struct ccb_scsiio *csio);
1041 int scsi_interpret_sense(union ccb *ccb,
1042 u_int32_t sense_flags,
1043 u_int32_t *relsim_flags,
1044 u_int32_t *reduction,
1046 scsi_sense_action error_action);
1048 int scsi_command_string(struct cam_device *device,
1049 struct ccb_scsiio *csio, struct sbuf *sb);
1050 int scsi_sense_sbuf(struct cam_device *device,
1051 struct ccb_scsiio *csio, struct sbuf *sb,
1052 scsi_sense_string_flags flags);
1053 char * scsi_sense_string(struct cam_device *device,
1054 struct ccb_scsiio *csio,
1055 char *str, int str_len);
1056 void scsi_sense_print(struct cam_device *device,
1057 struct ccb_scsiio *csio, FILE *ofile);
1058 int scsi_interpret_sense(struct cam_device *device,
1060 u_int32_t sense_flags,
1061 u_int32_t *relsim_flags,
1062 u_int32_t *reduction,
1064 scsi_sense_action error_action);
1065 #endif /* _KERNEL */
1067 #define SF_RETRY_UA 0x01
1068 #define SF_NO_PRINT 0x02
1069 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
1070 #define SF_PRINT_ALWAYS 0x08
1073 const char * scsi_op_desc(u_int16_t opcode,
1074 struct scsi_inquiry_data *inq_data);
1075 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
1078 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
1080 u_int scsi_calc_syncsrate(u_int period_factor);
1081 u_int scsi_calc_syncparam(u_int period);
1083 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
1084 void (*cbfcnp)(struct cam_periph *,
1086 u_int8_t tag_action,
1087 u_int8_t sense_len, u_int32_t timeout);
1089 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
1090 void (*cbfcnp)(struct cam_periph *,
1092 void *data_ptr, u_int8_t dxfer_len,
1093 u_int8_t tag_action, u_int8_t sense_len,
1096 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
1097 void (*cbfcnp)(struct cam_periph *, union ccb *),
1098 u_int8_t tag_action, u_int8_t *inq_buf,
1099 u_int32_t inq_len, int evpd, u_int8_t page_code,
1100 u_int8_t sense_len, u_int32_t timeout);
1102 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
1103 void (*cbfcnp)(struct cam_periph *,
1105 u_int8_t tag_action, int dbd,
1106 u_int8_t page_code, u_int8_t page,
1107 u_int8_t *param_buf, u_int32_t param_len,
1108 u_int8_t sense_len, u_int32_t timeout);
1110 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
1111 void (*cbfcnp)(struct cam_periph *,
1113 u_int8_t tag_action, int dbd,
1114 u_int8_t page_code, u_int8_t page,
1115 u_int8_t *param_buf, u_int32_t param_len,
1116 int minimum_cmd_size, u_int8_t sense_len,
1119 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
1120 void (*cbfcnp)(struct cam_periph *,
1122 u_int8_t tag_action, int scsi_page_fmt,
1123 int save_pages, u_int8_t *param_buf,
1124 u_int32_t param_len, u_int8_t sense_len,
1127 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
1128 void (*cbfcnp)(struct cam_periph *,
1130 u_int8_t tag_action, int scsi_page_fmt,
1131 int save_pages, u_int8_t *param_buf,
1132 u_int32_t param_len, int minimum_cmd_size,
1133 u_int8_t sense_len, u_int32_t timeout);
1135 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
1136 void (*cbfcnp)(struct cam_periph *, union ccb *),
1137 u_int8_t tag_action, u_int8_t page_code,
1138 u_int8_t page, int save_pages, int ppc,
1139 u_int32_t paramptr, u_int8_t *param_buf,
1140 u_int32_t param_len, u_int8_t sense_len,
1143 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
1144 void (*cbfcnp)(struct cam_periph *,
1145 union ccb *), u_int8_t tag_action,
1146 u_int8_t page_code, int save_pages,
1147 int pc_reset, u_int8_t *param_buf,
1148 u_int32_t param_len, u_int8_t sense_len,
1151 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
1152 void (*cbfcnp)(struct cam_periph *, union ccb *),
1153 u_int8_t tag_action, u_int8_t action,
1154 u_int8_t sense_len, u_int32_t timeout);
1156 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
1157 void (*cbfcnp)(struct cam_periph *,
1158 union ccb *), u_int8_t tag_action,
1159 struct scsi_read_capacity_data *,
1160 u_int8_t sense_len, u_int32_t timeout);
1161 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
1162 void (*cbfcnp)(struct cam_periph *,
1163 union ccb *), uint8_t tag_action,
1164 uint64_t lba, int reladr, int pmi,
1165 struct scsi_read_capacity_data_long
1166 *rcap_buf, uint8_t sense_len,
1169 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
1170 void (*cbfcnp)(struct cam_periph *,
1171 union ccb *), u_int8_t tag_action,
1172 u_int8_t select_report,
1173 struct scsi_report_luns_data *rpl_buf,
1174 u_int32_t alloc_len, u_int8_t sense_len,
1177 void scsi_synchronize_cache(struct ccb_scsiio *csio,
1179 void (*cbfcnp)(struct cam_periph *,
1180 union ccb *), u_int8_t tag_action,
1181 u_int32_t begin_lba, u_int16_t lb_count,
1182 u_int8_t sense_len, u_int32_t timeout);
1184 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
1185 void (*cbfcnp)(struct cam_periph *, union ccb *),
1186 u_int8_t tag_action, int readop, u_int8_t byte2,
1187 int minimum_cmd_size, u_int64_t lba,
1188 u_int32_t block_count, u_int8_t *data_ptr,
1189 u_int32_t dxfer_len, u_int8_t sense_len,
1192 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
1193 void (*cbfcnp)(struct cam_periph *, union ccb *),
1194 u_int8_t tag_action, int start, int load_eject,
1195 int immediate, u_int8_t sense_len, u_int32_t timeout);
1197 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
1198 int scsi_static_inquiry_match(caddr_t inqbuffer,
1199 caddr_t table_entry);
1201 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1202 int *error_code, int *sense_key,
1203 int *asc, int *ascq);
1204 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
1205 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
1206 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
1207 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
1208 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
1209 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
1210 static __inline int32_t scsi_3btol(u_int8_t *bytes);
1211 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
1212 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes);
1213 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
1214 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
1216 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1217 int *error_code, int *sense_key,
1218 int *asc, int *ascq)
1220 *error_code = sense->error_code & SSD_ERRCODE;
1221 *sense_key = sense->flags & SSD_KEY;
1222 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
1223 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
1226 static __inline void
1227 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
1230 bytes[0] = (val >> 8) & 0xff;
1231 bytes[1] = val & 0xff;
1234 static __inline void
1235 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
1238 bytes[0] = (val >> 16) & 0xff;
1239 bytes[1] = (val >> 8) & 0xff;
1240 bytes[2] = val & 0xff;
1243 static __inline void
1244 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
1247 bytes[0] = (val >> 24) & 0xff;
1248 bytes[1] = (val >> 16) & 0xff;
1249 bytes[2] = (val >> 8) & 0xff;
1250 bytes[3] = val & 0xff;
1253 static __inline void
1254 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
1257 bytes[0] = (val >> 56) & 0xff;
1258 bytes[1] = (val >> 48) & 0xff;
1259 bytes[2] = (val >> 40) & 0xff;
1260 bytes[3] = (val >> 32) & 0xff;
1261 bytes[4] = (val >> 24) & 0xff;
1262 bytes[5] = (val >> 16) & 0xff;
1263 bytes[6] = (val >> 8) & 0xff;
1264 bytes[7] = val & 0xff;
1267 static __inline u_int32_t
1268 scsi_2btoul(u_int8_t *bytes)
1272 rv = (bytes[0] << 8) |
1277 static __inline u_int32_t
1278 scsi_3btoul(u_int8_t *bytes)
1282 rv = (bytes[0] << 16) |
1288 static __inline int32_t
1289 scsi_3btol(u_int8_t *bytes)
1291 u_int32_t rc = scsi_3btoul(bytes);
1293 if (rc & 0x00800000)
1296 return (int32_t) rc;
1299 static __inline u_int32_t
1300 scsi_4btoul(u_int8_t *bytes)
1304 rv = (bytes[0] << 24) |
1311 static __inline uint64_t
1312 scsi_8btou64(uint8_t *bytes)
1316 rv = (((uint64_t)bytes[0]) << 56) |
1317 (((uint64_t)bytes[1]) << 48) |
1318 (((uint64_t)bytes[2]) << 40) |
1319 (((uint64_t)bytes[3]) << 32) |
1320 (((uint64_t)bytes[4]) << 24) |
1321 (((uint64_t)bytes[5]) << 16) |
1322 (((uint64_t)bytes[6]) << 8) |
1328 * Given the pointer to a returned mode sense buffer, return a pointer to
1329 * the start of the first mode page.
1331 static __inline void *
1332 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
1336 page_start = (void *)((u_int8_t *)&mode_header[1] +
1337 mode_header->blk_desc_len);
1342 static __inline void *
1343 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
1347 page_start = (void *)((u_int8_t *)&mode_header[1] +
1348 scsi_2btoul(mode_header->blk_desc_len));
1355 #endif /*_SCSI_SCSI_ALL_H*/