Skip to contentSkip to conversation

net: phy: improve generic clause 45 aneg configuration

PATCH In review Heiner Kallweit 2 participants 6 messages Feb 18, 2019 – Feb 21, 2019

Subsystems (4)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

cover net: phy: improve generic clause 45 aneg configuration

Improve generic clause 45 aneg configuration.

Heiner Kallweit (4):
net: phy: export genphy_config_eee_advert
net: phy: use genphy_config_eee_advert in genphy_c45_an_config_aneg
net: phy: add genphy_c45_check_and_restart_aneg
net: phy: marvell10g: use genphy_c45_check_and_restart_aneg in

    mv3310_config_aneg
 drivers/net/phy/marvell10g.c | 15 +--------------
 drivers/net/phy/phy-c45.c    | 34 +++++++++++++++++++++++++++++++++-
 drivers/net/phy/phy_device.c |  3 ++-
 include/linux/phy.h          |  2 ++
 4 files changed, 38 insertions(+), 16 deletions(-)
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 1/4 net: phy: export genphy_config_eee_advert

We want to use this function in phy-c45.c too, therefore export it.

---
 drivers/net/phy/phy_device.c | 3 ++-
 include/linux/phy.h          | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/net/phy/phy_device.c +2 -1
index 4bb3b6c28..49fdd1ee7 100644
@@ -1575,7 +1575,7 @@ static int genphy_config_advert(struct phy_device *phydev)
  *   efficent ethernet modes. Returns 0 if the PHY's advertisement hasn't
  *   changed, and 1 if it has changed.
  */
-static int genphy_config_eee_advert(struct phy_device *phydev)
+int genphy_config_eee_advert(struct phy_device *phydev)
 {
 	int err;
 
@@ -1588,6 +1588,7 @@ static int genphy_config_eee_advert(struct phy_device *phydev)
 	/* If the call failed, we assume that EEE is not supported */
 	return err < 0 ? 0 : err;
 }
+EXPORT_SYMBOL(genphy_config_eee_advert);
 
 /**
  * genphy_setup_forced - configures/forces speed/duplex from @phydev
include/linux/phy.h +1 -0
index 3db507e68..761131de4 100644
@@ -1077,6 +1077,7 @@ void phy_attached_info(struct phy_device *phydev);
 int genphy_config_init(struct phy_device *phydev);
 int genphy_setup_forced(struct phy_device *phydev);
 int genphy_restart_aneg(struct phy_device *phydev);
+int genphy_config_eee_advert(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);
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

PATCH 2/4 net: phy: use genphy_config_eee_advert in genphy_c45_an_config_aneg

In reply to Heiner Kallweit

Like in genphy_config_aneg() for clause 22 PHY's, we should keep modes from being advertised that are known to be broken with EEE.

---
 drivers/net/phy/phy-c45.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/phy/phy-c45.c +3 -1
index 16636d49b..2f5721430 100644
@@ -89,12 +89,14 @@ EXPORT_SYMBOL_GPL(genphy_c45_pma_setup_forced);
  */
 int genphy_c45_an_config_aneg(struct phy_device *phydev)
 {
-	int changed = 0, ret;
+	int changed, ret;
 	u32 adv;
 
 	linkmode_and(phydev->advertising, phydev->advertising,
 		     phydev->supported);
 
+	changed = genphy_config_eee_advert(phydev);
+
 	adv = linkmode_adv_to_mii_adv_t(phydev->advertising);
 
 	ret = phy_modify_mmd(phydev, MDIO_MMD_AN, MDIO_AN_ADVERTISE,
Signature · 1 line
2.20.1
author maintainer
#3 lore raw

PATCH 3/4 net: phy: add genphy_c45_check_and_restart_aneg

In reply to Heiner Kallweit

This function will be used by config_aneg callback implementations of PHY drivers and allows to reduce boilerplate code.

---
 drivers/net/phy/phy-c45.c | 30 ++++++++++++++++++++++++++++++
 include/linux/phy.h       |  1 +
 2 files changed, 31 insertions(+)
drivers/net/phy/phy-c45.c +30 -0
index 2f5721430..fc3173cc0 100644
@@ -156,6 +156,36 @@ int genphy_c45_restart_aneg(struct phy_device *phydev)
 }
 EXPORT_SYMBOL_GPL(genphy_c45_restart_aneg);
 
+/**
+ * genphy_c45_check_and_restart_aneg - Enable and restart auto-negotiation
+ * @phydev: target phy_device struct
+ * @restart: whether aneg restart is requested
+ *
+ * This assumes that the auto-negotiation MMD is present.
+ *
+ * Check, and restart auto-negotiation if needed.
+ */
+int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart)
+{
+	int ret = 0;
+
+	if (!restart) {
+		/* Configure and restart aneg if it wasn't set before */
+		ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1);
+		if (ret < 0)
+			return ret;
+
+		if (!(ret & MDIO_AN_CTRL1_ENABLE))
+			restart = true;
+	}
+
+	if (restart)
+		ret = genphy_c45_restart_aneg(phydev);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(genphy_c45_check_and_restart_aneg);
+
 /**
  * genphy_c45_aneg_done - return auto-negotiation complete status
  * @phydev: target phy_device struct
include/linux/phy.h +1 -0
index 761131de4..8e9fc5764 100644
@@ -1097,6 +1097,7 @@ int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum,
 
 /* Clause 45 PHY */
 int genphy_c45_restart_aneg(struct phy_device *phydev);
+int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart);
 int genphy_c45_aneg_done(struct phy_device *phydev);
 int genphy_c45_read_link(struct phy_device *phydev);
 int genphy_c45_read_lpa(struct phy_device *phydev);
Signature · 1 line
2.20.1
author maintainer
#4 lore raw

PATCH 4/4 net: phy: marvell10g: use genphy_c45_check_and_restart_aneg in mv3310_config_aneg

In reply to Heiner Kallweit

Use new function genphy_c45_check_and_restart_aneg() to reduce boilerplate code.

---
 drivers/net/phy/marvell10g.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/net/phy/marvell10g.c +1 -14
index 67066127b..8cbf35964 100644
@@ -291,20 +291,7 @@ static int mv3310_config_aneg(struct phy_device *phydev)
 	if (ret > 0)
 		changed = true;
 
-	if (!changed) {
-		/* Configure and restart aneg if it wasn't set before */
-		ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1);
-		if (ret < 0)
-			return ret;
-
-		if (!(ret & MDIO_AN_CTRL1_ENABLE))
-			changed = 1;
-	}
-
-	if (changed)
-		ret = genphy_c45_restart_aneg(phydev);
-
-	return ret;
+	return genphy_c45_check_and_restart_aneg(phydev, changed);
 }
 
 static int mv3310_aneg_done(struct phy_device *phydev)
Signature · 1 line
2.20.1