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.7 2007/05/16 20:59:38 dillon 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_MANUAL = 0x050000, /*
102 * This error must be handled manually,
103 * i.e. the code must look at the asc and
104 * ascq values and determine the proper
107 SS_TURSTART = 0x060000, /*
108 * Send a Test Unit Ready command to the
109 * device, and if that fails, send a start
117 SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */
118 SSQ_MANY = 0x0200, /* send lots of recovery commands */
119 SSQ_RANGE = 0x0400, /*
120 * Yes, this is a hack. Basically,
121 * if this flag is set then it
122 * represents an ascq range. The
123 * "correct" way to implement the
124 * ranges might be to add a special
125 * field to the sense code table,
126 * but that would take up a lot of
127 * additional space. This solution
128 * isn't as elegant, but is more
131 SSQ_PRINT_SENSE = 0x0800,
133 } scsi_sense_action_qualifier;
135 /* Mask for error status values */
136 #define SS_ERRMASK 0xff
138 /* The default error action */
139 #define SS_DEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
141 /* Default error action, without an error return value */
142 #define SS_NEDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
144 /* Default error action, without sense printing or an error return value */
145 #define SS_NEPDEF SS_RETRY|SSQ_DECREMENT_COUNT
153 struct scsi_request_sense
162 struct scsi_test_unit_ready
170 struct scsi_send_diag
176 #define SSD_SELFTEST 0x04
179 u_int8_t paramlen[2];
203 struct scsi_mode_sense_6
209 #define SMS_PAGE_CODE 0x3F
210 #define SMS_VENDOR_SPECIFIC_PAGE 0x00
211 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02
212 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
213 #define SMS_CONTROL_MODE_PAGE 0x0A
214 #define SMS_ALL_PAGES_PAGE 0x3F
215 #define SMS_PAGE_CTRL_MASK 0xC0
216 #define SMS_PAGE_CTRL_CURRENT 0x00
217 #define SMS_PAGE_CTRL_CHANGEABLE 0x40
218 #define SMS_PAGE_CTRL_DEFAULT 0x80
219 #define SMS_PAGE_CTRL_SAVED 0xC0
225 struct scsi_mode_sense_10
228 u_int8_t byte2; /* same bits as small version */
229 u_int8_t page; /* same bits as small version */
235 struct scsi_mode_select_6
246 struct scsi_mode_select_10
249 u_int8_t byte2; /* same bits as small version */
256 * When sending a mode select to a tape drive, the medium type must be 0.
258 struct scsi_mode_hdr_6
261 u_int8_t medium_type;
262 u_int8_t dev_specific;
263 u_int8_t block_descr_len;
266 struct scsi_mode_hdr_10
269 u_int8_t medium_type;
270 u_int8_t dev_specific;
271 u_int8_t reserved[2];
272 u_int8_t block_descr_len[2];
275 struct scsi_mode_block_descr
277 u_int8_t density_code;
278 u_int8_t num_blocks[3];
280 u_int8_t block_len[3];
283 struct scsi_control_page {
285 u_int8_t page_length;
287 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
288 u_int8_t queue_flags;
289 #define SCP_QUEUE_ALG_MASK 0xF0
290 #define SCP_QUEUE_ALG_RESTRICTED 0x00
291 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
292 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
293 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
294 u_int8_t eca_and_aen;
295 #define SCP_EECA 0x80 /*Enable Extended CA*/
296 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
297 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
298 #define SCP_EAENP 0x01 /*Error AEN Permission*/
300 u_int8_t aen_holdoff_period[2];
329 #define PR_PREVENT 0x01
330 #define PR_ALLOW 0x00
332 struct scsi_sync_cache
336 u_int8_t begin_lba[4];
338 u_int8_t lb_count[2];
343 struct scsi_changedef
354 struct scsi_read_buffer
358 #define RWB_MODE 0x07
359 #define RWB_MODE_HDR_DATA 0x00
360 #define RWB_MODE_DATA 0x02
361 #define RWB_MODE_DOWNLOAD 0x04
362 #define RWB_MODE_DOWNLOAD_SAVE 0x05
369 struct scsi_write_buffer
383 /* only 5 bits are valid in the MSB address byte */
384 #define SRW_TOPADDR 0x1F
392 #define SRW10_RELADDR 0x01
393 /* EBP defined for WRITE(10) only */
394 #define SRW10_EBP 0x04
395 #define SRW10_FUA 0x08
396 #define SRW10_DPO 0x10
407 #define SRW12_RELADDR 0x01
408 #define SRW12_FUA 0x08
409 #define SRW12_DPO 0x10
420 #define SRW16_RELADDR 0x01
421 #define SRW16_FUA 0x08
422 #define SRW16_DPO 0x10
431 struct scsi_start_stop_unit
435 #define SSS_IMMED 0x01
436 u_int8_t reserved[2];
438 #define SSS_START 0x01
439 #define SSS_LOEJ 0x02
443 #define SC_SCSI_1 0x01
444 #define SC_SCSI_2 0x03
450 #define TEST_UNIT_READY 0x00
451 #define REQUEST_SENSE 0x03
455 #define MODE_SELECT_6 0x15
456 #define MODE_SENSE_6 0x1a
457 #define START_STOP_UNIT 0x1b
458 #define START_STOP 0x1b
461 #define RECEIVE_DIAGNOSTIC 0x1c
462 #define SEND_DIAGNOSTIC 0x1d
463 #define PREVENT_ALLOW 0x1e
464 #define READ_CAPACITY 0x25
466 #define WRITE_10 0x2a
467 #define POSITION_TO_ELEMENT 0x2b
468 #define SYNCHRONIZE_CACHE 0x35
469 #define WRITE_BUFFER 0x3b
470 #define READ_BUFFER 0x3c
471 #define CHANGE_DEFINITION 0x40
472 #define MODE_SELECT_10 0x55
473 #define MODE_SENSE_10 0x5A
475 #define WRITE_16 0x8a
476 #define SERVICE_ACTION_IN 0x9e
477 #define MOVE_MEDIUM 0xa5
479 #define WRITE_12 0xaa
480 #define READ_ELEMENT_STATUS 0xb8
485 #define T_DIRECT 0x00
486 #define T_SEQUENTIAL 0x01
487 #define T_PRINTER 0x02
488 #define T_PROCESSOR 0x03
491 #define T_SCANNER 0x06
492 #define T_OPTICAL 0x07
493 #define T_CHANGER 0x08
497 #define T_STORARRAY 0x0c
498 #define T_ENCLOSURE 0x0d
501 #define T_NODEVICE 0x1F
502 #define T_ANY 0xFF /* Used in Quirk table matches */
508 * This length is the initial inquiry length used by the probe code, as
509 * well as the legnth necessary for scsi_print_inquiry() to function
510 * correctly. If either use requires a different length in the future,
511 * the two values should be de-coupled.
513 #define SHORT_INQUIRY_LENGTH 36
515 struct scsi_inquiry_data
518 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
519 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
520 #define SID_QUAL_LU_CONNECTED 0x00 /* The specified peripheral device
521 * type is currently connected to
522 * logical unit. If the target cannot
523 * determine whether or not a physical
524 * device is currently connected, it
525 * shall also use this peripheral
526 * qualifier when returning the INQUIRY
527 * data. This peripheral qualifier
528 * does not mean that the device is
529 * ready for access by the initiator.
531 #define SID_QUAL_LU_OFFLINE 0x01 /* The target is capable of supporting
532 * the specified peripheral device type
533 * on this logical unit; however, the
534 * physical device is not currently
535 * connected to this logical unit.
537 #define SID_QUAL_RSVD 0x02
538 #define SID_QUAL_BAD_LU 0x03 /* The target is not capable of
539 * supporting a physical device on
540 * this logical unit. For this
541 * peripheral qualifier the peripheral
542 * device type shall be set to 1Fh to
543 * provide compatibility with previous
544 * versions of SCSI. All other
545 * peripheral device type values are
546 * reserved for this peripheral
549 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
551 #define SID_QUAL2 0x7F
552 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
554 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
556 #define SCSI_REV_CCS 1
559 #define SCSI_REV_SPC2 4
561 #define SID_ECMA 0x38
563 u_int8_t response_format;
564 #define SID_AENC 0x80
565 #define SID_TrmIOP 0x40
566 u_int8_t additional_length;
567 u_int8_t reserved[2];
569 #define SID_SftRe 0x01
570 #define SID_CmdQue 0x02
571 #define SID_Linked 0x08
572 #define SID_Sync 0x10
573 #define SID_WBus16 0x20
574 #define SID_WBus32 0x40
575 #define SID_RelAdr 0x80
576 #define SID_VENDOR_SIZE 8
577 char vendor[SID_VENDOR_SIZE];
578 #define SID_PRODUCT_SIZE 16
579 char product[SID_PRODUCT_SIZE];
580 #define SID_REVISION_SIZE 4
581 char revision[SID_REVISION_SIZE];
583 * The following fields were taken from SCSI Primary Commands - 2
584 * (SPC-2) Revision 14, Dated 11 November 1999
586 #define SID_VENDOR_SPECIFIC_0_SIZE 20
587 u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
589 * An extension of SCSI Parallel Specific Values
591 #define SID_SPI_IUS 0x01
592 #define SID_SPI_QAS 0x02
593 #define SID_SPI_CLOCK_ST 0x00
594 #define SID_SPI_CLOCK_DT 0x04
595 #define SID_SPI_CLOCK_DT_ST 0x0C
599 * Version Descriptors, stored 2 byte values.
601 u_int8_t version1[2];
602 u_int8_t version2[2];
603 u_int8_t version3[2];
604 u_int8_t version4[2];
605 u_int8_t version5[2];
606 u_int8_t version6[2];
607 u_int8_t version7[2];
608 u_int8_t version8[2];
610 u_int8_t reserved3[22];
612 #define SID_VENDOR_SPECIFIC_1_SIZE 160
613 u_int8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
616 struct scsi_vpd_unit_serial_number
620 #define SVPD_UNIT_SERIAL_NUMBER 0x80
622 u_int8_t length; /* serial number length */
623 #define SVPD_SERIAL_NUM_SIZE 251
624 u_int8_t serial_num[SVPD_SERIAL_NUM_SIZE];
627 struct scsi_read_capacity
636 struct scsi_read_capacity_16
639 #define SRC16_SERVICE_ACTION 0x10
640 uint8_t service_action;
642 uint8_t alloc_len[4];
643 #define SRC16_PMI 0x01
644 #define SRC16_RELADR 0x02
649 struct scsi_read_capacity_data
655 struct scsi_read_capacity_data_long
661 struct scsi_sense_data
664 #define SSD_ERRCODE 0x7F
665 #define SSD_CURRENT_ERROR 0x70
666 #define SSD_DEFERRED_ERROR 0x71
667 #define SSD_ERRCODE_VALID 0x80
671 #define SSD_KEY_NO_SENSE 0x00
672 #define SSD_KEY_RECOVERED_ERROR 0x01
673 #define SSD_KEY_NOT_READY 0x02
674 #define SSD_KEY_MEDIUM_ERROR 0x03
675 #define SSD_KEY_HARDWARE_ERROR 0x04
676 #define SSD_KEY_ILLEGAL_REQUEST 0x05
677 #define SSD_KEY_UNIT_ATTENTION 0x06
678 #define SSD_KEY_DATA_PROTECT 0x07
679 #define SSD_KEY_BLANK_CHECK 0x08
680 #define SSD_KEY_Vendor_Specific 0x09
681 #define SSD_KEY_COPY_ABORTED 0x0a
682 #define SSD_KEY_ABORTED_COMMAND 0x0b
683 #define SSD_KEY_EQUAL 0x0c
684 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
685 #define SSD_KEY_MISCOMPARE 0x0e
686 #define SSD_KEY_RESERVED 0x0f
689 #define SSD_FILEMARK 0x80
692 u_int8_t cmd_spec_info[4];
693 u_int8_t add_sense_code;
694 u_int8_t add_sense_code_qual;
696 u_int8_t sense_key_spec[3];
697 #define SSD_SCS_VALID 0x80
698 #define SSD_FIELDPTR_CMD 0x40
699 #define SSD_BITPTR_VALID 0x08
700 #define SSD_BITPTR_VALUE 0x07
701 #define SSD_MIN_SIZE 18
702 u_int8_t extra_bytes[14];
703 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
706 struct scsi_mode_header_6
708 u_int8_t data_length; /* Sense data length */
709 u_int8_t medium_type;
711 u_int8_t blk_desc_len;
714 struct scsi_mode_header_10
716 u_int8_t data_length[2];/* Sense data length */
717 u_int8_t medium_type;
720 u_int8_t blk_desc_len[2];
723 struct scsi_mode_page_header
726 u_int8_t page_length;
729 struct scsi_mode_blk_desc
737 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
738 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
742 #define SCSI_STATUS_OK 0x00
743 #define SCSI_STATUS_CHECK_COND 0x02
744 #define SCSI_STATUS_COND_MET 0x04
745 #define SCSI_STATUS_BUSY 0x08
746 #define SCSI_STATUS_INTERMED 0x10
747 #define SCSI_STATUS_INTERMED_COND_MET 0x14
748 #define SCSI_STATUS_RESERV_CONFLICT 0x18
749 #define SCSI_STATUS_CMD_TERMINATED 0x22
750 #define SCSI_STATUS_QUEUE_FULL 0x28
752 struct scsi_inquiry_pattern {
755 #define SIP_MEDIA_REMOVABLE 0x01
756 #define SIP_MEDIA_FIXED 0x02
759 const char *revision;
762 struct scsi_static_inquiry_pattern {
765 char vendor[SID_VENDOR_SIZE+1];
766 char product[SID_PRODUCT_SIZE+1];
767 char revision[SID_REVISION_SIZE+1];
770 struct scsi_sense_quirk_entry {
771 struct scsi_inquiry_pattern inq_pat;
773 struct asc_table_entry *asc_info;
776 struct asc_table_entry {
780 #if !defined(SCSI_NO_SENSE_STRINGS)
785 struct op_table_entry {
791 struct scsi_op_quirk_entry {
792 struct scsi_inquiry_pattern inq_pat;
794 struct op_table_entry *op_table;
805 extern const char *scsi_sense_key_text[];
808 const char * scsi_sense_desc(int asc, int ascq,
809 struct scsi_inquiry_data *inq_data);
810 scsi_sense_action scsi_error_action(int asc, int ascq,
811 struct scsi_inquiry_data *inq_data);
814 void scsi_sense_print(struct ccb_scsiio *csio);
815 int scsi_interpret_sense(union ccb *ccb,
816 u_int32_t sense_flags,
817 u_int32_t *relsim_flags,
818 u_int32_t *reduction,
820 scsi_sense_action error_action);
823 char * scsi_sense_string(struct cam_device *device,
824 struct ccb_scsiio *csio,
825 char *str, int str_len);
826 void scsi_sense_print(struct cam_device *device,
827 struct ccb_scsiio *csio, FILE *ofile);
828 int scsi_interpret_sense(struct cam_device *device,
830 u_int32_t sense_flags,
831 u_int32_t *relsim_flags,
832 u_int32_t *reduction,
834 scsi_sense_action error_action);
837 #define SF_RETRY_UA 0x01
838 #define SF_NO_PRINT 0x02
839 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
840 #define SF_PRINT_ALWAYS 0x08
841 #define SF_RETRY_SELTO 0x10 /* Retry selection timeouts */
844 const char * scsi_op_desc(u_int16_t opcode,
845 struct scsi_inquiry_data *inq_data);
846 char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string,
849 void scsi_print_inquiry(struct scsi_inquiry_data *inq_data);
851 u_int scsi_calc_syncsrate(u_int period_factor);
852 u_int scsi_calc_syncparam(u_int period);
854 void scsi_test_unit_ready(struct ccb_scsiio *csio, u_int32_t retries,
855 void (*cbfcnp)(struct cam_periph *,
858 u_int8_t sense_len, u_int32_t timeout);
860 void scsi_request_sense(struct ccb_scsiio *csio, u_int32_t retries,
861 void (*cbfcnp)(struct cam_periph *,
863 void *data_ptr, u_int8_t dxfer_len,
864 u_int8_t tag_action, u_int8_t sense_len,
867 void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries,
868 void (*cbfcnp)(struct cam_periph *, union ccb *),
869 u_int8_t tag_action, u_int8_t *inq_buf,
870 u_int32_t inq_len, int evpd, u_int8_t page_code,
871 u_int8_t sense_len, u_int32_t timeout);
873 void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries,
874 void (*cbfcnp)(struct cam_periph *,
876 u_int8_t tag_action, int dbd,
877 u_int8_t page_code, u_int8_t page,
878 u_int8_t *param_buf, u_int32_t param_len,
879 u_int8_t sense_len, u_int32_t timeout);
880 void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries,
881 void (*cbfcnp)(struct cam_periph *,
883 u_int8_t tag_action, int dbd,
884 u_int8_t page_code, u_int8_t page,
885 u_int8_t *param_buf, u_int32_t param_len,
886 int minimum_cmd_size, u_int8_t sense_len,
889 void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries,
890 void (*cbfcnp)(struct cam_periph *,
892 u_int8_t tag_action, int scsi_page_fmt,
893 int save_pages, u_int8_t *param_buf,
894 u_int32_t param_len, u_int8_t sense_len,
897 void scsi_mode_select_len(struct ccb_scsiio *csio, u_int32_t retries,
898 void (*cbfcnp)(struct cam_periph *,
900 u_int8_t tag_action, int scsi_page_fmt,
901 int save_pages, u_int8_t *param_buf,
902 u_int32_t param_len, int minimum_cmd_size,
903 u_int8_t sense_len, u_int32_t timeout);
905 void scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
906 void (*cbfcnp)(struct cam_periph *,
907 union ccb *), u_int8_t tag_action,
908 struct scsi_read_capacity_data *rcap_buf,
909 u_int8_t sense_len, u_int32_t timeout);
910 void scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
911 void (*cbfcnp)(struct cam_periph *,
912 union ccb *), uint8_t tag_action,
913 uint64_t lba, int reladr, int pmi,
914 struct scsi_read_capacity_data_long
915 *rcap_buf, uint8_t sense_len,
918 void scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
919 void (*cbfcnp)(struct cam_periph *, union ccb *),
920 u_int8_t tag_action, u_int8_t action,
921 u_int8_t sense_len, u_int32_t timeout);
923 void scsi_synchronize_cache(struct ccb_scsiio *csio,
925 void (*cbfcnp)(struct cam_periph *,
926 union ccb *), u_int8_t tag_action,
927 u_int32_t begin_lba, u_int16_t lb_count,
928 u_int8_t sense_len, u_int32_t timeout);
930 void scsi_read_write(struct ccb_scsiio *csio, u_int32_t retries,
931 void (*cbfcnp)(struct cam_periph *, union ccb *),
932 u_int8_t tag_action, int readop, u_int8_t byte2,
933 int minimum_cmd_size, u_int64_t lba,
934 u_int32_t block_count, u_int8_t *data_ptr,
935 u_int32_t dxfer_len, u_int8_t sense_len,
938 void scsi_start_stop(struct ccb_scsiio *csio, u_int32_t retries,
939 void (*cbfcnp)(struct cam_periph *, union ccb *),
940 u_int8_t tag_action, int start, int load_eject,
941 int immediate, u_int8_t sense_len, u_int32_t timeout);
943 int scsi_inquiry_match(caddr_t inqbuffer, caddr_t table_entry);
944 int scsi_static_inquiry_match(caddr_t inqbuffer,
945 caddr_t table_entry);
947 static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
948 int *error_code, int *sense_key,
949 int *asc, int *ascq);
950 static __inline void scsi_ulto2b(u_int32_t val, u_int8_t *bytes);
951 static __inline void scsi_ulto3b(u_int32_t val, u_int8_t *bytes);
952 static __inline void scsi_ulto4b(u_int32_t val, u_int8_t *bytes);
953 static __inline void scsi_u64to8b(u_int64_t val, u_int8_t *bytes);
954 static __inline u_int32_t scsi_2btoul(u_int8_t *bytes);
955 static __inline u_int32_t scsi_3btoul(u_int8_t *bytes);
956 static __inline int32_t scsi_3btol(u_int8_t *bytes);
957 static __inline u_int32_t scsi_4btoul(u_int8_t *bytes);
958 static __inline u_int64_t scsi_8btou64(u_int8_t *bytes);
959 static __inline void *find_mode_page_6(struct scsi_mode_header_6 *mode_header);
960 static __inline void *find_mode_page_10(struct scsi_mode_header_10 *mode_header);
963 scsi_extract_sense(struct scsi_sense_data *sense, int *error_code,
964 int *sense_key, int *asc, int *ascq)
966 *error_code = sense->error_code & SSD_ERRCODE;
967 *sense_key = sense->flags & SSD_KEY;
968 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
969 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
973 scsi_ulto2b(u_int32_t val, u_int8_t *bytes)
976 bytes[0] = (val >> 8) & 0xff;
977 bytes[1] = val & 0xff;
981 scsi_ulto3b(u_int32_t val, u_int8_t *bytes)
984 bytes[0] = (val >> 16) & 0xff;
985 bytes[1] = (val >> 8) & 0xff;
986 bytes[2] = val & 0xff;
990 scsi_ulto4b(u_int32_t val, u_int8_t *bytes)
993 bytes[0] = (val >> 24) & 0xff;
994 bytes[1] = (val >> 16) & 0xff;
995 bytes[2] = (val >> 8) & 0xff;
996 bytes[3] = val & 0xff;
1000 scsi_u64to8b(u_int64_t val, u_int8_t *bytes)
1002 bytes[0] = (val >> 56) & 0xff;
1003 bytes[1] = (val >> 48) & 0xff;
1004 bytes[2] = (val >> 40) & 0xff;
1005 bytes[3] = (val >> 32) & 0xff;
1006 bytes[4] = (val >> 24) & 0xff;
1007 bytes[5] = (val >> 16) & 0xff;
1008 bytes[6] = (val >> 8) & 0xff;
1009 bytes[7] = val & 0xff;
1012 static __inline u_int32_t
1013 scsi_2btoul(u_int8_t *bytes)
1017 rv = (bytes[0] << 8) |
1022 static __inline uint64_t
1023 scsi_8btou64(uint8_t *bytes)
1027 rv = (((uint64_t)bytes[0]) << 56) |
1028 (((uint64_t)bytes[1]) << 48) |
1029 (((uint64_t)bytes[2]) << 40) |
1030 (((uint64_t)bytes[3]) << 32) |
1031 (((uint64_t)bytes[4]) << 24) |
1032 (((uint64_t)bytes[5]) << 16) |
1033 (((uint64_t)bytes[6]) << 8) |
1038 static __inline u_int32_t
1039 scsi_3btoul(u_int8_t *bytes)
1043 rv = (bytes[0] << 16) |
1049 static __inline int32_t
1050 scsi_3btol(u_int8_t *bytes)
1052 u_int32_t rc = scsi_3btoul(bytes);
1054 if (rc & 0x00800000)
1057 return (int32_t) rc;
1060 static __inline u_int32_t
1061 scsi_4btoul(u_int8_t *bytes)
1065 rv = (bytes[0] << 24) |
1073 * Given the pointer to a returned mode sense buffer, return a pointer to
1074 * the start of the first mode page.
1076 static __inline void *
1077 find_mode_page_6(struct scsi_mode_header_6 *mode_header)
1081 page_start = (void *)((u_int8_t *)&mode_header[1] +
1082 mode_header->blk_desc_len);
1087 static __inline void *
1088 find_mode_page_10(struct scsi_mode_header_10 *mode_header)
1092 page_start = (void *)((u_int8_t *)&mode_header[1] +
1093 scsi_2btoul(mode_header->blk_desc_len));
1100 #endif /*_SCSI_SCSI_ALL_H*/