From fdc424c1e32b50e05ba38cbc00e62b19d869e510 Mon Sep 17 00:00:00 2001 From: Sharadanand Karanjkar Date: Thu, 14 Aug 2025 15:48:14 +0000 Subject: [PATCH] realtek: dsa: add table-based statistics infrastructure Some Realtek SoCs such as the RTL931X store MIB counters in tables rather than registers. Unlike register reads, table access requires programming the table control register, setting the command field to determine read or write, and then polling for completion. This makes it necessary to implement a separate path for table-based statistics. Like register-based MIBs, the table-based MIBs also come in two types: STD and PRIV which will require slightly different implementations. Signed-off-by: Sharadanand Karanjkar Signed-off-by: Sven Eckelmann Link: https://github.com/openwrt/openwrt/pull/20631 Signed-off-by: Hauke Mehrtens --- .../realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c | 9 +++++++++ .../realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h | 1 + .../realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl83xx.h | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c index 6468f9a483..6d2dcbe609 100644 --- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c +++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c @@ -880,6 +880,15 @@ static bool rtldsa_read_mib_item(struct rtl838x_switch_priv *priv, int port, reg = priv->r->stat_port_prv_mib; reg_offset = 128; break; + case MIB_TBL_STD: + case MIB_TBL_PRV: + if (!priv->r->stat_port_table_read) + return false; + + *data = priv->r->stat_port_table_read(port, mib_item->size, mib_item->offset, + mib_item->reg == MIB_TBL_PRV); + + return true; default: return false; } diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h index 4120f5ff48..e3f894ad6d 100644 --- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h +++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h @@ -1121,6 +1121,7 @@ struct rtl838x_reg { int stat_rst; int stat_port_std_mib; int stat_port_prv_mib; + u64 (*stat_port_table_read)(int port, unsigned int mib_size, unsigned int offset, bool is_pvt); int (*port_iso_ctrl)(int p); void (*traffic_enable)(int source, int dest); void (*traffic_disable)(int source, int dest); diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl83xx.h b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl83xx.h index 5b98c85848..1b04c65708 100644 --- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl83xx.h +++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl83xx.h @@ -20,7 +20,9 @@ struct fdb_update_work { enum mib_reg { MIB_REG_INVALID = 0, MIB_REG_STD, - MIB_REG_PRV + MIB_REG_PRV, + MIB_TBL_STD, + MIB_TBL_PRV, }; #define MIB_ITEM(_reg, _offset, _size) \ -- 2.30.2