]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mlxsw: spectrum_switchdev: Add support for maintaining hash table of MDB entries
authorAmit Cohen <amcohen@nvidia.com>
Wed, 29 Jun 2022 09:40:02 +0000 (12:40 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 29 Jun 2022 12:35:46 +0000 (13:35 +0100)
Currently MDB entries are stored in a list as part of
'struct mlxsw_sp_bridge_device'. Storing them in a hash table in
addition to the list will allow finding a specific entry more efficiently.

Add support for the required hash table, the next patches will insert
and remove MDB entries from the table. The existing code which adds and
removes entries will be removed and replaced by new code in the next
patches, so there is no point to adjust the existing code.

Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c

index d1a1d55b0068e681c2d4132e880dee64f012d062..617ec3312fd8a5d6cce57a5117013cd5cdcf0c15 100644 (file)
@@ -49,6 +49,7 @@ struct mlxsw_sp_bridge_device {
        struct list_head list;
        struct list_head ports_list;
        struct list_head mdb_list;
+       struct rhashtable mdb_ht;
        u8 vlan_enabled:1,
           multicast_enabled:1,
           mrouter:1;
@@ -109,12 +110,19 @@ struct mlxsw_sp_mdb_entry_key {
 
 struct mlxsw_sp_mdb_entry {
        struct list_head list;
+       struct rhash_head ht_node;
        struct mlxsw_sp_mdb_entry_key key;
        u16 mid;
        bool in_hw;
        unsigned long *ports_in_mid; /* bits array */
 };
 
+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),
+       .key_len = sizeof(struct mlxsw_sp_mdb_entry_key),
+};
+
 static int
 mlxsw_sp_bridge_port_fdb_flush(struct mlxsw_sp *mlxsw_sp,
                               struct mlxsw_sp_bridge_port *bridge_port,
@@ -250,6 +258,10 @@ mlxsw_sp_bridge_device_create(struct mlxsw_sp_bridge *bridge,
        if (!bridge_device)
                return ERR_PTR(-ENOMEM);
 
+       err = rhashtable_init(&bridge_device->mdb_ht, &mlxsw_sp_mdb_ht_params);
+       if (err)
+               goto err_mdb_rhashtable_init;
+
        bridge_device->dev = br_dev;
        bridge_device->vlan_enabled = vlan_enabled;
        bridge_device->multicast_enabled = br_multicast_enabled(br_dev);
@@ -287,6 +299,8 @@ err_vxlan_init:
        list_del(&bridge_device->list);
        if (bridge_device->vlan_enabled)
                bridge->vlan_enabled_exists = false;
+       rhashtable_destroy(&bridge_device->mdb_ht);
+err_mdb_rhashtable_init:
        kfree(bridge_device);
        return ERR_PTR(err);
 }
@@ -305,6 +319,7 @@ mlxsw_sp_bridge_device_destroy(struct mlxsw_sp_bridge *bridge,
                bridge->vlan_enabled_exists = false;
        WARN_ON(!list_empty(&bridge_device->ports_list));
        WARN_ON(!list_empty(&bridge_device->mdb_list));
+       rhashtable_destroy(&bridge_device->mdb_ht);
        kfree(bridge_device);
 }