netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Kory Maincent <kory.maincent@bootlin.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Russ Weight <russ.weight@linux.dev>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Mark Brown <broonie@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org, devicetree@vger.kernel.org,
	Dent Project <dentproject@linuxfoundation.org>
Subject: Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework
Date: Sat, 2 Mar 2024 22:35:52 +0100	[thread overview]
Message-ID: <ZeObuKHkPN3tiWz_@pengutronix.de> (raw)
In-Reply-To: <20240227-feature_poe-v5-13-28f0aa48246d@bootlin.com>

On Tue, Feb 27, 2024 at 03:42:55PM +0100, Kory Maincent wrote:
> Integrate the regulator framework to the PSE framework for enhanced
> access to features such as voltage, power measurement, and limits, which
> are akin to regulators. Additionally, PSE features like port priorities
> could potentially enhance the regulator framework. Note that this
> integration introduces some implementation complexity, including wrapper
> callbacks and nested locks, but the potential benefits make it worthwhile.
> 
> Regulator are using enable counter with specific behavior.
> Two calls to regulator_disable will trigger kernel warnings.
> If the counter exceeds one, regulator_disable call won't disable the
> PSE PI. These behavior isn't suitable for PSE control.
> Added a boolean 'enabled' state to prevent multiple calls to

Please rename rename "enabled" to "admin_state_enabled". This variable
do not reflect real device state, it reflects only user configuration.

...  
> @@ -120,15 +118,9 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
>  	u32 phy_id;
>  	int rc;
>  
> -	psec = fwnode_find_pse_control(child);
> -	if (IS_ERR(psec))
> -		return PTR_ERR(psec);
> -
>  	mii_ts = fwnode_find_mii_timestamper(child);
> -	if (IS_ERR(mii_ts)) {
> -		rc = PTR_ERR(mii_ts);
> -		goto clean_pse;
> -	}
> +	if (IS_ERR(mii_ts))
> +		return PTR_ERR(mii_ts);
>  
>  	is_c45 = fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45");
>  	if (is_c45 || fwnode_get_phy_id(child, &phy_id))
> @@ -161,6 +153,12 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
>  			goto clean_phy;
>  	}
>  
> +	psec = dev_find_pse_control(&phy->mdio.dev);
> +	if (IS_ERR(psec)) {
> +		rc = PTR_ERR(psec);
> +		goto unregister_phy;
> +	}
> +

I do not think it is a good idea to make PSE controller depend on
phy->mdio.dev. The only reason why we have fwnode_find_pse_control()
here was the missing port abstraction.

...
> +static int
> +devm_pse_pi_regulator_register(struct pse_controller_dev *pcdev,
> +			       char *name, int id)
> +{
> +	struct regulator_config rconfig = {0};
> +	struct regulator_desc *rdesc;
> +	struct regulator_dev *rdev;
> +
> +	rdesc = devm_kzalloc(pcdev->dev, sizeof(*rdesc), GFP_KERNEL);
> +	if (!rdesc)
> +		return -ENOMEM;
> +
> +	/* Regulator descriptor id have to be the same as its associated
> +	 * PSE PI id for the well functioning of the PSE controls.
> +	 */
> +	rdesc->id = id;
> +	rdesc->name = name;
> +	rdesc->type = REGULATOR_CURRENT;
> +	rdesc->ops = &pse_pi_ops;
> +	rdesc->owner = pcdev->owner;
> +
> +	rconfig.dev = pcdev->dev;
> +	rconfig.driver_data = pcdev;
> +	rconfig.init_data = &pse_pi_initdata;

Please add input supply to track all dependencies:
        if (of_property_present(np, "vin-supply"))                                                                    
	                config->input_supply = "vin";

May be better to make it not optional...

Should be tested, but if, instead of "vin-supply", we will use
"pse-supply" it will make most part of pse_regulator.c obsolete.

....  
> @@ -310,6 +452,20 @@ pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index)
>  		return ERR_PTR(-ENODEV);
>  	}
>  
> +	psec->ps = devm_regulator_get_exclusive(dev,
> +						rdev_get_name(pcdev->pi[index].rdev));
> +	if (IS_ERR(psec->ps)) {
> +		kfree(psec);
> +		return ERR_CAST(psec->ps);
> +	}
> +
> +	ret = regulator_is_enabled(psec->ps);
> +	if (ret < 0) {
> +		kfree(psec);
> +		return ERR_PTR(ret);
> +	}
> +	pcdev->pi[index].enabled = ret;

If I see it correctly, it will prevent us to refcount a request from
user space. So, the runtime PM may suspend PI.

> +
>  	psec->pcdev = pcdev;
>  	list_add(&psec->list, &pcdev->pse_control_head);
>  	psec->id = index;
> @@ -344,7 +500,8 @@ static int psec_id_legacy_xlate(struct pse_controller_dev *pcdev,
>  	return pse_spec->args[0];
>  }
>  
> -struct pse_control *of_pse_control_get(struct device_node *node)
> +struct pse_control *of_pse_control_get(struct device *dev,
> +				       struct device_node *node)
>  {
>  	struct pse_controller_dev *r, *pcdev;
>  	struct of_phandle_args args;
> @@ -394,7 +551,7 @@ struct pse_control *of_pse_control_get(struct device_node *node)
>  	}
>  
>  	/* pse_list_mutex also protects the pcdev's pse_control list */
> -	psec = pse_control_get_internal(pcdev, psec_id);
> +	psec = pse_control_get_internal(dev, pcdev, psec_id);
>  
>  out:
>  	mutex_unlock(&pse_list_mutex);
> @@ -443,21 +600,24 @@ int pse_ethtool_set_config(struct pse_control *psec,
>  			   struct netlink_ext_ack *extack,
>  			   const struct pse_control_config *config)
>  {
> -	const struct pse_controller_ops *ops;
> -	int err;
> -
> -	ops = psec->pcdev->ops;
> +	int err = 0;
>  
> -	if (!ops->ethtool_set_config) {
> -		NL_SET_ERR_MSG(extack,
> -			       "PSE driver does not configuration");
> -		return -EOPNOTSUPP;
> +	/* Look at enabled status to not call regulator_enable or
> +	 * regulator_disable twice creating a regulator counter mismatch
> +	 */
> +	switch (config->c33_admin_control) {
> +	case ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED:
> +		if (!psec->pcdev->pi[psec->id].enabled)
> +			err = regulator_enable(psec->ps);
> +		break;
> +	case ETHTOOL_C33_PSE_ADMIN_STATE_DISABLED:
> +		if (psec->pcdev->pi[psec->id].enabled)
> +			err = regulator_disable(psec->ps);
> +		break;
> +	default:
> +		err = -EOPNOTSUPP;
>  	}

This change seems to break PoDL support

> -	mutex_lock(&psec->pcdev->lock);
> -	err = ops->ethtool_set_config(psec->pcdev, psec->id, extack, config);
> -	mutex_unlock(&psec->pcdev->lock);
> -
>  	return err;

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  parent reply	other threads:[~2024-03-02 21:36 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 14:42 [PATCH net-next v5 00/17] net: Add support for Power over Ethernet (PoE) Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 01/17] MAINTAINERS: net: Add Oleksij to pse-pd maintainers Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 02/17] of: property: Add fw_devlink support for pse parent Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 03/17] net: pse-pd: Rectify and adapt the naming of admin_cotrol member of struct pse_control_config Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 04/17] ethtool: Expand Ethernet Power Equipment with c33 (PoE) alongside PoDL Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 05/17] net: pse-pd: Introduce PSE types enumeration Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 06/17] net: ethtool: pse-pd: Expand pse commands with the PSE PoE interface Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 07/17] netlink: specs: Modify pse attribute prefix Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 08/17] netlink: specs: Expand the pse netlink command with PoE interface Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 09/17] MAINTAINERS: Add myself to pse networking maintainer Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 10/17] net: pse-pd: Add support for PSE PIs Kory Maincent
2024-03-01 14:24   ` Oleksij Rempel
2024-03-01 16:10     ` Köry Maincent
2024-03-01 16:48       ` Oleksij Rempel
2024-02-27 14:42 ` [PATCH net-next v5 11/17] dt-bindings: net: pse-pd: Add another way of describing several " Kory Maincent
2024-02-28 16:42   ` Rob Herring
2024-02-27 14:42 ` [PATCH net-next v5 12/17] net: pse-pd: Add support for setup_pi_matrix callback Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework Kory Maincent
2024-02-28  0:56   ` Jakub Kicinski
2024-02-29 10:19     ` Köry Maincent
2024-02-28 12:48   ` Simon Horman
2024-02-29  9:41     ` Köry Maincent
2024-03-02 21:35   ` Oleksij Rempel [this message]
2024-03-04  9:27     ` Köry Maincent
2024-03-04 10:31       ` Oleksij Rempel
2024-03-21 16:15         ` Kory Maincent
2024-03-21 16:43           ` Oleksij Rempel
2024-03-22 10:39             ` Kory Maincent
2024-03-22 14:07               ` Oleksij Rempel
2024-03-22 14:22                 ` Kory Maincent
2024-03-04 13:32       ` Andrew Lunn
2024-03-04 13:39         ` Oleksij Rempel
2024-03-04 13:53           ` Andrew Lunn
2024-03-04 14:23             ` Oleksij Rempel
2024-02-27 14:42 ` [PATCH net-next v5 14/17] dt-bindings: net: pse-pd: Add bindings for PD692x0 PSE controller Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 15/17] net: pse-pd: Add PD692x0 PSE controller driver Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 16/17] dt-bindings: net: pse-pd: Add bindings for TPS23881 PSE controller Kory Maincent
2024-02-27 14:42 ` [PATCH net-next v5 17/17] net: pse-pd: Add TI TPS23881 PSE controller driver Kory Maincent
2024-02-28 12:53   ` Simon Horman
2024-02-29 11:09     ` Köry Maincent
2024-02-27 15:31 ` [PATCH net-next v5 00/17] net: Add support for Power over Ethernet (PoE) Jamal Hadi Salim
2024-03-08 13:54   ` Köry Maincent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZeObuKHkPN3tiWz_@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=andrew@lunn.ch \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=dentproject@linuxfoundation.org \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=frowand.list@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hkallweit1@gmail.com \
    --cc=kory.maincent@bootlin.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mcgrof@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=russ.weight@linux.dev \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).