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