xref: /titanic_44/usr/src/uts/common/sys/scsi/impl/sense.h (revision 21bf64a78855d076f09716ea1c06175d954e934c)
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 2007 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  * Per SPC-3 standard, the maximum length of sense data is 252 bytes.
65  */
66 #define	MAX_SENSE_LENGTH	252
67 
68 /*
69  * Minimum useful Sense Length value
70  */
71 
72 #define	SUN_MIN_SENSE_LENGTH	4
73 
74 /*
75  * Specific variants to the Extended Sense structure.
76  *
77  * Defines for:
78  *	Emulex MD21 SCSI/ESDI Controller
79  *	Emulex MT02 SCSI/QIC-36 Controller.
80  *
81  * 1) The Emulex controllers put error class and error code into the byte
82  * right after the 'additional sense length' field in Extended Sense.
83  *
84  * 2) Except that some people state that this isn't so for the MD21- only
85  * the MT02.
86  */
87 
88 #define	emulex_ercl_ercd	es_cmd_info[0]
89 
90 /*
91  * 2) These are valid on Extended Sense for the MD21, FORMAT command only:
92  */
93 
94 #define	emulex_cyl_msb		es_info_1
95 #define	emulex_cyl_lsb		es_info_2
96 #define	emulex_head_num		es_info_3
97 #define	emulex_sect_num		es_info_4
98 
99 struct scsi_descr_template {
100 	uchar_t sdt_descr_type;
101 	uchar_t sdt_addl_length;
102 };
103 
104 /*
105  * Function prototypes for descriptor-format sense data functions
106  */
107 
108 uint8_t *scsi_find_sense_descr(uint8_t *sense_buffer, int sense_buf_len,
109     int descr_type);
110 
111 /*
112  * Function prototypes for format-neutral sense data functions
113  */
114 
115 uint8_t scsi_sense_key(uint8_t *sense_buffer);
116 
117 uint8_t scsi_sense_asc(uint8_t *sense_buffer);
118 
119 uint8_t scsi_sense_ascq(uint8_t *sense_buffer);
120 
121 boolean_t scsi_sense_info_uint64(uint8_t *sense_buffer,
122     int sense_buf_len, uint64_t *information);
123 
124 boolean_t scsi_sense_cmdspecific_uint64(uint8_t *sense_buffer,
125     int sense_buf_len, uint64_t *cmd_spec_info);
126 
127 void scsi_ext_sense_fields(uint8_t *sense_buffer, int sense_buf_len,
128     uint8_t **information, uint8_t **cmd_spec_info, uint8_t **fru_code,
129     uint8_t **sk_specific, uint8_t **stream_flags);
130 
131 int scsi_validate_sense(uint8_t *sense_buffer, int sense_buf_len, int *flags);
132 
133 /*
134  * Return codes for scsi_validate_sense
135  */
136 
137 #define	SENSE_UNUSABLE		0
138 #define	SENSE_FIXED_FORMAT	1
139 #define	SENSE_DESCR_FORMAT	2
140 
141 /*
142  * Flags from scsi_validate_sense
143  */
144 
145 #define	SNS_BUF_OVERFLOW	1	/* Sense buffer too small */
146 #define	SNS_BUF_DEFERRED 	2 	/* Sense data is for prior operation */
147 
148 #ifdef	__cplusplus
149 }
150 #endif
151 
152 #endif	/* _SYS_SCSI_IMPL_SENSE_H */
153