WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / xdpxceiver.h
blob61f595b6f200fcdb842bed6a1faaec2f4257cf4d
1 /* SPDX-License-Identifier: GPL-2.0
2 * Copyright(c) 2020 Intel Corporation.
3 */
5 #ifndef XDPXCEIVER_H_
6 #define XDPXCEIVER_H_
8 #ifndef SOL_XDP
9 #define SOL_XDP 283
10 #endif
12 #ifndef AF_XDP
13 #define AF_XDP 44
14 #endif
16 #ifndef PF_XDP
17 #define PF_XDP AF_XDP
18 #endif
20 #define MAX_INTERFACES 2
21 #define MAX_INTERFACE_NAME_CHARS 7
22 #define MAX_INTERFACES_NAMESPACE_CHARS 10
23 #define MAX_SOCKS 1
24 #define MAX_TEARDOWN_ITER 10
25 #define MAX_BIDI_ITER 2
26 #define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \
27 sizeof(struct udphdr))
28 #define MIN_PKT_SIZE 64
29 #define ETH_FCS_SIZE 4
30 #define PKT_SIZE (MIN_PKT_SIZE - ETH_FCS_SIZE)
31 #define IP_PKT_SIZE (PKT_SIZE - sizeof(struct ethhdr))
32 #define IP_PKT_VER 0x4
33 #define IP_PKT_TOS 0x9
34 #define UDP_PKT_SIZE (IP_PKT_SIZE - sizeof(struct iphdr))
35 #define UDP_PKT_DATA_SIZE (UDP_PKT_SIZE - sizeof(struct udphdr))
36 #define TMOUT_SEC (3)
37 #define EOT (-1)
38 #define USLEEP_MAX 200000
39 #define THREAD_STACK 60000000
40 #define SOCK_RECONF_CTR 10
41 #define BATCH_SIZE 64
42 #define POLL_TMOUT 1000
43 #define NEED_WAKEUP true
45 typedef __u32 u32;
46 typedef __u16 u16;
47 typedef __u8 u8;
49 enum TESTS {
50 ORDER_CONTENT_VALIDATE_XDP_SKB = 0,
51 ORDER_CONTENT_VALIDATE_XDP_DRV = 1,
54 u8 uut;
55 u8 debug_pkt_dump;
56 u32 num_frames;
57 u8 switching_notify;
58 u8 bidi_pass;
60 static u32 opt_xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST;
61 static int opt_queue;
62 static int opt_pkt_count;
63 static int opt_poll;
64 static int opt_teardown;
65 static int opt_bidi;
66 static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
67 static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE];
68 static u32 pkt_counter;
69 static u32 prev_pkt = -1;
70 static int sigvar;
72 struct xsk_umem_info {
73 struct xsk_ring_prod fq;
74 struct xsk_ring_cons cq;
75 struct xsk_umem *umem;
76 void *buffer;
79 struct xsk_socket_info {
80 struct xsk_ring_cons rx;
81 struct xsk_ring_prod tx;
82 struct xsk_umem_info *umem;
83 struct xsk_socket *xsk;
84 unsigned long rx_npkts;
85 unsigned long tx_npkts;
86 unsigned long prev_rx_npkts;
87 unsigned long prev_tx_npkts;
88 u32 outstanding_tx;
91 struct flow_vector {
92 enum fvector {
93 tx,
94 rx,
95 bidi,
96 undef,
97 } vector;
100 struct generic_data {
101 u32 seqnum;
104 struct ifaceconfigobj {
105 u8 dst_mac[ETH_ALEN];
106 u8 src_mac[ETH_ALEN];
107 struct in_addr dst_ip;
108 struct in_addr src_ip;
109 u16 src_port;
110 u16 dst_port;
111 } *ifaceconfig;
113 struct ifobject {
114 int ifindex;
115 int ifdict_index;
116 char ifname[MAX_INTERFACE_NAME_CHARS];
117 char nsname[MAX_INTERFACES_NAMESPACE_CHARS];
118 struct flow_vector fv;
119 struct xsk_socket_info *xsk;
120 struct xsk_umem_info *umem;
121 u8 dst_mac[ETH_ALEN];
122 u8 src_mac[ETH_ALEN];
123 u32 dst_ip;
124 u32 src_ip;
125 u16 src_port;
126 u16 dst_port;
129 static struct ifobject *ifdict[MAX_INTERFACES];
131 /*threads*/
132 atomic_int spinning_tx;
133 atomic_int spinning_rx;
134 pthread_mutex_t sync_mutex;
135 pthread_mutex_t sync_mutex_tx;
136 pthread_cond_t signal_rx_condition;
137 pthread_cond_t signal_tx_condition;
138 pthread_t t0, t1, ns_thread;
139 pthread_attr_t attr;
141 struct targs {
142 bool retptr;
143 int idx;
146 TAILQ_HEAD(head_s, pkt) head = TAILQ_HEAD_INITIALIZER(head);
147 struct head_s *head_p;
148 struct pkt {
149 char *pkt_frame;
151 TAILQ_ENTRY(pkt) pkt_nodes;
152 } *pkt_node_rx, *pkt_node_rx_q;
154 struct pkt_frame {
155 char *payload;
156 } *pkt_obj;
158 struct pkt_frame **pkt_buf;
160 #endif /* XDPXCEIVER_H */