Skip to contentSkip to conversation

net: pse-pd: realtek-pse-mcu: establish power management configuration

PATCH In review Jonas Jelonek 3 participants 7 messages Nov 16 – Nov 23

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover net: pse-pd: realtek-pse-mcu: establish power management configuration

Realtek PSE MCUs may start with a power-management configuration inherited from firmware defaults or previous host configuration. This series establishes an explicit configuration during probe: dynamic power management with port priorities and, when a VMAIN regulator is provided, an aggregate limit matching the board's usable PoE allowance.

The budget and management mode are configured before ungating ports. VMAIN is used only for budget accounting, with managed reservation cleanup; the rail is available independently of the host driver.

Validation includes W=1 builds and checkpatch.pl. OpenCode assisted with review, implementation refinements and drafting this cover letter.

---
Changes in v2:
- Move the binding first and clarify accounting-only use of VMAIN.
- Preserved Acked-by from Rob and Reviewed-by from Kory
- Set the mode directly in the helper and shorten names to "mgmt".
- Remove explicit VMAIN enable/disable; retain managed budget cleanup.
- Drop the unrelated global-disable teardown patch.

v1: https://lore.kernel.org/netdev/[email protected]/

---
Jonas Jelonek (2):
dt-bindings: net: pse-pd: realtek,pse-mcu: add VMAIN supply
net: pse-pd: realtek-pse-mcu: configure global power budget

Russell Senior (1):
net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management

 .../net/pse-pd/realtek,pse-mcu-gen1.yaml      |   9 +
 drivers/net/pse-pd/realtek-pse-mcu-core.c     | 155 +++++++++++++++++-
 drivers/net/pse-pd/realtek-pse-mcu.h          |   3 +
 3 files changed, 164 insertions(+), 3 deletions(-)

base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6

Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/3 dt-bindings: net: pse-pd: realtek,pse-mcu: add VMAIN supply

Describe the VMAIN supply at the MCU controller level. The rail feeds the PoE subsystem as a whole rather than an individual PI. Its regulator power budget defines the aggregate limit programmed into the MCU.

Require a finite regulator power budget dedicated to this MCU, representing the PoE power allocation of the system. The rail is available independently of the host driver, which uses the supply reference for budget accounting.

---
 .../bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml        | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml +9 -0
index 526f8525bb4d..6acb5fb641c1 100644
@@ -92,6 +92,15 @@ properties:
       asserted.
     maxItems: 1
 
+  vmain-supply:
+    description:
+      Regulator representing the PoE power allocation of the 44-57V VMAIN
+      supply. This MCU must be its only power-budget consumer. Its unclaimed
+      power budget is used to configure the MCU global PoE power budget. The
+      regulator must define a finite regulator-power-budget-milliwatt value.
+      The supply is available independently of the host driver and is used
+      for power-budget accounting only.
+
 required:
   - compatible
 
Signature · 1 line
2.53.0
#2 lore raw

PATCH v2 2/3 net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management

In reply to Jonas Jelonek

From: Russell Senior <[email protected]>

The MCU may have any power management mode configuration by default but the driver should ensure that the MCU performs dynamic power management with priorities as advertised. On certain devices, the default MCU configuration ships with another default, possibly preventing any power delivery.

Select the mode before deasserting the hardware port gate, so a failure to establish the management policy does not ungate the ports.

[[email protected]: adjust commit message, macro naming and comment;
shorten command and helper names to "mgmt"; change error handling; select the mode before ungating ports; set dynamic mode with priorities directly in the helper]

---
 drivers/net/pse-pd/realtek-pse-mcu-core.c | 32 +++++++++++++++++++++++
 1 file changed, 32 insertions(+)
drivers/net/pse-pd/realtek-pse-mcu-core.c +32 -0
index c70b09ca2012..d8b6e0503939 100644
@@ -68,10 +68,14 @@
 /* Nominal PSE rail; 802.3at/bt operating range. */
 #define RTPSE_MCU_PSE_VOLTAGE_UV		54000000
 
+/* RTPSE_MCU_CMD_SET_POWER_MGMT_MODE values */
+#define RTPSE_MCU_POWER_MGMT_DYNAMIC_PRIO	0x02	/* dynamic, with port priority */
+
 enum rtpse_mcu_cmd {
 	RTPSE_MCU_CMD_SET_GLOBAL_STATE,
 	RTPSE_MCU_CMD_GET_SYSTEM_INFO,
 	RTPSE_MCU_CMD_GET_EXT_CONFIG,
+	RTPSE_MCU_CMD_SET_POWER_MGMT_MODE,
 
 	RTPSE_MCU_CMD_PORT_ENABLE,
 	RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_TYPE,
@@ -369,6 +373,26 @@ static int rtpse_mcu_set_global_state(struct rtpse_mcu_ctrl *pse, bool enable)
 	return (resp.payload[0] == 0x0) ? 0 : -EIO;
 }
 
+static int rtpse_mcu_set_power_mgmt_mode(struct rtpse_mcu_ctrl *pse)
+{
+	struct rtpse_mcu_msg req, resp;
+	const struct rtpse_mcu_opcode *opc;
+	int ret;
+
+	opc = &pse->dialect->opcode[RTPSE_MCU_CMD_SET_POWER_MGMT_MODE];
+	if (!opc->valid)
+		return -EOPNOTSUPP;
+
+	rtpse_mcu_msg_init(&req, opc->op);
+	req.payload[0] = RTPSE_MCU_POWER_MGMT_DYNAMIC_PRIO;
+
+	ret = rtpse_mcu_do_xfer(pse, &req, &resp);
+	if (ret)
+		return ret;
+
+	return (resp.payload[0] == 0x0) ? 0 : -EIO;
+}
+
 /* Port operations */
 
 static int rtpse_mcu_port_get_status(struct rtpse_mcu_ctrl *pse, unsigned int port,
@@ -826,6 +850,12 @@ int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse)
 	if (ret)
 		return ret;
 
+	/* ensure the MCU does dynamic power management with priorities */
+	ret = rtpse_mcu_set_power_mgmt_mode(pse);
+	if (ret)
+		return dev_err_probe(pse->dev, ret,
+				     "failed to set power management mode\n");
+
 	/*
 	 * Some boards gate all ports through a hardware line; deassert it only
 	 * after the MCU is confirmed, so a discover failure never ungates the
@@ -944,6 +974,7 @@ static const struct rtpse_mcu_dialect rtpse_mcu_dialect_gen2 = {
 		[RTPSE_MCU_CMD_SET_GLOBAL_STATE]	= RTPSE_MCU_OP(0x00),
 		[RTPSE_MCU_CMD_GET_SYSTEM_INFO]		= RTPSE_MCU_OP(0x40),
 		[RTPSE_MCU_CMD_GET_EXT_CONFIG]		= RTPSE_MCU_OP(0x4a),
+		[RTPSE_MCU_CMD_SET_POWER_MGMT_MODE]	= RTPSE_MCU_OP(0x10),
 
 		[RTPSE_MCU_CMD_PORT_ENABLE]		= RTPSE_MCU_OP(0x01),
 		[RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_TYPE] = RTPSE_MCU_OP(0x12),
@@ -964,6 +995,7 @@ static const struct rtpse_mcu_dialect rtpse_mcu_dialect_gen1 = {
 	.opcode = {
 		[RTPSE_MCU_CMD_GET_SYSTEM_INFO]		= RTPSE_MCU_OP(0x20),
 		[RTPSE_MCU_CMD_GET_EXT_CONFIG]		= RTPSE_MCU_OP(0x2b),
+		[RTPSE_MCU_CMD_SET_POWER_MGMT_MODE]	= RTPSE_MCU_OP(0x17),
 
 		[RTPSE_MCU_CMD_PORT_ENABLE]		= RTPSE_MCU_OP(0x00),
 		[RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_TYPE] = RTPSE_MCU_OP(0x15),
Signature · 1 line
2.53.0
#3 lore raw

Re: [PATCH net-next v2 2/3] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] rtpse_mcu_register() (drivers/net/pse-pd/realtek-pse-mcu- core.c:854-857) now fails probe on any error from the new…
- [Low] The commit has no Fixes: tag, but it fixes a user-visible defect in the original driver commit 44566e614d84 ("net: pse-pd: add Realtek…
- [Low] In this commit, the comment above the 'disable-ports' GPIO request in rtpse_mcu_register() (drivers/net/pse-pd/realtek-pse-mcu-…

--

net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management

This adds a command that switches the Realtek PSE MCU to dynamic power management with port priorities. It uses opcode 0x17 on gen1 and 0x10 on gen2. rtpse_mcu_register() sends the command after discovery and before the disable-ports gpio is released, and probe fails if the command fails.

Quoted 5 lines

The MCU may have any power management mode configuration by default but the driver should ensure that the MCU performs dynamic power management with priorities as advertised. On certain devices, the default MCU configuration ships with another default, possibly preventing any power delivery.

[Severity: Low]
This describes a user-visible problem in the original driver. Should the patch carry a Fixes: tag?

Since commit 44566e614d84 ("net: pse-pd: add Realtek PSE MCU core"), rtpse_mcu_register() has set PSE_BUDGET_EVAL_STRAT_DYNAMIC and pis_prio_max. It has never put the MCU into the matching mode. That commit's message says "Power budgeting is left to the MCU firmware; the driver advertises PSE_BUDGET_EVAL_STRAT_DYNAMIC accordingly".

Without the tag, the stable and backport tooling won't pick this up for kernels that already carry the driver. Perhaps:

Fixes 44566e614d84 ("net: pse-pd: add Realtek PSE MCU core")

If the patch is meant to stay in net-next with the VMAIN budget work, could the commit message still name the commit it fixes?

Quoted 4 lines
drivers/net/pse-pd/realtek-pse-mcu-core.c +0 -0
index c70b09ca20122..d8b6e05039397 100644

[ ... ]

drivers/net/pse-pd/realtek-pse-mcu-core.c int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse) · line 857

Quoted 9 lines
drivers/net/pse-pd/realtek-pse-mcu-core.c +5 -0
@@ -826,6 +850,12 @@ int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse)
 	if (ret)
 		return ret;
 
+	/* ensure the MCU does dynamic power management with priorities */
+	ret = rtpse_mcu_set_power_mgmt_mode(pse);
+	if (ret)
+		return dev_err_probe(pse->dev, ret,
+				     "failed to set power management mode\n");

[Severity: Medium]
Could this break probe on boards that worked before this patch?

Both dialects now define the opcode (0x17 for gen1, 0x10 for gen2). That means rtpse_mcu_set_power_mgmt_mode() never takes its -EOPNOTSUPP path. It turns any non-zero status byte from the MCU into -EIO:

	return (resp.payload[0] == 0x0) ? 0 : -EIO;

A NOT_READY reply only gets the three resends inside rtpse_mcu_do_xfer(). It does not get the bounded boot-retry window that rtpse_mcu_discover() uses.

Some firmware variants may reject the command, or fail it with -EAGAIN, -EBADMSG or -EBADE. In that case rtpse_mcu_register() returns before the disable-ports gpio is requested and before devm_pse_controller_register() runs.

On boards with the disable-ports gate, that leaves no PoE at all. On boards without the gate, the MCU keeps its old policy but the kernel registers no PSE controller. Before this patch, those boards probed as long as the firmware default policy was usable.

Is it known that every supported gen1 and gen2 firmware accepts this command? The changelog mentions "change error handling", so a softer variant seems to have been considered. If warning and continuing is not safe, could the commit message explain why the failure needs to be fatal?

drivers/net/pse-pd/realtek-pse-mcu-core.c int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse) · line 861

Quoted 4 lines
drivers/net/pse-pd/realtek-pse-mcu-core.c +1 -0
+
 	/*
 	 * Some boards gate all ports through a hardware line; deassert it only
 	 * after the MCU is confirmed, so a discover failure never ungates the

[Severity: Low]
This isn't a bug, but this comment still names only discovery as the step that has to succeed before the ports are ungated. The new rtpse_mcu_set_power_mgmt_mode() call above is now a precondition too.

The next patch in the series, "net: pse-pd: realtek-pse-mcu: configure global power budget", rewrites this comment to "deassert it only after discovery, budget setup and management-mode selection succeed". That fixes it by the end of the series.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116115224.1454885-1-jonas%40jonasjelonek.de
maintainer
#4 lore raw

Re: [PATCH net-next v2 2/3] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management

Quoted 5 lines · On 11/19/26 06:54, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

Quoted 9 lines

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] rtpse_mcu_register() (drivers/net/pse-pd/realtek-pse-mcu- core.c:854-857) now fails probe on any error from the new…

The above looks like worth to be addressed.

/P

#5 lore raw

PATCH v2 3/3 net: pse-pd: realtek-pse-mcu: configure global power budget

In reply to Jonas Jelonek

Use the optional VMAIN supply's power budget to set the MCU's aggregate PoE limit. Require a finite budget of at least 100 mW and round it down to the protocol's 100 mW units. Reserve that amount through the regulator core and program the limit at the MCU's current budget index before selecting dynamic management and ungating the ports.

VMAIN must already be available: the MCU and downstream PSE managers assume an active rail and provide no dedicated control for it. Use the regulator only for budget accounting, leaving the rail externally controlled or marked with regulator-always-on.

The regulator budget represents the usable PoE allowance. Vendor firmware adds a device-specific guard on top: the UniFi USW Pro Max 24 PoE advertises 400 W but programs 404 W with a 4 W guard. The guard's effect on power management is not sufficiently documented to apply a fixed percentage across devices. Set it to zero rather than add an arbitrary margin to the regulator-derived budget.

Register managed cleanup before hardware initialization so probe failures and driver removal release the regulator reservation. Retain the programmed MCU limit in either case. Boards without vmain-supply keep their existing firmware-configured budget.

---
 drivers/net/pse-pd/realtek-pse-mcu-core.c | 123 +++++++++++++++++++++-
 drivers/net/pse-pd/realtek-pse-mcu.h      |   3 +
 2 files changed, 123 insertions(+), 3 deletions(-)
drivers/net/pse-pd/realtek-pse-mcu-core.c +120 -3
index d8b6e0503939..ae58581a0dad 100644
@@ -34,10 +34,12 @@
 #include <linux/delay.h>
 #include <linux/gpio/consumer.h>
 #include <linux/jiffies.h>
+#include <linux/math.h>
 #include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/property.h>
 #include <linux/pse-pd/pse.h>
+#include <linux/regulator/consumer.h>
 #include <linux/unaligned.h>
 
 #include "realtek-pse-mcu.h"
@@ -62,6 +64,8 @@
 #define RTPSE_MCU_MAX_PORTS			48
 #define RTPSE_MCU_PORT_MAX_PRIORITY		3
 
+#define RTPSE_MCU_GLOBAL_BUDGET_LSB_MW		100
+
 /* Bounded resends when the MCU replies NOT_READY (busy). */
 #define RTPSE_MCU_NOT_READY_RETRIES		3
 
@@ -76,6 +80,8 @@ enum rtpse_mcu_cmd {
 	RTPSE_MCU_CMD_GET_SYSTEM_INFO,
 	RTPSE_MCU_CMD_GET_EXT_CONFIG,
 	RTPSE_MCU_CMD_SET_POWER_MGMT_MODE,
+	RTPSE_MCU_CMD_GET_POWER_STATUS,
+	RTPSE_MCU_CMD_SET_GLOBAL_BUDGET,
 
 	RTPSE_MCU_CMD_PORT_ENABLE,
 	RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_TYPE,
@@ -393,6 +399,84 @@ static int rtpse_mcu_set_power_mgmt_mode(struct rtpse_mcu_ctrl *pse)
 	return (resp.payload[0] == 0x0) ? 0 : -EIO;
 }
 
+static int rtpse_mcu_get_global_budget_idx(struct rtpse_mcu_ctrl *pse, u8 *budget_idx)
+{
+	struct rtpse_mcu_msg req, resp;
+	const struct rtpse_mcu_opcode *opc;
+	int ret;
+
+	opc = &pse->dialect->opcode[RTPSE_MCU_CMD_GET_POWER_STATUS];
+	if (!opc->valid)
+		return -EOPNOTSUPP;
+
+	rtpse_mcu_msg_init(&req, opc->op);
+	ret = rtpse_mcu_do_xfer(pse, &req, &resp);
+	if (ret)
+		return ret;
+
+	if (resp.payload[4] > 0x7)
+		return -ERANGE;
+
+	*budget_idx = resp.payload[4];
+	return 0;
+}
+
+static int rtpse_mcu_set_global_budget(struct rtpse_mcu_ctrl *pse, u8 budget_idx,
+				       u16 budget_raw)
+{
+	const struct rtpse_mcu_opcode *opc;
+	struct rtpse_mcu_msg req, resp;
+	int ret;
+
+	opc = &pse->dialect->opcode[RTPSE_MCU_CMD_SET_GLOBAL_BUDGET];
+	if (!opc->valid)
+		return -EOPNOTSUPP;
+
+	rtpse_mcu_msg_init(&req, opc->op);
+	req.payload[0] = budget_idx;
+	put_unaligned_be16(budget_raw, &req.payload[1]);
+	put_unaligned_be16(0, &req.payload[3]);
+
+	ret = rtpse_mcu_do_xfer(pse, &req, &resp);
+	if (ret)
+		return ret;
+	if (resp.payload[0] != budget_idx || resp.payload[1] != 0)
+		return -EIO;
+
+	return 0;
+}
+
+static int rtpse_mcu_apply_global_budget(struct rtpse_mcu_ctrl *pse,
+					 struct regulator *vmain)
+{
+	int budget, ret;
+	u16 budget_raw;
+	u8 budget_idx;
+
+	budget = regulator_get_unclaimed_power_budget(vmain);
+	if (budget == INT_MAX)
+		return -ENODATA;
+	if (budget < 0 || budget > U16_MAX * RTPSE_MCU_GLOBAL_BUDGET_LSB_MW)
+		return -ERANGE;
+
+	budget = rounddown(budget, RTPSE_MCU_GLOBAL_BUDGET_LSB_MW);
+	if (!budget)
+		return -ERANGE;
+	budget_raw = budget / RTPSE_MCU_GLOBAL_BUDGET_LSB_MW;
+
+	ret = regulator_request_power_budget(vmain, budget);
+	if (ret)
+		return ret;
+	pse->requested_budget_mW = budget;
+
+	ret = rtpse_mcu_get_global_budget_idx(pse, &budget_idx);
+	if (ret)
+		return ret;
+
+	/* Retain the programmed MCU limit even if later probe steps fail. */
+	return rtpse_mcu_set_global_budget(pse, budget_idx, budget_raw);
+}
+
 /* Port operations */
 
 static int rtpse_mcu_port_get_status(struct rtpse_mcu_ctrl *pse, unsigned int port,
@@ -801,6 +885,14 @@ static int rtpse_mcu_discover(struct rtpse_mcu_ctrl *pse, struct rtpse_mcu_info
 	return 0;
 }
 
+static void rtpse_mcu_free_global_budget(void *data)
+{
+	struct rtpse_mcu_ctrl *pse = data;
+
+	if (pse->requested_budget_mW)
+		regulator_free_power_budget(pse->vmain, pse->requested_budget_mW);
+}
+
 static void rtpse_mcu_global_disable(void *data)
 {
 	struct rtpse_mcu_ctrl *pse = data;
@@ -813,6 +905,7 @@ int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse)
 	const struct rtpse_mcu_match_data *match;
 	struct rtpse_mcu_info info;
 	struct gpio_desc *gpiod;
+	struct regulator *vmain;
 	int ret;
 
 	BUILD_BUG_ON(sizeof(struct rtpse_mcu_msg) != RTPSE_MCU_MSG_SIZE);
@@ -837,6 +930,20 @@ int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse)
 		return dev_err_probe(pse->dev, -EINVAL,
 				     "dialect for chip is incomplete\n");
 
+	vmain = devm_regulator_get_optional(pse->dev, "vmain");
+	if (PTR_ERR(vmain) == -ENODEV)
+		vmain = NULL;
+	else if (IS_ERR(vmain))
+		return dev_err_probe(pse->dev, PTR_ERR(vmain),
+				     "failed to get vmain supply\n");
+
+	if (vmain) {
+		pse->vmain = vmain;
+		ret = devm_add_action_or_reset(pse->dev, rtpse_mcu_free_global_budget, pse);
+		if (ret)
+			return ret;
+	}
+
 	/*
 	 * Release the MCU from reset before the first transaction; the
 	 * boot-retry loop in discover() waits for it to answer.
@@ -850,6 +957,13 @@ int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse)
 	if (ret)
 		return ret;
 
+	if (vmain) {
+		ret = rtpse_mcu_apply_global_budget(pse, vmain);
+		if (ret)
+			return dev_err_probe(pse->dev, ret,
+					     "failed to apply global power budget\n");
+	}
+
 	/* ensure the MCU does dynamic power management with priorities */
 	ret = rtpse_mcu_set_power_mgmt_mode(pse);
 	if (ret)
@@ -858,9 +972,8 @@ int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse)
 
 	/*
 	 * Some boards gate all ports through a hardware line; deassert it only
-	 * after the MCU is confirmed, so a discover failure never ungates the
-	 * ports. It is then left to the MCU - not re-gated on unbind or a later
-	 * probe error - so a driver reload doesn't black out PoE.
+	 * after discovery, budget setup and management-mode selection succeed.
+	 * Do not reassert it on unbind or a later probe error.
 	 */
 	gpiod = devm_gpiod_get_optional(pse->dev, "disable-ports", GPIOD_OUT_LOW);
 	if (IS_ERR(gpiod))
@@ -975,6 +1088,8 @@ static const struct rtpse_mcu_dialect rtpse_mcu_dialect_gen2 = {
 		[RTPSE_MCU_CMD_GET_SYSTEM_INFO]		= RTPSE_MCU_OP(0x40),
 		[RTPSE_MCU_CMD_GET_EXT_CONFIG]		= RTPSE_MCU_OP(0x4a),
 		[RTPSE_MCU_CMD_SET_POWER_MGMT_MODE]	= RTPSE_MCU_OP(0x10),
+		[RTPSE_MCU_CMD_GET_POWER_STATUS]	= RTPSE_MCU_OP(0x41),
+		[RTPSE_MCU_CMD_SET_GLOBAL_BUDGET]	= RTPSE_MCU_OP(0x04),
 
 		[RTPSE_MCU_CMD_PORT_ENABLE]		= RTPSE_MCU_OP(0x01),
 		[RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_TYPE] = RTPSE_MCU_OP(0x12),
@@ -996,6 +1111,8 @@ static const struct rtpse_mcu_dialect rtpse_mcu_dialect_gen1 = {
 		[RTPSE_MCU_CMD_GET_SYSTEM_INFO]		= RTPSE_MCU_OP(0x20),
 		[RTPSE_MCU_CMD_GET_EXT_CONFIG]		= RTPSE_MCU_OP(0x2b),
 		[RTPSE_MCU_CMD_SET_POWER_MGMT_MODE]	= RTPSE_MCU_OP(0x17),
+		[RTPSE_MCU_CMD_GET_POWER_STATUS]	= RTPSE_MCU_OP(0x23),
+		[RTPSE_MCU_CMD_SET_GLOBAL_BUDGET]	= RTPSE_MCU_OP(0x18),
 
 		[RTPSE_MCU_CMD_PORT_ENABLE]		= RTPSE_MCU_OP(0x00),
 		[RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_TYPE] = RTPSE_MCU_OP(0x15),
drivers/net/pse-pd/realtek-pse-mcu.h +3 -0
index 5e31dd0993dd..56899ec4d76f 100644
@@ -62,6 +62,7 @@ static inline bool rtpse_mcu_resp_is_final(const struct rtpse_mcu_msg *req,
 struct rtpse_mcu_dialect;
 struct rtpse_mcu_chip_info;
 struct rtpse_mcu_ctrl;
+struct regulator;
 
 /* Per-compatible match data (the of_match .data). */
 struct rtpse_mcu_match_data {
@@ -82,6 +83,8 @@ struct rtpse_mcu_ctrl {
 	const struct rtpse_mcu_dialect *dialect;
 	const struct rtpse_mcu_chip_info *chip;
 	const struct rtpse_mcu_transport_ops *transport;
+	struct regulator *vmain;
+	unsigned int requested_budget_mW;
 	u8 seq;			/* rolling request seq_num, echoed by the MCU */
 };
 
Signature · 1 line
2.53.0
#6 lore raw

Re: [PATCH net-next v2 3/3] net: pse-pd: realtek-pse-mcu: configure global power budget

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] rtpse_mcu_register() (drivers/net/pse-pd/realtek-pse-mcu- core.c:933) gets the optional 'vmain' supply with…
- [Low] rtpse_mcu_get_global_budget_idx() (drivers/net/pse-pd/realtek- pse-mcu-core.c:402-422) reads the MCU's current budget/power-bank…

--

net: pse-pd: realtek-pse-mcu: configure global power budget

This patch takes the power budget of the optional vmain supply and uses it to program the MCU's aggregate PoE limit, in 100 mW units, at the MCU's current budget index. The budget is reserved through the regulator core and released by a devm action. The driver uses the regulator only for budget accounting and never enables it.

Quoted 4 lines
drivers/net/pse-pd/realtek-pse-mcu-core.c +0 -0
index d8b6e05039397..ae58581a0dad8 100644

[ ... ]

Quoted 6 lines
drivers/net/pse-pd/realtek-pse-mcu-core.c +2 -0
@@ -393,6 +399,84 @@ static int rtpse_mcu_set_power_mgmt_mode(struct rtpse_mcu_ctrl *pse)
 	return (resp.payload[0] == 0x0) ? 0 : -EIO;
 }
 
+static int rtpse_mcu_get_global_budget_idx(struct rtpse_mcu_ctrl *pse, u8 *budget_idx)
+{

[ ... ]

Quoted 7 lines
drivers/net/pse-pd/realtek-pse-mcu-core.c +7 -0
+	if (resp.payload[4] > 0x7)
+		return -ERANGE;
+
+	*budget_idx = resp.payload[4];
+	return 0;
+}
+

[ ... ]

Quoted 3 lines
drivers/net/pse-pd/realtek-pse-mcu-core.c +3 -0
+static int rtpse_mcu_apply_global_budget(struct rtpse_mcu_ctrl *pse,
+					 struct regulator *vmain)
+{

[ ... ]

drivers/net/pse-pd/realtek-pse-mcu-core.c static int rtpse_mcu_set_power_mgmt_mode(struct rtpse_mcu_ctrl *pse) · line 478

Quoted 12 lines
drivers/net/pse-pd/realtek-pse-mcu-core.c +12 -0
+	ret = regulator_request_power_budget(vmain, budget);
+	if (ret)
+		return ret;
+	pse->requested_budget_mW = budget;
+
+	ret = rtpse_mcu_get_global_budget_idx(pse, &budget_idx);
+	if (ret)
+		return ret;
+
+	/* Retain the programmed MCU limit even if later probe steps fail. */
+	return rtpse_mcu_set_global_budget(pse, budget_idx, budget_raw);
+}

[Severity: Low]
rtpse_mcu_get_global_budget_idx() accepts payload[4] values from 0 to 7, which suggests the MCU has up to eight budget banks. The limit is written only to the bank that is active at probe time, and the index is never read again. The other banks keep their firmware or EEPROM limits.

What happens if the MCU firmware switches its active bank after probe? For example, PSU presence inputs could change on a board with redundant or hot-plug PSUs. Would the MCU then enforce a firmware default limit that has nothing to do with requested_budget_mW? The reservation in the regulator core and the limit enforced in hardware would then disagree.

It isn't clear that any of the supported boards switch banks at runtime. Programming every bank with the same static value would not obviously be correct either. Should this limitation at least be documented?

[ ... ]

drivers/net/pse-pd/realtek-pse-mcu-core.c int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse) · line 939

Quoted 11 lines
drivers/net/pse-pd/realtek-pse-mcu-core.c +7 -0
@@ -837,6 +930,20 @@ int rtpse_mcu_register(struct rtpse_mcu_ctrl *pse)
 		return dev_err_probe(pse->dev, -EINVAL,
 				     "dialect for chip is incomplete\n");
 
+	vmain = devm_regulator_get_optional(pse->dev, "vmain");
+	if (PTR_ERR(vmain) == -ENODEV)
+		vmain = NULL;
+	else if (IS_ERR(vmain))
+		return dev_err_probe(pse->dev, PTR_ERR(vmain),
+				     "failed to get vmain supply\n");
+

[Severity: Low]
Here vmain is used only for budget accounting. Nothing takes an enable reference on it. There is no regulator_enable(), and no regulator_is_enabled() check runs before the MCU budget is programmed, the ports are ungated and the PSE controller is registered.

The PI regulators that pse_core registers take their supply from each PI's vpwr, not from vmain, so vmain's use_count stays at zero.

Suppose a board describes vmain-supply as a switchable regulator without regulator-always-on, such as a regulator-fixed with an enable GPIO, or one marked only regulator-boot-on. Would regulator_late_cleanup() then switch the PoE rail off after boot?

drivers/regulator/core.c:regulator_late_cleanup() {
    ...
	if (rdev->use_count)
		goto unlock;
    ...
	if (have_full_constraints()) {
		...
		ret = _regulator_do_disable(rdev);
    ...
}

In that case the MCU would still believe the programmed budget is available, and the driver would not report an error.

The commit message says:

Use the regulator only for budget accounting, leaving the rail externally controlled or marked with regulator-always-on.

The binding also says the supply is used for power-budget accounting only, so such a DT would go against the documented expectation.

Would it be worth enforcing that requirement instead of assuming it? That could be a regulator_is_enabled() check at probe, or a regulator_enable() call, which would be a no-op on a truly fixed rail.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116115224.1454885-1-jonas%40jonasjelonek.de