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