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@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/21527
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
Markus Stockhausen 2026-01-13 13:55:38 +01:00 committed by Hauke Mehrtens
parent 92121e6aa5
commit 84a6288a08
3 changed files with 11 additions and 27 deletions

View file

@ -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[] = {

View 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,

View 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);