Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp288271rwb; Thu, 22 Sep 2022 18:18:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ZIfDASlXPCXp+MLXL9/TElCJZeAzP4AvBCrvCItO6m3Gx5Mk/xjmJYIwdpRi/GrVKx8fI X-Received: by 2002:a63:d250:0:b0:435:1774:1f93 with SMTP id t16-20020a63d250000000b0043517741f93mr5504529pgi.339.1663895907071; Thu, 22 Sep 2022 18:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663895907; cv=none; d=google.com; s=arc-20160816; b=pwd3+JJePpgHGHgk6cXeBGF722aiN9QSCTlysUG4/L4ebSd9b1A0KU5c19Y60QmbZb zahrHRUnawMJ0KEaEf2u3p+GP3E839PCKJ5mwbq7CGeN7oLWIUiMBSZFjK4yW+dgLKu+ CXb+4+OzFklJdI9CUYLySK6XoO7gZUfeqJ6Md+ougucV5936A6w2Xb4TZXaWDUqypGQC VujT4G+5/5gUVzBOaEajw16C/0XxzLTWBRuWmpqm6T8xi+pGfZExWyW11WU+DjJU1ypv zhgQPtKbeNG7aV2X1jTAndmPWTu4XuKhpfXjOg+wEOErdHHdFvRSy3Esuw4EajIgG+jR f7Vg== 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=LRPPPAXSzwWx25gNlOkM55AxW4ApkjqM9SWaJ64iuDk=; b=ZRYFYm3vwn2d5dkXPZOjoeM4SMoj1CrBfdCidLTmqfblRVMTNB8oa3eyQf93LagFFU Phrt4sXRXk4gYRAYL19vEJa/WEIK9H23rsmdqthvmKnhuYgNiZzmigeXu8SCzk4ZvwPG zvmdofcQ1jP7jk/KSjj3QXajesSvPoHDr33Zj7tfBY4z1q9bR8Exf26993iJSzSAZPLQ 3B2RskS224JFJ4rCI6m7ifr3K9a4V9mgEAo3/kPmutl8zpTBn5cWwjqDudjA67yP+QBA SoyDU5a8Cgj/NYmGNnH/GivpMLja+ayY+hDBmX2q8rFOLkVf6FUUgKJ/RMjd37ZOJgR6 4HzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="a+Rb/isG"; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z22-20020aa791d6000000b0053e29668420si7238274pfa.94.2022.09.22.18.18.13; Thu, 22 Sep 2022 18:18:27 -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=@intel.com header.s=Intel header.b="a+Rb/isG"; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229519AbiIWBAC (ORCPT + 99 others); Thu, 22 Sep 2022 21:00:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230024AbiIWA77 (ORCPT ); Thu, 22 Sep 2022 20:59:59 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8AB652464; Thu, 22 Sep 2022 17:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663894796; x=1695430796; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/uo0jGzdyoJ+5Q+AgQzpBNuR2hij9YIXpWG6or5WiSw=; b=a+Rb/isGAP4I+ISwH4VbhM6MxGGS0xQsaHPhNq5hyTKRmHLXRTiFWra3 TEQ1L+1+AHAD5eE2C55xN43CcW46tJwb+7IPt3l6P/jTg143wi8dxo8cm OO9PSu2JaRxYOIYEky8dnWmtRPjb6yEwj9YzDqOkdOaj6/Gzp+Mms3GrN 74iWTV+C6mftGX9mSA9pFavZKC1TGASNZgOYMC9wajjooYV0GaLlamLgp HE2rOaeBD7VwIF7WG9cBRVPsNmxwIBLnHeyopZxnjNNbTz8PWkPAuFUb4 0XeFEXwI9J0nIN3JM/xKnA82Kl2qIJ62aGQS25raMH9uLTqDtgUtyJ/mQ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10478"; a="298074765" X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="298074765" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 17:59:56 -0700 X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="571196171" Received: from junxiaochang.bj.intel.com ([10.238.135.52]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 17:59:51 -0700 From: Junxiao Chang To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Ong Boon Leong , Voon Weifeng , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: jimmyjs.chen@adlinktech.com, hong.aun.looi@intel.com, junxiao.chang@intel.com Subject: [net] net: stmmac: power up/down serdes in stmmac_open/release Date: Fri, 23 Sep 2022 08:50:13 +0800 Message-Id: <20220923005014.955076-1-junxiao.chang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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_NONE 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 This commit fixes DMA engine reset timeout issue in suspend/resume with ADLink I-Pi SMARC Plus board which dmesg shows: ... [ 54.678271] PM: suspend exit [ 54.754066] intel-eth-pci 0000:00:1d.2 enp0s29f2: PHY [stmmac-3:01] driver [Maxlinear Ethernet GPY215B] (irq=POLL) [ 54.755808] intel-eth-pci 0000:00:1d.2 enp0s29f2: Register MEM_TYPE_PAGE_POOL RxQ-0 ... [ 54.780482] intel-eth-pci 0000:00:1d.2 enp0s29f2: Register MEM_TYPE_PAGE_POOL RxQ-7 [ 55.784098] intel-eth-pci 0000:00:1d.2: Failed to reset the dma [ 55.784111] intel-eth-pci 0000:00:1d.2 enp0s29f2: stmmac_hw_setup: DMA engine initialization failed [ 55.784115] intel-eth-pci 0000:00:1d.2 enp0s29f2: stmmac_open: Hw setup failed ... The issue is related with serdes which impacts clock. There is serdes in ADLink I-Pi SMARC board ethernet controller. Please refer to commit b9663b7ca6ff78 ("net: stmmac: Enable SERDES power up/down sequence") for detial. When issue is reproduced, DMA engine clock is not ready because serdes is not powered up. To reproduce DMA engine reset timeout issue with hardware which has serdes in GBE controller, install Ubuntu. In Ubuntu GUI, click "Power Off/Log Out" -> "Suspend" menu, it disables network interface, then goes to sleep mode. When it wakes up, it enables network interface again. Stmmac driver is called in this way: 1. stmmac_release: Stop network interface. In this function, it disables DMA engine and network interface; 2. stmmac_suspend: It is called in kernel suspend flow. But because network interface has been disabled(netif_running(ndev) is false), it does nothing and returns directly; 3. System goes into S3 or S0ix state. Some time later, system is waken up by keyboard or mouse; 4. stmmac_resume: It does nothing because network interface has been disabled; 5. stmmac_open: It is called to enable network interace again. DMA engine is initialized in this API, but serdes is not power on so there will be DMA engine reset timeout issue. Similarly, serdes powerdown should be added in stmmac_release. Network interface might be disabled by cmd "ifconfig eth0 down", DMA engine, phy and mac have been disabled in ndo_stop callback, serdes should be powered down as well. It doesn't make sense that serdes is on while other components have been turned off. If ethernet interface is in enabled state(netif_running(ndev) is true) before suspend/resume, the issue couldn't be reproduced because serdes could be powered up in stmmac_resume. Because serdes_powerup is added in stmmac_open, it doesn't need to be called in probe function. Fixes: b9663b7ca6ff78 ("net: stmmac: Enable SERDES power up/down sequence") Signed-off-by: Junxiao Chang Reviewed-by: Voon Weifeng Tested-by: Jimmy JS Chen Tested-by: Looi, Hong Aun --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 592d29abcb1c2..508972bce5024 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3801,6 +3801,14 @@ static int __stmmac_open(struct net_device *dev, stmmac_reset_queues_param(priv); + if (priv->plat->serdes_powerup) { + ret = priv->plat->serdes_powerup(dev, priv->plat->bsp_priv); + if (ret < 0) { + netdev_err(priv->dev, "%s: Serdes powerup failed\n", __func__); + goto init_error; + } + } + ret = stmmac_hw_setup(dev, true); if (ret < 0) { netdev_err(priv->dev, "%s: Hw setup failed\n", __func__); @@ -3904,6 +3912,10 @@ static int stmmac_release(struct net_device *dev) /* Disable the MAC Rx/Tx */ stmmac_mac_set(priv, priv->ioaddr, false); + /* Powerdown Serdes if there is */ + if (priv->plat->serdes_powerdown) + priv->plat->serdes_powerdown(dev, priv->plat->bsp_priv); + netif_carrier_off(dev); stmmac_release_ptp(priv); @@ -7293,14 +7305,6 @@ int stmmac_dvr_probe(struct device *device, goto error_netdev_register; } - if (priv->plat->serdes_powerup) { - ret = priv->plat->serdes_powerup(ndev, - priv->plat->bsp_priv); - - if (ret < 0) - goto error_serdes_powerup; - } - #ifdef CONFIG_DEBUG_FS stmmac_init_fs(ndev); #endif -- 2.25.1