Re: [PATCH net-next] net: lan966x: Don't use xdp_frame when action is XDP_TX

From: Alexander Lobakin
Date: Thu Apr 20 2023 - 10:50:32 EST


From: Horatiu Vultur <horatiu.vultur@xxxxxxxxxxxxx>
Date: Thu, 20 Apr 2023 14:11:52 +0200

> When the action of an xdp program was XDP_TX, lan966x was creating
> a xdp_frame and use this one to send the frame back. But it is also
> possible to send back the frame without needing a xdp_frame, because
> it possible to send it back using the page.
> And then once the frame is transmitted is possible to use directly
> page_pool_recycle_direct as lan966x is using page pools.
> This would save some CPU usage on this path.
>
> Signed-off-by: Horatiu Vultur <horatiu.vultur@xxxxxxxxxxxxx>

[...]

> @@ -702,6 +704,7 @@ static void lan966x_fdma_tx_start(struct lan966x_tx *tx, int next_to_use)
> int lan966x_fdma_xmit_xdpf(struct lan966x_port *port,
> struct xdp_frame *xdpf,
> struct page *page,
> + u32 len,
> bool dma_map)

I think you can cut the number of arguments by almost a half:

int lan966x_fdma_xmit_xdpf(struct lan966x_port *port,
void *ptr, u32 len)
{
if (len) {
/* XDP_TX, ptr is page */
page = ptr;

dma_sync_here(page, len);
} else {
/* XDP_REDIR, ptr is xdp_frame */
xdpf = ptr;

dma_map_here(xdpf->data, xdpf->len);
}

@page and @xdpf are mutually exclusive. When @xdpf is non-null, @len is
excessive (xdpf->len is here), so you can use @len as logical
`len * !dma_map`, i.e. zero for REDIR and the actual frame length for TX.

I generally enjoy seeing how you constantly improve stuff in your driver :)

> {
> struct lan966x *lan966x = port->lan966x;
> @@ -722,6 +725,15 @@ int lan966x_fdma_xmit_xdpf(struct lan966x_port *port,
> goto out;
> }
[...]

Thanks,
Olek