ath25: switch default kernel to 5.15
[openwrt/staging/ldir.git] / target / linux / generic / backport-5.10 / 761-net-next-net-dsa-qca8k-add-support-for-mdb_add-del.patch
1 From ba8f870dfa635113ce6e8095a5eb1835ecde2e9e Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Mon, 22 Nov 2021 16:23:48 +0100
4 Subject: net: dsa: qca8k: add support for mdb_add/del
5
6 Add support for mdb add/del function. The ARL table is used to insert
7 the rule. The rule will be searched, deleted and reinserted with the
8 port mask updated. The function will check if the rule has to be updated
9 or insert directly with no deletion of the old rule.
10 If every port is removed from the port mask, the rule is removed.
11 The rule is set STATIC in the ARL table (aka it doesn't age) to not be
12 flushed by fast age function.
13
14 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
15 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
17 ---
18 drivers/net/dsa/qca8k.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++
19 1 file changed, 99 insertions(+)
20
21 --- a/drivers/net/dsa/qca8k.c
22 +++ b/drivers/net/dsa/qca8k.c
23 @@ -436,6 +436,81 @@ qca8k_fdb_flush(struct qca8k_priv *priv)
24 }
25
26 static int
27 +qca8k_fdb_search_and_insert(struct qca8k_priv *priv, u8 port_mask,
28 + const u8 *mac, u16 vid)
29 +{
30 + struct qca8k_fdb fdb = { 0 };
31 + int ret;
32 +
33 + mutex_lock(&priv->reg_mutex);
34 +
35 + qca8k_fdb_write(priv, vid, 0, mac, 0);
36 + ret = qca8k_fdb_access(priv, QCA8K_FDB_SEARCH, -1);
37 + if (ret < 0)
38 + goto exit;
39 +
40 + ret = qca8k_fdb_read(priv, &fdb);
41 + if (ret < 0)
42 + goto exit;
43 +
44 + /* Rule exist. Delete first */
45 + if (!fdb.aging) {
46 + ret = qca8k_fdb_access(priv, QCA8K_FDB_PURGE, -1);
47 + if (ret)
48 + goto exit;
49 + }
50 +
51 + /* Add port to fdb portmask */
52 + fdb.port_mask |= port_mask;
53 +
54 + qca8k_fdb_write(priv, vid, fdb.port_mask, mac, fdb.aging);
55 + ret = qca8k_fdb_access(priv, QCA8K_FDB_LOAD, -1);
56 +
57 +exit:
58 + mutex_unlock(&priv->reg_mutex);
59 + return ret;
60 +}
61 +
62 +static int
63 +qca8k_fdb_search_and_del(struct qca8k_priv *priv, u8 port_mask,
64 + const u8 *mac, u16 vid)
65 +{
66 + struct qca8k_fdb fdb = { 0 };
67 + int ret;
68 +
69 + mutex_lock(&priv->reg_mutex);
70 +
71 + qca8k_fdb_write(priv, vid, 0, mac, 0);
72 + ret = qca8k_fdb_access(priv, QCA8K_FDB_SEARCH, -1);
73 + if (ret < 0)
74 + goto exit;
75 +
76 + /* Rule doesn't exist. Why delete? */
77 + if (!fdb.aging) {
78 + ret = -EINVAL;
79 + goto exit;
80 + }
81 +
82 + ret = qca8k_fdb_access(priv, QCA8K_FDB_PURGE, -1);
83 + if (ret)
84 + goto exit;
85 +
86 + /* Only port in the rule is this port. Don't re insert */
87 + if (fdb.port_mask == port_mask)
88 + goto exit;
89 +
90 + /* Remove port from port mask */
91 + fdb.port_mask &= ~port_mask;
92 +
93 + qca8k_fdb_write(priv, vid, fdb.port_mask, mac, fdb.aging);
94 + ret = qca8k_fdb_access(priv, QCA8K_FDB_LOAD, -1);
95 +
96 +exit:
97 + mutex_unlock(&priv->reg_mutex);
98 + return ret;
99 +}
100 +
101 +static int
102 qca8k_vlan_access(struct qca8k_priv *priv, enum qca8k_vlan_cmd cmd, u16 vid)
103 {
104 u32 reg;
105 @@ -1929,6 +2004,28 @@ qca8k_port_fdb_dump(struct dsa_switch *d
106 return 0;
107 }
108
109 +static void
110 +qca8k_port_mdb_add(struct dsa_switch *ds, int port,
111 + const struct switchdev_obj_port_mdb *mdb)
112 +{
113 + struct qca8k_priv *priv = ds->priv;
114 + const u8 *addr = mdb->addr;
115 + u16 vid = mdb->vid;
116 +
117 + qca8k_fdb_search_and_insert(priv, BIT(port), addr, vid);
118 +}
119 +
120 +static int
121 +qca8k_port_mdb_del(struct dsa_switch *ds, int port,
122 + const struct switchdev_obj_port_mdb *mdb)
123 +{
124 + struct qca8k_priv *priv = ds->priv;
125 + const u8 *addr = mdb->addr;
126 + u16 vid = mdb->vid;
127 +
128 + return qca8k_fdb_search_and_del(priv, BIT(port), addr, vid);
129 +}
130 +
131 static int
132 qca8k_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
133 struct switchdev_trans *trans)
134 @@ -2044,6 +2141,8 @@ static const struct dsa_switch_ops qca8k
135 .port_fdb_add = qca8k_port_fdb_add,
136 .port_fdb_del = qca8k_port_fdb_del,
137 .port_fdb_dump = qca8k_port_fdb_dump,
138 + .port_mdb_add = qca8k_port_mdb_add,
139 + .port_mdb_del = qca8k_port_mdb_del,
140 .port_vlan_filtering = qca8k_port_vlan_filtering,
141 .port_vlan_prepare = qca8k_port_vlan_prepare,
142 .port_vlan_add = qca8k_port_vlan_add,