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.9 2007/11/22 16:34:25 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 MOVE_MEDIUM 0xa5
535 #define WRITE_12 0xaa
536 #define READ_ELEMENT_STATUS 0xb8
541 #define T_DIRECT 0x00
542 #define T_SEQUENTIAL 0x01
543 #define T_PRINTER 0x02
544 #define T_PROCESSOR 0x03
547 #define T_SCANNER 0x06
548 #define T_OPTICAL 0x07
549 #define T_CHANGER 0x08
553 #define T_STORARRAY 0x0c
554 #define T_ENCLOSURE 0x0d
557 #define T_NODEVICE 0x1F
558 #define T_ANY 0xFF /* Used in Quirk table matches */
564 * This length is the initial inquiry length used by the probe code, as
565 * well as the legnth necessary for scsi_print_inquiry() to function
566 * correctly. If either use requires a different length in the future,
567 * the two values should be de-coupled.
569 #define SHORT_INQUIRY_LENGTH 36
571 struct scsi_inquiry_data
574 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
575 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
576 #define SID_QUAL_LU_CONNECTED 0x00 /*
577 * The specified peripheral device
578 * type is currently connected to
579 * logical unit. If the target cannot
580 * determine whether or not a physical
581 * device is currently connected, it
582 * shall also use this peripheral
583 * qualifier when returning the INQUIRY
584 * data. This peripheral qualifier
585 * does not mean that the device is
586 * ready for access by the initiator.
588 #define SID_QUAL_LU_OFFLINE 0x01 /*
589 * The target is capable of supporting
590 * the specified peripheral device type
591 * on this logical unit; however, the
592 * physical device is not currently
593 * connected to this logical unit.
595 #define SID_QUAL_RSVD 0x02
596 #define SID_QUAL_BAD_LU 0x03 /*
597 * The target is not capable of
598 * supporting a physical device on
599 * this logical unit. For this
600 * peripheral qualifier the peripheral
601 * device type shall be set to 1Fh to
602 * provide compatibility with previous
603 * versions of SCSI. All other
604 * peripheral device type values are
605 * reserved for this peripheral
608 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
610 #define SID_QUAL2 0x7F
611 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
613 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
615 #define SCSI_REV_CCS 1
617 #define SCSI_REV_SPC 3
618 #define SCSI_REV_SPC2 4
620 #define SID_ECMA 0x38
622 u_int8_t response_format;
623 #define SID_AENC 0x80
624 #define SID_TrmIOP 0x40
625 u_int8_t additional_length;
626 u_int8_t reserved[2];
628 #define SID_SftRe 0x01
629 #define SID_CmdQue 0x02
630 #define SID_Linked 0x08
631 #define SID_Sync 0x10
632 #define SID_WBus16 0x20
633 #define SID_WBus32 0x40
634 #define SID_RelAdr 0x80
635 #define SID_VENDOR_SIZE 8
636 char vendor[SID_VENDOR_SIZE];
637 #define SID_PRODUCT_SIZE 16
638 char product[SID_PRODUCT_SIZE];
639 #define SID_REVISION_SIZE 4
640 char revision[SID_REVISION_SIZE];
642 * The following fields were taken from SCSI Primary Commands - 2
643 * (SPC-2) Revision 14, Dated 11 November 1999
645 #define SID_VENDOR_SPECIFIC_0_SIZE 20
646 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
648 * An extension of SCSI Parallel Specific Values
650 #define SID_SPI_IUS 0x01
651 #define SID_SPI_QAS 0x02
652 #define SID_SPI_CLOCK_ST 0x00
653 #define SID_SPI_CLOCK_DT 0x04
654 #define SID_SPI_CLOCK_DT_ST 0x0C
655 #define SID_SPI_MASK 0x0F
659 * Version Descriptors, stored 2 byte values.
661 u_int8_t version1[2];
662 u_int8_t version2[2];
663 u_int8_t version3[2];
664 u_int8_t version4[2];
665 u_int8_t version5[2];
666 u_int8_t version6[2];
667 u_int8_t version7[2];
668 u_int8_t version8[2];
670 u_int8_t reserved3[22];
672 #define SID_VENDOR_SPECIFIC_1_SIZE 160
673 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
676 struct scsi_vpd_unit_serial_number
680 #define SVPD_UNIT_SERIAL_NUMBER 0x80
682 u_int8_t length; /* serial number length */
683 #define SVPD_SERIAL_NUM_SIZE 251
684 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
687 struct scsi_read_capacity
696 struct scsi_read_capacity_16
699 #define SRC16_SERVICE_ACTION 0x10
700 uint8_t service_action;
702 uint8_t alloc_len[4];
703 #define SRC16_PMI 0x01
704 #define SRC16_RELADR 0x02
709 struct scsi_read_capacity_data
715 struct scsi_read_capacity_data_long
721 struct scsi_sense_data
724 #define SSD_ERRCODE 0x7F
725 #define SSD_CURRENT_ERROR 0x70
726 #define SSD_DEFERRED_ERROR 0x71
727 #define SSD_ERRCODE_VALID 0x80
731 #define SSD_KEY_NO_SENSE 0x00
732 #define SSD_KEY_RECOVERED_ERROR 0x01
733 #define SSD_KEY_NOT_READY 0x02
734 #define SSD_KEY_MEDIUM_ERROR 0x03
735 #define SSD_KEY_HARDWARE_ERROR 0x04
736 #define SSD_KEY_ILLEGAL_REQUEST 0x05
737 #define SSD_KEY_UNIT_ATTENTION 0x06
738 #define SSD_KEY_DATA_PROTECT 0x07
739 #define SSD_KEY_BLANK_CHECK 0x08
740 #define SSD_KEY_Vendor_Specific 0x09
741 #define SSD_KEY_COPY_ABORTED 0x0a
742 #define SSD_KEY_ABORTED_COMMAND 0x0b
743 #define SSD_KEY_EQUAL 0x0c
744 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
745 #define SSD_KEY_MISCOMPARE 0x0e
746 #define SSD_KEY_RESERVED 0x0f
749 #define SSD_FILEMARK 0x80
752 u_int8_t cmd_spec_info[4];
753 u_int8_t add_sense_code;
754 u_int8_t add_sense_code_qual;
756 u_int8_t sense_key_spec[3];
757 #define SSD_SCS_VALID 0x80
758 #define SSD_FIELDPTR_CMD 0x40
759 #define SSD_BITPTR_VALID 0x08
760 #define SSD_BITPTR_VALUE 0x07
761 #define SSD_MIN_SIZE 18
762 u_int8_t extra_bytes[14];
763 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
766 struct scsi_mode_header_6
768 u_int8_t data_length; /* Sense data length */
769 u_int8_t medium_type;
771 u_int8_t blk_desc_len;
774 struct scsi_mode_header_10
776 u_int8_t data_length[2];/* Sense data length */
777 u_int8_t medium_type;
780 u_int8_t blk_desc_len[2];
783 struct scsi_mode_page_header
786 u_int8_t page_length;
789 struct scsi_mode_blk_desc
797 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
798 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
802 #define SCSI_STATUS_OK 0x00
803 #define SCSI_STATUS_CHECK_COND 0x02
804 #define SCSI_STATUS_COND_MET 0x04
805 #define SCSI_STATUS_BUSY 0x08
806 #define SCSI_STATUS_INTERMED 0x10
807 #define SCSI_STATUS_INTERMED_COND_MET 0x14
808 #define SCSI_STATUS_RESERV_CONFLICT 0x18
809 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
810 #define SCSI_STATUS_QUEUE_FULL 0x28
811 #define SCSI_STATUS_ACA_ACTIVE 0x30
812 #define SCSI_STATUS_TASK_ABORTED 0x40
814 struct scsi_inquiry_pattern {
817 #define SIP_MEDIA_REMOVABLE 0x01
818 #define SIP_MEDIA_FIXED 0x02
821 const char *revision;
824 struct scsi_static_inquiry_pattern {
827 char vendor[SID_VENDOR_SIZE+1];
828 char product[SID_PRODUCT_SIZE+1];
829 char revision[SID_REVISION_SIZE+1];
832 struct scsi_sense_quirk_entry {
833 struct scsi_inquiry_pattern inq_pat;
836 struct sense_key_table_entry *sense_key_info;
837 struct asc_table_entry *asc_info;
840 struct sense_key_table_entry {
846 struct asc_table_entry {
853 struct op_table_entry {
859 struct scsi_op_quirk_entry {
860 struct scsi_inquiry_pattern inq_pat;
862 struct op_table_entry *op_table;
866 SSS_FLAG_NONE = 0x00,
867 SSS_FLAG_PRINT_COMMAND = 0x01
868 } scsi_sense_string_flags;
877 extern const char *scsi_sense_key_text[];
882 void scsi_sense_desc(int sense_key, int asc, int ascq,
883 struct scsi_inquiry_data *inq_data,
884 const char **sense_key_desc, const char **asc_desc);
885 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
886 struct scsi_inquiry_data *inq_data,
887 u_int32_t sense_flags);
888 const char * scsi_status_string(struct ccb_scsiio *csio);
890 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
891 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
892 scsi_sense_string_flags flags);
893 char * scsi_sense_string(struct ccb_scsiio *csio,
894 char *str, int str_len);
895 void scsi_sense_print(struct ccb_scsiio *csio);
896 int scsi_interpret_sense(union ccb *ccb,
897 u_int32_t sense_flags,
898 u_int32_t *relsim_flags,
899 u_int32_t *reduction,
901 scsi_sense_action error_action);
903 int scsi_command_string(struct cam_device *device,
904 struct ccb_scsiio *csio, struct sbuf *sb);
905 int scsi_sense_sbuf(struct cam_device *device,
906 struct ccb_scsiio *csio, struct sbuf *sb,
907 scsi_sense_string_flags flags);
908 char * scsi_sense_string(struct cam_device *device,
909 struct ccb_scsiio *csio,
910 char *str, int str_len);
911 void scsi_sense_print(struct cam_device *device,
912 struct ccb_scsiio *csio, FILE *ofile);
913 int scsi_interpret_sense(struct cam_device *device,
915 u_int32_t sense_flags,
916 u_int32_t *relsim_flags,
917 u_int32_t *reduction,
919 scsi_sense_action error_action);
922 #define SF_RETRY_UA 0x01
923 #define SF_NO_PRINT 0x02
924 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
925 #define SF_PRINT_ALWAYS 0x08
928 const char * scsi_op_desc(u_int16_t opcode,
929 struct scsi_inquiry_data *inq_data);
930 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
933 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
935 u_int scsi_calc_syncsrate(u_int period_factor);
936 u_int scsi_calc_syncparam(u_int period);
938 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
939 void (*cbfcnp)(struct cam_periph *,
942 u_int8_t sense_len, u_int32_t timeout);
944 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
945 void (*cbfcnp)(struct cam_periph *,
947 void *data_ptr, u_int8_t dxfer_len,
948 u_int8_t tag_action, u_int8_t sense_len,
951 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
952 void (*cbfcnp)(struct cam_periph *, union ccb *),
953 u_int8_t tag_action, u_int8_t *inq_buf,
954 u_int32_t inq_len, int evpd, u_int8_t page_code,
955 u_int8_t sense_len, u_int32_t timeout);
957 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
958 void (*cbfcnp)(struct cam_periph *,
960 u_int8_t tag_action, int dbd,
961 u_int8_t page_code, u_int8_t page,
962 u_int8_t *param_buf, u_int32_t param_len,
963 u_int8_t sense_len, u_int32_t timeout);
964 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
965 void (*cbfcnp)(struct cam_periph *,
967 u_int8_t tag_action, int dbd,
968 u_int8_t page_code, u_int8_t page,
969 u_int8_t *param_buf, u_int32_t param_len,
970 int minimum_cmd_size, u_int8_t sense_len,
973 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
974 void (*cbfcnp)(struct cam_periph *,
976 u_int8_t tag_action, int scsi_page_fmt,
977 int save_pages, u_int8_t *param_buf,
978 u_int32_t param_len, u_int8_t sense_len,
981 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
982 void (*cbfcnp)(struct cam_periph *,
984 u_int8_t tag_action, int scsi_page_fmt,
985 int save_pages, u_int8_t *param_buf,
986 u_int32_t param_len, int minimum_cmd_size,
987 u_int8_t sense_len, u_int32_t timeout);
989 void scsi_log_sense(struct ccb_scsiio *csio, u_int32_t retries,
990 void (*cbfcnp)(struct cam_periph *, union ccb *),
991 u_int8_t tag_action, u_int8_t page_code,
992 u_int8_t page, int save_pages, int ppc,
993 u_int32_t paramptr, u_int8_t *param_buf,
994 u_int32_t param_len, u_int8_t sense_len,
997 void scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
998 void (*cbfcnp)(struct cam_periph *,
999 union ccb *), u_int8_t tag_action,
1000 u_int8_t page_code, int save_pages,
1001 int pc_reset, u_int8_t *param_buf,
1002 u_int32_t param_len, u_int8_t sense_len,
1005 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
1006 void (*cbfcnp)(struct cam_periph *,
1007 union ccb *), u_int8_t tag_action,
1008 struct scsi_read_capacity_data *rcap_buf,
1009 u_int8_t sense_len, u_int32_t timeout);
1010 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
1011 void (*cbfcnp)(struct cam_periph *,
1012 union ccb *), uint8_t tag_action,
1013 uint64_t lba, int reladr, int pmi,
1014 struct scsi_read_capacity_data_long
1015 *rcap_buf, uint8_t sense_len,
1018 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
1019 void (*cbfcnp)(struct cam_periph *, union ccb *),
1020 u_int8_t tag_action, u_int8_t action,
1021 u_int8_t sense_len, u_int32_t timeout);
1023 void scsi_synchronize_cache(struct ccb_scsiio *csio,
1025 void (*cbfcnp)(struct cam_periph *,
1026 union ccb *), u_int8_t tag_action,
1027 u_int32_t begin_lba, u_int16_t lb_count,
1028 u_int8_t sense_len, u_int32_t timeout);
1030 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
1031 void (*cbfcnp)(struct cam_periph *, union ccb *),
1032 u_int8_t tag_action, int readop, u_int8_t byte2,
1033 int minimum_cmd_size, u_int64_t lba,
1034 u_int32_t block_count, u_int8_t *data_ptr,
1035 u_int32_t dxfer_len, u_int8_t sense_len,
1038 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
1039 void (*cbfcnp)(struct cam_periph *, union ccb *),
1040 u_int8_t tag_action, int start, int load_eject,
1041 int immediate, u_int8_t sense_len, u_int32_t timeout);
1043 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
1044 int scsi_static_inquiry_match(caddr_t inqbuffer,
1045 caddr_t table_entry);
1047 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
1048 int *error_code, int *sense_key,
1049 int *asc, int *ascq);
1050 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
1051 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
1052 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
1053 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
1054 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
1055 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
1056 static __inline int32_t scsi_3btol(u_int8_t *bytes);
1057 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
1058 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes);
1059 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
1060 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
1062 static __inline void
1063 scsi_extract_sense(struct scsi_sense_data *sense, int *error_code,
1064 int *sense_key, int *asc, int *ascq)
1066 *error_code = sense->error_code & SSD_ERRCODE;
1067 *sense_key = sense->flags & SSD_KEY;
1068 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
1069 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
1072 static __inline void
1073 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
1076 bytes[0] = (val >> 8) & 0xff;
1077 bytes[1] = val & 0xff;
1080 static __inline void
1081 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
1084 bytes[0] = (val >> 16) & 0xff;
1085 bytes[1] = (val >> 8) & 0xff;
1086 bytes[2] = val & 0xff;
1089 static __inline void
1090 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
1093 bytes[0] = (val >> 24) & 0xff;
1094 bytes[1] = (val >> 16) & 0xff;
1095 bytes[2] = (val >> 8) & 0xff;
1096 bytes[3] = val & 0xff;
1099 static __inline void
1100 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
1102 bytes[0] = (val >> 56) & 0xff;
1103 bytes[1] = (val >> 48) & 0xff;
1104 bytes[2] = (val >> 40) & 0xff;
1105 bytes[3] = (val >> 32) & 0xff;
1106 bytes[4] = (val >> 24) & 0xff;
1107 bytes[5] = (val >> 16) & 0xff;
1108 bytes[6] = (val >> 8) & 0xff;
1109 bytes[7] = val & 0xff;
1112 static __inline u_int32_t
1113 scsi_2btoul(u_int8_t *bytes)
1117 rv = (bytes[0] << 8) |
1122 static __inline uint64_t
1123 scsi_8btou64(uint8_t *bytes)
1127 rv = (((uint64_t)bytes[0]) << 56) |
1128 (((uint64_t)bytes[1]) << 48) |
1129 (((uint64_t)bytes[2]) << 40) |
1130 (((uint64_t)bytes[3]) << 32) |
1131 (((uint64_t)bytes[4]) << 24) |
1132 (((uint64_t)bytes[5]) << 16) |
1133 (((uint64_t)bytes[6]) << 8) |
1138 static __inline u_int32_t
1139 scsi_3btoul(u_int8_t *bytes)
1143 rv = (bytes[0] << 16) |
1149 static __inline int32_t
1150 scsi_3btol(u_int8_t *bytes)
1152 u_int32_t rc = scsi_3btoul(bytes);
1154 if (rc & 0x00800000)
1157 return (int32_t) rc;
1160 static __inline u_int32_t
1161 scsi_4btoul(u_int8_t *bytes)
1165 rv = (bytes[0] << 24) |
1173 * Given the pointer to a returned mode sense buffer, return a pointer to
1174 * the start of the first mode page.
1176 static __inline void *
1177 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
1181 page_start = (void *)((u_int8_t *)&mode_header[1] +
1182 mode_header->blk_desc_len);
1187 static __inline void *
1188 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
1192 page_start = (void *)((u_int8_t *)&mode_header[1] +
1193 scsi_2btoul(mode_header->blk_desc_len));
1200 #endif /*_SCSI_SCSI_ALL_H*/