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