net: enetc: initialize SW PIR and CIR based HW PIR and CIR values
Wei Fang
maintainerPATCH 1/1 net: enetc: initialize SW PIR and CIR based HW PIR and CIR values
Software can only initialize the PIR and CIR of the command BD ring after a FLR, and these two registers can only be set to 0. But the reset values of these two registers are 0, so software does not need to update them. If there is no a FLR and PIR and CIR are not 0, resetting them to 0 or other values by software will cause the command BD ring to work abnormally. This is because of an internal context in the ring prefetch logic that will retain the state from the first incarnation of the ring and continue prefetching from the stale location when the ring is reinitialized. The internal context can only be reset by the FLR.
In addition, there is a logic error in the implementation, next_to_clean indicates the software CIR and next_to_use indicates the software PIR. But the current driver uses next_to_clean to set PIR and use next_to_use to set CIR. This does not cause a problem in actual use, because the current command BD ring is only initialized after FLR, and the initial values of next_to_use and next_to_clean are both 0.
Therefore, this patch removes the initialization of PIR and CIR. Instead, next_to_use and next_to_clean are initialized by reading the values of PIR and CIR.
--- drivers/net/ethernet/freescale/enetc/ntmp.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/net/ethernet/freescale/enetc/ntmp.c +5 -10
@@ -52,24 +52,19 @@ int ntmp_init_cbdr(struct netc_cbdr *cbdr, struct device *dev, cbdr->addr_base_align =PTR_ALIGN (cbdr->addr_base,NTMP_BASE_ADDR_ALIGN ); - cbdr->next_to_clean =0 ; - cbdr->next_to_use =0 ;spin_lock_init (&cbdr->ring_lock); + cbdr->next_to_use =netc_read (cbdr->regs.pir); + cbdr->next_to_clean =netc_read (cbdr->regs.cir); +/* Step 1: Configure the base address of the Control BD Ring */ netc_write (cbdr->regs.bar0,lower_32_bits (cbdr->dma_base_align));netc_write (cbdr->regs.bar1,upper_32_bits (cbdr->dma_base_align)); -/* Step 2: Configure the producer index register */ -netc_write (cbdr->regs.pir, cbdr->next_to_clean); - -/* Step 3: Configure the consumer index register */ -netc_write (cbdr->regs.cir, cbdr->next_to_use); - -/* Step4: Configure the number of BDs of the Control BD Ring */ +/* Step 2: Configure the number of BDs of the Control BD Ring */ netc_write (cbdr->regs.lenr, cbdr->bd_num); -/* Step 5: Enable the Control BD Ring */ +/* Step 3: Enable the Control BD Ring */ netc_write (cbdr->regs.mr,NETC_CBDR_MR_EN );return 0 ;
Signature · 1 line
2.34.1
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Fri, 26 Sep 2025 09:39:53 +0800 you wrote:
Software can only initialize the PIR and CIR of the command BD ring after a FLR, and these two registers can only be set to 0. But the reset values of these two registers are 0, so software does not need to update them. If there is no a FLR and PIR and CIR are not 0, resetting them to 0 or other values by software will cause the command BD ring to work abnormally. This is because of an internal context in the ring prefetch logic that will retain the state from the first incarnation of the ring and continue prefetching from the stale location when the ring is reinitialized. The internal context can only be reset by the FLR.
[...]
Here is the summary with links:
- [net] net: enetc: initialize SW PIR and CIR based HW PIR and CIR values
https://git.kernel.org/netdev/net/c/2aff4420efc2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html