From patchwork Wed Oct 2 16:14:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820040 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 B95CA1D049B; Wed, 2 Oct 2024 16:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885692; cv=none; b=ArCHkNJUhnxVPwrr6JyvXKeXIt4p8mO3yUlG7+J2jE6cbeTwnbINckfEBuc6kzHfIxMZHaBvzZxROgsQyzwZLM49x5N8lc6T8AKfHaYrZAZaeYl95hzCSynr1/lbPHVDWs5LkAbjy/cECtCdHDRCIWt6p8cqktZ0O/ZhmxB9fFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885692; c=relaxed/simple; bh=yqdYmWDPi96O6HF7ebbWScHKYpa6AeAvglvLs6cCSDk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L6aPgK+K99CHLCvfpuxjtJcVYqqBeWpRoSVTIcxJrT2RUI6lM/Y0XFgKxaASkx0f/gIPRve6Z+q1L9NlLokiuzY/P6dFFsq8zOkV+penKQPKUSxDCIsmx8gWWSBktpf34x5PkUJQfnQhFCN78okOHG/2L76tcpRZdiC74AIO2G8= 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=nogv84W1; arc=none smtp.client-ip=217.70.183.199 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="nogv84W1" Received: by mail.gandi.net (Postfix) with ESMTPSA id 28DF8FF80B; Wed, 2 Oct 2024 16:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885682; 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=nogv84W1O4Et/X6/iz/eFTTOnJcOtbNuQ8QmviCUOKZ/E4v+hTULS7+B03BNnYbyAtSCr9 Aii56OwTc6+x/z3gvPZVX9m7F1dX01Gz/F4BfRDi5J8MJxbkgzw+a6hr7lO7v/b/DWGWQj LxOKtwjsbzyBM/JTQsky+iH1TCdwvNif0hvQKmpe5lGiDNn7o9Y5JAqQKgj4oqALKzbqmE j3cy9n/d3XSGQdTBYk9baD78BUjL527hkVifBizTKala+85aefoQmU+BpugquXG9T/GVmL CgLFkH7frb5JlstRGRJN5FH6s48faOoRd9Gcv/j/C2A/ZSWBHsfDmQ6bH2UYcA== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:12 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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 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 --- 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:14:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820042 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 539701D0E0D; Wed, 2 Oct 2024 16:14:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885693; cv=none; b=Bs/JLS2R9ENfhNseU3Y+bhN1+9ZYXxNvnIlWPZAS5B2oVGVy9PJZZ3sNZK5P/eXQ/84DU42w4LGXEDr+1Ps16e4tuvTrQ/kZySWB105c8d2MG1OwyOTz52H6gt1yImyclpMmxjVtfTGxRer6X0HNizr2OoTH+nj6sY0pAZ3n8Fo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885693; c=relaxed/simple; bh=FdyIlP5QbAoJSErExFHqxvHzcDD2538/OXE26emypME=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qJmCprp5Rx5PNrHNy+yc9B8MI9jXObJdWJC/fhZXP+MZ1C2yhQUZ7PODuNszQtU6BRgDCAZi9iwkl/F6LkPqNNAZnrgzG+yMZN+5Nm7oTQqRIU7kjL7Z/0NpyYpIDEmHEBpLV3UZJeckkR5nBTDNK5zNcn2uVQptaXkXdsD++fg= 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=b1ZgqD1b; arc=none smtp.client-ip=217.70.183.199 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="b1ZgqD1b" Received: by mail.gandi.net (Postfix) with ESMTPSA id E28F7FF809; Wed, 2 Oct 2024 16:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885683; 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=b1ZgqD1bU7HymIOpRB1dPPuSfhqk8FMH9T8uAui0s12CZaVmLezgnRfREFAEnMUfytVc5Q C427PJw/AJHqweGjuib9IBap5fcj8yo2rAF3u3yvGYnGru5PomwcmiZfrFadWVYK9lW1Mb BzVtXV7VeY/iOp0JfJyWXqq3isYTv3U/Ikiw7/bUe9OogTchJaBKmRinmf5K71JRu8ERGC WokKtlqqgYEBwKmp6ikysvu2UABln9NYbQKAfjvkS9MJJWFV+ANvYo0+s1Ox3Z9kmPU0Px 5cFkW4ldUWNW0AVym5v/TGt64Qk7OZd26ZmFrYEG/tEtoP8mSw10bYf5AzTHVQ== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:13 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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:14:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820043 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 539CD1D0E19; Wed, 2 Oct 2024 16:14:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885693; cv=none; b=aObOa4EfaxNedhmPJgRbluwyrs7AszXP0gDyw1FF58ege1dGR2xxJMIkQjA22T8cMAnWB7cK4ypL6G8EM3UIoZe4Pq6V4NjhHUvrb8z7WR6bFOUkRkbzPax7rhzwbtn1rsneYT9vA5/BYxY4AJLv8lv1PCedhOjpN/3ONwbuwKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885693; c=relaxed/simple; bh=OV/RdTYEnlbC3pry5KNHKsetn+/sjren2tP879uTa5Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gDwCIDOjLfcEWt3VVdMs0MzfFmESBxkoHvKsVAavyRubU9OR90gPM+lo3XtfublFdKDO/zx4YiPxyJ7tlLC2Qfrcxbjb//IcI1Tqfn4cUs90X2b6goSxoPrqMWBii6rATy+vDLsexWkVDnNNUNBA63ald3vSib8UPBYJDKkDqOI= 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=ZMDM2Wpo; arc=none smtp.client-ip=217.70.183.199 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="ZMDM2Wpo" Received: by mail.gandi.net (Postfix) with ESMTPSA id B124AFF80A; Wed, 2 Oct 2024 16:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885684; 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=ZMDM2WpoyLVJwrUzZhoIq92Nx1nkGmEJVQDJactxsWB2Wg0wQXq/LGoyczTfefRCqoTyrC g44Q1f5bO9zVqCqej9FgYFjZOYBEinOUJZ+llp1AIz5GnAPZ0pbVlm5Y5Jm+eSsy4hfp4E EzNbB436ooNO8VqgHi6M0WaSPsq45WpUK7buatGmwHoMaNvLB+Hxy4ZBQHD52uR7+d7ZwZ 8028durkTipo0JxeDJkpI+2jJJtYr4mR1iQInuHPJevKht5E4s1smLFxlMVy3SHl8jhBIk OauvPKfWtb65XS2ppPaTzO7rxBeGb8BxidRazKAQesnzXcxAMibSXYgN0uYVoA== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:14 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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 --- 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:14:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820044 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 5318D1D0F64; Wed, 2 Oct 2024 16:14:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885695; cv=none; b=IVJMLMK6gmHf/NAkS2JHnKmMNlIp7gJVAZIda9/k/0LQJfdnUqGuSh2+XD81WjoMzHKOnV2462kYwDPklH9JojOrsPWNrHfama4AUzgUgKh3MmrxKJYpohgjefK8Jk7wb0h6pTrtTIfimpn6U/F3aLo44s2NpD/wRAnAEeb7tu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885695; c=relaxed/simple; bh=O6dqqwIb8ntWdhD7LBUoy2m5OdXAqUc9w9/iAHs433k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kvW0a0p9jn5h2+dNesfLdQ56XRJ8hfnDZFI8bOQiaD3+8lq7W96rZzfSZVvN7qm+0buPkrCEwZfG1HzXDqWFLm0Hnxqk1stYLqq0fwRnEYAQy+fJftz+IyPXkcTaxHJHc/hhavvED9n9ZaqCu4/cwWIxEcn6nJ1WdGlAAd57dvA= 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=RgapIwu5; arc=none smtp.client-ip=217.70.183.199 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="RgapIwu5" Received: by mail.gandi.net (Postfix) with ESMTPSA id 79E98FF80D; Wed, 2 Oct 2024 16:14:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885685; 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=RgapIwu5UKDeYMSbWamCVLnn7o+TQ1seOm5GMtxobvcsxQdlEqTlvvfdB43ytaKLwB20kD b8yVc67EcEmN8Bpnw6jlN5lpVEb7yWKuYhsHUShY0tneZQV0OOxdYipSgM/KjFFr+2CI28 asHPn4cYocMG2PukpAGP+ZYieQ/WE99mOwNDQq3DzKbkgQmHEzErGhcy+Nqlj67WT9NL7m hJ4Avqarmnhv9C22fbqwJ8Lxeg4T939YBEJ9c3pT7UBzEsGBxAnKuMj9fQSCQbxcdfOz2h A0RCk4Rd7YggKMtb2WZ/M8Dy14tTK5bogcyAJZNnfdE309QbHTt+/37oKK12oA== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:15 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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 --- 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:14:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820047 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 4E9BF1D14EC; Wed, 2 Oct 2024 16:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885695; cv=none; b=uzQi9BB8/giDcbjAmUwa1x8fCyVF+QZ9MCBxVC5rsKcKN7tp+Kq16Hz3cRfiwfvEXC4S+Mz9ba3EanOuG9n+QNECdSzg4U7nh/sHefWMEJeJTL8ktH3dcrav1HAn8H5t4BSRq5ryG7GIQKHsA1O7VW+s2DWc+FL7HHQGNYeUUsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885695; 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=THElHXNm4UnAHEBDr6NDv3ySaVhE42G+hx3XXlh/l1cvvI4hXEauBVvSmSe/eybSec1jMNzDaAGoQGpBNywBRvFwtky/WiBKYsmMi9rwHFCPdMfFWpHVVBMqCsfHXI2ri3iSgaE/1bD4dTXnBE5amGlNhMovDYdUhPteBidDQHs= 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=eK8IbIML; arc=none smtp.client-ip=217.70.183.199 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="eK8IbIML" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4EBC2FF805; Wed, 2 Oct 2024 16:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885686; 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=eK8IbIMLoTuHy8edsw9uXjxtJulSEsXPQwJexfAJgoxKyNuPCRS2GkC8KQFOCGO7ODk3kB 3h64cv73cdaeaUgI16Zc06jsxXYr3a5chfDFYuWptuqvp6kZKmDXAtidHTufNn1NdyChC1 EVL/DE6oA8vw/+LMawb5SNdAcdyg0CHdW6V4LjJxmcg4eWyyqHRhaxm4N9PMThocGfcUA4 mt5uReSjuQC8+7/sn68NWDBaWl3d0pYQXOdbseEFY6Al0c7I8szVC75Jjbp0ZQgQ9720xP fFWjTeu9EfugQBJwHKHcy/lrr2scnXZMwfPqG9iY3fBW8mAf0R1oFBX4YuqiVg== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:16 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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 --- 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:14:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820049 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 7E74A1D1E75; Wed, 2 Oct 2024 16:14:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885697; cv=none; b=UdUXG2Rv8gCXfWuY5ONx83nWNXPOt6P31TfMNPnxOoRQFdetd86D8K6uumYTy936LH1cpYw4yYxTxHohMd6clJRenOs8pbK+UIqk1yVcChBMzYodLTQ+GiirrT0ryslWAPj4kMH7das61Sb4LDFby51aOM3JWF1jmDqDctgDdI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885697; c=relaxed/simple; bh=dTcmCIDnixPq3eiYaqAldz0ta+57NaOU0QQ7rLhKxWI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NCmHXszmAo2s8aAI5j+n60l8OFHuRIa9iv4uHRVLVF44vPADauj5W8TEu4aDJU9xRhxH16jqBEkBshN1mv1IA2W8w9SSKRCMMxp3cxFj+QawhTZ9XVCkwts32iqgfA7XZfLR4qfg9EEkUkTdGgpFn2Zjo6CdlSH2gj7d4qR2FkU= 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=ECVQoYgR; arc=none smtp.client-ip=217.70.183.199 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="ECVQoYgR" Received: by mail.gandi.net (Postfix) with ESMTPSA id 2A029FF80C; Wed, 2 Oct 2024 16:14:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885686; 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=ECVQoYgRWgeZI4Hf2s0nyMtwLvj3knnnm0EbaKkhvuqNUChY3pplhK81H98y5JqfAOreP1 B7r22HeBfPZBqrNnOh657ceAJjyo5e5aSDMQQKXmz9cCfCc0Jl/oSCpM+ij17zJqI+gRkJ lcurqt7h7aC8dfeSTQYD3REwAPYQeYdZx/z+ibUUsQMm7KsUmaskdaCF6Tk2KAv0nIbrcX RgVVeq/8MgdWWOeUBrCscmsnDi1k3G6fCCpFHSSYWCg0MGMNaxNKtip+IikgbXsh5aFbqA Ih/UqQ4srOnhlusITM9eRYwNCxR8hvkqW/VPLxLP9fESIgDmgOzCJMttveW79g== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:17 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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 --- 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:14:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820038 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 629A51D014D; Wed, 2 Oct 2024 16:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885691; cv=none; b=fPb7sa5d5rQSZED5rb9j22VqyNkP/63bc9O+Fxfz3FYV07CTtiWzYW6+rMrXb8qKY1ihRygRNbWeX4sAKpRlBKVn1omryRp2GgBmW0s2BHhIPZwuPJEDhinxClkTzJRrfOG0cULw3PI8skQSycePnl/QHXIEIJZVHDd4yeGxXTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885691; c=relaxed/simple; bh=rVpijr8Ej3ERIa9M7Wj2D8vGyGBd8oUb+lInsTA0JrA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CvZ8soXjYP5s++pqpkyJv8YbHL80cEFne11FdjGvbNWFMOOv3g8emd4QLE0WWt0xCh8gjkCJAeR91NWz83mrDnJKzwqAWVP+FTjxqUTpR6fqCbL/WqFSqMIeb5tUw642GBtPiX4VLmjNJDqfUrtvQknX4WoVNNBohphuzHA/b2M= 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=DPWomRlT; arc=none smtp.client-ip=217.70.183.199 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="DPWomRlT" Received: by mail.gandi.net (Postfix) with ESMTPSA id F2A0EFF80E; Wed, 2 Oct 2024 16:14:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885687; 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=DPWomRlTMMGSztWOP2fzIuNo2vn4VPCscviVPD7kzV4EH3AD4Zuj+gu2f3DuooRkGv3eRn m1PUpBsZNdg0Ozvba3Ds8ir33vRCwk7Z+Q1d5f2L5pybaZ9jn4ZmiLZLMDQP6g+9q9Y/xT UVxY15Qwzaa9f5qu7EOWLVFwAgMNpyIF5tmdNLRADLu2S7UFVrAMM9FbtmuFJR20C8VBP0 Vuu1trp2Viz0WzWuycY5fWBUrOUBMQGycfywDMGyQV2kaDkF2O+xrd8dKNRKuwSi5iWXe4 LCmv0avSPeHnCUtDV5qlZM6I31vVkZsPDORGdR6fzZspS3rSFp4TZoLJ5/1V6A== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:18 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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 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 --- 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:14:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820039 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 1EEE11940B0; Wed, 2 Oct 2024 16:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885692; cv=none; b=VLeSlGq5dRyQVtqRuKpvplT1oo5OwBrfMEr+f05qyLahdG86bq2A3qaQiMnxTXrNUDUngOtjObIsjNvZ9oZTUWiE6hPATFgwwqdVy07DG26LiEM+9GdBeMgDdUtia6hWN0mIMEVuFVRR09qCm/oTaEQvKWq50CWFpr6mhZkmPFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885692; c=relaxed/simple; bh=tSaUcqD7eHSaObZjjijtJrsg0WBYhM+Yr7DGFDUV5w0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JI64+6TYleVzx3YrInJqkg8NsbVyHFtGEM2lyOwq/iREzweLcsjtix46524OOvtXe/Wc69f4deimMiENDspjbeVkxaCRJeLrM4Q8D3/8VZi4BIYRKTnROqFFLZN6aLYobmEvgxJdgnNZ7MBYXsyTqZsyGJcXZsrVZcslrd+UeJk= 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=DJJY7myM; arc=none smtp.client-ip=217.70.183.199 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="DJJY7myM" Received: by mail.gandi.net (Postfix) with ESMTPSA id CD912FF806; Wed, 2 Oct 2024 16:14:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885688; 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=DJJY7myMzwD0eFIM6O5nZZgsiKHs6nmFpJ25Mkh5PgLSrCZnPbsMFef8Z5gmZEwO7Dnx2Z CCK0vu74+h7DMpMF/W2QvExmrsCig/HdAnR/sX0k6yxTBXgCIEoU6C9ilFNF9rHGBFgu2B gO6QAxJI0u7pbA5wXiFQvYCm67846dJmmDmr0fTGGWQqornUGTCb2LPqEuw7Qhk/AUftX2 Lr8ae/Ah4VHATEmkUYp/PoQJfyOu2tBxwW+TC6abHb5p3odwFcn1qQnkSrtHJaPOUhgwZr pfMzrs7KDR+qitBSFrVZfCfPEbgORE78ZwzERL+X62lhFNpppGiMnoKha4wibw== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:19 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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:14:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820041 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 B962B1D096B; Wed, 2 Oct 2024 16:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885692; cv=none; b=A8A74GtI8EMOT+ksIcHxBnEPX/mz3S0h5V/VGnkqWUY+bfjpwy+OHITS9KT8hNgKb0SCWrA18RujC7i/W/DgtFQ9VeItXfCeYQhCdE0iUcmQ81uMb2ghzCGSoLYR+EBtj1U4Q24LJNa8jJdE7mSHoQhXqqIygaW0yM+nuw4nyWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885692; c=relaxed/simple; bh=m5UVg9uMgWclNQ0ZC+nkcUjkJnAqUFQoCJthQiR5YHE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qVGuHzCiEYBbHxYbuuH4pZhCm8w4w0MSLuYSSRpzWye2mY9s/JtUHSMU+mILUJU7B5WhRHRfFXlJ9mwTQJJV3wcFJi1+jdgUaegZfzWCgYjVVI/yLWKozLrPG/aX8NEiTeVpIK2ZrMnPtn+ajAL0rG8WkHQDbTyD4dhMi8zzgTc= 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=nE0MSvNd; arc=none smtp.client-ip=217.70.183.199 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="nE0MSvNd" Received: by mail.gandi.net (Postfix) with ESMTPSA id A7E85FF808; Wed, 2 Oct 2024 16:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885689; 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=nE0MSvNdgeUcQMJWWndaLmheX9aF/TItumjgg0Z8g23dBBVMLOSlNGZ2s5yscptKMemPYz +fz4xybb0Ot5/OyY4sGTkAq8A5OAK1aLTojmmqGOl5H2u/7lU6+TGPiiPapTsM9s3GcEM4 JzTl1KfRw2Dyr9fFNMDYZVsUiS4PQRMGDAUu8xAQCxLTw3qHu928leIVjvjVHBUVvbYtGH XDLMgiL7tVBANwoewKJyjI61rSASesVSO7dazSUzqqmvsAkfxZIE4pCUyrHg/420ibWrlD nSaBTyrNrnbCvsNP7gvi2JT3CiYRtZQexwl+dOJtxo3raS8F5Uiv4Gaijt4QVw== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:20 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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/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:14:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820045 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 3E97C1D14E4; Wed, 2 Oct 2024 16:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885695; cv=none; b=HaI33inr7OiwOZGlfMN1GdgBhaMi6VqBmaUbaSGUyuLBIJsRWaviSNlTJFwoCs3rRRY/umPa63Od82g59mLhEFeT/nceFCYK51kr6vt81lK8J2rdZ58UVkn03uyVqX+pcG2xpl2DpFiZXUfAAorXih+ljVKOJIOl4etebLBeq1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885695; c=relaxed/simple; bh=6fP4GiSZHpLwe8j151kxCCfVBFZI6rH3qmFV0hsMm8M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KTFJxM5iR5qxGz7XOkFaFzNSqm7EwIeuqxamJ5HXg656xKB/QnybNrlMKXDPP5AluMrwNmpGimF+qxcWMSVwhw/nqG32rMbE1twTrdWaeoZljzmZybS4I3Lt/bZwQL1GKsy+83hUUtO5lpeV97U/i1rlctaoFb4IKe3gMFju9QY= 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=eeAH35qR; arc=none smtp.client-ip=217.70.183.199 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="eeAH35qR" Received: by mail.gandi.net (Postfix) with ESMTPSA id 72803FF811; Wed, 2 Oct 2024 16:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885690; 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=eeAH35qR6wo0HlI/DnHR/+W7ZaBLCpS9kM1KlvBNpRA4uCZ1fEzlCvqGj9zF5JuLMIbU6D voUQdH2okeHTcXmQ5L77K0Np/6X2/Kfi8xqBYzK4cMehek8RRNvk1y1s9/QTztVVAEqqDH dmYk7cmuFtELQNthGalDtELz/htsr11H87xyaJtvlvsn699dlYyPccRkk5o0Okl0LMatvf 9r9Nux6EslkB/It3Y3hIvEtfheRppvMZ8+CycV029lJulPS15dt6fN0qACf9yv3MNVm3k/ 9VH/eTZHubd8ZUHb5d+UO0ZNMkKBOIjziSYjscYUxIdvbdmiHDp962St9AeukQ== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:21 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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:14:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820046 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 4E8E61D14EB; Wed, 2 Oct 2024 16:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885695; cv=none; b=WUHCljjJrBYB7GlnjgFVkR+VVY9tk52AkOGnWnoBfAHYG2eDSPFrXalKUk+pcpYl/G3ZcxYQm4zaM+nqygit9lLk5lDfUbCYhNle3T9ABaaCmZbNJ6kSb2He0WOhcvMphGUHxe9zG7EbVbPBGasrScTMCAEUYK/RcqzTCMnPb0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885695; c=relaxed/simple; bh=TmppxM30hDT5N6ZYZ9A5WGjGkeUb4dF0hUftJdet5Zk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a1L+cgYt6KXTtIgD9nfv2sSuJKj50aZ1WOiJ5NMG17TGxry/PwPsjHx4Fp72gNO9NjJC59Z6chK6DKlqCCLfHbJsAMurnJ7gBc/GDlvgISy2fSvhpntXrCHLsWqyDHxCjQWh8HT1C76948kcVUF3GeUb8u11gJ+WN6+yaKIad5o= 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=aUxJwbg+; arc=none smtp.client-ip=217.70.183.199 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="aUxJwbg+" Received: by mail.gandi.net (Postfix) with ESMTPSA id 47921FF807; Wed, 2 Oct 2024 16:14:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885691; 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=aUxJwbg+nBnnAuJ2BKBfn9HAO+DKiB+M78asXWhgS1cJhsG0BICzs1DOnTY26umO/wkqIY lKWa4lt/SNinKheT47Db4uveFXzNvVQKiW34+zjovNh4M3WuAPIyhwOzT9ME2Tyyxz/Ew6 v0jKGdMyAYER35xhbV/BZOssOz8zIA3xg0HiWH9ubWhHPf0sLeSL/5YeNoiPmp8ak5gO7R HXaL7z1n8RT+Ez1vNfC5WaGBVXsz7FHFR8NCt4tRNGNVL5ut7Q6dRogTuEog93PCNIq+A7 ofsjiPAkPoNEBY7DNiQkvEOMvDmHDOpzHn4gpfubH41FCnyaXdsToSnYDiL1yQ== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:22 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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:14:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kory Maincent X-Patchwork-Id: 13820048 X-Patchwork-Delegate: kuba@kernel.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 76F181D14FB; Wed, 2 Oct 2024 16:14:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885696; cv=none; b=PkNlPF2vt9AjqR8bKrefeHSt1GkKtGhlK5HfDU2InY0JPTJaaAMLv71AMHyX7oUDpjVlIgEIvwK7Jq5QjkCt+DpQZsh8R5DaBWMwOh4cdPoiwVgAR3P2fLlHmPIGIoRqJ7KGxLMuX7Btr8EtUtkUsid4SixSk1EgwDq2UQle+pY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727885696; 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=ZAkFCakBeXEVjixhBAWfd3nILjmhqj3K6AXQU0VBR6p5GrfYnNw+hpm9bEUNF6zkwPw0GTXL7nfOvt83Cszj+IjNMbly25hYKqp3yY0Btwzh55DI4reKysW7/VqRK85+eZ0pWZXcpwjgVDQgopMEV7WmYhrRFDcHJRyDrMjLkjU= 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=N1Zb+dKN; arc=none smtp.client-ip=217.70.183.199 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="N1Zb+dKN" Received: by mail.gandi.net (Postfix) with ESMTPSA id 1ABDFFF810; Wed, 2 Oct 2024 16:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1727885691; 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=N1Zb+dKNgAJFGEWCTdOE2CZBgCVMfuQ+d+oHC35W65f2kbkd+ptp1TP5Pz/N/tYijWdFfu LPwIrTDn5gOUlG3V8784RR0FfcLFfv+wGAQD4dgA0/CkHNnaTD+CYHQtRasi9ZPhT5mYyy rcocjNz3AsvV7e/PniUtoozNTe735PPKdAY3ZKkTEyMgHQ3+P5OGpGbZ1UjzvtkwnE0whm 7CNYkIxsm08v7fYzFycYeKSA371Ub6nMRQqgQQFKzQj+/gJ88SaAxNTrHBWQ0HEQwIZlhS EuwhzWjhwR96MXUxpz++lpTkY8YHiJGkdTq6cbRYG7TTiEtxd5gUoSbTor72eQ== From: Kory Maincent Date: Wed, 02 Oct 2024 18:14:23 +0200 Subject: [PATCH 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-eb067b78d6cf@bootlin.com> References: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@bootlin.com> In-Reply-To: <20241002-feature_poe_port_prio-v1-0-eb067b78d6cf@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; }