Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * ipmi.h
4 *
5 * MontaVista IPMI interface
6 *
7 * Author: MontaVista Software, Inc.
8 * Corey Minyard <minyard@mvista.com>
9 * source@mvista.com
10 *
11 * Copyright 2002 MontaVista Software Inc.
12 *
13 */
14#ifndef __LINUX_IPMI_H
15#define __LINUX_IPMI_H
16
17#include <uapi/linux/ipmi.h>
18
19#include <linux/list.h>
20#include <linux/proc_fs.h>
21#include <linux/acpi.h> /* For acpi_handle */
22
23struct module;
24struct device;
25
26/* Opaque type for a IPMI message user. One of these is needed to
27 send and receive messages. */
28typedef struct ipmi_user *ipmi_user_t;
29
30/*
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.
36 */
37struct ipmi_recv_msg {
38 struct list_head link;
39
40 /* The type of message as defined in the "Receive Types"
41 defines above. */
42 int recv_type;
43
44 ipmi_user_t user;
45 struct ipmi_addr addr;
46 long msgid;
47 struct kernel_ipmi_msg msg;
48
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
53 intf. */
54 void *user_msg_data;
55
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);
59
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];
63};
64
65/* Allocate and free the receive message. */
66void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
67
68struct 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,
75 void *user_msg_data);
76
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);
80};
81
82/* Create a new user of the IPMI layer on the given interface number. */
83int ipmi_create_user(unsigned int if_num,
84 const struct ipmi_user_hndl *handler,
85 void *handler_data,
86 ipmi_user_t *user);
87
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
93 safe, too. */
94int ipmi_destroy_user(ipmi_user_t user);
95
96/* Get the IPMI version of the BMC we are talking to. */
97int ipmi_get_version(ipmi_user_t user,
98 unsigned char *major,
99 unsigned char *minor);
100
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. */
107int ipmi_set_my_address(ipmi_user_t user,
108 unsigned int channel,
109 unsigned char address);
110int ipmi_get_my_address(ipmi_user_t user,
111 unsigned int channel,
112 unsigned char *address);
113int ipmi_set_my_LUN(ipmi_user_t user,
114 unsigned int channel,
115 unsigned char LUN);
116int ipmi_get_my_LUN(ipmi_user_t user,
117 unsigned int channel,
118 unsigned char *LUN);
119
120/*
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
126 * used.
127 *
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.
132 */
133int ipmi_request_settime(ipmi_user_t user,
134 struct ipmi_addr *addr,
135 long msgid,
136 struct kernel_ipmi_msg *msg,
137 void *user_msg_data,
138 int priority,
139 int max_retries,
140 unsigned int retry_time_ms);
141
142/*
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
149 * have to.
150 */
151int ipmi_request_supply_msgs(ipmi_user_t user,
152 struct ipmi_addr *addr,
153 long msgid,
154 struct kernel_ipmi_msg *msg,
155 void *user_msg_data,
156 void *supplied_smi,
157 struct ipmi_recv_msg *supplied_recv,
158 int priority);
159
160/*
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.
166 */
167void ipmi_poll_interface(ipmi_user_t user);
168
169/*
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
176 * mean all channels.
177 */
178int ipmi_register_for_cmd(ipmi_user_t user,
179 unsigned char netfn,
180 unsigned char cmd,
181 unsigned int chans);
182int ipmi_unregister_for_cmd(ipmi_user_t user,
183 unsigned char netfn,
184 unsigned char cmd,
185 unsigned int chans);
186
187/*
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
192 * nature.
193 *
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.
198 *
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.
203 *
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
209 * less.
210 *
211 * See the IPMI_MAINTENANCE_MODE_xxx defines for what the mode means.
212 */
213int ipmi_get_maintenance_mode(ipmi_user_t user);
214int ipmi_set_maintenance_mode(ipmi_user_t user, int mode);
215
216/*
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.
221 */
222int ipmi_set_gets_events(ipmi_user_t user, bool val);
223
224/*
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().
228 */
229struct ipmi_smi_watcher {
230 struct list_head link;
231
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;
235
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);
242};
243
244int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
245int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
246
247/* The following are various helper functions for dealing with IPMI
248 addresses. */
249
250/* Return the maximum length of an IPMI address given it's type. */
251unsigned int ipmi_addr_length(int addr_type);
252
253/* Validate that the given IPMI address is valid. */
254int ipmi_validate_addr(struct ipmi_addr *addr, int len);
255
256/*
257 * How did the IPMI driver find out about the device?
258 */
259enum ipmi_addr_src {
260 SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
261 SI_PCI, SI_DEVICETREE, SI_PLATFORM, SI_LAST
262};
263const char *ipmi_addr_src_to_str(enum ipmi_addr_src src);
264
265union ipmi_smi_info_union {
266#ifdef CONFIG_ACPI
267 /*
268 * the acpi_info element is defined for the SI_ACPI
269 * address type
270 */
271 struct {
272 acpi_handle acpi_handle;
273 } acpi_info;
274#endif
275};
276
277struct ipmi_smi_info {
278 enum ipmi_addr_src addr_src;
279
280 /*
281 * Base device for the interface. Don't forget to put this when
282 * you are done.
283 */
284 struct device *dev;
285
286 /*
287 * The addr_info provides more detailed info for some IPMI
288 * devices, depending on the addr_src. Currently only SI_ACPI
289 * info is provided.
290 */
291 union ipmi_smi_info_union addr_info;
292};
293
294/* This is to get the private info of ipmi_smi_t */
295extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data);
296
297#endif /* __LINUX_IPMI_H */