[RFC,net-next,06/11] net: enetc: consolidate rx_swbd freeing

Message ID 20230206100837.451300-7-vladimir.oltean@nxp.com
State New
Headers
Series NXP ENETC AF_XDP zero-copy sockets |

Commit Message

Vladimir Oltean Feb. 6, 2023, 10:08 a.m. UTC
  There are 2 code paths in the driver which DMA unmap and give back to
the allocator the page held by the shadow copy of an RX buffer
descriptor. One is on RX ring teardown, and the other on XDP_TX
recycling failure.

Refactor them to call the same helper function, which will make it
easier to add support for one more RX software BD type in the future
(XSK buffer).

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 drivers/net/ethernet/freescale/enetc/enetc.c | 28 ++++++++++----------
 1 file changed, 14 insertions(+), 14 deletions(-)
  

Patch

diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 37d6ad0576e5..33950c81e53c 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -95,6 +95,17 @@  static void enetc_free_tx_frame(struct enetc_bdr *tx_ring,
 	}
 }
 
+static void enetc_free_rx_swbd(struct enetc_bdr *rx_ring,
+			       struct enetc_rx_swbd *rx_swbd)
+{
+	if (rx_swbd->page) {
+		dma_unmap_page(rx_ring->dev, rx_swbd->dma, PAGE_SIZE,
+			       rx_swbd->dir);
+		__free_page(rx_swbd->page);
+		rx_swbd->page = NULL;
+	}
+}
+
 /* Let H/W know BD ring has been updated */
 static void enetc_update_tx_ring_tail(struct enetc_bdr *tx_ring)
 {
@@ -796,9 +807,7 @@  static void enetc_recycle_xdp_tx_buff(struct enetc_bdr *tx_ring,
 		 */
 		rx_ring->stats.recycle_failures++;
 
-		dma_unmap_page(rx_ring->dev, rx_swbd.dma, PAGE_SIZE,
-			       rx_swbd.dir);
-		__free_page(rx_swbd.page);
+		enetc_free_rx_swbd(rx_ring, &rx_swbd);
 	}
 
 	rx_ring->xdp.xdp_tx_in_flight--;
@@ -1988,17 +1997,8 @@  static void enetc_free_rx_ring(struct enetc_bdr *rx_ring)
 {
 	int i;
 
-	for (i = 0; i < rx_ring->bd_count; i++) {
-		struct enetc_rx_swbd *rx_swbd = &rx_ring->rx_swbd[i];
-
-		if (!rx_swbd->page)
-			continue;
-
-		dma_unmap_page(rx_ring->dev, rx_swbd->dma, PAGE_SIZE,
-			       rx_swbd->dir);
-		__free_page(rx_swbd->page);
-		rx_swbd->page = NULL;
-	}
+	for (i = 0; i < rx_ring->bd_count; i++)
+		enetc_free_rx_swbd(rx_ring, &rx_ring->rx_swbd[i]);
 }
 
 static void enetc_free_rxtx_rings(struct enetc_ndev_priv *priv)