[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1745416242-1162653-2-git-send-email-moshe@nvidia.com>
Date: Wed, 23 Apr 2025 16:50:38 +0300
From: Moshe Shemesh <moshe@...dia.com>
To: <netdev@...r.kernel.org>, "David S. Miller" <davem@...emloft.net>, "Eric
Dumazet" <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni
<pabeni@...hat.com>, Simon Horman <horms@...nel.org>, Donald Hunter
<donald.hunter@...il.com>, Jiri Pirko <jiri@...nulli.us>, Jonathan Corbet
<corbet@....net>, Andrew Lunn <andrew+netdev@...n.ch>
CC: Tariq Toukan <tariqt@...dia.com>, Saeed Mahameed <saeedm@...dia.com>,
"Leon Romanovsky" <leonro@...dia.com>, Mark Bloch <mbloch@...dia.com>, Avihai
Horon <avihaih@...dia.com>
Subject: [RFC net-next 1/5] devlink: Add unique identifier to devlink port function
From: Avihai Horon <avihaih@...dia.com>
A function unique identifier (UID) is a vendor defined string of
arbitrary length that universally identifies a function. The function
UID can be reported via devlink dev info.
Add UID attribute to devlink port function that reports the UID of the
function that pertains to the devlink port.
This can be used to unambiguously map between a function and the devlink
port that manages it, and vice versa.
Example output:
$ devlink port show pci/0000:03:00.0/327680 -jp
{
"port": {
"pci/0000:03:00.0/327680": {
"type": "eth",
"netdev": "pf0hpf",
"flavour": "pcipf",
"controller": 1,
"pfnum": 0,
"external": true,
"splittable": false,
"function": {
"hw_addr": "5c:25:73:37:70:5a",
"roce": "enable",
"max_io_eqs": 120,
"uid": "C6A76AD20605BE026D23C14E70B90704F4A5F5B3F304D83B37000732BF861D48MLNXS0D0F0"
}
}
}
}
Signed-off-by: Avihai Horon <avihaih@...dia.com>
---
Documentation/netlink/specs/devlink.yaml | 3 ++
.../networking/devlink/devlink-port.rst | 12 +++++++
include/net/devlink.h | 8 +++++
include/uapi/linux/devlink.h | 1 +
net/devlink/port.c | 32 +++++++++++++++++++
5 files changed, 56 insertions(+)
diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
index bd9726269b4f..f4dade0e3c70 100644
--- a/Documentation/netlink/specs/devlink.yaml
+++ b/Documentation/netlink/specs/devlink.yaml
@@ -894,6 +894,9 @@ attribute-sets:
type: bitfield32
enum: port-fn-attr-cap
enum-as-flags: True
+ -
+ name: uid
+ type: string
-
name: dl-dpipe-tables
diff --git a/Documentation/networking/devlink/devlink-port.rst b/Documentation/networking/devlink/devlink-port.rst
index 9d22d41a7cd1..bb6f0970b322 100644
--- a/Documentation/networking/devlink/devlink-port.rst
+++ b/Documentation/networking/devlink/devlink-port.rst
@@ -328,6 +328,18 @@ interrupt vector.
function:
hw_addr 00:00:00:00:00:00 ipsec_packet disabled max_io_eqs 32
+Function unique identifier
+--------------------------
+A function unique identifier (UID) is a vendor defined string of arbitrary
+length that universally identifies a function. The function UID can be reported
+via devlink dev info.
+
+The devlink port function UID attribute reports the UID of the function that
+pertains to the devlink port.
+
+This can be used to unambiguously map between a function and the devlink port
+that manages it, and vice versa.
+
Subfunction
============
diff --git a/include/net/devlink.h b/include/net/devlink.h
index b8783126c1ed..46fd5b3f3253 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -1627,6 +1627,11 @@ void devlink_free(struct devlink *devlink);
* of event queues. Should be used by device drivers to
* configure maximum number of event queues
* of a function managed by the devlink port.
+ * @port_fn_uid_get: Callback used to get port function's uid. Should be used by
+ * device drivers to report the uid of the function managed by
+ * the devlink port.
+ * @port_fn_uid_max_size: The maximum size of the port function's uid including
+ * the null terminating byte.
*
* Note: Driver should return -EOPNOTSUPP if it doesn't support
* port function (@port_fn_*) handling for a particular port.
@@ -1682,6 +1687,9 @@ struct devlink_port_ops {
int (*port_fn_max_io_eqs_set)(struct devlink_port *devlink_port,
u32 max_eqs,
struct netlink_ext_ack *extack);
+ int (*port_fn_uid_get)(struct devlink_port *devlink_port, char *fuid,
+ struct netlink_ext_ack *extack);
+ size_t port_fn_uid_max_size;
};
void devlink_port_init(struct devlink *devlink,
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 9401aa343673..7b9821433a72 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -687,6 +687,7 @@ enum devlink_port_function_attr {
DEVLINK_PORT_FN_ATTR_CAPS, /* bitfield32 */
DEVLINK_PORT_FN_ATTR_DEVLINK, /* nested */
DEVLINK_PORT_FN_ATTR_MAX_IO_EQS, /* u32 */
+ DEVLINK_PORT_FN_ATTR_UID, /* string */
__DEVLINK_PORT_FUNCTION_ATTR_MAX,
DEVLINK_PORT_FUNCTION_ATTR_MAX = __DEVLINK_PORT_FUNCTION_ATTR_MAX - 1
diff --git a/net/devlink/port.c b/net/devlink/port.c
index 939081a0e615..4d14d1bfab33 100644
--- a/net/devlink/port.c
+++ b/net/devlink/port.c
@@ -207,6 +207,35 @@ static int devlink_port_fn_max_io_eqs_fill(struct devlink_port *port,
return 0;
}
+static int devlink_port_fn_uid_fill(struct devlink_port *port,
+ struct sk_buff *msg,
+ struct netlink_ext_ack *extack,
+ bool *msg_updated)
+{
+ char *fuid;
+ int err;
+
+ if (!port->ops->port_fn_uid_get)
+ return 0;
+
+ fuid = kzalloc(port->ops->port_fn_uid_max_size, GFP_KERNEL);
+ if (!fuid)
+ return -ENOMEM;
+
+ err = port->ops->port_fn_uid_get(port, fuid, extack);
+ if (err) {
+ kfree(fuid);
+ return err == -EOPNOTSUPP ? 0 : err;
+ }
+
+ err = nla_put_string(msg, DEVLINK_PORT_FN_ATTR_UID, fuid);
+ if (!err)
+ *msg_updated = true;
+
+ kfree(fuid);
+ return err;
+}
+
int devlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port)
{
if (devlink_nl_put_handle(msg, devlink_port->devlink))
@@ -468,6 +497,9 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por
if (err)
goto out;
err = devlink_port_fn_max_io_eqs_fill(port, msg, extack, &msg_updated);
+ if (err)
+ goto out;
+ err = devlink_port_fn_uid_fill(port, msg, extack, &msg_updated);
if (err)
goto out;
err = devlink_rel_devlink_handle_put(msg, port->devlink,
--
2.27.0
Powered by blists - more mailing lists