1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Intel Corporation.
9 #include <netinet/in.h>
11 #include <sys/socket.h>
12 #include <sys/ioctl.h>
13 #include <linux/if_ether.h>
14 #include <linux/if_xdp.h>
15 #include <linux/if_link.h>
16 #include <linux/ethtool.h>
17 #include <linux/sockios.h>
18 #include "af_xdp_deps.h"
21 #include <rte_ethdev.h>
22 #include <ethdev_driver.h>
23 #include <ethdev_vdev.h>
24 #include <rte_kvargs.h>
25 #include <rte_bus_vdev.h>
26 #include <rte_string_fns.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_common.h>
31 #include <rte_ether.h>
32 #include <rte_lcore.h>
34 #include <rte_memory.h>
35 #include <rte_memzone.h>
36 #include <rte_mempool.h>
38 #include <rte_malloc.h>
40 #include <rte_spinlock.h>
57 RTE_LOG_REGISTER(af_xdp_logtype, pmd.net.af_xdp, NOTICE);
59 #define AF_XDP_LOG(level, fmt, args...) \
60 rte_log(RTE_LOG_ ## level, af_xdp_logtype, \
61 "%s(): " fmt, __func__, ##args)
63 #define ETH_AF_XDP_FRAME_SIZE 2048
64 #define ETH_AF_XDP_NUM_BUFFERS 4096
65 #define ETH_AF_XDP_DFLT_NUM_DESCS XSK_RING_CONS__DEFAULT_NUM_DESCS
66 #define ETH_AF_XDP_DFLT_START_QUEUE_IDX 0
67 #define ETH_AF_XDP_DFLT_QUEUE_COUNT 1
69 #define ETH_AF_XDP_RX_BATCH_SIZE XSK_RING_CONS__DEFAULT_NUM_DESCS
70 #define ETH_AF_XDP_TX_BATCH_SIZE XSK_RING_CONS__DEFAULT_NUM_DESCS
73 struct xsk_umem_info {
74 struct xsk_umem *umem;
75 struct rte_ring *buf_ring;
76 const struct rte_memzone *mz;
77 struct rte_mempool *mb_pool;
90 struct xsk_ring_cons rx;
91 struct xsk_umem_info *umem;
92 struct xsk_socket *xsk;
93 struct rte_mempool *mb_pool;
95 struct rx_stats stats;
97 struct xsk_ring_prod fq;
98 struct xsk_ring_cons cq;
100 struct pkt_tx_queue *pair;
101 struct pollfd fds[1];
111 struct pkt_tx_queue {
112 struct xsk_ring_prod tx;
113 struct xsk_umem_info *umem;
115 struct tx_stats stats;
117 struct pkt_rx_queue *pair;
121 struct pmd_internals {
123 char if_name[IFNAMSIZ];
127 int combined_queue_cnt;
129 char prog_path[PATH_MAX];
130 bool custom_prog_configured;
132 struct rte_ether_addr eth_addr;
134 struct pkt_rx_queue *rx_queues;
135 struct pkt_tx_queue *tx_queues;
138 #define ETH_AF_XDP_IFACE_ARG "iface"
139 #define ETH_AF_XDP_START_QUEUE_ARG "start_queue"
140 #define ETH_AF_XDP_QUEUE_COUNT_ARG "queue_count"
141 #define ETH_AF_XDP_SHARED_UMEM_ARG "shared_umem"
142 #define ETH_AF_XDP_PROG_ARG "xdp_prog"
144 static const char * const valid_arguments[] = {
145 ETH_AF_XDP_IFACE_ARG,
146 ETH_AF_XDP_START_QUEUE_ARG,
147 ETH_AF_XDP_QUEUE_COUNT_ARG,
148 ETH_AF_XDP_SHARED_UMEM_ARG,
153 static const struct rte_eth_link pmd_link = {
154 .link_speed = ETH_SPEED_NUM_10G,
155 .link_duplex = ETH_LINK_FULL_DUPLEX,
156 .link_status = ETH_LINK_DOWN,
157 .link_autoneg = ETH_LINK_AUTONEG
160 /* List which tracks PMDs to facilitate sharing UMEMs across them. */
161 struct internal_list {
162 TAILQ_ENTRY(internal_list) next;
163 struct rte_eth_dev *eth_dev;
166 TAILQ_HEAD(internal_list_head, internal_list);
167 static struct internal_list_head internal_list =
168 TAILQ_HEAD_INITIALIZER(internal_list);
170 static pthread_mutex_t internal_list_lock = PTHREAD_MUTEX_INITIALIZER;
172 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
174 reserve_fill_queue_zc(struct xsk_umem_info *umem, uint16_t reserve_size,
175 struct rte_mbuf **bufs, struct xsk_ring_prod *fq)
180 if (unlikely(!xsk_ring_prod__reserve(fq, reserve_size, &idx))) {
181 for (i = 0; i < reserve_size; i++)
182 rte_pktmbuf_free(bufs[i]);
183 AF_XDP_LOG(DEBUG, "Failed to reserve enough fq descs.\n");
187 for (i = 0; i < reserve_size; i++) {
191 fq_addr = xsk_ring_prod__fill_addr(fq, idx++);
192 addr = (uint64_t)bufs[i] - (uint64_t)umem->buffer -
193 umem->mb_pool->header_size;
197 xsk_ring_prod__submit(fq, reserve_size);
203 reserve_fill_queue_cp(struct xsk_umem_info *umem, uint16_t reserve_size,
204 struct rte_mbuf **bufs __rte_unused,
205 struct xsk_ring_prod *fq)
207 void *addrs[reserve_size];
211 if (rte_ring_dequeue_bulk(umem->buf_ring, addrs, reserve_size, NULL)
213 AF_XDP_LOG(DEBUG, "Failed to get enough buffers for fq.\n");
217 if (unlikely(!xsk_ring_prod__reserve(fq, reserve_size, &idx))) {
218 AF_XDP_LOG(DEBUG, "Failed to reserve enough fq descs.\n");
219 rte_ring_enqueue_bulk(umem->buf_ring, addrs,
224 for (i = 0; i < reserve_size; i++) {
227 fq_addr = xsk_ring_prod__fill_addr(fq, idx++);
228 *fq_addr = (uint64_t)addrs[i];
231 xsk_ring_prod__submit(fq, reserve_size);
238 reserve_fill_queue(struct xsk_umem_info *umem, uint16_t reserve_size,
239 struct rte_mbuf **bufs, struct xsk_ring_prod *fq)
241 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
242 return reserve_fill_queue_zc(umem, reserve_size, bufs, fq);
244 return reserve_fill_queue_cp(umem, reserve_size, bufs, fq);
248 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
250 af_xdp_rx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
252 struct pkt_rx_queue *rxq = queue;
253 struct xsk_ring_cons *rx = &rxq->rx;
254 struct xsk_ring_prod *fq = &rxq->fq;
255 struct xsk_umem_info *umem = rxq->umem;
257 unsigned long rx_bytes = 0;
259 struct rte_mbuf *fq_bufs[ETH_AF_XDP_RX_BATCH_SIZE];
261 nb_pkts = xsk_ring_cons__peek(rx, nb_pkts, &idx_rx);
264 #if defined(XDP_USE_NEED_WAKEUP)
265 if (xsk_ring_prod__needs_wakeup(fq))
266 recvfrom(xsk_socket__fd(rxq->xsk), NULL, 0,
267 MSG_DONTWAIT, NULL, NULL);
273 /* allocate bufs for fill queue replenishment after rx */
274 if (rte_pktmbuf_alloc_bulk(umem->mb_pool, fq_bufs, nb_pkts)) {
276 "Failed to get enough buffers for fq.\n");
277 /* rollback cached_cons which is added by
278 * xsk_ring_cons__peek
280 rx->cached_cons -= nb_pkts;
284 for (i = 0; i < nb_pkts; i++) {
285 const struct xdp_desc *desc;
290 desc = xsk_ring_cons__rx_desc(rx, idx_rx++);
294 offset = xsk_umem__extract_offset(addr);
295 addr = xsk_umem__extract_addr(addr);
297 bufs[i] = (struct rte_mbuf *)
298 xsk_umem__get_data(umem->buffer, addr +
299 umem->mb_pool->header_size);
300 bufs[i]->data_off = offset - sizeof(struct rte_mbuf) -
301 rte_pktmbuf_priv_size(umem->mb_pool) -
302 umem->mb_pool->header_size;
304 rte_pktmbuf_pkt_len(bufs[i]) = len;
305 rte_pktmbuf_data_len(bufs[i]) = len;
309 xsk_ring_cons__release(rx, nb_pkts);
310 (void)reserve_fill_queue(umem, nb_pkts, fq_bufs, fq);
313 rxq->stats.rx_pkts += nb_pkts;
314 rxq->stats.rx_bytes += rx_bytes;
320 af_xdp_rx_cp(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
322 struct pkt_rx_queue *rxq = queue;
323 struct xsk_ring_cons *rx = &rxq->rx;
324 struct xsk_umem_info *umem = rxq->umem;
325 struct xsk_ring_prod *fq = &rxq->fq;
327 unsigned long rx_bytes = 0;
329 uint32_t free_thresh = fq->size >> 1;
330 struct rte_mbuf *mbufs[ETH_AF_XDP_RX_BATCH_SIZE];
332 if (xsk_prod_nb_free(fq, free_thresh) >= free_thresh)
333 (void)reserve_fill_queue(umem, nb_pkts, NULL, fq);
335 nb_pkts = xsk_ring_cons__peek(rx, nb_pkts, &idx_rx);
337 #if defined(XDP_USE_NEED_WAKEUP)
338 if (xsk_ring_prod__needs_wakeup(fq))
339 recvfrom(xsk_socket__fd(rxq->xsk), NULL, 0,
340 MSG_DONTWAIT, NULL, NULL);
345 if (unlikely(rte_pktmbuf_alloc_bulk(rxq->mb_pool, mbufs, nb_pkts))) {
346 /* rollback cached_cons which is added by
347 * xsk_ring_cons__peek
349 rx->cached_cons -= nb_pkts;
353 for (i = 0; i < nb_pkts; i++) {
354 const struct xdp_desc *desc;
359 desc = xsk_ring_cons__rx_desc(rx, idx_rx++);
362 pkt = xsk_umem__get_data(rxq->umem->mz->addr, addr);
364 rte_memcpy(rte_pktmbuf_mtod(mbufs[i], void *), pkt, len);
365 rte_ring_enqueue(umem->buf_ring, (void *)addr);
366 rte_pktmbuf_pkt_len(mbufs[i]) = len;
367 rte_pktmbuf_data_len(mbufs[i]) = len;
372 xsk_ring_cons__release(rx, nb_pkts);
375 rxq->stats.rx_pkts += nb_pkts;
376 rxq->stats.rx_bytes += rx_bytes;
383 af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
385 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
386 return af_xdp_rx_zc(queue, bufs, nb_pkts);
388 return af_xdp_rx_cp(queue, bufs, nb_pkts);
393 eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
397 if (likely(nb_pkts <= ETH_AF_XDP_RX_BATCH_SIZE))
398 return af_xdp_rx(queue, bufs, nb_pkts);
400 /* Split larger batch into smaller batches of size
401 * ETH_AF_XDP_RX_BATCH_SIZE or less.
407 n = (uint16_t)RTE_MIN(nb_pkts, ETH_AF_XDP_RX_BATCH_SIZE);
408 ret = af_xdp_rx(queue, &bufs[nb_rx], n);
409 nb_rx = (uint16_t)(nb_rx + ret);
410 nb_pkts = (uint16_t)(nb_pkts - ret);
419 pull_umem_cq(struct xsk_umem_info *umem, int size, struct xsk_ring_cons *cq)
424 n = xsk_ring_cons__peek(cq, size, &idx_cq);
426 for (i = 0; i < n; i++) {
428 addr = *xsk_ring_cons__comp_addr(cq, idx_cq++);
429 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
430 addr = xsk_umem__extract_addr(addr);
431 rte_pktmbuf_free((struct rte_mbuf *)
432 xsk_umem__get_data(umem->buffer,
433 addr + umem->mb_pool->header_size));
435 rte_ring_enqueue(umem->buf_ring, (void *)addr);
439 xsk_ring_cons__release(cq, n);
443 kick_tx(struct pkt_tx_queue *txq, struct xsk_ring_cons *cq)
445 struct xsk_umem_info *umem = txq->umem;
447 pull_umem_cq(umem, XSK_RING_CONS__DEFAULT_NUM_DESCS, cq);
449 #if defined(XDP_USE_NEED_WAKEUP)
450 if (xsk_ring_prod__needs_wakeup(&txq->tx))
452 while (send(xsk_socket__fd(txq->pair->xsk), NULL,
453 0, MSG_DONTWAIT) < 0) {
454 /* some thing unexpected */
455 if (errno != EBUSY && errno != EAGAIN && errno != EINTR)
458 /* pull from completion queue to leave more space */
461 XSK_RING_CONS__DEFAULT_NUM_DESCS,
466 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
468 af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
470 struct pkt_tx_queue *txq = queue;
471 struct xsk_umem_info *umem = txq->umem;
472 struct rte_mbuf *mbuf;
473 unsigned long tx_bytes = 0;
477 struct xdp_desc *desc;
478 uint64_t addr, offset;
479 struct xsk_ring_cons *cq = &txq->pair->cq;
480 uint32_t free_thresh = cq->size >> 1;
482 if (xsk_cons_nb_avail(cq, free_thresh) >= free_thresh)
483 pull_umem_cq(umem, XSK_RING_CONS__DEFAULT_NUM_DESCS, cq);
485 for (i = 0; i < nb_pkts; i++) {
488 if (mbuf->pool == umem->mb_pool) {
489 if (!xsk_ring_prod__reserve(&txq->tx, 1, &idx_tx)) {
491 if (!xsk_ring_prod__reserve(&txq->tx, 1,
495 desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx);
496 desc->len = mbuf->pkt_len;
497 addr = (uint64_t)mbuf - (uint64_t)umem->buffer -
498 umem->mb_pool->header_size;
499 offset = rte_pktmbuf_mtod(mbuf, uint64_t) -
501 umem->mb_pool->header_size;
502 offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT;
503 desc->addr = addr | offset;
506 struct rte_mbuf *local_mbuf =
507 rte_pktmbuf_alloc(umem->mb_pool);
510 if (local_mbuf == NULL)
513 if (!xsk_ring_prod__reserve(&txq->tx, 1, &idx_tx)) {
514 rte_pktmbuf_free(local_mbuf);
519 desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx);
520 desc->len = mbuf->pkt_len;
522 addr = (uint64_t)local_mbuf - (uint64_t)umem->buffer -
523 umem->mb_pool->header_size;
524 offset = rte_pktmbuf_mtod(local_mbuf, uint64_t) -
525 (uint64_t)local_mbuf +
526 umem->mb_pool->header_size;
527 pkt = xsk_umem__get_data(umem->buffer, addr + offset);
528 offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT;
529 desc->addr = addr | offset;
530 rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
532 rte_pktmbuf_free(mbuf);
536 tx_bytes += mbuf->pkt_len;
542 xsk_ring_prod__submit(&txq->tx, count);
544 txq->stats.tx_pkts += count;
545 txq->stats.tx_bytes += tx_bytes;
546 txq->stats.tx_dropped += nb_pkts - count;
552 af_xdp_tx_cp(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
554 struct pkt_tx_queue *txq = queue;
555 struct xsk_umem_info *umem = txq->umem;
556 struct rte_mbuf *mbuf;
557 void *addrs[ETH_AF_XDP_TX_BATCH_SIZE];
558 unsigned long tx_bytes = 0;
561 struct xsk_ring_cons *cq = &txq->pair->cq;
563 pull_umem_cq(umem, nb_pkts, cq);
565 nb_pkts = rte_ring_dequeue_bulk(umem->buf_ring, addrs,
570 if (xsk_ring_prod__reserve(&txq->tx, nb_pkts, &idx_tx) != nb_pkts) {
572 rte_ring_enqueue_bulk(umem->buf_ring, addrs, nb_pkts, NULL);
576 for (i = 0; i < nb_pkts; i++) {
577 struct xdp_desc *desc;
580 desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx + i);
582 desc->len = mbuf->pkt_len;
584 desc->addr = (uint64_t)addrs[i];
585 pkt = xsk_umem__get_data(umem->mz->addr,
587 rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *), desc->len);
588 tx_bytes += mbuf->pkt_len;
589 rte_pktmbuf_free(mbuf);
592 xsk_ring_prod__submit(&txq->tx, nb_pkts);
596 txq->stats.tx_pkts += nb_pkts;
597 txq->stats.tx_bytes += tx_bytes;
603 af_xdp_tx_cp_batch(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
607 if (likely(nb_pkts <= ETH_AF_XDP_TX_BATCH_SIZE))
608 return af_xdp_tx_cp(queue, bufs, nb_pkts);
614 /* Split larger batch into smaller batches of size
615 * ETH_AF_XDP_TX_BATCH_SIZE or less.
617 n = (uint16_t)RTE_MIN(nb_pkts, ETH_AF_XDP_TX_BATCH_SIZE);
618 ret = af_xdp_tx_cp(queue, &bufs[nb_tx], n);
619 nb_tx = (uint16_t)(nb_tx + ret);
620 nb_pkts = (uint16_t)(nb_pkts - ret);
630 eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
632 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
633 return af_xdp_tx_zc(queue, bufs, nb_pkts);
635 return af_xdp_tx_cp_batch(queue, bufs, nb_pkts);
640 eth_dev_start(struct rte_eth_dev *dev)
642 dev->data->dev_link.link_status = ETH_LINK_UP;
647 /* This function gets called when the current port gets stopped. */
649 eth_dev_stop(struct rte_eth_dev *dev)
651 dev->data->dev_link.link_status = ETH_LINK_DOWN;
655 /* Find ethdev in list */
656 static inline struct internal_list *
657 find_internal_resource(struct pmd_internals *port_int)
660 struct internal_list *list = NULL;
662 if (port_int == NULL)
665 pthread_mutex_lock(&internal_list_lock);
667 TAILQ_FOREACH(list, &internal_list, next) {
668 struct pmd_internals *list_int =
669 list->eth_dev->data->dev_private;
670 if (list_int == port_int) {
676 pthread_mutex_unlock(&internal_list_lock);
684 /* Check if the netdev,qid context already exists */
686 ctx_exists(struct pkt_rx_queue *rxq, const char *ifname,
687 struct pkt_rx_queue *list_rxq, const char *list_ifname)
691 if (rxq->xsk_queue_idx == list_rxq->xsk_queue_idx &&
692 !strncmp(ifname, list_ifname, IFNAMSIZ)) {
693 AF_XDP_LOG(ERR, "ctx %s,%i already exists, cannot share umem\n",
694 ifname, rxq->xsk_queue_idx);
701 /* Get a pointer to an existing UMEM which overlays the rxq's mb_pool */
703 get_shared_umem(struct pkt_rx_queue *rxq, const char *ifname,
704 struct xsk_umem_info **umem)
706 struct internal_list *list;
707 struct pmd_internals *internals;
709 struct rte_mempool *mb_pool = rxq->mb_pool;
714 pthread_mutex_lock(&internal_list_lock);
716 TAILQ_FOREACH(list, &internal_list, next) {
717 internals = list->eth_dev->data->dev_private;
718 for (i = 0; i < internals->queue_cnt; i++) {
719 struct pkt_rx_queue *list_rxq =
720 &internals->rx_queues[i];
723 if (mb_pool == internals->rx_queues[i].mb_pool) {
724 if (ctx_exists(rxq, ifname, list_rxq,
725 internals->if_name)) {
730 &internals->rx_queues[i].umem->refcnt,
732 *umem = internals->rx_queues[i].umem;
740 pthread_mutex_unlock(&internal_list_lock);
746 eth_dev_configure(struct rte_eth_dev *dev)
748 struct pmd_internals *internal = dev->data->dev_private;
750 /* rx/tx must be paired */
751 if (dev->data->nb_rx_queues != dev->data->nb_tx_queues)
754 if (internal->shared_umem) {
755 struct internal_list *list = NULL;
756 const char *name = dev->device->name;
758 /* Ensure PMD is not already inserted into the list */
759 list = find_internal_resource(internal);
763 list = rte_zmalloc_socket(name, sizeof(*list), 0,
764 dev->device->numa_node);
769 pthread_mutex_lock(&internal_list_lock);
770 TAILQ_INSERT_TAIL(&internal_list, list, next);
771 pthread_mutex_unlock(&internal_list_lock);
778 eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
780 struct pmd_internals *internals = dev->data->dev_private;
782 dev_info->if_index = internals->if_index;
783 dev_info->max_mac_addrs = 1;
784 dev_info->max_rx_pktlen = ETH_FRAME_LEN;
785 dev_info->max_rx_queues = internals->queue_cnt;
786 dev_info->max_tx_queues = internals->queue_cnt;
788 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
789 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
790 dev_info->max_mtu = getpagesize() -
791 sizeof(struct rte_mempool_objhdr) -
792 sizeof(struct rte_mbuf) -
793 RTE_PKTMBUF_HEADROOM - XDP_PACKET_HEADROOM;
795 dev_info->max_mtu = ETH_AF_XDP_FRAME_SIZE - XDP_PACKET_HEADROOM;
798 dev_info->default_rxportconf.nb_queues = 1;
799 dev_info->default_txportconf.nb_queues = 1;
800 dev_info->default_rxportconf.ring_size = ETH_AF_XDP_DFLT_NUM_DESCS;
801 dev_info->default_txportconf.ring_size = ETH_AF_XDP_DFLT_NUM_DESCS;
807 eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
809 struct pmd_internals *internals = dev->data->dev_private;
810 struct xdp_statistics xdp_stats;
811 struct pkt_rx_queue *rxq;
812 struct pkt_tx_queue *txq;
816 for (i = 0; i < dev->data->nb_rx_queues; i++) {
817 optlen = sizeof(struct xdp_statistics);
818 rxq = &internals->rx_queues[i];
820 stats->q_ipackets[i] = rxq->stats.rx_pkts;
821 stats->q_ibytes[i] = rxq->stats.rx_bytes;
823 stats->q_opackets[i] = txq->stats.tx_pkts;
824 stats->q_obytes[i] = txq->stats.tx_bytes;
826 stats->ipackets += stats->q_ipackets[i];
827 stats->ibytes += stats->q_ibytes[i];
828 stats->imissed += rxq->stats.rx_dropped;
829 stats->oerrors += txq->stats.tx_dropped;
830 ret = getsockopt(xsk_socket__fd(rxq->xsk), SOL_XDP,
831 XDP_STATISTICS, &xdp_stats, &optlen);
833 AF_XDP_LOG(ERR, "getsockopt() failed for XDP_STATISTICS.\n");
836 stats->imissed += xdp_stats.rx_dropped;
838 stats->opackets += stats->q_opackets[i];
839 stats->obytes += stats->q_obytes[i];
846 eth_stats_reset(struct rte_eth_dev *dev)
848 struct pmd_internals *internals = dev->data->dev_private;
851 for (i = 0; i < internals->queue_cnt; i++) {
852 memset(&internals->rx_queues[i].stats, 0,
853 sizeof(struct rx_stats));
854 memset(&internals->tx_queues[i].stats, 0,
855 sizeof(struct tx_stats));
862 remove_xdp_program(struct pmd_internals *internals)
864 uint32_t curr_prog_id = 0;
866 if (bpf_get_link_xdp_id(internals->if_index, &curr_prog_id,
867 XDP_FLAGS_UPDATE_IF_NOEXIST)) {
868 AF_XDP_LOG(ERR, "bpf_get_link_xdp_id failed\n");
871 bpf_set_link_xdp_fd(internals->if_index, -1,
872 XDP_FLAGS_UPDATE_IF_NOEXIST);
876 xdp_umem_destroy(struct xsk_umem_info *umem)
878 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
879 umem->mb_pool = NULL;
881 rte_memzone_free(umem->mz);
884 rte_ring_free(umem->buf_ring);
885 umem->buf_ring = NULL;
892 eth_dev_close(struct rte_eth_dev *dev)
894 struct pmd_internals *internals = dev->data->dev_private;
895 struct pkt_rx_queue *rxq;
898 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
901 AF_XDP_LOG(INFO, "Closing AF_XDP ethdev on numa socket %u\n",
904 for (i = 0; i < internals->queue_cnt; i++) {
905 rxq = &internals->rx_queues[i];
906 if (rxq->umem == NULL)
908 xsk_socket__delete(rxq->xsk);
910 if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE)
912 (void)xsk_umem__delete(rxq->umem->umem);
913 xdp_umem_destroy(rxq->umem);
916 /* free pkt_tx_queue */
922 * MAC is not allocated dynamically, setting it to NULL would prevent
923 * from releasing it in rte_eth_dev_release_port.
925 dev->data->mac_addrs = NULL;
927 remove_xdp_program(internals);
929 if (internals->shared_umem) {
930 struct internal_list *list;
932 /* Remove ethdev from list used to track and share UMEMs */
933 list = find_internal_resource(internals);
935 pthread_mutex_lock(&internal_list_lock);
936 TAILQ_REMOVE(&internal_list, list, next);
937 pthread_mutex_unlock(&internal_list_lock);
946 eth_queue_release(void *q __rte_unused)
951 eth_link_update(struct rte_eth_dev *dev __rte_unused,
952 int wait_to_complete __rte_unused)
957 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
958 static inline uintptr_t get_base_addr(struct rte_mempool *mp, uint64_t *align)
960 struct rte_mempool_memhdr *memhdr;
961 uintptr_t memhdr_addr, aligned_addr;
963 memhdr = STAILQ_FIRST(&mp->mem_list);
964 memhdr_addr = (uintptr_t)memhdr->addr;
965 aligned_addr = memhdr_addr & ~(getpagesize() - 1);
966 *align = memhdr_addr - aligned_addr;
972 xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
973 struct pkt_rx_queue *rxq)
975 struct xsk_umem_info *umem = NULL;
977 struct xsk_umem_config usr_config = {
978 .fill_size = ETH_AF_XDP_DFLT_NUM_DESCS * 2,
979 .comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
980 .flags = XDP_UMEM_UNALIGNED_CHUNK_FLAG};
981 void *base_addr = NULL;
982 struct rte_mempool *mb_pool = rxq->mb_pool;
983 uint64_t umem_size, align = 0;
985 if (internals->shared_umem) {
986 if (get_shared_umem(rxq, internals->if_name, &umem) < 0)
990 __atomic_load_n(&umem->refcnt, __ATOMIC_ACQUIRE) <
992 AF_XDP_LOG(INFO, "%s,qid%i sharing UMEM\n",
993 internals->if_name, rxq->xsk_queue_idx);
994 __atomic_fetch_add(&umem->refcnt, 1, __ATOMIC_ACQUIRE);
999 usr_config.frame_size =
1000 rte_mempool_calc_obj_size(mb_pool->elt_size,
1001 mb_pool->flags, NULL);
1002 usr_config.frame_headroom = mb_pool->header_size +
1003 sizeof(struct rte_mbuf) +
1004 rte_pktmbuf_priv_size(mb_pool) +
1005 RTE_PKTMBUF_HEADROOM;
1007 umem = rte_zmalloc_socket("umem", sizeof(*umem), 0,
1010 AF_XDP_LOG(ERR, "Failed to allocate umem info");
1014 umem->mb_pool = mb_pool;
1015 base_addr = (void *)get_base_addr(mb_pool, &align);
1016 umem_size = (uint64_t)mb_pool->populated_size *
1017 (uint64_t)usr_config.frame_size +
1020 ret = xsk_umem__create(&umem->umem, base_addr, umem_size,
1021 &rxq->fq, &rxq->cq, &usr_config);
1023 AF_XDP_LOG(ERR, "Failed to create umem");
1026 umem->buffer = base_addr;
1028 if (internals->shared_umem) {
1029 umem->max_xsks = mb_pool->populated_size /
1030 ETH_AF_XDP_NUM_BUFFERS;
1031 AF_XDP_LOG(INFO, "Max xsks for UMEM %s: %u\n",
1032 mb_pool->name, umem->max_xsks);
1035 __atomic_store_n(&umem->refcnt, 1, __ATOMIC_RELEASE);
1040 xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
1041 struct pkt_rx_queue *rxq)
1043 struct xsk_umem_info *umem;
1044 const struct rte_memzone *mz;
1045 struct xsk_umem_config usr_config = {
1046 .fill_size = ETH_AF_XDP_DFLT_NUM_DESCS,
1047 .comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
1048 .frame_size = ETH_AF_XDP_FRAME_SIZE,
1049 .frame_headroom = 0 };
1050 char ring_name[RTE_RING_NAMESIZE];
1051 char mz_name[RTE_MEMZONE_NAMESIZE];
1055 umem = rte_zmalloc_socket("umem", sizeof(*umem), 0, rte_socket_id());
1057 AF_XDP_LOG(ERR, "Failed to allocate umem info");
1061 snprintf(ring_name, sizeof(ring_name), "af_xdp_ring_%s_%u",
1062 internals->if_name, rxq->xsk_queue_idx);
1063 umem->buf_ring = rte_ring_create(ring_name,
1064 ETH_AF_XDP_NUM_BUFFERS,
1067 if (umem->buf_ring == NULL) {
1068 AF_XDP_LOG(ERR, "Failed to create rte_ring\n");
1072 for (i = 0; i < ETH_AF_XDP_NUM_BUFFERS; i++)
1073 rte_ring_enqueue(umem->buf_ring,
1074 (void *)(i * ETH_AF_XDP_FRAME_SIZE));
1076 snprintf(mz_name, sizeof(mz_name), "af_xdp_umem_%s_%u",
1077 internals->if_name, rxq->xsk_queue_idx);
1078 mz = rte_memzone_reserve_aligned(mz_name,
1079 ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
1080 rte_socket_id(), RTE_MEMZONE_IOVA_CONTIG,
1083 AF_XDP_LOG(ERR, "Failed to reserve memzone for af_xdp umem.\n");
1087 ret = xsk_umem__create(&umem->umem, mz->addr,
1088 ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
1093 AF_XDP_LOG(ERR, "Failed to create umem");
1102 xdp_umem_destroy(umem);
1107 load_custom_xdp_prog(const char *prog_path, int if_index)
1109 int ret, prog_fd = -1;
1110 struct bpf_object *obj;
1111 struct bpf_map *map;
1113 ret = bpf_prog_load(prog_path, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
1115 AF_XDP_LOG(ERR, "Failed to load program %s\n", prog_path);
1120 * The loaded program must provision for a map of xsks, such that some
1121 * traffic can be redirected to userspace. When the xsk is created,
1122 * libbpf inserts it into the map.
1124 map = bpf_object__find_map_by_name(obj, "xsks_map");
1126 AF_XDP_LOG(ERR, "Failed to find xsks_map in %s\n", prog_path);
1130 /* Link the program with the given network device */
1131 ret = bpf_set_link_xdp_fd(if_index, prog_fd,
1132 XDP_FLAGS_UPDATE_IF_NOEXIST);
1134 AF_XDP_LOG(ERR, "Failed to set prog fd %d on interface\n",
1139 AF_XDP_LOG(INFO, "Successfully loaded XDP program %s with fd %d\n",
1140 prog_path, prog_fd);
1146 xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
1149 struct xsk_socket_config cfg;
1150 struct pkt_tx_queue *txq = rxq->pair;
1152 int reserve_size = ETH_AF_XDP_DFLT_NUM_DESCS;
1153 struct rte_mbuf *fq_bufs[reserve_size];
1155 rxq->umem = xdp_umem_configure(internals, rxq);
1156 if (rxq->umem == NULL)
1158 txq->umem = rxq->umem;
1160 cfg.rx_size = ring_size;
1161 cfg.tx_size = ring_size;
1162 cfg.libbpf_flags = 0;
1163 cfg.xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
1166 #if defined(XDP_USE_NEED_WAKEUP)
1167 cfg.bind_flags |= XDP_USE_NEED_WAKEUP;
1170 if (strnlen(internals->prog_path, PATH_MAX) &&
1171 !internals->custom_prog_configured) {
1172 ret = load_custom_xdp_prog(internals->prog_path,
1173 internals->if_index);
1175 AF_XDP_LOG(ERR, "Failed to load custom XDP program %s\n",
1176 internals->prog_path);
1179 internals->custom_prog_configured = 1;
1182 if (internals->shared_umem)
1183 ret = create_shared_socket(&rxq->xsk, internals->if_name,
1184 rxq->xsk_queue_idx, rxq->umem->umem, &rxq->rx,
1185 &txq->tx, &rxq->fq, &rxq->cq, &cfg);
1187 ret = xsk_socket__create(&rxq->xsk, internals->if_name,
1188 rxq->xsk_queue_idx, rxq->umem->umem, &rxq->rx,
1192 AF_XDP_LOG(ERR, "Failed to create xsk socket.\n");
1196 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
1197 ret = rte_pktmbuf_alloc_bulk(rxq->umem->mb_pool, fq_bufs, reserve_size);
1199 AF_XDP_LOG(DEBUG, "Failed to get enough buffers for fq.\n");
1203 ret = reserve_fill_queue(rxq->umem, reserve_size, fq_bufs, &rxq->fq);
1205 xsk_socket__delete(rxq->xsk);
1206 AF_XDP_LOG(ERR, "Failed to reserve fill queue.\n");
1213 if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) == 0)
1214 xdp_umem_destroy(rxq->umem);
1220 eth_rx_queue_setup(struct rte_eth_dev *dev,
1221 uint16_t rx_queue_id,
1222 uint16_t nb_rx_desc,
1223 unsigned int socket_id __rte_unused,
1224 const struct rte_eth_rxconf *rx_conf __rte_unused,
1225 struct rte_mempool *mb_pool)
1227 struct pmd_internals *internals = dev->data->dev_private;
1228 struct pkt_rx_queue *rxq;
1231 rxq = &internals->rx_queues[rx_queue_id];
1233 AF_XDP_LOG(INFO, "Set up rx queue, rx queue id: %d, xsk queue id: %d\n",
1234 rx_queue_id, rxq->xsk_queue_idx);
1236 #ifndef XDP_UMEM_UNALIGNED_CHUNK_FLAG
1237 uint32_t buf_size, data_size;
1239 /* Now get the space available for data in the mbuf */
1240 buf_size = rte_pktmbuf_data_room_size(mb_pool) -
1241 RTE_PKTMBUF_HEADROOM;
1242 data_size = ETH_AF_XDP_FRAME_SIZE;
1244 if (data_size > buf_size) {
1245 AF_XDP_LOG(ERR, "%s: %d bytes will not fit in mbuf (%d bytes)\n",
1246 dev->device->name, data_size, buf_size);
1252 rxq->mb_pool = mb_pool;
1254 if (xsk_configure(internals, rxq, nb_rx_desc)) {
1255 AF_XDP_LOG(ERR, "Failed to configure xdp socket\n");
1260 rxq->fds[0].fd = xsk_socket__fd(rxq->xsk);
1261 rxq->fds[0].events = POLLIN;
1263 dev->data->rx_queues[rx_queue_id] = rxq;
1271 eth_tx_queue_setup(struct rte_eth_dev *dev,
1272 uint16_t tx_queue_id,
1273 uint16_t nb_tx_desc __rte_unused,
1274 unsigned int socket_id __rte_unused,
1275 const struct rte_eth_txconf *tx_conf __rte_unused)
1277 struct pmd_internals *internals = dev->data->dev_private;
1278 struct pkt_tx_queue *txq;
1280 txq = &internals->tx_queues[tx_queue_id];
1282 dev->data->tx_queues[tx_queue_id] = txq;
1287 eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1289 struct pmd_internals *internals = dev->data->dev_private;
1290 struct ifreq ifr = { .ifr_mtu = mtu };
1294 s = socket(PF_INET, SOCK_DGRAM, 0);
1298 strlcpy(ifr.ifr_name, internals->if_name, IFNAMSIZ);
1299 ret = ioctl(s, SIOCSIFMTU, &ifr);
1302 return (ret < 0) ? -errno : 0;
1306 eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
1312 s = socket(PF_INET, SOCK_DGRAM, 0);
1316 strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
1317 if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) {
1321 ifr.ifr_flags &= mask;
1322 ifr.ifr_flags |= flags;
1323 if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) {
1333 eth_dev_promiscuous_enable(struct rte_eth_dev *dev)
1335 struct pmd_internals *internals = dev->data->dev_private;
1337 return eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0);
1341 eth_dev_promiscuous_disable(struct rte_eth_dev *dev)
1343 struct pmd_internals *internals = dev->data->dev_private;
1345 return eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC);
1348 static const struct eth_dev_ops ops = {
1349 .dev_start = eth_dev_start,
1350 .dev_stop = eth_dev_stop,
1351 .dev_close = eth_dev_close,
1352 .dev_configure = eth_dev_configure,
1353 .dev_infos_get = eth_dev_info,
1354 .mtu_set = eth_dev_mtu_set,
1355 .promiscuous_enable = eth_dev_promiscuous_enable,
1356 .promiscuous_disable = eth_dev_promiscuous_disable,
1357 .rx_queue_setup = eth_rx_queue_setup,
1358 .tx_queue_setup = eth_tx_queue_setup,
1359 .rx_queue_release = eth_queue_release,
1360 .tx_queue_release = eth_queue_release,
1361 .link_update = eth_link_update,
1362 .stats_get = eth_stats_get,
1363 .stats_reset = eth_stats_reset,
1366 /** parse integer from integer argument */
1368 parse_integer_arg(const char *key __rte_unused,
1369 const char *value, void *extra_args)
1371 int *i = (int *)extra_args;
1374 *i = strtol(value, &end, 10);
1376 AF_XDP_LOG(ERR, "Argument has to be positive.\n");
1383 /** parse name argument */
1385 parse_name_arg(const char *key __rte_unused,
1386 const char *value, void *extra_args)
1388 char *name = extra_args;
1390 if (strnlen(value, IFNAMSIZ) > IFNAMSIZ - 1) {
1391 AF_XDP_LOG(ERR, "Invalid name %s, should be less than %u bytes.\n",
1396 strlcpy(name, value, IFNAMSIZ);
1401 /** parse xdp prog argument */
1403 parse_prog_arg(const char *key __rte_unused,
1404 const char *value, void *extra_args)
1406 char *path = extra_args;
1408 if (strnlen(value, PATH_MAX) == PATH_MAX) {
1409 AF_XDP_LOG(ERR, "Invalid path %s, should be less than %u bytes.\n",
1414 if (access(value, F_OK) != 0) {
1415 AF_XDP_LOG(ERR, "Error accessing %s: %s\n",
1416 value, strerror(errno));
1420 strlcpy(path, value, PATH_MAX);
1426 xdp_get_channels_info(const char *if_name, int *max_queues,
1427 int *combined_queues)
1429 struct ethtool_channels channels;
1433 fd = socket(AF_INET, SOCK_DGRAM, 0);
1437 channels.cmd = ETHTOOL_GCHANNELS;
1438 ifr.ifr_data = (void *)&channels;
1439 strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
1440 ret = ioctl(fd, SIOCETHTOOL, &ifr);
1442 if (errno == EOPNOTSUPP) {
1450 if (channels.max_combined == 0 || errno == EOPNOTSUPP) {
1451 /* If the device says it has no channels, then all traffic
1452 * is sent to a single stream, so max queues = 1.
1455 *combined_queues = 1;
1457 *max_queues = channels.max_combined;
1458 *combined_queues = channels.combined_count;
1467 parse_parameters(struct rte_kvargs *kvlist, char *if_name, int *start_queue,
1468 int *queue_cnt, int *shared_umem, char *prog_path)
1472 ret = rte_kvargs_process(kvlist, ETH_AF_XDP_IFACE_ARG,
1473 &parse_name_arg, if_name);
1477 ret = rte_kvargs_process(kvlist, ETH_AF_XDP_START_QUEUE_ARG,
1478 &parse_integer_arg, start_queue);
1482 ret = rte_kvargs_process(kvlist, ETH_AF_XDP_QUEUE_COUNT_ARG,
1483 &parse_integer_arg, queue_cnt);
1484 if (ret < 0 || *queue_cnt <= 0) {
1489 ret = rte_kvargs_process(kvlist, ETH_AF_XDP_SHARED_UMEM_ARG,
1490 &parse_integer_arg, shared_umem);
1494 ret = rte_kvargs_process(kvlist, ETH_AF_XDP_PROG_ARG,
1495 &parse_prog_arg, prog_path);
1500 rte_kvargs_free(kvlist);
1505 get_iface_info(const char *if_name,
1506 struct rte_ether_addr *eth_addr,
1510 int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
1515 strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
1516 if (ioctl(sock, SIOCGIFINDEX, &ifr))
1519 *if_index = ifr.ifr_ifindex;
1521 if (ioctl(sock, SIOCGIFHWADDR, &ifr))
1524 rte_memcpy(eth_addr, ifr.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN);
1534 static struct rte_eth_dev *
1535 init_internals(struct rte_vdev_device *dev, const char *if_name,
1536 int start_queue_idx, int queue_cnt, int shared_umem,
1537 const char *prog_path)
1539 const char *name = rte_vdev_device_name(dev);
1540 const unsigned int numa_node = dev->device.numa_node;
1541 struct pmd_internals *internals;
1542 struct rte_eth_dev *eth_dev;
1546 internals = rte_zmalloc_socket(name, sizeof(*internals), 0, numa_node);
1547 if (internals == NULL)
1550 internals->start_queue_idx = start_queue_idx;
1551 internals->queue_cnt = queue_cnt;
1552 strlcpy(internals->if_name, if_name, IFNAMSIZ);
1553 strlcpy(internals->prog_path, prog_path, PATH_MAX);
1554 internals->custom_prog_configured = 0;
1556 #ifndef ETH_AF_XDP_SHARED_UMEM
1558 AF_XDP_LOG(ERR, "Shared UMEM feature not available. "
1559 "Check kernel and libbpf version\n");
1560 goto err_free_internals;
1563 internals->shared_umem = shared_umem;
1565 if (xdp_get_channels_info(if_name, &internals->max_queue_cnt,
1566 &internals->combined_queue_cnt)) {
1567 AF_XDP_LOG(ERR, "Failed to get channel info of interface: %s\n",
1569 goto err_free_internals;
1572 if (queue_cnt > internals->combined_queue_cnt) {
1573 AF_XDP_LOG(ERR, "Specified queue count %d is larger than combined queue count %d.\n",
1574 queue_cnt, internals->combined_queue_cnt);
1575 goto err_free_internals;
1578 internals->rx_queues = rte_zmalloc_socket(NULL,
1579 sizeof(struct pkt_rx_queue) * queue_cnt,
1581 if (internals->rx_queues == NULL) {
1582 AF_XDP_LOG(ERR, "Failed to allocate memory for rx queues.\n");
1583 goto err_free_internals;
1586 internals->tx_queues = rte_zmalloc_socket(NULL,
1587 sizeof(struct pkt_tx_queue) * queue_cnt,
1589 if (internals->tx_queues == NULL) {
1590 AF_XDP_LOG(ERR, "Failed to allocate memory for tx queues.\n");
1593 for (i = 0; i < queue_cnt; i++) {
1594 internals->tx_queues[i].pair = &internals->rx_queues[i];
1595 internals->rx_queues[i].pair = &internals->tx_queues[i];
1596 internals->rx_queues[i].xsk_queue_idx = start_queue_idx + i;
1597 internals->tx_queues[i].xsk_queue_idx = start_queue_idx + i;
1600 ret = get_iface_info(if_name, &internals->eth_addr,
1601 &internals->if_index);
1605 eth_dev = rte_eth_vdev_allocate(dev, 0);
1606 if (eth_dev == NULL)
1609 eth_dev->data->dev_private = internals;
1610 eth_dev->data->dev_link = pmd_link;
1611 eth_dev->data->mac_addrs = &internals->eth_addr;
1612 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1613 eth_dev->dev_ops = &ops;
1614 eth_dev->rx_pkt_burst = eth_af_xdp_rx;
1615 eth_dev->tx_pkt_burst = eth_af_xdp_tx;
1617 #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
1618 AF_XDP_LOG(INFO, "Zero copy between umem and mbuf enabled.\n");
1624 rte_free(internals->tx_queues);
1626 rte_free(internals->rx_queues);
1628 rte_free(internals);
1633 rte_pmd_af_xdp_probe(struct rte_vdev_device *dev)
1635 struct rte_kvargs *kvlist;
1636 char if_name[IFNAMSIZ] = {'\0'};
1637 int xsk_start_queue_idx = ETH_AF_XDP_DFLT_START_QUEUE_IDX;
1638 int xsk_queue_cnt = ETH_AF_XDP_DFLT_QUEUE_COUNT;
1639 int shared_umem = 0;
1640 char prog_path[PATH_MAX] = {'\0'};
1641 struct rte_eth_dev *eth_dev = NULL;
1644 AF_XDP_LOG(INFO, "Initializing pmd_af_xdp for %s\n",
1645 rte_vdev_device_name(dev));
1647 name = rte_vdev_device_name(dev);
1648 if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
1649 strlen(rte_vdev_device_args(dev)) == 0) {
1650 eth_dev = rte_eth_dev_attach_secondary(name);
1651 if (eth_dev == NULL) {
1652 AF_XDP_LOG(ERR, "Failed to probe %s\n", name);
1655 eth_dev->dev_ops = &ops;
1656 rte_eth_dev_probing_finish(eth_dev);
1660 kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
1661 if (kvlist == NULL) {
1662 AF_XDP_LOG(ERR, "Invalid kvargs key\n");
1666 if (dev->device.numa_node == SOCKET_ID_ANY)
1667 dev->device.numa_node = rte_socket_id();
1669 if (parse_parameters(kvlist, if_name, &xsk_start_queue_idx,
1670 &xsk_queue_cnt, &shared_umem, prog_path) < 0) {
1671 AF_XDP_LOG(ERR, "Invalid kvargs value\n");
1675 if (strlen(if_name) == 0) {
1676 AF_XDP_LOG(ERR, "Network interface must be specified\n");
1680 eth_dev = init_internals(dev, if_name, xsk_start_queue_idx,
1681 xsk_queue_cnt, shared_umem, prog_path);
1682 if (eth_dev == NULL) {
1683 AF_XDP_LOG(ERR, "Failed to init internals\n");
1687 rte_eth_dev_probing_finish(eth_dev);
1693 rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
1695 struct rte_eth_dev *eth_dev = NULL;
1697 AF_XDP_LOG(INFO, "Removing AF_XDP ethdev on numa socket %u\n",
1703 /* find the ethdev entry */
1704 eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
1705 if (eth_dev == NULL)
1708 eth_dev_close(eth_dev);
1709 rte_eth_dev_release_port(eth_dev);
1715 static struct rte_vdev_driver pmd_af_xdp_drv = {
1716 .probe = rte_pmd_af_xdp_probe,
1717 .remove = rte_pmd_af_xdp_remove,
1720 RTE_PMD_REGISTER_VDEV(net_af_xdp, pmd_af_xdp_drv);
1721 RTE_PMD_REGISTER_PARAM_STRING(net_af_xdp,
1723 "start_queue=<int> "
1724 "queue_count=<int> "
1725 "shared_umem=<int> "
1726 "xdp_prog=<string> ");