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
70 enum tx_pkt_split split;
74 .split = TX_PKT_SPLIT_OFF,
78 .split = TX_PKT_SPLIT_ON,
82 .split = TX_PKT_SPLIT_RND,
87 const struct rss_type_info rss_type_table[] = {
88 { "all", RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP | RTE_ETH_RSS_TCP |
89 RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP | RTE_ETH_RSS_L2_PAYLOAD |
90 RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP | RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP |
91 RTE_ETH_RSS_GTPU | RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_MPLS | RTE_ETH_RSS_L2TPV2},
93 { "eth", RTE_ETH_RSS_ETH },
94 { "l2-src-only", RTE_ETH_RSS_L2_SRC_ONLY },
95 { "l2-dst-only", RTE_ETH_RSS_L2_DST_ONLY },
96 { "vlan", RTE_ETH_RSS_VLAN },
97 { "s-vlan", RTE_ETH_RSS_S_VLAN },
98 { "c-vlan", RTE_ETH_RSS_C_VLAN },
99 { "ipv4", RTE_ETH_RSS_IPV4 },
100 { "ipv4-frag", RTE_ETH_RSS_FRAG_IPV4 },
101 { "ipv4-tcp", RTE_ETH_RSS_NONFRAG_IPV4_TCP },
102 { "ipv4-udp", RTE_ETH_RSS_NONFRAG_IPV4_UDP },
103 { "ipv4-sctp", RTE_ETH_RSS_NONFRAG_IPV4_SCTP },
104 { "ipv4-other", RTE_ETH_RSS_NONFRAG_IPV4_OTHER },
105 { "ipv6", RTE_ETH_RSS_IPV6 },
106 { "ipv6-frag", RTE_ETH_RSS_FRAG_IPV6 },
107 { "ipv6-tcp", RTE_ETH_RSS_NONFRAG_IPV6_TCP },
108 { "ipv6-udp", RTE_ETH_RSS_NONFRAG_IPV6_UDP },
109 { "ipv6-sctp", RTE_ETH_RSS_NONFRAG_IPV6_SCTP },
110 { "ipv6-other", RTE_ETH_RSS_NONFRAG_IPV6_OTHER },
111 { "l2-payload", RTE_ETH_RSS_L2_PAYLOAD },
112 { "ipv6-ex", RTE_ETH_RSS_IPV6_EX },
113 { "ipv6-tcp-ex", RTE_ETH_RSS_IPV6_TCP_EX },
114 { "ipv6-udp-ex", RTE_ETH_RSS_IPV6_UDP_EX },
115 { "port", RTE_ETH_RSS_PORT },
116 { "vxlan", RTE_ETH_RSS_VXLAN },
117 { "geneve", RTE_ETH_RSS_GENEVE },
118 { "nvgre", RTE_ETH_RSS_NVGRE },
119 { "ip", RTE_ETH_RSS_IP },
120 { "udp", RTE_ETH_RSS_UDP },
121 { "tcp", RTE_ETH_RSS_TCP },
122 { "sctp", RTE_ETH_RSS_SCTP },
123 { "tunnel", RTE_ETH_RSS_TUNNEL },
124 { "l3-pre32", RTE_ETH_RSS_L3_PRE32 },
125 { "l3-pre40", RTE_ETH_RSS_L3_PRE40 },
126 { "l3-pre48", RTE_ETH_RSS_L3_PRE48 },
127 { "l3-pre56", RTE_ETH_RSS_L3_PRE56 },
128 { "l3-pre64", RTE_ETH_RSS_L3_PRE64 },
129 { "l3-pre96", RTE_ETH_RSS_L3_PRE96 },
130 { "l3-src-only", RTE_ETH_RSS_L3_SRC_ONLY },
131 { "l3-dst-only", RTE_ETH_RSS_L3_DST_ONLY },
132 { "l4-src-only", RTE_ETH_RSS_L4_SRC_ONLY },
133 { "l4-dst-only", RTE_ETH_RSS_L4_DST_ONLY },
134 { "esp", RTE_ETH_RSS_ESP },
135 { "ah", RTE_ETH_RSS_AH },
136 { "l2tpv3", RTE_ETH_RSS_L2TPV3 },
137 { "pfcp", RTE_ETH_RSS_PFCP },
138 { "pppoe", RTE_ETH_RSS_PPPOE },
139 { "gtpu", RTE_ETH_RSS_GTPU },
140 { "ecpri", RTE_ETH_RSS_ECPRI },
141 { "mpls", RTE_ETH_RSS_MPLS },
142 { "ipv4-chksum", RTE_ETH_RSS_IPV4_CHKSUM },
143 { "l4-chksum", RTE_ETH_RSS_L4_CHKSUM },
144 { "l2tpv2", RTE_ETH_RSS_L2TPV2 },
148 static const struct {
149 enum rte_eth_fec_mode mode;
151 } fec_mode_name[] = {
153 .mode = RTE_ETH_FEC_NOFEC,
157 .mode = RTE_ETH_FEC_AUTO,
161 .mode = RTE_ETH_FEC_BASER,
165 .mode = RTE_ETH_FEC_RS,
171 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
173 char buf[RTE_ETHER_ADDR_FMT_SIZE];
174 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
175 printf("%s%s", name, buf);
179 nic_xstats_display_periodic(portid_t port_id)
181 struct xstat_display_info *xstats_info;
182 uint64_t *prev_values, *curr_values;
183 uint64_t diff_value, value_rate;
184 struct timespec cur_time;
191 xstats_info = &ports[port_id].xstats_info;
193 ids_supp_sz = xstats_info->ids_supp_sz;
194 if (ids_supp_sz == 0)
199 ids_supp = xstats_info->ids_supp;
200 prev_values = xstats_info->prev_values;
201 curr_values = xstats_info->curr_values;
203 rc = rte_eth_xstats_get_by_id(port_id, ids_supp, curr_values,
205 if (rc != (int)ids_supp_sz) {
207 "Failed to get values of %zu xstats for port %u - return code %d\n",
208 ids_supp_sz, port_id, rc);
213 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
216 ns = cur_time.tv_sec * NS_PER_SEC;
217 ns += cur_time.tv_nsec;
219 if (xstats_info->prev_ns != 0)
220 diff_ns = ns - xstats_info->prev_ns;
221 xstats_info->prev_ns = ns;
224 printf("%-31s%-17s%s\n", " ", "Value", "Rate (since last show)");
225 for (i = 0; i < ids_supp_sz; i++) {
226 diff_value = (curr_values[i] > prev_values[i]) ?
227 (curr_values[i] - prev_values[i]) : 0;
228 prev_values[i] = curr_values[i];
229 value_rate = diff_ns > 0 ?
230 (double)diff_value / diff_ns * NS_PER_SEC : 0;
232 printf(" %-25s%12"PRIu64" %15"PRIu64"\n",
233 xstats_display[i].name, curr_values[i], value_rate);
238 nic_stats_display(portid_t port_id)
240 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
241 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
242 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
243 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
244 static uint64_t prev_ns[RTE_MAX_ETHPORTS];
245 struct timespec cur_time;
246 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
248 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
249 struct rte_eth_stats stats;
250 static const char *nic_stats_border = "########################";
253 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
257 ret = rte_eth_stats_get(port_id, &stats);
260 "%s: Error: failed to get stats (port %u): %d",
261 __func__, port_id, ret);
264 printf("\n %s NIC statistics for port %-2d %s\n",
265 nic_stats_border, port_id, nic_stats_border);
267 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
268 "%-"PRIu64"\n", stats.ipackets, stats.imissed, stats.ibytes);
269 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
270 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
271 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
272 "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
275 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
278 ns = cur_time.tv_sec * NS_PER_SEC;
279 ns += cur_time.tv_nsec;
281 if (prev_ns[port_id] != 0)
282 diff_ns = ns - prev_ns[port_id];
283 prev_ns[port_id] = ns;
286 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
287 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
288 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
289 (stats.opackets - prev_pkts_tx[port_id]) : 0;
290 prev_pkts_rx[port_id] = stats.ipackets;
291 prev_pkts_tx[port_id] = stats.opackets;
292 mpps_rx = diff_ns > 0 ?
293 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
294 mpps_tx = diff_ns > 0 ?
295 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
297 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
298 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
299 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
300 (stats.obytes - prev_bytes_tx[port_id]) : 0;
301 prev_bytes_rx[port_id] = stats.ibytes;
302 prev_bytes_tx[port_id] = stats.obytes;
303 mbps_rx = diff_ns > 0 ?
304 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
305 mbps_tx = diff_ns > 0 ?
306 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
308 printf("\n Throughput (since last show)\n");
309 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
310 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
311 mpps_tx, mbps_tx * 8);
313 if (xstats_display_num > 0)
314 nic_xstats_display_periodic(port_id);
316 printf(" %s############################%s\n",
317 nic_stats_border, nic_stats_border);
321 nic_stats_clear(portid_t port_id)
325 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
330 ret = rte_eth_stats_reset(port_id);
333 "%s: Error: failed to reset stats (port %u): %s",
334 __func__, port_id, strerror(-ret));
338 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
343 "%s: Error: failed to get stats (port %u): %s",
344 __func__, port_id, strerror(ret));
347 printf("\n NIC statistics for port %d cleared\n", port_id);
351 nic_xstats_display(portid_t port_id)
353 struct rte_eth_xstat *xstats;
354 int cnt_xstats, idx_xstat;
355 struct rte_eth_xstat_name *xstats_names;
357 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
361 printf("###### NIC extended statistics for port %-2d\n", port_id);
362 if (!rte_eth_dev_is_valid_port(port_id)) {
363 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
368 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
369 if (cnt_xstats < 0) {
370 fprintf(stderr, "Error: Cannot get count of xstats\n");
374 /* Get id-name lookup table */
375 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
376 if (xstats_names == NULL) {
377 fprintf(stderr, "Cannot allocate memory for xstats lookup\n");
380 if (cnt_xstats != rte_eth_xstats_get_names(
381 port_id, xstats_names, cnt_xstats)) {
382 fprintf(stderr, "Error: Cannot get xstats lookup\n");
387 /* Get stats themselves */
388 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
389 if (xstats == NULL) {
390 fprintf(stderr, "Cannot allocate memory for xstats\n");
394 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
395 fprintf(stderr, "Error: Unable to get xstats\n");
402 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
403 if (xstats_hide_zero && !xstats[idx_xstat].value)
405 printf("%s: %"PRIu64"\n",
406 xstats_names[idx_xstat].name,
407 xstats[idx_xstat].value);
414 nic_xstats_clear(portid_t port_id)
418 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
423 ret = rte_eth_xstats_reset(port_id);
426 "%s: Error: failed to reset xstats (port %u): %s\n",
427 __func__, port_id, strerror(-ret));
431 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
435 fprintf(stderr, "%s: Error: failed to get stats (port %u): %s",
436 __func__, port_id, strerror(ret));
442 get_queue_state_name(uint8_t queue_state)
444 if (queue_state == RTE_ETH_QUEUE_STATE_STOPPED)
446 else if (queue_state == RTE_ETH_QUEUE_STATE_STARTED)
448 else if (queue_state == RTE_ETH_QUEUE_STATE_HAIRPIN)
455 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
457 struct rte_eth_burst_mode mode;
458 struct rte_eth_rxq_info qinfo;
460 static const char *info_border = "*********************";
462 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
465 "Failed to retrieve information for port: %u, RX queue: %hu\nerror desc: %s(%d)\n",
466 port_id, queue_id, strerror(-rc), rc);
470 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
471 info_border, port_id, queue_id, info_border);
473 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
474 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
475 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
476 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
477 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
478 printf("\nRX drop packets: %s",
479 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
480 printf("\nRX deferred start: %s",
481 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
482 printf("\nRX scattered packets: %s",
483 (qinfo.scattered_rx != 0) ? "on" : "off");
484 printf("\nRx queue state: %s", get_queue_state_name(qinfo.queue_state));
485 if (qinfo.rx_buf_size != 0)
486 printf("\nRX buffer size: %hu", qinfo.rx_buf_size);
487 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
489 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
490 printf("\nBurst mode: %s%s",
492 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
493 " (per queue)" : "");
499 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
501 struct rte_eth_burst_mode mode;
502 struct rte_eth_txq_info qinfo;
504 static const char *info_border = "*********************";
506 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
509 "Failed to retrieve information for port: %u, TX queue: %hu\nerror desc: %s(%d)\n",
510 port_id, queue_id, strerror(-rc), rc);
514 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
515 info_border, port_id, queue_id, info_border);
517 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
518 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
519 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
520 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
521 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
522 printf("\nTX deferred start: %s",
523 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
524 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
525 printf("\nTx queue state: %s", get_queue_state_name(qinfo.queue_state));
527 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
528 printf("\nBurst mode: %s%s",
530 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
531 " (per queue)" : "");
536 static int bus_match_all(const struct rte_bus *bus, const void *data)
544 device_infos_display_speeds(uint32_t speed_capa)
546 printf("\n\tDevice speed capability:");
547 if (speed_capa == RTE_ETH_LINK_SPEED_AUTONEG)
548 printf(" Autonegotiate (all speeds)");
549 if (speed_capa & RTE_ETH_LINK_SPEED_FIXED)
550 printf(" Disable autonegotiate (fixed speed) ");
551 if (speed_capa & RTE_ETH_LINK_SPEED_10M_HD)
552 printf(" 10 Mbps half-duplex ");
553 if (speed_capa & RTE_ETH_LINK_SPEED_10M)
554 printf(" 10 Mbps full-duplex ");
555 if (speed_capa & RTE_ETH_LINK_SPEED_100M_HD)
556 printf(" 100 Mbps half-duplex ");
557 if (speed_capa & RTE_ETH_LINK_SPEED_100M)
558 printf(" 100 Mbps full-duplex ");
559 if (speed_capa & RTE_ETH_LINK_SPEED_1G)
561 if (speed_capa & RTE_ETH_LINK_SPEED_2_5G)
562 printf(" 2.5 Gbps ");
563 if (speed_capa & RTE_ETH_LINK_SPEED_5G)
565 if (speed_capa & RTE_ETH_LINK_SPEED_10G)
567 if (speed_capa & RTE_ETH_LINK_SPEED_20G)
569 if (speed_capa & RTE_ETH_LINK_SPEED_25G)
571 if (speed_capa & RTE_ETH_LINK_SPEED_40G)
573 if (speed_capa & RTE_ETH_LINK_SPEED_50G)
575 if (speed_capa & RTE_ETH_LINK_SPEED_56G)
577 if (speed_capa & RTE_ETH_LINK_SPEED_100G)
578 printf(" 100 Gbps ");
579 if (speed_capa & RTE_ETH_LINK_SPEED_200G)
580 printf(" 200 Gbps ");
584 device_infos_display(const char *identifier)
586 static const char *info_border = "*********************";
587 struct rte_bus *start = NULL, *next;
588 struct rte_dev_iterator dev_iter;
589 char name[RTE_ETH_NAME_MAX_LEN];
590 struct rte_ether_addr mac_addr;
591 struct rte_device *dev;
592 struct rte_devargs da;
594 struct rte_eth_dev_info dev_info;
597 memset(&da, 0, sizeof(da));
601 if (rte_devargs_parsef(&da, "%s", identifier)) {
602 fprintf(stderr, "cannot parse identifier\n");
607 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
610 if (identifier && da.bus != next)
613 /* Skip buses that don't have iterate method */
614 if (!next->dev_iterate)
617 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
618 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
622 /* Check for matching device if identifier is present */
624 strncmp(da.name, dev->name, strlen(dev->name)))
626 printf("\n%s Infos for device %s %s\n",
627 info_border, dev->name, info_border);
628 printf("Bus name: %s", dev->bus->name);
629 printf("\nDriver name: %s", dev->driver->name);
630 printf("\nDevargs: %s",
631 dev->devargs ? dev->devargs->args : "");
632 printf("\nConnect to socket: %d", dev->numa_node);
635 /* List ports with matching device name */
636 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
637 printf("\n\tPort id: %-2d", port_id);
638 if (eth_macaddr_get_print_err(port_id,
640 print_ethaddr("\n\tMAC address: ",
642 rte_eth_dev_get_name_by_port(port_id, name);
643 printf("\n\tDevice name: %s", name);
644 if (rte_eth_dev_info_get(port_id, &dev_info) == 0)
645 device_infos_display_speeds(dev_info.speed_capa);
650 rte_devargs_reset(&da);
654 print_dev_capabilities(uint64_t capabilities)
656 uint64_t single_capa;
661 if (capabilities == 0)
664 begin = __builtin_ctzll(capabilities);
665 end = sizeof(capabilities) * CHAR_BIT - __builtin_clzll(capabilities);
667 single_capa = 1ULL << begin;
668 for (bit = begin; bit < end; bit++) {
669 if (capabilities & single_capa)
671 rte_eth_dev_capability_name(single_capa));
677 str_to_rsstypes(const char *str)
681 for (i = 0; rss_type_table[i].str != NULL; i++) {
682 if (strcmp(rss_type_table[i].str, str) == 0)
683 return rss_type_table[i].rss_type;
690 rsstypes_to_str(uint64_t rss_type)
694 for (i = 0; rss_type_table[i].str != NULL; i++) {
695 if (rss_type_table[i].rss_type == rss_type)
696 return rss_type_table[i].str;
703 port_infos_display(portid_t port_id)
705 struct rte_port *port;
706 struct rte_ether_addr mac_addr;
707 struct rte_eth_link link;
708 struct rte_eth_dev_info dev_info;
710 struct rte_mempool * mp;
711 static const char *info_border = "*********************";
713 char name[RTE_ETH_NAME_MAX_LEN];
715 char fw_version[ETHDEV_FWVERS_LEN];
717 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
721 port = &ports[port_id];
722 ret = eth_link_get_nowait_print_err(port_id, &link);
726 ret = eth_dev_info_get_print_err(port_id, &dev_info);
730 printf("\n%s Infos for port %-2d %s\n",
731 info_border, port_id, info_border);
732 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
733 print_ethaddr("MAC address: ", &mac_addr);
734 rte_eth_dev_get_name_by_port(port_id, name);
735 printf("\nDevice name: %s", name);
736 printf("\nDriver name: %s", dev_info.driver_name);
738 if (rte_eth_dev_fw_version_get(port_id, fw_version,
739 ETHDEV_FWVERS_LEN) == 0)
740 printf("\nFirmware-version: %s", fw_version);
742 printf("\nFirmware-version: %s", "not available");
744 if (dev_info.device->devargs && dev_info.device->devargs->args)
745 printf("\nDevargs: %s", dev_info.device->devargs->args);
746 printf("\nConnect to socket: %u", port->socket_id);
748 if (port_numa[port_id] != NUMA_NO_CONFIG) {
749 mp = mbuf_pool_find(port_numa[port_id], 0);
751 printf("\nmemory allocation on the socket: %d",
754 printf("\nmemory allocation on the socket: %u",port->socket_id);
756 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
757 printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
758 printf("Link duplex: %s\n", (link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
759 ("full-duplex") : ("half-duplex"));
760 printf("Autoneg status: %s\n", (link.link_autoneg == RTE_ETH_LINK_AUTONEG) ?
763 if (!rte_eth_dev_get_mtu(port_id, &mtu))
764 printf("MTU: %u\n", mtu);
766 printf("Promiscuous mode: %s\n",
767 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
768 printf("Allmulticast mode: %s\n",
769 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
770 printf("Maximum number of MAC addresses: %u\n",
771 (unsigned int)(port->dev_info.max_mac_addrs));
772 printf("Maximum number of MAC addresses of hash filtering: %u\n",
773 (unsigned int)(port->dev_info.max_hash_mac_addrs));
775 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
776 if (vlan_offload >= 0){
777 printf("VLAN offload: \n");
778 if (vlan_offload & RTE_ETH_VLAN_STRIP_OFFLOAD)
779 printf(" strip on, ");
781 printf(" strip off, ");
783 if (vlan_offload & RTE_ETH_VLAN_FILTER_OFFLOAD)
784 printf("filter on, ");
786 printf("filter off, ");
788 if (vlan_offload & RTE_ETH_VLAN_EXTEND_OFFLOAD)
789 printf("extend on, ");
791 printf("extend off, ");
793 if (vlan_offload & RTE_ETH_QINQ_STRIP_OFFLOAD)
794 printf("qinq strip on\n");
796 printf("qinq strip off\n");
799 if (dev_info.hash_key_size > 0)
800 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
801 if (dev_info.reta_size > 0)
802 printf("Redirection table size: %u\n", dev_info.reta_size);
803 if (!dev_info.flow_type_rss_offloads)
804 printf("No RSS offload flow type is supported.\n");
806 uint64_t rss_offload_types = dev_info.flow_type_rss_offloads;
809 printf("Supported RSS offload flow types:\n");
810 for (i = 0; i < sizeof(rss_offload_types) * CHAR_BIT; i++) {
811 uint64_t rss_offload = RTE_BIT64(i);
812 if ((rss_offload_types & rss_offload) != 0) {
813 const char *p = rsstypes_to_str(rss_offload);
817 printf(" user defined %u\n",
823 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
824 printf("Maximum configurable length of RX packet: %u\n",
825 dev_info.max_rx_pktlen);
826 printf("Maximum configurable size of LRO aggregated packet: %u\n",
827 dev_info.max_lro_pkt_size);
828 if (dev_info.max_vfs)
829 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
830 if (dev_info.max_vmdq_pools)
831 printf("Maximum number of VMDq pools: %u\n",
832 dev_info.max_vmdq_pools);
834 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
835 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
836 printf("Max possible number of RXDs per queue: %hu\n",
837 dev_info.rx_desc_lim.nb_max);
838 printf("Min possible number of RXDs per queue: %hu\n",
839 dev_info.rx_desc_lim.nb_min);
840 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
842 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
843 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
844 printf("Max possible number of TXDs per queue: %hu\n",
845 dev_info.tx_desc_lim.nb_max);
846 printf("Min possible number of TXDs per queue: %hu\n",
847 dev_info.tx_desc_lim.nb_min);
848 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
849 printf("Max segment number per packet: %hu\n",
850 dev_info.tx_desc_lim.nb_seg_max);
851 printf("Max segment number per MTU/TSO: %hu\n",
852 dev_info.tx_desc_lim.nb_mtu_seg_max);
854 printf("Device capabilities: 0x%"PRIx64"(", dev_info.dev_capa);
855 print_dev_capabilities(dev_info.dev_capa);
857 /* Show switch info only if valid switch domain and port id is set */
858 if (dev_info.switch_info.domain_id !=
859 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
860 if (dev_info.switch_info.name)
861 printf("Switch name: %s\n", dev_info.switch_info.name);
863 printf("Switch domain Id: %u\n",
864 dev_info.switch_info.domain_id);
865 printf("Switch Port Id: %u\n",
866 dev_info.switch_info.port_id);
867 if ((dev_info.dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE) != 0)
868 printf("Switch Rx domain: %u\n",
869 dev_info.switch_info.rx_domain);
874 port_summary_header_display(void)
876 uint16_t port_number;
878 port_number = rte_eth_dev_count_avail();
879 printf("Number of available ports: %i\n", port_number);
880 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
881 "Driver", "Status", "Link");
885 port_summary_display(portid_t port_id)
887 struct rte_ether_addr mac_addr;
888 struct rte_eth_link link;
889 struct rte_eth_dev_info dev_info;
890 char name[RTE_ETH_NAME_MAX_LEN];
893 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
898 ret = eth_link_get_nowait_print_err(port_id, &link);
902 ret = eth_dev_info_get_print_err(port_id, &dev_info);
906 rte_eth_dev_get_name_by_port(port_id, name);
907 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
911 printf("%-4d " RTE_ETHER_ADDR_PRT_FMT " %-12s %-14s %-8s %s\n",
912 port_id, RTE_ETHER_ADDR_BYTES(&mac_addr), name,
913 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
914 rte_eth_link_speed_to_str(link.link_speed));
918 port_eeprom_display(portid_t port_id)
920 struct rte_dev_eeprom_info einfo;
922 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
927 int len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
928 if (len_eeprom < 0) {
929 switch (len_eeprom) {
931 fprintf(stderr, "port index %d invalid\n", port_id);
934 fprintf(stderr, "operation not supported by device\n");
937 fprintf(stderr, "device is removed\n");
940 fprintf(stderr, "Unable to get EEPROM: %d\n",
948 einfo.length = len_eeprom;
949 einfo.data = calloc(1, len_eeprom);
952 "Allocation of port %u eeprom data failed\n",
957 ret = rte_eth_dev_get_eeprom(port_id, &einfo);
961 fprintf(stderr, "port index %d invalid\n", port_id);
964 fprintf(stderr, "operation not supported by device\n");
967 fprintf(stderr, "device is removed\n");
970 fprintf(stderr, "Unable to get EEPROM: %d\n", ret);
976 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
977 printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
982 port_module_eeprom_display(portid_t port_id)
984 struct rte_eth_dev_module_info minfo;
985 struct rte_dev_eeprom_info einfo;
988 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
994 ret = rte_eth_dev_get_module_info(port_id, &minfo);
998 fprintf(stderr, "port index %d invalid\n", port_id);
1001 fprintf(stderr, "operation not supported by device\n");
1004 fprintf(stderr, "device is removed\n");
1007 fprintf(stderr, "Unable to get module EEPROM: %d\n",
1015 einfo.length = minfo.eeprom_len;
1016 einfo.data = calloc(1, minfo.eeprom_len);
1019 "Allocation of port %u eeprom data failed\n",
1024 ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
1028 fprintf(stderr, "port index %d invalid\n", port_id);
1031 fprintf(stderr, "operation not supported by device\n");
1034 fprintf(stderr, "device is removed\n");
1037 fprintf(stderr, "Unable to get module EEPROM: %d\n",
1045 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
1046 printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
1051 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1055 if (port_id == (portid_t)RTE_PORT_ALL)
1058 RTE_ETH_FOREACH_DEV(pid)
1062 if (warning == ENABLED_WARN)
1063 fprintf(stderr, "Invalid port %d\n", port_id);
1068 void print_valid_ports(void)
1072 printf("The valid ports array is [");
1073 RTE_ETH_FOREACH_DEV(pid) {
1080 vlan_id_is_invalid(uint16_t vlan_id)
1084 fprintf(stderr, "Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1089 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1091 const struct rte_pci_device *pci_dev;
1092 const struct rte_bus *bus;
1095 if (reg_off & 0x3) {
1097 "Port register offset 0x%X not aligned on a 4-byte boundary\n",
1098 (unsigned int)reg_off);
1102 if (!ports[port_id].dev_info.device) {
1103 fprintf(stderr, "Invalid device\n");
1107 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1108 if (bus && !strcmp(bus->name, "pci")) {
1109 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1111 fprintf(stderr, "Not a PCI device\n");
1115 pci_len = pci_dev->mem_resource[0].len;
1116 if (reg_off >= pci_len) {
1118 "Port %d: register offset %u (0x%X) out of port PCI resource (length=%"PRIu64")\n",
1119 port_id, (unsigned int)reg_off, (unsigned int)reg_off,
1127 reg_bit_pos_is_invalid(uint8_t bit_pos)
1131 fprintf(stderr, "Invalid bit position %d (must be <= 31)\n", bit_pos);
1135 #define display_port_and_reg_off(port_id, reg_off) \
1136 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1139 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1141 display_port_and_reg_off(port_id, (unsigned)reg_off);
1142 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1146 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1151 if (port_id_is_invalid(port_id, ENABLED_WARN))
1153 if (port_reg_off_is_invalid(port_id, reg_off))
1155 if (reg_bit_pos_is_invalid(bit_x))
1157 reg_v = port_id_pci_reg_read(port_id, reg_off);
1158 display_port_and_reg_off(port_id, (unsigned)reg_off);
1159 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1163 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1164 uint8_t bit1_pos, uint8_t bit2_pos)
1170 if (port_id_is_invalid(port_id, ENABLED_WARN))
1172 if (port_reg_off_is_invalid(port_id, reg_off))
1174 if (reg_bit_pos_is_invalid(bit1_pos))
1176 if (reg_bit_pos_is_invalid(bit2_pos))
1178 if (bit1_pos > bit2_pos)
1179 l_bit = bit2_pos, h_bit = bit1_pos;
1181 l_bit = bit1_pos, h_bit = bit2_pos;
1183 reg_v = port_id_pci_reg_read(port_id, reg_off);
1186 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1187 display_port_and_reg_off(port_id, (unsigned)reg_off);
1188 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1189 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1193 port_reg_display(portid_t port_id, uint32_t reg_off)
1197 if (port_id_is_invalid(port_id, ENABLED_WARN))
1199 if (port_reg_off_is_invalid(port_id, reg_off))
1201 reg_v = port_id_pci_reg_read(port_id, reg_off);
1202 display_port_reg_value(port_id, reg_off, reg_v);
1206 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1211 if (port_id_is_invalid(port_id, ENABLED_WARN))
1213 if (port_reg_off_is_invalid(port_id, reg_off))
1215 if (reg_bit_pos_is_invalid(bit_pos))
1218 fprintf(stderr, "Invalid bit value %d (must be 0 or 1)\n",
1222 reg_v = port_id_pci_reg_read(port_id, reg_off);
1224 reg_v &= ~(1 << bit_pos);
1226 reg_v |= (1 << bit_pos);
1227 port_id_pci_reg_write(port_id, reg_off, reg_v);
1228 display_port_reg_value(port_id, reg_off, reg_v);
1232 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1233 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1240 if (port_id_is_invalid(port_id, ENABLED_WARN))
1242 if (port_reg_off_is_invalid(port_id, reg_off))
1244 if (reg_bit_pos_is_invalid(bit1_pos))
1246 if (reg_bit_pos_is_invalid(bit2_pos))
1248 if (bit1_pos > bit2_pos)
1249 l_bit = bit2_pos, h_bit = bit1_pos;
1251 l_bit = bit1_pos, h_bit = bit2_pos;
1253 if ((h_bit - l_bit) < 31)
1254 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1258 if (value > max_v) {
1259 fprintf(stderr, "Invalid value %u (0x%x) must be < %u (0x%x)\n",
1260 (unsigned)value, (unsigned)value,
1261 (unsigned)max_v, (unsigned)max_v);
1264 reg_v = port_id_pci_reg_read(port_id, reg_off);
1265 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1266 reg_v |= (value << l_bit); /* Set changed bits */
1267 port_id_pci_reg_write(port_id, reg_off, reg_v);
1268 display_port_reg_value(port_id, reg_off, reg_v);
1272 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1274 if (port_id_is_invalid(port_id, ENABLED_WARN))
1276 if (port_reg_off_is_invalid(port_id, reg_off))
1278 port_id_pci_reg_write(port_id, reg_off, reg_v);
1279 display_port_reg_value(port_id, reg_off, reg_v);
1283 eth_dev_get_overhead_len(uint32_t max_rx_pktlen, uint16_t max_mtu)
1285 uint32_t overhead_len;
1287 if (max_mtu != UINT16_MAX && max_rx_pktlen > max_mtu)
1288 overhead_len = max_rx_pktlen - max_mtu;
1290 overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1292 return overhead_len;
1296 eth_dev_validate_mtu(uint16_t port_id, uint16_t mtu)
1298 struct rte_eth_dev_info dev_info;
1299 uint32_t overhead_len;
1300 uint32_t frame_size;
1303 ret = rte_eth_dev_info_get(port_id, &dev_info);
1307 if (mtu < dev_info.min_mtu) {
1309 "MTU (%u) < device min MTU (%u) for port_id %u\n",
1310 mtu, dev_info.min_mtu, port_id);
1313 if (mtu > dev_info.max_mtu) {
1315 "MTU (%u) > device max MTU (%u) for port_id %u\n",
1316 mtu, dev_info.max_mtu, port_id);
1320 overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
1322 frame_size = mtu + overhead_len;
1323 if (frame_size > dev_info.max_rx_pktlen) {
1325 "Frame size (%u) > device max frame size (%u) for port_id %u\n",
1326 frame_size, dev_info.max_rx_pktlen, port_id);
1334 port_mtu_set(portid_t port_id, uint16_t mtu)
1336 struct rte_port *port = &ports[port_id];
1339 if (port_id_is_invalid(port_id, ENABLED_WARN))
1342 diag = eth_dev_validate_mtu(port_id, mtu);
1346 if (port->need_reconfig == 0) {
1347 diag = rte_eth_dev_set_mtu(port_id, mtu);
1349 fprintf(stderr, "Set MTU failed. diag=%d\n", diag);
1354 port->dev_conf.rxmode.mtu = mtu;
1357 /* Generic flow management functions. */
1359 static struct port_flow_tunnel *
1360 port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
1362 struct port_flow_tunnel *flow_tunnel;
1364 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1365 if (flow_tunnel->id == port_tunnel_id)
1375 port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
1378 switch (tunnel->type) {
1382 case RTE_FLOW_ITEM_TYPE_VXLAN:
1385 case RTE_FLOW_ITEM_TYPE_GRE:
1388 case RTE_FLOW_ITEM_TYPE_NVGRE:
1391 case RTE_FLOW_ITEM_TYPE_GENEVE:
1399 struct port_flow_tunnel *
1400 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
1402 struct rte_port *port = &ports[port_id];
1403 struct port_flow_tunnel *flow_tunnel;
1405 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1406 if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
1415 void port_flow_tunnel_list(portid_t port_id)
1417 struct rte_port *port = &ports[port_id];
1418 struct port_flow_tunnel *flt;
1420 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1421 printf("port %u tunnel #%u type=%s",
1422 port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
1423 if (flt->tunnel.tun_id)
1424 printf(" id=%" PRIu64, flt->tunnel.tun_id);
1429 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
1431 struct rte_port *port = &ports[port_id];
1432 struct port_flow_tunnel *flt;
1434 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1435 if (flt->id == tunnel_id)
1439 LIST_REMOVE(flt, chain);
1441 printf("port %u: flow tunnel #%u destroyed\n",
1442 port_id, tunnel_id);
1446 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
1448 struct rte_port *port = &ports[port_id];
1449 enum rte_flow_item_type type;
1450 struct port_flow_tunnel *flt;
1452 if (!strcmp(ops->type, "vxlan"))
1453 type = RTE_FLOW_ITEM_TYPE_VXLAN;
1454 else if (!strcmp(ops->type, "gre"))
1455 type = RTE_FLOW_ITEM_TYPE_GRE;
1456 else if (!strcmp(ops->type, "nvgre"))
1457 type = RTE_FLOW_ITEM_TYPE_NVGRE;
1458 else if (!strcmp(ops->type, "geneve"))
1459 type = RTE_FLOW_ITEM_TYPE_GENEVE;
1461 fprintf(stderr, "cannot offload \"%s\" tunnel type\n",
1465 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1466 if (flt->tunnel.type == type)
1470 flt = calloc(1, sizeof(*flt));
1472 fprintf(stderr, "failed to allocate port flt object\n");
1475 flt->tunnel.type = type;
1476 flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
1477 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
1478 LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
1480 printf("port %d: flow tunnel #%u type %s\n",
1481 port_id, flt->id, ops->type);
1484 /** Generate a port_flow entry from attributes/pattern/actions. */
1485 static struct port_flow *
1486 port_flow_new(const struct rte_flow_attr *attr,
1487 const struct rte_flow_item *pattern,
1488 const struct rte_flow_action *actions,
1489 struct rte_flow_error *error)
1491 const struct rte_flow_conv_rule rule = {
1493 .pattern_ro = pattern,
1494 .actions_ro = actions,
1496 struct port_flow *pf;
1499 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1502 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1505 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1509 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1516 /** Print a message out of a flow error. */
1518 port_flow_complain(struct rte_flow_error *error)
1520 static const char *const errstrlist[] = {
1521 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1522 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1523 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1524 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1525 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1526 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1527 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1528 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1529 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1530 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1531 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1532 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1533 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1534 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1535 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1536 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1537 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1541 int err = rte_errno;
1543 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1544 !errstrlist[error->type])
1545 errstr = "unknown type";
1547 errstr = errstrlist[error->type];
1548 fprintf(stderr, "%s(): Caught PMD error type %d (%s): %s%s: %s\n",
1549 __func__, error->type, errstr,
1550 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1551 error->cause), buf) : "",
1552 error->message ? error->message : "(no stated reason)",
1555 switch (error->type) {
1556 case RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER:
1557 fprintf(stderr, "The status suggests the use of \"transfer\" "
1558 "as the possible cause of the failure. Make "
1559 "sure that the flow in question and its "
1560 "indirect components (if any) are managed "
1561 "via \"transfer\" proxy port. Use command "
1562 "\"show port (port_id) flow transfer proxy\" "
1563 "to figure out the proxy port ID\n");
1573 rss_types_display(uint64_t rss_types)
1580 for (i = 0; rss_type_table[i].str; i++) {
1581 if (rss_type_table[i].rss_type == 0)
1583 if ((rss_types & rss_type_table[i].rss_type) ==
1584 rss_type_table[i].rss_type)
1585 printf(" %s", rss_type_table[i].str);
1590 rss_config_display(struct rte_flow_action_rss *rss_conf)
1594 if (rss_conf == NULL) {
1595 fprintf(stderr, "Invalid rule\n");
1601 if (rss_conf->queue_num == 0)
1603 for (i = 0; i < rss_conf->queue_num; i++)
1604 printf(" %d", rss_conf->queue[i]);
1607 printf(" function: ");
1608 switch (rss_conf->func) {
1609 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1610 printf("default\n");
1612 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1613 printf("toeplitz\n");
1615 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1616 printf("simple_xor\n");
1618 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1619 printf("symmetric_toeplitz\n");
1622 printf("Unknown function\n");
1626 printf(" types:\n");
1627 if (rss_conf->types == 0) {
1631 rss_types_display(rss_conf->types);
1634 static struct port_indirect_action *
1635 action_get_by_id(portid_t port_id, uint32_t id)
1637 struct rte_port *port;
1638 struct port_indirect_action **ppia;
1639 struct port_indirect_action *pia = NULL;
1641 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1642 port_id == (portid_t)RTE_PORT_ALL)
1644 port = &ports[port_id];
1645 ppia = &port->actions_list;
1647 if ((*ppia)->id == id) {
1651 ppia = &(*ppia)->next;
1655 "Failed to find indirect action #%u on port %u\n",
1661 action_alloc(portid_t port_id, uint32_t id,
1662 struct port_indirect_action **action)
1664 struct rte_port *port;
1665 struct port_indirect_action **ppia;
1666 struct port_indirect_action *pia = NULL;
1669 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1670 port_id == (portid_t)RTE_PORT_ALL)
1672 port = &ports[port_id];
1673 if (id == UINT32_MAX) {
1674 /* taking first available ID */
1675 if (port->actions_list) {
1676 if (port->actions_list->id == UINT32_MAX - 1) {
1678 "Highest indirect action ID is already assigned, delete it first\n");
1681 id = port->actions_list->id + 1;
1686 pia = calloc(1, sizeof(*pia));
1689 "Allocation of port %u indirect action failed\n",
1693 ppia = &port->actions_list;
1694 while (*ppia && (*ppia)->id > id)
1695 ppia = &(*ppia)->next;
1696 if (*ppia && (*ppia)->id == id) {
1698 "Indirect action #%u is already assigned, delete it first\n",
1711 template_alloc(uint32_t id, struct port_template **template,
1712 struct port_template **list)
1714 struct port_template *lst = *list;
1715 struct port_template **ppt;
1716 struct port_template *pt = NULL;
1719 if (id == UINT32_MAX) {
1720 /* taking first available ID */
1722 if (lst->id == UINT32_MAX - 1) {
1723 printf("Highest template ID is already"
1724 " assigned, delete it first\n");
1732 pt = calloc(1, sizeof(*pt));
1734 printf("Allocation of port template failed\n");
1738 while (*ppt && (*ppt)->id > id)
1739 ppt = &(*ppt)->next;
1740 if (*ppt && (*ppt)->id == id) {
1741 printf("Template #%u is already assigned,"
1742 " delete it first\n", id);
1754 table_alloc(uint32_t id, struct port_table **table,
1755 struct port_table **list)
1757 struct port_table *lst = *list;
1758 struct port_table **ppt;
1759 struct port_table *pt = NULL;
1762 if (id == UINT32_MAX) {
1763 /* taking first available ID */
1765 if (lst->id == UINT32_MAX - 1) {
1766 printf("Highest table ID is already"
1767 " assigned, delete it first\n");
1775 pt = calloc(1, sizeof(*pt));
1777 printf("Allocation of table failed\n");
1781 while (*ppt && (*ppt)->id > id)
1782 ppt = &(*ppt)->next;
1783 if (*ppt && (*ppt)->id == id) {
1784 printf("Table #%u is already assigned,"
1785 " delete it first\n", id);
1796 /** Get info about flow management resources. */
1798 port_flow_get_info(portid_t port_id)
1800 struct rte_flow_port_info port_info;
1801 struct rte_flow_queue_info queue_info;
1802 struct rte_flow_error error;
1804 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1805 port_id == (portid_t)RTE_PORT_ALL)
1807 /* Poisoning to make sure PMDs update it in case of error. */
1808 memset(&error, 0x99, sizeof(error));
1809 memset(&port_info, 0, sizeof(port_info));
1810 memset(&queue_info, 0, sizeof(queue_info));
1811 if (rte_flow_info_get(port_id, &port_info, &queue_info, &error))
1812 return port_flow_complain(&error);
1813 printf("Flow engine resources on port %u:\n"
1814 "Number of queues: %d\n"
1815 "Size of queues: %d\n"
1816 "Number of counters: %d\n"
1817 "Number of aging objects: %d\n"
1818 "Number of meter actions: %d\n",
1819 port_id, port_info.max_nb_queues,
1820 queue_info.max_size,
1821 port_info.max_nb_counters,
1822 port_info.max_nb_aging_objects,
1823 port_info.max_nb_meters);
1827 /** Configure flow management resources. */
1829 port_flow_configure(portid_t port_id,
1830 const struct rte_flow_port_attr *port_attr,
1832 const struct rte_flow_queue_attr *queue_attr)
1834 struct rte_port *port;
1835 struct rte_flow_error error;
1836 const struct rte_flow_queue_attr *attr_list[nb_queue];
1839 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1840 port_id == (portid_t)RTE_PORT_ALL)
1842 port = &ports[port_id];
1843 port->queue_nb = nb_queue;
1844 port->queue_sz = queue_attr->size;
1845 for (std_queue = 0; std_queue < nb_queue; std_queue++)
1846 attr_list[std_queue] = queue_attr;
1847 /* Poisoning to make sure PMDs update it in case of error. */
1848 memset(&error, 0x66, sizeof(error));
1849 if (rte_flow_configure(port_id, port_attr, nb_queue, attr_list, &error))
1850 return port_flow_complain(&error);
1851 printf("Configure flows on port %u: "
1852 "number of queues %d with %d elements\n",
1853 port_id, nb_queue, queue_attr->size);
1857 /** Create indirect action */
1859 port_action_handle_create(portid_t port_id, uint32_t id,
1860 const struct rte_flow_indir_action_conf *conf,
1861 const struct rte_flow_action *action)
1863 struct port_indirect_action *pia;
1865 struct rte_flow_error error;
1867 ret = action_alloc(port_id, id, &pia);
1870 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
1871 struct rte_flow_action_age *age =
1872 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
1874 pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
1875 age->context = &pia->age_type;
1876 } else if (action->type == RTE_FLOW_ACTION_TYPE_CONNTRACK) {
1877 struct rte_flow_action_conntrack *ct =
1878 (struct rte_flow_action_conntrack *)(uintptr_t)(action->conf);
1880 memcpy(ct, &conntrack_context, sizeof(*ct));
1882 /* Poisoning to make sure PMDs update it in case of error. */
1883 memset(&error, 0x22, sizeof(error));
1884 pia->handle = rte_flow_action_handle_create(port_id, conf, action,
1887 uint32_t destroy_id = pia->id;
1888 port_action_handle_destroy(port_id, 1, &destroy_id);
1889 return port_flow_complain(&error);
1891 pia->type = action->type;
1892 printf("Indirect action #%u created\n", pia->id);
1896 /** Destroy indirect action */
1898 port_action_handle_destroy(portid_t port_id,
1900 const uint32_t *actions)
1902 struct rte_port *port;
1903 struct port_indirect_action **tmp;
1907 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1908 port_id == (portid_t)RTE_PORT_ALL)
1910 port = &ports[port_id];
1911 tmp = &port->actions_list;
1915 for (i = 0; i != n; ++i) {
1916 struct rte_flow_error error;
1917 struct port_indirect_action *pia = *tmp;
1919 if (actions[i] != pia->id)
1922 * Poisoning to make sure PMDs update it in case
1925 memset(&error, 0x33, sizeof(error));
1927 if (pia->handle && rte_flow_action_handle_destroy(
1928 port_id, pia->handle, &error)) {
1929 ret = port_flow_complain(&error);
1933 printf("Indirect action #%u destroyed\n", pia->id);
1938 tmp = &(*tmp)->next;
1945 port_action_handle_flush(portid_t port_id)
1947 struct rte_port *port;
1948 struct port_indirect_action **tmp;
1951 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1952 port_id == (portid_t)RTE_PORT_ALL)
1954 port = &ports[port_id];
1955 tmp = &port->actions_list;
1956 while (*tmp != NULL) {
1957 struct rte_flow_error error;
1958 struct port_indirect_action *pia = *tmp;
1960 /* Poisoning to make sure PMDs update it in case of error. */
1961 memset(&error, 0x44, sizeof(error));
1962 if (pia->handle != NULL &&
1963 rte_flow_action_handle_destroy
1964 (port_id, pia->handle, &error) != 0) {
1965 printf("Indirect action #%u not destroyed\n", pia->id);
1966 ret = port_flow_complain(&error);
1976 /** Get indirect action by port + id */
1977 struct rte_flow_action_handle *
1978 port_action_handle_get_by_id(portid_t port_id, uint32_t id)
1981 struct port_indirect_action *pia = action_get_by_id(port_id, id);
1983 return (pia) ? pia->handle : NULL;
1986 /** Update indirect action */
1988 port_action_handle_update(portid_t port_id, uint32_t id,
1989 const struct rte_flow_action *action)
1991 struct rte_flow_error error;
1992 struct rte_flow_action_handle *action_handle;
1993 struct port_indirect_action *pia;
1996 action_handle = port_action_handle_get_by_id(port_id, id);
1999 pia = action_get_by_id(port_id, id);
2002 switch (pia->type) {
2003 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
2004 update = action->conf;
2010 if (rte_flow_action_handle_update(port_id, action_handle, update,
2012 return port_flow_complain(&error);
2014 printf("Indirect action #%u updated\n", id);
2019 port_action_handle_query(portid_t port_id, uint32_t id)
2021 struct rte_flow_error error;
2022 struct port_indirect_action *pia;
2024 struct rte_flow_query_count count;
2025 struct rte_flow_query_age age;
2026 struct rte_flow_action_conntrack ct;
2029 pia = action_get_by_id(port_id, id);
2032 switch (pia->type) {
2033 case RTE_FLOW_ACTION_TYPE_AGE:
2034 case RTE_FLOW_ACTION_TYPE_COUNT:
2038 "Indirect action %u (type: %d) on port %u doesn't support query\n",
2039 id, pia->type, port_id);
2042 /* Poisoning to make sure PMDs update it in case of error. */
2043 memset(&error, 0x55, sizeof(error));
2044 memset(&query, 0, sizeof(query));
2045 if (rte_flow_action_handle_query(port_id, pia->handle, &query, &error))
2046 return port_flow_complain(&error);
2047 switch (pia->type) {
2048 case RTE_FLOW_ACTION_TYPE_AGE:
2049 printf("Indirect AGE action:\n"
2051 " sec_since_last_hit_valid: %u\n"
2052 " sec_since_last_hit: %" PRIu32 "\n",
2054 query.age.sec_since_last_hit_valid,
2055 query.age.sec_since_last_hit);
2057 case RTE_FLOW_ACTION_TYPE_COUNT:
2058 printf("Indirect COUNT action:\n"
2061 " hits: %" PRIu64 "\n"
2062 " bytes: %" PRIu64 "\n",
2063 query.count.hits_set,
2064 query.count.bytes_set,
2068 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
2069 printf("Conntrack Context:\n"
2070 " Peer: %u, Flow dir: %s, Enable: %u\n"
2071 " Live: %u, SACK: %u, CACK: %u\n"
2072 " Packet dir: %s, Liberal: %u, State: %u\n"
2073 " Factor: %u, Retrans: %u, TCP flags: %u\n"
2074 " Last Seq: %u, Last ACK: %u\n"
2075 " Last Win: %u, Last End: %u\n",
2077 query.ct.is_original_dir ? "Original" : "Reply",
2078 query.ct.enable, query.ct.live_connection,
2079 query.ct.selective_ack, query.ct.challenge_ack_passed,
2080 query.ct.last_direction ? "Original" : "Reply",
2081 query.ct.liberal_mode, query.ct.state,
2082 query.ct.max_ack_window, query.ct.retransmission_limit,
2083 query.ct.last_index, query.ct.last_seq,
2084 query.ct.last_ack, query.ct.last_window,
2086 printf(" Original Dir:\n"
2087 " scale: %u, fin: %u, ack seen: %u\n"
2088 " unacked data: %u\n Sent end: %u,"
2089 " Reply end: %u, Max win: %u, Max ACK: %u\n",
2090 query.ct.original_dir.scale,
2091 query.ct.original_dir.close_initiated,
2092 query.ct.original_dir.last_ack_seen,
2093 query.ct.original_dir.data_unacked,
2094 query.ct.original_dir.sent_end,
2095 query.ct.original_dir.reply_end,
2096 query.ct.original_dir.max_win,
2097 query.ct.original_dir.max_ack);
2098 printf(" Reply Dir:\n"
2099 " scale: %u, fin: %u, ack seen: %u\n"
2100 " unacked data: %u\n Sent end: %u,"
2101 " Reply end: %u, Max win: %u, Max ACK: %u\n",
2102 query.ct.reply_dir.scale,
2103 query.ct.reply_dir.close_initiated,
2104 query.ct.reply_dir.last_ack_seen,
2105 query.ct.reply_dir.data_unacked,
2106 query.ct.reply_dir.sent_end,
2107 query.ct.reply_dir.reply_end,
2108 query.ct.reply_dir.max_win,
2109 query.ct.reply_dir.max_ack);
2113 "Indirect action %u (type: %d) on port %u doesn't support query\n",
2114 id, pia->type, port_id);
2120 static struct port_flow_tunnel *
2121 port_flow_tunnel_offload_cmd_prep(portid_t port_id,
2122 const struct rte_flow_item *pattern,
2123 const struct rte_flow_action *actions,
2124 const struct tunnel_ops *tunnel_ops)
2127 struct rte_port *port;
2128 struct port_flow_tunnel *pft;
2129 struct rte_flow_error error;
2131 port = &ports[port_id];
2132 pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
2134 fprintf(stderr, "failed to locate port flow tunnel #%u\n",
2138 if (tunnel_ops->actions) {
2139 uint32_t num_actions;
2140 const struct rte_flow_action *aptr;
2142 ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
2144 &pft->num_pmd_actions,
2147 port_flow_complain(&error);
2150 for (aptr = actions, num_actions = 1;
2151 aptr->type != RTE_FLOW_ACTION_TYPE_END;
2152 aptr++, num_actions++);
2153 pft->actions = malloc(
2154 (num_actions + pft->num_pmd_actions) *
2155 sizeof(actions[0]));
2156 if (!pft->actions) {
2157 rte_flow_tunnel_action_decap_release(
2158 port_id, pft->actions,
2159 pft->num_pmd_actions, &error);
2162 rte_memcpy(pft->actions, pft->pmd_actions,
2163 pft->num_pmd_actions * sizeof(actions[0]));
2164 rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
2165 num_actions * sizeof(actions[0]));
2167 if (tunnel_ops->items) {
2169 const struct rte_flow_item *iptr;
2171 ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
2173 &pft->num_pmd_items,
2176 port_flow_complain(&error);
2179 for (iptr = pattern, num_items = 1;
2180 iptr->type != RTE_FLOW_ITEM_TYPE_END;
2181 iptr++, num_items++);
2182 pft->items = malloc((num_items + pft->num_pmd_items) *
2183 sizeof(pattern[0]));
2185 rte_flow_tunnel_item_release(
2186 port_id, pft->pmd_items,
2187 pft->num_pmd_items, &error);
2190 rte_memcpy(pft->items, pft->pmd_items,
2191 pft->num_pmd_items * sizeof(pattern[0]));
2192 rte_memcpy(pft->items + pft->num_pmd_items, pattern,
2193 num_items * sizeof(pattern[0]));
2200 port_flow_tunnel_offload_cmd_release(portid_t port_id,
2201 const struct tunnel_ops *tunnel_ops,
2202 struct port_flow_tunnel *pft)
2204 struct rte_flow_error error;
2206 if (tunnel_ops->actions) {
2208 rte_flow_tunnel_action_decap_release(
2209 port_id, pft->pmd_actions,
2210 pft->num_pmd_actions, &error);
2211 pft->actions = NULL;
2212 pft->pmd_actions = NULL;
2214 if (tunnel_ops->items) {
2216 rte_flow_tunnel_item_release(port_id, pft->pmd_items,
2220 pft->pmd_items = NULL;
2224 /** Add port meter policy */
2226 port_meter_policy_add(portid_t port_id, uint32_t policy_id,
2227 const struct rte_flow_action *actions)
2229 struct rte_mtr_error error;
2230 const struct rte_flow_action *act = actions;
2231 const struct rte_flow_action *start;
2232 struct rte_mtr_meter_policy_params policy;
2233 uint32_t i = 0, act_n;
2236 for (i = 0; i < RTE_COLORS; i++) {
2237 for (act_n = 0, start = act;
2238 act->type != RTE_FLOW_ACTION_TYPE_END; act++)
2240 if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
2241 policy.actions[i] = start;
2243 policy.actions[i] = NULL;
2246 ret = rte_mtr_meter_policy_add(port_id,
2250 print_mtr_err_msg(&error);
2254 /** Validate flow rule. */
2256 port_flow_validate(portid_t port_id,
2257 const struct rte_flow_attr *attr,
2258 const struct rte_flow_item *pattern,
2259 const struct rte_flow_action *actions,
2260 const struct tunnel_ops *tunnel_ops)
2262 struct rte_flow_error error;
2263 struct port_flow_tunnel *pft = NULL;
2266 /* Poisoning to make sure PMDs update it in case of error. */
2267 memset(&error, 0x11, sizeof(error));
2268 if (tunnel_ops->enabled) {
2269 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2270 actions, tunnel_ops);
2274 pattern = pft->items;
2276 actions = pft->actions;
2278 ret = rte_flow_validate(port_id, attr, pattern, actions, &error);
2279 if (tunnel_ops->enabled)
2280 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2282 return port_flow_complain(&error);
2283 printf("Flow rule validated\n");
2287 /** Return age action structure if exists, otherwise NULL. */
2288 static struct rte_flow_action_age *
2289 age_action_get(const struct rte_flow_action *actions)
2291 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2292 switch (actions->type) {
2293 case RTE_FLOW_ACTION_TYPE_AGE:
2294 return (struct rte_flow_action_age *)
2295 (uintptr_t)actions->conf;
2303 /** Create pattern template */
2305 port_flow_pattern_template_create(portid_t port_id, uint32_t id,
2306 const struct rte_flow_pattern_template_attr *attr,
2307 const struct rte_flow_item *pattern)
2309 struct rte_port *port;
2310 struct port_template *pit;
2312 struct rte_flow_error error;
2314 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2315 port_id == (portid_t)RTE_PORT_ALL)
2317 port = &ports[port_id];
2318 ret = template_alloc(id, &pit, &port->pattern_templ_list);
2321 /* Poisoning to make sure PMDs update it in case of error. */
2322 memset(&error, 0x22, sizeof(error));
2323 pit->template.pattern_template = rte_flow_pattern_template_create(port_id,
2324 attr, pattern, &error);
2325 if (!pit->template.pattern_template) {
2326 uint32_t destroy_id = pit->id;
2327 port_flow_pattern_template_destroy(port_id, 1, &destroy_id);
2328 return port_flow_complain(&error);
2330 printf("Pattern template #%u created\n", pit->id);
2334 /** Destroy pattern template */
2336 port_flow_pattern_template_destroy(portid_t port_id, uint32_t n,
2337 const uint32_t *template)
2339 struct rte_port *port;
2340 struct port_template **tmp;
2344 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2345 port_id == (portid_t)RTE_PORT_ALL)
2347 port = &ports[port_id];
2348 tmp = &port->pattern_templ_list;
2352 for (i = 0; i != n; ++i) {
2353 struct rte_flow_error error;
2354 struct port_template *pit = *tmp;
2356 if (template[i] != pit->id)
2359 * Poisoning to make sure PMDs update it in case
2362 memset(&error, 0x33, sizeof(error));
2364 if (pit->template.pattern_template &&
2365 rte_flow_pattern_template_destroy(port_id,
2366 pit->template.pattern_template,
2368 ret = port_flow_complain(&error);
2372 printf("Pattern template #%u destroyed\n", pit->id);
2377 tmp = &(*tmp)->next;
2383 /** Create actions template */
2385 port_flow_actions_template_create(portid_t port_id, uint32_t id,
2386 const struct rte_flow_actions_template_attr *attr,
2387 const struct rte_flow_action *actions,
2388 const struct rte_flow_action *masks)
2390 struct rte_port *port;
2391 struct port_template *pat;
2393 struct rte_flow_error error;
2395 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2396 port_id == (portid_t)RTE_PORT_ALL)
2398 port = &ports[port_id];
2399 ret = template_alloc(id, &pat, &port->actions_templ_list);
2402 /* Poisoning to make sure PMDs update it in case of error. */
2403 memset(&error, 0x22, sizeof(error));
2404 pat->template.actions_template = rte_flow_actions_template_create(port_id,
2405 attr, actions, masks, &error);
2406 if (!pat->template.actions_template) {
2407 uint32_t destroy_id = pat->id;
2408 port_flow_actions_template_destroy(port_id, 1, &destroy_id);
2409 return port_flow_complain(&error);
2411 printf("Actions template #%u created\n", pat->id);
2415 /** Destroy actions template */
2417 port_flow_actions_template_destroy(portid_t port_id, uint32_t n,
2418 const uint32_t *template)
2420 struct rte_port *port;
2421 struct port_template **tmp;
2425 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2426 port_id == (portid_t)RTE_PORT_ALL)
2428 port = &ports[port_id];
2429 tmp = &port->actions_templ_list;
2433 for (i = 0; i != n; ++i) {
2434 struct rte_flow_error error;
2435 struct port_template *pat = *tmp;
2437 if (template[i] != pat->id)
2440 * Poisoning to make sure PMDs update it in case
2443 memset(&error, 0x33, sizeof(error));
2445 if (pat->template.actions_template &&
2446 rte_flow_actions_template_destroy(port_id,
2447 pat->template.actions_template, &error)) {
2448 ret = port_flow_complain(&error);
2452 printf("Actions template #%u destroyed\n", pat->id);
2457 tmp = &(*tmp)->next;
2465 port_flow_template_table_create(portid_t port_id, uint32_t id,
2466 const struct rte_flow_template_table_attr *table_attr,
2467 uint32_t nb_pattern_templates, uint32_t *pattern_templates,
2468 uint32_t nb_actions_templates, uint32_t *actions_templates)
2470 struct rte_port *port;
2471 struct port_table *pt;
2472 struct port_template *temp = NULL;
2475 struct rte_flow_error error;
2476 struct rte_flow_pattern_template
2477 *flow_pattern_templates[nb_pattern_templates];
2478 struct rte_flow_actions_template
2479 *flow_actions_templates[nb_actions_templates];
2481 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2482 port_id == (portid_t)RTE_PORT_ALL)
2484 port = &ports[port_id];
2485 for (i = 0; i < nb_pattern_templates; ++i) {
2487 temp = port->pattern_templ_list;
2489 if (pattern_templates[i] == temp->id) {
2490 flow_pattern_templates[i] =
2491 temp->template.pattern_template;
2498 printf("Pattern template #%u is invalid\n",
2499 pattern_templates[i]);
2503 for (i = 0; i < nb_actions_templates; ++i) {
2505 temp = port->actions_templ_list;
2507 if (actions_templates[i] == temp->id) {
2508 flow_actions_templates[i] =
2509 temp->template.actions_template;
2516 printf("Actions template #%u is invalid\n",
2517 actions_templates[i]);
2521 ret = table_alloc(id, &pt, &port->table_list);
2524 /* Poisoning to make sure PMDs update it in case of error. */
2525 memset(&error, 0x22, sizeof(error));
2526 pt->table = rte_flow_template_table_create(port_id, table_attr,
2527 flow_pattern_templates, nb_pattern_templates,
2528 flow_actions_templates, nb_actions_templates,
2532 uint32_t destroy_id = pt->id;
2533 port_flow_template_table_destroy(port_id, 1, &destroy_id);
2534 return port_flow_complain(&error);
2536 pt->nb_pattern_templates = nb_pattern_templates;
2537 pt->nb_actions_templates = nb_actions_templates;
2538 printf("Template table #%u created\n", pt->id);
2542 /** Destroy table */
2544 port_flow_template_table_destroy(portid_t port_id,
2545 uint32_t n, const uint32_t *table)
2547 struct rte_port *port;
2548 struct port_table **tmp;
2552 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2553 port_id == (portid_t)RTE_PORT_ALL)
2555 port = &ports[port_id];
2556 tmp = &port->table_list;
2560 for (i = 0; i != n; ++i) {
2561 struct rte_flow_error error;
2562 struct port_table *pt = *tmp;
2564 if (table[i] != pt->id)
2567 * Poisoning to make sure PMDs update it in case
2570 memset(&error, 0x33, sizeof(error));
2573 rte_flow_template_table_destroy(port_id,
2576 ret = port_flow_complain(&error);
2580 printf("Template table #%u destroyed\n", pt->id);
2585 tmp = &(*tmp)->next;
2591 /** Enqueue create flow rule operation. */
2593 port_queue_flow_create(portid_t port_id, queueid_t queue_id,
2594 bool postpone, uint32_t table_id,
2595 uint32_t pattern_idx, uint32_t actions_idx,
2596 const struct rte_flow_item *pattern,
2597 const struct rte_flow_action *actions)
2599 struct rte_flow_op_attr op_attr = { .postpone = postpone };
2600 struct rte_flow *flow;
2601 struct rte_port *port;
2602 struct port_flow *pf;
2603 struct port_table *pt;
2606 struct rte_flow_error error = { RTE_FLOW_ERROR_TYPE_NONE, NULL, NULL };
2607 struct rte_flow_action_age *age = age_action_get(actions);
2609 port = &ports[port_id];
2610 if (port->flow_list) {
2611 if (port->flow_list->id == UINT32_MAX) {
2612 printf("Highest rule ID is already assigned,"
2613 " delete it first");
2616 id = port->flow_list->id + 1;
2619 if (queue_id >= port->queue_nb) {
2620 printf("Queue #%u is invalid\n", queue_id);
2625 pt = port->table_list;
2627 if (table_id == pt->id) {
2634 printf("Table #%u is invalid\n", table_id);
2638 if (pattern_idx >= pt->nb_pattern_templates) {
2639 printf("Pattern template index #%u is invalid,"
2640 " %u templates present in the table\n",
2641 pattern_idx, pt->nb_pattern_templates);
2644 if (actions_idx >= pt->nb_actions_templates) {
2645 printf("Actions template index #%u is invalid,"
2646 " %u templates present in the table\n",
2647 actions_idx, pt->nb_actions_templates);
2651 pf = port_flow_new(NULL, pattern, actions, &error);
2653 return port_flow_complain(&error);
2655 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
2656 age->context = &pf->age_type;
2658 /* Poisoning to make sure PMDs update it in case of error. */
2659 memset(&error, 0x11, sizeof(error));
2660 flow = rte_flow_async_create(port_id, queue_id, &op_attr, pt->table,
2661 pattern, pattern_idx, actions, actions_idx, NULL, &error);
2663 uint32_t flow_id = pf->id;
2664 port_queue_flow_destroy(port_id, queue_id, true, 1, &flow_id);
2665 return port_flow_complain(&error);
2668 pf->next = port->flow_list;
2671 port->flow_list = pf;
2672 printf("Flow rule #%u creation enqueued\n", pf->id);
2676 /** Enqueue number of destroy flow rules operations. */
2678 port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
2679 bool postpone, uint32_t n, const uint32_t *rule)
2681 struct rte_flow_op_attr op_attr = { .postpone = postpone };
2682 struct rte_port *port;
2683 struct port_flow **tmp;
2687 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2688 port_id == (portid_t)RTE_PORT_ALL)
2690 port = &ports[port_id];
2692 if (queue_id >= port->queue_nb) {
2693 printf("Queue #%u is invalid\n", queue_id);
2697 tmp = &port->flow_list;
2701 for (i = 0; i != n; ++i) {
2702 struct rte_flow_error error;
2703 struct port_flow *pf = *tmp;
2705 if (rule[i] != pf->id)
2708 * Poisoning to make sure PMD
2709 * update it in case of error.
2711 memset(&error, 0x33, sizeof(error));
2712 if (rte_flow_async_destroy(port_id, queue_id, &op_attr,
2713 pf->flow, NULL, &error)) {
2714 ret = port_flow_complain(&error);
2717 printf("Flow rule #%u destruction enqueued\n", pf->id);
2723 tmp = &(*tmp)->next;
2729 /** Enqueue indirect action create operation. */
2731 port_queue_action_handle_create(portid_t port_id, uint32_t queue_id,
2732 bool postpone, uint32_t id,
2733 const struct rte_flow_indir_action_conf *conf,
2734 const struct rte_flow_action *action)
2736 const struct rte_flow_op_attr attr = { .postpone = postpone};
2737 struct rte_port *port;
2738 struct port_indirect_action *pia;
2740 struct rte_flow_error error;
2742 ret = action_alloc(port_id, id, &pia);
2746 port = &ports[port_id];
2747 if (queue_id >= port->queue_nb) {
2748 printf("Queue #%u is invalid\n", queue_id);
2752 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
2753 struct rte_flow_action_age *age =
2754 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
2756 pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
2757 age->context = &pia->age_type;
2759 /* Poisoning to make sure PMDs update it in case of error. */
2760 memset(&error, 0x88, sizeof(error));
2761 pia->handle = rte_flow_async_action_handle_create(port_id, queue_id,
2762 &attr, conf, action, NULL, &error);
2764 uint32_t destroy_id = pia->id;
2765 port_queue_action_handle_destroy(port_id, queue_id,
2766 postpone, 1, &destroy_id);
2767 return port_flow_complain(&error);
2769 pia->type = action->type;
2770 printf("Indirect action #%u creation queued\n", pia->id);
2774 /** Enqueue indirect action destroy operation. */
2776 port_queue_action_handle_destroy(portid_t port_id,
2777 uint32_t queue_id, bool postpone,
2778 uint32_t n, const uint32_t *actions)
2780 const struct rte_flow_op_attr attr = { .postpone = postpone};
2781 struct rte_port *port;
2782 struct port_indirect_action **tmp;
2786 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2787 port_id == (portid_t)RTE_PORT_ALL)
2789 port = &ports[port_id];
2791 if (queue_id >= port->queue_nb) {
2792 printf("Queue #%u is invalid\n", queue_id);
2796 tmp = &port->actions_list;
2800 for (i = 0; i != n; ++i) {
2801 struct rte_flow_error error;
2802 struct port_indirect_action *pia = *tmp;
2804 if (actions[i] != pia->id)
2807 * Poisoning to make sure PMDs update it in case
2810 memset(&error, 0x99, sizeof(error));
2813 rte_flow_async_action_handle_destroy(port_id,
2814 queue_id, &attr, pia->handle, NULL, &error)) {
2815 ret = port_flow_complain(&error);
2819 printf("Indirect action #%u destruction queued\n",
2825 tmp = &(*tmp)->next;
2831 /** Enqueue indirect action update operation. */
2833 port_queue_action_handle_update(portid_t port_id,
2834 uint32_t queue_id, bool postpone, uint32_t id,
2835 const struct rte_flow_action *action)
2837 const struct rte_flow_op_attr attr = { .postpone = postpone};
2838 struct rte_port *port;
2839 struct rte_flow_error error;
2840 struct rte_flow_action_handle *action_handle;
2842 action_handle = port_action_handle_get_by_id(port_id, id);
2846 port = &ports[port_id];
2847 if (queue_id >= port->queue_nb) {
2848 printf("Queue #%u is invalid\n", queue_id);
2852 if (rte_flow_async_action_handle_update(port_id, queue_id, &attr,
2853 action_handle, action, NULL, &error)) {
2854 return port_flow_complain(&error);
2856 printf("Indirect action #%u update queued\n", id);
2860 /** Push all the queue operations in the queue to the NIC. */
2862 port_queue_flow_push(portid_t port_id, queueid_t queue_id)
2864 struct rte_port *port;
2865 struct rte_flow_error error;
2868 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2869 port_id == (portid_t)RTE_PORT_ALL)
2871 port = &ports[port_id];
2873 if (queue_id >= port->queue_nb) {
2874 printf("Queue #%u is invalid\n", queue_id);
2878 memset(&error, 0x55, sizeof(error));
2879 ret = rte_flow_push(port_id, queue_id, &error);
2881 printf("Failed to push operations in the queue\n");
2884 printf("Queue #%u operations pushed\n", queue_id);
2888 /** Pull queue operation results from the queue. */
2890 port_queue_flow_pull(portid_t port_id, queueid_t queue_id)
2892 struct rte_port *port;
2893 struct rte_flow_op_result *res;
2894 struct rte_flow_error error;
2899 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2900 port_id == (portid_t)RTE_PORT_ALL)
2902 port = &ports[port_id];
2904 if (queue_id >= port->queue_nb) {
2905 printf("Queue #%u is invalid\n", queue_id);
2909 res = calloc(port->queue_sz, sizeof(struct rte_flow_op_result));
2911 printf("Failed to allocate memory for pulled results\n");
2915 memset(&error, 0x66, sizeof(error));
2916 ret = rte_flow_pull(port_id, queue_id, res,
2917 port->queue_sz, &error);
2919 printf("Failed to pull a operation results\n");
2924 for (i = 0; i < ret; i++) {
2925 if (res[i].status == RTE_FLOW_OP_SUCCESS)
2928 printf("Queue #%u pulled %u operations (%u failed, %u succeeded)\n",
2929 queue_id, ret, ret - success, success);
2934 /** Create flow rule. */
2936 port_flow_create(portid_t port_id,
2937 const struct rte_flow_attr *attr,
2938 const struct rte_flow_item *pattern,
2939 const struct rte_flow_action *actions,
2940 const struct tunnel_ops *tunnel_ops)
2942 struct rte_flow *flow;
2943 struct rte_port *port;
2944 struct port_flow *pf;
2946 struct rte_flow_error error;
2947 struct port_flow_tunnel *pft = NULL;
2948 struct rte_flow_action_age *age = age_action_get(actions);
2950 port = &ports[port_id];
2951 if (port->flow_list) {
2952 if (port->flow_list->id == UINT32_MAX) {
2954 "Highest rule ID is already assigned, delete it first");
2957 id = port->flow_list->id + 1;
2959 if (tunnel_ops->enabled) {
2960 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2961 actions, tunnel_ops);
2965 pattern = pft->items;
2967 actions = pft->actions;
2969 pf = port_flow_new(attr, pattern, actions, &error);
2971 return port_flow_complain(&error);
2973 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
2974 age->context = &pf->age_type;
2976 /* Poisoning to make sure PMDs update it in case of error. */
2977 memset(&error, 0x22, sizeof(error));
2978 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
2980 if (tunnel_ops->enabled)
2981 port_flow_tunnel_offload_cmd_release(port_id,
2984 return port_flow_complain(&error);
2986 pf->next = port->flow_list;
2989 port->flow_list = pf;
2990 if (tunnel_ops->enabled)
2991 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2992 printf("Flow rule #%u created\n", pf->id);
2996 /** Destroy a number of flow rules. */
2998 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
3000 struct rte_port *port;
3001 struct port_flow **tmp;
3005 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3006 port_id == (portid_t)RTE_PORT_ALL)
3008 port = &ports[port_id];
3009 tmp = &port->flow_list;
3013 for (i = 0; i != n; ++i) {
3014 struct rte_flow_error error;
3015 struct port_flow *pf = *tmp;
3017 if (rule[i] != pf->id)
3020 * Poisoning to make sure PMDs update it in case
3023 memset(&error, 0x33, sizeof(error));
3024 if (rte_flow_destroy(port_id, pf->flow, &error)) {
3025 ret = port_flow_complain(&error);
3028 printf("Flow rule #%u destroyed\n", pf->id);
3034 tmp = &(*tmp)->next;
3040 /** Remove all flow rules. */
3042 port_flow_flush(portid_t port_id)
3044 struct rte_flow_error error;
3045 struct rte_port *port;
3048 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3049 port_id == (portid_t)RTE_PORT_ALL)
3052 port = &ports[port_id];
3054 if (port->flow_list == NULL)
3057 /* Poisoning to make sure PMDs update it in case of error. */
3058 memset(&error, 0x44, sizeof(error));
3059 if (rte_flow_flush(port_id, &error)) {
3060 port_flow_complain(&error);
3063 while (port->flow_list) {
3064 struct port_flow *pf = port->flow_list->next;
3066 free(port->flow_list);
3067 port->flow_list = pf;
3072 /** Dump flow rules. */
3074 port_flow_dump(portid_t port_id, bool dump_all, uint32_t rule_id,
3075 const char *file_name)
3078 FILE *file = stdout;
3079 struct rte_flow_error error;
3080 struct rte_port *port;
3081 struct port_flow *pflow;
3082 struct rte_flow *tmpFlow = NULL;
3085 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3086 port_id == (portid_t)RTE_PORT_ALL)
3090 port = &ports[port_id];
3091 pflow = port->flow_list;
3093 if (rule_id != pflow->id) {
3094 pflow = pflow->next;
3096 tmpFlow = pflow->flow;
3102 if (found == false) {
3103 fprintf(stderr, "Failed to dump to flow %d\n", rule_id);
3108 if (file_name && strlen(file_name)) {
3109 file = fopen(file_name, "w");
3111 fprintf(stderr, "Failed to create file %s: %s\n",
3112 file_name, strerror(errno));
3118 ret = rte_flow_dev_dump(port_id, tmpFlow, file, &error);
3120 ret = rte_flow_dev_dump(port_id, NULL, file, &error);
3122 port_flow_complain(&error);
3123 fprintf(stderr, "Failed to dump flow: %s\n", strerror(-ret));
3125 printf("Flow dump finished\n");
3126 if (file_name && strlen(file_name))
3131 /** Query a flow rule. */
3133 port_flow_query(portid_t port_id, uint32_t rule,
3134 const struct rte_flow_action *action)
3136 struct rte_flow_error error;
3137 struct rte_port *port;
3138 struct port_flow *pf;
3141 struct rte_flow_query_count count;
3142 struct rte_flow_action_rss rss_conf;
3143 struct rte_flow_query_age age;
3147 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3148 port_id == (portid_t)RTE_PORT_ALL)
3150 port = &ports[port_id];
3151 for (pf = port->flow_list; pf; pf = pf->next)
3155 fprintf(stderr, "Flow rule #%u not found\n", rule);
3158 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
3159 &name, sizeof(name),
3160 (void *)(uintptr_t)action->type, &error);
3162 return port_flow_complain(&error);
3163 switch (action->type) {
3164 case RTE_FLOW_ACTION_TYPE_COUNT:
3165 case RTE_FLOW_ACTION_TYPE_RSS:
3166 case RTE_FLOW_ACTION_TYPE_AGE:
3169 fprintf(stderr, "Cannot query action type %d (%s)\n",
3170 action->type, name);
3173 /* Poisoning to make sure PMDs update it in case of error. */
3174 memset(&error, 0x55, sizeof(error));
3175 memset(&query, 0, sizeof(query));
3176 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
3177 return port_flow_complain(&error);
3178 switch (action->type) {
3179 case RTE_FLOW_ACTION_TYPE_COUNT:
3183 " hits: %" PRIu64 "\n"
3184 " bytes: %" PRIu64 "\n",
3186 query.count.hits_set,
3187 query.count.bytes_set,
3191 case RTE_FLOW_ACTION_TYPE_RSS:
3192 rss_config_display(&query.rss_conf);
3194 case RTE_FLOW_ACTION_TYPE_AGE:
3197 " sec_since_last_hit_valid: %u\n"
3198 " sec_since_last_hit: %" PRIu32 "\n",
3201 query.age.sec_since_last_hit_valid,
3202 query.age.sec_since_last_hit);
3206 "Cannot display result for action type %d (%s)\n",
3207 action->type, name);
3213 /** List simply and destroy all aged flows. */
3215 port_flow_aged(portid_t port_id, uint8_t destroy)
3218 int nb_context, total = 0, idx;
3219 struct rte_flow_error error;
3220 enum age_action_context_type *type;
3222 struct port_flow *pf;
3223 struct port_indirect_action *pia;
3226 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3227 port_id == (portid_t)RTE_PORT_ALL)
3229 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
3230 printf("Port %u total aged flows: %d\n", port_id, total);
3232 port_flow_complain(&error);
3237 contexts = malloc(sizeof(void *) * total);
3238 if (contexts == NULL) {
3239 fprintf(stderr, "Cannot allocate contexts for aged flow\n");
3242 printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
3243 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
3244 if (nb_context != total) {
3246 "Port:%d get aged flows count(%d) != total(%d)\n",
3247 port_id, nb_context, total);
3252 for (idx = 0; idx < nb_context; idx++) {
3253 if (!contexts[idx]) {
3254 fprintf(stderr, "Error: get Null context in port %u\n",
3258 type = (enum age_action_context_type *)contexts[idx];
3260 case ACTION_AGE_CONTEXT_TYPE_FLOW:
3261 ctx.pf = container_of(type, struct port_flow, age_type);
3262 printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
3266 ctx.pf->rule.attr->group,
3267 ctx.pf->rule.attr->priority,
3268 ctx.pf->rule.attr->ingress ? 'i' : '-',
3269 ctx.pf->rule.attr->egress ? 'e' : '-',
3270 ctx.pf->rule.attr->transfer ? 't' : '-');
3271 if (destroy && !port_flow_destroy(port_id, 1,
3275 case ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION:
3276 ctx.pia = container_of(type,
3277 struct port_indirect_action, age_type);
3278 printf("%-20s\t%" PRIu32 "\n", "Indirect action",
3282 fprintf(stderr, "Error: invalid context type %u\n",
3287 printf("\n%d flows destroyed\n", total);
3291 /** List flow rules. */
3293 port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group)
3295 struct rte_port *port;
3296 struct port_flow *pf;
3297 struct port_flow *list = NULL;
3300 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3301 port_id == (portid_t)RTE_PORT_ALL)
3303 port = &ports[port_id];
3304 if (!port->flow_list)
3306 /* Sort flows by group, priority and ID. */
3307 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
3308 struct port_flow **tmp;
3309 const struct rte_flow_attr *curr = pf->rule.attr;
3312 /* Filter out unwanted groups. */
3313 for (i = 0; i != n; ++i)
3314 if (curr->group == group[i])
3319 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
3320 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
3322 if (curr->group > comp->group ||
3323 (curr->group == comp->group &&
3324 curr->priority > comp->priority) ||
3325 (curr->group == comp->group &&
3326 curr->priority == comp->priority &&
3327 pf->id > (*tmp)->id))
3334 printf("ID\tGroup\tPrio\tAttr\tRule\n");
3335 for (pf = list; pf != NULL; pf = pf->tmp) {
3336 const struct rte_flow_item *item = pf->rule.pattern;
3337 const struct rte_flow_action *action = pf->rule.actions;
3340 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
3342 pf->rule.attr->group,
3343 pf->rule.attr->priority,
3344 pf->rule.attr->ingress ? 'i' : '-',
3345 pf->rule.attr->egress ? 'e' : '-',
3346 pf->rule.attr->transfer ? 't' : '-');
3347 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
3348 if ((uint32_t)item->type > INT_MAX)
3349 name = "PMD_INTERNAL";
3350 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
3351 &name, sizeof(name),
3352 (void *)(uintptr_t)item->type,
3355 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
3356 printf("%s ", name);
3360 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
3361 if ((uint32_t)action->type > INT_MAX)
3362 name = "PMD_INTERNAL";
3363 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
3364 &name, sizeof(name),
3365 (void *)(uintptr_t)action->type,
3368 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
3369 printf(" %s", name);
3376 /** Restrict ingress traffic to the defined flow rules. */
3378 port_flow_isolate(portid_t port_id, int set)
3380 struct rte_flow_error error;
3382 /* Poisoning to make sure PMDs update it in case of error. */
3383 memset(&error, 0x66, sizeof(error));
3384 if (rte_flow_isolate(port_id, set, &error))
3385 return port_flow_complain(&error);
3386 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
3388 set ? "now restricted" : "not restricted anymore");
3393 * RX/TX ring descriptors display functions.
3396 rx_queue_id_is_invalid(queueid_t rxq_id)
3398 if (rxq_id < nb_rxq)
3400 fprintf(stderr, "Invalid RX queue %d (must be < nb_rxq=%d)\n",
3406 tx_queue_id_is_invalid(queueid_t txq_id)
3408 if (txq_id < nb_txq)
3410 fprintf(stderr, "Invalid TX queue %d (must be < nb_txq=%d)\n",
3416 get_rx_ring_size(portid_t port_id, queueid_t rxq_id, uint16_t *ring_size)
3418 struct rte_port *port = &ports[port_id];
3419 struct rte_eth_rxq_info rx_qinfo;
3422 ret = rte_eth_rx_queue_info_get(port_id, rxq_id, &rx_qinfo);
3424 *ring_size = rx_qinfo.nb_desc;
3428 if (ret != -ENOTSUP)
3431 * If the rte_eth_rx_queue_info_get is not support for this PMD,
3432 * ring_size stored in testpmd will be used for validity verification.
3433 * When configure the rxq by rte_eth_rx_queue_setup with nb_rx_desc
3434 * being 0, it will use a default value provided by PMDs to setup this
3435 * rxq. If the default value is 0, it will use the
3436 * RTE_ETH_DEV_FALLBACK_RX_RINGSIZE to setup this rxq.
3438 if (port->nb_rx_desc[rxq_id])
3439 *ring_size = port->nb_rx_desc[rxq_id];
3440 else if (port->dev_info.default_rxportconf.ring_size)
3441 *ring_size = port->dev_info.default_rxportconf.ring_size;
3443 *ring_size = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
3448 get_tx_ring_size(portid_t port_id, queueid_t txq_id, uint16_t *ring_size)
3450 struct rte_port *port = &ports[port_id];
3451 struct rte_eth_txq_info tx_qinfo;
3454 ret = rte_eth_tx_queue_info_get(port_id, txq_id, &tx_qinfo);
3456 *ring_size = tx_qinfo.nb_desc;
3460 if (ret != -ENOTSUP)
3463 * If the rte_eth_tx_queue_info_get is not support for this PMD,
3464 * ring_size stored in testpmd will be used for validity verification.
3465 * When configure the txq by rte_eth_tx_queue_setup with nb_tx_desc
3466 * being 0, it will use a default value provided by PMDs to setup this
3467 * txq. If the default value is 0, it will use the
3468 * RTE_ETH_DEV_FALLBACK_TX_RINGSIZE to setup this txq.
3470 if (port->nb_tx_desc[txq_id])
3471 *ring_size = port->nb_tx_desc[txq_id];
3472 else if (port->dev_info.default_txportconf.ring_size)
3473 *ring_size = port->dev_info.default_txportconf.ring_size;
3475 *ring_size = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
3480 rx_desc_id_is_invalid(portid_t port_id, queueid_t rxq_id, uint16_t rxdesc_id)
3485 ret = get_rx_ring_size(port_id, rxq_id, &ring_size);
3489 if (rxdesc_id < ring_size)
3492 fprintf(stderr, "Invalid RX descriptor %u (must be < ring_size=%u)\n",
3493 rxdesc_id, ring_size);
3498 tx_desc_id_is_invalid(portid_t port_id, queueid_t txq_id, uint16_t txdesc_id)
3503 ret = get_tx_ring_size(port_id, txq_id, &ring_size);
3507 if (txdesc_id < ring_size)
3510 fprintf(stderr, "Invalid TX descriptor %u (must be < ring_size=%u)\n",
3511 txdesc_id, ring_size);
3515 static const struct rte_memzone *
3516 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
3518 char mz_name[RTE_MEMZONE_NAMESIZE];
3519 const struct rte_memzone *mz;
3521 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
3522 port_id, q_id, ring_name);
3523 mz = rte_memzone_lookup(mz_name);
3526 "%s ring memory zoneof (port %d, queue %d) not found (zone name = %s\n",
3527 ring_name, port_id, q_id, mz_name);
3531 union igb_ring_dword {
3534 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
3544 struct igb_ring_desc_32_bytes {
3545 union igb_ring_dword lo_dword;
3546 union igb_ring_dword hi_dword;
3547 union igb_ring_dword resv1;
3548 union igb_ring_dword resv2;
3551 struct igb_ring_desc_16_bytes {
3552 union igb_ring_dword lo_dword;
3553 union igb_ring_dword hi_dword;
3557 ring_rxd_display_dword(union igb_ring_dword dword)
3559 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
3560 (unsigned)dword.words.hi);
3564 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
3565 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
3568 __rte_unused portid_t port_id,
3572 struct igb_ring_desc_16_bytes *ring =
3573 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
3574 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
3576 struct rte_eth_dev_info dev_info;
3578 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3582 if (strstr(dev_info.driver_name, "i40e") != NULL) {
3583 /* 32 bytes RX descriptor, i40e only */
3584 struct igb_ring_desc_32_bytes *ring =
3585 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
3586 ring[desc_id].lo_dword.dword =
3587 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
3588 ring_rxd_display_dword(ring[desc_id].lo_dword);
3589 ring[desc_id].hi_dword.dword =
3590 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
3591 ring_rxd_display_dword(ring[desc_id].hi_dword);
3592 ring[desc_id].resv1.dword =
3593 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
3594 ring_rxd_display_dword(ring[desc_id].resv1);
3595 ring[desc_id].resv2.dword =
3596 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
3597 ring_rxd_display_dword(ring[desc_id].resv2);
3602 /* 16 bytes RX descriptor */
3603 ring[desc_id].lo_dword.dword =
3604 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
3605 ring_rxd_display_dword(ring[desc_id].lo_dword);
3606 ring[desc_id].hi_dword.dword =
3607 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
3608 ring_rxd_display_dword(ring[desc_id].hi_dword);
3612 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
3614 struct igb_ring_desc_16_bytes *ring;
3615 struct igb_ring_desc_16_bytes txd;
3617 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
3618 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
3619 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
3620 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
3621 (unsigned)txd.lo_dword.words.lo,
3622 (unsigned)txd.lo_dword.words.hi,
3623 (unsigned)txd.hi_dword.words.lo,
3624 (unsigned)txd.hi_dword.words.hi);
3628 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
3630 const struct rte_memzone *rx_mz;
3632 if (rx_desc_id_is_invalid(port_id, rxq_id, rxd_id))
3634 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
3637 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
3641 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
3643 const struct rte_memzone *tx_mz;
3645 if (tx_desc_id_is_invalid(port_id, txq_id, txd_id))
3647 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
3650 ring_tx_descriptor_display(tx_mz, txd_id);
3654 fwd_lcores_config_display(void)
3658 printf("List of forwarding lcores:");
3659 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
3660 printf(" %2u", fwd_lcores_cpuids[lc_id]);
3664 rxtx_config_display(void)
3669 printf(" %s packet forwarding%s packets/burst=%d\n",
3670 cur_fwd_eng->fwd_mode_name,
3671 retry_enabled == 0 ? "" : " with retry",
3674 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
3675 printf(" packet len=%u - nb packet segments=%d\n",
3676 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
3678 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
3679 nb_fwd_lcores, nb_fwd_ports);
3681 RTE_ETH_FOREACH_DEV(pid) {
3682 struct rte_eth_rxconf *rx_conf = &ports[pid].rxq[0].conf;
3683 struct rte_eth_txconf *tx_conf = &ports[pid].txq[0].conf;
3684 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
3685 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
3686 struct rte_eth_rxq_info rx_qinfo;
3687 struct rte_eth_txq_info tx_qinfo;
3688 uint16_t rx_free_thresh_tmp;
3689 uint16_t tx_free_thresh_tmp;
3690 uint16_t tx_rs_thresh_tmp;
3691 uint16_t nb_rx_desc_tmp;
3692 uint16_t nb_tx_desc_tmp;
3693 uint64_t offloads_tmp;
3694 uint8_t pthresh_tmp;
3695 uint8_t hthresh_tmp;
3696 uint8_t wthresh_tmp;
3699 /* per port config */
3700 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
3701 (unsigned int)pid, nb_rxq, nb_txq);
3703 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
3704 ports[pid].dev_conf.rxmode.offloads,
3705 ports[pid].dev_conf.txmode.offloads);
3707 /* per rx queue config only for first queue to be less verbose */
3708 for (qid = 0; qid < 1; qid++) {
3709 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
3711 nb_rx_desc_tmp = nb_rx_desc[qid];
3712 rx_free_thresh_tmp =
3713 rx_conf[qid].rx_free_thresh;
3714 pthresh_tmp = rx_conf[qid].rx_thresh.pthresh;
3715 hthresh_tmp = rx_conf[qid].rx_thresh.hthresh;
3716 wthresh_tmp = rx_conf[qid].rx_thresh.wthresh;
3717 offloads_tmp = rx_conf[qid].offloads;
3719 nb_rx_desc_tmp = rx_qinfo.nb_desc;
3720 rx_free_thresh_tmp =
3721 rx_qinfo.conf.rx_free_thresh;
3722 pthresh_tmp = rx_qinfo.conf.rx_thresh.pthresh;
3723 hthresh_tmp = rx_qinfo.conf.rx_thresh.hthresh;
3724 wthresh_tmp = rx_qinfo.conf.rx_thresh.wthresh;
3725 offloads_tmp = rx_qinfo.conf.offloads;
3728 printf(" RX queue: %d\n", qid);
3729 printf(" RX desc=%d - RX free threshold=%d\n",
3730 nb_rx_desc_tmp, rx_free_thresh_tmp);
3731 printf(" RX threshold registers: pthresh=%d hthresh=%d "
3733 pthresh_tmp, hthresh_tmp, wthresh_tmp);
3734 printf(" RX Offloads=0x%"PRIx64, offloads_tmp);
3735 if (rx_conf->share_group > 0)
3736 printf(" share_group=%u share_qid=%u",
3737 rx_conf->share_group,
3738 rx_conf->share_qid);
3742 /* per tx queue config only for first queue to be less verbose */
3743 for (qid = 0; qid < 1; qid++) {
3744 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
3746 nb_tx_desc_tmp = nb_tx_desc[qid];
3747 tx_free_thresh_tmp =
3748 tx_conf[qid].tx_free_thresh;
3749 pthresh_tmp = tx_conf[qid].tx_thresh.pthresh;
3750 hthresh_tmp = tx_conf[qid].tx_thresh.hthresh;
3751 wthresh_tmp = tx_conf[qid].tx_thresh.wthresh;
3752 offloads_tmp = tx_conf[qid].offloads;
3753 tx_rs_thresh_tmp = tx_conf[qid].tx_rs_thresh;
3755 nb_tx_desc_tmp = tx_qinfo.nb_desc;
3756 tx_free_thresh_tmp =
3757 tx_qinfo.conf.tx_free_thresh;
3758 pthresh_tmp = tx_qinfo.conf.tx_thresh.pthresh;
3759 hthresh_tmp = tx_qinfo.conf.tx_thresh.hthresh;
3760 wthresh_tmp = tx_qinfo.conf.tx_thresh.wthresh;
3761 offloads_tmp = tx_qinfo.conf.offloads;
3762 tx_rs_thresh_tmp = tx_qinfo.conf.tx_rs_thresh;
3765 printf(" TX queue: %d\n", qid);
3766 printf(" TX desc=%d - TX free threshold=%d\n",
3767 nb_tx_desc_tmp, tx_free_thresh_tmp);
3768 printf(" TX threshold registers: pthresh=%d hthresh=%d "
3770 pthresh_tmp, hthresh_tmp, wthresh_tmp);
3771 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
3772 offloads_tmp, tx_rs_thresh_tmp);
3778 port_rss_reta_info(portid_t port_id,
3779 struct rte_eth_rss_reta_entry64 *reta_conf,
3780 uint16_t nb_entries)
3782 uint16_t i, idx, shift;
3785 if (port_id_is_invalid(port_id, ENABLED_WARN))
3788 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
3791 "Failed to get RSS RETA info, return code = %d\n",
3796 for (i = 0; i < nb_entries; i++) {
3797 idx = i / RTE_ETH_RETA_GROUP_SIZE;
3798 shift = i % RTE_ETH_RETA_GROUP_SIZE;
3799 if (!(reta_conf[idx].mask & (1ULL << shift)))
3801 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
3802 i, reta_conf[idx].reta[shift]);
3807 * Displays the RSS hash functions of a port, and, optionally, the RSS hash
3811 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
3813 struct rte_eth_rss_conf rss_conf = {0};
3814 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
3818 struct rte_eth_dev_info dev_info;
3819 uint8_t hash_key_size;
3822 if (port_id_is_invalid(port_id, ENABLED_WARN))
3825 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3829 if (dev_info.hash_key_size > 0 &&
3830 dev_info.hash_key_size <= sizeof(rss_key))
3831 hash_key_size = dev_info.hash_key_size;
3834 "dev_info did not provide a valid hash key size\n");
3838 /* Get RSS hash key if asked to display it */
3839 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
3840 rss_conf.rss_key_len = hash_key_size;
3841 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
3845 fprintf(stderr, "port index %d invalid\n", port_id);
3848 fprintf(stderr, "operation not supported by device\n");
3851 fprintf(stderr, "operation failed - diag=%d\n", diag);
3856 rss_hf = rss_conf.rss_hf;
3858 printf("RSS disabled\n");
3861 printf("RSS functions:\n");
3862 rss_types_display(rss_hf);
3866 printf("RSS key:\n");
3867 for (i = 0; i < hash_key_size; i++)
3868 printf("%02X", rss_key[i]);
3873 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
3874 uint8_t hash_key_len)
3876 struct rte_eth_rss_conf rss_conf;
3879 rss_conf.rss_key = NULL;
3880 rss_conf.rss_key_len = 0;
3881 rss_conf.rss_hf = str_to_rsstypes(rss_type);
3882 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
3884 rss_conf.rss_key = hash_key;
3885 rss_conf.rss_key_len = hash_key_len;
3886 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
3893 fprintf(stderr, "port index %d invalid\n", port_id);
3896 fprintf(stderr, "operation not supported by device\n");
3899 fprintf(stderr, "operation failed - diag=%d\n", diag);
3905 * Check whether a shared rxq scheduled on other lcores.
3908 fwd_stream_on_other_lcores(uint16_t domain_id, lcoreid_t src_lc,
3909 portid_t src_port, queueid_t src_rxq,
3910 uint32_t share_group, queueid_t share_rxq)
3913 streamid_t nb_fs_per_lcore;
3916 struct fwd_stream *fs;
3917 struct rte_port *port;
3918 struct rte_eth_dev_info *dev_info;
3919 struct rte_eth_rxconf *rxq_conf;
3921 nb_fc = cur_fwd_config.nb_fwd_lcores;
3922 /* Check remaining cores. */
3923 for (lc_id = src_lc + 1; lc_id < nb_fc; lc_id++) {
3924 sm_id = fwd_lcores[lc_id]->stream_idx;
3925 nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
3926 for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
3928 fs = fwd_streams[sm_id];
3929 port = &ports[fs->rx_port];
3930 dev_info = &port->dev_info;
3931 rxq_conf = &port->rxq[fs->rx_queue].conf;
3932 if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
3933 == 0 || rxq_conf->share_group == 0)
3934 /* Not shared rxq. */
3936 if (domain_id != port->dev_info.switch_info.domain_id)
3938 if (rxq_conf->share_group != share_group)
3940 if (rxq_conf->share_qid != share_rxq)
3942 printf("Shared Rx queue group %u queue %hu can't be scheduled on different cores:\n",
3943 share_group, share_rxq);
3944 printf(" lcore %hhu Port %hu queue %hu\n",
3945 src_lc, src_port, src_rxq);
3946 printf(" lcore %hhu Port %hu queue %hu\n",
3947 lc_id, fs->rx_port, fs->rx_queue);
3948 printf("Please use --nb-cores=%hu to limit number of forwarding cores\n",
3957 * Check shared rxq configuration.
3959 * Shared group must not being scheduled on different core.
3962 pkt_fwd_shared_rxq_check(void)
3965 streamid_t nb_fs_per_lcore;
3968 struct fwd_stream *fs;
3970 struct rte_port *port;
3971 struct rte_eth_dev_info *dev_info;
3972 struct rte_eth_rxconf *rxq_conf;
3976 nb_fc = cur_fwd_config.nb_fwd_lcores;
3978 * Check streams on each core, make sure the same switch domain +
3979 * group + queue doesn't get scheduled on other cores.
3981 for (lc_id = 0; lc_id < nb_fc; lc_id++) {
3982 sm_id = fwd_lcores[lc_id]->stream_idx;
3983 nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
3984 for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
3986 fs = fwd_streams[sm_id];
3987 /* Update lcore info stream being scheduled. */
3988 fs->lcore = fwd_lcores[lc_id];
3989 port = &ports[fs->rx_port];
3990 dev_info = &port->dev_info;
3991 rxq_conf = &port->rxq[fs->rx_queue].conf;
3992 if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
3993 == 0 || rxq_conf->share_group == 0)
3994 /* Not shared rxq. */
3996 /* Check shared rxq not scheduled on remaining cores. */
3997 domain_id = port->dev_info.switch_info.domain_id;
3998 if (fwd_stream_on_other_lcores(domain_id, lc_id,
4001 rxq_conf->share_group,
4002 rxq_conf->share_qid))
4010 * Setup forwarding configuration for each logical core.
4013 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
4015 streamid_t nb_fs_per_lcore;
4023 nb_fs = cfg->nb_fwd_streams;
4024 nb_fc = cfg->nb_fwd_lcores;
4025 if (nb_fs <= nb_fc) {
4026 nb_fs_per_lcore = 1;
4029 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
4030 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
4033 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
4035 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
4036 fwd_lcores[lc_id]->stream_idx = sm_id;
4037 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
4038 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
4042 * Assign extra remaining streams, if any.
4044 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
4045 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
4046 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
4047 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
4048 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
4053 fwd_topology_tx_port_get(portid_t rxp)
4055 static int warning_once = 1;
4057 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
4059 switch (port_topology) {
4061 case PORT_TOPOLOGY_PAIRED:
4062 if ((rxp & 0x1) == 0) {
4063 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
4067 "\nWarning! port-topology=paired and odd forward ports number, the last port will pair with itself.\n\n");
4073 case PORT_TOPOLOGY_CHAINED:
4074 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
4075 case PORT_TOPOLOGY_LOOP:
4081 simple_fwd_config_setup(void)
4085 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
4086 cur_fwd_config.nb_fwd_streams =
4087 (streamid_t) cur_fwd_config.nb_fwd_ports;
4089 /* reinitialize forwarding streams */
4093 * In the simple forwarding test, the number of forwarding cores
4094 * must be lower or equal to the number of forwarding ports.
4096 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
4097 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
4098 cur_fwd_config.nb_fwd_lcores =
4099 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
4100 setup_fwd_config_of_each_lcore(&cur_fwd_config);
4102 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
4103 fwd_streams[i]->rx_port = fwd_ports_ids[i];
4104 fwd_streams[i]->rx_queue = 0;
4105 fwd_streams[i]->tx_port =
4106 fwd_ports_ids[fwd_topology_tx_port_get(i)];
4107 fwd_streams[i]->tx_queue = 0;
4108 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
4109 fwd_streams[i]->retry_enabled = retry_enabled;
4114 * For the RSS forwarding test all streams distributed over lcores. Each stream
4115 * being composed of a RX queue to poll on a RX port for input messages,
4116 * associated with a TX queue of a TX port where to send forwarded packets.
4119 rss_fwd_config_setup(void)
4132 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
4133 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
4134 cur_fwd_config.nb_fwd_streams =
4135 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
4137 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
4138 cur_fwd_config.nb_fwd_lcores =
4139 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
4141 /* reinitialize forwarding streams */
4144 setup_fwd_config_of_each_lcore(&cur_fwd_config);
4146 if (proc_id > 0 && nb_q % num_procs != 0)
4147 printf("Warning! queue numbers should be multiple of processes, or packet loss will happen.\n");
4150 * In multi-process, All queues are allocated to different
4151 * processes based on num_procs and proc_id. For example:
4152 * if supports 4 queues(nb_q), 2 processes(num_procs),
4153 * the 0~1 queue for primary process.
4154 * the 2~3 queue for secondary process.
4156 start = proc_id * nb_q / num_procs;
4157 end = start + nb_q / num_procs;
4160 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
4161 struct fwd_stream *fs;
4163 fs = fwd_streams[sm_id];
4164 txp = fwd_topology_tx_port_get(rxp);
4165 fs->rx_port = fwd_ports_ids[rxp];
4167 fs->tx_port = fwd_ports_ids[txp];
4169 fs->peer_addr = fs->tx_port;
4170 fs->retry_enabled = retry_enabled;
4172 if (rxp < nb_fwd_ports)
4182 get_fwd_port_total_tc_num(void)
4184 struct rte_eth_dcb_info dcb_info;
4185 uint16_t total_tc_num = 0;
4188 for (i = 0; i < nb_fwd_ports; i++) {
4189 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[i], &dcb_info);
4190 total_tc_num += dcb_info.nb_tcs;
4193 return total_tc_num;
4197 * For the DCB forwarding test, each core is assigned on each traffic class.
4199 * Each core is assigned a multi-stream, each stream being composed of
4200 * a RX queue to poll on a RX port for input messages, associated with
4201 * a TX queue of a TX port where to send forwarded packets. All RX and
4202 * TX queues are mapping to the same traffic class.
4203 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
4207 dcb_fwd_config_setup(void)
4209 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
4210 portid_t txp, rxp = 0;
4211 queueid_t txq, rxq = 0;
4213 uint16_t nb_rx_queue, nb_tx_queue;
4214 uint16_t i, j, k, sm_id = 0;
4215 uint16_t total_tc_num;
4216 struct rte_port *port;
4222 * The fwd_config_setup() is called when the port is RTE_PORT_STARTED
4223 * or RTE_PORT_STOPPED.
4225 * Re-configure ports to get updated mapping between tc and queue in
4226 * case the queue number of the port is changed. Skip for started ports
4227 * since modifying queue number and calling dev_configure need to stop
4230 for (pid = 0; pid < nb_fwd_ports; pid++) {
4231 if (port_is_started(pid) == 1)
4235 ret = rte_eth_dev_configure(pid, nb_rxq, nb_txq,
4239 "Failed to re-configure port %d, ret = %d.\n",
4245 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
4246 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
4247 cur_fwd_config.nb_fwd_streams =
4248 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
4249 total_tc_num = get_fwd_port_total_tc_num();
4250 if (cur_fwd_config.nb_fwd_lcores > total_tc_num)
4251 cur_fwd_config.nb_fwd_lcores = total_tc_num;
4253 /* reinitialize forwarding streams */
4257 /* get the dcb info on the first RX and TX ports */
4258 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
4259 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
4261 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
4262 fwd_lcores[lc_id]->stream_nb = 0;
4263 fwd_lcores[lc_id]->stream_idx = sm_id;
4264 for (i = 0; i < RTE_ETH_MAX_VMDQ_POOL; i++) {
4265 /* if the nb_queue is zero, means this tc is
4266 * not enabled on the POOL
4268 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
4270 k = fwd_lcores[lc_id]->stream_nb +
4271 fwd_lcores[lc_id]->stream_idx;
4272 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
4273 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
4274 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
4275 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
4276 for (j = 0; j < nb_rx_queue; j++) {
4277 struct fwd_stream *fs;
4279 fs = fwd_streams[k + j];
4280 fs->rx_port = fwd_ports_ids[rxp];
4281 fs->rx_queue = rxq + j;
4282 fs->tx_port = fwd_ports_ids[txp];
4283 fs->tx_queue = txq + j % nb_tx_queue;
4284 fs->peer_addr = fs->tx_port;
4285 fs->retry_enabled = retry_enabled;
4287 fwd_lcores[lc_id]->stream_nb +=
4288 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
4290 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
4293 if (tc < rxp_dcb_info.nb_tcs)
4295 /* Restart from TC 0 on next RX port */
4297 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
4299 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
4302 if (rxp >= nb_fwd_ports)
4304 /* get the dcb information on next RX and TX ports */
4305 if ((rxp & 0x1) == 0)
4306 txp = (portid_t) (rxp + 1);
4308 txp = (portid_t) (rxp - 1);
4309 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
4310 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
4315 icmp_echo_config_setup(void)
4322 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
4323 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
4324 (nb_txq * nb_fwd_ports);
4326 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
4327 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
4328 cur_fwd_config.nb_fwd_streams =
4329 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
4330 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
4331 cur_fwd_config.nb_fwd_lcores =
4332 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
4333 if (verbose_level > 0) {
4334 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
4336 cur_fwd_config.nb_fwd_lcores,
4337 cur_fwd_config.nb_fwd_ports,
4338 cur_fwd_config.nb_fwd_streams);
4341 /* reinitialize forwarding streams */
4343 setup_fwd_config_of_each_lcore(&cur_fwd_config);
4345 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
4346 if (verbose_level > 0)
4347 printf(" core=%d: \n", lc_id);
4348 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
4349 struct fwd_stream *fs;
4350 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
4351 fs->rx_port = fwd_ports_ids[rxp];
4353 fs->tx_port = fs->rx_port;
4355 fs->peer_addr = fs->tx_port;
4356 fs->retry_enabled = retry_enabled;
4357 if (verbose_level > 0)
4358 printf(" stream=%d port=%d rxq=%d txq=%d\n",
4359 sm_id, fs->rx_port, fs->rx_queue,
4361 rxq = (queueid_t) (rxq + 1);
4362 if (rxq == nb_rxq) {
4364 rxp = (portid_t) (rxp + 1);
4371 fwd_config_setup(void)
4373 struct rte_port *port;
4377 cur_fwd_config.fwd_eng = cur_fwd_eng;
4378 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
4379 icmp_echo_config_setup();
4383 if ((nb_rxq > 1) && (nb_txq > 1)){
4385 for (i = 0; i < nb_fwd_ports; i++) {
4386 pt_id = fwd_ports_ids[i];
4387 port = &ports[pt_id];
4388 if (!port->dcb_flag) {
4390 "In DCB mode, all forwarding ports must be configured in this mode.\n");
4394 if (nb_fwd_lcores == 1) {
4396 "In DCB mode,the nb forwarding cores should be larger than 1.\n");
4400 dcb_fwd_config_setup();
4402 rss_fwd_config_setup();
4405 simple_fwd_config_setup();
4409 mp_alloc_to_str(uint8_t mode)
4412 case MP_ALLOC_NATIVE:
4418 case MP_ALLOC_XMEM_HUGE:
4428 pkt_fwd_config_display(struct fwd_config *cfg)
4430 struct fwd_stream *fs;
4434 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
4435 "NUMA support %s, MP allocation mode: %s\n",
4436 cfg->fwd_eng->fwd_mode_name,
4437 retry_enabled == 0 ? "" : " with retry",
4438 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
4439 numa_support == 1 ? "enabled" : "disabled",
4440 mp_alloc_to_str(mp_alloc_type));
4443 printf("TX retry num: %u, delay between TX retries: %uus\n",
4444 burst_tx_retry_num, burst_tx_delay_time);
4445 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
4446 printf("Logical Core %u (socket %u) forwards packets on "
4448 fwd_lcores_cpuids[lc_id],
4449 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
4450 fwd_lcores[lc_id]->stream_nb);
4451 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
4452 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
4453 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
4454 "P=%d/Q=%d (socket %u) ",
4455 fs->rx_port, fs->rx_queue,
4456 ports[fs->rx_port].socket_id,
4457 fs->tx_port, fs->tx_queue,
4458 ports[fs->tx_port].socket_id);
4459 print_ethaddr("peer=",
4460 &peer_eth_addrs[fs->peer_addr]);
4468 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
4470 struct rte_ether_addr new_peer_addr;
4471 if (!rte_eth_dev_is_valid_port(port_id)) {
4472 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
4475 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
4476 fprintf(stderr, "Error: Invalid ethernet address: %s\n",
4480 peer_eth_addrs[port_id] = new_peer_addr;
4484 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
4487 unsigned int lcore_cpuid;
4492 for (i = 0; i < nb_lc; i++) {
4493 lcore_cpuid = lcorelist[i];
4494 if (! rte_lcore_is_enabled(lcore_cpuid)) {
4495 fprintf(stderr, "lcore %u not enabled\n", lcore_cpuid);
4498 if (lcore_cpuid == rte_get_main_lcore()) {
4500 "lcore %u cannot be masked on for running packet forwarding, which is the main lcore and reserved for command line parsing only\n",
4505 fwd_lcores_cpuids[i] = lcore_cpuid;
4507 if (record_now == 0) {
4511 nb_cfg_lcores = (lcoreid_t) nb_lc;
4512 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
4513 printf("previous number of forwarding cores %u - changed to "
4514 "number of configured cores %u\n",
4515 (unsigned int) nb_fwd_lcores, nb_lc);
4516 nb_fwd_lcores = (lcoreid_t) nb_lc;
4523 set_fwd_lcores_mask(uint64_t lcoremask)
4525 unsigned int lcorelist[64];
4529 if (lcoremask == 0) {
4530 fprintf(stderr, "Invalid NULL mask of cores\n");
4534 for (i = 0; i < 64; i++) {
4535 if (! ((uint64_t)(1ULL << i) & lcoremask))
4537 lcorelist[nb_lc++] = i;
4539 return set_fwd_lcores_list(lcorelist, nb_lc);
4543 set_fwd_lcores_number(uint16_t nb_lc)
4545 if (test_done == 0) {
4546 fprintf(stderr, "Please stop forwarding first\n");
4549 if (nb_lc > nb_cfg_lcores) {
4551 "nb fwd cores %u > %u (max. number of configured lcores) - ignored\n",
4552 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
4555 nb_fwd_lcores = (lcoreid_t) nb_lc;
4556 printf("Number of forwarding cores set to %u\n",
4557 (unsigned int) nb_fwd_lcores);
4561 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
4569 for (i = 0; i < nb_pt; i++) {
4570 port_id = (portid_t) portlist[i];
4571 if (port_id_is_invalid(port_id, ENABLED_WARN))
4574 fwd_ports_ids[i] = port_id;
4576 if (record_now == 0) {
4580 nb_cfg_ports = (portid_t) nb_pt;
4581 if (nb_fwd_ports != (portid_t) nb_pt) {
4582 printf("previous number of forwarding ports %u - changed to "
4583 "number of configured ports %u\n",
4584 (unsigned int) nb_fwd_ports, nb_pt);
4585 nb_fwd_ports = (portid_t) nb_pt;
4590 * Parse the user input and obtain the list of forwarding ports
4593 * String containing the user input. User can specify
4594 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
4595 * For example, if the user wants to use all the available
4596 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
4597 * If the user wants to use only the ports 1,2 then the input
4599 * valid characters are '-' and ','
4600 * @param[out] values
4601 * This array will be filled with a list of port IDs
4602 * based on the user input
4603 * Note that duplicate entries are discarded and only the first
4604 * count entries in this array are port IDs and all the rest
4605 * will contain default values
4606 * @param[in] maxsize
4607 * This parameter denotes 2 things
4608 * 1) Number of elements in the values array
4609 * 2) Maximum value of each element in the values array
4611 * On success, returns total count of parsed port IDs
4612 * On failure, returns 0
4615 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
4617 unsigned int count = 0;
4621 unsigned int marked[maxsize];
4623 if (list == NULL || values == NULL)
4626 for (i = 0; i < (int)maxsize; i++)
4632 /*Remove the blank spaces if any*/
4633 while (isblank(*list))
4638 value = strtol(list, &end, 10);
4639 if (errno || end == NULL)
4641 if (value < 0 || value >= (int)maxsize)
4643 while (isblank(*end))
4645 if (*end == '-' && min == INT_MAX) {
4647 } else if ((*end == ',') || (*end == '\0')) {
4651 for (i = min; i <= max; i++) {
4652 if (count < maxsize) {
4664 } while (*end != '\0');
4670 parse_fwd_portlist(const char *portlist)
4672 unsigned int portcount;
4673 unsigned int portindex[RTE_MAX_ETHPORTS];
4674 unsigned int i, valid_port_count = 0;
4676 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
4678 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
4681 * Here we verify the validity of the ports
4682 * and thereby calculate the total number of
4685 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
4686 if (rte_eth_dev_is_valid_port(portindex[i])) {
4687 portindex[valid_port_count] = portindex[i];
4692 set_fwd_ports_list(portindex, valid_port_count);
4696 set_fwd_ports_mask(uint64_t portmask)
4698 unsigned int portlist[64];
4702 if (portmask == 0) {
4703 fprintf(stderr, "Invalid NULL mask of ports\n");
4707 RTE_ETH_FOREACH_DEV(i) {
4708 if (! ((uint64_t)(1ULL << i) & portmask))
4710 portlist[nb_pt++] = i;
4712 set_fwd_ports_list(portlist, nb_pt);
4716 set_fwd_ports_number(uint16_t nb_pt)
4718 if (nb_pt > nb_cfg_ports) {
4720 "nb fwd ports %u > %u (number of configured ports) - ignored\n",
4721 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
4724 nb_fwd_ports = (portid_t) nb_pt;
4725 printf("Number of forwarding ports set to %u\n",
4726 (unsigned int) nb_fwd_ports);
4730 port_is_forwarding(portid_t port_id)
4734 if (port_id_is_invalid(port_id, ENABLED_WARN))
4737 for (i = 0; i < nb_fwd_ports; i++) {
4738 if (fwd_ports_ids[i] == port_id)
4746 set_nb_pkt_per_burst(uint16_t nb)
4748 if (nb > MAX_PKT_BURST) {
4750 "nb pkt per burst: %u > %u (maximum packet per burst) ignored\n",
4751 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
4754 nb_pkt_per_burst = nb;
4755 printf("Number of packets per burst set to %u\n",
4756 (unsigned int) nb_pkt_per_burst);
4760 tx_split_get_name(enum tx_pkt_split split)
4764 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
4765 if (tx_split_name[i].split == split)
4766 return tx_split_name[i].name;
4772 set_tx_pkt_split(const char *name)
4776 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
4777 if (strcmp(tx_split_name[i].name, name) == 0) {
4778 tx_pkt_split = tx_split_name[i].split;
4782 fprintf(stderr, "unknown value: \"%s\"\n", name);
4786 parse_fec_mode(const char *name, uint32_t *fec_capa)
4790 for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
4791 if (strcmp(fec_mode_name[i].name, name) == 0) {
4793 RTE_ETH_FEC_MODE_TO_CAPA(fec_mode_name[i].mode);
4801 show_fec_capability(unsigned int num, struct rte_eth_fec_capa *speed_fec_capa)
4805 printf("FEC capabilities:\n");
4807 for (i = 0; i < num; i++) {
4809 rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
4811 for (j = 0; j < RTE_DIM(fec_mode_name); j++) {
4812 if (RTE_ETH_FEC_MODE_TO_CAPA(j) &
4813 speed_fec_capa[i].capa)
4814 printf("%s ", fec_mode_name[j].name);
4821 show_rx_pkt_offsets(void)
4826 printf("Number of offsets: %u\n", n);
4828 printf("Segment offsets: ");
4829 for (i = 0; i != n - 1; i++)
4830 printf("%hu,", rx_pkt_seg_offsets[i]);
4831 printf("%hu\n", rx_pkt_seg_lengths[i]);
4836 set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs)
4840 if (nb_offs >= MAX_SEGS_BUFFER_SPLIT) {
4841 printf("nb segments per RX packets=%u >= "
4842 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_offs);
4847 * No extra check here, the segment length will be checked by PMD
4848 * in the extended queue setup.
4850 for (i = 0; i < nb_offs; i++) {
4851 if (seg_offsets[i] >= UINT16_MAX) {
4852 printf("offset[%u]=%u > UINT16_MAX - give up\n",
4858 for (i = 0; i < nb_offs; i++)
4859 rx_pkt_seg_offsets[i] = (uint16_t) seg_offsets[i];
4861 rx_pkt_nb_offs = (uint8_t) nb_offs;
4865 show_rx_pkt_segments(void)
4870 printf("Number of segments: %u\n", n);
4872 printf("Segment sizes: ");
4873 for (i = 0; i != n - 1; i++)
4874 printf("%hu,", rx_pkt_seg_lengths[i]);
4875 printf("%hu\n", rx_pkt_seg_lengths[i]);
4880 set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
4884 if (nb_segs >= MAX_SEGS_BUFFER_SPLIT) {
4885 printf("nb segments per RX packets=%u >= "
4886 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs);
4891 * No extra check here, the segment length will be checked by PMD
4892 * in the extended queue setup.
4894 for (i = 0; i < nb_segs; i++) {
4895 if (seg_lengths[i] >= UINT16_MAX) {
4896 printf("length[%u]=%u > UINT16_MAX - give up\n",
4902 for (i = 0; i < nb_segs; i++)
4903 rx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
4905 rx_pkt_nb_segs = (uint8_t) nb_segs;
4909 show_tx_pkt_segments(void)
4915 split = tx_split_get_name(tx_pkt_split);
4917 printf("Number of segments: %u\n", n);
4918 printf("Segment sizes: ");
4919 for (i = 0; i != n - 1; i++)
4920 printf("%hu,", tx_pkt_seg_lengths[i]);
4921 printf("%hu\n", tx_pkt_seg_lengths[i]);
4922 printf("Split packet: %s\n", split);
4926 nb_segs_is_invalid(unsigned int nb_segs)
4933 RTE_ETH_FOREACH_DEV(port_id) {
4934 for (queue_id = 0; queue_id < nb_txq; queue_id++) {
4935 ret = get_tx_ring_size(port_id, queue_id, &ring_size);
4937 /* Port may not be initialized yet, can't say
4938 * the port is invalid in this stage.
4942 if (ring_size < nb_segs) {
4943 printf("nb segments per TX packets=%u >= TX "
4944 "queue(%u) ring_size=%u - txpkts ignored\n",
4945 nb_segs, queue_id, ring_size);
4955 set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
4957 uint16_t tx_pkt_len;
4961 * For single segment settings failed check is ignored.
4962 * It is a very basic capability to send the single segment
4963 * packets, suppose it is always supported.
4965 if (nb_segs > 1 && nb_segs_is_invalid(nb_segs)) {
4967 "Tx segment size(%u) is not supported - txpkts ignored\n",
4972 if (nb_segs > RTE_MAX_SEGS_PER_PKT) {
4974 "Tx segment size(%u) is bigger than max number of segment(%u)\n",
4975 nb_segs, RTE_MAX_SEGS_PER_PKT);
4980 * Check that each segment length is greater or equal than
4981 * the mbuf data size.
4982 * Check also that the total packet length is greater or equal than the
4983 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
4987 for (i = 0; i < nb_segs; i++) {
4988 if (seg_lengths[i] > mbuf_data_size[0]) {
4990 "length[%u]=%u > mbuf_data_size=%u - give up\n",
4991 i, seg_lengths[i], mbuf_data_size[0]);
4994 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
4996 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
4997 fprintf(stderr, "total packet length=%u < %d - give up\n",
4998 (unsigned) tx_pkt_len,
4999 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
5003 for (i = 0; i < nb_segs; i++)
5004 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
5006 tx_pkt_length = tx_pkt_len;
5007 tx_pkt_nb_segs = (uint8_t) nb_segs;
5011 show_tx_pkt_times(void)
5013 printf("Interburst gap: %u\n", tx_pkt_times_inter);
5014 printf("Intraburst gap: %u\n", tx_pkt_times_intra);
5018 set_tx_pkt_times(unsigned int *tx_times)
5020 tx_pkt_times_inter = tx_times[0];
5021 tx_pkt_times_intra = tx_times[1];
5026 setup_gro(const char *onoff, portid_t port_id)
5028 if (!rte_eth_dev_is_valid_port(port_id)) {
5029 fprintf(stderr, "invalid port id %u\n", port_id);
5032 if (test_done == 0) {
5034 "Before enable/disable GRO, please stop forwarding first\n");
5037 if (strcmp(onoff, "on") == 0) {
5038 if (gro_ports[port_id].enable != 0) {
5040 "Port %u has enabled GRO. Please disable GRO first\n",
5044 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
5045 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
5046 gro_ports[port_id].param.max_flow_num =
5047 GRO_DEFAULT_FLOW_NUM;
5048 gro_ports[port_id].param.max_item_per_flow =
5049 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
5051 gro_ports[port_id].enable = 1;
5053 if (gro_ports[port_id].enable == 0) {
5054 fprintf(stderr, "Port %u has disabled GRO\n", port_id);
5057 gro_ports[port_id].enable = 0;
5062 setup_gro_flush_cycles(uint8_t cycles)
5064 if (test_done == 0) {
5066 "Before change flush interval for GRO, please stop forwarding first.\n");
5070 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
5071 GRO_DEFAULT_FLUSH_CYCLES) {
5073 "The flushing cycle be in the range of 1 to %u. Revert to the default value %u.\n",
5074 GRO_MAX_FLUSH_CYCLES, GRO_DEFAULT_FLUSH_CYCLES);
5075 cycles = GRO_DEFAULT_FLUSH_CYCLES;
5078 gro_flush_cycles = cycles;
5082 show_gro(portid_t port_id)
5084 struct rte_gro_param *param;
5085 uint32_t max_pkts_num;
5087 param = &gro_ports[port_id].param;
5089 if (!rte_eth_dev_is_valid_port(port_id)) {
5090 fprintf(stderr, "Invalid port id %u.\n", port_id);
5093 if (gro_ports[port_id].enable) {
5094 printf("GRO type: TCP/IPv4\n");
5095 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
5096 max_pkts_num = param->max_flow_num *
5097 param->max_item_per_flow;
5099 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
5100 printf("Max number of packets to perform GRO: %u\n",
5102 printf("Flushing cycles: %u\n", gro_flush_cycles);
5104 printf("Port %u doesn't enable GRO.\n", port_id);
5106 #endif /* RTE_LIB_GRO */
5110 setup_gso(const char *mode, portid_t port_id)
5112 if (!rte_eth_dev_is_valid_port(port_id)) {
5113 fprintf(stderr, "invalid port id %u\n", port_id);
5116 if (strcmp(mode, "on") == 0) {
5117 if (test_done == 0) {
5119 "before enabling GSO, please stop forwarding first\n");
5122 gso_ports[port_id].enable = 1;
5123 } else if (strcmp(mode, "off") == 0) {
5124 if (test_done == 0) {
5126 "before disabling GSO, please stop forwarding first\n");
5129 gso_ports[port_id].enable = 0;
5132 #endif /* RTE_LIB_GSO */
5135 list_pkt_forwarding_modes(void)
5137 static char fwd_modes[128] = "";
5138 const char *separator = "|";
5139 struct fwd_engine *fwd_eng;
5142 if (strlen (fwd_modes) == 0) {
5143 while ((fwd_eng = fwd_engines[i++]) != NULL) {
5144 strncat(fwd_modes, fwd_eng->fwd_mode_name,
5145 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
5146 strncat(fwd_modes, separator,
5147 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
5149 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
5156 list_pkt_forwarding_retry_modes(void)
5158 static char fwd_modes[128] = "";
5159 const char *separator = "|";
5160 struct fwd_engine *fwd_eng;
5163 if (strlen(fwd_modes) == 0) {
5164 while ((fwd_eng = fwd_engines[i++]) != NULL) {
5165 if (fwd_eng == &rx_only_engine)
5167 strncat(fwd_modes, fwd_eng->fwd_mode_name,
5169 strlen(fwd_modes) - 1);
5170 strncat(fwd_modes, separator,
5172 strlen(fwd_modes) - 1);
5174 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
5181 set_pkt_forwarding_mode(const char *fwd_mode_name)
5183 struct fwd_engine *fwd_eng;
5187 while ((fwd_eng = fwd_engines[i]) != NULL) {
5188 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
5189 printf("Set %s packet forwarding mode%s\n",
5191 retry_enabled == 0 ? "" : " with retry");
5192 cur_fwd_eng = fwd_eng;
5197 fprintf(stderr, "Invalid %s packet forwarding mode\n", fwd_mode_name);
5201 add_rx_dump_callbacks(portid_t portid)
5203 struct rte_eth_dev_info dev_info;
5207 if (port_id_is_invalid(portid, ENABLED_WARN))
5210 ret = eth_dev_info_get_print_err(portid, &dev_info);
5214 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
5215 if (!ports[portid].rx_dump_cb[queue])
5216 ports[portid].rx_dump_cb[queue] =
5217 rte_eth_add_rx_callback(portid, queue,
5218 dump_rx_pkts, NULL);
5222 add_tx_dump_callbacks(portid_t portid)
5224 struct rte_eth_dev_info dev_info;
5228 if (port_id_is_invalid(portid, ENABLED_WARN))
5231 ret = eth_dev_info_get_print_err(portid, &dev_info);
5235 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
5236 if (!ports[portid].tx_dump_cb[queue])
5237 ports[portid].tx_dump_cb[queue] =
5238 rte_eth_add_tx_callback(portid, queue,
5239 dump_tx_pkts, NULL);
5243 remove_rx_dump_callbacks(portid_t portid)
5245 struct rte_eth_dev_info dev_info;
5249 if (port_id_is_invalid(portid, ENABLED_WARN))
5252 ret = eth_dev_info_get_print_err(portid, &dev_info);
5256 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
5257 if (ports[portid].rx_dump_cb[queue]) {
5258 rte_eth_remove_rx_callback(portid, queue,
5259 ports[portid].rx_dump_cb[queue]);
5260 ports[portid].rx_dump_cb[queue] = NULL;
5265 remove_tx_dump_callbacks(portid_t portid)
5267 struct rte_eth_dev_info dev_info;
5271 if (port_id_is_invalid(portid, ENABLED_WARN))
5274 ret = eth_dev_info_get_print_err(portid, &dev_info);
5278 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
5279 if (ports[portid].tx_dump_cb[queue]) {
5280 rte_eth_remove_tx_callback(portid, queue,
5281 ports[portid].tx_dump_cb[queue]);
5282 ports[portid].tx_dump_cb[queue] = NULL;
5287 configure_rxtx_dump_callbacks(uint16_t verbose)
5291 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
5292 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
5296 RTE_ETH_FOREACH_DEV(portid)
5298 if (verbose == 1 || verbose > 2)
5299 add_rx_dump_callbacks(portid);
5301 remove_rx_dump_callbacks(portid);
5303 add_tx_dump_callbacks(portid);
5305 remove_tx_dump_callbacks(portid);
5310 set_verbose_level(uint16_t vb_level)
5312 printf("Change verbose level from %u to %u\n",
5313 (unsigned int) verbose_level, (unsigned int) vb_level);
5314 verbose_level = vb_level;
5315 configure_rxtx_dump_callbacks(verbose_level);
5319 vlan_extend_set(portid_t port_id, int on)
5323 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
5325 if (port_id_is_invalid(port_id, ENABLED_WARN))
5328 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
5331 vlan_offload |= RTE_ETH_VLAN_EXTEND_OFFLOAD;
5332 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
5334 vlan_offload &= ~RTE_ETH_VLAN_EXTEND_OFFLOAD;
5335 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
5338 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
5341 "rx_vlan_extend_set(port_pi=%d, on=%d) failed diag=%d\n",
5345 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
5349 rx_vlan_strip_set(portid_t port_id, int on)
5353 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
5355 if (port_id_is_invalid(port_id, ENABLED_WARN))
5358 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
5361 vlan_offload |= RTE_ETH_VLAN_STRIP_OFFLOAD;
5362 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5364 vlan_offload &= ~RTE_ETH_VLAN_STRIP_OFFLOAD;
5365 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5368 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
5371 "%s(port_pi=%d, on=%d) failed diag=%d\n",
5372 __func__, port_id, on, diag);
5375 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
5379 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
5383 if (port_id_is_invalid(port_id, ENABLED_WARN))
5386 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
5389 "%s(port_pi=%d, queue_id=%d, on=%d) failed diag=%d\n",
5390 __func__, port_id, queue_id, on, diag);
5394 rx_vlan_filter_set(portid_t port_id, int on)
5398 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
5400 if (port_id_is_invalid(port_id, ENABLED_WARN))
5403 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
5406 vlan_offload |= RTE_ETH_VLAN_FILTER_OFFLOAD;
5407 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
5409 vlan_offload &= ~RTE_ETH_VLAN_FILTER_OFFLOAD;
5410 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
5413 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
5416 "%s(port_pi=%d, on=%d) failed diag=%d\n",
5417 __func__, port_id, on, diag);
5420 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
5424 rx_vlan_qinq_strip_set(portid_t port_id, int on)
5428 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
5430 if (port_id_is_invalid(port_id, ENABLED_WARN))
5433 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
5436 vlan_offload |= RTE_ETH_QINQ_STRIP_OFFLOAD;
5437 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
5439 vlan_offload &= ~RTE_ETH_QINQ_STRIP_OFFLOAD;
5440 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
5443 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
5445 fprintf(stderr, "%s(port_pi=%d, on=%d) failed diag=%d\n",
5446 __func__, port_id, on, diag);
5449 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
5453 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
5457 if (port_id_is_invalid(port_id, ENABLED_WARN))
5459 if (vlan_id_is_invalid(vlan_id))
5461 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
5465 "rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed diag=%d\n",
5466 port_id, vlan_id, on, diag);
5471 rx_vlan_all_filter_set(portid_t port_id, int on)
5475 if (port_id_is_invalid(port_id, ENABLED_WARN))
5477 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
5478 if (rx_vft_set(port_id, vlan_id, on))
5484 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
5488 if (port_id_is_invalid(port_id, ENABLED_WARN))
5491 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
5496 "tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed diag=%d\n",
5497 port_id, vlan_type, tp_id, diag);
5501 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
5503 struct rte_eth_dev_info dev_info;
5506 if (vlan_id_is_invalid(vlan_id))
5509 if (ports[port_id].dev_conf.txmode.offloads &
5510 RTE_ETH_TX_OFFLOAD_QINQ_INSERT) {
5511 fprintf(stderr, "Error, as QinQ has been enabled.\n");
5515 ret = eth_dev_info_get_print_err(port_id, &dev_info);
5519 if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VLAN_INSERT) == 0) {
5521 "Error: vlan insert is not supported by port %d\n",
5526 tx_vlan_reset(port_id);
5527 ports[port_id].dev_conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
5528 ports[port_id].tx_vlan_id = vlan_id;
5532 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
5534 struct rte_eth_dev_info dev_info;
5537 if (vlan_id_is_invalid(vlan_id))
5539 if (vlan_id_is_invalid(vlan_id_outer))
5542 ret = eth_dev_info_get_print_err(port_id, &dev_info);
5546 if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_QINQ_INSERT) == 0) {
5548 "Error: qinq insert not supported by port %d\n",
5553 tx_vlan_reset(port_id);
5554 ports[port_id].dev_conf.txmode.offloads |= (RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
5555 RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
5556 ports[port_id].tx_vlan_id = vlan_id;
5557 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
5561 tx_vlan_reset(portid_t port_id)
5563 ports[port_id].dev_conf.txmode.offloads &=
5564 ~(RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
5565 RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
5566 ports[port_id].tx_vlan_id = 0;
5567 ports[port_id].tx_vlan_id_outer = 0;
5571 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
5573 if (port_id_is_invalid(port_id, ENABLED_WARN))
5576 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
5580 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
5584 if (port_id_is_invalid(port_id, ENABLED_WARN))
5587 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
5590 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
5591 fprintf(stderr, "map_value not in required range 0..%d\n",
5592 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
5596 if (!is_rx) { /* tx */
5597 ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, queue_id,
5601 "failed to set tx queue stats mapping.\n");
5605 ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, queue_id,
5609 "failed to set rx queue stats mapping.\n");
5616 set_xstats_hide_zero(uint8_t on_off)
5618 xstats_hide_zero = on_off;
5622 set_record_core_cycles(uint8_t on_off)
5624 record_core_cycles = on_off;
5628 set_record_burst_stats(uint8_t on_off)
5630 record_burst_stats = on_off;
5633 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
5636 flowtype_to_str(uint16_t flow_type)
5638 struct flow_type_info {
5644 static struct flow_type_info flowtype_str_table[] = {
5645 {"raw", RTE_ETH_FLOW_RAW},
5646 {"ipv4", RTE_ETH_FLOW_IPV4},
5647 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
5648 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
5649 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
5650 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
5651 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
5652 {"ipv6", RTE_ETH_FLOW_IPV6},
5653 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
5654 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
5655 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
5656 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
5657 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
5658 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
5659 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
5660 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
5661 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
5662 {"port", RTE_ETH_FLOW_PORT},
5663 {"vxlan", RTE_ETH_FLOW_VXLAN},
5664 {"geneve", RTE_ETH_FLOW_GENEVE},
5665 {"nvgre", RTE_ETH_FLOW_NVGRE},
5666 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
5667 {"gtpu", RTE_ETH_FLOW_GTPU},
5670 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
5671 if (flowtype_str_table[i].ftype == flow_type)
5672 return flowtype_str_table[i].str;
5679 print_fdir_mask(struct rte_eth_fdir_masks *mask)
5681 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
5683 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
5684 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
5685 " tunnel_id: 0x%08x",
5686 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
5687 rte_be_to_cpu_32(mask->tunnel_id_mask));
5688 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5689 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
5690 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
5691 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
5693 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
5694 rte_be_to_cpu_16(mask->src_port_mask),
5695 rte_be_to_cpu_16(mask->dst_port_mask));
5697 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
5698 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
5699 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
5700 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
5701 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
5703 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
5704 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
5705 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
5706 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
5707 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
5714 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
5716 struct rte_eth_flex_payload_cfg *cfg;
5719 for (i = 0; i < flex_conf->nb_payloads; i++) {
5720 cfg = &flex_conf->flex_set[i];
5721 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
5723 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
5724 printf("\n L2_PAYLOAD: ");
5725 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
5726 printf("\n L3_PAYLOAD: ");
5727 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
5728 printf("\n L4_PAYLOAD: ");
5730 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
5731 for (j = 0; j < num; j++)
5732 printf(" %-5u", cfg->src_offset[j]);
5738 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
5740 struct rte_eth_fdir_flex_mask *mask;
5744 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
5745 mask = &flex_conf->flex_mask[i];
5746 p = flowtype_to_str(mask->flow_type);
5747 printf("\n %s:\t", p ? p : "unknown");
5748 for (j = 0; j < num; j++)
5749 printf(" %02x", mask->mask[j]);
5755 print_fdir_flow_type(uint32_t flow_types_mask)
5760 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
5761 if (!(flow_types_mask & (1 << i)))
5763 p = flowtype_to_str(i);
5773 get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info,
5774 struct rte_eth_fdir_stats *fdir_stat)
5779 if (ret == -ENOTSUP) {
5780 ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info);
5782 ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat);
5785 #ifdef RTE_NET_IXGBE
5786 if (ret == -ENOTSUP) {
5787 ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info);
5789 ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat);
5796 fprintf(stderr, "\n FDIR is not supported on port %-2d\n",
5800 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
5807 fdir_get_infos(portid_t port_id)
5809 struct rte_eth_fdir_stats fdir_stat;
5810 struct rte_eth_fdir_info fdir_info;
5812 static const char *fdir_stats_border = "########################";
5814 if (port_id_is_invalid(port_id, ENABLED_WARN))
5817 memset(&fdir_info, 0, sizeof(fdir_info));
5818 memset(&fdir_stat, 0, sizeof(fdir_stat));
5819 if (get_fdir_info(port_id, &fdir_info, &fdir_stat))
5822 printf("\n %s FDIR infos for port %-2d %s\n",
5823 fdir_stats_border, port_id, fdir_stats_border);
5825 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
5826 printf(" PERFECT\n");
5827 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
5828 printf(" PERFECT-MAC-VLAN\n");
5829 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
5830 printf(" PERFECT-TUNNEL\n");
5831 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
5832 printf(" SIGNATURE\n");
5834 printf(" DISABLE\n");
5835 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
5836 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
5837 printf(" SUPPORTED FLOW TYPE: ");
5838 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
5840 printf(" FLEX PAYLOAD INFO:\n");
5841 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
5842 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
5843 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
5844 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
5845 fdir_info.flex_payload_unit,
5846 fdir_info.max_flex_payload_segment_num,
5847 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
5849 print_fdir_mask(&fdir_info.mask);
5850 if (fdir_info.flex_conf.nb_payloads > 0) {
5851 printf(" FLEX PAYLOAD SRC OFFSET:");
5852 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
5854 if (fdir_info.flex_conf.nb_flexmasks > 0) {
5855 printf(" FLEX MASK CFG:");
5856 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
5858 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
5859 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
5860 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
5861 fdir_info.guarant_spc, fdir_info.best_spc);
5862 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
5863 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
5864 " add: %-10"PRIu64" remove: %"PRIu64"\n"
5865 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
5866 fdir_stat.collision, fdir_stat.free,
5867 fdir_stat.maxhash, fdir_stat.maxlen,
5868 fdir_stat.add, fdir_stat.remove,
5869 fdir_stat.f_add, fdir_stat.f_remove);
5870 printf(" %s############################%s\n",
5871 fdir_stats_border, fdir_stats_border);
5874 #endif /* RTE_NET_I40E || RTE_NET_IXGBE */
5877 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
5879 struct rte_port *port;
5880 struct rte_eth_fdir_flex_conf *flex_conf;
5883 port = &ports[port_id];
5884 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
5885 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
5886 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
5891 if (i >= RTE_ETH_FLOW_MAX) {
5892 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
5893 idx = flex_conf->nb_flexmasks;
5894 flex_conf->nb_flexmasks++;
5897 "The flex mask table is full. Can not set flex mask for flow_type(%u).",
5902 rte_memcpy(&flex_conf->flex_mask[idx],
5904 sizeof(struct rte_eth_fdir_flex_mask));
5908 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
5910 struct rte_port *port;
5911 struct rte_eth_fdir_flex_conf *flex_conf;
5914 port = &ports[port_id];
5915 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
5916 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
5917 if (cfg->type == flex_conf->flex_set[i].type) {
5922 if (i >= RTE_ETH_PAYLOAD_MAX) {
5923 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
5924 idx = flex_conf->nb_payloads;
5925 flex_conf->nb_payloads++;
5928 "The flex payload table is full. Can not set flex payload for type(%u).",
5933 rte_memcpy(&flex_conf->flex_set[idx],
5935 sizeof(struct rte_eth_flex_payload_cfg));
5940 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
5942 #ifdef RTE_NET_IXGBE
5946 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
5948 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
5953 "rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
5954 is_rx ? "rx" : "tx", port_id, diag);
5957 fprintf(stderr, "VF %s setting not supported for port %d\n",
5958 is_rx ? "Rx" : "Tx", port_id);
5964 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
5967 struct rte_eth_link link;
5970 if (port_id_is_invalid(port_id, ENABLED_WARN))
5972 ret = eth_link_get_nowait_print_err(port_id, &link);
5975 if (link.link_speed != RTE_ETH_SPEED_NUM_UNKNOWN &&
5976 rate > link.link_speed) {
5978 "Invalid rate value:%u bigger than link speed: %u\n",
5979 rate, link.link_speed);
5982 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
5986 "rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
5992 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
5994 int diag = -ENOTSUP;
5998 RTE_SET_USED(q_msk);
6000 #ifdef RTE_NET_IXGBE
6001 if (diag == -ENOTSUP)
6002 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
6006 if (diag == -ENOTSUP)
6007 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
6013 "%s for port_id=%d failed diag=%d\n",
6014 __func__, port_id, diag);
6019 set_rxq_avail_thresh(portid_t port_id, uint16_t queue_id, uint8_t avail_thresh)
6021 if (port_id_is_invalid(port_id, ENABLED_WARN))
6024 return rte_eth_rx_avail_thresh_set(port_id, queue_id, avail_thresh);
6028 * Functions to manage the set of filtered Multicast MAC addresses.
6030 * A pool of filtered multicast MAC addresses is associated with each port.
6031 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
6032 * The address of the pool and the number of valid multicast MAC addresses
6033 * recorded in the pool are stored in the fields "mc_addr_pool" and
6034 * "mc_addr_nb" of the "rte_port" data structure.
6036 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
6037 * to be supplied a contiguous array of multicast MAC addresses.
6038 * To comply with this constraint, the set of multicast addresses recorded
6039 * into the pool are systematically compacted at the beginning of the pool.
6040 * Hence, when a multicast address is removed from the pool, all following
6041 * addresses, if any, are copied back to keep the set contiguous.
6043 #define MCAST_POOL_INC 32
6046 mcast_addr_pool_extend(struct rte_port *port)
6048 struct rte_ether_addr *mc_pool;
6049 size_t mc_pool_size;
6052 * If a free entry is available at the end of the pool, just
6053 * increment the number of recorded multicast addresses.
6055 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
6061 * [re]allocate a pool with MCAST_POOL_INC more entries.
6062 * The previous test guarantees that port->mc_addr_nb is a multiple
6063 * of MCAST_POOL_INC.
6065 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
6067 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
6069 if (mc_pool == NULL) {
6071 "allocation of pool of %u multicast addresses failed\n",
6072 port->mc_addr_nb + MCAST_POOL_INC);
6076 port->mc_addr_pool = mc_pool;
6083 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
6085 if (mcast_addr_pool_extend(port) != 0)
6087 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
6091 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
6094 if (addr_idx == port->mc_addr_nb) {
6095 /* No need to recompact the set of multicast addresses. */
6096 if (port->mc_addr_nb == 0) {
6097 /* free the pool of multicast addresses. */
6098 free(port->mc_addr_pool);
6099 port->mc_addr_pool = NULL;
6103 memmove(&port->mc_addr_pool[addr_idx],
6104 &port->mc_addr_pool[addr_idx + 1],
6105 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
6109 mcast_addr_pool_destroy(portid_t port_id)
6111 struct rte_port *port;
6113 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
6114 port_id == (portid_t)RTE_PORT_ALL)
6116 port = &ports[port_id];
6118 if (port->mc_addr_nb != 0) {
6119 /* free the pool of multicast addresses. */
6120 free(port->mc_addr_pool);
6121 port->mc_addr_pool = NULL;
6122 port->mc_addr_nb = 0;
6128 eth_port_multicast_addr_list_set(portid_t port_id)
6130 struct rte_port *port;
6133 port = &ports[port_id];
6134 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
6138 "rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
6139 port_id, port->mc_addr_nb, diag);
6145 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
6147 struct rte_port *port;
6150 if (port_id_is_invalid(port_id, ENABLED_WARN))
6153 port = &ports[port_id];
6156 * Check that the added multicast MAC address is not already recorded
6157 * in the pool of multicast addresses.
6159 for (i = 0; i < port->mc_addr_nb; i++) {
6160 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
6162 "multicast address already filtered by port\n");
6167 mcast_addr_pool_append(port, mc_addr);
6168 if (eth_port_multicast_addr_list_set(port_id) < 0)
6169 /* Rollback on failure, remove the address from the pool */
6170 mcast_addr_pool_remove(port, i);
6174 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
6176 struct rte_port *port;
6179 if (port_id_is_invalid(port_id, ENABLED_WARN))
6182 port = &ports[port_id];
6185 * Search the pool of multicast MAC addresses for the removed address.
6187 for (i = 0; i < port->mc_addr_nb; i++) {
6188 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
6191 if (i == port->mc_addr_nb) {
6192 fprintf(stderr, "multicast address not filtered by port %d\n",
6197 mcast_addr_pool_remove(port, i);
6198 if (eth_port_multicast_addr_list_set(port_id) < 0)
6199 /* Rollback on failure, add the address back into the pool */
6200 mcast_addr_pool_append(port, mc_addr);
6204 port_dcb_info_display(portid_t port_id)
6206 struct rte_eth_dcb_info dcb_info;
6209 static const char *border = "================";
6211 if (port_id_is_invalid(port_id, ENABLED_WARN))
6214 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
6216 fprintf(stderr, "\n Failed to get dcb infos on port %-2d\n",
6220 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
6221 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
6223 for (i = 0; i < dcb_info.nb_tcs; i++)
6225 printf("\n Priority : ");
6226 for (i = 0; i < dcb_info.nb_tcs; i++)
6227 printf("\t%4d", dcb_info.prio_tc[i]);
6228 printf("\n BW percent :");
6229 for (i = 0; i < dcb_info.nb_tcs; i++)
6230 printf("\t%4d%%", dcb_info.tc_bws[i]);
6231 printf("\n RXQ base : ");
6232 for (i = 0; i < dcb_info.nb_tcs; i++)
6233 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
6234 printf("\n RXQ number :");
6235 for (i = 0; i < dcb_info.nb_tcs; i++)
6236 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
6237 printf("\n TXQ base : ");
6238 for (i = 0; i < dcb_info.nb_tcs; i++)
6239 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
6240 printf("\n TXQ number :");
6241 for (i = 0; i < dcb_info.nb_tcs; i++)
6242 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
6247 open_file(const char *file_path, uint32_t *size)
6249 int fd = open(file_path, O_RDONLY);
6251 uint8_t *buf = NULL;
6259 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
6263 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
6265 fprintf(stderr, "%s: File operations failed\n", __func__);
6269 pkg_size = st_buf.st_size;
6272 fprintf(stderr, "%s: File operations failed\n", __func__);
6276 buf = (uint8_t *)malloc(pkg_size);
6279 fprintf(stderr, "%s: Failed to malloc memory\n", __func__);
6283 ret = read(fd, buf, pkg_size);
6286 fprintf(stderr, "%s: File read operation failed\n", __func__);
6300 save_file(const char *file_path, uint8_t *buf, uint32_t size)
6302 FILE *fh = fopen(file_path, "wb");
6305 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
6309 if (fwrite(buf, 1, size, fh) != size) {
6311 fprintf(stderr, "%s: File write operation failed\n", __func__);
6321 close_file(uint8_t *buf)
6332 show_macs(portid_t port_id)
6334 char buf[RTE_ETHER_ADDR_FMT_SIZE];
6335 struct rte_eth_dev_info dev_info;
6336 int32_t i, rc, num_macs = 0;
6338 if (eth_dev_info_get_print_err(port_id, &dev_info))
6341 struct rte_ether_addr addr[dev_info.max_mac_addrs];
6342 rc = rte_eth_macaddrs_get(port_id, addr, dev_info.max_mac_addrs);
6346 for (i = 0; i < rc; i++) {
6348 /* skip zero address */
6349 if (rte_is_zero_ether_addr(&addr[i]))
6355 printf("Number of MAC address added: %d\n", num_macs);
6357 for (i = 0; i < rc; i++) {
6359 /* skip zero address */
6360 if (rte_is_zero_ether_addr(&addr[i]))
6363 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &addr[i]);
6364 printf(" %s\n", buf);
6369 show_mcast_macs(portid_t port_id)
6371 char buf[RTE_ETHER_ADDR_FMT_SIZE];
6372 struct rte_ether_addr *addr;
6373 struct rte_port *port;
6376 port = &ports[port_id];
6378 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
6380 for (i = 0; i < port->mc_addr_nb; i++) {
6381 addr = &port->mc_addr_pool[i];
6383 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
6384 printf(" %s\n", buf);