8b97939ecb290f30e428e5c132c735b121add235
[openwrt/staging/jogo.git] /
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 @@ -1949,6 +2024,28 @@ qca8k_port_fdb_dump(struct dsa_switch *d
106 }
107
108 static int
109 +qca8k_port_mdb_add(struct dsa_switch *ds, int port,
110 + const struct switchdev_obj_port_mdb *mdb)
111 +{
112 + struct qca8k_priv *priv = ds->priv;
113 + const u8 *addr = mdb->addr;
114 + u16 vid = mdb->vid;
115 +
116 + return qca8k_fdb_search_and_insert(priv, BIT(port), addr, vid);
117 +}
118 +
119 +static int
120 +qca8k_port_mdb_del(struct dsa_switch *ds, int port,
121 + const struct switchdev_obj_port_mdb *mdb)
122 +{
123 + struct qca8k_priv *priv = ds->priv;
124 + const u8 *addr = mdb->addr;
125 + u16 vid = mdb->vid;
126 +
127 + return qca8k_fdb_search_and_del(priv, BIT(port), addr, vid);
128 +}
129 +
130 +static int
131 qca8k_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
132 struct netlink_ext_ack *extack)
133 {
134 @@ -2056,6 +2153,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_add = qca8k_port_vlan_add,
142 .port_vlan_del = qca8k_port_vlan_del,