00001 /* 00002 * ipmi.h 00003 * 00004 * MontaVista IPMI interface 00005 * 00006 * Author: MontaVista Software, Inc. 00007 * Corey Minyard <minyard@mvista.com> 00008 * source@mvista.com 00009 * 00010 * Copyright 2002,2003 MontaVista Software Inc. 00011 * 00012 * This program is free software; you can redistribute it and/or modify it 00013 * under the terms of the GNU General Public License as published by the 00014 * Free Software Foundation; either version 2 of the License, or (at your 00015 * option) any later version. 00016 * 00017 * 00018 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00019 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00020 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00021 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00022 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00023 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00024 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00025 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 00026 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00027 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 * 00029 * You should have received a copy of the GNU General Public License along 00030 * with this program; if not, write to the Free Software Foundation, Inc., 00031 * 675 Mass Ave, Cambridge, MA 02139, USA. 00032 */ 00033 00034 #ifndef __LINUX_IPMI_H 00035 #define __LINUX_IPMI_H 00036 00037 #include <linux/ipmi_msgdefs.h> 00038 00039 /* 00040 * This file describes an interface to an IPMI driver. You have to 00041 * have a fairly good understanding of IPMI to use this, so go read 00042 * the specs first before actually trying to do anything. 00043 * 00044 * With that said, this driver provides a multi-user interface to the 00045 * IPMI driver, and it allows multiple IPMI physical interfaces below 00046 * the driver. The physical interfaces bind as a lower layer on the 00047 * driver. They appear as interfaces to the application using this 00048 * interface. 00049 * 00050 * Multi-user means that multiple applications may use the driver, 00051 * send commands, receive responses, etc. The driver keeps track of 00052 * commands the user sends and tracks the responses. The responses 00053 * will go back to the application that send the command. If the 00054 * response doesn't come back in time, the driver will return a 00055 * timeout error response to the application. Asynchronous events 00056 * from the BMC event queue will go to all users bound to the driver. 00057 * The incoming event queue in the BMC will automatically be flushed 00058 * if it becomes full and it is queried once a second to see if 00059 * anything is in it. Incoming commands to the driver will get 00060 * delivered as commands. 00061 * 00062 * This driver provides two main interfaces: one for in-kernel 00063 * applications and another for userland applications. The 00064 * capabilities are basically the same for both interface, although 00065 * the interfaces are somewhat different. The stuff in the 00066 * #ifdef KERNEL below is the in-kernel interface. The userland 00067 * interface is defined later in the file. */ 00068 00069 00070 00071 /* 00072 * This is an overlay for all the address types, so it's easy to 00073 * determine the actual address type. This is kind of like addresses 00074 * work for sockets. 00075 */ 00076 #define IPMI_MAX_ADDR_SIZE 32 00077 struct ipmi_addr 00078 { 00079 /* Try to take these from the "Channel Medium Type" table 00080 in section 6.5 of the IPMI 1.5 manual. */ 00081 int addr_type; 00082 short channel; 00083 char data[IPMI_MAX_ADDR_SIZE]; 00084 }; 00085 00086 /* 00087 * When the address is not used, the type will be set to this value. 00088 * The channel is the BMC's channel number for the channel (usually 00089 * 0), or IPMC_BMC_CHANNEL if communicating directly with the BMC. 00090 */ 00091 #define IPMI_SYSTEM_INTERFACE_ADDR_TYPE 0x0c 00092 struct ipmi_system_interface_addr 00093 { 00094 int addr_type; 00095 short channel; 00096 unsigned char lun; 00097 }; 00098 00099 /* An IPMB Address. */ 00100 #define IPMI_IPMB_ADDR_TYPE 0x01 00101 /* Used for broadcast get device id as described in section 17.9 of the 00102 IPMI 1.5 manual. */ 00103 #define IPMI_IPMB_BROADCAST_ADDR_TYPE 0x41 00104 struct ipmi_ipmb_addr 00105 { 00106 int addr_type; 00107 short channel; 00108 unsigned char slave_addr; 00109 unsigned char lun; 00110 }; 00111 00112 00113 /* 00114 * Channel for talking directly with the BMC. When using this 00115 * channel, This is for the system interface address type only. FIXME 00116 * - is this right, or should we use -1? 00117 */ 00118 #define IPMI_BMC_CHANNEL 0xf 00119 #define IPMI_NUM_CHANNELS 0x10 00120 00121 00122 /* 00123 * A raw IPMI message without any addressing. This covers both 00124 * commands and responses. The completion code is always the first 00125 * byte of data in the response (as the spec shows the messages laid 00126 * out). 00127 */ 00128 struct ipmi_msg 00129 { 00130 unsigned char netfn; 00131 unsigned char cmd; 00132 unsigned short data_len; 00133 unsigned char *data; 00134 }; 00135 00136 /* 00137 * Various defines that are useful for IPMI applications. 00138 */ 00139 #define IPMI_INVALID_CMD_COMPLETION_CODE 0xC1 00140 #define IPMI_TIMEOUT_COMPLETION_CODE 0xC3 00141 #define IPMI_UNKNOWN_ERR_COMPLETION_CODE 0xff 00142 00143 00144 /* 00145 * Receive types for messages coming from the receive interface. This 00146 * is used for the receive in-kernel interface and in the receive 00147 * IOCTL. 00148 */ 00149 #define IPMI_RESPONSE_RECV_TYPE 1 /* A response to a command */ 00150 #define IPMI_ASYNC_EVENT_RECV_TYPE 2 /* Something from the event queue */ 00151 #define IPMI_CMD_RECV_TYPE 3 /* A command from somewhere else */ 00152 /* Note that async events and received commands do not have a completion 00153 code as the first byte of the incoming data, unlike a response. */ 00154 00155 00156 00157 #ifdef __KERNEL__ 00158 00159 /* 00160 * The in-kernel interface. 00161 */ 00162 #include <linux/list.h> 00163 00164 /* Opaque type for a IPMI message user. One of these is needed to 00165 send and receive messages. */ 00166 typedef struct ipmi_user *ipmi_user_t; 00167 00168 /* 00169 * Stuff coming from the recieve interface comes as one of these. 00170 * They are allocated, the receiver must free them with 00171 * ipmi_free_recv_msg() when done with the message. The link is not 00172 * used after the message is delivered, so the upper layer may use the 00173 * link to build a linked list, if it likes. 00174 */ 00175 struct ipmi_recv_msg 00176 { 00177 struct list_head link; 00178 00179 /* The type of message as defined in the "Receive Types" 00180 defines above. */ 00181 int recv_type; 00182 00183 ipmi_user_t user; 00184 struct ipmi_addr addr; 00185 long msgid; 00186 struct ipmi_msg msg; 00187 00188 /* Call this when done with the message. It will presumably free 00189 the message and do any other necessary cleanup. */ 00190 void (*done)(struct ipmi_recv_msg *msg); 00191 00192 /* Place-holder for the data, don't make any assumptions about 00193 the size or existance of this, since it may change. */ 00194 unsigned char msg_data[IPMI_MAX_MSG_LENGTH]; 00195 }; 00196 00197 /* Allocate and free the receive message. */ 00198 static inline void ipmi_free_recv_msg(struct ipmi_recv_msg *msg) 00199 { 00200 msg->done(msg); 00201 } 00202 struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); 00203 00204 struct ipmi_user_hndl 00205 { 00206 /* Routine type to call when a message needs to be routed to 00207 the upper layer. This will be called with some locks held, 00208 the only IPMI routines that can be called are ipmi_request 00209 and the alloc/free operations. */ 00210 void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg, 00211 void *handler_data); 00212 00213 /* Called when the interface detects a watchdog pre-timeout. If 00214 this is NULL, it will be ignored for the user. */ 00215 void (*ipmi_watchdog_pretimeout)(void *handler_data); 00216 }; 00217 00218 /* Create a new user of the IPMI layer on the given interface number. */ 00219 int ipmi_create_user(unsigned int if_num, 00220 struct ipmi_user_hndl *handler, 00221 void *handler_data, 00222 ipmi_user_t *user); 00223 00224 /* Destroy the given user of the IPMI layer. */ 00225 int ipmi_destroy_user(ipmi_user_t user); 00226 00227 /* Get the IPMI version of the BMC we are talking to. */ 00228 void ipmi_get_version(ipmi_user_t user, 00229 unsigned char *major, 00230 unsigned char *minor); 00231 00232 /* Set and get the slave address and LUN that we will use for our 00233 source messages. Note that this affects the interface, not just 00234 this user, so it will affect all users of this interface. This is 00235 so some initialization code can come in and do the OEM-specific 00236 things it takes to determine your address (if not the BMC) and set 00237 it for everyone else. */ 00238 void ipmi_set_my_address(ipmi_user_t user, 00239 unsigned char address); 00240 unsigned char ipmi_get_my_address(ipmi_user_t user); 00241 void ipmi_set_my_LUN(ipmi_user_t user, 00242 unsigned char LUN); 00243 unsigned char ipmi_get_my_LUN(ipmi_user_t user); 00244 00245 /* 00246 * Send a command request from the given user. The address is the 00247 * proper address for the channel type. If this is a command, then 00248 * the message response comes back, the receive handler for this user 00249 * will be called with the given msgid value in the recv msg. If this 00250 * is a response to a command, then the msgid will be used as the 00251 * sequence number for the response (truncated if necessary), so when 00252 * sending a response you should use the sequence number you received 00253 * in the msgid field of the received command. If the priority is > 00254 * 0, the message will go into a high-priority queue and be sent 00255 * first. Otherwise, it goes into a normal-priority queue. 00256 */ 00257 int ipmi_request(ipmi_user_t user, 00258 struct ipmi_addr *addr, 00259 long msgid, 00260 struct ipmi_msg *msg, 00261 int priority); 00262 00263 /* 00264 * Like ipmi_request, but lets you specify the slave return address. 00265 */ 00266 int ipmi_request_with_source(ipmi_user_t user, 00267 struct ipmi_addr *addr, 00268 long msgid, 00269 struct ipmi_msg *msg, 00270 int priority, 00271 unsigned char source_address, 00272 unsigned char source_lun); 00273 00274 /* 00275 * Like ipmi_request, but with messages supplied. This will not 00276 * allocate any memory, and the messages may be statically allocated 00277 * (just make sure to do the "done" handling on them). Note that this 00278 * is primarily for the watchdog timer, since it should be able to 00279 * send messages even if no memory is available. This is subject to 00280 * change as the system changes, so don't use it unless you REALLY 00281 * have to. 00282 */ 00283 int ipmi_request_supply_msgs(ipmi_user_t user, 00284 struct ipmi_addr *addr, 00285 long msgid, 00286 struct ipmi_msg *msg, 00287 void *supplied_smi, 00288 struct ipmi_recv_msg *supplied_recv, 00289 int priority); 00290 00291 /* 00292 * When commands come in to the SMS, the user can register to receive 00293 * them. Only one user can be listening on a specific netfn/cmd pair 00294 * at a time, you will get an EBUSY error if the command is already 00295 * registered. If a command is received that does not have a user 00296 * registered, the driver will automatically return the proper 00297 * error. 00298 */ 00299 int ipmi_register_for_cmd(ipmi_user_t user, 00300 unsigned char netfn, 00301 unsigned char cmd); 00302 int ipmi_unregister_for_cmd(ipmi_user_t user, 00303 unsigned char netfn, 00304 unsigned char cmd); 00305 00306 /* 00307 * When the user is created, it will not receive IPMI events by 00308 * default. The user must set this to TRUE to get incoming events. 00309 * The first user that sets this to TRUE will receive all events that 00310 * have been queued while no one was waiting for events. 00311 */ 00312 int ipmi_set_gets_events(ipmi_user_t user, int val); 00313 00314 /* 00315 * Register the given user to handle all received IPMI commands. This 00316 * will fail if anyone is registered as a command receiver or if 00317 * another is already registered to receive all commands. NOTE THAT 00318 * THIS IS FOR EMULATION USERS ONLY, DO NOT USER THIS FOR NORMAL 00319 * STUFF. 00320 */ 00321 int ipmi_register_all_cmd_rcvr(ipmi_user_t user); 00322 int ipmi_unregister_all_cmd_rcvr(ipmi_user_t user); 00323 00324 00325 /* 00326 * Called when a new SMI is registered. This will also be called on 00327 * every existing interface when a new watcher is registered with 00328 * ipmi_smi_watcher_register(). 00329 */ 00330 struct ipmi_smi_watcher 00331 { 00332 struct list_head link; 00333 00334 /* These two are called with read locks held for the interface 00335 the watcher list. So you can add and remove users from the 00336 IPMI interface, send messages, etc., but you cannot add 00337 or remove SMI watchers or SMI interfaces. */ 00338 void (*new_smi)(int if_num); 00339 void (*smi_gone)(int if_num); 00340 }; 00341 00342 int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher); 00343 int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher); 00344 00345 /* The following are various helper functions for dealing with IPMI 00346 addresses. */ 00347 00348 /* Return the maximum length of an IPMI address given it's type. */ 00349 unsigned int ipmi_addr_length(int addr_type); 00350 00351 /* Validate that the given IPMI address is valid. */ 00352 int ipmi_validate_addr(struct ipmi_addr *addr, int len); 00353 00354 /* Return 1 if the given addresses are equal, 0 if not. */ 00355 int ipmi_addr_equal(struct ipmi_addr *addr1, struct ipmi_addr *addr2); 00356 00357 #endif /* __KERNEL__ */ 00358 00359 00360 /* 00361 * The userland interface 00362 */ 00363 00364 /* 00365 * The userland interface for the IPMI driver is a standard character 00366 * device, with each instance of an interface registered as a minor 00367 * number under the major character device. 00368 * 00369 * The read and write calls do not work, to get messages in and out 00370 * requires ioctl calls because of the complexity of the data. select 00371 * and poll do work, so you can wait for input using the file 00372 * descriptor, you just can use read to get it. 00373 * 00374 * In general, you send a command down to the interface and receive 00375 * responses back. You can use the msgid value to correlate commands 00376 * and responses, the driver will take care of figuring out which 00377 * incoming messages are for which command and find the proper msgid 00378 * value to report. You will only receive reponses for commands you 00379 * send. Asynchronous events, however, go to all open users, so you 00380 * must be ready to handle these (or ignore them if you don't care). 00381 * 00382 * The address type depends upon the channel type. When talking 00383 * directly to the BMC (IPMC_BMC_CHANNEL), the address is ignored 00384 * (IPMI_UNUSED_ADDR_TYPE). When talking to an IPMB channel, you must 00385 * supply a valid IPMB address with the addr_type set properly. 00386 * 00387 * When talking to normal channels, the driver takes care of the 00388 * details of formatting and sending messages on that channel. You do 00389 * not, for instance, have to format a send command, you just send 00390 * whatever command you want to the channel, the driver will create 00391 * the send command, automatically issue receive command and get even 00392 * commands, and pass those up to the proper user. 00393 */ 00394 00395 00396 /* The magic IOCTL value for this interface. */ 00397 #define IPMI_IOC_MAGIC 'i' 00398 00399 00400 /* Messages sent to the interface are this format. */ 00401 struct ipmi_req 00402 { 00403 unsigned char *addr; /* Address to send the message to. */ 00404 unsigned int addr_len; 00405 00406 long msgid; /* The sequence number for the message. This 00407 exact value will be reported back in the 00408 response to this request if it is a command. 00409 If it is a response, this will be used as 00410 the sequence value for the response. */ 00411 00412 struct ipmi_msg msg; 00413 }; 00414 /* 00415 * Send a message to the interfaces. error values are: 00416 * - EFAULT - an address supplied was invalid. 00417 * - EINVAL - The address supplied was not valid, or the command 00418 * was not allowed. 00419 * - EMSGSIZE - The message to was too large. 00420 * - ENOMEM - Buffers could not be allocated for the command. 00421 */ 00422 #define IPMICTL_SEND_COMMAND _IOR(IPMI_IOC_MAGIC, 13, \ 00423 struct ipmi_req) 00424 00425 /* Messages sent to the interface with timing parameters are this 00426 format. */ 00427 struct ipmi_req_settime 00428 { 00429 struct ipmi_req req; 00430 00431 /* See below for details on these values. */ 00432 int retries; 00433 unsigned int retry_time_ms; 00434 }; 00435 /* 00436 * Like IPMI_SEND_COMMAND, but lets you specify the number of retries and 00437 * the retry time. The retries is the number of times the message 00438 * will be resent if no reply is received. If set to -1, the default 00439 * value will be used. The retry time is the time in milliseconds 00440 * between retries. If set to zero, the default value will be 00441 * used. 00442 * 00443 * Don't use this unless you *really* have to. It's primarily for the 00444 * IPMI over LAN converter; since the LAN stuff does its own retries, 00445 * it makes no sense to do it here. However, this can be used if you 00446 * have unusual requirements. 00447 * 00448 * Error values are: 00449 * - EFAULT - an address supplied was invalid. 00450 * - EINVAL - The address supplied was not valid, or the command 00451 * was not allowed. 00452 * - EMSGSIZE - The message to was too large. 00453 * - ENOMEM - Buffers could not be allocated for the command. 00454 */ 00455 #define IPMICTL_SEND_COMMAND_SETTIME _IOR(IPMI_IOC_MAGIC, 21, \ 00456 struct ipmi_req_settime) 00457 00458 /* Messages received from the interface are this format. */ 00459 struct ipmi_recv 00460 { 00461 int recv_type; /* Is this a command, response or an 00462 asyncronous event. */ 00463 00464 unsigned char *addr; /* Address the message was from is put 00465 here. The caller must supply the 00466 memory. */ 00467 unsigned int addr_len; /* The size of the address buffer. 00468 The caller supplies the full buffer 00469 length, this value is updated to 00470 the actual message length when the 00471 message is received. */ 00472 00473 long msgid; /* The sequence number specified in the request 00474 if this is a response. If this is a command, 00475 this will be the sequence number from the 00476 command. */ 00477 00478 struct ipmi_msg msg; /* The data field must point to a buffer. 00479 The data_size field must be set to the 00480 size of the message buffer. The 00481 caller supplies the full buffer 00482 length, this value is updated to the 00483 actual message length when the message 00484 is received. */ 00485 }; 00486 00487 /* 00488 * Receive a message. error values: 00489 * - EAGAIN - no messages in the queue. 00490 * - EFAULT - an address supplied was invalid. 00491 * - EINVAL - The address supplied was not valid. 00492 * - EMSGSIZE - The message to was too large to fit into the message buffer, 00493 * the message will be left in the buffer. */ 00494 #define IPMICTL_RECEIVE_MSG _IOWR(IPMI_IOC_MAGIC, 12, \ 00495 struct ipmi_recv) 00496 00497 /* 00498 * Like RECEIVE_MSG, but if the message won't fit in the buffer, it 00499 * will truncate the contents instead of leaving the data in the 00500 * buffer. 00501 */ 00502 #define IPMICTL_RECEIVE_MSG_TRUNC _IOWR(IPMI_IOC_MAGIC, 11, \ 00503 struct ipmi_recv) 00504 00505 /* Register to get commands from other entities on this interface. */ 00506 struct ipmi_cmdspec 00507 { 00508 unsigned char netfn; 00509 unsigned char cmd; 00510 }; 00511 00512 /* 00513 * Register to receive a specific command. error values: 00514 * - EFAULT - an address supplied was invalid. 00515 * - EBUSY - The netfn/cmd supplied was already in use. 00516 * - ENOMEM - could not allocate memory for the entry. 00517 */ 00518 #define IPMICTL_REGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 14, \ 00519 struct ipmi_cmdspec) 00520 /* 00521 * Unregister a regsitered command. error values: 00522 * - EFAULT - an address supplied was invalid. 00523 * - ENOENT - The netfn/cmd was not found registered for this user. 00524 */ 00525 #define IPMICTL_UNREGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 15, \ 00526 struct ipmi_cmdspec) 00527 00528 /* 00529 * Set whether this interface receives events. Note that the first 00530 * user registered for events will get all pending events for the 00531 * interface. error values: 00532 * - EFAULT - an address supplied was invalid. 00533 */ 00534 #define IPMICTL_SET_GETS_EVENTS_CMD _IOR(IPMI_IOC_MAGIC, 16, int) 00535 00536 /* 00537 * Set and get the slave address and LUN that we will use for our 00538 * source messages. Note that this affects the interface, not just 00539 * this user, so it will affect all users of this interface. This is 00540 * so some initialization code can come in and do the OEM-specific 00541 * things it takes to determine your address (if not the BMC) and set 00542 * it for everyone else. You should probably leave the LUN alone. 00543 */ 00544 struct ipmi_channel_lun_address_set 00545 { 00546 unsigned short channel; 00547 unsigned char value; 00548 }; 00549 #define IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 24, struct ipmi_channel_lun_address_set) 00550 #define IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 25, struct ipmi_channel_lun_address_set) 00551 #define IPMICTL_SET_MY_CHANNEL_LUN_CMD _IOR(IPMI_IOC_MAGIC, 26, struct ipmi_channel_lun_address_set) 00552 #define IPMICTL_GET_MY_CHANNEL_LUN_CMD _IOR(IPMI_IOC_MAGIC, 27, struct ipmi_channel_lun_address_set) 00553 /* Legacy interfaces, these only set IPMB 0. */ 00554 #define IPMICTL_SET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 17, unsigned int) 00555 #define IPMICTL_GET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 18, unsigned int) 00556 #define IPMICTL_SET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 19, unsigned int) 00557 #define IPMICTL_GET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 20, unsigned int) 00558 00559 /* 00560 * Get/set the default timing values for an interface. You shouldn't 00561 * generally mess with these. 00562 */ 00563 struct ipmi_timing_parms 00564 { 00565 int retries; 00566 unsigned int retry_time_ms; 00567 }; 00568 #define IPMICTL_SET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 22, \ 00569 struct ipmi_timing_parms) 00570 #define IPMICTL_GET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 23, \ 00571 struct ipmi_timing_parms) 00572 00573 #endif /* __LINUX_IPMI_H */