[PATCH ethtool v3 3/3] ethtool: pse-pd: Add PSE event monitoring support

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

Add support for PSE (Power Sourcing Equipment) event monitoring
capabilities through the monitor command.

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---

Changes in v3:
- Change event loop limit to not ignore events that could be out of scope.
- Fix incorrect attribute usage.
---
 netlink/monitor.c |  9 ++++++++-
 netlink/netlink.h |  1 +
 netlink/pse-pd.c  | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/netlink/monitor.c b/netlink/monitor.c
index c511389..a16cb97 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -79,6 +79,10 @@ static struct {
 		.cmd	= ETHTOOL_MSG_PLCA_NTF,
 		.cb	= plca_get_cfg_reply_cb,
 	},
+	{
+		.cmd	= ETHTOOL_MSG_PSE_NTF,
+		.cb	= pse_ntf_cb,
+	},
 };
 
 static void clear_filter(struct nl_context *nlctx)
@@ -194,7 +198,10 @@ static struct monitor_option monitor_opts[] = {
 		.pattern	= "--get-plca-cfg|--set-plca-cfg",
 		.cmd		= ETHTOOL_MSG_PLCA_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 290592b..eefedf7 100644
--- a/netlink/netlink.h
+++ b/netlink/netlink.h
@@ -93,6 +93,7 @@ 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 plca_get_cfg_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 f761871..77d599b 100644
--- a/netlink/pse-pd.c
+++ b/netlink/pse-pd.c
@@ -475,6 +475,66 @@ 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_NTF_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_NTF_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;
+	     i < mnl_attr_get_payload_len(tb[ETHTOOL_A_PSE_NTF_EVENTS]) * 8;
+	     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[] = {

-- 
2.43.0
Re: [PATCH ethtool v3 3/3] ethtool: pse-pd: Add PSE event monitoring support
Posted by Oleksij Rempel 1 month, 2 weeks ago
On Wed, Aug 20, 2025 at 11:07:34AM +0200, Kory Maincent wrote:
> From: Kory Maincent (Dent Project) <kory.maincent@bootlin.com>
> 
> Add support for PSE (Power Sourcing Equipment) event monitoring
> capabilities through the monitor command.
> 
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>

Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |