[PATCH net-next v2 0/2] net: dsa: qca8k: report port statistics from the MIB
From: Stanislaw Pal
Date: Mon Oct 19 2026 - 15:11:56 EST
qca8k has no .get_stats64, so a user port's netdev counts only what
crosses the CPU port; traffic the switch forwards in hardware never
shows up. Patch 2 reports the port counters from the switch MIB through
a delayed work, as ar9331 and rtl8365mb do. Patch 1 makes register
access safe for such a reader outside rtnl first.
Changes in v2:
- patch 1 is new: the regmap was created without locking while it
formats register and value in its shared work_buf, and an autocast
and qca8k_conduit_change() took the MIB and management mutexes in
opposite orders (netdev AI review)
- read the MIB with one autocast request for all ports when the
management path is up, register reads only as the fallback, only for
ports with link (Christian)
- index ar8327_mib[] by an enum instead of a second table of offsets,
share the register reads with qca8k_get_ethtool_stats() (Christian)
- MIB instead of STATS in the names, interval define in qca8k.h, one
spinlock for the cached counters (Christian)
- stop the work on shutdown and suspend, init it in probe; keep the
user port's tstats if the MIB did not come up; read the high word of
a 64-bit counter around the low one and drop a 64-bit sample that
goes backwards; take the FCS off the byte counters (netdev AI review)
On the FCS: on the CPU port of the B3000, with an 802.1Q tag on the
link, the maximum-size frames (1518 bytes without the FCS) land in
RxMaxByte, so the size buckets count the FCS; the CPU port's
RxGoodByte also matches the conduit GMAC's MMC octet counter byte for
byte. Please correct me if the byte counters are documented otherwise.
Tested on a GL-B3000 (QCA8337, CPU port 0), three 15 s uploads over the
WAN port per case: with register reads the wan netdev's TX bytes were
TxByte less 4 bytes per frame within 0.004%; with the qca tagger, where
every read is an autocast, the counters followed TxByte within 0.002%
(measured before the FCS change). With lockdep, a tagger change and
three conduit down/up cycles with the autocast work running and
ethtool -S in a loop gave no report.
v1: https://lore.kernel.org/netdev/20261018153658.209999-1-kuncy7@xxxxxxxxx/
Stanislaw Pal (2):
net: dsa: qca8k: serialize register access
net: dsa: qca8k: report port statistics from the MIB
drivers/net/dsa/qca/qca8k-8xxx.c | 194 ++++++++++++++++++++++++++---
drivers/net/dsa/qca/qca8k-common.c | 137 ++++++++++++--------
drivers/net/dsa/qca/qca8k.h | 72 ++++++++++-
3 files changed, 332 insertions(+), 71 deletions(-)
base-commit: d1241cdbbcf7bfac3e53482b2054504628f9f047
--
2.43.0