naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone

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

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