netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: phy: Add sysfs attribute for PHY c45 identifiers.
@ 2023-06-11 15:27 Jianhui Zhao
  2023-06-11 15:40 ` Andrew Lunn
  2023-06-12 14:04 ` Jianhui Zhao
  0 siblings, 2 replies; 6+ messages in thread
From: Jianhui Zhao @ 2023-06-11 15:27 UTC (permalink / raw)
  To: andrew
  Cc: hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, Jianhui Zhao

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

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
---
 drivers/net/phy/phy_device.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 17d0d0555a79..521228792840 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -560,6 +560,29 @@ phy_id_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR_RO(phy_id);
 
+static ssize_t
+phy_c45_ids_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct phy_device *phydev = to_phy_device(dev);
+	const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids);
+	int ret = 0;
+	int i;
+
+	if (!phydev->is_c45)
+		return 0;
+
+	for (i = 1; i < num_ids; i++) {
+		if (phydev->c45_ids.device_ids[i] == 0xffffffff)
+			continue;
+
+		ret += sprintf(buf + ret, "%d: 0x%.8lx\n", i,
+			(unsigned long)phydev->c45_ids.device_ids[i]);
+	}
+
+	return ret;
+}
+static DEVICE_ATTR_RO(phy_c45_ids);
+
 static ssize_t
 phy_interface_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -597,6 +620,7 @@ static DEVICE_ATTR_RO(phy_dev_flags);
 
 static struct attribute *phy_dev_attrs[] = {
 	&dev_attr_phy_id.attr,
+	&dev_attr_phy_c45_ids.attr,
 	&dev_attr_phy_interface.attr,
 	&dev_attr_phy_has_fixups.attr,
 	&dev_attr_phy_dev_flags.attr,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: phy: Add sysfs attribute for PHY c45 identifiers.
  2023-06-11 15:27 [PATCH] net: phy: Add sysfs attribute for PHY c45 identifiers Jianhui Zhao
@ 2023-06-11 15:40 ` Andrew Lunn
  2023-06-12 14:04 ` Jianhui Zhao
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2023-06-11 15:40 UTC (permalink / raw)
  To: Jianhui Zhao
  Cc: hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev, linux-kernel

On Sun, Jun 11, 2023 at 11:27:43PM +0800, Jianhui Zhao wrote:
> If a phydevice use c45, its phy_id property is always 0, so
> this adds a phy_c45_ids sysfs attribute to MDIO devices. This
> attribute can be useful when debugging problems related to
> phy drivers.

> +	for (i = 1; i < num_ids; i++) {
> +		if (phydev->c45_ids.device_ids[i] == 0xffffffff)
> +			continue;
> +
> +		ret += sprintf(buf + ret, "%d: 0x%.8lx\n", i,
> +			(unsigned long)phydev->c45_ids.device_ids[i]);
> +	}

https://www.kernel.org/doc/html/next/filesystems/sysfs.html says:

  Attributes should be ASCII text files, preferably with only one
  value per file. It is noted that it may not be efficient to contain
  only one value per file, so it is socially acceptable to express an
  array of values of the same type.

How about putting all 32 values in a subdirectory, one file per MMD?

Please also remember to document the attributes in
Documentation/ABI/testing/sysfs-class-net-phydev.

    Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] net: phy: Add sysfs attribute for PHY c45 identifiers.
  2023-06-11 15:27 [PATCH] net: phy: Add sysfs attribute for PHY c45 identifiers Jianhui Zhao
  2023-06-11 15:40 ` Andrew Lunn
@ 2023-06-12 14:04 ` Jianhui Zhao
  2023-06-12 14:10   ` Andrew Lunn
  2023-06-12 15:06   ` Russell King (Oracle)
  1 sibling, 2 replies; 6+ messages in thread
From: Jianhui Zhao @ 2023-06-12 14:04 UTC (permalink / raw)
  To: zhaojh329
  Cc: andrew, davem, edumazet, hkallweit1, kuba, linux-kernel, linux,
	netdev, pabeni

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 17d0d0555a79..81a4bc043ee2 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -541,8 +541,10 @@ static int phy_bus_match(struct device *dev, struct device_driver *drv)
 
 			if ((phydrv->phy_id & phydrv->phy_id_mask) ==
 			    (phydev->c45_ids.device_ids[i] &
-			     phydrv->phy_id_mask))
+			     phydrv->phy_id_mask)) {
+				phydev->phy_id = phydev->c45_ids.device_ids[i];
 				return 1;
+			}
 		}
 		return 0;
 	} else {

How about modifying it like this?

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: phy: Add sysfs attribute for PHY c45 identifiers.
  2023-06-12 14:04 ` Jianhui Zhao
@ 2023-06-12 14:10   ` Andrew Lunn
  2023-06-12 15:06   ` Russell King (Oracle)
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2023-06-12 14:10 UTC (permalink / raw)
  To: Jianhui Zhao
  Cc: davem, edumazet, hkallweit1, kuba, linux-kernel, linux, netdev, pabeni

On Mon, Jun 12, 2023 at 10:04:26PM +0800, Jianhui Zhao wrote:
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 17d0d0555a79..81a4bc043ee2 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -541,8 +541,10 @@ static int phy_bus_match(struct device *dev, struct device_driver *drv)
>  
>  			if ((phydrv->phy_id & phydrv->phy_id_mask) ==
>  			    (phydev->c45_ids.device_ids[i] &
> -			     phydrv->phy_id_mask))
> +			     phydrv->phy_id_mask)) {
> +				phydev->phy_id = phydev->c45_ids.device_ids[i];
>  				return 1;
> +			}
>  		}
>  		return 0;
>  	} else {
> 
> How about modifying it like this?

O.K.

Please update the sysfs documentation as well.

       Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: phy: Add sysfs attribute for PHY c45 identifiers.
  2023-06-12 14:04 ` Jianhui Zhao
  2023-06-12 14:10   ` Andrew Lunn
@ 2023-06-12 15:06   ` Russell King (Oracle)
  2023-06-12 15:10     ` Russell King (Oracle)
  1 sibling, 1 reply; 6+ messages in thread
From: Russell King (Oracle) @ 2023-06-12 15:06 UTC (permalink / raw)
  To: Jianhui Zhao
  Cc: andrew, davem, edumazet, hkallweit1, kuba, linux-kernel, netdev, pabeni

On Mon, Jun 12, 2023 at 10:04:26PM +0800, Jianhui Zhao wrote:
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 17d0d0555a79..81a4bc043ee2 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -541,8 +541,10 @@ static int phy_bus_match(struct device *dev, struct device_driver *drv)
>  
>  			if ((phydrv->phy_id & phydrv->phy_id_mask) ==
>  			    (phydev->c45_ids.device_ids[i] &
> -			     phydrv->phy_id_mask))
> +			     phydrv->phy_id_mask)) {
> +				phydev->phy_id = phydev->c45_ids.device_ids[i];
>  				return 1;
> +			}
>  		}
>  		return 0;
>  	} else {
> 
> How about modifying it like this?

No - there are C45 PHYs where the ID in each MMD are different. 88x3310
is one such example. If we're going to report any of them, we should
report all of them.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: phy: Add sysfs attribute for PHY c45 identifiers.
  2023-06-12 15:06   ` Russell King (Oracle)
@ 2023-06-12 15:10     ` Russell King (Oracle)
  0 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2023-06-12 15:10 UTC (permalink / raw)
  To: Jianhui Zhao
  Cc: andrew, davem, edumazet, hkallweit1, kuba, linux-kernel, netdev, pabeni

On Mon, Jun 12, 2023 at 04:06:32PM +0100, Russell King (Oracle) wrote:
> On Mon, Jun 12, 2023 at 10:04:26PM +0800, Jianhui Zhao wrote:
> > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > index 17d0d0555a79..81a4bc043ee2 100644
> > --- a/drivers/net/phy/phy_device.c
> > +++ b/drivers/net/phy/phy_device.c
> > @@ -541,8 +541,10 @@ static int phy_bus_match(struct device *dev, struct device_driver *drv)
> >  
> >  			if ((phydrv->phy_id & phydrv->phy_id_mask) ==
> >  			    (phydev->c45_ids.device_ids[i] &
> > -			     phydrv->phy_id_mask))
> > +			     phydrv->phy_id_mask)) {
> > +				phydev->phy_id = phydev->c45_ids.device_ids[i];
> >  				return 1;
> > +			}
> >  		}
> >  		return 0;
> >  	} else {
> > 
> > How about modifying it like this?
> 
> No - there are C45 PHYs where the ID in each MMD are different. 88x3310
> is one such example. If we're going to report any of them, we should
> report all of them.

The other issue is, this will remain as zero until a driver has
successfully matched the device, which means as far as userspace
knowing what type of PHY it is (to find a driver) this doesn't
improve the situation.

I don't think this is a very good solution.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-12 15:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-11 15:27 [PATCH] net: phy: Add sysfs attribute for PHY c45 identifiers Jianhui Zhao
2023-06-11 15:40 ` Andrew Lunn
2023-06-12 14:04 ` Jianhui Zhao
2023-06-12 14:10   ` Andrew Lunn
2023-06-12 15:06   ` Russell King (Oracle)
2023-06-12 15:10     ` Russell King (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).