On AM62x/AM625 with both CPSW3G ports in dual EMAC mode and VLAN
interfaces on top, reception of untagged frames on a port can stop. The
port VLAN entry at ALE index 0 had been overwritten by an IPv6
multicast entry (33:33:...). Only link down/up recovers the port.
Two independent causes were found:
1. The ALE table is accessed through an index register and three data
registers. The read-modify-write sequences in cpsw_ale.c run
concurrently from different contexts, for example ndo_set_rx_mode()
of one port against VLAN add/kill on the other, without any lock.
Entries get lost or mixed. Patch 2 adds a lock to struct cpsw_ale
and patch 3 extends it to the control register updates. Patch 1 is
a prerequisite of patch 2: netcp calls into the ALE with interrupts
disabled, which does not work with the lock taken by
spin_lock_bh().
2. Even with the lock held, a table read occasionally returns the
content of another index or all zeros. Reading the data words again
without rewriting the index stays wrong, rewriting the index and
reading again returns the right entry. Either of two consecutive
reads can be the bad one. If the VLAN entry reads as free, its
index is handed out as a free slot and overwritten. Patch 4 reads
every entry twice, rewriting the index each time, and retries until
both reads match. It is enabled for the am64-cpswxg ALE, on which
the problem was seen; am65-cpsw-nuss also uses that ALE for the J7
CPSWxG instances.
The AM62x TRM (SPRUIV7) says that after a write to ALE_TBLCTL any ALE
register access is stalled until the table operation completes, so the
access sequence in the driver is as documented. TI lists a matching
unresolved issue for the J7 CPSW in its public tracker as EXT_EP-12856
(workaround: trigger the read twice); AM62x is not listed there.
Measured on a PHYTEC phyCORE-AM62x (CPSW3G, two ports in dual EMAC
mode, VLAN sub-interfaces). Stress: multicast joins and leaves on
both ports plus VLAN add/remove, 120 seconds per run.
- net v7.4-rc3, table lock only: 2 of 19 runs failed
- net v7.4-rc3, table lock and read verification: 60 runs passed,
lockdep enabled, no warnings
- TI/PHYTEC 6.18 vendor kernel, table lock only: 1 of 29 runs failed
- same kernel, read verification only (no lock): failed in the first
run, with torn entries
- same kernel, lock and read verification: 400 runs passed;
mismatching reads were caught and corrected by the retry (seen at
index 0 and index 64)
- a 6.6 based kernel without the patches also fails (run 8); it does
not have the commit named in patch 2, which points to cause 2
- net v7.4-rc3, v3 of this series (all four patches): 60 runs
passed, lockdep enabled, no warnings, the read verification never
gave up
All results except the last one are from v1 and v2 of the patches
(table lock taken with spin_lock_bh() in v1 and spin_lock_irqsave() in
v2, read verification for all ALE variants).
Test coverage: the table lock and the read verification together were
run-tested on net v7.4-rc3 and on the 6.18 vendor kernel, which has the
same cpsw_ale.c table access code. The legacy cpsw, cpsw_new and netcp
users of the ALE, the netcp change in patch 1, the control register
lock in patch 3 and the suspend error path added to patch 4 in v4 are
compile-tested only.
Signed-off-by: Manuel Janocha <manu…@amperfied.com>
---
Changes in v4:
- Patch 1: changelog names the patch that depends on it and why; it
carries the Fixes tag of patch 2 so both are backported together
- Patch 2: lock comment says that only the writers of
p0_untag_vid_mask are serialized and the RX path reads it without
the lock
- Patch 4: cpsw_ale_dump() returns -EIO if an entry could not be
verified; am65_cpsw_nuss_suspend() then fails instead of saving the
entry for cpsw_ale_restore()
- Patch 4: changelog says that am65-cpsw-nuss uses the am64-cpswxg ALE
for the J7 CPSWxG instances too
- Link to v3: https://patch.msgid.link/2026…@amperfied.com
Changes in v3:
- New patch 1: netcp VLAN callbacks use spin_lock_bh() instead of
spin_lock_irqsave()
- Patch 2: take the ALE lock with spin_lock_bh() instead of
spin_lock_irqsave(), so hard interrupts stay enabled during the table
scans; lock comment names what the lock protects
- New patch 3: the locking of cpsw_ale_control_set() is split out of
the table lock patch, with its own Fixes tag
- Patch 4: verify reads only for am64-cpswxg through a feature flag,
Fixes tag changed accordingly
- Patch 4: return -EIO if a read cannot be verified; the callers leave
the entry alone
- Link to v2: https://patch.msgid.link/2026…@amperfied.com
Changes in v2:
- Patch 1: use spin_lock_irqsave() instead of spin_lock_bh(): netcp
calls cpsw_ale_add_vlan()/cpsw_ale_del_vlan() with interrupts
disabled
- Patch 1: also lock the read-modify-write in cpsw_ale_control_set()
- Patch 1: correct the changelog: affected drivers (cpsw/cpsw_new are
already serialized by their rx_mode work item), accessors are the
_relaxed variants; test results updated
- New patch 2: verify ALE table reads (hardware read glitch seen with
the lock in place)
- Link to v1: https://patch.msgid.link/2026…@amperfied.com
---
Manuel Janocha (4):
net: netcp: do not disable interrupts in the VLAN callbacks
net: ethernet: ti: cpsw_ale: serialize ALE table accesses
net: ethernet: ti: cpsw_ale: serialize control register updates
net: ethernet: ti: cpsw_ale: verify ALE table reads
drivers/net/ethernet/ti/am65-cpsw-nuss.c | 5 +-
drivers/net/ethernet/ti/cpsw_ale.c | 199 +++++++++++++++++++++++++------
drivers/net/ethernet/ti/cpsw_ale.h | 8 +-
drivers/net/ethernet/ti/netcp_core.c | 10 +-
4 files changed, 176 insertions(+), 46 deletions(-)
---
base-commit: ef3e21c61baa74e39a49b75318bd4541562ec43f
change-id: 20261126-cpsw-ale-lock-cc05d5bea7a0
Best regards,
--
Manuel Janocha <manu…@amperfied.com>
[PATCH net v4 0/4] net: ethernet: ti: cpsw_ale: fix lost ALE entries
- From
- devn…@kernel.org (Manuel Janocha via B4 Relay)
- Organization
- Usenet Network
- Message-ID
- <2026…@amperfied.com>
- Date
- Newsgroups
- linux.kernel.netdev