blob: 3474f04cf9aaa97745cb767e2767ae77b114da54 [file] [log] [blame]
Corey Minyard243ac212018-02-20 07:30:22 -06001/* SPDX-License-Identifier: GPL-2.0+ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#ifndef __LINUX_IPMI_H
15#define __LINUX_IPMI_H
16
David Howells607ca462012-10-13 10:46:48 +010017#include <uapi/linux/ipmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/list.h>
Corey Minyard3b625942005-06-23 22:01:42 -070020#include <linux/proc_fs.h>
Corey Minyarda11213f2014-10-10 17:47:04 -050021#include <linux/acpi.h> /* For acpi_handle */
Corey Minyard3b625942005-06-23 22:01:42 -070022
Paul Gortmakerde477252011-05-26 13:46:22 -040023struct module;
Paul Gortmaker313162d2012-01-30 11:46:54 -050024struct device;
Paul Gortmakerde477252011-05-26 13:46:22 -040025
Corey Minyard6dc11812018-04-04 08:54:05 -050026/*
27 * Opaque type for a IPMI message user. One of these is needed to
28 * send and receive messages.
29 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030typedef struct ipmi_user *ipmi_user_t;
31
32/*
33 * Stuff coming from the receive interface comes as one of these.
34 * They are allocated, the receiver must free them with
35 * ipmi_free_recv_msg() when done with the message. The link is not
36 * used after the message is delivered, so the upper layer may use the
37 * link to build a linked list, if it likes.
38 */
Corey Minyardc70d7492008-04-29 01:01:09 -070039struct ipmi_recv_msg {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 struct list_head link;
41
Corey Minyard6dc11812018-04-04 08:54:05 -050042 /*
43 * The type of message as defined in the "Receive Types"
44 * defines above.
45 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 int recv_type;
47
48 ipmi_user_t user;
49 struct ipmi_addr addr;
50 long msgid;
51 struct kernel_ipmi_msg msg;
52
Corey Minyard6dc11812018-04-04 08:54:05 -050053 /*
54 * The user_msg_data is the data supplied when a message was
55 * sent, if this is a response to a sent message. If this is
56 * not a response to a sent message, then user_msg_data will
57 * be NULL. If the user above is NULL, then this will be the
58 * intf.
59 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 void *user_msg_data;
61
Corey Minyard6dc11812018-04-04 08:54:05 -050062 /*
63 * Call this when done with the message. It will presumably free
64 * the message and do any other necessary cleanup.
65 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 void (*done)(struct ipmi_recv_msg *msg);
67
Corey Minyard6dc11812018-04-04 08:54:05 -050068 /*
69 * Place-holder for the data, don't make any assumptions about
70 * the size or existence of this, since it may change.
71 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 unsigned char msg_data[IPMI_MAX_MSG_LENGTH];
73};
74
75/* Allocate and free the receive message. */
Corey Minyard393d2cc2005-11-07 00:59:54 -080076void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Corey Minyardc70d7492008-04-29 01:01:09 -070078struct ipmi_user_hndl {
Corey Minyard6dc11812018-04-04 08:54:05 -050079 /*
80 * Routine type to call when a message needs to be routed to
81 * the upper layer. This will be called with some locks held,
82 * the only IPMI routines that can be called are ipmi_request
83 * and the alloc/free operations. The handler_data is the
84 * variable supplied when the receive handler was registered.
85 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
87 void *user_msg_data);
88
Corey Minyard6dc11812018-04-04 08:54:05 -050089 /*
90 * Called when the interface detects a watchdog pre-timeout. If
91 * this is NULL, it will be ignored for the user.
92 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 void (*ipmi_watchdog_pretimeout)(void *handler_data);
Corey Minyard91e2dd02018-03-28 13:19:25 -050094
95 /*
96 * If not NULL, called at panic time after the interface has
97 * been set up to handle run to completion.
98 */
99 void (*ipmi_panic_handler)(void *handler_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100};
101
102/* Create a new user of the IPMI layer on the given interface number. */
103int ipmi_create_user(unsigned int if_num,
Corey Minyard210af2a2017-01-05 10:52:10 -0600104 const struct ipmi_user_hndl *handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 void *handler_data,
106 ipmi_user_t *user);
107
Corey Minyard6dc11812018-04-04 08:54:05 -0500108/*
109 * Destroy the given user of the IPMI layer. Note that after this
110 * function returns, the system is guaranteed to not call any
111 * callbacks for the user. Thus as long as you destroy all the users
112 * before you unload a module, you will be safe. And if you destroy
113 * the users before you destroy the callback structures, it should be
114 * safe, too.
115 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116int ipmi_destroy_user(ipmi_user_t user);
117
118/* Get the IPMI version of the BMC we are talking to. */
Corey Minyard511d57d2017-08-30 08:04:24 -0500119int ipmi_get_version(ipmi_user_t user,
120 unsigned char *major,
121 unsigned char *minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Corey Minyard6dc11812018-04-04 08:54:05 -0500123/*
124 * Set and get the slave address and LUN that we will use for our
125 * source messages. Note that this affects the interface, not just
126 * this user, so it will affect all users of this interface. This is
127 * so some initialization code can come in and do the OEM-specific
128 * things it takes to determine your address (if not the BMC) and set
129 * it for everyone else. Note that each channel can have its own
130 * address.
131 */
Corey Minyardc14979b2005-09-06 15:18:38 -0700132int ipmi_set_my_address(ipmi_user_t user,
133 unsigned int channel,
134 unsigned char address);
135int ipmi_get_my_address(ipmi_user_t user,
136 unsigned int channel,
137 unsigned char *address);
138int ipmi_set_my_LUN(ipmi_user_t user,
139 unsigned int channel,
140 unsigned char LUN);
141int ipmi_get_my_LUN(ipmi_user_t user,
142 unsigned int channel,
143 unsigned char *LUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145/*
146 * Like ipmi_request, but lets you specify the number of retries and
147 * the retry time. The retries is the number of times the message
148 * will be resent if no reply is received. If set to -1, the default
149 * value will be used. The retry time is the time in milliseconds
150 * between retries. If set to zero, the default value will be
151 * used.
152 *
153 * Don't use this unless you *really* have to. It's primarily for the
154 * IPMI over LAN converter; since the LAN stuff does its own retries,
155 * it makes no sense to do it here. However, this can be used if you
156 * have unusual requirements.
157 */
158int ipmi_request_settime(ipmi_user_t user,
159 struct ipmi_addr *addr,
160 long msgid,
161 struct kernel_ipmi_msg *msg,
162 void *user_msg_data,
163 int priority,
164 int max_retries,
165 unsigned int retry_time_ms);
166
167/*
168 * Like ipmi_request, but with messages supplied. This will not
169 * allocate any memory, and the messages may be statically allocated
170 * (just make sure to do the "done" handling on them). Note that this
171 * is primarily for the watchdog timer, since it should be able to
172 * send messages even if no memory is available. This is subject to
173 * change as the system changes, so don't use it unless you REALLY
174 * have to.
175 */
176int ipmi_request_supply_msgs(ipmi_user_t user,
177 struct ipmi_addr *addr,
178 long msgid,
179 struct kernel_ipmi_msg *msg,
180 void *user_msg_data,
181 void *supplied_smi,
182 struct ipmi_recv_msg *supplied_recv,
183 int priority);
184
185/*
Corey Minyardfcfa4722007-10-18 03:07:09 -0700186 * Poll the IPMI interface for the user. This causes the IPMI code to
187 * do an immediate check for information from the driver and handle
188 * anything that is immediately pending. This will not block in any
Corey Minyardbda4c302008-04-29 01:01:02 -0700189 * way. This is useful if you need to spin waiting for something to
190 * happen in the IPMI driver.
Corey Minyardfcfa4722007-10-18 03:07:09 -0700191 */
192void ipmi_poll_interface(ipmi_user_t user);
193
194/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 * When commands come in to the SMS, the user can register to receive
Corey Minyardc69c3122006-09-30 23:27:56 -0700196 * them. Only one user can be listening on a specific netfn/cmd/chan tuple
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 * at a time, you will get an EBUSY error if the command is already
198 * registered. If a command is received that does not have a user
199 * registered, the driver will automatically return the proper
Corey Minyardc69c3122006-09-30 23:27:56 -0700200 * error. Channels are specified as a bitfield, use IPMI_CHAN_ALL to
201 * mean all channels.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 */
203int ipmi_register_for_cmd(ipmi_user_t user,
204 unsigned char netfn,
Corey Minyardc69c3122006-09-30 23:27:56 -0700205 unsigned char cmd,
206 unsigned int chans);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207int ipmi_unregister_for_cmd(ipmi_user_t user,
208 unsigned char netfn,
Corey Minyardc69c3122006-09-30 23:27:56 -0700209 unsigned char cmd,
210 unsigned int chans);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212/*
Corey Minyardb9675132006-12-06 20:41:02 -0800213 * Go into a mode where the driver will not autonomously attempt to do
214 * things with the interface. It will still respond to attentions and
215 * interrupts, and it will expect that commands will complete. It
216 * will not automatcially check for flags, events, or things of that
217 * nature.
218 *
219 * This is primarily used for firmware upgrades. The idea is that
220 * when you go into firmware upgrade mode, you do this operation
221 * and the driver will not attempt to do anything but what you tell
222 * it or what the BMC asks for.
223 *
224 * Note that if you send a command that resets the BMC, the driver
225 * will still expect a response from that command. So the BMC should
226 * reset itself *after* the response is sent. Resetting before the
227 * response is just silly.
228 *
229 * If in auto maintenance mode, the driver will automatically go into
230 * maintenance mode for 30 seconds if it sees a cold reset, a warm
231 * reset, or a firmware NetFN. This means that code that uses only
232 * firmware NetFN commands to do upgrades will work automatically
233 * without change, assuming it sends a message every 30 seconds or
234 * less.
235 *
236 * See the IPMI_MAINTENANCE_MODE_xxx defines for what the mode means.
237 */
238int ipmi_get_maintenance_mode(ipmi_user_t user);
239int ipmi_set_maintenance_mode(ipmi_user_t user, int mode);
240
241/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 * When the user is created, it will not receive IPMI events by
243 * default. The user must set this to TRUE to get incoming events.
244 * The first user that sets this to TRUE will receive all events that
245 * have been queued while no one was waiting for events.
246 */
Corey Minyard89986492014-04-14 09:46:54 -0500247int ipmi_set_gets_events(ipmi_user_t user, bool val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249/*
250 * Called when a new SMI is registered. This will also be called on
251 * every existing interface when a new watcher is registered with
252 * ipmi_smi_watcher_register().
253 */
Corey Minyardc70d7492008-04-29 01:01:09 -0700254struct ipmi_smi_watcher {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 struct list_head link;
256
Corey Minyard6dc11812018-04-04 08:54:05 -0500257 /*
258 * You must set the owner to the current module, if you are in
259 * a module (generally just set it to "THIS_MODULE").
260 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 struct module *owner;
262
Corey Minyard6dc11812018-04-04 08:54:05 -0500263 /*
264 * These two are called with read locks held for the interface
265 * the watcher list. So you can add and remove users from the
266 * IPMI interface, send messages, etc., but you cannot add
267 * or remove SMI watchers or SMI interfaces.
268 */
Corey Minyard50c812b2006-03-26 01:37:21 -0800269 void (*new_smi)(int if_num, struct device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 void (*smi_gone)(int if_num);
271};
272
273int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
274int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
275
Corey Minyard6dc11812018-04-04 08:54:05 -0500276/*
277 * The following are various helper functions for dealing with IPMI
278 * addresses.
279 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281/* Return the maximum length of an IPMI address given it's type. */
282unsigned int ipmi_addr_length(int addr_type);
283
284/* Validate that the given IPMI address is valid. */
285int ipmi_validate_addr(struct ipmi_addr *addr, int len);
286
Zhao Yakui16f42322010-12-08 10:10:16 +0800287/*
288 * How did the IPMI driver find out about the device?
289 */
290enum ipmi_addr_src {
291 SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
Corey Minyard95e300c2017-09-18 12:38:17 -0500292 SI_PCI, SI_DEVICETREE, SI_PLATFORM, SI_LAST
Zhao Yakui16f42322010-12-08 10:10:16 +0800293};
Corey Minyard7e503872014-10-09 07:20:32 -0500294const char *ipmi_addr_src_to_str(enum ipmi_addr_src src);
Zhao Yakui16f42322010-12-08 10:10:16 +0800295
296union ipmi_smi_info_union {
Corey Minyarda11213f2014-10-10 17:47:04 -0500297#ifdef CONFIG_ACPI
Zhao Yakui16f42322010-12-08 10:10:16 +0800298 /*
299 * the acpi_info element is defined for the SI_ACPI
300 * address type
301 */
302 struct {
Corey Minyarda11213f2014-10-10 17:47:04 -0500303 acpi_handle acpi_handle;
Zhao Yakui16f42322010-12-08 10:10:16 +0800304 } acpi_info;
Corey Minyarda11213f2014-10-10 17:47:04 -0500305#endif
Zhao Yakui16f42322010-12-08 10:10:16 +0800306};
307
308struct ipmi_smi_info {
309 enum ipmi_addr_src addr_src;
310
311 /*
312 * Base device for the interface. Don't forget to put this when
313 * you are done.
314 */
315 struct device *dev;
316
317 /*
318 * The addr_info provides more detailed info for some IPMI
319 * devices, depending on the addr_src. Currently only SI_ACPI
320 * info is provided.
321 */
322 union ipmi_smi_info_union addr_info;
323};
324
325/* This is to get the private info of ipmi_smi_t */
326extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data);
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#endif /* __LINUX_IPMI_H */