Blame SOURCES/0059-devlink-Add-param-command-support.patch

99be8f
From 8bd31b6df5fd1da612accbb4d131b3c3bcded079 Mon Sep 17 00:00:00 2001
99be8f
From: Andrea Claudi <aclaudi@redhat.com>
99be8f
Date: Mon, 25 Mar 2019 11:40:58 +0100
99be8f
Subject: [PATCH] devlink: Add param command support
99be8f
99be8f
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1644731
99be8f
Upstream Status: iproute2.git commit 13925ae9eb38b
99be8f
Conflicts: context change due to missing commit 844646a52837f
99be8f
           ("devlink: Change empty line indication with indentations")
99be8f
99be8f
commit 13925ae9eb38b99107be1d3fe21a1b73cf40bd97
99be8f
Author: Moshe Shemesh <moshe@mellanox.com>
99be8f
Date:   Wed Jul 4 17:12:06 2018 +0300
99be8f
99be8f
    devlink: Add param command support
99be8f
99be8f
    Add support for configuration parameters set and show.
99be8f
    Each parameter can be either generic or driver-specific.
99be8f
    The user can retrieve data on these configuration parameters by devlink
99be8f
    param show command and can set new value to a configuration parameter
99be8f
    by devlink param set command.
99be8f
    The configuration parameters can be set in different configuration
99be8f
    modes:
99be8f
      runtime - set while driver is running, no reset required.
99be8f
      driverinit - applied while driver initializes, requires restart
99be8f
                   driver by devlink reload command.
99be8f
      permanent - written to device's non-volatile memory, hard reset
99be8f
                  required to apply.
99be8f
99be8f
    New commands added:
99be8f
      devlink dev param show [DEV name PARAMETER]
99be8f
      devlink dev param set DEV name PARAMETER value VALUE
99be8f
                                cmode { permanent | driverinit | runtime }
99be8f
99be8f
    Signed-off-by: Moshe Shemesh <moshe@mellanox.com>
99be8f
    Signed-off-by: Jiri Pirko <jiri@mellanox.com>
99be8f
    Signed-off-by: David Ahern <dsahern@gmail.com>
99be8f
---
99be8f
 devlink/devlink.c      | 454 +++++++++++++++++++++++++++++++++++++++++
99be8f
 man/man8/devlink-dev.8 |  57 ++++++
99be8f
 2 files changed, 511 insertions(+)
99be8f
99be8f
diff --git a/devlink/devlink.c b/devlink/devlink.c
99be8f
index fc3939e564bc8..92e78c9c8d9f6 100644
99be8f
--- a/devlink/devlink.c
99be8f
+++ b/devlink/devlink.c
99be8f
@@ -33,6 +33,10 @@
99be8f
 #define ESWITCH_INLINE_MODE_NETWORK "network"
99be8f
 #define ESWITCH_INLINE_MODE_TRANSPORT "transport"
99be8f
 
99be8f
+#define PARAM_CMODE_RUNTIME_STR "runtime"
99be8f
+#define PARAM_CMODE_DRIVERINIT_STR "driverinit"
99be8f
+#define PARAM_CMODE_PERMANENT_STR "permanent"
99be8f
+
99be8f
 #define pr_err(args...) fprintf(stderr, ##args)
99be8f
 #define pr_out(args...)						\
99be8f
 	do {							\
99be8f
@@ -179,6 +183,9 @@ static void ifname_map_free(struct ifname_map *ifname_map)
99be8f
 #define DL_OPT_ESWITCH_ENCAP_MODE	BIT(15)
99be8f
 #define DL_OPT_RESOURCE_PATH	BIT(16)
99be8f
 #define DL_OPT_RESOURCE_SIZE	BIT(17)
99be8f
+#define DL_OPT_PARAM_NAME	BIT(18)
99be8f
+#define DL_OPT_PARAM_VALUE	BIT(19)
99be8f
+#define DL_OPT_PARAM_CMODE	BIT(20)
99be8f
 
99be8f
 struct dl_opts {
99be8f
 	uint32_t present; /* flags of present items */
99be8f
@@ -203,6 +210,9 @@ struct dl_opts {
99be8f
 	uint32_t resource_size;
99be8f
 	uint32_t resource_id;
99be8f
 	bool resource_id_valid;
99be8f
+	const char *param_name;
99be8f
+	const char *param_value;
99be8f
+	enum devlink_param_cmode cmode;
99be8f
 };
99be8f
 
99be8f
 struct dl {
99be8f
@@ -340,6 +350,12 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
99be8f
 	[DEVLINK_ATTR_DPIPE_FIELD_ID] = MNL_TYPE_U32,
99be8f
 	[DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH] = MNL_TYPE_U32,
99be8f
 	[DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE] = MNL_TYPE_U32,
99be8f
+	[DEVLINK_ATTR_PARAM] = MNL_TYPE_NESTED,
99be8f
+	[DEVLINK_ATTR_PARAM_NAME] = MNL_TYPE_STRING,
99be8f
+	[DEVLINK_ATTR_PARAM_TYPE] = MNL_TYPE_U8,
99be8f
+	[DEVLINK_ATTR_PARAM_VALUES_LIST] = MNL_TYPE_NESTED,
99be8f
+	[DEVLINK_ATTR_PARAM_VALUE] = MNL_TYPE_NESTED,
99be8f
+	[DEVLINK_ATTR_PARAM_VALUE_CMODE] = MNL_TYPE_U8,
99be8f
 };
99be8f
 
99be8f
 static int attr_cb(const struct nlattr *attr, void *data)
99be8f
@@ -506,6 +522,34 @@ static int strtouint16_t(const char *str, uint16_t *p_val)
99be8f
 	return 0;
99be8f
 }
99be8f
 
99be8f
+static int strtouint8_t(const char *str, uint8_t *p_val)
99be8f
+{
99be8f
+	char *endptr;
99be8f
+	unsigned long int val;
99be8f
+
99be8f
+	val = strtoul(str, &endptr, 10);
99be8f
+	if (endptr == str || *endptr != '\0')
99be8f
+		return -EINVAL;
99be8f
+	if (val > UCHAR_MAX)
99be8f
+		return -ERANGE;
99be8f
+	*p_val = val;
99be8f
+	return 0;
99be8f
+}
99be8f
+
99be8f
+static int strtobool(const char *str, bool *p_val)
99be8f
+{
99be8f
+	bool val;
99be8f
+
99be8f
+	if (!strcmp(str, "true") || !strcmp(str, "1"))
99be8f
+		val = true;
99be8f
+	else if (!strcmp(str, "false") || !strcmp(str, "0"))
99be8f
+		val = false;
99be8f
+	else
99be8f
+		return -EINVAL;
99be8f
+	*p_val = val;
99be8f
+	return 0;
99be8f
+}
99be8f
+
99be8f
 static int __dl_argv_handle(char *str, char **p_bus_name, char **p_dev_name)
99be8f
 {
99be8f
 	strslashrsplit(str, p_bus_name, p_dev_name);
99be8f
@@ -776,6 +820,22 @@ static int eswitch_encap_mode_get(const char *typestr, bool *p_mode)
99be8f
 	return 0;
99be8f
 }
99be8f
 
99be8f
+static int param_cmode_get(const char *cmodestr,
99be8f
+			   enum devlink_param_cmode *cmode)
99be8f
+{
99be8f
+	if (strcmp(cmodestr, PARAM_CMODE_RUNTIME_STR) == 0) {
99be8f
+		*cmode = DEVLINK_PARAM_CMODE_RUNTIME;
99be8f
+	} else if (strcmp(cmodestr, PARAM_CMODE_DRIVERINIT_STR) == 0) {
99be8f
+		*cmode = DEVLINK_PARAM_CMODE_DRIVERINIT;
99be8f
+	} else if (strcmp(cmodestr, PARAM_CMODE_PERMANENT_STR) == 0) {
99be8f
+		*cmode = DEVLINK_PARAM_CMODE_PERMANENT;
99be8f
+	} else {
99be8f
+		pr_err("Unknown configuration mode \"%s\"\n", cmodestr);
99be8f
+		return -EINVAL;
99be8f
+	}
99be8f
+	return 0;
99be8f
+}
99be8f
+
99be8f
 static int dl_argv_parse(struct dl *dl, uint32_t o_required,
99be8f
 			 uint32_t o_optional)
99be8f
 {
99be8f
@@ -957,6 +1017,32 @@ static int dl_argv_parse(struct dl *dl, uint32_t o_required,
99be8f
 			if (err)
99be8f
 				return err;
99be8f
 			o_found |= DL_OPT_RESOURCE_SIZE;
99be8f
+		} else if (dl_argv_match(dl, "name") &&
99be8f
+			   (o_all & DL_OPT_PARAM_NAME)) {
99be8f
+			dl_arg_inc(dl);
99be8f
+			err = dl_argv_str(dl, &opts->param_name);
99be8f
+			if (err)
99be8f
+				return err;
99be8f
+			o_found |= DL_OPT_PARAM_NAME;
99be8f
+		} else if (dl_argv_match(dl, "value") &&
99be8f
+			   (o_all & DL_OPT_PARAM_VALUE)) {
99be8f
+			dl_arg_inc(dl);
99be8f
+			err = dl_argv_str(dl, &opts->param_value);
99be8f
+			if (err)
99be8f
+				return err;
99be8f
+			o_found |= DL_OPT_PARAM_VALUE;
99be8f
+		} else if (dl_argv_match(dl, "cmode") &&
99be8f
+			   (o_all & DL_OPT_PARAM_CMODE)) {
99be8f
+			const char *cmodestr;
99be8f
+
99be8f
+			dl_arg_inc(dl);
99be8f
+			err = dl_argv_str(dl, &cmodestr);
99be8f
+			if (err)
99be8f
+				return err;
99be8f
+			err = param_cmode_get(cmodestr, &opts->cmode);
99be8f
+			if (err)
99be8f
+				return err;
99be8f
+			o_found |= DL_OPT_PARAM_CMODE;
99be8f
 		} else {
99be8f
 			pr_err("Unknown option \"%s\"\n", dl_argv(dl));
99be8f
 			return -EINVAL;
99be8f
@@ -1041,6 +1127,24 @@ static int dl_argv_parse(struct dl *dl, uint32_t o_required,
99be8f
 		return -EINVAL;
99be8f
 	}
99be8f
 
99be8f
+	if ((o_required & DL_OPT_PARAM_NAME) &&
99be8f
+	    !(o_found & DL_OPT_PARAM_NAME)) {
99be8f
+		pr_err("Parameter name expected.\n");
99be8f
+		return -EINVAL;
99be8f
+	}
99be8f
+
99be8f
+	if ((o_required & DL_OPT_PARAM_VALUE) &&
99be8f
+	    !(o_found & DL_OPT_PARAM_VALUE)) {
99be8f
+		pr_err("Value to set expected.\n");
99be8f
+		return -EINVAL;
99be8f
+	}
99be8f
+
99be8f
+	if ((o_required & DL_OPT_PARAM_CMODE) &&
99be8f
+	    !(o_found & DL_OPT_PARAM_CMODE)) {
99be8f
+		pr_err("Configuration mode expected.\n");
99be8f
+		return -EINVAL;
99be8f
+	}
99be8f
+
99be8f
 	return 0;
99be8f
 }
99be8f
 
99be8f
@@ -1105,6 +1209,12 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
99be8f
 	if (opts->present & DL_OPT_RESOURCE_SIZE)
99be8f
 		mnl_attr_put_u64(nlh, DEVLINK_ATTR_RESOURCE_SIZE,
99be8f
 				 opts->resource_size);
99be8f
+	if (opts->present & DL_OPT_PARAM_NAME)
99be8f
+		mnl_attr_put_strz(nlh, DEVLINK_ATTR_PARAM_NAME,
99be8f
+				  opts->param_name);
99be8f
+	if (opts->present & DL_OPT_PARAM_CMODE)
99be8f
+		mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_VALUE_CMODE,
99be8f
+				opts->cmode);
99be8f
 }
99be8f
 
99be8f
 static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
99be8f
@@ -1163,6 +1273,8 @@ static void cmd_dev_help(void)
99be8f
 	pr_err("                               [ inline-mode { none | link | network | transport } ]\n");
99be8f
 	pr_err("                               [ encap { disable | enable } ]\n");
99be8f
 	pr_err("       devlink dev eswitch show DEV\n");
99be8f
+	pr_err("       devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n");
99be8f
+	pr_err("       devlink dev param show [DEV name PARAMETER]\n");
99be8f
 	pr_err("       devlink dev reload DEV\n");
99be8f
 }
99be8f
 
99be8f
@@ -1377,6 +1489,14 @@ static void pr_out_str(struct dl *dl, const char *name, const char *val)
99be8f
 	}
99be8f
 }
99be8f
 
99be8f
+static void pr_out_bool(struct dl *dl, const char *name, bool val)
99be8f
+{
99be8f
+	if (val)
99be8f
+		pr_out_str(dl, name, "true");
99be8f
+	else
99be8f
+		pr_out_str(dl, name, "false");
99be8f
+}
99be8f
+
99be8f
 static void pr_out_uint(struct dl *dl, const char *name, unsigned int val)
99be8f
 {
99be8f
 	if (dl->json_output) {
99be8f
@@ -1449,6 +1569,19 @@ static void pr_out_entry_end(struct dl *dl)
99be8f
 		__pr_out_newline();
99be8f
 }
99be8f
 
99be8f
+static const char *param_cmode_name(uint8_t cmode)
99be8f
+{
99be8f
+	switch (cmode) {
99be8f
+	case DEVLINK_PARAM_CMODE_RUNTIME:
99be8f
+		return PARAM_CMODE_RUNTIME_STR;
99be8f
+	case DEVLINK_PARAM_CMODE_DRIVERINIT:
99be8f
+		return PARAM_CMODE_DRIVERINIT_STR;
99be8f
+	case DEVLINK_PARAM_CMODE_PERMANENT:
99be8f
+		return PARAM_CMODE_PERMANENT_STR;
99be8f
+	default: return "<unknown type>";
99be8f
+	}
99be8f
+}
99be8f
+
99be8f
 static const char *eswitch_mode_name(uint32_t mode)
99be8f
 {
99be8f
 	switch (mode) {
99be8f
@@ -1567,6 +1700,304 @@ static int cmd_dev_eswitch(struct dl *dl)
99be8f
 	return -ENOENT;
99be8f
 }
99be8f
 
99be8f
+static void pr_out_param_value(struct dl *dl, int nla_type, struct nlattr *nl)
99be8f
+{
99be8f
+	struct nlattr *nla_value[DEVLINK_ATTR_MAX + 1] = {};
99be8f
+	struct nlattr *val_attr;
99be8f
+	int err;
99be8f
+
99be8f
+	err = mnl_attr_parse_nested(nl, attr_cb, nla_value);
99be8f
+	if (err != MNL_CB_OK)
99be8f
+		return;
99be8f
+
99be8f
+	if (!nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE] ||
99be8f
+	    (nla_type != MNL_TYPE_FLAG &&
99be8f
+	     !nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA]))
99be8f
+		return;
99be8f
+
99be8f
+	pr_out_str(dl, "cmode",
99be8f
+		   param_cmode_name(mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE])));
99be8f
+	val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA];
99be8f
+
99be8f
+	switch (nla_type) {
99be8f
+	case MNL_TYPE_U8:
99be8f
+		pr_out_uint(dl, "value", mnl_attr_get_u8(val_attr));
99be8f
+		break;
99be8f
+	case MNL_TYPE_U16:
99be8f
+		pr_out_uint(dl, "value", mnl_attr_get_u16(val_attr));
99be8f
+		break;
99be8f
+	case MNL_TYPE_U32:
99be8f
+		pr_out_uint(dl, "value", mnl_attr_get_u32(val_attr));
99be8f
+		break;
99be8f
+	case MNL_TYPE_STRING:
99be8f
+		pr_out_str(dl, "value", mnl_attr_get_str(val_attr));
99be8f
+		break;
99be8f
+	case MNL_TYPE_FLAG:
99be8f
+		pr_out_bool(dl, "value", val_attr ? true : false);
99be8f
+		break;
99be8f
+	}
99be8f
+}
99be8f
+
99be8f
+static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array)
99be8f
+{
99be8f
+	struct nlattr *nla_param[DEVLINK_ATTR_MAX + 1] = {};
99be8f
+	struct nlattr *param_value_attr;
99be8f
+	int nla_type;
99be8f
+	int err;
99be8f
+
99be8f
+	err = mnl_attr_parse_nested(tb[DEVLINK_ATTR_PARAM], attr_cb, nla_param);
99be8f
+	if (err != MNL_CB_OK)
99be8f
+		return;
99be8f
+	if (!nla_param[DEVLINK_ATTR_PARAM_NAME] ||
99be8f
+	    !nla_param[DEVLINK_ATTR_PARAM_TYPE] ||
99be8f
+	    !nla_param[DEVLINK_ATTR_PARAM_VALUES_LIST])
99be8f
+		return;
99be8f
+
99be8f
+	if (array)
99be8f
+		pr_out_handle_start_arr(dl, tb);
99be8f
+	else
99be8f
+		__pr_out_handle_start(dl, tb, true, false);
99be8f
+
99be8f
+	nla_type = mnl_attr_get_u8(nla_param[DEVLINK_ATTR_PARAM_TYPE]);
99be8f
+
99be8f
+	pr_out_str(dl, "name",
99be8f
+		   mnl_attr_get_str(nla_param[DEVLINK_ATTR_PARAM_NAME]));
99be8f
+
99be8f
+	if (!nla_param[DEVLINK_ATTR_PARAM_GENERIC])
99be8f
+		pr_out_str(dl, "type", "driver-specific");
99be8f
+	else
99be8f
+		pr_out_str(dl, "type", "generic");
99be8f
+
99be8f
+	pr_out_array_start(dl, "values");
99be8f
+	mnl_attr_for_each_nested(param_value_attr,
99be8f
+				 nla_param[DEVLINK_ATTR_PARAM_VALUES_LIST]) {
99be8f
+		pr_out_entry_start(dl);
99be8f
+		pr_out_param_value(dl, nla_type, param_value_attr);
99be8f
+		pr_out_entry_end(dl);
99be8f
+	}
99be8f
+	pr_out_array_end(dl);
99be8f
+	pr_out_handle_end(dl);
99be8f
+}
99be8f
+
99be8f
+static int cmd_dev_param_show_cb(const struct nlmsghdr *nlh, void *data)
99be8f
+{
99be8f
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
99be8f
+	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
99be8f
+	struct dl *dl = data;
99be8f
+
99be8f
+	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
99be8f
+	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
99be8f
+	    !tb[DEVLINK_ATTR_PARAM])
99be8f
+		return MNL_CB_ERROR;
99be8f
+	pr_out_param(dl, tb, true);
99be8f
+	return MNL_CB_OK;
99be8f
+}
99be8f
+
99be8f
+struct param_ctx {
99be8f
+	struct dl *dl;
99be8f
+	int nla_type;
99be8f
+	union {
99be8f
+		uint8_t vu8;
99be8f
+		uint16_t vu16;
99be8f
+		uint32_t vu32;
99be8f
+		const char *vstr;
99be8f
+		bool vbool;
99be8f
+	} value;
99be8f
+};
99be8f
+
99be8f
+static int cmd_dev_param_set_cb(const struct nlmsghdr *nlh, void *data)
99be8f
+{
99be8f
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
99be8f
+	struct nlattr *nla_param[DEVLINK_ATTR_MAX + 1] = {};
99be8f
+	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
99be8f
+	struct nlattr *param_value_attr;
99be8f
+	enum devlink_param_cmode cmode;
99be8f
+	struct param_ctx *ctx = data;
99be8f
+	struct dl *dl = ctx->dl;
99be8f
+	int nla_type;
99be8f
+	int err;
99be8f
+
99be8f
+	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
99be8f
+	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
99be8f
+	    !tb[DEVLINK_ATTR_PARAM])
99be8f
+		return MNL_CB_ERROR;
99be8f
+
99be8f
+	err = mnl_attr_parse_nested(tb[DEVLINK_ATTR_PARAM], attr_cb, nla_param);
99be8f
+	if (err != MNL_CB_OK)
99be8f
+		return MNL_CB_ERROR;
99be8f
+
99be8f
+	if (!nla_param[DEVLINK_ATTR_PARAM_TYPE] ||
99be8f
+	    !nla_param[DEVLINK_ATTR_PARAM_VALUES_LIST])
99be8f
+		return MNL_CB_ERROR;
99be8f
+
99be8f
+	nla_type = mnl_attr_get_u8(nla_param[DEVLINK_ATTR_PARAM_TYPE]);
99be8f
+	mnl_attr_for_each_nested(param_value_attr,
99be8f
+				 nla_param[DEVLINK_ATTR_PARAM_VALUES_LIST]) {
99be8f
+		struct nlattr *nla_value[DEVLINK_ATTR_MAX + 1] = {};
99be8f
+		struct nlattr *val_attr;
99be8f
+
99be8f
+		err = mnl_attr_parse_nested(param_value_attr,
99be8f
+					    attr_cb, nla_value);
99be8f
+		if (err != MNL_CB_OK)
99be8f
+			return MNL_CB_ERROR;
99be8f
+
99be8f
+		if (!nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE] ||
99be8f
+		    (nla_type != MNL_TYPE_FLAG &&
99be8f
+		     !nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA]))
99be8f
+			return MNL_CB_ERROR;
99be8f
+
99be8f
+		cmode = mnl_attr_get_u8(nla_value[DEVLINK_ATTR_PARAM_VALUE_CMODE]);
99be8f
+		if (cmode == dl->opts.cmode) {
99be8f
+			val_attr = nla_value[DEVLINK_ATTR_PARAM_VALUE_DATA];
99be8f
+			switch (nla_type) {
99be8f
+			case MNL_TYPE_U8:
99be8f
+				ctx->value.vu8 = mnl_attr_get_u8(val_attr);
99be8f
+				break;
99be8f
+			case MNL_TYPE_U16:
99be8f
+				ctx->value.vu16 = mnl_attr_get_u16(val_attr);
99be8f
+				break;
99be8f
+			case MNL_TYPE_U32:
99be8f
+				ctx->value.vu32 = mnl_attr_get_u32(val_attr);
99be8f
+				break;
99be8f
+			case MNL_TYPE_STRING:
99be8f
+				ctx->value.vstr = mnl_attr_get_str(val_attr);
99be8f
+				break;
99be8f
+			case MNL_TYPE_FLAG:
99be8f
+				ctx->value.vbool = val_attr ? true : false;
99be8f
+				break;
99be8f
+			}
99be8f
+			break;
99be8f
+		}
99be8f
+	}
99be8f
+	ctx->nla_type = nla_type;
99be8f
+	return MNL_CB_OK;
99be8f
+}
99be8f
+
99be8f
+static int cmd_dev_param_set(struct dl *dl)
99be8f
+{
99be8f
+	struct param_ctx ctx = {};
99be8f
+	struct nlmsghdr *nlh;
99be8f
+	uint32_t val_u32;
99be8f
+	uint16_t val_u16;
99be8f
+	uint8_t val_u8;
99be8f
+	bool val_bool;
99be8f
+	int err;
99be8f
+
99be8f
+	err = dl_argv_parse(dl, DL_OPT_HANDLE |
99be8f
+			    DL_OPT_PARAM_NAME |
99be8f
+			    DL_OPT_PARAM_VALUE |
99be8f
+			    DL_OPT_PARAM_CMODE, 0);
99be8f
+	if (err)
99be8f
+		return err;
99be8f
+
99be8f
+	/* Get value type */
99be8f
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PARAM_GET,
99be8f
+			       NLM_F_REQUEST | NLM_F_ACK);
99be8f
+	dl_opts_put(nlh, dl);
99be8f
+
99be8f
+	ctx.dl = dl;
99be8f
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_param_set_cb, &ctx;;
99be8f
+	if (err)
99be8f
+		return err;
99be8f
+
99be8f
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PARAM_SET,
99be8f
+			       NLM_F_REQUEST | NLM_F_ACK);
99be8f
+	dl_opts_put(nlh, dl);
99be8f
+
99be8f
+	mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_TYPE, ctx.nla_type);
99be8f
+	switch (ctx.nla_type) {
99be8f
+	case MNL_TYPE_U8:
99be8f
+		err = strtouint8_t(dl->opts.param_value, &val_u8);
99be8f
+		if (err)
99be8f
+			goto err_param_value_parse;
99be8f
+		if (val_u8 == ctx.value.vu8)
99be8f
+			return 0;
99be8f
+		mnl_attr_put_u8(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA, val_u8);
99be8f
+		break;
99be8f
+	case MNL_TYPE_U16:
99be8f
+		err = strtouint16_t(dl->opts.param_value, &val_u16);
99be8f
+		if (err)
99be8f
+			goto err_param_value_parse;
99be8f
+		if (val_u16 == ctx.value.vu16)
99be8f
+			return 0;
99be8f
+		mnl_attr_put_u16(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA, val_u16);
99be8f
+		break;
99be8f
+	case MNL_TYPE_U32:
99be8f
+		err = strtouint32_t(dl->opts.param_value, &val_u32);
99be8f
+		if (err)
99be8f
+			goto err_param_value_parse;
99be8f
+		if (val_u32 == ctx.value.vu32)
99be8f
+			return 0;
99be8f
+		mnl_attr_put_u32(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA, val_u32);
99be8f
+		break;
99be8f
+	case MNL_TYPE_FLAG:
99be8f
+		err = strtobool(dl->opts.param_value, &val_bool);
99be8f
+		if (err)
99be8f
+			goto err_param_value_parse;
99be8f
+		if (val_bool == ctx.value.vbool)
99be8f
+			return 0;
99be8f
+		if (val_bool)
99be8f
+			mnl_attr_put(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA,
99be8f
+				     0, NULL);
99be8f
+		break;
99be8f
+	case MNL_TYPE_STRING:
99be8f
+		mnl_attr_put_strz(nlh, DEVLINK_ATTR_PARAM_VALUE_DATA,
99be8f
+				  dl->opts.param_value);
99be8f
+		if (!strcmp(dl->opts.param_value, ctx.value.vstr))
99be8f
+			return 0;
99be8f
+		break;
99be8f
+	default:
99be8f
+		printf("Value type not supported\n");
99be8f
+		return -ENOTSUP;
99be8f
+	}
99be8f
+	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
99be8f
+
99be8f
+err_param_value_parse:
99be8f
+	pr_err("Value \"%s\" is not a number or not within range\n",
99be8f
+	       dl->opts.param_value);
99be8f
+	return err;
99be8f
+}
99be8f
+
99be8f
+static int cmd_dev_param_show(struct dl *dl)
99be8f
+{
99be8f
+	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
99be8f
+	struct nlmsghdr *nlh;
99be8f
+	int err;
99be8f
+
99be8f
+	if (dl_argc(dl) == 0)
99be8f
+		flags |= NLM_F_DUMP;
99be8f
+
99be8f
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_PARAM_GET, flags);
99be8f
+
99be8f
+	if (dl_argc(dl) > 0) {
99be8f
+		err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE |
99be8f
+					DL_OPT_PARAM_NAME, 0);
99be8f
+		if (err)
99be8f
+			return err;
99be8f
+	}
99be8f
+
99be8f
+	pr_out_section_start(dl, "param");
99be8f
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dev_param_show_cb, dl);
99be8f
+	pr_out_section_end(dl);
99be8f
+	return err;
99be8f
+}
99be8f
+
99be8f
+static int cmd_dev_param(struct dl *dl)
99be8f
+{
99be8f
+	if (dl_argv_match(dl, "help")) {
99be8f
+		cmd_dev_help();
99be8f
+		return 0;
99be8f
+	} else if (dl_argv_match(dl, "show") ||
99be8f
+		   dl_argv_match(dl, "list") || dl_no_arg(dl)) {
99be8f
+		dl_arg_inc(dl);
99be8f
+		return cmd_dev_param_show(dl);
99be8f
+	} else if (dl_argv_match(dl, "set")) {
99be8f
+		dl_arg_inc(dl);
99be8f
+		return cmd_dev_param_set(dl);
99be8f
+	}
99be8f
+	pr_err("Command \"%s\" not found\n", dl_argv(dl));
99be8f
+	return -ENOENT;
99be8f
+}
99be8f
 static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
99be8f
 {
99be8f
 	struct dl *dl = data;
99be8f
@@ -1643,6 +2074,9 @@ static int cmd_dev(struct dl *dl)
99be8f
 	} else if (dl_argv_match(dl, "reload")) {
99be8f
 		dl_arg_inc(dl);
99be8f
 		return cmd_dev_reload(dl);
99be8f
+	} else if (dl_argv_match(dl, "param")) {
99be8f
+		dl_arg_inc(dl);
99be8f
+		return cmd_dev_param(dl);
99be8f
 	}
99be8f
 	pr_err("Command \"%s\" not found\n", dl_argv(dl));
99be8f
 	return -ENOENT;
99be8f
@@ -2586,6 +3020,10 @@ static const char *cmd_name(uint8_t cmd)
99be8f
 	case DEVLINK_CMD_PORT_SET: return "set";
99be8f
 	case DEVLINK_CMD_PORT_NEW: return "net";
99be8f
 	case DEVLINK_CMD_PORT_DEL: return "del";
99be8f
+	case DEVLINK_CMD_PARAM_GET: return "get";
99be8f
+	case DEVLINK_CMD_PARAM_SET: return "set";
99be8f
+	case DEVLINK_CMD_PARAM_NEW: return "new";
99be8f
+	case DEVLINK_CMD_PARAM_DEL: return "del";
99be8f
 	default: return "<unknown cmd>";
99be8f
 	}
99be8f
 }
99be8f
@@ -2604,6 +3042,11 @@ static const char *cmd_obj(uint8_t cmd)
99be8f
 	case DEVLINK_CMD_PORT_NEW:
99be8f
 	case DEVLINK_CMD_PORT_DEL:
99be8f
 		return "port";
99be8f
+	case DEVLINK_CMD_PARAM_GET:
99be8f
+	case DEVLINK_CMD_PARAM_SET:
99be8f
+	case DEVLINK_CMD_PARAM_NEW:
99be8f
+	case DEVLINK_CMD_PARAM_DEL:
99be8f
+		return "param";
99be8f
 	default: return "<unknown obj>";
99be8f
 	}
99be8f
 }
99be8f
@@ -2660,6 +3103,17 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
99be8f
 		pr_out_mon_header(genl->cmd);
99be8f
 		pr_out_port(dl, tb);
99be8f
 		break;
99be8f
+	case DEVLINK_CMD_PARAM_GET: /* fall through */
99be8f
+	case DEVLINK_CMD_PARAM_SET: /* fall through */
99be8f
+	case DEVLINK_CMD_PARAM_NEW: /* fall through */
99be8f
+	case DEVLINK_CMD_PARAM_DEL:
99be8f
+		mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
99be8f
+		if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
99be8f
+		    !tb[DEVLINK_ATTR_PARAM])
99be8f
+			return MNL_CB_ERROR;
99be8f
+		pr_out_mon_header(genl->cmd);
99be8f
+		pr_out_param(dl, tb, false);
99be8f
+		break;
99be8f
 	}
99be8f
 	return MNL_CB_OK;
99be8f
 }
99be8f
diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
99be8f
index 7c749ddabaeeb..d985da172aa05 100644
99be8f
--- a/man/man8/devlink-dev.8
99be8f
+++ b/man/man8/devlink-dev.8
99be8f
@@ -42,6 +42,23 @@ devlink-dev \- devlink device configuration
99be8f
 .BR "devlink dev eswitch show"
99be8f
 .IR DEV
99be8f
 
99be8f
+.ti -8
99be8f
+.BR "devlink dev param set"
99be8f
+.IR DEV
99be8f
+.BR name
99be8f
+.IR PARAMETER
99be8f
+.BR value
99be8f
+.IR VALUE
99be8f
+.BR cmode " { " runtime " | " driverinit " | " permanent " } "
99be8f
+
99be8f
+.ti -8
99be8f
+.BR "devlink dev param show"
99be8f
+.RI "[ "
99be8f
+.IR DEV
99be8f
+.BR name
99be8f
+.IR PARAMETER
99be8f
+.RI "]"
99be8f
+
99be8f
 .ti -8
99be8f
 .BR "devlink dev reload"
99be8f
 .IR DEV
99be8f
@@ -98,6 +115,36 @@ Set eswitch encapsulation support
99be8f
 .I enable
99be8f
 - Enable encapsulation support
99be8f
 
99be8f
+.SS devlink dev param set  - set new value to devlink device configuration parameter
99be8f
+
99be8f
+.TP
99be8f
+.BI name " PARAMETER"
99be8f
+Specify parameter name to set.
99be8f
+
99be8f
+.TP
99be8f
+.BI value " VALUE"
99be8f
+New value to set.
99be8f
+
99be8f
+.TP
99be8f
+.BR cmode " { " runtime " | " driverinit " | " permanent " } "
99be8f
+Configuration mode in which the new value is set.
99be8f
+
99be8f
+.I runtime
99be8f
+- Set new value while driver is running. This configuration mode doesn't require any reset to apply the new value.
99be8f
+
99be8f
+.I driverinit
99be8f
+- Set new value which will be applied during driver initialization. This configuration mode requires restart driver by devlink reload command to apply the new value.
99be8f
+
99be8f
+.I permanent
99be8f
+- New value is written to device's non-volatile memory. This configuration mode requires hard reset to apply the new value.
99be8f
+
99be8f
+.SS devlink dev param show - display devlink device supported configuration parameters attributes
99be8f
+
99be8f
+.BR name
99be8f
+.IR PARAMETER
99be8f
+Specify parameter name to show.
99be8f
+If this argument is omitted all parameters supported by devlink devices are listed.
99be8f
+
99be8f
 .SS devlink dev reload - perform hot reload of the driver.
99be8f
 
99be8f
 .PP
99be8f
@@ -126,6 +173,16 @@ devlink dev eswitch set pci/0000:01:00.0 mode switchdev
99be8f
 Sets the eswitch mode of specified devlink device to switchdev.
99be8f
 .RE
99be8f
 .PP
99be8f
+devlink dev param show pci/0000:01:00.0 name max_macs
99be8f
+.RS 4
99be8f
+Shows the parameter max_macs attributes.
99be8f
+.RE
99be8f
+.PP
99be8f
+devlink dev param set pci/0000:01:00.0 name internal_error_reset value true cmode runtime
99be8f
+.RS 4
99be8f
+Sets the parameter internal_error_reset of specified devlink device to true.
99be8f
+.RE
99be8f
+.PP
99be8f
 devlink dev reload pci/0000:01:00.0
99be8f
 .RS 4
99be8f
 Performs hot reload of specified devlink device.
99be8f
-- 
d30c09
2.21.0
99be8f