blob: 1487e7906bbdb3948f124bdfea8a0cf17075dd67 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#ifndef __LINUX_IPMI_H
34#define __LINUX_IPMI_H
35
David Howells607ca462012-10-13 10:46:48 +010036#include <uapi/linux/ipmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39/*
40 * The in-kernel interface.
41 */
42#include <linux/list.h>
Corey Minyard3b625942005-06-23 22:01:42 -070043#include <linux/proc_fs.h>
Corey Minyard3b625942005-06-23 22:01:42 -070044
Paul Gortmakerde477252011-05-26 13:46:22 -040045struct module;
Paul Gortmaker313162d2012-01-30 11:46:54 -050046struct device;
Paul Gortmakerde477252011-05-26 13:46:22 -040047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/* Opaque type for a IPMI message user. One of these is needed to
49 send and receive messages. */
50typedef struct ipmi_user *ipmi_user_t;
51
52/*
53 * Stuff coming from the receive interface comes as one of these.
54 * They are allocated, the receiver must free them with
55 * ipmi_free_recv_msg() when done with the message. The link is not
56 * used after the message is delivered, so the upper layer may use the
57 * link to build a linked list, if it likes.
58 */
Corey Minyardc70d7492008-04-29 01:01:09 -070059struct ipmi_recv_msg {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 struct list_head link;
61
62 /* The type of message as defined in the "Receive Types"
Corey Minyardc70d7492008-04-29 01:01:09 -070063 defines above. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 int recv_type;
65
66 ipmi_user_t user;
67 struct ipmi_addr addr;
68 long msgid;
69 struct kernel_ipmi_msg msg;
70
71 /* The user_msg_data is the data supplied when a message was
72 sent, if this is a response to a sent message. If this is
73 not a response to a sent message, then user_msg_data will
Corey Minyard56a55ec2005-09-06 15:18:42 -070074 be NULL. If the user above is NULL, then this will be the
75 intf. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 void *user_msg_data;
77
78 /* Call this when done with the message. It will presumably free
79 the message and do any other necessary cleanup. */
80 void (*done)(struct ipmi_recv_msg *msg);
81
82 /* Place-holder for the data, don't make any assumptions about
Lucas De Marchi25985ed2011-03-30 22:57:33 -030083 the size or existence of this, since it may change. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 unsigned char msg_data[IPMI_MAX_MSG_LENGTH];
85};
86
87/* Allocate and free the receive message. */
Corey Minyard393d2cc2005-11-07 00:59:54 -080088void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Corey Minyardc70d7492008-04-29 01:01:09 -070090struct ipmi_user_hndl {
91 /* Routine type to call when a message needs to be routed to
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 the upper layer. This will be called with some locks held,
93 the only IPMI routines that can be called are ipmi_request
94 and the alloc/free operations. The handler_data is the
95 variable supplied when the receive handler was registered. */
96 void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
97 void *user_msg_data);
98
99 /* Called when the interface detects a watchdog pre-timeout. If
100 this is NULL, it will be ignored for the user. */
101 void (*ipmi_watchdog_pretimeout)(void *handler_data);
102};
103
104/* Create a new user of the IPMI layer on the given interface number. */
105int ipmi_create_user(unsigned int if_num,
106 struct ipmi_user_hndl *handler,
107 void *handler_data,
108 ipmi_user_t *user);
109
110/* Destroy the given user of the IPMI layer. Note that after this
111 function returns, the system is guaranteed to not call any
112 callbacks for the user. Thus as long as you destroy all the users
113 before you unload a module, you will be safe. And if you destroy
114 the users before you destroy the callback structures, it should be
115 safe, too. */
116int ipmi_destroy_user(ipmi_user_t user);
117
118/* Get the IPMI version of the BMC we are talking to. */
119void ipmi_get_version(ipmi_user_t user,
120 unsigned char *major,
121 unsigned char *minor);
122
123/* Set and get the slave address and LUN that we will use for our
124 source messages. Note that this affects the interface, not just
125 this user, so it will affect all users of this interface. This is
126 so some initialization code can come in and do the OEM-specific
127 things it takes to determine your address (if not the BMC) and set
Corey Minyardc14979b2005-09-06 15:18:38 -0700128 it for everyone else. Note that each channel can have its own address. */
129int ipmi_set_my_address(ipmi_user_t user,
130 unsigned int channel,
131 unsigned char address);
132int ipmi_get_my_address(ipmi_user_t user,
133 unsigned int channel,
134 unsigned char *address);
135int ipmi_set_my_LUN(ipmi_user_t user,
136 unsigned int channel,
137 unsigned char LUN);
138int ipmi_get_my_LUN(ipmi_user_t user,
139 unsigned int channel,
140 unsigned char *LUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142/*
143 * Like ipmi_request, but lets you specify the number of retries and
144 * the retry time. The retries is the number of times the message
145 * will be resent if no reply is received. If set to -1, the default
146 * value will be used. The retry time is the time in milliseconds
147 * between retries. If set to zero, the default value will be
148 * used.
149 *
150 * Don't use this unless you *really* have to. It's primarily for the
151 * IPMI over LAN converter; since the LAN stuff does its own retries,
152 * it makes no sense to do it here. However, this can be used if you
153 * have unusual requirements.
154 */
155int ipmi_request_settime(ipmi_user_t user,
156 struct ipmi_addr *addr,
157 long msgid,
158 struct kernel_ipmi_msg *msg,
159 void *user_msg_data,
160 int priority,
161 int max_retries,
162 unsigned int retry_time_ms);
163
164/*
165 * Like ipmi_request, but with messages supplied. This will not
166 * allocate any memory, and the messages may be statically allocated
167 * (just make sure to do the "done" handling on them). Note that this
168 * is primarily for the watchdog timer, since it should be able to
169 * send messages even if no memory is available. This is subject to
170 * change as the system changes, so don't use it unless you REALLY
171 * have to.
172 */
173int ipmi_request_supply_msgs(ipmi_user_t user,
174 struct ipmi_addr *addr,
175 long msgid,
176 struct kernel_ipmi_msg *msg,
177 void *user_msg_data,
178 void *supplied_smi,
179 struct ipmi_recv_msg *supplied_recv,
180 int priority);
181
182/*
Corey Minyardfcfa4722007-10-18 03:07:09 -0700183 * Poll the IPMI interface for the user. This causes the IPMI code to
184 * do an immediate check for information from the driver and handle
185 * anything that is immediately pending. This will not block in any
Corey Minyardbda4c302008-04-29 01:01:02 -0700186 * way. This is useful if you need to spin waiting for something to
187 * happen in the IPMI driver.
Corey Minyardfcfa4722007-10-18 03:07:09 -0700188 */
189void ipmi_poll_interface(ipmi_user_t user);
190
191/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 * When commands come in to the SMS, the user can register to receive
Corey Minyardc69c3122006-09-30 23:27:56 -0700193 * them. Only one user can be listening on a specific netfn/cmd/chan tuple
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 * at a time, you will get an EBUSY error if the command is already
195 * registered. If a command is received that does not have a user
196 * registered, the driver will automatically return the proper
Corey Minyardc69c3122006-09-30 23:27:56 -0700197 * error. Channels are specified as a bitfield, use IPMI_CHAN_ALL to
198 * mean all channels.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 */
200int ipmi_register_for_cmd(ipmi_user_t user,
201 unsigned char netfn,
Corey Minyardc69c3122006-09-30 23:27:56 -0700202 unsigned char cmd,
203 unsigned int chans);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204int ipmi_unregister_for_cmd(ipmi_user_t user,
205 unsigned char netfn,
Corey Minyardc69c3122006-09-30 23:27:56 -0700206 unsigned char cmd,
207 unsigned int chans);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209/*
Corey Minyardb9675132006-12-06 20:41:02 -0800210 * Go into a mode where the driver will not autonomously attempt to do
211 * things with the interface. It will still respond to attentions and
212 * interrupts, and it will expect that commands will complete. It
213 * will not automatcially check for flags, events, or things of that
214 * nature.
215 *
216 * This is primarily used for firmware upgrades. The idea is that
217 * when you go into firmware upgrade mode, you do this operation
218 * and the driver will not attempt to do anything but what you tell
219 * it or what the BMC asks for.
220 *
221 * Note that if you send a command that resets the BMC, the driver
222 * will still expect a response from that command. So the BMC should
223 * reset itself *after* the response is sent. Resetting before the
224 * response is just silly.
225 *
226 * If in auto maintenance mode, the driver will automatically go into
227 * maintenance mode for 30 seconds if it sees a cold reset, a warm
228 * reset, or a firmware NetFN. This means that code that uses only
229 * firmware NetFN commands to do upgrades will work automatically
230 * without change, assuming it sends a message every 30 seconds or
231 * less.
232 *
233 * See the IPMI_MAINTENANCE_MODE_xxx defines for what the mode means.
234 */
235int ipmi_get_maintenance_mode(ipmi_user_t user);
236int ipmi_set_maintenance_mode(ipmi_user_t user, int mode);
237
238/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 * When the user is created, it will not receive IPMI events by
240 * default. The user must set this to TRUE to get incoming events.
241 * The first user that sets this to TRUE will receive all events that
242 * have been queued while no one was waiting for events.
243 */
244int ipmi_set_gets_events(ipmi_user_t user, int val);
245
246/*
247 * Called when a new SMI is registered. This will also be called on
248 * every existing interface when a new watcher is registered with
249 * ipmi_smi_watcher_register().
250 */
Corey Minyardc70d7492008-04-29 01:01:09 -0700251struct ipmi_smi_watcher {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 struct list_head link;
253
254 /* You must set the owner to the current module, if you are in
255 a module (generally just set it to "THIS_MODULE"). */
256 struct module *owner;
257
258 /* These two are called with read locks held for the interface
259 the watcher list. So you can add and remove users from the
260 IPMI interface, send messages, etc., but you cannot add
261 or remove SMI watchers or SMI interfaces. */
Corey Minyard50c812b2006-03-26 01:37:21 -0800262 void (*new_smi)(int if_num, struct device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 void (*smi_gone)(int if_num);
264};
265
266int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
267int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
268
269/* The following are various helper functions for dealing with IPMI
270 addresses. */
271
272/* Return the maximum length of an IPMI address given it's type. */
273unsigned int ipmi_addr_length(int addr_type);
274
275/* Validate that the given IPMI address is valid. */
276int ipmi_validate_addr(struct ipmi_addr *addr, int len);
277
Zhao Yakui16f42322010-12-08 10:10:16 +0800278/*
279 * How did the IPMI driver find out about the device?
280 */
281enum ipmi_addr_src {
282 SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
283 SI_PCI, SI_DEVICETREE, SI_DEFAULT
284};
285
286union ipmi_smi_info_union {
287 /*
288 * the acpi_info element is defined for the SI_ACPI
289 * address type
290 */
291 struct {
292 void *acpi_handle;
293 } acpi_info;
294};
295
296struct ipmi_smi_info {
297 enum ipmi_addr_src addr_src;
298
299 /*
300 * Base device for the interface. Don't forget to put this when
301 * you are done.
302 */
303 struct device *dev;
304
305 /*
306 * The addr_info provides more detailed info for some IPMI
307 * devices, depending on the addr_src. Currently only SI_ACPI
308 * info is provided.
309 */
310 union ipmi_smi_info_union addr_info;
311};
312
313/* This is to get the private info of ipmi_smi_t */
314extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data);
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316#endif /* __LINUX_IPMI_H */