mlxsw: spectrum_switchdev: Only query FDB notifications when necessary
authorIdo Schimmel <idosch@nvidia.com>
Wed, 4 May 2022 06:29:08 +0000 (09:29 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 4 May 2022 10:21:33 +0000 (11:21 +0100)
The driver periodically queries the device for FDB notifications (e.g.,
learned, aged-out) in order to update the bridge driver. These
notifications can only be generated when bridges are offloaded to the
device.

Avoid unnecessary queries by starting to query upon installation of the
first bridge and stop querying upon removal of the last bridge.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c

index 3bf12092a8a2a6d6e34355ed636559416fc403c1..a6d2e806cba93394f2d991041610252b96d1b5e9 100644 (file)
@@ -207,6 +207,16 @@ static void mlxsw_sp_bridge_device_vxlan_fini(struct mlxsw_sp_bridge *bridge,
        }
 }
 
+static void mlxsw_sp_fdb_notify_work_schedule(struct mlxsw_sp *mlxsw_sp,
+                                             bool no_delay)
+{
+       struct mlxsw_sp_bridge *bridge = mlxsw_sp->bridge;
+       unsigned int interval = no_delay ? 0 : bridge->fdb_notify.interval;
+
+       mlxsw_core_schedule_dw(&bridge->fdb_notify.dw,
+                              msecs_to_jiffies(interval));
+}
+
 static struct mlxsw_sp_bridge_device *
 mlxsw_sp_bridge_device_create(struct mlxsw_sp_bridge *bridge,
                              struct net_device *br_dev,
@@ -245,6 +255,8 @@ mlxsw_sp_bridge_device_create(struct mlxsw_sp_bridge *bridge,
                bridge_device->ops = bridge->bridge_8021d_ops;
        }
        INIT_LIST_HEAD(&bridge_device->mids_list);
+       if (list_empty(&bridge->bridges_list))
+               mlxsw_sp_fdb_notify_work_schedule(bridge->mlxsw_sp, false);
        list_add(&bridge_device->list, &bridge->bridges_list);
 
        /* It is possible we already have VXLAN devices enslaved to the bridge.
@@ -273,6 +285,8 @@ mlxsw_sp_bridge_device_destroy(struct mlxsw_sp_bridge *bridge,
        mlxsw_sp_bridge_device_rifs_destroy(bridge->mlxsw_sp,
                                            bridge_device->dev);
        list_del(&bridge_device->list);
+       if (list_empty(&bridge->bridges_list))
+               cancel_delayed_work(&bridge->fdb_notify.dw);
        if (bridge_device->vlan_enabled)
                bridge->vlan_enabled_exists = false;
        WARN_ON(!list_empty(&bridge_device->ports_list));
@@ -2886,22 +2900,13 @@ static void mlxsw_sp_fdb_notify_rec_process(struct mlxsw_sp *mlxsw_sp,
        }
 }
 
-static void mlxsw_sp_fdb_notify_work_schedule(struct mlxsw_sp *mlxsw_sp,
-                                             bool no_delay)
-{
-       struct mlxsw_sp_bridge *bridge = mlxsw_sp->bridge;
-       unsigned int interval = no_delay ? 0 : bridge->fdb_notify.interval;
-
-       mlxsw_core_schedule_dw(&bridge->fdb_notify.dw,
-                              msecs_to_jiffies(interval));
-}
-
 #define MLXSW_SP_FDB_SFN_QUERIES_PER_SESSION 10
 
 static void mlxsw_sp_fdb_notify_work(struct work_struct *work)
 {
        struct mlxsw_sp_bridge *bridge;
        struct mlxsw_sp *mlxsw_sp;
+       bool reschedule = false;
        char *sfn_pl;
        int queries;
        u8 num_rec;
@@ -2916,6 +2921,9 @@ static void mlxsw_sp_fdb_notify_work(struct work_struct *work)
        mlxsw_sp = bridge->mlxsw_sp;
 
        rtnl_lock();
+       if (list_empty(&bridge->bridges_list))
+               goto out;
+       reschedule = true;
        queries = MLXSW_SP_FDB_SFN_QUERIES_PER_SESSION;
        while (queries > 0) {
                mlxsw_reg_sfn_pack(sfn_pl);
@@ -2935,6 +2943,8 @@ static void mlxsw_sp_fdb_notify_work(struct work_struct *work)
 out:
        rtnl_unlock();
        kfree(sfn_pl);
+       if (!reschedule)
+               return;
        mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp, !queries);
 }
 
@@ -3665,7 +3675,6 @@ static int mlxsw_sp_fdb_init(struct mlxsw_sp *mlxsw_sp)
 
        INIT_DELAYED_WORK(&bridge->fdb_notify.dw, mlxsw_sp_fdb_notify_work);
        bridge->fdb_notify.interval = MLXSW_SP_DEFAULT_LEARNING_INTERVAL;
-       mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp, false);
        return 0;
 
 err_register_switchdev_blocking_notifier: