hostapd: update to latest Git hostap_2_9-1331-g5a8b366233f5
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 754-v5.7-net-dsa-mt7530-fix-roaming-from-DSA-user-ports.patch
1 From 5e5502e012b8129e11be616acb0f9c34bc8f8adb Mon Sep 17 00:00:00 2001
2 From: DENG Qingfang <dqfext@gmail.com>
3 Date: Wed, 13 May 2020 23:10:16 +0800
4 Subject: net: dsa: mt7530: fix roaming from DSA user ports
5
6 When a client moves from a DSA user port to a software port in a bridge,
7 it cannot reach any other clients that connected to the DSA user ports.
8 That is because SA learning on the CPU port is disabled, so the switch
9 ignores the client's frames from the CPU port and still thinks it is at
10 the user port.
11
12 Fix it by enabling SA learning on the CPU port.
13
14 To prevent the switch from learning from flooding frames from the CPU
15 port, set skb->offload_fwd_mark to 1 for unicast and broadcast frames,
16 and let the switch flood them instead of trapping to the CPU port.
17 Multicast frames still need to be trapped to the CPU port for snooping,
18 so set the SA_DIS bit of the MTK tag to 1 when transmitting those frames
19 to disable SA learning.
20
21 Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
22 Signed-off-by: DENG Qingfang <dqfext@gmail.com>
23 Signed-off-by: David S. Miller <davem@davemloft.net>
24 ---
25 drivers/net/dsa/mt7530.c | 9 ++-------
26 drivers/net/dsa/mt7530.h | 1 +
27 net/dsa/tag_mtk.c | 15 +++++++++++++++
28 3 files changed, 18 insertions(+), 7 deletions(-)
29
30 --- a/drivers/net/dsa/mt7530.c
31 +++ b/drivers/net/dsa/mt7530.c
32 @@ -639,11 +639,8 @@ mt7530_cpu_port_enable(struct mt7530_pri
33 mt7530_write(priv, MT7530_PVC_P(port),
34 PORT_SPEC_TAG);
35
36 - /* Disable auto learning on the cpu port */
37 - mt7530_set(priv, MT7530_PSC_P(port), SA_DIS);
38 -
39 - /* Unknown unicast frame fordwarding to the cpu port */
40 - mt7530_set(priv, MT7530_MFC, UNU_FFP(BIT(port)));
41 + /* Unknown multicast frame forwarding to the cpu port */
42 + mt7530_rmw(priv, MT7530_MFC, UNM_FFP_MASK, UNM_FFP(BIT(port)));
43
44 /* Set CPU port number */
45 if (priv->id == ID_MT7621)
46 @@ -1298,8 +1295,6 @@ mt7530_setup(struct dsa_switch *ds)
47 /* Enable and reset MIB counters */
48 mt7530_mib_reset(ds);
49
50 - mt7530_clear(priv, MT7530_MFC, UNU_FFP_MASK);
51 -
52 for (i = 0; i < MT7530_NUM_PORTS; i++) {
53 /* Disable forwarding by default on all ports */
54 mt7530_rmw(priv, MT7530_PCR_P(i), PCR_MATRIX_MASK,
55 --- a/drivers/net/dsa/mt7530.h
56 +++ b/drivers/net/dsa/mt7530.h
57 @@ -31,6 +31,7 @@ enum {
58 #define MT7530_MFC 0x10
59 #define BC_FFP(x) (((x) & 0xff) << 24)
60 #define UNM_FFP(x) (((x) & 0xff) << 16)
61 +#define UNM_FFP_MASK UNM_FFP(~0)
62 #define UNU_FFP(x) (((x) & 0xff) << 8)
63 #define UNU_FFP_MASK UNU_FFP(~0)
64 #define CPU_EN BIT(7)
65 --- a/net/dsa/tag_mtk.c
66 +++ b/net/dsa/tag_mtk.c
67 @@ -15,6 +15,7 @@
68 #define MTK_HDR_XMIT_TAGGED_TPID_8100 1
69 #define MTK_HDR_RECV_SOURCE_PORT_MASK GENMASK(2, 0)
70 #define MTK_HDR_XMIT_DP_BIT_MASK GENMASK(5, 0)
71 +#define MTK_HDR_XMIT_SA_DIS BIT(6)
72
73 static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
74 struct net_device *dev)
75 @@ -22,6 +23,9 @@ static struct sk_buff *mtk_tag_xmit(stru
76 struct dsa_port *dp = dsa_slave_to_port(dev);
77 u8 *mtk_tag;
78 bool is_vlan_skb = true;
79 + unsigned char *dest = eth_hdr(skb)->h_dest;
80 + bool is_multicast_skb = is_multicast_ether_addr(dest) &&
81 + !is_broadcast_ether_addr(dest);
82
83 /* Build the special tag after the MAC Source Address. If VLAN header
84 * is present, it's required that VLAN header and special tag is
85 @@ -47,6 +51,10 @@ static struct sk_buff *mtk_tag_xmit(stru
86 MTK_HDR_XMIT_UNTAGGED;
87 mtk_tag[1] = (1 << dp->index) & MTK_HDR_XMIT_DP_BIT_MASK;
88
89 + /* Disable SA learning for multicast frames */
90 + if (unlikely(is_multicast_skb))
91 + mtk_tag[1] |= MTK_HDR_XMIT_SA_DIS;
92 +
93 /* Tag control information is kept for 802.1Q */
94 if (!is_vlan_skb) {
95 mtk_tag[2] = 0;
96 @@ -61,6 +69,9 @@ static struct sk_buff *mtk_tag_rcv(struc
97 {
98 int port;
99 __be16 *phdr, hdr;
100 + unsigned char *dest = eth_hdr(skb)->h_dest;
101 + bool is_multicast_skb = is_multicast_ether_addr(dest) &&
102 + !is_broadcast_ether_addr(dest);
103
104 if (unlikely(!pskb_may_pull(skb, MTK_HDR_LEN)))
105 return NULL;
106 @@ -86,6 +97,10 @@ static struct sk_buff *mtk_tag_rcv(struc
107 if (!skb->dev)
108 return NULL;
109
110 + /* Only unicast or broadcast frames are offloaded */
111 + if (likely(!is_multicast_skb))
112 + skb->offload_fwd_mark = 1;
113 +
114 return skb;
115 }
116