All of lore.kernel.org
 help / color / mirror / Atom feed
From: Doug Berger <opendmb@gmail.com>
To: f.fainelli@gmail.com
Cc: robh+dt@kernel.org, mark.rutland@arm.com, davem@davemloft.net,
	rafal@milecki.pl, xow@google.com, joel@jms.id.au,
	jon.mason@broadcom.com, netdev@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	pgynther@google.com, jaedon.shin@gmail.com,
	Doug Berger <opendmb@gmail.com>
Subject: [PATCH net-next 03/12] net: bcmgenet: simplify circular pointer arithmetic
Date: Mon, 13 Mar 2017 17:41:33 -0700	[thread overview]
Message-ID: <20170314004142.4746-4-opendmb@gmail.com> (raw)
In-Reply-To: <20170314004142.4746-1-opendmb@gmail.com>

A 2's complement subtraction will always do a borrow, so masking
off the sign bits is the same as conditionally adding (mask+1).

Signed-off-by: Doug Berger <opendmb@gmail.com>
---
 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index f92896835d2a..2c008b09c4e3 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -1,7 +1,7 @@
 /*
  * Broadcom GENET (Gigabit Ethernet) controller driver
  *
- * Copyright (c) 2014 Broadcom Corporation
+ * Copyright (c) 2014-2017 Broadcom
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -1175,13 +1175,9 @@ static unsigned int __bcmgenet_tx_reclaim(struct net_device *dev,
 	unsigned int txbds_processed = 0;
 
 	/* Compute how many buffers are transmitted since last xmit call */
-	c_index = bcmgenet_tdma_ring_readl(priv, ring->index, TDMA_CONS_INDEX);
-	c_index &= DMA_C_INDEX_MASK;
-
-	if (likely(c_index >= ring->c_index))
-		txbds_ready = c_index - ring->c_index;
-	else
-		txbds_ready = (DMA_C_INDEX_MASK + 1) - ring->c_index + c_index;
+	c_index = bcmgenet_tdma_ring_readl(priv, ring->index, TDMA_CONS_INDEX)
+		& DMA_C_INDEX_MASK;
+	txbds_ready = (c_index - ring->c_index) & DMA_C_INDEX_MASK;
 
 	netif_dbg(priv, tx_done, dev,
 		  "%s ring=%d old_c_index=%u c_index=%u txbds_ready=%u\n",
@@ -1611,12 +1607,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
 	}
 
 	p_index &= DMA_P_INDEX_MASK;
-
-	if (likely(p_index >= ring->c_index))
-		rxpkttoprocess = p_index - ring->c_index;
-	else
-		rxpkttoprocess = (DMA_C_INDEX_MASK + 1) - ring->c_index +
-				 p_index;
+	rxpkttoprocess = (p_index - ring->c_index) & DMA_C_INDEX_MASK;
 
 	netif_dbg(priv, rx_status, dev,
 		  "RDMA: rxpkttoprocess=%d\n", rxpkttoprocess);
-- 
2.11.1

  parent reply	other threads:[~2017-03-14  0:42 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-14  0:41 [PATCH net-next 00/12] net: bcmgenet: add support for GENETv5 Doug Berger
2017-03-14  0:41 ` Doug Berger
2017-03-14  0:41 ` [PATCH net-next 01/12] net: phy: bcm-phylib: replace obsolete EEE macro references Doug Berger
2017-03-14  0:49   ` Florian Fainelli
2017-03-14  0:49     ` Florian Fainelli
2017-03-14  0:41 ` [PATCH net-next 02/12] net: phy: bcm7xxx: add support for 28nm EPHY Doug Berger
2017-03-14  0:50   ` Florian Fainelli
2017-03-14  0:50     ` Florian Fainelli
2017-03-14  1:06   ` Andrew Lunn
2017-03-14  1:06     ` Andrew Lunn
2017-03-14  2:06     ` Doug Berger
2017-03-14  2:43       ` Andrew Lunn
2017-03-14  2:43         ` Andrew Lunn
2017-03-14 17:23         ` Doug Berger
2017-03-14 17:23           ` Doug Berger
2017-03-14  0:41 ` Doug Berger [this message]
2017-03-14  0:54   ` [PATCH net-next 03/12] net: bcmgenet: simplify circular pointer arithmetic Florian Fainelli
2017-03-14  0:54     ` Florian Fainelli
2017-03-14  0:41 ` [PATCH net-next 04/12] net: bcmgenet: remove meaningless lines Doug Berger
2017-03-14  0:55   ` Florian Fainelli
2017-03-14  0:55     ` Florian Fainelli
2017-03-14  0:41 ` [PATCH net-next 05/12] net: bcmgenet: manage dma interrupts in napi code Doug Berger
2017-03-14  0:55   ` Florian Fainelli
2017-03-14  0:41 ` [PATCH net-next 06/12] net: bcmgenet: remove handling of wol interrupts from isr0 Doug Berger
2017-03-14  0:41   ` Doug Berger
2017-03-14  0:56   ` Florian Fainelli
2017-03-14  0:56     ` Florian Fainelli
2017-03-14  0:41 ` [PATCH net-next 07/12] net: bcmgenet: clear status to reduce spurious interrupts Doug Berger
2017-03-14  0:56   ` Florian Fainelli
2017-03-14  0:56     ` Florian Fainelli
2017-03-14  0:41 ` [PATCH net-next 08/12] net: bcmgenet: correct return value of __bcmgenet_tx_reclaim Doug Berger
2017-03-14  0:57   ` Florian Fainelli
2017-03-14  0:41 ` [PATCH net-next 09/12] net: bcmgenet: return EOPNOTSUPP for unknown ioctl commands Doug Berger
2017-03-14  0:57   ` Florian Fainelli
2017-03-14 11:04   ` David Laight
2017-03-14 17:31     ` Doug Berger
2017-03-14  0:41 ` [PATCH net-next 10/12] dt-bindings: net: document bcmgenet WoL interrupt Doug Berger
2017-03-14  0:58   ` Florian Fainelli
2017-03-14  0:58     ` Florian Fainelli
2017-03-20 22:09   ` Rob Herring
2017-03-20 22:09     ` Rob Herring
2017-03-14  0:41 ` [PATCH net-next 11/12] dt-bindings: net: update bcmgenet binding for GENETv5 Doug Berger
2017-03-14  0:58   ` Florian Fainelli
2017-03-14  0:41 ` [PATCH net-next 12/12] net: bcmgenet: add support for the GENETv5 hardware Doug Berger
2017-03-14  0:59   ` Florian Fainelli
2017-03-14  0:59     ` Florian Fainelli
2017-03-14  4:53 ` [PATCH net-next 00/12] net: bcmgenet: add support for GENETv5 David Miller
2017-03-14  4:53   ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170314004142.4746-4-opendmb@gmail.com \
    --to=opendmb@gmail.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=jaedon.shin@gmail.com \
    --cc=joel@jms.id.au \
    --cc=jon.mason@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pgynther@google.com \
    --cc=rafal@milecki.pl \
    --cc=robh+dt@kernel.org \
    --cc=xow@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.