From patchwork Wed Oct 2 16:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820052 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 677661D0E12; Wed, 2 Oct 2024 16:29:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886550; cv=none; b=kf1SRwKvTvHkcFtqLXgFHYAC7ThxXDYnXdz3vo1rl2ZXWpcLDdjdkhLyZvgfG9s9oabAOzY7hmmSy6ZUFfl+W7yPp84cZFK0AEP314UQllVzsWjr19uhga/GjlehAu61ol3yZcH6OJd+4Icu+tLegwkQAmWA7s9NwdWw7hH+FZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886550; c=relaxed/simple; bh=yqdYmWDPi96O6HF7ebbWScHKYpa6AeAvglvLs6cCSDk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LCLKR4OJJ1bFSYcpVCGevseepVfrKUsNlVMh/sKsB60ke4PeWU0Y8ZtzISI9JEB3s1gPsO1+/gFmRYGgWTayetGqWH9dJds1323jKtjeW8eMJ5H/SyiSHctm5GM4Oxpl45kuEDpcYbXCX3dEWYSZL650R4BW5Cdmb6WE/unoTYw= 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=bi6SBDSk; arc=none smtp.client-ip=217.70.183.201 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="bi6SBDSk" Received: by mail.gandi.net (Postfix) with ESMTPSA id 103421BF207; Wed, 2 Oct 2024 16:29:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886546; 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=kmgCX7Kwi/ErDtCadQPfPVZMgNr8nBIPVozcbt2OctU=; b=bi6SBDSktJJ3iNepc/zdDpDY/ZSwcYj/JsfdMJWSkQ776FDpd9emiE9ECcATgIT7f+Aish dyiGNKP5Sz2JFPXpR4Zjvl8ruT+HhR8JXpKcpXGG35aMr6qEzK+je0trW1VQUVmmmngjRj 2uzjLbbXKbgfBkM78ZfNwPJH5xkhBtzUovOSQq+t2TUuQnP5/MM9uRm6NBy44URbypl1q5 ZBoTiSbgZmciaQeQpYcLr01tZ+/+mYX45CGZfSCuIZ1mMp9W+LK2AV8H1dCGvXyQzz3APV sDxRwokM14OBhByMlvnbBQCbCNC4UNeCJt8280d80s4/3Ptld/hNz3jRAHQGxQ== From: Kory Maincent Date: Wed, 02 Oct 2024 18:27:57 +0200 Subject: [PATCH net-next 01/12] net: pse-pd: Remove unused pse_ethtool_get_pw_limit function declaration Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-1-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org 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. Signed-off-by: Kory Maincent Reviewed-by: Andrew Lunn Reviewed-by: Kalesh AP Acked-by: Oleksij Rempel --- 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); 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; } -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; From patchwork Wed Oct 2 16:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820053 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 3663B567D; Wed, 2 Oct 2024 16:29:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886551; cv=none; b=im4ltXp8R7RlMi4YqNOxRoW8b4Nmm06fJZNeQ1wCPbeous2cnN9I4wVr53UaD5Sf+pWGo6T45BN6HXSLOz0RshOLzvlacxYW1kn6F6fwGf+NjmugNT8otRQpb6z+N8MdZRS2qbnOqaZu4GL7nNoIRF75gn34sMloBEzxLVs392U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886551; c=relaxed/simple; bh=FdyIlP5QbAoJSErExFHqxvHzcDD2538/OXE26emypME=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Udb8VoZyV3N/pNcVOr8FT1ov0Br/pHblUY+wKxwx9a7C3mT28QFuri5EWSF0KNsqpgMp4g5rjF4hnC6XvpKpLzKCwKYqgvUaXar9+dbLVlN0qlfgAJRsHNhHIgjsxG+vMxUj1620HfIQN4K6HIRTNa1+W7y19rKZ6a7O7xAxauM= 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=ZbI5plEk; arc=none smtp.client-ip=217.70.183.201 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="ZbI5plEk" Received: by mail.gandi.net (Postfix) with ESMTPSA id C167F1BF209; Wed, 2 Oct 2024 16:29:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886547; 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=Ro47lYTPlToHjrMRk1db8NcTTZn4FWYXgojohtwvs0E=; b=ZbI5plEk+PFgezSJr60mckUjxT7KeGbgQcqG7OlR4FYkhAh8iaAuB3qMnbX1tsKQoB/5/v jESKCdgmLeukCiUkkw6X6/dBs37V1U0LS10XKvfoablOT5zqTqjcNRYeKc/KGWpEt5AjQF fietJNA2SdFnX0SqeiWLqKg+bx2djpDqIrRSdsZOJdpXNfmB7En+xlg0rFFjbbC3uXt0VI sQbFiKhCd8ckdvX9PuClaUSSezkHy2r+2mXE65GbDJw+PViSoPnq9fQSayeQDLUWJQyD7U XQoZpZDqDVwLjVqs9ncCI+cNbX96Ui2gVoQlxNyNWDECltbY3cW0WVY6jlMasQ== From: Kory Maincent Date: Wed, 02 Oct 2024 18:27:58 +0200 Subject: [PATCH net-next 02/12] net: pse-pd: tps23881: Correct boolean evaluation for bitmask checks Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-2-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org From: Kory Maincent (Dent Project) Update misleading boolean evaluation when checking bitmask values. The existing code directly assigned the result of bitwise operations to a boolean variable, which is not consistent with later assignments. This has been corrected by explicitly converting the bitmask results to boolean using the !! operator, ensuring proper code consistency Acked-by: Oleksij Rempel Signed-off-by: Kory Maincent --- drivers/net/pse-pd/tps23881.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index 5c4e88be46ee..1a57c55f8577 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -139,9 +139,9 @@ static int tps23881_pi_is_enabled(struct pse_controller_dev *pcdev, int id) chan = priv->port[id].chan[0]; if (chan < 4) - enabled = ret & BIT(chan); + enabled = !!(ret & BIT(chan)); else - enabled = ret & BIT(chan + 4); + enabled = !!(ret & BIT(chan + 4)); if (priv->port[id].is_4p) { chan = priv->port[id].chan[1]; @@ -172,11 +172,11 @@ static int tps23881_ethtool_get_status(struct pse_controller_dev *pcdev, chan = priv->port[id].chan[0]; if (chan < 4) { - enabled = ret & BIT(chan); - delivering = ret & BIT(chan + 4); + enabled = !!(ret & BIT(chan)); + delivering = !!(ret & BIT(chan + 4)); } else { - enabled = ret & BIT(chan + 4); - delivering = ret & BIT(chan + 8); + enabled = !!(ret & BIT(chan + 4)); + delivering = !!(ret & BIT(chan + 8)); } if (priv->port[id].is_4p) { From patchwork Wed Oct 2 16:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820054 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 C23BF1D0E1F; Wed, 2 Oct 2024 16:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886551; cv=none; b=enFEnNPH1kLzE6yxgCy4AK0LUnNW5Dq7oDGImAfZkwasvdUCLOgK+dt+eKByxIUKj+Koi6FJrKLZXiuymzrDwvVi1UzZHwTtoW4AEiqy3FXKY9shrjUU/V3HXWjksopsLBJfqvBAi/VAmmpPhS32q2csIaIw4njfjcp6euHtD6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886551; c=relaxed/simple; bh=OV/RdTYEnlbC3pry5KNHKsetn+/sjren2tP879uTa5Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z3Vh9gxwiDm1uVkssOsCdAnGeY0m4RjbykaU8Ig6F/TB5mNOExy5/pMKwnIzebfrG5Di2Pv50UOy6ZIQPPW+J0GL2Z9gdwiNJskZ6nS+qouQ0EMC6gDWdDxSNr7cTHCUr8dbBWytkS3GrGmRM+y/cSnjTZEQsuVlDLZqXsXjA6k= 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=N1MrWj6h; arc=none smtp.client-ip=217.70.183.201 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="N1MrWj6h" Received: by mail.gandi.net (Postfix) with ESMTPSA id 80D4D1BF208; Wed, 2 Oct 2024 16:29:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886548; 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=5ePH3amKbdbo1+SFMAbJyxHZ4YiapYq55nJZg7ttGFg=; b=N1MrWj6h9qj41DipZkRoo/OFRgxNbvpAKvmI+Rk10vHGl/kyto16dFcEU7lsG1kJ4/5jed IXrwjKzHbOayIS28cqUJ3n4If9flEKJarXRh0OMHeVa0H7F/v7ihKulR3v5Rj/zwlcAxmx PM8nnK43TyQghVWTww4D/AXYZzIVCnZhk+WAvI6Ldv1L0xZeok1qgzQ4I+gdR5GyRFoYJU b3ELvqDvRxQmwQS6/FTuA8GhYV0lSGmjkatu+uVk8AytmQWnAqkoBRfwAMLvGIYe8rVLjo y97F63yFCeN6dZAueL5jtQOa7P9K9CZR9sxCLxpsO5DvDbSo+6Tlk21JlrSbcQ== From: Kory Maincent Date: Wed, 02 Oct 2024 18:27:59 +0200 Subject: [PATCH net-next 03/12] net: pse-pd: tps23881: Simplify function returns by removing redundant checks Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-3-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org 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. Signed-off-by: Kory Maincent Reviewed-by: Andrew Lunn Acked-by: Oleksij Rempel --- 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 1a57c55f8577..fdf996f5d1f8 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_dev *pcdev, int id) val |= BIT(chan + 8); } - ret = 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); } 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 = priv->client; u8 pi_id, lgcl_chan, hw_chan; u16 val = 0; - int i, ret; + int i; for (i = 0; i < port_cnt; i++) { pi_id = port_matrix[i].pi_id; @@ -519,11 +515,7 @@ tps23881_write_port_matrix(struct tps23881_priv *priv, } /* Write hardware ports matrix */ - ret = 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); } static int @@ -572,11 +564,7 @@ tps23881_set_ports_conf(struct tps23881_priv *priv, val |= BIT(port_matrix[i].lgcl_chan[1]) | BIT(port_matrix[i].lgcl_chan[1] + 4); } - ret = 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); } static int @@ -602,11 +590,7 @@ tps23881_set_ports_matrix(struct tps23881_priv *priv, if (ret) return ret; - ret = tps23881_set_ports_conf(priv, port_matrix); - if (ret) - return ret; - - return 0; + return tps23881_set_ports_conf(priv, port_matrix); } static int tps23881_setup_pi_matrix(struct pse_controller_dev *pcdev) From patchwork Wed Oct 2 16:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820055 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 609341D0F57; Wed, 2 Oct 2024 16:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886553; cv=none; b=L0qp1F2+0M4zWmXmnTkqcI6iGDdIX5TW62t9uguffxT/DwJZRqv/m0NHhES9KnTo9OSBiPHebDsDqTSfXSuxiPL4pRKSu5rKA/XUmma0Q9Zc3nFGTY5A35/SDUGC96a68rnLiZVAQl0sa8wI9gGGU/JlacerDvJJodKwMmo+250= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886553; c=relaxed/simple; bh=O6dqqwIb8ntWdhD7LBUoy2m5OdXAqUc9w9/iAHs433k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QbgGp93SDDAJ4xkE5MHiWxRBD0vnNDuh+0VH2GKPShf/tExyu9O7S/kxOqqs0MPNm4X/SgWQT3lIend3pKAS2TU+g9E6fuUoLCp2ZnCJeKhEmeVg0DOnpcynjApZWkT0J0B+uh0fN3gcI+WB9kTI3hekF68PHxmKGujZb2ZrqtA= 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=F9UGxuCI; arc=none smtp.client-ip=217.70.183.201 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="F9UGxuCI" Received: by mail.gandi.net (Postfix) with ESMTPSA id 35D4D1BF20B; Wed, 2 Oct 2024 16:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886548; 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=s5rLJXL+Op3mv3qC1Ju68EqXWIew/9aiRguP/DQDY/M=; b=F9UGxuCI/xfLH/VjLKKhYnLrO4qQm1Qsj2mQkH84q/wooPLeYrQzIkcayCuiS6/C/1HpLZ ICF+1s3BecAyZ9mf3vMg0FMG7DGrSpHF6PcD2mLW5kH65S/KC4iWe5Pmiva666IzR5fRPu XUUkaP0AtFVL4ffjBRxVhFdKmAwTJ1buwomOOMoKAAS02EpsbWeSzMeLMJRaPKb2fG7Id7 8KrMyvjr4qlr2RGqTFp9Azfp+UvJ62X7RQr95w4i33K1f3o9cbl2LSGoeFatIGR6ylQpYt 9XlAQgDEeKbcRAJa4D0ArOVTNqJRaPn+dWDfqvF0KwhyTDCg8QrHk0+qdRFQEw== From: Kory Maincent Date: Wed, 02 Oct 2024 18:28:00 +0200 Subject: [PATCH net-next 04/12] net: pse-pd: tps23881: Add support for power limit and measurement features Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-4-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Andrew Lunn Acked-by: Oleksij Rempel --- drivers/net/pse-pd/tps23881.c | 314 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 314 insertions(+) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index fdf996f5d1f8..e05b45cdc9f8 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -25,17 +25,29 @@ #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_4PAIR_POL1 0x2a +#define TPS23881_REG_INPUT_V 0x2e +#define TPS23881_REG_CHAN1_A 0x30 +#define TPS23881_REG_CHAN1_V 0x32 #define TPS23881_REG_POEPLUS 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 +#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 + struct tps23881_port_desc { u8 chan[2]; bool is_4p; @@ -151,6 +163,175 @@ static int tps23881_pi_is_enabled(struct pse_controller_dev *pcdev, int id) return enabled; } +static int tps23881_pi_get_voltage(struct pse_controller_dev *pcdev, int id) +{ + struct tps23881_priv *priv = to_tps23881_priv(pcdev); + struct i2c_client *client = priv->client; + int ret, reg; + u8 chan; + u64 uV; + + /* Read Voltage only at one of the 2-pair ports */ + chan = priv->port[id].chan[0]; + if (chan < 4) + /* Registers 0x32 0x36 0x3a 0x3e */ + reg = TPS23881_REG_CHAN1_V + chan * 4; + else + /* Registers 0x33 0x37 0x3b 0x3f */ + reg = TPS23881_REG_CHAN1_V + 1 + (chan % 4) * 4; + + ret = i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + uV = ret; + uV *= 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 = priv->client; + int reg, ret; + u64 tmp_64; + + if (chan < 4) + /* Registers 0x30 0x34 0x38 0x3c */ + reg = TPS23881_REG_CHAN1_A + chan * 4; + else + /* Registers 0x31 0x35 0x39 0x3d */ + reg = TPS23881_REG_CHAN1_A + 1 + (chan % 4) * 4; + + ret = i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + tmp_64 = ret; + tmp_64 *= TPS23881_NA_STEP; + /* uA = nA / 1000 */ + tmp_64 = 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 = tps23881_pi_get_voltage(&priv->pcdev, id); + if (ret < 0) + return ret; + uV = ret; + + chan = priv->port[id].chan[0]; + ret = tps23881_pi_get_chan_current(priv, chan); + if (ret < 0) + return ret; + uA = ret; + + if (priv->port[id].is_4p) { + chan = priv->port[id].chan[1]; + ret = tps23881_pi_get_chan_current(priv, chan); + if (ret < 0) + return ret; + uA += ret; + } + + tmp_64 = uV; + tmp_64 *= uA; + /* mW = 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 = priv->client; + int ret, reg, mW; + + reg = TPS23881_REG_2PAIR_POL1 + (chan % 4); + ret = i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + if (chan < 4) + mW = (ret & 0xff) * TPS23881_MW_STEP; + else + mW = (ret >> 8) * TPS23881_MW_STEP; + + return mW; +} + +static int tps23881_pi_get_pw_limit(struct tps23881_priv *priv, int id) +{ + int ret, mW; + u8 chan; + + chan = priv->port[id].chan[0]; + ret = tps23881_pi_get_pw_limit_chan(priv, chan); + if (ret < 0) + return ret; + + mW = ret; + if (priv->port[id].is_4p) { + chan = priv->port[id].chan[1]; + ret = tps23881_pi_get_pw_limit_chan(priv, chan); + if (ret < 0) + return ret; + mW += ret; + } + + return mW; +} + +static int tps23881_pi_get_max_pw_limit(struct tps23881_priv *priv, int id) +{ + int ret, uV; + u64 tmp_64; + + ret = tps23881_pi_get_voltage(&priv->pcdev, id); + if (ret < 0) + return ret; + uV = ret; + + tmp_64 = uV; + tmp_64 *= MAX_PI_CURRENT; + /* mW = uV * uA / 1000000000 */ + return DIV_ROUND_CLOSEST_ULL(tmp_64, 1000000000); +} + +static int tps23881_pi_get_class(struct tps23881_priv *priv, int id) +{ + struct i2c_client *client = priv->client; + int ret, reg, class; + u8 chan; + + chan = priv->port[id].chan[0]; + reg = TPS23881_REG_CHAN1_CLASS + (chan % 4); + ret = i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + if (chan < 4) + class = ret >> 4; + else + class = ret >> 12; + + return class; +} + static int tps23881_ethtool_get_status(struct pse_controller_dev *pcdev, unsigned long id, struct netlink_ext_ack *extack, @@ -198,6 +379,35 @@ static int tps23881_ethtool_get_status(struct pse_controller_dev *pcdev, else status->c33_admin_state = ETHTOOL_C33_PSE_ADMIN_STATE_DISABLED; + ret = tps23881_pi_get_power(priv, id); + if (ret < 0) + return ret; + status->c33_actual_pw = ret; + + status->c33_pw_limit_ranges = kzalloc(sizeof(*status->c33_pw_limit_ranges), + GFP_KERNEL); + if (!status->c33_pw_limit_ranges) + return -ENOMEM; + + status->c33_actual_pw = ret; + + ret = tps23881_pi_get_max_pw_limit(priv, id); + if (ret < 0) + return ret; + status->c33_pw_limit_nb_ranges = 1; + status->c33_pw_limit_ranges->min = 2000; + status->c33_pw_limit_ranges->max = ret; + + ret = tps23881_pi_get_pw_limit(priv, id); + if (ret < 0) + return ret; + status->c33_avail_pw_limit = ret; + + ret = tps23881_pi_get_class(priv, id); + if (ret < 0) + return ret; + status->c33_pw_class = ret; + return 0; } @@ -614,12 +824,116 @@ static int tps23881_setup_pi_matrix(struct pse_controller_dev *pcdev) return ret; } +static int tps23881_pi_get_current_limit(struct pse_controller_dev *pcdev, + int id) +{ + struct tps23881_priv *priv = to_tps23881_priv(pcdev); + int ret, mW, uV; + u64 tmp_64; + + ret = tps23881_pi_get_pw_limit(priv, id); + if (ret < 0) + return ret; + mW = ret; + + ret = tps23881_pi_get_voltage(pcdev, id); + if (ret < 0) + return ret; + uV = ret; + + tmp_64 = mW; + tmp_64 *= 1000000000ull; + /* uA = mW * 1000000000 / uV */ + return DIV_ROUND_CLOSEST_ULL(tmp_64, uV); +} + +static int +tps23881_pi_set_2p_pw_limit(struct tps23881_priv *priv, u8 chan, u8 pol) +{ + struct i2c_client *client = priv->client; + int ret, reg; + u16 val; + + reg = TPS23881_REG_2PAIR_POL1 + (chan % 4); + ret = i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + if (chan < 4) + val = (ret & 0xff00) | pol; + else + val = (ret & 0xff) | (pol << 8); + + return i2c_smbus_write_word_data(client, reg, val); +} + +static int +tps23881_pi_set_4p_pw_limit(struct tps23881_priv *priv, u8 chan, u8 pol) +{ + struct i2c_client *client = priv->client; + int ret, reg; + u16 val; + + if ((chan % 4) < 2) + reg = TPS23881_REG_4PAIR_POL1; + else + reg = TPS23881_REG_4PAIR_POL1 + 1; + + ret = i2c_smbus_read_word_data(client, reg); + if (ret < 0) + return ret; + + if (chan < 4) + val = (ret & 0xff00) | pol; + else + val = (ret & 0xff) | (pol << 8); + + return i2c_smbus_write_word_data(client, reg, val); +} + +static int tps23881_pi_set_current_limit(struct pse_controller_dev *pcdev, + int id, int max_uA) +{ + struct tps23881_priv *priv = to_tps23881_priv(pcdev); + u8 chan, pw_pol; + int ret, mW; + u64 tmp_64; + + ret = tps23881_pi_get_voltage(pcdev, id); + if (ret < 0) + return ret; + + tmp_64 = ret; + tmp_64 *= max_uA; + /* mW = uV * uA / 1000000000 */ + mW = DIV_ROUND_CLOSEST_ULL(tmp_64, 1000000000); + pw_pol = DIV_ROUND_CLOSEST_ULL(mW, TPS23881_MW_STEP); + + if (priv->port[id].is_4p) { + chan = priv->port[id].chan[0]; + /* One chan is enough to configure the PI power limit */ + ret = tps23881_pi_set_4p_pw_limit(priv, chan, pw_pol); + if (ret < 0) + return ret; + } else { + chan = priv->port[id].chan[0]; + ret = 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 = { .setup_pi_matrix = tps23881_setup_pi_matrix, .pi_enable = tps23881_pi_enable, .pi_disable = tps23881_pi_disable, .pi_is_enabled = tps23881_pi_is_enabled, .ethtool_get_status = tps23881_ethtool_get_status, + .pi_get_voltage = tps23881_pi_get_voltage, + .pi_get_current_limit = tps23881_pi_get_current_limit, + .pi_set_current_limit = tps23881_pi_set_current_limit, }; static const char fw_parity_name[] = "ti/tps23881/tps23881-parity-14.bin"; From patchwork Wed Oct 2 16:28:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820056 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 391831D12EA; Wed, 2 Oct 2024 16:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886553; cv=none; b=mPJS4/lHwIU6gDlBw1f+nJ8UKTR9jv/ZZ2CHAjtaKWr59+L/COa8/5fB7PpCQy1MVJMnGiVIXaUDvHnDANtdbO7MU7ySEBAZ/V69AotRtnhi7xTHoA/ii/OiwDI1Tp0rFMM/dkNMkRn5hyq/H0hjxuNDDaFeRloSkeYofFotTM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886553; c=relaxed/simple; bh=IAn/aP5J4OooV+vXF/TyTGRcput+ez4+P0gxjzAXSdw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pb7O68TEA+pcFQde+fnbl9J2W7Tl8+TdnlafCE22cwkkLEKbA2UAM6Lby+29pMN0kIHjN/yjWJCTO36exB/dHJQtZe9Y1faDx/G07o966RDbPc6vxag8gjleBtEWiF1tk4Z53r5OUIN7QASWXMUQn/bWOaf1/P1BagNMHMjLQws= 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=Fl2CXcTH; arc=none smtp.client-ip=217.70.183.201 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="Fl2CXcTH" Received: by mail.gandi.net (Postfix) with ESMTPSA id EE0A51BF203; Wed, 2 Oct 2024 16:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886549; 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=iEgsL4qeKQAHgpYyJ07KFlg6HXoQP/UEP7QR/h3wag0=; b=Fl2CXcTHjs8H70SAMoeABIT75NYboULvJwO9UBrKxg9c1QPlYHk1NsmHAtNUwYCe/A8aUI PUieBvY6jebOkxPWxihm17IlrAoUNpjuhAK2Ie/toGJjUpSm81DTNG1+R3UtUjrPqHuqOi rSdU+vmKVfc8G9A4IlsoUXt3xhCKeAfRqqO5BBqa4qDplbs8mleLPwcqN7Y01qVk4xEniW EU/xISAsfCJ4U59SHvzcNogDPzjN4i0R3aBY7ZgecLAaftpUNVRAz+NULCPOOsvjvHMEyl ti3pVEHgWjTn+qJpEHJW4H1oJx5ZNH7mKJ/bO3chXAb1jdYivGwgr305Y9JDzQ== From: Kory Maincent Date: Wed, 02 Oct 2024 18:28:01 +0200 Subject: [PATCH net-next 05/12] net: pse-pd: Add support for getting and setting port priority Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-5-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org 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. Signed-off-by: Kory Maincent Reviewed-by: Andrew Lunn Acked-by: Oleksij Rempel --- drivers/net/pse-pd/pse_core.c | 30 ++++++++++++++++++++++++++++++ include/linux/pse-pd/pse.h | 19 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index f8e6854781e6..6b3893a3381c 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -750,6 +750,7 @@ static int _pse_ethtool_get_status(struct pse_controller_dev *pcdev, return -EOPNOTSUPP; } + status->c33_prio_max = pcdev->pis_prio_max; return ops->ethtool_get_status(pcdev, id, extack, status); } @@ -898,6 +899,35 @@ int pse_ethtool_set_pw_limit(struct pse_control *psec, } EXPORT_SYMBOL_GPL(pse_ethtool_set_pw_limit); +int pse_ethtool_set_prio(struct pse_control *psec, + struct netlink_ext_ack *extack, + unsigned int prio) +{ + const struct pse_controller_ops *ops; + int ret; + + ops = psec->pcdev->ops; + if (!ops->pi_set_prio) { + NL_SET_ERR_MSG(extack, + "pse driver does not support port priority"); + return -EOPNOTSUPP; + } + + if (prio > psec->pcdev->pis_prio_max) { + NL_SET_ERR_MSG_FMT(extack, + "priority %d exceed priority max %d", + prio, psec->pcdev->pis_prio_max); + return -ERANGE; + } + + mutex_lock(&psec->pcdev->lock); + ret = ops->pi_set_prio(psec->pcdev, psec->id, prio); + mutex_unlock(&psec->pcdev->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(pse_ethtool_set_prio); + 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 85a08c349256..b60fc56923bd 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -50,6 +50,8 @@ 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_max: max priority allowed for the c33_prio variable value + * @c33_prio: priority of the PSE */ struct pse_control_status { enum ethtool_podl_pse_admin_state podl_admin_state; @@ -62,6 +64,8 @@ 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_max; + u32 c33_prio; }; /** @@ -81,6 +85,7 @@ 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 */ struct pse_controller_ops { int (*ethtool_get_status)(struct pse_controller_dev *pcdev, @@ -95,6 +100,8 @@ 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); }; struct module; @@ -150,6 +157,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 + * @pis_prio_max: Maximum value allowed for the PSE PIs priority */ struct pse_controller_dev { const struct pse_controller_ops *ops; @@ -163,6 +171,7 @@ struct pse_controller_dev { enum ethtool_pse_types types; struct pse_pi *pi; bool no_of_pse_pi; + unsigned int pis_prio_max; }; #if IS_ENABLED(CONFIG_PSE_CONTROLLER) @@ -184,6 +193,9 @@ 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); bool pse_has_podl(struct pse_control *psec); bool pse_has_c33(struct pse_control *psec); @@ -220,6 +232,13 @@ static inline int pse_ethtool_set_pw_limit(struct pse_control *psec, return -EOPNOTSUPP; } +static inline int pse_ethtool_set_prio(struct pse_control *psec, + struct netlink_ext_ack *extack, + unsigned int prio) +{ + return -EOPNOTSUPP; +} + static inline bool pse_has_podl(struct pse_control *psec) { return false; From patchwork Wed Oct 2 16:28:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820057 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 5A5E21D150B; Wed, 2 Oct 2024 16:29:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886554; cv=none; b=fAT/qU3rJhubnSX5jeTv5iWkbOppgKqCWAwPXYTS5vrbPKtuJd0NrPCgxM1/eJsmWI4qmj4KVHLWdE8dAzKOE3LHqjTdk17zeChppNRGmwJtcJ8WPW0162/EK5RRgRVg6sWhIVYWoxxKf0R/Qq1kt2+gQRiMjWDoon9OXur0r/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886554; c=relaxed/simple; bh=dTcmCIDnixPq3eiYaqAldz0ta+57NaOU0QQ7rLhKxWI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mVGFL1pjuT8U1AD7tAzH3f1eZn7I4AH91dnhEYjrhJTfUknJCCi+/3tW/5ifi6VkZ65rg/qbVeaUiPKQU/EPbaXZQdz7FqLiipxfgPPmimU1h6nsFqsZbwCqyYapvFcT+d7mgoNEvlbNnEECiWrgnlK3OKx1jY3zqKlUJvEwcEk= 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=XGhklBW4; arc=none smtp.client-ip=217.70.183.201 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="XGhklBW4" Received: by mail.gandi.net (Postfix) with ESMTPSA id A9B8F1BF20A; Wed, 2 Oct 2024 16:29:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886550; 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=3GYugEsF4debH7Ai01HrEd8SCP3h/AFenW6Msf+6A9Y=; b=XGhklBW4yzbgHTAmBSvenfR1D9kIQznIoxWX/scZbiKXRr+PB/YodHY/58OP8hdoH47tI2 TPy4unKF5ATDigSolSVaV0oKYwYt9QKxTFUPsdstQ4eTZaZbgHGR7957JDG8JhAqnbYPAO GX3z4sSaTx5Uqjc68wd549Kvl/K00bTyTiRyLOwU5FTekwlcqd6z+/sFZNKuc45I/+4G2T X7LmF7S3o/cNFIR66AYNWg8JtVH2fgmGZYT6YQPxsU6CVevRjMx8KZDS8RhqfWBuyepXch XM8K2Lb5rwh1Ag7qvCZ596HRITG8IStPz3SLIqibBYzbeQdwfRjrtaiuY1XhVw== From: Kory Maincent Date: Wed, 02 Oct 2024 18:28:02 +0200 Subject: [PATCH net-next 06/12] net: ethtool: Add PSE new port priority support feature Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-6-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org 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() to configure the PSE port priority. Signed-off-by: Kory Maincent Reviewed-by: Andrew Lunn --- Documentation/networking/ethtool-netlink.rst | 16 ++++++++++++++++ include/uapi/linux/ethtool_netlink.h | 2 ++ net/ethtool/pse-pd.c | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index 295563e91082..15208429a973 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -1763,6 +1763,10 @@ Kernel response contents: limit of the PoE PSE. ``ETHTOOL_A_C33_PSE_PW_LIMIT_RANGES`` nested Supported power limit configuration ranges. + ``ETHTOOL_A_C33_PSE_PRIO_MAX`` u32 priority maximum configurable + on the PoE PSE + ``ETHTOOL_A_C33_PSE_PRIO`` u32 priority of the PoE PSE + currently configured ========================================== ====== ============================= When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_STATE`` attribute identifies @@ -1836,6 +1840,12 @@ identifies the C33 PSE power limit ranges through If the controller works with fixed classes, the min and max values will be equal. +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. + PSE_SET ======= @@ -1849,6 +1859,8 @@ 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`` u32 Control priority of the + PoE PSE ====================================== ====== ============================= When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_CONTROL`` attribute is used @@ -1871,6 +1883,10 @@ various existing products that document power consumption 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. +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. + RSS_GET ======= diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index 283305f6b063..874a4bca2e19 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -970,6 +970,8 @@ 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_C33_PSE_PRIO_MAX, /* u32 */ + ETHTOOL_A_C33_PSE_PRIO, /* u32 */ /* 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..439739eaf2ed 100644 --- a/net/ethtool/pse-pd.c +++ b/net/ethtool/pse-pd.c @@ -109,6 +109,9 @@ static int pse_reply_size(const struct ethnl_req_info *req_base, len += st->c33_pw_limit_nb_ranges * (nla_total_size(0) + nla_total_size(sizeof(u32)) * 2); + if (st->c33_prio_max) + /* _C33_PSE_PRIO_MAX + _C33_PSE_PRIO */ + len += nla_total_size(sizeof(u32)) * 2; return len; } @@ -198,6 +201,11 @@ static int pse_fill_reply(struct sk_buff *skb, pse_put_pw_limit_ranges(skb, st)) 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; + return 0; } @@ -219,6 +227,7 @@ const struct nla_policy ethnl_pse_set_policy[ETHTOOL_A_PSE_MAX + 1] = { NLA_POLICY_RANGE(NLA_U32, ETHTOOL_C33_PSE_ADMIN_STATE_DISABLED, ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED), [ETHTOOL_A_C33_PSE_AVAIL_PW_LIMIT] = { .type = NLA_U32 }, + [ETHTOOL_A_C33_PSE_PRIO] = { .type = NLA_U32 }, }; static int @@ -267,6 +276,15 @@ ethnl_set_pse(struct ethnl_req_info *req_info, struct genl_info *info) if (ret) return ret; + if (tb[ETHTOOL_A_C33_PSE_PRIO]) { + unsigned int prio; + + prio = nla_get_u32(tb[ETHTOOL_A_C33_PSE_PRIO]); + ret = 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; From patchwork Wed Oct 2 16:28:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820058 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 9656D1D151E; Wed, 2 Oct 2024 16:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886554; cv=none; b=s/OYTtcmdkpcKs/9yfZf5pupMEvwpVaByUpkcmYE43TbNvNq6df7ve7r3wgrRYZh+oWiNV/SZdUQO/3EdOVGJFWO3+A3H3vGRTHaATYmd6KP+D9dRR8UZcpUr+GX8dhp5Fp6Fjrfcb1Oa/NKzZTpxSeOVMORcQQ3ZA2J2ZXBjx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886554; c=relaxed/simple; bh=rVpijr8Ej3ERIa9M7Wj2D8vGyGBd8oUb+lInsTA0JrA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KvFnpRSuBvRXh38umTBtmb1/wIiw3Bs1BwakvbqEf4wpclFo+5ehcgTA/ElgiKugov4+8eaJQPCL6mL1Dw/uCg/3/VwRJridxuGsntieVroHGrorQ8KQ8+mtJYgXDZgs1sogoeGF8Up+ZX4ip2gBR9OhEue/K/nhDhlEtxKEuz0= 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=B+ci74lo; arc=none smtp.client-ip=217.70.183.201 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="B+ci74lo" Received: by mail.gandi.net (Postfix) with ESMTPSA id 6792B1BF204; Wed, 2 Oct 2024 16:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886551; 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=Q42vlEq9SAx89Xute+BoOnfEctMoZLGsOE40ryVf9pw=; b=B+ci74loAGXNI2/+BFpp5iyuy8Pj218w7C7E/UHHh38y+87bxkZyQ7GXqE4UxAoIyh4VTI i/iFdcvojuK1GDPJJMtRVfS5ttujiSwPPm3FagkJO5giWSqgo5RSD1tHeyDJ+7ArZx9wqp gkYfc/D7TsGSrDLRPVeGmvBifevW/lBrlvUrwaeah/hbl7xEe/YxpGcssokEl/42WG+sY2 U4tENZmwF3K8VPgKoorfoh8dusSEFard5FOvQFff1o/Lrdi1eFJYLnIcMlT4plTb0aKcbv dG5JWwOTPBEwLiH26AadfDi0bdKhuEi3+mCezQM6s76zj3+eYpz4WG7IR46diA== From: Kory Maincent Date: Wed, 02 Oct 2024 18:28:03 +0200 Subject: [PATCH net-next 07/12] netlink: specs: Expand the PSE netlink command with C33 prio attributes Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-7-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org From: Kory Maincent (Dent Project) Expand the c33 PSE attributes with 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 Reviewed-by: Donald Hunter --- Documentation/netlink/specs/ethtool.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 6a050d755b9c..e2967645fbf2 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -1020,6 +1020,14 @@ attribute-sets: type: nest multi-attr: true nested-attributes: c33-pse-pw-limit + - + name: c33-pse-prio-max + type: u32 + name-prefix: ethtool-a- + - + name: c33-pse-prio + type: u32 + name-prefix: ethtool-a- - name: rss attributes: @@ -1776,6 +1784,8 @@ operations: - c33-pse-ext-substate - c33-pse-avail-pw-limit - c33-pse-pw-limit-ranges + - c33-pse-prio-max + - c33-pse-prio dump: *pse-get-op - name: pse-set @@ -1790,6 +1800,7 @@ operations: - podl-pse-admin-control - c33-pse-admin-control - c33-pse-avail-pw-limit + - c33-pse-prio - name: rss-get doc: Get RSS params. From patchwork Wed Oct 2 16:28:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820059 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 464C71D1758; Wed, 2 Oct 2024 16:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886555; cv=none; b=p+kUYvhMwoarhTTxL3EY350yUB0AJQthOO+GeX39Zj4u8b9eJy/yCX4HO2wu8ng2JHf2s0LMpiWDMdc1IUPP0nw3MMJYnOWxXHoeyPIT/oZ1K9w6Krrkw9zmkaShyYw48Dxk5Wmi25B0a54IE6wJQB7Zf4YAc60m3ihitFfkBzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886555; c=relaxed/simple; bh=tSaUcqD7eHSaObZjjijtJrsg0WBYhM+Yr7DGFDUV5w0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BSqJIzTTMS1RzFKfVINH2Uw8V1AThexjWD+vjO7cts5l3MbjcSp0psbohefaxD2p3zUPBQcrFqF9EvtdIXq8u1eWHzLU8APmrmTIKU8U0qOlcmndSN3CYefH//69YgrO11Ly873YAJjT0j+8pdBXROLack8OBrgVl5T2o0hfeug= 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=jTJwi368; arc=none smtp.client-ip=217.70.183.201 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="jTJwi368" Received: by mail.gandi.net (Postfix) with ESMTPSA id 206BC1BF207; Wed, 2 Oct 2024 16:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886551; 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=G4biLTBMISLiI3PaOwg9EOAFMZ2vS5JuARGkBYnVsXc=; b=jTJwi368L/uga+EKVXuTpWNuZsMxJRHVKmN/YcHBWWM2SY/6no/x5Eslcqc86z2i4lD7EJ g6PZS013hiAM0nK6QHsIjnot/hRPwxBJBoYeR9dW637lOZ8OVMB1KDu0ohXKikhs2+SSv8 ImhHk5cNcBphaT4JWnZT5nZT3mrH3YLPFM1/6fdu8QGrNmnA4IGqhUoWIMRHh16eksklIz coHeD1nhFNSHS9Ov8dPOFpzeNLm/FelpdJgfxYpVyv7QGeuAd2yZ+5o0C2uPJOpR6uvCjd uT4zxTbbiGwZ/Yx40GHlzDAPU2C+OQ+xTBIX7hN9yYnk5mVxUbkaaZxL2S1dUA== From: Kory Maincent Date: Wed, 02 Oct 2024 18:28:04 +0200 Subject: [PATCH net-next 08/12] net: pse-pd: pd692x0: Add support for PSE PI priority feature Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-8-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org 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 --- drivers/net/pse-pd/pd692x0.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/net/pse-pd/pd692x0.c b/drivers/net/pse-pd/pd692x0.c index 0af7db80b2f8..3a4a9836d621 100644 --- a/drivers/net/pse-pd/pd692x0.c +++ b/drivers/net/pse-pd/pd692x0.c @@ -685,6 +685,8 @@ static int pd692x0_ethtool_get_status(struct pse_controller_dev *pcdev, if (ret < 0) return ret; status->c33_avail_pw_limit = ret; + /* PSE core priority start at 0 */ + status->c33_prio = buf.data[2] - 1; memset(&buf, 0, sizeof(buf)); msg = pd692x0_msg_template_list[PD692X0_MSG_GET_PORT_CLASS]; @@ -1061,6 +1063,25 @@ static int pd692x0_pi_set_current_limit(struct pse_controller_dev *pcdev, return pd692x0_sendrecv_msg(priv, &msg, &buf); } +static int pd692x0_pi_set_prio(struct pse_controller_dev *pcdev, int id, + unsigned int prio) +{ + struct pd692x0_priv *priv = to_pd692x0_priv(pcdev); + struct pd692x0_msg msg, buf = {0}; + int ret; + + ret = pd692x0_fw_unavailable(priv); + if (ret) + return ret; + + msg = pd692x0_msg_template_list[PD692X0_MSG_SET_PORT_PARAM]; + msg.sub[2] = id; + /* Controller priority from 1 to 3 */ + msg.data[4] = prio + 1; + + return pd692x0_sendrecv_msg(priv, &msg, &buf); +} + static const struct pse_controller_ops pd692x0_ops = { .setup_pi_matrix = pd692x0_setup_pi_matrix, .ethtool_get_status = pd692x0_ethtool_get_status, @@ -1070,6 +1091,7 @@ static const struct pse_controller_ops pd692x0_ops = { .pi_get_voltage = pd692x0_pi_get_voltage, .pi_get_current_limit = pd692x0_pi_get_current_limit, .pi_set_current_limit = pd692x0_pi_set_current_limit, + .pi_set_prio = pd692x0_pi_set_prio, }; #define PD692X0_FW_LINE_MAX_SZ 0xff @@ -1486,6 +1508,7 @@ static int pd692x0_i2c_probe(struct i2c_client *client) priv->pcdev.ops = &pd692x0_ops; priv->pcdev.dev = dev; priv->pcdev.types = ETHTOOL_PSE_C33; + priv->pcdev.pis_prio_max = 2; ret = devm_pse_controller_register(dev, &priv->pcdev); if (ret) return dev_err_probe(dev, ret, From patchwork Wed Oct 2 16:28:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820060 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 00EEA1D1E7C; Wed, 2 Oct 2024 16:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886556; cv=none; b=V4C2XTGAmhgy5XxqvRbAT+S/wo2e1Sh4hsfA1TXLgBW8syFLG2JfbIo+imY3HfgZoMybw0XjbUz+aPDD4Iq5TSa0rW3oIKqLWl67EyucX+drQwLB4CdsfkEkbxKPoGHJg3zGqt0l073inzbAZhFgyp62HLLvOWT0g1moj8XQHgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886556; c=relaxed/simple; bh=m5UVg9uMgWclNQ0ZC+nkcUjkJnAqUFQoCJthQiR5YHE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Aq74WJDcwnr30joLXS0xJYnCwi9l1uMUcKNbvSqxBAQHSTO5SOUXcl8IoOFlnQs4fgxiMqZuv1somR31mI8xiZ8Fnl2LkKFL9svbhg2gZDL9mUeAG51NCDUjnefc9/usUmJ+SgVmAMLEN9uBL/QcXlA9S2x16rWZY+yflRQJOoI= 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=lpA3bHFQ; arc=none smtp.client-ip=217.70.183.201 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="lpA3bHFQ" Received: by mail.gandi.net (Postfix) with ESMTPSA id D3DE71BF209; Wed, 2 Oct 2024 16:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886552; 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=qpBR8isuTmda5r4Ct+oNS3fZY4wF7+uxDTZEDgK+/Ng=; b=lpA3bHFQlmDafRf+NTzsXKa/h3ajO6D+MMX54qfWddn7TymIXi5CUK1NMb9vLv9pMs8aK7 9NWuUJhSnhQxzijRF6oaxezjZdyP/5e69TNJuBMVZTk7apk7WwapSVgs/rZ01MWGOGxpPY NZkJavfqmWXcZO+tUvxf2isiD2RkWc43dPQAuZYz0Y4MJMDhsI8bbrrBM+XiwGGgbQoXpv y4peffTbaXkBWs2iq9vF0PRcXmL8Pz36VcKtNm5gG4I1xcIQJAVRXMvd7TtqmFlNp6zye5 0BzWbPShKIJ6UwZLeFmaorSXB/G3d1RDfze4LN/V0K9bNedxO7FaeNUlywsVWA== From: Kory Maincent Date: Wed, 02 Oct 2024 18:28:05 +0200 Subject: [PATCH net-next 09/12] net: pse-pd: tps23881: Add support for PSE PI priority feature Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-9-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Andrew Lunn --- drivers/net/pse-pd/tps23881.c | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index e05b45cdc9f8..ddb44a17218a 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -22,6 +22,7 @@ #define TPS23881_OP_MODE_SEMIAUTO 0xaaaa #define TPS23881_REG_DIS_EN 0x13 #define TPS23881_REG_DET_CLA_EN 0x14 +#define TPS23881_REG_PW_PRIO 0x15 #define TPS23881_REG_GEN_MASK 0x17 #define TPS23881_REG_NBITACC BIT(5) #define TPS23881_REG_PW_EN 0x19 @@ -408,6 +409,24 @@ static int tps23881_ethtool_get_status(struct pse_controller_dev *pcdev, return ret; status->c33_pw_class = ret; + ret = i2c_smbus_read_word_data(client, TPS23881_REG_PW_PRIO); + if (ret < 0) + return ret; + + chan = priv->port[id].chan[0]; + if (chan < 4) + status->c33_prio = !!(ret & BIT(chan + 4)); + else + status->c33_prio = !!(ret & BIT(chan + 8)); + + if (priv->port[id].is_4p) { + chan = priv->port[id].chan[1]; + if (chan < 4) + status->c33_prio &= !!(ret & BIT(chan + 4)); + else + status->c33_prio &= !!(ret & BIT(chan + 8)); + } + return 0; } @@ -925,6 +944,42 @@ static int tps23881_pi_set_current_limit(struct pse_controller_dev *pcdev, return 0; } +static int tps23881_pi_set_prio(struct pse_controller_dev *pcdev, int id, + unsigned int prio) +{ + struct tps23881_priv *priv = to_tps23881_priv(pcdev); + struct i2c_client *client = priv->client; + u8 chan, bit; + u16 val; + int ret; + + ret = i2c_smbus_read_word_data(client, TPS23881_REG_PW_PRIO); + if (ret < 0) + return ret; + + chan = priv->port[id].chan[0]; + if (chan < 4) + bit = chan + 4; + else + bit = chan + 8; + + val = (u16)(ret & ~BIT(bit)); + val |= prio << (bit); + + if (priv->port[id].is_4p) { + chan = priv->port[id].chan[1]; + if (chan < 4) + bit = chan + 4; + else + bit = chan + 8; + + val &= ~BIT(bit); + val |= prio << (bit); + } + + return i2c_smbus_write_word_data(client, TPS23881_REG_PW_PRIO, val); +} + static const struct pse_controller_ops tps23881_ops = { .setup_pi_matrix = tps23881_setup_pi_matrix, .pi_enable = tps23881_pi_enable, @@ -934,6 +989,7 @@ static const struct pse_controller_ops tps23881_ops = { .pi_get_voltage = tps23881_pi_get_voltage, .pi_get_current_limit = tps23881_pi_get_current_limit, .pi_set_current_limit = tps23881_pi_set_current_limit, + .pi_set_prio = tps23881_pi_set_prio, }; static const char fw_parity_name[] = "ti/tps23881/tps23881-parity-14.bin"; @@ -1106,6 +1162,7 @@ static int tps23881_i2c_probe(struct i2c_client *client) priv->pcdev.dev = dev; priv->pcdev.types = ETHTOOL_PSE_C33; priv->pcdev.nr_lines = TPS23881_MAX_CHANS; + priv->pcdev.pis_prio_max = 1; ret = devm_pse_controller_register(dev, &priv->pcdev); if (ret) { return dev_err_probe(dev, ret, From patchwork Wed Oct 2 16:28:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820061 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 D282E1D1F4E; Wed, 2 Oct 2024 16:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886556; cv=none; b=jKWc2l0OIdjPJVKWQC0ZfJpUM0YZRonw8aFaZFeecMTg89P30bBU2juThF/269dLfaBQnF6Q79q1vzgY/RQOgtE7I+grbitC3qewelCBk+h+vzVmcQ+k+lcVS3vTLMlZHCVMWEGwrgDB1wBMHTFQ9nqqaXERGuAHCsASZofwEBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886556; c=relaxed/simple; bh=6fP4GiSZHpLwe8j151kxCCfVBFZI6rH3qmFV0hsMm8M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EjUg/ZA7l/EGgQnhRMnHuxn8sQeF9CxcmeBDxAyV9R/T6N1nz2T+59mlZuB9aLwxIIr0mF93OObRq2XlCadbbg0SvFAA4FT5sRRL9uO0pPOECQ+GiyjO4vXB26w4mwfc08M4nt74di1bW0wJ2rcqEPyEhPGRl/WU8NHPJUAgtJw= 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=jDuvl+Tg; arc=none smtp.client-ip=217.70.183.201 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="jDuvl+Tg" Received: by mail.gandi.net (Postfix) with ESMTPSA id 938731BF20C; Wed, 2 Oct 2024 16:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886553; 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=Ul5YyEM+HmobdSv66VP3I6i6ZUMsqXQf70IngMOL9vE=; b=jDuvl+TgD4NNN8Wms5GG43DxZEZ1S1qt9tcuUY8CJFH4uXutsNZ+je2UY0eubxoK3fMSQ/ YOWwFfOtTwckdneVJoCpQQaUH4kR+EjKpy/rIYV95lVCPgcHC8q3F0vYCJ6LH6hAZxWJHG Nn9sjuOzydXe/5Wb6N+xwe9nsrs/mTFR8VWNSjbTZWmlPUmlrEpTz2u3WdvjmhTGWJjbau RAKpk+r9pBrC4PykvFxQ8BAXogVyydtLxA8o6uCs5VzrRlUBZLQpWxadHsuEffocR/ffd9 IpTfhcUfu7jDl7A6UYNpTZsX0XyPACLbvorZfS2JRzo1/geHdZIrNSIrWx0C4w== From: Kory Maincent Date: Wed, 02 Oct 2024 18:28:06 +0200 Subject: [PATCH net-next 10/12] net: pse-pd: Register regulator even for undescribed PSE PIs Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-10-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org From: Kory Maincent (Dent Project) Ensure that regulators are registered for all PSE PIs, even those not explicitly described in the device tree. This change lays the groundwork for future support of regulator notifiers. Maintaining consistent ordering between the PSE PIs regulator table and the regulator notifier table will prevent added complexity in future implementations. Signed-off-by: Kory Maincent --- drivers/net/pse-pd/pse_core.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index 6b3893a3381c..d365fb7c8a98 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -463,10 +463,6 @@ int pse_controller_register(struct pse_controller_dev *pcdev) for (i = 0; i < pcdev->nr_lines; i++) { char *reg_name; - /* Do not register regulator for PIs not described */ - if (!pcdev->no_of_pse_pi && !pcdev->pi[i].np) - continue; - reg_name = devm_kzalloc(pcdev->dev, reg_name_len, GFP_KERNEL); if (!reg_name) return -ENOMEM; From patchwork Wed Oct 2 16:28:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820062 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 6D6CA1D1F76; Wed, 2 Oct 2024 16:29:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886557; cv=none; b=AUYvZMbb97rPRCHIogokn4Vl+AP0UNaG0XfZXFbQgvgHt35nO7v12CyAGc9eozfm0rMjKJ0W8dMU9QAg0tDLQHiI5EHxJW6WlIm0rQ4ZEo3R6VGnquqEmdv6Ie4kFecMSljBa/KCX76lNncI054IxBx1Y0lN+1Ch37sYEJQ3TdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886557; c=relaxed/simple; bh=TmppxM30hDT5N6ZYZ9A5WGjGkeUb4dF0hUftJdet5Zk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xl4ll/38Tyt9FB4PrPnUJm8ScfqWZgIjmJyb1tI7E2elsXHj4kTk6p2cIuj5JYIyxGqYsR/BOeLQyzxx2/tNSwDGvdqy/EkINAHJuYM9pJ4c+z7N7QToLv2uspQVVh5qseLoC3n2f3rMmBrgGStU5MIrE7DbLWQGsVSfqQEEWOk= 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=DiJbMRff; arc=none smtp.client-ip=217.70.183.201 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="DiJbMRff" Received: by mail.gandi.net (Postfix) with ESMTPSA id 579F11BF208; Wed, 2 Oct 2024 16:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886554; 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=NwYTIxMfa1jPmwx2OgcBIE/2wO/u4fQR0T5aEiPB4PM=; b=DiJbMRffZA+MwVWjVcqW2/FkadssdjolTvl//v+zd5bYFQ1PKBeDaWv9b5tWFBfCSi8wWh /b5zJcrVGKMSxF1FhDwnqU9+565wvbPyheURD/aejo0Ta+oFjNbBmW+5I9ICBzgArF0XC+ 6RkmmMxkrIn2bqJCTVcoiSIKs5ko+b7uwMuPq8Tpz/4CDDG+RBLY1ZdYvFod2VH/i2yNrd 1zBIxOCsEh8GnibKg7A6m3Ch83LFMwHWXD89eo28qWd2XI14nWvo2docBLWbmDq1LlcmrY GYvJtyNaNLyt3SsWxpGl/9RDF29ft8FsyBtgXol4IioLpZ9zHVR+Zoooz/UYtw== From: Kory Maincent Date: Wed, 02 Oct 2024 18:28:07 +0200 Subject: [PATCH net-next 11/12] net: pse-pd: Add support for event reporting using devm_regulator_irq_helper Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-11-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org From: Kory Maincent (Dent Project) Add support for devm_pse_irq_helper(), a wrapper for devm_regulator_irq_helper(). This aims to report events such as over-current or over-temperature conditions similarly to how the regulator API handles them. Additionally, this patch introduces several define wrappers to keep regulator naming conventions out of PSE drivers. Signed-off-by: Kory Maincent --- drivers/net/pse-pd/pse_core.c | 32 +++++++++++++++++++++++++++++++- include/linux/pse-pd/pse.h | 24 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index d365fb7c8a98..a9f102507f5e 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -8,7 +8,6 @@ #include #include #include -#include #include static DEFINE_MUTEX(pse_list_mutex); @@ -536,6 +535,37 @@ int devm_pse_controller_register(struct device *dev, } EXPORT_SYMBOL_GPL(devm_pse_controller_register); +int devm_pse_irq_helper(struct pse_controller_dev *pcdev, int irq, + int irq_flags, int supported_errs, + const struct pse_irq_desc *d) +{ + struct regulator_dev **rdevs; + void *irq_helper; + int i; + + rdevs = devm_kcalloc(pcdev->dev, pcdev->nr_lines, + sizeof(struct regulator_dev *), GFP_KERNEL); + if (!rdevs) + return -ENOMEM; + + for (i = 0; i < pcdev->nr_lines; i++) + rdevs[i] = pcdev->pi[i].rdev; + + /* Register notifiers - can fail if IRQ is not given */ + irq_helper = devm_regulator_irq_helper(pcdev->dev, d, irq, + 0, supported_errs, NULL, + &rdevs[0], pcdev->nr_lines); + if (IS_ERR(irq_helper)) { + if (PTR_ERR(irq_helper) == -EPROBE_DEFER) + return -EPROBE_DEFER; + + dev_warn(pcdev->dev, "IRQ disabled %pe\n", irq_helper); + } + + return 0; +} +EXPORT_SYMBOL_GPL(devm_pse_irq_helper); + /* PSE control section */ static void __pse_control_release(struct kref *kref) diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index b60fc56923bd..ba3d6630d768 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -8,6 +8,7 @@ #include #include #include +#include /* Maximum current in uA according to IEEE 802.3-2022 Table 145-1 */ #define MAX_PI_CURRENT 1920000 @@ -15,6 +16,26 @@ struct phy_device; struct pse_controller_dev; +/* structure and define wrappers from PSE to regulator */ +#define pse_irq_desc regulator_irq_desc +#define pse_irq_data regulator_irq_data +#define pse_err_data regulator_err_data +#define pse_err_state regulator_err_state + +#define PSE_EVENT_TABLE(event) REGULATOR_EVENT_##event +#define PSE_ERROR_TABLE(error) REGULATOR_ERROR_##error + +#define PSE_EVENT_OVER_CURRENT PSE_EVENT_TABLE(OVER_CURRENT) +#define PSE_EVENT_OVER_TEMP PSE_EVENT_TABLE(OVER_TEMP) + +#define PSE_ERROR_OVER_CURRENT PSE_ERROR_TABLE(OVER_CURRENT) +#define PSE_ERROR_OVER_TEMP PSE_ERROR_TABLE(OVER_TEMP) + +/* Return values for PSE IRQ helpers */ +#define PSE_ERROR_CLEARED PSE_ERROR_TABLE(CLEARED) +#define PSE_FAILED_RETRY REGULATOR_FAILED_RETRY +#define PSE_ERROR_ON PSE_ERROR_TABLE(ON) + /** * struct pse_control_config - PSE control/channel configuration. * @@ -180,6 +201,9 @@ void pse_controller_unregister(struct pse_controller_dev *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, int supported_errs, + const struct pse_irq_desc *d); struct pse_control *of_pse_control_get(struct device_node *node); void pse_control_put(struct pse_control *psec); From patchwork Wed Oct 2 16:28:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820063 X-Patchwork-Delegate: kuba@kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 5DC421D0E34; Wed, 2 Oct 2024 16:29:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886558; cv=none; b=qv0GQ/k56y/4IsBk6Yp5BsKwVandzPbbq8tuL7c+EdQzATkLpA96HL8/HOsoE6flFqqwAN627RiseIs1ZZ9zqBSQtP/QiZ0zWTfQqtLegkaG2fP+kOs0YcVvcm7OiUNqSy09/W1mo5NZyO30JlsLXFDwP+uiPVN+jgcPuQCr7U8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727886558; c=relaxed/simple; bh=lie+v4+aHAQjNO+R6PY+GE+xML+J1xWgPW0F7Qo/Yjk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OcDFQCmFTXCw82gbz4md6MhYRx0TEACxI5MSRdEHVkk+l917XboYW1AW3K/VJIX3wXTCIVoajRWJkLV0yHCy/vKFb2ZwH4ybmUvCpsxHU/0jPwxtJCr+pHkkh/7graW1701SwQHgQHx5n0vyjA0PsdvaIlKoRVtCxrktjk8UECU= 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=Q5k3kQxz; arc=none smtp.client-ip=217.70.183.201 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="Q5k3kQxz" Received: by mail.gandi.net (Postfix) with ESMTPSA id 1D3B11BF203; Wed, 2 Oct 2024 16:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727886554; 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=zg8or6L5eyzMH1TuklarP5kBCWGDZKKVNBcBHI7D8X4=; b=Q5k3kQxzsrX0DhSS0BNxLp/hw+twTNjflYLsWGPXUb8+aWaj1qsT9N6rtx4+o6JXg8gX4y ybRwg5i8CK49Fa3EHED4K7YtVdZxKfOfDi7Eid286okAaVXBnT8tskucWGHGsHYOSYdbBL j974Nb15SYb6W9LorYNC5CVt7ly3cQ9BNtz4KqKYmy2PkiiksA+YVmVN2isQFWtPOZEYk5 G1hVpfozz9Hp1Nc+oGgMShGPSdjONi/X7JTM52qADNdXW0tCNg8gx9H9g+RgPbYzasAv/X kVWkuP5m9oZPdTYNRm4A7AODdpzTD0/uOrR/e4acIHd7FBTRmiuji0+Z3Rg8dg== From: Kory Maincent Date: Wed, 02 Oct 2024 18:28:08 +0200 Subject: [PATCH net-next 12/12] net: pse-pd: tps23881: Add support for PSE events and interrupts Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241002-feature_poe_port_prio-v1-12-787054f74ed5@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-787054f74ed5@bootlin.com> To: Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com X-Patchwork-Delegate: kuba@kernel.org 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. This patch also adds support for an OSS GPIO line to turn off all low priority ports in case of an over-current event. Signed-off-by: Kory Maincent --- drivers/net/pse-pd/tps23881.c | 123 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c index ddb44a17218a..03f36b641bb4 100644 --- a/drivers/net/pse-pd/tps23881.c +++ b/drivers/net/pse-pd/tps23881.c @@ -17,6 +17,13 @@ #define TPS23881_MAX_CHANS 8 +#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 @@ -25,6 +32,7 @@ #define TPS23881_REG_PW_PRIO 0x15 #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 @@ -59,6 +67,7 @@ struct tps23881_priv { struct pse_controller_dev pcdev; struct device_node *np; struct tps23881_port_desc port[TPS23881_MAX_CHANS]; + struct gpio_desc *oss; }; static struct tps23881_priv *to_tps23881_priv(struct pse_controller_dev *pcdev) @@ -1088,11 +1097,112 @@ static int tps23881_flash_sram_fw(struct i2c_client *client) return 0; } +static void tps23881_turn_off_low_prio(struct tps23881_priv *priv) +{ + dev_info(&priv->client->dev, + "turn off low priority ports due to over current event.\n"); + gpiod_set_value_cansleep(priv->oss, 1); + + /* TPS23880 datasheet (Rev G) indicates minimum OSS pulse is 5us */ + usleep_range(5, 10); + gpiod_set_value_cansleep(priv->oss, 0); +} + +static int tps23881_irq_handler(int irq, struct pse_irq_data *pid, + unsigned long *dev_mask) +{ + struct tps23881_priv *priv = (struct tps23881_priv *)pid->data; + struct i2c_client *client = priv->client; + struct pse_err_state *stat; + int ret, i; + u16 val; + + *dev_mask = 0; + for (i = 0; i < TPS23881_MAX_CHANS; i++) { + stat = &pid->states[i]; + stat->notifs = 0; + stat->errors = 0; + } + + ret = i2c_smbus_read_word_data(client, TPS23881_REG_IT); + if (ret < 0) + return PSE_FAILED_RETRY; + + val = (u16)ret; + if (val & TPS23881_REG_IT_SUPF) { + ret = i2c_smbus_read_word_data(client, TPS23881_REG_SUPF_EVENT); + if (ret < 0) + return PSE_FAILED_RETRY; + + if (ret & TPS23881_REG_TSD) { + for (i = 0; i < TPS23881_MAX_CHANS; i++) { + stat = &pid->states[i]; + *dev_mask |= 1 << i; + stat->notifs = PSE_EVENT_OVER_TEMP; + stat->errors = PSE_ERROR_OVER_TEMP; + } + } + } + + if (val & (TPS23881_REG_IT_IFAULT | TPS23881_REG_IT_IFAULT << 8)) { + ret = i2c_smbus_read_word_data(client, TPS23881_REG_FAULT); + if (ret < 0) + return PSE_FAILED_RETRY; + + val = (u16)(ret & 0xf0f); + + /* Power cut detected, shutdown low priority port */ + if (val && priv->oss) + tps23881_turn_off_low_prio(priv); + + *dev_mask |= val; + for (i = 0; i < TPS23881_MAX_CHANS; i++) { + if (val & BIT(i)) { + stat = &pid->states[i]; + stat->notifs = PSE_EVENT_OVER_CURRENT; + stat->errors = PSE_ERROR_OVER_CURRENT; + } + } + } + + return PSE_ERROR_CLEARED; +} + +static int tps23881_setup_irq(struct tps23881_priv *priv, int irq) +{ + int errs = PSE_ERROR_OVER_CURRENT | PSE_ERROR_OVER_TEMP; + struct i2c_client *client = priv->client; + struct pse_irq_desc irq_desc = { + .name = "tps23881-irq", + .map_event = tps23881_irq_handler, + .data = priv, + }; + int ret; + u16 val; + + val = TPS23881_REG_IT_IFAULT | TPS23881_REG_IT_SUPF | + TPS23881_REG_IT_IFAULT << 8 | TPS23881_REG_IT_SUPF << 8; + ret = i2c_smbus_write_word_data(client, TPS23881_REG_IT_MASK, val); + if (ret) + return ret; + + ret = i2c_smbus_read_word_data(client, TPS23881_REG_GEN_MASK); + if (ret < 0) + return ret; + + val = (u16)(ret | TPS23881_REG_INTEN | TPS23881_REG_INTEN << 8); + ret = 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, errs, &irq_desc); +} + static int tps23881_i2c_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct tps23881_priv *priv; - struct gpio_desc *reset; + struct gpio_desc *reset, *oss; int ret; u8 val; @@ -1169,6 +1279,17 @@ static int tps23881_i2c_probe(struct i2c_client *client) "failed to register PSE controller\n"); } + oss = devm_gpiod_get_optional(dev, "oss", GPIOD_OUT_LOW); + if (IS_ERR(oss)) + return dev_err_probe(&client->dev, PTR_ERR(oss), "Failed to get OSS GPIO\n"); + priv->oss = oss; + + if (client->irq) { + ret = tps23881_setup_irq(priv, client->irq); + if (ret) + return ret; + } + return ret; }