1 /* SPDX-License-Identifier: GPL-2.0
2 * Copyright(c) 2020 Intel Corporation.
20 #define MAX_INTERFACES 2
21 #define MAX_INTERFACE_NAME_CHARS 7
22 #define MAX_INTERFACES_NAMESPACE_CHARS 10
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))
38 #define USLEEP_MAX 200000
39 #define THREAD_STACK 60000000
40 #define SOCK_RECONF_CTR 10
42 #define POLL_TMOUT 1000
43 #define NEED_WAKEUP true
50 ORDER_CONTENT_VALIDATE_XDP_SKB
= 0,
51 ORDER_CONTENT_VALIDATE_XDP_DRV
= 1,
60 static u32 opt_xdp_flags
= XDP_FLAGS_UPDATE_IF_NOEXIST
;
62 static int opt_pkt_count
;
64 static int opt_teardown
;
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;
72 struct xsk_umem_info
{
73 struct xsk_ring_prod fq
;
74 struct xsk_ring_cons cq
;
75 struct xsk_umem
*umem
;
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
;
100 struct generic_data
{
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
;
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
];
129 static struct ifobject
*ifdict
[MAX_INTERFACES
];
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
;
146 TAILQ_HEAD(head_s
, pkt
) head
= TAILQ_HEAD_INITIALIZER(head
);
147 struct head_s
*head_p
;
151 TAILQ_ENTRY(pkt
) pkt_nodes
;
152 } *pkt_node_rx
, *pkt_node_rx_q
;
158 struct pkt_frame
**pkt_buf
;
160 #endif /* XDPXCEIVER_H */