mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonas Jelonek <jonas@jonasjelonek.de>
To: Sander Vanheule <sander@svanheule.net>,
	Oleksij Rempel <o.rempel@pengutronix.de>,
	Kory Maincent <kory.maincent@bootlin.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	Russell Senior <russell@personaltelco.net>
Subject: Re: [PATCH net-next 3/4] net: pse-pd: realtek-pse-mcu: configure global power budget
Date: Fri, 6 Nov 2026 09:41:34 +0100	[thread overview]
Message-ID: <041c7f3c-92bf-4036-b404-c7aad959ac99@jonasjelonek.de> (raw)
In-Reply-To: <f67e328bcd20f405f2f15c62123bf3e0e740c14f.camel@svanheule.net>

Hi Sander,

On 05.11.26 22:51, Sander Vanheule wrote:
> ...
>>  
>> +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]);
> You don't want to configure a guard band? Can this lead to flapping of devices,
> where a port is rapidly switched off and on by the consumed power going above
> and below the power limit?

Maybe I got the idea of that guard band wrong, haven't found a good
explanation of that setting either. I just wanted to avoid setting any
guessed value here which reduces the global budget from e.g. 400W to
380W without specific reason.

>> +
>> +	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);
> This index is different from an earlier version of this patch, no? 
>
> My (old) documentation [1] describes the retrieved index as:
>     "Last updated PSE device ID. Also the PSE device the budget belongs to."
>
> I'm afraid I don't remember what I meant with the second part, but I suspect the
> power budget needs to be configured on all PSE devices. Does this work
> consistently on switches with multiple PSE chips? If "last updated" means it
> might sometimes return a lower index, I'm worried this might also lead to some
> cases where you query the MCU in the middle of an update cycle.

It works on several devices though I haven't pushed done tests to push those
devices to a specific global limit. I should probably do that soon to have more
of an idea about this behavior.

On Gen2, this doesn't refer to PSE indices but to a bank ID, and the whole system
apparently only uses one bank. It seems the bank is not changeable too, and
vendor firmware I've seen also just sets the power on a single bank.

For Gen1, the assumptions are based on that part "the PSE device the budget
belongs to" and on the userspace reference implementation [2] (grep for
pse_id_set_budget_mask). It varies for different devices there but most seem to
work also with a single index used? Also setting this budget on multiple
downstream managers sounds to me like we would grant each manager this
budget, unless there is some weird inter-manager communication going on.

Users in the OpenWrt forum came up with that issue and ran some own analysis
on vendor firmware. At least on the devices tested there also the vendor
justs sets the budget on a single index [3]. If some specific devices really need
this on multiple indices (like GS1900-24HPv1 in realtek-poe?) then I guess the
switch-specific compatibles need to be used for that purpose and a slightly
adjusted implementation.

> Otherwise this looks okay to me. I'll try to test it over the weekend.
>
> Best,
> Sander
>
> [1] https://svanheule.net/switches/software/broadcom_poe_control_protocol#get_power_statistics

Best,
Jonas

[2] https://github.com/Hurricos/realtek-poe/blob/realtek-poe/src/main.c
[3] https://forum.openwrt.org/t/support-for-zyxel-gs1920-series-gs1920-24hp/155683/170

  reply	other threads:[~2026-11-06  8:41 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 22:03 [PATCH net-next 0/4] net: pse-pd: realtek-pse-mcu: establish power management configuration Jonas Jelonek
2026-11-03 22:03 ` [PATCH net-next 1/4] net: pse-pd: realtek-pse-mcu: ensure MCU does dynamic power management Jonas Jelonek
2026-11-04 10:02   ` Kory Maincent
2026-11-03 22:03 ` [PATCH net-next 2/4] dt-bindings: net: pse-pd: realtek,pse-mcu: add VMAIN supply Jonas Jelonek
2026-11-04 10:04   ` Kory Maincent
2026-11-04 21:49   ` Rob Herring (Arm)
2026-11-03 22:03 ` [PATCH net-next 3/4] net: pse-pd: realtek-pse-mcu: configure global power budget Jonas Jelonek
2026-11-04 11:32   ` Kory Maincent
2026-11-04 12:20     ` Jonas Jelonek
2026-11-04 12:36       ` Kory Maincent
2026-11-04 12:51         ` Jonas Jelonek
2026-11-05 21:54         ` Sander Vanheule
2026-11-06  8:57           ` Jonas Jelonek
2026-11-05 21:51   ` Sander Vanheule
2026-11-06  8:41     ` Jonas Jelonek [this message]
2026-11-03 22:03 ` [PATCH net-next 4/4] net: pse-pd: realtek-pse-mcu: avoid global disable on teardown Jonas Jelonek
2026-11-04  9:45   ` Kory Maincent
2026-11-04  9:51     ` Jonas Jelonek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=041c7f3c-92bf-4036-b404-c7aad959ac99@jonasjelonek.de \
    --to=jonas@jonasjelonek.de \
    --cc=andrew+netdev@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=kory.maincent@bootlin.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=russell@personaltelco.net \
    --cc=sander@svanheule.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®