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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9B55C001DB for ; Thu, 3 Aug 2023 14:57:36 +0000 (UTC) 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) 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-Google-Smtp-Source: AGHT+IFpUmF3lOGna5OsFrZGINyKa+7kSVhPlDr16NTD/71Tbqjp6TL1O8whNtIBonLWEhbyK94EvA== 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 Content-Transfer-Encoding: 8bit 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 --- 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; -- 2.41.0