mbox series

[net-next,v2,0/7] add generic PSE support

Message ID 20220825130211.3730461-1-o.rempel@pengutronix.de
Headers show
Series add generic PSE support | expand

Message

Oleksij Rempel Aug. 25, 2022, 1:02 p.m. UTC
Add generic support for the Ethernet Power Sourcing Equipment.

changes are listed within patches.

Oleksij Rempel (7):
  dt-bindings: net: pse-dt: add bindings for generic PSE controller
  dt-bindings: net: phy: add PoDL PSE property
  net: add framework to support Ethernet PSE and PDs devices
  net: mdiobus: fwnode_mdiobus_register_phy() rework error handling
  net: mdiobus: search for PSE nodes by parsing PHY nodes.
  ethtool: add interface to interact with Ethernet Power Equipment
  net: pse-pd: add generic PSE driver

 .../devicetree/bindings/net/ethernet-phy.yaml |   5 +
 .../bindings/net/pse-pd/generic-pse.yaml      |  95 +++++
 Documentation/networking/ethtool-netlink.rst  |  60 +++
 drivers/net/Kconfig                           |   2 +
 drivers/net/Makefile                          |   1 +
 drivers/net/mdio/fwnode_mdio.c                |  58 ++-
 drivers/net/phy/phy_device.c                  |   2 +
 drivers/net/pse-pd/Kconfig                    |  22 +
 drivers/net/pse-pd/Makefile                   |   6 +
 drivers/net/pse-pd/pse_core.c                 | 381 ++++++++++++++++++
 drivers/net/pse-pd/pse_generic.c              | 148 +++++++
 include/linux/ethtool.h                       |  27 ++
 include/linux/phy.h                           |   2 +
 include/linux/pse-pd/pse.h                    | 134 ++++++
 include/uapi/linux/ethtool.h                  |  50 +++
 include/uapi/linux/ethtool_netlink.h          |  17 +
 net/ethtool/Makefile                          |   3 +-
 net/ethtool/common.c                          |  10 +
 net/ethtool/common.h                          |   1 +
 net/ethtool/netlink.c                         |  19 +
 net/ethtool/netlink.h                         |   4 +
 net/ethtool/pse-pd.c                          | 187 +++++++++
 22 files changed, 1222 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/pse-pd/generic-pse.yaml
 create mode 100644 drivers/net/pse-pd/Kconfig
 create mode 100644 drivers/net/pse-pd/Makefile
 create mode 100644 drivers/net/pse-pd/pse_core.c
 create mode 100644 drivers/net/pse-pd/pse_generic.c
 create mode 100644 include/linux/pse-pd/pse.h
 create mode 100644 net/ethtool/pse-pd.c

Comments

Russell King (Oracle) Aug. 25, 2022, 1:11 p.m. UTC | #1
On Thu, Aug 25, 2022 at 03:02:09PM +0200, Oleksij Rempel wrote:
> +static struct pse_control *
> +fwnode_find_pse_control(struct fwnode_handle *fwnode)
> +{
> +	struct pse_control *psec;
> +	struct device_node *np;
> +
> +	if (is_acpi_node(fwnode))
> +		return NULL;
> +
> +	np = to_of_node(fwnode);
> +	if (!np)
> +		return NULL;

Doesn't to_of_node() confirm that the fwnode is a DT node? In other
words, isn't the "is_acpi_node()" entirely redundant?

> +
> +	psec = of_pse_control_get(np);
> +	if (IS_ERR_OR_NULL(psec))
> +		return NULL;
> +
> +	return psec;
> +}

So fwnode_find_pse_control() returns NULL on error.

> +	psec = fwnode_find_pse_control(child);
> +	if (IS_ERR(psec))
> +		return PTR_ERR(psec);

This usage expects it to return an error-pointer.

Clearly, there is some disagreement about what fwnode_find_pse_control()
returns on error.
Jakub Kicinski Aug. 25, 2022, 6:07 p.m. UTC | #2
On Thu, 25 Aug 2022 15:02:10 +0200 Oleksij Rempel wrote:
> +void ethtool_set_ethtool_pse_ops(const struct ethtool_pse_ops *ops)
> +{
> +	rtnl_lock();
> +	ethtool_pse_ops = ops;
> +	rtnl_unlock();
> +}
> +EXPORT_SYMBOL_GPL(ethtool_set_ethtool_pse_ops);

Do we really need the loose linking on the PSE ops?
It's not a lot of code, and the pcdev->ops should be 
enough to decouple drivers, it seems.

> +static int pse_set_pse_config(struct net_device *dev,
> +			      struct netlink_ext_ack *extack,
> +			      struct nlattr **tb)
> +{
> +	struct phy_device *phydev = dev->phydev;
> +	struct pse_control_config config = {};
> +	const struct ethtool_pse_ops *ops;
> +	int ret;
> +
> +	if (!tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL])
> +		return 0;

If SET has no useful attrs the usual response is -EINVAL.

> +	ops = ethtool_pse_ops;
> +	if (!ops || !ops->set_config)
> +		return -EOPNOTSUPP;
> +
> +	config.admin_cotrol = nla_get_u8(tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL]);
> +
> +	if (!phydev)
> +		return -EOPNOTSUPP;
> +
> +	// todo resolve phydev dependecy

My lack of phydev understanding and laziness are likely the cause,
but I haven't found an explanation for this todo. What is it about?

> +	if (!phydev->psec)
> +		ret = -EOPNOTSUPP;
> +	else
> +		ret = ops->set_config(phydev->psec, extack, &config);
> +
> +	return ret;
> +}
Jakub Kicinski Aug. 25, 2022, 6:10 p.m. UTC | #3
On Thu, 25 Aug 2022 15:02:10 +0200 Oleksij Rempel wrote:
> +enum ethtool_podl_pse_admin_state {
> +	ETHTOOL_PODL_PSE_ADMIN_STATE_UNKNOWN = 1,

Why define UNKNOWN.. as 1? No real objection here, just in my head
somehow UNKNOWN = 0 or just start from 1.

> +	ETHTOOL_PODL_PSE_ADMIN_STATE_DISABLED,
> +	ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED,
> +
> +	/* add new constants above here */
> +	ETHTOOL_PODL_PSE_ADMIN_STATE_COUNT

Why define count for a value enum like this? For attrs we define it
because it's used to size tables, don't think anyone will size tables
based on states.

There's a bunch of kdoc warnings in the patches as well.
Oleksij Rempel Aug. 25, 2022, 6:47 p.m. UTC | #4
On Thu, Aug 25, 2022 at 11:10:19AM -0700, Jakub Kicinski wrote:
> On Thu, 25 Aug 2022 15:02:10 +0200 Oleksij Rempel wrote:
> > +enum ethtool_podl_pse_admin_state {
> > +	ETHTOOL_PODL_PSE_ADMIN_STATE_UNKNOWN = 1,
> 
> Why define UNKNOWN.. as 1? No real objection here, just in my head
> somehow UNKNOWN = 0 or just start from 1.

I need to keep difference between not supported functionality and
supported but unknown.

> > +	ETHTOOL_PODL_PSE_ADMIN_STATE_DISABLED,
> > +	ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED,
> > +
> > +	/* add new constants above here */
> > +	ETHTOOL_PODL_PSE_ADMIN_STATE_COUNT
> 
> Why define count for a value enum like this? For attrs we define it
> because it's used to size tables, don't think anyone will size tables
> based on states.

ok, i'll remove it.

> There's a bunch of kdoc warnings in the patches as well.

ok.
Oleksij Rempel Aug. 25, 2022, 6:56 p.m. UTC | #5
On Thu, Aug 25, 2022 at 11:07:56AM -0700, Jakub Kicinski wrote:
> On Thu, 25 Aug 2022 15:02:10 +0200 Oleksij Rempel wrote:
> > +void ethtool_set_ethtool_pse_ops(const struct ethtool_pse_ops *ops)
> > +{
> > +	rtnl_lock();
> > +	ethtool_pse_ops = ops;
> > +	rtnl_unlock();
> > +}
> > +EXPORT_SYMBOL_GPL(ethtool_set_ethtool_pse_ops);
> 
> Do we really need the loose linking on the PSE ops?
> It's not a lot of code, and the pcdev->ops should be 
> enough to decouple drivers, it seems.

Right now i have no good idea how to properly decouple pse-pd from phydev.

@Andrew, should i care about it on this stage or it is currently not a
big deal?

> > +static int pse_set_pse_config(struct net_device *dev,
> > +			      struct netlink_ext_ack *extack,
> > +			      struct nlattr **tb)
> > +{
> > +	struct phy_device *phydev = dev->phydev;
> > +	struct pse_control_config config = {};
> > +	const struct ethtool_pse_ops *ops;
> > +	int ret;
> > +
> > +	if (!tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL])
> > +		return 0;
> 
> If SET has no useful attrs the usual response is -EINVAL.

ack

> > +	ops = ethtool_pse_ops;
> > +	if (!ops || !ops->set_config)
> > +		return -EOPNOTSUPP;
> > +
> > +	config.admin_cotrol = nla_get_u8(tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL]);
> > +
> > +	if (!phydev)
> > +		return -EOPNOTSUPP;
> > +
> > +	// todo resolve phydev dependecy
> 
> My lack of phydev understanding and laziness are likely the cause,
> but I haven't found an explanation for this todo. What is it about?

sorry. old artifact, will be removed. It is part of phydev/phylink
related discussion in the last patch version.