Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: enetc: correct the command BD ring consumer index

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>

authored by

Wei Fang and committed by
Jakub Kicinski
759a3290 5099807f

+12 -3
+10 -3
drivers/net/ethernet/freescale/enetc/ntmp.c
··· 55 55 spin_lock_init(&cbdr->ring_lock); 56 56 57 57 cbdr->next_to_use = netc_read(cbdr->regs.pir); 58 - cbdr->next_to_clean = netc_read(cbdr->regs.cir); 58 + cbdr->next_to_clean = netc_read(cbdr->regs.cir) & NETC_CBDRCIR_INDEX; 59 59 60 60 /* Step 1: Configure the base address of the Control BD Ring */ 61 61 netc_write(cbdr->regs.bar0, lower_32_bits(cbdr->dma_base_align)); ··· 98 98 int i; 99 99 100 100 i = cbdr->next_to_clean; 101 - while (netc_read(cbdr->regs.cir) != i) { 101 + while ((netc_read(cbdr->regs.cir) & NETC_CBDRCIR_INDEX) != i) { 102 102 cbd = ntmp_get_cbd(cbdr, i); 103 103 memset(cbd, 0, sizeof(*cbd)); 104 104 i = (i + 1) % cbdr->bd_num; ··· 135 135 cbdr->next_to_use = i; 136 136 netc_write(cbdr->regs.pir, i); 137 137 138 - err = read_poll_timeout_atomic(netc_read, val, val == i, 138 + err = read_poll_timeout_atomic(netc_read, val, 139 + (val & NETC_CBDRCIR_INDEX) == i, 139 140 NETC_CBDR_DELAY_US, NETC_CBDR_TIMEOUT, 140 141 true, cbdr->regs.cir); 141 142 if (unlikely(err)) 142 143 goto cbdr_unlock; 144 + 145 + if (unlikely(val & NETC_CBDRCIR_SBE)) { 146 + dev_err(user->dev, "Command BD system bus error\n"); 147 + err = -EIO; 148 + goto cbdr_unlock; 149 + } 143 150 144 151 dma_rmb(); 145 152 /* Get the writeback command BD, because the caller may need
+2
drivers/net/ethernet/freescale/enetc/ntmp_private.h
··· 12 12 13 13 #define NTMP_EID_REQ_LEN 8 14 14 #define NETC_CBDR_BD_NUM 256 15 + #define NETC_CBDRCIR_INDEX GENMASK(9, 0) 16 + #define NETC_CBDRCIR_SBE BIT(31) 15 17 16 18 union netc_cbd { 17 19 struct {