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