mbox series

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

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

Message

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

changes are listed within patches.

Oleksij Rempel (7):
  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
  dt-bindings: net: pse-dt: add bindings for regulator based PoDL PSE
    controller
  net: pse-pd: add regulator based PSE driver

 .../devicetree/bindings/net/ethernet-phy.yaml |   6 +
 .../net/pse-pd/podl-pse-regulator.yaml        |  40 ++
 .../bindings/net/pse-pd/pse-controller.yaml   |  28 ++
 Documentation/networking/ethtool-netlink.rst  |  59 +++
 drivers/net/Kconfig                           |   2 +
 drivers/net/Makefile                          |   1 +
 drivers/net/mdio/fwnode_mdio.c                |  55 ++-
 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                 | 363 ++++++++++++++++++
 drivers/net/pse-pd/pse_regulator.c            | 147 +++++++
 include/linux/phy.h                           |   2 +
 include/linux/pse-pd/pse.h                    | 156 ++++++++
 include/uapi/linux/ethtool.h                  |  45 +++
 include/uapi/linux/ethtool_netlink.h          |  17 +
 net/ethtool/Makefile                          |   3 +-
 net/ethtool/common.h                          |   1 +
 net/ethtool/netlink.c                         |  19 +
 net/ethtool/netlink.h                         |   4 +
 net/ethtool/pse-pd.c                          | 178 +++++++++
 21 files changed, 1144 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/pse-pd/podl-pse-regulator.yaml
 create mode 100644 Documentation/devicetree/bindings/net/pse-pd/pse-controller.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_regulator.c
 create mode 100644 include/linux/pse-pd/pse.h
 create mode 100644 net/ethtool/pse-pd.c

Comments

Jakub Kicinski Sept. 2, 2022, 3:21 a.m. UTC | #1
On Wed, 31 Aug 2022 15:32:38 +0200 Oleksij Rempel wrote:
> +/**
> + * pse_ethtool_get_status - get status of PSE control
> + * @psec: PSE control pointer
> + * @extack: extack for reporting useful error messages
> + * @status: struct to store PSE status
> + */
> +int pse_ethtool_get_status(struct pse_control *psec,
> +			   struct netlink_ext_ack *extack,
> +			   struct pse_control_status *status)
> +{
> +	const struct pse_controller_ops *ops;
> +	int err;
> +
> +	if (!psec)
> +		return 0;

Defensive programming?

> +	if (WARN_ON(IS_ERR(psec)))
> +		return -EINVAL;
> +
> +	ops = psec->pcdev->ops;
> +
> +	if (!ops->ethtool_get_status) {
> +		NL_SET_ERR_MSG(extack,
> +			       "PSE driver does not support status report");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	mutex_lock(&psec->pcdev->lock);
> +	err = ops->ethtool_get_status(psec->pcdev, psec->id, extack, status);
> +	mutex_unlock(&psec->pcdev->lock);
> +
> +	return err;
> +}
> +EXPORT_SYMBOL_GPL(pse_ethtool_get_status);
> +
> +/**
> + * pse_ethtool_set_config - set PSE control configuration
> + * @psec: PSE control pointer
> + * @extack: extack for reporting useful error messages
> + * @config: Configuration of the test to run
> + */
> +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;
> +
> +	if (!psec)
> +		return 0;
> +
> +	if (WARN_ON(IS_ERR(psec)))
> +		return -EINVAL;

ditto

> +	ops = psec->pcdev->ops;
> +
> +	if (!ops->ethtool_set_config) {
> +		NL_SET_ERR_MSG(extack,
> +			       "PSE driver does not configuration");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	mutex_lock(&psec->pcdev->lock);
> +	err = ops->ethtool_set_config(psec->pcdev, psec->id, extack, config);
> +	mutex_unlock(&psec->pcdev->lock);
> +
> +	return err;
> +}
> +EXPORT_SYMBOL_GPL(pse_ethtool_set_config);

> +int pse_ethtool_get_status(struct pse_control *psec,
> +			   struct netlink_ext_ack *extack,
> +			   struct pse_control_status *status)
> +{
> +	return -ENOTSUPP;

EOPNOTSUPP, please run checkpatch --strict on this patch.
All of the complaints look legit at a glance.


> +	ETHTOOL_MSG_PSE_NTF,

I don't see you calling the ethtool_notify() function, does this ever

> +static int pse_prepare_data(const struct ethnl_req_info *req_base,
> +			       struct ethnl_reply_data *reply_base,
> +			       struct genl_info *info)
> +{
> +	struct pse_reply_data *data = PSE_REPDATA(reply_base);
> +	struct net_device *dev = reply_base->dev;
> +	int ret;
> +
> +	ret = ethnl_ops_begin(dev);
> +	if (ret < 0)
> +		return 0;

humpf, return ret;?

> +	ret = pse_get_pse_attributs(dev, info->extack, data);
> +
> +	ethnl_ops_complete(dev);
> +
> +	return ret;
> +}
> +
> +static int pse_reply_size(const struct ethnl_req_info *req_base,
> +			  const struct ethnl_reply_data *reply_base)
> +{
> +	const struct pse_reply_data *data = PSE_REPDATA(reply_base);
> +	const struct pse_control_status *st = &data->status;
> +	int len = 0;
> +
> +	if (st->podl_admin_state >= 0)

UNKNOWN is now 1, should be > 0 ?

> +		len += nla_total_size(sizeof(u32)); /* _PODL_PSE_ADMIN_STATE */
> +	if (st->podl_pw_status >= 0)
> +		len += nla_total_size(sizeof(u32)); /* _PODL_PSE_PW_D_STATUS */
> +
> +	return len;
> +}

> +	if (!phydev)
> +		return -EOPNOTSUPP;
> +
> +	if (!phydev->psec)
> +		ret = -EOPNOTSUPP;

Would be good to slap an extack msg on the two errors here.

> +	else
> +		ret = pse_ethtool_set_config(phydev->psec, extack, &config);

And avoid indenting the success path. So the !phydev->psec should
contain a return.

> +	return ret;
> +}
Jakub Kicinski Sept. 2, 2022, 3:22 a.m. UTC | #2
On Wed, 31 Aug 2022 15:32:38 +0200 Oleksij Rempel wrote:
> Add interface to support Power Sourcing Equipment. At current step it
> provides generic way to address all variants of PSE devices as defined
> in IEEE 802.3-2018 but support only objects specified for IEEE 802.3-2018 104.4
> PoDL Power Sourcing Equipment (PSE).

include/linux/pse-pd/pse.h:37: warning: Function parameter or member 'podl_admin_state' not described in 'pse_control_status'
include/linux/pse-pd/pse.h:37: warning: Function parameter or member 'podl_pw_status' not described in 'pse_control_status'
include/linux/pse-pd/pse.h:52: warning: Function parameter or member 'ethtool_get_status' not described in 'pse_controller_ops'
include/linux/pse-pd/pse.h:52: warning: Function parameter or member 'ethtool_set_config' not described in 'pse_controller_ops'