This patch changes the behavior of the comparator used to sort mlx5_dev_spawn_data structures, to put them in a more user friendly order
Before this patch, ports were sorted assuming there is only a single master port. It resulted in an order where master port first comes second, then representors in ascending order of IDs. This approach however is not desirable with devices configured for Multiport E-Switch, since uplink ports which do not correspond to the owning PCI device are representors as well and they will be mixed with VF/SF representors. To change that, this patch amends the comparator to force uplink ports to be first. If there are many uplink ports, the master port will come first and the rest will be sorted by port index. Signed-off-by: Dariusz Sosnowski <dsosnow...@nvidia.com> Acked-by: Viacheslav Ovsiienko <viachesl...@nvidia.com> --- drivers/net/mlx5/linux/mlx5_os.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 8ddf38288e..07f31de5ae 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -1797,9 +1797,15 @@ mlx5_dev_spawn_data_cmp(const void *a, const void *b) &((const struct mlx5_dev_spawn_data *)a)->info; const struct mlx5_switch_info *si_b = &((const struct mlx5_dev_spawn_data *)b)->info; + int uplink_a = si_a->name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK; + int uplink_b = si_b->name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK; int ret; - /* Master device first. */ + /* Uplink ports first. */ + ret = uplink_b - uplink_a; + if (ret) + return ret; + /* Then master devices. */ ret = si_b->master - si_a->master; if (ret) return ret; -- 2.25.1