Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * ipmi.h
0004  *
0005  * MontaVista IPMI interface
0006  *
0007  * Author: MontaVista Software, Inc.
0008  *         Corey Minyard <minyard@mvista.com>
0009  *         source@mvista.com
0010  *
0011  * Copyright 2002 MontaVista Software Inc.
0012  *
0013  */
0014 #ifndef __LINUX_IPMI_H
0015 #define __LINUX_IPMI_H
0016 
0017 #include <uapi/linux/ipmi.h>
0018 
0019 #include <linux/list.h>
0020 #include <linux/proc_fs.h>
0021 #include <linux/acpi.h> /* For acpi_handle */
0022 
0023 struct module;
0024 struct device;
0025 
0026 /*
0027  * Opaque type for a IPMI message user.  One of these is needed to
0028  * send and receive messages.
0029  */
0030 struct ipmi_user;
0031 
0032 /*
0033  * Stuff coming from the receive interface comes as one of these.
0034  * They are allocated, the receiver must free them with
0035  * ipmi_free_recv_msg() when done with the message.  The link is not
0036  * used after the message is delivered, so the upper layer may use the
0037  * link to build a linked list, if it likes.
0038  */
0039 struct ipmi_recv_msg {
0040     struct list_head link;
0041 
0042     /*
0043      * The type of message as defined in the "Receive Types"
0044      * defines above.
0045      */
0046     int              recv_type;
0047 
0048     struct ipmi_user *user;
0049     struct ipmi_addr addr;
0050     long             msgid;
0051     struct kernel_ipmi_msg  msg;
0052 
0053     /*
0054      * The user_msg_data is the data supplied when a message was
0055      * sent, if this is a response to a sent message.  If this is
0056      * not a response to a sent message, then user_msg_data will
0057      * be NULL.  If the user above is NULL, then this will be the
0058      * intf.
0059      */
0060     void             *user_msg_data;
0061 
0062     /*
0063      * Call this when done with the message.  It will presumably free
0064      * the message and do any other necessary cleanup.
0065      */
0066     void (*done)(struct ipmi_recv_msg *msg);
0067 
0068     /*
0069      * Place-holder for the data, don't make any assumptions about
0070      * the size or existence of this, since it may change.
0071      */
0072     unsigned char   msg_data[IPMI_MAX_MSG_LENGTH];
0073 };
0074 
0075 #define INIT_IPMI_RECV_MSG(done_handler) \
0076 {                   \
0077     .done = done_handler        \
0078 }
0079 
0080 /* Allocate and free the receive message. */
0081 void ipmi_free_recv_msg(struct ipmi_recv_msg *msg);
0082 
0083 struct ipmi_user_hndl {
0084     /*
0085      * Routine type to call when a message needs to be routed to
0086      * the upper layer.  This will be called with some locks held,
0087      * the only IPMI routines that can be called are ipmi_request
0088      * and the alloc/free operations.  The handler_data is the
0089      * variable supplied when the receive handler was registered.
0090      */
0091     void (*ipmi_recv_hndl)(struct ipmi_recv_msg *msg,
0092                    void                 *user_msg_data);
0093 
0094     /*
0095      * Called when the interface detects a watchdog pre-timeout.  If
0096      * this is NULL, it will be ignored for the user.
0097      */
0098     void (*ipmi_watchdog_pretimeout)(void *handler_data);
0099 
0100     /*
0101      * If not NULL, called at panic time after the interface has
0102      * been set up to handle run to completion.
0103      */
0104     void (*ipmi_panic_handler)(void *handler_data);
0105 
0106     /*
0107      * Called when the interface has been removed.  After this returns
0108      * the user handle will be invalid.  The interface may or may
0109      * not be usable when this is called, but it will return errors
0110      * if it is not usable.
0111      */
0112     void (*shutdown)(void *handler_data);
0113 };
0114 
0115 /* Create a new user of the IPMI layer on the given interface number. */
0116 int ipmi_create_user(unsigned int          if_num,
0117              const struct ipmi_user_hndl *handler,
0118              void                  *handler_data,
0119              struct ipmi_user      **user);
0120 
0121 /*
0122  * Destroy the given user of the IPMI layer.  Note that after this
0123  * function returns, the system is guaranteed to not call any
0124  * callbacks for the user.  Thus as long as you destroy all the users
0125  * before you unload a module, you will be safe.  And if you destroy
0126  * the users before you destroy the callback structures, it should be
0127  * safe, too.
0128  */
0129 int ipmi_destroy_user(struct ipmi_user *user);
0130 
0131 /* Get the IPMI version of the BMC we are talking to. */
0132 int ipmi_get_version(struct ipmi_user *user,
0133              unsigned char *major,
0134              unsigned char *minor);
0135 
0136 /*
0137  * Set and get the slave address and LUN that we will use for our
0138  * source messages.  Note that this affects the interface, not just
0139  * this user, so it will affect all users of this interface.  This is
0140  * so some initialization code can come in and do the OEM-specific
0141  * things it takes to determine your address (if not the BMC) and set
0142  * it for everyone else.  Note that each channel can have its own
0143  * address.
0144  */
0145 int ipmi_set_my_address(struct ipmi_user *user,
0146             unsigned int  channel,
0147             unsigned char address);
0148 int ipmi_get_my_address(struct ipmi_user *user,
0149             unsigned int  channel,
0150             unsigned char *address);
0151 int ipmi_set_my_LUN(struct ipmi_user *user,
0152             unsigned int  channel,
0153             unsigned char LUN);
0154 int ipmi_get_my_LUN(struct ipmi_user *user,
0155             unsigned int  channel,
0156             unsigned char *LUN);
0157 
0158 /*
0159  * Like ipmi_request, but lets you specify the number of retries and
0160  * the retry time.  The retries is the number of times the message
0161  * will be resent if no reply is received.  If set to -1, the default
0162  * value will be used.  The retry time is the time in milliseconds
0163  * between retries.  If set to zero, the default value will be
0164  * used.
0165  *
0166  * Don't use this unless you *really* have to.  It's primarily for the
0167  * IPMI over LAN converter; since the LAN stuff does its own retries,
0168  * it makes no sense to do it here.  However, this can be used if you
0169  * have unusual requirements.
0170  */
0171 int ipmi_request_settime(struct ipmi_user *user,
0172              struct ipmi_addr *addr,
0173              long             msgid,
0174              struct kernel_ipmi_msg  *msg,
0175              void             *user_msg_data,
0176              int              priority,
0177              int              max_retries,
0178              unsigned int     retry_time_ms);
0179 
0180 /*
0181  * Like ipmi_request, but with messages supplied.  This will not
0182  * allocate any memory, and the messages may be statically allocated
0183  * (just make sure to do the "done" handling on them).  Note that this
0184  * is primarily for the watchdog timer, since it should be able to
0185  * send messages even if no memory is available.  This is subject to
0186  * change as the system changes, so don't use it unless you REALLY
0187  * have to.
0188  */
0189 int ipmi_request_supply_msgs(struct ipmi_user     *user,
0190                  struct ipmi_addr     *addr,
0191                  long                 msgid,
0192                  struct kernel_ipmi_msg *msg,
0193                  void                 *user_msg_data,
0194                  void                 *supplied_smi,
0195                  struct ipmi_recv_msg *supplied_recv,
0196                  int                  priority);
0197 
0198 /*
0199  * Poll the IPMI interface for the user.  This causes the IPMI code to
0200  * do an immediate check for information from the driver and handle
0201  * anything that is immediately pending.  This will not block in any
0202  * way.  This is useful if you need to spin waiting for something to
0203  * happen in the IPMI driver.
0204  */
0205 void ipmi_poll_interface(struct ipmi_user *user);
0206 
0207 /*
0208  * When commands come in to the SMS, the user can register to receive
0209  * them.  Only one user can be listening on a specific netfn/cmd/chan tuple
0210  * at a time, you will get an EBUSY error if the command is already
0211  * registered.  If a command is received that does not have a user
0212  * registered, the driver will automatically return the proper
0213  * error.  Channels are specified as a bitfield, use IPMI_CHAN_ALL to
0214  * mean all channels.
0215  */
0216 int ipmi_register_for_cmd(struct ipmi_user *user,
0217               unsigned char netfn,
0218               unsigned char cmd,
0219               unsigned int  chans);
0220 int ipmi_unregister_for_cmd(struct ipmi_user *user,
0221                 unsigned char netfn,
0222                 unsigned char cmd,
0223                 unsigned int  chans);
0224 
0225 /*
0226  * Go into a mode where the driver will not autonomously attempt to do
0227  * things with the interface.  It will still respond to attentions and
0228  * interrupts, and it will expect that commands will complete.  It
0229  * will not automatcially check for flags, events, or things of that
0230  * nature.
0231  *
0232  * This is primarily used for firmware upgrades.  The idea is that
0233  * when you go into firmware upgrade mode, you do this operation
0234  * and the driver will not attempt to do anything but what you tell
0235  * it or what the BMC asks for.
0236  *
0237  * Note that if you send a command that resets the BMC, the driver
0238  * will still expect a response from that command.  So the BMC should
0239  * reset itself *after* the response is sent.  Resetting before the
0240  * response is just silly.
0241  *
0242  * If in auto maintenance mode, the driver will automatically go into
0243  * maintenance mode for 30 seconds if it sees a cold reset, a warm
0244  * reset, or a firmware NetFN.  This means that code that uses only
0245  * firmware NetFN commands to do upgrades will work automatically
0246  * without change, assuming it sends a message every 30 seconds or
0247  * less.
0248  *
0249  * See the IPMI_MAINTENANCE_MODE_xxx defines for what the mode means.
0250  */
0251 int ipmi_get_maintenance_mode(struct ipmi_user *user);
0252 int ipmi_set_maintenance_mode(struct ipmi_user *user, int mode);
0253 
0254 /*
0255  * When the user is created, it will not receive IPMI events by
0256  * default.  The user must set this to TRUE to get incoming events.
0257  * The first user that sets this to TRUE will receive all events that
0258  * have been queued while no one was waiting for events.
0259  */
0260 int ipmi_set_gets_events(struct ipmi_user *user, bool val);
0261 
0262 /*
0263  * Called when a new SMI is registered.  This will also be called on
0264  * every existing interface when a new watcher is registered with
0265  * ipmi_smi_watcher_register().
0266  */
0267 struct ipmi_smi_watcher {
0268     struct list_head link;
0269 
0270     /*
0271      * You must set the owner to the current module, if you are in
0272      * a module (generally just set it to "THIS_MODULE").
0273      */
0274     struct module *owner;
0275 
0276     /*
0277      * These two are called with read locks held for the interface
0278      * the watcher list.  So you can add and remove users from the
0279      * IPMI interface, send messages, etc., but you cannot add
0280      * or remove SMI watchers or SMI interfaces.
0281      */
0282     void (*new_smi)(int if_num, struct device *dev);
0283     void (*smi_gone)(int if_num);
0284 };
0285 
0286 int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher);
0287 int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher);
0288 
0289 /*
0290  * The following are various helper functions for dealing with IPMI
0291  * addresses.
0292  */
0293 
0294 /* Return the maximum length of an IPMI address given it's type. */
0295 unsigned int ipmi_addr_length(int addr_type);
0296 
0297 /* Validate that the given IPMI address is valid. */
0298 int ipmi_validate_addr(struct ipmi_addr *addr, int len);
0299 
0300 /*
0301  * How did the IPMI driver find out about the device?
0302  */
0303 enum ipmi_addr_src {
0304     SI_INVALID = 0, SI_HOTMOD, SI_HARDCODED, SI_SPMI, SI_ACPI, SI_SMBIOS,
0305     SI_PCI, SI_DEVICETREE, SI_PLATFORM, SI_LAST
0306 };
0307 const char *ipmi_addr_src_to_str(enum ipmi_addr_src src);
0308 
0309 union ipmi_smi_info_union {
0310 #ifdef CONFIG_ACPI
0311     /*
0312      * the acpi_info element is defined for the SI_ACPI
0313      * address type
0314      */
0315     struct {
0316         acpi_handle acpi_handle;
0317     } acpi_info;
0318 #endif
0319 };
0320 
0321 struct ipmi_smi_info {
0322     enum ipmi_addr_src addr_src;
0323 
0324     /*
0325      * Base device for the interface.  Don't forget to put this when
0326      * you are done.
0327      */
0328     struct device *dev;
0329 
0330     /*
0331      * The addr_info provides more detailed info for some IPMI
0332      * devices, depending on the addr_src.  Currently only SI_ACPI
0333      * info is provided.
0334      */
0335     union ipmi_smi_info_union addr_info;
0336 };
0337 
0338 /* This is to get the private info of struct ipmi_smi */
0339 extern int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data);
0340 
0341 #define GET_DEVICE_ID_MAX_RETRY     5
0342 
0343 /* Helper function for computing the IPMB checksum of some data. */
0344 unsigned char ipmb_checksum(unsigned char *data, int size);
0345 
0346 #endif /* __LINUX_IPMI_H */