Contiki-NG
Loading...
Searching...
No Matches
scsi_struct.h
1#include <stdint.h>
2#include <scsi_sense.h>
3#include <scsi_command.h>
4
5#ifndef CC_BYTE_ALIGNED
6#ifdef __GNUC__
7#define CC_BYTE_ALIGNED __attribute__ ((packed))
8#endif
9#endif
10
11#ifndef CC_BYTE_ALIGNED
12#define CC_BYTE_ALIGNED
13#endif
14
15#define HOST16_TO_BE_BYTES(x) {(((x) >> 8) & 0xff), ((x) & 0xff)}
16#define HOST24_TO_BE_BYTES(x) {(((x) >> 16) & 0xff), (((x) >> 8) & 0xff), \
17 ((x) & 0xff)}
18#define HOST32_TO_BE_BYTES(x) {(((x) >> 24) & 0xff), (((x) >> 16) & 0xff), \
19 (((x) >> 8) & 0xff), ((x) & 0xff)}
20#define HOST40_TO_BE_BYTES(x) {(((x) >> 32) & 0xff), (((x) >> 24) & 0xff), (((x) >> 16) & 0xff), \
21 (((x) >> 8) & 0xff), ((x) & 0xff)}
22
23typedef uint8_t uint40_bytes[5];
24typedef uint8_t uint32_bytes[4];
25typedef uint8_t int24_bytes[3];
26typedef uint8_t uint24_bytes[3];
27typedef uint8_t uint16_bytes[2];
28
29inline unsigned long
30be16_to_host(uint16_bytes bytes)
31{
32 return bytes[0] << 8 | bytes[1];
33}
34
35inline unsigned long
36be24_to_host(uint24_bytes bytes)
37{
38 return bytes[0] << 16 | bytes[1] << 8 | bytes[2];
39}
40
41inline long
42signed_be24_to_host(int24_bytes bytes)
43{
44 return ((bytes[0] << 16 | bytes[1] << 8 | bytes[2]) ^ 0x800000) - 0x800000;
45}
46
47
48inline unsigned long
49be32_to_host(uint32_bytes bytes)
50{
51 return (be16_to_host(bytes) << 16) | be16_to_host(bytes + 2);
52}
53
54
55#define BE16_TO_HOST(bytes) ((bytes)[0] << 8 | (bytes)[1])
56#define BE32_TO_HOST(bytes) \
57((BE16_TO_HOST(bytes) << 16) | BE16_TO_HOST((bytes)+2))
58
59/* Flag field of INQUIRY command */
60#define SCSI_INQUIRY_FLAG_CMDDT 0x02
61#define SCSI_INQUIRY_FLAG_EVPD 0x01
62#define SCSI_INQUIRY_FLAG_LUN(a) ((a)<<5)
63
64struct scsi_inquiry_cmd
65{
66 uint8_t op_code;
67 uint8_t flags;
68 uint8_t page;
69 uint8_t reserved;
70 uint8_t allocation_length;
71 uint8_t control;
72} CC_BYTE_ALIGNED;
73
74/* Constant for the standard inquiry data */
75#define SCSI_STD_INQUIRY_CONNECTED 0x00
76#define SCSI_STD_INQUIRY_NOT_CONNECTED 0x20
77
78#define SCSI_STD_INQUIRY_VERSION_NONE 0x00
79#define SCSI_STD_INQUIRY_VERSION_SCSI1 0x01
80#define SCSI_STD_INQUIRY_VERSION_SCSI2 0x02
81#define SCSI_STD_INQUIRY_VERSION_SPC2 0x04
82
83#define SCSI_STD_INQUIRY_RESPONSE_DATA_FORMAT_SCSI1 0x00
84#define SCSI_STD_INQUIRY_RESPONSE_DATA_FORMAT_SCSI2 0x02
85
86#define SCSI_STD_INQUIRY_TYPE_DIRECT_ACCESS 0x00
87#define SCSI_STD_INQUIRY_TYPE_SEQUENTIAL 0x01
88#define SCSI_STD_INQUIRY_TYPE_PRINTER 0x02
89#define SCSI_STD_INQUIRY_TYPE_PROCESSOR 0x03
90#define SCSI_STD_INQUIRY_TYPE_WRITE_ONCE 0x04
91#define SCSI_STD_INQUIRY_TYPE_CD_ROM 0x05
92#define SCSI_STD_INQUIRY_TYPE_SCANNER 0x06
93#define SCSI_STD_INQUIRY_TYPE_OPTICAL 0x07
94#define SCSI_STD_INQUIRY_TYPE_CHANGER 0x08
95#define SCSI_STD_INQUIRY_TYPE_COMM 0x09
96#define SCSI_STD_INQUIRY_TYPE_RAID 0x0C
97#define SCSI_STD_INQUIRY_TYPE_RBC 0x0E
98
99#define SCSI_STD_INQUIRY_FLAG1_RMB 0x80
100
101#define SCSI_STD_INQUIRY_FLAG2_AERC 0x80
102#define SCSI_STD_INQUIRY_FLAG2_AENC 0x80
103#define SCSI_STD_INQUIRY_FLAG2_NORMACA 0x20
104#define SCSI_STD_INQUIRY_FLAG2_HISUP 0x10
105#define SCSI_STD_INQUIRY_FLAG2_RESPONSE_FORMAT 0x02
106
107#define SCSI_STD_INQUIRY_FLAG3_SCCS 0x80
108
109#define SCSI_STD_INQUIRY_FLAG4_BQUE 0x80
110#define SCSI_STD_INQUIRY_FLAG4_ENCSERV 0x40
111#define SCSI_STD_INQUIRY_FLAG4_VS 0x20
112#define SCSI_STD_INQUIRY_FLAG4_MULTIP 0x10
113#define SCSI_STD_INQUIRY_FLAG4_MCHNGR 0x08
114#define SCSI_STD_INQUIRY_FLAG4_ADDR16 0x01
115
116#define SCSI_STD_INQUIRY_FLAG5_RELADR 0x80
117#define SCSI_STD_INQUIRY_FLAG5_WBUS 0x20
118#define SCSI_STD_INQUIRY_FLAG5_SYNC 0x10
119#define SCSI_STD_INQUIRY_FLAG5_LINKED 0x08
120#define SCSI_STD_INQUIRY_FLAG5_CMDQUE 0x02
121
122struct scsi_std_inquiry_data
123{
124 uint8_t device;
125 uint8_t flags1;
126 uint8_t version;
127 uint8_t flags2;
128 uint8_t additional_length;
129 uint8_t flags3;
130 uint8_t flags4;
131 uint8_t flags5;
132 char vendor_id[8];
133 char product_id[16];
134 char product_rev[4];
135} CC_BYTE_ALIGNED;
136
137struct scsi_vital_product_data_head
138{
139 uint8_t device;
140 uint8_t page;
141 uint8_t reserved;
142 uint8_t page_length;
143} CC_BYTE_ALIGNED;
144
145struct scsi_identification_descriptor
146{
147 uint8_t code_set;
148 uint8_t identifier_type;
149 uint8_t reserved;
150 uint8_t identifier_length;
151};
152
153struct scsi_request_sense_cmd
154{
155 uint8_t op_code;
156 uint8_t reserved1;
157 uint8_t reserved2;
158 uint8_t reserved3;
159 uint8_t allocation_length;
160 uint8_t control;
161} CC_BYTE_ALIGNED;
162
163#define SCSI_SENSE_CURRENT_ERROR 0x70
164#define SCSI_SENSE_DEFERRED_ERROR 0x71
165#define SCSI_SENSE_INFORMATION_VALID 0x80
166#define SCSI_SENSE_FILEMARK 0x80
167#define SCSI_SENSE_EOM 0x40
168#define SCSI_SENSE_ILI 0x20
169
170struct scsi_sense_data
171{
172 uint8_t response_code;
173 uint8_t obsolete;
174 uint8_t sense_key;
175 uint8_t information[4];
176 uint8_t additional_length;
177 uint8_t command_specific[4];
178 uint8_t asc;
179 uint8_t ascq;
180 uint8_t unit_code;
181 uint8_t sense_key_specific[3];
182} CC_BYTE_ALIGNED;
183
184
185/* Flag field of INQUIRY command */
186#define SCSI_MODE_SENSE_FLAG_DBD 0x08
187#define SCSI_MODE_SENSE_FLAG_LUN(a) ((a)<<5)
188
189#define SCSI_MODE_SENSE_PC_CURRENT 0x00
190#define SCSI_MODE_SENSE_PC_CHANGEABLE 0x40
191#define SCSI_MODE_SENSE_PC_DEFAULT 0x80
192#define SCSI_MODE_SENSE_PC_SAVED 0xc0
193
194struct scsi_mode_sence_6_cmd
195{
196 uint8_t op_code;
197 uint8_t flags;
198 uint8_t page_code;
199 uint8_t reserved;
200 uint8_t allocation_length;
201 uint8_t control;
202} CC_BYTE_ALIGNED;
203
204struct scsi_mode_select_6_cmd
205{
206 uint8_t op_code;
207 uint8_t flags;
208 uint8_t reserved1;
209 uint8_t reserved2;
210 uint8_t parameter_list_length;
211 uint8_t control;
212};
213
214#define SCSI_MODE_PARAM_WP 0x80
215#define SCSI_MODE_PARAM_BUFFERED_MODE_SYNC 0x00
216#define SCSI_MODE_PARAM_BUFFERED_MODE_ASYNC 0x10
217#define SCSI_MODE_PARAM_BUFFERED_MODE_ALL_SYNC 0x10
218#define SCSI_MODE_PARAM_SPEED_DEFAULT 0x00
219#define SCSI_MODE_PARAM_SPEED_LOWEST 0x01
220#define SCSI_MODE_PARAM_SPEED_HIGHEST 0x0f
221
222struct scsi_mode_parameter_header_6
223{
224 uint8_t mode_data_length;
225 uint8_t medium_type;
226 uint8_t device_specific_parameter;
227 uint8_t block_descriptor_length;
228} CC_BYTE_ALIGNED;
229
230#define SCSI_DENSITY_9_800 0x01
231#define SCSI_DENSITY_9_1600 0x02
232#define SCSI_DENSITY_9_6250 0x03
233#define SCSI_DENSITY_4_9_8000 0x05
234#define SCSI_DENSITY_9_3200 0x06
235#define SCSI_DENSITY_4_6400 0x07
236#define SCSI_DENSITY_4_8000 0x08
237#define SCSI_DENSITY_18_37871 0x09
238#define SCSI_DENSITY_22_6667 0x0a
239#define SCSI_DENSITY_4_1600 0x0b
240#define SCSI_DENSITY_24_12690 0x0c
241#define SCSI_DENSITY_24_25380 0xd
242#define SCSI_DENSITY_15_10000 0x0f
243#define SCSI_DENSITY_18_10000 0x10
244#define SCSI_DENSITY_26_16000 0x11
245#define SCSI_DENSITY_30_51667 0x12
246#define SCSI_DENSITY_1_2400 0x13
247#define SCSI_DENSITY_1_43245 0x14
248#define SCSI_DENSITY_1_45434 0x15
249#define SCSI_DENSITY_48_10000 0x16
250#define SCSI_DENSITY_48_42500 0x17
251
252
253struct scsi_mode_parameter_block_descriptor
254{
255 uint8_t density_code;
256 uint24_bytes number_of_blocks;
257 uint8_t reserved;
258 uint24_bytes block_length;
259} CC_BYTE_ALIGNED;
260
261
262#define SCSI_MODE_PAGE_PS 0x80
263#define SCSI_MODE_PAGE_CONTROL_MODE 0x0a
264#define SCSI_MODE_PAGE_DEVICE_CONFIGURATION 0x10
265#define SCSI_MODE_PAGE_CONNECT 0x02
266#define SCSI_MODE_PAGE_MEDIUM_PARTITION_1 0x11
267#define SCSI_MODE_PAGE_MEDIUM_PARTITION_2 0x12
268#define SCSI_MODE_PAGE_MEDIUM_PARTITION_3 0x13
269#define SCSI_MODE_PAGE_MEDIUM_PARTITION_4 0x14
270#define SCSI_MODE_PAGE_PERIPHERIAL_DEVICE 0x09
271#define SCSI_MODE_PAGE_RW_ERROR_RECOVERY 0x01
272#define SCSI_MODE_PAGE_VENDOR_SPECIFIC 0x00
273#define SCSI_MODE_PAGE_ALL_PAGES 0x3f
274
275struct scsi_mode_page_header
276{
277 uint8_t page_code;
278 uint8_t page_length;
279} CC_BYTE_ALIGNED;
280
281#define SCSI_MODE_PAGE_CONTROL_FLAGS1_RLEC 0x01
282#define SCSI_MODE_PAGE_CONTROL_FLAGS2_QERR 0x02
283#define SCSI_MODE_PAGE_CONTROL_FLAGS2_DQUE 0x02
284#define SCSI_MODE_PAGE_CONTROL_FLAGS2_RESTRICED_REORDERING 0x00
285#define SCSI_MODE_PAGE_CONTROL_FLAGS2_UNRESTRICED_REORDERING 0x01
286#define SCSI_MODE_PAGE_CONTROL_FLAGS3_EECA 0x80
287#define SCSI_MODE_PAGE_CONTROL_FLAGS3_UAAENP 0x02
288#define SCSI_MODE_PAGE_CONTROL_FLAGS3_EAENP 0x01
289
290struct scsi_mode_page_control
291{
292 struct scsi_mode_page_header header;
293 uint8_t flags1;
294 uint8_t flags2;
295 uint8_t flags3;
296 uint8_t reserved;
297 uint16_bytes ready_AEN_holdoff_period;
298} CC_BYTE_ALIGNED;
299
300#define SCSI_MODE_PAGE_CONNECT_FLAGS_DTDC_NONE 0x00
301#define SCSI_MODE_PAGE_CONNECT_FLAGS_DTDC_TRANSFERRED 0x01
302#define SCSI_MODE_PAGE_CONNECT_FLAGS_DTDC_COMPLETE 0x03
303
304struct scsi_mode_page_connect
305{
306 struct scsi_mode_page_header header;
307 uint8_t buffer_full_ratio;
308 uint8_t buffer_empty_ratio;
309 uint16_bytes bus_inactivity_limit;
310 uint16_bytes disconnect_time_limit;
311 uint16_bytes connect_time_limit;
312 uint16_bytes maximum_burst_size;
313 uint8_t flags;
314 uint8_t reserved[3];
315} CC_BYTE_ALIGNED;
316
317struct scsi_mode_page_peripherial_device
318{
319 struct scsi_mode_page_header header;
320 uint16_bytes interface_identifier;
321 uint8_t reserved[4];
322 uint16_bytes maximum_burst_size;
323} CC_BYTE_ALIGNED;
324
325#define SCSI_MODE_PAGE_DEV_CONF_CAF 0x02
326#define SCSI_MODE_PAGE_DEV_CONF_CAP 0x04
327#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_REW 0x01
328#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_RBO 0x02
329#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_SOCF_IGNORE 0x00
330#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_SOCF_1 0x04
331#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_SOCF_2 0x08
332#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_SOCF_3 0xc0
333#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_AVC 0x10
334#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_RSMK 0x20
335#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_BIS 0x40
336#define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_DBR 0x40
337#define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_SEW 0x08
338#define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EEG 0x10
339#define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EOD_DEFAULT 0x00
340#define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EOD_ERASE_AREA 0x20
341#define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EOD_SOCF 0x40
342#define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EOD_NONE 0x60
343
344#define SCSI_MODE_PAGE_DEV_CONF_COMPR_NONE 0x00
345#define SCSI_MODE_PAGE_DEV_CONF_COMPR_DEFAULT 0x01
346
347struct scsi_mode_page_device_configuration
348{
349 struct scsi_mode_page_header header;
350 uint8_t active_format;
351 uint8_t active_partition;
352 uint8_t write_buffer_full_ratio;
353 uint8_t read_buffer_empty_ratio;
354 uint16_bytes write_delay_time;
355 uint8_t flags1;
356 uint8_t gap_size;
357 uint8_t flags2;
358 uint24_bytes buffer_size_at_early_warning;
359 uint8_t select_data_compression;
360 uint8_t reserved;
361};
362
363struct scsi_read_buffer_limits_cmd
364{
365 uint8_t op_code;
366 uint8_t lun;
367 uint8_t reserved[3];
368 uint8_t control;
369} CC_BYTE_ALIGNED;
370
371struct scsi_read_buffer_limits_data
372{
373 uint8_t reserved;
374 uint24_bytes maximum_block_length_limit;
375 uint16_bytes minimum_block_length_limit;
376} CC_BYTE_ALIGNED;
377
378#define SCSI_READ_FLAGS_FIXED 0x01
379#define SCSI_READ_FLAGS_SILI 0x02
380
381struct scsi_read_6_cmd
382{
383 uint8_t op_code;
384 uint8_t flags;
385 uint24_bytes transfer_length;
386 uint8_t control;
387} CC_BYTE_ALIGNED;
388
389#define SCSI_WRITE_FLAGS_FIXED 0x01
390
391struct scsi_write_6_cmd
392{
393 uint8_t op_code;
394 uint8_t flags;
395 uint24_bytes transfer_length;
396 uint8_t control;
397} CC_BYTE_ALIGNED;
398
399#define SCSI_WRITE_FILEMARKS_FLAGS_IMMED 0x01
400#define SCSI_WRITE_FILEMARKS_FLAGS_WSMK 0x02
401
402struct scsi_write_filemarks_6_cmd
403{
404 uint8_t op_code;
405 uint8_t flags;
406 int24_bytes transfer_length;
407 uint8_t control;
408} CC_BYTE_ALIGNED;
409
410#define SCSI_SPACE_FLAGS_CODE 0x07
411#define SCSI_SPACE_FLAGS_CODE_BLOCKS 0x00
412#define SCSI_SPACE_FLAGS_CODE_FILEMARKS 0x01
413#define SCSI_SPACE_FLAGS_CODE_SEQ_FILEMARKS 0x02
414#define SCSI_SPACE_FLAGS_CODE_END_OF_DATA 0x03
415#define SCSI_SPACE_FLAGS_CODE_SETMARKS 0x04
416#define SCSI_SPACE_FLAGS_CODE_SEQ_SETMARKS 0x05
417
418struct scsi_space_cmd
419{
420 uint8_t op_code;
421 uint8_t flags;
422 int24_bytes transfer_length;
423 uint8_t control;
424} CC_BYTE_ALIGNED;