scsi_struct.h

00001 #include <stdint.h>
00002 #include <scsi_sense.h>
00003 #include <scsi_command.h>
00004 
00005 #ifndef CC_BYTE_ALIGNED
00006 #ifdef __GNUC__
00007 #define CC_BYTE_ALIGNED __attribute__ ((packed))
00008 #endif
00009 #endif
00010 
00011 #ifndef CC_BYTE_ALIGNED
00012 #define CC_BYTE_ALIGNED
00013 #endif
00014 
00015 #define HOST16_TO_BE_BYTES(x) {(((x) >> 8) & 0xff), ((x) & 0xff)}
00016 #define HOST24_TO_BE_BYTES(x) {(((x) >> 16) & 0xff), (((x) >> 8) & 0xff), \
00017  ((x) & 0xff)}
00018 #define HOST32_TO_BE_BYTES(x) {(((x) >> 24) & 0xff), (((x) >> 16) & 0xff), \
00019  (((x) >> 8) & 0xff), ((x) & 0xff)}
00020 #define HOST40_TO_BE_BYTES(x) {(((x) >> 32) & 0xff), (((x) >> 24) & 0xff), (((x) >> 16) & 0xff), \
00021  (((x) >> 8) & 0xff), ((x) & 0xff)}
00022 
00023 typedef uint8_t uint40_bytes[5];
00024 typedef uint8_t uint32_bytes[4];
00025 typedef uint8_t int24_bytes[3];
00026 typedef uint8_t uint24_bytes[3];
00027 typedef uint8_t uint16_bytes[2];
00028 
00029 inline unsigned long
00030 be16_to_host(uint16_bytes bytes)
00031 {
00032   return bytes[0] << 8 | bytes[1];
00033 }
00034 
00035 inline unsigned long
00036 be24_to_host(uint24_bytes bytes)
00037 {
00038   return bytes[0] << 16 | bytes[1] << 8 | bytes[2];
00039 }
00040 
00041 inline long
00042 signed_be24_to_host(int24_bytes bytes)
00043 {
00044   return ((bytes[0] << 16 | bytes[1] << 8 | bytes[2]) ^ 0x800000) - 0x800000;
00045 }
00046 
00047 
00048 inline unsigned long
00049 be32_to_host(uint32_bytes bytes)
00050 {
00051   return (be16_to_host(bytes) << 16) | be16_to_host(bytes + 2);
00052 }
00053 
00054 
00055 #define BE16_TO_HOST(bytes) ((bytes)[0] << 8 | (bytes)[1])
00056 #define BE32_TO_HOST(bytes) \
00057 ((BE16_TO_HOST(bytes) << 16) | BE16_TO_HOST((bytes)+2))
00058 
00059 /* Flag field of INQUIRY command */
00060 #define SCSI_INQUIRY_FLAG_CMDDT 0x02
00061 #define SCSI_INQUIRY_FLAG_EVPD 0x01
00062 #define SCSI_INQUIRY_FLAG_LUN(a) ((a)<<5)
00063 
00064 struct scsi_inquiry_cmd
00065 {
00066   uint8_t op_code;
00067   uint8_t flags;
00068   uint8_t page;
00069   uint8_t reserved;
00070   uint8_t allocation_length;
00071   uint8_t control;
00072 } CC_BYTE_ALIGNED;
00073 
00074 /* Constant for the standard inquiry data */
00075 #define SCSI_STD_INQUIRY_CONNECTED 0x00
00076 #define SCSI_STD_INQUIRY_NOT_CONNECTED 0x20
00077 
00078 #define SCSI_STD_INQUIRY_VERSION_NONE 0x00
00079 #define SCSI_STD_INQUIRY_VERSION_SCSI1 0x01
00080 #define SCSI_STD_INQUIRY_VERSION_SCSI2 0x02
00081 #define SCSI_STD_INQUIRY_VERSION_SPC2 0x04
00082 
00083 #define SCSI_STD_INQUIRY_RESPONSE_DATA_FORMAT_SCSI1 0x00
00084 #define SCSI_STD_INQUIRY_RESPONSE_DATA_FORMAT_SCSI2 0x02
00085 
00086 #define SCSI_STD_INQUIRY_TYPE_DIRECT_ACCESS 0x00
00087 #define SCSI_STD_INQUIRY_TYPE_SEQUENTIAL 0x01
00088 #define SCSI_STD_INQUIRY_TYPE_PRINTER 0x02
00089 #define SCSI_STD_INQUIRY_TYPE_PROCESSOR 0x03
00090 #define SCSI_STD_INQUIRY_TYPE_WRITE_ONCE 0x04
00091 #define SCSI_STD_INQUIRY_TYPE_CD_ROM 0x05
00092 #define SCSI_STD_INQUIRY_TYPE_SCANNER 0x06
00093 #define SCSI_STD_INQUIRY_TYPE_OPTICAL 0x07
00094 #define SCSI_STD_INQUIRY_TYPE_CHANGER 0x08
00095 #define SCSI_STD_INQUIRY_TYPE_COMM 0x09
00096 #define SCSI_STD_INQUIRY_TYPE_RAID 0x0C
00097 #define SCSI_STD_INQUIRY_TYPE_RBC 0x0E
00098 
00099 #define SCSI_STD_INQUIRY_FLAG1_RMB 0x80
00100 
00101 #define SCSI_STD_INQUIRY_FLAG2_AERC 0x80
00102 #define SCSI_STD_INQUIRY_FLAG2_AENC 0x80
00103 #define SCSI_STD_INQUIRY_FLAG2_NORMACA 0x20
00104 #define SCSI_STD_INQUIRY_FLAG2_HISUP 0x10
00105 #define SCSI_STD_INQUIRY_FLAG2_RESPONSE_FORMAT 0x02
00106 
00107 #define SCSI_STD_INQUIRY_FLAG3_SCCS 0x80
00108 
00109 #define SCSI_STD_INQUIRY_FLAG4_BQUE 0x80
00110 #define SCSI_STD_INQUIRY_FLAG4_ENCSERV 0x40
00111 #define SCSI_STD_INQUIRY_FLAG4_VS 0x20
00112 #define SCSI_STD_INQUIRY_FLAG4_MULTIP 0x10
00113 #define SCSI_STD_INQUIRY_FLAG4_MCHNGR 0x08
00114 #define SCSI_STD_INQUIRY_FLAG4_ADDR16 0x01
00115 
00116 #define SCSI_STD_INQUIRY_FLAG5_RELADR 0x80
00117 #define SCSI_STD_INQUIRY_FLAG5_WBUS 0x20
00118 #define SCSI_STD_INQUIRY_FLAG5_SYNC 0x10
00119 #define SCSI_STD_INQUIRY_FLAG5_LINKED 0x08
00120 #define SCSI_STD_INQUIRY_FLAG5_CMDQUE 0x02
00121 
00122 struct scsi_std_inquiry_data
00123 {
00124   uint8_t device;
00125   uint8_t flags1;
00126   uint8_t version;
00127   uint8_t flags2;
00128   uint8_t additional_length;
00129   uint8_t flags3;
00130   uint8_t flags4;
00131   uint8_t flags5;
00132   char vendor_id[8];
00133   char product_id[16];
00134   char product_rev[4];
00135 } CC_BYTE_ALIGNED;
00136 
00137 struct scsi_vital_product_data_head
00138 {
00139   uint8_t device;
00140   uint8_t page;
00141   uint8_t reserved;
00142   uint8_t page_length;
00143 } CC_BYTE_ALIGNED;
00144 
00145 struct scsi_identification_descriptor
00146 {
00147   uint8_t code_set;
00148   uint8_t identifier_type;
00149   uint8_t reserved;
00150   uint8_t identifier_length;
00151 };
00152 
00153 struct scsi_request_sense_cmd
00154 {
00155   uint8_t op_code;
00156   uint8_t reserved1;
00157   uint8_t reserved2;
00158   uint8_t reserved3;
00159   uint8_t allocation_length;
00160   uint8_t control;
00161 } CC_BYTE_ALIGNED;
00162 
00163 #define SCSI_SENSE_CURRENT_ERROR 0x70
00164 #define SCSI_SENSE_DEFERRED_ERROR 0x71
00165 #define SCSI_SENSE_INFORMATION_VALID 0x80
00166 #define SCSI_SENSE_FILEMARK 0x80
00167 #define SCSI_SENSE_EOM 0x40
00168 #define SCSI_SENSE_ILI 0x20
00169 
00170 struct scsi_sense_data
00171 {
00172   uint8_t response_code;
00173   uint8_t obsolete;
00174   uint8_t sense_key;
00175   uint8_t information[4];
00176   uint8_t additional_length;
00177   uint8_t command_specific[4];
00178   uint8_t asc;
00179   uint8_t ascq;
00180   uint8_t unit_code;
00181   uint8_t sense_key_specific[3];
00182 } CC_BYTE_ALIGNED;
00183 
00184 
00185 /* Flag field of INQUIRY command */
00186 #define SCSI_MODE_SENSE_FLAG_DBD 0x08
00187 #define SCSI_MODE_SENSE_FLAG_LUN(a) ((a)<<5)
00188 
00189 #define SCSI_MODE_SENSE_PC_CURRENT 0x00
00190 #define SCSI_MODE_SENSE_PC_CHANGEABLE 0x40
00191 #define SCSI_MODE_SENSE_PC_DEFAULT 0x80
00192 #define SCSI_MODE_SENSE_PC_SAVED 0xc0
00193 
00194 struct scsi_mode_sence_6_cmd
00195 {
00196   uint8_t op_code;
00197   uint8_t flags;
00198   uint8_t page_code;
00199   uint8_t reserved;
00200   uint8_t allocation_length;
00201   uint8_t control;
00202 } CC_BYTE_ALIGNED;
00203 
00204 struct scsi_mode_select_6_cmd
00205 {
00206   uint8_t op_code;
00207   uint8_t flags;
00208   uint8_t reserved1;
00209   uint8_t reserved2;
00210   uint8_t parameter_list_length;
00211   uint8_t control;
00212 };
00213 
00214 #define SCSI_MODE_PARAM_WP 0x80
00215 #define SCSI_MODE_PARAM_BUFFERED_MODE_SYNC 0x00
00216 #define SCSI_MODE_PARAM_BUFFERED_MODE_ASYNC 0x10
00217 #define SCSI_MODE_PARAM_BUFFERED_MODE_ALL_SYNC 0x10
00218 #define SCSI_MODE_PARAM_SPEED_DEFAULT 0x00
00219 #define SCSI_MODE_PARAM_SPEED_LOWEST 0x01
00220 #define SCSI_MODE_PARAM_SPEED_HIGHEST 0x0f
00221 
00222 struct scsi_mode_parameter_header_6
00223 {
00224   uint8_t mode_data_length;
00225   uint8_t medium_type;
00226   uint8_t device_specific_parameter;
00227   uint8_t block_descriptor_length;
00228 } CC_BYTE_ALIGNED;
00229 
00230 #define SCSI_DENSITY_9_800 0x01
00231 #define SCSI_DENSITY_9_1600 0x02
00232 #define SCSI_DENSITY_9_6250 0x03
00233 #define SCSI_DENSITY_4_9_8000 0x05
00234 #define SCSI_DENSITY_9_3200 0x06
00235 #define SCSI_DENSITY_4_6400 0x07
00236 #define SCSI_DENSITY_4_8000 0x08
00237 #define SCSI_DENSITY_18_37871 0x09
00238 #define SCSI_DENSITY_22_6667 0x0a
00239 #define SCSI_DENSITY_4_1600 0x0b
00240 #define SCSI_DENSITY_24_12690 0x0c
00241 #define SCSI_DENSITY_24_25380 0xd
00242 #define SCSI_DENSITY_15_10000 0x0f
00243 #define SCSI_DENSITY_18_10000 0x10
00244 #define SCSI_DENSITY_26_16000 0x11
00245 #define SCSI_DENSITY_30_51667 0x12
00246 #define SCSI_DENSITY_1_2400 0x13
00247 #define SCSI_DENSITY_1_43245 0x14
00248 #define SCSI_DENSITY_1_45434 0x15
00249 #define SCSI_DENSITY_48_10000 0x16
00250 #define SCSI_DENSITY_48_42500 0x17
00251 
00252 
00253 struct scsi_mode_parameter_block_descriptor
00254 {
00255   uint8_t density_code;
00256   uint24_bytes number_of_blocks;
00257   uint8_t reserved;
00258   uint24_bytes block_length;
00259 } CC_BYTE_ALIGNED;
00260 
00261 
00262 #define SCSI_MODE_PAGE_PS 0x80
00263 #define SCSI_MODE_PAGE_CONTROL_MODE 0x0a
00264 #define SCSI_MODE_PAGE_DEVICE_CONFIGURATION 0x10
00265 #define SCSI_MODE_PAGE_CONNECT 0x02
00266 #define SCSI_MODE_PAGE_MEDIUM_PARTITION_1 0x11
00267 #define SCSI_MODE_PAGE_MEDIUM_PARTITION_2 0x12
00268 #define SCSI_MODE_PAGE_MEDIUM_PARTITION_3 0x13
00269 #define SCSI_MODE_PAGE_MEDIUM_PARTITION_4 0x14
00270 #define SCSI_MODE_PAGE_PERIPHERIAL_DEVICE 0x09
00271 #define SCSI_MODE_PAGE_RW_ERROR_RECOVERY 0x01
00272 #define SCSI_MODE_PAGE_VENDOR_SPECIFIC 0x00
00273 #define SCSI_MODE_PAGE_ALL_PAGES 0x3f
00274 
00275 struct scsi_mode_page_header
00276 {
00277   uint8_t page_code;
00278   uint8_t page_length;
00279 } CC_BYTE_ALIGNED;
00280 
00281 #define SCSI_MODE_PAGE_CONTROL_FLAGS1_RLEC 0x01
00282 #define SCSI_MODE_PAGE_CONTROL_FLAGS2_QERR 0x02
00283 #define SCSI_MODE_PAGE_CONTROL_FLAGS2_DQUE 0x02
00284 #define SCSI_MODE_PAGE_CONTROL_FLAGS2_RESTRICED_REORDERING 0x00
00285 #define SCSI_MODE_PAGE_CONTROL_FLAGS2_UNRESTRICED_REORDERING 0x01
00286 #define SCSI_MODE_PAGE_CONTROL_FLAGS3_EECA 0x80
00287 #define SCSI_MODE_PAGE_CONTROL_FLAGS3_UAAENP 0x02
00288 #define SCSI_MODE_PAGE_CONTROL_FLAGS3_EAENP 0x01
00289 
00290 struct scsi_mode_page_control
00291 {
00292   struct scsi_mode_page_header header;
00293   uint8_t flags1;
00294   uint8_t flags2;
00295   uint8_t flags3;
00296   uint8_t reserved;
00297   uint16_bytes ready_AEN_holdoff_period;
00298 } CC_BYTE_ALIGNED;
00299 
00300 #define SCSI_MODE_PAGE_CONNECT_FLAGS_DTDC_NONE 0x00
00301 #define SCSI_MODE_PAGE_CONNECT_FLAGS_DTDC_TRANSFERRED 0x01
00302 #define SCSI_MODE_PAGE_CONNECT_FLAGS_DTDC_COMPLETE 0x03
00303 
00304 struct scsi_mode_page_connect
00305 {
00306   struct scsi_mode_page_header header;
00307   uint8_t buffer_full_ratio;
00308   uint8_t buffer_empty_ratio;
00309   uint16_bytes bus_inactivity_limit;
00310   uint16_bytes disconnect_time_limit;
00311   uint16_bytes connect_time_limit;
00312   uint16_bytes maximum_burst_size;
00313   uint8_t flags;
00314   uint8_t reserved[3];
00315 } CC_BYTE_ALIGNED;
00316 
00317 struct scsi_mode_page_peripherial_device
00318 {
00319   struct scsi_mode_page_header header;
00320   uint16_bytes interface_identifier;
00321   uint8_t reserved[4];
00322   uint16_bytes maximum_burst_size;
00323 } CC_BYTE_ALIGNED;
00324 
00325 #define SCSI_MODE_PAGE_DEV_CONF_CAF 0x02
00326 #define SCSI_MODE_PAGE_DEV_CONF_CAP 0x04
00327 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_REW 0x01
00328 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_RBO 0x02
00329 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_SOCF_IGNORE 0x00
00330 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_SOCF_1 0x04
00331 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_SOCF_2 0x08
00332 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_SOCF_3 0xc0
00333 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_AVC 0x10
00334 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_RSMK 0x20
00335 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_BIS 0x40
00336 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS1_DBR 0x40
00337 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_SEW 0x08
00338 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EEG 0x10
00339 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EOD_DEFAULT 0x00
00340 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EOD_ERASE_AREA 0x20
00341 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EOD_SOCF 0x40
00342 #define SCSI_MODE_PAGE_DEV_CONF_FLAGS2_EOD_NONE 0x60
00343 
00344 #define SCSI_MODE_PAGE_DEV_CONF_COMPR_NONE 0x00
00345 #define SCSI_MODE_PAGE_DEV_CONF_COMPR_DEFAULT 0x01
00346 
00347 struct scsi_mode_page_device_configuration
00348 {
00349   struct scsi_mode_page_header header;
00350   uint8_t active_format;
00351   uint8_t active_partition;
00352   uint8_t write_buffer_full_ratio;
00353   uint8_t read_buffer_empty_ratio;
00354   uint16_bytes write_delay_time;
00355   uint8_t flags1;
00356   uint8_t gap_size;
00357   uint8_t flags2;
00358   uint24_bytes buffer_size_at_early_warning;
00359   uint8_t select_data_compression;
00360   uint8_t reserved;
00361 };
00362 
00363 struct scsi_read_buffer_limits_cmd
00364 {
00365   uint8_t op_code;
00366   uint8_t lun;
00367   uint8_t reserved[3];
00368   uint8_t control;
00369 } CC_BYTE_ALIGNED;
00370 
00371 struct scsi_read_buffer_limits_data
00372 {
00373   uint8_t reserved;
00374   uint24_bytes maximum_block_length_limit;
00375   uint16_bytes minimum_block_length_limit;
00376 } CC_BYTE_ALIGNED;
00377 
00378 #define SCSI_READ_FLAGS_FIXED 0x01
00379 #define SCSI_READ_FLAGS_SILI 0x02
00380 
00381 struct scsi_read_6_cmd
00382 {
00383   uint8_t op_code;
00384   uint8_t flags;
00385   uint24_bytes transfer_length;
00386   uint8_t control;
00387 } CC_BYTE_ALIGNED;
00388 
00389 #define SCSI_WRITE_FLAGS_FIXED 0x01
00390 
00391 struct scsi_write_6_cmd
00392 {
00393   uint8_t op_code;
00394   uint8_t flags;
00395   uint24_bytes transfer_length;
00396   uint8_t control;
00397 } CC_BYTE_ALIGNED;
00398 
00399 #define SCSI_WRITE_FILEMARKS_FLAGS_IMMED 0x01
00400 #define SCSI_WRITE_FILEMARKS_FLAGS_WSMK 0x02
00401 
00402 struct scsi_write_filemarks_6_cmd
00403 {
00404   uint8_t op_code;
00405   uint8_t flags;
00406   int24_bytes transfer_length;
00407   uint8_t control;
00408 } CC_BYTE_ALIGNED;
00409 
00410 #define SCSI_SPACE_FLAGS_CODE 0x07
00411 #define SCSI_SPACE_FLAGS_CODE_BLOCKS 0x00
00412 #define SCSI_SPACE_FLAGS_CODE_FILEMARKS 0x01
00413 #define SCSI_SPACE_FLAGS_CODE_SEQ_FILEMARKS 0x02
00414 #define SCSI_SPACE_FLAGS_CODE_END_OF_DATA 0x03
00415 #define SCSI_SPACE_FLAGS_CODE_SETMARKS 0x04
00416 #define SCSI_SPACE_FLAGS_CODE_SEQ_SETMARKS 0x05
00417 
00418 struct scsi_space_cmd
00419 {
00420   uint8_t op_code;
00421   uint8_t flags;
00422   int24_bytes transfer_length;
00423   uint8_t control;
00424 } CC_BYTE_ALIGNED;

Generated on Mon Apr 11 14:23:35 2011 for Contiki 2.5 by  doxygen 1.6.1