Skip to content

Commit 6ce71ac

Browse files
Rony Efraimdavem330
authored andcommitted
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: Rony Efraim <ronye@mellanox.com> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dc8142e commit 6ce71ac

File tree

1 file changed

+10
-5
lines changed
  • drivers/net/ethernet/mellanox/mlx4

1 file changed

+10
-5
lines changed

drivers/net/ethernet/mellanox/mlx4/port.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
141141
}
142142

143143
if (mac == (MLX4_MAC_MASK & be64_to_cpu(table->entries[i]))) {
144-
/* MAC already registered, Must not have duplicates */
145-
err = -EEXIST;
144+
/* MAC already registered, increment ref count */
145+
err = i;
146+
++table->refs[i];
146147
goto out;
147148
}
148149
}
@@ -165,7 +166,7 @@ int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac)
165166
table->entries[free] = 0;
166167
goto out;
167168
}
168-
169+
table->refs[free] = 1;
169170
err = free;
170171
++table->total;
171172
out:
@@ -206,12 +207,16 @@ void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac)
206207
struct mlx4_mac_table *table = &info->mac_table;
207208
int index;
208209

209-
index = find_index(dev, table, mac);
210-
211210
mutex_lock(&table->mutex);
211+
index = find_index(dev, table, mac);
212212

213213
if (validate_index(dev, table, index))
214214
goto out;
215+
if (--table->refs[index]) {
216+
mlx4_dbg(dev, "Have more references for index %d,"
217+
"no need to modify mac table\n", index);
218+
goto out;
219+
}
215220

216221
table->entries[index] = 0;
217222
mlx4_set_port_mac_table(dev, port, table->entries);

0 commit comments

Comments
 (0)