Skip to content

Commit 26f5726

Browse files
emuslndavem330
authored andcommittedFeb 16, 2024
ionic: add ndo_xdp_xmit
When our ndo_xdp_xmit is called we mark the buffer with XDP_REDIRECT so we know to return it to the XDP stack for cleaning. Co-developed-by: Brett Creeley <brett.creeley@amd.com> Signed-off-by: Brett Creeley <brett.creeley@amd.com> Signed-off-by: Shannon Nelson <shannon.nelson@amd.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 587fc3f commit 26f5726

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed
 

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,8 @@ static int ionic_init_nic_features(struct ionic_lif *lif)
16501650
IFF_LIVE_ADDR_CHANGE;
16511651

16521652
netdev->xdp_features = NETDEV_XDP_ACT_BASIC |
1653-
NETDEV_XDP_ACT_REDIRECT;
1653+
NETDEV_XDP_ACT_REDIRECT |
1654+
NETDEV_XDP_ACT_NDO_XMIT;
16541655

16551656
return 0;
16561657
}
@@ -2847,6 +2848,7 @@ static const struct net_device_ops ionic_netdev_ops = {
28472848
.ndo_eth_ioctl = ionic_eth_ioctl,
28482849
.ndo_start_xmit = ionic_start_xmit,
28492850
.ndo_bpf = ionic_xdp,
2851+
.ndo_xdp_xmit = ionic_xdp_xmit,
28502852
.ndo_get_stats64 = ionic_get_stats64,
28512853
.ndo_set_rx_mode = ionic_ndo_set_rx_mode,
28522854
.ndo_set_features = ionic_set_features,

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

+62-1
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,13 @@ static void ionic_xdp_tx_desc_clean(struct ionic_queue *q,
320320
buf_info = desc_info->bufs;
321321
dma_unmap_single(dev, buf_info->dma_addr,
322322
buf_info->len, DMA_TO_DEVICE);
323-
__free_pages(buf_info->page, 0);
323+
if (desc_info->act == XDP_TX)
324+
__free_pages(buf_info->page, 0);
324325
buf_info->page = NULL;
325326

327+
if (desc_info->act == XDP_REDIRECT)
328+
xdp_return_frame(desc_info->xdpf);
329+
326330
desc_info->nbufs = 0;
327331
desc_info->xdpf = NULL;
328332
desc_info->act = 0;
@@ -376,6 +380,63 @@ static int ionic_xdp_post_frame(struct net_device *netdev,
376380
return 0;
377381
}
378382

383+
int ionic_xdp_xmit(struct net_device *netdev, int n,
384+
struct xdp_frame **xdp_frames, u32 flags)
385+
{
386+
struct ionic_lif *lif = netdev_priv(netdev);
387+
struct ionic_queue *txq;
388+
struct netdev_queue *nq;
389+
int nxmit;
390+
int space;
391+
int cpu;
392+
int qi;
393+
394+
if (unlikely(!test_bit(IONIC_LIF_F_UP, lif->state)))
395+
return -ENETDOWN;
396+
397+
if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
398+
return -EINVAL;
399+
400+
/* AdminQ is assumed on cpu 0, while we attempt to affinitize the
401+
* TxRx queue pairs 0..n-1 on cpus 1..n. We try to keep with that
402+
* affinitization here, but of course irqbalance and friends might
403+
* have juggled things anyway, so we have to check for the 0 case.
404+
*/
405+
cpu = smp_processor_id();
406+
qi = cpu ? (cpu - 1) % lif->nxqs : cpu;
407+
408+
txq = &lif->txqcqs[qi]->q;
409+
nq = netdev_get_tx_queue(netdev, txq->index);
410+
__netif_tx_lock(nq, cpu);
411+
txq_trans_cond_update(nq);
412+
413+
if (netif_tx_queue_stopped(nq) ||
414+
unlikely(ionic_maybe_stop_tx(txq, 1))) {
415+
__netif_tx_unlock(nq);
416+
return -EIO;
417+
}
418+
419+
space = min_t(int, n, ionic_q_space_avail(txq));
420+
for (nxmit = 0; nxmit < space ; nxmit++) {
421+
if (ionic_xdp_post_frame(netdev, txq, xdp_frames[nxmit],
422+
XDP_REDIRECT,
423+
virt_to_page(xdp_frames[nxmit]->data),
424+
0, false)) {
425+
nxmit--;
426+
break;
427+
}
428+
}
429+
430+
if (flags & XDP_XMIT_FLUSH)
431+
ionic_dbell_ring(lif->kern_dbpage, txq->hw_type,
432+
txq->dbval | txq->head_idx);
433+
434+
ionic_maybe_stop_tx(txq, 4);
435+
__netif_tx_unlock(nq);
436+
437+
return nxmit;
438+
}
439+
379440
static bool ionic_run_xdp(struct ionic_rx_stats *stats,
380441
struct net_device *netdev,
381442
struct bpf_prog *xdp_prog,

‎drivers/net/ethernet/pensando/ionic/ionic_txrx.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ netdev_tx_t ionic_start_xmit(struct sk_buff *skb, struct net_device *netdev);
1717
bool ionic_rx_service(struct ionic_cq *cq, struct ionic_cq_info *cq_info);
1818
bool ionic_tx_service(struct ionic_cq *cq, struct ionic_cq_info *cq_info);
1919

20+
int ionic_xdp_xmit(struct net_device *netdev, int n, struct xdp_frame **xdp, u32 flags);
2021
#endif /* _IONIC_TXRX_H_ */

0 commit comments

Comments
 (0)