From: Jonathan Cameron via <qemu-devel@nongnu.org>
To: Klaus Jensen <its@irrelevant.dk>
Cc: Corey Minyard <cminyard@mvista.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Jason Wang <jasowang@redhat.com>, Keith Busch <kbusch@kernel.org>,
Lior Weintraub <liorw@pliops.com>,
Jeremy Kerr <jk@codeconstruct.com.au>,
Matt Johnston <matt@codeconstruct.com.au>,
Peter Delevoryas <peter@pjd.dev>, <qemu-devel@nongnu.org>,
<qemu-arm@nongnu.org>, <qemu-block@nongnu.org>,
"Klaus Jensen" <k.jensen@samsung.com>
Subject: Re: [PATCH v4 3/3] hw/nvme: add nvme management interface model
Date: Wed, 30 Aug 2023 15:47:08 +0100 [thread overview]
Message-ID: <20230830154708.000045ef@Huawei.com> (raw)
In-Reply-To: <20230823-nmi-i2c-v4-3-2b0f86e5be25@samsung.com>
On Wed, 23 Aug 2023 11:22:00 +0200
Klaus Jensen <its@irrelevant.dk> wrote:
> From: Klaus Jensen <k.jensen@samsung.com>
>
> Add the 'nmi-i2c' device that emulates an NVMe Management Interface
> controller.
>
> Initial support is very basic (Read NMI DS, Configuration Get).
>
> This is based on previously posted code by Padmakar Kalghatgi, Arun
> Kumar Agasar and Saurav Kumar.
>
> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Hi Klaus
Minor suggestions inline. Either way given how trivial they are
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> diff --git a/hw/nvme/nmi-i2c.c b/hw/nvme/nmi-i2c.c
> new file mode 100644
> index 000000000000..9040ba28a87c
> --- /dev/null
> +++ b/hw/nvme/nmi-i2c.c
> @@ -0,0 +1,418 @@
...
> +#define NMI_MAX_MESSAGE_LENGTH 4224
Spec reference or similar would be good for this.
...
> +
> +static void nmi_set_error(NMIDevice *nmi, uint8_t status)
> +{
> + uint8_t buf[4] = {};
> +
> + buf[0] = status;
Could just do
uint8_t buf[4] = { status, };
> +
> + memcpy(nmi->scratch + nmi->pos, buf, 4);
> + nmi->pos += 4;
sizeof(buf)
> +}
> +
> +static void nmi_handle_mi_read_nmi_ds(NMIDevice *nmi, NMIRequest *request)
> +{
> + I2CSlave *i2c = I2C_SLAVE(nmi);
> +
> + uint32_t dw0 = le32_to_cpu(request->dw0);
> + uint8_t dtyp = (dw0 >> 24) & 0xf;
Maybe FIELD_EX32() with appropriate defines?
> + uint8_t *buf;
> + size_t len;
> +
> + trace_nmi_handle_mi_read_nmi_ds(dtyp);
> +
> + static uint8_t nmi_ds_subsystem[36] = {
> + 0x00, /* success */
> + 0x20, 0x00, /* response data length */
> + 0x00, /* reserved */
> + 0x00, /* number of ports */
> + 0x01, /* major version */
> + 0x01, /* minor version */
> + };
> +
> + /* cannot be static since we need to patch in the i2c address */
> + uint8_t nmi_ds_ports[36] = {
> + 0x00, /* success */
> + 0x20, 0x00, /* response data length */
> + 0x00, /* reserved */
> + 0x02, /* port type (smbus) */
> + 0x00, /* reserved */
> + 0x40, 0x00, /* maximum mctp transission unit size (64 bytes) */
> + 0x00, 0x00, 0x00, 0x00, /* management endpoint buffer size */
> + 0x00, /* vpd i2c address */
> + 0x00, /* vpd i2c frequency */
> + 0x00, /* management endpoint i2c address */
> + 0x01, /* management endpoint i2c frequency */
> + 0x00, /* nvme basic management command NOT supported */
> + };
> +
> + /**
> + * Controller Information is zeroed, since there are no associated
> + * controllers at this point.
> + */
> + static uint8_t nmi_ds_ctrl[36] = {};
> +
> + /**
> + * For the Controller List, Optionally Supported Command List and
> + * Management Endpoint Buffer Supported Command List data structures.
> + *
> + * The Controller List data structure is defined in the NVM Express Base
> + * Specification, revision 2.0b, Figure 134.
> + */
> + static uint8_t nmi_ds_empty[6] = {
> + 0x00, /* success */
> + 0x02, /* response data length */
> + 0x00, 0x00, /* reserved */
> + 0x00, 0x00, /* number of entries (zero) */
> + };
> +
> + switch (dtyp) {
> + case NMI_CMD_READ_NMI_DS_SUBSYSTEM:
> + len = sizeof(nmi_ds_subsystem);
> + buf = nmi_ds_subsystem;
> +
> + break;
> +
> + case NMI_CMD_READ_NMI_DS_PORTS:
> + len = sizeof(nmi_ds_ports);
> + buf = nmi_ds_ports;
> +
> + /* patch in the i2c address of the endpoint */
> + buf[14] = i2c->address;
> +
> + break;
> +
> + case NMI_CMD_READ_NMI_DS_CTRL_INFO:
> + len = sizeof(nmi_ds_ctrl);
> + buf = nmi_ds_ctrl;
> +
> + break;
> +
> + case NMI_CMD_READ_NMI_DS_CTRL_LIST:
> + case NMI_CMD_READ_NMI_DS_OPT_CMD_SUPPORT:
> + case NMI_CMD_READ_NMI_DS_MEB_CMD_SUPPORT:
> + len = sizeof(nmi_ds_empty);
> + buf = nmi_ds_empty;
> +
> + break;
> +
> + default:
> + nmi_set_parameter_error(nmi, offsetof(NMIRequest, dw0) + 4, 0);
> +
> + return;
> + }
> +
> + memcpy(nmi->scratch + nmi->pos, buf, len);
> + nmi->pos += len;
> +}
> +
> +static void nmi_handle_mi_config_get(NMIDevice *nmi, NMIRequest *request)
> +{
> + uint32_t dw0 = le32_to_cpu(request->dw0);
> + uint8_t identifier = dw0 & 0xff;
> + uint8_t *buf;
> +
> + static uint8_t smbus_freq[4] = {
> + 0x00, /* success */
> + 0x01, 0x00, 0x00, /* 100 kHz */
> + };
const for these? Same for other similar buffers.
> +
> + static uint8_t mtu[4] = {
> + 0x00, /* success */
> + 0x40, 0x00, /* 64 */
> + 0x00, /* reserved */
> + };
> +
> + trace_nmi_handle_mi_config_get(identifier);
> +
> + switch (identifier) {
> + case NMI_CMD_CONFIGURATION_GET_SMBUS_FREQ:
> + buf = smbus_freq;
> + break;
> +
> + case NMI_CMD_CONFIGURATION_GET_MCTP_TRANSMISSION_UNIT:
> + buf = mtu;
> + break;
> +
> + default:
> + nmi_set_parameter_error(nmi, 0x0, offsetof(NMIRequest, dw0));
> + return;
> + }
> +
> + memcpy(nmi->scratch + nmi->pos, buf, 4);
> + nmi->pos += 4;
> +}
> +
> +static void nmi_handle(MCTPI2CEndpoint *mctp)
> +{
> + NMIDevice *nmi = NMI_I2C_DEVICE(mctp);
> + NMIMessage *msg = (NMIMessage *)nmi->buffer;
> + uint32_t crc;
> + uint8_t nmimt;
> +
> + uint8_t buf[] = {
const?
> + msg->mctpd,
> + FIELD_DP8(msg->nmp, NMI_NMP, ROR, 1),
> + 0x0, 0x0,
> + };
> +
> + if (FIELD_EX8(msg->mctpd, NMI_MCTPD, MT) != NMI_MCTPD_MT_NMI) {
> + goto drop;
> + }
> +
> + if (FIELD_EX8(msg->mctpd, NMI_MCTPD, IC) != NMI_MCTPD_IC_ENABLED) {
> + goto drop;
> + }
> +
> + memcpy(nmi->scratch, buf, sizeof(buf));
Jonathan
prev parent reply other threads:[~2023-08-30 14:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 9:21 [PATCH v4 0/3] hw/{i2c,nvme}: mctp endpoint, nvme management interface model Klaus Jensen
2023-08-23 9:21 ` [PATCH v4 1/3] hw/i2c: add smbus pec utility function Klaus Jensen
2023-08-30 13:04 ` Jonathan Cameron via
2023-08-23 9:21 ` [PATCH v4 2/3] hw/i2c: add mctp core Klaus Jensen
2023-08-30 14:31 ` Jonathan Cameron via
2023-09-04 10:49 ` Klaus Jensen
2023-08-23 9:22 ` [PATCH v4 3/3] hw/nvme: add nvme management interface model Klaus Jensen
2023-08-30 14:47 ` Jonathan Cameron via [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230830154708.000045ef@Huawei.com \
--to=qemu-devel@nongnu.org \
--cc=Jonathan.Cameron@Huawei.com \
--cc=cminyard@mvista.com \
--cc=its@irrelevant.dk \
--cc=jasowang@redhat.com \
--cc=jk@codeconstruct.com.au \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=liorw@pliops.com \
--cc=matt@codeconstruct.com.au \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peter@pjd.dev \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).