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>
Subject: [PATCH net-next V3 09/15] devlink: Implement get/dump netlink commands for port params
Date: Fri, 25 Apr 2025 14:48:02 -0700 [thread overview]
Message-ID: <20250425214808.507732-10-saeed@kernel.org> (raw)
In-Reply-To: <20250425214808.507732-1-saeed@kernel.org>
From: Saeed Mahameed <saeedm@nvidia.com>
Add missing port-params netlink attributes and policies to devlink's
spec, reuse existing get_doit/dump_doit of the devlink params for port
params and implement the dump command for all devlink ports params.
This implements:
1) devlink port param show
2) devlink port param show <device>/<port>
3) devlink port param show <device>/<port> name <param_name>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
Documentation/netlink/specs/devlink.yaml | 13 ++--
include/net/devlink.h | 1 +
net/devlink/netlink_gen.c | 16 ++++-
net/devlink/param.c | 88 ++++++++++++++++++++----
4 files changed, 99 insertions(+), 19 deletions(-)
diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
index 05fee1b7fe19..f48fd83567c6 100644
--- a/Documentation/netlink/specs/devlink.yaml
+++ b/Documentation/netlink/specs/devlink.yaml
@@ -1852,12 +1852,17 @@ operations:
pre: devlink-nl-pre-doit-port
post: devlink-nl-post-doit
request:
- attributes: *port-id-attrs
- reply:
- attributes: *port-id-attrs
+ attributes: &port-param-id-attrs
+ - bus-name
+ - dev-name
+ - port-index
+ - param-name
+ reply: &port-param-get-reply
+ attributes: *port-param-id-attrs
dump:
- reply:
+ request:
attributes: *port-id-attrs
+ reply: *port-param-get-reply
-
name: port-param-set
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 11f98e3a750b..b409ccbcfd12 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -439,6 +439,7 @@ union devlink_param_value {
struct devlink_param_gset_ctx {
union devlink_param_value val;
enum devlink_param_cmode cmode;
+ struct devlink_port *devlink_port;
};
/**
diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c
index f9786d51f68f..d4876cf0f049 100644
--- a/net/devlink/netlink_gen.c
+++ b/net/devlink/netlink_gen.c
@@ -322,7 +322,15 @@ static const struct nla_policy devlink_region_read_nl_policy[DEVLINK_ATTR_REGION
};
/* DEVLINK_CMD_PORT_PARAM_GET - do */
-static const struct nla_policy devlink_port_param_get_nl_policy[DEVLINK_ATTR_PORT_INDEX + 1] = {
+static const struct nla_policy devlink_port_param_get_do_nl_policy[DEVLINK_ATTR_PARAM_NAME + 1] = {
+ [DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
+ [DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
+ [DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32, },
+ [DEVLINK_ATTR_PARAM_NAME] = { .type = NLA_NUL_STRING, },
+};
+
+/* DEVLINK_CMD_PORT_PARAM_GET - dump */
+static const struct nla_policy devlink_port_param_get_dump_nl_policy[DEVLINK_ATTR_PORT_INDEX + 1] = {
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
[DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32, },
@@ -938,14 +946,16 @@ const struct genl_split_ops devlink_nl_ops[74] = {
.pre_doit = devlink_nl_pre_doit_port,
.doit = devlink_nl_port_param_get_doit,
.post_doit = devlink_nl_post_doit,
- .policy = devlink_port_param_get_nl_policy,
- .maxattr = DEVLINK_ATTR_PORT_INDEX,
+ .policy = devlink_port_param_get_do_nl_policy,
+ .maxattr = DEVLINK_ATTR_PARAM_NAME,
.flags = GENL_CMD_CAP_DO,
},
{
.cmd = DEVLINK_CMD_PORT_PARAM_GET,
.validate = GENL_DONT_VALIDATE_DUMP_STRICT,
.dumpit = devlink_nl_port_param_get_dumpit,
+ .policy = devlink_port_param_get_dump_nl_policy,
+ .maxattr = DEVLINK_ATTR_PORT_INDEX,
.flags = GENL_CMD_CAP_DUMP,
},
{
diff --git a/net/devlink/param.c b/net/devlink/param.c
index 4656d16cd51a..918ee1abd4b4 100644
--- a/net/devlink/param.c
+++ b/net/devlink/param.c
@@ -153,11 +153,14 @@ devlink_param_cmode_is_supported(const struct devlink_param *param,
}
static int devlink_param_get(struct devlink *devlink,
+ struct devlink_port *devlink_port,
const struct devlink_param *param,
struct devlink_param_gset_ctx *ctx)
{
if (!param->get)
return -EOPNOTSUPP;
+
+ ctx->devlink_port = devlink_port;
return param->get(devlink, param->id, ctx);
}
@@ -249,7 +252,7 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
union devlink_param_value param_value[DEVLINK_PARAM_CMODE_MAX + 1];
bool param_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
const struct devlink_param *param = param_item->param;
- struct devlink_param_gset_ctx ctx;
+ struct devlink_param_gset_ctx ctx = {};
struct nlattr *param_values_list;
struct nlattr *param_attr;
int var_attr_type;
@@ -270,7 +273,7 @@ static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
return -EOPNOTSUPP;
} else {
ctx.cmode = i;
- err = devlink_param_get(devlink, param, &ctx);
+ err = devlink_param_get(devlink, devlink_port, param, &ctx);
if (err)
return err;
param_value[i] = ctx.val;
@@ -505,15 +508,17 @@ devlink_param_get_from_info(struct xarray *params, struct genl_info *info)
return devlink_param_find_by_name(params, param_name);
}
-int devlink_nl_param_get_doit(struct sk_buff *skb,
- struct genl_info *info)
+static int __devlink_nl_param_get_doit(struct devlink *devlink,
+ struct devlink_port *devlink_port,
+ struct xarray *params,
+ struct genl_info *info,
+ enum devlink_command cmd)
{
- struct devlink *devlink = info->user_ptr[0];
struct devlink_param_item *param_item;
struct sk_buff *msg;
int err;
- param_item = devlink_param_get_from_info(&devlink->params, info);
+ param_item = devlink_param_get_from_info(params, info);
if (!param_item)
return -EINVAL;
@@ -521,8 +526,7 @@ int devlink_nl_param_get_doit(struct sk_buff *skb,
if (!msg)
return -ENOMEM;
- err = devlink_nl_param_fill(msg, devlink, NULL, param_item,
- DEVLINK_CMD_PARAM_GET,
+ err = devlink_nl_param_fill(msg, devlink, devlink_port, param_item, cmd,
info->snd_portid, info->snd_seq, 0);
if (err) {
nlmsg_free(msg);
@@ -532,6 +536,14 @@ int devlink_nl_param_get_doit(struct sk_buff *skb,
return genlmsg_reply(msg, info);
}
+int devlink_nl_param_get_doit(struct sk_buff *skb, struct genl_info *info)
+{
+ struct devlink *devlink = info->user_ptr[0];
+
+ return __devlink_nl_param_get_doit(devlink, NULL, &devlink->params,
+ info, DEVLINK_CMD_PARAM_GET);
+}
+
static int __devlink_nl_cmd_param_set_doit(struct devlink *devlink,
struct devlink_port *devlink_port,
struct xarray *params,
@@ -595,18 +607,70 @@ int devlink_nl_param_set_doit(struct sk_buff *skb, struct genl_info *info)
info, DEVLINK_CMD_PARAM_NEW);
}
+static int
+devlink_nl_port_param_get_dump_one(struct sk_buff *msg,
+ struct devlink *devlink,
+ struct netlink_callback *cb,
+ int flags)
+{
+ struct devlink_nl_dump_state *state = devlink_dump_state(cb);
+ const struct genl_info *info = genl_info_dump(cb);
+ unsigned long port_index_end = ULONG_MAX;
+ struct devlink_param_item *param_item;
+ struct nlattr **attrs = info->attrs;
+ unsigned long port_index_start = 0;
+ struct devlink_port *devlink_port;
+ unsigned long port_index;
+ unsigned long param_id;
+ int idx = 0;
+ int err = 0;
+
+ if (attrs && attrs[DEVLINK_ATTR_PORT_INDEX]) {
+ port_index_start = nla_get_u32(attrs[DEVLINK_ATTR_PORT_INDEX]);
+ port_index_end = port_index_start;
+ flags |= NLM_F_DUMP_FILTERED;
+ }
+
+ xa_for_each_range(&devlink->ports, port_index, devlink_port,
+ port_index_start, port_index_end) {
+ xa_for_each_start(&devlink_port->params, param_id, param_item,
+ state->idx) {
+ if (idx < state->idx) {
+ idx++;
+ continue;
+ }
+ err = devlink_nl_param_fill(msg, devlink, devlink_port,
+ param_item,
+ DEVLINK_CMD_PORT_PARAM_GET,
+ NETLINK_CB(cb->skb).portid,
+ cb->nlh->nlmsg_seq, flags);
+ if (err == -EOPNOTSUPP) {
+ err = 0;
+ } else if (err) {
+ state->idx = param_id;
+ break;
+ }
+ }
+ }
+
+ return err;
+}
+
int devlink_nl_port_param_get_dumpit(struct sk_buff *msg,
struct netlink_callback *cb)
{
- NL_SET_ERR_MSG(cb->extack, "Port params are not supported");
- return msg->len;
+ return devlink_nl_dumpit(msg, cb, devlink_nl_port_param_get_dump_one);
}
int devlink_nl_port_param_get_doit(struct sk_buff *skb,
struct genl_info *info)
{
- NL_SET_ERR_MSG(info->extack, "Port params are not supported");
- return -EINVAL;
+ struct devlink_port *devlink_port = info->user_ptr[1];
+ struct devlink *devlink = info->user_ptr[0];
+
+ return __devlink_nl_param_get_doit(devlink, devlink_port,
+ &devlink_port->params,
+ info, DEVLINK_CMD_PORT_PARAM_GET);
}
int devlink_nl_port_param_set_doit(struct sk_buff *skb,
--
2.49.0
next prev parent reply other threads:[~2025-04-25 21:48 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-25 21:47 [PATCH net-next V3 00/15] devlink, mlx5: Add new parameters for link management and SRIOV/eSwitch configurations Saeed Mahameed
2025-04-25 21:47 ` [PATCH net-next V3 01/15] tools: ynl-gen: allow noncontiguous enums Saeed Mahameed
2025-04-28 23:06 ` Jakub Kicinski
2025-04-29 7:22 ` Jiri Pirko
2025-04-25 21:47 ` [PATCH net-next V3 02/15] devlink: define enum for attr types of dynamic attributes Saeed Mahameed
2025-04-28 23:10 ` Jakub Kicinski
2025-04-29 7:20 ` Jiri Pirko
2025-04-29 11:49 ` Jiri Pirko
2025-04-29 17:01 ` Jakub Kicinski
2025-04-25 21:47 ` [PATCH net-next V3 03/15] devlink: Add 'total_vfs' generic device param Saeed Mahameed
2025-04-25 21:47 ` [PATCH net-next V3 04/15] net/mlx5: Implement cqe_compress_type via devlink params Saeed Mahameed
2025-04-25 21:47 ` [PATCH net-next V3 05/15] net/mlx5: Implement devlink enable_sriov parameter Saeed Mahameed
2025-04-25 21:47 ` [PATCH net-next V3 06/15] net/mlx5: Implement devlink total_vfs parameter Saeed Mahameed
2025-04-25 21:48 ` [PATCH net-next V3 07/15] devlink: pass struct devlink_port * as arg to devlink_nl_param_fill() Saeed Mahameed
2025-04-25 21:48 ` [PATCH net-next V3 08/15] devlink: Implement port params registration Saeed Mahameed
2025-04-25 21:48 ` Saeed Mahameed [this message]
2025-04-25 21:48 ` [PATCH net-next V3 10/15] devlink: Implement set netlink command for port params Saeed Mahameed
2025-04-25 21:48 ` [PATCH net-next V3 11/15] devlink: Add 'keep_link_up' generic devlink device param Saeed Mahameed
2025-04-25 21:48 ` [PATCH net-next V3 12/15] net/mlx5: Implement devlink keep_link_up port parameter Saeed Mahameed
2025-04-25 21:48 ` [PATCH net-next V3 13/15] devlink: Throw extack messages on param value validation error Saeed Mahameed
2025-04-25 21:48 ` [PATCH net-next V3 14/15] devlink: Implement devlink param multi attribute nested data values Saeed Mahameed
2025-04-28 23:17 ` Jakub Kicinski
2025-04-29 11:34 ` Jiri Pirko
2025-04-29 13:54 ` Przemek Kitszel
2025-04-29 16:33 ` Jiri Pirko
2025-04-29 16:58 ` Jakub Kicinski
2025-04-30 6:24 ` Jiri Pirko
2025-05-02 11:16 ` Jiri Pirko
2025-04-25 21:48 ` [PATCH net-next V3 15/15] net/mlx5: Implement eSwitch hairpin per prio buffers devlink params Saeed Mahameed
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=20250425214808.507732-10-saeed@kernel.org \
--to=saeed@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=jiri@nvidia.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 \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.