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