Skip to content

Commit 6c5e682

Browse files
kliteynSaeed Mahameed
authored andcommitted
net/mlx5: HWS, added vport handling
Vport is a virtual eswitch port that is associated with its virtual function (VF), physical function (PF) or sub-function (SF). This patch adds handling of vports in HWS. Reviewed-by: Hamdan Agbariya <[email protected]> Signed-off-by: Yevgeny Kliteynik <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent aefc15a commit 6c5e682

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
/* Copyright (c) 2024 NVIDIA Corporation & Affiliates */
3+
4+
#include "mlx5hws_internal.h"
5+
6+
int mlx5hws_vport_init_vports(struct mlx5hws_context *ctx)
7+
{
8+
int ret;
9+
10+
if (!ctx->caps->eswitch_manager)
11+
return 0;
12+
13+
xa_init(&ctx->vports.vport_gvmi_xa);
14+
15+
/* Set gvmi for eswitch manager and uplink vports only. Rest of the vports
16+
* (vport 0 of other function, VFs and SFs) will be queried dynamically.
17+
*/
18+
19+
ret = mlx5hws_cmd_query_gvmi(ctx->mdev, false, 0, &ctx->vports.esw_manager_gvmi);
20+
if (ret)
21+
return ret;
22+
23+
ctx->vports.uplink_gvmi = 0;
24+
return 0;
25+
}
26+
27+
void mlx5hws_vport_uninit_vports(struct mlx5hws_context *ctx)
28+
{
29+
if (ctx->caps->eswitch_manager)
30+
xa_destroy(&ctx->vports.vport_gvmi_xa);
31+
}
32+
33+
static int hws_vport_add_gvmi(struct mlx5hws_context *ctx, u16 vport)
34+
{
35+
u16 vport_gvmi;
36+
int ret;
37+
38+
ret = mlx5hws_cmd_query_gvmi(ctx->mdev, true, vport, &vport_gvmi);
39+
if (ret)
40+
return -EINVAL;
41+
42+
ret = xa_insert(&ctx->vports.vport_gvmi_xa, vport,
43+
xa_mk_value(vport_gvmi), GFP_KERNEL);
44+
if (ret)
45+
mlx5hws_dbg(ctx, "Couldn't insert new vport gvmi into xarray (%d)\n", ret);
46+
47+
return ret;
48+
}
49+
50+
static bool hws_vport_is_esw_mgr_vport(struct mlx5hws_context *ctx, u16 vport)
51+
{
52+
return ctx->caps->is_ecpf ? vport == MLX5_VPORT_ECPF :
53+
vport == MLX5_VPORT_PF;
54+
}
55+
56+
int mlx5hws_vport_get_gvmi(struct mlx5hws_context *ctx, u16 vport, u16 *vport_gvmi)
57+
{
58+
void *entry;
59+
int ret;
60+
61+
if (!ctx->caps->eswitch_manager)
62+
return -EINVAL;
63+
64+
if (hws_vport_is_esw_mgr_vport(ctx, vport)) {
65+
*vport_gvmi = ctx->vports.esw_manager_gvmi;
66+
return 0;
67+
}
68+
69+
if (vport == MLX5_VPORT_UPLINK) {
70+
*vport_gvmi = ctx->vports.uplink_gvmi;
71+
return 0;
72+
}
73+
74+
load_entry:
75+
entry = xa_load(&ctx->vports.vport_gvmi_xa, vport);
76+
77+
if (!xa_is_value(entry)) {
78+
ret = hws_vport_add_gvmi(ctx, vport);
79+
if (ret && ret != -EBUSY)
80+
return ret;
81+
goto load_entry;
82+
}
83+
84+
*vport_gvmi = (u16)xa_to_value(entry);
85+
return 0;
86+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2+
/* Copyright (c) 2024 NVIDIA Corporation & Affiliates */
3+
4+
#ifndef MLX5HWS_VPORT_H_
5+
#define MLX5HWS_VPORT_H_
6+
7+
int mlx5hws_vport_init_vports(struct mlx5hws_context *ctx);
8+
9+
void mlx5hws_vport_uninit_vports(struct mlx5hws_context *ctx);
10+
11+
int mlx5hws_vport_get_gvmi(struct mlx5hws_context *ctx, u16 vport, u16 *vport_gvmi);
12+
13+
#endif /* MLX5HWS_VPORT_H_ */

0 commit comments

Comments
 (0)