Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * SCSI general interface description | |
3 | */ | |
4 | ||
15637ed4 RG |
5 | /* |
6 | * Largely written by Julian Elischer (julian@tfs.com) | |
7 | * for TRW Financial Systems. | |
8 | * | |
9 | * TRW Financial Systems, in accordance with their agreement with Carnegie | |
10 | * Mellon University, makes this software available to CMU to distribute | |
11 | * or use in any manner that they see fit as long as this message is kept with | |
12 | * the software. For this reason TFS also grants any other persons or | |
13 | * organisations permission to use or modify this software. | |
14 | * | |
15 | * TFS supplies this software to be publicly redistributed | |
16 | * on the understanding that TFS is not responsible for the correct | |
17 | * functioning of this software in any circumstances. | |
18 | * | |
78ed81a3 | 19 | * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 |
20 | * | |
21 | * $Id$ | |
15637ed4 RG |
22 | */ |
23 | ||
24 | /* | |
78ed81a3 | 25 | * SCSI command format |
15637ed4 RG |
26 | */ |
27 | ||
28 | /* | |
78ed81a3 | 29 | * Define dome bits that are in ALL (or a lot of) scsi commands |
15637ed4 | 30 | */ |
78ed81a3 | 31 | #define SCSI_CTL_LINK 0x01 |
32 | #define SCSI_CTL_FLAG 0x02 | |
33 | #define SCSI_CTL_VENDOR 0xC0 | |
34 | #define SCSI_CMD_LUN 0xA0 /*these two should not be needed*/ | |
35 | #define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */ | |
15637ed4 RG |
36 | |
37 | ||
38 | struct scsi_generic | |
39 | { | |
40 | u_char opcode; | |
41 | u_char bytes[11]; | |
42 | }; | |
43 | ||
44 | struct scsi_test_unit_ready | |
45 | { | |
46 | u_char op_code; | |
78ed81a3 | 47 | u_char byte2; |
15637ed4 | 48 | u_char unused[3]; |
78ed81a3 | 49 | u_char control; |
15637ed4 RG |
50 | }; |
51 | ||
52 | struct scsi_send_diag | |
53 | { | |
54 | u_char op_code; | |
78ed81a3 | 55 | u_char byte2; |
56 | #define SSD_UOL 0x01 | |
57 | #define SSD_DOL 0x02 | |
58 | #define SSD_SELFTEST 0x04 | |
59 | #define SSD_PF 0x10 | |
15637ed4 RG |
60 | u_char unused[1]; |
61 | u_char paramlen[2]; | |
78ed81a3 | 62 | u_char control; |
15637ed4 RG |
63 | }; |
64 | ||
65 | struct scsi_sense | |
66 | { | |
67 | u_char op_code; | |
78ed81a3 | 68 | u_char byte2; |
15637ed4 RG |
69 | u_char unused[2]; |
70 | u_char length; | |
78ed81a3 | 71 | u_char control; |
15637ed4 RG |
72 | }; |
73 | ||
74 | struct scsi_inquiry | |
75 | { | |
76 | u_char op_code; | |
78ed81a3 | 77 | u_char byte2; |
15637ed4 RG |
78 | u_char unused[2]; |
79 | u_char length; | |
78ed81a3 | 80 | u_char control; |
15637ed4 RG |
81 | }; |
82 | ||
83 | struct scsi_mode_sense | |
84 | { | |
85 | u_char op_code; | |
78ed81a3 | 86 | u_char byte2; |
87 | #define SMS_DBD 0x08 | |
88 | u_char page; | |
89 | #define SMS_PAGE_CODE 0x3F | |
90 | #define SMS_PAGE_CTRL 0xC0 | |
91 | #define SMS_PAGE_CTRL_CURRENT 0x00 | |
92 | #define SMS_PAGE_CTRL_CHANGEABLE 0x40 | |
93 | #define SMS_PAGE_CTRL_DEFAULT 0x80 | |
94 | #define SMS_PAGE_CTRL_SAVED 0xC0 | |
15637ed4 RG |
95 | u_char unused; |
96 | u_char length; | |
78ed81a3 | 97 | u_char control; |
15637ed4 RG |
98 | }; |
99 | ||
100 | struct scsi_mode_sense_big | |
101 | { | |
102 | u_char op_code; | |
78ed81a3 | 103 | u_char byte2; /* same bits as small version */ |
104 | u_char page; /* same bits as small version */ | |
15637ed4 RG |
105 | u_char unused[4]; |
106 | u_char length[2]; | |
78ed81a3 | 107 | u_char control; |
15637ed4 RG |
108 | }; |
109 | ||
110 | struct scsi_mode_select | |
111 | { | |
112 | u_char op_code; | |
78ed81a3 | 113 | u_char byte2; |
114 | #define SMS_SP 0x01 | |
115 | #define SMS_PF 0x10 | |
15637ed4 RG |
116 | u_char unused[2]; |
117 | u_char length; | |
78ed81a3 | 118 | u_char control; |
15637ed4 RG |
119 | }; |
120 | ||
121 | struct scsi_mode_select_big | |
122 | { | |
123 | u_char op_code; | |
78ed81a3 | 124 | u_char byte2; /* same bits as small version */ |
15637ed4 RG |
125 | u_char unused[5]; |
126 | u_char length[2]; | |
78ed81a3 | 127 | u_char control; |
15637ed4 RG |
128 | }; |
129 | ||
130 | struct scsi_reserve | |
131 | { | |
132 | u_char op_code; | |
78ed81a3 | 133 | u_char byte2; |
15637ed4 RG |
134 | u_char unused[2]; |
135 | u_char length; | |
78ed81a3 | 136 | u_char control; |
15637ed4 RG |
137 | }; |
138 | ||
139 | struct scsi_release | |
140 | { | |
141 | u_char op_code; | |
78ed81a3 | 142 | u_char byte2; |
15637ed4 RG |
143 | u_char unused[2]; |
144 | u_char length; | |
78ed81a3 | 145 | u_char control; |
15637ed4 RG |
146 | }; |
147 | ||
148 | struct scsi_prevent | |
149 | { | |
150 | u_char op_code; | |
78ed81a3 | 151 | u_char byte2; |
15637ed4 | 152 | u_char unused[2]; |
78ed81a3 | 153 | u_char how; |
154 | u_char control; | |
15637ed4 | 155 | }; |
78ed81a3 | 156 | #define PR_PREVENT 0x01 |
157 | #define PR_ALLOW 0x00 | |
15637ed4 RG |
158 | |
159 | /* | |
160 | * Opcodes | |
161 | */ | |
162 | ||
163 | #define TEST_UNIT_READY 0x00 | |
164 | #define REQUEST_SENSE 0x03 | |
165 | #define INQUIRY 0x12 | |
166 | #define MODE_SELECT 0x15 | |
167 | #define MODE_SENSE 0x1a | |
168 | #define START_STOP 0x1b | |
169 | #define RESERVE 0x16 | |
170 | #define RELEASE 0x17 | |
171 | #define PREVENT_ALLOW 0x1e | |
172 | #define POSITION_TO_ELEMENT 0x2b | |
173 | #define MODE_SENSE_BIG 0x54 | |
174 | #define MODE_SELECT_BIG 0x55 | |
175 | #define MOVE_MEDIUM 0xa5 | |
176 | #define READ_ELEMENT_STATUS 0xb8 | |
177 | ||
178 | ||
179 | /* | |
180 | * sense data format | |
181 | */ | |
182 | #define T_DIRECT 0 | |
183 | #define T_SEQUENTIAL 1 | |
184 | #define T_PRINTER 2 | |
185 | #define T_PROCESSOR 3 | |
186 | #define T_WORM 4 | |
187 | #define T_READONLY 5 | |
188 | #define T_SCANNER 6 | |
189 | #define T_OPTICAL 7 | |
190 | #define T_NODEVICE 0x1F | |
191 | ||
192 | #define T_CHANGER 8 | |
193 | #define T_COMM 9 | |
194 | ||
195 | #define T_REMOV 1 | |
196 | #define T_FIXED 0 | |
197 | ||
198 | struct scsi_inquiry_data | |
199 | { | |
78ed81a3 | 200 | u_char device; |
201 | #define SID_TYPE 0x1F | |
202 | #define SID_QUAL 0xE0 | |
203 | #define SID_QUAL_LU_OK 0x00 | |
204 | #define SID_QUAL_LU_OFFLINE 0x20 | |
205 | #define SID_QUAL_RSVD 0x40 | |
206 | #define SID_QUAL_BAD_LU 0x60 | |
207 | u_char dev_qual2; | |
208 | #define SID_QUAL2 0x7F | |
209 | #define SID_REMOVABLE 0x80 | |
210 | u_char version; | |
211 | #define SID_ANSII 0x07 | |
212 | #define SID_ECMA 0x38 | |
213 | #define SID_ISO 0xC0 | |
15637ed4 RG |
214 | u_char response_format; |
215 | u_char additional_length; | |
216 | u_char unused[2]; | |
78ed81a3 | 217 | u_char flags; |
218 | #define SID_SftRe 0x01 | |
219 | #define SID_CmdQue 0x02 | |
220 | #define SID_Linked 0x08 | |
221 | #define SID_Sync 0x10 | |
222 | #define SID_WBus16 0x20 | |
223 | #define SID_WBus32 0x40 | |
224 | #define SID_RelAdr 0x80 | |
15637ed4 RG |
225 | char vendor[8]; |
226 | char product[16]; | |
227 | char revision[4]; | |
228 | u_char extra[8]; | |
229 | }; | |
230 | ||
231 | ||
232 | struct scsi_sense_data | |
233 | { | |
78ed81a3 | 234 | u_char error_code; /* same bits as new version */ |
15637ed4 RG |
235 | union |
236 | { | |
237 | struct | |
238 | { | |
78ed81a3 | 239 | u_char blockhi; |
15637ed4 RG |
240 | u_char blockmed; |
241 | u_char blocklow; | |
242 | } unextended; | |
243 | struct | |
244 | { | |
245 | u_char segment; | |
78ed81a3 | 246 | u_char flags; /* same bits as new version */ |
15637ed4 RG |
247 | u_char info[4]; |
248 | u_char extra_len; | |
249 | /* allocate enough room to hold new stuff | |
15637ed4 RG |
250 | ( by increasing 16 to 26 below) */ |
251 | u_char extra_bytes[26]; | |
252 | } extended; | |
253 | }ext; | |
254 | }; | |
255 | struct scsi_sense_data_new | |
256 | { | |
78ed81a3 | 257 | u_char error_code; |
258 | #define SSD_ERRCODE 0x7F | |
259 | #define SSD_ERRCODE_VALID 0x80 | |
15637ed4 RG |
260 | union |
261 | { | |
78ed81a3 | 262 | struct /* this is depreciated, the standard says "DON'T"*/ |
15637ed4 | 263 | { |
78ed81a3 | 264 | u_char blockhi; |
15637ed4 RG |
265 | u_char blockmed; |
266 | u_char blocklow; | |
267 | } unextended; | |
268 | struct | |
269 | { | |
270 | u_char segment; | |
78ed81a3 | 271 | u_char flags; |
272 | #define SSD_KEY 0x0F | |
273 | #define SSD_ILI 0x20 | |
274 | #define SSD_EOM 0x40 | |
275 | #define SSD_FILEMARK 0x80 | |
15637ed4 RG |
276 | u_char info[4]; |
277 | u_char extra_len; | |
278 | u_char cmd_spec_info[4]; | |
279 | u_char add_sense_code; | |
280 | u_char add_sense_code_qual; | |
281 | u_char fru; | |
78ed81a3 | 282 | u_char sense_key_spec_1; |
283 | #define SSD_SCS_VALID 0x80 | |
15637ed4 RG |
284 | u_char sense_key_spec_2; |
285 | u_char sense_key_spec_3; | |
286 | u_char extra_bytes[16]; | |
287 | } extended; | |
288 | }ext; | |
289 | }; | |
290 | ||
291 | struct blk_desc | |
292 | { | |
293 | u_char density; | |
294 | u_char nblocks[3]; | |
295 | u_char reserved; | |
296 | u_char blklen[3]; | |
297 | }; | |
298 | ||
299 | struct scsi_mode_header | |
300 | { | |
301 | u_char data_length; /* Sense data length */ | |
302 | u_char medium_type; | |
303 | u_char dev_spec; | |
304 | u_char blk_desc_len; | |
305 | }; | |
306 | ||
307 | struct scsi_mode_header_big | |
308 | { | |
309 | u_char data_length[2]; /* Sense data length */ | |
310 | u_char medium_type; | |
311 | u_char dev_spec; | |
312 | u_char unused[2]; | |
313 | u_char blk_desc_len[2]; | |
314 | }; | |
315 | ||
316 | ||
317 | /* | |
318 | * Status Byte | |
319 | */ | |
320 | #define SCSI_OK 0x00 | |
321 | #define SCSI_CHECK 0x02 | |
322 | #define SCSI_BUSY 0x08 | |
323 | #define SCSI_INTERM 0x10 |