1313#include <linux/cpumask.h>
1414#include <linux/crash_dump.h>
1515#include <linux/vmalloc.h>
16+ #include <net/page_pool/helpers.h>
1617
1718#include "ionic.h"
1819#include "ionic_bus.h"
@@ -439,6 +440,9 @@ static void ionic_qcq_free(struct ionic_lif *lif, struct ionic_qcq *qcq)
439440 qcq -> sg_base_pa = 0 ;
440441 }
441442
443+ page_pool_destroy (qcq -> q .page_pool );
444+ qcq -> q .page_pool = NULL ;
445+
442446 ionic_qcq_intr_free (lif , qcq );
443447 vfree (qcq -> q .info );
444448 qcq -> q .info = NULL ;
@@ -553,7 +557,8 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
553557 unsigned int cq_desc_size ,
554558 unsigned int sg_desc_size ,
555559 unsigned int desc_info_size ,
556- unsigned int pid , struct ionic_qcq * * qcq )
560+ unsigned int pid , struct bpf_prog * xdp_prog ,
561+ struct ionic_qcq * * qcq )
557562{
558563 struct ionic_dev * idev = & lif -> ionic -> idev ;
559564 struct device * dev = lif -> ionic -> dev ;
@@ -579,19 +584,44 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
579584 goto err_out_free_qcq ;
580585 }
581586
587+ if (type == IONIC_QTYPE_RXQ ) {
588+ struct page_pool_params pp_params = {
589+ .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV ,
590+ .order = 0 ,
591+ .pool_size = num_descs ,
592+ .nid = NUMA_NO_NODE ,
593+ .dev = lif -> ionic -> dev ,
594+ .napi = & new -> napi ,
595+ .dma_dir = DMA_FROM_DEVICE ,
596+ .max_len = PAGE_SIZE ,
597+ .netdev = lif -> netdev ,
598+ };
599+
600+ if (xdp_prog )
601+ pp_params .dma_dir = DMA_BIDIRECTIONAL ;
602+
603+ new -> q .page_pool = page_pool_create (& pp_params );
604+ if (IS_ERR (new -> q .page_pool )) {
605+ netdev_err (lif -> netdev , "Cannot create page_pool\n" );
606+ err = PTR_ERR (new -> q .page_pool );
607+ new -> q .page_pool = NULL ;
608+ goto err_out_free_q_info ;
609+ }
610+ }
611+
582612 new -> q .type = type ;
583613 new -> q .max_sg_elems = lif -> qtype_info [type ].max_sg_elems ;
584614
585615 err = ionic_q_init (lif , idev , & new -> q , index , name , num_descs ,
586616 desc_size , sg_desc_size , pid );
587617 if (err ) {
588618 netdev_err (lif -> netdev , "Cannot initialize queue\n" );
589- goto err_out_free_q_info ;
619+ goto err_out_free_page_pool ;
590620 }
591621
592622 err = ionic_alloc_qcq_interrupt (lif , new );
593623 if (err )
594- goto err_out_free_q_info ;
624+ goto err_out_free_page_pool ;
595625
596626 err = ionic_cq_init (lif , & new -> cq , & new -> intr , num_descs , cq_desc_size );
597627 if (err ) {
@@ -712,6 +742,8 @@ static int ionic_qcq_alloc(struct ionic_lif *lif, unsigned int type,
712742 devm_free_irq (dev , new -> intr .vector , & new -> napi );
713743 ionic_intr_free (lif -> ionic , new -> intr .index );
714744 }
745+ err_out_free_page_pool :
746+ page_pool_destroy (new -> q .page_pool );
715747err_out_free_q_info :
716748 vfree (new -> q .info );
717749err_out_free_qcq :
@@ -734,7 +766,7 @@ static int ionic_qcqs_alloc(struct ionic_lif *lif)
734766 sizeof (struct ionic_admin_comp ),
735767 0 ,
736768 sizeof (struct ionic_admin_desc_info ),
737- lif -> kern_pid , & lif -> adminqcq );
769+ lif -> kern_pid , NULL , & lif -> adminqcq );
738770 if (err )
739771 return err ;
740772 ionic_debugfs_add_qcq (lif , lif -> adminqcq );
@@ -747,7 +779,7 @@ static int ionic_qcqs_alloc(struct ionic_lif *lif)
747779 sizeof (union ionic_notifyq_comp ),
748780 0 ,
749781 sizeof (struct ionic_admin_desc_info ),
750- lif -> kern_pid , & lif -> notifyqcq );
782+ lif -> kern_pid , NULL , & lif -> notifyqcq );
751783 if (err )
752784 goto err_out ;
753785 ionic_debugfs_add_qcq (lif , lif -> notifyqcq );
@@ -965,7 +997,7 @@ int ionic_lif_create_hwstamp_txq(struct ionic_lif *lif)
965997 err = ionic_qcq_alloc (lif , IONIC_QTYPE_TXQ , txq_i , "hwstamp_tx" , flags ,
966998 num_desc , desc_sz , comp_sz , sg_desc_sz ,
967999 sizeof (struct ionic_tx_desc_info ),
968- lif -> kern_pid , & txq );
1000+ lif -> kern_pid , NULL , & txq );
9691001 if (err )
9701002 goto err_qcq_alloc ;
9711003
@@ -1025,7 +1057,7 @@ int ionic_lif_create_hwstamp_rxq(struct ionic_lif *lif)
10251057 err = ionic_qcq_alloc (lif , IONIC_QTYPE_RXQ , rxq_i , "hwstamp_rx" , flags ,
10261058 num_desc , desc_sz , comp_sz , sg_desc_sz ,
10271059 sizeof (struct ionic_rx_desc_info ),
1028- lif -> kern_pid , & rxq );
1060+ lif -> kern_pid , NULL , & rxq );
10291061 if (err )
10301062 goto err_qcq_alloc ;
10311063
@@ -2051,7 +2083,7 @@ static int ionic_txrx_alloc(struct ionic_lif *lif)
20512083 err = ionic_qcq_alloc (lif , IONIC_QTYPE_TXQ , i , "tx" , flags ,
20522084 num_desc , desc_sz , comp_sz , sg_desc_sz ,
20532085 sizeof (struct ionic_tx_desc_info ),
2054- lif -> kern_pid , & lif -> txqcqs [i ]);
2086+ lif -> kern_pid , NULL , & lif -> txqcqs [i ]);
20552087 if (err )
20562088 goto err_out ;
20572089
@@ -2083,7 +2115,8 @@ static int ionic_txrx_alloc(struct ionic_lif *lif)
20832115 err = ionic_qcq_alloc (lif , IONIC_QTYPE_RXQ , i , "rx" , flags ,
20842116 num_desc , desc_sz , comp_sz , sg_desc_sz ,
20852117 sizeof (struct ionic_rx_desc_info ),
2086- lif -> kern_pid , & lif -> rxqcqs [i ]);
2118+ lif -> kern_pid , lif -> xdp_prog ,
2119+ & lif -> rxqcqs [i ]);
20872120 if (err )
20882121 goto err_out ;
20892122
@@ -2679,15 +2712,15 @@ static int ionic_register_rxq_info(struct ionic_queue *q, unsigned int napi_id)
26792712
26802713 err = xdp_rxq_info_reg (rxq_info , q -> lif -> netdev , q -> index , napi_id );
26812714 if (err ) {
2682- dev_err (q -> dev , "Queue %d xdp_rxq_info_reg failed, err %d\n" ,
2683- q -> index , err );
2715+ netdev_err (q -> lif -> netdev , "q %d xdp_rxq_info_reg failed, err %d\n" ,
2716+ q -> index , err );
26842717 goto err_out ;
26852718 }
26862719
2687- err = xdp_rxq_info_reg_mem_model (rxq_info , MEM_TYPE_PAGE_ORDER0 , NULL );
2720+ err = xdp_rxq_info_reg_mem_model (rxq_info , MEM_TYPE_PAGE_POOL , q -> page_pool );
26882721 if (err ) {
2689- dev_err (q -> dev , "Queue %d xdp_rxq_info_reg_mem_model failed, err %d\n" ,
2690- q -> index , err );
2722+ netdev_err (q -> lif -> netdev , "q %d xdp_rxq_info_reg_mem_model failed, err %d\n" ,
2723+ q -> index , err );
26912724 xdp_rxq_info_unreg (rxq_info );
26922725 goto err_out ;
26932726 }
@@ -2853,7 +2886,16 @@ static int ionic_cmb_reconfig(struct ionic_lif *lif,
28532886
28542887static void ionic_swap_queues (struct ionic_qcq * a , struct ionic_qcq * b )
28552888{
2856- /* only swapping the queues, not the napi, flags, or other stuff */
2889+ /* only swapping the queues and napi, not flags or other stuff */
2890+ swap (a -> napi , b -> napi );
2891+
2892+ if (a -> q .type == IONIC_QTYPE_RXQ ) {
2893+ swap (a -> q .page_pool , b -> q .page_pool );
2894+ a -> q .page_pool -> p .napi = & a -> napi ;
2895+ if (b -> q .page_pool ) /* is NULL when increasing queue count */
2896+ b -> q .page_pool -> p .napi = & b -> napi ;
2897+ }
2898+
28572899 swap (a -> q .features , b -> q .features );
28582900 swap (a -> q .num_descs , b -> q .num_descs );
28592901 swap (a -> q .desc_size , b -> q .desc_size );
@@ -2943,7 +2985,7 @@ int ionic_reconfigure_queues(struct ionic_lif *lif,
29432985 err = ionic_qcq_alloc (lif , IONIC_QTYPE_TXQ , i , "tx" , flags ,
29442986 4 , desc_sz , comp_sz , sg_desc_sz ,
29452987 sizeof (struct ionic_tx_desc_info ),
2946- lif -> kern_pid , & lif -> txqcqs [i ]);
2988+ lif -> kern_pid , NULL , & lif -> txqcqs [i ]);
29472989 if (err )
29482990 goto err_out ;
29492991 }
@@ -2952,7 +2994,7 @@ int ionic_reconfigure_queues(struct ionic_lif *lif,
29522994 err = ionic_qcq_alloc (lif , IONIC_QTYPE_TXQ , i , "tx" , flags ,
29532995 num_desc , desc_sz , comp_sz , sg_desc_sz ,
29542996 sizeof (struct ionic_tx_desc_info ),
2955- lif -> kern_pid , & tx_qcqs [i ]);
2997+ lif -> kern_pid , NULL , & tx_qcqs [i ]);
29562998 if (err )
29572999 goto err_out ;
29583000 }
@@ -2974,7 +3016,7 @@ int ionic_reconfigure_queues(struct ionic_lif *lif,
29743016 err = ionic_qcq_alloc (lif , IONIC_QTYPE_RXQ , i , "rx" , flags ,
29753017 4 , desc_sz , comp_sz , sg_desc_sz ,
29763018 sizeof (struct ionic_rx_desc_info ),
2977- lif -> kern_pid , & lif -> rxqcqs [i ]);
3019+ lif -> kern_pid , NULL , & lif -> rxqcqs [i ]);
29783020 if (err )
29793021 goto err_out ;
29803022 }
@@ -2983,7 +3025,7 @@ int ionic_reconfigure_queues(struct ionic_lif *lif,
29833025 err = ionic_qcq_alloc (lif , IONIC_QTYPE_RXQ , i , "rx" , flags ,
29843026 num_desc , desc_sz , comp_sz , sg_desc_sz ,
29853027 sizeof (struct ionic_rx_desc_info ),
2986- lif -> kern_pid , & rx_qcqs [i ]);
3028+ lif -> kern_pid , qparam -> xdp_prog , & rx_qcqs [i ]);
29873029 if (err )
29883030 goto err_out ;
29893031
0 commit comments