From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGVRQ-0005Ug-3l for qemu-devel@nongnu.org; Tue, 05 Jan 2016 12:30:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGVRM-0001md-Qz for qemu-devel@nongnu.org; Tue, 05 Jan 2016 12:30:40 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:56268) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGVRM-0001lu-It for qemu-devel@nongnu.org; Tue, 05 Jan 2016 12:30:36 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Jan 2016 17:30:34 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 3376D17D8069 for ; Tue, 5 Jan 2016 17:31:17 +0000 (GMT) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u05HUWHu9699696 for ; Tue, 5 Jan 2016 17:30:32 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u05HUVOY021603 for ; Tue, 5 Jan 2016 10:30:32 -0700 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Date: Tue, 5 Jan 2016 18:29:58 +0100 Message-Id: <1452015002-28493-5-git-send-email-clg@fr.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 4/8] ipmi: add FRU support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Minyard Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-devel@nongnu.org, "Michael S. Tsirkin" This patch provides a simplistic FRU support for the IPMI BMC simulator. The FRU area contains 32 entries * 256 bytes which should be enough to start some simulation. Signed-off-by: Cédric Le Goater --- hw/ipmi/ipmi_bmc_sim.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c index 5db94491b130..60586a67104e 100644 --- a/hw/ipmi/ipmi_bmc_sim.c +++ b/hw/ipmi/ipmi_bmc_sim.c @@ -81,6 +81,9 @@ #define IPMI_CMD_ENTER_SDR_REP_UPD_MODE 0x2A #define IPMI_CMD_EXIT_SDR_REP_UPD_MODE 0x2B #define IPMI_CMD_RUN_INIT_AGENT 0x2C +#define IPMI_CMD_GET_FRU_AREA_INFO 0x10 +#define IPMI_CMD_READ_FRU_DATA 0x11 +#define IPMI_CMD_WRITE_FRU_DATA 0x12 #define IPMI_CMD_GET_SEL_INFO 0x40 #define IPMI_CMD_GET_SEL_ALLOC_INFO 0x41 #define IPMI_CMD_RESERVE_SEL 0x42 @@ -123,6 +126,14 @@ typedef struct IPMISdr { uint8_t overflow; } IPMISdr; +/* theoretically, the offset being 16bits, it should be 65536 */ +#define MAX_FRU_SIZE 256 +#define MAX_FRU_ID 32 + +typedef struct IPMIFru { + uint8_t data[MAX_FRU_SIZE][MAX_FRU_ID]; +} IPMIFru; + typedef struct IPMISensor { uint8_t status; uint8_t reading; @@ -206,6 +217,7 @@ struct IPMIBmcSim { IPMISel sel; IPMISdr sdr; + IPMIFru fru; IPMISensor sensors[MAX_SENSORS]; /* Odd netfns are for responses, so we only need the even ones. */ @@ -1305,6 +1317,110 @@ static void get_sel_info(IPMIBmcSim *ibs, return; } +static void get_fru_area_info(IPMIBmcSim *ibs, + uint8_t *cmd, unsigned int cmd_len, + uint8_t *rsp, unsigned int *rsp_len, + unsigned int max_rsp_len) +{ + uint8_t fruid; + uint16_t fru_entry_size; + + IPMI_CHECK_CMD_LEN(3); + + fruid = cmd[2]; + + if (fruid > MAX_FRU_ID) { + rsp[2] = IPMI_CC_INVALID_DATA_FIELD; + goto out; + } + + fru_entry_size = MAX_FRU_SIZE; + + IPMI_ADD_RSP_DATA(fru_entry_size & 0xff); + IPMI_ADD_RSP_DATA(fru_entry_size >> 8 & 0xff); + IPMI_ADD_RSP_DATA(0x0); +out: + return; +} + +#define min(x, y) ((x) < (y) ? (x) : (y)) +#define max(x, y) ((x) > (y) ? (x) : (y)) + +static void read_fru_data(IPMIBmcSim *ibs, + uint8_t *cmd, unsigned int cmd_len, + uint8_t *rsp, unsigned int *rsp_len, + unsigned int max_rsp_len) +{ + uint8_t fruid; + uint16_t offset; + int i; + uint8_t *fru_entry; + unsigned int count; + + IPMI_CHECK_CMD_LEN(5); + + fruid = cmd[2]; + offset = (cmd[3] | cmd[4] << 8); + + if (fruid > MAX_FRU_ID) { + rsp[2] = IPMI_CC_INVALID_DATA_FIELD; + goto out; + } + + if (offset >= MAX_FRU_SIZE - 1) { + rsp[2] = IPMI_CC_INVALID_DATA_FIELD; + goto out; + } + + fru_entry = ibs->fru.data[fruid]; + + count = min(cmd[5], MAX_FRU_SIZE - offset); + + IPMI_ADD_RSP_DATA(count & 0xff); + for (i = 0; i < count; i++) { + IPMI_ADD_RSP_DATA(fru_entry[offset + i]); + } + + out: + return; +} + +static void write_fru_data(IPMIBmcSim *ibs, + uint8_t *cmd, unsigned int cmd_len, + uint8_t *rsp, unsigned int *rsp_len, + unsigned int max_rsp_len) +{ + uint8_t fruid; + uint16_t offset; + uint8_t *fru_entry; + unsigned int count; + + IPMI_CHECK_CMD_LEN(5); + + fruid = cmd[2]; + offset = (cmd[3] | cmd[4] << 8); + + if (fruid > MAX_FRU_ID) { + rsp[2] = IPMI_CC_INVALID_DATA_FIELD; + goto out; + } + + if (offset >= MAX_FRU_SIZE - 1) { + rsp[2] = IPMI_CC_INVALID_DATA_FIELD; + goto out; + } + + fru_entry = ibs->fru.data[fruid]; + + count = min(cmd_len - 5, MAX_FRU_SIZE - offset); + + memcpy(fru_entry + offset, cmd + 5, count); + + IPMI_ADD_RSP_DATA(count & 0xff); + out: + return; +} + static void reserve_sel(IPMIBmcSim *ibs, uint8_t *cmd, unsigned int cmd_len, uint8_t *rsp, unsigned int *rsp_len, @@ -1682,6 +1798,9 @@ static const IPMINetfn app_netfn = { }; static const IPMICmdHandler storage_cmds[IPMI_NETFN_STORAGE_MAXCMD] = { + [IPMI_CMD_GET_FRU_AREA_INFO] = get_fru_area_info, + [IPMI_CMD_READ_FRU_DATA] = read_fru_data, + [IPMI_CMD_WRITE_FRU_DATA] = write_fru_data, [IPMI_CMD_GET_SDR_REP_INFO] = get_sdr_rep_info, [IPMI_CMD_RESERVE_SDR_REP] = reserve_sdr_rep, [IPMI_CMD_GET_SDR] = get_sdr, -- 2.1.4