Skip to content

Commit a4c4961

Browse files
vladumkuba-moo
authored andcommitted
net/mlx5: Implement devlink total_vfs parameter
Some devices support both symmetric (same value for all PFs) and asymmetric, while others only support symmetric configuration. This implementation prefers asymmetric, since it is closer to the devlink model (per function settings), but falls back to symmetric when needed. Example usage: devlink dev param set pci/0000:01:00.0 name total_vfs value <u16> cmode permanent devlink dev reload pci/0000:01:00.0 action fw_activate echo 1 >/sys/bus/pci/devices/0000:01:00.0/remove echo 1 >/sys/bus/pci/rescan cat /sys/bus/pci/devices/0000:01:00.0/sriov_totalvfs Signed-off-by: Vlad Dumitrescu <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Tested-by: Kamal Heib <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 95a0af1 commit a4c4961

File tree

2 files changed

+154
-0
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/lib

2 files changed

+154
-0
lines changed

Documentation/networking/devlink/mlx5.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ Parameters
4040
- Boolean
4141
- Applies to each physical function (PF) independently, if the device
4242
supports it. Otherwise, it applies symmetrically to all PFs.
43+
* - ``total_vfs``
44+
- permanent
45+
- The range is between 1 and a device-specific max.
46+
- Applies to each physical function (PF) independently, if the device
47+
supports it. Otherwise, it applies symmetrically to all PFs.
48+
49+
Note: permanent parameters such as ``enable_sriov`` and ``total_vfs`` require FW reset to take effect
50+
51+
.. code-block:: bash
52+
53+
# setup parameters
54+
devlink dev param set pci/0000:01:00.0 name enable_sriov value true cmode permanent
55+
devlink dev param set pci/0000:01:00.0 name total_vfs value 8 cmode permanent
56+
57+
# Fw reset
58+
devlink dev reload pci/0000:01:00.0 action fw_activate
59+
60+
# for PCI related config such as sriov PCI reset/rescan is required:
61+
echo 1 >/sys/bus/pci/devices/0000:01:00.0/remove
62+
echo 1 >/sys/bus/pci/rescan
63+
grep ^ /sys/bus/pci/devices/0000:01:00.0/sriov_*
64+
4365
4466
The ``mlx5`` driver also implements the following driver-specific
4567
parameters.

drivers/net/ethernet/mellanox/mlx5/core/lib/nv_param.c

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,142 @@ static int mlx5_devlink_enable_sriov_set(struct devlink *devlink, u32 id,
412412
return mlx5_nv_param_write(dev, mnvda, sizeof(mnvda));
413413
}
414414

415+
static int mlx5_devlink_total_vfs_get(struct devlink *devlink, u32 id,
416+
struct devlink_param_gset_ctx *ctx)
417+
{
418+
struct mlx5_core_dev *dev = devlink_priv(devlink);
419+
u32 mnvda[MLX5_ST_SZ_DW(mnvda_reg)] = {};
420+
void *data;
421+
int err;
422+
423+
data = MLX5_ADDR_OF(mnvda_reg, mnvda, configuration_item_data);
424+
425+
err = mlx5_nv_param_read_global_pci_cap(dev, mnvda, sizeof(mnvda));
426+
if (err)
427+
return err;
428+
429+
if (!MLX5_GET(nv_global_pci_cap, data, sriov_support)) {
430+
ctx->val.vu32 = 0;
431+
return 0;
432+
}
433+
434+
memset(mnvda, 0, sizeof(mnvda));
435+
err = mlx5_nv_param_read_global_pci_conf(dev, mnvda, sizeof(mnvda));
436+
if (err)
437+
return err;
438+
439+
if (!MLX5_GET(nv_global_pci_conf, data, per_pf_total_vf)) {
440+
ctx->val.vu32 = MLX5_GET(nv_global_pci_conf, data, total_vfs);
441+
return 0;
442+
}
443+
444+
/* SRIOV is per PF */
445+
memset(mnvda, 0, sizeof(mnvda));
446+
err = mlx5_nv_param_read_per_host_pf_conf(dev, mnvda, sizeof(mnvda));
447+
if (err)
448+
return err;
449+
450+
ctx->val.vu32 = MLX5_GET(nv_pf_pci_conf, data, total_vf);
451+
452+
return 0;
453+
}
454+
455+
static int mlx5_devlink_total_vfs_set(struct devlink *devlink, u32 id,
456+
struct devlink_param_gset_ctx *ctx,
457+
struct netlink_ext_ack *extack)
458+
{
459+
struct mlx5_core_dev *dev = devlink_priv(devlink);
460+
u32 mnvda[MLX5_ST_SZ_DW(mnvda_reg)];
461+
bool per_pf_support;
462+
void *data;
463+
int err;
464+
465+
err = mlx5_nv_param_read_global_pci_cap(dev, mnvda, sizeof(mnvda));
466+
if (err) {
467+
NL_SET_ERR_MSG_MOD(extack, "Failed to read global pci cap");
468+
return err;
469+
}
470+
471+
data = MLX5_ADDR_OF(mnvda_reg, mnvda, configuration_item_data);
472+
if (!MLX5_GET(nv_global_pci_cap, data, sriov_support)) {
473+
NL_SET_ERR_MSG_MOD(extack, "Not configurable on this device");
474+
return -EOPNOTSUPP;
475+
}
476+
477+
per_pf_support = MLX5_GET(nv_global_pci_cap, data,
478+
per_pf_total_vf_supported);
479+
if (!per_pf_support) {
480+
/* We don't allow global SRIOV setting on per PF devlink */
481+
NL_SET_ERR_MSG_MOD(extack,
482+
"SRIOV is not per PF on this device");
483+
return -EOPNOTSUPP;
484+
}
485+
486+
memset(mnvda, 0, sizeof(mnvda));
487+
err = mlx5_nv_param_read_global_pci_conf(dev, mnvda, sizeof(mnvda));
488+
if (err)
489+
return err;
490+
491+
MLX5_SET(nv_global_pci_conf, data, sriov_valid, 1);
492+
MLX5_SET(nv_global_pci_conf, data, per_pf_total_vf, per_pf_support);
493+
494+
if (!per_pf_support) {
495+
MLX5_SET(nv_global_pci_conf, data, total_vfs, ctx->val.vu32);
496+
return mlx5_nv_param_write(dev, mnvda, sizeof(mnvda));
497+
}
498+
499+
/* SRIOV is per PF */
500+
err = mlx5_nv_param_write(dev, mnvda, sizeof(mnvda));
501+
if (err)
502+
return err;
503+
504+
memset(mnvda, 0, sizeof(mnvda));
505+
err = mlx5_nv_param_read_per_host_pf_conf(dev, mnvda, sizeof(mnvda));
506+
if (err)
507+
return err;
508+
509+
data = MLX5_ADDR_OF(mnvda_reg, mnvda, configuration_item_data);
510+
MLX5_SET(nv_pf_pci_conf, data, total_vf, ctx->val.vu32);
511+
return mlx5_nv_param_write(dev, mnvda, sizeof(mnvda));
512+
}
513+
514+
static int mlx5_devlink_total_vfs_validate(struct devlink *devlink, u32 id,
515+
union devlink_param_value val,
516+
struct netlink_ext_ack *extack)
517+
{
518+
struct mlx5_core_dev *dev = devlink_priv(devlink);
519+
u32 cap[MLX5_ST_SZ_DW(mnvda_reg)];
520+
void *data;
521+
u16 max;
522+
int err;
523+
524+
data = MLX5_ADDR_OF(mnvda_reg, cap, configuration_item_data);
525+
526+
err = mlx5_nv_param_read_global_pci_cap(dev, cap, sizeof(cap));
527+
if (err)
528+
return err;
529+
530+
if (!MLX5_GET(nv_global_pci_cap, data, max_vfs_per_pf_valid))
531+
return 0; /* optimistic, but set might fail later */
532+
533+
max = MLX5_GET(nv_global_pci_cap, data, max_vfs_per_pf);
534+
if (val.vu16 > max) {
535+
NL_SET_ERR_MSG_FMT_MOD(extack,
536+
"Max allowed by device is %u", max);
537+
return -EINVAL;
538+
}
539+
540+
return 0;
541+
}
542+
415543
static const struct devlink_param mlx5_nv_param_devlink_params[] = {
416544
DEVLINK_PARAM_GENERIC(ENABLE_SRIOV, BIT(DEVLINK_PARAM_CMODE_PERMANENT),
417545
mlx5_devlink_enable_sriov_get,
418546
mlx5_devlink_enable_sriov_set, NULL),
547+
DEVLINK_PARAM_GENERIC(TOTAL_VFS, BIT(DEVLINK_PARAM_CMODE_PERMANENT),
548+
mlx5_devlink_total_vfs_get,
549+
mlx5_devlink_total_vfs_set,
550+
mlx5_devlink_total_vfs_validate),
419551
DEVLINK_PARAM_DRIVER(MLX5_DEVLINK_PARAM_ID_CQE_COMPRESSION_TYPE,
420552
"cqe_compress_type", DEVLINK_PARAM_TYPE_STRING,
421553
BIT(DEVLINK_PARAM_CMODE_PERMANENT),

0 commit comments

Comments
 (0)