linux/include/uapi/linux/ipmi.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
   2/*
   3 * ipmi.h
   4 *
   5 * MontaVista IPMI interface
   6 *
   7 * Author: MontaVista Software, Inc.
   8 *         Corey Minyard <minyard@mvista.com>
   9 *         source@mvista.com
  10 *
  11 * Copyright 2002 MontaVista Software Inc.
  12 *
  13 *  This program is free software; you can redistribute it and/or modify it
  14 *  under the terms of the GNU General Public License as published by the
  15 *  Free Software Foundation; either version 2 of the License, or (at your
  16 *  option) any later version.
  17 *
  18 *
  19 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  20 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22 *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  23 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25 *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26 *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  27 *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  28 *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29 *
  30 *  You should have received a copy of the GNU General Public License along
  31 *  with this program; if not, write to the Free Software Foundation, Inc.,
  32 *  675 Mass Ave, Cambridge, MA 02139, USA.
  33 */
  34
  35#ifndef _UAPI__LINUX_IPMI_H
  36#define _UAPI__LINUX_IPMI_H
  37
  38#include <linux/ipmi_msgdefs.h>
  39#include <linux/compiler.h>
  40
  41/*
  42 * This file describes an interface to an IPMI driver.  You have to
  43 * have a fairly good understanding of IPMI to use this, so go read
  44 * the specs first before actually trying to do anything.
  45 *
  46 * With that said, this driver provides a multi-user interface to the
  47 * IPMI driver, and it allows multiple IPMI physical interfaces below
  48 * the driver.  The physical interfaces bind as a lower layer on the
  49 * driver.  They appear as interfaces to the application using this
  50 * interface.
  51 *
  52 * Multi-user means that multiple applications may use the driver,
  53 * send commands, receive responses, etc.  The driver keeps track of
  54 * commands the user sends and tracks the responses.  The responses
  55 * will go back to the application that send the command.  If the
  56 * response doesn't come back in time, the driver will return a
  57 * timeout error response to the application.  Asynchronous events
  58 * from the BMC event queue will go to all users bound to the driver.
  59 * The incoming event queue in the BMC will automatically be flushed
  60 * if it becomes full and it is queried once a second to see if
  61 * anything is in it.  Incoming commands to the driver will get
  62 * delivered as commands.
  63 */
  64
  65/*
  66 * This is an overlay for all the address types, so it's easy to
  67 * determine the actual address type.  This is kind of like addresses
  68 * work for sockets.
  69 */
  70#define IPMI_MAX_ADDR_SIZE 32
  71struct ipmi_addr {
  72         /* Try to take these from the "Channel Medium Type" table
  73            in section 6.5 of the IPMI 1.5 manual. */
  74        int   addr_type;
  75        short channel;
  76        char  data[IPMI_MAX_ADDR_SIZE];
  77};
  78
  79/*
  80 * When the address is not used, the type will be set to this value.
  81 * The channel is the BMC's channel number for the channel (usually
  82 * 0), or IPMC_BMC_CHANNEL if communicating directly with the BMC.
  83 */
  84#define IPMI_SYSTEM_INTERFACE_ADDR_TYPE 0x0c
  85struct ipmi_system_interface_addr {
  86        int           addr_type;
  87        short         channel;
  88        unsigned char lun;
  89};
  90
  91/* An IPMB Address. */
  92#define IPMI_IPMB_ADDR_TYPE             0x01
  93/* Used for broadcast get device id as described in section 17.9 of the
  94   IPMI 1.5 manual. */
  95#define IPMI_IPMB_BROADCAST_ADDR_TYPE   0x41
  96struct ipmi_ipmb_addr {
  97        int           addr_type;
  98        short         channel;
  99        unsigned char slave_addr;
 100        unsigned char lun;
 101};
 102
 103/*
 104 * A LAN Address.  This is an address to/from a LAN interface bridged
 105 * by the BMC, not an address actually out on the LAN.
 106 *
 107 * A conscious decision was made here to deviate slightly from the IPMI
 108 * spec.  We do not use rqSWID and rsSWID like it shows in the
 109 * message.  Instead, we use remote_SWID and local_SWID.  This means
 110 * that any message (a request or response) from another device will
 111 * always have exactly the same address.  If you didn't do this,
 112 * requests and responses from the same device would have different
 113 * addresses, and that's not too cool.
 114 *
 115 * In this address, the remote_SWID is always the SWID the remote
 116 * message came from, or the SWID we are sending the message to.
 117 * local_SWID is always our SWID.  Note that having our SWID in the
 118 * message is a little weird, but this is required.
 119 */
 120#define IPMI_LAN_ADDR_TYPE              0x04
 121struct ipmi_lan_addr {
 122        int           addr_type;
 123        short         channel;
 124        unsigned char privilege;
 125        unsigned char session_handle;
 126        unsigned char remote_SWID;
 127        unsigned char local_SWID;
 128        unsigned char lun;
 129};
 130
 131
 132/*
 133 * Channel for talking directly with the BMC.  When using this
 134 * channel, This is for the system interface address type only.  FIXME
 135 * - is this right, or should we use -1?
 136 */
 137#define IPMI_BMC_CHANNEL  0xf
 138#define IPMI_NUM_CHANNELS 0x10
 139
 140/*
 141 * Used to signify an "all channel" bitmask.  This is more than the
 142 * actual number of channels because this is used in userland and
 143 * will cover us if the number of channels is extended.
 144 */
 145#define IPMI_CHAN_ALL     (~0)
 146
 147
 148/*
 149 * A raw IPMI message without any addressing.  This covers both
 150 * commands and responses.  The completion code is always the first
 151 * byte of data in the response (as the spec shows the messages laid
 152 * out).
 153 */
 154struct ipmi_msg {
 155        unsigned char  netfn;
 156        unsigned char  cmd;
 157        unsigned short data_len;
 158        unsigned char  __user *data;
 159};
 160
 161struct kernel_ipmi_msg {
 162        unsigned char  netfn;
 163        unsigned char  cmd;
 164        unsigned short data_len;
 165        unsigned char  *data;
 166};
 167
 168/*
 169 * Various defines that are useful for IPMI applications.
 170 */
 171#define IPMI_INVALID_CMD_COMPLETION_CODE        0xC1
 172#define IPMI_TIMEOUT_COMPLETION_CODE            0xC3
 173#define IPMI_UNKNOWN_ERR_COMPLETION_CODE        0xff
 174
 175
 176/*
 177 * Receive types for messages coming from the receive interface.  This
 178 * is used for the receive in-kernel interface and in the receive
 179 * IOCTL.
 180 *
 181 * The "IPMI_RESPONSE_RESPNOSE_TYPE" is a little strange sounding, but
 182 * it allows you to get the message results when you send a response
 183 * message.
 184 */
 185#define IPMI_RESPONSE_RECV_TYPE         1 /* A response to a command */
 186#define IPMI_ASYNC_EVENT_RECV_TYPE      2 /* Something from the event queue */
 187#define IPMI_CMD_RECV_TYPE              3 /* A command from somewhere else */
 188#define IPMI_RESPONSE_RESPONSE_TYPE     4 /* The response for
 189                                              a sent response, giving any
 190                                              error status for sending the
 191                                              response.  When you send a
 192                                              response message, this will
 193                                              be returned. */
 194#define IPMI_OEM_RECV_TYPE              5 /* The response for OEM Channels */
 195
 196/* Note that async events and received commands do not have a completion
 197   code as the first byte of the incoming data, unlike a response. */
 198
 199
 200/*
 201 * Modes for ipmi_set_maint_mode() and the userland IOCTL.  The AUTO
 202 * setting is the default and means it will be set on certain
 203 * commands.  Hard setting it on and off will override automatic
 204 * operation.
 205 */
 206#define IPMI_MAINTENANCE_MODE_AUTO      0
 207#define IPMI_MAINTENANCE_MODE_OFF       1
 208#define IPMI_MAINTENANCE_MODE_ON        2
 209
 210
 211
 212/*
 213 * The userland interface
 214 */
 215
 216/*
 217 * The userland interface for the IPMI driver is a standard character
 218 * device, with each instance of an interface registered as a minor
 219 * number under the major character device.
 220 *
 221 * The read and write calls do not work, to get messages in and out
 222 * requires ioctl calls because of the complexity of the data.  select
 223 * and poll do work, so you can wait for input using the file
 224 * descriptor, you just can use read to get it.
 225 *
 226 * In general, you send a command down to the interface and receive
 227 * responses back.  You can use the msgid value to correlate commands
 228 * and responses, the driver will take care of figuring out which
 229 * incoming messages are for which command and find the proper msgid
 230 * value to report.  You will only receive reponses for commands you
 231 * send.  Asynchronous events, however, go to all open users, so you
 232 * must be ready to handle these (or ignore them if you don't care).
 233 *
 234 * The address type depends upon the channel type.  When talking
 235 * directly to the BMC (IPMC_BMC_CHANNEL), the address is ignored
 236 * (IPMI_UNUSED_ADDR_TYPE).  When talking to an IPMB channel, you must
 237 * supply a valid IPMB address with the addr_type set properly.
 238 *
 239 * When talking to normal channels, the driver takes care of the
 240 * details of formatting and sending messages on that channel.  You do
 241 * not, for instance, have to format a send command, you just send
 242 * whatever command you want to the channel, the driver will create
 243 * the send command, automatically issue receive command and get even
 244 * commands, and pass those up to the proper user.
 245 */
 246
 247
 248/* The magic IOCTL value for this interface. */
 249#define IPMI_IOC_MAGIC 'i'
 250
 251
 252/* Messages sent to the interface are this format. */
 253struct ipmi_req {
 254        unsigned char __user *addr; /* Address to send the message to. */
 255        unsigned int  addr_len;
 256
 257        long    msgid; /* The sequence number for the message.  This
 258                          exact value will be reported back in the
 259                          response to this request if it is a command.
 260                          If it is a response, this will be used as
 261                          the sequence value for the response.  */
 262
 263        struct ipmi_msg msg;
 264};
 265/*
 266 * Send a message to the interfaces.  error values are:
 267 *   - EFAULT - an address supplied was invalid.
 268 *   - EINVAL - The address supplied was not valid, or the command
 269 *              was not allowed.
 270 *   - EMSGSIZE - The message to was too large.
 271 *   - ENOMEM - Buffers could not be allocated for the command.
 272 */
 273#define IPMICTL_SEND_COMMAND            _IOR(IPMI_IOC_MAGIC, 13,        \
 274                                             struct ipmi_req)
 275
 276/* Messages sent to the interface with timing parameters are this
 277   format. */
 278struct ipmi_req_settime {
 279        struct ipmi_req req;
 280
 281        /* See ipmi_request_settime() above for details on these
 282           values. */
 283        int          retries;
 284        unsigned int retry_time_ms;
 285};
 286/*
 287 * Send a message to the interfaces with timing parameters.  error values
 288 * are:
 289 *   - EFAULT - an address supplied was invalid.
 290 *   - EINVAL - The address supplied was not valid, or the command
 291 *              was not allowed.
 292 *   - EMSGSIZE - The message to was too large.
 293 *   - ENOMEM - Buffers could not be allocated for the command.
 294 */
 295#define IPMICTL_SEND_COMMAND_SETTIME    _IOR(IPMI_IOC_MAGIC, 21,        \
 296                                             struct ipmi_req_settime)
 297
 298/* Messages received from the interface are this format. */
 299struct ipmi_recv {
 300        int     recv_type; /* Is this a command, response or an
 301                              asyncronous event. */
 302
 303        unsigned char __user *addr;    /* Address the message was from is put
 304                                   here.  The caller must supply the
 305                                   memory. */
 306        unsigned int  addr_len; /* The size of the address buffer.
 307                                   The caller supplies the full buffer
 308                                   length, this value is updated to
 309                                   the actual message length when the
 310                                   message is received. */
 311
 312        long    msgid; /* The sequence number specified in the request
 313                          if this is a response.  If this is a command,
 314                          this will be the sequence number from the
 315                          command. */
 316
 317        struct ipmi_msg msg; /* The data field must point to a buffer.
 318                                The data_size field must be set to the
 319                                size of the message buffer.  The
 320                                caller supplies the full buffer
 321                                length, this value is updated to the
 322                                actual message length when the message
 323                                is received. */
 324};
 325
 326/*
 327 * Receive a message.  error values:
 328 *  - EAGAIN - no messages in the queue.
 329 *  - EFAULT - an address supplied was invalid.
 330 *  - EINVAL - The address supplied was not valid.
 331 *  - EMSGSIZE - The message to was too large to fit into the message buffer,
 332 *               the message will be left in the buffer. */
 333#define IPMICTL_RECEIVE_MSG             _IOWR(IPMI_IOC_MAGIC, 12,       \
 334                                              struct ipmi_recv)
 335
 336/*
 337 * Like RECEIVE_MSG, but if the message won't fit in the buffer, it
 338 * will truncate the contents instead of leaving the data in the
 339 * buffer.
 340 */
 341#define IPMICTL_RECEIVE_MSG_TRUNC       _IOWR(IPMI_IOC_MAGIC, 11,       \
 342                                              struct ipmi_recv)
 343
 344/* Register to get commands from other entities on this interface. */
 345struct ipmi_cmdspec {
 346        unsigned char netfn;
 347        unsigned char cmd;
 348};
 349
 350/*
 351 * Register to receive a specific command.  error values:
 352 *   - EFAULT - an address supplied was invalid.
 353 *   - EBUSY - The netfn/cmd supplied was already in use.
 354 *   - ENOMEM - could not allocate memory for the entry.
 355 */
 356#define IPMICTL_REGISTER_FOR_CMD        _IOR(IPMI_IOC_MAGIC, 14,        \
 357                                             struct ipmi_cmdspec)
 358/*
 359 * Unregister a registered command.  error values:
 360 *  - EFAULT - an address supplied was invalid.
 361 *  - ENOENT - The netfn/cmd was not found registered for this user.
 362 */
 363#define IPMICTL_UNREGISTER_FOR_CMD      _IOR(IPMI_IOC_MAGIC, 15,        \
 364                                             struct ipmi_cmdspec)
 365
 366/*
 367 * Register to get commands from other entities on specific channels.
 368 * This way, you can only listen on specific channels, or have messages
 369 * from some channels go to one place and other channels to someplace
 370 * else.  The chans field is a bitmask, (1 << channel) for each channel.
 371 * It may be IPMI_CHAN_ALL for all channels.
 372 */
 373struct ipmi_cmdspec_chans {
 374        unsigned int netfn;
 375        unsigned int cmd;
 376        unsigned int chans;
 377};
 378
 379/*
 380 * Register to receive a specific command on specific channels.  error values:
 381 *   - EFAULT - an address supplied was invalid.
 382 *   - EBUSY - One of the netfn/cmd/chans supplied was already in use.
 383 *   - ENOMEM - could not allocate memory for the entry.
 384 */
 385#define IPMICTL_REGISTER_FOR_CMD_CHANS  _IOR(IPMI_IOC_MAGIC, 28,        \
 386                                             struct ipmi_cmdspec_chans)
 387/*
 388 * Unregister some netfn/cmd/chans.  error values:
 389 *  - EFAULT - an address supplied was invalid.
 390 *  - ENOENT - None of the netfn/cmd/chans were found registered for this user.
 391 */
 392#define IPMICTL_UNREGISTER_FOR_CMD_CHANS _IOR(IPMI_IOC_MAGIC, 29,       \
 393                                             struct ipmi_cmdspec_chans)
 394
 395/*
 396 * Set whether this interface receives events.  Note that the first
 397 * user registered for events will get all pending events for the
 398 * interface.  error values:
 399 *  - EFAULT - an address supplied was invalid.
 400 */
 401#define IPMICTL_SET_GETS_EVENTS_CMD     _IOR(IPMI_IOC_MAGIC, 16, int)
 402
 403/*
 404 * Set and get the slave address and LUN that we will use for our
 405 * source messages.  Note that this affects the interface, not just
 406 * this user, so it will affect all users of this interface.  This is
 407 * so some initialization code can come in and do the OEM-specific
 408 * things it takes to determine your address (if not the BMC) and set
 409 * it for everyone else.  You should probably leave the LUN alone.
 410 */
 411struct ipmi_channel_lun_address_set {
 412        unsigned short channel;
 413        unsigned char  value;
 414};
 415#define IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD \
 416        _IOR(IPMI_IOC_MAGIC, 24, struct ipmi_channel_lun_address_set)
 417#define IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD \
 418        _IOR(IPMI_IOC_MAGIC, 25, struct ipmi_channel_lun_address_set)
 419#define IPMICTL_SET_MY_CHANNEL_LUN_CMD \
 420        _IOR(IPMI_IOC_MAGIC, 26, struct ipmi_channel_lun_address_set)
 421#define IPMICTL_GET_MY_CHANNEL_LUN_CMD \
 422        _IOR(IPMI_IOC_MAGIC, 27, struct ipmi_channel_lun_address_set)
 423/* Legacy interfaces, these only set IPMB 0. */
 424#define IPMICTL_SET_MY_ADDRESS_CMD      _IOR(IPMI_IOC_MAGIC, 17, unsigned int)
 425#define IPMICTL_GET_MY_ADDRESS_CMD      _IOR(IPMI_IOC_MAGIC, 18, unsigned int)
 426#define IPMICTL_SET_MY_LUN_CMD          _IOR(IPMI_IOC_MAGIC, 19, unsigned int)
 427#define IPMICTL_GET_MY_LUN_CMD          _IOR(IPMI_IOC_MAGIC, 20, unsigned int)
 428
 429/*
 430 * Get/set the default timing values for an interface.  You shouldn't
 431 * generally mess with these.
 432 */
 433struct ipmi_timing_parms {
 434        int          retries;
 435        unsigned int retry_time_ms;
 436};
 437#define IPMICTL_SET_TIMING_PARMS_CMD    _IOR(IPMI_IOC_MAGIC, 22, \
 438                                             struct ipmi_timing_parms)
 439#define IPMICTL_GET_TIMING_PARMS_CMD    _IOR(IPMI_IOC_MAGIC, 23, \
 440                                             struct ipmi_timing_parms)
 441
 442/*
 443 * Set the maintenance mode.  See ipmi_set_maintenance_mode() above
 444 * for a description of what this does.
 445 */
 446#define IPMICTL_GET_MAINTENANCE_MODE_CMD        _IOR(IPMI_IOC_MAGIC, 30, int)
 447#define IPMICTL_SET_MAINTENANCE_MODE_CMD        _IOW(IPMI_IOC_MAGIC, 31, int)
 448
 449#endif /* _UAPI__LINUX_IPMI_H */
 450