Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2335320ybz; Thu, 23 Apr 2020 16:14:48 -0700 (PDT) X-Google-Smtp-Source: APiQypLZnPA0CAnuUwn3vMgguD0JymVcYQlqQY1fUL7w6uSWYanok+aSc23vCNQkkm+QpC3EmoRG X-Received: by 2002:a05:6402:17f1:: with SMTP id t17mr4921596edy.239.1587683688071; Thu, 23 Apr 2020 16:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587683688; cv=none; d=google.com; s=arc-20160816; b=0j3/1YRirT+vjuZyGSfgLfPj6S4PaC5vsQ0ZRVIRbMNFK3w8IDGHjfYGUDf1j5wEwi Yka8ztYhQw1xlFga1DXC7koFSrMg0SrlcTbokAuhKTxRCbeCoVm0dqhs52UmsLs2WI00 Csy8vfAF/Z4w/b16G4ZGYRA8MnLX5fzLjkYNkEv8NqDFqU+uA/zEmFpgA2nzVEMjCCXN nF3qeQdK0Ag7V6h0j0baRZ0jIdvlhlhtMF4w1QO5vcu0oi4poMrEBUjQN+5X9ryJAKl3 Oed1yIdd6kiQXt76W84xgVbXFy1kUAcHVVUTBIjXkegROvB2iVIVP6yImpz8pixZA7xn z6+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=3o5ud1ydxgHb+vrCVik5LGzfX69lMrYMZtNPYfex6q8=; b=c3saTFWHlHDJzSwtJFSfzA3jfwhDpiqCK7V46Wg6XlLt55u4+A1P0JYMnOJ9Qo7zQ9 oScuCSi0iTYsWL5rRipTv5nrSuS5cWd/Tx1JpsxKDyfgHVjpFYZhjAM3iA7AAfrMnRcN c3uJJIalfBPpoPN3/cVsR0QgiePhQvaX0il7/HDrIhLy2Umsc26LvMqXC5mbjE96nLZ6 XNmCkC/RRXoSX2fqU6A5R193cfnEQox2WuqFngOnlwHIKchmvodxgkqbohodXKXjvkgf kbAKz3gQaRx8CCvmrYPc+dH+tIAj39BKWLDowgWmd45P51tCfSIECCN/y/wOkT5hN+2p NOog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si2013338edv.534.2020.04.23.16.14.24; Thu, 23 Apr 2020 16:14:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728001AbgDWXLq (ORCPT + 99 others); Thu, 23 Apr 2020 19:11:46 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50222 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728551AbgDWXGw (ORCPT ); Thu, 23 Apr 2020 19:06:52 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvd-0004lu-0Z; Fri, 24 Apr 2020 00:06:45 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvY-00E6yr-Sa; Fri, 24 Apr 2020 00:06:40 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Finn Thain" , "Stan Johnson" , "David S. Miller" Date: Fri, 24 Apr 2020 00:07:13 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 206/245] net/sonic: Quiesce SONIC before re-initializing descriptor memory In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Finn Thain commit 3f4b7e6a2be982fd8820a2b54d46dd9c351db899 upstream. Make sure the SONIC's DMA engine is idle before altering the transmit and receive descriptors. Add a helper for this as it will be needed again. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Tested-by: Stan Johnson Signed-off-by: Finn Thain Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings --- drivers/net/ethernet/natsemi/sonic.c | 25 +++++++++++++++++++++++++ drivers/net/ethernet/natsemi/sonic.h | 3 +++ 2 files changed, 28 insertions(+) --- a/drivers/net/ethernet/natsemi/sonic.c +++ b/drivers/net/ethernet/natsemi/sonic.c @@ -103,6 +103,24 @@ static int sonic_open(struct net_device return 0; } +/* Wait for the SONIC to become idle. */ +static void sonic_quiesce(struct net_device *dev, u16 mask) +{ + struct sonic_local * __maybe_unused lp = netdev_priv(dev); + int i; + u16 bits; + + for (i = 0; i < 1000; ++i) { + bits = SONIC_READ(SONIC_CMD) & mask; + if (!bits) + return; + if (irqs_disabled() || in_interrupt()) + udelay(20); + else + usleep_range(100, 200); + } + WARN_ONCE(1, "command deadline expired! 0x%04x\n", bits); +} /* * Close the SONIC device @@ -120,6 +138,9 @@ static int sonic_close(struct net_device /* * stop the SONIC, disable interrupts */ + SONIC_WRITE(SONIC_CMD, SONIC_CR_RXDIS); + sonic_quiesce(dev, SONIC_CR_ALL); + SONIC_WRITE(SONIC_IMR, 0); SONIC_WRITE(SONIC_ISR, 0x7fff); SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); @@ -159,6 +180,9 @@ static void sonic_tx_timeout(struct net_ * put the Sonic into software-reset mode and * disable all interrupts before releasing DMA buffers */ + SONIC_WRITE(SONIC_CMD, SONIC_CR_RXDIS); + sonic_quiesce(dev, SONIC_CR_ALL); + SONIC_WRITE(SONIC_IMR, 0); SONIC_WRITE(SONIC_ISR, 0x7fff); SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); @@ -638,6 +662,7 @@ static int sonic_init(struct net_device */ SONIC_WRITE(SONIC_CMD, 0); SONIC_WRITE(SONIC_CMD, SONIC_CR_RXDIS); + sonic_quiesce(dev, SONIC_CR_ALL); /* * initialize the receive resource area --- a/drivers/net/ethernet/natsemi/sonic.h +++ b/drivers/net/ethernet/natsemi/sonic.h @@ -109,6 +109,9 @@ #define SONIC_CR_TXP 0x0002 #define SONIC_CR_HTX 0x0001 +#define SONIC_CR_ALL (SONIC_CR_LCAM | SONIC_CR_RRRA | \ + SONIC_CR_RXEN | SONIC_CR_TXP) + /* * SONIC data configuration bits */