xref: /onnv-gate/usr/src/lib/scsi/libsmp/common/libsmp_plugin.h (revision 12126:60364f3f65c7)
1*12126SHyon.Kim@Sun.COM /*
2*12126SHyon.Kim@Sun.COM  * CDDL HEADER START
3*12126SHyon.Kim@Sun.COM  *
4*12126SHyon.Kim@Sun.COM  * The contents of this file are subject to the terms of the
5*12126SHyon.Kim@Sun.COM  * Common Development and Distribution License (the "License").
6*12126SHyon.Kim@Sun.COM  * You may not use this file except in compliance with the License.
7*12126SHyon.Kim@Sun.COM  *
8*12126SHyon.Kim@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*12126SHyon.Kim@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*12126SHyon.Kim@Sun.COM  * See the License for the specific language governing permissions
11*12126SHyon.Kim@Sun.COM  * and limitations under the License.
12*12126SHyon.Kim@Sun.COM  *
13*12126SHyon.Kim@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*12126SHyon.Kim@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*12126SHyon.Kim@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*12126SHyon.Kim@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*12126SHyon.Kim@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*12126SHyon.Kim@Sun.COM  *
19*12126SHyon.Kim@Sun.COM  * CDDL HEADER END
20*12126SHyon.Kim@Sun.COM  */
21*12126SHyon.Kim@Sun.COM 
22*12126SHyon.Kim@Sun.COM /*
23*12126SHyon.Kim@Sun.COM  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24*12126SHyon.Kim@Sun.COM  */
25*12126SHyon.Kim@Sun.COM 
26*12126SHyon.Kim@Sun.COM #ifndef	_LIBSMP_PLUGIN_H
27*12126SHyon.Kim@Sun.COM #define	_LIBSMP_PLUGIN_H
28*12126SHyon.Kim@Sun.COM 
29*12126SHyon.Kim@Sun.COM #ifdef	__cplusplus
30*12126SHyon.Kim@Sun.COM extern "C" {
31*12126SHyon.Kim@Sun.COM #endif
32*12126SHyon.Kim@Sun.COM 
33*12126SHyon.Kim@Sun.COM #include <sys/scsi/generic/smp_frames.h>
34*12126SHyon.Kim@Sun.COM #include <scsi/libsmp.h>
35*12126SHyon.Kim@Sun.COM 
36*12126SHyon.Kim@Sun.COM #include <stddef.h>
37*12126SHyon.Kim@Sun.COM 
38*12126SHyon.Kim@Sun.COM #define	LIBSMP_PLUGIN_VERSION	1
39*12126SHyon.Kim@Sun.COM #define	LIBSMP_ENGINE_VERSION	1
40*12126SHyon.Kim@Sun.COM 
41*12126SHyon.Kim@Sun.COM #ifndef SMP_REQ_MINLEN
42*12126SHyon.Kim@Sun.COM #define	SMP_REQ_MINLEN	\
43*12126SHyon.Kim@Sun.COM 	(offsetof(smp_request_frame_t, srf_data[0]) + sizeof (smp_crc_t))
44*12126SHyon.Kim@Sun.COM #endif
45*12126SHyon.Kim@Sun.COM #ifndef	SMP_RESP_MINLEN
46*12126SHyon.Kim@Sun.COM #define	SMP_RESP_MINLEN	\
47*12126SHyon.Kim@Sun.COM 	(offsetof(smp_response_frame_t, srf_data[0]) + sizeof (smp_crc_t))
48*12126SHyon.Kim@Sun.COM #endif
49*12126SHyon.Kim@Sun.COM 
50*12126SHyon.Kim@Sun.COM #define	VERIFY(x)	((void)((x) || smp_assert(#x, __FILE__, __LINE__)))
51*12126SHyon.Kim@Sun.COM 
52*12126SHyon.Kim@Sun.COM #ifdef DEBUG
53*12126SHyon.Kim@Sun.COM #define	ASSERT(x)	VERIFY(x)
54*12126SHyon.Kim@Sun.COM #else
55*12126SHyon.Kim@Sun.COM #define	ASSERT(x)
56*12126SHyon.Kim@Sun.COM #endif
57*12126SHyon.Kim@Sun.COM 
58*12126SHyon.Kim@Sun.COM struct smp_engine;
59*12126SHyon.Kim@Sun.COM typedef struct smp_engine smp_engine_t;
60*12126SHyon.Kim@Sun.COM 
61*12126SHyon.Kim@Sun.COM struct smp_plugin;
62*12126SHyon.Kim@Sun.COM typedef struct smp_plugin smp_plugin_t;
63*12126SHyon.Kim@Sun.COM 
64*12126SHyon.Kim@Sun.COM typedef struct smp_engine_ops {
65*12126SHyon.Kim@Sun.COM 	void *(*seo_open)(const void *);
66*12126SHyon.Kim@Sun.COM 	void (*seo_close)(void *);
67*12126SHyon.Kim@Sun.COM 	int (*seo_exec)(void *, smp_action_t *);
68*12126SHyon.Kim@Sun.COM 	void (*seo_target_name)(void *, char *, size_t);
69*12126SHyon.Kim@Sun.COM 	uint64_t (*seo_target_addr)(void *);
70*12126SHyon.Kim@Sun.COM } smp_engine_ops_t;
71*12126SHyon.Kim@Sun.COM 
72*12126SHyon.Kim@Sun.COM typedef struct smp_engine_config {
73*12126SHyon.Kim@Sun.COM 	const char *sec_name;
74*12126SHyon.Kim@Sun.COM 	const smp_engine_ops_t *sec_ops;
75*12126SHyon.Kim@Sun.COM } smp_engine_config_t;
76*12126SHyon.Kim@Sun.COM 
77*12126SHyon.Kim@Sun.COM #define	SMP_FD_F_NEEDS_CHANGE_COUNT	0x0001
78*12126SHyon.Kim@Sun.COM #define	SMP_FD_F_PROVIDES_CHANGE_COUNT	0x0002
79*12126SHyon.Kim@Sun.COM #define	SMP_FD_F_READ			0x0004
80*12126SHyon.Kim@Sun.COM #define	SMP_FD_F_WRITE			0x0008
81*12126SHyon.Kim@Sun.COM 
82*12126SHyon.Kim@Sun.COM typedef struct smp_function_def {
83*12126SHyon.Kim@Sun.COM 	smp_function_t sfd_function;
84*12126SHyon.Kim@Sun.COM 	uint_t sfd_capmask;
85*12126SHyon.Kim@Sun.COM 	uint_t sfd_capset;
86*12126SHyon.Kim@Sun.COM 	uint_t sfd_flags;
87*12126SHyon.Kim@Sun.COM 	size_t (*sfd_rq_len)(size_t, smp_target_t *);
88*12126SHyon.Kim@Sun.COM 	off_t (*sfd_rq_dataoff)(smp_action_t *, smp_target_t *);
89*12126SHyon.Kim@Sun.COM 	void (*sfd_rq_setframe)(smp_action_t *, smp_target_t *);
90*12126SHyon.Kim@Sun.COM 	size_t (*sfd_rs_datalen)(smp_action_t *, smp_target_t *);
91*12126SHyon.Kim@Sun.COM 	off_t (*sfd_rs_dataoff)(smp_action_t *, smp_target_t *);
92*12126SHyon.Kim@Sun.COM 	void (*sfd_rs_getparams)(smp_action_t *, smp_target_t *);
93*12126SHyon.Kim@Sun.COM } smp_function_def_t;
94*12126SHyon.Kim@Sun.COM 
95*12126SHyon.Kim@Sun.COM typedef struct smp_plugin_config {
96*12126SHyon.Kim@Sun.COM 	const char *spc_name;
97*12126SHyon.Kim@Sun.COM 	smp_function_def_t *spc_functions;
98*12126SHyon.Kim@Sun.COM } smp_plugin_config_t;
99*12126SHyon.Kim@Sun.COM 
100*12126SHyon.Kim@Sun.COM extern int smp_assert(const char *, const char *, int);
101*12126SHyon.Kim@Sun.COM 
102*12126SHyon.Kim@Sun.COM extern void *smp_alloc(size_t);
103*12126SHyon.Kim@Sun.COM extern void *smp_zalloc(size_t);
104*12126SHyon.Kim@Sun.COM extern char *smp_strdup(const char *);
105*12126SHyon.Kim@Sun.COM extern void smp_free(void *);
106*12126SHyon.Kim@Sun.COM 
107*12126SHyon.Kim@Sun.COM extern int smp_set_errno(smp_errno_t);
108*12126SHyon.Kim@Sun.COM extern int smp_verror(smp_errno_t, const char *, va_list);
109*12126SHyon.Kim@Sun.COM extern int smp_error(smp_errno_t, const char *, ...);
110*12126SHyon.Kim@Sun.COM 
111*12126SHyon.Kim@Sun.COM extern void smp_action_get_request_frame(const smp_action_t *,
112*12126SHyon.Kim@Sun.COM     void **, size_t *);
113*12126SHyon.Kim@Sun.COM extern void smp_action_get_response_frame(const smp_action_t *,
114*12126SHyon.Kim@Sun.COM     void **, size_t *);
115*12126SHyon.Kim@Sun.COM extern void smp_action_set_response_len(smp_action_t *, size_t);
116*12126SHyon.Kim@Sun.COM extern void smp_action_set_result(smp_action_t *, smp_result_t);
117*12126SHyon.Kim@Sun.COM extern const smp_function_def_t *smp_action_get_function_def(
118*12126SHyon.Kim@Sun.COM     const smp_action_t *);
119*12126SHyon.Kim@Sun.COM 
120*12126SHyon.Kim@Sun.COM extern int smp_engine_register(smp_engine_t *, int,
121*12126SHyon.Kim@Sun.COM     const smp_engine_config_t *);
122*12126SHyon.Kim@Sun.COM 
123*12126SHyon.Kim@Sun.COM extern int smp_plugin_register(smp_plugin_t *, int,
124*12126SHyon.Kim@Sun.COM     const smp_plugin_config_t *);
125*12126SHyon.Kim@Sun.COM extern void smp_plugin_setspecific(smp_plugin_t *, void *);
126*12126SHyon.Kim@Sun.COM extern void *smp_plugin_getspecific(smp_plugin_t *);
127*12126SHyon.Kim@Sun.COM 
128*12126SHyon.Kim@Sun.COM #ifdef	__cplusplus
129*12126SHyon.Kim@Sun.COM }
130*12126SHyon.Kim@Sun.COM #endif
131*12126SHyon.Kim@Sun.COM 
132*12126SHyon.Kim@Sun.COM #endif	/* _LIBSMP_PLUGIN_H */
133