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