diff mbox series

[v1,1/1] net: usb: asix: ax88772: manage PHY PM from MAC

Message ID 20210610142009.16162-1-o.rempel@pengutronix.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [v1,1/1] net: usb: asix: ax88772: manage PHY PM from MAC | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers fail 1 blamed authors not CCed: linux@rempel-privat.de; 3 maintainers not CCed: linux@rempel-privat.de colin.king@canonical.com oneukum@suse.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 84 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Oleksij Rempel June 10, 2021, 2:20 p.m. UTC
Take over PHY power management, otherwise PHY framework will try to
access ASIX MDIO bus before MAC resume was completed.

Fixes: e532a096be0e ("net: usb: asix: ax88772: add phylib support")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reported-by: Jon Hunter <jonathanh@nvidia.com>
Suggested-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/usb/asix_devices.c | 43 ++++++++++------------------------
 1 file changed, 12 insertions(+), 31 deletions(-)

Comments

Jon Hunter June 10, 2021, 4:08 p.m. UTC | #1
On 10/06/2021 15:20, Oleksij Rempel wrote:
> Take over PHY power management, otherwise PHY framework will try to
> access ASIX MDIO bus before MAC resume was completed.
> 
> Fixes: e532a096be0e ("net: usb: asix: ax88772: add phylib support")
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Reported-by: Jon Hunter <jonathanh@nvidia.com>
> Suggested-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/usb/asix_devices.c | 43 ++++++++++------------------------
>  1 file changed, 12 insertions(+), 31 deletions(-)


Thanks! Works for me ...

Tested-by: Jon Hunter <jonathanh@nvidia.com>

Cheers
Jon
Marek Szyprowski June 10, 2021, 10:22 p.m. UTC | #2
Hi Oleksij,

On 10.06.2021 16:20, Oleksij Rempel wrote:
> Take over PHY power management, otherwise PHY framework will try to
> access ASIX MDIO bus before MAC resume was completed.
>
> Fixes: e532a096be0e ("net: usb: asix: ax88772: add phylib support")
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Reported-by: Jon Hunter <jonathanh@nvidia.com>
> Suggested-by: Heiner Kallweit <hkallweit1@gmail.com>

This fixes the issues observed on my test systems. Thanks!

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
>   drivers/net/usb/asix_devices.c | 43 ++++++++++------------------------
>   1 file changed, 12 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
> index 8a477171e8f5..aec97b021a73 100644
> --- a/drivers/net/usb/asix_devices.c
> +++ b/drivers/net/usb/asix_devices.c
> @@ -598,6 +598,9 @@ static void ax88772_suspend(struct usbnet *dev)
>   	struct asix_common_private *priv = dev->driver_priv;
>   	u16 medium;
>   
> +	if (netif_running(dev->net))
> +		phy_stop(priv->phydev);
> +
>   	/* Stop MAC operation */
>   	medium = asix_read_medium_status(dev, 1);
>   	medium &= ~AX_MEDIUM_RE;
> @@ -605,14 +608,6 @@ static void ax88772_suspend(struct usbnet *dev)
>   
>   	netdev_dbg(dev->net, "ax88772_suspend: medium=0x%04x\n",
>   		   asix_read_medium_status(dev, 1));
> -
> -	/* Preserve BMCR for restoring */
> -	priv->presvd_phy_bmcr =
> -		asix_mdio_read_nopm(dev->net, dev->mii.phy_id, MII_BMCR);
> -
> -	/* Preserve ANAR for restoring */
> -	priv->presvd_phy_advertise =
> -		asix_mdio_read_nopm(dev->net, dev->mii.phy_id, MII_ADVERTISE);
>   }
>   
>   static int asix_suspend(struct usb_interface *intf, pm_message_t message)
> @@ -626,39 +621,22 @@ static int asix_suspend(struct usb_interface *intf, pm_message_t message)
>   	return usbnet_suspend(intf, message);
>   }
>   
> -static void ax88772_restore_phy(struct usbnet *dev)
> -{
> -	struct asix_common_private *priv = dev->driver_priv;
> -
> -	if (priv->presvd_phy_advertise) {
> -		/* Restore Advertisement control reg */
> -		asix_mdio_write_nopm(dev->net, dev->mii.phy_id, MII_ADVERTISE,
> -				     priv->presvd_phy_advertise);
> -
> -		/* Restore BMCR */
> -		if (priv->presvd_phy_bmcr & BMCR_ANENABLE)
> -			priv->presvd_phy_bmcr |= BMCR_ANRESTART;
> -
> -		asix_mdio_write_nopm(dev->net, dev->mii.phy_id, MII_BMCR,
> -				     priv->presvd_phy_bmcr);
> -
> -		priv->presvd_phy_advertise = 0;
> -		priv->presvd_phy_bmcr = 0;
> -	}
> -}
> -
>   static void ax88772_resume(struct usbnet *dev)
>   {
> +	struct asix_common_private *priv = dev->driver_priv;
>   	int i;
>   
>   	for (i = 0; i < 3; i++)
>   		if (!ax88772_hw_reset(dev, 1))
>   			break;
> -	ax88772_restore_phy(dev);
> +
> +	if (netif_running(dev->net))
> +		phy_start(priv->phydev);
>   }
>   
>   static void ax88772a_resume(struct usbnet *dev)
>   {
> +	struct asix_common_private *priv = dev->driver_priv;
>   	int i;
>   
>   	for (i = 0; i < 3; i++) {
> @@ -666,7 +644,8 @@ static void ax88772a_resume(struct usbnet *dev)
>   			break;
>   	}
>   
> -	ax88772_restore_phy(dev);
> +	if (netif_running(dev->net))
> +		phy_start(priv->phydev);
>   }
>   
>   static int asix_resume(struct usb_interface *intf)
> @@ -722,6 +701,8 @@ static int ax88772_init_phy(struct usbnet *dev)
>   		return ret;
>   	}
>   
> +	priv->phydev->mac_managed_pm = 1;
> +
>   	phy_attached_info(priv->phydev);
>   
>   	return 0;

Best regards
diff mbox series

Patch

diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 8a477171e8f5..aec97b021a73 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -598,6 +598,9 @@  static void ax88772_suspend(struct usbnet *dev)
 	struct asix_common_private *priv = dev->driver_priv;
 	u16 medium;
 
+	if (netif_running(dev->net))
+		phy_stop(priv->phydev);
+
 	/* Stop MAC operation */
 	medium = asix_read_medium_status(dev, 1);
 	medium &= ~AX_MEDIUM_RE;
@@ -605,14 +608,6 @@  static void ax88772_suspend(struct usbnet *dev)
 
 	netdev_dbg(dev->net, "ax88772_suspend: medium=0x%04x\n",
 		   asix_read_medium_status(dev, 1));
-
-	/* Preserve BMCR for restoring */
-	priv->presvd_phy_bmcr =
-		asix_mdio_read_nopm(dev->net, dev->mii.phy_id, MII_BMCR);
-
-	/* Preserve ANAR for restoring */
-	priv->presvd_phy_advertise =
-		asix_mdio_read_nopm(dev->net, dev->mii.phy_id, MII_ADVERTISE);
 }
 
 static int asix_suspend(struct usb_interface *intf, pm_message_t message)
@@ -626,39 +621,22 @@  static int asix_suspend(struct usb_interface *intf, pm_message_t message)
 	return usbnet_suspend(intf, message);
 }
 
-static void ax88772_restore_phy(struct usbnet *dev)
-{
-	struct asix_common_private *priv = dev->driver_priv;
-
-	if (priv->presvd_phy_advertise) {
-		/* Restore Advertisement control reg */
-		asix_mdio_write_nopm(dev->net, dev->mii.phy_id, MII_ADVERTISE,
-				     priv->presvd_phy_advertise);
-
-		/* Restore BMCR */
-		if (priv->presvd_phy_bmcr & BMCR_ANENABLE)
-			priv->presvd_phy_bmcr |= BMCR_ANRESTART;
-
-		asix_mdio_write_nopm(dev->net, dev->mii.phy_id, MII_BMCR,
-				     priv->presvd_phy_bmcr);
-
-		priv->presvd_phy_advertise = 0;
-		priv->presvd_phy_bmcr = 0;
-	}
-}
-
 static void ax88772_resume(struct usbnet *dev)
 {
+	struct asix_common_private *priv = dev->driver_priv;
 	int i;
 
 	for (i = 0; i < 3; i++)
 		if (!ax88772_hw_reset(dev, 1))
 			break;
-	ax88772_restore_phy(dev);
+
+	if (netif_running(dev->net))
+		phy_start(priv->phydev);
 }
 
 static void ax88772a_resume(struct usbnet *dev)
 {
+	struct asix_common_private *priv = dev->driver_priv;
 	int i;
 
 	for (i = 0; i < 3; i++) {
@@ -666,7 +644,8 @@  static void ax88772a_resume(struct usbnet *dev)
 			break;
 	}
 
-	ax88772_restore_phy(dev);
+	if (netif_running(dev->net))
+		phy_start(priv->phydev);
 }
 
 static int asix_resume(struct usb_interface *intf)
@@ -722,6 +701,8 @@  static int ax88772_init_phy(struct usbnet *dev)
 		return ret;
 	}
 
+	priv->phydev->mac_managed_pm = 1;
+
 	phy_attached_info(priv->phydev);
 
 	return 0;