1243ac210SCorey Minyard /* SPDX-License-Identifier: GPL-2.0+ */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * ipmi.h 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * MontaVista IPMI interface 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Author: MontaVista Software, Inc. 81da177e4SLinus Torvalds * Corey Minyard <[email protected]> 91da177e4SLinus Torvalds * [email protected] 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * Copyright 2002 MontaVista Software Inc. 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds */ 141da177e4SLinus Torvalds #ifndef __LINUX_IPMI_H 151da177e4SLinus Torvalds #define __LINUX_IPMI_H 161da177e4SLinus Torvalds 17607ca46eSDavid Howells #include <uapi/linux/ipmi.h> 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds #include <linux/list.h> 203b625943SCorey Minyard #include <linux/proc_fs.h> 21a11213fcSCorey Minyard #include <linux/acpi.h> /* For acpi_handle */ 223b625943SCorey Minyard 23de477254SPaul Gortmaker struct module; 24313162d0SPaul Gortmaker struct device; 25de477254SPaul Gortmaker 266dc1181fSCorey Minyard /* 276dc1181fSCorey Minyard * Opaque type for a IPMI message user. One of these is needed to 286dc1181fSCorey Minyard * send and receive messages. 296dc1181fSCorey Minyard */ 304372ea94SCorey Minyard struct ipmi_user; 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds /* 331da177e4SLinus Torvalds * Stuff coming from the receive interface comes as one of these. 341da177e4SLinus Torvalds * They are allocated, the receiver must free them with 351da177e4SLinus Torvalds * ipmi_free_recv_msg() when done with the message. The link is not 361da177e4SLinus Torvalds * used after the message is delivered, so the upper layer may use the 371da177e4SLinus Torvalds * link to build a linked list, if it likes. 381da177e4SLinus Torvalds */ 39c70d7499SCorey Minyard struct ipmi_recv_msg { 401da177e4SLinus Torvalds struct list_head link; 411da177e4SLinus Torvalds 426dc1181fSCorey Minyard /* 436dc1181fSCorey Minyard * The type of message as defined in the "Receive Types" 446dc1181fSCorey Minyard * defines above. 456dc1181fSCorey Minyard */ 461da177e4SLinus Torvalds int recv_type; 471da177e4SLinus Torvalds 485ce1a7dcSCorey Minyard struct ipmi_user *user; 491da177e4SLinus Torvalds struct ipmi_addr addr; 501da177e4SLinus Torvalds long msgid; 511da177e4SLinus Torvalds struct kernel_ipmi_msg msg; 521da177e4SLinus Torvalds 536dc1181fSCorey Minyard /* 546dc1181fSCorey Minyard * The user_msg_data is the data supplied when a message was 556dc1181fSCorey Minyard * sent, if this is a response to a sent message. If this is 566dc1181fSCorey Minyard * not a response to a sent message, then user_msg_data will 576dc1181fSCorey Minyard * be NULL. If the user above is NULL, then this will be the 586dc1181fSCorey Minyard * intf. 596dc1181fSCorey Minyard */ 601da177e4SLinus Torvalds void *user_msg_data; 611da177e4SLinus Torvalds 626dc1181fSCorey Minyard /* 636dc1181fSCorey Minyard * Call this when done with the message. It will presumably free 646dc1181fSCorey Minyard * the message and do any other necessary cleanup. 656dc1181fSCorey Minyard */ 661da177e4SLinus Torvalds void (*done)(struct ipmi_recv_msg *msg); 671da177e4SLinus Torvalds 686dc1181fSCorey Minyard /* 696dc1181fSCorey Minyard * Place-holder for the data, don't make any assumptions about 706dc1181fSCorey Minyard * the size or existence of this, since it may change. 716dc1181fSCorey Minyard */ 721da177e4SLinus Torvalds unsigned char msg_data[IPMI_MAX_MSG_LENGTH]; 731da177e4SLinus Torvalds }; 741da177e4SLinus Torvalds 75f214549dSCorey Minyard #define INIT_IPMI_RECV_MSG(done_handler) \ 76f214549dSCorey Minyard { \ 77f214549dSCorey Minyard .done = done_handler \ 78f214549dSCorey Minyard } 79f214549dSCorey Minyard 801da177e4SLinus Torvalds /* Allocate and free the receive message. */ 81393d2cc3SCorey Minyard void ipmi_free_recv_msg(struct ipmi_recv_msg *msg); 821da177e4SLinus Torvalds 83c70d7499SCorey Minyard struct ipmi_user_hndl { 846dc1181fSCorey Minyard /* 856dc1181fSCorey Minyard * Routine type to call when a message needs to be routed to 866dc1181fSCorey Minyard * the upper layer. This will be called with some locks held, 876dc1181fSCorey Minyard * the only IPMI routines that can be called are ipmi_request 886dc1181fSCorey Minyard * and the alloc/free operations. The handler_data is the 896dc1181fSCorey Minyard * variable supplied when the receive handler was registered. 906dc1181fSCorey Minyard */ 911da177e4SLinus Torvalds void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg, 921da177e4SLinus Torvalds void *user_msg_data); 931da177e4SLinus Torvalds 946dc1181fSCorey Minyard /* 956dc1181fSCorey Minyard * Called when the interface detects a watchdog pre-timeout. If 966dc1181fSCorey Minyard * this is NULL, it will be ignored for the user. 976dc1181fSCorey Minyard */ 981da177e4SLinus Torvalds void (*ipmi_watchdog_pretimeout)(void *handler_data); 9991e2dd0aSCorey Minyard 10091e2dd0aSCorey Minyard /* 10191e2dd0aSCorey Minyard * If not NULL, called at panic time after the interface has 10291e2dd0aSCorey Minyard * been set up to handle run to completion. 10391e2dd0aSCorey Minyard */ 10491e2dd0aSCorey Minyard void (*ipmi_panic_handler)(void *handler_data); 105b7780dabSCorey Minyard 106b7780dabSCorey Minyard /* 107b7780dabSCorey Minyard * Called when the interface has been removed. After this returns 108b7780dabSCorey Minyard * the user handle will be invalid. The interface may or may 109b7780dabSCorey Minyard * not be usable when this is called, but it will return errors 110b7780dabSCorey Minyard * if it is not usable. 111b7780dabSCorey Minyard */ 112b7780dabSCorey Minyard void (*shutdown)(void *handler_data); 1131da177e4SLinus Torvalds }; 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds /* Create a new user of the IPMI layer on the given interface number. */ 1161da177e4SLinus Torvalds int ipmi_create_user(unsigned int if_num, 117210af2a5SCorey Minyard const struct ipmi_user_hndl *handler, 1181da177e4SLinus Torvalds void *handler_data, 1195ce1a7dcSCorey Minyard struct ipmi_user **user); 1201da177e4SLinus Torvalds 1216dc1181fSCorey Minyard /* 1226dc1181fSCorey Minyard * Destroy the given user of the IPMI layer. Note that after this 1236dc1181fSCorey Minyard * function returns, the system is guaranteed to not call any 1246dc1181fSCorey Minyard * callbacks for the user. Thus as long as you destroy all the users 1256dc1181fSCorey Minyard * before you unload a module, you will be safe. And if you destroy 1266dc1181fSCorey Minyard * the users before you destroy the callback structures, it should be 1276dc1181fSCorey Minyard * safe, too. 1286dc1181fSCorey Minyard */ 129*9b6442a3SVitaliy Shevtsov void ipmi_destroy_user(struct ipmi_user *user); 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds /* Get the IPMI version of the BMC we are talking to. */ 1325ce1a7dcSCorey Minyard int ipmi_get_version(struct ipmi_user *user, 1331da177e4SLinus Torvalds unsigned char *major, 1341da177e4SLinus Torvalds unsigned char *minor); 1351da177e4SLinus Torvalds 1366dc1181fSCorey Minyard /* 1376dc1181fSCorey Minyard * Set and get the slave address and LUN that we will use for our 1386dc1181fSCorey Minyard * source messages. Note that this affects the interface, not just 1396dc1181fSCorey Minyard * this user, so it will affect all users of this interface. This is 1406dc1181fSCorey Minyard * so some initialization code can come in and do the OEM-specific 1416dc1181fSCorey Minyard * things it takes to determine your address (if not the BMC) and set 1426dc1181fSCorey Minyard * it for everyone else. Note that each channel can have its own 1436dc1181fSCorey Minyard * address. 1446dc1181fSCorey Minyard */ 1455ce1a7dcSCorey Minyard int ipmi_set_my_address(struct ipmi_user *user, 146c14979b9SCorey Minyard unsigned int channel, 1471da177e4SLinus Torvalds unsigned char address); 1485ce1a7dcSCorey Minyard int ipmi_get_my_address(struct ipmi_user *user, 149c14979b9SCorey Minyard unsigned int channel, 150c14979b9SCorey Minyard unsigned char *address); 1515ce1a7dcSCorey Minyard int ipmi_set_my_LUN(struct ipmi_user *user, 152c14979b9SCorey Minyard unsigned int channel, 1531da177e4SLinus Torvalds unsigned char LUN); 1545ce1a7dcSCorey Minyard int ipmi_get_my_LUN(struct ipmi_user *user, 155c14979b9SCorey Minyard unsigned int channel, 156c14979b9SCorey Minyard unsigned char *LUN); 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds /* 1591da177e4SLinus Torvalds * Like ipmi_request, but lets you specify the number of retries and 1601da177e4SLinus Torvalds * the retry time. The retries is the number of times the message 1611da177e4SLinus Torvalds * will be resent if no reply is received. If set to -1, the default 1621da177e4SLinus Torvalds * value will be used. The retry time is the time in milliseconds 1631da177e4SLinus Torvalds * between retries. If set to zero, the default value will be 1641da177e4SLinus Torvalds * used. 1651da177e4SLinus Torvalds * 1661da177e4SLinus Torvalds * Don't use this unless you *really* have to. It's primarily for the 1671da177e4SLinus Torvalds * IPMI over LAN converter; since the LAN stuff does its own retries, 1681da177e4SLinus Torvalds * it makes no sense to do it here. However, this can be used if you 1691da177e4SLinus Torvalds * have unusual requirements. 1701da177e4SLinus Torvalds */ 1715ce1a7dcSCorey Minyard int ipmi_request_settime(struct ipmi_user *user, 1721da177e4SLinus Torvalds struct ipmi_addr *addr, 1731da177e4SLinus Torvalds long msgid, 1741da177e4SLinus Torvalds struct kernel_ipmi_msg *msg, 1751da177e4SLinus Torvalds void *user_msg_data, 1761da177e4SLinus Torvalds int priority, 1771da177e4SLinus Torvalds int max_retries, 1781da177e4SLinus Torvalds unsigned int retry_time_ms); 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds /* 1811da177e4SLinus Torvalds * Like ipmi_request, but with messages supplied. This will not 1821da177e4SLinus Torvalds * allocate any memory, and the messages may be statically allocated 1831da177e4SLinus Torvalds * (just make sure to do the "done" handling on them). Note that this 1841da177e4SLinus Torvalds * is primarily for the watchdog timer, since it should be able to 1851da177e4SLinus Torvalds * send messages even if no memory is available. This is subject to 1861da177e4SLinus Torvalds * change as the system changes, so don't use it unless you REALLY 1871da177e4SLinus Torvalds * have to. 1881da177e4SLinus Torvalds */ 1895ce1a7dcSCorey Minyard int ipmi_request_supply_msgs(struct ipmi_user *user, 1901da177e4SLinus Torvalds struct ipmi_addr *addr, 1911da177e4SLinus Torvalds long msgid, 1921da177e4SLinus Torvalds struct kernel_ipmi_msg *msg, 1931da177e4SLinus Torvalds void *user_msg_data, 1941da177e4SLinus Torvalds void *supplied_smi, 1951da177e4SLinus Torvalds struct ipmi_recv_msg *supplied_recv, 1961da177e4SLinus Torvalds int priority); 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds /* 199fcfa4724SCorey Minyard * Poll the IPMI interface for the user. This causes the IPMI code to 200fcfa4724SCorey Minyard * do an immediate check for information from the driver and handle 201fcfa4724SCorey Minyard * anything that is immediately pending. This will not block in any 202bda4c30aSCorey Minyard * way. This is useful if you need to spin waiting for something to 203bda4c30aSCorey Minyard * happen in the IPMI driver. 204fcfa4724SCorey Minyard */ 2055ce1a7dcSCorey Minyard void ipmi_poll_interface(struct ipmi_user *user); 206fcfa4724SCorey Minyard 207fcfa4724SCorey Minyard /* 2081da177e4SLinus Torvalds * When commands come in to the SMS, the user can register to receive 209c69c3127SCorey Minyard * them. Only one user can be listening on a specific netfn/cmd/chan tuple 2101da177e4SLinus Torvalds * at a time, you will get an EBUSY error if the command is already 2111da177e4SLinus Torvalds * registered. If a command is received that does not have a user 2121da177e4SLinus Torvalds * registered, the driver will automatically return the proper 213c69c3127SCorey Minyard * error. Channels are specified as a bitfield, use IPMI_CHAN_ALL to 214c69c3127SCorey Minyard * mean all channels. 2151da177e4SLinus Torvalds */ 2165ce1a7dcSCorey Minyard int ipmi_register_for_cmd(struct ipmi_user *user, 2171da177e4SLinus Torvalds unsigned char netfn, 218c69c3127SCorey Minyard unsigned char cmd, 219c69c3127SCorey Minyard unsigned int chans); 2205ce1a7dcSCorey Minyard int ipmi_unregister_for_cmd(struct ipmi_user *user, 2211da177e4SLinus Torvalds unsigned char netfn, 222c69c3127SCorey Minyard unsigned char cmd, 223c69c3127SCorey Minyard unsigned int chans); 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds /* 226b9675136SCorey Minyard * Go into a mode where the driver will not autonomously attempt to do 227b9675136SCorey Minyard * things with the interface. It will still respond to attentions and 228b9675136SCorey Minyard * interrupts, and it will expect that commands will complete. It 229b9675136SCorey Minyard * will not automatcially check for flags, events, or things of that 230b9675136SCorey Minyard * nature. 231b9675136SCorey Minyard * 232b9675136SCorey Minyard * This is primarily used for firmware upgrades. The idea is that 233b9675136SCorey Minyard * when you go into firmware upgrade mode, you do this operation 234b9675136SCorey Minyard * and the driver will not attempt to do anything but what you tell 235b9675136SCorey Minyard * it or what the BMC asks for. 236b9675136SCorey Minyard * 237b9675136SCorey Minyard * Note that if you send a command that resets the BMC, the driver 238b9675136SCorey Minyard * will still expect a response from that command. So the BMC should 239b9675136SCorey Minyard * reset itself *after* the response is sent. Resetting before the 240b9675136SCorey Minyard * response is just silly. 241b9675136SCorey Minyard * 242b9675136SCorey Minyard * If in auto maintenance mode, the driver will automatically go into 243b9675136SCorey Minyard * maintenance mode for 30 seconds if it sees a cold reset, a warm 244b9675136SCorey Minyard * reset, or a firmware NetFN. This means that code that uses only 245b9675136SCorey Minyard * firmware NetFN commands to do upgrades will work automatically 246b9675136SCorey Minyard * without change, assuming it sends a message every 30 seconds or 247b9675136SCorey Minyard * less. 248b9675136SCorey Minyard * 249b9675136SCorey Minyard * See the IPMI_MAINTENANCE_MODE_xxx defines for what the mode means. 250b9675136SCorey Minyard */ 2515ce1a7dcSCorey Minyard int ipmi_get_maintenance_mode(struct ipmi_user *user); 2525ce1a7dcSCorey Minyard int ipmi_set_maintenance_mode(struct ipmi_user *user, int mode); 253b9675136SCorey Minyard 254b9675136SCorey Minyard /* 2551da177e4SLinus Torvalds * When the user is created, it will not receive IPMI events by 2561da177e4SLinus Torvalds * default. The user must set this to TRUE to get incoming events. 2571da177e4SLinus Torvalds * The first user that sets this to TRUE will receive all events that 2581da177e4SLinus Torvalds * have been queued while no one was waiting for events. 2591da177e4SLinus Torvalds */ 2605ce1a7dcSCorey Minyard int ipmi_set_gets_events(struct ipmi_user *user, bool val); 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds /* 2631da177e4SLinus Torvalds * Called when a new SMI is registered. This will also be called on 2641da177e4SLinus Torvalds * every existing interface when a new watcher is registered with 2651da177e4SLinus Torvalds * ipmi_smi_watcher_register(). 2661da177e4SLinus Torvalds */ 267c70d7499SCorey Minyard struct ipmi_smi_watcher { 2681da177e4SLinus Torvalds struct list_head link; 2691da177e4SLinus Torvalds 2706dc1181fSCorey Minyard /* 2716dc1181fSCorey Minyard * You must set the owner to the current module, if you are in 2726dc1181fSCorey Minyard * a module (generally just set it to "THIS_MODULE"). 2736dc1181fSCorey Minyard */ 2741da177e4SLinus Torvalds struct module *owner; 2751da177e4SLinus Torvalds 2766dc1181fSCorey Minyard /* 2776dc1181fSCorey Minyard * These two are called with read locks held for the interface 2786dc1181fSCorey Minyard * the watcher list. So you can add and remove users from the 2796dc1181fSCorey Minyard * IPMI interface, send messages, etc., but you cannot add 2806dc1181fSCorey Minyard * or remove SMI watchers or SMI interfaces. 2816dc1181fSCorey Minyard */ 28250c812b2SCorey Minyard void (*new_smi)(int if_num, struct device *dev); 2831da177e4SLinus Torvalds void (*smi_gone)(int if_num); 2841da177e4SLinus Torvalds }; 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher); 2871da177e4SLinus Torvalds int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher); 2881da177e4SLinus Torvalds 2896dc1181fSCorey Minyard /* 2906dc1181fSCorey Minyard * The following are various helper functions for dealing with IPMI 2916dc1181fSCorey Minyard * addresses. 2926dc1181fSCorey Minyard */ 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds /* Return the maximum length of an IPMI address given it's type. */ 2951da177e4SLinus Torvalds unsigned int ipmi_addr_length(int addr_type); 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds /* Validate that the given IPMI address is valid. */ 2981da177e4SLinus Torvalds int ipmi_validate_addr(struct ipmi_addr *addr, int len); 2991da177e4SLinus Torvalds 30016f4232cSZhao Yakui /* 30116f4232cSZhao Yakui * How did the IPMI driver find out about the device? 30216f4232cSZhao Yakui */ 30316f4232cSZhao Yakui enum ipmi_addr_src { 30416f4232cSZhao Yakui SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS, 30595e300c0SCorey Minyard SI_PCI, SI_DEVICETREE, SI_PLATFORM, SI_LAST 30616f4232cSZhao Yakui }; 3077e50387bSCorey Minyard const char *ipmi_addr_src_to_str(enum ipmi_addr_src src); 30816f4232cSZhao Yakui 30916f4232cSZhao Yakui union ipmi_smi_info_union { 310a11213fcSCorey Minyard #ifdef CONFIG_ACPI 31116f4232cSZhao Yakui /* 31216f4232cSZhao Yakui * the acpi_info element is defined for the SI_ACPI 31316f4232cSZhao Yakui * address type 31416f4232cSZhao Yakui */ 31516f4232cSZhao Yakui struct { 316a11213fcSCorey Minyard acpi_handle acpi_handle; 31716f4232cSZhao Yakui } acpi_info; 318a11213fcSCorey Minyard #endif 31916f4232cSZhao Yakui }; 32016f4232cSZhao Yakui 32116f4232cSZhao Yakui struct ipmi_smi_info { 32216f4232cSZhao Yakui enum ipmi_addr_src addr_src; 32316f4232cSZhao Yakui 32416f4232cSZhao Yakui /* 32516f4232cSZhao Yakui * Base device for the interface. Don't forget to put this when 32616f4232cSZhao Yakui * you are done. 32716f4232cSZhao Yakui */ 32816f4232cSZhao Yakui struct device *dev; 32916f4232cSZhao Yakui 33016f4232cSZhao Yakui /* 33116f4232cSZhao Yakui * The addr_info provides more detailed info for some IPMI 33216f4232cSZhao Yakui * devices, depending on the addr_src. Currently only SI_ACPI 33316f4232cSZhao Yakui * info is provided. 33416f4232cSZhao Yakui */ 33516f4232cSZhao Yakui union ipmi_smi_info_union addr_info; 33616f4232cSZhao Yakui }; 33716f4232cSZhao Yakui 3385ce1a7dcSCorey Minyard /* This is to get the private info of struct ipmi_smi */ 33916f4232cSZhao Yakui extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data); 34016f4232cSZhao Yakui 34142d8a346SXianting Tian #define GET_DEVICE_ID_MAX_RETRY 5 34242d8a346SXianting Tian 3431e4071f6SCorey Minyard /* Helper function for computing the IPMB checksum of some data. */ 3441e4071f6SCorey Minyard unsigned char ipmb_checksum(unsigned char *data, int size); 3451e4071f6SCorey Minyard 3461da177e4SLinus Torvalds #endif /* __LINUX_IPMI_H */ 347