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
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.
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>
18 drivers/net/dsa/qca8k.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++
19 1 file changed, 99 insertions(+)
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)
27 +qca8k_fdb_search_and_insert(struct qca8k_priv *priv, u8 port_mask,
28 + const u8 *mac, u16 vid)
30 + struct qca8k_fdb fdb = { 0 };
33 + mutex_lock(&priv->reg_mutex);
35 + qca8k_fdb_write(priv, vid, 0, mac, 0);
36 + ret = qca8k_fdb_access(priv, QCA8K_FDB_SEARCH, -1);
40 + ret = qca8k_fdb_read(priv, &fdb);
44 + /* Rule exist. Delete first */
46 + ret = qca8k_fdb_access(priv, QCA8K_FDB_PURGE, -1);
51 + /* Add port to fdb portmask */
52 + fdb.port_mask |= port_mask;
54 + qca8k_fdb_write(priv, vid, fdb.port_mask, mac, fdb.aging);
55 + ret = qca8k_fdb_access(priv, QCA8K_FDB_LOAD, -1);
58 + mutex_unlock(&priv->reg_mutex);
63 +qca8k_fdb_search_and_del(struct qca8k_priv *priv, u8 port_mask,
64 + const u8 *mac, u16 vid)
66 + struct qca8k_fdb fdb = { 0 };
69 + mutex_lock(&priv->reg_mutex);
71 + qca8k_fdb_write(priv, vid, 0, mac, 0);
72 + ret = qca8k_fdb_access(priv, QCA8K_FDB_SEARCH, -1);
76 + /* Rule doesn't exist. Why delete? */
82 + ret = qca8k_fdb_access(priv, QCA8K_FDB_PURGE, -1);
86 + /* Only port in the rule is this port. Don't re insert */
87 + if (fdb.port_mask == port_mask)
90 + /* Remove port from port mask */
91 + fdb.port_mask &= ~port_mask;
93 + qca8k_fdb_write(priv, vid, fdb.port_mask, mac, fdb.aging);
94 + ret = qca8k_fdb_access(priv, QCA8K_FDB_LOAD, -1);
97 + mutex_unlock(&priv->reg_mutex);
102 qca8k_vlan_access(struct qca8k_priv *priv, enum qca8k_vlan_cmd cmd, u16 vid)
105 @@ -1949,6 +2024,28 @@ qca8k_port_fdb_dump(struct dsa_switch *d
109 +qca8k_port_mdb_add(struct dsa_switch *ds, int port,
110 + const struct switchdev_obj_port_mdb *mdb)
112 + struct qca8k_priv *priv = ds->priv;
113 + const u8 *addr = mdb->addr;
114 + u16 vid = mdb->vid;
116 + return qca8k_fdb_search_and_insert(priv, BIT(port), addr, vid);
120 +qca8k_port_mdb_del(struct dsa_switch *ds, int port,
121 + const struct switchdev_obj_port_mdb *mdb)
123 + struct qca8k_priv *priv = ds->priv;
124 + const u8 *addr = mdb->addr;
125 + u16 vid = mdb->vid;
127 + return qca8k_fdb_search_and_del(priv, BIT(port), addr, vid);
131 qca8k_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
132 struct netlink_ext_ack *extack)
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,