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