xref: /titanic_44/usr/src/lib/scsi/libsmp/common/libsmp_plugin.h (revision 8339b41da2395f0525c46ceedfeb01961893ec44)
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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef	_LIBSMP_PLUGIN_H
27 #define	_LIBSMP_PLUGIN_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/scsi/generic/smp_frames.h>
34 #include <scsi/libsmp.h>
35 
36 #include <stddef.h>
37 
38 #define	LIBSMP_PLUGIN_VERSION	1
39 #define	LIBSMP_ENGINE_VERSION	1
40 
41 #ifndef SMP_REQ_MINLEN
42 #define	SMP_REQ_MINLEN	\
43 	(offsetof(smp_request_frame_t, srf_data[0]) + sizeof (smp_crc_t))
44 #endif
45 #ifndef	SMP_RESP_MINLEN
46 #define	SMP_RESP_MINLEN	\
47 	(offsetof(smp_response_frame_t, srf_data[0]) + sizeof (smp_crc_t))
48 #endif
49 
50 #define	VERIFY(x)	((void)((x) || smp_assert(#x, __FILE__, __LINE__)))
51 
52 #ifdef DEBUG
53 #define	ASSERT(x)	VERIFY(x)
54 #else
55 #define	ASSERT(x)
56 #endif
57 
58 struct smp_engine;
59 typedef struct smp_engine smp_engine_t;
60 
61 struct smp_plugin;
62 typedef struct smp_plugin smp_plugin_t;
63 
64 typedef struct smp_engine_ops {
65 	void *(*seo_open)(const void *);
66 	void (*seo_close)(void *);
67 	int (*seo_exec)(void *, smp_action_t *);
68 	void (*seo_target_name)(void *, char *, size_t);
69 	uint64_t (*seo_target_addr)(void *);
70 } smp_engine_ops_t;
71 
72 typedef struct smp_engine_config {
73 	const char *sec_name;
74 	const smp_engine_ops_t *sec_ops;
75 } smp_engine_config_t;
76 
77 #define	SMP_FD_F_NEEDS_CHANGE_COUNT	0x0001
78 #define	SMP_FD_F_PROVIDES_CHANGE_COUNT	0x0002
79 #define	SMP_FD_F_READ			0x0004
80 #define	SMP_FD_F_WRITE			0x0008
81 
82 typedef struct smp_function_def {
83 	smp_function_t sfd_function;
84 	uint_t sfd_capmask;
85 	uint_t sfd_capset;
86 	uint_t sfd_flags;
87 	size_t (*sfd_rq_len)(size_t, smp_target_t *);
88 	off_t (*sfd_rq_dataoff)(smp_action_t *, smp_target_t *);
89 	void (*sfd_rq_setframe)(smp_action_t *, smp_target_t *);
90 	size_t (*sfd_rs_datalen)(smp_action_t *, smp_target_t *);
91 	off_t (*sfd_rs_dataoff)(smp_action_t *, smp_target_t *);
92 	void (*sfd_rs_getparams)(smp_action_t *, smp_target_t *);
93 } smp_function_def_t;
94 
95 typedef struct smp_plugin_config {
96 	const char *spc_name;
97 	smp_function_def_t *spc_functions;
98 } smp_plugin_config_t;
99 
100 extern int smp_assert(const char *, const char *, int);
101 
102 extern void *smp_alloc(size_t);
103 extern void *smp_zalloc(size_t);
104 extern char *smp_strdup(const char *);
105 extern void smp_free(void *);
106 
107 extern int smp_set_errno(smp_errno_t);
108 extern int smp_verror(smp_errno_t, const char *, va_list);
109 extern int smp_error(smp_errno_t, const char *, ...);
110 
111 extern void smp_action_get_request_frame(const smp_action_t *,
112     void **, size_t *);
113 extern void smp_action_get_response_frame(const smp_action_t *,
114     void **, size_t *);
115 extern void smp_action_set_response_len(smp_action_t *, size_t);
116 extern void smp_action_set_result(smp_action_t *, smp_result_t);
117 extern const smp_function_def_t *smp_action_get_function_def(
118     const smp_action_t *);
119 
120 extern int smp_engine_register(smp_engine_t *, int,
121     const smp_engine_config_t *);
122 
123 extern int smp_plugin_register(smp_plugin_t *, int,
124     const smp_plugin_config_t *);
125 extern void smp_plugin_setspecific(smp_plugin_t *, void *);
126 extern void *smp_plugin_getspecific(smp_plugin_t *);
127 
128 #ifdef	__cplusplus
129 }
130 #endif
131 
132 #endif	/* _LIBSMP_PLUGIN_H */
133