Skip to content

Commit 40653f2

Browse files
author
Saeed Mahameed
committed
{rdma,net}/mlx5: export mlx5_vport_get_vhca_id
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>
1 parent 1baf304 commit 40653f2

7 files changed

Lines changed: 35 additions & 35 deletions

File tree

drivers/infiniband/hw/mlx5/std_types.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,14 @@ static int fill_vport_icm_addr(struct mlx5_core_dev *mdev, u16 vport,
8383
static int fill_vport_vhca_id(struct mlx5_core_dev *mdev, u16 vport,
8484
struct mlx5_ib_uapi_query_port *info)
8585
{
86-
size_t out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
87-
u32 in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {};
88-
void *out;
89-
int err;
90-
91-
out = kzalloc(out_sz, GFP_KERNEL);
92-
if (!out)
93-
return -ENOMEM;
86+
int err = mlx5_vport_get_vhca_id(mdev, vport, &info->vport_vhca_id);
9487

95-
MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
96-
MLX5_SET(query_hca_cap_in, in, other_function, true);
97-
MLX5_SET(query_hca_cap_in, in, function_id, vport);
98-
MLX5_SET(query_hca_cap_in, in, op_mod,
99-
MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE |
100-
HCA_CAP_OPMOD_GET_CUR);
101-
102-
err = mlx5_cmd_exec(mdev, in, sizeof(in), out, out_sz);
10388
if (err)
104-
goto out;
105-
106-
info->vport_vhca_id = MLX5_GET(query_hca_cap_out, out,
107-
capability.cmd_hca_cap.vhca_id);
89+
return err;
10890

10991
info->flags |= MLX5_IB_UAPI_QUERY_PORT_VPORT_VHCA_ID;
110-
out:
111-
kfree(out);
112-
return err;
92+
93+
return 0;
11394
}
11495

11596
static int fill_multiport_info(struct mlx5_ib_dev *dev, u32 port_num,

drivers/net/ethernet/mellanox/mlx5/core/diag/reporter_vnic.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
22
/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. */
33

4+
#include <linux/mlx5/vport.h>
5+
46
#include "reporter_vnic.h"
57
#include "en_stats.h"
68
#include "devlink.h"

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,6 @@ int mlx5_vport_set_other_func_cap(struct mlx5_core_dev *dev, const void *hca_cap
447447
#define mlx5_vport_get_other_func_general_cap(dev, vport, out) \
448448
mlx5_vport_get_other_func_cap(dev, vport, out, MLX5_CAP_GENERAL)
449449

450-
int mlx5_vport_get_vhca_id(struct mlx5_core_dev *dev, u16 vport, u16 *vhca_id);
451-
452450
static inline u32 mlx5_sriov_get_vf_total_msix(struct pci_dev *pdev)
453451
{
454452
struct mlx5_core_dev *dev = pci_get_drvdata(pdev);

drivers/net/ethernet/mellanox/mlx5/core/steering/hws/cmd.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,22 +1199,28 @@ int mlx5hws_cmd_query_caps(struct mlx5_core_dev *mdev,
11991199
int mlx5hws_cmd_query_gvmi(struct mlx5_core_dev *mdev, bool other_function,
12001200
u16 vport_number, u16 *gvmi)
12011201
{
1202-
bool ec_vf_func = other_function ? mlx5_core_is_ec_vf_vport(mdev, vport_number) : false;
12031202
u32 in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {};
12041203
int out_size;
12051204
void *out;
12061205
int err;
12071206

1207+
if (other_function) {
1208+
err = mlx5_vport_get_vhca_id(mdev, vport_number, gvmi);
1209+
if (!err)
1210+
return 0;
1211+
1212+
mlx5_core_err(mdev, "Failed to get vport vhca id for vport %d\n",
1213+
vport_number);
1214+
return err;
1215+
}
1216+
1217+
/* get vhca_id for `this` function */
12081218
out_size = MLX5_ST_SZ_BYTES(query_hca_cap_out);
12091219
out = kzalloc(out_size, GFP_KERNEL);
12101220
if (!out)
12111221
return -ENOMEM;
12121222

12131223
MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
1214-
MLX5_SET(query_hca_cap_in, in, other_function, other_function);
1215-
MLX5_SET(query_hca_cap_in, in, function_id,
1216-
mlx5_vport_to_func_id(mdev, vport_number, ec_vf_func));
1217-
MLX5_SET(query_hca_cap_in, in, ec_vf_function, ec_vf_func);
12181224
MLX5_SET(query_hca_cap_in, in, op_mod,
12191225
MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE << 1 | HCA_CAP_OPMOD_GET_CUR);
12201226

drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_cmd.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Copyright (c) 2019 Mellanox Technologies. */
33

44
#include "dr_types.h"
5+
#include "eswitch.h"
56

67
int mlx5dr_cmd_query_esw_vport_context(struct mlx5_core_dev *mdev,
78
bool other_vport,
@@ -34,21 +35,28 @@ int mlx5dr_cmd_query_esw_vport_context(struct mlx5_core_dev *mdev,
3435
int mlx5dr_cmd_query_gvmi(struct mlx5_core_dev *mdev, bool other_vport,
3536
u16 vport_number, u16 *gvmi)
3637
{
37-
bool ec_vf_func = other_vport ? mlx5_core_is_ec_vf_vport(mdev, vport_number) : false;
3838
u32 in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {};
3939
int out_size;
4040
void *out;
4141
int err;
4242

43+
if (other_vport) {
44+
err = mlx5_vport_get_vhca_id(mdev, vport_number, gvmi);
45+
if (!err)
46+
return 0;
47+
48+
mlx5_core_err(mdev, "Failed to get vport vhca id for vport %d\n",
49+
vport_number);
50+
return err;
51+
}
52+
53+
/* get vhca_id for `this` function */
4354
out_size = MLX5_ST_SZ_BYTES(query_hca_cap_out);
4455
out = kzalloc(out_size, GFP_KERNEL);
4556
if (!out)
4657
return -ENOMEM;
4758

4859
MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
49-
MLX5_SET(query_hca_cap_in, in, other_function, other_vport);
50-
MLX5_SET(query_hca_cap_in, in, function_id, mlx5_vport_to_func_id(mdev, vport_number, ec_vf_func));
51-
MLX5_SET(query_hca_cap_in, in, ec_vf_function, ec_vf_func);
5260
MLX5_SET(query_hca_cap_in, in, op_mod,
5361
MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE << 1 |
5462
HCA_CAP_OPMOD_GET_CUR);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,9 @@ int mlx5_vport_get_vhca_id(struct mlx5_core_dev *dev, u16 vport, u16 *vhca_id)
12391239
void *hca_caps;
12401240
int err;
12411241

1242-
*vhca_id = 0;
1242+
/* try get vhca_id via eswitch */
1243+
if (mlx5_esw_vport_vhca_id(dev->priv.eswitch, vport, vhca_id))
1244+
return 0;
12431245

12441246
query_ctx = kzalloc(query_out_sz, GFP_KERNEL);
12451247
if (!query_ctx)
@@ -1256,6 +1258,7 @@ int mlx5_vport_get_vhca_id(struct mlx5_core_dev *dev, u16 vport, u16 *vhca_id)
12561258
kfree(query_ctx);
12571259
return err;
12581260
}
1261+
EXPORT_SYMBOL_GPL(mlx5_vport_get_vhca_id);
12591262

12601263
int mlx5_vport_set_other_func_cap(struct mlx5_core_dev *dev, const void *hca_cap,
12611264
u16 vport, u16 opmod)

include/linux/mlx5/vport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,6 @@ int mlx5_nic_vport_unaffiliate_multiport(struct mlx5_core_dev *port_mdev);
135135
u64 mlx5_query_nic_system_image_guid(struct mlx5_core_dev *mdev);
136136
int mlx5_vport_get_other_func_cap(struct mlx5_core_dev *dev, u16 vport, void *out,
137137
u16 opmod);
138+
int mlx5_vport_get_vhca_id(struct mlx5_core_dev *dev, u16 vport, u16 *vhca_id);
139+
138140
#endif /* __MLX5_VPORT_H__ */

0 commit comments

Comments
 (0)