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.8 2007/11/18 17:53:01 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_control_page {
271 u_int8_t page_length;
273 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
274 u_int8_t queue_flags;
275 #define SCP_QUEUE_ALG_MASK 0xF0
276 #define SCP_QUEUE_ALG_RESTRICTED 0x00
277 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
278 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
279 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
280 u_int8_t eca_and_aen;
281 #define SCP_EECA 0x80 /*Enable Extended CA*/
282 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
283 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
284 #define SCP_EAENP 0x01 /*Error AEN Permission*/
286 u_int8_t aen_holdoff_period[2];
315 #define PR_PREVENT 0x01
316 #define PR_ALLOW 0x00
318 struct scsi_sync_cache
322 u_int8_t begin_lba[4];
324 u_int8_t lb_count[2];
329 struct scsi_changedef
340 struct scsi_read_buffer
344 #define RWB_MODE 0x07
345 #define RWB_MODE_HDR_DATA 0x00
346 #define RWB_MODE_DATA 0x02
347 #define RWB_MODE_DOWNLOAD 0x04
348 #define RWB_MODE_DOWNLOAD_SAVE 0x05
355 struct scsi_write_buffer
369 /* only 5 bits are valid in the MSB address byte */
370 #define SRW_TOPADDR 0x1F
378 #define SRW10_RELADDR 0x01
379 /* EBP defined for WRITE(10) only */
380 #define SRW10_EBP 0x04
381 #define SRW10_FUA 0x08
382 #define SRW10_DPO 0x10
393 #define SRW12_RELADDR 0x01
394 #define SRW12_FUA 0x08
395 #define SRW12_DPO 0x10
406 #define SRW16_RELADDR 0x01
407 #define SRW16_FUA 0x08
408 #define SRW16_DPO 0x10
417 struct scsi_start_stop_unit
421 #define SSS_IMMED 0x01
422 u_int8_t reserved[2];
424 #define SSS_START 0x01
425 #define SSS_LOEJ 0x02
429 #define SC_SCSI_1 0x01
430 #define SC_SCSI_2 0x03
436 #define TEST_UNIT_READY 0x00
437 #define REQUEST_SENSE 0x03
441 #define MODE_SELECT_6 0x15
442 #define MODE_SENSE_6 0x1a
443 #define START_STOP_UNIT 0x1b
444 #define START_STOP 0x1b
447 #define RECEIVE_DIAGNOSTIC 0x1c
448 #define SEND_DIAGNOSTIC 0x1d
449 #define PREVENT_ALLOW 0x1e
450 #define READ_CAPACITY 0x25
452 #define WRITE_10 0x2a
453 #define POSITION_TO_ELEMENT 0x2b
454 #define SYNCHRONIZE_CACHE 0x35
455 #define WRITE_BUFFER 0x3b
456 #define READ_BUFFER 0x3c
457 #define CHANGE_DEFINITION 0x40
458 #define MODE_SELECT_10 0x55
459 #define MODE_SENSE_10 0x5A
461 #define WRITE_16 0x8a
462 #define SERVICE_ACTION_IN 0x9e
463 #define MOVE_MEDIUM 0xa5
465 #define WRITE_12 0xaa
466 #define READ_ELEMENT_STATUS 0xb8
471 #define T_DIRECT 0x00
472 #define T_SEQUENTIAL 0x01
473 #define T_PRINTER 0x02
474 #define T_PROCESSOR 0x03
477 #define T_SCANNER 0x06
478 #define T_OPTICAL 0x07
479 #define T_CHANGER 0x08
483 #define T_STORARRAY 0x0c
484 #define T_ENCLOSURE 0x0d
487 #define T_NODEVICE 0x1F
488 #define T_ANY 0xFF /* Used in Quirk table matches */
494 * This length is the initial inquiry length used by the probe code, as
495 * well as the legnth necessary for scsi_print_inquiry() to function
496 * correctly. If either use requires a different length in the future,
497 * the two values should be de-coupled.
499 #define SHORT_INQUIRY_LENGTH 36
501 struct scsi_inquiry_data
504 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
505 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
506 #define SID_QUAL_LU_CONNECTED 0x00 /*
507 * The specified peripheral device
508 * type is currently connected to
509 * logical unit. If the target cannot
510 * determine whether or not a physical
511 * device is currently connected, it
512 * shall also use this peripheral
513 * qualifier when returning the INQUIRY
514 * data. This peripheral qualifier
515 * does not mean that the device is
516 * ready for access by the initiator.
518 #define SID_QUAL_LU_OFFLINE 0x01 /*
519 * The target is capable of supporting
520 * the specified peripheral device type
521 * on this logical unit; however, the
522 * physical device is not currently
523 * connected to this logical unit.
525 #define SID_QUAL_RSVD 0x02
526 #define SID_QUAL_BAD_LU 0x03 /*
527 * The target is not capable of
528 * supporting a physical device on
529 * this logical unit. For this
530 * peripheral qualifier the peripheral
531 * device type shall be set to 1Fh to
532 * provide compatibility with previous
533 * versions of SCSI. All other
534 * peripheral device type values are
535 * reserved for this peripheral
538 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
540 #define SID_QUAL2 0x7F
541 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
543 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
545 #define SCSI_REV_CCS 1
547 #define SCSI_REV_SPC 3
548 #define SCSI_REV_SPC2 4
550 #define SID_ECMA 0x38
552 u_int8_t response_format;
553 #define SID_AENC 0x80
554 #define SID_TrmIOP 0x40
555 u_int8_t additional_length;
556 u_int8_t reserved[2];
558 #define SID_SftRe 0x01
559 #define SID_CmdQue 0x02
560 #define SID_Linked 0x08
561 #define SID_Sync 0x10
562 #define SID_WBus16 0x20
563 #define SID_WBus32 0x40
564 #define SID_RelAdr 0x80
565 #define SID_VENDOR_SIZE 8
566 char vendor[SID_VENDOR_SIZE];
567 #define SID_PRODUCT_SIZE 16
568 char product[SID_PRODUCT_SIZE];
569 #define SID_REVISION_SIZE 4
570 char revision[SID_REVISION_SIZE];
572 * The following fields were taken from SCSI Primary Commands - 2
573 * (SPC-2) Revision 14, Dated 11 November 1999
575 #define SID_VENDOR_SPECIFIC_0_SIZE 20
576 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
578 * An extension of SCSI Parallel Specific Values
580 #define SID_SPI_IUS 0x01
581 #define SID_SPI_QAS 0x02
582 #define SID_SPI_CLOCK_ST 0x00
583 #define SID_SPI_CLOCK_DT 0x04
584 #define SID_SPI_CLOCK_DT_ST 0x0C
585 #define SID_SPI_MASK 0x0F
589 * Version Descriptors, stored 2 byte values.
591 u_int8_t version1[2];
592 u_int8_t version2[2];
593 u_int8_t version3[2];
594 u_int8_t version4[2];
595 u_int8_t version5[2];
596 u_int8_t version6[2];
597 u_int8_t version7[2];
598 u_int8_t version8[2];
600 u_int8_t reserved3[22];
602 #define SID_VENDOR_SPECIFIC_1_SIZE 160
603 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
606 struct scsi_vpd_unit_serial_number
610 #define SVPD_UNIT_SERIAL_NUMBER 0x80
612 u_int8_t length; /* serial number length */
613 #define SVPD_SERIAL_NUM_SIZE 251
614 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
617 struct scsi_read_capacity
626 struct scsi_read_capacity_16
629 #define SRC16_SERVICE_ACTION 0x10
630 uint8_t service_action;
632 uint8_t alloc_len[4];
633 #define SRC16_PMI 0x01
634 #define SRC16_RELADR 0x02
639 struct scsi_read_capacity_data
645 struct scsi_read_capacity_data_long
651 struct scsi_sense_data
654 #define SSD_ERRCODE 0x7F
655 #define SSD_CURRENT_ERROR 0x70
656 #define SSD_DEFERRED_ERROR 0x71
657 #define SSD_ERRCODE_VALID 0x80
661 #define SSD_KEY_NO_SENSE 0x00
662 #define SSD_KEY_RECOVERED_ERROR 0x01
663 #define SSD_KEY_NOT_READY 0x02
664 #define SSD_KEY_MEDIUM_ERROR 0x03
665 #define SSD_KEY_HARDWARE_ERROR 0x04
666 #define SSD_KEY_ILLEGAL_REQUEST 0x05
667 #define SSD_KEY_UNIT_ATTENTION 0x06
668 #define SSD_KEY_DATA_PROTECT 0x07
669 #define SSD_KEY_BLANK_CHECK 0x08
670 #define SSD_KEY_Vendor_Specific 0x09
671 #define SSD_KEY_COPY_ABORTED 0x0a
672 #define SSD_KEY_ABORTED_COMMAND 0x0b
673 #define SSD_KEY_EQUAL 0x0c
674 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
675 #define SSD_KEY_MISCOMPARE 0x0e
676 #define SSD_KEY_RESERVED 0x0f
679 #define SSD_FILEMARK 0x80
682 u_int8_t cmd_spec_info[4];
683 u_int8_t add_sense_code;
684 u_int8_t add_sense_code_qual;
686 u_int8_t sense_key_spec[3];
687 #define SSD_SCS_VALID 0x80
688 #define SSD_FIELDPTR_CMD 0x40
689 #define SSD_BITPTR_VALID 0x08
690 #define SSD_BITPTR_VALUE 0x07
691 #define SSD_MIN_SIZE 18
692 u_int8_t extra_bytes[14];
693 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
696 struct scsi_mode_header_6
698 u_int8_t data_length; /* Sense data length */
699 u_int8_t medium_type;
701 u_int8_t blk_desc_len;
704 struct scsi_mode_header_10
706 u_int8_t data_length[2];/* Sense data length */
707 u_int8_t medium_type;
710 u_int8_t blk_desc_len[2];
713 struct scsi_mode_page_header
716 u_int8_t page_length;
719 struct scsi_mode_blk_desc
727 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
728 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
732 #define SCSI_STATUS_OK 0x00
733 #define SCSI_STATUS_CHECK_COND 0x02
734 #define SCSI_STATUS_COND_MET 0x04
735 #define SCSI_STATUS_BUSY 0x08
736 #define SCSI_STATUS_INTERMED 0x10
737 #define SCSI_STATUS_INTERMED_COND_MET 0x14
738 #define SCSI_STATUS_RESERV_CONFLICT 0x18
739 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
740 #define SCSI_STATUS_QUEUE_FULL 0x28
741 #define SCSI_STATUS_ACA_ACTIVE 0x30
742 #define SCSI_STATUS_TASK_ABORTED 0x40
744 struct scsi_inquiry_pattern {
747 #define SIP_MEDIA_REMOVABLE 0x01
748 #define SIP_MEDIA_FIXED 0x02
751 const char *revision;
754 struct scsi_static_inquiry_pattern {
757 char vendor[SID_VENDOR_SIZE+1];
758 char product[SID_PRODUCT_SIZE+1];
759 char revision[SID_REVISION_SIZE+1];
762 struct scsi_sense_quirk_entry {
763 struct scsi_inquiry_pattern inq_pat;
766 struct sense_key_table_entry *sense_key_info;
767 struct asc_table_entry *asc_info;
770 struct sense_key_table_entry {
776 struct asc_table_entry {
783 struct op_table_entry {
789 struct scsi_op_quirk_entry {
790 struct scsi_inquiry_pattern inq_pat;
792 struct op_table_entry *op_table;
796 SSS_FLAG_NONE = 0x00,
797 SSS_FLAG_PRINT_COMMAND = 0x01
798 } scsi_sense_string_flags;
807 extern const char *scsi_sense_key_text[];
812 void scsi_sense_desc(int sense_key, int asc, int ascq,
813 struct scsi_inquiry_data *inq_data,
814 const char **sense_key_desc, const char **asc_desc);
815 scsi_sense_action scsi_error_action(struct ccb_scsiio* csio,
816 struct scsi_inquiry_data *inq_data,
817 u_int32_t sense_flags);
818 const char * scsi_status_string(struct ccb_scsiio *csio);
820 int scsi_command_string(struct ccb_scsiio *csio, struct sbuf *sb);
821 int scsi_sense_sbuf(struct ccb_scsiio *csio, struct sbuf *sb,
822 scsi_sense_string_flags flags);
823 char * scsi_sense_string(struct ccb_scsiio *csio,
824 char *str, int str_len);
825 void scsi_sense_print(struct ccb_scsiio *csio);
826 int scsi_interpret_sense(union ccb *ccb,
827 u_int32_t sense_flags,
828 u_int32_t *relsim_flags,
829 u_int32_t *reduction,
831 scsi_sense_action error_action);
833 int scsi_command_string(struct cam_device *device,
834 struct ccb_scsiio *csio, struct sbuf *sb);
835 int scsi_sense_sbuf(struct cam_device *device,
836 struct ccb_scsiio *csio, struct sbuf *sb,
837 scsi_sense_string_flags flags);
838 char * scsi_sense_string(struct cam_device *device,
839 struct ccb_scsiio *csio,
840 char *str, int str_len);
841 void scsi_sense_print(struct cam_device *device,
842 struct ccb_scsiio *csio, FILE *ofile);
843 int scsi_interpret_sense(struct cam_device *device,
845 u_int32_t sense_flags,
846 u_int32_t *relsim_flags,
847 u_int32_t *reduction,
849 scsi_sense_action error_action);
852 #define SF_RETRY_UA 0x01
853 #define SF_NO_PRINT 0x02
854 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
855 #define SF_PRINT_ALWAYS 0x08
858 const char * scsi_op_desc(u_int16_t opcode,
859 struct scsi_inquiry_data *inq_data);
860 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
863 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
865 u_int scsi_calc_syncsrate(u_int period_factor);
866 u_int scsi_calc_syncparam(u_int period);
868 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
869 void (*cbfcnp)(struct cam_periph *,
872 u_int8_t sense_len, u_int32_t timeout);
874 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
875 void (*cbfcnp)(struct cam_periph *,
877 void *data_ptr, u_int8_t dxfer_len,
878 u_int8_t tag_action, u_int8_t sense_len,
881 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
882 void (*cbfcnp)(struct cam_periph *, union ccb *),
883 u_int8_t tag_action, u_int8_t *inq_buf,
884 u_int32_t inq_len, int evpd, u_int8_t page_code,
885 u_int8_t sense_len, u_int32_t timeout);
887 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
888 void (*cbfcnp)(struct cam_periph *,
890 u_int8_t tag_action, int dbd,
891 u_int8_t page_code, u_int8_t page,
892 u_int8_t *param_buf, u_int32_t param_len,
893 u_int8_t sense_len, u_int32_t timeout);
894 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
895 void (*cbfcnp)(struct cam_periph *,
897 u_int8_t tag_action, int dbd,
898 u_int8_t page_code, u_int8_t page,
899 u_int8_t *param_buf, u_int32_t param_len,
900 int minimum_cmd_size, u_int8_t sense_len,
903 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
904 void (*cbfcnp)(struct cam_periph *,
906 u_int8_t tag_action, int scsi_page_fmt,
907 int save_pages, u_int8_t *param_buf,
908 u_int32_t param_len, u_int8_t sense_len,
911 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
912 void (*cbfcnp)(struct cam_periph *,
914 u_int8_t tag_action, int scsi_page_fmt,
915 int save_pages, u_int8_t *param_buf,
916 u_int32_t param_len, int minimum_cmd_size,
917 u_int8_t sense_len, u_int32_t timeout);
919 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
920 void (*cbfcnp)(struct cam_periph *,
921 union ccb *), u_int8_t tag_action,
922 struct scsi_read_capacity_data *rcap_buf,
923 u_int8_t sense_len, u_int32_t timeout);
924 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
925 void (*cbfcnp)(struct cam_periph *,
926 union ccb *), uint8_t tag_action,
927 uint64_t lba, int reladr, int pmi,
928 struct scsi_read_capacity_data_long
929 *rcap_buf, uint8_t sense_len,
932 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
933 void (*cbfcnp)(struct cam_periph *, union ccb *),
934 u_int8_t tag_action, u_int8_t action,
935 u_int8_t sense_len, u_int32_t timeout);
937 void scsi_synchronize_cache(struct ccb_scsiio *csio,
939 void (*cbfcnp)(struct cam_periph *,
940 union ccb *), u_int8_t tag_action,
941 u_int32_t begin_lba, u_int16_t lb_count,
942 u_int8_t sense_len, u_int32_t timeout);
944 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
945 void (*cbfcnp)(struct cam_periph *, union ccb *),
946 u_int8_t tag_action, int readop, u_int8_t byte2,
947 int minimum_cmd_size, u_int64_t lba,
948 u_int32_t block_count, u_int8_t *data_ptr,
949 u_int32_t dxfer_len, u_int8_t sense_len,
952 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
953 void (*cbfcnp)(struct cam_periph *, union ccb *),
954 u_int8_t tag_action, int start, int load_eject,
955 int immediate, u_int8_t sense_len, u_int32_t timeout);
957 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
958 int scsi_static_inquiry_match(caddr_t inqbuffer,
959 caddr_t table_entry);
961 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
962 int *error_code, int *sense_key,
963 int *asc, int *ascq);
964 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
965 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
966 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
967 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
968 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
969 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
970 static __inline int32_t scsi_3btol(u_int8_t *bytes);
971 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
972 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes);
973 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
974 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
977 scsi_extract_sense(struct scsi_sense_data *sense, int *error_code,
978 int *sense_key, int *asc, int *ascq)
980 *error_code = sense->error_code & SSD_ERRCODE;
981 *sense_key = sense->flags & SSD_KEY;
982 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
983 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
987 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
990 bytes[0] = (val >> 8) & 0xff;
991 bytes[1] = val & 0xff;
995 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
998 bytes[0] = (val >> 16) & 0xff;
999 bytes[1] = (val >> 8) & 0xff;
1000 bytes[2] = val & 0xff;
1003 static __inline void
1004 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
1007 bytes[0] = (val >> 24) & 0xff;
1008 bytes[1] = (val >> 16) & 0xff;
1009 bytes[2] = (val >> 8) & 0xff;
1010 bytes[3] = val & 0xff;
1013 static __inline void
1014 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
1016 bytes[0] = (val >> 56) & 0xff;
1017 bytes[1] = (val >> 48) & 0xff;
1018 bytes[2] = (val >> 40) & 0xff;
1019 bytes[3] = (val >> 32) & 0xff;
1020 bytes[4] = (val >> 24) & 0xff;
1021 bytes[5] = (val >> 16) & 0xff;
1022 bytes[6] = (val >> 8) & 0xff;
1023 bytes[7] = val & 0xff;
1026 static __inline u_int32_t
1027 scsi_2btoul(u_int8_t *bytes)
1031 rv = (bytes[0] << 8) |
1036 static __inline uint64_t
1037 scsi_8btou64(uint8_t *bytes)
1041 rv = (((uint64_t)bytes[0]) << 56) |
1042 (((uint64_t)bytes[1]) << 48) |
1043 (((uint64_t)bytes[2]) << 40) |
1044 (((uint64_t)bytes[3]) << 32) |
1045 (((uint64_t)bytes[4]) << 24) |
1046 (((uint64_t)bytes[5]) << 16) |
1047 (((uint64_t)bytes[6]) << 8) |
1052 static __inline u_int32_t
1053 scsi_3btoul(u_int8_t *bytes)
1057 rv = (bytes[0] << 16) |
1063 static __inline int32_t
1064 scsi_3btol(u_int8_t *bytes)
1066 u_int32_t rc = scsi_3btoul(bytes);
1068 if (rc & 0x00800000)
1071 return (int32_t) rc;
1074 static __inline u_int32_t
1075 scsi_4btoul(u_int8_t *bytes)
1079 rv = (bytes[0] << 24) |
1087 * Given the pointer to a returned mode sense buffer, return a pointer to
1088 * the start of the first mode page.
1090 static __inline void *
1091 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
1095 page_start = (void *)((u_int8_t *)&mode_header[1] +
1096 mode_header->blk_desc_len);
1101 static __inline void *
1102 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
1106 page_start = (void *)((u_int8_t *)&mode_header[1] +
1107 scsi_2btoul(mode_header->blk_desc_len));
1114 #endif /*_SCSI_SCSI_ALL_H*/