2020-12-07 21:53:30 +00:00
/* SPDX-License-Identifier: GPL-2.0
* Copyright ( c ) 2020 Intel Corporation .
*/
# ifndef XDPXCEIVER_H_
# define XDPXCEIVER_H_
# ifndef SOL_XDP
# define SOL_XDP 283
# endif
# ifndef AF_XDP
# define AF_XDP 44
# endif
# ifndef PF_XDP
# define PF_XDP AF_XDP
# endif
# define MAX_INTERFACES 2
# define MAX_INTERFACE_NAME_CHARS 7
# define MAX_INTERFACES_NAMESPACE_CHARS 10
2021-09-07 09:19:09 +02:00
# define MAX_SOCKETS 2
2021-09-07 09:19:15 +02:00
# define MAX_TEST_NAME_SIZE 32
2020-12-07 21:53:32 +00:00
# define MAX_TEARDOWN_ITER 10
2020-12-07 21:53:30 +00:00
# define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \
sizeof ( struct udphdr ) )
# define MIN_PKT_SIZE 64
# define ETH_FCS_SIZE 4
# define PKT_SIZE (MIN_PKT_SIZE - ETH_FCS_SIZE)
# define IP_PKT_SIZE (PKT_SIZE - sizeof(struct ethhdr))
# define IP_PKT_VER 0x4
# define IP_PKT_TOS 0x9
# define UDP_PKT_SIZE (IP_PKT_SIZE - sizeof(struct iphdr))
# define UDP_PKT_DATA_SIZE (UDP_PKT_SIZE - sizeof(struct udphdr))
2021-08-25 11:37:11 +02:00
# define USLEEP_MAX 10000
2020-12-07 21:53:30 +00:00
# define SOCK_RECONF_CTR 10
2021-09-22 09:56:10 +02:00
# define BATCH_SIZE 64
2020-12-07 21:53:30 +00:00
# define POLL_TMOUT 1000
2021-08-25 11:37:08 +02:00
# define DEFAULT_PKT_CNT (4 * 1024)
2021-09-07 09:19:27 +02:00
# define DEFAULT_UMEM_BUFFERS (DEFAULT_PKT_CNT / 4)
# define UMEM_SIZE (DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE)
2021-02-23 16:23:04 +00:00
# define RX_FULL_RXQSIZE 32
2021-09-22 09:56:13 +02:00
# define UMEM_HEADROOM_TEST_SIZE 128
2021-08-25 11:37:20 +02:00
# define XSK_UMEM__INVALID_FRAME_SIZE (XSK_UMEM__DEFAULT_FRAME_SIZE + 1)
2020-12-07 21:53:30 +00:00
2021-02-23 16:23:01 +00:00
# define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0)
2021-08-25 11:37:21 +02:00
enum test_mode {
2021-02-23 16:23:03 +00:00
TEST_MODE_SKB ,
TEST_MODE_DRV ,
TEST_MODE_MAX
2020-12-07 21:53:30 +00:00
} ;
2021-08-25 11:37:21 +02:00
enum test_type {
2021-09-07 09:19:27 +02:00
TEST_TYPE_RUN_TO_COMPLETION ,
2021-09-07 09:19:28 +02:00
TEST_TYPE_RUN_TO_COMPLETION_2K_FRAME ,
2021-09-22 09:56:11 +02:00
TEST_TYPE_RUN_TO_COMPLETION_SINGLE_PKT ,
2021-02-23 16:23:03 +00:00
TEST_TYPE_POLL ,
2021-09-07 09:19:25 +02:00
TEST_TYPE_UNALIGNED ,
2021-09-07 09:19:27 +02:00
TEST_TYPE_ALIGNED_INV_DESC ,
2021-09-07 09:19:28 +02:00
TEST_TYPE_ALIGNED_INV_DESC_2K_FRAME ,
2021-09-07 09:19:27 +02:00
TEST_TYPE_UNALIGNED_INV_DESC ,
2021-09-22 09:56:13 +02:00
TEST_TYPE_HEADROOM ,
2021-02-23 16:23:03 +00:00
TEST_TYPE_TEARDOWN ,
TEST_TYPE_BIDI ,
2021-02-23 16:23:04 +00:00
TEST_TYPE_STATS ,
2021-03-30 00:43:13 +02:00
TEST_TYPE_BPF_RES ,
2021-02-23 16:23:03 +00:00
TEST_TYPE_MAX
} ;
2021-08-25 11:37:21 +02:00
enum stat_test_type {
2021-02-23 16:23:04 +00:00
STAT_TEST_RX_DROPPED ,
STAT_TEST_TX_INVALID ,
STAT_TEST_RX_FULL ,
STAT_TEST_RX_FILL_EMPTY ,
STAT_TEST_TYPE_MAX
} ;
2021-08-25 11:37:22 +02:00
static bool opt_pkt_dump ;
2021-02-23 16:23:03 +00:00
static int test_type ;
2020-12-07 21:53:30 +00:00
2021-08-25 11:37:22 +02:00
static bool opt_verbose ;
2021-02-23 16:23:04 +00:00
static int stat_test_type ;
2020-12-07 21:53:30 +00:00
struct xsk_umem_info {
struct xsk_ring_prod fq ;
struct xsk_ring_cons cq ;
struct xsk_umem * umem ;
2021-09-07 09:19:12 +02:00
u32 num_frames ;
u32 frame_headroom ;
2020-12-07 21:53:30 +00:00
void * buffer ;
2021-09-07 09:19:14 +02:00
u32 frame_size ;
2021-09-07 09:19:25 +02:00
bool unaligned_mode ;
2020-12-07 21:53:30 +00:00
} ;
struct xsk_socket_info {
struct xsk_ring_cons rx ;
struct xsk_ring_prod tx ;
struct xsk_umem_info * umem ;
struct xsk_socket * xsk ;
u32 outstanding_tx ;
2021-09-07 09:19:13 +02:00
u32 rxqsize ;
2020-12-07 21:53:30 +00:00
} ;
2021-08-25 11:37:20 +02:00
struct pkt {
u64 addr ;
u32 len ;
u32 payload ;
2021-09-07 09:19:23 +02:00
bool valid ;
2021-08-25 11:37:20 +02:00
} ;
struct pkt_stream {
u32 nb_pkts ;
2021-09-07 09:19:27 +02:00
u32 rx_pkt_nb ;
2021-08-25 11:37:20 +02:00
struct pkt * pkts ;
2021-09-07 09:19:25 +02:00
bool use_addr_for_fill ;
2021-08-25 11:37:20 +02:00
} ;
2021-09-07 09:19:10 +02:00
typedef void * ( * thread_func_t ) ( void * arg ) ;
2020-12-07 21:53:30 +00:00
struct ifobject {
char ifname [ MAX_INTERFACE_NAME_CHARS ] ;
char nsname [ MAX_INTERFACES_NAMESPACE_CHARS ] ;
struct xsk_socket_info * xsk ;
2021-09-07 09:19:09 +02:00
struct xsk_socket_info * xsk_arr ;
2020-12-07 21:53:30 +00:00
struct xsk_umem_info * umem ;
2021-09-07 09:19:09 +02:00
struct xsk_umem_info * umem_arr ;
2021-09-07 09:19:10 +02:00
thread_func_t func_ptr ;
2021-08-25 11:37:20 +02:00
struct pkt_stream * pkt_stream ;
2021-03-30 00:43:10 +02:00
int ns_fd ;
2020-12-07 21:53:30 +00:00
u32 dst_ip ;
u32 src_ip ;
2021-09-07 09:19:20 +02:00
u32 xdp_flags ;
u32 bind_flags ;
2020-12-07 21:53:30 +00:00
u16 src_port ;
u16 dst_port ;
2021-09-07 09:19:17 +02:00
bool tx_on ;
bool rx_on ;
2021-09-07 09:19:16 +02:00
bool use_poll ;
2021-09-22 09:56:10 +02:00
bool pacing_on ;
2021-03-30 00:43:10 +02:00
u8 dst_mac [ ETH_ALEN ] ;
u8 src_mac [ ETH_ALEN ] ;
2020-12-07 21:53:30 +00:00
} ;
2021-09-07 09:19:11 +02:00
struct test_spec {
struct ifobject * ifobj_tx ;
struct ifobject * ifobj_rx ;
2021-09-07 09:19:24 +02:00
struct pkt_stream * pkt_stream_default ;
2021-09-07 09:19:18 +02:00
u16 total_steps ;
u16 current_step ;
2021-09-07 09:19:19 +02:00
u16 nb_sockets ;
2021-09-07 09:19:15 +02:00
char name [ MAX_TEST_NAME_SIZE ] ;
2021-09-07 09:19:11 +02:00
} ;
2020-12-07 21:53:30 +00:00
2021-03-30 00:43:15 +02:00
pthread_barrier_t barr ;
2021-09-22 09:56:10 +02:00
pthread_mutex_t pacing_mutex = PTHREAD_MUTEX_INITIALIZER ;
pthread_cond_t pacing_cond = PTHREAD_COND_INITIALIZER ;
u32 pkts_in_flight ;
2020-12-07 21:53:30 +00:00
# endif /* XDPXCEIVER_H */