From: Simon Horman <horms@kernel.org>
To: han.junyang@zte.com.cn
Cc: Simon Horman <horms@kernel.org>,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, ran.ming@zte.com.cn,
han.chengfei@zte.com.cn, zhang.yanze@zte.com.cn
Subject: Re: [PATCH net-next v6 1/3] dinghai: add firmware version check and RISC-V readiness polling
Date: Thu, 19 Nov 2026 12:05:37 +0000 [thread overview]
Message-ID: <20261119120536.1041197-2-horms@kernel.org> (raw)
In-Reply-To: <20261113135038394NowoSxTdiA32KKAPcTmCa@zte.com.cn>
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@zte.com.cn?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?
next prev parent reply other threads:[~2026-11-19 12:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 5:47 [PATCH net-next v6 0/3] dinghai: firmware handshake, MSI-X pools and async event queues han.junyang
2026-11-13 5:50 ` [PATCH net-next v6 1/3] dinghai: add firmware version check and RISC-V readiness polling han.junyang
2026-11-19 12:05 ` Simon Horman [this message]
2026-11-13 5:52 ` [PATCH net-next v6 2/3] dinghai: add MSI-X interrupt pools han.junyang
2026-11-21 23:31 ` Jakub Kicinski
2026-11-13 5:53 ` [PATCH net-next v6 3/3] dinghai: add async event queue for firmware notifications han.junyang
2026-11-21 23:31 ` Jakub Kicinski
2026-11-21 23:44 ` [PATCH net-next v6 0/3] dinghai: firmware handshake, MSI-X pools and async event queues patchwork-bot+netdevbpf
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=20261119120536.1041197-2-horms@kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=han.chengfei@zte.com.cn \
--cc=han.junyang@zte.com.cn \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ran.ming@zte.com.cn \
--cc=zhang.yanze@zte.com.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.