1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57#ifndef _AICLIB_H
58#define _AICLIB_H
59
60struct scsi_sense
61{
62 uint8_t opcode;
63 uint8_t byte2;
64 uint8_t unused[2];
65 uint8_t length;
66 uint8_t control;
67};
68
69#define SCSI_REV_0 0
70#define SCSI_REV_CCS 1
71#define SCSI_REV_2 2
72#define SCSI_REV_SPC 3
73#define SCSI_REV_SPC2 4
74
75struct scsi_sense_data
76{
77 uint8_t error_code;
78#define SSD_ERRCODE 0x7F
79#define SSD_CURRENT_ERROR 0x70
80#define SSD_DEFERRED_ERROR 0x71
81#define SSD_ERRCODE_VALID 0x80
82 uint8_t segment;
83 uint8_t flags;
84#define SSD_KEY 0x0F
85#define SSD_KEY_NO_SENSE 0x00
86#define SSD_KEY_RECOVERED_ERROR 0x01
87#define SSD_KEY_NOT_READY 0x02
88#define SSD_KEY_MEDIUM_ERROR 0x03
89#define SSD_KEY_HARDWARE_ERROR 0x04
90#define SSD_KEY_ILLEGAL_REQUEST 0x05
91#define SSD_KEY_UNIT_ATTENTION 0x06
92#define SSD_KEY_DATA_PROTECT 0x07
93#define SSD_KEY_BLANK_CHECK 0x08
94#define SSD_KEY_Vendor_Specific 0x09
95#define SSD_KEY_COPY_ABORTED 0x0a
96#define SSD_KEY_ABORTED_COMMAND 0x0b
97#define SSD_KEY_EQUAL 0x0c
98#define SSD_KEY_VOLUME_OVERFLOW 0x0d
99#define SSD_KEY_MISCOMPARE 0x0e
100#define SSD_KEY_RESERVED 0x0f
101#define SSD_ILI 0x20
102#define SSD_EOM 0x40
103#define SSD_FILEMARK 0x80
104 uint8_t info[4];
105 uint8_t extra_len;
106 uint8_t cmd_spec_info[4];
107 uint8_t add_sense_code;
108 uint8_t add_sense_code_qual;
109 uint8_t fru;
110 uint8_t sense_key_spec[3];
111#define SSD_SCS_VALID 0x80
112#define SSD_FIELDPTR_CMD 0x40
113#define SSD_BITPTR_VALID 0x08
114#define SSD_BITPTR_VALUE 0x07
115#define SSD_MIN_SIZE 18
116 uint8_t extra_bytes[14];
117#define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
118};
119
120
121static inline int
122aic_sector_div(sector_t capacity, int heads, int sectors)
123{
124
125 sector_div(capacity, (heads * sectors));
126 return (int)capacity;
127}
128
129static inline uint32_t
130scsi_4btoul(uint8_t *bytes)
131{
132 uint32_t rv;
133
134 rv = (bytes[0] << 24) |
135 (bytes[1] << 16) |
136 (bytes[2] << 8) |
137 bytes[3];
138 return (rv);
139}
140
141
142
143#define GETID(v, s) (unsigned)(((v) >> (s)) & 0xFFFF ?: PCI_ANY_ID)
144
145#define ID_C(x, c) \
146{ \
147 GETID(x,32), GETID(x,48), GETID(x,0), GETID(x,16), \
148 (c) << 8, 0xFFFF00, 0 \
149}
150
151#define ID2C(x) \
152 ID_C(x, PCI_CLASS_STORAGE_SCSI), \
153 ID_C(x, PCI_CLASS_STORAGE_RAID)
154
155#define IDIROC(x) ((x) | ~ID_ALL_IROC_MASK)
156
157
158
159
160
161
162#define ID16(x) \
163 ID(x), \
164 ID((x) | 0x0001000000000000ull), \
165 ID((x) | 0x0002000000000000ull), \
166 ID((x) | 0x0003000000000000ull), \
167 ID((x) | 0x0004000000000000ull), \
168 ID((x) | 0x0005000000000000ull), \
169 ID((x) | 0x0006000000000000ull), \
170 ID((x) | 0x0007000000000000ull), \
171 ID((x) | 0x0008000000000000ull), \
172 ID((x) | 0x0009000000000000ull), \
173 ID((x) | 0x000A000000000000ull), \
174 ID((x) | 0x000B000000000000ull), \
175 ID((x) | 0x000C000000000000ull), \
176 ID((x) | 0x000D000000000000ull), \
177 ID((x) | 0x000E000000000000ull), \
178 ID((x) | 0x000F000000000000ull)
179
180#endif
181