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