Commit d2994e13 authored by Amit Cohen's avatar Amit Cohen Committed by David S. Miller

mlxsw: spectrum_switchdev: Add support for maintaining list of ports per MDB entry

As part of converting MDB code to use PGT APIs, PGT code stores which ports
are mapped to each PGT entry. PGT code is not aware of the type of the port
(multicast router or not), as it is not relevant there.

To be able to release an MDB entry when the there are no ports which are
not multicast routers, the entry should be aware of the state of its
ports. Add support for maintaining list of ports per MDB entry.

Each port will hold a reference count as multiple MDB entries can use the
same hardware MDB entry. It occurs because MDB entries in the Linux bridge
are keyed according to their multicast IP, when these entries are notified
to device drivers via switchdev, the multicast IP is converted to a
multicast MAC. This conversion might cause collisions, for example,
ff0e::1 and ff0e:1234::1 are both mapped to the multicast MAC
33:33:00:00:00:01.

Multicast router port will take a reference once, and will be marked as
'mrouter', then when port in the list is multicast router and its
reference value is one, it means that the entry can be removed in case
that there are no other ports which are not multicast routers. For that,
maintain a counter per MDB entry to count ports in the list, which were
added to the multicast group, and not because they are multicast routers.
When this counter is zero, the entry can be removed.

Add mlxsw_sp_mdb_entry_port_{get,put}() for regular ports and
mlxsw_sp_mdb_entry_mrouter_port_{get,put}() for multicast router ports.
Call PGT API to add or remove port from PGT entry when port is first added
or removed, according to the reference counting.
Signed-off-by: default avatarAmit Cohen <amcohen@nvidia.com>
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5d0512e5
......@@ -113,10 +113,19 @@ struct mlxsw_sp_mdb_entry {
struct rhash_head ht_node;
struct mlxsw_sp_mdb_entry_key key;
u16 mid;
struct list_head ports_list;
u16 ports_count;
bool in_hw;
unsigned long *ports_in_mid; /* bits array */
};
struct mlxsw_sp_mdb_entry_port {
struct list_head list; /* Member of 'ports_list'. */
u16 local_port;
refcount_t refcount;
bool mrouter;
};
static const struct rhashtable_params mlxsw_sp_mdb_ht_params = {
.key_offset = offsetof(struct mlxsw_sp_mdb_entry, key),
.head_offset = offsetof(struct mlxsw_sp_mdb_entry, ht_node),
......@@ -995,6 +1004,150 @@ static int mlxsw_sp_smid_router_port_set(struct mlxsw_sp *mlxsw_sp,
return err;
}
static struct mlxsw_sp_mdb_entry_port *
mlxsw_sp_mdb_entry_port_lookup(struct mlxsw_sp_mdb_entry *mdb_entry,
u16 local_port)
{
struct mlxsw_sp_mdb_entry_port *mdb_entry_port;
list_for_each_entry(mdb_entry_port, &mdb_entry->ports_list, list) {
if (mdb_entry_port->local_port == local_port)
return mdb_entry_port;
}
return NULL;
}
static __always_unused struct mlxsw_sp_mdb_entry_port *
mlxsw_sp_mdb_entry_port_get(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_mdb_entry *mdb_entry,
u16 local_port)
{
struct mlxsw_sp_mdb_entry_port *mdb_entry_port;
int err;
mdb_entry_port = mlxsw_sp_mdb_entry_port_lookup(mdb_entry, local_port);
if (mdb_entry_port) {
if (mdb_entry_port->mrouter &&
refcount_read(&mdb_entry_port->refcount) == 1)
mdb_entry->ports_count++;
refcount_inc(&mdb_entry_port->refcount);
return mdb_entry_port;
}
err = mlxsw_sp_pgt_entry_port_set(mlxsw_sp, mdb_entry->mid,
mdb_entry->key.fid, local_port, true);
if (err)
return ERR_PTR(err);
mdb_entry_port = kzalloc(sizeof(*mdb_entry_port), GFP_KERNEL);
if (!mdb_entry_port) {
err = -ENOMEM;
goto err_mdb_entry_port_alloc;
}
mdb_entry_port->local_port = local_port;
refcount_set(&mdb_entry_port->refcount, 1);
list_add(&mdb_entry_port->list, &mdb_entry->ports_list);
mdb_entry->ports_count++;
return mdb_entry_port;
err_mdb_entry_port_alloc:
mlxsw_sp_pgt_entry_port_set(mlxsw_sp, mdb_entry->mid,
mdb_entry->key.fid, local_port, false);
return ERR_PTR(err);
}
static __always_unused void
mlxsw_sp_mdb_entry_port_put(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_mdb_entry *mdb_entry,
u16 local_port, bool force)
{
struct mlxsw_sp_mdb_entry_port *mdb_entry_port;
mdb_entry_port = mlxsw_sp_mdb_entry_port_lookup(mdb_entry, local_port);
if (!mdb_entry_port)
return;
if (!force && !refcount_dec_and_test(&mdb_entry_port->refcount)) {
if (mdb_entry_port->mrouter &&
refcount_read(&mdb_entry_port->refcount) == 1)
mdb_entry->ports_count--;
return;
}
mdb_entry->ports_count--;
list_del(&mdb_entry_port->list);
kfree(mdb_entry_port);
mlxsw_sp_pgt_entry_port_set(mlxsw_sp, mdb_entry->mid,
mdb_entry->key.fid, local_port, false);
}
static __always_unused struct mlxsw_sp_mdb_entry_port *
mlxsw_sp_mdb_entry_mrouter_port_get(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_mdb_entry *mdb_entry,
u16 local_port)
{
struct mlxsw_sp_mdb_entry_port *mdb_entry_port;
int err;
mdb_entry_port = mlxsw_sp_mdb_entry_port_lookup(mdb_entry, local_port);
if (mdb_entry_port) {
if (!mdb_entry_port->mrouter)
refcount_inc(&mdb_entry_port->refcount);
return mdb_entry_port;
}
err = mlxsw_sp_pgt_entry_port_set(mlxsw_sp, mdb_entry->mid,
mdb_entry->key.fid, local_port, true);
if (err)
return ERR_PTR(err);
mdb_entry_port = kzalloc(sizeof(*mdb_entry_port), GFP_KERNEL);
if (!mdb_entry_port) {
err = -ENOMEM;
goto err_mdb_entry_port_alloc;
}
mdb_entry_port->local_port = local_port;
refcount_set(&mdb_entry_port->refcount, 1);
mdb_entry_port->mrouter = true;
list_add(&mdb_entry_port->list, &mdb_entry->ports_list);
return mdb_entry_port;
err_mdb_entry_port_alloc:
mlxsw_sp_pgt_entry_port_set(mlxsw_sp, mdb_entry->mid,
mdb_entry->key.fid, local_port, false);
return ERR_PTR(err);
}
static __always_unused void
mlxsw_sp_mdb_entry_mrouter_port_put(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_mdb_entry *mdb_entry,
u16 local_port)
{
struct mlxsw_sp_mdb_entry_port *mdb_entry_port;
mdb_entry_port = mlxsw_sp_mdb_entry_port_lookup(mdb_entry, local_port);
if (!mdb_entry_port)
return;
if (!mdb_entry_port->mrouter)
return;
mdb_entry_port->mrouter = false;
if (!refcount_dec_and_test(&mdb_entry_port->refcount))
return;
list_del(&mdb_entry_port->list);
kfree(mdb_entry_port);
mlxsw_sp_pgt_entry_port_set(mlxsw_sp, mdb_entry->mid,
mdb_entry->key.fid, local_port, false);
}
static void
mlxsw_sp_bridge_mrouter_update_mdb(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_bridge_device *bridge_device,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment