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