Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <shannon.nelson@amd.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Shannon Nelson and committed by
David S. Miller
40ced894 4569cce4

+127 -6
+19
Documentation/networking/device_drivers/ethernet/amd/pds_core.rst
··· 73 73 - fixed 74 74 - The revision of the ASIC for this device 75 75 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 + 76 95 Firmware Management 77 96 =================== 78 97
+7
drivers/net/ethernet/amd/pds_core/core.h
··· 251 251 int pdsc_dl_flash_update(struct devlink *dl, 252 252 struct devlink_flash_update_params *params, 253 253 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); 254 261 255 262 void __iomem *pdsc_map_dbpage(struct pdsc *pdsc, int page_num); 256 263
+73
drivers/net/ethernet/amd/pds_core/devlink.c
··· 2 2 /* Copyright(c) 2023 Advanced Micro Devices, Inc */ 3 3 4 4 #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 + } 5 78 6 79 int pdsc_dl_flash_update(struct devlink *dl, 7 80 struct devlink_flash_update_params *params,
+28 -6
drivers/net/ethernet/amd/pds_core/main.c
··· 199 199 .diagnose = pdsc_fw_reporter_diagnose, 200 200 }; 201 201 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 + 202 210 #define PDSC_WQ_NAME_LEN 24 203 211 204 212 static int pdsc_init_pf(struct pdsc *pdsc) ··· 254 246 255 247 dl = priv_to_devlink(pdsc); 256 248 devl_lock(dl); 249 + err = devl_params_register(dl, pdsc_dl_params, 250 + ARRAY_SIZE(pdsc_dl_params)); 251 + if (err) { 252 + dev_warn(pdsc->dev, "Failed to register devlink params: %pe\n", 253 + ERR_PTR(err)); 254 + goto err_out_unlock_dl; 255 + } 257 256 258 257 hr = devl_health_reporter_create(dl, &pdsc_fw_reporter_ops, 0, pdsc); 259 258 if (IS_ERR(hr)) { 260 259 dev_warn(pdsc->dev, "Failed to create fw reporter: %pe\n", hr); 261 260 err = PTR_ERR(hr); 262 - devl_unlock(dl); 263 - goto err_out_stop; 261 + goto err_out_unreg_params; 264 262 } 265 263 pdsc->fw_reporter = hr; 266 264 ··· 278 264 279 265 return 0; 280 266 281 - err_out_stop: 267 + err_out_unreg_params: 268 + devl_params_unregister(dl, pdsc_dl_params, 269 + ARRAY_SIZE(pdsc_dl_params)); 270 + err_out_unlock_dl: 271 + devl_unlock(dl); 282 272 pdsc_stop(pdsc); 283 273 err_out_teardown: 284 274 pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING); ··· 391 373 dl = priv_to_devlink(pdsc); 392 374 devl_lock(dl); 393 375 devl_unregister(dl); 394 - if (pdsc->fw_reporter) { 395 - devl_health_reporter_destroy(pdsc->fw_reporter); 396 - pdsc->fw_reporter = NULL; 376 + if (!pdev->is_virtfn) { 377 + if (pdsc->fw_reporter) { 378 + devl_health_reporter_destroy(pdsc->fw_reporter); 379 + pdsc->fw_reporter = NULL; 380 + } 381 + devl_params_unregister(dl, pdsc_dl_params, 382 + ARRAY_SIZE(pdsc_dl_params)); 397 383 } 398 384 devl_unlock(dl); 399 385