kernel: backport eth_addr_add()
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 770-v5.15-net-dsa-mt7530-support-MDB-operations.patch
1 From 1f11a07a33bc26997c18b633d63f088bf75d11f2 Mon Sep 17 00:00:00 2001
2 From: DENG Qingfang <dqfext@gmail.com>
3 Date: Tue, 24 Aug 2021 11:37:50 +0800
4 Subject: [PATCH] net: dsa: mt7530: support MDB operations
5
6 This is a partial backport of commit 5a30833b9a16f8d1aa15de06636f9317ca51f9df
7 ("net: dsa: mt7530: support MDB and bridge flag operations") upstream.
8
9 Signed-off-by: DENG Qingfang <dqfext@gmail.com>
10 ---
11 drivers/net/dsa/mt7530.c | 78 ++++++++++++++++++++++++++++++++++++++--
12 net/dsa/tag_mtk.c | 14 +-------
13 2 files changed, 76 insertions(+), 16 deletions(-)
14
15 --- a/drivers/net/dsa/mt7530.c
16 +++ b/drivers/net/dsa/mt7530.c
17 @@ -1001,9 +1001,6 @@ mt753x_cpu_port_enable(struct dsa_switch
18 mt7530_write(priv, MT7530_PVC_P(port),
19 PORT_SPEC_TAG);
20
21 - /* Unknown multicast frame forwarding to the cpu port */
22 - mt7530_rmw(priv, MT7530_MFC, UNM_FFP_MASK, UNM_FFP(BIT(port)));
23 -
24 /* Set CPU port number */
25 if (priv->id == ID_MT7621)
26 mt7530_rmw(priv, MT7530_MFC, CPU_MASK, CPU_EN | CPU_PORT(port));
27 @@ -1134,6 +1131,20 @@ mt7530_stp_state_set(struct dsa_switch *
28 }
29
30 static int
31 +mt7530_port_egress_floods(struct dsa_switch *ds, int port,
32 + bool unicast, bool multicast)
33 +{
34 + struct mt7530_priv *priv = ds->priv;
35 +
36 + mt7530_rmw(priv, MT7530_MFC,
37 + UNU_FFP(BIT(port)) | UNM_FFP(BIT(port)),
38 + (unicast ? UNU_FFP(BIT(port)) : 0) |
39 + (multicast ? UNM_FFP(BIT(port)) : 0));
40 +
41 + return 0;
42 +}
43 +
44 +static int
45 mt7530_port_bridge_join(struct dsa_switch *ds, int port,
46 struct net_device *bridge)
47 {
48 @@ -1334,6 +1345,63 @@ err:
49 }
50
51 static int
52 +mt7530_port_mdb_prepare(struct dsa_switch *ds, int port,
53 + const struct switchdev_obj_port_mdb *mdb)
54 +{
55 + return 0;
56 +}
57 +
58 +static void
59 +mt7530_port_mdb_add(struct dsa_switch *ds, int port,
60 + const struct switchdev_obj_port_mdb *mdb)
61 +{
62 + struct mt7530_priv *priv = ds->priv;
63 + const u8 *addr = mdb->addr;
64 + u16 vid = mdb->vid;
65 + u8 port_mask = 0;
66 +
67 + mutex_lock(&priv->reg_mutex);
68 +
69 + mt7530_fdb_write(priv, vid, 0, addr, 0, STATIC_EMP);
70 + if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL))
71 + port_mask = (mt7530_read(priv, MT7530_ATRD) >> PORT_MAP)
72 + & PORT_MAP_MASK;
73 +
74 + port_mask |= BIT(port);
75 + mt7530_fdb_write(priv, vid, port_mask, addr, -1, STATIC_ENT);
76 + mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, NULL);
77 +
78 + mutex_unlock(&priv->reg_mutex);
79 +}
80 +
81 +static int
82 +mt7530_port_mdb_del(struct dsa_switch *ds, int port,
83 + const struct switchdev_obj_port_mdb *mdb)
84 +{
85 + struct mt7530_priv *priv = ds->priv;
86 + const u8 *addr = mdb->addr;
87 + u16 vid = mdb->vid;
88 + u8 port_mask = 0;
89 + int ret;
90 +
91 + mutex_lock(&priv->reg_mutex);
92 +
93 + mt7530_fdb_write(priv, vid, 0, addr, 0, STATIC_EMP);
94 + if (!mt7530_fdb_cmd(priv, MT7530_FDB_READ, NULL))
95 + port_mask = (mt7530_read(priv, MT7530_ATRD) >> PORT_MAP)
96 + & PORT_MAP_MASK;
97 +
98 + port_mask &= ~BIT(port);
99 + mt7530_fdb_write(priv, vid, port_mask, addr, -1,
100 + port_mask ? STATIC_ENT : STATIC_EMP);
101 + ret = mt7530_fdb_cmd(priv, MT7530_FDB_WRITE, NULL);
102 +
103 + mutex_unlock(&priv->reg_mutex);
104 +
105 + return ret;
106 +}
107 +
108 +static int
109 mt7530_vlan_cmd(struct mt7530_priv *priv, enum mt7530_vlan_cmd cmd, u16 vid)
110 {
111 struct mt7530_dummy_poll p;
112 @@ -2743,11 +2811,15 @@ static const struct dsa_switch_ops mt753
113 .port_change_mtu = mt7530_port_change_mtu,
114 .port_max_mtu = mt7530_port_max_mtu,
115 .port_stp_state_set = mt7530_stp_state_set,
116 + .port_egress_floods = mt7530_port_egress_floods,
117 .port_bridge_join = mt7530_port_bridge_join,
118 .port_bridge_leave = mt7530_port_bridge_leave,
119 .port_fdb_add = mt7530_port_fdb_add,
120 .port_fdb_del = mt7530_port_fdb_del,
121 .port_fdb_dump = mt7530_port_fdb_dump,
122 + .port_mdb_prepare = mt7530_port_mdb_prepare,
123 + .port_mdb_add = mt7530_port_mdb_add,
124 + .port_mdb_del = mt7530_port_mdb_del,
125 .port_vlan_filtering = mt7530_port_vlan_filtering,
126 .port_vlan_prepare = mt7530_port_vlan_prepare,
127 .port_vlan_add = mt7530_port_vlan_add,
128 --- a/net/dsa/tag_mtk.c
129 +++ b/net/dsa/tag_mtk.c
130 @@ -24,9 +24,6 @@ static struct sk_buff *mtk_tag_xmit(stru
131 struct dsa_port *dp = dsa_slave_to_port(dev);
132 u8 xmit_tpid;
133 u8 *mtk_tag;
134 - unsigned char *dest = eth_hdr(skb)->h_dest;
135 - bool is_multicast_skb = is_multicast_ether_addr(dest) &&
136 - !is_broadcast_ether_addr(dest);
137
138 /* Build the special tag after the MAC Source Address. If VLAN header
139 * is present, it's required that VLAN header and special tag is
140 @@ -55,10 +52,6 @@ static struct sk_buff *mtk_tag_xmit(stru
141 mtk_tag[0] = xmit_tpid;
142 mtk_tag[1] = (1 << dp->index) & MTK_HDR_XMIT_DP_BIT_MASK;
143
144 - /* Disable SA learning for multicast frames */
145 - if (unlikely(is_multicast_skb))
146 - mtk_tag[1] |= MTK_HDR_XMIT_SA_DIS;
147 -
148 /* Tag control information is kept for 802.1Q */
149 if (xmit_tpid == MTK_HDR_XMIT_UNTAGGED) {
150 mtk_tag[2] = 0;
151 @@ -74,9 +67,6 @@ static struct sk_buff *mtk_tag_rcv(struc
152 u16 hdr;
153 int port;
154 __be16 *phdr;
155 - unsigned char *dest = eth_hdr(skb)->h_dest;
156 - bool is_multicast_skb = is_multicast_ether_addr(dest) &&
157 - !is_broadcast_ether_addr(dest);
158
159 if (unlikely(!pskb_may_pull(skb, MTK_HDR_LEN)))
160 return NULL;
161 @@ -102,9 +92,7 @@ static struct sk_buff *mtk_tag_rcv(struc
162 if (!skb->dev)
163 return NULL;
164
165 - /* Only unicast or broadcast frames are offloaded */
166 - if (likely(!is_multicast_skb))
167 - dsa_default_offload_fwd_mark(skb);
168 + dsa_default_offload_fwd_mark(skb);
169
170 return skb;
171 }