[openwrt/openwrt] realtek: dsa: Remove family check from port_get_stp_state()

LEDE Commits lede-commits at lists.infradead.org
Wed Jan 21 13:57:23 PST 2026


hauke pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/84a6288a0849fa0ef56a12e7bf028f07c0c6884f

commit 84a6288a0849fa0ef56a12e7bf028f07c0c6884f
Author: Markus Stockhausen <markus.stockhausen at gmx.de>
AuthorDate: Tue Jan 13 13:55:38 2026 +0100

    realtek: dsa: Remove family check from port_get_stp_state()
    
    The device specific stp_get() functions can return the state
    of a given port individually. No need to disassemble the
    device specific state table. Additionally change function
    prefix.
    
    Signed-off-by: Markus Stockhausen <markus.stockhausen at gmx.de>
    Link: https://github.com/openwrt/openwrt/pull/21527
    Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>
---
 .../files-6.12/drivers/net/dsa/rtl83xx/common.c    | 28 +++++-----------------
 .../files-6.12/drivers/net/dsa/rtl83xx/debugfs.c   |  8 +++----
 .../files-6.12/drivers/net/dsa/rtl83xx/rtl83xx.h   |  2 +-
 3 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/common.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/common.c
index 66e7c784ff..53e79bde82 100644
--- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/common.c
+++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/common.c
@@ -18,36 +18,20 @@
 
 struct phylink_pcs *rtpcs_create(struct device *dev, struct device_node *np, int port);
 
-int rtl83xx_port_get_stp_state(struct rtl838x_switch_priv *priv, int port)
+int rtldsa_port_get_stp_state(struct rtl838x_switch_priv *priv, int port)
 {
+	u32 table[4];
 	u32 msti = 0;
-	u32 port_state[4];
-	int index, bit;
-	int pos = port;
-	int n = priv->port_width << 1;
+	int state;
 
-	/* Ports above or equal CPU port can never be configured */
 	if (port >= priv->cpu_port)
-		return -1;
+		return -EINVAL;
 
 	mutex_lock(&priv->reg_mutex);
-
-	/* For the RTL839x and following, the bits are left-aligned in the 64/128 bit field */
-	if (priv->family_id == RTL8390_FAMILY_ID)
-		pos += 12;
-	if (priv->family_id == RTL9300_FAMILY_ID)
-		pos += 3;
-	if (priv->family_id == RTL9310_FAMILY_ID)
-		pos += 8;
-
-	index = n - (pos >> 4) - 1;
-	bit = (pos << 1) % 32;
-
-	priv->r->stp_get(priv, msti, port, port_state);
-
+	state = priv->r->stp_get(priv, msti, port, table);
 	mutex_unlock(&priv->reg_mutex);
 
-	return (port_state[index] >> bit) & 3;
+	return state;
 }
 
 static struct table_reg rtl838x_tbl_regs[] = {
diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c
index 5acdf05d80..908f6538dd 100644
--- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c
+++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c
@@ -162,12 +162,12 @@ static ssize_t stp_state_read(struct file *filp, char __user *buffer, size_t cou
 {
 	struct rtl838x_port *p = filp->private_data;
 	struct dsa_switch *ds = p->dp->ds;
-	int value = rtl83xx_port_get_stp_state(ds->priv, p->dp->index);
+	int state = rtldsa_port_get_stp_state(ds->priv, p->dp->index);
 
-	if (value < 0)
-		return -EINVAL;
+	if (state < 0)
+		return state;
 
-	return rtl838x_common_read(buffer, count, ppos, (u32)value);
+	return rtl838x_common_read(buffer, count, ppos, (u32)state);
 }
 
 static ssize_t stp_state_write(struct file *filp, const char __user *buffer,
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 f8516bbf58..66766da331 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
@@ -135,7 +135,7 @@ void __init rtl83xx_setup_qos(struct rtl838x_switch_priv *priv);
 
 void rtl83xx_fast_age(struct dsa_switch *ds, int port);
 int rtl83xx_packet_cntr_alloc(struct rtl838x_switch_priv *priv);
-int rtl83xx_port_get_stp_state(struct rtl838x_switch_priv *priv, int port);
+int rtldsa_port_get_stp_state(struct rtl838x_switch_priv *priv, int port);
 int rtl83xx_port_is_under(const struct net_device *dev, struct rtl838x_switch_priv *priv);
 void rtl83xx_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
 int rtl83xx_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data);




More information about the lede-commits mailing list