Message ID | 20230927175749.1419774-1-ben.wolsieffer@hefring.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2803843vqu; Wed, 27 Sep 2023 11:02:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmre9YURSZkLdmRA5UmsZsYsIlAnLn0KSQpHJHALUKdalybD7mXYsDVUnWgP4u4P5St12D X-Received: by 2002:a17:902:7d96:b0:1c3:83e2:d0a9 with SMTP id a22-20020a1709027d9600b001c383e2d0a9mr2183086plm.58.1695837767396; Wed, 27 Sep 2023 11:02:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695837767; cv=none; d=google.com; s=arc-20160816; b=K9o+dzBZVJP1WPiaRMdXECkJQR0+Wi6Fxzea+rN84L+UrIgPyA8tvd5NqtFfnTNKyH anVbrTMGxDntjzOsfSd2pxVqZ9tH8Nl8RDCj+gk8cWoHzGtNBaeuYH+Nz8n8gO6zzFoS DMYFr7ow0y5mm2CuUpXsRZ6F2TA3iXyCRX/VaezRabcThmtBZisRDh4ApQHZ5LHAMcct OlFJNYM2FN6I54l9GuJEb2nXjIzgVDepLDrs7gAWtqWKM/URkkWIjXXZZgwPozJfzMFV WfyYPHBXX3Yi8/sEUFXUt5TdPnLFG6NBrUQm1NPUh8zcWeDtRyD4wwdQtHkUx0fCNCo5 trBQ== 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:dkim-signature; bh=AQzb+SwvsGBOEDzBjP4js4Sz2yj+gakJ7LKev+o0njQ=; fh=f9safSkw/SQVr0kEtPvUiqQf5kZ6gbwV4tr+WhykmK8=; b=NYKEOvfm//f6CHdzqLtHWfFouL0uLDw+udxetLtEu8JqRh7bCxCnfR4hrX02kEZiWW uDW7Tzn5NMUbyZWCG1SOJ2qcL7xHMC5x1G7uhatcLhhHD7apEP526W79jvAApiKJhxHT C2Msh5lvvwD5kDN604MRDGoLjcVdMaLckDXa9TvnA1ueWMax1GqT6NfWiLprvbXkpOFo bi6k1AGALGNQYzJjz11TaDKIS2DVhnKGsJa+C+yR0fdT8i6V/vi1ziakktr0WAIfH3lt g7MAJtS4/h6ZTASb1ZeZArJ7g6BpuxU0LGoFXISYrxfqWHS6fHdAxrydg2xJfEOXu6dD Zf8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b=C5IIxI+p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id kh15-20020a170903064f00b001c589ba4a0asi15134721plb.7.2023.09.27.11.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 11:02:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b=C5IIxI+p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 198818026D89; Wed, 27 Sep 2023 10:59:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjI0R6u (ORCPT <rfc822;ruipengqi7@gmail.com> + 20 others); Wed, 27 Sep 2023 13:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbjI0R6b (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 27 Sep 2023 13:58:31 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E807199F for <linux-kernel@vger.kernel.org>; Wed, 27 Sep 2023 10:58:07 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id af79cd13be357-77428e40f71so528084785a.1 for <linux-kernel@vger.kernel.org>; Wed, 27 Sep 2023 10:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hefring-com.20230601.gappssmtp.com; s=20230601; t=1695837486; x=1696442286; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AQzb+SwvsGBOEDzBjP4js4Sz2yj+gakJ7LKev+o0njQ=; b=C5IIxI+pINtGg0abOaawu4LgnPahsj3UVakl7upV3RgvtwX5QSy27keLxYbeNHFAG+ PYWOvUaVPF+pNIe3AeYKSOUNTZD3mfZdI+2LiSyD5xtKScQOqVtcLHlMYTM++WULSUg4 gQ93CiD3cX4m6hUkyNKBJbTP1QCiYbieQQf1Ipk3X4COFhxHTaZ7t0P9pxzHZMBMAoi+ 5Pj53KLxnQl+qGMlbIsdpn8Mr9R90Za1sgKpBPMU8WRzFMwEmvJHQhw7LgiQYwPig6Tw mjbsm/r/h7MaaJGBYw8KNsH0qEc35MSAeA8SyLoxjiMnw+aemWQluvQ3VD6lKmbX6t9b RhOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695837486; x=1696442286; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AQzb+SwvsGBOEDzBjP4js4Sz2yj+gakJ7LKev+o0njQ=; b=I86NFoJppdXw82eShLafWjGEX13K3NdGAGgDVv4XA1WLOp3IkjKWOEyEyBSlJWNy8w ORlaoIPgX4z0LJWJxXqDtPj/5bF1nyYN16ZDFgTT0kqDJEr7hm064Rr8fAyFUomcnt0p Q6demA5pzhE7MUbE0soUn8qIQRqT2qYEPE4EtryCUJCSVKcqFMCBsFNRmZWbZWiyfbEa ETZ9PzdxILA2c0+2YfMe9rNuO7tCxo3We21Hvpr7Yw+M8tZrOen1SWTPn7DEL4pv34rO hFhLRwM6n0bUlwN4S7A7ytO40JJwg8n3U/nOPmRcY337ywzQqC+SzDVx6AKUuZhOGTM5 3FoA== X-Gm-Message-State: AOJu0YyLsJ+DExLWu+BvZUVtLPLo/NDpspRBe7CXQynifO0I4vkg7Ir8 CfoWLWgfbGtQgIOSzRijPypj4Q== X-Received: by 2002:a05:622a:14b:b0:416:5ead:6171 with SMTP id v11-20020a05622a014b00b004165ead6171mr3362737qtw.47.1695837486383; Wed, 27 Sep 2023 10:58:06 -0700 (PDT) Received: from localhost.localdomain ([50.212.55.89]) by smtp.gmail.com with ESMTPSA id j4-20020ac84c84000000b004195b8554efsm711368qtv.24.2023.09.27.10.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:58:05 -0700 (PDT) From: Ben Wolsieffer <ben.wolsieffer@hefring.com> To: linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>, Jose Abreu <joabreu@synopsys.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Maxime Coquelin <mcoquelin.stm32@gmail.com>, Christophe Roullier <christophe.roullier@st.com>, Ben Wolsieffer <ben.wolsieffer@hefring.com> Subject: [PATCH net] net: stmmac: dwmac-stm32: fix resume on STM32 MCU Date: Wed, 27 Sep 2023 13:57:49 -0400 Message-ID: <20230927175749.1419774-1-ben.wolsieffer@hefring.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 27 Sep 2023 10:59:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778214782729174172 X-GMAIL-MSGID: 1778214782729174172 |
Series |
[net] net: stmmac: dwmac-stm32: fix resume on STM32 MCU
|
|
Commit Message
Ben Wolsieffer
Sept. 27, 2023, 5:57 p.m. UTC
The STM32MP1 keeps clk_rx enabled during suspend, and therefore the
driver does not enable the clock in stm32_dwmac_init() if the device was
suspended. The problem is that this same code runs on STM32 MCUs, which
do disable clk_rx during suspend, causing the clock to never be
re-enabled on resume.
This patch adds a variant flag to indicate that clk_rx remains enabled
during suspend, and uses this to decide whether to enable the clock in
stm32_dwmac_init() if the device was suspended.
This approach fixes this specific bug with limited opportunity for
unintended side-effects, but I have a follow up patch that will refactor
the clock configuration and hopefully make it less error prone.
Fixes: 6528e02cc9ff ("net: ethernet: stmmac: add adaptation for stm32mp157c.")
Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
Comments
On 9/27/2023 10:57 AM, Ben Wolsieffer wrote: > The STM32MP1 keeps clk_rx enabled during suspend, and therefore the > driver does not enable the clock in stm32_dwmac_init() if the device was > suspended. The problem is that this same code runs on STM32 MCUs, which > do disable clk_rx during suspend, causing the clock to never be > re-enabled on resume. > > This patch adds a variant flag to indicate that clk_rx remains enabled > during suspend, and uses this to decide whether to enable the clock in > stm32_dwmac_init() if the device was suspended. > Why not just keep clk_rx enabled unconditionally or unconditionally stop it during suspend? I guess that might be part of a larger cleanup and has more side effects? > This approach fixes this specific bug with limited opportunity for > unintended side-effects, but I have a follow up patch that will refactor > the clock configuration and hopefully make it less error prone. > I'd guess the follow-up refactor would target next? > Fixes: 6528e02cc9ff ("net: ethernet: stmmac: add adaptation for stm32mp157c.") > Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com> > --- This seems pretty small and targeted so it does make sense to me as a net fix, but it definitely feels like a workaround. I look forward to reading the cleanup patch mentioned. Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> > drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > index bdb4de59a672..28c8ca5fba6c 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c > @@ -105,6 +105,7 @@ struct stm32_ops { > int (*parse_data)(struct stm32_dwmac *dwmac, > struct device *dev); > u32 syscfg_eth_mask; > + bool clk_rx_enable_in_suspend; > }; > > static int stm32_dwmac_init(struct plat_stmmacenet_data *plat_dat) > @@ -122,7 +123,8 @@ static int stm32_dwmac_init(struct plat_stmmacenet_data *plat_dat) > if (ret) > return ret; > > - if (!dwmac->dev->power.is_suspended) { > + if (!dwmac->ops->clk_rx_enable_in_suspend || > + !dwmac->dev->power.is_suspended) { > ret = clk_prepare_enable(dwmac->clk_rx); > if (ret) { > clk_disable_unprepare(dwmac->clk_tx); > @@ -514,7 +516,8 @@ static struct stm32_ops stm32mp1_dwmac_data = { > .suspend = stm32mp1_suspend, > .resume = stm32mp1_resume, > .parse_data = stm32mp1_parse_data, > - .syscfg_eth_mask = SYSCFG_MP1_ETH_MASK > + .syscfg_eth_mask = SYSCFG_MP1_ETH_MASK, > + .clk_rx_enable_in_suspend = true > }; > > static const struct of_device_id stm32_dwmac_match[] = {
Hi Jacob, On Fri, Sep 29, 2023 at 10:48:47AM -0700, Jacob Keller wrote: > > > On 9/27/2023 10:57 AM, Ben Wolsieffer wrote: > > The STM32MP1 keeps clk_rx enabled during suspend, and therefore the > > driver does not enable the clock in stm32_dwmac_init() if the device was > > suspended. The problem is that this same code runs on STM32 MCUs, which > > do disable clk_rx during suspend, causing the clock to never be > > re-enabled on resume. > > > > This patch adds a variant flag to indicate that clk_rx remains enabled > > during suspend, and uses this to decide whether to enable the clock in > > stm32_dwmac_init() if the device was suspended. > > > > Why not just keep clk_rx enabled unconditionally or unconditionally stop > it during suspend? I guess that might be part of a larger cleanup and > has more side effects? Ideally, you want to turn off as many clocks as possible in suspend to save power. I'm assuming there is some hardware reason the STM32MP1 needs the RX clock on during suspend, but it was not explained in the original patch. Without more information, I'm trying to maintain the existing behavior. > > > This approach fixes this specific bug with limited opportunity for > > unintended side-effects, but I have a follow up patch that will refactor > > the clock configuration and hopefully make it less error prone. > > > > I'd guess the follow-up refactor would target next? > > > Fixes: 6528e02cc9ff ("net: ethernet: stmmac: add adaptation for stm32mp157c.") > > Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com> > > --- > > This seems pretty small and targeted so it does make sense to me as a > net fix, but it definitely feels like a workaround. > > I look forward to reading the cleanup patch mentioned. Sorry, I should have linked this when I re-posted this patch for net, but I previously submitted this patch as part of a series with the cleanup but was asked to split them up for net and net-next. Personally, I would be fine with them going into net-next together (or squashed). The original series can be found here: https://lore.kernel.org/linux-arm-kernel/20230919164535.128125-3-ben.wolsieffer@hefring.com/T/ Thanks, Ben
Hello: This patch was applied to netdev/net.git (main) by Jakub Kicinski <kuba@kernel.org>: On Wed, 27 Sep 2023 13:57:49 -0400 you wrote: > The STM32MP1 keeps clk_rx enabled during suspend, and therefore the > driver does not enable the clock in stm32_dwmac_init() if the device was > suspended. The problem is that this same code runs on STM32 MCUs, which > do disable clk_rx during suspend, causing the clock to never be > re-enabled on resume. > > This patch adds a variant flag to indicate that clk_rx remains enabled > during suspend, and uses this to decide whether to enable the clock in > stm32_dwmac_init() if the device was suspended. > > [...] Here is the summary with links: - [net] net: stmmac: dwmac-stm32: fix resume on STM32 MCU https://git.kernel.org/netdev/net/c/6f195d6b0da3 You are awesome, thank you!
On 10/2/23 15:54, Ben Wolsieffer wrote: > Hi Jacob, > > On Fri, Sep 29, 2023 at 10:48:47AM -0700, Jacob Keller wrote: >> >> >> On 9/27/2023 10:57 AM, Ben Wolsieffer wrote: >>> The STM32MP1 keeps clk_rx enabled during suspend, and therefore the >>> driver does not enable the clock in stm32_dwmac_init() if the device was >>> suspended. The problem is that this same code runs on STM32 MCUs, which >>> do disable clk_rx during suspend, causing the clock to never be >>> re-enabled on resume. >>> >>> This patch adds a variant flag to indicate that clk_rx remains enabled >>> during suspend, and uses this to decide whether to enable the clock in >>> stm32_dwmac_init() if the device was suspended. >>> >> >> Why not just keep clk_rx enabled unconditionally or unconditionally stop >> it during suspend? I guess that might be part of a larger cleanup and >> has more side effects? > > Ideally, you want to turn off as many clocks as possible in suspend to > save power. I'm assuming there is some hardware reason the STM32MP1 > needs the RX clock on during suspend, but it was not explained in the > original patch. Without more information, I'm trying to maintain the > existing behavior. > Sorry for this late answer. We could need RX clock for WOL support. >> >>> This approach fixes this specific bug with limited opportunity for >>> unintended side-effects, but I have a follow up patch that will refactor >>> the clock configuration and hopefully make it less error prone. >>> >> >> I'd guess the follow-up refactor would target next? >> >>> Fixes: 6528e02cc9ff ("net: ethernet: stmmac: add adaptation for stm32mp157c.") >>> Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com> >>> --- >> >> This seems pretty small and targeted so it does make sense to me as a >> net fix, but it definitely feels like a workaround. >> >> I look forward to reading the cleanup patch mentioned. > > Sorry, I should have linked this when I re-posted this patch for > net, but I previously submitted this patch as part of a series with > the cleanup but was asked to split them up for net and net-next. > Personally, I would be fine with them going into net-next together (or > squashed). > > The original series can be found here: > https://lore.kernel.org/linux-arm-kernel/20230919164535.128125-3-ben.wolsieffer@hefring.com/T/ > > Thanks, Ben
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c index bdb4de59a672..28c8ca5fba6c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c @@ -105,6 +105,7 @@ struct stm32_ops { int (*parse_data)(struct stm32_dwmac *dwmac, struct device *dev); u32 syscfg_eth_mask; + bool clk_rx_enable_in_suspend; }; static int stm32_dwmac_init(struct plat_stmmacenet_data *plat_dat) @@ -122,7 +123,8 @@ static int stm32_dwmac_init(struct plat_stmmacenet_data *plat_dat) if (ret) return ret; - if (!dwmac->dev->power.is_suspended) { + if (!dwmac->ops->clk_rx_enable_in_suspend || + !dwmac->dev->power.is_suspended) { ret = clk_prepare_enable(dwmac->clk_rx); if (ret) { clk_disable_unprepare(dwmac->clk_tx); @@ -514,7 +516,8 @@ static struct stm32_ops stm32mp1_dwmac_data = { .suspend = stm32mp1_suspend, .resume = stm32mp1_resume, .parse_data = stm32mp1_parse_data, - .syscfg_eth_mask = SYSCFG_MP1_ETH_MASK + .syscfg_eth_mask = SYSCFG_MP1_ETH_MASK, + .clk_rx_enable_in_suspend = true }; static const struct of_device_id stm32_dwmac_match[] = {