1 /* SPDX-License-Identifier: GPL-2.0 2 * Copyright(c) 2020 Intel Corporation. 3 */ 4 5 #ifndef XSKXCEIVER_H_ 6 #define XSKXCEIVER_H_ 7 8 #include <limits.h> 9 10 #include "xsk_xdp_progs.skel.h" 11 #include "xsk_xdp_common.h" 12 13 #ifndef SOL_XDP 14 #define SOL_XDP 283 15 #endif 16 17 #ifndef AF_XDP 18 #define AF_XDP 44 19 #endif 20 21 #ifndef PF_XDP 22 #define PF_XDP AF_XDP 23 #endif 24 25 #ifndef SO_BUSY_POLL_BUDGET 26 #define SO_BUSY_POLL_BUDGET 70 27 #endif 28 29 #ifndef SO_PREFER_BUSY_POLL 30 #define SO_PREFER_BUSY_POLL 69 31 #endif 32 33 #define TEST_PASS 0 34 #define TEST_FAILURE -1 35 #define TEST_CONTINUE 1 36 #define TEST_SKIP 2 37 #define MAX_INTERFACES 2 38 #define MAX_INTERFACE_NAME_CHARS 16 39 #define MAX_TEST_NAME_SIZE 48 40 #define MAX_TEARDOWN_ITER 10 41 #define PKT_HDR_SIZE (sizeof(struct ethhdr) + 2) /* Just to align the data in the packet */ 42 #define MIN_PKT_SIZE 64 43 #define MAX_ETH_PKT_SIZE 1518 44 #define MAX_ETH_JUMBO_SIZE 9000 45 #define USLEEP_MAX 10000 46 #define SOCK_RECONF_CTR 10 47 #define BATCH_SIZE 64 48 #define POLL_TMOUT 1000 49 #define THREAD_TMOUT 3 50 #define DEFAULT_PKT_CNT (4 * 1024) 51 #define DEFAULT_UMEM_BUFFERS (DEFAULT_PKT_CNT / 4) 52 #define RX_FULL_RXQSIZE 32 53 #define UMEM_HEADROOM_TEST_SIZE 128 54 #define XSK_UMEM__INVALID_FRAME_SIZE (MAX_ETH_JUMBO_SIZE + 1) 55 #define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024) 56 #define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024) 57 #define XSK_DESC__INVALID_OPTION (0xffff) 58 #define XSK_DESC__MAX_SKB_FRAGS 18 59 #define HUGEPAGE_SIZE (2 * 1024 * 1024) 60 #define PKT_DUMP_NB_TO_PRINT 16 61 #define RUN_ALL_TESTS UINT_MAX 62 #define NUM_MAC_ADDRESSES 4 63 64 #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0) 65 66 enum test_mode { 67 TEST_MODE_SKB, 68 TEST_MODE_DRV, 69 TEST_MODE_ZC, 70 TEST_MODE_ALL 71 }; 72 73 struct xsk_umem_info { 74 struct xsk_ring_prod fq; 75 struct xsk_ring_cons cq; 76 struct xsk_umem *umem; 77 u64 next_buffer; 78 u32 num_frames; 79 u32 frame_headroom; 80 void *buffer; 81 u32 frame_size; 82 u32 base_addr; 83 bool unaligned_mode; 84 }; 85 86 struct xsk_socket_info { 87 struct xsk_ring_cons rx; 88 struct xsk_ring_prod tx; 89 struct xsk_umem_info *umem; 90 struct xsk_socket *xsk; 91 struct pkt_stream *pkt_stream; 92 u32 outstanding_tx; 93 u32 rxqsize; 94 u8 dst_mac[ETH_ALEN]; 95 u8 src_mac[ETH_ALEN]; 96 }; 97 98 struct pkt { 99 int offset; 100 u32 len; 101 u32 pkt_nb; 102 bool valid; 103 u16 options; 104 }; 105 106 struct pkt_stream { 107 u32 nb_pkts; 108 u32 current_pkt_nb; 109 struct pkt *pkts; 110 u32 max_pkt_len; 111 u32 nb_rx_pkts; 112 u32 nb_valid_entries; 113 bool verbatim; 114 }; 115 116 struct ifobject; 117 struct test_spec; 118 typedef int (*validation_func_t)(struct ifobject *ifobj); 119 typedef void *(*thread_func_t)(void *arg); 120 typedef int (*test_func_t)(struct test_spec *test); 121 122 struct ifobject { 123 char ifname[MAX_INTERFACE_NAME_CHARS]; 124 struct xsk_socket_info *xsk; 125 struct xsk_socket_info *xsk_arr; 126 struct xsk_umem_info *umem; 127 thread_func_t func_ptr; 128 validation_func_t validation_func; 129 struct xsk_xdp_progs *xdp_progs; 130 struct bpf_map *xskmap; 131 struct bpf_program *xdp_prog; 132 enum test_mode mode; 133 int ifindex; 134 int mtu; 135 u32 bind_flags; 136 u32 xdp_zc_max_segs; 137 bool tx_on; 138 bool rx_on; 139 bool use_poll; 140 bool busy_poll; 141 bool use_fill_ring; 142 bool release_rx; 143 bool shared_umem; 144 bool use_metadata; 145 bool unaligned_supp; 146 bool multi_buff_supp; 147 bool multi_buff_zc_supp; 148 }; 149 150 struct test_spec { 151 struct ifobject *ifobj_tx; 152 struct ifobject *ifobj_rx; 153 struct pkt_stream *tx_pkt_stream_default; 154 struct pkt_stream *rx_pkt_stream_default; 155 struct bpf_program *xdp_prog_rx; 156 struct bpf_program *xdp_prog_tx; 157 struct bpf_map *xskmap_rx; 158 struct bpf_map *xskmap_tx; 159 test_func_t test_func; 160 int mtu; 161 u16 total_steps; 162 u16 current_step; 163 u16 nb_sockets; 164 bool fail; 165 enum test_mode mode; 166 char name[MAX_TEST_NAME_SIZE]; 167 }; 168 169 pthread_barrier_t barr; 170 pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_INITIALIZER; 171 172 int pkts_in_flight; 173 174 static const u8 g_mac[ETH_ALEN] = {0x55, 0x44, 0x33, 0x22, 0x11, 0x00}; 175 176 #endif /* XSKXCEIVER_H_ */ 177