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.14 2008/05/18 20:30:19 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_CACHE_PAGE 0x08
180 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
181 #define SMS_CONTROL_MODE_PAGE 0x0A
182 #define SMS_PROTO_SPECIFIC_PAGE 0x19
183 #define SMS_INFO_EXCEPTIONS_PAGE 0x1C
184 #define SMS_ALL_PAGES_PAGE 0x3F
185 #define SMS_PAGE_CTRL_MASK 0xC0
186 #define SMS_PAGE_CTRL_CURRENT 0x00
187 #define SMS_PAGE_CTRL_CHANGEABLE 0x40
188 #define SMS_PAGE_CTRL_DEFAULT 0x80
189 #define SMS_PAGE_CTRL_SAVED 0xC0
195 struct scsi_mode_sense_10
198 u_int8_t byte2; /* same bits as small version */
199 u_int8_t page; /* same bits as small version */
205 struct scsi_mode_select_6
216 struct scsi_mode_select_10
219 u_int8_t byte2; /* same bits as small version */
226 * When sending a mode select to a tape drive, the medium type must be 0.
228 struct scsi_mode_hdr_6
231 u_int8_t medium_type;
232 u_int8_t dev_specific;
233 u_int8_t block_descr_len;
236 struct scsi_mode_hdr_10
239 u_int8_t medium_type;
240 u_int8_t dev_specific;
241 u_int8_t reserved[2];
242 u_int8_t block_descr_len[2];
245 struct scsi_mode_block_descr
247 u_int8_t density_code;
248 u_int8_t num_blocks[3];
250 u_int8_t block_len[3];
253 struct scsi_log_sense
260 #define SLS_PAGE_CODE 0x3F
261 #define SLS_ALL_PAGES_PAGE 0x00
262 #define SLS_OVERRUN_PAGE 0x01
263 #define SLS_ERROR_WRITE_PAGE 0x02
264 #define SLS_ERROR_READ_PAGE 0x03
265 #define SLS_ERROR_READREVERSE_PAGE 0x04
266 #define SLS_ERROR_VERIFY_PAGE 0x05
267 #define SLS_ERROR_NONMEDIUM_PAGE 0x06
268 #define SLS_ERROR_LASTN_PAGE 0x07
269 #define SLS_SELF_TEST_PAGE 0x10
270 #define SLS_IE_PAGE 0x2f
271 #define SLS_PAGE_CTRL_MASK 0xC0
272 #define SLS_PAGE_CTRL_THRESHOLD 0x00
273 #define SLS_PAGE_CTRL_CUMULATIVE 0x40
274 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
275 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
276 u_int8_t reserved[2];
277 u_int8_t paramptr[2];
282 struct scsi_log_select
289 /* SLS_PAGE_CTRL_MASK 0xC0 */
290 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */
291 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
292 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
293 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
294 u_int8_t reserved[4];
299 struct scsi_log_header
306 struct scsi_log_param_header {
307 u_int8_t param_code[2];
308 u_int8_t param_control;
310 #define SLP_LBIN 0x02
311 #define SLP_TMC_MASK 0x0C
312 #define SLP_TMC_ALWAYS 0x00
313 #define SLP_TMC_EQUAL 0x04
314 #define SLP_TMC_NOTEQUAL 0x08
315 #define SLP_TMC_GREATER 0x0C
323 struct scsi_control_page {
325 u_int8_t page_length;
327 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
328 u_int8_t queue_flags;
329 #define SCP_QUEUE_ALG_MASK 0xF0
330 #define SCP_QUEUE_ALG_RESTRICTED 0x00
331 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
332 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
333 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
334 u_int8_t eca_and_aen;
335 #define SCP_EECA 0x80 /*Enable Extended CA*/
336 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
337 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
338 #define SCP_EAENP 0x01 /*Error AEN Permission*/
340 u_int8_t aen_holdoff_period[2];
343 struct scsi_cache_page {
345 #define SCHP_PAGE_SAVABLE 0x80 /* Page is savable */
346 u_int8_t page_length;
347 u_int8_t cache_flags;
348 #define SCHP_FLAGS_WCE 0x04 /* Write Cache Enable */
349 #define SCHP_FLAGS_MF 0x02 /* Multiplication factor */
350 #define SCHP_FLAGS_RCD 0x01 /* Read Cache Disable */
351 u_int8_t rw_cache_policy;
352 u_int8_t dis_prefetch[2];
353 u_int8_t min_prefetch[2];
354 u_int8_t max_prefetch[2];
355 u_int8_t max_prefetch_ceil[2];
358 struct scsi_info_exceptions_page {
360 #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */
361 u_int8_t page_length;
363 #define SIEP_FLAGS_PERF 0x80
364 #define SIEP_FLAGS_EBF 0x20
365 #define SIEP_FLAGS_EWASC 0x10
366 #define SIEP_FLAGS_DEXCPT 0x08
367 #define SIEP_FLAGS_TEST 0x04
368 #define SIEP_FLAGS_EBACKERR 0x02
369 #define SIEP_FLAGS_LOGERR 0x01
371 u_int8_t interval_timer[4];
372 u_int8_t report_count[4];
375 struct scsi_proto_specific_page {
377 #define SPSP_PAGE_SAVABLE 0x80 /* Page is savable */
378 u_int8_t page_length;
380 #define SPSP_PROTO_FC 0x00
381 #define SPSP_PROTO_SPI 0x01
382 #define SPSP_PROTO_SSA 0x02
383 #define SPSP_PROTO_1394 0x03
384 #define SPSP_PROTO_RDMA 0x04
385 #define SPSP_PROTO_ISCSI 0x05
386 #define SPSP_PROTO_SAS 0x06
387 #define SPSP_PROTO_ADT 0x07
388 #define SPSP_PROTO_ATA 0x08
389 #define SPSP_PROTO_NONE 0x0f
418 #define PR_PREVENT 0x01
419 #define PR_ALLOW 0x00
421 struct scsi_sync_cache
425 u_int8_t begin_lba[4];
427 u_int8_t lb_count[2];
432 struct scsi_changedef
443 struct scsi_read_buffer
447 #define RWB_MODE 0x07
448 #define RWB_MODE_HDR_DATA 0x00
449 #define RWB_MODE_DATA 0x02
450 #define RWB_MODE_DOWNLOAD 0x04
451 #define RWB_MODE_DOWNLOAD_SAVE 0x05
458 struct scsi_write_buffer
472 /* only 5 bits are valid in the MSB address byte */
473 #define SRW_TOPADDR 0x1F
481 #define SRW10_RELADDR 0x01
482 /* EBP defined for WRITE(10) only */
483 #define SRW10_EBP 0x04
484 #define SRW10_FUA 0x08
485 #define SRW10_DPO 0x10
496 #define SRW12_RELADDR 0x01
497 #define SRW12_FUA 0x08
498 #define SRW12_DPO 0x10
509 #define SRW16_RELADDR 0x01
510 #define SRW16_FUA 0x08
511 #define SRW16_DPO 0x10
520 struct scsi_start_stop_unit
524 #define SSS_IMMED 0x01
525 u_int8_t reserved[2];
527 #define SSS_START 0x01
528 #define SSS_LOEJ 0x02
535 #define AP_MULTI 0xe0
537 #define AP_T_LEN 0x03
539 #define AP_T_DIR 0x08
540 #define AP_CK_COND 0x20
541 #define AP_OFFLINE 0x60
543 u_int8_t sector_count;
556 #define AP_EXTEND 0x01
558 u_int8_t features_ext;
560 u_int8_t sector_count_ext;
561 u_int8_t sector_count;
562 u_int8_t lba_low_ext;
564 u_int8_t lba_mid_ext;
566 u_int8_t lba_high_ext;
573 #define SC_SCSI_1 0x01
574 #define SC_SCSI_2 0x03
580 #define TEST_UNIT_READY 0x00
581 #define REQUEST_SENSE 0x03
585 #define MODE_SELECT_6 0x15
586 #define MODE_SENSE_6 0x1a
587 #define START_STOP_UNIT 0x1b
588 #define START_STOP 0x1b
591 #define RECEIVE_DIAGNOSTIC 0x1c
592 #define SEND_DIAGNOSTIC 0x1d
593 #define PREVENT_ALLOW 0x1e
594 #define READ_CAPACITY 0x25
596 #define WRITE_10 0x2a
597 #define POSITION_TO_ELEMENT 0x2b
598 #define SYNCHRONIZE_CACHE 0x35
599 #define READ_DEFECT_DATA_10 0x37
600 #define WRITE_BUFFER 0x3b
601 #define READ_BUFFER 0x3c
602 #define CHANGE_DEFINITION 0x40
603 #define LOG_SELECT 0x4c
604 #define LOG_SENSE 0x4d
605 #define MODE_SELECT_10 0x55
606 #define MODE_SENSE_10 0x5a
607 #define ATA_PASS_16 0x85
609 #define WRITE_16 0x8a
610 #define SERVICE_ACTION_IN 0x9e
611 #define REPORT_LUNS 0xa0
612 #define ATA_PASS_12 0xa1
613 #define MOVE_MEDIUM 0xa5
615 #define WRITE_12 0xaa
616 #define READ_ELEMENT_STATUS 0xb8
621 #define T_DIRECT 0x00
622 #define T_SEQUENTIAL 0x01
623 #define T_PRINTER 0x02
624 #define T_PROCESSOR 0x03
627 #define T_SCANNER 0x06
628 #define T_OPTICAL 0x07
629 #define T_CHANGER 0x08
633 #define T_STORARRAY 0x0c
634 #define T_ENCLOSURE 0x0d
637 #define T_NODEVICE 0x1F
638 #define T_ANY 0xFF /* Used in Quirk table matches */
644 * This length is the initial inquiry length used by the probe code, as
645 * well as the legnth necessary for scsi_print_inquiry() to function
646 * correctly. If either use requires a different length in the future,
647 * the two values should be de-coupled.
649 #define SHORT_INQUIRY_LENGTH 36
651 struct scsi_inquiry_data
654 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
655 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
656 #define SID_QUAL_LU_CONNECTED 0x00 /*
657 * The specified peripheral device
658 * type is currently connected to
659 * logical unit. If the target cannot
660 * determine whether or not a physical
661 * device is currently connected, it
662 * shall also use this peripheral
663 * qualifier when returning the INQUIRY
664 * data. This peripheral qualifier
665 * does not mean that the device is
666 * ready for access by the initiator.
668 #define SID_QUAL_LU_OFFLINE 0x01 /*
669 * The target is capable of supporting
670 * the specified peripheral device type
671 * on this logical unit; however, the
672 * physical device is not currently
673 * connected to this logical unit.
675 #define SID_QUAL_RSVD 0x02
676 #define SID_QUAL_BAD_LU 0x03 /*
677 * The target is not capable of
678 * supporting a physical device on
679 * this logical unit. For this
680 * peripheral qualifier the peripheral
681 * device type shall be set to 1Fh to
682 * provide compatibility with previous
683 * versions of SCSI. All other
684 * peripheral device type values are
685 * reserved for this peripheral
688 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
690 #define SID_QUAL2 0x7F
691 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
693 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
695 #define SCSI_REV_CCS 1
697 #define SCSI_REV_SPC 3
698 #define SCSI_REV_SPC2 4
700 #define SID_ECMA 0x38
702 u_int8_t response_format;
703 #define SID_AENC 0x80
704 #define SID_TrmIOP 0x40
705 u_int8_t additional_length;
706 #define SID_ADDITIONAL_LENGTH(iqd) \
707 ((iqd)->additional_length + \
708 offsetof(struct scsi_inquiry_data, additional_length) + 1)
711 #define SPC2_SID_MChngr 0x08
712 #define SPC2_SID_MultiP 0x10
713 #define SPC2_SID_EncServ 0x40
714 #define SPC2_SID_BQueue 0x80
716 #define INQ_DATA_TQ_ENABLED(iqd) \
717 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \
718 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \
719 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue)))
723 #define SID_SftRe 0x01
724 #define SID_CmdQue 0x02
725 #define SID_Linked 0x08
726 #define SID_Sync 0x10
727 #define SID_WBus16 0x20
728 #define SID_WBus32 0x40
729 #define SID_RelAdr 0x80
730 #define SID_VENDOR_SIZE 8
731 char vendor[SID_VENDOR_SIZE];
732 #define SID_PRODUCT_SIZE 16
733 char product[SID_PRODUCT_SIZE];
734 #define SID_REVISION_SIZE 4
735 char revision[SID_REVISION_SIZE];
737 * The following fields were taken from SCSI Primary Commands - 2
738 * (SPC-2) Revision 14, Dated 11 November 1999
740 #define SID_VENDOR_SPECIFIC_0_SIZE 20
741 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
743 * An extension of SCSI Parallel Specific Values
745 #define SID_SPI_IUS 0x01
746 #define SID_SPI_QAS 0x02
747 #define SID_SPI_CLOCK_ST 0x00
748 #define SID_SPI_CLOCK_DT 0x04
749 #define SID_SPI_CLOCK_DT_ST 0x0C
750 #define SID_SPI_MASK 0x0F
754 * Version Descriptors, stored 2 byte values.
756 u_int8_t version1[2];
757 u_int8_t version2[2];
758 u_int8_t version3[2];
759 u_int8_t version4[2];
760 u_int8_t version5[2];
761 u_int8_t version6[2];
762 u_int8_t version7[2];
763 u_int8_t version8[2];
765 u_int8_t reserved3[22];
767 #define SID_VENDOR_SPECIFIC_1_SIZE 160
768 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
771 struct scsi_vpd_supported_page_list
775 #define SVPD_SUPPORTED_PAGE_LIST 0x00
777 u_int8_t length; /* number of VPD entries */
778 #define SVPD_SUPPORTED_PAGES_SIZE 251
779 u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE];
782 struct scsi_vpd_unit_serial_number
786 #define SVPD_UNIT_SERIAL_NUMBER 0x80
788 u_int8_t length; /* serial number length */
789 #define SVPD_SERIAL_NUM_SIZE 251
790 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
793 struct scsi_read_capacity
802 struct scsi_read_capacity_16
805 #define SRC16_SERVICE_ACTION 0x10
806 uint8_t service_action;
808 uint8_t alloc_len[4];
809 #define SRC16_PMI 0x01
810 #define SRC16_RELADR 0x02
815 struct scsi_read_capacity_data
821 struct scsi_read_capacity_data_long
827 struct scsi_report_luns
831 #define RPL_REPORT_DEFAULT 0x00
832 #define RPL_REPORT_WELLKNOWN 0x01
833 #define RPL_REPORT_ALL 0x02
834 uint8_t select_report;
835 uint8_t reserved2[3];
841 struct scsi_report_luns_data {
842 u_int8_t length[4]; /* length of LUN inventory, in bytes */
843 u_int8_t reserved[4]; /* unused */
845 * LUN inventory- we only support the type zero form for now.
851 #define RPL_LUNDATA_PERIPH_BUS_MASK 0x3f
852 #define RPL_LUNDATA_FLAT_LUN_MASK 0x3f
853 #define RPL_LUNDATA_LUN_TARG_MASK 0x3f
854 #define RPL_LUNDATA_LUN_BUS_MASK 0xe0
855 #define RPL_LUNDATA_LUN_LUN_MASK 0x1f
856 #define RPL_LUNDATA_EXT_LEN_MASK 0x30
857 #define RPL_LUNDATA_EXT_EAM_MASK 0x0f
858 #define RPL_LUNDATA_EXT_EAM_WK 0x01
859 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC 0x0f
860 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
861 #define RPL_LUNDATA_ATYP_PERIPH 0x00
862 #define RPL_LUNDATA_ATYP_FLAT 0x40
863 #define RPL_LUNDATA_ATYP_LUN 0x80
864 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0
867 struct scsi_sense_data
870 #define SSD_ERRCODE 0x7F
871 #define SSD_CURRENT_ERROR 0x70
872 #define SSD_DEFERRED_ERROR 0x71
873 #define SSD_ERRCODE_VALID 0x80
877 #define SSD_KEY_NO_SENSE 0x00
878 #define SSD_KEY_RECOVERED_ERROR 0x01
879 #define SSD_KEY_NOT_READY 0x02
880 #define SSD_KEY_MEDIUM_ERROR 0x03
881 #define SSD_KEY_HARDWARE_ERROR 0x04
882 #define SSD_KEY_ILLEGAL_REQUEST 0x05
883 #define SSD_KEY_UNIT_ATTENTION 0x06
884 #define SSD_KEY_DATA_PROTECT 0x07
885 #define SSD_KEY_BLANK_CHECK 0x08
886 #define SSD_KEY_Vendor_Specific 0x09
887 #define SSD_KEY_COPY_ABORTED 0x0a
888 #define SSD_KEY_ABORTED_COMMAND 0x0b
889 #define SSD_KEY_EQUAL 0x0c
890 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
891 #define SSD_KEY_MISCOMPARE 0x0e
892 #define SSD_KEY_RESERVED 0x0f
895 #define SSD_FILEMARK 0x80
898 u_int8_t cmd_spec_info[4];
899 u_int8_t add_sense_code;
900 u_int8_t add_sense_code_qual;
902 u_int8_t sense_key_spec[3];
903 #define SSD_SCS_VALID 0x80
904 #define SSD_FIELDPTR_CMD 0x40
905 #define SSD_BITPTR_VALID 0x08
906 #define SSD_BITPTR_VALUE 0x07
907 #define SSD_MIN_SIZE 18
908 u_int8_t extra_bytes[14];
909 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
912 struct scsi_mode_header_6
914 u_int8_t data_length; /* Sense data length */
915 u_int8_t medium_type;
917 u_int8_t blk_desc_len;
920 struct scsi_mode_header_10
922 u_int8_t data_length[2];/* Sense data length */
923 u_int8_t medium_type;
926 u_int8_t blk_desc_len[2];
929 struct scsi_mode_page_header
932 u_int8_t page_length;
935 struct scsi_mode_blk_desc
943 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
944 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
950 #define SCSI_STATUS_OK 0x00
951 #define SCSI_STATUS_CHECK_COND 0x02
952 #define SCSI_STATUS_COND_MET 0x04
953 #define SCSI_STATUS_BUSY 0x08
954 #define SCSI_STATUS_INTERMED 0x10
955 #define SCSI_STATUS_INTERMED_COND_MET 0x14
956 #define SCSI_STATUS_RESERV_CONFLICT 0x18
957 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
958 #define SCSI_STATUS_QUEUE_FULL 0x28
959 #define SCSI_STATUS_ACA_ACTIVE 0x30
960 #define SCSI_STATUS_TASK_ABORTED 0x40
962 struct scsi_inquiry_pattern {
965 #define SIP_MEDIA_REMOVABLE 0x01
966 #define SIP_MEDIA_FIXED 0x02
969 const char *revision;
972 struct scsi_static_inquiry_pattern {
975 char vendor[SID_VENDOR_SIZE+1];
976 char product[SID_PRODUCT_SIZE+1];
977 char revision[SID_REVISION_SIZE+1];
980 struct scsi_sense_quirk_entry {
981 struct scsi_inquiry_pattern inq_pat;
984 struct sense_key_table_entry *sense_key_info;
985 struct asc_table_entry *asc_info;
988 struct sense_key_table_entry {
994 struct asc_table_entry {
1001 struct op_table_entry {
1007 struct scsi_op_quirk_entry {
1008 struct scsi_inquiry_pattern inq_pat;
1010 struct op_table_entry *op_table;
1014 SSS_FLAG_NONE = 0x00,
1015 SSS_FLAG_PRINT_COMMAND = 0x01
1016 } scsi_sense_string_flags;
1025 extern const char *scsi_sense_key_text[];
1030 void scsi_sense_desc(int sense_key, int asc, int ascq,
1031 struct scsi_inquiry_data *inq_data,
1032 const char **sense_key_desc, const char **asc_desc);
1033 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
1034 struct scsi_inquiry_data *inq_data,
1035 u_int32_t sense_flags);
1036 const char * scsi_status_string(struct ccb_scsiio *csio);
1038 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
1039 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
1040 scsi_sense_string_flags flags);
1041 char * scsi_sense_string(struct ccb_scsiio *csio,
1042 char *str, int str_len);
1043 void scsi_sense_print(struct ccb_scsiio *csio);
1044 int scsi_interpret_sense(union ccb *ccb,
1045 u_int32_t sense_flags,
1046 u_int32_t *relsim_flags,
1047 u_int32_t *reduction,
1049 scsi_sense_action error_action);
1051 int scsi_command_string(struct cam_device *device,
1052 struct ccb_scsiio *csio, struct sbuf *sb);
1053 int scsi_sense_sbuf(struct cam_device *device,
1054 struct ccb_scsiio *csio, struct sbuf *sb,
1055 scsi_sense_string_flags flags);
1056 char * scsi_sense_string(struct cam_device *device,
1057 struct ccb_scsiio *csio,
1058 char *str, int str_len);
1059 void scsi_sense_print(struct cam_device *device,
1060 struct ccb_scsiio *csio, FILE *ofile);
1061 int scsi_interpret_sense(struct cam_device *device,
1063 u_int32_t sense_flags,
1064 u_int32_t *relsim_flags,
1065 u_int32_t *reduction,
1067 scsi_sense_action error_action);
1068 #endif /* _KERNEL */
1070 #define SF_RETRY_UA 0x01
1071 #define SF_NO_PRINT 0x02
1072 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
1073 #define SF_PRINT_ALWAYS 0x08
1076 const char * scsi_op_desc(u_int16_t opcode,
1077 struct scsi_inquiry_data *inq_data);
1078 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
1081 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
1083 u_int scsi_calc_syncsrate(u_int period_factor);
1084 u_int scsi_calc_syncparam(u_int period);
1086 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
1087 void (*cbfcnp)(struct cam_periph *,
1089 u_int8_t tag_action,
1090 u_int8_t sense_len, u_int32_t timeout);
1092 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
1093 void (*cbfcnp)(struct cam_periph *,
1095 void *data_ptr, u_int8_t dxfer_len,
1096 u_int8_t tag_action, u_int8_t sense_len,
1099 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
1100 void (*cbfcnp)(struct cam_periph *, union ccb *),
1101 u_int8_t tag_action, u_int8_t *inq_buf,
1102 u_int32_t inq_len, int evpd, u_int8_t page_code,
1103 u_int8_t sense_len, u_int32_t timeout);
1105 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
1106 void (*cbfcnp)(struct cam_periph *,
1108 u_int8_t tag_action, int dbd,
1109 u_int8_t page_code, u_int8_t page,
1110 u_int8_t *param_buf, u_int32_t param_len,
1111 u_int8_t sense_len, u_int32_t timeout);
1112 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
1113 void (*cbfcnp)(struct cam_periph *,
1115 u_int8_t tag_action, int dbd,
1116 u_int8_t page_code, u_int8_t page,
1117 u_int8_t *param_buf, u_int32_t param_len,
1118 int minimum_cmd_size, u_int8_t sense_len,
1121 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
1122 void (*cbfcnp)(struct cam_periph *,
1124 u_int8_t tag_action, int scsi_page_fmt,
1125 int save_pages, u_int8_t *param_buf,
1126 u_int32_t param_len, u_int8_t sense_len,
1129 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
1130 void (*cbfcnp)(struct cam_periph *,
1132 u_int8_t tag_action, int scsi_page_fmt,
1133 int save_pages, u_int8_t *param_buf,
1134 u_int32_t param_len, int minimum_cmd_size,
1135 u_int8_t sense_len, u_int32_t timeout);
1137 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
1138 void (*cbfcnp)(struct cam_periph *, union ccb *),
1139 u_int8_t tag_action, u_int8_t page_code,
1140 u_int8_t page, int save_pages, int ppc,
1141 u_int32_t paramptr, u_int8_t *param_buf,
1142 u_int32_t param_len, u_int8_t sense_len,
1145 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
1146 void (*cbfcnp)(struct cam_periph *,
1147 union ccb *), u_int8_t tag_action,
1148 u_int8_t page_code, int save_pages,
1149 int pc_reset, u_int8_t *param_buf,
1150 u_int32_t param_len, u_int8_t sense_len,
1153 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
1154 void (*cbfcnp)(struct cam_periph *, union ccb *),
1155 u_int8_t tag_action, u_int8_t action,
1156 u_int8_t sense_len, u_int32_t timeout);
1158 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
1159 void (*cbfcnp)(struct cam_periph *,
1160 union ccb *), u_int8_t tag_action,
1161 struct scsi_read_capacity_data *,
1162 u_int8_t sense_len, u_int32_t timeout);
1163 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
1164 void (*cbfcnp)(struct cam_periph *,
1165 union ccb *), uint8_t tag_action,
1166 uint64_t lba, int reladr, int pmi,
1167 struct scsi_read_capacity_data_long
1168 *rcap_buf, uint8_t sense_len,
1171 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
1172 void (*cbfcnp)(struct cam_periph *,
1173 union ccb *), u_int8_t tag_action,
1174 u_int8_t select_report,
1175 struct scsi_report_luns_data *rpl_buf,
1176 u_int32_t alloc_len, u_int8_t sense_len,
1179 void scsi_synchronize_cache(struct ccb_scsiio *csio,
1181 void (*cbfcnp)(struct cam_periph *,
1182 union ccb *), u_int8_t tag_action,
1183 u_int32_t begin_lba, u_int16_t lb_count,
1184 u_int8_t sense_len, u_int32_t timeout);
1186 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
1187 void (*cbfcnp)(struct cam_periph *, union ccb *),
1188 u_int8_t tag_action, int readop, u_int8_t byte2,
1189 int minimum_cmd_size, u_int64_t lba,
1190 u_int32_t block_count, u_int8_t *data_ptr,
1191 u_int32_t dxfer_len, u_int8_t sense_len,
1194 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
1195 void (*cbfcnp)(struct cam_periph *, union ccb *),
1196 u_int8_t tag_action, int start, int load_eject,
1197 int immediate, u_int8_t sense_len, u_int32_t timeout);
1199 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
1200 int scsi_static_inquiry_match(caddr_t inqbuffer,
1201 caddr_t table_entry);
1203 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1204 int *error_code, int *sense_key,
1205 int *asc, int *ascq);
1206 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
1207 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
1208 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
1209 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
1210 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
1211 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
1212 static __inline int32_t scsi_3btol(u_int8_t *bytes);
1213 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
1214 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes);
1215 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
1216 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
1218 static __inline void
1219 scsi_extract_sense(struct scsi_sense_data *sense, int *error_code,
1220 int *sense_key, int *asc, int *ascq)
1222 *error_code = sense->error_code & SSD_ERRCODE;
1223 *sense_key = sense->flags & SSD_KEY;
1224 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
1225 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
1228 static __inline void
1229 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
1232 bytes[0] = (val >> 8) & 0xff;
1233 bytes[1] = val & 0xff;
1236 static __inline void
1237 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
1240 bytes[0] = (val >> 16) & 0xff;
1241 bytes[1] = (val >> 8) & 0xff;
1242 bytes[2] = val & 0xff;
1245 static __inline void
1246 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
1249 bytes[0] = (val >> 24) & 0xff;
1250 bytes[1] = (val >> 16) & 0xff;
1251 bytes[2] = (val >> 8) & 0xff;
1252 bytes[3] = val & 0xff;
1255 static __inline void
1256 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
1258 bytes[0] = (val >> 56) & 0xff;
1259 bytes[1] = (val >> 48) & 0xff;
1260 bytes[2] = (val >> 40) & 0xff;
1261 bytes[3] = (val >> 32) & 0xff;
1262 bytes[4] = (val >> 24) & 0xff;
1263 bytes[5] = (val >> 16) & 0xff;
1264 bytes[6] = (val >> 8) & 0xff;
1265 bytes[7] = val & 0xff;
1268 static __inline u_int32_t
1269 scsi_2btoul(u_int8_t *bytes)
1273 rv = (bytes[0] << 8) |
1278 static __inline uint64_t
1279 scsi_8btou64(uint8_t *bytes)
1283 rv = (((uint64_t)bytes[0]) << 56) |
1284 (((uint64_t)bytes[1]) << 48) |
1285 (((uint64_t)bytes[2]) << 40) |
1286 (((uint64_t)bytes[3]) << 32) |
1287 (((uint64_t)bytes[4]) << 24) |
1288 (((uint64_t)bytes[5]) << 16) |
1289 (((uint64_t)bytes[6]) << 8) |
1294 static __inline u_int32_t
1295 scsi_3btoul(u_int8_t *bytes)
1299 rv = (bytes[0] << 16) |
1305 static __inline int32_t
1306 scsi_3btol(u_int8_t *bytes)
1308 u_int32_t rc = scsi_3btoul(bytes);
1310 if (rc & 0x00800000)
1313 return (int32_t) rc;
1316 static __inline u_int32_t
1317 scsi_4btoul(u_int8_t *bytes)
1321 rv = (bytes[0] << 24) |
1329 * Given the pointer to a returned mode sense buffer, return a pointer to
1330 * the start of the first mode page.
1332 static __inline void *
1333 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
1337 page_start = (void *)((u_int8_t *)&mode_header[1] +
1338 mode_header->blk_desc_len);
1343 static __inline void *
1344 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
1348 page_start = (void *)((u_int8_t *)&mode_header[1] +
1349 scsi_2btoul(mode_header->blk_desc_len));
1356 #endif /*_SCSI_SCSI_ALL_H*/