Skip to contentSkip to conversation

net: phy: Add c45_phy_ids sysfs directory entry

PATCH RESEND Superseded Yajun Deng 2 participants 3 messages Jun 12, 2025 – Jun 13, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yajun Deng

author
#0 lore raw

PATCH RESEND v2 1/1 net: phy: Add c45_phy_ids sysfs directory entry

The phy_id field only shows the PHY ID of the C22 device, and the C45 device did not store its PHY ID in this field.

Add a new phy_mmd_group, and export the mmd<n>_device_id for the C45 device. These files are invisible to the C22 device.

---
v2: Only one value for per file and invisible to the C22 device.
v1: https://lore.kernel.org/all/[email protected]/

---
 .../ABI/testing/sysfs-class-net-phydev        | 10 +++
 drivers/net/phy/phy_device.c                  | 62 ++++++++++++++++++-
 2 files changed, 70 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-class-net-phydev +10 -0
index ac722dd5e694..31615c59bff9 100644
@@ -26,6 +26,16 @@ Description:
 		This ID is used to match the device with the appropriate
 		driver.
 
+What:		/sys/class/mdio_bus/<bus>/<device>/c45_phy_ids/mmd<n>_device_id
+Date:		June 2025
+KernelVersion:	6.17
+Contact:	[email protected]
+Description:
+		This attribute contains the 32-bit PHY Identifier as reported
+		by the device during bus enumeration, encoded in hexadecimal.
+		These C45 IDs are used to match the device with the appropriate
+		driver. These files are invisible to the C22 device.
+
 What:		/sys/class/mdio_bus/<bus>/<device>/phy_interface
 Date:		February 2014
 KernelVersion:	3.15
drivers/net/phy/phy_device.c +60 -2

71 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#1 lore raw

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

Quoted 5 lines
drivers/net/phy/phy_device.c +5 -0
+#define MMD_INDICES \
+	_(1) _(2) _(3) _(4) _(5) _(6) _(7) _(8) \
+	_(9) _(10) _(11) _(12) _(13) _(14) _(15) _(16) \
+	_(17) _(18) _(19) _(20) _(21) _(22) _(23) _(24) \
+	_(25) _(26) _(27) _(28) _(29) _(30) _(31)

Is 0 not valid?

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

Quoted 9 lines
drivers/net/phy/phy_device.c +9 -0
+#define MMD_DEVICE_ID_ATTR(n) \
+static ssize_t mmd##n##_device_id_show(struct device *dev, \
+				struct device_attribute *attr, char *buf) \
+{ \
+	struct phy_device *phydev = to_phy_device(dev); \
+	return sysfs_emit(buf, "0x%.8lx\n", \
+			 (unsigned long)phydev->c45_ids.device_ids[n]); \
+} \
+static DEVICE_ATTR_RO(mmd##n##_device_id)

This macro magic i can follow, you see this quite a bit in the kernel.

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

Quoted 11 lines
drivers/net/phy/phy_device.c +11 -0
+
+#define _(x) MMD_DEVICE_ID_ATTR(x);
+MMD_INDICES
+#undef _
+
+static struct attribute *phy_mmd_attrs[] = {
+	#define _(x) &dev_attr_mmd##x##_device_id.attr,
+	MMD_INDICES
+	#undef _
+	NULL
+};

If i squint at this enough, i can work it out, but generally a much more readable KISS approach is taken, of just invoking a macro 32 times. See mdio_bus.c as an example.

Andrew

---
pw-bot: cr

author
#2 lore raw
Quoted 6 lines · Andrew Lunn
Quoted 6 lines

+#define MMD_INDICES \

+ _(1) _(2) _(3) _(4) _(5) _(6) _(7) _(8) \

Quoted 9 lines
Quoted 6 lines

+ _(9) _(10) _(11) _(12) _(13) _(14) _(15) _(16) \

+ _(17) _(18) _(19) _(20) _(21) _(22) _(23) _(24) \

+ _(25) _(26) _(27) _(28) _(29) _(30) _(31)

Is 0 not valid?

Yes, the MMD starts at 1. See "include/uapi/linux/mdio.h".

Quoted 13 lines
Quoted 13 lines

+#define MMD_DEVICE_ID_ATTR(n) \

+static ssize_t mmd##n##_device_id_show(struct device *dev, \

+ struct device_attribute *attr, char *buf) \

+{ \

+ struct phy_device *phydev = to_phy_device(dev); \

+ return sysfs_emit(buf, "0x%.8lx\n", \

Quoted 9 lines
Quoted 6 lines

+ (unsigned long)phydev->c45_ids.device_ids[n]); \

+} \

+static DEVICE_ATTR_RO(mmd##n##_device_id)

This macro magic i can follow, you see this quite a bit in the kernel.

Okay.

Quoted 21 lines
Quoted 21 lines

+

+#define _(x) MMD_DEVICE_ID_ATTR(x);

+MMD_INDICES

+#undef _

+

+static struct attribute *phy_mmd_attrs[] = {

+ #define _(x) &dev_attr_mmd##x##_device_id.attr,

+ MMD_INDICES

+ #undef _

+ NULL

Quoted 9 lines
Quoted 2 lines

+};

If i squint at this enough, i can work it out, but generally a much

more readable KISS approach is taken, of just invoking a macro 32

times. See mdio_bus.c as an example.

Okay.

Quoted 6 lines

Andrew

---

pw-bot: cr