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, int reserve_size)
139 struct xsk_ring_prod *fq = &umem->fq;
143 ret = xsk_ring_prod__reserve(fq, reserve_size, &idx);
144 if (unlikely(!ret)) {
145 AF_XDP_LOG(ERR, "Failed to reserve enough fq descs.\n");
149 for (i = 0; i < reserve_size; i++) {
152 if (rte_ring_dequeue(umem->buf_ring, &addr)) {
156 fq_addr = xsk_ring_prod__fill_addr(fq, idx++);
157 *fq_addr = (uint64_t)addr;
160 xsk_ring_prod__submit(fq, i);
166 eth_af_xdp_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
168 struct pkt_rx_queue *rxq = queue;
169 struct xsk_ring_cons *rx = &rxq->rx;
170 struct xsk_umem_info *umem = rxq->umem;
171 struct xsk_ring_prod *fq = &umem->fq;
173 uint32_t free_thresh = fq->size >> 1;
174 struct rte_mbuf *mbufs[ETH_AF_XDP_TX_BATCH_SIZE];
175 unsigned long dropped = 0;
176 unsigned long rx_bytes = 0;
180 nb_pkts = RTE_MIN(nb_pkts, ETH_AF_XDP_TX_BATCH_SIZE);
182 rcvd = xsk_ring_cons__peek(rx, nb_pkts, &idx_rx);
186 if (xsk_prod_nb_free(fq, free_thresh) >= free_thresh)
187 (void)reserve_fill_queue(umem, ETH_AF_XDP_RX_BATCH_SIZE);
189 if (unlikely(rte_pktmbuf_alloc_bulk(rxq->mb_pool, mbufs, rcvd) != 0))
192 for (i = 0; i < rcvd; i++) {
193 const struct xdp_desc *desc;
198 desc = xsk_ring_cons__rx_desc(rx, idx_rx++);
201 pkt = xsk_umem__get_data(rxq->umem->mz->addr, addr);
203 rte_memcpy(rte_pktmbuf_mtod(mbufs[i], void *), pkt, len);
204 rte_pktmbuf_pkt_len(mbufs[i]) = len;
205 rte_pktmbuf_data_len(mbufs[i]) = len;
207 bufs[count++] = mbufs[i];
209 rte_ring_enqueue(umem->buf_ring, (void *)addr);
212 xsk_ring_cons__release(rx, rcvd);
215 rxq->stats.rx_pkts += (rcvd - dropped);
216 rxq->stats.rx_bytes += rx_bytes;
222 pull_umem_cq(struct xsk_umem_info *umem, int size)
224 struct xsk_ring_cons *cq = &umem->cq;
228 n = xsk_ring_cons__peek(cq, size, &idx_cq);
230 for (i = 0; i < n; i++) {
232 addr = *xsk_ring_cons__comp_addr(cq, idx_cq++);
233 rte_ring_enqueue(umem->buf_ring, (void *)addr);
236 xsk_ring_cons__release(cq, n);
240 kick_tx(struct pkt_tx_queue *txq)
242 struct xsk_umem_info *umem = txq->pair->umem;
244 while (send(xsk_socket__fd(txq->pair->xsk), NULL,
245 0, MSG_DONTWAIT) < 0) {
246 /* some thing unexpected */
247 if (errno != EBUSY && errno != EAGAIN && errno != EINTR)
250 /* pull from completion queue to leave more space */
252 pull_umem_cq(umem, ETH_AF_XDP_TX_BATCH_SIZE);
254 pull_umem_cq(umem, ETH_AF_XDP_TX_BATCH_SIZE);
258 eth_af_xdp_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
260 struct pkt_tx_queue *txq = queue;
261 struct xsk_umem_info *umem = txq->pair->umem;
262 struct rte_mbuf *mbuf;
263 void *addrs[ETH_AF_XDP_TX_BATCH_SIZE];
264 unsigned long tx_bytes = 0;
268 nb_pkts = RTE_MIN(nb_pkts, ETH_AF_XDP_TX_BATCH_SIZE);
270 pull_umem_cq(umem, nb_pkts);
272 nb_pkts = rte_ring_dequeue_bulk(umem->buf_ring, addrs,
277 if (xsk_ring_prod__reserve(&txq->tx, nb_pkts, &idx_tx) != nb_pkts) {
279 rte_ring_enqueue_bulk(umem->buf_ring, addrs, nb_pkts, NULL);
283 for (i = 0; i < nb_pkts; i++) {
284 struct xdp_desc *desc;
286 uint32_t buf_len = ETH_AF_XDP_FRAME_SIZE
287 - ETH_AF_XDP_DATA_HEADROOM;
288 desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx + i);
290 if (mbuf->pkt_len <= buf_len) {
291 desc->addr = (uint64_t)addrs[valid];
292 desc->len = mbuf->pkt_len;
293 pkt = xsk_umem__get_data(umem->mz->addr,
295 rte_memcpy(pkt, rte_pktmbuf_mtod(mbuf, void *),
298 tx_bytes += mbuf->pkt_len;
300 rte_pktmbuf_free(mbuf);
303 xsk_ring_prod__submit(&txq->tx, nb_pkts);
308 rte_ring_enqueue_bulk(umem->buf_ring, &addrs[valid],
309 nb_pkts - valid, NULL);
311 txq->stats.err_pkts += nb_pkts - valid;
312 txq->stats.tx_pkts += valid;
313 txq->stats.tx_bytes += tx_bytes;
319 eth_dev_start(struct rte_eth_dev *dev)
321 dev->data->dev_link.link_status = ETH_LINK_UP;
326 /* This function gets called when the current port gets stopped. */
328 eth_dev_stop(struct rte_eth_dev *dev)
330 dev->data->dev_link.link_status = ETH_LINK_DOWN;
334 eth_dev_configure(struct rte_eth_dev *dev)
336 /* rx/tx must be paired */
337 if (dev->data->nb_rx_queues != dev->data->nb_tx_queues)
344 eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
346 struct pmd_internals *internals = dev->data->dev_private;
348 dev_info->if_index = internals->if_index;
349 dev_info->max_mac_addrs = 1;
350 dev_info->max_rx_pktlen = ETH_FRAME_LEN;
351 dev_info->max_rx_queues = 1;
352 dev_info->max_tx_queues = 1;
354 dev_info->default_rxportconf.nb_queues = 1;
355 dev_info->default_txportconf.nb_queues = 1;
356 dev_info->default_rxportconf.ring_size = ETH_AF_XDP_DFLT_NUM_DESCS;
357 dev_info->default_txportconf.ring_size = ETH_AF_XDP_DFLT_NUM_DESCS;
361 eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
363 struct pmd_internals *internals = dev->data->dev_private;
364 struct xdp_statistics xdp_stats;
365 struct pkt_rx_queue *rxq;
369 for (i = 0; i < dev->data->nb_rx_queues; i++) {
370 optlen = sizeof(struct xdp_statistics);
371 rxq = &internals->rx_queues[i];
372 stats->q_ipackets[i] = internals->rx_queues[i].stats.rx_pkts;
373 stats->q_ibytes[i] = internals->rx_queues[i].stats.rx_bytes;
375 stats->q_opackets[i] = internals->tx_queues[i].stats.tx_pkts;
376 stats->q_obytes[i] = internals->tx_queues[i].stats.tx_bytes;
378 stats->ipackets += stats->q_ipackets[i];
379 stats->ibytes += stats->q_ibytes[i];
380 stats->imissed += internals->rx_queues[i].stats.rx_dropped;
381 ret = getsockopt(xsk_socket__fd(rxq->xsk), SOL_XDP,
382 XDP_STATISTICS, &xdp_stats, &optlen);
384 AF_XDP_LOG(ERR, "getsockopt() failed for XDP_STATISTICS.\n");
387 stats->imissed += xdp_stats.rx_dropped;
389 stats->opackets += stats->q_opackets[i];
390 stats->oerrors += internals->tx_queues[i].stats.err_pkts;
391 stats->obytes += stats->q_obytes[i];
398 eth_stats_reset(struct rte_eth_dev *dev)
400 struct pmd_internals *internals = dev->data->dev_private;
403 for (i = 0; i < ETH_AF_XDP_MAX_QUEUE_PAIRS; i++) {
404 memset(&internals->rx_queues[i].stats, 0,
405 sizeof(struct rx_stats));
406 memset(&internals->tx_queues[i].stats, 0,
407 sizeof(struct tx_stats));
412 remove_xdp_program(struct pmd_internals *internals)
414 uint32_t curr_prog_id = 0;
416 if (bpf_get_link_xdp_id(internals->if_index, &curr_prog_id,
417 XDP_FLAGS_UPDATE_IF_NOEXIST)) {
418 AF_XDP_LOG(ERR, "bpf_get_link_xdp_id failed\n");
421 bpf_set_link_xdp_fd(internals->if_index, -1,
422 XDP_FLAGS_UPDATE_IF_NOEXIST);
426 eth_dev_close(struct rte_eth_dev *dev)
428 struct pmd_internals *internals = dev->data->dev_private;
429 struct pkt_rx_queue *rxq;
432 AF_XDP_LOG(INFO, "Closing AF_XDP ethdev on numa socket %u\n",
435 for (i = 0; i < ETH_AF_XDP_MAX_QUEUE_PAIRS; i++) {
436 rxq = &internals->rx_queues[i];
437 if (rxq->umem == NULL)
439 xsk_socket__delete(rxq->xsk);
442 (void)xsk_umem__delete(internals->umem->umem);
443 remove_xdp_program(internals);
447 eth_queue_release(void *q __rte_unused)
452 eth_link_update(struct rte_eth_dev *dev __rte_unused,
453 int wait_to_complete __rte_unused)
459 xdp_umem_destroy(struct xsk_umem_info *umem)
461 rte_memzone_free(umem->mz);
464 rte_ring_free(umem->buf_ring);
465 umem->buf_ring = NULL;
472 xsk_umem_info *xdp_umem_configure(void)
474 struct xsk_umem_info *umem;
475 const struct rte_memzone *mz;
476 struct xsk_umem_config usr_config = {
477 .fill_size = ETH_AF_XDP_DFLT_NUM_DESCS,
478 .comp_size = ETH_AF_XDP_DFLT_NUM_DESCS,
479 .frame_size = ETH_AF_XDP_FRAME_SIZE,
480 .frame_headroom = ETH_AF_XDP_DATA_HEADROOM };
484 umem = rte_zmalloc_socket("umem", sizeof(*umem), 0, rte_socket_id());
486 AF_XDP_LOG(ERR, "Failed to allocate umem info");
490 umem->buf_ring = rte_ring_create("af_xdp_ring",
491 ETH_AF_XDP_NUM_BUFFERS,
494 if (umem->buf_ring == NULL) {
495 AF_XDP_LOG(ERR, "Failed to create rte_ring\n");
499 for (i = 0; i < ETH_AF_XDP_NUM_BUFFERS; i++)
500 rte_ring_enqueue(umem->buf_ring,
501 (void *)(i * ETH_AF_XDP_FRAME_SIZE +
502 ETH_AF_XDP_DATA_HEADROOM));
504 mz = rte_memzone_reserve_aligned("af_xdp uemem",
505 ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
506 rte_socket_id(), RTE_MEMZONE_IOVA_CONTIG,
509 AF_XDP_LOG(ERR, "Failed to reserve memzone for af_xdp umem.\n");
513 ret = xsk_umem__create(&umem->umem, mz->addr,
514 ETH_AF_XDP_NUM_BUFFERS * ETH_AF_XDP_FRAME_SIZE,
515 &umem->fq, &umem->cq,
519 AF_XDP_LOG(ERR, "Failed to create umem");
527 xdp_umem_destroy(umem);
532 xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
535 struct xsk_socket_config cfg;
536 struct pkt_tx_queue *txq = rxq->pair;
540 rxq->umem = xdp_umem_configure();
541 if (rxq->umem == NULL)
544 cfg.rx_size = ring_size;
545 cfg.tx_size = ring_size;
546 cfg.libbpf_flags = 0;
547 cfg.xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
549 ret = xsk_socket__create(&rxq->xsk, internals->if_name,
550 internals->queue_idx, rxq->umem->umem, &rxq->rx,
553 AF_XDP_LOG(ERR, "Failed to create xsk socket.\n");
557 reserve_size = ETH_AF_XDP_DFLT_NUM_DESCS / 2;
558 ret = reserve_fill_queue(rxq->umem, reserve_size);
560 xsk_socket__delete(rxq->xsk);
561 AF_XDP_LOG(ERR, "Failed to reserve fill queue.\n");
568 xdp_umem_destroy(rxq->umem);
574 queue_reset(struct pmd_internals *internals, uint16_t queue_idx)
576 struct pkt_rx_queue *rxq = &internals->rx_queues[queue_idx];
577 struct pkt_tx_queue *txq = rxq->pair;
579 memset(rxq, 0, sizeof(*rxq));
580 memset(txq, 0, sizeof(*txq));
583 rxq->queue_idx = queue_idx;
584 txq->queue_idx = queue_idx;
588 eth_rx_queue_setup(struct rte_eth_dev *dev,
589 uint16_t rx_queue_id,
591 unsigned int socket_id __rte_unused,
592 const struct rte_eth_rxconf *rx_conf __rte_unused,
593 struct rte_mempool *mb_pool)
595 struct pmd_internals *internals = dev->data->dev_private;
596 uint32_t buf_size, data_size;
597 struct pkt_rx_queue *rxq;
600 rxq = &internals->rx_queues[rx_queue_id];
601 queue_reset(internals, rx_queue_id);
603 /* Now get the space available for data in the mbuf */
604 buf_size = rte_pktmbuf_data_room_size(mb_pool) -
605 RTE_PKTMBUF_HEADROOM;
606 data_size = ETH_AF_XDP_FRAME_SIZE - ETH_AF_XDP_DATA_HEADROOM;
608 if (data_size > buf_size) {
609 AF_XDP_LOG(ERR, "%s: %d bytes will not fit in mbuf (%d bytes)\n",
610 dev->device->name, data_size, buf_size);
615 rxq->mb_pool = mb_pool;
617 if (xsk_configure(internals, rxq, nb_rx_desc)) {
618 AF_XDP_LOG(ERR, "Failed to configure xdp socket\n");
623 internals->umem = rxq->umem;
625 dev->data->rx_queues[rx_queue_id] = rxq;
629 queue_reset(internals, rx_queue_id);
634 eth_tx_queue_setup(struct rte_eth_dev *dev,
635 uint16_t tx_queue_id,
636 uint16_t nb_tx_desc __rte_unused,
637 unsigned int socket_id __rte_unused,
638 const struct rte_eth_txconf *tx_conf __rte_unused)
640 struct pmd_internals *internals = dev->data->dev_private;
641 struct pkt_tx_queue *txq;
643 txq = &internals->tx_queues[tx_queue_id];
645 dev->data->tx_queues[tx_queue_id] = txq;
650 eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
652 struct pmd_internals *internals = dev->data->dev_private;
653 struct ifreq ifr = { .ifr_mtu = mtu };
657 s = socket(PF_INET, SOCK_DGRAM, 0);
661 strlcpy(ifr.ifr_name, internals->if_name, IFNAMSIZ);
662 ret = ioctl(s, SIOCSIFMTU, &ifr);
665 return (ret < 0) ? -errno : 0;
669 eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
674 s = socket(PF_INET, SOCK_DGRAM, 0);
678 strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
679 if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
681 ifr.ifr_flags &= mask;
682 ifr.ifr_flags |= flags;
683 if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0)
690 eth_dev_promiscuous_enable(struct rte_eth_dev *dev)
692 struct pmd_internals *internals = dev->data->dev_private;
694 eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0);
698 eth_dev_promiscuous_disable(struct rte_eth_dev *dev)
700 struct pmd_internals *internals = dev->data->dev_private;
702 eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC);
705 static const struct eth_dev_ops ops = {
706 .dev_start = eth_dev_start,
707 .dev_stop = eth_dev_stop,
708 .dev_close = eth_dev_close,
709 .dev_configure = eth_dev_configure,
710 .dev_infos_get = eth_dev_info,
711 .mtu_set = eth_dev_mtu_set,
712 .promiscuous_enable = eth_dev_promiscuous_enable,
713 .promiscuous_disable = eth_dev_promiscuous_disable,
714 .rx_queue_setup = eth_rx_queue_setup,
715 .tx_queue_setup = eth_tx_queue_setup,
716 .rx_queue_release = eth_queue_release,
717 .tx_queue_release = eth_queue_release,
718 .link_update = eth_link_update,
719 .stats_get = eth_stats_get,
720 .stats_reset = eth_stats_reset,
723 /** parse integer from integer argument */
725 parse_integer_arg(const char *key __rte_unused,
726 const char *value, void *extra_args)
728 int *i = (int *)extra_args;
731 *i = strtol(value, &end, 10);
733 AF_XDP_LOG(ERR, "Argument has to be positive.\n");
740 /** parse name argument */
742 parse_name_arg(const char *key __rte_unused,
743 const char *value, void *extra_args)
745 char *name = extra_args;
747 if (strnlen(value, IFNAMSIZ) > IFNAMSIZ - 1) {
748 AF_XDP_LOG(ERR, "Invalid name %s, should be less than %u bytes.\n",
753 strlcpy(name, value, IFNAMSIZ);
759 parse_parameters(struct rte_kvargs *kvlist,
765 ret = rte_kvargs_process(kvlist, ETH_AF_XDP_IFACE_ARG,
766 &parse_name_arg, if_name);
770 ret = rte_kvargs_process(kvlist, ETH_AF_XDP_QUEUE_IDX_ARG,
771 &parse_integer_arg, queue_idx);
776 rte_kvargs_free(kvlist);
781 get_iface_info(const char *if_name,
782 struct ether_addr *eth_addr,
786 int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
791 strlcpy(ifr.ifr_name, if_name, IFNAMSIZ);
792 if (ioctl(sock, SIOCGIFINDEX, &ifr))
795 *if_index = ifr.ifr_ifindex;
797 if (ioctl(sock, SIOCGIFHWADDR, &ifr))
800 rte_memcpy(eth_addr, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
810 static struct rte_eth_dev *
811 init_internals(struct rte_vdev_device *dev,
815 const char *name = rte_vdev_device_name(dev);
816 const unsigned int numa_node = dev->device.numa_node;
817 struct pmd_internals *internals;
818 struct rte_eth_dev *eth_dev;
822 internals = rte_zmalloc_socket(name, sizeof(*internals), 0, numa_node);
823 if (internals == NULL)
826 internals->queue_idx = queue_idx;
827 strlcpy(internals->if_name, if_name, IFNAMSIZ);
829 for (i = 0; i < ETH_AF_XDP_MAX_QUEUE_PAIRS; i++) {
830 internals->tx_queues[i].pair = &internals->rx_queues[i];
831 internals->rx_queues[i].pair = &internals->tx_queues[i];
834 ret = get_iface_info(if_name, &internals->eth_addr,
835 &internals->if_index);
839 eth_dev = rte_eth_vdev_allocate(dev, 0);
843 eth_dev->data->dev_private = internals;
844 eth_dev->data->dev_link = pmd_link;
845 eth_dev->data->mac_addrs = &internals->eth_addr;
846 eth_dev->dev_ops = &ops;
847 eth_dev->rx_pkt_burst = eth_af_xdp_rx;
848 eth_dev->tx_pkt_burst = eth_af_xdp_tx;
858 rte_pmd_af_xdp_probe(struct rte_vdev_device *dev)
860 struct rte_kvargs *kvlist;
861 char if_name[IFNAMSIZ] = {'\0'};
862 int xsk_queue_idx = ETH_AF_XDP_DFLT_QUEUE_IDX;
863 struct rte_eth_dev *eth_dev = NULL;
866 AF_XDP_LOG(INFO, "Initializing pmd_af_xdp for %s\n",
867 rte_vdev_device_name(dev));
869 name = rte_vdev_device_name(dev);
870 if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
871 strlen(rte_vdev_device_args(dev)) == 0) {
872 eth_dev = rte_eth_dev_attach_secondary(name);
873 if (eth_dev == NULL) {
874 AF_XDP_LOG(ERR, "Failed to probe %s\n", name);
877 eth_dev->dev_ops = &ops;
878 rte_eth_dev_probing_finish(eth_dev);
882 kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
883 if (kvlist == NULL) {
884 AF_XDP_LOG(ERR, "Invalid kvargs key\n");
888 if (dev->device.numa_node == SOCKET_ID_ANY)
889 dev->device.numa_node = rte_socket_id();
891 if (parse_parameters(kvlist, if_name, &xsk_queue_idx) < 0) {
892 AF_XDP_LOG(ERR, "Invalid kvargs value\n");
896 if (strlen(if_name) == 0) {
897 AF_XDP_LOG(ERR, "Network interface must be specified\n");
901 eth_dev = init_internals(dev, if_name, xsk_queue_idx);
902 if (eth_dev == NULL) {
903 AF_XDP_LOG(ERR, "Failed to init internals\n");
907 rte_eth_dev_probing_finish(eth_dev);
913 rte_pmd_af_xdp_remove(struct rte_vdev_device *dev)
915 struct rte_eth_dev *eth_dev = NULL;
916 struct pmd_internals *internals;
918 AF_XDP_LOG(INFO, "Removing AF_XDP ethdev on numa socket %u\n",
924 /* find the ethdev entry */
925 eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
929 internals = eth_dev->data->dev_private;
931 rte_ring_free(internals->umem->buf_ring);
932 rte_memzone_free(internals->umem->mz);
933 rte_free(internals->umem);
935 rte_eth_dev_release_port(eth_dev);
941 static struct rte_vdev_driver pmd_af_xdp_drv = {
942 .probe = rte_pmd_af_xdp_probe,
943 .remove = rte_pmd_af_xdp_remove,
946 RTE_PMD_REGISTER_VDEV(net_af_xdp, pmd_af_xdp_drv);
947 RTE_PMD_REGISTER_PARAM_STRING(net_af_xdp,
951 RTE_INIT(af_xdp_init_log)
953 af_xdp_logtype = rte_log_register("pmd.net.af_xdp");
954 if (af_xdp_logtype >= 0)
955 rte_log_set_level(af_xdp_logtype, RTE_LOG_NOTICE);