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>
28 #include <machine/stdarg.h>
32 * This is the number of seconds we wait for devices to settle after a SCSI
35 extern int scsi_delay;
43 * Define dome bits that are in ALL (or a lot of) scsi commands
45 #define SCSI_CTL_LINK 0x01
46 #define SCSI_CTL_FLAG 0x02
47 #define SCSI_CTL_VENDOR 0xC0
48 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */
49 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */
51 #define SCSI_MAX_CDBLEN 16 /*
52 * 16 byte commands are in the
55 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN)
56 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN"
59 /* 6byte CDBs special case 0 length to be 256 */
60 #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len)
63 * This type defines actions to be taken when a particular sense code is
64 * received. Right now, these flags are only defined to take up 16 bits,
65 * but can be expanded in the future if necessary.
68 SS_NOP = 0x000000, /* Do nothing */
69 SS_RETRY = 0x010000, /* Retry the command */
70 SS_FAIL = 0x020000, /* Bail out */
71 SS_START = 0x030000, /* Send a Start Unit command to the device,
72 * then retry the original command.
74 SS_TUR = 0x040000, /* Send a Test Unit Ready command to the
75 * device, then retry the original command.
77 SS_REQSENSE = 0x050000, /* Send a RequestSense command to the
78 * device, then retry the original command.
85 SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */
86 SSQ_MANY = 0x0200, /* send lots of recovery commands */
87 SSQ_RANGE = 0x0400, /*
88 * This table entry represents the
89 * end of a range of ASCQs that
90 * have identical error actions
93 SSQ_PRINT_SENSE = 0x0800,
95 } scsi_sense_action_qualifier;
97 /* Mask for error status values */
98 #define SS_ERRMASK 0xff
100 /* The default, retyable, error action */
101 #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
103 /* The retyable, error action, with table specified error code */
104 #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
106 /* Fatal error action, with table specified error code */
107 #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE
115 struct scsi_request_sense
119 #define SRS_DESC 0x01
125 struct scsi_test_unit_ready
133 struct scsi_receive_diag {
142 struct scsi_send_diag {
145 #define SSD_UNITOFFL 0x01
146 #define SSD_DEVOFFL 0x02
147 #define SSD_SELFTEST 0x04
149 #define SSD_SELF_TEST_CODE_MASK 0xE0
150 #define SSD_SELF_TEST_CODE_SHIFT 5
151 #define SSD_SELF_TEST_CODE_NONE 0x00
152 #define SSD_SELF_TEST_CODE_BG_SHORT 0x01
153 #define SSD_SELF_TEST_CODE_BG_EXTENDED 0x02
154 #define SSD_SELF_TEST_CODE_BG_ABORT 0x04
155 #define SSD_SELF_TEST_CODE_FG_SHORT 0x05
156 #define SSD_SELF_TEST_CODE_FG_EXTENDED 0x06
176 #define SI_CMDDT 0x02
183 struct scsi_mode_sense_6
189 #define SMS_PAGE_CODE 0x3F
190 #define SMS_VENDOR_SPECIFIC_PAGE 0x00
191 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02
192 #define SMS_FORMAT_DEVICE_PAGE 0x03
193 #define SMS_GEOMETRY_PAGE 0x04
194 #define SMS_CACHE_PAGE 0x08
195 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
196 #define SMS_CONTROL_MODE_PAGE 0x0A
197 #define SMS_PROTO_SPECIFIC_PAGE 0x19
198 #define SMS_INFO_EXCEPTIONS_PAGE 0x1C
199 #define SMS_ALL_PAGES_PAGE 0x3F
200 #define SMS_PAGE_CTRL_MASK 0xC0
201 #define SMS_PAGE_CTRL_CURRENT 0x00
202 #define SMS_PAGE_CTRL_CHANGEABLE 0x40
203 #define SMS_PAGE_CTRL_DEFAULT 0x80
204 #define SMS_PAGE_CTRL_SAVED 0xC0
206 #define SMS_SUBPAGE_PAGE_0 0x00
207 #define SMS_SUBPAGE_ALL 0xff
212 struct scsi_mode_sense_10
215 u_int8_t byte2; /* same bits as small version */
216 #define SMS10_LLBAA 0x10
217 u_int8_t page; /* same bits as small version */
224 struct scsi_mode_select_6
235 struct scsi_mode_select_10
238 u_int8_t byte2; /* same bits as small version */
245 * When sending a mode select to a tape drive, the medium type must be 0.
247 struct scsi_mode_hdr_6
250 u_int8_t medium_type;
251 u_int8_t dev_specific;
252 u_int8_t block_descr_len;
255 struct scsi_mode_hdr_10
258 u_int8_t medium_type;
259 u_int8_t dev_specific;
260 u_int8_t reserved[2];
261 u_int8_t block_descr_len[2];
264 struct scsi_mode_block_descr
266 u_int8_t density_code;
267 u_int8_t num_blocks[3];
269 u_int8_t block_len[3];
272 struct scsi_per_res_in
280 u_int8_t reserved[5];
285 struct scsi_per_res_in_header
287 u_int8_t generation[4];
291 struct scsi_per_res_key
296 struct scsi_per_res_in_keys
298 struct scsi_per_res_in_header header;
299 struct scsi_per_res_key keys[0];
302 struct scsi_per_res_cap
306 #define SPRI_CRH 0x10
307 #define SPRI_SIP_C 0x08
308 #define SPRI_ATP_C 0x04
309 #define SPRI_PTPL_C 0x01
311 #define SPRI_TMV 0x80
312 #define SPRI_PTPL_A 0x01
313 uint8_t type_mask[2];
314 #define SPRI_TM_WR_EX_AR 0x8000
315 #define SPRI_TM_EX_AC_RO 0x4000
316 #define SPRI_TM_WR_EX_RO 0x2000
317 #define SPRI_TM_EX_AC 0x0800
318 #define SPRI_TM_WR_EX 0x0200
319 #define SPRI_TM_EX_AC_AR 0x0001
323 struct scsi_per_res_in_rsrv_data
325 uint8_t reservation[8];
326 uint8_t obsolete1[4];
331 #define SPRT_WERO 0x05
332 #define SPRT_EARO 0x06
333 #define SPRT_WEAR 0x07
334 #define SPRT_EAAR 0x08
335 uint8_t obsolete2[2];
338 struct scsi_per_res_in_rsrv
340 struct scsi_per_res_in_header header;
341 struct scsi_per_res_in_rsrv_data data;
344 struct scsi_per_res_out
348 #define SPRO_REGISTER 0x00
349 #define SPRO_RESERVE 0x01
350 #define SPRO_RELEASE 0x02
351 #define SPRO_CLEAR 0x03
352 #define SPRO_PREEMPT 0x04
353 #define SPRO_PRE_ABO 0x05
354 #define SPRO_REG_IGNO 0x06
355 #define SPRO_REG_MOVE 0x07
356 #define SPRO_ACTION_MASK 0x1f
358 #define SPR_SCOPE_MASK 0xf0
359 #define SPR_LU_SCOPE 0x00
360 #define SPR_TYPE_MASK 0x0f
361 #define SPR_TYPE_WR_EX 0x01
362 #define SPR_TYPE_EX_AC 0x03
363 #define SPR_TYPE_WR_EX_RO 0x05
364 #define SPR_TYPE_EX_AC_RO 0x06
365 #define SPR_TYPE_WR_EX_AR 0x07
366 #define SPR_TYPE_EX_AC_AR 0x08
367 u_int8_t reserved[2];
372 struct scsi_per_res_out_parms
374 struct scsi_per_res_key res_key;
375 u_int8_t serv_act_res_key[8];
376 u_int8_t obsolete1[4];
378 #define SPR_SPEC_I_PT 0x08
379 #define SPR_ALL_TG_PT 0x04
380 #define SPR_APTPL 0x01
382 u_int8_t obsolete2[2];
386 struct scsi_log_sense
393 #define SLS_PAGE_CODE 0x3F
394 #define SLS_ALL_PAGES_PAGE 0x00
395 #define SLS_OVERRUN_PAGE 0x01
396 #define SLS_ERROR_WRITE_PAGE 0x02
397 #define SLS_ERROR_READ_PAGE 0x03
398 #define SLS_ERROR_READREVERSE_PAGE 0x04
399 #define SLS_ERROR_VERIFY_PAGE 0x05
400 #define SLS_ERROR_NONMEDIUM_PAGE 0x06
401 #define SLS_ERROR_LASTN_PAGE 0x07
402 #define SLS_SELF_TEST_PAGE 0x10
403 #define SLS_IE_PAGE 0x2f
404 #define SLS_PAGE_CTRL_MASK 0xC0
405 #define SLS_PAGE_CTRL_THRESHOLD 0x00
406 #define SLS_PAGE_CTRL_CUMULATIVE 0x40
407 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
408 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
409 u_int8_t reserved[2];
410 u_int8_t paramptr[2];
415 struct scsi_log_select
422 /* SLS_PAGE_CTRL_MASK 0xC0 */
423 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */
424 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
425 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
426 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
427 u_int8_t reserved[4];
432 struct scsi_log_header
439 struct scsi_log_param_header {
440 u_int8_t param_code[2];
441 u_int8_t param_control;
443 #define SLP_LBIN 0x02
444 #define SLP_TMC_MASK 0x0C
445 #define SLP_TMC_ALWAYS 0x00
446 #define SLP_TMC_EQUAL 0x04
447 #define SLP_TMC_NOTEQUAL 0x08
448 #define SLP_TMC_GREATER 0x0C
456 struct scsi_control_page {
458 u_int8_t page_length;
460 #define SCP_RLEC 0x01 /*Report Log Exception Cond*/
461 #define SCP_GLTSD 0x02 /*Global Logging target
463 #define SCP_DSENSE 0x04 /*Descriptor Sense */
464 #define SCP_DPICZ 0x08 /*Disable Prot. Info Check
465 if Prot. Field is Zero */
466 #define SCP_TMF_ONLY 0x10 /*TM Functions Only*/
467 #define SCP_TST_MASK 0xE0 /*Task Set Type Mask*/
468 #define SCP_TST_ONE 0x00 /*One Task Set*/
469 #define SCP_TST_SEPARATE 0x20 /*Separate Task Sets*/
470 u_int8_t queue_flags;
471 #define SCP_QUEUE_ALG_MASK 0xF0
472 #define SCP_QUEUE_ALG_RESTRICTED 0x00
473 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
474 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
475 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
476 u_int8_t eca_and_aen;
477 #define SCP_EECA 0x80 /*Enable Extended CA*/
478 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
479 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
480 #define SCP_EAENP 0x01 /*Error AEN Permission*/
482 u_int8_t aen_holdoff_period[2];
485 struct scsi_cache_page {
487 #define SCHP_PAGE_SAVABLE 0x80 /* Page is savable */
488 u_int8_t page_length;
489 u_int8_t cache_flags;
490 #define SCHP_FLAGS_WCE 0x04 /* Write Cache Enable */
491 #define SCHP_FLAGS_MF 0x02 /* Multiplication factor */
492 #define SCHP_FLAGS_RCD 0x01 /* Read Cache Disable */
493 u_int8_t rw_cache_policy;
494 u_int8_t dis_prefetch[2];
495 u_int8_t min_prefetch[2];
496 u_int8_t max_prefetch[2];
497 u_int8_t max_prefetch_ceil[2];
502 * Updated version of the cache page, as of SBC. Update this to SBC-3 and
503 * rationalize the two.
505 struct scsi_caching_page {
507 #define SMS_CACHING_PAGE 0x08
511 #define SCP_ABPF 0x40
513 #define SCP_DISC 0x10
514 #define SCP_SIZE 0x08
518 uint8_t ret_priority;
519 uint8_t disable_pf_transfer_len[2];
520 uint8_t min_prefetch[2];
521 uint8_t max_prefetch[2];
522 uint8_t max_pf_ceiling[2];
525 #define SCP_LBCSS 0x40
529 uint8_t cache_segments;
530 uint8_t cache_seg_size[2];
532 uint8_t non_cache_seg_size[3];
535 struct scsi_info_exceptions_page {
537 #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */
538 u_int8_t page_length;
540 #define SIEP_FLAGS_PERF 0x80
541 #define SIEP_FLAGS_EBF 0x20
542 #define SIEP_FLAGS_EWASC 0x10
543 #define SIEP_FLAGS_DEXCPT 0x08
544 #define SIEP_FLAGS_TEST 0x04
545 #define SIEP_FLAGS_EBACKERR 0x02
546 #define SIEP_FLAGS_LOGERR 0x01
548 u_int8_t interval_timer[4];
549 u_int8_t report_count[4];
552 struct scsi_proto_specific_page {
554 #define SPSP_PAGE_SAVABLE 0x80 /* Page is savable */
555 u_int8_t page_length;
557 #define SPSP_PROTO_FC 0x00
558 #define SPSP_PROTO_SPI 0x01
559 #define SPSP_PROTO_SSA 0x02
560 #define SPSP_PROTO_1394 0x03
561 #define SPSP_PROTO_RDMA 0x04
562 #define SPSP_PROTO_ISCSI 0x05
563 #define SPSP_PROTO_SAS 0x06
564 #define SPSP_PROTO_ADT 0x07
565 #define SPSP_PROTO_ATA 0x08
566 #define SPSP_PROTO_NONE 0x0f
573 #define SR_EXTENT 0x01
574 #define SR_ID_MASK 0x0e
575 #define SR_3RDPTY 0x10
576 #define SR_LUN_MASK 0xe0
582 struct scsi_reserve_10 {
585 #define SR10_3RDPTY 0x10
586 #define SR10_LONGID 0x02
587 #define SR10_EXTENT 0x01
589 uint8_t thirdparty_id;
606 struct scsi_release_10 {
610 uint8_t thirdparty_id;
624 #define PR_PREVENT 0x01
625 #define PR_ALLOW 0x00
627 struct scsi_sync_cache
631 #define SSC_IMMED 0x02
632 #define SSC_RELADR 0x01
633 u_int8_t begin_lba[4];
635 u_int8_t lb_count[2];
639 struct scsi_sync_cache_16
643 uint8_t begin_lba[8];
652 #define SF_LONGLIST 0x20
653 #define SF_FMTDATA 0x10
654 #define SF_CMPLIST 0x08
655 #define SF_FORMAT_MASK 0x07
656 #define SF_FORMAT_BLOCK 0x00
657 #define SF_FORMAT_LONG_BLOCK 0x03
658 #define SF_FORMAT_BFI 0x04
659 #define SF_FORMAT_PHYS 0x05
661 uint8_t interleave[2];
665 struct scsi_format_header_short {
667 #define SF_DATA_FOV 0x80
668 #define SF_DATA_DPRY 0x40
669 #define SF_DATA_DCRT 0x20
670 #define SF_DATA_STPF 0x10
671 #define SF_DATA_IP 0x08
672 #define SF_DATA_DSP 0x04
673 #define SF_DATA_IMMED 0x02
674 #define SF_DATA_VS 0x01
676 uint8_t defect_list_len[2];
679 struct scsi_format_header_long {
682 uint8_t reserved2[2];
683 uint8_t defect_list_len[4];
686 struct scsi_changedef
697 struct scsi_read_buffer
701 #define RWB_MODE 0x07
702 #define RWB_MODE_HDR_DATA 0x00
703 #define RWB_MODE_VENDOR 0x01
704 #define RWB_MODE_DATA 0x02
705 #define RWB_MODE_DOWNLOAD 0x04
706 #define RWB_MODE_DOWNLOAD_SAVE 0x05
713 struct scsi_write_buffer
727 /* only 5 bits are valid in the MSB address byte */
728 #define SRW_TOPADDR 0x1F
736 #define SRW10_RELADDR 0x01
737 /* EBP defined for WRITE(10) only */
738 #define SRW10_EBP 0x04
739 #define SRW10_FUA 0x08
740 #define SRW10_DPO 0x10
751 #define SRW12_RELADDR 0x01
752 #define SRW12_FUA 0x08
753 #define SRW12_DPO 0x10
764 #define SRW16_RELADDR 0x01
765 #define SRW16_FUA 0x08
766 #define SRW16_DPO 0x10
774 struct scsi_write_verify_10
778 #define SWV_BYTCHK 0x02
780 #define SWV_WRPROECT_MASK 0xe0
787 struct scsi_write_verify_12
797 struct scsi_write_verify_16
808 struct scsi_start_stop_unit
812 #define SSS_IMMED 0x01
813 u_int8_t reserved[2];
815 #define SSS_START 0x01
816 #define SSS_LOEJ 0x02
817 #define SSS_PC_MASK 0xf0
818 #define SSS_PC_START_VALID 0x00
819 #define SSS_PC_ACTIVE 0x10
820 #define SSS_PC_IDLE 0x20
821 #define SSS_PC_STANDBY 0x30
822 #define SSS_PC_LU_CONTROL 0x70
823 #define SSS_PC_FORCE_IDLE_0 0xa0
824 #define SSS_PC_FORCE_STANDBY_0 0xb0
831 #define AP_MULTI 0xe0
833 #define AP_T_LEN 0x03
835 #define AP_T_DIR 0x08
836 #define AP_CK_COND 0x20
837 #define AP_OFFLINE 0x60
839 u_int8_t sector_count;
849 struct scsi_maintenance_in
853 #define SERVICE_ACTION_MASK 0x1f
854 #define SA_RPRT_TRGT_GRP 0x0a
864 #define AP_EXTEND 0x01
866 u_int8_t features_ext;
868 u_int8_t sector_count_ext;
869 u_int8_t sector_count;
870 u_int8_t lba_low_ext;
872 u_int8_t lba_mid_ext;
874 u_int8_t lba_high_ext;
881 #define SC_SCSI_1 0x01
882 #define SC_SCSI_2 0x03
888 #define TEST_UNIT_READY 0x00
889 #define REQUEST_SENSE 0x03
893 #define MODE_SELECT_6 0x15
894 #define MODE_SENSE_6 0x1A
895 #define START_STOP_UNIT 0x1B
896 #define START_STOP 0x1B
899 #define RECEIVE_DIAGNOSTIC 0x1C
900 #define SEND_DIAGNOSTIC 0x1D
901 #define PREVENT_ALLOW 0x1E
902 #define READ_CAPACITY 0x25
904 #define WRITE_10 0x2A
905 #define POSITION_TO_ELEMENT 0x2B
906 #define WRITE_VERIFY_10 0x2E
907 #define SYNCHRONIZE_CACHE 0x35
908 #define READ_DEFECT_DATA_10 0x37
909 #define WRITE_BUFFER 0x3B
910 #define READ_BUFFER 0x3C
911 #define CHANGE_DEFINITION 0x40
912 #define LOG_SELECT 0x4C
913 #define LOG_SENSE 0x4D
914 #define MODE_SELECT_10 0x55
915 #define RESERVE_10 0x56
916 #define RELEASE_10 0x57
917 #define MODE_SENSE_10 0x5A
918 #define PERSISTENT_RES_IN 0x5E
919 #define PERSISTENT_RES_OUT 0x5F
920 #define ATA_PASS_16 0x85
922 #define WRITE_16 0x8A
923 #define WRITE_VERIFY_16 0x8E
924 #define SYNCHRONIZE_CACHE_16 0x91
925 #define SERVICE_ACTION_IN 0x9E
926 #define REPORT_LUNS 0xA0
927 #define ATA_PASS_12 0xA1
928 #define MAINTENANCE_IN 0xA3
929 #define MAINTENANCE_OUT 0xA4
930 #define MOVE_MEDIUM 0xA5
932 #define WRITE_12 0xAA
933 #define WRITE_VERIFY_12 0xAE
934 #define READ_ELEMENT_STATUS 0xB8
936 /* Maintenance In Service Action Codes */
937 #define REPORT_IDENTIFYING_INFRMATION 0x05
938 #define REPORT_TARGET_PORT_GROUPS 0x0A
939 #define REPORT_ALIASES 0x0B
940 #define REPORT_SUPPORTED_OPERATION_CODES 0x0C
941 #define REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0D
942 #define REPORT_PRIORITY 0x0E
943 #define REPORT_TIMESTAMP 0x0F
944 #define MANAGEMENT_PROTOCOL_IN 0x10
945 /* Maintenance Out Service Action Codes */
946 #define SET_IDENTIFY_INFORMATION 0x06
947 #define SET_TARGET_PORT_GROUPS 0x0A
948 #define CHANGE_ALIASES 0x0B
949 #define SET_PRIORITY 0x0E
950 #define SET_TIMESTAMP 0x0F
951 #define MANGAEMENT_PROTOCOL_OUT 0x10
956 #define T_DIRECT 0x00
957 #define T_SEQUENTIAL 0x01
958 #define T_PRINTER 0x02
959 #define T_PROCESSOR 0x03
962 #define T_SCANNER 0x06
963 #define T_OPTICAL 0x07
964 #define T_CHANGER 0x08
968 #define T_STORARRAY 0x0c
969 #define T_ENCLOSURE 0x0d
974 #define T_NODEVICE 0x1f
975 #define T_ANY 0xff /* Used in Quirk table matches */
981 * This length is the initial inquiry length used by the probe code, as
982 * well as the legnth necessary for scsi_print_inquiry() to function
983 * correctly. If either use requires a different length in the future,
984 * the two values should be de-coupled.
986 #define SHORT_INQUIRY_LENGTH 36
988 struct scsi_inquiry_data
991 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
992 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
993 #define SID_QUAL_LU_CONNECTED 0x00 /*
994 * The specified peripheral device
995 * type is currently connected to
996 * logical unit. If the target cannot
997 * determine whether or not a physical
998 * device is currently connected, it
999 * shall also use this peripheral
1000 * qualifier when returning the INQUIRY
1001 * data. This peripheral qualifier
1002 * does not mean that the device is
1003 * ready for access by the initiator.
1005 #define SID_QUAL_LU_OFFLINE 0x01 /*
1006 * The target is capable of supporting
1007 * the specified peripheral device type
1008 * on this logical unit; however, the
1009 * physical device is not currently
1010 * connected to this logical unit.
1012 #define SID_QUAL_RSVD 0x02
1013 #define SID_QUAL_BAD_LU 0x03 /*
1014 * The target is not capable of
1015 * supporting a physical device on
1016 * this logical unit. For this
1017 * peripheral qualifier the peripheral
1018 * device type shall be set to 1Fh to
1019 * provide compatibility with previous
1020 * versions of SCSI. All other
1021 * peripheral device type values are
1022 * reserved for this peripheral
1025 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
1027 #define SID_QUAL2 0x7F
1028 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
1030 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
1031 #define SCSI_REV_0 0
1032 #define SCSI_REV_CCS 1
1033 #define SCSI_REV_2 2
1034 #define SCSI_REV_SPC 3
1035 #define SCSI_REV_SPC2 4
1036 #define SCSI_REV_SPC3 5
1037 #define SCSI_REV_SPC4 6
1039 #define SID_ECMA 0x38
1040 #define SID_ISO 0xC0
1041 u_int8_t response_format;
1042 #define SID_AENC 0x80
1043 #define SID_TrmIOP 0x40
1044 #define SID_NormACA 0x20
1045 #define SID_HiSup 0x10
1046 u_int8_t additional_length;
1047 #define SID_ADDITIONAL_LENGTH(iqd) \
1048 ((iqd)->additional_length + \
1049 __offsetof(struct scsi_inquiry_data, additional_length) + 1)
1050 u_int8_t spc3_flags;
1051 #define SPC3_SID_PROTECT 0x01
1052 #define SPC3_SID_3PC 0x08
1053 #define SPC3_SID_TPGS_MASK 0x30
1054 #define SPC3_SID_TPGS_IMPLICIT 0x10
1055 #define SPC3_SID_TPGS_EXPLICIT 0x20
1056 #define SPC3_SID_ACC 0x40
1057 #define SPC3_SID_SCCS 0x80
1058 u_int8_t spc2_flags;
1059 #define SPC2_SID_ADDR16 0x01
1060 #define SPC2_SID_MChngr 0x08
1061 #define SPC2_SID_MultiP 0x10
1062 #define SPC2_SID_EncServ 0x40
1063 #define SPC2_SID_BQueue 0x80
1065 #define INQ_DATA_TQ_ENABLED(iqd) \
1066 ((SID_ANSI_REV(iqd) < SCSI_REV_SPC2)? ((iqd)->flags & SID_CmdQue) : \
1067 (((iqd)->flags & SID_CmdQue) && !((iqd)->spc2_flags & SPC2_SID_BQueue)) || \
1068 (!((iqd)->flags & SID_CmdQue) && ((iqd)->spc2_flags & SPC2_SID_BQueue)))
1071 #define SID_SftRe 0x01
1072 #define SID_CmdQue 0x02
1073 #define SID_Linked 0x08
1074 #define SID_Sync 0x10
1075 #define SID_WBus16 0x20
1076 #define SID_WBus32 0x40
1077 #define SID_RelAdr 0x80
1078 #define SID_VENDOR_SIZE 8
1079 char vendor[SID_VENDOR_SIZE];
1080 #define SID_PRODUCT_SIZE 16
1081 char product[SID_PRODUCT_SIZE];
1082 #define SID_REVISION_SIZE 4
1083 char revision[SID_REVISION_SIZE];
1085 * The following fields were taken from SCSI Primary Commands - 2
1086 * (SPC-2) Revision 14, Dated 11 November 1999
1088 #define SID_VENDOR_SPECIFIC_0_SIZE 20
1089 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
1091 * An extension of SCSI Parallel Specific Values
1093 #define SID_SPI_IUS 0x01
1094 #define SID_SPI_QAS 0x02
1095 #define SID_SPI_CLOCK_ST 0x00
1096 #define SID_SPI_CLOCK_DT 0x04
1097 #define SID_SPI_CLOCK_DT_ST 0x0C
1098 #define SID_SPI_MASK 0x0F
1102 * Version Descriptors, stored 2 byte values.
1104 u_int8_t version1[2];
1105 u_int8_t version2[2];
1106 u_int8_t version3[2];
1107 u_int8_t version4[2];
1108 u_int8_t version5[2];
1109 u_int8_t version6[2];
1110 u_int8_t version7[2];
1111 u_int8_t version8[2];
1113 u_int8_t reserved3[22];
1115 #define SID_VENDOR_SPECIFIC_1_SIZE 160
1116 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
1120 * This structure is more suited to initiator operation, because the
1121 * maximum number of supported pages is already allocated.
1123 struct scsi_vpd_supported_page_list
1127 #define SVPD_SUPPORTED_PAGE_LIST 0x00
1128 #define SVPD_SUPPORTED_PAGES_HDR_LEN 4
1130 u_int8_t length; /* number of VPD entries */
1131 #define SVPD_SUPPORTED_PAGES_SIZE 251
1132 u_int8_t list[SVPD_SUPPORTED_PAGES_SIZE];
1136 * This structure is more suited to target operation, because the
1137 * number of supported pages is left to the user to allocate.
1139 struct scsi_vpd_supported_pages
1144 #define SVPD_SUPPORTED_PAGES 0x00
1146 u_int8_t page_list[0];
1150 struct scsi_vpd_unit_serial_number
1154 #define SVPD_UNIT_SERIAL_NUMBER 0x80
1156 u_int8_t length; /* serial number length */
1157 #define SVPD_SERIAL_NUM_SIZE 251
1158 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
1161 struct scsi_vpd_device_id
1165 #define SVPD_DEVICE_ID 0x83
1166 #define SVPD_DEVICE_ID_MAX_SIZE 252
1167 #define SVPD_DEVICE_ID_HDR_LEN \
1168 __offsetof(struct scsi_vpd_device_id, desc_list)
1170 u_int8_t desc_list[];
1173 struct scsi_vpd_id_descriptor
1175 u_int8_t proto_codeset;
1176 #define SCSI_PROTO_FC 0x00
1177 #define SCSI_PROTO_SPI 0x01
1178 #define SCSI_PROTO_SSA 0x02
1179 #define SCSI_PROTO_1394 0x03
1180 #define SCSI_PROTO_RDMA 0x04
1181 #define SCSI_PROTO_iSCSI 0x05
1182 #define SCSI_PROTO_SAS 0x06
1183 #define SVPD_ID_PROTO_SHIFT 4
1184 #define SVPD_ID_CODESET_BINARY 0x01
1185 #define SVPD_ID_CODESET_ASCII 0x02
1186 #define SVPD_ID_CODESET_MASK 0x0f
1188 #define SVPD_ID_PIV 0x80
1189 #define SVPD_ID_ASSOC_LUN 0x00
1190 #define SVPD_ID_ASSOC_PORT 0x10
1191 #define SVPD_ID_ASSOC_TARGET 0x20
1192 #define SVPD_ID_ASSOC_MASK 0x30
1193 #define SVPD_ID_TYPE_VENDOR 0x00
1194 #define SVPD_ID_TYPE_T10 0x01
1195 #define SVPD_ID_TYPE_EUI64 0x02
1196 #define SVPD_ID_TYPE_NAA 0x03
1197 #define SVPD_ID_TYPE_RELTARG 0x04
1198 #define SVPD_ID_TYPE_TPORTGRP 0x05
1199 #define SVPD_ID_TYPE_LUNGRP 0x06
1200 #define SVPD_ID_TYPE_MD5_LUN_ID 0x07
1201 #define SVPD_ID_TYPE_SCSI_NAME 0x08
1202 #define SVPD_ID_TYPE_MASK 0x0f
1205 #define SVPD_DEVICE_ID_DESC_HDR_LEN \
1206 __offsetof(struct scsi_vpd_id_descriptor, identifier)
1207 u_int8_t identifier[];
1210 struct scsi_vpd_id_t10
1213 u_int8_t vendor_spec_id[0];
1216 struct scsi_vpd_id_eui64
1218 u_int8_t ieee_company_id[3];
1219 u_int8_t extension_id[5];
1222 struct scsi_vpd_id_naa_basic
1225 /* big endian, packed:
1227 uint8_t naa_desig : 4;
1229 #define SVPD_ID_NAA_NAA_SHIFT 4
1230 #define SVPD_ID_NAA_IEEE_EXT 0x02
1231 #define SVPD_ID_NAA_LOCAL_REG 0x03
1232 #define SVPD_ID_NAA_IEEE_REG 0x05
1233 #define SVPD_ID_NAA_IEEE_REG_EXT 0x06
1237 struct scsi_vpd_id_naa_ieee_extended_id
1240 uint8_t vendor_specific_id_a;
1241 uint8_t ieee_company_id[3];
1242 uint8_t vendor_specific_id_b[4];
1245 struct scsi_vpd_id_naa_local_reg
1248 uint8_t local_value[7];
1251 struct scsi_vpd_id_naa_ieee_reg
1254 uint8_t reg_value[7];
1255 /* big endian, packed:
1256 uint8_t naa_basic : 4;
1257 uint8_t ieee_company_id_0 : 4;
1258 uint8_t ieee_company_id_1[2];
1259 uint8_t ieee_company_id_2 : 4;
1260 uint8_t vendor_specific_id_0 : 4;
1261 uint8_t vendor_specific_id_1[4];
1265 struct scsi_vpd_id_naa_ieee_reg_extended
1268 uint8_t reg_value[15];
1269 /* big endian, packed:
1270 uint8_t naa_basic : 4;
1271 uint8_t ieee_company_id_0 : 4;
1272 uint8_t ieee_company_id_1[2];
1273 uint8_t ieee_company_id_2 : 4;
1274 uint8_t vendor_specific_id_0 : 4;
1275 uint8_t vendor_specific_id_1[4];
1276 uint8_t vendor_specific_id_ext[8];
1280 struct scsi_vpd_id_rel_trgt_port_id
1282 uint8_t obsolete[2];
1283 uint8_t rel_trgt_port_id[2];
1286 struct scsi_vpd_id_trgt_port_grp_id
1288 uint8_t reserved[2];
1289 uint8_t trgt_port_grp[2];
1292 struct scsi_vpd_id_lun_grp_id
1294 uint8_t reserved[2];
1295 uint8_t log_unit_grp[2];
1298 struct scsi_vpd_id_md5_lun_id
1303 struct scsi_vpd_id_scsi_name
1305 uint8_t name_string[256];
1308 struct scsi_service_action_in
1311 uint8_t service_action;
1312 uint8_t action_dependent[13];
1316 struct scsi_read_capacity
1320 #define SRC_RELADR 0x01
1324 #define SRC_PMI 0x01
1328 struct scsi_read_capacity_16
1331 #define SRC16_SERVICE_ACTION 0x10
1332 uint8_t service_action;
1334 uint8_t alloc_len[4];
1335 #define SRC16_PMI 0x01
1336 #define SRC16_RELADR 0x02
1341 struct scsi_read_capacity_data
1347 struct scsi_read_capacity_data_long
1353 struct scsi_report_luns
1357 #define RPL_REPORT_DEFAULT 0x00
1358 #define RPL_REPORT_WELLKNOWN 0x01
1359 #define RPL_REPORT_ALL 0x02
1360 uint8_t select_report;
1361 uint8_t reserved2[3];
1367 struct scsi_report_luns_lundata {
1369 #define RPL_LUNDATA_PERIPH_BUS_MASK 0x3f
1370 #define RPL_LUNDATA_FLAT_LUN_MASK 0x3f
1371 #define RPL_LUNDATA_FLAT_LUN_BITS 0x06
1372 #define RPL_LUNDATA_LUN_TARG_MASK 0x3f
1373 #define RPL_LUNDATA_LUN_BUS_MASK 0xe0
1374 #define RPL_LUNDATA_LUN_LUN_MASK 0x1f
1375 #define RPL_LUNDATA_EXT_LEN_MASK 0x30
1376 #define RPL_LUNDATA_EXT_EAM_MASK 0x0f
1377 #define RPL_LUNDATA_EXT_EAM_WK 0x01
1378 #define RPL_LUNDATA_EXT_EAM_NOT_SPEC 0x0f
1379 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
1380 #define RPL_LUNDATA_ATYP_PERIPH 0x00
1381 #define RPL_LUNDATA_ATYP_FLAT 0x40
1382 #define RPL_LUNDATA_ATYP_LUN 0x80
1383 #define RPL_LUNDATA_ATYP_EXTLUN 0xc0
1386 struct scsi_report_luns_data {
1387 u_int8_t length[4]; /* length of LUN inventory, in bytes */
1388 u_int8_t reserved[4]; /* unused */
1390 * LUN inventory- we only support the type zero form for now.
1392 struct scsi_report_luns_lundata luns[0];
1395 struct scsi_target_group
1398 uint8_t service_action;
1399 #define STG_PDF_LENGTH 0x00
1400 #define RPL_PDF_EXTENDED 0x20
1401 uint8_t reserved1[4];
1407 struct scsi_target_port_descriptor {
1408 uint8_t reserved[2];
1409 uint8_t relative_target_port_identifier[2];
1410 uint8_t desc_list[];
1413 struct scsi_target_port_group_descriptor {
1415 #define TPG_PRIMARY 0x80
1416 #define TPG_ASYMMETRIC_ACCESS_STATE_MASK 0xf
1417 #define TPG_ASYMMETRIC_ACCESS_OPTIMIZED 0x0
1418 #define TPG_ASYMMETRIC_ACCESS_NONOPTIMIZED 0x1
1419 #define TPG_ASYMMETRIC_ACCESS_STANDBY 0x2
1420 #define TPG_ASYMMETRIC_ACCESS_UNAVAILABLE 0x3
1421 #define TPG_ASYMMETRIC_ACCESS_LBA_DEPENDENT 0x4
1422 #define TPG_ASYMMETRIC_ACCESS_OFFLINE 0xE
1423 #define TPG_ASYMMETRIC_ACCESS_TRANSITIONING 0xF
1425 #define TPG_AO_SUP 0x01
1426 #define TPG_AN_SUP 0x02
1427 #define TPG_S_SUP 0x04
1428 #define TPG_U_SUP 0x08
1429 #define TPG_LBD_SUP 0x10
1430 #define TPG_O_SUP 0x40
1431 #define TPG_T_SUP 0x80
1432 uint8_t target_port_group[2];
1435 #define TPG_UNAVLBL 0
1436 #define TPG_SET_BY_STPG 0x01
1437 #define TPG_IMPLICIT 0x02
1438 uint8_t vendor_specific;
1439 uint8_t target_port_count;
1440 struct scsi_target_port_descriptor descriptors[];
1443 struct scsi_target_group_data {
1444 uint8_t length[4]; /* length of returned data, in bytes */
1445 struct scsi_target_port_group_descriptor groups[];
1448 struct scsi_target_group_data_extended {
1449 uint8_t length[4]; /* length of returned data, in bytes */
1450 uint8_t format_type; /* STG_PDF_LENGTH or RPL_PDF_EXTENDED */
1451 uint8_t implicit_transition_time;
1452 uint8_t reserved[2];
1453 struct scsi_target_port_group_descriptor groups[];
1461 } scsi_sense_data_type;
1473 } scsi_sense_elem_type;
1476 struct scsi_sense_data
1480 * SPC-4 says that the maximum length of sense data is 252 bytes.
1481 * So this structure is exactly 252 bytes log.
1483 #define SSD_FULL_SIZE 252
1484 uint8_t sense_buf[SSD_FULL_SIZE - 1];
1486 * XXX KDM is this still a reasonable minimum size?
1488 #define SSD_MIN_SIZE 18
1490 * Maximum value for the extra_len field in the sense data.
1492 #define SSD_EXTRA_MAX 244
1496 * Fixed format sense data.
1498 struct scsi_sense_data_fixed
1500 u_int8_t error_code;
1501 #define SSD_ERRCODE 0x7F
1502 #define SSD_CURRENT_ERROR 0x70
1503 #define SSD_DEFERRED_ERROR 0x71
1504 #define SSD_ERRCODE_VALID 0x80
1507 #define SSD_KEY 0x0F
1508 #define SSD_KEY_NO_SENSE 0x00
1509 #define SSD_KEY_RECOVERED_ERROR 0x01
1510 #define SSD_KEY_NOT_READY 0x02
1511 #define SSD_KEY_MEDIUM_ERROR 0x03
1512 #define SSD_KEY_HARDWARE_ERROR 0x04
1513 #define SSD_KEY_ILLEGAL_REQUEST 0x05
1514 #define SSD_KEY_UNIT_ATTENTION 0x06
1515 #define SSD_KEY_DATA_PROTECT 0x07
1516 #define SSD_KEY_BLANK_CHECK 0x08
1517 #define SSD_KEY_Vendor_Specific 0x09
1518 #define SSD_KEY_COPY_ABORTED 0x0a
1519 #define SSD_KEY_ABORTED_COMMAND 0x0b
1520 #define SSD_KEY_EQUAL 0x0c
1521 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
1522 #define SSD_KEY_MISCOMPARE 0x0e
1523 #define SSD_KEY_COMPLETED 0x0f
1524 #define SSD_ILI 0x20
1525 #define SSD_EOM 0x40
1526 #define SSD_FILEMARK 0x80
1529 u_int8_t cmd_spec_info[4];
1530 u_int8_t add_sense_code;
1531 u_int8_t add_sense_code_qual;
1533 u_int8_t sense_key_spec[3];
1534 #define SSD_SCS_VALID 0x80
1535 #define SSD_FIELDPTR_CMD 0x40
1536 #define SSD_BITPTR_VALID 0x08
1537 #define SSD_BITPTR_VALUE 0x07
1538 u_int8_t extra_bytes[14];
1539 #define SSD_FIXED_IS_PRESENT(sense, length, field) \
1540 ((length >= (offsetof(struct scsi_sense_data_fixed, field) + \
1541 sizeof(sense->field))) ? 1 :0)
1542 #define SSD_FIXED_IS_FILLED(sense, field) \
1543 ((((offsetof(struct scsi_sense_data_fixed, field) + \
1544 sizeof(sense->field)) - \
1545 (offsetof(struct scsi_sense_data_fixed, extra_len) + \
1546 sizeof(sense->extra_len))) <= sense->extra_len) ? 1 : 0)
1550 * Descriptor format sense data definitions.
1551 * Introduced in SPC-3.
1553 struct scsi_sense_data_desc
1556 #define SSD_DESC_CURRENT_ERROR 0x72
1557 #define SSD_DESC_DEFERRED_ERROR 0x73
1559 uint8_t add_sense_code;
1560 uint8_t add_sense_code_qual;
1561 uint8_t reserved[3];
1563 * Note that SPC-4, section 4.5.2.1 says that the extra_len field
1564 * must be less than or equal to 244.
1567 uint8_t sense_desc[0];
1568 #define SSD_DESC_IS_PRESENT(sense, length, field) \
1569 ((length >= (offsetof(struct scsi_sense_data_desc, field) + \
1570 sizeof(sense->field))) ? 1 :0)
1573 struct scsi_sense_desc_header
1579 * The information provide in the Information descriptor is device type or
1580 * command specific information, and defined in a command standard.
1582 * Note that any changes to the field names or positions in this structure,
1583 * even reserved fields, should be accompanied by an examination of the
1584 * code in ctl_set_sense() that uses them.
1586 * Maximum descriptors allowed: 1 (as of SPC-4)
1588 struct scsi_sense_info
1591 #define SSD_DESC_INFO 0x00
1594 #define SSD_INFO_VALID 0x80
1600 * Command-specific information depends on the command for which the
1601 * reported condition occured.
1603 * Note that any changes to the field names or positions in this structure,
1604 * even reserved fields, should be accompanied by an examination of the
1605 * code in ctl_set_sense() that uses them.
1607 * Maximum descriptors allowed: 1 (as of SPC-4)
1609 struct scsi_sense_command
1612 #define SSD_DESC_COMMAND 0x01
1614 uint8_t reserved[2];
1615 uint8_t command_info[8];
1619 * Sense key specific descriptor. The sense key specific data format
1620 * depends on the sense key in question.
1622 * Maximum descriptors allowed: 1 (as of SPC-4)
1624 struct scsi_sense_sks
1627 #define SSD_DESC_SKS 0x02
1629 uint8_t reserved1[2];
1630 uint8_t sense_key_spec[3];
1631 #define SSD_SKS_VALID 0x80
1636 * This is used for the Illegal Request sense key (0x05) only.
1638 struct scsi_sense_sks_field
1641 #define SSD_SKS_FIELD_VALID 0x80
1642 #define SSD_SKS_FIELD_CMD 0x40
1643 #define SSD_SKS_BPV 0x08
1644 #define SSD_SKS_BIT_VALUE 0x07
1650 * This is used for the Hardware Error (0x04), Medium Error (0x03) and
1651 * Recovered Error (0x01) sense keys.
1653 struct scsi_sense_sks_retry
1656 #define SSD_SKS_RETRY_VALID 0x80
1657 uint8_t actual_retry_count[2];
1661 * Used with the NO Sense (0x00) or Not Ready (0x02) sense keys.
1663 struct scsi_sense_sks_progress
1666 #define SSD_SKS_PROGRESS_VALID 0x80
1667 uint8_t progress[2];
1668 #define SSD_SKS_PROGRESS_DENOM 0x10000
1672 * Used with the Copy Aborted (0x0a) sense key.
1674 struct scsi_sense_sks_segment
1677 #define SSD_SKS_SEGMENT_VALID 0x80
1678 #define SSD_SKS_SEGMENT_SD 0x20
1679 #define SSD_SKS_SEGMENT_BPV 0x08
1680 #define SSD_SKS_SEGMENT_BITPTR 0x07
1685 * Used with the Unit Attention (0x06) sense key.
1687 * This is currently used to indicate that the unit attention condition
1688 * queue has overflowed (when the overflow bit is set).
1690 struct scsi_sense_sks_overflow
1693 #define SSD_SKS_OVERFLOW_VALID 0x80
1694 #define SSD_SKS_OVERFLOW_SET 0x01
1695 uint8_t reserved[2];
1699 * This specifies which component is associated with the sense data. There
1700 * is no standard meaning for the fru value.
1702 * Maximum descriptors allowed: 1 (as of SPC-4)
1704 struct scsi_sense_fru
1707 #define SSD_DESC_FRU 0x03
1714 * Used for Stream commands, defined in SSC-4.
1716 * Maximum descriptors allowed: 1 (as of SPC-4)
1719 struct scsi_sense_stream
1722 #define SSD_DESC_STREAM 0x04
1726 #define SSD_DESC_STREAM_FM 0x80
1727 #define SSD_DESC_STREAM_EOM 0x40
1728 #define SSD_DESC_STREAM_ILI 0x20
1732 * Used for Block commands, defined in SBC-3.
1734 * This is currently (as of SBC-3) only used for the Incorrect Length
1735 * Indication (ILI) bit, which says that the data length requested in the
1736 * READ LONG or WRITE LONG command did not match the length of the logical
1739 * Maximum descriptors allowed: 1 (as of SPC-4)
1741 struct scsi_sense_block
1744 #define SSD_DESC_BLOCK 0x05
1748 #define SSD_DESC_BLOCK_ILI 0x20
1752 * Used for Object-Based Storage Devices (OSD-3).
1754 * Maximum descriptors allowed: 1 (as of SPC-4)
1756 struct scsi_sense_osd_objid
1759 #define SSD_DESC_OSD_OBJID 0x06
1761 uint8_t reserved[6];
1763 * XXX KDM provide the bit definitions here? There are a lot of
1764 * them, and we don't have an OSD driver yet.
1766 uint8_t not_init_cmds[4];
1767 uint8_t completed_cmds[4];
1768 uint8_t partition_id[8];
1769 uint8_t object_id[8];
1773 * Used for Object-Based Storage Devices (OSD-3).
1775 * Maximum descriptors allowed: 1 (as of SPC-4)
1777 struct scsi_sense_osd_integrity
1780 #define SSD_DESC_OSD_INTEGRITY 0x07
1782 uint8_t integ_check_val[32];
1786 * Used for Object-Based Storage Devices (OSD-3).
1788 * Maximum descriptors allowed: 1 (as of SPC-4)
1790 struct scsi_sense_osd_attr_id
1793 #define SSD_DESC_OSD_ATTR_ID 0x08
1795 uint8_t reserved[2];
1796 uint8_t attr_desc[0];
1800 * Used with Sense keys No Sense (0x00) and Not Ready (0x02).
1802 * Maximum descriptors allowed: 32 (as of SPC-4)
1804 struct scsi_sense_progress
1807 #define SSD_DESC_PROGRESS 0x0a
1810 uint8_t add_sense_code;
1811 uint8_t add_sense_code_qual;
1813 uint8_t progress[2];
1817 * This is typically forwarded as the result of an EXTENDED COPY command.
1819 * Maximum descriptors allowed: 2 (as of SPC-4)
1821 struct scsi_sense_forwarded
1824 #define SSD_DESC_FORWARDED 0x0c
1827 #define SSD_FORWARDED_FSDT 0x80
1828 #define SSD_FORWARDED_SDS_MASK 0x0f
1829 #define SSD_FORWARDED_SDS_UNK 0x00
1830 #define SSD_FORWARDED_SDS_EXSRC 0x01
1831 #define SSD_FORWARDED_SDS_EXDST 0x02
1835 * Vendor-specific sense descriptor. The desc_type field will be in the
1836 * range bewteen MIN and MAX inclusive.
1838 struct scsi_sense_vendor
1841 #define SSD_DESC_VENDOR_MIN 0x80
1842 #define SSD_DESC_VENDOR_MAX 0xff
1847 struct scsi_mode_header_6
1849 u_int8_t data_length; /* Sense data length */
1850 u_int8_t medium_type;
1852 u_int8_t blk_desc_len;
1855 struct scsi_mode_header_10
1857 u_int8_t data_length[2];/* Sense data length */
1858 u_int8_t medium_type;
1861 u_int8_t blk_desc_len[2];
1864 struct scsi_mode_page_header
1867 #define SMPH_PS 0x80
1868 #define SMPH_SPF 0x40
1869 #define SMPH_PC_MASK 0x3f
1870 u_int8_t page_length;
1873 struct scsi_mode_page_header_sp
1877 uint8_t page_length[2];
1881 struct scsi_mode_blk_desc
1884 u_int8_t nblocks[3];
1889 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
1890 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
1896 #define SCSI_STATUS_OK 0x00
1897 #define SCSI_STATUS_CHECK_COND 0x02
1898 #define SCSI_STATUS_COND_MET 0x04
1899 #define SCSI_STATUS_BUSY 0x08
1900 #define SCSI_STATUS_INTERMED 0x10
1901 #define SCSI_STATUS_INTERMED_COND_MET 0x14
1902 #define SCSI_STATUS_RESERV_CONFLICT 0x18
1903 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
1904 #define SCSI_STATUS_QUEUE_FULL 0x28
1905 #define SCSI_STATUS_ACA_ACTIVE 0x30
1906 #define SCSI_STATUS_TASK_ABORTED 0x40
1908 struct scsi_inquiry_pattern {
1910 u_int8_t media_type;
1911 #define SIP_MEDIA_REMOVABLE 0x01
1912 #define SIP_MEDIA_FIXED 0x02
1914 const char *product;
1915 const char *revision;
1918 struct scsi_static_inquiry_pattern {
1920 u_int8_t media_type;
1921 char vendor[SID_VENDOR_SIZE+1];
1922 char product[SID_PRODUCT_SIZE+1];
1923 char revision[SID_REVISION_SIZE+1];
1926 struct scsi_sense_quirk_entry {
1927 struct scsi_inquiry_pattern inq_pat;
1930 struct sense_key_table_entry *sense_key_info;
1931 struct asc_table_entry *asc_info;
1934 struct sense_key_table_entry {
1940 struct asc_table_entry {
1947 struct op_table_entry {
1953 struct scsi_op_quirk_entry {
1954 struct scsi_inquiry_pattern inq_pat;
1956 struct op_table_entry *op_table;
1960 SSS_FLAG_NONE = 0x00,
1961 SSS_FLAG_PRINT_COMMAND = 0x01
1962 } scsi_sense_string_flags;
1971 extern const char *scsi_sense_key_text[];
1976 void scsi_sense_desc(int sense_key, int asc, int ascq,
1977 struct scsi_inquiry_data *inq_data,
1978 const char **sense_key_desc, const char **asc_desc);
1979 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
1980 struct scsi_inquiry_data *inq_data,
1981 u_int32_t sense_flags);
1982 const char * scsi_status_string(struct ccb_scsiio *csio);
1984 void scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len,
1985 int (*iter_func)(struct scsi_sense_data_desc *sense,
1986 u_int, struct scsi_sense_desc_header *,
1987 void *), void *arg);
1988 uint8_t *scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len,
1990 void scsi_set_sense_data(struct scsi_sense_data *sense_data,
1991 scsi_sense_data_type sense_format, int current_error,
1992 int sense_key, int asc, int ascq, ...) ;
1993 void scsi_set_sense_data_va(struct scsi_sense_data *sense_data,
1994 scsi_sense_data_type sense_format,
1995 int current_error, int sense_key, int asc,
1996 int ascq, va_list ap);
1997 int scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len,
1998 uint8_t info_type, uint64_t *info,
1999 int64_t *signed_info);
2000 int scsi_get_sks(struct scsi_sense_data *sense_data, u_int sense_len,
2002 int scsi_get_block_info(struct scsi_sense_data *sense_data, u_int sense_len,
2003 struct scsi_inquiry_data *inq_data,
2004 uint8_t *block_bits);
2005 int scsi_get_stream_info(struct scsi_sense_data *sense_data, u_int sense_len,
2006 struct scsi_inquiry_data *inq_data,
2007 uint8_t *stream_bits);
2008 void scsi_info_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
2009 struct scsi_inquiry_data *inq_data, uint64_t info);
2010 void scsi_command_sbuf(struct sbuf *sb, uint8_t *cdb, int cdb_len,
2011 struct scsi_inquiry_data *inq_data, uint64_t csi);
2012 void scsi_progress_sbuf(struct sbuf *sb, uint16_t progress);
2013 int scsi_sks_sbuf(struct sbuf *sb, int sense_key, uint8_t *sks);
2014 void scsi_fru_sbuf(struct sbuf *sb, uint64_t fru);
2015 void scsi_stream_sbuf(struct sbuf *sb, uint8_t stream_bits, uint64_t info);
2016 void scsi_block_sbuf(struct sbuf *sb, uint8_t block_bits, uint64_t info);
2017 void scsi_sense_info_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
2018 u_int sense_len, uint8_t *cdb, int cdb_len,
2019 struct scsi_inquiry_data *inq_data,
2020 struct scsi_sense_desc_header *header);
2022 void scsi_sense_command_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
2023 u_int sense_len, uint8_t *cdb, int cdb_len,
2024 struct scsi_inquiry_data *inq_data,
2025 struct scsi_sense_desc_header *header);
2026 void scsi_sense_sks_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
2027 u_int sense_len, uint8_t *cdb, int cdb_len,
2028 struct scsi_inquiry_data *inq_data,
2029 struct scsi_sense_desc_header *header);
2030 void scsi_sense_fru_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
2031 u_int sense_len, uint8_t *cdb, int cdb_len,
2032 struct scsi_inquiry_data *inq_data,
2033 struct scsi_sense_desc_header *header);
2034 void scsi_sense_stream_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
2035 u_int sense_len, uint8_t *cdb, int cdb_len,
2036 struct scsi_inquiry_data *inq_data,
2037 struct scsi_sense_desc_header *header);
2038 void scsi_sense_block_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
2039 u_int sense_len, uint8_t *cdb, int cdb_len,
2040 struct scsi_inquiry_data *inq_data,
2041 struct scsi_sense_desc_header *header);
2042 void scsi_sense_progress_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
2043 u_int sense_len, uint8_t *cdb, int cdb_len,
2044 struct scsi_inquiry_data *inq_data,
2045 struct scsi_sense_desc_header *header);
2046 void scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
2047 u_int sense_len, uint8_t *cdb, int cdb_len,
2048 struct scsi_inquiry_data *inq_data,
2049 struct scsi_sense_desc_header *header);
2050 void scsi_sense_desc_sbuf(struct sbuf *sb, struct scsi_sense_data *sense,
2051 u_int sense_len, uint8_t *cdb, int cdb_len,
2052 struct scsi_inquiry_data *inq_data,
2053 struct scsi_sense_desc_header *header);
2054 scsi_sense_data_type scsi_sense_type(struct scsi_sense_data *sense_data);
2056 void scsi_sense_only_sbuf(struct scsi_sense_data *sense, u_int sense_len,
2057 struct sbuf *sb, char *path_str,
2058 struct scsi_inquiry_data *inq_data, uint8_t *cdb,
2062 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
2063 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
2064 scsi_sense_string_flags flags);
2065 char * scsi_sense_string(struct ccb_scsiio *csio,
2066 char *str, int str_len);
2067 void scsi_sense_print(struct ccb_scsiio *csio);
2068 int scsi_interpret_sense(union ccb *ccb,
2069 u_int32_t sense_flags,
2070 u_int32_t *relsim_flags,
2071 u_int32_t *reduction,
2073 scsi_sense_action error_action);
2075 int scsi_command_string(struct cam_device *device,
2076 struct ccb_scsiio *csio, struct sbuf *sb);
2077 int scsi_sense_sbuf(struct cam_device *device,
2078 struct ccb_scsiio *csio, struct sbuf *sb,
2079 scsi_sense_string_flags flags);
2080 char * scsi_sense_string(struct cam_device *device,
2081 struct ccb_scsiio *csio,
2082 char *str, int str_len);
2083 void scsi_sense_print(struct cam_device *device,
2084 struct ccb_scsiio *csio, FILE *ofile);
2085 int scsi_interpret_sense(struct cam_device *device,
2087 u_int32_t sense_flags,
2088 u_int32_t *relsim_flags,
2089 u_int32_t *reduction,
2091 scsi_sense_action error_action);
2092 #endif /* _KERNEL */
2094 #define SF_RETRY_UA 0x01
2095 #define SF_NO_PRINT 0x02
2096 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
2097 #define SF_PRINT_ALWAYS 0x08
2100 const char * scsi_op_desc(u_int16_t opcode,
2101 struct scsi_inquiry_data *inq_data);
2102 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
2105 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
2107 u_int scsi_calc_syncsrate(u_int period_factor);
2108 u_int scsi_calc_syncparam(u_int period);
2110 typedef int (*scsi_devid_checkfn_t)(uint8_t *);
2111 int scsi_devid_is_naa_ieee_reg(uint8_t *bufp);
2112 int scsi_devid_is_sas_target(uint8_t *bufp);
2113 uint8_t * scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t len,
2114 scsi_devid_checkfn_t ck_fn);
2116 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
2117 void (*cbfcnp)(struct cam_periph *,
2119 u_int8_t tag_action,
2120 u_int8_t sense_len, u_int32_t timeout);
2122 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
2123 void (*cbfcnp)(struct cam_periph *,
2125 void *data_ptr, u_int8_t dxfer_len,
2126 u_int8_t tag_action, u_int8_t sense_len,
2129 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
2130 void (*cbfcnp)(struct cam_periph *, union ccb *),
2131 u_int8_t tag_action, u_int8_t *inq_buf,
2132 u_int32_t inq_len, int evpd, u_int8_t page_code,
2133 u_int8_t sense_len, u_int32_t timeout);
2135 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
2136 void (*cbfcnp)(struct cam_periph *,
2138 u_int8_t tag_action, int dbd,
2139 u_int8_t page_code, u_int8_t page,
2140 u_int8_t *param_buf, u_int32_t param_len,
2141 u_int8_t sense_len, u_int32_t timeout);
2143 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
2144 void (*cbfcnp)(struct cam_periph *,
2146 u_int8_t tag_action, int dbd,
2147 u_int8_t page_code, u_int8_t page,
2148 u_int8_t *param_buf, u_int32_t param_len,
2149 int minimum_cmd_size, u_int8_t sense_len,
2152 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
2153 void (*cbfcnp)(struct cam_periph *,
2155 u_int8_t tag_action, int scsi_page_fmt,
2156 int save_pages, u_int8_t *param_buf,
2157 u_int32_t param_len, u_int8_t sense_len,
2160 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
2161 void (*cbfcnp)(struct cam_periph *,
2163 u_int8_t tag_action, int scsi_page_fmt,
2164 int save_pages, u_int8_t *param_buf,
2165 u_int32_t param_len, int minimum_cmd_size,
2166 u_int8_t sense_len, u_int32_t timeout);
2168 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
2169 void (*cbfcnp)(struct cam_periph *, union ccb *),
2170 u_int8_t tag_action, u_int8_t page_code,
2171 u_int8_t page, int save_pages, int ppc,
2172 u_int32_t paramptr, u_int8_t *param_buf,
2173 u_int32_t param_len, u_int8_t sense_len,
2176 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
2177 void (*cbfcnp)(struct cam_periph *,
2178 union ccb *), u_int8_t tag_action,
2179 u_int8_t page_code, int save_pages,
2180 int pc_reset, u_int8_t *param_buf,
2181 u_int32_t param_len, u_int8_t sense_len,
2184 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
2185 void (*cbfcnp)(struct cam_periph *, union ccb *),
2186 u_int8_t tag_action, u_int8_t action,
2187 u_int8_t sense_len, u_int32_t timeout);
2189 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
2190 void (*cbfcnp)(struct cam_periph *,
2191 union ccb *), u_int8_t tag_action,
2192 struct scsi_read_capacity_data *,
2193 u_int8_t sense_len, u_int32_t timeout);
2194 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
2195 void (*cbfcnp)(struct cam_periph *,
2196 union ccb *), uint8_t tag_action,
2197 uint64_t lba, int reladr, int pmi,
2198 struct scsi_read_capacity_data_long
2199 *rcap_buf, uint8_t sense_len,
2202 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
2203 void (*cbfcnp)(struct cam_periph *,
2204 union ccb *), u_int8_t tag_action,
2205 u_int8_t select_report,
2206 struct scsi_report_luns_data *rpl_buf,
2207 u_int32_t alloc_len, u_int8_t sense_len,
2210 void scsi_report_target_group(struct ccb_scsiio *csio, u_int32_t retries,
2211 void (*cbfcnp)(struct cam_periph *,
2212 union ccb *), u_int8_t tag_action,
2215 u_int32_t alloc_len, u_int8_t sense_len,
2218 void scsi_set_target_group(struct ccb_scsiio *csio, u_int32_t retries,
2219 void (*cbfcnp)(struct cam_periph *,
2220 union ccb *), u_int8_t tag_action, void *buf,
2221 u_int32_t alloc_len, u_int8_t sense_len,
2224 void scsi_synchronize_cache(struct ccb_scsiio *csio,
2226 void (*cbfcnp)(struct cam_periph *,
2227 union ccb *), u_int8_t tag_action,
2228 u_int32_t begin_lba, u_int16_t lb_count,
2229 u_int8_t sense_len, u_int32_t timeout);
2231 void scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries,
2232 void (*cbfcnp)(struct cam_periph *,
2234 uint8_t tag_action, int pcv,
2235 uint8_t page_code, uint8_t *data_ptr,
2236 uint16_t allocation_length,
2237 uint8_t sense_len, uint32_t timeout);
2239 void scsi_send_diagnostic(struct ccb_scsiio *csio, u_int32_t retries,
2240 void (*cbfcnp)(struct cam_periph *, union ccb *),
2241 uint8_t tag_action, int unit_offline,
2242 int device_offline, int self_test, int page_format,
2243 int self_test_code, uint8_t *data_ptr,
2244 uint16_t param_list_length, uint8_t sense_len,
2247 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
2248 void (*cbfcnp)(struct cam_periph *, union ccb *),
2249 u_int8_t tag_action, int readop, u_int8_t byte2,
2250 int minimum_cmd_size, u_int64_t lba,
2251 u_int32_t block_count, u_int8_t *data_ptr,
2252 u_int32_t dxfer_len, u_int8_t sense_len,
2255 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
2256 void (*cbfcnp)(struct cam_periph *, union ccb *),
2257 u_int8_t tag_action, int start, int load_eject,
2258 int immediate, u_int8_t sense_len, u_int32_t timeout);
2260 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
2261 int scsi_static_inquiry_match(caddr_t inqbuffer,
2262 caddr_t table_entry);
2263 int scsi_devid_match(uint8_t *rhs, size_t rhs_len,
2264 uint8_t *lhs, size_t lhs_len);
2266 void scsi_extract_sense(struct scsi_sense_data *sense, int *error_code,
2267 int *sense_key, int *asc, int *ascq);
2268 void scsi_extract_sense_len(struct scsi_sense_data *sense,
2269 u_int sense_len, int *error_code, int *sense_key,
2270 int *asc, int *ascq, int show_errors);
2271 int scsi_get_sense_key(struct scsi_sense_data *sense, u_int sense_len,
2273 int scsi_get_asc(struct scsi_sense_data *sense, u_int sense_len,
2275 int scsi_get_ascq(struct scsi_sense_data *sense, u_int sense_len,
2277 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
2278 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
2279 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
2280 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
2281 static __inline uint32_t scsi_2btoul(const uint8_t *bytes);
2282 static __inline uint32_t scsi_3btoul(const uint8_t *bytes);
2283 static __inline int32_t scsi_3btol(const uint8_t *bytes);
2284 static __inline uint32_t scsi_4btoul(const uint8_t *bytes);
2285 static __inline uint64_t scsi_8btou64(const uint8_t *bytes);
2286 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
2287 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
2289 static __inline void
2290 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
2293 bytes[0] = (val >> 8) & 0xff;
2294 bytes[1] = val & 0xff;
2297 static __inline void
2298 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
2301 bytes[0] = (val >> 16) & 0xff;
2302 bytes[1] = (val >> 8) & 0xff;
2303 bytes[2] = val & 0xff;
2306 static __inline void
2307 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
2310 bytes[0] = (val >> 24) & 0xff;
2311 bytes[1] = (val >> 16) & 0xff;
2312 bytes[2] = (val >> 8) & 0xff;
2313 bytes[3] = val & 0xff;
2316 static __inline void
2317 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
2320 bytes[0] = (val >> 56) & 0xff;
2321 bytes[1] = (val >> 48) & 0xff;
2322 bytes[2] = (val >> 40) & 0xff;
2323 bytes[3] = (val >> 32) & 0xff;
2324 bytes[4] = (val >> 24) & 0xff;
2325 bytes[5] = (val >> 16) & 0xff;
2326 bytes[6] = (val >> 8) & 0xff;
2327 bytes[7] = val & 0xff;
2330 static __inline uint32_t
2331 scsi_2btoul(const uint8_t *bytes)
2335 rv = (bytes[0] << 8) |
2340 static __inline uint32_t
2341 scsi_3btoul(const uint8_t *bytes)
2345 rv = (bytes[0] << 16) |
2351 static __inline int32_t
2352 scsi_3btol(const uint8_t *bytes)
2354 uint32_t rc = scsi_3btoul(bytes);
2356 if (rc & 0x00800000)
2359 return (int32_t) rc;
2362 static __inline uint32_t
2363 scsi_4btoul(const uint8_t *bytes)
2367 rv = (bytes[0] << 24) |
2374 static __inline uint64_t
2375 scsi_8btou64(const uint8_t *bytes)
2379 rv = (((uint64_t)bytes[0]) << 56) |
2380 (((uint64_t)bytes[1]) << 48) |
2381 (((uint64_t)bytes[2]) << 40) |
2382 (((uint64_t)bytes[3]) << 32) |
2383 (((uint64_t)bytes[4]) << 24) |
2384 (((uint64_t)bytes[5]) << 16) |
2385 (((uint64_t)bytes[6]) << 8) |
2391 * Given the pointer to a returned mode sense buffer, return a pointer to
2392 * the start of the first mode page.
2394 static __inline void *
2395 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
2399 page_start = (void *)((u_int8_t *)&mode_header[1] +
2400 mode_header->blk_desc_len);
2405 static __inline void *
2406 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
2410 page_start = (void *)((u_int8_t *)&mode_header[1] +
2411 scsi_2btoul(mode_header->blk_desc_len));
2418 #endif /*_SCSI_SCSI_ALL_H*/