From: Saeed Mahameed <saeed@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Eric Dumazet <edumazet@google.com>
Cc: Saeed Mahameed <saeedm@nvidia.com>,
netdev@vger.kernel.org, Tariq Toukan <tariqt@nvidia.com>,
Gal Pressman <gal@nvidia.com>,
Leon Romanovsky <leonro@nvidia.com>, Jiri Pirko <jiri@nvidia.com>,
Simon Horman <horms@kernel.org>,
Vlad Dumitrescu <vdumitrescu@nvidia.com>,
Kamal Heib <kheib@redhat.com>
Subject: [PATCH net-next V6 04/13] net/mlx5: Implement devlink total_vfs parameter
Date: Tue, 8 Jul 2025 20:04:46 -0700 [thread overview]
Message-ID: <20250709030456.1290841-5-saeed@kernel.org> (raw)
In-Reply-To: <20250709030456.1290841-1-saeed@kernel.org>
From: Vlad Dumitrescu <vdumitrescu@nvidia.com>
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 <vdumitrescu@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Tested-by: Kamal Heib <kheib@redhat.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
---
Documentation/networking/devlink/mlx5.rst | 22 +++
.../mellanox/mlx5/core/lib/nv_param.c | 132 ++++++++++++++++++
2 files changed, 154 insertions(+)
diff --git a/Documentation/networking/devlink/mlx5.rst b/Documentation/networking/devlink/mlx5.rst
index 587e0200c1cd..00a43324dec2 100644
--- a/Documentation/networking/devlink/mlx5.rst
+++ b/Documentation/networking/devlink/mlx5.rst
@@ -40,6 +40,28 @@ Parameters
- Boolean
- Applies to each physical function (PF) independently, if the device
supports it. Otherwise, it applies symmetrically to all PFs.
+ * - ``total_vfs``
+ - permanent
+ - The range is between 1 and a device-specific max.
+ - Applies to each physical function (PF) independently, if the device
+ supports it. Otherwise, it applies symmetrically to all PFs.
+
+Note: permanent parameters such as ``enable_sriov`` and ``total_vfs`` require FW reset to take effect
+
+.. code-block:: bash
+
+ # setup parameters
+ devlink dev param set pci/0000:01:00.0 name enable_sriov value true cmode permanent
+ devlink dev param set pci/0000:01:00.0 name total_vfs value 8 cmode permanent
+
+ # Fw reset
+ devlink dev reload pci/0000:01:00.0 action fw_activate
+
+ # for PCI related config such as sriov PCI reset/rescan is required:
+ echo 1 >/sys/bus/pci/devices/0000:01:00.0/remove
+ echo 1 >/sys/bus/pci/rescan
+ grep ^ /sys/bus/pci/devices/0000:01:00.0/sriov_*
+
The ``mlx5`` driver also implements the following driver-specific
parameters.
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/nv_param.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/nv_param.c
index ed2129843ec7..383d8cfe4c0a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/nv_param.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/nv_param.c
@@ -412,10 +412,142 @@ static int mlx5_devlink_enable_sriov_set(struct devlink *devlink, u32 id,
return mlx5_nv_param_write(dev, mnvda, sizeof(mnvda));
}
+static int mlx5_devlink_total_vfs_get(struct devlink *devlink, u32 id,
+ struct devlink_param_gset_ctx *ctx)
+{
+ struct mlx5_core_dev *dev = devlink_priv(devlink);
+ u32 mnvda[MLX5_ST_SZ_DW(mnvda_reg)] = {};
+ void *data;
+ int err;
+
+ data = MLX5_ADDR_OF(mnvda_reg, mnvda, configuration_item_data);
+
+ err = mlx5_nv_param_read_global_pci_cap(dev, mnvda, sizeof(mnvda));
+ if (err)
+ return err;
+
+ if (!MLX5_GET(nv_global_pci_cap, data, sriov_support)) {
+ ctx->val.vu32 = 0;
+ return 0;
+ }
+
+ memset(mnvda, 0, sizeof(mnvda));
+ err = mlx5_nv_param_read_global_pci_conf(dev, mnvda, sizeof(mnvda));
+ if (err)
+ return err;
+
+ if (!MLX5_GET(nv_global_pci_conf, data, per_pf_total_vf)) {
+ ctx->val.vu32 = MLX5_GET(nv_global_pci_conf, data, total_vfs);
+ return 0;
+ }
+
+ /* SRIOV is per PF */
+ memset(mnvda, 0, sizeof(mnvda));
+ err = mlx5_nv_param_read_per_host_pf_conf(dev, mnvda, sizeof(mnvda));
+ if (err)
+ return err;
+
+ ctx->val.vu32 = MLX5_GET(nv_pf_pci_conf, data, total_vf);
+
+ return 0;
+}
+
+static int mlx5_devlink_total_vfs_set(struct devlink *devlink, u32 id,
+ struct devlink_param_gset_ctx *ctx,
+ struct netlink_ext_ack *extack)
+{
+ struct mlx5_core_dev *dev = devlink_priv(devlink);
+ u32 mnvda[MLX5_ST_SZ_DW(mnvda_reg)];
+ bool per_pf_support;
+ void *data;
+ int err;
+
+ err = mlx5_nv_param_read_global_pci_cap(dev, mnvda, sizeof(mnvda));
+ if (err) {
+ NL_SET_ERR_MSG_MOD(extack, "Failed to read global pci cap");
+ return err;
+ }
+
+ data = MLX5_ADDR_OF(mnvda_reg, mnvda, configuration_item_data);
+ if (!MLX5_GET(nv_global_pci_cap, data, sriov_support)) {
+ NL_SET_ERR_MSG_MOD(extack, "Not configurable on this device");
+ return -EOPNOTSUPP;
+ }
+
+ per_pf_support = MLX5_GET(nv_global_pci_cap, data,
+ per_pf_total_vf_supported);
+ if (!per_pf_support) {
+ /* We don't allow global SRIOV setting on per PF devlink */
+ NL_SET_ERR_MSG_MOD(extack,
+ "SRIOV is not per PF on this device");
+ return -EOPNOTSUPP;
+ }
+
+ memset(mnvda, 0, sizeof(mnvda));
+ err = mlx5_nv_param_read_global_pci_conf(dev, mnvda, sizeof(mnvda));
+ if (err)
+ return err;
+
+ MLX5_SET(nv_global_pci_conf, data, sriov_valid, 1);
+ MLX5_SET(nv_global_pci_conf, data, per_pf_total_vf, per_pf_support);
+
+ if (!per_pf_support) {
+ MLX5_SET(nv_global_pci_conf, data, total_vfs, ctx->val.vu32);
+ return mlx5_nv_param_write(dev, mnvda, sizeof(mnvda));
+ }
+
+ /* SRIOV is per PF */
+ err = mlx5_nv_param_write(dev, mnvda, sizeof(mnvda));
+ if (err)
+ return err;
+
+ memset(mnvda, 0, sizeof(mnvda));
+ err = mlx5_nv_param_read_per_host_pf_conf(dev, mnvda, sizeof(mnvda));
+ if (err)
+ return err;
+
+ data = MLX5_ADDR_OF(mnvda_reg, mnvda, configuration_item_data);
+ MLX5_SET(nv_pf_pci_conf, data, total_vf, ctx->val.vu32);
+ return mlx5_nv_param_write(dev, mnvda, sizeof(mnvda));
+}
+
+static int mlx5_devlink_total_vfs_validate(struct devlink *devlink, u32 id,
+ union devlink_param_value val,
+ struct netlink_ext_ack *extack)
+{
+ struct mlx5_core_dev *dev = devlink_priv(devlink);
+ u32 cap[MLX5_ST_SZ_DW(mnvda_reg)];
+ void *data;
+ u16 max;
+ int err;
+
+ data = MLX5_ADDR_OF(mnvda_reg, cap, configuration_item_data);
+
+ err = mlx5_nv_param_read_global_pci_cap(dev, cap, sizeof(cap));
+ if (err)
+ return err;
+
+ if (!MLX5_GET(nv_global_pci_cap, data, max_vfs_per_pf_valid))
+ return 0; /* optimistic, but set might fail later */
+
+ max = MLX5_GET(nv_global_pci_cap, data, max_vfs_per_pf);
+ if (val.vu16 > max) {
+ NL_SET_ERR_MSG_FMT_MOD(extack,
+ "Max allowed by device is %u", max);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static const struct devlink_param mlx5_nv_param_devlink_params[] = {
DEVLINK_PARAM_GENERIC(ENABLE_SRIOV, BIT(DEVLINK_PARAM_CMODE_PERMANENT),
mlx5_devlink_enable_sriov_get,
mlx5_devlink_enable_sriov_set, NULL),
+ DEVLINK_PARAM_GENERIC(TOTAL_VFS, BIT(DEVLINK_PARAM_CMODE_PERMANENT),
+ mlx5_devlink_total_vfs_get,
+ mlx5_devlink_total_vfs_set,
+ mlx5_devlink_total_vfs_validate),
DEVLINK_PARAM_DRIVER(MLX5_DEVLINK_PARAM_ID_CQE_COMPRESSION_TYPE,
"cqe_compress_type", DEVLINK_PARAM_TYPE_STRING,
BIT(DEVLINK_PARAM_CMODE_PERMANENT),
--
2.50.0
next prev parent reply other threads:[~2025-07-09 3:05 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 3:04 [PATCH net-next V6 00/13] devlink, mlx5: Add new parameters for link management and SRIOV/eSwitch configurations Saeed Mahameed
2025-07-09 3:04 ` [PATCH net-next V6 01/13] devlink: Add 'total_vfs' generic device param Saeed Mahameed
2025-07-09 8:36 ` Simon Horman
2025-07-10 2:53 ` Jakub Kicinski
2025-07-10 5:38 ` Saeed Mahameed
2025-09-02 21:24 ` Jacob Keller
2025-09-03 21:32 ` Saeed Mahameed
2025-07-09 3:04 ` [PATCH net-next V6 02/13] net/mlx5: Implement cqe_compress_type via devlink params Saeed Mahameed
2025-07-09 8:37 ` Simon Horman
2025-07-09 9:06 ` Subbaraya Sundeep
2025-07-10 5:51 ` Saeed Mahameed
2025-07-11 16:19 ` Subbaraya Sundeep
2025-07-10 2:53 ` Jakub Kicinski
2025-07-10 5:44 ` Saeed Mahameed
2025-07-10 22:16 ` Jakub Kicinski
2025-07-09 3:04 ` [PATCH net-next V6 03/13] net/mlx5: Implement devlink enable_sriov parameter Saeed Mahameed
2025-07-09 8:37 ` Simon Horman
2025-07-09 3:04 ` Saeed Mahameed [this message]
2025-07-09 8:37 ` [PATCH net-next V6 04/13] net/mlx5: Implement devlink total_vfs parameter Simon Horman
2025-07-09 3:04 ` [PATCH net-next V6 05/13] devlink: pass struct devlink_port * as arg to devlink_nl_param_fill() Saeed Mahameed
2025-07-09 8:38 ` Simon Horman
2025-07-09 3:04 ` [PATCH net-next V6 06/13] devlink: Implement port params registration Saeed Mahameed
2025-07-09 8:38 ` Simon Horman
2025-07-09 3:04 ` [PATCH net-next V6 07/13] devlink: Implement get/dump netlink commands for port params Saeed Mahameed
2025-07-09 8:38 ` Simon Horman
2025-07-09 3:04 ` [PATCH net-next V6 08/13] devlink: Implement set netlink command " Saeed Mahameed
2025-07-09 8:40 ` Simon Horman
2025-07-09 3:04 ` [PATCH net-next V6 09/13] devlink: Add 'keep_link_up' generic devlink device param Saeed Mahameed
2025-07-09 8:40 ` Simon Horman
2025-07-10 2:58 ` Jakub Kicinski
2025-07-10 6:04 ` Saeed Mahameed
2025-07-10 12:45 ` Jiri Pirko
2025-07-10 22:24 ` Jakub Kicinski
2025-08-28 20:09 ` Saeed Mahameed
2025-08-28 22:38 ` Jakub Kicinski
2025-09-02 19:02 ` Saeed Mahameed
2025-09-02 21:57 ` Jacob Keller
2025-09-03 6:45 ` Saeed Mahameed
2025-09-03 19:59 ` Jacob Keller
2025-09-03 21:30 ` Saeed Mahameed
2025-07-09 3:04 ` [PATCH net-next V6 10/13] net/mlx5: Implement devlink keep_link_up port parameter Saeed Mahameed
2025-07-09 8:40 ` Simon Horman
2025-07-09 3:04 ` [PATCH net-next V6 11/13] devlink: Throw extack messages on param value validation error Saeed Mahameed
2025-07-09 8:40 ` Simon Horman
2025-07-09 3:04 ` [PATCH net-next V6 12/13] devlink: Implement devlink param multi attribute nested data values Saeed Mahameed
2025-07-09 8:41 ` Simon Horman
2025-07-09 3:04 ` [PATCH net-next V6 13/13] net/mlx5: Implement eSwitch hairpin per prio buffers devlink params Saeed Mahameed
2025-07-09 8:41 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250709030456.1290841-5-saeed@kernel.org \
--to=saeed@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=horms@kernel.org \
--cc=jiri@nvidia.com \
--cc=kheib@redhat.com \
--cc=kuba@kernel.org \
--cc=leonro@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
--cc=tariqt@nvidia.com \
--cc=vdumitrescu@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).