]> www.infradead.org Git - users/willy/xarray.git/commitdiff
{rdma,net}/mlx5: export mlx5_vport_get_vhca_id
authorSaeed Mahameed <saeedm@nvidia.com>
Tue, 17 Jun 2025 00:28:20 +0000 (17:28 -0700)
committerSaeed Mahameed <saeedm@nvidia.com>
Fri, 15 Aug 2025 19:17:47 +0000 (12:17 -0700)
vhca id is already cached in the vport structure no need to query on
every mlx5 layer, use the mlx5_vport_get_vhca_id, where possible.

Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Alexei Lazar <alazar@nvidia.com>
Reviewed-by: Feng Liu <feliu@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
drivers/infiniband/hw/mlx5/std_types.c
drivers/net/ethernet/mellanox/mlx5/core/diag/reporter_vnic.c
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/cmd.c
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_cmd.c
drivers/net/ethernet/mellanox/mlx5/core/vport.c
include/linux/mlx5/vport.h

index bdb568411091c84939f0c29d110e9246b80651b6..2fcf553044e15eed6897cd9320f532ea5a0ef91b 100644 (file)
@@ -83,33 +83,14 @@ static int fill_vport_icm_addr(struct mlx5_core_dev *mdev, u16 vport,
 static int fill_vport_vhca_id(struct mlx5_core_dev *mdev, u16 vport,
                              struct mlx5_ib_uapi_query_port *info)
 {
-       size_t out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
-       u32 in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {};
-       void *out;
-       int err;
-
-       out = kzalloc(out_sz, GFP_KERNEL);
-       if (!out)
-               return -ENOMEM;
+       int err = mlx5_vport_get_vhca_id(mdev, vport, &info->vport_vhca_id);
 
-       MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
-       MLX5_SET(query_hca_cap_in, in, other_function, true);
-       MLX5_SET(query_hca_cap_in, in, function_id, vport);
-       MLX5_SET(query_hca_cap_in, in, op_mod,
-                MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE |
-                HCA_CAP_OPMOD_GET_CUR);
-
-       err = mlx5_cmd_exec(mdev, in, sizeof(in), out, out_sz);
        if (err)
-               goto out;
-
-       info->vport_vhca_id = MLX5_GET(query_hca_cap_out, out,
-                                      capability.cmd_hca_cap.vhca_id);
+               return err;
 
        info->flags |= MLX5_IB_UAPI_QUERY_PORT_VPORT_VHCA_ID;
-out:
-       kfree(out);
-       return err;
+
+       return 0;
 }
 
 static int fill_multiport_info(struct mlx5_ib_dev *dev, u32 port_num,
index 86253a89c24c9175c2de95d28ee78a691b380875..32bb769f182998f97a13605352ac22000d4d7d2c 100644 (file)
@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 /* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. */
 
+#include <linux/mlx5/vport.h>
+
 #include "reporter_vnic.h"
 #include "en_stats.h"
 #include "devlink.h"
index b6d53db27cd573da8c68816afc790adc39a3a1b8..81857c6f6bf7bb1751b21242a0febf17a04868eb 100644 (file)
@@ -447,8 +447,6 @@ int mlx5_vport_set_other_func_cap(struct mlx5_core_dev *dev, const void *hca_cap
 #define mlx5_vport_get_other_func_general_cap(dev, vport, out)         \
        mlx5_vport_get_other_func_cap(dev, vport, out, MLX5_CAP_GENERAL)
 
-int mlx5_vport_get_vhca_id(struct mlx5_core_dev *dev, u16 vport, u16 *vhca_id);
-
 static inline u32 mlx5_sriov_get_vf_total_msix(struct pci_dev *pdev)
 {
        struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
index 9c83753e459243cbaa1f70603dc05261a3bb7240..d447574d86fe2865a7cb3076d3640368e90adae8 100644 (file)
@@ -1199,22 +1199,28 @@ out:
 int mlx5hws_cmd_query_gvmi(struct mlx5_core_dev *mdev, bool other_function,
                           u16 vport_number, u16 *gvmi)
 {
-       bool ec_vf_func = other_function ? mlx5_core_is_ec_vf_vport(mdev, vport_number) : false;
        u32 in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {};
        int out_size;
        void *out;
        int err;
 
+       if (other_function) {
+               err = mlx5_vport_get_vhca_id(mdev, vport_number, gvmi);
+               if  (!err)
+                       return 0;
+
+               mlx5_core_err(mdev, "Failed to get vport vhca id for vport %d\n",
+                             vport_number);
+               return err;
+       }
+
+       /* get vhca_id for `this` function */
        out_size = MLX5_ST_SZ_BYTES(query_hca_cap_out);
        out = kzalloc(out_size, GFP_KERNEL);
        if (!out)
                return -ENOMEM;
 
        MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
-       MLX5_SET(query_hca_cap_in, in, other_function, other_function);
-       MLX5_SET(query_hca_cap_in, in, function_id,
-                mlx5_vport_to_func_id(mdev, vport_number, ec_vf_func));
-       MLX5_SET(query_hca_cap_in, in, ec_vf_function, ec_vf_func);
        MLX5_SET(query_hca_cap_in, in, op_mod,
                 MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE << 1 | HCA_CAP_OPMOD_GET_CUR);
 
index baefb9a3fa05ea6ec5eb7227936d3b6768225e54..bf99b933fd14bebefb2c96e52d7dff7c52382e2a 100644 (file)
@@ -2,6 +2,7 @@
 /* Copyright (c) 2019 Mellanox Technologies. */
 
 #include "dr_types.h"
+#include "eswitch.h"
 
 int mlx5dr_cmd_query_esw_vport_context(struct mlx5_core_dev *mdev,
                                       bool other_vport,
@@ -34,21 +35,28 @@ int mlx5dr_cmd_query_esw_vport_context(struct mlx5_core_dev *mdev,
 int mlx5dr_cmd_query_gvmi(struct mlx5_core_dev *mdev, bool other_vport,
                          u16 vport_number, u16 *gvmi)
 {
-       bool ec_vf_func = other_vport ? mlx5_core_is_ec_vf_vport(mdev, vport_number) : false;
        u32 in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {};
        int out_size;
        void *out;
        int err;
 
+       if (other_vport) {
+               err = mlx5_vport_get_vhca_id(mdev, vport_number, gvmi);
+               if  (!err)
+                       return 0;
+
+               mlx5_core_err(mdev, "Failed to get vport vhca id for vport %d\n",
+                             vport_number);
+               return err;
+       }
+
+       /* get vhca_id for `this` function */
        out_size = MLX5_ST_SZ_BYTES(query_hca_cap_out);
        out = kzalloc(out_size, GFP_KERNEL);
        if (!out)
                return -ENOMEM;
 
        MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
-       MLX5_SET(query_hca_cap_in, in, other_function, other_vport);
-       MLX5_SET(query_hca_cap_in, in, function_id, mlx5_vport_to_func_id(mdev, vport_number, ec_vf_func));
-       MLX5_SET(query_hca_cap_in, in, ec_vf_function, ec_vf_func);
        MLX5_SET(query_hca_cap_in, in, op_mod,
                 MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE << 1 |
                 HCA_CAP_OPMOD_GET_CUR);
index 231bedc6a252dcc273af2ae3b809268b2e692b04..2ed2e530b07d0f97bbfa7a4a3e66cae24799706e 100644 (file)
@@ -1239,7 +1239,9 @@ int mlx5_vport_get_vhca_id(struct mlx5_core_dev *dev, u16 vport, u16 *vhca_id)
        void *hca_caps;
        int err;
 
-       *vhca_id = 0;
+       /* try get vhca_id via eswitch */
+       if (mlx5_esw_vport_vhca_id(dev->priv.eswitch, vport, vhca_id))
+               return 0;
 
        query_ctx = kzalloc(query_out_sz, GFP_KERNEL);
        if (!query_ctx)
@@ -1256,6 +1258,7 @@ out_free:
        kfree(query_ctx);
        return err;
 }
+EXPORT_SYMBOL_GPL(mlx5_vport_get_vhca_id);
 
 int mlx5_vport_set_other_func_cap(struct mlx5_core_dev *dev, const void *hca_cap,
                                  u16 vport, u16 opmod)
index c36cc6d829267e8b795c5c1ea7f71c1e28dcdaed..c87b9507cfa180f59f7b0180ffdde00bf912782b 100644 (file)
@@ -135,4 +135,6 @@ int mlx5_nic_vport_unaffiliate_multiport(struct mlx5_core_dev *port_mdev);
 u64 mlx5_query_nic_system_image_guid(struct mlx5_core_dev *mdev);
 int mlx5_vport_get_other_func_cap(struct mlx5_core_dev *dev, u16 vport, void *out,
                                  u16 opmod);
+int mlx5_vport_get_vhca_id(struct mlx5_core_dev *dev, u16 vport, u16 *vhca_id);
+
 #endif /* __MLX5_VPORT_H__ */