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.21 2002/10/08 17:12:44 ken Exp $
19 * Copyright (c) 2003 Adaptec Inc.
20 * All rights reserved.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
25 * 1. Redistributions of source code must retain the above copyright
26 * notice, this list of conditions, and the following disclaimer,
27 * without modification.
28 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
29 * substantially similar to the "NO WARRANTY" disclaimer below
30 * ("Disclaimer") and any redistribution must be conditioned upon
31 * including a substantially similar Disclaimer requirement for further
32 * binary redistribution.
33 * 3. Neither the names of the above-listed copyright holders nor the names
34 * of any contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
37 * Alternatively, this software may be distributed under the terms of the
38 * GNU General Public License ("GPL") version 2 as published by the Free
39 * Software Foundation.
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
51 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52 * POSSIBILITY OF SUCH DAMAGES.
61 * Linux Interrupt Support.
64 typedef void irqreturn_t
;
73 * Define dome bits that are in ALL (or a lot of) scsi commands
75 #define SCSI_CTL_LINK 0x01
76 #define SCSI_CTL_FLAG 0x02
77 #define SCSI_CTL_VENDOR 0xC0
78 #define SCSI_CMD_LUN 0xA0 /* these two should not be needed */
79 #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */
81 #define SCSI_MAX_CDBLEN 16 /*
82 * 16 byte commands are in the
85 /* 6byte CDBs special case 0 length to be 256 */
86 #define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len)
89 * This type defines actions to be taken when a particular sense code is
90 * received. Right now, these flags are only defined to take up 16 bits,
91 * but can be expanded in the future if necessary.
94 SS_NOP
= 0x000000, /* Do nothing */
95 SS_RETRY
= 0x010000, /* Retry the command */
96 SS_FAIL
= 0x020000, /* Bail out */
97 SS_START
= 0x030000, /* Send a Start Unit command to the device,
98 * then retry the original command.
100 SS_TUR
= 0x040000, /* Send a Test Unit Ready command to the
101 * device, then retry the original command.
103 SS_REQSENSE
= 0x050000, /* Send a RequestSense command to the
104 * device, then retry the original command.
106 SS_INQ_REFRESH
= 0x060000,
112 SSQ_DECREMENT_COUNT
= 0x0100, /* Decrement the retry count */
113 SSQ_MANY
= 0x0200, /* send lots of recovery commands */
114 SSQ_RANGE
= 0x0400, /*
115 * This table entry represents the
116 * end of a range of ASCQs that
117 * have identical error actions
120 SSQ_PRINT_SENSE
= 0x0800,
121 SSQ_DELAY
= 0x1000, /* Delay before retry. */
122 SSQ_DELAY_RANDOM
= 0x2000, /* Randomized delay before retry. */
123 SSQ_FALLBACK
= 0x4000, /* Do a speed fallback to recover */
125 } aic_sense_action_qualifier
;
127 /* Mask for error status values */
128 #define SS_ERRMASK 0xff
130 /* The default, retyable, error action */
131 #define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
133 /* The retyable, error action, with table specified error code */
134 #define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
136 /* Fatal error action, with table specified error code */
137 #define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE
145 struct scsi_request_sense
154 struct scsi_test_unit_ready
162 struct scsi_send_diag
168 #define SSD_SELFTEST 0x04
195 struct scsi_mode_sense_6
201 #define SMS_PAGE_CODE 0x3F
202 #define SMS_VENDOR_SPECIFIC_PAGE 0x00
203 #define SMS_DISCONNECT_RECONNECT_PAGE 0x02
204 #define SMS_PERIPHERAL_DEVICE_PAGE 0x09
205 #define SMS_CONTROL_MODE_PAGE 0x0A
206 #define SMS_ALL_PAGES_PAGE 0x3F
207 #define SMS_PAGE_CTRL_MASK 0xC0
208 #define SMS_PAGE_CTRL_CURRENT 0x00
209 #define SMS_PAGE_CTRL_CHANGEABLE 0x40
210 #define SMS_PAGE_CTRL_DEFAULT 0x80
211 #define SMS_PAGE_CTRL_SAVED 0xC0
217 struct scsi_mode_sense_10
220 uint8_t byte2
; /* same bits as small version */
221 uint8_t page
; /* same bits as small version */
227 struct scsi_mode_select_6
238 struct scsi_mode_select_10
241 uint8_t byte2
; /* same bits as small version */
248 * When sending a mode select to a tape drive, the medium type must be 0.
250 struct scsi_mode_hdr_6
254 uint8_t dev_specific
;
255 uint8_t block_descr_len
;
258 struct scsi_mode_hdr_10
262 uint8_t dev_specific
;
264 uint8_t block_descr_len
[2];
267 struct scsi_mode_block_descr
269 uint8_t density_code
;
270 uint8_t num_blocks
[3];
272 uint8_t block_len
[3];
275 struct scsi_log_sense
282 #define SLS_PAGE_CODE 0x3F
283 #define SLS_ALL_PAGES_PAGE 0x00
284 #define SLS_OVERRUN_PAGE 0x01
285 #define SLS_ERROR_WRITE_PAGE 0x02
286 #define SLS_ERROR_READ_PAGE 0x03
287 #define SLS_ERROR_READREVERSE_PAGE 0x04
288 #define SLS_ERROR_VERIFY_PAGE 0x05
289 #define SLS_ERROR_NONMEDIUM_PAGE 0x06
290 #define SLS_ERROR_LASTN_PAGE 0x07
291 #define SLS_PAGE_CTRL_MASK 0xC0
292 #define SLS_PAGE_CTRL_THRESHOLD 0x00
293 #define SLS_PAGE_CTRL_CUMULATIVE 0x40
294 #define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
295 #define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
302 struct scsi_log_select
309 /* SLS_PAGE_CTRL_MASK 0xC0 */
310 /* SLS_PAGE_CTRL_THRESHOLD 0x00 */
311 /* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
312 /* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
313 /* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
319 struct scsi_log_header
326 struct scsi_log_param_header
{
327 uint8_t param_code
[2];
328 uint8_t param_control
;
330 #define SLP_LBIN 0x02
331 #define SLP_TMC_MASK 0x0C
332 #define SLP_TMC_ALWAYS 0x00
333 #define SLP_TMC_EQUAL 0x04
334 #define SLP_TMC_NOTEQUAL 0x08
335 #define SLP_TMC_GREATER 0x0C
343 struct scsi_control_page
{
347 #define SCB_RLEC 0x01 /*Report Log Exception Cond*/
349 #define SCP_QUEUE_ALG_MASK 0xF0
350 #define SCP_QUEUE_ALG_RESTRICTED 0x00
351 #define SCP_QUEUE_ALG_UNRESTRICTED 0x10
352 #define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
353 #define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
355 #define SCP_EECA 0x80 /*Enable Extended CA*/
356 #define SCP_RAENP 0x04 /*Ready AEN Permission*/
357 #define SCP_UAAENP 0x02 /*UA AEN Permission*/
358 #define SCP_EAENP 0x01 /*Error AEN Permission*/
360 uint8_t aen_holdoff_period
[2];
389 #define PR_PREVENT 0x01
390 #define PR_ALLOW 0x00
392 struct scsi_sync_cache
396 uint8_t begin_lba
[4];
403 struct scsi_changedef
414 struct scsi_read_buffer
418 #define RWB_MODE 0x07
419 #define RWB_MODE_HDR_DATA 0x00
420 #define RWB_MODE_DATA 0x02
421 #define RWB_MODE_DOWNLOAD 0x04
422 #define RWB_MODE_DOWNLOAD_SAVE 0x05
429 struct scsi_write_buffer
443 /* only 5 bits are valid in the MSB address byte */
444 #define SRW_TOPADDR 0x1F
452 #define SRW10_RELADDR 0x01
453 #define SRW10_FUA 0x08
454 #define SRW10_DPO 0x10
465 #define SRW12_RELADDR 0x01
466 #define SRW12_FUA 0x08
467 #define SRW12_DPO 0x10
475 struct scsi_start_stop_unit
479 #define SSS_IMMED 0x01
482 #define SSS_START 0x01
483 #define SSS_LOEJ 0x02
487 #define SC_SCSI_1 0x01
488 #define SC_SCSI_2 0x03
494 #define TEST_UNIT_READY 0x00
495 #define REQUEST_SENSE 0x03
499 #define MODE_SELECT_6 0x15
500 #define MODE_SENSE_6 0x1a
501 #define START_STOP_UNIT 0x1b
502 #define START_STOP 0x1b
505 #define RECEIVE_DIAGNOSTIC 0x1c
506 #define SEND_DIAGNOSTIC 0x1d
507 #define PREVENT_ALLOW 0x1e
508 #define READ_CAPACITY 0x25
510 #define WRITE_10 0x2a
511 #define POSITION_TO_ELEMENT 0x2b
512 #define SYNCHRONIZE_CACHE 0x35
513 #define WRITE_BUFFER 0x3b
514 #define READ_BUFFER 0x3c
515 #define CHANGE_DEFINITION 0x40
516 #define LOG_SELECT 0x4c
517 #define LOG_SENSE 0x4d
519 #define MODE_SENSE_10 0x5A
521 #define MODE_SELECT_10 0x55
522 #define MOVE_MEDIUM 0xa5
524 #define WRITE_12 0xaa
525 #define READ_ELEMENT_STATUS 0xb8
531 #define T_DIRECT 0x00
532 #define T_SEQUENTIAL 0x01
533 #define T_PRINTER 0x02
534 #define T_PROCESSOR 0x03
537 #define T_SCANNER 0x06
538 #define T_OPTICAL 0x07
539 #define T_CHANGER 0x08
543 #define T_STORARRAY 0x0c
544 #define T_ENCLOSURE 0x0d
547 #define T_NODEVICE 0x1F
548 #define T_ANY 0xFF /* Used in Quirk table matches */
554 * This length is the initial inquiry length used by the probe code, as
555 * well as the legnth necessary for aic_print_inquiry() to function
556 * correctly. If either use requires a different length in the future,
557 * the two values should be de-coupled.
559 #define SHORT_INQUIRY_LENGTH 36
561 struct scsi_inquiry_data
564 #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
565 #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
566 #define SID_QUAL_LU_CONNECTED 0x00 /*
567 * The specified peripheral device
568 * type is currently connected to
569 * logical unit. If the target cannot
570 * determine whether or not a physical
571 * device is currently connected, it
572 * shall also use this peripheral
573 * qualifier when returning the INQUIRY
574 * data. This peripheral qualifier
575 * does not mean that the device is
576 * ready for access by the initiator.
578 #define SID_QUAL_LU_OFFLINE 0x01 /*
579 * The target is capable of supporting
580 * the specified peripheral device type
581 * on this logical unit; however, the
582 * physical device is not currently
583 * connected to this logical unit.
585 #define SID_QUAL_RSVD 0x02
586 #define SID_QUAL_BAD_LU 0x03 /*
587 * The target is not capable of
588 * supporting a physical device on
589 * this logical unit. For this
590 * peripheral qualifier the peripheral
591 * device type shall be set to 1Fh to
592 * provide compatibility with previous
593 * versions of SCSI. All other
594 * peripheral device type values are
595 * reserved for this peripheral
598 #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
600 #define SID_QUAL2 0x7F
601 #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
603 #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
605 #define SCSI_REV_CCS 1
607 #define SCSI_REV_SPC 3
608 #define SCSI_REV_SPC2 4
610 #define SID_ECMA 0x38
612 uint8_t response_format
;
613 #define SID_AENC 0x80
614 #define SID_TrmIOP 0x40
615 uint8_t additional_length
;
618 #define SID_SftRe 0x01
619 #define SID_CmdQue 0x02
620 #define SID_Linked 0x08
621 #define SID_Sync 0x10
622 #define SID_WBus16 0x20
623 #define SID_WBus32 0x40
624 #define SID_RelAdr 0x80
625 #define SID_VENDOR_SIZE 8
626 char vendor
[SID_VENDOR_SIZE
];
627 #define SID_PRODUCT_SIZE 16
628 char product
[SID_PRODUCT_SIZE
];
629 #define SID_REVISION_SIZE 4
630 char revision
[SID_REVISION_SIZE
];
632 * The following fields were taken from SCSI Primary Commands - 2
633 * (SPC-2) Revision 14, Dated 11 November 1999
635 #define SID_VENDOR_SPECIFIC_0_SIZE 20
636 uint8_t vendor_specific0
[SID_VENDOR_SPECIFIC_0_SIZE
];
638 * An extension of SCSI Parallel Specific Values
640 #define SID_SPI_IUS 0x01
641 #define SID_SPI_QAS 0x02
642 #define SID_SPI_CLOCK_ST 0x00
643 #define SID_SPI_CLOCK_DT 0x04
644 #define SID_SPI_CLOCK_DT_ST 0x0C
645 #define SID_SPI_MASK 0x0F
649 * Version Descriptors, stored 2 byte values.
660 uint8_t reserved3
[22];
662 #define SID_VENDOR_SPECIFIC_1_SIZE 160
663 uint8_t vendor_specific1
[SID_VENDOR_SPECIFIC_1_SIZE
];
666 struct scsi_vpd_unit_serial_number
670 #define SVPD_UNIT_SERIAL_NUMBER 0x80
672 uint8_t length
; /* serial number length */
673 #define SVPD_SERIAL_NUM_SIZE 251
674 uint8_t serial_num
[SVPD_SERIAL_NUM_SIZE
];
677 struct scsi_read_capacity
686 struct scsi_read_capacity_data
692 struct scsi_report_luns
701 struct scsi_report_luns_data
{
702 uint8_t length
[4]; /* length of LUN inventory, in bytes */
703 uint8_t reserved
[4]; /* unused */
705 * LUN inventory- we only support the type zero form for now.
711 #define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
712 #define RPL_LUNDATA_T0LUN 1 /* @ lundata[1] */
715 struct scsi_sense_data
718 #define SSD_ERRCODE 0x7F
719 #define SSD_CURRENT_ERROR 0x70
720 #define SSD_DEFERRED_ERROR 0x71
721 #define SSD_ERRCODE_VALID 0x80
725 #define SSD_KEY_NO_SENSE 0x00
726 #define SSD_KEY_RECOVERED_ERROR 0x01
727 #define SSD_KEY_NOT_READY 0x02
728 #define SSD_KEY_MEDIUM_ERROR 0x03
729 #define SSD_KEY_HARDWARE_ERROR 0x04
730 #define SSD_KEY_ILLEGAL_REQUEST 0x05
731 #define SSD_KEY_UNIT_ATTENTION 0x06
732 #define SSD_KEY_DATA_PROTECT 0x07
733 #define SSD_KEY_BLANK_CHECK 0x08
734 #define SSD_KEY_Vendor_Specific 0x09
735 #define SSD_KEY_COPY_ABORTED 0x0a
736 #define SSD_KEY_ABORTED_COMMAND 0x0b
737 #define SSD_KEY_EQUAL 0x0c
738 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
739 #define SSD_KEY_MISCOMPARE 0x0e
740 #define SSD_KEY_RESERVED 0x0f
743 #define SSD_FILEMARK 0x80
746 uint8_t cmd_spec_info
[4];
747 uint8_t add_sense_code
;
748 uint8_t add_sense_code_qual
;
750 uint8_t sense_key_spec
[3];
751 #define SSD_SCS_VALID 0x80
752 #define SSD_FIELDPTR_CMD 0x40
753 #define SSD_BITPTR_VALID 0x08
754 #define SSD_BITPTR_VALUE 0x07
755 #define SSD_MIN_SIZE 18
756 uint8_t extra_bytes
[14];
757 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
760 struct scsi_mode_header_6
762 uint8_t data_length
; /* Sense data length */
765 uint8_t blk_desc_len
;
768 struct scsi_mode_header_10
770 uint8_t data_length
[2];/* Sense data length */
774 uint8_t blk_desc_len
[2];
777 struct scsi_mode_page_header
783 struct scsi_mode_blk_desc
791 #define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
792 #define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
798 #define SCSI_STATUS_OK 0x00
799 #define SCSI_STATUS_CHECK_COND 0x02
800 #define SCSI_STATUS_COND_MET 0x04
801 #define SCSI_STATUS_BUSY 0x08
802 #define SCSI_STATUS_INTERMED 0x10
803 #define SCSI_STATUS_INTERMED_COND_MET 0x14
804 #define SCSI_STATUS_RESERV_CONFLICT 0x18
805 #define SCSI_STATUS_CMD_TERMINATED 0x22 /* Obsolete in SAM-2 */
806 #define SCSI_STATUS_QUEUE_FULL 0x28
807 #define SCSI_STATUS_ACA_ACTIVE 0x30
808 #define SCSI_STATUS_TASK_ABORTED 0x40
810 struct scsi_inquiry_pattern
{
813 #define SIP_MEDIA_REMOVABLE 0x01
814 #define SIP_MEDIA_FIXED 0x02
817 const char *revision
;
820 struct scsi_static_inquiry_pattern
{
823 char vendor
[SID_VENDOR_SIZE
+1];
824 char product
[SID_PRODUCT_SIZE
+1];
825 char revision
[SID_REVISION_SIZE
+1];
828 struct scsi_sense_quirk_entry
{
829 struct scsi_inquiry_pattern inq_pat
;
832 struct sense_key_table_entry
*sense_key_info
;
833 struct asc_table_entry
*asc_info
;
836 struct sense_key_table_entry
{
842 struct asc_table_entry
{
849 struct op_table_entry
{
855 struct scsi_op_quirk_entry
{
856 struct scsi_inquiry_pattern inq_pat
;
858 struct op_table_entry
*op_table
;
862 SSS_FLAG_NONE
= 0x00,
863 SSS_FLAG_PRINT_COMMAND
= 0x01
864 } scsi_sense_string_flags
;
866 extern const char *scsi_sense_key_text
[];
868 /************************* Large Disk Handling ********************************/
869 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
870 static __inline
int aic_sector_div(u_long capacity
, int heads
, int sectors
);
873 aic_sector_div(u_long capacity
, int heads
, int sectors
)
875 return (capacity
/ (heads
* sectors
));
878 static __inline
int aic_sector_div(sector_t capacity
, int heads
, int sectors
);
881 aic_sector_div(sector_t capacity
, int heads
, int sectors
)
883 /* ugly, ugly sector_div calling convention.. */
884 sector_div(capacity
, (heads
* sectors
));
885 return (int)capacity
;
889 /**************************** Module Library Hack *****************************/
891 * What we'd like to do is have a single "scsi library" module that both the
892 * aic7xxx and aic79xx drivers could load and depend on. A cursory examination
893 * of implementing module dependencies in Linux (handling the install and
894 * initrd cases) does not look promissing. For now, we just duplicate this
895 * code in both drivers using a simple symbol renaming scheme that hides this
896 * hack from the drivers.
898 #define AIC_LIB_ENTRY_CONCAT(x, prefix) prefix ## x
899 #define AIC_LIB_ENTRY_EXPAND(x, prefix) AIC_LIB_ENTRY_CONCAT(x, prefix)
900 #define AIC_LIB_ENTRY(x) AIC_LIB_ENTRY_EXPAND(x, AIC_LIB_PREFIX)
902 #define aic_sense_desc AIC_LIB_ENTRY(_sense_desc)
903 #define aic_sense_error_action AIC_LIB_ENTRY(_sense_error_action)
904 #define aic_error_action AIC_LIB_ENTRY(_error_action)
905 #define aic_op_desc AIC_LIB_ENTRY(_op_desc)
906 #define aic_cdb_string AIC_LIB_ENTRY(_cdb_string)
907 #define aic_print_inquiry AIC_LIB_ENTRY(_print_inquiry)
908 #define aic_calc_syncsrate AIC_LIB_ENTRY(_calc_syncrate)
909 #define aic_calc_syncparam AIC_LIB_ENTRY(_calc_syncparam)
910 #define aic_calc_speed AIC_LIB_ENTRY(_calc_speed)
911 #define aic_inquiry_match AIC_LIB_ENTRY(_inquiry_match)
912 #define aic_static_inquiry_match AIC_LIB_ENTRY(_static_inquiry_match)
913 #define aic_parse_brace_option AIC_LIB_ENTRY(_parse_brace_option)
915 /******************************************************************************/
917 void aic_sense_desc(int /*sense_key*/, int /*asc*/,
918 int /*ascq*/, struct scsi_inquiry_data
*,
919 const char** /*sense_key_desc*/,
920 const char** /*asc_desc*/);
921 aic_sense_action
aic_sense_error_action(struct scsi_sense_data
*,
922 struct scsi_inquiry_data
*,
923 uint32_t /*sense_flags*/);
924 uint32_t aic_error_action(struct scsi_cmnd
*,
925 struct scsi_inquiry_data
*,
928 #define SF_RETRY_UA 0x01
929 #define SF_NO_PRINT 0x02
930 #define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
931 #define SF_PRINT_ALWAYS 0x08
934 const char * aic_op_desc(uint16_t /*opcode*/, struct scsi_inquiry_data
*);
935 char * aic_cdb_string(uint8_t* /*cdb_ptr*/, char* /*cdb_string*/,
937 void aic_print_inquiry(struct scsi_inquiry_data
*);
939 u_int
aic_calc_syncsrate(u_int
/*period_factor*/);
940 u_int
aic_calc_syncparam(u_int
/*period*/);
941 u_int
aic_calc_speed(u_int width
, u_int period
, u_int offset
,
944 int aic_inquiry_match(caddr_t
/*inqbuffer*/,
945 caddr_t
/*table_entry*/);
946 int aic_static_inquiry_match(caddr_t
/*inqbuffer*/,
947 caddr_t
/*table_entry*/);
949 typedef void aic_option_callback_t(u_long
, int, int, int32_t);
950 char * aic_parse_brace_option(char *opt_name
, char *opt_arg
,
951 char *end
, int depth
,
952 aic_option_callback_t
*, u_long
);
954 static __inline
void scsi_extract_sense(struct scsi_sense_data
*sense
,
955 int *error_code
, int *sense_key
,
956 int *asc
, int *ascq
);
957 static __inline
void scsi_ulto2b(uint32_t val
, uint8_t *bytes
);
958 static __inline
void scsi_ulto3b(uint32_t val
, uint8_t *bytes
);
959 static __inline
void scsi_ulto4b(uint32_t val
, uint8_t *bytes
);
960 static __inline
uint32_t scsi_2btoul(uint8_t *bytes
);
961 static __inline
uint32_t scsi_3btoul(uint8_t *bytes
);
962 static __inline
int32_t scsi_3btol(uint8_t *bytes
);
963 static __inline
uint32_t scsi_4btoul(uint8_t *bytes
);
965 static __inline
void scsi_extract_sense(struct scsi_sense_data
*sense
,
966 int *error_code
, int *sense_key
,
969 *error_code
= sense
->error_code
& SSD_ERRCODE
;
970 *sense_key
= sense
->flags
& SSD_KEY
;
971 *asc
= (sense
->extra_len
>= 5) ? sense
->add_sense_code
: 0;
972 *ascq
= (sense
->extra_len
>= 6) ? sense
->add_sense_code_qual
: 0;
976 scsi_ulto2b(uint32_t val
, uint8_t *bytes
)
979 bytes
[0] = (val
>> 8) & 0xff;
980 bytes
[1] = val
& 0xff;
984 scsi_ulto3b(uint32_t val
, uint8_t *bytes
)
987 bytes
[0] = (val
>> 16) & 0xff;
988 bytes
[1] = (val
>> 8) & 0xff;
989 bytes
[2] = val
& 0xff;
993 scsi_ulto4b(uint32_t val
, uint8_t *bytes
)
996 bytes
[0] = (val
>> 24) & 0xff;
997 bytes
[1] = (val
>> 16) & 0xff;
998 bytes
[2] = (val
>> 8) & 0xff;
999 bytes
[3] = val
& 0xff;
1002 static __inline
uint32_t
1003 scsi_2btoul(uint8_t *bytes
)
1007 rv
= (bytes
[0] << 8) |
1012 static __inline
uint32_t
1013 scsi_3btoul(uint8_t *bytes
)
1017 rv
= (bytes
[0] << 16) |
1023 static __inline
int32_t
1024 scsi_3btol(uint8_t *bytes
)
1026 uint32_t rc
= scsi_3btoul(bytes
);
1028 if (rc
& 0x00800000)
1031 return (int32_t) rc
;
1034 static __inline
uint32_t
1035 scsi_4btoul(uint8_t *bytes
)
1039 rv
= (bytes
[0] << 24) |
1046 /* Macros for generating the elements of the PCI ID tables. */
1048 #define GETID(v, s) (unsigned)(((v) >> (s)) & 0xFFFF ?: PCI_ANY_ID)
1050 #define ID_C(x, c) \
1052 GETID(x,32), GETID(x,48), GETID(x,0), GETID(x,16), \
1053 (c) << 8, 0xFFFF00, 0 \
1057 ID_C(x, PCI_CLASS_STORAGE_SCSI), \
1058 ID_C(x, PCI_CLASS_STORAGE_RAID)
1060 #define IDIROC(x) ((x) | ~ID_ALL_IROC_MASK)
1062 /* Generate IDs for all 16 possibilites.
1063 * The argument has already masked out
1064 * the 4 least significant bits of the device id.
1065 * (e.g., mask: ID_9005_GENERIC_MASK).
1069 ID((x) | 0x0001000000000000ull), \
1070 ID((x) | 0x0002000000000000ull), \
1071 ID((x) | 0x0003000000000000ull), \
1072 ID((x) | 0x0004000000000000ull), \
1073 ID((x) | 0x0005000000000000ull), \
1074 ID((x) | 0x0006000000000000ull), \
1075 ID((x) | 0x0007000000000000ull), \
1076 ID((x) | 0x0008000000000000ull), \
1077 ID((x) | 0x0009000000000000ull), \
1078 ID((x) | 0x000A000000000000ull), \
1079 ID((x) | 0x000B000000000000ull), \
1080 ID((x) | 0x000C000000000000ull), \
1081 ID((x) | 0x000D000000000000ull), \
1082 ID((x) | 0x000E000000000000ull), \
1083 ID((x) | 0x000F000000000000ull)
1085 #endif /*_AICLIB_H */