Re: [PATCH V10 net-next 06/10] net: hibmcge: Implement .ndo_start_xmit function
From: Jakub Kicinski
Date: Sun Sep 15 2024 - 11:16:37 EST
On Thu, 12 Sep 2024 10:51:23 +0800 Jijie Shao wrote:
> +static int hbg_napi_tx_recycle(struct napi_struct *napi, int budget)
> +{
> + struct hbg_ring *ring = container_of(napi, struct hbg_ring, napi);
> + /* This smp_load_acquire() pairs with smp_store_release() in
> + * hbg_start_xmit() called in xmit process.
> + */
> + u32 ntu = smp_load_acquire(&ring->ntu);
> + struct hbg_priv *priv = ring->priv;
> + struct hbg_buffer *buffer;
> + u32 ntc = ring->ntc;
> + int packet_done = 0;
> +
> + while (packet_done < budget) {
you should so some cleanup even if budget is 0
in fact you can hardcode the amount of work Tx NAPI does to 128 and
don't look at the budget as a limit. Per NAPI documentation budget
is for Rx
> + if (unlikely(hbg_queue_is_empty(ntc, ntu, ring)))
> + break;
> +
> + /* make sure HW write desc complete */
> + dma_rmb();
> +
> + buffer = &ring->queue[ntc];
> + if (buffer->state != HBG_TX_STATE_COMPLETE)
> + break;
> +
> + hbg_buffer_free(buffer);
> + ntc = hbg_queue_next_prt(ntc, ring);
> + packet_done++;
> + }
> +
> + /* This smp_store_release() pairs with smp_load_acquire() in
> + * hbg_start_xmit() called in xmit process.
> + */
> + smp_store_release(&ring->ntc, ntc);
> + netif_wake_queue(priv->netdev);
> +
> + if (likely(napi_complete_done(napi, packet_done)))
if packet_done >= budget you should not call napi_complete_done()
as you are not done
> + hbg_hw_irq_enable(priv, HBG_INT_MSK_TX_B, true);