Commit 2deda2f1 authored by Vlad Buslov's avatar Vlad Buslov Committed by Saeed Mahameed

net/mlx5: Bridge, extract code to lookup and del/notify entry

Following two patterns in bridge code are used in multiple places where
similar code is duplicated:

- Lookup FDB entry from hashtable by address+vid pair.

- Notify software bridge and then delete existing FDB entry.

In order to improve code quality and prepare for following patch series
that also uses described patterns, extract the codes to dedicated helper
functions.

This commit doesn't change functionality.
Signed-off-by: default avatarVlad Buslov <vladbu@nvidia.com>
Reviewed-by: default avatarPaul Blakey <paulb@nvidia.com>
Reviewed-by: default avatarRoi Dayan <roid@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 5a1023de
...@@ -888,14 +888,20 @@ mlx5_esw_bridge_fdb_entry_cleanup(struct mlx5_esw_bridge_fdb_entry *entry, ...@@ -888,14 +888,20 @@ mlx5_esw_bridge_fdb_entry_cleanup(struct mlx5_esw_bridge_fdb_entry *entry,
kvfree(entry); kvfree(entry);
} }
static void
mlx5_esw_bridge_fdb_entry_notify_and_cleanup(struct mlx5_esw_bridge_fdb_entry *entry,
struct mlx5_esw_bridge *bridge)
{
mlx5_esw_bridge_fdb_del_notify(entry);
mlx5_esw_bridge_fdb_entry_cleanup(entry, bridge);
}
static void mlx5_esw_bridge_fdb_flush(struct mlx5_esw_bridge *bridge) static void mlx5_esw_bridge_fdb_flush(struct mlx5_esw_bridge *bridge)
{ {
struct mlx5_esw_bridge_fdb_entry *entry, *tmp; struct mlx5_esw_bridge_fdb_entry *entry, *tmp;
list_for_each_entry_safe(entry, tmp, &bridge->fdb_list, list) { list_for_each_entry_safe(entry, tmp, &bridge->fdb_list, list)
mlx5_esw_bridge_fdb_del_notify(entry); mlx5_esw_bridge_fdb_entry_notify_and_cleanup(entry, bridge);
mlx5_esw_bridge_fdb_entry_cleanup(entry, bridge);
}
} }
static struct mlx5_esw_bridge_vlan * static struct mlx5_esw_bridge_vlan *
...@@ -1065,10 +1071,8 @@ static void mlx5_esw_bridge_vlan_flush(struct mlx5_esw_bridge_vlan *vlan, ...@@ -1065,10 +1071,8 @@ static void mlx5_esw_bridge_vlan_flush(struct mlx5_esw_bridge_vlan *vlan,
struct mlx5_eswitch *esw = bridge->br_offloads->esw; struct mlx5_eswitch *esw = bridge->br_offloads->esw;
struct mlx5_esw_bridge_fdb_entry *entry, *tmp; struct mlx5_esw_bridge_fdb_entry *entry, *tmp;
list_for_each_entry_safe(entry, tmp, &vlan->fdb_list, vlan_list) { list_for_each_entry_safe(entry, tmp, &vlan->fdb_list, vlan_list)
mlx5_esw_bridge_fdb_del_notify(entry); mlx5_esw_bridge_fdb_entry_notify_and_cleanup(entry, bridge);
mlx5_esw_bridge_fdb_entry_cleanup(entry, bridge);
}
if (vlan->pkt_reformat_pop) if (vlan->pkt_reformat_pop)
mlx5_esw_bridge_vlan_pop_cleanup(vlan, esw); mlx5_esw_bridge_vlan_pop_cleanup(vlan, esw);
...@@ -1127,6 +1131,17 @@ mlx5_esw_bridge_port_vlan_lookup(u16 vid, u16 vport_num, u16 esw_owner_vhca_id, ...@@ -1127,6 +1131,17 @@ mlx5_esw_bridge_port_vlan_lookup(u16 vid, u16 vport_num, u16 esw_owner_vhca_id,
return vlan; return vlan;
} }
static struct mlx5_esw_bridge_fdb_entry *
mlx5_esw_bridge_fdb_lookup(struct mlx5_esw_bridge *bridge,
const unsigned char *addr, u16 vid)
{
struct mlx5_esw_bridge_fdb_key key = {};
ether_addr_copy(key.addr, addr);
key.vid = vid;
return rhashtable_lookup_fast(&bridge->fdb_ht, &key, fdb_ht_params);
}
static struct mlx5_esw_bridge_fdb_entry * static struct mlx5_esw_bridge_fdb_entry *
mlx5_esw_bridge_fdb_entry_init(struct net_device *dev, u16 vport_num, u16 esw_owner_vhca_id, mlx5_esw_bridge_fdb_entry_init(struct net_device *dev, u16 vport_num, u16 esw_owner_vhca_id,
const unsigned char *addr, u16 vid, bool added_by_user, bool peer, const unsigned char *addr, u16 vid, bool added_by_user, bool peer,
...@@ -1444,7 +1459,6 @@ void mlx5_esw_bridge_fdb_update_used(struct net_device *dev, u16 vport_num, u16 ...@@ -1444,7 +1459,6 @@ void mlx5_esw_bridge_fdb_update_used(struct net_device *dev, u16 vport_num, u16
struct switchdev_notifier_fdb_info *fdb_info) struct switchdev_notifier_fdb_info *fdb_info)
{ {
struct mlx5_esw_bridge_fdb_entry *entry; struct mlx5_esw_bridge_fdb_entry *entry;
struct mlx5_esw_bridge_fdb_key key;
struct mlx5_esw_bridge_port *port; struct mlx5_esw_bridge_port *port;
struct mlx5_esw_bridge *bridge; struct mlx5_esw_bridge *bridge;
...@@ -1453,13 +1467,11 @@ void mlx5_esw_bridge_fdb_update_used(struct net_device *dev, u16 vport_num, u16 ...@@ -1453,13 +1467,11 @@ void mlx5_esw_bridge_fdb_update_used(struct net_device *dev, u16 vport_num, u16
return; return;
bridge = port->bridge; bridge = port->bridge;
ether_addr_copy(key.addr, fdb_info->addr); entry = mlx5_esw_bridge_fdb_lookup(bridge, fdb_info->addr, fdb_info->vid);
key.vid = fdb_info->vid;
entry = rhashtable_lookup_fast(&bridge->fdb_ht, &key, fdb_ht_params);
if (!entry) { if (!entry) {
esw_debug(br_offloads->esw->dev, esw_debug(br_offloads->esw->dev,
"FDB entry with specified key not found (MAC=%pM,vid=%u,vport=%u)\n", "FDB entry with specified key not found (MAC=%pM,vid=%u,vport=%u)\n",
key.addr, key.vid, vport_num); fdb_info->addr, fdb_info->vid, vport_num);
return; return;
} }
...@@ -1501,7 +1513,6 @@ void mlx5_esw_bridge_fdb_remove(struct net_device *dev, u16 vport_num, u16 esw_o ...@@ -1501,7 +1513,6 @@ void mlx5_esw_bridge_fdb_remove(struct net_device *dev, u16 vport_num, u16 esw_o
{ {
struct mlx5_eswitch *esw = br_offloads->esw; struct mlx5_eswitch *esw = br_offloads->esw;
struct mlx5_esw_bridge_fdb_entry *entry; struct mlx5_esw_bridge_fdb_entry *entry;
struct mlx5_esw_bridge_fdb_key key;
struct mlx5_esw_bridge_port *port; struct mlx5_esw_bridge_port *port;
struct mlx5_esw_bridge *bridge; struct mlx5_esw_bridge *bridge;
...@@ -1510,18 +1521,15 @@ void mlx5_esw_bridge_fdb_remove(struct net_device *dev, u16 vport_num, u16 esw_o ...@@ -1510,18 +1521,15 @@ void mlx5_esw_bridge_fdb_remove(struct net_device *dev, u16 vport_num, u16 esw_o
return; return;
bridge = port->bridge; bridge = port->bridge;
ether_addr_copy(key.addr, fdb_info->addr); entry = mlx5_esw_bridge_fdb_lookup(bridge, fdb_info->addr, fdb_info->vid);
key.vid = fdb_info->vid;
entry = rhashtable_lookup_fast(&bridge->fdb_ht, &key, fdb_ht_params);
if (!entry) { if (!entry) {
esw_warn(esw->dev, esw_warn(esw->dev,
"FDB entry with specified key not found (MAC=%pM,vid=%u,vport=%u)\n", "FDB entry with specified key not found (MAC=%pM,vid=%u,vport=%u)\n",
key.addr, key.vid, vport_num); fdb_info->addr, fdb_info->vid, vport_num);
return; return;
} }
mlx5_esw_bridge_fdb_del_notify(entry); mlx5_esw_bridge_fdb_entry_notify_and_cleanup(entry, bridge);
mlx5_esw_bridge_fdb_entry_cleanup(entry, bridge);
} }
void mlx5_esw_bridge_update(struct mlx5_esw_bridge_offloads *br_offloads) void mlx5_esw_bridge_update(struct mlx5_esw_bridge_offloads *br_offloads)
...@@ -1537,13 +1545,11 @@ void mlx5_esw_bridge_update(struct mlx5_esw_bridge_offloads *br_offloads) ...@@ -1537,13 +1545,11 @@ void mlx5_esw_bridge_update(struct mlx5_esw_bridge_offloads *br_offloads)
if (entry->flags & MLX5_ESW_BRIDGE_FLAG_ADDED_BY_USER) if (entry->flags & MLX5_ESW_BRIDGE_FLAG_ADDED_BY_USER)
continue; continue;
if (time_after(lastuse, entry->lastuse)) { if (time_after(lastuse, entry->lastuse))
mlx5_esw_bridge_fdb_entry_refresh(entry); mlx5_esw_bridge_fdb_entry_refresh(entry);
} else if (!(entry->flags & MLX5_ESW_BRIDGE_FLAG_PEER) && else if (!(entry->flags & MLX5_ESW_BRIDGE_FLAG_PEER) &&
time_is_before_jiffies(entry->lastuse + bridge->ageing_time)) { time_is_before_jiffies(entry->lastuse + bridge->ageing_time))
mlx5_esw_bridge_fdb_del_notify(entry); mlx5_esw_bridge_fdb_entry_notify_and_cleanup(entry, bridge);
mlx5_esw_bridge_fdb_entry_cleanup(entry, bridge);
}
} }
} }
} }
......
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