xref: /titanic_50/usr/src/lib/libipmi/common/ipmi_impl.h (revision fe62dec3a38f1f79ffe68417df75dbbb58135bb7)
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_IPMI_IMPL_H
27 #define	_IPMI_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <stdlib.h>
32 #include <libipmi.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 typedef struct ipmi_list {
39 	struct ipmi_list *l_prev;
40 	struct ipmi_list *l_next;
41 } ipmi_list_t;
42 
43 typedef struct ipmi_hash_link {
44 	ipmi_list_t  ihl_list;		/* next on list of all elements */
45 	struct ipmi_hash_link *ihl_next;	/* next on this bucket */
46 } ipmi_hash_link_t;
47 
48 typedef struct ipmi_hash {
49 	ipmi_handle_t *ih_handle;	/* handle to library state */
50 	ipmi_hash_link_t **ih_buckets;	/* array of buckets */
51 	size_t ih_nbuckets;		/* number of buckets */
52 	size_t ih_nelements;		/* number of elements */
53 	ipmi_list_t ih_list;		/* list of all elements */
54 	size_t ih_linkoffs;		/* offset of ipmi_hash_link in elem */
55 	const void *(*ih_convert)(const void *); /* key conversion function */
56 	ulong_t (*ih_compute)(const void *); /* hash computing function */
57 	int (*ih_compare)(const void *, const void *); /* compare function */
58 } ipmi_hash_t;
59 
60 typedef struct ipmi_transport {
61 	void *		(*it_open)(struct ipmi_handle *);
62 	void		(*it_close)(void *);
63 	int 		(*it_send)(void *, struct ipmi_cmd *, struct ipmi_cmd *,
64 			    int *);
65 } ipmi_transport_t;
66 
67 struct ipmi_handle {
68 	ipmi_transport_t	*ih_transport;
69 	void			*ih_tdata;
70 	ipmi_cmd_t		ih_response;
71 	int			ih_errno;
72 	uint16_t		ih_reservation;
73 	int			ih_retries;
74 	ipmi_hash_t		*ih_sdr_cache;
75 	uint32_t		ih_sdr_ts;
76 	ipmi_deviceid_t		*ih_deviceid;
77 	uint32_t		ih_deviceid_len;
78 	char			*ih_firmware_rev;
79 	char			ih_errmsg[1024];
80 	char			ih_errbuf[1024];
81 	ipmi_list_t		ih_users;
82 	ipmi_hash_t		*ih_entities;
83 };
84 
85 /*
86  * Error handling
87  */
88 extern int ipmi_set_error(ipmi_handle_t *, int, const char *, ...);
89 
90 /*
91  * Memory allocation
92  */
93 extern void *ipmi_alloc(ipmi_handle_t *, size_t);
94 extern void *ipmi_zalloc(ipmi_handle_t *, size_t);
95 extern void ipmi_free(ipmi_handle_t *, void *);
96 extern void *impi_realloc(ipmi_handle_t *, void *, size_t);
97 extern char *ipmi_strdup(ipmi_handle_t *, const char *);
98 
99 /*
100  * Supported transports
101  */
102 extern ipmi_transport_t ipmi_transport_bmc;
103 
104 /*
105  * Primitives for converting
106  */
107 typedef struct ipmi_name_trans {
108 	int		int_value;
109 	const char	*int_name;
110 } ipmi_name_trans_t;
111 
112 typedef struct ipmi_sensor_trans {
113 	uint8_t			ist_key;
114 	uint8_t			ist_value;
115 	ipmi_name_trans_t	ist_mask[1];
116 } ipmi_sensor_trans_t;
117 
118 extern ipmi_name_trans_t ipmi_entity_table[];
119 extern ipmi_name_trans_t ipmi_sensor_type_table[];
120 extern ipmi_name_trans_t ipmi_reading_type_table[];
121 extern ipmi_name_trans_t ipmi_errno_table[];
122 extern ipmi_name_trans_t ipmi_threshold_state_table[];
123 extern ipmi_name_trans_t ipmi_units_type_table[];
124 extern ipmi_sensor_trans_t ipmi_reading_state_table[];
125 extern ipmi_sensor_trans_t ipmi_specific_state_table[];
126 
127 /*
128  * Miscellaneous routines
129  */
130 extern int ipmi_sdr_init(ipmi_handle_t *);
131 extern void ipmi_sdr_clear(ipmi_handle_t *);
132 extern void ipmi_sdr_fini(ipmi_handle_t *);
133 extern void ipmi_user_clear(ipmi_handle_t *);
134 extern int ipmi_entity_init(ipmi_handle_t *);
135 extern void ipmi_entity_clear(ipmi_handle_t *);
136 extern void ipmi_entity_fini(ipmi_handle_t *);
137 
138 extern int ipmi_convert_bcd(int);
139 extern void ipmi_decode_string(uint8_t type, uint8_t len, char *data,
140     char *buf);
141 extern boolean_t ipmi_is_sun_ilom(ipmi_deviceid_t *);
142 
143 /*
144  * List routines
145  */
146 
147 #define	ipmi_list_prev(elem)	((void *)(((ipmi_list_t *)(elem))->l_prev))
148 #define	ipmi_list_next(elem)	((void *)(((ipmi_list_t *)(elem))->l_next))
149 
150 extern void ipmi_list_append(ipmi_list_t *, void *);
151 extern void ipmi_list_prepend(ipmi_list_t *, void *);
152 extern void ipmi_list_insert_before(ipmi_list_t *, void *, void *);
153 extern void ipmi_list_insert_after(ipmi_list_t *, void *, void *);
154 extern void ipmi_list_delete(ipmi_list_t *, void *);
155 
156 /*
157  * Hash table routines
158  */
159 
160 extern ipmi_hash_t *ipmi_hash_create(ipmi_handle_t *, size_t,
161     const void *(*convert)(const void *),
162     ulong_t (*compute)(const void *),
163     int (*compare)(const void *, const void *));
164 
165 extern void ipmi_hash_destroy(ipmi_hash_t *);
166 extern void *ipmi_hash_lookup(ipmi_hash_t *, const void *);
167 extern void ipmi_hash_insert(ipmi_hash_t *, void *);
168 extern void ipmi_hash_remove(ipmi_hash_t *, void *);
169 extern size_t ipmi_hash_count(ipmi_hash_t *);
170 
171 extern ulong_t ipmi_hash_strhash(const void *);
172 extern int ipmi_hash_strcmp(const void *, const void *);
173 
174 extern ulong_t ipmi_hash_ptrhash(const void *);
175 extern int ipmi_hash_ptrcmp(const void *, const void *);
176 
177 extern void *ipmi_hash_first(ipmi_hash_t *);
178 extern void *ipmi_hash_next(ipmi_hash_t *, void *);
179 
180 #ifdef	__cplusplus
181 }
182 #endif
183 
184 #endif	/* _IPMI_IMPL_H */
185