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) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 /*
26  * Copyright 2020 Joyent, Inc.
27  */
28 
29 #ifndef _LIBTOPO_H
30 #define	_LIBTOPO_H
31 
32 #include <sys/nvpair.h>
33 #include <stdio.h>
34 #include <libdevinfo.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #define	TOPO_VERSION	1	/* Library ABI Interface Version */
41 
42 typedef struct topo_hdl topo_hdl_t;
43 typedef struct topo_node tnode_t;
44 typedef struct topo_walk topo_walk_t;
45 typedef uint64_t topo_instance_t;
46 typedef uint32_t topo_version_t;
47 
48 typedef struct topo_list {
49 	struct topo_list *l_prev;
50 	struct topo_list *l_next;
51 } topo_list_t;
52 
53 typedef struct topo_faclist {
54 	topo_list_t	tf_list;
55 	tnode_t		*tf_node;
56 } topo_faclist_t;
57 
58 typedef struct topo_digraph topo_digraph_t;
59 typedef struct topo_vertex topo_vertex_t;
60 typedef struct topo_edge topo_edge_t;
61 
62 typedef struct topo_path {
63 	const char	*tsp_fmristr;
64 	nvlist_t	*tsp_fmri;
65 	topo_list_t	tsp_components;
66 } topo_path_t;
67 
68 typedef struct topo_path_component {
69 	topo_list_t	tspc_link;
70 	topo_vertex_t	*tspc_vertex;
71 } topo_path_component_t;
72 
73 /*
74  * The following functions, error codes and data structures are private
75  * to libtopo snapshot consumers and enumerator modules.
76  */
77 extern topo_hdl_t *topo_open(int, const char *, int *);
78 extern void topo_close(topo_hdl_t *);
79 extern char *topo_snap_hold(topo_hdl_t *, const char *, int *);
80 extern void topo_snap_release(topo_hdl_t *);
81 
82 /*
83  * Snapshot walker support
84  */
85 typedef int (*topo_walk_cb_t)(topo_hdl_t *, tnode_t *, void *);
86 
87 extern topo_walk_t *topo_walk_init(topo_hdl_t *, const char *, topo_walk_cb_t,
88     void *, int *);
89 extern int topo_walk_step(topo_walk_t *, int);
90 extern void topo_walk_fini(topo_walk_t *);
91 extern di_node_t topo_hdl_devinfo(topo_hdl_t *);
92 extern di_prom_handle_t topo_hdl_prominfo(topo_hdl_t *);
93 
94 /*
95  * Walk status returned from walker
96  */
97 #define	TOPO_WALK_ERR		-1
98 #define	TOPO_WALK_NEXT		0
99 #define	TOPO_WALK_TERMINATE	1
100 
101 /*
102  * Types of walks: depth-first (child) or breadth-first (sibling)
103  */
104 #define	TOPO_WALK_CHILD		0x0001
105 #define	TOPO_WALK_SIBLING	0x0002
106 
107 /*
108  * FMRI helper routines
109  */
110 extern int topo_fmri_present(topo_hdl_t *, nvlist_t *, int *);
111 extern int topo_fmri_replaced(topo_hdl_t *, nvlist_t *, int *);
112 extern int topo_fmri_contains(topo_hdl_t *, nvlist_t *, nvlist_t *, int *);
113 extern int topo_fmri_expand(topo_hdl_t *, nvlist_t *, int *);
114 extern int topo_fmri_unusable(topo_hdl_t *, nvlist_t *, int *);
115 extern int topo_fmri_service_state(topo_hdl_t *, nvlist_t *, int *);
116 extern int topo_fmri_retire(topo_hdl_t *, nvlist_t *, int *);
117 extern int topo_fmri_unretire(topo_hdl_t *, nvlist_t *, int *);
118 extern int topo_fmri_nvl2str(topo_hdl_t *, nvlist_t *, char **, int *);
119 extern int topo_fmri_str2nvl(topo_hdl_t *, const char *, nvlist_t **, int *);
120 extern int topo_fmri_asru(topo_hdl_t *, nvlist_t *, nvlist_t **, int *);
121 extern int topo_fmri_fru(topo_hdl_t *, nvlist_t *, nvlist_t **,
122     int *);
123 extern int topo_fmri_label(topo_hdl_t *, nvlist_t *, char **, int *);
124 extern int topo_fmri_serial(topo_hdl_t *, nvlist_t *, char **, int *);
125 extern int topo_fmri_compare(topo_hdl_t *, nvlist_t *, nvlist_t *, int *);
126 extern int topo_fmri_facility(topo_hdl_t *, nvlist_t *, const char *,
127     uint32_t, topo_walk_cb_t, void *, int *);
128 
129 /*
130  * Consolidation private utility functions
131  */
132 extern ulong_t topo_fmri_strhash(topo_hdl_t *, const char *);
133 extern ulong_t topo_fmri_strhash_noauth(topo_hdl_t *, const char *);
134 extern boolean_t topo_fmri_strcmp(topo_hdl_t *, const char *, const char *);
135 extern boolean_t topo_fmri_strcmp_noauth(topo_hdl_t *, const char *,
136     const char *);
137 
138 /*
139  * Topo node utilities: callable from topo_walk_step() callback or module
140  * enumeration, topo_mod_enumerate()
141  */
142 extern char *topo_node_name(tnode_t *);
143 extern topo_instance_t topo_node_instance(tnode_t *);
144 extern tnode_t *topo_node_parent(tnode_t *);
145 extern void *topo_node_private(tnode_t *);
146 extern int topo_node_flags(tnode_t *);
147 extern int topo_node_asru(tnode_t *, nvlist_t **, nvlist_t *, int *);
148 extern int topo_node_fru(tnode_t *, nvlist_t **, nvlist_t *, int *);
149 extern int topo_node_resource(tnode_t *, nvlist_t **, int *);
150 extern int topo_node_label(tnode_t *, char **, int *);
151 extern tnode_t *topo_node_lookup(tnode_t *, const char *, topo_instance_t);
152 extern int topo_method_invoke(tnode_t *node, const char *, topo_version_t,
153     nvlist_t *, nvlist_t **, int *);
154 extern boolean_t topo_method_supported(tnode_t *, const char *,
155     topo_version_t);
156 extern int topo_node_facility(topo_hdl_t *, tnode_t *, const char *,
157     uint32_t, topo_faclist_t *, int *);
158 extern int topo_node_child_walk(topo_hdl_t *, tnode_t *, topo_walk_cb_t,
159     void *, int *);
160 extern int topo_node_occupied(tnode_t *, boolean_t *);
161 
162 /*
163  * Node flags: denotes type of node
164  */
165 #define	TOPO_NODE_DEFAULT	0
166 #define	TOPO_NODE_FACILITY	1
167 
168 #define	TOPO_FAC_TYPE_SENSOR	"sensor"
169 #define	TOPO_FAC_TYPE_INDICATOR	"indicator"
170 
171 /*
172  * Topo property get functions
173  */
174 extern int topo_prop_get_int32(tnode_t *, const char *, const char *,
175     int32_t *, int *);
176 extern int topo_prop_get_uint32(tnode_t *, const char *, const char *,
177     uint32_t *, int *);
178 extern int topo_prop_get_int64(tnode_t *, const char *, const char *,
179     int64_t *, int *);
180 extern int topo_prop_get_uint64(tnode_t *, const char *, const char *,
181     uint64_t *, int *);
182 extern int topo_prop_get_double(tnode_t *, const char *, const char *,
183     double *, int *);
184 extern int topo_prop_get_string(tnode_t *, const char *, const char *,
185     char **, int *);
186 extern int topo_prop_get_fmri(tnode_t *, const char *, const char *,
187     nvlist_t **, int *);
188 extern int topo_prop_get_int32_array(tnode_t *, const char *, const char *,
189     int32_t **, uint_t *, int *);
190 extern int topo_prop_get_uint32_array(tnode_t *, const char *, const char *,
191     uint32_t **, uint_t *, int *);
192 extern int topo_prop_get_int64_array(tnode_t *, const char *, const char *,
193     int64_t **, uint_t *, int *);
194 extern int topo_prop_get_uint64_array(tnode_t *, const char *, const char *,
195     uint64_t **, uint_t *, int *);
196 extern int topo_prop_get_string_array(tnode_t *, const char *, const char *,
197     char ***, uint_t *, int *);
198 extern int topo_prop_get_fmri_array(tnode_t *, const char *, const char *,
199     nvlist_t ***, uint_t *, int *);
200 
201 /*
202  * Topo property set functions
203  */
204 extern int topo_prop_set_int32(tnode_t *, const char *, const char *, int,
205     int32_t, int *);
206 extern int topo_prop_set_uint32(tnode_t *, const char *, const char *, int,
207     uint32_t, int *);
208 extern int topo_prop_set_int64(tnode_t *, const char *, const char *,
209     int, int64_t, int *);
210 extern int topo_prop_set_uint64(tnode_t *, const char *, const char *,
211     int, uint64_t, int *);
212 extern int topo_prop_set_double(tnode_t *, const char *, const char *,
213     int, double, int *);
214 extern int topo_prop_set_string(tnode_t *, const char *, const char *,
215     int, const char *, int *);
216 extern int topo_prop_set_fmri(tnode_t *, const char *, const char *,
217     int, const nvlist_t *, int *);
218 extern int topo_prop_set_int32_array(tnode_t *, const char *, const char *, int,
219     int32_t *, uint_t, int *);
220 extern int topo_prop_set_uint32_array(tnode_t *, const char *, const char *,
221     int, uint32_t *, uint_t, int *);
222 extern int topo_prop_set_int64_array(tnode_t *, const char *, const char *,
223     int, int64_t *, uint_t, int *);
224 extern int topo_prop_set_uint64_array(tnode_t *, const char *, const char *,
225     int, uint64_t *, uint_t, int *);
226 extern int topo_prop_set_string_array(tnode_t *, const char *, const char *,
227     int, const char **, uint_t, int *);
228 extern int topo_prop_set_fmri_array(tnode_t *, const char *, const char *,
229     int, const nvlist_t **, uint_t, int *);
230 
231 #define	TOPO_PROP_IMMUTABLE	0
232 #define	TOPO_PROP_MUTABLE	0x01
233 #define	TOPO_PROP_NONVOLATILE	0x02
234 
235 /* Protocol property group and property names */
236 #define	TOPO_PGROUP_PROTOCOL	"protocol"	/* Required property group */
237 #define	TOPO_PROP_RESOURCE	"resource"	/* resource FMRI */
238 #define	TOPO_PROP_ASRU		"ASRU"		/* ASRU FMRI */
239 #define	TOPO_PROP_FRU		"FRU"		/* FRU FMRI */
240 #define	TOPO_PROP_MOD		"module"	/* software module FMRI */
241 #define	TOPO_PROP_PKG		"package"	/* software package FMRI */
242 #define	TOPO_PROP_LABEL		"label"		/*  property LABEL */
243 
244 #define	TOPO_METH_FAC_ENUM	"fac_enum"
245 
246 /*
247  * System property group
248  */
249 #define	TOPO_PGROUP_SYSTEM	"system"
250 #define	TOPO_PROP_ISA		"isa"
251 #define	TOPO_PROP_MACHINE	"machine"
252 
253 #define	TOPO_PGROUP_IPMI	"ipmi"
254 
255 /*
256  * These enum definitions are used to define a set of error tags associated with
257  * libtopo error conditions occuring during the adminstration of
258  * properties, invocation of methods and fmri-based queries.  The shell script
259  * mkerror.sh is used to parse this file and create a corresponding topo_error.c
260  * source file.
261  *
262  * If you do something other than add a new error tag here, you may need to
263  * update the mkerror shell script as it is based upon simple regexps.
264  */
265 typedef enum topo_prop_errno {
266     ETOPO_PROP_UNKNOWN = 3000, /* unknown topo prop error */
267     ETOPO_PROP_NOENT,   /* undefined property or property group */
268     ETOPO_PROP_DEFD,    /* static property already defined */
269     ETOPO_PROP_NOMEM,   /* memory limit exceeded during property allocation */
270     ETOPO_PROP_TYPE,    /* invalid property type */
271     ETOPO_PROP_NAME,    /* invalid property name */
272     ETOPO_PROP_NOINHERIT, /* can not inherit property */
273     ETOPO_PROP_NVL,	/* malformed property nvlist */
274     ETOPO_PROP_METHOD,	/* get property method failed */
275     ETOPO_PROP_END	/* end of prop errno list (to ease auto-merge) */
276 } topo_prop_errno_t;
277 
278 typedef enum topo_method_errno {
279     ETOPO_METHOD_UNKNOWN = 3100, /* unknown topo method error */
280     ETOPO_METHOD_INVAL,		/* invalid method registration */
281     ETOPO_METHOD_NOTSUP,	/* method not supported */
282     ETOPO_METHOD_FAIL,		/* method failed */
283     ETOPO_METHOD_VEROLD,	/* app is compiled to use obsolete method */
284     ETOPO_METHOD_VERNEW,	/* app is compiled to use obsolete method */
285     ETOPO_METHOD_NOMEM,		/* memory limit exceeded during method op */
286     ETOPO_METHOD_DEFD,		/* method op already defined */
287     ETOPO_METHOD_END		/* end of method errno list */
288 } topo_method_errno_t;
289 
290 typedef enum topo_fmri_errno {
291     ETOPO_FMRI_UNKNOWN = 3200, /* unknown topo fmri error */
292     ETOPO_FMRI_NVL,		/* nvlist allocation failure for FMRI */
293     ETOPO_FMRI_VERSION,		/* invalid FMRI scheme version */
294     ETOPO_FMRI_MALFORM,		/* malformed FMRI */
295     ETOPO_FMRI_NOMEM,		/* memory limit exceeded */
296     ETOPO_FMRI_END		/* end of fmri errno list */
297 } topo_fmri_errno_t;
298 
299 typedef enum topo_hdl_errno {
300     ETOPO_HDL_UNKNOWN = 3300,	/* unknown topo handle error */
301     ETOPO_HDL_ABIVER,		/* handle opened with invalid ABI version */
302     ETOPO_HDL_SNAP,		/* snapshot already taken */
303     ETOPO_HDL_INVAL,		/* invalid argument specified */
304     ETOPO_HDL_UUID,		/* uuid already set */
305     ETOPO_HDL_NOMEM,		/* memory limit exceeded */
306     ETOPO_HDL_END		/* end of handle errno list */
307 } topo_hdl_errno_t;
308 
309 extern const char *topo_strerror(int);
310 extern void topo_hdl_strfree(topo_hdl_t *, char *);
311 extern void topo_hdl_strfreev(topo_hdl_t *, char **, uint_t);
312 extern void topo_debug_set(topo_hdl_t *, const char *, const char *);
313 
314 /*
315  * The following functions and data structures to support property
316  * observability are private to the fmtopo command.
317  */
318 
319 /*
320  * Each topology node advertises the name and data stability of each of its
321  * modules and properties. (see attributes(5)).
322  */
323 
324 /*
325  * Topo stability attributes
326  */
327 typedef enum topo_stability {
328 	TOPO_STABILITY_UNKNOWN = 0,	/* private to libtopo */
329 	TOPO_STABILITY_INTERNAL,	/* private to libtopo */
330 	TOPO_STABILITY_PRIVATE,		/* private to Sun */
331 	TOPO_STABILITY_OBSOLETE,	/* scheduled for removal */
332 	TOPO_STABILITY_EXTERNAL,	/* not controlled by Sun */
333 	TOPO_STABILITY_UNSTABLE,	/* new or rapidly changing */
334 	TOPO_STABILITY_EVOLVING,	/* less rapidly changing */
335 	TOPO_STABILITY_STABLE,		/* mature interface from Sun */
336 	TOPO_STABILITY_STANDARD		/* industry standard */
337 } topo_stability_t;
338 
339 #define	TOPO_STABILITY_MAX	TOPO_STABILITY_STANDARD	/* max valid stab */
340 
341 typedef struct topo_pgroup_info {
342 	const char *tpi_name;		/* property group name */
343 	topo_stability_t tpi_namestab;	/* stability of group name */
344 	topo_stability_t tpi_datastab;	/* stability of all property values */
345 	topo_version_t tpi_version;	/* version of pgroup definition */
346 } topo_pgroup_info_t;
347 
348 extern topo_stability_t topo_name2stability(const char *);
349 extern const char *topo_stability2name(topo_stability_t);
350 extern void topo_pgroup_destroy(tnode_t *, const char *);
351 extern topo_pgroup_info_t *topo_pgroup_info(tnode_t *, const char *, int *);
352 
353 typedef enum {
354 	TOPO_TYPE_INVALID = 0,
355 	TOPO_TYPE_BOOLEAN,	/* boolean */
356 	TOPO_TYPE_INT32,	/* int32_t */
357 	TOPO_TYPE_UINT32,	/* uint32_t */
358 	TOPO_TYPE_INT64,	/* int64_t */
359 	TOPO_TYPE_UINT64,	/* uint64_t */
360 	TOPO_TYPE_STRING,	/* const char* */
361 	TOPO_TYPE_TIME,		/* uint64_t */
362 	TOPO_TYPE_SIZE,		/* uint64_t */
363 	TOPO_TYPE_FMRI,		/* nvlist_t */
364 	TOPO_TYPE_INT32_ARRAY,	/* array of int32_t */
365 	TOPO_TYPE_UINT32_ARRAY,	/* array of uint32_t */
366 	TOPO_TYPE_INT64_ARRAY,	/* array of int64_t */
367 	TOPO_TYPE_UINT64_ARRAY,	/* array of uint64_t */
368 	TOPO_TYPE_STRING_ARRAY,	/* array of const char* */
369 	TOPO_TYPE_FMRI_ARRAY,	/* array of nvlist_t */
370 	TOPO_TYPE_DOUBLE	/* double */
371 } topo_type_t;
372 
373 extern nvlist_t *topo_prop_getprops(tnode_t *, int *err);
374 extern int topo_prop_getprop(tnode_t *, const char *, const char *,
375     nvlist_t *, nvlist_t **, int *);
376 extern int topo_prop_getpgrp(tnode_t *, const char *, nvlist_t **, int *);
377 extern int topo_prop_setprop(tnode_t *, const char *, nvlist_t *,
378     int, nvlist_t *, int *);
379 extern int topo_fmri_getprop(topo_hdl_t *, nvlist_t *, const char *,
380     const char *, nvlist_t *,  nvlist_t **, int *);
381 extern int topo_fmri_getpgrp(topo_hdl_t *, nvlist_t *, const char *,
382     nvlist_t **, int *);
383 extern int topo_fmri_setprop(topo_hdl_t *, nvlist_t *, const char *,
384     nvlist_t *, int, nvlist_t *, int *);
385 extern void topo_pgroup_hcset(tnode_t *, nvlist_t *);
386 
387 /* Property node NVL names used in topo_prop_getprops */
388 #define	TOPO_PROP_GROUP		"property-group"
389 #define	TOPO_PROP_GROUP_NAME	"property-group-name"
390 #define	TOPO_PROP_GROUP_DSTAB	"property-group-data-stability"
391 #define	TOPO_PROP_GROUP_NSTAB	"property-group-name-stability"
392 #define	TOPO_PROP_GROUP_VERSION	"property-group-version"
393 #define	TOPO_PROP_VAL		"property"
394 #define	TOPO_PROP_VAL_NAME	"property-name"
395 #define	TOPO_PROP_VAL_VAL	"property-value"
396 #define	TOPO_PROP_VAL_TYPE	"property-type"
397 #define	TOPO_PROP_FLAG		"property-flag"
398 
399 /*
400  * ARGS list used in topo property methods
401  */
402 #define	TOPO_PROP_ARGS	"args"
403 #define	TOPO_PROP_PARGS	"private-args"
404 
405 extern int topo_xml_print(topo_hdl_t *, FILE *, const char *scheme, int *);
406 
407 extern void *topo_hdl_alloc(topo_hdl_t *, size_t);
408 extern void *topo_hdl_zalloc(topo_hdl_t *, size_t);
409 extern void topo_hdl_free(topo_hdl_t *, void *, size_t);
410 extern int topo_hdl_nvalloc(topo_hdl_t *, nvlist_t **, uint_t);
411 extern int topo_hdl_nvdup(topo_hdl_t *, nvlist_t *, nvlist_t **);
412 extern char *topo_hdl_strdup(topo_hdl_t *, const char *);
413 
414 /*
415  * Interfaces for interacting with directed graph topologies
416  */
417 extern topo_digraph_t *topo_digraph_get(topo_hdl_t *, const char *);
418 extern int topo_vertex_iter(topo_hdl_t *, topo_digraph_t *,
419     int (*)(topo_hdl_t *, topo_vertex_t *, boolean_t, void *), void *);
420 extern tnode_t *topo_vertex_node(topo_vertex_t *);
421 extern int topo_edge_iter(topo_hdl_t *, topo_vertex_t *,
422     int (*)(topo_hdl_t *, topo_edge_t *, boolean_t, void *), void *);
423 extern int topo_digraph_paths(topo_hdl_t *, topo_digraph_t *,
424     topo_vertex_t *, topo_vertex_t *, topo_path_t ***, uint_t *);
425 extern void topo_path_destroy(topo_hdl_t *, topo_path_t *);
426 extern int topo_digraph_serialize(topo_hdl_t *, topo_digraph_t *, FILE *);
427 extern topo_digraph_t *topo_digraph_deserialize(topo_hdl_t *, const char *,
428     size_t);
429 extern topo_vertex_t *topo_node_vertex(tnode_t *);
430 
431 /*
432  * Interfaces for converting sensor/indicator types, units, states, etc to
433  * a string
434  */
435 void topo_sensor_type_name(uint32_t type, char *buf, size_t len);
436 void topo_sensor_units_name(uint8_t type, char *buf, size_t len);
437 void topo_led_type_name(uint8_t type, char *buf, size_t len);
438 void topo_led_state_name(uint8_t type, char *buf, size_t len);
439 void topo_sensor_state_name(uint32_t sensor_type, uint8_t state, char *buf,
440     size_t len);
441 
442 /*
443  * Defines for standard properties for sensors and indicators
444  */
445 #define	TOPO_PGROUP_FACILITY	"facility"
446 
447 #define	TOPO_SENSOR_READING	"reading"
448 #define	TOPO_SENSOR_STATE	"state"
449 #define	TOPO_SENSOR_CLASS	"sensor-class"
450 #define	TOPO_FACILITY_TYPE	"type"
451 #define	TOPO_SENSOR_UNITS	"units"
452 #define	TOPO_LED_MODE		"mode"
453 
454 #define	TOPO_PROP_THRESHOLD_LNC		"threshold-lower-non-critical"
455 #define	TOPO_PROP_THRESHOLD_LCR		"threshold-lower-critical"
456 #define	TOPO_PROP_THRESHOLD_LNR		"threshold-lower-non-recoverable"
457 
458 #define	TOPO_PROP_THRESHOLD_UNC		"threshold-upper-non-critical"
459 #define	TOPO_PROP_THRESHOLD_UCR		"threshold-upper-critical"
460 #define	TOPO_PROP_THRESHOLD_UNR		"threshold-upper-non-recoverable"
461 
462 /*
463  * Sensor Classes
464  *
465  * The "sensor-class" property in the "facility" propgroup on
466  * facility nodes of type "sensor" should be set to one of these
467  * two values.
468  *
469  * Threshold sensors provide an analog sensor reading via the
470  * "reading" property in the facility propgroup.  They will also
471  * provide one or more discrete states via the "state" property
472  * in the facility propgroup.
473  *
474  * Discrete sensors will not provide an analog reading by will
475  * provide one or more discrete states via the "state" property
476  * in the facility propgroup.
477  */
478 #define	TOPO_SENSOR_CLASS_THRESHOLD	"threshold"
479 #define	TOPO_SENSOR_CLASS_DISCRETE	"discrete"
480 
481 /*
482  * Sensor unit types.  We're using the unit types and corresponding
483  * codes described in section 43.17 of the IPMI 2.0 as a reference as it seems
484  * to be a reasonably comprehensive list.  This also simplifies the IPMI
485  * facility provider code since the unit type codes will map exactly to what
486  * libtopo uses (so no conversion necessary).  To allow for future growth if
487  * new unit types are added to IPMI in the future, while still allowing unit
488  * types not supported by IPMI to be represented, we include a gap between
489  * the last IPMI unit type and the first non-IPMI unit type.
490  */
491 typedef enum topo_sensor_unit {
492 	TOPO_SENSOR_UNITS_UNSPECIFIED = 0,
493 	TOPO_SENSOR_UNITS_DEGREES_C,
494 	TOPO_SENSOR_UNITS_DEGREES_F,
495 	TOPO_SENSOR_UNITS_DEGREES_K,
496 	TOPO_SENSOR_UNITS_VOLTS,
497 	TOPO_SENSOR_UNITS_AMPS,
498 	TOPO_SENSOR_UNITS_WATTS,
499 	TOPO_SENSOR_UNITS_JOULES,
500 	TOPO_SENSOR_UNITS_COULOMBS,
501 	TOPO_SENSOR_UNITS_VA,
502 	TOPO_SENSOR_UNITS_NITS,
503 	TOPO_SENSOR_UNITS_LUMEN,
504 	TOPO_SENSOR_UNITS_LUX,
505 	TOPO_SENSOR_UNITS_CANDELA,
506 	TOPO_SENSOR_UNITS_KPA,
507 	TOPO_SENSOR_UNITS_PSI,
508 
509 	TOPO_SENSOR_UNITS_NEWTON,
510 	TOPO_SENSOR_UNITS_CFM,
511 	TOPO_SENSOR_UNITS_RPM,
512 	TOPO_SENSOR_UNITS_HZ,
513 	TOPO_SENSOR_UNITS_MICROSEC,
514 	TOPO_SENSOR_UNITS_MILLISEC,
515 	TOPO_SENSOR_UNITS_SECS,
516 	TOPO_SENSOR_UNITS_MIN,
517 	TOPO_SENSOR_UNITS_HOUR,
518 	TOPO_SENSOR_UNITS_DAY,
519 	TOPO_SENSOR_UNITS_WEEK,
520 	TOPO_SENSOR_UNITS_MIL,
521 	TOPO_SENSOR_UNITS_INCHES,
522 	TOPO_SENSOR_UNITS_FEET,
523 	TOPO_SENSOR_UNITS_CUB_INCH,
524 	TOPO_SENSOR_UNITS_CUB_FEET,
525 
526 	TOPO_SENSOR_UNITS_MM,
527 	TOPO_SENSOR_UNITS_CM,
528 	TOPO_SENSOR_UNITS_METERS,
529 	TOPO_SENSOR_UNITS_CUB_CM,
530 	TOPO_SENSOR_UNITS_CUB_METER,
531 	TOPO_SENSOR_UNITS_LITERS,
532 	TOPO_SENSOR_UNITS_FLUID_OUNCE,
533 	TOPO_SENSOR_UNITS_RADIANS,
534 	TOPO_SENSOR_UNITS_STERADIANS,
535 	TOPO_SENSOR_UNITS_REVOLUTIONS,
536 	TOPO_SENSOR_UNITS_CYCLES,
537 	TOPO_SENSOR_UNITS_GRAVITIES,
538 	TOPO_SENSOR_UNITS_OUNCE,
539 	TOPO_SENSOR_UNITS_POUND,
540 	TOPO_SENSOR_UNITS_FOOT_POUND,
541 	TOPO_SENSOR_UNITS_OZ_INCH,
542 
543 	TOPO_SENSOR_UNITS_GAUSS,
544 	TOPO_SENSOR_UNITS_GILBERTS,
545 	TOPO_SENSOR_UNITS_HENRY,
546 	TOPO_SENSOR_UNITS_MILHENRY,
547 	TOPO_SENSOR_UNITS_FARAD,
548 	TOPO_SENSOR_UNITS_MICROFARAD,
549 	TOPO_SENSOR_UNITS_OHMS,
550 	TOPO_SENSOR_UNITS_SIEMENS,
551 	TOPO_SENSOR_UNITS_MOLE,
552 	TOPO_SENSOR_UNITS_BECQUEREL,
553 	TOPO_SENSOR_UNITS_PPM,
554 	TOPO_SENSOR_UNITS_RESERVED1,
555 	TOPO_SENSOR_UNITS_DECIBELS,
556 	TOPO_SENSOR_UNITS_DBA,
557 	TOPO_SENSOR_UNITS_DBC,
558 	TOPO_SENSOR_UNITS_GRAY,
559 
560 	TOPO_SENSOR_UNITS_SIEVERT,
561 	TOPO_SENSOR_UNITS_COLOR_TEMP_K,
562 	TOPO_SENSOR_UNITS_BIT,
563 	TOPO_SENSOR_UNITS_KILOBIT,
564 	TOPO_SENSOR_UNITS_MEGABIT,
565 	TOPO_SENSOR_UNITS_GIGABIT,
566 	TOPO_SENSOR_UNITS_BYTE,
567 	TOPO_SENSOR_UNITS_KILOBYTE,
568 	TOPO_SENSOR_UNITS_MEGABYTE,
569 	TOPO_SENSOR_UNITS_GIGABYTE,
570 	TOPO_SENSOR_UNITS_WORD,
571 	TOPO_SENSOR_UNITS_DWORD,
572 	TOPO_SENSOR_UNITS_QWORD,
573 	TOPO_SENSOR_UNITS_MEMLINE,
574 	TOPO_SENSOR_UNITS_HIT,
575 	TOPO_SENSOR_UNITS_MISS,
576 
577 	TOPO_SENSOR_UNITS_RETRY,
578 	TOPO_SENSOR_UNITS_RESET,
579 	TOPO_SENSOR_UNITS_OVERFLOW,
580 	TOPO_SENSOR_UNITS_UNDERRUN,
581 	TOPO_SENSOR_UNITS_COLLISION,
582 	TOPO_SENSOR_UNITS_PACKETS,
583 	TOPO_SENSOR_UNITS_MESSAGES,
584 	TOPO_SENSOR_UNITS_CHARACTERS,
585 	TOPO_SENSOR_UNITS_ERROR,
586 	TOPO_SENSOR_UNITS_CE,
587 	TOPO_SENSOR_UNITS_UE,
588 	TOPO_SENSOR_UNITS_FATAL_ERROR,
589 	TOPO_SENSOR_UNITS_GRAMS,
590 
591 	TOPO_SENSOR_UNITS_PERCENT = 512
592 } topo_sensor_unit_t;
593 
594 /*
595  * These defines are used by the topo_method_sensor_failure to indicate
596  * whether the source of a sensor failure is believed to be the result of an
597  * internal failure, external condition or unknown
598  */
599 #define	TOPO_SENSOR_ERRSRC_UNKNOWN	0
600 #define	TOPO_SENSOR_ERRSRC_INTERNAL	1
601 #define	TOPO_SENSOR_ERRSRC_EXTERNAL	2
602 
603 /*
604  * Sensor Types amd the associated sensor-type-specific states
605  *
606  * These are used to decode the type and state properties in the facility
607  * propgroup on facility nodes of type sensor.
608  *
609  * Again we're basically using the same defines as listed in the IPMI
610  * specification (see section 42) as it's serves as a good starting point and
611  * simplifies the IPMI provider code.  Of course other facility providers will
612  * need to convert from their native codes to the topo code when they set the
613  * type and state properties.
614  */
615 #define	TOPO_SENSOR_TYPE_RESERVED			0x0000
616 #define	TOPO_SENSOR_TYPE_TEMP				0x0001
617 #define	TOPO_SENSOR_TYPE_VOLTAGE			0x0002
618 #define	TOPO_SENSOR_TYPE_CURRENT			0x0003
619 #define	TOPO_SENSOR_TYPE_FAN				0x0004
620 #define	TOPO_SENSOR_TYPE_PHYSICAL			0x0005
621 
622 #define	TOPO_SENSOR_STATE_PHYSICAL_GENERAL		0x0001
623 #define	TOPO_SENSOR_STATE_PHYSICAL_BAY			0x0002
624 #define	TOPO_SENSOR_STATE_PHYSICAL_CARD			0x0004
625 #define	TOPO_SENSOR_STATE_PHYSICAL_PROCESSOR		0x0008
626 #define	TOPO_SENSOR_STATE_PHYSICAL_LAN			0x0010
627 #define	TOPO_SENSOR_STATE_PHYSICAL_DOCK			0x0020
628 #define	TOPO_SENSOR_STATE_PHYSICAL_FAN			0x0040
629 
630 #define	TOPO_SENSOR_TYPE_PLATFORM			0x0006
631 
632 #define	TOPO_SENSOR_STATE_PLATFORM_SECURE		0x0001
633 #define	TOPO_SENSOR_STATE_PLATFORM_USER_PASS		0x0002
634 #define	TOPO_SENSOR_STATE_PLATFORM_SETUP_PASS		0x0004
635 #define	TOPO_SENSOR_STATE_PLATFORM_NETWORK_PASS		0x0008
636 #define	TOPO_SENSOR_STATE_PLATFORM_OTHER_PASS		0x0010
637 #define	TOPO_SENSOR_STATE_PLATFORM_OUT_OF_BAND		0x0020
638 
639 #define	TOPO_SENSOR_TYPE_PROCESSOR			0x0007
640 
641 #define	TOPO_SENSOR_STATE_PROCESSOR_IERR		0x0001
642 #define	TOPO_SENSOR_STATE_PROCESSOR_THERMAL		0x0002
643 #define	TOPO_SENSOR_STATE_PROCESSOR_FRB1		0x0004
644 #define	TOPO_SENSOR_STATE_PROCESSOR_FRB2		0x0008
645 #define	TOPO_SENSOR_STATE_PROCESSOR_FRB3		0x0010
646 #define	TOPO_SENSOR_STATE_PROCESSOR_CONFIG		0x0020
647 #define	TOPO_SENSOR_STATE_PROCESSOR_SMBIOS		0x0040
648 #define	TOPO_SENSOR_STATE_PROCESSOR_PRESENT		0x0080
649 #define	TOPO_SENSOR_STATE_PROCESSOR_DISABLED		0x0100
650 #define	TOPO_SENSOR_STATE_PROCESSOR_TERMINATOR		0x0200
651 #define	TOPO_SENSOR_STATE_PROCESSOR_THROTTLED		0x0400
652 
653 #define	TOPO_SENSOR_TYPE_POWER_SUPPLY			0x0008
654 
655 #define	TOPO_SENSOR_STATE_POWER_SUPPLY_PRESENT		0x0001
656 #define	TOPO_SENSOR_STATE_POWER_SUPPLY_FAILURE		0x0002
657 #define	TOPO_SENSOR_STATE_POWER_SUPPLY_PREDFAIL		0x0004
658 #define	TOPO_SENSOR_STATE_POWER_SUPPLY_INPUT_LOST	0x0008
659 #define	TOPO_SENSOR_STATE_POWER_SUPPLY_INPUT_RANGE	0x0010
660 #define	TOPO_SENSOR_STATE_POWER_SUPPLY_INPUT_RANGE_PRES	0x0020
661 #define	TOPO_SENSOR_STATE_POWER_SUPPLY_CONFIG_ERR	0x0040
662 
663 #define	TOPO_SENSOR_TYPE_POWER_UNIT			0x0009
664 
665 #define	TOPO_SENSOR_STATE_POWER_UNIT_OFF		0x0001
666 #define	TOPO_SENSOR_STATE_POWER_UNIT_CYCLE		0x0002
667 #define	TOPO_SENSOR_STATE_POWER_UNIT_240_DOWN		0x0004
668 #define	TOPO_SENSOR_STATE_POWER_UNIT_INTERLOCK_DOWN	0x0008
669 #define	TOPO_SENSOR_STATE_POWER_UNIT_AC_LOST		0x0010
670 #define	TOPO_SENSOR_STATE_POWER_UNIT_SOFT_FAILURE	0x0020
671 #define	TOPO_SENSOR_STATE_POWER_UNIT_FAIL		0x0040
672 #define	TOPO_SENSOR_STATE_POWER_UNIT_PREDFAIL		0x0080
673 
674 #define	TOPO_SENSOR_TYPE_COOLING			0x000A
675 #define	TOPO_SENSOR_TYPE_OTHER				0x000B
676 
677 #define	TOPO_SENSOR_TYPE_MEMORY				0x000C
678 
679 #define	TOPO_SENSOR_STATE_MEMORY_CE			0x0001
680 #define	TOPO_SENSOR_STATE_MEMORY_UE			0x0002
681 #define	TOPO_SENSOR_STATE_MEMORY_PARITY			0x0004
682 #define	TOPO_SENSOR_STATE_MEMORY_SCRUB_FAIL		0x0008
683 #define	TOPO_SENSOR_STATE_MEMORY_DISABLED		0x0010
684 #define	TOPO_SENSOR_STATE_MEMORY_CE_LOG_LIMIT		0x0020
685 #define	TOPO_SENSOR_STATE_MEMORY_PRESENT		0x0040
686 #define	TOPO_SENSOR_STATE_MEMORY_CONFIG_ERR		0x0080
687 #define	TOPO_SENSOR_STATE_MEMORY_SPARE			0x0100
688 #define	TOPO_SENSOR_STATE_MEMORY_THROTTLED		0x0200
689 #define	TOPO_SENSOR_STATE_MEMORY_OVERTEMP		0x0400
690 
691 #define	TOPO_SENSOR_TYPE_BAY				0x000D
692 
693 #define	TOPO_SENSOR_STATE_BAY_PRESENT			0x0001
694 #define	TOPO_SENSOR_STATE_BAY_FAULT			0x0002
695 #define	TOPO_SENSOR_STATE_BAY_PREDFAIL			0x0004
696 #define	TOPO_SENSOR_STATE_BAY_SPARE			0x0008
697 #define	TOPO_SENSOR_STATE_BAY_CHECK			0x0010
698 #define	TOPO_SENSOR_STATE_BAY_CRITICAL			0x0020
699 #define	TOPO_SENSOR_STATE_BAY_FAILED			0x0040
700 #define	TOPO_SENSOR_STATE_BAY_REBUILDING		0x0080
701 #define	TOPO_SENSOR_STATE_BAY_ABORTED			0x0100
702 
703 #define	TOPO_SENSOR_TYPE_POST_RESIZE			0x000E
704 
705 #define	TOPO_SENSOR_TYPE_FIRMWARE			0x000F
706 
707 #define	TOPO_SENSOR_STATE_FIRMWARE_ERROR		0x0001
708 #define	TOPO_SENSOR_STATE_FIRMWARE_HANG			0x0002
709 #define	TOPO_SENSOR_STATE_FIRMWARE_PROGRESS		0x0004
710 
711 #define	TOPO_SENSOR_TYPE_EVENT_LOG			0x0010
712 
713 #define	TOPO_SENSOR_STATE_EVENT_LOG_CE			0x0001
714 #define	TOPO_SENSOR_STATE_EVENT_LOG_TYPE		0x0002
715 #define	TOPO_SENSOR_STATE_EVENT_LOG_RESET		0x0004
716 #define	TOPO_SENSOR_STATE_EVENT_LOG_ALL			0x0008
717 #define	TOPO_SENSOR_STATE_EVENT_LOG_FULL		0x0010
718 #define	TOPO_SENSOR_STATE_EVENT_LOG_ALMOST_FULL		0x0020
719 
720 #define	TOPO_SENSOR_TYPE_WATCHDOG1			0x0011
721 
722 #define	TOPO_SENSOR_STATE_WATCHDOG_BIOS_RESET		0x0001
723 #define	TOPO_SENSOR_STATE_WATCHDOG_OS_RESET		0x0002
724 #define	TOPO_SENSOR_STATE_WATCHDOG_OS_SHUTDOWN		0x0004
725 #define	TOPO_SENSOR_STATE_WATCHDOG_OS_PWR_DOWN		0x0008
726 #define	TOPO_SENSOR_STATE_WATCHDOG_OS_PWR_CYCLE		0x0010
727 #define	TOPO_SENSOR_STATE_WATCHDOG_OS_NMI_DIAG		0x0020
728 #define	TOPO_SENSOR_STATE_WATCHDOG_EXPIRED		0x0040
729 #define	TOPO_SENSOR_STATE_WATCHDOG_PRE_TIMEOUT_INT	0x0080
730 
731 #define	TOPO_SENSOR_TYPE_SYSTEM				0x0012
732 
733 #define	TOPO_SENSOR_STATE_SYSTEM_RECONF			0x0001
734 #define	TOPO_SENSOR_STATE_SYSTEM_BOOT			0x0002
735 #define	TOPO_SENSOR_STATE_SYSTEM_UNKNOWN_HW_FAILURE	0x0004
736 #define	TOPO_SENSOR_STATE_SYSTEM_AUX_LOG_UPDATED	0x0008
737 #define	TOPO_SENSOR_STATE_SYSTEM_PEF_ACTION		0x0010
738 #define	TOPO_SENSOR_STATE_SYSTEM_TIMETAMP_CLOCKSYNC	0x0020
739 
740 #define	TOPO_SENSOR_TYPE_CRITICAL			0x0013
741 
742 #define	TOPO_SENSOR_STATE_CRITICAL_EXT_NMI		0x0001
743 #define	TOPO_SENSOR_STATE_CRITICAL_BUS_TIMEOUT		0x0002
744 #define	TOPO_SENSOR_STATE_CRITICAL_IO_NMI		0x0004
745 #define	TOPO_SENSOR_STATE_CRITICAL_SW_NMI		0x0008
746 #define	TOPO_SENSOR_STATE_CRITICAL_PCI_PERR		0x0010
747 #define	TOPO_SENSOR_STATE_CRITICAL_PCI_SERR		0x0020
748 #define	TOPO_SENSOR_STATE_CRITICAL_EISA_FAILSAFE	0x0040
749 #define	TOPO_SENSOR_STATE_CRITICAL_BUS_CE		0x0080
750 #define	TOPO_SENSOR_STATE_CRITICAL_BUS_UE		0x0100
751 #define	TOPO_SENSOR_STATE_CRITICAL_FATAL_NMI		0x0200
752 #define	TOPO_SENSOR_STATE_CRITICAL_BUS_FATAL_ERR	0x0400
753 #define	TOPO_SENSOR_STATE_CRITICAL_BUS_DEGRADED		0x0800
754 
755 #define	TOPO_SENSOR_TYPE_BUTTON				0x0014
756 
757 #define	TOPO_SENSOR_STATE_BUTTON_PWR			0x0001
758 #define	TOPO_SENSOR_STATE_BUTTON_SLEEP			0x0002
759 #define	TOPO_SENSOR_STATE_BUTTON_RESET			0x0004
760 #define	TOPO_SENSOR_STATE_BUTTON_FRU_LATCH		0x0008
761 #define	TOPO_SENSOR_STATE_BUTTON_FRU_SERVICE		0x0010
762 
763 #define	TOPO_SENSOR_TYPE_MODULE				0x0015
764 #define	TOPO_SENSOR_TYPE_MICROCONTROLLER		0x0016
765 #define	TOPO_SENSOR_TYPE_CARD				0x0017
766 #define	TOPO_SENSOR_TYPE_CHASSIS			0x0018
767 
768 #define	TOPO_SENSOR_TYPE_CHIPSET			0x0019
769 
770 #define	TOPO_SENSOR_STATE_CHIPSET_PWR_CTL_FAIL		0x0001
771 
772 #define	TOPO_SENSOR_TYPE_FRU				0x001A
773 
774 #define	TOPO_SENSOR_TYPE_CABLE				0x001B
775 
776 #define	TOPO_SENSOR_STATE_CABLE_CONNECTED		0x0001
777 #define	TOPO_SENSOR_STATE_CABLE_CONFIG_ERR		0x0002
778 
779 #define	TOPO_SENSOR_TYPE_TERMINATOR			0x001C
780 
781 #define	TOPO_SENSOR_TYPE_BOOT_STATE			0x001D
782 
783 #define	TOPO_SENSOR_STATE_BOOT_STATE_BIOS_PWR_UP	0x0001
784 #define	TOPO_SENSOR_STATE_BOOT_STATE_BIOS_HARD_RESET	0x0002
785 #define	TOPO_SENSOR_STATE_BOOT_STATE_BIOS_WARM_RESET	0x0004
786 #define	TOPO_SENSOR_STATE_BOOT_STATE_PXE_BOOT		0x0008
787 #define	TOPO_SENSOR_STATE_BOOT_STATE_DIAG_BOOT		0x0010
788 #define	TOPO_SENSOR_STATE_BOOT_STATE_OS_HARD_RESET	0x0020
789 #define	TOPO_SENSOR_STATE_BOOT_STATE_OS_WARM_RESET	0x0040
790 #define	TOPO_SENSOR_STATE_BOOT_STATE_SYS_RESTART	0x0080
791 
792 #define	TOPO_SENSOR_TYPE_BOOT_ERROR			0x001E
793 
794 #define	TOPO_SENSOR_STATE_BOOT_ERROR_NOMEDIA		0x0001
795 #define	TOPO_SENSOR_STATE_BOOT_ERROR_NON_BOOTABLE_DISK	0x0002
796 #define	TOPO_SENSOR_STATE_BOOT_ERROR_NO_PXE_SERVER	0x0004
797 #define	TOPO_SENSOR_STATE_BOOT_ERROR_INV_BOOT_SECT	0x0008
798 #define	TOPO_SENSOR_STATE_BOOT_ERROR_USR_SELECT_TIMEOUT	0x0010
799 
800 #define	TOPO_SENSOR_TYPE_BOOT_OS			0x001F
801 
802 #define	TOPO_SENSOR_STATE_BOOT_OS_A_DRV_BOOT_COMPLETE	0x0001
803 #define	TOPO_SENSOR_STATE_BOOT_OS_C_DRV_BOOT_COMPLETE	0x0002
804 #define	TOPO_SENSOR_STATE_BOOT_OS_PXE_BOOT_COMPLETE	0x0004
805 #define	TOPO_SENSOR_STATE_BOOT_OS_DIAG_BOOT_COMPLETE	0x0008
806 #define	TOPO_SENSOR_STATE_BOOT_OS_CDROM_BOOT_COMPLETE	0x0010
807 #define	TOPO_SENSOR_STATE_BOOT_OS_ROM_BOOT_COMPLETE	0x0020
808 #define	TOPO_SENSOR_STATE_BOOT_OS_UNSPEC_BOOT_COMPLETE	0x0040
809 
810 #define	TOPO_SENSOR_TYPE_OS_SHUTDOWN			0x0020
811 
812 #define	TOPO_SENSOR_STATE_OS_SHUTDOWN_LOADING		0x0001
813 #define	TOPO_SENSOR_STATE_OS_SHUTDOWN_CRASH		0x0002
814 #define	TOPO_SENSOR_STATE_OS_STOP_GRACEFUL		0x0004
815 #define	TOPO_SENSOR_STATE_OS_SHUTDOWN_GRACEFUL		0x0008
816 #define	TOPO_SENSOR_STATE_OS_SHUTDOWN_PEF		0x0010
817 #define	TOPO_SENSOR_STATE_OS_SHUTDOWN_BMC		0x0020
818 
819 #define	TOPO_SENSOR_TYPE_SLOT				0x0021
820 
821 #define	TOPO_SENSOR_STATE_SLOT_FAULT_ASSERTED		0x0001
822 #define	TOPO_SENSOR_STATE_SLOT_IDENTIFY_ASSERTED	0x0002
823 #define	TOPO_SENSOR_STATE_SLOT_CONNECTED		0x0004
824 #define	TOPO_SENSOR_STATE_SLOT_INSTALL_READY		0x0008
825 #define	TOPO_SENSOR_STATE_SLOT_REMOVE_READY		0x0010
826 #define	TOPO_SENSOR_STATE_SLOT_PWR_OFF			0x0020
827 #define	TOPO_SENSOR_STATE_SLOT_REMOVED			0x0040
828 #define	TOPO_SENSOR_STATE_SLOT_INTERLOCK_ASSERTED	0x0080
829 #define	TOPO_SENSOR_STATE_SLOT_DISABLED			0x0100
830 #define	TOPO_SENSOR_STATE_SLOT_SPARE_DEVICE		0x0200
831 
832 #define	TOPO_SENSOR_TYPE_ACPI				0x0022
833 
834 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_S0_G0		0x0001
835 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_S1		0x0002
836 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_S2		0x0004
837 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_S3		0x0008
838 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_S4		0x0010
839 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_S5_G2_SOFT_OFF	0x0020
840 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_S4_S5_SOFT_OFF	0x0040
841 #define	TOPO_SENSOR_STATE_ACPI_PSATTE_G3_MECH_OFF	0x0080
842 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_S1_S2_S3_SLEEP	0x0100
843 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_G1_SLEEP		0x0200
844 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_S5_OVERRIDE	0x0400
845 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_LEGACY_ON		0x0800
846 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_LEGACY_OFF	0x1000
847 #define	TOPO_SENSOR_STATE_ACPI_PSTATE_UNKNOWN		0x2000
848 
849 #define	TOPO_SENSOR_TYPE_WATCHDOG2			0x0023
850 
851 #define	TOPO_SENSOR_STATE_WATCHDOG2_EXPIRED		0x0001
852 #define	TOPO_SENSOR_STATE_WATCHDOG2_HARD_RESET		0x0002
853 #define	TOPO_SENSOR_STATE_WATCHDOG2_PWR_DOWN		0x0004
854 #define	TOPO_SENSOR_STATE_WATCHDOG2_PWR_CYCLE		0x0008
855 #define	TOPO_SENSOR_STATE_WATCHDOG2_RESERVED1		0x0010
856 #define	TOPO_SENSOR_STATE_WATCHDOG2_RESERVED2		0x0020
857 #define	TOPO_SENSOR_STATE_WATCHDOG2_RESERVED3		0x0040
858 #define	TOPO_SENSOR_STATE_WATCHDOG2_RESERVED4		0x0080
859 #define	TOPO_SENSOR_STATE_WATCHDOG2_TIMEOUT_INT		0x0100
860 
861 #define	TOPO_SENSOR_TYPE_ALERT				0x0024
862 
863 #define	TOPO_SENSOR_STATE_ALERT_PLAT_PAGE		0x0001
864 #define	TOPO_SENSOR_STATE_ALERT_PLAT_LAN_ALERT		0x0002
865 #define	TOPO_SENSOR_STATE_ALERT_PLAT_EVT_TRAP		0x0004
866 #define	TOPO_SENSOR_STATE_ALERT_PLAT_SNMP_TRAP		0x0008
867 
868 #define	TOPO_SENSOR_TYPE_PRESENCE			0x0025
869 
870 #define	TOPO_SENSOR_STATE_PRESENCE_PRESENT		0x0001
871 #define	TOPO_SENSOR_STATE_PRESENCE_ABSENT		0x0002
872 #define	TOPO_SENSOR_STATE_PRESENCE_DISABLED		0x0004
873 
874 #define	TOPO_SENSOR_TYPE_ASIC				0x0026
875 
876 #define	TOPO_SENSOR_TYPE_LAN				0x0027
877 
878 #define	TOPO_SENSOR_STATE_LAN_HEARTBEAT_LOST		0x0001
879 #define	TOPO_SENSOR_STATE_LAN_HEARTBEAT			0x0002
880 
881 #define	TOPO_SENSOR_TYPE_HEALTH				0x0028
882 
883 #define	TOPO_SENSOR_STATE_HEALTH_SENSOR_ACC_DEGRADED	0x0001
884 #define	TOPO_SENSOR_STATE_HEALTH_CNTLR_ACC_DEGRADED	0x0002
885 #define	TOPO_SENSOR_STATE_HEALTH_CNTLR_OFFLINE		0x0004
886 #define	TOPO_SENSOR_STATE_HEALTH_CNTLR_UNAVAIL		0x0008
887 #define	TOPO_SENSOR_STATE_HEALTH_SENSOR_FAILURE		0x0010
888 #define	TOPO_SENSOR_STATE_HEALTH_FRU_FAILURE		0x0020
889 
890 #define	TOPO_SENSOR_TYPE_BATTERY			0x0029
891 
892 #define	TOPO_SENSOR_STATE_BATTERY_LOW			0x0001
893 #define	TOPO_SENSOR_STATE_BATTERY_FAILED		0x0002
894 #define	TOPO_SENSOR_STATE_BATTERY_PRESENCE		0x0004
895 
896 #define	TOPO_SENSOR_TYPE_AUDIT				0x002A
897 
898 #define	TOPO_SENSOR_STATE_AUDIT_SESSION_ACTIVATED	0x0001
899 #define	TOPO_SENSOR_STATE_AUDIT_SESSION_DEACTIVATED	0x0002
900 
901 #define	TOPO_SENSOR_TYPE_VERSION			0x002B
902 
903 #define	TOPO_SENSOR_STATE_VERSION_HW_CHANGE		0x0001
904 #define	TOPO_SENSOR_STATE_VERSION_SW_CHANGE		0x0002
905 #define	TOPO_SENSOR_STATE_VERSION_HW_INCOMPATIBLE	0x0004
906 #define	TOPO_SENSOR_STATE_VERSION_SW_INCOMPATIBLE	0x0008
907 #define	TOPO_SENSOR_STATE_VERSION_HW_INVAL		0x0010
908 #define	TOPO_SENSOR_STATE_VERSION_SW_INVAL		0x0020
909 #define	TOPO_SENSOR_STATE_VERSION_HW_CHANGE_SUCCESS	0x0040
910 #define	TOPO_SENSOR_STATE_VERSION_SW_CHANGE_SUCCESS	0x0080
911 
912 #define	TOPO_SENSOR_TYPE_FRU_STATE			0x002C
913 
914 #define	TOPO_SENSOR_STATE_FRU_STATE_NOT_INSTALLED	0x0001
915 #define	TOPO_SENSOR_STATE_FRU_STATE_INACTIVE		0x0002
916 #define	TOPO_SENSOR_STATE_FRU_STATE_ACT_REQ		0x0004
917 #define	TOPO_SENSOR_STATE_FRU_STATE_ACT_INPROGRESS	0x0008
918 #define	TOPO_SENSOR_STATE_FRU_STATE_ACTIVE		0x0010
919 #define	TOPO_SENSOR_STATE_FRU_STATE_DEACT_REQ		0x0020
920 #define	TOPO_SENSOR_STATE_FRU_STATE_DEACT_INPROGRESS	0x0040
921 #define	TOPO_SENSOR_STATE_FRU_STATE_COMM_LOST		0x0080
922 
923 /*
924  * We simplify the IPMI sensor type code defines by combining the generic
925  * and sensor-specific codes into a single range.  Because there's overlap
926  * between the two ranges we offset the generic type codes by 0x0100
927  * which allows ample room in the hole for future expansion of the table to
928  * accomodate either additions to the IPMI spec or to support new sensor types
929  * for alternate provider modules.
930  */
931 #define	TOPO_SENSOR_TYPE_THRESHOLD_STATE		0x0101
932 
933 #define	TOPO_SENSOR_STATE_THRESH_LOWER_NONCRIT		0x0001
934 #define	TOPO_SENSOR_STATE_THRESH_LOWER_CRIT		0x0002
935 #define	TOPO_SENSOR_STATE_THRESH_LOWER_NONREC		0x0004
936 #define	TOPO_SENSOR_STATE_THRESH_UPPER_NONCRIT		0x0008
937 #define	TOPO_SENSOR_STATE_THRESH_UPPER_CRIT		0x0010
938 #define	TOPO_SENSOR_STATE_THRESH_UPPER_NONREC		0x0020
939 
940 #define	TOPO_SENSOR_TYPE_GENERIC_USAGE			0x0102
941 
942 #define	TOPO_SENSOR_STATE_GENERIC_USAGE_IDLE		0x0001
943 #define	TOPO_SENSOR_STATE_GENERIC_USAGE_ACTIVE		0x0002
944 #define	TOPO_SENSOR_STATE_GENERIC_USAGE_BUSY		0x0004
945 
946 #define	TOPO_SENSOR_TYPE_GENERIC_STATE			0x0103
947 
948 #define	TOPO_SENSOR_STATE_GENERIC_STATE_DEASSERTED	0x0001
949 #define	TOPO_SENSOR_STATE_GENERIC_STATE_ASSERTED	0x0002
950 
951 #define	TOPO_SENSOR_TYPE_GENERIC_PREDFAIL		0x0104
952 
953 #define	TOPO_SENSOR_STATE_GENERIC_PREDFAIL_DEASSERTED	0x0001
954 #define	TOPO_SENSOR_STATE_GENERIC_PREDFAIL_ASSERTED	0x0002
955 
956 #define	TOPO_SENSOR_TYPE_GENERIC_LIMIT			0x0105
957 
958 #define	TOPO_SENSOR_STATE_GENERIC_LIMIT_NOT_EXCEEDED	0x0001
959 #define	TOPO_SENSOR_STATE_GENERIC_LIMIT_EXCEEDED	0x0002
960 
961 #define	TOPO_SENSOR_TYPE_GENERIC_PERFORMANCE		0x0106
962 
963 #define	TOPO_SENSOR_STATE_GENERIC_PERFORMANCE_MET	0x0001
964 #define	TOPO_SENSOR_STATE_GENERIC_PERFORMANCE_LAGS	0x0002
965 
966 #define	TOPO_SENSOR_TYPE_SEVERITY			0x0107
967 
968 #define	TOPO_SENSOR_STATE_SEVERITY_OK			0x0001
969 #define	TOPO_SENSOR_STATE_SEVERITY_NONCRIT_GOING_HIGH	0x0002
970 #define	TOPO_SENSOR_STATE_SEVERITY_CRIT_GOING_HIGH	0x0004
971 #define	TOPO_SENSOR_STATE_SEVERITY_NONREC_GOING_HIGH	0x0008
972 #define	TOPO_SENSOR_STATE_SEVERITY_NONCRIT_GOING_LOW	0x0010
973 #define	TOPO_SENSOR_STATE_SEVERITY_CRIT_GOING_LOW	0x0020
974 #define	TOPO_SENSOR_STATE_SEVERITY_NONREC_GOING_LOW	0x0020
975 #define	TOPO_SENSOR_STATE_SEVERITY_MONITOR		0x0040
976 #define	TOPO_SENSOR_STATE_SEVERITY_INFORMATIONAL	0x0080
977 
978 #define	TOPO_SENSOR_TYPE_GENERIC_PRESENCE		0x0108
979 
980 #define	TOPO_SENSOR_STATE_GENERIC_PRESENCE_DEASSERTED	0x0001
981 #define	TOPO_SENSOR_STATE_GENERIC_PRESENCE_ASSERTED	0x0002
982 
983 #define	TOPO_SENSOR_TYPE_GENERIC_AVAILABILITY		0x0109
984 
985 #define	TOPO_SENSOR_STATE_GENERIC_AVAIL_DEASSERTED	0x0001
986 #define	TOPO_SENSOR_STATE_GENERIC_AVAIL_ASSERTED	0x0002
987 
988 #define	TOPO_SENSOR_TYPE_GENERIC_STATUS			0x010A
989 
990 #define	TOPO_SENSOR_STATE_GENERIC_STATUS_RUNNING	0x0001
991 #define	TOPO_SENSOR_STATE_GENERIC_STATUS_IN_TEST	0x0002
992 #define	TOPO_SENSOR_STATE_GENERIC_STATUS_POWER_OFF	0x0004
993 #define	TOPO_SENSOR_STATE_GENERIC_STATUS_ONLINE		0x0008
994 #define	TOPO_SENSOR_STATE_GENERIC_STATUS_OFFLINE	0x0010
995 #define	TOPO_SENSOR_STATE_GENERIC_STATUS_OFF_DUTY	0x0020
996 #define	TOPO_SENSOR_STATE_GENERIC_STATUS_DEGRADED	0x0040
997 #define	TOPO_SENSOR_STATE_GENERIC_STATUS_POWER_SAVE	0x0080
998 #define	TOPO_SENSOR_STATE_GENERIC_STATUS_INSTALL_ERR	0x0100
999 
1000 #define	TOPO_SENSOR_TYPE_GENERIC_REDUNDANCY		0x010B
1001 
1002 /*
1003  * ACPI power state
1004  */
1005 #define	TOPO_SENSOR_TYPE_GENERIC_ACPI			0x010C
1006 
1007 #define	TOPO_SENSOR_STATE_GENERIC_ACPI_D0		0x0001
1008 #define	TOPO_SENSOR_STATE_GENERIC_ACPI_D1		0x0002
1009 #define	TOPO_SENSOR_STATE_GENERIC_ACPI_D2		0x0004
1010 #define	TOPO_SENSOR_STATE_GENERIC_ACPI_D3		0x0008
1011 
1012 /*
1013  * These sensor types don't exist in the IPMI spec, but allow consumers to
1014  * associate discrete sensors with component failure.  The 'ok' sensor is the
1015  * inverse of the 'failure' sensor.  Note that the values intentionally mimic
1016  * TOPO_SENSOR_TYPE_GENERIC_STATE, so that you can use existing IPMI sensors
1017  * but just change the type to get semantically meaningful behavior.
1018  */
1019 #define	TOPO_SENSOR_TYPE_GENERIC_FAILURE		0x010D
1020 
1021 #define	TOPO_SENSOR_STATE_GENERIC_FAIL_DEASSERTED	0x0001
1022 #define	TOPO_SENSOR_STATE_GENERIC_FAIL_NONRECOV		0x0002
1023 #define	TOPO_SENSOR_STATE_GENERIC_FAIL_CRITICAL		0x0004
1024 
1025 #define	TOPO_SENSOR_TYPE_GENERIC_OK			0x010E
1026 
1027 #define	TOPO_SENSOR_STATE_GENERIC_OK_DEASSERTED		0x0001
1028 #define	TOPO_SENSOR_STATE_GENERIC_OK_ASSERTED		0x0002
1029 
1030 /*
1031  * Indicator modes and types
1032  */
1033 typedef enum topo_led_state {
1034 	TOPO_LED_STATE_OFF = 0,
1035 	TOPO_LED_STATE_ON
1036 } topo_led_state_t;
1037 
1038 #define	TOPO_FAC_TYPE_ANY	0xFFFFFFFF
1039 
1040 /*
1041  * This list is limited to the set of LED's that we're likely to manage through
1042  * FMA.  Thus is does not include things like power or activity LED's
1043  */
1044 typedef enum topo_led_type {
1045 	TOPO_LED_TYPE_SERVICE = 0,
1046 	TOPO_LED_TYPE_LOCATE,
1047 	TOPO_LED_TYPE_OK2RM,
1048 	TOPO_LED_TYPE_PRESENT
1049 } topo_led_type_t;
1050 
1051 typedef enum topo_slot_type {
1052 	TOPO_SLOT_TYPE_DIMM = 1,
1053 	TOPO_SLOT_TYPE_UFM,
1054 	TOPO_SLOT_TYPE_M2
1055 } topo_slot_type_t;
1056 
1057 /*
1058  * Read permission indicates that we can read the raw firmware image in this
1059  * slot off of the device.
1060  *
1061  * Write permission indicates that we can write a firmware image into this
1062  * slot.
1063  *
1064  * These permission are orthogonal to the ability to simply report information
1065  * about the firmware image in a slot.
1066  */
1067 typedef enum topo_ufm_slot_mode {
1068 	TOPO_UFM_SLOT_MODE_NONE = 1,
1069 	TOPO_UFM_SLOT_MODE_RO,
1070 	TOPO_UFM_SLOT_MODE_WO,
1071 	TOPO_UFM_SLOT_MODE_RW
1072 } topo_ufm_slot_mode_t;
1073 
1074 typedef struct topo_ufm_slot_info {
1075 	uint32_t usi_slotid;
1076 	topo_ufm_slot_mode_t usi_mode;
1077 	const char *usi_version;
1078 	boolean_t usi_active;
1079 	nvlist_t *usi_extra;
1080 } topo_ufm_slot_info_t;
1081 
1082 #ifdef __cplusplus
1083 }
1084 #endif
1085 
1086 #endif /* _LIBTOPO_H */
1087