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