From patchwork Thu Jan 21 17:18:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 8083581 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1290FBEEE5 for ; Thu, 21 Jan 2016 17:24:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 557FA20251 for ; Thu, 21 Jan 2016 17:24:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6AD9E2024F for ; Thu, 21 Jan 2016 17:24:27 +0000 (UTC) Received: from localhost ([::1]:49070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMIyA-0005yW-Pu for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jan 2016 12:24:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51756) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMItC-0005Ph-PC for qemu-devel@nongnu.org; Thu, 21 Jan 2016 12:19:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMItA-0005sh-7i for qemu-devel@nongnu.org; Thu, 21 Jan 2016 12:19:18 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:35352) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMIt9-0005rJ-Ug for qemu-devel@nongnu.org; Thu, 21 Jan 2016 12:19:16 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 21 Jan 2016 17:19:13 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 21 Jan 2016 17:19:11 -0000 X-IBM-Helo: d06dlp03.portsmouth.uk.ibm.com X-IBM-MailFrom: clg@fr.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id AE2E01B08061 for ; Thu, 21 Jan 2016 17:19:16 +0000 (GMT) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0LHJB4T10224056 for ; Thu, 21 Jan 2016 17:19:11 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 u0LHJAQc001192 for ; Thu, 21 Jan 2016 10:19:11 -0700 Received: from hermes.lab.toulouse-stg.fr.ibm.com (hermes.lab.toulouse-stg.fr.ibm.com [9.101.4.42]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u0LHJ718000958; Thu, 21 Jan 2016 10:19:10 -0700 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Corey Minyard Date: Thu, 21 Jan 2016 18:18:54 +0100 Message-Id: <1453396734-9363-10-git-send-email-clg@fr.ibm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1453396734-9363-1-git-send-email-clg@fr.ibm.com> References: <1453396734-9363-1-git-send-email-clg@fr.ibm.com> MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16012117-0021-0000-0000-00001FE59B97 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.111 Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Greg Kurz , qemu-devel@nongnu.org, Marcel Apfelbaum , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH v2 9/9] ipmi: add SET_SENSOR_READING command (tentative try) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP SET_SENSOR_READING is a complex IPMI command (IPMI spec : "35.17 Set Sensor Reading And Event Status Command"). Here is a very minimum framework fitting the Open PowerNV platform needs. This command is used on this platform to set the "System Firmware Progress" sensor and the "Boot Count" sensor. Signed-off-by: Cédric Le Goater Acked-by: Corey Minyard Reviewed-by: Greg Kurz --- hw/ipmi/ipmi_bmc_sim.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c index 53c75cb21c1a..0aa7e67ae217 100644 --- a/hw/ipmi/ipmi_bmc_sim.c +++ b/hw/ipmi/ipmi_bmc_sim.c @@ -46,6 +46,7 @@ #define IPMI_CMD_GET_SENSOR_READING 0x2d #define IPMI_CMD_SET_SENSOR_TYPE 0x2e #define IPMI_CMD_GET_SENSOR_TYPE 0x2f +#define IPMI_CMD_SET_SENSOR_READING 0x30 /* #define IPMI_NETFN_APP 0x06 In ipmi.h */ @@ -1616,6 +1617,139 @@ static void get_sensor_type(IPMIBmcSim *ibs, IPMI_ADD_RSP_DATA(sens->evt_reading_type_code); } +static void set_sensor_reading(IPMIBmcSim *ibs, + uint8_t *cmd, unsigned int cmd_len, + uint8_t *rsp, unsigned int *rsp_len, + unsigned int max_rsp_len) +{ + IPMISensor *sens; + uint8_t evd1; + uint8_t evd2; + uint8_t evd3; + + IPMI_CHECK_CMD_LEN(5); + if ((cmd[2] > MAX_SENSORS) || + !IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) { + rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT; + return; + } + + sens = ibs->sensors + cmd[2]; + + /* Sensor Reading operation */ + switch ((cmd[3]) & 0x3) { + case 0: /* Do not change */ + break; + case 1: /* write given value to sensor reading byte */ + sens->reading = cmd[4]; + break; + case 2: + case 3: + rsp[2] = IPMI_CC_INVALID_DATA_FIELD; + return; + } + + /* Deassertion bits operation */ + switch ((cmd[3] >> 2) & 0x3) { + case 0: /* Do not change */ + break; + case 1: /* write given value */ + if (cmd_len > 7) { + sens->deassert_states = cmd[7]; + } + if (cmd_len > 8) { + sens->deassert_states = cmd[8] << 8; + } + + case 2: /* mask on */ + if (cmd_len > 7) { + sens->deassert_states |= cmd[7]; + } + if (cmd_len > 8) { + sens->deassert_states |= cmd[8] << 8; + } + break; + case 3: /* mask off */ + if (cmd_len > 7) { + sens->deassert_states &= cmd[7]; + } + if (cmd_len > 8) { + sens->deassert_states &= (cmd[8] << 8); + } + break; + } + + /* Assertion bits operation */ + switch ((cmd[3] >> 4) & 0x3) { + case 0: /* Do not change */ + break; + case 1: /* write given value */ + if (cmd_len > 5) { + sens->assert_states = cmd[5]; + } + if (cmd_len > 6) { + sens->assert_states = cmd[6] << 8; + } + + case 2: /* mask on */ + if (cmd_len > 5) { + sens->assert_states |= cmd[5]; + } + if (cmd_len > 6) { + sens->assert_states |= cmd[6] << 8; + } + break; + case 3: /* mask off */ + if (cmd_len > 5) { + sens->assert_states &= cmd[5]; + } + if (cmd_len > 6) { + sens->assert_states &= (cmd[6] << 8); + } + break; + } + + evd1 = evd2 = evd3 = 0x0; + if (cmd_len > 9) { + evd1 = cmd[9]; + } + if (cmd_len > 10) { + evd2 = cmd[10]; + } + if (cmd_len > 11) { + evd3 = cmd[11]; + } + + /* Event Data Bytes operation */ + switch ((cmd[3] >> 6) & 0x3) { + case 0: /* Do not use the event data in message */ + evd1 = evd2 = evd3 = 0x0; + break; + case 1: /* Write given values to event data bytes excluding bits + * [3:0] Event Data 1. */ + evd1 &= 0xf0; + break; + case 2: /* Write given values to event data bytes including bits + * [3:0] Event Data 1. */ + break; + case 3: + rsp[2] = IPMI_CC_INVALID_DATA_FIELD; + return; + } + + if (IPMI_SENSOR_IS_DISCRETE(sens)) { + unsigned int bit = evd1 & 0xf; + uint16_t mask = (1 << bit); + + if (sens->assert_states & mask & sens->assert_enable) { + gen_event(ibs, cmd[2], 0, evd1, evd2, evd3); + } + + if (sens->deassert_states & mask & sens->deassert_enable) { + gen_event(ibs, cmd[2], 1, evd1, evd2, evd3); + } + } +} static const IPMICmdHandler chassis_cmds[] = { [IPMI_CMD_GET_CHASSIS_CAPABILITIES] = chassis_capabilities, @@ -1636,6 +1770,7 @@ static const IPMICmdHandler sensor_event_cmds[] = { [IPMI_CMD_GET_SENSOR_READING] = get_sensor_reading, [IPMI_CMD_SET_SENSOR_TYPE] = set_sensor_type, [IPMI_CMD_GET_SENSOR_TYPE] = get_sensor_type, + [IPMI_CMD_SET_SENSOR_READING] = set_sensor_reading }; static const IPMINetfn sensor_event_netfn = { .cmd_nums = ARRAY_SIZE(sensor_event_cmds),