Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1950941ybl; Sun, 19 Jan 2020 15:18:17 -0800 (PST) X-Google-Smtp-Source: APXvYqzMWTsIPtYcsMpAA4rZaUzTt7TAxl+lSndA0h8XWfL6NO4fSlrN5v40ax6yQ42nHLMw3PuC X-Received: by 2002:a9d:7315:: with SMTP id e21mr14546553otk.255.1579475897551; Sun, 19 Jan 2020 15:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579475897; cv=none; d=google.com; s=arc-20160816; b=jSi+U5QXc83d0WR3HytTxSpRZPy4WUIAmVIPIyEdp7Y1gyr+wojlKAHoFdQV55maQW zL9lIwi9CxJ/99nSI0WkHVF68x0fi1c3wDladWoqKaLPrn6V6y7bOTAKRw9UDyZDKO53 y0LpEtlaUwd/wRBs4Xskx0Iy54aTh0oshD2f5fbc/6APW7MOz/Jd842+kqQGww8KRG+O LusQD0VjSUoJ3sn+519MEmIipOI/RaVlAA1mmxSjw7eADFwz9j0KWXfc/ZnPlBy7HpMR IyotEkWzvGyShtWnnRZOcF1/OBdXm2YYYwIU1foi+L41yUZA02+nKuVLU3/SrDSbmbPi Nv9w== 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=y3V2HoE6geUlPF9gSKXWlaVFLCWMXq+tAv+6hjcbwmE=; b=OYGsqv4ao5TbrijJ/FruhBucutiCsyPdFtCM6871azBllfdU4ldAR0zPkL3joYsMuM mIdI3xXXd6yox+Y7fF8Frt2983kPnKFsKA/1mfxWVFwR+7wo/2fu6Im9naqjwDqGcKK8 seWXKtus3H3eoiWFHZXKQNAqikXwgX5xaYXLtWZSGLQnwDFzIY8vtT05irCml4tXCN/7 cWkdeFV6/P3T34joLsNnbImdcjQT4tSKdbovO1gs0Etn7jEAO+Txdhpq7bnvdLyzfgIL 4pExHp7aW8fbhPbnuIhHASn8oFITjPr4ANTEG6uQRhJEM+PVtM1smCDZctX1rvmrdwt1 AjNg== 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 e20si16170314oig.199.2020.01.19.15.18.05; Sun, 19 Jan 2020 15:18:17 -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 S1729271AbgASXQ4 (ORCPT + 99 others); Sun, 19 Jan 2020 18:16:56 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:49800 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729047AbgASXQd (ORCPT ); Sun, 19 Jan 2020 18:16:33 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 8A1A8299A5; Sun, 19 Jan 2020 18:16:31 -0500 (EST) To: "David S. Miller" Cc: Thomas Bogendoerfer , Chris Zankel , Laurent Vivier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-Id: <2f7d911960c9e625f85f1563d8cbd9ab296e7209.1579474569.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH net 16/19] net/sonic: Quiesce SONIC before re-initializing descriptor memory Date: Mon, 20 Jan 2020 09:56:09 +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 --- drivers/net/ethernet/natsemi/sonic.c | 26 ++++++++++++++++++++++++++ drivers/net/ethernet/natsemi/sonic.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/drivers/net/ethernet/natsemi/sonic.c b/drivers/net/ethernet/natsemi/sonic.c index 343a8a7a6edf..b70470ce9c9c 100644 --- a/drivers/net/ethernet/natsemi/sonic.c +++ b/drivers/net/ethernet/natsemi/sonic.c @@ -150,6 +150,25 @@ 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 @@ -166,6 +185,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); @@ -205,6 +227,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); @@ -684,6 +709,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 61f253be92a0..e0d74ca9a77a 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