xref: /titanic_52/usr/src/cmd/fm/fmd/common/fmd_api.h (revision e4f5a11d4a234623168c1558fcdf4341e11769e1)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_FMD_API_H
28 #define	_FMD_API_H
29 
30 #include <sys/types.h>
31 #include <libnvpair.h>
32 #include <stdarg.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Fault Management Daemon Client Interfaces
40  *
41  * Note: The contents of this file are private to the implementation of the
42  * Solaris system and FMD subsystem and are subject to change at any time
43  * without notice.  Applications and drivers using these interfaces will fail
44  * to run on future releases.  These interfaces should not be used for any
45  * purpose until they are publicly documented for use outside of Sun.
46  */
47 
48 #define	FMD_API_VERSION_1	1
49 #define	FMD_API_VERSION_2	2
50 #define	FMD_API_VERSION_3	3
51 #define	FMD_API_VERSION_4	4
52 
53 #define	FMD_API_VERSION		FMD_API_VERSION_4
54 
55 typedef struct fmd_hdl fmd_hdl_t;
56 typedef struct fmd_event fmd_event_t;
57 typedef struct fmd_case fmd_case_t;
58 typedef struct fmd_xprt fmd_xprt_t;
59 
60 struct topo_hdl;
61 
62 #define	FMD_B_FALSE	0		/* false value for booleans as int */
63 #define	FMD_B_TRUE	1		/* true value for booleans as int */
64 
65 #ifndef	MIN
66 #define	MIN(x, y) ((x) < (y) ? (x) : (y))
67 #endif
68 
69 #ifndef	MAX
70 #define	MAX(x, y) ((x) > (y) ? (x) : (y))
71 #endif
72 
73 #define	FMD_TYPE_BOOL	0		/* int */
74 #define	FMD_TYPE_INT32	1		/* int32_t */
75 #define	FMD_TYPE_UINT32	2		/* uint32_t */
76 #define	FMD_TYPE_INT64	3		/* int64_t */
77 #define	FMD_TYPE_UINT64	4		/* uint64_t */
78 #define	FMD_TYPE_STRING	5		/* const char* */
79 #define	FMD_TYPE_TIME	6		/* uint64_t */
80 #define	FMD_TYPE_SIZE	7		/* uint64_t */
81 
82 typedef struct fmd_prop {
83 	const char *fmdp_name;		/* property name */
84 	uint_t fmdp_type;		/* property type (see above) */
85 	const char *fmdp_defv;		/* default value */
86 } fmd_prop_t;
87 
88 typedef struct fmd_stat {
89 	char fmds_name[32];		/* statistic name */
90 	uint_t fmds_type;		/* statistic type (see above) */
91 	char fmds_desc[64];		/* statistic description */
92 	union {
93 		int bool;		/* FMD_TYPE_BOOL */
94 		int32_t i32;		/* FMD_TYPE_INT32 */
95 		uint32_t ui32;		/* FMD_TYPE_UINT32 */
96 		int64_t i64;		/* FMD_TYPE_INT64 */
97 		uint64_t ui64;		/* FMD_TYPE_UINT64, TIME, SIZE */
98 		char *str;		/* FMD_TYPE_STRING */
99 	} fmds_value;
100 } fmd_stat_t;
101 
102 typedef struct fmd_hdl_ops {
103 	void (*fmdo_recv)(fmd_hdl_t *, fmd_event_t *, nvlist_t *, const char *);
104 	void (*fmdo_timeout)(fmd_hdl_t *, id_t, void *);
105 	void (*fmdo_close)(fmd_hdl_t *, fmd_case_t *);
106 	void (*fmdo_stats)(fmd_hdl_t *);
107 	void (*fmdo_gc)(fmd_hdl_t *);
108 	int (*fmdo_send)(fmd_hdl_t *, fmd_xprt_t *, fmd_event_t *, nvlist_t *);
109 	void (*fmdo_topo)(fmd_hdl_t *, struct topo_hdl *);
110 } fmd_hdl_ops_t;
111 
112 #define	FMD_SEND_SUCCESS	0	/* fmdo_send queued event */
113 #define	FMD_SEND_FAILED		1	/* fmdo_send unrecoverable error */
114 #define	FMD_SEND_RETRY		2	/* fmdo_send requests retry */
115 
116 typedef struct fmd_hdl_info {
117 	const char *fmdi_desc;		/* fmd client description string */
118 	const char *fmdi_vers;		/* fmd client version string */
119 	const fmd_hdl_ops_t *fmdi_ops;	/* ops vector for client */
120 	const fmd_prop_t *fmdi_props;	/* array of configuration props */
121 } fmd_hdl_info_t;
122 
123 extern void _fmd_init(fmd_hdl_t *);
124 extern void _fmd_fini(fmd_hdl_t *);
125 
126 extern int fmd_hdl_register(fmd_hdl_t *, int, const fmd_hdl_info_t *);
127 extern void fmd_hdl_unregister(fmd_hdl_t *);
128 
129 extern void fmd_hdl_subscribe(fmd_hdl_t *, const char *);
130 extern void fmd_hdl_unsubscribe(fmd_hdl_t *, const char *);
131 
132 extern void fmd_hdl_setspecific(fmd_hdl_t *, void *);
133 extern void *fmd_hdl_getspecific(fmd_hdl_t *);
134 
135 extern void fmd_hdl_opendict(fmd_hdl_t *, const char *);
136 extern struct topo_hdl *fmd_hdl_topo_hold(fmd_hdl_t *, int);
137 extern void fmd_hdl_topo_rele(fmd_hdl_t *, struct topo_hdl *);
138 
139 #define	FMD_NOSLEEP		0x0	/* do not sleep or retry on failure */
140 #define	FMD_SLEEP		0x1	/* sleep or retry if alloc fails */
141 
142 extern void *fmd_hdl_alloc(fmd_hdl_t *, size_t, int);
143 extern void *fmd_hdl_zalloc(fmd_hdl_t *, size_t, int);
144 extern void fmd_hdl_free(fmd_hdl_t *, void *, size_t);
145 
146 extern char *fmd_hdl_strdup(fmd_hdl_t *, const char *, int);
147 extern void fmd_hdl_strfree(fmd_hdl_t *, char *);
148 
149 extern void fmd_hdl_vabort(fmd_hdl_t *, const char *, va_list) __NORETURN;
150 extern void fmd_hdl_abort(fmd_hdl_t *, const char *, ...) __NORETURN;
151 
152 extern void fmd_hdl_verror(fmd_hdl_t *, const char *, va_list);
153 extern void fmd_hdl_error(fmd_hdl_t *, const char *, ...);
154 
155 extern void fmd_hdl_vdebug(fmd_hdl_t *, const char *, va_list);
156 extern void fmd_hdl_debug(fmd_hdl_t *, const char *, ...);
157 
158 extern int32_t fmd_prop_get_int32(fmd_hdl_t *, const char *);
159 extern int64_t fmd_prop_get_int64(fmd_hdl_t *, const char *);
160 extern char *fmd_prop_get_string(fmd_hdl_t *, const char *);
161 extern void fmd_prop_free_string(fmd_hdl_t *, char *);
162 
163 #define	FMD_STAT_NOALLOC	0x0	/* fmd should use caller's memory */
164 #define	FMD_STAT_ALLOC		0x1	/* fmd should allocate stats memory */
165 
166 extern fmd_stat_t *fmd_stat_create(fmd_hdl_t *, uint_t, uint_t, fmd_stat_t *);
167 extern void fmd_stat_destroy(fmd_hdl_t *, uint_t, fmd_stat_t *);
168 extern void fmd_stat_setstr(fmd_hdl_t *, fmd_stat_t *, const char *);
169 
170 extern fmd_case_t *fmd_case_open(fmd_hdl_t *, void *);
171 extern void fmd_case_reset(fmd_hdl_t *, fmd_case_t *);
172 extern void fmd_case_solve(fmd_hdl_t *, fmd_case_t *);
173 extern void fmd_case_close(fmd_hdl_t *, fmd_case_t *);
174 
175 extern const char *fmd_case_uuid(fmd_hdl_t *, fmd_case_t *);
176 extern fmd_case_t *fmd_case_uulookup(fmd_hdl_t *, const char *);
177 extern void fmd_case_uuclose(fmd_hdl_t *, const char *);
178 extern int fmd_case_uuclosed(fmd_hdl_t *, const char *);
179 extern void fmd_case_uuresolved(fmd_hdl_t *, const char *);
180 
181 extern int fmd_case_solved(fmd_hdl_t *, fmd_case_t *);
182 extern int fmd_case_closed(fmd_hdl_t *, fmd_case_t *);
183 
184 extern void fmd_case_add_ereport(fmd_hdl_t *, fmd_case_t *, fmd_event_t *);
185 extern void fmd_case_add_serd(fmd_hdl_t *, fmd_case_t *, const char *);
186 extern void fmd_case_add_suspect(fmd_hdl_t *, fmd_case_t *, nvlist_t *);
187 
188 extern void fmd_case_setspecific(fmd_hdl_t *, fmd_case_t *, void *);
189 extern void *fmd_case_getspecific(fmd_hdl_t *, fmd_case_t *);
190 
191 extern void fmd_case_setprincipal(fmd_hdl_t *, fmd_case_t *, fmd_event_t *);
192 extern fmd_event_t *fmd_case_getprincipal(fmd_hdl_t *, fmd_case_t *);
193 
194 extern fmd_case_t *fmd_case_next(fmd_hdl_t *, fmd_case_t *);
195 extern fmd_case_t *fmd_case_prev(fmd_hdl_t *, fmd_case_t *);
196 
197 extern void fmd_buf_create(fmd_hdl_t *, fmd_case_t *, const char *, size_t);
198 extern void fmd_buf_destroy(fmd_hdl_t *, fmd_case_t *, const char *);
199 extern void fmd_buf_read(fmd_hdl_t *, fmd_case_t *,
200     const char *, void *, size_t);
201 extern void fmd_buf_write(fmd_hdl_t *, fmd_case_t *,
202     const char *, const void *, size_t);
203 extern size_t fmd_buf_size(fmd_hdl_t *, fmd_case_t *, const char *);
204 
205 extern void fmd_serd_create(fmd_hdl_t *, const char *, uint_t, hrtime_t);
206 extern void fmd_serd_destroy(fmd_hdl_t *, const char *);
207 extern int fmd_serd_exists(fmd_hdl_t *, const char *);
208 extern void fmd_serd_reset(fmd_hdl_t *, const char *);
209 extern int fmd_serd_record(fmd_hdl_t *, const char *, fmd_event_t *);
210 extern int fmd_serd_fired(fmd_hdl_t *, const char *);
211 extern int fmd_serd_empty(fmd_hdl_t *, const char *);
212 
213 extern pthread_t fmd_thr_create(fmd_hdl_t *, void (*)(void *), void *);
214 extern void fmd_thr_destroy(fmd_hdl_t *, pthread_t);
215 extern void fmd_thr_signal(fmd_hdl_t *, pthread_t);
216 extern void fmd_thr_checkpoint(fmd_hdl_t *);
217 
218 extern id_t fmd_timer_install(fmd_hdl_t *, void *, fmd_event_t *, hrtime_t);
219 extern void fmd_timer_remove(fmd_hdl_t *, id_t);
220 
221 extern nvlist_t *fmd_nvl_create_fault(fmd_hdl_t *,
222     const char *, uint8_t, nvlist_t *, nvlist_t *, nvlist_t *);
223 
224 extern int fmd_nvl_class_match(fmd_hdl_t *, nvlist_t *, const char *);
225 extern int fmd_nvl_fmri_expand(fmd_hdl_t *, nvlist_t *);
226 extern int fmd_nvl_fmri_present(fmd_hdl_t *, nvlist_t *);
227 extern int fmd_nvl_fmri_unusable(fmd_hdl_t *, nvlist_t *);
228 extern int fmd_nvl_fmri_retire(fmd_hdl_t *, nvlist_t *);
229 extern int fmd_nvl_fmri_unretire(fmd_hdl_t *, nvlist_t *);
230 extern int fmd_nvl_fmri_replaced(fmd_hdl_t *, nvlist_t *);
231 extern int fmd_nvl_fmri_service_state(fmd_hdl_t *, nvlist_t *);
232 extern int fmd_nvl_fmri_has_fault(fmd_hdl_t *, nvlist_t *, int, char *);
233 
234 #define	FMD_HAS_FAULT_FRU	0
235 #define	FMD_HAS_FAULT_ASRU	1
236 #define	FMD_HAS_FAULT_RESOURCE	2
237 
238 extern void fmd_repair_fru(fmd_hdl_t *, const char *);
239 extern int fmd_repair_asru(fmd_hdl_t *, const char *);
240 
241 extern int fmd_nvl_fmri_contains(fmd_hdl_t *, nvlist_t *, nvlist_t *);
242 extern nvlist_t *fmd_nvl_fmri_translate(fmd_hdl_t *, nvlist_t *, nvlist_t *);
243 
244 extern nvlist_t *fmd_nvl_alloc(fmd_hdl_t *, int);
245 extern nvlist_t *fmd_nvl_dup(fmd_hdl_t *, nvlist_t *, int);
246 
247 extern int fmd_event_local(fmd_hdl_t *, fmd_event_t *);
248 extern uint64_t fmd_event_ena_create(fmd_hdl_t *);
249 
250 
251 #define	FMD_XPRT_RDONLY		0x1	/* transport is read-only */
252 #define	FMD_XPRT_RDWR		0x3	/* transport is read-write */
253 #define	FMD_XPRT_ACCEPT		0x4	/* transport is accepting connection */
254 #define	FMD_XPRT_SUSPENDED	0x8	/* transport starts suspended */
255 #define	FMD_XPRT_EXTERNAL	0x80	/* xprt is external to a chassis */
256 #define	FMD_XPRT_NO_REMOTE_REPAIR 0x100	/* xprt does not allow remote repair */
257 #define	FMD_XPRT_CACHE_AS_LOCAL 0x200	/* xprt caches fault as if local */
258 #define	FMD_XPRT_HCONLY		0x400	/* xprt only proxies hc-scheme faults */
259 #define	FMD_XPRT_HC_PRESENT_ONLY 0x800	/* only locally present hc faults */
260 
261 extern fmd_xprt_t *fmd_xprt_open(fmd_hdl_t *, uint_t, nvlist_t *, void *);
262 extern void fmd_xprt_close(fmd_hdl_t *, fmd_xprt_t *);
263 extern void fmd_xprt_post(fmd_hdl_t *, fmd_xprt_t *, nvlist_t *, hrtime_t);
264 extern void fmd_xprt_log(fmd_hdl_t *, fmd_xprt_t *, nvlist_t *, hrtime_t);
265 extern void fmd_xprt_suspend(fmd_hdl_t *, fmd_xprt_t *);
266 extern void fmd_xprt_resume(fmd_hdl_t *, fmd_xprt_t *);
267 extern int fmd_xprt_error(fmd_hdl_t *, fmd_xprt_t *);
268 extern nvlist_t *fmd_xprt_translate(fmd_hdl_t *, fmd_xprt_t *, fmd_event_t *);
269 extern void fmd_xprt_add_domain(fmd_hdl_t *, nvlist_t *, char *);
270 extern void fmd_xprt_setspecific(fmd_hdl_t *, fmd_xprt_t *, void *);
271 extern void *fmd_xprt_getspecific(fmd_hdl_t *, fmd_xprt_t *);
272 
273 #ifdef	__cplusplus
274 }
275 #endif
276 
277 #endif	/* _FMD_API_H */
278