0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 #ifndef _AICLIB_H
0058 #define _AICLIB_H
0059
0060 struct scsi_sense
0061 {
0062 uint8_t opcode;
0063 uint8_t byte2;
0064 uint8_t unused[2];
0065 uint8_t length;
0066 uint8_t control;
0067 };
0068
0069 #define SCSI_REV_0 0
0070 #define SCSI_REV_CCS 1
0071 #define SCSI_REV_2 2
0072 #define SCSI_REV_SPC 3
0073 #define SCSI_REV_SPC2 4
0074
0075 struct scsi_sense_data
0076 {
0077 uint8_t error_code;
0078 #define SSD_ERRCODE 0x7F
0079 #define SSD_CURRENT_ERROR 0x70
0080 #define SSD_DEFERRED_ERROR 0x71
0081 #define SSD_ERRCODE_VALID 0x80
0082 uint8_t segment;
0083 uint8_t flags;
0084 #define SSD_KEY 0x0F
0085 #define SSD_KEY_NO_SENSE 0x00
0086 #define SSD_KEY_RECOVERED_ERROR 0x01
0087 #define SSD_KEY_NOT_READY 0x02
0088 #define SSD_KEY_MEDIUM_ERROR 0x03
0089 #define SSD_KEY_HARDWARE_ERROR 0x04
0090 #define SSD_KEY_ILLEGAL_REQUEST 0x05
0091 #define SSD_KEY_UNIT_ATTENTION 0x06
0092 #define SSD_KEY_DATA_PROTECT 0x07
0093 #define SSD_KEY_BLANK_CHECK 0x08
0094 #define SSD_KEY_Vendor_Specific 0x09
0095 #define SSD_KEY_COPY_ABORTED 0x0a
0096 #define SSD_KEY_ABORTED_COMMAND 0x0b
0097 #define SSD_KEY_EQUAL 0x0c
0098 #define SSD_KEY_VOLUME_OVERFLOW 0x0d
0099 #define SSD_KEY_MISCOMPARE 0x0e
0100 #define SSD_KEY_RESERVED 0x0f
0101 #define SSD_ILI 0x20
0102 #define SSD_EOM 0x40
0103 #define SSD_FILEMARK 0x80
0104 uint8_t info[4];
0105 uint8_t extra_len;
0106 uint8_t cmd_spec_info[4];
0107 uint8_t add_sense_code;
0108 uint8_t add_sense_code_qual;
0109 uint8_t fru;
0110 uint8_t sense_key_spec[3];
0111 #define SSD_SCS_VALID 0x80
0112 #define SSD_FIELDPTR_CMD 0x40
0113 #define SSD_BITPTR_VALID 0x08
0114 #define SSD_BITPTR_VALUE 0x07
0115 #define SSD_MIN_SIZE 18
0116 uint8_t extra_bytes[14];
0117 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
0118 };
0119
0120
0121 static inline int
0122 aic_sector_div(sector_t capacity, int heads, int sectors)
0123 {
0124
0125 sector_div(capacity, (heads * sectors));
0126 return (int)capacity;
0127 }
0128
0129 static inline uint32_t
0130 scsi_4btoul(uint8_t *bytes)
0131 {
0132 uint32_t rv;
0133
0134 rv = (bytes[0] << 24) |
0135 (bytes[1] << 16) |
0136 (bytes[2] << 8) |
0137 bytes[3];
0138 return (rv);
0139 }
0140
0141
0142
0143 #define GETID(v, s) (unsigned)(((v) >> (s)) & 0xFFFF ?: PCI_ANY_ID)
0144
0145 #define ID_C(x, c) \
0146 { \
0147 GETID(x,32), GETID(x,48), GETID(x,0), GETID(x,16), \
0148 (c) << 8, 0xFFFF00, 0 \
0149 }
0150
0151 #define ID2C(x) \
0152 ID_C(x, PCI_CLASS_STORAGE_SCSI), \
0153 ID_C(x, PCI_CLASS_STORAGE_RAID)
0154
0155 #define IDIROC(x) ((x) | ~ID_ALL_IROC_MASK)
0156
0157
0158
0159
0160
0161
0162 #define ID16(x) \
0163 ID(x), \
0164 ID((x) | 0x0001000000000000ull), \
0165 ID((x) | 0x0002000000000000ull), \
0166 ID((x) | 0x0003000000000000ull), \
0167 ID((x) | 0x0004000000000000ull), \
0168 ID((x) | 0x0005000000000000ull), \
0169 ID((x) | 0x0006000000000000ull), \
0170 ID((x) | 0x0007000000000000ull), \
0171 ID((x) | 0x0008000000000000ull), \
0172 ID((x) | 0x0009000000000000ull), \
0173 ID((x) | 0x000A000000000000ull), \
0174 ID((x) | 0x000B000000000000ull), \
0175 ID((x) | 0x000C000000000000ull), \
0176 ID((x) | 0x000D000000000000ull), \
0177 ID((x) | 0x000E000000000000ull), \
0178 ID((x) | 0x000F000000000000ull)
0179
0180 #endif