]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: enetc: initialize SW PIR and CIR based HW PIR and CIR values
authorWei Fang <wei.fang@nxp.com>
Fri, 26 Sep 2025 01:39:53 +0000 (09:39 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 30 Sep 2025 08:47:41 +0000 (10:47 +0200)
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.

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/20250926013954.2003456-1-wei.fang@nxp.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/freescale/enetc/ntmp.c

index ba32c1bbd9e18425a767e6432eb140cc28402200..0c1d343253bfb7f05f7d019dc380feb23fad89c2 100644 (file)
@@ -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;