Re: [PATCH v35 net-next 2/8] net/nebula-matrix: add common resource implementation
From: netdev-bot+sashiko
Date: Mon Nov 23 2026 - 07:52:11 EST
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The control-PF probe reads firmware-written board
configuration from the mailbox BAR exactly once: the DW3 port…
- [Low] net/nebula-matrix: single-implementation hw_ops and commit
message mismatch
--
net/nebula-matrix: add common resource implementation
This adds a chip-agnostic resource layer for the Nebula Matrix driver. On
the control PF it reads the PF topology, per-PF BDF, Ethernet port and VSI
mappings from hardware and firmware registers once at probe time. It also
adds plain lookup helpers that convert between VSI, PF and Ethernet IDs.
> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
> index f363ab1fd4168..fa5b88e8c70fc 100644
> --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_hw_leonis.c
[ ... ]
> +/*
> + * Registers reset to zero after cold boot / FLR / bus reset. Firmware
> + * programs valid values before driver probe, so zero is only seen on
> + * hardware fault or register read failure. Initialize data=0 to guard
> + * against nbl_hw_read_mbx_regs() early-return on bounds-check failure.
> + */
> +static void nbl_hw_get_fw_eth_map(struct nbl_hw_mgt *hw_mgt, u32 *eth_map)
> +{
> + u32 data = 0;
> +
> + nbl_hw_read_mbx_regs(hw_mgt, NBL_FW_BOARD_DW6_OFFSET, &data,
> + sizeof(data));
> + *eth_map = FIELD_GET(NBL_FW_BOARD_DW6_ETH_BITMAP_MASK, data);
> +}
[ ... ]
> +static void nbl_hw_get_board_info(struct nbl_hw_mgt *hw_mgt,
> + struct nbl_board_port_info *board_info)
> +{
> + u32 data = 0;
> +
> + nbl_hw_read_mbx_regs(hw_mgt, NBL_FW_BOARD_DW3_OFFSET, &data,
> + sizeof(data));
> + board_info->eth_num = FIELD_GET(NBL_FW_BOARD_DW3_PORT_NUM_MASK, data);
[ ... ]
> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c
> new file mode 100644
> index 0000000000000..b96ac999ec82f
> --- /dev/null
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_hw/nbl_hw_leonis/nbl_resource_leonis.c
[ ... ]
> +static int nbl_res_ctrl_dev_setup_eth_info(struct nbl_resource_mgt *res_mgt)
> +{
[ ... ]
> + fw_port_num = res_mgt->resource_info->board_info.eth_num;
> +
> + hw_ops->get_fw_eth_map(res_mgt->hw_ops_tbl->priv, ð_bitmap);
> + if (eth_bitmap & ~((1 << NBL_MAX_ETHERNET) - 1)) {
> + dev_err(dev, "FW reported invalid eth_bitmap 0x%x\n",
> + eth_bitmap);
> + return -EINVAL;
> + }
> + if (fw_port_num != hweight32(eth_bitmap)) {
> + dev_err(dev, "FW inconsistency: port_num=%u, bitmap=0x%x\n",
> + fw_port_num, eth_bitmap);
> + return -EINVAL;
> + }
> + /*
> + * Firmware is ready before probe. Valid port counts are 1/2/4;
> + * 0 (invalid config), 3 (unsupported topology), and >4 (exceeds
> + * hardware max) are all rejected with -EINVAL.
> + */
> + if (fw_port_num == 0 || fw_port_num == 3 ||
> + fw_port_num > NBL_MAX_ETHERNET) {
> + dev_err(dev, "FW reports %u Ethernet ports, unsupported (valid: 1/2/4)\n",
> + fw_port_num);
> + return -EINVAL;
> + }
[Severity: Medium]
What happens if the control PF is probed before firmware has rewritten the
DW3 and DW6 board words?
The comment above nbl_hw_get_fw_eth_map() and nbl_hw_get_board_info() says
these registers reset to zero after cold boot, FLR or bus reset. It relies on
firmware programming them before probe.
The probe path doesn't seem to check that this has happened. There is no
ready bit, poll or -EPROBE_DEFER between nbl_hw_init_leonis() and these
single reads:
nbl_probe()->nbl_core_init()->nbl_res_init_leonis()->nbl_res_start()
->nbl_res_init_board_info()
->nbl_res_ctrl_dev_setup_eth_info()
If PF0 is bound shortly after an FLR or secondary bus reset, for example a
sysfs reset followed by a bind, both reads could return 0. Then:
eth_bitmap == 0 passes the check for bits above NBL_MAX_ETHERNET
fw_port_num == 0 passes fw_port_num != hweight32(eth_bitmap)
fw_port_num == 0 returns -EINVAL
The control PF probe would then fail for good. Later in the series the
sibling PFs wait on function 0 via nbl_probe_chip_deps(). Would they stay in
-EPROBE_DEFER until the management PF is rebound by hand?
Could the all-zero case be treated as "firmware not ready yet" instead of an
invalid configuration? A bounded readiness poll in nbl_res_start(), or
returning -EPROBE_DEFER for that case, would do it.
> + eth_info->eth_num = fw_port_num;
[ ... ]
> +static int nbl_res_start(struct nbl_resource_mgt *res_mgt)
> +{
> + struct nbl_common_info *common = res_mgt->common;
> + int ret = 0;
> +
> + if (common->has_ctrl) {
> + nbl_res_init_board_info(res_mgt);
> +
> + ret = nbl_res_init_pf_num(res_mgt);
> + if (ret)
> + return ret;
[ ... ]
> diff --git a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h
> --- a/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h
> +++ b/drivers/net/ethernet/nebula-matrix/nbl/nbl_include/nbl_def_hw.h
> @@ -44,9 +57,22 @@ struct nbl_hw_ops {
> * PFs starting at PF0.
> */
> void (*get_host_pf_mask)(struct nbl_hw_mgt *hw_mgt, u32 *pf_mask);
> + void (*get_real_bus)(struct nbl_hw_mgt *hw_mgt, u8 *bus);
>
> void (*cfg_mailbox_qinfo)(struct nbl_hw_mgt *hw_mgt, u16 func_id,
> u8 bus, u8 devid, u8 function);
> + void (*get_fw_eth_map)(struct nbl_hw_mgt *hw_mgt, u32 *eth_map);
> + /**
> + * get_board_info - Fetch board info from firmware
> + * @hw_mgt: hardware management context
> + * @board_info: output pointer for board info structure
> + *
> + * Firmware contract: board_info.eth_num MUST equal the number of
> + * unmasked PFs from get_host_pf_mask(). See get_host_pf_mask for
> + * details.
> + */
> + void (*get_board_info)(struct nbl_hw_mgt *hw_mgt,
> + struct nbl_board_port_info *board_info);
> };
>
> struct nbl_hw_ops_tbl {
[Severity: Low]
This patch adds four more callbacks to struct nbl_hw_ops (flush_write,
get_real_bus, get_fw_eth_map and get_board_info), and nbl_hw_ops still
has only one implementation, the static hw_ops in nbl_hw_leonis.c.
v35 dropped nbl_resource_ops after the earlier request not to add ops
tables until a second implementation exists. Does the same reasoning
apply to nbl_hw_ops?
The callers in nbl_res_init_pf_num(), nbl_res_ctrl_dev_pf_info_init(),
nbl_res_ctrl_dev_setup_eth_info() and nbl_res_init_board_info() are all
in nbl_hw_leonis/nbl_resource_leonis.c, so this is Leonis code calling
Leonis helpers through res_mgt->hw_ops_tbl->ops. nbl_hw_setup_ops()
also devm-allocates a wrapper whose only job is to point at a static
table. Could these be direct calls until draco actually lands?
The commit message also doesn't seem to match the code. It says
nbl_hw_ops_tbl is the only remaining ops table, but struct
nbl_channel_ops_tbl is already in struct nbl_interface, and a later
patch in the series adds struct nbl_dispatch_ops_tbl. It also says the
PF mask validation and the BDF/Eth/VSI table construction are shared
between the two chip families. Those are static functions in
nbl_resource_leonis.c, called only from nbl_res_init_leonis(). Only the
ID conversion helpers in nbl_resource.c are chip-agnostic. Can the
description be updated, or the shared code moved where the message
says it is?
Finally, this patch removes the NULL checks on the static hw_ops
members in nbl_hw_setup_ops() that the channel layer patch earlier in
this series added. Those checks could never fire. Could they be left
out of the patch that introduces nbl_hw_setup_ops(), so this one does
not have to delete them?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119113530.32107-1-illusion.wang%40nebula-matrix.com