1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
11 #include <rte_bus_pci.h>
18 #include <rte_os_shim.h>
20 #include <sys/queue.h>
21 #ifdef RTE_HAS_JANSSON
25 #define RTE_PORT_ALL (~(portid_t)0x0)
27 #define RTE_TEST_RX_DESC_MAX 2048
28 #define RTE_TEST_TX_DESC_MAX 2048
30 #define RTE_PORT_STOPPED (uint16_t)0
31 #define RTE_PORT_STARTED (uint16_t)1
32 #define RTE_PORT_CLOSED (uint16_t)2
33 #define RTE_PORT_HANDLING (uint16_t)3
36 * It is used to allocate the memory for hash key.
37 * The hash key size is NIC dependent.
39 #define RSS_HASH_KEY_LENGTH 64
42 * Default size of the mbuf data buffer to receive standard 1518-byte
43 * Ethernet frames in a mono-segment memory buffer.
45 #define DEFAULT_MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE
46 /**< Default size of mbuf data buffer. */
49 * The maximum number of segments per packet is used when creating
50 * scattered transmit packets composed of a list of mbufs.
52 #define RTE_MAX_SEGS_PER_PKT 255 /**< nb_segs is a 8-bit unsigned char. */
55 * The maximum number of segments per packet is used to configure
56 * buffer split feature, also specifies the maximum amount of
57 * optional Rx pools to allocate mbufs to split.
59 #define MAX_SEGS_BUFFER_SPLIT 8 /**< nb_segs is a 8-bit unsigned char. */
61 /* The prefix of the mbuf pool names created by the application. */
62 #define MBUF_POOL_NAME_PFX "mb_pool"
64 #define MAX_PKT_BURST 512
65 #define DEF_PKT_BURST 32
67 #define DEF_MBUF_CACHE 250
69 #define RTE_CACHE_LINE_SIZE_ROUNDUP(size) \
70 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE))
72 #define NUMA_NO_CONFIG 0xFF
73 #define UMA_NO_CONFIG 0xFF
75 typedef uint8_t lcoreid_t;
76 typedef uint16_t portid_t;
77 typedef uint16_t queueid_t;
78 typedef uint16_t streamid_t;
82 PORT_TOPOLOGY_CHAINED,
87 MP_ALLOC_NATIVE, /**< allocate and populate mempool natively */
89 /**< allocate mempool natively, but populate using anonymous memory */
91 /**< allocate and populate mempool using anonymous memory */
93 /**< allocate and populate mempool using anonymous hugepage memory */
95 /**< allocate mempool natively, use rte_pktmbuf_pool_create_extbuf */
99 * The data structure associated with RX and TX packet burst statistics
100 * that are recorded for each forwarding stream.
102 struct pkt_burst_stats {
103 unsigned int pkt_burst_spread[MAX_PKT_BURST + 1];
106 /** Information for a given RSS type. */
107 struct rss_type_info {
108 const char *str; /**< Type name. */
109 uint64_t rss_type; /**< Type value. */
113 * RSS type information table.
115 * An entry with a NULL type name terminates the list.
117 extern const struct rss_type_info rss_type_table[];
122 * Array that holds the name for each dynf.
124 extern char dynf_names[64][RTE_MBUF_DYN_NAMESIZE];
127 * The data structure associated with a forwarding stream between a receive
128 * port/queue and a transmit port/queue.
131 /* "read-only" data */
132 portid_t rx_port; /**< port to poll for received packets */
133 queueid_t rx_queue; /**< RX queue to poll on "rx_port" */
134 portid_t tx_port; /**< forwarding port of received packets */
135 queueid_t tx_queue; /**< TX queue to send forwarded packets */
136 streamid_t peer_addr; /**< index of peer ethernet address of packets */
138 unsigned int retry_enabled;
140 /* "read-write" results */
141 uint64_t rx_packets; /**< received packets */
142 uint64_t tx_packets; /**< received packets transmitted */
143 uint64_t fwd_dropped; /**< received packets not forwarded */
144 uint64_t rx_bad_ip_csum ; /**< received packets has bad ip checksum */
145 uint64_t rx_bad_l4_csum ; /**< received packets has bad l4 checksum */
146 uint64_t rx_bad_outer_l4_csum;
147 /**< received packets has bad outer l4 checksum */
148 uint64_t rx_bad_outer_ip_csum;
149 /**< received packets having bad outer ip checksum */
151 unsigned int gro_times; /**< GRO operation times */
153 uint64_t core_cycles; /**< used for RX and TX processing */
154 struct pkt_burst_stats rx_burst_stats;
155 struct pkt_burst_stats tx_burst_stats;
156 struct fwd_lcore *lcore; /**< Lcore being scheduled. */
160 * Age action context types, must be included inside the age action
163 enum age_action_context_type {
164 ACTION_AGE_CONTEXT_TYPE_FLOW,
165 ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION,
168 /** Descriptor for a single flow. */
170 struct port_flow *next; /**< Next flow in list. */
171 struct port_flow *tmp; /**< Temporary linking. */
172 uint32_t id; /**< Flow rule ID. */
173 struct rte_flow *flow; /**< Opaque flow object returned by PMD. */
174 struct rte_flow_conv_rule rule; /**< Saved flow rule description. */
175 enum age_action_context_type age_type; /**< Age action context type. */
176 uint8_t data[]; /**< Storage for flow rule description */
179 /* Descriptor for indirect action */
180 struct port_indirect_action {
181 struct port_indirect_action *next; /**< Next flow in list. */
182 uint32_t id; /**< Indirect action ID. */
183 enum rte_flow_action_type type; /**< Action type. */
184 struct rte_flow_action_handle *handle; /**< Indirect action handle. */
185 enum age_action_context_type age_type; /**< Age action context type. */
188 struct port_flow_tunnel {
189 LIST_ENTRY(port_flow_tunnel) chain;
190 struct rte_flow_action *pmd_actions;
191 struct rte_flow_item *pmd_items;
193 uint32_t num_pmd_actions;
194 uint32_t num_pmd_items;
195 struct rte_flow_tunnel tunnel;
196 struct rte_flow_action *actions;
197 struct rte_flow_item *items;
208 /** Information for an extended statistics to show. */
209 struct xstat_display_info {
210 /** Supported xstats IDs in the order of xstats_display */
213 uint64_t *prev_values;
214 uint64_t *curr_values;
220 * The data structure associated with each port.
223 struct rte_eth_dev_info dev_info; /**< PCI info + driver name */
224 struct rte_eth_conf dev_conf; /**< Port configuration. */
225 struct rte_ether_addr eth_addr; /**< Port ethernet address */
226 struct rte_eth_stats stats; /**< Last port statistics */
227 unsigned int socket_id; /**< For NUMA support */
228 uint16_t parse_tunnel:1; /**< Parse internal headers */
229 uint16_t tso_segsz; /**< Segmentation offload MSS for non-tunneled packets. */
230 uint16_t tunnel_tso_segsz; /**< Segmentation offload MSS for tunneled pkts. */
231 uint16_t tx_vlan_id;/**< The tag ID */
232 uint16_t tx_vlan_id_outer;/**< The outer tag ID */
233 volatile uint16_t port_status; /**< port started or not */
234 uint8_t need_setup; /**< port just attached */
235 uint8_t need_reconfig; /**< need reconfiguring port or not */
236 uint8_t need_reconfig_queues; /**< need reconfiguring queues or not */
237 uint8_t rss_flag; /**< enable rss or not */
238 uint8_t dcb_flag; /**< enable dcb */
239 uint16_t nb_rx_desc[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue rx desc number */
240 uint16_t nb_tx_desc[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue tx desc number */
241 struct rte_eth_rxconf rx_conf[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue rx configuration */
242 struct rte_eth_txconf tx_conf[RTE_MAX_QUEUES_PER_PORT+1]; /**< per queue tx configuration */
243 struct rte_ether_addr *mc_addr_pool; /**< pool of multicast addrs */
244 uint32_t mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
245 uint8_t slave_flag; /**< bonding slave port */
246 struct port_flow *flow_list; /**< Associated flows. */
247 struct port_indirect_action *actions_list;
248 /**< Associated indirect actions. */
249 LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
250 const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
251 const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
252 /**< metadata value to insert in Tx packets. */
253 uint32_t tx_metadata;
254 const struct rte_eth_rxtx_callback *tx_set_md_cb[RTE_MAX_QUEUES_PER_PORT+1];
255 /**< dynamic flags. */
257 const struct rte_eth_rxtx_callback *tx_set_dynf_cb[RTE_MAX_QUEUES_PER_PORT+1];
258 struct xstat_display_info xstats_info;
262 * The data structure associated with each forwarding logical core.
263 * The logical cores are internally numbered by a core index from 0 to
264 * the maximum number of logical cores - 1.
265 * The system CPU identifier of all logical cores are setup in a global
266 * CPU id. configuration table.
270 struct rte_gso_ctx gso_ctx; /**< GSO context */
272 struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
274 void *gro_ctx; /**< GRO context */
276 streamid_t stream_idx; /**< index of 1st stream in "fwd_streams" */
277 streamid_t stream_nb; /**< number of streams in "fwd_streams" */
278 lcoreid_t cpuid_idx; /**< index of logical core in CPU id table */
279 volatile char stopped; /**< stop forwarding when set */
283 * Forwarding mode operations:
284 * - IO forwarding mode (default mode)
285 * Forwards packets unchanged.
287 * - MAC forwarding mode
288 * Set the source and the destination Ethernet addresses of packets
289 * before forwarding them.
291 * - IEEE1588 forwarding mode
292 * Check that received IEEE1588 Precise Time Protocol (PTP) packets are
293 * filtered and timestamped by the hardware.
294 * Forwards packets unchanged on the same port.
295 * Check that sent IEEE1588 PTP packets are timestamped by the hardware.
297 typedef int (*port_fwd_begin_t)(portid_t pi);
298 typedef void (*port_fwd_end_t)(portid_t pi);
299 typedef void (*packet_fwd_t)(struct fwd_stream *fs);
302 const char *fwd_mode_name; /**< Forwarding mode name. */
303 port_fwd_begin_t port_fwd_begin; /**< NULL if nothing special to do. */
304 port_fwd_end_t port_fwd_end; /**< NULL if nothing special to do. */
305 packet_fwd_t packet_fwd; /**< Mandatory. */
308 #define FLEX_ITEM_MAX_SAMPLES_NUM 16
309 #define FLEX_ITEM_MAX_LINKS_NUM 16
310 #define FLEX_MAX_FLOW_PATTERN_LENGTH 64
311 #define FLEX_MAX_PARSERS_NUM 8
312 #define FLEX_MAX_PATTERNS_NUM 64
313 #define FLEX_PARSER_ERR ((struct flex_item *)-1)
316 struct rte_flow_item_flex_conf flex_conf;
317 struct rte_flow_item_flex_handle *flex_handle;
321 struct flex_pattern {
322 struct rte_flow_item_flex spec, mask;
323 uint8_t spec_pattern[FLEX_MAX_FLOW_PATTERN_LENGTH];
324 uint8_t mask_pattern[FLEX_MAX_FLOW_PATTERN_LENGTH];
326 extern struct flex_item *flex_items[RTE_MAX_ETHPORTS][FLEX_MAX_PARSERS_NUM];
327 extern struct flex_pattern flex_patterns[FLEX_MAX_PATTERNS_NUM];
329 #define BURST_TX_WAIT_US 1
330 #define BURST_TX_RETRIES 64
332 extern uint32_t burst_tx_delay_time;
333 extern uint32_t burst_tx_retry_num;
335 extern struct fwd_engine io_fwd_engine;
336 extern struct fwd_engine mac_fwd_engine;
337 extern struct fwd_engine mac_swap_engine;
338 extern struct fwd_engine flow_gen_engine;
339 extern struct fwd_engine rx_only_engine;
340 extern struct fwd_engine tx_only_engine;
341 extern struct fwd_engine csum_fwd_engine;
342 extern struct fwd_engine icmp_echo_engine;
343 extern struct fwd_engine noisy_vnf_engine;
344 extern struct fwd_engine five_tuple_swap_fwd_engine;
345 #ifdef RTE_LIBRTE_IEEE1588
346 extern struct fwd_engine ieee1588_fwd_engine;
348 extern struct fwd_engine shared_rxq_engine;
350 extern struct fwd_engine * fwd_engines[]; /**< NULL terminated array. */
351 extern cmdline_parse_inst_t cmd_set_raw;
352 extern cmdline_parse_inst_t cmd_show_set_raw;
353 extern cmdline_parse_inst_t cmd_show_set_raw_all;
354 extern cmdline_parse_inst_t cmd_set_flex_is_pattern;
355 extern cmdline_parse_inst_t cmd_set_flex_spec_pattern;
357 extern uint16_t mempool_flags;
360 * Forwarding Configuration
364 struct fwd_engine *fwd_eng; /**< Packet forwarding mode. */
365 streamid_t nb_fwd_streams; /**< Nb. of forward streams to process. */
366 lcoreid_t nb_fwd_lcores; /**< Nb. of logical cores to launch. */
367 portid_t nb_fwd_ports; /**< Nb. of ports involved. */
379 extern uint8_t xstats_hide_zero; /**< Hide zero values for xstats display */
381 /* globals used for configuration */
382 extern uint8_t record_core_cycles; /**< Enables measurement of CPU cycles */
383 extern uint8_t record_burst_stats; /**< Enables display of RX and TX bursts */
384 extern uint16_t verbose_level; /**< Drives messages being displayed, if any. */
385 extern int testpmd_logtype; /**< Log type for testpmd logs */
386 extern uint8_t interactive;
387 extern uint8_t auto_start;
388 extern uint8_t tx_first;
389 extern char cmdline_filename[PATH_MAX]; /**< offline commands file */
390 extern uint8_t numa_support; /**< set by "--numa" parameter */
391 extern uint16_t port_topology; /**< set by "--port-topology" parameter */
392 extern uint8_t no_flush_rx; /**<set by "--no-flush-rx" parameter */
393 extern uint8_t flow_isolate_all; /**< set by "--flow-isolate-all */
394 extern uint8_t mp_alloc_type;
395 /**< set by "--mp-anon" or "--mp-alloc" parameter */
396 extern uint32_t eth_link_speed;
397 extern uint8_t no_link_check; /**<set by "--disable-link-check" parameter */
398 extern uint8_t no_device_start; /**<set by "--disable-device-start" parameter */
399 extern volatile int test_done; /* stop packet forwarding when set to 1. */
400 extern uint8_t lsc_interrupt; /**< disabled by "--no-lsc-interrupt" parameter */
401 extern uint8_t rmv_interrupt; /**< disabled by "--no-rmv-interrupt" parameter */
402 extern uint32_t event_print_mask;
403 /**< set by "--print-event xxxx" and "--mask-event xxxx parameters */
404 extern bool setup_on_probe_event; /**< disabled by port setup-on iterator */
405 extern uint8_t hot_plug; /**< enable by "--hot-plug" parameter */
406 extern int do_mlockall; /**< set by "--mlockall" or "--no-mlockall" parameter */
407 extern uint8_t clear_ptypes; /**< disabled by set ptype cmd */
409 #ifdef RTE_LIBRTE_IXGBE_BYPASS
410 extern uint32_t bypass_timeout; /**< Store the NIC bypass watchdog timeout */
414 * Store specified sockets on which memory pool to be used by ports
417 extern uint8_t port_numa[RTE_MAX_ETHPORTS];
420 * Store specified sockets on which RX ring to be used by ports
423 extern uint8_t rxring_numa[RTE_MAX_ETHPORTS];
426 * Store specified sockets on which TX ring to be used by ports
429 extern uint8_t txring_numa[RTE_MAX_ETHPORTS];
431 extern uint8_t socket_num;
434 * Configuration of logical cores:
435 * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
437 extern lcoreid_t nb_lcores; /**< Number of logical cores probed at init time. */
438 extern lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
439 extern lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
440 extern unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE];
441 extern unsigned int num_sockets;
442 extern unsigned int socket_ids[RTE_MAX_NUMA_NODES];
445 * Configuration of Ethernet ports:
446 * nb_fwd_ports <= nb_cfg_ports <= nb_ports
448 extern portid_t nb_ports; /**< Number of ethernet ports probed at init time. */
449 extern portid_t nb_cfg_ports; /**< Number of configured ports. */
450 extern portid_t nb_fwd_ports; /**< Number of forwarding ports. */
451 extern portid_t fwd_ports_ids[RTE_MAX_ETHPORTS];
452 extern struct rte_port *ports;
454 extern struct rte_eth_rxmode rx_mode;
455 extern struct rte_eth_txmode tx_mode;
457 extern uint64_t rss_hf;
459 extern queueid_t nb_hairpinq;
460 extern queueid_t nb_rxq;
461 extern queueid_t nb_txq;
463 extern uint16_t nb_rxd;
464 extern uint16_t nb_txd;
466 extern int16_t rx_free_thresh;
467 extern int8_t rx_drop_en;
468 extern int16_t tx_free_thresh;
469 extern int16_t tx_rs_thresh;
471 extern uint16_t noisy_tx_sw_bufsz;
472 extern uint16_t noisy_tx_sw_buf_flush_time;
473 extern uint64_t noisy_lkup_mem_sz;
474 extern uint64_t noisy_lkup_num_writes;
475 extern uint64_t noisy_lkup_num_reads;
476 extern uint64_t noisy_lkup_num_reads_writes;
478 extern uint8_t dcb_config;
480 extern uint32_t mbuf_data_size_n;
481 extern uint16_t mbuf_data_size[MAX_SEGS_BUFFER_SPLIT];
482 /**< Mbuf data space size. */
483 extern uint32_t param_total_num_mbufs;
485 extern uint16_t stats_period;
487 extern struct rte_eth_xstat_name *xstats_display;
488 extern unsigned int xstats_display_num;
490 extern uint16_t hairpin_mode;
492 #ifdef RTE_LIB_LATENCYSTATS
493 extern uint8_t latencystats_enabled;
494 extern lcoreid_t latencystats_lcore_id;
497 #ifdef RTE_LIB_BITRATESTATS
498 extern lcoreid_t bitrate_lcore_id;
499 extern uint8_t bitrate_enabled;
502 extern struct rte_eth_fdir_conf fdir_conf;
504 extern uint32_t max_rx_pkt_len;
507 * Configuration of packet segments used to scatter received packets
508 * if some of split features is configured.
510 extern uint16_t rx_pkt_seg_lengths[MAX_SEGS_BUFFER_SPLIT];
511 extern uint8_t rx_pkt_nb_segs; /**< Number of segments to split */
512 extern uint16_t rx_pkt_seg_offsets[MAX_SEGS_BUFFER_SPLIT];
513 extern uint8_t rx_pkt_nb_offs; /**< Number of specified offsets */
516 * Configuration of packet segments used by the "txonly" processing engine.
518 #define TXONLY_DEF_PACKET_LEN 64
519 extern uint16_t tx_pkt_length; /**< Length of TXONLY packet */
520 extern uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT]; /**< Seg. lengths */
521 extern uint8_t tx_pkt_nb_segs; /**< Number of segments in TX packets */
522 extern uint32_t tx_pkt_times_intra;
523 extern uint32_t tx_pkt_times_inter;
531 extern enum tx_pkt_split tx_pkt_split;
533 extern uint8_t txonly_multi_flow;
535 extern uint32_t rxq_share;
537 extern uint16_t nb_pkt_per_burst;
538 extern uint16_t nb_pkt_flowgen_clones;
539 extern int nb_flows_flowgen;
540 extern uint16_t mb_mempool_cache;
541 extern int8_t rx_pthresh;
542 extern int8_t rx_hthresh;
543 extern int8_t rx_wthresh;
544 extern int8_t tx_pthresh;
545 extern int8_t tx_hthresh;
546 extern int8_t tx_wthresh;
548 extern uint16_t tx_udp_src_port;
549 extern uint16_t tx_udp_dst_port;
551 extern uint32_t tx_ip_src_addr;
552 extern uint32_t tx_ip_dst_addr;
554 extern struct fwd_config cur_fwd_config;
555 extern struct fwd_engine *cur_fwd_eng;
556 extern uint32_t retry_enabled;
557 extern struct fwd_lcore **fwd_lcores;
558 extern struct fwd_stream **fwd_streams;
560 extern uint16_t vxlan_gpe_udp_port; /**< UDP port of tunnel VXLAN-GPE. */
561 extern uint16_t geneve_udp_port; /**< UDP port of tunnel GENEVE. */
563 extern portid_t nb_peer_eth_addrs; /**< Number of peer ethernet addresses. */
564 extern struct rte_ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
566 extern uint32_t burst_tx_delay_time; /**< Burst tx delay time(us) for mac-retry. */
567 extern uint32_t burst_tx_retry_num; /**< Burst tx retry number for mac-retry. */
570 #define GRO_DEFAULT_ITEM_NUM_PER_FLOW 32
571 #define GRO_DEFAULT_FLOW_NUM (RTE_GRO_MAX_BURST_ITEM_NUM / \
572 GRO_DEFAULT_ITEM_NUM_PER_FLOW)
574 #define GRO_DEFAULT_FLUSH_CYCLES 1
575 #define GRO_MAX_FLUSH_CYCLES 4
578 struct rte_gro_param param;
581 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
582 extern uint8_t gro_flush_cycles;
583 #endif /* RTE_LIB_GRO */
586 #define GSO_MAX_PKT_BURST 2048
590 extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
591 extern uint16_t gso_max_segment_size;
592 #endif /* RTE_LIB_GSO */
594 /* VXLAN encap/decap parameters. */
595 struct vxlan_encap_conf {
596 uint32_t select_ipv4:1;
597 uint32_t select_vlan:1;
598 uint32_t select_tos_ttl:1;
604 uint8_t ipv6_src[16];
605 uint8_t ipv6_dst[16];
609 uint8_t eth_src[RTE_ETHER_ADDR_LEN];
610 uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
613 extern struct vxlan_encap_conf vxlan_encap_conf;
615 /* NVGRE encap/decap parameters. */
616 struct nvgre_encap_conf {
617 uint32_t select_ipv4:1;
618 uint32_t select_vlan:1;
622 uint8_t ipv6_src[16];
623 uint8_t ipv6_dst[16];
625 uint8_t eth_src[RTE_ETHER_ADDR_LEN];
626 uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
629 extern struct nvgre_encap_conf nvgre_encap_conf;
631 /* L2 encap parameters. */
632 struct l2_encap_conf {
633 uint32_t select_ipv4:1;
634 uint32_t select_vlan:1;
636 uint8_t eth_src[RTE_ETHER_ADDR_LEN];
637 uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
639 extern struct l2_encap_conf l2_encap_conf;
641 /* L2 decap parameters. */
642 struct l2_decap_conf {
643 uint32_t select_vlan:1;
645 extern struct l2_decap_conf l2_decap_conf;
647 /* MPLSoGRE encap parameters. */
648 struct mplsogre_encap_conf {
649 uint32_t select_ipv4:1;
650 uint32_t select_vlan:1;
654 uint8_t ipv6_src[16];
655 uint8_t ipv6_dst[16];
657 uint8_t eth_src[RTE_ETHER_ADDR_LEN];
658 uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
660 extern struct mplsogre_encap_conf mplsogre_encap_conf;
662 /* MPLSoGRE decap parameters. */
663 struct mplsogre_decap_conf {
664 uint32_t select_ipv4:1;
665 uint32_t select_vlan:1;
667 extern struct mplsogre_decap_conf mplsogre_decap_conf;
669 /* MPLSoUDP encap parameters. */
670 struct mplsoudp_encap_conf {
671 uint32_t select_ipv4:1;
672 uint32_t select_vlan:1;
678 uint8_t ipv6_src[16];
679 uint8_t ipv6_dst[16];
681 uint8_t eth_src[RTE_ETHER_ADDR_LEN];
682 uint8_t eth_dst[RTE_ETHER_ADDR_LEN];
684 extern struct mplsoudp_encap_conf mplsoudp_encap_conf;
686 /* MPLSoUDP decap parameters. */
687 struct mplsoudp_decap_conf {
688 uint32_t select_ipv4:1;
689 uint32_t select_vlan:1;
691 extern struct mplsoudp_decap_conf mplsoudp_decap_conf;
693 extern enum rte_eth_rx_mq_mode rx_mq_mode;
695 extern struct rte_flow_action_conntrack conntrack_context;
698 extern unsigned int num_procs;
701 is_proc_primary(void)
703 return rte_eal_process_type() == RTE_PROC_PRIMARY;
706 static inline unsigned int
711 for (i = 0; i < RTE_MAX_LCORE; ++i)
712 if (fwd_lcores_cpuids[i] == rte_lcore_id())
715 rte_panic("lcore_id of current thread not found in fwd_lcores_cpuids\n");
719 parse_fwd_portlist(const char *port);
721 static inline struct fwd_lcore *
722 current_fwd_lcore(void)
724 return fwd_lcores[lcore_num()];
729 mbuf_poolname_build(unsigned int sock_id, char *mp_name,
730 int name_size, uint16_t idx)
733 snprintf(mp_name, name_size,
734 MBUF_POOL_NAME_PFX "_%u", sock_id);
736 snprintf(mp_name, name_size,
737 MBUF_POOL_NAME_PFX "_%hu_%hu", (uint16_t)sock_id, idx);
740 static inline struct rte_mempool *
741 mbuf_pool_find(unsigned int sock_id, uint16_t idx)
743 char pool_name[RTE_MEMPOOL_NAMESIZE];
745 mbuf_poolname_build(sock_id, pool_name, sizeof(pool_name), idx);
746 return rte_mempool_lookup((const char *)pool_name);
750 * Read/Write operations on a PCI register of a port.
752 static inline uint32_t
753 port_pci_reg_read(struct rte_port *port, uint32_t reg_off)
755 const struct rte_pci_device *pci_dev;
756 const struct rte_bus *bus;
760 if (!port->dev_info.device) {
761 fprintf(stderr, "Invalid device\n");
765 bus = rte_bus_find_by_device(port->dev_info.device);
766 if (bus && !strcmp(bus->name, "pci")) {
767 pci_dev = RTE_DEV_TO_PCI(port->dev_info.device);
769 fprintf(stderr, "Not a PCI device\n");
773 reg_addr = ((char *)pci_dev->mem_resource[0].addr + reg_off);
774 reg_v = *((volatile uint32_t *)reg_addr);
775 return rte_le_to_cpu_32(reg_v);
778 #define port_id_pci_reg_read(pt_id, reg_off) \
779 port_pci_reg_read(&ports[(pt_id)], (reg_off))
782 port_pci_reg_write(struct rte_port *port, uint32_t reg_off, uint32_t reg_v)
784 const struct rte_pci_device *pci_dev;
785 const struct rte_bus *bus;
788 if (!port->dev_info.device) {
789 fprintf(stderr, "Invalid device\n");
793 bus = rte_bus_find_by_device(port->dev_info.device);
794 if (bus && !strcmp(bus->name, "pci")) {
795 pci_dev = RTE_DEV_TO_PCI(port->dev_info.device);
797 fprintf(stderr, "Not a PCI device\n");
801 reg_addr = ((char *)pci_dev->mem_resource[0].addr + reg_off);
802 *((volatile uint32_t *)reg_addr) = rte_cpu_to_le_32(reg_v);
805 #define port_id_pci_reg_write(pt_id, reg_off, reg_value) \
806 port_pci_reg_write(&ports[(pt_id)], (reg_off), (reg_value))
809 get_start_cycles(uint64_t *start_tsc)
811 if (record_core_cycles)
812 *start_tsc = rte_rdtsc();
816 get_end_cycles(struct fwd_stream *fs, uint64_t start_tsc)
818 if (record_core_cycles)
819 fs->core_cycles += rte_rdtsc() - start_tsc;
823 inc_rx_burst_stats(struct fwd_stream *fs, uint16_t nb_rx)
825 if (record_burst_stats)
826 fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
830 inc_tx_burst_stats(struct fwd_stream *fs, uint16_t nb_tx)
832 if (record_burst_stats)
833 fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
837 unsigned int parse_item_list(const char *str, const char *item_name,
838 unsigned int max_items,
839 unsigned int *parsed_items, int check_unique_values);
840 void launch_args_parse(int argc, char** argv);
841 void cmdline_read_from_file(const char *filename);
843 void prompt_exit(void);
844 void nic_stats_display(portid_t port_id);
845 void nic_stats_clear(portid_t port_id);
846 void nic_xstats_display(portid_t port_id);
847 void nic_xstats_clear(portid_t port_id);
848 void device_infos_display(const char *identifier);
849 void port_infos_display(portid_t port_id);
850 void port_summary_display(portid_t port_id);
851 void port_eeprom_display(portid_t port_id);
852 void port_module_eeprom_display(portid_t port_id);
853 void port_summary_header_display(void);
854 void rx_queue_infos_display(portid_t port_idi, uint16_t queue_id);
855 void tx_queue_infos_display(portid_t port_idi, uint16_t queue_id);
856 void fwd_lcores_config_display(void);
857 bool pkt_fwd_shared_rxq_check(void);
858 void pkt_fwd_config_display(struct fwd_config *cfg);
859 void rxtx_config_display(void);
860 void fwd_config_setup(void);
861 void set_def_fwd_config(void);
862 void reconfig(portid_t new_port_id, unsigned socket_id);
863 int init_fwd_streams(void);
864 void update_fwd_ports(portid_t new_pid);
866 void set_fwd_eth_peer(portid_t port_id, char *peer_addr);
868 void port_mtu_set(portid_t port_id, uint16_t mtu);
869 void port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_pos);
870 void port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
872 void port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
873 uint8_t bit1_pos, uint8_t bit2_pos);
874 void port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
875 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value);
876 void port_reg_display(portid_t port_id, uint32_t reg_off);
877 void port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t value);
878 int port_action_handle_create(portid_t port_id, uint32_t id,
879 const struct rte_flow_indir_action_conf *conf,
880 const struct rte_flow_action *action);
881 int port_action_handle_destroy(portid_t port_id,
882 uint32_t n, const uint32_t *action);
883 struct rte_flow_action_handle *port_action_handle_get_by_id(portid_t port_id,
885 int port_action_handle_update(portid_t port_id, uint32_t id,
886 const struct rte_flow_action *action);
887 int port_flow_validate(portid_t port_id,
888 const struct rte_flow_attr *attr,
889 const struct rte_flow_item *pattern,
890 const struct rte_flow_action *actions,
891 const struct tunnel_ops *tunnel_ops);
892 int port_flow_create(portid_t port_id,
893 const struct rte_flow_attr *attr,
894 const struct rte_flow_item *pattern,
895 const struct rte_flow_action *actions,
896 const struct tunnel_ops *tunnel_ops);
897 int port_action_handle_query(portid_t port_id, uint32_t id);
898 void update_age_action_context(const struct rte_flow_action *actions,
899 struct port_flow *pf);
900 int port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule);
901 int port_flow_flush(portid_t port_id);
902 int port_flow_dump(portid_t port_id, bool dump_all,
903 uint32_t rule, const char *file_name);
904 int port_flow_query(portid_t port_id, uint32_t rule,
905 const struct rte_flow_action *action);
906 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
907 void port_flow_aged(portid_t port_id, uint8_t destroy);
908 const char *port_flow_tunnel_type(struct rte_flow_tunnel *tunnel);
909 struct port_flow_tunnel *
910 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun);
911 void port_flow_tunnel_list(portid_t port_id);
912 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
913 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
914 int port_flow_isolate(portid_t port_id, int set);
915 int port_meter_policy_add(portid_t port_id, uint32_t policy_id,
916 const struct rte_flow_action *actions);
918 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
919 void tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id);
921 int set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc);
922 int set_fwd_lcores_mask(uint64_t lcoremask);
923 void set_fwd_lcores_number(uint16_t nb_lc);
925 void set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt);
926 void set_fwd_ports_mask(uint64_t portmask);
927 void set_fwd_ports_number(uint16_t nb_pt);
928 int port_is_forwarding(portid_t port_id);
930 void rx_vlan_strip_set(portid_t port_id, int on);
931 void rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on);
933 void rx_vlan_filter_set(portid_t port_id, int on);
934 void rx_vlan_all_filter_set(portid_t port_id, int on);
935 void rx_vlan_qinq_strip_set(portid_t port_id, int on);
936 int rx_vft_set(portid_t port_id, uint16_t vlan_id, int on);
937 void vlan_extend_set(portid_t port_id, int on);
938 void vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type,
940 void tx_vlan_set(portid_t port_id, uint16_t vlan_id);
941 void tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer);
942 void tx_vlan_reset(portid_t port_id);
943 void tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on);
945 void set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value);
947 void set_xstats_hide_zero(uint8_t on_off);
949 void set_record_core_cycles(uint8_t on_off);
950 void set_record_burst_stats(uint8_t on_off);
951 void set_verbose_level(uint16_t vb_level);
952 void set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs);
953 void show_rx_pkt_segments(void);
954 void set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs);
955 void show_rx_pkt_offsets(void);
956 void set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs);
957 void show_tx_pkt_segments(void);
958 void set_tx_pkt_times(unsigned int *tx_times);
959 void show_tx_pkt_times(void);
960 void set_tx_pkt_split(const char *name);
961 int parse_fec_mode(const char *name, uint32_t *fec_capa);
962 void show_fec_capability(uint32_t num, struct rte_eth_fec_capa *speed_fec_capa);
963 void set_nb_pkt_per_burst(uint16_t pkt_burst);
964 char *list_pkt_forwarding_modes(void);
965 char *list_pkt_forwarding_retry_modes(void);
966 void set_pkt_forwarding_mode(const char *fwd_mode);
967 void start_packet_forwarding(int with_tx_first);
968 void fwd_stats_display(void);
969 void fwd_stats_reset(void);
970 void stop_packet_forwarding(void);
971 void dev_set_link_up(portid_t pid);
972 void dev_set_link_down(portid_t pid);
973 void init_port_config(void);
974 void set_port_slave_flag(portid_t slave_pid);
975 void clear_port_slave_flag(portid_t slave_pid);
976 uint8_t port_is_bonding_slave(portid_t slave_pid);
978 int init_port_dcb_config(portid_t pid, enum dcb_mode_enable dcb_mode,
979 enum rte_eth_nb_tcs num_tcs,
981 int start_port(portid_t pid);
982 void stop_port(portid_t pid);
983 void close_port(portid_t pid);
984 void reset_port(portid_t pid);
985 void attach_port(char *identifier);
986 void detach_devargs(char *identifier);
987 void detach_port_device(portid_t port_id);
988 int all_ports_stopped(void);
989 int port_is_stopped(portid_t port_id);
990 int port_is_started(portid_t port_id);
991 void pmd_test_exit(void);
992 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
993 void fdir_get_infos(portid_t port_id);
995 void fdir_set_flex_mask(portid_t port_id,
996 struct rte_eth_fdir_flex_mask *cfg);
997 void fdir_set_flex_payload(portid_t port_id,
998 struct rte_eth_flex_payload_cfg *cfg);
999 void port_rss_reta_info(portid_t port_id,
1000 struct rte_eth_rss_reta_entry64 *reta_conf,
1001 uint16_t nb_entries);
1003 void set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on);
1006 rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
1007 uint16_t nb_rx_desc, unsigned int socket_id,
1008 struct rte_eth_rxconf *rx_conf, struct rte_mempool *mp);
1010 int set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate);
1011 int set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate,
1014 void port_rss_hash_conf_show(portid_t port_id, int show_rss_key);
1015 void port_rss_hash_key_update(portid_t port_id, char rss_type[],
1016 uint8_t *hash_key, uint8_t hash_key_len);
1017 int rx_queue_id_is_invalid(queueid_t rxq_id);
1018 int tx_queue_id_is_invalid(queueid_t txq_id);
1020 void setup_gro(const char *onoff, portid_t port_id);
1021 void setup_gro_flush_cycles(uint8_t cycles);
1022 void show_gro(portid_t port_id);
1025 void setup_gso(const char *mode, portid_t port_id);
1027 int eth_dev_info_get_print_err(uint16_t port_id,
1028 struct rte_eth_dev_info *dev_info);
1029 int eth_dev_conf_get_print_err(uint16_t port_id,
1030 struct rte_eth_conf *dev_conf);
1031 void eth_set_promisc_mode(uint16_t port_id, int enable);
1032 void eth_set_allmulticast_mode(uint16_t port, int enable);
1033 int eth_link_get_nowait_print_err(uint16_t port_id, struct rte_eth_link *link);
1034 int eth_macaddr_get_print_err(uint16_t port_id,
1035 struct rte_ether_addr *mac_addr);
1037 /* Functions to display the set of MAC addresses added to a port*/
1038 void show_macs(portid_t port_id);
1039 void show_mcast_macs(portid_t port_id);
1041 /* Functions to manage the set of filtered Multicast MAC addresses */
1042 void mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr);
1043 void mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr);
1044 void port_dcb_info_display(portid_t port_id);
1046 uint8_t *open_file(const char *file_path, uint32_t *size);
1047 int save_file(const char *file_path, uint8_t *buf, uint32_t size);
1048 int close_file(uint8_t *buf);
1050 void port_queue_region_info_display(portid_t port_id, void *buf);
1052 enum print_warning {
1056 int port_id_is_invalid(portid_t port_id, enum print_warning warning);
1057 void print_valid_ports(void);
1058 int new_socket_id(unsigned int socket_id);
1060 queueid_t get_allowed_max_nb_rxq(portid_t *pid);
1061 int check_nb_rxq(queueid_t rxq);
1062 queueid_t get_allowed_max_nb_txq(portid_t *pid);
1063 int check_nb_txq(queueid_t txq);
1064 int check_nb_rxd(queueid_t rxd);
1065 int check_nb_txd(queueid_t txd);
1066 queueid_t get_allowed_max_nb_hairpinq(portid_t *pid);
1067 int check_nb_hairpinq(queueid_t hairpinq);
1069 uint16_t dump_rx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
1070 uint16_t nb_pkts, __rte_unused uint16_t max_pkts,
1071 __rte_unused void *user_param);
1073 uint16_t dump_tx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
1074 uint16_t nb_pkts, __rte_unused void *user_param);
1076 void add_rx_dump_callbacks(portid_t portid);
1077 void remove_rx_dump_callbacks(portid_t portid);
1078 void add_tx_dump_callbacks(portid_t portid);
1079 void remove_tx_dump_callbacks(portid_t portid);
1080 void configure_rxtx_dump_callbacks(uint16_t verbose);
1082 uint16_t tx_pkt_set_md(uint16_t port_id, __rte_unused uint16_t queue,
1083 struct rte_mbuf *pkts[], uint16_t nb_pkts,
1084 __rte_unused void *user_param);
1085 void add_tx_md_callback(portid_t portid);
1086 void remove_tx_md_callback(portid_t portid);
1088 uint16_t tx_pkt_set_dynf(uint16_t port_id, __rte_unused uint16_t queue,
1089 struct rte_mbuf *pkts[], uint16_t nb_pkts,
1090 __rte_unused void *user_param);
1091 void add_tx_dynf_callback(portid_t portid);
1092 void remove_tx_dynf_callback(portid_t portid);
1093 int update_mtu_from_frame_size(portid_t portid, uint32_t max_rx_pktlen);
1094 int update_jumbo_frame_offload(portid_t portid);
1095 void flex_item_create(portid_t port_id, uint16_t flex_id, const char *filename);
1096 void flex_item_destroy(portid_t port_id, uint16_t flex_id);
1097 void port_flex_item_flush(portid_t port_id);
1099 extern int flow_parse(const char *src, void *result, unsigned int size,
1100 struct rte_flow_attr **attr,
1101 struct rte_flow_item **pattern,
1102 struct rte_flow_action **actions);
1105 * Work-around of a compilation error with ICC on invocations of the
1106 * rte_be_to_cpu_16() function.
1109 #define RTE_BE_TO_CPU_16(be_16_v) rte_be_to_cpu_16((be_16_v))
1110 #define RTE_CPU_TO_BE_16(cpu_16_v) rte_cpu_to_be_16((cpu_16_v))
1112 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
1113 #define RTE_BE_TO_CPU_16(be_16_v) (be_16_v)
1114 #define RTE_CPU_TO_BE_16(cpu_16_v) (cpu_16_v)
1116 #define RTE_BE_TO_CPU_16(be_16_v) \
1117 (uint16_t) ((((be_16_v) & 0xFF) << 8) | ((be_16_v) >> 8))
1118 #define RTE_CPU_TO_BE_16(cpu_16_v) \
1119 (uint16_t) ((((cpu_16_v) & 0xFF) << 8) | ((cpu_16_v) >> 8))
1121 #endif /* __GCC__ */
1123 #define TESTPMD_LOG(level, fmt, args...) \
1124 rte_log(RTE_LOG_ ## level, testpmd_logtype, "testpmd: " fmt, ## args)
1126 #endif /* _TESTPMD_H_ */