@@ -480,6 +480,20 @@ int ionic_xdp_xmit(struct net_device *netdev, int n,
480480 return nxmit ;
481481}
482482
483+ static void ionic_xdp_rx_put_bufs (struct ionic_queue * q ,
484+ struct ionic_buf_info * buf_info ,
485+ int nbufs )
486+ {
487+ int i ;
488+
489+ for (i = 0 ; i < nbufs ; i ++ ) {
490+ dma_unmap_page (q -> dev , buf_info -> dma_addr ,
491+ IONIC_PAGE_SIZE , DMA_FROM_DEVICE );
492+ buf_info -> page = NULL ;
493+ buf_info ++ ;
494+ }
495+ }
496+
483497static bool ionic_run_xdp (struct ionic_rx_stats * stats ,
484498 struct net_device * netdev ,
485499 struct bpf_prog * xdp_prog ,
@@ -493,6 +507,7 @@ static bool ionic_run_xdp(struct ionic_rx_stats *stats,
493507 struct netdev_queue * nq ;
494508 struct xdp_frame * xdpf ;
495509 int remain_len ;
510+ int nbufs = 1 ;
496511 int frag_len ;
497512 int err = 0 ;
498513
@@ -542,6 +557,7 @@ static bool ionic_run_xdp(struct ionic_rx_stats *stats,
542557 if (page_is_pfmemalloc (bi -> page ))
543558 xdp_buff_set_frag_pfmemalloc (& xdp_buf );
544559 } while (remain_len > 0 );
560+ nbufs += sinfo -> nr_frags ;
545561 }
546562
547563 xdp_action = bpf_prog_run_xdp (xdp_prog , & xdp_buf );
@@ -574,9 +590,6 @@ static bool ionic_run_xdp(struct ionic_rx_stats *stats,
574590 goto out_xdp_abort ;
575591 }
576592
577- dma_unmap_page (rxq -> dev , buf_info -> dma_addr ,
578- IONIC_PAGE_SIZE , DMA_FROM_DEVICE );
579-
580593 err = ionic_xdp_post_frame (txq , xdpf , XDP_TX ,
581594 buf_info -> page ,
582595 buf_info -> page_offset ,
@@ -586,23 +599,19 @@ static bool ionic_run_xdp(struct ionic_rx_stats *stats,
586599 netdev_dbg (netdev , "tx ionic_xdp_post_frame err %d\n" , err );
587600 goto out_xdp_abort ;
588601 }
589- buf_info -> page = NULL ;
602+ ionic_xdp_rx_put_bufs ( rxq , buf_info , nbufs ) ;
590603 stats -> xdp_tx ++ ;
591604
592605 /* the Tx completion will free the buffers */
593606 break ;
594607
595608 case XDP_REDIRECT :
596- /* unmap the pages before handing them to a different device */
597- dma_unmap_page (rxq -> dev , buf_info -> dma_addr ,
598- IONIC_PAGE_SIZE , DMA_FROM_DEVICE );
599-
600609 err = xdp_do_redirect (netdev , & xdp_buf , xdp_prog );
601610 if (err ) {
602611 netdev_dbg (netdev , "xdp_do_redirect err %d\n" , err );
603612 goto out_xdp_abort ;
604613 }
605- buf_info -> page = NULL ;
614+ ionic_xdp_rx_put_bufs ( rxq , buf_info , nbufs ) ;
606615 rxq -> xdp_flush = true;
607616 stats -> xdp_redirect ++ ;
608617 break ;
0 commit comments