mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/6] net: fsl-fman: Store index for txbd
Date: Thu, 14 Nov 2019 14:00:17 +0100	[thread overview]
Message-ID: <20191114130021.1029-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20191114130021.1029-1-s.hauer@pengutronix.de>

Instead of storing a pointer to the current txbd store the index of the
current buffer. This makes the code more straight forward.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fsl-fman.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index 287a891a63..b5d617212e 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -107,8 +107,8 @@ struct fm_eth {
 	void *rx_bd_ring;		/* Rx BD ring base */
 	void *cur_rxbd;			/* current Rx BD */
 	void *rx_buf;			/* Rx buffer base */
-	void *tx_bd_ring;		/* Tx BD ring base */
-	void *cur_txbd;			/* current Tx BD */
+	struct fm_port_bd *tx_bd_ring;	/* Tx BD ring base */
+	int cur_txbd_idx;		/* current Tx BD index */
 	struct memac *regs;
 };
 
@@ -702,16 +702,16 @@ static int fm_eth_tx_port_parameter_init(struct fm_eth *fm_eth)
 			* TX_BD_RING_SIZE);
 	/* save it to fm_eth */
 	fm_eth->tx_bd_ring = tx_bd_ring_base;
-	fm_eth->cur_txbd = tx_bd_ring_base;
+	fm_eth->cur_txbd_idx = 0;
 
 	/* init Tx BDs ring */
-	txbd = tx_bd_ring_base;
 	for (i = 0; i < TX_BD_RING_SIZE; i++) {
+		txbd = &fm_eth->tx_bd_ring[i];
+
 		muram_writew(&txbd->status, TxBD_LAST);
 		muram_writew(&txbd->len, 0);
 		muram_writew(&txbd->buf_ptr_hi, 0);
 		out_be32(&txbd->buf_ptr_lo, 0);
-		txbd++;
 	}
 
 	/* set the Tx queue decriptor */
@@ -834,13 +834,13 @@ static int fm_eth_send(struct eth_device *edev, void *buf, int len)
 {
 	struct fm_eth *fm_eth = to_fm_eth(edev);
 	struct fm_port_global_pram *pram;
-	struct fm_port_bd *txbd, *txbd_base;
+	struct fm_port_bd *txbd;
 	u16 offset_in;
 	int i;
 	dma_addr_t dma;
 
 	pram = fm_eth->tx_pram;
-	txbd = fm_eth->cur_txbd;
+	txbd = &fm_eth->tx_bd_ring[fm_eth->cur_txbd_idx];
 
 	/* find one empty TxBD */
 	for (i = 0; muram_readw(&txbd->status) & TxBD_READY; i++) {
@@ -882,12 +882,7 @@ static int fm_eth_send(struct eth_device *edev, void *buf, int len)
 	dma_unmap_single(fm_eth->dev, dma, len, DMA_TO_DEVICE);
 
 	/* advance the TxBD */
-	txbd++;
-	txbd_base = fm_eth->tx_bd_ring;
-	if (txbd >= (txbd_base + TX_BD_RING_SIZE))
-		txbd = txbd_base;
-	/* update current txbd */
-	fm_eth->cur_txbd = (void *)txbd;
+	fm_eth->cur_txbd_idx = (fm_eth->cur_txbd_idx + 1) % TX_BD_RING_SIZE;
 
 	return 0;
 }
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-11-14 13:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-14 13:00 [PATCH 0/6] fsl-fman patches Sascha Hauer
2019-11-14 13:00 ` [PATCH 1/6] net: fsl-fman: reset device before leaving Sascha Hauer
2019-11-14 13:23   ` Ahmad Fatoum
2019-11-14 14:36     ` Sascha Hauer
2019-11-14 13:00 ` Sascha Hauer [this message]
2019-11-14 13:00 ` [PATCH 3/6] net: fsl-fman: move status read into loop Sascha Hauer
2019-11-14 13:00 ` [PATCH 4/6] net: fsl-fman: Store index for rxbd Sascha Hauer
2019-11-14 13:00 ` [PATCH 5/6] net: fsl-fman: simplify setting next offset Sascha Hauer
2019-11-14 13:00 ` [PATCH 6/6] net: fsl-fman: do not leave not transmitted DMA buffers mapped Sascha Hauer

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=20191114130021.1029-3-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox