From patchwork Mon Feb 8 14:08:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 12075687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 707CCC433DB for ; Mon, 8 Feb 2021 14:19:47 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2078F64E2E for ; Mon, 8 Feb 2021 14:19:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2078F64E2E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baikalelectronics.ru Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qpObNScQTky/jHY4buaybjggz4ZlKlukiNcvBGID3C8=; b=DSHbXBGIWO/rni8Oj77tncuzr jcr3DhGgp540NyTk8Cl90qIbvbUWzHnXbQT9FPMcqZZNvxszqtLsl6L5PNLNi9dLYwYzTocDsrv76 hirfXhS3mydnKERiCmHAwHsP4F1CRHl3sjI3uqVSzd/TCuWZOTnomqUZCo0dV5Nx9f977ZuDNlUWj V6yet5cH8fPixETKzWrFDAs6iDY6l/hrM+PCqTby/7sYMRBxMm1Fdhs78xieFfzS1OhWFFtapah1/ xUt3nIgKySrlZ0cdKWA8QmQ9ZslMzGh/f9xUQLh+GUQhSwDtdROsAuGv2tqqyh6xrBuzvgca5DKQS zg/rD/SWQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l97Mf-0001ti-Ro; Mon, 08 Feb 2021 14:18:10 +0000 Received: from mail.baikalelectronics.com ([87.245.175.226] helo=mail.baikalelectronics.ru) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l97DP-0005JQ-Cj for linux-arm-kernel@lists.infradead.org; Mon, 08 Feb 2021 14:08:44 +0000 From: Serge Semin To: Rob Herring , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Maxime Coquelin Subject: [PATCH 12/16] net: stmmac: Introduce NIC software reset function Date: Mon, 8 Feb 2021 17:08:16 +0300 Message-ID: <20210208140820.10410-13-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20210208140820.10410-1-Sergey.Semin@baikalelectronics.ru> References: <20210208140820.10410-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210208_090835_694549_B4BD39F2 X-CRM114-Status: GOOD ( 13.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Serge Semin , Alexey Malahov , Serge Semin , Vyacheslav Mitrofanov , Pavel Parkhomenko , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since we are about to move the IRQs handler setup into the device probe method, the DW MAC reset procedure needs to be redefined to be performed with care. We must make sure the IRQs handler isn't executed while the reset is proceeded and the IRQs are fully masked after that. The later is required for some early versions of DW GMAC (in our case it's DW GMAC v3.73a). Signed-off-by: Serge Semin --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index b37f49f3dc03..c4c41b554c6a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1827,6 +1827,34 @@ static void free_dma_desc_resources(struct stmmac_priv *priv) free_dma_tx_desc_resources(priv); } +/** + * stmmac_sw_reset - reset the MAC/DMA/etc state + * @priv: driver private structure + * Description: Cleanup/reset the DW *MAC registers to their initial state. + */ +static int stmmac_sw_reset(struct stmmac_priv *priv) +{ + int ret; + + /* Disable the IRQ signal while the reset is in progress so not to + * interfere with what the main ISR is doing. + */ + disable_irq(priv->dev->irq); + + ret = stmmac_reset(priv, priv->ioaddr); + + /* Make sure all IRQs are disabled by default. Some DW MAC IP-cores + * like early versions of DW GMAC have MAC and MMC interrupts enabled + * after reset. + */ + if (!ret) + stmmac_disable_irq(priv); + + enable_irq(priv->dev->irq); + + return ret; +} + /** * stmmac_mac_enable_rx_queues - Enable MAC rx queues * @priv: driver private structure @@ -2340,9 +2368,9 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv) if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE)) atds = 1; - ret = stmmac_reset(priv, priv->ioaddr); + ret = stmmac_sw_reset(priv); if (ret) { - dev_err(priv->device, "Failed to reset the dma\n"); + dev_err(priv->device, "Failed to reset the core\n"); return ret; }