1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation.
6 #include <linux/version.h>
9 #if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE && \
10 defined(RTE_LIBRTE_AF_XDP_PMD_SHARED_UMEM)
11 #define ETH_AF_XDP_SHARED_UMEM 1
14 #ifdef ETH_AF_XDP_SHARED_UMEM
15 static __rte_always_inline int
16 create_shared_socket(struct xsk_socket **xsk_ptr,
18 __u32 queue_id, struct xsk_umem *umem,
19 struct xsk_ring_cons *rx,
20 struct xsk_ring_prod *tx,
21 struct xsk_ring_prod *fill,
22 struct xsk_ring_cons *comp,
23 const struct xsk_socket_config *config)
25 return xsk_socket__create_shared(xsk_ptr, ifname, queue_id, umem, rx,
26 tx, fill, comp, config);
29 static __rte_always_inline int
30 create_shared_socket(struct xsk_socket **xsk_ptr __rte_unused,
31 const char *ifname __rte_unused,
32 __u32 queue_id __rte_unused,
33 struct xsk_umem *umem __rte_unused,
34 struct xsk_ring_cons *rx __rte_unused,
35 struct xsk_ring_prod *tx __rte_unused,
36 struct xsk_ring_prod *fill __rte_unused,
37 struct xsk_ring_cons *comp __rte_unused,
38 const struct xsk_socket_config *config __rte_unused)
44 #ifdef XDP_USE_NEED_WAKEUP
46 rx_syscall_handler(struct xsk_ring_prod *q, uint32_t busy_budget,
47 struct pollfd *fds, struct xsk_socket *xsk)
49 /* we can assume a kernel >= 5.11 is in use if busy polling is enabled
50 * and thus we can safely use the recvfrom() syscall which is only
51 * supported for AF_XDP sockets in kernels >= 5.11.
54 (void)recvfrom(xsk_socket__fd(xsk), NULL, 0,
55 MSG_DONTWAIT, NULL, NULL);
59 if (xsk_ring_prod__needs_wakeup(q))
60 (void)poll(fds, 1, 1000);
63 tx_syscall_needed(struct xsk_ring_prod *q)
65 return xsk_ring_prod__needs_wakeup(q);
69 rx_syscall_handler(struct xsk_ring_prod *q __rte_unused, uint32_t busy_budget,
70 struct pollfd *fds __rte_unused, struct xsk_socket *xsk)
73 (void)recvfrom(xsk_socket__fd(xsk), NULL, 0,
74 MSG_DONTWAIT, NULL, NULL);
77 tx_syscall_needed(struct xsk_ring_prod *q __rte_unused)