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 XSK_DESC__MAX_SKB_FRAGS 18 58 #define XSK_DESC__MAX_SKB_FRAGS 18 59 #define HUGEPAGE_SIZE (2 * 1024 * 1024) 59 #define HUGEPAGE_SIZE (2 * 1024 * 1024) 60 #define PKT_DUMP_NB_TO_PRINT 16 60 #define PKT_DUMP_NB_TO_PRINT 16 61 #define RUN_ALL_TESTS UINT_MAX 61 #define RUN_ALL_TESTS UINT_MAX 62 #define NUM_MAC_ADDRESSES 4 62 #define NUM_MAC_ADDRESSES 4 63 63 64 #define print_verbose(x...) do { if (opt_verbo 64 #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0) 65 65 66 enum test_mode { 66 enum test_mode { 67 TEST_MODE_SKB, 67 TEST_MODE_SKB, 68 TEST_MODE_DRV, 68 TEST_MODE_DRV, 69 TEST_MODE_ZC, 69 TEST_MODE_ZC, 70 TEST_MODE_ALL 70 TEST_MODE_ALL 71 }; 71 }; 72 72 73 struct xsk_umem_info { 73 struct xsk_umem_info { 74 struct xsk_ring_prod fq; 74 struct xsk_ring_prod fq; 75 struct xsk_ring_cons cq; 75 struct xsk_ring_cons cq; 76 struct xsk_umem *umem; 76 struct xsk_umem *umem; 77 u64 next_buffer; 77 u64 next_buffer; 78 u32 num_frames; 78 u32 num_frames; 79 u32 frame_headroom; 79 u32 frame_headroom; 80 void *buffer; 80 void *buffer; 81 u32 frame_size; 81 u32 frame_size; 82 u32 base_addr; 82 u32 base_addr; 83 u32 fill_size; << 84 u32 comp_size; << 85 bool unaligned_mode; 83 bool unaligned_mode; 86 }; 84 }; 87 85 88 struct xsk_socket_info { 86 struct xsk_socket_info { 89 struct xsk_ring_cons rx; 87 struct xsk_ring_cons rx; 90 struct xsk_ring_prod tx; 88 struct xsk_ring_prod tx; 91 struct xsk_umem_info *umem; 89 struct xsk_umem_info *umem; 92 struct xsk_socket *xsk; 90 struct xsk_socket *xsk; 93 struct pkt_stream *pkt_stream; 91 struct pkt_stream *pkt_stream; 94 u32 outstanding_tx; 92 u32 outstanding_tx; 95 u32 rxqsize; 93 u32 rxqsize; 96 u32 batch_size; 94 u32 batch_size; 97 u8 dst_mac[ETH_ALEN]; 95 u8 dst_mac[ETH_ALEN]; 98 u8 src_mac[ETH_ALEN]; 96 u8 src_mac[ETH_ALEN]; 99 }; 97 }; 100 98 101 struct pkt { 99 struct pkt { 102 int offset; 100 int offset; 103 u32 len; 101 u32 len; 104 u32 pkt_nb; 102 u32 pkt_nb; 105 bool valid; 103 bool valid; 106 u16 options; 104 u16 options; 107 }; 105 }; 108 106 109 struct pkt_stream { 107 struct pkt_stream { 110 u32 nb_pkts; 108 u32 nb_pkts; 111 u32 current_pkt_nb; 109 u32 current_pkt_nb; 112 struct pkt *pkts; 110 struct pkt *pkts; 113 u32 max_pkt_len; 111 u32 max_pkt_len; 114 u32 nb_rx_pkts; 112 u32 nb_rx_pkts; 115 u32 nb_valid_entries; 113 u32 nb_valid_entries; 116 bool verbatim; 114 bool verbatim; 117 }; 115 }; 118 116 119 struct set_hw_ring { 117 struct set_hw_ring { 120 u32 default_tx; 118 u32 default_tx; 121 u32 default_rx; 119 u32 default_rx; 122 }; 120 }; 123 121 124 struct ifobject; 122 struct ifobject; 125 struct test_spec; 123 struct test_spec; 126 typedef int (*validation_func_t)(struct ifobje 124 typedef int (*validation_func_t)(struct ifobject *ifobj); 127 typedef void *(*thread_func_t)(void *arg); 125 typedef void *(*thread_func_t)(void *arg); 128 typedef int (*test_func_t)(struct test_spec *t 126 typedef int (*test_func_t)(struct test_spec *test); 129 127 130 struct ifobject { 128 struct ifobject { 131 char ifname[MAX_INTERFACE_NAME_CHARS]; 129 char ifname[MAX_INTERFACE_NAME_CHARS]; 132 struct xsk_socket_info *xsk; 130 struct xsk_socket_info *xsk; 133 struct xsk_socket_info *xsk_arr; 131 struct xsk_socket_info *xsk_arr; 134 struct xsk_umem_info *umem; 132 struct xsk_umem_info *umem; 135 thread_func_t func_ptr; 133 thread_func_t func_ptr; 136 validation_func_t validation_func; 134 validation_func_t validation_func; 137 struct xsk_xdp_progs *xdp_progs; 135 struct xsk_xdp_progs *xdp_progs; 138 struct bpf_map *xskmap; 136 struct bpf_map *xskmap; 139 struct bpf_program *xdp_prog; 137 struct bpf_program *xdp_prog; 140 struct ethtool_ringparam ring; 138 struct ethtool_ringparam ring; 141 struct set_hw_ring set_ring; 139 struct set_hw_ring set_ring; 142 enum test_mode mode; 140 enum test_mode mode; 143 int ifindex; 141 int ifindex; 144 int mtu; 142 int mtu; 145 u32 bind_flags; 143 u32 bind_flags; 146 u32 xdp_zc_max_segs; 144 u32 xdp_zc_max_segs; 147 bool tx_on; 145 bool tx_on; 148 bool rx_on; 146 bool rx_on; 149 bool use_poll; 147 bool use_poll; 150 bool busy_poll; 148 bool busy_poll; 151 bool use_fill_ring; 149 bool use_fill_ring; 152 bool release_rx; 150 bool release_rx; 153 bool shared_umem; 151 bool shared_umem; 154 bool use_metadata; 152 bool use_metadata; 155 bool unaligned_supp; 153 bool unaligned_supp; 156 bool multi_buff_supp; 154 bool multi_buff_supp; 157 bool multi_buff_zc_supp; 155 bool multi_buff_zc_supp; 158 bool hw_ring_size_supp; 156 bool hw_ring_size_supp; 159 }; 157 }; 160 158 161 struct test_spec { 159 struct test_spec { 162 struct ifobject *ifobj_tx; 160 struct ifobject *ifobj_tx; 163 struct ifobject *ifobj_rx; 161 struct ifobject *ifobj_rx; 164 struct pkt_stream *tx_pkt_stream_defau 162 struct pkt_stream *tx_pkt_stream_default; 165 struct pkt_stream *rx_pkt_stream_defau 163 struct pkt_stream *rx_pkt_stream_default; 166 struct bpf_program *xdp_prog_rx; 164 struct bpf_program *xdp_prog_rx; 167 struct bpf_program *xdp_prog_tx; 165 struct bpf_program *xdp_prog_tx; 168 struct bpf_map *xskmap_rx; 166 struct bpf_map *xskmap_rx; 169 struct bpf_map *xskmap_tx; 167 struct bpf_map *xskmap_tx; 170 test_func_t test_func; 168 test_func_t test_func; 171 int mtu; 169 int mtu; 172 u16 total_steps; 170 u16 total_steps; 173 u16 current_step; 171 u16 current_step; 174 u16 nb_sockets; 172 u16 nb_sockets; 175 bool fail; 173 bool fail; 176 bool set_ring; 174 bool set_ring; 177 enum test_mode mode; 175 enum test_mode mode; 178 char name[MAX_TEST_NAME_SIZE]; 176 char name[MAX_TEST_NAME_SIZE]; 179 }; 177 }; 180 178 181 pthread_barrier_t barr; 179 pthread_barrier_t barr; 182 pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_I 180 pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_INITIALIZER; 183 181 184 int pkts_in_flight; 182 int pkts_in_flight; 185 183 186 static const u8 g_mac[ETH_ALEN] = {0x55, 0x44, 184 static const u8 g_mac[ETH_ALEN] = {0x55, 0x44, 0x33, 0x22, 0x11, 0x00}; 187 185 188 #endif /* XSKXCEIVER_ 186 #endif /* XSKXCEIVER_H_ */ 189 187
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.