netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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>
Subject: [PATCH net-next V6 12/13] devlink: Implement devlink param multi attribute nested data values
Date: Tue,  8 Jul 2025 20:04:54 -0700	[thread overview]
Message-ID: <20250709030456.1290841-13-saeed@kernel.org> (raw)
In-Reply-To: <20250709030456.1290841-1-saeed@kernel.org>

From: Saeed Mahameed <saeedm@nvidia.com>

Devlink param value attribute is not defined since devlink is handling
the value validating and parsing internally, this allows us to implement
multi attribute values without breaking any policies.

Devlink param multi-attribute values are considered to be dynamically
sized arrays of u32 values, by introducing a new devlink param type
DEVLINK_PARAM_TYPE_ARR_U32, driver and user space can set a variable
count of u32 values into the DEVLINK_ATTR_PARAM_VALUE_DATA attribute.

Implement get/set parsing and add to the internal value structure passed
to drivers.

This is useful for devices that need to configure a list of values for
a specific configuration.

example:
 $ devlink dev param show pci/... name multi-value-param
    name multi-value-param type driver-specific
    values:
      cmode permanent value: 0,1,2,3,4,5,6,7

 $ devlink dev param set pci/... name multi-value-param \
	value 4,5,6,7,0,1,2,3 cmode permanent

Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 Documentation/netlink/specs/devlink.yaml |  3 ++
 include/net/devlink.h                    |  7 ++++
 include/uapi/linux/devlink.h             |  1 +
 net/devlink/netlink_gen.c                |  2 ++
 net/devlink/param.c                      | 42 +++++++++++++++++++++++-
 5 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
index 606070ae75f5..441fd0aa34f3 100644
--- a/Documentation/netlink/specs/devlink.yaml
+++ b/Documentation/netlink/specs/devlink.yaml
@@ -224,6 +224,9 @@ definitions:
         value: 10
       -
         name: binary
+      -
+        name: u32-array
+        value: 129
   -
     name: rate-tc-index-max
     type: const
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 13331194e143..93bd5cc7911b 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -422,12 +422,15 @@ typedef u64 devlink_resource_occ_get_t(void *priv);
 #define DEVLINK_RESOURCE_GENERIC_NAME_PORTS "physical_ports"
 
 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
+#define __DEVLINK_PARAM_MAX_ARRAY_SIZE 32
+
 enum devlink_param_type {
 	DEVLINK_PARAM_TYPE_U8 = DEVLINK_VAR_ATTR_TYPE_U8,
 	DEVLINK_PARAM_TYPE_U16 = DEVLINK_VAR_ATTR_TYPE_U16,
 	DEVLINK_PARAM_TYPE_U32 = DEVLINK_VAR_ATTR_TYPE_U32,
 	DEVLINK_PARAM_TYPE_STRING = DEVLINK_VAR_ATTR_TYPE_STRING,
 	DEVLINK_PARAM_TYPE_BOOL = DEVLINK_VAR_ATTR_TYPE_FLAG,
+	DEVLINK_PARAM_TYPE_ARR_U32 = DEVLINK_VAR_ATTR_TYPE_U32_ARRAY,
 };
 
 union devlink_param_value {
@@ -436,6 +439,10 @@ union devlink_param_value {
 	u32 vu32;
 	char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
 	bool vbool;
+	struct {
+		u32 size;
+		u32 vu32[__DEVLINK_PARAM_MAX_ARRAY_SIZE];
+	} arr;
 };
 
 struct devlink_param_gset_ctx {
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index e72bcc239afd..7597c2481476 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -403,6 +403,7 @@ enum devlink_var_attr_type {
 	DEVLINK_VAR_ATTR_TYPE_BINARY,
 	__DEVLINK_VAR_ATTR_TYPE_CUSTOM_BASE = 0x80,
 	/* Any possible custom types, unrelated to NLA_* values go below */
+	DEVLINK_VAR_ATTR_TYPE_U32_ARRAY,
 };
 
 enum devlink_attr {
diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c
index 0c2e58e75022..7201caa7a7ed 100644
--- a/net/devlink/netlink_gen.c
+++ b/net/devlink/netlink_gen.c
@@ -31,6 +31,8 @@ devlink_attr_param_type_validate(const struct nlattr *attr,
 	case DEVLINK_VAR_ATTR_TYPE_NUL_STRING:
 		fallthrough;
 	case DEVLINK_VAR_ATTR_TYPE_BINARY:
+		fallthrough;
+	case DEVLINK_VAR_ATTR_TYPE_U32_ARRAY:
 		return 0;
 	}
 	NL_SET_ERR_MSG_ATTR(extack, attr, "invalid enum value");
diff --git a/net/devlink/param.c b/net/devlink/param.c
index 7b6affea459e..e30d5b54d364 100644
--- a/net/devlink/param.c
+++ b/net/devlink/param.c
@@ -225,6 +225,13 @@ devlink_nl_param_value_fill_one(struct sk_buff *msg,
 		    nla_put_flag(msg, DEVLINK_ATTR_PARAM_VALUE_DATA))
 			goto value_nest_cancel;
 		break;
+	case DEVLINK_PARAM_TYPE_ARR_U32:
+		for (int i = 0; i < val.arr.size; i++) {
+			if (nla_put_u32(msg, DEVLINK_ATTR_PARAM_VALUE_DATA,
+					val.arr.vu32[i]))
+				goto value_nest_cancel;
+		}
+		break;
 	}
 
 	nla_nest_end(msg, param_value_attr);
@@ -428,7 +435,7 @@ devlink_param_value_validate(struct genl_info *info,
 {
 	struct netlink_ext_ack *extack = info->extack;
 	struct nlattr *param_data;
-	int len = 0;
+	int len = 0, rem;
 
 	if (type != DEVLINK_PARAM_TYPE_BOOL &&
 	    GENL_REQ_ATTR_CHECK(info, DEVLINK_ATTR_PARAM_VALUE_DATA))
@@ -479,6 +486,28 @@ devlink_param_value_validate(struct genl_info *info,
 			return 0;
 		NL_SET_ERR_MSG_MOD(extack, "String too long");
 		break;
+	case DEVLINK_PARAM_TYPE_ARR_U32:
+		len = 0;
+		nla_for_each_attr_type(param_data,
+				       DEVLINK_ATTR_PARAM_VALUE_DATA,
+				       genlmsg_data(info->genlhdr),
+				       genlmsg_len(info->genlhdr), rem) {
+			if (nla_len(param_data) != sizeof(u32)) {
+				NL_SET_ERR_MSG_MOD(extack,
+						   "Array element size must be 4 bytes");
+				return -EINVAL;
+			}
+			if (++len > __DEVLINK_PARAM_MAX_ARRAY_SIZE) {
+				NL_SET_ERR_MSG_MOD(extack,
+						   "Array size exceeds maximum");
+				return -EINVAL;
+			}
+		}
+		if (len)
+			return 0;
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Value array must have at least one entry");
+		break;
 	default:
 		NL_SET_ERR_MSG_FMT_MOD(extack,
 				       "Not supported value type %d", type);
@@ -493,6 +522,7 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
 				  union devlink_param_value *value)
 {
 	struct nlattr *param_data;
+	int rem, i = 0;
 
 	if (devlink_param_value_validate(info, param->type))
 		return -EINVAL;
@@ -515,6 +545,16 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
 	case DEVLINK_PARAM_TYPE_BOOL:
 		value->vbool = nla_get_flag(param_data);
 		break;
+	case DEVLINK_PARAM_TYPE_ARR_U32: {
+		nla_for_each_attr_type(param_data,
+				       DEVLINK_ATTR_PARAM_VALUE_DATA,
+				       genlmsg_data(info->genlhdr),
+				       genlmsg_len(info->genlhdr), rem)
+			value->arr.vu32[i++] = nla_get_u32(param_data);
+
+		value->arr.size = i;
+		break;
+		}
 	}
 	return 0;
 }
-- 
2.50.0


  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 ` [PATCH net-next V6 04/13] net/mlx5: Implement devlink total_vfs parameter Saeed Mahameed
2025-07-09  8:37   ` 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 ` Saeed Mahameed [this message]
2025-07-09  8:41   ` [PATCH net-next V6 12/13] devlink: Implement devlink param multi attribute nested data values 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-13-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=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 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).