Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp485914imn; Wed, 27 Jul 2022 11:31:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uYmqxHdCAWFnjyjp0W4Ht+DiAY3BKRin8RJMlPX16QVo6OmNVGuYeD4X/gF6oADNeVK8mE X-Received: by 2002:a17:902:760f:b0:16c:ae59:c9b2 with SMTP id k15-20020a170902760f00b0016cae59c9b2mr22719223pll.0.1658946716486; Wed, 27 Jul 2022 11:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946716; cv=none; d=google.com; s=arc-20160816; b=IeES15z2bNEy5GYfItUfgQL03NSyGU7YIy1dtPqQL+SuQTzbVJqupFeWfQAPvqgoyz r86JShKHS3QqnJyEBMfVYqcZAvlUQrA2pPr7bQi2x7U5vzevfEVILkMsA7qSjdlbUus2 0tpGnuFN5U8Dq/UCAuErMQT3NKVlmpD7z2TY+3DzXrdjsGUUz6S8CrTLIviaaWi1ydfr /spKWkCxDxEuwthE4JtqBcQMU2pSHox4Sr8l3NuMyd9BeXv1TfA/Sknq5aH4RiFFe0bY 4/V2WuRJ3viOerhTx3lXQWCOygzK4/Fs2ZMm9BKHl/oSqG8MhTvUr5kwwnDDwp1RcAjJ zcgA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SKRHxRCiLE5Q3xveUkk3uTmaqlv7cl4i8J6tOQ6IViA=; b=suI618eYvi5rO7nm+m5xh6VNt18SEFqvX/19HUp+53sJehA9PtApTrVC2abSPVrHUQ dMyIN8dWFozGaw4LbHpLtav5K6Xncf9WQqXjpq9Y1dUADFuyaAEGi3fep1JfNFSDs24j uLX4ZICTFzH4jR2GfMiPrNcr0DNOylHcexcCE1K71FM/6lyV0YcZUBV8GE2raXIDnIix L/Ugm0JVeULS5N0FJeVCa1Z8VkQa+78OWVYMzjl3T9q8YdNeumd4A4cKmX4rJ2DhS867 lFxb1EoVqETwW6BgfbkkmP/TlAGuuzIMEsswlPcg6hfLCmu4y3poLJD3FB9Jni8yMXU/ bB+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iH1BiLMs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t14-20020a170902b20e00b0016a17da4ad3si19053498plr.339.2022.07.27.11.31.40; Wed, 27 Jul 2022 11:31:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iH1BiLMs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241498AbiG0RIe (ORCPT + 99 others); Wed, 27 Jul 2022 13:08:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237673AbiG0RHw (ORCPT ); Wed, 27 Jul 2022 13:07:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23DA04E609; Wed, 27 Jul 2022 09:40:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0ACC860D3C; Wed, 27 Jul 2022 16:40:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 123F5C433D6; Wed, 27 Jul 2022 16:40:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940018; bh=Xd3Ruhz90sS4nMtEn5T2f4REu/L1TQxJ8JzAp/2+XaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iH1BiLMska++rh+V1huD+UmhUHUXo7OzHNHksomOg+g+5Ve4jYx/3G8QbQgt7Zfck sayczo26M7wDcL6jex+mdfO45jU4+f9WZ9KwCyjRzXqRhUVoUnMOnJdqdn5/0r/vgQ 0B65FmZxRSEbZOl1PCV7Rjo8gBwlgqlIr5CklqbY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Biao Huang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 070/201] net: stmmac: fix unbalanced ptp clock issue in suspend/resume flow Date: Wed, 27 Jul 2022 18:09:34 +0200 Message-Id: <20220727161029.846082694@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Biao Huang [ Upstream commit f4c7d8948e866918d61493264dbbd67e45ef2bda ] Current stmmac driver will prepare/enable ptp_ref clock in stmmac_init_tstamp_counter(). The stmmac_pltfr_noirq_suspend will disable it once in suspend flow. But in resume flow, stmmac_pltfr_noirq_resume --> stmmac_init_tstamp_counter stmmac_resume --> stmmac_hw_setup --> stmmac_init_ptp --> stmmac_init_tstamp_counter ptp_ref clock reference counter increases twice, which leads to unbalance ptp clock when resume back. Move ptp_ref clock prepare/enable out of stmmac_init_tstamp_counter to fix it. Fixes: 0735e639f129d ("net: stmmac: skip only stmmac_ptp_register when resume from suspend") Signed-off-by: Biao Huang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 17 ++++++++--------- .../ethernet/stmicro/stmmac/stmmac_platform.c | 8 +++++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 95e1307cfda2..b4f83c865568 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -844,19 +844,10 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags) struct timespec64 now; u32 sec_inc = 0; u64 temp = 0; - int ret; if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) return -EOPNOTSUPP; - ret = clk_prepare_enable(priv->plat->clk_ptp_ref); - if (ret < 0) { - netdev_warn(priv->dev, - "failed to enable PTP reference clock: %pe\n", - ERR_PTR(ret)); - return ret; - } - stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags); priv->systime_flags = systime_flags; @@ -3325,6 +3316,14 @@ static int stmmac_hw_setup(struct net_device *dev, bool ptp_register) stmmac_mmc_setup(priv); + if (ptp_register) { + ret = clk_prepare_enable(priv->plat->clk_ptp_ref); + if (ret < 0) + netdev_warn(priv->dev, + "failed to enable PTP reference clock: %pe\n", + ERR_PTR(ret)); + } + ret = stmmac_init_ptp(priv); if (ret == -EOPNOTSUPP) netdev_warn(priv->dev, "PTP not supported by HW\n"); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 11e1055e8260..9f5cac4000da 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -815,7 +815,13 @@ static int __maybe_unused stmmac_pltfr_noirq_resume(struct device *dev) if (ret) return ret; - stmmac_init_tstamp_counter(priv, priv->systime_flags); + ret = clk_prepare_enable(priv->plat->clk_ptp_ref); + if (ret < 0) { + netdev_warn(priv->dev, + "failed to enable PTP reference clock: %pe\n", + ERR_PTR(ret)); + return ret; + } } return 0; -- 2.35.1