Skip to contentSkip to conversation

net: phy: Add sysfs attribute for PHY c45 identifiers.

PATCH Superseded Jianhui Zhao 4 participants 5 messages Jun 14, 2023 – Jun 16, 2023

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: phy: Add sysfs attribute for PHY c45 identifiers.

If a phydevice use c45, its phy_id property is always 0, so this adds a c45_ids sysfs attribute group contains from mmd0 to mmd31 to MDIO devices.
This attribute group can be useful when debugging problems related to phy drivers.

Likes this:
/sys/bus/mdio_bus/devices/mdio-bus:05/c45_ids/mmd0 /sys/bus/mdio_bus/devices/mdio-bus:05/c45_ids/mmd1
...
/sys/bus/mdio_bus/devices/mdio-bus:05/c45_ids/mmd31

---
V2 -> V3: Use the most efficient implementation.
V1 -> V2: putting all 32 values in a subdirectory, one file per MMD

 .../ABI/testing/sysfs-class-net-phydev        |  10 ++
 drivers/net/phy/phy_device.c                  | 115 +++++++++++++++++-
 2 files changed, 124 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-class-net-phydev +10 -0
index ac722dd5e694..aefddd911b04 100644
@@ -63,3 +63,13 @@ Description:
 		only used internally by the kernel and their placement are
 		not meant to be stable across kernel versions. This is intended
 		for facilitating the debugging of PHY drivers.
+
+What:		/sys/class/mdio_bus/<bus>/<device>/c45_ids/mmd<n>
+Date:		November 2023
+KernelVersion:	6.4
+Contact:	[email protected]
+Description:
+		This attribute group c45_ids contains 32 mmd id attribute from mmd0 to mmd31
+		as reported by the device during bus enumeration, encoded in hexadecimal.
+		This ID is used to match the device with the appropriate
+		driver.
drivers/net/phy/phy_device.c +114 -1

121 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Wed, 14 Jun 2023 21:45:22 +0800 Jianhui Zhao wrote:

Did Andrew and Russell give review tags on the list ? I don't see any given to v2.

Well spotted, I did not. I merely made a suggestion that the author has picked up. The tel-tale is that my r-b line doesn't include "(Oracle)" in this instance. That r-b will need to be removed whatever the outcome of my further suggestion I've just sent.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#3 lore raw
In reply to Jianhui Zhao

drivers/net/phy/phy_device.c static struct attribute *phy_dev_attrs[] = { · line 712

Quoted 4 lines · Jianhui Zhao
drivers/net/phy/phy_device.c +4 -0
+static const struct attribute_group phy_dev_c45_ids_group = {
+	.name = "c45_ids",
+	.attrs = phy_c45_id_attrs
+};

One last thing - is there any point to creating these attributes if the PHY isn't c45?

We could add here:

	.is_visible = phy_dev_c45_visible,

with:

static umode_t phy_dev_c45_visible(struct kobject *kobj,
struct attribute *attr, int foo)

{
	struct phy_device *phydev = to_phy_device(kobj_to_dev(kobj));

	return phydev->is_c45 ? attr->mode : 0;
}

which will only show the c45 attributes if the PHY is a c45 PHY.

Andrew, any opinions?

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
maintainer
#4 lore raw
Quoted 23 lines · Russell King (Oracle)

drivers/net/phy/phy_device.c static struct attribute *phy_dev_attrs[] = { · line 712

Quoted 4 lines · Jianhui Zhao
drivers/net/phy/phy_device.c +4 -0
+static const struct attribute_group phy_dev_c45_ids_group = {
+	.name = "c45_ids",
+	.attrs = phy_c45_id_attrs
+};

One last thing - is there any point to creating these attributes if the PHY isn't c45?

We could add here:

	.is_visible = phy_dev_c45_visible,

with:

static umode_t phy_dev_c45_visible(struct kobject *kobj,
struct attribute *attr, int foo)

{
	struct phy_device *phydev = to_phy_device(kobj_to_dev(kobj));

	return phydev->is_c45 ? attr->mode : 0;
}
Quoted 3 lines

which will only show the c45 attributes if the PHY is a c45 PHY.

Andrew, any opinions?

There are PHYs which get detected via their C22 ID, but the driver then uses C45. So phydev->is_c45 could be false yet the device does have C45 IDs. But i don't see a good solution to this. If the point of these values is to aid debugging matching devices to drivers, this does not really matter. Its C22 ID is what will be used, and that sysfs file will be populated.

So this .is_visible seems reasonable.

I suppose there is the flip condition. Do we want the C22 sysfs file visible if there is no C22 ID? But that is probably ABI, we cannot change it now.

Andrew