net/mlx5e: Propagate an internal event in case uplink netdev changes
authorJiri Pirko <jiri@nvidia.com>
Tue, 1 Nov 2022 14:27:43 +0000 (15:27 +0100)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 9 Feb 2023 04:40:57 +0000 (20:40 -0800)
Whenever uplink netdev is set/cleared, propagate newly introduced event
to inform notifier blocks netdev was added/removed.

Move the set() helper to core.c from header, introduce clear() and
netdev_added_event_replay() helpers. The last one is going to be called
from rdma driver, so export it.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/lib/mlx5.h
drivers/net/ethernet/mellanox/mlx5/core/main.c
include/linux/mlx5/device.h
include/linux/mlx5/driver.h

index 7471c4e8004cd8a726d821e7659c6790eaf22a9c..85b51039d2a6db233865f267c3bcd5d4cc040605 100644 (file)
@@ -5961,7 +5961,7 @@ static int mlx5e_probe(struct auxiliary_device *adev,
        }
 
        mlx5e_dcbnl_init_app(priv);
-       mlx5_uplink_netdev_set(mdev, netdev);
+       mlx5_core_uplink_netdev_set(mdev, netdev);
        mlx5e_params_print_info(mdev, &priv->channels.params);
        return 0;
 
@@ -5981,6 +5981,7 @@ static void mlx5e_remove(struct auxiliary_device *adev)
        struct mlx5e_priv *priv = auxiliary_get_drvdata(adev);
        pm_message_t state = {};
 
+       mlx5_core_uplink_netdev_set(priv->mdev, NULL);
        mlx5e_dcbnl_delete_app(priv);
        unregister_netdev(priv->netdev);
        mlx5e_suspend(adev, state);
index 032adb21ad4b663cd669dea857b8f7cff088fad2..bfd3a1121ed8dc14e37ec28dce8cbc86a07ffc24 100644 (file)
@@ -96,11 +96,6 @@ static inline struct net *mlx5_core_net(struct mlx5_core_dev *dev)
        return devlink_net(priv_to_devlink(dev));
 }
 
-static inline void mlx5_uplink_netdev_set(struct mlx5_core_dev *mdev, struct net_device *netdev)
-{
-       mdev->mlx5e_res.uplink_netdev = netdev;
-}
-
 static inline struct net_device *mlx5_uplink_netdev_get(struct mlx5_core_dev *mdev)
 {
        return mdev->mlx5e_res.uplink_netdev;
index df134f6d32dc583a93f96f24cef5ccfc1a4cfd23..72716d1f8b37c14438cf4125ba411f34240ecbc0 100644 (file)
@@ -336,6 +336,24 @@ static u16 to_fw_pkey_sz(struct mlx5_core_dev *dev, u32 size)
        }
 }
 
+void mlx5_core_uplink_netdev_set(struct mlx5_core_dev *dev, struct net_device *netdev)
+{
+       mutex_lock(&dev->mlx5e_res.uplink_netdev_lock);
+       dev->mlx5e_res.uplink_netdev = netdev;
+       mlx5_blocking_notifier_call_chain(dev, MLX5_DRIVER_EVENT_UPLINK_NETDEV,
+                                         netdev);
+       mutex_unlock(&dev->mlx5e_res.uplink_netdev_lock);
+}
+
+void mlx5_core_uplink_netdev_event_replay(struct mlx5_core_dev *dev)
+{
+       mutex_lock(&dev->mlx5e_res.uplink_netdev_lock);
+       mlx5_blocking_notifier_call_chain(dev, MLX5_DRIVER_EVENT_UPLINK_NETDEV,
+                                         dev->mlx5e_res.uplink_netdev);
+       mutex_unlock(&dev->mlx5e_res.uplink_netdev_lock);
+}
+EXPORT_SYMBOL(mlx5_core_uplink_netdev_event_replay);
+
 static int mlx5_core_get_caps_mode(struct mlx5_core_dev *dev,
                                   enum mlx5_cap_type cap_type,
                                   enum mlx5_cap_mode cap_mode)
@@ -1608,6 +1626,7 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
        lockdep_register_key(&dev->lock_key);
        mutex_init(&dev->intf_state_mutex);
        lockdep_set_class(&dev->intf_state_mutex, &dev->lock_key);
+       mutex_init(&dev->mlx5e_res.uplink_netdev_lock);
 
        mutex_init(&priv->bfregs.reg_head.lock);
        mutex_init(&priv->bfregs.wc_head.lock);
@@ -1696,6 +1715,7 @@ void mlx5_mdev_uninit(struct mlx5_core_dev *dev)
        mutex_destroy(&priv->alloc_mutex);
        mutex_destroy(&priv->bfregs.wc_head.lock);
        mutex_destroy(&priv->bfregs.reg_head.lock);
+       mutex_destroy(&dev->mlx5e_res.uplink_netdev_lock);
        mutex_destroy(&dev->intf_state_mutex);
        lockdep_unregister_key(&dev->lock_key);
 }
index 29d4b201c7b26dd8d6a6a698bbc4f9d042ae1206..f2b271169dafee30015043800139cec1dfc4658a 100644 (file)
@@ -362,6 +362,7 @@ enum mlx5_event {
 
 enum mlx5_driver_event {
        MLX5_DRIVER_EVENT_TYPE_TRAP = 0,
+       MLX5_DRIVER_EVENT_UPLINK_NETDEV,
 };
 
 enum {
index d476255c9a3f0d9ea7f0dcd3c8231fbcd9e30d3e..cc48aa30826965c3edd3da4a8661528190153252 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/notifier.h>
 #include <linux/refcount.h>
 #include <linux/auxiliary_bus.h>
+#include <linux/mutex.h>
 
 #include <linux/mlx5/device.h>
 #include <linux/mlx5/doorbell.h>
@@ -674,6 +675,7 @@ struct mlx5e_resources {
        } hw_objs;
        struct devlink_port dl_port;
        struct net_device *uplink_netdev;
+       struct mutex uplink_netdev_lock;
 };
 
 enum mlx5_sw_icm_type {
@@ -1011,6 +1013,9 @@ int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
                          void *out, int out_size);
 bool mlx5_cmd_is_down(struct mlx5_core_dev *dev);
 
+void mlx5_core_uplink_netdev_set(struct mlx5_core_dev *mdev, struct net_device *netdev);
+void mlx5_core_uplink_netdev_event_replay(struct mlx5_core_dev *mdev);
+
 int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
 void mlx5_health_cleanup(struct mlx5_core_dev *dev);
 int mlx5_health_init(struct mlx5_core_dev *dev);