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