From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B1681CD1EF; Thu, 21 Nov 2024 14:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200222; cv=none; b=pFyc7F5mIHH2IcQCs2gTgZyb+6tP3GUE1VlfgqzAFQIEzY2LCAdaX0PKAqB2l3RuY0WCkpXmKWIDUPRkvH2+F6GA4u5C+mvNUFGI4WjJJE8qIAFaTSL/ozjiUGSMytfOqmWzLAd+X5TnReL22NtjdTS0VTDsXVe1m0nBWUzrYMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200222; c=relaxed/simple; bh=7J/eh52uJk71WbVQkH2eMFY49Q8W9fou8NIi2HeyyTc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u6Fo7DT2Y8jfAOqMP5vTWtJ9/FssxmBqiCr04TOhX2hBZRBb0XrqHILaGw5pvCNNm1GIhGE3lxNmhSd6iqBjdXp0yp0lINexASglui96x5UIHz6HZonSJPt7bwltygIFCnkxt6IynrE1NWh4OC+yTSiJ3736sojQvz4A+p1r1Hc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=SVaHKaVW; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="SVaHKaVW" Received: by mail.gandi.net (Postfix) with ESMTPSA id 845F440007; Thu, 21 Nov 2024 14:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200213; 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=Z4FptY7neSNIpm8/KU8J5QUzyVqJhV+phM8Nu0jRFeM=; b=SVaHKaVWgVx29UyAi9iDL6JErcoU9cWtXFxK0CZJsonyX3I6McZlPTBpp5Vc9BWBqz5CLW HZmZafyloTDjJHJrf4glvsPsF2wbjnptF98abO6Qxo0HYHkUInnx460szNHpG2ZdqBEbca G8JKyY6vGahEUhOtWl0J9IDb6jkkzxKOYAkNYhpRTuPoV15s57HJVzMtJH6wj6i4aUS83M UtUliBzd3hV5kDIlFxfCAtfAVcRa//6MhfGck1oD6zJjKV3riefqhKuoosZm5BUtKF3h9J tQu6VM+SZBsID4+A8RsKkxGHgvSfEJbDw2sNutlKT6vs8y4WXw/huk3euT7sJg== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:27 +0100 Subject: [PATCH RFC net-next v3 01/27] net: pse-pd: Remove unused pse_ethtool_get_pw_limit function declaration Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-1-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent , Kalesh AP X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Removed the unused pse_ethtool_get_pw_limit() function declaration from pse.h. This function was declared but never implemented or used, making the declaration unnecessary. Reviewed-by: Kalesh AP Reviewed-by: Andrew Lunn Acked-by: Oleksij Rempel Reviewed-by: Kyle Swenson Signed-off-by: Kory Maincent --- include/linux/pse-pd/pse.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index 591a53e082e6..85a08c349256 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -184,8 +184,6 @@ int pse_ethtool_set_config(struct pse_control *psec, int pse_ethtool_set_pw_limit(struct pse_control *psec, struct netlink_ext_ack *extack, const unsigned int pw_limit); -int pse_ethtool_get_pw_limit(struct pse_control *psec, - struct netlink_ext_ack *extack); =20 bool pse_has_podl(struct pse_control *psec); bool pse_has_c33(struct pse_control *psec); @@ -222,12 +220,6 @@ static inline int pse_ethtool_set_pw_limit(struct pse_= control *psec, return -EOPNOTSUPP; } =20 -static inline int pse_ethtool_get_pw_limit(struct pse_control *psec, - struct netlink_ext_ack *extack) -{ - return -EOPNOTSUPP; -} - static inline bool pse_has_podl(struct pse_control *psec) { return false; --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BD241D95B3; Thu, 21 Nov 2024 14:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200224; cv=none; b=reGhiQnSXGgXKDXkzeK5+VmfnRRMbFUzQbdnZmiemeiweZrKHmMCk+/W329FnuMS68cZ0qscH+h1mky2MGuGRJOhGe8ns879ayytL8JaU6+k1y8PIgHYs9lre+qNSNKo3q3VihBsQRFudfijkhpU/AD1lkvkBslGKpbWW+SV724= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200224; c=relaxed/simple; bh=DC/9YkU2BchaabD5ycgLbSoIt4/zucrbbySyiKTAodw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GJWMDY79jjXbe53bQau3QgY2MytMDkx/+ZRROryvLjzYKho2s9xPPICZs1j/Op9sMYwxuQxnCg/HzCJxSbN5xnJZzAqASaf+848lmplnEcO8RDhKhJ2n6WcdlkQfTm83p73H2/Hpbik4msVKwhw8Ee+WvnLFQZ4VeKwa7xWQemw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Hn2mOj1w; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Hn2mOj1w" Received: by mail.gandi.net (Postfix) with ESMTPSA id B4D774000B; Thu, 21 Nov 2024 14:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200215; 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=PB4N4irPSyn5rR+E/NNWqmUZSG81ZYdtH5kOGb0VcXk=; b=Hn2mOj1wPiMHfblYXynxvv9q601z9o/gA4WJNSOy3/TJLNPerLtchzzAx7IBpYdTINhWwc SGJCzhjPy3fNZ/J8NE5Qwo3JfaqmotoZpcwZOt/VDG0I4spU13YLwsGwFvTDDbp6AU6m1c OtTTZKQ8flYbHNQ+yeLFDMsij5KljziJL5NB8o3ucUfIAVGb/xc5t3MeClrLuo1yQK35ev o9yhM0jvMj+L1NRE6WUJkQ4kvVMa5z8OWd8EQD5qnZoYJanQtlzUKZdWlgTG3fM2xQDDiU wh1eHuEyPT5gCxb3Mq+Bz7aqZKTfL9TZb5b0hccvr+ILOGFxi8rGhV2i1+Tt+Q== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:28 +0100 Subject: [PATCH RFC net-next v3 02/27] regulator: core: Ignore unset max_uA constraints in current limit check Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-2-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) We should only consider max_uA constraints if they are explicitly defined. In cases where it is not set, we should assume the regulator has no current limit. Signed-off-by: Kory Maincent --- Change in v3: - New patch --- drivers/regulator/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1179766811f5..2948a7eca734 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -497,7 +497,8 @@ static int regulator_check_current_limit(struct regulat= or_dev *rdev, return -EPERM; } =20 - if (*max_uA > rdev->constraints->max_uA) + if (*max_uA > rdev->constraints->max_uA && + rdev->constraints->max_uA) *max_uA =3D rdev->constraints->max_uA; if (*min_uA < rdev->constraints->min_uA) *min_uA =3D rdev->constraints->min_uA; --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 705101386D7; Thu, 21 Nov 2024 14:43:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200222; cv=none; b=H/nmJec87jlOTMiTow0b8nYrGigjTVItK1qHV46UlwtSziTjUDKGPzM0BvlIGh0WVCbCNpUaufpVlmo/v7425BWcj/1dfJGJ+ha34joaGk5ytxDCycP0dikcY6YaAHDGMyY4SVuZT0gu861zhyfwMq9e6T5QwdFS5N3X2i6DE/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200222; c=relaxed/simple; bh=Z9ZNL3rh1rUDWm5Q3HrHpjTA0Zx0JXMguecu4dqyCSQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iCpYkGsqV4tVDUUPjMdfhWBCLs3KsP9+G7vTJnhOwb83qFaGsQzSaCfHs2SGI5ik8iRtOraWxJ+okAwY8hp2StXIa0V/U5LD6l6DX6gWoofodQ8XJ9pXiORc9DN7Pl7rHuDueTDfC5ErqgKZsaiM5F1TIogBU52OIEtyLRJciWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=e8jJdSO5; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="e8jJdSO5" Received: by mail.gandi.net (Postfix) with ESMTPSA id CB7ED4000C; Thu, 21 Nov 2024 14:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200217; 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=EmHAa5lzTlUKP9x1tLfYUr5FJHSMHYYBy7nd5w51Avs=; b=e8jJdSO5ViEhXGf3Ny2QOlNBN0n5eeXTbNv5GuHUTacuHbdaUyQ0Jl7p7A4bYxQKIvtxHo IEOeMbWgmMA3IlJmMUwFA+dY2LaMQQcJh4pNk05ICaoWJueV/B4uni6UHYxWuqLRP0d1X0 K2Dlc2+A7UoEs5NTNN7T6wIWJoFB6zhw940tiX4+tj2LEop+fFA1jTQYiSekrNIrZoEa7B eF6UxLzbsTeDv+pANeS2GJFAT+MGp2uy74dRICOF6G5hk6UV/uukMdgoKykGyGpZSVU3tn 4OFMKpB2tqoybQSK7nDB+XWS9cXcBHskFM09JbtpjNTp8YzUClUnDr/OPyg4jw== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:29 +0100 Subject: [PATCH RFC net-next v3 03/27] net: pse-pd: Avoid setting max_uA in regulator constraints Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-3-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Setting the max_uA constraint in the regulator API imposes a current limit during the regulator registration process. This behavior conflicts with preserving the maximum PI power budget configuration across reboots. Instead, compare the desired current limit to MAX_PI_CURRENT in the pse_pi_set_current_limit() function to ensure proper handling of the power budget. Signed-off-by: Kory Maincent --- Change ni v3: - New patch --- drivers/net/pse-pd/pse_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index 2906ce173f66..9fee4dd53515 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -357,6 +357,9 @@ static int pse_pi_set_current_limit(struct regulator_de= v *rdev, int min_uA, if (!ops->pi_set_current_limit) return -EOPNOTSUPP; =20 + if (max_uA > MAX_PI_CURRENT) + return -ERANGE; + id =3D rdev_get_id(rdev); mutex_lock(&pcdev->lock); ret =3D ops->pi_set_current_limit(pcdev, id, max_uA); @@ -403,11 +406,9 @@ devm_pse_pi_regulator_register(struct pse_controller_d= ev *pcdev, =20 rinit_data->constraints.valid_ops_mask =3D REGULATOR_CHANGE_STATUS; =20 - if (pcdev->ops->pi_set_current_limit) { + if (pcdev->ops->pi_set_current_limit) rinit_data->constraints.valid_ops_mask |=3D REGULATOR_CHANGE_CURRENT; - rinit_data->constraints.max_uA =3D MAX_PI_CURRENT; - } =20 rinit_data->supply_regulator =3D "vpwr"; =20 --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA50D1D86F6; Thu, 21 Nov 2024 14:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200224; cv=none; b=RyCuHzgz5s3KT39GAZF5Oh66RkK46wDBxChgrrM7QZ5maOWfBYw61K1ezd206zPW6nb8lKy/dsvVHWbRWDLOGiqH5HYQjS/bHA0/2xLpqSCePurF6dxfN2dpIl3gb/aqUIbvzxmsO3j9XaFWgdIx9yKI2gr7ux3/5IR1O6UbGo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200224; c=relaxed/simple; bh=qJswWfPi8lT2mzZnIIIC4cBWZ7Nfz/y4Mv1II5hMV5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Jatb+5fh6XgPHccVBhadulHTpGSFVQw5IH+7KxFWgLd1e6g0wVYVVzXcZhaPe9t5r9ZMrK7smQVVV1XxHiBkcrgL+i/nYo7NaulHsdQx6Kk76bwM2AEiwpyp8pnYaXqQK3Jsh4xr+GCK0vBxrdeZXIvQgUDLJ9rjZw2aqS/VqDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=U6BdPniQ; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="U6BdPniQ" Received: by mail.gandi.net (Postfix) with ESMTPSA id EF5F040011; Thu, 21 Nov 2024 14:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200219; 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=8tHPZeF+rLMZJ6NpsuiZNrNpDwdvxaE67fXkw7mxPhw=; b=U6BdPniQHZbdrJLLl8vkB42DRF9M1WxIZuFMyy1+Cf3vOAgHSm+AHO1Bhq6piq3OetuSgC wEVijjE0ciEDbF8zdf/ifM0jiYl6T+DPHaxw6Sv7co0fRcXiCbJErp1Ut5NN3om0IBopX/ ntcdabmFv3y/XwWhjE5NAg/KMVO6ETtmDrUjS0ZAds2DwUS6IYDQAtR+/aYdRl+D+1zVo6 XF2wJqY/MBTWc9tkz5uRSFUV1DUiZ6bZITFwash4/OvdMly42Zl/gg6l/fqu9Ziw1hiphC Jq3lbvsSHCLhaTQfva6wIIY/+F32MJy095ECCDzK4stDRSPjw+lseZ9JfIqhqA== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:30 +0100 Subject: [PATCH RFC net-next v3 04/27] net: pse-pd: Add power limit check Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-4-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Checking only the current limit is not sufficient. According to the standard, voltage can reach up to 57V and current up to 1.92A, which exceeds the power limit described in the standard (99.9W). Add a power limit check to prevent this. Signed-off-by: Kory Maincent --- Change ni v3: - New patch --- drivers/net/pse-pd/pse_core.c | 3 +++ include/linux/pse-pd/pse.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index 9fee4dd53515..432b6c2c04f8 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -877,6 +877,9 @@ int pse_ethtool_set_pw_limit(struct pse_control *psec, int uV, uA, ret; s64 tmp_64; =20 + if (pw_limit > MAX_PI_PW) + return -ERANGE; + ret =3D regulator_get_voltage(psec->ps); if (!ret) { NL_SET_ERR_MSG(extack, diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index 85a08c349256..bc5addccbf32 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -11,6 +11,8 @@ =20 /* Maximum current in uA according to IEEE 802.3-2022 Table 145-1 */ #define MAX_PI_CURRENT 1920000 +/* Maximum power in mW according to IEEE 802.3-2022 Table 145-16 */ +#define MAX_PI_PW 99900 =20 struct phy_device; struct pse_controller_dev; --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B87991DD877; Thu, 21 Nov 2024 14:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200226; cv=none; b=YvZzahqpHOhvjVxtG6YmfjrUik5sMXZQllihrSREsOBciMxthMNyYBiqRzun2fmfy+AtgwC3GdZSFliYDbINhhb3XL3QmTvRbUcT0uRtaW2ZVeGXTJ6k6MwSjTgd7eymyS3NudtBck6GcSZgOBOQw72Bc14+5QTPv5fe/JS8dJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200226; c=relaxed/simple; bh=ZsdCmW4n2LvHHk61rNgVX7raqVKq/pW4WBuFPn32Q2I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bQ79+my5K9/3ZUBM5TeQbdEhW/vdGj+Om3O9HcmtxfMxAm2yujVJS2kF0yLuBz+SZV+1qucNx6HHsZsmzS9AjHMueAY2OzcUg1zvUVEauGTrnicdEQSHkWYaABy4znWj+p11XI69rmzvPgzpvJGzDqyRnnujhqz0KJLsW3jAW9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=nbCYWFlY; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="nbCYWFlY" Received: by mail.gandi.net (Postfix) with ESMTPSA id 198CB40006; Thu, 21 Nov 2024 14:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200222; 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=ZR/OQqXD89qyu5jFhAfZEfAZSUhVQIdWY1c3hbVfIMM=; b=nbCYWFlYdqMjzdMZMVjm2eP2ZK2CE0KsGNaRD0BVd3lFbkTqjUsjj0Z9fuoHa7J2RUo0b3 C+Z9NoRJzW5WOBtTd2Mq3J4y5Fz5eT39tkn4VHtkPpqTj4Hn/ISjhc0hOG+ugZGyRVAQhj xTEZ9xwrNJaliOzr6aE5P7/vtzubWZ3sxtx1ogpv+FZrkkT/5HXXwYCyl5erLdXewRrdrM A/tHNdNKWpmkPeZFQnanv83mXhej5T7SKXqeLWJPpTE4s4YN1OnLFNumvyZS/gjqtaIm9D 92UvzppHSGrCw4H5XxPa6CzpZKpQA9ICHJ5JI5zI/Pkbt+xzjzbHC8d/4KUTWg== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:31 +0100 Subject: [PATCH RFC net-next v3 05/27] net: pse-pd: tps23881: Simplify function returns by removing redundant checks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-5-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Cleaned up several functions in tps23881 by removing redundant checks on return values at the end of functions. These check has been removed, and the return statement now directly returns the function result, reducing the code's complexity and making it more concise. Reviewed-by: Andrew Lunn Acked-by: Oleksij Rempel Reviewed-by: Kyle Swenson Signed-off-by: Kory Maincent --- drivers/net/pse-pd/tps23881.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index 5c4e88be46ee..20eab9857817 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -118,11 +118,7 @@ static int tps23881_pi_disable(struct pse_controller_d= ev *pcdev, int id) val |=3D BIT(chan + 8); } =20 - ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_PW_EN, val); - if (ret) - return ret; - - return 0; + return i2c_smbus_write_word_data(client, TPS23881_REG_PW_EN, val); } =20 static int tps23881_pi_is_enabled(struct pse_controller_dev *pcdev, int id) @@ -488,7 +484,7 @@ tps23881_write_port_matrix(struct tps23881_priv *priv, struct i2c_client *client =3D priv->client; u8 pi_id, lgcl_chan, hw_chan; u16 val =3D 0; - int i, ret; + int i; =20 for (i =3D 0; i < port_cnt; i++) { pi_id =3D port_matrix[i].pi_id; @@ -519,11 +515,7 @@ tps23881_write_port_matrix(struct tps23881_priv *priv, } =20 /* Write hardware ports matrix */ - ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_PORT_MAP, val); - if (ret) - return ret; - - return 0; + return i2c_smbus_write_word_data(client, TPS23881_REG_PORT_MAP, val); } =20 static int @@ -572,11 +564,7 @@ tps23881_set_ports_conf(struct tps23881_priv *priv, val |=3D BIT(port_matrix[i].lgcl_chan[1]) | BIT(port_matrix[i].lgcl_chan[1] + 4); } - ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_DET_CLA_EN, val); - if (ret) - return ret; - - return 0; + return i2c_smbus_write_word_data(client, TPS23881_REG_DET_CLA_EN, val); } =20 static int @@ -602,11 +590,7 @@ tps23881_set_ports_matrix(struct tps23881_priv *priv, if (ret) return ret; =20 - ret =3D tps23881_set_ports_conf(priv, port_matrix); - if (ret) - return ret; - - return 0; + return tps23881_set_ports_conf(priv, port_matrix); } =20 static int tps23881_setup_pi_matrix(struct pse_controller_dev *pcdev) --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 142491DE3AB; Thu, 21 Nov 2024 14:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200228; cv=none; b=tiFLjpBPIXz3e2Y5PvFMPxi9s3vlPV6hECAfd8lQd+be8ckDVQJb18O9hw68J91pgpbUz2RDB84x0Vg49LVFGkFqhc9SrrKhktyMs77KhAudQX1w1cZmFg75zdsJ08v3M0TOs6P7zi6zronp50/GWqEjpkXJ4H452GoZMHP0QJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200228; c=relaxed/simple; bh=ffDIfIKozJdI36XtPpaxP40wvqXasjwC2BubHWmTuu8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u00IIbLskWWKSriNWwTK9H3NkRNf+q8bktUwAQRtEG/uxrYtw1wjEAh6AqsYzTiMSsmHfERKwLHAJZcRPHz0FvxE/jq3FWmcM9WsZs1EAK+JHUVky9ZBv7CxldWDBtlByaLbj+qBZuCQHwGQ4Am4Pt2ttwHXTIEi4M6+eypzbn4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=M4i6De0U; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="M4i6De0U" Received: by mail.gandi.net (Postfix) with ESMTPSA id 6179440009; Thu, 21 Nov 2024 14:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200224; 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=FThTH0Mg3xvhRUwUt4xppHY86DV1YRmcuOvIlQciNKQ=; b=M4i6De0U36ljagcarLtkQ2bJvJDR7XwiuOdelooC8eCbRHxR1SflLUYP1+Dzgua6WdhrKz gESOYPHRlnPAgurN1t1/ATYloqKY3fUxRDSQOzpTpH9Cjtu2qQSrcKOzv+PYCMONb0K0R6 Z38gtxB4A/QNt+0BqsinI5vNV56q1jUfPKH4FHivh+TjRh59GMwUHIN9nb7cYqEBm/qEXd Zaera19EDGiuWNDYNVtra3BWNhliLO0aS1lGvVdFIaI5O+ZPx53BHRp403mlPoSya1yIBO DDi/tvMyz8MSipF6IJjk99+HsWyi/w8htzuXdx0shFYsmninOQsyIsc8xLZZ+g== From: "Kory Maincent (Dent Project)" Date: Thu, 21 Nov 2024 15:42:32 +0100 Subject: [PATCH RFC net-next v3 06/27] net: pse-pd: tps23881: Use helpers to calculate bit offset for a channel Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-6-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) This driver frequently follows a pattern where two registers are read or written in a single operation, followed by calculating the bit offset for a specific channel. Introduce helpers to streamline this process and reduce code redundancy, making the codebase cleaner and more maintainable. Acked-by: Oleksij Rempel Signed-off-by: Kory Maincent --- Thanks to Oleksij for the design of the helpers functions. Change in v3: - Small fix: use chan >=3D 4 instead of chan > 4; Change in v2: - New patch --- drivers/net/pse-pd/tps23881.c | 107 +++++++++++++++++++++++++++-----------= ---- 1 file changed, 69 insertions(+), 38 deletions(-) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index 20eab9857817..6fd76ecb2961 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -53,6 +53,55 @@ static struct tps23881_priv *to_tps23881_priv(struct pse= _controller_dev *pcdev) return container_of(pcdev, struct tps23881_priv, pcdev); } =20 +/* + * Helper to extract a value from a u16 register value, which is made of t= wo + * u8 registers. The function calculates the bit offset based on the chann= el + * and extracts the relevant bits using a provided field mask. + * + * @param reg_val: The u16 register value (composed of two u8 registers). + * @param chan: The channel number (0-7). + * @param field_offset: The base bit offset to apply (e.g., 0 or 4). + * @param field_mask: The mask to apply to extract the required bits. + * @return: The extracted value for the specific channel. + */ +static u16 tps23881_calc_val(u16 reg_val, u8 chan, u8 field_offset, + u16 field_mask) +{ + if (chan >=3D 4) + reg_val >>=3D 8; + + return (reg_val >> field_offset) & field_mask; +} + +/* + * Helper to combine individual channel values into a u16 register value. + * The function sets the value for a specific channel in the appropriate + * position. + * + * @param reg_val: The current u16 register value. + * @param chan: The channel number (0-7). + * @param field_offset: The base bit offset to apply (e.g., 0 or 4). + * @param field_mask: The mask to apply for the field (e.g., 0x0F). + * @param field_val: The value to set for the specific channel (masked by + * field_mask). + * @return: The updated u16 register value with the channel value set. + */ +static u16 tps23881_set_val(u16 reg_val, u8 chan, u8 field_offset, + u16 field_mask, u16 field_val) +{ + field_val &=3D field_mask; + + if (chan < 4) { + reg_val &=3D ~(field_mask << field_offset); + reg_val |=3D (field_val << field_offset); + } else { + reg_val &=3D ~(field_mask << (field_offset + 8)); + reg_val |=3D (field_val << (field_offset + 8)); + } + + return reg_val; +} + static int tps23881_pi_enable(struct pse_controller_dev *pcdev, int id) { struct tps23881_priv *priv =3D to_tps23881_priv(pcdev); @@ -69,17 +118,12 @@ static int tps23881_pi_enable(struct pse_controller_de= v *pcdev, int id) return ret; =20 chan =3D priv->port[id].chan[0]; - if (chan < 4) - val =3D (u16)(ret | BIT(chan)); - else - val =3D (u16)(ret | BIT(chan + 4)); + val =3D tps23881_set_val(ret, chan, 0, BIT(chan % 4), BIT(chan % 4)); =20 if (priv->port[id].is_4p) { chan =3D priv->port[id].chan[1]; - if (chan < 4) - val |=3D BIT(chan); - else - val |=3D BIT(chan + 4); + val =3D tps23881_set_val(val, chan, 0, BIT(chan % 4), + BIT(chan % 4)); } =20 ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_PW_EN, val); @@ -105,17 +149,12 @@ static int tps23881_pi_disable(struct pse_controller_= dev *pcdev, int id) return ret; =20 chan =3D priv->port[id].chan[0]; - if (chan < 4) - val =3D (u16)(ret | BIT(chan + 4)); - else - val =3D (u16)(ret | BIT(chan + 8)); + val =3D tps23881_set_val(ret, chan, 4, BIT(chan % 4), BIT(chan % 4)); =20 if (priv->port[id].is_4p) { chan =3D priv->port[id].chan[1]; - if (chan < 4) - val |=3D BIT(chan + 4); - else - val |=3D BIT(chan + 8); + val =3D tps23881_set_val(val, chan, 4, BIT(chan % 4), + BIT(chan % 4)); } =20 return i2c_smbus_write_word_data(client, TPS23881_REG_PW_EN, val); @@ -127,6 +166,7 @@ static int tps23881_pi_is_enabled(struct pse_controller= _dev *pcdev, int id) struct i2c_client *client =3D priv->client; bool enabled; u8 chan; + u16 val; int ret; =20 ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_PW_STATUS); @@ -134,17 +174,13 @@ static int tps23881_pi_is_enabled(struct pse_controll= er_dev *pcdev, int id) return ret; =20 chan =3D priv->port[id].chan[0]; - if (chan < 4) - enabled =3D ret & BIT(chan); - else - enabled =3D ret & BIT(chan + 4); + val =3D tps23881_calc_val(ret, chan, 0, BIT(chan % 4)); + enabled =3D !!(val); =20 if (priv->port[id].is_4p) { chan =3D priv->port[id].chan[1]; - if (chan < 4) - enabled &=3D !!(ret & BIT(chan)); - else - enabled &=3D !!(ret & BIT(chan + 4)); + val =3D tps23881_calc_val(ret, chan, 0, BIT(chan % 4)); + enabled &=3D !!(val); } =20 /* Return enabled status only if both channel are on this state */ @@ -160,6 +196,7 @@ static int tps23881_ethtool_get_status(struct pse_contr= oller_dev *pcdev, struct i2c_client *client =3D priv->client; bool enabled, delivering; u8 chan; + u16 val; int ret; =20 ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_PW_STATUS); @@ -167,23 +204,17 @@ static int tps23881_ethtool_get_status(struct pse_con= troller_dev *pcdev, return ret; =20 chan =3D priv->port[id].chan[0]; - if (chan < 4) { - enabled =3D ret & BIT(chan); - delivering =3D ret & BIT(chan + 4); - } else { - enabled =3D ret & BIT(chan + 4); - delivering =3D ret & BIT(chan + 8); - } + val =3D tps23881_calc_val(ret, chan, 0, BIT(chan % 4)); + enabled =3D !!(val); + val =3D tps23881_calc_val(ret, chan, 4, BIT(chan % 4)); + delivering =3D !!(val); =20 if (priv->port[id].is_4p) { chan =3D priv->port[id].chan[1]; - if (chan < 4) { - enabled &=3D !!(ret & BIT(chan)); - delivering &=3D !!(ret & BIT(chan + 4)); - } else { - enabled &=3D !!(ret & BIT(chan + 4)); - delivering &=3D !!(ret & BIT(chan + 8)); - } + val =3D tps23881_calc_val(ret, chan, 0, BIT(chan % 4)); + enabled &=3D !!(val); + val =3D tps23881_calc_val(ret, chan, 4, BIT(chan % 4)); + delivering &=3D !!(val); } =20 /* Return delivering status only if both channel are on this state */ --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A7941DE880; Thu, 21 Nov 2024 14:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200230; cv=none; b=gnEXv4eJ+MXs0cdgCtaUNM6vOnGQ5yZUfC0vMYYfFP1ro0L/gz2KD011YnmsgomsG9SsyF0BcAtnceB+jic+OTYpfUKylzhrqG8Q6CmfN87wNNvYmLdnpYfITOD+ZCVd8q7RXSIfVN6gBKZd8spQIiNkLVZA9QWeG5fgLDXU7JI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200230; c=relaxed/simple; bh=4XBU9fiQlzWzOj4Ap5N0rMJeKmyzkpk9Ed8r2jHf+oo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ifVLa7ArRwImhrKALc8bFmKxTf7TWSCkO1nPVjWzFDnQBvuEzFzB43/D8VcV6SWYtT3eW80fJpxwHOgfVlFlzlghi/fmsziHsSZGtNyGmYgiVUFXXqD8EreLkO0aIYlPygLQgcTNQLkvJqgc/Z6TmQuekFrudomafykSGptioeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=p6xzK8ud; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="p6xzK8ud" Received: by mail.gandi.net (Postfix) with ESMTPSA id 7FC784000F; Thu, 21 Nov 2024 14:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200226; 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=N74s09ADogUFQ5VtdAqKfmIMNkv7NvPfQkufVZ2lQ5w=; b=p6xzK8udS0cuZPR3JGcj0GZY1ANZTkUW3fTqcJepb/PjLYeoRsnKr+R58FV8FfHbSo+4yj gL5xeeWgNNdJOuZvEdSto9eNVbow+RX3paCACaEj1H07FxdEqCznMFI8s8T6af6HgFydau NTGUCu0JkRpvWX7V1rmpk4EFrglyqyW9EQ4EHc2qmkc6x2fMpARV4KupgT2iyCyVHiOec0 dcNnZW7wSk98H+bJD2YpTajftkk0KjxygXocawWCDj7GIMxcZBLMh/TMf3AadnuSXyuCci Gnyr3Tfz5Uq3zn9mwcJhnnj9dy4HdDBlP3jTZk5wK4Vjpnyg75s6fpU5imBv0w== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:33 +0100 Subject: [PATCH RFC net-next v3 07/27] net: pse-pd: tps23881: Add missing configuration register after disable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-7-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) When setting the PWOFF register, the controller resets multiple configuration registers. This patch ensures these registers are reconfigured as needed following a disable operation. Signed-off-by: Kory Maincent Acked-by: Oleksij Rempel --- Change in v3: - New patch --- drivers/net/pse-pd/tps23881.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index 6fd76ecb2961..58864b7d28d2 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -157,7 +157,34 @@ static int tps23881_pi_disable(struct pse_controller_d= ev *pcdev, int id) BIT(chan % 4)); } =20 - return i2c_smbus_write_word_data(client, TPS23881_REG_PW_EN, val); + ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_PW_EN, val); + if (ret) + return ret; + + /* PWOFF command resets lots of register which need to be + * configured again. According to the datasheet "It may take upwards + * of 5ms after PWOFFn command for all register values to be updated" + */ + mdelay(5); + + /* Enable detection and classification */ + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_DET_CLA_EN); + if (ret < 0) + return ret; + + chan =3D priv->port[id].chan[0]; + val =3D tps23881_set_val(ret, chan, 0, BIT(chan % 4), BIT(chan % 4)); + val =3D tps23881_set_val(val, chan, 4, BIT(chan % 4), BIT(chan % 4)); + + if (priv->port[id].is_4p) { + chan =3D priv->port[id].chan[1]; + val =3D tps23881_set_val(ret, chan, 0, BIT(chan % 4), + BIT(chan % 4)); + val =3D tps23881_set_val(val, chan, 4, BIT(chan % 4), + BIT(chan % 4)); + } + + return i2c_smbus_write_word_data(client, TPS23881_REG_DET_CLA_EN, val); } =20 static int tps23881_pi_is_enabled(struct pse_controller_dev *pcdev, int id) --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DF1A1DE8A9; Thu, 21 Nov 2024 14:43:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200233; cv=none; b=cDadyP3aMmT2CIDz679BFPqRXuSfkq0ROu3eEID03jqYQurEyL06QxKR4LaCNjWHoZGFnQA1xl2MxzctuRvU4FWdrsXKuq7DEeXSFqradqyjzBXcKwWNdKde7Em+mOMRldPYSw1jTKxTNw38buo24GepzivVBovI5FKCX6fN1mM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200233; c=relaxed/simple; bh=N2VnxB2ko/xn9R1ZPLwugn+mKFltCGe40AyxoZVHGUw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EPUrOWGz0a8zlIerQ6c3Ck+LfunA6+Jg+i57rx9E2Ruwc0nG1Tbzd4v223azxxtDQeapWxAi1mWi5vG5MgRRkiCnOcWVPoL8Y7FtwOf2LB8+SGp3rN5omFV/fABfsrjHPK420qYkwPdqTDUD8hn6lgiF55HuXz/03iQWoZXjdmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=btoHyHOm; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="btoHyHOm" Received: by mail.gandi.net (Postfix) with ESMTPSA id AFBD640006; Thu, 21 Nov 2024 14:43:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200228; 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=1a3e7ksDGRat7Ji4aJzMVkldZtaeGAH9wNk6J3hf2Ow=; b=btoHyHOm5j4Aivtwyl4rDU6QojJjkxPSk6VHX7lHtxohOZFJwTOe1aY1tt5eWeV0cmssRN 1GNrynnc9OFf4ERyqs9w+vN1ihztHw5q6/QO7rjZsEMBBa1ASyxAM5+/pkdwK3b1LR5eBR BYi9c4w6oA31o/yIYay0oZ/I8wDA0VBUYLqXhVtLSi63R48bBIBAczlGRoZYIa41146awc 0kgaVxtzAWTwlYExuq0Loid016ddX5TprKInvArgnmFY21abdwqVk209oqnqXDUWw1pe9s hRF9IQNtoiZyeeilYdZhGUyu3wT5I2VCBS5DCn4MdgUaTPUu2+rs8tA+txWAcA== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:34 +0100 Subject: [PATCH RFC net-next v3 08/27] net: pse-pd: tps23881: Add support for power limit and measurement features Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-8-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Expand PSE callbacks to support the newly introduced pi_get/set_current_limit() and pi_get_voltage() functions. These callbacks allow for power limit configuration in the TPS23881 controller. Additionally, the patch includes the detected class, the current power delivered and the power limit ranges in the status returned, providing more comprehensive PoE status reporting. Signed-off-by: Kory Maincent --- Change in v3: - NIT change, use tps23881_set_val helper to set the power limit register value. - Add policy varaible internally to being able to reconfigure it after a PWOFF call. Change in v2: - Use newly introduced helpers. --- drivers/net/pse-pd/tps23881.c | 326 ++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 324 insertions(+), 2 deletions(-) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index 58864b7d28d2..b25561f95774 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -25,20 +25,34 @@ #define TPS23881_REG_GEN_MASK 0x17 #define TPS23881_REG_NBITACC BIT(5) #define TPS23881_REG_PW_EN 0x19 +#define TPS23881_REG_2PAIR_POL1 0x1e #define TPS23881_REG_PORT_MAP 0x26 #define TPS23881_REG_PORT_POWER 0x29 -#define TPS23881_REG_POEPLUS 0x40 +#define TPS23881_REG_4PAIR_POL1 0x2a +#define TPS23881_REG_INPUT_V 0x2e +#define TPS23881_REG_CHAN1_A 0x30 +#define TPS23881_REG_CHAN1_V 0x32 +#define TPS23881_REG_FOLDBACK 0x40 #define TPS23881_REG_TPON BIT(0) #define TPS23881_REG_FWREV 0x41 #define TPS23881_REG_DEVID 0x43 #define TPS23881_REG_DEVID_MASK 0xF0 #define TPS23881_DEVICE_ID 0x02 +#define TPS23881_REG_CHAN1_CLASS 0x4c #define TPS23881_REG_SRAM_CTRL 0x60 #define TPS23881_REG_SRAM_DATA 0x61 =20 +#define TPS23881_UV_STEP 3662 +#define TPS23881_MAX_UV 60000000 +#define TPS23881_NA_STEP 70190 +#define TPS23881_MAX_UA 1150000 +#define TPS23881_MW_STEP 500 +#define TPS23881_MIN_PI_PW_LIMIT 2000 + struct tps23881_port_desc { u8 chan[2]; bool is_4p; + int pw_pol; }; =20 struct tps23881_priv { @@ -102,6 +116,42 @@ static u16 tps23881_set_val(u16 reg_val, u8 chan, u8 f= ield_offset, return reg_val; } =20 +static int +tps23881_pi_set_2p_pw_limit(struct tps23881_priv *priv, u8 chan, u8 pw_pol) +{ + struct i2c_client *client =3D priv->client; + int ret, reg; + u16 val; + + reg =3D TPS23881_REG_2PAIR_POL1 + (chan % 4); + ret =3D i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + val =3D tps23881_set_val(ret, chan, 0, 0xff, pw_pol); + return i2c_smbus_write_word_data(client, reg, val); +} + +static int +tps23881_pi_set_4p_pw_limit(struct tps23881_priv *priv, u8 chan, u8 pw_pol) +{ + struct i2c_client *client =3D priv->client; + int ret, reg; + u16 val; + + if ((chan % 4) < 2) + reg =3D TPS23881_REG_4PAIR_POL1; + else + reg =3D TPS23881_REG_4PAIR_POL1 + 1; + + ret =3D i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + val =3D tps23881_set_val(ret, chan, 0, 0xff, pw_pol); + return i2c_smbus_write_word_data(client, reg, val); +} + static int tps23881_pi_enable(struct pse_controller_dev *pcdev, int id) { struct tps23881_priv *priv =3D to_tps23881_priv(pcdev); @@ -184,7 +234,38 @@ static int tps23881_pi_disable(struct pse_controller_d= ev *pcdev, int id) BIT(chan % 4)); } =20 - return i2c_smbus_write_word_data(client, TPS23881_REG_DET_CLA_EN, val); + ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_DET_CLA_EN, val); + if (ret) + return ret; + + /* No power policy set */ + if (priv->port[id].pw_pol < 0) + return 0; + + chan =3D priv->port[id].chan[0]; + ret =3D i2c_smbus_read_byte_data(client, TPS23881_REG_FOLDBACK); + if (ret < 0) + return ret; + + /* No need to test if the chan is PoE4 as setting either bit for a + * 4P configured port disables the automatic configuration on both + * channels. + */ + val =3D tps23881_set_val(ret, chan, 0, BIT(chan % 4), BIT(chan % 4)); + ret =3D i2c_smbus_write_byte_data(client, TPS23881_REG_FOLDBACK, val); + if (ret) + return ret; + + /* Set power policy */ + if (priv->port[id].is_4p) + /* One chan is enough to configure the PI power limit */ + ret =3D tps23881_pi_set_4p_pw_limit(priv, chan, + priv->port[id].pw_pol); + else + ret =3D tps23881_pi_set_2p_pw_limit(priv, chan, + priv->port[id].pw_pol); + + return ret; } =20 static int tps23881_pi_is_enabled(struct pse_controller_dev *pcdev, int id) @@ -214,6 +295,141 @@ static int tps23881_pi_is_enabled(struct pse_controll= er_dev *pcdev, int id) return enabled; } =20 +static int tps23881_pi_get_voltage(struct pse_controller_dev *pcdev, int i= d) +{ + struct tps23881_priv *priv =3D to_tps23881_priv(pcdev); + struct i2c_client *client =3D priv->client; + int ret; + u64 uV; + + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_INPUT_V); + if (ret < 0) + return ret; + + uV =3D ret & 0x3fff; + uV *=3D TPS23881_UV_STEP; + if (uV > TPS23881_MAX_UV) { + dev_err(&client->dev, "voltage read out of range\n"); + return -ERANGE; + } + + return (int)uV; +} + +static int +tps23881_pi_get_chan_current(struct tps23881_priv *priv, u8 chan) +{ + struct i2c_client *client =3D priv->client; + int reg, ret; + u64 tmp_64; + + if (chan < 4) + /* Registers 0x30 0x34 0x38 0x3c */ + reg =3D TPS23881_REG_CHAN1_A + chan * 4; + else + /* Registers 0x31 0x35 0x39 0x3d */ + reg =3D TPS23881_REG_CHAN1_A + 1 + (chan % 4) * 4; + + ret =3D i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + tmp_64 =3D ret; + tmp_64 *=3D TPS23881_NA_STEP; + /* uA =3D nA / 1000 */ + tmp_64 =3D DIV_ROUND_CLOSEST_ULL(tmp_64, 1000); + if (tmp_64 > TPS23881_MAX_UA) { + dev_err(&client->dev, "current read out of range\n"); + return -ERANGE; + } + return (int)tmp_64; +} + +static int +tps23881_pi_get_power(struct tps23881_priv *priv, unsigned long id) +{ + int ret, uV, uA; + u64 tmp_64; + u8 chan; + + ret =3D tps23881_pi_get_voltage(&priv->pcdev, id); + if (ret < 0) + return ret; + uV =3D ret; + + chan =3D priv->port[id].chan[0]; + ret =3D tps23881_pi_get_chan_current(priv, chan); + if (ret < 0) + return ret; + uA =3D ret; + + if (priv->port[id].is_4p) { + chan =3D priv->port[id].chan[1]; + ret =3D tps23881_pi_get_chan_current(priv, chan); + if (ret < 0) + return ret; + uA +=3D ret; + } + + tmp_64 =3D uV; + tmp_64 *=3D uA; + /* mW =3D uV * uA / 1000000000 */ + return DIV_ROUND_CLOSEST_ULL(tmp_64, 1000000000); +} + +static int +tps23881_pi_get_pw_limit_chan(struct tps23881_priv *priv, u8 chan) +{ + struct i2c_client *client =3D priv->client; + int ret, reg; + u16 val; + + reg =3D TPS23881_REG_2PAIR_POL1 + (chan % 4); + ret =3D i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + val =3D tps23881_calc_val(ret, chan, 0, 0xff); + return val * TPS23881_MW_STEP; +} + +static int tps23881_pi_get_pw_limit(struct tps23881_priv *priv, int id) +{ + int ret, mW; + u8 chan; + + chan =3D priv->port[id].chan[0]; + ret =3D tps23881_pi_get_pw_limit_chan(priv, chan); + if (ret < 0) + return ret; + + mW =3D ret; + if (priv->port[id].is_4p) { + chan =3D priv->port[id].chan[1]; + ret =3D tps23881_pi_get_pw_limit_chan(priv, chan); + if (ret < 0) + return ret; + mW +=3D ret; + } + + return mW; +} + +static int tps23881_pi_get_class(struct tps23881_priv *priv, int id) +{ + struct i2c_client *client =3D priv->client; + int ret, reg; + u8 chan; + + chan =3D priv->port[id].chan[0]; + reg =3D TPS23881_REG_CHAN1_CLASS + (chan % 4); + ret =3D i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + return tps23881_calc_val(ret, chan, 4, 0x0f); +} + static int tps23881_ethtool_get_status(struct pse_controller_dev *pcdev, unsigned long id, struct netlink_ext_ack *extack, @@ -256,6 +472,31 @@ static int tps23881_ethtool_get_status(struct pse_cont= roller_dev *pcdev, else status->c33_admin_state =3D ETHTOOL_C33_PSE_ADMIN_STATE_DISABLED; =20 + ret =3D tps23881_pi_get_power(priv, id); + if (ret < 0) + return ret; + status->c33_actual_pw =3D ret; + + status->c33_pw_limit_ranges =3D kzalloc(sizeof(*status->c33_pw_limit_rang= es), + GFP_KERNEL); + if (!status->c33_pw_limit_ranges) + return -ENOMEM; + + status->c33_actual_pw =3D ret; + status->c33_pw_limit_nb_ranges =3D 1; + status->c33_pw_limit_ranges->min =3D TPS23881_MIN_PI_PW_LIMIT; + status->c33_pw_limit_ranges->max =3D MAX_PI_PW; + + ret =3D tps23881_pi_get_pw_limit(priv, id); + if (ret < 0) + return ret; + status->c33_avail_pw_limit =3D ret; + + ret =3D tps23881_pi_get_class(priv, id); + if (ret < 0) + return ret; + status->c33_pw_class =3D ret; + return 0; } =20 @@ -553,6 +794,9 @@ tps23881_write_port_matrix(struct tps23881_priv *priv, if (port_matrix[i].exist) priv->port[pi_id].chan[0] =3D lgcl_chan; =20 + /* Initialize power policy internal value */ + priv->port[pi_id].pw_pol =3D -1; + /* Set hardware port matrix for all ports */ val |=3D hw_chan << (lgcl_chan * 2); =20 @@ -672,12 +916,90 @@ static int tps23881_setup_pi_matrix(struct pse_contro= ller_dev *pcdev) return ret; } =20 +static int tps23881_pi_get_current_limit(struct pse_controller_dev *pcdev, + int id) +{ + struct tps23881_priv *priv =3D to_tps23881_priv(pcdev); + int ret, mW, uV; + u64 tmp_64; + + ret =3D tps23881_pi_get_pw_limit(priv, id); + if (ret < 0) + return ret; + mW =3D ret; + + ret =3D tps23881_pi_get_voltage(pcdev, id); + if (ret < 0) + return ret; + uV =3D ret; + + tmp_64 =3D mW; + tmp_64 *=3D 1000000000ull; + /* uA =3D mW * 1000000000 / uV */ + return DIV_ROUND_CLOSEST_ULL(tmp_64, uV); +} + +static int tps23881_pi_set_current_limit(struct pse_controller_dev *pcdev, + int id, int max_uA) +{ + struct tps23881_priv *priv =3D to_tps23881_priv(pcdev); + u8 chan, pw_pol; + int ret, mW; + u64 tmp_64; + u16 val; + + ret =3D tps23881_pi_get_voltage(pcdev, id); + if (ret < 0) + return ret; + + tmp_64 =3D ret; + tmp_64 *=3D max_uA; + /* mW =3D uV * uA / 1000000000 */ + mW =3D DIV_ROUND_CLOSEST_ULL(tmp_64, 1000000000); + if (mW < TPS23881_MIN_PI_PW_LIMIT || MAX_PI_PW < mW) + return -ERANGE; + + chan =3D priv->port[id].chan[0]; + ret =3D i2c_smbus_read_byte_data(priv->client, TPS23881_REG_FOLDBACK); + if (ret < 0) + return ret; + + /* No need to test if the chan is PoE4 as setting either bit for a + * 4P configured port disables the automatic configuration on both + * channels. + */ + val =3D tps23881_set_val(ret, chan, 0, BIT(chan % 4), BIT(chan % 4)); + ret =3D i2c_smbus_write_byte_data(priv->client, TPS23881_REG_FOLDBACK, va= l); + if (ret) + return ret; + + pw_pol =3D DIV_ROUND_CLOSEST_ULL(mW, TPS23881_MW_STEP); + + /* Save power policy to reconfigure it after a disabled call */ + priv->port[id].pw_pol =3D pw_pol; + if (priv->port[id].is_4p) { + /* One chan is enough to configure the PI power limit */ + ret =3D tps23881_pi_set_4p_pw_limit(priv, chan, pw_pol); + if (ret < 0) + return ret; + } else { + ret =3D tps23881_pi_set_2p_pw_limit(priv, chan, pw_pol); + if (ret < 0) + return ret; + } + + return 0; +} + static const struct pse_controller_ops tps23881_ops =3D { .setup_pi_matrix =3D tps23881_setup_pi_matrix, .pi_enable =3D tps23881_pi_enable, .pi_disable =3D tps23881_pi_disable, .pi_is_enabled =3D tps23881_pi_is_enabled, .ethtool_get_status =3D tps23881_ethtool_get_status, + .pi_get_voltage =3D tps23881_pi_get_voltage, + .pi_get_current_limit =3D tps23881_pi_get_current_limit, + .pi_set_current_limit =3D tps23881_pi_set_current_limit, }; =20 static const char fw_parity_name[] =3D "ti/tps23881/tps23881-parity-14.bin= "; --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F46F1DED6E; Thu, 21 Nov 2024 14:43:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200234; cv=none; b=YNCG5SluG8T4S02Baw7nW+ziuNrLi0Mmn0znl1/gkZMXvQcmJO9MK6Hl0Y8O+21s+j8jAcmUtwNEGOk18JjcJy9dQphoqxBTj8afVNcsGQuDcN/NfmYeLvdF8oLpFelA2fhT6vRjbwHdOVZm8WDeFXIsILp3dluszC1cNMK7mbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200234; c=relaxed/simple; bh=r2LVXcXz9BO9jX+SECBfo4p/PJGFk8PifuoZoGDFf6c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=osJXkIDGvef5fgvZFQXf88teqYFJUUOODW1KvCIjkEX10Lj7jrP71umS0fBZFxygXp5y9odcJwbq+HOc7Y2DOtyFJuwaeNOLImMfKH0AGQuO0lDOS1IKTDb3dsMZFWpNcXmZoPqMnRlVILmsHPWlnY3EDsHiNRP/5D8kiNHE2T0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=FGpYhcEC; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="FGpYhcEC" Received: by mail.gandi.net (Postfix) with ESMTPSA id D79BB40008; Thu, 21 Nov 2024 14:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200230; 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=1mToZpR+IImksBdjIBc4se6t1/bKD5M6yV62a708rgs=; b=FGpYhcECvMZcC5GkEI5iC3x5GHTyj3FiwOloBeqXspbDY/09uUwiJ75WFQKxrAdDroi3XT eCEw+dqWVz9EJPqamyDx2iZeOSzPUr7i+8i8NY1Rup85HUlvjA29iHoOjUfSZuqDqb9jGO 7ezjU6Y0BTHj/QIELdUMhJizTfUWEvJ7BPM9uJq5FSZfw13cruErcX0MZZvDRAj1q4fVys YZJP9PHMyxLUYJh965hb54Rme+gYYkklpqwgm/ACA0FcD4mhxypgDxKwT/0HW7GCJb4kuL gzJTQWgBrsC6XmnHaL+H10YCQI2SuEUqDuMQvZz8EkpcoBSEdWLXRNaQZEdIEw== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:35 +0100 Subject: [PATCH RFC net-next v3 09/27] net: pse-pd: Add support for PSE device index Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-9-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Add support for a PSE device index to report the PSE controller index to the user through ethtool. This will be useful for future support of power domains and port priority management. Signed-off-by: Kory Maincent Acked-by: Oleksij Rempel --- Changes in v3: - Use u32 for all variables. Changes in v2: - new patch. --- drivers/net/pse-pd/pse_core.c | 23 ++++++++++++++++++----- include/linux/pse-pd/pse.h | 4 ++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index 432b6c2c04f8..411868bccbcc 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -13,6 +13,7 @@ =20 static DEFINE_MUTEX(pse_list_mutex); static LIST_HEAD(pse_controller_list); +static DEFINE_IDA(pse_ida); =20 /** * struct pse_control - a PSE control @@ -441,18 +442,22 @@ int pse_controller_register(struct pse_controller_dev= *pcdev) =20 mutex_init(&pcdev->lock); INIT_LIST_HEAD(&pcdev->pse_control_head); + ret =3D ida_alloc_max(&pse_ida, INT_MAX, GFP_KERNEL); + if (ret < 0) + return ret; + pcdev->id =3D ret; =20 if (!pcdev->nr_lines) pcdev->nr_lines =3D 1; =20 ret =3D of_load_pse_pis(pcdev); if (ret) - return ret; + goto free_pse_ida; =20 if (pcdev->ops->setup_pi_matrix) { ret =3D pcdev->ops->setup_pi_matrix(pcdev); if (ret) - return ret; + goto free_pse_ida; } =20 /* Each regulator name len is pcdev dev name + 7 char + @@ -469,15 +474,17 @@ int pse_controller_register(struct pse_controller_dev= *pcdev) continue; =20 reg_name =3D devm_kzalloc(pcdev->dev, reg_name_len, GFP_KERNEL); - if (!reg_name) - return -ENOMEM; + if (!reg_name) { + ret =3D -ENOMEM; + goto free_pse_ida; + } =20 snprintf(reg_name, reg_name_len, "pse-%s_pi%d", dev_name(pcdev->dev), i); =20 ret =3D devm_pse_pi_regulator_register(pcdev, reg_name, i); if (ret) - return ret; + goto free_pse_ida; } =20 mutex_lock(&pse_list_mutex); @@ -485,6 +492,10 @@ int pse_controller_register(struct pse_controller_dev = *pcdev) mutex_unlock(&pse_list_mutex); =20 return 0; + +free_pse_ida: + ida_free(&pse_ida, pcdev->id); + return ret; } EXPORT_SYMBOL_GPL(pse_controller_register); =20 @@ -495,6 +506,7 @@ EXPORT_SYMBOL_GPL(pse_controller_register); void pse_controller_unregister(struct pse_controller_dev *pcdev) { pse_release_pis(pcdev); + ida_free(&pse_ida, pcdev->id); mutex_lock(&pse_list_mutex); list_del(&pcdev->list); mutex_unlock(&pse_list_mutex); @@ -751,6 +763,7 @@ static int _pse_ethtool_get_status(struct pse_controlle= r_dev *pcdev, return -EOPNOTSUPP; } =20 + status->pse_id =3D pcdev->id; return ops->ethtool_get_status(pcdev, id, extack, status); } =20 diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index bc5addccbf32..f2294a1d9b58 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -33,6 +33,7 @@ struct pse_control_config { /** * struct pse_control_status - PSE control/channel status. * + * @pse_id: index number of the PSE. Set by PSE core. * @podl_admin_state: operational state of the PoDL PSE * functions. IEEE 802.3-2018 30.15.1.1.2 aPoDLPSEAdminState * @podl_pw_status: power detection status of the PoDL PSE. @@ -54,6 +55,7 @@ struct pse_control_config { * ranges */ struct pse_control_status { + u32 pse_id; enum ethtool_podl_pse_admin_state podl_admin_state; enum ethtool_podl_pse_pw_d_status podl_pw_status; enum ethtool_c33_pse_admin_state c33_admin_state; @@ -152,6 +154,7 @@ struct pse_pi { * @types: types of the PSE controller * @pi: table of PSE PIs described in this controller device * @no_of_pse_pi: flag set if the pse_pis devicetree node is not used + * @id: Index of the PSE */ struct pse_controller_dev { const struct pse_controller_ops *ops; @@ -165,6 +168,7 @@ struct pse_controller_dev { enum ethtool_pse_types types; struct pse_pi *pi; bool no_of_pse_pi; + u32 id; }; =20 #if IS_ENABLED(CONFIG_PSE_CONTROLLER) --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 677361DEFE2; Thu, 21 Nov 2024 14:43:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200236; cv=none; b=KBqiO0YlDRH3WbONf4gaJvVkTJ7r0GSGzlrvX8NDKvCODoTzwwHtv1XNlVuqmFy1loNHVGr/R4RW1y76c7Nfw4wdTPS4KJIRlWOlgFh0hvoBbEeMtUOKn6bflEkx/wf4q2z7zKc3tV7MSgFbKF69xfuAJQzRnZlGAgs0dqhNoFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200236; c=relaxed/simple; bh=GpiGdCyu1IXDR6hQGwdCSe4nlwJmEzxGDVSAK+kmfWw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ouDM/Faw0FSkFx5K7rPMJqANIZ3EXyaB8Gj9BFcGhwDXVLAQf15T5DJFYc+g6ufGgi4MAPRuog9DyHMl2pK1KUgRCEDqfNJ/cKMCM9oYG/8oV9JugUglX5F/TuBQawAN4taV4mtg2DQPRq6xw1GZSerBgBE/GKm4Ltm28Qb/3IM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=iSPs/3vj; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="iSPs/3vj" Received: by mail.gandi.net (Postfix) with ESMTPSA id F25F040007; Thu, 21 Nov 2024 14:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200233; 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=tkd5eN5qU75yl4G79Wuk8W+36wyuuBZi6jiU/wIf/k0=; b=iSPs/3vjQYI/RSDOUIFwCSb+QGwS4+6KtbVTf+OGPuFBlcCXx/qmPaoXTuVhSnCSzMBML3 4VzoUQJaHxtaqQyTjYoUM3yP/GAjW+lie1sF1+oFPlnYWpZ3jcWvdL9FJvVZg96hzhDPdh 55Mm2ciCcEr2li4DyZJlD2PdUG9Kp6fuhTq88eXspc+0tqZiCxoYDRRw0ttGQJCegJaZs5 kX6TcEZWqpjaKAtuJylSan9YWWWGr3XV/Mzq9GXlLHJ475AjYjUnnSBbulQxM7Wd6a1bZ5 /NnyISImnR5b4lFDH6D7GpIkI269I2Tx/x4Yqz59ttoOTNHDLyV1WHtb1Dqvhw== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:36 +0100 Subject: [PATCH RFC net-next v3 10/27] net: ethtool: Add support for new PSE device index description Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-10-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Add functionality to report the newly introduced PSE device index to the user, enabling better identification and management of PSE devices. Reviewed-by: Oleksij Rempel Reviewed-by: Andrew Lunn Signed-off-by: Kory Maincent --- Changes in v2: - new patch. --- Documentation/networking/ethtool-netlink.rst | 4 ++++ include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/pse-pd.c | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/n= etworking/ethtool-netlink.rst index b25926071ece..bd7173d1fa4d 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -1766,6 +1766,7 @@ Kernel response contents: limit of the PoE PSE. ``ETHTOOL_A_C33_PSE_PW_LIMIT_RANGES`` nested Supported power limit configuration ranges. + ``ETHTOOL_A_PSE_ID`` u32 Index of the PSE =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D =20 When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_STATE`` attribute identi= fies @@ -1839,6 +1840,9 @@ identifies the C33 PSE power limit ranges through If the controller works with fixed classes, the min and max values will be equal. =20 +The ``ETHTOOL_A_PSE_ID`` attribute identifies the index of the PSE +controller. + PSE_SET =3D=3D=3D=3D=3D=3D=3D =20 diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/etht= ool_netlink.h index 283305f6b063..9a4c293a9a82 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -970,6 +970,7 @@ enum { ETHTOOL_A_C33_PSE_EXT_SUBSTATE, /* u32 */ ETHTOOL_A_C33_PSE_AVAIL_PW_LIMIT, /* u32 */ ETHTOOL_A_C33_PSE_PW_LIMIT_RANGES, /* nest - _C33_PSE_PW_LIMIT_* */ + ETHTOOL_A_PSE_ID, /* u32 */ =20 /* add new constants above here */ __ETHTOOL_A_PSE_CNT, diff --git a/net/ethtool/pse-pd.c b/net/ethtool/pse-pd.c index a0705edca22a..5edb8b0a669e 100644 --- a/net/ethtool/pse-pd.c +++ b/net/ethtool/pse-pd.c @@ -83,6 +83,7 @@ static int pse_reply_size(const struct ethnl_req_info *re= q_base, const struct pse_control_status *st =3D &data->status; int len =3D 0; =20 + len +=3D nla_total_size(sizeof(u32)); /* _PSE_ID */ if (st->podl_admin_state > 0) len +=3D nla_total_size(sizeof(u32)); /* _PODL_PSE_ADMIN_STATE */ if (st->podl_pw_status > 0) @@ -148,6 +149,9 @@ static int pse_fill_reply(struct sk_buff *skb, const struct pse_reply_data *data =3D PSE_REPDATA(reply_base); const struct pse_control_status *st =3D &data->status; =20 + if (nla_put_u32(skb, ETHTOOL_A_PSE_ID, st->pse_id)) + return -EMSGSIZE; + if (st->podl_admin_state > 0 && nla_put_u32(skb, ETHTOOL_A_PODL_PSE_ADMIN_STATE, st->podl_admin_state)) --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D02AD1DF263; Thu, 21 Nov 2024 14:43:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200238; cv=none; b=p4US2dddlI+T0uc40QmPN4NOAVRv/c1zwIQ/YWag4PQH+xxW/73S9LnjbGdYDfVrPl2KnbYGNEEhGwEJjwF60WED2J39Jq8fDdj5R5Uwv7KwYpj20mD+vGvpB6wYxInmUuqNVL3gI/JynDFV7dopV8SGqb5wGPRcpHADy7GQTQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200238; c=relaxed/simple; bh=rP+gjxfNiydSHOlT4Rz1/ZTy07AjwCiEEMb4usd8nBo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E2svQFzJh2CZgihJE3uQndprbwMJWZWn29i6w7jdM3anV4DfNyFdnV9yPNQ9p/S8u0iWjw4qKJYbnf/wPifW0E0PNVIfoV5ALpLWW9SPLC2YCpB/qcGp9++9Qag9KIC85Y+p9uQsw7c3/wfboOlFUUmDXMbtHQX7tWewnPZDQnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=TKH4TMvy; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="TKH4TMvy" Received: by mail.gandi.net (Postfix) with ESMTPSA id 41A494000B; Thu, 21 Nov 2024 14:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200235; 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=bP1tzyckBMmYWq9DCKVrsYF6OCjs8sclMJz28WzMgsE=; b=TKH4TMvy/YPRsNjWIDWtlg41nY1Aq+yhQUZ47XO3mjmcxxMLQ4w/FDxJ3YGvLEuzehKfE1 0ykmyN3XwXdMvKRu/C18PYiP2VfbDd1H68XXA3nj6uIHjkyNUD8ncDkQOk614bLddtb47m gmDVnZQzvAXifx2brnxpz9ZJrK/Mk9E7MfcNdjBFSlzUowCm7QYg+yHp3XQxTdxvz7BZpf kM9JllzFyik1A/HYfqYSl/G5444Ye8xZGw78HfogU4+XX0djhOjBypKFCxacHjglTOME8Q Ex6vXcYveIlrHFYgnsByS1BsA4nRGAHFqIFIYRl/d6UtLuUKbJRN1tXFtkgtPQ== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:37 +0100 Subject: [PATCH RFC net-next v3 11/27] net: ethtool: Add support for ethnl_info_init_ntf helper function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-11-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Introduce support for the ethnl_info_init_ntf helper function to enable initialization of ethtool notifications outside of the netlink.c file. This change allows for more flexible notification handling. Signed-off-by: Kory Maincent --- Changes in v2: - new patch. --- net/ethtool/netlink.c | 5 +++++ net/ethtool/netlink.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index e3f0ef6b851b..808cc8096f93 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -805,6 +805,11 @@ static void ethnl_default_notify(struct net_device *de= v, unsigned int cmd, typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned in= t cmd, const void *data); =20 +void ethnl_info_init_ntf(struct genl_info *info, u8 cmd) +{ + genl_info_init_ntf(info, ðtool_genl_family, cmd); +} + static const ethnl_notify_handler_t ethnl_notify_handlers[] =3D { [ETHTOOL_MSG_LINKINFO_NTF] =3D ethnl_default_notify, [ETHTOOL_MSG_LINKMODES_NTF] =3D ethnl_default_notify, diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 203b08eb6c6f..d04a8e9d54db 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -322,6 +322,8 @@ struct ethnl_sock_priv { int ethnl_sock_priv_set(struct sk_buff *skb, struct net_device *dev, u32 p= ortid, enum ethnl_sock_type type); =20 +void ethnl_info_init_ntf(struct genl_info *info, u8 cmd); + /** * struct ethnl_request_ops - unified handling of GET and SET requests * @request_cmd: command id for request (GET) --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6E011DF74C; Thu, 21 Nov 2024 14:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200241; cv=none; b=ur/HU/zP84r6itfIt8Ri15jUK0r74XP7PvFfiav+YQY0gPXKYUt3wKRg5itfDVt4qIuz3E09IDBELmXcJ4g/DQiV8GAJdVp+VdEzqaWe8agcd4FXhGDqj7vYN/fVzGuoTQ8lD0AzjKnZ97fTRQn4+Wvib92pBwdW5RWn4GcY6rw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200241; c=relaxed/simple; bh=OVOfaZFZVSk9ljv9ZOCPW4tDpDDQDn5SpqypUiNhPME=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pC2IFlXZRzk8BNIInZC565un7xDLTnOe86tCvXoaUOha6zvMZqpYJvrzGrkzDQXi+bYTDALUDW1BlVBijDX79Nrh+kkrTIkbmO8BL5qnwO9Eu2+HKO/KmFFWrri1VQFjCwKzuzaTHovXMQSAtZSC6mtjtsEBWgb7peRmPDn5Z+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=QuCwusy7; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="QuCwusy7" Received: by mail.gandi.net (Postfix) with ESMTPSA id 5F94540009; Thu, 21 Nov 2024 14:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200237; 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=WBYfM8Qow2vJ/07+gWETNGXed90ocsCYB+Bq/z8BBNo=; b=QuCwusy7FyNROlrYqZUHOKV/wUMfKrrpKRxtytIv8UEvog2FSSEjZVT/lOxIoFz5x0Z4c2 J7H9hwp6wmYpr2R77xz3sEv/xWDgVG89e56e4dqRcShpLlr63dDumGRZ7z3ffgprbr8EVZ 0CY9YtJ/rVWQi0LXZaRdaqrcmz6Gz3BshhYn+Cwqpr8+4v718ZYt9FHY9CdPRz4dIi2dvp KDjoboCrIhNPosp6mczyds6xhtLwf/88Vq0lQ0bgzQkqSO/YKRZ1zIX56gfrniUxeG3n3M L58tkGwnOlfYLSZYt8J51C+y1dQRZmieE5fkjtqVy6LhKizAKDtzfdnrkrVZMg== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:38 +0100 Subject: [PATCH RFC net-next v3 12/27] net: pse-pd: Add support for reporting events Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-12-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Add support for devm_pse_irq_helper() to register PSE interrupts. This aims to report events such as over-current or over-temperature conditions similarly to how the regulator API handles them but using a specific PSE ethtool netlink socket. Signed-off-by: Kory Maincent --- Change in v3: - Remove C33 prefix when it is not in the standards. - Fix pse_to_regulator_notifs which could not report regulator events together. - Fix deadlock issue. - Save interrupt in pcdev structure for later use. Change in v2: - Add support for PSE ethtool notification. - Saved the attached phy_device in the pse_control structure to know which interface should have the notification. - Rethink devm_pse_irq_helper() without devm_regulator_irq_helper() call. --- drivers/net/mdio/fwnode_mdio.c | 26 ++++---- drivers/net/pse-pd/pse_core.c | 126 +++++++++++++++++++++++++++++++= +++- include/linux/ethtool_netlink.h | 9 +++ include/linux/pse-pd/pse.h | 18 ++++- include/uapi/linux/ethtool.h | 11 +++ include/uapi/linux/ethtool_netlink.h | 11 +++ net/ethtool/pse-pd.c | 46 +++++++++++++ 7 files changed, 230 insertions(+), 17 deletions(-) diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index b156493d7084..7d571895a8eb 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -18,7 +18,8 @@ MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("FWNODE MDIO bus (Ethernet PHY) accessors"); =20 static struct pse_control * -fwnode_find_pse_control(struct fwnode_handle *fwnode) +fwnode_find_pse_control(struct fwnode_handle *fwnode, + struct phy_device *phydev) { struct pse_control *psec; struct device_node *np; @@ -30,7 +31,7 @@ fwnode_find_pse_control(struct fwnode_handle *fwnode) if (!np) return NULL; =20 - psec =3D of_pse_control_get(np); + psec =3D of_pse_control_get(np, phydev); if (PTR_ERR(psec) =3D=3D -ENOENT) return NULL; =20 @@ -121,15 +122,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, u32 phy_id; int rc; =20 - psec =3D fwnode_find_pse_control(child); - if (IS_ERR(psec)) - return PTR_ERR(psec); - mii_ts =3D fwnode_find_mii_timestamper(child); - if (IS_ERR(mii_ts)) { - rc =3D PTR_ERR(mii_ts); - goto clean_pse; - } + if (IS_ERR(mii_ts)) + return PTR_ERR(mii_ts); =20 is_c45 =3D fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45= "); if (is_c45 || fwnode_get_phy_id(child, &phy_id)) @@ -162,6 +157,12 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, goto clean_phy; } =20 + psec =3D fwnode_find_pse_control(child, phy); + if (IS_ERR(psec)) { + rc =3D PTR_ERR(psec); + goto unregister_phy; + } + phy->psec =3D psec; =20 /* phy->mii_ts may already be defined by the PHY driver. A @@ -173,12 +174,13 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, =20 return 0; =20 +unregister_phy: + if (is_acpi_node(child) || is_of_node(child)) + phy_device_remove(phy); clean_phy: phy_device_free(phy); clean_mii_ts: unregister_mii_timestamper(mii_ts); -clean_pse: - pse_control_put(psec); =20 return rc; } diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index 411868bccbcc..8b5a9e7fd9c5 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -6,6 +6,7 @@ // =20 #include +#include #include #include #include @@ -23,6 +24,7 @@ static DEFINE_IDA(pse_ida); * @list: list entry for the pcdev's PSE controller list * @id: ID of the PSE line in the PSE controller device * @refcnt: Number of gets of this pse_control + * @attached_phydev: PHY device pointer attached by the PSE control */ struct pse_control { struct pse_controller_dev *pcdev; @@ -30,6 +32,7 @@ struct pse_control { struct list_head list; unsigned int id; struct kref refcnt; + struct phy_device *attached_phydev; }; =20 static int of_load_single_pse_pi_pairset(struct device_node *node, @@ -553,6 +556,120 @@ int devm_pse_controller_register(struct device *dev, } EXPORT_SYMBOL_GPL(devm_pse_controller_register); =20 +struct pse_irq { + struct pse_controller_dev *pcdev; + struct pse_irq_desc desc; + unsigned long *notifs; +}; + +static unsigned long pse_to_regulator_notifs(unsigned long notifs) +{ + unsigned long rnotifs =3D 0; + + if (notifs & ETHTOOL_PSE_EVENT_OVER_CURRENT) + rnotifs |=3D REGULATOR_EVENT_OVER_CURRENT; + if (notifs & ETHTOOL_PSE_EVENT_OVER_TEMP) + rnotifs |=3D REGULATOR_EVENT_OVER_TEMP; + + return rnotifs; +} + +static struct phy_device * +pse_control_find_phy_by_id(struct pse_controller_dev *pcdev, int id) +{ + struct pse_control *psec; + + mutex_lock(&pse_list_mutex); + list_for_each_entry(psec, &pcdev->pse_control_head, list) { + if (psec->id =3D=3D id) { + mutex_unlock(&pse_list_mutex); + return psec->attached_phydev; + } + } + mutex_unlock(&pse_list_mutex); + + return NULL; +} + +static irqreturn_t pse_isr(int irq, void *data) +{ + struct netlink_ext_ack extack =3D {}; + struct pse_controller_dev *pcdev; + unsigned long notifs_mask =3D 0; + struct pse_irq_desc *desc; + struct pse_irq *h =3D data; + int ret, i; + + desc =3D &h->desc; + pcdev =3D h->pcdev; + + /* Clear notifs mask */ + memset(h->notifs, 0, pcdev->nr_lines * sizeof(*h->notifs)); + mutex_lock(&pcdev->lock); + ret =3D desc->map_event(irq, pcdev, h->notifs, ¬ifs_mask); + mutex_unlock(&pcdev->lock); + if (ret || !notifs_mask) + return IRQ_NONE; + + for_each_set_bit(i, ¬ifs_mask, pcdev->nr_lines) { + struct phy_device *phydev; + unsigned long notifs, rnotifs; + + /* Do nothing PI not described */ + if (!pcdev->pi[i].rdev) + continue; + + notifs =3D h->notifs[i]; + dev_dbg(h->pcdev->dev, + "Sending PSE notification EVT 0x%lx\n", notifs); + + phydev =3D pse_control_find_phy_by_id(pcdev, i); + if (phydev) + ethnl_pse_send_ntf(phydev, notifs, &extack); + rnotifs =3D pse_to_regulator_notifs(notifs); + regulator_notifier_call_chain(pcdev->pi[i].rdev, rnotifs, + NULL); + } + + return IRQ_HANDLED; +} + +int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, + int irq_flags, const struct pse_irq_desc *d) +{ + struct device *dev =3D pcdev->dev; + struct pse_irq *h; + int ret; + + if (!d || !d->map_event || !d->name) + return -EINVAL; + + h =3D devm_kzalloc(dev, sizeof(*h), GFP_KERNEL); + if (!h) + return -ENOMEM; + + h->pcdev =3D pcdev; + h->desc =3D *d; + h->desc.name =3D devm_kstrdup(dev, d->name, GFP_KERNEL); + if (!h->desc.name) + return -ENOMEM; + + h->notifs =3D devm_kcalloc(pcdev->dev, pcdev->nr_lines, + sizeof(*h->notifs), GFP_KERNEL); + if (!h->notifs) + return -ENOMEM; + + ret =3D devm_request_threaded_irq(dev, irq, NULL, pse_isr, + IRQF_ONESHOT | irq_flags, + h->desc.name, h); + if (ret) + dev_err(pcdev->dev, "Failed to request IRQ %d\n", irq); + + pcdev->irq =3D irq; + return ret; +} +EXPORT_SYMBOL_GPL(devm_pse_irq_helper); + /* PSE control section */ =20 static void __pse_control_release(struct kref *kref) @@ -595,7 +712,8 @@ void pse_control_put(struct pse_control *psec) EXPORT_SYMBOL_GPL(pse_control_put); =20 static struct pse_control * -pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int in= dex) +pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int in= dex, + struct phy_device *phydev) { struct pse_control *psec; int ret; @@ -634,6 +752,7 @@ pse_control_get_internal(struct pse_controller_dev *pcd= ev, unsigned int index) psec->pcdev =3D pcdev; list_add(&psec->list, &pcdev->pse_control_head); psec->id =3D index; + psec->attached_phydev =3D phydev; kref_init(&psec->refcnt); =20 return psec; @@ -689,7 +808,8 @@ static int psec_id_xlate(struct pse_controller_dev *pcd= ev, return pse_spec->args[0]; } =20 -struct pse_control *of_pse_control_get(struct device_node *node) +struct pse_control *of_pse_control_get(struct device_node *node, + struct phy_device *phydev) { struct pse_controller_dev *r, *pcdev; struct of_phandle_args args; @@ -739,7 +859,7 @@ struct pse_control *of_pse_control_get(struct device_no= de *node) } =20 /* pse_list_mutex also protects the pcdev's pse_control list */ - psec =3D pse_control_get_internal(pcdev, psec_id); + psec =3D pse_control_get_internal(pcdev, psec_id, phydev); =20 out: mutex_unlock(&pse_list_mutex); diff --git a/include/linux/ethtool_netlink.h b/include/linux/ethtool_netlin= k.h index aba91335273a..0fa1d8f59cf2 100644 --- a/include/linux/ethtool_netlink.h +++ b/include/linux/ethtool_netlink.h @@ -43,6 +43,9 @@ void ethtool_aggregate_rmon_stats(struct net_device *dev, struct ethtool_rmon_stats *rmon_stats); bool ethtool_dev_mm_supported(struct net_device *dev); =20 +void ethnl_pse_send_ntf(struct phy_device *phydev, unsigned long notif, + struct netlink_ext_ack *extack); + #else static inline int ethnl_cable_test_alloc(struct phy_device *phydev, u8 cmd) { @@ -120,6 +123,12 @@ static inline bool ethtool_dev_mm_supported(struct net= _device *dev) return false; } =20 +static inline void ethnl_pse_send_ntf(struct phy_device *phydev, + unsigned long notif, + struct netlink_ext_ack *extack) +{ +} + #endif /* IS_ENABLED(CONFIG_ETHTOOL_NETLINK) */ =20 static inline int ethnl_cable_test_result(struct phy_device *phydev, u8 pa= ir, diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index f2294a1d9b58..be6e967f9ac3 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -8,6 +8,7 @@ #include #include #include +#include =20 /* Maximum current in uA according to IEEE 802.3-2022 Table 145-1 */ #define MAX_PI_CURRENT 1920000 @@ -17,6 +18,13 @@ struct phy_device; struct pse_controller_dev; =20 +struct pse_irq_desc { + const char *name; + int (*map_event)(int irq, struct pse_controller_dev *pcdev, + unsigned long *notifs, + unsigned long *notifs_mask); +}; + /** * struct pse_control_config - PSE control/channel configuration. * @@ -155,6 +163,7 @@ struct pse_pi { * @pi: table of PSE PIs described in this controller device * @no_of_pse_pi: flag set if the pse_pis devicetree node is not used * @id: Index of the PSE + * @irq: PSE interrupt */ struct pse_controller_dev { const struct pse_controller_ops *ops; @@ -169,6 +178,7 @@ struct pse_controller_dev { struct pse_pi *pi; bool no_of_pse_pi; u32 id; + int irq; }; =20 #if IS_ENABLED(CONFIG_PSE_CONTROLLER) @@ -177,8 +187,11 @@ void pse_controller_unregister(struct pse_controller_d= ev *pcdev); struct device; int devm_pse_controller_register(struct device *dev, struct pse_controller_dev *pcdev); +int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, + int irq_flags, const struct pse_irq_desc *d); =20 -struct pse_control *of_pse_control_get(struct device_node *node); +struct pse_control *of_pse_control_get(struct device_node *node, + struct phy_device *phydev); void pse_control_put(struct pse_control *psec); =20 int pse_ethtool_get_status(struct pse_control *psec, @@ -196,7 +209,8 @@ bool pse_has_c33(struct pse_control *psec); =20 #else =20 -static inline struct pse_control *of_pse_control_get(struct device_node *n= ode) +static inline struct pse_control *of_pse_control_get(struct device_node *n= ode, + struct phy_device *phydev) { return ERR_PTR(-ENOENT); } diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index fc1f54b065f9..a4c93d6de218 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -998,6 +998,17 @@ enum ethtool_c33_pse_pw_d_status { ETHTOOL_C33_PSE_PW_D_STATUS_OTHERFAULT, }; =20 +/** + * enum ethtool_pse_events - event list of the PSE controller. + * @ETHTOOL_PSE_EVENT_OVER_CURRENT: PSE output current is too high. + * @ETHTOOL_PSE_EVENT_OVER_TEMP: PSE in over temperature state. + */ + +enum ethtool_pse_events { + ETHTOOL_PSE_EVENT_OVER_CURRENT =3D 1 << 0, + ETHTOOL_PSE_EVENT_OVER_TEMP =3D 1 << 1, +}; + /** * enum ethtool_podl_pse_admin_state - operational state of the PoDL PSE * functions. IEEE 802.3-2018 30.15.1.1.2 aPoDLPSEAdminState diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/etht= ool_netlink.h index 9a4c293a9a82..91c1bd9349b0 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -114,6 +114,7 @@ enum { ETHTOOL_MSG_MODULE_FW_FLASH_NTF, ETHTOOL_MSG_PHY_GET_REPLY, ETHTOOL_MSG_PHY_NTF, + ETHTOOL_MSG_PSE_NTF, =20 /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -977,6 +978,16 @@ enum { ETHTOOL_A_PSE_MAX =3D (__ETHTOOL_A_PSE_CNT - 1) }; =20 +/* PSE NOTIFY */ +enum { + ETHTOOL_A_PSE_NTF_UNSPEC, + ETHTOOL_A_PSE_NTF_HEADER, /* nest - ETHTOOL_A_HEADER_* */ + ETHTOOL_A_PSE_NTF_EVENTS, /* u32 */ + + __ETHTOOL_A_PSE_NTF_CNT, + ETHTOOL_A_PSE_NTF_MAX =3D (__ETHTOOL_A_PSE_NTF_CNT - 1) +}; + enum { ETHTOOL_A_RSS_UNSPEC, ETHTOOL_A_RSS_HEADER, diff --git a/net/ethtool/pse-pd.c b/net/ethtool/pse-pd.c index 5edb8b0a669e..19ab6bd35ad4 100644 --- a/net/ethtool/pse-pd.c +++ b/net/ethtool/pse-pd.c @@ -319,3 +319,49 @@ const struct ethnl_request_ops ethnl_pse_request_ops = =3D { .set =3D ethnl_set_pse, /* PSE has no notification */ }; + +void ethnl_pse_send_ntf(struct phy_device *phydev, unsigned long notifs, + struct netlink_ext_ack *extack) +{ + struct net_device *netdev =3D phydev->attached_dev; + struct genl_info info; + void *reply_payload; + struct sk_buff *skb; + int reply_len; + int ret; + + if (!netdev || !notifs) + return; + + ethnl_info_init_ntf(&info, ETHTOOL_MSG_MM_NTF); + info.extack =3D extack; + + reply_len =3D ethnl_reply_header_size(); + /* _C33_PSE_NTF_EVENTS */ + reply_len +=3D nla_total_size(sizeof(u32)); + skb =3D genlmsg_new(reply_len, GFP_KERNEL); + reply_payload =3D ethnl_bcastmsg_put(skb, ETHTOOL_MSG_MM_NTF); + if (!reply_payload) + goto err_skb; + + ret =3D ethnl_fill_reply_header(skb, netdev, + ETHTOOL_A_PSE_NTF_HEADER); + if (ret < 0) + goto err_skb; + + ret =3D nla_put_u32(skb, ETHTOOL_A_PSE_NTF_EVENTS, notifs); + if (ret) { + WARN_ONCE(ret =3D=3D -EMSGSIZE, + "calculated message payload length (%d) not sufficient\n", + reply_len); + goto err_skb; + } + + genlmsg_end(skb, reply_payload); + ethnl_multicast(skb, netdev); + return; + +err_skb: + nlmsg_free(skb); +} +EXPORT_SYMBOL_GPL(ethnl_pse_send_ntf); --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F9331DF749; Thu, 21 Nov 2024 14:44:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200243; cv=none; b=R6tsm3PQenauKvKn19/GpfxXtuIkUiBbM5AsCSCMCwKtEs89ZMB07WzZ2yUPdiXDyADECBqmhSqM5XN78xooOQEW5J7qVctMmZVTooAR2KWjkpi8AboMqWfqaxS0UWBgFj3M0Dx9mkRm8Xj0wwRS/IlvIqAeCIXhb7kUtTxf2bM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200243; c=relaxed/simple; bh=RJtM4WeK5tdP2686V9W4U9y9FnQlBaytEc06Hdxl9cw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=adHo6jWc3iN97rS4+3XM3yR7S5tlEkInXvRqQnuLpKcfIpDZriyUQtP011Nowf7jWL3CMS8ydWWVCJ47pVqhug/OkTIhhy04SA0CdcYe4imbi+6NOsg2zx+wUqG1669WD6DLLbJD7MTMsPyuxZTq6eJVgm5p0OQgBpE50VUxD98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=hAJJ0V5C; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="hAJJ0V5C" Received: by mail.gandi.net (Postfix) with ESMTPSA id B520040011; Thu, 21 Nov 2024 14:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200239; 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=jD37FPcA/oQ7xGn1KpPQBFYBDQ3WJO4x7PpFCfb9VOo=; b=hAJJ0V5CTFbBMb6NqiJLOhhBUHzrqgpuTXEdWcgCtAJnk3rQZanLRZUOEtLl6MRr/ayWCW DkKn3i/bMqUuFIimhN45ZeTVAg1xSXpbBUgjZYY/ZXXnp7lIw/mXSyrv9zYp7YLop+SR3v +vPpBiU/OgLesg95uSh6oGAeWCA62fCrtu/QWDwUvBqZQHpY0Kcy90B9Hg4u+1jabDdTZm 6mbEDaTSsmcfFgyOlNW0cckLLrnpO5YEnuvStwsrCSZ30pUMoZVNxjgY6/5DolHw7g2PSR +fY3n7Ov6ytW9wdyk6ghoRsa4CAeeInq1qVclwNPUNjkZaE7xePMny9pkUl6aA== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:39 +0100 Subject: [PATCH RFC net-next v3 13/27] netlink: specs: Add support for PSE netlink notifications Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-13-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Introduce support for PSE-specific netlink notifications, allowing for the reporting of events related to c33 PSE (Power Sourcing Equipment). Signed-off-by: Kory Maincent --- Changes in v2: - new patch. --- Documentation/netlink/specs/ethtool.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netli= nk/specs/ethtool.yaml index 93369f0eb816..f27c76d965d9 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -1137,6 +1137,18 @@ attribute-sets: - name: downstream-sfp-name type: string + - + name: pse-ntf + attributes: + - + name: header + type: nest + nested-attributes: header + - + name: pse-ntf-events + type: nest + nested-attributes: bitset + name-prefix: ethtool-a- =20 operations: enum-model: directional @@ -1960,3 +1972,13 @@ operations: name: phy-ntf doc: Notification for change in PHY devices. notify: phy-get + - + name: pse-ntf + doc: Notification for pse events. + + attribute-set: pse-ntf + + event: + attributes: + - header + - pse-ntf-events --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B3241DFD82; Thu, 21 Nov 2024 14:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200245; cv=none; b=cM2iKEN3G6fOqp4Nv0ol4CPvD0CCeltYx8SG7R3GRlG4EVmTTrqIGRaXedT07PnLCnjyw9hMIOIKVNnn2qerm/mXjPOEjgugWZD39HGPYqxQhVIqB8eRhqMsBYv8EFcoSVRtacfyhS+oqK6chRw88pYBuWhhkqOWnI29GuQwjOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200245; c=relaxed/simple; bh=QfqHP8jQ3HE57WJ53GO2+IxI/8dWMrI4Z5hUUWqWUFA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LU1019CDIYqZqTLkKTkrUst3n2CD87hJPr2AvRH+A+oUwP61uZVqy+elL7Nx9+go/kMwYqkKz/0H+tBQm6FfgR9CcOv4LSiA8d6Rjav+P2tKnomyr/GBYorLzr18SGnTDXv002q9aNqi2F/dehB70za417D0CtjgtJ26DWcVGv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=egn34iF4; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="egn34iF4" Received: by mail.gandi.net (Postfix) with ESMTPSA id D8F1740006; Thu, 21 Nov 2024 14:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200241; 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=MRiOopLuCYf+dwOYK9bRpViinqwBSZssZX1G6ZdiUGg=; b=egn34iF4U5Ktiu8MZiJJRYipnbX7sbjp7BajncIw7eluYuQkvQjtUNu8OJgpsd+9Hk0EY8 gt6UJhGFzBbxboasTsOrwp/Fh6C1B0BbX07Z3ckJllgevFL/maJ2E7zRF1i/71cwOWw9Yb 9R+tFqsOoIXONy4cvycFlvomvMLiLQLheRsHPNJyhdYrpZxLQBPmkqfGJL7afgETEqc2+4 hdnmJ6oA/oRe2P4KOMsVRHjh2kq/3CPMvmy44Nr9DMFF5qW4vfqhuPACuNHA8y6CRcRxlM gITg94d6gan4DLpCX47UMQMfj3/L3WL9vYLhsdB780jZuLD8XM7gqpVHg8DF2A== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:40 +0100 Subject: [PATCH RFC net-next v3 14/27] net: pse-pd: tps23881: Add support for PSE events and interrupts Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-14-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Add support for PSE event reporting through interrupts. Set up the newly introduced devm_pse_irq_helper helper to register the interrupt. Events are reported for over-current and over-temperature conditions. Signed-off-by: Kory Maincent --- Change in v3: - Loop over interruption register to be sure the interruption pin is freed before exiting the interrupt handler function. - Add exist variable to not report event for undescribed PIs. - Used helpers to convert the chan number to the PI port number. Change in v2: - Remove support for OSS pin and TPC23881 specific port priority management --- drivers/net/pse-pd/tps23881.c | 178 ++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 177 insertions(+), 1 deletion(-) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index b25561f95774..6fe8f150231f 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -17,6 +17,13 @@ =20 #define TPS23881_MAX_CHANS 8 =20 +#define TPS23881_REG_IT 0x0 +#define TPS23881_REG_IT_MASK 0x1 +#define TPS23881_REG_IT_IFAULT BIT(5) +#define TPS23881_REG_IT_SUPF BIT(7) +#define TPS23881_REG_FAULT 0x7 +#define TPS23881_REG_SUPF_EVENT 0xb +#define TPS23881_REG_TSD BIT(7) #define TPS23881_REG_PW_STATUS 0x10 #define TPS23881_REG_OP_MODE 0x12 #define TPS23881_OP_MODE_SEMIAUTO 0xaaaa @@ -24,6 +31,7 @@ #define TPS23881_REG_DET_CLA_EN 0x14 #define TPS23881_REG_GEN_MASK 0x17 #define TPS23881_REG_NBITACC BIT(5) +#define TPS23881_REG_INTEN BIT(7) #define TPS23881_REG_PW_EN 0x19 #define TPS23881_REG_2PAIR_POL1 0x1e #define TPS23881_REG_PORT_MAP 0x26 @@ -53,6 +61,7 @@ struct tps23881_port_desc { u8 chan[2]; bool is_4p; int pw_pol; + bool exist; }; =20 struct tps23881_priv { @@ -791,8 +800,10 @@ tps23881_write_port_matrix(struct tps23881_priv *priv, hw_chan =3D port_matrix[i].hw_chan[0] % 4; =20 /* Set software port matrix for existing ports */ - if (port_matrix[i].exist) + if (port_matrix[i].exist) { priv->port[pi_id].chan[0] =3D lgcl_chan; + priv->port[pi_id].exist =3D true; + } =20 /* Initialize power policy internal value */ priv->port[pi_id].pw_pol =3D -1; @@ -1098,6 +1109,165 @@ static int tps23881_flash_sram_fw(struct i2c_client= *client) return 0; } =20 +/* Convert interrupt events to 0xff to be aligned with the chan + * number. + */ +static u8 tps23881_it_export_chans_helper(u16 reg_val, u8 field_offset) +{ + u8 val; + + val =3D (reg_val >> (4 + field_offset) & 0xf0) | + (reg_val >> field_offset & 0x0f); + + return val; +} + +/* Convert chan number to port number */ +static void tps23881_set_notifs_helper(struct tps23881_priv *priv, + u8 chans, + unsigned long *notifs, + unsigned long *notifs_mask, + enum ethtool_pse_events event) +{ + u8 chan; + int i; + + if (!chans) + return; + + for (i =3D 0; i < TPS23881_MAX_CHANS; i++) { + if (!priv->port[i].exist) + continue; + /* No need to look at the 2nd channel in case of PoE4 as + * both registers are set. + */ + chan =3D priv->port[i].chan[0]; + + if (BIT(chan) & chans) { + *notifs_mask |=3D BIT(i); + notifs[i] |=3D event; + } + } +} + +static void tps23881_irq_event_over_temp(struct tps23881_priv *priv, + u16 reg_val, + unsigned long *notifs, + unsigned long *notifs_mask) +{ + int i; + + if (reg_val & TPS23881_REG_TSD) { + for (i =3D 0; i < TPS23881_MAX_CHANS; i++) { + if (!priv->port[i].exist) + continue; + + *notifs_mask |=3D BIT(i); + notifs[i] |=3D ETHTOOL_PSE_EVENT_OVER_TEMP; + } + } +} + +static void tps23881_irq_event_over_current(struct tps23881_priv *priv, + u16 reg_val, + unsigned long *notifs, + unsigned long *notifs_mask) +{ + u8 chans; + + chans =3D tps23881_it_export_chans_helper(reg_val, 0); + if (chans) + tps23881_set_notifs_helper(priv, chans, notifs, notifs_mask, + ETHTOOL_PSE_EVENT_OVER_CURRENT); +} + +static int tps23881_irq_event_handler(struct tps23881_priv *priv, u16 reg, + unsigned long *notifs, + unsigned long *notifs_mask) +{ + struct i2c_client *client =3D priv->client; + int ret; + + /* The Supply event bit is repeated twice so we only need to read + * the one from the first byte. + */ + if (reg & TPS23881_REG_IT_SUPF) { + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_SUPF_EVENT); + if (ret < 0) + return ret; + tps23881_irq_event_over_temp(priv, ret, notifs, notifs_mask); + } + + if (reg & (TPS23881_REG_IT_IFAULT | TPS23881_REG_IT_IFAULT << 8)) { + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_FAULT); + if (ret < 0) + return ret; + tps23881_irq_event_over_current(priv, ret, notifs, notifs_mask); + } + + return 0; +} + +static int tps23881_irq_handler(int irq, struct pse_controller_dev *pcdev, + unsigned long *notifs, + unsigned long *notifs_mask) +{ + struct tps23881_priv *priv =3D to_tps23881_priv(pcdev); + struct i2c_client *client =3D priv->client; + int ret, it_mask; + + /* Get interruption mask */ + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_IT_MASK); + if (ret < 0) + return ret; + it_mask =3D ret; + + /* Read interrupt register until it frees the interruption pin. */ + while (true) { + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_IT); + if (ret < 0) + return ret; + + /* No more relevant interruption */ + if (!(ret & it_mask)) + return 0; + + ret =3D tps23881_irq_event_handler(priv, (u16)ret, notifs, + notifs_mask); + if (ret) + return ret; + } + return 0; +} + +static int tps23881_setup_irq(struct tps23881_priv *priv, int irq) +{ + struct i2c_client *client =3D priv->client; + struct pse_irq_desc irq_desc =3D { + .name =3D "tps23881-irq", + .map_event =3D tps23881_irq_handler, + }; + int ret; + u16 val; + + val =3D TPS23881_REG_IT_IFAULT | TPS23881_REG_IT_SUPF; + val |=3D val << 8; + ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_IT_MASK, val); + if (ret) + return ret; + + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_GEN_MASK); + if (ret < 0) + return ret; + + val =3D (u16)(ret | TPS23881_REG_INTEN | TPS23881_REG_INTEN << 8); + ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_GEN_MASK, val); + if (ret < 0) + return ret; + + return devm_pse_irq_helper(&priv->pcdev, irq, 0, &irq_desc); +} + static int tps23881_i2c_probe(struct i2c_client *client) { struct device *dev =3D &client->dev; @@ -1178,6 +1348,12 @@ static int tps23881_i2c_probe(struct i2c_client *cli= ent) "failed to register PSE controller\n"); } =20 + if (client->irq) { + ret =3D tps23881_setup_irq(priv, client->irq); + if (ret) + return ret; + } + return ret; } =20 --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 780381DFDBF; Thu, 21 Nov 2024 14:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200247; cv=none; b=WPUBSPxJfyuXBagjGqKZuEWFZ0j5w+cYnWklxLAnM6wxPgFGCWIDfIo3D3qfsl/kaJHxR3qqV7uA0g9ydPcSimv5uDdS1Y0ntKiY8u8ir4fVoLQU7jGwmvGFbaAq3cSuvKNAbDOP8NSNShvg8jPylwE8I/thYXfbeuzpmcRbLLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200247; c=relaxed/simple; bh=yCdz15S5n9bwP+eHaxIWj26ftD8GPdXVftvaKhrORvA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EKqAfJSW2UbRN09lSNBRdhOqKRd3oTswFL3+eP2DPFcL/VI7YegcON72acbPaBKZvF1xTygGhImnYBhJzqEkAi6D+2ljUv9xMSu/5ruiahqsJRPOk8kQdZ8wRFl3MRcayE86/frak8bATc0dAJWRD4wtOeytmArfiEqTFweD1Hw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=MuOmbRms; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MuOmbRms" Received: by mail.gandi.net (Postfix) with ESMTPSA id 0A0C340003; Thu, 21 Nov 2024 14:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200244; 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=u04a+OXero5sCODR6WNJl3zCEzppF8sFRXUhrvCAEFA=; b=MuOmbRmsOjc4Ak4mjQG71ptircy1YwGmFjL+4izltDHAczySCSRRb44DGGapgcBlg1tkWo BlmiGzQK8lQrfiNG64vczgNWpVWK1Qba2x2Dsh4j0QbfU/iF3CdVFcXh1+0t+noPKAsRQJ HfCWA3aKyxfpjqzywprzrGN1ubt/GSxEaz5BCby5cNenkhGPyO/b8sPg7PO8EYYZnXDnlM ujet5rfH9zCFgRi7oOBnbRC07ddZbQ/hTB8daGGjadvhgwcqpkjlvRMQ01yo4NMYGpkhdY 9jHcsqztnF6aqp0pqJl2tk21TAc8+DQzsZEqnBnQaLhZ62YAqI1u+lydR3BLew== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:41 +0100 Subject: [PATCH RFC net-next v3 15/27] regulator: core: Resolve supply using of_node from regulator_config Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-15-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Previously, the regulator core resolved its supply only from the parent device or its children, ignoring the of_node specified in the regulator_config structure. This behavior causes issues in scenarios where multiple regulator devices are registered for components described as children of a controller, each with their own specific regulator supply. For instance, in a PSE controller with multiple PIs (Power Interfaces), each PI may have a distinct regulator supply. However, the regulator core would incorrectly use the PSE controller node or its first child to look up the regulator supply, rather than the node specified by the regulator_config->of_node for the PI. This update modifies the behavior to prioritize the of_node in regulator_config for resolving the supply. This ensures correct resolution of the power supply for each device. If no supply is found in the provided of_node, the core falls back to searching within the parent device as before. Signed-off-by: Kory Maincent --- It is weird that it wasn't seen before, maybe there was not any case were it can't find the supply_name from the parent device. Changes in v3: - New patch --- drivers/regulator/core.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 2948a7eca734..b49f751893b9 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1936,6 +1936,20 @@ static struct regulator_dev *regulator_lookup_by_nam= e(const char *name) return dev ? dev_to_rdev(dev) : NULL; } =20 +static struct regulator_dev *regulator_dt_lookup(struct device *dev, + const char *supply) +{ + struct regulator_dev *r =3D NULL; + + if (dev && dev->of_node) { + r =3D of_regulator_dev_lookup(dev, supply); + if (PTR_ERR(r) =3D=3D -ENODEV) + r =3D NULL; + } + + return r; +} + /** * regulator_dev_lookup - lookup a regulator device. * @dev: device for regulator "consumer". @@ -1960,16 +1974,9 @@ static struct regulator_dev *regulator_dev_lookup(st= ruct device *dev, regulator_supply_alias(&dev, &supply); =20 /* first do a dt based lookup */ - if (dev && dev->of_node) { - r =3D of_regulator_dev_lookup(dev, supply); - if (!IS_ERR(r)) - return r; - if (PTR_ERR(r) =3D=3D -EPROBE_DEFER) - return r; - - if (PTR_ERR(r) =3D=3D -ENODEV) - r =3D NULL; - } + r =3D regulator_dt_lookup(dev, supply); + if (r) + return r; =20 /* if not found, try doing it non-dt way */ if (dev) @@ -2002,8 +2009,8 @@ static struct regulator_dev *regulator_dev_lookup(str= uct device *dev, =20 static int regulator_resolve_supply(struct regulator_dev *rdev) { - struct regulator_dev *r; struct device *dev =3D rdev->dev.parent; + struct regulator_dev *r =3D NULL; struct ww_acquire_ctx ww_ctx; int ret =3D 0; =20 @@ -2015,7 +2022,18 @@ static int regulator_resolve_supply(struct regulator= _dev *rdev) if (rdev->supply) return 0; =20 - r =3D regulator_dev_lookup(dev, rdev->supply_name); + /* first do a dt based lookup on the node described in the virtual + * device. + */ + if (rdev->dev.of_node) + r =3D regulator_dt_lookup(&rdev->dev, rdev->supply_name); + + /* If regulator not found use usual search path in the parent + * device. + */ + if (!r) + r =3D regulator_dev_lookup(dev, rdev->supply_name); + if (IS_ERR(r)) { ret =3D PTR_ERR(r); =20 --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 290FD1E009B; Thu, 21 Nov 2024 14:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200251; cv=none; b=mp+TGU9PRwgBnGR2uv8pnZhKt+xbJa1uYUtcfyNSNbQaCaCkzRDKBPK3++WUZNCloTJsMs9sTrCShlhqszTmZG1W7CF3+k9mSjYDCgDAXz9ixmfuiV/zwfguEdhOlTxbupqOff8nRelCYglCgcEB26hrMl0/DnBeCjUATAWcE9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200251; c=relaxed/simple; bh=f8G5srbt+NdUisJx7UVblCJrh84QznUzTZYMEE2Brcc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d6POmhbqJluNrrK2YAYCmSM5et5Ut4v/ohlgedbKVvN0ZQxUIyaKBYW4MaGbzz9V1BOpDR7VsvEyOLDntd3atX2CthvlIvkSK3SEjsqGc+XJjHkjNMzTGJBq+XIAfxPEHMtedx6gqGRQdOYX4SFG+u0pP2cJnVmiLq7wxR8ghts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=VdPQ1Pzt; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="VdPQ1Pzt" Received: by mail.gandi.net (Postfix) with ESMTPSA id 555974000E; Thu, 21 Nov 2024 14:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200247; 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=oitQokj0j3eWr60sys9itIeEYJx4Zq/Y2Qd1sTJJauM=; b=VdPQ1Pztpctb4Q8xW4uto+ktk+o6pm6TDPEtbazVur+WfZehQ29MqwTUHgl/9FF1w4qvRY PVTvdesBEj+iyXdws50/wFe7071W6DAj22m4xxfhCYTr9zxPuK71gEeibrBjI52nZCWVzy V9k58St61T/CN3irGADmOjhvqPg8xKMZtlwXeG8z5vwTSHRwWolVHjgNzpJmrxNPyqMcic SOJKA+vGs+Lys8NVbgF5ISgqN0LrJyltZzttUj1XLEjoV1Sf0IFBVSqP8yaf7qAcs2hGg5 nYgwj65pmcd5uzrJm2a8+F0o7NLaZ1FJZ8aziMHKjv3XWIW673A8M5h4FldMnw== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:42 +0100 Subject: [PATCH RFC net-next v3 16/27] regulator: Add support for power budget description Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-16-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) In preparation for future support of PSE port priority and power management, we need the power budget value of the power supply. This addition allows the regulator to track the available power capacity, which will be essential for prioritizing ports when making power allocation decisions. Signed-off-by: Kory Maincent --- Changes in v3: - Add management of available power. Changes in v2: - new patch. --- drivers/regulator/core.c | 89 ++++++++++++++++++++++++++++++++++= ++++ drivers/regulator/of_regulator.c | 3 ++ include/linux/regulator/consumer.h | 21 +++++++++ include/linux/regulator/driver.h | 2 + include/linux/regulator/machine.h | 2 + 5 files changed, 117 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b49f751893b9..828b4dd10f68 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -917,6 +917,15 @@ static ssize_t bypass_show(struct device *dev, } static DEVICE_ATTR_RO(bypass); =20 +static ssize_t power_budget_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct regulator_dev *rdev =3D dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", rdev->pw_available); +} +static DEVICE_ATTR_RO(power_budget); + #define REGULATOR_ERROR_ATTR(name, bit) \ static ssize_t name##_show(struct device *dev, struct device_attribute *a= ttr, \ char *buf) \ @@ -1149,6 +1158,10 @@ static void print_constraints_debug(struct regulator= _dev *rdev) if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) count +=3D scnprintf(buf + count, len - count, "standby "); =20 + if (constraints->pw_budget) + count +=3D scnprintf(buf + count, len - count, "%d mW budget", + constraints->pw_budget); + if (!count) count =3D scnprintf(buf, len, "no parameters"); else @@ -1627,6 +1640,13 @@ static int set_machine_constraints(struct regulator_= dev *rdev) rdev->last_off =3D ktime_get(); } =20 + if (rdev->constraints->pw_budget) + rdev->pw_available =3D rdev->constraints->pw_budget; + else if (rdev->supply) + rdev->pw_available =3D regulator_get_power_budget(rdev->supply); + else + rdev->pw_available =3D INT_MAX; + print_constraints(rdev); return 0; } @@ -4641,6 +4661,71 @@ int regulator_get_current_limit(struct regulator *re= gulator) } EXPORT_SYMBOL_GPL(regulator_get_current_limit); =20 +/** + * regulator_get_power_budget - get regulator total power budget + * @regulator: regulator source + * + * Return: Power budget of the regulator in mW. + */ +int regulator_get_power_budget(struct regulator *regulator) +{ + return regulator->rdev->pw_available; +} +EXPORT_SYMBOL_GPL(regulator_get_power_budget); + +/** + * regulator_request_power_budget - request power budget on a regulator + * @regulator: regulator source + * @pw_req: Power requested + * + * Return: 0 on success or a negative error number on failure. + */ +int regulator_request_power_budget(struct regulator *regulator, + unsigned int pw_req) +{ + struct regulator_dev *rdev =3D regulator->rdev; + int ret =3D 0; + + regulator_lock(rdev); + if (rdev->supply) { + ret =3D regulator_request_power_budget(rdev->supply, pw_req); + if (ret < 0) + goto out; + } + if (pw_req > rdev->pw_available) { + rdev_dbg(rdev, "power requested %d mW out of budget %d mW", + pw_req, rdev->pw_available); + ret =3D -ERANGE; + goto out; + } + + rdev->pw_available -=3D pw_req; +out: + regulator_unlock(rdev); + return ret; +} +EXPORT_SYMBOL_GPL(regulator_request_power_budget); + +/** + * regulator_free_power_budget - free power budget on a regulator + * @regulator: regulator source + * @pw: Power to be released. + * + * Return: Power budget of the regulator in mW. + */ +void regulator_free_power_budget(struct regulator *regulator, + unsigned int pw) +{ + struct regulator_dev *rdev =3D regulator->rdev; + + regulator_lock(rdev); + if (rdev->supply) + regulator_free_power_budget(rdev->supply, pw); + rdev->pw_available +=3D pw; + regulator_unlock(rdev); +} +EXPORT_SYMBOL_GPL(regulator_free_power_budget); + /** * regulator_set_mode - set regulator operating mode * @regulator: regulator source @@ -5279,6 +5364,7 @@ static struct attribute *regulator_dev_attrs[] =3D { &dev_attr_suspend_standby_mode.attr, &dev_attr_suspend_mem_mode.attr, &dev_attr_suspend_disk_mode.attr, + &dev_attr_power_budget.attr, NULL }; =20 @@ -5360,6 +5446,9 @@ static umode_t regulator_attr_is_visible(struct kobje= ct *kobj, attr =3D=3D &dev_attr_suspend_disk_mode.attr) return ops->set_suspend_mode ? mode : 0; =20 + if (attr =3D=3D &dev_attr_power_budget.attr) + return rdev->pw_available !=3D INT_MAX ? mode : 0; + return mode; } =20 diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regula= tor.c index 3f490d81abc2..a8996e7597d4 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -125,6 +125,9 @@ static int of_get_regulation_constraints(struct device = *dev, if (constraints->min_uA !=3D constraints->max_uA) constraints->valid_ops_mask |=3D REGULATOR_CHANGE_CURRENT; =20 + if (!of_property_read_u32(np, "regulator-power-budget", &pval)) + constraints->pw_budget =3D pval; + constraints->boot_on =3D of_property_read_bool(np, "regulator-boot-on"); constraints->always_on =3D of_property_read_bool(np, "regulator-always-on= "); if (!constraints->always_on) /* status change should be possible. */ diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/c= onsumer.h index b9ce521910a0..8f0a0e98d7ee 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -235,6 +235,11 @@ int regulator_sync_voltage(struct regulator *regulator= ); int regulator_set_current_limit(struct regulator *regulator, int min_uA, int max_uA); int regulator_get_current_limit(struct regulator *regulator); +int regulator_get_power_budget(struct regulator *regulator); +int regulator_request_power_budget(struct regulator *regulator, + unsigned int pw_req); +void regulator_free_power_budget(struct regulator *regulator, + unsigned int pw); =20 int regulator_set_mode(struct regulator *regulator, unsigned int mode); unsigned int regulator_get_mode(struct regulator *regulator); @@ -534,6 +539,22 @@ static inline int regulator_get_current_limit(struct r= egulator *regulator) return 0; } =20 +static inline int regulator_get_power_budget(struct regulator *regulator) +{ + return INT_MAX; +} + +static inline int regulator_request_power_budget(struct regulator *regulat= or, + unsigned int pw_req) +{ + return -EOPNOTSUPP; +} + +static inline void regulator_free_power_budget(struct regulator *regulator, + unsigned int pw) +{ +} + static inline int regulator_set_mode(struct regulator *regulator, unsigned int mode) { diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/dri= ver.h index f230a472ccd3..e006d0c19542 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -649,6 +649,8 @@ struct regulator_dev { int cached_err; bool use_cached_err; spinlock_t err_lock; + + int pw_available; }; =20 /* diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/ma= chine.h index 0cd76d264727..3304cf8773b7 100644 --- a/include/linux/regulator/machine.h +++ b/include/linux/regulator/machine.h @@ -113,6 +113,7 @@ struct notification_limit { * @min_uA: Smallest current consumers may set. * @max_uA: Largest current consumers may set. * @ilim_uA: Maximum input current. + * @pw_budget: Power budget for the regulator in mW. * @system_load: Load that isn't captured by any consumer requests. * * @over_curr_limits: Limits for acting on over current. @@ -185,6 +186,7 @@ struct regulation_constraints { int max_uA; int ilim_uA; =20 + int pw_budget; int system_load; =20 /* used for coupled regulators */ --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61EC21E00B5; Thu, 21 Nov 2024 14:44:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200253; cv=none; b=oiHWU5eNl4wLIyOYqNu/YcFUjZTQKfXojYHoppFKo2+B62KWeSM2p+hae//4Vg2+IEqGuglH+LOdIuWR3rhP0l5uulMjAKD4tesDqp1DS9JiplH60PVinB+Sa2ZyifqWeeKKiDmiMuQC0z6lT2JRY76vKmkkBlvQT3CbRWU6cFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200253; c=relaxed/simple; bh=PmcM6Eq4mUZeQnTjPYQUDIKawcn+VUJWOtS6yiaro5w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hRs0zHUCqxWcWyku2CpZQzCTanMHBt8zQSOKx5CyvD0MW1t1LNdlphja06LuTkhc1NBxMbhLzrsZqiSzjmMOanveouD9L8gMPsOk0KdoKmtgHfLXD3uCqzz9sAKQotCXecP18yel4s4rU7ZtSA4MQNhuKvHHFQK4OdCAYExJIBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=kiHmy+S0; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="kiHmy+S0" Received: by mail.gandi.net (Postfix) with ESMTPSA id E960C40003; Thu, 21 Nov 2024 14:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200250; 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=eH94oL4C+uAtHpUg+7hvQnupTMOvyV/l+52BXsH7jwA=; b=kiHmy+S0eG7bPmaCZkcWGHxdMkmfD7q8lFrQp+Ma78J4hUymBplOcFA/xT7MOEE8gWj4ab Gf1YiPXTju442tbUAss8RHd3wSIiq8EUJMF/JfaPM1Mlk0mr0USlrUq8CdrcAP4tH5e9O4 VeDvkRNua2Qj/AHNuJ3cIYkdkijHJ/x5tsSHZpmWtaQfjLwo1VACahKPe00WfP1UX4V1sr YqH64qz95EZ6C91ziRqxpaa/9wDAJXJeXAC/wX6RCtLcHWRzln7v3j+9kv+F+/HywX7ILp kWeRavdtc6eFuDmc61LaBTiIxmUH1mkbPO2r5iPDXRew5UMMyF8gtdLuYueUlQ== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:43 +0100 Subject: [PATCH RFC net-next v3 17/27] regulator: dt-bindings: Add regulator-power-budget property Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-17-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Introduce a new property to describe the power budget of the regulator. This property will allow power management support for regulator consumers like PSE controllers, enabling them to make decisions based on the available power capacity. Signed-off-by: Kory Maincent --- Changes in v2: - new patch. --- Documentation/devicetree/bindings/regulator/regulator.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/regulator/regulator.yaml b/D= ocumentation/devicetree/bindings/regulator/regulator.yaml index 1ef380d1515e..52a410b51769 100644 --- a/Documentation/devicetree/bindings/regulator/regulator.yaml +++ b/Documentation/devicetree/bindings/regulator/regulator.yaml @@ -34,6 +34,9 @@ properties: regulator-input-current-limit-microamp: description: maximum input current regulator allows =20 + regulator-power-budget: + description: power budget of the regulator in mW + regulator-always-on: description: boolean, regulator should never be disabled type: boolean --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77D131E04A7; Thu, 21 Nov 2024 14:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200255; cv=none; b=K61MEli0Hqipcbg2fsPQuMbDjL9ljwc85Oy9nBRKGiKh3J4F3HhKgKbT+62rq2lSLaAB8gt1S9V1xPzc5KWORElPX9Bw/O6ANH8GORNnaEGsmiDPgYB1zMXnNYZfQDskjINF2abhpd5mDokDIVNItbq//Ml0I0QCfyKVv1cFFGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200255; c=relaxed/simple; bh=WH6zA1+MIUfZhwa/PH2qa3dZoRc301GBKoubmQQg7Uw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SxSpWBJPsyzisFSgRQwrCqPWuiJsOlCwHlli1KXkJULNGfJtQLBjZgHja43teJfzXiex9QyKze4kyAbua6EvTx0ff0KSzDjWoHIcB5EjAKEnAd0Q6WvnMMxpO1JplB+h1DQH3KXgsKEObkbJMZrLbn6dhy7w0DNa2OUdj1mSpl8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Qk45GfvQ; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Qk45GfvQ" Received: by mail.gandi.net (Postfix) with ESMTPSA id 2FB794000C; Thu, 21 Nov 2024 14:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200252; 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=yETHLHBxm1BUiuBXz4EFHD6m1F9pqw5fe/ucOLdBnZ0=; b=Qk45GfvQQxggahXsYwMi96xLzBOJJ34wh0tze2YJ8zWbXO2oI6Hjesp9Ao2eYQKZBbzUUg JrYC2g1g2oFUn4ld4OIRR4cWqiYkSkkgqPSBr0P/jE4syG0wLypFkgZp6LRCanfN95UOkY Hsdm0KlzCVqFNI1xcfsvWPGGkYyJvThikxUiI1vh1yb3r3ZZPM6KuFzxyVUq3Cnaidstm5 IXC+zE4qXC/M4rHGpot9tNefNpwXZR9tR+4cwRtvMW9yYe6EQIwvA7kVFSqymNMD3XFNwa PvegJ9taHJixHjoguNCYLWiSjFq5DbcoCFvj5bUWhb+wJLiRa2v1NwG5jjaHTg== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:44 +0100 Subject: [PATCH RFC net-next v3 18/27] net: pse-pd: Fix missing PI of_node description Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-18-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) The PI of_node was not assigned in the regulator_config structure, leading to failures in resolving the correct supply when different power supplies are assigned to multiple PIs of a PSE controller. This fix ensures that the of_node is properly set in the regulator_config, allowing accurate supply resolution for each PI. Signed-off-by: Kory Maincent --- Changes in v3: - New patch --- drivers/net/pse-pd/pse_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index 8b5a9e7fd9c5..d4cf5523194d 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -419,6 +419,7 @@ devm_pse_pi_regulator_register(struct pse_controller_de= v *pcdev, rconfig.dev =3D pcdev->dev; rconfig.driver_data =3D pcdev; rconfig.init_data =3D rinit_data; + rconfig.of_node =3D pcdev->pi[id].np; =20 rdev =3D devm_regulator_register(pcdev->dev, rdesc, &rconfig); if (IS_ERR(rdev)) { --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D55F1E0DB6; Thu, 21 Nov 2024 14:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200259; cv=none; b=LO1H2tXC6DxyF44JgdFH5KVNeuv5bMkC5TBXbiqEhnj7mtRTSkpbBDAJ9VjRxXvgaAJrvPm+Wid/L3ws/ruatberYIWKUFPM1wphJDL8PPduC7rx4MtsRUfd8GN2+YBCRUvka5Yx8Kh0lleQ9lWqBvYDvQRmRmXyo/U0X7WiD/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200259; c=relaxed/simple; bh=azFcBWJegH1Stk6Ga1l7n8qmM3wLmOuNlbKSXEZ9MXc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BD469WxIYu+4DdqN3udxsICDQocBWeVnSgGFfTSW1LoyBmZGiglPLicKVEnp0P+CH93Q0wSkUbP58gYdxH9gbormFc1QLGb7Dw4zUDnQQ4LtZBz74faqzRUokMIT+PpKO6DUTksozT41QQXWMqcOqkbjI0MrTpGVHjh8F2g3To8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=cxH1G9QS; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="cxH1G9QS" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4633B40002; Thu, 21 Nov 2024 14:44:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200254; 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=bcgJuKLJismZ9vaz8zGQ8LaYUmd4CadaQ0PkC7ZGheY=; b=cxH1G9QSkI3fHw+hVkOTh19zEhmIjiqE2yr3gz/qYrdT+v8VQ27xFHeaxrsKjJVDQcQMBo eRzO4Gf77LhXtAWqLVpw7ppelzx2pV9YCDdzCXwb2hiciQND94uPeynG/IY5yZpSp8xjoV EWhwxpV2xo17aacnSLAjvo5OWIVYPRF7Iq07GtGZWLr0kXNa5FYm6zyUFBrf6j8elPhbRp 5kwTDP+ERhgvXX//BkdpqS0GiVmWmC4GGZ8Ue1/dQcul92YrNaQypxOjoDnVwOM7MDSuNg 8OY86xlqJGOvGjIjFcqaEsfRyzVZfyhCsjj5Zu3QN8TtkZxS2ANNEtNo2AMRPg== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:45 +0100 Subject: [PATCH RFC net-next v3 19/27] net: pse-pd: Add support for PSE power domains Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-19-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Introduce PSE power domain support as groundwork for upcoming port priority features. Multiple PSE PIs can now be grouped under a single PSE power domain, enabling future enhancements like defining available power budgets, port priority modes, and disconnection policies. This setup will allow the system to assess whether activating a port would exceed the available power budget, preventing over-budget states proactively. Signed-off-by: Kory Maincent --- Changes in v3: - Remove pw_budget variable. Changes in v2: - new patch. --- drivers/net/pse-pd/pse_core.c | 95 +++++++++++++++++++++++++++++++++++++++= ++++ include/linux/pse-pd/pse.h | 2 + 2 files changed, 97 insertions(+) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index d4cf5523194d..8b9ce8c6ecef 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -15,6 +15,7 @@ static DEFINE_MUTEX(pse_list_mutex); static LIST_HEAD(pse_controller_list); static DEFINE_IDA(pse_ida); +static DEFINE_XARRAY_ALLOC(pse_pw_d_map); =20 /** * struct pse_control - a PSE control @@ -35,6 +36,16 @@ struct pse_control { struct phy_device *attached_phydev; }; =20 +/** + * struct pse_power_domain - a PSE power domain + * @id: ID of the power domain + * @supply: Power supply the Power Domain + */ +struct pse_power_domain { + int id; + struct regulator *supply; +}; + static int of_load_single_pse_pi_pairset(struct device_node *node, struct pse_pi *pi, int pairset_num) @@ -433,6 +444,84 @@ devm_pse_pi_regulator_register(struct pse_controller_d= ev *pcdev, return 0; } =20 +static void pse_flush_pw_ds(struct pse_controller_dev *pcdev) +{ + struct pse_power_domain *pw_d; + int i; + + for (i =3D 0; i < pcdev->nr_lines; i++) { + pw_d =3D xa_load(&pse_pw_d_map, pcdev->pi[i].pw_d->id); + if (pw_d) { + regulator_put(pw_d->supply); + xa_erase(&pse_pw_d_map, pw_d->id); + } + } +} + +static struct pse_power_domain *devm_pse_alloc_pw_d(struct device *dev) +{ + struct pse_power_domain *pw_d; + int index, ret; + + pw_d =3D devm_kzalloc(dev, sizeof(*pw_d), GFP_KERNEL); + if (!pw_d) + return ERR_PTR(-ENOMEM); + + ret =3D xa_alloc(&pse_pw_d_map, &index, pw_d, XA_LIMIT(1, INT_MAX), GFP_K= ERNEL); + if (ret) + return ERR_PTR(ret); + + pw_d->id =3D index; + return pw_d; +} + +static int pse_register_pw_ds(struct pse_controller_dev *pcdev) +{ + int i; + + for (i =3D 0; i < pcdev->nr_lines; i++) { + struct regulator_dev *rdev =3D pcdev->pi[i].rdev; + struct pse_power_domain *pw_d; + struct regulator *supply; + bool present =3D false; + unsigned long index; + + /* No regulator or regulator parent supply registered. + * We need a regulator parent to register a PSE power domain + */ + if (!rdev || !rdev->supply) + continue; + + xa_for_each(&pse_pw_d_map, index, pw_d) { + /* Power supply already registered as a PSE power + * domain. + */ + if (regulator_is_equal(pw_d->supply, rdev->supply)) { + present =3D true; + pcdev->pi[i].pw_d =3D pw_d; + break; + } + } + if (present) + continue; + + pw_d =3D devm_pse_alloc_pw_d(pcdev->dev); + if (IS_ERR_OR_NULL(pw_d)) + return PTR_ERR(pw_d); + + supply =3D regulator_get(&rdev->dev, rdev->supply_name); + if (IS_ERR(supply)) { + xa_erase(&pse_pw_d_map, pw_d->id); + return PTR_ERR(supply); + } + + pw_d->supply =3D supply; + pcdev->pi[i].pw_d =3D pw_d; + } + + return 0; +} + /** * pse_controller_register - register a PSE controller device * @pcdev: a pointer to the initialized PSE controller device @@ -491,6 +580,11 @@ int pse_controller_register(struct pse_controller_dev = *pcdev) goto free_pse_ida; } =20 + ret =3D pse_register_pw_ds(pcdev); + + if (ret) + goto free_pse_ida; + mutex_lock(&pse_list_mutex); list_add(&pcdev->list, &pse_controller_list); mutex_unlock(&pse_list_mutex); @@ -509,6 +603,7 @@ EXPORT_SYMBOL_GPL(pse_controller_register); */ void pse_controller_unregister(struct pse_controller_dev *pcdev) { + pse_flush_pw_ds(pcdev); pse_release_pis(pcdev); ida_free(&pse_ida, pcdev->id); mutex_lock(&pse_list_mutex); diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index be6e967f9ac3..9d06eb9ca663 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -140,12 +140,14 @@ struct pse_pi_pairset { * @np: device node pointer of the PSE PI node * @rdev: regulator represented by the PSE PI * @admin_state_enabled: PI enabled state + * @pw_d: Power domain of the PSE PI */ struct pse_pi { struct pse_pi_pairset pairset[2]; struct device_node *np; struct regulator_dev *rdev; bool admin_state_enabled; + struct pse_power_domain *pw_d; }; =20 /** --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 487061E0DF9; Thu, 21 Nov 2024 14:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200260; cv=none; b=Eunu4nv63f0t9h5NVtIzMJC4/+C4hqAYBfQ+aLt/gbjNf2mXZLwR9JGEPzcxmIYAQIrIakKfUOZG0AGUtuCvjr3/Ndw7tP6/wDSTgv+cypL1Udl1Wkw2dCoyAI5tCxzkUbjklGbjK3VudomSaqTmzesGTkbeGiGg0pq4upKGzxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200260; c=relaxed/simple; bh=OqzDm7Z/gQBlx9q8tSj+GJD9uMx9aZ5dguVYSY8A9lE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Tfsjrsgv9bWo6ko1DDVi7lYBobgA7UKCsqCMLADpDt4X2TVboVkN6OLq6dnG0wJPGiZ+/9ChnKHXRnmtW0OzgEh9Jp4HdJtWZjYeBs9ynRr6ZHTyPlh+F4DcUv8DTzhbsjsmbsMl9ADK6c86reIXV4ygDb9fGnDmxJ51bHD+jAw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=iiP9yTk5; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="iiP9yTk5" Received: by mail.gandi.net (Postfix) with ESMTPSA id 9A3E740008; Thu, 21 Nov 2024 14:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200256; 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=Bp11jeKFQf+n77xKj8jA9tjL6fptB01Kk8DXFAMTdXw=; b=iiP9yTk5YpbTLBvUN7p3G7uT+izT2eY3XFm2arhqYsB4ZsrrJ0iJysm+UbWLMNL8spNZBB zLxshzKNFVvfSXsgyPIHmr5Lwi80ZvDBYY1UJ15yCh+5SgA7lbLtmh9SD0v0hpzX2FBaRl z+qBXeWq7ZTjvoQXyhn6WXp+oyAcjn/dVQ4Vv/bACN2x2I4TWXybybWmnUIZcr81OJHqqS 2lc+ZTduHAptqRqT6BQ1FARPZLH7Qgigfwoxkua/zI7rS7KMjXOWJPV+IUX+z88Swym75+ qzQPYT/QdiBOqzIWkuzxgEaJE8rrWOoQUPjdxPRf/NAzZjiFfhd/lj4Q/CwV/A== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:46 +0100 Subject: [PATCH RFC net-next v3 20/27] net: ethtool: Add support for new power domains index description Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-20-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Report the index of the newly introduced PSE power domain to the user, enabling improved management of the power budget for PSE devices. Signed-off-by: Kory Maincent --- Changes in v3: - Add support power domain id =3D 0 in ethtool. Changes in v2: - new patch. --- Documentation/networking/ethtool-netlink.rst | 4 ++++ drivers/net/pse-pd/pse_core.c | 3 +++ include/linux/pse-pd/pse.h | 2 ++ include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/pse-pd.c | 7 +++++++ 5 files changed, 17 insertions(+) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/n= etworking/ethtool-netlink.rst index bd7173d1fa4d..3573543ae5ad 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -1767,6 +1767,7 @@ Kernel response contents: ``ETHTOOL_A_C33_PSE_PW_LIMIT_RANGES`` nested Supported power limit configuration ranges. ``ETHTOOL_A_PSE_ID`` u32 Index of the PSE + ``ETHTOOL_A_PSE_PW_D_ID`` u32 Index of the PSE pow= er domain =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D =20 When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_STATE`` attribute identi= fies @@ -1843,6 +1844,9 @@ equal. The ``ETHTOOL_A_PSE_ID`` attribute identifies the index of the PSE controller. =20 +The ``ETHTOOL_A_PSE_PW_D_ID`` attribute identifies the index of PSE power +domain. + PSE_SET =3D=3D=3D=3D=3D=3D=3D =20 diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index 8b9ce8c6ecef..ff0ffbccf139 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -980,6 +980,9 @@ static int _pse_ethtool_get_status(struct pse_controlle= r_dev *pcdev, } =20 status->pse_id =3D pcdev->id; + if (pcdev->pi[id].pw_d) + status->pw_d_id =3D pcdev->pi[id].pw_d->id; + return ops->ethtool_get_status(pcdev, id, extack, status); } =20 diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index 9d06eb9ca663..bdf3e8c468fc 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -42,6 +42,7 @@ struct pse_control_config { * struct pse_control_status - PSE control/channel status. * * @pse_id: index number of the PSE. Set by PSE core. + * @pw_d_id: PSE power domain index. Set by PSE core. * @podl_admin_state: operational state of the PoDL PSE * functions. IEEE 802.3-2018 30.15.1.1.2 aPoDLPSEAdminState * @podl_pw_status: power detection status of the PoDL PSE. @@ -64,6 +65,7 @@ struct pse_control_config { */ struct pse_control_status { u32 pse_id; + u32 pw_d_id; enum ethtool_podl_pse_admin_state podl_admin_state; enum ethtool_podl_pse_pw_d_status podl_pw_status; enum ethtool_c33_pse_admin_state c33_admin_state; diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/etht= ool_netlink.h index 91c1bd9349b0..088ad7b956fb 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -972,6 +972,7 @@ enum { ETHTOOL_A_C33_PSE_AVAIL_PW_LIMIT, /* u32 */ ETHTOOL_A_C33_PSE_PW_LIMIT_RANGES, /* nest - _C33_PSE_PW_LIMIT_* */ ETHTOOL_A_PSE_ID, /* u32 */ + ETHTOOL_A_PSE_PW_D_ID, /* u32 */ =20 /* add new constants above here */ __ETHTOOL_A_PSE_CNT, diff --git a/net/ethtool/pse-pd.c b/net/ethtool/pse-pd.c index 19ab6bd35ad4..d67803b67e76 100644 --- a/net/ethtool/pse-pd.c +++ b/net/ethtool/pse-pd.c @@ -84,6 +84,8 @@ static int pse_reply_size(const struct ethnl_req_info *re= q_base, int len =3D 0; =20 len +=3D nla_total_size(sizeof(u32)); /* _PSE_ID */ + if (st->pw_d_id > 0) + len +=3D nla_total_size(sizeof(u32)); /* _PSE_PW_D_ID */ if (st->podl_admin_state > 0) len +=3D nla_total_size(sizeof(u32)); /* _PODL_PSE_ADMIN_STATE */ if (st->podl_pw_status > 0) @@ -152,6 +154,11 @@ static int pse_fill_reply(struct sk_buff *skb, if (nla_put_u32(skb, ETHTOOL_A_PSE_ID, st->pse_id)) return -EMSGSIZE; =20 + if (st->pw_d_id > 0 && + nla_put_u32(skb, ETHTOOL_A_PSE_PW_D_ID, + st->pw_d_id)) + return -EMSGSIZE; + if (st->podl_admin_state > 0 && nla_put_u32(skb, ETHTOOL_A_PODL_PSE_ADMIN_STATE, st->podl_admin_state)) --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 745921E1028; Thu, 21 Nov 2024 14:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200263; cv=none; b=EM9qhv1afh80fUSs3P/4E2av8zBhbpP9mOATXR5E2NLwVTxI++Lrfs9aegDio3sbnyYqhkpxuZYWdDPDs2ehh32LZvqHu+C0GouEhw2agUs7ZkWKvwYHNPVfx4WBOlcemmyX/5QOts9BEqcjC1BGWUB8xVR1YSD1GE2ccXpcPg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200263; c=relaxed/simple; bh=jZ+p6SWY/sur9QXkhHK7CuEAnJCoxKWsnZyEYwFMLjU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PPmni3izBmyf48YM+q5WOYFz4M7MFjwmoiZa43wCf6bAl4SClenxIQRPKB14QMoCulaLCpWvBUUc/8qqIk+sxjIJ3BYe7gw1wBw2AI7OkoqsBG/eIokWA4aqEenFq8BhP5E/si98LZ6U8xknNFunEiEPFCpPrVAipgKCB7yhSRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=iOdPRo8Y; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="iOdPRo8Y" Received: by mail.gandi.net (Postfix) with ESMTPSA id D844840009; Thu, 21 Nov 2024 14:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200259; 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=bkyFhoREI2ODCCiYHamIwNZ5qVV9BPNhyEjx2uNNK/s=; b=iOdPRo8Y13nZ7Dql8Ncf+8UzE1MrrY+tgWkAs/aounqBgQJtz/m2tnKouMK+1cpm4ThTx1 4XUDGFib8erp2rFaIZRWIFCCC/xlOubuDLpyRPr6Qb2B+WdTKarSGHQI6tF5m2tUiSTUju zTpbLHR0D/+VgSSQZIPyJ6uqRYyLQDrf/LM3G0zopcdFp8BEd2RWM1lcA9MH5Kuqe9LLeR WiGk0lxfVQdytCJh92Cl9Y7hoNFlPM8JuYLVxwcaXuktHDlcb1mNYJTkNM9KYTdLwvyoR6 6I+j3m//pJW2j3ApyS93851q1wc+OTpIe+FR/AJP4iybuZSCoGtd4UW+gEymzg== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:47 +0100 Subject: [PATCH RFC net-next v3 21/27] net: pse-pd: Add support for getting and setting port priority Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-21-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) This patch introduces the ability to configure the PSE PI port priority. Port priority is utilized by PSE controllers to determine which ports to turn off first in scenarios such as power budget exceedance. The pis_prio_max value is used to define the maximum priority level supported by the controller. Both the current priority and the maximum priority are exposed to the user through the pse_ethtool_get_status call. This patch add support for two mode of port priority modes. 1. Static Method: This method involves distributing power based on PD classification. It=E2=80=99s straightforward and stable, the PSE core keeping track of t= he budget and subtracting the power requested by each PD=E2=80=99s class. Advantages: Every PD gets its promised power at any time, which guarantees reliability. Disadvantages: PD classification steps are large, meaning devices request much more power than they actually need. As a result, the power supply may only operate at, say, 50% capacity, which is inefficient and wastes money. Priority max value is matching the number of PSE PIs within the PSE. 2. Dynamic Method: To address the inefficiencies of the static method, vendors like Microchip have introduced dynamic power budgeting, as seen in the PD692x0 firmware. This method monitors the current consumption per port and subtracts it from the available power budget. When the budget is exceeded, lower-priority ports are shut down. Advantages: This method optimizes resource utilization, saving costs. Disadvantages: Low-priority devices may experience instability. Priority max value is set by the PSE controller driver. Signed-off-by: Kory Maincent --- Change in v3: - Add disconnection policy. - Add management of disabled port priority in the interrupt handler. - Move port prio mode in the power domain instead of the PSE. Change in v2: - Rethink the port priority support. --- drivers/net/pse-pd/pse_core.c | 550 ++++++++++++++++++++++++++++++++++++++= +++- include/linux/pse-pd/pse.h | 63 +++++ include/uapi/linux/ethtool.h | 73 ++++++ 3 files changed, 676 insertions(+), 10 deletions(-) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index ff0ffbccf139..f15a693692ae 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -40,10 +40,17 @@ struct pse_control { * struct pse_power_domain - a PSE power domain * @id: ID of the power domain * @supply: Power supply the Power Domain + * @port_prio_mode: Current port priority mode of the power domain + * @discon_pol: Current disonnection policy of the power domain + * @pi_lrc_id: ID of the last recently connected PI. -1 if none. Relevant + * for static port priority mode. */ struct pse_power_domain { int id; struct regulator *supply; + u32 port_prio_mode; + u32 discon_pol; + int pi_lrc_id; }; =20 static int of_load_single_pse_pi_pairset(struct device_node *node, @@ -222,6 +229,33 @@ static int of_load_pse_pis(struct pse_controller_dev *= pcdev) return ret; } =20 +static void pse_pi_deallocate_pw_budget(struct pse_pi *pi) +{ + if (!pi->pw_d) + return; + + regulator_free_power_budget(pi->pw_d->supply, pi->pw_allocated); +} + +/* Helper returning true if the power control is managed from the software + * in the interrupt handler + */ +static bool pse_pw_d_is_sw_pw_control(struct pse_controller_dev *pcdev, + struct pse_power_domain *pw_d) +{ + if (!pw_d) + return false; + + if (pw_d->port_prio_mode & ETHTOOL_PSE_PORT_PRIO_STATIC) + return true; + if (pw_d->port_prio_mode =3D=3D ETHTOOL_PSE_PORT_PRIO_DISABLED && + pcdev->ops->pi_enable && pcdev->ops->pi_get_pw_req && + pcdev->irq) + return true; + + return false; +} + static int pse_pi_is_enabled(struct regulator_dev *rdev) { struct pse_controller_dev *pcdev =3D rdev_get_drvdata(rdev); @@ -234,6 +268,13 @@ static int pse_pi_is_enabled(struct regulator_dev *rde= v) =20 id =3D rdev_get_id(rdev); mutex_lock(&pcdev->lock); + if (pse_pw_d_is_sw_pw_control(pcdev, pcdev->pi[id].pw_d)) { + ret =3D pcdev->pi[id].isr_enabled && + pcdev->pi[id].admin_state_enabled; + mutex_unlock(&pcdev->lock); + return ret; + } + ret =3D ops->pi_is_enabled(pcdev, id); mutex_unlock(&pcdev->lock); =20 @@ -244,7 +285,7 @@ static int pse_pi_enable(struct regulator_dev *rdev) { struct pse_controller_dev *pcdev =3D rdev_get_drvdata(rdev); const struct pse_controller_ops *ops; - int id, ret; + int id, ret =3D 0; =20 ops =3D pcdev->ops; if (!ops->pi_enable) @@ -252,6 +293,21 @@ static int pse_pi_enable(struct regulator_dev *rdev) =20 id =3D rdev_get_id(rdev); mutex_lock(&pcdev->lock); + if (pse_pw_d_is_sw_pw_control(pcdev, pcdev->pi[id].pw_d)) { + /* Manage enabled status by software. + * Real enable process will happen if a port is connected. + */ + if (pcdev->pi[id].isr_enabled) { + ret =3D ops->pi_enable(pcdev, id); + if (!ret) + pcdev->pi[id].admin_state_enabled =3D 1; + } else { + pcdev->pi[id].admin_state_enabled =3D 1; + } + mutex_unlock(&pcdev->lock); + return ret; + } + ret =3D ops->pi_enable(pcdev, id); if (!ret) pcdev->pi[id].admin_state_enabled =3D 1; @@ -264,6 +320,7 @@ static int pse_pi_disable(struct regulator_dev *rdev) { struct pse_controller_dev *pcdev =3D rdev_get_drvdata(rdev); const struct pse_controller_ops *ops; + struct pse_pi *pi; int id, ret; =20 ops =3D pcdev->ops; @@ -272,9 +329,16 @@ static int pse_pi_disable(struct regulator_dev *rdev) =20 id =3D rdev_get_id(rdev); mutex_lock(&pcdev->lock); + + pi =3D &pcdev->pi[id]; ret =3D ops->pi_disable(pcdev, id); - if (!ret) - pcdev->pi[id].admin_state_enabled =3D 0; + if (!ret) { + pse_pi_deallocate_pw_budget(pi); + pi->admin_state_enabled =3D 0; + pi->isr_enabled =3D 0; + if (pi->pw_d && pi->pw_d->pi_lrc_id =3D=3D id) + pi->pw_d->pi_lrc_id =3D -1; + } mutex_unlock(&pcdev->lock); =20 return ret; @@ -516,6 +580,8 @@ static int pse_register_pw_ds(struct pse_controller_dev= *pcdev) } =20 pw_d->supply =3D supply; + pw_d->port_prio_mode =3D ETHTOOL_PSE_PORT_PRIO_DISABLED; + pw_d->discon_pol =3D ETHTOOL_PSE_DISCON_ROUND_ROBIN_IDX_LOWEST_FIRST; pcdev->pi[i].pw_d =3D pw_d; } =20 @@ -539,6 +605,7 @@ int pse_controller_register(struct pse_controller_dev *= pcdev) if (ret < 0) return ret; pcdev->id =3D ret; + pcdev->port_prio_supp_modes |=3D ETHTOOL_PSE_PORT_PRIO_DISABLED; =20 if (!pcdev->nr_lines) pcdev->nr_lines =3D 1; @@ -683,10 +750,279 @@ pse_control_find_phy_by_id(struct pse_controller_dev= *pcdev, int id) } } mutex_unlock(&pse_list_mutex); - return NULL; } =20 +static int pse_pi_disable_isr(struct pse_controller_dev *pcdev, int id, + struct netlink_ext_ack *extack) +{ + const struct pse_controller_ops *ops =3D pcdev->ops; + struct pse_pi *pi =3D &pcdev->pi[id]; + int ret; + + if (!ops->pi_disable) { + NL_SET_ERR_MSG(extack, "PSE does not support disable control"); + return -EOPNOTSUPP; + } + + if (!pi->isr_enabled) + return 0; + + if (pi->admin_state_enabled) { + ret =3D ops->pi_disable(pcdev, id); + if (ret) { + NL_SET_ERR_MSG_FMT(extack, + "PI %d: disable error %d", + id, ret); + return ret; + } + } + + pse_pi_deallocate_pw_budget(pi); + pi->isr_enabled =3D 0; + if (pi->pw_d && pi->pw_d->pi_lrc_id =3D=3D id) + pi->pw_d->pi_lrc_id =3D -1; + + return 0; +} + +static int _pse_disable_pi_pol(struct pse_controller_dev *pcdev, int id) +{ + unsigned long notifs =3D ETHTOOL_C33_PSE_EVENT_DISCONNECTION; + struct netlink_ext_ack extack =3D {}; + struct phy_device *phydev; + int ret; + + dev_dbg(pcdev->dev, "Disabling PI %d to free power budget\n", id); + + NL_SET_ERR_MSG_FMT(&extack, + "Disabling PI %d to free power budget", id); + + ret =3D pse_pi_disable_isr(pcdev, id, &extack); + if (ret) + notifs |=3D ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR; + phydev =3D pse_control_find_phy_by_id(pcdev, id); + if (phydev) + ethnl_pse_send_ntf(phydev, notifs, &extack); + + return ret; +} + +static int pse_disable_pi_prio_lrc(struct pse_controller_dev *pcdev, + struct pse_power_domain *pw_d, + int prio) +{ + int lrc_id =3D pw_d->pi_lrc_id; + int ret; + + if (lrc_id < 0) + return 0; + + if (pcdev->pi[lrc_id].prio !=3D prio) + return 0; + + ret =3D _pse_disable_pi_pol(pcdev, lrc_id); + if (ret) + return ret; + + /* PI disabled */ + return 1; +} + +static int pse_disable_pi_prio_round_rob_low(struct pse_controller_dev *pc= dev, + struct pse_power_domain *pw_d, + int prio) +{ + int i; + + for (i =3D 0; i < pcdev->nr_lines; i++) { + int ret; + + if (pcdev->pi[i].prio !=3D prio || + pcdev->pi[i].pw_d !=3D pw_d || + !pcdev->pi[i].isr_enabled) + continue; + + ret =3D _pse_disable_pi_pol(pcdev, i); + if (ret) + return ret; + + /* PI disabled */ + return 1; + } + + /* No PI disabled */ + return 0; +} + +static int pse_disable_pi_prio_pol(struct pse_controller_dev *pcdev, + struct pse_power_domain *pw_d, + int prio) +{ + int ret; + + if (pw_d->discon_pol & ETHTOOL_PSE_DISCON_LRC) { + ret =3D pse_disable_pi_prio_lrc(pcdev, pw_d, prio); + if (ret) + return ret; + } + + if (pw_d->discon_pol & + ETHTOOL_PSE_DISCON_ROUND_ROBIN_IDX_LOWEST_FIRST) { + ret =3D pse_disable_pi_prio_round_rob_low(pcdev, pw_d, prio); + if (ret) + return ret; + } + + return 0; +} + +static int +pse_pi_allocate_pw_budget_static_prio(struct pse_controller_dev *pcdev, in= t id, + int pw_req, struct netlink_ext_ack *extack) +{ + struct pse_pi *pi =3D &pcdev->pi[id]; + int ret, _prio; + + _prio =3D pcdev->nr_lines; + while (regulator_request_power_budget(pi->pw_d->supply, pw_req) =3D=3D -E= RANGE) { + ret =3D pse_disable_pi_prio_pol(pcdev, pi->pw_d, _prio); + if (ret < 0) + return ret; + /* No pi disabled, decrease priority value */ + if (!ret) + _prio--; + + if (_prio <=3D pi->prio) { + NL_SET_ERR_MSG_FMT(extack, + "PI %d: not enough power budget available", + id); + return -ERANGE; + } + } + + pi->pw_allocated =3D pw_req; + return 0; +} + +static int pse_pi_allocate_pw_budget(struct pse_controller_dev *pcdev, int= id, + int pw_req, struct netlink_ext_ack *extack) +{ + struct pse_pi *pi =3D &pcdev->pi[id]; + int ret; + + if (!pi->pw_d) + return 0; + + /* ETHTOOL_PSE_PORT_PRIO_STATIC */ + if (pi->pw_d->port_prio_mode & ETHTOOL_PSE_PORT_PRIO_STATIC) + return pse_pi_allocate_pw_budget_static_prio(pcdev, id, pw_req, + extack); + + /* ETHTOOL_PSE_PORT_PRIO_DISABLED */ + ret =3D regulator_request_power_budget(pi->pw_d->supply, pw_req); + if (ret) + NL_SET_ERR_MSG_FMT(extack, + "PI %d: not enough power budget available", + id); + else + pi->pw_allocated =3D pw_req; + + return ret; +} + +static int pse_pi_enable_isr(struct pse_controller_dev *pcdev, int id, + struct netlink_ext_ack *extack) +{ + const struct pse_controller_ops *ops =3D pcdev->ops; + struct pse_pi *pi =3D &pcdev->pi[id]; + int ret, pw_req; + + if (!ops->pi_enable || !ops->pi_get_pw_req) { + NL_SET_ERR_MSG(extack, "PSE does not support enable control"); + return -EOPNOTSUPP; + } + + if (pi->isr_enabled) + return 0; + + ret =3D ops->pi_get_pw_req(pcdev, id); + if (ret < 0) + return ret; + + pw_req =3D ret; + + /* Compare requested power with port power limit and use the lowest + * one. + */ + if (ops->pi_get_current_limit && ops->pi_get_voltage) { + int uV, mW; + s64 tmp_64; + + ret =3D ops->pi_get_voltage(pcdev, id); + if (ret < 0) + return ret; + uV =3D ret; + + ret =3D ops->pi_get_current_limit(pcdev, id); + if (ret < 0) + return ret; + + tmp_64 =3D ret; + tmp_64 *=3D uV; + /* mW =3D uV * uA / 1000000000 */ + mW =3D DIV_ROUND_CLOSEST_ULL(tmp_64, 1000000000); + if (mW < pw_req) + pw_req =3D mW; + } + + ret =3D pse_pi_allocate_pw_budget(pcdev, id, pw_req, extack); + if (ret) + return ret; + + if (pi->admin_state_enabled) { + ret =3D ops->pi_enable(pcdev, id); + if (ret) { + pse_pi_deallocate_pw_budget(pi); + NL_SET_ERR_MSG_FMT(extack, + "PI %d: enable error %d", + id, ret); + return ret; + } + } + + pi->isr_enabled =3D 1; + if (pi->pw_d) + pi->pw_d->pi_lrc_id =3D id; + return 0; +} + +static int pse_set_config_isr(struct pse_controller_dev *pcdev, int id, + unsigned long notifs, + struct netlink_ext_ack *extack) +{ + int ret =3D 0; + + if (notifs & ETHTOOL_PSE_PORT_PRIO_DYNAMIC) + return 0; + + if ((notifs & ETHTOOL_C33_PSE_EVENT_DISCONNECTION) && + ((notifs & ETHTOOL_C33_PSE_EVENT_DETECTION) || + (notifs & ETHTOOL_C33_PSE_EVENT_CLASSIFICATION))) { + NL_SET_ERR_MSG_FMT(extack, + "PI %d: error, connection and disconnection reported simultaneously= ", + id); + return -EINVAL; + } + + if (notifs & ETHTOOL_C33_PSE_EVENT_CLASSIFICATION) + ret =3D pse_pi_enable_isr(pcdev, id, extack); + else if (notifs & ETHTOOL_C33_PSE_EVENT_DISCONNECTION) + ret =3D pse_pi_disable_isr(pcdev, id, extack); + + return ret; +} + static irqreturn_t pse_isr(int irq, void *data) { struct netlink_ext_ack extack =3D {}; @@ -703,9 +1039,10 @@ static irqreturn_t pse_isr(int irq, void *data) memset(h->notifs, 0, pcdev->nr_lines * sizeof(*h->notifs)); mutex_lock(&pcdev->lock); ret =3D desc->map_event(irq, pcdev, h->notifs, ¬ifs_mask); - mutex_unlock(&pcdev->lock); - if (ret || !notifs_mask) + if (ret || !notifs_mask) { + mutex_unlock(&pcdev->lock); return IRQ_NONE; + } =20 for_each_set_bit(i, ¬ifs_mask, pcdev->nr_lines) { struct phy_device *phydev; @@ -716,6 +1053,12 @@ static irqreturn_t pse_isr(int irq, void *data) continue; =20 notifs =3D h->notifs[i]; + if (pse_pw_d_is_sw_pw_control(pcdev, pcdev->pi[i].pw_d)) { + ret =3D pse_set_config_isr(pcdev, i, notifs, &extack); + if (ret) + notifs |=3D ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR; + } + dev_dbg(h->pcdev->dev, "Sending PSE notification EVT 0x%lx\n", notifs); =20 @@ -727,6 +1070,8 @@ static irqreturn_t pse_isr(int irq, void *data) NULL); } =20 + mutex_unlock(&pcdev->lock); + return IRQ_HANDLED; } =20 @@ -971,6 +1316,7 @@ static int _pse_ethtool_get_status(struct pse_controll= er_dev *pcdev, struct pse_control_status *status) { const struct pse_controller_ops *ops; + struct pse_pi *pi =3D &pcdev->pi[id]; =20 ops =3D pcdev->ops; if (!ops->ethtool_get_status) { @@ -980,8 +1326,23 @@ static int _pse_ethtool_get_status(struct pse_control= ler_dev *pcdev, } =20 status->pse_id =3D pcdev->id; - if (pcdev->pi[id].pw_d) - status->pw_d_id =3D pcdev->pi[id].pw_d->id; + if (pi->pw_d) { + status->pw_d_id =3D pi->pw_d->id; + status->c33_prio_mode =3D pi->pw_d->port_prio_mode; + status->c33_discon_pol =3D pi->pw_d->discon_pol; + switch (pi->pw_d->port_prio_mode) { + case ETHTOOL_PSE_PORT_PRIO_STATIC: + status->c33_prio_max =3D pcdev->nr_lines; + status->c33_prio =3D pi->prio; + break; + case ETHTOOL_PSE_PORT_PRIO_DYNAMIC: + status->c33_prio_max =3D pcdev->pis_prio_max; + break; + default: + break; + } + status->c33_prio_supp_modes =3D pcdev->port_prio_supp_modes; + } =20 return ops->ethtool_get_status(pcdev, id, extack, status); } @@ -1020,8 +1381,9 @@ static int pse_ethtool_c33_set_config(struct pse_cont= rol *psec, case ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED: /* We could have mismatch between admin_state_enabled and * state reported by regulator_is_enabled. This can occur when - * the PI is forcibly turn off by the controller. Call - * regulator_disable on that case to fix the counters state. + * the PI is forcibly turn off by the controller or by the + * interrupt context. Call regulator_disable on that case + * to fix the counters state. */ if (psec->pcdev->pi[psec->id].admin_state_enabled && !regulator_is_enabled(psec->ps)) { @@ -1094,6 +1456,32 @@ int pse_ethtool_set_config(struct pse_control *psec, } EXPORT_SYMBOL_GPL(pse_ethtool_set_config); =20 +static int pse_pi_update_pw_budget(struct pse_pi *pi, int id, + const unsigned int pw_limit, + struct netlink_ext_ack *extack) +{ + int pw_diff, ret; + + pw_diff =3D pw_limit - pi->pw_allocated; + if (!pw_diff) { + return 0; + } else if (pw_diff > 0) { + ret =3D regulator_request_power_budget(pi->pw_d->supply, pw_diff); + if (ret) { + NL_SET_ERR_MSG_FMT(extack, + "PI %d: not enough power budget available", + id); + return ret; + } + + } else { + regulator_free_power_budget(pi->pw_d->supply, -pw_diff); + } + pi->pw_allocated =3D pw_limit; + + return 0; +} + /** * pse_ethtool_set_pw_limit - set PSE control power limit * @psec: PSE control pointer @@ -1130,10 +1518,152 @@ int pse_ethtool_set_pw_limit(struct pse_control *p= sec, /* uA =3D mW * 1000000000 / uV */ uA =3D DIV_ROUND_CLOSEST_ULL(tmp_64, uV); =20 + if (psec->pcdev->pi[psec->id].pw_d) { + ret =3D pse_pi_update_pw_budget(&psec->pcdev->pi[psec->id], + psec->id, pw_limit, extack); + if (ret) + return ret; + } + return regulator_set_current_limit(psec->ps, 0, uA); } EXPORT_SYMBOL_GPL(pse_ethtool_set_pw_limit); =20 +int pse_ethtool_set_prio(struct pse_control *psec, + struct netlink_ext_ack *extack, + unsigned int prio) +{ + struct pse_controller_dev *pcdev =3D psec->pcdev; + const struct pse_controller_ops *ops; + int ret =3D 0; + + if (!pcdev->pi[psec->id].pw_d) { + NL_SET_ERR_MSG(extack, "no power domain attached"); + return -EOPNOTSUPP; + } + + /* We don't want priority change in the middle of an + * enable/disable call or a priority mode change + */ + mutex_lock(&pcdev->lock); + switch (pcdev->pi[psec->id].pw_d->port_prio_mode) { + case ETHTOOL_PSE_PORT_PRIO_STATIC: + if (prio > pcdev->nr_lines) { + NL_SET_ERR_MSG_FMT(extack, + "priority %d exceed priority max %d", + prio, pcdev->nr_lines); + ret =3D -ERANGE; + goto out; + } + + pcdev->pi[psec->id].prio =3D prio; + break; + + case ETHTOOL_PSE_PORT_PRIO_DYNAMIC: + ops =3D psec->pcdev->ops; + if (!ops->pi_set_prio) { + NL_SET_ERR_MSG(extack, + "pse driver does not support setting port priority"); + ret =3D -EOPNOTSUPP; + goto out; + } + + if (prio > pcdev->pis_prio_max) { + NL_SET_ERR_MSG_FMT(extack, + "priority %d exceed priority max %d", + prio, pcdev->pis_prio_max); + ret =3D -ERANGE; + goto out; + } + + ret =3D ops->pi_set_prio(pcdev, psec->id, prio); + break; + + default: + ret =3D -EOPNOTSUPP; + } + +out: + mutex_unlock(&pcdev->lock); + return ret; +} +EXPORT_SYMBOL_GPL(pse_ethtool_set_prio); + +int pse_ethtool_set_prio_mode(struct pse_control *psec, + struct netlink_ext_ack *extack, + u32 prio_mode) +{ + struct pse_controller_dev *pcdev =3D psec->pcdev; + const struct pse_controller_ops *ops; + int ret =3D 0, i; + + if (!(prio_mode & pcdev->port_prio_supp_modes)) { + NL_SET_ERR_MSG(extack, "priority mode not supported"); + return -EOPNOTSUPP; + } + + if (!pcdev->pi[psec->id].pw_d) { + NL_SET_ERR_MSG(extack, "no power domain attached"); + return -EOPNOTSUPP; + } + + /* ETHTOOL_PSE_PORT_PRIO_DISABLED can't be ORed with another mode */ + if (prio_mode & ETHTOOL_PSE_PORT_PRIO_DISABLED && + prio_mode & ~ETHTOOL_PSE_PORT_PRIO_DISABLED) { + NL_SET_ERR_MSG(extack, + "port priority can't be enabled and disabled simultaneously"); + return -EINVAL; + } + + ops =3D psec->pcdev->ops; + + /* We don't want priority mode change in the middle of an + * enable/disable call + */ + mutex_lock(&pcdev->lock); + pcdev->pi[psec->id].pw_d->port_prio_mode =3D prio_mode; + + /* Reset all priorities of the Power Domain */ + for (i =3D 0; i < psec->pcdev->nr_lines; i++) { + if (!pcdev->pi[i].rdev || + pcdev->pi[i].pw_d !=3D pcdev->pi[psec->id].pw_d) + continue; + + pcdev->pi[i].prio =3D 0; + + if (!ops->pi_set_prio) + continue; + + if (pcdev->port_prio_supp_modes & + ETHTOOL_PSE_PORT_PRIO_DYNAMIC) + ret =3D ops->pi_set_prio(pcdev, psec->id, 0); + } + + mutex_unlock(&psec->pcdev->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(pse_ethtool_set_prio_mode); + +int pse_ethtool_set_discon_pol(struct pse_control *psec, + struct netlink_ext_ack *extack, + u32 pol) +{ + struct pse_controller_dev *pcdev =3D psec->pcdev; + + if (!pcdev->pi[psec->id].pw_d) { + NL_SET_ERR_MSG(extack, "no power domain attached"); + return -EOPNOTSUPP; + } + + mutex_lock(&pcdev->lock); + pcdev->pi[psec->id].pw_d->discon_pol =3D pol; + mutex_unlock(&psec->pcdev->lock); + + return 0; +} +EXPORT_SYMBOL_GPL(pse_ethtool_set_discon_pol); + bool pse_has_podl(struct pse_control *psec) { return psec->pcdev->types & ETHTOOL_PSE_PODL; diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index bdf3e8c468fc..e84eba710dc8 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -9,6 +9,7 @@ #include #include #include +#include =20 /* Maximum current in uA according to IEEE 802.3-2022 Table 145-1 */ #define MAX_PI_CURRENT 1920000 @@ -62,6 +63,13 @@ struct pse_control_config { * is in charge of the memory allocation. * @c33_pw_limit_nb_ranges: number of supported power limit configuration * ranges + * @c33_prio_supp_modes: PSE port priority modes supported. Set by PSE cor= e. + * @c33_prio_mode: PSE port priority mode selected. Set by PSE core. + * @c33_prio_max: max priority allowed for the c33_prio variable value. Set + * by PSE core. + * @c33_prio: priority of the PSE. Set by PSE core in case of static port + * priority mode. + * @c33_discon_pol: PSE disconnection policy selected. Set by PSE core. */ struct pse_control_status { u32 pse_id; @@ -76,6 +84,11 @@ struct pse_control_status { u32 c33_avail_pw_limit; struct ethtool_c33_pse_pw_limit_range *c33_pw_limit_ranges; u32 c33_pw_limit_nb_ranges; + u32 c33_prio_supp_modes; + enum pse_port_prio_modes c33_prio_mode; + u32 c33_prio_max; + u32 c33_prio; + u32 c33_discon_pol; }; =20 /** @@ -95,6 +108,10 @@ struct pse_control_status { * set_current_limit regulator callback. * Should not return an error in case of MAX_PI_CURRENT * current value set. + * @pi_set_prio: Configure the PSE PI priority. + * @pi_get_pw_req: Get the power requested by a PD before enabling the PSE= PI. + * This is only relevant when an interrupt is registered using + * devm_pse_irq_helper helper. */ struct pse_controller_ops { int (*ethtool_get_status)(struct pse_controller_dev *pcdev, @@ -109,6 +126,9 @@ struct pse_controller_ops { int id); int (*pi_set_current_limit)(struct pse_controller_dev *pcdev, int id, int max_uA); + int (*pi_set_prio)(struct pse_controller_dev *pcdev, int id, + unsigned int prio); + int (*pi_get_pw_req)(struct pse_controller_dev *pcdev, int id); }; =20 struct module; @@ -143,6 +163,12 @@ struct pse_pi_pairset { * @rdev: regulator represented by the PSE PI * @admin_state_enabled: PI enabled state * @pw_d: Power domain of the PSE PI + * @prio: Priority of the PSE PI. Used in static port priority mode + * @isr_enabled: PSE PI power status managed by the interruption handler. + * This variable is relevant when the power enabled management + * is a managed in software like the static port priority mode. + * @pw_allocated: Power allocated to a PSE PI to manage power budget in + * static port priority mode */ struct pse_pi { struct pse_pi_pairset pairset[2]; @@ -150,6 +176,9 @@ struct pse_pi { struct regulator_dev *rdev; bool admin_state_enabled; struct pse_power_domain *pw_d; + int prio; + bool isr_enabled; + int pw_allocated; }; =20 /** @@ -168,6 +197,8 @@ struct pse_pi { * @no_of_pse_pi: flag set if the pse_pis devicetree node is not used * @id: Index of the PSE * @irq: PSE interrupt + * @pis_prio_max: Maximum value allowed for the PSE PIs priority + * @port_prio_supp_modes: Bitfield of port priority mode supported by the = PSE */ struct pse_controller_dev { const struct pse_controller_ops *ops; @@ -183,6 +214,8 @@ struct pse_controller_dev { bool no_of_pse_pi; u32 id; int irq; + unsigned int pis_prio_max; + u32 port_prio_supp_modes; }; =20 #if IS_ENABLED(CONFIG_PSE_CONTROLLER) @@ -207,6 +240,15 @@ int pse_ethtool_set_config(struct pse_control *psec, int pse_ethtool_set_pw_limit(struct pse_control *psec, struct netlink_ext_ack *extack, const unsigned int pw_limit); +int pse_ethtool_set_prio(struct pse_control *psec, + struct netlink_ext_ack *extack, + unsigned int prio); +int pse_ethtool_set_prio_mode(struct pse_control *psec, + struct netlink_ext_ack *extack, + u32 prio_mode); +int pse_ethtool_set_discon_pol(struct pse_control *psec, + struct netlink_ext_ack *extack, + u32 pol); =20 bool pse_has_podl(struct pse_control *psec); bool pse_has_c33(struct pse_control *psec); @@ -244,6 +286,27 @@ static inline int pse_ethtool_set_pw_limit(struct pse_= control *psec, return -EOPNOTSUPP; } =20 +static inline int pse_ethtool_set_prio(struct pse_control *psec, + struct netlink_ext_ack *extack, + unsigned int prio) +{ + return -EOPNOTSUPP; +} + +static inline int pse_ethtool_set_prio_mode(struct pse_control *psec, + struct netlink_ext_ack *extack, + u32 prio_mode) +{ + return -EOPNOTSUPP; +} + +static inline int pse_ethtool_set_discon_pol(struct pse_control *psec, + struct netlink_ext_ack *extack, + u32 pol) +{ + return -EOPNOTSUPP; +} + static inline bool pse_has_podl(struct pse_control *psec) { return false; diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index a4c93d6de218..b6727049840c 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -1002,11 +1002,84 @@ enum ethtool_c33_pse_pw_d_status { * enum ethtool_pse_events - event list of the PSE controller. * @ETHTOOL_PSE_EVENT_OVER_CURRENT: PSE output current is too high. * @ETHTOOL_PSE_EVENT_OVER_TEMP: PSE in over temperature state. + * @ETHTOOL_C33_PSE_EVENT_DETECTION: detection process occur on the PSE. + * IEEE 802.3-2022 145.2.6 PSE detection of PDs + * @ETHTOOL_C33_PSE_EVENT_CLASSIFICATION: classification process occur on + * the PSE. IEEE 802.3-2022 145.2.8 PSE classification of PDs and + * mutual identification + * @ETHTOOL_C33_PSE_EVENT_DISCONNECTION: PD has been disconnected on the P= SE. + * @ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR: PSE faced an error managing the + * power control from software. */ =20 enum ethtool_pse_events { ETHTOOL_PSE_EVENT_OVER_CURRENT =3D 1 << 0, ETHTOOL_PSE_EVENT_OVER_TEMP =3D 1 << 1, + ETHTOOL_C33_PSE_EVENT_DETECTION =3D 1 << 2, + ETHTOOL_C33_PSE_EVENT_CLASSIFICATION =3D 1 << 3, + ETHTOOL_C33_PSE_EVENT_DISCONNECTION =3D 1 << 4, + ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR =3D 1 << 5, +}; + +/** + * enum pse_port_prio_modes - PSE port priority modes. + * @ETHTOOL_PSE_PORT_PRIO_DISABLED: Port priority disabled. + * @ETHTOOL_PSE_PORT_PRIO_STATIC: PSE static port priority. Port priority + * based on the power requested during PD classification. This mode + * is managed by the PSE core. + * @ETHTOOL_PSE_PORT_PRIO_DYNAMIC: PSE dynamic port priority. Port priority + * based on the current consumption per ports compared to the total + * power budget. This mode is managed by the PSE controller. + */ + +enum pse_port_prio_modes { + ETHTOOL_PSE_PORT_PRIO_DISABLED =3D 1 << 0, + ETHTOOL_PSE_PORT_PRIO_STATIC =3D 1 << 1, + ETHTOOL_PSE_PORT_PRIO_DYNAMIC =3D 1 << 2, +}; + +/** + * enum ethtool_pse_disconnection_policy - Disconnection strategies for + * same-priority devices when power budget is exceeded, tailored to + * specific priority modes. + * + * @ETHTOOL_PSE_DISCON_LRC: Disconnect least recently connected device. + * Relevant for: ETHTOOL_PSE_PORT_PRIO_STATIC + * Behavior: When multiple devices share the same priority level, the + * system disconnects the device that was most recently connected. + * Rationale: This strategy favors stability for longer-standing + * connections, assuming that established devices may be more critical. + * Use Case: Suitable for systems prioritizing stable power allocation for + * existing static-priority connections, making newer devices suitable + * candidates for disconnection if limits are exceeded. + * @ETHTOOL_PSE_DISCON_ROUND_ROBIN_IDX_LOWEST_FIRST: Disconnect based on p= ort + * index in a round-robin manner, starting with the lowest index. + * Relevant for: ETHTOOL_PSE_PORT_PRIO_STATIC + * Behavior: Disconnects devices sequentially based on port index, starting + * with the lowest. If multiple disconnections are required, the process + * continues in ascending order. + * Rationale: Provides a predictable, systematic approach for + * static-priority devices, making it clear which device will be + * disconnected next if power limits are reached. + * Use Case: Appropriate for systems where static-priority devices are + * equal in role, and fairness in disconnections is prioritized. + * + * Each device can have multiple disconnection policies set as an array of + * priorities. When the power budget is exceeded, the policies are executed + * in the order defined by the user. This allows for a more nuanced and + * flexible approach to handling power constraints across a range of devic= es + * with similar priorities or attributes. + * + * Example Usage: + * Users can specify an ordered list of policies, such as starting with + * `PSE_DISCON_STATIC_CLASS_HIGHEST_FIRST` to prioritize based on class, + * followed by `PSE_DISCON_LRC` to break ties based on connection time. + * This ordered execution ensures that power disconnections align closely + * with the system=E2=80=99s operational requirements and priorities. + */ +enum ethtool_pse_disconnection_policy { + ETHTOOL_PSE_DISCON_LRC =3D 1 << 0, + ETHTOOL_PSE_DISCON_ROUND_ROBIN_IDX_LOWEST_FIRST =3D 1 << 1, }; =20 /** --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A92B61E1C01; Thu, 21 Nov 2024 14:44:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200265; cv=none; b=tBIVgfhBT5uZCxayAqCAKwcvE+Mgifjk4gYNjj3Z+0bvTcTftdNUhBdN9XECjorLvxVo5P/YTmL5kblKGBj/qR9RgDwsSxnE4Hdkd2kokpHpgRWcz/gxbFHDuJnT6R4RzQmc8ymHGE13XNmP7ZB6N6Nqzy6U9UBUM1WBBK4nUCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200265; c=relaxed/simple; bh=booA6yFdShFtwHnqZy37RrZNkbRfD1d+Ls3c8nI8p4o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=vEendikPA1xmUJgaCS7CZv5nTVwCIevGmVSkLd544ZOPxNOgcPV1KbB8mShPcrA3PQoLB/7R4tpyCYDN6Su1ElEEmq3MOEN8+4t6Jgtdgo09Vo5FiSVzrBImSNqYGqiEdugK9svguSXWA6YFcvwngslGZp5S1NmyBhLpl45wvGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=VRNSRpMh; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="VRNSRpMh" Received: by mail.gandi.net (Postfix) with ESMTPSA id 55E8240003; Thu, 21 Nov 2024 14:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200261; 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=AZJWuBjeqKJmnEiwEBR1gMP6oqgwjaK+489mv7sDUPk=; b=VRNSRpMhX+8Tdpq6PqqEHZvgDmXy6UFHj+cZTWZyFS5pFWapGK6+8ISK+c1KyiKBHX1eYI Y9hpJ/tClZqrtDgjIX1jetLoPCtocowRfCM7YPQwzyeeCHNp8RmyIfPN0MAQa8KW6UqTtQ dNii+LRWEQ+cbm112ri24LD8Kl6KyzF+97gEDMs+FzqdPjx7dPDbvg2R9MS9xGxdCkT9Dd KMsH8L5TBqASejGtKIfqYCJOIS6WWP4j2B7X7UdHrAOloZGFKsbEzWUnr0XBo+pNnn1icT DK8U4HKT6/6IAcxxvzXzNi/+Hz07l1+5Y348MDBJACoJAnqwIEEM1Mcuak3NxA== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:48 +0100 Subject: [PATCH RFC net-next v3 22/27] net: ethtool: Add PSE new port priority support feature Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-22-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) This patch expands the status information provided by ethtool for PSE c33 with current port priority and max port priority. It also adds a call to pse_ethtool_set_prio(), pse_ethtool_set_prio_mode() and pse_ethtool_set_discon_pol() to configure the PSE port priority, mode and disconnection policy. Signed-off-by: Kory Maincent --- Change in v3: - Add disconnection policy. Change in v2: - Improve port priority documentation. - Add port priority modes. --- Documentation/networking/ethtool-netlink.rst | 77 ++++++++++++++++++++++++= ++++ include/uapi/linux/ethtool_netlink.h | 5 ++ net/ethtool/pse-pd.c | 66 ++++++++++++++++++++++++ 3 files changed, 148 insertions(+) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/n= etworking/ethtool-netlink.rst index 3573543ae5ad..b231641dd4a9 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -1768,6 +1768,15 @@ Kernel response contents: configuration ranges. ``ETHTOOL_A_PSE_ID`` u32 Index of the PSE ``ETHTOOL_A_PSE_PW_D_ID`` u32 Index of the PSE pow= er domain + ``ETHTOOL_A_C33_PSE_PRIO_SUPP_MODES`` u32 priority modes suppo= rted + ``ETHTOOL_A_C33_PSE_PRIO_MODE`` u32 priority mode of the= PSE + currently configured + ``ETHTOOL_A_C33_PSE_PRIO_MAX`` u32 priority maximum con= figurable + on the PoE PSE + ``ETHTOOL_A_C33_PSE_PRIO`` u32 priority of the PoE = PSE + currently configured + ``ETHTOOL_A_C33_PSE_DISCON_POL`` u32 disconnection policy + currently configured =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D =20 When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_STATE`` attribute identi= fies @@ -1847,6 +1856,21 @@ controller. The ``ETHTOOL_A_PSE_PW_D_ID`` attribute identifies the index of PSE power domain. =20 +When set, the optional ``ETHTOOL_A_C33_PSE_PRIO_SUPP_MODES`` attribute +identifies the priority mode supported by the C33 PSE. +When set, the optional ``ETHTOOL_A_C33_PSE_PRIO_MODE`` attributes is used = to +identifies the currently configured C33 PSE priority mode. +When set, the optional ``ETHTOOL_A_C33_PSE_DISCON_POL`` attributes is used= to +identifies the currently configured C33 PSE disconnection policy. +For a description of C33 PSE priority modes and disconnection policy, +see ``PSE_SET``. + +When set, the optional ``ETHTOOL_A_C33_PSE_PRIO_MAX`` attribute identifies +the C33 PSE maximum priority value. +When set, the optional ``ETHTOOL_A_C33_PSE_PRIO`` attributes is used to +identifies the currently configured C33 PSE priority. +For a description of C33 PSE priority attributes, see ``PSE_SET``. + PSE_SET =3D=3D=3D=3D=3D=3D=3D =20 @@ -1860,6 +1884,12 @@ Request contents: ``ETHTOOL_A_C33_PSE_ADMIN_CONTROL`` u32 Control PSE Admin state ``ETHTOOL_A_C33_PSE_AVAIL_PWR_LIMIT`` u32 Control PoE PSE available power limit + ``ETHTOOL_A_C33_PSE_PRIO_MODE`` u32 Control priority mode of= the + PoE PSE + ``ETHTOOL_A_C33_PSE_PRIO`` u32 Control priority of the + PoE PSE + ``ETHTOOL_A_C33_PSE_DISCON_POL`` u32 Control disconnection po= licy + of the PoE PSE =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =20 When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_CONTROL`` attribute is u= sed @@ -1882,6 +1912,53 @@ various existing products that document power consum= ption in watts rather than classes. If power limit configuration based on classes is needed, the conversion can be done in user space, for example by ethtool. =20 +When set, the optional ``ETHTOOL_A_C33_PSE_PRIO_MODE`` attributes is used = to +control the C33 PSE priority mode. The available mode are: + +1. Static Method: + + This method involves distributing power based on PD classification. It= =E2=80=99s + straightforward and stable, with the PSE core keeping track of the budg= et + and subtracting the power requested by each PD=E2=80=99s class. + + Advantages: Every PD gets its promised power at any time, which guarant= ees + reliability. + + Disadvantages: PD classification steps are large, meaning devices reque= st + much more power than they actually need. As a result, the power supply = may + only operate at, say, 50% capacity, which is inefficient and wastes mon= ey. + +2. Dynamic Method: + + This method monitors the current consumption per port and subtracts it = from + the available power budget. When the budget is exceeded, lower-priority + ports are shut down. This method is managed by the PSE controller itsel= f. + + Advantages: This method optimizes resource utilization, saving costs. + + Disadvantages: Low-priority devices may experience instability. + +When set, the optional ``ETHTOOL_A_C33_PSE_PRIO`` attributes is used to +control the C33 PSE priority. Allowed priority value are between zero +and the value of ``ETHTOOL_A_C33_PSE_PRIO_MAX`` attribute. + +A lower value indicates a higher priority, meaning that a priority value +of 0 corresponds to the highest port priority. +Port priority serves two functions: + + - Power-up Order: After a reset, ports are powered up in order of their + priority from highest to lowest. Ports with higher priority + (lower values) power up first. + - Shutdown Order: When the power budget is exceeded, ports with lower + priority (higher values) are turned off first. + +When set, the optional ``ETHTOOL_A_C33_PSE_DISCON_POL`` attributes is used +to control the disconnection policy. When port are on the same priority +the disconnection policy is used to specify the shutdown order. + +.. kernel-doc:: include/uapi/linux/ethtool.h + :identifiers: ethtool_pse_disconnection_policy + RSS_GET =3D=3D=3D=3D=3D=3D=3D =20 diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/etht= ool_netlink.h index 088ad7b956fb..e668a91ed1ca 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -973,6 +973,11 @@ enum { ETHTOOL_A_C33_PSE_PW_LIMIT_RANGES, /* nest - _C33_PSE_PW_LIMIT_* */ ETHTOOL_A_PSE_ID, /* u32 */ ETHTOOL_A_PSE_PW_D_ID, /* u32 */ + ETHTOOL_A_C33_PSE_PRIO_SUPP_MODES, /* u32 */ + ETHTOOL_A_C33_PSE_PRIO_MODE, /* u32 */ + ETHTOOL_A_C33_PSE_PRIO_MAX, /* u32 */ + ETHTOOL_A_C33_PSE_PRIO, /* u32 */ + ETHTOOL_A_C33_PSE_DISCON_POL, /* u32 */ =20 /* add new constants above here */ __ETHTOOL_A_PSE_CNT, diff --git a/net/ethtool/pse-pd.c b/net/ethtool/pse-pd.c index d67803b67e76..f8253f4c69cc 100644 --- a/net/ethtool/pse-pd.c +++ b/net/ethtool/pse-pd.c @@ -112,6 +112,18 @@ static int pse_reply_size(const struct ethnl_req_info = *req_base, len +=3D st->c33_pw_limit_nb_ranges * (nla_total_size(0) + nla_total_size(sizeof(u32)) * 2); + if (st->c33_prio_supp_modes) + /* _C33_PSE_PRIO_SUPP_MODES */ + len +=3D nla_total_size(sizeof(u32)); + if (st->c33_prio_mode) + /* _C33_PSE_PRIO_MODE */ + len +=3D nla_total_size(sizeof(u32)); + if (st->c33_prio_max) + /* _C33_PSE_PRIO_MAX + _C33_PSE_PRIO */ + len +=3D nla_total_size(sizeof(u32)) * 2; + if (st->c33_discon_pol) + /* _C33_PSE_DISCON_POL */ + len +=3D nla_total_size(sizeof(u32)); =20 return len; } @@ -209,6 +221,24 @@ static int pse_fill_reply(struct sk_buff *skb, pse_put_pw_limit_ranges(skb, st)) return -EMSGSIZE; =20 + if (st->c33_prio_supp_modes > 0 && + nla_put_u32(skb, ETHTOOL_A_C33_PSE_PRIO_SUPP_MODES, + st->c33_prio_supp_modes)) + return -EMSGSIZE; + + if (st->c33_prio_mode > 0 && + nla_put_u32(skb, ETHTOOL_A_C33_PSE_PRIO_MODE, st->c33_prio_mode)) + return -EMSGSIZE; + + if (st->c33_prio_max > 0 && + (nla_put_u32(skb, ETHTOOL_A_C33_PSE_PRIO_MAX, st->c33_prio_max) || + nla_put_u32(skb, ETHTOOL_A_C33_PSE_PRIO, st->c33_prio))) + return -EMSGSIZE; + + if (st->c33_discon_pol > 0 && + nla_put_u32(skb, ETHTOOL_A_C33_PSE_DISCON_POL, st->c33_discon_pol)) + return -EMSGSIZE; + return 0; } =20 @@ -230,6 +260,13 @@ const struct nla_policy ethnl_pse_set_policy[ETHTOOL_A= _PSE_MAX + 1] =3D { NLA_POLICY_RANGE(NLA_U32, ETHTOOL_C33_PSE_ADMIN_STATE_DISABLED, ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED), [ETHTOOL_A_C33_PSE_AVAIL_PW_LIMIT] =3D { .type =3D NLA_U32 }, + [ETHTOOL_A_C33_PSE_PRIO_MODE] =3D + NLA_POLICY_RANGE(NLA_U32, ETHTOOL_PSE_PORT_PRIO_DISABLED, + ETHTOOL_PSE_PORT_PRIO_DYNAMIC), + [ETHTOOL_A_C33_PSE_PRIO] =3D { .type =3D NLA_U32 }, + [ETHTOOL_A_C33_PSE_DISCON_POL] =3D + NLA_POLICY_RANGE(NLA_U32, ETHTOOL_PSE_DISCON_LRC, + ETHTOOL_PSE_DISCON_ROUND_ROBIN_IDX_LOWEST_FIRST), }; =20 static int @@ -278,6 +315,35 @@ ethnl_set_pse(struct ethnl_req_info *req_info, struct = genl_info *info) if (ret) return ret; =20 + if (tb[ETHTOOL_A_C33_PSE_PRIO_MODE]) { + unsigned int prio_mode; + + prio_mode =3D nla_get_u32(tb[ETHTOOL_A_C33_PSE_PRIO_MODE]); + ret =3D pse_ethtool_set_prio_mode(phydev->psec, info->extack, + prio_mode); + if (ret) + return ret; + } + + if (tb[ETHTOOL_A_C33_PSE_DISCON_POL]) { + unsigned int pol; + + pol =3D nla_get_u32(tb[ETHTOOL_A_C33_PSE_DISCON_POL]); + ret =3D pse_ethtool_set_discon_pol(phydev->psec, info->extack, + pol); + if (ret) + return ret; + } + + if (tb[ETHTOOL_A_C33_PSE_PRIO]) { + unsigned int prio; + + prio =3D nla_get_u32(tb[ETHTOOL_A_C33_PSE_PRIO]); + ret =3D pse_ethtool_set_prio(phydev->psec, info->extack, prio); + if (ret) + return ret; + } + if (tb[ETHTOOL_A_C33_PSE_AVAIL_PW_LIMIT]) { unsigned int pw_limit; =20 --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D19351DDA2F; Thu, 21 Nov 2024 14:44:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200271; cv=none; b=bsUu4GH9lyyjaE4mUMi9ZF02FCCdJ3HedmizM+m2x3YpDC2y8PXRWxIeT6acftAZxvziSPLRT6ZHxW2S1HdWKk0nf7WzWH+9iJjpHYL8FY/Ur33xLQF8A5giv8QhlqUryPpE76ehszMB8UOOcegWC6r0aU00BdtiJlFXSRK0p50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200271; c=relaxed/simple; bh=exL8Nr6/+o176cowBQBWABHM3Mc4D55qQlnWSf3Ptac=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VLfd72jp84oXI5IgrMR4zEorrkVsFfp3qo7GknSROK4q7cYFCIhItsJA4VVOvohp0t3fOWig8YNLtj0tp4Wwq+2P1y0BKC3qFsYlKYfyHiNsdMFpUBpOMqjg0DQvE0t3Ax6+Af+uFp9N9k5FnfMRz3M5b2WdY8W2KqHPBe9fJHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=BA7lBh13; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="BA7lBh13" Received: by mail.gandi.net (Postfix) with ESMTPSA id 758CF4000F; Thu, 21 Nov 2024 14:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200266; 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=SypnoOdg8blA9bbWfoucUhr8Y916y7yHuW6LBJ8Fqgk=; b=BA7lBh13PfI/k1mvUPzi+nyAiO+4oO9ViMiW0ciRtO6OBQn9aTIUi4Hg6xJIq58RZdC8HK Hgpc3Pi9sBxTY2Dh70gK66a1hC2lOtFkkbSksqzbSwb/LudDC/1zkaiBVpYjzAV+e+lS/M 4HJ4OIiieoQNZjo8TGqeP1LYXvdcliRJt4TbXjivV83ULEu01sBoZCNob8oxfqzK+3wxHa OlIFfnK8kRFWb4HKuIVqIIfoo2W9p/mzD7lkiXy1xj087l0ZjkMUwbmRh4YZd+JWnlaLsy 26RH6mPNUEcthslGScxgku1AaSraaGZye0fGTMcKgK8KhVHp/egLWEgC8rYDKA== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:49 +0100 Subject: [PATCH RFC net-next v3 23/27] netlink: specs: Expand the PSE netlink command with newly supported features Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-23-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Expand the c33 PSE attributes with PSE id, PSE power domain id, priority and priority max to be able to set and get the PSE Power Interface priority. ./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do pse-get --json '{"header":{"dev-name":"eth1"}}' {'c33-pse-actual-pw': 1700, 'c33-pse-admin-state': 3, 'c33-pse-avail-pw-limit': 97500, 'c33-pse-prio': 2, 'c33-pse-prio-max': 2, 'c33-pse-pw-class': 4, 'c33-pse-pw-d-status': 4, 'c33-pse-pw-limit-ranges': [{'max': 18100, 'min': 15000}, {'max': 38000, 'min': 30000}, {'max': 65000, 'min': 60000}, {'max': 97500, 'min': 90000}], 'header': {'dev-index': 5, 'dev-name': 'eth1'}} ./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do pse-set --json '{"header":{"dev-name":"eth1"}, "c33-pse-prio":1}' None Signed-off-by: Kory Maincent --- Documentation/netlink/specs/ethtool.yaml | 37 ++++++++++++++++++++++++++++= ++++ 1 file changed, 37 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netli= nk/specs/ethtool.yaml index f27c76d965d9..c089c315cc2f 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -1025,6 +1025,34 @@ attribute-sets: type: nest multi-attr: true nested-attributes: c33-pse-pw-limit + - + name: pse-id + type: u32 + name-prefix: ethtool-a- + - + name: pse-pw-d-id + type: u32 + name-prefix: ethtool-a- + - + name: c33-pse-prio-supp-modes + type: u32 + name-prefix: ethtool-a- + - + name: c33-pse-prio-mode + type: u32 + name-prefix: ethtool-a- + - + name: c33-pse-prio-max + type: u32 + name-prefix: ethtool-a- + - + name: c33-pse-prio + type: u32 + name-prefix: ethtool-a- + - + name: c33-pse-discon-pol + type: u32 + name-prefix: ethtool-a- - name: rss attributes: @@ -1793,6 +1821,13 @@ operations: - c33-pse-ext-substate - c33-pse-avail-pw-limit - c33-pse-pw-limit-ranges + - pse-id + - pse-pw-d-id + - c33-pse-prio-supp-modes + - c33-pse-prio-mode + - c33-pse-prio-max + - c33-pse-prio + - c33-pse-discon-pol dump: *pse-get-op - name: pse-set @@ -1807,6 +1842,8 @@ operations: - podl-pse-admin-control - c33-pse-admin-control - c33-pse-avail-pw-limit + - c33-pse-prio + - c33-pse-discon-pol - name: rss-get doc: Get RSS params. --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AD451E25F9; Thu, 21 Nov 2024 14:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200275; cv=none; b=DaQ3BCx+BGyNmQcNpo9nstJvpiY5+HnzoZLOB4C3bcHR10PUSvbOP/z6SF9RF0J1XXQ2XEM3faY05YHrwP2oTDw+72IGxPf6QIXZdzECwqL5/69ps8YT1KlYtvFYLqFA1HipKvYPOVqEPnEwf21ExFv/LQkHg1I+kyD1vsLCZU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200275; c=relaxed/simple; bh=bnUXPyLx7iAkFU20XjCdcMR55Cku/ESx2wvQ0EUs5Dk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HZf6IIbpRU1zcipOrGEJiXPdCk5mEOKwLD1Mnmk5NsG7F1GrC1jAlM44nzLgK+/qGvPZyMEIeBfD4k0Izot0uX2XHFmfPiTLOsJ3AXrTsXMaZ36SsV2kVS5aN1jmKfGwuRrmfXMLlZu0+zKzxLc63j6fhOx4ZWj5GHkX6fiJv5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=m03yPGHf; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="m03yPGHf" Received: by mail.gandi.net (Postfix) with ESMTPSA id A706440009; Thu, 21 Nov 2024 14:44:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200272; 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=eOP1IkfFRlL4Pq7d7OAf+/sTC6P+RABrKmfkbVwNO/0=; b=m03yPGHfa3kJe6MncevMvD+YUB4QJ0xD/j+rb8JzDb2bDSDbM1i8+EGKmQuI7wri3w7kfY GNtKFS7SqaDvbT5dqomxk3VU86/B9IVPDeRK/2jhzTjc8VdwG7DicyHtHcVaZH72Vzoj0t WdlsA+ejizqRbTlOQ+qKdxxN1QWO+MZfgFxx4EoiDPe4AsBFpsF5YYcPwKO61cewUytPwR DOmp61OhQl4npXt/cY5Hhd5FEviicrfP+FI4EtwBDMDUo/j5JrwMpfoFD1G5dNvIbvaqqC MY8KrJHuvquXcISqWnQ4ssOF+hJ8q2Vt7gQrs7x2DJUG9EKpOLBlZmaJkI7dLg== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:50 +0100 Subject: [PATCH RFC net-next v3 24/27] net: pse-pd: pd692x0: Add support for PSE PI priority feature Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-24-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) This patch extends the PSE callbacks by adding support for the newly introduced pi_set_prio() callback, enabling the configuration of PSE PI priorities. The current port priority is now also included in the status information returned to users. Signed-off-by: Kory Maincent --- Changes in v3: - New patch --- drivers/net/pse-pd/pd692x0.c | 183 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 183 insertions(+) diff --git a/drivers/net/pse-pd/pd692x0.c b/drivers/net/pse-pd/pd692x0.c index 0af7db80b2f8..be9fc4afaf97 100644 --- a/drivers/net/pse-pd/pd692x0.c +++ b/drivers/net/pse-pd/pd692x0.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include =20 #define PD692X0_PSE_NAME "pd692x0_pse" =20 @@ -76,6 +78,8 @@ enum { PD692X0_MSG_GET_PORT_CLASS, PD692X0_MSG_GET_PORT_MEAS, PD692X0_MSG_GET_PORT_PARAM, + PD692X0_MSG_GET_POWER_BANK, + PD692X0_MSG_SET_POWER_BANK, =20 /* add new message above here */ PD692X0_MSG_CNT @@ -95,6 +99,8 @@ struct pd692x0_priv { unsigned long last_cmd_key_time; =20 enum ethtool_c33_pse_admin_state admin_state[PD692X0_MAX_PIS]; + struct regulator_dev *manager_reg[PD692X0_MAX_MANAGERS]; + int manager_pw_budget[PD692X0_MAX_MANAGERS]; }; =20 /* Template list of communication messages. The non-null bytes defined here @@ -170,6 +176,16 @@ static const struct pd692x0_msg pd692x0_msg_template_l= ist[PD692X0_MSG_CNT] =3D { .data =3D {0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e}, }, + [PD692X0_MSG_GET_POWER_BANK] =3D { + .key =3D PD692X0_KEY_REQ, + .sub =3D {0x07, 0x0b, 0x57}, + .data =3D { 0, 0x4e, 0x4e, 0x4e, + 0x4e, 0x4e, 0x4e, 0x4e}, + }, + [PD692X0_MSG_SET_POWER_BANK] =3D { + .key =3D PD692X0_KEY_CMD, + .sub =3D {0x07, 0x0b, 0x57}, + }, }; =20 static u8 pd692x0_build_msg(struct pd692x0_msg *msg, u8 echo) @@ -685,6 +701,8 @@ static int pd692x0_ethtool_get_status(struct pse_contro= ller_dev *pcdev, if (ret < 0) return ret; status->c33_avail_pw_limit =3D ret; + /* PSE core priority start at 0 */ + status->c33_prio =3D buf.data[2] - 1; =20 memset(&buf, 0, sizeof(buf)); msg =3D pd692x0_msg_template_list[PD692X0_MSG_GET_PORT_CLASS]; @@ -731,6 +749,7 @@ static struct pd692x0_msg_ver pd692x0_get_sw_version(st= ruct pd692x0_priv *priv) =20 struct pd692x0_manager { struct device_node *port_node[PD692X0_MAX_MANAGER_PORTS]; + struct device_node *node; int nports; }; =20 @@ -822,6 +841,8 @@ pd692x0_of_get_managers(struct pd692x0_priv *priv, if (ret) goto out; =20 + of_node_get(node); + manager[manager_id].node =3D node; nmanagers++; } =20 @@ -834,6 +855,8 @@ pd692x0_of_get_managers(struct pd692x0_priv *priv, of_node_put(manager[i].port_node[j]); manager[i].port_node[j] =3D NULL; } + of_node_put(manager[i].node); + manager[i].node =3D NULL; } =20 of_node_put(node); @@ -841,6 +864,130 @@ pd692x0_of_get_managers(struct pd692x0_priv *priv, return ret; } =20 +static const struct regulator_ops dummy_ops; + +static struct regulator_dev * +pd692x0_register_manager_regulator(struct device *dev, char *reg_name, + struct device_node *node) +{ + struct regulator_init_data *rinit_data; + struct regulator_config rconfig =3D {0}; + struct regulator_desc *rdesc; + struct regulator_dev *rdev; + + rinit_data =3D devm_kzalloc(dev, sizeof(*rinit_data), + GFP_KERNEL); + if (!rinit_data) + return ERR_PTR(-ENOMEM); + + rdesc =3D devm_kzalloc(dev, sizeof(*rdesc), GFP_KERNEL); + if (!rdesc) + return ERR_PTR(-ENOMEM); + + rdesc->name =3D reg_name; + rdesc->type =3D REGULATOR_VOLTAGE; + rdesc->ops =3D &dummy_ops; + rdesc->owner =3D THIS_MODULE; + + rinit_data->supply_regulator =3D "vmain"; + + rconfig.dev =3D dev; + rconfig.init_data =3D rinit_data; + rconfig.of_node =3D node; + + rdev =3D devm_regulator_register(dev, rdesc, &rconfig); + if (IS_ERR(rdev)) { + dev_err_probe(dev, PTR_ERR(rdev), + "Failed to register regulator\n"); + return rdev; + } + + return rdev; +} + +static int +pd692x0_register_managers_regulator(struct pd692x0_priv *priv, + const struct pd692x0_manager *manager, + int nmanagers) +{ + struct device *dev =3D &priv->client->dev; + size_t reg_name_len; + int i; + + /* Each regulator name len is dev name + 12 char + + * int max digit number (10) + 1 + */ + reg_name_len =3D strlen(dev_name(dev)) + 23; + + for (i =3D 0; i < nmanagers; i++) { + struct regulator_dev *rdev; + char *reg_name; + + reg_name =3D devm_kzalloc(dev, reg_name_len, GFP_KERNEL); + if (!reg_name) + return -ENOMEM; + snprintf(reg_name, 26, "pse-%s-manager%d", dev_name(dev), i); + rdev =3D pd692x0_register_manager_regulator(dev, reg_name, + manager[i].node); + if (IS_ERR(rdev)) + return PTR_ERR(rdev); + + priv->manager_reg[i] =3D rdev; + } + + return 0; +} + +static int +pd692x0_conf_manager_power_budget(struct pd692x0_priv *priv, int id, int p= w) +{ + struct pd692x0_msg msg, buf; + int ret, pw_mW =3D pw / 1000; + + msg =3D pd692x0_msg_template_list[PD692X0_MSG_GET_POWER_BANK]; + msg.data[0] =3D id; + ret =3D pd692x0_sendrecv_msg(priv, &msg, &buf); + if (ret < 0) + return ret; + + msg =3D pd692x0_msg_template_list[PD692X0_MSG_SET_POWER_BANK]; + msg.data[0] =3D id; + msg.data[1] =3D pw_mW >> 8; + msg.data[2] =3D pw_mW & 0xff; + msg.data[3] =3D buf.sub[2]; + msg.data[4] =3D buf.data[0]; + msg.data[5] =3D buf.data[1]; + msg.data[6] =3D buf.data[2]; + msg.data[7] =3D buf.data[3]; + return pd692x0_sendrecv_msg(priv, &msg, &buf); +} + +static int +pd692x0_configure_managers(struct pd692x0_priv *priv, int nmanagers) +{ + int i, ret; + + for (i =3D 0; i < nmanagers; i++) { + struct regulator *supply =3D priv->manager_reg[i]->supply; + int pw_budget; + + pw_budget =3D regulator_get_power_budget(supply); + /* Max power budget per manager */ + if (pw_budget > 6000000) + pw_budget =3D 6000000; + ret =3D regulator_request_power_budget(supply, pw_budget); + if (ret < 0) + return ret; + + priv->manager_pw_budget[i] =3D pw_budget; + ret =3D pd692x0_conf_manager_power_budget(priv, i, pw_budget); + if (ret < 0) + return ret; + } + + return 0; +} + static int pd692x0_set_port_matrix(const struct pse_pi_pairset *pairset, const struct pd692x0_manager *manager, @@ -963,6 +1110,14 @@ static int pd692x0_setup_pi_matrix(struct pse_control= ler_dev *pcdev) return ret; =20 nmanagers =3D ret; + ret =3D pd692x0_register_managers_regulator(priv, manager, nmanagers); + if (ret) + goto out; + + ret =3D pd692x0_configure_managers(priv, nmanagers); + if (ret) + goto out; + ret =3D pd692x0_set_ports_matrix(priv, manager, nmanagers, port_matrix); if (ret) goto out; @@ -973,8 +1128,14 @@ static int pd692x0_setup_pi_matrix(struct pse_control= ler_dev *pcdev) =20 out: for (i =3D 0; i < nmanagers; i++) { + struct regulator *supply =3D priv->manager_reg[i]->supply; + + regulator_free_power_budget(supply, + priv->manager_pw_budget[i]); + for (j =3D 0; j < manager[i].nports; j++) of_node_put(manager[i].port_node[j]); + of_node_put(manager[i].node); } return ret; } @@ -1061,6 +1222,25 @@ static int pd692x0_pi_set_current_limit(struct pse_c= ontroller_dev *pcdev, return pd692x0_sendrecv_msg(priv, &msg, &buf); } =20 +static int pd692x0_pi_set_prio(struct pse_controller_dev *pcdev, int id, + unsigned int prio) +{ + struct pd692x0_priv *priv =3D to_pd692x0_priv(pcdev); + struct pd692x0_msg msg, buf =3D {0}; + int ret; + + ret =3D pd692x0_fw_unavailable(priv); + if (ret) + return ret; + + msg =3D pd692x0_msg_template_list[PD692X0_MSG_SET_PORT_PARAM]; + msg.sub[2] =3D id; + /* Controller priority from 1 to 3 */ + msg.data[4] =3D prio + 1; + + return pd692x0_sendrecv_msg(priv, &msg, &buf); +} + static const struct pse_controller_ops pd692x0_ops =3D { .setup_pi_matrix =3D pd692x0_setup_pi_matrix, .ethtool_get_status =3D pd692x0_ethtool_get_status, @@ -1070,6 +1250,7 @@ static const struct pse_controller_ops pd692x0_ops = =3D { .pi_get_voltage =3D pd692x0_pi_get_voltage, .pi_get_current_limit =3D pd692x0_pi_get_current_limit, .pi_set_current_limit =3D pd692x0_pi_set_current_limit, + .pi_set_prio =3D pd692x0_pi_set_prio, }; =20 #define PD692X0_FW_LINE_MAX_SZ 0xff @@ -1486,6 +1667,8 @@ static int pd692x0_i2c_probe(struct i2c_client *clien= t) priv->pcdev.ops =3D &pd692x0_ops; priv->pcdev.dev =3D dev; priv->pcdev.types =3D ETHTOOL_PSE_C33; + priv->pcdev.port_prio_supp_modes =3D ETHTOOL_PSE_PORT_PRIO_DYNAMIC; + priv->pcdev.pis_prio_max =3D 2; ret =3D devm_pse_controller_register(dev, &priv->pcdev); if (ret) return dev_err_probe(dev, ret, --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94ED51E2820; Thu, 21 Nov 2024 14:44:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200280; cv=none; b=imd9HlbHncvJnIYuhiFsBrGNiAiywS5gBhAFSng7It4Uftvu7preAutu9PKANrSwi/i2EEStlfQP+fhNwvv+G/Ys5zXUtmL70GmiN5u5zn6d9XgD0ZPYF2fze2BR3IaFk0XCTDkM6FJWRIqGfJ1DpVyrQ6ZiDgHPe4in/Gzm/tA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200280; c=relaxed/simple; bh=8sobjCFBFsT9+xz8+Z2UWonKTJ0mO4ZVu0JHkUEE4Bk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=azUh4qeYOzCul87eIpD+px+kdC+9x0pWvj3jqXrKLtMhBfZBccP8L06Np8e/8cSjoFg+X7hRF6SESGxlLtKgOn6FoeiutuUUZ/5pHUjPrziaZF+SzZnoB6hMlF7WJO8jKSTn5BRipUGySq5f7dIPWHSYW+Mnli5AcEfRnfwfCTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=pJ6nxZg0; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="pJ6nxZg0" Received: by mail.gandi.net (Postfix) with ESMTPSA id 5588D40003; Thu, 21 Nov 2024 14:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200276; 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=2EYD2bXtQk97J4lHluWo/28Vyaff+Wh4G3DPULHC/tI=; b=pJ6nxZg0cp7GyOYCB1QGV2TOze1sEmZCXPdYldOLTlNuUe51DrWxiSXRF240RkODN+plN8 /I9CQBBo8NvPObSWtyYMmYz+4N5UKkXXfXDOhZtJ0cvYmGheTiwFI9L2SbgUhXyjZuEthA RVG2405bJSpia5iB9GC+1SSVrkrXmY6KIxgM/e+GSd6znRQ5Ehy6n5yITuYRmgVd8EiNKX TkJkRf1Q8h/dSpfrMKaXquDN5tSWQ+0mxSH7hHxmDrAr+uOhdFaTsBu5yHU5NOiEyqZOHV WrrVFdpLVmBD4anRH5nL+773UATJYyQ0Q+4pm5Y0drOXBDsGDXZrC6AQcm/MlA== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:51 +0100 Subject: [PATCH RFC net-next v3 25/27] dt-bindings: net: pse-pd: microchip,pd692x0: Add manager regulator supply Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-25-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) This patch adds the regulator supply parameter of the managers. It updates also the example as the regulator supply of the PSE PIs should be the managers itself and not an external regulator. Signed-off-by: Kory Maincent --- Changes in v3: - New patch --- .../devicetree/bindings/net/pse-pd/microchip,pd692x0.yaml | 12 ++++++++= ---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/net/pse-pd/microchip,pd692x0= .yaml b/Documentation/devicetree/bindings/net/pse-pd/microchip,pd692x0.yaml index fd4244fceced..0dc0da32576b 100644 --- a/Documentation/devicetree/bindings/net/pse-pd/microchip,pd692x0.yaml +++ b/Documentation/devicetree/bindings/net/pse-pd/microchip,pd692x0.yaml @@ -68,6 +68,9 @@ properties: "#size-cells": const: 0 =20 + vmain-supply: + description: Regulator power supply for the PD69208X manager. + patternProperties: '^port@[0-7]$': type: object @@ -106,10 +109,11 @@ examples: #address-cells =3D <1>; #size-cells =3D <0>; =20 - manager@0 { + manager0: manager@0 { reg =3D <0>; #address-cells =3D <1>; #size-cells =3D <0>; + vmain-supply =3D <&pse1_supply>; =20 phys0: port@0 { reg =3D <0>; @@ -128,7 +132,7 @@ examples: }; }; =20 - manager@1 { + manager1: manager@1 { reg =3D <1>; #address-cells =3D <1>; #size-cells =3D <0>; @@ -161,7 +165,7 @@ examples: pairset-names =3D "alternative-a", "alternative-b"; pairsets =3D <&phys0>, <&phys1>; polarity-supported =3D "MDI", "S"; - vpwr-supply =3D <&vpwr1>; + vpwr-supply =3D <&manager0>; }; pse_pi1: pse-pi@1 { reg =3D <1>; @@ -169,7 +173,7 @@ examples: pairset-names =3D "alternative-a"; pairsets =3D <&phys2>; polarity-supported =3D "MDI"; - vpwr-supply =3D <&vpwr2>; + vpwr-supply =3D <&manager0>; }; }; }; --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95D4A1E284B; Thu, 21 Nov 2024 14:44:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200284; cv=none; b=cx/o6K/BY0geBk8sUft8l3PeHeMHBh5UTUIgvrN1gjajg3AVOrbVVE62PBy7SLKfuoP0mta41JSOEu++jMXg4Zm2/0TYQA7Q41V5/ZT+R0otB1V91V0IUyVL8d1najl621Riba0hMn808/J5AFoOOwdNNhh8fUovRQ6cMkhL7XE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200284; c=relaxed/simple; bh=v5J+08NmArma6dpVpg7cLAzvIs/ri2nCEqzIMUR01Us=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Cve6J3xoblH2ndXAfCp9GFz7kyIjDqh3ZD8HV915FIgy6H9lONl3nmHQfVQImO9mgqCBrv6nN+m0nGIM2kDSmXlfizib4/NLVgNPqhTm22ja9DguHz7de260bdis7nK3eIK7KF6lPo3Bz0DUhF3jLLFuvCvW+iDrZaD2NUKI/vs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Agql/hyI; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Agql/hyI" Received: by mail.gandi.net (Postfix) with ESMTPSA id 1B2AB4000C; Thu, 21 Nov 2024 14:44:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200280; 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=Bp8/QWFlegjnCbGdXZycjaz1LZVfDVH9JsjekA21Oek=; b=Agql/hyImLGy5UmyugslsKGl/AimG2y4gL+/NaM0z1hc9G+gYZ/PCXWhIOI8BaaYnhGy5z 8OClCK41XV8IhMSXsklIHIhttPJOMHVgYv34idieRJaABRow6ZI9huFXIUmhrE6Nf+rzXh tYe0Wq7RC9WfULCC487qRs0SAkco3a9XCNJkNHkhyfOqt2GaLOiWX94y4601GQCyXYYtPd 4QbDiwYVgyne0ba8ptdGYRRzJmPliIDpc2vcyMJSdLb5f1F2/KBpj/3PvK22UyQZMQMK4l DEqCy0jiPOzQzHYI5Y1U9ZI4LPzr96kqbPN1NKZsyjnHuSKZuZDJEizoIZUWeA== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:52 +0100 Subject: [PATCH RFC net-next v3 26/27] net: pse-pd: tps23881: Add support for static port priority feature Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-26-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) This patch enhances PSE callbacks by introducing support for the static port priority feature. It extends interrupt management to handle and report detection, classification, and disconnection events. Additionally, it introduces the pi_get_pw_req() callback, which provides information about the power requested by the Powered Devices. Interrupt support is essential for the proper functioning of the TPS23881 controller. Without it, after a power-on (PWON), the controller will no longer perform detection and classification. This could lead to potential hazards, such as connecting a non-PoE device after a PoE device, which might result in magic smoke. Signed-off-by: Kory Maincent --- We may need a fix for the interrupt support in old version of Linux. Change in v3: - New patch --- drivers/net/pse-pd/tps23881.c | 197 ++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 188 insertions(+), 9 deletions(-) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index 6fe8f150231f..49757e141990 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -19,20 +19,30 @@ =20 #define TPS23881_REG_IT 0x0 #define TPS23881_REG_IT_MASK 0x1 +#define TPS23881_REG_IT_DISF BIT(2) +#define TPS23881_REG_IT_DETC BIT(3) +#define TPS23881_REG_IT_CLASC BIT(4) #define TPS23881_REG_IT_IFAULT BIT(5) #define TPS23881_REG_IT_SUPF BIT(7) +#define TPS23881_REG_DET_EVENT 0x5 #define TPS23881_REG_FAULT 0x7 #define TPS23881_REG_SUPF_EVENT 0xb #define TPS23881_REG_TSD BIT(7) +#define TPS23881_REG_DISC 0xc #define TPS23881_REG_PW_STATUS 0x10 #define TPS23881_REG_OP_MODE 0x12 +#define TPS23881_REG_DISC_EN 0x13 #define TPS23881_OP_MODE_SEMIAUTO 0xaaaa #define TPS23881_REG_DIS_EN 0x13 #define TPS23881_REG_DET_CLA_EN 0x14 #define TPS23881_REG_GEN_MASK 0x17 +#define TPS23881_REG_CLCHE BIT(2) +#define TPS23881_REG_DECHE BIT(3) #define TPS23881_REG_NBITACC BIT(5) #define TPS23881_REG_INTEN BIT(7) #define TPS23881_REG_PW_EN 0x19 +#define TPS23881_REG_RESET 0x1a +#define TPS23881_REG_CLRAIN BIT(7) #define TPS23881_REG_2PAIR_POL1 0x1e #define TPS23881_REG_PORT_MAP 0x26 #define TPS23881_REG_PORT_POWER 0x29 @@ -189,6 +199,17 @@ static int tps23881_pi_enable(struct pse_controller_de= v *pcdev, int id) if (ret) return ret; =20 + /* Enable DC disconnect*/ + chan =3D priv->port[id].chan[0]; + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_DISC_EN); + if (ret < 0) + return ret; + + val =3D tps23881_set_val(ret, chan, 0, BIT(chan % 4), BIT(chan % 4)); + ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_DISC_EN, val); + if (ret) + return ret; + return 0; } =20 @@ -226,6 +247,17 @@ static int tps23881_pi_disable(struct pse_controller_d= ev *pcdev, int id) */ mdelay(5); =20 + /* Disable DC disconnect*/ + chan =3D priv->port[id].chan[0]; + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_DISC_EN); + if (ret < 0) + return ret; + + val =3D tps23881_set_val(ret, chan, 0, 0, BIT(chan % 4)); + ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_DISC_EN, val); + if (ret) + return ret; + /* Enable detection and classification */ ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_DET_CLA_EN); if (ret < 0) @@ -1002,6 +1034,47 @@ static int tps23881_pi_set_current_limit(struct pse_= controller_dev *pcdev, return 0; } =20 +static int tps23881_power_class_table[] =3D { + -ERANGE, + 4000, + 7000, + 15500, + 30000, + 15500, + 15500, + -ERANGE, + 45000, + 60000, + 75000, + 90000, + 15500, + 45000, + -ERANGE, + -ERANGE, +}; + +static int tps23881_pi_get_pw_req(struct pse_controller_dev *pcdev, int id) +{ + struct tps23881_priv *priv =3D to_tps23881_priv(pcdev); + struct i2c_client *client =3D priv->client; + u8 reg, chan; + int ret; + u16 val; + + /* For a 4-pair the classification need 5ms to be completed */ + if (priv->port[id].is_4p) + mdelay(5); + + chan =3D priv->port[id].chan[0]; + reg =3D TPS23881_REG_DISC + (chan % 4); + ret =3D i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + val =3D tps23881_calc_val(ret, chan, 4, 0xf); + return tps23881_power_class_table[val]; +} + static const struct pse_controller_ops tps23881_ops =3D { .setup_pi_matrix =3D tps23881_setup_pi_matrix, .pi_enable =3D tps23881_pi_enable, @@ -1011,6 +1084,7 @@ static const struct pse_controller_ops tps23881_ops = =3D { .pi_get_voltage =3D tps23881_pi_get_voltage, .pi_get_current_limit =3D tps23881_pi_get_current_limit, .pi_set_current_limit =3D tps23881_pi_set_current_limit, + .pi_get_pw_req =3D tps23881_pi_get_pw_req, }; =20 static const char fw_parity_name[] =3D "ti/tps23881/tps23881-parity-14.bin= "; @@ -1181,12 +1255,83 @@ static void tps23881_irq_event_over_current(struct = tps23881_priv *priv, ETHTOOL_PSE_EVENT_OVER_CURRENT); } =20 +static void tps23881_irq_event_disconnection(struct tps23881_priv *priv, + u16 reg_val, + unsigned long *notifs, + unsigned long *notifs_mask) +{ + u8 chans; + + chans =3D tps23881_it_export_chans_helper(reg_val, 4); + if (chans) + tps23881_set_notifs_helper(priv, chans, notifs, notifs_mask, + ETHTOOL_C33_PSE_EVENT_DISCONNECTION); +} + +static int tps23881_irq_event_detection(struct tps23881_priv *priv, + u16 reg_val, + unsigned long *notifs, + unsigned long *notifs_mask) +{ + enum ethtool_pse_events event; + int reg, ret, i, val; + u8 chans; + + chans =3D tps23881_it_export_chans_helper(reg_val, 0); + for_each_set_bit(i, (unsigned long *)&chans, TPS23881_MAX_CHANS) { + reg =3D TPS23881_REG_DISC + (i % 4); + ret =3D i2c_smbus_read_word_data(priv->client, reg); + if (ret < 0) + return ret; + + val =3D tps23881_calc_val(ret, i, 0, 0xf); + /* If detection valid */ + if (val =3D=3D 0x4) + event =3D ETHTOOL_C33_PSE_EVENT_DETECTION; + else + event =3D ETHTOOL_C33_PSE_EVENT_DISCONNECTION; + + tps23881_set_notifs_helper(priv, BIT(i), notifs, + notifs_mask, event); + } + + return 0; +} + +static int tps23881_irq_event_classification(struct tps23881_priv *priv, + u16 reg_val, + unsigned long *notifs, + unsigned long *notifs_mask) +{ + int reg, ret, val, i; + u8 chans; + + chans =3D tps23881_it_export_chans_helper(reg_val, 4); + for_each_set_bit(i, (unsigned long *)&chans, TPS23881_MAX_CHANS) { + reg =3D TPS23881_REG_DISC + (i % 4); + ret =3D i2c_smbus_read_word_data(priv->client, reg); + if (ret < 0) + return ret; + + val =3D tps23881_calc_val(ret, i, 4, 0xf); + /* Do not report classification event for unknown class */ + if (!val || val =3D=3D 0x8 || val =3D=3D 0xf) + continue; + + tps23881_set_notifs_helper(priv, BIT(i), notifs, + notifs_mask, + ETHTOOL_C33_PSE_EVENT_CLASSIFICATION); + } + + return 0; +} + static int tps23881_irq_event_handler(struct tps23881_priv *priv, u16 reg, unsigned long *notifs, unsigned long *notifs_mask) { struct i2c_client *client =3D priv->client; - int ret; + int ret, val; =20 /* The Supply event bit is repeated twice so we only need to read * the one from the first byte. @@ -1198,13 +1343,33 @@ static int tps23881_irq_event_handler(struct tps238= 81_priv *priv, u16 reg, tps23881_irq_event_over_temp(priv, ret, notifs, notifs_mask); } =20 - if (reg & (TPS23881_REG_IT_IFAULT | TPS23881_REG_IT_IFAULT << 8)) { + if (reg & (TPS23881_REG_IT_IFAULT | TPS23881_REG_IT_IFAULT << 8 | + TPS23881_REG_IT_DISF | TPS23881_REG_IT_DISF << 8)) { ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_FAULT); if (ret < 0) return ret; tps23881_irq_event_over_current(priv, ret, notifs, notifs_mask); + + tps23881_irq_event_disconnection(priv, ret, notifs, notifs_mask); } =20 + if (reg & (TPS23881_REG_IT_DETC | TPS23881_REG_IT_DETC << 8 | + TPS23881_REG_IT_CLASC | TPS23881_REG_IT_CLASC << 8)) { + ret =3D i2c_smbus_read_word_data(client, TPS23881_REG_DET_EVENT); + if (ret < 0) + return ret; + + val =3D ret; + ret =3D tps23881_irq_event_detection(priv, val, notifs, + notifs_mask); + if (ret) + return ret; + + ret =3D tps23881_irq_event_classification(priv, val, notifs, + notifs_mask); + if (ret) + return ret; + } return 0; } =20 @@ -1250,7 +1415,14 @@ static int tps23881_setup_irq(struct tps23881_priv *= priv, int irq) int ret; u16 val; =20 - val =3D TPS23881_REG_IT_IFAULT | TPS23881_REG_IT_SUPF; + if (!irq) { + dev_err(&client->dev, "interrupt is missing"); + return -EINVAL; + } + + val =3D TPS23881_REG_IT_IFAULT | TPS23881_REG_IT_SUPF | + TPS23881_REG_IT_DETC | TPS23881_REG_IT_CLASC | + TPS23881_REG_IT_DISF; val |=3D val << 8; ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_IT_MASK, val); if (ret) @@ -1260,11 +1432,19 @@ static int tps23881_setup_irq(struct tps23881_priv = *priv, int irq) if (ret < 0) return ret; =20 - val =3D (u16)(ret | TPS23881_REG_INTEN | TPS23881_REG_INTEN << 8); + val =3D TPS23881_REG_INTEN | TPS23881_REG_CLCHE | TPS23881_REG_DECHE; + val |=3D val << 8; + val |=3D (u16)ret; ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_GEN_MASK, val); if (ret < 0) return ret; =20 + /* Reset interrupts registers */ + ret =3D i2c_smbus_write_word_data(client, TPS23881_REG_RESET, + TPS23881_REG_CLRAIN); + if (ret < 0) + return ret; + return devm_pse_irq_helper(&priv->pcdev, irq, 0, &irq_desc); } =20 @@ -1342,17 +1522,16 @@ static int tps23881_i2c_probe(struct i2c_client *cl= ient) priv->pcdev.dev =3D dev; priv->pcdev.types =3D ETHTOOL_PSE_C33; priv->pcdev.nr_lines =3D TPS23881_MAX_CHANS; + priv->pcdev.port_prio_supp_modes =3D ETHTOOL_PSE_PORT_PRIO_STATIC; ret =3D devm_pse_controller_register(dev, &priv->pcdev); if (ret) { return dev_err_probe(dev, ret, "failed to register PSE controller\n"); } =20 - if (client->irq) { - ret =3D tps23881_setup_irq(priv, client->irq); - if (ret) - return ret; - } + ret =3D tps23881_setup_irq(priv, client->irq); + if (ret) + return ret; =20 return ret; } --=20 2.34.1 From nobody Sun Nov 24 05:09:00 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B04FC1E32B8; Thu, 21 Nov 2024 14:44:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200286; cv=none; b=oIZjAIvBwmRBGtxN4vhy2QnUXMBZ16Fd6Gti8WmYeO3V6CxE2wprKDDyW+/B04vk3grsdO58ODu1dI8wb3PkgDEmjALWEYkpFJE7+btskf/1OZBaPEp+ItjDeFjf9xtlygCo5Y4dtrbMOwm9/42CZ+9igxCDFWpboJG1gf381hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200286; c=relaxed/simple; bh=FSkXv1pEsc86xlSs+uKmP+IRGAKuUeBV0ielPAvM/68=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PsL9aXMYEpJ/NKcSiSBvMq/vC7tRPSYnBVSa9NjGryX9zBFQXmNpbRlV9qK/Mg/nrZUmeu+qzJidUqUIuLhoJwDffX7hwrGVEM1o0XZ/sOmgL/NcBmlqjeLbEsPz+UT4qevNPTbqKB7kBe+bZK5hpFZAW8nQFX5YGS0odHx2jzg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Hp64aSHI; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Hp64aSHI" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4CF7140009; Thu, 21 Nov 2024 14:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200283; 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=2CvRQYaUK8EzFLZ0ybAaQ1/a+EAtN4SsfxIocmO3j0U=; b=Hp64aSHI2mGUiaYZk5ZdDk7RKmT7XJMh98IgzYaYJTEc0U7Gx/XtK3Rz1GlH/F0zEW1UTL G+sA3+znMcF8I8lgdBUtzqiLAB/ElvSstmVGobgWH4oWBI+kfSswAnpc+dRRB0C+7I89++ cEM1yZYaMAV9Mw4XT0hgCvEBMzwsnpVN6Qjsrfxr1P2XhCGCGO8M9jTqAlQTgCycSkpMUv 1n3u/R+M8DTFh9WPsRAXxF2CyWBR3CN+4qYguPEthDDK7kg9W7r8MeklIzK0p85FnUPoYB sFD9F0FnWTxpOW7938ZakXllbmLbVU5ky57x39YRTSbqctw+x2mc5CiWWnMB+w== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:53 +0100 Subject: [PATCH RFC net-next v3 27/27] dt-bindings: net: pse-pd: ti,tps23881: Add interrupt description Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-27-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Add an interrupt property to the device tree bindings for the TI TPS23881 PSE controller. The interrupt is primarily used to detect classification and disconnection events, which are essential for managing the PSE controller in compliance with the PoE standard. Signed-off-by: Kory Maincent --- Change in v3: - New patch --- Documentation/devicetree/bindings/net/pse-pd/ti,tps23881.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/net/pse-pd/ti,tps23881.yaml = b/Documentation/devicetree/bindings/net/pse-pd/ti,tps23881.yaml index d08abcb01211..19d25ded4e58 100644 --- a/Documentation/devicetree/bindings/net/pse-pd/ti,tps23881.yaml +++ b/Documentation/devicetree/bindings/net/pse-pd/ti,tps23881.yaml @@ -20,6 +20,9 @@ properties: reg: maxItems: 1 =20 + interrupts: + maxItems: 1 + '#pse-cells': const: 1 =20 @@ -62,6 +65,7 @@ unevaluatedProperties: false required: - compatible - reg + - interrupts =20 examples: - | @@ -72,6 +76,8 @@ examples: ethernet-pse@20 { compatible =3D "ti,tps23881"; reg =3D <0x20>; + interrupts =3D <8 0>; + interrupt-parent =3D <&gpiog>; =20 channels { #address-cells =3D <1>; --=20 2.34.1