[PATCH rdma-next] IB/mlx5: Fix port speed query for representors

Edward Srouji posted 1 patch 3 weeks, 4 days ago
There is a newer version of this series
drivers/infiniband/hw/mlx5/main.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
[PATCH rdma-next] IB/mlx5: Fix port speed query for representors
Posted by Edward Srouji 3 weeks, 4 days ago
From: Or Har-Toov <ohartoov@nvidia.com>

When querying speed information for a representor in switchdev mode,
the code previously used the first device in the eswitch, which may not
match the device that actually owns the representor. In setups such as
multi-port eswitch or LAG, this led to incorrect port attributes being
reported.

Fix this by retrieving the correct core device from the representor's
eswitch before querying its port attributes.

Fixes: 27f9e0ccb6da ("net/mlx5: Lag, Add single RDMA device in multiport mode")
Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Edward Srouji <edwards@nvidia.com>
---
 drivers/infiniband/hw/mlx5/main.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index e81080622283..d0c6648ee035 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -561,12 +561,23 @@ static int mlx5_query_port_roce(struct ib_device *device, u32 port_num,
 	 * of an error it will still be zeroed out.
 	 * Use native port in case of reps
 	 */
-	if (dev->is_rep)
-		err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN,
-					   1, 0);
-	else
-		err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN,
-					   mdev_port_num, 0);
+	if (dev->is_rep) {
+		struct mlx5_eswitch_rep *rep;
+		struct mlx5_core_dev *esw_mdev;
+
+		rep = dev->port[port_num - 1].rep;
+		if (rep) {
+			esw_mdev = mlx5_eswitch_get_core_dev(rep->esw);
+			if (esw_mdev)
+				mdev = esw_mdev;
+		}
+
+		mdev_port_num = 1;
+	}
+
+	err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN,
+				   mdev_port_num, 0);
+
 	if (err)
 		goto out;
 	ext = !!MLX5_GET_ETH_PROTO(ptys_reg, out, true, eth_proto_capability);

---
base-commit: 325e3b5431ddd27c5f93156b36838a351e3b2f72
change-id: 20260113-port-speed-query-fix-592efa2b4e36

Best regards,
-- 
Edward Srouji <edwards@nvidia.com>
Re: [PATCH rdma-next] IB/mlx5: Fix port speed query for representors
Posted by Leon Romanovsky 3 weeks, 4 days ago
On Tue, Jan 13, 2026 at 03:31:26PM +0200, Edward Srouji wrote:
> From: Or Har-Toov <ohartoov@nvidia.com>
> 
> When querying speed information for a representor in switchdev mode,
> the code previously used the first device in the eswitch, which may not
> match the device that actually owns the representor. In setups such as
> multi-port eswitch or LAG, this led to incorrect port attributes being
> reported.
> 
> Fix this by retrieving the correct core device from the representor's
> eswitch before querying its port attributes.
> 
> Fixes: 27f9e0ccb6da ("net/mlx5: Lag, Add single RDMA device in multiport mode")
> Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
> Reviewed-by: Mark Bloch <mbloch@nvidia.com>
> Signed-off-by: Edward Srouji <edwards@nvidia.com>
> ---
>  drivers/infiniband/hw/mlx5/main.c | 23 +++++++++++++++++------
>  1 file changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
> index e81080622283..d0c6648ee035 100644
> --- a/drivers/infiniband/hw/mlx5/main.c
> +++ b/drivers/infiniband/hw/mlx5/main.c
> @@ -561,12 +561,23 @@ static int mlx5_query_port_roce(struct ib_device *device, u32 port_num,
>  	 * of an error it will still be zeroed out.
>  	 * Use native port in case of reps
>  	 */
> -	if (dev->is_rep)
> -		err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN,
> -					   1, 0);
> -	else
> -		err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN,
> -					   mdev_port_num, 0);
> +	if (dev->is_rep) {
> +		struct mlx5_eswitch_rep *rep;
> +		struct mlx5_core_dev *esw_mdev;
> +
> +		rep = dev->port[port_num - 1].rep;
> +		if (rep) {
> +			esw_mdev = mlx5_eswitch_get_core_dev(rep->esw);
> +			if (esw_mdev)

When can this esw_mdev be NULL? We are in representor code, so
mlx5_esw_allowed() should evaluate to true in mlx5_eswitch_get_core_dev().
Is there any scenario where it wouldn't?

> +				mdev = esw_mdev;
> +		}
> +
> +		mdev_port_num = 1;
> +	}
> +
> +	err = mlx5_query_port_ptys(mdev, out, sizeof(out), MLX5_PTYS_EN,
> +				   mdev_port_num, 0);
> +
>  	if (err)
>  		goto out;
>  	ext = !!MLX5_GET_ETH_PROTO(ptys_reg, out, true, eth_proto_capability);
> 
> ---
> base-commit: 325e3b5431ddd27c5f93156b36838a351e3b2f72
> change-id: 20260113-port-speed-query-fix-592efa2b4e36
> 
> Best regards,
> -- 
> Edward Srouji <edwards@nvidia.com>
>