Skip to contentSkip to conversation

net: phy: small cleanups and improvements

PATCH In review Florian Fainelli 3 participants 15 messages Feb 12, 2014 – Feb 13, 2014

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

cover net: phy: small cleanups and improvements

Hi David,

This patchset contains some small cleanups which have been sent on the mailing-list before to improve phy_print_status() and make it useful.

The second part of the patch allows PHY drivers to implement their own aneg_done() callback.

Finally, two new sysfs properties are exposed to help troubleshoot libphy aware Linux systems.

Thanks!

Florian Fainelli (10):
net: phy: use network device in phy_print_status
net: phy: update phy_print_status to show pause settings
net: phy: display human readable PHY speed settings
net: phy: add genphy_aneg_done()
net: phy: allow driver to implement their own aneg_done
net: phy: fix phy_{clear,config}_interrupt comment typos
net: phy: re-design phy_modes to be self-contained
net: phy: expose PHY device interface mode
net: phy: add "has_fixups" boolean property
net: phy: expose phydev->has_fixups to sysfs

 Documentation/ABI/testing/sysfs-bus-mdio | 21 ++++++++++++++
 drivers/net/phy/mdio_bus.c               | 20 ++++++++++++++
 drivers/net/phy/phy.c                    | 46 +++++++++++++++++++++++--------
 drivers/net/phy/phy_device.c             | 18 ++++++++++++
 drivers/of/of_net.c                      | 26 ++----------------
 include/linux/phy.h                      | 47 ++++++++++++++++++++++++++++++++
 6 files changed, 142 insertions(+), 36 deletions(-)
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/10 net: phy: use network device in phy_print_status

phy_print_status() currently uses dev_name(&phydev->dev) which will usually result in printing something along those lines for Device Tree aware drivers:

libphy: f0b60000.etherne:0a - Link is Down
libphy: f0ba0000.etherne:00 - Link is Up - 1000/Full

This is not terribly useful for network administrators or users since we expect a network interface name to be able to correlate link events with interfaces. Update phy_print_status() to use netdev_info() with phydev->attached_dev which is the backing network device for our PHY device. The leading dash is removed since netdev_info() prefixes the messages with "<interface>: " already.

---
 drivers/net/phy/phy.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/phy/phy.c +2 -3
index 19c9eca..c35b2e7 100644
@@ -45,12 +45,11 @@
 void phy_print_status(struct phy_device *phydev)
 {
 	if (phydev->link) {
-		pr_info("%s - Link is Up - %d/%s\n",
-			dev_name(&phydev->dev),
+		netdev_info(phydev->attached_dev, "Link is Up - %d/%s\n",
 			phydev->speed,
 			DUPLEX_FULL == phydev->duplex ? "Full" : "Half");
 	} else	{
-		pr_info("%s - Link is Down\n", dev_name(&phydev->dev));
+		netdev_info(phydev->attached_dev, "Link is Down\n");
 	}
 }
 EXPORT_SYMBOL(phy_print_status);
Signature · 1 line
1.8.3.2
maintainer
#2 lore raw

Re: [PATCH 01/10] net: phy: use network device in phy_print_status

Series applied, but this patch series had several problems which I want you absolutely to correct in future submissions.

First of all, when you submit more than one patch at a time, you must provide a leading "PATCH 00/NN" posting which gives a top-level, detailed, description of the overall nature of the changes you are submitting.

It also gives me a single, specific, posting to reply to when I reply the whole series. Otherwise I have only two options, 1) pick an arbitrary patch to reply to (which I am doing right now) or 2) reply to every single patch (which is a serious waste of everyone's time).

Furthermore, some of your patches added empty lines to the end of files. I corrected this by hand, but please avoid this in the future.

Thank you.

#3 lore raw

Re: [PATCH 01/10] net: phy: use network device in phy_print_status

2014-02-12 16:13 GMT-08:00 David Miller <[email protected]>:

Quoted 8 lines

Series applied, but this patch series had several problems which I want you absolutely to correct in future submissions.

First of all, when you submit more than one patch at a time, you must provide a leading "PATCH 00/NN" posting which gives a top-level, detailed, description of the overall nature of the changes you are submitting.

Weird, did not you receive this cover-letter:
http://permalink.gmane.org/gmane.linux.network/303496
if not, that probably explains why the threading was all messed up in your inbox.

Quoted 8 lines

It also gives me a single, specific, posting to reply to when I reply the whole series. Otherwise I have only two options, 1) pick an arbitrary patch to reply to (which I am doing right now) or 2) reply to every single patch (which is a serious waste of everyone's time).

Furthermore, some of your patches added empty lines to the end of files. I corrected this by hand, but please avoid this in the future.

Thanks!

Quoted 3 lines

Thank you.

Signature · 1 line
Florian
maintainer
#4 lore raw

Re: [PATCH 01/10] net: phy: use network device in phy_print_status

From: Florian Fainelli <[email protected]>
Date: Wed, 12 Feb 2014 16:20:19 -0800

Quoted 10 lines

2014-02-12 16:13 GMT-08:00 David Miller <[email protected]>:

Quoted 8 lines

Series applied, but this patch series had several problems which I want you absolutely to correct in future submissions.

First of all, when you submit more than one patch at a time, you must provide a leading "PATCH 00/NN" posting which gives a top-level, detailed, description of the overall nature of the changes you are submitting.

Quoted 4 lines

Weird, did not you receive this cover-letter:
http://permalink.gmane.org/gmane.linux.network/303496
if not, that probably explains why the threading was all messed up in your inbox.

Weird indeed, I'll watch out for this in the future.

#5 lore raw

PATCH 2/10 net: phy: update phy_print_status to show pause settings

In reply to Florian Fainelli

Update phy_print_status() to also display the PHY device pause settings (rx/tx or off).

---
 drivers/net/phy/phy.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +4 -2
index c35b2e7..8ae2260 100644
@@ -45,9 +45,11 @@
 void phy_print_status(struct phy_device *phydev)
 {
 	if (phydev->link) {
-		netdev_info(phydev->attached_dev, "Link is Up - %d/%s\n",
+		netdev_info(phydev->attached_dev,
+			"Link is Up - %d/%s - flow control %s\n",
 			phydev->speed,
-			DUPLEX_FULL == phydev->duplex ? "Full" : "Half");
+			DUPLEX_FULL == phydev->duplex ? "Full" : "Half",
+			phydev->pause ? "rx/tx" : "off");
 	} else	{
 		netdev_info(phydev->attached_dev, "Link is Down\n");
 	}
Signature · 1 line
1.8.3.2
#6 lore raw

PATCH 3/10 net: phy: display human readable PHY speed settings

In reply to Florian Fainelli

Use a convenience function: phy_speed_to_str() which will display human readable speeds.

---
 drivers/net/phy/phy.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +22 -2
index 8ae2260..36fc6e1 100644
@@ -38,6 +38,26 @@
 
 #include <asm/irq.h>
 
+static const char *phy_speed_to_str(int speed)
+{
+	switch (speed) {
+	case SPEED_10:
+		return "10Mbps";
+	case SPEED_100:
+		return "100Mbps";
+	case SPEED_1000:
+		return "1Gbps";
+	case SPEED_2500:
+		return "2.5Gbps";
+	case SPEED_10000:
+		return "10Gbps";
+	case SPEED_UNKNOWN:
+		return "Unknown";
+	default:
+		return "Unsupported (update phy.c)";
+	}
+}
+
 /**
  * phy_print_status - Convenience function to print out the current phy status
  * @phydev: the phy_device struct
@@ -46,8 +66,8 @@ void phy_print_status(struct phy_device *phydev)
 {
 	if (phydev->link) {
 		netdev_info(phydev->attached_dev,
-			"Link is Up - %d/%s - flow control %s\n",
-			phydev->speed,
+			"Link is Up - %s/%s - flow control %s\n",
+			phy_speed_to_str(phydev->speed),
 			DUPLEX_FULL == phydev->duplex ? "Full" : "Half",
 			phydev->pause ? "rx/tx" : "off");
 	} else	{
Signature · 1 line
1.8.3.2
#7 lore raw

PATCH 4/10 net: phy: add genphy_aneg_done()

In reply to Florian Fainelli

In preparation for allowing PHY drivers to potentially override their auto-negotiation done callback, move the contents of phy_aneg_done() to genphy_aneg_done() since that function really is the generic implementation based on the BMSR_ANEGCOMPLETE status.

---
 drivers/net/phy/phy.c        |  4 +---
 drivers/net/phy/phy_device.c | 16 ++++++++++++++++
 include/linux/phy.h          |  1 +
 3 files changed, 18 insertions(+), 3 deletions(-)
drivers/net/phy/phy.c +1 -3
index 36fc6e1..db9c543 100644
@@ -120,9 +120,7 @@ static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
  */
 static inline int phy_aneg_done(struct phy_device *phydev)
 {
-	int retval = phy_read(phydev, MII_BMSR);
-
-	return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE);
+	return genphy_aneg_done(phydev);
 }
 
 /* A structure for mapping a particular speed and duplex
drivers/net/phy/phy_device.c +16 -0
index 82514e7..4e7db72 100644
@@ -865,6 +865,22 @@ int genphy_config_aneg(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_config_aneg);
 
+/**
+ * genphy_aneg_done - return auto-negotiation status
+ * @phydev: target phy_device struct
+ *
+ * Description: Reads the status register and returns 0 either if
+ *   auto-negotiation is incomplete, or if there was an error.
+ *   Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
+ */
+int genphy_aneg_done(struct phy_device *phydev)
+{
+	int retval = phy_read(phydev, MII_BMSR);
+
+	return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE);
+}
+EXPORT_SYMBOL(genphy_aneg_done);
+
 static int gen10g_config_aneg(struct phy_device *phydev)
 {
 	return 0;
include/linux/phy.h +1 -0
index 565188c..c572842 100644
@@ -612,6 +612,7 @@ static inline int phy_read_status(struct phy_device *phydev)
 int genphy_setup_forced(struct phy_device *phydev);
 int genphy_restart_aneg(struct phy_device *phydev);
 int genphy_config_aneg(struct phy_device *phydev);
+int genphy_aneg_done(struct phy_device *phydev);
 int genphy_update_link(struct phy_device *phydev);
 int genphy_read_status(struct phy_device *phydev);
 int genphy_suspend(struct phy_device *phydev);
Signature · 1 line
1.8.3.2
#8 lore raw

Re: [PATCH 04/10] net: phy: add genphy_aneg_done()

Hello.

Quoted 6 lines · Florian Fainelli

In preparation for allowing PHY drivers to potentially override their auto-negotiation done callback, move the contents of phy_aneg_done() to genphy_aneg_done() since that function really is the generic implementation based on the BMSR_ANEGCOMPLETE status.

[...]

Quoted 11 lines
drivers/net/phy/phy_device.c +3 -0
index 82514e7..4e7db72 100644
@@ -865,6 +865,22 @@ int genphy_config_aneg(struct phy_device *phydev)
  }
  EXPORT_SYMBOL(genphy_config_aneg);
 
+/**
+ * genphy_aneg_done - return auto-negotiation status
+ * @phydev: target phy_device struct

drivers/net/phy/phy_device.c int genphy_config_aneg(struct phy_device *phydev) · line 880

Quoted 10 lines
drivers/net/phy/phy_device.c +10 -0
+ *
+ * Description: Reads the status register and returns 0 either if
+ *   auto-negotiation is incomplete, or if there was an error.
+ *   Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
+ */
+int genphy_aneg_done(struct phy_device *phydev)
+{
+	int retval = phy_read(phydev, MII_BMSR);
+
+	return (retval < 0) ? retval : (retval & BMSR_ANEGCOMPLETE);

I doubt parens are needed here.

WBR, Sergei

#9 lore raw

PATCH 5/10 net: phy: allow driver to implement their own aneg_done

In reply to Florian Fainelli

Some PHYs out there can be very quirky with respect to how they would report the auto-negotiation is completed. Allow drivers to override the generic aneg_done() implementation by providing their own.

Since not all drivers have been updated yet to use genphy_aneg_done() as aneg_done() callback, we explicitely check that this callback is valid before calling into it.

---
 drivers/net/phy/phy.c        | 9 ++++++---
 drivers/net/phy/phy_device.c | 1 +
 include/linux/phy.h          | 3 +++
 3 files changed, 10 insertions(+), 3 deletions(-)
drivers/net/phy/phy.c +6 -3
index db9c543..2fa4611 100644
@@ -114,12 +114,15 @@ static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
  * phy_aneg_done - return auto-negotiation status
  * @phydev: target phy_device struct
  *
- * Description: Reads the status register and returns 0 either if
- *   auto-negotiation is incomplete, or if there was an error.
- *   Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
+ * Description: Return the auto-negotiation status from this @phydev
+ * Returns > 0 on success or < 0 on error. 0 means that auto-negotiation
+ * is still pending.
  */
 static inline int phy_aneg_done(struct phy_device *phydev)
 {
+	if (phydev->drv->aneg_done)
+		return phydev->drv->aneg_done(phydev);
+
 	return genphy_aneg_done(phydev);
 }
 
drivers/net/phy/phy_device.c +1 -0
index 4e7db72..7c18420 100644
@@ -1267,6 +1267,7 @@ static struct phy_driver genphy_driver[] = {
 	.config_init	= genphy_config_init,
 	.features	= 0,
 	.config_aneg	= genphy_config_aneg,
+	.aneg_done	= genphy_aneg_done,
 	.read_status	= genphy_read_status,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
include/linux/phy.h +3 -0
index c572842..eede657 100644
@@ -417,6 +417,9 @@ struct phy_driver {
 	 */
 	int (*config_aneg)(struct phy_device *phydev);
 
+	/* Determines the auto negotiation result */
+	int (*aneg_done)(struct phy_device *phydev);
+
 	/* Determines the negotiated speed and duplex */
 	int (*read_status)(struct phy_device *phydev);
 
Signature · 1 line
1.8.3.2
#10 lore raw

PATCH 6/10 net: phy: fix phy_{clear,config}_interrupt comment typos

In reply to Florian Fainelli

The comments above phy_{clear,config}_interrupt used the word "on" instead of "or", when talking about the return values of the functions, fix these two typos.

---
 drivers/net/phy/phy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/phy.c +2 -2
index 2fa4611..fc918b6 100644
@@ -83,7 +83,7 @@ EXPORT_SYMBOL(phy_print_status);
  * If the @phydev driver has an ack_interrupt function, call it to
  * ack and clear the phy device's interrupt.
  *
- * Returns 0 on success on < 0 on error.
+ * Returns 0 on success or < 0 on error.
  */
 static int phy_clear_interrupt(struct phy_device *phydev)
 {
@@ -98,7 +98,7 @@ static int phy_clear_interrupt(struct phy_device *phydev)
  * @phydev: the phy_device struct
  * @interrupts: interrupt flags to configure for this @phydev
  *
- * Returns 0 on success on < 0 on error.
+ * Returns 0 on success or < 0 on error.
  */
 static int phy_config_interrupt(struct phy_device *phydev, u32 interrupts)
 {
Signature · 1 line
1.8.3.2
#11 lore raw

PATCH 7/10 net: phy: re-design phy_modes to be self-contained

In reply to Florian Fainelli

of_get_phy_mode() uses a local array to map phy_interface_t values from include/linux/net/phy.h to a string which is read from the 'phy-mode' or 'phy-connection-type' property. In preparation for exposing the PHY interface mode through sysfs, perform the following:

- mode phy_modes from drivers/of/of_net.c to include/linux/phy.h such that it is right below the phy_interface_t enum
- make it a static inline function returning the string such that we can use it by just including include/linux/net/phy.h
- add a PHY_INTERFACE_MODE_MAX enum value to guard the iteration in of_get_phy_mode()

---
 drivers/of/of_net.c | 26 ++------------------------
 include/linux/phy.h | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 24 deletions(-)
drivers/of/of_net.c +2 -24
index a208a45..84215c1 100644
@@ -12,28 +12,6 @@
 #include <linux/export.h>
 
 /**
- * It maps 'enum phy_interface_t' found in include/linux/phy.h
- * into the device tree binding of 'phy-mode', so that Ethernet
- * device driver can get phy interface from device tree.
- */
-static const char *phy_modes[] = {
-	[PHY_INTERFACE_MODE_NA]		= "",
-	[PHY_INTERFACE_MODE_MII]	= "mii",
-	[PHY_INTERFACE_MODE_GMII]	= "gmii",
-	[PHY_INTERFACE_MODE_SGMII]	= "sgmii",
-	[PHY_INTERFACE_MODE_TBI]	= "tbi",
-	[PHY_INTERFACE_MODE_REVMII]	= "rev-mii",
-	[PHY_INTERFACE_MODE_RMII]	= "rmii",
-	[PHY_INTERFACE_MODE_RGMII]	= "rgmii",
-	[PHY_INTERFACE_MODE_RGMII_ID]	= "rgmii-id",
-	[PHY_INTERFACE_MODE_RGMII_RXID]	= "rgmii-rxid",
-	[PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid",
-	[PHY_INTERFACE_MODE_RTBI]	= "rtbi",
-	[PHY_INTERFACE_MODE_SMII]	= "smii",
-	[PHY_INTERFACE_MODE_XGMII]	= "xgmii",
-};
-
-/**
  * of_get_phy_mode - Get phy mode for given device_node
  * @np:	Pointer to the given device_node
  *
@@ -49,8 +27,8 @@ int of_get_phy_mode(struct device_node *np)
 	if (err < 0)
 		return err;
 
-	for (i = 0; i < ARRAY_SIZE(phy_modes); i++)
-		if (!strcasecmp(pm, phy_modes[i]))
+	for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++)
+		if (!strcasecmp(pm, phy_modes(i)))
 			return i;
 
 	return -ENODEV;
include/linux/phy.h +42 -0

50 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#12 lore raw

PATCH 8/10 net: phy: expose PHY device interface mode

In reply to Florian Fainelli

Expose the PHY device interface mode through sysfs since this is an useful piece of information for knowing how the attached networking device will have configured its transmit/receive path.

---
 Documentation/ABI/testing/sysfs-bus-mdio | 10 ++++++++++
 drivers/net/phy/mdio_bus.c               | 10 ++++++++++
 2 files changed, 20 insertions(+)
Documentation/ABI/testing/sysfs-bus-mdio +10 -0
index 6349749..2133afd 100644
@@ -7,3 +7,13 @@ Description:
 		by the device during bus enumeration, encoded in hexadecimal.
 		This ID is used to match the device with the appropriate
 		driver.
+
+What:		/sys/bus/mdio_bus/devices/.../phy_interface
+Date:		February 2014
+KernelVersion:	3.15
+Contact:	[email protected]
+Description:
+		This attribute contains the PHY interface as configured by the
+		Ethernet driver during bus enumeration, encoded in string.
+		This interface mode is used to configure the Ethernet MAC with the
+		appropriate mode for its data lines to the PHY hardware.
drivers/net/phy/mdio_bus.c +10 -0
index 71e4900..7c66ea0 100644
@@ -432,8 +432,18 @@ phy_id_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR_RO(phy_id);
 
+static ssize_t
+phy_interface_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct phy_device *phydev = to_phy_device(dev);
+
+	return sprintf(buf, "%s\n", phy_modes(phydev->interface));
+}
+static DEVICE_ATTR_RO(phy_interface);
+
 static struct attribute *mdio_dev_attrs[] = {
 	&dev_attr_phy_id.attr,
+	&dev_attr_phy_interface.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(mdio_dev);
Signature · 1 line
1.8.3.2
#13 lore raw

PATCH 9/10 net: phy: add "has_fixups" boolean property

In reply to Florian Fainelli

Add a boolean property which indicates if the PHY has had any fixup routine ran on it. We are later going to use that boolean to expose it as a sysfs property to help troubleshooting.

---
 drivers/net/phy/phy_device.c | 1 +
 include/linux/phy.h          | 1 +
 2 files changed, 2 insertions(+)
drivers/net/phy/phy_device.c +1 -0
index 7c18420..c2d778d 100644
@@ -139,6 +139,7 @@ static int phy_scan_fixups(struct phy_device *phydev)
 				mutex_unlock(&phy_fixup_lock);
 				return err;
 			}
+			phydev->has_fixups = true;
 		}
 	}
 	mutex_unlock(&phy_fixup_lock);
include/linux/phy.h +1 -0
index ef7fa11..42f1bc7 100644
@@ -350,6 +350,7 @@ struct phy_device {
 	struct phy_c45_device_ids c45_ids;
 	bool is_c45;
 	bool is_internal;
+	bool has_fixups;
 
 	enum phy_state state;
 
Signature · 1 line
1.8.3.2
#14 lore raw

PATCH 10/10 net: phy: expose phydev->has_fixups to sysfs

In reply to Florian Fainelli

Expose the PHY device has_fixups boolean as a sysfs property to help troubleshooting PHY configurations.

---
 Documentation/ABI/testing/sysfs-bus-mdio | 11 +++++++++++
 drivers/net/phy/mdio_bus.c               | 10 ++++++++++
 2 files changed, 21 insertions(+)
Documentation/ABI/testing/sysfs-bus-mdio +11 -0
index 2133afd..fcab995 100644
@@ -17,3 +17,14 @@ Description:
 		Ethernet driver during bus enumeration, encoded in string.
 		This interface mode is used to configure the Ethernet MAC with the
 		appropriate mode for its data lines to the PHY hardware.
+
+What:		/sys/bus/mdio_bus/devices/.../phy_has_fixups
+Date:		February 2014
+KernelVersion:	3.15
+Contact:	[email protected]
+Description:
+		This attribute contains the boolean value whether a given PHY
+		device has had any "fixup" workaround running on it, encoded as
+		a boolean. This information is provided to help troubleshooting
+		PHY configurations.
+
drivers/net/phy/mdio_bus.c +10 -0
index 7c66ea0..76f54b3 100644
@@ -441,9 +441,19 @@ phy_interface_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR_RO(phy_interface);
 
+static ssize_t
+phy_has_fixups_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct phy_device *phydev = to_phy_device(dev);
+
+	return sprintf(buf, "%d\n", phydev->has_fixups);
+}
+static DEVICE_ATTR_RO(phy_has_fixups);
+
 static struct attribute *mdio_dev_attrs[] = {
 	&dev_attr_phy_id.attr,
 	&dev_attr_phy_interface.attr,
+	&dev_attr_phy_has_fixups.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(mdio_dev);
Signature · 1 line
1.8.3.2