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