1 /* SPDX-License-Identifier: GPL-2.0+ */
5 * MontaVista IPMI interface
7 * Author: MontaVista Software, Inc.
8 * Corey Minyard <minyard@mvista.com>
11 * Copyright 2002 MontaVista Software Inc.
14 #ifndef __LINUX_IPMI_H
15 #define __LINUX_IPMI_H
17 #include <uapi/linux/ipmi.h>
19 #include <linux/list.h>
20 #include <linux/proc_fs.h>
21 #include <linux/acpi.h> /* For acpi_handle */
26 /* Opaque type for a IPMI message user. One of these is needed to
27 send and receive messages. */
28 typedef struct ipmi_user *ipmi_user_t;
31 * Stuff coming from the receive interface comes as one of these.
32 * They are allocated, the receiver must free them with
33 * ipmi_free_recv_msg() when done with the message. The link is not
34 * used after the message is delivered, so the upper layer may use the
35 * link to build a linked list, if it likes.
37 struct ipmi_recv_msg {
38 struct list_head link;
40 /* The type of message as defined in the "Receive Types"
45 struct ipmi_addr addr;
47 struct kernel_ipmi_msg msg;
49 /* The user_msg_data is the data supplied when a message was
50 sent, if this is a response to a sent message. If this is
51 not a response to a sent message, then user_msg_data will
52 be NULL. If the user above is NULL, then this will be the
56 /* Call this when done with the message. It will presumably free
57 the message and do any other necessary cleanup. */
58 void (*done)(struct ipmi_recv_msg *msg);
60 /* Place-holder for the data, don't make any assumptions about
61 the size or existence of this, since it may change. */
62 unsigned char msg_data[IPMI_MAX_MSG_LENGTH];
65 /* Allocate and free the receive message. */
66 void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
68 struct ipmi_user_hndl {
69 /* Routine type to call when a message needs to be routed to
70 the upper layer. This will be called with some locks held,
71 the only IPMI routines that can be called are ipmi_request
72 and the alloc/free operations. The handler_data is the
73 variable supplied when the receive handler was registered. */
74 void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
77 /* Called when the interface detects a watchdog pre-timeout. If
78 this is NULL, it will be ignored for the user. */
79 void (*ipmi_watchdog_pretimeout)(void *handler_data);
82 /* Create a new user of the IPMI layer on the given interface number. */
83 int ipmi_create_user(unsigned int if_num,
84 const struct ipmi_user_hndl *handler,
88 /* Destroy the given user of the IPMI layer. Note that after this
89 function returns, the system is guaranteed to not call any
90 callbacks for the user. Thus as long as you destroy all the users
91 before you unload a module, you will be safe. And if you destroy
92 the users before you destroy the callback structures, it should be
94 int ipmi_destroy_user(ipmi_user_t user);
96 /* Get the IPMI version of the BMC we are talking to. */
97 int ipmi_get_version(ipmi_user_t user,
99 unsigned char *minor);
101 /* Set and get the slave address and LUN that we will use for our
102 source messages. Note that this affects the interface, not just
103 this user, so it will affect all users of this interface. This is
104 so some initialization code can come in and do the OEM-specific
105 things it takes to determine your address (if not the BMC) and set
106 it for everyone else. Note that each channel can have its own address. */
107 int ipmi_set_my_address(ipmi_user_t user,
108 unsigned int channel,
109 unsigned char address);
110 int ipmi_get_my_address(ipmi_user_t user,
111 unsigned int channel,
112 unsigned char *address);
113 int ipmi_set_my_LUN(ipmi_user_t user,
114 unsigned int channel,
116 int ipmi_get_my_LUN(ipmi_user_t user,
117 unsigned int channel,
121 * Like ipmi_request, but lets you specify the number of retries and
122 * the retry time. The retries is the number of times the message
123 * will be resent if no reply is received. If set to -1, the default
124 * value will be used. The retry time is the time in milliseconds
125 * between retries. If set to zero, the default value will be
128 * Don't use this unless you *really* have to. It's primarily for the
129 * IPMI over LAN converter; since the LAN stuff does its own retries,
130 * it makes no sense to do it here. However, this can be used if you
131 * have unusual requirements.
133 int ipmi_request_settime(ipmi_user_t user,
134 struct ipmi_addr *addr,
136 struct kernel_ipmi_msg *msg,
140 unsigned int retry_time_ms);
143 * Like ipmi_request, but with messages supplied. This will not
144 * allocate any memory, and the messages may be statically allocated
145 * (just make sure to do the "done" handling on them). Note that this
146 * is primarily for the watchdog timer, since it should be able to
147 * send messages even if no memory is available. This is subject to
148 * change as the system changes, so don't use it unless you REALLY
151 int ipmi_request_supply_msgs(ipmi_user_t user,
152 struct ipmi_addr *addr,
154 struct kernel_ipmi_msg *msg,
157 struct ipmi_recv_msg *supplied_recv,
161 * Poll the IPMI interface for the user. This causes the IPMI code to
162 * do an immediate check for information from the driver and handle
163 * anything that is immediately pending. This will not block in any
164 * way. This is useful if you need to spin waiting for something to
165 * happen in the IPMI driver.
167 void ipmi_poll_interface(ipmi_user_t user);
170 * When commands come in to the SMS, the user can register to receive
171 * them. Only one user can be listening on a specific netfn/cmd/chan tuple
172 * at a time, you will get an EBUSY error if the command is already
173 * registered. If a command is received that does not have a user
174 * registered, the driver will automatically return the proper
175 * error. Channels are specified as a bitfield, use IPMI_CHAN_ALL to
178 int ipmi_register_for_cmd(ipmi_user_t user,
182 int ipmi_unregister_for_cmd(ipmi_user_t user,
188 * Go into a mode where the driver will not autonomously attempt to do
189 * things with the interface. It will still respond to attentions and
190 * interrupts, and it will expect that commands will complete. It
191 * will not automatcially check for flags, events, or things of that
194 * This is primarily used for firmware upgrades. The idea is that
195 * when you go into firmware upgrade mode, you do this operation
196 * and the driver will not attempt to do anything but what you tell
197 * it or what the BMC asks for.
199 * Note that if you send a command that resets the BMC, the driver
200 * will still expect a response from that command. So the BMC should
201 * reset itself *after* the response is sent. Resetting before the
202 * response is just silly.
204 * If in auto maintenance mode, the driver will automatically go into
205 * maintenance mode for 30 seconds if it sees a cold reset, a warm
206 * reset, or a firmware NetFN. This means that code that uses only
207 * firmware NetFN commands to do upgrades will work automatically
208 * without change, assuming it sends a message every 30 seconds or
211 * See the IPMI_MAINTENANCE_MODE_xxx defines for what the mode means.
213 int ipmi_get_maintenance_mode(ipmi_user_t user);
214 int ipmi_set_maintenance_mode(ipmi_user_t user, int mode);
217 * When the user is created, it will not receive IPMI events by
218 * default. The user must set this to TRUE to get incoming events.
219 * The first user that sets this to TRUE will receive all events that
220 * have been queued while no one was waiting for events.
222 int ipmi_set_gets_events(ipmi_user_t user, bool val);
225 * Called when a new SMI is registered. This will also be called on
226 * every existing interface when a new watcher is registered with
227 * ipmi_smi_watcher_register().
229 struct ipmi_smi_watcher {
230 struct list_head link;
232 /* You must set the owner to the current module, if you are in
233 a module (generally just set it to "THIS_MODULE"). */
234 struct module *owner;
236 /* These two are called with read locks held for the interface
237 the watcher list. So you can add and remove users from the
238 IPMI interface, send messages, etc., but you cannot add
239 or remove SMI watchers or SMI interfaces. */
240 void (*new_smi)(int if_num, struct device *dev);
241 void (*smi_gone)(int if_num);
244 int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
245 int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
247 /* The following are various helper functions for dealing with IPMI
250 /* Return the maximum length of an IPMI address given it's type. */
251 unsigned int ipmi_addr_length(int addr_type);
253 /* Validate that the given IPMI address is valid. */
254 int ipmi_validate_addr(struct ipmi_addr *addr, int len);
257 * How did the IPMI driver find out about the device?
260 SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
261 SI_PCI, SI_DEVICETREE, SI_PLATFORM, SI_LAST
263 const char *ipmi_addr_src_to_str(enum ipmi_addr_src src);
265 union ipmi_smi_info_union {
268 * the acpi_info element is defined for the SI_ACPI
272 acpi_handle acpi_handle;
277 struct ipmi_smi_info {
278 enum ipmi_addr_src addr_src;
281 * Base device for the interface. Don't forget to put this when
287 * The addr_info provides more detailed info for some IPMI
288 * devices, depending on the addr_src. Currently only SI_ACPI
291 union ipmi_smi_info_union addr_info;
294 /* This is to get the private info of ipmi_smi_t */
295 extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data);
297 #endif /* __LINUX_IPMI_H */