Re: [PATCH v2 4/4] tools/testing/cxl: add firmware update emulation to CXL memdevs

Jonathan Cameron
2023-06-08T14:54:44Z

On Mon, 05 Jun 2023 14:20:25 -0600
Vishal Verma <vishal.l.verma@intel.com> wrote:

> Add emulation for the 'Get FW Info', 'Transfer FW', and 'Activate FW'
> CXL mailbox commands to the cxl_test emulated memdevs to enable
> end-to-end unit testing of a firmware update flow. For now, only
> advertise an 'offline activation' capability as that is all the CXL
> memdev driver currently implements.
>
> Add some canned values for the serial number fields, and create a
> platform device sysfs knob to calculate the sha256sum of the firmware
> image that was received, so a unit test can compare it with the original
> file that was uploaded.
>
> Cc: Davidlohr Bueso <dave@stgolabs.net>
> Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
> Cc: Russ Weight <russell.h.weight@intel.com>
> Cc: Alison Schofield <alison.schofield@intel.com>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: Ben Widawsky <bwidawsk@kernel.org>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

One trivial comment inline.

I've somewhat lost track of the test utils, so less comfortable on reviewing
them than the kernel code. With that in mind this looks good to me.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
> tools/testing/cxl/test/mem.c | 162 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 162 insertions(+)
>

> +static int mock_activate_fw(struct cxl_dev_state *cxlds,
> + struct cxl_mbox_cmd *cmd)
> +{
> + struct cxl_mbox_activate_fw *activate = cmd->payload_in;
> + struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev);
> +
> + if (activate->slot == 0 || activate->slot > FW_SLOTS)
> + return -EINVAL;
> +
> + switch (activate->action) {
> + case CXL_FW_ACTIVATE_ONLINE:
> + mdata->fw_slot = activate->slot;
> + mdata->fw_staged = 0;
> + break;
> + case CXL_FW_ACTIVATE_OFFLINE:
> + mdata->fw_staged = activate->slot;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;

Might as well push the return 0 up to the cases instead of breaking out.

>