xref: /titanic_52/usr/src/lib/scsi/libses/common/libses_plugin.h (revision 826ac02a0def83e0a41b29321470d299c7389aab)
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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef	_LIBSES_PLUGIN_H
27 #define	_LIBSES_PLUGIN_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #define	LIBSES_PLUGIN_VERSION	1
34 
35 /*
36  * These are the primary APIs for plugins to interact with libses.
37  */
38 
39 struct ses_plugin;
40 typedef struct ses_plugin ses_plugin_t;
41 
42 typedef enum {
43 	SES_PAGE_DIAG,
44 	SES_PAGE_CTL
45 } ses_pagetype_t;
46 
47 typedef enum ses_page_req {
48 	SES_REQ_OPTIONAL,
49 	SES_REQ_MANDATORY_ALL,
50 	SES_REQ_MANDATORY_STANDARD,
51 	SES_REQ_OPTIONAL_STANDARD
52 } ses_page_req_t;
53 
54 typedef struct ses_pagedesc {
55 	int		spd_pagenum;
56 	size_t		(*spd_ctl_len)(uint_t, int, size_t);
57 	void		*(*spd_ctl_fill)(ses_plugin_t *, void *, size_t,
58 	    ses_node_t *);
59 	void		*(*spd_index)(ses_plugin_t *, ses_node_t *,
60 	    void *, size_t, size_t *);
61 	int		spd_gcoff;
62 	ses_page_req_t	spd_req;
63 } ses_pagedesc_t;
64 
65 typedef struct ses_plugin_config {
66 	ses_pagedesc_t	*spc_pages;
67 	int		(*spc_node_parse)(ses_plugin_t *, ses_node_t *);
68 	int		(*spc_node_ctl)(ses_plugin_t *, ses_node_t *,
69 	    const char *, nvlist_t *);
70 } ses_plugin_config_t;
71 
72 extern int ses_plugin_register(ses_plugin_t *, int, ses_plugin_config_t *);
73 
74 extern void *ses_plugin_page_lookup(ses_plugin_t *, ses_snap_t *, int,
75     ses_node_t *, size_t *);
76 
77 extern void *ses_plugin_ctlpage_lookup(ses_plugin_t *, ses_snap_t *, int,
78     size_t, ses_node_t *, boolean_t);
79 
80 extern void ses_plugin_setspecific(ses_plugin_t *, void *);
81 extern void *ses_plugin_getspecific(ses_plugin_t *);
82 
83 /*
84  * The following are support functions provided by libses.
85  */
86 
87 extern int ses_assert(const char *, const char *, int);
88 
89 #define	VERIFY(x)	((void)((x) || ses_assert(#x, __FILE__, __LINE__)))
90 
91 #ifdef DEBUG
92 #define	ASSERT(x)	VERIFY(x)
93 #else
94 #define	ASSERT(x)
95 #endif
96 
97 #define	SES_NV_ADD(_t, _e, _l, _n, ...)	\
98 	if (((_e) = nvlist_add_##_t((_l), (_n), __VA_ARGS__)) != 0) \
99 	    return (ses_set_nverrno((_e), (_n)))
100 
101 #define	SES_NV_ADD_OR_FREE(_t, _e, _l, _n, ...)	\
102 	if (((_e) = nvlist_add_##_t((_l), (_n), __VA_ARGS__)) != 0) { \
103 	    nvlist_free(_l); return (ses_set_nverrno((_e), (_n))); }
104 
105 #define	SES_NV_ADD_FS(_e, _l, _name, _buf)	\
106 	SES_NV_ADD(fixed_string, (_e), (_l), (_name), (_buf), sizeof (_buf))
107 
108 #define	SES_NV_ADD_FS_TRUNC(_e, _l, _name, _buf)	\
109 	SES_NV_ADD(fixed_string_trunc, (_e), (_l), (_name), (_buf), \
110 	    sizeof (_buf))
111 
112 #define	SES_NV_CTLBOOL(_l, _n, _b)	\
113 	{	\
114 		boolean_t v = B_FALSE;	\
115 		(void) nvlist_lookup_boolean_value((_l), (_n), &v);	\
116 		(_b) = v;	\
117 	}
118 
119 #define	SES_NV_CTLBOOL_INVERT(_l, _n, _b)	\
120 	{	\
121 		boolean_t v = B_FALSE;	\
122 		(void) nvlist_lookup_boolean_value((_l), (_n), &v);	\
123 		(_b) = !v;	\
124 	}
125 
126 #define	SES_NV_CTL64(_l, _n, _v)	\
127 	{	\
128 		uint64_t v = 0;	\
129 		(void) nvlist_lookup_uint64((_l), (_n), &v);	\
130 		(_v) = v;	\
131 	}
132 
133 #define	SES_NV_CTL16(_l, _n, _v)	\
134 	{	\
135 		uint16_t v = 0;	\
136 		(void) nvlist_lookup_uint16((_l), (_n), &v);	\
137 		SCSI_WRITE16(&(_v), v);	\
138 	}
139 
140 extern void *ses_alloc(size_t);
141 extern void *ses_zalloc(size_t);
142 extern char *ses_strdup(const char *);
143 extern void *ses_realloc(void *, size_t);
144 extern void ses_free(void *);
145 
146 extern int ses_set_errno(ses_errno_t);
147 extern int ses_set_nverrno(int, const char *);
148 extern int ses_error(ses_errno_t, const char *, ...);
149 extern int ses_nverror(int, const char *, const char *, ...);
150 extern void ses_panic(const char *, ...) __NORETURN;
151 
152 extern int nvlist_add_fixed_string(nvlist_t *, const char *,
153     const char *, size_t);
154 extern int nvlist_add_fixed_string_trunc(nvlist_t *, const char *,
155     const char *, size_t);
156 
157 #define	SES_WITHIN_PAGE(sp, size, data, len)	\
158 	((char *)(sp) <= (char *)(data) + (len) - (size))
159 #define	SES_WITHIN_PAGE_STRUCT(sp, data, len)	\
160 	SES_WITHIN_PAGE((sp), sizeof (*(sp)), (data), (len))
161 
162 #ifdef	__cplusplus
163 }
164 #endif
165 
166 #endif	/* _LIBSES_PLUGIN_H */
167