Skip to content

Commit 587fc3f

Browse files
emuslndavem330
authored andcommitted
ionic: Add XDP_REDIRECT support
The XDP_REDIRECT packets are given to the XDP stack and we drop the use of the related page: it will get freed by the driver that ends up doing the Tx. Because we have some hardware configurations with limited queue resources, we use the existing datapath Tx queues rather than creating and managing a separate set of xdp_tx queues. Co-developed-by: Brett Creeley <[email protected]> Signed-off-by: Brett Creeley <[email protected]> Signed-off-by: Shannon Nelson <[email protected]> Reviewed-by: Jacob Keller <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8eeed83 commit 587fc3f

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

drivers/net/ethernet/pensando/ionic/ionic_dev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ struct ionic_queue {
266266
};
267267
struct xdp_rxq_info *xdp_rxq_info;
268268
struct ionic_queue *partner;
269+
bool xdp_flush;
269270
dma_addr_t base_pa;
270271
dma_addr_t cmb_base_pa;
271272
dma_addr_t sg_base_pa;

drivers/net/ethernet/pensando/ionic/ionic_lif.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,8 @@ static int ionic_init_nic_features(struct ionic_lif *lif)
16491649
netdev->priv_flags |= IFF_UNICAST_FLT |
16501650
IFF_LIVE_ADDR_CHANGE;
16511651

1652-
netdev->xdp_features = NETDEV_XDP_ACT_BASIC;
1652+
netdev->xdp_features = NETDEV_XDP_ACT_BASIC |
1653+
NETDEV_XDP_ACT_REDIRECT;
16531654

16541655
return 0;
16551656
}

drivers/net/ethernet/pensando/ionic/ionic_lif.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct ionic_rx_stats {
5656
u64 xdp_aborted;
5757
u64 xdp_pass;
5858
u64 xdp_tx;
59+
u64 xdp_redirect;
5960
};
6061

6162
#define IONIC_QCQ_F_INITED BIT(0)
@@ -144,6 +145,7 @@ struct ionic_lif_sw_stats {
144145
u64 xdp_aborted;
145146
u64 xdp_pass;
146147
u64 xdp_tx;
148+
u64 xdp_redirect;
147149
u64 xdp_frames;
148150
};
149151

drivers/net/ethernet/pensando/ionic/ionic_stats.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static const struct ionic_stat_desc ionic_lif_stats_desc[] = {
3131
IONIC_LIF_STAT_DESC(xdp_aborted),
3232
IONIC_LIF_STAT_DESC(xdp_pass),
3333
IONIC_LIF_STAT_DESC(xdp_tx),
34+
IONIC_LIF_STAT_DESC(xdp_redirect),
3435
IONIC_LIF_STAT_DESC(xdp_frames),
3536
};
3637

@@ -159,6 +160,7 @@ static const struct ionic_stat_desc ionic_rx_stats_desc[] = {
159160
IONIC_RX_STAT_DESC(xdp_aborted),
160161
IONIC_RX_STAT_DESC(xdp_pass),
161162
IONIC_RX_STAT_DESC(xdp_tx),
163+
IONIC_RX_STAT_DESC(xdp_redirect),
162164
};
163165

164166
#define IONIC_NUM_LIF_STATS ARRAY_SIZE(ionic_lif_stats_desc)
@@ -200,6 +202,7 @@ static void ionic_add_lif_rxq_stats(struct ionic_lif *lif, int q_num,
200202
stats->xdp_aborted += rxstats->xdp_aborted;
201203
stats->xdp_pass += rxstats->xdp_pass;
202204
stats->xdp_tx += rxstats->xdp_tx;
205+
stats->xdp_redirect += rxstats->xdp_redirect;
203206
}
204207

205208
static void ionic_get_lif_stats(struct ionic_lif *lif,

drivers/net/ethernet/pensando/ionic/ionic_txrx.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,20 @@ static bool ionic_run_xdp(struct ionic_rx_stats *stats,
446446
break;
447447

448448
case XDP_REDIRECT:
449+
/* unmap the pages before handing them to a different device */
450+
dma_unmap_page(rxq->dev, buf_info->dma_addr,
451+
IONIC_PAGE_SIZE, DMA_FROM_DEVICE);
452+
453+
err = xdp_do_redirect(netdev, &xdp_buf, xdp_prog);
454+
if (err) {
455+
netdev_dbg(netdev, "xdp_do_redirect err %d\n", err);
456+
goto out_xdp_abort;
457+
}
458+
buf_info->page = NULL;
459+
rxq->xdp_flush = true;
460+
stats->xdp_redirect++;
461+
break;
462+
449463
case XDP_ABORTED:
450464
default:
451465
goto out_xdp_abort;
@@ -809,6 +823,14 @@ int ionic_tx_napi(struct napi_struct *napi, int budget)
809823
return work_done;
810824
}
811825

826+
static void ionic_xdp_do_flush(struct ionic_cq *cq)
827+
{
828+
if (cq->bound_q->xdp_flush) {
829+
xdp_do_flush();
830+
cq->bound_q->xdp_flush = false;
831+
}
832+
}
833+
812834
int ionic_rx_napi(struct napi_struct *napi, int budget)
813835
{
814836
struct ionic_qcq *qcq = napi_to_qcq(napi);
@@ -829,6 +851,7 @@ int ionic_rx_napi(struct napi_struct *napi, int budget)
829851

830852
ionic_rx_fill(cq->bound_q);
831853

854+
ionic_xdp_do_flush(cq);
832855
if (work_done < budget && napi_complete_done(napi, work_done)) {
833856
ionic_dim_update(qcq, IONIC_LIF_F_RX_DIM_INTR);
834857
flags |= IONIC_INTR_CRED_UNMASK;
@@ -878,6 +901,7 @@ int ionic_txrx_napi(struct napi_struct *napi, int budget)
878901

879902
ionic_rx_fill(rxcq->bound_q);
880903

904+
ionic_xdp_do_flush(rxcq);
881905
if (rx_work_done < budget && napi_complete_done(napi, rx_work_done)) {
882906
ionic_dim_update(rxqcq, 0);
883907
flags |= IONIC_INTR_CRED_UNMASK;

0 commit comments

Comments
 (0)