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 _DS_SCSI_H
27 #define _DS_SCSI_H
28
29 #pragma ident "%Z%%M% %I% %E% SMI"
30
31 #include <sys/types.h>
32 #include <sys/byteorder.h>
33 #include <sys/scsi/scsi.h>
34
35 #include "ds_impl.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #if !defined(_BIT_FIELDS_LTOH) && !defined(_BIT_FIELDS_HTOL)
42 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
43 #endif
44
45 /*
46 * Log page structures
47 */
48 #pragma pack(1)
49
50 typedef struct scsi_log_header {
51 #if defined(_BIT_FIELDS_LTOH)
52 uint8_t lh_code : 6,
53 __reserved : 2;
54 #else
55 uint8_t __reserved : 2,
56 lh_code : 6;
57 #endif
58 uint8_t __reserved2;
59 uint16_t lh_length;
60 } scsi_log_header_t;
61
62 typedef struct scsi_log_parameter_header {
63 uint16_t lph_param;
64 #if defined(_BIT_FIELDS_LTOH)
65 uint8_t lph_lp : 1,
66 lph_lbin : 1,
67 lph_tmc : 2,
68 lph_etc : 1,
69 lph_tsd : 1,
70 lph_ds : 1,
71 lph_du : 1;
72 #else
73 uint8_t lph_du : 1,
74 lph_ds : 1,
75 lph_tsd : 1,
76 lph_etc : 1,
77 lph_tmc : 2,
78 lph_lbin : 1,
141 #define SELFTEST_FAILURE_INCOMPLETE 0x3
142 #define SELFTEST_FAILURE_SEG_UNKNOWN 0x4
143 #define SELFTEST_FAILURE_SEG_FIRST 0x5
144 #define SELFTEST_FAILURE_SEG_SECOND 0x6
145 #define SELFTEST_FAILURE_SEG_OTHER 0x7
146 #define SELFTEST_INPROGRESS 0xf
147
148 #define SELFTEST_COMPLETE(code) \
149 ((code) == SELFTEST_OK || \
150 ((code) >= SELFTEST_FAILURE_INCOMPLETE && \
151 ((code) <= SELFTEST_FAILURE_SEG_OTHER)))
152
153 #define LOGPARAM_TEMP_CURTEMP 0x0000
154 #define LOGPARAM_TEMP_REFTEMP 0x0001
155
156 #define LOGPARAM_TEMP_LEN \
157 (sizeof (scsi_temp_log_param_t) - \
158 sizeof (scsi_log_parameter_header_t))
159
160 /*
161 * Mode sense/select page header information
162 */
163 typedef struct scsi_ms_header {
164 struct mode_header ms_header;
165 struct block_descriptor ms_descriptor;
166 } scsi_ms_header_t;
167
168 typedef struct scsi_ms_header_g1 {
169 struct mode_header_g1 ms_header;
170 struct block_descriptor ms_descriptor;
171 } scsi_ms_header_g1_t;
172
173 typedef struct scsi_ms_hdrs {
174 int ms_length;
175 union {
176 scsi_ms_header_t g0;
177 scsi_ms_header_g1_t g1;
178 } ms_hdr;
179 } scsi_ms_hdrs_t;
180
261 /*
262 * Mode Sense Page Control
263 */
264 #define PC_CURRENT (0 << 6)
265 #define PC_CHANGEABLE (1 << 6)
266 #define PC_DEFAULT (2 << 6)
267 #define PC_SAVED (3 << 6)
268
269 /*
270 * Log Sense Page Control
271 */
272 #define PC_CUMULATIVE (1 << 6)
273
274 /*
275 * LOG page codes
276 */
277 #define LOGPAGE_SUPP_LIST 0x00
278 #define LOGPAGE_TEMP 0x0d
279 #define LOGPAGE_SELFTEST 0x10
280 #define LOGPAGE_IE 0x2f
281
282 /* ASC constants */
283 #define ASC_INVALID_OPCODE 0x20
284 #define ASC_INVALID_CDB_FIELD 0x24
285 #define ASC_FAILURE_PREDICTION_THRESHOLD_EXCEEDED 0x5d
286
287 /* ASCQ constants */
288 #define ASCQ_INVALID_OPCODE 0
289
290 /* Error tests */
291 #define SCSI_INVALID_OPCODE(s, a, aq) \
292 (((s) == KEY_ILLEGAL_REQUEST) && ((a) == ASC_INVALID_OPCODE) && \
293 ((aq) == ASCQ_INVALID_OPCODE))
294
295 #define MODE_PAGE_UNSUPPORTED(s, a, aq) \
296 (((s) == KEY_ILLEGAL_REQUEST) && ((a) == ASC_INVALID_CDB_FIELD))
297
298 /* command length to use */
299 #define MODE_CMD_LEN_UNKNOWN 0
300 #define MODE_CMD_LEN_6 1
301 #define MODE_CMD_LEN_10 2
302
303 /* supported modepages bitmask */
304 #define MODEPAGE_SUPP_IEC 0x1
305
306 /* supported logpages bitmask */
307 #define LOGPAGE_SUPP_IE 0x1
308 #define LOGPAGE_SUPP_TEMP 0x2
309 #define LOGPAGE_SUPP_SELFTEST 0x4
310
311 #define MSG_BUFLEN 256
312
313 /*
314 * For SCSI commands which want to accept arbitrary length responses, we need to
315 * allocate an appropriate sized buffer. The maximum length is USHRT_MAX,
316 * because some devices return nothing if the buffer length is too big.
317 */
318 #define MAX_BUFLEN(type) (USHRT_MAX - sizeof (type))
319
320 extern ds_transport_t ds_scsi_uscsi_transport;
321 extern ds_transport_t ds_scsi_sim_transport;
322
323 #ifdef __cplusplus
324 }
325 #endif
326
327 #endif /* _DS_SCSI_H */
|
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 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 #ifndef _DS_SCSI_H
28 #define _DS_SCSI_H
29
30 #include <sys/types.h>
31 #include <sys/byteorder.h>
32 #include <sys/scsi/scsi.h>
33
34 #include "ds_impl.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 #if !defined(_BIT_FIELDS_LTOH) && !defined(_BIT_FIELDS_HTOL)
41 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
42 #endif
43
44 /*
45 * Log page structures
46 */
47 #pragma pack(1)
48
49 typedef struct scsi_log_header {
50 #if defined(_BIT_FIELDS_LTOH)
51 uint8_t lh_code : 6,
52 lh_spf : 1,
53 lh_ds : 1;
54 #else
55 uint8_t lh_ds : 1,
56 lh_spf : 1,
57 lh_code : 6;
58 #endif
59 uint8_t lh_subpage;
60 uint16_t lh_length;
61 } scsi_log_header_t;
62
63 typedef struct scsi_log_parameter_header {
64 uint16_t lph_param;
65 #if defined(_BIT_FIELDS_LTOH)
66 uint8_t lph_lp : 1,
67 lph_lbin : 1,
68 lph_tmc : 2,
69 lph_etc : 1,
70 lph_tsd : 1,
71 lph_ds : 1,
72 lph_du : 1;
73 #else
74 uint8_t lph_du : 1,
75 lph_ds : 1,
76 lph_tsd : 1,
77 lph_etc : 1,
78 lph_tmc : 2,
79 lph_lbin : 1,
142 #define SELFTEST_FAILURE_INCOMPLETE 0x3
143 #define SELFTEST_FAILURE_SEG_UNKNOWN 0x4
144 #define SELFTEST_FAILURE_SEG_FIRST 0x5
145 #define SELFTEST_FAILURE_SEG_SECOND 0x6
146 #define SELFTEST_FAILURE_SEG_OTHER 0x7
147 #define SELFTEST_INPROGRESS 0xf
148
149 #define SELFTEST_COMPLETE(code) \
150 ((code) == SELFTEST_OK || \
151 ((code) >= SELFTEST_FAILURE_INCOMPLETE && \
152 ((code) <= SELFTEST_FAILURE_SEG_OTHER)))
153
154 #define LOGPARAM_TEMP_CURTEMP 0x0000
155 #define LOGPARAM_TEMP_REFTEMP 0x0001
156
157 #define LOGPARAM_TEMP_LEN \
158 (sizeof (scsi_temp_log_param_t) - \
159 sizeof (scsi_log_parameter_header_t))
160
161 /*
162 * Described in SBC3
163 */
164 typedef struct scsi_ssm_log_param {
165 scsi_log_parameter_header_t ssm_hdr;
166 uint16_t __reserved2;
167 uint8_t __reserved1;
168 uchar_t ssm_prcnt_used;
169 } scsi_ssm_log_param_t;
170
171 #define LOGPARAM_PRCNT_USED 0x0001
172 #define LOGPARAM_PRCNT_USED_PARAM_LEN 0x04
173 #define PRCNT_USED_FAULT_THRSH 90
174
175 /*
176 * Mode sense/select page header information
177 */
178 typedef struct scsi_ms_header {
179 struct mode_header ms_header;
180 struct block_descriptor ms_descriptor;
181 } scsi_ms_header_t;
182
183 typedef struct scsi_ms_header_g1 {
184 struct mode_header_g1 ms_header;
185 struct block_descriptor ms_descriptor;
186 } scsi_ms_header_g1_t;
187
188 typedef struct scsi_ms_hdrs {
189 int ms_length;
190 union {
191 scsi_ms_header_t g0;
192 scsi_ms_header_g1_t g1;
193 } ms_hdr;
194 } scsi_ms_hdrs_t;
195
276 /*
277 * Mode Sense Page Control
278 */
279 #define PC_CURRENT (0 << 6)
280 #define PC_CHANGEABLE (1 << 6)
281 #define PC_DEFAULT (2 << 6)
282 #define PC_SAVED (3 << 6)
283
284 /*
285 * Log Sense Page Control
286 */
287 #define PC_CUMULATIVE (1 << 6)
288
289 /*
290 * LOG page codes
291 */
292 #define LOGPAGE_SUPP_LIST 0x00
293 #define LOGPAGE_TEMP 0x0d
294 #define LOGPAGE_SELFTEST 0x10
295 #define LOGPAGE_IE 0x2f
296 /* Solid State Media log page code */
297 #define LOGPAGE_SSM 0x11
298
299 /* ASC constants */
300 #define ASC_INVALID_OPCODE 0x20
301 #define ASC_INVALID_CDB_FIELD 0x24
302 #define ASC_FAILURE_PREDICTION_THRESHOLD_EXCEEDED 0x5d
303
304 /* ASCQ constants */
305 #define ASCQ_INVALID_OPCODE 0
306
307 /* Error tests */
308 #define SCSI_INVALID_OPCODE(s, a, aq) \
309 (((s) == KEY_ILLEGAL_REQUEST) && ((a) == ASC_INVALID_OPCODE) && \
310 ((aq) == ASCQ_INVALID_OPCODE))
311
312 #define MODE_PAGE_UNSUPPORTED(s, a, aq) \
313 (((s) == KEY_ILLEGAL_REQUEST) && ((a) == ASC_INVALID_CDB_FIELD))
314
315 /* command length to use */
316 #define MODE_CMD_LEN_UNKNOWN 0
317 #define MODE_CMD_LEN_6 1
318 #define MODE_CMD_LEN_10 2
319
320 /* supported modepages bitmask */
321 #define MODEPAGE_SUPP_IEC 0x1
322
323 /* supported logpages bitmask */
324 #define LOGPAGE_SUPP_IE 0x1
325 #define LOGPAGE_SUPP_TEMP 0x2
326 #define LOGPAGE_SUPP_SELFTEST 0x4
327 #define LOGPAGE_SUPP_SSM 0x8
328
329 #define MSG_BUFLEN 256
330
331 /*
332 * For SCSI commands which want to accept arbitrary length responses, we need to
333 * allocate an appropriate sized buffer. The maximum length is USHRT_MAX,
334 * because some devices return nothing if the buffer length is too big.
335 */
336 #define MAX_BUFLEN(type) (USHRT_MAX - sizeof (type))
337
338 extern ds_transport_t ds_scsi_uscsi_transport;
339 extern ds_transport_t ds_scsi_sim_transport;
340
341 #ifdef __cplusplus
342 }
343 #endif
344
345 #endif /* _DS_SCSI_H */
|