xref: /dpdk/app/test-pmd/testpmd.h (revision 55509e3a49fb28317c1e56a534cdcc4a3849df79)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4 
5 #ifndef _TESTPMD_H_
6 #define _TESTPMD_H_
7 
8 #include <stdbool.h>
9 
10 #include <rte_pci.h>
11 #include <rte_bus_pci.h>
12 #include <rte_gro.h>
13 #include <rte_gso.h>
14 #include <cmdline.h>
15 
16 #define RTE_PORT_ALL            (~(portid_t)0x0)
17 
18 #define RTE_TEST_RX_DESC_MAX    2048
19 #define RTE_TEST_TX_DESC_MAX    2048
20 
21 #define RTE_PORT_STOPPED        (uint16_t)0
22 #define RTE_PORT_STARTED        (uint16_t)1
23 #define RTE_PORT_CLOSED         (uint16_t)2
24 #define RTE_PORT_HANDLING       (uint16_t)3
25 
26 /*
27  * It is used to allocate the memory for hash key.
28  * The hash key size is NIC dependent.
29  */
30 #define RSS_HASH_KEY_LENGTH 64
31 
32 /*
33  * Default size of the mbuf data buffer to receive standard 1518-byte
34  * Ethernet frames in a mono-segment memory buffer.
35  */
36 #define DEFAULT_MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE
37 /**< Default size of mbuf data buffer. */
38 
39 /*
40  * The maximum number of segments per packet is used when creating
41  * scattered transmit packets composed of a list of mbufs.
42  */
43 #define RTE_MAX_SEGS_PER_PKT 255 /**< nb_segs is a 8-bit unsigned char. */
44 
45 #define MAX_PKT_BURST 512
46 #define DEF_PKT_BURST 32
47 
48 #define DEF_MBUF_CACHE 250
49 
50 #define RTE_CACHE_LINE_SIZE_ROUNDUP(size) \
51 	(RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE))
52 
53 #define NUMA_NO_CONFIG 0xFF
54 #define UMA_NO_CONFIG  0xFF
55 
56 typedef uint8_t  lcoreid_t;
57 typedef uint16_t portid_t;
58 typedef uint16_t queueid_t;
59 typedef uint16_t streamid_t;
60 
61 enum {
62 	PORT_TOPOLOGY_PAIRED,
63 	PORT_TOPOLOGY_CHAINED,
64 	PORT_TOPOLOGY_LOOP,
65 };
66 
67 enum {
68 	MP_ALLOC_NATIVE, /**< allocate and populate mempool natively */
69 	MP_ALLOC_ANON,
70 	/**< allocate mempool natively, but populate using anonymous memory */
71 	MP_ALLOC_XMEM,
72 	/**< allocate and populate mempool using anonymous memory */
73 	MP_ALLOC_XMEM_HUGE,
74 	/**< allocate and populate mempool using anonymous hugepage memory */
75 	MP_ALLOC_XBUF
76 	/**< allocate mempool natively, use rte_pktmbuf_pool_create_extbuf */
77 };
78 
79 /**
80  * The data structure associated with RX and TX packet burst statistics
81  * that are recorded for each forwarding stream.
82  */
83 struct pkt_burst_stats {
84 	unsigned int pkt_burst_spread[MAX_PKT_BURST];
85 };
86 
87 /** Information for a given RSS type. */
88 struct rss_type_info {
89 	const char *str; /**< Type name. */
90 	uint64_t rss_type; /**< Type value. */
91 };
92 
93 /**
94  * RSS type information table.
95  *
96  * An entry with a NULL type name terminates the list.
97  */
98 extern const struct rss_type_info rss_type_table[];
99 
100 /**
101  * Dynf name array.
102  *
103  * Array that holds the name for each dynf.
104  */
105 extern char dynf_names[64][RTE_MBUF_DYN_NAMESIZE];
106 
107 /**
108  * The data structure associated with a forwarding stream between a receive
109  * port/queue and a transmit port/queue.
110  */
111 struct fwd_stream {
112 	/* "read-only" data */
113 	portid_t   rx_port;   /**< port to poll for received packets */
114 	queueid_t  rx_queue;  /**< RX queue to poll on "rx_port" */
115 	portid_t   tx_port;   /**< forwarding port of received packets */
116 	queueid_t  tx_queue;  /**< TX queue to send forwarded packets */
117 	streamid_t peer_addr; /**< index of peer ethernet address of packets */
118 
119 	unsigned int retry_enabled;
120 
121 	/* "read-write" results */
122 	uint64_t rx_packets;  /**< received packets */
123 	uint64_t tx_packets;  /**< received packets transmitted */
124 	uint64_t fwd_dropped; /**< received packets not forwarded */
125 	uint64_t rx_bad_ip_csum ; /**< received packets has bad ip checksum */
126 	uint64_t rx_bad_l4_csum ; /**< received packets has bad l4 checksum */
127 	uint64_t rx_bad_outer_l4_csum;
128 	/**< received packets has bad outer l4 checksum */
129 	unsigned int gro_times;	/**< GRO operation times */
130 	uint64_t     core_cycles; /**< used for RX and TX processing */
131 	struct pkt_burst_stats rx_burst_stats;
132 	struct pkt_burst_stats tx_burst_stats;
133 };
134 
135 /** Descriptor for a single flow. */
136 struct port_flow {
137 	struct port_flow *next; /**< Next flow in list. */
138 	struct port_flow *tmp; /**< Temporary linking. */
139 	uint32_t id; /**< Flow rule ID. */
140 	struct rte_flow *flow; /**< Opaque flow object returned by PMD. */
141 	struct rte_flow_conv_rule rule; /* Saved flow rule description. */
142 	uint8_t data[]; /**< Storage for flow rule description */
143 };
144 
145 /* Descriptor for shared action */
146 struct port_shared_action {
147 	struct port_shared_action *next; /**< Next flow in list. */
148 	uint32_t id; /**< Shared action ID. */
149 	enum rte_flow_action_type type; /**< Action type. */
150 	struct rte_flow_shared_action *action;	/**< Shared action handle. */
151 };
152 
153 /**
154  * The data structure associated with each port.
155  */
156 struct rte_port {
157 	struct rte_eth_dev_info dev_info;   /**< PCI info + driver name */
158 	struct rte_eth_conf     dev_conf;   /**< Port configuration. */
159 	struct rte_ether_addr       eth_addr;   /**< Port ethernet address */
160 	struct rte_eth_stats    stats;      /**< Last port statistics */
161 	unsigned int            socket_id;  /**< For NUMA support */
162 	uint16_t		parse_tunnel:1; /**< Parse internal headers */
163 	uint16_t                tso_segsz;  /**< Segmentation offload MSS for non-tunneled packets. */
164 	uint16_t                tunnel_tso_segsz; /**< Segmentation offload MSS for tunneled pkts. */
165 	uint16_t                tx_vlan_id;/**< The tag ID */
166 	uint16_t                tx_vlan_id_outer;/**< The outer tag ID */
167 	uint8_t                 tx_queue_stats_mapping_enabled;
168 	uint8_t                 rx_queue_stats_mapping_enabled;
169 	volatile uint16_t        port_status;    /**< port started or not */
170 	uint8_t                 need_setup;     /**< port just attached */
171 	uint8_t                 need_reconfig;  /**< need reconfiguring port or not */
172 	uint8_t                 need_reconfig_queues; /**< need reconfiguring queues or not */
173 	uint8_t                 rss_flag;   /**< enable rss or not */
174 	uint8_t                 dcb_flag;   /**< enable dcb */
175 	uint16_t                nb_rx_desc[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue rx desc number */
176 	uint16_t                nb_tx_desc[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue tx desc number */
177 	struct rte_eth_rxconf   rx_conf[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue rx configuration */
178 	struct rte_eth_txconf   tx_conf[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue tx configuration */
179 	struct rte_ether_addr   *mc_addr_pool; /**< pool of multicast addrs */
180 	uint32_t                mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
181 	uint8_t                 slave_flag; /**< bonding slave port */
182 	struct port_flow        *flow_list; /**< Associated flows. */
183 	struct port_shared_action *actions_list;
184 	/**< Associated shared actions. */
185 	const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
186 	const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
187 	/**< metadata value to insert in Tx packets. */
188 	uint32_t		tx_metadata;
189 	const struct rte_eth_rxtx_callback *tx_set_md_cb[RTE_MAX_QUEUES_PER_PORT+1];
190 	/**< dynamic flags. */
191 	uint64_t		mbuf_dynf;
192 	const struct rte_eth_rxtx_callback *tx_set_dynf_cb[RTE_MAX_QUEUES_PER_PORT+1];
193 };
194 
195 /**
196  * The data structure associated with each forwarding logical core.
197  * The logical cores are internally numbered by a core index from 0 to
198  * the maximum number of logical cores - 1.
199  * The system CPU identifier of all logical cores are setup in a global
200  * CPU id. configuration table.
201  */
202 struct fwd_lcore {
203 	struct rte_gso_ctx gso_ctx;     /**< GSO context */
204 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
205 	void *gro_ctx;		/**< GRO context */
206 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
207 	streamid_t stream_nb;    /**< number of streams in "fwd_streams" */
208 	lcoreid_t  cpuid_idx;    /**< index of logical core in CPU id table */
209 	queueid_t  tx_queue;     /**< TX queue to send forwarded packets */
210 	volatile char stopped;   /**< stop forwarding when set */
211 };
212 
213 /*
214  * Forwarding mode operations:
215  *   - IO forwarding mode (default mode)
216  *     Forwards packets unchanged.
217  *
218  *   - MAC forwarding mode
219  *     Set the source and the destination Ethernet addresses of packets
220  *     before forwarding them.
221  *
222  *   - IEEE1588 forwarding mode
223  *     Check that received IEEE1588 Precise Time Protocol (PTP) packets are
224  *     filtered and timestamped by the hardware.
225  *     Forwards packets unchanged on the same port.
226  *     Check that sent IEEE1588 PTP packets are timestamped by the hardware.
227  */
228 typedef void (*port_fwd_begin_t)(portid_t pi);
229 typedef void (*port_fwd_end_t)(portid_t pi);
230 typedef void (*packet_fwd_t)(struct fwd_stream *fs);
231 
232 struct fwd_engine {
233 	const char       *fwd_mode_name; /**< Forwarding mode name. */
234 	port_fwd_begin_t port_fwd_begin; /**< NULL if nothing special to do. */
235 	port_fwd_end_t   port_fwd_end;   /**< NULL if nothing special to do. */
236 	packet_fwd_t     packet_fwd;     /**< Mandatory. */
237 };
238 
239 #define BURST_TX_WAIT_US 1
240 #define BURST_TX_RETRIES 64
241 
242 extern uint32_t burst_tx_delay_time;
243 extern uint32_t burst_tx_retry_num;
244 
245 extern struct fwd_engine io_fwd_engine;
246 extern struct fwd_engine mac_fwd_engine;
247 extern struct fwd_engine mac_swap_engine;
248 extern struct fwd_engine flow_gen_engine;
249 extern struct fwd_engine rx_only_engine;
250 extern struct fwd_engine tx_only_engine;
251 extern struct fwd_engine csum_fwd_engine;
252 extern struct fwd_engine icmp_echo_engine;
253 extern struct fwd_engine noisy_vnf_engine;
254 extern struct fwd_engine five_tuple_swap_fwd_engine;
255 #ifdef RTE_LIBRTE_IEEE1588
256 extern struct fwd_engine ieee1588_fwd_engine;
257 #endif
258 
259 extern struct fwd_engine * fwd_engines[]; /**< NULL terminated array. */
260 extern cmdline_parse_inst_t cmd_set_raw;
261 extern cmdline_parse_inst_t cmd_show_set_raw;
262 extern cmdline_parse_inst_t cmd_show_set_raw_all;
263 
264 extern uint16_t mempool_flags;
265 
266 /**
267  * Forwarding Configuration
268  *
269  */
270 struct fwd_config {
271 	struct fwd_engine *fwd_eng; /**< Packet forwarding mode. */
272 	streamid_t nb_fwd_streams;  /**< Nb. of forward streams to process. */
273 	lcoreid_t  nb_fwd_lcores;   /**< Nb. of logical cores to launch. */
274 	portid_t   nb_fwd_ports;    /**< Nb. of ports involved. */
275 };
276 
277 /**
278  * DCB mode enable
279  */
280 enum dcb_mode_enable
281 {
282 	DCB_VT_ENABLED,
283 	DCB_ENABLED
284 };
285 
286 #define MAX_TX_QUEUE_STATS_MAPPINGS 1024 /* MAX_PORT of 32 @ 32 tx_queues/port */
287 #define MAX_RX_QUEUE_STATS_MAPPINGS 4096 /* MAX_PORT of 32 @ 128 rx_queues/port */
288 
289 struct queue_stats_mappings {
290 	portid_t port_id;
291 	uint16_t queue_id;
292 	uint8_t stats_counter_id;
293 } __rte_cache_aligned;
294 
295 extern struct queue_stats_mappings tx_queue_stats_mappings_array[];
296 extern struct queue_stats_mappings rx_queue_stats_mappings_array[];
297 
298 /* Assign both tx and rx queue stats mappings to the same default values */
299 extern struct queue_stats_mappings *tx_queue_stats_mappings;
300 extern struct queue_stats_mappings *rx_queue_stats_mappings;
301 
302 extern uint16_t nb_tx_queue_stats_mappings;
303 extern uint16_t nb_rx_queue_stats_mappings;
304 
305 extern uint8_t xstats_hide_zero; /**< Hide zero values for xstats display */
306 
307 /* globals used for configuration */
308 extern uint8_t record_core_cycles; /**< Enables measurement of CPU cycles */
309 extern uint8_t record_burst_stats; /**< Enables display of RX and TX bursts */
310 extern uint16_t verbose_level; /**< Drives messages being displayed, if any. */
311 extern int testpmd_logtype; /**< Log type for testpmd logs */
312 extern uint8_t  interactive;
313 extern uint8_t  auto_start;
314 extern uint8_t  tx_first;
315 extern char cmdline_filename[PATH_MAX]; /**< offline commands file */
316 extern uint8_t  numa_support; /**< set by "--numa" parameter */
317 extern uint16_t port_topology; /**< set by "--port-topology" parameter */
318 extern uint8_t no_flush_rx; /**<set by "--no-flush-rx" parameter */
319 extern uint8_t flow_isolate_all; /**< set by "--flow-isolate-all */
320 extern uint8_t  mp_alloc_type;
321 /**< set by "--mp-anon" or "--mp-alloc" parameter */
322 extern uint8_t no_link_check; /**<set by "--disable-link-check" parameter */
323 extern uint8_t no_device_start; /**<set by "--disable-device-start" parameter */
324 extern volatile int test_done; /* stop packet forwarding when set to 1. */
325 extern uint8_t lsc_interrupt; /**< disabled by "--no-lsc-interrupt" parameter */
326 extern uint8_t rmv_interrupt; /**< disabled by "--no-rmv-interrupt" parameter */
327 extern uint32_t event_print_mask;
328 /**< set by "--print-event xxxx" and "--mask-event xxxx parameters */
329 extern bool setup_on_probe_event; /**< disabled by port setup-on iterator */
330 extern uint8_t hot_plug; /**< enable by "--hot-plug" parameter */
331 extern int do_mlockall; /**< set by "--mlockall" or "--no-mlockall" parameter */
332 extern uint8_t clear_ptypes; /**< disabled by set ptype cmd */
333 
334 #ifdef RTE_LIBRTE_IXGBE_BYPASS
335 extern uint32_t bypass_timeout; /**< Store the NIC bypass watchdog timeout */
336 #endif
337 
338 /*
339  * Store specified sockets on which memory pool to be used by ports
340  * is allocated.
341  */
342 extern uint8_t port_numa[RTE_MAX_ETHPORTS];
343 
344 /*
345  * Store specified sockets on which RX ring to be used by ports
346  * is allocated.
347  */
348 extern uint8_t rxring_numa[RTE_MAX_ETHPORTS];
349 
350 /*
351  * Store specified sockets on which TX ring to be used by ports
352  * is allocated.
353  */
354 extern uint8_t txring_numa[RTE_MAX_ETHPORTS];
355 
356 extern uint8_t socket_num;
357 
358 /*
359  * Configuration of logical cores:
360  * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
361  */
362 extern lcoreid_t nb_lcores; /**< Number of logical cores probed at init time. */
363 extern lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
364 extern lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
365 extern unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE];
366 extern unsigned int num_sockets;
367 extern unsigned int socket_ids[RTE_MAX_NUMA_NODES];
368 
369 /*
370  * Configuration of Ethernet ports:
371  * nb_fwd_ports <= nb_cfg_ports <= nb_ports
372  */
373 extern portid_t nb_ports; /**< Number of ethernet ports probed at init time. */
374 extern portid_t nb_cfg_ports; /**< Number of configured ports. */
375 extern portid_t nb_fwd_ports; /**< Number of forwarding ports. */
376 extern portid_t fwd_ports_ids[RTE_MAX_ETHPORTS];
377 extern struct rte_port *ports;
378 
379 extern struct rte_eth_rxmode rx_mode;
380 extern struct rte_eth_txmode tx_mode;
381 
382 extern uint64_t rss_hf;
383 
384 extern queueid_t nb_hairpinq;
385 extern queueid_t nb_rxq;
386 extern queueid_t nb_txq;
387 
388 extern uint16_t nb_rxd;
389 extern uint16_t nb_txd;
390 
391 extern int16_t rx_free_thresh;
392 extern int8_t rx_drop_en;
393 extern int16_t tx_free_thresh;
394 extern int16_t tx_rs_thresh;
395 
396 extern uint16_t noisy_tx_sw_bufsz;
397 extern uint16_t noisy_tx_sw_buf_flush_time;
398 extern uint64_t noisy_lkup_mem_sz;
399 extern uint64_t noisy_lkup_num_writes;
400 extern uint64_t noisy_lkup_num_reads;
401 extern uint64_t noisy_lkup_num_reads_writes;
402 
403 extern uint8_t dcb_config;
404 extern uint8_t dcb_test;
405 
406 extern uint16_t mbuf_data_size; /**< Mbuf data space size. */
407 extern uint32_t param_total_num_mbufs;
408 
409 extern uint16_t stats_period;
410 
411 #ifdef RTE_LIBRTE_LATENCY_STATS
412 extern uint8_t latencystats_enabled;
413 extern lcoreid_t latencystats_lcore_id;
414 #endif
415 
416 #ifdef RTE_LIBRTE_BITRATESTATS
417 extern lcoreid_t bitrate_lcore_id;
418 extern uint8_t bitrate_enabled;
419 #endif
420 
421 extern struct rte_fdir_conf fdir_conf;
422 
423 /*
424  * Configuration of packet segments used by the "txonly" processing engine.
425  */
426 #define TXONLY_DEF_PACKET_LEN 64
427 extern uint16_t tx_pkt_length; /**< Length of TXONLY packet */
428 extern uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT]; /**< Seg. lengths */
429 extern uint8_t  tx_pkt_nb_segs; /**< Number of segments in TX packets */
430 extern uint32_t tx_pkt_times_intra;
431 extern uint32_t tx_pkt_times_inter;
432 
433 enum tx_pkt_split {
434 	TX_PKT_SPLIT_OFF,
435 	TX_PKT_SPLIT_ON,
436 	TX_PKT_SPLIT_RND,
437 };
438 
439 extern enum tx_pkt_split tx_pkt_split;
440 
441 extern uint8_t txonly_multi_flow;
442 
443 extern uint16_t nb_pkt_per_burst;
444 extern uint16_t mb_mempool_cache;
445 extern int8_t rx_pthresh;
446 extern int8_t rx_hthresh;
447 extern int8_t rx_wthresh;
448 extern int8_t tx_pthresh;
449 extern int8_t tx_hthresh;
450 extern int8_t tx_wthresh;
451 
452 extern uint16_t tx_udp_src_port;
453 extern uint16_t tx_udp_dst_port;
454 
455 extern uint32_t tx_ip_src_addr;
456 extern uint32_t tx_ip_dst_addr;
457 
458 extern struct fwd_config cur_fwd_config;
459 extern struct fwd_engine *cur_fwd_eng;
460 extern uint32_t retry_enabled;
461 extern struct fwd_lcore  **fwd_lcores;
462 extern struct fwd_stream **fwd_streams;
463 
464 extern uint16_t vxlan_gpe_udp_port; /**< UDP port of tunnel VXLAN-GPE. */
465 extern uint16_t geneve_udp_port; /**< UDP port of tunnel GENEVE. */
466 
467 extern portid_t nb_peer_eth_addrs; /**< Number of peer ethernet addresses. */
468 extern struct rte_ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
469 
470 extern uint32_t burst_tx_delay_time; /**< Burst tx delay time(us) for mac-retry. */
471 extern uint32_t burst_tx_retry_num;  /**< Burst tx retry number for mac-retry. */
472 
473 #define GRO_DEFAULT_ITEM_NUM_PER_FLOW 32
474 #define GRO_DEFAULT_FLOW_NUM (RTE_GRO_MAX_BURST_ITEM_NUM / \
475 		GRO_DEFAULT_ITEM_NUM_PER_FLOW)
476 
477 #define GRO_DEFAULT_FLUSH_CYCLES 1
478 #define GRO_MAX_FLUSH_CYCLES 4
479 
480 struct gro_status {
481 	struct rte_gro_param param;
482 	uint8_t enable;
483 };
484 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
485 extern uint8_t gro_flush_cycles;
486 
487 #define GSO_MAX_PKT_BURST 2048
488 struct gso_status {
489 	uint8_t enable;
490 };
491 extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
492 extern uint16_t gso_max_segment_size;
493 
494 /* VXLAN encap/decap parameters. */
495 struct vxlan_encap_conf {
496 	uint32_t select_ipv4:1;
497 	uint32_t select_vlan:1;
498 	uint32_t select_tos_ttl:1;
499 	uint8_t vni[3];
500 	rte_be16_t udp_src;
501 	rte_be16_t udp_dst;
502 	rte_be32_t ipv4_src;
503 	rte_be32_t ipv4_dst;
504 	uint8_t ipv6_src[16];
505 	uint8_t ipv6_dst[16];
506 	rte_be16_t vlan_tci;
507 	uint8_t ip_tos;
508 	uint8_t ip_ttl;
509 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
510 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
511 };
512 
513 extern struct vxlan_encap_conf vxlan_encap_conf;
514 
515 /* NVGRE encap/decap parameters. */
516 struct nvgre_encap_conf {
517 	uint32_t select_ipv4:1;
518 	uint32_t select_vlan:1;
519 	uint8_t tni[3];
520 	rte_be32_t ipv4_src;
521 	rte_be32_t ipv4_dst;
522 	uint8_t ipv6_src[16];
523 	uint8_t ipv6_dst[16];
524 	rte_be16_t vlan_tci;
525 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
526 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
527 };
528 
529 extern struct nvgre_encap_conf nvgre_encap_conf;
530 
531 /* L2 encap parameters. */
532 struct l2_encap_conf {
533 	uint32_t select_ipv4:1;
534 	uint32_t select_vlan:1;
535 	rte_be16_t vlan_tci;
536 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
537 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
538 };
539 extern struct l2_encap_conf l2_encap_conf;
540 
541 /* L2 decap parameters. */
542 struct l2_decap_conf {
543 	uint32_t select_vlan:1;
544 };
545 extern struct l2_decap_conf l2_decap_conf;
546 
547 /* MPLSoGRE encap parameters. */
548 struct mplsogre_encap_conf {
549 	uint32_t select_ipv4:1;
550 	uint32_t select_vlan:1;
551 	uint8_t label[3];
552 	rte_be32_t ipv4_src;
553 	rte_be32_t ipv4_dst;
554 	uint8_t ipv6_src[16];
555 	uint8_t ipv6_dst[16];
556 	rte_be16_t vlan_tci;
557 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
558 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
559 };
560 extern struct mplsogre_encap_conf mplsogre_encap_conf;
561 
562 /* MPLSoGRE decap parameters. */
563 struct mplsogre_decap_conf {
564 	uint32_t select_ipv4:1;
565 	uint32_t select_vlan:1;
566 };
567 extern struct mplsogre_decap_conf mplsogre_decap_conf;
568 
569 /* MPLSoUDP encap parameters. */
570 struct mplsoudp_encap_conf {
571 	uint32_t select_ipv4:1;
572 	uint32_t select_vlan:1;
573 	uint8_t label[3];
574 	rte_be16_t udp_src;
575 	rte_be16_t udp_dst;
576 	rte_be32_t ipv4_src;
577 	rte_be32_t ipv4_dst;
578 	uint8_t ipv6_src[16];
579 	uint8_t ipv6_dst[16];
580 	rte_be16_t vlan_tci;
581 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
582 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
583 };
584 extern struct mplsoudp_encap_conf mplsoudp_encap_conf;
585 
586 /* MPLSoUDP decap parameters. */
587 struct mplsoudp_decap_conf {
588 	uint32_t select_ipv4:1;
589 	uint32_t select_vlan:1;
590 };
591 extern struct mplsoudp_decap_conf mplsoudp_decap_conf;
592 
593 extern enum rte_eth_rx_mq_mode rx_mq_mode;
594 
595 static inline unsigned int
596 lcore_num(void)
597 {
598 	unsigned int i;
599 
600 	for (i = 0; i < RTE_MAX_LCORE; ++i)
601 		if (fwd_lcores_cpuids[i] == rte_lcore_id())
602 			return i;
603 
604 	rte_panic("lcore_id of current thread not found in fwd_lcores_cpuids\n");
605 }
606 
607 void
608 parse_fwd_portlist(const char *port);
609 
610 static inline struct fwd_lcore *
611 current_fwd_lcore(void)
612 {
613 	return fwd_lcores[lcore_num()];
614 }
615 
616 /* Mbuf Pools */
617 static inline void
618 mbuf_poolname_build(unsigned int sock_id, char* mp_name, int name_size)
619 {
620 	snprintf(mp_name, name_size, "mbuf_pool_socket_%u", sock_id);
621 }
622 
623 static inline struct rte_mempool *
624 mbuf_pool_find(unsigned int sock_id)
625 {
626 	char pool_name[RTE_MEMPOOL_NAMESIZE];
627 
628 	mbuf_poolname_build(sock_id, pool_name, sizeof(pool_name));
629 	return rte_mempool_lookup((const char *)pool_name);
630 }
631 
632 /**
633  * Read/Write operations on a PCI register of a port.
634  */
635 static inline uint32_t
636 port_pci_reg_read(struct rte_port *port, uint32_t reg_off)
637 {
638 	const struct rte_pci_device *pci_dev;
639 	const struct rte_bus *bus;
640 	void *reg_addr;
641 	uint32_t reg_v;
642 
643 	if (!port->dev_info.device) {
644 		printf("Invalid device\n");
645 		return 0;
646 	}
647 
648 	bus = rte_bus_find_by_device(port->dev_info.device);
649 	if (bus && !strcmp(bus->name, "pci")) {
650 		pci_dev = RTE_DEV_TO_PCI(port->dev_info.device);
651 	} else {
652 		printf("Not a PCI device\n");
653 		return 0;
654 	}
655 
656 	reg_addr = ((char *)pci_dev->mem_resource[0].addr + reg_off);
657 	reg_v = *((volatile uint32_t *)reg_addr);
658 	return rte_le_to_cpu_32(reg_v);
659 }
660 
661 #define port_id_pci_reg_read(pt_id, reg_off) \
662 	port_pci_reg_read(&ports[(pt_id)], (reg_off))
663 
664 static inline void
665 port_pci_reg_write(struct rte_port *port, uint32_t reg_off, uint32_t reg_v)
666 {
667 	const struct rte_pci_device *pci_dev;
668 	const struct rte_bus *bus;
669 	void *reg_addr;
670 
671 	if (!port->dev_info.device) {
672 		printf("Invalid device\n");
673 		return;
674 	}
675 
676 	bus = rte_bus_find_by_device(port->dev_info.device);
677 	if (bus && !strcmp(bus->name, "pci")) {
678 		pci_dev = RTE_DEV_TO_PCI(port->dev_info.device);
679 	} else {
680 		printf("Not a PCI device\n");
681 		return;
682 	}
683 
684 	reg_addr = ((char *)pci_dev->mem_resource[0].addr + reg_off);
685 	*((volatile uint32_t *)reg_addr) = rte_cpu_to_le_32(reg_v);
686 }
687 
688 #define port_id_pci_reg_write(pt_id, reg_off, reg_value) \
689 	port_pci_reg_write(&ports[(pt_id)], (reg_off), (reg_value))
690 
691 static inline void
692 get_start_cycles(uint64_t *start_tsc)
693 {
694 	if (record_core_cycles)
695 		*start_tsc = rte_rdtsc();
696 }
697 
698 static inline void
699 get_end_cycles(struct fwd_stream *fs, uint64_t start_tsc)
700 {
701 	if (record_core_cycles)
702 		fs->core_cycles += rte_rdtsc() - start_tsc;
703 }
704 
705 static inline void
706 inc_rx_burst_stats(struct fwd_stream *fs, uint16_t nb_rx)
707 {
708 	if (record_burst_stats)
709 		fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
710 }
711 
712 static inline void
713 inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
714 {
715 	if (record_burst_stats)
716 		fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
717 }
718 
719 /* Prototypes */
720 unsigned int parse_item_list(char* str, const char* item_name,
721 			unsigned int max_items,
722 			unsigned int *parsed_items, int check_unique_values);
723 void launch_args_parse(int argc, char** argv);
724 void cmdline_read_from_file(const char *filename);
725 void prompt(void);
726 void prompt_exit(void);
727 void nic_stats_display(portid_t port_id);
728 void nic_stats_clear(portid_t port_id);
729 void nic_xstats_display(portid_t port_id);
730 void nic_xstats_clear(portid_t port_id);
731 void nic_stats_mapping_display(portid_t port_id);
732 void device_infos_display(const char *identifier);
733 void port_infos_display(portid_t port_id);
734 void port_summary_display(portid_t port_id);
735 void port_eeprom_display(portid_t port_id);
736 void port_module_eeprom_display(portid_t port_id);
737 void port_summary_header_display(void);
738 void port_offload_cap_display(portid_t port_id);
739 void rx_queue_infos_display(portid_t port_idi, uint16_t queue_id);
740 void tx_queue_infos_display(portid_t port_idi, uint16_t queue_id);
741 void fwd_lcores_config_display(void);
742 void pkt_fwd_config_display(struct fwd_config *cfg);
743 void rxtx_config_display(void);
744 void fwd_config_setup(void);
745 void set_def_fwd_config(void);
746 void reconfig(portid_t new_port_id, unsigned socket_id);
747 int init_fwd_streams(void);
748 void update_fwd_ports(portid_t new_pid);
749 
750 void set_fwd_eth_peer(portid_t port_id, char *peer_addr);
751 
752 void port_mtu_set(portid_t port_id, uint16_t mtu);
753 void port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_pos);
754 void port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
755 		      uint8_t bit_v);
756 void port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
757 				uint8_t bit1_pos, uint8_t bit2_pos);
758 void port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
759 			    uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value);
760 void port_reg_display(portid_t port_id, uint32_t reg_off);
761 void port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t value);
762 int port_shared_action_create(portid_t port_id, uint32_t id,
763 			      const struct rte_flow_shared_action_conf *conf,
764 			      const struct rte_flow_action *action);
765 int port_shared_action_destroy(portid_t port_id,
766 			       uint32_t n, const uint32_t *action);
767 struct rte_flow_shared_action *port_shared_action_get_by_id(portid_t port_id,
768 							    uint32_t id);
769 int port_shared_action_update(portid_t port_id, uint32_t id,
770 			      const struct rte_flow_action *action);
771 int port_flow_validate(portid_t port_id,
772 		       const struct rte_flow_attr *attr,
773 		       const struct rte_flow_item *pattern,
774 		       const struct rte_flow_action *actions);
775 int port_flow_create(portid_t port_id,
776 		     const struct rte_flow_attr *attr,
777 		     const struct rte_flow_item *pattern,
778 		     const struct rte_flow_action *actions);
779 int port_shared_action_query(portid_t port_id, uint32_t id);
780 void update_age_action_context(const struct rte_flow_action *actions,
781 		     struct port_flow *pf);
782 int port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule);
783 int port_flow_flush(portid_t port_id);
784 int port_flow_dump(portid_t port_id, const char *file_name);
785 int port_flow_query(portid_t port_id, uint32_t rule,
786 		    const struct rte_flow_action *action);
787 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
788 void port_flow_aged(portid_t port_id, uint8_t destroy);
789 int port_flow_isolate(portid_t port_id, int set);
790 
791 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
792 void tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id);
793 
794 int set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc);
795 int set_fwd_lcores_mask(uint64_t lcoremask);
796 void set_fwd_lcores_number(uint16_t nb_lc);
797 
798 void set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt);
799 void set_fwd_ports_mask(uint64_t portmask);
800 void set_fwd_ports_number(uint16_t nb_pt);
801 int port_is_forwarding(portid_t port_id);
802 
803 void rx_vlan_strip_set(portid_t port_id, int on);
804 void rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on);
805 
806 void rx_vlan_filter_set(portid_t port_id, int on);
807 void rx_vlan_all_filter_set(portid_t port_id, int on);
808 void rx_vlan_qinq_strip_set(portid_t port_id, int on);
809 int rx_vft_set(portid_t port_id, uint16_t vlan_id, int on);
810 void vlan_extend_set(portid_t port_id, int on);
811 void vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type,
812 		   uint16_t tp_id);
813 void tx_vlan_set(portid_t port_id, uint16_t vlan_id);
814 void tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer);
815 void tx_vlan_reset(portid_t port_id);
816 void tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on);
817 
818 void set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value);
819 
820 void set_xstats_hide_zero(uint8_t on_off);
821 
822 void set_record_core_cycles(uint8_t on_off);
823 void set_record_burst_stats(uint8_t on_off);
824 void set_verbose_level(uint16_t vb_level);
825 void set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs);
826 void show_tx_pkt_segments(void);
827 void set_tx_pkt_times(unsigned int *tx_times);
828 void show_tx_pkt_times(void);
829 void set_tx_pkt_split(const char *name);
830 int parse_fec_mode(const char *name, enum rte_eth_fec_mode *mode);
831 void show_fec_capability(uint32_t num, struct rte_eth_fec_capa *speed_fec_capa);
832 void set_nb_pkt_per_burst(uint16_t pkt_burst);
833 char *list_pkt_forwarding_modes(void);
834 char *list_pkt_forwarding_retry_modes(void);
835 void set_pkt_forwarding_mode(const char *fwd_mode);
836 void start_packet_forwarding(int with_tx_first);
837 void fwd_stats_display(void);
838 void fwd_stats_reset(void);
839 void stop_packet_forwarding(void);
840 void dev_set_link_up(portid_t pid);
841 void dev_set_link_down(portid_t pid);
842 void init_port_config(void);
843 void set_port_slave_flag(portid_t slave_pid);
844 void clear_port_slave_flag(portid_t slave_pid);
845 uint8_t port_is_bonding_slave(portid_t slave_pid);
846 
847 int init_port_dcb_config(portid_t pid, enum dcb_mode_enable dcb_mode,
848 		     enum rte_eth_nb_tcs num_tcs,
849 		     uint8_t pfc_en);
850 int start_port(portid_t pid);
851 void stop_port(portid_t pid);
852 void close_port(portid_t pid);
853 void reset_port(portid_t pid);
854 void attach_port(char *identifier);
855 void detach_devargs(char *identifier);
856 void detach_port_device(portid_t port_id);
857 int all_ports_stopped(void);
858 int port_is_stopped(portid_t port_id);
859 int port_is_started(portid_t port_id);
860 void pmd_test_exit(void);
861 void fdir_get_infos(portid_t port_id);
862 void fdir_set_flex_mask(portid_t port_id,
863 			   struct rte_eth_fdir_flex_mask *cfg);
864 void fdir_set_flex_payload(portid_t port_id,
865 			   struct rte_eth_flex_payload_cfg *cfg);
866 void port_rss_reta_info(portid_t port_id,
867 			struct rte_eth_rss_reta_entry64 *reta_conf,
868 			uint16_t nb_entries);
869 
870 void set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on);
871 
872 int set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate);
873 int set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate,
874 				uint64_t q_msk);
875 
876 void port_rss_hash_conf_show(portid_t port_id, int show_rss_key);
877 void port_rss_hash_key_update(portid_t port_id, char rss_type[],
878 			      uint8_t *hash_key, uint hash_key_len);
879 int rx_queue_id_is_invalid(queueid_t rxq_id);
880 int tx_queue_id_is_invalid(queueid_t txq_id);
881 void setup_gro(const char *onoff, portid_t port_id);
882 void setup_gro_flush_cycles(uint8_t cycles);
883 void show_gro(portid_t port_id);
884 void setup_gso(const char *mode, portid_t port_id);
885 int eth_dev_info_get_print_err(uint16_t port_id,
886 			struct rte_eth_dev_info *dev_info);
887 void eth_set_promisc_mode(uint16_t port_id, int enable);
888 void eth_set_allmulticast_mode(uint16_t port, int enable);
889 int eth_link_get_nowait_print_err(uint16_t port_id, struct rte_eth_link *link);
890 int eth_macaddr_get_print_err(uint16_t port_id,
891 			struct rte_ether_addr *mac_addr);
892 
893 /* Functions to display the set of MAC addresses added to a port*/
894 void show_macs(portid_t port_id);
895 void show_mcast_macs(portid_t port_id);
896 
897 /* Functions to manage the set of filtered Multicast MAC addresses */
898 void mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr);
899 void mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr);
900 void port_dcb_info_display(portid_t port_id);
901 
902 uint8_t *open_file(const char *file_path, uint32_t *size);
903 int save_file(const char *file_path, uint8_t *buf, uint32_t size);
904 int close_file(uint8_t *buf);
905 
906 void port_queue_region_info_display(portid_t port_id, void *buf);
907 
908 enum print_warning {
909 	ENABLED_WARN = 0,
910 	DISABLED_WARN
911 };
912 int port_id_is_invalid(portid_t port_id, enum print_warning warning);
913 void print_valid_ports(void);
914 int new_socket_id(unsigned int socket_id);
915 
916 queueid_t get_allowed_max_nb_rxq(portid_t *pid);
917 int check_nb_rxq(queueid_t rxq);
918 queueid_t get_allowed_max_nb_txq(portid_t *pid);
919 int check_nb_txq(queueid_t txq);
920 int check_nb_rxd(queueid_t rxd);
921 int check_nb_txd(queueid_t txd);
922 queueid_t get_allowed_max_nb_hairpinq(portid_t *pid);
923 int check_nb_hairpinq(queueid_t hairpinq);
924 
925 uint16_t dump_rx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
926 		      uint16_t nb_pkts, __rte_unused uint16_t max_pkts,
927 		      __rte_unused void *user_param);
928 
929 uint16_t dump_tx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
930 		      uint16_t nb_pkts, __rte_unused void *user_param);
931 
932 void add_rx_dump_callbacks(portid_t portid);
933 void remove_rx_dump_callbacks(portid_t portid);
934 void add_tx_dump_callbacks(portid_t portid);
935 void remove_tx_dump_callbacks(portid_t portid);
936 void configure_rxtx_dump_callbacks(uint16_t verbose);
937 
938 uint16_t tx_pkt_set_md(uint16_t port_id, __rte_unused uint16_t queue,
939 		       struct rte_mbuf *pkts[], uint16_t nb_pkts,
940 		       __rte_unused void *user_param);
941 void add_tx_md_callback(portid_t portid);
942 void remove_tx_md_callback(portid_t portid);
943 
944 uint16_t tx_pkt_set_dynf(uint16_t port_id, __rte_unused uint16_t queue,
945 			 struct rte_mbuf *pkts[], uint16_t nb_pkts,
946 			 __rte_unused void *user_param);
947 void add_tx_dynf_callback(portid_t portid);
948 void remove_tx_dynf_callback(portid_t portid);
949 
950 /*
951  * Work-around of a compilation error with ICC on invocations of the
952  * rte_be_to_cpu_16() function.
953  */
954 #ifdef __GCC__
955 #define RTE_BE_TO_CPU_16(be_16_v)  rte_be_to_cpu_16((be_16_v))
956 #define RTE_CPU_TO_BE_16(cpu_16_v) rte_cpu_to_be_16((cpu_16_v))
957 #else
958 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
959 #define RTE_BE_TO_CPU_16(be_16_v)  (be_16_v)
960 #define RTE_CPU_TO_BE_16(cpu_16_v) (cpu_16_v)
961 #else
962 #define RTE_BE_TO_CPU_16(be_16_v) \
963 	(uint16_t) ((((be_16_v) & 0xFF) << 8) | ((be_16_v) >> 8))
964 #define RTE_CPU_TO_BE_16(cpu_16_v) \
965 	(uint16_t) ((((cpu_16_v) & 0xFF) << 8) | ((cpu_16_v) >> 8))
966 #endif
967 #endif /* __GCC__ */
968 
969 #define TESTPMD_LOG(level, fmt, args...) \
970 	rte_log(RTE_LOG_ ## level, testpmd_logtype, "testpmd: " fmt, ## args)
971 
972 #endif /* _TESTPMD_H_ */
973