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