Skip to content

Commit 40ced89

Browse files
emuslndavem330
authored andcommitted
pds_core: devlink params for enabling VIF support
Add the devlink parameter switches so the user can enable the features supported by the VFs. The only feature supported at the moment is vDPA. Example: devlink dev param set pci/0000:2b:00.0 \ name enable_vnet cmode runtime value true Signed-off-by: Shannon Nelson <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4569cce commit 40ced89

File tree

4 files changed

+127
-6
lines changed

4 files changed

+127
-6
lines changed

Documentation/networking/device_drivers/ethernet/amd/pds_core.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ The ``pds_core`` driver reports the following versions
7373
- fixed
7474
- The revision of the ASIC for this device
7575

76+
Parameters
77+
==========
78+
79+
The ``pds_core`` driver implements the following generic
80+
parameters for controlling the functionality to be made available
81+
as auxiliary_bus devices.
82+
83+
.. list-table:: Generic parameters implemented
84+
:widths: 5 5 8 82
85+
86+
* - Name
87+
- Mode
88+
- Type
89+
- Description
90+
* - ``enable_vnet``
91+
- runtime
92+
- Boolean
93+
- Enables vDPA functionality through an auxiliary_bus device
94+
7695
Firmware Management
7796
===================
7897

drivers/net/ethernet/amd/pds_core/core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ int pdsc_dl_info_get(struct devlink *dl, struct devlink_info_req *req,
251251
int pdsc_dl_flash_update(struct devlink *dl,
252252
struct devlink_flash_update_params *params,
253253
struct netlink_ext_ack *extack);
254+
int pdsc_dl_enable_get(struct devlink *dl, u32 id,
255+
struct devlink_param_gset_ctx *ctx);
256+
int pdsc_dl_enable_set(struct devlink *dl, u32 id,
257+
struct devlink_param_gset_ctx *ctx);
258+
int pdsc_dl_enable_validate(struct devlink *dl, u32 id,
259+
union devlink_param_value val,
260+
struct netlink_ext_ack *extack);
254261

255262
void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num);
256263

drivers/net/ethernet/amd/pds_core/devlink.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,79 @@
22
/* Copyright(c) 2023 Advanced Micro Devices, Inc */
33

44
#include "core.h"
5+
#include <linux/pds/pds_auxbus.h>
6+
7+
static struct
8+
pdsc_viftype *pdsc_dl_find_viftype_by_id(struct pdsc *pdsc,
9+
enum devlink_param_type dl_id)
10+
{
11+
int vt;
12+
13+
for (vt = 0; vt < PDS_DEV_TYPE_MAX; vt++) {
14+
if (pdsc->viftype_status[vt].dl_id == dl_id)
15+
return &pdsc->viftype_status[vt];
16+
}
17+
18+
return NULL;
19+
}
20+
21+
int pdsc_dl_enable_get(struct devlink *dl, u32 id,
22+
struct devlink_param_gset_ctx *ctx)
23+
{
24+
struct pdsc *pdsc = devlink_priv(dl);
25+
struct pdsc_viftype *vt_entry;
26+
27+
vt_entry = pdsc_dl_find_viftype_by_id(pdsc, id);
28+
if (!vt_entry)
29+
return -ENOENT;
30+
31+
ctx->val.vbool = vt_entry->enabled;
32+
33+
return 0;
34+
}
35+
36+
int pdsc_dl_enable_set(struct devlink *dl, u32 id,
37+
struct devlink_param_gset_ctx *ctx)
38+
{
39+
struct pdsc *pdsc = devlink_priv(dl);
40+
struct pdsc_viftype *vt_entry;
41+
int err = 0;
42+
int vf_id;
43+
44+
vt_entry = pdsc_dl_find_viftype_by_id(pdsc, id);
45+
if (!vt_entry || !vt_entry->supported)
46+
return -EOPNOTSUPP;
47+
48+
if (vt_entry->enabled == ctx->val.vbool)
49+
return 0;
50+
51+
vt_entry->enabled = ctx->val.vbool;
52+
for (vf_id = 0; vf_id < pdsc->num_vfs; vf_id++) {
53+
struct pdsc *vf = pdsc->vfs[vf_id].vf;
54+
55+
err = ctx->val.vbool ? pdsc_auxbus_dev_add(vf, pdsc) :
56+
pdsc_auxbus_dev_del(vf, pdsc);
57+
}
58+
59+
return err;
60+
}
61+
62+
int pdsc_dl_enable_validate(struct devlink *dl, u32 id,
63+
union devlink_param_value val,
64+
struct netlink_ext_ack *extack)
65+
{
66+
struct pdsc *pdsc = devlink_priv(dl);
67+
struct pdsc_viftype *vt_entry;
68+
69+
vt_entry = pdsc_dl_find_viftype_by_id(pdsc, id);
70+
if (!vt_entry || !vt_entry->supported)
71+
return -EOPNOTSUPP;
72+
73+
if (!pdsc->viftype_status[vt_entry->vif_id].supported)
74+
return -ENODEV;
75+
76+
return 0;
77+
}
578

679
int pdsc_dl_flash_update(struct devlink *dl,
780
struct devlink_flash_update_params *params,

drivers/net/ethernet/amd/pds_core/main.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ static const struct devlink_health_reporter_ops pdsc_fw_reporter_ops = {
199199
.diagnose = pdsc_fw_reporter_diagnose,
200200
};
201201

202+
static const struct devlink_param pdsc_dl_params[] = {
203+
DEVLINK_PARAM_GENERIC(ENABLE_VNET,
204+
BIT(DEVLINK_PARAM_CMODE_RUNTIME),
205+
pdsc_dl_enable_get,
206+
pdsc_dl_enable_set,
207+
pdsc_dl_enable_validate),
208+
};
209+
202210
#define PDSC_WQ_NAME_LEN 24
203211

204212
static int pdsc_init_pf(struct pdsc *pdsc)
@@ -246,13 +254,19 @@ static int pdsc_init_pf(struct pdsc *pdsc)
246254

247255
dl = priv_to_devlink(pdsc);
248256
devl_lock(dl);
257+
err = devl_params_register(dl, pdsc_dl_params,
258+
ARRAY_SIZE(pdsc_dl_params));
259+
if (err) {
260+
dev_warn(pdsc->dev, "Failed to register devlink params: %pe\n",
261+
ERR_PTR(err));
262+
goto err_out_unlock_dl;
263+
}
249264

250265
hr = devl_health_reporter_create(dl, &pdsc_fw_reporter_ops, 0, pdsc);
251266
if (IS_ERR(hr)) {
252267
dev_warn(pdsc->dev, "Failed to create fw reporter: %pe\n", hr);
253268
err = PTR_ERR(hr);
254-
devl_unlock(dl);
255-
goto err_out_stop;
269+
goto err_out_unreg_params;
256270
}
257271
pdsc->fw_reporter = hr;
258272

@@ -264,7 +278,11 @@ static int pdsc_init_pf(struct pdsc *pdsc)
264278

265279
return 0;
266280

267-
err_out_stop:
281+
err_out_unreg_params:
282+
devl_params_unregister(dl, pdsc_dl_params,
283+
ARRAY_SIZE(pdsc_dl_params));
284+
err_out_unlock_dl:
285+
devl_unlock(dl);
268286
pdsc_stop(pdsc);
269287
err_out_teardown:
270288
pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING);
@@ -373,9 +391,13 @@ static void pdsc_remove(struct pci_dev *pdev)
373391
dl = priv_to_devlink(pdsc);
374392
devl_lock(dl);
375393
devl_unregister(dl);
376-
if (pdsc->fw_reporter) {
377-
devl_health_reporter_destroy(pdsc->fw_reporter);
378-
pdsc->fw_reporter = NULL;
394+
if (!pdev->is_virtfn) {
395+
if (pdsc->fw_reporter) {
396+
devl_health_reporter_destroy(pdsc->fw_reporter);
397+
pdsc->fw_reporter = NULL;
398+
}
399+
devl_params_unregister(dl, pdsc_dl_params,
400+
ARRAY_SIZE(pdsc_dl_params));
379401
}
380402
devl_unlock(dl);
381403

0 commit comments

Comments
 (0)