Skip to content

Commit 2aff442

Browse files
Wei FangPaolo Abeni
authored andcommitted
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. Fixes: 4701073 ("net: enetc: add initial netc-lib driver to support NTMP") Signed-off-by: Wei Fang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 9c328f5 commit 2aff442

File tree

1 file changed

+5
-10
lines changed
  • drivers/net/ethernet/freescale/enetc

1 file changed

+5
-10
lines changed

drivers/net/ethernet/freescale/enetc/ntmp.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,19 @@ int ntmp_init_cbdr(struct netc_cbdr *cbdr, struct device *dev,
5252
cbdr->addr_base_align = PTR_ALIGN(cbdr->addr_base,
5353
NTMP_BASE_ADDR_ALIGN);
5454

55-
cbdr->next_to_clean = 0;
56-
cbdr->next_to_use = 0;
5755
spin_lock_init(&cbdr->ring_lock);
5856

57+
cbdr->next_to_use = netc_read(cbdr->regs.pir);
58+
cbdr->next_to_clean = netc_read(cbdr->regs.cir);
59+
5960
/* Step 1: Configure the base address of the Control BD Ring */
6061
netc_write(cbdr->regs.bar0, lower_32_bits(cbdr->dma_base_align));
6162
netc_write(cbdr->regs.bar1, upper_32_bits(cbdr->dma_base_align));
6263

63-
/* Step 2: Configure the producer index register */
64-
netc_write(cbdr->regs.pir, cbdr->next_to_clean);
65-
66-
/* Step 3: Configure the consumer index register */
67-
netc_write(cbdr->regs.cir, cbdr->next_to_use);
68-
69-
/* Step4: Configure the number of BDs of the Control BD Ring */
64+
/* Step 2: Configure the number of BDs of the Control BD Ring */
7065
netc_write(cbdr->regs.lenr, cbdr->bd_num);
7166

72-
/* Step 5: Enable the Control BD Ring */
67+
/* Step 3: Enable the Control BD Ring */
7368
netc_write(cbdr->regs.mr, NETC_CBDR_MR_EN);
7469

7570
return 0;

0 commit comments

Comments
 (0)