Commit 6ce71acd authored by Rony Efraim's avatar Rony Efraim Committed by David S. Miller

net/mlx4: Add reference counting to MAC registeration

Add reference counting to the driver MAC registeration code. This would
be needed for cases where a mac is registered from more than once, e.g
when both the host and the VM driver register the same mac, the host
for mac spoof protection purposes and the VM for its regular needs.
Signed-off-by: default avatarRony Efraim <ronye@mellanox.com>
Signed-off-by: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dc8142ea
...@@ -141,8 +141,9 @@ int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac) ...@@ -141,8 +141,9 @@ int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
} }
if (mac == (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) { if (mac == (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) {
/* MAC already registered, Must not have duplicates */ /* MAC already registered, increment ref count */
err = -EEXIST; err = i;
++table->refs[i];
goto out; goto out;
} }
} }
...@@ -165,7 +166,7 @@ int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac) ...@@ -165,7 +166,7 @@ int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
table->entries[free] = 0; table->entries[free] = 0;
goto out; goto out;
} }
table->refs[free] = 1;
err = free; err = free;
++table->total; ++table->total;
out: out:
...@@ -206,12 +207,16 @@ void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac) ...@@ -206,12 +207,16 @@ void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
struct mlx4_mac_table *table = &info->mac_table; struct mlx4_mac_table *table = &info->mac_table;
int index; int index;
index = find_index(dev, table, mac);
mutex_lock(&table->mutex); mutex_lock(&table->mutex);
index = find_index(dev, table, mac);
if (validate_index(dev, table, index)) if (validate_index(dev, table, index))
goto out; goto out;
if (--table->refs[index]) {
mlx4_dbg(dev, "Have more references for index %d,"
"no need to modify mac table\n", index);
goto out;
}
table->entries[index] = 0; table->entries[index] = 0;
mlx4_set_port_mac_table(dev, port, table->entries); mlx4_set_port_mac_table(dev, port, table->entries);
......
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