|
| 1 | +From: Andrew Sim < [email protected]> |
| 2 | +Date: Fri, 20 Nov 2026 19:00:00 +0100 |
| 3 | +Subject: [PATCH] net: dsa: realtek: rtl8365mb: learn in SVL in a VLAN-unaware |
| 4 | + bridge on family C |
| 5 | + |
| 6 | +Family C always enables Independent VLAN Learning (IVL), so the switch |
| 7 | +keys its L2 table by MAC address, VID and EFID. In a VLAN-unaware bridge, |
| 8 | +DSA programs FDB and MDB entries with VID 0, but the switch learns |
| 9 | +addresses in the port's PVID (VID 1 by default). A static entry from DSA |
| 10 | +therefore never replaces the entry the switch learned for the same |
| 11 | +address, and lookups only hit the learned one. |
| 12 | + |
| 13 | +This breaks roaming. When a Wi-Fi client moves from an AP wired behind a |
| 14 | +user port onto this device's Wi-Fi, DSA adds its address towards the CPU |
| 15 | +port, but the switch keeps forwarding to the old port until the learned |
| 16 | +entry ages out. The client's frames enter from the CPU port, which does |
| 17 | +not learn, so nothing corrects it. On an RTL8367S this meant no DHCP |
| 18 | +lease and no traffic for about 100 seconds after each roam. |
| 19 | + |
| 20 | +Family D already learns in SVL while no user port is VLAN-filtering, see |
| 21 | +"net: dsa: realtek: rtl8365mb: set and get vlan 4k for family D". Do the |
| 22 | +same on family C: drop the family D checks around the IVL_EN choice, the |
| 23 | +vlan_4k_used bookkeeping, the refresh on a VLAN filtering change and its |
| 24 | +undo, and rename the helpers to match. In the family C L2 entry layout, |
| 25 | +program VID 0 entries with the SVL key as family D does, and report |
| 26 | +entries read back in SVL with VID 0. Family C keeps separating bridges |
| 27 | +and standalone ports by EFID, so it does not need the port-based FID |
| 28 | +that family D uses for that. |
| 29 | + |
| 30 | +Co-developed-by: Mieczyslaw Nalewaj < [email protected]> |
| 31 | +Signed-off-by: Mieczyslaw Nalewaj < [email protected]> |
| 32 | +Assisted-by: Claude:claude-opus-5-5 |
| 33 | +Signed-off-by: Andrew Sim < [email protected]> |
| 34 | +--- |
| 35 | + drivers/net/dsa/realtek/rtl8365mb_l2.c | 24 +++++++++--- |
| 36 | + drivers/net/dsa/realtek/rtl8365mb_main.c | 20 +++++----- |
| 37 | + drivers/net/dsa/realtek/rtl8365mb_vlan.c | 48 ++++++++++++------------ |
| 38 | + drivers/net/dsa/realtek/rtl8365mb_vlan.h | 6 +-- |
| 39 | + 4 files changed, 54 insertions(+), 44 deletions(-) |
| 40 | + |
| 41 | +diff --git a/drivers/net/dsa/realtek/rtl8365mb_l2.c b/drivers/net/dsa/realtek/rtl8365mb_l2.c |
| 42 | +index 162082e..120190b 100644 |
| 43 | +--- a/drivers/net/dsa/realtek/rtl8365mb_l2.c |
| 44 | ++++ b/drivers/net/dsa/realtek/rtl8365mb_l2.c |
| 45 | +@@ -157,8 +157,10 @@ void rtl8365mb_c_l2_data_to_uc(const u16 *data, |
| 46 | + |
| 47 | + rtl8365mb_l2_data_to_mac(data, uc->key.mac_addr); |
| 48 | + uc->key.efid = FIELD_GET(RTL8365MB_L2_UC_D4_EFID_MSK, data[4]); |
| 49 | +- uc->key.vid = FIELD_GET(RTL8365MB_L2_UC_D3_VID_MSK, data[3]); |
| 50 | + uc->key.ivl = FIELD_GET(RTL8365MB_L2_UC_D3_IVL_MSK, data[3]); |
| 51 | ++ /* an SVL entry belongs to a VLAN-unaware bridge or a standalone port */ |
| 52 | ++ uc->key.vid = uc->key.ivl ? |
| 53 | ++ FIELD_GET(RTL8365MB_L2_UC_D3_VID_MSK, data[3]) : 0; |
| 54 | + uc->key.fid = FIELD_GET(RTL8365MB_L2_UC_D4_FID_MSK, data[4]); |
| 55 | + uc->age = FIELD_GET(RTL8365MB_L2_UC_D4_AGE_MSK, data[4]); |
| 56 | + uc->auth = FIELD_GET(RTL8365MB_L2_UC_D4_AUTH_MSK, data[4]); |
| 57 | +@@ -179,12 +181,20 @@ void rtl8365mb_c_l2_data_to_uc(const u16 *data, |
| 58 | + void rtl8365mb_c_l2_uc_to_data(const struct rtl8365mb_l2_uc *uc, |
| 59 | + u16 *data) |
| 60 | + { |
| 61 | ++ /* As on family D: VID 0 is a VLAN-unaware bridge or a standalone |
| 62 | ++ * port, whose traffic the switch learns in SVL (IVL=0, FID=0), see |
| 63 | ++ * rtl8365mb_vlan_4k_refresh_ivl(). Use the same key here, otherwise |
| 64 | ++ * a static entry would not replace the learned one. Only a real VID |
| 65 | ++ * selects IVL. |
| 66 | ++ */ |
| 67 | ++ bool ivl = uc->key.ivl && uc->key.vid; |
| 68 | + u32 val; |
| 69 | + |
| 70 | + memset(data, 0, RTL8365MB_C_L2_ENTRY_SIZE * 2); |
| 71 | + rtl8365mb_l2_mac_to_data(uc->key.mac_addr, data); |
| 72 | +- data[3] |= FIELD_PREP(RTL8365MB_L2_UC_D3_VID_MSK, uc->key.vid); |
| 73 | +- data[3] |= FIELD_PREP(RTL8365MB_L2_UC_D3_IVL_MSK, uc->key.ivl); |
| 74 | ++ data[3] |= FIELD_PREP(RTL8365MB_L2_UC_D3_VID_MSK, |
| 75 | ++ ivl ? uc->key.vid : 0); |
| 76 | ++ data[3] |= FIELD_PREP(RTL8365MB_L2_UC_D3_IVL_MSK, ivl); |
| 77 | + |
| 78 | + val = FIELD_GET(RTL8365MB_L2_UC_PORT_HI_MSK, uc->port); |
| 79 | + data[3] |= FIELD_PREP(RTL8365MB_L2_UC_D3_PORT_EXT_MSK, val); |
| 80 | +@@ -232,12 +242,14 @@ void rtl8365mb_c_l2_data_to_mc(const u16 *data, |
| 81 | + void rtl8365mb_c_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, |
| 82 | + u16 *data) |
| 83 | + { |
| 84 | ++ /* Same as for unicast: VID 0 means SVL, and FID 0 then */ |
| 85 | ++ bool ivl = mc->key.ivl && mc->key.vid; |
| 86 | + u32 val; |
| 87 | + |
| 88 | + memset(data, 0, RTL8365MB_C_L2_ENTRY_SIZE * 2); |
| 89 | + rtl8365mb_l2_mac_to_data(mc->key.mac_addr, data); |
| 90 | +- data[3] |= FIELD_PREP(RTL8365MB_L2_MC_D3_VID_MSK, mc->key.vid); |
| 91 | +- data[3] |= FIELD_PREP(RTL8365MB_L2_MC_D3_IVL_MSK, mc->key.ivl); |
| 92 | ++ data[3] |= FIELD_PREP(RTL8365MB_L2_MC_D3_VID_MSK, ivl ? mc->key.vid : 0); |
| 93 | ++ data[3] |= FIELD_PREP(RTL8365MB_L2_MC_D3_IVL_MSK, ivl); |
| 94 | + |
| 95 | + val = FIELD_GET(RTL8365MB_L2_MC_MBR_HI1_MSK, mc->member); |
| 96 | + data[3] |= FIELD_PREP(RTL8365MB_L2_MC_D3_MBR_HI1_MSK, val); |
| 97 | +@@ -280,7 +292,7 @@ void rtl8365mb_d_l2_uc_to_data(const struct rtl8365mb_l2_uc *uc, |
| 98 | + * in SVL (IVL=0, FID=1), isolated from standalone ports in FID 0. |
| 99 | + * Use the same key here so static entries match the learned ones. |
| 100 | + * Only a real VID selects IVL. IVL_EN of the VLANs follows the VLAN |
| 101 | +- * filtering state (see rtl8365mb_d_vlan_4k_refresh_ivl()), so this |
| 102 | ++ * filtering state (see rtl8365mb_vlan_4k_refresh_ivl()), so this |
| 103 | + * matches the key the chip learns with. An entry read back with |
| 104 | + * IVL=0 and FID 0 is written back with FID 1: the driver only |
| 105 | + * creates SVL entries in FID 1, FID 0 is used by standalone ports, |
| 106 | +diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c |
| 107 | +index 954ab74..ddb7526 100644 |
| 108 | +--- a/drivers/net/dsa/realtek/rtl8365mb_main.c |
| 109 | ++++ b/drivers/net/dsa/realtek/rtl8365mb_main.c |
| 110 | +@@ -2452,13 +2452,11 @@ static int rtl8365mb_port_vlan_filtering(struct dsa_switch *ds, int port, |
| 111 | + if (ret) |
| 112 | + goto undo_set_framefilter; |
| 113 | + |
| 114 | +- if (rtl8365mb_is_d(priv)) { |
| 115 | +- mutex_lock(&priv->vlan_lock); |
| 116 | +- ret = rtl8365mb_d_vlan_4k_refresh_ivl(ds, port, vlan_filtering); |
| 117 | +- mutex_unlock(&priv->vlan_lock); |
| 118 | +- if (ret) |
| 119 | +- goto undo_egress_mode; |
| 120 | +- } |
| 121 | ++ mutex_lock(&priv->vlan_lock); |
| 122 | ++ ret = rtl8365mb_vlan_4k_refresh_ivl(ds, port, vlan_filtering); |
| 123 | ++ mutex_unlock(&priv->vlan_lock); |
| 124 | ++ if (ret) |
| 125 | ++ goto undo_egress_mode; |
| 126 | + |
| 127 | + if (rtl8365mb_is_d(priv) && |
| 128 | + dsa_port_bridge_dev_get(dsa_to_port(ds, port))) { |
| 129 | +@@ -2502,18 +2500,18 @@ static int rtl8365mb_port_vlan_filtering(struct dsa_switch *ds, int port, |
| 130 | + (void)regmap_update_bits(priv->map, RTL8365MB_D_PORT_PBFID_REG(port), |
| 131 | + RTL8365MB_D_PORT_PBFID_MASK, 0); |
| 132 | + undo_refresh_ivl: |
| 133 | +- if (rtl8365mb_is_d(priv)) { |
| 134 | ++ { |
| 135 | + /* DSA updates dp->vlan_filtering only after this callback |
| 136 | + * returns, so old_ivl is the state before the change. Restore |
| 137 | + * IVL_EN only if the change flipped it; refresh_ivl() would |
| 138 | + * see no flip here and do nothing. |
| 139 | + */ |
| 140 | +- bool old_ivl = rtl8365mb_d_want_ivl(ds, -1, false); |
| 141 | +- bool new_ivl = rtl8365mb_d_want_ivl(ds, port, vlan_filtering); |
| 142 | ++ bool old_ivl = rtl8365mb_vlan_want_ivl(ds, -1, false); |
| 143 | ++ bool new_ivl = rtl8365mb_vlan_want_ivl(ds, port, vlan_filtering); |
| 144 | + |
| 145 | + if (new_ivl != old_ivl) { |
| 146 | + mutex_lock(&priv->vlan_lock); |
| 147 | +- (void)rtl8365mb_d_vlan_4k_set_ivl(ds, old_ivl); |
| 148 | ++ (void)rtl8365mb_vlan_4k_set_ivl(ds, old_ivl); |
| 149 | + mutex_unlock(&priv->vlan_lock); |
| 150 | + } |
| 151 | + } |
| 152 | +diff --git a/drivers/net/dsa/realtek/rtl8365mb_vlan.c b/drivers/net/dsa/realtek/rtl8365mb_vlan.c |
| 153 | +index aec11ea..9ff6d51 100644 |
| 154 | +--- a/drivers/net/dsa/realtek/rtl8365mb_vlan.c |
| 155 | ++++ b/drivers/net/dsa/realtek/rtl8365mb_vlan.c |
| 156 | +@@ -367,13 +367,19 @@ int rtl8365mb_d_vlan_4k_write(struct realtek_priv *priv, |
| 157 | + data, RTL8365MB_D_CVLAN_ENTRY_SIZE); |
| 158 | + } |
| 159 | + |
| 160 | +-/* Family D has no EFID, so a VLAN-unaware bridge must learn in SVL (IVL=0) |
| 161 | +- * to match static FDB/MDB entries programmed with VID 0. Use IVL only while |
| 162 | +- * at least one user port is VLAN-filtering. @port/@filtering override |
| 163 | ++/* DSA programs the FDB/MDB entries of a VLAN-unaware bridge with VID 0, while |
| 164 | ++ * the switch learns an address in the VLAN that it classifies the frame to. |
| 165 | ++ * With IVL these are two different keys: a static entry does not replace the |
| 166 | ++ * entry learned for the same address, and the switch keeps forwarding to the |
| 167 | ++ * port it learned the address on after the address moved behind the CPU port. |
| 168 | ++ * So learn in SVL (IVL=0) to match static entries programmed with VID 0, and |
| 169 | ++ * use IVL only while at least one user port is VLAN-filtering. This applies to |
| 170 | ++ * both families; family D, which has no EFID, also needs it to separate a |
| 171 | ++ * VLAN-unaware bridge from standalone ports by FID. @port/@filtering override |
| 172 | + * the state of the port currently being changed, as DSA updates |
| 173 | + * dp->vlan_filtering only after the driver callback returns. |
| 174 | + */ |
| 175 | +-bool rtl8365mb_d_want_ivl(struct dsa_switch *ds, int port, bool filtering) |
| 176 | ++bool rtl8365mb_vlan_want_ivl(struct dsa_switch *ds, int port, bool filtering) |
| 177 | + { |
| 178 | + struct dsa_port *dp; |
| 179 | + |
| 180 | +@@ -388,10 +394,10 @@ bool rtl8365mb_d_want_ivl(struct dsa_switch *ds, int port, bool filtering) |
| 181 | + |
| 182 | + /* Set IVL_EN of every 4K entry in use to @want_ivl. Callers must use it only |
| 183 | + * for a change of the switch-wide state (see |
| 184 | +- * rtl8365mb_d_vlan_4k_refresh_ivl()), so that every entry in use holds |
| 185 | ++ * rtl8365mb_vlan_4k_refresh_ivl()), so that every entry in use holds |
| 186 | + * !@want_ivl on entry. Must be called with &priv->vlan_lock held. |
| 187 | + */ |
| 188 | +-int rtl8365mb_d_vlan_4k_set_ivl(struct dsa_switch *ds, bool want_ivl) |
| 189 | ++int rtl8365mb_vlan_4k_set_ivl(struct dsa_switch *ds, bool want_ivl) |
| 190 | + { |
| 191 | + const struct rtl8365mb_family_info *fi; |
| 192 | + struct realtek_priv *priv = ds->priv; |
| 193 | +@@ -439,18 +445,18 @@ int rtl8365mb_d_vlan_4k_set_ivl(struct dsa_switch *ds, bool want_ivl) |
| 194 | + } |
| 195 | + |
| 196 | + /* Must be called with &priv->vlan_lock held. */ |
| 197 | +-int rtl8365mb_d_vlan_4k_refresh_ivl(struct dsa_switch *ds, int port, |
| 198 | ++int rtl8365mb_vlan_4k_refresh_ivl(struct dsa_switch *ds, int port, |
| 199 | + bool filtering) |
| 200 | + { |
| 201 | +- bool want_ivl = rtl8365mb_d_want_ivl(ds, port, filtering); |
| 202 | ++ bool want_ivl = rtl8365mb_vlan_want_ivl(ds, port, filtering); |
| 203 | + |
| 204 | + /* The scan visits every entry in use, so do it only if this |
| 205 | + * change flips the switch-wide state, not for each port of a bridge. |
| 206 | + */ |
| 207 | +- if (want_ivl == rtl8365mb_d_want_ivl(ds, -1, false)) |
| 208 | ++ if (want_ivl == rtl8365mb_vlan_want_ivl(ds, -1, false)) |
| 209 | + return 0; |
| 210 | + |
| 211 | +- return rtl8365mb_d_vlan_4k_set_ivl(ds, want_ivl); |
| 212 | ++ return rtl8365mb_vlan_4k_set_ivl(ds, want_ivl); |
| 213 | + } |
| 214 | + |
| 215 | + static int |
| 216 | +@@ -491,14 +497,10 @@ rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port, |
| 217 | + else |
| 218 | + vlan4k.untag &= ~BIT(port); |
| 219 | + |
| 220 | +- if (!rtl8365mb_is_d(priv)) |
| 221 | +- vlan4k.ivl_en = true; |
| 222 | +- else |
| 223 | +- /* An emptied entry goes back to its reset state, so that |
| 224 | +- * it is not left in IVL after it leaves vlan_4k_used. |
| 225 | +- */ |
| 226 | +- vlan4k.ivl_en = vlan4k.member && |
| 227 | +- rtl8365mb_d_want_ivl(ds, -1, false); |
| 228 | ++ /* An emptied entry goes back to its reset state, so that it is not |
| 229 | ++ * left in IVL after it leaves vlan_4k_used. |
| 230 | ++ */ |
| 231 | ++ vlan4k.ivl_en = vlan4k.member && rtl8365mb_vlan_want_ivl(ds, -1, false); |
| 232 | + |
| 233 | + ret = fi->vlan_4k_write(priv, &vlan4k); |
| 234 | + if (ret) { |
| 235 | +@@ -506,12 +508,10 @@ rtl8365mb_vlan_4k_port_set(struct dsa_switch *ds, int port, |
| 236 | + return ret; |
| 237 | + } |
| 238 | + |
| 239 | +- if (rtl8365mb_is_d(priv)) { |
| 240 | +- if (vlan4k.member) |
| 241 | +- set_bit(vlan->vid, priv->vlan_4k_used); |
| 242 | +- else |
| 243 | +- clear_bit(vlan->vid, priv->vlan_4k_used); |
| 244 | +- } |
| 245 | ++ if (vlan4k.member) |
| 246 | ++ set_bit(vlan->vid, priv->vlan_4k_used); |
| 247 | ++ else |
| 248 | ++ clear_bit(vlan->vid, priv->vlan_4k_used); |
| 249 | + |
| 250 | + return 0; |
| 251 | + } |
| 252 | +diff --git a/drivers/net/dsa/realtek/rtl8365mb_vlan.h b/drivers/net/dsa/realtek/rtl8365mb_vlan.h |
| 253 | +index 270f88b..1db8184 100644 |
| 254 | +--- a/drivers/net/dsa/realtek/rtl8365mb_vlan.h |
| 255 | ++++ b/drivers/net/dsa/realtek/rtl8365mb_vlan.h |
| 256 | +@@ -60,8 +60,8 @@ int rtl8365mb_vlan_pvid_port_set(struct dsa_switch *ds, int port, u16 vid, |
| 257 | + struct netlink_ext_ack *extack); |
| 258 | + int rtl8365mb_vlan_pvid_port_clear(struct dsa_switch *ds, int port, u16 vid); |
| 259 | + |
| 260 | +-bool rtl8365mb_d_want_ivl(struct dsa_switch *ds, int port, bool filtering); |
| 261 | +-int rtl8365mb_d_vlan_4k_set_ivl(struct dsa_switch *ds, bool want_ivl); |
| 262 | +-int rtl8365mb_d_vlan_4k_refresh_ivl(struct dsa_switch *ds, int port, |
| 263 | ++bool rtl8365mb_vlan_want_ivl(struct dsa_switch *ds, int port, bool filtering); |
| 264 | ++int rtl8365mb_vlan_4k_set_ivl(struct dsa_switch *ds, bool want_ivl); |
| 265 | ++int rtl8365mb_vlan_4k_refresh_ivl(struct dsa_switch *ds, int port, |
| 266 | + bool filtering); |
| 267 | + #endif /* _REALTEK_RTL8365MB_VLAN_H */ |
0 commit comments