Message ID | 20231205234229.274601-1-justin.chen@broadcom.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3773928vqy; Tue, 5 Dec 2023 15:42:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHo3dqyTuXRN+hgjLom+DKurcdTGvdGfGJ2Eav49gDLvj1xgbIdQdgOFlpCZV63h3GAQ6CE X-Received: by 2002:a05:6a20:7493:b0:18b:9031:81a4 with SMTP id p19-20020a056a20749300b0018b903181a4mr4483823pzd.47.1701819765395; Tue, 05 Dec 2023 15:42:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701819765; cv=none; d=google.com; s=arc-20160816; b=vMHca3l68wcYIJWzNS65DTHTReGAIINxh8skSFalgZOjbbPNPC9Cs0Mq+srD7PEDdd +Y8ezkvRsQOeZAEjJG0KavBlV9h2kCrwjLvCm67I7lUyZdwhIUI0XUilqkU8KA8HGGXo zzc5CZnfdjplq2olv9tNG7CYZECL1Mv3+pfxUBgYuSgMGsLjRvOpEpHBOPq6aCC1N7st vs3PPNgJ8oChf8D+7g38ezItaP6wMXB+eJ75vH9EJQBs/rhloQ/GKQTaXUGDPDmOk/rt RNv1O+cFmSzUGhE+oVQvBlTeAqHeYn1uVB1LuV9x+0au4Rw5DAB+cDYYWr6q3Pc5+CDS DsCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=akB1uGbj4rlIB0fM+hP0bxXNCb6a5aMvzIZZnv03GXk=; fh=NjbKW5lZqgrCPsck0o+jT+H2Dfk4vZ5xoNvfGB2uLTM=; b=J+40HSZ6jPgn1r358SZauYHYl2A5j52M7wCnAM5/vYv68djlh6LacbJ6kclr2s6/Nf DNZTGhzL0Pcxhdzg6ef+YG94CBQpp7kv/QGIFxRlhyhwtw3+YBCUgfgrXWX0wOXArKJk TDv6yrtsGtsAz2+G2ieeme1YxrgSGzWaJsFwUet18gPg02U7OH65djdLjadabw62kv6n grOhM5pvIKcdy6qAowW1QeLzsf/d+FWat7j9i3ose+QCpS9KWluBBtLPo2bwyYSxekgx Smupi59qKjnhe7YqGVagz0AIFhM8/kRCpapFKxG0GrcgOZfP270ib1jOOYgJR6LzR/TX X14w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=JV2Uuy3s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id e9-20020a170902b78900b001b045d65aedsi8417698pls.228.2023.12.05.15.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 15:42:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=JV2Uuy3s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 85455804ADA8; Tue, 5 Dec 2023 15:42:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230410AbjLEXmb (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Tue, 5 Dec 2023 18:42:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbjLEXm3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 5 Dec 2023 18:42:29 -0500 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18968122 for <linux-kernel@vger.kernel.org>; Tue, 5 Dec 2023 15:42:36 -0800 (PST) Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-77f04969d2eso217533185a.1 for <linux-kernel@vger.kernel.org>; Tue, 05 Dec 2023 15:42:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1701819755; x=1702424555; darn=vger.kernel.org; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=akB1uGbj4rlIB0fM+hP0bxXNCb6a5aMvzIZZnv03GXk=; b=JV2Uuy3st1EWFlxXDsL3sErk65KjNDyQEo6IM6X9g6xuHZvcNsEqoL4awuqUQYx7bK mG8D6S+ZA155VQzVLIlHQ7x+ul9heOYSUrQiuUhRE2sTL2p7udfEl5os0mKJzxiskyp2 8bgidpfl5zpfFSpPMiIJGgHf7XROnKn+Tg0Mo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701819755; x=1702424555; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=akB1uGbj4rlIB0fM+hP0bxXNCb6a5aMvzIZZnv03GXk=; b=vFt3iaTZKeRFG9a26iLSw1XCWn//KEHGlCLAx4y69achuyMjZ3wYKYG1mzNqqA2wbL 9mjINPDGyQh/j7nyOimKXH0N4D8/VeQdr73mkvWe/IOj45fgl72EDGmxsuveExOXsCfb Qg78DJJQbOa40U+LQlregsg/cttHHKuTxweXHV9pdh582JFow1EWwrvcB08bw45t6DTa CxI5jch/GhmjwrGRlt6Uv8UJOhB8YTuIZ4A7R1zSxMkTsnZX3Gp1be5DHKGgy36cqHDm BQ6DhmPz0y0HDsRtcwblzKOPRBvU7N/F6c/XV0drsXS/4uyEioSEsSPISxo/wD1ALw5t IYOQ== X-Gm-Message-State: AOJu0YwUAf+/XnjVyoIokOHQuNg9WM7oIlcNfZh0TurGvLCeoaCgDEyw Ngq2fy5ASPPCge6Hb3MIMjQTUg== X-Received: by 2002:a05:620a:4d97:b0:77f:2bad:99f3 with SMTP id uw23-20020a05620a4d9700b0077f2bad99f3mr16829qkn.113.1701819755133; Tue, 05 Dec 2023 15:42:35 -0800 (PST) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id de36-20020a05620a372400b00767b0c35c15sm5437125qkb.91.2023.12.05.15.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 15:42:34 -0800 (PST) From: Justin Chen <justin.chen@broadcom.com> To: netdev@vger.kernel.org Cc: bcm-kernel-feedback-list@broadcom.com, florian.fainelli@broadcom.com, Justin Chen <justin.chen@broadcom.com>, Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>, Russell King <linux@armlinux.org.uk>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, linux-kernel@vger.kernel.org (open list) Subject: [PATCH] net: phy: Only resume phy if it is suspended Date: Tue, 5 Dec 2023 15:42:29 -0800 Message-Id: <20231205234229.274601-1-justin.chen@broadcom.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="000000000000ff2c4f060bcbc9f4" X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MIME_NO_TEXT,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 05 Dec 2023 15:42:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784487362413234255 X-GMAIL-MSGID: 1784487362413234255 |
Series |
net: phy: Only resume phy if it is suspended
|
|
Commit Message
Justin Chen
Dec. 5, 2023, 11:42 p.m. UTC
Resuming the phy can take quite a bit of time. Lets only resume the
phy if it is suspended.
Signed-off-by: Justin Chen <justin.chen@broadcom.com>
---
drivers/net/phy/phy.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Tue, Dec 05, 2023 at 03:42:29PM -0800, Justin Chen wrote: > Resuming the phy can take quite a bit of time. Lets only resume the > phy if it is suspended. Humm... https://lore.kernel.org/netdev/6d45f4da-c45e-4d35-869f-85dd4ec37b31@lunn.ch/T/ If Broadcom PHYs are slow to resume, maybe you should solve this in the broadcom resume handler, read the status from the hardware and only do the resume if the hardware is suspended. Andrew
On 12/5/23 4:03 PM, Andrew Lunn wrote: > On Tue, Dec 05, 2023 at 03:42:29PM -0800, Justin Chen wrote: >> Resuming the phy can take quite a bit of time. Lets only resume the >> phy if it is suspended. > > Humm... > > https://lore.kernel.org/netdev/6d45f4da-c45e-4d35-869f-85dd4ec37b31@lunn.ch/T/ > > If Broadcom PHYs are slow to resume, maybe you should solve this in > the broadcom resume handler, read the status from the hardware and > only do the resume if the hardware is suspended. > > Andrew Right... Guess this won't work. It is odd that during resume we call __phy_resume twice. Once from phy_resume() and another at phy_start(). Let me rethink this. Thanks for the feedback. Justin
On 12/5/23 16:10, Justin Chen wrote: > > > On 12/5/23 4:03 PM, Andrew Lunn wrote: >> On Tue, Dec 05, 2023 at 03:42:29PM -0800, Justin Chen wrote: >>> Resuming the phy can take quite a bit of time. Lets only resume the >>> phy if it is suspended. >> >> Humm... >> >> https://lore.kernel.org/netdev/6d45f4da-c45e-4d35-869f-85dd4ec37b31@lunn.ch/T/ >> >> If Broadcom PHYs are slow to resume, maybe you should solve this in >> the broadcom resume handler, read the status from the hardware and >> only do the resume if the hardware is suspended. >> >> Andrew > > Right... Guess this won't work. It is odd that during resume we call > __phy_resume twice. Once from phy_resume() and another at phy_start(). > Let me rethink this. Thanks for the feedback. This might be something for us to figure out on the driver side, I think historically I have always followed the pattern of doing: phy_suspend() phy_stop() and phy_resume() phy_start() because it used to be necessary to do that way back when...
Hi Andrew, On 12/5/23 16:12, Florian Fainelli wrote: > On 12/5/23 16:10, Justin Chen wrote: >> >> >> On 12/5/23 4:03 PM, Andrew Lunn wrote: >>> On Tue, Dec 05, 2023 at 03:42:29PM -0800, Justin Chen wrote: >>>> Resuming the phy can take quite a bit of time. Lets only resume the >>>> phy if it is suspended. >>> >>> Humm... >>> >>> https://lore.kernel.org/netdev/6d45f4da-c45e-4d35-869f-85dd4ec37b31@lunn.ch/T/ >>> >>> If Broadcom PHYs are slow to resume, maybe you should solve this in >>> the broadcom resume handler, read the status from the hardware and >>> only do the resume if the hardware is suspended. >>> >>> Andrew >> >> Right... Guess this won't work. It is odd that during resume we call >> __phy_resume twice. Once from phy_resume() and another at phy_start(). >> Let me rethink this. Thanks for the feedback. > > This might be something for us to figure out on the driver side, I think > historically I have always followed the pattern of doing: > > phy_suspend() > phy_stop() > > and > > phy_resume() > phy_start() > > because it used to be necessary to do that way back when... So we discussed with Justin and Doug about this yesterday and the main reason for the phy_resume() ... MAC initialization ... phy_start() pattern has to do with external RGMII PHYs and the clocking dependency between the MAC and the PHY on the RX path. And also a tiny bit of cargo culting, but shhh. When the external RGMII PHYs are suspended they will stop providing a RXC back to the Ethernet MAC and our Ethernet MAC like a lot of designs out there require the RXC in order to be functional and complete its reset procedure correctly (you would think there would be a way to mux in a different clock, but that does not appear to be the case). If we reset the UniMAC block without a RXC we will typically see duplicate packets being received, or absurdly long round trip times as soon as we try to use the RX path. Doug lifted that requirement in GENET with: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=88f6c8bf1aaed5039923fb4c701cab4d42176275 by delaying the MAC reset until we have a link UP confirmation. Since this is the same UniMAC design in the bcmasp driver we should be able to apply the same strategy and remove the initial phy_resume(). There are also other opportunities for avoiding link disruption upon suspend/resume when Wake-on-LAN is enabled and avoid a re-negotiation of the link, though that's for another set of changes.
On Thu, Dec 07, 2023 at 09:56:01AM -0800, Florian Fainelli wrote: > Hi Andrew, > > So we discussed with Justin and Doug about this yesterday and the main > reason for the phy_resume() ... MAC initialization ... phy_start() pattern > has to do with external RGMII PHYs and the clocking dependency between the > MAC and the PHY on the RX path. And also a tiny bit of cargo culting, but > shhh. > > When the external RGMII PHYs are suspended they will stop providing a RXC > back to the Ethernet MAC and our Ethernet MAC like a lot of designs out > there require the RXC in order to be functional and complete its reset > procedure correctly (you would think there would be a way to mux in a > different clock, but that does not appear to be the case). If we reset the > UniMAC block without a RXC we will typically see duplicate packets being > received, or absurdly long round trip times as soon as we try to use the RX > path. This issue keeps appearing, and I think phylib ought to be doing more to support it, rather than ethernet drivers having to play fancy games. If one recalls stmmac, that has similar issues - it needs the RXC from the PHY to reset properly. I did propose that we have: +#define PHY_F_RXC_ALWAYS_ON BIT(30) that can be passed to phy_attach_direct()'s flags, which phylib drivers can then act upon to e.g. in the case of at803x, disable their hibernation mode which stops the RXC when the system isn't suspended. (AT803x Hibernation mode is enabled by default and the PHY automatically enters it when the link is down.) Maybe this flag should be used to determine the resume behaviour, e.g. to ensure that the RXC is re-enabled early without the MAC driver needing to be involved? WoL is a different problem - that depends whether the PHY is itself doing WoL independently from the MAC, or whether the MAC is involved. If the MAC is involved, then clearly the MII link between the PHY and MAC needs to be maintained while the system is in low power mode, which is an entirely different issue from the RXC being present while the MAC is being resumed. Maybe PHY_F_RXC_ALWAYS_ON is a bad name, as I intended it to only refer to while the system is running, not while in low power mode.
On 12/7/23 10:50, Russell King (Oracle) wrote: > On Thu, Dec 07, 2023 at 09:56:01AM -0800, Florian Fainelli wrote: >> Hi Andrew, >> >> So we discussed with Justin and Doug about this yesterday and the main >> reason for the phy_resume() ... MAC initialization ... phy_start() pattern >> has to do with external RGMII PHYs and the clocking dependency between the >> MAC and the PHY on the RX path. And also a tiny bit of cargo culting, but >> shhh. >> >> When the external RGMII PHYs are suspended they will stop providing a RXC >> back to the Ethernet MAC and our Ethernet MAC like a lot of designs out >> there require the RXC in order to be functional and complete its reset >> procedure correctly (you would think there would be a way to mux in a >> different clock, but that does not appear to be the case). If we reset the >> UniMAC block without a RXC we will typically see duplicate packets being >> received, or absurdly long round trip times as soon as we try to use the RX >> path. > > This issue keeps appearing, and I think phylib ought to be doing more > to support it, rather than ethernet drivers having to play fancy games. > If one recalls stmmac, that has similar issues - it needs the RXC from > the PHY to reset properly. > > I did propose that we have: > > +#define PHY_F_RXC_ALWAYS_ON BIT(30) > > that can be passed to phy_attach_direct()'s flags, which phylib drivers > can then act upon to e.g. in the case of at803x, disable their > hibernation mode which stops the RXC when the system isn't suspended. > (AT803x Hibernation mode is enabled by default and the PHY automatically > enters it when the link is down.) > > Maybe this flag should be used to determine the resume behaviour, > e.g. to ensure that the RXC is re-enabled early without the MAC driver > needing to be involved? > > WoL is a different problem - that depends whether the PHY is itself > doing WoL independently from the MAC, or whether the MAC is involved. > If the MAC is involved, then clearly the MII link between the PHY and > MAC needs to be maintained while the system is in low power mode, > which is an entirely different issue from the RXC being present > while the MAC is being resumed. > > Maybe PHY_F_RXC_ALWAYS_ON is a bad name, as I intended it to only refer > to while the system is running, not while in low power mode. > Sure, I would like to see something similar and be able to use it, especially during boot. In our particular case however we have a "double" suspend and resume which is at best unnecessary and wasting time, and at worst causing some unidentified side effects.
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 3376e58e2b88..7fbb21922d64 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1549,7 +1549,8 @@ void phy_start(struct phy_device *phydev) sfp_upstream_start(phydev->sfp_bus); /* if phy was suspended, bring the physical link up again */ - __phy_resume(phydev); + if (phydev->suspended) + __phy_resume(phydev); phydev->state = PHY_UP;