1 /*
2  * ipmi_int.h
3  *
4  * MontaVista IPMI interface, internal information.
5  *
6  * Author: MontaVista Software, Inc.
7  *         Corey Minyard <minyard@mvista.com>
8  *         source@mvista.com
9  *
10  * Copyright 2002,2003,2004 MontaVista Software Inc.
11  *
12  *  This program is free software; you can redistribute it and/or
13  *  modify it under the terms of the GNU Lesser General Public License
14  *  as published by the Free Software Foundation; either version 2 of
15  *  the License, or (at your option) any later version.
16  *
17  *
18  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  *  You should have received a copy of the GNU Lesser General Public
30  *  License along with this program; if not, write to the Free
31  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32  */
33 
34 #ifndef OPENIPMI_INT_H
35 #define OPENIPMI_INT_H
36 
37 /* Stuff used internally in the IPMI code, and possibly by OEM code. */
38 
39 #include <OpenIPMI/os_handler.h>
40 #include <OpenIPMI/ipmi_types.h>
41 #include <OpenIPMI/ipmi_bits.h>
42 #include <OpenIPMI/ipmi_log.h>
43 #include <OpenIPMI/ipmiif.h> /* for ipmi_args_t, sigh */
44 #include <OpenIPMI/ipmi_string.h>
45 
46 #include <OpenIPMI/internal/ipmi_malloc.h>
47 #include <OpenIPMI/internal/ipmi_locks.h>
48 
49 /* Get the "global" OS handlers used for non-domain operations. */
50 os_handler_t *ipmi_get_global_os_handler(void);
51 
52 /* Create a lock, using the OS handlers for the given MC. */
53 int ipmi_create_lock(ipmi_domain_t *mc, ipmi_lock_t **lock);
54 
55 /* Create a lock using the main os handler registered with ipmi_init(). */
56 int ipmi_create_global_lock(ipmi_lock_t **new_lock);
57 
58 /* Get a globally unique sequence number. */
59 long ipmi_get_seq(void);
60 
61 /* The event state data structure. */
62 struct ipmi_event_state_s
63 {
64     unsigned int status;
65     /* Pay no attention to the implementation. */
66     unsigned int __assertion_events;
67     unsigned int __deassertion_events;
68 };
69 
70 struct ipmi_thresholds_s
71 {
72     /* Pay no attention to the implementation here. */
73     struct {
74 	unsigned int status; /* Is this threshold enabled? */
75 	double       val;
76     } vals[6];
77 };
78 
79 struct ipmi_states_s
80 {
81     int          __event_messages_enabled;
82     int          __sensor_scanning_enabled;
83     int          __initial_update_in_progress;
84     unsigned int __states;
85 };
86 
87 /* Called by connections to see if they have any special OEM handling
88    to do. */
89 int ipmi_check_oem_conn_handlers(ipmi_con_t   *conn,
90 				 unsigned int manufacturer_id,
91 				 unsigned int product_id);
92 
93 /* IPMI data handling. */
94 
95 /* Extract a 32-bit integer from the data, IPMI (little-endian) style. */
96 unsigned int ipmi_get_uint32(const unsigned char *data);
97 
98 /* Extract a 16-bit integer from the data, IPMI (little-endian) style. */
99 unsigned int ipmi_get_uint16(const unsigned char *data);
100 
101 /* Add a 32-bit integer to the data, IPMI (little-endian) style. */
102 void ipmi_set_uint32(unsigned char *data, int val);
103 
104 /* Add a 16-bit integer to the data, IPMI (little-endian) style. */
105 void ipmi_set_uint16(unsigned char *data, int val);
106 
107 /* Generate a log.  Note that logs should not end in a newline, that
108    will be automatically added as needed to the log.  */
109 void ipmi_log(enum ipmi_log_type_e log_type, const char *format, ...)
110 #ifdef __GNUC__
111      __attribute__ ((__format__ (__printf__, 2, 3)))
112 #endif
113 ;
114 
115 /* Information for connection handlers. */
116 typedef struct ipmi_con_setup_s ipmi_con_setup_t;
117 typedef int (*ipmi_con_parse_args_cb)(int         *curr_arg,
118 				      int         arg_count,
119 				      char        * const *args,
120 				      ipmi_args_t **iargs);
121 typedef const char *(*ipmi_con_get_help_cb)(void);
122 typedef ipmi_args_t *(*ipmi_con_alloc_args_cb)(void);
123 ipmi_con_setup_t *i_ipmi_alloc_con_setup(ipmi_con_parse_args_cb parse,
124 					ipmi_con_get_help_cb   help,
125 					ipmi_con_alloc_args_cb alloc);
126 void i_ipmi_free_con_setup(ipmi_con_setup_t *v);
127 
128 int i_ipmi_register_con_type(const char *name, ipmi_con_setup_t *setup);
129 int i_ipmi_unregister_con_type(const char *name, ipmi_con_setup_t *setup);
130 
131 typedef void (*ipmi_args_free_cb)(ipmi_args_t *args);
132 typedef int (*ipmi_args_connect_cb)(ipmi_args_t  *args,
133 				    os_handler_t *handler,
134 				    void         *user_data,
135 				    ipmi_con_t   **new_con);
136 typedef int (*ipmi_args_get_val_cb)(ipmi_args_t  *args,
137 				    unsigned int argnum,
138 				    const char   **name,
139 				    const char   **type,
140 				    const char   **help,
141 				    char         **value,
142 				    const char   ***range);
143 typedef int (*ipmi_args_set_val_cb)(ipmi_args_t  *args,
144 				    unsigned int argnum,
145 				    const char   *name,
146 				    const char   *value);
147 typedef ipmi_args_t *(*ipmi_args_copy_cb)(ipmi_args_t *args);
148 typedef int (*ipmi_args_validate_cb)(ipmi_args_t *args, int *argnum);
149 typedef void (*ipmi_args_free_val_cb)(ipmi_args_t *args, char *value);
150 typedef const char *(*ipmi_args_get_type_cb)(ipmi_args_t *args);
151 ipmi_args_t *i_ipmi_args_alloc(ipmi_args_free_cb     free,
152 			       ipmi_args_connect_cb  connect,
153 			       ipmi_args_get_val_cb  get_val,
154 			       ipmi_args_set_val_cb  set_val,
155 			       ipmi_args_copy_cb     copy,
156 			       ipmi_args_validate_cb validate,
157 			       ipmi_args_free_val_cb free_val,
158 			       ipmi_args_get_type_cb get_type,
159 			       unsigned int          extra_data_len);
160 void *i_ipmi_args_get_extra_data(ipmi_args_t *args);
161 
162 
163 /* Internal function to get the name of a domain. */
164 const char *i_ipmi_domain_name(const ipmi_domain_t *domain);
165 const char *i_ipmi_mc_name(const ipmi_mc_t *mc);
166 const char *i_ipmi_sensor_name(const ipmi_sensor_t *sensor);
167 const char *i_ipmi_control_name(const ipmi_control_t *control);
168 const char *i_ipmi_entity_name(const ipmi_entity_t *entity);
169 const char *i_ipmi_entity_id_name(const ipmi_entity_id_t entity_id);
170 #define DOMAIN_NAME(d) ((d) ? i_ipmi_domain_name(d) : "")
171 #define MC_NAME(m) ((m) ? i_ipmi_mc_name(m) : "")
172 #define ENTITY_NAME(e) ((e) ? i_ipmi_entity_name(e) : "")
173 #define ENTITY_ID_NAME(e) (i_ipmi_entity_id_name(e))
174 #define SENSOR_NAME(s) ((s) ? i_ipmi_sensor_name(s) : "")
175 #define CONTROL_NAME(c) ((c) ? i_ipmi_control_name(c) : "")
176 
177 #include <OpenIPMI/ipmi_debug.h>
178 
179 /* Lock/unlock the entities/mcs for the given domain. */
180 void i_ipmi_domain_entity_lock(ipmi_domain_t *domain);
181 void i_ipmi_domain_entity_unlock(ipmi_domain_t *domain);
182 void i_ipmi_domain_mc_lock(ipmi_domain_t *domain);
183 void i_ipmi_domain_mc_unlock(ipmi_domain_t *domain);
184 
185 #ifdef IPMI_CHECK_LOCKS
186 /* Various lock-checking information. */
187 /* Nothing for now. */
188 void i__ipmi_check_mc_lock(const ipmi_mc_t *mc);
189 #define CHECK_MC_LOCK(mc) i__ipmi_check_mc_lock(mc)
190 
191 void i__ipmi_check_domain_lock(const ipmi_domain_t *domain);
192 #define CHECK_DOMAIN_LOCK(domain) i__ipmi_check_domain_lock(domain)
193 void i__ipmi_check_entity_lock(const ipmi_entity_t *entity);
194 #define CHECK_ENTITY_LOCK(entity) i__ipmi_check_entity_lock(entity)
195 void i__ipmi_check_sensor_lock(const ipmi_sensor_t *sensor);
196 #define CHECK_SENSOR_LOCK(sensor) i__ipmi_check_sensor_lock(sensor)
197 void i__ipmi_check_control_lock(const ipmi_control_t *control);
198 #define CHECK_CONTROL_LOCK(control) i__ipmi_check_control_lock(control)
199 
200 void ipmi_check_lock(const ipmi_lock_t *lock, const char *str);
201 #else
202 #define CHECK_MC_LOCK(mc) do {} while (0)
203 #define CHECK_DOMAIN_LOCK(domain) do {} while (0)
204 #define CHECK_ENTITY_LOCK(entity) do {} while (0)
205 #define CHECK_DOMAIN_ENTITY_LOCK(domain) do {} while (0)
206 #define CHECK_SENSOR_LOCK(sensor) do {} while (0)
207 #define CHECK_CONTROL_LOCK(control) do {} while (0)
208 #endif
209 
210 #define ipmi_seconds_to_time(x) (((ipmi_time_t) (x)) * 1000000000)
211 #define ipmi_timeval_to_time(x) ((((ipmi_time_t) (x).tv_sec) * 1000000000) \
212 				 + (((ipmi_time_t) (x).tv_usec) * 1000))
213 
214 #endif /* OPENIPMI_INT_H */
215