1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 /* BSD LICENSE 34 * 35 * Copyright 2013-2014 6WIND S.A. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 41 * * Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * * Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in 45 * the documentation and/or other materials provided with the 46 * distribution. 47 * * Neither the name of 6WIND S.A. nor the names of its 48 * contributors may be used to endorse or promote products derived 49 * from this software without specific prior written permission. 50 * 51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 */ 63 64 #include <stdarg.h> 65 #include <errno.h> 66 #include <stdio.h> 67 #include <string.h> 68 #include <stdarg.h> 69 #include <stdint.h> 70 #include <inttypes.h> 71 72 #include <sys/queue.h> 73 74 #include <rte_common.h> 75 #include <rte_byteorder.h> 76 #include <rte_debug.h> 77 #include <rte_log.h> 78 #include <rte_memory.h> 79 #include <rte_memcpy.h> 80 #include <rte_memzone.h> 81 #include <rte_launch.h> 82 #include <rte_eal.h> 83 #include <rte_per_lcore.h> 84 #include <rte_lcore.h> 85 #include <rte_atomic.h> 86 #include <rte_branch_prediction.h> 87 #include <rte_mempool.h> 88 #include <rte_mbuf.h> 89 #include <rte_interrupts.h> 90 #include <rte_pci.h> 91 #include <rte_ether.h> 92 #include <rte_ethdev.h> 93 #include <rte_string_fns.h> 94 #include <rte_cycles.h> 95 #include <rte_flow.h> 96 #include <rte_errno.h> 97 #ifdef RTE_LIBRTE_IXGBE_PMD 98 #include <rte_pmd_ixgbe.h> 99 #endif 100 101 #include "testpmd.h" 102 103 static char *flowtype_to_str(uint16_t flow_type); 104 105 static const struct { 106 enum tx_pkt_split split; 107 const char *name; 108 } tx_split_name[] = { 109 { 110 .split = TX_PKT_SPLIT_OFF, 111 .name = "off", 112 }, 113 { 114 .split = TX_PKT_SPLIT_ON, 115 .name = "on", 116 }, 117 { 118 .split = TX_PKT_SPLIT_RND, 119 .name = "rand", 120 }, 121 }; 122 123 struct rss_type_info { 124 char str[32]; 125 uint64_t rss_type; 126 }; 127 128 static const struct rss_type_info rss_type_table[] = { 129 { "ipv4", ETH_RSS_IPV4 }, 130 { "ipv4-frag", ETH_RSS_FRAG_IPV4 }, 131 { "ipv4-tcp", ETH_RSS_NONFRAG_IPV4_TCP }, 132 { "ipv4-udp", ETH_RSS_NONFRAG_IPV4_UDP }, 133 { "ipv4-sctp", ETH_RSS_NONFRAG_IPV4_SCTP }, 134 { "ipv4-other", ETH_RSS_NONFRAG_IPV4_OTHER }, 135 { "ipv6", ETH_RSS_IPV6 }, 136 { "ipv6-frag", ETH_RSS_FRAG_IPV6 }, 137 { "ipv6-tcp", ETH_RSS_NONFRAG_IPV6_TCP }, 138 { "ipv6-udp", ETH_RSS_NONFRAG_IPV6_UDP }, 139 { "ipv6-sctp", ETH_RSS_NONFRAG_IPV6_SCTP }, 140 { "ipv6-other", ETH_RSS_NONFRAG_IPV6_OTHER }, 141 { "l2-payload", ETH_RSS_L2_PAYLOAD }, 142 { "ipv6-ex", ETH_RSS_IPV6_EX }, 143 { "ipv6-tcp-ex", ETH_RSS_IPV6_TCP_EX }, 144 { "ipv6-udp-ex", ETH_RSS_IPV6_UDP_EX }, 145 { "port", ETH_RSS_PORT }, 146 { "vxlan", ETH_RSS_VXLAN }, 147 { "geneve", ETH_RSS_GENEVE }, 148 { "nvgre", ETH_RSS_NVGRE }, 149 150 }; 151 152 static void 153 print_ethaddr(const char *name, struct ether_addr *eth_addr) 154 { 155 char buf[ETHER_ADDR_FMT_SIZE]; 156 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr); 157 printf("%s%s", name, buf); 158 } 159 160 void 161 nic_stats_display(portid_t port_id) 162 { 163 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS]; 164 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS]; 165 static uint64_t prev_cycles[RTE_MAX_ETHPORTS]; 166 uint64_t diff_pkts_rx, diff_pkts_tx, diff_cycles; 167 uint64_t mpps_rx, mpps_tx; 168 struct rte_eth_stats stats; 169 struct rte_port *port = &ports[port_id]; 170 uint8_t i; 171 portid_t pid; 172 173 static const char *nic_stats_border = "########################"; 174 175 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 176 printf("Valid port range is [0"); 177 RTE_ETH_FOREACH_DEV(pid) 178 printf(", %d", pid); 179 printf("]\n"); 180 return; 181 } 182 rte_eth_stats_get(port_id, &stats); 183 printf("\n %s NIC statistics for port %-2d %s\n", 184 nic_stats_border, port_id, nic_stats_border); 185 186 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) { 187 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: " 188 "%-"PRIu64"\n", 189 stats.ipackets, stats.imissed, stats.ibytes); 190 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors); 191 printf(" RX-nombuf: %-10"PRIu64"\n", 192 stats.rx_nombuf); 193 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: " 194 "%-"PRIu64"\n", 195 stats.opackets, stats.oerrors, stats.obytes); 196 } 197 else { 198 printf(" RX-packets: %10"PRIu64" RX-errors: %10"PRIu64 199 " RX-bytes: %10"PRIu64"\n", 200 stats.ipackets, stats.ierrors, stats.ibytes); 201 printf(" RX-errors: %10"PRIu64"\n", stats.ierrors); 202 printf(" RX-nombuf: %10"PRIu64"\n", 203 stats.rx_nombuf); 204 printf(" TX-packets: %10"PRIu64" TX-errors: %10"PRIu64 205 " TX-bytes: %10"PRIu64"\n", 206 stats.opackets, stats.oerrors, stats.obytes); 207 } 208 209 if (port->rx_queue_stats_mapping_enabled) { 210 printf("\n"); 211 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) { 212 printf(" Stats reg %2d RX-packets: %10"PRIu64 213 " RX-errors: %10"PRIu64 214 " RX-bytes: %10"PRIu64"\n", 215 i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]); 216 } 217 } 218 if (port->tx_queue_stats_mapping_enabled) { 219 printf("\n"); 220 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) { 221 printf(" Stats reg %2d TX-packets: %10"PRIu64 222 " TX-bytes: %10"PRIu64"\n", 223 i, stats.q_opackets[i], stats.q_obytes[i]); 224 } 225 } 226 227 diff_cycles = prev_cycles[port_id]; 228 prev_cycles[port_id] = rte_rdtsc(); 229 if (diff_cycles > 0) 230 diff_cycles = prev_cycles[port_id] - diff_cycles; 231 232 diff_pkts_rx = stats.ipackets - prev_pkts_rx[port_id]; 233 diff_pkts_tx = stats.opackets - prev_pkts_tx[port_id]; 234 prev_pkts_rx[port_id] = stats.ipackets; 235 prev_pkts_tx[port_id] = stats.opackets; 236 mpps_rx = diff_cycles > 0 ? 237 diff_pkts_rx * rte_get_tsc_hz() / diff_cycles : 0; 238 mpps_tx = diff_cycles > 0 ? 239 diff_pkts_tx * rte_get_tsc_hz() / diff_cycles : 0; 240 printf("\n Throughput (since last show)\n"); 241 printf(" Rx-pps: %12"PRIu64"\n Tx-pps: %12"PRIu64"\n", 242 mpps_rx, mpps_tx); 243 244 printf(" %s############################%s\n", 245 nic_stats_border, nic_stats_border); 246 } 247 248 void 249 nic_stats_clear(portid_t port_id) 250 { 251 portid_t pid; 252 253 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 254 printf("Valid port range is [0"); 255 RTE_ETH_FOREACH_DEV(pid) 256 printf(", %d", pid); 257 printf("]\n"); 258 return; 259 } 260 rte_eth_stats_reset(port_id); 261 printf("\n NIC statistics for port %d cleared\n", port_id); 262 } 263 264 void 265 nic_xstats_display(portid_t port_id) 266 { 267 int cnt_xstats, idx_xstat; 268 struct rte_eth_xstat_name *xstats_names; 269 uint64_t *values; 270 271 printf("###### NIC extended statistics for port %-2d\n", port_id); 272 if (!rte_eth_dev_is_valid_port(port_id)) { 273 printf("Error: Invalid port number %i\n", port_id); 274 return; 275 } 276 277 /* Get count */ 278 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0, NULL); 279 if (cnt_xstats < 0) { 280 printf("Error: Cannot get count of xstats\n"); 281 return; 282 } 283 284 /* Get id-name lookup table */ 285 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats); 286 if (xstats_names == NULL) { 287 printf("Cannot allocate memory for xstats lookup\n"); 288 return; 289 } 290 if (cnt_xstats != rte_eth_xstats_get_names( 291 port_id, xstats_names, cnt_xstats, NULL)) { 292 printf("Error: Cannot get xstats lookup\n"); 293 free(xstats_names); 294 return; 295 } 296 297 /* Get stats themselves */ 298 values = malloc(sizeof(values) * cnt_xstats); 299 if (values == NULL) { 300 printf("Cannot allocate memory for xstats\n"); 301 free(xstats_names); 302 return; 303 } 304 if (cnt_xstats != rte_eth_xstats_get(port_id, NULL, values, 305 cnt_xstats)) { 306 printf("Error: Unable to get xstats\n"); 307 free(xstats_names); 308 free(values); 309 return; 310 } 311 312 /* Display xstats */ 313 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) 314 printf("%s: %"PRIu64"\n", 315 xstats_names[idx_xstat].name, 316 values[idx_xstat]); 317 free(xstats_names); 318 free(values); 319 } 320 321 void 322 nic_xstats_clear(portid_t port_id) 323 { 324 rte_eth_xstats_reset(port_id); 325 } 326 327 void 328 nic_stats_mapping_display(portid_t port_id) 329 { 330 struct rte_port *port = &ports[port_id]; 331 uint16_t i; 332 portid_t pid; 333 334 static const char *nic_stats_mapping_border = "########################"; 335 336 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 337 printf("Valid port range is [0"); 338 RTE_ETH_FOREACH_DEV(pid) 339 printf(", %d", pid); 340 printf("]\n"); 341 return; 342 } 343 344 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) { 345 printf("Port id %d - either does not support queue statistic mapping or" 346 " no queue statistic mapping set\n", port_id); 347 return; 348 } 349 350 printf("\n %s NIC statistics mapping for port %-2d %s\n", 351 nic_stats_mapping_border, port_id, nic_stats_mapping_border); 352 353 if (port->rx_queue_stats_mapping_enabled) { 354 for (i = 0; i < nb_rx_queue_stats_mappings; i++) { 355 if (rx_queue_stats_mappings[i].port_id == port_id) { 356 printf(" RX-queue %2d mapped to Stats Reg %2d\n", 357 rx_queue_stats_mappings[i].queue_id, 358 rx_queue_stats_mappings[i].stats_counter_id); 359 } 360 } 361 printf("\n"); 362 } 363 364 365 if (port->tx_queue_stats_mapping_enabled) { 366 for (i = 0; i < nb_tx_queue_stats_mappings; i++) { 367 if (tx_queue_stats_mappings[i].port_id == port_id) { 368 printf(" TX-queue %2d mapped to Stats Reg %2d\n", 369 tx_queue_stats_mappings[i].queue_id, 370 tx_queue_stats_mappings[i].stats_counter_id); 371 } 372 } 373 } 374 375 printf(" %s####################################%s\n", 376 nic_stats_mapping_border, nic_stats_mapping_border); 377 } 378 379 void 380 rx_queue_infos_display(portid_t port_id, uint16_t queue_id) 381 { 382 struct rte_eth_rxq_info qinfo; 383 int32_t rc; 384 static const char *info_border = "*********************"; 385 386 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo); 387 if (rc != 0) { 388 printf("Failed to retrieve information for port: %hhu, " 389 "RX queue: %hu\nerror desc: %s(%d)\n", 390 port_id, queue_id, strerror(-rc), rc); 391 return; 392 } 393 394 printf("\n%s Infos for port %-2u, RX queue %-2u %s", 395 info_border, port_id, queue_id, info_border); 396 397 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name); 398 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh); 399 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh); 400 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh); 401 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh); 402 printf("\nRX drop packets: %s", 403 (qinfo.conf.rx_drop_en != 0) ? "on" : "off"); 404 printf("\nRX deferred start: %s", 405 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off"); 406 printf("\nRX scattered packets: %s", 407 (qinfo.scattered_rx != 0) ? "on" : "off"); 408 printf("\nNumber of RXDs: %hu", qinfo.nb_desc); 409 printf("\n"); 410 } 411 412 void 413 tx_queue_infos_display(portid_t port_id, uint16_t queue_id) 414 { 415 struct rte_eth_txq_info qinfo; 416 int32_t rc; 417 static const char *info_border = "*********************"; 418 419 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo); 420 if (rc != 0) { 421 printf("Failed to retrieve information for port: %hhu, " 422 "TX queue: %hu\nerror desc: %s(%d)\n", 423 port_id, queue_id, strerror(-rc), rc); 424 return; 425 } 426 427 printf("\n%s Infos for port %-2u, TX queue %-2u %s", 428 info_border, port_id, queue_id, info_border); 429 430 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh); 431 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh); 432 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh); 433 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh); 434 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh); 435 printf("\nTX flags: %#x", qinfo.conf.txq_flags); 436 printf("\nTX deferred start: %s", 437 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off"); 438 printf("\nNumber of TXDs: %hu", qinfo.nb_desc); 439 printf("\n"); 440 } 441 442 void 443 port_infos_display(portid_t port_id) 444 { 445 struct rte_port *port; 446 struct ether_addr mac_addr; 447 struct rte_eth_link link; 448 struct rte_eth_dev_info dev_info; 449 int vlan_offload; 450 struct rte_mempool * mp; 451 static const char *info_border = "*********************"; 452 portid_t pid; 453 uint16_t mtu; 454 455 if (port_id_is_invalid(port_id, ENABLED_WARN)) { 456 printf("Valid port range is [0"); 457 RTE_ETH_FOREACH_DEV(pid) 458 printf(", %d", pid); 459 printf("]\n"); 460 return; 461 } 462 port = &ports[port_id]; 463 rte_eth_link_get_nowait(port_id, &link); 464 memset(&dev_info, 0, sizeof(dev_info)); 465 rte_eth_dev_info_get(port_id, &dev_info); 466 printf("\n%s Infos for port %-2d %s\n", 467 info_border, port_id, info_border); 468 rte_eth_macaddr_get(port_id, &mac_addr); 469 print_ethaddr("MAC address: ", &mac_addr); 470 printf("\nDriver name: %s", dev_info.driver_name); 471 printf("\nConnect to socket: %u", port->socket_id); 472 473 if (port_numa[port_id] != NUMA_NO_CONFIG) { 474 mp = mbuf_pool_find(port_numa[port_id]); 475 if (mp) 476 printf("\nmemory allocation on the socket: %d", 477 port_numa[port_id]); 478 } else 479 printf("\nmemory allocation on the socket: %u",port->socket_id); 480 481 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down")); 482 printf("Link speed: %u Mbps\n", (unsigned) link.link_speed); 483 printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? 484 ("full-duplex") : ("half-duplex")); 485 486 if (!rte_eth_dev_get_mtu(port_id, &mtu)) 487 printf("MTU: %u\n", mtu); 488 489 printf("Promiscuous mode: %s\n", 490 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled"); 491 printf("Allmulticast mode: %s\n", 492 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled"); 493 printf("Maximum number of MAC addresses: %u\n", 494 (unsigned int)(port->dev_info.max_mac_addrs)); 495 printf("Maximum number of MAC addresses of hash filtering: %u\n", 496 (unsigned int)(port->dev_info.max_hash_mac_addrs)); 497 498 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 499 if (vlan_offload >= 0){ 500 printf("VLAN offload: \n"); 501 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD) 502 printf(" strip on \n"); 503 else 504 printf(" strip off \n"); 505 506 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD) 507 printf(" filter on \n"); 508 else 509 printf(" filter off \n"); 510 511 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) 512 printf(" qinq(extend) on \n"); 513 else 514 printf(" qinq(extend) off \n"); 515 } 516 517 if (dev_info.hash_key_size > 0) 518 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size); 519 if (dev_info.reta_size > 0) 520 printf("Redirection table size: %u\n", dev_info.reta_size); 521 if (!dev_info.flow_type_rss_offloads) 522 printf("No flow type is supported.\n"); 523 else { 524 uint16_t i; 525 char *p; 526 527 printf("Supported flow types:\n"); 528 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX; 529 i++) { 530 if (!(dev_info.flow_type_rss_offloads & (1ULL << i))) 531 continue; 532 p = flowtype_to_str(i); 533 printf(" %s\n", (p ? p : "unknown")); 534 } 535 } 536 537 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues); 538 printf("Max possible number of RXDs per queue: %hu\n", 539 dev_info.rx_desc_lim.nb_max); 540 printf("Min possible number of RXDs per queue: %hu\n", 541 dev_info.rx_desc_lim.nb_min); 542 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align); 543 544 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues); 545 printf("Max possible number of TXDs per queue: %hu\n", 546 dev_info.tx_desc_lim.nb_max); 547 printf("Min possible number of TXDs per queue: %hu\n", 548 dev_info.tx_desc_lim.nb_min); 549 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align); 550 } 551 552 void 553 port_offload_cap_display(portid_t port_id) 554 { 555 struct rte_eth_dev *dev; 556 struct rte_eth_dev_info dev_info; 557 static const char *info_border = "************"; 558 559 if (port_id_is_invalid(port_id, ENABLED_WARN)) 560 return; 561 562 dev = &rte_eth_devices[port_id]; 563 rte_eth_dev_info_get(port_id, &dev_info); 564 565 printf("\n%s Port %d supported offload features: %s\n", 566 info_border, port_id, info_border); 567 568 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) { 569 printf("VLAN stripped: "); 570 if (dev->data->dev_conf.rxmode.hw_vlan_strip) 571 printf("on\n"); 572 else 573 printf("off\n"); 574 } 575 576 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) { 577 printf("Double VLANs stripped: "); 578 if (dev->data->dev_conf.rxmode.hw_vlan_extend) 579 printf("on\n"); 580 else 581 printf("off\n"); 582 } 583 584 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) { 585 printf("RX IPv4 checksum: "); 586 if (dev->data->dev_conf.rxmode.hw_ip_checksum) 587 printf("on\n"); 588 else 589 printf("off\n"); 590 } 591 592 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) { 593 printf("RX UDP checksum: "); 594 if (dev->data->dev_conf.rxmode.hw_ip_checksum) 595 printf("on\n"); 596 else 597 printf("off\n"); 598 } 599 600 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) { 601 printf("RX TCP checksum: "); 602 if (dev->data->dev_conf.rxmode.hw_ip_checksum) 603 printf("on\n"); 604 else 605 printf("off\n"); 606 } 607 608 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM) 609 printf("RX Outer IPv4 checksum: on"); 610 611 if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) { 612 printf("Large receive offload: "); 613 if (dev->data->dev_conf.rxmode.enable_lro) 614 printf("on\n"); 615 else 616 printf("off\n"); 617 } 618 619 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) { 620 printf("VLAN insert: "); 621 if (ports[port_id].tx_ol_flags & 622 TESTPMD_TX_OFFLOAD_INSERT_VLAN) 623 printf("on\n"); 624 else 625 printf("off\n"); 626 } 627 628 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) { 629 printf("Double VLANs insert: "); 630 if (ports[port_id].tx_ol_flags & 631 TESTPMD_TX_OFFLOAD_INSERT_QINQ) 632 printf("on\n"); 633 else 634 printf("off\n"); 635 } 636 637 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) { 638 printf("TX IPv4 checksum: "); 639 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) 640 printf("on\n"); 641 else 642 printf("off\n"); 643 } 644 645 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) { 646 printf("TX UDP checksum: "); 647 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) 648 printf("on\n"); 649 else 650 printf("off\n"); 651 } 652 653 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) { 654 printf("TX TCP checksum: "); 655 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) 656 printf("on\n"); 657 else 658 printf("off\n"); 659 } 660 661 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) { 662 printf("TX SCTP checksum: "); 663 if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) 664 printf("on\n"); 665 else 666 printf("off\n"); 667 } 668 669 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) { 670 printf("TX Outer IPv4 checksum: "); 671 if (ports[port_id].tx_ol_flags & 672 TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) 673 printf("on\n"); 674 else 675 printf("off\n"); 676 } 677 678 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) { 679 printf("TX TCP segmentation: "); 680 if (ports[port_id].tso_segsz != 0) 681 printf("on\n"); 682 else 683 printf("off\n"); 684 } 685 686 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) { 687 printf("TX UDP segmentation: "); 688 if (ports[port_id].tso_segsz != 0) 689 printf("on\n"); 690 else 691 printf("off\n"); 692 } 693 694 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) { 695 printf("TSO for VXLAN tunnel packet: "); 696 if (ports[port_id].tunnel_tso_segsz) 697 printf("on\n"); 698 else 699 printf("off\n"); 700 } 701 702 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) { 703 printf("TSO for GRE tunnel packet: "); 704 if (ports[port_id].tunnel_tso_segsz) 705 printf("on\n"); 706 else 707 printf("off\n"); 708 } 709 710 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) { 711 printf("TSO for IPIP tunnel packet: "); 712 if (ports[port_id].tunnel_tso_segsz) 713 printf("on\n"); 714 else 715 printf("off\n"); 716 } 717 718 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) { 719 printf("TSO for GENEVE tunnel packet: "); 720 if (ports[port_id].tunnel_tso_segsz) 721 printf("on\n"); 722 else 723 printf("off\n"); 724 } 725 726 } 727 728 int 729 port_id_is_invalid(portid_t port_id, enum print_warning warning) 730 { 731 if (port_id == (portid_t)RTE_PORT_ALL) 732 return 0; 733 734 if (rte_eth_dev_is_valid_port(port_id)) 735 return 0; 736 737 if (warning == ENABLED_WARN) 738 printf("Invalid port %d\n", port_id); 739 740 return 1; 741 } 742 743 static int 744 vlan_id_is_invalid(uint16_t vlan_id) 745 { 746 if (vlan_id < 4096) 747 return 0; 748 printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id); 749 return 1; 750 } 751 752 static int 753 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off) 754 { 755 uint64_t pci_len; 756 757 if (reg_off & 0x3) { 758 printf("Port register offset 0x%X not aligned on a 4-byte " 759 "boundary\n", 760 (unsigned)reg_off); 761 return 1; 762 } 763 pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len; 764 if (reg_off >= pci_len) { 765 printf("Port %d: register offset %u (0x%X) out of port PCI " 766 "resource (length=%"PRIu64")\n", 767 port_id, (unsigned)reg_off, (unsigned)reg_off, pci_len); 768 return 1; 769 } 770 return 0; 771 } 772 773 static int 774 reg_bit_pos_is_invalid(uint8_t bit_pos) 775 { 776 if (bit_pos <= 31) 777 return 0; 778 printf("Invalid bit position %d (must be <= 31)\n", bit_pos); 779 return 1; 780 } 781 782 #define display_port_and_reg_off(port_id, reg_off) \ 783 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off)) 784 785 static inline void 786 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v) 787 { 788 display_port_and_reg_off(port_id, (unsigned)reg_off); 789 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v); 790 } 791 792 void 793 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x) 794 { 795 uint32_t reg_v; 796 797 798 if (port_id_is_invalid(port_id, ENABLED_WARN)) 799 return; 800 if (port_reg_off_is_invalid(port_id, reg_off)) 801 return; 802 if (reg_bit_pos_is_invalid(bit_x)) 803 return; 804 reg_v = port_id_pci_reg_read(port_id, reg_off); 805 display_port_and_reg_off(port_id, (unsigned)reg_off); 806 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x)); 807 } 808 809 void 810 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off, 811 uint8_t bit1_pos, uint8_t bit2_pos) 812 { 813 uint32_t reg_v; 814 uint8_t l_bit; 815 uint8_t h_bit; 816 817 if (port_id_is_invalid(port_id, ENABLED_WARN)) 818 return; 819 if (port_reg_off_is_invalid(port_id, reg_off)) 820 return; 821 if (reg_bit_pos_is_invalid(bit1_pos)) 822 return; 823 if (reg_bit_pos_is_invalid(bit2_pos)) 824 return; 825 if (bit1_pos > bit2_pos) 826 l_bit = bit2_pos, h_bit = bit1_pos; 827 else 828 l_bit = bit1_pos, h_bit = bit2_pos; 829 830 reg_v = port_id_pci_reg_read(port_id, reg_off); 831 reg_v >>= l_bit; 832 if (h_bit < 31) 833 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1); 834 display_port_and_reg_off(port_id, (unsigned)reg_off); 835 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit, 836 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v); 837 } 838 839 void 840 port_reg_display(portid_t port_id, uint32_t reg_off) 841 { 842 uint32_t reg_v; 843 844 if (port_id_is_invalid(port_id, ENABLED_WARN)) 845 return; 846 if (port_reg_off_is_invalid(port_id, reg_off)) 847 return; 848 reg_v = port_id_pci_reg_read(port_id, reg_off); 849 display_port_reg_value(port_id, reg_off, reg_v); 850 } 851 852 void 853 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos, 854 uint8_t bit_v) 855 { 856 uint32_t reg_v; 857 858 if (port_id_is_invalid(port_id, ENABLED_WARN)) 859 return; 860 if (port_reg_off_is_invalid(port_id, reg_off)) 861 return; 862 if (reg_bit_pos_is_invalid(bit_pos)) 863 return; 864 if (bit_v > 1) { 865 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v); 866 return; 867 } 868 reg_v = port_id_pci_reg_read(port_id, reg_off); 869 if (bit_v == 0) 870 reg_v &= ~(1 << bit_pos); 871 else 872 reg_v |= (1 << bit_pos); 873 port_id_pci_reg_write(port_id, reg_off, reg_v); 874 display_port_reg_value(port_id, reg_off, reg_v); 875 } 876 877 void 878 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off, 879 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value) 880 { 881 uint32_t max_v; 882 uint32_t reg_v; 883 uint8_t l_bit; 884 uint8_t h_bit; 885 886 if (port_id_is_invalid(port_id, ENABLED_WARN)) 887 return; 888 if (port_reg_off_is_invalid(port_id, reg_off)) 889 return; 890 if (reg_bit_pos_is_invalid(bit1_pos)) 891 return; 892 if (reg_bit_pos_is_invalid(bit2_pos)) 893 return; 894 if (bit1_pos > bit2_pos) 895 l_bit = bit2_pos, h_bit = bit1_pos; 896 else 897 l_bit = bit1_pos, h_bit = bit2_pos; 898 899 if ((h_bit - l_bit) < 31) 900 max_v = (1 << (h_bit - l_bit + 1)) - 1; 901 else 902 max_v = 0xFFFFFFFF; 903 904 if (value > max_v) { 905 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n", 906 (unsigned)value, (unsigned)value, 907 (unsigned)max_v, (unsigned)max_v); 908 return; 909 } 910 reg_v = port_id_pci_reg_read(port_id, reg_off); 911 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */ 912 reg_v |= (value << l_bit); /* Set changed bits */ 913 port_id_pci_reg_write(port_id, reg_off, reg_v); 914 display_port_reg_value(port_id, reg_off, reg_v); 915 } 916 917 void 918 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v) 919 { 920 if (port_id_is_invalid(port_id, ENABLED_WARN)) 921 return; 922 if (port_reg_off_is_invalid(port_id, reg_off)) 923 return; 924 port_id_pci_reg_write(port_id, reg_off, reg_v); 925 display_port_reg_value(port_id, reg_off, reg_v); 926 } 927 928 void 929 port_mtu_set(portid_t port_id, uint16_t mtu) 930 { 931 int diag; 932 933 if (port_id_is_invalid(port_id, ENABLED_WARN)) 934 return; 935 diag = rte_eth_dev_set_mtu(port_id, mtu); 936 if (diag == 0) 937 return; 938 printf("Set MTU failed. diag=%d\n", diag); 939 } 940 941 /* Generic flow management functions. */ 942 943 /** Generate flow_item[] entry. */ 944 #define MK_FLOW_ITEM(t, s) \ 945 [RTE_FLOW_ITEM_TYPE_ ## t] = { \ 946 .name = # t, \ 947 .size = s, \ 948 } 949 950 /** Information about known flow pattern items. */ 951 static const struct { 952 const char *name; 953 size_t size; 954 } flow_item[] = { 955 MK_FLOW_ITEM(END, 0), 956 MK_FLOW_ITEM(VOID, 0), 957 MK_FLOW_ITEM(INVERT, 0), 958 MK_FLOW_ITEM(ANY, sizeof(struct rte_flow_item_any)), 959 MK_FLOW_ITEM(PF, 0), 960 MK_FLOW_ITEM(VF, sizeof(struct rte_flow_item_vf)), 961 MK_FLOW_ITEM(PORT, sizeof(struct rte_flow_item_port)), 962 MK_FLOW_ITEM(RAW, sizeof(struct rte_flow_item_raw)), /* +pattern[] */ 963 MK_FLOW_ITEM(ETH, sizeof(struct rte_flow_item_eth)), 964 MK_FLOW_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)), 965 MK_FLOW_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)), 966 MK_FLOW_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)), 967 MK_FLOW_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)), 968 MK_FLOW_ITEM(UDP, sizeof(struct rte_flow_item_udp)), 969 MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)), 970 MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)), 971 MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)), 972 MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)), 973 MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)), 974 }; 975 976 /** Compute storage space needed by item specification. */ 977 static void 978 flow_item_spec_size(const struct rte_flow_item *item, 979 size_t *size, size_t *pad) 980 { 981 if (!item->spec) 982 goto empty; 983 switch (item->type) { 984 union { 985 const struct rte_flow_item_raw *raw; 986 } spec; 987 988 case RTE_FLOW_ITEM_TYPE_RAW: 989 spec.raw = item->spec; 990 *size = offsetof(struct rte_flow_item_raw, pattern) + 991 spec.raw->length * sizeof(*spec.raw->pattern); 992 break; 993 default: 994 empty: 995 *size = 0; 996 break; 997 } 998 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size; 999 } 1000 1001 /** Generate flow_action[] entry. */ 1002 #define MK_FLOW_ACTION(t, s) \ 1003 [RTE_FLOW_ACTION_TYPE_ ## t] = { \ 1004 .name = # t, \ 1005 .size = s, \ 1006 } 1007 1008 /** Information about known flow actions. */ 1009 static const struct { 1010 const char *name; 1011 size_t size; 1012 } flow_action[] = { 1013 MK_FLOW_ACTION(END, 0), 1014 MK_FLOW_ACTION(VOID, 0), 1015 MK_FLOW_ACTION(PASSTHRU, 0), 1016 MK_FLOW_ACTION(MARK, sizeof(struct rte_flow_action_mark)), 1017 MK_FLOW_ACTION(FLAG, 0), 1018 MK_FLOW_ACTION(QUEUE, sizeof(struct rte_flow_action_queue)), 1019 MK_FLOW_ACTION(DROP, 0), 1020 MK_FLOW_ACTION(COUNT, 0), 1021 MK_FLOW_ACTION(DUP, sizeof(struct rte_flow_action_dup)), 1022 MK_FLOW_ACTION(RSS, sizeof(struct rte_flow_action_rss)), /* +queue[] */ 1023 MK_FLOW_ACTION(PF, 0), 1024 MK_FLOW_ACTION(VF, sizeof(struct rte_flow_action_vf)), 1025 }; 1026 1027 /** Compute storage space needed by action configuration. */ 1028 static void 1029 flow_action_conf_size(const struct rte_flow_action *action, 1030 size_t *size, size_t *pad) 1031 { 1032 if (!action->conf) 1033 goto empty; 1034 switch (action->type) { 1035 union { 1036 const struct rte_flow_action_rss *rss; 1037 } conf; 1038 1039 case RTE_FLOW_ACTION_TYPE_RSS: 1040 conf.rss = action->conf; 1041 *size = offsetof(struct rte_flow_action_rss, queue) + 1042 conf.rss->num * sizeof(*conf.rss->queue); 1043 break; 1044 default: 1045 empty: 1046 *size = 0; 1047 break; 1048 } 1049 *pad = RTE_ALIGN_CEIL(*size, sizeof(double)) - *size; 1050 } 1051 1052 /** Generate a port_flow entry from attributes/pattern/actions. */ 1053 static struct port_flow * 1054 port_flow_new(const struct rte_flow_attr *attr, 1055 const struct rte_flow_item *pattern, 1056 const struct rte_flow_action *actions) 1057 { 1058 const struct rte_flow_item *item; 1059 const struct rte_flow_action *action; 1060 struct port_flow *pf = NULL; 1061 size_t tmp; 1062 size_t pad; 1063 size_t off1 = 0; 1064 size_t off2 = 0; 1065 int err = ENOTSUP; 1066 1067 store: 1068 item = pattern; 1069 if (pf) 1070 pf->pattern = (void *)&pf->data[off1]; 1071 do { 1072 struct rte_flow_item *dst = NULL; 1073 1074 if ((unsigned int)item->type >= RTE_DIM(flow_item) || 1075 !flow_item[item->type].name) 1076 goto notsup; 1077 if (pf) 1078 dst = memcpy(pf->data + off1, item, sizeof(*item)); 1079 off1 += sizeof(*item); 1080 flow_item_spec_size(item, &tmp, &pad); 1081 if (item->spec) { 1082 if (pf) 1083 dst->spec = memcpy(pf->data + off2, 1084 item->spec, tmp); 1085 off2 += tmp + pad; 1086 } 1087 if (item->last) { 1088 if (pf) 1089 dst->last = memcpy(pf->data + off2, 1090 item->last, tmp); 1091 off2 += tmp + pad; 1092 } 1093 if (item->mask) { 1094 if (pf) 1095 dst->mask = memcpy(pf->data + off2, 1096 item->mask, tmp); 1097 off2 += tmp + pad; 1098 } 1099 off2 = RTE_ALIGN_CEIL(off2, sizeof(double)); 1100 } while ((item++)->type != RTE_FLOW_ITEM_TYPE_END); 1101 off1 = RTE_ALIGN_CEIL(off1, sizeof(double)); 1102 action = actions; 1103 if (pf) 1104 pf->actions = (void *)&pf->data[off1]; 1105 do { 1106 struct rte_flow_action *dst = NULL; 1107 1108 if ((unsigned int)action->type >= RTE_DIM(flow_action) || 1109 !flow_action[action->type].name) 1110 goto notsup; 1111 if (pf) 1112 dst = memcpy(pf->data + off1, action, sizeof(*action)); 1113 off1 += sizeof(*action); 1114 flow_action_conf_size(action, &tmp, &pad); 1115 if (action->conf) { 1116 if (pf) 1117 dst->conf = memcpy(pf->data + off2, 1118 action->conf, tmp); 1119 off2 += tmp + pad; 1120 } 1121 off2 = RTE_ALIGN_CEIL(off2, sizeof(double)); 1122 } while ((action++)->type != RTE_FLOW_ACTION_TYPE_END); 1123 if (pf != NULL) 1124 return pf; 1125 off1 = RTE_ALIGN_CEIL(off1, sizeof(double)); 1126 tmp = RTE_ALIGN_CEIL(offsetof(struct port_flow, data), sizeof(double)); 1127 pf = calloc(1, tmp + off1 + off2); 1128 if (pf == NULL) 1129 err = errno; 1130 else { 1131 *pf = (const struct port_flow){ 1132 .size = tmp + off1 + off2, 1133 .attr = *attr, 1134 }; 1135 tmp -= offsetof(struct port_flow, data); 1136 off2 = tmp + off1; 1137 off1 = tmp; 1138 goto store; 1139 } 1140 notsup: 1141 rte_errno = err; 1142 return NULL; 1143 } 1144 1145 /** Print a message out of a flow error. */ 1146 static int 1147 port_flow_complain(struct rte_flow_error *error) 1148 { 1149 static const char *const errstrlist[] = { 1150 [RTE_FLOW_ERROR_TYPE_NONE] = "no error", 1151 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified", 1152 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)", 1153 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field", 1154 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field", 1155 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field", 1156 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field", 1157 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure", 1158 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length", 1159 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item", 1160 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions", 1161 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action", 1162 }; 1163 const char *errstr; 1164 char buf[32]; 1165 int err = rte_errno; 1166 1167 if ((unsigned int)error->type >= RTE_DIM(errstrlist) || 1168 !errstrlist[error->type]) 1169 errstr = "unknown type"; 1170 else 1171 errstr = errstrlist[error->type]; 1172 printf("Caught error type %d (%s): %s%s\n", 1173 error->type, errstr, 1174 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ", 1175 error->cause), buf) : "", 1176 error->message ? error->message : "(no stated reason)"); 1177 return -err; 1178 } 1179 1180 /** Validate flow rule. */ 1181 int 1182 port_flow_validate(portid_t port_id, 1183 const struct rte_flow_attr *attr, 1184 const struct rte_flow_item *pattern, 1185 const struct rte_flow_action *actions) 1186 { 1187 struct rte_flow_error error; 1188 1189 /* Poisoning to make sure PMDs update it in case of error. */ 1190 memset(&error, 0x11, sizeof(error)); 1191 if (rte_flow_validate(port_id, attr, pattern, actions, &error)) 1192 return port_flow_complain(&error); 1193 printf("Flow rule validated\n"); 1194 return 0; 1195 } 1196 1197 /** Create flow rule. */ 1198 int 1199 port_flow_create(portid_t port_id, 1200 const struct rte_flow_attr *attr, 1201 const struct rte_flow_item *pattern, 1202 const struct rte_flow_action *actions) 1203 { 1204 struct rte_flow *flow; 1205 struct rte_port *port; 1206 struct port_flow *pf; 1207 uint32_t id; 1208 struct rte_flow_error error; 1209 1210 /* Poisoning to make sure PMDs update it in case of error. */ 1211 memset(&error, 0x22, sizeof(error)); 1212 flow = rte_flow_create(port_id, attr, pattern, actions, &error); 1213 if (!flow) 1214 return port_flow_complain(&error); 1215 port = &ports[port_id]; 1216 if (port->flow_list) { 1217 if (port->flow_list->id == UINT32_MAX) { 1218 printf("Highest rule ID is already assigned, delete" 1219 " it first"); 1220 rte_flow_destroy(port_id, flow, NULL); 1221 return -ENOMEM; 1222 } 1223 id = port->flow_list->id + 1; 1224 } else 1225 id = 0; 1226 pf = port_flow_new(attr, pattern, actions); 1227 if (!pf) { 1228 int err = rte_errno; 1229 1230 printf("Cannot allocate flow: %s\n", rte_strerror(err)); 1231 rte_flow_destroy(port_id, flow, NULL); 1232 return -err; 1233 } 1234 pf->next = port->flow_list; 1235 pf->id = id; 1236 pf->flow = flow; 1237 port->flow_list = pf; 1238 printf("Flow rule #%u created\n", pf->id); 1239 return 0; 1240 } 1241 1242 /** Destroy a number of flow rules. */ 1243 int 1244 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule) 1245 { 1246 struct rte_port *port; 1247 struct port_flow **tmp; 1248 uint32_t c = 0; 1249 int ret = 0; 1250 1251 if (port_id_is_invalid(port_id, ENABLED_WARN) || 1252 port_id == (portid_t)RTE_PORT_ALL) 1253 return -EINVAL; 1254 port = &ports[port_id]; 1255 tmp = &port->flow_list; 1256 while (*tmp) { 1257 uint32_t i; 1258 1259 for (i = 0; i != n; ++i) { 1260 struct rte_flow_error error; 1261 struct port_flow *pf = *tmp; 1262 1263 if (rule[i] != pf->id) 1264 continue; 1265 /* 1266 * Poisoning to make sure PMDs update it in case 1267 * of error. 1268 */ 1269 memset(&error, 0x33, sizeof(error)); 1270 if (rte_flow_destroy(port_id, pf->flow, &error)) { 1271 ret = port_flow_complain(&error); 1272 continue; 1273 } 1274 printf("Flow rule #%u destroyed\n", pf->id); 1275 *tmp = pf->next; 1276 free(pf); 1277 break; 1278 } 1279 if (i == n) 1280 tmp = &(*tmp)->next; 1281 ++c; 1282 } 1283 return ret; 1284 } 1285 1286 /** Remove all flow rules. */ 1287 int 1288 port_flow_flush(portid_t port_id) 1289 { 1290 struct rte_flow_error error; 1291 struct rte_port *port; 1292 int ret = 0; 1293 1294 /* Poisoning to make sure PMDs update it in case of error. */ 1295 memset(&error, 0x44, sizeof(error)); 1296 if (rte_flow_flush(port_id, &error)) { 1297 ret = port_flow_complain(&error); 1298 if (port_id_is_invalid(port_id, DISABLED_WARN) || 1299 port_id == (portid_t)RTE_PORT_ALL) 1300 return ret; 1301 } 1302 port = &ports[port_id]; 1303 while (port->flow_list) { 1304 struct port_flow *pf = port->flow_list->next; 1305 1306 free(port->flow_list); 1307 port->flow_list = pf; 1308 } 1309 return ret; 1310 } 1311 1312 /** Query a flow rule. */ 1313 int 1314 port_flow_query(portid_t port_id, uint32_t rule, 1315 enum rte_flow_action_type action) 1316 { 1317 struct rte_flow_error error; 1318 struct rte_port *port; 1319 struct port_flow *pf; 1320 const char *name; 1321 union { 1322 struct rte_flow_query_count count; 1323 } query; 1324 1325 if (port_id_is_invalid(port_id, ENABLED_WARN) || 1326 port_id == (portid_t)RTE_PORT_ALL) 1327 return -EINVAL; 1328 port = &ports[port_id]; 1329 for (pf = port->flow_list; pf; pf = pf->next) 1330 if (pf->id == rule) 1331 break; 1332 if (!pf) { 1333 printf("Flow rule #%u not found\n", rule); 1334 return -ENOENT; 1335 } 1336 if ((unsigned int)action >= RTE_DIM(flow_action) || 1337 !flow_action[action].name) 1338 name = "unknown"; 1339 else 1340 name = flow_action[action].name; 1341 switch (action) { 1342 case RTE_FLOW_ACTION_TYPE_COUNT: 1343 break; 1344 default: 1345 printf("Cannot query action type %d (%s)\n", action, name); 1346 return -ENOTSUP; 1347 } 1348 /* Poisoning to make sure PMDs update it in case of error. */ 1349 memset(&error, 0x55, sizeof(error)); 1350 memset(&query, 0, sizeof(query)); 1351 if (rte_flow_query(port_id, pf->flow, action, &query, &error)) 1352 return port_flow_complain(&error); 1353 switch (action) { 1354 case RTE_FLOW_ACTION_TYPE_COUNT: 1355 printf("%s:\n" 1356 " hits_set: %u\n" 1357 " bytes_set: %u\n" 1358 " hits: %" PRIu64 "\n" 1359 " bytes: %" PRIu64 "\n", 1360 name, 1361 query.count.hits_set, 1362 query.count.bytes_set, 1363 query.count.hits, 1364 query.count.bytes); 1365 break; 1366 default: 1367 printf("Cannot display result for action type %d (%s)\n", 1368 action, name); 1369 break; 1370 } 1371 return 0; 1372 } 1373 1374 /** List flow rules. */ 1375 void 1376 port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n]) 1377 { 1378 struct rte_port *port; 1379 struct port_flow *pf; 1380 struct port_flow *list = NULL; 1381 uint32_t i; 1382 1383 if (port_id_is_invalid(port_id, ENABLED_WARN) || 1384 port_id == (portid_t)RTE_PORT_ALL) 1385 return; 1386 port = &ports[port_id]; 1387 if (!port->flow_list) 1388 return; 1389 /* Sort flows by group, priority and ID. */ 1390 for (pf = port->flow_list; pf != NULL; pf = pf->next) { 1391 struct port_flow **tmp; 1392 1393 if (n) { 1394 /* Filter out unwanted groups. */ 1395 for (i = 0; i != n; ++i) 1396 if (pf->attr.group == group[i]) 1397 break; 1398 if (i == n) 1399 continue; 1400 } 1401 tmp = &list; 1402 while (*tmp && 1403 (pf->attr.group > (*tmp)->attr.group || 1404 (pf->attr.group == (*tmp)->attr.group && 1405 pf->attr.priority > (*tmp)->attr.priority) || 1406 (pf->attr.group == (*tmp)->attr.group && 1407 pf->attr.priority == (*tmp)->attr.priority && 1408 pf->id > (*tmp)->id))) 1409 tmp = &(*tmp)->tmp; 1410 pf->tmp = *tmp; 1411 *tmp = pf; 1412 } 1413 printf("ID\tGroup\tPrio\tAttr\tRule\n"); 1414 for (pf = list; pf != NULL; pf = pf->tmp) { 1415 const struct rte_flow_item *item = pf->pattern; 1416 const struct rte_flow_action *action = pf->actions; 1417 1418 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c\t", 1419 pf->id, 1420 pf->attr.group, 1421 pf->attr.priority, 1422 pf->attr.ingress ? 'i' : '-', 1423 pf->attr.egress ? 'e' : '-'); 1424 while (item->type != RTE_FLOW_ITEM_TYPE_END) { 1425 if (item->type != RTE_FLOW_ITEM_TYPE_VOID) 1426 printf("%s ", flow_item[item->type].name); 1427 ++item; 1428 } 1429 printf("=>"); 1430 while (action->type != RTE_FLOW_ACTION_TYPE_END) { 1431 if (action->type != RTE_FLOW_ACTION_TYPE_VOID) 1432 printf(" %s", flow_action[action->type].name); 1433 ++action; 1434 } 1435 printf("\n"); 1436 } 1437 } 1438 1439 /* 1440 * RX/TX ring descriptors display functions. 1441 */ 1442 int 1443 rx_queue_id_is_invalid(queueid_t rxq_id) 1444 { 1445 if (rxq_id < nb_rxq) 1446 return 0; 1447 printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq); 1448 return 1; 1449 } 1450 1451 int 1452 tx_queue_id_is_invalid(queueid_t txq_id) 1453 { 1454 if (txq_id < nb_txq) 1455 return 0; 1456 printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq); 1457 return 1; 1458 } 1459 1460 static int 1461 rx_desc_id_is_invalid(uint16_t rxdesc_id) 1462 { 1463 if (rxdesc_id < nb_rxd) 1464 return 0; 1465 printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n", 1466 rxdesc_id, nb_rxd); 1467 return 1; 1468 } 1469 1470 static int 1471 tx_desc_id_is_invalid(uint16_t txdesc_id) 1472 { 1473 if (txdesc_id < nb_txd) 1474 return 0; 1475 printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n", 1476 txdesc_id, nb_txd); 1477 return 1; 1478 } 1479 1480 static const struct rte_memzone * 1481 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id) 1482 { 1483 char mz_name[RTE_MEMZONE_NAMESIZE]; 1484 const struct rte_memzone *mz; 1485 1486 snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d", 1487 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id); 1488 mz = rte_memzone_lookup(mz_name); 1489 if (mz == NULL) 1490 printf("%s ring memory zoneof (port %d, queue %d) not" 1491 "found (zone name = %s\n", 1492 ring_name, port_id, q_id, mz_name); 1493 return mz; 1494 } 1495 1496 union igb_ring_dword { 1497 uint64_t dword; 1498 struct { 1499 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN 1500 uint32_t lo; 1501 uint32_t hi; 1502 #else 1503 uint32_t hi; 1504 uint32_t lo; 1505 #endif 1506 } words; 1507 }; 1508 1509 struct igb_ring_desc_32_bytes { 1510 union igb_ring_dword lo_dword; 1511 union igb_ring_dword hi_dword; 1512 union igb_ring_dword resv1; 1513 union igb_ring_dword resv2; 1514 }; 1515 1516 struct igb_ring_desc_16_bytes { 1517 union igb_ring_dword lo_dword; 1518 union igb_ring_dword hi_dword; 1519 }; 1520 1521 static void 1522 ring_rxd_display_dword(union igb_ring_dword dword) 1523 { 1524 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo, 1525 (unsigned)dword.words.hi); 1526 } 1527 1528 static void 1529 ring_rx_descriptor_display(const struct rte_memzone *ring_mz, 1530 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC 1531 uint8_t port_id, 1532 #else 1533 __rte_unused uint8_t port_id, 1534 #endif 1535 uint16_t desc_id) 1536 { 1537 struct igb_ring_desc_16_bytes *ring = 1538 (struct igb_ring_desc_16_bytes *)ring_mz->addr; 1539 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC 1540 struct rte_eth_dev_info dev_info; 1541 1542 memset(&dev_info, 0, sizeof(dev_info)); 1543 rte_eth_dev_info_get(port_id, &dev_info); 1544 if (strstr(dev_info.driver_name, "i40e") != NULL) { 1545 /* 32 bytes RX descriptor, i40e only */ 1546 struct igb_ring_desc_32_bytes *ring = 1547 (struct igb_ring_desc_32_bytes *)ring_mz->addr; 1548 ring[desc_id].lo_dword.dword = 1549 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword); 1550 ring_rxd_display_dword(ring[desc_id].lo_dword); 1551 ring[desc_id].hi_dword.dword = 1552 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword); 1553 ring_rxd_display_dword(ring[desc_id].hi_dword); 1554 ring[desc_id].resv1.dword = 1555 rte_le_to_cpu_64(ring[desc_id].resv1.dword); 1556 ring_rxd_display_dword(ring[desc_id].resv1); 1557 ring[desc_id].resv2.dword = 1558 rte_le_to_cpu_64(ring[desc_id].resv2.dword); 1559 ring_rxd_display_dword(ring[desc_id].resv2); 1560 1561 return; 1562 } 1563 #endif 1564 /* 16 bytes RX descriptor */ 1565 ring[desc_id].lo_dword.dword = 1566 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword); 1567 ring_rxd_display_dword(ring[desc_id].lo_dword); 1568 ring[desc_id].hi_dword.dword = 1569 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword); 1570 ring_rxd_display_dword(ring[desc_id].hi_dword); 1571 } 1572 1573 static void 1574 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id) 1575 { 1576 struct igb_ring_desc_16_bytes *ring; 1577 struct igb_ring_desc_16_bytes txd; 1578 1579 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr; 1580 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword); 1581 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword); 1582 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n", 1583 (unsigned)txd.lo_dword.words.lo, 1584 (unsigned)txd.lo_dword.words.hi, 1585 (unsigned)txd.hi_dword.words.lo, 1586 (unsigned)txd.hi_dword.words.hi); 1587 } 1588 1589 void 1590 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id) 1591 { 1592 const struct rte_memzone *rx_mz; 1593 1594 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1595 return; 1596 if (rx_queue_id_is_invalid(rxq_id)) 1597 return; 1598 if (rx_desc_id_is_invalid(rxd_id)) 1599 return; 1600 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id); 1601 if (rx_mz == NULL) 1602 return; 1603 ring_rx_descriptor_display(rx_mz, port_id, rxd_id); 1604 } 1605 1606 void 1607 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id) 1608 { 1609 const struct rte_memzone *tx_mz; 1610 1611 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1612 return; 1613 if (tx_queue_id_is_invalid(txq_id)) 1614 return; 1615 if (tx_desc_id_is_invalid(txd_id)) 1616 return; 1617 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id); 1618 if (tx_mz == NULL) 1619 return; 1620 ring_tx_descriptor_display(tx_mz, txd_id); 1621 } 1622 1623 void 1624 fwd_lcores_config_display(void) 1625 { 1626 lcoreid_t lc_id; 1627 1628 printf("List of forwarding lcores:"); 1629 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++) 1630 printf(" %2u", fwd_lcores_cpuids[lc_id]); 1631 printf("\n"); 1632 } 1633 void 1634 rxtx_config_display(void) 1635 { 1636 printf(" %s packet forwarding%s - CRC stripping %s - " 1637 "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name, 1638 retry_enabled == 0 ? "" : " with retry", 1639 rx_mode.hw_strip_crc ? "enabled" : "disabled", 1640 nb_pkt_per_burst); 1641 1642 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine) 1643 printf(" packet len=%u - nb packet segments=%d\n", 1644 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs); 1645 1646 struct rte_eth_rxconf *rx_conf = &ports[0].rx_conf; 1647 struct rte_eth_txconf *tx_conf = &ports[0].tx_conf; 1648 1649 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n", 1650 nb_fwd_lcores, nb_fwd_ports); 1651 printf(" RX queues=%d - RX desc=%d - RX free threshold=%d\n", 1652 nb_rxq, nb_rxd, rx_conf->rx_free_thresh); 1653 printf(" RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n", 1654 rx_conf->rx_thresh.pthresh, rx_conf->rx_thresh.hthresh, 1655 rx_conf->rx_thresh.wthresh); 1656 printf(" TX queues=%d - TX desc=%d - TX free threshold=%d\n", 1657 nb_txq, nb_txd, tx_conf->tx_free_thresh); 1658 printf(" TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n", 1659 tx_conf->tx_thresh.pthresh, tx_conf->tx_thresh.hthresh, 1660 tx_conf->tx_thresh.wthresh); 1661 printf(" TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n", 1662 tx_conf->tx_rs_thresh, tx_conf->txq_flags); 1663 } 1664 1665 void 1666 port_rss_reta_info(portid_t port_id, 1667 struct rte_eth_rss_reta_entry64 *reta_conf, 1668 uint16_t nb_entries) 1669 { 1670 uint16_t i, idx, shift; 1671 int ret; 1672 1673 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1674 return; 1675 1676 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries); 1677 if (ret != 0) { 1678 printf("Failed to get RSS RETA info, return code = %d\n", ret); 1679 return; 1680 } 1681 1682 for (i = 0; i < nb_entries; i++) { 1683 idx = i / RTE_RETA_GROUP_SIZE; 1684 shift = i % RTE_RETA_GROUP_SIZE; 1685 if (!(reta_conf[idx].mask & (1ULL << shift))) 1686 continue; 1687 printf("RSS RETA configuration: hash index=%u, queue=%u\n", 1688 i, reta_conf[idx].reta[shift]); 1689 } 1690 } 1691 1692 /* 1693 * Displays the RSS hash functions of a port, and, optionaly, the RSS hash 1694 * key of the port. 1695 */ 1696 void 1697 port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key) 1698 { 1699 struct rte_eth_rss_conf rss_conf; 1700 uint8_t rss_key[RSS_HASH_KEY_LENGTH]; 1701 uint64_t rss_hf; 1702 uint8_t i; 1703 int diag; 1704 struct rte_eth_dev_info dev_info; 1705 uint8_t hash_key_size; 1706 1707 if (port_id_is_invalid(port_id, ENABLED_WARN)) 1708 return; 1709 1710 memset(&dev_info, 0, sizeof(dev_info)); 1711 rte_eth_dev_info_get(port_id, &dev_info); 1712 if (dev_info.hash_key_size > 0 && 1713 dev_info.hash_key_size <= sizeof(rss_key)) 1714 hash_key_size = dev_info.hash_key_size; 1715 else { 1716 printf("dev_info did not provide a valid hash key size\n"); 1717 return; 1718 } 1719 1720 rss_conf.rss_hf = 0; 1721 for (i = 0; i < RTE_DIM(rss_type_table); i++) { 1722 if (!strcmp(rss_info, rss_type_table[i].str)) 1723 rss_conf.rss_hf = rss_type_table[i].rss_type; 1724 } 1725 1726 /* Get RSS hash key if asked to display it */ 1727 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL; 1728 rss_conf.rss_key_len = hash_key_size; 1729 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); 1730 if (diag != 0) { 1731 switch (diag) { 1732 case -ENODEV: 1733 printf("port index %d invalid\n", port_id); 1734 break; 1735 case -ENOTSUP: 1736 printf("operation not supported by device\n"); 1737 break; 1738 default: 1739 printf("operation failed - diag=%d\n", diag); 1740 break; 1741 } 1742 return; 1743 } 1744 rss_hf = rss_conf.rss_hf; 1745 if (rss_hf == 0) { 1746 printf("RSS disabled\n"); 1747 return; 1748 } 1749 printf("RSS functions:\n "); 1750 for (i = 0; i < RTE_DIM(rss_type_table); i++) { 1751 if (rss_hf & rss_type_table[i].rss_type) 1752 printf("%s ", rss_type_table[i].str); 1753 } 1754 printf("\n"); 1755 if (!show_rss_key) 1756 return; 1757 printf("RSS key:\n"); 1758 for (i = 0; i < hash_key_size; i++) 1759 printf("%02X", rss_key[i]); 1760 printf("\n"); 1761 } 1762 1763 void 1764 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key, 1765 uint hash_key_len) 1766 { 1767 struct rte_eth_rss_conf rss_conf; 1768 int diag; 1769 unsigned int i; 1770 1771 rss_conf.rss_key = NULL; 1772 rss_conf.rss_key_len = hash_key_len; 1773 rss_conf.rss_hf = 0; 1774 for (i = 0; i < RTE_DIM(rss_type_table); i++) { 1775 if (!strcmp(rss_type_table[i].str, rss_type)) 1776 rss_conf.rss_hf = rss_type_table[i].rss_type; 1777 } 1778 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); 1779 if (diag == 0) { 1780 rss_conf.rss_key = hash_key; 1781 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf); 1782 } 1783 if (diag == 0) 1784 return; 1785 1786 switch (diag) { 1787 case -ENODEV: 1788 printf("port index %d invalid\n", port_id); 1789 break; 1790 case -ENOTSUP: 1791 printf("operation not supported by device\n"); 1792 break; 1793 default: 1794 printf("operation failed - diag=%d\n", diag); 1795 break; 1796 } 1797 } 1798 1799 /* 1800 * Setup forwarding configuration for each logical core. 1801 */ 1802 static void 1803 setup_fwd_config_of_each_lcore(struct fwd_config *cfg) 1804 { 1805 streamid_t nb_fs_per_lcore; 1806 streamid_t nb_fs; 1807 streamid_t sm_id; 1808 lcoreid_t nb_extra; 1809 lcoreid_t nb_fc; 1810 lcoreid_t nb_lc; 1811 lcoreid_t lc_id; 1812 1813 nb_fs = cfg->nb_fwd_streams; 1814 nb_fc = cfg->nb_fwd_lcores; 1815 if (nb_fs <= nb_fc) { 1816 nb_fs_per_lcore = 1; 1817 nb_extra = 0; 1818 } else { 1819 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc); 1820 nb_extra = (lcoreid_t) (nb_fs % nb_fc); 1821 } 1822 1823 nb_lc = (lcoreid_t) (nb_fc - nb_extra); 1824 sm_id = 0; 1825 for (lc_id = 0; lc_id < nb_lc; lc_id++) { 1826 fwd_lcores[lc_id]->stream_idx = sm_id; 1827 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore; 1828 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore); 1829 } 1830 1831 /* 1832 * Assign extra remaining streams, if any. 1833 */ 1834 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1); 1835 for (lc_id = 0; lc_id < nb_extra; lc_id++) { 1836 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id; 1837 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore; 1838 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore); 1839 } 1840 } 1841 1842 static void 1843 simple_fwd_config_setup(void) 1844 { 1845 portid_t i; 1846 portid_t j; 1847 portid_t inc = 2; 1848 1849 if (port_topology == PORT_TOPOLOGY_CHAINED || 1850 port_topology == PORT_TOPOLOGY_LOOP) { 1851 inc = 1; 1852 } else if (nb_fwd_ports % 2) { 1853 printf("\nWarning! Cannot handle an odd number of ports " 1854 "with the current port topology. Configuration " 1855 "must be changed to have an even number of ports, " 1856 "or relaunch application with " 1857 "--port-topology=chained\n\n"); 1858 } 1859 1860 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports; 1861 cur_fwd_config.nb_fwd_streams = 1862 (streamid_t) cur_fwd_config.nb_fwd_ports; 1863 1864 /* reinitialize forwarding streams */ 1865 init_fwd_streams(); 1866 1867 /* 1868 * In the simple forwarding test, the number of forwarding cores 1869 * must be lower or equal to the number of forwarding ports. 1870 */ 1871 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores; 1872 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports) 1873 cur_fwd_config.nb_fwd_lcores = 1874 (lcoreid_t) cur_fwd_config.nb_fwd_ports; 1875 setup_fwd_config_of_each_lcore(&cur_fwd_config); 1876 1877 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) { 1878 if (port_topology != PORT_TOPOLOGY_LOOP) 1879 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports); 1880 else 1881 j = i; 1882 fwd_streams[i]->rx_port = fwd_ports_ids[i]; 1883 fwd_streams[i]->rx_queue = 0; 1884 fwd_streams[i]->tx_port = fwd_ports_ids[j]; 1885 fwd_streams[i]->tx_queue = 0; 1886 fwd_streams[i]->peer_addr = j; 1887 fwd_streams[i]->retry_enabled = retry_enabled; 1888 1889 if (port_topology == PORT_TOPOLOGY_PAIRED) { 1890 fwd_streams[j]->rx_port = fwd_ports_ids[j]; 1891 fwd_streams[j]->rx_queue = 0; 1892 fwd_streams[j]->tx_port = fwd_ports_ids[i]; 1893 fwd_streams[j]->tx_queue = 0; 1894 fwd_streams[j]->peer_addr = i; 1895 fwd_streams[j]->retry_enabled = retry_enabled; 1896 } 1897 } 1898 } 1899 1900 /** 1901 * For the RSS forwarding test all streams distributed over lcores. Each stream 1902 * being composed of a RX queue to poll on a RX port for input messages, 1903 * associated with a TX queue of a TX port where to send forwarded packets. 1904 * All packets received on the RX queue of index "RxQj" of the RX port "RxPi" 1905 * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two 1906 * following rules: 1907 * - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd 1908 * - TxQl = RxQj 1909 */ 1910 static void 1911 rss_fwd_config_setup(void) 1912 { 1913 portid_t rxp; 1914 portid_t txp; 1915 queueid_t rxq; 1916 queueid_t nb_q; 1917 streamid_t sm_id; 1918 1919 nb_q = nb_rxq; 1920 if (nb_q > nb_txq) 1921 nb_q = nb_txq; 1922 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores; 1923 cur_fwd_config.nb_fwd_ports = nb_fwd_ports; 1924 cur_fwd_config.nb_fwd_streams = 1925 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports); 1926 1927 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores) 1928 cur_fwd_config.nb_fwd_lcores = 1929 (lcoreid_t)cur_fwd_config.nb_fwd_streams; 1930 1931 /* reinitialize forwarding streams */ 1932 init_fwd_streams(); 1933 1934 setup_fwd_config_of_each_lcore(&cur_fwd_config); 1935 rxp = 0; rxq = 0; 1936 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) { 1937 struct fwd_stream *fs; 1938 1939 fs = fwd_streams[sm_id]; 1940 1941 if ((rxp & 0x1) == 0) 1942 txp = (portid_t) (rxp + 1); 1943 else 1944 txp = (portid_t) (rxp - 1); 1945 /* 1946 * if we are in loopback, simply send stuff out through the 1947 * ingress port 1948 */ 1949 if (port_topology == PORT_TOPOLOGY_LOOP) 1950 txp = rxp; 1951 1952 fs->rx_port = fwd_ports_ids[rxp]; 1953 fs->rx_queue = rxq; 1954 fs->tx_port = fwd_ports_ids[txp]; 1955 fs->tx_queue = rxq; 1956 fs->peer_addr = fs->tx_port; 1957 fs->retry_enabled = retry_enabled; 1958 rxq = (queueid_t) (rxq + 1); 1959 if (rxq < nb_q) 1960 continue; 1961 /* 1962 * rxq == nb_q 1963 * Restart from RX queue 0 on next RX port 1964 */ 1965 rxq = 0; 1966 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1))) 1967 rxp = (portid_t) 1968 (rxp + ((nb_ports >> 1) / nb_fwd_ports)); 1969 else 1970 rxp = (portid_t) (rxp + 1); 1971 } 1972 } 1973 1974 /** 1975 * For the DCB forwarding test, each core is assigned on each traffic class. 1976 * 1977 * Each core is assigned a multi-stream, each stream being composed of 1978 * a RX queue to poll on a RX port for input messages, associated with 1979 * a TX queue of a TX port where to send forwarded packets. All RX and 1980 * TX queues are mapping to the same traffic class. 1981 * If VMDQ and DCB co-exist, each traffic class on different POOLs share 1982 * the same core 1983 */ 1984 static void 1985 dcb_fwd_config_setup(void) 1986 { 1987 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info; 1988 portid_t txp, rxp = 0; 1989 queueid_t txq, rxq = 0; 1990 lcoreid_t lc_id; 1991 uint16_t nb_rx_queue, nb_tx_queue; 1992 uint16_t i, j, k, sm_id = 0; 1993 uint8_t tc = 0; 1994 1995 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores; 1996 cur_fwd_config.nb_fwd_ports = nb_fwd_ports; 1997 cur_fwd_config.nb_fwd_streams = 1998 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports); 1999 2000 /* reinitialize forwarding streams */ 2001 init_fwd_streams(); 2002 sm_id = 0; 2003 txp = 1; 2004 /* get the dcb info on the first RX and TX ports */ 2005 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info); 2006 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info); 2007 2008 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) { 2009 fwd_lcores[lc_id]->stream_nb = 0; 2010 fwd_lcores[lc_id]->stream_idx = sm_id; 2011 for (i = 0; i < ETH_MAX_VMDQ_POOL; i++) { 2012 /* if the nb_queue is zero, means this tc is 2013 * not enabled on the POOL 2014 */ 2015 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0) 2016 break; 2017 k = fwd_lcores[lc_id]->stream_nb + 2018 fwd_lcores[lc_id]->stream_idx; 2019 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base; 2020 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base; 2021 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue; 2022 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue; 2023 for (j = 0; j < nb_rx_queue; j++) { 2024 struct fwd_stream *fs; 2025 2026 fs = fwd_streams[k + j]; 2027 fs->rx_port = fwd_ports_ids[rxp]; 2028 fs->rx_queue = rxq + j; 2029 fs->tx_port = fwd_ports_ids[txp]; 2030 fs->tx_queue = txq + j % nb_tx_queue; 2031 fs->peer_addr = fs->tx_port; 2032 fs->retry_enabled = retry_enabled; 2033 } 2034 fwd_lcores[lc_id]->stream_nb += 2035 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue; 2036 } 2037 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb); 2038 2039 tc++; 2040 if (tc < rxp_dcb_info.nb_tcs) 2041 continue; 2042 /* Restart from TC 0 on next RX port */ 2043 tc = 0; 2044 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1))) 2045 rxp = (portid_t) 2046 (rxp + ((nb_ports >> 1) / nb_fwd_ports)); 2047 else 2048 rxp++; 2049 if (rxp >= nb_fwd_ports) 2050 return; 2051 /* get the dcb information on next RX and TX ports */ 2052 if ((rxp & 0x1) == 0) 2053 txp = (portid_t) (rxp + 1); 2054 else 2055 txp = (portid_t) (rxp - 1); 2056 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info); 2057 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info); 2058 } 2059 } 2060 2061 static void 2062 icmp_echo_config_setup(void) 2063 { 2064 portid_t rxp; 2065 queueid_t rxq; 2066 lcoreid_t lc_id; 2067 uint16_t sm_id; 2068 2069 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores) 2070 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) 2071 (nb_txq * nb_fwd_ports); 2072 else 2073 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores; 2074 cur_fwd_config.nb_fwd_ports = nb_fwd_ports; 2075 cur_fwd_config.nb_fwd_streams = 2076 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports); 2077 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores) 2078 cur_fwd_config.nb_fwd_lcores = 2079 (lcoreid_t)cur_fwd_config.nb_fwd_streams; 2080 if (verbose_level > 0) { 2081 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n", 2082 __FUNCTION__, 2083 cur_fwd_config.nb_fwd_lcores, 2084 cur_fwd_config.nb_fwd_ports, 2085 cur_fwd_config.nb_fwd_streams); 2086 } 2087 2088 /* reinitialize forwarding streams */ 2089 init_fwd_streams(); 2090 setup_fwd_config_of_each_lcore(&cur_fwd_config); 2091 rxp = 0; rxq = 0; 2092 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) { 2093 if (verbose_level > 0) 2094 printf(" core=%d: \n", lc_id); 2095 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) { 2096 struct fwd_stream *fs; 2097 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id]; 2098 fs->rx_port = fwd_ports_ids[rxp]; 2099 fs->rx_queue = rxq; 2100 fs->tx_port = fs->rx_port; 2101 fs->tx_queue = rxq; 2102 fs->peer_addr = fs->tx_port; 2103 fs->retry_enabled = retry_enabled; 2104 if (verbose_level > 0) 2105 printf(" stream=%d port=%d rxq=%d txq=%d\n", 2106 sm_id, fs->rx_port, fs->rx_queue, 2107 fs->tx_queue); 2108 rxq = (queueid_t) (rxq + 1); 2109 if (rxq == nb_rxq) { 2110 rxq = 0; 2111 rxp = (portid_t) (rxp + 1); 2112 } 2113 } 2114 } 2115 } 2116 2117 void 2118 fwd_config_setup(void) 2119 { 2120 cur_fwd_config.fwd_eng = cur_fwd_eng; 2121 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) { 2122 icmp_echo_config_setup(); 2123 return; 2124 } 2125 if ((nb_rxq > 1) && (nb_txq > 1)){ 2126 if (dcb_config) 2127 dcb_fwd_config_setup(); 2128 else 2129 rss_fwd_config_setup(); 2130 } 2131 else 2132 simple_fwd_config_setup(); 2133 } 2134 2135 void 2136 pkt_fwd_config_display(struct fwd_config *cfg) 2137 { 2138 struct fwd_stream *fs; 2139 lcoreid_t lc_id; 2140 streamid_t sm_id; 2141 2142 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - " 2143 "NUMA support %s, MP over anonymous pages %s\n", 2144 cfg->fwd_eng->fwd_mode_name, 2145 retry_enabled == 0 ? "" : " with retry", 2146 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams, 2147 numa_support == 1 ? "enabled" : "disabled", 2148 mp_anon != 0 ? "enabled" : "disabled"); 2149 2150 if (retry_enabled) 2151 printf("TX retry num: %u, delay between TX retries: %uus\n", 2152 burst_tx_retry_num, burst_tx_delay_time); 2153 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) { 2154 printf("Logical Core %u (socket %u) forwards packets on " 2155 "%d streams:", 2156 fwd_lcores_cpuids[lc_id], 2157 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]), 2158 fwd_lcores[lc_id]->stream_nb); 2159 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) { 2160 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id]; 2161 printf("\n RX P=%d/Q=%d (socket %u) -> TX " 2162 "P=%d/Q=%d (socket %u) ", 2163 fs->rx_port, fs->rx_queue, 2164 ports[fs->rx_port].socket_id, 2165 fs->tx_port, fs->tx_queue, 2166 ports[fs->tx_port].socket_id); 2167 print_ethaddr("peer=", 2168 &peer_eth_addrs[fs->peer_addr]); 2169 } 2170 printf("\n"); 2171 } 2172 printf("\n"); 2173 } 2174 2175 int 2176 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc) 2177 { 2178 unsigned int i; 2179 unsigned int lcore_cpuid; 2180 int record_now; 2181 2182 record_now = 0; 2183 again: 2184 for (i = 0; i < nb_lc; i++) { 2185 lcore_cpuid = lcorelist[i]; 2186 if (! rte_lcore_is_enabled(lcore_cpuid)) { 2187 printf("lcore %u not enabled\n", lcore_cpuid); 2188 return -1; 2189 } 2190 if (lcore_cpuid == rte_get_master_lcore()) { 2191 printf("lcore %u cannot be masked on for running " 2192 "packet forwarding, which is the master lcore " 2193 "and reserved for command line parsing only\n", 2194 lcore_cpuid); 2195 return -1; 2196 } 2197 if (record_now) 2198 fwd_lcores_cpuids[i] = lcore_cpuid; 2199 } 2200 if (record_now == 0) { 2201 record_now = 1; 2202 goto again; 2203 } 2204 nb_cfg_lcores = (lcoreid_t) nb_lc; 2205 if (nb_fwd_lcores != (lcoreid_t) nb_lc) { 2206 printf("previous number of forwarding cores %u - changed to " 2207 "number of configured cores %u\n", 2208 (unsigned int) nb_fwd_lcores, nb_lc); 2209 nb_fwd_lcores = (lcoreid_t) nb_lc; 2210 } 2211 2212 return 0; 2213 } 2214 2215 int 2216 set_fwd_lcores_mask(uint64_t lcoremask) 2217 { 2218 unsigned int lcorelist[64]; 2219 unsigned int nb_lc; 2220 unsigned int i; 2221 2222 if (lcoremask == 0) { 2223 printf("Invalid NULL mask of cores\n"); 2224 return -1; 2225 } 2226 nb_lc = 0; 2227 for (i = 0; i < 64; i++) { 2228 if (! ((uint64_t)(1ULL << i) & lcoremask)) 2229 continue; 2230 lcorelist[nb_lc++] = i; 2231 } 2232 return set_fwd_lcores_list(lcorelist, nb_lc); 2233 } 2234 2235 void 2236 set_fwd_lcores_number(uint16_t nb_lc) 2237 { 2238 if (nb_lc > nb_cfg_lcores) { 2239 printf("nb fwd cores %u > %u (max. number of configured " 2240 "lcores) - ignored\n", 2241 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores); 2242 return; 2243 } 2244 nb_fwd_lcores = (lcoreid_t) nb_lc; 2245 printf("Number of forwarding cores set to %u\n", 2246 (unsigned int) nb_fwd_lcores); 2247 } 2248 2249 void 2250 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt) 2251 { 2252 unsigned int i; 2253 portid_t port_id; 2254 int record_now; 2255 2256 record_now = 0; 2257 again: 2258 for (i = 0; i < nb_pt; i++) { 2259 port_id = (portid_t) portlist[i]; 2260 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2261 return; 2262 if (record_now) 2263 fwd_ports_ids[i] = port_id; 2264 } 2265 if (record_now == 0) { 2266 record_now = 1; 2267 goto again; 2268 } 2269 nb_cfg_ports = (portid_t) nb_pt; 2270 if (nb_fwd_ports != (portid_t) nb_pt) { 2271 printf("previous number of forwarding ports %u - changed to " 2272 "number of configured ports %u\n", 2273 (unsigned int) nb_fwd_ports, nb_pt); 2274 nb_fwd_ports = (portid_t) nb_pt; 2275 } 2276 } 2277 2278 void 2279 set_fwd_ports_mask(uint64_t portmask) 2280 { 2281 unsigned int portlist[64]; 2282 unsigned int nb_pt; 2283 unsigned int i; 2284 2285 if (portmask == 0) { 2286 printf("Invalid NULL mask of ports\n"); 2287 return; 2288 } 2289 nb_pt = 0; 2290 RTE_ETH_FOREACH_DEV(i) { 2291 if (! ((uint64_t)(1ULL << i) & portmask)) 2292 continue; 2293 portlist[nb_pt++] = i; 2294 } 2295 set_fwd_ports_list(portlist, nb_pt); 2296 } 2297 2298 void 2299 set_fwd_ports_number(uint16_t nb_pt) 2300 { 2301 if (nb_pt > nb_cfg_ports) { 2302 printf("nb fwd ports %u > %u (number of configured " 2303 "ports) - ignored\n", 2304 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports); 2305 return; 2306 } 2307 nb_fwd_ports = (portid_t) nb_pt; 2308 printf("Number of forwarding ports set to %u\n", 2309 (unsigned int) nb_fwd_ports); 2310 } 2311 2312 int 2313 port_is_forwarding(portid_t port_id) 2314 { 2315 unsigned int i; 2316 2317 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2318 return -1; 2319 2320 for (i = 0; i < nb_fwd_ports; i++) { 2321 if (fwd_ports_ids[i] == port_id) 2322 return 1; 2323 } 2324 2325 return 0; 2326 } 2327 2328 void 2329 set_nb_pkt_per_burst(uint16_t nb) 2330 { 2331 if (nb > MAX_PKT_BURST) { 2332 printf("nb pkt per burst: %u > %u (maximum packet per burst) " 2333 " ignored\n", 2334 (unsigned int) nb, (unsigned int) MAX_PKT_BURST); 2335 return; 2336 } 2337 nb_pkt_per_burst = nb; 2338 printf("Number of packets per burst set to %u\n", 2339 (unsigned int) nb_pkt_per_burst); 2340 } 2341 2342 static const char * 2343 tx_split_get_name(enum tx_pkt_split split) 2344 { 2345 uint32_t i; 2346 2347 for (i = 0; i != RTE_DIM(tx_split_name); i++) { 2348 if (tx_split_name[i].split == split) 2349 return tx_split_name[i].name; 2350 } 2351 return NULL; 2352 } 2353 2354 void 2355 set_tx_pkt_split(const char *name) 2356 { 2357 uint32_t i; 2358 2359 for (i = 0; i != RTE_DIM(tx_split_name); i++) { 2360 if (strcmp(tx_split_name[i].name, name) == 0) { 2361 tx_pkt_split = tx_split_name[i].split; 2362 return; 2363 } 2364 } 2365 printf("unknown value: \"%s\"\n", name); 2366 } 2367 2368 void 2369 show_tx_pkt_segments(void) 2370 { 2371 uint32_t i, n; 2372 const char *split; 2373 2374 n = tx_pkt_nb_segs; 2375 split = tx_split_get_name(tx_pkt_split); 2376 2377 printf("Number of segments: %u\n", n); 2378 printf("Segment sizes: "); 2379 for (i = 0; i != n - 1; i++) 2380 printf("%hu,", tx_pkt_seg_lengths[i]); 2381 printf("%hu\n", tx_pkt_seg_lengths[i]); 2382 printf("Split packet: %s\n", split); 2383 } 2384 2385 void 2386 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs) 2387 { 2388 uint16_t tx_pkt_len; 2389 unsigned i; 2390 2391 if (nb_segs >= (unsigned) nb_txd) { 2392 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n", 2393 nb_segs, (unsigned int) nb_txd); 2394 return; 2395 } 2396 2397 /* 2398 * Check that each segment length is greater or equal than 2399 * the mbuf data sise. 2400 * Check also that the total packet length is greater or equal than the 2401 * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8). 2402 */ 2403 tx_pkt_len = 0; 2404 for (i = 0; i < nb_segs; i++) { 2405 if (seg_lengths[i] > (unsigned) mbuf_data_size) { 2406 printf("length[%u]=%u > mbuf_data_size=%u - give up\n", 2407 i, seg_lengths[i], (unsigned) mbuf_data_size); 2408 return; 2409 } 2410 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]); 2411 } 2412 if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) { 2413 printf("total packet length=%u < %d - give up\n", 2414 (unsigned) tx_pkt_len, 2415 (int)(sizeof(struct ether_hdr) + 20 + 8)); 2416 return; 2417 } 2418 2419 for (i = 0; i < nb_segs; i++) 2420 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i]; 2421 2422 tx_pkt_length = tx_pkt_len; 2423 tx_pkt_nb_segs = (uint8_t) nb_segs; 2424 } 2425 2426 char* 2427 list_pkt_forwarding_modes(void) 2428 { 2429 static char fwd_modes[128] = ""; 2430 const char *separator = "|"; 2431 struct fwd_engine *fwd_eng; 2432 unsigned i = 0; 2433 2434 if (strlen (fwd_modes) == 0) { 2435 while ((fwd_eng = fwd_engines[i++]) != NULL) { 2436 strncat(fwd_modes, fwd_eng->fwd_mode_name, 2437 sizeof(fwd_modes) - strlen(fwd_modes) - 1); 2438 strncat(fwd_modes, separator, 2439 sizeof(fwd_modes) - strlen(fwd_modes) - 1); 2440 } 2441 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0'; 2442 } 2443 2444 return fwd_modes; 2445 } 2446 2447 char* 2448 list_pkt_forwarding_retry_modes(void) 2449 { 2450 static char fwd_modes[128] = ""; 2451 const char *separator = "|"; 2452 struct fwd_engine *fwd_eng; 2453 unsigned i = 0; 2454 2455 if (strlen(fwd_modes) == 0) { 2456 while ((fwd_eng = fwd_engines[i++]) != NULL) { 2457 if (fwd_eng == &rx_only_engine) 2458 continue; 2459 strncat(fwd_modes, fwd_eng->fwd_mode_name, 2460 sizeof(fwd_modes) - 2461 strlen(fwd_modes) - 1); 2462 strncat(fwd_modes, separator, 2463 sizeof(fwd_modes) - 2464 strlen(fwd_modes) - 1); 2465 } 2466 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0'; 2467 } 2468 2469 return fwd_modes; 2470 } 2471 2472 void 2473 set_pkt_forwarding_mode(const char *fwd_mode_name) 2474 { 2475 struct fwd_engine *fwd_eng; 2476 unsigned i; 2477 2478 i = 0; 2479 while ((fwd_eng = fwd_engines[i]) != NULL) { 2480 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) { 2481 printf("Set %s packet forwarding mode%s\n", 2482 fwd_mode_name, 2483 retry_enabled == 0 ? "" : " with retry"); 2484 cur_fwd_eng = fwd_eng; 2485 return; 2486 } 2487 i++; 2488 } 2489 printf("Invalid %s packet forwarding mode\n", fwd_mode_name); 2490 } 2491 2492 void 2493 set_verbose_level(uint16_t vb_level) 2494 { 2495 printf("Change verbose level from %u to %u\n", 2496 (unsigned int) verbose_level, (unsigned int) vb_level); 2497 verbose_level = vb_level; 2498 } 2499 2500 void 2501 vlan_extend_set(portid_t port_id, int on) 2502 { 2503 int diag; 2504 int vlan_offload; 2505 2506 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2507 return; 2508 2509 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 2510 2511 if (on) 2512 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD; 2513 else 2514 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD; 2515 2516 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload); 2517 if (diag < 0) 2518 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed " 2519 "diag=%d\n", port_id, on, diag); 2520 } 2521 2522 void 2523 rx_vlan_strip_set(portid_t port_id, int on) 2524 { 2525 int diag; 2526 int vlan_offload; 2527 2528 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2529 return; 2530 2531 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 2532 2533 if (on) 2534 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD; 2535 else 2536 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD; 2537 2538 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload); 2539 if (diag < 0) 2540 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed " 2541 "diag=%d\n", port_id, on, diag); 2542 } 2543 2544 void 2545 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on) 2546 { 2547 int diag; 2548 2549 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2550 return; 2551 2552 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on); 2553 if (diag < 0) 2554 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed " 2555 "diag=%d\n", port_id, queue_id, on, diag); 2556 } 2557 2558 void 2559 rx_vlan_filter_set(portid_t port_id, int on) 2560 { 2561 int diag; 2562 int vlan_offload; 2563 2564 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2565 return; 2566 2567 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 2568 2569 if (on) 2570 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD; 2571 else 2572 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD; 2573 2574 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload); 2575 if (diag < 0) 2576 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed " 2577 "diag=%d\n", port_id, on, diag); 2578 } 2579 2580 int 2581 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on) 2582 { 2583 int diag; 2584 2585 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2586 return 1; 2587 if (vlan_id_is_invalid(vlan_id)) 2588 return 1; 2589 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on); 2590 if (diag == 0) 2591 return 0; 2592 printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed " 2593 "diag=%d\n", 2594 port_id, vlan_id, on, diag); 2595 return -1; 2596 } 2597 2598 void 2599 rx_vlan_all_filter_set(portid_t port_id, int on) 2600 { 2601 uint16_t vlan_id; 2602 2603 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2604 return; 2605 for (vlan_id = 0; vlan_id < 4096; vlan_id++) { 2606 if (rx_vft_set(port_id, vlan_id, on)) 2607 break; 2608 } 2609 } 2610 2611 void 2612 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id) 2613 { 2614 int diag; 2615 2616 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2617 return; 2618 2619 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id); 2620 if (diag == 0) 2621 return; 2622 2623 printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed " 2624 "diag=%d\n", 2625 port_id, vlan_type, tp_id, diag); 2626 } 2627 2628 void 2629 tx_vlan_set(portid_t port_id, uint16_t vlan_id) 2630 { 2631 int vlan_offload; 2632 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2633 return; 2634 if (vlan_id_is_invalid(vlan_id)) 2635 return; 2636 2637 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 2638 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) { 2639 printf("Error, as QinQ has been enabled.\n"); 2640 return; 2641 } 2642 2643 tx_vlan_reset(port_id); 2644 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN; 2645 ports[port_id].tx_vlan_id = vlan_id; 2646 } 2647 2648 void 2649 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer) 2650 { 2651 int vlan_offload; 2652 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2653 return; 2654 if (vlan_id_is_invalid(vlan_id)) 2655 return; 2656 if (vlan_id_is_invalid(vlan_id_outer)) 2657 return; 2658 2659 vlan_offload = rte_eth_dev_get_vlan_offload(port_id); 2660 if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) { 2661 printf("Error, as QinQ hasn't been enabled.\n"); 2662 return; 2663 } 2664 2665 tx_vlan_reset(port_id); 2666 ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ; 2667 ports[port_id].tx_vlan_id = vlan_id; 2668 ports[port_id].tx_vlan_id_outer = vlan_id_outer; 2669 } 2670 2671 void 2672 tx_vlan_reset(portid_t port_id) 2673 { 2674 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2675 return; 2676 ports[port_id].tx_ol_flags &= ~(TESTPMD_TX_OFFLOAD_INSERT_VLAN | 2677 TESTPMD_TX_OFFLOAD_INSERT_QINQ); 2678 ports[port_id].tx_vlan_id = 0; 2679 ports[port_id].tx_vlan_id_outer = 0; 2680 } 2681 2682 void 2683 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on) 2684 { 2685 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2686 return; 2687 2688 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on); 2689 } 2690 2691 void 2692 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value) 2693 { 2694 uint16_t i; 2695 uint8_t existing_mapping_found = 0; 2696 2697 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2698 return; 2699 2700 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id))) 2701 return; 2702 2703 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) { 2704 printf("map_value not in required range 0..%d\n", 2705 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1); 2706 return; 2707 } 2708 2709 if (!is_rx) { /*then tx*/ 2710 for (i = 0; i < nb_tx_queue_stats_mappings; i++) { 2711 if ((tx_queue_stats_mappings[i].port_id == port_id) && 2712 (tx_queue_stats_mappings[i].queue_id == queue_id)) { 2713 tx_queue_stats_mappings[i].stats_counter_id = map_value; 2714 existing_mapping_found = 1; 2715 break; 2716 } 2717 } 2718 if (!existing_mapping_found) { /* A new additional mapping... */ 2719 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id; 2720 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id; 2721 tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value; 2722 nb_tx_queue_stats_mappings++; 2723 } 2724 } 2725 else { /*rx*/ 2726 for (i = 0; i < nb_rx_queue_stats_mappings; i++) { 2727 if ((rx_queue_stats_mappings[i].port_id == port_id) && 2728 (rx_queue_stats_mappings[i].queue_id == queue_id)) { 2729 rx_queue_stats_mappings[i].stats_counter_id = map_value; 2730 existing_mapping_found = 1; 2731 break; 2732 } 2733 } 2734 if (!existing_mapping_found) { /* A new additional mapping... */ 2735 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id; 2736 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id; 2737 rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value; 2738 nb_rx_queue_stats_mappings++; 2739 } 2740 } 2741 } 2742 2743 static inline void 2744 print_fdir_mask(struct rte_eth_fdir_masks *mask) 2745 { 2746 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask)); 2747 2748 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) 2749 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x," 2750 " tunnel_id: 0x%08x", 2751 mask->mac_addr_byte_mask, mask->tunnel_type_mask, 2752 rte_be_to_cpu_32(mask->tunnel_id_mask)); 2753 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) { 2754 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x", 2755 rte_be_to_cpu_32(mask->ipv4_mask.src_ip), 2756 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip)); 2757 2758 printf("\n src_port: 0x%04x, dst_port: 0x%04x", 2759 rte_be_to_cpu_16(mask->src_port_mask), 2760 rte_be_to_cpu_16(mask->dst_port_mask)); 2761 2762 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x", 2763 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]), 2764 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]), 2765 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]), 2766 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3])); 2767 2768 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x", 2769 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]), 2770 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]), 2771 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]), 2772 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3])); 2773 } 2774 2775 printf("\n"); 2776 } 2777 2778 static inline void 2779 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num) 2780 { 2781 struct rte_eth_flex_payload_cfg *cfg; 2782 uint32_t i, j; 2783 2784 for (i = 0; i < flex_conf->nb_payloads; i++) { 2785 cfg = &flex_conf->flex_set[i]; 2786 if (cfg->type == RTE_ETH_RAW_PAYLOAD) 2787 printf("\n RAW: "); 2788 else if (cfg->type == RTE_ETH_L2_PAYLOAD) 2789 printf("\n L2_PAYLOAD: "); 2790 else if (cfg->type == RTE_ETH_L3_PAYLOAD) 2791 printf("\n L3_PAYLOAD: "); 2792 else if (cfg->type == RTE_ETH_L4_PAYLOAD) 2793 printf("\n L4_PAYLOAD: "); 2794 else 2795 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type); 2796 for (j = 0; j < num; j++) 2797 printf(" %-5u", cfg->src_offset[j]); 2798 } 2799 printf("\n"); 2800 } 2801 2802 static char * 2803 flowtype_to_str(uint16_t flow_type) 2804 { 2805 struct flow_type_info { 2806 char str[32]; 2807 uint16_t ftype; 2808 }; 2809 2810 uint8_t i; 2811 static struct flow_type_info flowtype_str_table[] = { 2812 {"raw", RTE_ETH_FLOW_RAW}, 2813 {"ipv4", RTE_ETH_FLOW_IPV4}, 2814 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, 2815 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, 2816 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, 2817 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, 2818 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, 2819 {"ipv6", RTE_ETH_FLOW_IPV6}, 2820 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, 2821 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, 2822 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, 2823 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, 2824 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, 2825 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, 2826 {"port", RTE_ETH_FLOW_PORT}, 2827 {"vxlan", RTE_ETH_FLOW_VXLAN}, 2828 {"geneve", RTE_ETH_FLOW_GENEVE}, 2829 {"nvgre", RTE_ETH_FLOW_NVGRE}, 2830 }; 2831 2832 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) { 2833 if (flowtype_str_table[i].ftype == flow_type) 2834 return flowtype_str_table[i].str; 2835 } 2836 2837 return NULL; 2838 } 2839 2840 static inline void 2841 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num) 2842 { 2843 struct rte_eth_fdir_flex_mask *mask; 2844 uint32_t i, j; 2845 char *p; 2846 2847 for (i = 0; i < flex_conf->nb_flexmasks; i++) { 2848 mask = &flex_conf->flex_mask[i]; 2849 p = flowtype_to_str(mask->flow_type); 2850 printf("\n %s:\t", p ? p : "unknown"); 2851 for (j = 0; j < num; j++) 2852 printf(" %02x", mask->mask[j]); 2853 } 2854 printf("\n"); 2855 } 2856 2857 static inline void 2858 print_fdir_flow_type(uint32_t flow_types_mask) 2859 { 2860 int i; 2861 char *p; 2862 2863 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) { 2864 if (!(flow_types_mask & (1 << i))) 2865 continue; 2866 p = flowtype_to_str(i); 2867 if (p) 2868 printf(" %s", p); 2869 else 2870 printf(" unknown"); 2871 } 2872 printf("\n"); 2873 } 2874 2875 void 2876 fdir_get_infos(portid_t port_id) 2877 { 2878 struct rte_eth_fdir_stats fdir_stat; 2879 struct rte_eth_fdir_info fdir_info; 2880 int ret; 2881 2882 static const char *fdir_stats_border = "########################"; 2883 2884 if (port_id_is_invalid(port_id, ENABLED_WARN)) 2885 return; 2886 ret = rte_eth_dev_filter_supported(port_id, RTE_ETH_FILTER_FDIR); 2887 if (ret < 0) { 2888 printf("\n FDIR is not supported on port %-2d\n", 2889 port_id); 2890 return; 2891 } 2892 2893 memset(&fdir_info, 0, sizeof(fdir_info)); 2894 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR, 2895 RTE_ETH_FILTER_INFO, &fdir_info); 2896 memset(&fdir_stat, 0, sizeof(fdir_stat)); 2897 rte_eth_dev_filter_ctrl(port_id, RTE_ETH_FILTER_FDIR, 2898 RTE_ETH_FILTER_STATS, &fdir_stat); 2899 printf("\n %s FDIR infos for port %-2d %s\n", 2900 fdir_stats_border, port_id, fdir_stats_border); 2901 printf(" MODE: "); 2902 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT) 2903 printf(" PERFECT\n"); 2904 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) 2905 printf(" PERFECT-MAC-VLAN\n"); 2906 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) 2907 printf(" PERFECT-TUNNEL\n"); 2908 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE) 2909 printf(" SIGNATURE\n"); 2910 else 2911 printf(" DISABLE\n"); 2912 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN 2913 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) { 2914 printf(" SUPPORTED FLOW TYPE: "); 2915 print_fdir_flow_type(fdir_info.flow_types_mask[0]); 2916 } 2917 printf(" FLEX PAYLOAD INFO:\n"); 2918 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n" 2919 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n" 2920 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n", 2921 fdir_info.max_flexpayload, fdir_info.flex_payload_limit, 2922 fdir_info.flex_payload_unit, 2923 fdir_info.max_flex_payload_segment_num, 2924 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num); 2925 printf(" MASK: "); 2926 print_fdir_mask(&fdir_info.mask); 2927 if (fdir_info.flex_conf.nb_payloads > 0) { 2928 printf(" FLEX PAYLOAD SRC OFFSET:"); 2929 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload); 2930 } 2931 if (fdir_info.flex_conf.nb_flexmasks > 0) { 2932 printf(" FLEX MASK CFG:"); 2933 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload); 2934 } 2935 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n", 2936 fdir_stat.guarant_cnt, fdir_stat.best_cnt); 2937 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n", 2938 fdir_info.guarant_spc, fdir_info.best_spc); 2939 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n" 2940 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n" 2941 " add: %-10"PRIu64" remove: %"PRIu64"\n" 2942 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n", 2943 fdir_stat.collision, fdir_stat.free, 2944 fdir_stat.maxhash, fdir_stat.maxlen, 2945 fdir_stat.add, fdir_stat.remove, 2946 fdir_stat.f_add, fdir_stat.f_remove); 2947 printf(" %s############################%s\n", 2948 fdir_stats_border, fdir_stats_border); 2949 } 2950 2951 void 2952 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg) 2953 { 2954 struct rte_port *port; 2955 struct rte_eth_fdir_flex_conf *flex_conf; 2956 int i, idx = 0; 2957 2958 port = &ports[port_id]; 2959 flex_conf = &port->dev_conf.fdir_conf.flex_conf; 2960 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) { 2961 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) { 2962 idx = i; 2963 break; 2964 } 2965 } 2966 if (i >= RTE_ETH_FLOW_MAX) { 2967 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) { 2968 idx = flex_conf->nb_flexmasks; 2969 flex_conf->nb_flexmasks++; 2970 } else { 2971 printf("The flex mask table is full. Can not set flex" 2972 " mask for flow_type(%u).", cfg->flow_type); 2973 return; 2974 } 2975 } 2976 (void)rte_memcpy(&flex_conf->flex_mask[idx], 2977 cfg, 2978 sizeof(struct rte_eth_fdir_flex_mask)); 2979 } 2980 2981 void 2982 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg) 2983 { 2984 struct rte_port *port; 2985 struct rte_eth_fdir_flex_conf *flex_conf; 2986 int i, idx = 0; 2987 2988 port = &ports[port_id]; 2989 flex_conf = &port->dev_conf.fdir_conf.flex_conf; 2990 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) { 2991 if (cfg->type == flex_conf->flex_set[i].type) { 2992 idx = i; 2993 break; 2994 } 2995 } 2996 if (i >= RTE_ETH_PAYLOAD_MAX) { 2997 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) { 2998 idx = flex_conf->nb_payloads; 2999 flex_conf->nb_payloads++; 3000 } else { 3001 printf("The flex payload table is full. Can not set" 3002 " flex payload for type(%u).", cfg->type); 3003 return; 3004 } 3005 } 3006 (void)rte_memcpy(&flex_conf->flex_set[idx], 3007 cfg, 3008 sizeof(struct rte_eth_flex_payload_cfg)); 3009 3010 } 3011 3012 #ifdef RTE_LIBRTE_IXGBE_PMD 3013 void 3014 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on) 3015 { 3016 int diag; 3017 3018 if (is_rx) 3019 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on); 3020 else 3021 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on); 3022 3023 if (diag == 0) 3024 return; 3025 if(is_rx) 3026 printf("rte_pmd_ixgbe_set_vf_rx for port_id=%d failed " 3027 "diag=%d\n", port_id, diag); 3028 else 3029 printf("rte_pmd_ixgbe_set_vf_tx for port_id=%d failed " 3030 "diag=%d\n", port_id, diag); 3031 3032 } 3033 #endif 3034 3035 int 3036 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate) 3037 { 3038 int diag; 3039 struct rte_eth_link link; 3040 3041 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3042 return 1; 3043 rte_eth_link_get_nowait(port_id, &link); 3044 if (rate > link.link_speed) { 3045 printf("Invalid rate value:%u bigger than link speed: %u\n", 3046 rate, link.link_speed); 3047 return 1; 3048 } 3049 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate); 3050 if (diag == 0) 3051 return diag; 3052 printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n", 3053 port_id, diag); 3054 return diag; 3055 } 3056 3057 #ifdef RTE_LIBRTE_IXGBE_PMD 3058 int 3059 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk) 3060 { 3061 int diag; 3062 3063 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate, q_msk); 3064 if (diag == 0) 3065 return diag; 3066 printf("rte_pmd_ixgbe_set_vf_rate_limit for port_id=%d failed diag=%d\n", 3067 port_id, diag); 3068 return diag; 3069 } 3070 #endif 3071 3072 /* 3073 * Functions to manage the set of filtered Multicast MAC addresses. 3074 * 3075 * A pool of filtered multicast MAC addresses is associated with each port. 3076 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses. 3077 * The address of the pool and the number of valid multicast MAC addresses 3078 * recorded in the pool are stored in the fields "mc_addr_pool" and 3079 * "mc_addr_nb" of the "rte_port" data structure. 3080 * 3081 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes 3082 * to be supplied a contiguous array of multicast MAC addresses. 3083 * To comply with this constraint, the set of multicast addresses recorded 3084 * into the pool are systematically compacted at the beginning of the pool. 3085 * Hence, when a multicast address is removed from the pool, all following 3086 * addresses, if any, are copied back to keep the set contiguous. 3087 */ 3088 #define MCAST_POOL_INC 32 3089 3090 static int 3091 mcast_addr_pool_extend(struct rte_port *port) 3092 { 3093 struct ether_addr *mc_pool; 3094 size_t mc_pool_size; 3095 3096 /* 3097 * If a free entry is available at the end of the pool, just 3098 * increment the number of recorded multicast addresses. 3099 */ 3100 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) { 3101 port->mc_addr_nb++; 3102 return 0; 3103 } 3104 3105 /* 3106 * [re]allocate a pool with MCAST_POOL_INC more entries. 3107 * The previous test guarantees that port->mc_addr_nb is a multiple 3108 * of MCAST_POOL_INC. 3109 */ 3110 mc_pool_size = sizeof(struct ether_addr) * (port->mc_addr_nb + 3111 MCAST_POOL_INC); 3112 mc_pool = (struct ether_addr *) realloc(port->mc_addr_pool, 3113 mc_pool_size); 3114 if (mc_pool == NULL) { 3115 printf("allocation of pool of %u multicast addresses failed\n", 3116 port->mc_addr_nb + MCAST_POOL_INC); 3117 return -ENOMEM; 3118 } 3119 3120 port->mc_addr_pool = mc_pool; 3121 port->mc_addr_nb++; 3122 return 0; 3123 3124 } 3125 3126 static void 3127 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx) 3128 { 3129 port->mc_addr_nb--; 3130 if (addr_idx == port->mc_addr_nb) { 3131 /* No need to recompact the set of multicast addressses. */ 3132 if (port->mc_addr_nb == 0) { 3133 /* free the pool of multicast addresses. */ 3134 free(port->mc_addr_pool); 3135 port->mc_addr_pool = NULL; 3136 } 3137 return; 3138 } 3139 memmove(&port->mc_addr_pool[addr_idx], 3140 &port->mc_addr_pool[addr_idx + 1], 3141 sizeof(struct ether_addr) * (port->mc_addr_nb - addr_idx)); 3142 } 3143 3144 static void 3145 eth_port_multicast_addr_list_set(uint8_t port_id) 3146 { 3147 struct rte_port *port; 3148 int diag; 3149 3150 port = &ports[port_id]; 3151 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool, 3152 port->mc_addr_nb); 3153 if (diag == 0) 3154 return; 3155 printf("rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n", 3156 port->mc_addr_nb, port_id, -diag); 3157 } 3158 3159 void 3160 mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr) 3161 { 3162 struct rte_port *port; 3163 uint32_t i; 3164 3165 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3166 return; 3167 3168 port = &ports[port_id]; 3169 3170 /* 3171 * Check that the added multicast MAC address is not already recorded 3172 * in the pool of multicast addresses. 3173 */ 3174 for (i = 0; i < port->mc_addr_nb; i++) { 3175 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) { 3176 printf("multicast address already filtered by port\n"); 3177 return; 3178 } 3179 } 3180 3181 if (mcast_addr_pool_extend(port) != 0) 3182 return; 3183 ether_addr_copy(mc_addr, &port->mc_addr_pool[i]); 3184 eth_port_multicast_addr_list_set(port_id); 3185 } 3186 3187 void 3188 mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr) 3189 { 3190 struct rte_port *port; 3191 uint32_t i; 3192 3193 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3194 return; 3195 3196 port = &ports[port_id]; 3197 3198 /* 3199 * Search the pool of multicast MAC addresses for the removed address. 3200 */ 3201 for (i = 0; i < port->mc_addr_nb; i++) { 3202 if (is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) 3203 break; 3204 } 3205 if (i == port->mc_addr_nb) { 3206 printf("multicast address not filtered by port %d\n", port_id); 3207 return; 3208 } 3209 3210 mcast_addr_pool_remove(port, i); 3211 eth_port_multicast_addr_list_set(port_id); 3212 } 3213 3214 void 3215 port_dcb_info_display(uint8_t port_id) 3216 { 3217 struct rte_eth_dcb_info dcb_info; 3218 uint16_t i; 3219 int ret; 3220 static const char *border = "================"; 3221 3222 if (port_id_is_invalid(port_id, ENABLED_WARN)) 3223 return; 3224 3225 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info); 3226 if (ret) { 3227 printf("\n Failed to get dcb infos on port %-2d\n", 3228 port_id); 3229 return; 3230 } 3231 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border); 3232 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs); 3233 printf("\n TC : "); 3234 for (i = 0; i < dcb_info.nb_tcs; i++) 3235 printf("\t%4d", i); 3236 printf("\n Priority : "); 3237 for (i = 0; i < dcb_info.nb_tcs; i++) 3238 printf("\t%4d", dcb_info.prio_tc[i]); 3239 printf("\n BW percent :"); 3240 for (i = 0; i < dcb_info.nb_tcs; i++) 3241 printf("\t%4d%%", dcb_info.tc_bws[i]); 3242 printf("\n RXQ base : "); 3243 for (i = 0; i < dcb_info.nb_tcs; i++) 3244 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base); 3245 printf("\n RXQ number :"); 3246 for (i = 0; i < dcb_info.nb_tcs; i++) 3247 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue); 3248 printf("\n TXQ base : "); 3249 for (i = 0; i < dcb_info.nb_tcs; i++) 3250 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base); 3251 printf("\n TXQ number :"); 3252 for (i = 0; i < dcb_info.nb_tcs; i++) 3253 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue); 3254 printf("\n"); 3255 } 3256 3257 uint8_t * 3258 open_ddp_package_file(const char *file_path, uint32_t *size) 3259 { 3260 FILE *fh = fopen(file_path, "rb"); 3261 uint32_t pkg_size; 3262 uint8_t *buf = NULL; 3263 int ret = 0; 3264 3265 if (size) 3266 *size = 0; 3267 3268 if (fh == NULL) { 3269 printf("%s: Failed to open %s\n", __func__, file_path); 3270 return buf; 3271 } 3272 3273 ret = fseek(fh, 0, SEEK_END); 3274 if (ret < 0) { 3275 fclose(fh); 3276 printf("%s: File operations failed\n", __func__); 3277 return buf; 3278 } 3279 3280 pkg_size = ftell(fh); 3281 3282 buf = (uint8_t *)malloc(pkg_size); 3283 if (!buf) { 3284 fclose(fh); 3285 printf("%s: Failed to malloc memory\n", __func__); 3286 return buf; 3287 } 3288 3289 ret = fseek(fh, 0, SEEK_SET); 3290 if (ret < 0) { 3291 fclose(fh); 3292 printf("%s: File seek operation failed\n", __func__); 3293 close_ddp_package_file(buf); 3294 return NULL; 3295 } 3296 3297 ret = fread(buf, 1, pkg_size, fh); 3298 if (ret < 0) { 3299 fclose(fh); 3300 printf("%s: File read operation failed\n", __func__); 3301 close_ddp_package_file(buf); 3302 return NULL; 3303 } 3304 3305 if (size) 3306 *size = pkg_size; 3307 3308 fclose(fh); 3309 3310 return buf; 3311 } 3312 3313 int 3314 close_ddp_package_file(uint8_t *buf) 3315 { 3316 if (buf) { 3317 free((void *)buf); 3318 return 0; 3319 } 3320 3321 return -1; 3322 } 3323