2018-02-20 16:30:22 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* ipmi_smi.h
|
|
|
|
*
|
|
|
|
* MontaVista IPMI system management interface
|
|
|
|
*
|
|
|
|
* Author: MontaVista Software, Inc.
|
|
|
|
* Corey Minyard <minyard@mvista.com>
|
|
|
|
* source@mvista.com
|
|
|
|
*
|
|
|
|
* Copyright 2002 MontaVista Software Inc.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_IPMI_SMI_H
|
|
|
|
#define __LINUX_IPMI_SMI_H
|
|
|
|
|
|
|
|
#include <linux/ipmi_msgdefs.h>
|
|
|
|
#include <linux/proc_fs.h>
|
2006-03-26 13:37:21 +04:00
|
|
|
#include <linux/platform_device.h>
|
2010-12-08 05:10:16 +03:00
|
|
|
#include <linux/ipmi.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-01-30 20:46:54 +04:00
|
|
|
struct device;
|
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* This files describes the interface for IPMI system management interface
|
|
|
|
* drivers to bind into the IPMI message handler.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Structure for the low-level drivers. */
|
2018-04-18 18:00:47 +03:00
|
|
|
struct ipmi_smi;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-10-23 19:29:02 +03:00
|
|
|
/*
|
|
|
|
* Flags for set_check_watch() below. Tells if the SMI should be
|
2018-10-24 23:17:04 +03:00
|
|
|
* waiting for watchdog timeouts, commands and/or messages.
|
2018-10-23 19:29:02 +03:00
|
|
|
*/
|
2018-10-24 23:17:04 +03:00
|
|
|
#define IPMI_WATCH_MASK_CHECK_MESSAGES (1 << 0)
|
|
|
|
#define IPMI_WATCH_MASK_CHECK_WATCHDOG (1 << 1)
|
|
|
|
#define IPMI_WATCH_MASK_CHECK_COMMANDS (1 << 2)
|
2018-10-23 19:29:02 +03:00
|
|
|
|
2021-09-24 19:42:56 +03:00
|
|
|
/*
|
|
|
|
* SMI messages
|
|
|
|
*
|
|
|
|
* When communicating with an SMI, messages come in two formats:
|
|
|
|
*
|
|
|
|
* * Normal (to a BMC over a BMC interface)
|
|
|
|
*
|
|
|
|
* * IPMB (over a IPMB to another MC)
|
|
|
|
*
|
|
|
|
* When normal, commands are sent using the format defined by a
|
|
|
|
* standard message over KCS (NetFn must be even):
|
|
|
|
*
|
|
|
|
* +-----------+-----+------+
|
|
|
|
* | NetFn/LUN | Cmd | Data |
|
|
|
|
* +-----------+-----+------+
|
|
|
|
*
|
|
|
|
* And responses, similarly, with an completion code added (NetFn must
|
|
|
|
* be odd):
|
|
|
|
*
|
|
|
|
* +-----------+-----+------+------+
|
|
|
|
* | NetFn/LUN | Cmd | CC | Data |
|
|
|
|
* +-----------+-----+------+------+
|
|
|
|
*
|
|
|
|
* With normal messages, only commands are sent and only responses are
|
|
|
|
* received.
|
|
|
|
*
|
|
|
|
* In IPMB mode, we are acting as an IPMB device. Commands will be in
|
|
|
|
* the following format (NetFn must be even):
|
|
|
|
*
|
|
|
|
* +-------------+------+-------------+-----+------+
|
|
|
|
* | NetFn/rsLUN | Addr | rqSeq/rqLUN | Cmd | Data |
|
|
|
|
* +-------------+------+-------------+-----+------+
|
|
|
|
*
|
|
|
|
* Responses will using the following format:
|
|
|
|
*
|
|
|
|
* +-------------+------+-------------+-----+------+------+
|
|
|
|
* | NetFn/rqLUN | Addr | rqSeq/rsLUN | Cmd | CC | Data |
|
|
|
|
* +-------------+------+-------------+-----+------+------+
|
|
|
|
*
|
|
|
|
* This is similar to the format defined in the IPMB manual section
|
|
|
|
* 2.11.1 with the checksums and the first address removed. Also, the
|
|
|
|
* address is always the remote address.
|
|
|
|
*
|
|
|
|
* IPMB messages can be commands and responses in both directions.
|
|
|
|
* Received commands are handled as received commands from the message
|
|
|
|
* queue.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum ipmi_smi_msg_type {
|
|
|
|
IPMI_SMI_MSG_TYPE_NORMAL = 0,
|
|
|
|
IPMI_SMI_MSG_TYPE_IPMB_DIRECT
|
|
|
|
};
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Messages to/from the lower layer. The smi interface will take one
|
|
|
|
* of these to send. After the send has occurred and a response has
|
|
|
|
* been received, it will report this same data structure back up to
|
|
|
|
* the upper layer. If an error occurs, it should fill in the
|
|
|
|
* response with an error code in the completion code location. When
|
|
|
|
* asynchronous data is received, one of these is allocated, the
|
|
|
|
* data_size is set to zero and the response holds the data from the
|
|
|
|
* get message or get event command that the interface initiated.
|
|
|
|
* Note that it is the interfaces responsibility to detect
|
|
|
|
* asynchronous data and messages and request them from the
|
|
|
|
* interface.
|
|
|
|
*/
|
2008-04-29 12:01:09 +04:00
|
|
|
struct ipmi_smi_msg {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct list_head link;
|
|
|
|
|
2021-09-24 19:42:56 +03:00
|
|
|
enum ipmi_smi_msg_type type;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
long msgid;
|
|
|
|
void *user_data;
|
|
|
|
|
|
|
|
int data_size;
|
|
|
|
unsigned char data[IPMI_MAX_MSG_LENGTH];
|
|
|
|
|
|
|
|
int rsp_size;
|
|
|
|
unsigned char rsp[IPMI_MAX_MSG_LENGTH];
|
|
|
|
|
2018-10-23 19:29:02 +03:00
|
|
|
/*
|
|
|
|
* Will be called when the system is done with the message
|
|
|
|
* (presumably to free it).
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
void (*done)(struct ipmi_smi_msg *msg);
|
|
|
|
};
|
|
|
|
|
2022-04-12 23:38:51 +03:00
|
|
|
#define INIT_IPMI_SMI_MSG(done_handler) \
|
|
|
|
{ \
|
|
|
|
.done = done_handler, \
|
|
|
|
.type = IPMI_SMI_MSG_TYPE_NORMAL \
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:01:09 +04:00
|
|
|
struct ipmi_smi_handlers {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct module *owner;
|
|
|
|
|
2021-09-24 19:42:56 +03:00
|
|
|
/* Capabilities of the SMI. */
|
|
|
|
#define IPMI_SMI_CAN_HANDLE_IPMB_DIRECT (1 << 0)
|
|
|
|
unsigned int flags;
|
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* The low-level interface cannot start sending messages to
|
|
|
|
* the upper layer until this function is called. This may
|
|
|
|
* not be NULL, the lower layer must take the interface from
|
|
|
|
* this call.
|
|
|
|
*/
|
2018-04-11 21:11:54 +03:00
|
|
|
int (*start_processing)(void *send_info,
|
|
|
|
struct ipmi_smi *new_intf);
|
2006-03-31 14:30:39 +04:00
|
|
|
|
2018-04-06 00:44:12 +03:00
|
|
|
/*
|
|
|
|
* When called, the low-level interface should disable all
|
|
|
|
* processing, it should be complete shut down when it returns.
|
|
|
|
*/
|
|
|
|
void (*shutdown)(void *send_info);
|
|
|
|
|
2010-12-08 05:10:16 +03:00
|
|
|
/*
|
|
|
|
* Get the detailed private info of the low level interface and store
|
|
|
|
* it into the structure of ipmi_smi_data. For example: the
|
|
|
|
* ACPI device handle will be returned for the pnp_acpi IPMI device.
|
|
|
|
*/
|
|
|
|
int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data);
|
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* Called to enqueue an SMI message to be sent. This
|
|
|
|
* operation is not allowed to fail. If an error occurs, it
|
|
|
|
* should report back the error in a received message. It may
|
|
|
|
* do this in the current call context, since no write locks
|
|
|
|
* are held when this is run. Message are delivered one at
|
|
|
|
* a time by the message handler, a new message will not be
|
|
|
|
* delivered until the previous message is returned.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
void (*sender)(void *send_info,
|
2014-11-07 16:57:31 +03:00
|
|
|
struct ipmi_smi_msg *msg);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* Called by the upper layer to request that we try to get
|
|
|
|
* events from the BMC we are attached to.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
void (*request_events)(void *send_info);
|
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* Called by the upper layer when some user requires that the
|
2018-10-23 19:29:02 +03:00
|
|
|
* interface watch for received messages and watchdog
|
|
|
|
* pretimeouts (basically do a "Get Flags", or not. Used by
|
|
|
|
* the SMI to know if it should watch for these. This may be
|
|
|
|
* NULL if the SMI does not implement it. watch_mask is from
|
|
|
|
* IPMI_WATCH_MASK_xxx above. The interface should run slower
|
|
|
|
* timeouts for just watchdog checking or faster timeouts when
|
|
|
|
* waiting for the message queue.
|
2018-04-04 16:54:05 +03:00
|
|
|
*/
|
2018-10-23 19:29:02 +03:00
|
|
|
void (*set_need_watch)(void *send_info, unsigned int watch_mask);
|
2014-04-14 18:46:54 +04:00
|
|
|
|
2015-07-27 08:55:16 +03:00
|
|
|
/*
|
|
|
|
* Called when flushing all pending messages.
|
|
|
|
*/
|
|
|
|
void (*flush_messages)(void *send_info);
|
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* Called when the interface should go into "run to
|
|
|
|
* completion" mode. If this call sets the value to true, the
|
|
|
|
* interface should make sure that all messages are flushed
|
|
|
|
* out and that none are pending, and any new requests are run
|
|
|
|
* to completion immediately.
|
|
|
|
*/
|
2014-04-14 18:46:56 +04:00
|
|
|
void (*set_run_to_completion)(void *send_info, bool run_to_completion);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* Called to poll for work to do. This is so upper layers can
|
|
|
|
* poll for operations during things like crash dumps.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
void (*poll)(void *send_info);
|
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* Enable/disable firmware maintenance mode. Note that this
|
|
|
|
* is *not* the modes defined, this is simply an on/off
|
|
|
|
* setting. The message handler does the mode handling. Note
|
|
|
|
* that this is called from interrupt context, so it cannot
|
|
|
|
* block.
|
|
|
|
*/
|
2014-04-14 18:46:56 +04:00
|
|
|
void (*set_maintenance_mode)(void *send_info, bool enable);
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2006-03-26 13:37:21 +04:00
|
|
|
struct ipmi_device_id {
|
|
|
|
unsigned char device_id;
|
|
|
|
unsigned char device_revision;
|
|
|
|
unsigned char firmware_revision_1;
|
|
|
|
unsigned char firmware_revision_2;
|
|
|
|
unsigned char ipmi_version;
|
|
|
|
unsigned char additional_device_support;
|
|
|
|
unsigned int manufacturer_id;
|
|
|
|
unsigned int product_id;
|
|
|
|
unsigned char aux_firmware_revision[4];
|
|
|
|
unsigned int aux_firmware_revision_set : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
|
|
|
|
#define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
|
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* Take a pointer to an IPMI response and extract device id information from
|
2017-08-25 10:47:23 +03:00
|
|
|
* it. @netfn is in the IPMI_NETFN_ format, so may need to be shifted from
|
|
|
|
* a SI response.
|
|
|
|
*/
|
|
|
|
static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd,
|
|
|
|
const unsigned char *data,
|
2007-10-18 14:07:11 +04:00
|
|
|
unsigned int data_len,
|
|
|
|
struct ipmi_device_id *id)
|
2006-03-26 13:37:21 +04:00
|
|
|
{
|
2017-08-25 10:47:23 +03:00
|
|
|
if (data_len < 7)
|
2007-10-18 14:07:11 +04:00
|
|
|
return -EINVAL;
|
2017-08-25 10:47:23 +03:00
|
|
|
if (netfn != IPMI_NETFN_APP_RESPONSE || cmd != IPMI_GET_DEVICE_ID_CMD)
|
2007-10-18 14:07:11 +04:00
|
|
|
/* Strange, didn't get the response we expected. */
|
|
|
|
return -EINVAL;
|
2017-08-25 10:47:23 +03:00
|
|
|
if (data[0] != 0)
|
2007-10-18 14:07:11 +04:00
|
|
|
/* That's odd, it shouldn't be able to fail. */
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-08-25 10:47:23 +03:00
|
|
|
data++;
|
|
|
|
data_len--;
|
|
|
|
|
2006-03-26 13:37:21 +04:00
|
|
|
id->device_id = data[0];
|
|
|
|
id->device_revision = data[1];
|
|
|
|
id->firmware_revision_1 = data[2];
|
|
|
|
id->firmware_revision_2 = data[3];
|
|
|
|
id->ipmi_version = data[4];
|
|
|
|
id->additional_device_support = data[5];
|
2007-10-30 00:37:13 +03:00
|
|
|
if (data_len >= 11) {
|
2007-10-18 14:07:11 +04:00
|
|
|
id->manufacturer_id = (data[6] | (data[7] << 8) |
|
|
|
|
(data[8] << 16));
|
|
|
|
id->product_id = data[9] | (data[10] << 8);
|
|
|
|
} else {
|
|
|
|
id->manufacturer_id = 0;
|
|
|
|
id->product_id = 0;
|
|
|
|
}
|
2006-03-26 13:37:21 +04:00
|
|
|
if (data_len >= 15) {
|
|
|
|
memcpy(id->aux_firmware_revision, data+11, 4);
|
|
|
|
id->aux_firmware_revision_set = 1;
|
|
|
|
} else
|
|
|
|
id->aux_firmware_revision_set = 0;
|
2007-10-18 14:07:11 +04:00
|
|
|
|
|
|
|
return 0;
|
2006-03-26 13:37:21 +04:00
|
|
|
}
|
|
|
|
|
2018-04-04 16:54:05 +03:00
|
|
|
/*
|
|
|
|
* Add a low-level interface to the IPMI driver. Note that if the
|
|
|
|
* interface doesn't know its slave address, it should pass in zero.
|
|
|
|
* The low-level interface should not deliver any messages to the
|
|
|
|
* upper layer until the start_processing() function in the handlers
|
|
|
|
* is called, and the lower layer must get the interface from that
|
|
|
|
* call.
|
|
|
|
*/
|
2019-10-14 18:35:56 +03:00
|
|
|
int ipmi_add_smi(struct module *owner,
|
|
|
|
const struct ipmi_smi_handlers *handlers,
|
|
|
|
void *send_info,
|
|
|
|
struct device *dev,
|
|
|
|
unsigned char slave_addr);
|
|
|
|
|
|
|
|
#define ipmi_register_smi(handlers, send_info, dev, slave_addr) \
|
|
|
|
ipmi_add_smi(THIS_MODULE, handlers, send_info, dev, slave_addr)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a low-level interface from the IPMI driver. This will
|
|
|
|
* return an error if the interface is still in use by a user.
|
|
|
|
*/
|
2018-04-11 21:11:54 +03:00
|
|
|
void ipmi_unregister_smi(struct ipmi_smi *intf);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The lower layer reports received messages through this interface.
|
2012-09-20 05:48:02 +04:00
|
|
|
* The data_size should be zero if this is an asynchronous message. If
|
2005-04-17 02:20:36 +04:00
|
|
|
* the lower layer gets an error sending a message, it should format
|
|
|
|
* an error response in the message response.
|
|
|
|
*/
|
2018-04-11 21:11:54 +03:00
|
|
|
void ipmi_smi_msg_received(struct ipmi_smi *intf,
|
2005-04-17 02:20:36 +04:00
|
|
|
struct ipmi_smi_msg *msg);
|
|
|
|
|
|
|
|
/* The lower layer received a watchdog pre-timeout on interface. */
|
2018-04-11 21:11:54 +03:00
|
|
|
void ipmi_smi_watchdog_pretimeout(struct ipmi_smi *intf);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
|
|
|
|
static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
|
|
|
|
{
|
|
|
|
msg->done(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __LINUX_IPMI_SMI_H */
|