]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: enetc: correct the command BD ring consumer index
authorWei Fang <wei.fang@nxp.com>
Wed, 15 Apr 2026 06:08:32 +0000 (14:08 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 17 Apr 2026 02:27:51 +0000 (19:27 -0700)
The command BD ring cousumer index register has the consumer index as
the lower 10 bits, and the bit 31 is SBE, which indicates whether a
system bus error occurred during execution of the CBD command. So if a
system bus error occurs, reading the register will get the SBE bit set.

However, the current implementation directly uses the register value as
the consumer index without masking it. Therefore, if a system bus error
occurs, an incorrect consumer index will be obtained, causing errors in
the processing of the command BD ring. Thus, we need to mask out the
other bits to obtain the correct consumer index.

In addition, this patch adds a check for the SBE bit after the polling
loop and returns an error if the bit is set.

Fixes: 4701073c3deb ("net: enetc: add initial netc-lib driver to support NTMP")
Signed-off-by: Wei Fang <wei.fang@nxp.com>
Link: https://patch.msgid.link/20260415060833.2303846-2-wei.fang@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/freescale/enetc/ntmp.c
drivers/net/ethernet/freescale/enetc/ntmp_private.h

index 703752995e93184074705fb370eed2c2e0813780..0dad38735234038499c26400d5f2f43f9677e026 100644 (file)
@@ -55,7 +55,7 @@ int ntmp_init_cbdr(struct netc_cbdr *cbdr, struct device *dev,
        spin_lock_init(&cbdr->ring_lock);
 
        cbdr->next_to_use = netc_read(cbdr->regs.pir);
-       cbdr->next_to_clean = netc_read(cbdr->regs.cir);
+       cbdr->next_to_clean = netc_read(cbdr->regs.cir) & NETC_CBDRCIR_INDEX;
 
        /* Step 1: Configure the base address of the Control BD Ring */
        netc_write(cbdr->regs.bar0, lower_32_bits(cbdr->dma_base_align));
@@ -98,7 +98,7 @@ static void ntmp_clean_cbdr(struct netc_cbdr *cbdr)
        int i;
 
        i = cbdr->next_to_clean;
-       while (netc_read(cbdr->regs.cir) != i) {
+       while ((netc_read(cbdr->regs.cir) & NETC_CBDRCIR_INDEX) != i) {
                cbd = ntmp_get_cbd(cbdr, i);
                memset(cbd, 0, sizeof(*cbd));
                i = (i + 1) % cbdr->bd_num;
@@ -135,12 +135,19 @@ static int netc_xmit_ntmp_cmd(struct ntmp_user *user, union netc_cbd *cbd)
        cbdr->next_to_use = i;
        netc_write(cbdr->regs.pir, i);
 
-       err = read_poll_timeout_atomic(netc_read, val, val == i,
+       err = read_poll_timeout_atomic(netc_read, val,
+                                      (val & NETC_CBDRCIR_INDEX) == i,
                                       NETC_CBDR_DELAY_US, NETC_CBDR_TIMEOUT,
                                       true, cbdr->regs.cir);
        if (unlikely(err))
                goto cbdr_unlock;
 
+       if (unlikely(val & NETC_CBDRCIR_SBE)) {
+               dev_err(user->dev, "Command BD system bus error\n");
+               err = -EIO;
+               goto cbdr_unlock;
+       }
+
        dma_rmb();
        /* Get the writeback command BD, because the caller may need
         * to check some other fields of the response header.
index 34394e40fddd4d5f20d601d0b79233e4a21411e1..3459cc45b6103ee0f2ed57d59bc131789f668a8a 100644 (file)
@@ -12,6 +12,8 @@
 
 #define NTMP_EID_REQ_LEN       8
 #define NETC_CBDR_BD_NUM       256
+#define NETC_CBDRCIR_INDEX     GENMASK(9, 0)
+#define NETC_CBDRCIR_SBE       BIT(31)
 
 union netc_cbd {
        struct {