Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp244090pxj; Thu, 10 Jun 2021 20:58:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyo5pBTXSFDqk0Z7zw+HvZnkuKepOuQZojP8D98OYc7Sr8HA4Byyg+FYgVTgwef+nBIyxC8 X-Received: by 2002:a17:906:c0da:: with SMTP id bn26mr1634152ejb.437.1623383914906; Thu, 10 Jun 2021 20:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623383914; cv=none; d=google.com; s=arc-20160816; b=VS84yFQ+4ZvwV1382vlkSNSrRl4u1Ks8aRdxodG0whbJ0+0/1EAeQq+TGytOMyLX1L ri8KD6KkCwl247jEecQNmZGglE1P9Dz09q6I1mEuJ54o0sopwO/fTw1qtGx7FunrEkzp UDfiD3Nc0t4lHyPB9VNbePNMNVa8ijczTzD/1A270B7FGwFsz8P0G+9YMtfuawvlCzPA iv1zf84Z1NYXdCVrX70u2V6DtLt49WGSwPFKOUabMXwLwc2XziXXG6uKdnw5AI3sfh4J zdeNVO+QAALotguBfztrRNFwEZe5puemja3JOAVMZ7yF+nZMaCXVnud+U6zejd4VmUhV 8ETA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=SjS3TArK189iCwlYA16kOXVCR9nx9R0Jn4ZOCdAZCzo=; b=fA64wlRSr74ts8jcL+4FGrX04KbpmXOOsv+Gg+S/RGzjDX1j2Gz0AMq514jqnDwfSf wB+3udu+YwV/4djaYPif/UqnSAu2tDB/FNQHxWOQNJ8r6jdBoiOr3Pdla13mDCRicHV+ HJzBidJUNJu/ptUZ+9K87MmcqH+BKkza2SjykPmuK05RooUR9Lqe/T5O+hjv5BRL59Vr efu5u+Jw22QEm/DS42VL6LWMivSNmwV2GgMW8y1oUiALX2w0iEH6WpHd/p9o2OpINghf EEX5g8kdQM/KHxJM+fljy05izbZWSGEuDg5/Knk8nZsAqCGtKnMQ09hPdsd9j0F3lmHP rTlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bq26si3747475ejb.251.2021.06.10.20.58.11; Thu, 10 Jun 2021 20:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231512AbhFKD6P (ORCPT + 99 others); Thu, 10 Jun 2021 23:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231309AbhFKD6O (ORCPT ); Thu, 10 Jun 2021 23:58:14 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B71FDC0617AD for ; Thu, 10 Jun 2021 20:56:17 -0700 (PDT) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lrYH6-0005B6-1C; Fri, 11 Jun 2021 05:56:04 +0200 Received: from ore by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lrYH3-0003Sc-4D; Fri, 11 Jun 2021 05:56:01 +0200 From: Oleksij Rempel To: "David S. Miller" , Jakub Kicinski , Andrew Lunn , Heiner Kallweit , Russell King Cc: Oleksij Rempel , Marek Szyprowski , Jon Hunter , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v2] net: usb: asix: ax88772: manage PHY PM from MAC Date: Fri, 11 Jun 2021 05:55:59 +0200 Message-Id: <20210611035559.13252-1-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reported-by: Marek Szyprowski Reported-by: Jon Hunter Suggested-by: Heiner Kallweit Tested-by: Jon Hunter Tested-by: Marek Szyprowski --- 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; -- 2.29.2