Skip to content

Commit 38dad81

Browse files
author
Paolo Abeni
committed
Merge tag 'mlx5-next-vhca-id' of git://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux
Saeed Mahameed says: ==================== mlx5-next-vhca-id A preparation patchset for adjacent function vports. Adjacent functions can delegate their SR-IOV VFs to sibling PFs, allowing for more flexible and scalable management in multi-host and ECPF-to-host scenarios. Adjacent vports can be managed by the management PF via their unique vhca id and can't be managed by function index as the index can conflict with the local vports/vfs. This series provides: - Use the cached vcha id instead of querying it every time from fw - Query hca cap using vhca id instead of function id when FW supports it - Add HW capabilities and required definitions for adjacent function vports * tag 'mlx5-next-vhca-id' of git://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux: {rdma,net}/mlx5: export mlx5_vport_get_vhca_id net/mlx5: E-Switch, Set/Query hca cap via vhca id net/mlx5: E-Switch, Cache vport vhca id on first cap query net/mlx5: mlx5_ifc, Add hardware definitions needed for adjacent vports ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 833e431 + 40653f2 commit 38dad81

File tree

11 files changed

+263
-65
lines changed

11 files changed

+263
-65
lines changed

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/eswitch.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ static int mlx5_esw_vport_caps_get(struct mlx5_eswitch *esw, struct mlx5_vport *
820820

821821
hca_caps = MLX5_ADDR_OF(query_hca_cap_out, query_ctx, capability);
822822
vport->info.roce_enabled = MLX5_GET(cmd_hca_cap, hca_caps, roce);
823+
vport->vhca_id = MLX5_GET(cmd_hca_cap, hca_caps, vhca_id);
823824

824825
if (!MLX5_CAP_GEN_MAX(esw->dev, hca_cap_2))
825826
goto out_free;
@@ -839,6 +840,18 @@ static int mlx5_esw_vport_caps_get(struct mlx5_eswitch *esw, struct mlx5_vport *
839840
return err;
840841
}
841842

843+
bool mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16 vportn, u16 *vhca_id)
844+
{
845+
struct mlx5_vport *vport;
846+
847+
vport = mlx5_eswitch_get_vport(esw, vportn);
848+
if (IS_ERR(vport) || MLX5_VPORT_INVAL_VHCA_ID(vport))
849+
return false;
850+
851+
*vhca_id = vport->vhca_id;
852+
return true;
853+
}
854+
842855
static int esw_vport_setup(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
843856
{
844857
bool vst_mode_steering = esw_vst_mode_is_steering(esw);
@@ -929,7 +942,7 @@ int mlx5_esw_vport_enable(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
929942

930943
if (!mlx5_esw_is_manager_vport(esw, vport_num) &&
931944
MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) {
932-
ret = mlx5_esw_vport_vhca_id_set(esw, vport_num);
945+
ret = mlx5_esw_vport_vhca_id_map(esw, vport);
933946
if (ret)
934947
goto err_vhca_mapping;
935948
}
@@ -973,7 +986,7 @@ void mlx5_esw_vport_disable(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
973986

974987
if (!mlx5_esw_is_manager_vport(esw, vport_num) &&
975988
MLX5_CAP_GEN(esw->dev, vhca_resource_manager))
976-
mlx5_esw_vport_vhca_id_clear(esw, vport_num);
989+
mlx5_esw_vport_vhca_id_unmap(esw, vport);
977990

978991
if (vport->vport != MLX5_VPORT_PF &&
979992
(vport->info.ipsec_crypto_enabled || vport->info.ipsec_packet_enabled))
@@ -1735,6 +1748,7 @@ static int mlx5_esw_vport_alloc(struct mlx5_eswitch *esw,
17351748
vport->vport = vport_num;
17361749
vport->index = index;
17371750
vport->info.link_state = MLX5_VPORT_ADMIN_STATE_AUTO;
1751+
vport->vhca_id = MLX5_VHCA_ID_INVALID;
17381752
INIT_WORK(&vport->vport_change_handler, esw_vport_change_handler);
17391753
err = xa_insert(&esw->vports, vport_num, vport, GFP_KERNEL);
17401754
if (err)

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ static inline struct mlx5_vport *mlx5_devlink_port_vport_get(struct devlink_port
197197
return mlx5_devlink_port_get(dl_port)->vport;
198198
}
199199

200+
#define MLX5_VHCA_ID_INVALID (-1)
201+
202+
#define MLX5_VPORT_INVAL_VHCA_ID(vport) \
203+
((vport)->vhca_id == MLX5_VHCA_ID_INVALID)
204+
200205
struct mlx5_vport {
201206
struct mlx5_core_dev *dev;
202207
struct hlist_head uc_list[MLX5_L2_ADDR_HASH_SIZE];
@@ -209,6 +214,7 @@ struct mlx5_vport {
209214
struct vport_egress egress;
210215
u32 default_metadata;
211216
u32 metadata;
217+
int vhca_id;
212218

213219
struct mlx5_vport_info info;
214220

@@ -823,9 +829,12 @@ struct devlink_port *mlx5_esw_offloads_devlink_port(struct mlx5_eswitch *esw, u1
823829

824830
int mlx5_esw_sf_max_hpf_functions(struct mlx5_core_dev *dev, u16 *max_sfs, u16 *sf_base_id);
825831

826-
int mlx5_esw_vport_vhca_id_set(struct mlx5_eswitch *esw, u16 vport_num);
827-
void mlx5_esw_vport_vhca_id_clear(struct mlx5_eswitch *esw, u16 vport_num);
832+
int mlx5_esw_vport_vhca_id_map(struct mlx5_eswitch *esw,
833+
struct mlx5_vport *vport);
834+
void mlx5_esw_vport_vhca_id_unmap(struct mlx5_eswitch *esw,
835+
struct mlx5_vport *vport);
828836
int mlx5_eswitch_vhca_id_to_vport(struct mlx5_eswitch *esw, u16 vhca_id, u16 *vport_num);
837+
bool mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16 vportn, u16 *vhca_id);
829838

830839
/**
831840
* struct mlx5_esw_event_info - Indicates eswitch mode changed/changing.
@@ -973,6 +982,13 @@ mlx5_esw_host_functions_enabled(const struct mlx5_core_dev *dev)
973982
{
974983
return true;
975984
}
985+
986+
static inline bool
987+
mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16 vportn, u16 *vhca_id)
988+
{
989+
return -EOPNOTSUPP;
990+
}
991+
976992
#endif /* CONFIG_MLX5_ESWITCH */
977993

978994
#endif /* __MLX5_ESWITCH_H__ */

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4167,23 +4167,28 @@ u32 mlx5_eswitch_get_vport_metadata_for_match(struct mlx5_eswitch *esw,
41674167
}
41684168
EXPORT_SYMBOL(mlx5_eswitch_get_vport_metadata_for_match);
41694169

4170-
int mlx5_esw_vport_vhca_id_set(struct mlx5_eswitch *esw, u16 vport_num)
4170+
int mlx5_esw_vport_vhca_id_map(struct mlx5_eswitch *esw,
4171+
struct mlx5_vport *vport)
41714172
{
41724173
u16 *old_entry, *vhca_map_entry, vhca_id;
4173-
int err;
41744174

4175-
err = mlx5_vport_get_vhca_id(esw->dev, vport_num, &vhca_id);
4176-
if (err) {
4177-
esw_warn(esw->dev, "Getting vhca_id for vport failed (vport=%u,err=%d)\n",
4178-
vport_num, err);
4179-
return err;
4175+
if (WARN_ONCE(MLX5_VPORT_INVAL_VHCA_ID(vport),
4176+
"vport %d vhca_id is not set", vport->vport)) {
4177+
int err;
4178+
4179+
err = mlx5_vport_get_vhca_id(vport->dev, vport->vport,
4180+
&vhca_id);
4181+
if (err)
4182+
return err;
4183+
vport->vhca_id = vhca_id;
41804184
}
41814185

4186+
vhca_id = vport->vhca_id;
41824187
vhca_map_entry = kmalloc(sizeof(*vhca_map_entry), GFP_KERNEL);
41834188
if (!vhca_map_entry)
41844189
return -ENOMEM;
41854190

4186-
*vhca_map_entry = vport_num;
4191+
*vhca_map_entry = vport->vport;
41874192
old_entry = xa_store(&esw->offloads.vhca_map, vhca_id, vhca_map_entry, GFP_KERNEL);
41884193
if (xa_is_err(old_entry)) {
41894194
kfree(vhca_map_entry);
@@ -4193,17 +4198,12 @@ int mlx5_esw_vport_vhca_id_set(struct mlx5_eswitch *esw, u16 vport_num)
41934198
return 0;
41944199
}
41954200

4196-
void mlx5_esw_vport_vhca_id_clear(struct mlx5_eswitch *esw, u16 vport_num)
4201+
void mlx5_esw_vport_vhca_id_unmap(struct mlx5_eswitch *esw,
4202+
struct mlx5_vport *vport)
41974203
{
4198-
u16 *vhca_map_entry, vhca_id;
4199-
int err;
4200-
4201-
err = mlx5_vport_get_vhca_id(esw->dev, vport_num, &vhca_id);
4202-
if (err)
4203-
esw_warn(esw->dev, "Getting vhca_id for vport failed (vport=%hu,err=%d)\n",
4204-
vport_num, err);
4204+
u16 *vhca_map_entry;
42054205

4206-
vhca_map_entry = xa_erase(&esw->offloads.vhca_map, vhca_id);
4206+
vhca_map_entry = xa_erase(&esw->offloads.vhca_map, vport->vhca_id);
42074207
kfree(vhca_map_entry);
42084208
}
42094209

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);

0 commit comments

Comments
 (0)