[PATCH ethtool-next 2/2] ethtool: pse-pd: Add PSE priority and event monitoring support

Kory Maincent posted 2 patches 3 months, 2 weeks ago
[PATCH ethtool-next 2/2] ethtool: pse-pd: Add PSE priority and event monitoring support
Posted by Kory Maincent 3 months, 2 weeks ago
From: Kory Maincent (Dent Project) <kory.maincent@bootlin.com>

Add support for PSE (Power Sourcing Equipment) priority management and
event monitoring capabilities:

- Add priority configuration parameter (prio) for port priority management
- Display power domain index, maximum priority, and current priority
- Add PSE event monitoring support in ethtool monitor command

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
 ethtool.8.in      | 13 ++++++++
 ethtool.c         |  1 +
 netlink/monitor.c |  8 +++++
 netlink/netlink.h |  1 +
 netlink/pse-pd.c  | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 111 insertions(+)

diff --git a/ethtool.8.in b/ethtool.8.in
index 7e164a6..b9025bd 100644
--- a/ethtool.8.in
+++ b/ethtool.8.in
@@ -561,6 +561,7 @@ ethtool \- query or control network driver and hardware settings
 .RB [ c33\-pse\-admin\-control
 .BR enable | disable ]
 .BN c33\-pse\-avail\-pw\-limit N
+.BN prio N
 .HP
 .B ethtool \-\-flash\-module\-firmware
 .I devname
@@ -1893,6 +1894,15 @@ This attribute specifies the allowed power limit ranges in mW for
 configuring the c33-pse-avail-pw-limit parameter. It defines the valid
 power levels that can be assigned to the c33 PSE in compliance with the
 c33 standard.
+.TP
+.B power-domain-index
+This attribute defines the index of the PSE Power Domain.
+.TP
+.B priority-max
+This attribute defines the maximum priority available for the PSE.
+.TP
+.B priority
+This attribute defines the currently configured priority for the PSE.
 
 .RE
 .TP
@@ -1912,6 +1922,9 @@ This parameter manages c33 PSE Admin operations in accordance with the IEEE
 This parameter manages c33 PSE Available Power Limit in mW, in accordance
 with the IEEE 802.3-2022 33.2.4.4 Variables (pse_available_power)
 specification.
+.TP
+.B prio \ N
+This parameter manages port priority.
 
 .RE
 .TP
diff --git a/ethtool.c b/ethtool.c
index 327a2da..281484f 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -6283,6 +6283,7 @@ static const struct option args[] = {
 		.xhelp	= "		[ podl-pse-admin-control enable|disable ]\n"
 			  "		[ c33-pse-admin-control enable|disable ]\n"
 			  "		[ c33-pse-avail-pw-limit N ]\n"
+			  "		[ prio N ]\n"
 	},
 	{
 		.opts	= "--flash-module-firmware",
diff --git a/netlink/monitor.c b/netlink/monitor.c
index ace9b25..cc5163e 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -75,6 +75,10 @@ static struct {
 		.cmd	= ETHTOOL_MSG_MODULE_NTF,
 		.cb	= module_reply_cb,
 	},
+	{
+		.cmd	= ETHTOOL_MSG_PSE_NTF,
+		.cb	= pse_ntf_cb,
+	},
 };
 
 static void clear_filter(struct nl_context *nlctx)
@@ -186,6 +190,10 @@ static struct monitor_option monitor_opts[] = {
 		.pattern	= "--show-module|--set-module",
 		.cmd		= ETHTOOL_MSG_MODULE_NTF,
 	},
+	{
+		.pattern	= "--pse-event",
+		.cmd		= ETHTOOL_MSG_PSE_NTF,
+	},
 };
 
 static bool pattern_match(const char *s, const char *pattern)
diff --git a/netlink/netlink.h b/netlink/netlink.h
index ad2a787..6a91336 100644
--- a/netlink/netlink.h
+++ b/netlink/netlink.h
@@ -92,6 +92,7 @@ int cable_test_tdr_reply_cb(const struct nlmsghdr *nlhdr, void *data);
 int cable_test_tdr_ntf_cb(const struct nlmsghdr *nlhdr, void *data);
 int fec_reply_cb(const struct nlmsghdr *nlhdr, void *data);
 int module_reply_cb(const struct nlmsghdr *nlhdr, void *data);
+int pse_ntf_cb(const struct nlmsghdr *nlhdr, void *data);
 
 /* dump helpers */
 
diff --git a/netlink/pse-pd.c b/netlink/pse-pd.c
index fd1fc4d..41af9de 100644
--- a/netlink/pse-pd.c
+++ b/netlink/pse-pd.c
@@ -13,6 +13,7 @@
 
 #include "../internal.h"
 #include "../common.h"
+#include "bitset.h"
 #include "netlink.h"
 #include "parser.h"
 
@@ -420,6 +421,29 @@ int pse_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 		}
 	}
 
+	if (tb[ETHTOOL_A_PSE_PW_D_ID]) {
+		u32 val;
+
+		val = mnl_attr_get_u32(tb[ETHTOOL_A_PSE_PW_D_ID]);
+		print_uint(PRINT_ANY, "power-domain-index",
+			   "Power domain index: %u\n", val);
+	}
+
+	if (tb[ETHTOOL_A_PSE_PRIO_MAX]) {
+		u32 val;
+
+		val = mnl_attr_get_u32(tb[ETHTOOL_A_PSE_PRIO_MAX]);
+		print_uint(PRINT_ANY, "priority-max",
+			   "Max allowed priority: %u\n", val);
+	}
+
+	if (tb[ETHTOOL_A_PSE_PRIO]) {
+		u32 val;
+
+		val = mnl_attr_get_u32(tb[ETHTOOL_A_PSE_PRIO]);
+		print_uint(PRINT_ANY, "priority", "Priority %u\n", val);
+	}
+
 	close_json_object();
 
 	return MNL_CB_OK;
@@ -452,6 +476,64 @@ int nl_gpse(struct cmd_context *ctx)
 	return ret;
 }
 
+static const char *pse_events_name(u64 val)
+{
+	switch (val) {
+	case ETHTOOL_PSE_EVENT_OVER_CURRENT:
+		return "over-current";
+	case ETHTOOL_PSE_EVENT_OVER_TEMP:
+		return "over-temperature";
+	case ETHTOOL_C33_PSE_EVENT_DETECTION:
+		return "detection";
+	case ETHTOOL_C33_PSE_EVENT_CLASSIFICATION:
+		return "classification";
+	case ETHTOOL_C33_PSE_EVENT_DISCONNECTION:
+		return "disconnection";
+	case ETHTOOL_PSE_EVENT_OVER_BUDGET:
+		return "over-budget";
+	case ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR:
+		return "software power control error";
+	default:
+		return "unknown";
+	}
+}
+
+int pse_ntf_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+	const struct nlattr *tb[ETHTOOL_A_PSE_MAX + 1] = {};
+	struct nl_context *nlctx = data;
+	DECLARE_ATTR_TB_INFO(tb);
+	u64 val;
+	int ret, i;
+
+	ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+	if (ret < 0)
+		return MNL_CB_OK;
+
+	if (!tb[ETHTOOL_A_PSE_NTF_EVENTS])
+		return MNL_CB_OK;
+
+	nlctx->devname = get_dev_name(tb[ETHTOOL_A_PSE_HEADER]);
+	if (!dev_ok(nlctx))
+		return MNL_CB_OK;
+
+	open_json_object(NULL);
+	print_string(PRINT_ANY, "ifname", "PSE event for %s:\n",
+		     nlctx->devname);
+	open_json_array("events", "Events:");
+	val = attr_get_uint(tb[ETHTOOL_A_PSE_NTF_EVENTS]);
+	for (i = 0; 1 << i <= ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR; i++)
+		if (val & 1 << i)
+			print_string(PRINT_ANY, NULL, " %s",
+				     pse_events_name(val & 1 << i));
+	close_json_array("\n");
+	if (ret < 0)
+		return MNL_CB_OK;
+
+	close_json_object();
+	return MNL_CB_OK;
+}
+
 /* PSE_SET */
 
 static const struct lookup_entry_u32 podl_pse_admin_control_values[] = {
@@ -487,6 +569,12 @@ static const struct param_parser spse_params[] = {
 		.handler	= nl_parse_direct_u32,
 		.min_argc	= 1,
 	},
+	{
+		.arg		= "prio",
+		.type		= ETHTOOL_A_PSE_PRIO,
+		.handler	= nl_parse_direct_u32,
+		.min_argc	= 1,
+	},
 	{}
 };
 

-- 
2.43.0
Re: [PATCH ethtool-next 2/2] ethtool: pse-pd: Add PSE priority and event monitoring support
Posted by Michal Kubecek 3 months ago
On Fri, Jun 20, 2025 at 02:33:07PM GMT, Kory Maincent wrote:
> From: Kory Maincent (Dent Project) <kory.maincent@bootlin.com>
> 
> Add support for PSE (Power Sourcing Equipment) priority management and
> event monitoring capabilities:
> 
> - Add priority configuration parameter (prio) for port priority management
> - Display power domain index, maximum priority, and current priority
> - Add PSE event monitoring support in ethtool monitor command
> 
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> ---

This patch adds two different features which do not seem to be related
so closely that they would have to be added in one patch. Could you
please split it into two separate patches?

Michal