]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mlxsw: spectrum_switchdev: Add support for getting and putting MDB entry
authorAmit Cohen <amcohen@nvidia.com>
Wed, 29 Jun 2022 09:40:05 +0000 (12:40 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 29 Jun 2022 12:35:46 +0000 (13:35 +0100)
A previous patch added support for init() and fini() for MDB entries. MDB
entry can be updated, ports can be added and removed from the entry. Add
get() and put() functions, the first one checks if the entry already exists
and otherwise initializes the entry. The second removes the entry just in
case that there are no more ports in this entry.

Use the list of the ports which was added in a previous patch. When the
list contains only one port which is not multicast router, and this port
is removed, the MDB entry can be removed. Use
'struct mlxsw_sp_mdb_entry.ports_count' to know how many ports use the
entry, regardless the use of multicast router ports.

When mlxsw_sp_mc_mdb_entry_put() is called with specific port which
supposed to be removed, check if the removal will cause a deletion of
the entry. If this is the case, call mlxsw_sp_mc_mdb_entry_fini() which
first deletes the MDB entry and then releases the PGT entry, to avoid a
temporary situation in which the MDB entry points to an empty PGT entry,
as otherwise packets will be temporarily dropped instead of being flooded.

The new functions will be used in the next patches.

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 bb2694ef6220b2cd84957263cf62bc11d36b7727..5f8136a8db13bef7322517e622021df4c4e1a18d 100644 (file)
@@ -2131,7 +2131,7 @@ mlxsw_sp_mc_mdb_mrouters_set(struct mlxsw_sp *mlxsw_sp,
        return err;
 }
 
-static __always_unused struct mlxsw_sp_mdb_entry *
+static struct mlxsw_sp_mdb_entry *
 mlxsw_sp_mc_mdb_entry_init(struct mlxsw_sp *mlxsw_sp,
                           struct mlxsw_sp_bridge_device *bridge_device,
                           const unsigned char *addr, u16 fid, u16 local_port)
@@ -2194,7 +2194,7 @@ err_pgt_mid_alloc:
        return ERR_PTR(err);
 }
 
-static __always_unused void
+static void
 mlxsw_sp_mc_mdb_entry_fini(struct mlxsw_sp *mlxsw_sp,
                           struct mlxsw_sp_mdb_entry *mdb_entry,
                           struct mlxsw_sp_bridge_device *bridge_device,
@@ -2212,6 +2212,82 @@ mlxsw_sp_mc_mdb_entry_fini(struct mlxsw_sp *mlxsw_sp,
        kfree(mdb_entry);
 }
 
+static __always_unused struct mlxsw_sp_mdb_entry *
+mlxsw_sp_mc_mdb_entry_get(struct mlxsw_sp *mlxsw_sp,
+                         struct mlxsw_sp_bridge_device *bridge_device,
+                         const unsigned char *addr, u16 fid, u16 local_port)
+{
+       struct mlxsw_sp_mdb_entry_key key = {};
+       struct mlxsw_sp_mdb_entry *mdb_entry;
+
+       ether_addr_copy(key.addr, addr);
+       key.fid = fid;
+       mdb_entry = rhashtable_lookup_fast(&bridge_device->mdb_ht, &key,
+                                          mlxsw_sp_mdb_ht_params);
+       if (mdb_entry) {
+               struct mlxsw_sp_mdb_entry_port *mdb_entry_port;
+
+               mdb_entry_port = mlxsw_sp_mdb_entry_port_get(mlxsw_sp,
+                                                            mdb_entry,
+                                                            local_port);
+               if (IS_ERR(mdb_entry_port))
+                       return ERR_CAST(mdb_entry_port);
+
+               return mdb_entry;
+       }
+
+       return mlxsw_sp_mc_mdb_entry_init(mlxsw_sp, bridge_device, addr, fid,
+                                         local_port);
+}
+
+static bool
+mlxsw_sp_mc_mdb_entry_remove(struct mlxsw_sp_mdb_entry *mdb_entry,
+                            struct mlxsw_sp_mdb_entry_port *removed_entry_port,
+                            bool force)
+{
+       if (mdb_entry->ports_count > 1)
+               return false;
+
+       if (force)
+               return true;
+
+       if (!removed_entry_port->mrouter &&
+           refcount_read(&removed_entry_port->refcount) > 1)
+               return false;
+
+       if (removed_entry_port->mrouter &&
+           refcount_read(&removed_entry_port->refcount) > 2)
+               return false;
+
+       return true;
+}
+
+static __always_unused void
+mlxsw_sp_mc_mdb_entry_put(struct mlxsw_sp *mlxsw_sp,
+                         struct mlxsw_sp_bridge_device *bridge_device,
+                         struct mlxsw_sp_mdb_entry *mdb_entry, u16 local_port,
+                         bool force)
+{
+       struct mlxsw_sp_mdb_entry_port *mdb_entry_port;
+
+       mdb_entry_port = mlxsw_sp_mdb_entry_port_lookup(mdb_entry, local_port);
+       if (!mdb_entry_port)
+               return;
+
+       /* Avoid a temporary situation in which the MDB entry points to an empty
+        * PGT entry, as otherwise packets will be temporarily dropped instead
+        * of being flooded. Instead, in this situation, call
+        * mlxsw_sp_mc_mdb_entry_fini(), which first deletes the MDB entry and
+        * then releases the PGT entry.
+        */
+       if (mlxsw_sp_mc_mdb_entry_remove(mdb_entry, mdb_entry_port, force))
+               mlxsw_sp_mc_mdb_entry_fini(mlxsw_sp, mdb_entry, bridge_device,
+                                          local_port, force);
+       else
+               mlxsw_sp_mdb_entry_port_put(mlxsw_sp, mdb_entry, local_port,
+                                           force);
+}
+
 static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
                                 const struct switchdev_obj_port_mdb *mdb)
 {