Skip to content

Commit 5e82147

Browse files
oleremkuba-moo
authored andcommitted
net: mdiobus: search for PSE nodes by parsing PHY nodes.
Some PHYs can be linked with PSE (Power Sourcing Equipment), so search for related nodes and attach it to the phydev. Signed-off-by: Oleksij Rempel <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent cfaa202 commit 5e82147

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

drivers/net/mdio/fwnode_mdio.c

Lines changed: 35 additions & 2 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 <[email protected]>");
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");
@@ -134,18 +162,23 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
134162
goto clean_phy;
135163
}
136164

165+
phy->psec = psec;
166+
137167
/* phy->mii_ts may already be defined by the PHY driver. A
138168
* mii_timestamper probed via the device tree will still have
139169
* precedence.
140170
*/
141171
if (mii_ts)
142172
phy->mii_ts = mii_ts;
173+
143174
return 0;
144175

145176
clean_phy:
146177
phy_device_free(phy);
147178
clean_mii_ts:
148179
unregister_mii_timestamper(mii_ts);
180+
clean_pse:
181+
pse_control_put(psec);
149182

150183
return rc;
151184
}

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

include/linux/phy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ struct macsec_ops;
597597
* @master_slave_get: Current master/slave advertisement
598598
* @master_slave_state: Current master/slave configuration
599599
* @mii_ts: Pointer to time stamper callbacks
600+
* @psec: Pointer to Power Sourcing Equipment control struct
600601
* @lock: Mutex for serialization access to PHY
601602
* @state_queue: Work queue for state machine
602603
* @shared: Pointer to private data shared by phys in one package
@@ -715,6 +716,7 @@ struct phy_device {
715716
struct phylink *phylink;
716717
struct net_device *attached_dev;
717718
struct mii_timestamper *mii_ts;
719+
struct pse_control *psec;
718720

719721
u8 mdix;
720722
u8 mdix_ctrl;

0 commit comments

Comments
 (0)