public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Zahka <daniel.zahka@gmail.com>
To: Jiri Pirko <jiri@resnulli.us>,
	"David S. Miller" <davem@davemloft.net>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,  Simon Horman <horms@kernel.org>,
	Donald Hunter <donald.hunter@gmail.com>,
	 David Ahern <dsahern@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Daniel Zahka <daniel.zahka@gmail.com>
Subject: [PATCH iproute2-next v2 2/2] devlink: support displaying and resetting to default params
Date: Fri, 06 Feb 2026 13:11:30 -0800	[thread overview]
Message-ID: <20260206-param-defaults-v2-2-1ce78e2c5a31@gmail.com> (raw)
In-Reply-To: <20260206-param-defaults-v2-0-1ce78e2c5a31@gmail.com>

Add devlink cli support for default param values.

For param-get, any default values provided by the kernel will be
displayed next to the current value. For param-set,
DEVLINK_ATTR_PARAM_RESET_DEFAULT can be included in the request to
request that the parameter be reset to its default value.

Default values of type bool are encoded with a u8 by the kernel to
distinguish "false" from "not present".

Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
 devlink/devlink.c      | 54 ++++++++++++++++++++++++++++++++++++++++++++------
 man/man8/devlink-dev.8 | 22 ++++++++++++++++++--
 2 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 81739291..39b0fac0 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -313,6 +313,7 @@ static int ifname_map_update(struct ifname_map *ifname_map, const char *ifname)
 #define DL_OPT_PORT_FN_MAX_IO_EQS	BIT(58)
 #define DL_OPT_PORT_FN_RATE_TC_BWS	BIT(59)
 #define DL_OPT_HEALTH_REPORTER_BURST_PERIOD	BIT(60)
+#define DL_OPT_PARAM_SET_DEFAULT	BIT(61)
 
 struct dl_opts {
 	uint64_t present; /* flags of present items */
@@ -2011,6 +2012,10 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
 			if (err)
 				return err;
 			o_found |= DL_OPT_PARAM_CMODE;
+		} else if (dl_argv_match(dl, "default") &&
+			   (o_all & DL_OPT_PARAM_SET_DEFAULT)) {
+			dl_arg_inc(dl);
+			o_found |= DL_OPT_PARAM_SET_DEFAULT;
 		} else if (dl_argv_match(dl, "snapshot") &&
 			   (o_all & DL_OPT_REGION_SNAPSHOT_ID)) {
 			dl_arg_inc(dl);
@@ -2672,6 +2677,8 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
 	if (opts->present & DL_OPT_PARAM_CMODE)
 		mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_VALUE_CMODE,
 				opts->cmode);
+	if (opts->present & DL_OPT_PARAM_SET_DEFAULT)
+		mnl_attr_put(nlh, DEVLINK_ATTR_PARAM_RESET_DEFAULT, 0, NULL);
 	if (opts->present & DL_OPT_REGION_SNAPSHOT_ID)
 		mnl_attr_put_u32(nlh, DEVLINK_ATTR_REGION_SNAPSHOT_ID,
 				 opts->region_snapshot_id);
@@ -2839,7 +2846,7 @@ static void cmd_dev_help(void)
 	pr_err("                               [ inline-mode { none | link | network | transport } ]\n");
 	pr_err("                               [ encap-mode { none | basic } ]\n");
 	pr_err("       devlink dev eswitch show DEV\n");
-	pr_err("       devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
+	pr_err("       devlink dev param set DEV name PARAMETER [ value VALUE | default ] cmode { permanent | driverinit | runtime }\n");
 	pr_err("       devlink dev param show [DEV name PARAMETER]\n");
 	pr_err("       devlink dev reload DEV [ netns { PID | NAME | ID } ]\n");
 	pr_err("                              [ action { driver_reinit | fw_activate } ] [ limit no_reset ]\n");
@@ -3504,7 +3511,7 @@ static const struct param_val_conv param_val_conv[] = {
 
 static int pr_out_param_value_print(const char *nla_name, int nla_type,
 				     struct nlattr *val_attr, bool conv_exists,
-				     const char *label)
+				     const char *label, bool flag_as_u8)
 {
 	const char *vstr;
 	int err;
@@ -3562,7 +3569,11 @@ static int pr_out_param_value_print(const char *nla_name, int nla_type,
 			     mnl_attr_get_str(val_attr));
 		break;
 	case MNL_TYPE_FLAG:
-		print_bool(PRINT_ANY, label, "%s", val_attr);
+		if (flag_as_u8)
+			print_bool(PRINT_ANY, label, "%s",
+				   mnl_attr_get_u8(val_attr));
+		else
+			print_bool(PRINT_ANY, label, "%s", val_attr);
 		break;
 	}
 
@@ -3595,7 +3606,18 @@ static void pr_out_param_value(struct dl *dl, const char *nla_name,
 	conv_exists = param_val_conv_exists(param_val_conv, PARAM_VAL_CONV_LEN,
 					    nla_name);
 
-	pr_out_param_value_print(nla_name, nla_type, val_attr, conv_exists, "value");
+	err = pr_out_param_value_print(nla_name, nla_type, val_attr,
+				       conv_exists, "value", false);
+	if (err)
+		return;
+
+	val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DEFAULT];
+	if (val_attr) {
+		err = pr_out_param_value_print(nla_name, nla_type, val_attr,
+					       conv_exists, "default", true);
+		if (err)
+			return;
+	}
 }
 
 static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array,
@@ -3764,11 +3786,23 @@ static int cmd_dev_param_set(struct dl *dl)
 
 	err = dl_argv_parse(dl, DL_OPT_HANDLE |
 			    DL_OPT_PARAM_NAME |
-			    DL_OPT_PARAM_VALUE |
-			    DL_OPT_PARAM_CMODE, 0);
+			    DL_OPT_PARAM_CMODE,
+			    DL_OPT_PARAM_VALUE | DL_OPT_PARAM_SET_DEFAULT);
 	if (err)
 		return err;
 
+	if ((dl->opts.present & DL_OPT_PARAM_VALUE) &&
+	    (dl->opts.present & DL_OPT_PARAM_SET_DEFAULT)) {
+		pr_err("Cannot specify both value and default\n");
+		return -EINVAL;
+	}
+
+	if (!(dl->opts.present & DL_OPT_PARAM_VALUE) &&
+	    !(dl->opts.present & DL_OPT_PARAM_SET_DEFAULT)) {
+		pr_err("Either value or default must be specified\n");
+		return -EINVAL;
+	}
+
 	/* Get value type */
 	nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PARAM_GET,
 			       NLM_F_REQUEST | NLM_F_ACK);
@@ -3783,6 +3817,14 @@ static int cmd_dev_param_set(struct dl *dl)
 		return -ENOTSUP;
 	}
 
+	if (dl->opts.present & DL_OPT_PARAM_SET_DEFAULT) {
+		nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PARAM_SET,
+				       NLM_F_REQUEST | NLM_F_ACK);
+		dl_opts_put(nlh, dl);
+		mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_TYPE, ctx.nla_type);
+		return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL);
+	}
+
 	nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PARAM_SET,
 			       NLM_F_REQUEST | NLM_F_ACK);
 	dl_opts_put(nlh, dl);
diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
index d10b1f9a..ad65f6f8 100644
--- a/man/man8/devlink-dev.8
+++ b/man/man8/devlink-dev.8
@@ -45,8 +45,12 @@ devlink-dev \- devlink device configuration
 .I DEV
 .B name
 .I PARAMETER
+[
 .B value
 .I VALUE
+|
+.B default
+]
 .BR cmode " { " runtime " | " driverinit " | " permanent " } "
 
 .ti -8
@@ -159,7 +163,13 @@ Specify parameter name to set.
 
 .TP
 .BI value " VALUE"
-New value to set.
+New value to set. Mutually exclusive with
+.BR default .
+
+.TP
+.B default
+Restore parameter to its default value. Mutually exclusive with
+.BR value .
 
 .TP
 .BR cmode " { " runtime " | " driverinit " | " permanent " } "
@@ -176,10 +186,13 @@ Configuration mode in which the new value is set.
 
 .SS devlink dev param show - display devlink device supported configuration parameters attributes
 
+.TP
 .B name
 .I PARAMETER
 Specify parameter name to show.
 If this argument is omitted all parameters supported by devlink devices are listed.
+When the kernel provides a default value for a parameter, it will be automatically displayed
+in the output alongside the current value.
 
 .SS devlink dev reload - perform hot reload of the driver.
 
@@ -309,7 +322,7 @@ Sets the eswitch mode of specified devlink device to switchdev.
 .PP
 devlink dev param show pci/0000:01:00.0 name max_macs
 .RS 4
-Shows the parameter max_macs attributes.
+Shows the parameter max_macs attributes. If a default value exists, it will be displayed alongside the current value.
 .RE
 .PP
 devlink dev param set pci/0000:01:00.0 name internal_error_reset value true cmode runtime
@@ -317,6 +330,11 @@ devlink dev param set pci/0000:01:00.0 name internal_error_reset value true cmod
 Sets the parameter internal_error_reset of specified devlink device to true.
 .RE
 .PP
+devlink dev param set pci/0000:01:00.0 name internal_error_reset default cmode runtime
+.RS 4
+Restores the parameter internal_error_reset of specified devlink device to its default value.
+.RE
+.PP
 devlink dev reload pci/0000:01:00.0
 .RS 4
 Performs hot reload of specified devlink device.

-- 
2.47.3


  parent reply	other threads:[~2026-02-06 21:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-06 21:11 [PATCH iproute2-next v2 0/2] devlink: support default flag attr for param-get and param-set commands Daniel Zahka
2026-02-06 21:11 ` [PATCH iproute2-next v2 1/2] devlink: Pull the value printing logic out of pr_out_param_value() Daniel Zahka
2026-02-06 21:11 ` Daniel Zahka [this message]
2026-02-19 17:00 ` [PATCH iproute2-next v2 0/2] devlink: support default flag attr for param-get and param-set commands patchwork-bot+netdevbpf

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=20260206-param-defaults-v2-2-1ce78e2c5a31@gmail.com \
    --to=daniel.zahka@gmail.com \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=dsahern@kernel.org \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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