Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
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 
0015 #ifndef _UAPI__LINUX_IPMI_H
0016 #define _UAPI__LINUX_IPMI_H
0017 
0018 #include <linux/ipmi_msgdefs.h>
0019 #include <linux/compiler.h>
0020 
0021 /*
0022  * This file describes an interface to an IPMI driver.  You have to
0023  * have a fairly good understanding of IPMI to use this, so go read
0024  * the specs first before actually trying to do anything.
0025  *
0026  * With that said, this driver provides a multi-user interface to the
0027  * IPMI driver, and it allows multiple IPMI physical interfaces below
0028  * the driver.  The physical interfaces bind as a lower layer on the
0029  * driver.  They appear as interfaces to the application using this
0030  * interface.
0031  *
0032  * Multi-user means that multiple applications may use the driver,
0033  * send commands, receive responses, etc.  The driver keeps track of
0034  * commands the user sends and tracks the responses.  The responses
0035  * will go back to the application that send the command.  If the
0036  * response doesn't come back in time, the driver will return a
0037  * timeout error response to the application.  Asynchronous events
0038  * from the BMC event queue will go to all users bound to the driver.
0039  * The incoming event queue in the BMC will automatically be flushed
0040  * if it becomes full and it is queried once a second to see if
0041  * anything is in it.  Incoming commands to the driver will get
0042  * delivered as commands.
0043  */
0044 
0045 /*
0046  * This is an overlay for all the address types, so it's easy to
0047  * determine the actual address type.  This is kind of like addresses
0048  * work for sockets.
0049  */
0050 #define IPMI_MAX_ADDR_SIZE 32
0051 struct ipmi_addr {
0052      /* Try to take these from the "Channel Medium Type" table
0053         in section 6.5 of the IPMI 1.5 manual. */
0054     int   addr_type;
0055     short channel;
0056     char  data[IPMI_MAX_ADDR_SIZE];
0057 };
0058 
0059 /*
0060  * When the address is not used, the type will be set to this value.
0061  * The channel is the BMC's channel number for the channel (usually
0062  * 0), or IPMC_BMC_CHANNEL if communicating directly with the BMC.
0063  */
0064 #define IPMI_SYSTEM_INTERFACE_ADDR_TYPE 0x0c
0065 struct ipmi_system_interface_addr {
0066     int           addr_type;
0067     short         channel;
0068     unsigned char lun;
0069 };
0070 
0071 /* An IPMB Address. */
0072 #define IPMI_IPMB_ADDR_TYPE     0x01
0073 /* Used for broadcast get device id as described in section 17.9 of the
0074    IPMI 1.5 manual. */
0075 #define IPMI_IPMB_BROADCAST_ADDR_TYPE   0x41
0076 struct ipmi_ipmb_addr {
0077     int           addr_type;
0078     short         channel;
0079     unsigned char slave_addr;
0080     unsigned char lun;
0081 };
0082 
0083 /*
0084  * Used for messages received directly from an IPMB that have not gone
0085  * through a MC.  This is for systems that sit right on an IPMB so
0086  * they can receive commands and respond to them.
0087  */
0088 #define IPMI_IPMB_DIRECT_ADDR_TYPE  0x81
0089 struct ipmi_ipmb_direct_addr {
0090     int           addr_type;
0091     short         channel;
0092     unsigned char slave_addr;
0093     unsigned char rs_lun;
0094     unsigned char rq_lun;
0095 };
0096 
0097 /*
0098  * A LAN Address.  This is an address to/from a LAN interface bridged
0099  * by the BMC, not an address actually out on the LAN.
0100  *
0101  * A conscious decision was made here to deviate slightly from the IPMI
0102  * spec.  We do not use rqSWID and rsSWID like it shows in the
0103  * message.  Instead, we use remote_SWID and local_SWID.  This means
0104  * that any message (a request or response) from another device will
0105  * always have exactly the same address.  If you didn't do this,
0106  * requests and responses from the same device would have different
0107  * addresses, and that's not too cool.
0108  *
0109  * In this address, the remote_SWID is always the SWID the remote
0110  * message came from, or the SWID we are sending the message to.
0111  * local_SWID is always our SWID.  Note that having our SWID in the
0112  * message is a little weird, but this is required.
0113  */
0114 #define IPMI_LAN_ADDR_TYPE      0x04
0115 struct ipmi_lan_addr {
0116     int           addr_type;
0117     short         channel;
0118     unsigned char privilege;
0119     unsigned char session_handle;
0120     unsigned char remote_SWID;
0121     unsigned char local_SWID;
0122     unsigned char lun;
0123 };
0124 
0125 
0126 /*
0127  * Channel for talking directly with the BMC.  When using this
0128  * channel, This is for the system interface address type only.  FIXME
0129  * - is this right, or should we use -1?
0130  */
0131 #define IPMI_BMC_CHANNEL  0xf
0132 #define IPMI_NUM_CHANNELS 0x10
0133 
0134 /*
0135  * Used to signify an "all channel" bitmask.  This is more than the
0136  * actual number of channels because this is used in userland and
0137  * will cover us if the number of channels is extended.
0138  */
0139 #define IPMI_CHAN_ALL     (~0)
0140 
0141 
0142 /*
0143  * A raw IPMI message without any addressing.  This covers both
0144  * commands and responses.  The completion code is always the first
0145  * byte of data in the response (as the spec shows the messages laid
0146  * out).
0147  */
0148 struct ipmi_msg {
0149     unsigned char  netfn;
0150     unsigned char  cmd;
0151     unsigned short data_len;
0152     unsigned char  __user *data;
0153 };
0154 
0155 struct kernel_ipmi_msg {
0156     unsigned char  netfn;
0157     unsigned char  cmd;
0158     unsigned short data_len;
0159     unsigned char  *data;
0160 };
0161 
0162 /*
0163  * Various defines that are useful for IPMI applications.
0164  */
0165 #define IPMI_INVALID_CMD_COMPLETION_CODE    0xC1
0166 #define IPMI_TIMEOUT_COMPLETION_CODE        0xC3
0167 #define IPMI_UNKNOWN_ERR_COMPLETION_CODE    0xff
0168 
0169 
0170 /*
0171  * Receive types for messages coming from the receive interface.  This
0172  * is used for the receive in-kernel interface and in the receive
0173  * IOCTL.
0174  *
0175  * The "IPMI_RESPONSE_RESPONSE_TYPE" is a little strange sounding, but
0176  * it allows you to get the message results when you send a response
0177  * message.
0178  */
0179 #define IPMI_RESPONSE_RECV_TYPE     1 /* A response to a command */
0180 #define IPMI_ASYNC_EVENT_RECV_TYPE  2 /* Something from the event queue */
0181 #define IPMI_CMD_RECV_TYPE      3 /* A command from somewhere else */
0182 #define IPMI_RESPONSE_RESPONSE_TYPE 4 /* The response for
0183                           a sent response, giving any
0184                           error status for sending the
0185                           response.  When you send a
0186                           response message, this will
0187                           be returned. */
0188 #define IPMI_OEM_RECV_TYPE      5 /* The response for OEM Channels */
0189 
0190 /* Note that async events and received commands do not have a completion
0191    code as the first byte of the incoming data, unlike a response. */
0192 
0193 
0194 /*
0195  * Modes for ipmi_set_maint_mode() and the userland IOCTL.  The AUTO
0196  * setting is the default and means it will be set on certain
0197  * commands.  Hard setting it on and off will override automatic
0198  * operation.
0199  */
0200 #define IPMI_MAINTENANCE_MODE_AUTO  0
0201 #define IPMI_MAINTENANCE_MODE_OFF   1
0202 #define IPMI_MAINTENANCE_MODE_ON    2
0203 
0204 
0205 
0206 /*
0207  * The userland interface
0208  */
0209 
0210 /*
0211  * The userland interface for the IPMI driver is a standard character
0212  * device, with each instance of an interface registered as a minor
0213  * number under the major character device.
0214  *
0215  * The read and write calls do not work, to get messages in and out
0216  * requires ioctl calls because of the complexity of the data.  select
0217  * and poll do work, so you can wait for input using the file
0218  * descriptor, you just can use read to get it.
0219  *
0220  * In general, you send a command down to the interface and receive
0221  * responses back.  You can use the msgid value to correlate commands
0222  * and responses, the driver will take care of figuring out which
0223  * incoming messages are for which command and find the proper msgid
0224  * value to report.  You will only receive reponses for commands you
0225  * send.  Asynchronous events, however, go to all open users, so you
0226  * must be ready to handle these (or ignore them if you don't care).
0227  *
0228  * The address type depends upon the channel type.  When talking
0229  * directly to the BMC (IPMC_BMC_CHANNEL), the address is ignored
0230  * (IPMI_UNUSED_ADDR_TYPE).  When talking to an IPMB channel, you must
0231  * supply a valid IPMB address with the addr_type set properly.
0232  *
0233  * When talking to normal channels, the driver takes care of the
0234  * details of formatting and sending messages on that channel.  You do
0235  * not, for instance, have to format a send command, you just send
0236  * whatever command you want to the channel, the driver will create
0237  * the send command, automatically issue receive command and get even
0238  * commands, and pass those up to the proper user.
0239  */
0240 
0241 
0242 /* The magic IOCTL value for this interface. */
0243 #define IPMI_IOC_MAGIC 'i'
0244 
0245 
0246 /* Messages sent to the interface are this format. */
0247 struct ipmi_req {
0248     unsigned char __user *addr; /* Address to send the message to. */
0249     unsigned int  addr_len;
0250 
0251     long    msgid; /* The sequence number for the message.  This
0252               exact value will be reported back in the
0253               response to this request if it is a command.
0254               If it is a response, this will be used as
0255               the sequence value for the response.  */
0256 
0257     struct ipmi_msg msg;
0258 };
0259 /*
0260  * Send a message to the interfaces.  error values are:
0261  *   - EFAULT - an address supplied was invalid.
0262  *   - EINVAL - The address supplied was not valid, or the command
0263  *              was not allowed.
0264  *   - EMSGSIZE - The message to was too large.
0265  *   - ENOMEM - Buffers could not be allocated for the command.
0266  */
0267 #define IPMICTL_SEND_COMMAND        _IOR(IPMI_IOC_MAGIC, 13,    \
0268                          struct ipmi_req)
0269 
0270 /* Messages sent to the interface with timing parameters are this
0271    format. */
0272 struct ipmi_req_settime {
0273     struct ipmi_req req;
0274 
0275     /* See ipmi_request_settime() above for details on these
0276        values. */
0277     int          retries;
0278     unsigned int retry_time_ms;
0279 };
0280 /*
0281  * Send a message to the interfaces with timing parameters.  error values
0282  * are:
0283  *   - EFAULT - an address supplied was invalid.
0284  *   - EINVAL - The address supplied was not valid, or the command
0285  *              was not allowed.
0286  *   - EMSGSIZE - The message to was too large.
0287  *   - ENOMEM - Buffers could not be allocated for the command.
0288  */
0289 #define IPMICTL_SEND_COMMAND_SETTIME    _IOR(IPMI_IOC_MAGIC, 21,    \
0290                          struct ipmi_req_settime)
0291 
0292 /* Messages received from the interface are this format. */
0293 struct ipmi_recv {
0294     int     recv_type; /* Is this a command, response or an
0295                   asyncronous event. */
0296 
0297     unsigned char __user *addr;    /* Address the message was from is put
0298                    here.  The caller must supply the
0299                    memory. */
0300     unsigned int  addr_len; /* The size of the address buffer.
0301                    The caller supplies the full buffer
0302                    length, this value is updated to
0303                    the actual message length when the
0304                    message is received. */
0305 
0306     long    msgid; /* The sequence number specified in the request
0307               if this is a response.  If this is a command,
0308               this will be the sequence number from the
0309               command. */
0310 
0311     struct ipmi_msg msg; /* The data field must point to a buffer.
0312                 The data_size field must be set to the
0313                 size of the message buffer.  The
0314                 caller supplies the full buffer
0315                 length, this value is updated to the
0316                 actual message length when the message
0317                 is received. */
0318 };
0319 
0320 /*
0321  * Receive a message.  error values:
0322  *  - EAGAIN - no messages in the queue.
0323  *  - EFAULT - an address supplied was invalid.
0324  *  - EINVAL - The address supplied was not valid.
0325  *  - EMSGSIZE - The message to was too large to fit into the message buffer,
0326  *               the message will be left in the buffer. */
0327 #define IPMICTL_RECEIVE_MSG     _IOWR(IPMI_IOC_MAGIC, 12,   \
0328                           struct ipmi_recv)
0329 
0330 /*
0331  * Like RECEIVE_MSG, but if the message won't fit in the buffer, it
0332  * will truncate the contents instead of leaving the data in the
0333  * buffer.
0334  */
0335 #define IPMICTL_RECEIVE_MSG_TRUNC   _IOWR(IPMI_IOC_MAGIC, 11,   \
0336                           struct ipmi_recv)
0337 
0338 /* Register to get commands from other entities on this interface. */
0339 struct ipmi_cmdspec {
0340     unsigned char netfn;
0341     unsigned char cmd;
0342 };
0343 
0344 /*
0345  * Register to receive a specific command.  error values:
0346  *   - EFAULT - an address supplied was invalid.
0347  *   - EBUSY - The netfn/cmd supplied was already in use.
0348  *   - ENOMEM - could not allocate memory for the entry.
0349  */
0350 #define IPMICTL_REGISTER_FOR_CMD    _IOR(IPMI_IOC_MAGIC, 14,    \
0351                          struct ipmi_cmdspec)
0352 /*
0353  * Unregister a registered command.  error values:
0354  *  - EFAULT - an address supplied was invalid.
0355  *  - ENOENT - The netfn/cmd was not found registered for this user.
0356  */
0357 #define IPMICTL_UNREGISTER_FOR_CMD  _IOR(IPMI_IOC_MAGIC, 15,    \
0358                          struct ipmi_cmdspec)
0359 
0360 /*
0361  * Register to get commands from other entities on specific channels.
0362  * This way, you can only listen on specific channels, or have messages
0363  * from some channels go to one place and other channels to someplace
0364  * else.  The chans field is a bitmask, (1 << channel) for each channel.
0365  * It may be IPMI_CHAN_ALL for all channels.
0366  */
0367 struct ipmi_cmdspec_chans {
0368     unsigned int netfn;
0369     unsigned int cmd;
0370     unsigned int chans;
0371 };
0372 
0373 /*
0374  * Register to receive a specific command on specific channels.  error values:
0375  *   - EFAULT - an address supplied was invalid.
0376  *   - EBUSY - One of the netfn/cmd/chans supplied was already in use.
0377  *   - ENOMEM - could not allocate memory for the entry.
0378  */
0379 #define IPMICTL_REGISTER_FOR_CMD_CHANS  _IOR(IPMI_IOC_MAGIC, 28,    \
0380                          struct ipmi_cmdspec_chans)
0381 /*
0382  * Unregister some netfn/cmd/chans.  error values:
0383  *  - EFAULT - an address supplied was invalid.
0384  *  - ENOENT - None of the netfn/cmd/chans were found registered for this user.
0385  */
0386 #define IPMICTL_UNREGISTER_FOR_CMD_CHANS _IOR(IPMI_IOC_MAGIC, 29,   \
0387                          struct ipmi_cmdspec_chans)
0388 
0389 /*
0390  * Set whether this interface receives events.  Note that the first
0391  * user registered for events will get all pending events for the
0392  * interface.  error values:
0393  *  - EFAULT - an address supplied was invalid.
0394  */
0395 #define IPMICTL_SET_GETS_EVENTS_CMD _IOR(IPMI_IOC_MAGIC, 16, int)
0396 
0397 /*
0398  * Set and get the slave address and LUN that we will use for our
0399  * source messages.  Note that this affects the interface, not just
0400  * this user, so it will affect all users of this interface.  This is
0401  * so some initialization code can come in and do the OEM-specific
0402  * things it takes to determine your address (if not the BMC) and set
0403  * it for everyone else.  You should probably leave the LUN alone.
0404  */
0405 struct ipmi_channel_lun_address_set {
0406     unsigned short channel;
0407     unsigned char  value;
0408 };
0409 #define IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD \
0410     _IOR(IPMI_IOC_MAGIC, 24, struct ipmi_channel_lun_address_set)
0411 #define IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD \
0412     _IOR(IPMI_IOC_MAGIC, 25, struct ipmi_channel_lun_address_set)
0413 #define IPMICTL_SET_MY_CHANNEL_LUN_CMD \
0414     _IOR(IPMI_IOC_MAGIC, 26, struct ipmi_channel_lun_address_set)
0415 #define IPMICTL_GET_MY_CHANNEL_LUN_CMD \
0416     _IOR(IPMI_IOC_MAGIC, 27, struct ipmi_channel_lun_address_set)
0417 /* Legacy interfaces, these only set IPMB 0. */
0418 #define IPMICTL_SET_MY_ADDRESS_CMD  _IOR(IPMI_IOC_MAGIC, 17, unsigned int)
0419 #define IPMICTL_GET_MY_ADDRESS_CMD  _IOR(IPMI_IOC_MAGIC, 18, unsigned int)
0420 #define IPMICTL_SET_MY_LUN_CMD      _IOR(IPMI_IOC_MAGIC, 19, unsigned int)
0421 #define IPMICTL_GET_MY_LUN_CMD      _IOR(IPMI_IOC_MAGIC, 20, unsigned int)
0422 
0423 /*
0424  * Get/set the default timing values for an interface.  You shouldn't
0425  * generally mess with these.
0426  */
0427 struct ipmi_timing_parms {
0428     int          retries;
0429     unsigned int retry_time_ms;
0430 };
0431 #define IPMICTL_SET_TIMING_PARMS_CMD    _IOR(IPMI_IOC_MAGIC, 22, \
0432                          struct ipmi_timing_parms)
0433 #define IPMICTL_GET_TIMING_PARMS_CMD    _IOR(IPMI_IOC_MAGIC, 23, \
0434                          struct ipmi_timing_parms)
0435 
0436 /*
0437  * Set the maintenance mode.  See ipmi_set_maintenance_mode() above
0438  * for a description of what this does.
0439  */
0440 #define IPMICTL_GET_MAINTENANCE_MODE_CMD    _IOR(IPMI_IOC_MAGIC, 30, int)
0441 #define IPMICTL_SET_MAINTENANCE_MODE_CMD    _IOW(IPMI_IOC_MAGIC, 31, int)
0442 
0443 #endif /* _UAPI__LINUX_IPMI_H */