1 /* SPDX-License-Identifier: GPL-2.0
2 * Copyright(c) 2020 Intel Corporation.
8 #include "xsk_xdp_progs.skel.h"
22 #ifndef SO_BUSY_POLL_BUDGET
23 #define SO_BUSY_POLL_BUDGET 70
26 #ifndef SO_PREFER_BUSY_POLL
27 #define SO_PREFER_BUSY_POLL 69
31 #define TEST_FAILURE -1
32 #define TEST_CONTINUE 1
33 #define MAX_INTERFACES 2
34 #define MAX_INTERFACE_NAME_CHARS 16
36 #define MAX_TEST_NAME_SIZE 32
37 #define MAX_TEARDOWN_ITER 10
38 #define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \
39 sizeof(struct udphdr))
40 #define MIN_ETH_PKT_SIZE 64
41 #define ETH_FCS_SIZE 4
42 #define MIN_PKT_SIZE (MIN_ETH_PKT_SIZE - ETH_FCS_SIZE)
43 #define PKT_SIZE (MIN_PKT_SIZE)
44 #define IP_PKT_SIZE (PKT_SIZE - sizeof(struct ethhdr))
45 #define IP_PKT_VER 0x4
46 #define IP_PKT_TOS 0x9
47 #define UDP_PKT_SIZE (IP_PKT_SIZE - sizeof(struct iphdr))
48 #define UDP_PKT_DATA_SIZE (UDP_PKT_SIZE - sizeof(struct udphdr))
49 #define USLEEP_MAX 10000
50 #define SOCK_RECONF_CTR 10
52 #define POLL_TMOUT 1000
53 #define THREAD_TMOUT 3
54 #define DEFAULT_PKT_CNT (4 * 1024)
55 #define DEFAULT_UMEM_BUFFERS (DEFAULT_PKT_CNT / 4)
56 #define UMEM_SIZE (DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE)
57 #define RX_FULL_RXQSIZE 32
58 #define UMEM_HEADROOM_TEST_SIZE 128
59 #define XSK_UMEM__INVALID_FRAME_SIZE (XSK_UMEM__DEFAULT_FRAME_SIZE + 1)
61 #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0)
71 TEST_TYPE_RUN_TO_COMPLETION,
72 TEST_TYPE_RUN_TO_COMPLETION_2K_FRAME,
73 TEST_TYPE_RUN_TO_COMPLETION_SINGLE_PKT,
76 TEST_TYPE_POLL_RXQ_TMOUT,
77 TEST_TYPE_POLL_TXQ_TMOUT,
79 TEST_TYPE_ALIGNED_INV_DESC,
80 TEST_TYPE_ALIGNED_INV_DESC_2K_FRAME,
81 TEST_TYPE_UNALIGNED_INV_DESC,
85 TEST_TYPE_STATS_RX_DROPPED,
86 TEST_TYPE_STATS_TX_INVALID_DESCS,
87 TEST_TYPE_STATS_RX_FULL,
88 TEST_TYPE_STATS_FILL_EMPTY,
90 TEST_TYPE_XDP_DROP_HALF,
91 TEST_TYPE_XDP_METADATA_COUNT,
95 static bool opt_pkt_dump;
96 static bool opt_verbose;
98 struct xsk_umem_info {
99 struct xsk_ring_prod fq;
100 struct xsk_ring_cons cq;
101 struct xsk_umem *umem;
110 struct xsk_socket_info {
111 struct xsk_ring_cons rx;
112 struct xsk_ring_prod tx;
113 struct xsk_umem_info *umem;
114 struct xsk_socket *xsk;
130 bool use_addr_for_fill;
134 typedef int (*validation_func_t)(struct ifobject *ifobj);
135 typedef void *(*thread_func_t)(void *arg);
138 char ifname[MAX_INTERFACE_NAME_CHARS];
139 struct xsk_socket_info *xsk;
140 struct xsk_socket_info *xsk_arr;
141 struct xsk_umem_info *umem;
142 thread_func_t func_ptr;
143 validation_func_t validation_func;
144 struct pkt_stream *pkt_stream;
145 struct xsk_xdp_progs *xdp_progs;
146 struct bpf_map *xskmap;
147 struct bpf_program *xdp_prog;
163 u8 dst_mac[ETH_ALEN];
164 u8 src_mac[ETH_ALEN];
168 struct ifobject *ifobj_tx;
169 struct ifobject *ifobj_rx;
170 struct pkt_stream *tx_pkt_stream_default;
171 struct pkt_stream *rx_pkt_stream_default;
172 struct bpf_program *xdp_prog_rx;
173 struct bpf_program *xdp_prog_tx;
174 struct bpf_map *xskmap_rx;
175 struct bpf_map *xskmap_tx;
181 char name[MAX_TEST_NAME_SIZE];
184 pthread_barrier_t barr;
185 pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_INITIALIZER;
186 pthread_cond_t pacing_cond = PTHREAD_COND_INITIALIZER;
190 #endif /* XSKXCEIVER_H_ */