🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #11894

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

#11894
From: Sander Vanheule
Date: Thu, 05 Nov 2026 21:51
152 lines
13452 bytes
Hi Jonas,

On Tue, 2026-11-03 at 22:03 +0000, Jonas Jelonek wrote:
> Use the optional VMAIN regulator power budget to configure the MCU's
> aggregate PoE power limit during probe. Quantize the available budget to
> the protocol's 100 mW units and reserve exactly that amount through the
> regulator core.
> 
> The regulator budget represents the usable PoE allowance. Program zero
> reserved power so the previous firmware guard band does not further reduce
> that allowance.
> 
> Require a finite budget of at least one protocol unit when vmain-supply is
> provided. Program the budget before selecting dynamic power management and
> ungating the ports, so enforcement starts with the regulator-derived limit.
> 
> Enable VMAIN before hardware initialization and register one managed cleanup
> action to free any reserved budget and release the enable reference on probe
> failure and driver removal. Record each successful reservation immediately
> so subsequent initialization failures are covered by this action.
> 
> Read the current budget index before programming the MCU. Retain the
> programmed MCU limit on probe failure and driver removal, as reducing that
> limit to zero would interrupt ongoing power delivery.
> 
> Boards without vmain-supply retain their existing firmware-managed
> budget.
> 
> Signed-off-by: Jonas Jelonek <jonas@jonasjelonek.de>
> ---

...

>  
> +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?

> +
> +	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.

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
Technical Details
Message-ID: <f67e328bcd20f405f2f15c62123bf3e0e740c14f.camel@svanheule.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357623-linux-kernel-netdev=dewy.ru
References: <20261103220312.860629-1-jonas@jonasjelonek.de> <20261103220312.860629-4-jonas@jonasjelonek.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357623-linux-kernel-netdev=dewy.ru
From: sander@svanheule.net (Sander Vanheule)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 3/4] net: pse-pd: realtek-pse-mcu: configure
 global power budget
Date: Thu, 05 Nov 2026 22:51:45 +0100
Organization: Usenet Network
Message-ID: <f67e328bcd20f405f2f15c62123bf3e0e740c14f.camel@svanheule.net>
References: <20261103220312.860629-1-jonas@jonasjelonek.de>
	 <20261103220312.860629-4-jonas@jonasjelonek.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="3738378"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:UO2+ZybF8LWDiLeyqIyFEywB4Es= sha256:lkhkHtgFEI77b/aKp7eB8fjIyGnLsXyYrteqbtkg6Bg=
	sha1:8Z15RqZtNSHs1ReWMFeuSZ/2zWo= sha256:Os3hR/RHN2o+fLmfuOWTPiRlV1xBxYz55tUfX5NaAGk=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id C66151130CC; Fri,  6 Nov 2026 00:53:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=svanheule.net
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id UW0uIi34ZK6N;
	Fri,  6 Nov 2026 00:53:04 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-357623-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=svanheule.net
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 8A4F91130C2; Fri,  6 Nov 2026 00:52:55 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 573C2264EB; Thu,  5 Nov 2026 21:52:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793915523;
	b=sdCf3q9RMqjni+UsUHt7xTK2XgtnYr7LAEyhV+Ku7M4pqCcKb3tzcP8ZWpk+uHowUiKB
	 XXNm7F691NEizF02VoWbmsmizC8P7u50JJjNZrrMnVe/GQre59fxvZJI1tE5fzY121rI4
	 M1ntInME/s7y/zdmOoU2bsZRFBcdYitSZXnvzKWHEUmn4XW+KB1f3a3FuMw37+TMJg3c+
	 mnPYctAasJ6kDVQb3Jm3O4p0DExCbR+QWrgS4YYBq3bimoZLZ/skN57ZVSmuoM0l53TM8
	 sr7OYsmRA4vUss9WFzu+aZ9nUC90yRsoHUhmm3ELLt+WjWfS0Th/FaXoSBy1/T9RZAA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793915523;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References:
	 Content-Type:Content-Transfer-Encoding:User-Agent:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version;
	bh=JyvKj/BvlW8+6fz7K9+CtTrZqOGel4PT34AP4CpOPD8=;
	b=P9bdLvRzO8CIW8/pAqhoPsJlfnjO4CtbyrmPCmO/ZRF4lAhFjmR64u8pOznt8xTBT1sx
	 /sYSMyaN8XzZDtBkUMh+ZrcxILtJfpZf6AiVkgjazWV7WRai3U+ujEFb5gaAvjj1eRL3X
	 c1dR7OWBRCdm25ccm/u+ttLQalQHZ8UlRqV8+h/zo54x+5iWrlObUUs6j8/eUBw9pgm1I
	 NtClkAMUH/D9dkKewUk0GSayjWirjcs6VkOP5wgpiXoUvGzVb+VXMOKPPCqstqjwxaEat
	 3nEUes1UPV13TmtaKu7NXf3GDeW+VYNx3lxpSJVkFtMaJzRwzyV5MmkdU1FYHcMKa1w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=svanheule.net header.i=@svanheule.net header.a=rsa-sha256 header.s=mail1707 header.b=xvR0GAZF;
	dmarc=pass header.from=svanheule.net;
	spf=pass smtp.mailfrom=svanheule.net;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BEC2606A31B;
	Thu,  5 Nov 2026 21:52:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=svanheule.net header.i=@svanheule.net header.a=rsa-sha256 header.s=mail1707 header.b=xvR0GAZF
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=84.16.241.116
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793915517;
	b=teNUpKB+pDMydZQGE+Po+96PC0oXIZwq65uObZHf72o4q3aQTNmtj8QRTz+1HyVREAI9
	 hd1fcb9Eq6b2ZNVF8Ri2rgmOhk8y67OYniAq70LxR+YJcDpZp0fR6/Z0urae0ijF9ESg9
	 4vLfhRfXxOWfgOZpgYyb+6txaVM11MCXtI77fFFokSvBeUncZUHM1+FV4EbyCLLHuDYjG
	 k14Eo5cwoyguBsZk4AEp1vXt4/QQOO85ZH5PSa4ejTYmg63wUaZtHtWVXZI7XfXsOJ8DJ
	 VpcjpoBI5BEs2IcDBBpws9oByI9BYdr75d4F4NnmE9qVhY9xcxgruPj+KKBPhtrwkqw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793915517;
	h=DMARC-Filter:Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:
	 Date:In-Reply-To:References:Content-Type:Content-Transfer-Encoding:
	 User-Agent:MIME-Version;
	bh=JyvKj/BvlW8+6fz7K9+CtTrZqOGel4PT34AP4CpOPD8=;
	b=KTard02uWBSx1Y01fhszaJma7ADKdUYUmcatKEpZb9v3vqiws8dh0Zd36CECmLR3ROuV
	 0/vMRMr8BAifulcbjXiK/g7P0mVbMtsw6ocaEW6PBvRyKNqUcuEKW9L8zCl2jNADIPTDt
	 8IKI4vTQmk4FtwLxRxYTCoKeEYeXxjAL3e8jAS2D36fjRMuXtFyn5M/xlmu+m73gxXjEI
	 yA3iZkkkLWv3jjMf10s+sjVeGNoKljKzgzW9dBG8M3YrOjpqyr0T+oW6w9OpjIwCQ4tJD
	 inu/xENk4Pl7zuaC6za99Qmd1RL+5Uy/zfrt7nRQQfJTcRdja9OZpy+PFVJMjameQ8g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=svanheule.net;
	spf=pass smtp.mailfrom=svanheule.net;
	arc=none smtp.remote-ip=84.16.241.116
X-Received: from polaris.svanheule.net (polaris.svanheule.net [84.16.241.116])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28C11606A333
	for <netdev@vger.kernel.org>; Thu,  5 Nov 2026 21:51:54 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 28C11606A333
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=svanheule.net
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=svanheule.net
X-Received: from [IPv6:2a02:1812:1620:5d00:3b08:a3e3:d87d:2eff] (2a02-1812-1620-5d00-3b08-a3e3-d87d-2eff.ip6.access.telenet.be [IPv6:2a02:1812:1620:5d00:3b08:a3e3:d87d:2eff])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	(Authenticated sender: sander@svanheule.net)
	by polaris.svanheule.net (Postfix) with ESMTPSA id 1BD4E9D45B4;
	Thu,  5 Nov 2026 22:51:47 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net;
	s=mail1707; t=1793915507;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=JyvKj/BvlW8+6fz7K9+CtTrZqOGel4PT34AP4CpOPD8=;
	b=xvR0GAZFd5UZrfDKoeb5LNCdGHKkHjtkJwUiEr9kML+RBGjytpaVxAxkRIFb3VszzLoneh
	YWSB3cpehSojWjYoJhKx7BSMJAbhQJycPS/0+WWfkPZ91UukPU8oVgLYyFykAxTgghMxvr
	w5phmvTYa2fwCYhqT7gEZwIuzvm8sTtsTOj8ziNacs2kA+dZ37i+di/y/1TOm7nFSwQunZ
	cxFw58GSKZB4qlhiee81zGVNtOKwAMelO7rS1L7icKRsv3nziJ+dtCS2kgiT3Xy+KtnhNP
	wsc+eObk7Ch0IhupGxuiT5HACQxlD7/DmZBmp7ZUiNbEcrGEzW6eYabJewtJ6A==
X-Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Russell Senior
	 <russell@personaltelco.net>
X-In-Reply-To: <20261103220312.860629-4-jonas@jonasjelonek.de>
X-User-Agent: Evolution 3.60.2 (3.60.2-3.fc44) 
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list