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