1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2016 Intel Corporation. 3 * Copyright 2013-2014 6WIND S.A. 4 */ 5 6 #include <stdarg.h> 7 #include <errno.h> 8 #include <stdio.h> 9 #include <string.h> 10 #include <stdint.h> 11 #include <inttypes.h> 12 13 #include <sys/queue.h> 14 #include <sys/types.h> 15 #include <sys/stat.h> 16 #include <fcntl.h> 17 #include <unistd.h> 18 19 #include <rte_common.h> 20 #include <rte_byteorder.h> 21 #include <rte_debug.h> 22 #include <rte_log.h> 23 #include <rte_memory.h> 24 #include <rte_memcpy.h> 25 #include <rte_memzone.h> 26 #include <rte_launch.h> 27 #include <rte_eal.h> 28 #include <rte_per_lcore.h> 29 #include <rte_lcore.h> 30 #include <rte_atomic.h> 31 #include <rte_branch_prediction.h> 32 #include <rte_mempool.h> 33 #include <rte_mbuf.h> 34 #include <rte_interrupts.h> 35 #include <rte_pci.h> 36 #include <rte_ether.h> 37 #include <rte_ethdev.h> 38 #include <rte_string_fns.h> 39 #include <rte_cycles.h> 40 #include <rte_flow.h> 41 #include <rte_errno.h> 42 #ifdef RTE_LIBRTE_IXGBE_PMD 43 #include <rte_pmd_ixgbe.h> 44 #endif 45 #ifdef RTE_LIBRTE_I40E_PMD 46 #include <rte_pmd_i40e.h> 47 #endif 48 #ifdef RTE_LIBRTE_BNXT_PMD 49 #include <rte_pmd_bnxt.h> 50 #endif 51 #include <rte_gro.h> 52 53 #include "testpmd.h" 54 55 #define ETHDEV_FWVERS_LEN 32 56 57 #ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */ 58 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW 59 #else 60 #define CLOCK_TYPE_ID CLOCK_MONOTONIC 61 #endif 62 63 #define NS_PER_SEC 1E9 64 65 static char *flowtype_to_str(uint16_t flow_type); 66 67 static const struct { 68 enum tx_pkt_split split; 69 const char *name; 70 } tx_split_name[] = { 71 { 72 .split = TX_PKT_SPLIT_OFF, 73 .name = "off", 74 }, 75 { 76 .split = TX_PKT_SPLIT_ON, 77 .name = "on", 78 }, 79 { 80 .split = TX_PKT_SPLIT_RND, 81 .name = "rand", 82 }, 83 }; 84 85 const struct rss_type_info rss_type_table[] = { 86 { "all", ETH_RSS_ETH | ETH_RSS_VLAN | ETH_RSS_IP | ETH_RSS_TCP | 87 ETH_RSS_UDP | ETH_RSS_SCTP | ETH_RSS_L2_PAYLOAD | 88 ETH_RSS_L2TPV3 | ETH_RSS_ESP | ETH_RSS_AH | ETH_RSS_PFCP | 89 ETH_RSS_GTPU}, 90 { "none", 0 }, 91 { "eth", ETH_RSS_ETH }, 92 { "l2-src-only", ETH_RSS_L2_SRC_ONLY }, 93 { "l2-dst-only", ETH_RSS_L2_DST_ONLY }, 94 { "vlan", ETH_RSS_VLAN }, 95 { "s-vlan", ETH_RSS_S_VLAN }, 96 { "c-vlan", ETH_RSS_C_VLAN }, 97 { "ipv4", ETH_RSS_IPV4 }, 98 { "ipv4-frag", ETH_RSS_FRAG_IPV4 }, 99 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP }, 100 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP }, 101 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP }, 102 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER }, 103 { "ipv6", ETH_RSS_IPV6 }, 104 { "ipv6-frag", ETH_RSS_FRAG_IPV6 }, 105 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP }, 106 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP }, 107 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP }, 108 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER }, 109 { "l2-payload", ETH_RSS_L2_PAYLOAD }, 110 { "ipv6-ex", ETH_RSS_IPV6_EX }, 111 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX }, 112 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX }, 113 { "port", ETH_RSS_PORT }, 114 { "vxlan", ETH_RSS_VXLAN }, 115 { "geneve", ETH_RSS_GENEVE }, 116 { "nvgre", ETH_RSS_NVGRE }, 117 { "ip", ETH_RSS_IP }, 118 { "udp", ETH_RSS_UDP }, 119 { "tcp", ETH_RSS_TCP }, 120 { "sctp", ETH_RSS_SCTP }, 121 { "tunnel", ETH_RSS_TUNNEL }, 122 { "l3-pre32", RTE_ETH_RSS_L3_PRE32 }, 123 { "l3-pre40", RTE_ETH_RSS_L3_PRE40 }, 124 { "l3-pre48", RTE_ETH_RSS_L3_PRE48 }, 125 { "l3-pre56", RTE_ETH_RSS_L3_PRE56 }, 126 { "l3-pre64", RTE_ETH_RSS_L3_PRE64 }, 127 { "l3-pre96", RTE_ETH_RSS_L3_PRE96 }, 128 { "l3-src-only", ETH_RSS_L3_SRC_ONLY }, 129 { "l3-dst-only", ETH_RSS_L3_DST_ONLY }, 130 { "l4-src-only", ETH_RSS_L4_SRC_ONLY }, 131 { "l4-dst-only", ETH_RSS_L4_DST_ONLY }, 132 { "esp", ETH_RSS_ESP }, 133 { "ah", ETH_RSS_AH }, 134 { "l2tpv3", ETH_RSS_L2TPV3 }, 135 { "pfcp", ETH_RSS_PFCP }, 136 { "pppoe", ETH_RSS_PPPOE }, 137 { "gtpu", ETH_RSS_GTPU }, 138 { NULL, 0 }, 139 }; 140 141 static void 142 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr) 143 { 144 char buf[RTE_ETHER_ADDR_FMT_SIZE]; 145 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr); 146 printf("%s%s", name, buf); 147 } 148 149 void 150 nic_stats_display(portid_t port_id) 151 { 152 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS]; 153 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS]; 154 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS]; 155 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS]; 156 static uint64_t prev_ns[RTE_MAX_ETHPORTS]; 157 struct timespec cur_time; 158 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx, 159 diff_ns; 160 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx; 161 struct rte_eth_stats stats; 162 struct rte_port *port = &ports[port_id]; 163 uint8_t i; 164 165 static const char *nic_stats_border = "########################"; 166 167 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 168 print_valid_ports(); 169 return; 170 } 171 rte_eth_stats_get(port_id, &stats); 172 printf("\n %s NIC statistics for port %-2d %s\n", 173 nic_stats_border, port_id, nic_stats_border); 174 175 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) { 176 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: " 177 "%-"PRIu64"\n", 178 stats.ipackets, stats.imissed, stats.ibytes); 179 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors); 180 printf(" RX-nombuf: %-10"PRIu64"\n", 181 stats.rx_nombuf); 182 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: " 183 "%-"PRIu64"\n", 184 stats.opackets, stats.oerrors, stats.obytes); 185 } 186 else { 187 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64 188 " RX-bytes: %10"PRIu64"\n", 189 stats.ipackets, stats.ierrors, stats.ibytes); 190 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors); 191 printf(" RX-nombuf: %10"PRIu64"\n", 192 stats.rx_nombuf); 193 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64 194 " TX-bytes: %10"PRIu64"\n", 195 stats.opackets, stats.oerrors, stats.obytes); 196 } 197 198 if (port->rx_queue_stats_mapping_enabled) { 199 printf("\n"); 200 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) { 201 printf(" Stats reg %2d RX-packets: %10"PRIu64 202 " RX-errors: %10"PRIu64 203 " RX-bytes: %10"PRIu64"\n", 204 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]); 205 } 206 } 207 if (port->tx_queue_stats_mapping_enabled) { 208 printf("\n"); 209 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) { 210 printf(" Stats reg %2d TX-packets: %10"PRIu64 211 " TX-bytes: %10"PRIu64"\n", 212 i, stats.q_opackets[i], stats.q_obytes[i]); 213 } 214 } 215 216 diff_ns = 0; 217 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) { 218 uint64_t ns; 219 220 ns = cur_time.tv_sec * NS_PER_SEC; 221 ns += cur_time.tv_nsec; 222 223 if (prev_ns[port_id] != 0) 224 diff_ns = ns - prev_ns[port_id]; 225 prev_ns[port_id] = ns; 226 } 227 228 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ? 229 (stats.ipackets - prev_pkts_rx[port_id]) : 0; 230 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ? 231 (stats.opackets - prev_pkts_tx[port_id]) : 0; 232 prev_pkts_rx[port_id] = stats.ipackets; 233 prev_pkts_tx[port_id] = stats.opackets; 234 mpps_rx = diff_ns > 0 ? 235 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0; 236 mpps_tx = diff_ns > 0 ? 237 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0; 238 239 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ? 240 (stats.ibytes - prev_bytes_rx[port_id]) : 0; 241 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ? 242 (stats.obytes - prev_bytes_tx[port_id]) : 0; 243 prev_bytes_rx[port_id] = stats.ibytes; 244 prev_bytes_tx[port_id] = stats.obytes; 245 mbps_rx = diff_ns > 0 ? 246 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0; 247 mbps_tx = diff_ns > 0 ? 248 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0; 249 250 printf("\n Throughput (since last show)\n"); 251 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12" 252 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8, 253 mpps_tx, mbps_tx * 8); 254 255 printf(" %s############################%s\n", 256 nic_stats_border, nic_stats_border); 257 } 258 259 void 260 nic_stats_clear(portid_t port_id) 261 { 262 int ret; 263 264 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 265 print_valid_ports(); 266 return; 267 } 268 269 ret = rte_eth_stats_reset(port_id); 270 if (ret != 0) { 271 printf("%s: Error: failed to reset stats (port %u): %s", 272 __func__, port_id, strerror(-ret)); 273 return; 274 } 275 276 ret = rte_eth_stats_get(port_id, &ports[port_id].stats); 277 if (ret != 0) { 278 if (ret < 0) 279 ret = -ret; 280 printf("%s: Error: failed to get stats (port %u): %s", 281 __func__, port_id, strerror(ret)); 282 return; 283 } 284 printf("\n NIC statistics for port %d cleared\n", port_id); 285 } 286 287 void 288 nic_xstats_display(portid_t port_id) 289 { 290 struct rte_eth_xstat *xstats; 291 int cnt_xstats, idx_xstat; 292 struct rte_eth_xstat_name *xstats_names; 293 294 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 295 print_valid_ports(); 296 return; 297 } 298 printf("###### NIC extended statistics for port %-2d\n", port_id); 299 if (!rte_eth_dev_is_valid_port(port_id)) { 300 printf("Error: Invalid port number %i\n", port_id); 301 return; 302 } 303 304 /* Get count */ 305 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0); 306 if (cnt_xstats < 0) { 307 printf("Error: Cannot get count of xstats\n"); 308 return; 309 } 310 311 /* Get id-name lookup table */ 312 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats); 313 if (xstats_names == NULL) { 314 printf("Cannot allocate memory for xstats lookup\n"); 315 return; 316 } 317 if (cnt_xstats != rte_eth_xstats_get_names( 318 port_id, xstats_names, cnt_xstats)) { 319 printf("Error: Cannot get xstats lookup\n"); 320 free(xstats_names); 321 return; 322 } 323 324 /* Get stats themselves */ 325 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats); 326 if (xstats == NULL) { 327 printf("Cannot allocate memory for xstats\n"); 328 free(xstats_names); 329 return; 330 } 331 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) { 332 printf("Error: Unable to get xstats\n"); 333 free(xstats_names); 334 free(xstats); 335 return; 336 } 337 338 /* Display xstats */ 339 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) { 340 if (xstats_hide_zero && !xstats[idx_xstat].value) 341 continue; 342 printf("%s: %"PRIu64"\n", 343 xstats_names[idx_xstat].name, 344 xstats[idx_xstat].value); 345 } 346 free(xstats_names); 347 free(xstats); 348 } 349 350 void 351 nic_xstats_clear(portid_t port_id) 352 { 353 int ret; 354 355 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 356 print_valid_ports(); 357 return; 358 } 359 360 ret = rte_eth_xstats_reset(port_id); 361 if (ret != 0) { 362 printf("%s: Error: failed to reset xstats (port %u): %s", 363 __func__, port_id, strerror(-ret)); 364 return; 365 } 366 367 ret = rte_eth_stats_get(port_id, &ports[port_id].stats); 368 if (ret != 0) { 369 if (ret < 0) 370 ret = -ret; 371 printf("%s: Error: failed to get stats (port %u): %s", 372 __func__, port_id, strerror(ret)); 373 return; 374 } 375 } 376 377 void 378 nic_stats_mapping_display(portid_t port_id) 379 { 380 struct rte_port *port = &ports[port_id]; 381 uint16_t i; 382 383 static const char *nic_stats_mapping_border = "########################"; 384 385 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 386 print_valid_ports(); 387 return; 388 } 389 390 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) { 391 printf("Port id %d - either does not support queue statistic mapping or" 392 " no queue statistic mapping set\n", port_id); 393 return; 394 } 395 396 printf("\n %s NIC statistics mapping for port %-2d %s\n", 397 nic_stats_mapping_border, port_id, nic_stats_mapping_border); 398 399 if (port->rx_queue_stats_mapping_enabled) { 400 for (i = 0; i < nb_rx_queue_stats_mappings; i++) { 401 if (rx_queue_stats_mappings[i].port_id == port_id) { 402 printf(" RX-queue %2d mapped to Stats Reg %2d\n", 403 rx_queue_stats_mappings[i].queue_id, 404 rx_queue_stats_mappings[i].stats_counter_id); 405 } 406 } 407 printf("\n"); 408 } 409 410 411 if (port->tx_queue_stats_mapping_enabled) { 412 for (i = 0; i < nb_tx_queue_stats_mappings; i++) { 413 if (tx_queue_stats_mappings[i].port_id == port_id) { 414 printf(" TX-queue %2d mapped to Stats Reg %2d\n", 415 tx_queue_stats_mappings[i].queue_id, 416 tx_queue_stats_mappings[i].stats_counter_id); 417 } 418 } 419 } 420 421 printf(" %s####################################%s\n", 422 nic_stats_mapping_border, nic_stats_mapping_border); 423 } 424 425 void 426 rx_queue_infos_display(portid_t port_id, uint16_t queue_id) 427 { 428 struct rte_eth_burst_mode mode; 429 struct rte_eth_rxq_info qinfo; 430 int32_t rc; 431 static const char *info_border = "*********************"; 432 433 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo); 434 if (rc != 0) { 435 printf("Failed to retrieve information for port: %u, " 436 "RX queue: %hu\nerror desc: %s(%d)\n", 437 port_id, queue_id, strerror(-rc), rc); 438 return; 439 } 440 441 printf("\n%s Infos for port %-2u, RX queue %-2u %s", 442 info_border, port_id, queue_id, info_border); 443 444 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name); 445 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh); 446 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh); 447 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh); 448 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh); 449 printf("\nRX drop packets: %s", 450 (qinfo.conf.rx_drop_en != 0) ? "on" : "off"); 451 printf("\nRX deferred start: %s", 452 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off"); 453 printf("\nRX scattered packets: %s", 454 (qinfo.scattered_rx != 0) ? "on" : "off"); 455 printf("\nNumber of RXDs: %hu", qinfo.nb_desc); 456 457 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0) 458 printf("\nBurst mode: %s%s", 459 mode.info, 460 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ? 461 " (per queue)" : ""); 462 463 printf("\n"); 464 } 465 466 void 467 tx_queue_infos_display(portid_t port_id, uint16_t queue_id) 468 { 469 struct rte_eth_burst_mode mode; 470 struct rte_eth_txq_info qinfo; 471 int32_t rc; 472 static const char *info_border = "*********************"; 473 474 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo); 475 if (rc != 0) { 476 printf("Failed to retrieve information for port: %u, " 477 "TX queue: %hu\nerror desc: %s(%d)\n", 478 port_id, queue_id, strerror(-rc), rc); 479 return; 480 } 481 482 printf("\n%s Infos for port %-2u, TX queue %-2u %s", 483 info_border, port_id, queue_id, info_border); 484 485 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh); 486 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh); 487 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh); 488 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh); 489 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh); 490 printf("\nTX deferred start: %s", 491 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off"); 492 printf("\nNumber of TXDs: %hu", qinfo.nb_desc); 493 494 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0) 495 printf("\nBurst mode: %s%s", 496 mode.info, 497 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ? 498 " (per queue)" : ""); 499 500 printf("\n"); 501 } 502 503 static int bus_match_all(const struct rte_bus *bus, const void *data) 504 { 505 RTE_SET_USED(bus); 506 RTE_SET_USED(data); 507 return 0; 508 } 509 510 void 511 device_infos_display(const char *identifier) 512 { 513 static const char *info_border = "*********************"; 514 struct rte_bus *start = NULL, *next; 515 struct rte_dev_iterator dev_iter; 516 char name[RTE_ETH_NAME_MAX_LEN]; 517 struct rte_ether_addr mac_addr; 518 struct rte_device *dev; 519 struct rte_devargs da; 520 portid_t port_id; 521 char devstr[128]; 522 523 memset(&da, 0, sizeof(da)); 524 if (!identifier) 525 goto skip_parse; 526 527 if (rte_devargs_parsef(&da, "%s", identifier)) { 528 printf("cannot parse identifier\n"); 529 if (da.args) 530 free(da.args); 531 return; 532 } 533 534 skip_parse: 535 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) { 536 537 start = next; 538 if (identifier && da.bus != next) 539 continue; 540 541 /* Skip buses that don't have iterate method */ 542 if (!next->dev_iterate) 543 continue; 544 545 snprintf(devstr, sizeof(devstr), "bus=%s", next->name); 546 RTE_DEV_FOREACH(dev, devstr, &dev_iter) { 547 548 if (!dev->driver) 549 continue; 550 /* Check for matching device if identifier is present */ 551 if (identifier && 552 strncmp(da.name, dev->name, strlen(dev->name))) 553 continue; 554 printf("\n%s Infos for device %s %s\n", 555 info_border, dev->name, info_border); 556 printf("Bus name: %s", dev->bus->name); 557 printf("\nDriver name: %s", dev->driver->name); 558 printf("\nDevargs: %s", 559 dev->devargs ? dev->devargs->args : ""); 560 printf("\nConnect to socket: %d", dev->numa_node); 561 printf("\n"); 562 563 /* List ports with matching device name */ 564 RTE_ETH_FOREACH_DEV_OF(port_id, dev) { 565 printf("\n\tPort id: %-2d", port_id); 566 if (eth_macaddr_get_print_err(port_id, 567 &mac_addr) == 0) 568 print_ethaddr("\n\tMAC address: ", 569 &mac_addr); 570 rte_eth_dev_get_name_by_port(port_id, name); 571 printf("\n\tDevice name: %s", name); 572 printf("\n"); 573 } 574 } 575 }; 576 } 577 578 void 579 port_infos_display(portid_t port_id) 580 { 581 struct rte_port *port; 582 struct rte_ether_addr mac_addr; 583 struct rte_eth_link link; 584 struct rte_eth_dev_info dev_info; 585 int vlan_offload; 586 struct rte_mempool * mp; 587 static const char *info_border = "*********************"; 588 uint16_t mtu; 589 char name[RTE_ETH_NAME_MAX_LEN]; 590 int ret; 591 char fw_version[ETHDEV_FWVERS_LEN]; 592 593 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 594 print_valid_ports(); 595 return; 596 } 597 port = &ports[port_id]; 598 ret = eth_link_get_nowait_print_err(port_id, &link); 599 if (ret < 0) 600 return; 601 602 ret = eth_dev_info_get_print_err(port_id, &dev_info); 603 if (ret != 0) 604 return; 605 606 printf("\n%s Infos for port %-2d %s\n", 607 info_border, port_id, info_border); 608 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0) 609 print_ethaddr("MAC address: ", &mac_addr); 610 rte_eth_dev_get_name_by_port(port_id, name); 611 printf("\nDevice name: %s", name); 612 printf("\nDriver name: %s", dev_info.driver_name); 613 614 if (rte_eth_dev_fw_version_get(port_id, fw_version, 615 ETHDEV_FWVERS_LEN) == 0) 616 printf("\nFirmware-version: %s", fw_version); 617 else 618 printf("\nFirmware-version: %s", "not available"); 619 620 if (dev_info.device->devargs && dev_info.device->devargs->args) 621 printf("\nDevargs: %s", dev_info.device->devargs->args); 622 printf("\nConnect to socket: %u", port->socket_id); 623 624 if (port_numa[port_id] != NUMA_NO_CONFIG) { 625 mp = mbuf_pool_find(port_numa[port_id]); 626 if (mp) 627 printf("\nmemory allocation on the socket: %d", 628 port_numa[port_id]); 629 } else 630 printf("\nmemory allocation on the socket: %u",port->socket_id); 631 632 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down")); 633 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed); 634 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? 635 ("full-duplex") : ("half-duplex")); 636 637 if (!rte_eth_dev_get_mtu(port_id, &mtu)) 638 printf("MTU: %u\n", mtu); 639 640 printf("Promiscuous mode: %s\n", 641 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled"); 642 printf("Allmulticast mode: %s\n", 643 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled"); 644 printf("Maximum number of MAC addresses: %u\n", 645 (unsigned int)(port->dev_info.max_mac_addrs)); 646 printf("Maximum number of MAC addresses of hash filtering: %u\n", 647 (unsigned int)(port->dev_info.max_hash_mac_addrs)); 648 649 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 650 if (vlan_offload >= 0){ 651 printf("VLAN offload: \n"); 652 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD) 653 printf(" strip on, "); 654 else 655 printf(" strip off, "); 656 657 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD) 658 printf("filter on, "); 659 else 660 printf("filter off, "); 661 662 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) 663 printf("extend on, "); 664 else 665 printf("extend off, "); 666 667 if (vlan_offload & ETH_QINQ_STRIP_OFFLOAD) 668 printf("qinq strip on\n"); 669 else 670 printf("qinq strip off\n"); 671 } 672 673 if (dev_info.hash_key_size > 0) 674 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size); 675 if (dev_info.reta_size > 0) 676 printf("Redirection table size: %u\n", dev_info.reta_size); 677 if (!dev_info.flow_type_rss_offloads) 678 printf("No RSS offload flow type is supported.\n"); 679 else { 680 uint16_t i; 681 char *p; 682 683 printf("Supported RSS offload flow types:\n"); 684 for (i = RTE_ETH_FLOW_UNKNOWN + 1; 685 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) { 686 if (!(dev_info.flow_type_rss_offloads & (1ULL << i))) 687 continue; 688 p = flowtype_to_str(i); 689 if (p) 690 printf(" %s\n", p); 691 else 692 printf(" user defined %d\n", i); 693 } 694 } 695 696 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize); 697 printf("Maximum configurable length of RX packet: %u\n", 698 dev_info.max_rx_pktlen); 699 printf("Maximum configurable size of LRO aggregated packet: %u\n", 700 dev_info.max_lro_pkt_size); 701 if (dev_info.max_vfs) 702 printf("Maximum number of VFs: %u\n", dev_info.max_vfs); 703 if (dev_info.max_vmdq_pools) 704 printf("Maximum number of VMDq pools: %u\n", 705 dev_info.max_vmdq_pools); 706 707 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues); 708 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues); 709 printf("Max possible number of RXDs per queue: %hu\n", 710 dev_info.rx_desc_lim.nb_max); 711 printf("Min possible number of RXDs per queue: %hu\n", 712 dev_info.rx_desc_lim.nb_min); 713 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align); 714 715 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues); 716 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues); 717 printf("Max possible number of TXDs per queue: %hu\n", 718 dev_info.tx_desc_lim.nb_max); 719 printf("Min possible number of TXDs per queue: %hu\n", 720 dev_info.tx_desc_lim.nb_min); 721 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align); 722 printf("Max segment number per packet: %hu\n", 723 dev_info.tx_desc_lim.nb_seg_max); 724 printf("Max segment number per MTU/TSO: %hu\n", 725 dev_info.tx_desc_lim.nb_mtu_seg_max); 726 727 /* Show switch info only if valid switch domain and port id is set */ 728 if (dev_info.switch_info.domain_id != 729 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) { 730 if (dev_info.switch_info.name) 731 printf("Switch name: %s\n", dev_info.switch_info.name); 732 733 printf("Switch domain Id: %u\n", 734 dev_info.switch_info.domain_id); 735 printf("Switch Port Id: %u\n", 736 dev_info.switch_info.port_id); 737 } 738 } 739 740 void 741 port_summary_header_display(void) 742 { 743 uint16_t port_number; 744 745 port_number = rte_eth_dev_count_avail(); 746 printf("Number of available ports: %i\n", port_number); 747 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name", 748 "Driver", "Status", "Link"); 749 } 750 751 void 752 port_summary_display(portid_t port_id) 753 { 754 struct rte_ether_addr mac_addr; 755 struct rte_eth_link link; 756 struct rte_eth_dev_info dev_info; 757 char name[RTE_ETH_NAME_MAX_LEN]; 758 int ret; 759 760 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 761 print_valid_ports(); 762 return; 763 } 764 765 ret = eth_link_get_nowait_print_err(port_id, &link); 766 if (ret < 0) 767 return; 768 769 ret = eth_dev_info_get_print_err(port_id, &dev_info); 770 if (ret != 0) 771 return; 772 773 rte_eth_dev_get_name_by_port(port_id, name); 774 ret = eth_macaddr_get_print_err(port_id, &mac_addr); 775 if (ret != 0) 776 return; 777 778 printf("%-4d %02X:%02X:%02X:%02X:%02X:%02X %-12s %-14s %-8s %uMbps\n", 779 port_id, mac_addr.addr_bytes[0], mac_addr.addr_bytes[1], 780 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3], 781 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5], name, 782 dev_info.driver_name, (link.link_status) ? ("up") : ("down"), 783 (unsigned int) link.link_speed); 784 } 785 786 void 787 port_offload_cap_display(portid_t port_id) 788 { 789 struct rte_eth_dev_info dev_info; 790 static const char *info_border = "************"; 791 int ret; 792 793 if (port_id_is_invalid(port_id, ENABLED_WARN)) 794 return; 795 796 ret = eth_dev_info_get_print_err(port_id, &dev_info); 797 if (ret != 0) 798 return; 799 800 printf("\n%s Port %d supported offload features: %s\n", 801 info_border, port_id, info_border); 802 803 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) { 804 printf("VLAN stripped: "); 805 if (ports[port_id].dev_conf.rxmode.offloads & 806 DEV_RX_OFFLOAD_VLAN_STRIP) 807 printf("on\n"); 808 else 809 printf("off\n"); 810 } 811 812 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) { 813 printf("Double VLANs stripped: "); 814 if (ports[port_id].dev_conf.rxmode.offloads & 815 DEV_RX_OFFLOAD_QINQ_STRIP) 816 printf("on\n"); 817 else 818 printf("off\n"); 819 } 820 821 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) { 822 printf("RX IPv4 checksum: "); 823 if (ports[port_id].dev_conf.rxmode.offloads & 824 DEV_RX_OFFLOAD_IPV4_CKSUM) 825 printf("on\n"); 826 else 827 printf("off\n"); 828 } 829 830 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) { 831 printf("RX UDP checksum: "); 832 if (ports[port_id].dev_conf.rxmode.offloads & 833 DEV_RX_OFFLOAD_UDP_CKSUM) 834 printf("on\n"); 835 else 836 printf("off\n"); 837 } 838 839 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) { 840 printf("RX TCP checksum: "); 841 if (ports[port_id].dev_conf.rxmode.offloads & 842 DEV_RX_OFFLOAD_TCP_CKSUM) 843 printf("on\n"); 844 else 845 printf("off\n"); 846 } 847 848 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCTP_CKSUM) { 849 printf("RX SCTP checksum: "); 850 if (ports[port_id].dev_conf.rxmode.offloads & 851 DEV_RX_OFFLOAD_SCTP_CKSUM) 852 printf("on\n"); 853 else 854 printf("off\n"); 855 } 856 857 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) { 858 printf("RX Outer IPv4 checksum: "); 859 if (ports[port_id].dev_conf.rxmode.offloads & 860 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) 861 printf("on\n"); 862 else 863 printf("off\n"); 864 } 865 866 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) { 867 printf("RX Outer UDP checksum: "); 868 if (ports[port_id].dev_conf.rxmode.offloads & 869 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM) 870 printf("on\n"); 871 else 872 printf("off\n"); 873 } 874 875 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) { 876 printf("Large receive offload: "); 877 if (ports[port_id].dev_conf.rxmode.offloads & 878 DEV_RX_OFFLOAD_TCP_LRO) 879 printf("on\n"); 880 else 881 printf("off\n"); 882 } 883 884 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) { 885 printf("HW timestamp: "); 886 if (ports[port_id].dev_conf.rxmode.offloads & 887 DEV_RX_OFFLOAD_TIMESTAMP) 888 printf("on\n"); 889 else 890 printf("off\n"); 891 } 892 893 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC) { 894 printf("Rx Keep CRC: "); 895 if (ports[port_id].dev_conf.rxmode.offloads & 896 DEV_RX_OFFLOAD_KEEP_CRC) 897 printf("on\n"); 898 else 899 printf("off\n"); 900 } 901 902 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SECURITY) { 903 printf("RX offload security: "); 904 if (ports[port_id].dev_conf.rxmode.offloads & 905 DEV_RX_OFFLOAD_SECURITY) 906 printf("on\n"); 907 else 908 printf("off\n"); 909 } 910 911 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) { 912 printf("VLAN insert: "); 913 if (ports[port_id].dev_conf.txmode.offloads & 914 DEV_TX_OFFLOAD_VLAN_INSERT) 915 printf("on\n"); 916 else 917 printf("off\n"); 918 } 919 920 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) { 921 printf("Double VLANs insert: "); 922 if (ports[port_id].dev_conf.txmode.offloads & 923 DEV_TX_OFFLOAD_QINQ_INSERT) 924 printf("on\n"); 925 else 926 printf("off\n"); 927 } 928 929 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) { 930 printf("TX IPv4 checksum: "); 931 if (ports[port_id].dev_conf.txmode.offloads & 932 DEV_TX_OFFLOAD_IPV4_CKSUM) 933 printf("on\n"); 934 else 935 printf("off\n"); 936 } 937 938 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) { 939 printf("TX UDP checksum: "); 940 if (ports[port_id].dev_conf.txmode.offloads & 941 DEV_TX_OFFLOAD_UDP_CKSUM) 942 printf("on\n"); 943 else 944 printf("off\n"); 945 } 946 947 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) { 948 printf("TX TCP checksum: "); 949 if (ports[port_id].dev_conf.txmode.offloads & 950 DEV_TX_OFFLOAD_TCP_CKSUM) 951 printf("on\n"); 952 else 953 printf("off\n"); 954 } 955 956 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) { 957 printf("TX SCTP checksum: "); 958 if (ports[port_id].dev_conf.txmode.offloads & 959 DEV_TX_OFFLOAD_SCTP_CKSUM) 960 printf("on\n"); 961 else 962 printf("off\n"); 963 } 964 965 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) { 966 printf("TX Outer IPv4 checksum: "); 967 if (ports[port_id].dev_conf.txmode.offloads & 968 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) 969 printf("on\n"); 970 else 971 printf("off\n"); 972 } 973 974 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) { 975 printf("TX TCP segmentation: "); 976 if (ports[port_id].dev_conf.txmode.offloads & 977 DEV_TX_OFFLOAD_TCP_TSO) 978 printf("on\n"); 979 else 980 printf("off\n"); 981 } 982 983 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) { 984 printf("TX UDP segmentation: "); 985 if (ports[port_id].dev_conf.txmode.offloads & 986 DEV_TX_OFFLOAD_UDP_TSO) 987 printf("on\n"); 988 else 989 printf("off\n"); 990 } 991 992 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) { 993 printf("TSO for VXLAN tunnel packet: "); 994 if (ports[port_id].dev_conf.txmode.offloads & 995 DEV_TX_OFFLOAD_VXLAN_TNL_TSO) 996 printf("on\n"); 997 else 998 printf("off\n"); 999 } 1000 1001 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) { 1002 printf("TSO for GRE tunnel packet: "); 1003 if (ports[port_id].dev_conf.txmode.offloads & 1004 DEV_TX_OFFLOAD_GRE_TNL_TSO) 1005 printf("on\n"); 1006 else 1007 printf("off\n"); 1008 } 1009 1010 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) { 1011 printf("TSO for IPIP tunnel packet: "); 1012 if (ports[port_id].dev_conf.txmode.offloads & 1013 DEV_TX_OFFLOAD_IPIP_TNL_TSO) 1014 printf("on\n"); 1015 else 1016 printf("off\n"); 1017 } 1018 1019 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) { 1020 printf("TSO for GENEVE tunnel packet: "); 1021 if (ports[port_id].dev_conf.txmode.offloads & 1022 DEV_TX_OFFLOAD_GENEVE_TNL_TSO) 1023 printf("on\n"); 1024 else 1025 printf("off\n"); 1026 } 1027 1028 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IP_TNL_TSO) { 1029 printf("IP tunnel TSO: "); 1030 if (ports[port_id].dev_conf.txmode.offloads & 1031 DEV_TX_OFFLOAD_IP_TNL_TSO) 1032 printf("on\n"); 1033 else 1034 printf("off\n"); 1035 } 1036 1037 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TNL_TSO) { 1038 printf("UDP tunnel TSO: "); 1039 if (ports[port_id].dev_conf.txmode.offloads & 1040 DEV_TX_OFFLOAD_UDP_TNL_TSO) 1041 printf("on\n"); 1042 else 1043 printf("off\n"); 1044 } 1045 1046 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) { 1047 printf("TX Outer UDP checksum: "); 1048 if (ports[port_id].dev_conf.txmode.offloads & 1049 DEV_TX_OFFLOAD_OUTER_UDP_CKSUM) 1050 printf("on\n"); 1051 else 1052 printf("off\n"); 1053 } 1054 1055 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) { 1056 printf("Tx scheduling on timestamp: "); 1057 if (ports[port_id].dev_conf.txmode.offloads & 1058 DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) 1059 printf("on\n"); 1060 else 1061 printf("off\n"); 1062 } 1063 1064 } 1065 1066 int 1067 port_id_is_invalid(portid_t port_id, enum print_warning warning) 1068 { 1069 uint16_t pid; 1070 1071 if (port_id == (portid_t)RTE_PORT_ALL) 1072 return 0; 1073 1074 RTE_ETH_FOREACH_DEV(pid) 1075 if (port_id == pid) 1076 return 0; 1077 1078 if (warning == ENABLED_WARN) 1079 printf("Invalid port %d\n", port_id); 1080 1081 return 1; 1082 } 1083 1084 void print_valid_ports(void) 1085 { 1086 portid_t pid; 1087 1088 printf("The valid ports array is ["); 1089 RTE_ETH_FOREACH_DEV(pid) { 1090 printf(" %d", pid); 1091 } 1092 printf(" ]\n"); 1093 } 1094 1095 static int 1096 vlan_id_is_invalid(uint16_t vlan_id) 1097 { 1098 if (vlan_id < 4096) 1099 return 0; 1100 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id); 1101 return 1; 1102 } 1103 1104 static int 1105 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off) 1106 { 1107 const struct rte_pci_device *pci_dev; 1108 const struct rte_bus *bus; 1109 uint64_t pci_len; 1110 1111 if (reg_off & 0x3) { 1112 printf("Port register offset 0x%X not aligned on a 4-byte " 1113 "boundary\n", 1114 (unsigned)reg_off); 1115 return 1; 1116 } 1117 1118 if (!ports[port_id].dev_info.device) { 1119 printf("Invalid device\n"); 1120 return 0; 1121 } 1122 1123 bus = rte_bus_find_by_device(ports[port_id].dev_info.device); 1124 if (bus && !strcmp(bus->name, "pci")) { 1125 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device); 1126 } else { 1127 printf("Not a PCI device\n"); 1128 return 1; 1129 } 1130 1131 pci_len = pci_dev->mem_resource[0].len; 1132 if (reg_off >= pci_len) { 1133 printf("Port %d: register offset %u (0x%X) out of port PCI " 1134 "resource (length=%"PRIu64")\n", 1135 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len); 1136 return 1; 1137 } 1138 return 0; 1139 } 1140 1141 static int 1142 reg_bit_pos_is_invalid(uint8_t bit_pos) 1143 { 1144 if (bit_pos <= 31) 1145 return 0; 1146 printf("Invalid bit position %d (must be <= 31)\n", bit_pos); 1147 return 1; 1148 } 1149 1150 #define display_port_and_reg_off(port_id, reg_off) \ 1151 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off)) 1152 1153 static inline void 1154 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v) 1155 { 1156 display_port_and_reg_off(port_id, (unsigned)reg_off); 1157 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v); 1158 } 1159 1160 void 1161 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x) 1162 { 1163 uint32_t reg_v; 1164 1165 1166 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1167 return; 1168 if (port_reg_off_is_invalid(port_id, reg_off)) 1169 return; 1170 if (reg_bit_pos_is_invalid(bit_x)) 1171 return; 1172 reg_v = port_id_pci_reg_read(port_id, reg_off); 1173 display_port_and_reg_off(port_id, (unsigned)reg_off); 1174 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x)); 1175 } 1176 1177 void 1178 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off, 1179 uint8_t bit1_pos, uint8_t bit2_pos) 1180 { 1181 uint32_t reg_v; 1182 uint8_t l_bit; 1183 uint8_t h_bit; 1184 1185 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1186 return; 1187 if (port_reg_off_is_invalid(port_id, reg_off)) 1188 return; 1189 if (reg_bit_pos_is_invalid(bit1_pos)) 1190 return; 1191 if (reg_bit_pos_is_invalid(bit2_pos)) 1192 return; 1193 if (bit1_pos > bit2_pos) 1194 l_bit = bit2_pos, h_bit = bit1_pos; 1195 else 1196 l_bit = bit1_pos, h_bit = bit2_pos; 1197 1198 reg_v = port_id_pci_reg_read(port_id, reg_off); 1199 reg_v >>= l_bit; 1200 if (h_bit < 31) 1201 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1); 1202 display_port_and_reg_off(port_id, (unsigned)reg_off); 1203 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit, 1204 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v); 1205 } 1206 1207 void 1208 port_reg_display(portid_t port_id, uint32_t reg_off) 1209 { 1210 uint32_t reg_v; 1211 1212 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1213 return; 1214 if (port_reg_off_is_invalid(port_id, reg_off)) 1215 return; 1216 reg_v = port_id_pci_reg_read(port_id, reg_off); 1217 display_port_reg_value(port_id, reg_off, reg_v); 1218 } 1219 1220 void 1221 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos, 1222 uint8_t bit_v) 1223 { 1224 uint32_t reg_v; 1225 1226 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1227 return; 1228 if (port_reg_off_is_invalid(port_id, reg_off)) 1229 return; 1230 if (reg_bit_pos_is_invalid(bit_pos)) 1231 return; 1232 if (bit_v > 1) { 1233 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v); 1234 return; 1235 } 1236 reg_v = port_id_pci_reg_read(port_id, reg_off); 1237 if (bit_v == 0) 1238 reg_v &= ~(1 << bit_pos); 1239 else 1240 reg_v |= (1 << bit_pos); 1241 port_id_pci_reg_write(port_id, reg_off, reg_v); 1242 display_port_reg_value(port_id, reg_off, reg_v); 1243 } 1244 1245 void 1246 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off, 1247 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value) 1248 { 1249 uint32_t max_v; 1250 uint32_t reg_v; 1251 uint8_t l_bit; 1252 uint8_t h_bit; 1253 1254 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1255 return; 1256 if (port_reg_off_is_invalid(port_id, reg_off)) 1257 return; 1258 if (reg_bit_pos_is_invalid(bit1_pos)) 1259 return; 1260 if (reg_bit_pos_is_invalid(bit2_pos)) 1261 return; 1262 if (bit1_pos > bit2_pos) 1263 l_bit = bit2_pos, h_bit = bit1_pos; 1264 else 1265 l_bit = bit1_pos, h_bit = bit2_pos; 1266 1267 if ((h_bit - l_bit) < 31) 1268 max_v = (1 << (h_bit - l_bit + 1)) - 1; 1269 else 1270 max_v = 0xFFFFFFFF; 1271 1272 if (value > max_v) { 1273 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n", 1274 (unsigned)value, (unsigned)value, 1275 (unsigned)max_v, (unsigned)max_v); 1276 return; 1277 } 1278 reg_v = port_id_pci_reg_read(port_id, reg_off); 1279 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */ 1280 reg_v |= (value << l_bit); /* Set changed bits */ 1281 port_id_pci_reg_write(port_id, reg_off, reg_v); 1282 display_port_reg_value(port_id, reg_off, reg_v); 1283 } 1284 1285 void 1286 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v) 1287 { 1288 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1289 return; 1290 if (port_reg_off_is_invalid(port_id, reg_off)) 1291 return; 1292 port_id_pci_reg_write(port_id, reg_off, reg_v); 1293 display_port_reg_value(port_id, reg_off, reg_v); 1294 } 1295 1296 void 1297 port_mtu_set(portid_t port_id, uint16_t mtu) 1298 { 1299 int diag; 1300 struct rte_port *rte_port = &ports[port_id]; 1301 struct rte_eth_dev_info dev_info; 1302 uint16_t eth_overhead; 1303 int ret; 1304 1305 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1306 return; 1307 1308 ret = eth_dev_info_get_print_err(port_id, &dev_info); 1309 if (ret != 0) 1310 return; 1311 1312 if (mtu > dev_info.max_mtu || mtu < dev_info.min_mtu) { 1313 printf("Set MTU failed. MTU:%u is not in valid range, min:%u - max:%u\n", 1314 mtu, dev_info.min_mtu, dev_info.max_mtu); 1315 return; 1316 } 1317 diag = rte_eth_dev_set_mtu(port_id, mtu); 1318 if (diag) 1319 printf("Set MTU failed. diag=%d\n", diag); 1320 else if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) { 1321 /* 1322 * Ether overhead in driver is equal to the difference of 1323 * max_rx_pktlen and max_mtu in rte_eth_dev_info when the 1324 * device supports jumbo frame. 1325 */ 1326 eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu; 1327 if (mtu > RTE_ETHER_MAX_LEN - eth_overhead) { 1328 rte_port->dev_conf.rxmode.offloads |= 1329 DEV_RX_OFFLOAD_JUMBO_FRAME; 1330 rte_port->dev_conf.rxmode.max_rx_pkt_len = 1331 mtu + eth_overhead; 1332 } else 1333 rte_port->dev_conf.rxmode.offloads &= 1334 ~DEV_RX_OFFLOAD_JUMBO_FRAME; 1335 } 1336 } 1337 1338 /* Generic flow management functions. */ 1339 1340 /** Generate a port_flow entry from attributes/pattern/actions. */ 1341 static struct port_flow * 1342 port_flow_new(const struct rte_flow_attr *attr, 1343 const struct rte_flow_item *pattern, 1344 const struct rte_flow_action *actions, 1345 struct rte_flow_error *error) 1346 { 1347 const struct rte_flow_conv_rule rule = { 1348 .attr_ro = attr, 1349 .pattern_ro = pattern, 1350 .actions_ro = actions, 1351 }; 1352 struct port_flow *pf; 1353 int ret; 1354 1355 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error); 1356 if (ret < 0) 1357 return NULL; 1358 pf = calloc(1, offsetof(struct port_flow, rule) + ret); 1359 if (!pf) { 1360 rte_flow_error_set 1361 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, 1362 "calloc() failed"); 1363 return NULL; 1364 } 1365 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule, 1366 error) >= 0) 1367 return pf; 1368 free(pf); 1369 return NULL; 1370 } 1371 1372 /** Print a message out of a flow error. */ 1373 static int 1374 port_flow_complain(struct rte_flow_error *error) 1375 { 1376 static const char *const errstrlist[] = { 1377 [RTE_FLOW_ERROR_TYPE_NONE] = "no error", 1378 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified", 1379 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)", 1380 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field", 1381 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field", 1382 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field", 1383 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field", 1384 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field", 1385 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure", 1386 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length", 1387 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification", 1388 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range", 1389 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask", 1390 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item", 1391 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions", 1392 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration", 1393 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action", 1394 }; 1395 const char *errstr; 1396 char buf[32]; 1397 int err = rte_errno; 1398 1399 if ((unsigned int)error->type >= RTE_DIM(errstrlist) || 1400 !errstrlist[error->type]) 1401 errstr = "unknown type"; 1402 else 1403 errstr = errstrlist[error->type]; 1404 printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__, 1405 error->type, errstr, 1406 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ", 1407 error->cause), buf) : "", 1408 error->message ? error->message : "(no stated reason)", 1409 rte_strerror(err)); 1410 return -err; 1411 } 1412 1413 static void 1414 rss_config_display(struct rte_flow_action_rss *rss_conf) 1415 { 1416 uint8_t i; 1417 1418 if (rss_conf == NULL) { 1419 printf("Invalid rule\n"); 1420 return; 1421 } 1422 1423 printf("RSS:\n" 1424 " queues: "); 1425 if (rss_conf->queue_num == 0) 1426 printf("none\n"); 1427 for (i = 0; i < rss_conf->queue_num; i++) 1428 printf("%d\n", rss_conf->queue[i]); 1429 1430 printf(" function: "); 1431 switch (rss_conf->func) { 1432 case RTE_ETH_HASH_FUNCTION_DEFAULT: 1433 printf("default\n"); 1434 break; 1435 case RTE_ETH_HASH_FUNCTION_TOEPLITZ: 1436 printf("toeplitz\n"); 1437 break; 1438 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR: 1439 printf("simple_xor\n"); 1440 break; 1441 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ: 1442 printf("symmetric_toeplitz\n"); 1443 break; 1444 default: 1445 printf("Unknown function\n"); 1446 return; 1447 } 1448 1449 printf(" types:\n"); 1450 if (rss_conf->types == 0) { 1451 printf(" none\n"); 1452 return; 1453 } 1454 for (i = 0; rss_type_table[i].str; i++) { 1455 if ((rss_conf->types & 1456 rss_type_table[i].rss_type) == 1457 rss_type_table[i].rss_type && 1458 rss_type_table[i].rss_type != 0) 1459 printf(" %s\n", rss_type_table[i].str); 1460 } 1461 } 1462 1463 /** Validate flow rule. */ 1464 int 1465 port_flow_validate(portid_t port_id, 1466 const struct rte_flow_attr *attr, 1467 const struct rte_flow_item *pattern, 1468 const struct rte_flow_action *actions) 1469 { 1470 struct rte_flow_error error; 1471 1472 /* Poisoning to make sure PMDs update it in case of error. */ 1473 memset(&error, 0x11, sizeof(error)); 1474 if (rte_flow_validate(port_id, attr, pattern, actions, &error)) 1475 return port_flow_complain(&error); 1476 printf("Flow rule validated\n"); 1477 return 0; 1478 } 1479 1480 /** Update age action context by port_flow pointer. */ 1481 void 1482 update_age_action_context(const struct rte_flow_action *actions, 1483 struct port_flow *pf) 1484 { 1485 struct rte_flow_action_age *age = NULL; 1486 1487 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) { 1488 switch (actions->type) { 1489 case RTE_FLOW_ACTION_TYPE_AGE: 1490 age = (struct rte_flow_action_age *) 1491 (uintptr_t)actions->conf; 1492 age->context = pf; 1493 return; 1494 default: 1495 break; 1496 } 1497 } 1498 } 1499 1500 /** Create flow rule. */ 1501 int 1502 port_flow_create(portid_t port_id, 1503 const struct rte_flow_attr *attr, 1504 const struct rte_flow_item *pattern, 1505 const struct rte_flow_action *actions) 1506 { 1507 struct rte_flow *flow; 1508 struct rte_port *port; 1509 struct port_flow *pf; 1510 uint32_t id = 0; 1511 struct rte_flow_error error; 1512 1513 port = &ports[port_id]; 1514 if (port->flow_list) { 1515 if (port->flow_list->id == UINT32_MAX) { 1516 printf("Highest rule ID is already assigned, delete" 1517 " it first"); 1518 return -ENOMEM; 1519 } 1520 id = port->flow_list->id + 1; 1521 } 1522 pf = port_flow_new(attr, pattern, actions, &error); 1523 if (!pf) 1524 return port_flow_complain(&error); 1525 update_age_action_context(actions, pf); 1526 /* Poisoning to make sure PMDs update it in case of error. */ 1527 memset(&error, 0x22, sizeof(error)); 1528 flow = rte_flow_create(port_id, attr, pattern, actions, &error); 1529 if (!flow) { 1530 free(pf); 1531 return port_flow_complain(&error); 1532 } 1533 pf->next = port->flow_list; 1534 pf->id = id; 1535 pf->flow = flow; 1536 port->flow_list = pf; 1537 printf("Flow rule #%u created\n", pf->id); 1538 return 0; 1539 } 1540 1541 /** Destroy a number of flow rules. */ 1542 int 1543 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule) 1544 { 1545 struct rte_port *port; 1546 struct port_flow **tmp; 1547 uint32_t c = 0; 1548 int ret = 0; 1549 1550 if (port_id_is_invalid(port_id, ENABLED_WARN) || 1551 port_id == (portid_t)RTE_PORT_ALL) 1552 return -EINVAL; 1553 port = &ports[port_id]; 1554 tmp = &port->flow_list; 1555 while (*tmp) { 1556 uint32_t i; 1557 1558 for (i = 0; i != n; ++i) { 1559 struct rte_flow_error error; 1560 struct port_flow *pf = *tmp; 1561 1562 if (rule[i] != pf->id) 1563 continue; 1564 /* 1565 * Poisoning to make sure PMDs update it in case 1566 * of error. 1567 */ 1568 memset(&error, 0x33, sizeof(error)); 1569 if (rte_flow_destroy(port_id, pf->flow, &error)) { 1570 ret = port_flow_complain(&error); 1571 continue; 1572 } 1573 printf("Flow rule #%u destroyed\n", pf->id); 1574 *tmp = pf->next; 1575 free(pf); 1576 break; 1577 } 1578 if (i == n) 1579 tmp = &(*tmp)->next; 1580 ++c; 1581 } 1582 return ret; 1583 } 1584 1585 /** Remove all flow rules. */ 1586 int 1587 port_flow_flush(portid_t port_id) 1588 { 1589 struct rte_flow_error error; 1590 struct rte_port *port; 1591 int ret = 0; 1592 1593 /* Poisoning to make sure PMDs update it in case of error. */ 1594 memset(&error, 0x44, sizeof(error)); 1595 if (rte_flow_flush(port_id, &error)) { 1596 ret = port_flow_complain(&error); 1597 if (port_id_is_invalid(port_id, DISABLED_WARN) || 1598 port_id == (portid_t)RTE_PORT_ALL) 1599 return ret; 1600 } 1601 port = &ports[port_id]; 1602 while (port->flow_list) { 1603 struct port_flow *pf = port->flow_list->next; 1604 1605 free(port->flow_list); 1606 port->flow_list = pf; 1607 } 1608 return ret; 1609 } 1610 1611 /** Dump all flow rules. */ 1612 int 1613 port_flow_dump(portid_t port_id, const char *file_name) 1614 { 1615 int ret = 0; 1616 FILE *file = stdout; 1617 struct rte_flow_error error; 1618 1619 if (file_name && strlen(file_name)) { 1620 file = fopen(file_name, "w"); 1621 if (!file) { 1622 printf("Failed to create file %s: %s\n", file_name, 1623 strerror(errno)); 1624 return -errno; 1625 } 1626 } 1627 ret = rte_flow_dev_dump(port_id, file, &error); 1628 if (ret) { 1629 port_flow_complain(&error); 1630 printf("Failed to dump flow: %s\n", strerror(-ret)); 1631 } else 1632 printf("Flow dump finished\n"); 1633 if (file_name && strlen(file_name)) 1634 fclose(file); 1635 return ret; 1636 } 1637 1638 /** Query a flow rule. */ 1639 int 1640 port_flow_query(portid_t port_id, uint32_t rule, 1641 const struct rte_flow_action *action) 1642 { 1643 struct rte_flow_error error; 1644 struct rte_port *port; 1645 struct port_flow *pf; 1646 const char *name; 1647 union { 1648 struct rte_flow_query_count count; 1649 struct rte_flow_action_rss rss_conf; 1650 } query; 1651 int ret; 1652 1653 if (port_id_is_invalid(port_id, ENABLED_WARN) || 1654 port_id == (portid_t)RTE_PORT_ALL) 1655 return -EINVAL; 1656 port = &ports[port_id]; 1657 for (pf = port->flow_list; pf; pf = pf->next) 1658 if (pf->id == rule) 1659 break; 1660 if (!pf) { 1661 printf("Flow rule #%u not found\n", rule); 1662 return -ENOENT; 1663 } 1664 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR, 1665 &name, sizeof(name), 1666 (void *)(uintptr_t)action->type, &error); 1667 if (ret < 0) 1668 return port_flow_complain(&error); 1669 switch (action->type) { 1670 case RTE_FLOW_ACTION_TYPE_COUNT: 1671 case RTE_FLOW_ACTION_TYPE_RSS: 1672 break; 1673 default: 1674 printf("Cannot query action type %d (%s)\n", 1675 action->type, name); 1676 return -ENOTSUP; 1677 } 1678 /* Poisoning to make sure PMDs update it in case of error. */ 1679 memset(&error, 0x55, sizeof(error)); 1680 memset(&query, 0, sizeof(query)); 1681 if (rte_flow_query(port_id, pf->flow, action, &query, &error)) 1682 return port_flow_complain(&error); 1683 switch (action->type) { 1684 case RTE_FLOW_ACTION_TYPE_COUNT: 1685 printf("%s:\n" 1686 " hits_set: %u\n" 1687 " bytes_set: %u\n" 1688 " hits: %" PRIu64 "\n" 1689 " bytes: %" PRIu64 "\n", 1690 name, 1691 query.count.hits_set, 1692 query.count.bytes_set, 1693 query.count.hits, 1694 query.count.bytes); 1695 break; 1696 case RTE_FLOW_ACTION_TYPE_RSS: 1697 rss_config_display(&query.rss_conf); 1698 break; 1699 default: 1700 printf("Cannot display result for action type %d (%s)\n", 1701 action->type, name); 1702 break; 1703 } 1704 return 0; 1705 } 1706 1707 /** List simply and destroy all aged flows. */ 1708 void 1709 port_flow_aged(portid_t port_id, uint8_t destroy) 1710 { 1711 void **contexts; 1712 int nb_context, total = 0, idx; 1713 struct rte_flow_error error; 1714 struct port_flow *pf; 1715 1716 if (port_id_is_invalid(port_id, ENABLED_WARN) || 1717 port_id == (portid_t)RTE_PORT_ALL) 1718 return; 1719 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error); 1720 printf("Port %u total aged flows: %d\n", port_id, total); 1721 if (total < 0) { 1722 port_flow_complain(&error); 1723 return; 1724 } 1725 if (total == 0) 1726 return; 1727 contexts = malloc(sizeof(void *) * total); 1728 if (contexts == NULL) { 1729 printf("Cannot allocate contexts for aged flow\n"); 1730 return; 1731 } 1732 printf("ID\tGroup\tPrio\tAttr\n"); 1733 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error); 1734 if (nb_context != total) { 1735 printf("Port:%d get aged flows count(%d) != total(%d)\n", 1736 port_id, nb_context, total); 1737 free(contexts); 1738 return; 1739 } 1740 for (idx = 0; idx < nb_context; idx++) { 1741 pf = (struct port_flow *)contexts[idx]; 1742 if (!pf) { 1743 printf("Error: get Null context in port %u\n", port_id); 1744 continue; 1745 } 1746 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n", 1747 pf->id, 1748 pf->rule.attr->group, 1749 pf->rule.attr->priority, 1750 pf->rule.attr->ingress ? 'i' : '-', 1751 pf->rule.attr->egress ? 'e' : '-', 1752 pf->rule.attr->transfer ? 't' : '-'); 1753 } 1754 if (destroy) { 1755 int ret; 1756 uint32_t flow_id; 1757 1758 total = 0; 1759 printf("\n"); 1760 for (idx = 0; idx < nb_context; idx++) { 1761 pf = (struct port_flow *)contexts[idx]; 1762 if (!pf) 1763 continue; 1764 flow_id = pf->id; 1765 ret = port_flow_destroy(port_id, 1, &flow_id); 1766 if (!ret) 1767 total++; 1768 } 1769 printf("%d flows be destroyed\n", total); 1770 } 1771 free(contexts); 1772 } 1773 1774 /** List flow rules. */ 1775 void 1776 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n]) 1777 { 1778 struct rte_port *port; 1779 struct port_flow *pf; 1780 struct port_flow *list = NULL; 1781 uint32_t i; 1782 1783 if (port_id_is_invalid(port_id, ENABLED_WARN) || 1784 port_id == (portid_t)RTE_PORT_ALL) 1785 return; 1786 port = &ports[port_id]; 1787 if (!port->flow_list) 1788 return; 1789 /* Sort flows by group, priority and ID. */ 1790 for (pf = port->flow_list; pf != NULL; pf = pf->next) { 1791 struct port_flow **tmp; 1792 const struct rte_flow_attr *curr = pf->rule.attr; 1793 1794 if (n) { 1795 /* Filter out unwanted groups. */ 1796 for (i = 0; i != n; ++i) 1797 if (curr->group == group[i]) 1798 break; 1799 if (i == n) 1800 continue; 1801 } 1802 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) { 1803 const struct rte_flow_attr *comp = (*tmp)->rule.attr; 1804 1805 if (curr->group > comp->group || 1806 (curr->group == comp->group && 1807 curr->priority > comp->priority) || 1808 (curr->group == comp->group && 1809 curr->priority == comp->priority && 1810 pf->id > (*tmp)->id)) 1811 continue; 1812 break; 1813 } 1814 pf->tmp = *tmp; 1815 *tmp = pf; 1816 } 1817 printf("ID\tGroup\tPrio\tAttr\tRule\n"); 1818 for (pf = list; pf != NULL; pf = pf->tmp) { 1819 const struct rte_flow_item *item = pf->rule.pattern; 1820 const struct rte_flow_action *action = pf->rule.actions; 1821 const char *name; 1822 1823 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t", 1824 pf->id, 1825 pf->rule.attr->group, 1826 pf->rule.attr->priority, 1827 pf->rule.attr->ingress ? 'i' : '-', 1828 pf->rule.attr->egress ? 'e' : '-', 1829 pf->rule.attr->transfer ? 't' : '-'); 1830 while (item->type != RTE_FLOW_ITEM_TYPE_END) { 1831 if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR, 1832 &name, sizeof(name), 1833 (void *)(uintptr_t)item->type, 1834 NULL) <= 0) 1835 name = "[UNKNOWN]"; 1836 if (item->type != RTE_FLOW_ITEM_TYPE_VOID) 1837 printf("%s ", name); 1838 ++item; 1839 } 1840 printf("=>"); 1841 while (action->type != RTE_FLOW_ACTION_TYPE_END) { 1842 if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR, 1843 &name, sizeof(name), 1844 (void *)(uintptr_t)action->type, 1845 NULL) <= 0) 1846 name = "[UNKNOWN]"; 1847 if (action->type != RTE_FLOW_ACTION_TYPE_VOID) 1848 printf(" %s", name); 1849 ++action; 1850 } 1851 printf("\n"); 1852 } 1853 } 1854 1855 /** Restrict ingress traffic to the defined flow rules. */ 1856 int 1857 port_flow_isolate(portid_t port_id, int set) 1858 { 1859 struct rte_flow_error error; 1860 1861 /* Poisoning to make sure PMDs update it in case of error. */ 1862 memset(&error, 0x66, sizeof(error)); 1863 if (rte_flow_isolate(port_id, set, &error)) 1864 return port_flow_complain(&error); 1865 printf("Ingress traffic on port %u is %s to the defined flow rules\n", 1866 port_id, 1867 set ? "now restricted" : "not restricted anymore"); 1868 return 0; 1869 } 1870 1871 /* 1872 * RX/TX ring descriptors display functions. 1873 */ 1874 int 1875 rx_queue_id_is_invalid(queueid_t rxq_id) 1876 { 1877 if (rxq_id < nb_rxq) 1878 return 0; 1879 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq); 1880 return 1; 1881 } 1882 1883 int 1884 tx_queue_id_is_invalid(queueid_t txq_id) 1885 { 1886 if (txq_id < nb_txq) 1887 return 0; 1888 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq); 1889 return 1; 1890 } 1891 1892 static int 1893 rx_desc_id_is_invalid(uint16_t rxdesc_id) 1894 { 1895 if (rxdesc_id < nb_rxd) 1896 return 0; 1897 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n", 1898 rxdesc_id, nb_rxd); 1899 return 1; 1900 } 1901 1902 static int 1903 tx_desc_id_is_invalid(uint16_t txdesc_id) 1904 { 1905 if (txdesc_id < nb_txd) 1906 return 0; 1907 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n", 1908 txdesc_id, nb_txd); 1909 return 1; 1910 } 1911 1912 static const struct rte_memzone * 1913 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id) 1914 { 1915 char mz_name[RTE_MEMZONE_NAMESIZE]; 1916 const struct rte_memzone *mz; 1917 1918 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s", 1919 port_id, q_id, ring_name); 1920 mz = rte_memzone_lookup(mz_name); 1921 if (mz == NULL) 1922 printf("%s ring memory zoneof (port %d, queue %d) not" 1923 "found (zone name = %s\n", 1924 ring_name, port_id, q_id, mz_name); 1925 return mz; 1926 } 1927 1928 union igb_ring_dword { 1929 uint64_t dword; 1930 struct { 1931 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN 1932 uint32_t lo; 1933 uint32_t hi; 1934 #else 1935 uint32_t hi; 1936 uint32_t lo; 1937 #endif 1938 } words; 1939 }; 1940 1941 struct igb_ring_desc_32_bytes { 1942 union igb_ring_dword lo_dword; 1943 union igb_ring_dword hi_dword; 1944 union igb_ring_dword resv1; 1945 union igb_ring_dword resv2; 1946 }; 1947 1948 struct igb_ring_desc_16_bytes { 1949 union igb_ring_dword lo_dword; 1950 union igb_ring_dword hi_dword; 1951 }; 1952 1953 static void 1954 ring_rxd_display_dword(union igb_ring_dword dword) 1955 { 1956 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo, 1957 (unsigned)dword.words.hi); 1958 } 1959 1960 static void 1961 ring_rx_descriptor_display(const struct rte_memzone *ring_mz, 1962 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC 1963 portid_t port_id, 1964 #else 1965 __rte_unused portid_t port_id, 1966 #endif 1967 uint16_t desc_id) 1968 { 1969 struct igb_ring_desc_16_bytes *ring = 1970 (struct igb_ring_desc_16_bytes *)ring_mz->addr; 1971 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC 1972 int ret; 1973 struct rte_eth_dev_info dev_info; 1974 1975 ret = eth_dev_info_get_print_err(port_id, &dev_info); 1976 if (ret != 0) 1977 return; 1978 1979 if (strstr(dev_info.driver_name, "i40e") != NULL) { 1980 /* 32 bytes RX descriptor, i40e only */ 1981 struct igb_ring_desc_32_bytes *ring = 1982 (struct igb_ring_desc_32_bytes *)ring_mz->addr; 1983 ring[desc_id].lo_dword.dword = 1984 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword); 1985 ring_rxd_display_dword(ring[desc_id].lo_dword); 1986 ring[desc_id].hi_dword.dword = 1987 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword); 1988 ring_rxd_display_dword(ring[desc_id].hi_dword); 1989 ring[desc_id].resv1.dword = 1990 rte_le_to_cpu_64(ring[desc_id].resv1.dword); 1991 ring_rxd_display_dword(ring[desc_id].resv1); 1992 ring[desc_id].resv2.dword = 1993 rte_le_to_cpu_64(ring[desc_id].resv2.dword); 1994 ring_rxd_display_dword(ring[desc_id].resv2); 1995 1996 return; 1997 } 1998 #endif 1999 /* 16 bytes RX descriptor */ 2000 ring[desc_id].lo_dword.dword = 2001 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword); 2002 ring_rxd_display_dword(ring[desc_id].lo_dword); 2003 ring[desc_id].hi_dword.dword = 2004 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword); 2005 ring_rxd_display_dword(ring[desc_id].hi_dword); 2006 } 2007 2008 static void 2009 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id) 2010 { 2011 struct igb_ring_desc_16_bytes *ring; 2012 struct igb_ring_desc_16_bytes txd; 2013 2014 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr; 2015 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword); 2016 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword); 2017 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n", 2018 (unsigned)txd.lo_dword.words.lo, 2019 (unsigned)txd.lo_dword.words.hi, 2020 (unsigned)txd.hi_dword.words.lo, 2021 (unsigned)txd.hi_dword.words.hi); 2022 } 2023 2024 void 2025 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id) 2026 { 2027 const struct rte_memzone *rx_mz; 2028 2029 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2030 return; 2031 if (rx_queue_id_is_invalid(rxq_id)) 2032 return; 2033 if (rx_desc_id_is_invalid(rxd_id)) 2034 return; 2035 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id); 2036 if (rx_mz == NULL) 2037 return; 2038 ring_rx_descriptor_display(rx_mz, port_id, rxd_id); 2039 } 2040 2041 void 2042 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id) 2043 { 2044 const struct rte_memzone *tx_mz; 2045 2046 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2047 return; 2048 if (tx_queue_id_is_invalid(txq_id)) 2049 return; 2050 if (tx_desc_id_is_invalid(txd_id)) 2051 return; 2052 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id); 2053 if (tx_mz == NULL) 2054 return; 2055 ring_tx_descriptor_display(tx_mz, txd_id); 2056 } 2057 2058 void 2059 fwd_lcores_config_display(void) 2060 { 2061 lcoreid_t lc_id; 2062 2063 printf("List of forwarding lcores:"); 2064 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++) 2065 printf(" %2u", fwd_lcores_cpuids[lc_id]); 2066 printf("\n"); 2067 } 2068 void 2069 rxtx_config_display(void) 2070 { 2071 portid_t pid; 2072 queueid_t qid; 2073 2074 printf(" %s packet forwarding%s packets/burst=%d\n", 2075 cur_fwd_eng->fwd_mode_name, 2076 retry_enabled == 0 ? "" : " with retry", 2077 nb_pkt_per_burst); 2078 2079 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine) 2080 printf(" packet len=%u - nb packet segments=%d\n", 2081 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs); 2082 2083 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n", 2084 nb_fwd_lcores, nb_fwd_ports); 2085 2086 RTE_ETH_FOREACH_DEV(pid) { 2087 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0]; 2088 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0]; 2089 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0]; 2090 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0]; 2091 uint16_t nb_rx_desc_tmp; 2092 uint16_t nb_tx_desc_tmp; 2093 struct rte_eth_rxq_info rx_qinfo; 2094 struct rte_eth_txq_info tx_qinfo; 2095 int32_t rc; 2096 2097 /* per port config */ 2098 printf(" port %d: RX queue number: %d Tx queue number: %d\n", 2099 (unsigned int)pid, nb_rxq, nb_txq); 2100 2101 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n", 2102 ports[pid].dev_conf.rxmode.offloads, 2103 ports[pid].dev_conf.txmode.offloads); 2104 2105 /* per rx queue config only for first queue to be less verbose */ 2106 for (qid = 0; qid < 1; qid++) { 2107 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo); 2108 if (rc) 2109 nb_rx_desc_tmp = nb_rx_desc[qid]; 2110 else 2111 nb_rx_desc_tmp = rx_qinfo.nb_desc; 2112 2113 printf(" RX queue: %d\n", qid); 2114 printf(" RX desc=%d - RX free threshold=%d\n", 2115 nb_rx_desc_tmp, rx_conf[qid].rx_free_thresh); 2116 printf(" RX threshold registers: pthresh=%d hthresh=%d " 2117 " wthresh=%d\n", 2118 rx_conf[qid].rx_thresh.pthresh, 2119 rx_conf[qid].rx_thresh.hthresh, 2120 rx_conf[qid].rx_thresh.wthresh); 2121 printf(" RX Offloads=0x%"PRIx64"\n", 2122 rx_conf[qid].offloads); 2123 } 2124 2125 /* per tx queue config only for first queue to be less verbose */ 2126 for (qid = 0; qid < 1; qid++) { 2127 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo); 2128 if (rc) 2129 nb_tx_desc_tmp = nb_tx_desc[qid]; 2130 else 2131 nb_tx_desc_tmp = tx_qinfo.nb_desc; 2132 2133 printf(" TX queue: %d\n", qid); 2134 printf(" TX desc=%d - TX free threshold=%d\n", 2135 nb_tx_desc_tmp, tx_conf[qid].tx_free_thresh); 2136 printf(" TX threshold registers: pthresh=%d hthresh=%d " 2137 " wthresh=%d\n", 2138 tx_conf[qid].tx_thresh.pthresh, 2139 tx_conf[qid].tx_thresh.hthresh, 2140 tx_conf[qid].tx_thresh.wthresh); 2141 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n", 2142 tx_conf[qid].offloads, tx_conf->tx_rs_thresh); 2143 } 2144 } 2145 } 2146 2147 void 2148 port_rss_reta_info(portid_t port_id, 2149 struct rte_eth_rss_reta_entry64 *reta_conf, 2150 uint16_t nb_entries) 2151 { 2152 uint16_t i, idx, shift; 2153 int ret; 2154 2155 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2156 return; 2157 2158 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries); 2159 if (ret != 0) { 2160 printf("Failed to get RSS RETA info, return code = %d\n", ret); 2161 return; 2162 } 2163 2164 for (i = 0; i < nb_entries; i++) { 2165 idx = i / RTE_RETA_GROUP_SIZE; 2166 shift = i % RTE_RETA_GROUP_SIZE; 2167 if (!(reta_conf[idx].mask & (1ULL << shift))) 2168 continue; 2169 printf("RSS RETA configuration: hash index=%u, queue=%u\n", 2170 i, reta_conf[idx].reta[shift]); 2171 } 2172 } 2173 2174 /* 2175 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash 2176 * key of the port. 2177 */ 2178 void 2179 port_rss_hash_conf_show(portid_t port_id, int show_rss_key) 2180 { 2181 struct rte_eth_rss_conf rss_conf = {0}; 2182 uint8_t rss_key[RSS_HASH_KEY_LENGTH]; 2183 uint64_t rss_hf; 2184 uint8_t i; 2185 int diag; 2186 struct rte_eth_dev_info dev_info; 2187 uint8_t hash_key_size; 2188 int ret; 2189 2190 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2191 return; 2192 2193 ret = eth_dev_info_get_print_err(port_id, &dev_info); 2194 if (ret != 0) 2195 return; 2196 2197 if (dev_info.hash_key_size > 0 && 2198 dev_info.hash_key_size <= sizeof(rss_key)) 2199 hash_key_size = dev_info.hash_key_size; 2200 else { 2201 printf("dev_info did not provide a valid hash key size\n"); 2202 return; 2203 } 2204 2205 /* Get RSS hash key if asked to display it */ 2206 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL; 2207 rss_conf.rss_key_len = hash_key_size; 2208 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); 2209 if (diag != 0) { 2210 switch (diag) { 2211 case -ENODEV: 2212 printf("port index %d invalid\n", port_id); 2213 break; 2214 case -ENOTSUP: 2215 printf("operation not supported by device\n"); 2216 break; 2217 default: 2218 printf("operation failed - diag=%d\n", diag); 2219 break; 2220 } 2221 return; 2222 } 2223 rss_hf = rss_conf.rss_hf; 2224 if (rss_hf == 0) { 2225 printf("RSS disabled\n"); 2226 return; 2227 } 2228 printf("RSS functions:\n "); 2229 for (i = 0; rss_type_table[i].str; i++) { 2230 if (rss_hf & rss_type_table[i].rss_type) 2231 printf("%s ", rss_type_table[i].str); 2232 } 2233 printf("\n"); 2234 if (!show_rss_key) 2235 return; 2236 printf("RSS key:\n"); 2237 for (i = 0; i < hash_key_size; i++) 2238 printf("%02X", rss_key[i]); 2239 printf("\n"); 2240 } 2241 2242 void 2243 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key, 2244 uint hash_key_len) 2245 { 2246 struct rte_eth_rss_conf rss_conf; 2247 int diag; 2248 unsigned int i; 2249 2250 rss_conf.rss_key = NULL; 2251 rss_conf.rss_key_len = hash_key_len; 2252 rss_conf.rss_hf = 0; 2253 for (i = 0; rss_type_table[i].str; i++) { 2254 if (!strcmp(rss_type_table[i].str, rss_type)) 2255 rss_conf.rss_hf = rss_type_table[i].rss_type; 2256 } 2257 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); 2258 if (diag == 0) { 2259 rss_conf.rss_key = hash_key; 2260 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf); 2261 } 2262 if (diag == 0) 2263 return; 2264 2265 switch (diag) { 2266 case -ENODEV: 2267 printf("port index %d invalid\n", port_id); 2268 break; 2269 case -ENOTSUP: 2270 printf("operation not supported by device\n"); 2271 break; 2272 default: 2273 printf("operation failed - diag=%d\n", diag); 2274 break; 2275 } 2276 } 2277 2278 /* 2279 * Setup forwarding configuration for each logical core. 2280 */ 2281 static void 2282 setup_fwd_config_of_each_lcore(struct fwd_config *cfg) 2283 { 2284 streamid_t nb_fs_per_lcore; 2285 streamid_t nb_fs; 2286 streamid_t sm_id; 2287 lcoreid_t nb_extra; 2288 lcoreid_t nb_fc; 2289 lcoreid_t nb_lc; 2290 lcoreid_t lc_id; 2291 2292 nb_fs = cfg->nb_fwd_streams; 2293 nb_fc = cfg->nb_fwd_lcores; 2294 if (nb_fs <= nb_fc) { 2295 nb_fs_per_lcore = 1; 2296 nb_extra = 0; 2297 } else { 2298 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc); 2299 nb_extra = (lcoreid_t) (nb_fs % nb_fc); 2300 } 2301 2302 nb_lc = (lcoreid_t) (nb_fc - nb_extra); 2303 sm_id = 0; 2304 for (lc_id = 0; lc_id < nb_lc; lc_id++) { 2305 fwd_lcores[lc_id]->stream_idx = sm_id; 2306 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore; 2307 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore); 2308 } 2309 2310 /* 2311 * Assign extra remaining streams, if any. 2312 */ 2313 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1); 2314 for (lc_id = 0; lc_id < nb_extra; lc_id++) { 2315 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id; 2316 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore; 2317 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore); 2318 } 2319 } 2320 2321 static portid_t 2322 fwd_topology_tx_port_get(portid_t rxp) 2323 { 2324 static int warning_once = 1; 2325 2326 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports); 2327 2328 switch (port_topology) { 2329 default: 2330 case PORT_TOPOLOGY_PAIRED: 2331 if ((rxp & 0x1) == 0) { 2332 if (rxp + 1 < cur_fwd_config.nb_fwd_ports) 2333 return rxp + 1; 2334 if (warning_once) { 2335 printf("\nWarning! port-topology=paired" 2336 " and odd forward ports number," 2337 " the last port will pair with" 2338 " itself.\n\n"); 2339 warning_once = 0; 2340 } 2341 return rxp; 2342 } 2343 return rxp - 1; 2344 case PORT_TOPOLOGY_CHAINED: 2345 return (rxp + 1) % cur_fwd_config.nb_fwd_ports; 2346 case PORT_TOPOLOGY_LOOP: 2347 return rxp; 2348 } 2349 } 2350 2351 static void 2352 simple_fwd_config_setup(void) 2353 { 2354 portid_t i; 2355 2356 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports; 2357 cur_fwd_config.nb_fwd_streams = 2358 (streamid_t) cur_fwd_config.nb_fwd_ports; 2359 2360 /* reinitialize forwarding streams */ 2361 init_fwd_streams(); 2362 2363 /* 2364 * In the simple forwarding test, the number of forwarding cores 2365 * must be lower or equal to the number of forwarding ports. 2366 */ 2367 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores; 2368 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports) 2369 cur_fwd_config.nb_fwd_lcores = 2370 (lcoreid_t) cur_fwd_config.nb_fwd_ports; 2371 setup_fwd_config_of_each_lcore(&cur_fwd_config); 2372 2373 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) { 2374 fwd_streams[i]->rx_port = fwd_ports_ids[i]; 2375 fwd_streams[i]->rx_queue = 0; 2376 fwd_streams[i]->tx_port = 2377 fwd_ports_ids[fwd_topology_tx_port_get(i)]; 2378 fwd_streams[i]->tx_queue = 0; 2379 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port; 2380 fwd_streams[i]->retry_enabled = retry_enabled; 2381 } 2382 } 2383 2384 /** 2385 * For the RSS forwarding test all streams distributed over lcores. Each stream 2386 * being composed of a RX queue to poll on a RX port for input messages, 2387 * associated with a TX queue of a TX port where to send forwarded packets. 2388 */ 2389 static void 2390 rss_fwd_config_setup(void) 2391 { 2392 portid_t rxp; 2393 portid_t txp; 2394 queueid_t rxq; 2395 queueid_t nb_q; 2396 streamid_t sm_id; 2397 2398 nb_q = nb_rxq; 2399 if (nb_q > nb_txq) 2400 nb_q = nb_txq; 2401 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores; 2402 cur_fwd_config.nb_fwd_ports = nb_fwd_ports; 2403 cur_fwd_config.nb_fwd_streams = 2404 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports); 2405 2406 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores) 2407 cur_fwd_config.nb_fwd_lcores = 2408 (lcoreid_t)cur_fwd_config.nb_fwd_streams; 2409 2410 /* reinitialize forwarding streams */ 2411 init_fwd_streams(); 2412 2413 setup_fwd_config_of_each_lcore(&cur_fwd_config); 2414 rxp = 0; rxq = 0; 2415 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) { 2416 struct fwd_stream *fs; 2417 2418 fs = fwd_streams[sm_id]; 2419 txp = fwd_topology_tx_port_get(rxp); 2420 fs->rx_port = fwd_ports_ids[rxp]; 2421 fs->rx_queue = rxq; 2422 fs->tx_port = fwd_ports_ids[txp]; 2423 fs->tx_queue = rxq; 2424 fs->peer_addr = fs->tx_port; 2425 fs->retry_enabled = retry_enabled; 2426 rxp++; 2427 if (rxp < nb_fwd_ports) 2428 continue; 2429 rxp = 0; 2430 rxq++; 2431 } 2432 } 2433 2434 /** 2435 * For the DCB forwarding test, each core is assigned on each traffic class. 2436 * 2437 * Each core is assigned a multi-stream, each stream being composed of 2438 * a RX queue to poll on a RX port for input messages, associated with 2439 * a TX queue of a TX port where to send forwarded packets. All RX and 2440 * TX queues are mapping to the same traffic class. 2441 * If VMDQ and DCB co-exist, each traffic class on different POOLs share 2442 * the same core 2443 */ 2444 static void 2445 dcb_fwd_config_setup(void) 2446 { 2447 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info; 2448 portid_t txp, rxp = 0; 2449 queueid_t txq, rxq = 0; 2450 lcoreid_t lc_id; 2451 uint16_t nb_rx_queue, nb_tx_queue; 2452 uint16_t i, j, k, sm_id = 0; 2453 uint8_t tc = 0; 2454 2455 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores; 2456 cur_fwd_config.nb_fwd_ports = nb_fwd_ports; 2457 cur_fwd_config.nb_fwd_streams = 2458 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports); 2459 2460 /* reinitialize forwarding streams */ 2461 init_fwd_streams(); 2462 sm_id = 0; 2463 txp = 1; 2464 /* get the dcb info on the first RX and TX ports */ 2465 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info); 2466 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info); 2467 2468 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) { 2469 fwd_lcores[lc_id]->stream_nb = 0; 2470 fwd_lcores[lc_id]->stream_idx = sm_id; 2471 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) { 2472 /* if the nb_queue is zero, means this tc is 2473 * not enabled on the POOL 2474 */ 2475 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0) 2476 break; 2477 k = fwd_lcores[lc_id]->stream_nb + 2478 fwd_lcores[lc_id]->stream_idx; 2479 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base; 2480 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base; 2481 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue; 2482 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue; 2483 for (j = 0; j < nb_rx_queue; j++) { 2484 struct fwd_stream *fs; 2485 2486 fs = fwd_streams[k + j]; 2487 fs->rx_port = fwd_ports_ids[rxp]; 2488 fs->rx_queue = rxq + j; 2489 fs->tx_port = fwd_ports_ids[txp]; 2490 fs->tx_queue = txq + j % nb_tx_queue; 2491 fs->peer_addr = fs->tx_port; 2492 fs->retry_enabled = retry_enabled; 2493 } 2494 fwd_lcores[lc_id]->stream_nb += 2495 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue; 2496 } 2497 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb); 2498 2499 tc++; 2500 if (tc < rxp_dcb_info.nb_tcs) 2501 continue; 2502 /* Restart from TC 0 on next RX port */ 2503 tc = 0; 2504 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1))) 2505 rxp = (portid_t) 2506 (rxp + ((nb_ports >> 1) / nb_fwd_ports)); 2507 else 2508 rxp++; 2509 if (rxp >= nb_fwd_ports) 2510 return; 2511 /* get the dcb information on next RX and TX ports */ 2512 if ((rxp & 0x1) == 0) 2513 txp = (portid_t) (rxp + 1); 2514 else 2515 txp = (portid_t) (rxp - 1); 2516 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info); 2517 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info); 2518 } 2519 } 2520 2521 static void 2522 icmp_echo_config_setup(void) 2523 { 2524 portid_t rxp; 2525 queueid_t rxq; 2526 lcoreid_t lc_id; 2527 uint16_t sm_id; 2528 2529 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores) 2530 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) 2531 (nb_txq * nb_fwd_ports); 2532 else 2533 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores; 2534 cur_fwd_config.nb_fwd_ports = nb_fwd_ports; 2535 cur_fwd_config.nb_fwd_streams = 2536 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports); 2537 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores) 2538 cur_fwd_config.nb_fwd_lcores = 2539 (lcoreid_t)cur_fwd_config.nb_fwd_streams; 2540 if (verbose_level > 0) { 2541 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n", 2542 __FUNCTION__, 2543 cur_fwd_config.nb_fwd_lcores, 2544 cur_fwd_config.nb_fwd_ports, 2545 cur_fwd_config.nb_fwd_streams); 2546 } 2547 2548 /* reinitialize forwarding streams */ 2549 init_fwd_streams(); 2550 setup_fwd_config_of_each_lcore(&cur_fwd_config); 2551 rxp = 0; rxq = 0; 2552 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) { 2553 if (verbose_level > 0) 2554 printf(" core=%d: \n", lc_id); 2555 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) { 2556 struct fwd_stream *fs; 2557 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id]; 2558 fs->rx_port = fwd_ports_ids[rxp]; 2559 fs->rx_queue = rxq; 2560 fs->tx_port = fs->rx_port; 2561 fs->tx_queue = rxq; 2562 fs->peer_addr = fs->tx_port; 2563 fs->retry_enabled = retry_enabled; 2564 if (verbose_level > 0) 2565 printf(" stream=%d port=%d rxq=%d txq=%d\n", 2566 sm_id, fs->rx_port, fs->rx_queue, 2567 fs->tx_queue); 2568 rxq = (queueid_t) (rxq + 1); 2569 if (rxq == nb_rxq) { 2570 rxq = 0; 2571 rxp = (portid_t) (rxp + 1); 2572 } 2573 } 2574 } 2575 } 2576 2577 void 2578 fwd_config_setup(void) 2579 { 2580 cur_fwd_config.fwd_eng = cur_fwd_eng; 2581 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) { 2582 icmp_echo_config_setup(); 2583 return; 2584 } 2585 2586 if ((nb_rxq > 1) && (nb_txq > 1)){ 2587 if (dcb_config) 2588 dcb_fwd_config_setup(); 2589 else 2590 rss_fwd_config_setup(); 2591 } 2592 else 2593 simple_fwd_config_setup(); 2594 } 2595 2596 static const char * 2597 mp_alloc_to_str(uint8_t mode) 2598 { 2599 switch (mode) { 2600 case MP_ALLOC_NATIVE: 2601 return "native"; 2602 case MP_ALLOC_ANON: 2603 return "anon"; 2604 case MP_ALLOC_XMEM: 2605 return "xmem"; 2606 case MP_ALLOC_XMEM_HUGE: 2607 return "xmemhuge"; 2608 case MP_ALLOC_XBUF: 2609 return "xbuf"; 2610 default: 2611 return "invalid"; 2612 } 2613 } 2614 2615 void 2616 pkt_fwd_config_display(struct fwd_config *cfg) 2617 { 2618 struct fwd_stream *fs; 2619 lcoreid_t lc_id; 2620 streamid_t sm_id; 2621 2622 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - " 2623 "NUMA support %s, MP allocation mode: %s\n", 2624 cfg->fwd_eng->fwd_mode_name, 2625 retry_enabled == 0 ? "" : " with retry", 2626 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams, 2627 numa_support == 1 ? "enabled" : "disabled", 2628 mp_alloc_to_str(mp_alloc_type)); 2629 2630 if (retry_enabled) 2631 printf("TX retry num: %u, delay between TX retries: %uus\n", 2632 burst_tx_retry_num, burst_tx_delay_time); 2633 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) { 2634 printf("Logical Core %u (socket %u) forwards packets on " 2635 "%d streams:", 2636 fwd_lcores_cpuids[lc_id], 2637 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]), 2638 fwd_lcores[lc_id]->stream_nb); 2639 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) { 2640 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id]; 2641 printf("\n RX P=%d/Q=%d (socket %u) -> TX " 2642 "P=%d/Q=%d (socket %u) ", 2643 fs->rx_port, fs->rx_queue, 2644 ports[fs->rx_port].socket_id, 2645 fs->tx_port, fs->tx_queue, 2646 ports[fs->tx_port].socket_id); 2647 print_ethaddr("peer=", 2648 &peer_eth_addrs[fs->peer_addr]); 2649 } 2650 printf("\n"); 2651 } 2652 printf("\n"); 2653 } 2654 2655 void 2656 set_fwd_eth_peer(portid_t port_id, char *peer_addr) 2657 { 2658 struct rte_ether_addr new_peer_addr; 2659 if (!rte_eth_dev_is_valid_port(port_id)) { 2660 printf("Error: Invalid port number %i\n", port_id); 2661 return; 2662 } 2663 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) { 2664 printf("Error: Invalid ethernet address: %s\n", peer_addr); 2665 return; 2666 } 2667 peer_eth_addrs[port_id] = new_peer_addr; 2668 } 2669 2670 int 2671 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc) 2672 { 2673 unsigned int i; 2674 unsigned int lcore_cpuid; 2675 int record_now; 2676 2677 record_now = 0; 2678 again: 2679 for (i = 0; i < nb_lc; i++) { 2680 lcore_cpuid = lcorelist[i]; 2681 if (! rte_lcore_is_enabled(lcore_cpuid)) { 2682 printf("lcore %u not enabled\n", lcore_cpuid); 2683 return -1; 2684 } 2685 if (lcore_cpuid == rte_get_master_lcore()) { 2686 printf("lcore %u cannot be masked on for running " 2687 "packet forwarding, which is the master lcore " 2688 "and reserved for command line parsing only\n", 2689 lcore_cpuid); 2690 return -1; 2691 } 2692 if (record_now) 2693 fwd_lcores_cpuids[i] = lcore_cpuid; 2694 } 2695 if (record_now == 0) { 2696 record_now = 1; 2697 goto again; 2698 } 2699 nb_cfg_lcores = (lcoreid_t) nb_lc; 2700 if (nb_fwd_lcores != (lcoreid_t) nb_lc) { 2701 printf("previous number of forwarding cores %u - changed to " 2702 "number of configured cores %u\n", 2703 (unsigned int) nb_fwd_lcores, nb_lc); 2704 nb_fwd_lcores = (lcoreid_t) nb_lc; 2705 } 2706 2707 return 0; 2708 } 2709 2710 int 2711 set_fwd_lcores_mask(uint64_t lcoremask) 2712 { 2713 unsigned int lcorelist[64]; 2714 unsigned int nb_lc; 2715 unsigned int i; 2716 2717 if (lcoremask == 0) { 2718 printf("Invalid NULL mask of cores\n"); 2719 return -1; 2720 } 2721 nb_lc = 0; 2722 for (i = 0; i < 64; i++) { 2723 if (! ((uint64_t)(1ULL << i) & lcoremask)) 2724 continue; 2725 lcorelist[nb_lc++] = i; 2726 } 2727 return set_fwd_lcores_list(lcorelist, nb_lc); 2728 } 2729 2730 void 2731 set_fwd_lcores_number(uint16_t nb_lc) 2732 { 2733 if (nb_lc > nb_cfg_lcores) { 2734 printf("nb fwd cores %u > %u (max. number of configured " 2735 "lcores) - ignored\n", 2736 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores); 2737 return; 2738 } 2739 nb_fwd_lcores = (lcoreid_t) nb_lc; 2740 printf("Number of forwarding cores set to %u\n", 2741 (unsigned int) nb_fwd_lcores); 2742 } 2743 2744 void 2745 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt) 2746 { 2747 unsigned int i; 2748 portid_t port_id; 2749 int record_now; 2750 2751 record_now = 0; 2752 again: 2753 for (i = 0; i < nb_pt; i++) { 2754 port_id = (portid_t) portlist[i]; 2755 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2756 return; 2757 if (record_now) 2758 fwd_ports_ids[i] = port_id; 2759 } 2760 if (record_now == 0) { 2761 record_now = 1; 2762 goto again; 2763 } 2764 nb_cfg_ports = (portid_t) nb_pt; 2765 if (nb_fwd_ports != (portid_t) nb_pt) { 2766 printf("previous number of forwarding ports %u - changed to " 2767 "number of configured ports %u\n", 2768 (unsigned int) nb_fwd_ports, nb_pt); 2769 nb_fwd_ports = (portid_t) nb_pt; 2770 } 2771 } 2772 2773 /** 2774 * Parse the user input and obtain the list of forwarding ports 2775 * 2776 * @param[in] list 2777 * String containing the user input. User can specify 2778 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6. 2779 * For example, if the user wants to use all the available 2780 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3. 2781 * If the user wants to use only the ports 1,2 then the input 2782 * is 1,2. 2783 * valid characters are '-' and ',' 2784 * @param[out] values 2785 * This array will be filled with a list of port IDs 2786 * based on the user input 2787 * Note that duplicate entries are discarded and only the first 2788 * count entries in this array are port IDs and all the rest 2789 * will contain default values 2790 * @param[in] maxsize 2791 * This parameter denotes 2 things 2792 * 1) Number of elements in the values array 2793 * 2) Maximum value of each element in the values array 2794 * @return 2795 * On success, returns total count of parsed port IDs 2796 * On failure, returns 0 2797 */ 2798 static unsigned int 2799 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize) 2800 { 2801 unsigned int count = 0; 2802 char *end = NULL; 2803 int min, max; 2804 int value, i; 2805 unsigned int marked[maxsize]; 2806 2807 if (list == NULL || values == NULL) 2808 return 0; 2809 2810 for (i = 0; i < (int)maxsize; i++) 2811 marked[i] = 0; 2812 2813 min = INT_MAX; 2814 2815 do { 2816 /*Remove the blank spaces if any*/ 2817 while (isblank(*list)) 2818 list++; 2819 if (*list == '\0') 2820 break; 2821 errno = 0; 2822 value = strtol(list, &end, 10); 2823 if (errno || end == NULL) 2824 return 0; 2825 if (value < 0 || value >= (int)maxsize) 2826 return 0; 2827 while (isblank(*end)) 2828 end++; 2829 if (*end == '-' && min == INT_MAX) { 2830 min = value; 2831 } else if ((*end == ',') || (*end == '\0')) { 2832 max = value; 2833 if (min == INT_MAX) 2834 min = value; 2835 for (i = min; i <= max; i++) { 2836 if (count < maxsize) { 2837 if (marked[i]) 2838 continue; 2839 values[count] = i; 2840 marked[i] = 1; 2841 count++; 2842 } 2843 } 2844 min = INT_MAX; 2845 } else 2846 return 0; 2847 list = end + 1; 2848 } while (*end != '\0'); 2849 2850 return count; 2851 } 2852 2853 void 2854 parse_fwd_portlist(const char *portlist) 2855 { 2856 unsigned int portcount; 2857 unsigned int portindex[RTE_MAX_ETHPORTS]; 2858 unsigned int i, valid_port_count = 0; 2859 2860 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS); 2861 if (!portcount) 2862 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n"); 2863 2864 /* 2865 * Here we verify the validity of the ports 2866 * and thereby calculate the total number of 2867 * valid ports 2868 */ 2869 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) { 2870 if (rte_eth_dev_is_valid_port(portindex[i])) { 2871 portindex[valid_port_count] = portindex[i]; 2872 valid_port_count++; 2873 } 2874 } 2875 2876 set_fwd_ports_list(portindex, valid_port_count); 2877 } 2878 2879 void 2880 set_fwd_ports_mask(uint64_t portmask) 2881 { 2882 unsigned int portlist[64]; 2883 unsigned int nb_pt; 2884 unsigned int i; 2885 2886 if (portmask == 0) { 2887 printf("Invalid NULL mask of ports\n"); 2888 return; 2889 } 2890 nb_pt = 0; 2891 RTE_ETH_FOREACH_DEV(i) { 2892 if (! ((uint64_t)(1ULL << i) & portmask)) 2893 continue; 2894 portlist[nb_pt++] = i; 2895 } 2896 set_fwd_ports_list(portlist, nb_pt); 2897 } 2898 2899 void 2900 set_fwd_ports_number(uint16_t nb_pt) 2901 { 2902 if (nb_pt > nb_cfg_ports) { 2903 printf("nb fwd ports %u > %u (number of configured " 2904 "ports) - ignored\n", 2905 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports); 2906 return; 2907 } 2908 nb_fwd_ports = (portid_t) nb_pt; 2909 printf("Number of forwarding ports set to %u\n", 2910 (unsigned int) nb_fwd_ports); 2911 } 2912 2913 int 2914 port_is_forwarding(portid_t port_id) 2915 { 2916 unsigned int i; 2917 2918 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2919 return -1; 2920 2921 for (i = 0; i < nb_fwd_ports; i++) { 2922 if (fwd_ports_ids[i] == port_id) 2923 return 1; 2924 } 2925 2926 return 0; 2927 } 2928 2929 void 2930 set_nb_pkt_per_burst(uint16_t nb) 2931 { 2932 if (nb > MAX_PKT_BURST) { 2933 printf("nb pkt per burst: %u > %u (maximum packet per burst) " 2934 " ignored\n", 2935 (unsigned int) nb, (unsigned int) MAX_PKT_BURST); 2936 return; 2937 } 2938 nb_pkt_per_burst = nb; 2939 printf("Number of packets per burst set to %u\n", 2940 (unsigned int) nb_pkt_per_burst); 2941 } 2942 2943 static const char * 2944 tx_split_get_name(enum tx_pkt_split split) 2945 { 2946 uint32_t i; 2947 2948 for (i = 0; i != RTE_DIM(tx_split_name); i++) { 2949 if (tx_split_name[i].split == split) 2950 return tx_split_name[i].name; 2951 } 2952 return NULL; 2953 } 2954 2955 void 2956 set_tx_pkt_split(const char *name) 2957 { 2958 uint32_t i; 2959 2960 for (i = 0; i != RTE_DIM(tx_split_name); i++) { 2961 if (strcmp(tx_split_name[i].name, name) == 0) { 2962 tx_pkt_split = tx_split_name[i].split; 2963 return; 2964 } 2965 } 2966 printf("unknown value: \"%s\"\n", name); 2967 } 2968 2969 void 2970 show_tx_pkt_segments(void) 2971 { 2972 uint32_t i, n; 2973 const char *split; 2974 2975 n = tx_pkt_nb_segs; 2976 split = tx_split_get_name(tx_pkt_split); 2977 2978 printf("Number of segments: %u\n", n); 2979 printf("Segment sizes: "); 2980 for (i = 0; i != n - 1; i++) 2981 printf("%hu,", tx_pkt_seg_lengths[i]); 2982 printf("%hu\n", tx_pkt_seg_lengths[i]); 2983 printf("Split packet: %s\n", split); 2984 } 2985 2986 void 2987 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs) 2988 { 2989 uint16_t tx_pkt_len; 2990 unsigned i; 2991 2992 if (nb_segs >= (unsigned) nb_txd) { 2993 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n", 2994 nb_segs, (unsigned int) nb_txd); 2995 return; 2996 } 2997 2998 /* 2999 * Check that each segment length is greater or equal than 3000 * the mbuf data sise. 3001 * Check also that the total packet length is greater or equal than the 3002 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) + 3003 * 20 + 8). 3004 */ 3005 tx_pkt_len = 0; 3006 for (i = 0; i < nb_segs; i++) { 3007 if (seg_lengths[i] > (unsigned) mbuf_data_size) { 3008 printf("length[%u]=%u > mbuf_data_size=%u - give up\n", 3009 i, seg_lengths[i], (unsigned) mbuf_data_size); 3010 return; 3011 } 3012 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]); 3013 } 3014 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) { 3015 printf("total packet length=%u < %d - give up\n", 3016 (unsigned) tx_pkt_len, 3017 (int)(sizeof(struct rte_ether_hdr) + 20 + 8)); 3018 return; 3019 } 3020 3021 for (i = 0; i < nb_segs; i++) 3022 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i]; 3023 3024 tx_pkt_length = tx_pkt_len; 3025 tx_pkt_nb_segs = (uint8_t) nb_segs; 3026 } 3027 3028 void 3029 show_tx_pkt_times(void) 3030 { 3031 printf("Interburst gap: %u\n", tx_pkt_times_inter); 3032 printf("Intraburst gap: %u\n", tx_pkt_times_intra); 3033 } 3034 3035 void 3036 set_tx_pkt_times(unsigned int *tx_times) 3037 { 3038 uint16_t port_id; 3039 int offload_found = 0; 3040 int offset; 3041 int flag; 3042 3043 static const struct rte_mbuf_dynfield desc_offs = { 3044 .name = RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, 3045 .size = sizeof(uint64_t), 3046 .align = __alignof__(uint64_t), 3047 }; 3048 static const struct rte_mbuf_dynflag desc_flag = { 3049 .name = RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME, 3050 }; 3051 3052 RTE_ETH_FOREACH_DEV(port_id) { 3053 struct rte_eth_dev_info dev_info = { 0 }; 3054 int ret; 3055 3056 ret = rte_eth_dev_info_get(port_id, &dev_info); 3057 if (ret == 0 && dev_info.tx_offload_capa & 3058 DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) { 3059 offload_found = 1; 3060 break; 3061 } 3062 } 3063 if (!offload_found) { 3064 printf("No device supporting Tx timestamp scheduling found, " 3065 "dynamic flag and field not registered\n"); 3066 return; 3067 } 3068 offset = rte_mbuf_dynfield_register(&desc_offs); 3069 if (offset < 0 && rte_errno != EEXIST) 3070 printf("Dynamic timestamp field registration error: %d", 3071 rte_errno); 3072 flag = rte_mbuf_dynflag_register(&desc_flag); 3073 if (flag < 0 && rte_errno != EEXIST) 3074 printf("Dynamic timestamp flag registration error: %d", 3075 rte_errno); 3076 tx_pkt_times_inter = tx_times[0]; 3077 tx_pkt_times_intra = tx_times[1]; 3078 } 3079 3080 void 3081 setup_gro(const char *onoff, portid_t port_id) 3082 { 3083 if (!rte_eth_dev_is_valid_port(port_id)) { 3084 printf("invalid port id %u\n", port_id); 3085 return; 3086 } 3087 if (test_done == 0) { 3088 printf("Before enable/disable GRO," 3089 " please stop forwarding first\n"); 3090 return; 3091 } 3092 if (strcmp(onoff, "on") == 0) { 3093 if (gro_ports[port_id].enable != 0) { 3094 printf("Port %u has enabled GRO. Please" 3095 " disable GRO first\n", port_id); 3096 return; 3097 } 3098 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) { 3099 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4; 3100 gro_ports[port_id].param.max_flow_num = 3101 GRO_DEFAULT_FLOW_NUM; 3102 gro_ports[port_id].param.max_item_per_flow = 3103 GRO_DEFAULT_ITEM_NUM_PER_FLOW; 3104 } 3105 gro_ports[port_id].enable = 1; 3106 } else { 3107 if (gro_ports[port_id].enable == 0) { 3108 printf("Port %u has disabled GRO\n", port_id); 3109 return; 3110 } 3111 gro_ports[port_id].enable = 0; 3112 } 3113 } 3114 3115 void 3116 setup_gro_flush_cycles(uint8_t cycles) 3117 { 3118 if (test_done == 0) { 3119 printf("Before change flush interval for GRO," 3120 " please stop forwarding first.\n"); 3121 return; 3122 } 3123 3124 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles < 3125 GRO_DEFAULT_FLUSH_CYCLES) { 3126 printf("The flushing cycle be in the range" 3127 " of 1 to %u. Revert to the default" 3128 " value %u.\n", 3129 GRO_MAX_FLUSH_CYCLES, 3130 GRO_DEFAULT_FLUSH_CYCLES); 3131 cycles = GRO_DEFAULT_FLUSH_CYCLES; 3132 } 3133 3134 gro_flush_cycles = cycles; 3135 } 3136 3137 void 3138 show_gro(portid_t port_id) 3139 { 3140 struct rte_gro_param *param; 3141 uint32_t max_pkts_num; 3142 3143 param = &gro_ports[port_id].param; 3144 3145 if (!rte_eth_dev_is_valid_port(port_id)) { 3146 printf("Invalid port id %u.\n", port_id); 3147 return; 3148 } 3149 if (gro_ports[port_id].enable) { 3150 printf("GRO type: TCP/IPv4\n"); 3151 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) { 3152 max_pkts_num = param->max_flow_num * 3153 param->max_item_per_flow; 3154 } else 3155 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES; 3156 printf("Max number of packets to perform GRO: %u\n", 3157 max_pkts_num); 3158 printf("Flushing cycles: %u\n", gro_flush_cycles); 3159 } else 3160 printf("Port %u doesn't enable GRO.\n", port_id); 3161 } 3162 3163 void 3164 setup_gso(const char *mode, portid_t port_id) 3165 { 3166 if (!rte_eth_dev_is_valid_port(port_id)) { 3167 printf("invalid port id %u\n", port_id); 3168 return; 3169 } 3170 if (strcmp(mode, "on") == 0) { 3171 if (test_done == 0) { 3172 printf("before enabling GSO," 3173 " please stop forwarding first\n"); 3174 return; 3175 } 3176 gso_ports[port_id].enable = 1; 3177 } else if (strcmp(mode, "off") == 0) { 3178 if (test_done == 0) { 3179 printf("before disabling GSO," 3180 " please stop forwarding first\n"); 3181 return; 3182 } 3183 gso_ports[port_id].enable = 0; 3184 } 3185 } 3186 3187 char* 3188 list_pkt_forwarding_modes(void) 3189 { 3190 static char fwd_modes[128] = ""; 3191 const char *separator = "|"; 3192 struct fwd_engine *fwd_eng; 3193 unsigned i = 0; 3194 3195 if (strlen (fwd_modes) == 0) { 3196 while ((fwd_eng = fwd_engines[i++]) != NULL) { 3197 strncat(fwd_modes, fwd_eng->fwd_mode_name, 3198 sizeof(fwd_modes) - strlen(fwd_modes) - 1); 3199 strncat(fwd_modes, separator, 3200 sizeof(fwd_modes) - strlen(fwd_modes) - 1); 3201 } 3202 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0'; 3203 } 3204 3205 return fwd_modes; 3206 } 3207 3208 char* 3209 list_pkt_forwarding_retry_modes(void) 3210 { 3211 static char fwd_modes[128] = ""; 3212 const char *separator = "|"; 3213 struct fwd_engine *fwd_eng; 3214 unsigned i = 0; 3215 3216 if (strlen(fwd_modes) == 0) { 3217 while ((fwd_eng = fwd_engines[i++]) != NULL) { 3218 if (fwd_eng == &rx_only_engine) 3219 continue; 3220 strncat(fwd_modes, fwd_eng->fwd_mode_name, 3221 sizeof(fwd_modes) - 3222 strlen(fwd_modes) - 1); 3223 strncat(fwd_modes, separator, 3224 sizeof(fwd_modes) - 3225 strlen(fwd_modes) - 1); 3226 } 3227 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0'; 3228 } 3229 3230 return fwd_modes; 3231 } 3232 3233 void 3234 set_pkt_forwarding_mode(const char *fwd_mode_name) 3235 { 3236 struct fwd_engine *fwd_eng; 3237 unsigned i; 3238 3239 i = 0; 3240 while ((fwd_eng = fwd_engines[i]) != NULL) { 3241 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) { 3242 printf("Set %s packet forwarding mode%s\n", 3243 fwd_mode_name, 3244 retry_enabled == 0 ? "" : " with retry"); 3245 cur_fwd_eng = fwd_eng; 3246 return; 3247 } 3248 i++; 3249 } 3250 printf("Invalid %s packet forwarding mode\n", fwd_mode_name); 3251 } 3252 3253 void 3254 add_rx_dump_callbacks(portid_t portid) 3255 { 3256 struct rte_eth_dev_info dev_info; 3257 uint16_t queue; 3258 int ret; 3259 3260 if (port_id_is_invalid(portid, ENABLED_WARN)) 3261 return; 3262 3263 ret = eth_dev_info_get_print_err(portid, &dev_info); 3264 if (ret != 0) 3265 return; 3266 3267 for (queue = 0; queue < dev_info.nb_rx_queues; queue++) 3268 if (!ports[portid].rx_dump_cb[queue]) 3269 ports[portid].rx_dump_cb[queue] = 3270 rte_eth_add_rx_callback(portid, queue, 3271 dump_rx_pkts, NULL); 3272 } 3273 3274 void 3275 add_tx_dump_callbacks(portid_t portid) 3276 { 3277 struct rte_eth_dev_info dev_info; 3278 uint16_t queue; 3279 int ret; 3280 3281 if (port_id_is_invalid(portid, ENABLED_WARN)) 3282 return; 3283 3284 ret = eth_dev_info_get_print_err(portid, &dev_info); 3285 if (ret != 0) 3286 return; 3287 3288 for (queue = 0; queue < dev_info.nb_tx_queues; queue++) 3289 if (!ports[portid].tx_dump_cb[queue]) 3290 ports[portid].tx_dump_cb[queue] = 3291 rte_eth_add_tx_callback(portid, queue, 3292 dump_tx_pkts, NULL); 3293 } 3294 3295 void 3296 remove_rx_dump_callbacks(portid_t portid) 3297 { 3298 struct rte_eth_dev_info dev_info; 3299 uint16_t queue; 3300 int ret; 3301 3302 if (port_id_is_invalid(portid, ENABLED_WARN)) 3303 return; 3304 3305 ret = eth_dev_info_get_print_err(portid, &dev_info); 3306 if (ret != 0) 3307 return; 3308 3309 for (queue = 0; queue < dev_info.nb_rx_queues; queue++) 3310 if (ports[portid].rx_dump_cb[queue]) { 3311 rte_eth_remove_rx_callback(portid, queue, 3312 ports[portid].rx_dump_cb[queue]); 3313 ports[portid].rx_dump_cb[queue] = NULL; 3314 } 3315 } 3316 3317 void 3318 remove_tx_dump_callbacks(portid_t portid) 3319 { 3320 struct rte_eth_dev_info dev_info; 3321 uint16_t queue; 3322 int ret; 3323 3324 if (port_id_is_invalid(portid, ENABLED_WARN)) 3325 return; 3326 3327 ret = eth_dev_info_get_print_err(portid, &dev_info); 3328 if (ret != 0) 3329 return; 3330 3331 for (queue = 0; queue < dev_info.nb_tx_queues; queue++) 3332 if (ports[portid].tx_dump_cb[queue]) { 3333 rte_eth_remove_tx_callback(portid, queue, 3334 ports[portid].tx_dump_cb[queue]); 3335 ports[portid].tx_dump_cb[queue] = NULL; 3336 } 3337 } 3338 3339 void 3340 configure_rxtx_dump_callbacks(uint16_t verbose) 3341 { 3342 portid_t portid; 3343 3344 #ifndef RTE_ETHDEV_RXTX_CALLBACKS 3345 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n"); 3346 return; 3347 #endif 3348 3349 RTE_ETH_FOREACH_DEV(portid) 3350 { 3351 if (verbose == 1 || verbose > 2) 3352 add_rx_dump_callbacks(portid); 3353 else 3354 remove_rx_dump_callbacks(portid); 3355 if (verbose >= 2) 3356 add_tx_dump_callbacks(portid); 3357 else 3358 remove_tx_dump_callbacks(portid); 3359 } 3360 } 3361 3362 void 3363 set_verbose_level(uint16_t vb_level) 3364 { 3365 printf("Change verbose level from %u to %u\n", 3366 (unsigned int) verbose_level, (unsigned int) vb_level); 3367 verbose_level = vb_level; 3368 configure_rxtx_dump_callbacks(verbose_level); 3369 } 3370 3371 void 3372 vlan_extend_set(portid_t port_id, int on) 3373 { 3374 int diag; 3375 int vlan_offload; 3376 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads; 3377 3378 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3379 return; 3380 3381 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 3382 3383 if (on) { 3384 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD; 3385 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND; 3386 } else { 3387 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD; 3388 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND; 3389 } 3390 3391 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload); 3392 if (diag < 0) 3393 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed " 3394 "diag=%d\n", port_id, on, diag); 3395 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads; 3396 } 3397 3398 void 3399 rx_vlan_strip_set(portid_t port_id, int on) 3400 { 3401 int diag; 3402 int vlan_offload; 3403 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads; 3404 3405 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3406 return; 3407 3408 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 3409 3410 if (on) { 3411 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD; 3412 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP; 3413 } else { 3414 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD; 3415 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP; 3416 } 3417 3418 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload); 3419 if (diag < 0) 3420 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed " 3421 "diag=%d\n", port_id, on, diag); 3422 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads; 3423 } 3424 3425 void 3426 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on) 3427 { 3428 int diag; 3429 3430 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3431 return; 3432 3433 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on); 3434 if (diag < 0) 3435 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed " 3436 "diag=%d\n", port_id, queue_id, on, diag); 3437 } 3438 3439 void 3440 rx_vlan_filter_set(portid_t port_id, int on) 3441 { 3442 int diag; 3443 int vlan_offload; 3444 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads; 3445 3446 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3447 return; 3448 3449 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 3450 3451 if (on) { 3452 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD; 3453 port_rx_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER; 3454 } else { 3455 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD; 3456 port_rx_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER; 3457 } 3458 3459 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload); 3460 if (diag < 0) 3461 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed " 3462 "diag=%d\n", port_id, on, diag); 3463 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads; 3464 } 3465 3466 void 3467 rx_vlan_qinq_strip_set(portid_t port_id, int on) 3468 { 3469 int diag; 3470 int vlan_offload; 3471 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads; 3472 3473 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3474 return; 3475 3476 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 3477 3478 if (on) { 3479 vlan_offload |= ETH_QINQ_STRIP_OFFLOAD; 3480 port_rx_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP; 3481 } else { 3482 vlan_offload &= ~ETH_QINQ_STRIP_OFFLOAD; 3483 port_rx_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP; 3484 } 3485 3486 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload); 3487 if (diag < 0) 3488 printf("%s(port_pi=%d, on=%d) failed " 3489 "diag=%d\n", __func__, port_id, on, diag); 3490 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads; 3491 } 3492 3493 int 3494 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on) 3495 { 3496 int diag; 3497 3498 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3499 return 1; 3500 if (vlan_id_is_invalid(vlan_id)) 3501 return 1; 3502 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on); 3503 if (diag == 0) 3504 return 0; 3505 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed " 3506 "diag=%d\n", 3507 port_id, vlan_id, on, diag); 3508 return -1; 3509 } 3510 3511 void 3512 rx_vlan_all_filter_set(portid_t port_id, int on) 3513 { 3514 uint16_t vlan_id; 3515 3516 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3517 return; 3518 for (vlan_id = 0; vlan_id < 4096; vlan_id++) { 3519 if (rx_vft_set(port_id, vlan_id, on)) 3520 break; 3521 } 3522 } 3523 3524 void 3525 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id) 3526 { 3527 int diag; 3528 3529 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3530 return; 3531 3532 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id); 3533 if (diag == 0) 3534 return; 3535 3536 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed " 3537 "diag=%d\n", 3538 port_id, vlan_type, tp_id, diag); 3539 } 3540 3541 void 3542 tx_vlan_set(portid_t port_id, uint16_t vlan_id) 3543 { 3544 struct rte_eth_dev_info dev_info; 3545 int ret; 3546 3547 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3548 return; 3549 if (vlan_id_is_invalid(vlan_id)) 3550 return; 3551 3552 if (ports[port_id].dev_conf.txmode.offloads & 3553 DEV_TX_OFFLOAD_QINQ_INSERT) { 3554 printf("Error, as QinQ has been enabled.\n"); 3555 return; 3556 } 3557 3558 ret = eth_dev_info_get_print_err(port_id, &dev_info); 3559 if (ret != 0) 3560 return; 3561 3562 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) == 0) { 3563 printf("Error: vlan insert is not supported by port %d\n", 3564 port_id); 3565 return; 3566 } 3567 3568 tx_vlan_reset(port_id); 3569 ports[port_id].dev_conf.txmode.offloads |= DEV_TX_OFFLOAD_VLAN_INSERT; 3570 ports[port_id].tx_vlan_id = vlan_id; 3571 } 3572 3573 void 3574 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer) 3575 { 3576 struct rte_eth_dev_info dev_info; 3577 int ret; 3578 3579 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3580 return; 3581 if (vlan_id_is_invalid(vlan_id)) 3582 return; 3583 if (vlan_id_is_invalid(vlan_id_outer)) 3584 return; 3585 3586 ret = eth_dev_info_get_print_err(port_id, &dev_info); 3587 if (ret != 0) 3588 return; 3589 3590 if ((dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) == 0) { 3591 printf("Error: qinq insert not supported by port %d\n", 3592 port_id); 3593 return; 3594 } 3595 3596 tx_vlan_reset(port_id); 3597 ports[port_id].dev_conf.txmode.offloads |= (DEV_TX_OFFLOAD_VLAN_INSERT | 3598 DEV_TX_OFFLOAD_QINQ_INSERT); 3599 ports[port_id].tx_vlan_id = vlan_id; 3600 ports[port_id].tx_vlan_id_outer = vlan_id_outer; 3601 } 3602 3603 void 3604 tx_vlan_reset(portid_t port_id) 3605 { 3606 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3607 return; 3608 ports[port_id].dev_conf.txmode.offloads &= 3609 ~(DEV_TX_OFFLOAD_VLAN_INSERT | 3610 DEV_TX_OFFLOAD_QINQ_INSERT); 3611 ports[port_id].tx_vlan_id = 0; 3612 ports[port_id].tx_vlan_id_outer = 0; 3613 } 3614 3615 void 3616 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on) 3617 { 3618 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3619 return; 3620 3621 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on); 3622 } 3623 3624 void 3625 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value) 3626 { 3627 uint16_t i; 3628 uint8_t existing_mapping_found = 0; 3629 3630 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3631 return; 3632 3633 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id))) 3634 return; 3635 3636 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) { 3637 printf("map_value not in required range 0..%d\n", 3638 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1); 3639 return; 3640 } 3641 3642 if (!is_rx) { /*then tx*/ 3643 for (i = 0; i < nb_tx_queue_stats_mappings; i++) { 3644 if ((tx_queue_stats_mappings[i].port_id == port_id) && 3645 (tx_queue_stats_mappings[i].queue_id == queue_id)) { 3646 tx_queue_stats_mappings[i].stats_counter_id = map_value; 3647 existing_mapping_found = 1; 3648 break; 3649 } 3650 } 3651 if (!existing_mapping_found) { /* A new additional mapping... */ 3652 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id; 3653 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id; 3654 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value; 3655 nb_tx_queue_stats_mappings++; 3656 } 3657 } 3658 else { /*rx*/ 3659 for (i = 0; i < nb_rx_queue_stats_mappings; i++) { 3660 if ((rx_queue_stats_mappings[i].port_id == port_id) && 3661 (rx_queue_stats_mappings[i].queue_id == queue_id)) { 3662 rx_queue_stats_mappings[i].stats_counter_id = map_value; 3663 existing_mapping_found = 1; 3664 break; 3665 } 3666 } 3667 if (!existing_mapping_found) { /* A new additional mapping... */ 3668 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id; 3669 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id; 3670 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value; 3671 nb_rx_queue_stats_mappings++; 3672 } 3673 } 3674 } 3675 3676 void 3677 set_xstats_hide_zero(uint8_t on_off) 3678 { 3679 xstats_hide_zero = on_off; 3680 } 3681 3682 static inline void 3683 print_fdir_mask(struct rte_eth_fdir_masks *mask) 3684 { 3685 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask)); 3686 3687 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) 3688 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x," 3689 " tunnel_id: 0x%08x", 3690 mask->mac_addr_byte_mask, mask->tunnel_type_mask, 3691 rte_be_to_cpu_32(mask->tunnel_id_mask)); 3692 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 3693 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x", 3694 rte_be_to_cpu_32(mask->ipv4_mask.src_ip), 3695 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip)); 3696 3697 printf("\n src_port: 0x%04x, dst_port: 0x%04x", 3698 rte_be_to_cpu_16(mask->src_port_mask), 3699 rte_be_to_cpu_16(mask->dst_port_mask)); 3700 3701 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x", 3702 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]), 3703 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]), 3704 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]), 3705 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3])); 3706 3707 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x", 3708 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]), 3709 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]), 3710 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]), 3711 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3])); 3712 } 3713 3714 printf("\n"); 3715 } 3716 3717 static inline void 3718 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num) 3719 { 3720 struct rte_eth_flex_payload_cfg *cfg; 3721 uint32_t i, j; 3722 3723 for (i = 0; i < flex_conf->nb_payloads; i++) { 3724 cfg = &flex_conf->flex_set[i]; 3725 if (cfg->type == RTE_ETH_RAW_PAYLOAD) 3726 printf("\n RAW: "); 3727 else if (cfg->type == RTE_ETH_L2_PAYLOAD) 3728 printf("\n L2_PAYLOAD: "); 3729 else if (cfg->type == RTE_ETH_L3_PAYLOAD) 3730 printf("\n L3_PAYLOAD: "); 3731 else if (cfg->type == RTE_ETH_L4_PAYLOAD) 3732 printf("\n L4_PAYLOAD: "); 3733 else 3734 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type); 3735 for (j = 0; j < num; j++) 3736 printf(" %-5u", cfg->src_offset[j]); 3737 } 3738 printf("\n"); 3739 } 3740 3741 static char * 3742 flowtype_to_str(uint16_t flow_type) 3743 { 3744 struct flow_type_info { 3745 char str[32]; 3746 uint16_t ftype; 3747 }; 3748 3749 uint8_t i; 3750 static struct flow_type_info flowtype_str_table[] = { 3751 {"raw", RTE_ETH_FLOW_RAW}, 3752 {"ipv4", RTE_ETH_FLOW_IPV4}, 3753 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 3754 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 3755 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 3756 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 3757 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 3758 {"ipv6", RTE_ETH_FLOW_IPV6}, 3759 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 3760 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 3761 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 3762 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 3763 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 3764 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 3765 {"port", RTE_ETH_FLOW_PORT}, 3766 {"vxlan", RTE_ETH_FLOW_VXLAN}, 3767 {"geneve", RTE_ETH_FLOW_GENEVE}, 3768 {"nvgre", RTE_ETH_FLOW_NVGRE}, 3769 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE}, 3770 }; 3771 3772 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) { 3773 if (flowtype_str_table[i].ftype == flow_type) 3774 return flowtype_str_table[i].str; 3775 } 3776 3777 return NULL; 3778 } 3779 3780 static inline void 3781 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num) 3782 { 3783 struct rte_eth_fdir_flex_mask *mask; 3784 uint32_t i, j; 3785 char *p; 3786 3787 for (i = 0; i < flex_conf->nb_flexmasks; i++) { 3788 mask = &flex_conf->flex_mask[i]; 3789 p = flowtype_to_str(mask->flow_type); 3790 printf("\n %s:\t", p ? p : "unknown"); 3791 for (j = 0; j < num; j++) 3792 printf(" %02x", mask->mask[j]); 3793 } 3794 printf("\n"); 3795 } 3796 3797 static inline void 3798 print_fdir_flow_type(uint32_t flow_types_mask) 3799 { 3800 int i; 3801 char *p; 3802 3803 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) { 3804 if (!(flow_types_mask & (1 << i))) 3805 continue; 3806 p = flowtype_to_str(i); 3807 if (p) 3808 printf(" %s", p); 3809 else 3810 printf(" unknown"); 3811 } 3812 printf("\n"); 3813 } 3814 3815 static int 3816 get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info, 3817 struct rte_eth_fdir_stats *fdir_stat) 3818 { 3819 int ret; 3820 3821 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR); 3822 if (!ret) { 3823 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR, 3824 RTE_ETH_FILTER_INFO, fdir_info); 3825 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR, 3826 RTE_ETH_FILTER_STATS, fdir_stat); 3827 return 0; 3828 } 3829 3830 #ifdef RTE_LIBRTE_I40E_PMD 3831 if (ret == -ENOTSUP) { 3832 ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info); 3833 if (!ret) 3834 ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat); 3835 } 3836 #endif 3837 #ifdef RTE_LIBRTE_IXGBE_PMD 3838 if (ret == -ENOTSUP) { 3839 ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info); 3840 if (!ret) 3841 ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat); 3842 } 3843 #endif 3844 switch (ret) { 3845 case 0: 3846 break; 3847 case -ENOTSUP: 3848 printf("\n FDIR is not supported on port %-2d\n", 3849 port_id); 3850 break; 3851 default: 3852 printf("programming error: (%s)\n", strerror(-ret)); 3853 break; 3854 } 3855 return ret; 3856 } 3857 3858 void 3859 fdir_get_infos(portid_t port_id) 3860 { 3861 struct rte_eth_fdir_stats fdir_stat; 3862 struct rte_eth_fdir_info fdir_info; 3863 3864 static const char *fdir_stats_border = "########################"; 3865 3866 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3867 return; 3868 3869 memset(&fdir_info, 0, sizeof(fdir_info)); 3870 memset(&fdir_stat, 0, sizeof(fdir_stat)); 3871 if (get_fdir_info(port_id, &fdir_info, &fdir_stat)) 3872 return; 3873 3874 printf("\n %s FDIR infos for port %-2d %s\n", 3875 fdir_stats_border, port_id, fdir_stats_border); 3876 printf(" MODE: "); 3877 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT) 3878 printf(" PERFECT\n"); 3879 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) 3880 printf(" PERFECT-MAC-VLAN\n"); 3881 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) 3882 printf(" PERFECT-TUNNEL\n"); 3883 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE) 3884 printf(" SIGNATURE\n"); 3885 else 3886 printf(" DISABLE\n"); 3887 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN 3888 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) { 3889 printf(" SUPPORTED FLOW TYPE: "); 3890 print_fdir_flow_type(fdir_info.flow_types_mask[0]); 3891 } 3892 printf(" FLEX PAYLOAD INFO:\n"); 3893 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n" 3894 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n" 3895 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n", 3896 fdir_info.max_flexpayload, fdir_info.flex_payload_limit, 3897 fdir_info.flex_payload_unit, 3898 fdir_info.max_flex_payload_segment_num, 3899 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num); 3900 printf(" MASK: "); 3901 print_fdir_mask(&fdir_info.mask); 3902 if (fdir_info.flex_conf.nb_payloads > 0) { 3903 printf(" FLEX PAYLOAD SRC OFFSET:"); 3904 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload); 3905 } 3906 if (fdir_info.flex_conf.nb_flexmasks > 0) { 3907 printf(" FLEX MASK CFG:"); 3908 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload); 3909 } 3910 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n", 3911 fdir_stat.guarant_cnt, fdir_stat.best_cnt); 3912 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n", 3913 fdir_info.guarant_spc, fdir_info.best_spc); 3914 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n" 3915 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n" 3916 " add: %-10"PRIu64" remove: %"PRIu64"\n" 3917 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n", 3918 fdir_stat.collision, fdir_stat.free, 3919 fdir_stat.maxhash, fdir_stat.maxlen, 3920 fdir_stat.add, fdir_stat.remove, 3921 fdir_stat.f_add, fdir_stat.f_remove); 3922 printf(" %s############################%s\n", 3923 fdir_stats_border, fdir_stats_border); 3924 } 3925 3926 void 3927 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg) 3928 { 3929 struct rte_port *port; 3930 struct rte_eth_fdir_flex_conf *flex_conf; 3931 int i, idx = 0; 3932 3933 port = &ports[port_id]; 3934 flex_conf = &port->dev_conf.fdir_conf.flex_conf; 3935 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) { 3936 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) { 3937 idx = i; 3938 break; 3939 } 3940 } 3941 if (i >= RTE_ETH_FLOW_MAX) { 3942 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) { 3943 idx = flex_conf->nb_flexmasks; 3944 flex_conf->nb_flexmasks++; 3945 } else { 3946 printf("The flex mask table is full. Can not set flex" 3947 " mask for flow_type(%u).", cfg->flow_type); 3948 return; 3949 } 3950 } 3951 rte_memcpy(&flex_conf->flex_mask[idx], 3952 cfg, 3953 sizeof(struct rte_eth_fdir_flex_mask)); 3954 } 3955 3956 void 3957 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg) 3958 { 3959 struct rte_port *port; 3960 struct rte_eth_fdir_flex_conf *flex_conf; 3961 int i, idx = 0; 3962 3963 port = &ports[port_id]; 3964 flex_conf = &port->dev_conf.fdir_conf.flex_conf; 3965 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) { 3966 if (cfg->type == flex_conf->flex_set[i].type) { 3967 idx = i; 3968 break; 3969 } 3970 } 3971 if (i >= RTE_ETH_PAYLOAD_MAX) { 3972 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) { 3973 idx = flex_conf->nb_payloads; 3974 flex_conf->nb_payloads++; 3975 } else { 3976 printf("The flex payload table is full. Can not set" 3977 " flex payload for type(%u).", cfg->type); 3978 return; 3979 } 3980 } 3981 rte_memcpy(&flex_conf->flex_set[idx], 3982 cfg, 3983 sizeof(struct rte_eth_flex_payload_cfg)); 3984 3985 } 3986 3987 void 3988 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on) 3989 { 3990 #ifdef RTE_LIBRTE_IXGBE_PMD 3991 int diag; 3992 3993 if (is_rx) 3994 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on); 3995 else 3996 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on); 3997 3998 if (diag == 0) 3999 return; 4000 printf("rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n", 4001 is_rx ? "rx" : "tx", port_id, diag); 4002 return; 4003 #endif 4004 printf("VF %s setting not supported for port %d\n", 4005 is_rx ? "Rx" : "Tx", port_id); 4006 RTE_SET_USED(vf); 4007 RTE_SET_USED(on); 4008 } 4009 4010 int 4011 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate) 4012 { 4013 int diag; 4014 struct rte_eth_link link; 4015 int ret; 4016 4017 if (port_id_is_invalid(port_id, ENABLED_WARN)) 4018 return 1; 4019 ret = eth_link_get_nowait_print_err(port_id, &link); 4020 if (ret < 0) 4021 return 1; 4022 if (rate > link.link_speed) { 4023 printf("Invalid rate value:%u bigger than link speed: %u\n", 4024 rate, link.link_speed); 4025 return 1; 4026 } 4027 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate); 4028 if (diag == 0) 4029 return diag; 4030 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n", 4031 port_id, diag); 4032 return diag; 4033 } 4034 4035 int 4036 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk) 4037 { 4038 int diag = -ENOTSUP; 4039 4040 RTE_SET_USED(vf); 4041 RTE_SET_USED(rate); 4042 RTE_SET_USED(q_msk); 4043 4044 #ifdef RTE_LIBRTE_IXGBE_PMD 4045 if (diag == -ENOTSUP) 4046 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate, 4047 q_msk); 4048 #endif 4049 #ifdef RTE_LIBRTE_BNXT_PMD 4050 if (diag == -ENOTSUP) 4051 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk); 4052 #endif 4053 if (diag == 0) 4054 return diag; 4055 4056 printf("set_vf_rate_limit for port_id=%d failed diag=%d\n", 4057 port_id, diag); 4058 return diag; 4059 } 4060 4061 /* 4062 * Functions to manage the set of filtered Multicast MAC addresses. 4063 * 4064 * A pool of filtered multicast MAC addresses is associated with each port. 4065 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses. 4066 * The address of the pool and the number of valid multicast MAC addresses 4067 * recorded in the pool are stored in the fields "mc_addr_pool" and 4068 * "mc_addr_nb" of the "rte_port" data structure. 4069 * 4070 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes 4071 * to be supplied a contiguous array of multicast MAC addresses. 4072 * To comply with this constraint, the set of multicast addresses recorded 4073 * into the pool are systematically compacted at the beginning of the pool. 4074 * Hence, when a multicast address is removed from the pool, all following 4075 * addresses, if any, are copied back to keep the set contiguous. 4076 */ 4077 #define MCAST_POOL_INC 32 4078 4079 static int 4080 mcast_addr_pool_extend(struct rte_port *port) 4081 { 4082 struct rte_ether_addr *mc_pool; 4083 size_t mc_pool_size; 4084 4085 /* 4086 * If a free entry is available at the end of the pool, just 4087 * increment the number of recorded multicast addresses. 4088 */ 4089 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) { 4090 port->mc_addr_nb++; 4091 return 0; 4092 } 4093 4094 /* 4095 * [re]allocate a pool with MCAST_POOL_INC more entries. 4096 * The previous test guarantees that port->mc_addr_nb is a multiple 4097 * of MCAST_POOL_INC. 4098 */ 4099 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb + 4100 MCAST_POOL_INC); 4101 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool, 4102 mc_pool_size); 4103 if (mc_pool == NULL) { 4104 printf("allocation of pool of %u multicast addresses failed\n", 4105 port->mc_addr_nb + MCAST_POOL_INC); 4106 return -ENOMEM; 4107 } 4108 4109 port->mc_addr_pool = mc_pool; 4110 port->mc_addr_nb++; 4111 return 0; 4112 4113 } 4114 4115 static void 4116 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr) 4117 { 4118 if (mcast_addr_pool_extend(port) != 0) 4119 return; 4120 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]); 4121 } 4122 4123 static void 4124 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx) 4125 { 4126 port->mc_addr_nb--; 4127 if (addr_idx == port->mc_addr_nb) { 4128 /* No need to recompact the set of multicast addressses. */ 4129 if (port->mc_addr_nb == 0) { 4130 /* free the pool of multicast addresses. */ 4131 free(port->mc_addr_pool); 4132 port->mc_addr_pool = NULL; 4133 } 4134 return; 4135 } 4136 memmove(&port->mc_addr_pool[addr_idx], 4137 &port->mc_addr_pool[addr_idx + 1], 4138 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx)); 4139 } 4140 4141 static int 4142 eth_port_multicast_addr_list_set(portid_t port_id) 4143 { 4144 struct rte_port *port; 4145 int diag; 4146 4147 port = &ports[port_id]; 4148 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool, 4149 port->mc_addr_nb); 4150 if (diag < 0) 4151 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n", 4152 port_id, port->mc_addr_nb, diag); 4153 4154 return diag; 4155 } 4156 4157 void 4158 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr) 4159 { 4160 struct rte_port *port; 4161 uint32_t i; 4162 4163 if (port_id_is_invalid(port_id, ENABLED_WARN)) 4164 return; 4165 4166 port = &ports[port_id]; 4167 4168 /* 4169 * Check that the added multicast MAC address is not already recorded 4170 * in the pool of multicast addresses. 4171 */ 4172 for (i = 0; i < port->mc_addr_nb; i++) { 4173 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) { 4174 printf("multicast address already filtered by port\n"); 4175 return; 4176 } 4177 } 4178 4179 mcast_addr_pool_append(port, mc_addr); 4180 if (eth_port_multicast_addr_list_set(port_id) < 0) 4181 /* Rollback on failure, remove the address from the pool */ 4182 mcast_addr_pool_remove(port, i); 4183 } 4184 4185 void 4186 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr) 4187 { 4188 struct rte_port *port; 4189 uint32_t i; 4190 4191 if (port_id_is_invalid(port_id, ENABLED_WARN)) 4192 return; 4193 4194 port = &ports[port_id]; 4195 4196 /* 4197 * Search the pool of multicast MAC addresses for the removed address. 4198 */ 4199 for (i = 0; i < port->mc_addr_nb; i++) { 4200 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) 4201 break; 4202 } 4203 if (i == port->mc_addr_nb) { 4204 printf("multicast address not filtered by port %d\n", port_id); 4205 return; 4206 } 4207 4208 mcast_addr_pool_remove(port, i); 4209 if (eth_port_multicast_addr_list_set(port_id) < 0) 4210 /* Rollback on failure, add the address back into the pool */ 4211 mcast_addr_pool_append(port, mc_addr); 4212 } 4213 4214 void 4215 port_dcb_info_display(portid_t port_id) 4216 { 4217 struct rte_eth_dcb_info dcb_info; 4218 uint16_t i; 4219 int ret; 4220 static const char *border = "================"; 4221 4222 if (port_id_is_invalid(port_id, ENABLED_WARN)) 4223 return; 4224 4225 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info); 4226 if (ret) { 4227 printf("\n Failed to get dcb infos on port %-2d\n", 4228 port_id); 4229 return; 4230 } 4231 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border); 4232 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs); 4233 printf("\n TC : "); 4234 for (i = 0; i < dcb_info.nb_tcs; i++) 4235 printf("\t%4d", i); 4236 printf("\n Priority : "); 4237 for (i = 0; i < dcb_info.nb_tcs; i++) 4238 printf("\t%4d", dcb_info.prio_tc[i]); 4239 printf("\n BW percent :"); 4240 for (i = 0; i < dcb_info.nb_tcs; i++) 4241 printf("\t%4d%%", dcb_info.tc_bws[i]); 4242 printf("\n RXQ base : "); 4243 for (i = 0; i < dcb_info.nb_tcs; i++) 4244 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base); 4245 printf("\n RXQ number :"); 4246 for (i = 0; i < dcb_info.nb_tcs; i++) 4247 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue); 4248 printf("\n TXQ base : "); 4249 for (i = 0; i < dcb_info.nb_tcs; i++) 4250 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base); 4251 printf("\n TXQ number :"); 4252 for (i = 0; i < dcb_info.nb_tcs; i++) 4253 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue); 4254 printf("\n"); 4255 } 4256 4257 uint8_t * 4258 open_file(const char *file_path, uint32_t *size) 4259 { 4260 int fd = open(file_path, O_RDONLY); 4261 off_t pkg_size; 4262 uint8_t *buf = NULL; 4263 int ret = 0; 4264 struct stat st_buf; 4265 4266 if (size) 4267 *size = 0; 4268 4269 if (fd == -1) { 4270 printf("%s: Failed to open %s\n", __func__, file_path); 4271 return buf; 4272 } 4273 4274 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) { 4275 close(fd); 4276 printf("%s: File operations failed\n", __func__); 4277 return buf; 4278 } 4279 4280 pkg_size = st_buf.st_size; 4281 if (pkg_size < 0) { 4282 close(fd); 4283 printf("%s: File operations failed\n", __func__); 4284 return buf; 4285 } 4286 4287 buf = (uint8_t *)malloc(pkg_size); 4288 if (!buf) { 4289 close(fd); 4290 printf("%s: Failed to malloc memory\n", __func__); 4291 return buf; 4292 } 4293 4294 ret = read(fd, buf, pkg_size); 4295 if (ret < 0) { 4296 close(fd); 4297 printf("%s: File read operation failed\n", __func__); 4298 close_file(buf); 4299 return NULL; 4300 } 4301 4302 if (size) 4303 *size = pkg_size; 4304 4305 close(fd); 4306 4307 return buf; 4308 } 4309 4310 int 4311 save_file(const char *file_path, uint8_t *buf, uint32_t size) 4312 { 4313 FILE *fh = fopen(file_path, "wb"); 4314 4315 if (fh == NULL) { 4316 printf("%s: Failed to open %s\n", __func__, file_path); 4317 return -1; 4318 } 4319 4320 if (fwrite(buf, 1, size, fh) != size) { 4321 fclose(fh); 4322 printf("%s: File write operation failed\n", __func__); 4323 return -1; 4324 } 4325 4326 fclose(fh); 4327 4328 return 0; 4329 } 4330 4331 int 4332 close_file(uint8_t *buf) 4333 { 4334 if (buf) { 4335 free((void *)buf); 4336 return 0; 4337 } 4338 4339 return -1; 4340 } 4341 4342 void 4343 port_queue_region_info_display(portid_t port_id, void *buf) 4344 { 4345 #ifdef RTE_LIBRTE_I40E_PMD 4346 uint16_t i, j; 4347 struct rte_pmd_i40e_queue_regions *info = 4348 (struct rte_pmd_i40e_queue_regions *)buf; 4349 static const char *queue_region_info_stats_border = "-------"; 4350 4351 if (!info->queue_region_number) 4352 printf("there is no region has been set before"); 4353 4354 printf("\n %s All queue region info for port=%2d %s", 4355 queue_region_info_stats_border, port_id, 4356 queue_region_info_stats_border); 4357 printf("\n queue_region_number: %-14u \n", 4358 info->queue_region_number); 4359 4360 for (i = 0; i < info->queue_region_number; i++) { 4361 printf("\n region_id: %-14u queue_number: %-14u " 4362 "queue_start_index: %-14u \n", 4363 info->region[i].region_id, 4364 info->region[i].queue_num, 4365 info->region[i].queue_start_index); 4366 4367 printf(" user_priority_num is %-14u :", 4368 info->region[i].user_priority_num); 4369 for (j = 0; j < info->region[i].user_priority_num; j++) 4370 printf(" %-14u ", info->region[i].user_priority[j]); 4371 4372 printf("\n flowtype_num is %-14u :", 4373 info->region[i].flowtype_num); 4374 for (j = 0; j < info->region[i].flowtype_num; j++) 4375 printf(" %-14u ", info->region[i].hw_flowtype[j]); 4376 } 4377 #else 4378 RTE_SET_USED(port_id); 4379 RTE_SET_USED(buf); 4380 #endif 4381 4382 printf("\n\n"); 4383 } 4384 4385 void 4386 show_macs(portid_t port_id) 4387 { 4388 char buf[RTE_ETHER_ADDR_FMT_SIZE]; 4389 struct rte_eth_dev_info dev_info; 4390 struct rte_ether_addr *addr; 4391 uint32_t i, num_macs = 0; 4392 struct rte_eth_dev *dev; 4393 4394 dev = &rte_eth_devices[port_id]; 4395 4396 rte_eth_dev_info_get(port_id, &dev_info); 4397 4398 for (i = 0; i < dev_info.max_mac_addrs; i++) { 4399 addr = &dev->data->mac_addrs[i]; 4400 4401 /* skip zero address */ 4402 if (rte_is_zero_ether_addr(addr)) 4403 continue; 4404 4405 num_macs++; 4406 } 4407 4408 printf("Number of MAC address added: %d\n", num_macs); 4409 4410 for (i = 0; i < dev_info.max_mac_addrs; i++) { 4411 addr = &dev->data->mac_addrs[i]; 4412 4413 /* skip zero address */ 4414 if (rte_is_zero_ether_addr(addr)) 4415 continue; 4416 4417 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr); 4418 printf(" %s\n", buf); 4419 } 4420 } 4421 4422 void 4423 show_mcast_macs(portid_t port_id) 4424 { 4425 char buf[RTE_ETHER_ADDR_FMT_SIZE]; 4426 struct rte_ether_addr *addr; 4427 struct rte_port *port; 4428 uint32_t i; 4429 4430 port = &ports[port_id]; 4431 4432 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb); 4433 4434 for (i = 0; i < port->mc_addr_nb; i++) { 4435 addr = &port->mc_addr_pool[i]; 4436 4437 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr); 4438 printf(" %s\n", buf); 4439 } 4440 } 4441