1018a8e75SMaciej Fijalkowski /* SPDX-License-Identifier: GPL-2.0 2018a8e75SMaciej Fijalkowski * Copyright(c) 2020 Intel Corporation. 3018a8e75SMaciej Fijalkowski */ 4018a8e75SMaciej Fijalkowski 5018a8e75SMaciej Fijalkowski #ifndef XSKXCEIVER_H_ 6018a8e75SMaciej Fijalkowski #define XSKXCEIVER_H_ 7018a8e75SMaciej Fijalkowski 8f0a249dfSMagnus Karlsson #include "xsk_xdp_progs.skel.h" 9f0a249dfSMagnus Karlsson 10018a8e75SMaciej Fijalkowski #ifndef SOL_XDP 11018a8e75SMaciej Fijalkowski #define SOL_XDP 283 12018a8e75SMaciej Fijalkowski #endif 13018a8e75SMaciej Fijalkowski 14018a8e75SMaciej Fijalkowski #ifndef AF_XDP 15018a8e75SMaciej Fijalkowski #define AF_XDP 44 16018a8e75SMaciej Fijalkowski #endif 17018a8e75SMaciej Fijalkowski 18018a8e75SMaciej Fijalkowski #ifndef PF_XDP 19018a8e75SMaciej Fijalkowski #define PF_XDP AF_XDP 20018a8e75SMaciej Fijalkowski #endif 21018a8e75SMaciej Fijalkowski 22018a8e75SMaciej Fijalkowski #ifndef SO_BUSY_POLL_BUDGET 23018a8e75SMaciej Fijalkowski #define SO_BUSY_POLL_BUDGET 70 24018a8e75SMaciej Fijalkowski #endif 25018a8e75SMaciej Fijalkowski 26018a8e75SMaciej Fijalkowski #ifndef SO_PREFER_BUSY_POLL 27018a8e75SMaciej Fijalkowski #define SO_PREFER_BUSY_POLL 69 28018a8e75SMaciej Fijalkowski #endif 29018a8e75SMaciej Fijalkowski 30018a8e75SMaciej Fijalkowski #define TEST_PASS 0 31018a8e75SMaciej Fijalkowski #define TEST_FAILURE -1 323143d10bSShibin Koikkara Reeny #define TEST_CONTINUE 1 33041b68f6SMagnus Karlsson #define TEST_SKIP 2 34018a8e75SMaciej Fijalkowski #define MAX_INTERFACES 2 3524037ba7SMaciej Fijalkowski #define MAX_INTERFACE_NAME_CHARS 16 36018a8e75SMaciej Fijalkowski #define MAX_SOCKETS 2 37018a8e75SMaciej Fijalkowski #define MAX_TEST_NAME_SIZE 32 38018a8e75SMaciej Fijalkowski #define MAX_TEARDOWN_ITER 10 39df82d2e8SMagnus Karlsson #define PKT_HDR_SIZE (sizeof(struct ethhdr) + 2) /* Just to align the data in the packet */ 40df82d2e8SMagnus Karlsson #define MIN_PKT_SIZE 64 41f540d44eSMagnus Karlsson #define MAX_ETH_PKT_SIZE 1518 4217f1034dSMagnus Karlsson #define MAX_ETH_JUMBO_SIZE 9000 43018a8e75SMaciej Fijalkowski #define USLEEP_MAX 10000 44018a8e75SMaciej Fijalkowski #define SOCK_RECONF_CTR 10 45018a8e75SMaciej Fijalkowski #define BATCH_SIZE 64 46018a8e75SMaciej Fijalkowski #define POLL_TMOUT 1000 473143d10bSShibin Koikkara Reeny #define THREAD_TMOUT 3 48018a8e75SMaciej Fijalkowski #define DEFAULT_PKT_CNT (4 * 1024) 49018a8e75SMaciej Fijalkowski #define DEFAULT_UMEM_BUFFERS (DEFAULT_PKT_CNT / 4) 50018a8e75SMaciej Fijalkowski #define RX_FULL_RXQSIZE 32 51018a8e75SMaciej Fijalkowski #define UMEM_HEADROOM_TEST_SIZE 128 5217f1034dSMagnus Karlsson #define XSK_UMEM__INVALID_FRAME_SIZE (MAX_ETH_JUMBO_SIZE + 1) 5369760449SMagnus Karlsson #define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024) 5469760449SMagnus Karlsson #define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024) 5569760449SMagnus Karlsson #define XSK_DESC__INVALID_OPTION (0xffff) 56*807bf4daSMagnus Karlsson #define XSK_DESC__MAX_SKB_FRAGS 18 572ddade32SMagnus Karlsson #define HUGEPAGE_SIZE (2 * 1024 * 1024) 58feb973a9SMagnus Karlsson #define PKT_DUMP_NB_TO_PRINT 16 59018a8e75SMaciej Fijalkowski 60018a8e75SMaciej Fijalkowski #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0) 61018a8e75SMaciej Fijalkowski 62018a8e75SMaciej Fijalkowski enum test_mode { 63018a8e75SMaciej Fijalkowski TEST_MODE_SKB, 64018a8e75SMaciej Fijalkowski TEST_MODE_DRV, 65fe2ad08eSMaciej Fijalkowski TEST_MODE_ZC, 66018a8e75SMaciej Fijalkowski TEST_MODE_MAX 67018a8e75SMaciej Fijalkowski }; 68018a8e75SMaciej Fijalkowski 69018a8e75SMaciej Fijalkowski enum test_type { 70018a8e75SMaciej Fijalkowski TEST_TYPE_RUN_TO_COMPLETION, 71018a8e75SMaciej Fijalkowski TEST_TYPE_RUN_TO_COMPLETION_2K_FRAME, 72018a8e75SMaciej Fijalkowski TEST_TYPE_RUN_TO_COMPLETION_SINGLE_PKT, 733143d10bSShibin Koikkara Reeny TEST_TYPE_RX_POLL, 743143d10bSShibin Koikkara Reeny TEST_TYPE_TX_POLL, 753143d10bSShibin Koikkara Reeny TEST_TYPE_POLL_RXQ_TMOUT, 763143d10bSShibin Koikkara Reeny TEST_TYPE_POLL_TXQ_TMOUT, 77018a8e75SMaciej Fijalkowski TEST_TYPE_UNALIGNED, 78018a8e75SMaciej Fijalkowski TEST_TYPE_ALIGNED_INV_DESC, 79018a8e75SMaciej Fijalkowski TEST_TYPE_ALIGNED_INV_DESC_2K_FRAME, 80018a8e75SMaciej Fijalkowski TEST_TYPE_UNALIGNED_INV_DESC, 81c0801598SKal Conley TEST_TYPE_UNALIGNED_INV_DESC_4K1_FRAME, 82018a8e75SMaciej Fijalkowski TEST_TYPE_HEADROOM, 83018a8e75SMaciej Fijalkowski TEST_TYPE_TEARDOWN, 84018a8e75SMaciej Fijalkowski TEST_TYPE_BIDI, 85018a8e75SMaciej Fijalkowski TEST_TYPE_STATS_RX_DROPPED, 86018a8e75SMaciej Fijalkowski TEST_TYPE_STATS_TX_INVALID_DESCS, 87018a8e75SMaciej Fijalkowski TEST_TYPE_STATS_RX_FULL, 88018a8e75SMaciej Fijalkowski TEST_TYPE_STATS_FILL_EMPTY, 89018a8e75SMaciej Fijalkowski TEST_TYPE_BPF_RES, 9080bea9acSMagnus Karlsson TEST_TYPE_XDP_DROP_HALF, 919a321fd3STushar Vyavahare TEST_TYPE_XDP_METADATA_COUNT, 92f80ddbecSMagnus Karlsson TEST_TYPE_XDP_METADATA_COUNT_MB, 93f540d44eSMagnus Karlsson TEST_TYPE_RUN_TO_COMPLETION_MB, 941005a226SMagnus Karlsson TEST_TYPE_UNALIGNED_MB, 9569760449SMagnus Karlsson TEST_TYPE_ALIGNED_INV_DESC_MB, 9669760449SMagnus Karlsson TEST_TYPE_UNALIGNED_INV_DESC_MB, 97*807bf4daSMagnus Karlsson TEST_TYPE_TOO_MANY_FRAGS, 98018a8e75SMaciej Fijalkowski TEST_TYPE_MAX 99018a8e75SMaciej Fijalkowski }; 100018a8e75SMaciej Fijalkowski 101018a8e75SMaciej Fijalkowski static bool opt_verbose; 102018a8e75SMaciej Fijalkowski 103018a8e75SMaciej Fijalkowski struct xsk_umem_info { 104018a8e75SMaciej Fijalkowski struct xsk_ring_prod fq; 105018a8e75SMaciej Fijalkowski struct xsk_ring_cons cq; 106018a8e75SMaciej Fijalkowski struct xsk_umem *umem; 107d9f6d970SMagnus Karlsson u64 next_buffer; 108018a8e75SMaciej Fijalkowski u32 num_frames; 109018a8e75SMaciej Fijalkowski u32 frame_headroom; 110018a8e75SMaciej Fijalkowski void *buffer; 111018a8e75SMaciej Fijalkowski u32 frame_size; 1121adef064SMaciej Fijalkowski u32 base_addr; 113018a8e75SMaciej Fijalkowski bool unaligned_mode; 114018a8e75SMaciej Fijalkowski }; 115018a8e75SMaciej Fijalkowski 116018a8e75SMaciej Fijalkowski struct xsk_socket_info { 117018a8e75SMaciej Fijalkowski struct xsk_ring_cons rx; 118018a8e75SMaciej Fijalkowski struct xsk_ring_prod tx; 119018a8e75SMaciej Fijalkowski struct xsk_umem_info *umem; 120018a8e75SMaciej Fijalkowski struct xsk_socket *xsk; 121018a8e75SMaciej Fijalkowski u32 outstanding_tx; 122018a8e75SMaciej Fijalkowski u32 rxqsize; 123018a8e75SMaciej Fijalkowski }; 124018a8e75SMaciej Fijalkowski 125018a8e75SMaciej Fijalkowski struct pkt { 126d9f6d970SMagnus Karlsson int offset; 127018a8e75SMaciej Fijalkowski u32 len; 128feb973a9SMagnus Karlsson u32 pkt_nb; 129018a8e75SMaciej Fijalkowski bool valid; 13069760449SMagnus Karlsson u16 options; 131018a8e75SMaciej Fijalkowski }; 132018a8e75SMaciej Fijalkowski 133018a8e75SMaciej Fijalkowski struct pkt_stream { 134018a8e75SMaciej Fijalkowski u32 nb_pkts; 13569fc03d2SMagnus Karlsson u32 current_pkt_nb; 136018a8e75SMaciej Fijalkowski struct pkt *pkts; 1377cd6df4fSMagnus Karlsson u32 max_pkt_len; 13869760449SMagnus Karlsson bool verbatim; 139018a8e75SMaciej Fijalkowski }; 140018a8e75SMaciej Fijalkowski 141018a8e75SMaciej Fijalkowski struct ifobject; 142018a8e75SMaciej Fijalkowski typedef int (*validation_func_t)(struct ifobject *ifobj); 143018a8e75SMaciej Fijalkowski typedef void *(*thread_func_t)(void *arg); 144018a8e75SMaciej Fijalkowski 145018a8e75SMaciej Fijalkowski struct ifobject { 146018a8e75SMaciej Fijalkowski char ifname[MAX_INTERFACE_NAME_CHARS]; 147018a8e75SMaciej Fijalkowski struct xsk_socket_info *xsk; 148018a8e75SMaciej Fijalkowski struct xsk_socket_info *xsk_arr; 149018a8e75SMaciej Fijalkowski struct xsk_umem_info *umem; 150018a8e75SMaciej Fijalkowski thread_func_t func_ptr; 151018a8e75SMaciej Fijalkowski validation_func_t validation_func; 152018a8e75SMaciej Fijalkowski struct pkt_stream *pkt_stream; 153f0a249dfSMagnus Karlsson struct xsk_xdp_progs *xdp_progs; 154f0a249dfSMagnus Karlsson struct bpf_map *xskmap; 1557d8319a7SMagnus Karlsson struct bpf_program *xdp_prog; 1567d8319a7SMagnus Karlsson enum test_mode mode; 157aa61d81fSMagnus Karlsson int ifindex; 158f540d44eSMagnus Karlsson int mtu; 159018a8e75SMaciej Fijalkowski u32 bind_flags; 160*807bf4daSMagnus Karlsson u32 xdp_zc_max_segs; 161018a8e75SMaciej Fijalkowski bool tx_on; 162018a8e75SMaciej Fijalkowski bool rx_on; 163018a8e75SMaciej Fijalkowski bool use_poll; 164018a8e75SMaciej Fijalkowski bool busy_poll; 165018a8e75SMaciej Fijalkowski bool use_fill_ring; 166018a8e75SMaciej Fijalkowski bool release_rx; 167a693ff3eSMaciej Fijalkowski bool shared_umem; 1689a321fd3STushar Vyavahare bool use_metadata; 169041b68f6SMagnus Karlsson bool unaligned_supp; 170f540d44eSMagnus Karlsson bool multi_buff_supp; 171f540d44eSMagnus Karlsson bool multi_buff_zc_supp; 172018a8e75SMaciej Fijalkowski u8 dst_mac[ETH_ALEN]; 173018a8e75SMaciej Fijalkowski u8 src_mac[ETH_ALEN]; 174018a8e75SMaciej Fijalkowski }; 175018a8e75SMaciej Fijalkowski 176018a8e75SMaciej Fijalkowski struct test_spec { 177018a8e75SMaciej Fijalkowski struct ifobject *ifobj_tx; 178018a8e75SMaciej Fijalkowski struct ifobject *ifobj_rx; 1791adef064SMaciej Fijalkowski struct pkt_stream *tx_pkt_stream_default; 1801adef064SMaciej Fijalkowski struct pkt_stream *rx_pkt_stream_default; 1817d8319a7SMagnus Karlsson struct bpf_program *xdp_prog_rx; 1827d8319a7SMagnus Karlsson struct bpf_program *xdp_prog_tx; 1837d8319a7SMagnus Karlsson struct bpf_map *xskmap_rx; 1847d8319a7SMagnus Karlsson struct bpf_map *xskmap_tx; 185f540d44eSMagnus Karlsson int mtu; 186018a8e75SMaciej Fijalkowski u16 total_steps; 187018a8e75SMaciej Fijalkowski u16 current_step; 188018a8e75SMaciej Fijalkowski u16 nb_sockets; 189018a8e75SMaciej Fijalkowski bool fail; 190fe2ad08eSMaciej Fijalkowski enum test_mode mode; 191018a8e75SMaciej Fijalkowski char name[MAX_TEST_NAME_SIZE]; 192018a8e75SMaciej Fijalkowski }; 193018a8e75SMaciej Fijalkowski 194018a8e75SMaciej Fijalkowski pthread_barrier_t barr; 195018a8e75SMaciej Fijalkowski pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_INITIALIZER; 196018a8e75SMaciej Fijalkowski 197018a8e75SMaciej Fijalkowski int pkts_in_flight; 198018a8e75SMaciej Fijalkowski 199018a8e75SMaciej Fijalkowski #endif /* XSKXCEIVER_H_ */ 200