1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation.
3 * Copyright 2013-2014 6WIND S.A.
13 #include <sys/queue.h>
14 #include <sys/types.h>
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_debug.h>
23 #include <rte_memory.h>
24 #include <rte_memcpy.h>
25 #include <rte_memzone.h>
26 #include <rte_launch.h>
28 #include <rte_per_lcore.h>
29 #include <rte_lcore.h>
30 #include <rte_branch_prediction.h>
31 #include <rte_mempool.h>
33 #include <rte_interrupts.h>
35 #include <rte_ether.h>
36 #include <rte_ethdev.h>
37 #include <rte_string_fns.h>
38 #include <rte_cycles.h>
41 #include <rte_errno.h>
43 #include <rte_pmd_ixgbe.h>
46 #include <rte_pmd_i40e.h>
49 #include <rte_pmd_bnxt.h>
54 #include <rte_hexdump.h>
57 #include "cmdline_mtr.h"
59 #define ETHDEV_FWVERS_LEN 32
61 #ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
62 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
64 #define CLOCK_TYPE_ID CLOCK_MONOTONIC
67 #define NS_PER_SEC 1E9
69 static char *flowtype_to_str(uint16_t flow_type);
72 enum tx_pkt_split split;
76 .split = TX_PKT_SPLIT_OFF,
80 .split = TX_PKT_SPLIT_ON,
84 .split = TX_PKT_SPLIT_RND,
89 const struct rss_type_info rss_type_table[] = {
90 { "all", RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP | RTE_ETH_RSS_TCP |
91 RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP | RTE_ETH_RSS_L2_PAYLOAD |
92 RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP | RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP |
93 RTE_ETH_RSS_GTPU | RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_MPLS},
95 { "eth", RTE_ETH_RSS_ETH },
96 { "l2-src-only", RTE_ETH_RSS_L2_SRC_ONLY },
97 { "l2-dst-only", RTE_ETH_RSS_L2_DST_ONLY },
98 { "vlan", RTE_ETH_RSS_VLAN },
99 { "s-vlan", RTE_ETH_RSS_S_VLAN },
100 { "c-vlan", RTE_ETH_RSS_C_VLAN },
101 { "ipv4", RTE_ETH_RSS_IPV4 },
102 { "ipv4-frag", RTE_ETH_RSS_FRAG_IPV4 },
103 { "ipv4-tcp", RTE_ETH_RSS_NONFRAG_IPV4_TCP },
104 { "ipv4-udp", RTE_ETH_RSS_NONFRAG_IPV4_UDP },
105 { "ipv4-sctp", RTE_ETH_RSS_NONFRAG_IPV4_SCTP },
106 { "ipv4-other", RTE_ETH_RSS_NONFRAG_IPV4_OTHER },
107 { "ipv6", RTE_ETH_RSS_IPV6 },
108 { "ipv6-frag", RTE_ETH_RSS_FRAG_IPV6 },
109 { "ipv6-tcp", RTE_ETH_RSS_NONFRAG_IPV6_TCP },
110 { "ipv6-udp", RTE_ETH_RSS_NONFRAG_IPV6_UDP },
111 { "ipv6-sctp", RTE_ETH_RSS_NONFRAG_IPV6_SCTP },
112 { "ipv6-other", RTE_ETH_RSS_NONFRAG_IPV6_OTHER },
113 { "l2-payload", RTE_ETH_RSS_L2_PAYLOAD },
114 { "ipv6-ex", RTE_ETH_RSS_IPV6_EX },
115 { "ipv6-tcp-ex", RTE_ETH_RSS_IPV6_TCP_EX },
116 { "ipv6-udp-ex", RTE_ETH_RSS_IPV6_UDP_EX },
117 { "port", RTE_ETH_RSS_PORT },
118 { "vxlan", RTE_ETH_RSS_VXLAN },
119 { "geneve", RTE_ETH_RSS_GENEVE },
120 { "nvgre", RTE_ETH_RSS_NVGRE },
121 { "ip", RTE_ETH_RSS_IP },
122 { "udp", RTE_ETH_RSS_UDP },
123 { "tcp", RTE_ETH_RSS_TCP },
124 { "sctp", RTE_ETH_RSS_SCTP },
125 { "tunnel", RTE_ETH_RSS_TUNNEL },
126 { "l3-pre32", RTE_ETH_RSS_L3_PRE32 },
127 { "l3-pre40", RTE_ETH_RSS_L3_PRE40 },
128 { "l3-pre48", RTE_ETH_RSS_L3_PRE48 },
129 { "l3-pre56", RTE_ETH_RSS_L3_PRE56 },
130 { "l3-pre64", RTE_ETH_RSS_L3_PRE64 },
131 { "l3-pre96", RTE_ETH_RSS_L3_PRE96 },
132 { "l3-src-only", RTE_ETH_RSS_L3_SRC_ONLY },
133 { "l3-dst-only", RTE_ETH_RSS_L3_DST_ONLY },
134 { "l4-src-only", RTE_ETH_RSS_L4_SRC_ONLY },
135 { "l4-dst-only", RTE_ETH_RSS_L4_DST_ONLY },
136 { "esp", RTE_ETH_RSS_ESP },
137 { "ah", RTE_ETH_RSS_AH },
138 { "l2tpv3", RTE_ETH_RSS_L2TPV3 },
139 { "pfcp", RTE_ETH_RSS_PFCP },
140 { "pppoe", RTE_ETH_RSS_PPPOE },
141 { "gtpu", RTE_ETH_RSS_GTPU },
142 { "ecpri", RTE_ETH_RSS_ECPRI },
143 { "mpls", RTE_ETH_RSS_MPLS },
144 { "ipv4-chksum", RTE_ETH_RSS_IPV4_CHKSUM },
145 { "l4-chksum", RTE_ETH_RSS_L4_CHKSUM },
149 static const struct {
150 enum rte_eth_fec_mode mode;
152 } fec_mode_name[] = {
154 .mode = RTE_ETH_FEC_NOFEC,
158 .mode = RTE_ETH_FEC_AUTO,
162 .mode = RTE_ETH_FEC_BASER,
166 .mode = RTE_ETH_FEC_RS,
172 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
174 char buf[RTE_ETHER_ADDR_FMT_SIZE];
175 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
176 printf("%s%s", name, buf);
180 nic_xstats_display_periodic(portid_t port_id)
182 struct xstat_display_info *xstats_info;
183 uint64_t *prev_values, *curr_values;
184 uint64_t diff_value, value_rate;
185 struct timespec cur_time;
192 xstats_info = &ports[port_id].xstats_info;
194 ids_supp_sz = xstats_info->ids_supp_sz;
195 if (ids_supp_sz == 0)
200 ids_supp = xstats_info->ids_supp;
201 prev_values = xstats_info->prev_values;
202 curr_values = xstats_info->curr_values;
204 rc = rte_eth_xstats_get_by_id(port_id, ids_supp, curr_values,
206 if (rc != (int)ids_supp_sz) {
208 "Failed to get values of %zu xstats for port %u - return code %d\n",
209 ids_supp_sz, port_id, rc);
214 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
217 ns = cur_time.tv_sec * NS_PER_SEC;
218 ns += cur_time.tv_nsec;
220 if (xstats_info->prev_ns != 0)
221 diff_ns = ns - xstats_info->prev_ns;
222 xstats_info->prev_ns = ns;
225 printf("%-31s%-17s%s\n", " ", "Value", "Rate (since last show)");
226 for (i = 0; i < ids_supp_sz; i++) {
227 diff_value = (curr_values[i] > prev_values[i]) ?
228 (curr_values[i] - prev_values[i]) : 0;
229 prev_values[i] = curr_values[i];
230 value_rate = diff_ns > 0 ?
231 (double)diff_value / diff_ns * NS_PER_SEC : 0;
233 printf(" %-25s%12"PRIu64" %15"PRIu64"\n",
234 xstats_display[i].name, curr_values[i], value_rate);
239 nic_stats_display(portid_t port_id)
241 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
242 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
243 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
244 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
245 static uint64_t prev_ns[RTE_MAX_ETHPORTS];
246 struct timespec cur_time;
247 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
249 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
250 struct rte_eth_stats stats;
252 static const char *nic_stats_border = "########################";
254 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
258 rte_eth_stats_get(port_id, &stats);
259 printf("\n %s NIC statistics for port %-2d %s\n",
260 nic_stats_border, port_id, nic_stats_border);
262 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
263 "%-"PRIu64"\n", stats.ipackets, stats.imissed, stats.ibytes);
264 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
265 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
266 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
267 "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
270 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
273 ns = cur_time.tv_sec * NS_PER_SEC;
274 ns += cur_time.tv_nsec;
276 if (prev_ns[port_id] != 0)
277 diff_ns = ns - prev_ns[port_id];
278 prev_ns[port_id] = ns;
281 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
282 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
283 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
284 (stats.opackets - prev_pkts_tx[port_id]) : 0;
285 prev_pkts_rx[port_id] = stats.ipackets;
286 prev_pkts_tx[port_id] = stats.opackets;
287 mpps_rx = diff_ns > 0 ?
288 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
289 mpps_tx = diff_ns > 0 ?
290 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
292 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
293 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
294 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
295 (stats.obytes - prev_bytes_tx[port_id]) : 0;
296 prev_bytes_rx[port_id] = stats.ibytes;
297 prev_bytes_tx[port_id] = stats.obytes;
298 mbps_rx = diff_ns > 0 ?
299 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
300 mbps_tx = diff_ns > 0 ?
301 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
303 printf("\n Throughput (since last show)\n");
304 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
305 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
306 mpps_tx, mbps_tx * 8);
308 if (xstats_display_num > 0)
309 nic_xstats_display_periodic(port_id);
311 printf(" %s############################%s\n",
312 nic_stats_border, nic_stats_border);
316 nic_stats_clear(portid_t port_id)
320 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
325 ret = rte_eth_stats_reset(port_id);
328 "%s: Error: failed to reset stats (port %u): %s",
329 __func__, port_id, strerror(-ret));
333 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
338 "%s: Error: failed to get stats (port %u): %s",
339 __func__, port_id, strerror(ret));
342 printf("\n NIC statistics for port %d cleared\n", port_id);
346 nic_xstats_display(portid_t port_id)
348 struct rte_eth_xstat *xstats;
349 int cnt_xstats, idx_xstat;
350 struct rte_eth_xstat_name *xstats_names;
352 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
356 printf("###### NIC extended statistics for port %-2d\n", port_id);
357 if (!rte_eth_dev_is_valid_port(port_id)) {
358 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
363 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
364 if (cnt_xstats < 0) {
365 fprintf(stderr, "Error: Cannot get count of xstats\n");
369 /* Get id-name lookup table */
370 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
371 if (xstats_names == NULL) {
372 fprintf(stderr, "Cannot allocate memory for xstats lookup\n");
375 if (cnt_xstats != rte_eth_xstats_get_names(
376 port_id, xstats_names, cnt_xstats)) {
377 fprintf(stderr, "Error: Cannot get xstats lookup\n");
382 /* Get stats themselves */
383 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
384 if (xstats == NULL) {
385 fprintf(stderr, "Cannot allocate memory for xstats\n");
389 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
390 fprintf(stderr, "Error: Unable to get xstats\n");
397 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
398 if (xstats_hide_zero && !xstats[idx_xstat].value)
400 printf("%s: %"PRIu64"\n",
401 xstats_names[idx_xstat].name,
402 xstats[idx_xstat].value);
409 nic_xstats_clear(portid_t port_id)
413 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
418 ret = rte_eth_xstats_reset(port_id);
421 "%s: Error: failed to reset xstats (port %u): %s\n",
422 __func__, port_id, strerror(-ret));
426 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
430 fprintf(stderr, "%s: Error: failed to get stats (port %u): %s",
431 __func__, port_id, strerror(ret));
437 get_queue_state_name(uint8_t queue_state)
439 if (queue_state == RTE_ETH_QUEUE_STATE_STOPPED)
441 else if (queue_state == RTE_ETH_QUEUE_STATE_STARTED)
443 else if (queue_state == RTE_ETH_QUEUE_STATE_HAIRPIN)
450 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
452 struct rte_eth_burst_mode mode;
453 struct rte_eth_rxq_info qinfo;
455 static const char *info_border = "*********************";
457 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
460 "Failed to retrieve information for port: %u, RX queue: %hu\nerror desc: %s(%d)\n",
461 port_id, queue_id, strerror(-rc), rc);
465 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
466 info_border, port_id, queue_id, info_border);
468 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
469 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
470 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
471 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
472 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
473 printf("\nRX drop packets: %s",
474 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
475 printf("\nRX deferred start: %s",
476 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
477 printf("\nRX scattered packets: %s",
478 (qinfo.scattered_rx != 0) ? "on" : "off");
479 printf("\nRx queue state: %s", get_queue_state_name(qinfo.queue_state));
480 if (qinfo.rx_buf_size != 0)
481 printf("\nRX buffer size: %hu", qinfo.rx_buf_size);
482 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
484 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
485 printf("\nBurst mode: %s%s",
487 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
488 " (per queue)" : "");
494 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
496 struct rte_eth_burst_mode mode;
497 struct rte_eth_txq_info qinfo;
499 static const char *info_border = "*********************";
501 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
504 "Failed to retrieve information for port: %u, TX queue: %hu\nerror desc: %s(%d)\n",
505 port_id, queue_id, strerror(-rc), rc);
509 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
510 info_border, port_id, queue_id, info_border);
512 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
513 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
514 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
515 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
516 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
517 printf("\nTX deferred start: %s",
518 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
519 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
520 printf("\nTx queue state: %s", get_queue_state_name(qinfo.queue_state));
522 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
523 printf("\nBurst mode: %s%s",
525 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
526 " (per queue)" : "");
531 static int bus_match_all(const struct rte_bus *bus, const void *data)
539 device_infos_display_speeds(uint32_t speed_capa)
541 printf("\n\tDevice speed capability:");
542 if (speed_capa == RTE_ETH_LINK_SPEED_AUTONEG)
543 printf(" Autonegotiate (all speeds)");
544 if (speed_capa & RTE_ETH_LINK_SPEED_FIXED)
545 printf(" Disable autonegotiate (fixed speed) ");
546 if (speed_capa & RTE_ETH_LINK_SPEED_10M_HD)
547 printf(" 10 Mbps half-duplex ");
548 if (speed_capa & RTE_ETH_LINK_SPEED_10M)
549 printf(" 10 Mbps full-duplex ");
550 if (speed_capa & RTE_ETH_LINK_SPEED_100M_HD)
551 printf(" 100 Mbps half-duplex ");
552 if (speed_capa & RTE_ETH_LINK_SPEED_100M)
553 printf(" 100 Mbps full-duplex ");
554 if (speed_capa & RTE_ETH_LINK_SPEED_1G)
556 if (speed_capa & RTE_ETH_LINK_SPEED_2_5G)
557 printf(" 2.5 Gbps ");
558 if (speed_capa & RTE_ETH_LINK_SPEED_5G)
560 if (speed_capa & RTE_ETH_LINK_SPEED_10G)
562 if (speed_capa & RTE_ETH_LINK_SPEED_20G)
564 if (speed_capa & RTE_ETH_LINK_SPEED_25G)
566 if (speed_capa & RTE_ETH_LINK_SPEED_40G)
568 if (speed_capa & RTE_ETH_LINK_SPEED_50G)
570 if (speed_capa & RTE_ETH_LINK_SPEED_56G)
572 if (speed_capa & RTE_ETH_LINK_SPEED_100G)
573 printf(" 100 Gbps ");
574 if (speed_capa & RTE_ETH_LINK_SPEED_200G)
575 printf(" 200 Gbps ");
579 device_infos_display(const char *identifier)
581 static const char *info_border = "*********************";
582 struct rte_bus *start = NULL, *next;
583 struct rte_dev_iterator dev_iter;
584 char name[RTE_ETH_NAME_MAX_LEN];
585 struct rte_ether_addr mac_addr;
586 struct rte_device *dev;
587 struct rte_devargs da;
589 struct rte_eth_dev_info dev_info;
592 memset(&da, 0, sizeof(da));
596 if (rte_devargs_parsef(&da, "%s", identifier)) {
597 fprintf(stderr, "cannot parse identifier\n");
602 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
605 if (identifier && da.bus != next)
608 /* Skip buses that don't have iterate method */
609 if (!next->dev_iterate)
612 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
613 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
617 /* Check for matching device if identifier is present */
619 strncmp(da.name, dev->name, strlen(dev->name)))
621 printf("\n%s Infos for device %s %s\n",
622 info_border, dev->name, info_border);
623 printf("Bus name: %s", dev->bus->name);
624 printf("\nDriver name: %s", dev->driver->name);
625 printf("\nDevargs: %s",
626 dev->devargs ? dev->devargs->args : "");
627 printf("\nConnect to socket: %d", dev->numa_node);
630 /* List ports with matching device name */
631 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
632 printf("\n\tPort id: %-2d", port_id);
633 if (eth_macaddr_get_print_err(port_id,
635 print_ethaddr("\n\tMAC address: ",
637 rte_eth_dev_get_name_by_port(port_id, name);
638 printf("\n\tDevice name: %s", name);
639 if (rte_eth_dev_info_get(port_id, &dev_info) == 0)
640 device_infos_display_speeds(dev_info.speed_capa);
645 rte_devargs_reset(&da);
649 print_dev_capabilities(uint64_t capabilities)
651 uint64_t single_capa;
656 if (capabilities == 0)
659 begin = __builtin_ctzll(capabilities);
660 end = sizeof(capabilities) * CHAR_BIT - __builtin_clzll(capabilities);
662 single_capa = 1ULL << begin;
663 for (bit = begin; bit < end; bit++) {
664 if (capabilities & single_capa)
666 rte_eth_dev_capability_name(single_capa));
672 port_infos_display(portid_t port_id)
674 struct rte_port *port;
675 struct rte_ether_addr mac_addr;
676 struct rte_eth_link link;
677 struct rte_eth_dev_info dev_info;
679 struct rte_mempool * mp;
680 static const char *info_border = "*********************";
682 char name[RTE_ETH_NAME_MAX_LEN];
684 char fw_version[ETHDEV_FWVERS_LEN];
686 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
690 port = &ports[port_id];
691 ret = eth_link_get_nowait_print_err(port_id, &link);
695 ret = eth_dev_info_get_print_err(port_id, &dev_info);
699 printf("\n%s Infos for port %-2d %s\n",
700 info_border, port_id, info_border);
701 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
702 print_ethaddr("MAC address: ", &mac_addr);
703 rte_eth_dev_get_name_by_port(port_id, name);
704 printf("\nDevice name: %s", name);
705 printf("\nDriver name: %s", dev_info.driver_name);
707 if (rte_eth_dev_fw_version_get(port_id, fw_version,
708 ETHDEV_FWVERS_LEN) == 0)
709 printf("\nFirmware-version: %s", fw_version);
711 printf("\nFirmware-version: %s", "not available");
713 if (dev_info.device->devargs && dev_info.device->devargs->args)
714 printf("\nDevargs: %s", dev_info.device->devargs->args);
715 printf("\nConnect to socket: %u", port->socket_id);
717 if (port_numa[port_id] != NUMA_NO_CONFIG) {
718 mp = mbuf_pool_find(port_numa[port_id], 0);
720 printf("\nmemory allocation on the socket: %d",
723 printf("\nmemory allocation on the socket: %u",port->socket_id);
725 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
726 printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
727 printf("Link duplex: %s\n", (link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
728 ("full-duplex") : ("half-duplex"));
729 printf("Autoneg status: %s\n", (link.link_autoneg == RTE_ETH_LINK_AUTONEG) ?
732 if (!rte_eth_dev_get_mtu(port_id, &mtu))
733 printf("MTU: %u\n", mtu);
735 printf("Promiscuous mode: %s\n",
736 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
737 printf("Allmulticast mode: %s\n",
738 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
739 printf("Maximum number of MAC addresses: %u\n",
740 (unsigned int)(port->dev_info.max_mac_addrs));
741 printf("Maximum number of MAC addresses of hash filtering: %u\n",
742 (unsigned int)(port->dev_info.max_hash_mac_addrs));
744 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
745 if (vlan_offload >= 0){
746 printf("VLAN offload: \n");
747 if (vlan_offload & RTE_ETH_VLAN_STRIP_OFFLOAD)
748 printf(" strip on, ");
750 printf(" strip off, ");
752 if (vlan_offload & RTE_ETH_VLAN_FILTER_OFFLOAD)
753 printf("filter on, ");
755 printf("filter off, ");
757 if (vlan_offload & RTE_ETH_VLAN_EXTEND_OFFLOAD)
758 printf("extend on, ");
760 printf("extend off, ");
762 if (vlan_offload & RTE_ETH_QINQ_STRIP_OFFLOAD)
763 printf("qinq strip on\n");
765 printf("qinq strip off\n");
768 if (dev_info.hash_key_size > 0)
769 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
770 if (dev_info.reta_size > 0)
771 printf("Redirection table size: %u\n", dev_info.reta_size);
772 if (!dev_info.flow_type_rss_offloads)
773 printf("No RSS offload flow type is supported.\n");
778 printf("Supported RSS offload flow types:\n");
779 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
780 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
781 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
783 p = flowtype_to_str(i);
787 printf(" user defined %d\n", i);
791 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
792 printf("Maximum configurable length of RX packet: %u\n",
793 dev_info.max_rx_pktlen);
794 printf("Maximum configurable size of LRO aggregated packet: %u\n",
795 dev_info.max_lro_pkt_size);
796 if (dev_info.max_vfs)
797 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
798 if (dev_info.max_vmdq_pools)
799 printf("Maximum number of VMDq pools: %u\n",
800 dev_info.max_vmdq_pools);
802 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
803 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
804 printf("Max possible number of RXDs per queue: %hu\n",
805 dev_info.rx_desc_lim.nb_max);
806 printf("Min possible number of RXDs per queue: %hu\n",
807 dev_info.rx_desc_lim.nb_min);
808 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
810 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
811 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
812 printf("Max possible number of TXDs per queue: %hu\n",
813 dev_info.tx_desc_lim.nb_max);
814 printf("Min possible number of TXDs per queue: %hu\n",
815 dev_info.tx_desc_lim.nb_min);
816 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
817 printf("Max segment number per packet: %hu\n",
818 dev_info.tx_desc_lim.nb_seg_max);
819 printf("Max segment number per MTU/TSO: %hu\n",
820 dev_info.tx_desc_lim.nb_mtu_seg_max);
822 printf("Device capabilities: 0x%"PRIx64"(", dev_info.dev_capa);
823 print_dev_capabilities(dev_info.dev_capa);
825 /* Show switch info only if valid switch domain and port id is set */
826 if (dev_info.switch_info.domain_id !=
827 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
828 if (dev_info.switch_info.name)
829 printf("Switch name: %s\n", dev_info.switch_info.name);
831 printf("Switch domain Id: %u\n",
832 dev_info.switch_info.domain_id);
833 printf("Switch Port Id: %u\n",
834 dev_info.switch_info.port_id);
835 if ((dev_info.dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE) != 0)
836 printf("Switch Rx domain: %u\n",
837 dev_info.switch_info.rx_domain);
842 port_summary_header_display(void)
844 uint16_t port_number;
846 port_number = rte_eth_dev_count_avail();
847 printf("Number of available ports: %i\n", port_number);
848 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
849 "Driver", "Status", "Link");
853 port_summary_display(portid_t port_id)
855 struct rte_ether_addr mac_addr;
856 struct rte_eth_link link;
857 struct rte_eth_dev_info dev_info;
858 char name[RTE_ETH_NAME_MAX_LEN];
861 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
866 ret = eth_link_get_nowait_print_err(port_id, &link);
870 ret = eth_dev_info_get_print_err(port_id, &dev_info);
874 rte_eth_dev_get_name_by_port(port_id, name);
875 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
879 printf("%-4d " RTE_ETHER_ADDR_PRT_FMT " %-12s %-14s %-8s %s\n",
880 port_id, RTE_ETHER_ADDR_BYTES(&mac_addr), name,
881 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
882 rte_eth_link_speed_to_str(link.link_speed));
886 port_eeprom_display(portid_t port_id)
888 struct rte_dev_eeprom_info einfo;
890 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
895 int len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
896 if (len_eeprom < 0) {
897 switch (len_eeprom) {
899 fprintf(stderr, "port index %d invalid\n", port_id);
902 fprintf(stderr, "operation not supported by device\n");
905 fprintf(stderr, "device is removed\n");
908 fprintf(stderr, "Unable to get EEPROM: %d\n",
915 char buf[len_eeprom];
917 einfo.length = len_eeprom;
920 ret = rte_eth_dev_get_eeprom(port_id, &einfo);
924 fprintf(stderr, "port index %d invalid\n", port_id);
927 fprintf(stderr, "operation not supported by device\n");
930 fprintf(stderr, "device is removed\n");
933 fprintf(stderr, "Unable to get EEPROM: %d\n", ret);
938 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
939 printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
943 port_module_eeprom_display(portid_t port_id)
945 struct rte_eth_dev_module_info minfo;
946 struct rte_dev_eeprom_info einfo;
949 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
955 ret = rte_eth_dev_get_module_info(port_id, &minfo);
959 fprintf(stderr, "port index %d invalid\n", port_id);
962 fprintf(stderr, "operation not supported by device\n");
965 fprintf(stderr, "device is removed\n");
968 fprintf(stderr, "Unable to get module EEPROM: %d\n",
975 char buf[minfo.eeprom_len];
977 einfo.length = minfo.eeprom_len;
980 ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
984 fprintf(stderr, "port index %d invalid\n", port_id);
987 fprintf(stderr, "operation not supported by device\n");
990 fprintf(stderr, "device is removed\n");
993 fprintf(stderr, "Unable to get module EEPROM: %d\n",
1000 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
1001 printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
1005 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1009 if (port_id == (portid_t)RTE_PORT_ALL)
1012 RTE_ETH_FOREACH_DEV(pid)
1016 if (warning == ENABLED_WARN)
1017 fprintf(stderr, "Invalid port %d\n", port_id);
1022 void print_valid_ports(void)
1026 printf("The valid ports array is [");
1027 RTE_ETH_FOREACH_DEV(pid) {
1034 vlan_id_is_invalid(uint16_t vlan_id)
1038 fprintf(stderr, "Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1043 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1045 const struct rte_pci_device *pci_dev;
1046 const struct rte_bus *bus;
1049 if (reg_off & 0x3) {
1051 "Port register offset 0x%X not aligned on a 4-byte boundary\n",
1052 (unsigned int)reg_off);
1056 if (!ports[port_id].dev_info.device) {
1057 fprintf(stderr, "Invalid device\n");
1061 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1062 if (bus && !strcmp(bus->name, "pci")) {
1063 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1065 fprintf(stderr, "Not a PCI device\n");
1069 pci_len = pci_dev->mem_resource[0].len;
1070 if (reg_off >= pci_len) {
1072 "Port %d: register offset %u (0x%X) out of port PCI resource (length=%"PRIu64")\n",
1073 port_id, (unsigned int)reg_off, (unsigned int)reg_off,
1081 reg_bit_pos_is_invalid(uint8_t bit_pos)
1085 fprintf(stderr, "Invalid bit position %d (must be <= 31)\n", bit_pos);
1089 #define display_port_and_reg_off(port_id, reg_off) \
1090 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1093 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1095 display_port_and_reg_off(port_id, (unsigned)reg_off);
1096 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1100 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1105 if (port_id_is_invalid(port_id, ENABLED_WARN))
1107 if (port_reg_off_is_invalid(port_id, reg_off))
1109 if (reg_bit_pos_is_invalid(bit_x))
1111 reg_v = port_id_pci_reg_read(port_id, reg_off);
1112 display_port_and_reg_off(port_id, (unsigned)reg_off);
1113 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1117 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1118 uint8_t bit1_pos, uint8_t bit2_pos)
1124 if (port_id_is_invalid(port_id, ENABLED_WARN))
1126 if (port_reg_off_is_invalid(port_id, reg_off))
1128 if (reg_bit_pos_is_invalid(bit1_pos))
1130 if (reg_bit_pos_is_invalid(bit2_pos))
1132 if (bit1_pos > bit2_pos)
1133 l_bit = bit2_pos, h_bit = bit1_pos;
1135 l_bit = bit1_pos, h_bit = bit2_pos;
1137 reg_v = port_id_pci_reg_read(port_id, reg_off);
1140 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1141 display_port_and_reg_off(port_id, (unsigned)reg_off);
1142 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1143 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1147 port_reg_display(portid_t port_id, uint32_t reg_off)
1151 if (port_id_is_invalid(port_id, ENABLED_WARN))
1153 if (port_reg_off_is_invalid(port_id, reg_off))
1155 reg_v = port_id_pci_reg_read(port_id, reg_off);
1156 display_port_reg_value(port_id, reg_off, reg_v);
1160 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1165 if (port_id_is_invalid(port_id, ENABLED_WARN))
1167 if (port_reg_off_is_invalid(port_id, reg_off))
1169 if (reg_bit_pos_is_invalid(bit_pos))
1172 fprintf(stderr, "Invalid bit value %d (must be 0 or 1)\n",
1176 reg_v = port_id_pci_reg_read(port_id, reg_off);
1178 reg_v &= ~(1 << bit_pos);
1180 reg_v |= (1 << bit_pos);
1181 port_id_pci_reg_write(port_id, reg_off, reg_v);
1182 display_port_reg_value(port_id, reg_off, reg_v);
1186 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1187 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1194 if (port_id_is_invalid(port_id, ENABLED_WARN))
1196 if (port_reg_off_is_invalid(port_id, reg_off))
1198 if (reg_bit_pos_is_invalid(bit1_pos))
1200 if (reg_bit_pos_is_invalid(bit2_pos))
1202 if (bit1_pos > bit2_pos)
1203 l_bit = bit2_pos, h_bit = bit1_pos;
1205 l_bit = bit1_pos, h_bit = bit2_pos;
1207 if ((h_bit - l_bit) < 31)
1208 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1212 if (value > max_v) {
1213 fprintf(stderr, "Invalid value %u (0x%x) must be < %u (0x%x)\n",
1214 (unsigned)value, (unsigned)value,
1215 (unsigned)max_v, (unsigned)max_v);
1218 reg_v = port_id_pci_reg_read(port_id, reg_off);
1219 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1220 reg_v |= (value << l_bit); /* Set changed bits */
1221 port_id_pci_reg_write(port_id, reg_off, reg_v);
1222 display_port_reg_value(port_id, reg_off, reg_v);
1226 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1228 if (port_id_is_invalid(port_id, ENABLED_WARN))
1230 if (port_reg_off_is_invalid(port_id, reg_off))
1232 port_id_pci_reg_write(port_id, reg_off, reg_v);
1233 display_port_reg_value(port_id, reg_off, reg_v);
1237 port_mtu_set(portid_t port_id, uint16_t mtu)
1239 struct rte_port *port = &ports[port_id];
1242 if (port_id_is_invalid(port_id, ENABLED_WARN))
1245 if (port->need_reconfig == 0) {
1246 diag = rte_eth_dev_set_mtu(port_id, mtu);
1248 fprintf(stderr, "Set MTU failed. diag=%d\n", diag);
1253 port->dev_conf.rxmode.mtu = mtu;
1256 /* Generic flow management functions. */
1258 static struct port_flow_tunnel *
1259 port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
1261 struct port_flow_tunnel *flow_tunnel;
1263 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1264 if (flow_tunnel->id == port_tunnel_id)
1274 port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
1277 switch (tunnel->type) {
1281 case RTE_FLOW_ITEM_TYPE_VXLAN:
1284 case RTE_FLOW_ITEM_TYPE_GRE:
1287 case RTE_FLOW_ITEM_TYPE_NVGRE:
1290 case RTE_FLOW_ITEM_TYPE_GENEVE:
1298 struct port_flow_tunnel *
1299 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
1301 struct rte_port *port = &ports[port_id];
1302 struct port_flow_tunnel *flow_tunnel;
1304 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1305 if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
1314 void port_flow_tunnel_list(portid_t port_id)
1316 struct rte_port *port = &ports[port_id];
1317 struct port_flow_tunnel *flt;
1319 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1320 printf("port %u tunnel #%u type=%s",
1321 port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
1322 if (flt->tunnel.tun_id)
1323 printf(" id=%" PRIu64, flt->tunnel.tun_id);
1328 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
1330 struct rte_port *port = &ports[port_id];
1331 struct port_flow_tunnel *flt;
1333 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1334 if (flt->id == tunnel_id)
1338 LIST_REMOVE(flt, chain);
1340 printf("port %u: flow tunnel #%u destroyed\n",
1341 port_id, tunnel_id);
1345 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
1347 struct rte_port *port = &ports[port_id];
1348 enum rte_flow_item_type type;
1349 struct port_flow_tunnel *flt;
1351 if (!strcmp(ops->type, "vxlan"))
1352 type = RTE_FLOW_ITEM_TYPE_VXLAN;
1353 else if (!strcmp(ops->type, "gre"))
1354 type = RTE_FLOW_ITEM_TYPE_GRE;
1355 else if (!strcmp(ops->type, "nvgre"))
1356 type = RTE_FLOW_ITEM_TYPE_NVGRE;
1357 else if (!strcmp(ops->type, "geneve"))
1358 type = RTE_FLOW_ITEM_TYPE_GENEVE;
1360 fprintf(stderr, "cannot offload \"%s\" tunnel type\n",
1364 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1365 if (flt->tunnel.type == type)
1369 flt = calloc(1, sizeof(*flt));
1371 fprintf(stderr, "failed to allocate port flt object\n");
1374 flt->tunnel.type = type;
1375 flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
1376 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
1377 LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
1379 printf("port %d: flow tunnel #%u type %s\n",
1380 port_id, flt->id, ops->type);
1383 /** Generate a port_flow entry from attributes/pattern/actions. */
1384 static struct port_flow *
1385 port_flow_new(const struct rte_flow_attr *attr,
1386 const struct rte_flow_item *pattern,
1387 const struct rte_flow_action *actions,
1388 struct rte_flow_error *error)
1390 const struct rte_flow_conv_rule rule = {
1392 .pattern_ro = pattern,
1393 .actions_ro = actions,
1395 struct port_flow *pf;
1398 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1401 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1404 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1408 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1415 /** Print a message out of a flow error. */
1417 port_flow_complain(struct rte_flow_error *error)
1419 static const char *const errstrlist[] = {
1420 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1421 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1422 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1423 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1424 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1425 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1426 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1427 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1428 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1429 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1430 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1431 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1432 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1433 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1434 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1435 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1436 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1440 int err = rte_errno;
1442 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1443 !errstrlist[error->type])
1444 errstr = "unknown type";
1446 errstr = errstrlist[error->type];
1447 fprintf(stderr, "%s(): Caught PMD error type %d (%s): %s%s: %s\n",
1448 __func__, error->type, errstr,
1449 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1450 error->cause), buf) : "",
1451 error->message ? error->message : "(no stated reason)",
1454 switch (error->type) {
1455 case RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER:
1456 fprintf(stderr, "The status suggests the use of \"transfer\" "
1457 "as the possible cause of the failure. Make "
1458 "sure that the flow in question and its "
1459 "indirect components (if any) are managed "
1460 "via \"transfer\" proxy port. Use command "
1461 "\"show port (port_id) flow transfer proxy\" "
1462 "to figure out the proxy port ID\n");
1472 rss_config_display(struct rte_flow_action_rss *rss_conf)
1476 if (rss_conf == NULL) {
1477 fprintf(stderr, "Invalid rule\n");
1483 if (rss_conf->queue_num == 0)
1485 for (i = 0; i < rss_conf->queue_num; i++)
1486 printf(" %d", rss_conf->queue[i]);
1489 printf(" function: ");
1490 switch (rss_conf->func) {
1491 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1492 printf("default\n");
1494 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1495 printf("toeplitz\n");
1497 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1498 printf("simple_xor\n");
1500 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1501 printf("symmetric_toeplitz\n");
1504 printf("Unknown function\n");
1508 printf(" types:\n");
1509 if (rss_conf->types == 0) {
1513 for (i = 0; rss_type_table[i].str; i++) {
1514 if ((rss_conf->types &
1515 rss_type_table[i].rss_type) ==
1516 rss_type_table[i].rss_type &&
1517 rss_type_table[i].rss_type != 0)
1518 printf(" %s\n", rss_type_table[i].str);
1522 static struct port_indirect_action *
1523 action_get_by_id(portid_t port_id, uint32_t id)
1525 struct rte_port *port;
1526 struct port_indirect_action **ppia;
1527 struct port_indirect_action *pia = NULL;
1529 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1530 port_id == (portid_t)RTE_PORT_ALL)
1532 port = &ports[port_id];
1533 ppia = &port->actions_list;
1535 if ((*ppia)->id == id) {
1539 ppia = &(*ppia)->next;
1543 "Failed to find indirect action #%u on port %u\n",
1549 action_alloc(portid_t port_id, uint32_t id,
1550 struct port_indirect_action **action)
1552 struct rte_port *port;
1553 struct port_indirect_action **ppia;
1554 struct port_indirect_action *pia = NULL;
1557 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1558 port_id == (portid_t)RTE_PORT_ALL)
1560 port = &ports[port_id];
1561 if (id == UINT32_MAX) {
1562 /* taking first available ID */
1563 if (port->actions_list) {
1564 if (port->actions_list->id == UINT32_MAX - 1) {
1566 "Highest indirect action ID is already assigned, delete it first\n");
1569 id = port->actions_list->id + 1;
1574 pia = calloc(1, sizeof(*pia));
1577 "Allocation of port %u indirect action failed\n",
1581 ppia = &port->actions_list;
1582 while (*ppia && (*ppia)->id > id)
1583 ppia = &(*ppia)->next;
1584 if (*ppia && (*ppia)->id == id) {
1586 "Indirect action #%u is already assigned, delete it first\n",
1598 /** Create indirect action */
1600 port_action_handle_create(portid_t port_id, uint32_t id,
1601 const struct rte_flow_indir_action_conf *conf,
1602 const struct rte_flow_action *action)
1604 struct port_indirect_action *pia;
1606 struct rte_flow_error error;
1608 ret = action_alloc(port_id, id, &pia);
1611 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
1612 struct rte_flow_action_age *age =
1613 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
1615 pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
1616 age->context = &pia->age_type;
1617 } else if (action->type == RTE_FLOW_ACTION_TYPE_CONNTRACK) {
1618 struct rte_flow_action_conntrack *ct =
1619 (struct rte_flow_action_conntrack *)(uintptr_t)(action->conf);
1621 memcpy(ct, &conntrack_context, sizeof(*ct));
1623 /* Poisoning to make sure PMDs update it in case of error. */
1624 memset(&error, 0x22, sizeof(error));
1625 pia->handle = rte_flow_action_handle_create(port_id, conf, action,
1628 uint32_t destroy_id = pia->id;
1629 port_action_handle_destroy(port_id, 1, &destroy_id);
1630 return port_flow_complain(&error);
1632 pia->type = action->type;
1633 printf("Indirect action #%u created\n", pia->id);
1637 /** Destroy indirect action */
1639 port_action_handle_destroy(portid_t port_id,
1641 const uint32_t *actions)
1643 struct rte_port *port;
1644 struct port_indirect_action **tmp;
1648 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1649 port_id == (portid_t)RTE_PORT_ALL)
1651 port = &ports[port_id];
1652 tmp = &port->actions_list;
1656 for (i = 0; i != n; ++i) {
1657 struct rte_flow_error error;
1658 struct port_indirect_action *pia = *tmp;
1660 if (actions[i] != pia->id)
1663 * Poisoning to make sure PMDs update it in case
1666 memset(&error, 0x33, sizeof(error));
1668 if (pia->handle && rte_flow_action_handle_destroy(
1669 port_id, pia->handle, &error)) {
1670 ret = port_flow_complain(&error);
1674 printf("Indirect action #%u destroyed\n", pia->id);
1679 tmp = &(*tmp)->next;
1686 /** Get indirect action by port + id */
1687 struct rte_flow_action_handle *
1688 port_action_handle_get_by_id(portid_t port_id, uint32_t id)
1691 struct port_indirect_action *pia = action_get_by_id(port_id, id);
1693 return (pia) ? pia->handle : NULL;
1696 /** Update indirect action */
1698 port_action_handle_update(portid_t port_id, uint32_t id,
1699 const struct rte_flow_action *action)
1701 struct rte_flow_error error;
1702 struct rte_flow_action_handle *action_handle;
1703 struct port_indirect_action *pia;
1706 action_handle = port_action_handle_get_by_id(port_id, id);
1709 pia = action_get_by_id(port_id, id);
1712 switch (pia->type) {
1713 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1714 update = action->conf;
1720 if (rte_flow_action_handle_update(port_id, action_handle, update,
1722 return port_flow_complain(&error);
1724 printf("Indirect action #%u updated\n", id);
1729 port_action_handle_query(portid_t port_id, uint32_t id)
1731 struct rte_flow_error error;
1732 struct port_indirect_action *pia;
1734 struct rte_flow_query_count count;
1735 struct rte_flow_query_age age;
1736 struct rte_flow_action_conntrack ct;
1739 pia = action_get_by_id(port_id, id);
1742 switch (pia->type) {
1743 case RTE_FLOW_ACTION_TYPE_AGE:
1744 case RTE_FLOW_ACTION_TYPE_COUNT:
1748 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1749 id, pia->type, port_id);
1752 /* Poisoning to make sure PMDs update it in case of error. */
1753 memset(&error, 0x55, sizeof(error));
1754 memset(&query, 0, sizeof(query));
1755 if (rte_flow_action_handle_query(port_id, pia->handle, &query, &error))
1756 return port_flow_complain(&error);
1757 switch (pia->type) {
1758 case RTE_FLOW_ACTION_TYPE_AGE:
1759 printf("Indirect AGE action:\n"
1761 " sec_since_last_hit_valid: %u\n"
1762 " sec_since_last_hit: %" PRIu32 "\n",
1764 query.age.sec_since_last_hit_valid,
1765 query.age.sec_since_last_hit);
1767 case RTE_FLOW_ACTION_TYPE_COUNT:
1768 printf("Indirect COUNT action:\n"
1771 " hits: %" PRIu64 "\n"
1772 " bytes: %" PRIu64 "\n",
1773 query.count.hits_set,
1774 query.count.bytes_set,
1778 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1779 printf("Conntrack Context:\n"
1780 " Peer: %u, Flow dir: %s, Enable: %u\n"
1781 " Live: %u, SACK: %u, CACK: %u\n"
1782 " Packet dir: %s, Liberal: %u, State: %u\n"
1783 " Factor: %u, Retrans: %u, TCP flags: %u\n"
1784 " Last Seq: %u, Last ACK: %u\n"
1785 " Last Win: %u, Last End: %u\n",
1787 query.ct.is_original_dir ? "Original" : "Reply",
1788 query.ct.enable, query.ct.live_connection,
1789 query.ct.selective_ack, query.ct.challenge_ack_passed,
1790 query.ct.last_direction ? "Original" : "Reply",
1791 query.ct.liberal_mode, query.ct.state,
1792 query.ct.max_ack_window, query.ct.retransmission_limit,
1793 query.ct.last_index, query.ct.last_seq,
1794 query.ct.last_ack, query.ct.last_window,
1796 printf(" Original Dir:\n"
1797 " scale: %u, fin: %u, ack seen: %u\n"
1798 " unacked data: %u\n Sent end: %u,"
1799 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1800 query.ct.original_dir.scale,
1801 query.ct.original_dir.close_initiated,
1802 query.ct.original_dir.last_ack_seen,
1803 query.ct.original_dir.data_unacked,
1804 query.ct.original_dir.sent_end,
1805 query.ct.original_dir.reply_end,
1806 query.ct.original_dir.max_win,
1807 query.ct.original_dir.max_ack);
1808 printf(" Reply Dir:\n"
1809 " scale: %u, fin: %u, ack seen: %u\n"
1810 " unacked data: %u\n Sent end: %u,"
1811 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1812 query.ct.reply_dir.scale,
1813 query.ct.reply_dir.close_initiated,
1814 query.ct.reply_dir.last_ack_seen,
1815 query.ct.reply_dir.data_unacked,
1816 query.ct.reply_dir.sent_end,
1817 query.ct.reply_dir.reply_end,
1818 query.ct.reply_dir.max_win,
1819 query.ct.reply_dir.max_ack);
1823 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1824 id, pia->type, port_id);
1830 static struct port_flow_tunnel *
1831 port_flow_tunnel_offload_cmd_prep(portid_t port_id,
1832 const struct rte_flow_item *pattern,
1833 const struct rte_flow_action *actions,
1834 const struct tunnel_ops *tunnel_ops)
1837 struct rte_port *port;
1838 struct port_flow_tunnel *pft;
1839 struct rte_flow_error error;
1841 port = &ports[port_id];
1842 pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
1844 fprintf(stderr, "failed to locate port flow tunnel #%u\n",
1848 if (tunnel_ops->actions) {
1849 uint32_t num_actions;
1850 const struct rte_flow_action *aptr;
1852 ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
1854 &pft->num_pmd_actions,
1857 port_flow_complain(&error);
1860 for (aptr = actions, num_actions = 1;
1861 aptr->type != RTE_FLOW_ACTION_TYPE_END;
1862 aptr++, num_actions++);
1863 pft->actions = malloc(
1864 (num_actions + pft->num_pmd_actions) *
1865 sizeof(actions[0]));
1866 if (!pft->actions) {
1867 rte_flow_tunnel_action_decap_release(
1868 port_id, pft->actions,
1869 pft->num_pmd_actions, &error);
1872 rte_memcpy(pft->actions, pft->pmd_actions,
1873 pft->num_pmd_actions * sizeof(actions[0]));
1874 rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
1875 num_actions * sizeof(actions[0]));
1877 if (tunnel_ops->items) {
1879 const struct rte_flow_item *iptr;
1881 ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
1883 &pft->num_pmd_items,
1886 port_flow_complain(&error);
1889 for (iptr = pattern, num_items = 1;
1890 iptr->type != RTE_FLOW_ITEM_TYPE_END;
1891 iptr++, num_items++);
1892 pft->items = malloc((num_items + pft->num_pmd_items) *
1893 sizeof(pattern[0]));
1895 rte_flow_tunnel_item_release(
1896 port_id, pft->pmd_items,
1897 pft->num_pmd_items, &error);
1900 rte_memcpy(pft->items, pft->pmd_items,
1901 pft->num_pmd_items * sizeof(pattern[0]));
1902 rte_memcpy(pft->items + pft->num_pmd_items, pattern,
1903 num_items * sizeof(pattern[0]));
1910 port_flow_tunnel_offload_cmd_release(portid_t port_id,
1911 const struct tunnel_ops *tunnel_ops,
1912 struct port_flow_tunnel *pft)
1914 struct rte_flow_error error;
1916 if (tunnel_ops->actions) {
1918 rte_flow_tunnel_action_decap_release(
1919 port_id, pft->pmd_actions,
1920 pft->num_pmd_actions, &error);
1921 pft->actions = NULL;
1922 pft->pmd_actions = NULL;
1924 if (tunnel_ops->items) {
1926 rte_flow_tunnel_item_release(port_id, pft->pmd_items,
1930 pft->pmd_items = NULL;
1934 /** Add port meter policy */
1936 port_meter_policy_add(portid_t port_id, uint32_t policy_id,
1937 const struct rte_flow_action *actions)
1939 struct rte_mtr_error error;
1940 const struct rte_flow_action *act = actions;
1941 const struct rte_flow_action *start;
1942 struct rte_mtr_meter_policy_params policy;
1943 uint32_t i = 0, act_n;
1946 for (i = 0; i < RTE_COLORS; i++) {
1947 for (act_n = 0, start = act;
1948 act->type != RTE_FLOW_ACTION_TYPE_END; act++)
1950 if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
1951 policy.actions[i] = start;
1953 policy.actions[i] = NULL;
1956 ret = rte_mtr_meter_policy_add(port_id,
1960 print_mtr_err_msg(&error);
1964 /** Validate flow rule. */
1966 port_flow_validate(portid_t port_id,
1967 const struct rte_flow_attr *attr,
1968 const struct rte_flow_item *pattern,
1969 const struct rte_flow_action *actions,
1970 const struct tunnel_ops *tunnel_ops)
1972 struct rte_flow_error error;
1973 struct port_flow_tunnel *pft = NULL;
1976 /* Poisoning to make sure PMDs update it in case of error. */
1977 memset(&error, 0x11, sizeof(error));
1978 if (tunnel_ops->enabled) {
1979 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
1980 actions, tunnel_ops);
1984 pattern = pft->items;
1986 actions = pft->actions;
1988 ret = rte_flow_validate(port_id, attr, pattern, actions, &error);
1989 if (tunnel_ops->enabled)
1990 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
1992 return port_flow_complain(&error);
1993 printf("Flow rule validated\n");
1997 /** Return age action structure if exists, otherwise NULL. */
1998 static struct rte_flow_action_age *
1999 age_action_get(const struct rte_flow_action *actions)
2001 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2002 switch (actions->type) {
2003 case RTE_FLOW_ACTION_TYPE_AGE:
2004 return (struct rte_flow_action_age *)
2005 (uintptr_t)actions->conf;
2013 /** Create flow rule. */
2015 port_flow_create(portid_t port_id,
2016 const struct rte_flow_attr *attr,
2017 const struct rte_flow_item *pattern,
2018 const struct rte_flow_action *actions,
2019 const struct tunnel_ops *tunnel_ops)
2021 struct rte_flow *flow;
2022 struct rte_port *port;
2023 struct port_flow *pf;
2025 struct rte_flow_error error;
2026 struct port_flow_tunnel *pft = NULL;
2027 struct rte_flow_action_age *age = age_action_get(actions);
2029 port = &ports[port_id];
2030 if (port->flow_list) {
2031 if (port->flow_list->id == UINT32_MAX) {
2033 "Highest rule ID is already assigned, delete it first");
2036 id = port->flow_list->id + 1;
2038 if (tunnel_ops->enabled) {
2039 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2040 actions, tunnel_ops);
2044 pattern = pft->items;
2046 actions = pft->actions;
2048 pf = port_flow_new(attr, pattern, actions, &error);
2050 return port_flow_complain(&error);
2052 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
2053 age->context = &pf->age_type;
2055 /* Poisoning to make sure PMDs update it in case of error. */
2056 memset(&error, 0x22, sizeof(error));
2057 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
2059 if (tunnel_ops->enabled)
2060 port_flow_tunnel_offload_cmd_release(port_id,
2063 return port_flow_complain(&error);
2065 pf->next = port->flow_list;
2068 port->flow_list = pf;
2069 if (tunnel_ops->enabled)
2070 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2071 printf("Flow rule #%u created\n", pf->id);
2075 /** Destroy a number of flow rules. */
2077 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
2079 struct rte_port *port;
2080 struct port_flow **tmp;
2084 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2085 port_id == (portid_t)RTE_PORT_ALL)
2087 port = &ports[port_id];
2088 tmp = &port->flow_list;
2092 for (i = 0; i != n; ++i) {
2093 struct rte_flow_error error;
2094 struct port_flow *pf = *tmp;
2096 if (rule[i] != pf->id)
2099 * Poisoning to make sure PMDs update it in case
2102 memset(&error, 0x33, sizeof(error));
2103 if (rte_flow_destroy(port_id, pf->flow, &error)) {
2104 ret = port_flow_complain(&error);
2107 printf("Flow rule #%u destroyed\n", pf->id);
2113 tmp = &(*tmp)->next;
2119 /** Remove all flow rules. */
2121 port_flow_flush(portid_t port_id)
2123 struct rte_flow_error error;
2124 struct rte_port *port;
2127 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2128 port_id == (portid_t)RTE_PORT_ALL)
2131 port = &ports[port_id];
2133 if (port->flow_list == NULL)
2136 /* Poisoning to make sure PMDs update it in case of error. */
2137 memset(&error, 0x44, sizeof(error));
2138 if (rte_flow_flush(port_id, &error)) {
2139 port_flow_complain(&error);
2142 while (port->flow_list) {
2143 struct port_flow *pf = port->flow_list->next;
2145 free(port->flow_list);
2146 port->flow_list = pf;
2151 /** Dump flow rules. */
2153 port_flow_dump(portid_t port_id, bool dump_all, uint32_t rule_id,
2154 const char *file_name)
2157 FILE *file = stdout;
2158 struct rte_flow_error error;
2159 struct rte_port *port;
2160 struct port_flow *pflow;
2161 struct rte_flow *tmpFlow = NULL;
2164 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2165 port_id == (portid_t)RTE_PORT_ALL)
2169 port = &ports[port_id];
2170 pflow = port->flow_list;
2172 if (rule_id != pflow->id) {
2173 pflow = pflow->next;
2175 tmpFlow = pflow->flow;
2181 if (found == false) {
2182 fprintf(stderr, "Failed to dump to flow %d\n", rule_id);
2187 if (file_name && strlen(file_name)) {
2188 file = fopen(file_name, "w");
2190 fprintf(stderr, "Failed to create file %s: %s\n",
2191 file_name, strerror(errno));
2197 ret = rte_flow_dev_dump(port_id, tmpFlow, file, &error);
2199 ret = rte_flow_dev_dump(port_id, NULL, file, &error);
2201 port_flow_complain(&error);
2202 fprintf(stderr, "Failed to dump flow: %s\n", strerror(-ret));
2204 printf("Flow dump finished\n");
2205 if (file_name && strlen(file_name))
2210 /** Query a flow rule. */
2212 port_flow_query(portid_t port_id, uint32_t rule,
2213 const struct rte_flow_action *action)
2215 struct rte_flow_error error;
2216 struct rte_port *port;
2217 struct port_flow *pf;
2220 struct rte_flow_query_count count;
2221 struct rte_flow_action_rss rss_conf;
2222 struct rte_flow_query_age age;
2226 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2227 port_id == (portid_t)RTE_PORT_ALL)
2229 port = &ports[port_id];
2230 for (pf = port->flow_list; pf; pf = pf->next)
2234 fprintf(stderr, "Flow rule #%u not found\n", rule);
2237 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2238 &name, sizeof(name),
2239 (void *)(uintptr_t)action->type, &error);
2241 return port_flow_complain(&error);
2242 switch (action->type) {
2243 case RTE_FLOW_ACTION_TYPE_COUNT:
2244 case RTE_FLOW_ACTION_TYPE_RSS:
2245 case RTE_FLOW_ACTION_TYPE_AGE:
2248 fprintf(stderr, "Cannot query action type %d (%s)\n",
2249 action->type, name);
2252 /* Poisoning to make sure PMDs update it in case of error. */
2253 memset(&error, 0x55, sizeof(error));
2254 memset(&query, 0, sizeof(query));
2255 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
2256 return port_flow_complain(&error);
2257 switch (action->type) {
2258 case RTE_FLOW_ACTION_TYPE_COUNT:
2262 " hits: %" PRIu64 "\n"
2263 " bytes: %" PRIu64 "\n",
2265 query.count.hits_set,
2266 query.count.bytes_set,
2270 case RTE_FLOW_ACTION_TYPE_RSS:
2271 rss_config_display(&query.rss_conf);
2273 case RTE_FLOW_ACTION_TYPE_AGE:
2276 " sec_since_last_hit_valid: %u\n"
2277 " sec_since_last_hit: %" PRIu32 "\n",
2280 query.age.sec_since_last_hit_valid,
2281 query.age.sec_since_last_hit);
2285 "Cannot display result for action type %d (%s)\n",
2286 action->type, name);
2292 /** List simply and destroy all aged flows. */
2294 port_flow_aged(portid_t port_id, uint8_t destroy)
2297 int nb_context, total = 0, idx;
2298 struct rte_flow_error error;
2299 enum age_action_context_type *type;
2301 struct port_flow *pf;
2302 struct port_indirect_action *pia;
2305 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2306 port_id == (portid_t)RTE_PORT_ALL)
2308 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
2309 printf("Port %u total aged flows: %d\n", port_id, total);
2311 port_flow_complain(&error);
2316 contexts = malloc(sizeof(void *) * total);
2317 if (contexts == NULL) {
2318 fprintf(stderr, "Cannot allocate contexts for aged flow\n");
2321 printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
2322 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
2323 if (nb_context != total) {
2325 "Port:%d get aged flows count(%d) != total(%d)\n",
2326 port_id, nb_context, total);
2331 for (idx = 0; idx < nb_context; idx++) {
2332 if (!contexts[idx]) {
2333 fprintf(stderr, "Error: get Null context in port %u\n",
2337 type = (enum age_action_context_type *)contexts[idx];
2339 case ACTION_AGE_CONTEXT_TYPE_FLOW:
2340 ctx.pf = container_of(type, struct port_flow, age_type);
2341 printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
2345 ctx.pf->rule.attr->group,
2346 ctx.pf->rule.attr->priority,
2347 ctx.pf->rule.attr->ingress ? 'i' : '-',
2348 ctx.pf->rule.attr->egress ? 'e' : '-',
2349 ctx.pf->rule.attr->transfer ? 't' : '-');
2350 if (destroy && !port_flow_destroy(port_id, 1,
2354 case ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION:
2355 ctx.pia = container_of(type,
2356 struct port_indirect_action, age_type);
2357 printf("%-20s\t%" PRIu32 "\n", "Indirect action",
2361 fprintf(stderr, "Error: invalid context type %u\n",
2366 printf("\n%d flows destroyed\n", total);
2370 /** List flow rules. */
2372 port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group)
2374 struct rte_port *port;
2375 struct port_flow *pf;
2376 struct port_flow *list = NULL;
2379 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2380 port_id == (portid_t)RTE_PORT_ALL)
2382 port = &ports[port_id];
2383 if (!port->flow_list)
2385 /* Sort flows by group, priority and ID. */
2386 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
2387 struct port_flow **tmp;
2388 const struct rte_flow_attr *curr = pf->rule.attr;
2391 /* Filter out unwanted groups. */
2392 for (i = 0; i != n; ++i)
2393 if (curr->group == group[i])
2398 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
2399 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
2401 if (curr->group > comp->group ||
2402 (curr->group == comp->group &&
2403 curr->priority > comp->priority) ||
2404 (curr->group == comp->group &&
2405 curr->priority == comp->priority &&
2406 pf->id > (*tmp)->id))
2413 printf("ID\tGroup\tPrio\tAttr\tRule\n");
2414 for (pf = list; pf != NULL; pf = pf->tmp) {
2415 const struct rte_flow_item *item = pf->rule.pattern;
2416 const struct rte_flow_action *action = pf->rule.actions;
2419 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
2421 pf->rule.attr->group,
2422 pf->rule.attr->priority,
2423 pf->rule.attr->ingress ? 'i' : '-',
2424 pf->rule.attr->egress ? 'e' : '-',
2425 pf->rule.attr->transfer ? 't' : '-');
2426 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
2427 if ((uint32_t)item->type > INT_MAX)
2428 name = "PMD_INTERNAL";
2429 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
2430 &name, sizeof(name),
2431 (void *)(uintptr_t)item->type,
2434 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
2435 printf("%s ", name);
2439 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
2440 if ((uint32_t)action->type > INT_MAX)
2441 name = "PMD_INTERNAL";
2442 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2443 &name, sizeof(name),
2444 (void *)(uintptr_t)action->type,
2447 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
2448 printf(" %s", name);
2455 /** Restrict ingress traffic to the defined flow rules. */
2457 port_flow_isolate(portid_t port_id, int set)
2459 struct rte_flow_error error;
2461 /* Poisoning to make sure PMDs update it in case of error. */
2462 memset(&error, 0x66, sizeof(error));
2463 if (rte_flow_isolate(port_id, set, &error))
2464 return port_flow_complain(&error);
2465 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
2467 set ? "now restricted" : "not restricted anymore");
2472 * RX/TX ring descriptors display functions.
2475 rx_queue_id_is_invalid(queueid_t rxq_id)
2477 if (rxq_id < nb_rxq)
2479 fprintf(stderr, "Invalid RX queue %d (must be < nb_rxq=%d)\n",
2485 tx_queue_id_is_invalid(queueid_t txq_id)
2487 if (txq_id < nb_txq)
2489 fprintf(stderr, "Invalid TX queue %d (must be < nb_txq=%d)\n",
2495 get_rx_ring_size(portid_t port_id, queueid_t rxq_id, uint16_t *ring_size)
2497 struct rte_port *port = &ports[port_id];
2498 struct rte_eth_rxq_info rx_qinfo;
2501 ret = rte_eth_rx_queue_info_get(port_id, rxq_id, &rx_qinfo);
2503 *ring_size = rx_qinfo.nb_desc;
2507 if (ret != -ENOTSUP)
2510 * If the rte_eth_rx_queue_info_get is not support for this PMD,
2511 * ring_size stored in testpmd will be used for validity verification.
2512 * When configure the rxq by rte_eth_rx_queue_setup with nb_rx_desc
2513 * being 0, it will use a default value provided by PMDs to setup this
2514 * rxq. If the default value is 0, it will use the
2515 * RTE_ETH_DEV_FALLBACK_RX_RINGSIZE to setup this rxq.
2517 if (port->nb_rx_desc[rxq_id])
2518 *ring_size = port->nb_rx_desc[rxq_id];
2519 else if (port->dev_info.default_rxportconf.ring_size)
2520 *ring_size = port->dev_info.default_rxportconf.ring_size;
2522 *ring_size = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
2527 get_tx_ring_size(portid_t port_id, queueid_t txq_id, uint16_t *ring_size)
2529 struct rte_port *port = &ports[port_id];
2530 struct rte_eth_txq_info tx_qinfo;
2533 ret = rte_eth_tx_queue_info_get(port_id, txq_id, &tx_qinfo);
2535 *ring_size = tx_qinfo.nb_desc;
2539 if (ret != -ENOTSUP)
2542 * If the rte_eth_tx_queue_info_get is not support for this PMD,
2543 * ring_size stored in testpmd will be used for validity verification.
2544 * When configure the txq by rte_eth_tx_queue_setup with nb_tx_desc
2545 * being 0, it will use a default value provided by PMDs to setup this
2546 * txq. If the default value is 0, it will use the
2547 * RTE_ETH_DEV_FALLBACK_TX_RINGSIZE to setup this txq.
2549 if (port->nb_tx_desc[txq_id])
2550 *ring_size = port->nb_tx_desc[txq_id];
2551 else if (port->dev_info.default_txportconf.ring_size)
2552 *ring_size = port->dev_info.default_txportconf.ring_size;
2554 *ring_size = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
2559 rx_desc_id_is_invalid(portid_t port_id, queueid_t rxq_id, uint16_t rxdesc_id)
2564 ret = get_rx_ring_size(port_id, rxq_id, &ring_size);
2568 if (rxdesc_id < ring_size)
2571 fprintf(stderr, "Invalid RX descriptor %u (must be < ring_size=%u)\n",
2572 rxdesc_id, ring_size);
2577 tx_desc_id_is_invalid(portid_t port_id, queueid_t txq_id, uint16_t txdesc_id)
2582 ret = get_tx_ring_size(port_id, txq_id, &ring_size);
2586 if (txdesc_id < ring_size)
2589 fprintf(stderr, "Invalid TX descriptor %u (must be < ring_size=%u)\n",
2590 txdesc_id, ring_size);
2594 static const struct rte_memzone *
2595 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
2597 char mz_name[RTE_MEMZONE_NAMESIZE];
2598 const struct rte_memzone *mz;
2600 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
2601 port_id, q_id, ring_name);
2602 mz = rte_memzone_lookup(mz_name);
2605 "%s ring memory zoneof (port %d, queue %d) not found (zone name = %s\n",
2606 ring_name, port_id, q_id, mz_name);
2610 union igb_ring_dword {
2613 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
2623 struct igb_ring_desc_32_bytes {
2624 union igb_ring_dword lo_dword;
2625 union igb_ring_dword hi_dword;
2626 union igb_ring_dword resv1;
2627 union igb_ring_dword resv2;
2630 struct igb_ring_desc_16_bytes {
2631 union igb_ring_dword lo_dword;
2632 union igb_ring_dword hi_dword;
2636 ring_rxd_display_dword(union igb_ring_dword dword)
2638 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
2639 (unsigned)dword.words.hi);
2643 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
2644 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2647 __rte_unused portid_t port_id,
2651 struct igb_ring_desc_16_bytes *ring =
2652 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2653 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
2655 struct rte_eth_dev_info dev_info;
2657 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2661 if (strstr(dev_info.driver_name, "i40e") != NULL) {
2662 /* 32 bytes RX descriptor, i40e only */
2663 struct igb_ring_desc_32_bytes *ring =
2664 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
2665 ring[desc_id].lo_dword.dword =
2666 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2667 ring_rxd_display_dword(ring[desc_id].lo_dword);
2668 ring[desc_id].hi_dword.dword =
2669 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2670 ring_rxd_display_dword(ring[desc_id].hi_dword);
2671 ring[desc_id].resv1.dword =
2672 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
2673 ring_rxd_display_dword(ring[desc_id].resv1);
2674 ring[desc_id].resv2.dword =
2675 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
2676 ring_rxd_display_dword(ring[desc_id].resv2);
2681 /* 16 bytes RX descriptor */
2682 ring[desc_id].lo_dword.dword =
2683 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2684 ring_rxd_display_dword(ring[desc_id].lo_dword);
2685 ring[desc_id].hi_dword.dword =
2686 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2687 ring_rxd_display_dword(ring[desc_id].hi_dword);
2691 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
2693 struct igb_ring_desc_16_bytes *ring;
2694 struct igb_ring_desc_16_bytes txd;
2696 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
2697 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
2698 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
2699 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
2700 (unsigned)txd.lo_dword.words.lo,
2701 (unsigned)txd.lo_dword.words.hi,
2702 (unsigned)txd.hi_dword.words.lo,
2703 (unsigned)txd.hi_dword.words.hi);
2707 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
2709 const struct rte_memzone *rx_mz;
2711 if (rx_desc_id_is_invalid(port_id, rxq_id, rxd_id))
2713 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
2716 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
2720 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
2722 const struct rte_memzone *tx_mz;
2724 if (tx_desc_id_is_invalid(port_id, txq_id, txd_id))
2726 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
2729 ring_tx_descriptor_display(tx_mz, txd_id);
2733 fwd_lcores_config_display(void)
2737 printf("List of forwarding lcores:");
2738 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
2739 printf(" %2u", fwd_lcores_cpuids[lc_id]);
2743 rxtx_config_display(void)
2748 printf(" %s packet forwarding%s packets/burst=%d\n",
2749 cur_fwd_eng->fwd_mode_name,
2750 retry_enabled == 0 ? "" : " with retry",
2753 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
2754 printf(" packet len=%u - nb packet segments=%d\n",
2755 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
2757 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
2758 nb_fwd_lcores, nb_fwd_ports);
2760 RTE_ETH_FOREACH_DEV(pid) {
2761 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
2762 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
2763 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
2764 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
2765 struct rte_eth_rxq_info rx_qinfo;
2766 struct rte_eth_txq_info tx_qinfo;
2767 uint16_t rx_free_thresh_tmp;
2768 uint16_t tx_free_thresh_tmp;
2769 uint16_t tx_rs_thresh_tmp;
2770 uint16_t nb_rx_desc_tmp;
2771 uint16_t nb_tx_desc_tmp;
2772 uint64_t offloads_tmp;
2773 uint8_t pthresh_tmp;
2774 uint8_t hthresh_tmp;
2775 uint8_t wthresh_tmp;
2778 /* per port config */
2779 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
2780 (unsigned int)pid, nb_rxq, nb_txq);
2782 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
2783 ports[pid].dev_conf.rxmode.offloads,
2784 ports[pid].dev_conf.txmode.offloads);
2786 /* per rx queue config only for first queue to be less verbose */
2787 for (qid = 0; qid < 1; qid++) {
2788 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
2790 nb_rx_desc_tmp = nb_rx_desc[qid];
2791 rx_free_thresh_tmp =
2792 rx_conf[qid].rx_free_thresh;
2793 pthresh_tmp = rx_conf[qid].rx_thresh.pthresh;
2794 hthresh_tmp = rx_conf[qid].rx_thresh.hthresh;
2795 wthresh_tmp = rx_conf[qid].rx_thresh.wthresh;
2796 offloads_tmp = rx_conf[qid].offloads;
2798 nb_rx_desc_tmp = rx_qinfo.nb_desc;
2799 rx_free_thresh_tmp =
2800 rx_qinfo.conf.rx_free_thresh;
2801 pthresh_tmp = rx_qinfo.conf.rx_thresh.pthresh;
2802 hthresh_tmp = rx_qinfo.conf.rx_thresh.hthresh;
2803 wthresh_tmp = rx_qinfo.conf.rx_thresh.wthresh;
2804 offloads_tmp = rx_qinfo.conf.offloads;
2807 printf(" RX queue: %d\n", qid);
2808 printf(" RX desc=%d - RX free threshold=%d\n",
2809 nb_rx_desc_tmp, rx_free_thresh_tmp);
2810 printf(" RX threshold registers: pthresh=%d hthresh=%d "
2812 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2813 printf(" RX Offloads=0x%"PRIx64, offloads_tmp);
2814 if (rx_conf->share_group > 0)
2815 printf(" share_group=%u share_qid=%u",
2816 rx_conf->share_group,
2817 rx_conf->share_qid);
2821 /* per tx queue config only for first queue to be less verbose */
2822 for (qid = 0; qid < 1; qid++) {
2823 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
2825 nb_tx_desc_tmp = nb_tx_desc[qid];
2826 tx_free_thresh_tmp =
2827 tx_conf[qid].tx_free_thresh;
2828 pthresh_tmp = tx_conf[qid].tx_thresh.pthresh;
2829 hthresh_tmp = tx_conf[qid].tx_thresh.hthresh;
2830 wthresh_tmp = tx_conf[qid].tx_thresh.wthresh;
2831 offloads_tmp = tx_conf[qid].offloads;
2832 tx_rs_thresh_tmp = tx_conf[qid].tx_rs_thresh;
2834 nb_tx_desc_tmp = tx_qinfo.nb_desc;
2835 tx_free_thresh_tmp =
2836 tx_qinfo.conf.tx_free_thresh;
2837 pthresh_tmp = tx_qinfo.conf.tx_thresh.pthresh;
2838 hthresh_tmp = tx_qinfo.conf.tx_thresh.hthresh;
2839 wthresh_tmp = tx_qinfo.conf.tx_thresh.wthresh;
2840 offloads_tmp = tx_qinfo.conf.offloads;
2841 tx_rs_thresh_tmp = tx_qinfo.conf.tx_rs_thresh;
2844 printf(" TX queue: %d\n", qid);
2845 printf(" TX desc=%d - TX free threshold=%d\n",
2846 nb_tx_desc_tmp, tx_free_thresh_tmp);
2847 printf(" TX threshold registers: pthresh=%d hthresh=%d "
2849 pthresh_tmp, hthresh_tmp, wthresh_tmp);
2850 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
2851 offloads_tmp, tx_rs_thresh_tmp);
2857 port_rss_reta_info(portid_t port_id,
2858 struct rte_eth_rss_reta_entry64 *reta_conf,
2859 uint16_t nb_entries)
2861 uint16_t i, idx, shift;
2864 if (port_id_is_invalid(port_id, ENABLED_WARN))
2867 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
2870 "Failed to get RSS RETA info, return code = %d\n",
2875 for (i = 0; i < nb_entries; i++) {
2876 idx = i / RTE_ETH_RETA_GROUP_SIZE;
2877 shift = i % RTE_ETH_RETA_GROUP_SIZE;
2878 if (!(reta_conf[idx].mask & (1ULL << shift)))
2880 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
2881 i, reta_conf[idx].reta[shift]);
2886 * Displays the RSS hash functions of a port, and, optionally, the RSS hash
2890 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
2892 struct rte_eth_rss_conf rss_conf = {0};
2893 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
2897 struct rte_eth_dev_info dev_info;
2898 uint8_t hash_key_size;
2901 if (port_id_is_invalid(port_id, ENABLED_WARN))
2904 ret = eth_dev_info_get_print_err(port_id, &dev_info);
2908 if (dev_info.hash_key_size > 0 &&
2909 dev_info.hash_key_size <= sizeof(rss_key))
2910 hash_key_size = dev_info.hash_key_size;
2913 "dev_info did not provide a valid hash key size\n");
2917 /* Get RSS hash key if asked to display it */
2918 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
2919 rss_conf.rss_key_len = hash_key_size;
2920 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2924 fprintf(stderr, "port index %d invalid\n", port_id);
2927 fprintf(stderr, "operation not supported by device\n");
2930 fprintf(stderr, "operation failed - diag=%d\n", diag);
2935 rss_hf = rss_conf.rss_hf;
2937 printf("RSS disabled\n");
2940 printf("RSS functions:\n ");
2941 for (i = 0; rss_type_table[i].str; i++) {
2942 if (rss_type_table[i].rss_type == 0)
2944 if ((rss_hf & rss_type_table[i].rss_type) == rss_type_table[i].rss_type)
2945 printf("%s ", rss_type_table[i].str);
2950 printf("RSS key:\n");
2951 for (i = 0; i < hash_key_size; i++)
2952 printf("%02X", rss_key[i]);
2957 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
2958 uint8_t hash_key_len)
2960 struct rte_eth_rss_conf rss_conf;
2964 rss_conf.rss_key = NULL;
2965 rss_conf.rss_key_len = 0;
2966 rss_conf.rss_hf = 0;
2967 for (i = 0; rss_type_table[i].str; i++) {
2968 if (!strcmp(rss_type_table[i].str, rss_type))
2969 rss_conf.rss_hf = rss_type_table[i].rss_type;
2971 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
2973 rss_conf.rss_key = hash_key;
2974 rss_conf.rss_key_len = hash_key_len;
2975 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
2982 fprintf(stderr, "port index %d invalid\n", port_id);
2985 fprintf(stderr, "operation not supported by device\n");
2988 fprintf(stderr, "operation failed - diag=%d\n", diag);
2994 * Check whether a shared rxq scheduled on other lcores.
2997 fwd_stream_on_other_lcores(uint16_t domain_id, lcoreid_t src_lc,
2998 portid_t src_port, queueid_t src_rxq,
2999 uint32_t share_group, queueid_t share_rxq)
3002 streamid_t nb_fs_per_lcore;
3005 struct fwd_stream *fs;
3006 struct rte_port *port;
3007 struct rte_eth_dev_info *dev_info;
3008 struct rte_eth_rxconf *rxq_conf;
3010 nb_fc = cur_fwd_config.nb_fwd_lcores;
3011 /* Check remaining cores. */
3012 for (lc_id = src_lc + 1; lc_id < nb_fc; lc_id++) {
3013 sm_id = fwd_lcores[lc_id]->stream_idx;
3014 nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
3015 for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
3017 fs = fwd_streams[sm_id];
3018 port = &ports[fs->rx_port];
3019 dev_info = &port->dev_info;
3020 rxq_conf = &port->rx_conf[fs->rx_queue];
3021 if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
3022 == 0 || rxq_conf->share_group == 0)
3023 /* Not shared rxq. */
3025 if (domain_id != port->dev_info.switch_info.domain_id)
3027 if (rxq_conf->share_group != share_group)
3029 if (rxq_conf->share_qid != share_rxq)
3031 printf("Shared Rx queue group %u queue %hu can't be scheduled on different cores:\n",
3032 share_group, share_rxq);
3033 printf(" lcore %hhu Port %hu queue %hu\n",
3034 src_lc, src_port, src_rxq);
3035 printf(" lcore %hhu Port %hu queue %hu\n",
3036 lc_id, fs->rx_port, fs->rx_queue);
3037 printf("Please use --nb-cores=%hu to limit number of forwarding cores\n",
3046 * Check shared rxq configuration.
3048 * Shared group must not being scheduled on different core.
3051 pkt_fwd_shared_rxq_check(void)
3054 streamid_t nb_fs_per_lcore;
3057 struct fwd_stream *fs;
3059 struct rte_port *port;
3060 struct rte_eth_dev_info *dev_info;
3061 struct rte_eth_rxconf *rxq_conf;
3065 nb_fc = cur_fwd_config.nb_fwd_lcores;
3067 * Check streams on each core, make sure the same switch domain +
3068 * group + queue doesn't get scheduled on other cores.
3070 for (lc_id = 0; lc_id < nb_fc; lc_id++) {
3071 sm_id = fwd_lcores[lc_id]->stream_idx;
3072 nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
3073 for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
3075 fs = fwd_streams[sm_id];
3076 /* Update lcore info stream being scheduled. */
3077 fs->lcore = fwd_lcores[lc_id];
3078 port = &ports[fs->rx_port];
3079 dev_info = &port->dev_info;
3080 rxq_conf = &port->rx_conf[fs->rx_queue];
3081 if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
3082 == 0 || rxq_conf->share_group == 0)
3083 /* Not shared rxq. */
3085 /* Check shared rxq not scheduled on remaining cores. */
3086 domain_id = port->dev_info.switch_info.domain_id;
3087 if (fwd_stream_on_other_lcores(domain_id, lc_id,
3090 rxq_conf->share_group,
3091 rxq_conf->share_qid))
3099 * Setup forwarding configuration for each logical core.
3102 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
3104 streamid_t nb_fs_per_lcore;
3112 nb_fs = cfg->nb_fwd_streams;
3113 nb_fc = cfg->nb_fwd_lcores;
3114 if (nb_fs <= nb_fc) {
3115 nb_fs_per_lcore = 1;
3118 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
3119 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
3122 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
3124 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
3125 fwd_lcores[lc_id]->stream_idx = sm_id;
3126 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
3127 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
3131 * Assign extra remaining streams, if any.
3133 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
3134 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
3135 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
3136 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
3137 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
3142 fwd_topology_tx_port_get(portid_t rxp)
3144 static int warning_once = 1;
3146 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
3148 switch (port_topology) {
3150 case PORT_TOPOLOGY_PAIRED:
3151 if ((rxp & 0x1) == 0) {
3152 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
3156 "\nWarning! port-topology=paired and odd forward ports number, the last port will pair with itself.\n\n");
3162 case PORT_TOPOLOGY_CHAINED:
3163 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
3164 case PORT_TOPOLOGY_LOOP:
3170 simple_fwd_config_setup(void)
3174 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
3175 cur_fwd_config.nb_fwd_streams =
3176 (streamid_t) cur_fwd_config.nb_fwd_ports;
3178 /* reinitialize forwarding streams */
3182 * In the simple forwarding test, the number of forwarding cores
3183 * must be lower or equal to the number of forwarding ports.
3185 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3186 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
3187 cur_fwd_config.nb_fwd_lcores =
3188 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
3189 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3191 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
3192 fwd_streams[i]->rx_port = fwd_ports_ids[i];
3193 fwd_streams[i]->rx_queue = 0;
3194 fwd_streams[i]->tx_port =
3195 fwd_ports_ids[fwd_topology_tx_port_get(i)];
3196 fwd_streams[i]->tx_queue = 0;
3197 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
3198 fwd_streams[i]->retry_enabled = retry_enabled;
3203 * For the RSS forwarding test all streams distributed over lcores. Each stream
3204 * being composed of a RX queue to poll on a RX port for input messages,
3205 * associated with a TX queue of a TX port where to send forwarded packets.
3208 rss_fwd_config_setup(void)
3221 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3222 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3223 cur_fwd_config.nb_fwd_streams =
3224 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
3226 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3227 cur_fwd_config.nb_fwd_lcores =
3228 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3230 /* reinitialize forwarding streams */
3233 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3235 if (proc_id > 0 && nb_q % num_procs != 0)
3236 printf("Warning! queue numbers should be multiple of processes, or packet loss will happen.\n");
3239 * In multi-process, All queues are allocated to different
3240 * processes based on num_procs and proc_id. For example:
3241 * if supports 4 queues(nb_q), 2 processes(num_procs),
3242 * the 0~1 queue for primary process.
3243 * the 2~3 queue for secondary process.
3245 start = proc_id * nb_q / num_procs;
3246 end = start + nb_q / num_procs;
3249 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
3250 struct fwd_stream *fs;
3252 fs = fwd_streams[sm_id];
3253 txp = fwd_topology_tx_port_get(rxp);
3254 fs->rx_port = fwd_ports_ids[rxp];
3256 fs->tx_port = fwd_ports_ids[txp];
3258 fs->peer_addr = fs->tx_port;
3259 fs->retry_enabled = retry_enabled;
3261 if (rxp < nb_fwd_ports)
3271 get_fwd_port_total_tc_num(void)
3273 struct rte_eth_dcb_info dcb_info;
3274 uint16_t total_tc_num = 0;
3277 for (i = 0; i < nb_fwd_ports; i++) {
3278 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[i], &dcb_info);
3279 total_tc_num += dcb_info.nb_tcs;
3282 return total_tc_num;
3286 * For the DCB forwarding test, each core is assigned on each traffic class.
3288 * Each core is assigned a multi-stream, each stream being composed of
3289 * a RX queue to poll on a RX port for input messages, associated with
3290 * a TX queue of a TX port where to send forwarded packets. All RX and
3291 * TX queues are mapping to the same traffic class.
3292 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
3296 dcb_fwd_config_setup(void)
3298 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
3299 portid_t txp, rxp = 0;
3300 queueid_t txq, rxq = 0;
3302 uint16_t nb_rx_queue, nb_tx_queue;
3303 uint16_t i, j, k, sm_id = 0;
3304 uint16_t total_tc_num;
3305 struct rte_port *port;
3311 * The fwd_config_setup() is called when the port is RTE_PORT_STARTED
3312 * or RTE_PORT_STOPPED.
3314 * Re-configure ports to get updated mapping between tc and queue in
3315 * case the queue number of the port is changed. Skip for started ports
3316 * since modifying queue number and calling dev_configure need to stop
3319 for (pid = 0; pid < nb_fwd_ports; pid++) {
3320 if (port_is_started(pid) == 1)
3324 ret = rte_eth_dev_configure(pid, nb_rxq, nb_txq,
3328 "Failed to re-configure port %d, ret = %d.\n",
3334 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3335 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3336 cur_fwd_config.nb_fwd_streams =
3337 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3338 total_tc_num = get_fwd_port_total_tc_num();
3339 if (cur_fwd_config.nb_fwd_lcores > total_tc_num)
3340 cur_fwd_config.nb_fwd_lcores = total_tc_num;
3342 /* reinitialize forwarding streams */
3346 /* get the dcb info on the first RX and TX ports */
3347 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3348 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3350 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3351 fwd_lcores[lc_id]->stream_nb = 0;
3352 fwd_lcores[lc_id]->stream_idx = sm_id;
3353 for (i = 0; i < RTE_ETH_MAX_VMDQ_POOL; i++) {
3354 /* if the nb_queue is zero, means this tc is
3355 * not enabled on the POOL
3357 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
3359 k = fwd_lcores[lc_id]->stream_nb +
3360 fwd_lcores[lc_id]->stream_idx;
3361 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
3362 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
3363 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3364 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
3365 for (j = 0; j < nb_rx_queue; j++) {
3366 struct fwd_stream *fs;
3368 fs = fwd_streams[k + j];
3369 fs->rx_port = fwd_ports_ids[rxp];
3370 fs->rx_queue = rxq + j;
3371 fs->tx_port = fwd_ports_ids[txp];
3372 fs->tx_queue = txq + j % nb_tx_queue;
3373 fs->peer_addr = fs->tx_port;
3374 fs->retry_enabled = retry_enabled;
3376 fwd_lcores[lc_id]->stream_nb +=
3377 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3379 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
3382 if (tc < rxp_dcb_info.nb_tcs)
3384 /* Restart from TC 0 on next RX port */
3386 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
3388 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
3391 if (rxp >= nb_fwd_ports)
3393 /* get the dcb information on next RX and TX ports */
3394 if ((rxp & 0x1) == 0)
3395 txp = (portid_t) (rxp + 1);
3397 txp = (portid_t) (rxp - 1);
3398 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3399 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3404 icmp_echo_config_setup(void)
3411 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
3412 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
3413 (nb_txq * nb_fwd_ports);
3415 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3416 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3417 cur_fwd_config.nb_fwd_streams =
3418 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3419 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3420 cur_fwd_config.nb_fwd_lcores =
3421 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3422 if (verbose_level > 0) {
3423 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
3425 cur_fwd_config.nb_fwd_lcores,
3426 cur_fwd_config.nb_fwd_ports,
3427 cur_fwd_config.nb_fwd_streams);
3430 /* reinitialize forwarding streams */
3432 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3434 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3435 if (verbose_level > 0)
3436 printf(" core=%d: \n", lc_id);
3437 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3438 struct fwd_stream *fs;
3439 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3440 fs->rx_port = fwd_ports_ids[rxp];
3442 fs->tx_port = fs->rx_port;
3444 fs->peer_addr = fs->tx_port;
3445 fs->retry_enabled = retry_enabled;
3446 if (verbose_level > 0)
3447 printf(" stream=%d port=%d rxq=%d txq=%d\n",
3448 sm_id, fs->rx_port, fs->rx_queue,
3450 rxq = (queueid_t) (rxq + 1);
3451 if (rxq == nb_rxq) {
3453 rxp = (portid_t) (rxp + 1);
3460 fwd_config_setup(void)
3462 struct rte_port *port;
3466 cur_fwd_config.fwd_eng = cur_fwd_eng;
3467 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
3468 icmp_echo_config_setup();
3472 if ((nb_rxq > 1) && (nb_txq > 1)){
3474 for (i = 0; i < nb_fwd_ports; i++) {
3475 pt_id = fwd_ports_ids[i];
3476 port = &ports[pt_id];
3477 if (!port->dcb_flag) {
3479 "In DCB mode, all forwarding ports must be configured in this mode.\n");
3483 if (nb_fwd_lcores == 1) {
3485 "In DCB mode,the nb forwarding cores should be larger than 1.\n");
3489 dcb_fwd_config_setup();
3491 rss_fwd_config_setup();
3494 simple_fwd_config_setup();
3498 mp_alloc_to_str(uint8_t mode)
3501 case MP_ALLOC_NATIVE:
3507 case MP_ALLOC_XMEM_HUGE:
3517 pkt_fwd_config_display(struct fwd_config *cfg)
3519 struct fwd_stream *fs;
3523 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
3524 "NUMA support %s, MP allocation mode: %s\n",
3525 cfg->fwd_eng->fwd_mode_name,
3526 retry_enabled == 0 ? "" : " with retry",
3527 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
3528 numa_support == 1 ? "enabled" : "disabled",
3529 mp_alloc_to_str(mp_alloc_type));
3532 printf("TX retry num: %u, delay between TX retries: %uus\n",
3533 burst_tx_retry_num, burst_tx_delay_time);
3534 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
3535 printf("Logical Core %u (socket %u) forwards packets on "
3537 fwd_lcores_cpuids[lc_id],
3538 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
3539 fwd_lcores[lc_id]->stream_nb);
3540 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3541 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3542 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
3543 "P=%d/Q=%d (socket %u) ",
3544 fs->rx_port, fs->rx_queue,
3545 ports[fs->rx_port].socket_id,
3546 fs->tx_port, fs->tx_queue,
3547 ports[fs->tx_port].socket_id);
3548 print_ethaddr("peer=",
3549 &peer_eth_addrs[fs->peer_addr]);
3557 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
3559 struct rte_ether_addr new_peer_addr;
3560 if (!rte_eth_dev_is_valid_port(port_id)) {
3561 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
3564 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
3565 fprintf(stderr, "Error: Invalid ethernet address: %s\n",
3569 peer_eth_addrs[port_id] = new_peer_addr;
3573 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
3576 unsigned int lcore_cpuid;
3581 for (i = 0; i < nb_lc; i++) {
3582 lcore_cpuid = lcorelist[i];
3583 if (! rte_lcore_is_enabled(lcore_cpuid)) {
3584 fprintf(stderr, "lcore %u not enabled\n", lcore_cpuid);
3587 if (lcore_cpuid == rte_get_main_lcore()) {
3589 "lcore %u cannot be masked on for running packet forwarding, which is the main lcore and reserved for command line parsing only\n",
3594 fwd_lcores_cpuids[i] = lcore_cpuid;
3596 if (record_now == 0) {
3600 nb_cfg_lcores = (lcoreid_t) nb_lc;
3601 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
3602 printf("previous number of forwarding cores %u - changed to "
3603 "number of configured cores %u\n",
3604 (unsigned int) nb_fwd_lcores, nb_lc);
3605 nb_fwd_lcores = (lcoreid_t) nb_lc;
3612 set_fwd_lcores_mask(uint64_t lcoremask)
3614 unsigned int lcorelist[64];
3618 if (lcoremask == 0) {
3619 fprintf(stderr, "Invalid NULL mask of cores\n");
3623 for (i = 0; i < 64; i++) {
3624 if (! ((uint64_t)(1ULL << i) & lcoremask))
3626 lcorelist[nb_lc++] = i;
3628 return set_fwd_lcores_list(lcorelist, nb_lc);
3632 set_fwd_lcores_number(uint16_t nb_lc)
3634 if (test_done == 0) {
3635 fprintf(stderr, "Please stop forwarding first\n");
3638 if (nb_lc > nb_cfg_lcores) {
3640 "nb fwd cores %u > %u (max. number of configured lcores) - ignored\n",
3641 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
3644 nb_fwd_lcores = (lcoreid_t) nb_lc;
3645 printf("Number of forwarding cores set to %u\n",
3646 (unsigned int) nb_fwd_lcores);
3650 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
3658 for (i = 0; i < nb_pt; i++) {
3659 port_id = (portid_t) portlist[i];
3660 if (port_id_is_invalid(port_id, ENABLED_WARN))
3663 fwd_ports_ids[i] = port_id;
3665 if (record_now == 0) {
3669 nb_cfg_ports = (portid_t) nb_pt;
3670 if (nb_fwd_ports != (portid_t) nb_pt) {
3671 printf("previous number of forwarding ports %u - changed to "
3672 "number of configured ports %u\n",
3673 (unsigned int) nb_fwd_ports, nb_pt);
3674 nb_fwd_ports = (portid_t) nb_pt;
3679 * Parse the user input and obtain the list of forwarding ports
3682 * String containing the user input. User can specify
3683 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
3684 * For example, if the user wants to use all the available
3685 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
3686 * If the user wants to use only the ports 1,2 then the input
3688 * valid characters are '-' and ','
3689 * @param[out] values
3690 * This array will be filled with a list of port IDs
3691 * based on the user input
3692 * Note that duplicate entries are discarded and only the first
3693 * count entries in this array are port IDs and all the rest
3694 * will contain default values
3695 * @param[in] maxsize
3696 * This parameter denotes 2 things
3697 * 1) Number of elements in the values array
3698 * 2) Maximum value of each element in the values array
3700 * On success, returns total count of parsed port IDs
3701 * On failure, returns 0
3704 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
3706 unsigned int count = 0;
3710 unsigned int marked[maxsize];
3712 if (list == NULL || values == NULL)
3715 for (i = 0; i < (int)maxsize; i++)
3721 /*Remove the blank spaces if any*/
3722 while (isblank(*list))
3727 value = strtol(list, &end, 10);
3728 if (errno || end == NULL)
3730 if (value < 0 || value >= (int)maxsize)
3732 while (isblank(*end))
3734 if (*end == '-' && min == INT_MAX) {
3736 } else if ((*end == ',') || (*end == '\0')) {
3740 for (i = min; i <= max; i++) {
3741 if (count < maxsize) {
3753 } while (*end != '\0');
3759 parse_fwd_portlist(const char *portlist)
3761 unsigned int portcount;
3762 unsigned int portindex[RTE_MAX_ETHPORTS];
3763 unsigned int i, valid_port_count = 0;
3765 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
3767 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
3770 * Here we verify the validity of the ports
3771 * and thereby calculate the total number of
3774 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
3775 if (rte_eth_dev_is_valid_port(portindex[i])) {
3776 portindex[valid_port_count] = portindex[i];
3781 set_fwd_ports_list(portindex, valid_port_count);
3785 set_fwd_ports_mask(uint64_t portmask)
3787 unsigned int portlist[64];
3791 if (portmask == 0) {
3792 fprintf(stderr, "Invalid NULL mask of ports\n");
3796 RTE_ETH_FOREACH_DEV(i) {
3797 if (! ((uint64_t)(1ULL << i) & portmask))
3799 portlist[nb_pt++] = i;
3801 set_fwd_ports_list(portlist, nb_pt);
3805 set_fwd_ports_number(uint16_t nb_pt)
3807 if (nb_pt > nb_cfg_ports) {
3809 "nb fwd ports %u > %u (number of configured ports) - ignored\n",
3810 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
3813 nb_fwd_ports = (portid_t) nb_pt;
3814 printf("Number of forwarding ports set to %u\n",
3815 (unsigned int) nb_fwd_ports);
3819 port_is_forwarding(portid_t port_id)
3823 if (port_id_is_invalid(port_id, ENABLED_WARN))
3826 for (i = 0; i < nb_fwd_ports; i++) {
3827 if (fwd_ports_ids[i] == port_id)
3835 set_nb_pkt_per_burst(uint16_t nb)
3837 if (nb > MAX_PKT_BURST) {
3839 "nb pkt per burst: %u > %u (maximum packet per burst) ignored\n",
3840 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
3843 nb_pkt_per_burst = nb;
3844 printf("Number of packets per burst set to %u\n",
3845 (unsigned int) nb_pkt_per_burst);
3849 tx_split_get_name(enum tx_pkt_split split)
3853 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3854 if (tx_split_name[i].split == split)
3855 return tx_split_name[i].name;
3861 set_tx_pkt_split(const char *name)
3865 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
3866 if (strcmp(tx_split_name[i].name, name) == 0) {
3867 tx_pkt_split = tx_split_name[i].split;
3871 fprintf(stderr, "unknown value: \"%s\"\n", name);
3875 parse_fec_mode(const char *name, uint32_t *fec_capa)
3879 for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
3880 if (strcmp(fec_mode_name[i].name, name) == 0) {
3882 RTE_ETH_FEC_MODE_TO_CAPA(fec_mode_name[i].mode);
3890 show_fec_capability(unsigned int num, struct rte_eth_fec_capa *speed_fec_capa)
3894 printf("FEC capabilities:\n");
3896 for (i = 0; i < num; i++) {
3898 rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
3900 for (j = 0; j < RTE_DIM(fec_mode_name); j++) {
3901 if (RTE_ETH_FEC_MODE_TO_CAPA(j) &
3902 speed_fec_capa[i].capa)
3903 printf("%s ", fec_mode_name[j].name);
3910 show_rx_pkt_offsets(void)
3915 printf("Number of offsets: %u\n", n);
3917 printf("Segment offsets: ");
3918 for (i = 0; i != n - 1; i++)
3919 printf("%hu,", rx_pkt_seg_offsets[i]);
3920 printf("%hu\n", rx_pkt_seg_lengths[i]);
3925 set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs)
3929 if (nb_offs >= MAX_SEGS_BUFFER_SPLIT) {
3930 printf("nb segments per RX packets=%u >= "
3931 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_offs);
3936 * No extra check here, the segment length will be checked by PMD
3937 * in the extended queue setup.
3939 for (i = 0; i < nb_offs; i++) {
3940 if (seg_offsets[i] >= UINT16_MAX) {
3941 printf("offset[%u]=%u > UINT16_MAX - give up\n",
3947 for (i = 0; i < nb_offs; i++)
3948 rx_pkt_seg_offsets[i] = (uint16_t) seg_offsets[i];
3950 rx_pkt_nb_offs = (uint8_t) nb_offs;
3954 show_rx_pkt_segments(void)
3959 printf("Number of segments: %u\n", n);
3961 printf("Segment sizes: ");
3962 for (i = 0; i != n - 1; i++)
3963 printf("%hu,", rx_pkt_seg_lengths[i]);
3964 printf("%hu\n", rx_pkt_seg_lengths[i]);
3969 set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
3973 if (nb_segs >= MAX_SEGS_BUFFER_SPLIT) {
3974 printf("nb segments per RX packets=%u >= "
3975 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs);
3980 * No extra check here, the segment length will be checked by PMD
3981 * in the extended queue setup.
3983 for (i = 0; i < nb_segs; i++) {
3984 if (seg_lengths[i] >= UINT16_MAX) {
3985 printf("length[%u]=%u > UINT16_MAX - give up\n",
3991 for (i = 0; i < nb_segs; i++)
3992 rx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
3994 rx_pkt_nb_segs = (uint8_t) nb_segs;
3998 show_tx_pkt_segments(void)
4004 split = tx_split_get_name(tx_pkt_split);
4006 printf("Number of segments: %u\n", n);
4007 printf("Segment sizes: ");
4008 for (i = 0; i != n - 1; i++)
4009 printf("%hu,", tx_pkt_seg_lengths[i]);
4010 printf("%hu\n", tx_pkt_seg_lengths[i]);
4011 printf("Split packet: %s\n", split);
4015 nb_segs_is_invalid(unsigned int nb_segs)
4022 RTE_ETH_FOREACH_DEV(port_id) {
4023 for (queue_id = 0; queue_id < nb_txq; queue_id++) {
4024 ret = get_tx_ring_size(port_id, queue_id, &ring_size);
4026 /* Port may not be initialized yet, can't say
4027 * the port is invalid in this stage.
4031 if (ring_size < nb_segs) {
4032 printf("nb segments per TX packets=%u >= TX "
4033 "queue(%u) ring_size=%u - txpkts ignored\n",
4034 nb_segs, queue_id, ring_size);
4044 set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
4046 uint16_t tx_pkt_len;
4050 * For single segment settings failed check is ignored.
4051 * It is a very basic capability to send the single segment
4052 * packets, suppose it is always supported.
4054 if (nb_segs > 1 && nb_segs_is_invalid(nb_segs)) {
4056 "Tx segment size(%u) is not supported - txpkts ignored\n",
4061 if (nb_segs > RTE_MAX_SEGS_PER_PKT) {
4063 "Tx segment size(%u) is bigger than max number of segment(%u)\n",
4064 nb_segs, RTE_MAX_SEGS_PER_PKT);
4069 * Check that each segment length is greater or equal than
4070 * the mbuf data size.
4071 * Check also that the total packet length is greater or equal than the
4072 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
4076 for (i = 0; i < nb_segs; i++) {
4077 if (seg_lengths[i] > mbuf_data_size[0]) {
4079 "length[%u]=%u > mbuf_data_size=%u - give up\n",
4080 i, seg_lengths[i], mbuf_data_size[0]);
4083 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
4085 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
4086 fprintf(stderr, "total packet length=%u < %d - give up\n",
4087 (unsigned) tx_pkt_len,
4088 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
4092 for (i = 0; i < nb_segs; i++)
4093 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
4095 tx_pkt_length = tx_pkt_len;
4096 tx_pkt_nb_segs = (uint8_t) nb_segs;
4100 show_tx_pkt_times(void)
4102 printf("Interburst gap: %u\n", tx_pkt_times_inter);
4103 printf("Intraburst gap: %u\n", tx_pkt_times_intra);
4107 set_tx_pkt_times(unsigned int *tx_times)
4109 tx_pkt_times_inter = tx_times[0];
4110 tx_pkt_times_intra = tx_times[1];
4115 setup_gro(const char *onoff, portid_t port_id)
4117 if (!rte_eth_dev_is_valid_port(port_id)) {
4118 fprintf(stderr, "invalid port id %u\n", port_id);
4121 if (test_done == 0) {
4123 "Before enable/disable GRO, please stop forwarding first\n");
4126 if (strcmp(onoff, "on") == 0) {
4127 if (gro_ports[port_id].enable != 0) {
4129 "Port %u has enabled GRO. Please disable GRO first\n",
4133 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
4134 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
4135 gro_ports[port_id].param.max_flow_num =
4136 GRO_DEFAULT_FLOW_NUM;
4137 gro_ports[port_id].param.max_item_per_flow =
4138 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
4140 gro_ports[port_id].enable = 1;
4142 if (gro_ports[port_id].enable == 0) {
4143 fprintf(stderr, "Port %u has disabled GRO\n", port_id);
4146 gro_ports[port_id].enable = 0;
4151 setup_gro_flush_cycles(uint8_t cycles)
4153 if (test_done == 0) {
4155 "Before change flush interval for GRO, please stop forwarding first.\n");
4159 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
4160 GRO_DEFAULT_FLUSH_CYCLES) {
4162 "The flushing cycle be in the range of 1 to %u. Revert to the default value %u.\n",
4163 GRO_MAX_FLUSH_CYCLES, GRO_DEFAULT_FLUSH_CYCLES);
4164 cycles = GRO_DEFAULT_FLUSH_CYCLES;
4167 gro_flush_cycles = cycles;
4171 show_gro(portid_t port_id)
4173 struct rte_gro_param *param;
4174 uint32_t max_pkts_num;
4176 param = &gro_ports[port_id].param;
4178 if (!rte_eth_dev_is_valid_port(port_id)) {
4179 fprintf(stderr, "Invalid port id %u.\n", port_id);
4182 if (gro_ports[port_id].enable) {
4183 printf("GRO type: TCP/IPv4\n");
4184 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
4185 max_pkts_num = param->max_flow_num *
4186 param->max_item_per_flow;
4188 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
4189 printf("Max number of packets to perform GRO: %u\n",
4191 printf("Flushing cycles: %u\n", gro_flush_cycles);
4193 printf("Port %u doesn't enable GRO.\n", port_id);
4195 #endif /* RTE_LIB_GRO */
4199 setup_gso(const char *mode, portid_t port_id)
4201 if (!rte_eth_dev_is_valid_port(port_id)) {
4202 fprintf(stderr, "invalid port id %u\n", port_id);
4205 if (strcmp(mode, "on") == 0) {
4206 if (test_done == 0) {
4208 "before enabling GSO, please stop forwarding first\n");
4211 gso_ports[port_id].enable = 1;
4212 } else if (strcmp(mode, "off") == 0) {
4213 if (test_done == 0) {
4215 "before disabling GSO, please stop forwarding first\n");
4218 gso_ports[port_id].enable = 0;
4221 #endif /* RTE_LIB_GSO */
4224 list_pkt_forwarding_modes(void)
4226 static char fwd_modes[128] = "";
4227 const char *separator = "|";
4228 struct fwd_engine *fwd_eng;
4231 if (strlen (fwd_modes) == 0) {
4232 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4233 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4234 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4235 strncat(fwd_modes, separator,
4236 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4238 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4245 list_pkt_forwarding_retry_modes(void)
4247 static char fwd_modes[128] = "";
4248 const char *separator = "|";
4249 struct fwd_engine *fwd_eng;
4252 if (strlen(fwd_modes) == 0) {
4253 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4254 if (fwd_eng == &rx_only_engine)
4256 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4258 strlen(fwd_modes) - 1);
4259 strncat(fwd_modes, separator,
4261 strlen(fwd_modes) - 1);
4263 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4270 set_pkt_forwarding_mode(const char *fwd_mode_name)
4272 struct fwd_engine *fwd_eng;
4276 while ((fwd_eng = fwd_engines[i]) != NULL) {
4277 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
4278 printf("Set %s packet forwarding mode%s\n",
4280 retry_enabled == 0 ? "" : " with retry");
4281 cur_fwd_eng = fwd_eng;
4286 fprintf(stderr, "Invalid %s packet forwarding mode\n", fwd_mode_name);
4290 add_rx_dump_callbacks(portid_t portid)
4292 struct rte_eth_dev_info dev_info;
4296 if (port_id_is_invalid(portid, ENABLED_WARN))
4299 ret = eth_dev_info_get_print_err(portid, &dev_info);
4303 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4304 if (!ports[portid].rx_dump_cb[queue])
4305 ports[portid].rx_dump_cb[queue] =
4306 rte_eth_add_rx_callback(portid, queue,
4307 dump_rx_pkts, NULL);
4311 add_tx_dump_callbacks(portid_t portid)
4313 struct rte_eth_dev_info dev_info;
4317 if (port_id_is_invalid(portid, ENABLED_WARN))
4320 ret = eth_dev_info_get_print_err(portid, &dev_info);
4324 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4325 if (!ports[portid].tx_dump_cb[queue])
4326 ports[portid].tx_dump_cb[queue] =
4327 rte_eth_add_tx_callback(portid, queue,
4328 dump_tx_pkts, NULL);
4332 remove_rx_dump_callbacks(portid_t portid)
4334 struct rte_eth_dev_info dev_info;
4338 if (port_id_is_invalid(portid, ENABLED_WARN))
4341 ret = eth_dev_info_get_print_err(portid, &dev_info);
4345 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4346 if (ports[portid].rx_dump_cb[queue]) {
4347 rte_eth_remove_rx_callback(portid, queue,
4348 ports[portid].rx_dump_cb[queue]);
4349 ports[portid].rx_dump_cb[queue] = NULL;
4354 remove_tx_dump_callbacks(portid_t portid)
4356 struct rte_eth_dev_info dev_info;
4360 if (port_id_is_invalid(portid, ENABLED_WARN))
4363 ret = eth_dev_info_get_print_err(portid, &dev_info);
4367 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4368 if (ports[portid].tx_dump_cb[queue]) {
4369 rte_eth_remove_tx_callback(portid, queue,
4370 ports[portid].tx_dump_cb[queue]);
4371 ports[portid].tx_dump_cb[queue] = NULL;
4376 configure_rxtx_dump_callbacks(uint16_t verbose)
4380 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4381 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
4385 RTE_ETH_FOREACH_DEV(portid)
4387 if (verbose == 1 || verbose > 2)
4388 add_rx_dump_callbacks(portid);
4390 remove_rx_dump_callbacks(portid);
4392 add_tx_dump_callbacks(portid);
4394 remove_tx_dump_callbacks(portid);
4399 set_verbose_level(uint16_t vb_level)
4401 printf("Change verbose level from %u to %u\n",
4402 (unsigned int) verbose_level, (unsigned int) vb_level);
4403 verbose_level = vb_level;
4404 configure_rxtx_dump_callbacks(verbose_level);
4408 vlan_extend_set(portid_t port_id, int on)
4412 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4414 if (port_id_is_invalid(port_id, ENABLED_WARN))
4417 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4420 vlan_offload |= RTE_ETH_VLAN_EXTEND_OFFLOAD;
4421 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4423 vlan_offload &= ~RTE_ETH_VLAN_EXTEND_OFFLOAD;
4424 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4427 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4430 "rx_vlan_extend_set(port_pi=%d, on=%d) failed diag=%d\n",
4434 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4438 rx_vlan_strip_set(portid_t port_id, int on)
4442 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4444 if (port_id_is_invalid(port_id, ENABLED_WARN))
4447 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4450 vlan_offload |= RTE_ETH_VLAN_STRIP_OFFLOAD;
4451 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4453 vlan_offload &= ~RTE_ETH_VLAN_STRIP_OFFLOAD;
4454 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4457 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4460 "%s(port_pi=%d, on=%d) failed diag=%d\n",
4461 __func__, port_id, on, diag);
4464 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4468 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
4472 if (port_id_is_invalid(port_id, ENABLED_WARN))
4475 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
4478 "%s(port_pi=%d, queue_id=%d, on=%d) failed diag=%d\n",
4479 __func__, port_id, queue_id, on, diag);
4483 rx_vlan_filter_set(portid_t port_id, int on)
4487 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4489 if (port_id_is_invalid(port_id, ENABLED_WARN))
4492 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4495 vlan_offload |= RTE_ETH_VLAN_FILTER_OFFLOAD;
4496 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4498 vlan_offload &= ~RTE_ETH_VLAN_FILTER_OFFLOAD;
4499 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4502 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4505 "%s(port_pi=%d, on=%d) failed diag=%d\n",
4506 __func__, port_id, on, diag);
4509 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4513 rx_vlan_qinq_strip_set(portid_t port_id, int on)
4517 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4519 if (port_id_is_invalid(port_id, ENABLED_WARN))
4522 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4525 vlan_offload |= RTE_ETH_QINQ_STRIP_OFFLOAD;
4526 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4528 vlan_offload &= ~RTE_ETH_QINQ_STRIP_OFFLOAD;
4529 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4532 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4534 fprintf(stderr, "%s(port_pi=%d, on=%d) failed diag=%d\n",
4535 __func__, port_id, on, diag);
4538 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4542 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
4546 if (port_id_is_invalid(port_id, ENABLED_WARN))
4548 if (vlan_id_is_invalid(vlan_id))
4550 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
4554 "rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed diag=%d\n",
4555 port_id, vlan_id, on, diag);
4560 rx_vlan_all_filter_set(portid_t port_id, int on)
4564 if (port_id_is_invalid(port_id, ENABLED_WARN))
4566 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
4567 if (rx_vft_set(port_id, vlan_id, on))
4573 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
4577 if (port_id_is_invalid(port_id, ENABLED_WARN))
4580 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
4585 "tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed diag=%d\n",
4586 port_id, vlan_type, tp_id, diag);
4590 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
4592 struct rte_eth_dev_info dev_info;
4595 if (vlan_id_is_invalid(vlan_id))
4598 if (ports[port_id].dev_conf.txmode.offloads &
4599 RTE_ETH_TX_OFFLOAD_QINQ_INSERT) {
4600 fprintf(stderr, "Error, as QinQ has been enabled.\n");
4604 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4608 if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VLAN_INSERT) == 0) {
4610 "Error: vlan insert is not supported by port %d\n",
4615 tx_vlan_reset(port_id);
4616 ports[port_id].dev_conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
4617 ports[port_id].tx_vlan_id = vlan_id;
4621 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
4623 struct rte_eth_dev_info dev_info;
4626 if (vlan_id_is_invalid(vlan_id))
4628 if (vlan_id_is_invalid(vlan_id_outer))
4631 ret = eth_dev_info_get_print_err(port_id, &dev_info);
4635 if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_QINQ_INSERT) == 0) {
4637 "Error: qinq insert not supported by port %d\n",
4642 tx_vlan_reset(port_id);
4643 ports[port_id].dev_conf.txmode.offloads |= (RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
4644 RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
4645 ports[port_id].tx_vlan_id = vlan_id;
4646 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
4650 tx_vlan_reset(portid_t port_id)
4652 ports[port_id].dev_conf.txmode.offloads &=
4653 ~(RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
4654 RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
4655 ports[port_id].tx_vlan_id = 0;
4656 ports[port_id].tx_vlan_id_outer = 0;
4660 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
4662 if (port_id_is_invalid(port_id, ENABLED_WARN))
4665 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
4669 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
4673 if (port_id_is_invalid(port_id, ENABLED_WARN))
4676 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
4679 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
4680 fprintf(stderr, "map_value not in required range 0..%d\n",
4681 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
4685 if (!is_rx) { /* tx */
4686 ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, queue_id,
4690 "failed to set tx queue stats mapping.\n");
4694 ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, queue_id,
4698 "failed to set rx queue stats mapping.\n");
4705 set_xstats_hide_zero(uint8_t on_off)
4707 xstats_hide_zero = on_off;
4711 set_record_core_cycles(uint8_t on_off)
4713 record_core_cycles = on_off;
4717 set_record_burst_stats(uint8_t on_off)
4719 record_burst_stats = on_off;
4723 flowtype_to_str(uint16_t flow_type)
4725 struct flow_type_info {
4731 static struct flow_type_info flowtype_str_table[] = {
4732 {"raw", RTE_ETH_FLOW_RAW},
4733 {"ipv4", RTE_ETH_FLOW_IPV4},
4734 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
4735 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
4736 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
4737 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
4738 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
4739 {"ipv6", RTE_ETH_FLOW_IPV6},
4740 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
4741 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
4742 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
4743 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
4744 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
4745 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
4746 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
4747 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
4748 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
4749 {"port", RTE_ETH_FLOW_PORT},
4750 {"vxlan", RTE_ETH_FLOW_VXLAN},
4751 {"geneve", RTE_ETH_FLOW_GENEVE},
4752 {"nvgre", RTE_ETH_FLOW_NVGRE},
4753 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
4754 {"gtpu", RTE_ETH_FLOW_GTPU},
4757 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
4758 if (flowtype_str_table[i].ftype == flow_type)
4759 return flowtype_str_table[i].str;
4765 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
4768 print_fdir_mask(struct rte_eth_fdir_masks *mask)
4770 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
4772 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4773 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
4774 " tunnel_id: 0x%08x",
4775 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
4776 rte_be_to_cpu_32(mask->tunnel_id_mask));
4777 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
4778 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
4779 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
4780 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
4782 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
4783 rte_be_to_cpu_16(mask->src_port_mask),
4784 rte_be_to_cpu_16(mask->dst_port_mask));
4786 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4787 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
4788 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
4789 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
4790 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
4792 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
4793 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
4794 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
4795 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
4796 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
4803 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4805 struct rte_eth_flex_payload_cfg *cfg;
4808 for (i = 0; i < flex_conf->nb_payloads; i++) {
4809 cfg = &flex_conf->flex_set[i];
4810 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
4812 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
4813 printf("\n L2_PAYLOAD: ");
4814 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
4815 printf("\n L3_PAYLOAD: ");
4816 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
4817 printf("\n L4_PAYLOAD: ");
4819 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
4820 for (j = 0; j < num; j++)
4821 printf(" %-5u", cfg->src_offset[j]);
4827 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
4829 struct rte_eth_fdir_flex_mask *mask;
4833 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
4834 mask = &flex_conf->flex_mask[i];
4835 p = flowtype_to_str(mask->flow_type);
4836 printf("\n %s:\t", p ? p : "unknown");
4837 for (j = 0; j < num; j++)
4838 printf(" %02x", mask->mask[j]);
4844 print_fdir_flow_type(uint32_t flow_types_mask)
4849 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
4850 if (!(flow_types_mask & (1 << i)))
4852 p = flowtype_to_str(i);
4862 get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info,
4863 struct rte_eth_fdir_stats *fdir_stat)
4868 if (ret == -ENOTSUP) {
4869 ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info);
4871 ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat);
4874 #ifdef RTE_NET_IXGBE
4875 if (ret == -ENOTSUP) {
4876 ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info);
4878 ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat);
4885 fprintf(stderr, "\n FDIR is not supported on port %-2d\n",
4889 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
4896 fdir_get_infos(portid_t port_id)
4898 struct rte_eth_fdir_stats fdir_stat;
4899 struct rte_eth_fdir_info fdir_info;
4901 static const char *fdir_stats_border = "########################";
4903 if (port_id_is_invalid(port_id, ENABLED_WARN))
4906 memset(&fdir_info, 0, sizeof(fdir_info));
4907 memset(&fdir_stat, 0, sizeof(fdir_stat));
4908 if (get_fdir_info(port_id, &fdir_info, &fdir_stat))
4911 printf("\n %s FDIR infos for port %-2d %s\n",
4912 fdir_stats_border, port_id, fdir_stats_border);
4914 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
4915 printf(" PERFECT\n");
4916 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
4917 printf(" PERFECT-MAC-VLAN\n");
4918 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
4919 printf(" PERFECT-TUNNEL\n");
4920 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
4921 printf(" SIGNATURE\n");
4923 printf(" DISABLE\n");
4924 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
4925 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
4926 printf(" SUPPORTED FLOW TYPE: ");
4927 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
4929 printf(" FLEX PAYLOAD INFO:\n");
4930 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
4931 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
4932 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
4933 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
4934 fdir_info.flex_payload_unit,
4935 fdir_info.max_flex_payload_segment_num,
4936 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
4938 print_fdir_mask(&fdir_info.mask);
4939 if (fdir_info.flex_conf.nb_payloads > 0) {
4940 printf(" FLEX PAYLOAD SRC OFFSET:");
4941 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4943 if (fdir_info.flex_conf.nb_flexmasks > 0) {
4944 printf(" FLEX MASK CFG:");
4945 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
4947 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
4948 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
4949 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
4950 fdir_info.guarant_spc, fdir_info.best_spc);
4951 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
4952 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
4953 " add: %-10"PRIu64" remove: %"PRIu64"\n"
4954 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
4955 fdir_stat.collision, fdir_stat.free,
4956 fdir_stat.maxhash, fdir_stat.maxlen,
4957 fdir_stat.add, fdir_stat.remove,
4958 fdir_stat.f_add, fdir_stat.f_remove);
4959 printf(" %s############################%s\n",
4960 fdir_stats_border, fdir_stats_border);
4963 #endif /* RTE_NET_I40E || RTE_NET_IXGBE */
4966 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
4968 struct rte_port *port;
4969 struct rte_eth_fdir_flex_conf *flex_conf;
4972 port = &ports[port_id];
4973 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
4974 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
4975 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
4980 if (i >= RTE_ETH_FLOW_MAX) {
4981 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
4982 idx = flex_conf->nb_flexmasks;
4983 flex_conf->nb_flexmasks++;
4986 "The flex mask table is full. Can not set flex mask for flow_type(%u).",
4991 rte_memcpy(&flex_conf->flex_mask[idx],
4993 sizeof(struct rte_eth_fdir_flex_mask));
4997 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
4999 struct rte_port *port;
5000 struct rte_eth_fdir_flex_conf *flex_conf;
5003 port = &ports[port_id];
5004 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
5005 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
5006 if (cfg->type == flex_conf->flex_set[i].type) {
5011 if (i >= RTE_ETH_PAYLOAD_MAX) {
5012 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
5013 idx = flex_conf->nb_payloads;
5014 flex_conf->nb_payloads++;
5017 "The flex payload table is full. Can not set flex payload for type(%u).",
5022 rte_memcpy(&flex_conf->flex_set[idx],
5024 sizeof(struct rte_eth_flex_payload_cfg));
5029 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
5031 #ifdef RTE_NET_IXGBE
5035 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
5037 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
5042 "rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
5043 is_rx ? "rx" : "tx", port_id, diag);
5046 fprintf(stderr, "VF %s setting not supported for port %d\n",
5047 is_rx ? "Rx" : "Tx", port_id);
5053 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
5056 struct rte_eth_link link;
5059 if (port_id_is_invalid(port_id, ENABLED_WARN))
5061 ret = eth_link_get_nowait_print_err(port_id, &link);
5064 if (link.link_speed != RTE_ETH_SPEED_NUM_UNKNOWN &&
5065 rate > link.link_speed) {
5067 "Invalid rate value:%u bigger than link speed: %u\n",
5068 rate, link.link_speed);
5071 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
5075 "rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
5081 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
5083 int diag = -ENOTSUP;
5087 RTE_SET_USED(q_msk);
5089 #ifdef RTE_NET_IXGBE
5090 if (diag == -ENOTSUP)
5091 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
5095 if (diag == -ENOTSUP)
5096 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
5102 "%s for port_id=%d failed diag=%d\n",
5103 __func__, port_id, diag);
5108 * Functions to manage the set of filtered Multicast MAC addresses.
5110 * A pool of filtered multicast MAC addresses is associated with each port.
5111 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
5112 * The address of the pool and the number of valid multicast MAC addresses
5113 * recorded in the pool are stored in the fields "mc_addr_pool" and
5114 * "mc_addr_nb" of the "rte_port" data structure.
5116 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
5117 * to be supplied a contiguous array of multicast MAC addresses.
5118 * To comply with this constraint, the set of multicast addresses recorded
5119 * into the pool are systematically compacted at the beginning of the pool.
5120 * Hence, when a multicast address is removed from the pool, all following
5121 * addresses, if any, are copied back to keep the set contiguous.
5123 #define MCAST_POOL_INC 32
5126 mcast_addr_pool_extend(struct rte_port *port)
5128 struct rte_ether_addr *mc_pool;
5129 size_t mc_pool_size;
5132 * If a free entry is available at the end of the pool, just
5133 * increment the number of recorded multicast addresses.
5135 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
5141 * [re]allocate a pool with MCAST_POOL_INC more entries.
5142 * The previous test guarantees that port->mc_addr_nb is a multiple
5143 * of MCAST_POOL_INC.
5145 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
5147 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
5149 if (mc_pool == NULL) {
5151 "allocation of pool of %u multicast addresses failed\n",
5152 port->mc_addr_nb + MCAST_POOL_INC);
5156 port->mc_addr_pool = mc_pool;
5163 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
5165 if (mcast_addr_pool_extend(port) != 0)
5167 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
5171 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
5174 if (addr_idx == port->mc_addr_nb) {
5175 /* No need to recompact the set of multicast addresses. */
5176 if (port->mc_addr_nb == 0) {
5177 /* free the pool of multicast addresses. */
5178 free(port->mc_addr_pool);
5179 port->mc_addr_pool = NULL;
5183 memmove(&port->mc_addr_pool[addr_idx],
5184 &port->mc_addr_pool[addr_idx + 1],
5185 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
5189 eth_port_multicast_addr_list_set(portid_t port_id)
5191 struct rte_port *port;
5194 port = &ports[port_id];
5195 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
5199 "rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
5200 port_id, port->mc_addr_nb, diag);
5206 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
5208 struct rte_port *port;
5211 if (port_id_is_invalid(port_id, ENABLED_WARN))
5214 port = &ports[port_id];
5217 * Check that the added multicast MAC address is not already recorded
5218 * in the pool of multicast addresses.
5220 for (i = 0; i < port->mc_addr_nb; i++) {
5221 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
5223 "multicast address already filtered by port\n");
5228 mcast_addr_pool_append(port, mc_addr);
5229 if (eth_port_multicast_addr_list_set(port_id) < 0)
5230 /* Rollback on failure, remove the address from the pool */
5231 mcast_addr_pool_remove(port, i);
5235 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
5237 struct rte_port *port;
5240 if (port_id_is_invalid(port_id, ENABLED_WARN))
5243 port = &ports[port_id];
5246 * Search the pool of multicast MAC addresses for the removed address.
5248 for (i = 0; i < port->mc_addr_nb; i++) {
5249 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
5252 if (i == port->mc_addr_nb) {
5253 fprintf(stderr, "multicast address not filtered by port %d\n",
5258 mcast_addr_pool_remove(port, i);
5259 if (eth_port_multicast_addr_list_set(port_id) < 0)
5260 /* Rollback on failure, add the address back into the pool */
5261 mcast_addr_pool_append(port, mc_addr);
5265 port_dcb_info_display(portid_t port_id)
5267 struct rte_eth_dcb_info dcb_info;
5270 static const char *border = "================";
5272 if (port_id_is_invalid(port_id, ENABLED_WARN))
5275 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
5277 fprintf(stderr, "\n Failed to get dcb infos on port %-2d\n",
5281 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
5282 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
5284 for (i = 0; i < dcb_info.nb_tcs; i++)
5286 printf("\n Priority : ");
5287 for (i = 0; i < dcb_info.nb_tcs; i++)
5288 printf("\t%4d", dcb_info.prio_tc[i]);
5289 printf("\n BW percent :");
5290 for (i = 0; i < dcb_info.nb_tcs; i++)
5291 printf("\t%4d%%", dcb_info.tc_bws[i]);
5292 printf("\n RXQ base : ");
5293 for (i = 0; i < dcb_info.nb_tcs; i++)
5294 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
5295 printf("\n RXQ number :");
5296 for (i = 0; i < dcb_info.nb_tcs; i++)
5297 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
5298 printf("\n TXQ base : ");
5299 for (i = 0; i < dcb_info.nb_tcs; i++)
5300 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
5301 printf("\n TXQ number :");
5302 for (i = 0; i < dcb_info.nb_tcs; i++)
5303 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
5308 open_file(const char *file_path, uint32_t *size)
5310 int fd = open(file_path, O_RDONLY);
5312 uint8_t *buf = NULL;
5320 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
5324 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
5326 fprintf(stderr, "%s: File operations failed\n", __func__);
5330 pkg_size = st_buf.st_size;
5333 fprintf(stderr, "%s: File operations failed\n", __func__);
5337 buf = (uint8_t *)malloc(pkg_size);
5340 fprintf(stderr, "%s: Failed to malloc memory\n", __func__);
5344 ret = read(fd, buf, pkg_size);
5347 fprintf(stderr, "%s: File read operation failed\n", __func__);
5361 save_file(const char *file_path, uint8_t *buf, uint32_t size)
5363 FILE *fh = fopen(file_path, "wb");
5366 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
5370 if (fwrite(buf, 1, size, fh) != size) {
5372 fprintf(stderr, "%s: File write operation failed\n", __func__);
5382 close_file(uint8_t *buf)
5393 port_queue_region_info_display(portid_t port_id, void *buf)
5397 struct rte_pmd_i40e_queue_regions *info =
5398 (struct rte_pmd_i40e_queue_regions *)buf;
5399 static const char *queue_region_info_stats_border = "-------";
5401 if (!info->queue_region_number)
5402 printf("there is no region has been set before");
5404 printf("\n %s All queue region info for port=%2d %s",
5405 queue_region_info_stats_border, port_id,
5406 queue_region_info_stats_border);
5407 printf("\n queue_region_number: %-14u \n",
5408 info->queue_region_number);
5410 for (i = 0; i < info->queue_region_number; i++) {
5411 printf("\n region_id: %-14u queue_number: %-14u "
5412 "queue_start_index: %-14u \n",
5413 info->region[i].region_id,
5414 info->region[i].queue_num,
5415 info->region[i].queue_start_index);
5417 printf(" user_priority_num is %-14u :",
5418 info->region[i].user_priority_num);
5419 for (j = 0; j < info->region[i].user_priority_num; j++)
5420 printf(" %-14u ", info->region[i].user_priority[j]);
5422 printf("\n flowtype_num is %-14u :",
5423 info->region[i].flowtype_num);
5424 for (j = 0; j < info->region[i].flowtype_num; j++)
5425 printf(" %-14u ", info->region[i].hw_flowtype[j]);
5428 RTE_SET_USED(port_id);
5436 show_macs(portid_t port_id)
5438 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5439 struct rte_eth_dev_info dev_info;
5440 int32_t i, rc, num_macs = 0;
5442 if (eth_dev_info_get_print_err(port_id, &dev_info))
5445 struct rte_ether_addr addr[dev_info.max_mac_addrs];
5446 rc = rte_eth_macaddrs_get(port_id, addr, dev_info.max_mac_addrs);
5450 for (i = 0; i < rc; i++) {
5452 /* skip zero address */
5453 if (rte_is_zero_ether_addr(&addr[i]))
5459 printf("Number of MAC address added: %d\n", num_macs);
5461 for (i = 0; i < rc; i++) {
5463 /* skip zero address */
5464 if (rte_is_zero_ether_addr(&addr[i]))
5467 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &addr[i]);
5468 printf(" %s\n", buf);
5473 show_mcast_macs(portid_t port_id)
5475 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5476 struct rte_ether_addr *addr;
5477 struct rte_port *port;
5480 port = &ports[port_id];
5482 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
5484 for (i = 0; i < port->mc_addr_nb; i++) {
5485 addr = &port->mc_addr_pool[i];
5487 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5488 printf(" %s\n", buf);