Subject: Re: [PATCH 3/4] igb: add AF_XDP zero-copy Rx support

From: Simon Horman <[email-masked]>
Date: Tue, 4 Jul 2023 20:30:59 +0100

On Tue, Jul 04, 2023 at 11:59:14AM +0200, Sriram Yagnaraman wrote:
> Add support for AF_XDP zero-copy receive path.
> 
> Add IGB_RING_FLAG_AF_XDP_ZC ring flag to indicate that a ring has AF_XDP
> zero-copy support. This flag is used in igb_configure_rx_ring to
> register XSK_BUFF_POOL (if zero-copy is enabled) memory model or the
> default PAGE_SHARED model otherwise.
> 
> When AF_XDP zero-copy is enabled, the rx buffers are allocated from the
> xsk buff pool using igb_alloc_rx_buffers_zc.
> 
> Signed-off-by: Sriram Yagnaraman <[email-masked]>

...

> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 391c0eb136d9..f4dbb75d6eac 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -2013,7 +2013,9 @@ static void igb_configure(struct igb_adapter *adapter)
>  	 */
>  	for (i = 0; i < adapter->num_rx_queues; i++) {
>  		struct igb_ring *ring = adapter->rx_ring[i];
> -		igb_alloc_rx_buffers(ring, igb_desc_unused(ring));
> +		ring->xsk_pool ?
> +			igb_alloc_rx_buffers_zc(ring, igb_desc_unused(ring)) :
> +			igb_alloc_rx_buffers(ring, igb_desc_unused(ring));

This construction seems a little unusual (to me) as the result of
the ternary operator is not assigned. I wonder if it it would
be sensible to follow a simple if/else pattern here.o

Flagged by Sparse as:

 .../igb_main.c:2016:32: error: incompatible types in conditional expression (different base types):
 .../igb_main.c:2016:32:    bool
 .../igb_main.c:2016:32:    void

...

> @@ -4892,7 +4917,9 @@ void igb_txrx_ring_enable(struct igb_adapter *adapter, u16 qid)
>  	 * at least 1 descriptor unused to make sure
>  	 * next_to_use != next_to_clean
>  	 */
> -	igb_alloc_rx_buffers(rx_ring, igb_desc_unused(rx_ring));
> +	rx_ring->xsk_pool ?
> +		igb_alloc_rx_buffers_zc(rx_ring, igb_desc_unused(rx_ring)) :
> +		igb_alloc_rx_buffers(rx_ring, igb_desc_unused(rx_ring));

Ditto.

...

> +static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid)
> +{
> +	struct igb_ring *rx_ring;
> +	struct xsk_buff_pool *pool;
> +	bool if_running;

Please use reverse xmas tree - longest line to shortest - for
new Networking code. Likewise elsewhere in this patch.
You can use the tool at the link below to help.

https://github.com/ecree-solarflare/xmastree

...