1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation.
3 * Copyright 2013-2014 6WIND S.A.
13 #include <sys/queue.h>
14 #include <sys/types.h>
19 #include <rte_common.h>
20 #include <rte_byteorder.h>
21 #include <rte_debug.h>
23 #include <rte_memory.h>
24 #include <rte_memcpy.h>
25 #include <rte_memzone.h>
26 #include <rte_launch.h>
28 #include <rte_per_lcore.h>
29 #include <rte_lcore.h>
30 #include <rte_branch_prediction.h>
31 #include <rte_mempool.h>
33 #include <rte_interrupts.h>
35 #include <rte_ether.h>
36 #include <rte_ethdev.h>
37 #include <rte_string_fns.h>
38 #include <rte_cycles.h>
41 #include <rte_errno.h>
43 #include <rte_pmd_ixgbe.h>
46 #include <rte_pmd_i40e.h>
49 #include <rte_pmd_bnxt.h>
54 #include <rte_hexdump.h>
57 #include "cmdline_mtr.h"
59 #define ETHDEV_FWVERS_LEN 32
61 #ifdef CLOCK_MONOTONIC_RAW /* Defined in glibc bits/time.h */
62 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
64 #define CLOCK_TYPE_ID CLOCK_MONOTONIC
67 #define NS_PER_SEC 1E9
69 static char *flowtype_to_str(uint16_t flow_type);
72 enum tx_pkt_split split;
76 .split = TX_PKT_SPLIT_OFF,
80 .split = TX_PKT_SPLIT_ON,
84 .split = TX_PKT_SPLIT_RND,
89 const struct rss_type_info rss_type_table[] = {
90 { "all", RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP | RTE_ETH_RSS_TCP |
91 RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP | RTE_ETH_RSS_L2_PAYLOAD |
92 RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP | RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP |
93 RTE_ETH_RSS_GTPU | RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_MPLS | RTE_ETH_RSS_L2TPV2},
95 { "eth", RTE_ETH_RSS_ETH },
96 { "l2-src-only", RTE_ETH_RSS_L2_SRC_ONLY },
97 { "l2-dst-only", RTE_ETH_RSS_L2_DST_ONLY },
98 { "vlan", RTE_ETH_RSS_VLAN },
99 { "s-vlan", RTE_ETH_RSS_S_VLAN },
100 { "c-vlan", RTE_ETH_RSS_C_VLAN },
101 { "ipv4", RTE_ETH_RSS_IPV4 },
102 { "ipv4-frag", RTE_ETH_RSS_FRAG_IPV4 },
103 { "ipv4-tcp", RTE_ETH_RSS_NONFRAG_IPV4_TCP },
104 { "ipv4-udp", RTE_ETH_RSS_NONFRAG_IPV4_UDP },
105 { "ipv4-sctp", RTE_ETH_RSS_NONFRAG_IPV4_SCTP },
106 { "ipv4-other", RTE_ETH_RSS_NONFRAG_IPV4_OTHER },
107 { "ipv6", RTE_ETH_RSS_IPV6 },
108 { "ipv6-frag", RTE_ETH_RSS_FRAG_IPV6 },
109 { "ipv6-tcp", RTE_ETH_RSS_NONFRAG_IPV6_TCP },
110 { "ipv6-udp", RTE_ETH_RSS_NONFRAG_IPV6_UDP },
111 { "ipv6-sctp", RTE_ETH_RSS_NONFRAG_IPV6_SCTP },
112 { "ipv6-other", RTE_ETH_RSS_NONFRAG_IPV6_OTHER },
113 { "l2-payload", RTE_ETH_RSS_L2_PAYLOAD },
114 { "ipv6-ex", RTE_ETH_RSS_IPV6_EX },
115 { "ipv6-tcp-ex", RTE_ETH_RSS_IPV6_TCP_EX },
116 { "ipv6-udp-ex", RTE_ETH_RSS_IPV6_UDP_EX },
117 { "port", RTE_ETH_RSS_PORT },
118 { "vxlan", RTE_ETH_RSS_VXLAN },
119 { "geneve", RTE_ETH_RSS_GENEVE },
120 { "nvgre", RTE_ETH_RSS_NVGRE },
121 { "ip", RTE_ETH_RSS_IP },
122 { "udp", RTE_ETH_RSS_UDP },
123 { "tcp", RTE_ETH_RSS_TCP },
124 { "sctp", RTE_ETH_RSS_SCTP },
125 { "tunnel", RTE_ETH_RSS_TUNNEL },
126 { "l3-pre32", RTE_ETH_RSS_L3_PRE32 },
127 { "l3-pre40", RTE_ETH_RSS_L3_PRE40 },
128 { "l3-pre48", RTE_ETH_RSS_L3_PRE48 },
129 { "l3-pre56", RTE_ETH_RSS_L3_PRE56 },
130 { "l3-pre64", RTE_ETH_RSS_L3_PRE64 },
131 { "l3-pre96", RTE_ETH_RSS_L3_PRE96 },
132 { "l3-src-only", RTE_ETH_RSS_L3_SRC_ONLY },
133 { "l3-dst-only", RTE_ETH_RSS_L3_DST_ONLY },
134 { "l4-src-only", RTE_ETH_RSS_L4_SRC_ONLY },
135 { "l4-dst-only", RTE_ETH_RSS_L4_DST_ONLY },
136 { "esp", RTE_ETH_RSS_ESP },
137 { "ah", RTE_ETH_RSS_AH },
138 { "l2tpv3", RTE_ETH_RSS_L2TPV3 },
139 { "pfcp", RTE_ETH_RSS_PFCP },
140 { "pppoe", RTE_ETH_RSS_PPPOE },
141 { "gtpu", RTE_ETH_RSS_GTPU },
142 { "ecpri", RTE_ETH_RSS_ECPRI },
143 { "mpls", RTE_ETH_RSS_MPLS },
144 { "ipv4-chksum", RTE_ETH_RSS_IPV4_CHKSUM },
145 { "l4-chksum", RTE_ETH_RSS_L4_CHKSUM },
146 { "l2tpv2", RTE_ETH_RSS_L2TPV2 },
150 static const struct {
151 enum rte_eth_fec_mode mode;
153 } fec_mode_name[] = {
155 .mode = RTE_ETH_FEC_NOFEC,
159 .mode = RTE_ETH_FEC_AUTO,
163 .mode = RTE_ETH_FEC_BASER,
167 .mode = RTE_ETH_FEC_RS,
173 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
175 char buf[RTE_ETHER_ADDR_FMT_SIZE];
176 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
177 printf("%s%s", name, buf);
181 nic_xstats_display_periodic(portid_t port_id)
183 struct xstat_display_info *xstats_info;
184 uint64_t *prev_values, *curr_values;
185 uint64_t diff_value, value_rate;
186 struct timespec cur_time;
193 xstats_info = &ports[port_id].xstats_info;
195 ids_supp_sz = xstats_info->ids_supp_sz;
196 if (ids_supp_sz == 0)
201 ids_supp = xstats_info->ids_supp;
202 prev_values = xstats_info->prev_values;
203 curr_values = xstats_info->curr_values;
205 rc = rte_eth_xstats_get_by_id(port_id, ids_supp, curr_values,
207 if (rc != (int)ids_supp_sz) {
209 "Failed to get values of %zu xstats for port %u - return code %d\n",
210 ids_supp_sz, port_id, rc);
215 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
218 ns = cur_time.tv_sec * NS_PER_SEC;
219 ns += cur_time.tv_nsec;
221 if (xstats_info->prev_ns != 0)
222 diff_ns = ns - xstats_info->prev_ns;
223 xstats_info->prev_ns = ns;
226 printf("%-31s%-17s%s\n", " ", "Value", "Rate (since last show)");
227 for (i = 0; i < ids_supp_sz; i++) {
228 diff_value = (curr_values[i] > prev_values[i]) ?
229 (curr_values[i] - prev_values[i]) : 0;
230 prev_values[i] = curr_values[i];
231 value_rate = diff_ns > 0 ?
232 (double)diff_value / diff_ns * NS_PER_SEC : 0;
234 printf(" %-25s%12"PRIu64" %15"PRIu64"\n",
235 xstats_display[i].name, curr_values[i], value_rate);
240 nic_stats_display(portid_t port_id)
242 static uint64_t prev_pkts_rx[RTE_MAX_ETHPORTS];
243 static uint64_t prev_pkts_tx[RTE_MAX_ETHPORTS];
244 static uint64_t prev_bytes_rx[RTE_MAX_ETHPORTS];
245 static uint64_t prev_bytes_tx[RTE_MAX_ETHPORTS];
246 static uint64_t prev_ns[RTE_MAX_ETHPORTS];
247 struct timespec cur_time;
248 uint64_t diff_pkts_rx, diff_pkts_tx, diff_bytes_rx, diff_bytes_tx,
250 uint64_t mpps_rx, mpps_tx, mbps_rx, mbps_tx;
251 struct rte_eth_stats stats;
252 static const char *nic_stats_border = "########################";
255 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
259 ret = rte_eth_stats_get(port_id, &stats);
262 "%s: Error: failed to get stats (port %u): %d",
263 __func__, port_id, ret);
266 printf("\n %s NIC statistics for port %-2d %s\n",
267 nic_stats_border, port_id, nic_stats_border);
269 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
270 "%-"PRIu64"\n", stats.ipackets, stats.imissed, stats.ibytes);
271 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
272 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
273 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
274 "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
277 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
280 ns = cur_time.tv_sec * NS_PER_SEC;
281 ns += cur_time.tv_nsec;
283 if (prev_ns[port_id] != 0)
284 diff_ns = ns - prev_ns[port_id];
285 prev_ns[port_id] = ns;
288 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
289 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
290 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
291 (stats.opackets - prev_pkts_tx[port_id]) : 0;
292 prev_pkts_rx[port_id] = stats.ipackets;
293 prev_pkts_tx[port_id] = stats.opackets;
294 mpps_rx = diff_ns > 0 ?
295 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
296 mpps_tx = diff_ns > 0 ?
297 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
299 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
300 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
301 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
302 (stats.obytes - prev_bytes_tx[port_id]) : 0;
303 prev_bytes_rx[port_id] = stats.ibytes;
304 prev_bytes_tx[port_id] = stats.obytes;
305 mbps_rx = diff_ns > 0 ?
306 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
307 mbps_tx = diff_ns > 0 ?
308 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
310 printf("\n Throughput (since last show)\n");
311 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
312 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
313 mpps_tx, mbps_tx * 8);
315 if (xstats_display_num > 0)
316 nic_xstats_display_periodic(port_id);
318 printf(" %s############################%s\n",
319 nic_stats_border, nic_stats_border);
323 nic_stats_clear(portid_t port_id)
327 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
332 ret = rte_eth_stats_reset(port_id);
335 "%s: Error: failed to reset stats (port %u): %s",
336 __func__, port_id, strerror(-ret));
340 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
345 "%s: Error: failed to get stats (port %u): %s",
346 __func__, port_id, strerror(ret));
349 printf("\n NIC statistics for port %d cleared\n", port_id);
353 nic_xstats_display(portid_t port_id)
355 struct rte_eth_xstat *xstats;
356 int cnt_xstats, idx_xstat;
357 struct rte_eth_xstat_name *xstats_names;
359 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
363 printf("###### NIC extended statistics for port %-2d\n", port_id);
364 if (!rte_eth_dev_is_valid_port(port_id)) {
365 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
370 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
371 if (cnt_xstats < 0) {
372 fprintf(stderr, "Error: Cannot get count of xstats\n");
376 /* Get id-name lookup table */
377 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
378 if (xstats_names == NULL) {
379 fprintf(stderr, "Cannot allocate memory for xstats lookup\n");
382 if (cnt_xstats != rte_eth_xstats_get_names(
383 port_id, xstats_names, cnt_xstats)) {
384 fprintf(stderr, "Error: Cannot get xstats lookup\n");
389 /* Get stats themselves */
390 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
391 if (xstats == NULL) {
392 fprintf(stderr, "Cannot allocate memory for xstats\n");
396 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
397 fprintf(stderr, "Error: Unable to get xstats\n");
404 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
405 if (xstats_hide_zero && !xstats[idx_xstat].value)
407 printf("%s: %"PRIu64"\n",
408 xstats_names[idx_xstat].name,
409 xstats[idx_xstat].value);
416 nic_xstats_clear(portid_t port_id)
420 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
425 ret = rte_eth_xstats_reset(port_id);
428 "%s: Error: failed to reset xstats (port %u): %s\n",
429 __func__, port_id, strerror(-ret));
433 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
437 fprintf(stderr, "%s: Error: failed to get stats (port %u): %s",
438 __func__, port_id, strerror(ret));
444 get_queue_state_name(uint8_t queue_state)
446 if (queue_state == RTE_ETH_QUEUE_STATE_STOPPED)
448 else if (queue_state == RTE_ETH_QUEUE_STATE_STARTED)
450 else if (queue_state == RTE_ETH_QUEUE_STATE_HAIRPIN)
457 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
459 struct rte_eth_burst_mode mode;
460 struct rte_eth_rxq_info qinfo;
462 static const char *info_border = "*********************";
464 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
467 "Failed to retrieve information for port: %u, RX queue: %hu\nerror desc: %s(%d)\n",
468 port_id, queue_id, strerror(-rc), rc);
472 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
473 info_border, port_id, queue_id, info_border);
475 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
476 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
477 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
478 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
479 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
480 printf("\nRX drop packets: %s",
481 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
482 printf("\nRX deferred start: %s",
483 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
484 printf("\nRX scattered packets: %s",
485 (qinfo.scattered_rx != 0) ? "on" : "off");
486 printf("\nRx queue state: %s", get_queue_state_name(qinfo.queue_state));
487 if (qinfo.rx_buf_size != 0)
488 printf("\nRX buffer size: %hu", qinfo.rx_buf_size);
489 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
491 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
492 printf("\nBurst mode: %s%s",
494 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
495 " (per queue)" : "");
501 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
503 struct rte_eth_burst_mode mode;
504 struct rte_eth_txq_info qinfo;
506 static const char *info_border = "*********************";
508 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
511 "Failed to retrieve information for port: %u, TX queue: %hu\nerror desc: %s(%d)\n",
512 port_id, queue_id, strerror(-rc), rc);
516 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
517 info_border, port_id, queue_id, info_border);
519 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
520 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
521 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
522 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
523 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
524 printf("\nTX deferred start: %s",
525 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
526 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
527 printf("\nTx queue state: %s", get_queue_state_name(qinfo.queue_state));
529 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
530 printf("\nBurst mode: %s%s",
532 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
533 " (per queue)" : "");
538 static int bus_match_all(const struct rte_bus *bus, const void *data)
546 device_infos_display_speeds(uint32_t speed_capa)
548 printf("\n\tDevice speed capability:");
549 if (speed_capa == RTE_ETH_LINK_SPEED_AUTONEG)
550 printf(" Autonegotiate (all speeds)");
551 if (speed_capa & RTE_ETH_LINK_SPEED_FIXED)
552 printf(" Disable autonegotiate (fixed speed) ");
553 if (speed_capa & RTE_ETH_LINK_SPEED_10M_HD)
554 printf(" 10 Mbps half-duplex ");
555 if (speed_capa & RTE_ETH_LINK_SPEED_10M)
556 printf(" 10 Mbps full-duplex ");
557 if (speed_capa & RTE_ETH_LINK_SPEED_100M_HD)
558 printf(" 100 Mbps half-duplex ");
559 if (speed_capa & RTE_ETH_LINK_SPEED_100M)
560 printf(" 100 Mbps full-duplex ");
561 if (speed_capa & RTE_ETH_LINK_SPEED_1G)
563 if (speed_capa & RTE_ETH_LINK_SPEED_2_5G)
564 printf(" 2.5 Gbps ");
565 if (speed_capa & RTE_ETH_LINK_SPEED_5G)
567 if (speed_capa & RTE_ETH_LINK_SPEED_10G)
569 if (speed_capa & RTE_ETH_LINK_SPEED_20G)
571 if (speed_capa & RTE_ETH_LINK_SPEED_25G)
573 if (speed_capa & RTE_ETH_LINK_SPEED_40G)
575 if (speed_capa & RTE_ETH_LINK_SPEED_50G)
577 if (speed_capa & RTE_ETH_LINK_SPEED_56G)
579 if (speed_capa & RTE_ETH_LINK_SPEED_100G)
580 printf(" 100 Gbps ");
581 if (speed_capa & RTE_ETH_LINK_SPEED_200G)
582 printf(" 200 Gbps ");
586 device_infos_display(const char *identifier)
588 static const char *info_border = "*********************";
589 struct rte_bus *start = NULL, *next;
590 struct rte_dev_iterator dev_iter;
591 char name[RTE_ETH_NAME_MAX_LEN];
592 struct rte_ether_addr mac_addr;
593 struct rte_device *dev;
594 struct rte_devargs da;
596 struct rte_eth_dev_info dev_info;
599 memset(&da, 0, sizeof(da));
603 if (rte_devargs_parsef(&da, "%s", identifier)) {
604 fprintf(stderr, "cannot parse identifier\n");
609 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
612 if (identifier && da.bus != next)
615 /* Skip buses that don't have iterate method */
616 if (!next->dev_iterate)
619 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
620 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
624 /* Check for matching device if identifier is present */
626 strncmp(da.name, dev->name, strlen(dev->name)))
628 printf("\n%s Infos for device %s %s\n",
629 info_border, dev->name, info_border);
630 printf("Bus name: %s", dev->bus->name);
631 printf("\nDriver name: %s", dev->driver->name);
632 printf("\nDevargs: %s",
633 dev->devargs ? dev->devargs->args : "");
634 printf("\nConnect to socket: %d", dev->numa_node);
637 /* List ports with matching device name */
638 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
639 printf("\n\tPort id: %-2d", port_id);
640 if (eth_macaddr_get_print_err(port_id,
642 print_ethaddr("\n\tMAC address: ",
644 rte_eth_dev_get_name_by_port(port_id, name);
645 printf("\n\tDevice name: %s", name);
646 if (rte_eth_dev_info_get(port_id, &dev_info) == 0)
647 device_infos_display_speeds(dev_info.speed_capa);
652 rte_devargs_reset(&da);
656 print_dev_capabilities(uint64_t capabilities)
658 uint64_t single_capa;
663 if (capabilities == 0)
666 begin = __builtin_ctzll(capabilities);
667 end = sizeof(capabilities) * CHAR_BIT - __builtin_clzll(capabilities);
669 single_capa = 1ULL << begin;
670 for (bit = begin; bit < end; bit++) {
671 if (capabilities & single_capa)
673 rte_eth_dev_capability_name(single_capa));
679 port_infos_display(portid_t port_id)
681 struct rte_port *port;
682 struct rte_ether_addr mac_addr;
683 struct rte_eth_link link;
684 struct rte_eth_dev_info dev_info;
686 struct rte_mempool * mp;
687 static const char *info_border = "*********************";
689 char name[RTE_ETH_NAME_MAX_LEN];
691 char fw_version[ETHDEV_FWVERS_LEN];
693 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
697 port = &ports[port_id];
698 ret = eth_link_get_nowait_print_err(port_id, &link);
702 ret = eth_dev_info_get_print_err(port_id, &dev_info);
706 printf("\n%s Infos for port %-2d %s\n",
707 info_border, port_id, info_border);
708 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
709 print_ethaddr("MAC address: ", &mac_addr);
710 rte_eth_dev_get_name_by_port(port_id, name);
711 printf("\nDevice name: %s", name);
712 printf("\nDriver name: %s", dev_info.driver_name);
714 if (rte_eth_dev_fw_version_get(port_id, fw_version,
715 ETHDEV_FWVERS_LEN) == 0)
716 printf("\nFirmware-version: %s", fw_version);
718 printf("\nFirmware-version: %s", "not available");
720 if (dev_info.device->devargs && dev_info.device->devargs->args)
721 printf("\nDevargs: %s", dev_info.device->devargs->args);
722 printf("\nConnect to socket: %u", port->socket_id);
724 if (port_numa[port_id] != NUMA_NO_CONFIG) {
725 mp = mbuf_pool_find(port_numa[port_id], 0);
727 printf("\nmemory allocation on the socket: %d",
730 printf("\nmemory allocation on the socket: %u",port->socket_id);
732 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
733 printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
734 printf("Link duplex: %s\n", (link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
735 ("full-duplex") : ("half-duplex"));
736 printf("Autoneg status: %s\n", (link.link_autoneg == RTE_ETH_LINK_AUTONEG) ?
739 if (!rte_eth_dev_get_mtu(port_id, &mtu))
740 printf("MTU: %u\n", mtu);
742 printf("Promiscuous mode: %s\n",
743 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
744 printf("Allmulticast mode: %s\n",
745 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
746 printf("Maximum number of MAC addresses: %u\n",
747 (unsigned int)(port->dev_info.max_mac_addrs));
748 printf("Maximum number of MAC addresses of hash filtering: %u\n",
749 (unsigned int)(port->dev_info.max_hash_mac_addrs));
751 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
752 if (vlan_offload >= 0){
753 printf("VLAN offload: \n");
754 if (vlan_offload & RTE_ETH_VLAN_STRIP_OFFLOAD)
755 printf(" strip on, ");
757 printf(" strip off, ");
759 if (vlan_offload & RTE_ETH_VLAN_FILTER_OFFLOAD)
760 printf("filter on, ");
762 printf("filter off, ");
764 if (vlan_offload & RTE_ETH_VLAN_EXTEND_OFFLOAD)
765 printf("extend on, ");
767 printf("extend off, ");
769 if (vlan_offload & RTE_ETH_QINQ_STRIP_OFFLOAD)
770 printf("qinq strip on\n");
772 printf("qinq strip off\n");
775 if (dev_info.hash_key_size > 0)
776 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
777 if (dev_info.reta_size > 0)
778 printf("Redirection table size: %u\n", dev_info.reta_size);
779 if (!dev_info.flow_type_rss_offloads)
780 printf("No RSS offload flow type is supported.\n");
785 printf("Supported RSS offload flow types:\n");
786 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
787 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
788 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
790 p = flowtype_to_str(i);
794 printf(" user defined %d\n", i);
798 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
799 printf("Maximum configurable length of RX packet: %u\n",
800 dev_info.max_rx_pktlen);
801 printf("Maximum configurable size of LRO aggregated packet: %u\n",
802 dev_info.max_lro_pkt_size);
803 if (dev_info.max_vfs)
804 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
805 if (dev_info.max_vmdq_pools)
806 printf("Maximum number of VMDq pools: %u\n",
807 dev_info.max_vmdq_pools);
809 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
810 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
811 printf("Max possible number of RXDs per queue: %hu\n",
812 dev_info.rx_desc_lim.nb_max);
813 printf("Min possible number of RXDs per queue: %hu\n",
814 dev_info.rx_desc_lim.nb_min);
815 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
817 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
818 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
819 printf("Max possible number of TXDs per queue: %hu\n",
820 dev_info.tx_desc_lim.nb_max);
821 printf("Min possible number of TXDs per queue: %hu\n",
822 dev_info.tx_desc_lim.nb_min);
823 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
824 printf("Max segment number per packet: %hu\n",
825 dev_info.tx_desc_lim.nb_seg_max);
826 printf("Max segment number per MTU/TSO: %hu\n",
827 dev_info.tx_desc_lim.nb_mtu_seg_max);
829 printf("Device capabilities: 0x%"PRIx64"(", dev_info.dev_capa);
830 print_dev_capabilities(dev_info.dev_capa);
832 /* Show switch info only if valid switch domain and port id is set */
833 if (dev_info.switch_info.domain_id !=
834 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
835 if (dev_info.switch_info.name)
836 printf("Switch name: %s\n", dev_info.switch_info.name);
838 printf("Switch domain Id: %u\n",
839 dev_info.switch_info.domain_id);
840 printf("Switch Port Id: %u\n",
841 dev_info.switch_info.port_id);
842 if ((dev_info.dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE) != 0)
843 printf("Switch Rx domain: %u\n",
844 dev_info.switch_info.rx_domain);
849 port_summary_header_display(void)
851 uint16_t port_number;
853 port_number = rte_eth_dev_count_avail();
854 printf("Number of available ports: %i\n", port_number);
855 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
856 "Driver", "Status", "Link");
860 port_summary_display(portid_t port_id)
862 struct rte_ether_addr mac_addr;
863 struct rte_eth_link link;
864 struct rte_eth_dev_info dev_info;
865 char name[RTE_ETH_NAME_MAX_LEN];
868 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
873 ret = eth_link_get_nowait_print_err(port_id, &link);
877 ret = eth_dev_info_get_print_err(port_id, &dev_info);
881 rte_eth_dev_get_name_by_port(port_id, name);
882 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
886 printf("%-4d " RTE_ETHER_ADDR_PRT_FMT " %-12s %-14s %-8s %s\n",
887 port_id, RTE_ETHER_ADDR_BYTES(&mac_addr), name,
888 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
889 rte_eth_link_speed_to_str(link.link_speed));
893 port_eeprom_display(portid_t port_id)
895 struct rte_dev_eeprom_info einfo;
897 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
902 int len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
903 if (len_eeprom < 0) {
904 switch (len_eeprom) {
906 fprintf(stderr, "port index %d invalid\n", port_id);
909 fprintf(stderr, "operation not supported by device\n");
912 fprintf(stderr, "device is removed\n");
915 fprintf(stderr, "Unable to get EEPROM: %d\n",
923 einfo.length = len_eeprom;
924 einfo.data = calloc(1, len_eeprom);
927 "Allocation of port %u eeprom data failed\n",
932 ret = rte_eth_dev_get_eeprom(port_id, &einfo);
936 fprintf(stderr, "port index %d invalid\n", port_id);
939 fprintf(stderr, "operation not supported by device\n");
942 fprintf(stderr, "device is removed\n");
945 fprintf(stderr, "Unable to get EEPROM: %d\n", ret);
951 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
952 printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
957 port_module_eeprom_display(portid_t port_id)
959 struct rte_eth_dev_module_info minfo;
960 struct rte_dev_eeprom_info einfo;
963 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
969 ret = rte_eth_dev_get_module_info(port_id, &minfo);
973 fprintf(stderr, "port index %d invalid\n", port_id);
976 fprintf(stderr, "operation not supported by device\n");
979 fprintf(stderr, "device is removed\n");
982 fprintf(stderr, "Unable to get module EEPROM: %d\n",
990 einfo.length = minfo.eeprom_len;
991 einfo.data = calloc(1, minfo.eeprom_len);
994 "Allocation of port %u eeprom data failed\n",
999 ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
1003 fprintf(stderr, "port index %d invalid\n", port_id);
1006 fprintf(stderr, "operation not supported by device\n");
1009 fprintf(stderr, "device is removed\n");
1012 fprintf(stderr, "Unable to get module EEPROM: %d\n",
1020 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
1021 printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
1026 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1030 if (port_id == (portid_t)RTE_PORT_ALL)
1033 RTE_ETH_FOREACH_DEV(pid)
1037 if (warning == ENABLED_WARN)
1038 fprintf(stderr, "Invalid port %d\n", port_id);
1043 void print_valid_ports(void)
1047 printf("The valid ports array is [");
1048 RTE_ETH_FOREACH_DEV(pid) {
1055 vlan_id_is_invalid(uint16_t vlan_id)
1059 fprintf(stderr, "Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1064 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1066 const struct rte_pci_device *pci_dev;
1067 const struct rte_bus *bus;
1070 if (reg_off & 0x3) {
1072 "Port register offset 0x%X not aligned on a 4-byte boundary\n",
1073 (unsigned int)reg_off);
1077 if (!ports[port_id].dev_info.device) {
1078 fprintf(stderr, "Invalid device\n");
1082 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1083 if (bus && !strcmp(bus->name, "pci")) {
1084 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1086 fprintf(stderr, "Not a PCI device\n");
1090 pci_len = pci_dev->mem_resource[0].len;
1091 if (reg_off >= pci_len) {
1093 "Port %d: register offset %u (0x%X) out of port PCI resource (length=%"PRIu64")\n",
1094 port_id, (unsigned int)reg_off, (unsigned int)reg_off,
1102 reg_bit_pos_is_invalid(uint8_t bit_pos)
1106 fprintf(stderr, "Invalid bit position %d (must be <= 31)\n", bit_pos);
1110 #define display_port_and_reg_off(port_id, reg_off) \
1111 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1114 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1116 display_port_and_reg_off(port_id, (unsigned)reg_off);
1117 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1121 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1126 if (port_id_is_invalid(port_id, ENABLED_WARN))
1128 if (port_reg_off_is_invalid(port_id, reg_off))
1130 if (reg_bit_pos_is_invalid(bit_x))
1132 reg_v = port_id_pci_reg_read(port_id, reg_off);
1133 display_port_and_reg_off(port_id, (unsigned)reg_off);
1134 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1138 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1139 uint8_t bit1_pos, uint8_t bit2_pos)
1145 if (port_id_is_invalid(port_id, ENABLED_WARN))
1147 if (port_reg_off_is_invalid(port_id, reg_off))
1149 if (reg_bit_pos_is_invalid(bit1_pos))
1151 if (reg_bit_pos_is_invalid(bit2_pos))
1153 if (bit1_pos > bit2_pos)
1154 l_bit = bit2_pos, h_bit = bit1_pos;
1156 l_bit = bit1_pos, h_bit = bit2_pos;
1158 reg_v = port_id_pci_reg_read(port_id, reg_off);
1161 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1162 display_port_and_reg_off(port_id, (unsigned)reg_off);
1163 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1164 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1168 port_reg_display(portid_t port_id, uint32_t reg_off)
1172 if (port_id_is_invalid(port_id, ENABLED_WARN))
1174 if (port_reg_off_is_invalid(port_id, reg_off))
1176 reg_v = port_id_pci_reg_read(port_id, reg_off);
1177 display_port_reg_value(port_id, reg_off, reg_v);
1181 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1186 if (port_id_is_invalid(port_id, ENABLED_WARN))
1188 if (port_reg_off_is_invalid(port_id, reg_off))
1190 if (reg_bit_pos_is_invalid(bit_pos))
1193 fprintf(stderr, "Invalid bit value %d (must be 0 or 1)\n",
1197 reg_v = port_id_pci_reg_read(port_id, reg_off);
1199 reg_v &= ~(1 << bit_pos);
1201 reg_v |= (1 << bit_pos);
1202 port_id_pci_reg_write(port_id, reg_off, reg_v);
1203 display_port_reg_value(port_id, reg_off, reg_v);
1207 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1208 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1215 if (port_id_is_invalid(port_id, ENABLED_WARN))
1217 if (port_reg_off_is_invalid(port_id, reg_off))
1219 if (reg_bit_pos_is_invalid(bit1_pos))
1221 if (reg_bit_pos_is_invalid(bit2_pos))
1223 if (bit1_pos > bit2_pos)
1224 l_bit = bit2_pos, h_bit = bit1_pos;
1226 l_bit = bit1_pos, h_bit = bit2_pos;
1228 if ((h_bit - l_bit) < 31)
1229 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1233 if (value > max_v) {
1234 fprintf(stderr, "Invalid value %u (0x%x) must be < %u (0x%x)\n",
1235 (unsigned)value, (unsigned)value,
1236 (unsigned)max_v, (unsigned)max_v);
1239 reg_v = port_id_pci_reg_read(port_id, reg_off);
1240 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1241 reg_v |= (value << l_bit); /* Set changed bits */
1242 port_id_pci_reg_write(port_id, reg_off, reg_v);
1243 display_port_reg_value(port_id, reg_off, reg_v);
1247 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1249 if (port_id_is_invalid(port_id, ENABLED_WARN))
1251 if (port_reg_off_is_invalid(port_id, reg_off))
1253 port_id_pci_reg_write(port_id, reg_off, reg_v);
1254 display_port_reg_value(port_id, reg_off, reg_v);
1258 port_mtu_set(portid_t port_id, uint16_t mtu)
1260 struct rte_port *port = &ports[port_id];
1263 if (port_id_is_invalid(port_id, ENABLED_WARN))
1266 if (port->need_reconfig == 0) {
1267 diag = rte_eth_dev_set_mtu(port_id, mtu);
1269 fprintf(stderr, "Set MTU failed. diag=%d\n", diag);
1274 port->dev_conf.rxmode.mtu = mtu;
1277 /* Generic flow management functions. */
1279 static struct port_flow_tunnel *
1280 port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
1282 struct port_flow_tunnel *flow_tunnel;
1284 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1285 if (flow_tunnel->id == port_tunnel_id)
1295 port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
1298 switch (tunnel->type) {
1302 case RTE_FLOW_ITEM_TYPE_VXLAN:
1305 case RTE_FLOW_ITEM_TYPE_GRE:
1308 case RTE_FLOW_ITEM_TYPE_NVGRE:
1311 case RTE_FLOW_ITEM_TYPE_GENEVE:
1319 struct port_flow_tunnel *
1320 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
1322 struct rte_port *port = &ports[port_id];
1323 struct port_flow_tunnel *flow_tunnel;
1325 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1326 if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
1335 void port_flow_tunnel_list(portid_t port_id)
1337 struct rte_port *port = &ports[port_id];
1338 struct port_flow_tunnel *flt;
1340 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1341 printf("port %u tunnel #%u type=%s",
1342 port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
1343 if (flt->tunnel.tun_id)
1344 printf(" id=%" PRIu64, flt->tunnel.tun_id);
1349 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
1351 struct rte_port *port = &ports[port_id];
1352 struct port_flow_tunnel *flt;
1354 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1355 if (flt->id == tunnel_id)
1359 LIST_REMOVE(flt, chain);
1361 printf("port %u: flow tunnel #%u destroyed\n",
1362 port_id, tunnel_id);
1366 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
1368 struct rte_port *port = &ports[port_id];
1369 enum rte_flow_item_type type;
1370 struct port_flow_tunnel *flt;
1372 if (!strcmp(ops->type, "vxlan"))
1373 type = RTE_FLOW_ITEM_TYPE_VXLAN;
1374 else if (!strcmp(ops->type, "gre"))
1375 type = RTE_FLOW_ITEM_TYPE_GRE;
1376 else if (!strcmp(ops->type, "nvgre"))
1377 type = RTE_FLOW_ITEM_TYPE_NVGRE;
1378 else if (!strcmp(ops->type, "geneve"))
1379 type = RTE_FLOW_ITEM_TYPE_GENEVE;
1381 fprintf(stderr, "cannot offload \"%s\" tunnel type\n",
1385 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1386 if (flt->tunnel.type == type)
1390 flt = calloc(1, sizeof(*flt));
1392 fprintf(stderr, "failed to allocate port flt object\n");
1395 flt->tunnel.type = type;
1396 flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
1397 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
1398 LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
1400 printf("port %d: flow tunnel #%u type %s\n",
1401 port_id, flt->id, ops->type);
1404 /** Generate a port_flow entry from attributes/pattern/actions. */
1405 static struct port_flow *
1406 port_flow_new(const struct rte_flow_attr *attr,
1407 const struct rte_flow_item *pattern,
1408 const struct rte_flow_action *actions,
1409 struct rte_flow_error *error)
1411 const struct rte_flow_conv_rule rule = {
1413 .pattern_ro = pattern,
1414 .actions_ro = actions,
1416 struct port_flow *pf;
1419 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1422 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1425 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1429 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1436 /** Print a message out of a flow error. */
1438 port_flow_complain(struct rte_flow_error *error)
1440 static const char *const errstrlist[] = {
1441 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1442 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1443 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1444 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1445 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1446 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1447 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1448 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1449 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1450 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1451 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1452 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1453 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1454 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1455 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1456 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1457 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1461 int err = rte_errno;
1463 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1464 !errstrlist[error->type])
1465 errstr = "unknown type";
1467 errstr = errstrlist[error->type];
1468 fprintf(stderr, "%s(): Caught PMD error type %d (%s): %s%s: %s\n",
1469 __func__, error->type, errstr,
1470 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1471 error->cause), buf) : "",
1472 error->message ? error->message : "(no stated reason)",
1475 switch (error->type) {
1476 case RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER:
1477 fprintf(stderr, "The status suggests the use of \"transfer\" "
1478 "as the possible cause of the failure. Make "
1479 "sure that the flow in question and its "
1480 "indirect components (if any) are managed "
1481 "via \"transfer\" proxy port. Use command "
1482 "\"show port (port_id) flow transfer proxy\" "
1483 "to figure out the proxy port ID\n");
1493 rss_config_display(struct rte_flow_action_rss *rss_conf)
1497 if (rss_conf == NULL) {
1498 fprintf(stderr, "Invalid rule\n");
1504 if (rss_conf->queue_num == 0)
1506 for (i = 0; i < rss_conf->queue_num; i++)
1507 printf(" %d", rss_conf->queue[i]);
1510 printf(" function: ");
1511 switch (rss_conf->func) {
1512 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1513 printf("default\n");
1515 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1516 printf("toeplitz\n");
1518 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1519 printf("simple_xor\n");
1521 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1522 printf("symmetric_toeplitz\n");
1525 printf("Unknown function\n");
1529 printf(" types:\n");
1530 if (rss_conf->types == 0) {
1534 for (i = 0; rss_type_table[i].str; i++) {
1535 if ((rss_conf->types &
1536 rss_type_table[i].rss_type) ==
1537 rss_type_table[i].rss_type &&
1538 rss_type_table[i].rss_type != 0)
1539 printf(" %s\n", rss_type_table[i].str);
1543 static struct port_indirect_action *
1544 action_get_by_id(portid_t port_id, uint32_t id)
1546 struct rte_port *port;
1547 struct port_indirect_action **ppia;
1548 struct port_indirect_action *pia = NULL;
1550 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1551 port_id == (portid_t)RTE_PORT_ALL)
1553 port = &ports[port_id];
1554 ppia = &port->actions_list;
1556 if ((*ppia)->id == id) {
1560 ppia = &(*ppia)->next;
1564 "Failed to find indirect action #%u on port %u\n",
1570 action_alloc(portid_t port_id, uint32_t id,
1571 struct port_indirect_action **action)
1573 struct rte_port *port;
1574 struct port_indirect_action **ppia;
1575 struct port_indirect_action *pia = NULL;
1578 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1579 port_id == (portid_t)RTE_PORT_ALL)
1581 port = &ports[port_id];
1582 if (id == UINT32_MAX) {
1583 /* taking first available ID */
1584 if (port->actions_list) {
1585 if (port->actions_list->id == UINT32_MAX - 1) {
1587 "Highest indirect action ID is already assigned, delete it first\n");
1590 id = port->actions_list->id + 1;
1595 pia = calloc(1, sizeof(*pia));
1598 "Allocation of port %u indirect action failed\n",
1602 ppia = &port->actions_list;
1603 while (*ppia && (*ppia)->id > id)
1604 ppia = &(*ppia)->next;
1605 if (*ppia && (*ppia)->id == id) {
1607 "Indirect action #%u is already assigned, delete it first\n",
1620 template_alloc(uint32_t id, struct port_template **template,
1621 struct port_template **list)
1623 struct port_template *lst = *list;
1624 struct port_template **ppt;
1625 struct port_template *pt = NULL;
1628 if (id == UINT32_MAX) {
1629 /* taking first available ID */
1631 if (lst->id == UINT32_MAX - 1) {
1632 printf("Highest template ID is already"
1633 " assigned, delete it first\n");
1641 pt = calloc(1, sizeof(*pt));
1643 printf("Allocation of port template failed\n");
1647 while (*ppt && (*ppt)->id > id)
1648 ppt = &(*ppt)->next;
1649 if (*ppt && (*ppt)->id == id) {
1650 printf("Template #%u is already assigned,"
1651 " delete it first\n", id);
1663 table_alloc(uint32_t id, struct port_table **table,
1664 struct port_table **list)
1666 struct port_table *lst = *list;
1667 struct port_table **ppt;
1668 struct port_table *pt = NULL;
1671 if (id == UINT32_MAX) {
1672 /* taking first available ID */
1674 if (lst->id == UINT32_MAX - 1) {
1675 printf("Highest table ID is already"
1676 " assigned, delete it first\n");
1684 pt = calloc(1, sizeof(*pt));
1686 printf("Allocation of table failed\n");
1690 while (*ppt && (*ppt)->id > id)
1691 ppt = &(*ppt)->next;
1692 if (*ppt && (*ppt)->id == id) {
1693 printf("Table #%u is already assigned,"
1694 " delete it first\n", id);
1705 /** Get info about flow management resources. */
1707 port_flow_get_info(portid_t port_id)
1709 struct rte_flow_port_info port_info;
1710 struct rte_flow_queue_info queue_info;
1711 struct rte_flow_error error;
1713 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1714 port_id == (portid_t)RTE_PORT_ALL)
1716 /* Poisoning to make sure PMDs update it in case of error. */
1717 memset(&error, 0x99, sizeof(error));
1718 memset(&port_info, 0, sizeof(port_info));
1719 memset(&queue_info, 0, sizeof(queue_info));
1720 if (rte_flow_info_get(port_id, &port_info, &queue_info, &error))
1721 return port_flow_complain(&error);
1722 printf("Flow engine resources on port %u:\n"
1723 "Number of queues: %d\n"
1724 "Size of queues: %d\n"
1725 "Number of counters: %d\n"
1726 "Number of aging objects: %d\n"
1727 "Number of meter actions: %d\n",
1728 port_id, port_info.max_nb_queues,
1729 queue_info.max_size,
1730 port_info.max_nb_counters,
1731 port_info.max_nb_aging_objects,
1732 port_info.max_nb_meters);
1736 /** Configure flow management resources. */
1738 port_flow_configure(portid_t port_id,
1739 const struct rte_flow_port_attr *port_attr,
1741 const struct rte_flow_queue_attr *queue_attr)
1743 struct rte_port *port;
1744 struct rte_flow_error error;
1745 const struct rte_flow_queue_attr *attr_list[nb_queue];
1748 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1749 port_id == (portid_t)RTE_PORT_ALL)
1751 port = &ports[port_id];
1752 port->queue_nb = nb_queue;
1753 port->queue_sz = queue_attr->size;
1754 for (std_queue = 0; std_queue < nb_queue; std_queue++)
1755 attr_list[std_queue] = queue_attr;
1756 /* Poisoning to make sure PMDs update it in case of error. */
1757 memset(&error, 0x66, sizeof(error));
1758 if (rte_flow_configure(port_id, port_attr, nb_queue, attr_list, &error))
1759 return port_flow_complain(&error);
1760 printf("Configure flows on port %u: "
1761 "number of queues %d with %d elements\n",
1762 port_id, nb_queue, queue_attr->size);
1766 /** Create indirect action */
1768 port_action_handle_create(portid_t port_id, uint32_t id,
1769 const struct rte_flow_indir_action_conf *conf,
1770 const struct rte_flow_action *action)
1772 struct port_indirect_action *pia;
1774 struct rte_flow_error error;
1776 ret = action_alloc(port_id, id, &pia);
1779 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
1780 struct rte_flow_action_age *age =
1781 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
1783 pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
1784 age->context = &pia->age_type;
1785 } else if (action->type == RTE_FLOW_ACTION_TYPE_CONNTRACK) {
1786 struct rte_flow_action_conntrack *ct =
1787 (struct rte_flow_action_conntrack *)(uintptr_t)(action->conf);
1789 memcpy(ct, &conntrack_context, sizeof(*ct));
1791 /* Poisoning to make sure PMDs update it in case of error. */
1792 memset(&error, 0x22, sizeof(error));
1793 pia->handle = rte_flow_action_handle_create(port_id, conf, action,
1796 uint32_t destroy_id = pia->id;
1797 port_action_handle_destroy(port_id, 1, &destroy_id);
1798 return port_flow_complain(&error);
1800 pia->type = action->type;
1801 printf("Indirect action #%u created\n", pia->id);
1805 /** Destroy indirect action */
1807 port_action_handle_destroy(portid_t port_id,
1809 const uint32_t *actions)
1811 struct rte_port *port;
1812 struct port_indirect_action **tmp;
1816 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1817 port_id == (portid_t)RTE_PORT_ALL)
1819 port = &ports[port_id];
1820 tmp = &port->actions_list;
1824 for (i = 0; i != n; ++i) {
1825 struct rte_flow_error error;
1826 struct port_indirect_action *pia = *tmp;
1828 if (actions[i] != pia->id)
1831 * Poisoning to make sure PMDs update it in case
1834 memset(&error, 0x33, sizeof(error));
1836 if (pia->handle && rte_flow_action_handle_destroy(
1837 port_id, pia->handle, &error)) {
1838 ret = port_flow_complain(&error);
1842 printf("Indirect action #%u destroyed\n", pia->id);
1847 tmp = &(*tmp)->next;
1854 /** Get indirect action by port + id */
1855 struct rte_flow_action_handle *
1856 port_action_handle_get_by_id(portid_t port_id, uint32_t id)
1859 struct port_indirect_action *pia = action_get_by_id(port_id, id);
1861 return (pia) ? pia->handle : NULL;
1864 /** Update indirect action */
1866 port_action_handle_update(portid_t port_id, uint32_t id,
1867 const struct rte_flow_action *action)
1869 struct rte_flow_error error;
1870 struct rte_flow_action_handle *action_handle;
1871 struct port_indirect_action *pia;
1874 action_handle = port_action_handle_get_by_id(port_id, id);
1877 pia = action_get_by_id(port_id, id);
1880 switch (pia->type) {
1881 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1882 update = action->conf;
1888 if (rte_flow_action_handle_update(port_id, action_handle, update,
1890 return port_flow_complain(&error);
1892 printf("Indirect action #%u updated\n", id);
1897 port_action_handle_query(portid_t port_id, uint32_t id)
1899 struct rte_flow_error error;
1900 struct port_indirect_action *pia;
1902 struct rte_flow_query_count count;
1903 struct rte_flow_query_age age;
1904 struct rte_flow_action_conntrack ct;
1907 pia = action_get_by_id(port_id, id);
1910 switch (pia->type) {
1911 case RTE_FLOW_ACTION_TYPE_AGE:
1912 case RTE_FLOW_ACTION_TYPE_COUNT:
1916 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1917 id, pia->type, port_id);
1920 /* Poisoning to make sure PMDs update it in case of error. */
1921 memset(&error, 0x55, sizeof(error));
1922 memset(&query, 0, sizeof(query));
1923 if (rte_flow_action_handle_query(port_id, pia->handle, &query, &error))
1924 return port_flow_complain(&error);
1925 switch (pia->type) {
1926 case RTE_FLOW_ACTION_TYPE_AGE:
1927 printf("Indirect AGE action:\n"
1929 " sec_since_last_hit_valid: %u\n"
1930 " sec_since_last_hit: %" PRIu32 "\n",
1932 query.age.sec_since_last_hit_valid,
1933 query.age.sec_since_last_hit);
1935 case RTE_FLOW_ACTION_TYPE_COUNT:
1936 printf("Indirect COUNT action:\n"
1939 " hits: %" PRIu64 "\n"
1940 " bytes: %" PRIu64 "\n",
1941 query.count.hits_set,
1942 query.count.bytes_set,
1946 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1947 printf("Conntrack Context:\n"
1948 " Peer: %u, Flow dir: %s, Enable: %u\n"
1949 " Live: %u, SACK: %u, CACK: %u\n"
1950 " Packet dir: %s, Liberal: %u, State: %u\n"
1951 " Factor: %u, Retrans: %u, TCP flags: %u\n"
1952 " Last Seq: %u, Last ACK: %u\n"
1953 " Last Win: %u, Last End: %u\n",
1955 query.ct.is_original_dir ? "Original" : "Reply",
1956 query.ct.enable, query.ct.live_connection,
1957 query.ct.selective_ack, query.ct.challenge_ack_passed,
1958 query.ct.last_direction ? "Original" : "Reply",
1959 query.ct.liberal_mode, query.ct.state,
1960 query.ct.max_ack_window, query.ct.retransmission_limit,
1961 query.ct.last_index, query.ct.last_seq,
1962 query.ct.last_ack, query.ct.last_window,
1964 printf(" Original Dir:\n"
1965 " scale: %u, fin: %u, ack seen: %u\n"
1966 " unacked data: %u\n Sent end: %u,"
1967 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1968 query.ct.original_dir.scale,
1969 query.ct.original_dir.close_initiated,
1970 query.ct.original_dir.last_ack_seen,
1971 query.ct.original_dir.data_unacked,
1972 query.ct.original_dir.sent_end,
1973 query.ct.original_dir.reply_end,
1974 query.ct.original_dir.max_win,
1975 query.ct.original_dir.max_ack);
1976 printf(" Reply Dir:\n"
1977 " scale: %u, fin: %u, ack seen: %u\n"
1978 " unacked data: %u\n Sent end: %u,"
1979 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1980 query.ct.reply_dir.scale,
1981 query.ct.reply_dir.close_initiated,
1982 query.ct.reply_dir.last_ack_seen,
1983 query.ct.reply_dir.data_unacked,
1984 query.ct.reply_dir.sent_end,
1985 query.ct.reply_dir.reply_end,
1986 query.ct.reply_dir.max_win,
1987 query.ct.reply_dir.max_ack);
1991 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1992 id, pia->type, port_id);
1998 static struct port_flow_tunnel *
1999 port_flow_tunnel_offload_cmd_prep(portid_t port_id,
2000 const struct rte_flow_item *pattern,
2001 const struct rte_flow_action *actions,
2002 const struct tunnel_ops *tunnel_ops)
2005 struct rte_port *port;
2006 struct port_flow_tunnel *pft;
2007 struct rte_flow_error error;
2009 port = &ports[port_id];
2010 pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
2012 fprintf(stderr, "failed to locate port flow tunnel #%u\n",
2016 if (tunnel_ops->actions) {
2017 uint32_t num_actions;
2018 const struct rte_flow_action *aptr;
2020 ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
2022 &pft->num_pmd_actions,
2025 port_flow_complain(&error);
2028 for (aptr = actions, num_actions = 1;
2029 aptr->type != RTE_FLOW_ACTION_TYPE_END;
2030 aptr++, num_actions++);
2031 pft->actions = malloc(
2032 (num_actions + pft->num_pmd_actions) *
2033 sizeof(actions[0]));
2034 if (!pft->actions) {
2035 rte_flow_tunnel_action_decap_release(
2036 port_id, pft->actions,
2037 pft->num_pmd_actions, &error);
2040 rte_memcpy(pft->actions, pft->pmd_actions,
2041 pft->num_pmd_actions * sizeof(actions[0]));
2042 rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
2043 num_actions * sizeof(actions[0]));
2045 if (tunnel_ops->items) {
2047 const struct rte_flow_item *iptr;
2049 ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
2051 &pft->num_pmd_items,
2054 port_flow_complain(&error);
2057 for (iptr = pattern, num_items = 1;
2058 iptr->type != RTE_FLOW_ITEM_TYPE_END;
2059 iptr++, num_items++);
2060 pft->items = malloc((num_items + pft->num_pmd_items) *
2061 sizeof(pattern[0]));
2063 rte_flow_tunnel_item_release(
2064 port_id, pft->pmd_items,
2065 pft->num_pmd_items, &error);
2068 rte_memcpy(pft->items, pft->pmd_items,
2069 pft->num_pmd_items * sizeof(pattern[0]));
2070 rte_memcpy(pft->items + pft->num_pmd_items, pattern,
2071 num_items * sizeof(pattern[0]));
2078 port_flow_tunnel_offload_cmd_release(portid_t port_id,
2079 const struct tunnel_ops *tunnel_ops,
2080 struct port_flow_tunnel *pft)
2082 struct rte_flow_error error;
2084 if (tunnel_ops->actions) {
2086 rte_flow_tunnel_action_decap_release(
2087 port_id, pft->pmd_actions,
2088 pft->num_pmd_actions, &error);
2089 pft->actions = NULL;
2090 pft->pmd_actions = NULL;
2092 if (tunnel_ops->items) {
2094 rte_flow_tunnel_item_release(port_id, pft->pmd_items,
2098 pft->pmd_items = NULL;
2102 /** Add port meter policy */
2104 port_meter_policy_add(portid_t port_id, uint32_t policy_id,
2105 const struct rte_flow_action *actions)
2107 struct rte_mtr_error error;
2108 const struct rte_flow_action *act = actions;
2109 const struct rte_flow_action *start;
2110 struct rte_mtr_meter_policy_params policy;
2111 uint32_t i = 0, act_n;
2114 for (i = 0; i < RTE_COLORS; i++) {
2115 for (act_n = 0, start = act;
2116 act->type != RTE_FLOW_ACTION_TYPE_END; act++)
2118 if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
2119 policy.actions[i] = start;
2121 policy.actions[i] = NULL;
2124 ret = rte_mtr_meter_policy_add(port_id,
2128 print_mtr_err_msg(&error);
2132 /** Validate flow rule. */
2134 port_flow_validate(portid_t port_id,
2135 const struct rte_flow_attr *attr,
2136 const struct rte_flow_item *pattern,
2137 const struct rte_flow_action *actions,
2138 const struct tunnel_ops *tunnel_ops)
2140 struct rte_flow_error error;
2141 struct port_flow_tunnel *pft = NULL;
2144 /* Poisoning to make sure PMDs update it in case of error. */
2145 memset(&error, 0x11, sizeof(error));
2146 if (tunnel_ops->enabled) {
2147 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2148 actions, tunnel_ops);
2152 pattern = pft->items;
2154 actions = pft->actions;
2156 ret = rte_flow_validate(port_id, attr, pattern, actions, &error);
2157 if (tunnel_ops->enabled)
2158 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2160 return port_flow_complain(&error);
2161 printf("Flow rule validated\n");
2165 /** Return age action structure if exists, otherwise NULL. */
2166 static struct rte_flow_action_age *
2167 age_action_get(const struct rte_flow_action *actions)
2169 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2170 switch (actions->type) {
2171 case RTE_FLOW_ACTION_TYPE_AGE:
2172 return (struct rte_flow_action_age *)
2173 (uintptr_t)actions->conf;
2181 /** Create pattern template */
2183 port_flow_pattern_template_create(portid_t port_id, uint32_t id,
2184 const struct rte_flow_pattern_template_attr *attr,
2185 const struct rte_flow_item *pattern)
2187 struct rte_port *port;
2188 struct port_template *pit;
2190 struct rte_flow_error error;
2192 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2193 port_id == (portid_t)RTE_PORT_ALL)
2195 port = &ports[port_id];
2196 ret = template_alloc(id, &pit, &port->pattern_templ_list);
2199 /* Poisoning to make sure PMDs update it in case of error. */
2200 memset(&error, 0x22, sizeof(error));
2201 pit->template.pattern_template = rte_flow_pattern_template_create(port_id,
2202 attr, pattern, &error);
2203 if (!pit->template.pattern_template) {
2204 uint32_t destroy_id = pit->id;
2205 port_flow_pattern_template_destroy(port_id, 1, &destroy_id);
2206 return port_flow_complain(&error);
2208 printf("Pattern template #%u created\n", pit->id);
2212 /** Destroy pattern template */
2214 port_flow_pattern_template_destroy(portid_t port_id, uint32_t n,
2215 const uint32_t *template)
2217 struct rte_port *port;
2218 struct port_template **tmp;
2222 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2223 port_id == (portid_t)RTE_PORT_ALL)
2225 port = &ports[port_id];
2226 tmp = &port->pattern_templ_list;
2230 for (i = 0; i != n; ++i) {
2231 struct rte_flow_error error;
2232 struct port_template *pit = *tmp;
2234 if (template[i] != pit->id)
2237 * Poisoning to make sure PMDs update it in case
2240 memset(&error, 0x33, sizeof(error));
2242 if (pit->template.pattern_template &&
2243 rte_flow_pattern_template_destroy(port_id,
2244 pit->template.pattern_template,
2246 ret = port_flow_complain(&error);
2250 printf("Pattern template #%u destroyed\n", pit->id);
2255 tmp = &(*tmp)->next;
2261 /** Create actions template */
2263 port_flow_actions_template_create(portid_t port_id, uint32_t id,
2264 const struct rte_flow_actions_template_attr *attr,
2265 const struct rte_flow_action *actions,
2266 const struct rte_flow_action *masks)
2268 struct rte_port *port;
2269 struct port_template *pat;
2271 struct rte_flow_error error;
2273 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2274 port_id == (portid_t)RTE_PORT_ALL)
2276 port = &ports[port_id];
2277 ret = template_alloc(id, &pat, &port->actions_templ_list);
2280 /* Poisoning to make sure PMDs update it in case of error. */
2281 memset(&error, 0x22, sizeof(error));
2282 pat->template.actions_template = rte_flow_actions_template_create(port_id,
2283 attr, actions, masks, &error);
2284 if (!pat->template.actions_template) {
2285 uint32_t destroy_id = pat->id;
2286 port_flow_actions_template_destroy(port_id, 1, &destroy_id);
2287 return port_flow_complain(&error);
2289 printf("Actions template #%u created\n", pat->id);
2293 /** Destroy actions template */
2295 port_flow_actions_template_destroy(portid_t port_id, uint32_t n,
2296 const uint32_t *template)
2298 struct rte_port *port;
2299 struct port_template **tmp;
2303 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2304 port_id == (portid_t)RTE_PORT_ALL)
2306 port = &ports[port_id];
2307 tmp = &port->actions_templ_list;
2311 for (i = 0; i != n; ++i) {
2312 struct rte_flow_error error;
2313 struct port_template *pat = *tmp;
2315 if (template[i] != pat->id)
2318 * Poisoning to make sure PMDs update it in case
2321 memset(&error, 0x33, sizeof(error));
2323 if (pat->template.actions_template &&
2324 rte_flow_actions_template_destroy(port_id,
2325 pat->template.actions_template, &error)) {
2326 ret = port_flow_complain(&error);
2330 printf("Actions template #%u destroyed\n", pat->id);
2335 tmp = &(*tmp)->next;
2343 port_flow_template_table_create(portid_t port_id, uint32_t id,
2344 const struct rte_flow_template_table_attr *table_attr,
2345 uint32_t nb_pattern_templates, uint32_t *pattern_templates,
2346 uint32_t nb_actions_templates, uint32_t *actions_templates)
2348 struct rte_port *port;
2349 struct port_table *pt;
2350 struct port_template *temp = NULL;
2353 struct rte_flow_error error;
2354 struct rte_flow_pattern_template
2355 *flow_pattern_templates[nb_pattern_templates];
2356 struct rte_flow_actions_template
2357 *flow_actions_templates[nb_actions_templates];
2359 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2360 port_id == (portid_t)RTE_PORT_ALL)
2362 port = &ports[port_id];
2363 for (i = 0; i < nb_pattern_templates; ++i) {
2365 temp = port->pattern_templ_list;
2367 if (pattern_templates[i] == temp->id) {
2368 flow_pattern_templates[i] =
2369 temp->template.pattern_template;
2376 printf("Pattern template #%u is invalid\n",
2377 pattern_templates[i]);
2381 for (i = 0; i < nb_actions_templates; ++i) {
2383 temp = port->actions_templ_list;
2385 if (actions_templates[i] == temp->id) {
2386 flow_actions_templates[i] =
2387 temp->template.actions_template;
2394 printf("Actions template #%u is invalid\n",
2395 actions_templates[i]);
2399 ret = table_alloc(id, &pt, &port->table_list);
2402 /* Poisoning to make sure PMDs update it in case of error. */
2403 memset(&error, 0x22, sizeof(error));
2404 pt->table = rte_flow_template_table_create(port_id, table_attr,
2405 flow_pattern_templates, nb_pattern_templates,
2406 flow_actions_templates, nb_actions_templates,
2410 uint32_t destroy_id = pt->id;
2411 port_flow_template_table_destroy(port_id, 1, &destroy_id);
2412 return port_flow_complain(&error);
2414 pt->nb_pattern_templates = nb_pattern_templates;
2415 pt->nb_actions_templates = nb_actions_templates;
2416 printf("Template table #%u created\n", pt->id);
2420 /** Destroy table */
2422 port_flow_template_table_destroy(portid_t port_id,
2423 uint32_t n, const uint32_t *table)
2425 struct rte_port *port;
2426 struct port_table **tmp;
2430 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2431 port_id == (portid_t)RTE_PORT_ALL)
2433 port = &ports[port_id];
2434 tmp = &port->table_list;
2438 for (i = 0; i != n; ++i) {
2439 struct rte_flow_error error;
2440 struct port_table *pt = *tmp;
2442 if (table[i] != pt->id)
2445 * Poisoning to make sure PMDs update it in case
2448 memset(&error, 0x33, sizeof(error));
2451 rte_flow_template_table_destroy(port_id,
2454 ret = port_flow_complain(&error);
2458 printf("Template table #%u destroyed\n", pt->id);
2463 tmp = &(*tmp)->next;
2469 /** Enqueue create flow rule operation. */
2471 port_queue_flow_create(portid_t port_id, queueid_t queue_id,
2472 bool postpone, uint32_t table_id,
2473 uint32_t pattern_idx, uint32_t actions_idx,
2474 const struct rte_flow_item *pattern,
2475 const struct rte_flow_action *actions)
2477 struct rte_flow_op_attr op_attr = { .postpone = postpone };
2478 struct rte_flow *flow;
2479 struct rte_port *port;
2480 struct port_flow *pf;
2481 struct port_table *pt;
2484 struct rte_flow_error error = { RTE_FLOW_ERROR_TYPE_NONE, NULL, NULL };
2485 struct rte_flow_action_age *age = age_action_get(actions);
2487 port = &ports[port_id];
2488 if (port->flow_list) {
2489 if (port->flow_list->id == UINT32_MAX) {
2490 printf("Highest rule ID is already assigned,"
2491 " delete it first");
2494 id = port->flow_list->id + 1;
2497 if (queue_id >= port->queue_nb) {
2498 printf("Queue #%u is invalid\n", queue_id);
2503 pt = port->table_list;
2505 if (table_id == pt->id) {
2512 printf("Table #%u is invalid\n", table_id);
2516 if (pattern_idx >= pt->nb_pattern_templates) {
2517 printf("Pattern template index #%u is invalid,"
2518 " %u templates present in the table\n",
2519 pattern_idx, pt->nb_pattern_templates);
2522 if (actions_idx >= pt->nb_actions_templates) {
2523 printf("Actions template index #%u is invalid,"
2524 " %u templates present in the table\n",
2525 actions_idx, pt->nb_actions_templates);
2529 pf = port_flow_new(NULL, pattern, actions, &error);
2531 return port_flow_complain(&error);
2533 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
2534 age->context = &pf->age_type;
2536 /* Poisoning to make sure PMDs update it in case of error. */
2537 memset(&error, 0x11, sizeof(error));
2538 flow = rte_flow_async_create(port_id, queue_id, &op_attr, pt->table,
2539 pattern, pattern_idx, actions, actions_idx, NULL, &error);
2541 uint32_t flow_id = pf->id;
2542 port_queue_flow_destroy(port_id, queue_id, true, 1, &flow_id);
2543 return port_flow_complain(&error);
2546 pf->next = port->flow_list;
2549 port->flow_list = pf;
2550 printf("Flow rule #%u creation enqueued\n", pf->id);
2554 /** Enqueue number of destroy flow rules operations. */
2556 port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
2557 bool postpone, uint32_t n, const uint32_t *rule)
2559 struct rte_flow_op_attr op_attr = { .postpone = postpone };
2560 struct rte_port *port;
2561 struct port_flow **tmp;
2565 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2566 port_id == (portid_t)RTE_PORT_ALL)
2568 port = &ports[port_id];
2570 if (queue_id >= port->queue_nb) {
2571 printf("Queue #%u is invalid\n", queue_id);
2575 tmp = &port->flow_list;
2579 for (i = 0; i != n; ++i) {
2580 struct rte_flow_error error;
2581 struct port_flow *pf = *tmp;
2583 if (rule[i] != pf->id)
2586 * Poisoning to make sure PMD
2587 * update it in case of error.
2589 memset(&error, 0x33, sizeof(error));
2590 if (rte_flow_async_destroy(port_id, queue_id, &op_attr,
2591 pf->flow, NULL, &error)) {
2592 ret = port_flow_complain(&error);
2595 printf("Flow rule #%u destruction enqueued\n", pf->id);
2601 tmp = &(*tmp)->next;
2607 /** Enqueue indirect action create operation. */
2609 port_queue_action_handle_create(portid_t port_id, uint32_t queue_id,
2610 bool postpone, uint32_t id,
2611 const struct rte_flow_indir_action_conf *conf,
2612 const struct rte_flow_action *action)
2614 const struct rte_flow_op_attr attr = { .postpone = postpone};
2615 struct rte_port *port;
2616 struct port_indirect_action *pia;
2618 struct rte_flow_error error;
2620 ret = action_alloc(port_id, id, &pia);
2624 port = &ports[port_id];
2625 if (queue_id >= port->queue_nb) {
2626 printf("Queue #%u is invalid\n", queue_id);
2630 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
2631 struct rte_flow_action_age *age =
2632 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
2634 pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
2635 age->context = &pia->age_type;
2637 /* Poisoning to make sure PMDs update it in case of error. */
2638 memset(&error, 0x88, sizeof(error));
2639 pia->handle = rte_flow_async_action_handle_create(port_id, queue_id,
2640 &attr, conf, action, NULL, &error);
2642 uint32_t destroy_id = pia->id;
2643 port_queue_action_handle_destroy(port_id, queue_id,
2644 postpone, 1, &destroy_id);
2645 return port_flow_complain(&error);
2647 pia->type = action->type;
2648 printf("Indirect action #%u creation queued\n", pia->id);
2652 /** Enqueue indirect action destroy operation. */
2654 port_queue_action_handle_destroy(portid_t port_id,
2655 uint32_t queue_id, bool postpone,
2656 uint32_t n, const uint32_t *actions)
2658 const struct rte_flow_op_attr attr = { .postpone = postpone};
2659 struct rte_port *port;
2660 struct port_indirect_action **tmp;
2664 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2665 port_id == (portid_t)RTE_PORT_ALL)
2667 port = &ports[port_id];
2669 if (queue_id >= port->queue_nb) {
2670 printf("Queue #%u is invalid\n", queue_id);
2674 tmp = &port->actions_list;
2678 for (i = 0; i != n; ++i) {
2679 struct rte_flow_error error;
2680 struct port_indirect_action *pia = *tmp;
2682 if (actions[i] != pia->id)
2685 * Poisoning to make sure PMDs update it in case
2688 memset(&error, 0x99, sizeof(error));
2691 rte_flow_async_action_handle_destroy(port_id,
2692 queue_id, &attr, pia->handle, NULL, &error)) {
2693 ret = port_flow_complain(&error);
2697 printf("Indirect action #%u destruction queued\n",
2703 tmp = &(*tmp)->next;
2709 /** Enqueue indirect action update operation. */
2711 port_queue_action_handle_update(portid_t port_id,
2712 uint32_t queue_id, bool postpone, uint32_t id,
2713 const struct rte_flow_action *action)
2715 const struct rte_flow_op_attr attr = { .postpone = postpone};
2716 struct rte_port *port;
2717 struct rte_flow_error error;
2718 struct rte_flow_action_handle *action_handle;
2720 action_handle = port_action_handle_get_by_id(port_id, id);
2724 port = &ports[port_id];
2725 if (queue_id >= port->queue_nb) {
2726 printf("Queue #%u is invalid\n", queue_id);
2730 if (rte_flow_async_action_handle_update(port_id, queue_id, &attr,
2731 action_handle, action, NULL, &error)) {
2732 return port_flow_complain(&error);
2734 printf("Indirect action #%u update queued\n", id);
2738 /** Push all the queue operations in the queue to the NIC. */
2740 port_queue_flow_push(portid_t port_id, queueid_t queue_id)
2742 struct rte_port *port;
2743 struct rte_flow_error error;
2746 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2747 port_id == (portid_t)RTE_PORT_ALL)
2749 port = &ports[port_id];
2751 if (queue_id >= port->queue_nb) {
2752 printf("Queue #%u is invalid\n", queue_id);
2756 memset(&error, 0x55, sizeof(error));
2757 ret = rte_flow_push(port_id, queue_id, &error);
2759 printf("Failed to push operations in the queue\n");
2762 printf("Queue #%u operations pushed\n", queue_id);
2766 /** Pull queue operation results from the queue. */
2768 port_queue_flow_pull(portid_t port_id, queueid_t queue_id)
2770 struct rte_port *port;
2771 struct rte_flow_op_result *res;
2772 struct rte_flow_error error;
2777 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2778 port_id == (portid_t)RTE_PORT_ALL)
2780 port = &ports[port_id];
2782 if (queue_id >= port->queue_nb) {
2783 printf("Queue #%u is invalid\n", queue_id);
2787 res = calloc(port->queue_sz, sizeof(struct rte_flow_op_result));
2789 printf("Failed to allocate memory for pulled results\n");
2793 memset(&error, 0x66, sizeof(error));
2794 ret = rte_flow_pull(port_id, queue_id, res,
2795 port->queue_sz, &error);
2797 printf("Failed to pull a operation results\n");
2802 for (i = 0; i < ret; i++) {
2803 if (res[i].status == RTE_FLOW_OP_SUCCESS)
2806 printf("Queue #%u pulled %u operations (%u failed, %u succeeded)\n",
2807 queue_id, ret, ret - success, success);
2812 /** Create flow rule. */
2814 port_flow_create(portid_t port_id,
2815 const struct rte_flow_attr *attr,
2816 const struct rte_flow_item *pattern,
2817 const struct rte_flow_action *actions,
2818 const struct tunnel_ops *tunnel_ops)
2820 struct rte_flow *flow;
2821 struct rte_port *port;
2822 struct port_flow *pf;
2824 struct rte_flow_error error;
2825 struct port_flow_tunnel *pft = NULL;
2826 struct rte_flow_action_age *age = age_action_get(actions);
2828 port = &ports[port_id];
2829 if (port->flow_list) {
2830 if (port->flow_list->id == UINT32_MAX) {
2832 "Highest rule ID is already assigned, delete it first");
2835 id = port->flow_list->id + 1;
2837 if (tunnel_ops->enabled) {
2838 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2839 actions, tunnel_ops);
2843 pattern = pft->items;
2845 actions = pft->actions;
2847 pf = port_flow_new(attr, pattern, actions, &error);
2849 return port_flow_complain(&error);
2851 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
2852 age->context = &pf->age_type;
2854 /* Poisoning to make sure PMDs update it in case of error. */
2855 memset(&error, 0x22, sizeof(error));
2856 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
2858 if (tunnel_ops->enabled)
2859 port_flow_tunnel_offload_cmd_release(port_id,
2862 return port_flow_complain(&error);
2864 pf->next = port->flow_list;
2867 port->flow_list = pf;
2868 if (tunnel_ops->enabled)
2869 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2870 printf("Flow rule #%u created\n", pf->id);
2874 /** Destroy a number of flow rules. */
2876 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
2878 struct rte_port *port;
2879 struct port_flow **tmp;
2883 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2884 port_id == (portid_t)RTE_PORT_ALL)
2886 port = &ports[port_id];
2887 tmp = &port->flow_list;
2891 for (i = 0; i != n; ++i) {
2892 struct rte_flow_error error;
2893 struct port_flow *pf = *tmp;
2895 if (rule[i] != pf->id)
2898 * Poisoning to make sure PMDs update it in case
2901 memset(&error, 0x33, sizeof(error));
2902 if (rte_flow_destroy(port_id, pf->flow, &error)) {
2903 ret = port_flow_complain(&error);
2906 printf("Flow rule #%u destroyed\n", pf->id);
2912 tmp = &(*tmp)->next;
2918 /** Remove all flow rules. */
2920 port_flow_flush(portid_t port_id)
2922 struct rte_flow_error error;
2923 struct rte_port *port;
2926 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2927 port_id == (portid_t)RTE_PORT_ALL)
2930 port = &ports[port_id];
2932 if (port->flow_list == NULL)
2935 /* Poisoning to make sure PMDs update it in case of error. */
2936 memset(&error, 0x44, sizeof(error));
2937 if (rte_flow_flush(port_id, &error)) {
2938 port_flow_complain(&error);
2941 while (port->flow_list) {
2942 struct port_flow *pf = port->flow_list->next;
2944 free(port->flow_list);
2945 port->flow_list = pf;
2950 /** Dump flow rules. */
2952 port_flow_dump(portid_t port_id, bool dump_all, uint32_t rule_id,
2953 const char *file_name)
2956 FILE *file = stdout;
2957 struct rte_flow_error error;
2958 struct rte_port *port;
2959 struct port_flow *pflow;
2960 struct rte_flow *tmpFlow = NULL;
2963 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2964 port_id == (portid_t)RTE_PORT_ALL)
2968 port = &ports[port_id];
2969 pflow = port->flow_list;
2971 if (rule_id != pflow->id) {
2972 pflow = pflow->next;
2974 tmpFlow = pflow->flow;
2980 if (found == false) {
2981 fprintf(stderr, "Failed to dump to flow %d\n", rule_id);
2986 if (file_name && strlen(file_name)) {
2987 file = fopen(file_name, "w");
2989 fprintf(stderr, "Failed to create file %s: %s\n",
2990 file_name, strerror(errno));
2996 ret = rte_flow_dev_dump(port_id, tmpFlow, file, &error);
2998 ret = rte_flow_dev_dump(port_id, NULL, file, &error);
3000 port_flow_complain(&error);
3001 fprintf(stderr, "Failed to dump flow: %s\n", strerror(-ret));
3003 printf("Flow dump finished\n");
3004 if (file_name && strlen(file_name))
3009 /** Query a flow rule. */
3011 port_flow_query(portid_t port_id, uint32_t rule,
3012 const struct rte_flow_action *action)
3014 struct rte_flow_error error;
3015 struct rte_port *port;
3016 struct port_flow *pf;
3019 struct rte_flow_query_count count;
3020 struct rte_flow_action_rss rss_conf;
3021 struct rte_flow_query_age age;
3025 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3026 port_id == (portid_t)RTE_PORT_ALL)
3028 port = &ports[port_id];
3029 for (pf = port->flow_list; pf; pf = pf->next)
3033 fprintf(stderr, "Flow rule #%u not found\n", rule);
3036 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
3037 &name, sizeof(name),
3038 (void *)(uintptr_t)action->type, &error);
3040 return port_flow_complain(&error);
3041 switch (action->type) {
3042 case RTE_FLOW_ACTION_TYPE_COUNT:
3043 case RTE_FLOW_ACTION_TYPE_RSS:
3044 case RTE_FLOW_ACTION_TYPE_AGE:
3047 fprintf(stderr, "Cannot query action type %d (%s)\n",
3048 action->type, name);
3051 /* Poisoning to make sure PMDs update it in case of error. */
3052 memset(&error, 0x55, sizeof(error));
3053 memset(&query, 0, sizeof(query));
3054 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
3055 return port_flow_complain(&error);
3056 switch (action->type) {
3057 case RTE_FLOW_ACTION_TYPE_COUNT:
3061 " hits: %" PRIu64 "\n"
3062 " bytes: %" PRIu64 "\n",
3064 query.count.hits_set,
3065 query.count.bytes_set,
3069 case RTE_FLOW_ACTION_TYPE_RSS:
3070 rss_config_display(&query.rss_conf);
3072 case RTE_FLOW_ACTION_TYPE_AGE:
3075 " sec_since_last_hit_valid: %u\n"
3076 " sec_since_last_hit: %" PRIu32 "\n",
3079 query.age.sec_since_last_hit_valid,
3080 query.age.sec_since_last_hit);
3084 "Cannot display result for action type %d (%s)\n",
3085 action->type, name);
3091 /** List simply and destroy all aged flows. */
3093 port_flow_aged(portid_t port_id, uint8_t destroy)
3096 int nb_context, total = 0, idx;
3097 struct rte_flow_error error;
3098 enum age_action_context_type *type;
3100 struct port_flow *pf;
3101 struct port_indirect_action *pia;
3104 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3105 port_id == (portid_t)RTE_PORT_ALL)
3107 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
3108 printf("Port %u total aged flows: %d\n", port_id, total);
3110 port_flow_complain(&error);
3115 contexts = malloc(sizeof(void *) * total);
3116 if (contexts == NULL) {
3117 fprintf(stderr, "Cannot allocate contexts for aged flow\n");
3120 printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
3121 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
3122 if (nb_context != total) {
3124 "Port:%d get aged flows count(%d) != total(%d)\n",
3125 port_id, nb_context, total);
3130 for (idx = 0; idx < nb_context; idx++) {
3131 if (!contexts[idx]) {
3132 fprintf(stderr, "Error: get Null context in port %u\n",
3136 type = (enum age_action_context_type *)contexts[idx];
3138 case ACTION_AGE_CONTEXT_TYPE_FLOW:
3139 ctx.pf = container_of(type, struct port_flow, age_type);
3140 printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
3144 ctx.pf->rule.attr->group,
3145 ctx.pf->rule.attr->priority,
3146 ctx.pf->rule.attr->ingress ? 'i' : '-',
3147 ctx.pf->rule.attr->egress ? 'e' : '-',
3148 ctx.pf->rule.attr->transfer ? 't' : '-');
3149 if (destroy && !port_flow_destroy(port_id, 1,
3153 case ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION:
3154 ctx.pia = container_of(type,
3155 struct port_indirect_action, age_type);
3156 printf("%-20s\t%" PRIu32 "\n", "Indirect action",
3160 fprintf(stderr, "Error: invalid context type %u\n",
3165 printf("\n%d flows destroyed\n", total);
3169 /** List flow rules. */
3171 port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group)
3173 struct rte_port *port;
3174 struct port_flow *pf;
3175 struct port_flow *list = NULL;
3178 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
3179 port_id == (portid_t)RTE_PORT_ALL)
3181 port = &ports[port_id];
3182 if (!port->flow_list)
3184 /* Sort flows by group, priority and ID. */
3185 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
3186 struct port_flow **tmp;
3187 const struct rte_flow_attr *curr = pf->rule.attr;
3190 /* Filter out unwanted groups. */
3191 for (i = 0; i != n; ++i)
3192 if (curr->group == group[i])
3197 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
3198 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
3200 if (curr->group > comp->group ||
3201 (curr->group == comp->group &&
3202 curr->priority > comp->priority) ||
3203 (curr->group == comp->group &&
3204 curr->priority == comp->priority &&
3205 pf->id > (*tmp)->id))
3212 printf("ID\tGroup\tPrio\tAttr\tRule\n");
3213 for (pf = list; pf != NULL; pf = pf->tmp) {
3214 const struct rte_flow_item *item = pf->rule.pattern;
3215 const struct rte_flow_action *action = pf->rule.actions;
3218 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
3220 pf->rule.attr->group,
3221 pf->rule.attr->priority,
3222 pf->rule.attr->ingress ? 'i' : '-',
3223 pf->rule.attr->egress ? 'e' : '-',
3224 pf->rule.attr->transfer ? 't' : '-');
3225 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
3226 if ((uint32_t)item->type > INT_MAX)
3227 name = "PMD_INTERNAL";
3228 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
3229 &name, sizeof(name),
3230 (void *)(uintptr_t)item->type,
3233 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
3234 printf("%s ", name);
3238 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
3239 if ((uint32_t)action->type > INT_MAX)
3240 name = "PMD_INTERNAL";
3241 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
3242 &name, sizeof(name),
3243 (void *)(uintptr_t)action->type,
3246 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
3247 printf(" %s", name);
3254 /** Restrict ingress traffic to the defined flow rules. */
3256 port_flow_isolate(portid_t port_id, int set)
3258 struct rte_flow_error error;
3260 /* Poisoning to make sure PMDs update it in case of error. */
3261 memset(&error, 0x66, sizeof(error));
3262 if (rte_flow_isolate(port_id, set, &error))
3263 return port_flow_complain(&error);
3264 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
3266 set ? "now restricted" : "not restricted anymore");
3271 * RX/TX ring descriptors display functions.
3274 rx_queue_id_is_invalid(queueid_t rxq_id)
3276 if (rxq_id < nb_rxq)
3278 fprintf(stderr, "Invalid RX queue %d (must be < nb_rxq=%d)\n",
3284 tx_queue_id_is_invalid(queueid_t txq_id)
3286 if (txq_id < nb_txq)
3288 fprintf(stderr, "Invalid TX queue %d (must be < nb_txq=%d)\n",
3294 get_rx_ring_size(portid_t port_id, queueid_t rxq_id, uint16_t *ring_size)
3296 struct rte_port *port = &ports[port_id];
3297 struct rte_eth_rxq_info rx_qinfo;
3300 ret = rte_eth_rx_queue_info_get(port_id, rxq_id, &rx_qinfo);
3302 *ring_size = rx_qinfo.nb_desc;
3306 if (ret != -ENOTSUP)
3309 * If the rte_eth_rx_queue_info_get is not support for this PMD,
3310 * ring_size stored in testpmd will be used for validity verification.
3311 * When configure the rxq by rte_eth_rx_queue_setup with nb_rx_desc
3312 * being 0, it will use a default value provided by PMDs to setup this
3313 * rxq. If the default value is 0, it will use the
3314 * RTE_ETH_DEV_FALLBACK_RX_RINGSIZE to setup this rxq.
3316 if (port->nb_rx_desc[rxq_id])
3317 *ring_size = port->nb_rx_desc[rxq_id];
3318 else if (port->dev_info.default_rxportconf.ring_size)
3319 *ring_size = port->dev_info.default_rxportconf.ring_size;
3321 *ring_size = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
3326 get_tx_ring_size(portid_t port_id, queueid_t txq_id, uint16_t *ring_size)
3328 struct rte_port *port = &ports[port_id];
3329 struct rte_eth_txq_info tx_qinfo;
3332 ret = rte_eth_tx_queue_info_get(port_id, txq_id, &tx_qinfo);
3334 *ring_size = tx_qinfo.nb_desc;
3338 if (ret != -ENOTSUP)
3341 * If the rte_eth_tx_queue_info_get is not support for this PMD,
3342 * ring_size stored in testpmd will be used for validity verification.
3343 * When configure the txq by rte_eth_tx_queue_setup with nb_tx_desc
3344 * being 0, it will use a default value provided by PMDs to setup this
3345 * txq. If the default value is 0, it will use the
3346 * RTE_ETH_DEV_FALLBACK_TX_RINGSIZE to setup this txq.
3348 if (port->nb_tx_desc[txq_id])
3349 *ring_size = port->nb_tx_desc[txq_id];
3350 else if (port->dev_info.default_txportconf.ring_size)
3351 *ring_size = port->dev_info.default_txportconf.ring_size;
3353 *ring_size = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
3358 rx_desc_id_is_invalid(portid_t port_id, queueid_t rxq_id, uint16_t rxdesc_id)
3363 ret = get_rx_ring_size(port_id, rxq_id, &ring_size);
3367 if (rxdesc_id < ring_size)
3370 fprintf(stderr, "Invalid RX descriptor %u (must be < ring_size=%u)\n",
3371 rxdesc_id, ring_size);
3376 tx_desc_id_is_invalid(portid_t port_id, queueid_t txq_id, uint16_t txdesc_id)
3381 ret = get_tx_ring_size(port_id, txq_id, &ring_size);
3385 if (txdesc_id < ring_size)
3388 fprintf(stderr, "Invalid TX descriptor %u (must be < ring_size=%u)\n",
3389 txdesc_id, ring_size);
3393 static const struct rte_memzone *
3394 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
3396 char mz_name[RTE_MEMZONE_NAMESIZE];
3397 const struct rte_memzone *mz;
3399 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
3400 port_id, q_id, ring_name);
3401 mz = rte_memzone_lookup(mz_name);
3404 "%s ring memory zoneof (port %d, queue %d) not found (zone name = %s\n",
3405 ring_name, port_id, q_id, mz_name);
3409 union igb_ring_dword {
3412 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
3422 struct igb_ring_desc_32_bytes {
3423 union igb_ring_dword lo_dword;
3424 union igb_ring_dword hi_dword;
3425 union igb_ring_dword resv1;
3426 union igb_ring_dword resv2;
3429 struct igb_ring_desc_16_bytes {
3430 union igb_ring_dword lo_dword;
3431 union igb_ring_dword hi_dword;
3435 ring_rxd_display_dword(union igb_ring_dword dword)
3437 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
3438 (unsigned)dword.words.hi);
3442 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
3443 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
3446 __rte_unused portid_t port_id,
3450 struct igb_ring_desc_16_bytes *ring =
3451 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
3452 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
3454 struct rte_eth_dev_info dev_info;
3456 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3460 if (strstr(dev_info.driver_name, "i40e") != NULL) {
3461 /* 32 bytes RX descriptor, i40e only */
3462 struct igb_ring_desc_32_bytes *ring =
3463 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
3464 ring[desc_id].lo_dword.dword =
3465 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
3466 ring_rxd_display_dword(ring[desc_id].lo_dword);
3467 ring[desc_id].hi_dword.dword =
3468 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
3469 ring_rxd_display_dword(ring[desc_id].hi_dword);
3470 ring[desc_id].resv1.dword =
3471 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
3472 ring_rxd_display_dword(ring[desc_id].resv1);
3473 ring[desc_id].resv2.dword =
3474 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
3475 ring_rxd_display_dword(ring[desc_id].resv2);
3480 /* 16 bytes RX descriptor */
3481 ring[desc_id].lo_dword.dword =
3482 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
3483 ring_rxd_display_dword(ring[desc_id].lo_dword);
3484 ring[desc_id].hi_dword.dword =
3485 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
3486 ring_rxd_display_dword(ring[desc_id].hi_dword);
3490 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
3492 struct igb_ring_desc_16_bytes *ring;
3493 struct igb_ring_desc_16_bytes txd;
3495 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
3496 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
3497 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
3498 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
3499 (unsigned)txd.lo_dword.words.lo,
3500 (unsigned)txd.lo_dword.words.hi,
3501 (unsigned)txd.hi_dword.words.lo,
3502 (unsigned)txd.hi_dword.words.hi);
3506 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
3508 const struct rte_memzone *rx_mz;
3510 if (rx_desc_id_is_invalid(port_id, rxq_id, rxd_id))
3512 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
3515 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
3519 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
3521 const struct rte_memzone *tx_mz;
3523 if (tx_desc_id_is_invalid(port_id, txq_id, txd_id))
3525 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
3528 ring_tx_descriptor_display(tx_mz, txd_id);
3532 fwd_lcores_config_display(void)
3536 printf("List of forwarding lcores:");
3537 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
3538 printf(" %2u", fwd_lcores_cpuids[lc_id]);
3542 rxtx_config_display(void)
3547 printf(" %s packet forwarding%s packets/burst=%d\n",
3548 cur_fwd_eng->fwd_mode_name,
3549 retry_enabled == 0 ? "" : " with retry",
3552 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
3553 printf(" packet len=%u - nb packet segments=%d\n",
3554 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
3556 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
3557 nb_fwd_lcores, nb_fwd_ports);
3559 RTE_ETH_FOREACH_DEV(pid) {
3560 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
3561 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
3562 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
3563 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
3564 struct rte_eth_rxq_info rx_qinfo;
3565 struct rte_eth_txq_info tx_qinfo;
3566 uint16_t rx_free_thresh_tmp;
3567 uint16_t tx_free_thresh_tmp;
3568 uint16_t tx_rs_thresh_tmp;
3569 uint16_t nb_rx_desc_tmp;
3570 uint16_t nb_tx_desc_tmp;
3571 uint64_t offloads_tmp;
3572 uint8_t pthresh_tmp;
3573 uint8_t hthresh_tmp;
3574 uint8_t wthresh_tmp;
3577 /* per port config */
3578 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
3579 (unsigned int)pid, nb_rxq, nb_txq);
3581 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
3582 ports[pid].dev_conf.rxmode.offloads,
3583 ports[pid].dev_conf.txmode.offloads);
3585 /* per rx queue config only for first queue to be less verbose */
3586 for (qid = 0; qid < 1; qid++) {
3587 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
3589 nb_rx_desc_tmp = nb_rx_desc[qid];
3590 rx_free_thresh_tmp =
3591 rx_conf[qid].rx_free_thresh;
3592 pthresh_tmp = rx_conf[qid].rx_thresh.pthresh;
3593 hthresh_tmp = rx_conf[qid].rx_thresh.hthresh;
3594 wthresh_tmp = rx_conf[qid].rx_thresh.wthresh;
3595 offloads_tmp = rx_conf[qid].offloads;
3597 nb_rx_desc_tmp = rx_qinfo.nb_desc;
3598 rx_free_thresh_tmp =
3599 rx_qinfo.conf.rx_free_thresh;
3600 pthresh_tmp = rx_qinfo.conf.rx_thresh.pthresh;
3601 hthresh_tmp = rx_qinfo.conf.rx_thresh.hthresh;
3602 wthresh_tmp = rx_qinfo.conf.rx_thresh.wthresh;
3603 offloads_tmp = rx_qinfo.conf.offloads;
3606 printf(" RX queue: %d\n", qid);
3607 printf(" RX desc=%d - RX free threshold=%d\n",
3608 nb_rx_desc_tmp, rx_free_thresh_tmp);
3609 printf(" RX threshold registers: pthresh=%d hthresh=%d "
3611 pthresh_tmp, hthresh_tmp, wthresh_tmp);
3612 printf(" RX Offloads=0x%"PRIx64, offloads_tmp);
3613 if (rx_conf->share_group > 0)
3614 printf(" share_group=%u share_qid=%u",
3615 rx_conf->share_group,
3616 rx_conf->share_qid);
3620 /* per tx queue config only for first queue to be less verbose */
3621 for (qid = 0; qid < 1; qid++) {
3622 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
3624 nb_tx_desc_tmp = nb_tx_desc[qid];
3625 tx_free_thresh_tmp =
3626 tx_conf[qid].tx_free_thresh;
3627 pthresh_tmp = tx_conf[qid].tx_thresh.pthresh;
3628 hthresh_tmp = tx_conf[qid].tx_thresh.hthresh;
3629 wthresh_tmp = tx_conf[qid].tx_thresh.wthresh;
3630 offloads_tmp = tx_conf[qid].offloads;
3631 tx_rs_thresh_tmp = tx_conf[qid].tx_rs_thresh;
3633 nb_tx_desc_tmp = tx_qinfo.nb_desc;
3634 tx_free_thresh_tmp =
3635 tx_qinfo.conf.tx_free_thresh;
3636 pthresh_tmp = tx_qinfo.conf.tx_thresh.pthresh;
3637 hthresh_tmp = tx_qinfo.conf.tx_thresh.hthresh;
3638 wthresh_tmp = tx_qinfo.conf.tx_thresh.wthresh;
3639 offloads_tmp = tx_qinfo.conf.offloads;
3640 tx_rs_thresh_tmp = tx_qinfo.conf.tx_rs_thresh;
3643 printf(" TX queue: %d\n", qid);
3644 printf(" TX desc=%d - TX free threshold=%d\n",
3645 nb_tx_desc_tmp, tx_free_thresh_tmp);
3646 printf(" TX threshold registers: pthresh=%d hthresh=%d "
3648 pthresh_tmp, hthresh_tmp, wthresh_tmp);
3649 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
3650 offloads_tmp, tx_rs_thresh_tmp);
3656 port_rss_reta_info(portid_t port_id,
3657 struct rte_eth_rss_reta_entry64 *reta_conf,
3658 uint16_t nb_entries)
3660 uint16_t i, idx, shift;
3663 if (port_id_is_invalid(port_id, ENABLED_WARN))
3666 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
3669 "Failed to get RSS RETA info, return code = %d\n",
3674 for (i = 0; i < nb_entries; i++) {
3675 idx = i / RTE_ETH_RETA_GROUP_SIZE;
3676 shift = i % RTE_ETH_RETA_GROUP_SIZE;
3677 if (!(reta_conf[idx].mask & (1ULL << shift)))
3679 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
3680 i, reta_conf[idx].reta[shift]);
3685 * Displays the RSS hash functions of a port, and, optionally, the RSS hash
3689 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
3691 struct rte_eth_rss_conf rss_conf = {0};
3692 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
3696 struct rte_eth_dev_info dev_info;
3697 uint8_t hash_key_size;
3700 if (port_id_is_invalid(port_id, ENABLED_WARN))
3703 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3707 if (dev_info.hash_key_size > 0 &&
3708 dev_info.hash_key_size <= sizeof(rss_key))
3709 hash_key_size = dev_info.hash_key_size;
3712 "dev_info did not provide a valid hash key size\n");
3716 /* Get RSS hash key if asked to display it */
3717 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
3718 rss_conf.rss_key_len = hash_key_size;
3719 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
3723 fprintf(stderr, "port index %d invalid\n", port_id);
3726 fprintf(stderr, "operation not supported by device\n");
3729 fprintf(stderr, "operation failed - diag=%d\n", diag);
3734 rss_hf = rss_conf.rss_hf;
3736 printf("RSS disabled\n");
3739 printf("RSS functions:\n ");
3740 for (i = 0; rss_type_table[i].str; i++) {
3741 if (rss_type_table[i].rss_type == 0)
3743 if ((rss_hf & rss_type_table[i].rss_type) == rss_type_table[i].rss_type)
3744 printf("%s ", rss_type_table[i].str);
3749 printf("RSS key:\n");
3750 for (i = 0; i < hash_key_size; i++)
3751 printf("%02X", rss_key[i]);
3756 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
3757 uint8_t hash_key_len)
3759 struct rte_eth_rss_conf rss_conf;
3763 rss_conf.rss_key = NULL;
3764 rss_conf.rss_key_len = 0;
3765 rss_conf.rss_hf = 0;
3766 for (i = 0; rss_type_table[i].str; i++) {
3767 if (!strcmp(rss_type_table[i].str, rss_type))
3768 rss_conf.rss_hf = rss_type_table[i].rss_type;
3770 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
3772 rss_conf.rss_key = hash_key;
3773 rss_conf.rss_key_len = hash_key_len;
3774 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
3781 fprintf(stderr, "port index %d invalid\n", port_id);
3784 fprintf(stderr, "operation not supported by device\n");
3787 fprintf(stderr, "operation failed - diag=%d\n", diag);
3793 * Check whether a shared rxq scheduled on other lcores.
3796 fwd_stream_on_other_lcores(uint16_t domain_id, lcoreid_t src_lc,
3797 portid_t src_port, queueid_t src_rxq,
3798 uint32_t share_group, queueid_t share_rxq)
3801 streamid_t nb_fs_per_lcore;
3804 struct fwd_stream *fs;
3805 struct rte_port *port;
3806 struct rte_eth_dev_info *dev_info;
3807 struct rte_eth_rxconf *rxq_conf;
3809 nb_fc = cur_fwd_config.nb_fwd_lcores;
3810 /* Check remaining cores. */
3811 for (lc_id = src_lc + 1; lc_id < nb_fc; lc_id++) {
3812 sm_id = fwd_lcores[lc_id]->stream_idx;
3813 nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
3814 for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
3816 fs = fwd_streams[sm_id];
3817 port = &ports[fs->rx_port];
3818 dev_info = &port->dev_info;
3819 rxq_conf = &port->rx_conf[fs->rx_queue];
3820 if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
3821 == 0 || rxq_conf->share_group == 0)
3822 /* Not shared rxq. */
3824 if (domain_id != port->dev_info.switch_info.domain_id)
3826 if (rxq_conf->share_group != share_group)
3828 if (rxq_conf->share_qid != share_rxq)
3830 printf("Shared Rx queue group %u queue %hu can't be scheduled on different cores:\n",
3831 share_group, share_rxq);
3832 printf(" lcore %hhu Port %hu queue %hu\n",
3833 src_lc, src_port, src_rxq);
3834 printf(" lcore %hhu Port %hu queue %hu\n",
3835 lc_id, fs->rx_port, fs->rx_queue);
3836 printf("Please use --nb-cores=%hu to limit number of forwarding cores\n",
3845 * Check shared rxq configuration.
3847 * Shared group must not being scheduled on different core.
3850 pkt_fwd_shared_rxq_check(void)
3853 streamid_t nb_fs_per_lcore;
3856 struct fwd_stream *fs;
3858 struct rte_port *port;
3859 struct rte_eth_dev_info *dev_info;
3860 struct rte_eth_rxconf *rxq_conf;
3864 nb_fc = cur_fwd_config.nb_fwd_lcores;
3866 * Check streams on each core, make sure the same switch domain +
3867 * group + queue doesn't get scheduled on other cores.
3869 for (lc_id = 0; lc_id < nb_fc; lc_id++) {
3870 sm_id = fwd_lcores[lc_id]->stream_idx;
3871 nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
3872 for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
3874 fs = fwd_streams[sm_id];
3875 /* Update lcore info stream being scheduled. */
3876 fs->lcore = fwd_lcores[lc_id];
3877 port = &ports[fs->rx_port];
3878 dev_info = &port->dev_info;
3879 rxq_conf = &port->rx_conf[fs->rx_queue];
3880 if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
3881 == 0 || rxq_conf->share_group == 0)
3882 /* Not shared rxq. */
3884 /* Check shared rxq not scheduled on remaining cores. */
3885 domain_id = port->dev_info.switch_info.domain_id;
3886 if (fwd_stream_on_other_lcores(domain_id, lc_id,
3889 rxq_conf->share_group,
3890 rxq_conf->share_qid))
3898 * Setup forwarding configuration for each logical core.
3901 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
3903 streamid_t nb_fs_per_lcore;
3911 nb_fs = cfg->nb_fwd_streams;
3912 nb_fc = cfg->nb_fwd_lcores;
3913 if (nb_fs <= nb_fc) {
3914 nb_fs_per_lcore = 1;
3917 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
3918 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
3921 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
3923 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
3924 fwd_lcores[lc_id]->stream_idx = sm_id;
3925 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
3926 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
3930 * Assign extra remaining streams, if any.
3932 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
3933 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
3934 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
3935 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
3936 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
3941 fwd_topology_tx_port_get(portid_t rxp)
3943 static int warning_once = 1;
3945 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
3947 switch (port_topology) {
3949 case PORT_TOPOLOGY_PAIRED:
3950 if ((rxp & 0x1) == 0) {
3951 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
3955 "\nWarning! port-topology=paired and odd forward ports number, the last port will pair with itself.\n\n");
3961 case PORT_TOPOLOGY_CHAINED:
3962 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
3963 case PORT_TOPOLOGY_LOOP:
3969 simple_fwd_config_setup(void)
3973 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
3974 cur_fwd_config.nb_fwd_streams =
3975 (streamid_t) cur_fwd_config.nb_fwd_ports;
3977 /* reinitialize forwarding streams */
3981 * In the simple forwarding test, the number of forwarding cores
3982 * must be lower or equal to the number of forwarding ports.
3984 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3985 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
3986 cur_fwd_config.nb_fwd_lcores =
3987 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
3988 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3990 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
3991 fwd_streams[i]->rx_port = fwd_ports_ids[i];
3992 fwd_streams[i]->rx_queue = 0;
3993 fwd_streams[i]->tx_port =
3994 fwd_ports_ids[fwd_topology_tx_port_get(i)];
3995 fwd_streams[i]->tx_queue = 0;
3996 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
3997 fwd_streams[i]->retry_enabled = retry_enabled;
4002 * For the RSS forwarding test all streams distributed over lcores. Each stream
4003 * being composed of a RX queue to poll on a RX port for input messages,
4004 * associated with a TX queue of a TX port where to send forwarded packets.
4007 rss_fwd_config_setup(void)
4020 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
4021 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
4022 cur_fwd_config.nb_fwd_streams =
4023 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
4025 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
4026 cur_fwd_config.nb_fwd_lcores =
4027 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
4029 /* reinitialize forwarding streams */
4032 setup_fwd_config_of_each_lcore(&cur_fwd_config);
4034 if (proc_id > 0 && nb_q % num_procs != 0)
4035 printf("Warning! queue numbers should be multiple of processes, or packet loss will happen.\n");
4038 * In multi-process, All queues are allocated to different
4039 * processes based on num_procs and proc_id. For example:
4040 * if supports 4 queues(nb_q), 2 processes(num_procs),
4041 * the 0~1 queue for primary process.
4042 * the 2~3 queue for secondary process.
4044 start = proc_id * nb_q / num_procs;
4045 end = start + nb_q / num_procs;
4048 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
4049 struct fwd_stream *fs;
4051 fs = fwd_streams[sm_id];
4052 txp = fwd_topology_tx_port_get(rxp);
4053 fs->rx_port = fwd_ports_ids[rxp];
4055 fs->tx_port = fwd_ports_ids[txp];
4057 fs->peer_addr = fs->tx_port;
4058 fs->retry_enabled = retry_enabled;
4060 if (rxp < nb_fwd_ports)
4070 get_fwd_port_total_tc_num(void)
4072 struct rte_eth_dcb_info dcb_info;
4073 uint16_t total_tc_num = 0;
4076 for (i = 0; i < nb_fwd_ports; i++) {
4077 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[i], &dcb_info);
4078 total_tc_num += dcb_info.nb_tcs;
4081 return total_tc_num;
4085 * For the DCB forwarding test, each core is assigned on each traffic class.
4087 * Each core is assigned a multi-stream, each stream being composed of
4088 * a RX queue to poll on a RX port for input messages, associated with
4089 * a TX queue of a TX port where to send forwarded packets. All RX and
4090 * TX queues are mapping to the same traffic class.
4091 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
4095 dcb_fwd_config_setup(void)
4097 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
4098 portid_t txp, rxp = 0;
4099 queueid_t txq, rxq = 0;
4101 uint16_t nb_rx_queue, nb_tx_queue;
4102 uint16_t i, j, k, sm_id = 0;
4103 uint16_t total_tc_num;
4104 struct rte_port *port;
4110 * The fwd_config_setup() is called when the port is RTE_PORT_STARTED
4111 * or RTE_PORT_STOPPED.
4113 * Re-configure ports to get updated mapping between tc and queue in
4114 * case the queue number of the port is changed. Skip for started ports
4115 * since modifying queue number and calling dev_configure need to stop
4118 for (pid = 0; pid < nb_fwd_ports; pid++) {
4119 if (port_is_started(pid) == 1)
4123 ret = rte_eth_dev_configure(pid, nb_rxq, nb_txq,
4127 "Failed to re-configure port %d, ret = %d.\n",
4133 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
4134 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
4135 cur_fwd_config.nb_fwd_streams =
4136 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
4137 total_tc_num = get_fwd_port_total_tc_num();
4138 if (cur_fwd_config.nb_fwd_lcores > total_tc_num)
4139 cur_fwd_config.nb_fwd_lcores = total_tc_num;
4141 /* reinitialize forwarding streams */
4145 /* get the dcb info on the first RX and TX ports */
4146 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
4147 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
4149 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
4150 fwd_lcores[lc_id]->stream_nb = 0;
4151 fwd_lcores[lc_id]->stream_idx = sm_id;
4152 for (i = 0; i < RTE_ETH_MAX_VMDQ_POOL; i++) {
4153 /* if the nb_queue is zero, means this tc is
4154 * not enabled on the POOL
4156 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
4158 k = fwd_lcores[lc_id]->stream_nb +
4159 fwd_lcores[lc_id]->stream_idx;
4160 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
4161 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
4162 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
4163 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
4164 for (j = 0; j < nb_rx_queue; j++) {
4165 struct fwd_stream *fs;
4167 fs = fwd_streams[k + j];
4168 fs->rx_port = fwd_ports_ids[rxp];
4169 fs->rx_queue = rxq + j;
4170 fs->tx_port = fwd_ports_ids[txp];
4171 fs->tx_queue = txq + j % nb_tx_queue;
4172 fs->peer_addr = fs->tx_port;
4173 fs->retry_enabled = retry_enabled;
4175 fwd_lcores[lc_id]->stream_nb +=
4176 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
4178 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
4181 if (tc < rxp_dcb_info.nb_tcs)
4183 /* Restart from TC 0 on next RX port */
4185 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
4187 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
4190 if (rxp >= nb_fwd_ports)
4192 /* get the dcb information on next RX and TX ports */
4193 if ((rxp & 0x1) == 0)
4194 txp = (portid_t) (rxp + 1);
4196 txp = (portid_t) (rxp - 1);
4197 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
4198 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
4203 icmp_echo_config_setup(void)
4210 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
4211 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
4212 (nb_txq * nb_fwd_ports);
4214 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
4215 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
4216 cur_fwd_config.nb_fwd_streams =
4217 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
4218 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
4219 cur_fwd_config.nb_fwd_lcores =
4220 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
4221 if (verbose_level > 0) {
4222 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
4224 cur_fwd_config.nb_fwd_lcores,
4225 cur_fwd_config.nb_fwd_ports,
4226 cur_fwd_config.nb_fwd_streams);
4229 /* reinitialize forwarding streams */
4231 setup_fwd_config_of_each_lcore(&cur_fwd_config);
4233 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
4234 if (verbose_level > 0)
4235 printf(" core=%d: \n", lc_id);
4236 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
4237 struct fwd_stream *fs;
4238 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
4239 fs->rx_port = fwd_ports_ids[rxp];
4241 fs->tx_port = fs->rx_port;
4243 fs->peer_addr = fs->tx_port;
4244 fs->retry_enabled = retry_enabled;
4245 if (verbose_level > 0)
4246 printf(" stream=%d port=%d rxq=%d txq=%d\n",
4247 sm_id, fs->rx_port, fs->rx_queue,
4249 rxq = (queueid_t) (rxq + 1);
4250 if (rxq == nb_rxq) {
4252 rxp = (portid_t) (rxp + 1);
4259 fwd_config_setup(void)
4261 struct rte_port *port;
4265 cur_fwd_config.fwd_eng = cur_fwd_eng;
4266 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
4267 icmp_echo_config_setup();
4271 if ((nb_rxq > 1) && (nb_txq > 1)){
4273 for (i = 0; i < nb_fwd_ports; i++) {
4274 pt_id = fwd_ports_ids[i];
4275 port = &ports[pt_id];
4276 if (!port->dcb_flag) {
4278 "In DCB mode, all forwarding ports must be configured in this mode.\n");
4282 if (nb_fwd_lcores == 1) {
4284 "In DCB mode,the nb forwarding cores should be larger than 1.\n");
4288 dcb_fwd_config_setup();
4290 rss_fwd_config_setup();
4293 simple_fwd_config_setup();
4297 mp_alloc_to_str(uint8_t mode)
4300 case MP_ALLOC_NATIVE:
4306 case MP_ALLOC_XMEM_HUGE:
4316 pkt_fwd_config_display(struct fwd_config *cfg)
4318 struct fwd_stream *fs;
4322 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
4323 "NUMA support %s, MP allocation mode: %s\n",
4324 cfg->fwd_eng->fwd_mode_name,
4325 retry_enabled == 0 ? "" : " with retry",
4326 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
4327 numa_support == 1 ? "enabled" : "disabled",
4328 mp_alloc_to_str(mp_alloc_type));
4331 printf("TX retry num: %u, delay between TX retries: %uus\n",
4332 burst_tx_retry_num, burst_tx_delay_time);
4333 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
4334 printf("Logical Core %u (socket %u) forwards packets on "
4336 fwd_lcores_cpuids[lc_id],
4337 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
4338 fwd_lcores[lc_id]->stream_nb);
4339 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
4340 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
4341 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
4342 "P=%d/Q=%d (socket %u) ",
4343 fs->rx_port, fs->rx_queue,
4344 ports[fs->rx_port].socket_id,
4345 fs->tx_port, fs->tx_queue,
4346 ports[fs->tx_port].socket_id);
4347 print_ethaddr("peer=",
4348 &peer_eth_addrs[fs->peer_addr]);
4356 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
4358 struct rte_ether_addr new_peer_addr;
4359 if (!rte_eth_dev_is_valid_port(port_id)) {
4360 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
4363 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
4364 fprintf(stderr, "Error: Invalid ethernet address: %s\n",
4368 peer_eth_addrs[port_id] = new_peer_addr;
4372 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
4375 unsigned int lcore_cpuid;
4380 for (i = 0; i < nb_lc; i++) {
4381 lcore_cpuid = lcorelist[i];
4382 if (! rte_lcore_is_enabled(lcore_cpuid)) {
4383 fprintf(stderr, "lcore %u not enabled\n", lcore_cpuid);
4386 if (lcore_cpuid == rte_get_main_lcore()) {
4388 "lcore %u cannot be masked on for running packet forwarding, which is the main lcore and reserved for command line parsing only\n",
4393 fwd_lcores_cpuids[i] = lcore_cpuid;
4395 if (record_now == 0) {
4399 nb_cfg_lcores = (lcoreid_t) nb_lc;
4400 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
4401 printf("previous number of forwarding cores %u - changed to "
4402 "number of configured cores %u\n",
4403 (unsigned int) nb_fwd_lcores, nb_lc);
4404 nb_fwd_lcores = (lcoreid_t) nb_lc;
4411 set_fwd_lcores_mask(uint64_t lcoremask)
4413 unsigned int lcorelist[64];
4417 if (lcoremask == 0) {
4418 fprintf(stderr, "Invalid NULL mask of cores\n");
4422 for (i = 0; i < 64; i++) {
4423 if (! ((uint64_t)(1ULL << i) & lcoremask))
4425 lcorelist[nb_lc++] = i;
4427 return set_fwd_lcores_list(lcorelist, nb_lc);
4431 set_fwd_lcores_number(uint16_t nb_lc)
4433 if (test_done == 0) {
4434 fprintf(stderr, "Please stop forwarding first\n");
4437 if (nb_lc > nb_cfg_lcores) {
4439 "nb fwd cores %u > %u (max. number of configured lcores) - ignored\n",
4440 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
4443 nb_fwd_lcores = (lcoreid_t) nb_lc;
4444 printf("Number of forwarding cores set to %u\n",
4445 (unsigned int) nb_fwd_lcores);
4449 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
4457 for (i = 0; i < nb_pt; i++) {
4458 port_id = (portid_t) portlist[i];
4459 if (port_id_is_invalid(port_id, ENABLED_WARN))
4462 fwd_ports_ids[i] = port_id;
4464 if (record_now == 0) {
4468 nb_cfg_ports = (portid_t) nb_pt;
4469 if (nb_fwd_ports != (portid_t) nb_pt) {
4470 printf("previous number of forwarding ports %u - changed to "
4471 "number of configured ports %u\n",
4472 (unsigned int) nb_fwd_ports, nb_pt);
4473 nb_fwd_ports = (portid_t) nb_pt;
4478 * Parse the user input and obtain the list of forwarding ports
4481 * String containing the user input. User can specify
4482 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
4483 * For example, if the user wants to use all the available
4484 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
4485 * If the user wants to use only the ports 1,2 then the input
4487 * valid characters are '-' and ','
4488 * @param[out] values
4489 * This array will be filled with a list of port IDs
4490 * based on the user input
4491 * Note that duplicate entries are discarded and only the first
4492 * count entries in this array are port IDs and all the rest
4493 * will contain default values
4494 * @param[in] maxsize
4495 * This parameter denotes 2 things
4496 * 1) Number of elements in the values array
4497 * 2) Maximum value of each element in the values array
4499 * On success, returns total count of parsed port IDs
4500 * On failure, returns 0
4503 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
4505 unsigned int count = 0;
4509 unsigned int marked[maxsize];
4511 if (list == NULL || values == NULL)
4514 for (i = 0; i < (int)maxsize; i++)
4520 /*Remove the blank spaces if any*/
4521 while (isblank(*list))
4526 value = strtol(list, &end, 10);
4527 if (errno || end == NULL)
4529 if (value < 0 || value >= (int)maxsize)
4531 while (isblank(*end))
4533 if (*end == '-' && min == INT_MAX) {
4535 } else if ((*end == ',') || (*end == '\0')) {
4539 for (i = min; i <= max; i++) {
4540 if (count < maxsize) {
4552 } while (*end != '\0');
4558 parse_fwd_portlist(const char *portlist)
4560 unsigned int portcount;
4561 unsigned int portindex[RTE_MAX_ETHPORTS];
4562 unsigned int i, valid_port_count = 0;
4564 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
4566 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
4569 * Here we verify the validity of the ports
4570 * and thereby calculate the total number of
4573 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
4574 if (rte_eth_dev_is_valid_port(portindex[i])) {
4575 portindex[valid_port_count] = portindex[i];
4580 set_fwd_ports_list(portindex, valid_port_count);
4584 set_fwd_ports_mask(uint64_t portmask)
4586 unsigned int portlist[64];
4590 if (portmask == 0) {
4591 fprintf(stderr, "Invalid NULL mask of ports\n");
4595 RTE_ETH_FOREACH_DEV(i) {
4596 if (! ((uint64_t)(1ULL << i) & portmask))
4598 portlist[nb_pt++] = i;
4600 set_fwd_ports_list(portlist, nb_pt);
4604 set_fwd_ports_number(uint16_t nb_pt)
4606 if (nb_pt > nb_cfg_ports) {
4608 "nb fwd ports %u > %u (number of configured ports) - ignored\n",
4609 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
4612 nb_fwd_ports = (portid_t) nb_pt;
4613 printf("Number of forwarding ports set to %u\n",
4614 (unsigned int) nb_fwd_ports);
4618 port_is_forwarding(portid_t port_id)
4622 if (port_id_is_invalid(port_id, ENABLED_WARN))
4625 for (i = 0; i < nb_fwd_ports; i++) {
4626 if (fwd_ports_ids[i] == port_id)
4634 set_nb_pkt_per_burst(uint16_t nb)
4636 if (nb > MAX_PKT_BURST) {
4638 "nb pkt per burst: %u > %u (maximum packet per burst) ignored\n",
4639 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
4642 nb_pkt_per_burst = nb;
4643 printf("Number of packets per burst set to %u\n",
4644 (unsigned int) nb_pkt_per_burst);
4648 tx_split_get_name(enum tx_pkt_split split)
4652 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
4653 if (tx_split_name[i].split == split)
4654 return tx_split_name[i].name;
4660 set_tx_pkt_split(const char *name)
4664 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
4665 if (strcmp(tx_split_name[i].name, name) == 0) {
4666 tx_pkt_split = tx_split_name[i].split;
4670 fprintf(stderr, "unknown value: \"%s\"\n", name);
4674 parse_fec_mode(const char *name, uint32_t *fec_capa)
4678 for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
4679 if (strcmp(fec_mode_name[i].name, name) == 0) {
4681 RTE_ETH_FEC_MODE_TO_CAPA(fec_mode_name[i].mode);
4689 show_fec_capability(unsigned int num, struct rte_eth_fec_capa *speed_fec_capa)
4693 printf("FEC capabilities:\n");
4695 for (i = 0; i < num; i++) {
4697 rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
4699 for (j = 0; j < RTE_DIM(fec_mode_name); j++) {
4700 if (RTE_ETH_FEC_MODE_TO_CAPA(j) &
4701 speed_fec_capa[i].capa)
4702 printf("%s ", fec_mode_name[j].name);
4709 show_rx_pkt_offsets(void)
4714 printf("Number of offsets: %u\n", n);
4716 printf("Segment offsets: ");
4717 for (i = 0; i != n - 1; i++)
4718 printf("%hu,", rx_pkt_seg_offsets[i]);
4719 printf("%hu\n", rx_pkt_seg_lengths[i]);
4724 set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs)
4728 if (nb_offs >= MAX_SEGS_BUFFER_SPLIT) {
4729 printf("nb segments per RX packets=%u >= "
4730 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_offs);
4735 * No extra check here, the segment length will be checked by PMD
4736 * in the extended queue setup.
4738 for (i = 0; i < nb_offs; i++) {
4739 if (seg_offsets[i] >= UINT16_MAX) {
4740 printf("offset[%u]=%u > UINT16_MAX - give up\n",
4746 for (i = 0; i < nb_offs; i++)
4747 rx_pkt_seg_offsets[i] = (uint16_t) seg_offsets[i];
4749 rx_pkt_nb_offs = (uint8_t) nb_offs;
4753 show_rx_pkt_segments(void)
4758 printf("Number of segments: %u\n", n);
4760 printf("Segment sizes: ");
4761 for (i = 0; i != n - 1; i++)
4762 printf("%hu,", rx_pkt_seg_lengths[i]);
4763 printf("%hu\n", rx_pkt_seg_lengths[i]);
4768 set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
4772 if (nb_segs >= MAX_SEGS_BUFFER_SPLIT) {
4773 printf("nb segments per RX packets=%u >= "
4774 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs);
4779 * No extra check here, the segment length will be checked by PMD
4780 * in the extended queue setup.
4782 for (i = 0; i < nb_segs; i++) {
4783 if (seg_lengths[i] >= UINT16_MAX) {
4784 printf("length[%u]=%u > UINT16_MAX - give up\n",
4790 for (i = 0; i < nb_segs; i++)
4791 rx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
4793 rx_pkt_nb_segs = (uint8_t) nb_segs;
4797 show_tx_pkt_segments(void)
4803 split = tx_split_get_name(tx_pkt_split);
4805 printf("Number of segments: %u\n", n);
4806 printf("Segment sizes: ");
4807 for (i = 0; i != n - 1; i++)
4808 printf("%hu,", tx_pkt_seg_lengths[i]);
4809 printf("%hu\n", tx_pkt_seg_lengths[i]);
4810 printf("Split packet: %s\n", split);
4814 nb_segs_is_invalid(unsigned int nb_segs)
4821 RTE_ETH_FOREACH_DEV(port_id) {
4822 for (queue_id = 0; queue_id < nb_txq; queue_id++) {
4823 ret = get_tx_ring_size(port_id, queue_id, &ring_size);
4825 /* Port may not be initialized yet, can't say
4826 * the port is invalid in this stage.
4830 if (ring_size < nb_segs) {
4831 printf("nb segments per TX packets=%u >= TX "
4832 "queue(%u) ring_size=%u - txpkts ignored\n",
4833 nb_segs, queue_id, ring_size);
4843 set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
4845 uint16_t tx_pkt_len;
4849 * For single segment settings failed check is ignored.
4850 * It is a very basic capability to send the single segment
4851 * packets, suppose it is always supported.
4853 if (nb_segs > 1 && nb_segs_is_invalid(nb_segs)) {
4855 "Tx segment size(%u) is not supported - txpkts ignored\n",
4860 if (nb_segs > RTE_MAX_SEGS_PER_PKT) {
4862 "Tx segment size(%u) is bigger than max number of segment(%u)\n",
4863 nb_segs, RTE_MAX_SEGS_PER_PKT);
4868 * Check that each segment length is greater or equal than
4869 * the mbuf data size.
4870 * Check also that the total packet length is greater or equal than the
4871 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
4875 for (i = 0; i < nb_segs; i++) {
4876 if (seg_lengths[i] > mbuf_data_size[0]) {
4878 "length[%u]=%u > mbuf_data_size=%u - give up\n",
4879 i, seg_lengths[i], mbuf_data_size[0]);
4882 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
4884 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
4885 fprintf(stderr, "total packet length=%u < %d - give up\n",
4886 (unsigned) tx_pkt_len,
4887 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
4891 for (i = 0; i < nb_segs; i++)
4892 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
4894 tx_pkt_length = tx_pkt_len;
4895 tx_pkt_nb_segs = (uint8_t) nb_segs;
4899 show_tx_pkt_times(void)
4901 printf("Interburst gap: %u\n", tx_pkt_times_inter);
4902 printf("Intraburst gap: %u\n", tx_pkt_times_intra);
4906 set_tx_pkt_times(unsigned int *tx_times)
4908 tx_pkt_times_inter = tx_times[0];
4909 tx_pkt_times_intra = tx_times[1];
4914 setup_gro(const char *onoff, portid_t port_id)
4916 if (!rte_eth_dev_is_valid_port(port_id)) {
4917 fprintf(stderr, "invalid port id %u\n", port_id);
4920 if (test_done == 0) {
4922 "Before enable/disable GRO, please stop forwarding first\n");
4925 if (strcmp(onoff, "on") == 0) {
4926 if (gro_ports[port_id].enable != 0) {
4928 "Port %u has enabled GRO. Please disable GRO first\n",
4932 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
4933 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
4934 gro_ports[port_id].param.max_flow_num =
4935 GRO_DEFAULT_FLOW_NUM;
4936 gro_ports[port_id].param.max_item_per_flow =
4937 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
4939 gro_ports[port_id].enable = 1;
4941 if (gro_ports[port_id].enable == 0) {
4942 fprintf(stderr, "Port %u has disabled GRO\n", port_id);
4945 gro_ports[port_id].enable = 0;
4950 setup_gro_flush_cycles(uint8_t cycles)
4952 if (test_done == 0) {
4954 "Before change flush interval for GRO, please stop forwarding first.\n");
4958 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
4959 GRO_DEFAULT_FLUSH_CYCLES) {
4961 "The flushing cycle be in the range of 1 to %u. Revert to the default value %u.\n",
4962 GRO_MAX_FLUSH_CYCLES, GRO_DEFAULT_FLUSH_CYCLES);
4963 cycles = GRO_DEFAULT_FLUSH_CYCLES;
4966 gro_flush_cycles = cycles;
4970 show_gro(portid_t port_id)
4972 struct rte_gro_param *param;
4973 uint32_t max_pkts_num;
4975 param = &gro_ports[port_id].param;
4977 if (!rte_eth_dev_is_valid_port(port_id)) {
4978 fprintf(stderr, "Invalid port id %u.\n", port_id);
4981 if (gro_ports[port_id].enable) {
4982 printf("GRO type: TCP/IPv4\n");
4983 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
4984 max_pkts_num = param->max_flow_num *
4985 param->max_item_per_flow;
4987 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
4988 printf("Max number of packets to perform GRO: %u\n",
4990 printf("Flushing cycles: %u\n", gro_flush_cycles);
4992 printf("Port %u doesn't enable GRO.\n", port_id);
4994 #endif /* RTE_LIB_GRO */
4998 setup_gso(const char *mode, portid_t port_id)
5000 if (!rte_eth_dev_is_valid_port(port_id)) {
5001 fprintf(stderr, "invalid port id %u\n", port_id);
5004 if (strcmp(mode, "on") == 0) {
5005 if (test_done == 0) {
5007 "before enabling GSO, please stop forwarding first\n");
5010 gso_ports[port_id].enable = 1;
5011 } else if (strcmp(mode, "off") == 0) {
5012 if (test_done == 0) {
5014 "before disabling GSO, please stop forwarding first\n");
5017 gso_ports[port_id].enable = 0;
5020 #endif /* RTE_LIB_GSO */
5023 list_pkt_forwarding_modes(void)
5025 static char fwd_modes[128] = "";
5026 const char *separator = "|";
5027 struct fwd_engine *fwd_eng;
5030 if (strlen (fwd_modes) == 0) {
5031 while ((fwd_eng = fwd_engines[i++]) != NULL) {
5032 strncat(fwd_modes, fwd_eng->fwd_mode_name,
5033 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
5034 strncat(fwd_modes, separator,
5035 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
5037 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
5044 list_pkt_forwarding_retry_modes(void)
5046 static char fwd_modes[128] = "";
5047 const char *separator = "|";
5048 struct fwd_engine *fwd_eng;
5051 if (strlen(fwd_modes) == 0) {
5052 while ((fwd_eng = fwd_engines[i++]) != NULL) {
5053 if (fwd_eng == &rx_only_engine)
5055 strncat(fwd_modes, fwd_eng->fwd_mode_name,
5057 strlen(fwd_modes) - 1);
5058 strncat(fwd_modes, separator,
5060 strlen(fwd_modes) - 1);
5062 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
5069 set_pkt_forwarding_mode(const char *fwd_mode_name)
5071 struct fwd_engine *fwd_eng;
5075 while ((fwd_eng = fwd_engines[i]) != NULL) {
5076 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
5077 printf("Set %s packet forwarding mode%s\n",
5079 retry_enabled == 0 ? "" : " with retry");
5080 cur_fwd_eng = fwd_eng;
5085 fprintf(stderr, "Invalid %s packet forwarding mode\n", fwd_mode_name);
5089 add_rx_dump_callbacks(portid_t portid)
5091 struct rte_eth_dev_info dev_info;
5095 if (port_id_is_invalid(portid, ENABLED_WARN))
5098 ret = eth_dev_info_get_print_err(portid, &dev_info);
5102 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
5103 if (!ports[portid].rx_dump_cb[queue])
5104 ports[portid].rx_dump_cb[queue] =
5105 rte_eth_add_rx_callback(portid, queue,
5106 dump_rx_pkts, NULL);
5110 add_tx_dump_callbacks(portid_t portid)
5112 struct rte_eth_dev_info dev_info;
5116 if (port_id_is_invalid(portid, ENABLED_WARN))
5119 ret = eth_dev_info_get_print_err(portid, &dev_info);
5123 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
5124 if (!ports[portid].tx_dump_cb[queue])
5125 ports[portid].tx_dump_cb[queue] =
5126 rte_eth_add_tx_callback(portid, queue,
5127 dump_tx_pkts, NULL);
5131 remove_rx_dump_callbacks(portid_t portid)
5133 struct rte_eth_dev_info dev_info;
5137 if (port_id_is_invalid(portid, ENABLED_WARN))
5140 ret = eth_dev_info_get_print_err(portid, &dev_info);
5144 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
5145 if (ports[portid].rx_dump_cb[queue]) {
5146 rte_eth_remove_rx_callback(portid, queue,
5147 ports[portid].rx_dump_cb[queue]);
5148 ports[portid].rx_dump_cb[queue] = NULL;
5153 remove_tx_dump_callbacks(portid_t portid)
5155 struct rte_eth_dev_info dev_info;
5159 if (port_id_is_invalid(portid, ENABLED_WARN))
5162 ret = eth_dev_info_get_print_err(portid, &dev_info);
5166 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
5167 if (ports[portid].tx_dump_cb[queue]) {
5168 rte_eth_remove_tx_callback(portid, queue,
5169 ports[portid].tx_dump_cb[queue]);
5170 ports[portid].tx_dump_cb[queue] = NULL;
5175 configure_rxtx_dump_callbacks(uint16_t verbose)
5179 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
5180 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
5184 RTE_ETH_FOREACH_DEV(portid)
5186 if (verbose == 1 || verbose > 2)
5187 add_rx_dump_callbacks(portid);
5189 remove_rx_dump_callbacks(portid);
5191 add_tx_dump_callbacks(portid);
5193 remove_tx_dump_callbacks(portid);
5198 set_verbose_level(uint16_t vb_level)
5200 printf("Change verbose level from %u to %u\n",
5201 (unsigned int) verbose_level, (unsigned int) vb_level);
5202 verbose_level = vb_level;
5203 configure_rxtx_dump_callbacks(verbose_level);
5207 vlan_extend_set(portid_t port_id, int on)
5211 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
5213 if (port_id_is_invalid(port_id, ENABLED_WARN))
5216 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
5219 vlan_offload |= RTE_ETH_VLAN_EXTEND_OFFLOAD;
5220 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
5222 vlan_offload &= ~RTE_ETH_VLAN_EXTEND_OFFLOAD;
5223 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
5226 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
5229 "rx_vlan_extend_set(port_pi=%d, on=%d) failed diag=%d\n",
5233 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
5237 rx_vlan_strip_set(portid_t port_id, int on)
5241 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
5243 if (port_id_is_invalid(port_id, ENABLED_WARN))
5246 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
5249 vlan_offload |= RTE_ETH_VLAN_STRIP_OFFLOAD;
5250 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5252 vlan_offload &= ~RTE_ETH_VLAN_STRIP_OFFLOAD;
5253 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
5256 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
5259 "%s(port_pi=%d, on=%d) failed diag=%d\n",
5260 __func__, port_id, on, diag);
5263 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
5267 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
5271 if (port_id_is_invalid(port_id, ENABLED_WARN))
5274 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
5277 "%s(port_pi=%d, queue_id=%d, on=%d) failed diag=%d\n",
5278 __func__, port_id, queue_id, on, diag);
5282 rx_vlan_filter_set(portid_t port_id, int on)
5286 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
5288 if (port_id_is_invalid(port_id, ENABLED_WARN))
5291 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
5294 vlan_offload |= RTE_ETH_VLAN_FILTER_OFFLOAD;
5295 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
5297 vlan_offload &= ~RTE_ETH_VLAN_FILTER_OFFLOAD;
5298 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
5301 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
5304 "%s(port_pi=%d, on=%d) failed diag=%d\n",
5305 __func__, port_id, on, diag);
5308 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
5312 rx_vlan_qinq_strip_set(portid_t port_id, int on)
5316 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
5318 if (port_id_is_invalid(port_id, ENABLED_WARN))
5321 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
5324 vlan_offload |= RTE_ETH_QINQ_STRIP_OFFLOAD;
5325 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
5327 vlan_offload &= ~RTE_ETH_QINQ_STRIP_OFFLOAD;
5328 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
5331 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
5333 fprintf(stderr, "%s(port_pi=%d, on=%d) failed diag=%d\n",
5334 __func__, port_id, on, diag);
5337 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
5341 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
5345 if (port_id_is_invalid(port_id, ENABLED_WARN))
5347 if (vlan_id_is_invalid(vlan_id))
5349 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
5353 "rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed diag=%d\n",
5354 port_id, vlan_id, on, diag);
5359 rx_vlan_all_filter_set(portid_t port_id, int on)
5363 if (port_id_is_invalid(port_id, ENABLED_WARN))
5365 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
5366 if (rx_vft_set(port_id, vlan_id, on))
5372 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
5376 if (port_id_is_invalid(port_id, ENABLED_WARN))
5379 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
5384 "tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed diag=%d\n",
5385 port_id, vlan_type, tp_id, diag);
5389 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
5391 struct rte_eth_dev_info dev_info;
5394 if (vlan_id_is_invalid(vlan_id))
5397 if (ports[port_id].dev_conf.txmode.offloads &
5398 RTE_ETH_TX_OFFLOAD_QINQ_INSERT) {
5399 fprintf(stderr, "Error, as QinQ has been enabled.\n");
5403 ret = eth_dev_info_get_print_err(port_id, &dev_info);
5407 if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VLAN_INSERT) == 0) {
5409 "Error: vlan insert is not supported by port %d\n",
5414 tx_vlan_reset(port_id);
5415 ports[port_id].dev_conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
5416 ports[port_id].tx_vlan_id = vlan_id;
5420 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
5422 struct rte_eth_dev_info dev_info;
5425 if (vlan_id_is_invalid(vlan_id))
5427 if (vlan_id_is_invalid(vlan_id_outer))
5430 ret = eth_dev_info_get_print_err(port_id, &dev_info);
5434 if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_QINQ_INSERT) == 0) {
5436 "Error: qinq insert not supported by port %d\n",
5441 tx_vlan_reset(port_id);
5442 ports[port_id].dev_conf.txmode.offloads |= (RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
5443 RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
5444 ports[port_id].tx_vlan_id = vlan_id;
5445 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
5449 tx_vlan_reset(portid_t port_id)
5451 ports[port_id].dev_conf.txmode.offloads &=
5452 ~(RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
5453 RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
5454 ports[port_id].tx_vlan_id = 0;
5455 ports[port_id].tx_vlan_id_outer = 0;
5459 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
5461 if (port_id_is_invalid(port_id, ENABLED_WARN))
5464 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
5468 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
5472 if (port_id_is_invalid(port_id, ENABLED_WARN))
5475 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
5478 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
5479 fprintf(stderr, "map_value not in required range 0..%d\n",
5480 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
5484 if (!is_rx) { /* tx */
5485 ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, queue_id,
5489 "failed to set tx queue stats mapping.\n");
5493 ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, queue_id,
5497 "failed to set rx queue stats mapping.\n");
5504 set_xstats_hide_zero(uint8_t on_off)
5506 xstats_hide_zero = on_off;
5510 set_record_core_cycles(uint8_t on_off)
5512 record_core_cycles = on_off;
5516 set_record_burst_stats(uint8_t on_off)
5518 record_burst_stats = on_off;
5522 flowtype_to_str(uint16_t flow_type)
5524 struct flow_type_info {
5530 static struct flow_type_info flowtype_str_table[] = {
5531 {"raw", RTE_ETH_FLOW_RAW},
5532 {"ipv4", RTE_ETH_FLOW_IPV4},
5533 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
5534 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
5535 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
5536 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
5537 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
5538 {"ipv6", RTE_ETH_FLOW_IPV6},
5539 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
5540 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
5541 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
5542 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
5543 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
5544 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
5545 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
5546 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
5547 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
5548 {"port", RTE_ETH_FLOW_PORT},
5549 {"vxlan", RTE_ETH_FLOW_VXLAN},
5550 {"geneve", RTE_ETH_FLOW_GENEVE},
5551 {"nvgre", RTE_ETH_FLOW_NVGRE},
5552 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
5553 {"gtpu", RTE_ETH_FLOW_GTPU},
5556 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
5557 if (flowtype_str_table[i].ftype == flow_type)
5558 return flowtype_str_table[i].str;
5564 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
5567 print_fdir_mask(struct rte_eth_fdir_masks *mask)
5569 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
5571 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
5572 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
5573 " tunnel_id: 0x%08x",
5574 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
5575 rte_be_to_cpu_32(mask->tunnel_id_mask));
5576 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5577 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
5578 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
5579 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
5581 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
5582 rte_be_to_cpu_16(mask->src_port_mask),
5583 rte_be_to_cpu_16(mask->dst_port_mask));
5585 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
5586 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
5587 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
5588 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
5589 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
5591 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
5592 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
5593 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
5594 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
5595 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
5602 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
5604 struct rte_eth_flex_payload_cfg *cfg;
5607 for (i = 0; i < flex_conf->nb_payloads; i++) {
5608 cfg = &flex_conf->flex_set[i];
5609 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
5611 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
5612 printf("\n L2_PAYLOAD: ");
5613 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
5614 printf("\n L3_PAYLOAD: ");
5615 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
5616 printf("\n L4_PAYLOAD: ");
5618 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
5619 for (j = 0; j < num; j++)
5620 printf(" %-5u", cfg->src_offset[j]);
5626 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
5628 struct rte_eth_fdir_flex_mask *mask;
5632 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
5633 mask = &flex_conf->flex_mask[i];
5634 p = flowtype_to_str(mask->flow_type);
5635 printf("\n %s:\t", p ? p : "unknown");
5636 for (j = 0; j < num; j++)
5637 printf(" %02x", mask->mask[j]);
5643 print_fdir_flow_type(uint32_t flow_types_mask)
5648 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
5649 if (!(flow_types_mask & (1 << i)))
5651 p = flowtype_to_str(i);
5661 get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info,
5662 struct rte_eth_fdir_stats *fdir_stat)
5667 if (ret == -ENOTSUP) {
5668 ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info);
5670 ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat);
5673 #ifdef RTE_NET_IXGBE
5674 if (ret == -ENOTSUP) {
5675 ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info);
5677 ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat);
5684 fprintf(stderr, "\n FDIR is not supported on port %-2d\n",
5688 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
5695 fdir_get_infos(portid_t port_id)
5697 struct rte_eth_fdir_stats fdir_stat;
5698 struct rte_eth_fdir_info fdir_info;
5700 static const char *fdir_stats_border = "########################";
5702 if (port_id_is_invalid(port_id, ENABLED_WARN))
5705 memset(&fdir_info, 0, sizeof(fdir_info));
5706 memset(&fdir_stat, 0, sizeof(fdir_stat));
5707 if (get_fdir_info(port_id, &fdir_info, &fdir_stat))
5710 printf("\n %s FDIR infos for port %-2d %s\n",
5711 fdir_stats_border, port_id, fdir_stats_border);
5713 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
5714 printf(" PERFECT\n");
5715 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
5716 printf(" PERFECT-MAC-VLAN\n");
5717 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
5718 printf(" PERFECT-TUNNEL\n");
5719 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
5720 printf(" SIGNATURE\n");
5722 printf(" DISABLE\n");
5723 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
5724 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
5725 printf(" SUPPORTED FLOW TYPE: ");
5726 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
5728 printf(" FLEX PAYLOAD INFO:\n");
5729 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
5730 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
5731 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
5732 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
5733 fdir_info.flex_payload_unit,
5734 fdir_info.max_flex_payload_segment_num,
5735 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
5737 print_fdir_mask(&fdir_info.mask);
5738 if (fdir_info.flex_conf.nb_payloads > 0) {
5739 printf(" FLEX PAYLOAD SRC OFFSET:");
5740 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
5742 if (fdir_info.flex_conf.nb_flexmasks > 0) {
5743 printf(" FLEX MASK CFG:");
5744 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
5746 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
5747 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
5748 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
5749 fdir_info.guarant_spc, fdir_info.best_spc);
5750 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
5751 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
5752 " add: %-10"PRIu64" remove: %"PRIu64"\n"
5753 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
5754 fdir_stat.collision, fdir_stat.free,
5755 fdir_stat.maxhash, fdir_stat.maxlen,
5756 fdir_stat.add, fdir_stat.remove,
5757 fdir_stat.f_add, fdir_stat.f_remove);
5758 printf(" %s############################%s\n",
5759 fdir_stats_border, fdir_stats_border);
5762 #endif /* RTE_NET_I40E || RTE_NET_IXGBE */
5765 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
5767 struct rte_port *port;
5768 struct rte_eth_fdir_flex_conf *flex_conf;
5771 port = &ports[port_id];
5772 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
5773 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
5774 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
5779 if (i >= RTE_ETH_FLOW_MAX) {
5780 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
5781 idx = flex_conf->nb_flexmasks;
5782 flex_conf->nb_flexmasks++;
5785 "The flex mask table is full. Can not set flex mask for flow_type(%u).",
5790 rte_memcpy(&flex_conf->flex_mask[idx],
5792 sizeof(struct rte_eth_fdir_flex_mask));
5796 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
5798 struct rte_port *port;
5799 struct rte_eth_fdir_flex_conf *flex_conf;
5802 port = &ports[port_id];
5803 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
5804 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
5805 if (cfg->type == flex_conf->flex_set[i].type) {
5810 if (i >= RTE_ETH_PAYLOAD_MAX) {
5811 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
5812 idx = flex_conf->nb_payloads;
5813 flex_conf->nb_payloads++;
5816 "The flex payload table is full. Can not set flex payload for type(%u).",
5821 rte_memcpy(&flex_conf->flex_set[idx],
5823 sizeof(struct rte_eth_flex_payload_cfg));
5828 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
5830 #ifdef RTE_NET_IXGBE
5834 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
5836 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
5841 "rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
5842 is_rx ? "rx" : "tx", port_id, diag);
5845 fprintf(stderr, "VF %s setting not supported for port %d\n",
5846 is_rx ? "Rx" : "Tx", port_id);
5852 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
5855 struct rte_eth_link link;
5858 if (port_id_is_invalid(port_id, ENABLED_WARN))
5860 ret = eth_link_get_nowait_print_err(port_id, &link);
5863 if (link.link_speed != RTE_ETH_SPEED_NUM_UNKNOWN &&
5864 rate > link.link_speed) {
5866 "Invalid rate value:%u bigger than link speed: %u\n",
5867 rate, link.link_speed);
5870 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
5874 "rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
5880 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
5882 int diag = -ENOTSUP;
5886 RTE_SET_USED(q_msk);
5888 #ifdef RTE_NET_IXGBE
5889 if (diag == -ENOTSUP)
5890 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
5894 if (diag == -ENOTSUP)
5895 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
5901 "%s for port_id=%d failed diag=%d\n",
5902 __func__, port_id, diag);
5907 * Functions to manage the set of filtered Multicast MAC addresses.
5909 * A pool of filtered multicast MAC addresses is associated with each port.
5910 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
5911 * The address of the pool and the number of valid multicast MAC addresses
5912 * recorded in the pool are stored in the fields "mc_addr_pool" and
5913 * "mc_addr_nb" of the "rte_port" data structure.
5915 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
5916 * to be supplied a contiguous array of multicast MAC addresses.
5917 * To comply with this constraint, the set of multicast addresses recorded
5918 * into the pool are systematically compacted at the beginning of the pool.
5919 * Hence, when a multicast address is removed from the pool, all following
5920 * addresses, if any, are copied back to keep the set contiguous.
5922 #define MCAST_POOL_INC 32
5925 mcast_addr_pool_extend(struct rte_port *port)
5927 struct rte_ether_addr *mc_pool;
5928 size_t mc_pool_size;
5931 * If a free entry is available at the end of the pool, just
5932 * increment the number of recorded multicast addresses.
5934 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
5940 * [re]allocate a pool with MCAST_POOL_INC more entries.
5941 * The previous test guarantees that port->mc_addr_nb is a multiple
5942 * of MCAST_POOL_INC.
5944 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
5946 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
5948 if (mc_pool == NULL) {
5950 "allocation of pool of %u multicast addresses failed\n",
5951 port->mc_addr_nb + MCAST_POOL_INC);
5955 port->mc_addr_pool = mc_pool;
5962 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
5964 if (mcast_addr_pool_extend(port) != 0)
5966 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
5970 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
5973 if (addr_idx == port->mc_addr_nb) {
5974 /* No need to recompact the set of multicast addresses. */
5975 if (port->mc_addr_nb == 0) {
5976 /* free the pool of multicast addresses. */
5977 free(port->mc_addr_pool);
5978 port->mc_addr_pool = NULL;
5982 memmove(&port->mc_addr_pool[addr_idx],
5983 &port->mc_addr_pool[addr_idx + 1],
5984 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
5988 eth_port_multicast_addr_list_set(portid_t port_id)
5990 struct rte_port *port;
5993 port = &ports[port_id];
5994 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
5998 "rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
5999 port_id, port->mc_addr_nb, diag);
6005 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
6007 struct rte_port *port;
6010 if (port_id_is_invalid(port_id, ENABLED_WARN))
6013 port = &ports[port_id];
6016 * Check that the added multicast MAC address is not already recorded
6017 * in the pool of multicast addresses.
6019 for (i = 0; i < port->mc_addr_nb; i++) {
6020 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
6022 "multicast address already filtered by port\n");
6027 mcast_addr_pool_append(port, mc_addr);
6028 if (eth_port_multicast_addr_list_set(port_id) < 0)
6029 /* Rollback on failure, remove the address from the pool */
6030 mcast_addr_pool_remove(port, i);
6034 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
6036 struct rte_port *port;
6039 if (port_id_is_invalid(port_id, ENABLED_WARN))
6042 port = &ports[port_id];
6045 * Search the pool of multicast MAC addresses for the removed address.
6047 for (i = 0; i < port->mc_addr_nb; i++) {
6048 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
6051 if (i == port->mc_addr_nb) {
6052 fprintf(stderr, "multicast address not filtered by port %d\n",
6057 mcast_addr_pool_remove(port, i);
6058 if (eth_port_multicast_addr_list_set(port_id) < 0)
6059 /* Rollback on failure, add the address back into the pool */
6060 mcast_addr_pool_append(port, mc_addr);
6064 port_dcb_info_display(portid_t port_id)
6066 struct rte_eth_dcb_info dcb_info;
6069 static const char *border = "================";
6071 if (port_id_is_invalid(port_id, ENABLED_WARN))
6074 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
6076 fprintf(stderr, "\n Failed to get dcb infos on port %-2d\n",
6080 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
6081 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
6083 for (i = 0; i < dcb_info.nb_tcs; i++)
6085 printf("\n Priority : ");
6086 for (i = 0; i < dcb_info.nb_tcs; i++)
6087 printf("\t%4d", dcb_info.prio_tc[i]);
6088 printf("\n BW percent :");
6089 for (i = 0; i < dcb_info.nb_tcs; i++)
6090 printf("\t%4d%%", dcb_info.tc_bws[i]);
6091 printf("\n RXQ base : ");
6092 for (i = 0; i < dcb_info.nb_tcs; i++)
6093 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
6094 printf("\n RXQ number :");
6095 for (i = 0; i < dcb_info.nb_tcs; i++)
6096 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
6097 printf("\n TXQ base : ");
6098 for (i = 0; i < dcb_info.nb_tcs; i++)
6099 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
6100 printf("\n TXQ number :");
6101 for (i = 0; i < dcb_info.nb_tcs; i++)
6102 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
6107 open_file(const char *file_path, uint32_t *size)
6109 int fd = open(file_path, O_RDONLY);
6111 uint8_t *buf = NULL;
6119 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
6123 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
6125 fprintf(stderr, "%s: File operations failed\n", __func__);
6129 pkg_size = st_buf.st_size;
6132 fprintf(stderr, "%s: File operations failed\n", __func__);
6136 buf = (uint8_t *)malloc(pkg_size);
6139 fprintf(stderr, "%s: Failed to malloc memory\n", __func__);
6143 ret = read(fd, buf, pkg_size);
6146 fprintf(stderr, "%s: File read operation failed\n", __func__);
6160 save_file(const char *file_path, uint8_t *buf, uint32_t size)
6162 FILE *fh = fopen(file_path, "wb");
6165 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
6169 if (fwrite(buf, 1, size, fh) != size) {
6171 fprintf(stderr, "%s: File write operation failed\n", __func__);
6181 close_file(uint8_t *buf)
6192 port_queue_region_info_display(portid_t port_id, void *buf)
6196 struct rte_pmd_i40e_queue_regions *info =
6197 (struct rte_pmd_i40e_queue_regions *)buf;
6198 static const char *queue_region_info_stats_border = "-------";
6200 if (!info->queue_region_number)
6201 printf("there is no region has been set before");
6203 printf("\n %s All queue region info for port=%2d %s",
6204 queue_region_info_stats_border, port_id,
6205 queue_region_info_stats_border);
6206 printf("\n queue_region_number: %-14u \n",
6207 info->queue_region_number);
6209 for (i = 0; i < info->queue_region_number; i++) {
6210 printf("\n region_id: %-14u queue_number: %-14u "
6211 "queue_start_index: %-14u \n",
6212 info->region[i].region_id,
6213 info->region[i].queue_num,
6214 info->region[i].queue_start_index);
6216 printf(" user_priority_num is %-14u :",
6217 info->region[i].user_priority_num);
6218 for (j = 0; j < info->region[i].user_priority_num; j++)
6219 printf(" %-14u ", info->region[i].user_priority[j]);
6221 printf("\n flowtype_num is %-14u :",
6222 info->region[i].flowtype_num);
6223 for (j = 0; j < info->region[i].flowtype_num; j++)
6224 printf(" %-14u ", info->region[i].hw_flowtype[j]);
6227 RTE_SET_USED(port_id);
6235 show_macs(portid_t port_id)
6237 char buf[RTE_ETHER_ADDR_FMT_SIZE];
6238 struct rte_eth_dev_info dev_info;
6239 int32_t i, rc, num_macs = 0;
6241 if (eth_dev_info_get_print_err(port_id, &dev_info))
6244 struct rte_ether_addr addr[dev_info.max_mac_addrs];
6245 rc = rte_eth_macaddrs_get(port_id, addr, dev_info.max_mac_addrs);
6249 for (i = 0; i < rc; i++) {
6251 /* skip zero address */
6252 if (rte_is_zero_ether_addr(&addr[i]))
6258 printf("Number of MAC address added: %d\n", num_macs);
6260 for (i = 0; i < rc; i++) {
6262 /* skip zero address */
6263 if (rte_is_zero_ether_addr(&addr[i]))
6266 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &addr[i]);
6267 printf(" %s\n", buf);
6272 show_mcast_macs(portid_t port_id)
6274 char buf[RTE_ETHER_ADDR_FMT_SIZE];
6275 struct rte_ether_addr *addr;
6276 struct rte_port *port;
6279 port = &ports[port_id];
6281 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
6283 for (i = 0; i < port->mc_addr_nb; i++) {
6284 addr = &port->mc_addr_pool[i];
6286 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
6287 printf(" %s\n", buf);