Skip to contentSkip to conversation

net: phy: Create sysfs reciprocal links for attached_dev/phydev

PATCH In review Florian Fainelli 3 participants 6 messages May 25, 2017 – May 26, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover net: phy: Create sysfs reciprocal links for attached_dev/phydev

Hi David, Andrew,

This patch series addresses a device topology shortcoming where a program scanning /sys would not be able to establish a mapping between the network device and the PHY device.

In the process it turned out that no PHY device documentation existed for sysfs attributes.

Thanks!

Changes in v2:

- document possible phy_interface values in sysfs-class-net-phydev

Florian Fainelli (3):
net: phy: Create sysfs reciprocal links for attached_dev/phydev
net: sysfs: Document "phydev" symbolic link
net: sysfs: Document PHY device sysfs attributes

 Documentation/ABI/testing/sysfs-class-net        |  8 ++++++
 Documentation/ABI/testing/sysfs-class-net-phydev | 36 ++++++++++++++++++++++++
 drivers/net/phy/phy_device.c                     | 11 ++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-net-phydev
Signature · 1 line
2.9.3
#1 lore raw

PATCH v2 1/3 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.

---
 drivers/net/phy/phy_device.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/phy/phy_device.c +11 -0
index 1219eeab69d1..8151477c7027 100644
@@ -960,6 +960,15 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 
 	phydev->attached_dev = dev;
 	dev->phydev = phydev;
+	err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj,
+				"attached_dev");
+	if (err)
+		goto error;
+
+	err = sysfs_create_link(&dev->dev.kobj, &phydev->mdio.dev.kobj,
+				"phydev");
+	if (err)
+		goto error;
 
 	phydev->dev_flags = flags;
 
@@ -1050,6 +1059,8 @@ void phy_detach(struct phy_device *phydev)
 	struct mii_bus *bus;
 	int i;
 
+	sysfs_remove_link(&dev->dev.kobj, "phydev");
+	sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev");
 	phydev->attached_dev->phydev = NULL;
 	phydev->attached_dev = NULL;
 	phy_suspend(phydev);
Signature · 1 line
2.9.3
#2 lore raw

PATCH v2 2/3 net: sysfs: Document "phydev" symbolic link

In reply to Florian Fainelli

Now that we link the network device to its PHY device, document this sysfs symbolic link.

---
 Documentation/ABI/testing/sysfs-class-net | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/ABI/testing/sysfs-class-net +8 -0
index 668604fc8e06..6856da99b6f7 100644
@@ -251,3 +251,11 @@ Contact:	[email protected]
 Description:
 		Indicates the unique physical switch identifier of a switch this
 		port belongs to, as a string.
+
+What:		/sys/class/net/<iface>/phydev
+Date:		May 2017
+KernelVersion:	4.13
+Contact:	[email protected]
+Description:
+		Symbolic link to the PHY device this network device is attached
+		to.
Signature · 1 line
2.9.3
#3 lore raw

PATCH v2 3/3 net: sysfs: Document PHY device sysfs attributes

In reply to Florian Fainelli

Document the different sysfs attributes that exist for PHY devices:
attached_dev, phy_has_fixups, phy_id and phy_interface.

---
 Documentation/ABI/testing/sysfs-class-net-phydev | 36 ++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-net-phydev
Documentation/ABI/testing/sysfs-class-net-phydev new file +36 -0
new file mode 100644
index 000000000000..c768d5fd8496
@@ -0,0 +1,36 @@
+What:		/sys/class/mdio_bus/<bus>/<device>/attached_dev
+Date:		May 2017
+KernelVersion:	4.13
+Contact:	[email protected]
+Description:
+		Symbolic link to the network device this PHY device is
+		attached to.
+
+What:		/sys/class/mdio_bus/<bus>/<device>/phy_has_fixups
+Date:		February 2014
+KernelVersion:	3.15
+Contact:	[email protected]
+Description:
+		Boolean value indicating whether the PHY device has
+		any fixups registered against it (phy_register_fixup)
+
+What:		/sys/class/mdio_bus/<bus>/<device>/phy_id
+Date:		November 2012
+KernelVersion:	3.8
+Contact:	[email protected]
+Description:
+		32-bit hexadecimal value corresponding to the PHY device's OUI,
+		model and revision number.
+
+What:		/sys/class/mdio_bus/<bus>/<device>/phy_interface
+Date:		February 2014
+KernelVersion:	3.15
+Contact:	[email protected]
+Description:
+		String value indicating the PHY interface, possible
+		values are:.
+		<empty> (not available), mii, gmii, sgmii, tbi, rev-mii,
+		rmii, rgmii, rgmii-id, rgmii-rxid, rgmii-txid, rtbi, smii
+		xgmii, moca, qsgmii, trgmii, 1000base-x, 2500base-x, rxaui,
+		unknown
+
Signature · 1 line
2.9.3
maintainer Reviewed-by on the v2 series
#4 lore raw
In reply to Florian Fainelli
Quoted 10 lines · Florian Fainelli

Hi David, Andrew,

This patch series addresses a device topology shortcoming where a program scanning /sys would not be able to establish a mapping between the network device and the PHY device.

In the process it turned out that no PHY device documentation existed for sysfs attributes.

Thanks!

Andrew

maintainer
#5 lore raw

From: Andrew Lunn <[email protected]>
Date: Thu, 25 May 2017 18:42:27 +0200

Quoted 7 lines · Florian Fainelli
Quoted 6 lines

Hi David, Andrew,

This patch series addresses a device topology shortcoming where a program scanning /sys would not be able to establish a mapping between the network device and the PHY device.

Quoted 6 lines
Quoted 4 lines

In the process it turned out that no PHY device documentation existed for sysfs attributes.

Thanks!

Series applied, thanks everyone.