Patchwork [12/19] usbnet: smsc95xx: Replace ad-hoc PHY functions with generic ones

login
register
mail settings
Submitter Marek Vasut
Date Jan. 3, 2019, 1:10 a.m.
Message ID <20190103011040.25974-13-marex@denx.de>
Download mbox | patch
Permalink /patch/691887/
State New
Headers show

Comments

Marek Vasut - Jan. 3, 2019, 1:10 a.m.
Replace the ad-hoc reimplementation of genphy_soft_reset() and
genphy_config_aneg() with the generic functions.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: David S. Miller <davem@davemloft.net>
Cc: Nisar Sayed <Nisar.Sayed@microchip.com>
Cc: Woojung Huh <Woojung.Huh@microchip.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: linux-usb@vger.kernel.org
To: netdev@vger.kernel.org
---
 drivers/net/usb/smsc95xx.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)
Andrew Lunn - Jan. 3, 2019, 1:28 p.m.
On Thu, Jan 03, 2019 at 02:10:33AM +0100, Marek Vasut wrote:
> Replace the ad-hoc reimplementation of genphy_soft_reset() and
> genphy_config_aneg() with the generic functions.

phylib will either call the phy driver specific reset function, or
genphy_soft_reset. The same is also true for configuring
auto-neg. Please just kill this code and leave the PHY driver to do
its job.

	  Andrew
Marek Vasut - Jan. 4, 2019, 2:19 a.m.
On 1/3/19 2:28 PM, Andrew Lunn wrote:
> On Thu, Jan 03, 2019 at 02:10:33AM +0100, Marek Vasut wrote:
>> Replace the ad-hoc reimplementation of genphy_soft_reset() and
>> genphy_config_aneg() with the generic functions.
> 
> phylib will either call the phy driver specific reset function, or
> genphy_soft_reset. The same is also true for configuring
> auto-neg. Please just kill this code and leave the PHY driver to do
> its job.

In this patch or subsequent ? I think we should do that in a subsequent
patch, to keep this bisectable in case something breaks.

Patch

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index c1e59813c1fc..fa33eda61275 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -970,25 +970,16 @@  static void smsc95xx_adjust_link(struct net_device *netdev)
 static int smsc95xx_phy_initialize(struct usbnet *dev)
 {
 	struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
-	int bmcr, ret, timeout = 0;
+	int ret;
 
 	/* reset phy and wait for reset to complete */
-	phy_write(pdata->phydev, MII_BMCR, BMCR_RESET);
-
-	do {
-		msleep(10);
-		bmcr = phy_read(pdata->phydev, MII_BMCR);
-		timeout++;
-	} while ((bmcr & BMCR_RESET) && (timeout < 100));
-
-	if (timeout >= 100) {
-		netdev_warn(dev->net, "timeout on PHY Reset");
-		return -EIO;
-	}
+	ret = genphy_soft_reset(pdata->phydev);
+	if (ret)
+		return ret;
 
-	phy_write(pdata->phydev, MII_ADVERTISE,
-		ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP |
-		ADVERTISE_PAUSE_ASYM);
+	ret = genphy_config_aneg(pdata->phydev);
+	if (ret)
+		return ret;
 
 	/* read to clear */
 	ret = phy_read(pdata->phydev, PHY_INT_SRC);