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 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
26 */
27
28 #ifndef _LIBSCSI_IMPL_H
29 #define _LIBSCSI_IMPL_H
30
31 #pragma ident "%Z%%M% %I% %E% SMI"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include <libscsi.h>
38
39 #define LIBSCSI_ENGINE_EXT ".so"
40
41 #define LIBSCSI_ERRMSGLEN 512
42
43 typedef struct libscsi_engine_impl {
44 const libscsi_engine_t *lsei_engine;
45 void *lsei_dl_hdl;
46 struct libscsi_engine_impl *lsei_next;
47 } libscsi_engine_impl_t;
48
49 typedef struct libscsi_action_impl {
50 libscsi_hdl_t *lsai_hdl;
51 uint_t lsai_flags;
52 uint32_t lsai_timeout;
53 uint8_t *lsai_cdb;
54 size_t lsai_cdb_len;
55 size_t lsai_data_len;
56 size_t lsai_data_alloc;
57 uint8_t *lsai_data;
58 sam4_status_t lsai_status;
59 size_t lsai_sense_len;
60 uint8_t *lsai_sense_data;
61 uint8_t lsai_buf[1];
62 } libscsi_action_impl_t;
63
64 struct libscsi_hdl {
65 uint_t lsh_version;
66 libscsi_errno_t lsh_errno;
67 char lsh_errmsg[LIBSCSI_ERRMSGLEN];
68 libscsi_engine_impl_t *lsh_engines;
69 uint_t lsh_targets;
70 };
71
72 struct libscsi_target {
73 const libscsi_engine_t *lst_engine;
74 char *lst_vendor;
75 char *lst_product;
76 char *lst_revision;
77 char *lst_lid;
78 char *lst_usn;
79 void *lst_priv;
80 uint_t lst_mtbf_cdb;
81 uint_t lst_mtbf_read;
82 uint_t lst_mtbf_write;
83 struct libscsi_hdl *lst_hdl;
84 };
85
86 #define VERIFY(x) ((void)((x) || libscsi_assert(#x, __FILE__, __LINE__)))
87
88 #ifdef DEBUG
89 #define ASSERT(x) VERIFY(x)
90 #else
91 #define ASSERT(x)
92 #endif
93
94 #define LXOR(l, r) (((l) != 0) ^ ((r) != 0))
95
96 extern int libscsi_assert(const char *, const char *, int);
97 extern int libscsi_get_inquiry(struct libscsi_hdl *, struct libscsi_target *);
98 extern int libscsi_get_inquiry_dev_id(struct libscsi_hdl *,
99 struct libscsi_target *);
100 extern int libscsi_get_inquiry_usn(struct libscsi_hdl *,
101 struct libscsi_target *);
102
103 #ifdef __cplusplus
104 }
105 #endif
106
107 #endif /* _LIBSCSI_IMPL_H */