Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5308737ybl; Wed, 22 Jan 2020 14:27:07 -0800 (PST) X-Google-Smtp-Source: APXvYqwR1aX5LyVkGcWJW/iriOaS8pvBIBMd+P6/Ak/rEIyg7zohpgEtRL9zaI9Le8aPCP5RlnVE X-Received: by 2002:a9d:7c90:: with SMTP id q16mr9307414otn.191.1579732027197; Wed, 22 Jan 2020 14:27:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579732027; cv=none; d=google.com; s=arc-20160816; b=E/k7pEkSDA3T0xm4Hvg6gO3pPCxOPio0t9fwe2mh7UHoAjgoWx88l5dYMuJLzRY2E1 TolvQHVvpRFR1GlS1s4fv2gXWutlQTsg+vpSHnCFgQsi/UM8G3ZgI513K+UEB5IP/fi2 OCpCSKVbhw+fmWYwG4v8GBeZkgD999C3Ovu7Jhk6kX5/KvwE2rXK7dD8rndsQOAm9zGn Rh1PfNEKR2BvLM1bepRKeITlScAOBTahZE0mdjTBwSSpMnTExbNmA5EsH/F70f7dRIPy BYXeEWDJZ/Rbp6BDIbV9IGaFeD+U1ZCHbiIFio/WMAMX0wpA1FOcAFPb8Z7+t5rY9HdA pW0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:from:references:in-reply-to :message-id:cc:to; bh=bFsfwun3wObxyaGkoTQejhyBT0vd3wqL/ToIHt6n2FA=; b=gI1ycGDJGR9qv6jJBbFmj3VuKesmVMwfujSDfzRFVcScj80bz9IUylg3bveklgWvgQ 37wL1HQTga4ZJzvwlzvpPMAvPdW+Jjoae6dXiwwG1UtFtaVktcAcEjSso6h3wO7CyGTw 0btNUUG6p5bVfQtZnIS1s0E9kppISt3vuIObz4bzU37FisapUHb4aCQs1XXIjaY5t8k6 JYKlAk2teiv+4N9OY8w0njjM6IYzl8k2hmG0S/0Kg0+crsLBqpLm29YBRFF/yZEiFNeU g3uSNANxtTICog8Im1YkL9HAeUFBLF7xxV+LbmU5sDO2Uh/CGFNiqb30+1+YXX/n1SAx ByDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i13si68307oth.175.2020.01.22.14.26.55; Wed, 22 Jan 2020 14:27:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729154AbgAVWYj (ORCPT + 99 others); Wed, 22 Jan 2020 17:24:39 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47912 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbgAVWYD (ORCPT ); Wed, 22 Jan 2020 17:24:03 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id DDCB4299C0; Wed, 22 Jan 2020 17:23:59 -0500 (EST) To: "David S. Miller" Cc: Thomas Bogendoerfer , Chris Zankel , Laurent Vivier , Geert Uytterhoeven , Eric Dumazet , Stephen Hemminger , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-Id: <1b839d1752b28d3ee4089371577562c7211e59d4.1579730846.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH net v3 09/12] net/sonic: Quiesce SONIC before re-initializing descriptor memory Date: Thu, 23 Jan 2020 09:07:26 +1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changed since v2: - Removed blank line. --- drivers/net/ethernet/natsemi/sonic.c | 25 +++++++++++++++++++++++++ drivers/net/ethernet/natsemi/sonic.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/drivers/net/ethernet/natsemi/sonic.c b/drivers/net/ethernet/natsemi/sonic.c index 26848acec63d..42a6b87d8886 100644 --- a/drivers/net/ethernet/natsemi/sonic.c +++ b/drivers/net/ethernet/natsemi/sonic.c @@ -116,6 +116,24 @@ static int sonic_open(struct net_device *dev) 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 @@ -132,6 +150,9 @@ static int sonic_close(struct net_device *dev) /* * 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); @@ -171,6 +192,9 @@ static void sonic_tx_timeout(struct net_device *dev) * 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); @@ -658,6 +682,7 @@ static int sonic_init(struct net_device *dev) */ SONIC_WRITE(SONIC_CMD, 0); SONIC_WRITE(SONIC_CMD, SONIC_CR_RXDIS); + sonic_quiesce(dev, SONIC_CR_ALL); /* * initialize the receive resource area diff --git a/drivers/net/ethernet/natsemi/sonic.h b/drivers/net/ethernet/natsemi/sonic.h index cc2f7b4b77e3..1df6d2f06cc4 100644 --- a/drivers/net/ethernet/natsemi/sonic.h +++ b/drivers/net/ethernet/natsemi/sonic.h @@ -110,6 +110,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 */ -- 2.24.1