Re: [PATCH net-next v6 1/3] dinghai: add firmware version check and RISC-V readiness polling

From: Simon Horman

Date: Thu Nov 19 2026 - 07:06:22 EST


This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev/#/patchset/20261113135038394NowoSxTdiA32KKAPcTmCa@xxxxxxxxxx?part=1
---
dinghai: add firmware version check and RISC-V readiness polling

This commit polls the BAR 0 firmware compatibility block to verify the
driver/firmware version contract during PF probe and waits for the RISC-V
management core power-on flag when supported.

> diff --git a/drivers/net/ethernet/zte/dinghai/en_pf.c b/drivers/net/ethernet/zte/dinghai/en_pf.c
> index 86d4374088203..ddff9b0438fb3 100644
> --- a/drivers/net/ethernet/zte/dinghai/en_pf.c
> +++ b/drivers/net/ethernet/zte/dinghai/en_pf.c

[ ... ]

> @@ -369,6 +371,120 @@ int zxdh_pf_modern_cfg_init(struct zxdh_core_dev *zxdh_dev)
> return ret;
> }
>
> +/* The firmware fills the compatibility block field by field, so it is
> + * only ready to be read once every field we consume has lost its
> + * erased value.
> + */
> +static bool zxdh_pf_fw_compat_ready(struct zxdh_fw_compat __iomem *compat)
> +{
> + return ioread8(&compat->module_id) != 0xffU &&
> + ioread8(&compat->major) != 0xffU &&
> + ioread8(&compat->fw_minor) != 0xffU &&
> + ioread8(&compat->drv_minor) != 0xffU &&
> + ioread16(&compat->patch) != 0xffffU;
> +}
> +
> +/* Read the firmware version block and verify the driver/firmware
> + * version contract.
> + */
> +static int zxdh_pf_fw_compat_check(struct zxdh_core_dev *zxdh_dev)
> +{
> + struct zxdh_pf_dev *pf_dev = zxdh_dev->priv;
> + struct zxdh_fw_compat __iomem *compat;
> + struct zxdh_fw_compat *fw_compat;
> + bool ready;
> + int err;
> +
> + fw_compat = &pf_dev->fw_compat;
> + compat = pf_dev->pci_ioremap_addr[0] + ZXDH_FW_COMPAT_OFFSET;
> +
> + /* The firmware publishes the block within 10 s of boot; wait twice
> + * that to leave margin.
> + */
> + err = readx_poll_timeout(zxdh_pf_fw_compat_ready, compat, ready,
> + ready, USEC_PER_SEC,
> + ZXDH_FW_COMPAT_TIMEOUT_SEC * USEC_PER_SEC);
> + if (err)
> + dev_info(zxdh_dev->device,
> + "compat region not populated, assuming legacy firmware\n");
> +
> + /* Firmware predating the compatibility region keeps the erased
> + * pattern, which fails the module id check below and defers the
> + * decision to the readiness wait.
> + */
> + fw_compat->module_id = ioread8(&compat->module_id);
> + fw_compat->major = ioread8(&compat->major);
> + fw_compat->fw_minor = ioread8(&compat->fw_minor);
> + fw_compat->drv_minor = ioread8(&compat->drv_minor);
> + fw_compat->patch = ioread16(&compat->patch);

[Severity: Medium]
Does falling through on timeout here read and validate a partially populated
compatibility block?

Since the firmware populates compat field by field, readx_poll_timeout() can
time out after module_id is set to ZXDH_MODULE_ID while later fields still
hold 0xff or 0xffff. In that case the module_id check does not bail out, and
zxdh_pf_fw_compat_check() either fails probe with -EINVAL (if major or
drv_minor is still 0xff) or records fw_compat->patch as 0xffff, causing
zxdh_pf_wait_riscv_ready() to wait 40 seconds for riscv_power_on. Should the
if (err) branch set fw_compat->patch = 0 and return 0 directly?