Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v5.11 160 lines 3.2 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 2 * Copyright(c) 2020 Intel Corporation. 3 */ 4 5#ifndef XDPXCEIVER_H_ 6#define XDPXCEIVER_H_ 7 8#ifndef SOL_XDP 9#define SOL_XDP 283 10#endif 11 12#ifndef AF_XDP 13#define AF_XDP 44 14#endif 15 16#ifndef PF_XDP 17#define PF_XDP AF_XDP 18#endif 19 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 44 45typedef __u32 u32; 46typedef __u16 u16; 47typedef __u8 u8; 48 49enum TESTS { 50 ORDER_CONTENT_VALIDATE_XDP_SKB = 0, 51 ORDER_CONTENT_VALIDATE_XDP_DRV = 1, 52}; 53 54u8 uut; 55u8 debug_pkt_dump; 56u32 num_frames; 57u8 switching_notify; 58u8 bidi_pass; 59 60static u32 opt_xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; 61static int opt_queue; 62static int opt_pkt_count; 63static int opt_poll; 64static int opt_teardown; 65static int opt_bidi; 66static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP; 67static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE]; 68static u32 pkt_counter; 69static u32 prev_pkt = -1; 70static int sigvar; 71 72struct xsk_umem_info { 73 struct xsk_ring_prod fq; 74 struct xsk_ring_cons cq; 75 struct xsk_umem *umem; 76 void *buffer; 77}; 78 79struct 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; 89}; 90 91struct flow_vector { 92 enum fvector { 93 tx, 94 rx, 95 bidi, 96 undef, 97 } vector; 98}; 99 100struct generic_data { 101 u32 seqnum; 102}; 103 104struct 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; 112 113struct 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; 127}; 128 129static struct ifobject *ifdict[MAX_INTERFACES]; 130 131/*threads*/ 132atomic_int spinning_tx; 133atomic_int spinning_rx; 134pthread_mutex_t sync_mutex; 135pthread_mutex_t sync_mutex_tx; 136pthread_cond_t signal_rx_condition; 137pthread_cond_t signal_tx_condition; 138pthread_t t0, t1, ns_thread; 139pthread_attr_t attr; 140 141struct targs { 142 bool retptr; 143 int idx; 144}; 145 146TAILQ_HEAD(head_s, pkt) head = TAILQ_HEAD_INITIALIZER(head); 147struct head_s *head_p; 148struct pkt { 149 char *pkt_frame; 150 151 TAILQ_ENTRY(pkt) pkt_nodes; 152} *pkt_node_rx, *pkt_node_rx_q; 153 154struct pkt_frame { 155 char *payload; 156} *pkt_obj; 157 158struct pkt_frame **pkt_buf; 159 160#endif /* XDPXCEIVER_H */