From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9A02C61DA4 for ; Thu, 23 Feb 2023 10:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+zAaAXcxQLw0vhcizhszeEz4FvoaP08S0W7g7wYheTQ=; b=A/Ek5d57S3MUre 51G397Xe33/1JFAXZ0zb888KwhxXCSDRawKK+BMtKaXAPQXKkLjbwewA07xb/xPjjF3yTXcQjbq2S BdyW9cyKoflTYojp/wLFRQZ+0WK2E0UfdrJe4D9hfByHt0sPAOmefWm1hQS4Ksu3hZJGWOiUdNltb yOquAjPPPSRw1ctURdTYUcmsxC61iWjH/baViTmIvTrM7EBM2qE4ASsXd++q+w6Q0h0lZJ73Hzpdf 3uDOhp4v/yqpchzDAJwAPF85kYLUgRFMBItUMtb7no4vYpppLecFJ7B4cgYnKUQgl1pGYWcHZ3vGy 3/DPqz2MBxO64DDE50Bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV8XQ-00FrG9-Ge; Thu, 23 Feb 2023 10:09:20 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV8XM-00FrDo-Qj for linux-arm-kernel@lists.infradead.org; Thu, 23 Feb 2023 10:09:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677146951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RkvJTf97FKy/fS5owtL2kbI4ZWoazZ97WEJk/xaK81w=; b=Od7zGpVCWGG8bnoJlYevwSNYSEqwLAPrJZSulxQcc+GLxlgUamJkayYqM6znroUG9XQT4U WcTI7OHVGFXmPt3VltaitC4fPQFoIyvU7nDmVNmdNjNmFKUApT2dxe1UPILh8Waj4Vu8RB G9WQanMzXRaaq+0zeKhmp4PwYTPvLgs= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-203-aXaFlkw3NXWtAZyQmrBlsg-1; Thu, 23 Feb 2023 05:09:09 -0500 X-MC-Unique: aXaFlkw3NXWtAZyQmrBlsg-1 Received: by mail-qk1-f200.google.com with SMTP id b1-20020a05620a126100b0073b2dc0e161so5184247qkl.12 for ; Thu, 23 Feb 2023 02:09:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677146949; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=MwNi2R/qfei2F24G6SnycO92yZ0kjnuQBMoTKw0Q4E8=; b=ZB48VZhxf5Nw7nKc/K2Hv5yA8zPhvY2oHFCb/Cpdm9rVxUsAygOxBts5NhnVs4cNiW an1d397UGxNoxPXPgcSDVWgfaNKHfuGs6yK0g5HW3gw1rb/KOdUDYrkNx7pgcgLHaeNC QkCCUzi1Z/+F+VM4bDNoFjorv4CEvFj65Ktz5kOBN34I6JiZkFcwuacWpzjEdH/eK3QJ uvHc/94IJ+SK980e2tKFuu/Epo6pTWhCQL8aHGaBD/9h4dORwCauLyY5wqAFzk+YcICo RcNZifLul/yskBW4LZjgK3wlshuMYxjR7nq1WXcxuNh8t7FWiI2E3/w6mIKlgnskM+jH Wubw== X-Gm-Message-State: AO0yUKVoM7qn6nQo1wDfAfcu3xSNy2+vpnVQubbaKesDpfQ/3QGzad++ PkB7OYzzNtyRgwxHi7mZo3VK3XC2VrsDvEiZSD3GJm5oLqc/IZb5EKlFKxtC6q62f5zRdgFVswB n573cu+RXqtfeN7q0N84gBtJYGSCs7/Mn7Pk= X-Received: by 2002:ac8:5cd4:0:b0:3bb:75c7:9326 with SMTP id s20-20020ac85cd4000000b003bb75c79326mr22869252qta.0.1677146949163; Thu, 23 Feb 2023 02:09:09 -0800 (PST) X-Google-Smtp-Source: AK7set/koRPNANUmknQG+7kAuYwa4ay569snO2eNYzEq0HDqUGBTIoDvfkqm5FimiOMJ/yChM2nVyQ== X-Received: by 2002:ac8:5cd4:0:b0:3bb:75c7:9326 with SMTP id s20-20020ac85cd4000000b003bb75c79326mr22869227qta.0.1677146948834; Thu, 23 Feb 2023 02:09:08 -0800 (PST) Received: from gerbillo.redhat.com (146-241-121-8.dyn.eolo.it. [146.241.121.8]) by smtp.gmail.com with ESMTPSA id x191-20020a3763c8000000b007402fdda195sm6650615qkb.123.2023.02.23.02.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 02:09:08 -0800 (PST) Message-ID: <83a8fb89ac7a69d08c9ea1422dade301dcc87297.camel@redhat.com> Subject: Re: [PATCH V3 1/2] net: phylink: add a function to resume phy alone to fix resume issue with WoL enabled From: Paolo Abeni To: Clark Wang , peppe.cavallaro@st.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, mcoquelin.stm32@gmail.com, linux@armlinux.org.uk, andrew@lunn.ch, hkallweit1@gmail.com Cc: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com Date: Thu, 23 Feb 2023 11:09:04 +0100 In-Reply-To: <20230202081559.3553637-1-xiaoning.wang@nxp.com> References: <20230202081559.3553637-1-xiaoning.wang@nxp.com> User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230223_020916_985281_49B26243 X-CRM114-Status: GOOD ( 29.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 2023-02-02 at 16:15 +0800, Clark Wang wrote: > Issue we met: > On some platforms, mac cannot work after resumed from the suspend with WoL > enabled. > > The cause of the issue: > 1. phylink_resolve() is in a workqueue which will not be executed immediately. > This is the call sequence: > phylink_resolve()->phylink_link_up()->pl->mac_ops->mac_link_up() > For stmmac driver, mac_link_up() will set the correct speed/duplex... > values which are from link_state. > 2. In stmmac_resume(), it will call stmmac_hw_setup() after called the > phylink_resume(), because mac need phy rx_clk to do the reset. > stmmac_core_init() is called in function stmmac_hw_setup(), which will > reset the mac and set the speed/duplex... to default value. > Conclusion: Because phylink_resolve() cannot determine when it is called, it > cannot be guaranteed to be called after stmmac_core_init(). > Once stmmac_core_init() is called after phylink_resolve(), > the mac will be misconfigured and cannot be used. > > In order to avoid this problem, add a function called phylink_phy_resume() > to resume phy separately. This eliminates the need to call phylink_resume() > before stmmac_hw_setup(). > > Add another judgement before called phy_start() in phylink_start(). This way > phy_start() will not be called multiple times when resumes. At the same time, > it may not affect other drivers that do not use phylink_phy_resume(). > > Signed-off-by: Clark Wang > --- > V2 change: > - add mac_resume_phy_separately flag to struct phylink to mark if the mac > driver uses the phylink_phy_resume() first. > V3 change: > - add brace to avoid ambiguous 'else' > Reported-by: kernel test robot > --- > drivers/net/phy/phylink.c | 32 ++++++++++++++++++++++++++++++-- > include/linux/phylink.h | 1 + > 2 files changed, 31 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c > index 319790221d7f..c2fe66f0b78f 100644 > --- a/drivers/net/phy/phylink.c > +++ b/drivers/net/phy/phylink.c > @@ -80,6 +80,8 @@ struct phylink { > DECLARE_PHY_INTERFACE_MASK(sfp_interfaces); > __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support); > u8 sfp_port; > + > + bool mac_resume_phy_separately; > }; > > #define phylink_printk(level, pl, fmt, ...) \ > @@ -1509,6 +1511,7 @@ struct phylink *phylink_create(struct phylink_config *config, > return ERR_PTR(-EINVAL); > } > > + pl->mac_resume_phy_separately = false; > pl->using_mac_select_pcs = using_mac_select_pcs; > pl->phy_state.interface = iface; > pl->link_interface = iface; > @@ -1943,8 +1946,12 @@ void phylink_start(struct phylink *pl) > } > if (poll) > mod_timer(&pl->link_poll, jiffies + HZ); > - if (pl->phydev) > - phy_start(pl->phydev); > + if (pl->phydev) { > + if (!pl->mac_resume_phy_separately) > + phy_start(pl->phydev); > + else > + pl->mac_resume_phy_separately = false; > + } > if (pl->sfp_bus) > sfp_upstream_start(pl->sfp_bus); > } > @@ -2024,6 +2031,27 @@ void phylink_suspend(struct phylink *pl, bool mac_wol) > } > EXPORT_SYMBOL_GPL(phylink_suspend); > > +/** > + * phylink_phy_resume() - resume phy alone > + * @pl: a pointer to a &struct phylink returned from phylink_create() > + * > + * In the MAC driver using phylink, if the MAC needs the clock of the phy > + * when it resumes, can call this function to resume the phy separately. > + * Then proceed to MAC resume operations. > + */ > +void phylink_phy_resume(struct phylink *pl) > +{ > + ASSERT_RTNL(); > + > + if (!test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state) > + && pl->phydev) { > + phy_start(pl->phydev); > + pl->mac_resume_phy_separately = true; > + } > + Minor nit: the empty line here is not needed. Cheers, Paolo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel