RE: [PATCH v8 net-next 6/9] net: dsa: netc: check return value of ntmp_ipft_delete_entry()

From: Wei Fang

Date: Mon Nov 23 2026 - 01:27:10 EST


> > @@ -1880,32 +1874,36 @@ static int netc_port_add_host_flood_rule(struct
> netc_port *np,
> > return err;
> > }
> >
> > -static void netc_port_remove_host_flood(struct netc_port *np, u32
> entry_id)
> > +static int netc_port_remove_host_flood(struct netc_port *np)
> > {
> > struct netc_switch *priv = np->switch_priv;
> > - bool disable_host_flood = false;
> > + u32 entry_id = np->ipft_hf_eid;
> > + int err;
> >
> > if (entry_id == NTMP_NULL_ENTRY_ID)
> > - return;
> > + return 0;
> >
> > - if (np->ipft_hf_eid == entry_id)
> > - disable_host_flood = true;
> > + /* The command BD ring is always enabled here, with the ring
> > + * enabled, the hardware completes a command well within 1 ms,
> > + * so -ETIMEDOUT cannot happen here. Any error therefore means
> > + * that the entry has not been deleted, so keep tracking it.
> > + */
> > + err = ntmp_ipft_delete_entry(&priv->ntmp, entry_id);
> > + if (err)
> > + return err;
>
> [Severity: Medium]
> Is it safe to read every error from ntmp_ipft_delete_entry() as "the
> entry was not deleted"?
>
> In netc_xmit_ntmp_cmd() in drivers/net/ethernet/freescale/enetc/ntmp.c,
> the command BD is posted and the producer index is written before the
> poll:
>
> cbdr->next_to_use = i;
> netc_write(cbdr->regs.pir, i);
>
> err = read_poll_timeout(netc_read, val,
> (val & NETC_CBDRCIR_INDEX) == i,
> NETC_CBDR_DELAY_US,
> NETC_CBDR_TIMEOUT,
> true, cbdr->regs.cir);
> if (unlikely(err))
> return err;
>
> if (unlikely(val & NETC_CBDRCIR_SBE)) {
> dev_err(cbdr->dev, "Command BD system bus error\n");
> return -EIO;
> }
>
> When this returns -ETIMEDOUT, or -EIO for SBE, the hardware may already
> have done the delete, or may still do it later. The comment above rules
> out the timeout, but nothing in the code enforces that. There are also
> two command rings (NETC_CBDR_NUM is 2), and the poll is a fixed 1 ms.
>
> If the delete did take effect, np->ipft_hf_eid would keep an entry ID
> that no longer exists. Every later delete of that ID would then fail on
> the response error status check in netc_xmit_ntmp_cmd():
>
> if (unlikely(status)) {
> dev_err(cbdr->dev, "Command BD error: 0x%04x\n", status);
> return -EIO;
>
> Wouldn't that make the failure permanent?

A timeout error will only occur when the command BD ring is disabled.
Normally, from a hardware perspective, the execution time of a single
command BD is far less than 1 ms. Therefore, there should be no timeout
error. Otherwise, this is a hardware issue. The current interfaces are not
called when the command BD ring is disabled, so there will be no timeout
error.

The SBE error stands for System Bus Error, which indicates that the current
command bus (BD) failed to execute. In fact, if this error occurs, it indicates
a problem with the system configuration; all command BD operations will
generate this error.

In fact, netc_xmit_ntmp_cmd() should not have any errors; otherwise, it
indicates a configuration error or a hardware issue. Checking for various
errors here is to prevent misconfigurations during development from
causing unsuccessful feature setup, and to verify the hardware functionality
of new SoCs.

Therefore, for verified features, netc_xmit_ntmp_cmd() will not return
errors. Otherwise, it indicates a problem that needs fixing, rather than
an expectation that the hardware or software is still working correctly.

>
> >
> > - ntmp_ipft_delete_entry(&priv->ntmp, entry_id);
> > + np->ipft_hf_eid = NTMP_NULL_ENTRY_ID;
> > + np->uc = false;
> > + np->mc = false;
> > + netc_port_wr(np, NETC_PIPFCR, 0);
>
> [ ... ]
>
> > @@ -2099,6 +2109,8 @@ static int netc_port_bridge_join(struct dsa_switch
> *ds, int port,
> > struct netc_port *np = NETC_PORT(ds, port);
> > struct netc_switch *priv = ds->priv;
> > u16 vlan_unaware_pvid;
> > + bool uc = np->uc;
> > + bool mc = np->mc;
> > int err;
> >
> > if (!bridge.num) {
> > @@ -2110,6 +2122,12 @@ static int netc_port_bridge_join(struct
> dsa_switch *ds, int port,
> > if (err)
> > return err;
> >
> > + err = netc_port_remove_host_flood(np);
> > + if (err) {
> > + NL_SET_ERR_MSG_MOD(extack, "Failed to delete host flood
> rule");
> > + return err;
> > + }
> > +
> > netc_port_set_mlo(np, MLO_NOT_OVERRIDE);
> >
>
> [ ... ]
>
> > @@ -2123,8 +2141,6 @@ static int netc_port_bridge_join(struct dsa_switch
> *ds, int port,
> > netc_port_set_pvid(np, vlan_unaware_pvid);
> >
> > out:
> > - netc_port_remove_host_flood(np, np->ipft_hf_eid);
> > -
> > if (atomic_inc_return(&priv->br_cnt) == 1)
>
> [ ... ]
>
> > @@ -2134,6 +2150,11 @@ static int netc_port_bridge_join(struct
> dsa_switch *ds, int port,
> > disable_mlo:
> > netc_port_set_mlo(np, MLO_DISABLE);
> >
> > + if (netc_port_add_host_flood_rule(np, uc, mc))
> > + dev_err(ds->dev,
> > + "Failed to restore host flood rule on port %d\n",
> > + port);
> > +
> > return err;
> > }
>
> [Severity: Low]
> Should the commit message also describe this change to
> netc_port_bridge_join()?
>
> Before this patch, the host flood rule was removed only at the out:
> label, after the join had succeeded. If the join failed, for example
> because netc_port_set_vlan_entry() failed, the standalone host flood
> rule and PIPFCR were left alone.
>
> Now the rule is deleted at the start of the join. The disable_mlo path
> then tries to add it back using the uc and mc values saved on entry. If
> that add fails (-ENOMEM, -EBUSY or -EIO), the port stays standalone with
> no host flood rule, np->uc and np->mc are false, and only a dev_err() is
> printed.
>
> DSA does not call .port_set_host_flood() again after a failed join. So
> the port would stay without host flooding until its RX flags change.
>
> The commit message covers the delete-then-add trade-off only for
> port_set_host_flood(). It does not mention the bridge join reordering,
> the new restore path, or this failure mode on the join error path.
>

I think the current commit message already contains the main content,
which is good enough. There is no need to describe every detail.