xref: /illumos-gate/usr/src/lib/scsi/libscsi/common/libscsi_impl.h (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
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  */
26 
27 #ifndef	_LIBSCSI_IMPL_H
28 #define	_LIBSCSI_IMPL_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <libscsi.h>
35 
36 #define	LIBSCSI_ENGINE_EXT	".so"
37 
38 #define	LIBSCSI_ERRMSGLEN	512
39 
40 typedef struct libscsi_engine_impl {
41 	const libscsi_engine_t *lsei_engine;
42 	void *lsei_dl_hdl;
43 	struct libscsi_engine_impl *lsei_next;
44 } libscsi_engine_impl_t;
45 
46 typedef struct libscsi_action_impl {
47 	libscsi_hdl_t *lsai_hdl;
48 	uint_t lsai_flags;
49 	uint32_t lsai_timeout;
50 	uint8_t *lsai_cdb;
51 	size_t lsai_cdb_len;
52 	size_t lsai_data_len;
53 	size_t lsai_data_alloc;
54 	uint8_t *lsai_data;
55 	sam4_status_t lsai_status;
56 	size_t lsai_sense_len;
57 	uint8_t *lsai_sense_data;
58 	uint8_t lsai_buf[1];
59 } libscsi_action_impl_t;
60 
61 struct libscsi_hdl {
62 	uint_t lsh_version;
63 	libscsi_errno_t lsh_errno;
64 	char lsh_errmsg[LIBSCSI_ERRMSGLEN];
65 	libscsi_engine_impl_t *lsh_engines;
66 	uint_t lsh_targets;
67 };
68 
69 struct libscsi_target {
70 	const libscsi_engine_t *lst_engine;
71 	char *lst_vendor;
72 	char *lst_product;
73 	char *lst_revision;
74 	void *lst_priv;
75 	uint_t lst_mtbf_cdb;
76 	uint_t lst_mtbf_read;
77 	uint_t lst_mtbf_write;
78 	struct libscsi_hdl *lst_hdl;
79 };
80 
81 #define	VERIFY(x)	((void)((x) || libscsi_assert(#x, __FILE__, __LINE__)))
82 
83 #ifdef DEBUG
84 #define	ASSERT(x)	VERIFY(x)
85 #else
86 #define	ASSERT(x)
87 #endif
88 
89 #define	LXOR(l, r)	(((l) != 0) ^ ((r) != 0))
90 
91 extern int libscsi_assert(const char *, const char *, int);
92 extern int libscsi_get_inquiry(struct libscsi_hdl *, struct libscsi_target *);
93 
94 #ifdef	__cplusplus
95 }
96 #endif
97 
98 #endif	/* _LIBSCSI_IMPL_H */
99