Skip to content

Commit

Permalink
net: ethernet: ti: am65_cpsw: move am65_cpsw_put_page() out of am65_c…
Browse files Browse the repository at this point in the history
…psw_run_xdp()

This allows us to re-use am65_cpsw_run_xdp() for zero copy
case. Add AM65_CPSW_XDP_TX case for successful XDP_TX so we don't
free the page while in flight.

Signed-off-by: Roger Quadros <rogerq@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Roger Quadros authored and David S. Miller committed Feb 19, 2025
1 parent 09057ce commit 6d6c793
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions drivers/net/ethernet/ti/am65-cpsw-nuss.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
#define AM65_CPSW_CPPI_TX_PKT_TYPE 0x7

/* XDP */
#define AM65_CPSW_XDP_TX BIT(2)
#define AM65_CPSW_XDP_CONSUMED BIT(1)
#define AM65_CPSW_XDP_REDIRECT BIT(0)
#define AM65_CPSW_XDP_PASS 0
Expand Down Expand Up @@ -1177,7 +1178,6 @@ static int am65_cpsw_run_xdp(struct am65_cpsw_rx_flow *flow,
int cpu = smp_processor_id();
struct xdp_frame *xdpf;
struct bpf_prog *prog;
struct page *page;
int pkt_len;
u32 act;
int err;
Expand Down Expand Up @@ -1212,7 +1212,7 @@ static int am65_cpsw_run_xdp(struct am65_cpsw_rx_flow *flow,
goto drop;

dev_sw_netstats_rx_add(ndev, pkt_len);
return AM65_CPSW_XDP_CONSUMED;
return AM65_CPSW_XDP_TX;
case XDP_REDIRECT:
if (unlikely(xdp_do_redirect(ndev, xdp, prog)))
goto drop;
Expand All @@ -1230,9 +1230,6 @@ static int am65_cpsw_run_xdp(struct am65_cpsw_rx_flow *flow,
ndev->stats.rx_dropped++;
}

page = virt_to_head_page(xdp->data);
am65_cpsw_put_page(flow, page, true);

return ret;
}

Expand Down Expand Up @@ -1331,6 +1328,12 @@ static int am65_cpsw_nuss_rx_packets(struct am65_cpsw_rx_flow *flow,
xdp_prepare_buff(&xdp, page_addr, AM65_CPSW_HEADROOM,
pkt_len, false);
*xdp_state = am65_cpsw_run_xdp(flow, port, &xdp, &pkt_len);
if (*xdp_state == AM65_CPSW_XDP_CONSUMED) {
page = virt_to_head_page(xdp.data);
am65_cpsw_put_page(flow, page, true);
goto allocate;
}

if (*xdp_state != AM65_CPSW_XDP_PASS)
goto allocate;

Expand Down

0 comments on commit 6d6c793

Please sign in to comment.