blob: 596ca6130159f749036cf15860ba275c2122a6d3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ipmi.h
3 *
4 * MontaVista IPMI interface
5 *
6 * Author: MontaVista Software, Inc.
7 * Corey Minyard <minyard@mvista.com>
8 * source@mvista.com
9 *
10 * Copyright 2002 MontaVista Software Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 */
33
34#ifndef __LINUX_IPMI_H
35#define __LINUX_IPMI_H
36
37#include <linux/ipmi_msgdefs.h>
38
39/*
40 * This file describes an interface to an IPMI driver. You have to
41 * have a fairly good understanding of IPMI to use this, so go read
42 * the specs first before actually trying to do anything.
43 *
44 * With that said, this driver provides a multi-user interface to the
45 * IPMI driver, and it allows multiple IPMI physical interfaces below
46 * the driver. The physical interfaces bind as a lower layer on the
47 * driver. They appear as interfaces to the application using this
48 * interface.
49 *
50 * Multi-user means that multiple applications may use the driver,
51 * send commands, receive responses, etc. The driver keeps track of
52 * commands the user sends and tracks the responses. The responses
53 * will go back to the application that send the command. If the
54 * response doesn't come back in time, the driver will return a
55 * timeout error response to the application. Asynchronous events
56 * from the BMC event queue will go to all users bound to the driver.
57 * The incoming event queue in the BMC will automatically be flushed
58 * if it becomes full and it is queried once a second to see if
59 * anything is in it. Incoming commands to the driver will get
60 * delivered as commands.
61 *
62 * This driver provides two main interfaces: one for in-kernel
63 * applications and another for userland applications. The
64 * capabilities are basically the same for both interface, although
65 * the interfaces are somewhat different. The stuff in the
66 * #ifdef KERNEL below is the in-kernel interface. The userland
67 * interface is defined later in the file. */
68
69
70
71/*
72 * This is an overlay for all the address types, so it's easy to
73 * determine the actual address type. This is kind of like addresses
74 * work for sockets.
75 */
76#define IPMI_MAX_ADDR_SIZE 32
77struct ipmi_addr
78{
79 /* Try to take these from the "Channel Medium Type" table
80 in section 6.5 of the IPMI 1.5 manual. */
81 int addr_type;
82 short channel;
83 char data[IPMI_MAX_ADDR_SIZE];
84};
85
86/*
87 * When the address is not used, the type will be set to this value.
88 * The channel is the BMC's channel number for the channel (usually
89 * 0), or IPMC_BMC_CHANNEL if communicating directly with the BMC.
90 */
91#define IPMI_SYSTEM_INTERFACE_ADDR_TYPE 0x0c
92struct ipmi_system_interface_addr
93{
94 int addr_type;
95 short channel;
96 unsigned char lun;
97};
98
99/* An IPMB Address. */
100#define IPMI_IPMB_ADDR_TYPE 0x01
101/* Used for broadcast get device id as described in section 17.9 of the
102 IPMI 1.5 manual. */
103#define IPMI_IPMB_BROADCAST_ADDR_TYPE 0x41
104struct ipmi_ipmb_addr
105{
106 int addr_type;
107 short channel;
108 unsigned char slave_addr;
109 unsigned char lun;
110};
111
112/*
113 * A LAN Address. This is an address to/from a LAN interface bridged
114 * by the BMC, not an address actually out on the LAN.
115 *
116 * A concious decision was made here to deviate slightly from the IPMI
117 * spec. We do not use rqSWID and rsSWID like it shows in the
118 * message. Instead, we use remote_SWID and local_SWID. This means
119 * that any message (a request or response) from another device will
120 * always have exactly the same address. If you didn't do this,
121 * requests and responses from the same device would have different
122 * addresses, and that's not too cool.
123 *
124 * In this address, the remote_SWID is always the SWID the remote
125 * message came from, or the SWID we are sending the message to.
126 * local_SWID is always our SWID. Note that having our SWID in the
127 * message is a little weird, but this is required.
128 */
129#define IPMI_LAN_ADDR_TYPE 0x04
130struct ipmi_lan_addr
131{
132 int addr_type;
133 short channel;
134 unsigned char privilege;
135 unsigned char session_handle;
136 unsigned char remote_SWID;
137 unsigned char local_SWID;
138 unsigned char lun;
139};
140
141
142/*
143 * Channel for talking directly with the BMC. When using this
144 * channel, This is for the system interface address type only. FIXME
145 * - is this right, or should we use -1?
146 */
147#define IPMI_BMC_CHANNEL 0xf
148#define IPMI_NUM_CHANNELS 0x10
149
150
151/*
152 * A raw IPMI message without any addressing. This covers both
153 * commands and responses. The completion code is always the first
154 * byte of data in the response (as the spec shows the messages laid
155 * out).
156 */
157struct ipmi_msg
158{
159 unsigned char netfn;
160 unsigned char cmd;
161 unsigned short data_len;
162 unsigned char __user *data;
163};
164
165struct kernel_ipmi_msg
166{
167 unsigned char netfn;
168 unsigned char cmd;
169 unsigned short data_len;
170 unsigned char *data;
171};
172
173/*
174 * Various defines that are useful for IPMI applications.
175 */
176#define IPMI_INVALID_CMD_COMPLETION_CODE 0xC1
177#define IPMI_TIMEOUT_COMPLETION_CODE 0xC3
178#define IPMI_UNKNOWN_ERR_COMPLETION_CODE 0xff
179
180
181/*
182 * Receive types for messages coming from the receive interface. This
183 * is used for the receive in-kernel interface and in the receive
184 * IOCTL.
185 *
186 * The "IPMI_RESPONSE_RESPNOSE_TYPE" is a little strange sounding, but
187 * it allows you to get the message results when you send a response
188 * message.
189 */
190#define IPMI_RESPONSE_RECV_TYPE 1 /* A response to a command */
191#define IPMI_ASYNC_EVENT_RECV_TYPE 2 /* Something from the event queue */
192#define IPMI_CMD_RECV_TYPE 3 /* A command from somewhere else */
193#define IPMI_RESPONSE_RESPONSE_TYPE 4 /* The response for
194 a sent response, giving any
195 error status for sending the
196 response. When you send a
197 response message, this will
198 be returned. */
199/* Note that async events and received commands do not have a completion
200 code as the first byte of the incoming data, unlike a response. */
201
202
203
204#ifdef __KERNEL__
205
206/*
207 * The in-kernel interface.
208 */
209#include <linux/list.h>
210#include <linux/module.h>
211
Corey Minyard3b625942005-06-23 22:01:42 -0700212#ifdef CONFIG_PROC_FS
213#include <linux/proc_fs.h>
214extern struct proc_dir_entry *proc_ipmi_root;
215#endif /* CONFIG_PROC_FS */
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217/* Opaque type for a IPMI message user. One of these is needed to
218 send and receive messages. */
219typedef struct ipmi_user *ipmi_user_t;
220
221/*
222 * Stuff coming from the receive interface comes as one of these.
223 * They are allocated, the receiver must free them with
224 * ipmi_free_recv_msg() when done with the message. The link is not
225 * used after the message is delivered, so the upper layer may use the
226 * link to build a linked list, if it likes.
227 */
228struct ipmi_recv_msg
229{
230 struct list_head link;
231
232 /* The type of message as defined in the "Receive Types"
233 defines above. */
234 int recv_type;
235
236 ipmi_user_t user;
237 struct ipmi_addr addr;
238 long msgid;
239 struct kernel_ipmi_msg msg;
240
241 /* The user_msg_data is the data supplied when a message was
242 sent, if this is a response to a sent message. If this is
243 not a response to a sent message, then user_msg_data will
244 be NULL. */
245 void *user_msg_data;
246
247 /* Call this when done with the message. It will presumably free
248 the message and do any other necessary cleanup. */
249 void (*done)(struct ipmi_recv_msg *msg);
250
251 /* Place-holder for the data, don't make any assumptions about
252 the size or existance of this, since it may change. */
253 unsigned char msg_data[IPMI_MAX_MSG_LENGTH];
254};
255
256/* Allocate and free the receive message. */
257static inline void ipmi_free_recv_msg(struct ipmi_recv_msg *msg)
258{
259 msg->done(msg);
260}
261
262struct ipmi_user_hndl
263{
264 /* Routine type to call when a message needs to be routed to
265 the upper layer. This will be called with some locks held,
266 the only IPMI routines that can be called are ipmi_request
267 and the alloc/free operations. The handler_data is the
268 variable supplied when the receive handler was registered. */
269 void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
270 void *user_msg_data);
271
272 /* Called when the interface detects a watchdog pre-timeout. If
273 this is NULL, it will be ignored for the user. */
274 void (*ipmi_watchdog_pretimeout)(void *handler_data);
275};
276
277/* Create a new user of the IPMI layer on the given interface number. */
278int ipmi_create_user(unsigned int if_num,
279 struct ipmi_user_hndl *handler,
280 void *handler_data,
281 ipmi_user_t *user);
282
283/* Destroy the given user of the IPMI layer. Note that after this
284 function returns, the system is guaranteed to not call any
285 callbacks for the user. Thus as long as you destroy all the users
286 before you unload a module, you will be safe. And if you destroy
287 the users before you destroy the callback structures, it should be
288 safe, too. */
289int ipmi_destroy_user(ipmi_user_t user);
290
291/* Get the IPMI version of the BMC we are talking to. */
292void ipmi_get_version(ipmi_user_t user,
293 unsigned char *major,
294 unsigned char *minor);
295
296/* Set and get the slave address and LUN that we will use for our
297 source messages. Note that this affects the interface, not just
298 this user, so it will affect all users of this interface. This is
299 so some initialization code can come in and do the OEM-specific
300 things it takes to determine your address (if not the BMC) and set
301 it for everyone else. */
302void ipmi_set_my_address(ipmi_user_t user,
303 unsigned char address);
304unsigned char ipmi_get_my_address(ipmi_user_t user);
305void ipmi_set_my_LUN(ipmi_user_t user,
306 unsigned char LUN);
307unsigned char ipmi_get_my_LUN(ipmi_user_t user);
308
309/*
310 * Like ipmi_request, but lets you specify the number of retries and
311 * the retry time. The retries is the number of times the message
312 * will be resent if no reply is received. If set to -1, the default
313 * value will be used. The retry time is the time in milliseconds
314 * between retries. If set to zero, the default value will be
315 * used.
316 *
317 * Don't use this unless you *really* have to. It's primarily for the
318 * IPMI over LAN converter; since the LAN stuff does its own retries,
319 * it makes no sense to do it here. However, this can be used if you
320 * have unusual requirements.
321 */
322int ipmi_request_settime(ipmi_user_t user,
323 struct ipmi_addr *addr,
324 long msgid,
325 struct kernel_ipmi_msg *msg,
326 void *user_msg_data,
327 int priority,
328 int max_retries,
329 unsigned int retry_time_ms);
330
331/*
332 * Like ipmi_request, but with messages supplied. This will not
333 * allocate any memory, and the messages may be statically allocated
334 * (just make sure to do the "done" handling on them). Note that this
335 * is primarily for the watchdog timer, since it should be able to
336 * send messages even if no memory is available. This is subject to
337 * change as the system changes, so don't use it unless you REALLY
338 * have to.
339 */
340int ipmi_request_supply_msgs(ipmi_user_t user,
341 struct ipmi_addr *addr,
342 long msgid,
343 struct kernel_ipmi_msg *msg,
344 void *user_msg_data,
345 void *supplied_smi,
346 struct ipmi_recv_msg *supplied_recv,
347 int priority);
348
349/*
350 * When commands come in to the SMS, the user can register to receive
351 * them. Only one user can be listening on a specific netfn/cmd pair
352 * at a time, you will get an EBUSY error if the command is already
353 * registered. If a command is received that does not have a user
354 * registered, the driver will automatically return the proper
355 * error.
356 */
357int ipmi_register_for_cmd(ipmi_user_t user,
358 unsigned char netfn,
359 unsigned char cmd);
360int ipmi_unregister_for_cmd(ipmi_user_t user,
361 unsigned char netfn,
362 unsigned char cmd);
363
364/*
365 * Allow run-to-completion mode to be set for the interface of
366 * a specific user.
367 */
368void ipmi_user_set_run_to_completion(ipmi_user_t user, int val);
369
370/*
371 * When the user is created, it will not receive IPMI events by
372 * default. The user must set this to TRUE to get incoming events.
373 * The first user that sets this to TRUE will receive all events that
374 * have been queued while no one was waiting for events.
375 */
376int ipmi_set_gets_events(ipmi_user_t user, int val);
377
378/*
379 * Called when a new SMI is registered. This will also be called on
380 * every existing interface when a new watcher is registered with
381 * ipmi_smi_watcher_register().
382 */
383struct ipmi_smi_watcher
384{
385 struct list_head link;
386
387 /* You must set the owner to the current module, if you are in
388 a module (generally just set it to "THIS_MODULE"). */
389 struct module *owner;
390
391 /* These two are called with read locks held for the interface
392 the watcher list. So you can add and remove users from the
393 IPMI interface, send messages, etc., but you cannot add
394 or remove SMI watchers or SMI interfaces. */
395 void (*new_smi)(int if_num);
396 void (*smi_gone)(int if_num);
397};
398
399int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
400int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
401
402/* The following are various helper functions for dealing with IPMI
403 addresses. */
404
405/* Return the maximum length of an IPMI address given it's type. */
406unsigned int ipmi_addr_length(int addr_type);
407
408/* Validate that the given IPMI address is valid. */
409int ipmi_validate_addr(struct ipmi_addr *addr, int len);
410
411#endif /* __KERNEL__ */
412
413
414/*
415 * The userland interface
416 */
417
418/*
419 * The userland interface for the IPMI driver is a standard character
420 * device, with each instance of an interface registered as a minor
421 * number under the major character device.
422 *
423 * The read and write calls do not work, to get messages in and out
424 * requires ioctl calls because of the complexity of the data. select
425 * and poll do work, so you can wait for input using the file
426 * descriptor, you just can use read to get it.
427 *
428 * In general, you send a command down to the interface and receive
429 * responses back. You can use the msgid value to correlate commands
430 * and responses, the driver will take care of figuring out which
431 * incoming messages are for which command and find the proper msgid
432 * value to report. You will only receive reponses for commands you
433 * send. Asynchronous events, however, go to all open users, so you
434 * must be ready to handle these (or ignore them if you don't care).
435 *
436 * The address type depends upon the channel type. When talking
437 * directly to the BMC (IPMC_BMC_CHANNEL), the address is ignored
438 * (IPMI_UNUSED_ADDR_TYPE). When talking to an IPMB channel, you must
439 * supply a valid IPMB address with the addr_type set properly.
440 *
441 * When talking to normal channels, the driver takes care of the
442 * details of formatting and sending messages on that channel. You do
443 * not, for instance, have to format a send command, you just send
444 * whatever command you want to the channel, the driver will create
445 * the send command, automatically issue receive command and get even
446 * commands, and pass those up to the proper user.
447 */
448
449
450/* The magic IOCTL value for this interface. */
451#define IPMI_IOC_MAGIC 'i'
452
453
454/* Messages sent to the interface are this format. */
455struct ipmi_req
456{
457 unsigned char __user *addr; /* Address to send the message to. */
458 unsigned int addr_len;
459
460 long msgid; /* The sequence number for the message. This
461 exact value will be reported back in the
462 response to this request if it is a command.
463 If it is a response, this will be used as
464 the sequence value for the response. */
465
466 struct ipmi_msg msg;
467};
468/*
469 * Send a message to the interfaces. error values are:
470 * - EFAULT - an address supplied was invalid.
471 * - EINVAL - The address supplied was not valid, or the command
472 * was not allowed.
473 * - EMSGSIZE - The message to was too large.
474 * - ENOMEM - Buffers could not be allocated for the command.
475 */
476#define IPMICTL_SEND_COMMAND _IOR(IPMI_IOC_MAGIC, 13, \
477 struct ipmi_req)
478
479/* Messages sent to the interface with timing parameters are this
480 format. */
481struct ipmi_req_settime
482{
483 struct ipmi_req req;
484
485 /* See ipmi_request_settime() above for details on these
486 values. */
487 int retries;
488 unsigned int retry_time_ms;
489};
490/*
491 * Send a message to the interfaces with timing parameters. error values
492 * are:
493 * - EFAULT - an address supplied was invalid.
494 * - EINVAL - The address supplied was not valid, or the command
495 * was not allowed.
496 * - EMSGSIZE - The message to was too large.
497 * - ENOMEM - Buffers could not be allocated for the command.
498 */
499#define IPMICTL_SEND_COMMAND_SETTIME _IOR(IPMI_IOC_MAGIC, 21, \
500 struct ipmi_req_settime)
501
502/* Messages received from the interface are this format. */
503struct ipmi_recv
504{
505 int recv_type; /* Is this a command, response or an
506 asyncronous event. */
507
508 unsigned char __user *addr; /* Address the message was from is put
509 here. The caller must supply the
510 memory. */
511 unsigned int addr_len; /* The size of the address buffer.
512 The caller supplies the full buffer
513 length, this value is updated to
514 the actual message length when the
515 message is received. */
516
517 long msgid; /* The sequence number specified in the request
518 if this is a response. If this is a command,
519 this will be the sequence number from the
520 command. */
521
522 struct ipmi_msg msg; /* The data field must point to a buffer.
523 The data_size field must be set to the
524 size of the message buffer. The
525 caller supplies the full buffer
526 length, this value is updated to the
527 actual message length when the message
528 is received. */
529};
530
531/*
532 * Receive a message. error values:
533 * - EAGAIN - no messages in the queue.
534 * - EFAULT - an address supplied was invalid.
535 * - EINVAL - The address supplied was not valid.
536 * - EMSGSIZE - The message to was too large to fit into the message buffer,
537 * the message will be left in the buffer. */
538#define IPMICTL_RECEIVE_MSG _IOWR(IPMI_IOC_MAGIC, 12, \
539 struct ipmi_recv)
540
541/*
542 * Like RECEIVE_MSG, but if the message won't fit in the buffer, it
543 * will truncate the contents instead of leaving the data in the
544 * buffer.
545 */
546#define IPMICTL_RECEIVE_MSG_TRUNC _IOWR(IPMI_IOC_MAGIC, 11, \
547 struct ipmi_recv)
548
549/* Register to get commands from other entities on this interface. */
550struct ipmi_cmdspec
551{
552 unsigned char netfn;
553 unsigned char cmd;
554};
555
556/*
557 * Register to receive a specific command. error values:
558 * - EFAULT - an address supplied was invalid.
559 * - EBUSY - The netfn/cmd supplied was already in use.
560 * - ENOMEM - could not allocate memory for the entry.
561 */
562#define IPMICTL_REGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 14, \
563 struct ipmi_cmdspec)
564/*
565 * Unregister a regsitered command. error values:
566 * - EFAULT - an address supplied was invalid.
567 * - ENOENT - The netfn/cmd was not found registered for this user.
568 */
569#define IPMICTL_UNREGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 15, \
570 struct ipmi_cmdspec)
571
572/*
573 * Set whether this interface receives events. Note that the first
574 * user registered for events will get all pending events for the
575 * interface. error values:
576 * - EFAULT - an address supplied was invalid.
577 */
578#define IPMICTL_SET_GETS_EVENTS_CMD _IOR(IPMI_IOC_MAGIC, 16, int)
579
580/*
581 * Set and get the slave address and LUN that we will use for our
582 * source messages. Note that this affects the interface, not just
583 * this user, so it will affect all users of this interface. This is
584 * so some initialization code can come in and do the OEM-specific
585 * things it takes to determine your address (if not the BMC) and set
586 * it for everyone else. You should probably leave the LUN alone.
587 */
588#define IPMICTL_SET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 17, unsigned int)
589#define IPMICTL_GET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 18, unsigned int)
590#define IPMICTL_SET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 19, unsigned int)
591#define IPMICTL_GET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 20, unsigned int)
592
593/*
594 * Get/set the default timing values for an interface. You shouldn't
595 * generally mess with these.
596 */
597struct ipmi_timing_parms
598{
599 int retries;
600 unsigned int retry_time_ms;
601};
602#define IPMICTL_SET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 22, \
603 struct ipmi_timing_parms)
604#define IPMICTL_GET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 23, \
605 struct ipmi_timing_parms)
606
607#endif /* __LINUX_IPMI_H */