realtek: dsa: remove RTL931x family check from VLAN init

Initialize struct rtl838x_vlan_info with a designated initializer instead
of conditionally initializing the RTL931x-only fields based on
family_id.

The RTL931x VLAN table contains the additional if_id,
multicast_grp_mask and l2_tunnel_list_id fields. Of these,
if_id and multicast_grp_mask require the value zero during the
initial VLAN table setup, while l2_tunnel_list_id uses -1 to denote
that no L2 tunnel list is configured.

A designated initializer already zero-initializes every member which
is not explicitly specified. It is therefore sufficient to initialize
only l2_tunnel_list_id to -1:

struct rtl838x_vlan_info info = {
    .l2_tunnel_list_id = -1,
};

This preserves the previous RTL931x values exactly:

if_id                  = 0
multicast_grp_mask     = 0
l2_tunnel_list_id      = -1

It also preserves the values previously assigned explicitly for all
families:

fid                    = 0
hash_uc_fid            = false
hash_mc_fid            = false
profile_id             = 0
member_ports           = 0

The RTL838x, RTL839x and RTL930x VLAN table writers do not consume the
RTL931x-specific members, so initializing those members unconditionally
has no effect on those SoCs. Their relevant members retain exactly the
same zero values as before.

For RTL931x, rtl931x_vlan_set_tagged() does consume the additional
members, but receives exactly the same values that were previously set
inside the RTL9310_FAMILY_ID conditional.

As a side effect, the whole structure is now initialized before first
use, including members such as untagged_ports which are not relevant
to this particular write path.

This removes one unnecessary family_id dependency from the common
DSA code without changing the generated VLAN table contents.

Assisted-by: ChatGPT (OpenAI GPT-5.6 Sol)
Link: https://github.com/openwrt/openwrt/pull/24918
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
This commit is contained in:
Markus Stockhausen committed 2026-08-29 09:04:29 +02:00
1 parent c84be1db42
commit fad3ebd4f1
1 file changed
+3 -12
@@ -80,24 +80,15 @@ static void rtldsa_83xx_mc_pmasks_setup(struct rtl838x_switch_priv *priv)
/* Initialize all VLANS */
static void rtldsa_vlan_setup(struct rtl838x_switch_priv *priv)
{
struct rtl838x_vlan_info info;
struct rtl838x_vlan_info info = {
.l2_tunnel_list_id = -1,
};
pr_info("In %s\n", __func__);
priv->r->vlan_profile_setup(0);
priv->r->vlan_profile_dump(priv, 0);
info.fid = 0; /* Default Forwarding ID / MSTI */
info.hash_uc_fid = false; /* Do not build the L2 lookup hash with FID, but VID */
info.hash_mc_fid = false; /* Do the same for Multicast packets */
info.profile_id = 0; /* Use default Vlan Profile 0 */
info.member_ports = 0; /* Initially no port members */
if (priv->family_id == RTL9310_FAMILY_ID) {
info.if_id = 0;
info.multicast_grp_mask = 0;
info.l2_tunnel_list_id = -1;
}
/* Initialize normal VLANs 1-4095 */
for (int i = 1; i < MAX_VLANS; i++)
priv->r->vlan_set_tagged(i, &info);