nlm: Ensure callback code also checks that the files match
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / ipmi.h
CommitLineData
1da177e4
LT
1/*
2 * ipmi.h
3 *
4 * MontaVista IPMI interface
5 *
6 * Author: MontaVista Software, Inc.
7 * Corey Minyard <minyard@mvista.com>
8 * source@mvista.com
9 *
10 * Copyright 2002 MontaVista Software Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * 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 General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 */
1da177e4
LT
33#ifndef __LINUX_IPMI_H
34#define __LINUX_IPMI_H
35
607ca46e 36#include <uapi/linux/ipmi.h>
1da177e4 37
1da177e4 38#include <linux/list.h>
3b625943 39#include <linux/proc_fs.h>
3b625943 40
de477254 41struct module;
313162d0 42struct device;
de477254 43
1da177e4
LT
44/* Opaque type for a IPMI message user. One of these is needed to
45 send and receive messages. */
46typedef struct ipmi_user *ipmi_user_t;
47
48/*
49 * Stuff coming from the receive interface comes as one of these.
50 * They are allocated, the receiver must free them with
51 * ipmi_free_recv_msg() when done with the message. The link is not
52 * used after the message is delivered, so the upper layer may use the
53 * link to build a linked list, if it likes.
54 */
c70d7499 55struct ipmi_recv_msg {
1da177e4
LT
56 struct list_head link;
57
58 /* The type of message as defined in the "Receive Types"
c70d7499 59 defines above. */
1da177e4
LT
60 int recv_type;
61
62 ipmi_user_t user;
63 struct ipmi_addr addr;
64 long msgid;
65 struct kernel_ipmi_msg msg;
66
67 /* The user_msg_data is the data supplied when a message was
68 sent, if this is a response to a sent message. If this is
69 not a response to a sent message, then user_msg_data will
56a55ec6
CM
70 be NULL. If the user above is NULL, then this will be the
71 intf. */
1da177e4
LT
72 void *user_msg_data;
73
74 /* Call this when done with the message. It will presumably free
75 the message and do any other necessary cleanup. */
76 void (*done)(struct ipmi_recv_msg *msg);
77
78 /* Place-holder for the data, don't make any assumptions about
25985edc 79 the size or existence of this, since it may change. */
1da177e4
LT
80 unsigned char msg_data[IPMI_MAX_MSG_LENGTH];
81};
82
83/* Allocate and free the receive message. */
393d2cc3 84void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
1da177e4 85
c70d7499
CM
86struct ipmi_user_hndl {
87 /* Routine type to call when a message needs to be routed to
1da177e4
LT
88 the upper layer. This will be called with some locks held,
89 the only IPMI routines that can be called are ipmi_request
90 and the alloc/free operations. The handler_data is the
91 variable supplied when the receive handler was registered. */
92 void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
93 void *user_msg_data);
94
95 /* Called when the interface detects a watchdog pre-timeout. If
96 this is NULL, it will be ignored for the user. */
97 void (*ipmi_watchdog_pretimeout)(void *handler_data);
98};
99
100/* Create a new user of the IPMI layer on the given interface number. */
101int ipmi_create_user(unsigned int if_num,
102 struct ipmi_user_hndl *handler,
103 void *handler_data,
104 ipmi_user_t *user);
105
106/* Destroy the given user of the IPMI layer. Note that after this
107 function returns, the system is guaranteed to not call any
108 callbacks for the user. Thus as long as you destroy all the users
109 before you unload a module, you will be safe. And if you destroy
110 the users before you destroy the callback structures, it should be
111 safe, too. */
112int ipmi_destroy_user(ipmi_user_t user);
113
114/* Get the IPMI version of the BMC we are talking to. */
115void ipmi_get_version(ipmi_user_t user,
116 unsigned char *major,
117 unsigned char *minor);
118
119/* Set and get the slave address and LUN that we will use for our
120 source messages. Note that this affects the interface, not just
121 this user, so it will affect all users of this interface. This is
122 so some initialization code can come in and do the OEM-specific
123 things it takes to determine your address (if not the BMC) and set
c14979b9
CM
124 it for everyone else. Note that each channel can have its own address. */
125int ipmi_set_my_address(ipmi_user_t user,
126 unsigned int channel,
127 unsigned char address);
128int ipmi_get_my_address(ipmi_user_t user,
129 unsigned int channel,
130 unsigned char *address);
131int ipmi_set_my_LUN(ipmi_user_t user,
132 unsigned int channel,
133 unsigned char LUN);
134int ipmi_get_my_LUN(ipmi_user_t user,
135 unsigned int channel,
136 unsigned char *LUN);
1da177e4
LT
137
138/*
139 * Like ipmi_request, but lets you specify the number of retries and
140 * the retry time. The retries is the number of times the message
141 * will be resent if no reply is received. If set to -1, the default
142 * value will be used. The retry time is the time in milliseconds
143 * between retries. If set to zero, the default value will be
144 * used.
145 *
146 * Don't use this unless you *really* have to. It's primarily for the
147 * IPMI over LAN converter; since the LAN stuff does its own retries,
148 * it makes no sense to do it here. However, this can be used if you
149 * have unusual requirements.
150 */
151int ipmi_request_settime(ipmi_user_t user,
152 struct ipmi_addr *addr,
153 long msgid,
154 struct kernel_ipmi_msg *msg,
155 void *user_msg_data,
156 int priority,
157 int max_retries,
158 unsigned int retry_time_ms);
159
160/*
161 * Like ipmi_request, but with messages supplied. This will not
162 * allocate any memory, and the messages may be statically allocated
163 * (just make sure to do the "done" handling on them). Note that this
164 * is primarily for the watchdog timer, since it should be able to
165 * send messages even if no memory is available. This is subject to
166 * change as the system changes, so don't use it unless you REALLY
167 * have to.
168 */
169int ipmi_request_supply_msgs(ipmi_user_t user,
170 struct ipmi_addr *addr,
171 long msgid,
172 struct kernel_ipmi_msg *msg,
173 void *user_msg_data,
174 void *supplied_smi,
175 struct ipmi_recv_msg *supplied_recv,
176 int priority);
177
fcfa4724
CM
178/*
179 * Poll the IPMI interface for the user. This causes the IPMI code to
180 * do an immediate check for information from the driver and handle
181 * anything that is immediately pending. This will not block in any
bda4c30a
CM
182 * way. This is useful if you need to spin waiting for something to
183 * happen in the IPMI driver.
fcfa4724
CM
184 */
185void ipmi_poll_interface(ipmi_user_t user);
186
1da177e4
LT
187/*
188 * When commands come in to the SMS, the user can register to receive
c69c3127 189 * them. Only one user can be listening on a specific netfn/cmd/chan tuple
1da177e4
LT
190 * at a time, you will get an EBUSY error if the command is already
191 * registered. If a command is received that does not have a user
192 * registered, the driver will automatically return the proper
c69c3127
CM
193 * error. Channels are specified as a bitfield, use IPMI_CHAN_ALL to
194 * mean all channels.
1da177e4
LT
195 */
196int ipmi_register_for_cmd(ipmi_user_t user,
197 unsigned char netfn,
c69c3127
CM
198 unsigned char cmd,
199 unsigned int chans);
1da177e4
LT
200int ipmi_unregister_for_cmd(ipmi_user_t user,
201 unsigned char netfn,
c69c3127
CM
202 unsigned char cmd,
203 unsigned int chans);
1da177e4 204
b9675136
CM
205/*
206 * Go into a mode where the driver will not autonomously attempt to do
207 * things with the interface. It will still respond to attentions and
208 * interrupts, and it will expect that commands will complete. It
209 * will not automatcially check for flags, events, or things of that
210 * nature.
211 *
212 * This is primarily used for firmware upgrades. The idea is that
213 * when you go into firmware upgrade mode, you do this operation
214 * and the driver will not attempt to do anything but what you tell
215 * it or what the BMC asks for.
216 *
217 * Note that if you send a command that resets the BMC, the driver
218 * will still expect a response from that command. So the BMC should
219 * reset itself *after* the response is sent. Resetting before the
220 * response is just silly.
221 *
222 * If in auto maintenance mode, the driver will automatically go into
223 * maintenance mode for 30 seconds if it sees a cold reset, a warm
224 * reset, or a firmware NetFN. This means that code that uses only
225 * firmware NetFN commands to do upgrades will work automatically
226 * without change, assuming it sends a message every 30 seconds or
227 * less.
228 *
229 * See the IPMI_MAINTENANCE_MODE_xxx defines for what the mode means.
230 */
231int ipmi_get_maintenance_mode(ipmi_user_t user);
232int ipmi_set_maintenance_mode(ipmi_user_t user, int mode);
233
1da177e4
LT
234/*
235 * When the user is created, it will not receive IPMI events by
236 * default. The user must set this to TRUE to get incoming events.
237 * The first user that sets this to TRUE will receive all events that
238 * have been queued while no one was waiting for events.
239 */
240int ipmi_set_gets_events(ipmi_user_t user, int val);
241
242/*
243 * Called when a new SMI is registered. This will also be called on
244 * every existing interface when a new watcher is registered with
245 * ipmi_smi_watcher_register().
246 */
c70d7499 247struct ipmi_smi_watcher {
1da177e4
LT
248 struct list_head link;
249
250 /* You must set the owner to the current module, if you are in
251 a module (generally just set it to "THIS_MODULE"). */
252 struct module *owner;
253
254 /* These two are called with read locks held for the interface
255 the watcher list. So you can add and remove users from the
256 IPMI interface, send messages, etc., but you cannot add
257 or remove SMI watchers or SMI interfaces. */
50c812b2 258 void (*new_smi)(int if_num, struct device *dev);
1da177e4
LT
259 void (*smi_gone)(int if_num);
260};
261
262int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
263int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
264
265/* The following are various helper functions for dealing with IPMI
266 addresses. */
267
268/* Return the maximum length of an IPMI address given it's type. */
269unsigned int ipmi_addr_length(int addr_type);
270
271/* Validate that the given IPMI address is valid. */
272int ipmi_validate_addr(struct ipmi_addr *addr, int len);
273
16f4232c
ZY
274/*
275 * How did the IPMI driver find out about the device?
276 */
277enum ipmi_addr_src {
278 SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
279 SI_PCI, SI_DEVICETREE, SI_DEFAULT
280};
281
282union ipmi_smi_info_union {
283 /*
284 * the acpi_info element is defined for the SI_ACPI
285 * address type
286 */
287 struct {
288 void *acpi_handle;
289 } acpi_info;
290};
291
292struct ipmi_smi_info {
293 enum ipmi_addr_src addr_src;
294
295 /*
296 * Base device for the interface. Don't forget to put this when
297 * you are done.
298 */
299 struct device *dev;
300
301 /*
302 * The addr_info provides more detailed info for some IPMI
303 * devices, depending on the addr_src. Currently only SI_ACPI
304 * info is provided.
305 */
306 union ipmi_smi_info_union addr_info;
307};
308
309/* This is to get the private info of ipmi_smi_t */
310extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data);
311
1da177e4 312#endif /* __LINUX_IPMI_H */