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