From patchwork Thu Aug 3 14:56:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryosuke Saito X-Patchwork-Id: 709595 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1675609ltf; Thu, 3 Aug 2023 07:57:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlF6HnntVVFhSdmCNTOfU6UQbe69CnPHPD4f4s8zJU2f+5gY/R6aWyD0rSYnYAICqVOw7QnN X-Received: by 2002:a5d:4bc4:0:b0:317:5b42:4264 with SMTP id l4-20020a5d4bc4000000b003175b424264mr7946033wrt.21.1691074656402; Thu, 03 Aug 2023 07:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691074656; cv=none; d=google.com; s=arc-20160816; b=Po65pFjQbB7tCJ7SmtzIFc4fcIoywhfbJ4ODn5BguIEsmpI3ZCZLm9zYmkuCwGCMVK BkM2oBEWVg+mDVZpd381rktUd72rgM658lXBvb7EVe53Nu4+OQXRnY73QqDFXDAIdmPz rGsZjWCABDm/ztm5GmcDQlskZ1MbtAi7CdH+/gsyfoMEbq49sBhBrBIta/UAQm4V5+8X CRsBSJ+ya/XYHFmiXxBFm4ulNM18R1Z4U0Y0hoXjzadpCzfjdvhkSMyA8inEMqdbrunz nSabJxhDWXrNQxxbqCfZEhJdzfDNBV3f+OWE83wBEqXGJIwNhoVUGaBQ00Y20UDrnbsj mTrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cpeZsGrhlNAGHQ7AVgk2O9nT9aCKw0yz9HITsom0hQc=; fh=H7kAERvUgUiO5yUYops8YZmxxhUUandgrV94Y9pWQfQ=; b=MUzQjLdASxmV2FycKFztizmETSysSjwETM+sGwSUtAk5HGl8WuiDKpefAWwHgD5Une QeVR4tKPfIRUINr7W1hUx9UYgn39f11X0Ru8ZteSVs4Dug/i4hJ+sB7/Eyen7617FJTT kmlg9XhVfe+rzQvfXOzzRbkfM2eb/7WYZax8J7Pi1So0/dnxiQ5OIvuqH2MKS5QQRMbT ynv637/BerT80GFqQMW7n4ok43rpQuTdnsdBMJgOg1n8e668fCdLYmL2BJnieirwGY1u Eeu0kO+sLTGAUEws6ZbifsLQFmSrQ+KJM0xw+LFY+NcbfW1Cqfvf+Xs/50LqE+C5ECnr GftQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LvtqF5nT; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id m5-20020adfe945000000b003143237ed61si16072wrn.424.2023.08.03.07.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:57:36 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LvtqF5nT; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E31DB868DC; Thu, 3 Aug 2023 16:57:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="LvtqF5nT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 08D9B867BC; Thu, 3 Aug 2023 16:57:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 97C1C867F7 for ; Thu, 3 Aug 2023 16:56:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ryosuke.saito@linaro.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b7dfb95761so1772305ad.1 for ; Thu, 03 Aug 2023 07:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691074615; x=1691679415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cpeZsGrhlNAGHQ7AVgk2O9nT9aCKw0yz9HITsom0hQc=; b=LvtqF5nTWbfXfO5PwI9rsh9JeiiPvnr1Yu++HpySVm2UT/Z0sv8JMMJOaG7233TB/3 u3B3HiVWgvlSHk4jokE2WdbRAccPocV0rJduawhSL1UYeBQzZpXBJLjKU/ITmrl08sKx iXl63BaYABED8ktm69nLVD28PdrKnND2Xlg7/0qsFrLbJC8fyKQhUg+/32eXUgg4xvhw ITjY7XJadx8MtVSUjZ31RIPYbfUD8NrrbaA4dYXVsefOIgFndqKQDlXdf5WTd2e6mZCd T/DEiXj5YnWSA8gpK/gqZ+tJGlLDUby80q5uZJf8WGHFjOJ2qprKua1QBuPpwIyzB+B7 +3UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691074615; x=1691679415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cpeZsGrhlNAGHQ7AVgk2O9nT9aCKw0yz9HITsom0hQc=; b=By13faur50fGKCVNi9pgA/1ewup7K0NolhjpNjUgNg/X2O/wmAH1Unv2VurqSOwe8R s218jCKZk5GJQfzikdskubx4NVTAYF257iVCL5DZ8waZHe1UJnVtcft2V9zSvFLz8akI VYoB0BvvrJMKzUrdWlam4zuhdqzSDhufeLwVu2+udDtuIgGTdnf7dB1YAEfaUjU8EBHQ gHSuTXpX5vb1hE4jtXUU59MeT1UW+5hNvDR7RlNnIz3g2VwlUDRFPvXdH+Os525t2HQh prHtvMuuyeSOOny9nBa/hhgiMpPg72NrLKo9wcuamYYhUMtFlAqI0daT7BQtuSyFrs2p xnTw== X-Gm-Message-State: AOJu0YwREBEtopIyVHbna+3lM3rfGX2qKaiaAgy+S9WGpOadONUUeVM5 QpgKgwyhXDIJ/MxnE6usd6PH6Q== X-Received: by 2002:a17:902:c947:b0:1bc:496c:8eda with SMTP id i7-20020a170902c94700b001bc496c8edamr598555pla.4.1691074614947; Thu, 03 Aug 2023 07:56:54 -0700 (PDT) Received: from fedora.. ([240d:1a:3a7:a400:9a57:aa11:487a:b54f]) by smtp.gmail.com with ESMTPSA id m1-20020a170902db0100b001b869410ed2sm14476842plx.72.2023.08.03.07.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 07:56:54 -0700 (PDT) From: Ryosuke Saito To: jaswinder.singh@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com Cc: masahisa.kojima@linaro.org, u-boot@lists.denx.de Subject: [PATCH 1/1] net: sni_netsec: Add workaround for timeout error Date: Thu, 3 Aug 2023 23:56:48 +0900 Message-ID: <20230803145648.1023981-2-ryosuke.saito@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803145648.1023981-1-ryosuke.saito@linaro.org> References: <20230803145648.1023981-1-ryosuke.saito@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 03 Aug 2023 16:57:26 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The NETSEC GMAC occasionally falls into a weird state where MAC_REG_DESC_SOFT_RST has never been cleared and shows errors like the below when networking commands are issued: => ping 192.168.1.1 ethernet@522d0000 Waiting for PHY auto negotiation to complete... done netsec_wait_while_busy: timeout Using ethernet@522d0000 device ARP Retry count exceeded; starting again ping failed; host 192.168.1.1 is not alive It happens on not only 'ping' but also 'dhcp', 'tftp' and so on. Luckily, restarting the NETSEC GMAC and trying again seems to fix the problematic state. So first ensure that we haven't entered the state by checking MAC_REG_DESC_SOFT_RST to be cleared; otherwise, restarting NETSEC/PHY and trying again would work as a workaround. Signed-off-by: Ryosuke Saito Tested-By: Masahisa Kojima --- drivers/net/sni_netsec.c | 50 ++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/drivers/net/sni_netsec.c b/drivers/net/sni_netsec.c index 9780f2092bd4..71afe78fd28a 100644 --- a/drivers/net/sni_netsec.c +++ b/drivers/net/sni_netsec.c @@ -286,6 +286,8 @@ struct netsec_rx_pkt_info { bool err_flag; }; +static int netsec_reset_hardware(struct netsec_priv *priv, bool load_ucode); + static void netsec_write_reg(struct netsec_priv *priv, u32 reg_addr, u32 val) { writel(val, priv->ioaddr + reg_addr); @@ -532,18 +534,11 @@ static int netsec_mac_update_to_phy_state(struct netsec_priv *priv) return 0; } -static int netsec_start_gmac(struct netsec_priv *priv) +static int netsec_reset_gmac(struct netsec_priv *priv) { u32 value = 0; int ret; - if (priv->max_speed != SPEED_1000) - value = (NETSEC_GMAC_MCR_REG_CST | - NETSEC_GMAC_MCR_REG_HALF_DUPLEX_COMMON); - - if (netsec_set_mac_reg(priv, GMAC_REG_MCR, value)) - return -ETIMEDOUT; - if (netsec_set_mac_reg(priv, GMAC_REG_BMR, NETSEC_GMAC_BMR_REG_RESET)) return -ETIMEDOUT; @@ -558,10 +553,47 @@ static int netsec_start_gmac(struct netsec_priv *priv) if (value & NETSEC_GMAC_BMR_REG_SWR) return -EAGAIN; + /** + * NETSEC GMAC sometimes shows the peculiar behaviour where + * MAC_REG_DESC_SOFT_RST never been cleared, resulting in the loss of + * sending packets. + * + * Workaround: + * Restart NETSEC and PHY, retry again. + */ netsec_write_reg(priv, MAC_REG_DESC_SOFT_RST, 1); - if (netsec_wait_while_busy(priv, MAC_REG_DESC_SOFT_RST, 1)) + udelay(1000); + if (netsec_read_reg(priv, MAC_REG_DESC_SOFT_RST)) { + phy_shutdown(priv->phydev); + netsec_reset_hardware(priv, false); + phy_startup(priv->phydev); + return -EAGAIN; + } + return 0; +} + +static int netsec_start_gmac(struct netsec_priv *priv) +{ + u32 value = 0; + u32 failure = 0; + int ret; + + if (priv->max_speed != SPEED_1000) + value = (NETSEC_GMAC_MCR_REG_CST | + NETSEC_GMAC_MCR_REG_HALF_DUPLEX_COMMON); + + if (netsec_set_mac_reg(priv, GMAC_REG_MCR, value)) return -ETIMEDOUT; + /* Reset GMAC */ + while ((ret = netsec_reset_gmac(priv)) == -EAGAIN && ++failure < 3) + ; + + if (ret) { + pr_err("%s: failed to reset gmac(err=%d).\n", __func__, ret); + return ret; + } + netsec_write_reg(priv, MAC_REG_DESC_INIT, 1); if (netsec_wait_while_busy(priv, MAC_REG_DESC_INIT, 1)) return -ETIMEDOUT;