Commit 0161b950 authored by Nogah Frankel's avatar Nogah Frankel Committed by David S. Miller

mlxsw: spectrum_switchdev: Remove reference count from mid

Since there is a bitmap for the ports registered to each mid, there is no
need for a ref count, since it will always be the number of set bits in
this bitmap. Any check of the ref count was replaced with checking if the
bitmap is empty.
Signed-off-by: default avatarNogah Frankel <nogahf@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4cdc35e4
...@@ -94,7 +94,6 @@ struct mlxsw_sp_mid { ...@@ -94,7 +94,6 @@ struct mlxsw_sp_mid {
unsigned char addr[ETH_ALEN]; unsigned char addr[ETH_ALEN];
u16 fid; u16 fid;
u16 mid; u16 mid;
unsigned int ref_count;
unsigned long *ports_in_mid; /* bits array */ unsigned long *ports_in_mid; /* bits array */
}; };
......
...@@ -1263,19 +1263,19 @@ static struct mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp, ...@@ -1263,19 +1263,19 @@ static struct mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp,
ether_addr_copy(mid->addr, addr); ether_addr_copy(mid->addr, addr);
mid->fid = fid; mid->fid = fid;
mid->mid = mid_idx; mid->mid = mid_idx;
mid->ref_count = 0;
list_add_tail(&mid->list, &mlxsw_sp->bridge->mids_list); list_add_tail(&mid->list, &mlxsw_sp->bridge->mids_list);
return mid; return mid;
} }
static int __mlxsw_sp_mc_dec_ref(struct mlxsw_sp_port *mlxsw_sp_port, static int mlxsw_sp_port_remove_from_mid(struct mlxsw_sp_port *mlxsw_sp_port,
struct mlxsw_sp_mid *mid) struct mlxsw_sp_mid *mid)
{ {
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
clear_bit(mlxsw_sp_port->local_port, mid->ports_in_mid); clear_bit(mlxsw_sp_port->local_port, mid->ports_in_mid);
if (--mid->ref_count == 0) { if (bitmap_empty(mid->ports_in_mid,
mlxsw_core_max_ports(mlxsw_sp->core))) {
list_del(&mid->list); list_del(&mid->list);
clear_bit(mid->mid, mlxsw_sp->bridge->mids_bitmap); clear_bit(mid->mid, mlxsw_sp->bridge->mids_bitmap);
kfree(mid->ports_in_mid); kfree(mid->ports_in_mid);
...@@ -1296,6 +1296,7 @@ static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1296,6 +1296,7 @@ static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
struct mlxsw_sp_bridge_device *bridge_device; struct mlxsw_sp_bridge_device *bridge_device;
struct mlxsw_sp_bridge_port *bridge_port; struct mlxsw_sp_bridge_port *bridge_port;
struct mlxsw_sp_mid *mid; struct mlxsw_sp_mid *mid;
bool is_new_mid = false;
u16 fid_index; u16 fid_index;
int err = 0; int err = 0;
...@@ -1322,18 +1323,17 @@ static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1322,18 +1323,17 @@ static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
netdev_err(dev, "Unable to allocate MC group\n"); netdev_err(dev, "Unable to allocate MC group\n");
return -ENOMEM; return -ENOMEM;
} }
is_new_mid = true;
} }
mid->ref_count++;
set_bit(mlxsw_sp_port->local_port, mid->ports_in_mid); set_bit(mlxsw_sp_port->local_port, mid->ports_in_mid);
err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, true, err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, true, is_new_mid);
mid->ref_count == 1);
if (err) { if (err) {
netdev_err(dev, "Unable to set SMID\n"); netdev_err(dev, "Unable to set SMID\n");
goto err_out; goto err_out;
} }
if (mid->ref_count == 1) { if (is_new_mid) {
err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid_index, err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid_index,
mid->mid, true); mid->mid, true);
if (err) { if (err) {
...@@ -1345,7 +1345,7 @@ static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1345,7 +1345,7 @@ static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
return 0; return 0;
err_out: err_out:
__mlxsw_sp_mc_dec_ref(mlxsw_sp_port, mid); mlxsw_sp_port_remove_from_mid(mlxsw_sp_port, mid);
return err; return err;
} }
...@@ -1451,7 +1451,7 @@ static int mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1451,7 +1451,7 @@ static int mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port,
netdev_err(dev, "Unable to remove port from SMID\n"); netdev_err(dev, "Unable to remove port from SMID\n");
mid_idx = mid->mid; mid_idx = mid->mid;
if (__mlxsw_sp_mc_dec_ref(mlxsw_sp_port, mid)) { if (mlxsw_sp_port_remove_from_mid(mlxsw_sp_port, mid)) {
err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid_index, err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid_index,
mid_idx, false); mid_idx, false);
if (err) if (err)
......
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