1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_SCSI_GENERIC_SENSE_H 27 #define _SYS_SCSI_GENERIC_SENSE_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /* 36 * Standard (Non-Extended) SCSI Sense. 37 * 38 * For Error Classe 0-6. This is all 39 * Vendor Unique sense information. 40 * 41 * Note: This is pre-SCSI-2. 42 */ 43 44 struct scsi_sense { 45 #if defined(_BIT_FIELDS_LTOH) 46 uchar_t ns_code : 4, /* Vendor Uniqe error code */ 47 ns_class : 3, /* Error class */ 48 ns_valid : 1; /* Logical Block Address is val */ 49 uchar_t ns_lba_hi : 5, /* High Logical Block Address */ 50 ns_vu : 3; /* Vendor Unique value */ 51 #elif defined(_BIT_FIELDS_HTOL) 52 uchar_t ns_valid : 1, /* Logical Block Address is valid */ 53 ns_class : 3, /* Error class */ 54 ns_code : 4; /* Vendor Uniqe error code */ 55 uchar_t ns_vu : 3, /* Vendor Unique value */ 56 ns_lba_hi : 5; /* High Logical Block Address */ 57 #else 58 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 59 #endif /* _BIT_FIELDS_LTOH */ 60 uchar_t ns_lba_mid; /* Middle Logical Block Address */ 61 uchar_t ns_lba_lo; /* Low part of Logical Block Address */ 62 }; 63 64 /* 65 * SCSI Extended Sense structure 66 * 67 * For Error Class 7, the Extended Sense Structure is applicable (now referred 68 * to in SPC-3 as "fixed format sense data"). The es_code field is used 69 * to determine whether the extended sense data is actually "fixed format" or 70 * the newer "descriptor format" introduced in SPC-3. 71 */ 72 73 #define CLASS_EXTENDED_SENSE 0x7 /* indicates extended sense */ 74 #define ADDL_SENSE_ADJUST 0x8 /* Add to es_add_length for total */ 75 #define MIN_FIXED_SENSE_LEN 0xE /* Minimum allowed fixed buf len */ 76 77 struct scsi_extended_sense { 78 #if defined(_BIT_FIELDS_LTOH) 79 uchar_t es_code : 4, /* Vendor Unique error code */ 80 es_class : 3, /* Error Class- fixed at 0x7 */ 81 es_valid : 1; /* sense data is valid */ 82 83 uchar_t es_segnum; /* segment number: for COPY cmd */ 84 85 uchar_t es_key : 4, /* Sense key (see below) */ 86 : 1, /* reserved */ 87 es_ili : 1, /* Incorrect Length Indicator */ 88 es_eom : 1, /* End of Media */ 89 es_filmk : 1; /* File Mark Detected */ 90 #elif defined(_BIT_FIELDS_HTOL) 91 uchar_t es_valid : 1, /* sense data is valid */ 92 es_class : 3, /* Error Class- fixed at 0x7 */ 93 es_code : 4; /* Vendor Unique error code */ 94 95 uchar_t es_segnum; /* segment number: for COPY cmd */ 96 97 uchar_t es_filmk : 1, /* File Mark Detected */ 98 es_eom : 1, /* End of Media */ 99 es_ili : 1, /* Incorrect Length Indicator */ 100 : 1, /* reserved */ 101 es_key : 4; /* Sense key (see below) */ 102 #else 103 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 104 #endif /* _BIT_FIELDS_LTOH */ 105 106 uchar_t es_info_1; /* information byte 1 */ 107 uchar_t es_info_2; /* information byte 2 */ 108 uchar_t es_info_3; /* information byte 3 */ 109 uchar_t es_info_4; /* information byte 4 */ 110 uchar_t es_add_len; /* number of additional bytes */ 111 112 uchar_t es_cmd_info[4]; /* command specific information */ 113 uchar_t es_add_code; /* Additional Sense Code */ 114 uchar_t es_qual_code; /* Additional Sense Code Qualifier */ 115 uchar_t es_fru_code; /* Field Replaceable Unit Code */ 116 uchar_t es_skey_specific[3]; /* Sense Key Specific information */ 117 118 /* 119 * Additional bytes may be defined in each implementation. 120 * The actual amount of space allocated for Sense Information 121 * is also implementation dependent. 122 * 123 * Modulo that, the declaration of an array two bytes in size 124 * nicely rounds this entire structure to a size of 20 bytes. 125 */ 126 127 uchar_t es_add_info[2]; /* additional information */ 128 129 }; 130 131 /* 132 * Sense code values for Extended Sense 133 */ 134 135 #define CODE_FMT_FIXED_CURRENT 0x0 136 #define CODE_FMT_FIXED_DEFERRED 0x1 137 #define CODE_FMT_DESCR_CURRENT 0x2 138 #define CODE_FMT_DESCR_DEFERRED 0x3 139 #define CODE_FMT_VENDOR_SPECIFIC 0xF 140 141 #define SCSI_IS_DESCR_SENSE(sns_ptr) \ 142 (((((struct scsi_extended_sense *)(sns_ptr))->es_code) == \ 143 CODE_FMT_DESCR_CURRENT) || \ 144 ((((struct scsi_extended_sense *)(sns_ptr))->es_code) == \ 145 CODE_FMT_DESCR_DEFERRED)) 146 147 /* 148 * Sense Key values for Extended Sense. 149 */ 150 151 #define KEY_NO_SENSE 0x00 152 #define KEY_RECOVERABLE_ERROR 0x01 153 #define KEY_NOT_READY 0x02 154 #define KEY_MEDIUM_ERROR 0x03 155 #define KEY_HARDWARE_ERROR 0x04 156 #define KEY_ILLEGAL_REQUEST 0x05 157 #define KEY_UNIT_ATTENTION 0x06 158 #define KEY_WRITE_PROTECT 0x07 159 #define KEY_DATA_PROTECT KEY_WRITE_PROTECT 160 #define KEY_BLANK_CHECK 0x08 161 #define KEY_VENDOR_UNIQUE 0x09 162 #define KEY_COPY_ABORTED 0x0A 163 #define KEY_ABORTED_COMMAND 0x0B 164 #define KEY_EQUAL 0x0C 165 #define KEY_VOLUME_OVERFLOW 0x0D 166 #define KEY_MISCOMPARE 0x0E 167 #define KEY_RESERVED 0x0F 168 169 /* 170 * Descriptor sense data header 171 * 172 * Descriptor format sense data is described in the SPC-3 standard. Unlike 173 * the fixed format sense data, descriptor format consists of a header 174 * followed by a variable length list of sense data descriptors. 175 */ 176 177 struct scsi_descr_sense_hdr { 178 #if defined(_BIT_FIELDS_LTOH) 179 uchar_t ds_code : 4, /* Vendor Unique error code */ 180 ds_class : 3, /* Error Class- fixed at 0x7 */ 181 ds_reserved : 1; /* sense data is valid */ 182 183 uchar_t ds_key : 4, /* Sense key */ 184 ds_reserved2 : 4; /* reserved */ 185 #elif defined(_BIT_FIELDS_HTOL) 186 uchar_t ds_reserved : 1, /* sense data is valid */ 187 ds_class : 3, /* Error Class- fixed at 0x7 */ 188 ds_code : 4; /* Vendor Unique error code */ 189 190 uchar_t ds_reserved2 : 4, /* reserved */ 191 ds_key : 4; /* Sense key (see below) */ 192 #else 193 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 194 #endif /* _BIT_FIELDS_LTOH */ 195 196 uchar_t ds_add_code; /* Additional Sense Code */ 197 uchar_t ds_qual_code; /* Additional Sense Code Qualifier */ 198 199 uchar_t ds_reserved3[3]; /* reserved */ 200 201 uchar_t ds_addl_sense_length; /* Additional sense data length */ 202 }; 203 204 /* 205 * SCSI sense descriptors 206 */ 207 208 struct scsi_information_sense_descr { 209 uchar_t isd_descr_type; /* Descriptor type (0x00) */ 210 uchar_t isd_addl_length; /* Additional byte count (0x0A) */ 211 #if defined(_BIT_FIELDS_LTOH) 212 uchar_t isd_reserved1 : 7, /* reserved */ 213 isd_valid : 1; /* Always set to 1 */ 214 #elif defined(_BIT_FIELDS_HTOL) 215 uchar_t isd_valid : 1, /* Always set to 1 */ 216 isd_reserved1 : 7; /* reserved */ 217 #else 218 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 219 #endif /* _BIT_FIELDS_LTOH */ 220 uchar_t isd_reserved2; /* reserved */ 221 uchar_t isd_information[8]; /* Information bytes */ 222 }; 223 224 struct scsi_cmd_specific_sense_descr { 225 uchar_t css_descr_type; /* Descriptor type (0x01) */ 226 uchar_t css_addl_length; /* Additional byte count (0x0A) */ 227 uchar_t css_reserved[2]; /* reserved */ 228 uchar_t css_cmd_specific_info[8]; /* Command specific info */ 229 }; 230 231 union scsi_sk_specific_data { 232 /* 233 * Field pointer (Sense key = Illegal Request) 234 */ 235 struct { 236 #if defined(_BIT_FIELDS_LTOH) 237 uchar_t bit_pointer : 3, 238 bpv : 1, 239 reserved : 2, 240 cd : 1, 241 sksv : 1; 242 #elif defined(_BIT_FIELDS_HTOL) 243 uchar_t sksv : 1, 244 cd : 1, 245 reserved : 2, 246 bpv : 1, 247 bit_pointer : 3; 248 #else 249 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 250 #endif /* _BIT_FIELDS_LTOH */ 251 uchar_t field_pointer[2]; 252 } fp; 253 /* 254 * Actual Retry Count (Sense key = Hardware error, 255 * Medium Error or Recovered Error) 256 */ 257 struct { 258 uchar_t sksv; 259 uchar_t actual_retry_count[2]; 260 } arc; 261 /* 262 * Progress Indication (Sense key = No Sense or Not Ready 263 */ 264 struct { 265 uchar_t sksv; 266 uchar_t progress_indication[2]; 267 } pi; 268 /* 269 * Segment Pointer (Sense key = Copy Aborted) 270 */ 271 struct { 272 #if defined(_BIT_FIELDS_LTOH) 273 uchar_t bit_pointer : 3, 274 bpv : 1, 275 reserved : 1, 276 sd : 1, 277 reserved2 : 1, 278 sksv : 1; 279 #elif defined(_BIT_FIELDS_HTOL) 280 uchar_t sksv : 1, 281 reserved2 : 1, 282 sd : 1, 283 reserved : 1, 284 bpv : 1, 285 bit_pointer : 3; 286 #else 287 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 288 #endif /* _BIT_FIELDS_LTOH */ 289 uchar_t field_pointer[2]; 290 } sp; 291 }; 292 293 struct scsi_sk_specific_sense_descr { 294 uchar_t sss_descr_type; /* Descriptor type */ 295 uchar_t sss_addl_length; /* Additional byte count (0x06) */ 296 uchar_t sss_reserved[2]; /* reserved */ 297 union scsi_sk_specific_data sss_data; 298 uchar_t sss_reserved2; 299 }; 300 301 struct scsi_fru_sense_descr { 302 uchar_t fs_descr_type; /* Descriptor type (0x03) */ 303 uchar_t fs_addl_length; /* Additional byte count (0x02) */ 304 uchar_t fs_reserved; /* reserved */ 305 uchar_t fs_fru_code; /* Field Replaceable Unit Code */ 306 }; 307 308 struct scsi_stream_cmd_data { 309 #if defined(_BIT_FIELDS_LTOH) 310 uchar_t scs_reserved2 : 5, 311 scs_ili : 1, 312 scs_eom : 1, 313 scs_filemark : 1; 314 #elif defined(_BIT_FIELDS_HTOL) 315 uchar_t scs_filemark : 1, 316 scs_eom : 1, 317 scs_ili : 1, 318 scs_reserved2 : 5; 319 #else 320 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 321 #endif /* _BIT_FIELDS_LTOH */ 322 }; 323 324 struct scsi_stream_cmd_sense_descr { 325 uchar_t scs_descr_type; /* Descriptor type (0x04) */ 326 uchar_t scs_addl_length; /* Additional byte count (0x02) */ 327 uchar_t scs_reserved; /* reserved */ 328 struct scsi_stream_cmd_data scs_data; 329 }; 330 331 struct scsi_block_cmd_sense_descr { 332 uchar_t bcs_descr_type; /* Descriptor type (0x05) */ 333 uchar_t bcs_addl_length; /* Additional byte count (0x02) */ 334 uchar_t bcs_reserved; /* reserved */ 335 #if defined(_BIT_FIELDS_LTOH) 336 uchar_t bcs_reserved2 : 5, 337 bcs_ili : 1, 338 bcs_reserved3 : 2; 339 #elif defined(_BIT_FIELDS_HTOL) 340 uchar_t bcs_reserved3 : 2, 341 bcs_ili : 1, 342 bcs_reserved2 : 5; 343 #else 344 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined 345 #endif /* _BIT_FIELDS_LTOH */ 346 }; 347 348 struct scsi_vendor_specific_sense_descr { 349 uchar_t vss_descr_type; /* Descriptor type (0x80-0xFF) */ 350 uchar_t vss_addl_length; /* Additional byte count */ 351 /* 352 * Variable length vendor specific data 353 */ 354 uchar_t vss_vendor_specific_info[1]; 355 }; 356 357 /* 358 * SCSI Descriptor Types 359 */ 360 #define DESCR_INFORMATION 0x00 361 #define DESCR_COMMAND_SPECIFIC 0x01 362 #define DESCR_SENSE_KEY_SPECIFIC 0x02 363 #define DESCR_FRU 0x03 364 #define DESCR_STREAM_COMMANDS 0x04 365 #define DESCR_BLOCK_COMMANDS 0x05 366 #define DESCR_OSD_OID 0x06 367 #define DESCR_OSD_RESP_INTEGRITY 0x07 368 #define DESCR_OSD_ATTR_ID 0x08 369 370 #ifdef __cplusplus 371 } 372 #endif 373 374 /* 375 * Each implementation will have specific mappings to what 376 * Sense Information means 377 */ 378 379 #include <sys/scsi/impl/sense.h> 380 381 #endif /* _SYS_SCSI_GENERIC_SENSE_H */ 382