[openwrt/openwrt] realtek: rtl931x: set hash_msb based on VLAN ID when adding a new L2 entry

LEDE Commits lede-commits at lists.infradead.org
Mon Sep 29 11:55:26 PDT 2025


robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/36d8d19993c220198a81c0545b246eea496f4d1c

commit 36d8d19993c220198a81c0545b246eea496f4d1c
Author: Issam Hamdi <ih at simonwunderlich.de>
AuthorDate: Wed Sep 3 14:19:38 2025 +0200

    realtek: rtl931x: set hash_msb based on VLAN ID when adding a new L2 entry
    
    During testing, we discovered that when adding a new offload FDB rule
    on certain VLANs and then delete it, does not work as expected.
    
    Steps to Reproduce:
    
    * Create VLAN 4094 on the port lan1:
    
          bridge vlan add vid 4094 dev lan1 pvid
    
    * Add a new FDB entry on port lan1 for VLAN 4094:
    
          bridge fdb add 00:01:02:22:33:44 dev lan1 vlan 4094 master permanent
    
    * Delete the new FDB entry on port lan1 for VLAN4094
    
          bridge fdb del 00:01:02:22:33:44 dev lan1 vlan 4094 master permanent
    
    Root Cause:
    
    The failure occurs because the hash_msb flag is not set correctly
    based on the VLAN ID when adding a new L2 entry.
    
    Signed-off-by: Issam Hamdi <ih at simonwunderlich.de>
    Signed-off-by: Sven Eckelmann <se at simonwunderlich.de>
    Link: https://github.com/openwrt/openwrt/pull/20183
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 .../realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h     |  1 +
 .../realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c     | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h
index 1126d082eb..469246f0f8 100644
--- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h
+++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl838x.h
@@ -737,6 +737,7 @@ struct rtl838x_l2_entry {
 	bool is_local_forward:1;
 	bool is_remote_forward:1;
 	bool is_l2_tunnel:1;
+	bool hash_msb:1;
 	int l2_tunnel_id;
 	int l2_tunnel_list_id;
 };
diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c
index 27dd999840..28602151c0 100644
--- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c
+++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c
@@ -558,6 +558,7 @@ static void rtl931x_fill_l2_row(u32 r[], struct rtl838x_l2_entry *e)
 
 	r[0] |= e->is_open_flow ? BIT(30) : 0;
 	r[0] |= e->is_pe_forward ? BIT(29) : 0;
+	r[0] |= e->hash_msb ? BIT(28): 0;
 	r[2] = e->next_hop ? BIT(30) : 0;
 	r[0] |= (e->rvid & 0xfff) << 16;
 
@@ -675,11 +676,22 @@ static void rtl931x_write_l2_entry_using_hash(u32 hash, u32 pos, struct rtl838x_
 	u32 r[4];
 	struct table_reg *q = rtl_table_get(RTL9310_TBL_0, 0);
 	u32 idx = (0 << 14) | (hash << 2) | pos; /* Access SRAM, with hash and at pos in bucket */
+	int hash_algo_id;
 
 	pr_debug("%s: hash %d, pos %d\n", __func__, hash, pos);
 	pr_debug("%s: index %d -> mac %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, idx,
 		e->mac[0], e->mac[1], e->mac[2], e->mac[3],e->mac[4],e->mac[5]);
 
+	if (idx < 0x4000)
+		hash_algo_id = sw_r32(RTL931X_L2_CTRL) & BIT(0);
+	else
+		hash_algo_id = (sw_r32(RTL931X_L2_CTRL) & BIT(1)) >> 1;
+
+	if (hash_algo_id == 0)
+		e->hash_msb = (e->rvid >> 2) & 0x1;
+	else
+		e->hash_msb = (e->rvid >> 11) & 0x1;
+
 	rtl931x_fill_l2_row(r, e);
 	pr_debug("%s: %d: %08x %08x %08x\n", __func__, idx, r[0], r[1], r[2]);
 




More information about the lede-commits mailing list