net/mlx5: Lag, filter non compatible devices
authorMark Bloch <mbloch@nvidia.com>
Sun, 27 Feb 2022 12:40:39 +0000 (12:40 +0000)
committerSaeed Mahameed <saeedm@nvidia.com>
Tue, 10 May 2022 05:54:01 +0000 (22:54 -0700)
When search for a peer lag device we can filter based on that
device's capabilities.

Downstream patch will be less strict when filtering compatible devices
and remove the limitation where we require exact MLX5_MAX_PORTS and
change it to a range.

Signed-off-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Maor Gottlieb <maorg@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/dev.c
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h

index ba6dad97e308da83cc4c304983a51134a4bc91c3..3e750b827a19e461619b71f649cd801ff692fc75 100644 (file)
@@ -555,12 +555,9 @@ static u32 mlx5_gen_pci_id(const struct mlx5_core_dev *dev)
                     PCI_SLOT(dev->pdev->devfn));
 }
 
-static int next_phys_dev(struct device *dev, const void *data)
+static int _next_phys_dev(struct mlx5_core_dev *mdev,
+                         const struct mlx5_core_dev *curr)
 {
-       struct mlx5_adev *madev = container_of(dev, struct mlx5_adev, adev.dev);
-       struct mlx5_core_dev *mdev = madev->mdev;
-       const struct mlx5_core_dev *curr = data;
-
        if (!mlx5_core_is_pf(mdev))
                return 0;
 
@@ -574,8 +571,29 @@ static int next_phys_dev(struct device *dev, const void *data)
        return 1;
 }
 
-/* Must be called with intf_mutex held */
-struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev)
+static int next_phys_dev(struct device *dev, const void *data)
+{
+       struct mlx5_adev *madev = container_of(dev, struct mlx5_adev, adev.dev);
+       struct mlx5_core_dev *mdev = madev->mdev;
+
+       return _next_phys_dev(mdev, data);
+}
+
+static int next_phys_dev_lag(struct device *dev, const void *data)
+{
+       struct mlx5_adev *madev = container_of(dev, struct mlx5_adev, adev.dev);
+       struct mlx5_core_dev *mdev = madev->mdev;
+
+       if (!MLX5_CAP_GEN(mdev, vport_group_manager) ||
+           !MLX5_CAP_GEN(mdev, lag_master) ||
+           MLX5_CAP_GEN(mdev, num_lag_ports) != MLX5_MAX_PORTS)
+               return 0;
+
+       return _next_phys_dev(mdev, data);
+}
+
+static struct mlx5_core_dev *mlx5_get_next_dev(struct mlx5_core_dev *dev,
+                                              int (*match)(struct device *dev, const void *data))
 {
        struct auxiliary_device *adev;
        struct mlx5_adev *madev;
@@ -583,7 +601,7 @@ struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev)
        if (!mlx5_core_is_pf(dev))
                return NULL;
 
-       adev = auxiliary_find_device(NULL, dev, &next_phys_dev);
+       adev = auxiliary_find_device(NULL, dev, match);
        if (!adev)
                return NULL;
 
@@ -592,6 +610,20 @@ struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev)
        return madev->mdev;
 }
 
+/* Must be called with intf_mutex held */
+struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev)
+{
+       lockdep_assert_held(&mlx5_intf_mutex);
+       return mlx5_get_next_dev(dev, &next_phys_dev);
+}
+
+/* Must be called with intf_mutex held */
+struct mlx5_core_dev *mlx5_get_next_phys_dev_lag(struct mlx5_core_dev *dev)
+{
+       lockdep_assert_held(&mlx5_intf_mutex);
+       return mlx5_get_next_dev(dev, &next_phys_dev_lag);
+}
+
 void mlx5_dev_list_lock(void)
 {
        mutex_lock(&mlx5_intf_mutex);
index fc32f3e05191a8517799ad9b91a4a577e23fa6b4..360cb1c4221eab26010f2e8a53080a4c9998821c 100644 (file)
@@ -913,12 +913,7 @@ static int __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev)
        struct mlx5_lag *ldev = NULL;
        struct mlx5_core_dev *tmp_dev;
 
-       if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
-           !MLX5_CAP_GEN(dev, lag_master) ||
-           MLX5_CAP_GEN(dev, num_lag_ports) != MLX5_MAX_PORTS)
-               return 0;
-
-       tmp_dev = mlx5_get_next_phys_dev(dev);
+       tmp_dev = mlx5_get_next_phys_dev_lag(dev);
        if (tmp_dev)
                ldev = tmp_dev->priv.lag;
 
@@ -968,6 +963,11 @@ void mlx5_lag_add_mdev(struct mlx5_core_dev *dev)
 {
        int err;
 
+       if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
+           !MLX5_CAP_GEN(dev, lag_master) ||
+           MLX5_CAP_GEN(dev, num_lag_ports) != MLX5_MAX_PORTS)
+               return;
+
 recheck:
        mlx5_dev_list_lock();
        err = __mlx5_lag_dev_add_mdev(dev);
index 9026be1d62232a309e5a7241f2b46ec037b3bdc0..484cb1e4fc7f649467f3bf83a04c8f7aa2b2648a 100644 (file)
@@ -210,6 +210,7 @@ void mlx5_detach_device(struct mlx5_core_dev *dev);
 int mlx5_register_device(struct mlx5_core_dev *dev);
 void mlx5_unregister_device(struct mlx5_core_dev *dev);
 struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev);
+struct mlx5_core_dev *mlx5_get_next_phys_dev_lag(struct mlx5_core_dev *dev);
 void mlx5_dev_list_lock(void);
 void mlx5_dev_list_unlock(void);
 int mlx5_dev_list_trylock(void);