From nobody Sun Nov 24 08:03:08 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D55F1E0DB6; Thu, 21 Nov 2024 14:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200259; cv=none; b=LO1H2tXC6DxyF44JgdFH5KVNeuv5bMkC5TBXbiqEhnj7mtRTSkpbBDAJ9VjRxXvgaAJrvPm+Wid/L3ws/ruatberYIWKUFPM1wphJDL8PPduC7rx4MtsRUfd8GN2+YBCRUvka5Yx8Kh0lleQ9lWqBvYDvQRmRmXyo/U0X7WiD/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200259; c=relaxed/simple; bh=azFcBWJegH1Stk6Ga1l7n8qmM3wLmOuNlbKSXEZ9MXc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BD469WxIYu+4DdqN3udxsICDQocBWeVnSgGFfTSW1LoyBmZGiglPLicKVEnp0P+CH93Q0wSkUbP58gYdxH9gbormFc1QLGb7Dw4zUDnQQ4LtZBz74faqzRUokMIT+PpKO6DUTksozT41QQXWMqcOqkbjI0MrTpGVHjh8F2g3To8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=cxH1G9QS; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="cxH1G9QS" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4633B40002; Thu, 21 Nov 2024 14:44:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bcgJuKLJismZ9vaz8zGQ8LaYUmd4CadaQ0PkC7ZGheY=; b=cxH1G9QSkI3fHw+hVkOTh19zEhmIjiqE2yr3gz/qYrdT+v8VQ27xFHeaxrsKjJVDQcQMBo eRzO4Gf77LhXtAWqLVpw7ppelzx2pV9YCDdzCXwb2hiciQND94uPeynG/IY5yZpSp8xjoV EWhwxpV2xo17aacnSLAjvo5OWIVYPRF7Iq07GtGZWLr0kXNa5FYm6zyUFBrf6j8elPhbRp 5kwTDP+ERhgvXX//BkdpqS0GiVmWmC4GGZ8Ue1/dQcul92YrNaQypxOjoDnVwOM7MDSuNg 8OY86xlqJGOvGjIjFcqaEsfRyzVZfyhCsjj5Zu3QN8TtkZxS2ANNEtNo2AMRPg== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:45 +0100 Subject: [PATCH RFC net-next v3 19/27] net: pse-pd: Add support for PSE power domains Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-19-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Introduce PSE power domain support as groundwork for upcoming port priority features. Multiple PSE PIs can now be grouped under a single PSE power domain, enabling future enhancements like defining available power budgets, port priority modes, and disconnection policies. This setup will allow the system to assess whether activating a port would exceed the available power budget, preventing over-budget states proactively. Signed-off-by: Kory Maincent --- Changes in v3: - Remove pw_budget variable. Changes in v2: - new patch. --- drivers/net/pse-pd/pse_core.c | 95 +++++++++++++++++++++++++++++++++++++++= ++++ include/linux/pse-pd/pse.h | 2 + 2 files changed, 97 insertions(+) diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c index d4cf5523194d..8b9ce8c6ecef 100644 --- a/drivers/net/pse-pd/pse_core.c +++ b/drivers/net/pse-pd/pse_core.c @@ -15,6 +15,7 @@ static DEFINE_MUTEX(pse_list_mutex); static LIST_HEAD(pse_controller_list); static DEFINE_IDA(pse_ida); +static DEFINE_XARRAY_ALLOC(pse_pw_d_map); =20 /** * struct pse_control - a PSE control @@ -35,6 +36,16 @@ struct pse_control { struct phy_device *attached_phydev; }; =20 +/** + * struct pse_power_domain - a PSE power domain + * @id: ID of the power domain + * @supply: Power supply the Power Domain + */ +struct pse_power_domain { + int id; + struct regulator *supply; +}; + static int of_load_single_pse_pi_pairset(struct device_node *node, struct pse_pi *pi, int pairset_num) @@ -433,6 +444,84 @@ devm_pse_pi_regulator_register(struct pse_controller_d= ev *pcdev, return 0; } =20 +static void pse_flush_pw_ds(struct pse_controller_dev *pcdev) +{ + struct pse_power_domain *pw_d; + int i; + + for (i =3D 0; i < pcdev->nr_lines; i++) { + pw_d =3D xa_load(&pse_pw_d_map, pcdev->pi[i].pw_d->id); + if (pw_d) { + regulator_put(pw_d->supply); + xa_erase(&pse_pw_d_map, pw_d->id); + } + } +} + +static struct pse_power_domain *devm_pse_alloc_pw_d(struct device *dev) +{ + struct pse_power_domain *pw_d; + int index, ret; + + pw_d =3D devm_kzalloc(dev, sizeof(*pw_d), GFP_KERNEL); + if (!pw_d) + return ERR_PTR(-ENOMEM); + + ret =3D xa_alloc(&pse_pw_d_map, &index, pw_d, XA_LIMIT(1, INT_MAX), GFP_K= ERNEL); + if (ret) + return ERR_PTR(ret); + + pw_d->id =3D index; + return pw_d; +} + +static int pse_register_pw_ds(struct pse_controller_dev *pcdev) +{ + int i; + + for (i =3D 0; i < pcdev->nr_lines; i++) { + struct regulator_dev *rdev =3D pcdev->pi[i].rdev; + struct pse_power_domain *pw_d; + struct regulator *supply; + bool present =3D false; + unsigned long index; + + /* No regulator or regulator parent supply registered. + * We need a regulator parent to register a PSE power domain + */ + if (!rdev || !rdev->supply) + continue; + + xa_for_each(&pse_pw_d_map, index, pw_d) { + /* Power supply already registered as a PSE power + * domain. + */ + if (regulator_is_equal(pw_d->supply, rdev->supply)) { + present =3D true; + pcdev->pi[i].pw_d =3D pw_d; + break; + } + } + if (present) + continue; + + pw_d =3D devm_pse_alloc_pw_d(pcdev->dev); + if (IS_ERR_OR_NULL(pw_d)) + return PTR_ERR(pw_d); + + supply =3D regulator_get(&rdev->dev, rdev->supply_name); + if (IS_ERR(supply)) { + xa_erase(&pse_pw_d_map, pw_d->id); + return PTR_ERR(supply); + } + + pw_d->supply =3D supply; + pcdev->pi[i].pw_d =3D pw_d; + } + + return 0; +} + /** * pse_controller_register - register a PSE controller device * @pcdev: a pointer to the initialized PSE controller device @@ -491,6 +580,11 @@ int pse_controller_register(struct pse_controller_dev = *pcdev) goto free_pse_ida; } =20 + ret =3D pse_register_pw_ds(pcdev); + + if (ret) + goto free_pse_ida; + mutex_lock(&pse_list_mutex); list_add(&pcdev->list, &pse_controller_list); mutex_unlock(&pse_list_mutex); @@ -509,6 +603,7 @@ EXPORT_SYMBOL_GPL(pse_controller_register); */ void pse_controller_unregister(struct pse_controller_dev *pcdev) { + pse_flush_pw_ds(pcdev); pse_release_pis(pcdev); ida_free(&pse_ida, pcdev->id); mutex_lock(&pse_list_mutex); diff --git a/include/linux/pse-pd/pse.h b/include/linux/pse-pd/pse.h index be6e967f9ac3..9d06eb9ca663 100644 --- a/include/linux/pse-pd/pse.h +++ b/include/linux/pse-pd/pse.h @@ -140,12 +140,14 @@ struct pse_pi_pairset { * @np: device node pointer of the PSE PI node * @rdev: regulator represented by the PSE PI * @admin_state_enabled: PI enabled state + * @pw_d: Power domain of the PSE PI */ struct pse_pi { struct pse_pi_pairset pairset[2]; struct device_node *np; struct regulator_dev *rdev; bool admin_state_enabled; + struct pse_power_domain *pw_d; }; =20 /** --=20 2.34.1