xref: /titanic_51/usr/src/uts/common/sys/scsi/impl/sense.h (revision 5c46c6a053defc1bf25f2e08df2653bc7717ed0b)
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_IMPL_SENSE_H
27 #define	_SYS_SCSI_IMPL_SENSE_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Implementation Variant defines
37  * for SCSI Sense Information
38  */
39 
40 /*
41  * These are 'pseudo' sense keys for common Sun implementation driver
42  * detected errors. Note that they start out as being higher than the
43  * legal key numbers for standard SCSI.
44  */
45 
46 #define	SUN_KEY_FATAL		0x10	/* driver, scsi handshake failure */
47 #define	SUN_KEY_TIMEOUT		0x11	/* driver, command timeout */
48 #define	SUN_KEY_EOF		0x12	/* driver, eof hit */
49 #define	SUN_KEY_EOT		0x13	/* driver, eot hit */
50 #define	SUN_KEY_LENGTH		0x14	/* driver, length error */
51 #define	SUN_KEY_BOT		0x15	/* driver, bot hit */
52 #define	SUN_KEY_WRONGMEDIA	0x16	/* driver, wrong tape media */
53 
54 #define	NUM_IMPL_SENSE_KEYS	7	/* seven extra keys */
55 
56 /*
57  * Common sense length allocation sufficient for this implementation.
58  */
59 
60 #define	SENSE_LENGTH	\
61 	(roundup(sizeof (struct scsi_extended_sense), sizeof (int)))
62 
63 /*
64  * Minimum useful Sense Length value
65  */
66 
67 #define	SUN_MIN_SENSE_LENGTH	4
68 
69 /*
70  * Specific variants to the Extended Sense structure.
71  *
72  * Defines for:
73  *	Emulex MD21 SCSI/ESDI Controller
74  *	Emulex MT02 SCSI/QIC-36 Controller.
75  *
76  * 1) The Emulex controllers put error class and error code into the byte
77  * right after the 'additional sense length' field in Extended Sense.
78  *
79  * 2) Except that some people state that this isn't so for the MD21- only
80  * the MT02.
81  */
82 
83 #define	emulex_ercl_ercd	es_cmd_info[0]
84 
85 /*
86  * 2) These are valid on Extended Sense for the MD21, FORMAT command only:
87  */
88 
89 #define	emulex_cyl_msb		es_info_1
90 #define	emulex_cyl_lsb		es_info_2
91 #define	emulex_head_num		es_info_3
92 #define	emulex_sect_num		es_info_4
93 
94 struct scsi_descr_template {
95 	uchar_t sdt_descr_type;
96 	uchar_t sdt_addl_length;
97 };
98 
99 /*
100  * Function prototypes for descriptor-format sense data functions
101  */
102 
103 uint8_t *scsi_find_sense_descr(uint8_t *sense_buffer, int sense_buf_len,
104     int descr_type);
105 
106 /*
107  * Function prototypes for format-neutral sense data functions
108  */
109 
110 uint8_t scsi_sense_key(uint8_t *sense_buffer);
111 
112 uint8_t scsi_sense_asc(uint8_t *sense_buffer);
113 
114 uint8_t scsi_sense_ascq(uint8_t *sense_buffer);
115 
116 boolean_t scsi_sense_info_uint64(uint8_t *sense_buffer,
117     int sense_buf_len, uint64_t *information);
118 
119 boolean_t scsi_sense_cmdspecific_uint64(uint8_t *sense_buffer,
120     int sense_buf_len, uint64_t *cmd_spec_info);
121 
122 void scsi_ext_sense_fields(uint8_t *sense_buffer, int sense_buf_len,
123     uint8_t **information, uint8_t **cmd_spec_info, uint8_t **fru_code,
124     uint8_t **sk_specific, uint8_t **stream_flags);
125 
126 int scsi_validate_sense(uint8_t *sense_buffer, int sense_buf_len, int *flags);
127 
128 /*
129  * Return codes for scsi_validate_sense
130  */
131 
132 #define	SENSE_UNUSABLE		0
133 #define	SENSE_FIXED_FORMAT	1
134 #define	SENSE_DESCR_FORMAT	2
135 
136 /*
137  * Flags from scsi_validate_sense
138  */
139 
140 #define	SNS_BUF_OVERFLOW	1	/* Sense buffer too small */
141 #define	SNS_BUF_DEFERRED 	2 	/* Sense data is for prior operation */
142 
143 #ifdef	__cplusplus
144 }
145 #endif
146 
147 #endif	/* _SYS_SCSI_IMPL_SENSE_H */
148