From patchwork Thu Nov 9 05:00:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gan, Yi Fang" X-Patchwork-Id: 163221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp222080vqs; Wed, 8 Nov 2023 21:04:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHT2CAs0vPEUYJJm6Jcg/nlywsP6wP2h7YfWkzsp02ImIxBjlewNJhtnoS9z+cLbY8MMmyo X-Received: by 2002:a05:6808:1808:b0:3b5:9583:dc80 with SMTP id bh8-20020a056808180800b003b59583dc80mr741946oib.30.1699506258201; Wed, 08 Nov 2023 21:04:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699506258; cv=none; d=google.com; s=arc-20160816; b=baJn7xd4c8JFtDMlEhqMGZSxm7r33S7n5Ilku0w8Ytt2iHadZyGCHW91aJUfFj+57z fyZhQEyCs6X3L0KBhEmR/MR1y6GI2CxqFVLrTv3JnH254hPNmOf+w68X7W22vvko2S1L hoUjQhJTdSUNdv4TCjkwQGVsuoAzjXgv+twnyrLKvLleZnP5gqp4+0K1eNeuzjqTBaCa paHARNzPnQYgSNBurCX1uJ1WKZBWoEK3wPdY/3zrup0NmO45zgK9XtRmfi/BSiKkEy15 WfApp9PXqzg5ag1Fb4lOz/kxzhIkh2nlwnntgbH8X/tQU5NpD3jgUHgA2GL5r/W1KI3s 6gxA== 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=GRwspqJu67H4n19zGm1vB6TA0Bf2YRzp78EbKHRlQvk=; fh=ze6AhWzsVnZWvPtw8PTEtuhCfn6eovY85WpeeoqqbgA=; b=lt5s3hcIsIRUUQdYmHC6UDZoICoAg+fdjRYv6C8rBPyYWuSPjvg3jEV49IZtJd5EhY OYCmGnsi+qwfGcBO47oGjo+4Tw9oxy48laab1lbhuz8WvQneMFOjsnspmEQbVrWnjXk0 3f8JDJupsOy0QrmVSztmb9MonJriyzYQImrd03NmV2YNuEvwwu6xJa24lu1yBLKL/5IX CPufxSKSsXF6KOnyn2fJ+89RgI/1K6llCjT7XL+fJaIUh/ATZF0HCTLLvmIyoHaTpb25 SGs3V16APT41v//sgDcL26l2WTN6b8BXVXqcQgc0SI3y0LQ9uIxLCJordv37I+4A6Mi/ R8Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eKzsamSc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id v16-20020a63f210000000b00577448019b5si6183655pgh.276.2023.11.08.21.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 21:04:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eKzsamSc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id EA16882972DD; Wed, 8 Nov 2023 21:04:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232221AbjKIFEE (ORCPT + 32 others); Thu, 9 Nov 2023 00:04:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbjKIFEC (ORCPT ); Thu, 9 Nov 2023 00:04:02 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05261D58; Wed, 8 Nov 2023 21:03:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699506239; x=1731042239; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uxgTlz8DTOjfWlg4jszUqQlmMAps8QNPlUyELVJIm1M=; b=eKzsamScKLOWc88vsxUaLUmovGLUDUBtgB5KXlHuxBybKL1NKchXW9RJ k1j1Q98QTDpWon0Ct2yqzv1YywlhwLwksHiPnx3WPsbyu3kX9K5MIDRlr 62D55Kq8kLcsD+wCHlUgLBcP+Tfh9nl+awh6eHPk+h3KrxjLTEvOmOVAh J+eBb4GaiolhwDR+YO29n8Kw6j1eCS5r+1zGlQ7C7gsXEC2IztxZRZNOY 49nnVX3rUkgWFwYl7nYHRgr4nwYTrFIog3OFZV4t1Lq/NByTmgv0fHnzg nQw8Mdxp0nnPNxk9RNjUIDFd8zhGI810XS8cz6FFRGUtngu/fG7BsXXio w==; X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="369249823" X-IronPort-AV: E=Sophos;i="6.03,288,1694761200"; d="scan'208";a="369249823" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 21:03:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,288,1694761200"; d="scan'208";a="4425719" Received: from ssid-ilbpg3-teeminta.png.intel.com ([10.88.227.74]) by orviesa002.jf.intel.com with ESMTP; 08 Nov 2023 21:03:55 -0800 From: Gan Yi Fang To: Alexandre Torgue , Jose Abreu , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Russell King , Joakim Zhang , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Looi Hong Aun , Voon Weifeng , Song Yoong Siang , Gan Yi Fang Subject: [PATCH net 1/1] net: stmmac: fix MAC and phylink mismatch issue after resume with STMMAC_FLAG_USE_PHY_WOL enabled Date: Thu, 9 Nov 2023 13:00:27 +0800 Message-Id: <20231109050027.2545000-1-yi.fang.gan@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 08 Nov 2023 21:04:16 -0800 (PST) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 lipwig.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782061474235203367 X-GMAIL-MSGID: 1782061474235203367 From: "Gan, Yi Fang" The issue happened when flag STMMAC_FLAG_USE_PHY_WOL is enabled. It can be reproduced with steps below: 1. Advertise only one speed on the host 2. Enable the WoL on the host 3. Suspend the host 4. Wake up the host When the WoL is disabled, both the PHY and MAC will suspend and wake up with everything configured well. When WoL is enabled, the PHY needs to be stay awake to receive the signal from remote client but MAC will enter suspend mode. When the MAC resumes from suspend, phylink_resume() will call phylink_start() to start the phylink instance which will trigger the phylink machine to invoke the mac_link_up callback function. The stmmac_mac_link_up() will configure the MAC_CTRL_REG based on the current link state. Then the stmmac_hw_setup() will be called to configure the MAC. This sequence might cause mismatch of the link state between MAC and phylink. This patch moves the phylink_resume() after stmamc_hw_setup() to ensure the MAC is initialized before phylink is being configured. As phylink_resume() is called all the time, refactor the code and remove the redundant check. Fixes: 90702dcd19c0 ("net: stmmac: fix MAC not working when system resume back with WoL active") Cc: # 5.15+ Signed-off-by: Gan, Yi Fang --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 3e50fd53a617..9b009fa5478f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -7844,16 +7844,6 @@ int stmmac_resume(struct device *dev) return ret; } - rtnl_lock(); - if (device_may_wakeup(priv->device) && priv->plat->pmt) { - phylink_resume(priv->phylink); - } else { - phylink_resume(priv->phylink); - if (device_may_wakeup(priv->device)) - phylink_speed_up(priv->phylink); - } - rtnl_unlock(); - rtnl_lock(); mutex_lock(&priv->lock); @@ -7868,6 +7858,11 @@ int stmmac_resume(struct device *dev) stmmac_restore_hw_vlan_rx_fltr(priv, ndev, priv->hw); + phylink_resume(priv->phylink); + + if (device_may_wakeup(priv->device) && !(priv->plat->pmt)) + phylink_speed_up(priv->phylink); + stmmac_enable_all_queues(priv); stmmac_enable_all_dma_irq(priv);