2 #include <scsi_sense.h>
3 #include <scsi_command.h>
5 #ifndef CC_BYTE_ALIGNED
7 #define CC_BYTE_ALIGNED __attribute__ ((packed))
11 #ifndef CC_BYTE_ALIGNED
12 #define CC_BYTE_ALIGNED
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), \
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)}
23 typedef uint8_t uint40_bytes[5];
24 typedef uint8_t uint32_bytes[4];
25 typedef uint8_t int24_bytes[3];
26 typedef uint8_t uint24_bytes[3];
27 typedef uint8_t uint16_bytes[2];
30 be16_to_host(uint16_bytes bytes)
32 return bytes[0] << 8 | bytes[1];
36 be24_to_host(uint24_bytes bytes)
38 return bytes[0] << 16 | bytes[1] << 8 | bytes[2];
42 signed_be24_to_host(int24_bytes bytes)
44 return ((bytes[0] << 16 | bytes[1] << 8 | bytes[2]) ^ 0x800000) - 0x800000;
49 be32_to_host(uint32_bytes bytes)
51 return (be16_to_host(bytes) << 16) | be16_to_host(bytes + 2);
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))
60 #define SCSI_INQUIRY_FLAG_CMDDT 0x02
61 #define SCSI_INQUIRY_FLAG_EVPD 0x01
62 #define SCSI_INQUIRY_FLAG_LUN(a) ((a)<<5)
64 struct scsi_inquiry_cmd
70 uint8_t allocation_length;
75 #define SCSI_STD_INQUIRY_CONNECTED 0x00
76 #define SCSI_STD_INQUIRY_NOT_CONNECTED 0x20
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
83 #define SCSI_STD_INQUIRY_RESPONSE_DATA_FORMAT_SCSI1 0x00
84 #define SCSI_STD_INQUIRY_RESPONSE_DATA_FORMAT_SCSI2 0x02
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
99 #define SCSI_STD_INQUIRY_FLAG1_RMB 0x80
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
107 #define SCSI_STD_INQUIRY_FLAG3_SCCS 0x80
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
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
122 struct scsi_std_inquiry_data
128 uint8_t additional_length;
137 struct scsi_vital_product_data_head
145 struct scsi_identification_descriptor
148 uint8_t identifier_type;
150 uint8_t identifier_length;
153 struct scsi_request_sense_cmd
159 uint8_t allocation_length;
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
170 struct scsi_sense_data
172 uint8_t response_code;
175 uint8_t information[4];
176 uint8_t additional_length;
177 uint8_t command_specific[4];
181 uint8_t sense_key_specific[3];
186 #define SCSI_MODE_SENSE_FLAG_DBD 0x08
187 #define SCSI_MODE_SENSE_FLAG_LUN(a) ((a)<<5)
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
194 struct scsi_mode_sence_6_cmd
200 uint8_t allocation_length;
204 struct scsi_mode_select_6_cmd
210 uint8_t parameter_list_length;
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
222 struct scsi_mode_parameter_header_6
224 uint8_t mode_data_length;
226 uint8_t device_specific_parameter;
227 uint8_t block_descriptor_length;
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
253 struct scsi_mode_parameter_block_descriptor
255 uint8_t density_code;
256 uint24_bytes number_of_blocks;
258 uint24_bytes block_length;
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
275 struct scsi_mode_page_header
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
290 struct scsi_mode_page_control
292 struct scsi_mode_page_header header;
297 uint16_bytes ready_AEN_holdoff_period;
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
304 struct scsi_mode_page_connect
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;
317 struct scsi_mode_page_peripherial_device
319 struct scsi_mode_page_header header;
320 uint16_bytes interface_identifier;
322 uint16_bytes maximum_burst_size;
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
344 #define SCSI_MODE_PAGE_DEV_CONF_COMPR_NONE 0x00
345 #define SCSI_MODE_PAGE_DEV_CONF_COMPR_DEFAULT 0x01
347 struct scsi_mode_page_device_configuration
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;
358 uint24_bytes buffer_size_at_early_warning;
359 uint8_t select_data_compression;
363 struct scsi_read_buffer_limits_cmd
371 struct scsi_read_buffer_limits_data
374 uint24_bytes maximum_block_length_limit;
375 uint16_bytes minimum_block_length_limit;
378 #define SCSI_READ_FLAGS_FIXED 0x01
379 #define SCSI_READ_FLAGS_SILI 0x02
381 struct scsi_read_6_cmd
385 uint24_bytes transfer_length;
389 #define SCSI_WRITE_FLAGS_FIXED 0x01
391 struct scsi_write_6_cmd
395 uint24_bytes transfer_length;
399 #define SCSI_WRITE_FILEMARKS_FLAGS_IMMED 0x01
400 #define SCSI_WRITE_FILEMARKS_FLAGS_WSMK 0x02
402 struct scsi_write_filemarks_6_cmd
406 int24_bytes transfer_length;
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
418 struct scsi_space_cmd
422 int24_bytes transfer_length;