Skip to content

Commit 3318348

Browse files
committed
Merge branch 'add-generic-pse-support'
Oleksij Rempel says: ==================== add generic PSE support Add generic support for the Ethernet Power Sourcing Equipment. ==================== Link: https://lore.kernel.org/r/20221003065202.3889095-1-o.rempel@pengutronix.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 46a275a + 66741b4 commit 3318348

File tree

21 files changed

+1080
-12
lines changed

21 files changed

+1080
-12
lines changed

Documentation/devicetree/bindings/net/ethernet-phy.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ properties:
144144
Mark the corresponding energy efficient ethernet mode as
145145
broken and request the ethernet to stop advertising it.
146146

147+
pses:
148+
$ref: /schemas/types.yaml#/definitions/phandle-array
149+
maxItems: 1
150+
description:
151+
Specifies a reference to a node representing a Power Sourcing Equipment.
152+
147153
phy-is-integrated:
148154
$ref: /schemas/types.yaml#/definitions/flag
149155
description:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/net/pse-pd/podl-pse-regulator.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Regulator based Power Sourcing Equipment
8+
9+
maintainers:
10+
- Oleksij Rempel <o.rempel@pengutronix.de>
11+
12+
description: Regulator based PoDL PSE controller. The device must be referenced
13+
by the PHY node to control power injection to the Ethernet cable.
14+
15+
allOf:
16+
- $ref: "pse-controller.yaml#"
17+
18+
properties:
19+
compatible:
20+
const: podl-pse-regulator
21+
22+
'#pse-cells':
23+
const: 0
24+
25+
pse-supply:
26+
description: Power supply for the PSE controller
27+
28+
additionalProperties: false
29+
30+
required:
31+
- compatible
32+
- pse-supply
33+
34+
examples:
35+
- |
36+
ethernet-pse {
37+
compatible = "podl-pse-regulator";
38+
pse-supply = <&reg_t1l1>;
39+
#pse-cells = <0>;
40+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/net/pse-pd/pse-controller.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Power Sourcing Equipment (PSE).
8+
9+
description: Binding for the Power Sourcing Equipment (PSE) as defined in the
10+
IEEE 802.3 specification. It is designed for hardware which is delivering
11+
power over twisted pair/ethernet cable. The ethernet-pse nodes should be
12+
used to describe PSE controller and referenced by the ethernet-phy node.
13+
14+
maintainers:
15+
- Oleksij Rempel <o.rempel@pengutronix.de>
16+
17+
properties:
18+
$nodename:
19+
pattern: "^ethernet-pse(@.*)?$"
20+
21+
"#pse-cells":
22+
description:
23+
Used to uniquely identify a PSE instance within an IC. Will be
24+
0 on PSE nodes with only a single output and at least 1 on nodes
25+
controlling several outputs.
26+
enum: [0, 1]
27+
28+
required:
29+
- "#pse-cells"
30+
31+
additionalProperties: true
32+
33+
...

Documentation/networking/ethtool-netlink.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ Userspace to kernel:
220220
``ETHTOOL_MSG_PHC_VCLOCKS_GET`` get PHC virtual clocks info
221221
``ETHTOOL_MSG_MODULE_SET`` set transceiver module parameters
222222
``ETHTOOL_MSG_MODULE_GET`` get transceiver module parameters
223+
``ETHTOOL_MSG_PSE_SET`` set PSE parameters
224+
``ETHTOOL_MSG_PSE_GET`` get PSE parameters
223225
===================================== =================================
224226

225227
Kernel to userspace:
@@ -260,6 +262,7 @@ Kernel to userspace:
260262
``ETHTOOL_MSG_STATS_GET_REPLY`` standard statistics
261263
``ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY`` PHC virtual clocks info
262264
``ETHTOOL_MSG_MODULE_GET_REPLY`` transceiver module parameters
265+
``ETHTOOL_MSG_PSE_GET_REPLY`` PSE parameters
263266
======================================== =================================
264267

265268
``GET`` requests are sent by userspace applications to retrieve device
@@ -1627,6 +1630,62 @@ For SFF-8636 modules, low power mode is forced by the host according to table
16271630
For CMIS modules, low power mode is forced by the host according to table 6-12
16281631
in revision 5.0 of the specification.
16291632

1633+
PSE_GET
1634+
=======
1635+
1636+
Gets PSE attributes.
1637+
1638+
Request contents:
1639+
1640+
===================================== ====== ==========================
1641+
``ETHTOOL_A_PSE_HEADER`` nested request header
1642+
===================================== ====== ==========================
1643+
1644+
Kernel response contents:
1645+
1646+
====================================== ====== =============================
1647+
``ETHTOOL_A_PSE_HEADER`` nested reply header
1648+
``ETHTOOL_A_PODL_PSE_ADMIN_STATE`` u32 Operational state of the PoDL
1649+
PSE functions
1650+
``ETHTOOL_A_PODL_PSE_PW_D_STATUS`` u32 power detection status of the
1651+
PoDL PSE.
1652+
====================================== ====== =============================
1653+
1654+
When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_STATE`` attribute identifies
1655+
the operational state of the PoDL PSE functions. The operational state of the
1656+
PSE function can be changed using the ``ETHTOOL_A_PODL_PSE_ADMIN_CONTROL``
1657+
action. This option is corresponding to ``IEEE 802.3-2018`` 30.15.1.1.2
1658+
aPoDLPSEAdminState. Possible values are:
1659+
1660+
.. kernel-doc:: include/uapi/linux/ethtool.h
1661+
:identifiers: ethtool_podl_pse_admin_state
1662+
1663+
When set, the optional ``ETHTOOL_A_PODL_PSE_PW_D_STATUS`` attribute identifies
1664+
the power detection status of the PoDL PSE. The status depend on internal PSE
1665+
state machine and automatic PD classification support. This option is
1666+
corresponding to ``IEEE 802.3-2018`` 30.15.1.1.3 aPoDLPSEPowerDetectionStatus.
1667+
Possible values are:
1668+
1669+
.. kernel-doc:: include/uapi/linux/ethtool.h
1670+
:identifiers: ethtool_podl_pse_pw_d_status
1671+
1672+
PSE_SET
1673+
=======
1674+
1675+
Sets PSE parameters.
1676+
1677+
Request contents:
1678+
1679+
====================================== ====== =============================
1680+
``ETHTOOL_A_PSE_HEADER`` nested request header
1681+
``ETHTOOL_A_PODL_PSE_ADMIN_CONTROL`` u32 Control PoDL PSE Admin state
1682+
====================================== ====== =============================
1683+
1684+
When set, the optional ``ETHTOOL_A_PODL_PSE_ADMIN_CONTROL`` attribute is used
1685+
to control PoDL PSE Admin functions. This option is implementing
1686+
``IEEE 802.3-2018`` 30.15.1.2.1 acPoDLPSEAdminControl. See
1687+
``ETHTOOL_A_PODL_PSE_ADMIN_STATE`` for supported values.
1688+
16301689
Request translation
16311690
===================
16321691

drivers/net/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ config NET_SB1000
500500

501501
source "drivers/net/phy/Kconfig"
502502

503+
source "drivers/net/pse-pd/Kconfig"
504+
503505
source "drivers/net/can/Kconfig"
504506

505507
source "drivers/net/mctp/Kconfig"

drivers/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ obj-$(CONFIG_NET) += loopback.o
2323
obj-$(CONFIG_NETDEV_LEGACY_INIT) += Space.o
2424
obj-$(CONFIG_NETCONSOLE) += netconsole.o
2525
obj-y += phy/
26+
obj-y += pse-pd/
2627
obj-y += mdio/
2728
obj-y += pcs/
2829
obj-$(CONFIG_RIONET) += rionet.o

drivers/net/mdio/fwnode_mdio.c

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,31 @@
1010
#include <linux/fwnode_mdio.h>
1111
#include <linux/of.h>
1212
#include <linux/phy.h>
13+
#include <linux/pse-pd/pse.h>
1314

1415
MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>");
1516
MODULE_LICENSE("GPL");
1617

18+
static struct pse_control *
19+
fwnode_find_pse_control(struct fwnode_handle *fwnode)
20+
{
21+
struct pse_control *psec;
22+
struct device_node *np;
23+
24+
if (!IS_ENABLED(CONFIG_PSE_CONTROLLER))
25+
return NULL;
26+
27+
np = to_of_node(fwnode);
28+
if (!np)
29+
return NULL;
30+
31+
psec = of_pse_control_get(np);
32+
if (PTR_ERR(psec) == -ENOENT)
33+
return NULL;
34+
35+
return psec;
36+
}
37+
1738
static struct mii_timestamper *
1839
fwnode_find_mii_timestamper(struct fwnode_handle *fwnode)
1940
{
@@ -91,14 +112,21 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
91112
struct fwnode_handle *child, u32 addr)
92113
{
93114
struct mii_timestamper *mii_ts = NULL;
115+
struct pse_control *psec = NULL;
94116
struct phy_device *phy;
95117
bool is_c45 = false;
96118
u32 phy_id;
97119
int rc;
98120

121+
psec = fwnode_find_pse_control(child);
122+
if (IS_ERR(psec))
123+
return PTR_ERR(psec);
124+
99125
mii_ts = fwnode_find_mii_timestamper(child);
100-
if (IS_ERR(mii_ts))
101-
return PTR_ERR(mii_ts);
126+
if (IS_ERR(mii_ts)) {
127+
rc = PTR_ERR(mii_ts);
128+
goto clean_pse;
129+
}
102130

103131
rc = fwnode_property_match_string(child, "compatible",
104132
"ethernet-phy-ieee802.3-c45");
@@ -110,8 +138,8 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
110138
else
111139
phy = phy_device_create(bus, addr, phy_id, 0, NULL);
112140
if (IS_ERR(phy)) {
113-
unregister_mii_timestamper(mii_ts);
114-
return PTR_ERR(phy);
141+
rc = PTR_ERR(phy);
142+
goto clean_mii_ts;
115143
}
116144

117145
if (is_acpi_node(child)) {
@@ -125,25 +153,33 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
125153
/* All data is now stored in the phy struct, so register it */
126154
rc = phy_device_register(phy);
127155
if (rc) {
128-
phy_device_free(phy);
129156
fwnode_handle_put(phy->mdio.dev.fwnode);
130-
return rc;
157+
goto clean_phy;
131158
}
132159
} else if (is_of_node(child)) {
133160
rc = fwnode_mdiobus_phy_device_register(bus, phy, child, addr);
134-
if (rc) {
135-
unregister_mii_timestamper(mii_ts);
136-
phy_device_free(phy);
137-
return rc;
138-
}
161+
if (rc)
162+
goto clean_phy;
139163
}
140164

165+
phy->psec = psec;
166+
141167
/* phy->mii_ts may already be defined by the PHY driver. A
142168
* mii_timestamper probed via the device tree will still have
143169
* precedence.
144170
*/
145171
if (mii_ts)
146172
phy->mii_ts = mii_ts;
173+
147174
return 0;
175+
176+
clean_phy:
177+
phy_device_free(phy);
178+
clean_mii_ts:
179+
unregister_mii_timestamper(mii_ts);
180+
clean_pse:
181+
pse_control_put(psec);
182+
183+
return rc;
148184
}
149185
EXPORT_SYMBOL(fwnode_mdiobus_register_phy);

drivers/net/phy/phy_device.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/netdevice.h>
2727
#include <linux/phy.h>
2828
#include <linux/phy_led_triggers.h>
29+
#include <linux/pse-pd/pse.h>
2930
#include <linux/property.h>
3031
#include <linux/sfp.h>
3132
#include <linux/skbuff.h>
@@ -991,6 +992,7 @@ EXPORT_SYMBOL(phy_device_register);
991992
void phy_device_remove(struct phy_device *phydev)
992993
{
993994
unregister_mii_timestamper(phydev->mii_ts);
995+
pse_control_put(phydev->psec);
994996

995997
device_del(&phydev->mdio.dev);
996998

drivers/net/pse-pd/Kconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
# Ethernet Power Sourcing Equipment drivers
4+
#
5+
6+
menuconfig PSE_CONTROLLER
7+
bool "Ethernet Power Sourcing Equipment Support"
8+
help
9+
Generic Power Sourcing Equipment Controller support.
10+
11+
If unsure, say no.
12+
13+
if PSE_CONTROLLER
14+
15+
config PSE_REGULATOR
16+
tristate "Regulator based PSE controller"
17+
help
18+
This module provides support for simple regulator based Ethernet Power
19+
Sourcing Equipment without automatic classification support. For
20+
example for basic implementation of PoDL (802.3bu) specification.
21+
22+
endif

drivers/net/pse-pd/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
# Makefile for Linux PSE drivers
3+
4+
obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o
5+
6+
obj-$(CONFIG_PSE_REGULATOR) += pse_regulator.o

0 commit comments

Comments
 (0)