Blame view

include/linux/ipmi.h 10.9 KB
243ac2103   Corey Minyard   ipmi: Add or fix ...
1
  /* SPDX-License-Identifier: GPL-2.0+ */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
  /*
   * ipmi.h
   *
   * MontaVista IPMI interface
   *
   * Author: MontaVista Software, Inc.
   *         Corey Minyard <minyard@mvista.com>
   *         source@mvista.com
   *
   * Copyright 2002 MontaVista Software Inc.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
  #ifndef __LINUX_IPMI_H
  #define __LINUX_IPMI_H
607ca46e9   David Howells   UAPI: (Scripted) ...
16
  #include <uapi/linux/ipmi.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
  #include <linux/list.h>
3b6259432   Corey Minyard   [PATCH] ipmi: add...
19
  #include <linux/proc_fs.h>
a11213fc3   Corey Minyard   ipmi: Use the pro...
20
  #include <linux/acpi.h> /* For acpi_handle */
3b6259432   Corey Minyard   [PATCH] ipmi: add...
21

de4772542   Paul Gortmaker   include: replace ...
22
  struct module;
313162d0b   Paul Gortmaker   device.h: audit a...
23
  struct device;
de4772542   Paul Gortmaker   include: replace ...
24

6dc1181f9   Corey Minyard   ipmi: Clean up co...
25
26
27
28
  /*
   * Opaque type for a IPMI message user.  One of these is needed to
   * send and receive messages.
   */
4372ea94d   Corey Minyard   ipmi: Finally get...
29
  struct ipmi_user;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
31
32
33
34
35
36
37
  
  /*
   * Stuff coming from the receive interface comes as one of these.
   * They are allocated, the receiver must free them with
   * ipmi_free_recv_msg() when done with the message.  The link is not
   * used after the message is delivered, so the upper layer may use the
   * link to build a linked list, if it likes.
   */
c70d74998   Corey Minyard   ipmi: style fixes...
38
  struct ipmi_recv_msg {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
  	struct list_head link;
6dc1181f9   Corey Minyard   ipmi: Clean up co...
40
41
42
43
  	/*
  	 * The type of message as defined in the "Receive Types"
  	 * defines above.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
  	int              recv_type;
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
45
  	struct ipmi_user *user;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
  	struct ipmi_addr addr;
  	long             msgid;
  	struct kernel_ipmi_msg  msg;
6dc1181f9   Corey Minyard   ipmi: Clean up co...
49
50
51
52
53
54
55
  	/*
  	 * The user_msg_data is the data supplied when a message was
  	 * sent, if this is a response to a sent message.  If this is
  	 * not a response to a sent message, then user_msg_data will
  	 * be NULL.  If the user above is NULL, then this will be the
  	 * intf.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
  	void             *user_msg_data;
6dc1181f9   Corey Minyard   ipmi: Clean up co...
57
58
59
60
  	/*
  	 * Call this when done with the message.  It will presumably free
  	 * the message and do any other necessary cleanup.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
  	void (*done)(struct ipmi_recv_msg *msg);
6dc1181f9   Corey Minyard   ipmi: Clean up co...
62
63
64
65
  	/*
  	 * Place-holder for the data, don't make any assumptions about
  	 * the size or existence of this, since it may change.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
  	unsigned char   msg_data[IPMI_MAX_MSG_LENGTH];
  };
  
  /* Allocate and free the receive message. */
393d2cc35   Corey Minyard   [PATCH] ipmi: use...
70
  void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71

c70d74998   Corey Minyard   ipmi: style fixes...
72
  struct ipmi_user_hndl {
6dc1181f9   Corey Minyard   ipmi: Clean up co...
73
74
75
76
77
78
79
  	/*
  	 * Routine type to call when a message needs to be routed to
  	 * the upper layer.  This will be called with some locks held,
  	 * the only IPMI routines that can be called are ipmi_request
  	 * and the alloc/free operations.  The handler_data is the
  	 * variable supplied when the receive handler was registered.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
81
  	void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
  			       void                 *user_msg_data);
6dc1181f9   Corey Minyard   ipmi: Clean up co...
82
83
84
85
  	/*
  	 * Called when the interface detects a watchdog pre-timeout.  If
  	 * this is NULL, it will be ignored for the user.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
  	void (*ipmi_watchdog_pretimeout)(void *handler_data);
91e2dd0a4   Corey Minyard   ipmi: Add a panic...
87
88
89
90
91
92
  
  	/*
  	 * If not NULL, called at panic time after the interface has
  	 * been set up to handle run to completion.
  	 */
  	void (*ipmi_panic_handler)(void *handler_data);
b7780dab9   Corey Minyard   ipmi: Add shutdow...
93
94
95
96
97
98
99
100
  
  	/*
  	 * Called when the interface has been removed.  After this returns
  	 * the user handle will be invalid.  The interface may or may
  	 * not be usable when this is called, but it will return errors
  	 * if it is not usable.
  	 */
  	void (*shutdown)(void *handler_data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
101
102
103
104
  };
  
  /* Create a new user of the IPMI layer on the given interface number. */
  int ipmi_create_user(unsigned int          if_num,
210af2a5f   Corey Minyard   ipmi: make ipmi_u...
105
  		     const struct ipmi_user_hndl *handler,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
106
  		     void                  *handler_data,
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
107
  		     struct ipmi_user      **user);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108

6dc1181f9   Corey Minyard   ipmi: Clean up co...
109
110
111
112
113
114
115
116
  /*
   * Destroy the given user of the IPMI layer.  Note that after this
   * function returns, the system is guaranteed to not call any
   * callbacks for the user.  Thus as long as you destroy all the users
   * before you unload a module, you will be safe.  And if you destroy
   * the users before you destroy the callback structures, it should be
   * safe, too.
   */
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
117
  int ipmi_destroy_user(struct ipmi_user *user);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
119
  
  /* Get the IPMI version of the BMC we are talking to. */
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
120
  int ipmi_get_version(struct ipmi_user *user,
511d57dc7   Corey Minyard   ipmi: Get the dev...
121
122
  		     unsigned char *major,
  		     unsigned char *minor);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123

6dc1181f9   Corey Minyard   ipmi: Clean up co...
124
125
126
127
128
129
130
131
132
  /*
   * Set and get the slave address and LUN that we will use for our
   * source messages.  Note that this affects the interface, not just
   * this user, so it will affect all users of this interface.  This is
   * so some initialization code can come in and do the OEM-specific
   * things it takes to determine your address (if not the BMC) and set
   * it for everyone else.  Note that each channel can have its own
   * address.
   */
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
133
  int ipmi_set_my_address(struct ipmi_user *user,
c14979b99   Corey Minyard   [PATCH] ipmi: add...
134
135
  			unsigned int  channel,
  			unsigned char address);
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
136
  int ipmi_get_my_address(struct ipmi_user *user,
c14979b99   Corey Minyard   [PATCH] ipmi: add...
137
138
  			unsigned int  channel,
  			unsigned char *address);
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
139
  int ipmi_set_my_LUN(struct ipmi_user *user,
c14979b99   Corey Minyard   [PATCH] ipmi: add...
140
141
  		    unsigned int  channel,
  		    unsigned char LUN);
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
142
  int ipmi_get_my_LUN(struct ipmi_user *user,
c14979b99   Corey Minyard   [PATCH] ipmi: add...
143
144
  		    unsigned int  channel,
  		    unsigned char *LUN);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  
  /*
   * Like ipmi_request, but lets you specify the number of retries and
   * the retry time.  The retries is the number of times the message
   * will be resent if no reply is received.  If set to -1, the default
   * value will be used.  The retry time is the time in milliseconds
   * between retries.  If set to zero, the default value will be
   * used.
   *
   * Don't use this unless you *really* have to.  It's primarily for the
   * IPMI over LAN converter; since the LAN stuff does its own retries,
   * it makes no sense to do it here.  However, this can be used if you
   * have unusual requirements.
   */
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
159
  int ipmi_request_settime(struct ipmi_user *user,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  			 struct ipmi_addr *addr,
  			 long             msgid,
  			 struct kernel_ipmi_msg  *msg,
  			 void             *user_msg_data,
  			 int              priority,
  			 int              max_retries,
  			 unsigned int     retry_time_ms);
  
  /*
   * Like ipmi_request, but with messages supplied.  This will not
   * allocate any memory, and the messages may be statically allocated
   * (just make sure to do the "done" handling on them).  Note that this
   * is primarily for the watchdog timer, since it should be able to
   * send messages even if no memory is available.  This is subject to
   * change as the system changes, so don't use it unless you REALLY
   * have to.
   */
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
177
  int ipmi_request_supply_msgs(struct ipmi_user     *user,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
179
180
181
182
183
184
185
186
  			     struct ipmi_addr     *addr,
  			     long                 msgid,
  			     struct kernel_ipmi_msg *msg,
  			     void                 *user_msg_data,
  			     void                 *supplied_smi,
  			     struct ipmi_recv_msg *supplied_recv,
  			     int                  priority);
  
  /*
fcfa47241   Corey Minyard   IPMI: add polled ...
187
188
189
   * Poll the IPMI interface for the user.  This causes the IPMI code to
   * do an immediate check for information from the driver and handle
   * anything that is immediately pending.  This will not block in any
bda4c30aa   Corey Minyard   ipmi: run to comp...
190
191
   * way.  This is useful if you need to spin waiting for something to
   * happen in the IPMI driver.
fcfa47241   Corey Minyard   IPMI: add polled ...
192
   */
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
193
  void ipmi_poll_interface(struct ipmi_user *user);
fcfa47241   Corey Minyard   IPMI: add polled ...
194
195
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
196
   * When commands come in to the SMS, the user can register to receive
c69c31270   Corey Minyard   [PATCH] IPMI: per...
197
   * them.  Only one user can be listening on a specific netfn/cmd/chan tuple
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198
199
200
   * at a time, you will get an EBUSY error if the command is already
   * registered.  If a command is received that does not have a user
   * registered, the driver will automatically return the proper
c69c31270   Corey Minyard   [PATCH] IPMI: per...
201
202
   * error.  Channels are specified as a bitfield, use IPMI_CHAN_ALL to
   * mean all channels.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
203
   */
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
204
  int ipmi_register_for_cmd(struct ipmi_user *user,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205
  			  unsigned char netfn,
c69c31270   Corey Minyard   [PATCH] IPMI: per...
206
207
  			  unsigned char cmd,
  			  unsigned int  chans);
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
208
  int ipmi_unregister_for_cmd(struct ipmi_user *user,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
  			    unsigned char netfn,
c69c31270   Corey Minyard   [PATCH] IPMI: per...
210
211
  			    unsigned char cmd,
  			    unsigned int  chans);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
212
213
  
  /*
b9675136e   Corey Minyard   [PATCH] IPMI: Add...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
   * Go into a mode where the driver will not autonomously attempt to do
   * things with the interface.  It will still respond to attentions and
   * interrupts, and it will expect that commands will complete.  It
   * will not automatcially check for flags, events, or things of that
   * nature.
   *
   * This is primarily used for firmware upgrades.  The idea is that
   * when you go into firmware upgrade mode, you do this operation
   * and the driver will not attempt to do anything but what you tell
   * it or what the BMC asks for.
   *
   * Note that if you send a command that resets the BMC, the driver
   * will still expect a response from that command.  So the BMC should
   * reset itself *after* the response is sent.  Resetting before the
   * response is just silly.
   *
   * If in auto maintenance mode, the driver will automatically go into
   * maintenance mode for 30 seconds if it sees a cold reset, a warm
   * reset, or a firmware NetFN.  This means that code that uses only
   * firmware NetFN commands to do upgrades will work automatically
   * without change, assuming it sends a message every 30 seconds or
   * less.
   *
   * See the IPMI_MAINTENANCE_MODE_xxx defines for what the mode means.
   */
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
239
240
  int ipmi_get_maintenance_mode(struct ipmi_user *user);
  int ipmi_set_maintenance_mode(struct ipmi_user *user, int mode);
b9675136e   Corey Minyard   [PATCH] IPMI: Add...
241
242
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
243
244
245
246
247
   * When the user is created, it will not receive IPMI events by
   * default.  The user must set this to TRUE to get incoming events.
   * The first user that sets this to TRUE will receive all events that
   * have been queued while no one was waiting for events.
   */
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
248
  int ipmi_set_gets_events(struct ipmi_user *user, bool val);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
250
251
252
253
254
  
  /*
   * Called when a new SMI is registered.  This will also be called on
   * every existing interface when a new watcher is registered with
   * ipmi_smi_watcher_register().
   */
c70d74998   Corey Minyard   ipmi: style fixes...
255
  struct ipmi_smi_watcher {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
256
  	struct list_head link;
6dc1181f9   Corey Minyard   ipmi: Clean up co...
257
258
259
260
  	/*
  	 * You must set the owner to the current module, if you are in
  	 * a module (generally just set it to "THIS_MODULE").
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261
  	struct module *owner;
6dc1181f9   Corey Minyard   ipmi: Clean up co...
262
263
264
265
266
267
  	/*
  	 * These two are called with read locks held for the interface
  	 * the watcher list.  So you can add and remove users from the
  	 * IPMI interface, send messages, etc., but you cannot add
  	 * or remove SMI watchers or SMI interfaces.
  	 */
50c812b2b   Corey Minyard   [PATCH] ipmi: add...
268
  	void (*new_smi)(int if_num, struct device *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269
270
271
272
273
  	void (*smi_gone)(int if_num);
  };
  
  int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
  int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
6dc1181f9   Corey Minyard   ipmi: Clean up co...
274
275
276
277
  /*
   * The following are various helper functions for dealing with IPMI
   * addresses.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
278
279
280
281
282
283
  
  /* Return the maximum length of an IPMI address given it's type. */
  unsigned int ipmi_addr_length(int addr_type);
  
  /* Validate that the given IPMI address is valid. */
  int ipmi_validate_addr(struct ipmi_addr *addr, int len);
16f4232ce   Zhao Yakui   IPMI: Add one int...
284
285
286
287
288
  /*
   * How did the IPMI driver find out about the device?
   */
  enum ipmi_addr_src {
  	SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
95e300c05   Corey Minyard   ipmi: Make the DM...
289
  	SI_PCI,	SI_DEVICETREE, SI_PLATFORM, SI_LAST
16f4232ce   Zhao Yakui   IPMI: Add one int...
290
  };
7e50387bc   Corey Minyard   ipmi: Move the ad...
291
  const char *ipmi_addr_src_to_str(enum ipmi_addr_src src);
16f4232ce   Zhao Yakui   IPMI: Add one int...
292
293
  
  union ipmi_smi_info_union {
a11213fc3   Corey Minyard   ipmi: Use the pro...
294
  #ifdef CONFIG_ACPI
16f4232ce   Zhao Yakui   IPMI: Add one int...
295
296
297
298
299
  	/*
  	 * the acpi_info element is defined for the SI_ACPI
  	 * address type
  	 */
  	struct {
a11213fc3   Corey Minyard   ipmi: Use the pro...
300
  		acpi_handle acpi_handle;
16f4232ce   Zhao Yakui   IPMI: Add one int...
301
  	} acpi_info;
a11213fc3   Corey Minyard   ipmi: Use the pro...
302
  #endif
16f4232ce   Zhao Yakui   IPMI: Add one int...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  };
  
  struct ipmi_smi_info {
  	enum ipmi_addr_src addr_src;
  
  	/*
  	 * Base device for the interface.  Don't forget to put this when
  	 * you are done.
  	 */
  	struct device *dev;
  
  	/*
  	 * The addr_info provides more detailed info for some IPMI
  	 * devices, depending on the addr_src.  Currently only SI_ACPI
  	 * info is provided.
  	 */
  	union ipmi_smi_info_union addr_info;
  };
5ce1a7dc8   Corey Minyard   ipmi: Get rid of ...
321
  /* This is to get the private info of struct ipmi_smi */
16f4232ce   Zhao Yakui   IPMI: Add one int...
322
  extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data);
42d8a346c   Xianting Tian   ipmi: add retry i...
323
  #define GET_DEVICE_ID_MAX_RETRY		5
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
324
  #endif /* __LINUX_IPMI_H */