]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: dsa: Remove family check from port_get_stp_state() 21527/head
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Tue, 13 Jan 2026 12:55:38 +0000 (13:55 +0100)
committerHauke Mehrtens <hauke@hauke-m.de>
Wed, 21 Jan 2026 21:54:46 +0000 (22:54 +0100)
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@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/21527
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/common.c
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl83xx.h

index 66e7c784ffa80e2fe3aa98a3ea25d77c8b07f0d7..53e79bde82264795bef948d2ffc823e9d817be3c 100644 (file)
 
 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[] = {
index 5acdf05d8074957dae45d6cece34b9bd6420e8c8..908f6538dd60109c9cff406f94220f26f9968b5d 100644 (file)
@@ -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,
index f8516bbf58a0474d9466f7c49d48397e9e3ddeb7..66766da3315746cbffc9ef5e3b3c401511ad193e 100644 (file)
@@ -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);