a71d7480da2a358738359030042772ba8d29008e
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 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 diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
22 index 45e769b9166b8..67742fbd80409 100644
23 --- a/drivers/net/dsa/qca8k.c
24 +++ b/drivers/net/dsa/qca8k.c
25 @@ -435,6 +435,81 @@ qca8k_fdb_flush(struct qca8k_priv *priv)
26 mutex_unlock(&priv->reg_mutex);
27 }
28
29 +static int
30 +qca8k_fdb_search_and_insert(struct qca8k_priv *priv, u8 port_mask,
31 + const u8 *mac, u16 vid)
32 +{
33 + struct qca8k_fdb fdb = { 0 };
34 + int ret;
35 +
36 + mutex_lock(&priv->reg_mutex);
37 +
38 + qca8k_fdb_write(priv, vid, 0, mac, 0);
39 + ret = qca8k_fdb_access(priv, QCA8K_FDB_SEARCH, -1);
40 + if (ret < 0)
41 + goto exit;
42 +
43 + ret = qca8k_fdb_read(priv, &fdb);
44 + if (ret < 0)
45 + goto exit;
46 +
47 + /* Rule exist. Delete first */
48 + if (!fdb.aging) {
49 + ret = qca8k_fdb_access(priv, QCA8K_FDB_PURGE, -1);
50 + if (ret)
51 + goto exit;
52 + }
53 +
54 + /* Add port to fdb portmask */
55 + fdb.port_mask |= port_mask;
56 +
57 + qca8k_fdb_write(priv, vid, fdb.port_mask, mac, fdb.aging);
58 + ret = qca8k_fdb_access(priv, QCA8K_FDB_LOAD, -1);
59 +
60 +exit:
61 + mutex_unlock(&priv->reg_mutex);
62 + return ret;
63 +}
64 +
65 +static int
66 +qca8k_fdb_search_and_del(struct qca8k_priv *priv, u8 port_mask,
67 + const u8 *mac, u16 vid)
68 +{
69 + struct qca8k_fdb fdb = { 0 };
70 + int ret;
71 +
72 + mutex_lock(&priv->reg_mutex);
73 +
74 + qca8k_fdb_write(priv, vid, 0, mac, 0);
75 + ret = qca8k_fdb_access(priv, QCA8K_FDB_SEARCH, -1);
76 + if (ret < 0)
77 + goto exit;
78 +
79 + /* Rule doesn't exist. Why delete? */
80 + if (!fdb.aging) {
81 + ret = -EINVAL;
82 + goto exit;
83 + }
84 +
85 + ret = qca8k_fdb_access(priv, QCA8K_FDB_PURGE, -1);
86 + if (ret)
87 + goto exit;
88 +
89 + /* Only port in the rule is this port. Don't re insert */
90 + if (fdb.port_mask == port_mask)
91 + goto exit;
92 +
93 + /* Remove port from port mask */
94 + fdb.port_mask &= ~port_mask;
95 +
96 + qca8k_fdb_write(priv, vid, fdb.port_mask, mac, fdb.aging);
97 + ret = qca8k_fdb_access(priv, QCA8K_FDB_LOAD, -1);
98 +
99 +exit:
100 + mutex_unlock(&priv->reg_mutex);
101 + return ret;
102 +}
103 +
104 static int
105 qca8k_vlan_access(struct qca8k_priv *priv, enum qca8k_vlan_cmd cmd, u16 vid)
106 {
107 @@ -1925,6 +2000,28 @@ qca8k_port_fdb_dump(struct dsa_switch *ds, int port,
108 return 0;
109 }
110
111 +static int
112 +qca8k_port_mdb_add(struct dsa_switch *ds, int port,
113 + const struct switchdev_obj_port_mdb *mdb)
114 +{
115 + struct qca8k_priv *priv = ds->priv;
116 + const u8 *addr = mdb->addr;
117 + u16 vid = mdb->vid;
118 +
119 + return qca8k_fdb_search_and_insert(priv, BIT(port), addr, vid);
120 +}
121 +
122 +static int
123 +qca8k_port_mdb_del(struct dsa_switch *ds, int port,
124 + const struct switchdev_obj_port_mdb *mdb)
125 +{
126 + struct qca8k_priv *priv = ds->priv;
127 + const u8 *addr = mdb->addr;
128 + u16 vid = mdb->vid;
129 +
130 + return qca8k_fdb_search_and_del(priv, BIT(port), addr, vid);
131 +}
132 +
133 static int
134 qca8k_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
135 struct netlink_ext_ack *extack)
136 @@ -2033,6 +2130,8 @@ static const struct dsa_switch_ops qca8k_switch_ops = {
137 .port_fdb_add = qca8k_port_fdb_add,
138 .port_fdb_del = qca8k_port_fdb_del,
139 .port_fdb_dump = qca8k_port_fdb_dump,
140 + .port_mdb_add = qca8k_port_mdb_add,
141 + .port_mdb_del = qca8k_port_mdb_del,
142 .port_vlan_filtering = qca8k_port_vlan_filtering,
143 .port_vlan_add = qca8k_port_vlan_add,
144 .port_vlan_del = qca8k_port_vlan_del,
145 --
146 cgit 1.2.3-1.el7
147