1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation.
8 #include <netinet/in.h>
10 #include <sys/socket.h>
11 #include <sys/ioctl.h>
12 #include <linux/if_ether.h>
13 #include <linux/if_xdp.h>
14 #include <linux/if_link.h>
15 #include "af_xdp_deps.h"
18 #include <rte_ethdev.h>
19 #include <rte_ethdev_driver.h>
20 #include <rte_ethdev_vdev.h>
21 #include <rte_kvargs.h>
22 #include <rte_bus_vdev.h>
23 #include <rte_string_fns.h>
24 #include <rte_branch_prediction.h>
25 #include <rte_common.h>
26 #include <rte_config.h>
29 #include <rte_ether.h>
30 #include <rte_lcore.h>
32 #include <rte_memory.h>
33 #include <rte_memzone.h>
35 #include <rte_malloc.h>
50 static int af_xdp_logtype;
52 #define AF_XDP_LOG(level, fmt, args...) \
53 rte_log(RTE_LOG_ ## level, af_xdp_logtype, \
54 "%s(): " fmt, __func__, ##args)
56 #define ETH_AF_XDP_FRAME_SIZE XSK_UMEM__DEFAULT_FRAME_SIZE
57 #define ETH_AF_XDP_NUM_BUFFERS 4096
58 #define ETH_AF_XDP_DATA_HEADROOM 0
59 #define ETH_AF_XDP_DFLT_NUM_DESCS XSK_RING_CONS__DEFAULT_NUM_DESCS
60 #define ETH_AF_XDP_DFLT_QUEUE_IDX 0
62 #define ETH_AF_XDP_RX_BATCH_SIZE 32
63 #define ETH_AF_XDP_TX_BATCH_SIZE 32
65 #define ETH_AF_XDP_MAX_QUEUE_PAIRS 16
67 struct xsk_umem_info {
68 struct xsk_ring_prod fq;
69 struct xsk_ring_cons cq;
70 struct xsk_umem *umem;
71 struct rte_ring *buf_ring;
72 const struct rte_memzone *mz;
82 struct xsk_ring_cons rx;
83 struct xsk_umem_info *umem;
84 struct xsk_socket *xsk;
85 struct rte_mempool *mb_pool;
87 struct rx_stats stats;
89 struct pkt_tx_queue *pair;
100 struct xsk_ring_prod tx;
102 struct tx_stats stats;
104 struct pkt_rx_queue *pair;
108 struct pmd_internals {
110 char if_name[IFNAMSIZ];
112 struct ether_addr eth_addr;
113 struct xsk_umem_info *umem;
114 struct rte_mempool *mb_pool_share;
116 struct pkt_rx_queue rx_queues[ETH_AF_XDP_MAX_QUEUE_PAIRS];
117 struct pkt_tx_queue tx_queues[ETH_AF_XDP_MAX_QUEUE_PAIRS];
120 #define ETH_AF_XDP_IFACE_ARG "iface"
121 #define ETH_AF_XDP_QUEUE_IDX_ARG "queue"
123 static const char * const valid_arguments[] = {
124 ETH_AF_XDP_IFACE_ARG,
125 ETH_AF_XDP_QUEUE_IDX_ARG,
129 static const struct rte_eth_link pmd_link = {
130 .link_speed = ETH_SPEED_NUM_10G,
131 .link_duplex = ETH_LINK_FULL_DUPLEX,
132 .link_status = ETH_LINK_DOWN,
133 .link_autoneg = ETH_LINK_AUTONEG
137 reserve_fill_queue(struct xsk_umem_info *umem, uint16_t reserve_size)
139 struct xsk_ring_prod *fq = &umem->fq;
140 void *addrs[reserve_size];
144 if (rte_ring_dequeue_bulk(umem->buf_ring, addrs, reserve_size, NULL)
146 AF_XDP_LOG(DEBUG, "Failed to get enough buffers for fq.\n");
150 if (unlikely(!xsk_ring_prod__reserve(fq, reserve_size, &idx))) {
151 AF_XDP_LOG(DEBUG, "Failed to reserve enough fq descs.\n");
152 rte_ring_enqueue_bulk(umem->buf_ring, addrs,
157 for (i = 0; i < reserve_size; i++) {
160 fq_addr = xsk_ring_prod__fill_addr(fq, idx++);
161 *fq_addr = (uint64_t)addrs[i];
164 xsk_ring_prod__submit(fq, reserve_size);
170 eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
172 struct pkt_rx_queue *rxq = queue;
173 struct xsk_ring_cons *rx = &rxq->rx;
174 struct xsk_umem_info *umem = rxq->umem;
175 struct xsk_ring_prod *fq = &umem->fq;
177 uint32_t free_thresh = fq->size >> 1;
178 struct rte_mbuf *mbufs[ETH_AF_XDP_RX_BATCH_SIZE];
179 unsigned long dropped = 0;
180 unsigned long rx_bytes = 0;
183 nb_pkts = RTE_MIN(nb_pkts, ETH_AF_XDP_RX_BATCH_SIZE);
185 if (unlikely(rte_pktmbuf_alloc_bulk(rxq->mb_pool, mbufs, nb_pkts) != 0))
188 rcvd = xsk_ring_cons__peek(rx, nb_pkts, &idx_rx);
192 if (xsk_prod_nb_free(fq, free_thresh) >= free_thresh)
193 (void)reserve_fill_queue(umem, ETH_AF_XDP_RX_BATCH_SIZE);
195 for (i = 0; i < rcvd; i++) {
196 const struct xdp_desc *desc;
201 desc = xsk_ring_cons__rx_desc(rx, idx_rx++);
204 pkt = xsk_umem__get_data(rxq->umem->mz->addr, addr);
206 rte_memcpy(rte_pktmbuf_mtod(mbufs[i], void *), pkt, len);
207 rte_pktmbuf_pkt_len(mbufs[i]) = len;
208 rte_pktmbuf_data_len(mbufs[i]) = len;
212 rte_ring_enqueue(umem->buf_ring, (void *)addr);
215 xsk_ring_cons__release(rx, rcvd);
218 rxq->stats.rx_pkts += (rcvd - dropped);
219 rxq->stats.rx_bytes += rx_bytes;
223 rte_mempool_put_bulk(rxq->mb_pool, (void **)&mbufs[rcvd],
230 pull_umem_cq(struct xsk_umem_info *umem, int size)
232 struct xsk_ring_cons *cq = &umem->cq;
236 n = xsk_ring_cons__peek(cq, size, &idx_cq);
238 for (i = 0; i < n; i++) {
240 addr = *xsk_ring_cons__comp_addr(cq, idx_cq++);
241 rte_ring_enqueue(umem->buf_ring, (void *)addr);
244 xsk_ring_cons__release(cq, n);
248 kick_tx(struct pkt_tx_queue *txq)
250 struct xsk_umem_info *umem = txq->pair->umem;
252 while (send(xsk_socket__fd(txq->pair->xsk), NULL,
253 0, MSG_DONTWAIT) < 0) {
254 /* some thing unexpected */
255 if (errno != EBUSY && errno != EAGAIN && errno != EINTR)
258 /* pull from completion queue to leave more space */
260 pull_umem_cq(umem, ETH_AF_XDP_TX_BATCH_SIZE);
262 pull_umem_cq(umem, ETH_AF_XDP_TX_BATCH_SIZE);
266 eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
268 struct pkt_tx_queue *txq = queue;
269 struct xsk_umem_info *umem = txq->pair->umem;
270 struct rte_mbuf *mbuf;
271 void *addrs[ETH_AF_XDP_TX_BATCH_SIZE];
272 unsigned long tx_bytes = 0;
276 nb_pkts = RTE_MIN(nb_pkts, ETH_AF_XDP_TX_BATCH_SIZE);
278 pull_umem_cq(umem, nb_pkts);
280 nb_pkts = rte_ring_dequeue_bulk(umem->buf_ring, addrs,
285 if (xsk_ring_prod__reserve(&txq->tx, nb_pkts, &idx_tx) != nb_pkts) {
287 rte_ring_enqueue_bulk(umem->buf_ring, addrs, nb_pkts, NULL);
291 for (i = 0; i < nb_pkts; i++) {
292 struct xdp_desc *desc;
295 desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx + i);
298 desc->addr = (uint64_t)addrs[i];
299 desc->len = mbuf->pkt_len;
300 pkt = xsk_umem__get_data(umem->mz->addr,
302 rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
304 tx_bytes += mbuf->pkt_len;
306 rte_pktmbuf_free(mbuf);
309 xsk_ring_prod__submit(&txq->tx, nb_pkts);
313 txq->stats.tx_pkts += nb_pkts;
314 txq->stats.tx_bytes += tx_bytes;
320 eth_dev_start(struct rte_eth_dev *dev)
322 dev->data->dev_link.link_status = ETH_LINK_UP;
327 /* This function gets called when the current port gets stopped. */
329 eth_dev_stop(struct rte_eth_dev *dev)
331 dev->data->dev_link.link_status = ETH_LINK_DOWN;
335 eth_dev_configure(struct rte_eth_dev *dev)
337 /* rx/tx must be paired */
338 if (dev->data->nb_rx_queues != dev->data->nb_tx_queues)
345 eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
347 struct pmd_internals *internals = dev->data->dev_private;
349 dev_info->if_index = internals->if_index;
350 dev_info->max_mac_addrs = 1;
351 dev_info->max_rx_pktlen = ETH_FRAME_LEN;
352 dev_info->max_rx_queues = 1;
353 dev_info->max_tx_queues = 1;
355 dev_info->min_mtu = ETHER_MIN_MTU;
356 dev_info->max_mtu = ETH_AF_XDP_FRAME_SIZE - ETH_AF_XDP_DATA_HEADROOM;
358 dev_info->default_rxportconf.nb_queues = 1;
359 dev_info->default_txportconf.nb_queues = 1;
360 dev_info->default_rxportconf.ring_size = ETH_AF_XDP_DFLT_NUM_DESCS;
361 dev_info->default_txportconf.ring_size = ETH_AF_XDP_DFLT_NUM_DESCS;
365 eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
367 struct pmd_internals *internals = dev->data->dev_private;
368 struct xdp_statistics xdp_stats;
369 struct pkt_rx_queue *rxq;
373 for (i = 0; i < dev->data->nb_rx_queues; i++) {
374 optlen = sizeof(struct xdp_statistics);
375 rxq = &internals->rx_queues[i];
376 stats->q_ipackets[i] = internals->rx_queues[i].stats.rx_pkts;
377 stats->q_ibytes[i] = internals->rx_queues[i].stats.rx_bytes;
379 stats->q_opackets[i] = internals->tx_queues[i].stats.tx_pkts;
380 stats->q_obytes[i] = internals->tx_queues[i].stats.tx_bytes;
382 stats->ipackets += stats->q_ipackets[i];
383 stats->ibytes += stats->q_ibytes[i];
384 stats->imissed += internals->rx_queues[i].stats.rx_dropped;
385 ret = getsockopt(xsk_socket__fd(rxq->xsk), SOL_XDP,
386 XDP_STATISTICS, &xdp_stats, &optlen);
388 AF_XDP_LOG(ERR, "getsockopt() failed for XDP_STATISTICS.\n");
391 stats->imissed += xdp_stats.rx_dropped;
393 stats->opackets += stats->q_opackets[i];
394 stats->oerrors += internals->tx_queues[i].stats.err_pkts;
395 stats->obytes += stats->q_obytes[i];
402 eth_stats_reset(struct rte_eth_dev *dev)
404 struct pmd_internals *internals = dev->data->dev_private;
407 for (i = 0; i < ETH_AF_XDP_MAX_QUEUE_PAIRS; i++) {
408 memset(&internals->rx_queues[i].stats, 0,
409 sizeof(struct rx_stats));
410 memset(&internals->tx_queues[i].stats, 0,
411 sizeof(struct tx_stats));
416 remove_xdp_program(struct pmd_internals *internals)
418 uint32_t curr_prog_id = 0;
420 if (bpf_get_link_xdp_id(internals->if_index, &curr_prog_id,
421 XDP_FLAGS_UPDATE_IF_NOEXIST)) {
422 AF_XDP_LOG(ERR, "bpf_get_link_xdp_id failed\n");
425 bpf_set_link_xdp_fd(internals->if_index, -1,
426 XDP_FLAGS_UPDATE_IF_NOEXIST);
430 xdp_umem_destroy(struct xsk_umem_info *umem)
432 rte_memzone_free(umem->mz);
435 rte_ring_free(umem->buf_ring);
436 umem->buf_ring = NULL;
443 eth_dev_close(struct rte_eth_dev *dev)
445 struct pmd_internals *internals = dev->data->dev_private;
446 struct pkt_rx_queue *rxq;
449 AF_XDP_LOG(INFO, "Closing AF_XDP ethdev on numa socket %u\n",
452 for (i = 0; i < ETH_AF_XDP_MAX_QUEUE_PAIRS; i++) {
453 rxq = &internals->rx_queues[i];
454 if (rxq->umem == NULL)
456 xsk_socket__delete(rxq->xsk);
459 (void)xsk_umem__delete(internals->umem->umem);
462 * MAC is not allocated dynamically, setting it to NULL would prevent
463 * from releasing it in rte_eth_dev_release_port.
465 dev->data->mac_addrs = NULL;
467 xdp_umem_destroy(internals->umem);
469 remove_xdp_program(internals);
473 eth_queue_release(void *q __rte_unused)
478 eth_link_update(struct rte_eth_dev *dev __rte_unused,
479 int wait_to_complete __rte_unused)
485 xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals)
487 struct xsk_umem_info *umem;
488 const struct rte_memzone *mz;
489 struct xsk_umem_config usr_config = {
490 .fill_size = ETH_AF_XDP_DFLT_NUM_DESCS,
491 .comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
492 .frame_size = ETH_AF_XDP_FRAME_SIZE,
493 .frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
494 char ring_name[RTE_RING_NAMESIZE];
495 char mz_name[RTE_MEMZONE_NAMESIZE];
499 umem = rte_zmalloc_socket("umem", sizeof(*umem), 0, rte_socket_id());
501 AF_XDP_LOG(ERR, "Failed to allocate umem info");
505 snprintf(ring_name, sizeof(ring_name), "af_xdp_ring_%s_%u",
506 internals->if_name, internals->queue_idx);
507 umem->buf_ring = rte_ring_create(ring_name,
508 ETH_AF_XDP_NUM_BUFFERS,
511 if (umem->buf_ring == NULL) {
512 AF_XDP_LOG(ERR, "Failed to create rte_ring\n");
516 for (i = 0; i < ETH_AF_XDP_NUM_BUFFERS; i++)
517 rte_ring_enqueue(umem->buf_ring,
518 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
519 ETH_AF_XDP_DATA_HEADROOM));
521 snprintf(mz_name, sizeof(mz_name), "af_xdp_umem_%s_%u",
522 internals->if_name, internals->queue_idx);
523 mz = rte_memzone_reserve_aligned(mz_name,
524 ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
525 rte_socket_id(), RTE_MEMZONE_IOVA_CONTIG,
528 AF_XDP_LOG(ERR, "Failed to reserve memzone for af_xdp umem.\n");
532 ret = xsk_umem__create(&umem->umem, mz->addr,
533 ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
534 &umem->fq, &umem->cq,
538 AF_XDP_LOG(ERR, "Failed to create umem");
546 xdp_umem_destroy(umem);
551 xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
554 struct xsk_socket_config cfg;
555 struct pkt_tx_queue *txq = rxq->pair;
559 rxq->umem = xdp_umem_configure(internals);
560 if (rxq->umem == NULL)
563 cfg.rx_size = ring_size;
564 cfg.tx_size = ring_size;
565 cfg.libbpf_flags = 0;
566 cfg.xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
568 ret = xsk_socket__create(&rxq->xsk, internals->if_name,
569 internals->queue_idx, rxq->umem->umem, &rxq->rx,
572 AF_XDP_LOG(ERR, "Failed to create xsk socket.\n");
576 reserve_size = ETH_AF_XDP_DFLT_NUM_DESCS / 2;
577 ret = reserve_fill_queue(rxq->umem, reserve_size);
579 xsk_socket__delete(rxq->xsk);
580 AF_XDP_LOG(ERR, "Failed to reserve fill queue.\n");
587 xdp_umem_destroy(rxq->umem);
593 queue_reset(struct pmd_internals *internals, uint16_t queue_idx)
595 struct pkt_rx_queue *rxq = &internals->rx_queues[queue_idx];
596 struct pkt_tx_queue *txq = rxq->pair;
598 memset(rxq, 0, sizeof(*rxq));
599 memset(txq, 0, sizeof(*txq));
602 rxq->queue_idx = queue_idx;
603 txq->queue_idx = queue_idx;
607 eth_rx_queue_setup(struct rte_eth_dev *dev,
608 uint16_t rx_queue_id,
610 unsigned int socket_id __rte_unused,
611 const struct rte_eth_rxconf *rx_conf __rte_unused,
612 struct rte_mempool *mb_pool)
614 struct pmd_internals *internals = dev->data->dev_private;
615 uint32_t buf_size, data_size;
616 struct pkt_rx_queue *rxq;
619 rxq = &internals->rx_queues[rx_queue_id];
620 queue_reset(internals, rx_queue_id);
622 /* Now get the space available for data in the mbuf */
623 buf_size = rte_pktmbuf_data_room_size(mb_pool) -
624 RTE_PKTMBUF_HEADROOM;
625 data_size = ETH_AF_XDP_FRAME_SIZE - ETH_AF_XDP_DATA_HEADROOM;
627 if (data_size > buf_size) {
628 AF_XDP_LOG(ERR, "%s: %d bytes will not fit in mbuf (%d bytes)\n",
629 dev->device->name, data_size, buf_size);
634 rxq->mb_pool = mb_pool;
636 if (xsk_configure(internals, rxq, nb_rx_desc)) {
637 AF_XDP_LOG(ERR, "Failed to configure xdp socket\n");
642 internals->umem = rxq->umem;
644 dev->data->rx_queues[rx_queue_id] = rxq;
648 queue_reset(internals, rx_queue_id);
653 eth_tx_queue_setup(struct rte_eth_dev *dev,
654 uint16_t tx_queue_id,
655 uint16_t nb_tx_desc __rte_unused,
656 unsigned int socket_id __rte_unused,
657 const struct rte_eth_txconf *tx_conf __rte_unused)
659 struct pmd_internals *internals = dev->data->dev_private;
660 struct pkt_tx_queue *txq;
662 txq = &internals->tx_queues[tx_queue_id];
664 dev->data->tx_queues[tx_queue_id] = txq;
669 eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
671 struct pmd_internals *internals = dev->data->dev_private;
672 struct ifreq ifr = { .ifr_mtu = mtu };
676 s = socket(PF_INET, SOCK_DGRAM, 0);
680 strlcpy(ifr.ifr_name, internals->if_name, IFNAMSIZ);
681 ret = ioctl(s, SIOCSIFMTU, &ifr);
684 return (ret < 0) ? -errno : 0;
688 eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
693 s = socket(PF_INET, SOCK_DGRAM, 0);
697 strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
698 if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
700 ifr.ifr_flags &= mask;
701 ifr.ifr_flags |= flags;
702 if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0)
709 eth_dev_promiscuous_enable(struct rte_eth_dev *dev)
711 struct pmd_internals *internals = dev->data->dev_private;
713 eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0);
717 eth_dev_promiscuous_disable(struct rte_eth_dev *dev)
719 struct pmd_internals *internals = dev->data->dev_private;
721 eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC);
724 static const struct eth_dev_ops ops = {
725 .dev_start = eth_dev_start,
726 .dev_stop = eth_dev_stop,
727 .dev_close = eth_dev_close,
728 .dev_configure = eth_dev_configure,
729 .dev_infos_get = eth_dev_info,
730 .mtu_set = eth_dev_mtu_set,
731 .promiscuous_enable = eth_dev_promiscuous_enable,
732 .promiscuous_disable = eth_dev_promiscuous_disable,
733 .rx_queue_setup = eth_rx_queue_setup,
734 .tx_queue_setup = eth_tx_queue_setup,
735 .rx_queue_release = eth_queue_release,
736 .tx_queue_release = eth_queue_release,
737 .link_update = eth_link_update,
738 .stats_get = eth_stats_get,
739 .stats_reset = eth_stats_reset,
742 /** parse integer from integer argument */
744 parse_integer_arg(const char *key __rte_unused,
745 const char *value, void *extra_args)
747 int *i = (int *)extra_args;
750 *i = strtol(value, &end, 10);
752 AF_XDP_LOG(ERR, "Argument has to be positive.\n");
759 /** parse name argument */
761 parse_name_arg(const char *key __rte_unused,
762 const char *value, void *extra_args)
764 char *name = extra_args;
766 if (strnlen(value, IFNAMSIZ) > IFNAMSIZ - 1) {
767 AF_XDP_LOG(ERR, "Invalid name %s, should be less than %u bytes.\n",
772 strlcpy(name, value, IFNAMSIZ);
778 parse_parameters(struct rte_kvargs *kvlist,
784 ret = rte_kvargs_process(kvlist, ETH_AF_XDP_IFACE_ARG,
785 &parse_name_arg, if_name);
789 ret = rte_kvargs_process(kvlist, ETH_AF_XDP_QUEUE_IDX_ARG,
790 &parse_integer_arg, queue_idx);
795 rte_kvargs_free(kvlist);
800 get_iface_info(const char *if_name,
801 struct ether_addr *eth_addr,
805 int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
810 strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
811 if (ioctl(sock, SIOCGIFINDEX, &ifr))
814 *if_index = ifr.ifr_ifindex;
816 if (ioctl(sock, SIOCGIFHWADDR, &ifr))
819 rte_memcpy(eth_addr, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
829 static struct rte_eth_dev *
830 init_internals(struct rte_vdev_device *dev,
834 const char *name = rte_vdev_device_name(dev);
835 const unsigned int numa_node = dev->device.numa_node;
836 struct pmd_internals *internals;
837 struct rte_eth_dev *eth_dev;
841 internals = rte_zmalloc_socket(name, sizeof(*internals), 0, numa_node);
842 if (internals == NULL)
845 internals->queue_idx = queue_idx;
846 strlcpy(internals->if_name, if_name, IFNAMSIZ);
848 for (i = 0; i < ETH_AF_XDP_MAX_QUEUE_PAIRS; i++) {
849 internals->tx_queues[i].pair = &internals->rx_queues[i];
850 internals->rx_queues[i].pair = &internals->tx_queues[i];
853 ret = get_iface_info(if_name, &internals->eth_addr,
854 &internals->if_index);
858 eth_dev = rte_eth_vdev_allocate(dev, 0);
862 eth_dev->data->dev_private = internals;
863 eth_dev->data->dev_link = pmd_link;
864 eth_dev->data->mac_addrs = &internals->eth_addr;
865 eth_dev->dev_ops = &ops;
866 eth_dev->rx_pkt_burst = eth_af_xdp_rx;
867 eth_dev->tx_pkt_burst = eth_af_xdp_tx;
868 /* Let rte_eth_dev_close() release the port resources. */
869 eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
879 rte_pmd_af_xdp_probe(struct rte_vdev_device *dev)
881 struct rte_kvargs *kvlist;
882 char if_name[IFNAMSIZ] = {'\0'};
883 int xsk_queue_idx = ETH_AF_XDP_DFLT_QUEUE_IDX;
884 struct rte_eth_dev *eth_dev = NULL;
887 AF_XDP_LOG(INFO, "Initializing pmd_af_xdp for %s\n",
888 rte_vdev_device_name(dev));
890 name = rte_vdev_device_name(dev);
891 if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
892 strlen(rte_vdev_device_args(dev)) == 0) {
893 eth_dev = rte_eth_dev_attach_secondary(name);
894 if (eth_dev == NULL) {
895 AF_XDP_LOG(ERR, "Failed to probe %s\n", name);
898 eth_dev->dev_ops = &ops;
899 rte_eth_dev_probing_finish(eth_dev);
903 kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
904 if (kvlist == NULL) {
905 AF_XDP_LOG(ERR, "Invalid kvargs key\n");
909 if (dev->device.numa_node == SOCKET_ID_ANY)
910 dev->device.numa_node = rte_socket_id();
912 if (parse_parameters(kvlist, if_name, &xsk_queue_idx) < 0) {
913 AF_XDP_LOG(ERR, "Invalid kvargs value\n");
917 if (strlen(if_name) == 0) {
918 AF_XDP_LOG(ERR, "Network interface must be specified\n");
922 eth_dev = init_internals(dev, if_name, xsk_queue_idx);
923 if (eth_dev == NULL) {
924 AF_XDP_LOG(ERR, "Failed to init internals\n");
928 rte_eth_dev_probing_finish(eth_dev);
934 rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
936 struct rte_eth_dev *eth_dev = NULL;
938 AF_XDP_LOG(INFO, "Removing AF_XDP ethdev on numa socket %u\n",
944 /* find the ethdev entry */
945 eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
949 eth_dev_close(eth_dev);
950 rte_eth_dev_release_port(eth_dev);
956 static struct rte_vdev_driver pmd_af_xdp_drv = {
957 .probe = rte_pmd_af_xdp_probe,
958 .remove = rte_pmd_af_xdp_remove,
961 RTE_PMD_REGISTER_VDEV(net_af_xdp, pmd_af_xdp_drv);
962 RTE_PMD_REGISTER_PARAM_STRING(net_af_xdp,
966 RTE_INIT(af_xdp_init_log)
968 af_xdp_logtype = rte_log_register("pmd.net.af_xdp");
969 if (af_xdp_logtype >= 0)
970 rte_log_set_level(af_xdp_logtype, RTE_LOG_NOTICE);