Skip to content

Commit 5568363

Browse files
ffainellidavem330
authored andcommitted
net: phy: Create sysfs reciprocal links for attached_dev/phydev
There is currently no way for a program scanning /sys to know whether a network device is attached to a particular PHY device, just like the PHY device is not pointed back to its attached network device. Create a symbolic link in the network device's namespace named "phydev" which points to the PHY device and create a symbolic link in the PHY device's namespace named "attached_dev" that points back to the network device. These links are set up during phy_attach_direct() and removed during phy_detach() for symetry. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9226976 commit 5568363

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/net/phy/phy_device.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,15 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
960960

961961
phydev->attached_dev = dev;
962962
dev->phydev = phydev;
963+
err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj,
964+
"attached_dev");
965+
if (err)
966+
goto error;
967+
968+
err = sysfs_create_link(&dev->dev.kobj, &phydev->mdio.dev.kobj,
969+
"phydev");
970+
if (err)
971+
goto error;
963972

964973
phydev->dev_flags = flags;
965974

@@ -1050,6 +1059,8 @@ void phy_detach(struct phy_device *phydev)
10501059
struct mii_bus *bus;
10511060
int i;
10521061

1062+
sysfs_remove_link(&dev->dev.kobj, "phydev");
1063+
sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev");
10531064
phydev->attached_dev->phydev = NULL;
10541065
phydev->attached_dev = NULL;
10551066
phy_suspend(phydev);

0 commit comments

Comments
 (0)