Skip to content

Commit bc4c2f2

Browse files
mark-blochSaeed Mahameed
authored andcommitted
net/mlx5: Lag, filter non compatible devices
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 <[email protected]> Reviewed-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent ec2fa47 commit bc4c2f2

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

drivers/net/ethernet/mellanox/mlx5/core/dev.c

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,9 @@ static u32 mlx5_gen_pci_id(const struct mlx5_core_dev *dev)
555555
PCI_SLOT(dev->pdev->devfn));
556556
}
557557

558-
static int next_phys_dev(struct device *dev, const void *data)
558+
static int _next_phys_dev(struct mlx5_core_dev *mdev,
559+
const struct mlx5_core_dev *curr)
559560
{
560-
struct mlx5_adev *madev = container_of(dev, struct mlx5_adev, adev.dev);
561-
struct mlx5_core_dev *mdev = madev->mdev;
562-
const struct mlx5_core_dev *curr = data;
563-
564561
if (!mlx5_core_is_pf(mdev))
565562
return 0;
566563

@@ -574,16 +571,37 @@ static int next_phys_dev(struct device *dev, const void *data)
574571
return 1;
575572
}
576573

577-
/* Must be called with intf_mutex held */
578-
struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev)
574+
static int next_phys_dev(struct device *dev, const void *data)
575+
{
576+
struct mlx5_adev *madev = container_of(dev, struct mlx5_adev, adev.dev);
577+
struct mlx5_core_dev *mdev = madev->mdev;
578+
579+
return _next_phys_dev(mdev, data);
580+
}
581+
582+
static int next_phys_dev_lag(struct device *dev, const void *data)
583+
{
584+
struct mlx5_adev *madev = container_of(dev, struct mlx5_adev, adev.dev);
585+
struct mlx5_core_dev *mdev = madev->mdev;
586+
587+
if (!MLX5_CAP_GEN(mdev, vport_group_manager) ||
588+
!MLX5_CAP_GEN(mdev, lag_master) ||
589+
MLX5_CAP_GEN(mdev, num_lag_ports) != MLX5_MAX_PORTS)
590+
return 0;
591+
592+
return _next_phys_dev(mdev, data);
593+
}
594+
595+
static struct mlx5_core_dev *mlx5_get_next_dev(struct mlx5_core_dev *dev,
596+
int (*match)(struct device *dev, const void *data))
579597
{
580598
struct auxiliary_device *adev;
581599
struct mlx5_adev *madev;
582600

583601
if (!mlx5_core_is_pf(dev))
584602
return NULL;
585603

586-
adev = auxiliary_find_device(NULL, dev, &next_phys_dev);
604+
adev = auxiliary_find_device(NULL, dev, match);
587605
if (!adev)
588606
return NULL;
589607

@@ -592,6 +610,20 @@ struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev)
592610
return madev->mdev;
593611
}
594612

613+
/* Must be called with intf_mutex held */
614+
struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev)
615+
{
616+
lockdep_assert_held(&mlx5_intf_mutex);
617+
return mlx5_get_next_dev(dev, &next_phys_dev);
618+
}
619+
620+
/* Must be called with intf_mutex held */
621+
struct mlx5_core_dev *mlx5_get_next_phys_dev_lag(struct mlx5_core_dev *dev)
622+
{
623+
lockdep_assert_held(&mlx5_intf_mutex);
624+
return mlx5_get_next_dev(dev, &next_phys_dev_lag);
625+
}
626+
595627
void mlx5_dev_list_lock(void)
596628
{
597629
mutex_lock(&mlx5_intf_mutex);

drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -913,12 +913,7 @@ static int __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev)
913913
struct mlx5_lag *ldev = NULL;
914914
struct mlx5_core_dev *tmp_dev;
915915

916-
if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
917-
!MLX5_CAP_GEN(dev, lag_master) ||
918-
MLX5_CAP_GEN(dev, num_lag_ports) != MLX5_MAX_PORTS)
919-
return 0;
920-
921-
tmp_dev = mlx5_get_next_phys_dev(dev);
916+
tmp_dev = mlx5_get_next_phys_dev_lag(dev);
922917
if (tmp_dev)
923918
ldev = tmp_dev->priv.lag;
924919

@@ -968,6 +963,11 @@ void mlx5_lag_add_mdev(struct mlx5_core_dev *dev)
968963
{
969964
int err;
970965

966+
if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
967+
!MLX5_CAP_GEN(dev, lag_master) ||
968+
MLX5_CAP_GEN(dev, num_lag_ports) != MLX5_MAX_PORTS)
969+
return;
970+
971971
recheck:
972972
mlx5_dev_list_lock();
973973
err = __mlx5_lag_dev_add_mdev(dev);

drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ void mlx5_detach_device(struct mlx5_core_dev *dev);
210210
int mlx5_register_device(struct mlx5_core_dev *dev);
211211
void mlx5_unregister_device(struct mlx5_core_dev *dev);
212212
struct mlx5_core_dev *mlx5_get_next_phys_dev(struct mlx5_core_dev *dev);
213+
struct mlx5_core_dev *mlx5_get_next_phys_dev_lag(struct mlx5_core_dev *dev);
213214
void mlx5_dev_list_lock(void);
214215
void mlx5_dev_list_unlock(void);
215216
int mlx5_dev_list_trylock(void);

0 commit comments

Comments
 (0)