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