Skip to contentSkip to conversation

net: Add support for Power over Ethernet (PoE)

PATCH Superseded Kory Maincent 7 participants 42 messages Feb 27, 2024 – Mar 22, 2024

Subsystems (9)

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Kory Maincent

author maintainer
#0 lore raw

v5 cover net: Add support for Power over Ethernet (PoE)

This patch series aims at adding support for PoE (Power over Ethernet), based on the already existing support for PoDL (Power over Data Line) implementation. In addition, it adds support for two specific PoE controller, the Microchip PD692x0 and the TI TPS23881.

This patch series is sponsored by Dent Project
<[email protected]>.

In detail:
- Patch 1 to 13 prepare net to support PoE devices.
- Patch 14 and 15 add PD692x0 PoE PSE controller driver and its binding.
- Patch 16 and 17 add TI TPS23881 PSE controller driver and its binding.

Changes in v5:
- Fix bindings nit.
- Add supported-polarity parameter to bindings.
- Fix yamllint binding errors.
- Remove the nested lock brought by the use of regulator framework.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Replaced sponsored-by tag by a simple sentence.
- Fix pse_pi node bindings.
- Add pse pi documentation written by Oleksij.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Add patches to add Oleksij and myself to PSE MAINTAINERS.
- Add patches to add pse devlink.
- Add TI TPS23881 PSE controller driver with its binding.
- Replace pse_get_types helper by pse_has_podl and pse_has_c33
- Changed the PSE core bindings.
- Add a setup_pi_matrix callback.
- Register regulator for each PSE PI (Power Interface).
- Changed the PD692x0 bindings.
- Updated PD692x0 drivers to new bindings and PSE PI description.
- Updated PD692x0 drivers according to the reviews and made fixes.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Extract "firmware_loader: Expand Firmware upload error codes patches" to send it alone and get it merge in an immutable branch.
- Add "c33" prefix for PoE variables and enums.
- Enhance few comments.
- Add PSE Documentation.
- Make several changes in pd692x0 driver, mainly for readibility.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Kory Maincent (17):
MAINTAINERS: net: Add Oleksij to pse-pd maintainers
of: property: Add fw_devlink support for pse parent
net: pse-pd: Rectify and adapt the naming of admin_cotrol member of struct pse_control_config
ethtool: Expand Ethernet Power Equipment with c33 (PoE) alongside PoDL
net: pse-pd: Introduce PSE types enumeration
net: ethtool: pse-pd: Expand pse commands with the PSE PoE interface
netlink: specs: Modify pse attribute prefix
netlink: specs: Expand the pse netlink command with PoE interface
MAINTAINERS: Add myself to pse networking maintainer
net: pse-pd: Add support for PSE PIs
dt-bindings: net: pse-pd: Add another way of describing several PSE PIs
net: pse-pd: Add support for setup_pi_matrix callback
net: pse-pd: Use regulator framework within PSE framework
dt-bindings: net: pse-pd: Add bindings for PD692x0 PSE controller
net: pse-pd: Add PD692x0 PSE controller driver
dt-bindings: net: pse-pd: Add bindings for TPS23881 PSE controller
net: pse-pd: Add TI TPS23881 PSE controller driver

 .../bindings/net/pse-pd/microchip,pd692x0.yaml     |  158 +++
 .../bindings/net/pse-pd/pse-controller.yaml        |  100 +-
 .../bindings/net/pse-pd/ti,tps23881.yaml           |   93 ++
 Documentation/netlink/specs/ethtool.yaml           |   33 +-
 Documentation/networking/ethtool-netlink.rst       |   20 +
 Documentation/networking/index.rst                 |    1 +
 Documentation/networking/pse-pd/index.rst          |   10 +
 Documentation/networking/pse-pd/introduction.rst   |   73 ++
 Documentation/networking/pse-pd/pse-pi.rst         |  302 +++++
 MAINTAINERS                                        |    8 +
 drivers/net/mdio/fwnode_mdio.c                     |   29 +-
 drivers/net/pse-pd/Kconfig                         |   20 +
 drivers/net/pse-pd/Makefile                        |    2 +
 drivers/net/pse-pd/pd692x0.c                       | 1223 ++++++++++++++++++++
 drivers/net/pse-pd/pse_core.c                      |  429 ++++++-
 drivers/net/pse-pd/pse_regulator.c                 |   49 +-
 drivers/net/pse-pd/tps23881.c                      |  818 +++++++++++++
 drivers/of/property.c                              |    2 +
 include/linux/pse-pd/pse.h                         |   86 +-
 include/uapi/linux/ethtool.h                       |   55 +
 include/uapi/linux/ethtool_netlink.h               |    3 +
 net/ethtool/pse-pd.c                               |   60 +-
 22 files changed, 3451 insertions(+), 123 deletions(-)

---
base-commit: f308eae1e1cdacca3cef65c7f4f691dfcb0c8976
change-id: 20231024-feature_poe-139490e73403

Best regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
author maintainer
#1 lore raw

PATCH v5 1/17 MAINTAINERS: net: Add Oleksij to pse-pd maintainers

Oleksij was the first to add support for pse-pd net subsystem. Add himself to the maintainers seems logical.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v3:
- New patch

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index cfe44a876d8a..4f9b554f79da 100644
@@ -17690,6 +17690,13 @@ F:	include/net/psample.h
 F:	include/uapi/linux/psample.h
 F:	net/psample
 
+PSE NETWORK DRIVER
+M:	Oleksij Rempel <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/pse-pd/
+F:	drivers/net/pse-pd/
+
 PSTORE FILESYSTEM
 M:	Kees Cook <[email protected]>
 R:	Tony Luck <[email protected]>
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH v5 2/17 of: property: Add fw_devlink support for pse parent

In reply to Kory Maincent

This allows fw_devlink to create device links between consumers of a PSE and the supplier of the PSE.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v3:
- New patch

---
 drivers/of/property.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/property.c +2 -0
index b71267c6667c..c14001d40cd2 100644
@@ -1240,6 +1240,7 @@ DEFINE_SIMPLE_PROP(leds, "leds", NULL)
 DEFINE_SIMPLE_PROP(backlight, "backlight", NULL)
 DEFINE_SIMPLE_PROP(panel, "panel", NULL)
 DEFINE_SIMPLE_PROP(msi_parent, "msi-parent", "#msi-cells")
+DEFINE_SIMPLE_PROP(pses, "pses", "#pse-cells")
 DEFINE_SUFFIX_PROP(regulators, "-supply", NULL)
 DEFINE_SUFFIX_PROP(gpio, "-gpio", "#gpio-cells")
 
@@ -1344,6 +1345,7 @@ static const struct supplier_bindings of_supplier_bindings[] = {
 	{ .parse_prop = parse_backlight, },
 	{ .parse_prop = parse_panel, },
 	{ .parse_prop = parse_msi_parent, },
+	{ .parse_prop = parse_pses, },
 	{ .parse_prop = parse_gpio_compat, },
 	{ .parse_prop = parse_interrupts, },
 	{ .parse_prop = parse_regulators, },
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH v5 3/17 net: pse-pd: Rectify and adapt the naming of admin_cotrol member of struct pse_control_config

In reply to Kory Maincent

In commit 18ff0bcda6d1 ("ethtool: add interface to interact with Ethernet Power Equipment"), the 'pse_control_config' structure was introduced, housing a single member labeled 'admin_cotrol' responsible for maintaining the operational state of the PoDL PSE functions.

A noticeable typographical error exists in the naming of this field ('cotrol' should be corrected to 'control'), which this commit aims to rectify.

Furthermore, with upcoming extensions of this structure to encompass PoE functionalities, the field is being renamed to 'podl_admin_state' to distinctly indicate that this state is tailored specifically for PoDL."

This patch is sponsored by Dent Project <[email protected]>.

---
 drivers/net/pse-pd/pse_regulator.c | 8 ++++----
 include/linux/pse-pd/pse.h         | 4 ++--
 net/ethtool/pse-pd.c               | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/pse-pd/pse_regulator.c +4 -4
index e2bf8306ca90..1dedf4de296e 100644
@@ -31,10 +31,10 @@ pse_reg_ethtool_set_config(struct pse_controller_dev *pcdev, unsigned long id,
 	struct pse_reg_priv *priv = to_pse_reg(pcdev);
 	int ret;
 
-	if (priv->admin_state == config->admin_cotrol)
+	if (priv->admin_state == config->podl_admin_control)
 		return 0;
 
-	switch (config->admin_cotrol) {
+	switch (config->podl_admin_control) {
 	case ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED:
 		ret = regulator_enable(priv->ps);
 		break;
@@ -43,14 +43,14 @@ pse_reg_ethtool_set_config(struct pse_controller_dev *pcdev, unsigned long id,
 		break;
 	default:
 		dev_err(pcdev->dev, "Unknown admin state %i\n",
-			config->admin_cotrol);
+			config->podl_admin_control);
 		ret = -ENOTSUPP;
 	}
 
 	if (ret)
 		return ret;
 
-	priv->admin_state = config->admin_cotrol;
+	priv->admin_state = config->podl_admin_control;
 
 	return 0;
 }
include/linux/pse-pd/pse.h +2 -2
index fb724c65c77b..199cf4ae3cf2 100644
@@ -15,11 +15,11 @@ struct pse_controller_dev;
 /**
  * struct pse_control_config - PSE control/channel configuration.
  *
- * @admin_cotrol: set PoDL PSE admin control as described in
+ * @podl_admin_control: set PoDL PSE admin control as described in
  *	IEEE 802.3-2018 30.15.1.2.1 acPoDLPSEAdminControl
  */
 struct pse_control_config {
-	enum ethtool_podl_pse_admin_state admin_cotrol;
+	enum ethtool_podl_pse_admin_state podl_admin_control;
 };
 
 /**
net/ethtool/pse-pd.c +1 -1
index cc478af77111..aef57a058f0d 100644
@@ -130,7 +130,7 @@ ethnl_set_pse(struct ethnl_req_info *req_info, struct genl_info *info)
 	struct phy_device *phydev;
 
 	/* this values are already validated by the ethnl_pse_set_policy */
-	config.admin_cotrol = nla_get_u32(tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL]);
+	config.podl_admin_control = nla_get_u32(tb[ETHTOOL_A_PODL_PSE_ADMIN_CONTROL]);
 
 	phydev = dev->phydev;
 	if (!phydev) {
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH v5 4/17 ethtool: Expand Ethernet Power Equipment with c33 (PoE) alongside PoDL

In reply to Kory Maincent

In the current PSE interface for Ethernet Power Equipment, support is limited to PoDL. This patch extends the interface to accommodate the objects specified in IEEE 802.3-2022 145.2 for Power sourcing Equipment (PSE).

The following objects are now supported and considered mandatory:
- IEEE 802.3-2022 30.9.1.1.5 aPSEPowerDetectionStatus
- IEEE 802.3-2022 30.9.1.1.2 aPSEAdminState
- IEEE 802.3-2022 30.9.1.2.1 aPSEAdminControl

To avoid confusion between "PoDL PSE" and "PoE PSE", which have similar names but distinct values, we have followed the suggestion of Oleksij Rempel and Andrew Lunn to maintain separate naming schemes for each, using c33 (clause 33) prefix for "PoE PSE".
You can find more details in the discussion threads here:
https://lore.kernel.org/netdev/[email protected]/
https://lore.kernel.org/netdev/[email protected]/

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v2:
- Rename all the PoE variables and enum with a c33 prefix.
- Add documentation, thanks to Oleksij for having written one.

Changes in v3:
- Fix documentation build warning.

---
 Documentation/networking/index.rst               |  1 +
 Documentation/networking/pse-pd/index.rst        |  9 +++
 Documentation/networking/pse-pd/introduction.rst | 73 ++++++++++++++++++++++++
 include/linux/pse-pd/pse.h                       |  9 +++
 include/uapi/linux/ethtool.h                     | 43 ++++++++++++++
 include/uapi/linux/ethtool_netlink.h             |  3 +
 6 files changed, 138 insertions(+)
Documentation/networking/index.rst +1 -0
index 69f3d6dcd9fd..af7da7006ce8 100644
@@ -92,6 +92,7 @@ Contents:
    plip
    ppp_generic
    proc_net_tcp
+   pse-pd/index
    radiotap-headers
    rds
    regulatory
Documentation/networking/pse-pd/index.rst new file +9 -0
new file mode 100644
index 000000000000..18197bc7303d
@@ -0,0 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Power Sourcing Equipment (PSE) Documentation
+============================================
+
+.. toctree::
+   :maxdepth: 2
+
+   introduction
Documentation/networking/pse-pd/introduction.rst new file +73 -0

73 lines not on this page · raw message

include/linux/pse-pd/pse.h +9 -0
index 199cf4ae3cf2..be4e5754eb24 100644
@@ -17,9 +17,12 @@ struct pse_controller_dev;
  *
  * @podl_admin_control: set PoDL PSE admin control as described in
  *	IEEE 802.3-2018 30.15.1.2.1 acPoDLPSEAdminControl
+ * @c33_admin_control: set PSE admin control as described in
+ *	IEEE 802.3-2022 30.9.1.2.1 acPSEAdminControl
  */
 struct pse_control_config {
 	enum ethtool_podl_pse_admin_state podl_admin_control;
+	enum ethtool_c33_pse_admin_state c33_admin_control;
 };
 
 /**
@@ -29,10 +32,16 @@ struct pse_control_config {
  *	functions. IEEE 802.3-2018 30.15.1.1.2 aPoDLPSEAdminState
  * @podl_pw_status: power detection status of the PoDL PSE.
  *	IEEE 802.3-2018 30.15.1.1.3 aPoDLPSEPowerDetectionStatus:
+ * @c33_admin_state: operational state of the PSE
+ *	functions. IEEE 802.3-2022 30.9.1.1.2 aPSEAdminState
+ * @c33_pw_status: power detection status of the PSE.
+ *	IEEE 802.3-2022 30.9.1.1.5 aPSEPowerDetectionStatus:
  */
 struct pse_control_status {
 	enum ethtool_podl_pse_admin_state podl_admin_state;
 	enum ethtool_podl_pse_pw_d_status podl_pw_status;
+	enum ethtool_c33_pse_admin_state c33_admin_state;
+	enum ethtool_c33_pse_pw_d_status c33_pw_status;
 };
 
 /**
include/uapi/linux/ethtool.h +43 -0

49 lines not on this page · raw message

include/uapi/linux/ethtool_netlink.h +3 -0
index 3f89074aa06c..3f32d360beb1 100644
@@ -895,6 +895,9 @@ enum {
 	ETHTOOL_A_PODL_PSE_ADMIN_STATE,		/* u32 */
 	ETHTOOL_A_PODL_PSE_ADMIN_CONTROL,	/* u32 */
 	ETHTOOL_A_PODL_PSE_PW_D_STATUS,		/* u32 */
+	ETHTOOL_A_C33_PSE_ADMIN_STATE,		/* u32 */
+	ETHTOOL_A_C33_PSE_ADMIN_CONTROL,	/* u32 */
+	ETHTOOL_A_C33_PSE_PW_D_STATUS,		/* u32 */
 
 	/* add new constants above here */
 	__ETHTOOL_A_PSE_CNT,
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH v5 5/17 net: pse-pd: Introduce PSE types enumeration

In reply to Kory Maincent

Introduce an enumeration to define PSE types (C33 or PoDL), utilizing a bitfield for potential future support of both types. Include 'pse_get_types' helper for external access to PSE type info.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v2:
- Rename PSE_POE to PSE_C33 to have naming consistency.
- Use "static inline" instead of simple static in the header

Changes in v3:
- Move the pse_type enum in uapi.
- Replace pse_get_types helper by pse_has_podl and pse_has_c33.

Changes in v5:
- Move the pse types enum in ethtool.
- Add ethtool prefix to the value.

---
 drivers/net/pse-pd/pse_core.c      | 12 ++++++++++++
 drivers/net/pse-pd/pse_regulator.c |  1 +
 include/linux/pse-pd/pse.h         | 15 +++++++++++++++
 include/uapi/linux/ethtool.h       | 12 ++++++++++++
 4 files changed, 40 insertions(+)
drivers/net/pse-pd/pse_core.c +12 -0
index 146b81f08a89..fed006cbc185 100644
@@ -312,3 +312,15 @@ int pse_ethtool_set_config(struct pse_control *psec,
 	return err;
 }
 EXPORT_SYMBOL_GPL(pse_ethtool_set_config);
+
+bool pse_has_podl(struct pse_control *psec)
+{
+	return psec->pcdev->types & ETHTOOL_PSE_PODL;
+}
+EXPORT_SYMBOL_GPL(pse_has_podl);
+
+bool pse_has_c33(struct pse_control *psec)
+{
+	return psec->pcdev->types & ETHTOOL_PSE_C33;
+}
+EXPORT_SYMBOL_GPL(pse_has_c33);
drivers/net/pse-pd/pse_regulator.c +1 -0
index 1dedf4de296e..547af384764b 100644
@@ -116,6 +116,7 @@ pse_reg_probe(struct platform_device *pdev)
 	priv->pcdev.owner = THIS_MODULE;
 	priv->pcdev.ops = &pse_reg_ops;
 	priv->pcdev.dev = dev;
+	priv->pcdev.types = ETHTOOL_PSE_PODL;
 	ret = devm_pse_controller_register(dev, &priv->pcdev);
 	if (ret) {
 		dev_err(dev, "failed to register PSE controller (%pe)\n",
include/linux/pse-pd/pse.h +15 -0
index be4e5754eb24..19589571157f 100644
@@ -77,6 +77,7 @@ struct pse_control;
  *            device tree to id as given to the PSE control ops
  * @nr_lines: number of PSE controls in this controller device
  * @lock: Mutex for serialization access to the PSE controller
+ * @types: types of the PSE controller
  */
 struct pse_controller_dev {
 	const struct pse_controller_ops *ops;
@@ -89,6 +90,7 @@ struct pse_controller_dev {
 			const struct of_phandle_args *pse_spec);
 	unsigned int nr_lines;
 	struct mutex lock;
+	enum ethtool_pse_types types;
 };
 
 #if IS_ENABLED(CONFIG_PSE_CONTROLLER)
@@ -108,6 +110,9 @@ int pse_ethtool_set_config(struct pse_control *psec,
 			   struct netlink_ext_ack *extack,
 			   const struct pse_control_config *config);
 
+bool pse_has_podl(struct pse_control *psec);
+bool pse_has_c33(struct pse_control *psec);
+
 #else
 
 static inline struct pse_control *of_pse_control_get(struct device_node *node)
@@ -133,6 +138,16 @@ static inline int pse_ethtool_set_config(struct pse_control *psec,
 	return -ENOTSUPP;
 }
 
+static inline bool pse_has_podl(struct pse_control *psec)
+{
+	return false;
+}
+
+static inline bool pse_has_c33(struct pse_control *psec)
+{
+	return false;
+}
+
 #endif
 
 #endif
include/uapi/linux/ethtool.h +12 -0
index d35f044e88eb..f63fdeb422e8 100644
@@ -752,6 +752,18 @@ enum ethtool_module_power_mode {
 	ETHTOOL_MODULE_POWER_MODE_HIGH,
 };
 
+/**
+ * enum - Types of PSE controller.
+ * @ETHTOOL_PSE_UNKNOWN: Type of PSE controller is unknown
+ * @ETHTOOL_PSE_PODL: PSE controller which support PoDL
+ * @ETHTOOL_PSE_C33: PSE controller which support Clause 33 (PoE)
+ */
+enum ethtool_pse_types {
+	ETHTOOL_PSE_UNKNOWN =	1 << 0,
+	ETHTOOL_PSE_PODL =	1 << 1,
+	ETHTOOL_PSE_C33 =	1 << 2,
+};
+
 /**
  * enum ethtool_c33_pse_admin_state - operational state of the PoDL PSE
  *	functions. IEEE 802.3-2022 30.9.1.1.2 aPSEAdminState
Signature · 1 line
2.25.1
author maintainer
#6 lore raw

PATCH v5 6/17 net: ethtool: pse-pd: Expand pse commands with the PSE PoE interface

In reply to Kory Maincent

Add PSE PoE interface support in the ethtool pse command.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v2:
- Follow the "c33" PoE prefix naming change.

Changes in v3:
- Replace the pse_get_types() helper by pse_has_podl() and pse_has_c33().
- Replace PoE to c33 in the netlink error log.
- Fix documentation build warning.

---
 Documentation/networking/ethtool-netlink.rst | 20 ++++++++++
 net/ethtool/pse-pd.c                         | 60 +++++++++++++++++++++++-----
 2 files changed, 70 insertions(+), 10 deletions(-)
Documentation/networking/ethtool-netlink.rst +20 -0
index d583d9abf2f8..294187c3a3b0 100644
@@ -1717,6 +1717,10 @@ Kernel response contents:
                                                   PSE functions
   ``ETHTOOL_A_PODL_PSE_PW_D_STATUS``         u32  power detection status of the
                                                   PoDL PSE.
+  ``ETHTOOL_A_C33_PSE_ADMIN_STATE``          u32  Operational state of the PoE
+                                                  PSE functions.
+  ``ETHTOOL_A_C33_PSE_PW_D_STATUS``          u32  power detection status of the
+                                                  PoE PSE.
   ======================================  ======  =============================
 
 When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_STATE`` attribute identifies
@@ -1728,6 +1732,12 @@ aPoDLPSEAdminState. Possible values are:
 .. kernel-doc:: include/uapi/linux/ethtool.h
     :identifiers: ethtool_podl_pse_admin_state
 
+The same goes for ``ETHTOOL_A_C33_PSE_ADMIN_STATE`` implementing
+``IEEE 802.3-2022`` 30.9.1.1.2 aPSEAdminState.
+
+.. kernel-doc:: include/uapi/linux/ethtool.h
+    :identifiers: ethtool_c33_pse_admin_state
+
 When set, the optional ``ETHTOOL_A_PODL_PSE_PW_D_STATUS`` attribute identifies
 the power detection status of the PoDL PSE.  The status depend on internal PSE
 state machine and automatic PD classification support. This option is
@@ -1737,6 +1747,12 @@ Possible values are:
 .. kernel-doc:: include/uapi/linux/ethtool.h
     :identifiers: ethtool_podl_pse_pw_d_status
 
+The same goes for ``ETHTOOL_A_C33_PSE_ADMIN_PW_D_STATUS`` implementing
+``IEEE 802.3-2022`` 30.9.1.1.5 aPSEPowerDetectionStatus.
+
+.. kernel-doc:: include/uapi/linux/ethtool.h
+    :identifiers: ethtool_c33_pse_pw_d_status
+
 PSE_SET
 =======
 
@@ -1747,6 +1763,7 @@ Request contents:
   ======================================  ======  =============================
   ``ETHTOOL_A_PSE_HEADER``                nested  request header
   ``ETHTOOL_A_PODL_PSE_ADMIN_CONTROL``       u32  Control PoDL PSE Admin state
+  ``ETHTOOL_A_C33_PSE_ADMIN_CONTROL``        u32  Control PSE Admin state
   ======================================  ======  =============================
 
 When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_CONTROL`` attribute is used
@@ -1754,6 +1771,9 @@ to control PoDL PSE Admin functions. This option is implementing
 ``IEEE 802.3-2018`` 30.15.1.2.1 acPoDLPSEAdminControl. See
 ``ETHTOOL_A_PODL_PSE_ADMIN_STATE`` for supported values.
 
+The same goes for ``ETHTOOL_A_C33_PSE_ADMIN_CONTROL`` implementing
+``IEEE 802.3-2022`` 30.9.1.2.1 acPSEAdminControl.
+
 RSS_GET
 =======
 
net/ethtool/pse-pd.c +50 -10

93 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#7 lore raw

PATCH v5 7/17 netlink: specs: Modify pse attribute prefix

In reply to Kory Maincent

Remove podl from the attribute prefix to prepare the support of PoE pse netlink spec.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v2:
- Add the ethtool auto generated code.

Changes in v3:
- Remove the ethtool auto generated code.

---
 Documentation/netlink/specs/ethtool.yaml | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
Documentation/netlink/specs/ethtool.yaml +9 -9
index 197208f419dc..33e81fa189ca 100644
@@ -878,17 +878,17 @@ attribute-sets:
         type: nest
         nested-attributes: header
       -
-        name: admin-state
+        name: podl-pse-admin-state
         type: u32
-        name-prefix: ethtool-a-podl-pse-
+        name-prefix: ethtool-a-
       -
-        name: admin-control
+        name: podl-pse-admin-control
         type: u32
-        name-prefix: ethtool-a-podl-pse-
+        name-prefix: ethtool-a-
       -
-        name: pw-d-status
+        name: podl-pse-pw-d-status
         type: u32
-        name-prefix: ethtool-a-podl-pse-
+        name-prefix: ethtool-a-
   -
     name: rss
     attributes:
@@ -1571,9 +1571,9 @@ operations:
         reply:
           attributes: &pse
             - header
-            - admin-state
-            - admin-control
-            - pw-d-status
+            - podl-pse-admin-state
+            - podl-pse-admin-control
+            - podl-pse-pw-d-status
       dump: *pse-get-op
     -
       name: pse-set
Signature · 1 line
2.25.1
author maintainer
#8 lore raw

PATCH v5 8/17 netlink: specs: Expand the pse netlink command with PoE interface

In reply to Kory Maincent

Add the PoE pse attributes prefix to be able to use PoE interface.

Example usage:

./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do pse-get \
             --json '{"header":{"dev-name":"eth0"}}'

{'header': {'dev-index': 4, 'dev-name': 'eth0'},
'c33-pse-admin-state': 3,
'c33-pse-pw-d-status': 4}

./ynl/cli.py --spec netlink/specs/ethtool.yaml --no-schema --do pse-set \
             --json '{"header":{"dev-name":"eth0"},
		     "c33-pse-admin-control":3}'

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v2:
- Follow the "c33" PoE prefix naming change.
- Add the ethtool auto generated code.

Changes in v3:
- Remove the ethtool auto generated code.

---
 Documentation/netlink/specs/ethtool.yaml | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
Documentation/netlink/specs/ethtool.yaml +15 -0
index 33e81fa189ca..beaab9f0017f 100644
@@ -889,6 +889,18 @@ attribute-sets:
         name: podl-pse-pw-d-status
         type: u32
         name-prefix: ethtool-a-
+      -
+        name: c33-pse-admin-state
+        type: u32
+        name-prefix: ethtool-a-
+      -
+        name: c33-pse-admin-control
+        type: u32
+        name-prefix: ethtool-a-
+      -
+        name: c33-pse-pw-d-status
+        type: u32
+        name-prefix: ethtool-a-
   -
     name: rss
     attributes:
@@ -1574,6 +1586,9 @@ operations:
             - podl-pse-admin-state
             - podl-pse-admin-control
             - podl-pse-pw-d-status
+            - c33-pse-admin-state
+            - c33-pse-admin-control
+            - c33-pse-pw-d-status
       dump: *pse-get-op
     -
       name: pse-set
Signature · 1 line
2.25.1
author maintainer
#9 lore raw

PATCH v5 9/17 MAINTAINERS: Add myself to pse networking maintainer

In reply to Kory Maincent

As I add support for PoE in PSE networking subsystem it seems legitimate to be added to the maintainers.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v3:
- New patch

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 4f9b554f79da..43d26b766936 100644
@@ -17692,6 +17692,7 @@ F:	net/psample
 
 PSE NETWORK DRIVER
 M:	Oleksij Rempel <[email protected]>
+M:	Kory Maincent <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/net/pse-pd/
Signature · 1 line
2.25.1
author maintainer
#10 lore raw

PATCH v5 10/17 net: pse-pd: Add support for PSE PIs

In reply to Kory Maincent

Add support for getting the PSE controller node through PSE PI device subnode.
This supports adds a way to get the PSE PI id from the pse_pi devicetree subnode of a PSE controller node simply by reading the reg property.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v3:
- New patch.

Changes in v4:
- Add PSE PI documentation.

Changes in v5:
- Update PSE PI documentation.

---
 Documentation/networking/pse-pd/index.rst  |   1 +
 Documentation/networking/pse-pd/pse-pi.rst | 302 +++++++++++++++++++++++++++++
 drivers/net/pse-pd/pse_core.c              | 223 +++++++++++++++++----
 include/linux/pse-pd/pse.h                 |  38 +++-
 4 files changed, 520 insertions(+), 44 deletions(-)
Documentation/networking/pse-pd/index.rst +1 -0
index 18197bc7303d..de28a5aee316 100644
@@ -7,3 +7,4 @@ Power Sourcing Equipment (PSE) Documentation
    :maxdepth: 2
 
    introduction
+   pse-pi
Documentation/networking/pse-pd/pse-pi.rst new file +302 -0

302 lines not on this page · raw message

drivers/net/pse-pd/pse_core.c +183 -40

268 lines not on this page · raw message

include/linux/pse-pd/pse.h +34 -4
index 19589571157f..01b3b9adfe2a 100644
@@ -64,6 +64,36 @@ struct device_node;
 struct of_phandle_args;
 struct pse_control;
 
+/* PSE PI pairset pinout can either be Alternative A or Alternative B */
+enum pse_pi_pairset_pinout {
+	ALTERNATIVE_A,
+	ALTERNATIVE_B,
+};
+
+/**
+ * struct pse_pi_pairset - PSE PI pairset entity describing the pinout
+ *			   alternative ant its phandle
+ *
+ * @pinout: description of the pinout alternative
+ * @np: device node pointer describing the pairset phandle
+ */
+struct pse_pi_pairset {
+	enum pse_pi_pairset_pinout pinout;
+	struct device_node *np;
+};
+
+/**
+ * struct pse_pi - PSE PI (Power Interface) entity as described in
+ *		   IEEE 802.3-2022 145.2.4
+ *
+ * @pairset: table of the PSE PI pinout alternative for the two pairset
+ * @np: device node pointer of the PSE PI node
+ */
+struct pse_pi {
+	struct pse_pi_pairset pairset[2];
+	struct device_node *np;
+};
+
 /**
  * struct pse_controller_dev - PSE controller entity that might
  *                             provide multiple PSE controls
@@ -73,11 +103,11 @@ struct pse_control;
  * @pse_control_head: head of internal list of requested PSE controls
  * @dev: corresponding driver model device struct
  * @of_pse_n_cells: number of cells in PSE line specifiers
- * @of_xlate: translation function to translate from specifier as found in the
- *            device tree to id as given to the PSE control ops
  * @nr_lines: number of PSE controls in this controller device
  * @lock: Mutex for serialization access to the PSE controller
  * @types: types of the PSE controller
+ * @pi: table of PSE PIs described in this controller device
+ * @of_legacy: flag set if the pse_pis devicetree node is not used
  */
 struct pse_controller_dev {
 	const struct pse_controller_ops *ops;
@@ -86,11 +116,11 @@ struct pse_controller_dev {
 	struct list_head pse_control_head;
 	struct device *dev;
 	int of_pse_n_cells;
-	int (*of_xlate)(struct pse_controller_dev *pcdev,
-			const struct of_phandle_args *pse_spec);
 	unsigned int nr_lines;
 	struct mutex lock;
 	enum ethtool_pse_types types;
+	struct pse_pi *pi;
+	bool of_legacy;
 };
 
 #if IS_ENABLED(CONFIG_PSE_CONTROLLER)
Signature · 1 line
2.25.1
maintainer
#11 lore raw

Re: [PATCH net-next v5 10/17] net: pse-pd: Add support for PSE PIs

Hi Kory,

On Tue, Feb 27, 2024 at 03:42:52PM +0100, Kory Maincent wrote:
....

Quoted 7 lines
drivers/net/pse-pd/pse_core.c +0 -0
index fed006cbc185..9124eb3d6492 100644
@@ -27,38 +27,137 @@ struct pse_control {
 	struct kref refcnt;
 };

drivers/net/pse-pd/pse_core.c struct pse_control { · line 38

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +0 -9
 
-/**
- * of_pse_zero_xlate - dummy function for controllers with one only control
- * @pcdev: a pointer to the PSE controller device
- * @pse_spec: PSE line specifier as found in the device tree
- *
- * This static translation function is used by default if of_xlate in
- * :c:type:`pse_controller_dev` is not set. It is useful for all PSE
- * controllers with #pse-cells = <0>.
- */

Please replace documentation

drivers/net/pse-pd/pse_core.c struct pse_control { · line 38

Quoted 12 lines
drivers/net/pse-pd/pse_core.c +8 -3
-static int of_pse_zero_xlate(struct pse_controller_dev *pcdev,
-			     const struct of_phandle_args *pse_spec)
+static int of_load_pse_pi_pairsets(struct device_node *node,
+				   struct pse_pi *pi,
+				   int npairsets)
 {
-	return 0;
+	struct device_node *pairset_np;
+	const char *name;
+	int i, ret;
+
+	for (i = 0; i < npairsets; i++) {

please move this scope to a separate function.

drivers/net/pse-pd/pse_core.c struct pse_control { · line 45

Quoted 7 lines
drivers/net/pse-pd/pse_core.c +7 -0
+		ret = of_property_read_string_index(node,
+						    "pairset-names",
+						     i, &name);
+		if (ret)
+			break;
+
+		if (strcmp(name, "alternative-a")) {

strcmp returns 0 if it matching

		if (!strcmp(name, "alternative-a")) {

drivers/net/pse-pd/pse_core.c struct pse_control { · line 47

Quoted 2 lines
drivers/net/pse-pd/pse_core.c +2 -0
+			pi->pairset[i].pinout = ALTERNATIVE_A;
+		} else if (strcmp(name, "alternative-b")) {
		if (!strcmp(name, "alternative-a")) {
Quoted 34 lines
drivers/net/pse-pd/pse_core.c +32 -0
+			pi->pairset[i].pinout = ALTERNATIVE_B;
+		} else {
+			pr_err("pse: wrong pairset-names value %s\n", name);
+			ret = -EINVAL;
+			break;
+		}
+
+		pairset_np = of_parse_phandle(node, "pairsets", i);
+		if (!pairset_np) {
+			ret = -ENODEV;
+			break;
+		}
+
+		pi->pairset[i].np = pairset_np;
+	}
+
+	if (i == 2 && pi->pairset[0].pinout == pi->pairset[1].pinout) {
+		pr_err("pse: two PI pairsets can not have identical pinout");
+		ret = -EINVAL;
+	}
+
+	/* If an error appears on the second pairset load, release the first
+	 * pairset device node kref
+	 */
+	if (ret) {
+		of_node_put(pi->pairset[0].np);
+		pi->pairset[0].np = NULL;
+		of_node_put(pi->pairset[1].np);
+		pi->pairset[1].np = NULL;
+	}
+
+	return ret;
 }
 

drivers/net/pse-pd/pse_core.c struct pse_control { · line 54

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +0 -10
-/**
- * of_pse_simple_xlate - translate pse_spec to the PSE line number
- * @pcdev: a pointer to the PSE controller device
- * @pse_spec: PSE line specifier as found in the device tree
- *
- * This static translation function is used by default if of_xlate in
- * :c:type:`pse_controller_dev` is not set. It is useful for all PSE
- * controllers with 1:1 mapping, where PSE lines can be indexed by number
- * without gaps.
- */

Please replace documentation

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +4 -4
-static int of_pse_simple_xlate(struct pse_controller_dev *pcdev,
-			       const struct of_phandle_args *pse_spec)
+static int of_load_pse_pis(struct pse_controller_dev *pcdev)
 {
-	if (pse_spec->args[0] >= pcdev->nr_lines)
-		return -EINVAL;
+	struct device_node *np = pcdev->dev->of_node;
+	struct device_node *node, *pis;
+	int ret, i;
 

drivers/net/pse-pd/pse_core.c struct pse_control { · line 96

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +9 -1
-	return pse_spec->args[0];
+	if (!np)
+		return -ENODEV;
+
+	pcdev->pi = kcalloc(pcdev->nr_lines, sizeof(*pcdev->pi), GFP_KERNEL);
+	if (!pcdev->pi)
+		return -ENOMEM;
+
+	pis = of_get_child_by_name(np, "pse-pis");
+	if (!pis) {

Do we need to allocate pcdev->pi if there are no pse-pis?

drivers/net/pse-pd/pse_core.c struct pse_control { · line 98

Quoted 2 lines
drivers/net/pse-pd/pse_core.c +2 -0
+		/* Legacy OF description of PSE PIs */
+		pcdev->of_legacy = true;

It is not "legacy" :) PoDL do not providing definition of PSE PI since there is only one pair. May be: single_pair, no_pse_pi or any other idea.

drivers/net/pse-pd/pse_core.c struct pse_control { · line 102

Quoted 4 lines
drivers/net/pse-pd/pse_core.c +4 -0
+		return 0;
+	}
+
+	for_each_child_of_node(pis, node) {

please move this scope to a separate function.

drivers/net/pse-pd/pse_core.c struct pse_control { · line 111

Quoted 9 lines
drivers/net/pse-pd/pse_core.c +9 -0
+		struct pse_pi pi = {0};
+		int npairsets;
+		u32 id;
+
+		if (!of_node_name_eq(node, "pse-pi"))
+			continue;
+
+		ret = of_property_read_u32(node, "reg", &id);
+		if (ret)

error: can't get "reg" property for node "%s"

drivers/net/pse-pd/pse_core.c struct pse_control { · line 114

Quoted 3 lines
drivers/net/pse-pd/pse_core.c +3 -0
+			goto out;
+
+		if (id >= pcdev->nr_lines || pcdev->pi[id].np) {

Here two different kind of errors:
- (id >= pcdev->nr_lines) reg value is out of range. print value and max range.
- (pcdev->pi[id].np) other node with same reg value was already registered... print both node names.

drivers/net/pse-pd/pse_core.c struct pse_control { · line 122

Quoted 8 lines
drivers/net/pse-pd/pse_core.c +8 -0
+			dev_err(pcdev->dev, "wrong id of pse pi: %u\n",
+				id);
+			ret = -EINVAL;
+			goto out;
+		}
+
+		ret = of_property_count_strings(node, "pairset-names");
+		if (ret <= 0)

if (ret < 0)
error: can't get "pairset-names" property: %pe
if (ret < 1 || ret > 2)
error: wrong number of pairset-names. Should be 1 or 2, got %i

drivers/net/pse-pd/pse_core.c struct pse_control { · line 127

Quoted 5 lines
drivers/net/pse-pd/pse_core.c +5 -0
+			goto out;
+		npairsets = ret;
+
+		ret = of_count_phandle_with_args(node, "pairsets", NULL);
+		if (ret <= 0)

same as for pairset-names

drivers/net/pse-pd/pse_core.c struct pse_control { · line 131

Quoted 4 lines
drivers/net/pse-pd/pse_core.c +4 -0
+			goto out;
+
+		/* npairsets is limited to value one or two */
+		if (ret != npairsets || ret > 2) {

(ret > 2) will be handled by previous checks
(ret != npairsets) amount of pairsets and pairset-names is not equal %i != %i

Quoted 59 lines
drivers/net/pse-pd/pse_core.c +37 -6
+			dev_err(pcdev->dev,
+				"wrong number of pairsets or pairset-names for pse pi %d\n",
+				id);
+			ret = -EINVAL;
+			goto out;
+		}
+
+		ret = of_load_pse_pi_pairsets(node, &pi, npairsets);
+		if (ret)
+			goto out;
+
+		of_node_get(node);
+		pi.np = node;
+		memcpy(&pcdev->pi[id], &pi, sizeof(pi));
+	}
+
+	of_node_put(pis);
+	return 0;
+
+out:
+	for (i = 0; i <= pcdev->nr_lines; i++) {
+		of_node_put(pcdev->pi[i].pairset[0].np);
+		of_node_put(pcdev->pi[i].pairset[1].np);
+		of_node_put(pcdev->pi[i].np);
+	}
+	of_node_put(node);
+	of_node_put(pis);
+	kfree(pcdev->pi);
+	return ret;
 }
 
 /**
@@ -67,16 +166,18 @@ static int of_pse_simple_xlate(struct pse_controller_dev *pcdev,
  */
 int pse_controller_register(struct pse_controller_dev *pcdev)
 {
-	if (!pcdev->of_xlate) {
-		if (pcdev->of_pse_n_cells == 0)
-			pcdev->of_xlate = of_pse_zero_xlate;
-		else if (pcdev->of_pse_n_cells == 1)
-			pcdev->of_xlate = of_pse_simple_xlate;
-	}
+	int ret;
 
 	mutex_init(&pcdev->lock);
 	INIT_LIST_HEAD(&pcdev->pse_control_head);
 
+	if (!pcdev->nr_lines)
+		pcdev->nr_lines = 1;
+
+	ret = of_load_pse_pis(pcdev);
+	if (ret)
+		return ret;
+
 	mutex_lock(&pse_list_mutex);
 	list_add(&pcdev->list, &pse_controller_list);
 	mutex_unlock(&pse_list_mutex);
@@ -91,6 +192,14 @@ EXPORT_SYMBOL_GPL(pse_controller_register);
  */

drivers/net/pse-pd/pse_core.c EXPORT_SYMBOL_GPL(pse_controller_register); · line 202

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +8 -0
 void pse_controller_unregister(struct pse_controller_dev *pcdev)
 {
+	int i;
+
+	for (i = 0; i <= pcdev->nr_lines; i++) {
+		of_node_put(pcdev->pi[i].pairset[0].np);
+		of_node_put(pcdev->pi[i].pairset[1].np);
+		of_node_put(pcdev->pi[i].np);
+	}
+	kfree(pcdev->pi);

Same pattern was already used. It is better to move it to a separate function.

Quoted 14 lines
drivers/net/pse-pd/pse_core.c +5 -2
 	mutex_lock(&pse_list_mutex);
 	list_del(&pcdev->list);
 	mutex_unlock(&pse_list_mutex);
@@ -203,8 +312,33 @@ pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index)
 	return psec;
 }
 
-struct pse_control *
-of_pse_control_get(struct device_node *node)
+static int of_pse_match_pi(struct pse_controller_dev *pcdev,
+			   struct device_node *np)
+{
+	int i;
+

drivers/net/pse-pd/pse_core.c pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index) · line 329

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +10 -0
+	for (i = 0; i <= pcdev->nr_lines; i++) {
+		if (pcdev->pi[i].np == np)
+			return i;
+	}
+
+	return -EINVAL;
+}
+
+static int psec_id_legacy_xlate(struct pse_controller_dev *pcdev,
+				const struct of_phandle_args *pse_spec)

rename legacy to some other name in all places.

Quoted 107 lines
drivers/net/pse-pd/pse_core.c +26 -5
+{
+	if (!pcdev->of_pse_n_cells)
+		return 0;
+
+	if (pcdev->of_pse_n_cells > 1 ||
+	    pse_spec->args[0] >= pcdev->nr_lines)
+		return -EINVAL;
+
+	return pse_spec->args[0];
+}
+
+struct pse_control *of_pse_control_get(struct device_node *node)
 {
 	struct pse_controller_dev *r, *pcdev;
 	struct of_phandle_args args;
@@ -222,7 +356,14 @@ of_pse_control_get(struct device_node *node)
 	mutex_lock(&pse_list_mutex);
 	pcdev = NULL;
 	list_for_each_entry(r, &pse_controller_list, list) {
-		if (args.np == r->dev->of_node) {
+		if (!r->of_legacy) {
+			ret = of_pse_match_pi(r, args.np);
+			if (ret >= 0) {
+				pcdev = r;
+				psec_id = ret;
+				break;
+			}
+		} else if (args.np == r->dev->of_node) {
 			pcdev = r;
 			break;
 		}
@@ -238,10 +379,12 @@ of_pse_control_get(struct device_node *node)
 		goto out;
 	}
 
-	psec_id = pcdev->of_xlate(pcdev, &args);
-	if (psec_id < 0) {
-		psec = ERR_PTR(psec_id);
-		goto out;
+	if (pcdev->of_legacy) {
+		psec_id = psec_id_legacy_xlate(pcdev, &args);
+		if (psec_id < 0) {
+			psec = ERR_PTR(psec_id);
+			goto out;
+		}
 	}
 
 	/* pse_list_mutex also protects the pcdev's pse_control list */
include/linux/pse-pd/pse.h +32 -2
index 19589571157f..01b3b9adfe2a 100644
@@ -64,6 +64,36 @@ struct device_node;
 struct of_phandle_args;
 struct pse_control;
 
+/* PSE PI pairset pinout can either be Alternative A or Alternative B */
+enum pse_pi_pairset_pinout {
+	ALTERNATIVE_A,
+	ALTERNATIVE_B,
+};
+
+/**
+ * struct pse_pi_pairset - PSE PI pairset entity describing the pinout
+ *			   alternative ant its phandle
+ *
+ * @pinout: description of the pinout alternative
+ * @np: device node pointer describing the pairset phandle
+ */
+struct pse_pi_pairset {
+	enum pse_pi_pairset_pinout pinout;
+	struct device_node *np;
+};
+
+/**
+ * struct pse_pi - PSE PI (Power Interface) entity as described in
+ *		   IEEE 802.3-2022 145.2.4
+ *
+ * @pairset: table of the PSE PI pinout alternative for the two pairset
+ * @np: device node pointer of the PSE PI node
+ */
+struct pse_pi {
+	struct pse_pi_pairset pairset[2];
+	struct device_node *np;
+};
+
 /**
  * struct pse_controller_dev - PSE controller entity that might
  *                             provide multiple PSE controls
@@ -73,11 +103,11 @@ struct pse_control;
  * @pse_control_head: head of internal list of requested PSE controls
  * @dev: corresponding driver model device struct
  * @of_pse_n_cells: number of cells in PSE line specifiers
- * @of_xlate: translation function to translate from specifier as found in the
- *            device tree to id as given to the PSE control ops
  * @nr_lines: number of PSE controls in this controller device
  * @lock: Mutex for serialization access to the PSE controller
  * @types: types of the PSE controller
+ * @pi: table of PSE PIs described in this controller device
+ * @of_legacy: flag set if the pse_pis devicetree node is not used
  */
 struct pse_controller_dev {
 	const struct pse_controller_ops *ops;
@@ -86,11 +116,11 @@ struct pse_controller_dev {
 	struct list_head pse_control_head;
 	struct device *dev;
 	int of_pse_n_cells;

include/linux/pse-pd/pse.h struct pse_controller_dev { · line 126

Quoted 10 lines
include/linux/pse-pd/pse.h +2 -2
-	int (*of_xlate)(struct pse_controller_dev *pcdev,
-			const struct of_phandle_args *pse_spec);
 	unsigned int nr_lines;
 	struct mutex lock;
 	enum ethtool_pse_types types;
+	struct pse_pi *pi;
+	bool of_legacy;
 };
 
 #if IS_ENABLED(CONFIG_PSE_CONTROLLER)

Regards,
Oleksij

Signature · 4 lines
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 |
author maintainer
#12 lore raw

Re: [PATCH net-next v5 10/17] net: pse-pd: Add support for PSE PIs

Hello Oleskij,

Thanks you for the review.

Quoted 10 lines · On Fri, 1 Mar 2024 15:24:07 +0100 Oleksij Rempel <[email protected]>…
Quoted 10 lines
drivers/net/pse-pd/pse_core.c +4 -4
-static int of_pse_simple_xlate(struct pse_controller_dev *pcdev,
-			       const struct of_phandle_args *pse_spec)
+static int of_load_pse_pis(struct pse_controller_dev *pcdev)
 {
-	if (pse_spec->args[0] >= pcdev->nr_lines)
-		return -EINVAL;
+	struct device_node *np = pcdev->dev->of_node;
+	struct device_node *node, *pis;
+	int ret, i;
Quoted 13 lines

drivers/net/pse-pd/pse_core.c struct pse_control { · line 96

Quoted 11 lines
drivers/net/pse-pd/pse_core.c +4 -1
-	return pse_spec->args[0];
+	if (!np)
+		return -ENODEV;
+
+	pcdev->pi = kcalloc(pcdev->nr_lines, sizeof(*pcdev->pi),

GFP_KERNEL);

drivers/net/pse-pd/pse_core.c +5 -0
+	if (!pcdev->pi)
+		return -ENOMEM;
+
+	pis = of_get_child_by_name(np, "pse-pis");
+	if (!pis) {  

Do we need to allocate pcdev->pi if there are no pse-pis?

In fact it is not needed in this patch but in the patch 13 which use regulator framework, as the regulator is described on each pi structure.

I will update them accordingly.

Quoted 5 lines

drivers/net/pse-pd/pse_core.c struct pse_control { · line 98

Quoted 2 lines
drivers/net/pse-pd/pse_core.c +2 -0
+		/* Legacy OF description of PSE PIs */
+		pcdev->of_legacy = true;  

It is not "legacy" :) PoDL do not providing definition of PSE PI since there is only one pair. May be: single_pair, no_pse_pi or any other idea.

You right it is not needed for PoDL. Maybe no_pse_pi is better according to the following thoughts.

Just wondering, how a pse controller that support PoE and PoDL simultaneously would be exposed in the binding. In that case I suppose all the PIs (PoE and PoDL) need to use the pse-pi subnode. Then the "alternative pinout" and "polarity" parameter would not be requested for PoDL PIs.

Quoted 5 lines
Quoted 5 lines
drivers/net/pse-pd/pse_core.c +5 -0
+			dev_err(pcdev->dev, "wrong id of pse pi: %u\n",
+				id);
+			ret = -EINVAL;
+			goto out;
+		}
Quoted 8 lines

drivers/net/pse-pd/pse_core.c struct pse_control { · line 122

Quoted 3 lines
drivers/net/pse-pd/pse_core.c +3 -0
+
+		ret = of_property_count_strings(node, "pairset-names");
+		if (ret <= 0)  

if (ret < 0)
error: can't get "pairset-names" property: %pe
if (ret < 1 || ret > 2)
error: wrong number of pairset-names. Should be 1 or 2, got %i

Need to modify this to be able to have PoDL PIs without pairset description.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
maintainer
#13 lore raw

Re: [PATCH net-next v5 10/17] net: pse-pd: Add support for PSE PIs

Hay Köry,

Quoted 3 lines · Köry Maincent

Hello Oleskij,

Thanks you for the review.

I'll try to review more at weekend.

Quoted 6 lines
Quoted 5 lines

drivers/net/pse-pd/pse_core.c struct pse_control { · line 98

Quoted 2 lines
drivers/net/pse-pd/pse_core.c +2 -0
+		/* Legacy OF description of PSE PIs */
+		pcdev->of_legacy = true;  

It is not "legacy" :) PoDL do not providing definition of PSE PI since there is only one pair. May be: single_pair, no_pse_pi or any other idea.

Quoted 7 lines

You right it is not needed for PoDL. Maybe no_pse_pi is better according to the following thoughts.

Just wondering, how a pse controller that support PoE and PoDL simultaneously would be exposed in the binding. In that case I suppose all the PIs (PoE and PoDL) need to use the pse-pi subnode. Then the "alternative pinout" and "polarity" parameter would not be requested for PoDL PIs.

In case of hybrid device I would expect that we will have an 4 pair connector where only one pair will be used. In this case we will need to know what pair and polarity is supported or can be configured for PoDL. It will be full blown PSE PI node with PoDL specific extras.

Don't worry about it right now.

Regards,
Oleksij

Signature · 4 lines
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 |
author maintainer
#14 lore raw

PATCH v5 11/17 dt-bindings: net: pse-pd: Add another way of describing several PSE PIs

In reply to Kory Maincent

PSE PI setup may encompass multiple PSE controllers or auxiliary circuits that collectively manage power delivery to one Ethernet port. Such configurations might support a range of PoE standards and require the capability to dynamically configure power delivery based on the operational mode (e.g., PoE2 versus PoE4) or specific requirements of connected devices. In these instances, a dedicated PSE PI node becomes essential for accurately documenting the system architecture. This node would serve to detail the interactions between different PSE controllers, the support for various PoE modes, and any additional logic required to coordinate power delivery across the network infrastructure.

The old usage of "#pse-cells" is unsuficient as it carries only the PSE PI index information.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v3:
- New patch

Changes in v4:
- Remove $def
- Fix pairset-names item list
- Upgrade few properties description
- Update the commit message

Changes in v5:
- Fix yamllint error.
- Replace underscore by dash in properties names.
- Add polarity-supported property.

---
 .../bindings/net/pse-pd/pse-controller.yaml        | 100 ++++++++++++++++++++-
 1 file changed, 97 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml +97 -3
index 2d382faca0e6..76a301463b48 100644
@@ -13,6 +13,7 @@ description: Binding for the Power Sourcing Equipment (PSE) as defined in the
 
 maintainers:
   - Oleksij Rempel <[email protected]>
+  - Kory Maincent <[email protected]>
 
 properties:
   $nodename:
@@ -22,11 +23,104 @@ properties:
     description:
       Used to uniquely identify a PSE instance within an IC. Will be
       0 on PSE nodes with only a single output and at least 1 on nodes
-      controlling several outputs.
+      controlling several outputs which are not described in the pse-pis
+      subnode. This property is deprecated, please use pse-pis instead.
     enum: [0, 1]
 
-required:
-  - "#pse-cells"
+  pse-pis:
+    type: object
+    description:
+      Overview of the PSE PIs provided by the controller.
+
+    properties:
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+    required:
+      - "#address-cells"
+      - "#size-cells"
+
+    patternProperties:
+      "^pse-pi@[0-9a-f]+$":
+        type: object
+        description:
+          PSE PI for power delivery via pairsets, compliant with IEEE
+          802.3-2022, Section 145.2.4. Each pairset comprises a positive and
+          a negative VPSE pair, adhering to the pinout configurations
+          detailed in the standard.
+          See Documentation/networking/pse-pd/pse-pi.rst for details.
+
+        properties:
+          reg:
+            description:
+              Address describing the PSE PI index.
+            maxItems: 1
+
+          "#pse-cells":
+            const: 0
+
+          pairset-names:
+            $ref: /schemas/types.yaml#/definitions/string-array
+            description:
+              Names of the pairsets as per IEEE 802.3-2022, Section 145.2.4.
+              Valid values are "alternative-a" and "alternative-b". Each name
+              should correspond to a phandle in the 'pairset' property
+              pointing to the power supply for that pairset.
+            minItems: 1
+            maxItems: 2
+            items:
+              enum:
+                - alternative-a
+                - alternative-b
+
+          pairsets:
+            $ref: /schemas/types.yaml#/definitions/phandle-array
+            description:
+              List of phandles, each pointing to the power supply for the
+              corresponding pairset named in 'pairset-names'. This property
+              aligns with IEEE 802.3-2022, Section 33.2.3 and 145.2.4.
+              PSE Pinout Alternatives (as per IEEE 802.3-2022 Table 145–3)
+              | Conductor | Alternative A (MDI-X) | Alternative A (MDI) | Alternative B(X) | Alternative B(S) |
+              |-----------|-----------------------|---------------------|------------------|------------------|
+              | 1         | Negative VPSE         | Positive VPSE       | —                | —                |
+              | 2         | Negative VPSE         | Positive VPSE       | —                | —                |
+              | 3         | Positive VPSE         | Negative VPSE       | —                | —                |
+              | 4         | —                     | —                   | Negative VPSE    | Positive VPSE    |
+              | 5         | —                     | —                   | Negative VPSE    | Positive VPSE    |
+              | 6         | Positive VPSE         | Negative VPSE       | —                | —                |
+              | 7         | —                     | —                   | Positive VPSE    | Negative VPSE    |
+              | 8         | —                     | —                   | Positive VPSE    | Negative VPSE    |
+            minItems: 1
+            maxItems: 2
+
+          polarity-supported:
+            $ref: /schemas/types.yaml#/definitions/string-array
+            description:
+              Polarity configuration supported by the PSE PI pairsets.
+            minItems: 1
+            maxItems: 4
+            items:
+              enum:
+                - MDI-X
+                - MDI
+                - X
+                - S
+
+        required:
+          - reg
+          - "#pse-cells"
+          - pairset-names
+          - pairsets
+          - polarity-supported
+
+oneOf:
+  - required:
+      - "#pse-cells"
+  - required:
+      - pse-pis
 
 additionalProperties: true
 
Signature · 1 line
2.25.1
maintainer
#15 lore raw

Re: [PATCH net-next v5 11/17] dt-bindings: net: pse-pd: Add another way of describing several PSE PIs

Quoted 28 lines · Kory Maincent

PSE PI setup may encompass multiple PSE controllers or auxiliary circuits that collectively manage power delivery to one Ethernet port. Such configurations might support a range of PoE standards and require the capability to dynamically configure power delivery based on the operational mode (e.g., PoE2 versus PoE4) or specific requirements of connected devices. In these instances, a dedicated PSE PI node becomes essential for accurately documenting the system architecture. This node would serve to detail the interactions between different PSE controllers, the support for various PoE modes, and any additional logic required to coordinate power delivery across the network infrastructure.

The old usage of "#pse-cells" is unsuficient as it carries only the PSE PI index information.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v3:
- New patch

Changes in v4:
- Remove $def
- Fix pairset-names item list
- Upgrade few properties description
- Update the commit message

Quoted 8 lines

Changes in v5:
- Fix yamllint error.
- Replace underscore by dash in properties names.
- Add polarity-supported property.

---
 .../bindings/net/pse-pd/pse-controller.yaml        | 100 ++++++++++++++++++++-
 1 file changed, 97 insertions(+), 3 deletions(-)

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:
./Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml:86:111: [warning] line too long (111 > 110 characters) (line-length) ./Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml:88:111: [warning] line too long (111 > 110 characters) (line-length) ./Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml:89:111: [warning] line too long (111 > 110 characters) (line-length) ./Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml:90:111: [warning] line too long (111 > 110 characters) (line-length) ./Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml:91:111: [warning] line too long (111 > 110 characters) (line-length) ./Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml:92:111: [warning] line too long (111 > 110 characters) (line-length) ./Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml:93:111: [warning] line too long (111 > 110 characters) (line-length) ./Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml:94:111: [warning] line too long (111 > 110 characters) (line-length) ./Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml:95:111: [warning] line too long (111 > 110 characters) (line-length)

dtschema/dtc warnings/errors:

doc reference errors (make refcheckdocs):
Warning: Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml references a file that doesn't exist: Documentation/networking/pse-pd/pse-pi.rst Documentation/devicetree/bindings/net/pse-pd/pse-controller.yaml: Documentation/networking/pse-pd/pse-pi.rst

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

author maintainer
#16 lore raw

PATCH v5 12/17 net: pse-pd: Add support for setup_pi_matrix callback

In reply to Kory Maincent

Implement setup_pi_matrix callback to configure the PSE PI matrix. This functionality is invoked before registering the PSE and following the core parsing of the pse_pis devicetree subnode.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v3:
- New patch

---
 drivers/net/pse-pd/pse_core.c | 6 ++++++
 include/linux/pse-pd/pse.h    | 2 ++
 2 files changed, 8 insertions(+)
drivers/net/pse-pd/pse_core.c +6 -0
index 9124eb3d6492..a2eb9a424668 100644
@@ -178,6 +178,12 @@ int pse_controller_register(struct pse_controller_dev *pcdev)
 	if (ret)
 		return ret;
 
+	if (pcdev->ops->setup_pi_matrix) {
+		ret = pcdev->ops->setup_pi_matrix(pcdev);
+		if (ret)
+			return ret;
+	}
+
 	mutex_lock(&pse_list_mutex);
 	list_add(&pcdev->list, &pse_controller_list);
 	mutex_unlock(&pse_list_mutex);
include/linux/pse-pd/pse.h +2 -0
index 01b3b9adfe2a..522115cc6cef 100644
@@ -49,6 +49,7 @@ struct pse_control_status {
  *
  * @ethtool_get_status: get PSE control status for ethtool interface
  * @ethtool_set_config: set PSE control configuration over ethtool interface
+ * @setup_pi_matrix: setup PI matrix of the PSE controller
  */
 struct pse_controller_ops {
 	int (*ethtool_get_status)(struct pse_controller_dev *pcdev,
@@ -57,6 +58,7 @@ struct pse_controller_ops {
 	int (*ethtool_set_config)(struct pse_controller_dev *pcdev,
 		unsigned long id, struct netlink_ext_ack *extack,
 		const struct pse_control_config *config);
+	int (*setup_pi_matrix)(struct pse_controller_dev *pcdev);
 };
 
 struct module;
Signature · 1 line
2.25.1
author maintainer
#17 lore raw

PATCH v5 13/17 net: pse-pd: Use regulator framework within PSE framework

In reply to Kory Maincent

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 regulator_enable/disable. These calls will only be called from PSE framework as it won't have any regulator children, therefore no mutex are needed to safeguards this boolean.

regulator_get uses the consumer device pointer therefore of_pse_control_get is modified accordingly to pass the PSE consumer device alongside its device node.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v3:
- New patch

Changes in v4:
- Remove the nested lock as the regulator_enable/disable ops will only be called from the PSE framework. No need to protect the 'enabled' boolean.
- Update regulator to current instead of voltage.

---
 drivers/net/mdio/fwnode_mdio.c     |  29 +++---
 drivers/net/pse-pd/pse_core.c      | 192 +++++++++++++++++++++++++++++++++----
 drivers/net/pse-pd/pse_regulator.c |  48 ++++++----
 include/linux/pse-pd/pse.h         |  18 +++-
 4 files changed, 230 insertions(+), 57 deletions(-)
drivers/net/mdio/fwnode_mdio.c +14 -15
index fd02f5cbc853..aa20b2ac7f2d 100644
@@ -17,19 +17,17 @@ MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("FWNODE MDIO bus (Ethernet PHY) accessors");
 
 static struct pse_control *
-fwnode_find_pse_control(struct fwnode_handle *fwnode)
+dev_find_pse_control(struct device *dev)
 {
 	struct pse_control *psec;
-	struct device_node *np;
 
 	if (!IS_ENABLED(CONFIG_PSE_CONTROLLER))
 		return NULL;
 
-	np = to_of_node(fwnode);
-	if (!np)
+	if (!dev->of_node)
 		return NULL;
 
-	psec = of_pse_control_get(np);
+	psec = of_pse_control_get(dev, dev->of_node);
 	if (PTR_ERR(psec) == -ENOENT)
 		return NULL;
 
@@ -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;
+	}
+
 	phy->psec = psec;
 
 	/* phy->mii_ts may already be defined by the PHY driver. A
@@ -172,12 +170,13 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
 
 	return 0;
 
+unregister_phy:
+	if (is_acpi_node(child) || is_of_node(child))
+		phy_device_remove(phy);
 clean_phy:
 	phy_device_free(phy);
 clean_mii_ts:
 	unregister_mii_timestamper(mii_ts);
-clean_pse:
-	pse_control_put(psec);
 
 	return rc;
 }
drivers/net/pse-pd/pse_core.c +176 -16

269 lines not on this page · raw message

drivers/net/pse-pd/pse_regulator.c +27 -21

71 lines not on this page · raw message

include/linux/pse-pd/pse.h +13 -5
index 522115cc6cef..a3e297cc2150 100644
@@ -55,10 +55,10 @@ struct pse_controller_ops {
 	int (*ethtool_get_status)(struct pse_controller_dev *pcdev,
 		unsigned long id, struct netlink_ext_ack *extack,
 		struct pse_control_status *status);
-	int (*ethtool_set_config)(struct pse_controller_dev *pcdev,
-		unsigned long id, struct netlink_ext_ack *extack,
-		const struct pse_control_config *config);
 	int (*setup_pi_matrix)(struct pse_controller_dev *pcdev);
+	int (*pi_is_enabled)(struct pse_controller_dev *pcdev, int id);
+	int (*pi_enable)(struct pse_controller_dev *pcdev, int id);
+	int (*pi_disable)(struct pse_controller_dev *pcdev, int id);
 };
 
 struct module;
@@ -90,10 +90,14 @@ struct pse_pi_pairset {
  *
  * @pairset: table of the PSE PI pinout alternative for the two pairset
  * @np: device node pointer of the PSE PI node
+ * @rdev: regulator represented by the PSE PI
+ * @enabled: PI enabled state
  */
 struct pse_pi {
 	struct pse_pi_pairset pairset[2];
 	struct device_node *np;
+	struct regulator_dev *rdev;
+	bool enabled;
 };
 
 /**
@@ -107,6 +111,8 @@ struct pse_pi {
  * @of_pse_n_cells: number of cells in PSE line specifiers
  * @nr_lines: number of PSE controls in this controller device
  * @lock: Mutex for serialization access to the PSE controller
+ * @lock_owner: current owner of the mutex
+ * @ref_cnt: mutex's reference count
  * @types: types of the PSE controller
  * @pi: table of PSE PIs described in this controller device
  * @of_legacy: flag set if the pse_pis devicetree node is not used
@@ -132,7 +138,8 @@ struct device;
 int devm_pse_controller_register(struct device *dev,
 				 struct pse_controller_dev *pcdev);
 
-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);
 void pse_control_put(struct pse_control *psec);
 
 int pse_ethtool_get_status(struct pse_control *psec,
@@ -147,7 +154,8 @@ bool pse_has_c33(struct pse_control *psec);
 
 #else
 
-static inline struct pse_control *of_pse_control_get(struct device_node *node)
+static inline struct pse_control *of_pse_control_get(struct device *dev,
+						     struct device_node *node)
 {
 	return ERR_PTR(-ENOENT);
 }
Signature · 1 line
2.25.1
maintainer
#18 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

drivers/net/pse-pd/pse_core.c pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index) · line 459

Quoted 5 lines · On Tue, 27 Feb 2024 15:42:55 +0100 Kory Maincent wrote:
drivers/net/pse-pd/pse_core.c +5 -0
+	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);

coccinelle says: ERROR: reference preceded by free on line 458

Signature · 1 line
pw-bot: cr
author maintainer
#19 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Quoted 9 lines · On Tue, 27 Feb 2024 16:56:59 -0800 Jakub Kicinski <[email protected]> wrote:

drivers/net/pse-pd/pse_core.c pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index) · line 459

Quoted 6 lines · On Tue, 27 Feb 2024 15:42:55 +0100 Kory Maincent wrote:
(quoted diff) +2 -0
+	psec->ps = devm_regulator_get_exclusive(dev,
+

rdev_get_name(pcdev->pi[index].rdev));

drivers/net/pse-pd/pse_core.c +3 -0
+	if (IS_ERR(psec->ps)) {
+		kfree(psec);
+		return ERR_CAST(psec->ps);  

coccinelle says: ERROR: reference preceded by free on line 458

Ouch, indeed, missed this error.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
reviewer
#20 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

In reply to Kory Maincent

On Tue, Feb 27, 2024 at 03:42:55PM +0100, Kory Maincent wrote:

...

Quoted 5 lines
include/linux/pse-pd/pse.h +0 -0
index 522115cc6cef..a3e297cc2150 100644

include/linux/pse-pd/pse.h struct pse_controller_ops { · line 61

Quoted 10 lines
include/linux/pse-pd/pse.h +3 -3
@@ -55,10 +55,10 @@ struct pse_controller_ops {
 	int (*ethtool_get_status)(struct pse_controller_dev *pcdev,
 		unsigned long id, struct netlink_ext_ack *extack,
 		struct pse_control_status *status);
-	int (*ethtool_set_config)(struct pse_controller_dev *pcdev,
-		unsigned long id, struct netlink_ext_ack *extack,
-		const struct pse_control_config *config);
 	int (*setup_pi_matrix)(struct pse_controller_dev *pcdev);
+	int (*pi_is_enabled)(struct pse_controller_dev *pcdev, int id);
+	int (*pi_enable)(struct pse_controller_dev *pcdev, int id);
+	int (*pi_disable)(struct pse_controller_dev *pcdev, int id);

Hi Kory,

Please update the Kernel doc for struct pse_controller_ops to reflect the added and removed fields.

Quoted 19 lines
include/linux/pse-pd/pse.h +4 -0
 };
 
 struct module;
@@ -90,10 +90,14 @@ struct pse_pi_pairset {
  *
  * @pairset: table of the PSE PI pinout alternative for the two pairset
  * @np: device node pointer of the PSE PI node
+ * @rdev: regulator represented by the PSE PI
+ * @enabled: PI enabled state
  */
 struct pse_pi {
 	struct pse_pi_pairset pairset[2];
 	struct device_node *np;
+	struct regulator_dev *rdev;
+	bool enabled;
 };
 
 /**

include/linux/pse-pd/pse.h struct pse_pi { · line 115

Quoted 5 lines
include/linux/pse-pd/pse.h +2 -0
@@ -107,6 +111,8 @@ struct pse_pi {
  * @of_pse_n_cells: number of cells in PSE line specifiers
  * @nr_lines: number of PSE controls in this controller device
  * @lock: Mutex for serialization access to the PSE controller
+ * @lock_owner: current owner of the mutex
+ * @ref_cnt: mutex's reference count

These newly documented fields don't seem to exist in struct pse_controller_dev. Perhaps this is an left over from earlier development?

Quoted 28 lines
include/linux/pse-pd/pse.h +4 -2
  * @types: types of the PSE controller
  * @pi: table of PSE PIs described in this controller device
  * @of_legacy: flag set if the pse_pis devicetree node is not used
@@ -132,7 +138,8 @@ struct device;
 int devm_pse_controller_register(struct device *dev,
 				 struct pse_controller_dev *pcdev);
 
-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);
 void pse_control_put(struct pse_control *psec);
 
 int pse_ethtool_get_status(struct pse_control *psec,
@@ -147,7 +154,8 @@ bool pse_has_c33(struct pse_control *psec);
 
 #else
 
-static inline struct pse_control *of_pse_control_get(struct device_node *node)
+static inline struct pse_control *of_pse_control_get(struct device *dev,
+						     struct device_node *node)
 {
 	return ERR_PTR(-ENOENT);
 }
Signature · 2 lines
-- 
2.25.1
author maintainer
#21 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Quoted 22 lines · On Wed, 28 Feb 2024 12:48:01 +0000 Simon Horman <[email protected]> wrote:

On Tue, Feb 27, 2024 at 03:42:55PM +0100, Kory Maincent wrote:

...

Quoted 5 lines
include/linux/pse-pd/pse.h +0 -0
index 522115cc6cef..a3e297cc2150 100644

include/linux/pse-pd/pse.h struct pse_controller_ops { · line 61

Quoted 10 lines
include/linux/pse-pd/pse.h +3 -3
@@ -55,10 +55,10 @@ struct pse_controller_ops {
 	int (*ethtool_get_status)(struct pse_controller_dev *pcdev,
 		unsigned long id, struct netlink_ext_ack *extack,
 		struct pse_control_status *status);
-	int (*ethtool_set_config)(struct pse_controller_dev *pcdev,
-		unsigned long id, struct netlink_ext_ack *extack,
-		const struct pse_control_config *config);
 	int (*setup_pi_matrix)(struct pse_controller_dev *pcdev);
+	int (*pi_is_enabled)(struct pse_controller_dev *pcdev, int id);
+	int (*pi_enable)(struct pse_controller_dev *pcdev, int id);
+	int (*pi_disable)(struct pse_controller_dev *pcdev, int id);  

Hi Kory,

Quoted 2 lines

Please update the Kernel doc for struct pse_controller_ops to reflect the added and removed fields.

Hello Simon,
Sorry I totally forgot to update the kernel doc on that patch.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
maintainer
#22 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

In reply to Kory Maincent
Quoted 7 lines · Kory Maincent

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.

Quoted 5 lines

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.

...

Quoted 19 lines
drivers/net/mdio/fwnode_mdio.c +2 -8
@@ -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))

drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_register_phy(struct mii_bus *bus, · line 161

Quoted 9 lines
drivers/net/mdio/fwnode_mdio.c +6 -0
@@ -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.

...

Quoted 14 lines
drivers/net/pse-pd/pse_core.c +14 -0
+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.

drivers/net/pse-pd/pse_core.c static int of_load_pse_pis(struct pse_controller_dev *pcdev) · line 260

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +10 -0
+	 */
+	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.

....

Quoted 7 lines
drivers/net/pse-pd/pse_core.c +3 -0
@@ -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)) {

drivers/net/pse-pd/pse_core.c pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index) · line 467

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +10 -0
+		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.

Quoted 42 lines
drivers/net/pse-pd/pse_core.c +10 -10
+
 	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:

drivers/net/pse-pd/pse_core.c int pse_ethtool_set_config(struct pse_control *psec, · line 619

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +9 -0
+		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

drivers/net/pse-pd/pse_core.c int pse_ethtool_set_config(struct pse_control *psec, · line 621

Quoted 5 lines
drivers/net/pse-pd/pse_core.c +0 -4
-	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

Signature · 4 lines
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 |
author maintainer
#23 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Hello Oleksij,

Thanks for your review!!

Quoted 8 lines · On Sat, 2 Mar 2024 22:35:52 +0100 Oleksij Rempel <[email protected]>…
Quoted 7 lines · Kory Maincent

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.

Quoted 8 lines
Quoted 5 lines

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.

Right,

Quoted 24 lines

...

Quoted 22 lines
drivers/net/mdio/fwnode_mdio.c +2 -8
@@ -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;
}

Quoted 10 lines

drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_register_phy(struct mii_bus *bus, · line 161

Quoted 6 lines
drivers/net/mdio/fwnode_mdio.c +6 -0
+	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.

I totally agree that having port abstraction would be more convenient. Maxime Chevallier is currently working on this and will post it after his multi-phy series get merged.
Meanwhile, we still need a device pointer for getting the regulator. The phy->mdio.dev is the only one I can think of as a regulator consumer. Another idea?

Quoted 30 lines

...

Quoted 14 lines
drivers/net/pse-pd/pse_core.c +14 -0
+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.

drivers/net/pse-pd/pse_core.c static int of_load_pse_pis(struct pse_controller_dev *pcdev) · line 260

Quoted 10 lines
drivers/net/pse-pd/pse_core.c +10 -0
+	 */
+	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";

Quoted 1 line

May be better to make it not optional...

Does the "vin-supply" property be added at the pse-pi node level or the pse-controller node level or at the hardware port node level or the manager node level for the pd692x0?
Maybe better at the pse-pi node level and each PIs of the manager will get the same regulator?
What do you think?

Quoted 2 lines

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

Don't know, if it is done at the pse-pi node level it may not break pse_regulator.c. Not sure about it.

Quoted 14 lines

....

Quoted 13 lines
drivers/net/pse-pd/pse_core.c +8 -0
@@ -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);
Quoted 8 lines

drivers/net/pse-pd/pse_core.c pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index) · line 467

Quoted 5 lines
drivers/net/pse-pd/pse_core.c +5 -0
+	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.

I don't think so as the regulator_get_exclusive() does the same and refcount it:
https://elixir.bootlin.com/linux/v6.7.8/source/drivers/regulator/core.c#L2268

Quoted 6 lines
Quoted 6 lines
drivers/net/pse-pd/pse_core.c +6 -0
+	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:
Quoted 8 lines

drivers/net/pse-pd/pse_core.c int pse_ethtool_set_config(struct pse_control *psec, · line 619

Quoted 6 lines
drivers/net/pse-pd/pse_core.c +5 -0
+		if (psec->pcdev->pi[psec->id].enabled)
+			err = regulator_disable(psec->ps);
+		break;
+	default:
+		err = -EOPNOTSUPP;
 	}  

This change seems to break PoDL support

Oh that's totally true sorry for that mistake.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
maintainer
#24 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Quoted 13 lines · Köry Maincent

Hello Oleksij,

Quoted 10 lines

drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_register_phy(struct mii_bus *bus, · line 161

Quoted 6 lines
drivers/net/mdio/fwnode_mdio.c +6 -0
+	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.

Quoted 6 lines

I totally agree that having port abstraction would be more convenient. Maxime Chevallier is currently working on this and will post it after his multi-phy series get merged.
Meanwhile, we still need a device pointer for getting the regulator. The phy->mdio.dev is the only one I can think of as a regulator consumer. Another idea?

I would say, in current code state, PSE controller is regulator provider and consumer - both are same devices. Otherwise, it will be impossible to unregistered PHY devices without shutting down PSE-PI. Mostly, we should be able to continue to provide the power even if network interface is down.

Quoted 8 lines
Quoted 8 lines

drivers/net/pse-pd/pse_core.c static int of_load_pse_pis(struct pse_controller_dev *pcdev) · line 260

Quoted 3 lines
drivers/net/pse-pd/pse_core.c +3 -0
+	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";

Quoted 8 lines
Quoted 1 line

May be better to make it not optional...

Does the "vin-supply" property be added at the pse-pi node level or the pse-controller node level or at the hardware port node level or the manager node level for the pd692x0?
Maybe better at the pse-pi node level and each PIs of the manager will get the same regulator?
What do you think?

Yes, I agree. PSE-PI should share same parent regulator. Different PSE managers may have different power supplies. One port (PSE PI) - not.

Quoted 6 lines
Quoted 3 lines

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

Don't know, if it is done at the pse-pi node level it may not break pse_regulator.c. Not sure about it.

me too. Before your patch set, the regulator topology for PoDL PSE was following:
power-source
fixed-regulator
PoDL_PSE-consumer

Now it will be:
power-source
fixed-regulator
PoDL_PSE-consumer
PSE-PI-provider
PSE-PI-consumer

By porting porting PSE framework to regulator, probably it make sense to remove two levels of regulators?
power-source
fixed-regulator
PSE-PI-consumer

Quoted 23 lines
Quoted 14 lines

....

Quoted 13 lines
drivers/net/pse-pd/pse_core.c +8 -0
@@ -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);
Quoted 8 lines

drivers/net/pse-pd/pse_core.c pse_control_get_internal(struct pse_controller_dev *pcdev, unsigned int index) · line 467

Quoted 5 lines
drivers/net/pse-pd/pse_core.c +5 -0
+	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.

Quoted 2 lines

I don't think so as the regulator_get_exclusive() does the same and refcount it:
https://elixir.bootlin.com/linux/v6.7.8/source/drivers/regulator/core.c#L2268

ok, thx.

Signature · 4 lines
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 |
author maintainer
#25 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Hello Oleksij,

Quoted 20 lines · On Mon, 4 Mar 2024 11:31:19 +0100 Oleksij Rempel <[email protected]>…
Quoted 6 lines
Quoted 3 lines

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

Don't know, if it is done at the pse-pi node level it may not break pse_regulator.c. Not sure about it.

me too. Before your patch set, the regulator topology for PoDL PSE was following:
power-source
fixed-regulator
PoDL_PSE-consumer

Now it will be:
power-source
fixed-regulator
PoDL_PSE-consumer
PSE-PI-provider
PSE-PI-consumer

Quoted 5 lines

By porting porting PSE framework to regulator, probably it make sense to remove two levels of regulators?
power-source
fixed-regulator
PSE-PI-consumer

Sorry, I forgot to reply about this.
This is specific to pse_regulator driver. Could we tackle this change in another patch series when the current patch series got applied?
Also I don't have the hardware to test it.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
maintainer
#26 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Quoted 31 lines · Kory Maincent

Hello Oleksij,

Quoted 20 lines · On Mon, 4 Mar 2024 11:31:19 +0100 Oleksij Rempel <[email protected]>…
Quoted 6 lines
Quoted 3 lines

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

Don't know, if it is done at the pse-pi node level it may not break pse_regulator.c. Not sure about it.

me too. Before your patch set, the regulator topology for PoDL PSE was following:
power-source
fixed-regulator
PoDL_PSE-consumer

Now it will be:
power-source
fixed-regulator
PoDL_PSE-consumer
PSE-PI-provider
PSE-PI-consumer

Quoted 5 lines

By porting porting PSE framework to regulator, probably it make sense to remove two levels of regulators?
power-source
fixed-regulator
PSE-PI-consumer

Quoted 4 lines

Sorry, I forgot to reply about this.
This is specific to pse_regulator driver. Could we tackle this change in another patch series when the current patch series got applied?
Also I don't have the hardware to test it.

ACK, no problem.

Signature · 4 lines
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 |
author maintainer
#27 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Hello Oleksij,

Quoted 8 lines · On Thu, 21 Mar 2024 17:43:14 +0100 Oleksij Rempel <[email protected]>…
Quoted 5 lines · Kory Maincent

Hello Oleksij,
Sorry, I forgot to reply about this.
This is specific to pse_regulator driver. Could we tackle this change in another patch series when the current patch series got applied? Also I don't have the hardware to test it.

ACK, no problem.

I have a question unrelated to this.
Why do you add refcount on the pse_control struct?
The pse control is related to the RJ45 port. Each port is exclusively related to one pse control.
Shouldn't we return an error in case of two get of the same pse control index? Do you see use cases where a pse control could be get two times?

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
maintainer
#28 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Hay Kory,

Quoted 12 lines · Kory Maincent

Hello Oleksij,

Quoted 7 lines · On Thu, 21 Mar 2024 17:43:14 +0100 Oleksij Rempel <[email protected]>…
Quoted 5 lines · Kory Maincent

Hello Oleksij,
Sorry, I forgot to reply about this.
This is specific to pse_regulator driver. Could we tackle this change in another patch series when the current patch series got applied? Also I don't have the hardware to test it.

Quoted 8 lines
Quoted 1 line

ACK, no problem.

I have a question unrelated to this.
Why do you add refcount on the pse_control struct?
The pse control is related to the RJ45 port. Each port is exclusively related to one pse control.
Shouldn't we return an error in case of two get of the same pse control index? Do you see use cases where a pse control could be get two times?

I assume, any instance which need coordinate PSE behavior with own actions. For example - PHY will probably need to coordinate PHY state with PSE PD classification process.

Regards,
Oleksij

Signature · 4 lines
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 |
author maintainer
#29 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Quoted 24 lines · On Fri, 22 Mar 2024 15:07:45 +0100 Oleksij Rempel <[email protected]>…

Hay Kory,

Quoted 12 lines · Kory Maincent

Hello Oleksij,

Quoted 7 lines · On Thu, 21 Mar 2024 17:43:14 +0100 Oleksij Rempel <[email protected]>…
Quoted 5 lines · Kory Maincent

Hello Oleksij,
Sorry, I forgot to reply about this.
This is specific to pse_regulator driver. Could we tackle this change in another patch series when the current patch series got applied? Also I don't have the hardware to test it.

Quoted 8 lines
Quoted 1 line

ACK, no problem.

I have a question unrelated to this.
Why do you add refcount on the pse_control struct?
The pse control is related to the RJ45 port. Each port is exclusively related to one pse control.
Shouldn't we return an error in case of two get of the same pse control index? Do you see use cases where a pse control could be get two times?

Quoted 3 lines

I assume, any instance which need coordinate PSE behavior with own actions. For example - PHY will probably need to coordinate PHY state with PSE PD classification process.

Indeed, I was focused on devicetree and didn't thought of coordination between PHY and PSE. Thanks for your reply.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
maintainer
#30 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

In reply to Köry Maincent
Quoted 11 lines
Quoted 10 lines

drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_register_phy(struct mii_bus *bus, · line 161

Quoted 6 lines
drivers/net/mdio/fwnode_mdio.c +6 -0
+	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.

Quoted 6 lines

I totally agree that having port abstraction would be more convenient. Maxime Chevallier is currently working on this and will post it after his multi-phy series get merged.
Meanwhile, we still need a device pointer for getting the regulator. The phy->mdio.dev is the only one I can think of as a regulator consumer. Another idea?

Sorry, i've not been keeping up...

Doesn't the device tree binding determine this? Where is the consumer in the tree?

Andrew

maintainer
#31 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Quoted 18 lines · Andrew Lunn
Quoted 11 lines
Quoted 10 lines

drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_register_phy(struct mii_bus *bus, · line 161

Quoted 6 lines
drivers/net/mdio/fwnode_mdio.c +6 -0
+	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.

Quoted 6 lines

I totally agree that having port abstraction would be more convenient. Maxime Chevallier is currently working on this and will post it after his multi-phy series get merged.
Meanwhile, we still need a device pointer for getting the regulator. The phy->mdio.dev is the only one I can think of as a regulator consumer. Another idea?

Quoted 4 lines

Sorry, i've not been keeping up...

Doesn't the device tree binding determine this? Where is the consumer in the tree?

The real consumer is outside of the system. Withing the system, it would be the RJ45 port, but we have no abstraction for ports so far.

Signature · 4 lines
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 |
maintainer
#32 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Quoted 19 lines · Oleksij Rempel
Quoted 18 lines · Andrew Lunn
Quoted 17 lines
Quoted 10 lines

drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_register_phy(struct mii_bus *bus, · line 161

Quoted 6 lines
drivers/net/mdio/fwnode_mdio.c +6 -0
+	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.

I totally agree that having port abstraction would be more convenient. Maxime Chevallier is currently working on this and will post it after his multi-phy series get merged.
Meanwhile, we still need a device pointer for getting the regulator. The phy->mdio.dev is the only one I can think of as a regulator consumer. Another idea?

Quoted 6 lines
Quoted 4 lines

Sorry, i've not been keeping up...

Doesn't the device tree binding determine this? Where is the consumer in the tree?

The real consumer is outside of the system.

The device on the other end of the cable?

Quoted 2 lines

Withing the system, it would be the RJ45 port, but we have no abstraction for ports so far.

A Linux regulator is generally used in a producer/consumer pair. If there is no consumer device, why have a producer? What is going to use the consumer API?

When we have a port representor, do we expect it to have active elements? Something which will consume this regulator?

Andrew

maintainer
#33 lore raw

Re: [PATCH net-next v5 13/17] net: pse-pd: Use regulator framework within PSE framework

Quoted 20 lines · Andrew Lunn
Quoted 19 lines · Oleksij Rempel
Quoted 18 lines · Andrew Lunn
Quoted 17 lines
Quoted 10 lines

drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_register_phy(struct mii_bus *bus, · line 161

Quoted 6 lines
drivers/net/mdio/fwnode_mdio.c +6 -0
+	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.

I totally agree that having port abstraction would be more convenient. Maxime Chevallier is currently working on this and will post it after his multi-phy series get merged.
Meanwhile, we still need a device pointer for getting the regulator. The phy->mdio.dev is the only one I can think of as a regulator consumer. Another idea?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Sorry, i've not been keeping up...

Doesn't the device tree binding determine this? Where is the consumer in the tree?

The real consumer is outside of the system.

The device on the other end of the cable?

yes.

Quoted 6 lines
Quoted 2 lines

Withing the system, it would be the RJ45 port, but we have no abstraction for ports so far.

A Linux regulator is generally used in a producer/consumer pair. If there is no consumer device, why have a producer? What is going to use the consumer API?

We already consulted Mark Brown in precious iterations of this patch series and got his OK. I also described all advantages of using regulator framework within the PSE subsystem. I need to search it. Short answer, it is relatively common to have open-ended regulator with consumer outside of the system. A PSE system can be relatively complex, representing all supply dependencies from power supplies (one or multiple) to the ports will help to provide needed diagnostic information and power saving if port are disabled. Some functionality is currently not supported by the regulator framework, but need to be extended - power budged, priorities and reservation. All of this are not exclusive PSE challenges. So, using regulator framework seems to be a straightforward decision.

Quoted 2 lines

When we have a port representor, do we expect it to have active elements? Something which will consume this regulator?

Not in a usual sense. There are two levels of PSE control:
- autodetected by PSE controller
- fine tuned by using LLDP wich may respond to PD requests by allocating more or reducing/disabling power.

Regards,
Oleksij

Signature · 4 lines
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 |
author maintainer
#34 lore raw

PATCH v5 14/17 dt-bindings: net: pse-pd: Add bindings for PD692x0 PSE controller

In reply to Kory Maincent

Add the PD692x0 I2C Power Sourcing Equipment controller device tree bindings documentation.

This patch is sponsored by Dent Project <[email protected]>.

---

Changes in v2:
- Enhance ports-matrix description.
- Replace additionalProperties by unevaluatedProperties.
- Drop i2c suffix.

Changes in v3:
- Remove ports-matrix parameter.
- Add description of all physical ports and managers.
- Add pse_pis subnode moving to the API of pse-controller binding.
- Remove the MAINTAINERS section for this driver as I will be maintaining all pse-pd subsystem.

Changes in v5:
- Remove defs used only once.
- Replace underscore by dash.
- Add description.

---
 .../bindings/net/pse-pd/microchip,pd692x0.yaml     | 158 +++++++++++++++++++++
 1 file changed, 158 insertions(+)
Documentation/devicetree/bindings/net/pse-pd/microchip,pd692x0.yaml new file +158 -0
new file mode 100644
index 000000000000..62ea4363cba3
@@ -0,0 +1,158 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/pse-pd/microchip,pd692x0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip PD692x0 Power Sourcing Equipment controller
+
+maintainers:
+  - Kory Maincent <[email protected]>
+
+allOf:
+  - $ref: pse-controller.yaml#
+
+properties:
+  compatible:
+    enum:
+      - microchip,pd69200
+      - microchip,pd69210
+      - microchip,pd69220
+
+  reg:
+    maxItems: 1
+
+  managers:
+    type: object
+    description:
+      List of the PD69208T4/PD69204T4/PD69208M PSE managers. Each manager
+      have 4 or 8 physical ports according to the chip version. No need to
+      specify the SPI chip select as it is automatically detected by the
+      PD692x0 PSE controller. The PSE managers have to be described from
+      the lowest chip select to the greatest one, which is the detection
+      behavior of the PD692x0 PSE controller. The PD692x0 support up to
+      12 PSE managers which can expose up to 96 physical ports. All
+      physical ports available on a manager have to be described in the
+      incremental order even if they are not used.
+
+    properties:
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+    required:
+      - "#address-cells"
+      - "#size-cells"
+
+    patternProperties:
+      "^manager@0[0-9]|1[0-2]$":
+        $ref: /schemas/graph.yaml#/properties/ports
+        description:
+          PD69208T4/PD69204T4/PD69208M PSE manager exposing 4 or 8 physical
+          ports.
+
+        properties:
+          reg:
+            description:
+              Incremental index of the PSE manager starting from 0, ranging
+              from lowest to highest chip select, up to 12.
+            maxItems: 1
+
+        patternProperties:
+          '^port@[0-7]$':
+            type: object
+            required:
+              - reg
+
+        required:
+          - reg
+
+required:
+  - compatible
+  - reg
+  - pse-pis
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      ethernet-pse@3c {
+        compatible = "microchip,pd69200";
+        reg = <0x3c>;
+
+        managers {
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          manager@0 {
+            reg = <0>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            phys0: port@0 {
+              reg = <0>;
+            };
+
+            phys1: port@1 {
+              reg = <1>;
+            };
+
+            phys2: port@2 {
+              reg = <2>;
+            };
+
+            phys3: port@3 {
+              reg = <3>;
+            };
+          };
+
+          manager@1 {
+            reg = <1>;
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            phys4: port@0 {
+              reg = <0>;
+            };
+
+            phys5: port@1 {
+              reg = <1>;
+            };
+
+            phys6: port@2 {
+              reg = <2>;
+            };
+
+            phys7: port@3 {
+              reg = <3>;
+            };
+          };
+        };
+
+        pse-pis {
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          pse_pi0: pse-pi@0 {
+            reg = <0>;
+            #pse-cells = <0>;
+            pairset-names = "alternative-a", "alternative-b";
+            pairsets = <&phys0>, <&phys1>;
+            polarity-supported = "MDI", "S";
+          };
+          pse_pi1: pse-pi@1 {
+            reg = <1>;
+            #pse-cells = <0>;
+            pairset-names = "alternative-a";
+            pairsets = <&phys2>;
+            polarity-supported = "MDI";
+          };
+        };
+      };
+    };
Signature · 1 line
2.25.1
author maintainer
#35 lore raw

PATCH v5 15/17 net: pse-pd: Add PD692x0 PSE controller driver

In reply to Kory Maincent

Add a new driver for the PD692x0 I2C Power Sourcing Equipment controller. This driver only support i2c communication for now.

This patch is sponsored by Dent Project <[email protected]>.

---
Change in v2:
- Drop of_match_ptr
- Follow the "c33" PoE prefix naming change.
- Remove unused delay_recv variable. Then, remove struct pd692x0_msg_content which is similar to struct pd692x0_msg.
- Fix a weird sleep loop.
- Improve pd692x0_recv_msg for better readability.
- Fix a warning reported by Simon on a pd692x0_fw_write_line call.

Change in v3:
- Fix few nit.
- Change the return value of pd692x0_try_recv_msg function.
- Replace a dev_err() function to dev_err_probe().
- Replace pd692x0_update_matrix by the newly introduced setup_pi_matrix callback.
- Follow new bindings of managers subnode description.
- Update the pse ops with the newly introduced pi_enable, pi_is_enabled and pi_disable ones.
- Replace firmware version check by a softer one (< instead of =!).
- Rearrange the probe function, which had wrong ordering on error case between pcdcev registering and software version read.
- Fixed the probe function in the case it is call two times. The status won't be sent automatically on the second times so ask for it.

---
 drivers/net/pse-pd/Kconfig   |   11 +
 drivers/net/pse-pd/Makefile  |    1 +
 drivers/net/pse-pd/pd692x0.c | 1223 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1235 insertions(+)
drivers/net/pse-pd/Kconfig +11 -0
index 687dec49c1e1..e3a6ba669f20 100644
@@ -20,4 +20,15 @@ config PSE_REGULATOR
 	  Sourcing Equipment without automatic classification support. For
 	  example for basic implementation of PoDL (802.3bu) specification.
 
+config PSE_PD692X0
+	tristate "PD692X0 PSE controller"
+	depends on I2C
+	select FW_UPLOAD
+	help
+	  This module provides support for PD692x0 regulator based Ethernet
+	  Power Sourcing Equipment.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called pd692x0.
+
 endif
drivers/net/pse-pd/Makefile +1 -0
index 1b8aa4c70f0b..9c12c4a65730 100644
@@ -4,3 +4,4 @@
 obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o
 
 obj-$(CONFIG_PSE_REGULATOR) += pse_regulator.o
+obj-$(CONFIG_PSE_PD692X0) += pd692x0.o
drivers/net/pse-pd/pd692x0.c new file +1223 -0

1,223 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#36 lore raw

PATCH v5 16/17 dt-bindings: net: pse-pd: Add bindings for TPS23881 PSE controller

In reply to Kory Maincent

Add the TPS23881 I2C Power Sourcing Equipment controller device tree bindings documentation.

This patch is sponsored by Dent Project <[email protected]>.

---
Change in v3:
- New patch.

Change in v4:
- Rename the file to ti,tps23881 as it support only this version of the PSE controller.

---
 .../bindings/net/pse-pd/ti,tps23881.yaml           | 93 ++++++++++++++++++++++
 1 file changed, 93 insertions(+)
Documentation/devicetree/bindings/net/pse-pd/ti,tps23881.yaml new file +93 -0
new file mode 100644
index 000000000000..b8891d109e51
@@ -0,0 +1,93 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/pse-pd/ti,tps23881.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI TPS23881 Power Sourcing Equipment controller
+
+maintainers:
+  - Kory Maincent <[email protected]>
+
+allOf:
+  - $ref: pse-controller.yaml#
+
+properties:
+  compatible:
+    enum:
+      - ti,tps23881
+
+  reg:
+    maxItems: 1
+
+  '#pse-cells':
+    const: 1
+
+  channels:
+    description: each set of 8 ports can be assigned to one physical
+      channels or two for PoE4. This parameter describes the configuration
+      of the ports conversion matrix that establishes relationship between
+      the logical ports and the physical channels.
+    type: object
+
+    patternProperties:
+      '^channel@[0-7]$':
+        type: object
+        required:
+          - reg
+
+unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      ethernet-pse@20 {
+        compatible = "ti,tps23881";
+        reg = <0x20>;
+
+        channels {
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          phys0: channel@0 {
+            reg = <0>;
+          };
+
+          phys1: channel@1 {
+            reg = <1>;
+          };
+
+          phys2: channel@2 {
+            reg = <2>;
+          };
+        };
+
+        pse-pis {
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          pse_pi0: pse-pi@0 {
+            reg = <0>;
+            #pse-cells = <0>;
+            pairset-names = "alternative-a", "alternative-b";
+            pairsets = <&phys0>, <&phys1>;
+            polarity-supported = "MDI", "S";
+          };
+
+          pse_pi1: pse-pi@1 {
+            reg = <1>;
+            #pse-cells = <0>;
+            pairset-names = "alternative-a";
+            pairsets = <&phys2>;
+            polarity-supported = "MDI";
+          };
+        };
+      };
+    };
Signature · 1 line
2.25.1
author maintainer
#37 lore raw

PATCH v5 17/17 net: pse-pd: Add TI TPS23881 PSE controller driver

In reply to Kory Maincent

Add a new driver for the TI TPS23881 I2C Power Sourcing Equipment controller.

This patch is sponsored by Dent Project <[email protected]>.

---
Change in v3:
- New patch.

---
 drivers/net/pse-pd/Kconfig    |   9 +
 drivers/net/pse-pd/Makefile   |   1 +
 drivers/net/pse-pd/tps23881.c | 818 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 828 insertions(+)
drivers/net/pse-pd/Kconfig +9 -0
index e3a6ba669f20..80cf373a5a0e 100644
@@ -31,4 +31,13 @@ config PSE_PD692X0
 	  To compile this driver as a module, choose M here: the
 	  module will be called pd692x0.
 
+config PSE_TPS23881
+	tristate "TPS23881 PSE controller"
+	depends on I2C
+	help
+	  This module provides support for TPS23881 regulator based Ethernet
+	  Power Sourcing Equipment.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called tps23881.
 endif
drivers/net/pse-pd/Makefile +1 -0
index 9c12c4a65730..9d2898b36737 100644
@@ -5,3 +5,4 @@ obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o
 
 obj-$(CONFIG_PSE_REGULATOR) += pse_regulator.o
 obj-$(CONFIG_PSE_PD692X0) += pd692x0.o
+obj-$(CONFIG_PSE_TPS23881) += tps23881.o
drivers/net/pse-pd/tps23881.c new file +818 -0

818 lines not on this page · raw message

Signature · 1 line
2.25.1
reviewer
#38 lore raw

Re: [PATCH net-next v5 17/17] net: pse-pd: Add TI TPS23881 PSE controller driver

Quoted 6 lines · Kory Maincent

Add a new driver for the TI TPS23881 I2C Power Sourcing Equipment controller.

This patch is sponsored by Dent Project <[email protected]>.

...

Quoted 8 lines
drivers/net/pse-pd/tps23881.c new file +8 -0
+static int tps23881_flash_fw_part(struct i2c_client *client,
+				  const char *fw_name,
+				  const struct tps23881_fw_conf *fw_conf)
+{
+	const struct firmware *fw = NULL;
+	int i, ret;
+
+	ret = request_firmware(&fw, fw_name, &client->dev);

drivers/net/pse-pd/tps23881.c line 688

Quoted 10 lines
drivers/net/pse-pd/tps23881.c new file +10 -0
+	if (ret)
+		return ret;
+
+	dev_info(&client->dev, "Flashing %s\n", fw_name);
+
+	/* Prepare device for RAM download */
+	while (fw_conf->reg) {
+		ret = i2c_smbus_write_byte_data(client, fw_conf->reg,
+						fw_conf->val);
+		if (ret < 0)

Hi Kory,

Should fw be released here.

drivers/net/pse-pd/tps23881.c line 699

Quoted 11 lines
drivers/net/pse-pd/tps23881.c new file +11 -0
+			return ret;
+
+		fw_conf++;
+	}
+
+	/* Flash the firmware file */
+	for (i = 0; i < fw->size; i++) {
+		ret = i2c_smbus_write_byte_data(client,
+						TPS23881_REG_SRAM_DATA,
+						fw->data[i]);
+		if (ret < 0)

And here?

Flagged by Smatch.

Quoted 7 lines
drivers/net/pse-pd/tps23881.c new file +7 -0
+			return ret;
+	}
+
+	release_firmware(fw);
+
+	return 0;
+}

...

author maintainer
#39 lore raw

Re: [PATCH net-next v5 17/17] net: pse-pd: Add TI TPS23881 PSE controller driver

Quoted 31 lines · On Wed, 28 Feb 2024 12:53:44 +0000 Simon Horman <[email protected]> wrote:
Quoted 6 lines · Kory Maincent

Add a new driver for the TI TPS23881 I2C Power Sourcing Equipment controller.

This patch is sponsored by Dent Project <[email protected]>.

...

Quoted 8 lines
drivers/net/pse-pd/tps23881.c new file +8 -0
+static int tps23881_flash_fw_part(struct i2c_client *client,
+				  const char *fw_name,
+				  const struct tps23881_fw_conf *fw_conf)
+{
+	const struct firmware *fw = NULL;
+	int i, ret;
+
+	ret = request_firmware(&fw, fw_name, &client->dev);

drivers/net/pse-pd/tps23881.c line 688

Quoted 10 lines
drivers/net/pse-pd/tps23881.c new file +10 -0
+	if (ret)
+		return ret;
+
+	dev_info(&client->dev, "Flashing %s\n", fw_name);
+
+	/* Prepare device for RAM download */
+	while (fw_conf->reg) {
+		ret = i2c_smbus_write_byte_data(client, fw_conf->reg,
+						fw_conf->val);
+		if (ret < 0)  

Hi Kory,

Quoted 1 line

Should fw be released here.

Hello Simon,

Indeed I have missed it, thanks.

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
#40 lore raw
In reply to Kory Maincent
Quoted 8 lines · Kory Maincent

This patch series aims at adding support for PoE (Power over Ethernet), based on the already existing support for PoDL (Power over Data Line) implementation. In addition, it adds support for two specific PoE controller, the Microchip PD692x0 and the TI TPS23881.

This patch series is sponsored by Dent Project
<[email protected]>.

Sorry, couldnt resist because it sounded like a commercial;-> And likely i am out of touch. I am all for giving credit but does it have to be explicitly called out as "this patch is sponsored by X"?

cheers,
jamal

Quoted 95 lines

In detail:
- Patch 1 to 13 prepare net to support PoE devices.
- Patch 14 and 15 add PD692x0 PoE PSE controller driver and its binding.
- Patch 16 and 17 add TI TPS23881 PSE controller driver and its binding.

Changes in v5:
- Fix bindings nit.
- Add supported-polarity parameter to bindings.
- Fix yamllint binding errors.
- Remove the nested lock brought by the use of regulator framework.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Replaced sponsored-by tag by a simple sentence.
- Fix pse_pi node bindings.
- Add pse pi documentation written by Oleksij.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Add patches to add Oleksij and myself to PSE MAINTAINERS.
- Add patches to add pse devlink.
- Add TI TPS23881 PSE controller driver with its binding.
- Replace pse_get_types helper by pse_has_podl and pse_has_c33
- Changed the PSE core bindings.
- Add a setup_pi_matrix callback.
- Register regulator for each PSE PI (Power Interface).
- Changed the PD692x0 bindings.
- Updated PD692x0 drivers to new bindings and PSE PI description.
- Updated PD692x0 drivers according to the reviews and made fixes.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Extract "firmware_loader: Expand Firmware upload error codes patches" to send it alone and get it merge in an immutable branch.
- Add "c33" prefix for PoE variables and enums.
- Enhance few comments.
- Add PSE Documentation.
- Make several changes in pd692x0 driver, mainly for readibility.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Kory Maincent (17):
MAINTAINERS: net: Add Oleksij to pse-pd maintainers
of: property: Add fw_devlink support for pse parent
net: pse-pd: Rectify and adapt the naming of admin_cotrol member of struct pse_control_config
ethtool: Expand Ethernet Power Equipment with c33 (PoE) alongside PoDL
net: pse-pd: Introduce PSE types enumeration
net: ethtool: pse-pd: Expand pse commands with the PSE PoE interface
netlink: specs: Modify pse attribute prefix
netlink: specs: Expand the pse netlink command with PoE interface
MAINTAINERS: Add myself to pse networking maintainer
net: pse-pd: Add support for PSE PIs
dt-bindings: net: pse-pd: Add another way of describing several PSE PIs
net: pse-pd: Add support for setup_pi_matrix callback
net: pse-pd: Use regulator framework within PSE framework
dt-bindings: net: pse-pd: Add bindings for PD692x0 PSE controller
net: pse-pd: Add PD692x0 PSE controller driver
dt-bindings: net: pse-pd: Add bindings for TPS23881 PSE controller
net: pse-pd: Add TI TPS23881 PSE controller driver

 .../bindings/net/pse-pd/microchip,pd692x0.yaml     |  158 +++
 .../bindings/net/pse-pd/pse-controller.yaml        |  100 +-
 .../bindings/net/pse-pd/ti,tps23881.yaml           |   93 ++
 Documentation/netlink/specs/ethtool.yaml           |   33 +-
 Documentation/networking/ethtool-netlink.rst       |   20 +
 Documentation/networking/index.rst                 |    1 +
 Documentation/networking/pse-pd/index.rst          |   10 +
 Documentation/networking/pse-pd/introduction.rst   |   73 ++
 Documentation/networking/pse-pd/pse-pi.rst         |  302 +++++
 MAINTAINERS                                        |    8 +
 drivers/net/mdio/fwnode_mdio.c                     |   29 +-
 drivers/net/pse-pd/Kconfig                         |   20 +
 drivers/net/pse-pd/Makefile                        |    2 +
 drivers/net/pse-pd/pd692x0.c                       | 1223 ++++++++++++++++++++
 drivers/net/pse-pd/pse_core.c                      |  429 ++++++-
 drivers/net/pse-pd/pse_regulator.c                 |   49 +-
 drivers/net/pse-pd/tps23881.c                      |  818 +++++++++++++
 drivers/of/property.c                              |    2 +
 include/linux/pse-pd/pse.h                         |   86 +-
 include/uapi/linux/ethtool.h                       |   55 +
 include/uapi/linux/ethtool_netlink.h               |    3 +
 net/ethtool/pse-pd.c                               |   60 +-
 22 files changed, 3451 insertions(+), 123 deletions(-)

---
base-commit: f308eae1e1cdacca3cef65c7f4f691dfcb0c8976
change-id: 20231024-feature_poe-139490e73403

Best regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

author maintainer
#41 lore raw
Quoted 8 lines · On Tue, 27 Feb 2024 10:31:05 -0500 Jamal Hadi Salim <[email protected]> wrote:
Quoted 6 lines · Kory Maincent

This patch series aims at adding support for PoE (Power over Ethernet), based on the already existing support for PoDL (Power over Data Line) implementation. In addition, it adds support for two specific PoE controller, the Microchip PD692x0 and the TI TPS23881.

Quoted 6 lines
Quoted 2 lines

This patch series is sponsored by Dent Project
<[email protected]>.

Sorry, couldnt resist because it sounded like a commercial;-> And likely i am out of touch. I am all for giving credit but does it have to be explicitly called out as "this patch is sponsored by X"?

Hello Jamal,

I will remove the line and add it in the From field as suggested by Jakub. It seems to be the usual way to do it.

Regards,

Signature · 3 lines
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com