xref: /dpdk/app/test-pmd/testpmd.h (revision 8ac3a1cd3ebdf54d9bae0dba0b3b8aa5b3f5339a)
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 #ifdef RTE_LIB_GRO
11 #include <rte_gro.h>
12 #endif
13 #ifdef RTE_LIB_GSO
14 #include <rte_gso.h>
15 #endif
16 #include <rte_os_shim.h>
17 #include <rte_ethdev.h>
18 #include <rte_flow.h>
19 #include <rte_mbuf_dyn.h>
20 
21 #include <cmdline.h>
22 #include <cmdline_parse.h>
23 
24 #include <sys/queue.h>
25 #ifdef RTE_HAS_JANSSON
26 #include <jansson.h>
27 #endif
28 
29 #define RTE_PORT_ALL            (~(portid_t)0x0)
30 
31 #define RTE_PORT_STOPPED        (uint16_t)0
32 #define RTE_PORT_STARTED        (uint16_t)1
33 #define RTE_PORT_CLOSED         (uint16_t)2
34 #define RTE_PORT_HANDLING       (uint16_t)3
35 
36 extern uint8_t cl_quit;
37 extern volatile uint8_t f_quit;
38 
39 /*
40  * It is used to allocate the memory for hash key.
41  * The hash key size is NIC dependent.
42  */
43 #define RSS_HASH_KEY_LENGTH 64
44 
45 /*
46  * Default size of the mbuf data buffer to receive standard 1518-byte
47  * Ethernet frames in a mono-segment memory buffer.
48  */
49 #define DEFAULT_MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE
50 /**< Default size of mbuf data buffer. */
51 
52 /*
53  * The maximum number of segments per packet is used when creating
54  * scattered transmit packets composed of a list of mbufs.
55  */
56 #define RTE_MAX_SEGS_PER_PKT 255 /**< nb_segs is a 8-bit unsigned char. */
57 
58 /*
59  * The maximum number of segments per packet is used to configure
60  * buffer split feature, also specifies the maximum amount of
61  * optional Rx pools to allocate mbufs to split.
62  */
63 #define MAX_SEGS_BUFFER_SPLIT 8 /**< nb_segs is a 8-bit unsigned char. */
64 
65 /* The prefix of the mbuf pool names created by the application. */
66 #define MBUF_POOL_NAME_PFX "mb_pool"
67 
68 #define RX_DESC_MAX    2048
69 #define TX_DESC_MAX    2048
70 
71 #define MAX_PKT_BURST 512
72 #define DEF_PKT_BURST 32
73 
74 #define DEF_MBUF_CACHE 250
75 
76 #define RTE_CACHE_LINE_SIZE_ROUNDUP(size) \
77 	(RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE))
78 
79 #define NUMA_NO_CONFIG 0xFF
80 #define UMA_NO_CONFIG  0xFF
81 
82 #define MIN_TOTAL_NUM_MBUFS 1024
83 
84 /* Maximum number of pools supported per Rx queue */
85 #define MAX_MEMPOOL 8
86 
87 typedef uint8_t  lcoreid_t;
88 typedef uint16_t portid_t;
89 typedef uint16_t queueid_t;
90 typedef uint16_t streamid_t;
91 
92 enum {
93 	PORT_TOPOLOGY_PAIRED,
94 	PORT_TOPOLOGY_CHAINED,
95 	PORT_TOPOLOGY_LOOP,
96 };
97 
98 enum {
99 	MP_ALLOC_NATIVE, /**< allocate and populate mempool natively */
100 	MP_ALLOC_ANON,
101 	/**< allocate mempool natively, but populate using anonymous memory */
102 	MP_ALLOC_XMEM,
103 	/**< allocate and populate mempool using anonymous memory */
104 	MP_ALLOC_XMEM_HUGE,
105 	/**< allocate and populate mempool using anonymous hugepage memory */
106 	MP_ALLOC_XBUF
107 	/**< allocate mempool natively, use rte_pktmbuf_pool_create_extbuf */
108 };
109 
110 enum {
111 	QUEUE_JOB_TYPE_FLOW_CREATE,
112 	QUEUE_JOB_TYPE_FLOW_DESTROY,
113 	QUEUE_JOB_TYPE_FLOW_UPDATE,
114 	QUEUE_JOB_TYPE_ACTION_CREATE,
115 	QUEUE_JOB_TYPE_ACTION_DESTROY,
116 	QUEUE_JOB_TYPE_ACTION_UPDATE,
117 	QUEUE_JOB_TYPE_ACTION_QUERY,
118 };
119 
120 enum noisy_fwd_mode {
121 	NOISY_FWD_MODE_IO,
122 	NOISY_FWD_MODE_MAC,
123 	NOISY_FWD_MODE_MACSWAP,
124 	NOISY_FWD_MODE_5TSWAP,
125 	NOISY_FWD_MODE_MAX,
126 };
127 
128 /**
129  * The data structure associated with RX and TX packet burst statistics
130  * that are recorded for each forwarding stream.
131  */
132 struct pkt_burst_stats {
133 	unsigned int pkt_burst_spread[MAX_PKT_BURST + 1];
134 };
135 
136 
137 #define TESTPMD_RSS_TYPES_CHAR_NUM_PER_LINE 64
138 /** Information for a given RSS type. */
139 struct rss_type_info {
140 	const char *str; /**< Type name. */
141 	uint64_t rss_type; /**< Type value. */
142 };
143 
144 /**
145  * RSS type information table.
146  *
147  * An entry with a NULL type name terminates the list.
148  */
149 extern const struct rss_type_info rss_type_table[];
150 
151 /**
152  * Dynf name array.
153  *
154  * Array that holds the name for each dynf.
155  */
156 extern char dynf_names[64][RTE_MBUF_DYN_NAMESIZE];
157 
158 /**
159  * The data structure associated with a forwarding stream between a receive
160  * port/queue and a transmit port/queue.
161  */
162 struct fwd_stream {
163 	/* "read-only" data */
164 	portid_t   rx_port;   /**< port to poll for received packets */
165 	queueid_t  rx_queue;  /**< RX queue to poll on "rx_port" */
166 	portid_t   tx_port;   /**< forwarding port of received packets */
167 	queueid_t  tx_queue;  /**< TX queue to send forwarded packets */
168 	streamid_t peer_addr; /**< index of peer ethernet address of packets */
169 	bool       disabled;  /**< the stream is disabled and should not run */
170 
171 	unsigned int retry_enabled;
172 
173 	/* "read-write" results */
174 	uint64_t rx_packets;  /**< received packets */
175 	uint64_t tx_packets;  /**< received packets transmitted */
176 	uint64_t fwd_dropped; /**< received packets not forwarded */
177 	uint64_t rx_bad_ip_csum ; /**< received packets has bad ip checksum */
178 	uint64_t rx_bad_l4_csum ; /**< received packets has bad l4 checksum */
179 	uint64_t rx_bad_outer_l4_csum;
180 	/**< received packets has bad outer l4 checksum */
181 	uint64_t rx_bad_outer_ip_csum;
182 	/**< received packets having bad outer ip checksum */
183 	uint64_t ts_skew; /**< TX scheduling timestamp */
184 #ifdef RTE_LIB_GRO
185 	unsigned int gro_times;	/**< GRO operation times */
186 #endif
187 	uint64_t busy_cycles; /**< used with --record-core-cycles */
188 	struct pkt_burst_stats rx_burst_stats;
189 	struct pkt_burst_stats tx_burst_stats;
190 	struct fwd_lcore *lcore; /**< Lcore being scheduled. */
191 };
192 
193 /**
194  * Age action context types, must be included inside the age action
195  * context structure.
196  */
197 enum age_action_context_type {
198 	ACTION_AGE_CONTEXT_TYPE_FLOW,
199 	ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION,
200 };
201 
202 /** Descriptor for a template. */
203 struct port_template {
204 	struct port_template *next; /**< Next template in list. */
205 	struct port_template *tmp; /**< Temporary linking. */
206 	uint32_t id; /**< Template ID. */
207 	union {
208 		struct rte_flow_pattern_template *pattern_template;
209 		struct rte_flow_actions_template *actions_template;
210 	} template; /**< PMD opaque template object */
211 };
212 
213 /** Descriptor for a flow table. */
214 struct port_table {
215 	struct port_table *next; /**< Next table in list. */
216 	struct port_table *tmp; /**< Temporary linking. */
217 	uint32_t id; /**< Table ID. */
218 	uint32_t nb_pattern_templates; /**< Number of pattern templates. */
219 	uint32_t nb_actions_templates; /**< Number of actions templates. */
220 	struct rte_flow_attr flow_attr; /**< Flow attributes. */
221 	struct rte_flow_template_table *table; /**< PMD opaque template object */
222 };
223 
224 /** Descriptor for a single flow. */
225 struct port_flow {
226 	struct port_flow *next; /**< Next flow in list. */
227 	struct port_flow *tmp; /**< Temporary linking. */
228 	uint64_t id; /**< Flow rule ID. */
229 	uint64_t user_id; /**< User rule ID. */
230 	struct port_table *table; /**< Flow table. */
231 	struct rte_flow *flow; /**< Opaque flow object returned by PMD. */
232 	struct rte_flow_conv_rule rule; /**< Saved flow rule description. */
233 	enum age_action_context_type age_type; /**< Age action context type. */
234 	uint8_t data[]; /**< Storage for flow rule description */
235 };
236 
237 /* Descriptor for indirect action */
238 struct port_indirect_action {
239 	struct port_indirect_action *next; /**< Next flow in list. */
240 	uint32_t id; /**< Indirect action ID. */
241 	enum rte_flow_action_type type; /**< Action type. */
242 	union {
243 		struct rte_flow_action_handle *handle;
244 		/**< Indirect action handle. */
245 		struct rte_flow_action_list_handle *list_handle;
246 		/**< Indirect action list handle*/
247 	};
248 	enum age_action_context_type age_type; /**< Age action context type. */
249 };
250 
251 /* Descriptor for action query data. */
252 union port_action_query {
253 	struct rte_flow_query_count count;
254 	struct rte_flow_query_age age;
255 	struct rte_flow_action_conntrack ct;
256 	struct rte_flow_query_quota quota;
257 };
258 
259 /* Descriptor for queue job. */
260 struct queue_job {
261 	uint32_t type; /**< Job type. */
262 	union {
263 		struct port_flow *pf;
264 		struct port_indirect_action *pia;
265 	};
266 	union port_action_query query;
267 };
268 
269 struct port_flow_tunnel {
270 	LIST_ENTRY(port_flow_tunnel) chain;
271 	struct rte_flow_action *pmd_actions;
272 	struct rte_flow_item   *pmd_items;
273 	uint32_t id;
274 	uint32_t num_pmd_actions;
275 	uint32_t num_pmd_items;
276 	struct rte_flow_tunnel tunnel;
277 	struct rte_flow_action *actions;
278 	struct rte_flow_item *items;
279 };
280 
281 struct tunnel_ops {
282 	uint32_t id;
283 	char type[16];
284 	uint32_t enabled:1;
285 	uint32_t actions:1;
286 	uint32_t items:1;
287 };
288 
289 /** Information for an extended statistics to show. */
290 struct xstat_display_info {
291 	/** Supported xstats IDs in the order of xstats_display */
292 	uint64_t *ids_supp;
293 	size_t   ids_supp_sz;
294 	uint64_t *prev_values;
295 	uint64_t *curr_values;
296 	uint64_t prev_ns;
297 	bool	 allocated;
298 };
299 
300 /** RX queue configuration and state. */
301 struct port_rxqueue {
302 	struct rte_eth_rxconf conf;
303 	uint8_t state; /**< RTE_ETH_QUEUE_STATE_* value. */
304 };
305 
306 /** TX queue configuration and state. */
307 struct port_txqueue {
308 	struct rte_eth_txconf conf;
309 	uint8_t state; /**< RTE_ETH_QUEUE_STATE_* value. */
310 };
311 
312 /**
313  * The data structure associated with each port.
314  */
315 struct rte_port {
316 	struct rte_eth_dev_info dev_info;   /**< Device info + driver name */
317 	struct rte_eth_conf     dev_conf;   /**< Port configuration. */
318 	struct rte_ether_addr       eth_addr;   /**< Port ethernet address */
319 	struct rte_eth_stats    stats;      /**< Last port statistics */
320 	unsigned int            socket_id;  /**< For NUMA support */
321 	uint16_t		parse_tunnel:1; /**< Parse internal headers */
322 	uint16_t                tso_segsz;  /**< Segmentation offload MSS for non-tunneled packets. */
323 	uint16_t                tunnel_tso_segsz; /**< Segmentation offload MSS for tunneled pkts. */
324 	uint16_t                tx_vlan_id;/**< The tag ID */
325 	uint16_t                tx_vlan_id_outer;/**< The outer tag ID */
326 	volatile uint16_t        port_status;    /**< port started or not */
327 	uint8_t                 need_setup;     /**< port just attached */
328 	uint8_t                 need_reconfig;  /**< need reconfiguring port or not */
329 	uint8_t                 need_reconfig_queues; /**< need reconfiguring queues or not */
330 	uint8_t                 rss_flag;   /**< enable rss or not */
331 	uint8_t                 dcb_flag;   /**< enable dcb */
332 	uint16_t                nb_rx_desc[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue rx desc number */
333 	uint16_t                nb_tx_desc[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue tx desc number */
334 	struct port_rxqueue     rxq[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue Rx config and state */
335 	struct port_txqueue     txq[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue Tx config and state */
336 	struct rte_ether_addr   *mc_addr_pool; /**< pool of multicast addrs */
337 	uint32_t                mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
338 	queueid_t               queue_nb; /**< nb. of queues for flow rules */
339 	uint32_t                queue_sz; /**< size of a queue for flow rules */
340 	uint8_t                 slave_flag : 1, /**< bonding slave port */
341 				bond_flag : 1, /**< port is bond device */
342 				fwd_mac_swap : 1, /**< swap packet MAC before forward */
343 				update_conf : 1; /**< need to update bonding device configuration */
344 	struct port_template    *pattern_templ_list; /**< Pattern templates. */
345 	struct port_template    *actions_templ_list; /**< Actions templates. */
346 	struct port_table       *table_list; /**< Flow tables. */
347 	struct port_flow        *flow_list; /**< Associated flows. */
348 	struct port_indirect_action *actions_list;
349 	/**< Associated indirect actions. */
350 	LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
351 	const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
352 	const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
353 	/**< metadata value to insert in Tx packets. */
354 	uint32_t		tx_metadata;
355 	const struct rte_eth_rxtx_callback *tx_set_md_cb[RTE_MAX_QUEUES_PER_PORT+1];
356 	/**< dynamic flags. */
357 	uint64_t		mbuf_dynf;
358 	const struct rte_eth_rxtx_callback *tx_set_dynf_cb[RTE_MAX_QUEUES_PER_PORT+1];
359 	struct xstat_display_info xstats_info;
360 };
361 
362 /**
363  * The data structure associated with each forwarding logical core.
364  * The logical cores are internally numbered by a core index from 0 to
365  * the maximum number of logical cores - 1.
366  * The system CPU identifier of all logical cores are setup in a global
367  * CPU id. configuration table.
368  */
369 struct fwd_lcore {
370 #ifdef RTE_LIB_GSO
371 	struct rte_gso_ctx gso_ctx;     /**< GSO context */
372 #endif
373 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
374 #ifdef RTE_LIB_GRO
375 	void *gro_ctx;		/**< GRO context */
376 #endif
377 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
378 	streamid_t stream_nb;    /**< number of streams in "fwd_streams" */
379 	lcoreid_t  cpuid_idx;    /**< index of logical core in CPU id table */
380 	volatile char stopped;   /**< stop forwarding when set */
381 	uint64_t total_cycles;   /**< used with --record-core-cycles */
382 };
383 
384 /*
385  * Forwarding mode operations:
386  *   - IO forwarding mode (default mode)
387  *     Forwards packets unchanged.
388  *
389  *   - MAC forwarding mode
390  *     Set the source and the destination Ethernet addresses of packets
391  *     before forwarding them.
392  *
393  *   - IEEE1588 forwarding mode
394  *     Check that received IEEE1588 Precise Time Protocol (PTP) packets are
395  *     filtered and timestamped by the hardware.
396  *     Forwards packets unchanged on the same port.
397  *     Check that sent IEEE1588 PTP packets are timestamped by the hardware.
398  */
399 typedef int (*port_fwd_begin_t)(portid_t pi);
400 typedef void (*port_fwd_end_t)(portid_t pi);
401 typedef void (*stream_init_t)(struct fwd_stream *fs);
402 typedef bool (*packet_fwd_t)(struct fwd_stream *fs);
403 
404 struct fwd_engine {
405 	const char       *fwd_mode_name; /**< Forwarding mode name. */
406 	port_fwd_begin_t port_fwd_begin; /**< NULL if nothing special to do. */
407 	port_fwd_end_t   port_fwd_end;   /**< NULL if nothing special to do. */
408 	stream_init_t    stream_init;    /**< NULL if nothing special to do. */
409 	packet_fwd_t     packet_fwd;     /**< Mandatory. */
410 	const char       *status;        /**< NULL if nothing to display. */
411 };
412 
413 void common_fwd_stream_init(struct fwd_stream *fs);
414 
415 #define FLEX_ITEM_MAX_SAMPLES_NUM 16
416 #define FLEX_ITEM_MAX_LINKS_NUM 16
417 #define FLEX_MAX_FLOW_PATTERN_LENGTH 64
418 #define FLEX_MAX_PARSERS_NUM 8
419 #define FLEX_MAX_PATTERNS_NUM 64
420 #define FLEX_PARSER_ERR ((struct flex_item *)-1)
421 
422 struct flex_item {
423 	struct rte_flow_item_flex_conf flex_conf;
424 	struct rte_flow_item_flex_handle *flex_handle;
425 	uint32_t flex_id;
426 };
427 
428 struct flex_pattern {
429 	struct rte_flow_item_flex spec, mask;
430 	uint8_t spec_pattern[FLEX_MAX_FLOW_PATTERN_LENGTH];
431 	uint8_t mask_pattern[FLEX_MAX_FLOW_PATTERN_LENGTH];
432 };
433 extern struct flex_item *flex_items[RTE_MAX_ETHPORTS][FLEX_MAX_PARSERS_NUM];
434 extern struct flex_pattern flex_patterns[FLEX_MAX_PATTERNS_NUM];
435 
436 #define BURST_TX_WAIT_US 1
437 #define BURST_TX_RETRIES 64
438 
439 extern uint32_t burst_tx_delay_time;
440 extern uint32_t burst_tx_retry_num;
441 
442 extern struct fwd_engine io_fwd_engine;
443 extern struct fwd_engine mac_fwd_engine;
444 extern struct fwd_engine mac_swap_engine;
445 extern struct fwd_engine flow_gen_engine;
446 extern struct fwd_engine rx_only_engine;
447 extern struct fwd_engine tx_only_engine;
448 extern struct fwd_engine csum_fwd_engine;
449 extern struct fwd_engine icmp_echo_engine;
450 extern struct fwd_engine noisy_vnf_engine;
451 extern struct fwd_engine five_tuple_swap_fwd_engine;
452 #ifdef RTE_LIBRTE_IEEE1588
453 extern struct fwd_engine ieee1588_fwd_engine;
454 #endif
455 extern struct fwd_engine shared_rxq_engine;
456 
457 extern struct fwd_engine * fwd_engines[]; /**< NULL terminated array. */
458 extern cmdline_parse_inst_t cmd_set_raw;
459 extern cmdline_parse_inst_t cmd_show_set_raw;
460 extern cmdline_parse_inst_t cmd_show_set_raw_all;
461 extern cmdline_parse_inst_t cmd_set_flex_is_pattern;
462 extern cmdline_parse_inst_t cmd_set_flex_spec_pattern;
463 
464 extern uint16_t mempool_flags;
465 
466 /**
467  * Forwarding Configuration
468  *
469  */
470 struct fwd_config {
471 	struct fwd_engine *fwd_eng; /**< Packet forwarding mode. */
472 	streamid_t nb_fwd_streams;  /**< Nb. of forward streams to process. */
473 	lcoreid_t  nb_fwd_lcores;   /**< Nb. of logical cores to launch. */
474 	portid_t   nb_fwd_ports;    /**< Nb. of ports involved. */
475 };
476 
477 /**
478  * DCB mode enable
479  */
480 enum dcb_mode_enable
481 {
482 	DCB_VT_ENABLED,
483 	DCB_ENABLED
484 };
485 
486 extern uint8_t xstats_hide_zero; /**< Hide zero values for xstats display */
487 
488 /* globals used for configuration */
489 extern uint8_t record_core_cycles; /**< Enables measurement of CPU cycles */
490 extern uint8_t record_burst_stats; /**< Enables display of RX and TX bursts */
491 extern uint16_t verbose_level; /**< Drives messages being displayed, if any. */
492 extern int testpmd_logtype; /**< Log type for testpmd logs */
493 extern uint8_t  interactive;
494 extern uint8_t  auto_start;
495 extern uint8_t  tx_first;
496 extern char cmdline_filename[PATH_MAX]; /**< offline commands file */
497 extern uint8_t  numa_support; /**< set by "--numa" parameter */
498 extern uint16_t port_topology; /**< set by "--port-topology" parameter */
499 extern uint8_t no_flush_rx; /**<set by "--no-flush-rx" parameter */
500 extern uint8_t flow_isolate_all; /**< set by "--flow-isolate-all */
501 extern uint8_t no_flow_flush; /**< set by "--disable-flow-flush" parameter */
502 extern uint8_t  mp_alloc_type;
503 /**< set by "--mp-anon" or "--mp-alloc" parameter */
504 extern uint32_t eth_link_speed;
505 extern uint8_t no_link_check; /**<set by "--disable-link-check" parameter */
506 extern uint8_t no_device_start; /**<set by "--disable-device-start" parameter */
507 extern volatile int test_done; /* stop packet forwarding when set to 1. */
508 extern uint8_t lsc_interrupt; /**< disabled by "--no-lsc-interrupt" parameter */
509 extern uint8_t rmv_interrupt; /**< disabled by "--no-rmv-interrupt" parameter */
510 extern uint32_t event_print_mask;
511 /**< set by "--print-event xxxx" and "--mask-event xxxx parameters */
512 extern bool setup_on_probe_event; /**< disabled by port setup-on iterator */
513 extern uint8_t hot_plug; /**< enable by "--hot-plug" parameter */
514 extern int do_mlockall; /**< set by "--mlockall" or "--no-mlockall" parameter */
515 extern uint8_t clear_ptypes; /**< disabled by set ptype cmd */
516 
517 /*
518  * Store specified sockets on which memory pool to be used by ports
519  * is allocated.
520  */
521 extern uint8_t port_numa[RTE_MAX_ETHPORTS];
522 
523 /*
524  * Store specified sockets on which RX ring to be used by ports
525  * is allocated.
526  */
527 extern uint8_t rxring_numa[RTE_MAX_ETHPORTS];
528 
529 /*
530  * Store specified sockets on which TX ring to be used by ports
531  * is allocated.
532  */
533 extern uint8_t txring_numa[RTE_MAX_ETHPORTS];
534 
535 extern uint8_t socket_num;
536 
537 /*
538  * Configuration of logical cores:
539  * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
540  */
541 extern lcoreid_t nb_lcores; /**< Number of logical cores probed at init time. */
542 extern lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
543 extern lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
544 extern unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE];
545 extern unsigned int num_sockets;
546 extern unsigned int socket_ids[RTE_MAX_NUMA_NODES];
547 
548 /*
549  * Configuration of Ethernet ports:
550  * nb_fwd_ports <= nb_cfg_ports <= nb_ports
551  */
552 extern portid_t nb_ports; /**< Number of ethernet ports probed at init time. */
553 extern portid_t nb_cfg_ports; /**< Number of configured ports. */
554 extern portid_t nb_fwd_ports; /**< Number of forwarding ports. */
555 extern portid_t fwd_ports_ids[RTE_MAX_ETHPORTS];
556 extern struct rte_port *ports;
557 
558 extern struct rte_eth_rxmode rx_mode;
559 extern struct rte_eth_txmode tx_mode;
560 
561 extern uint64_t rss_hf;
562 
563 extern queueid_t nb_hairpinq;
564 extern queueid_t nb_rxq;
565 extern queueid_t nb_txq;
566 
567 extern uint16_t nb_rxd;
568 extern uint16_t nb_txd;
569 
570 extern int16_t rx_free_thresh;
571 extern int8_t rx_drop_en;
572 extern int16_t tx_free_thresh;
573 extern int16_t tx_rs_thresh;
574 
575 extern enum noisy_fwd_mode noisy_fwd_mode;
576 extern const char * const noisy_fwd_mode_desc[];
577 extern uint16_t noisy_tx_sw_bufsz;
578 extern uint16_t noisy_tx_sw_buf_flush_time;
579 extern uint64_t noisy_lkup_mem_sz;
580 extern uint64_t noisy_lkup_num_writes;
581 extern uint64_t noisy_lkup_num_reads;
582 extern uint64_t noisy_lkup_num_reads_writes;
583 
584 extern uint8_t dcb_config;
585 
586 extern uint32_t mbuf_data_size_n;
587 extern uint16_t mbuf_data_size[MAX_SEGS_BUFFER_SPLIT];
588 /**< Mbuf data space size. */
589 extern uint32_t param_total_num_mbufs;
590 
591 extern uint16_t stats_period;
592 
593 extern struct rte_eth_xstat_name *xstats_display;
594 extern unsigned int xstats_display_num;
595 
596 extern uint32_t hairpin_mode;
597 
598 #ifdef RTE_LIB_LATENCYSTATS
599 extern uint8_t latencystats_enabled;
600 extern lcoreid_t latencystats_lcore_id;
601 #endif
602 
603 #ifdef RTE_LIB_BITRATESTATS
604 extern lcoreid_t bitrate_lcore_id;
605 extern uint8_t bitrate_enabled;
606 #endif
607 
608 extern uint32_t max_rx_pkt_len;
609 
610 /*
611  * Configuration of packet segments used to scatter received packets
612  * if some of split features is configured.
613  */
614 extern uint32_t rx_pkt_hdr_protos[MAX_SEGS_BUFFER_SPLIT];
615 extern uint16_t rx_pkt_seg_lengths[MAX_SEGS_BUFFER_SPLIT];
616 extern uint8_t  rx_pkt_nb_segs; /**< Number of segments to split */
617 extern uint16_t rx_pkt_seg_offsets[MAX_SEGS_BUFFER_SPLIT];
618 extern uint8_t  rx_pkt_nb_offs; /**< Number of specified offsets */
619 
620 extern uint8_t multi_rx_mempool; /**< Enables multi-rx-mempool feature. */
621 
622 /*
623  * Configuration of packet segments used by the "txonly" processing engine.
624  */
625 #define TXONLY_DEF_PACKET_LEN 64
626 extern uint16_t tx_pkt_length; /**< Length of TXONLY packet */
627 extern uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT]; /**< Seg. lengths */
628 extern uint8_t  tx_pkt_nb_segs; /**< Number of segments in TX packets */
629 extern uint32_t tx_pkt_times_intra;
630 extern uint32_t tx_pkt_times_inter;
631 
632 enum tx_pkt_split {
633 	TX_PKT_SPLIT_OFF,
634 	TX_PKT_SPLIT_ON,
635 	TX_PKT_SPLIT_RND,
636 };
637 
638 extern enum tx_pkt_split tx_pkt_split;
639 
640 extern uint8_t txonly_multi_flow;
641 
642 extern uint32_t rxq_share;
643 
644 extern uint16_t nb_pkt_per_burst;
645 extern uint16_t nb_pkt_flowgen_clones;
646 extern int nb_flows_flowgen;
647 extern uint16_t mb_mempool_cache;
648 extern int8_t rx_pthresh;
649 extern int8_t rx_hthresh;
650 extern int8_t rx_wthresh;
651 extern int8_t tx_pthresh;
652 extern int8_t tx_hthresh;
653 extern int8_t tx_wthresh;
654 
655 extern uint16_t tx_udp_src_port;
656 extern uint16_t tx_udp_dst_port;
657 
658 extern uint32_t tx_ip_src_addr;
659 extern uint32_t tx_ip_dst_addr;
660 
661 extern struct fwd_config cur_fwd_config;
662 extern struct fwd_engine *cur_fwd_eng;
663 extern uint32_t retry_enabled;
664 extern struct fwd_lcore  **fwd_lcores;
665 extern struct fwd_stream **fwd_streams;
666 
667 extern uint16_t vxlan_gpe_udp_port; /**< UDP port of tunnel VXLAN-GPE. */
668 extern uint16_t geneve_udp_port; /**< UDP port of tunnel GENEVE. */
669 
670 extern portid_t nb_peer_eth_addrs; /**< Number of peer ethernet addresses. */
671 extern struct rte_ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
672 
673 extern uint32_t burst_tx_delay_time; /**< Burst tx delay time(us) for mac-retry. */
674 extern uint32_t burst_tx_retry_num;  /**< Burst tx retry number for mac-retry. */
675 
676 #ifdef RTE_LIB_GRO
677 #define GRO_DEFAULT_ITEM_NUM_PER_FLOW 32
678 #define GRO_DEFAULT_FLOW_NUM (RTE_GRO_MAX_BURST_ITEM_NUM / \
679 		GRO_DEFAULT_ITEM_NUM_PER_FLOW)
680 
681 #define GRO_DEFAULT_FLUSH_CYCLES 1
682 #define GRO_MAX_FLUSH_CYCLES 4
683 
684 struct gro_status {
685 	struct rte_gro_param param;
686 	uint8_t enable;
687 };
688 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
689 extern uint8_t gro_flush_cycles;
690 #endif /* RTE_LIB_GRO */
691 
692 #ifdef RTE_LIB_GSO
693 #define GSO_MAX_PKT_BURST 2048
694 struct gso_status {
695 	uint8_t enable;
696 };
697 extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
698 extern uint16_t gso_max_segment_size;
699 #endif /* RTE_LIB_GSO */
700 
701 /* VXLAN encap/decap parameters. */
702 struct vxlan_encap_conf {
703 	uint32_t select_ipv4:1;
704 	uint32_t select_vlan:1;
705 	uint32_t select_tos_ttl:1;
706 	uint8_t vni[3];
707 	rte_be16_t udp_src;
708 	rte_be16_t udp_dst;
709 	rte_be32_t ipv4_src;
710 	rte_be32_t ipv4_dst;
711 	uint8_t ipv6_src[16];
712 	uint8_t ipv6_dst[16];
713 	rte_be16_t vlan_tci;
714 	uint8_t ip_tos;
715 	uint8_t ip_ttl;
716 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
717 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
718 };
719 
720 extern struct vxlan_encap_conf vxlan_encap_conf;
721 
722 /* NVGRE encap/decap parameters. */
723 struct nvgre_encap_conf {
724 	uint32_t select_ipv4:1;
725 	uint32_t select_vlan:1;
726 	uint8_t tni[3];
727 	rte_be32_t ipv4_src;
728 	rte_be32_t ipv4_dst;
729 	uint8_t ipv6_src[16];
730 	uint8_t ipv6_dst[16];
731 	rte_be16_t vlan_tci;
732 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
733 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
734 };
735 
736 extern struct nvgre_encap_conf nvgre_encap_conf;
737 
738 /* L2 encap parameters. */
739 struct l2_encap_conf {
740 	uint32_t select_ipv4:1;
741 	uint32_t select_vlan:1;
742 	rte_be16_t vlan_tci;
743 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
744 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
745 };
746 extern struct l2_encap_conf l2_encap_conf;
747 
748 /* L2 decap parameters. */
749 struct l2_decap_conf {
750 	uint32_t select_vlan:1;
751 };
752 extern struct l2_decap_conf l2_decap_conf;
753 
754 /* MPLSoGRE encap parameters. */
755 struct mplsogre_encap_conf {
756 	uint32_t select_ipv4:1;
757 	uint32_t select_vlan:1;
758 	uint8_t label[3];
759 	rte_be32_t ipv4_src;
760 	rte_be32_t ipv4_dst;
761 	uint8_t ipv6_src[16];
762 	uint8_t ipv6_dst[16];
763 	rte_be16_t vlan_tci;
764 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
765 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
766 };
767 extern struct mplsogre_encap_conf mplsogre_encap_conf;
768 
769 /* MPLSoGRE decap parameters. */
770 struct mplsogre_decap_conf {
771 	uint32_t select_ipv4:1;
772 	uint32_t select_vlan:1;
773 };
774 extern struct mplsogre_decap_conf mplsogre_decap_conf;
775 
776 /* MPLSoUDP encap parameters. */
777 struct mplsoudp_encap_conf {
778 	uint32_t select_ipv4:1;
779 	uint32_t select_vlan:1;
780 	uint8_t label[3];
781 	rte_be16_t udp_src;
782 	rte_be16_t udp_dst;
783 	rte_be32_t ipv4_src;
784 	rte_be32_t ipv4_dst;
785 	uint8_t ipv6_src[16];
786 	uint8_t ipv6_dst[16];
787 	rte_be16_t vlan_tci;
788 	uint8_t eth_src[RTE_ETHER_ADDR_LEN];
789 	uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
790 };
791 extern struct mplsoudp_encap_conf mplsoudp_encap_conf;
792 
793 /* MPLSoUDP decap parameters. */
794 struct mplsoudp_decap_conf {
795 	uint32_t select_ipv4:1;
796 	uint32_t select_vlan:1;
797 };
798 extern struct mplsoudp_decap_conf mplsoudp_decap_conf;
799 
800 extern enum rte_eth_rx_mq_mode rx_mq_mode;
801 
802 extern struct rte_flow_action_conntrack conntrack_context;
803 
804 extern int proc_id;
805 extern unsigned int num_procs;
806 
807 static inline bool
808 is_proc_primary(void)
809 {
810 	return rte_eal_process_type() == RTE_PROC_PRIMARY;
811 }
812 
813 static inline struct fwd_lcore *
814 lcore_to_fwd_lcore(uint16_t lcore_id)
815 {
816 	unsigned int i;
817 
818 	for (i = 0; i < cur_fwd_config.nb_fwd_lcores; ++i) {
819 		if (fwd_lcores_cpuids[i] == lcore_id)
820 			return fwd_lcores[i];
821 	}
822 
823 	return NULL;
824 }
825 
826 static inline struct fwd_lcore *
827 current_fwd_lcore(void)
828 {
829 	struct fwd_lcore *fc = lcore_to_fwd_lcore(rte_lcore_id());
830 
831 	if (fc == NULL)
832 		rte_panic("lcore_id of current thread not found in fwd_lcores_cpuids\n");
833 
834 	return fc;
835 }
836 
837 void
838 parse_fwd_portlist(const char *port);
839 
840 /* Mbuf Pools */
841 static inline void
842 mbuf_poolname_build(unsigned int sock_id, char *mp_name,
843 		    int name_size, uint16_t idx)
844 {
845 	if (!idx)
846 		snprintf(mp_name, name_size,
847 			 MBUF_POOL_NAME_PFX "_%u", sock_id);
848 	else
849 		snprintf(mp_name, name_size,
850 			 MBUF_POOL_NAME_PFX "_%hu_%hu", (uint16_t)sock_id, idx);
851 }
852 
853 static inline struct rte_mempool *
854 mbuf_pool_find(unsigned int sock_id, uint16_t idx)
855 {
856 	char pool_name[RTE_MEMPOOL_NAMESIZE];
857 
858 	mbuf_poolname_build(sock_id, pool_name, sizeof(pool_name), idx);
859 	return rte_mempool_lookup((const char *)pool_name);
860 }
861 
862 static inline uint16_t
863 common_fwd_stream_receive(struct fwd_stream *fs, struct rte_mbuf **burst,
864 	unsigned int nb_pkts)
865 {
866 	uint16_t nb_rx;
867 
868 	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, burst, nb_pkts);
869 	if (record_burst_stats)
870 		fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
871 	fs->rx_packets += nb_rx;
872 	return nb_rx;
873 }
874 
875 static inline uint16_t
876 common_fwd_stream_transmit(struct fwd_stream *fs, struct rte_mbuf **burst,
877 	unsigned int nb_pkts)
878 {
879 	uint16_t nb_tx;
880 	uint32_t retry;
881 
882 	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, burst, nb_pkts);
883 	/*
884 	 * Retry if necessary
885 	 */
886 	if (unlikely(nb_tx < nb_pkts) && fs->retry_enabled) {
887 		retry = 0;
888 		while (nb_tx < nb_pkts && retry++ < burst_tx_retry_num) {
889 			rte_delay_us(burst_tx_delay_time);
890 			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
891 				&burst[nb_tx], nb_pkts - nb_tx);
892 		}
893 	}
894 	fs->tx_packets += nb_tx;
895 	if (record_burst_stats)
896 		fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
897 	if (unlikely(nb_tx < nb_pkts)) {
898 		fs->fwd_dropped += (nb_pkts - nb_tx);
899 		rte_pktmbuf_free_bulk(&burst[nb_tx], nb_pkts - nb_tx);
900 	}
901 
902 	return nb_tx;
903 }
904 
905 /* Prototypes */
906 unsigned int parse_item_list(const char *str, const char *item_name,
907 			unsigned int max_items,
908 			unsigned int *parsed_items, int check_unique_values);
909 unsigned int parse_hdrs_list(const char *str, const char *item_name,
910 			unsigned int max_item,
911 			unsigned int *parsed_items);
912 void launch_args_parse(int argc, char** argv);
913 void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
914 void cmdline_read_from_file(const char *filename);
915 int init_cmdline(void);
916 void prompt(void);
917 void prompt_exit(void);
918 void nic_stats_display(portid_t port_id);
919 void nic_stats_clear(portid_t port_id);
920 void nic_xstats_display(portid_t port_id);
921 void nic_xstats_clear(portid_t port_id);
922 void device_infos_display(const char *identifier);
923 void port_infos_display(portid_t port_id);
924 void port_summary_display(portid_t port_id);
925 void port_eeprom_display(portid_t port_id);
926 void port_module_eeprom_display(portid_t port_id);
927 void port_summary_header_display(void);
928 void rx_queue_infos_display(portid_t port_idi, uint16_t queue_id);
929 void tx_queue_infos_display(portid_t port_idi, uint16_t queue_id);
930 void fwd_lcores_config_display(void);
931 bool pkt_fwd_shared_rxq_check(void);
932 void pkt_fwd_config_display(struct fwd_config *cfg);
933 void rxtx_config_display(void);
934 void fwd_config_setup(void);
935 void set_def_fwd_config(void);
936 void reconfig(portid_t new_port_id, unsigned socket_id);
937 int init_fwd_streams(void);
938 void update_fwd_ports(portid_t new_pid);
939 
940 void set_fwd_eth_peer(portid_t port_id, char *peer_addr);
941 
942 void port_mtu_set(portid_t port_id, uint16_t mtu);
943 int port_action_handle_create(portid_t port_id, uint32_t id, bool indirect_list,
944 			      const struct rte_flow_indir_action_conf *conf,
945 			      const struct rte_flow_action *action);
946 int port_action_handle_destroy(portid_t port_id,
947 			       uint32_t n, const uint32_t *action);
948 int port_action_handle_flush(portid_t port_id);
949 struct rte_flow_action_handle *port_action_handle_get_by_id(portid_t port_id,
950 							    uint32_t id);
951 int port_action_handle_update(portid_t port_id, uint32_t id,
952 			      const struct rte_flow_action *action);
953 void
954 port_action_handle_query_update(portid_t port_id, uint32_t id,
955 				enum rte_flow_query_update_mode qu_mode,
956 				const struct rte_flow_action *action);
957 int port_flow_get_info(portid_t port_id);
958 int port_flow_configure(portid_t port_id,
959 			const struct rte_flow_port_attr *port_attr,
960 			uint16_t nb_queue,
961 			const struct rte_flow_queue_attr *queue_attr);
962 int port_flow_pattern_template_create(portid_t port_id, uint32_t id,
963 				      const struct rte_flow_pattern_template_attr *attr,
964 				      const struct rte_flow_item *pattern);
965 int port_flow_pattern_template_destroy(portid_t port_id, uint32_t n,
966 				       const uint32_t *template);
967 int port_flow_pattern_template_flush(portid_t port_id);
968 int port_flow_actions_template_create(portid_t port_id, uint32_t id,
969 				      const struct rte_flow_actions_template_attr *attr,
970 				      const struct rte_flow_action *actions,
971 				      const struct rte_flow_action *masks);
972 int port_flow_actions_template_destroy(portid_t port_id, uint32_t n,
973 				       const uint32_t *template);
974 int port_flow_actions_template_flush(portid_t port_id);
975 int port_flow_template_table_create(portid_t port_id, uint32_t id,
976 		   const struct rte_flow_template_table_attr *table_attr,
977 		   uint32_t nb_pattern_templates, uint32_t *pattern_templates,
978 		   uint32_t nb_actions_templates, uint32_t *actions_templates);
979 int port_flow_template_table_destroy(portid_t port_id,
980 			    uint32_t n, const uint32_t *table);
981 int port_flow_template_table_flush(portid_t port_id);
982 int port_queue_flow_create(portid_t port_id, queueid_t queue_id,
983 			   bool postpone, uint32_t table_id, uint32_t rule_idx,
984 			   uint32_t pattern_idx, uint32_t actions_idx,
985 			   const struct rte_flow_item *pattern,
986 			   const struct rte_flow_action *actions);
987 int port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
988 			    bool postpone, uint32_t n, const uint64_t *rule);
989 int port_queue_flow_update(portid_t port_id, queueid_t queue_id,
990 			   bool postpone, uint32_t rule_idx, uint32_t actions_idx,
991 			   const struct rte_flow_action *actions);
992 int port_queue_action_handle_create(portid_t port_id, uint32_t queue_id,
993 			bool postpone, uint32_t id,
994 			const struct rte_flow_indir_action_conf *conf,
995 			const struct rte_flow_action *action);
996 int port_queue_action_handle_destroy(portid_t port_id,
997 				     uint32_t queue_id, bool postpone,
998 				     uint32_t n, const uint32_t *action);
999 int port_queue_action_handle_update(portid_t port_id, uint32_t queue_id,
1000 				    bool postpone, uint32_t id,
1001 				    const struct rte_flow_action *action);
1002 int port_queue_action_handle_query(portid_t port_id, uint32_t queue_id,
1003 				   bool postpone, uint32_t id);
1004 void
1005 port_queue_action_handle_query_update(portid_t port_id,
1006 				      uint32_t queue_id, bool postpone,
1007 				      uint32_t id,
1008 				      enum rte_flow_query_update_mode qu_mode,
1009 				      const struct rte_flow_action *action);
1010 int port_queue_flow_push(portid_t port_id, queueid_t queue_id);
1011 int port_queue_flow_pull(portid_t port_id, queueid_t queue_id);
1012 void port_queue_flow_aged(portid_t port_id, uint32_t queue_id, uint8_t destroy);
1013 int port_flow_validate(portid_t port_id,
1014 		       const struct rte_flow_attr *attr,
1015 		       const struct rte_flow_item *pattern,
1016 		       const struct rte_flow_action *actions,
1017 		       const struct tunnel_ops *tunnel_ops);
1018 int port_flow_create(portid_t port_id,
1019 		     const struct rte_flow_attr *attr,
1020 		     const struct rte_flow_item *pattern,
1021 		     const struct rte_flow_action *actions,
1022 		     const struct tunnel_ops *tunnel_ops,
1023 		     uintptr_t user_id);
1024 int port_action_handle_query(portid_t port_id, uint32_t id);
1025 void update_age_action_context(const struct rte_flow_action *actions,
1026 		     struct port_flow *pf);
1027 int mcast_addr_pool_destroy(portid_t port_id);
1028 int port_flow_destroy(portid_t port_id, uint32_t n, const uint64_t *rule,
1029 		      bool is_user_id);
1030 int port_flow_flush(portid_t port_id);
1031 int port_flow_dump(portid_t port_id, bool dump_all,
1032 			uint64_t rule, const char *file_name,
1033 			bool is_user_id);
1034 int port_flow_query(portid_t port_id, uint64_t rule,
1035 		    const struct rte_flow_action *action, bool is_user_id);
1036 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
1037 void port_flow_aged(portid_t port_id, uint8_t destroy);
1038 const char *port_flow_tunnel_type(struct rte_flow_tunnel *tunnel);
1039 struct port_flow_tunnel *
1040 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun);
1041 void port_flow_tunnel_list(portid_t port_id);
1042 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
1043 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
1044 int port_flow_isolate(portid_t port_id, int set);
1045 int port_meter_policy_add(portid_t port_id, uint32_t policy_id,
1046 		const struct rte_flow_action *actions);
1047 struct rte_flow_meter_profile *port_meter_profile_get_by_id(portid_t port_id,
1048 							    uint32_t id);
1049 struct rte_flow_meter_policy *port_meter_policy_get_by_id(portid_t port_id,
1050 							  uint32_t id);
1051 
1052 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
1053 void tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id);
1054 
1055 int set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc);
1056 int set_fwd_lcores_mask(uint64_t lcoremask);
1057 void set_fwd_lcores_number(uint16_t nb_lc);
1058 
1059 void set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt);
1060 void set_fwd_ports_mask(uint64_t portmask);
1061 void set_fwd_ports_number(uint16_t nb_pt);
1062 int port_is_forwarding(portid_t port_id);
1063 
1064 void rx_vlan_strip_set(portid_t port_id, int on);
1065 void rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on);
1066 
1067 void rx_vlan_filter_set(portid_t port_id, int on);
1068 void rx_vlan_all_filter_set(portid_t port_id, int on);
1069 void rx_vlan_qinq_strip_set(portid_t port_id, int on);
1070 int rx_vft_set(portid_t port_id, uint16_t vlan_id, int on);
1071 void vlan_extend_set(portid_t port_id, int on);
1072 void vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type,
1073 		   uint16_t tp_id);
1074 void tx_vlan_set(portid_t port_id, uint16_t vlan_id);
1075 void tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer);
1076 void tx_vlan_reset(portid_t port_id);
1077 void tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on);
1078 
1079 void set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value);
1080 
1081 void set_xstats_hide_zero(uint8_t on_off);
1082 
1083 void set_record_core_cycles(uint8_t on_off);
1084 void set_record_burst_stats(uint8_t on_off);
1085 void set_verbose_level(uint16_t vb_level);
1086 void set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs);
1087 void set_rx_pkt_hdrs(unsigned int *seg_protos, unsigned int nb_segs);
1088 void show_rx_pkt_hdrs(void);
1089 void show_rx_pkt_segments(void);
1090 void set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs);
1091 void show_rx_pkt_offsets(void);
1092 void set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs);
1093 void show_tx_pkt_segments(void);
1094 void set_tx_pkt_times(unsigned int *tx_times);
1095 void show_tx_pkt_times(void);
1096 void set_tx_pkt_split(const char *name);
1097 int parse_fec_mode(const char *name, uint32_t *fec_capa);
1098 void show_fec_capability(uint32_t num, struct rte_eth_fec_capa *speed_fec_capa);
1099 void set_nb_pkt_per_burst(uint16_t pkt_burst);
1100 char *list_pkt_forwarding_modes(void);
1101 char *list_pkt_forwarding_retry_modes(void);
1102 void set_pkt_forwarding_mode(const char *fwd_mode);
1103 void start_packet_forwarding(int with_tx_first);
1104 void fwd_stats_display(void);
1105 void fwd_stats_reset(void);
1106 void stop_packet_forwarding(void);
1107 void dev_set_link_up(portid_t pid);
1108 void dev_set_link_down(portid_t pid);
1109 void init_port_config(void);
1110 void set_port_slave_flag(portid_t slave_pid);
1111 void clear_port_slave_flag(portid_t slave_pid);
1112 uint8_t port_is_bonding_slave(portid_t slave_pid);
1113 
1114 int init_port_dcb_config(portid_t pid, enum dcb_mode_enable dcb_mode,
1115 		     enum rte_eth_nb_tcs num_tcs,
1116 		     uint8_t pfc_en);
1117 int start_port(portid_t pid);
1118 void stop_port(portid_t pid);
1119 void close_port(portid_t pid);
1120 void reset_port(portid_t pid);
1121 void attach_port(char *identifier);
1122 void detach_devargs(char *identifier);
1123 void detach_port_device(portid_t port_id);
1124 int all_ports_stopped(void);
1125 int port_is_stopped(portid_t port_id);
1126 int port_is_started(portid_t port_id);
1127 void pmd_test_exit(void);
1128 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
1129 void fdir_get_infos(portid_t port_id);
1130 #endif
1131 void port_rss_reta_info(portid_t port_id,
1132 			struct rte_eth_rss_reta_entry64 *reta_conf,
1133 			uint16_t nb_entries);
1134 
1135 void set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on);
1136 
1137 int
1138 rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1139 	       uint16_t nb_rx_desc, unsigned int socket_id,
1140 	       struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp);
1141 
1142 int set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint32_t rate);
1143 int set_vf_rate_limit(portid_t port_id, uint16_t vf, uint32_t rate,
1144 				uint64_t q_msk);
1145 
1146 int set_rxq_avail_thresh(portid_t port_id, uint16_t queue_id,
1147 			 uint8_t avail_thresh);
1148 
1149 void port_rss_hash_conf_show(portid_t port_id, int show_rss_key);
1150 void port_rss_hash_key_update(portid_t port_id, char rss_type[],
1151 			      uint8_t *hash_key, uint8_t hash_key_len);
1152 int rx_queue_id_is_invalid(queueid_t rxq_id);
1153 int tx_queue_id_is_invalid(queueid_t txq_id);
1154 #ifdef RTE_LIB_GRO
1155 void setup_gro(const char *onoff, portid_t port_id);
1156 void setup_gro_flush_cycles(uint8_t cycles);
1157 void show_gro(portid_t port_id);
1158 #endif
1159 #ifdef RTE_LIB_GSO
1160 void setup_gso(const char *mode, portid_t port_id);
1161 #endif
1162 int eth_dev_info_get_print_err(uint16_t port_id,
1163 			struct rte_eth_dev_info *dev_info);
1164 int eth_dev_conf_get_print_err(uint16_t port_id,
1165 			struct rte_eth_conf *dev_conf);
1166 void eth_set_promisc_mode(uint16_t port_id, int enable);
1167 void eth_set_allmulticast_mode(uint16_t port, int enable);
1168 int eth_link_get_nowait_print_err(uint16_t port_id, struct rte_eth_link *link);
1169 int eth_macaddr_get_print_err(uint16_t port_id,
1170 			struct rte_ether_addr *mac_addr);
1171 
1172 /* Functions to display the set of MAC addresses added to a port*/
1173 void show_macs(portid_t port_id);
1174 void show_mcast_macs(portid_t port_id);
1175 
1176 /* Functions to manage the set of filtered Multicast MAC addresses */
1177 void mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr);
1178 void mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr);
1179 void port_dcb_info_display(portid_t port_id);
1180 
1181 uint8_t *open_file(const char *file_path, uint32_t *size);
1182 int save_file(const char *file_path, uint8_t *buf, uint32_t size);
1183 int close_file(uint8_t *buf);
1184 
1185 enum print_warning {
1186 	ENABLED_WARN = 0,
1187 	DISABLED_WARN
1188 };
1189 int port_id_is_invalid(portid_t port_id, enum print_warning warning);
1190 void print_valid_ports(void);
1191 int new_socket_id(unsigned int socket_id);
1192 
1193 queueid_t get_allowed_max_nb_rxq(portid_t *pid);
1194 int check_nb_rxq(queueid_t rxq);
1195 queueid_t get_allowed_max_nb_txq(portid_t *pid);
1196 int check_nb_txq(queueid_t txq);
1197 int check_nb_rxd(queueid_t rxd);
1198 int check_nb_txd(queueid_t txd);
1199 queueid_t get_allowed_max_nb_hairpinq(portid_t *pid);
1200 int check_nb_hairpinq(queueid_t hairpinq);
1201 
1202 uint16_t dump_rx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
1203 		      uint16_t nb_pkts, __rte_unused uint16_t max_pkts,
1204 		      __rte_unused void *user_param);
1205 
1206 uint16_t dump_tx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
1207 		      uint16_t nb_pkts, __rte_unused void *user_param);
1208 
1209 void add_rx_dump_callbacks(portid_t portid);
1210 void remove_rx_dump_callbacks(portid_t portid);
1211 void add_tx_dump_callbacks(portid_t portid);
1212 void remove_tx_dump_callbacks(portid_t portid);
1213 void configure_rxtx_dump_callbacks(uint16_t verbose);
1214 
1215 uint16_t tx_pkt_set_md(uint16_t port_id, __rte_unused uint16_t queue,
1216 		       struct rte_mbuf *pkts[], uint16_t nb_pkts,
1217 		       __rte_unused void *user_param);
1218 void add_tx_md_callback(portid_t portid);
1219 void remove_tx_md_callback(portid_t portid);
1220 
1221 uint16_t tx_pkt_set_dynf(uint16_t port_id, __rte_unused uint16_t queue,
1222 			 struct rte_mbuf *pkts[], uint16_t nb_pkts,
1223 			 __rte_unused void *user_param);
1224 void add_tx_dynf_callback(portid_t portid);
1225 void remove_tx_dynf_callback(portid_t portid);
1226 int update_mtu_from_frame_size(portid_t portid, uint32_t max_rx_pktlen);
1227 void flex_item_create(portid_t port_id, uint16_t flex_id, const char *filename);
1228 void flex_item_destroy(portid_t port_id, uint16_t flex_id);
1229 void port_flex_item_flush(portid_t port_id);
1230 
1231 extern int flow_parse(const char *src, void *result, unsigned int size,
1232 		      struct rte_flow_attr **attr,
1233 		      struct rte_flow_item **pattern,
1234 		      struct rte_flow_action **actions);
1235 
1236 uint64_t str_to_rsstypes(const char *str);
1237 const char *rsstypes_to_str(uint64_t rss_type);
1238 
1239 uint16_t str_to_flowtype(const char *string);
1240 const char *flowtype_to_str(uint16_t flow_type);
1241 
1242 /* For registering driver specific testpmd commands. */
1243 struct testpmd_driver_commands {
1244 	TAILQ_ENTRY(testpmd_driver_commands) next;
1245 	struct {
1246 		cmdline_parse_inst_t *ctx;
1247 		const char *help;
1248 	} commands[];
1249 };
1250 
1251 void testpmd_add_driver_commands(struct testpmd_driver_commands *c);
1252 #define TESTPMD_ADD_DRIVER_COMMANDS(c) \
1253 RTE_INIT(__##c) \
1254 { \
1255 	testpmd_add_driver_commands(&c); \
1256 }
1257 
1258 /*
1259  * Work-around of a compilation error with ICC on invocations of the
1260  * rte_be_to_cpu_16() function.
1261  */
1262 #ifdef __GCC__
1263 #define RTE_BE_TO_CPU_16(be_16_v)  rte_be_to_cpu_16((be_16_v))
1264 #define RTE_CPU_TO_BE_16(cpu_16_v) rte_cpu_to_be_16((cpu_16_v))
1265 #else
1266 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1267 #define RTE_BE_TO_CPU_16(be_16_v)  (be_16_v)
1268 #define RTE_CPU_TO_BE_16(cpu_16_v) (cpu_16_v)
1269 #else
1270 #define RTE_BE_TO_CPU_16(be_16_v) \
1271 	(uint16_t) ((((be_16_v) & 0xFF) << 8) | ((be_16_v) >> 8))
1272 #define RTE_CPU_TO_BE_16(cpu_16_v) \
1273 	(uint16_t) ((((cpu_16_v) & 0xFF) << 8) | ((cpu_16_v) >> 8))
1274 #endif
1275 #endif /* __GCC__ */
1276 
1277 #define TESTPMD_LOG(level, fmt, args...) \
1278 	rte_log(RTE_LOG_ ## level, testpmd_logtype, "testpmd: " fmt, ## args)
1279 
1280 #endif /* _TESTPMD_H_ */
1281