1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2018 Intel Corporation. */
4 #include <linux/bpf_trace.h>
5 #include <net/xdp_sock.h>
9 #include "i40e_txrx_common.h"
13 * i40e_alloc_xsk_umems - Allocate an array to store per ring UMEMs
16 * Returns 0 on success, <0 on failure
18 static int i40e_alloc_xsk_umems(struct i40e_vsi *vsi)
23 vsi->num_xsk_umems_used = 0;
24 vsi->num_xsk_umems = vsi->alloc_queue_pairs;
25 vsi->xsk_umems = kcalloc(vsi->num_xsk_umems, sizeof(*vsi->xsk_umems),
27 if (!vsi->xsk_umems) {
28 vsi->num_xsk_umems = 0;
36 * i40e_add_xsk_umem - Store an UMEM for a certain ring/qid
38 * @umem: UMEM to store
39 * @qid: Ring/qid to associate with the UMEM
41 * Returns 0 on success, <0 on failure
43 static int i40e_add_xsk_umem(struct i40e_vsi *vsi, struct xdp_umem *umem,
48 err = i40e_alloc_xsk_umems(vsi);
52 vsi->xsk_umems[qid] = umem;
53 vsi->num_xsk_umems_used++;
59 * i40e_remove_xsk_umem - Remove an UMEM for a certain ring/qid
61 * @qid: Ring/qid associated with the UMEM
63 static void i40e_remove_xsk_umem(struct i40e_vsi *vsi, u16 qid)
65 vsi->xsk_umems[qid] = NULL;
66 vsi->num_xsk_umems_used--;
68 if (vsi->num_xsk_umems == 0) {
69 kfree(vsi->xsk_umems);
70 vsi->xsk_umems = NULL;
71 vsi->num_xsk_umems = 0;
76 * i40e_xsk_umem_dma_map - DMA maps all UMEM memory for the netdev
78 * @umem: UMEM to DMA map
80 * Returns 0 on success, <0 on failure
82 static int i40e_xsk_umem_dma_map(struct i40e_vsi *vsi, struct xdp_umem *umem)
84 struct i40e_pf *pf = vsi->back;
90 for (i = 0; i < umem->npgs; i++) {
91 dma = dma_map_page_attrs(dev, umem->pgs[i], 0, PAGE_SIZE,
92 DMA_BIDIRECTIONAL, I40E_RX_DMA_ATTR);
93 if (dma_mapping_error(dev, dma))
96 umem->pages[i].dma = dma;
102 for (j = 0; j < i; j++) {
103 dma_unmap_page_attrs(dev, umem->pages[i].dma, PAGE_SIZE,
104 DMA_BIDIRECTIONAL, I40E_RX_DMA_ATTR);
105 umem->pages[i].dma = 0;
112 * i40e_xsk_umem_dma_unmap - DMA unmaps all UMEM memory for the netdev
114 * @umem: UMEM to DMA map
116 static void i40e_xsk_umem_dma_unmap(struct i40e_vsi *vsi, struct xdp_umem *umem)
118 struct i40e_pf *pf = vsi->back;
122 dev = &pf->pdev->dev;
124 for (i = 0; i < umem->npgs; i++) {
125 dma_unmap_page_attrs(dev, umem->pages[i].dma, PAGE_SIZE,
126 DMA_BIDIRECTIONAL, I40E_RX_DMA_ATTR);
128 umem->pages[i].dma = 0;
133 * i40e_xsk_umem_enable - Enable/associate an UMEM to a certain ring/qid
136 * @qid: Rx ring to associate UMEM to
138 * Returns 0 on success, <0 on failure
140 static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem,
143 struct xdp_umem_fq_reuse *reuseq;
147 if (vsi->type != I40E_VSI_MAIN)
150 if (qid >= vsi->num_queue_pairs)
153 if (vsi->xsk_umems) {
154 if (qid >= vsi->num_xsk_umems)
156 if (vsi->xsk_umems[qid])
160 reuseq = xsk_reuseq_prepare(vsi->rx_rings[0]->count);
164 xsk_reuseq_free(xsk_reuseq_swap(umem, reuseq));
166 err = i40e_xsk_umem_dma_map(vsi, umem);
170 if_running = netif_running(vsi->netdev) && i40e_enabled_xdp_vsi(vsi);
173 err = i40e_queue_pair_disable(vsi, qid);
178 err = i40e_add_xsk_umem(vsi, umem, qid);
183 err = i40e_queue_pair_enable(vsi, qid);
192 * i40e_xsk_umem_disable - Diassociate an UMEM from a certain ring/qid
194 * @qid: Rx ring to associate UMEM to
196 * Returns 0 on success, <0 on failure
198 static int i40e_xsk_umem_disable(struct i40e_vsi *vsi, u16 qid)
203 if (!vsi->xsk_umems || qid >= vsi->num_xsk_umems ||
204 !vsi->xsk_umems[qid])
207 if_running = netif_running(vsi->netdev) && i40e_enabled_xdp_vsi(vsi);
210 err = i40e_queue_pair_disable(vsi, qid);
215 i40e_xsk_umem_dma_unmap(vsi, vsi->xsk_umems[qid]);
216 i40e_remove_xsk_umem(vsi, qid);
219 err = i40e_queue_pair_enable(vsi, qid);
228 * i40e_xsk_umem_query - Queries a certain ring/qid for its UMEM
230 * @umem: UMEM associated to the ring, if any
231 * @qid: Rx ring to associate UMEM to
233 * This function will store, if any, the UMEM associated to certain ring.
235 * Returns 0 on success, <0 on failure
237 int i40e_xsk_umem_query(struct i40e_vsi *vsi, struct xdp_umem **umem,
240 if (vsi->type != I40E_VSI_MAIN)
243 if (qid >= vsi->num_queue_pairs)
246 if (vsi->xsk_umems) {
247 if (qid >= vsi->num_xsk_umems)
249 *umem = vsi->xsk_umems[qid];
258 * i40e_xsk_umem_query - Queries a certain ring/qid for its UMEM
260 * @umem: UMEM to enable/associate to a ring, or NULL to disable
261 * @qid: Rx ring to (dis)associate UMEM (from)to
263 * This function enables or disables an UMEM to a certain ring.
265 * Returns 0 on success, <0 on failure
267 int i40e_xsk_umem_setup(struct i40e_vsi *vsi, struct xdp_umem *umem,
270 return umem ? i40e_xsk_umem_enable(vsi, umem, qid) :
271 i40e_xsk_umem_disable(vsi, qid);
275 * i40e_run_xdp_zc - Executes an XDP program on an xdp_buff
277 * @xdp: xdp_buff used as input to the XDP program
279 * This function enables or disables an UMEM to a certain ring.
281 * Returns any of I40E_XDP_{PASS, CONSUMED, TX, REDIR}
283 static int i40e_run_xdp_zc(struct i40e_ring *rx_ring, struct xdp_buff *xdp)
285 int err, result = I40E_XDP_PASS;
286 struct i40e_ring *xdp_ring;
287 struct bpf_prog *xdp_prog;
291 /* NB! xdp_prog will always be !NULL, due to the fact that
292 * this path is enabled by setting an XDP program.
294 xdp_prog = READ_ONCE(rx_ring->xdp_prog);
295 act = bpf_prog_run_xdp(xdp_prog, xdp);
296 xdp->handle += xdp->data - xdp->data_hard_start;
301 xdp_ring = rx_ring->vsi->xdp_rings[rx_ring->queue_index];
302 result = i40e_xmit_xdp_tx_ring(xdp, xdp_ring);
305 err = xdp_do_redirect(rx_ring->netdev, xdp, xdp_prog);
306 result = !err ? I40E_XDP_REDIR : I40E_XDP_CONSUMED;
309 bpf_warn_invalid_xdp_action(act);
311 trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
312 /* fallthrough -- handle aborts by dropping packet */
314 result = I40E_XDP_CONSUMED;
322 * i40e_alloc_buffer_zc - Allocates an i40e_rx_buffer
324 * @bi: Rx buffer to populate
326 * This function allocates an Rx buffer. The buffer can come from fill
327 * queue, or via the recycle queue (next_to_alloc).
329 * Returns true for a successful allocation, false otherwise
331 static bool i40e_alloc_buffer_zc(struct i40e_ring *rx_ring,
332 struct i40e_rx_buffer *bi)
334 struct xdp_umem *umem = rx_ring->xsk_umem;
335 void *addr = bi->addr;
339 rx_ring->rx_stats.page_reuse_count++;
343 if (!xsk_umem_peek_addr(umem, &handle)) {
344 rx_ring->rx_stats.alloc_page_failed++;
348 hr = umem->headroom + XDP_PACKET_HEADROOM;
350 bi->dma = xdp_umem_get_dma(umem, handle);
353 bi->addr = xdp_umem_get_data(umem, handle);
356 bi->handle = handle + umem->headroom;
358 xsk_umem_discard_addr(umem);
363 * i40e_alloc_buffer_slow_zc - Allocates an i40e_rx_buffer
365 * @bi: Rx buffer to populate
367 * This function allocates an Rx buffer. The buffer can come from fill
368 * queue, or via the reuse queue.
370 * Returns true for a successful allocation, false otherwise
372 static bool i40e_alloc_buffer_slow_zc(struct i40e_ring *rx_ring,
373 struct i40e_rx_buffer *bi)
375 struct xdp_umem *umem = rx_ring->xsk_umem;
378 if (!xsk_umem_peek_addr_rq(umem, &handle)) {
379 rx_ring->rx_stats.alloc_page_failed++;
383 handle &= rx_ring->xsk_umem->chunk_mask;
385 hr = umem->headroom + XDP_PACKET_HEADROOM;
387 bi->dma = xdp_umem_get_dma(umem, handle);
390 bi->addr = xdp_umem_get_data(umem, handle);
393 bi->handle = handle + umem->headroom;
395 xsk_umem_discard_addr_rq(umem);
399 static __always_inline bool
400 __i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count,
401 bool alloc(struct i40e_ring *rx_ring,
402 struct i40e_rx_buffer *bi))
404 u16 ntu = rx_ring->next_to_use;
405 union i40e_rx_desc *rx_desc;
406 struct i40e_rx_buffer *bi;
409 rx_desc = I40E_RX_DESC(rx_ring, ntu);
410 bi = &rx_ring->rx_bi[ntu];
412 if (!alloc(rx_ring, bi)) {
417 dma_sync_single_range_for_device(rx_ring->dev, bi->dma, 0,
421 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
427 if (unlikely(ntu == rx_ring->count)) {
428 rx_desc = I40E_RX_DESC(rx_ring, 0);
433 rx_desc->wb.qword1.status_error_len = 0;
438 if (rx_ring->next_to_use != ntu)
439 i40e_release_rx_desc(rx_ring, ntu);
445 * i40e_alloc_rx_buffers_zc - Allocates a number of Rx buffers
447 * @count: The number of buffers to allocate
449 * This function allocates a number of Rx buffers from the reuse queue
450 * or fill ring and places them on the Rx ring.
452 * Returns true for a successful allocation, false otherwise
454 bool i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count)
456 return __i40e_alloc_rx_buffers_zc(rx_ring, count,
457 i40e_alloc_buffer_slow_zc);
461 * i40e_alloc_rx_buffers_fast_zc - Allocates a number of Rx buffers
463 * @count: The number of buffers to allocate
465 * This function allocates a number of Rx buffers from the fill ring
466 * or the internal recycle mechanism and places them on the Rx ring.
468 * Returns true for a successful allocation, false otherwise
470 static bool i40e_alloc_rx_buffers_fast_zc(struct i40e_ring *rx_ring, u16 count)
472 return __i40e_alloc_rx_buffers_zc(rx_ring, count,
473 i40e_alloc_buffer_zc);
477 * i40e_get_rx_buffer_zc - Return the current Rx buffer
479 * @size: The size of the rx buffer (read from descriptor)
481 * This function returns the current, received Rx buffer, and also
482 * does DMA synchronization. the Rx ring.
484 * Returns the received Rx buffer
486 static struct i40e_rx_buffer *i40e_get_rx_buffer_zc(struct i40e_ring *rx_ring,
487 const unsigned int size)
489 struct i40e_rx_buffer *bi;
491 bi = &rx_ring->rx_bi[rx_ring->next_to_clean];
493 /* we are reusing so sync this buffer for CPU use */
494 dma_sync_single_range_for_cpu(rx_ring->dev,
503 * i40e_reuse_rx_buffer_zc - Recycle an Rx buffer
505 * @old_bi: The Rx buffer to recycle
507 * This function recycles a finished Rx buffer, and places it on the
508 * recycle queue (next_to_alloc).
510 static void i40e_reuse_rx_buffer_zc(struct i40e_ring *rx_ring,
511 struct i40e_rx_buffer *old_bi)
513 struct i40e_rx_buffer *new_bi = &rx_ring->rx_bi[rx_ring->next_to_alloc];
514 unsigned long mask = (unsigned long)rx_ring->xsk_umem->chunk_mask;
515 u64 hr = rx_ring->xsk_umem->headroom + XDP_PACKET_HEADROOM;
516 u16 nta = rx_ring->next_to_alloc;
518 /* update, and store next to alloc */
520 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
522 /* transfer page from old buffer to new buffer */
523 new_bi->dma = old_bi->dma & mask;
526 new_bi->addr = (void *)((unsigned long)old_bi->addr & mask);
529 new_bi->handle = old_bi->handle & mask;
530 new_bi->handle += rx_ring->xsk_umem->headroom;
536 * i40e_zca_free - Free callback for MEM_TYPE_ZERO_COPY allocations
537 * @alloc: Zero-copy allocator
538 * @handle: Buffer handle
540 void i40e_zca_free(struct zero_copy_allocator *alloc, unsigned long handle)
542 struct i40e_rx_buffer *bi;
543 struct i40e_ring *rx_ring;
547 rx_ring = container_of(alloc, struct i40e_ring, zca);
548 hr = rx_ring->xsk_umem->headroom + XDP_PACKET_HEADROOM;
549 mask = rx_ring->xsk_umem->chunk_mask;
551 nta = rx_ring->next_to_alloc;
552 bi = &rx_ring->rx_bi[nta];
555 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
559 bi->dma = xdp_umem_get_dma(rx_ring->xsk_umem, handle);
562 bi->addr = xdp_umem_get_data(rx_ring->xsk_umem, handle);
565 bi->handle = (u64)handle + rx_ring->xsk_umem->headroom;
569 * i40e_construct_skb_zc - Create skbufff from zero-copy Rx buffer
574 * This functions allocates a new skb from a zero-copy Rx buffer.
576 * Returns the skb, or NULL on failure.
578 static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring,
579 struct i40e_rx_buffer *bi,
580 struct xdp_buff *xdp)
582 unsigned int metasize = xdp->data - xdp->data_meta;
583 unsigned int datasize = xdp->data_end - xdp->data;
586 /* allocate a skb to store the frags */
587 skb = __napi_alloc_skb(&rx_ring->q_vector->napi,
588 xdp->data_end - xdp->data_hard_start,
589 GFP_ATOMIC | __GFP_NOWARN);
593 skb_reserve(skb, xdp->data - xdp->data_hard_start);
594 memcpy(__skb_put(skb, datasize), xdp->data, datasize);
596 skb_metadata_set(skb, metasize);
598 i40e_reuse_rx_buffer_zc(rx_ring, bi);
603 * i40e_inc_ntc: Advance the next_to_clean index
606 static void i40e_inc_ntc(struct i40e_ring *rx_ring)
608 u32 ntc = rx_ring->next_to_clean + 1;
610 ntc = (ntc < rx_ring->count) ? ntc : 0;
611 rx_ring->next_to_clean = ntc;
612 prefetch(I40E_RX_DESC(rx_ring, ntc));
616 * i40e_clean_rx_irq_zc - Consumes Rx packets from the hardware ring
618 * @budget: NAPI budget
620 * Returns amount of work completed
622 int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget)
624 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
625 u16 cleaned_count = I40E_DESC_UNUSED(rx_ring);
626 unsigned int xdp_res, xdp_xmit = 0;
627 bool failure = false;
631 xdp.rxq = &rx_ring->xdp_rxq;
633 while (likely(total_rx_packets < (unsigned int)budget)) {
634 struct i40e_rx_buffer *bi;
635 union i40e_rx_desc *rx_desc;
641 if (cleaned_count >= I40E_RX_BUFFER_WRITE) {
643 !i40e_alloc_rx_buffers_fast_zc(rx_ring,
648 rx_desc = I40E_RX_DESC(rx_ring, rx_ring->next_to_clean);
649 qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len);
651 /* This memory barrier is needed to keep us from reading
652 * any other fields out of the rx_desc until we have
653 * verified the descriptor has been written back.
657 bi = i40e_clean_programming_status(rx_ring, rx_desc,
660 i40e_reuse_rx_buffer_zc(rx_ring, bi);
665 size = (qword & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
666 I40E_RXD_QW1_LENGTH_PBUF_SHIFT;
670 bi = i40e_get_rx_buffer_zc(rx_ring, size);
672 xdp.data_meta = xdp.data;
673 xdp.data_hard_start = xdp.data - XDP_PACKET_HEADROOM;
674 xdp.data_end = xdp.data + size;
675 xdp.handle = bi->handle;
677 xdp_res = i40e_run_xdp_zc(rx_ring, &xdp);
679 if (xdp_res & (I40E_XDP_TX | I40E_XDP_REDIR)) {
683 i40e_reuse_rx_buffer_zc(rx_ring, bi);
686 total_rx_bytes += size;
690 i40e_inc_ntc(rx_ring);
696 /* NB! We are not checking for errors using
697 * i40e_test_staterr with
698 * BIT(I40E_RXD_QW1_ERROR_SHIFT). This is due to that
699 * SBP is *not* set in PRT_SBPVSI (default not set).
701 skb = i40e_construct_skb_zc(rx_ring, bi, &xdp);
703 rx_ring->rx_stats.alloc_buff_failed++;
708 i40e_inc_ntc(rx_ring);
710 if (eth_skb_pad(skb))
713 total_rx_bytes += skb->len;
716 qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len);
717 rx_ptype = (qword & I40E_RXD_QW1_PTYPE_MASK) >>
718 I40E_RXD_QW1_PTYPE_SHIFT;
719 i40e_process_skb_fields(rx_ring, rx_desc, skb, rx_ptype);
721 vlan_tag = (qword & BIT(I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) ?
722 le16_to_cpu(rx_desc->wb.qword0.lo_dword.l2tag1) : 0;
723 i40e_receive_skb(rx_ring, skb, vlan_tag);
726 i40e_finalize_xdp_rx(rx_ring, xdp_xmit);
727 i40e_update_rx_stats(rx_ring, total_rx_bytes, total_rx_packets);
728 return failure ? budget : (int)total_rx_packets;
732 * i40e_xmit_zc - Performs zero-copy Tx AF_XDP
733 * @xdp_ring: XDP Tx ring
734 * @budget: NAPI budget
736 * Returns true if the work is finished.
738 static bool i40e_xmit_zc(struct i40e_ring *xdp_ring, unsigned int budget)
740 struct i40e_tx_desc *tx_desc = NULL;
741 struct i40e_tx_buffer *tx_bi;
742 bool work_done = true;
746 while (budget-- > 0) {
747 if (!unlikely(I40E_DESC_UNUSED(xdp_ring))) {
748 xdp_ring->tx_stats.tx_busy++;
753 if (!xsk_umem_consume_tx(xdp_ring->xsk_umem, &dma, &len))
756 dma_sync_single_for_device(xdp_ring->dev, dma, len,
759 tx_bi = &xdp_ring->tx_bi[xdp_ring->next_to_use];
760 tx_bi->bytecount = len;
762 tx_desc = I40E_TX_DESC(xdp_ring, xdp_ring->next_to_use);
763 tx_desc->buffer_addr = cpu_to_le64(dma);
764 tx_desc->cmd_type_offset_bsz =
765 build_ctob(I40E_TX_DESC_CMD_ICRC
766 | I40E_TX_DESC_CMD_EOP,
769 xdp_ring->next_to_use++;
770 if (xdp_ring->next_to_use == xdp_ring->count)
771 xdp_ring->next_to_use = 0;
775 /* Request an interrupt for the last frame and bump tail ptr. */
776 tx_desc->cmd_type_offset_bsz |= (I40E_TX_DESC_CMD_RS <<
777 I40E_TXD_QW1_CMD_SHIFT);
778 i40e_xdp_ring_update_tail(xdp_ring);
780 xsk_umem_consume_tx_done(xdp_ring->xsk_umem);
783 return !!budget && work_done;
787 * i40e_clean_xdp_tx_buffer - Frees and unmaps an XDP Tx entry
788 * @tx_ring: XDP Tx ring
789 * @tx_bi: Tx buffer info to clean
791 static void i40e_clean_xdp_tx_buffer(struct i40e_ring *tx_ring,
792 struct i40e_tx_buffer *tx_bi)
794 xdp_return_frame(tx_bi->xdpf);
795 dma_unmap_single(tx_ring->dev,
796 dma_unmap_addr(tx_bi, dma),
797 dma_unmap_len(tx_bi, len), DMA_TO_DEVICE);
798 dma_unmap_len_set(tx_bi, len, 0);
802 * i40e_clean_xdp_tx_irq - Completes AF_XDP entries, and cleans XDP entries
803 * @tx_ring: XDP Tx ring
804 * @tx_bi: Tx buffer info to clean
806 * Returns true if cleanup/tranmission is done.
808 bool i40e_clean_xdp_tx_irq(struct i40e_vsi *vsi,
809 struct i40e_ring *tx_ring, int napi_budget)
811 unsigned int ntc, total_bytes = 0, budget = vsi->work_limit;
812 u32 i, completed_frames, frames_ready, xsk_frames = 0;
813 struct xdp_umem *umem = tx_ring->xsk_umem;
814 u32 head_idx = i40e_get_head(tx_ring);
815 bool work_done = true, xmit_done;
816 struct i40e_tx_buffer *tx_bi;
818 if (head_idx < tx_ring->next_to_clean)
819 head_idx += tx_ring->count;
820 frames_ready = head_idx - tx_ring->next_to_clean;
822 if (frames_ready == 0) {
824 } else if (frames_ready > budget) {
825 completed_frames = budget;
828 completed_frames = frames_ready;
831 ntc = tx_ring->next_to_clean;
833 for (i = 0; i < completed_frames; i++) {
834 tx_bi = &tx_ring->tx_bi[ntc];
837 i40e_clean_xdp_tx_buffer(tx_ring, tx_bi);
842 total_bytes += tx_bi->bytecount;
844 if (++ntc >= tx_ring->count)
848 tx_ring->next_to_clean += completed_frames;
849 if (unlikely(tx_ring->next_to_clean >= tx_ring->count))
850 tx_ring->next_to_clean -= tx_ring->count;
853 xsk_umem_complete_tx(umem, xsk_frames);
855 i40e_arm_wb(tx_ring, vsi, budget);
856 i40e_update_tx_stats(tx_ring, completed_frames, total_bytes);
859 xmit_done = i40e_xmit_zc(tx_ring, budget);
861 return work_done && xmit_done;
865 * i40e_xsk_async_xmit - Implements the ndo_xsk_async_xmit
866 * @dev: the netdevice
867 * @queue_id: queue id to wake up
869 * Returns <0 for errors, 0 otherwise.
871 int i40e_xsk_async_xmit(struct net_device *dev, u32 queue_id)
873 struct i40e_netdev_priv *np = netdev_priv(dev);
874 struct i40e_vsi *vsi = np->vsi;
875 struct i40e_ring *ring;
877 if (test_bit(__I40E_VSI_DOWN, vsi->state))
880 if (!i40e_enabled_xdp_vsi(vsi))
883 if (queue_id >= vsi->num_queue_pairs)
886 if (!vsi->xdp_rings[queue_id]->xsk_umem)
889 ring = vsi->xdp_rings[queue_id];
891 /* The idea here is that if NAPI is running, mark a miss, so
892 * it will run again. If not, trigger an interrupt and
893 * schedule the NAPI from interrupt context. If NAPI would be
894 * scheduled here, the interrupt affinity would not be
897 if (!napi_if_scheduled_mark_missed(&ring->q_vector->napi))
898 i40e_force_wb(vsi, ring->q_vector);
903 void i40e_xsk_clean_rx_ring(struct i40e_ring *rx_ring)
907 for (i = 0; i < rx_ring->count; i++) {
908 struct i40e_rx_buffer *rx_bi = &rx_ring->rx_bi[i];
913 xsk_umem_fq_reuse(rx_ring->xsk_umem, rx_bi->handle);
919 * i40e_xsk_clean_xdp_ring - Clean the XDP Tx ring on shutdown
920 * @xdp_ring: XDP Tx ring
922 void i40e_xsk_clean_tx_ring(struct i40e_ring *tx_ring)
924 u16 ntc = tx_ring->next_to_clean, ntu = tx_ring->next_to_use;
925 struct xdp_umem *umem = tx_ring->xsk_umem;
926 struct i40e_tx_buffer *tx_bi;
930 tx_bi = &tx_ring->tx_bi[ntc];
933 i40e_clean_xdp_tx_buffer(tx_ring, tx_bi);
940 if (ntc >= tx_ring->count)
945 xsk_umem_complete_tx(umem, xsk_frames);
949 * i40e_xsk_any_rx_ring_enabled - Checks if Rx rings have AF_XDP UMEM attached
952 * Returns true if any of the Rx rings has an AF_XDP UMEM attached
954 bool i40e_xsk_any_rx_ring_enabled(struct i40e_vsi *vsi)
961 for (i = 0; i < vsi->num_queue_pairs; i++) {
962 if (vsi->xsk_umems[i])