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