[7/8] net/mlx5: sort port spawn data with uplink ports first

Message ID 20231031142733.2009166-8-dsosnowski@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: add Multiport E-Switch support |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Dariusz Sosnowski Oct. 31, 2023, 2:27 p.m. UTC
  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 <dsosnowski@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_os.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Patch

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;