Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5308746ybl; Wed, 22 Jan 2020 14:27:07 -0800 (PST) X-Google-Smtp-Source: APXvYqw/sVfXLvTXhbHxgCrWZ0FCa9iDht+BzPZiNRZwIjSTRBqFylyICggB2LLbpRAzm13IPh8h X-Received: by 2002:a9d:3676:: with SMTP id w109mr9525755otb.35.1579732027784; 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=mO2rb1wivL9ATqoU8+qiuOG9NzCseMav4I/ENWWgIhorssLK7RAskuFJT06UiM3z/c E6YElkAMWzGb7jzMRraDBBgZLpZKl7Eomf26pLgT/Ss+VyZNBZxqSSSy0ebi0K6ySHlB tqlCtJsnmHeJj7o5bc/epSUxdlP0MrAtx8T9cHEQBTq1mXASr9HeGX29mbEBdsyrSnjZ LTztsPhpv3nkAAAp2iJWx7YcscNiFebJvFTvZQBR68ClWCefdrccv/1wP3Mp4osOY+YU pO2Be/R4Rq1Mxp0lOB4tpnqEuYVX9ygcgINhk4pkjhbId34WsfK4jY9lpX3YjdhbRi20 Omxw== 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=bmONbxCNzC0oo3mtNgfrjnUzkoO/BD7jEYypJRi3/5Y=; b=Kb4+MTgZssYW4R2T2n+G+aLScNqDHVYCqvpUgPTEkrjfvvDvTo/vO1lgqCK8tOVhy/ Z5nSO1/uEcBxu2tuyUU8QYfB+rCD3kX67//Ucf04POBdwKgMVBfTZ+vv6Hd7YCoEHJE3 kNoXpluQbu20oS90HyN6mQmbI4+FMCj21lUAmIaXMQKveFlVpf5YnNXATRWIUlNUEX62 ZkSxTZCb3Vrd0MY7H+4T+BehRyWRmKzmNtXVatASK3EDW42FCO2r8HLxpQQw0eAhB/Is MC8YGD0M+7XfmzGEHxtyPSya/UGaHBTiSAZH4VDncBIu3QvDhmqD1EeK74RxAn9DNStn fhmw== 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 b18si19908509oib.170.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 S1728765AbgAVWYD (ORCPT + 99 others); Wed, 22 Jan 2020 17:24:03 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47896 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbgAVWYC (ORCPT ); Wed, 22 Jan 2020 17:24:02 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 95746299BB; 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: <36024a80d3f0428430752ce1428b7dc3e6f19f9e.1579730846.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH net v3 06/12] net/sonic: Avoid needless receive descriptor EOL flag updates 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 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 c666bbf15116..2cee702f49b8 100644 --- a/drivers/net/ethernet/natsemi/sonic.c +++ b/drivers/net/ethernet/natsemi/sonic.c @@ -436,6 +436,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; @@ -516,13 +517,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