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