mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: han.junyang@zte.com.cn
Cc: 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 v3 1/3] dinghai: add firmware version check and? RISC-V readiness polling
Date: Tue, 22 Sep 2026 11:11:33 +0100	[thread overview]
Message-ID: <20260922101132.GB13925@horms.kernel.org> (raw)
In-Reply-To: <202609211456442872LYTVrDg_UG7l6DJ0Slmt@zte.com.cn>

On Mon, Sep 21, 2026 at 02:56:44PM +0800, han.junyang@zte.com.cn wrote:
> From: Junyang Han <han.junyang@zte.com.cn>
> 
> The DingHai firmware publishes a version compatibility block and a
> RISC-V health buffer at fixed offsets within BAR 0.
> 
> After the PCI capabilities are mapped, poll the compatibility block
> until the firmware populates it (the region reads as all ones until
> then) and verify the driver/firmware version contract. Then wait for
> the RISC-V management core to set its power-on flag in the health
> buffer before the rest of the probe continues.
> 
> Firmware images predating the health buffer protocol (health version
> other than 1 and patch level below ZXDH_HPIRQ_PATCH) skip the
> readiness wait.
> 
> Signed-off-by: Junyang Han <han.junyang@zte.com.cn>
> ---
>  drivers/net/ethernet/zte/dinghai/en_pf.c | 113 +++++++++++++++++++++++
>  drivers/net/ethernet/zte/dinghai/en_pf.h |  46 +++++++++
>  2 files changed, 159 insertions(+)
> 
> diff --git a/drivers/net/ethernet/zte/dinghai/en_pf.c b/drivers/net/ethernet/zte/dinghai/en_pf.c
> index 86d437408820..7c991e0951a8 100644
> --- a/drivers/net/ethernet/zte/dinghai/en_pf.c
> +++ b/drivers/net/ethernet/zte/dinghai/en_pf.c
> @@ -6,6 +6,8 @@
> 
>  #include <linux/module.h>
>  #include <linux/pci.h>
> +#include <linux/io.h>
> +#include <linux/iopoll.h>
>  #include <net/devlink.h>
>  #include <linux/dma-mapping.h>
>  #include "en_pf.h"
> @@ -369,6 +371,103 @@ int zxdh_pf_modern_cfg_init(struct zxdh_core_dev *zxdh_dev)
>  	return ret;
>  }
> 
> +/* 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;
> +	u32 erased;
> +
> +	fw_compat = &pf_dev->fw_compat;
> +	compat = pf_dev->pci_ioremap_addr[0] + ZXDH_FW_COMPAT_OFFSET;
> +
> +	/* The region reads as all ones until the firmware populates it at
> +	 * the end of its boot; allow up to 200 s for a cold boot.
> +	 */
> +	readx_poll_timeout(ioread32, compat, erased, erased != 0xffffffffU,
> +			   USEC_PER_SEC,
> +			   ZXDH_FW_COMPAT_TIMEOUT_SEC * USEC_PER_SEC);

Hi,

There is an AI-generated review of this patch available at
https://sashiko.dev/#/patchset/202609211451400236_aZ55Ox3y7NW8MQnYImM%40zte.com.cn

In my view the critical point made there, which I'd appreciate you looking
into, is:

  Is the timeout error intentionally ignored here? If legacy firmware never
  populates this region, wouldn't the 200 second stall exceed the default
  udev timeout (180s), causing the worker to be killed and completely
  breaking legacy hardware support?

> +
> +	/* 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);
> +
> +	if (fw_compat->module_id != ZXDH_MODULE_ID) {
> +		dev_info(zxdh_dev->device,
> +			 "unknown module id %u, skip fw compat check\n",
> +			 fw_compat->module_id);
> +		/* Unknown firmware is treated as predating the HPIRQ
> +		 * patch, so that the readiness wait is skipped.
> +		 */
> +		fw_compat->patch = 0;
> +		return 0;
> +	}
> +
> +	if (fw_compat->major != ZXDH_MAJOR) {
> +		dev_err(zxdh_dev->device,
> +			"driver major %u incompatible with firmware major %u\n",
> +			ZXDH_MAJOR, fw_compat->major);
> +		return -EINVAL;
> +	}
> +
> +	if (fw_compat->fw_minor < ZXDH_FW_MINOR) {
> +		dev_err(zxdh_dev->device,
> +			"firmware fw_minor %u older than required %u\n",
> +			fw_compat->fw_minor, ZXDH_FW_MINOR);
> +		return -EINVAL;
> +	}
> +
> +	if (fw_compat->drv_minor > ZXDH_DRV_MINOR) {
> +		dev_err(zxdh_dev->device,
> +			"driver drv_minor %u older than required by firmware %u\n",
> +			ZXDH_DRV_MINOR, fw_compat->drv_minor);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}

...

  reply	other threads:[~2026-09-22 10:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21  6:51 [PATCH net-next v3 0/3] dinghai: firmware handshake, MSI-X pools and async event queues han.junyang
2026-09-21  6:56 ` [PATCH net-next v3 1/3] dinghai: add firmware version check and RISC-V readiness polling han.junyang
2026-09-22 10:11   ` Simon Horman [this message]
2026-09-21  6:59 ` [PATCH net-next v3 2/3] dinghai: add MSI-X interrupt pools han.junyang
2026-09-22 10:09   ` Simon Horman
2026-09-21  7:03 ` [PATCH net-next v3 3/3] dinghai: add async event queue for firmware notifications han.junyang

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=20260922101132.GB13925@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®