From patchwork Wed Aug 24 20:34:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12953956 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 7E8C1C04AA5 for ; Wed, 24 Aug 2022 20:36:22 +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:Subject:Cc:To:From:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=IsUOxHWWqCQuIIXk9xcgxgcJQTJkUCEBSyfhSdIV2XM=; b=qaP2eZLXghj+hN z7+xoh0iKcrSfpKed1URtgFSqp/sklRuh3FRoARgdU0rgsp5L0q7gui2UreKuPp6Yvuo66QRkVSuE Wn0c1F9b8W737uJsou0pwIRrlo0MLNGnfLrmDWXY1vZEO03fk+o//l5qgxz3WysvfcXUCnnOgDN+O eNCuKcIaA+SUOZD+KJtXPDypSInCIcuo/Hcf199+J7ZJaMP27swoWLw9kMXOD7N5/qQKRBUdFo+4e mZ3Rfjep1NUtCuFPyXV6l3zdNn66f/AszlJEA1auB3ptEbv/EpoTLcP9j0YIZO8vo/oNe+LWAHwqN tTWiMr2SNYM5Ra+FgLrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQx5c-00Ge6t-Mn; Wed, 24 Aug 2022 20:35:04 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQx5Z-00Ge27-AW for linux-arm-kernel@lists.infradead.org; Wed, 24 Aug 2022 20:35:02 +0000 Received: by mail-wr1-x42e.google.com with SMTP id bs25so22174261wrb.2 for ; Wed, 24 Aug 2022 13:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:subject:content-language:cc:to:from :user-agent:mime-version:date:message-id:from:to:cc; bh=POi4hFc+gT1EkX4nPsQgNWfQX18l5gCV7T3rOCIonGM=; b=FZ+Xf1MRzXvpmhNHqPc2EePKUbklI/0FZjUYDen+1mw5aNhAu/hpI2e8k2vh0TG8IY 99/skphyC+XLZ0YaeZt7yfVhMMiu8+VkrUd8rEeRwtMloH6C7Zik2h6R1ZCQjnKLLxiU mkY98XkjXamZiLpQ8S5z4opJT1BtcSJfwXZEWR6Hu8FszhwlKH9ES1lIXKn8WEyhIKC5 PF9+F13olVYZy3zFTe8KI1232uAfkovKKKxpGGszEsqJy1VCvWYiY59I9ECTQCgNwJIE fLmoapu/GeqmOBqJrv3oaDz6S16DPH7JqSIx9AxKvD+Z6Sg0C4Js2nIcv81lJIBeKqJ6 mFMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:content-language:cc:to:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc; bh=POi4hFc+gT1EkX4nPsQgNWfQX18l5gCV7T3rOCIonGM=; b=HkPKXYWmb+7zLoLVw4aERtkMcfVvQPh8awSEbBP9nvtnOPqs50m1B/181WCyr7VcTG qkSASdnmzUnnhGdjHRr7gr33YQGio7QMmtq2dzKwz8KQUujcl4IC802uSY4FHZeK1vq2 7F8l+i5bfIJwt5suXKnxwUu6EeUUXdmpLOZ+DS3rwUZkgs9uAkBE6NpVSrzLC8jJuxJB VNeYCmqmCWwrNc1tvWAeYg82rIzjjtkvqtLITVilGt+KajSx8MRFgRL4ejxStmSnx4EG DVE8ec0PmVI+KIxBgMJj3MPMPXseHstI4Nn3eOXIFa4hB5X7zy7f6LSbQ8dbb4QxGY/3 sTrA== X-Gm-Message-State: ACgBeo0VbbSJpvErqZKveY8s8FkUyVk+oFv90maxheY87w0GL2GDK75E aKoR3q72kYJ7mpKWpxEevQs= X-Google-Smtp-Source: AA6agR7/fqfPu8mLXwbFrXsWyggUliREN5FH5jjzxB3kXibRHkWwoPpvxXHT0f+TYoAHRZIdcBdOQw== X-Received: by 2002:adf:f74b:0:b0:225:1fdb:a787 with SMTP id z11-20020adff74b000000b002251fdba787mr464018wrp.33.1661373297511; Wed, 24 Aug 2022 13:34:57 -0700 (PDT) Received: from ?IPV6:2a01:c22:7aa2:100:8857:e17a:56:c2b2? (dynamic-2a01-0c22-7aa2-0100-8857-e17a-0056-c2b2.c22.pool.telefonica.de. [2a01:c22:7aa2:100:8857:e17a:56:c2b2]) by smtp.googlemail.com with ESMTPSA id k6-20020a5d6d46000000b00225221fd286sm17844759wri.114.2022.08.24.13.34.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Aug 2022 13:34:56 -0700 (PDT) Message-ID: Date: Wed, 24 Aug 2022 22:34:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 From: Heiner Kallweit To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin Cc: "netdev@vger.kernel.org" , "moderated list:ARM/STM32 ARCHITECTURE" , "linux-arm-kernel@lists.infradead.org" , Qi Duan , Da Xue , Jerome Brunet , rayagond@vayavyalabs.com, Giuseppe Cavallaro Content-Language: en-US Subject: [PATCH v2 net] net: stmmac: work around sporadic tx issue on link-up X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220824_133501_400841_F422B480 X-CRM114-Status: GOOD ( 14.72 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a follow-up to the discussion in [0]. It seems to me that at least the IP version used on Amlogic SoC's sometimes has a problem if register MAC_CTRL_REG is written whilst the chip is still processing a previous write. But that's just a guess. Adding a delay between two writes to this register helps, but we can also simply omit the offending second write. This patch uses the second approach and is based on a suggestion from Qi Duan. Benefit of this approach is that we can save few register writes, also on not affected chip versions. [0] https://www.spinics.net/lists/netdev/msg831526.html v2: - change Fixes tag to the commmit that added stmmac_set_mac() 11yrs ago Fixes: bfab27a146ed ("stmmac: add the experimental PCI support") Suggested-by: Qi Duan Suggested-by: Jerome Brunet Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c | 8 ++++++-- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c index caa4bfc4c..9b6138b11 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c @@ -258,14 +258,18 @@ EXPORT_SYMBOL_GPL(stmmac_set_mac_addr); /* Enable disable MAC RX/TX */ void stmmac_set_mac(void __iomem *ioaddr, bool enable) { - u32 value = readl(ioaddr + MAC_CTRL_REG); + u32 old_val, value; + + old_val = readl(ioaddr + MAC_CTRL_REG); + value = old_val; if (enable) value |= MAC_ENABLE_RX | MAC_ENABLE_TX; else value &= ~(MAC_ENABLE_TX | MAC_ENABLE_RX); - writel(value, ioaddr + MAC_CTRL_REG); + if (value != old_val) + writel(value, ioaddr + MAC_CTRL_REG); } void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 070b5ef16..592d29abc 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -986,10 +986,10 @@ static void stmmac_mac_link_up(struct phylink_config *config, bool tx_pause, bool rx_pause) { struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); - u32 ctrl; + u32 old_ctrl, ctrl; - ctrl = readl(priv->ioaddr + MAC_CTRL_REG); - ctrl &= ~priv->hw->link.speed_mask; + old_ctrl = readl(priv->ioaddr + MAC_CTRL_REG); + ctrl = old_ctrl & ~priv->hw->link.speed_mask; if (interface == PHY_INTERFACE_MODE_USXGMII) { switch (speed) { @@ -1064,7 +1064,8 @@ static void stmmac_mac_link_up(struct phylink_config *config, if (tx_pause && rx_pause) stmmac_mac_flow_ctrl(priv, duplex); - writel(ctrl, priv->ioaddr + MAC_CTRL_REG); + if (ctrl != old_ctrl) + writel(ctrl, priv->ioaddr + MAC_CTRL_REG); stmmac_mac_set(priv, priv->ioaddr, true); if (phy && priv->dma_cap.eee) {