From: Manuel Janocha <manu…@amperfied.com>
On AM62x (CPSW3G) a read of an ALE table entry occasionally returns the
contents of a different table index, or all zeros, although the access
sequence is the documented one and is serialized by the ALE lock.
Reading the data words again does not help, the wrong value is latched;
writing the index to ALE_TBLCTL again and then reading returns the
right entry.
The TRM states that after a write to ALE_TBLCTL any access to an ALE
register is stalled until the table operation completes, so software is
not expected to wait or poll. TI tracks the same symptom for the J7
CPSW as EXT_EP-12856, unresolved, with the workaround to trigger the
read twice.
A wrong read is not harmless: when the entry at the index of the
untagged VLAN reads as free, cpsw_ale_match_free() hands that index out
and the next multicast address overwrites the VLAN entry. Untagged
receive on the port is then dead until the link goes down and up again.
In testing, either the first or the second of two consecutive reads was
the wrong one, so taking the second read is not sufficient. Read every
entry twice, each time after writing the index, and retry until both
reads match. After four unsuccessful tries warn (ratelimited) and
return the last read. Every table read now costs two index writes and
six data reads instead of one and three, and the loops over the table
hold the ALE lock correspondingly longer.
Testing: AM625 board (PHYTEC phyCORE-AM62x, two CPSW ports in dual EMAC
mode with VLAN interfaces), reproducer as in the previous patch
(multicast joins and leaves on both ports plus VLAN add and delete,
120 seconds per run). On the TI vendor kernel 6.18, which has the same
table access code, the previous patch alone failed in 1 of 29 runs and
this patch alone, without the lock, failed in the first run with torn
entries. With both patches 400 runs passed, and the retry corrected
mismatching reads at index 0 and index 64. On net v7.4-rc3 with both
patches 60 runs passed.
Tooling: this patch and its changelog were prepared with an AI coding
assistant (Claude).
Fixes: db82173f23c5 ("netdev: driver: ethernet: add cpsw address lookup engine support")
Signed-off-by: Manuel Janocha <manu…@amperfied.com>
---
drivers/net/ethernet/ti/cpsw_ale.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
index 8434803335d5..bef324bc171e 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.c
+++ b/drivers/net/ethernet/ti/cpsw_ale.c
@@ -339,17 +339,42 @@ static inline void cpsw_ale_set_addr(u32 *ale_entry, const u8 *addr)
cpsw_ale_set_field(ale_entry, 40 - 8*i, 8, addr[i]);
}
-static int cpsw_ale_read(struct cpsw_ale *ale, int idx, u32 *ale_entry)
+/*
+ * A table read occasionally returns the entry of another index or all
+ * zeros. Reading the data words again does not help, but writing the
+ * index again and reading returns the right entry. Either of two
+ * consecutive reads can be the wrong one, so read twice and compare.
+ */
+#define ALE_TABLE_READ_RETRIES 4
+
+static void cpsw_ale_read_entry(struct cpsw_ale *ale, int idx, u32 *ale_entry)
{
int i;
- WARN_ON(idx > ale->params.ale_entries);
-
writel_relaxed(idx, ale->params.ale_regs + ALE_TABLE_CONTROL);
for (i = 0; i < ALE_ENTRY_WORDS; i++)
ale_entry[i] = readl_relaxed(ale->params.ale_regs +
ALE_TABLE + 4 * i);
+}
+
+static int cpsw_ale_read(struct cpsw_ale *ale, int idx, u32 *ale_entry)
+{
+ u32 prev[ALE_ENTRY_WORDS];
+ int tries;
+
+ WARN_ON(idx > ale->params.ale_entries);
+
+ for (tries = 0; tries < ALE_TABLE_READ_RETRIES; tries++) {
+ cpsw_ale_read_entry(ale, idx, prev);
+ cpsw_ale_read_entry(ale, idx, ale_entry);
+ if (!memcmp(prev, ale_entry, sizeof(prev)))
+ return idx;
+ }
+
+ dev_warn_ratelimited(ale->params.dev,
+ "ALE table read of entry %d did not stabilize\n",
+ idx);
return idx;
}
--
2.34.1