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;
253 static const char *nic_stats_border = "########################";
255 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
259 rte_eth_stats_get(port_id, &stats);
260 printf("\n %s NIC statistics for port %-2d %s\n",
261 nic_stats_border, port_id, nic_stats_border);
263 printf(" RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes: "
264 "%-"PRIu64"\n", stats.ipackets, stats.imissed, stats.ibytes);
265 printf(" RX-errors: %-"PRIu64"\n", stats.ierrors);
266 printf(" RX-nombuf: %-10"PRIu64"\n", stats.rx_nombuf);
267 printf(" TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes: "
268 "%-"PRIu64"\n", stats.opackets, stats.oerrors, stats.obytes);
271 if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
274 ns = cur_time.tv_sec * NS_PER_SEC;
275 ns += cur_time.tv_nsec;
277 if (prev_ns[port_id] != 0)
278 diff_ns = ns - prev_ns[port_id];
279 prev_ns[port_id] = ns;
282 diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ?
283 (stats.ipackets - prev_pkts_rx[port_id]) : 0;
284 diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ?
285 (stats.opackets - prev_pkts_tx[port_id]) : 0;
286 prev_pkts_rx[port_id] = stats.ipackets;
287 prev_pkts_tx[port_id] = stats.opackets;
288 mpps_rx = diff_ns > 0 ?
289 (double)diff_pkts_rx / diff_ns * NS_PER_SEC : 0;
290 mpps_tx = diff_ns > 0 ?
291 (double)diff_pkts_tx / diff_ns * NS_PER_SEC : 0;
293 diff_bytes_rx = (stats.ibytes > prev_bytes_rx[port_id]) ?
294 (stats.ibytes - prev_bytes_rx[port_id]) : 0;
295 diff_bytes_tx = (stats.obytes > prev_bytes_tx[port_id]) ?
296 (stats.obytes - prev_bytes_tx[port_id]) : 0;
297 prev_bytes_rx[port_id] = stats.ibytes;
298 prev_bytes_tx[port_id] = stats.obytes;
299 mbps_rx = diff_ns > 0 ?
300 (double)diff_bytes_rx / diff_ns * NS_PER_SEC : 0;
301 mbps_tx = diff_ns > 0 ?
302 (double)diff_bytes_tx / diff_ns * NS_PER_SEC : 0;
304 printf("\n Throughput (since last show)\n");
305 printf(" Rx-pps: %12"PRIu64" Rx-bps: %12"PRIu64"\n Tx-pps: %12"
306 PRIu64" Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
307 mpps_tx, mbps_tx * 8);
309 if (xstats_display_num > 0)
310 nic_xstats_display_periodic(port_id);
312 printf(" %s############################%s\n",
313 nic_stats_border, nic_stats_border);
317 nic_stats_clear(portid_t port_id)
321 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
326 ret = rte_eth_stats_reset(port_id);
329 "%s: Error: failed to reset stats (port %u): %s",
330 __func__, port_id, strerror(-ret));
334 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
339 "%s: Error: failed to get stats (port %u): %s",
340 __func__, port_id, strerror(ret));
343 printf("\n NIC statistics for port %d cleared\n", port_id);
347 nic_xstats_display(portid_t port_id)
349 struct rte_eth_xstat *xstats;
350 int cnt_xstats, idx_xstat;
351 struct rte_eth_xstat_name *xstats_names;
353 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
357 printf("###### NIC extended statistics for port %-2d\n", port_id);
358 if (!rte_eth_dev_is_valid_port(port_id)) {
359 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
364 cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0);
365 if (cnt_xstats < 0) {
366 fprintf(stderr, "Error: Cannot get count of xstats\n");
370 /* Get id-name lookup table */
371 xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
372 if (xstats_names == NULL) {
373 fprintf(stderr, "Cannot allocate memory for xstats lookup\n");
376 if (cnt_xstats != rte_eth_xstats_get_names(
377 port_id, xstats_names, cnt_xstats)) {
378 fprintf(stderr, "Error: Cannot get xstats lookup\n");
383 /* Get stats themselves */
384 xstats = malloc(sizeof(struct rte_eth_xstat) * cnt_xstats);
385 if (xstats == NULL) {
386 fprintf(stderr, "Cannot allocate memory for xstats\n");
390 if (cnt_xstats != rte_eth_xstats_get(port_id, xstats, cnt_xstats)) {
391 fprintf(stderr, "Error: Unable to get xstats\n");
398 for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
399 if (xstats_hide_zero && !xstats[idx_xstat].value)
401 printf("%s: %"PRIu64"\n",
402 xstats_names[idx_xstat].name,
403 xstats[idx_xstat].value);
410 nic_xstats_clear(portid_t port_id)
414 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
419 ret = rte_eth_xstats_reset(port_id);
422 "%s: Error: failed to reset xstats (port %u): %s\n",
423 __func__, port_id, strerror(-ret));
427 ret = rte_eth_stats_get(port_id, &ports[port_id].stats);
431 fprintf(stderr, "%s: Error: failed to get stats (port %u): %s",
432 __func__, port_id, strerror(ret));
438 get_queue_state_name(uint8_t queue_state)
440 if (queue_state == RTE_ETH_QUEUE_STATE_STOPPED)
442 else if (queue_state == RTE_ETH_QUEUE_STATE_STARTED)
444 else if (queue_state == RTE_ETH_QUEUE_STATE_HAIRPIN)
451 rx_queue_infos_display(portid_t port_id, uint16_t queue_id)
453 struct rte_eth_burst_mode mode;
454 struct rte_eth_rxq_info qinfo;
456 static const char *info_border = "*********************";
458 rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo);
461 "Failed to retrieve information for port: %u, RX queue: %hu\nerror desc: %s(%d)\n",
462 port_id, queue_id, strerror(-rc), rc);
466 printf("\n%s Infos for port %-2u, RX queue %-2u %s",
467 info_border, port_id, queue_id, info_border);
469 printf("\nMempool: %s", (qinfo.mp == NULL) ? "NULL" : qinfo.mp->name);
470 printf("\nRX prefetch threshold: %hhu", qinfo.conf.rx_thresh.pthresh);
471 printf("\nRX host threshold: %hhu", qinfo.conf.rx_thresh.hthresh);
472 printf("\nRX writeback threshold: %hhu", qinfo.conf.rx_thresh.wthresh);
473 printf("\nRX free threshold: %hu", qinfo.conf.rx_free_thresh);
474 printf("\nRX drop packets: %s",
475 (qinfo.conf.rx_drop_en != 0) ? "on" : "off");
476 printf("\nRX deferred start: %s",
477 (qinfo.conf.rx_deferred_start != 0) ? "on" : "off");
478 printf("\nRX scattered packets: %s",
479 (qinfo.scattered_rx != 0) ? "on" : "off");
480 printf("\nRx queue state: %s", get_queue_state_name(qinfo.queue_state));
481 if (qinfo.rx_buf_size != 0)
482 printf("\nRX buffer size: %hu", qinfo.rx_buf_size);
483 printf("\nNumber of RXDs: %hu", qinfo.nb_desc);
485 if (rte_eth_rx_burst_mode_get(port_id, queue_id, &mode) == 0)
486 printf("\nBurst mode: %s%s",
488 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
489 " (per queue)" : "");
495 tx_queue_infos_display(portid_t port_id, uint16_t queue_id)
497 struct rte_eth_burst_mode mode;
498 struct rte_eth_txq_info qinfo;
500 static const char *info_border = "*********************";
502 rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo);
505 "Failed to retrieve information for port: %u, TX queue: %hu\nerror desc: %s(%d)\n",
506 port_id, queue_id, strerror(-rc), rc);
510 printf("\n%s Infos for port %-2u, TX queue %-2u %s",
511 info_border, port_id, queue_id, info_border);
513 printf("\nTX prefetch threshold: %hhu", qinfo.conf.tx_thresh.pthresh);
514 printf("\nTX host threshold: %hhu", qinfo.conf.tx_thresh.hthresh);
515 printf("\nTX writeback threshold: %hhu", qinfo.conf.tx_thresh.wthresh);
516 printf("\nTX RS threshold: %hu", qinfo.conf.tx_rs_thresh);
517 printf("\nTX free threshold: %hu", qinfo.conf.tx_free_thresh);
518 printf("\nTX deferred start: %s",
519 (qinfo.conf.tx_deferred_start != 0) ? "on" : "off");
520 printf("\nNumber of TXDs: %hu", qinfo.nb_desc);
521 printf("\nTx queue state: %s", get_queue_state_name(qinfo.queue_state));
523 if (rte_eth_tx_burst_mode_get(port_id, queue_id, &mode) == 0)
524 printf("\nBurst mode: %s%s",
526 mode.flags & RTE_ETH_BURST_FLAG_PER_QUEUE ?
527 " (per queue)" : "");
532 static int bus_match_all(const struct rte_bus *bus, const void *data)
540 device_infos_display_speeds(uint32_t speed_capa)
542 printf("\n\tDevice speed capability:");
543 if (speed_capa == RTE_ETH_LINK_SPEED_AUTONEG)
544 printf(" Autonegotiate (all speeds)");
545 if (speed_capa & RTE_ETH_LINK_SPEED_FIXED)
546 printf(" Disable autonegotiate (fixed speed) ");
547 if (speed_capa & RTE_ETH_LINK_SPEED_10M_HD)
548 printf(" 10 Mbps half-duplex ");
549 if (speed_capa & RTE_ETH_LINK_SPEED_10M)
550 printf(" 10 Mbps full-duplex ");
551 if (speed_capa & RTE_ETH_LINK_SPEED_100M_HD)
552 printf(" 100 Mbps half-duplex ");
553 if (speed_capa & RTE_ETH_LINK_SPEED_100M)
554 printf(" 100 Mbps full-duplex ");
555 if (speed_capa & RTE_ETH_LINK_SPEED_1G)
557 if (speed_capa & RTE_ETH_LINK_SPEED_2_5G)
558 printf(" 2.5 Gbps ");
559 if (speed_capa & RTE_ETH_LINK_SPEED_5G)
561 if (speed_capa & RTE_ETH_LINK_SPEED_10G)
563 if (speed_capa & RTE_ETH_LINK_SPEED_20G)
565 if (speed_capa & RTE_ETH_LINK_SPEED_25G)
567 if (speed_capa & RTE_ETH_LINK_SPEED_40G)
569 if (speed_capa & RTE_ETH_LINK_SPEED_50G)
571 if (speed_capa & RTE_ETH_LINK_SPEED_56G)
573 if (speed_capa & RTE_ETH_LINK_SPEED_100G)
574 printf(" 100 Gbps ");
575 if (speed_capa & RTE_ETH_LINK_SPEED_200G)
576 printf(" 200 Gbps ");
580 device_infos_display(const char *identifier)
582 static const char *info_border = "*********************";
583 struct rte_bus *start = NULL, *next;
584 struct rte_dev_iterator dev_iter;
585 char name[RTE_ETH_NAME_MAX_LEN];
586 struct rte_ether_addr mac_addr;
587 struct rte_device *dev;
588 struct rte_devargs da;
590 struct rte_eth_dev_info dev_info;
593 memset(&da, 0, sizeof(da));
597 if (rte_devargs_parsef(&da, "%s", identifier)) {
598 fprintf(stderr, "cannot parse identifier\n");
603 while ((next = rte_bus_find(start, bus_match_all, NULL)) != NULL) {
606 if (identifier && da.bus != next)
609 /* Skip buses that don't have iterate method */
610 if (!next->dev_iterate)
613 snprintf(devstr, sizeof(devstr), "bus=%s", next->name);
614 RTE_DEV_FOREACH(dev, devstr, &dev_iter) {
618 /* Check for matching device if identifier is present */
620 strncmp(da.name, dev->name, strlen(dev->name)))
622 printf("\n%s Infos for device %s %s\n",
623 info_border, dev->name, info_border);
624 printf("Bus name: %s", dev->bus->name);
625 printf("\nDriver name: %s", dev->driver->name);
626 printf("\nDevargs: %s",
627 dev->devargs ? dev->devargs->args : "");
628 printf("\nConnect to socket: %d", dev->numa_node);
631 /* List ports with matching device name */
632 RTE_ETH_FOREACH_DEV_OF(port_id, dev) {
633 printf("\n\tPort id: %-2d", port_id);
634 if (eth_macaddr_get_print_err(port_id,
636 print_ethaddr("\n\tMAC address: ",
638 rte_eth_dev_get_name_by_port(port_id, name);
639 printf("\n\tDevice name: %s", name);
640 if (rte_eth_dev_info_get(port_id, &dev_info) == 0)
641 device_infos_display_speeds(dev_info.speed_capa);
646 rte_devargs_reset(&da);
650 print_dev_capabilities(uint64_t capabilities)
652 uint64_t single_capa;
657 if (capabilities == 0)
660 begin = __builtin_ctzll(capabilities);
661 end = sizeof(capabilities) * CHAR_BIT - __builtin_clzll(capabilities);
663 single_capa = 1ULL << begin;
664 for (bit = begin; bit < end; bit++) {
665 if (capabilities & single_capa)
667 rte_eth_dev_capability_name(single_capa));
673 port_infos_display(portid_t port_id)
675 struct rte_port *port;
676 struct rte_ether_addr mac_addr;
677 struct rte_eth_link link;
678 struct rte_eth_dev_info dev_info;
680 struct rte_mempool * mp;
681 static const char *info_border = "*********************";
683 char name[RTE_ETH_NAME_MAX_LEN];
685 char fw_version[ETHDEV_FWVERS_LEN];
687 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
691 port = &ports[port_id];
692 ret = eth_link_get_nowait_print_err(port_id, &link);
696 ret = eth_dev_info_get_print_err(port_id, &dev_info);
700 printf("\n%s Infos for port %-2d %s\n",
701 info_border, port_id, info_border);
702 if (eth_macaddr_get_print_err(port_id, &mac_addr) == 0)
703 print_ethaddr("MAC address: ", &mac_addr);
704 rte_eth_dev_get_name_by_port(port_id, name);
705 printf("\nDevice name: %s", name);
706 printf("\nDriver name: %s", dev_info.driver_name);
708 if (rte_eth_dev_fw_version_get(port_id, fw_version,
709 ETHDEV_FWVERS_LEN) == 0)
710 printf("\nFirmware-version: %s", fw_version);
712 printf("\nFirmware-version: %s", "not available");
714 if (dev_info.device->devargs && dev_info.device->devargs->args)
715 printf("\nDevargs: %s", dev_info.device->devargs->args);
716 printf("\nConnect to socket: %u", port->socket_id);
718 if (port_numa[port_id] != NUMA_NO_CONFIG) {
719 mp = mbuf_pool_find(port_numa[port_id], 0);
721 printf("\nmemory allocation on the socket: %d",
724 printf("\nmemory allocation on the socket: %u",port->socket_id);
726 printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
727 printf("Link speed: %s\n", rte_eth_link_speed_to_str(link.link_speed));
728 printf("Link duplex: %s\n", (link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
729 ("full-duplex") : ("half-duplex"));
730 printf("Autoneg status: %s\n", (link.link_autoneg == RTE_ETH_LINK_AUTONEG) ?
733 if (!rte_eth_dev_get_mtu(port_id, &mtu))
734 printf("MTU: %u\n", mtu);
736 printf("Promiscuous mode: %s\n",
737 rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
738 printf("Allmulticast mode: %s\n",
739 rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
740 printf("Maximum number of MAC addresses: %u\n",
741 (unsigned int)(port->dev_info.max_mac_addrs));
742 printf("Maximum number of MAC addresses of hash filtering: %u\n",
743 (unsigned int)(port->dev_info.max_hash_mac_addrs));
745 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
746 if (vlan_offload >= 0){
747 printf("VLAN offload: \n");
748 if (vlan_offload & RTE_ETH_VLAN_STRIP_OFFLOAD)
749 printf(" strip on, ");
751 printf(" strip off, ");
753 if (vlan_offload & RTE_ETH_VLAN_FILTER_OFFLOAD)
754 printf("filter on, ");
756 printf("filter off, ");
758 if (vlan_offload & RTE_ETH_VLAN_EXTEND_OFFLOAD)
759 printf("extend on, ");
761 printf("extend off, ");
763 if (vlan_offload & RTE_ETH_QINQ_STRIP_OFFLOAD)
764 printf("qinq strip on\n");
766 printf("qinq strip off\n");
769 if (dev_info.hash_key_size > 0)
770 printf("Hash key size in bytes: %u\n", dev_info.hash_key_size);
771 if (dev_info.reta_size > 0)
772 printf("Redirection table size: %u\n", dev_info.reta_size);
773 if (!dev_info.flow_type_rss_offloads)
774 printf("No RSS offload flow type is supported.\n");
779 printf("Supported RSS offload flow types:\n");
780 for (i = RTE_ETH_FLOW_UNKNOWN + 1;
781 i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) {
782 if (!(dev_info.flow_type_rss_offloads & (1ULL << i)))
784 p = flowtype_to_str(i);
788 printf(" user defined %d\n", i);
792 printf("Minimum size of RX buffer: %u\n", dev_info.min_rx_bufsize);
793 printf("Maximum configurable length of RX packet: %u\n",
794 dev_info.max_rx_pktlen);
795 printf("Maximum configurable size of LRO aggregated packet: %u\n",
796 dev_info.max_lro_pkt_size);
797 if (dev_info.max_vfs)
798 printf("Maximum number of VFs: %u\n", dev_info.max_vfs);
799 if (dev_info.max_vmdq_pools)
800 printf("Maximum number of VMDq pools: %u\n",
801 dev_info.max_vmdq_pools);
803 printf("Current number of RX queues: %u\n", dev_info.nb_rx_queues);
804 printf("Max possible RX queues: %u\n", dev_info.max_rx_queues);
805 printf("Max possible number of RXDs per queue: %hu\n",
806 dev_info.rx_desc_lim.nb_max);
807 printf("Min possible number of RXDs per queue: %hu\n",
808 dev_info.rx_desc_lim.nb_min);
809 printf("RXDs number alignment: %hu\n", dev_info.rx_desc_lim.nb_align);
811 printf("Current number of TX queues: %u\n", dev_info.nb_tx_queues);
812 printf("Max possible TX queues: %u\n", dev_info.max_tx_queues);
813 printf("Max possible number of TXDs per queue: %hu\n",
814 dev_info.tx_desc_lim.nb_max);
815 printf("Min possible number of TXDs per queue: %hu\n",
816 dev_info.tx_desc_lim.nb_min);
817 printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
818 printf("Max segment number per packet: %hu\n",
819 dev_info.tx_desc_lim.nb_seg_max);
820 printf("Max segment number per MTU/TSO: %hu\n",
821 dev_info.tx_desc_lim.nb_mtu_seg_max);
823 printf("Device capabilities: 0x%"PRIx64"(", dev_info.dev_capa);
824 print_dev_capabilities(dev_info.dev_capa);
826 /* Show switch info only if valid switch domain and port id is set */
827 if (dev_info.switch_info.domain_id !=
828 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
829 if (dev_info.switch_info.name)
830 printf("Switch name: %s\n", dev_info.switch_info.name);
832 printf("Switch domain Id: %u\n",
833 dev_info.switch_info.domain_id);
834 printf("Switch Port Id: %u\n",
835 dev_info.switch_info.port_id);
836 if ((dev_info.dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE) != 0)
837 printf("Switch Rx domain: %u\n",
838 dev_info.switch_info.rx_domain);
843 port_summary_header_display(void)
845 uint16_t port_number;
847 port_number = rte_eth_dev_count_avail();
848 printf("Number of available ports: %i\n", port_number);
849 printf("%-4s %-17s %-12s %-14s %-8s %s\n", "Port", "MAC Address", "Name",
850 "Driver", "Status", "Link");
854 port_summary_display(portid_t port_id)
856 struct rte_ether_addr mac_addr;
857 struct rte_eth_link link;
858 struct rte_eth_dev_info dev_info;
859 char name[RTE_ETH_NAME_MAX_LEN];
862 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
867 ret = eth_link_get_nowait_print_err(port_id, &link);
871 ret = eth_dev_info_get_print_err(port_id, &dev_info);
875 rte_eth_dev_get_name_by_port(port_id, name);
876 ret = eth_macaddr_get_print_err(port_id, &mac_addr);
880 printf("%-4d " RTE_ETHER_ADDR_PRT_FMT " %-12s %-14s %-8s %s\n",
881 port_id, RTE_ETHER_ADDR_BYTES(&mac_addr), name,
882 dev_info.driver_name, (link.link_status) ? ("up") : ("down"),
883 rte_eth_link_speed_to_str(link.link_speed));
887 port_eeprom_display(portid_t port_id)
889 struct rte_dev_eeprom_info einfo;
891 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
896 int len_eeprom = rte_eth_dev_get_eeprom_length(port_id);
897 if (len_eeprom < 0) {
898 switch (len_eeprom) {
900 fprintf(stderr, "port index %d invalid\n", port_id);
903 fprintf(stderr, "operation not supported by device\n");
906 fprintf(stderr, "device is removed\n");
909 fprintf(stderr, "Unable to get EEPROM: %d\n",
917 einfo.length = len_eeprom;
918 einfo.data = calloc(1, len_eeprom);
921 "Allocation of port %u eeprom data failed\n",
926 ret = rte_eth_dev_get_eeprom(port_id, &einfo);
930 fprintf(stderr, "port index %d invalid\n", port_id);
933 fprintf(stderr, "operation not supported by device\n");
936 fprintf(stderr, "device is removed\n");
939 fprintf(stderr, "Unable to get EEPROM: %d\n", ret);
945 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
946 printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
951 port_module_eeprom_display(portid_t port_id)
953 struct rte_eth_dev_module_info minfo;
954 struct rte_dev_eeprom_info einfo;
957 if (port_id_is_invalid(port_id, ENABLED_WARN)) {
963 ret = rte_eth_dev_get_module_info(port_id, &minfo);
967 fprintf(stderr, "port index %d invalid\n", port_id);
970 fprintf(stderr, "operation not supported by device\n");
973 fprintf(stderr, "device is removed\n");
976 fprintf(stderr, "Unable to get module EEPROM: %d\n",
984 einfo.length = minfo.eeprom_len;
985 einfo.data = calloc(1, minfo.eeprom_len);
988 "Allocation of port %u eeprom data failed\n",
993 ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
997 fprintf(stderr, "port index %d invalid\n", port_id);
1000 fprintf(stderr, "operation not supported by device\n");
1003 fprintf(stderr, "device is removed\n");
1006 fprintf(stderr, "Unable to get module EEPROM: %d\n",
1014 rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
1015 printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
1020 port_id_is_invalid(portid_t port_id, enum print_warning warning)
1024 if (port_id == (portid_t)RTE_PORT_ALL)
1027 RTE_ETH_FOREACH_DEV(pid)
1031 if (warning == ENABLED_WARN)
1032 fprintf(stderr, "Invalid port %d\n", port_id);
1037 void print_valid_ports(void)
1041 printf("The valid ports array is [");
1042 RTE_ETH_FOREACH_DEV(pid) {
1049 vlan_id_is_invalid(uint16_t vlan_id)
1053 fprintf(stderr, "Invalid vlan_id %d (must be < 4096)\n", vlan_id);
1058 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
1060 const struct rte_pci_device *pci_dev;
1061 const struct rte_bus *bus;
1064 if (reg_off & 0x3) {
1066 "Port register offset 0x%X not aligned on a 4-byte boundary\n",
1067 (unsigned int)reg_off);
1071 if (!ports[port_id].dev_info.device) {
1072 fprintf(stderr, "Invalid device\n");
1076 bus = rte_bus_find_by_device(ports[port_id].dev_info.device);
1077 if (bus && !strcmp(bus->name, "pci")) {
1078 pci_dev = RTE_DEV_TO_PCI(ports[port_id].dev_info.device);
1080 fprintf(stderr, "Not a PCI device\n");
1084 pci_len = pci_dev->mem_resource[0].len;
1085 if (reg_off >= pci_len) {
1087 "Port %d: register offset %u (0x%X) out of port PCI resource (length=%"PRIu64")\n",
1088 port_id, (unsigned int)reg_off, (unsigned int)reg_off,
1096 reg_bit_pos_is_invalid(uint8_t bit_pos)
1100 fprintf(stderr, "Invalid bit position %d (must be <= 31)\n", bit_pos);
1104 #define display_port_and_reg_off(port_id, reg_off) \
1105 printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
1108 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1110 display_port_and_reg_off(port_id, (unsigned)reg_off);
1111 printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
1115 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
1120 if (port_id_is_invalid(port_id, ENABLED_WARN))
1122 if (port_reg_off_is_invalid(port_id, reg_off))
1124 if (reg_bit_pos_is_invalid(bit_x))
1126 reg_v = port_id_pci_reg_read(port_id, reg_off);
1127 display_port_and_reg_off(port_id, (unsigned)reg_off);
1128 printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
1132 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
1133 uint8_t bit1_pos, uint8_t bit2_pos)
1139 if (port_id_is_invalid(port_id, ENABLED_WARN))
1141 if (port_reg_off_is_invalid(port_id, reg_off))
1143 if (reg_bit_pos_is_invalid(bit1_pos))
1145 if (reg_bit_pos_is_invalid(bit2_pos))
1147 if (bit1_pos > bit2_pos)
1148 l_bit = bit2_pos, h_bit = bit1_pos;
1150 l_bit = bit1_pos, h_bit = bit2_pos;
1152 reg_v = port_id_pci_reg_read(port_id, reg_off);
1155 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
1156 display_port_and_reg_off(port_id, (unsigned)reg_off);
1157 printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
1158 ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
1162 port_reg_display(portid_t port_id, uint32_t reg_off)
1166 if (port_id_is_invalid(port_id, ENABLED_WARN))
1168 if (port_reg_off_is_invalid(port_id, reg_off))
1170 reg_v = port_id_pci_reg_read(port_id, reg_off);
1171 display_port_reg_value(port_id, reg_off, reg_v);
1175 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
1180 if (port_id_is_invalid(port_id, ENABLED_WARN))
1182 if (port_reg_off_is_invalid(port_id, reg_off))
1184 if (reg_bit_pos_is_invalid(bit_pos))
1187 fprintf(stderr, "Invalid bit value %d (must be 0 or 1)\n",
1191 reg_v = port_id_pci_reg_read(port_id, reg_off);
1193 reg_v &= ~(1 << bit_pos);
1195 reg_v |= (1 << bit_pos);
1196 port_id_pci_reg_write(port_id, reg_off, reg_v);
1197 display_port_reg_value(port_id, reg_off, reg_v);
1201 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
1202 uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
1209 if (port_id_is_invalid(port_id, ENABLED_WARN))
1211 if (port_reg_off_is_invalid(port_id, reg_off))
1213 if (reg_bit_pos_is_invalid(bit1_pos))
1215 if (reg_bit_pos_is_invalid(bit2_pos))
1217 if (bit1_pos > bit2_pos)
1218 l_bit = bit2_pos, h_bit = bit1_pos;
1220 l_bit = bit1_pos, h_bit = bit2_pos;
1222 if ((h_bit - l_bit) < 31)
1223 max_v = (1 << (h_bit - l_bit + 1)) - 1;
1227 if (value > max_v) {
1228 fprintf(stderr, "Invalid value %u (0x%x) must be < %u (0x%x)\n",
1229 (unsigned)value, (unsigned)value,
1230 (unsigned)max_v, (unsigned)max_v);
1233 reg_v = port_id_pci_reg_read(port_id, reg_off);
1234 reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
1235 reg_v |= (value << l_bit); /* Set changed bits */
1236 port_id_pci_reg_write(port_id, reg_off, reg_v);
1237 display_port_reg_value(port_id, reg_off, reg_v);
1241 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
1243 if (port_id_is_invalid(port_id, ENABLED_WARN))
1245 if (port_reg_off_is_invalid(port_id, reg_off))
1247 port_id_pci_reg_write(port_id, reg_off, reg_v);
1248 display_port_reg_value(port_id, reg_off, reg_v);
1252 port_mtu_set(portid_t port_id, uint16_t mtu)
1254 struct rte_port *port = &ports[port_id];
1257 if (port_id_is_invalid(port_id, ENABLED_WARN))
1260 if (port->need_reconfig == 0) {
1261 diag = rte_eth_dev_set_mtu(port_id, mtu);
1263 fprintf(stderr, "Set MTU failed. diag=%d\n", diag);
1268 port->dev_conf.rxmode.mtu = mtu;
1271 /* Generic flow management functions. */
1273 static struct port_flow_tunnel *
1274 port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
1276 struct port_flow_tunnel *flow_tunnel;
1278 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1279 if (flow_tunnel->id == port_tunnel_id)
1289 port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
1292 switch (tunnel->type) {
1296 case RTE_FLOW_ITEM_TYPE_VXLAN:
1299 case RTE_FLOW_ITEM_TYPE_GRE:
1302 case RTE_FLOW_ITEM_TYPE_NVGRE:
1305 case RTE_FLOW_ITEM_TYPE_GENEVE:
1313 struct port_flow_tunnel *
1314 port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
1316 struct rte_port *port = &ports[port_id];
1317 struct port_flow_tunnel *flow_tunnel;
1319 LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
1320 if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
1329 void port_flow_tunnel_list(portid_t port_id)
1331 struct rte_port *port = &ports[port_id];
1332 struct port_flow_tunnel *flt;
1334 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1335 printf("port %u tunnel #%u type=%s",
1336 port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
1337 if (flt->tunnel.tun_id)
1338 printf(" id=%" PRIu64, flt->tunnel.tun_id);
1343 void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
1345 struct rte_port *port = &ports[port_id];
1346 struct port_flow_tunnel *flt;
1348 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1349 if (flt->id == tunnel_id)
1353 LIST_REMOVE(flt, chain);
1355 printf("port %u: flow tunnel #%u destroyed\n",
1356 port_id, tunnel_id);
1360 void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
1362 struct rte_port *port = &ports[port_id];
1363 enum rte_flow_item_type type;
1364 struct port_flow_tunnel *flt;
1366 if (!strcmp(ops->type, "vxlan"))
1367 type = RTE_FLOW_ITEM_TYPE_VXLAN;
1368 else if (!strcmp(ops->type, "gre"))
1369 type = RTE_FLOW_ITEM_TYPE_GRE;
1370 else if (!strcmp(ops->type, "nvgre"))
1371 type = RTE_FLOW_ITEM_TYPE_NVGRE;
1372 else if (!strcmp(ops->type, "geneve"))
1373 type = RTE_FLOW_ITEM_TYPE_GENEVE;
1375 fprintf(stderr, "cannot offload \"%s\" tunnel type\n",
1379 LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
1380 if (flt->tunnel.type == type)
1384 flt = calloc(1, sizeof(*flt));
1386 fprintf(stderr, "failed to allocate port flt object\n");
1389 flt->tunnel.type = type;
1390 flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
1391 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
1392 LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
1394 printf("port %d: flow tunnel #%u type %s\n",
1395 port_id, flt->id, ops->type);
1398 /** Generate a port_flow entry from attributes/pattern/actions. */
1399 static struct port_flow *
1400 port_flow_new(const struct rte_flow_attr *attr,
1401 const struct rte_flow_item *pattern,
1402 const struct rte_flow_action *actions,
1403 struct rte_flow_error *error)
1405 const struct rte_flow_conv_rule rule = {
1407 .pattern_ro = pattern,
1408 .actions_ro = actions,
1410 struct port_flow *pf;
1413 ret = rte_flow_conv(RTE_FLOW_CONV_OP_RULE, NULL, 0, &rule, error);
1416 pf = calloc(1, offsetof(struct port_flow, rule) + ret);
1419 (error, errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1423 if (rte_flow_conv(RTE_FLOW_CONV_OP_RULE, &pf->rule, ret, &rule,
1430 /** Print a message out of a flow error. */
1432 port_flow_complain(struct rte_flow_error *error)
1434 static const char *const errstrlist[] = {
1435 [RTE_FLOW_ERROR_TYPE_NONE] = "no error",
1436 [RTE_FLOW_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
1437 [RTE_FLOW_ERROR_TYPE_HANDLE] = "flow rule (handle)",
1438 [RTE_FLOW_ERROR_TYPE_ATTR_GROUP] = "group field",
1439 [RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY] = "priority field",
1440 [RTE_FLOW_ERROR_TYPE_ATTR_INGRESS] = "ingress field",
1441 [RTE_FLOW_ERROR_TYPE_ATTR_EGRESS] = "egress field",
1442 [RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER] = "transfer field",
1443 [RTE_FLOW_ERROR_TYPE_ATTR] = "attributes structure",
1444 [RTE_FLOW_ERROR_TYPE_ITEM_NUM] = "pattern length",
1445 [RTE_FLOW_ERROR_TYPE_ITEM_SPEC] = "item specification",
1446 [RTE_FLOW_ERROR_TYPE_ITEM_LAST] = "item specification range",
1447 [RTE_FLOW_ERROR_TYPE_ITEM_MASK] = "item specification mask",
1448 [RTE_FLOW_ERROR_TYPE_ITEM] = "specific pattern item",
1449 [RTE_FLOW_ERROR_TYPE_ACTION_NUM] = "number of actions",
1450 [RTE_FLOW_ERROR_TYPE_ACTION_CONF] = "action configuration",
1451 [RTE_FLOW_ERROR_TYPE_ACTION] = "specific action",
1455 int err = rte_errno;
1457 if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
1458 !errstrlist[error->type])
1459 errstr = "unknown type";
1461 errstr = errstrlist[error->type];
1462 fprintf(stderr, "%s(): Caught PMD error type %d (%s): %s%s: %s\n",
1463 __func__, error->type, errstr,
1464 error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
1465 error->cause), buf) : "",
1466 error->message ? error->message : "(no stated reason)",
1469 switch (error->type) {
1470 case RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER:
1471 fprintf(stderr, "The status suggests the use of \"transfer\" "
1472 "as the possible cause of the failure. Make "
1473 "sure that the flow in question and its "
1474 "indirect components (if any) are managed "
1475 "via \"transfer\" proxy port. Use command "
1476 "\"show port (port_id) flow transfer proxy\" "
1477 "to figure out the proxy port ID\n");
1487 rss_config_display(struct rte_flow_action_rss *rss_conf)
1491 if (rss_conf == NULL) {
1492 fprintf(stderr, "Invalid rule\n");
1498 if (rss_conf->queue_num == 0)
1500 for (i = 0; i < rss_conf->queue_num; i++)
1501 printf(" %d", rss_conf->queue[i]);
1504 printf(" function: ");
1505 switch (rss_conf->func) {
1506 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1507 printf("default\n");
1509 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1510 printf("toeplitz\n");
1512 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1513 printf("simple_xor\n");
1515 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1516 printf("symmetric_toeplitz\n");
1519 printf("Unknown function\n");
1523 printf(" types:\n");
1524 if (rss_conf->types == 0) {
1528 for (i = 0; rss_type_table[i].str; i++) {
1529 if ((rss_conf->types &
1530 rss_type_table[i].rss_type) ==
1531 rss_type_table[i].rss_type &&
1532 rss_type_table[i].rss_type != 0)
1533 printf(" %s\n", rss_type_table[i].str);
1537 static struct port_indirect_action *
1538 action_get_by_id(portid_t port_id, uint32_t id)
1540 struct rte_port *port;
1541 struct port_indirect_action **ppia;
1542 struct port_indirect_action *pia = NULL;
1544 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1545 port_id == (portid_t)RTE_PORT_ALL)
1547 port = &ports[port_id];
1548 ppia = &port->actions_list;
1550 if ((*ppia)->id == id) {
1554 ppia = &(*ppia)->next;
1558 "Failed to find indirect action #%u on port %u\n",
1564 action_alloc(portid_t port_id, uint32_t id,
1565 struct port_indirect_action **action)
1567 struct rte_port *port;
1568 struct port_indirect_action **ppia;
1569 struct port_indirect_action *pia = NULL;
1572 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1573 port_id == (portid_t)RTE_PORT_ALL)
1575 port = &ports[port_id];
1576 if (id == UINT32_MAX) {
1577 /* taking first available ID */
1578 if (port->actions_list) {
1579 if (port->actions_list->id == UINT32_MAX - 1) {
1581 "Highest indirect action ID is already assigned, delete it first\n");
1584 id = port->actions_list->id + 1;
1589 pia = calloc(1, sizeof(*pia));
1592 "Allocation of port %u indirect action failed\n",
1596 ppia = &port->actions_list;
1597 while (*ppia && (*ppia)->id > id)
1598 ppia = &(*ppia)->next;
1599 if (*ppia && (*ppia)->id == id) {
1601 "Indirect action #%u is already assigned, delete it first\n",
1614 template_alloc(uint32_t id, struct port_template **template,
1615 struct port_template **list)
1617 struct port_template *lst = *list;
1618 struct port_template **ppt;
1619 struct port_template *pt = NULL;
1622 if (id == UINT32_MAX) {
1623 /* taking first available ID */
1625 if (lst->id == UINT32_MAX - 1) {
1626 printf("Highest template ID is already"
1627 " assigned, delete it first\n");
1635 pt = calloc(1, sizeof(*pt));
1637 printf("Allocation of port template failed\n");
1641 while (*ppt && (*ppt)->id > id)
1642 ppt = &(*ppt)->next;
1643 if (*ppt && (*ppt)->id == id) {
1644 printf("Template #%u is already assigned,"
1645 " delete it first\n", id);
1657 table_alloc(uint32_t id, struct port_table **table,
1658 struct port_table **list)
1660 struct port_table *lst = *list;
1661 struct port_table **ppt;
1662 struct port_table *pt = NULL;
1665 if (id == UINT32_MAX) {
1666 /* taking first available ID */
1668 if (lst->id == UINT32_MAX - 1) {
1669 printf("Highest table ID is already"
1670 " assigned, delete it first\n");
1678 pt = calloc(1, sizeof(*pt));
1680 printf("Allocation of table failed\n");
1684 while (*ppt && (*ppt)->id > id)
1685 ppt = &(*ppt)->next;
1686 if (*ppt && (*ppt)->id == id) {
1687 printf("Table #%u is already assigned,"
1688 " delete it first\n", id);
1699 /** Get info about flow management resources. */
1701 port_flow_get_info(portid_t port_id)
1703 struct rte_flow_port_info port_info;
1704 struct rte_flow_queue_info queue_info;
1705 struct rte_flow_error error;
1707 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1708 port_id == (portid_t)RTE_PORT_ALL)
1710 /* Poisoning to make sure PMDs update it in case of error. */
1711 memset(&error, 0x99, sizeof(error));
1712 memset(&port_info, 0, sizeof(port_info));
1713 memset(&queue_info, 0, sizeof(queue_info));
1714 if (rte_flow_info_get(port_id, &port_info, &queue_info, &error))
1715 return port_flow_complain(&error);
1716 printf("Flow engine resources on port %u:\n"
1717 "Number of queues: %d\n"
1718 "Size of queues: %d\n"
1719 "Number of counters: %d\n"
1720 "Number of aging objects: %d\n"
1721 "Number of meter actions: %d\n",
1722 port_id, port_info.max_nb_queues,
1723 queue_info.max_size,
1724 port_info.max_nb_counters,
1725 port_info.max_nb_aging_objects,
1726 port_info.max_nb_meters);
1730 /** Configure flow management resources. */
1732 port_flow_configure(portid_t port_id,
1733 const struct rte_flow_port_attr *port_attr,
1735 const struct rte_flow_queue_attr *queue_attr)
1737 struct rte_port *port;
1738 struct rte_flow_error error;
1739 const struct rte_flow_queue_attr *attr_list[nb_queue];
1742 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1743 port_id == (portid_t)RTE_PORT_ALL)
1745 port = &ports[port_id];
1746 port->queue_nb = nb_queue;
1747 port->queue_sz = queue_attr->size;
1748 for (std_queue = 0; std_queue < nb_queue; std_queue++)
1749 attr_list[std_queue] = queue_attr;
1750 /* Poisoning to make sure PMDs update it in case of error. */
1751 memset(&error, 0x66, sizeof(error));
1752 if (rte_flow_configure(port_id, port_attr, nb_queue, attr_list, &error))
1753 return port_flow_complain(&error);
1754 printf("Configure flows on port %u: "
1755 "number of queues %d with %d elements\n",
1756 port_id, nb_queue, queue_attr->size);
1760 /** Create indirect action */
1762 port_action_handle_create(portid_t port_id, uint32_t id,
1763 const struct rte_flow_indir_action_conf *conf,
1764 const struct rte_flow_action *action)
1766 struct port_indirect_action *pia;
1768 struct rte_flow_error error;
1770 ret = action_alloc(port_id, id, &pia);
1773 if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
1774 struct rte_flow_action_age *age =
1775 (struct rte_flow_action_age *)(uintptr_t)(action->conf);
1777 pia->age_type = ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION;
1778 age->context = &pia->age_type;
1779 } else if (action->type == RTE_FLOW_ACTION_TYPE_CONNTRACK) {
1780 struct rte_flow_action_conntrack *ct =
1781 (struct rte_flow_action_conntrack *)(uintptr_t)(action->conf);
1783 memcpy(ct, &conntrack_context, sizeof(*ct));
1785 /* Poisoning to make sure PMDs update it in case of error. */
1786 memset(&error, 0x22, sizeof(error));
1787 pia->handle = rte_flow_action_handle_create(port_id, conf, action,
1790 uint32_t destroy_id = pia->id;
1791 port_action_handle_destroy(port_id, 1, &destroy_id);
1792 return port_flow_complain(&error);
1794 pia->type = action->type;
1795 printf("Indirect action #%u created\n", pia->id);
1799 /** Destroy indirect action */
1801 port_action_handle_destroy(portid_t port_id,
1803 const uint32_t *actions)
1805 struct rte_port *port;
1806 struct port_indirect_action **tmp;
1810 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
1811 port_id == (portid_t)RTE_PORT_ALL)
1813 port = &ports[port_id];
1814 tmp = &port->actions_list;
1818 for (i = 0; i != n; ++i) {
1819 struct rte_flow_error error;
1820 struct port_indirect_action *pia = *tmp;
1822 if (actions[i] != pia->id)
1825 * Poisoning to make sure PMDs update it in case
1828 memset(&error, 0x33, sizeof(error));
1830 if (pia->handle && rte_flow_action_handle_destroy(
1831 port_id, pia->handle, &error)) {
1832 ret = port_flow_complain(&error);
1836 printf("Indirect action #%u destroyed\n", pia->id);
1841 tmp = &(*tmp)->next;
1848 /** Get indirect action by port + id */
1849 struct rte_flow_action_handle *
1850 port_action_handle_get_by_id(portid_t port_id, uint32_t id)
1853 struct port_indirect_action *pia = action_get_by_id(port_id, id);
1855 return (pia) ? pia->handle : NULL;
1858 /** Update indirect action */
1860 port_action_handle_update(portid_t port_id, uint32_t id,
1861 const struct rte_flow_action *action)
1863 struct rte_flow_error error;
1864 struct rte_flow_action_handle *action_handle;
1865 struct port_indirect_action *pia;
1868 action_handle = port_action_handle_get_by_id(port_id, id);
1871 pia = action_get_by_id(port_id, id);
1874 switch (pia->type) {
1875 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1876 update = action->conf;
1882 if (rte_flow_action_handle_update(port_id, action_handle, update,
1884 return port_flow_complain(&error);
1886 printf("Indirect action #%u updated\n", id);
1891 port_action_handle_query(portid_t port_id, uint32_t id)
1893 struct rte_flow_error error;
1894 struct port_indirect_action *pia;
1896 struct rte_flow_query_count count;
1897 struct rte_flow_query_age age;
1898 struct rte_flow_action_conntrack ct;
1901 pia = action_get_by_id(port_id, id);
1904 switch (pia->type) {
1905 case RTE_FLOW_ACTION_TYPE_AGE:
1906 case RTE_FLOW_ACTION_TYPE_COUNT:
1910 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1911 id, pia->type, port_id);
1914 /* Poisoning to make sure PMDs update it in case of error. */
1915 memset(&error, 0x55, sizeof(error));
1916 memset(&query, 0, sizeof(query));
1917 if (rte_flow_action_handle_query(port_id, pia->handle, &query, &error))
1918 return port_flow_complain(&error);
1919 switch (pia->type) {
1920 case RTE_FLOW_ACTION_TYPE_AGE:
1921 printf("Indirect AGE action:\n"
1923 " sec_since_last_hit_valid: %u\n"
1924 " sec_since_last_hit: %" PRIu32 "\n",
1926 query.age.sec_since_last_hit_valid,
1927 query.age.sec_since_last_hit);
1929 case RTE_FLOW_ACTION_TYPE_COUNT:
1930 printf("Indirect COUNT action:\n"
1933 " hits: %" PRIu64 "\n"
1934 " bytes: %" PRIu64 "\n",
1935 query.count.hits_set,
1936 query.count.bytes_set,
1940 case RTE_FLOW_ACTION_TYPE_CONNTRACK:
1941 printf("Conntrack Context:\n"
1942 " Peer: %u, Flow dir: %s, Enable: %u\n"
1943 " Live: %u, SACK: %u, CACK: %u\n"
1944 " Packet dir: %s, Liberal: %u, State: %u\n"
1945 " Factor: %u, Retrans: %u, TCP flags: %u\n"
1946 " Last Seq: %u, Last ACK: %u\n"
1947 " Last Win: %u, Last End: %u\n",
1949 query.ct.is_original_dir ? "Original" : "Reply",
1950 query.ct.enable, query.ct.live_connection,
1951 query.ct.selective_ack, query.ct.challenge_ack_passed,
1952 query.ct.last_direction ? "Original" : "Reply",
1953 query.ct.liberal_mode, query.ct.state,
1954 query.ct.max_ack_window, query.ct.retransmission_limit,
1955 query.ct.last_index, query.ct.last_seq,
1956 query.ct.last_ack, query.ct.last_window,
1958 printf(" Original Dir:\n"
1959 " scale: %u, fin: %u, ack seen: %u\n"
1960 " unacked data: %u\n Sent end: %u,"
1961 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1962 query.ct.original_dir.scale,
1963 query.ct.original_dir.close_initiated,
1964 query.ct.original_dir.last_ack_seen,
1965 query.ct.original_dir.data_unacked,
1966 query.ct.original_dir.sent_end,
1967 query.ct.original_dir.reply_end,
1968 query.ct.original_dir.max_win,
1969 query.ct.original_dir.max_ack);
1970 printf(" Reply Dir:\n"
1971 " scale: %u, fin: %u, ack seen: %u\n"
1972 " unacked data: %u\n Sent end: %u,"
1973 " Reply end: %u, Max win: %u, Max ACK: %u\n",
1974 query.ct.reply_dir.scale,
1975 query.ct.reply_dir.close_initiated,
1976 query.ct.reply_dir.last_ack_seen,
1977 query.ct.reply_dir.data_unacked,
1978 query.ct.reply_dir.sent_end,
1979 query.ct.reply_dir.reply_end,
1980 query.ct.reply_dir.max_win,
1981 query.ct.reply_dir.max_ack);
1985 "Indirect action %u (type: %d) on port %u doesn't support query\n",
1986 id, pia->type, port_id);
1992 static struct port_flow_tunnel *
1993 port_flow_tunnel_offload_cmd_prep(portid_t port_id,
1994 const struct rte_flow_item *pattern,
1995 const struct rte_flow_action *actions,
1996 const struct tunnel_ops *tunnel_ops)
1999 struct rte_port *port;
2000 struct port_flow_tunnel *pft;
2001 struct rte_flow_error error;
2003 port = &ports[port_id];
2004 pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
2006 fprintf(stderr, "failed to locate port flow tunnel #%u\n",
2010 if (tunnel_ops->actions) {
2011 uint32_t num_actions;
2012 const struct rte_flow_action *aptr;
2014 ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
2016 &pft->num_pmd_actions,
2019 port_flow_complain(&error);
2022 for (aptr = actions, num_actions = 1;
2023 aptr->type != RTE_FLOW_ACTION_TYPE_END;
2024 aptr++, num_actions++);
2025 pft->actions = malloc(
2026 (num_actions + pft->num_pmd_actions) *
2027 sizeof(actions[0]));
2028 if (!pft->actions) {
2029 rte_flow_tunnel_action_decap_release(
2030 port_id, pft->actions,
2031 pft->num_pmd_actions, &error);
2034 rte_memcpy(pft->actions, pft->pmd_actions,
2035 pft->num_pmd_actions * sizeof(actions[0]));
2036 rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
2037 num_actions * sizeof(actions[0]));
2039 if (tunnel_ops->items) {
2041 const struct rte_flow_item *iptr;
2043 ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
2045 &pft->num_pmd_items,
2048 port_flow_complain(&error);
2051 for (iptr = pattern, num_items = 1;
2052 iptr->type != RTE_FLOW_ITEM_TYPE_END;
2053 iptr++, num_items++);
2054 pft->items = malloc((num_items + pft->num_pmd_items) *
2055 sizeof(pattern[0]));
2057 rte_flow_tunnel_item_release(
2058 port_id, pft->pmd_items,
2059 pft->num_pmd_items, &error);
2062 rte_memcpy(pft->items, pft->pmd_items,
2063 pft->num_pmd_items * sizeof(pattern[0]));
2064 rte_memcpy(pft->items + pft->num_pmd_items, pattern,
2065 num_items * sizeof(pattern[0]));
2072 port_flow_tunnel_offload_cmd_release(portid_t port_id,
2073 const struct tunnel_ops *tunnel_ops,
2074 struct port_flow_tunnel *pft)
2076 struct rte_flow_error error;
2078 if (tunnel_ops->actions) {
2080 rte_flow_tunnel_action_decap_release(
2081 port_id, pft->pmd_actions,
2082 pft->num_pmd_actions, &error);
2083 pft->actions = NULL;
2084 pft->pmd_actions = NULL;
2086 if (tunnel_ops->items) {
2088 rte_flow_tunnel_item_release(port_id, pft->pmd_items,
2092 pft->pmd_items = NULL;
2096 /** Add port meter policy */
2098 port_meter_policy_add(portid_t port_id, uint32_t policy_id,
2099 const struct rte_flow_action *actions)
2101 struct rte_mtr_error error;
2102 const struct rte_flow_action *act = actions;
2103 const struct rte_flow_action *start;
2104 struct rte_mtr_meter_policy_params policy;
2105 uint32_t i = 0, act_n;
2108 for (i = 0; i < RTE_COLORS; i++) {
2109 for (act_n = 0, start = act;
2110 act->type != RTE_FLOW_ACTION_TYPE_END; act++)
2112 if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END)
2113 policy.actions[i] = start;
2115 policy.actions[i] = NULL;
2118 ret = rte_mtr_meter_policy_add(port_id,
2122 print_mtr_err_msg(&error);
2126 /** Validate flow rule. */
2128 port_flow_validate(portid_t port_id,
2129 const struct rte_flow_attr *attr,
2130 const struct rte_flow_item *pattern,
2131 const struct rte_flow_action *actions,
2132 const struct tunnel_ops *tunnel_ops)
2134 struct rte_flow_error error;
2135 struct port_flow_tunnel *pft = NULL;
2138 /* Poisoning to make sure PMDs update it in case of error. */
2139 memset(&error, 0x11, sizeof(error));
2140 if (tunnel_ops->enabled) {
2141 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2142 actions, tunnel_ops);
2146 pattern = pft->items;
2148 actions = pft->actions;
2150 ret = rte_flow_validate(port_id, attr, pattern, actions, &error);
2151 if (tunnel_ops->enabled)
2152 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2154 return port_flow_complain(&error);
2155 printf("Flow rule validated\n");
2159 /** Return age action structure if exists, otherwise NULL. */
2160 static struct rte_flow_action_age *
2161 age_action_get(const struct rte_flow_action *actions)
2163 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
2164 switch (actions->type) {
2165 case RTE_FLOW_ACTION_TYPE_AGE:
2166 return (struct rte_flow_action_age *)
2167 (uintptr_t)actions->conf;
2175 /** Create pattern template */
2177 port_flow_pattern_template_create(portid_t port_id, uint32_t id,
2178 const struct rte_flow_pattern_template_attr *attr,
2179 const struct rte_flow_item *pattern)
2181 struct rte_port *port;
2182 struct port_template *pit;
2184 struct rte_flow_error error;
2186 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2187 port_id == (portid_t)RTE_PORT_ALL)
2189 port = &ports[port_id];
2190 ret = template_alloc(id, &pit, &port->pattern_templ_list);
2193 /* Poisoning to make sure PMDs update it in case of error. */
2194 memset(&error, 0x22, sizeof(error));
2195 pit->template.pattern_template = rte_flow_pattern_template_create(port_id,
2196 attr, pattern, &error);
2197 if (!pit->template.pattern_template) {
2198 uint32_t destroy_id = pit->id;
2199 port_flow_pattern_template_destroy(port_id, 1, &destroy_id);
2200 return port_flow_complain(&error);
2202 printf("Pattern template #%u created\n", pit->id);
2206 /** Destroy pattern template */
2208 port_flow_pattern_template_destroy(portid_t port_id, uint32_t n,
2209 const uint32_t *template)
2211 struct rte_port *port;
2212 struct port_template **tmp;
2216 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2217 port_id == (portid_t)RTE_PORT_ALL)
2219 port = &ports[port_id];
2220 tmp = &port->pattern_templ_list;
2224 for (i = 0; i != n; ++i) {
2225 struct rte_flow_error error;
2226 struct port_template *pit = *tmp;
2228 if (template[i] != pit->id)
2231 * Poisoning to make sure PMDs update it in case
2234 memset(&error, 0x33, sizeof(error));
2236 if (pit->template.pattern_template &&
2237 rte_flow_pattern_template_destroy(port_id,
2238 pit->template.pattern_template,
2240 ret = port_flow_complain(&error);
2244 printf("Pattern template #%u destroyed\n", pit->id);
2249 tmp = &(*tmp)->next;
2255 /** Create actions template */
2257 port_flow_actions_template_create(portid_t port_id, uint32_t id,
2258 const struct rte_flow_actions_template_attr *attr,
2259 const struct rte_flow_action *actions,
2260 const struct rte_flow_action *masks)
2262 struct rte_port *port;
2263 struct port_template *pat;
2265 struct rte_flow_error error;
2267 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2268 port_id == (portid_t)RTE_PORT_ALL)
2270 port = &ports[port_id];
2271 ret = template_alloc(id, &pat, &port->actions_templ_list);
2274 /* Poisoning to make sure PMDs update it in case of error. */
2275 memset(&error, 0x22, sizeof(error));
2276 pat->template.actions_template = rte_flow_actions_template_create(port_id,
2277 attr, actions, masks, &error);
2278 if (!pat->template.actions_template) {
2279 uint32_t destroy_id = pat->id;
2280 port_flow_actions_template_destroy(port_id, 1, &destroy_id);
2281 return port_flow_complain(&error);
2283 printf("Actions template #%u created\n", pat->id);
2287 /** Destroy actions template */
2289 port_flow_actions_template_destroy(portid_t port_id, uint32_t n,
2290 const uint32_t *template)
2292 struct rte_port *port;
2293 struct port_template **tmp;
2297 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2298 port_id == (portid_t)RTE_PORT_ALL)
2300 port = &ports[port_id];
2301 tmp = &port->actions_templ_list;
2305 for (i = 0; i != n; ++i) {
2306 struct rte_flow_error error;
2307 struct port_template *pat = *tmp;
2309 if (template[i] != pat->id)
2312 * Poisoning to make sure PMDs update it in case
2315 memset(&error, 0x33, sizeof(error));
2317 if (pat->template.actions_template &&
2318 rte_flow_actions_template_destroy(port_id,
2319 pat->template.actions_template, &error)) {
2320 ret = port_flow_complain(&error);
2324 printf("Actions template #%u destroyed\n", pat->id);
2329 tmp = &(*tmp)->next;
2337 port_flow_template_table_create(portid_t port_id, uint32_t id,
2338 const struct rte_flow_template_table_attr *table_attr,
2339 uint32_t nb_pattern_templates, uint32_t *pattern_templates,
2340 uint32_t nb_actions_templates, uint32_t *actions_templates)
2342 struct rte_port *port;
2343 struct port_table *pt;
2344 struct port_template *temp = NULL;
2347 struct rte_flow_error error;
2348 struct rte_flow_pattern_template
2349 *flow_pattern_templates[nb_pattern_templates];
2350 struct rte_flow_actions_template
2351 *flow_actions_templates[nb_actions_templates];
2353 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2354 port_id == (portid_t)RTE_PORT_ALL)
2356 port = &ports[port_id];
2357 for (i = 0; i < nb_pattern_templates; ++i) {
2359 temp = port->pattern_templ_list;
2361 if (pattern_templates[i] == temp->id) {
2362 flow_pattern_templates[i] =
2363 temp->template.pattern_template;
2370 printf("Pattern template #%u is invalid\n",
2371 pattern_templates[i]);
2375 for (i = 0; i < nb_actions_templates; ++i) {
2377 temp = port->actions_templ_list;
2379 if (actions_templates[i] == temp->id) {
2380 flow_actions_templates[i] =
2381 temp->template.actions_template;
2388 printf("Actions template #%u is invalid\n",
2389 actions_templates[i]);
2393 ret = table_alloc(id, &pt, &port->table_list);
2396 /* Poisoning to make sure PMDs update it in case of error. */
2397 memset(&error, 0x22, sizeof(error));
2398 pt->table = rte_flow_template_table_create(port_id, table_attr,
2399 flow_pattern_templates, nb_pattern_templates,
2400 flow_actions_templates, nb_actions_templates,
2404 uint32_t destroy_id = pt->id;
2405 port_flow_template_table_destroy(port_id, 1, &destroy_id);
2406 return port_flow_complain(&error);
2408 pt->nb_pattern_templates = nb_pattern_templates;
2409 pt->nb_actions_templates = nb_actions_templates;
2410 printf("Template table #%u created\n", pt->id);
2414 /** Destroy table */
2416 port_flow_template_table_destroy(portid_t port_id,
2417 uint32_t n, const uint32_t *table)
2419 struct rte_port *port;
2420 struct port_table **tmp;
2424 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2425 port_id == (portid_t)RTE_PORT_ALL)
2427 port = &ports[port_id];
2428 tmp = &port->table_list;
2432 for (i = 0; i != n; ++i) {
2433 struct rte_flow_error error;
2434 struct port_table *pt = *tmp;
2436 if (table[i] != pt->id)
2439 * Poisoning to make sure PMDs update it in case
2442 memset(&error, 0x33, sizeof(error));
2445 rte_flow_template_table_destroy(port_id,
2448 ret = port_flow_complain(&error);
2452 printf("Template table #%u destroyed\n", pt->id);
2457 tmp = &(*tmp)->next;
2463 /** Create flow rule. */
2465 port_flow_create(portid_t port_id,
2466 const struct rte_flow_attr *attr,
2467 const struct rte_flow_item *pattern,
2468 const struct rte_flow_action *actions,
2469 const struct tunnel_ops *tunnel_ops)
2471 struct rte_flow *flow;
2472 struct rte_port *port;
2473 struct port_flow *pf;
2475 struct rte_flow_error error;
2476 struct port_flow_tunnel *pft = NULL;
2477 struct rte_flow_action_age *age = age_action_get(actions);
2479 port = &ports[port_id];
2480 if (port->flow_list) {
2481 if (port->flow_list->id == UINT32_MAX) {
2483 "Highest rule ID is already assigned, delete it first");
2486 id = port->flow_list->id + 1;
2488 if (tunnel_ops->enabled) {
2489 pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
2490 actions, tunnel_ops);
2494 pattern = pft->items;
2496 actions = pft->actions;
2498 pf = port_flow_new(attr, pattern, actions, &error);
2500 return port_flow_complain(&error);
2502 pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
2503 age->context = &pf->age_type;
2505 /* Poisoning to make sure PMDs update it in case of error. */
2506 memset(&error, 0x22, sizeof(error));
2507 flow = rte_flow_create(port_id, attr, pattern, actions, &error);
2509 if (tunnel_ops->enabled)
2510 port_flow_tunnel_offload_cmd_release(port_id,
2513 return port_flow_complain(&error);
2515 pf->next = port->flow_list;
2518 port->flow_list = pf;
2519 if (tunnel_ops->enabled)
2520 port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
2521 printf("Flow rule #%u created\n", pf->id);
2525 /** Destroy a number of flow rules. */
2527 port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
2529 struct rte_port *port;
2530 struct port_flow **tmp;
2534 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2535 port_id == (portid_t)RTE_PORT_ALL)
2537 port = &ports[port_id];
2538 tmp = &port->flow_list;
2542 for (i = 0; i != n; ++i) {
2543 struct rte_flow_error error;
2544 struct port_flow *pf = *tmp;
2546 if (rule[i] != pf->id)
2549 * Poisoning to make sure PMDs update it in case
2552 memset(&error, 0x33, sizeof(error));
2553 if (rte_flow_destroy(port_id, pf->flow, &error)) {
2554 ret = port_flow_complain(&error);
2557 printf("Flow rule #%u destroyed\n", pf->id);
2563 tmp = &(*tmp)->next;
2569 /** Remove all flow rules. */
2571 port_flow_flush(portid_t port_id)
2573 struct rte_flow_error error;
2574 struct rte_port *port;
2577 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2578 port_id == (portid_t)RTE_PORT_ALL)
2581 port = &ports[port_id];
2583 if (port->flow_list == NULL)
2586 /* Poisoning to make sure PMDs update it in case of error. */
2587 memset(&error, 0x44, sizeof(error));
2588 if (rte_flow_flush(port_id, &error)) {
2589 port_flow_complain(&error);
2592 while (port->flow_list) {
2593 struct port_flow *pf = port->flow_list->next;
2595 free(port->flow_list);
2596 port->flow_list = pf;
2601 /** Dump flow rules. */
2603 port_flow_dump(portid_t port_id, bool dump_all, uint32_t rule_id,
2604 const char *file_name)
2607 FILE *file = stdout;
2608 struct rte_flow_error error;
2609 struct rte_port *port;
2610 struct port_flow *pflow;
2611 struct rte_flow *tmpFlow = NULL;
2614 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2615 port_id == (portid_t)RTE_PORT_ALL)
2619 port = &ports[port_id];
2620 pflow = port->flow_list;
2622 if (rule_id != pflow->id) {
2623 pflow = pflow->next;
2625 tmpFlow = pflow->flow;
2631 if (found == false) {
2632 fprintf(stderr, "Failed to dump to flow %d\n", rule_id);
2637 if (file_name && strlen(file_name)) {
2638 file = fopen(file_name, "w");
2640 fprintf(stderr, "Failed to create file %s: %s\n",
2641 file_name, strerror(errno));
2647 ret = rte_flow_dev_dump(port_id, tmpFlow, file, &error);
2649 ret = rte_flow_dev_dump(port_id, NULL, file, &error);
2651 port_flow_complain(&error);
2652 fprintf(stderr, "Failed to dump flow: %s\n", strerror(-ret));
2654 printf("Flow dump finished\n");
2655 if (file_name && strlen(file_name))
2660 /** Query a flow rule. */
2662 port_flow_query(portid_t port_id, uint32_t rule,
2663 const struct rte_flow_action *action)
2665 struct rte_flow_error error;
2666 struct rte_port *port;
2667 struct port_flow *pf;
2670 struct rte_flow_query_count count;
2671 struct rte_flow_action_rss rss_conf;
2672 struct rte_flow_query_age age;
2676 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2677 port_id == (portid_t)RTE_PORT_ALL)
2679 port = &ports[port_id];
2680 for (pf = port->flow_list; pf; pf = pf->next)
2684 fprintf(stderr, "Flow rule #%u not found\n", rule);
2687 ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2688 &name, sizeof(name),
2689 (void *)(uintptr_t)action->type, &error);
2691 return port_flow_complain(&error);
2692 switch (action->type) {
2693 case RTE_FLOW_ACTION_TYPE_COUNT:
2694 case RTE_FLOW_ACTION_TYPE_RSS:
2695 case RTE_FLOW_ACTION_TYPE_AGE:
2698 fprintf(stderr, "Cannot query action type %d (%s)\n",
2699 action->type, name);
2702 /* Poisoning to make sure PMDs update it in case of error. */
2703 memset(&error, 0x55, sizeof(error));
2704 memset(&query, 0, sizeof(query));
2705 if (rte_flow_query(port_id, pf->flow, action, &query, &error))
2706 return port_flow_complain(&error);
2707 switch (action->type) {
2708 case RTE_FLOW_ACTION_TYPE_COUNT:
2712 " hits: %" PRIu64 "\n"
2713 " bytes: %" PRIu64 "\n",
2715 query.count.hits_set,
2716 query.count.bytes_set,
2720 case RTE_FLOW_ACTION_TYPE_RSS:
2721 rss_config_display(&query.rss_conf);
2723 case RTE_FLOW_ACTION_TYPE_AGE:
2726 " sec_since_last_hit_valid: %u\n"
2727 " sec_since_last_hit: %" PRIu32 "\n",
2730 query.age.sec_since_last_hit_valid,
2731 query.age.sec_since_last_hit);
2735 "Cannot display result for action type %d (%s)\n",
2736 action->type, name);
2742 /** List simply and destroy all aged flows. */
2744 port_flow_aged(portid_t port_id, uint8_t destroy)
2747 int nb_context, total = 0, idx;
2748 struct rte_flow_error error;
2749 enum age_action_context_type *type;
2751 struct port_flow *pf;
2752 struct port_indirect_action *pia;
2755 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2756 port_id == (portid_t)RTE_PORT_ALL)
2758 total = rte_flow_get_aged_flows(port_id, NULL, 0, &error);
2759 printf("Port %u total aged flows: %d\n", port_id, total);
2761 port_flow_complain(&error);
2766 contexts = malloc(sizeof(void *) * total);
2767 if (contexts == NULL) {
2768 fprintf(stderr, "Cannot allocate contexts for aged flow\n");
2771 printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
2772 nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
2773 if (nb_context != total) {
2775 "Port:%d get aged flows count(%d) != total(%d)\n",
2776 port_id, nb_context, total);
2781 for (idx = 0; idx < nb_context; idx++) {
2782 if (!contexts[idx]) {
2783 fprintf(stderr, "Error: get Null context in port %u\n",
2787 type = (enum age_action_context_type *)contexts[idx];
2789 case ACTION_AGE_CONTEXT_TYPE_FLOW:
2790 ctx.pf = container_of(type, struct port_flow, age_type);
2791 printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
2795 ctx.pf->rule.attr->group,
2796 ctx.pf->rule.attr->priority,
2797 ctx.pf->rule.attr->ingress ? 'i' : '-',
2798 ctx.pf->rule.attr->egress ? 'e' : '-',
2799 ctx.pf->rule.attr->transfer ? 't' : '-');
2800 if (destroy && !port_flow_destroy(port_id, 1,
2804 case ACTION_AGE_CONTEXT_TYPE_INDIRECT_ACTION:
2805 ctx.pia = container_of(type,
2806 struct port_indirect_action, age_type);
2807 printf("%-20s\t%" PRIu32 "\n", "Indirect action",
2811 fprintf(stderr, "Error: invalid context type %u\n",
2816 printf("\n%d flows destroyed\n", total);
2820 /** List flow rules. */
2822 port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group)
2824 struct rte_port *port;
2825 struct port_flow *pf;
2826 struct port_flow *list = NULL;
2829 if (port_id_is_invalid(port_id, ENABLED_WARN) ||
2830 port_id == (portid_t)RTE_PORT_ALL)
2832 port = &ports[port_id];
2833 if (!port->flow_list)
2835 /* Sort flows by group, priority and ID. */
2836 for (pf = port->flow_list; pf != NULL; pf = pf->next) {
2837 struct port_flow **tmp;
2838 const struct rte_flow_attr *curr = pf->rule.attr;
2841 /* Filter out unwanted groups. */
2842 for (i = 0; i != n; ++i)
2843 if (curr->group == group[i])
2848 for (tmp = &list; *tmp; tmp = &(*tmp)->tmp) {
2849 const struct rte_flow_attr *comp = (*tmp)->rule.attr;
2851 if (curr->group > comp->group ||
2852 (curr->group == comp->group &&
2853 curr->priority > comp->priority) ||
2854 (curr->group == comp->group &&
2855 curr->priority == comp->priority &&
2856 pf->id > (*tmp)->id))
2863 printf("ID\tGroup\tPrio\tAttr\tRule\n");
2864 for (pf = list; pf != NULL; pf = pf->tmp) {
2865 const struct rte_flow_item *item = pf->rule.pattern;
2866 const struct rte_flow_action *action = pf->rule.actions;
2869 printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t",
2871 pf->rule.attr->group,
2872 pf->rule.attr->priority,
2873 pf->rule.attr->ingress ? 'i' : '-',
2874 pf->rule.attr->egress ? 'e' : '-',
2875 pf->rule.attr->transfer ? 't' : '-');
2876 while (item->type != RTE_FLOW_ITEM_TYPE_END) {
2877 if ((uint32_t)item->type > INT_MAX)
2878 name = "PMD_INTERNAL";
2879 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
2880 &name, sizeof(name),
2881 (void *)(uintptr_t)item->type,
2884 if (item->type != RTE_FLOW_ITEM_TYPE_VOID)
2885 printf("%s ", name);
2889 while (action->type != RTE_FLOW_ACTION_TYPE_END) {
2890 if ((uint32_t)action->type > INT_MAX)
2891 name = "PMD_INTERNAL";
2892 else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
2893 &name, sizeof(name),
2894 (void *)(uintptr_t)action->type,
2897 if (action->type != RTE_FLOW_ACTION_TYPE_VOID)
2898 printf(" %s", name);
2905 /** Restrict ingress traffic to the defined flow rules. */
2907 port_flow_isolate(portid_t port_id, int set)
2909 struct rte_flow_error error;
2911 /* Poisoning to make sure PMDs update it in case of error. */
2912 memset(&error, 0x66, sizeof(error));
2913 if (rte_flow_isolate(port_id, set, &error))
2914 return port_flow_complain(&error);
2915 printf("Ingress traffic on port %u is %s to the defined flow rules\n",
2917 set ? "now restricted" : "not restricted anymore");
2922 * RX/TX ring descriptors display functions.
2925 rx_queue_id_is_invalid(queueid_t rxq_id)
2927 if (rxq_id < nb_rxq)
2929 fprintf(stderr, "Invalid RX queue %d (must be < nb_rxq=%d)\n",
2935 tx_queue_id_is_invalid(queueid_t txq_id)
2937 if (txq_id < nb_txq)
2939 fprintf(stderr, "Invalid TX queue %d (must be < nb_txq=%d)\n",
2945 get_rx_ring_size(portid_t port_id, queueid_t rxq_id, uint16_t *ring_size)
2947 struct rte_port *port = &ports[port_id];
2948 struct rte_eth_rxq_info rx_qinfo;
2951 ret = rte_eth_rx_queue_info_get(port_id, rxq_id, &rx_qinfo);
2953 *ring_size = rx_qinfo.nb_desc;
2957 if (ret != -ENOTSUP)
2960 * If the rte_eth_rx_queue_info_get is not support for this PMD,
2961 * ring_size stored in testpmd will be used for validity verification.
2962 * When configure the rxq by rte_eth_rx_queue_setup with nb_rx_desc
2963 * being 0, it will use a default value provided by PMDs to setup this
2964 * rxq. If the default value is 0, it will use the
2965 * RTE_ETH_DEV_FALLBACK_RX_RINGSIZE to setup this rxq.
2967 if (port->nb_rx_desc[rxq_id])
2968 *ring_size = port->nb_rx_desc[rxq_id];
2969 else if (port->dev_info.default_rxportconf.ring_size)
2970 *ring_size = port->dev_info.default_rxportconf.ring_size;
2972 *ring_size = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
2977 get_tx_ring_size(portid_t port_id, queueid_t txq_id, uint16_t *ring_size)
2979 struct rte_port *port = &ports[port_id];
2980 struct rte_eth_txq_info tx_qinfo;
2983 ret = rte_eth_tx_queue_info_get(port_id, txq_id, &tx_qinfo);
2985 *ring_size = tx_qinfo.nb_desc;
2989 if (ret != -ENOTSUP)
2992 * If the rte_eth_tx_queue_info_get is not support for this PMD,
2993 * ring_size stored in testpmd will be used for validity verification.
2994 * When configure the txq by rte_eth_tx_queue_setup with nb_tx_desc
2995 * being 0, it will use a default value provided by PMDs to setup this
2996 * txq. If the default value is 0, it will use the
2997 * RTE_ETH_DEV_FALLBACK_TX_RINGSIZE to setup this txq.
2999 if (port->nb_tx_desc[txq_id])
3000 *ring_size = port->nb_tx_desc[txq_id];
3001 else if (port->dev_info.default_txportconf.ring_size)
3002 *ring_size = port->dev_info.default_txportconf.ring_size;
3004 *ring_size = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
3009 rx_desc_id_is_invalid(portid_t port_id, queueid_t rxq_id, uint16_t rxdesc_id)
3014 ret = get_rx_ring_size(port_id, rxq_id, &ring_size);
3018 if (rxdesc_id < ring_size)
3021 fprintf(stderr, "Invalid RX descriptor %u (must be < ring_size=%u)\n",
3022 rxdesc_id, ring_size);
3027 tx_desc_id_is_invalid(portid_t port_id, queueid_t txq_id, uint16_t txdesc_id)
3032 ret = get_tx_ring_size(port_id, txq_id, &ring_size);
3036 if (txdesc_id < ring_size)
3039 fprintf(stderr, "Invalid TX descriptor %u (must be < ring_size=%u)\n",
3040 txdesc_id, ring_size);
3044 static const struct rte_memzone *
3045 ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id)
3047 char mz_name[RTE_MEMZONE_NAMESIZE];
3048 const struct rte_memzone *mz;
3050 snprintf(mz_name, sizeof(mz_name), "eth_p%d_q%d_%s",
3051 port_id, q_id, ring_name);
3052 mz = rte_memzone_lookup(mz_name);
3055 "%s ring memory zoneof (port %d, queue %d) not found (zone name = %s\n",
3056 ring_name, port_id, q_id, mz_name);
3060 union igb_ring_dword {
3063 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
3073 struct igb_ring_desc_32_bytes {
3074 union igb_ring_dword lo_dword;
3075 union igb_ring_dword hi_dword;
3076 union igb_ring_dword resv1;
3077 union igb_ring_dword resv2;
3080 struct igb_ring_desc_16_bytes {
3081 union igb_ring_dword lo_dword;
3082 union igb_ring_dword hi_dword;
3086 ring_rxd_display_dword(union igb_ring_dword dword)
3088 printf(" 0x%08X - 0x%08X\n", (unsigned)dword.words.lo,
3089 (unsigned)dword.words.hi);
3093 ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
3094 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
3097 __rte_unused portid_t port_id,
3101 struct igb_ring_desc_16_bytes *ring =
3102 (struct igb_ring_desc_16_bytes *)ring_mz->addr;
3103 #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
3105 struct rte_eth_dev_info dev_info;
3107 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3111 if (strstr(dev_info.driver_name, "i40e") != NULL) {
3112 /* 32 bytes RX descriptor, i40e only */
3113 struct igb_ring_desc_32_bytes *ring =
3114 (struct igb_ring_desc_32_bytes *)ring_mz->addr;
3115 ring[desc_id].lo_dword.dword =
3116 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
3117 ring_rxd_display_dword(ring[desc_id].lo_dword);
3118 ring[desc_id].hi_dword.dword =
3119 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
3120 ring_rxd_display_dword(ring[desc_id].hi_dword);
3121 ring[desc_id].resv1.dword =
3122 rte_le_to_cpu_64(ring[desc_id].resv1.dword);
3123 ring_rxd_display_dword(ring[desc_id].resv1);
3124 ring[desc_id].resv2.dword =
3125 rte_le_to_cpu_64(ring[desc_id].resv2.dword);
3126 ring_rxd_display_dword(ring[desc_id].resv2);
3131 /* 16 bytes RX descriptor */
3132 ring[desc_id].lo_dword.dword =
3133 rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
3134 ring_rxd_display_dword(ring[desc_id].lo_dword);
3135 ring[desc_id].hi_dword.dword =
3136 rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
3137 ring_rxd_display_dword(ring[desc_id].hi_dword);
3141 ring_tx_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
3143 struct igb_ring_desc_16_bytes *ring;
3144 struct igb_ring_desc_16_bytes txd;
3146 ring = (struct igb_ring_desc_16_bytes *)ring_mz->addr;
3147 txd.lo_dword.dword = rte_le_to_cpu_64(ring[desc_id].lo_dword.dword);
3148 txd.hi_dword.dword = rte_le_to_cpu_64(ring[desc_id].hi_dword.dword);
3149 printf(" 0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
3150 (unsigned)txd.lo_dword.words.lo,
3151 (unsigned)txd.lo_dword.words.hi,
3152 (unsigned)txd.hi_dword.words.lo,
3153 (unsigned)txd.hi_dword.words.hi);
3157 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
3159 const struct rte_memzone *rx_mz;
3161 if (rx_desc_id_is_invalid(port_id, rxq_id, rxd_id))
3163 rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
3166 ring_rx_descriptor_display(rx_mz, port_id, rxd_id);
3170 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
3172 const struct rte_memzone *tx_mz;
3174 if (tx_desc_id_is_invalid(port_id, txq_id, txd_id))
3176 tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
3179 ring_tx_descriptor_display(tx_mz, txd_id);
3183 fwd_lcores_config_display(void)
3187 printf("List of forwarding lcores:");
3188 for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
3189 printf(" %2u", fwd_lcores_cpuids[lc_id]);
3193 rxtx_config_display(void)
3198 printf(" %s packet forwarding%s packets/burst=%d\n",
3199 cur_fwd_eng->fwd_mode_name,
3200 retry_enabled == 0 ? "" : " with retry",
3203 if (cur_fwd_eng == &tx_only_engine || cur_fwd_eng == &flow_gen_engine)
3204 printf(" packet len=%u - nb packet segments=%d\n",
3205 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
3207 printf(" nb forwarding cores=%d - nb forwarding ports=%d\n",
3208 nb_fwd_lcores, nb_fwd_ports);
3210 RTE_ETH_FOREACH_DEV(pid) {
3211 struct rte_eth_rxconf *rx_conf = &ports[pid].rx_conf[0];
3212 struct rte_eth_txconf *tx_conf = &ports[pid].tx_conf[0];
3213 uint16_t *nb_rx_desc = &ports[pid].nb_rx_desc[0];
3214 uint16_t *nb_tx_desc = &ports[pid].nb_tx_desc[0];
3215 struct rte_eth_rxq_info rx_qinfo;
3216 struct rte_eth_txq_info tx_qinfo;
3217 uint16_t rx_free_thresh_tmp;
3218 uint16_t tx_free_thresh_tmp;
3219 uint16_t tx_rs_thresh_tmp;
3220 uint16_t nb_rx_desc_tmp;
3221 uint16_t nb_tx_desc_tmp;
3222 uint64_t offloads_tmp;
3223 uint8_t pthresh_tmp;
3224 uint8_t hthresh_tmp;
3225 uint8_t wthresh_tmp;
3228 /* per port config */
3229 printf(" port %d: RX queue number: %d Tx queue number: %d\n",
3230 (unsigned int)pid, nb_rxq, nb_txq);
3232 printf(" Rx offloads=0x%"PRIx64" Tx offloads=0x%"PRIx64"\n",
3233 ports[pid].dev_conf.rxmode.offloads,
3234 ports[pid].dev_conf.txmode.offloads);
3236 /* per rx queue config only for first queue to be less verbose */
3237 for (qid = 0; qid < 1; qid++) {
3238 rc = rte_eth_rx_queue_info_get(pid, qid, &rx_qinfo);
3240 nb_rx_desc_tmp = nb_rx_desc[qid];
3241 rx_free_thresh_tmp =
3242 rx_conf[qid].rx_free_thresh;
3243 pthresh_tmp = rx_conf[qid].rx_thresh.pthresh;
3244 hthresh_tmp = rx_conf[qid].rx_thresh.hthresh;
3245 wthresh_tmp = rx_conf[qid].rx_thresh.wthresh;
3246 offloads_tmp = rx_conf[qid].offloads;
3248 nb_rx_desc_tmp = rx_qinfo.nb_desc;
3249 rx_free_thresh_tmp =
3250 rx_qinfo.conf.rx_free_thresh;
3251 pthresh_tmp = rx_qinfo.conf.rx_thresh.pthresh;
3252 hthresh_tmp = rx_qinfo.conf.rx_thresh.hthresh;
3253 wthresh_tmp = rx_qinfo.conf.rx_thresh.wthresh;
3254 offloads_tmp = rx_qinfo.conf.offloads;
3257 printf(" RX queue: %d\n", qid);
3258 printf(" RX desc=%d - RX free threshold=%d\n",
3259 nb_rx_desc_tmp, rx_free_thresh_tmp);
3260 printf(" RX threshold registers: pthresh=%d hthresh=%d "
3262 pthresh_tmp, hthresh_tmp, wthresh_tmp);
3263 printf(" RX Offloads=0x%"PRIx64, offloads_tmp);
3264 if (rx_conf->share_group > 0)
3265 printf(" share_group=%u share_qid=%u",
3266 rx_conf->share_group,
3267 rx_conf->share_qid);
3271 /* per tx queue config only for first queue to be less verbose */
3272 for (qid = 0; qid < 1; qid++) {
3273 rc = rte_eth_tx_queue_info_get(pid, qid, &tx_qinfo);
3275 nb_tx_desc_tmp = nb_tx_desc[qid];
3276 tx_free_thresh_tmp =
3277 tx_conf[qid].tx_free_thresh;
3278 pthresh_tmp = tx_conf[qid].tx_thresh.pthresh;
3279 hthresh_tmp = tx_conf[qid].tx_thresh.hthresh;
3280 wthresh_tmp = tx_conf[qid].tx_thresh.wthresh;
3281 offloads_tmp = tx_conf[qid].offloads;
3282 tx_rs_thresh_tmp = tx_conf[qid].tx_rs_thresh;
3284 nb_tx_desc_tmp = tx_qinfo.nb_desc;
3285 tx_free_thresh_tmp =
3286 tx_qinfo.conf.tx_free_thresh;
3287 pthresh_tmp = tx_qinfo.conf.tx_thresh.pthresh;
3288 hthresh_tmp = tx_qinfo.conf.tx_thresh.hthresh;
3289 wthresh_tmp = tx_qinfo.conf.tx_thresh.wthresh;
3290 offloads_tmp = tx_qinfo.conf.offloads;
3291 tx_rs_thresh_tmp = tx_qinfo.conf.tx_rs_thresh;
3294 printf(" TX queue: %d\n", qid);
3295 printf(" TX desc=%d - TX free threshold=%d\n",
3296 nb_tx_desc_tmp, tx_free_thresh_tmp);
3297 printf(" TX threshold registers: pthresh=%d hthresh=%d "
3299 pthresh_tmp, hthresh_tmp, wthresh_tmp);
3300 printf(" TX offloads=0x%"PRIx64" - TX RS bit threshold=%d\n",
3301 offloads_tmp, tx_rs_thresh_tmp);
3307 port_rss_reta_info(portid_t port_id,
3308 struct rte_eth_rss_reta_entry64 *reta_conf,
3309 uint16_t nb_entries)
3311 uint16_t i, idx, shift;
3314 if (port_id_is_invalid(port_id, ENABLED_WARN))
3317 ret = rte_eth_dev_rss_reta_query(port_id, reta_conf, nb_entries);
3320 "Failed to get RSS RETA info, return code = %d\n",
3325 for (i = 0; i < nb_entries; i++) {
3326 idx = i / RTE_ETH_RETA_GROUP_SIZE;
3327 shift = i % RTE_ETH_RETA_GROUP_SIZE;
3328 if (!(reta_conf[idx].mask & (1ULL << shift)))
3330 printf("RSS RETA configuration: hash index=%u, queue=%u\n",
3331 i, reta_conf[idx].reta[shift]);
3336 * Displays the RSS hash functions of a port, and, optionally, the RSS hash
3340 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
3342 struct rte_eth_rss_conf rss_conf = {0};
3343 uint8_t rss_key[RSS_HASH_KEY_LENGTH];
3347 struct rte_eth_dev_info dev_info;
3348 uint8_t hash_key_size;
3351 if (port_id_is_invalid(port_id, ENABLED_WARN))
3354 ret = eth_dev_info_get_print_err(port_id, &dev_info);
3358 if (dev_info.hash_key_size > 0 &&
3359 dev_info.hash_key_size <= sizeof(rss_key))
3360 hash_key_size = dev_info.hash_key_size;
3363 "dev_info did not provide a valid hash key size\n");
3367 /* Get RSS hash key if asked to display it */
3368 rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
3369 rss_conf.rss_key_len = hash_key_size;
3370 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
3374 fprintf(stderr, "port index %d invalid\n", port_id);
3377 fprintf(stderr, "operation not supported by device\n");
3380 fprintf(stderr, "operation failed - diag=%d\n", diag);
3385 rss_hf = rss_conf.rss_hf;
3387 printf("RSS disabled\n");
3390 printf("RSS functions:\n ");
3391 for (i = 0; rss_type_table[i].str; i++) {
3392 if (rss_type_table[i].rss_type == 0)
3394 if ((rss_hf & rss_type_table[i].rss_type) == rss_type_table[i].rss_type)
3395 printf("%s ", rss_type_table[i].str);
3400 printf("RSS key:\n");
3401 for (i = 0; i < hash_key_size; i++)
3402 printf("%02X", rss_key[i]);
3407 port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
3408 uint8_t hash_key_len)
3410 struct rte_eth_rss_conf rss_conf;
3414 rss_conf.rss_key = NULL;
3415 rss_conf.rss_key_len = 0;
3416 rss_conf.rss_hf = 0;
3417 for (i = 0; rss_type_table[i].str; i++) {
3418 if (!strcmp(rss_type_table[i].str, rss_type))
3419 rss_conf.rss_hf = rss_type_table[i].rss_type;
3421 diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
3423 rss_conf.rss_key = hash_key;
3424 rss_conf.rss_key_len = hash_key_len;
3425 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
3432 fprintf(stderr, "port index %d invalid\n", port_id);
3435 fprintf(stderr, "operation not supported by device\n");
3438 fprintf(stderr, "operation failed - diag=%d\n", diag);
3444 * Check whether a shared rxq scheduled on other lcores.
3447 fwd_stream_on_other_lcores(uint16_t domain_id, lcoreid_t src_lc,
3448 portid_t src_port, queueid_t src_rxq,
3449 uint32_t share_group, queueid_t share_rxq)
3452 streamid_t nb_fs_per_lcore;
3455 struct fwd_stream *fs;
3456 struct rte_port *port;
3457 struct rte_eth_dev_info *dev_info;
3458 struct rte_eth_rxconf *rxq_conf;
3460 nb_fc = cur_fwd_config.nb_fwd_lcores;
3461 /* Check remaining cores. */
3462 for (lc_id = src_lc + 1; lc_id < nb_fc; lc_id++) {
3463 sm_id = fwd_lcores[lc_id]->stream_idx;
3464 nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
3465 for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
3467 fs = fwd_streams[sm_id];
3468 port = &ports[fs->rx_port];
3469 dev_info = &port->dev_info;
3470 rxq_conf = &port->rx_conf[fs->rx_queue];
3471 if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
3472 == 0 || rxq_conf->share_group == 0)
3473 /* Not shared rxq. */
3475 if (domain_id != port->dev_info.switch_info.domain_id)
3477 if (rxq_conf->share_group != share_group)
3479 if (rxq_conf->share_qid != share_rxq)
3481 printf("Shared Rx queue group %u queue %hu can't be scheduled on different cores:\n",
3482 share_group, share_rxq);
3483 printf(" lcore %hhu Port %hu queue %hu\n",
3484 src_lc, src_port, src_rxq);
3485 printf(" lcore %hhu Port %hu queue %hu\n",
3486 lc_id, fs->rx_port, fs->rx_queue);
3487 printf("Please use --nb-cores=%hu to limit number of forwarding cores\n",
3496 * Check shared rxq configuration.
3498 * Shared group must not being scheduled on different core.
3501 pkt_fwd_shared_rxq_check(void)
3504 streamid_t nb_fs_per_lcore;
3507 struct fwd_stream *fs;
3509 struct rte_port *port;
3510 struct rte_eth_dev_info *dev_info;
3511 struct rte_eth_rxconf *rxq_conf;
3515 nb_fc = cur_fwd_config.nb_fwd_lcores;
3517 * Check streams on each core, make sure the same switch domain +
3518 * group + queue doesn't get scheduled on other cores.
3520 for (lc_id = 0; lc_id < nb_fc; lc_id++) {
3521 sm_id = fwd_lcores[lc_id]->stream_idx;
3522 nb_fs_per_lcore = fwd_lcores[lc_id]->stream_nb;
3523 for (; sm_id < fwd_lcores[lc_id]->stream_idx + nb_fs_per_lcore;
3525 fs = fwd_streams[sm_id];
3526 /* Update lcore info stream being scheduled. */
3527 fs->lcore = fwd_lcores[lc_id];
3528 port = &ports[fs->rx_port];
3529 dev_info = &port->dev_info;
3530 rxq_conf = &port->rx_conf[fs->rx_queue];
3531 if ((dev_info->dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE)
3532 == 0 || rxq_conf->share_group == 0)
3533 /* Not shared rxq. */
3535 /* Check shared rxq not scheduled on remaining cores. */
3536 domain_id = port->dev_info.switch_info.domain_id;
3537 if (fwd_stream_on_other_lcores(domain_id, lc_id,
3540 rxq_conf->share_group,
3541 rxq_conf->share_qid))
3549 * Setup forwarding configuration for each logical core.
3552 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
3554 streamid_t nb_fs_per_lcore;
3562 nb_fs = cfg->nb_fwd_streams;
3563 nb_fc = cfg->nb_fwd_lcores;
3564 if (nb_fs <= nb_fc) {
3565 nb_fs_per_lcore = 1;
3568 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
3569 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
3572 nb_lc = (lcoreid_t) (nb_fc - nb_extra);
3574 for (lc_id = 0; lc_id < nb_lc; lc_id++) {
3575 fwd_lcores[lc_id]->stream_idx = sm_id;
3576 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
3577 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
3581 * Assign extra remaining streams, if any.
3583 nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
3584 for (lc_id = 0; lc_id < nb_extra; lc_id++) {
3585 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
3586 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
3587 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
3592 fwd_topology_tx_port_get(portid_t rxp)
3594 static int warning_once = 1;
3596 RTE_ASSERT(rxp < cur_fwd_config.nb_fwd_ports);
3598 switch (port_topology) {
3600 case PORT_TOPOLOGY_PAIRED:
3601 if ((rxp & 0x1) == 0) {
3602 if (rxp + 1 < cur_fwd_config.nb_fwd_ports)
3606 "\nWarning! port-topology=paired and odd forward ports number, the last port will pair with itself.\n\n");
3612 case PORT_TOPOLOGY_CHAINED:
3613 return (rxp + 1) % cur_fwd_config.nb_fwd_ports;
3614 case PORT_TOPOLOGY_LOOP:
3620 simple_fwd_config_setup(void)
3624 cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
3625 cur_fwd_config.nb_fwd_streams =
3626 (streamid_t) cur_fwd_config.nb_fwd_ports;
3628 /* reinitialize forwarding streams */
3632 * In the simple forwarding test, the number of forwarding cores
3633 * must be lower or equal to the number of forwarding ports.
3635 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3636 if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
3637 cur_fwd_config.nb_fwd_lcores =
3638 (lcoreid_t) cur_fwd_config.nb_fwd_ports;
3639 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3641 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
3642 fwd_streams[i]->rx_port = fwd_ports_ids[i];
3643 fwd_streams[i]->rx_queue = 0;
3644 fwd_streams[i]->tx_port =
3645 fwd_ports_ids[fwd_topology_tx_port_get(i)];
3646 fwd_streams[i]->tx_queue = 0;
3647 fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port;
3648 fwd_streams[i]->retry_enabled = retry_enabled;
3653 * For the RSS forwarding test all streams distributed over lcores. Each stream
3654 * being composed of a RX queue to poll on a RX port for input messages,
3655 * associated with a TX queue of a TX port where to send forwarded packets.
3658 rss_fwd_config_setup(void)
3671 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3672 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3673 cur_fwd_config.nb_fwd_streams =
3674 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
3676 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3677 cur_fwd_config.nb_fwd_lcores =
3678 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3680 /* reinitialize forwarding streams */
3683 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3685 if (proc_id > 0 && nb_q % num_procs != 0)
3686 printf("Warning! queue numbers should be multiple of processes, or packet loss will happen.\n");
3689 * In multi-process, All queues are allocated to different
3690 * processes based on num_procs and proc_id. For example:
3691 * if supports 4 queues(nb_q), 2 processes(num_procs),
3692 * the 0~1 queue for primary process.
3693 * the 2~3 queue for secondary process.
3695 start = proc_id * nb_q / num_procs;
3696 end = start + nb_q / num_procs;
3699 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
3700 struct fwd_stream *fs;
3702 fs = fwd_streams[sm_id];
3703 txp = fwd_topology_tx_port_get(rxp);
3704 fs->rx_port = fwd_ports_ids[rxp];
3706 fs->tx_port = fwd_ports_ids[txp];
3708 fs->peer_addr = fs->tx_port;
3709 fs->retry_enabled = retry_enabled;
3711 if (rxp < nb_fwd_ports)
3721 get_fwd_port_total_tc_num(void)
3723 struct rte_eth_dcb_info dcb_info;
3724 uint16_t total_tc_num = 0;
3727 for (i = 0; i < nb_fwd_ports; i++) {
3728 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[i], &dcb_info);
3729 total_tc_num += dcb_info.nb_tcs;
3732 return total_tc_num;
3736 * For the DCB forwarding test, each core is assigned on each traffic class.
3738 * Each core is assigned a multi-stream, each stream being composed of
3739 * a RX queue to poll on a RX port for input messages, associated with
3740 * a TX queue of a TX port where to send forwarded packets. All RX and
3741 * TX queues are mapping to the same traffic class.
3742 * If VMDQ and DCB co-exist, each traffic class on different POOLs share
3746 dcb_fwd_config_setup(void)
3748 struct rte_eth_dcb_info rxp_dcb_info, txp_dcb_info;
3749 portid_t txp, rxp = 0;
3750 queueid_t txq, rxq = 0;
3752 uint16_t nb_rx_queue, nb_tx_queue;
3753 uint16_t i, j, k, sm_id = 0;
3754 uint16_t total_tc_num;
3755 struct rte_port *port;
3761 * The fwd_config_setup() is called when the port is RTE_PORT_STARTED
3762 * or RTE_PORT_STOPPED.
3764 * Re-configure ports to get updated mapping between tc and queue in
3765 * case the queue number of the port is changed. Skip for started ports
3766 * since modifying queue number and calling dev_configure need to stop
3769 for (pid = 0; pid < nb_fwd_ports; pid++) {
3770 if (port_is_started(pid) == 1)
3774 ret = rte_eth_dev_configure(pid, nb_rxq, nb_txq,
3778 "Failed to re-configure port %d, ret = %d.\n",
3784 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3785 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3786 cur_fwd_config.nb_fwd_streams =
3787 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3788 total_tc_num = get_fwd_port_total_tc_num();
3789 if (cur_fwd_config.nb_fwd_lcores > total_tc_num)
3790 cur_fwd_config.nb_fwd_lcores = total_tc_num;
3792 /* reinitialize forwarding streams */
3796 /* get the dcb info on the first RX and TX ports */
3797 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3798 (void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3800 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3801 fwd_lcores[lc_id]->stream_nb = 0;
3802 fwd_lcores[lc_id]->stream_idx = sm_id;
3803 for (i = 0; i < RTE_ETH_MAX_VMDQ_POOL; i++) {
3804 /* if the nb_queue is zero, means this tc is
3805 * not enabled on the POOL
3807 if (rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue == 0)
3809 k = fwd_lcores[lc_id]->stream_nb +
3810 fwd_lcores[lc_id]->stream_idx;
3811 rxq = rxp_dcb_info.tc_queue.tc_rxq[i][tc].base;
3812 txq = txp_dcb_info.tc_queue.tc_txq[i][tc].base;
3813 nb_rx_queue = txp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3814 nb_tx_queue = txp_dcb_info.tc_queue.tc_txq[i][tc].nb_queue;
3815 for (j = 0; j < nb_rx_queue; j++) {
3816 struct fwd_stream *fs;
3818 fs = fwd_streams[k + j];
3819 fs->rx_port = fwd_ports_ids[rxp];
3820 fs->rx_queue = rxq + j;
3821 fs->tx_port = fwd_ports_ids[txp];
3822 fs->tx_queue = txq + j % nb_tx_queue;
3823 fs->peer_addr = fs->tx_port;
3824 fs->retry_enabled = retry_enabled;
3826 fwd_lcores[lc_id]->stream_nb +=
3827 rxp_dcb_info.tc_queue.tc_rxq[i][tc].nb_queue;
3829 sm_id = (streamid_t) (sm_id + fwd_lcores[lc_id]->stream_nb);
3832 if (tc < rxp_dcb_info.nb_tcs)
3834 /* Restart from TC 0 on next RX port */
3836 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
3838 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
3841 if (rxp >= nb_fwd_ports)
3843 /* get the dcb information on next RX and TX ports */
3844 if ((rxp & 0x1) == 0)
3845 txp = (portid_t) (rxp + 1);
3847 txp = (portid_t) (rxp - 1);
3848 rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
3849 rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
3854 icmp_echo_config_setup(void)
3861 if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
3862 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
3863 (nb_txq * nb_fwd_ports);
3865 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
3866 cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
3867 cur_fwd_config.nb_fwd_streams =
3868 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
3869 if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
3870 cur_fwd_config.nb_fwd_lcores =
3871 (lcoreid_t)cur_fwd_config.nb_fwd_streams;
3872 if (verbose_level > 0) {
3873 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
3875 cur_fwd_config.nb_fwd_lcores,
3876 cur_fwd_config.nb_fwd_ports,
3877 cur_fwd_config.nb_fwd_streams);
3880 /* reinitialize forwarding streams */
3882 setup_fwd_config_of_each_lcore(&cur_fwd_config);
3884 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
3885 if (verbose_level > 0)
3886 printf(" core=%d: \n", lc_id);
3887 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3888 struct fwd_stream *fs;
3889 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3890 fs->rx_port = fwd_ports_ids[rxp];
3892 fs->tx_port = fs->rx_port;
3894 fs->peer_addr = fs->tx_port;
3895 fs->retry_enabled = retry_enabled;
3896 if (verbose_level > 0)
3897 printf(" stream=%d port=%d rxq=%d txq=%d\n",
3898 sm_id, fs->rx_port, fs->rx_queue,
3900 rxq = (queueid_t) (rxq + 1);
3901 if (rxq == nb_rxq) {
3903 rxp = (portid_t) (rxp + 1);
3910 fwd_config_setup(void)
3912 struct rte_port *port;
3916 cur_fwd_config.fwd_eng = cur_fwd_eng;
3917 if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
3918 icmp_echo_config_setup();
3922 if ((nb_rxq > 1) && (nb_txq > 1)){
3924 for (i = 0; i < nb_fwd_ports; i++) {
3925 pt_id = fwd_ports_ids[i];
3926 port = &ports[pt_id];
3927 if (!port->dcb_flag) {
3929 "In DCB mode, all forwarding ports must be configured in this mode.\n");
3933 if (nb_fwd_lcores == 1) {
3935 "In DCB mode,the nb forwarding cores should be larger than 1.\n");
3939 dcb_fwd_config_setup();
3941 rss_fwd_config_setup();
3944 simple_fwd_config_setup();
3948 mp_alloc_to_str(uint8_t mode)
3951 case MP_ALLOC_NATIVE:
3957 case MP_ALLOC_XMEM_HUGE:
3967 pkt_fwd_config_display(struct fwd_config *cfg)
3969 struct fwd_stream *fs;
3973 printf("%s packet forwarding%s - ports=%d - cores=%d - streams=%d - "
3974 "NUMA support %s, MP allocation mode: %s\n",
3975 cfg->fwd_eng->fwd_mode_name,
3976 retry_enabled == 0 ? "" : " with retry",
3977 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
3978 numa_support == 1 ? "enabled" : "disabled",
3979 mp_alloc_to_str(mp_alloc_type));
3982 printf("TX retry num: %u, delay between TX retries: %uus\n",
3983 burst_tx_retry_num, burst_tx_delay_time);
3984 for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
3985 printf("Logical Core %u (socket %u) forwards packets on "
3987 fwd_lcores_cpuids[lc_id],
3988 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
3989 fwd_lcores[lc_id]->stream_nb);
3990 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
3991 fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
3992 printf("\n RX P=%d/Q=%d (socket %u) -> TX "
3993 "P=%d/Q=%d (socket %u) ",
3994 fs->rx_port, fs->rx_queue,
3995 ports[fs->rx_port].socket_id,
3996 fs->tx_port, fs->tx_queue,
3997 ports[fs->tx_port].socket_id);
3998 print_ethaddr("peer=",
3999 &peer_eth_addrs[fs->peer_addr]);
4007 set_fwd_eth_peer(portid_t port_id, char *peer_addr)
4009 struct rte_ether_addr new_peer_addr;
4010 if (!rte_eth_dev_is_valid_port(port_id)) {
4011 fprintf(stderr, "Error: Invalid port number %i\n", port_id);
4014 if (rte_ether_unformat_addr(peer_addr, &new_peer_addr) < 0) {
4015 fprintf(stderr, "Error: Invalid ethernet address: %s\n",
4019 peer_eth_addrs[port_id] = new_peer_addr;
4023 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
4026 unsigned int lcore_cpuid;
4031 for (i = 0; i < nb_lc; i++) {
4032 lcore_cpuid = lcorelist[i];
4033 if (! rte_lcore_is_enabled(lcore_cpuid)) {
4034 fprintf(stderr, "lcore %u not enabled\n", lcore_cpuid);
4037 if (lcore_cpuid == rte_get_main_lcore()) {
4039 "lcore %u cannot be masked on for running packet forwarding, which is the main lcore and reserved for command line parsing only\n",
4044 fwd_lcores_cpuids[i] = lcore_cpuid;
4046 if (record_now == 0) {
4050 nb_cfg_lcores = (lcoreid_t) nb_lc;
4051 if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
4052 printf("previous number of forwarding cores %u - changed to "
4053 "number of configured cores %u\n",
4054 (unsigned int) nb_fwd_lcores, nb_lc);
4055 nb_fwd_lcores = (lcoreid_t) nb_lc;
4062 set_fwd_lcores_mask(uint64_t lcoremask)
4064 unsigned int lcorelist[64];
4068 if (lcoremask == 0) {
4069 fprintf(stderr, "Invalid NULL mask of cores\n");
4073 for (i = 0; i < 64; i++) {
4074 if (! ((uint64_t)(1ULL << i) & lcoremask))
4076 lcorelist[nb_lc++] = i;
4078 return set_fwd_lcores_list(lcorelist, nb_lc);
4082 set_fwd_lcores_number(uint16_t nb_lc)
4084 if (test_done == 0) {
4085 fprintf(stderr, "Please stop forwarding first\n");
4088 if (nb_lc > nb_cfg_lcores) {
4090 "nb fwd cores %u > %u (max. number of configured lcores) - ignored\n",
4091 (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
4094 nb_fwd_lcores = (lcoreid_t) nb_lc;
4095 printf("Number of forwarding cores set to %u\n",
4096 (unsigned int) nb_fwd_lcores);
4100 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
4108 for (i = 0; i < nb_pt; i++) {
4109 port_id = (portid_t) portlist[i];
4110 if (port_id_is_invalid(port_id, ENABLED_WARN))
4113 fwd_ports_ids[i] = port_id;
4115 if (record_now == 0) {
4119 nb_cfg_ports = (portid_t) nb_pt;
4120 if (nb_fwd_ports != (portid_t) nb_pt) {
4121 printf("previous number of forwarding ports %u - changed to "
4122 "number of configured ports %u\n",
4123 (unsigned int) nb_fwd_ports, nb_pt);
4124 nb_fwd_ports = (portid_t) nb_pt;
4129 * Parse the user input and obtain the list of forwarding ports
4132 * String containing the user input. User can specify
4133 * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
4134 * For example, if the user wants to use all the available
4135 * 4 ports in his system, then the input can be 0-3 or 0,1,2,3.
4136 * If the user wants to use only the ports 1,2 then the input
4138 * valid characters are '-' and ','
4139 * @param[out] values
4140 * This array will be filled with a list of port IDs
4141 * based on the user input
4142 * Note that duplicate entries are discarded and only the first
4143 * count entries in this array are port IDs and all the rest
4144 * will contain default values
4145 * @param[in] maxsize
4146 * This parameter denotes 2 things
4147 * 1) Number of elements in the values array
4148 * 2) Maximum value of each element in the values array
4150 * On success, returns total count of parsed port IDs
4151 * On failure, returns 0
4154 parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
4156 unsigned int count = 0;
4160 unsigned int marked[maxsize];
4162 if (list == NULL || values == NULL)
4165 for (i = 0; i < (int)maxsize; i++)
4171 /*Remove the blank spaces if any*/
4172 while (isblank(*list))
4177 value = strtol(list, &end, 10);
4178 if (errno || end == NULL)
4180 if (value < 0 || value >= (int)maxsize)
4182 while (isblank(*end))
4184 if (*end == '-' && min == INT_MAX) {
4186 } else if ((*end == ',') || (*end == '\0')) {
4190 for (i = min; i <= max; i++) {
4191 if (count < maxsize) {
4203 } while (*end != '\0');
4209 parse_fwd_portlist(const char *portlist)
4211 unsigned int portcount;
4212 unsigned int portindex[RTE_MAX_ETHPORTS];
4213 unsigned int i, valid_port_count = 0;
4215 portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
4217 rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
4220 * Here we verify the validity of the ports
4221 * and thereby calculate the total number of
4224 for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
4225 if (rte_eth_dev_is_valid_port(portindex[i])) {
4226 portindex[valid_port_count] = portindex[i];
4231 set_fwd_ports_list(portindex, valid_port_count);
4235 set_fwd_ports_mask(uint64_t portmask)
4237 unsigned int portlist[64];
4241 if (portmask == 0) {
4242 fprintf(stderr, "Invalid NULL mask of ports\n");
4246 RTE_ETH_FOREACH_DEV(i) {
4247 if (! ((uint64_t)(1ULL << i) & portmask))
4249 portlist[nb_pt++] = i;
4251 set_fwd_ports_list(portlist, nb_pt);
4255 set_fwd_ports_number(uint16_t nb_pt)
4257 if (nb_pt > nb_cfg_ports) {
4259 "nb fwd ports %u > %u (number of configured ports) - ignored\n",
4260 (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
4263 nb_fwd_ports = (portid_t) nb_pt;
4264 printf("Number of forwarding ports set to %u\n",
4265 (unsigned int) nb_fwd_ports);
4269 port_is_forwarding(portid_t port_id)
4273 if (port_id_is_invalid(port_id, ENABLED_WARN))
4276 for (i = 0; i < nb_fwd_ports; i++) {
4277 if (fwd_ports_ids[i] == port_id)
4285 set_nb_pkt_per_burst(uint16_t nb)
4287 if (nb > MAX_PKT_BURST) {
4289 "nb pkt per burst: %u > %u (maximum packet per burst) ignored\n",
4290 (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
4293 nb_pkt_per_burst = nb;
4294 printf("Number of packets per burst set to %u\n",
4295 (unsigned int) nb_pkt_per_burst);
4299 tx_split_get_name(enum tx_pkt_split split)
4303 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
4304 if (tx_split_name[i].split == split)
4305 return tx_split_name[i].name;
4311 set_tx_pkt_split(const char *name)
4315 for (i = 0; i != RTE_DIM(tx_split_name); i++) {
4316 if (strcmp(tx_split_name[i].name, name) == 0) {
4317 tx_pkt_split = tx_split_name[i].split;
4321 fprintf(stderr, "unknown value: \"%s\"\n", name);
4325 parse_fec_mode(const char *name, uint32_t *fec_capa)
4329 for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
4330 if (strcmp(fec_mode_name[i].name, name) == 0) {
4332 RTE_ETH_FEC_MODE_TO_CAPA(fec_mode_name[i].mode);
4340 show_fec_capability(unsigned int num, struct rte_eth_fec_capa *speed_fec_capa)
4344 printf("FEC capabilities:\n");
4346 for (i = 0; i < num; i++) {
4348 rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
4350 for (j = 0; j < RTE_DIM(fec_mode_name); j++) {
4351 if (RTE_ETH_FEC_MODE_TO_CAPA(j) &
4352 speed_fec_capa[i].capa)
4353 printf("%s ", fec_mode_name[j].name);
4360 show_rx_pkt_offsets(void)
4365 printf("Number of offsets: %u\n", n);
4367 printf("Segment offsets: ");
4368 for (i = 0; i != n - 1; i++)
4369 printf("%hu,", rx_pkt_seg_offsets[i]);
4370 printf("%hu\n", rx_pkt_seg_lengths[i]);
4375 set_rx_pkt_offsets(unsigned int *seg_offsets, unsigned int nb_offs)
4379 if (nb_offs >= MAX_SEGS_BUFFER_SPLIT) {
4380 printf("nb segments per RX packets=%u >= "
4381 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_offs);
4386 * No extra check here, the segment length will be checked by PMD
4387 * in the extended queue setup.
4389 for (i = 0; i < nb_offs; i++) {
4390 if (seg_offsets[i] >= UINT16_MAX) {
4391 printf("offset[%u]=%u > UINT16_MAX - give up\n",
4397 for (i = 0; i < nb_offs; i++)
4398 rx_pkt_seg_offsets[i] = (uint16_t) seg_offsets[i];
4400 rx_pkt_nb_offs = (uint8_t) nb_offs;
4404 show_rx_pkt_segments(void)
4409 printf("Number of segments: %u\n", n);
4411 printf("Segment sizes: ");
4412 for (i = 0; i != n - 1; i++)
4413 printf("%hu,", rx_pkt_seg_lengths[i]);
4414 printf("%hu\n", rx_pkt_seg_lengths[i]);
4419 set_rx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
4423 if (nb_segs >= MAX_SEGS_BUFFER_SPLIT) {
4424 printf("nb segments per RX packets=%u >= "
4425 "MAX_SEGS_BUFFER_SPLIT - ignored\n", nb_segs);
4430 * No extra check here, the segment length will be checked by PMD
4431 * in the extended queue setup.
4433 for (i = 0; i < nb_segs; i++) {
4434 if (seg_lengths[i] >= UINT16_MAX) {
4435 printf("length[%u]=%u > UINT16_MAX - give up\n",
4441 for (i = 0; i < nb_segs; i++)
4442 rx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
4444 rx_pkt_nb_segs = (uint8_t) nb_segs;
4448 show_tx_pkt_segments(void)
4454 split = tx_split_get_name(tx_pkt_split);
4456 printf("Number of segments: %u\n", n);
4457 printf("Segment sizes: ");
4458 for (i = 0; i != n - 1; i++)
4459 printf("%hu,", tx_pkt_seg_lengths[i]);
4460 printf("%hu\n", tx_pkt_seg_lengths[i]);
4461 printf("Split packet: %s\n", split);
4465 nb_segs_is_invalid(unsigned int nb_segs)
4472 RTE_ETH_FOREACH_DEV(port_id) {
4473 for (queue_id = 0; queue_id < nb_txq; queue_id++) {
4474 ret = get_tx_ring_size(port_id, queue_id, &ring_size);
4476 /* Port may not be initialized yet, can't say
4477 * the port is invalid in this stage.
4481 if (ring_size < nb_segs) {
4482 printf("nb segments per TX packets=%u >= TX "
4483 "queue(%u) ring_size=%u - txpkts ignored\n",
4484 nb_segs, queue_id, ring_size);
4494 set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
4496 uint16_t tx_pkt_len;
4500 * For single segment settings failed check is ignored.
4501 * It is a very basic capability to send the single segment
4502 * packets, suppose it is always supported.
4504 if (nb_segs > 1 && nb_segs_is_invalid(nb_segs)) {
4506 "Tx segment size(%u) is not supported - txpkts ignored\n",
4511 if (nb_segs > RTE_MAX_SEGS_PER_PKT) {
4513 "Tx segment size(%u) is bigger than max number of segment(%u)\n",
4514 nb_segs, RTE_MAX_SEGS_PER_PKT);
4519 * Check that each segment length is greater or equal than
4520 * the mbuf data size.
4521 * Check also that the total packet length is greater or equal than the
4522 * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) +
4526 for (i = 0; i < nb_segs; i++) {
4527 if (seg_lengths[i] > mbuf_data_size[0]) {
4529 "length[%u]=%u > mbuf_data_size=%u - give up\n",
4530 i, seg_lengths[i], mbuf_data_size[0]);
4533 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
4535 if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) {
4536 fprintf(stderr, "total packet length=%u < %d - give up\n",
4537 (unsigned) tx_pkt_len,
4538 (int)(sizeof(struct rte_ether_hdr) + 20 + 8));
4542 for (i = 0; i < nb_segs; i++)
4543 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
4545 tx_pkt_length = tx_pkt_len;
4546 tx_pkt_nb_segs = (uint8_t) nb_segs;
4550 show_tx_pkt_times(void)
4552 printf("Interburst gap: %u\n", tx_pkt_times_inter);
4553 printf("Intraburst gap: %u\n", tx_pkt_times_intra);
4557 set_tx_pkt_times(unsigned int *tx_times)
4559 tx_pkt_times_inter = tx_times[0];
4560 tx_pkt_times_intra = tx_times[1];
4565 setup_gro(const char *onoff, portid_t port_id)
4567 if (!rte_eth_dev_is_valid_port(port_id)) {
4568 fprintf(stderr, "invalid port id %u\n", port_id);
4571 if (test_done == 0) {
4573 "Before enable/disable GRO, please stop forwarding first\n");
4576 if (strcmp(onoff, "on") == 0) {
4577 if (gro_ports[port_id].enable != 0) {
4579 "Port %u has enabled GRO. Please disable GRO first\n",
4583 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
4584 gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4;
4585 gro_ports[port_id].param.max_flow_num =
4586 GRO_DEFAULT_FLOW_NUM;
4587 gro_ports[port_id].param.max_item_per_flow =
4588 GRO_DEFAULT_ITEM_NUM_PER_FLOW;
4590 gro_ports[port_id].enable = 1;
4592 if (gro_ports[port_id].enable == 0) {
4593 fprintf(stderr, "Port %u has disabled GRO\n", port_id);
4596 gro_ports[port_id].enable = 0;
4601 setup_gro_flush_cycles(uint8_t cycles)
4603 if (test_done == 0) {
4605 "Before change flush interval for GRO, please stop forwarding first.\n");
4609 if (cycles > GRO_MAX_FLUSH_CYCLES || cycles <
4610 GRO_DEFAULT_FLUSH_CYCLES) {
4612 "The flushing cycle be in the range of 1 to %u. Revert to the default value %u.\n",
4613 GRO_MAX_FLUSH_CYCLES, GRO_DEFAULT_FLUSH_CYCLES);
4614 cycles = GRO_DEFAULT_FLUSH_CYCLES;
4617 gro_flush_cycles = cycles;
4621 show_gro(portid_t port_id)
4623 struct rte_gro_param *param;
4624 uint32_t max_pkts_num;
4626 param = &gro_ports[port_id].param;
4628 if (!rte_eth_dev_is_valid_port(port_id)) {
4629 fprintf(stderr, "Invalid port id %u.\n", port_id);
4632 if (gro_ports[port_id].enable) {
4633 printf("GRO type: TCP/IPv4\n");
4634 if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) {
4635 max_pkts_num = param->max_flow_num *
4636 param->max_item_per_flow;
4638 max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES;
4639 printf("Max number of packets to perform GRO: %u\n",
4641 printf("Flushing cycles: %u\n", gro_flush_cycles);
4643 printf("Port %u doesn't enable GRO.\n", port_id);
4645 #endif /* RTE_LIB_GRO */
4649 setup_gso(const char *mode, portid_t port_id)
4651 if (!rte_eth_dev_is_valid_port(port_id)) {
4652 fprintf(stderr, "invalid port id %u\n", port_id);
4655 if (strcmp(mode, "on") == 0) {
4656 if (test_done == 0) {
4658 "before enabling GSO, please stop forwarding first\n");
4661 gso_ports[port_id].enable = 1;
4662 } else if (strcmp(mode, "off") == 0) {
4663 if (test_done == 0) {
4665 "before disabling GSO, please stop forwarding first\n");
4668 gso_ports[port_id].enable = 0;
4671 #endif /* RTE_LIB_GSO */
4674 list_pkt_forwarding_modes(void)
4676 static char fwd_modes[128] = "";
4677 const char *separator = "|";
4678 struct fwd_engine *fwd_eng;
4681 if (strlen (fwd_modes) == 0) {
4682 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4683 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4684 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4685 strncat(fwd_modes, separator,
4686 sizeof(fwd_modes) - strlen(fwd_modes) - 1);
4688 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4695 list_pkt_forwarding_retry_modes(void)
4697 static char fwd_modes[128] = "";
4698 const char *separator = "|";
4699 struct fwd_engine *fwd_eng;
4702 if (strlen(fwd_modes) == 0) {
4703 while ((fwd_eng = fwd_engines[i++]) != NULL) {
4704 if (fwd_eng == &rx_only_engine)
4706 strncat(fwd_modes, fwd_eng->fwd_mode_name,
4708 strlen(fwd_modes) - 1);
4709 strncat(fwd_modes, separator,
4711 strlen(fwd_modes) - 1);
4713 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
4720 set_pkt_forwarding_mode(const char *fwd_mode_name)
4722 struct fwd_engine *fwd_eng;
4726 while ((fwd_eng = fwd_engines[i]) != NULL) {
4727 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
4728 printf("Set %s packet forwarding mode%s\n",
4730 retry_enabled == 0 ? "" : " with retry");
4731 cur_fwd_eng = fwd_eng;
4736 fprintf(stderr, "Invalid %s packet forwarding mode\n", fwd_mode_name);
4740 add_rx_dump_callbacks(portid_t portid)
4742 struct rte_eth_dev_info dev_info;
4746 if (port_id_is_invalid(portid, ENABLED_WARN))
4749 ret = eth_dev_info_get_print_err(portid, &dev_info);
4753 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4754 if (!ports[portid].rx_dump_cb[queue])
4755 ports[portid].rx_dump_cb[queue] =
4756 rte_eth_add_rx_callback(portid, queue,
4757 dump_rx_pkts, NULL);
4761 add_tx_dump_callbacks(portid_t portid)
4763 struct rte_eth_dev_info dev_info;
4767 if (port_id_is_invalid(portid, ENABLED_WARN))
4770 ret = eth_dev_info_get_print_err(portid, &dev_info);
4774 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4775 if (!ports[portid].tx_dump_cb[queue])
4776 ports[portid].tx_dump_cb[queue] =
4777 rte_eth_add_tx_callback(portid, queue,
4778 dump_tx_pkts, NULL);
4782 remove_rx_dump_callbacks(portid_t portid)
4784 struct rte_eth_dev_info dev_info;
4788 if (port_id_is_invalid(portid, ENABLED_WARN))
4791 ret = eth_dev_info_get_print_err(portid, &dev_info);
4795 for (queue = 0; queue < dev_info.nb_rx_queues; queue++)
4796 if (ports[portid].rx_dump_cb[queue]) {
4797 rte_eth_remove_rx_callback(portid, queue,
4798 ports[portid].rx_dump_cb[queue]);
4799 ports[portid].rx_dump_cb[queue] = NULL;
4804 remove_tx_dump_callbacks(portid_t portid)
4806 struct rte_eth_dev_info dev_info;
4810 if (port_id_is_invalid(portid, ENABLED_WARN))
4813 ret = eth_dev_info_get_print_err(portid, &dev_info);
4817 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
4818 if (ports[portid].tx_dump_cb[queue]) {
4819 rte_eth_remove_tx_callback(portid, queue,
4820 ports[portid].tx_dump_cb[queue]);
4821 ports[portid].tx_dump_cb[queue] = NULL;
4826 configure_rxtx_dump_callbacks(uint16_t verbose)
4830 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
4831 TESTPMD_LOG(ERR, "setting rxtx callbacks is not enabled\n");
4835 RTE_ETH_FOREACH_DEV(portid)
4837 if (verbose == 1 || verbose > 2)
4838 add_rx_dump_callbacks(portid);
4840 remove_rx_dump_callbacks(portid);
4842 add_tx_dump_callbacks(portid);
4844 remove_tx_dump_callbacks(portid);
4849 set_verbose_level(uint16_t vb_level)
4851 printf("Change verbose level from %u to %u\n",
4852 (unsigned int) verbose_level, (unsigned int) vb_level);
4853 verbose_level = vb_level;
4854 configure_rxtx_dump_callbacks(verbose_level);
4858 vlan_extend_set(portid_t port_id, int on)
4862 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4864 if (port_id_is_invalid(port_id, ENABLED_WARN))
4867 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4870 vlan_offload |= RTE_ETH_VLAN_EXTEND_OFFLOAD;
4871 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4873 vlan_offload &= ~RTE_ETH_VLAN_EXTEND_OFFLOAD;
4874 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4877 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4880 "rx_vlan_extend_set(port_pi=%d, on=%d) failed diag=%d\n",
4884 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4888 rx_vlan_strip_set(portid_t port_id, int on)
4892 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4894 if (port_id_is_invalid(port_id, ENABLED_WARN))
4897 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4900 vlan_offload |= RTE_ETH_VLAN_STRIP_OFFLOAD;
4901 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4903 vlan_offload &= ~RTE_ETH_VLAN_STRIP_OFFLOAD;
4904 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4907 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4910 "%s(port_pi=%d, on=%d) failed diag=%d\n",
4911 __func__, port_id, on, diag);
4914 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4918 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
4922 if (port_id_is_invalid(port_id, ENABLED_WARN))
4925 diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
4928 "%s(port_pi=%d, queue_id=%d, on=%d) failed diag=%d\n",
4929 __func__, port_id, queue_id, on, diag);
4933 rx_vlan_filter_set(portid_t port_id, int on)
4937 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4939 if (port_id_is_invalid(port_id, ENABLED_WARN))
4942 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4945 vlan_offload |= RTE_ETH_VLAN_FILTER_OFFLOAD;
4946 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4948 vlan_offload &= ~RTE_ETH_VLAN_FILTER_OFFLOAD;
4949 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4952 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4955 "%s(port_pi=%d, on=%d) failed diag=%d\n",
4956 __func__, port_id, on, diag);
4959 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4963 rx_vlan_qinq_strip_set(portid_t port_id, int on)
4967 uint64_t port_rx_offloads = ports[port_id].dev_conf.rxmode.offloads;
4969 if (port_id_is_invalid(port_id, ENABLED_WARN))
4972 vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
4975 vlan_offload |= RTE_ETH_QINQ_STRIP_OFFLOAD;
4976 port_rx_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4978 vlan_offload &= ~RTE_ETH_QINQ_STRIP_OFFLOAD;
4979 port_rx_offloads &= ~RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4982 diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
4984 fprintf(stderr, "%s(port_pi=%d, on=%d) failed diag=%d\n",
4985 __func__, port_id, on, diag);
4988 ports[port_id].dev_conf.rxmode.offloads = port_rx_offloads;
4992 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
4996 if (port_id_is_invalid(port_id, ENABLED_WARN))
4998 if (vlan_id_is_invalid(vlan_id))
5000 diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
5004 "rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed diag=%d\n",
5005 port_id, vlan_id, on, diag);
5010 rx_vlan_all_filter_set(portid_t port_id, int on)
5014 if (port_id_is_invalid(port_id, ENABLED_WARN))
5016 for (vlan_id = 0; vlan_id < 4096; vlan_id++) {
5017 if (rx_vft_set(port_id, vlan_id, on))
5023 vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
5027 if (port_id_is_invalid(port_id, ENABLED_WARN))
5030 diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
5035 "tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed diag=%d\n",
5036 port_id, vlan_type, tp_id, diag);
5040 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
5042 struct rte_eth_dev_info dev_info;
5045 if (vlan_id_is_invalid(vlan_id))
5048 if (ports[port_id].dev_conf.txmode.offloads &
5049 RTE_ETH_TX_OFFLOAD_QINQ_INSERT) {
5050 fprintf(stderr, "Error, as QinQ has been enabled.\n");
5054 ret = eth_dev_info_get_print_err(port_id, &dev_info);
5058 if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_VLAN_INSERT) == 0) {
5060 "Error: vlan insert is not supported by port %d\n",
5065 tx_vlan_reset(port_id);
5066 ports[port_id].dev_conf.txmode.offloads |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
5067 ports[port_id].tx_vlan_id = vlan_id;
5071 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
5073 struct rte_eth_dev_info dev_info;
5076 if (vlan_id_is_invalid(vlan_id))
5078 if (vlan_id_is_invalid(vlan_id_outer))
5081 ret = eth_dev_info_get_print_err(port_id, &dev_info);
5085 if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_QINQ_INSERT) == 0) {
5087 "Error: qinq insert not supported by port %d\n",
5092 tx_vlan_reset(port_id);
5093 ports[port_id].dev_conf.txmode.offloads |= (RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
5094 RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
5095 ports[port_id].tx_vlan_id = vlan_id;
5096 ports[port_id].tx_vlan_id_outer = vlan_id_outer;
5100 tx_vlan_reset(portid_t port_id)
5102 ports[port_id].dev_conf.txmode.offloads &=
5103 ~(RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
5104 RTE_ETH_TX_OFFLOAD_QINQ_INSERT);
5105 ports[port_id].tx_vlan_id = 0;
5106 ports[port_id].tx_vlan_id_outer = 0;
5110 tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on)
5112 if (port_id_is_invalid(port_id, ENABLED_WARN))
5115 rte_eth_dev_set_vlan_pvid(port_id, vlan_id, on);
5119 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
5123 if (port_id_is_invalid(port_id, ENABLED_WARN))
5126 if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
5129 if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
5130 fprintf(stderr, "map_value not in required range 0..%d\n",
5131 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
5135 if (!is_rx) { /* tx */
5136 ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, queue_id,
5140 "failed to set tx queue stats mapping.\n");
5144 ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, queue_id,
5148 "failed to set rx queue stats mapping.\n");
5155 set_xstats_hide_zero(uint8_t on_off)
5157 xstats_hide_zero = on_off;
5161 set_record_core_cycles(uint8_t on_off)
5163 record_core_cycles = on_off;
5167 set_record_burst_stats(uint8_t on_off)
5169 record_burst_stats = on_off;
5173 flowtype_to_str(uint16_t flow_type)
5175 struct flow_type_info {
5181 static struct flow_type_info flowtype_str_table[] = {
5182 {"raw", RTE_ETH_FLOW_RAW},
5183 {"ipv4", RTE_ETH_FLOW_IPV4},
5184 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
5185 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
5186 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
5187 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
5188 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
5189 {"ipv6", RTE_ETH_FLOW_IPV6},
5190 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
5191 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
5192 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
5193 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
5194 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
5195 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
5196 {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
5197 {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
5198 {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
5199 {"port", RTE_ETH_FLOW_PORT},
5200 {"vxlan", RTE_ETH_FLOW_VXLAN},
5201 {"geneve", RTE_ETH_FLOW_GENEVE},
5202 {"nvgre", RTE_ETH_FLOW_NVGRE},
5203 {"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
5204 {"gtpu", RTE_ETH_FLOW_GTPU},
5207 for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
5208 if (flowtype_str_table[i].ftype == flow_type)
5209 return flowtype_str_table[i].str;
5215 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
5218 print_fdir_mask(struct rte_eth_fdir_masks *mask)
5220 printf("\n vlan_tci: 0x%04x", rte_be_to_cpu_16(mask->vlan_tci_mask));
5222 if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
5223 printf(", mac_addr: 0x%02x, tunnel_type: 0x%01x,"
5224 " tunnel_id: 0x%08x",
5225 mask->mac_addr_byte_mask, mask->tunnel_type_mask,
5226 rte_be_to_cpu_32(mask->tunnel_id_mask));
5227 else if (fdir_conf.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
5228 printf(", src_ipv4: 0x%08x, dst_ipv4: 0x%08x",
5229 rte_be_to_cpu_32(mask->ipv4_mask.src_ip),
5230 rte_be_to_cpu_32(mask->ipv4_mask.dst_ip));
5232 printf("\n src_port: 0x%04x, dst_port: 0x%04x",
5233 rte_be_to_cpu_16(mask->src_port_mask),
5234 rte_be_to_cpu_16(mask->dst_port_mask));
5236 printf("\n src_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
5237 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[0]),
5238 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[1]),
5239 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[2]),
5240 rte_be_to_cpu_32(mask->ipv6_mask.src_ip[3]));
5242 printf("\n dst_ipv6: 0x%08x,0x%08x,0x%08x,0x%08x",
5243 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[0]),
5244 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[1]),
5245 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[2]),
5246 rte_be_to_cpu_32(mask->ipv6_mask.dst_ip[3]));
5253 print_fdir_flex_payload(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
5255 struct rte_eth_flex_payload_cfg *cfg;
5258 for (i = 0; i < flex_conf->nb_payloads; i++) {
5259 cfg = &flex_conf->flex_set[i];
5260 if (cfg->type == RTE_ETH_RAW_PAYLOAD)
5262 else if (cfg->type == RTE_ETH_L2_PAYLOAD)
5263 printf("\n L2_PAYLOAD: ");
5264 else if (cfg->type == RTE_ETH_L3_PAYLOAD)
5265 printf("\n L3_PAYLOAD: ");
5266 else if (cfg->type == RTE_ETH_L4_PAYLOAD)
5267 printf("\n L4_PAYLOAD: ");
5269 printf("\n UNKNOWN PAYLOAD(%u): ", cfg->type);
5270 for (j = 0; j < num; j++)
5271 printf(" %-5u", cfg->src_offset[j]);
5277 print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
5279 struct rte_eth_fdir_flex_mask *mask;
5283 for (i = 0; i < flex_conf->nb_flexmasks; i++) {
5284 mask = &flex_conf->flex_mask[i];
5285 p = flowtype_to_str(mask->flow_type);
5286 printf("\n %s:\t", p ? p : "unknown");
5287 for (j = 0; j < num; j++)
5288 printf(" %02x", mask->mask[j]);
5294 print_fdir_flow_type(uint32_t flow_types_mask)
5299 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
5300 if (!(flow_types_mask & (1 << i)))
5302 p = flowtype_to_str(i);
5312 get_fdir_info(portid_t port_id, struct rte_eth_fdir_info *fdir_info,
5313 struct rte_eth_fdir_stats *fdir_stat)
5318 if (ret == -ENOTSUP) {
5319 ret = rte_pmd_i40e_get_fdir_info(port_id, fdir_info);
5321 ret = rte_pmd_i40e_get_fdir_stats(port_id, fdir_stat);
5324 #ifdef RTE_NET_IXGBE
5325 if (ret == -ENOTSUP) {
5326 ret = rte_pmd_ixgbe_get_fdir_info(port_id, fdir_info);
5328 ret = rte_pmd_ixgbe_get_fdir_stats(port_id, fdir_stat);
5335 fprintf(stderr, "\n FDIR is not supported on port %-2d\n",
5339 fprintf(stderr, "programming error: (%s)\n", strerror(-ret));
5346 fdir_get_infos(portid_t port_id)
5348 struct rte_eth_fdir_stats fdir_stat;
5349 struct rte_eth_fdir_info fdir_info;
5351 static const char *fdir_stats_border = "########################";
5353 if (port_id_is_invalid(port_id, ENABLED_WARN))
5356 memset(&fdir_info, 0, sizeof(fdir_info));
5357 memset(&fdir_stat, 0, sizeof(fdir_stat));
5358 if (get_fdir_info(port_id, &fdir_info, &fdir_stat))
5361 printf("\n %s FDIR infos for port %-2d %s\n",
5362 fdir_stats_border, port_id, fdir_stats_border);
5364 if (fdir_info.mode == RTE_FDIR_MODE_PERFECT)
5365 printf(" PERFECT\n");
5366 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN)
5367 printf(" PERFECT-MAC-VLAN\n");
5368 else if (fdir_info.mode == RTE_FDIR_MODE_PERFECT_TUNNEL)
5369 printf(" PERFECT-TUNNEL\n");
5370 else if (fdir_info.mode == RTE_FDIR_MODE_SIGNATURE)
5371 printf(" SIGNATURE\n");
5373 printf(" DISABLE\n");
5374 if (fdir_info.mode != RTE_FDIR_MODE_PERFECT_MAC_VLAN
5375 && fdir_info.mode != RTE_FDIR_MODE_PERFECT_TUNNEL) {
5376 printf(" SUPPORTED FLOW TYPE: ");
5377 print_fdir_flow_type(fdir_info.flow_types_mask[0]);
5379 printf(" FLEX PAYLOAD INFO:\n");
5380 printf(" max_len: %-10"PRIu32" payload_limit: %-10"PRIu32"\n"
5381 " payload_unit: %-10"PRIu32" payload_seg: %-10"PRIu32"\n"
5382 " bitmask_unit: %-10"PRIu32" bitmask_num: %-10"PRIu32"\n",
5383 fdir_info.max_flexpayload, fdir_info.flex_payload_limit,
5384 fdir_info.flex_payload_unit,
5385 fdir_info.max_flex_payload_segment_num,
5386 fdir_info.flex_bitmask_unit, fdir_info.max_flex_bitmask_num);
5388 print_fdir_mask(&fdir_info.mask);
5389 if (fdir_info.flex_conf.nb_payloads > 0) {
5390 printf(" FLEX PAYLOAD SRC OFFSET:");
5391 print_fdir_flex_payload(&fdir_info.flex_conf, fdir_info.max_flexpayload);
5393 if (fdir_info.flex_conf.nb_flexmasks > 0) {
5394 printf(" FLEX MASK CFG:");
5395 print_fdir_flex_mask(&fdir_info.flex_conf, fdir_info.max_flexpayload);
5397 printf(" guarant_count: %-10"PRIu32" best_count: %"PRIu32"\n",
5398 fdir_stat.guarant_cnt, fdir_stat.best_cnt);
5399 printf(" guarant_space: %-10"PRIu32" best_space: %"PRIu32"\n",
5400 fdir_info.guarant_spc, fdir_info.best_spc);
5401 printf(" collision: %-10"PRIu32" free: %"PRIu32"\n"
5402 " maxhash: %-10"PRIu32" maxlen: %"PRIu32"\n"
5403 " add: %-10"PRIu64" remove: %"PRIu64"\n"
5404 " f_add: %-10"PRIu64" f_remove: %"PRIu64"\n",
5405 fdir_stat.collision, fdir_stat.free,
5406 fdir_stat.maxhash, fdir_stat.maxlen,
5407 fdir_stat.add, fdir_stat.remove,
5408 fdir_stat.f_add, fdir_stat.f_remove);
5409 printf(" %s############################%s\n",
5410 fdir_stats_border, fdir_stats_border);
5413 #endif /* RTE_NET_I40E || RTE_NET_IXGBE */
5416 fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg)
5418 struct rte_port *port;
5419 struct rte_eth_fdir_flex_conf *flex_conf;
5422 port = &ports[port_id];
5423 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
5424 for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
5425 if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) {
5430 if (i >= RTE_ETH_FLOW_MAX) {
5431 if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) {
5432 idx = flex_conf->nb_flexmasks;
5433 flex_conf->nb_flexmasks++;
5436 "The flex mask table is full. Can not set flex mask for flow_type(%u).",
5441 rte_memcpy(&flex_conf->flex_mask[idx],
5443 sizeof(struct rte_eth_fdir_flex_mask));
5447 fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg)
5449 struct rte_port *port;
5450 struct rte_eth_fdir_flex_conf *flex_conf;
5453 port = &ports[port_id];
5454 flex_conf = &port->dev_conf.fdir_conf.flex_conf;
5455 for (i = 0; i < RTE_ETH_PAYLOAD_MAX; i++) {
5456 if (cfg->type == flex_conf->flex_set[i].type) {
5461 if (i >= RTE_ETH_PAYLOAD_MAX) {
5462 if (flex_conf->nb_payloads < RTE_DIM(flex_conf->flex_set)) {
5463 idx = flex_conf->nb_payloads;
5464 flex_conf->nb_payloads++;
5467 "The flex payload table is full. Can not set flex payload for type(%u).",
5472 rte_memcpy(&flex_conf->flex_set[idx],
5474 sizeof(struct rte_eth_flex_payload_cfg));
5479 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
5481 #ifdef RTE_NET_IXGBE
5485 diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
5487 diag = rte_pmd_ixgbe_set_vf_tx(port_id, vf, on);
5492 "rte_pmd_ixgbe_set_vf_%s for port_id=%d failed diag=%d\n",
5493 is_rx ? "rx" : "tx", port_id, diag);
5496 fprintf(stderr, "VF %s setting not supported for port %d\n",
5497 is_rx ? "Rx" : "Tx", port_id);
5503 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
5506 struct rte_eth_link link;
5509 if (port_id_is_invalid(port_id, ENABLED_WARN))
5511 ret = eth_link_get_nowait_print_err(port_id, &link);
5514 if (link.link_speed != RTE_ETH_SPEED_NUM_UNKNOWN &&
5515 rate > link.link_speed) {
5517 "Invalid rate value:%u bigger than link speed: %u\n",
5518 rate, link.link_speed);
5521 diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
5525 "rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
5531 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
5533 int diag = -ENOTSUP;
5537 RTE_SET_USED(q_msk);
5539 #ifdef RTE_NET_IXGBE
5540 if (diag == -ENOTSUP)
5541 diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate,
5545 if (diag == -ENOTSUP)
5546 diag = rte_pmd_bnxt_set_vf_rate_limit(port_id, vf, rate, q_msk);
5552 "%s for port_id=%d failed diag=%d\n",
5553 __func__, port_id, diag);
5558 * Functions to manage the set of filtered Multicast MAC addresses.
5560 * A pool of filtered multicast MAC addresses is associated with each port.
5561 * The pool is allocated in chunks of MCAST_POOL_INC multicast addresses.
5562 * The address of the pool and the number of valid multicast MAC addresses
5563 * recorded in the pool are stored in the fields "mc_addr_pool" and
5564 * "mc_addr_nb" of the "rte_port" data structure.
5566 * The function "rte_eth_dev_set_mc_addr_list" of the PMDs API imposes
5567 * to be supplied a contiguous array of multicast MAC addresses.
5568 * To comply with this constraint, the set of multicast addresses recorded
5569 * into the pool are systematically compacted at the beginning of the pool.
5570 * Hence, when a multicast address is removed from the pool, all following
5571 * addresses, if any, are copied back to keep the set contiguous.
5573 #define MCAST_POOL_INC 32
5576 mcast_addr_pool_extend(struct rte_port *port)
5578 struct rte_ether_addr *mc_pool;
5579 size_t mc_pool_size;
5582 * If a free entry is available at the end of the pool, just
5583 * increment the number of recorded multicast addresses.
5585 if ((port->mc_addr_nb % MCAST_POOL_INC) != 0) {
5591 * [re]allocate a pool with MCAST_POOL_INC more entries.
5592 * The previous test guarantees that port->mc_addr_nb is a multiple
5593 * of MCAST_POOL_INC.
5595 mc_pool_size = sizeof(struct rte_ether_addr) * (port->mc_addr_nb +
5597 mc_pool = (struct rte_ether_addr *) realloc(port->mc_addr_pool,
5599 if (mc_pool == NULL) {
5601 "allocation of pool of %u multicast addresses failed\n",
5602 port->mc_addr_nb + MCAST_POOL_INC);
5606 port->mc_addr_pool = mc_pool;
5613 mcast_addr_pool_append(struct rte_port *port, struct rte_ether_addr *mc_addr)
5615 if (mcast_addr_pool_extend(port) != 0)
5617 rte_ether_addr_copy(mc_addr, &port->mc_addr_pool[port->mc_addr_nb - 1]);
5621 mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx)
5624 if (addr_idx == port->mc_addr_nb) {
5625 /* No need to recompact the set of multicast addresses. */
5626 if (port->mc_addr_nb == 0) {
5627 /* free the pool of multicast addresses. */
5628 free(port->mc_addr_pool);
5629 port->mc_addr_pool = NULL;
5633 memmove(&port->mc_addr_pool[addr_idx],
5634 &port->mc_addr_pool[addr_idx + 1],
5635 sizeof(struct rte_ether_addr) * (port->mc_addr_nb - addr_idx));
5639 eth_port_multicast_addr_list_set(portid_t port_id)
5641 struct rte_port *port;
5644 port = &ports[port_id];
5645 diag = rte_eth_dev_set_mc_addr_list(port_id, port->mc_addr_pool,
5649 "rte_eth_dev_set_mc_addr_list(port=%d, nb=%u) failed. diag=%d\n",
5650 port_id, port->mc_addr_nb, diag);
5656 mcast_addr_add(portid_t port_id, struct rte_ether_addr *mc_addr)
5658 struct rte_port *port;
5661 if (port_id_is_invalid(port_id, ENABLED_WARN))
5664 port = &ports[port_id];
5667 * Check that the added multicast MAC address is not already recorded
5668 * in the pool of multicast addresses.
5670 for (i = 0; i < port->mc_addr_nb; i++) {
5671 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i])) {
5673 "multicast address already filtered by port\n");
5678 mcast_addr_pool_append(port, mc_addr);
5679 if (eth_port_multicast_addr_list_set(port_id) < 0)
5680 /* Rollback on failure, remove the address from the pool */
5681 mcast_addr_pool_remove(port, i);
5685 mcast_addr_remove(portid_t port_id, struct rte_ether_addr *mc_addr)
5687 struct rte_port *port;
5690 if (port_id_is_invalid(port_id, ENABLED_WARN))
5693 port = &ports[port_id];
5696 * Search the pool of multicast MAC addresses for the removed address.
5698 for (i = 0; i < port->mc_addr_nb; i++) {
5699 if (rte_is_same_ether_addr(mc_addr, &port->mc_addr_pool[i]))
5702 if (i == port->mc_addr_nb) {
5703 fprintf(stderr, "multicast address not filtered by port %d\n",
5708 mcast_addr_pool_remove(port, i);
5709 if (eth_port_multicast_addr_list_set(port_id) < 0)
5710 /* Rollback on failure, add the address back into the pool */
5711 mcast_addr_pool_append(port, mc_addr);
5715 port_dcb_info_display(portid_t port_id)
5717 struct rte_eth_dcb_info dcb_info;
5720 static const char *border = "================";
5722 if (port_id_is_invalid(port_id, ENABLED_WARN))
5725 ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info);
5727 fprintf(stderr, "\n Failed to get dcb infos on port %-2d\n",
5731 printf("\n %s DCB infos for port %-2d %s\n", border, port_id, border);
5732 printf(" TC NUMBER: %d\n", dcb_info.nb_tcs);
5734 for (i = 0; i < dcb_info.nb_tcs; i++)
5736 printf("\n Priority : ");
5737 for (i = 0; i < dcb_info.nb_tcs; i++)
5738 printf("\t%4d", dcb_info.prio_tc[i]);
5739 printf("\n BW percent :");
5740 for (i = 0; i < dcb_info.nb_tcs; i++)
5741 printf("\t%4d%%", dcb_info.tc_bws[i]);
5742 printf("\n RXQ base : ");
5743 for (i = 0; i < dcb_info.nb_tcs; i++)
5744 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].base);
5745 printf("\n RXQ number :");
5746 for (i = 0; i < dcb_info.nb_tcs; i++)
5747 printf("\t%4d", dcb_info.tc_queue.tc_rxq[0][i].nb_queue);
5748 printf("\n TXQ base : ");
5749 for (i = 0; i < dcb_info.nb_tcs; i++)
5750 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].base);
5751 printf("\n TXQ number :");
5752 for (i = 0; i < dcb_info.nb_tcs; i++)
5753 printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
5758 open_file(const char *file_path, uint32_t *size)
5760 int fd = open(file_path, O_RDONLY);
5762 uint8_t *buf = NULL;
5770 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
5774 if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) {
5776 fprintf(stderr, "%s: File operations failed\n", __func__);
5780 pkg_size = st_buf.st_size;
5783 fprintf(stderr, "%s: File operations failed\n", __func__);
5787 buf = (uint8_t *)malloc(pkg_size);
5790 fprintf(stderr, "%s: Failed to malloc memory\n", __func__);
5794 ret = read(fd, buf, pkg_size);
5797 fprintf(stderr, "%s: File read operation failed\n", __func__);
5811 save_file(const char *file_path, uint8_t *buf, uint32_t size)
5813 FILE *fh = fopen(file_path, "wb");
5816 fprintf(stderr, "%s: Failed to open %s\n", __func__, file_path);
5820 if (fwrite(buf, 1, size, fh) != size) {
5822 fprintf(stderr, "%s: File write operation failed\n", __func__);
5832 close_file(uint8_t *buf)
5843 port_queue_region_info_display(portid_t port_id, void *buf)
5847 struct rte_pmd_i40e_queue_regions *info =
5848 (struct rte_pmd_i40e_queue_regions *)buf;
5849 static const char *queue_region_info_stats_border = "-------";
5851 if (!info->queue_region_number)
5852 printf("there is no region has been set before");
5854 printf("\n %s All queue region info for port=%2d %s",
5855 queue_region_info_stats_border, port_id,
5856 queue_region_info_stats_border);
5857 printf("\n queue_region_number: %-14u \n",
5858 info->queue_region_number);
5860 for (i = 0; i < info->queue_region_number; i++) {
5861 printf("\n region_id: %-14u queue_number: %-14u "
5862 "queue_start_index: %-14u \n",
5863 info->region[i].region_id,
5864 info->region[i].queue_num,
5865 info->region[i].queue_start_index);
5867 printf(" user_priority_num is %-14u :",
5868 info->region[i].user_priority_num);
5869 for (j = 0; j < info->region[i].user_priority_num; j++)
5870 printf(" %-14u ", info->region[i].user_priority[j]);
5872 printf("\n flowtype_num is %-14u :",
5873 info->region[i].flowtype_num);
5874 for (j = 0; j < info->region[i].flowtype_num; j++)
5875 printf(" %-14u ", info->region[i].hw_flowtype[j]);
5878 RTE_SET_USED(port_id);
5886 show_macs(portid_t port_id)
5888 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5889 struct rte_eth_dev_info dev_info;
5890 int32_t i, rc, num_macs = 0;
5892 if (eth_dev_info_get_print_err(port_id, &dev_info))
5895 struct rte_ether_addr addr[dev_info.max_mac_addrs];
5896 rc = rte_eth_macaddrs_get(port_id, addr, dev_info.max_mac_addrs);
5900 for (i = 0; i < rc; i++) {
5902 /* skip zero address */
5903 if (rte_is_zero_ether_addr(&addr[i]))
5909 printf("Number of MAC address added: %d\n", num_macs);
5911 for (i = 0; i < rc; i++) {
5913 /* skip zero address */
5914 if (rte_is_zero_ether_addr(&addr[i]))
5917 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, &addr[i]);
5918 printf(" %s\n", buf);
5923 show_mcast_macs(portid_t port_id)
5925 char buf[RTE_ETHER_ADDR_FMT_SIZE];
5926 struct rte_ether_addr *addr;
5927 struct rte_port *port;
5930 port = &ports[port_id];
5932 printf("Number of Multicast MAC address added: %d\n", port->mc_addr_nb);
5934 for (i = 0; i < port->mc_addr_nb; i++) {
5935 addr = &port->mc_addr_pool[i];
5937 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, addr);
5938 printf(" %s\n", buf);