From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2hmn-0001ID-0Q for qemu-devel@nongnu.org; Mon, 24 Apr 2017 13:28:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2hmh-0007cy-Ts for qemu-devel@nongnu.org; Mon, 24 Apr 2017 13:28:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d2hmh-0007c5-K9 for qemu-devel@nongnu.org; Mon, 24 Apr 2017 13:28:23 -0400 Date: Mon, 24 Apr 2017 20:28:20 +0300 From: "Michael S. Tsirkin" Message-ID: <20170424202145-mutt-send-email-mst@kernel.org> References: <1491980930-32184-1-git-send-email-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1491980930-32184-1-git-send-email-clg@kaod.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] ipmi: add SET_SENSOR_READING command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?C=E9dric?= Le Goater Cc: Corey Minyard , David Gibson , qemu-devel@nongnu.org On Wed, Apr 12, 2017 at 09:08:50AM +0200, C=C3=A9dric Le Goater wrote: > SET_SENSOR_READING is a complex IPMI command (see IPMI spec 35.17) > which enables the host software to set the reading value and the event > status of sensors supporting it. >=20 > Below is a proposal for all the operations (reading, assert, deassert, > event data) with the following limitations : >=20 > - No event are generated for threshold-based sensors.=20 > - The case in which the BMC needs to generate its own events is not > supported. > =20 > Signed-off-by: C=C3=A9dric Le Goater Need to look at how guests will behave if they start on a new QEMU and migrate to old one. Any input? Do we need a flag to behave like 2.9 did if we want compatibility? > --- >=20 > Corey, >=20 > There is some progress but I didn't add a check on the value before > generating events because we would not generate an event when only > the event bytes change.=20 >=20 > Changes since v1: > =20 > - created copies of the reading and the assertion bits before > committing the values > - added some TODOs > - handled inconsistent Event Data Bytes operation > =20 > hw/ipmi/ipmi_bmc_sim.c | 213 ++++++++++++++++++++++++++++++++++++++++= +++++++++ > 1 file changed, 213 insertions(+) >=20 > Index: qemu-powernv-2.9.git/hw/ipmi/ipmi_bmc_sim.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- qemu-powernv-2.9.git.orig/hw/ipmi/ipmi_bmc_sim.c > +++ qemu-powernv-2.9.git/hw/ipmi/ipmi_bmc_sim.c > @@ -45,6 +45,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 > =20 > /* #define IPMI_NETFN_APP 0x06 In ipmi.h */ > =20 > @@ -1739,6 +1740,217 @@ static void get_sensor_type(IPMIBmcSim * > rsp_buffer_push(rsp, sens->evt_reading_type_code); > } > =20 > +/* > + * bytes parameter > + * 1 sensor number > + * 2 operation (see below for bits meaning) > + * 3 sensor reading > + * 4:5 assertion states (optional) > + * 6:7 deassertion states (optional) > + * 8:10 event data 1,2,3 (optional) > + */ > +static void set_sensor_reading(IPMIBmcSim *ibs, > + uint8_t *cmd, unsigned int cmd_len, > + RspBuffer *rsp) > +{ > + IPMISensor *sens; > + uint8_t evd1 =3D 0; > + uint8_t evd2 =3D 0; > + uint8_t evd3 =3D 0; > + uint8_t new_reading =3D 0; > + uint16_t new_assert_states =3D 0; > + uint16_t new_deassert_states =3D 0; > + bool change_reading =3D false; > + bool change_assert =3D false; > + bool change_deassert =3D false; > + enum { > + SENSOR_GEN_EVENT_NONE, > + SENSOR_GEN_EVENT_DATA, > + SENSOR_GEN_EVENT_BMC, > + } do_gen_event =3D SENSOR_GEN_EVENT_NONE; > + > + if ((cmd[2] >=3D MAX_SENSORS) || > + !IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) { > + rsp_buffer_set_error(rsp, IPMI_CC_REQ_ENTRY_NOT_PRESENT); > + return; > + } > + > + sens =3D ibs->sensors + cmd[2]; > + > + /* [1:0] Sensor Reading operation */ > + switch ((cmd[3]) & 0x3) { > + case 0: /* Do not change */ > + break; > + case 1: /* write given value to sensor reading byte */ > + new_reading =3D cmd[4]; > + if (sens->reading !=3D new_reading) { > + change_reading =3D true; > + } > + break; > + case 2: > + case 3: > + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); > + return; > + } > + > + /* [3:2] Deassertion bits operation */ > + switch ((cmd[3] >> 2) & 0x3) { > + case 0: /* Do not change */ > + break; > + case 1: /* write given value */ > + if (cmd_len > 7) { > + new_deassert_states =3D cmd[7]; > + change_deassert =3D true; > + } > + if (cmd_len > 8) { > + new_deassert_states |=3D (cmd[8] << 8); > + } > + break; > + > + case 2: /* mask on */ > + if (cmd_len > 7) { > + new_deassert_states =3D (sens->deassert_states | cmd[7]); > + change_deassert =3D true; > + } > + if (cmd_len > 8) { > + new_deassert_states |=3D (sens->deassert_states | (cmd[8] = << 8)); > + } > + break; > + > + case 3: /* mask off */ > + if (cmd_len > 7) { > + new_deassert_states =3D (sens->deassert_states & cmd[7]); > + change_deassert =3D true; > + } > + if (cmd_len > 8) { > + new_deassert_states |=3D (sens->deassert_states & (cmd[8] = << 8)); > + } > + break; > + } > + > + if (change_deassert && (new_deassert_states =3D=3D sens->deassert_= states)) { > + change_deassert =3D false; > + } > + > + /* [5:4] Assertion bits operation */ > + switch ((cmd[3] >> 4) & 0x3) { > + case 0: /* Do not change */ > + break; > + case 1: /* write given value */ > + if (cmd_len > 5) { > + new_assert_states =3D cmd[5]; > + change_assert =3D true; > + } > + if (cmd_len > 6) { > + new_assert_states |=3D (cmd[6] << 8); > + } > + break; > + > + case 2: /* mask on */ > + if (cmd_len > 5) { > + new_assert_states =3D (sens->assert_states | cmd[5]); > + change_assert =3D true; > + } > + if (cmd_len > 6) { > + new_assert_states |=3D (sens->assert_states | (cmd[6] << 8= )); > + } > + break; > + > + case 3: /* mask off */ > + if (cmd_len > 5) { > + new_assert_states =3D (sens->assert_states & cmd[5]); > + change_assert =3D true; > + } > + if (cmd_len > 6) { > + new_assert_states |=3D (sens->assert_states & (cmd[6] << 8= )); > + } > + break; > + } > + > + if (change_assert && (new_assert_states =3D=3D sens->assert_states= )) { > + change_assert =3D false; > + } > + > + if (cmd_len > 9) { > + evd1 =3D cmd[9]; > + } > + if (cmd_len > 10) { > + evd2 =3D cmd[10]; > + } > + if (cmd_len > 11) { > + evd3 =3D cmd[11]; > + } > + > + /* [7:6] Event Data Bytes operation */ > + switch ((cmd[3] >> 6) & 0x3) { > + case 0: /* Don=E2=80=99t use Event Data bytes from this command. B= MC will > + * generate it's own Event Data bytes based on its sensor > + * implementation. */ > + evd1 =3D evd2 =3D evd3 =3D 0x0; > + do_gen_event =3D SENSOR_GEN_EVENT_BMC; > + break; > + case 1: /* Write given values to event data bytes including bits > + * [3:0] Event Data 1. */ > + do_gen_event =3D SENSOR_GEN_EVENT_DATA; > + break; > + case 2: /* Write given values to event data bytes excluding bits > + * [3:0] Event Data 1. */ > + evd1 &=3D 0xf0; > + do_gen_event =3D SENSOR_GEN_EVENT_DATA; > + break; > + case 3: > + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); > + return; > + } > + > + /* Event Data Bytes operation and parameter are inconsistent. The > + * Specs are not clear on that topic but generating an error seems > + * correct. */ > + if (do_gen_event =3D=3D SENSOR_GEN_EVENT_DATA && cmd_len < 10) { > + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); > + return; > + } > + > + /* commit values */ > + if (change_reading) { > + sens->reading =3D new_reading; > + } > + > + if (change_assert) { > + sens->assert_states =3D new_assert_states; > + } > + > + if (change_deassert) { > + sens->deassert_states =3D new_deassert_states; > + } > + > + /* TODO: handle threshold sensor */ > + if (!IPMI_SENSOR_IS_DISCRETE(sens)) { > + return; > + } > + > + switch (do_gen_event) { > + case SENSOR_GEN_EVENT_DATA: { > + unsigned int bit =3D evd1 & 0xf; > + uint16_t mask =3D (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); > + } > + } > + break; > + case SENSOR_GEN_EVENT_BMC: > + /* TODO: generate event and event data bytes depending on the > + * sensor */ > + break; > + case SENSOR_GEN_EVENT_NONE: > + break; > + } > +} > =20 > static const IPMICmdHandler chassis_cmds[] =3D { > [IPMI_CMD_GET_CHASSIS_CAPABILITIES] =3D { chassis_capabilities }, > @@ -1759,6 +1971,7 @@ static const IPMICmdHandler sensor_event > [IPMI_CMD_GET_SENSOR_READING] =3D { get_sensor_reading, 3 }, > [IPMI_CMD_SET_SENSOR_TYPE] =3D { set_sensor_type, 5 }, > [IPMI_CMD_GET_SENSOR_TYPE] =3D { get_sensor_type, 3 }, > + [IPMI_CMD_SET_SENSOR_READING] =3D { set_sensor_reading, 5 }, > }; > static const IPMINetfn sensor_event_netfn =3D { > .cmd_nums =3D ARRAY_SIZE(sensor_event_cmds),