🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
5 messages
5 total messages Started by Jonas Jelonek Sun, 29 Nov 2026 23:46
[PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
#24273
Author: Jonas Jelonek
Date: Sun, 29 Nov 2026 23:46
120 lines
17336 bytes
From: Russell Senior <russell@personaltelco.net>

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.

Both protocol generations define the mode-setting command, and no
firmware lacking it is known. Fail probe if the command fails rather
than register a controller advertising dynamic power management without
having established that policy in the MCU.

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

Fixes: 44566e614d84 ("net: pse-pd: add Realtek PSE MCU core")
Signed-off-by: Russell Senior <russell@personaltelco.net>
[jonas@jonasjelonek.de: 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]
Signed-off-by: Jonas Jelonek <jonas@jonasjelonek.de>
---
 drivers/net/pse-pd/realtek-pse-mcu-core.c | 36 +++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/drivers/net/pse-pd/realtek-pse-mcu-core.c b/drivers/net/pse-pd/realtek-pse-mcu-core.c
index c70b09ca2012..e382045932e9 100644
--- a/drivers/net/pse-pd/realtek-pse-mcu-core.c
+++ b/drivers/net/pse-pd/realtek-pse-mcu-core.c
@@ -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,10 +850,16 @@ 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
-	 * ports. It is then left to the MCU - not re-gated on unbind or a later
+	 * after discovery and management-mode selection succeed.
+	 * 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.
 	 */
 	gpiod = devm_gpiod_get_optional(pse->dev, "disable-ports", GPIOD_OUT_LOW);
@@ -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),

base-commit: fad0d57b12f6979bc0127f0a4f704c6d7177ca78
-- 
2.53.0
Re: [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
#24274
Author: netdev-bot+sinfo
Date: Sun, 29 Nov 2026 23:48
23 lines
8769 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
Re: [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
#24279
Author: Russell Senior
Date: Mon, 30 Nov 2026 00:25
39 lines
13861 bytes
On Sun, Nov 29, 2026 at 3:48 PM <netdev-bot+sinfo@kernel.org> wrote:
>
> Hi!
>
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
>
>  - How the issue was discovered, e.g. hit in production, hit during
>    development, syzbot report, manual code inspection, LLM or static
>    analysis tool scan.

It was discovered during development by a human.

>
>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by LLM and not proven at runtime). If it was triggered
>    please include the symptoms, like the stack trace or kernel messages.

As I recall, the symptoms were that poe didn't work, which led to an
investigation of what the vendor firmware did. This was the thing that
fixed it.

-- 
Russell Senior
russell@personaltelco.net


>
> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account.
>
> *IMPORTANT*: If you do repost (for other reasons) - please include
> the relevant info in the cover letter or commit messages.
> --
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.
Re: [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
#24841
Author: netdev-bot+sashiko
Date: Mon, 30 Nov 2026 23:47
91 lines
11151 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

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

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] In drivers/net/pse-pd/realtek-pse-mcu-core.c,
  rtpse_mcu_register() now forces the MCU into mode 0x02, "dynamic, with…

--

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

This commit adds a SET_POWER_MGMT_MODE command to both dialects: 0x17
for Gen1 and 0x10 for Gen2. rtpse_mcu_register() issues it to put the
MCU into dynamic power management with port priority (mode 0x02). Probe
fails if the command fails, and the mode is selected before the
disable-ports GPIO is deasserted.

> diff --git a/drivers/net/pse-pd/realtek-pse-mcu-core.c b/drivers/net/pse-pd/realtek-pse-mcu-core.c
> index c70b09ca20122..e382045932e9e 100644
> --- a/drivers/net/pse-pd/realtek-pse-mcu-core.c
> +++ b/drivers/net/pse-pd/realtek-pse-mcu-core.c

[ ... ]

> @@ -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;

[Severity: Medium]
Is the global power budget that this mode checks against ever set?

This function writes only the mode byte. enum rtpse_mcu_cmd has no
budget command, and neither the Gen1 nor the Gen2 opcode table maps
one. In the Gen1 command family, 0x18 (next to 0x17) is the set global
power budget command.

The only budget reference in the driver is in rtpse_mcu_register():

    pse->pcdev.supp_budget_eval_strategies = PSE_BUDGET_EVAL_STRAT_DYNAMIC;

pse.h says PSE_BUDGET_EVAL_STRAT_DYNAMIC compares "the current
consumption per ports compared to the total power budget". It also
says this mode "is managed by the PSE controller". pse_core does not do
its own budget accounting for this strategy.

If a board's firmware defaults to a non-managed mode, the MCU used to
ignore its stored budget. With this patch, every probe makes the MCU
enforce whatever budget the firmware holds.

If that budget is below the real supply, or zero, could PDs be refused
or shed? If it is above what the PSU can deliver, could the PSU be
over-committed?

The commit message says the driver should "ensure that the MCU performs
dynamic power management with priorities as advertised". Should the
budget also be programmed here, or at least read back and logged, so
that the policy is actually established?

> +
> +	ret = rtpse_mcu_do_xfer(pse, &req, &resp);
> +	if (ret)
> +		return ret;
> +
> +	return (resp.payload[0] == 0x0) ? 0 : -EIO;
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129234635.3357243-1-jonas%40jonasjelonek.de
Re: [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
#25193
Author: Jonas Jelonek
Date: Tue, 01 Dec 2026 11:35
122 lines
17835 bytes

On 01.12.26 00:47, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
>
> 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] In drivers/net/pse-pd/realtek-pse-mcu-core.c,
>   rtpse_mcu_register() now forces the MCU into mode 0x02, "dynamic, with…
>
> --
>
> net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
>
> This commit adds a SET_POWER_MGMT_MODE command to both dialects: 0x17
> for Gen1 and 0x10 for Gen2. rtpse_mcu_register() issues it to put the
> MCU into dynamic power management with port priority (mode 0x02). Probe
> fails if the command fails, and the mode is selected before the
> disable-ports GPIO is deasserted.
>
>> diff --git a/drivers/net/pse-pd/realtek-pse-mcu-core.c b/drivers/net/pse-pd/realtek-pse-mcu-core.c
>> index c70b09ca20122..e382045932e9e 100644
>> --- a/drivers/net/pse-pd/realtek-pse-mcu-core.c
>> +++ b/drivers/net/pse-pd/realtek-pse-mcu-core.c
> [ ... ]
>
>> @@ -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;
> [Severity: Medium]
> Is the global power budget that this mode checks against ever set?
>
> This function writes only the mode byte. enum rtpse_mcu_cmd has no
> budget command, and neither the Gen1 nor the Gen2 opcode table maps
> one. In the Gen1 command family, 0x18 (next to 0x17) is the set global
> power budget command.
>
> The only budget reference in the driver is in rtpse_mcu_register():
>
>     pse->pcdev.supp_budget_eval_strategies = PSE_BUDGET_EVAL_STRAT_DYNAMIC;
>
> pse.h says PSE_BUDGET_EVAL_STRAT_DYNAMIC compares "the current
> consumption per ports compared to the total power budget". It also
> says this mode "is managed by the PSE controller". pse_core does not do
> its own budget accounting for this strategy.
>
> If a board's firmware defaults to a non-managed mode, the MCU used to
> ignore its stored budget. With this patch, every probe makes the MCU
> enforce whatever budget the firmware holds.
>
> If that budget is below the real supply, or zero, could PDs be refused
> or shed? If it is above what the PSU can deliver, could the PSU be
> over-committed?
>
> The commit message says the driver should "ensure that the MCU performs
> dynamic power management with priorities as advertised". Should the
> budget also be programmed here, or at least read back and logged, so
> that the policy is actually established?

The concern is correct but I would reduce its importance.
The majority of switches already come with a good default configuration.
This change targets a few devices which for whatever reason ship with
IIRC mode 'None', preventing any power delivery. Still, they have a power
budget configured. So when this is set as the patch intends, the MCU will
do the dynamic budgeting with the configured budget.

I cannot exclude that there are devices which both have a power management
mode of 'None' by default and also a bad/zero budget defined. Probably it
exists but no-one has seen it so far, only either isolated case.

This was sent as a separate fix from [1] following the Sashiko suggestion.
It also seems to affect more devices than having to provide a global budget.
I plan to update the global budget on net-next too, this appears to me rather
as a new feature than a fix worth to backport.

If anyone favor having those patches together on either net or net-next,
please say so.

>> +
>> +	ret = rtpse_mcu_do_xfer(pse, &req, &resp);
>> +	if (ret)
>> +		return ret;
>> +
>> +	return (resp.payload[0] == 0x0) ? 0 : -EIO;
>> +}
> [ ... ]
>

[1] https://lore.kernel.org/all/20261116115224.1454885-1-jonas@jonasjelonek.de/

Best,
Jonas
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads