mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
@ 2026-11-29 23:46 Jonas Jelonek
  2026-11-29 23:48 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jonas Jelonek @ 2026-11-29 23:46 UTC (permalink / raw)
  To: Oleksij Rempel, Kory Maincent, Andrew Lunn, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev
  Cc: linux-kernel, Russell Senior, Jonas Jelonek

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
  2026-11-29 23:46 [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management Jonas Jelonek
@ 2026-11-29 23:48 ` netdev-bot+sinfo
  2026-11-30  0:25   ` Russell Senior
  2026-11-30 15:09 ` Kory Maincent
  2026-11-30 23:47 ` netdev-bot+sashiko
  2 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sinfo @ 2026-11-29 23:48 UTC (permalink / raw)
  To: Jonas Jelonek
  Cc: Oleksij Rempel, Kory Maincent, Andrew Lunn, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	Russell Senior

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
  2026-11-29 23:48 ` netdev-bot+sinfo
@ 2026-11-30  0:25   ` Russell Senior
  0 siblings, 0 replies; 5+ messages in thread
From: Russell Senior @ 2026-11-30  0:25 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: Jonas Jelonek, Oleksij Rempel, Kory Maincent, Andrew Lunn,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	netdev, linux-kernel

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
  2026-11-29 23:46 [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management Jonas Jelonek
  2026-11-29 23:48 ` netdev-bot+sinfo
@ 2026-11-30 15:09 ` Kory Maincent
  2026-11-30 23:47 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: Kory Maincent @ 2026-11-30 15:09 UTC (permalink / raw)
  To: Jonas Jelonek, Oleksij Rempel, Andrew Lunn, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev
  Cc: linux-kernel, Russell Senior

On 11/30/26 00:46, Jonas Jelonek wrote:
> 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.

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

Thank you!
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management
  2026-11-29 23:46 [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management Jonas Jelonek
  2026-11-29 23:48 ` netdev-bot+sinfo
  2026-11-30 15:09 ` Kory Maincent
@ 2026-11-30 23:47 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 23:47 UTC (permalink / raw)
  To: jonas
  Cc: o.rempel, kory.maincent, andrew+netdev, davem, edumazet, kuba,
	pabeni, netdev, linux-kernel, russell

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-30 23:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 23:46 [PATCH net] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management Jonas Jelonek
2026-11-29 23:48 ` netdev-bot+sinfo
2026-11-30  0:25   ` Russell Senior
2026-11-30 15:09 ` Kory Maincent
2026-11-30 23:47 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®