Skip to content

Commit 92d4256

Browse files
tlebkuba-moo
authored andcommitted
net: macb: move ring size computation to functions
The tx/rx ring size calculation is somewhat complex and partially hidden behind a macro. Move that out of the {RX,TX}_RING_BYTES() macros and macb_{alloc,free}_consistent() functions into neat separate functions. In macb_free_consistent(), we drop the size variable and directly call the size helpers in the arguments list. In macb_alloc_consistent(), we keep the size variable that is used by netdev_dbg() calls. Acked-by: Nicolas Ferre <[email protected]> Signed-off-by: Théo Lebrun <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent fca3dc8 commit 92d4256

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,10 @@ struct sifive_fu540_macb_mgmt {
5151
#define DEFAULT_RX_RING_SIZE 512 /* must be power of 2 */
5252
#define MIN_RX_RING_SIZE 64
5353
#define MAX_RX_RING_SIZE 8192
54-
#define RX_RING_BYTES(bp) (macb_dma_desc_get_size(bp) \
55-
* (bp)->rx_ring_size)
5654

5755
#define DEFAULT_TX_RING_SIZE 512 /* must be power of 2 */
5856
#define MIN_TX_RING_SIZE 64
5957
#define MAX_TX_RING_SIZE 4096
60-
#define TX_RING_BYTES(bp) (macb_dma_desc_get_size(bp) \
61-
* (bp)->tx_ring_size)
6258

6359
/* level of occupied TX descriptors under which we wake up TX process */
6460
#define MACB_TX_WAKEUP_THRESH(bp) (3 * (bp)->tx_ring_size / 4)
@@ -2470,11 +2466,20 @@ static void macb_free_rx_buffers(struct macb *bp)
24702466
}
24712467
}
24722468

2469+
static unsigned int macb_tx_ring_size_per_queue(struct macb *bp)
2470+
{
2471+
return macb_dma_desc_get_size(bp) * bp->tx_ring_size + bp->tx_bd_rd_prefetch;
2472+
}
2473+
2474+
static unsigned int macb_rx_ring_size_per_queue(struct macb *bp)
2475+
{
2476+
return macb_dma_desc_get_size(bp) * bp->rx_ring_size + bp->rx_bd_rd_prefetch;
2477+
}
2478+
24732479
static void macb_free_consistent(struct macb *bp)
24742480
{
24752481
struct macb_queue *queue;
24762482
unsigned int q;
2477-
int size;
24782483

24792484
if (bp->rx_ring_tieoff) {
24802485
dma_free_coherent(&bp->pdev->dev, macb_dma_desc_get_size(bp),
@@ -2488,14 +2493,14 @@ static void macb_free_consistent(struct macb *bp)
24882493
kfree(queue->tx_skb);
24892494
queue->tx_skb = NULL;
24902495
if (queue->tx_ring) {
2491-
size = TX_RING_BYTES(bp) + bp->tx_bd_rd_prefetch;
2492-
dma_free_coherent(&bp->pdev->dev, size,
2496+
dma_free_coherent(&bp->pdev->dev,
2497+
macb_tx_ring_size_per_queue(bp),
24932498
queue->tx_ring, queue->tx_ring_dma);
24942499
queue->tx_ring = NULL;
24952500
}
24962501
if (queue->rx_ring) {
2497-
size = RX_RING_BYTES(bp) + bp->rx_bd_rd_prefetch;
2498-
dma_free_coherent(&bp->pdev->dev, size,
2502+
dma_free_coherent(&bp->pdev->dev,
2503+
macb_rx_ring_size_per_queue(bp),
24992504
queue->rx_ring, queue->rx_ring_dma);
25002505
queue->rx_ring = NULL;
25012506
}
@@ -2546,7 +2551,7 @@ static int macb_alloc_consistent(struct macb *bp)
25462551
int size;
25472552

25482553
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
2549-
size = TX_RING_BYTES(bp) + bp->tx_bd_rd_prefetch;
2554+
size = macb_tx_ring_size_per_queue(bp);
25502555
queue->tx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
25512556
&queue->tx_ring_dma,
25522557
GFP_KERNEL);
@@ -2564,7 +2569,7 @@ static int macb_alloc_consistent(struct macb *bp)
25642569
if (!queue->tx_skb)
25652570
goto out_err;
25662571

2567-
size = RX_RING_BYTES(bp) + bp->rx_bd_rd_prefetch;
2572+
size = macb_rx_ring_size_per_queue(bp);
25682573
queue->rx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
25692574
&queue->rx_ring_dma,
25702575
GFP_KERNEL);

0 commit comments

Comments
 (0)