Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4163662ybl; Tue, 21 Jan 2020 14:12:51 -0800 (PST) X-Google-Smtp-Source: APXvYqxKsArDULj4KruiFApG5sloYFW8TPWnHnLpctx6dnJQwFvN5j4tt9B4m2douQzp6WVayPxI X-Received: by 2002:a9d:7f11:: with SMTP id j17mr5393088otq.281.1579644771117; Tue, 21 Jan 2020 14:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579644771; cv=none; d=google.com; s=arc-20160816; b=Ycqz78exKeZuZCTIYLPRgg+ye4zm8oyEQ6BPBnnKndZFc0zNvWYp9CZXAW8jVr9ok4 hJxxYhMHPe04FqCqbgPuyqn69dcKKOdFOt9TO8RQNNwfO4mMenHmFT3hI/fNoGRzxJ6c bY4/TOP+gHx7YVptPeIWTTPPRJBslbUchYKhYq9CLJqAvucNm5ZTh7z+2fjzYnAxtZ/k 1qo8VBozaV56RRTegkUZzN1tE/uvpDIpyUYFJ85WoWU2r5WeZv5Ljk6QpiGrz89eP7vM zdUE8KMmtTErGx52Utny0BTaLQ/sA/buocAUAWpqID4USKfV4sg+LginzDTVwQWrTaf/ B2eg== 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=Qs4aIcl8N8V7d9L+U00k73j1Qo+UNvTiWM6AAIHaeKg=; b=JEsKG1Fx7Y8X+79/AgJZe9H6VU1rfk3btdSqJ99uoaJOk4FORqmM0dIq60rLH8Ehl8 YHWlhXaO5O41mKMpD53QIXOhDYpEJm1l4nGNUYuiXQWAKxulCjwtP4+PlreYFiY6d88F 6nMxFKtQUyiolLuawsEKR81jowUmDZZDyvxazyi2caCNmkJASNp8otE9o/kctYRgSXVm DdeMx+Cndfc3Pc5oS5G5rEEAzlIgVyuUgt011JFT1VaTxfQKnwETuERUS8OVqI+s9jW0 tnHxtHrXDKLul6e4B/7ddFNbsmb3RSzHV4OnsWVmWXmjXlO59jhW6z/7SmYth4bwRsCh mkEA== 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 t82si20757393oif.45.2020.01.21.14.12.39; Tue, 21 Jan 2020 14:12:51 -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 S1729475AbgAUWLX (ORCPT + 99 others); Tue, 21 Jan 2020 17:11:23 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:44792 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729064AbgAUWKh (ORCPT ); Tue, 21 Jan 2020 17:10:37 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 5C724299A4; Tue, 21 Jan 2020 17:10:36 -0500 (EST) To: "David S. Miller" Cc: Thomas Bogendoerfer , Chris Zankel , Laurent Vivier , Geert Uytterhoeven , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-Id: <960febac5aedee833195d0270ca1cde5d81a5d43.1579641728.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH net v2 06/12] net/sonic: Avoid needless receive descriptor EOL flag updates Date: Wed, 22 Jan 2020 08:22:08 +1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The while loop in sonic_rx() traverses the rx descriptor ring. It stops when it reaches a descriptor that the SONIC has not used. Each iteration advances the EOL flag so the SONIC can keep using more descriptors. Therefore, the while loop has no definite termination condition. The algorithm described in the National Semiconductor literature is quite different. It consumes descriptors up to the one with its EOL flag set (which will also have its "in use" flag set). All freed descriptors are then returned to the ring at once, by adjusting the EOL flags (and link pointers). Adopt the algorithm from datasheet as it's simpler, terminates quickly and avoids a lot of pointless descriptor EOL flag changes. Fixes: efcce839360f ("[PATCH] macsonic/jazzsonic network drivers update") Tested-by: Stan Johnson Signed-off-by: Finn Thain --- drivers/net/ethernet/natsemi/sonic.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/natsemi/sonic.c b/drivers/net/ethernet/natsemi/sonic.c index 3387f7bc1a80..431a6e46c08c 100644 --- a/drivers/net/ethernet/natsemi/sonic.c +++ b/drivers/net/ethernet/natsemi/sonic.c @@ -432,6 +432,7 @@ static void sonic_rx(struct net_device *dev) struct sonic_local *lp = netdev_priv(dev); int status; int entry = lp->cur_rx; + int prev_entry = lp->eol_rx; while (sonic_rda_get(dev, entry, SONIC_RD_IN_USE) == 0) { struct sk_buff *used_skb; @@ -512,13 +513,21 @@ static void sonic_rx(struct net_device *dev) /* * give back the descriptor */ - sonic_rda_put(dev, entry, SONIC_RD_LINK, - sonic_rda_get(dev, entry, SONIC_RD_LINK) | SONIC_EOL); sonic_rda_put(dev, entry, SONIC_RD_IN_USE, 1); - sonic_rda_put(dev, lp->eol_rx, SONIC_RD_LINK, - sonic_rda_get(dev, lp->eol_rx, SONIC_RD_LINK) & ~SONIC_EOL); - lp->eol_rx = entry; - lp->cur_rx = entry = (entry + 1) & SONIC_RDS_MASK; + + prev_entry = entry; + entry = (entry + 1) & SONIC_RDS_MASK; + } + + lp->cur_rx = entry; + + if (prev_entry != lp->eol_rx) { + /* Advance the EOL flag to put descriptors back into service */ + sonic_rda_put(dev, prev_entry, SONIC_RD_LINK, SONIC_EOL | + sonic_rda_get(dev, prev_entry, SONIC_RD_LINK)); + sonic_rda_put(dev, lp->eol_rx, SONIC_RD_LINK, ~SONIC_EOL & + sonic_rda_get(dev, lp->eol_rx, SONIC_RD_LINK)); + lp->eol_rx = prev_entry; } /* * If any worth-while packets have been received, netif_rx() -- 2.24.1