444 lines · c
1/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */2/*3 * ipmi.h4 *5 * MontaVista IPMI interface6 *7 * Author: MontaVista Software, Inc.8 * Corey Minyard <minyard@mvista.com>9 * source@mvista.com10 *11 * Copyright 2002 MontaVista Software Inc.12 *13 */14 15#ifndef _UAPI__LINUX_IPMI_H16#define _UAPI__LINUX_IPMI_H17 18#include <linux/ipmi_msgdefs.h>19#include <linux/compiler.h>20 21/*22 * This file describes an interface to an IPMI driver. You have to23 * have a fairly good understanding of IPMI to use this, so go read24 * the specs first before actually trying to do anything.25 *26 * With that said, this driver provides a multi-user interface to the27 * IPMI driver, and it allows multiple IPMI physical interfaces below28 * the driver. The physical interfaces bind as a lower layer on the29 * driver. They appear as interfaces to the application using this30 * interface.31 *32 * Multi-user means that multiple applications may use the driver,33 * send commands, receive responses, etc. The driver keeps track of34 * commands the user sends and tracks the responses. The responses35 * will go back to the application that send the command. If the36 * response doesn't come back in time, the driver will return a37 * timeout error response to the application. Asynchronous events38 * from the BMC event queue will go to all users bound to the driver.39 * The incoming event queue in the BMC will automatically be flushed40 * if it becomes full and it is queried once a second to see if41 * anything is in it. Incoming commands to the driver will get42 * delivered as commands.43 */44 45/*46 * This is an overlay for all the address types, so it's easy to47 * determine the actual address type. This is kind of like addresses48 * work for sockets.49 */50#define IPMI_MAX_ADDR_SIZE 3251struct ipmi_addr {52 /* Try to take these from the "Channel Medium Type" table53 in section 6.5 of the IPMI 1.5 manual. */54 int addr_type;55 short channel;56 char data[IPMI_MAX_ADDR_SIZE];57};58 59/*60 * When the address is not used, the type will be set to this value.61 * The channel is the BMC's channel number for the channel (usually62 * 0), or IPMC_BMC_CHANNEL if communicating directly with the BMC.63 */64#define IPMI_SYSTEM_INTERFACE_ADDR_TYPE 0x0c65struct ipmi_system_interface_addr {66 int addr_type;67 short channel;68 unsigned char lun;69};70 71/* An IPMB Address. */72#define IPMI_IPMB_ADDR_TYPE 0x0173/* Used for broadcast get device id as described in section 17.9 of the74 IPMI 1.5 manual. */75#define IPMI_IPMB_BROADCAST_ADDR_TYPE 0x4176struct ipmi_ipmb_addr {77 int addr_type;78 short channel;79 unsigned char slave_addr;80 unsigned char lun;81};82 83/*84 * Used for messages received directly from an IPMB that have not gone85 * through a MC. This is for systems that sit right on an IPMB so86 * they can receive commands and respond to them.87 */88#define IPMI_IPMB_DIRECT_ADDR_TYPE 0x8189struct ipmi_ipmb_direct_addr {90 int addr_type;91 short channel;92 unsigned char slave_addr;93 unsigned char rs_lun;94 unsigned char rq_lun;95};96 97/*98 * A LAN Address. This is an address to/from a LAN interface bridged99 * by the BMC, not an address actually out on the LAN.100 *101 * A conscious decision was made here to deviate slightly from the IPMI102 * spec. We do not use rqSWID and rsSWID like it shows in the103 * message. Instead, we use remote_SWID and local_SWID. This means104 * that any message (a request or response) from another device will105 * always have exactly the same address. If you didn't do this,106 * requests and responses from the same device would have different107 * addresses, and that's not too cool.108 *109 * In this address, the remote_SWID is always the SWID the remote110 * message came from, or the SWID we are sending the message to.111 * local_SWID is always our SWID. Note that having our SWID in the112 * message is a little weird, but this is required.113 */114#define IPMI_LAN_ADDR_TYPE 0x04115struct ipmi_lan_addr {116 int addr_type;117 short channel;118 unsigned char privilege;119 unsigned char session_handle;120 unsigned char remote_SWID;121 unsigned char local_SWID;122 unsigned char lun;123};124 125 126/*127 * Channel for talking directly with the BMC. When using this128 * channel, This is for the system interface address type only. FIXME129 * - is this right, or should we use -1?130 */131#define IPMI_BMC_CHANNEL 0xf132#define IPMI_NUM_CHANNELS 0x10133 134/*135 * Used to signify an "all channel" bitmask. This is more than the136 * actual number of channels because this is used in userland and137 * will cover us if the number of channels is extended.138 */139#define IPMI_CHAN_ALL (~0)140 141 142/*143 * A raw IPMI message without any addressing. This covers both144 * commands and responses. The completion code is always the first145 * byte of data in the response (as the spec shows the messages laid146 * out).147 */148struct ipmi_msg {149 unsigned char netfn;150 unsigned char cmd;151 unsigned short data_len;152 unsigned char __user *data;153};154 155struct kernel_ipmi_msg {156 unsigned char netfn;157 unsigned char cmd;158 unsigned short data_len;159 unsigned char *data;160};161 162/*163 * Various defines that are useful for IPMI applications.164 */165#define IPMI_INVALID_CMD_COMPLETION_CODE 0xC1166#define IPMI_TIMEOUT_COMPLETION_CODE 0xC3167#define IPMI_UNKNOWN_ERR_COMPLETION_CODE 0xff168 169 170/*171 * Receive types for messages coming from the receive interface. This172 * is used for the receive in-kernel interface and in the receive173 * IOCTL.174 *175 * The "IPMI_RESPONSE_RESPONSE_TYPE" is a little strange sounding, but176 * it allows you to get the message results when you send a response177 * message.178 */179#define IPMI_RESPONSE_RECV_TYPE 1 /* A response to a command */180#define IPMI_ASYNC_EVENT_RECV_TYPE 2 /* Something from the event queue */181#define IPMI_CMD_RECV_TYPE 3 /* A command from somewhere else */182#define IPMI_RESPONSE_RESPONSE_TYPE 4 /* The response for183 a sent response, giving any184 error status for sending the185 response. When you send a186 response message, this will187 be returned. */188#define IPMI_OEM_RECV_TYPE 5 /* The response for OEM Channels */189 190/* Note that async events and received commands do not have a completion191 code as the first byte of the incoming data, unlike a response. */192 193 194/*195 * Modes for ipmi_set_maint_mode() and the userland IOCTL. The AUTO196 * setting is the default and means it will be set on certain197 * commands. Hard setting it on and off will override automatic198 * operation.199 */200#define IPMI_MAINTENANCE_MODE_AUTO 0201#define IPMI_MAINTENANCE_MODE_OFF 1202#define IPMI_MAINTENANCE_MODE_ON 2203 204 205 206/*207 * The userland interface208 */209 210/*211 * The userland interface for the IPMI driver is a standard character212 * device, with each instance of an interface registered as a minor213 * number under the major character device.214 *215 * The read and write calls do not work, to get messages in and out216 * requires ioctl calls because of the complexity of the data. select217 * and poll do work, so you can wait for input using the file218 * descriptor, you just can use read to get it.219 *220 * In general, you send a command down to the interface and receive221 * responses back. You can use the msgid value to correlate commands222 * and responses, the driver will take care of figuring out which223 * incoming messages are for which command and find the proper msgid224 * value to report. You will only receive reponses for commands you225 * send. Asynchronous events, however, go to all open users, so you226 * must be ready to handle these (or ignore them if you don't care).227 *228 * The address type depends upon the channel type. When talking229 * directly to the BMC (IPMC_BMC_CHANNEL), the address is ignored230 * (IPMI_UNUSED_ADDR_TYPE). When talking to an IPMB channel, you must231 * supply a valid IPMB address with the addr_type set properly.232 *233 * When talking to normal channels, the driver takes care of the234 * details of formatting and sending messages on that channel. You do235 * not, for instance, have to format a send command, you just send236 * whatever command you want to the channel, the driver will create237 * the send command, automatically issue receive command and get even238 * commands, and pass those up to the proper user.239 */240 241 242/* The magic IOCTL value for this interface. */243#define IPMI_IOC_MAGIC 'i'244 245 246/* Messages sent to the interface are this format. */247struct ipmi_req {248 unsigned char __user *addr; /* Address to send the message to. */249 unsigned int addr_len;250 251 long msgid; /* The sequence number for the message. This252 exact value will be reported back in the253 response to this request if it is a command.254 If it is a response, this will be used as255 the sequence value for the response. */256 257 struct ipmi_msg msg;258};259/*260 * Send a message to the interfaces. error values are:261 * - EFAULT - an address supplied was invalid.262 * - EINVAL - The address supplied was not valid, or the command263 * was not allowed.264 * - EMSGSIZE - The message to was too large.265 * - ENOMEM - Buffers could not be allocated for the command.266 */267#define IPMICTL_SEND_COMMAND _IOR(IPMI_IOC_MAGIC, 13, \268 struct ipmi_req)269 270/* Messages sent to the interface with timing parameters are this271 format. */272struct ipmi_req_settime {273 struct ipmi_req req;274 275 /* See ipmi_request_settime() above for details on these276 values. */277 int retries;278 unsigned int retry_time_ms;279};280/*281 * Send a message to the interfaces with timing parameters. error values282 * are:283 * - EFAULT - an address supplied was invalid.284 * - EINVAL - The address supplied was not valid, or the command285 * was not allowed.286 * - EMSGSIZE - The message to was too large.287 * - ENOMEM - Buffers could not be allocated for the command.288 */289#define IPMICTL_SEND_COMMAND_SETTIME _IOR(IPMI_IOC_MAGIC, 21, \290 struct ipmi_req_settime)291 292/* Messages received from the interface are this format. */293struct ipmi_recv {294 int recv_type; /* Is this a command, response or an295 asyncronous event. */296 297 unsigned char __user *addr; /* Address the message was from is put298 here. The caller must supply the299 memory. */300 unsigned int addr_len; /* The size of the address buffer.301 The caller supplies the full buffer302 length, this value is updated to303 the actual message length when the304 message is received. */305 306 long msgid; /* The sequence number specified in the request307 if this is a response. If this is a command,308 this will be the sequence number from the309 command. */310 311 struct ipmi_msg msg; /* The data field must point to a buffer.312 The data_size field must be set to the313 size of the message buffer. The314 caller supplies the full buffer315 length, this value is updated to the316 actual message length when the message317 is received. */318};319 320/*321 * Receive a message. error values:322 * - EAGAIN - no messages in the queue.323 * - EFAULT - an address supplied was invalid.324 * - EINVAL - The address supplied was not valid.325 * - EMSGSIZE - The message to was too large to fit into the message buffer,326 * the message will be left in the buffer. */327#define IPMICTL_RECEIVE_MSG _IOWR(IPMI_IOC_MAGIC, 12, \328 struct ipmi_recv)329 330/*331 * Like RECEIVE_MSG, but if the message won't fit in the buffer, it332 * will truncate the contents instead of leaving the data in the333 * buffer.334 */335#define IPMICTL_RECEIVE_MSG_TRUNC _IOWR(IPMI_IOC_MAGIC, 11, \336 struct ipmi_recv)337 338/* Register to get commands from other entities on this interface. */339struct ipmi_cmdspec {340 unsigned char netfn;341 unsigned char cmd;342};343 344/*345 * Register to receive a specific command. error values:346 * - EFAULT - an address supplied was invalid.347 * - EBUSY - The netfn/cmd supplied was already in use.348 * - ENOMEM - could not allocate memory for the entry.349 */350#define IPMICTL_REGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 14, \351 struct ipmi_cmdspec)352/*353 * Unregister a registered command. error values:354 * - EFAULT - an address supplied was invalid.355 * - ENOENT - The netfn/cmd was not found registered for this user.356 */357#define IPMICTL_UNREGISTER_FOR_CMD _IOR(IPMI_IOC_MAGIC, 15, \358 struct ipmi_cmdspec)359 360/*361 * Register to get commands from other entities on specific channels.362 * This way, you can only listen on specific channels, or have messages363 * from some channels go to one place and other channels to someplace364 * else. The chans field is a bitmask, (1 << channel) for each channel.365 * It may be IPMI_CHAN_ALL for all channels.366 */367struct ipmi_cmdspec_chans {368 unsigned int netfn;369 unsigned int cmd;370 unsigned int chans;371};372 373/*374 * Register to receive a specific command on specific channels. error values:375 * - EFAULT - an address supplied was invalid.376 * - EBUSY - One of the netfn/cmd/chans supplied was already in use.377 * - ENOMEM - could not allocate memory for the entry.378 */379#define IPMICTL_REGISTER_FOR_CMD_CHANS _IOR(IPMI_IOC_MAGIC, 28, \380 struct ipmi_cmdspec_chans)381/*382 * Unregister some netfn/cmd/chans. error values:383 * - EFAULT - an address supplied was invalid.384 * - ENOENT - None of the netfn/cmd/chans were found registered for this user.385 */386#define IPMICTL_UNREGISTER_FOR_CMD_CHANS _IOR(IPMI_IOC_MAGIC, 29, \387 struct ipmi_cmdspec_chans)388 389/*390 * Set whether this interface receives events. Note that the first391 * user registered for events will get all pending events for the392 * interface. error values:393 * - EFAULT - an address supplied was invalid.394 */395#define IPMICTL_SET_GETS_EVENTS_CMD _IOR(IPMI_IOC_MAGIC, 16, int)396 397/*398 * Set and get the slave address and LUN that we will use for our399 * source messages. Note that this affects the interface, not just400 * this user, so it will affect all users of this interface. This is401 * so some initialization code can come in and do the OEM-specific402 * things it takes to determine your address (if not the BMC) and set403 * it for everyone else. You should probably leave the LUN alone.404 */405struct ipmi_channel_lun_address_set {406 unsigned short channel;407 unsigned char value;408};409#define IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD \410 _IOR(IPMI_IOC_MAGIC, 24, struct ipmi_channel_lun_address_set)411#define IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD \412 _IOR(IPMI_IOC_MAGIC, 25, struct ipmi_channel_lun_address_set)413#define IPMICTL_SET_MY_CHANNEL_LUN_CMD \414 _IOR(IPMI_IOC_MAGIC, 26, struct ipmi_channel_lun_address_set)415#define IPMICTL_GET_MY_CHANNEL_LUN_CMD \416 _IOR(IPMI_IOC_MAGIC, 27, struct ipmi_channel_lun_address_set)417/* Legacy interfaces, these only set IPMB 0. */418#define IPMICTL_SET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 17, unsigned int)419#define IPMICTL_GET_MY_ADDRESS_CMD _IOR(IPMI_IOC_MAGIC, 18, unsigned int)420#define IPMICTL_SET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 19, unsigned int)421#define IPMICTL_GET_MY_LUN_CMD _IOR(IPMI_IOC_MAGIC, 20, unsigned int)422 423/*424 * Get/set the default timing values for an interface. You shouldn't425 * generally mess with these.426 */427struct ipmi_timing_parms {428 int retries;429 unsigned int retry_time_ms;430};431#define IPMICTL_SET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 22, \432 struct ipmi_timing_parms)433#define IPMICTL_GET_TIMING_PARMS_CMD _IOR(IPMI_IOC_MAGIC, 23, \434 struct ipmi_timing_parms)435 436/*437 * Set the maintenance mode. See ipmi_set_maintenance_mode() above438 * for a description of what this does.439 */440#define IPMICTL_GET_MAINTENANCE_MODE_CMD _IOR(IPMI_IOC_MAGIC, 30, int)441#define IPMICTL_SET_MAINTENANCE_MODE_CMD _IOW(IPMI_IOC_MAGIC, 31, int)442 443#endif /* _UAPI__LINUX_IPMI_H */444