[PATCH] dquot: add proper locking when using current->signal->tty
[usb.git] / include / linux / ipmi.h
blobd09fbeabf1dc976539384f1889299bfc2e69383e
1 /*
2 * ipmi.h
4 * MontaVista IPMI interface
6 * Author: MontaVista Software, Inc.
7 * Corey Minyard <minyard@mvista.com>
8 * source@mvista.com
10 * Copyright 2002 MontaVista Software Inc.
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.
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.
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.
34 #ifndef __LINUX_IPMI_H
35 #define __LINUX_IPMI_H
37 #include <linux/ipmi_msgdefs.h>
38 #include <linux/compiler.h>
41 * This file describes an interface to an IPMI driver. You have to
42 * have a fairly good understanding of IPMI to use this, so go read
43 * the specs first before actually trying to do anything.
45 * With that said, this driver provides a multi-user interface to the
46 * IPMI driver, and it allows multiple IPMI physical interfaces below
47 * the driver. The physical interfaces bind as a lower layer on the
48 * driver. They appear as interfaces to the application using this
49 * interface.
51 * Multi-user means that multiple applications may use the driver,
52 * send commands, receive responses, etc. The driver keeps track of
53 * commands the user sends and tracks the responses. The responses
54 * will go back to the application that send the command. If the
55 * response doesn't come back in time, the driver will return a
56 * timeout error response to the application. Asynchronous events
57 * from the BMC event queue will go to all users bound to the driver.
58 * The incoming event queue in the BMC will automatically be flushed
59 * if it becomes full and it is queried once a second to see if
60 * anything is in it. Incoming commands to the driver will get
61 * delivered as commands.
63 * This driver provides two main interfaces: one for in-kernel
64 * applications and another for userland applications. The
65 * capabilities are basically the same for both interface, although
66 * the interfaces are somewhat different. The stuff in the
67 * #ifdef KERNEL below is the in-kernel interface. The userland
68 * interface is defined later in the file. */
73 * This is an overlay for all the address types, so it's easy to
74 * determine the actual address type. This is kind of like addresses
75 * work for sockets.
77 #define IPMI_MAX_ADDR_SIZE 32
78 struct ipmi_addr
80 /* Try to take these from the "Channel Medium Type" table
81 in section 6.5 of the IPMI 1.5 manual. */
82 int addr_type;
83 short channel;
84 char data[IPMI_MAX_ADDR_SIZE];
88 * When the address is not used, the type will be set to this value.
89 * The channel is the BMC's channel number for the channel (usually
90 * 0), or IPMC_BMC_CHANNEL if communicating directly with the BMC.
92 #define IPMI_SYSTEM_INTERFACE_ADDR_TYPE 0x0c
93 struct ipmi_system_interface_addr
95 int addr_type;
96 short channel;
97 unsigned char lun;
100 /* An IPMB Address. */
101 #define IPMI_IPMB_ADDR_TYPE 0x01
102 /* Used for broadcast get device id as described in section 17.9 of the
103 IPMI 1.5 manual. */
104 #define IPMI_IPMB_BROADCAST_ADDR_TYPE 0x41
105 struct ipmi_ipmb_addr
107 int addr_type;
108 short channel;
109 unsigned char slave_addr;
110 unsigned char lun;
114 * A LAN Address. This is an address to/from a LAN interface bridged
115 * by the BMC, not an address actually out on the LAN.
117 * A concious decision was made here to deviate slightly from the IPMI
118 * spec. We do not use rqSWID and rsSWID like it shows in the
119 * message. Instead, we use remote_SWID and local_SWID. This means
120 * that any message (a request or response) from another device will
121 * always have exactly the same address. If you didn't do this,
122 * requests and responses from the same device would have different
123 * addresses, and that's not too cool.
125 * In this address, the remote_SWID is always the SWID the remote
126 * message came from, or the SWID we are sending the message to.
127 * local_SWID is always our SWID. Note that having our SWID in the
128 * message is a little weird, but this is required.
130 #define IPMI_LAN_ADDR_TYPE 0x04
131 struct ipmi_lan_addr
133 int addr_type;
134 short channel;
135 unsigned char privilege;
136 unsigned char session_handle;
137 unsigned char remote_SWID;
138 unsigned char local_SWID;
139 unsigned char lun;
144 * Channel for talking directly with the BMC. When using this
145 * channel, This is for the system interface address type only. FIXME
146 * - is this right, or should we use -1?
148 #define IPMI_BMC_CHANNEL 0xf
149 #define IPMI_NUM_CHANNELS 0x10
153 * A raw IPMI message without any addressing. This covers both
154 * commands and responses. The completion code is always the first
155 * byte of data in the response (as the spec shows the messages laid
156 * out).
158 struct ipmi_msg
160 unsigned char netfn;
161 unsigned char cmd;
162 unsigned short data_len;
163 unsigned char __user *data;
166 struct kernel_ipmi_msg
168 unsigned char netfn;
169 unsigned char cmd;
170 unsigned short data_len;
171 unsigned char *data;
175 * Various defines that are useful for IPMI applications.
177 #define IPMI_INVALID_CMD_COMPLETION_CODE 0xC1
178 #define IPMI_TIMEOUT_COMPLETION_CODE 0xC3
179 #define IPMI_UNKNOWN_ERR_COMPLETION_CODE 0xff
183 * Receive types for messages coming from the receive interface. This
184 * is used for the receive in-kernel interface and in the receive
185 * IOCTL.
187 * The "IPMI_RESPONSE_RESPNOSE_TYPE" is a little strange sounding, but
188 * it allows you to get the message results when you send a response
189 * message.
191 #define IPMI_RESPONSE_RECV_TYPE 1 /* A response to a command */
192 #define IPMI_ASYNC_EVENT_RECV_TYPE 2 /* Something from the event queue */
193 #define IPMI_CMD_RECV_TYPE 3 /* A command from somewhere else */
194 #define IPMI_RESPONSE_RESPONSE_TYPE 4 /* The response for
195 a sent response, giving any
196 error status for sending the
197 response. When you send a
198 response message, this will
199 be returned. */
200 /* Note that async events and received commands do not have a completion
201 code as the first byte of the incoming data, unlike a response. */
205 #ifdef __KERNEL__
208 * The in-kernel interface.
210 #include <linux/list.h>
211 #include <linux/module.h>
212 #include <linux/device.h>
213 #include <linux/proc_fs.h>
215 /* Opaque type for a IPMI message user. One of these is needed to
216 send and receive messages. */
217 typedef struct ipmi_user *ipmi_user_t;
220 * Stuff coming from the receive interface comes as one of these.
221 * They are allocated, the receiver must free them with
222 * ipmi_free_recv_msg() when done with the message. The link is not
223 * used after the message is delivered, so the upper layer may use the
224 * link to build a linked list, if it likes.
226 struct ipmi_recv_msg
228 struct list_head link;
230 /* The type of message as defined in the "Receive Types"
231 defines above. */
232 int recv_type;
234 ipmi_user_t user;
235 struct ipmi_addr addr;
236 long msgid;
237 struct kernel_ipmi_msg msg;
239 /* The user_msg_data is the data supplied when a message was
240 sent, if this is a response to a sent message. If this is
241 not a response to a sent message, then user_msg_data will
242 be NULL. If the user above is NULL, then this will be the
243 intf. */
244 void *user_msg_data;
246 /* Call this when done with the message. It will presumably free
247 the message and do any other necessary cleanup. */
248 void (*done)(struct ipmi_recv_msg *msg);
250 /* Place-holder for the data, don't make any assumptions about
251 the size or existance of this, since it may change. */
252 unsigned char msg_data[IPMI_MAX_MSG_LENGTH];
255 /* Allocate and free the receive message. */
256 void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
258 struct ipmi_user_hndl
260 /* Routine type to call when a message needs to be routed to
261 the upper layer. This will be called with some locks held,
262 the only IPMI routines that can be called are ipmi_request
263 and the alloc/free operations. The handler_data is the
264 variable supplied when the receive handler was registered. */
265 void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
266 void *user_msg_data);
268 /* Called when the interface detects a watchdog pre-timeout. If
269 this is NULL, it will be ignored for the user. */
270 void (*ipmi_watchdog_pretimeout)(void *handler_data);
273 /* Create a new user of the IPMI layer on the given interface number. */
274 int ipmi_create_user(unsigned int if_num,
275 struct ipmi_user_hndl *handler,
276 void *handler_data,
277 ipmi_user_t *user);
279 /* Destroy the given user of the IPMI layer. Note that after this
280 function returns, the system is guaranteed to not call any
281 callbacks for the user. Thus as long as you destroy all the users
282 before you unload a module, you will be safe. And if you destroy
283 the users before you destroy the callback structures, it should be
284 safe, too. */
285 int ipmi_destroy_user(ipmi_user_t user);
287 /* Get the IPMI version of the BMC we are talking to. */
288 void ipmi_get_version(ipmi_user_t user,
289 unsigned char *major,
290 unsigned char *minor);
292 /* Set and get the slave address and LUN that we will use for our
293 source messages. Note that this affects the interface, not just
294 this user, so it will affect all users of this interface. This is
295 so some initialization code can come in and do the OEM-specific
296 things it takes to determine your address (if not the BMC) and set
297 it for everyone else. Note that each channel can have its own address. */
298 int ipmi_set_my_address(ipmi_user_t user,
299 unsigned int channel,
300 unsigned char address);
301 int ipmi_get_my_address(ipmi_user_t user,
302 unsigned int channel,
303 unsigned char *address);
304 int ipmi_set_my_LUN(ipmi_user_t user,
305 unsigned int channel,
306 unsigned char LUN);
307 int ipmi_get_my_LUN(ipmi_user_t user,
308 unsigned int channel,
309 unsigned char *LUN);
312 * Like ipmi_request, but lets you specify the number of retries and
313 * the retry time. The retries is the number of times the message
314 * will be resent if no reply is received. If set to -1, the default
315 * value will be used. The retry time is the time in milliseconds
316 * between retries. If set to zero, the default value will be
317 * used.
319 * Don't use this unless you *really* have to. It's primarily for the
320 * IPMI over LAN converter; since the LAN stuff does its own retries,
321 * it makes no sense to do it here. However, this can be used if you
322 * have unusual requirements.
324 int ipmi_request_settime(ipmi_user_t user,
325 struct ipmi_addr *addr,
326 long msgid,
327 struct kernel_ipmi_msg *msg,
328 void *user_msg_data,
329 int priority,
330 int max_retries,
331 unsigned int retry_time_ms);
334 * Like ipmi_request, but with messages supplied. This will not
335 * allocate any memory, and the messages may be statically allocated
336 * (just make sure to do the "done" handling on them). Note that this
337 * is primarily for the watchdog timer, since it should be able to
338 * send messages even if no memory is available. This is subject to
339 * change as the system changes, so don't use it unless you REALLY
340 * have to.
342 int ipmi_request_supply_msgs(ipmi_user_t user,
343 struct ipmi_addr *addr,
344 long msgid,
345 struct kernel_ipmi_msg *msg,
346 void *user_msg_data,
347 void *supplied_smi,
348 struct ipmi_recv_msg *supplied_recv,
349 int priority);
352 * When commands come in to the SMS, the user can register to receive
353 * them. Only one user can be listening on a specific netfn/cmd pair
354 * at a time, you will get an EBUSY error if the command is already
355 * registered. If a command is received that does not have a user
356 * registered, the driver will automatically return the proper
357 * error.
359 int ipmi_register_for_cmd(ipmi_user_t user,
360 unsigned char netfn,
361 unsigned char cmd);
362 int ipmi_unregister_for_cmd(ipmi_user_t user,
363 unsigned char netfn,
364 unsigned char cmd);
367 * Allow run-to-completion mode to be set for the interface of
368 * a specific user.
370 void ipmi_user_set_run_to_completion(ipmi_user_t user, int val);
373 * When the user is created, it will not receive IPMI events by
374 * default. The user must set this to TRUE to get incoming events.
375 * The first user that sets this to TRUE will receive all events that
376 * have been queued while no one was waiting for events.
378 int ipmi_set_gets_events(ipmi_user_t user, int val);
381 * Called when a new SMI is registered. This will also be called on
382 * every existing interface when a new watcher is registered with
383 * ipmi_smi_watcher_register().
385 struct ipmi_smi_watcher
387 struct list_head link;
389 /* You must set the owner to the current module, if you are in
390 a module (generally just set it to "THIS_MODULE"). */
391 struct module *owner;
393 /* These two are called with read locks held for the interface
394 the watcher list. So you can add and remove users from the
395 IPMI interface, send messages, etc., but you cannot add
396 or remove SMI watchers or SMI interfaces. */
397 void (*new_smi)(int if_num, struct device *dev);
398 void (*smi_gone)(int if_num);
401 int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
402 int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
404 /* The following are various helper functions for dealing with IPMI
405 addresses. */
407 /* Return the maximum length of an IPMI address given it's type. */
408 unsigned int ipmi_addr_length(int addr_type);
410 /* Validate that the given IPMI address is valid. */
411 int ipmi_validate_addr(struct ipmi_addr *addr, int len);
413 #endif /* __KERNEL__ */
417 * The userland interface
421 * The userland interface for the IPMI driver is a standard character
422 * device, with each instance of an interface registered as a minor
423 * number under the major character device.
425 * The read and write calls do not work, to get messages in and out
426 * requires ioctl calls because of the complexity of the data. select
427 * and poll do work, so you can wait for input using the file
428 * descriptor, you just can use read to get it.
430 * In general, you send a command down to the interface and receive
431 * responses back. You can use the msgid value to correlate commands
432 * and responses, the driver will take care of figuring out which
433 * incoming messages are for which command and find the proper msgid
434 * value to report. You will only receive reponses for commands you
435 * send. Asynchronous events, however, go to all open users, so you
436 * must be ready to handle these (or ignore them if you don't care).
438 * The address type depends upon the channel type. When talking
439 * directly to the BMC (IPMC_BMC_CHANNEL), the address is ignored
440 * (IPMI_UNUSED_ADDR_TYPE). When talking to an IPMB channel, you must
441 * supply a valid IPMB address with the addr_type set properly.
443 * When talking to normal channels, the driver takes care of the
444 * details of formatting and sending messages on that channel. You do
445 * not, for instance, have to format a send command, you just send
446 * whatever command you want to the channel, the driver will create
447 * the send command, automatically issue receive command and get even
448 * commands, and pass those up to the proper user.
452 /* The magic IOCTL value for this interface. */
453 #define IPMI_IOC_MAGIC 'i'
456 /* Messages sent to the interface are this format. */
457 struct ipmi_req
459 unsigned char __user *addr; /* Address to send the message to. */
460 unsigned int addr_len;
462 long msgid; /* The sequence number for the message. This
463 exact value will be reported back in the
464 response to this request if it is a command.
465 If it is a response, this will be used as
466 the sequence value for the response. */
468 struct ipmi_msg msg;
471 * Send a message to the interfaces. error values are:
472 * - EFAULT - an address supplied was invalid.
473 * - EINVAL - The address supplied was not valid, or the command
474 * was not allowed.
475 * - EMSGSIZE - The message to was too large.
476 * - ENOMEM - Buffers could not be allocated for the command.
478 #define IPMICTL_SEND_COMMAND _IOR(IPMI_IOC_MAGIC, 13, \
479 struct ipmi_req)
481 /* Messages sent to the interface with timing parameters are this
482 format. */
483 struct ipmi_req_settime
485 struct ipmi_req req;
487 /* See ipmi_request_settime() above for details on these
488 values. */
489 int retries;
490 unsigned int retry_time_ms;
493 * Send a message to the interfaces with timing parameters. error values
494 * are:
495 * - EFAULT - an address supplied was invalid.
496 * - EINVAL - The address supplied was not valid, or the command
497 * was not allowed.
498 * - EMSGSIZE - The message to was too large.
499 * - ENOMEM - Buffers could not be allocated for the command.
501 #define IPMICTL_SEND_COMMAND_SETTIME _IOR(IPMI_IOC_MAGIC, 21, \
502 struct ipmi_req_settime)
504 /* Messages received from the interface are this format. */
505 struct ipmi_recv
507 int recv_type; /* Is this a command, response or an
508 asyncronous event. */
510 unsigned char __user *addr; /* Address the message was from is put
511 here. The caller must supply the
512 memory. */
513 unsigned int addr_len; /* The size of the address buffer.
514 The caller supplies the full buffer
515 length, this value is updated to
516 the actual message length when the
517 message is received. */
519 long msgid; /* The sequence number specified in the request
520 if this is a response. If this is a command,
521 this will be the sequence number from the
522 command. */
524 struct ipmi_msg msg; /* The data field must point to a buffer.
525 The data_size field must be set to the
526 size of the message buffer. The
527 caller supplies the full buffer
528 length, this value is updated to the
529 actual message length when the message
530 is received. */
534 * Receive a message. error values:
535 * - EAGAIN - no messages in the queue.
536 * - EFAULT - an address supplied was invalid.
537 * - EINVAL - The address supplied was not valid.
538 * - EMSGSIZE - The message to was too large to fit into the message buffer,
539 * the message will be left in the buffer. */
540 #define IPMICTL_RECEIVE_MSG _IOWR(IPMI_IOC_MAGIC, 12, \
541 struct ipmi_recv)
544 * Like RECEIVE_MSG, but if the message won't fit in the buffer, it
545 * will truncate the contents instead of leaving the data in the
546 * buffer.
548 #define IPMICTL_RECEIVE_MSG_TRUNC _IOWR(IPMI_IOC_MAGIC, 11, \
549 struct ipmi_recv)
551 /* Register to get commands from other entities on this interface. */
552 struct ipmi_cmdspec
554 unsigned char netfn;
555 unsigned char cmd;
559 * Register to receive a specific command. error values:
560 * - EFAULT - an address supplied was invalid.
561 * - EBUSY - The netfn/cmd supplied was already in use.
562 * - ENOMEM - could not allocate memory for the entry.
564 #define IPMICTL_REGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 14, \
565 struct ipmi_cmdspec)
567 * Unregister a regsitered command. error values:
568 * - EFAULT - an address supplied was invalid.
569 * - ENOENT - The netfn/cmd was not found registered for this user.
571 #define IPMICTL_UNREGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 15, \
572 struct ipmi_cmdspec)
575 * Set whether this interface receives events. Note that the first
576 * user registered for events will get all pending events for the
577 * interface. error values:
578 * - EFAULT - an address supplied was invalid.
580 #define IPMICTL_SET_GETS_EVENTS_CMD _IOR(IPMI_IOC_MAGIC, 16, int)
583 * Set and get the slave address and LUN that we will use for our
584 * source messages. Note that this affects the interface, not just
585 * this user, so it will affect all users of this interface. This is
586 * so some initialization code can come in and do the OEM-specific
587 * things it takes to determine your address (if not the BMC) and set
588 * it for everyone else. You should probably leave the LUN alone.
590 struct ipmi_channel_lun_address_set
592 unsigned short channel;
593 unsigned char value;
595 #define IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 24, struct ipmi_channel_lun_address_set)
596 #define IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 25, struct ipmi_channel_lun_address_set)
597 #define IPMICTL_SET_MY_CHANNEL_LUN_CMD _IOR(IPMI_IOC_MAGIC, 26, struct ipmi_channel_lun_address_set)
598 #define IPMICTL_GET_MY_CHANNEL_LUN_CMD _IOR(IPMI_IOC_MAGIC, 27, struct ipmi_channel_lun_address_set)
599 /* Legacy interfaces, these only set IPMB 0. */
600 #define IPMICTL_SET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 17, unsigned int)
601 #define IPMICTL_GET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 18, unsigned int)
602 #define IPMICTL_SET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 19, unsigned int)
603 #define IPMICTL_GET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 20, unsigned int)
606 * Get/set the default timing values for an interface. You shouldn't
607 * generally mess with these.
609 struct ipmi_timing_parms
611 int retries;
612 unsigned int retry_time_ms;
614 #define IPMICTL_SET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 22, \
615 struct ipmi_timing_parms)
616 #define IPMICTL_GET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 23, \
617 struct ipmi_timing_parms)
619 #endif /* __LINUX_IPMI_H */