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