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.10 2007/11/24 03:48:31 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 */
38 * This is the number of seconds we wait for devices to settle after a SCSI
42 #define SCSI_DELAY 2000
45 * If someone sets this to 0, we assume that they want the minimum
46 * allowable bus settle delay. All devices need _some_ sort of bus settle
47 * delay, so we'll set it to a minimum value of 100ms.
51 #define SCSI_DELAY 100
55 * Make sure the user isn't using seconds instead of milliseconds.
57 #if (SCSI_DELAY < 100)
58 #error "SCSI_DELAY is in milliseconds, not seconds! Please use a larger value"
67 * Define dome bits that are in ALL (or a lot of) scsi commands
69 #define SCSI_CTL_LINK 0x01
70 #define SCSI_CTL_FLAG 0x02
71 #define SCSI_CTL_VENDOR 0xC0
72 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */
73 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */
75 #define SCSI_MAX_CDBLEN 16 /*
76 * 16 byte commands are in the
79 #if defined(CAM_MAX_CDBLEN) && (CAM_MAX_CDBLEN < SCSI_MAX_CDBLEN)
80 #error "CAM_MAX_CDBLEN cannot be less than SCSI_MAX_CDBLEN"
83 /* 6byte CDBs special case 0 length to be 256 */
84 #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len)
87 * This type defines actions to be taken when a particular sense code is
88 * received. Right now, these flags are only defined to take up 16 bits,
89 * but can be expanded in the future if necessary.
92 SS_NOP = 0x000000, /* Do nothing */
93 SS_RETRY = 0x010000, /* Retry the command */
94 SS_FAIL = 0x020000, /* Bail out */
95 SS_START = 0x030000, /* Send a Start Unit command to the device,
96 * then retry the original command.
98 SS_TUR = 0x040000, /* Send a Test Unit Ready command to the
99 * device, then retry the original command.
101 SS_REQSENSE = 0x050000, /* Send a RequestSense command to the
102 * device, then retry the original command.
109 SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */
110 SSQ_MANY = 0x0200, /* send lots of recovery commands */
111 SSQ_RANGE = 0x0400, /*
112 * This table entry represents the
113 * end of a range of ASCQs that
114 * have identical error actions
117 SSQ_PRINT_SENSE = 0x0800,
119 } scsi_sense_action_qualifier;
121 /* Mask for error status values */
122 #define SS_ERRMASK 0xff
124 /* The default, retyable, error action */
125 #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
127 /* The retyable, error action, with table specified error code */
128 #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
130 /* Fatal error action, with table specified error code */
131 #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE
139 struct scsi_request_sense
148 struct scsi_test_unit_ready
156 struct scsi_send_diag
162 #define SSD_SELFTEST 0x04
165 u_int8_t paramlen[2];
189 struct scsi_mode_sense_6
195 #define SMS_PAGE_CODE 0x3F
196 #define SMS_VENDOR_SPECIFIC_PAGE 0x00
197 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02
198 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
199 #define SMS_CONTROL_MODE_PAGE 0x0A
200 #define SMS_ALL_PAGES_PAGE 0x3F
201 #define SMS_PAGE_CTRL_MASK 0xC0
202 #define SMS_PAGE_CTRL_CURRENT 0x00
203 #define SMS_PAGE_CTRL_CHANGEABLE 0x40
204 #define SMS_PAGE_CTRL_DEFAULT 0x80
205 #define SMS_PAGE_CTRL_SAVED 0xC0
211 struct scsi_mode_sense_10
214 u_int8_t byte2; /* same bits as small version */
215 u_int8_t page; /* same bits as small version */
221 struct scsi_mode_select_6
232 struct scsi_mode_select_10
235 u_int8_t byte2; /* same bits as small version */
242 * When sending a mode select to a tape drive, the medium type must be 0.
244 struct scsi_mode_hdr_6
247 u_int8_t medium_type;
248 u_int8_t dev_specific;
249 u_int8_t block_descr_len;
252 struct scsi_mode_hdr_10
255 u_int8_t medium_type;
256 u_int8_t dev_specific;
257 u_int8_t reserved[2];
258 u_int8_t block_descr_len[2];
261 struct scsi_mode_block_descr
263 u_int8_t density_code;
264 u_int8_t num_blocks[3];
266 u_int8_t block_len[3];
269 struct scsi_log_sense
276 #define SLS_PAGE_CODE 0x3F
277 #define SLS_ALL_PAGES_PAGE 0x00
278 #define SLS_OVERRUN_PAGE 0x01
279 #define SLS_ERROR_WRITE_PAGE 0x02
280 #define SLS_ERROR_READ_PAGE 0x03
281 #define SLS_ERROR_READREVERSE_PAGE 0x04
282 #define SLS_ERROR_VERIFY_PAGE 0x05
283 #define SLS_ERROR_NONMEDIUM_PAGE 0x06
284 #define SLS_ERROR_LASTN_PAGE 0x07
285 #define SLS_PAGE_CTRL_MASK 0xC0
286 #define SLS_PAGE_CTRL_THRESHOLD 0x00
287 #define SLS_PAGE_CTRL_CUMULATIVE 0x40
288 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
289 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
290 u_int8_t reserved[2];
291 u_int8_t paramptr[2];
296 struct scsi_log_select
303 /* SLS_PAGE_CTRL_MASK 0xC0 */
304 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */
305 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
306 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
307 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
308 u_int8_t reserved[4];
313 struct scsi_log_header
320 struct scsi_log_param_header {
321 u_int8_t param_code[2];
322 u_int8_t param_control;
324 #define SLP_LBIN 0x02
325 #define SLP_TMC_MASK 0x0C
326 #define SLP_TMC_ALWAYS 0x00
327 #define SLP_TMC_EQUAL 0x04
328 #define SLP_TMC_NOTEQUAL 0x08
329 #define SLP_TMC_GREATER 0x0C
337 struct scsi_control_page {
339 u_int8_t page_length;
341 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
342 u_int8_t queue_flags;
343 #define SCP_QUEUE_ALG_MASK 0xF0
344 #define SCP_QUEUE_ALG_RESTRICTED 0x00
345 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
346 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
347 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
348 u_int8_t eca_and_aen;
349 #define SCP_EECA 0x80 /*Enable Extended CA*/
350 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
351 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
352 #define SCP_EAENP 0x01 /*Error AEN Permission*/
354 u_int8_t aen_holdoff_period[2];
383 #define PR_PREVENT 0x01
384 #define PR_ALLOW 0x00
386 struct scsi_sync_cache
390 u_int8_t begin_lba[4];
392 u_int8_t lb_count[2];
397 struct scsi_changedef
408 struct scsi_read_buffer
412 #define RWB_MODE 0x07
413 #define RWB_MODE_HDR_DATA 0x00
414 #define RWB_MODE_DATA 0x02
415 #define RWB_MODE_DOWNLOAD 0x04
416 #define RWB_MODE_DOWNLOAD_SAVE 0x05
423 struct scsi_write_buffer
437 /* only 5 bits are valid in the MSB address byte */
438 #define SRW_TOPADDR 0x1F
446 #define SRW10_RELADDR 0x01
447 /* EBP defined for WRITE(10) only */
448 #define SRW10_EBP 0x04
449 #define SRW10_FUA 0x08
450 #define SRW10_DPO 0x10
461 #define SRW12_RELADDR 0x01
462 #define SRW12_FUA 0x08
463 #define SRW12_DPO 0x10
474 #define SRW16_RELADDR 0x01
475 #define SRW16_FUA 0x08
476 #define SRW16_DPO 0x10
485 struct scsi_start_stop_unit
489 #define SSS_IMMED 0x01
490 u_int8_t reserved[2];
492 #define SSS_START 0x01
493 #define SSS_LOEJ 0x02
497 #define SC_SCSI_1 0x01
498 #define SC_SCSI_2 0x03
504 #define TEST_UNIT_READY 0x00
505 #define REQUEST_SENSE 0x03
509 #define MODE_SELECT_6 0x15
510 #define MODE_SENSE_6 0x1a
511 #define START_STOP_UNIT 0x1b
512 #define START_STOP 0x1b
515 #define RECEIVE_DIAGNOSTIC 0x1c
516 #define SEND_DIAGNOSTIC 0x1d
517 #define PREVENT_ALLOW 0x1e
518 #define READ_CAPACITY 0x25
520 #define WRITE_10 0x2a
521 #define POSITION_TO_ELEMENT 0x2b
522 #define SYNCHRONIZE_CACHE 0x35
523 #define WRITE_BUFFER 0x3b
524 #define READ_BUFFER 0x3c
525 #define CHANGE_DEFINITION 0x40
526 #define LOG_SELECT 0x4c
527 #define LOG_SENSE 0x4d
528 #define MODE_SELECT_10 0x55
529 #define MODE_SENSE_10 0x5A
531 #define WRITE_16 0x8a
532 #define SERVICE_ACTION_IN 0x9e
533 #define REPORT_LUNS 0xa0
534 #define MOVE_MEDIUM 0xa5
536 #define WRITE_12 0xaa
537 #define READ_ELEMENT_STATUS 0xb8
542 #define T_DIRECT 0x00
543 #define T_SEQUENTIAL 0x01
544 #define T_PRINTER 0x02
545 #define T_PROCESSOR 0x03
548 #define T_SCANNER 0x06
549 #define T_OPTICAL 0x07
550 #define T_CHANGER 0x08
554 #define T_STORARRAY 0x0c
555 #define T_ENCLOSURE 0x0d
558 #define T_NODEVICE 0x1F
559 #define T_ANY 0xFF /* Used in Quirk table matches */
565 * This length is the initial inquiry length used by the probe code, as
566 * well as the legnth necessary for scsi_print_inquiry() to function
567 * correctly. If either use requires a different length in the future,
568 * the two values should be de-coupled.
570 #define SHORT_INQUIRY_LENGTH 36
572 struct scsi_inquiry_data
575 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
576 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
577 #define SID_QUAL_LU_CONNECTED 0x00 /*
578 * The specified peripheral device
579 * type is currently connected to
580 * logical unit. If the target cannot
581 * determine whether or not a physical
582 * device is currently connected, it
583 * shall also use this peripheral
584 * qualifier when returning the INQUIRY
585 * data. This peripheral qualifier
586 * does not mean that the device is
587 * ready for access by the initiator.
589 #define SID_QUAL_LU_OFFLINE 0x01 /*
590 * The target is capable of supporting
591 * the specified peripheral device type
592 * on this logical unit; however, the
593 * physical device is not currently
594 * connected to this logical unit.
596 #define SID_QUAL_RSVD 0x02
597 #define SID_QUAL_BAD_LU 0x03 /*
598 * The target is not capable of
599 * supporting a physical device on
600 * this logical unit. For this
601 * peripheral qualifier the peripheral
602 * device type shall be set to 1Fh to
603 * provide compatibility with previous
604 * versions of SCSI. All other
605 * peripheral device type values are
606 * reserved for this peripheral
609 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
611 #define SID_QUAL2 0x7F
612 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
614 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
616 #define SCSI_REV_CCS 1
618 #define SCSI_REV_SPC 3
619 #define SCSI_REV_SPC2 4
621 #define SID_ECMA 0x38
623 u_int8_t response_format;
624 #define SID_AENC 0x80
625 #define SID_TrmIOP 0x40
626 u_int8_t additional_length;
627 u_int8_t reserved[2];
629 #define SID_SftRe 0x01
630 #define SID_CmdQue 0x02
631 #define SID_Linked 0x08
632 #define SID_Sync 0x10
633 #define SID_WBus16 0x20
634 #define SID_WBus32 0x40
635 #define SID_RelAdr 0x80
636 #define SID_VENDOR_SIZE 8
637 char vendor[SID_VENDOR_SIZE];
638 #define SID_PRODUCT_SIZE 16
639 char product[SID_PRODUCT_SIZE];
640 #define SID_REVISION_SIZE 4
641 char revision[SID_REVISION_SIZE];
643 * The following fields were taken from SCSI Primary Commands - 2
644 * (SPC-2) Revision 14, Dated 11 November 1999
646 #define SID_VENDOR_SPECIFIC_0_SIZE 20
647 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
649 * An extension of SCSI Parallel Specific Values
651 #define SID_SPI_IUS 0x01
652 #define SID_SPI_QAS 0x02
653 #define SID_SPI_CLOCK_ST 0x00
654 #define SID_SPI_CLOCK_DT 0x04
655 #define SID_SPI_CLOCK_DT_ST 0x0C
656 #define SID_SPI_MASK 0x0F
660 * Version Descriptors, stored 2 byte values.
662 u_int8_t version1[2];
663 u_int8_t version2[2];
664 u_int8_t version3[2];
665 u_int8_t version4[2];
666 u_int8_t version5[2];
667 u_int8_t version6[2];
668 u_int8_t version7[2];
669 u_int8_t version8[2];
671 u_int8_t reserved3[22];
673 #define SID_VENDOR_SPECIFIC_1_SIZE 160
674 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
677 struct scsi_vpd_unit_serial_number
681 #define SVPD_UNIT_SERIAL_NUMBER 0x80
683 u_int8_t length; /* serial number length */
684 #define SVPD_SERIAL_NUM_SIZE 251
685 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
688 struct scsi_read_capacity
697 struct scsi_read_capacity_16
700 #define SRC16_SERVICE_ACTION 0x10
701 uint8_t service_action;
703 uint8_t alloc_len[4];
704 #define SRC16_PMI 0x01
705 #define SRC16_RELADR 0x02
710 struct scsi_read_capacity_data
716 struct scsi_read_capacity_data_long
722 struct scsi_report_luns
731 struct scsi_report_luns_data {
732 u_int8_t length[4]; /* length of LUN inventory, in bytes */
733 u_int8_t reserved[4]; /* unused */
735 * LUN inventory- we only support the type zero form for now.
741 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
742 #define RPL_LUNDATA_T0LUN 1 /* @ lundata[1] */
745 struct scsi_sense_data
748 #define SSD_ERRCODE 0x7F
749 #define SSD_CURRENT_ERROR 0x70
750 #define SSD_DEFERRED_ERROR 0x71
751 #define SSD_ERRCODE_VALID 0x80
755 #define SSD_KEY_NO_SENSE 0x00
756 #define SSD_KEY_RECOVERED_ERROR 0x01
757 #define SSD_KEY_NOT_READY 0x02
758 #define SSD_KEY_MEDIUM_ERROR 0x03
759 #define SSD_KEY_HARDWARE_ERROR 0x04
760 #define SSD_KEY_ILLEGAL_REQUEST 0x05
761 #define SSD_KEY_UNIT_ATTENTION 0x06
762 #define SSD_KEY_DATA_PROTECT 0x07
763 #define SSD_KEY_BLANK_CHECK 0x08
764 #define SSD_KEY_Vendor_Specific 0x09
765 #define SSD_KEY_COPY_ABORTED 0x0a
766 #define SSD_KEY_ABORTED_COMMAND 0x0b
767 #define SSD_KEY_EQUAL 0x0c
768 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
769 #define SSD_KEY_MISCOMPARE 0x0e
770 #define SSD_KEY_RESERVED 0x0f
773 #define SSD_FILEMARK 0x80
776 u_int8_t cmd_spec_info[4];
777 u_int8_t add_sense_code;
778 u_int8_t add_sense_code_qual;
780 u_int8_t sense_key_spec[3];
781 #define SSD_SCS_VALID 0x80
782 #define SSD_FIELDPTR_CMD 0x40
783 #define SSD_BITPTR_VALID 0x08
784 #define SSD_BITPTR_VALUE 0x07
785 #define SSD_MIN_SIZE 18
786 u_int8_t extra_bytes[14];
787 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
790 struct scsi_mode_header_6
792 u_int8_t data_length; /* Sense data length */
793 u_int8_t medium_type;
795 u_int8_t blk_desc_len;
798 struct scsi_mode_header_10
800 u_int8_t data_length[2];/* Sense data length */
801 u_int8_t medium_type;
804 u_int8_t blk_desc_len[2];
807 struct scsi_mode_page_header
810 u_int8_t page_length;
813 struct scsi_mode_blk_desc
821 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
822 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
828 #define SCSI_STATUS_OK 0x00
829 #define SCSI_STATUS_CHECK_COND 0x02
830 #define SCSI_STATUS_COND_MET 0x04
831 #define SCSI_STATUS_BUSY 0x08
832 #define SCSI_STATUS_INTERMED 0x10
833 #define SCSI_STATUS_INTERMED_COND_MET 0x14
834 #define SCSI_STATUS_RESERV_CONFLICT 0x18
835 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
836 #define SCSI_STATUS_QUEUE_FULL 0x28
837 #define SCSI_STATUS_ACA_ACTIVE 0x30
838 #define SCSI_STATUS_TASK_ABORTED 0x40
840 struct scsi_inquiry_pattern {
843 #define SIP_MEDIA_REMOVABLE 0x01
844 #define SIP_MEDIA_FIXED 0x02
847 const char *revision;
850 struct scsi_static_inquiry_pattern {
853 char vendor[SID_VENDOR_SIZE+1];
854 char product[SID_PRODUCT_SIZE+1];
855 char revision[SID_REVISION_SIZE+1];
858 struct scsi_sense_quirk_entry {
859 struct scsi_inquiry_pattern inq_pat;
862 struct sense_key_table_entry *sense_key_info;
863 struct asc_table_entry *asc_info;
866 struct sense_key_table_entry {
872 struct asc_table_entry {
879 struct op_table_entry {
885 struct scsi_op_quirk_entry {
886 struct scsi_inquiry_pattern inq_pat;
888 struct op_table_entry *op_table;
892 SSS_FLAG_NONE = 0x00,
893 SSS_FLAG_PRINT_COMMAND = 0x01
894 } scsi_sense_string_flags;
903 extern const char *scsi_sense_key_text[];
908 void scsi_sense_desc(int sense_key, int asc, int ascq,
909 struct scsi_inquiry_data *inq_data,
910 const char **sense_key_desc, const char **asc_desc);
911 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
912 struct scsi_inquiry_data *inq_data,
913 u_int32_t sense_flags);
914 const char * scsi_status_string(struct ccb_scsiio *csio);
916 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
917 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
918 scsi_sense_string_flags flags);
919 char * scsi_sense_string(struct ccb_scsiio *csio,
920 char *str, int str_len);
921 void scsi_sense_print(struct ccb_scsiio *csio);
922 int scsi_interpret_sense(union ccb *ccb,
923 u_int32_t sense_flags,
924 u_int32_t *relsim_flags,
925 u_int32_t *reduction,
927 scsi_sense_action error_action);
929 int scsi_command_string(struct cam_device *device,
930 struct ccb_scsiio *csio, struct sbuf *sb);
931 int scsi_sense_sbuf(struct cam_device *device,
932 struct ccb_scsiio *csio, struct sbuf *sb,
933 scsi_sense_string_flags flags);
934 char * scsi_sense_string(struct cam_device *device,
935 struct ccb_scsiio *csio,
936 char *str, int str_len);
937 void scsi_sense_print(struct cam_device *device,
938 struct ccb_scsiio *csio, FILE *ofile);
939 int scsi_interpret_sense(struct cam_device *device,
941 u_int32_t sense_flags,
942 u_int32_t *relsim_flags,
943 u_int32_t *reduction,
945 scsi_sense_action error_action);
948 #define SF_RETRY_UA 0x01
949 #define SF_NO_PRINT 0x02
950 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
951 #define SF_PRINT_ALWAYS 0x08
954 const char * scsi_op_desc(u_int16_t opcode,
955 struct scsi_inquiry_data *inq_data);
956 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
959 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
961 u_int scsi_calc_syncsrate(u_int period_factor);
962 u_int scsi_calc_syncparam(u_int period);
964 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
965 void (*cbfcnp)(struct cam_periph *,
968 u_int8_t sense_len, u_int32_t timeout);
970 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
971 void (*cbfcnp)(struct cam_periph *,
973 void *data_ptr, u_int8_t dxfer_len,
974 u_int8_t tag_action, u_int8_t sense_len,
977 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
978 void (*cbfcnp)(struct cam_periph *, union ccb *),
979 u_int8_t tag_action, u_int8_t *inq_buf,
980 u_int32_t inq_len, int evpd, u_int8_t page_code,
981 u_int8_t sense_len, u_int32_t timeout);
983 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
984 void (*cbfcnp)(struct cam_periph *,
986 u_int8_t tag_action, int dbd,
987 u_int8_t page_code, u_int8_t page,
988 u_int8_t *param_buf, u_int32_t param_len,
989 u_int8_t sense_len, u_int32_t timeout);
990 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
991 void (*cbfcnp)(struct cam_periph *,
993 u_int8_t tag_action, int dbd,
994 u_int8_t page_code, u_int8_t page,
995 u_int8_t *param_buf, u_int32_t param_len,
996 int minimum_cmd_size, u_int8_t sense_len,
999 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
1000 void (*cbfcnp)(struct cam_periph *,
1002 u_int8_t tag_action, int scsi_page_fmt,
1003 int save_pages, u_int8_t *param_buf,
1004 u_int32_t param_len, u_int8_t sense_len,
1007 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
1008 void (*cbfcnp)(struct cam_periph *,
1010 u_int8_t tag_action, int scsi_page_fmt,
1011 int save_pages, u_int8_t *param_buf,
1012 u_int32_t param_len, int minimum_cmd_size,
1013 u_int8_t sense_len, u_int32_t timeout);
1015 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
1016 void (*cbfcnp)(struct cam_periph *, union ccb *),
1017 u_int8_t tag_action, u_int8_t page_code,
1018 u_int8_t page, int save_pages, int ppc,
1019 u_int32_t paramptr, u_int8_t *param_buf,
1020 u_int32_t param_len, u_int8_t sense_len,
1023 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
1024 void (*cbfcnp)(struct cam_periph *,
1025 union ccb *), u_int8_t tag_action,
1026 u_int8_t page_code, int save_pages,
1027 int pc_reset, u_int8_t *param_buf,
1028 u_int32_t param_len, u_int8_t sense_len,
1031 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
1032 void (*cbfcnp)(struct cam_periph *, union ccb *),
1033 u_int8_t tag_action, u_int8_t action,
1034 u_int8_t sense_len, u_int32_t timeout);
1036 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
1037 void (*cbfcnp)(struct cam_periph *,
1038 union ccb *), u_int8_t tag_action,
1039 struct scsi_read_capacity_data *,
1040 u_int8_t sense_len, u_int32_t timeout);
1041 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
1042 void (*cbfcnp)(struct cam_periph *,
1043 union ccb *), uint8_t tag_action,
1044 uint64_t lba, int reladr, int pmi,
1045 struct scsi_read_capacity_data_long
1046 *rcap_buf, uint8_t sense_len,
1049 void scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
1050 void (*cbfcnp)(struct cam_periph *,
1051 union ccb *), u_int8_t tag_action,
1052 struct scsi_report_luns_data *,
1053 u_int32_t alloc_len, u_int8_t sense_len,
1056 void scsi_synchronize_cache(struct ccb_scsiio *csio,
1058 void (*cbfcnp)(struct cam_periph *,
1059 union ccb *), u_int8_t tag_action,
1060 u_int32_t begin_lba, u_int16_t lb_count,
1061 u_int8_t sense_len, u_int32_t timeout);
1063 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
1064 void (*cbfcnp)(struct cam_periph *, union ccb *),
1065 u_int8_t tag_action, int readop, u_int8_t byte2,
1066 int minimum_cmd_size, u_int64_t lba,
1067 u_int32_t block_count, u_int8_t *data_ptr,
1068 u_int32_t dxfer_len, u_int8_t sense_len,
1071 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
1072 void (*cbfcnp)(struct cam_periph *, union ccb *),
1073 u_int8_t tag_action, int start, int load_eject,
1074 int immediate, u_int8_t sense_len, u_int32_t timeout);
1076 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
1077 int scsi_static_inquiry_match(caddr_t inqbuffer,
1078 caddr_t table_entry);
1080 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1081 int *error_code, int *sense_key,
1082 int *asc, int *ascq);
1083 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
1084 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
1085 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
1086 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
1087 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
1088 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
1089 static __inline int32_t scsi_3btol(u_int8_t *bytes);
1090 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
1091 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes);
1092 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
1093 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
1095 static __inline void
1096 scsi_extract_sense(struct scsi_sense_data *sense, int *error_code,
1097 int *sense_key, int *asc, int *ascq)
1099 *error_code = sense->error_code & SSD_ERRCODE;
1100 *sense_key = sense->flags & SSD_KEY;
1101 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
1102 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
1105 static __inline void
1106 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
1109 bytes[0] = (val >> 8) & 0xff;
1110 bytes[1] = val & 0xff;
1113 static __inline void
1114 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
1117 bytes[0] = (val >> 16) & 0xff;
1118 bytes[1] = (val >> 8) & 0xff;
1119 bytes[2] = val & 0xff;
1122 static __inline void
1123 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
1126 bytes[0] = (val >> 24) & 0xff;
1127 bytes[1] = (val >> 16) & 0xff;
1128 bytes[2] = (val >> 8) & 0xff;
1129 bytes[3] = val & 0xff;
1132 static __inline void
1133 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
1135 bytes[0] = (val >> 56) & 0xff;
1136 bytes[1] = (val >> 48) & 0xff;
1137 bytes[2] = (val >> 40) & 0xff;
1138 bytes[3] = (val >> 32) & 0xff;
1139 bytes[4] = (val >> 24) & 0xff;
1140 bytes[5] = (val >> 16) & 0xff;
1141 bytes[6] = (val >> 8) & 0xff;
1142 bytes[7] = val & 0xff;
1145 static __inline u_int32_t
1146 scsi_2btoul(u_int8_t *bytes)
1150 rv = (bytes[0] << 8) |
1155 static __inline uint64_t
1156 scsi_8btou64(uint8_t *bytes)
1160 rv = (((uint64_t)bytes[0]) << 56) |
1161 (((uint64_t)bytes[1]) << 48) |
1162 (((uint64_t)bytes[2]) << 40) |
1163 (((uint64_t)bytes[3]) << 32) |
1164 (((uint64_t)bytes[4]) << 24) |
1165 (((uint64_t)bytes[5]) << 16) |
1166 (((uint64_t)bytes[6]) << 8) |
1171 static __inline u_int32_t
1172 scsi_3btoul(u_int8_t *bytes)
1176 rv = (bytes[0] << 16) |
1182 static __inline int32_t
1183 scsi_3btol(u_int8_t *bytes)
1185 u_int32_t rc = scsi_3btoul(bytes);
1187 if (rc & 0x00800000)
1190 return (int32_t) rc;
1193 static __inline u_int32_t
1194 scsi_4btoul(u_int8_t *bytes)
1198 rv = (bytes[0] << 24) |
1206 * Given the pointer to a returned mode sense buffer, return a pointer to
1207 * the start of the first mode page.
1209 static __inline void *
1210 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
1214 page_start = (void *)((u_int8_t *)&mode_header[1] +
1215 mode_header->blk_desc_len);
1220 static __inline void *
1221 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
1225 page_start = (void *)((u_int8_t *)&mode_header[1] +
1226 scsi_2btoul(mode_header->blk_desc_len));
1233 #endif /*_SCSI_SCSI_ALL_H*/