realtek: dsa: Fix LAG id allocation
authorSven Eckelmann <[email protected]>
Sun, 9 Nov 2025 08:23:48 +0000 (09:23 +0100)
committerHauke Mehrtens <[email protected]>
Tue, 11 Nov 2025 00:06:49 +0000 (01:06 +0100)
The rtl83xx_lag_can_offload() function always returned an error because
ds->num_lag_ids was never set. This basically disabled the DSA lag
configuration completely.

Drop the private n_lag variable and instead use the DSA specific one. This
ensures that all the code always has the same reference for the number of
LAGs.

Fixes: 32e5b5ee6b86 ("realtek: Add Link Aggregation (aka trunking) support")
Signed-off-by: Sven Eckelmann <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/20707
Signed-off-by: Hauke Mehrtens <[email protected]>
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/dsa.c
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h

index 502c130d6febc8c206833f490cb64af91d9d56fb..0a77db6b5d4e5f8210ee2a4ee7f71e295067ecd8 100644 (file)
@@ -457,7 +457,7 @@ int rtl83xx_lag_add(struct dsa_switch *ds, int group, int port, struct netdev_la
                return -EINVAL;
        }
 
-       if (group >= priv->n_lags) {
+       if (group >= priv->ds->num_lag_ids) {
                pr_err("%s: LAG %d invalid.\n", __func__, group);
                return -EINVAL;
        }
@@ -467,11 +467,11 @@ int rtl83xx_lag_add(struct dsa_switch *ds, int group, int port, struct netdev_la
                return -EINVAL;
        }
 
-       for (i = 0; i < priv->n_lags; i++) {
+       for (i = 0; i < priv->ds->num_lag_ids; i++) {
                if (priv->lags_port_members[i] & BIT_ULL(port))
                        break;
        }
-       if (i != priv->n_lags) {
+       if (i != priv->ds->num_lag_ids) {
                pr_err("%s: Port %d already member of LAG %d.\n", __func__, port, i);
                return -ENOSPC;
        }
@@ -513,7 +513,7 @@ int rtl83xx_lag_del(struct dsa_switch *ds, int group, int port)
 {
        struct rtl838x_switch_priv *priv = ds->priv;
 
-       if (group >= priv->n_lags) {
+       if (group >= priv->ds->num_lag_ids) {
                pr_err("%s: LAG %d invalid.\n", __func__, group);
                return -EINVAL;
        }
@@ -702,7 +702,7 @@ static int rtl83xx_handle_changeupper(struct rtl838x_switch_priv *priv,
 
        mutex_lock(&priv->reg_mutex);
 
-       for (i = 0; i < priv->n_lags; i++) {
+       for (i = 0; i < priv->ds->num_lag_ids; i++) {
                if ((!priv->lag_devs[i]) || (priv->lag_devs[i] == upper))
                        break;
        }
@@ -1563,7 +1563,7 @@ static int __init rtl83xx_sw_probe(struct platform_device *pdev)
                priv->ds->num_ports = 29;
                priv->fib_entries = 8192;
                rtl8380_get_version(priv);
-               priv->n_lags = 8;
+               priv->ds->num_lag_ids = 8;
                priv->l2_bucket_size = 4;
                priv->n_pie_blocks = 12;
                priv->port_ignore = 0x1f;
@@ -1579,7 +1579,7 @@ static int __init rtl83xx_sw_probe(struct platform_device *pdev)
                priv->ds->num_ports = 53;
                priv->fib_entries = 16384;
                rtl8390_get_version(priv);
-               priv->n_lags = 16;
+               priv->ds->num_lag_ids = 16;
                priv->l2_bucket_size = 4;
                priv->n_pie_blocks = 18;
                priv->port_ignore = 0x3f;
@@ -1598,7 +1598,7 @@ static int __init rtl83xx_sw_probe(struct platform_device *pdev)
                 * be constructed. For now, just set it to a static 'A'
                 */
                priv->version = RTL8390_VERSION_A;
-               priv->n_lags = 16;
+               priv->ds->num_lag_ids = 16;
                sw_w32(1, RTL930X_ST_CTRL);
                priv->l2_bucket_size = 8;
                priv->n_pie_blocks = 16;
@@ -1618,7 +1618,7 @@ static int __init rtl83xx_sw_probe(struct platform_device *pdev)
                 * be constructed. For now, just set it to a static 'A'
                 */
                priv->version = RTL8390_VERSION_A;
-               priv->n_lags = 16;
+               priv->ds->num_lag_ids = 16;
                sw_w32(1, RTL931x_ST_CTRL);
                priv->l2_bucket_size = 8;
                priv->n_pie_blocks = 16;
index 00f2642624ab932bb170612520d011cec90da131..79387a0c37c60763a042d74ac3dd548b5ea0eda3 100644 (file)
@@ -613,7 +613,7 @@ void rtl838x_dbgfs_init(struct rtl838x_switch_priv *priv)
        debugfs_create_u8("id", 0444, port_dir, &priv->cpu_port);
 
        /* Create entries for LAGs */
-       for (int i = 0; i < priv->n_lags; i++) {
+       for (int i = 0; i < priv->ds->num_lag_ids; i++) {
                snprintf(lag_name, sizeof(lag_name), "lag.%02d", i);
                if (priv->family_id == RTL8380_FAMILY_ID)
                        debugfs_create_x32(lag_name, 0644, rtl838x_dir,
index 2b743dd53a4351c78cb8ff9582b9dd7f85f53da0..1787904b5b80f21d9446843d04941f2b2966274b 100644 (file)
@@ -2407,7 +2407,7 @@ static int rtl83xx_port_lag_join(struct dsa_switch *ds,
 
        mutex_lock(&priv->reg_mutex);
 
-       for (i = 0; i < priv->n_lags; i++) {
+       for (i = 0; i < priv->ds->num_lag_ids; i++) {
                if ((!priv->lag_devs[i]) || (priv->lag_devs[i] == lag.dev))
                        break;
        }
@@ -2446,7 +2446,7 @@ static int rtl83xx_port_lag_leave(struct dsa_switch *ds, int port,
        struct rtl838x_switch_priv *priv = ds->priv;
 
        mutex_lock(&priv->reg_mutex);
-       for (i = 0; i < priv->n_lags; i++) {
+       for (i = 0; i < priv->ds->num_lag_ids; i++) {
                if (priv->lags_port_members[i] & BIT_ULL(port)) {
                        group = i;
                        break;
index 1ab943a6816a5628f80990b851154d30c173c962..f0005b6be027af6b40afbb88c532a358404234d3 100644 (file)
@@ -1164,7 +1164,6 @@ struct rtl838x_switch_priv {
        u32 fib_entries;
        int l2_bucket_size;
        struct dentry *dbgfs_dir;
-       int n_lags;
        u64 lags_port_members[MAX_LAGS];
        struct net_device *lag_devs[MAX_LAGS];
        u32 lag_primary[MAX_LAGS];