ethdev: add Rx error counters for missed, badcrc and badlen packets
[dpdk.git] / app / test-pmd / config.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 /*   BSD LICENSE
34  *
35  *   Copyright(c) 2013 6WIND.
36  *
37  *   Redistribution and use in source and binary forms, with or without
38  *   modification, are permitted provided that the following conditions
39  *   are met:
40  *
41  *     * Redistributions of source code must retain the above copyright
42  *       notice, this list of conditions and the following disclaimer.
43  *     * Redistributions in binary form must reproduce the above copyright
44  *       notice, this list of conditions and the following disclaimer in
45  *       the documentation and/or other materials provided with the
46  *       distribution.
47  *     * Neither the name of 6WIND S.A. nor the names of its
48  *       contributors may be used to endorse or promote products derived
49  *       from this software without specific prior written permission.
50  *
51  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  */
63
64 #include <stdarg.h>
65 #include <errno.h>
66 #include <stdio.h>
67 #include <string.h>
68 #include <stdarg.h>
69 #include <stdint.h>
70 #include <inttypes.h>
71
72 #include <sys/queue.h>
73
74 #include <rte_common.h>
75 #include <rte_byteorder.h>
76 #include <rte_debug.h>
77 #include <rte_log.h>
78 #include <rte_memory.h>
79 #include <rte_memcpy.h>
80 #include <rte_memzone.h>
81 #include <rte_launch.h>
82 #include <rte_tailq.h>
83 #include <rte_eal.h>
84 #include <rte_per_lcore.h>
85 #include <rte_lcore.h>
86 #include <rte_atomic.h>
87 #include <rte_branch_prediction.h>
88 #include <rte_ring.h>
89 #include <rte_mempool.h>
90 #include <rte_mbuf.h>
91 #include <rte_interrupts.h>
92 #include <rte_pci.h>
93 #include <rte_ether.h>
94 #include <rte_ethdev.h>
95 #include <rte_string_fns.h>
96
97 #include "testpmd.h"
98
99 static void
100 print_ethaddr(const char *name, struct ether_addr *eth_addr)
101 {
102         printf("%s%02X:%02X:%02X:%02X:%02X:%02X", name,
103                (unsigned int)eth_addr->addr_bytes[0],
104                (unsigned int)eth_addr->addr_bytes[1],
105                (unsigned int)eth_addr->addr_bytes[2],
106                (unsigned int)eth_addr->addr_bytes[3],
107                (unsigned int)eth_addr->addr_bytes[4],
108                (unsigned int)eth_addr->addr_bytes[5]);
109 }
110
111 void
112 nic_stats_display(portid_t port_id)
113 {
114         struct rte_eth_stats stats;
115         struct rte_port *port = &ports[port_id];
116         uint8_t i;
117
118         static const char *nic_stats_border = "########################";
119
120         if (port_id >= nb_ports) {
121                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
122                 return;
123         }
124         rte_eth_stats_get(port_id, &stats);
125         printf("\n  %s NIC statistics for port %-2d %s\n",
126                nic_stats_border, port_id, nic_stats_border);
127
128         if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
129                 printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
130                        "%-"PRIu64"\n",
131                        stats.ipackets, stats.imissed, stats.ibytes);
132                 printf("  RX-badcrc:  %-10"PRIu64" RX-badlen: %-10"PRIu64" RX-errors: "
133                        "%-"PRIu64"\n",
134                        stats.ibadcrc, stats.ibadlen, stats.ierrors);
135                 printf("  RX-nombuf:  %-10"PRIu64"\n",
136                        stats.rx_nombuf);
137                 printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
138                        "%-"PRIu64"\n",
139                        stats.opackets, stats.oerrors, stats.obytes);
140         }
141         else {
142                 printf("  RX-packets:              %10"PRIu64"    RX-errors: %10"PRIu64
143                        "    RX-bytes: %10"PRIu64"\n",
144                        stats.ipackets, stats.ierrors, stats.ibytes);
145                 printf("  RX-badcrc:               %10"PRIu64"    RX-badlen: %10"PRIu64
146                        "  RX-errors:  %10"PRIu64"\n",
147                        stats.ibadcrc, stats.ibadlen, stats.ierrors);
148                 printf("  RX-nombuf:               %10"PRIu64"\n",
149                        stats.rx_nombuf);
150                 printf("  TX-packets:              %10"PRIu64"    TX-errors: %10"PRIu64
151                        "    TX-bytes: %10"PRIu64"\n",
152                        stats.opackets, stats.oerrors, stats.obytes);
153         }
154
155         /* stats fdir */
156         if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
157                 printf("  Fdirmiss:   %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
158                        stats.fdirmiss,
159                        stats.fdirmatch);
160
161         if (port->rx_queue_stats_mapping_enabled) {
162                 printf("\n");
163                 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
164                         printf("  Stats reg %2d RX-packets: %10"PRIu64
165                                "    RX-errors: %10"PRIu64
166                                "    RX-bytes: %10"PRIu64"\n",
167                                i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
168                 }
169         }
170         if (port->tx_queue_stats_mapping_enabled) {
171                 printf("\n");
172                 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
173                         printf("  Stats reg %2d TX-packets: %10"PRIu64
174                                "                             TX-bytes: %10"PRIu64"\n",
175                                i, stats.q_opackets[i], stats.q_obytes[i]);
176                 }
177         }
178
179         /* Display statistics of XON/XOFF pause frames, if any. */
180         if ((stats.tx_pause_xon  | stats.rx_pause_xon |
181              stats.tx_pause_xoff | stats.rx_pause_xoff) > 0) {
182                 printf("  RX-XOFF:    %-10"PRIu64" RX-XON:    %-10"PRIu64"\n",
183                        stats.rx_pause_xoff, stats.rx_pause_xon);
184                 printf("  TX-XOFF:    %-10"PRIu64" TX-XON:    %-10"PRIu64"\n",
185                        stats.tx_pause_xoff, stats.tx_pause_xon);
186         }
187         printf("  %s############################%s\n",
188                nic_stats_border, nic_stats_border);
189 }
190
191 void
192 nic_stats_clear(portid_t port_id)
193 {
194         if (port_id >= nb_ports) {
195                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
196                 return;
197         }
198         rte_eth_stats_reset(port_id);
199         printf("\n  NIC statistics for port %d cleared\n", port_id);
200 }
201
202
203 void
204 nic_stats_mapping_display(portid_t port_id)
205 {
206         struct rte_port *port = &ports[port_id];
207         uint16_t i;
208
209         static const char *nic_stats_mapping_border = "########################";
210
211         if (port_id >= nb_ports) {
212                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
213                 return;
214         }
215
216         if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
217                 printf("Port id %d - either does not support queue statistic mapping or"
218                        " no queue statistic mapping set\n", port_id);
219                 return;
220         }
221
222         printf("\n  %s NIC statistics mapping for port %-2d %s\n",
223                nic_stats_mapping_border, port_id, nic_stats_mapping_border);
224
225         if (port->rx_queue_stats_mapping_enabled) {
226                 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
227                         if (rx_queue_stats_mappings[i].port_id == port_id) {
228                                 printf("  RX-queue %2d mapped to Stats Reg %2d\n",
229                                        rx_queue_stats_mappings[i].queue_id,
230                                        rx_queue_stats_mappings[i].stats_counter_id);
231                         }
232                 }
233                 printf("\n");
234         }
235
236
237         if (port->tx_queue_stats_mapping_enabled) {
238                 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
239                         if (tx_queue_stats_mappings[i].port_id == port_id) {
240                                 printf("  TX-queue %2d mapped to Stats Reg %2d\n",
241                                        tx_queue_stats_mappings[i].queue_id,
242                                        tx_queue_stats_mappings[i].stats_counter_id);
243                         }
244                 }
245         }
246
247         printf("  %s####################################%s\n",
248                nic_stats_mapping_border, nic_stats_mapping_border);
249 }
250
251 void
252 port_infos_display(portid_t port_id)
253 {
254         struct rte_port *port;
255         struct rte_eth_link link;
256         int vlan_offload;
257         struct rte_mempool * mp;
258         static const char *info_border = "*********************";
259
260         if (port_id >= nb_ports) {
261                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
262                 return;
263         }
264         port = &ports[port_id];
265         rte_eth_link_get_nowait(port_id, &link);
266         printf("\n%s Infos for port %-2d %s\n",
267                info_border, port_id, info_border);
268         print_ethaddr("MAC address: ", &port->eth_addr);
269         printf("\nConnect to socket: %u", port->socket_id);
270
271         if (port_numa[port_id] != NUMA_NO_CONFIG) {
272                 mp = mbuf_pool_find(port_numa[port_id]);
273                 if (mp)
274                         printf("\nmemory allocation on the socket: %d",
275                                                         port_numa[port_id]);
276         } else
277                 printf("\nmemory allocation on the socket: %u",port->socket_id);
278
279         printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
280         printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
281         printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
282                ("full-duplex") : ("half-duplex"));
283         printf("Promiscuous mode: %s\n",
284                rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
285         printf("Allmulticast mode: %s\n",
286                rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
287         printf("Maximum number of MAC addresses: %u\n",
288                (unsigned int)(port->dev_info.max_mac_addrs));
289         printf("Maximum number of MAC addresses of hash filtering: %u\n",
290                (unsigned int)(port->dev_info.max_hash_mac_addrs));
291
292         vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
293         if (vlan_offload >= 0){
294                 printf("VLAN offload: \n");
295                 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
296                         printf("  strip on \n");
297                 else
298                         printf("  strip off \n");
299
300                 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
301                         printf("  filter on \n");
302                 else
303                         printf("  filter off \n");
304
305                 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
306                         printf("  qinq(extend) on \n");
307                 else
308                         printf("  qinq(extend) off \n");
309         }
310 }
311
312 static int
313 port_id_is_invalid(portid_t port_id)
314 {
315         if (port_id < nb_ports)
316                 return 0;
317         printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
318         return 1;
319 }
320
321 static int
322 vlan_id_is_invalid(uint16_t vlan_id)
323 {
324         if (vlan_id < 4096)
325                 return 0;
326         printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
327         return 1;
328 }
329
330 static int
331 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
332 {
333         uint64_t pci_len;
334
335         if (reg_off & 0x3) {
336                 printf("Port register offset 0x%X not aligned on a 4-byte "
337                        "boundary\n",
338                        (unsigned)reg_off);
339                 return 1;
340         }
341         pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
342         if (reg_off >= pci_len) {
343                 printf("Port %d: register offset %u (0x%X) out of port PCI "
344                        "resource (length=%"PRIu64")\n",
345                        port_id, (unsigned)reg_off, (unsigned)reg_off,  pci_len);
346                 return 1;
347         }
348         return 0;
349 }
350
351 static int
352 reg_bit_pos_is_invalid(uint8_t bit_pos)
353 {
354         if (bit_pos <= 31)
355                 return 0;
356         printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
357         return 1;
358 }
359
360 #define display_port_and_reg_off(port_id, reg_off) \
361         printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
362
363 static inline void
364 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
365 {
366         display_port_and_reg_off(port_id, (unsigned)reg_off);
367         printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
368 }
369
370 void
371 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
372 {
373         uint32_t reg_v;
374
375
376         if (port_id_is_invalid(port_id))
377                 return;
378         if (port_reg_off_is_invalid(port_id, reg_off))
379                 return;
380         if (reg_bit_pos_is_invalid(bit_x))
381                 return;
382         reg_v = port_id_pci_reg_read(port_id, reg_off);
383         display_port_and_reg_off(port_id, (unsigned)reg_off);
384         printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
385 }
386
387 void
388 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
389                            uint8_t bit1_pos, uint8_t bit2_pos)
390 {
391         uint32_t reg_v;
392         uint8_t  l_bit;
393         uint8_t  h_bit;
394
395         if (port_id_is_invalid(port_id))
396                 return;
397         if (port_reg_off_is_invalid(port_id, reg_off))
398                 return;
399         if (reg_bit_pos_is_invalid(bit1_pos))
400                 return;
401         if (reg_bit_pos_is_invalid(bit2_pos))
402                 return;
403         if (bit1_pos > bit2_pos)
404                 l_bit = bit2_pos, h_bit = bit1_pos;
405         else
406                 l_bit = bit1_pos, h_bit = bit2_pos;
407
408         reg_v = port_id_pci_reg_read(port_id, reg_off);
409         reg_v >>= l_bit;
410         if (h_bit < 31)
411                 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
412         display_port_and_reg_off(port_id, (unsigned)reg_off);
413         printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
414                ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
415 }
416
417 void
418 port_reg_display(portid_t port_id, uint32_t reg_off)
419 {
420         uint32_t reg_v;
421
422         if (port_id_is_invalid(port_id))
423                 return;
424         if (port_reg_off_is_invalid(port_id, reg_off))
425                 return;
426         reg_v = port_id_pci_reg_read(port_id, reg_off);
427         display_port_reg_value(port_id, reg_off, reg_v);
428 }
429
430 void
431 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
432                  uint8_t bit_v)
433 {
434         uint32_t reg_v;
435
436         if (port_id_is_invalid(port_id))
437                 return;
438         if (port_reg_off_is_invalid(port_id, reg_off))
439                 return;
440         if (reg_bit_pos_is_invalid(bit_pos))
441                 return;
442         if (bit_v > 1) {
443                 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
444                 return;
445         }
446         reg_v = port_id_pci_reg_read(port_id, reg_off);
447         if (bit_v == 0)
448                 reg_v &= ~(1 << bit_pos);
449         else
450                 reg_v |= (1 << bit_pos);
451         port_id_pci_reg_write(port_id, reg_off, reg_v);
452         display_port_reg_value(port_id, reg_off, reg_v);
453 }
454
455 void
456 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
457                        uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
458 {
459         uint32_t max_v;
460         uint32_t reg_v;
461         uint8_t  l_bit;
462         uint8_t  h_bit;
463
464         if (port_id_is_invalid(port_id))
465                 return;
466         if (port_reg_off_is_invalid(port_id, reg_off))
467                 return;
468         if (reg_bit_pos_is_invalid(bit1_pos))
469                 return;
470         if (reg_bit_pos_is_invalid(bit2_pos))
471                 return;
472         if (bit1_pos > bit2_pos)
473                 l_bit = bit2_pos, h_bit = bit1_pos;
474         else
475                 l_bit = bit1_pos, h_bit = bit2_pos;
476
477         if ((h_bit - l_bit) < 31)
478                 max_v = (1 << (h_bit - l_bit + 1)) - 1;
479         else
480                 max_v = 0xFFFFFFFF;
481
482         if (value > max_v) {
483                 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
484                                 (unsigned)value, (unsigned)value,
485                                 (unsigned)max_v, (unsigned)max_v);
486                 return;
487         }
488         reg_v = port_id_pci_reg_read(port_id, reg_off);
489         reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
490         reg_v |= (value << l_bit); /* Set changed bits */
491         port_id_pci_reg_write(port_id, reg_off, reg_v);
492         display_port_reg_value(port_id, reg_off, reg_v);
493 }
494
495 void
496 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
497 {
498         if (port_id_is_invalid(port_id))
499                 return;
500         if (port_reg_off_is_invalid(port_id, reg_off))
501                 return;
502         port_id_pci_reg_write(port_id, reg_off, reg_v);
503         display_port_reg_value(port_id, reg_off, reg_v);
504 }
505
506 /*
507  * RX/TX ring descriptors display functions.
508  */
509 static int
510 rx_queue_id_is_invalid(queueid_t rxq_id)
511 {
512         if (rxq_id < nb_rxq)
513                 return 0;
514         printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
515         return 1;
516 }
517
518 static int
519 tx_queue_id_is_invalid(queueid_t txq_id)
520 {
521         if (txq_id < nb_txq)
522                 return 0;
523         printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
524         return 1;
525 }
526
527 static int
528 rx_desc_id_is_invalid(uint16_t rxdesc_id)
529 {
530         if (rxdesc_id < nb_rxd)
531                 return 0;
532         printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
533                rxdesc_id, nb_rxd);
534         return 1;
535 }
536
537 static int
538 tx_desc_id_is_invalid(uint16_t txdesc_id)
539 {
540         if (txdesc_id < nb_txd)
541                 return 0;
542         printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
543                txdesc_id, nb_txd);
544         return 1;
545 }
546
547 static const struct rte_memzone *
548 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
549 {
550         char mz_name[RTE_MEMZONE_NAMESIZE];
551         const struct rte_memzone *mz;
552
553         rte_snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
554                  ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
555         mz = rte_memzone_lookup(mz_name);
556         if (mz == NULL)
557                 printf("%s ring memory zoneof (port %d, queue %d) not"
558                        "found (zone name = %s\n",
559                        ring_name, port_id, q_id, mz_name);
560         return (mz);
561 }
562
563 union igb_ring_dword {
564         uint64_t dword;
565         struct {
566                 uint32_t hi;
567                 uint32_t lo;
568         } words;
569 };
570
571 struct igb_ring_desc {
572         union igb_ring_dword lo_dword;
573         union igb_ring_dword hi_dword;
574 };
575
576 static void
577 ring_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
578 {
579         struct igb_ring_desc *ring;
580         struct igb_ring_desc rd;
581
582         ring = (struct igb_ring_desc *) ring_mz->addr;
583         rd.lo_dword = rte_le_to_cpu_64(ring[desc_id].lo_dword);
584         rd.hi_dword = rte_le_to_cpu_64(ring[desc_id].hi_dword);
585         printf("    0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
586                 (unsigned)rd.lo_dword.words.lo, (unsigned)rd.lo_dword.words.hi,
587                 (unsigned)rd.hi_dword.words.lo, (unsigned)rd.hi_dword.words.hi);
588 }
589
590 void
591 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
592 {
593         const struct rte_memzone *rx_mz;
594
595         if (port_id_is_invalid(port_id))
596                 return;
597         if (rx_queue_id_is_invalid(rxq_id))
598                 return;
599         if (rx_desc_id_is_invalid(rxd_id))
600                 return;
601         rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
602         if (rx_mz == NULL)
603                 return;
604         ring_descriptor_display(rx_mz, rxd_id);
605 }
606
607 void
608 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
609 {
610         const struct rte_memzone *tx_mz;
611
612         if (port_id_is_invalid(port_id))
613                 return;
614         if (tx_queue_id_is_invalid(txq_id))
615                 return;
616         if (tx_desc_id_is_invalid(txd_id))
617                 return;
618         tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
619         if (tx_mz == NULL)
620                 return;
621         ring_descriptor_display(tx_mz, txd_id);
622 }
623
624 void
625 fwd_lcores_config_display(void)
626 {
627         lcoreid_t lc_id;
628
629         printf("List of forwarding lcores:");
630         for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
631                 printf(" %2u", fwd_lcores_cpuids[lc_id]);
632         printf("\n");
633 }
634 void
635 rxtx_config_display(void)
636 {
637         printf("  %s packet forwarding - CRC stripping %s - "
638                "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
639                rx_mode.hw_strip_crc ? "enabled" : "disabled",
640                nb_pkt_per_burst);
641
642         if (cur_fwd_eng == &tx_only_engine)
643                 printf("  packet len=%u - nb packet segments=%d\n",
644                                 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
645
646         printf("  nb forwarding cores=%d - nb forwarding ports=%d\n",
647                nb_fwd_lcores, nb_fwd_ports);
648         printf("  RX queues=%d - RX desc=%d - RX free threshold=%d\n",
649                nb_rxq, nb_rxd, rx_free_thresh);
650         printf("  RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
651                rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh);
652         printf("  TX queues=%d - TX desc=%d - TX free threshold=%d\n",
653                nb_txq, nb_txd, tx_free_thresh);
654         printf("  TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
655                tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);
656         printf("  TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
657                tx_rs_thresh, txq_flags);
658 }
659
660 void
661 port_rss_reta_info(portid_t port_id,struct rte_eth_rss_reta *reta_conf)
662 {
663         uint8_t i,j;
664         int ret;
665
666         if (port_id_is_invalid(port_id))
667                 return;
668
669         ret = rte_eth_dev_rss_reta_query(port_id, reta_conf);
670         if (ret != 0) {
671                 printf("Failed to get RSS RETA info, return code = %d\n", ret);
672                 return;
673         }
674
675         if (reta_conf->mask_lo != 0) {
676                 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
677                         if (reta_conf->mask_lo & (uint64_t)(1ULL << i))
678                                 printf("RSS RETA configuration: hash index=%d,"
679                                         "queue=%d\n",i,reta_conf->reta[i]);
680                 }
681         }
682
683         if (reta_conf->mask_hi != 0) {
684                 for (i = 0; i< ETH_RSS_RETA_NUM_ENTRIES/2; i++) {
685                         if(reta_conf->mask_hi & (uint64_t)(1ULL << i)) {
686                                 j = (uint8_t)(i + ETH_RSS_RETA_NUM_ENTRIES/2);
687                                 printf("RSS RETA configuration: hash index=%d,"
688                                         "queue=%d\n",j,reta_conf->reta[j]);
689                         }
690                 }
691         }
692 }
693
694 /*
695  * Displays the RSS hash functions of a port, and, optionaly, the RSS hash
696  * key of the port.
697  */
698 void
699 port_rss_hash_conf_show(portid_t port_id, int show_rss_key)
700 {
701         struct rte_eth_rss_conf rss_conf;
702         uint8_t rss_key[10 * 4];
703         uint16_t rss_hf;
704         uint8_t i;
705         int diag;
706
707         if (port_id_is_invalid(port_id))
708                 return;
709         /* Get RSS hash key if asked to display it */
710         rss_conf.rss_key = (show_rss_key) ? rss_key : NULL;
711         diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
712         if (diag != 0) {
713                 switch (diag) {
714                 case -ENODEV:
715                         printf("port index %d invalid\n", port_id);
716                         break;
717                 case -ENOTSUP:
718                         printf("operation not supported by device\n");
719                         break;
720                 default:
721                         printf("operation failed - diag=%d\n", diag);
722                         break;
723                 }
724                 return;
725         }
726         rss_hf = rss_conf.rss_hf;
727         if (rss_hf == 0) {
728                 printf("RSS disabled\n");
729                 return;
730         }
731         printf("RSS functions:\n ");
732         if (rss_hf & ETH_RSS_IPV4)
733                 printf("ip4");
734         if (rss_hf & ETH_RSS_IPV4_TCP)
735                 printf(" tcp4");
736         if (rss_hf & ETH_RSS_IPV4_UDP)
737                 printf(" udp4");
738         if (rss_hf & ETH_RSS_IPV6)
739                 printf(" ip6");
740         if (rss_hf & ETH_RSS_IPV6_EX)
741                 printf(" ip6-ex");
742         if (rss_hf & ETH_RSS_IPV6_TCP)
743                 printf(" tcp6");
744         if (rss_hf & ETH_RSS_IPV6_TCP_EX)
745                 printf(" tcp6-ex");
746         if (rss_hf & ETH_RSS_IPV6_UDP)
747                 printf(" udp6");
748         if (rss_hf & ETH_RSS_IPV6_UDP_EX)
749                 printf(" udp6-ex");
750         printf("\n");
751         if (!show_rss_key)
752                 return;
753         printf("RSS key:\n");
754         for (i = 0; i < sizeof(rss_key); i++)
755                 printf("%02X", rss_key[i]);
756         printf("\n");
757 }
758
759 void
760 port_rss_hash_key_update(portid_t port_id, uint8_t *hash_key)
761 {
762         struct rte_eth_rss_conf rss_conf;
763         int diag;
764
765         rss_conf.rss_key = NULL;
766         diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
767         if (diag == 0) {
768                 rss_conf.rss_key = hash_key;
769                 diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf);
770         }
771         if (diag == 0)
772                 return;
773
774         switch (diag) {
775         case -ENODEV:
776                 printf("port index %d invalid\n", port_id);
777                 break;
778         case -ENOTSUP:
779                 printf("operation not supported by device\n");
780                 break;
781         default:
782                 printf("operation failed - diag=%d\n", diag);
783                 break;
784         }
785 }
786
787 /*
788  * Setup forwarding configuration for each logical core.
789  */
790 static void
791 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
792 {
793         streamid_t nb_fs_per_lcore;
794         streamid_t nb_fs;
795         streamid_t sm_id;
796         lcoreid_t  nb_extra;
797         lcoreid_t  nb_fc;
798         lcoreid_t  nb_lc;
799         lcoreid_t  lc_id;
800
801         nb_fs = cfg->nb_fwd_streams;
802         nb_fc = cfg->nb_fwd_lcores;
803         if (nb_fs <= nb_fc) {
804                 nb_fs_per_lcore = 1;
805                 nb_extra = 0;
806         } else {
807                 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
808                 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
809         }
810
811         nb_lc = (lcoreid_t) (nb_fc - nb_extra);
812         sm_id = 0;
813         for (lc_id = 0; lc_id < nb_lc; lc_id++) {
814                 fwd_lcores[lc_id]->stream_idx = sm_id;
815                 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
816                 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
817         }
818
819         /*
820          * Assign extra remaining streams, if any.
821          */
822         nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
823         for (lc_id = 0; lc_id < nb_extra; lc_id++) {
824                 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
825                 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
826                 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
827         }
828 }
829
830 static void
831 simple_fwd_config_setup(void)
832 {
833         portid_t i;
834         portid_t j;
835         portid_t inc = 2;
836
837         if (port_topology == PORT_TOPOLOGY_CHAINED ||
838             port_topology == PORT_TOPOLOGY_LOOP) {
839                 inc = 1;
840         } else if (nb_fwd_ports % 2) {
841                 printf("\nWarning! Cannot handle an odd number of ports "
842                        "with the current port topology. Configuration "
843                        "must be changed to have an even number of ports, "
844                        "or relaunch application with "
845                        "--port-topology=chained\n\n");
846         }
847
848         cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
849         cur_fwd_config.nb_fwd_streams =
850                 (streamid_t) cur_fwd_config.nb_fwd_ports;
851
852         /* reinitialize forwarding streams */
853         init_fwd_streams();
854
855         /*
856          * In the simple forwarding test, the number of forwarding cores
857          * must be lower or equal to the number of forwarding ports.
858          */
859         cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
860         if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
861                 cur_fwd_config.nb_fwd_lcores =
862                         (lcoreid_t) cur_fwd_config.nb_fwd_ports;
863         setup_fwd_config_of_each_lcore(&cur_fwd_config);
864
865         for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
866                 if (port_topology != PORT_TOPOLOGY_LOOP)
867                         j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
868                 else
869                         j = i;
870                 fwd_streams[i]->rx_port   = fwd_ports_ids[i];
871                 fwd_streams[i]->rx_queue  = 0;
872                 fwd_streams[i]->tx_port   = fwd_ports_ids[j];
873                 fwd_streams[i]->tx_queue  = 0;
874                 fwd_streams[i]->peer_addr = j;
875
876                 if (port_topology == PORT_TOPOLOGY_PAIRED) {
877                         fwd_streams[j]->rx_port   = fwd_ports_ids[j];
878                         fwd_streams[j]->rx_queue  = 0;
879                         fwd_streams[j]->tx_port   = fwd_ports_ids[i];
880                         fwd_streams[j]->tx_queue  = 0;
881                         fwd_streams[j]->peer_addr = i;
882                 }
883         }
884 }
885
886 /**
887  * For the RSS forwarding test, each core is assigned on every port a transmit
888  * queue whose index is the index of the core itself. This approach limits the
889  * maximumm number of processing cores of the RSS test to the maximum number of
890  * TX queues supported by the devices.
891  *
892  * Each core is assigned a single stream, each stream being composed of
893  * a RX queue to poll on a RX port for input messages, associated with
894  * a TX queue of a TX port where to send forwarded packets.
895  * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
896  * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
897  * following rules:
898  *    - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
899  *    - TxQl = RxQj
900  */
901 static void
902 rss_fwd_config_setup(void)
903 {
904         portid_t   rxp;
905         portid_t   txp;
906         queueid_t  rxq;
907         queueid_t  nb_q;
908         lcoreid_t  lc_id;
909
910         nb_q = nb_rxq;
911         if (nb_q > nb_txq)
912                 nb_q = nb_txq;
913         cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
914         cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
915         cur_fwd_config.nb_fwd_streams =
916                 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
917         if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
918                 cur_fwd_config.nb_fwd_streams =
919                         (streamid_t)cur_fwd_config.nb_fwd_lcores;
920         else
921                 cur_fwd_config.nb_fwd_lcores =
922                         (lcoreid_t)cur_fwd_config.nb_fwd_streams;
923
924         /* reinitialize forwarding streams */
925         init_fwd_streams();
926
927         setup_fwd_config_of_each_lcore(&cur_fwd_config);
928         rxp = 0; rxq = 0;
929         for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
930                 struct fwd_stream *fs;
931
932                 fs = fwd_streams[lc_id];
933
934                 if ((rxp & 0x1) == 0)
935                         txp = (portid_t) (rxp + 1);
936                 else
937                         txp = (portid_t) (rxp - 1);
938                 /*
939                  * if we are in loopback, simply send stuff out through the
940                  * ingress port
941                  */
942                 if (port_topology == PORT_TOPOLOGY_LOOP)
943                         txp = rxp;
944
945                 fs->rx_port = fwd_ports_ids[rxp];
946                 fs->rx_queue = rxq;
947                 fs->tx_port = fwd_ports_ids[txp];
948                 fs->tx_queue = rxq;
949                 fs->peer_addr = fs->tx_port;
950                 rxq = (queueid_t) (rxq + 1);
951                 if (rxq < nb_q)
952                         continue;
953                 /*
954                  * rxq == nb_q
955                  * Restart from RX queue 0 on next RX port
956                  */
957                 rxq = 0;
958                 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
959                         rxp = (portid_t)
960                                 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
961                 else
962                         rxp = (portid_t) (rxp + 1);
963         }
964 }
965
966 /*
967  * In DCB and VT on,the mapping of 128 receive queues to 128 transmit queues.
968  */
969 static void
970 dcb_rxq_2_txq_mapping(queueid_t rxq, queueid_t *txq)
971 {
972         if(dcb_q_mapping == DCB_4_TCS_Q_MAPPING) {
973
974                 if (rxq < 32)
975                         /* tc0: 0-31 */
976                         *txq = rxq;
977                 else if (rxq < 64) {
978                         /* tc1: 64-95 */
979                         *txq =  (uint16_t)(rxq + 32);
980                 }
981                 else {
982                         /* tc2: 96-111;tc3:112-127 */
983                         *txq =  (uint16_t)(rxq/2 + 64);
984                 }
985         }
986         else {
987                 if (rxq < 16)
988                         /* tc0 mapping*/
989                         *txq = rxq;
990                 else if (rxq < 32) {
991                         /* tc1 mapping*/
992                          *txq = (uint16_t)(rxq + 16);
993                 }
994                 else if (rxq < 64) {
995                         /*tc2,tc3 mapping */
996                         *txq =  (uint16_t)(rxq + 32);
997                 }
998                 else {
999                         /* tc4,tc5,tc6 and tc7 mapping */
1000                         *txq =  (uint16_t)(rxq/2 + 64);
1001                 }
1002         }
1003 }
1004
1005 /**
1006  * For the DCB forwarding test, each core is assigned on every port multi-transmit
1007  * queue.
1008  *
1009  * Each core is assigned a multi-stream, each stream being composed of
1010  * a RX queue to poll on a RX port for input messages, associated with
1011  * a TX queue of a TX port where to send forwarded packets.
1012  * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
1013  * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
1014  * following rules:
1015  * In VT mode,
1016  *    - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1017  *    - TxQl = RxQj
1018  * In non-VT mode,
1019  *    - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
1020  *    There is a mapping of RxQj to TxQl to be required,and the mapping was implemented
1021  *    in dcb_rxq_2_txq_mapping function.
1022  */
1023 static void
1024 dcb_fwd_config_setup(void)
1025 {
1026         portid_t   rxp;
1027         portid_t   txp;
1028         queueid_t  rxq;
1029         queueid_t  nb_q;
1030         lcoreid_t  lc_id;
1031         uint16_t sm_id;
1032
1033         nb_q = nb_rxq;
1034
1035         cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1036         cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1037         cur_fwd_config.nb_fwd_streams =
1038                 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
1039
1040         /* reinitialize forwarding streams */
1041         init_fwd_streams();
1042
1043         setup_fwd_config_of_each_lcore(&cur_fwd_config);
1044         rxp = 0; rxq = 0;
1045         for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1046                 /* a fwd core can run multi-streams */
1047                 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++)
1048                 {
1049                         struct fwd_stream *fs;
1050                         fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1051                         if ((rxp & 0x1) == 0)
1052                                 txp = (portid_t) (rxp + 1);
1053                         else
1054                                 txp = (portid_t) (rxp - 1);
1055                         fs->rx_port = fwd_ports_ids[rxp];
1056                         fs->rx_queue = rxq;
1057                         fs->tx_port = fwd_ports_ids[txp];
1058                         if (dcb_q_mapping == DCB_VT_Q_MAPPING)
1059                                 fs->tx_queue = rxq;
1060                         else
1061                                 dcb_rxq_2_txq_mapping(rxq, &fs->tx_queue);
1062                         fs->peer_addr = fs->tx_port;
1063                         rxq = (queueid_t) (rxq + 1);
1064                         if (rxq < nb_q)
1065                                 continue;
1066                         rxq = 0;
1067                         if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
1068                                 rxp = (portid_t)
1069                                         (rxp + ((nb_ports >> 1) / nb_fwd_ports));
1070                         else
1071                                 rxp = (portid_t) (rxp + 1);
1072                 }
1073         }
1074 }
1075
1076 static void
1077 icmp_echo_config_setup(void)
1078 {
1079         portid_t  rxp;
1080         queueid_t rxq;
1081         lcoreid_t lc_id;
1082         uint16_t  sm_id;
1083
1084         if ((nb_txq * nb_fwd_ports) < nb_fwd_lcores)
1085                 cur_fwd_config.nb_fwd_lcores = (lcoreid_t)
1086                         (nb_txq * nb_fwd_ports);
1087         else
1088                 cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
1089         cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
1090         cur_fwd_config.nb_fwd_streams =
1091                 (streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
1092         if (cur_fwd_config.nb_fwd_streams < cur_fwd_config.nb_fwd_lcores)
1093                 cur_fwd_config.nb_fwd_lcores =
1094                         (lcoreid_t)cur_fwd_config.nb_fwd_streams;
1095         if (verbose_level > 0) {
1096                 printf("%s fwd_cores=%d fwd_ports=%d fwd_streams=%d\n",
1097                        __FUNCTION__,
1098                        cur_fwd_config.nb_fwd_lcores,
1099                        cur_fwd_config.nb_fwd_ports,
1100                        cur_fwd_config.nb_fwd_streams);
1101         }
1102
1103         /* reinitialize forwarding streams */
1104         init_fwd_streams();
1105         setup_fwd_config_of_each_lcore(&cur_fwd_config);
1106         rxp = 0; rxq = 0;
1107         for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
1108                 if (verbose_level > 0)
1109                         printf("  core=%d: \n", lc_id);
1110                 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1111                         struct fwd_stream *fs;
1112                         fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1113                         fs->rx_port = fwd_ports_ids[rxp];
1114                         fs->rx_queue = rxq;
1115                         fs->tx_port = fs->rx_port;
1116                         fs->tx_queue = lc_id;
1117                         fs->peer_addr = fs->tx_port;
1118                         if (verbose_level > 0)
1119                                 printf("  stream=%d port=%d rxq=%d txq=%d\n",
1120                                        sm_id, fs->rx_port, fs->rx_queue,
1121                                        fs->tx_queue);
1122                         rxq = (queueid_t) (rxq + 1);
1123                         if (rxq == nb_rxq) {
1124                                 rxq = 0;
1125                                 rxp = (portid_t) (rxp + 1);
1126                         }
1127                 }
1128         }
1129 }
1130
1131 void
1132 fwd_config_setup(void)
1133 {
1134         cur_fwd_config.fwd_eng = cur_fwd_eng;
1135         if (strcmp(cur_fwd_eng->fwd_mode_name, "icmpecho") == 0) {
1136                 icmp_echo_config_setup();
1137                 return;
1138         }
1139         if ((nb_rxq > 1) && (nb_txq > 1)){
1140                 if (dcb_config)
1141                         dcb_fwd_config_setup();
1142                 else
1143                         rss_fwd_config_setup();
1144         }
1145         else
1146                 simple_fwd_config_setup();
1147 }
1148
1149 static void
1150 pkt_fwd_config_display(struct fwd_config *cfg)
1151 {
1152         struct fwd_stream *fs;
1153         lcoreid_t  lc_id;
1154         streamid_t sm_id;
1155
1156         printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
1157                 "NUMA support %s, MP over anonymous pages %s\n",
1158                 cfg->fwd_eng->fwd_mode_name,
1159                 cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
1160                 numa_support == 1 ? "enabled" : "disabled",
1161                 mp_anon != 0 ? "enabled" : "disabled");
1162
1163         if (strcmp(cfg->fwd_eng->fwd_mode_name, "mac_retry") == 0)
1164                 printf("TX retry num: %u, delay between TX retries: %uus\n",
1165                         burst_tx_retry_num, burst_tx_delay_time);
1166         for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
1167                 printf("Logical Core %u (socket %u) forwards packets on "
1168                        "%d streams:",
1169                        fwd_lcores_cpuids[lc_id],
1170                        rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
1171                        fwd_lcores[lc_id]->stream_nb);
1172                 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
1173                         fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
1174                         printf("\n  RX P=%d/Q=%d (socket %u) -> TX "
1175                                "P=%d/Q=%d (socket %u) ",
1176                                fs->rx_port, fs->rx_queue,
1177                                ports[fs->rx_port].socket_id,
1178                                fs->tx_port, fs->tx_queue,
1179                                ports[fs->tx_port].socket_id);
1180                         print_ethaddr("peer=",
1181                                       &peer_eth_addrs[fs->peer_addr]);
1182                 }
1183                 printf("\n");
1184         }
1185         printf("\n");
1186 }
1187
1188
1189 void
1190 fwd_config_display(void)
1191 {
1192         if((dcb_config) && (nb_fwd_lcores == 1)) {
1193                 printf("In DCB mode,the nb forwarding cores should be larger than 1\n");
1194                 return;
1195         }
1196         fwd_config_setup();
1197         pkt_fwd_config_display(&cur_fwd_config);
1198 }
1199
1200 int
1201 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
1202 {
1203         unsigned int i;
1204         unsigned int lcore_cpuid;
1205         int record_now;
1206
1207         record_now = 0;
1208  again:
1209         for (i = 0; i < nb_lc; i++) {
1210                 lcore_cpuid = lcorelist[i];
1211                 if (! rte_lcore_is_enabled(lcore_cpuid)) {
1212                         printf("lcore %u not enabled\n", lcore_cpuid);
1213                         return -1;
1214                 }
1215                 if (lcore_cpuid == rte_get_master_lcore()) {
1216                         printf("lcore %u cannot be masked on for running "
1217                                "packet forwarding, which is the master lcore "
1218                                "and reserved for command line parsing only\n",
1219                                lcore_cpuid);
1220                         return -1;
1221                 }
1222                 if (record_now)
1223                         fwd_lcores_cpuids[i] = lcore_cpuid;
1224         }
1225         if (record_now == 0) {
1226                 record_now = 1;
1227                 goto again;
1228         }
1229         nb_cfg_lcores = (lcoreid_t) nb_lc;
1230         if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
1231                 printf("previous number of forwarding cores %u - changed to "
1232                        "number of configured cores %u\n",
1233                        (unsigned int) nb_fwd_lcores, nb_lc);
1234                 nb_fwd_lcores = (lcoreid_t) nb_lc;
1235         }
1236
1237         return 0;
1238 }
1239
1240 int
1241 set_fwd_lcores_mask(uint64_t lcoremask)
1242 {
1243         unsigned int lcorelist[64];
1244         unsigned int nb_lc;
1245         unsigned int i;
1246
1247         if (lcoremask == 0) {
1248                 printf("Invalid NULL mask of cores\n");
1249                 return -1;
1250         }
1251         nb_lc = 0;
1252         for (i = 0; i < 64; i++) {
1253                 if (! ((uint64_t)(1ULL << i) & lcoremask))
1254                         continue;
1255                 lcorelist[nb_lc++] = i;
1256         }
1257         return set_fwd_lcores_list(lcorelist, nb_lc);
1258 }
1259
1260 void
1261 set_fwd_lcores_number(uint16_t nb_lc)
1262 {
1263         if (nb_lc > nb_cfg_lcores) {
1264                 printf("nb fwd cores %u > %u (max. number of configured "
1265                        "lcores) - ignored\n",
1266                        (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1267                 return;
1268         }
1269         nb_fwd_lcores = (lcoreid_t) nb_lc;
1270         printf("Number of forwarding cores set to %u\n",
1271                (unsigned int) nb_fwd_lcores);
1272 }
1273
1274 void
1275 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1276 {
1277         unsigned int i;
1278         portid_t port_id;
1279         int record_now;
1280
1281         record_now = 0;
1282  again:
1283         for (i = 0; i < nb_pt; i++) {
1284                 port_id = (portid_t) portlist[i];
1285                 if (port_id >= nb_ports) {
1286                         printf("Invalid port id %u >= %u\n",
1287                                (unsigned int) port_id,
1288                                (unsigned int) nb_ports);
1289                         return;
1290                 }
1291                 if (record_now)
1292                         fwd_ports_ids[i] = port_id;
1293         }
1294         if (record_now == 0) {
1295                 record_now = 1;
1296                 goto again;
1297         }
1298         nb_cfg_ports = (portid_t) nb_pt;
1299         if (nb_fwd_ports != (portid_t) nb_pt) {
1300                 printf("previous number of forwarding ports %u - changed to "
1301                        "number of configured ports %u\n",
1302                        (unsigned int) nb_fwd_ports, nb_pt);
1303                 nb_fwd_ports = (portid_t) nb_pt;
1304         }
1305 }
1306
1307 void
1308 set_fwd_ports_mask(uint64_t portmask)
1309 {
1310         unsigned int portlist[64];
1311         unsigned int nb_pt;
1312         unsigned int i;
1313
1314         if (portmask == 0) {
1315                 printf("Invalid NULL mask of ports\n");
1316                 return;
1317         }
1318         nb_pt = 0;
1319         for (i = 0; i < 64; i++) {
1320                 if (! ((uint64_t)(1ULL << i) & portmask))
1321                         continue;
1322                 portlist[nb_pt++] = i;
1323         }
1324         set_fwd_ports_list(portlist, nb_pt);
1325 }
1326
1327 void
1328 set_fwd_ports_number(uint16_t nb_pt)
1329 {
1330         if (nb_pt > nb_cfg_ports) {
1331                 printf("nb fwd ports %u > %u (number of configured "
1332                        "ports) - ignored\n",
1333                        (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1334                 return;
1335         }
1336         nb_fwd_ports = (portid_t) nb_pt;
1337         printf("Number of forwarding ports set to %u\n",
1338                (unsigned int) nb_fwd_ports);
1339 }
1340
1341 void
1342 set_nb_pkt_per_burst(uint16_t nb)
1343 {
1344         if (nb > MAX_PKT_BURST) {
1345                 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1346                        " ignored\n",
1347                        (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1348                 return;
1349         }
1350         nb_pkt_per_burst = nb;
1351         printf("Number of packets per burst set to %u\n",
1352                (unsigned int) nb_pkt_per_burst);
1353 }
1354
1355 void
1356 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1357 {
1358         uint16_t tx_pkt_len;
1359         unsigned i;
1360
1361         if (nb_segs >= (unsigned) nb_txd) {
1362                 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1363                        nb_segs, (unsigned int) nb_txd);
1364                 return;
1365         }
1366
1367         /*
1368          * Check that each segment length is greater or equal than
1369          * the mbuf data sise.
1370          * Check also that the total packet length is greater or equal than the
1371          * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1372          */
1373         tx_pkt_len = 0;
1374         for (i = 0; i < nb_segs; i++) {
1375                 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1376                         printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1377                                i, seg_lengths[i], (unsigned) mbuf_data_size);
1378                         return;
1379                 }
1380                 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1381         }
1382         if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1383                 printf("total packet length=%u < %d - give up\n",
1384                                 (unsigned) tx_pkt_len,
1385                                 (int)(sizeof(struct ether_hdr) + 20 + 8));
1386                 return;
1387         }
1388
1389         for (i = 0; i < nb_segs; i++)
1390                 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1391
1392         tx_pkt_length  = tx_pkt_len;
1393         tx_pkt_nb_segs = (uint8_t) nb_segs;
1394 }
1395
1396 char*
1397 list_pkt_forwarding_modes(void)
1398 {
1399         static char fwd_modes[128] = "";
1400         const char *separator = "|";
1401         struct fwd_engine *fwd_eng;
1402         unsigned i = 0;
1403
1404         if (strlen (fwd_modes) == 0) {
1405                 while ((fwd_eng = fwd_engines[i++]) != NULL) {
1406                         strcat(fwd_modes, fwd_eng->fwd_mode_name);
1407                         strcat(fwd_modes, separator);
1408                 }
1409                 fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
1410         }
1411
1412         return fwd_modes;
1413 }
1414
1415 void
1416 set_pkt_forwarding_mode(const char *fwd_mode_name)
1417 {
1418         struct fwd_engine *fwd_eng;
1419         unsigned i;
1420
1421         i = 0;
1422         while ((fwd_eng = fwd_engines[i]) != NULL) {
1423                 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1424                         printf("Set %s packet forwarding mode\n",
1425                                fwd_mode_name);
1426                         cur_fwd_eng = fwd_eng;
1427                         return;
1428                 }
1429                 i++;
1430         }
1431         printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1432 }
1433
1434 void
1435 set_verbose_level(uint16_t vb_level)
1436 {
1437         printf("Change verbose level from %u to %u\n",
1438                (unsigned int) verbose_level, (unsigned int) vb_level);
1439         verbose_level = vb_level;
1440 }
1441
1442 void
1443 vlan_extend_set(portid_t port_id, int on)
1444 {
1445         int diag;
1446         int vlan_offload;
1447
1448         if (port_id_is_invalid(port_id))
1449                 return;
1450
1451         vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1452
1453         if (on)
1454                 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1455         else
1456                 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1457
1458         diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1459         if (diag < 0)
1460                 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1461                "diag=%d\n", port_id, on, diag);
1462 }
1463
1464 void
1465 rx_vlan_strip_set(portid_t port_id, int on)
1466 {
1467         int diag;
1468         int vlan_offload;
1469
1470         if (port_id_is_invalid(port_id))
1471                 return;
1472
1473         vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1474
1475         if (on)
1476                 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1477         else
1478                 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1479
1480         diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1481         if (diag < 0)
1482                 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1483                "diag=%d\n", port_id, on, diag);
1484 }
1485
1486 void
1487 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1488 {
1489         int diag;
1490
1491         if (port_id_is_invalid(port_id))
1492                 return;
1493
1494         diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1495         if (diag < 0)
1496                 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1497                "diag=%d\n", port_id, queue_id, on, diag);
1498 }
1499
1500 void
1501 rx_vlan_filter_set(portid_t port_id, int on)
1502 {
1503         int diag;
1504         int vlan_offload;
1505
1506         if (port_id_is_invalid(port_id))
1507                 return;
1508
1509         vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1510
1511         if (on)
1512                 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1513         else
1514                 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1515
1516         diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1517         if (diag < 0)
1518                 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1519                "diag=%d\n", port_id, on, diag);
1520 }
1521
1522 void
1523 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1524 {
1525         int diag;
1526
1527         if (port_id_is_invalid(port_id))
1528                 return;
1529         if (vlan_id_is_invalid(vlan_id))
1530                 return;
1531         diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1532         if (diag == 0)
1533                 return;
1534         printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1535                "diag=%d\n",
1536                port_id, vlan_id, on, diag);
1537 }
1538
1539 void
1540 rx_vlan_all_filter_set(portid_t port_id, int on)
1541 {
1542         uint16_t vlan_id;
1543
1544         if (port_id_is_invalid(port_id))
1545                 return;
1546         for (vlan_id = 0; vlan_id < 4096; vlan_id++)
1547                 rx_vft_set(port_id, vlan_id, on);
1548 }
1549
1550 void
1551 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1552 {
1553         int diag;
1554         if (port_id_is_invalid(port_id))
1555                 return;
1556
1557         diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1558         if (diag == 0)
1559                 return;
1560
1561         printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1562                "diag=%d\n",
1563                port_id, tp_id, diag);
1564 }
1565
1566 void
1567 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1568 {
1569         if (port_id_is_invalid(port_id))
1570                 return;
1571         if (vlan_id_is_invalid(vlan_id))
1572                 return;
1573         ports[port_id].tx_ol_flags |= PKT_TX_VLAN_PKT;
1574         ports[port_id].tx_vlan_id = vlan_id;
1575 }
1576
1577 void
1578 tx_vlan_reset(portid_t port_id)
1579 {
1580         if (port_id_is_invalid(port_id))
1581                 return;
1582         ports[port_id].tx_ol_flags &= ~PKT_TX_VLAN_PKT;
1583 }
1584
1585 void
1586 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1587 {
1588         uint16_t i;
1589         uint8_t existing_mapping_found = 0;
1590
1591         if (port_id_is_invalid(port_id))
1592                 return;
1593
1594         if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1595                 return;
1596
1597         if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1598                 printf("map_value not in required range 0..%d\n",
1599                                 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1600                 return;
1601         }
1602
1603         if (!is_rx) { /*then tx*/
1604                 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1605                         if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1606                             (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1607                                 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1608                                 existing_mapping_found = 1;
1609                                 break;
1610                         }
1611                 }
1612                 if (!existing_mapping_found) { /* A new additional mapping... */
1613                         tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1614                         tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1615                         tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1616                         nb_tx_queue_stats_mappings++;
1617                 }
1618         }
1619         else { /*rx*/
1620                 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1621                         if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1622                             (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1623                                 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1624                                 existing_mapping_found = 1;
1625                                 break;
1626                         }
1627                 }
1628                 if (!existing_mapping_found) { /* A new additional mapping... */
1629                         rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1630                         rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1631                         rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1632                         nb_rx_queue_stats_mappings++;
1633                 }
1634         }
1635 }
1636
1637 void
1638 tx_cksum_set(portid_t port_id, uint8_t cksum_mask)
1639 {
1640         uint16_t tx_ol_flags;
1641         if (port_id_is_invalid(port_id))
1642                 return;
1643         /* Clear last 4 bits and then set L3/4 checksum mask again */
1644         tx_ol_flags = (uint16_t) (ports[port_id].tx_ol_flags & 0xFFF0);
1645         ports[port_id].tx_ol_flags = (uint16_t) ((cksum_mask & 0xf) | tx_ol_flags);
1646 }
1647
1648 void
1649 fdir_add_signature_filter(portid_t port_id, uint8_t queue_id,
1650                           struct rte_fdir_filter *fdir_filter)
1651 {
1652         int diag;
1653
1654         if (port_id_is_invalid(port_id))
1655                 return;
1656
1657         diag = rte_eth_dev_fdir_add_signature_filter(port_id, fdir_filter,
1658                                                      queue_id);
1659         if (diag == 0)
1660                 return;
1661
1662         printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1663                "diag=%d\n", port_id, diag);
1664 }
1665
1666 void
1667 fdir_update_signature_filter(portid_t port_id, uint8_t queue_id,
1668                              struct rte_fdir_filter *fdir_filter)
1669 {
1670         int diag;
1671
1672         if (port_id_is_invalid(port_id))
1673                 return;
1674
1675         diag = rte_eth_dev_fdir_update_signature_filter(port_id, fdir_filter,
1676                                                         queue_id);
1677         if (diag == 0)
1678                 return;
1679
1680         printf("rte_eth_dev_fdir_update_signature_filter for port_id=%d failed "
1681                "diag=%d\n", port_id, diag);
1682 }
1683
1684 void
1685 fdir_remove_signature_filter(portid_t port_id,
1686                              struct rte_fdir_filter *fdir_filter)
1687 {
1688         int diag;
1689
1690         if (port_id_is_invalid(port_id))
1691                 return;
1692
1693         diag = rte_eth_dev_fdir_remove_signature_filter(port_id, fdir_filter);
1694         if (diag == 0)
1695                 return;
1696
1697         printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1698                "diag=%d\n", port_id, diag);
1699
1700 }
1701
1702 void
1703 fdir_get_infos(portid_t port_id)
1704 {
1705         struct rte_eth_fdir fdir_infos;
1706
1707         static const char *fdir_stats_border = "########################";
1708
1709         if (port_id_is_invalid(port_id))
1710                 return;
1711
1712         rte_eth_dev_fdir_get_infos(port_id, &fdir_infos);
1713
1714         printf("\n  %s FDIR infos for port %-2d     %s\n",
1715                fdir_stats_border, port_id, fdir_stats_border);
1716
1717         printf("  collision: %-10"PRIu64"  free:     %"PRIu64"\n"
1718                "  maxhash:   %-10"PRIu64"  maxlen:   %"PRIu64"\n"
1719                "  add:       %-10"PRIu64"  remove:   %"PRIu64"\n"
1720                "  f_add:     %-10"PRIu64"  f_remove: %"PRIu64"\n",
1721                (uint64_t)(fdir_infos.collision), (uint64_t)(fdir_infos.free),
1722                (uint64_t)(fdir_infos.maxhash), (uint64_t)(fdir_infos.maxlen),
1723                fdir_infos.add, fdir_infos.remove,
1724                fdir_infos.f_add, fdir_infos.f_remove);
1725         printf("  %s############################%s\n",
1726                fdir_stats_border, fdir_stats_border);
1727 }
1728
1729 void
1730 fdir_add_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1731                         uint8_t drop, struct rte_fdir_filter *fdir_filter)
1732 {
1733         int diag;
1734
1735         if (port_id_is_invalid(port_id))
1736                 return;
1737
1738         diag = rte_eth_dev_fdir_add_perfect_filter(port_id, fdir_filter,
1739                                                    soft_id, queue_id, drop);
1740         if (diag == 0)
1741                 return;
1742
1743         printf("rte_eth_dev_fdir_add_perfect_filter for port_id=%d failed "
1744                "diag=%d\n", port_id, diag);
1745 }
1746
1747 void
1748 fdir_update_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1749                            uint8_t drop, struct rte_fdir_filter *fdir_filter)
1750 {
1751         int diag;
1752
1753         if (port_id_is_invalid(port_id))
1754                 return;
1755
1756         diag = rte_eth_dev_fdir_update_perfect_filter(port_id, fdir_filter,
1757                                                       soft_id, queue_id, drop);
1758         if (diag == 0)
1759                 return;
1760
1761         printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1762                "diag=%d\n", port_id, diag);
1763 }
1764
1765 void
1766 fdir_remove_perfect_filter(portid_t port_id, uint16_t soft_id,
1767                            struct rte_fdir_filter *fdir_filter)
1768 {
1769         int diag;
1770
1771         if (port_id_is_invalid(port_id))
1772                 return;
1773
1774         diag = rte_eth_dev_fdir_remove_perfect_filter(port_id, fdir_filter,
1775                                                       soft_id);
1776         if (diag == 0)
1777                 return;
1778
1779         printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1780                "diag=%d\n", port_id, diag);
1781 }
1782
1783 void
1784 fdir_set_masks(portid_t port_id, struct rte_fdir_masks *fdir_masks)
1785 {
1786         int diag;
1787
1788         if (port_id_is_invalid(port_id))
1789                 return;
1790
1791         diag = rte_eth_dev_fdir_set_masks(port_id, fdir_masks);
1792         if (diag == 0)
1793                 return;
1794
1795         printf("rte_eth_dev_set_masks_filter for port_id=%d failed "
1796                "diag=%d\n", port_id, diag);
1797 }
1798
1799 void
1800 set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
1801 {
1802         int diag;
1803
1804         if (port_id_is_invalid(port_id))
1805                 return;
1806         if (is_rx)
1807                 diag = rte_eth_dev_set_vf_rx(port_id,vf,on);
1808         else
1809                 diag = rte_eth_dev_set_vf_tx(port_id,vf,on);
1810         if (diag == 0)
1811                 return;
1812         if(is_rx)
1813                 printf("rte_eth_dev_set_vf_rx for port_id=%d failed "
1814                         "diag=%d\n", port_id, diag);
1815         else
1816                 printf("rte_eth_dev_set_vf_tx for port_id=%d failed "
1817                         "diag=%d\n", port_id, diag);
1818
1819 }
1820
1821 void
1822 set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
1823 {
1824         int diag;
1825
1826         if (port_id_is_invalid(port_id))
1827                 return;
1828         if (vlan_id_is_invalid(vlan_id))
1829                 return;
1830         diag = rte_eth_dev_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
1831         if (diag == 0)
1832                 return;
1833         printf("rte_eth_dev_set_vf_vlan_filter for port_id=%d failed "
1834                "diag=%d\n", port_id, diag);
1835 }
1836
1837 int
1838 set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
1839 {
1840         int diag;
1841         struct rte_eth_link link;
1842
1843         if (port_id_is_invalid(port_id))
1844                 return 1;
1845         rte_eth_link_get_nowait(port_id, &link);
1846         if (rate > link.link_speed) {
1847                 printf("Invalid rate value:%u bigger than link speed: %u\n",
1848                         rate, link.link_speed);
1849                 return 1;
1850         }
1851         diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
1852         if (diag == 0)
1853                 return diag;
1854         printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
1855                 port_id, diag);
1856         return diag;
1857 }
1858
1859 int
1860 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
1861 {
1862         int diag;
1863         struct rte_eth_link link;
1864
1865         if (q_msk == 0)
1866                 return 0;
1867
1868         if (port_id_is_invalid(port_id))
1869                 return 1;
1870         rte_eth_link_get_nowait(port_id, &link);
1871         if (rate > link.link_speed) {
1872                 printf("Invalid rate value:%u bigger than link speed: %u\n",
1873                         rate, link.link_speed);
1874                 return 1;
1875         }
1876         diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
1877         if (diag == 0)
1878                 return diag;
1879         printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",
1880                 port_id, diag);
1881         return diag;
1882 }
1883
1884 void
1885 get_ethertype_filter(uint8_t port_id, uint16_t index)
1886 {
1887         struct rte_ethertype_filter filter;
1888         int ret = 0;
1889         uint16_t rx_queue;
1890
1891         memset(&filter, 0, sizeof(filter));
1892         ret = rte_eth_dev_get_ethertype_filter(port_id, index,
1893                                 &filter, &rx_queue);
1894         if (ret < 0) {
1895                 if (ret == (-ENOENT))
1896                         printf("filter[%d] is not enabled\n", index);
1897                 else
1898                         printf("get ethertype filter fails(%s)\n", strerror(-ret));
1899                 return;
1900         } else {
1901                 printf("filter[%d]:\n", index);
1902                 printf("    ethertype:  0x%04x\n",
1903                         rte_le_to_cpu_32(filter.ethertype));
1904                 printf("    priority: %s, %d\n",
1905                         filter.priority_en ? "enable" : "disable",
1906                         filter.priority);
1907                 printf("    queue: %d\n", rx_queue);
1908         }
1909 }
1910
1911 void
1912 get_syn_filter(uint8_t port_id)
1913 {
1914         struct rte_syn_filter filter;
1915         int ret = 0;
1916         uint16_t rx_queue;
1917
1918         memset(&filter, 0, sizeof(filter));
1919         ret = rte_eth_dev_get_syn_filter(port_id, &filter, &rx_queue);
1920
1921         if (ret < 0) {
1922                 if (ret == (-ENOENT))
1923                         printf("syn filter is not enabled\n");
1924                 else
1925                         printf("get syn filter fails(%s)\n", strerror(-ret));
1926                 return;
1927         }
1928         printf("syn filter: priority: %s, queue: %d\n",
1929                 filter.hig_pri ? "high" : "low",
1930                 rx_queue);
1931 }
1932 void
1933 get_2tuple_filter(uint8_t port_id, uint16_t index)
1934 {
1935         struct rte_2tuple_filter filter;
1936         int ret = 0;
1937         uint16_t rx_queue;
1938
1939         memset(&filter, 0, sizeof(filter));
1940         ret = rte_eth_dev_get_2tuple_filter(port_id, index,
1941                                 &filter, &rx_queue);
1942         if (ret < 0) {
1943                 if (ret == (-ENOENT))
1944                         printf("filter[%d] is not enabled\n", index);
1945                 else
1946                         printf("get 2tuple filter fails(%s)\n", strerror(-ret));
1947                 return;
1948         } else {
1949                 printf("filter[%d]:\n", index);
1950                 printf("    Destination Port:     0x%04x    mask: %d\n",
1951                         rte_be_to_cpu_16(filter.dst_port),
1952                         filter.dst_port_mask ? 0 : 1);
1953                 printf("    protocol:  0x%02x     mask:%d     tcp_flags: 0x%02x\n",
1954                         filter.protocol, filter.protocol_mask ? 0 : 1,
1955                         filter.tcp_flags);
1956                 printf("    priority: %d    queue: %d\n",
1957                         filter.priority, rx_queue);
1958         }
1959 }
1960
1961 void
1962 get_5tuple_filter(uint8_t port_id, uint16_t index)
1963 {
1964         struct rte_5tuple_filter filter;
1965         int ret = 0;
1966         uint16_t rx_queue;
1967
1968         memset(&filter, 0, sizeof(filter));
1969         ret = rte_eth_dev_get_5tuple_filter(port_id, index,
1970                                 &filter, &rx_queue);
1971         if (ret < 0) {
1972                 if (ret == (-ENOENT))
1973                         printf("filter[%d] is not enabled\n", index);
1974                 else
1975                         printf("get 5tuple filter fails(%s)\n", strerror(-ret));
1976                 return;
1977         } else {
1978                 printf("filter[%d]:\n", index);
1979                 printf("    Destination IP:  0x%08x    mask: %d\n",
1980                         (unsigned)rte_be_to_cpu_32(filter.dst_ip),
1981                         filter.dst_ip_mask ? 0 : 1);
1982                 printf("    Source IP:       0x%08x    mask: %d\n",
1983                         (unsigned)rte_be_to_cpu_32(filter.src_ip),
1984                         filter.src_ip_mask ? 0 : 1);
1985                 printf("    Destination Port:       0x%04x    mask: %d\n",
1986                         rte_be_to_cpu_16(filter.dst_port),
1987                         filter.dst_port_mask ? 0 : 1);
1988                 printf("    Source Port:       0x%04x    mask: %d\n",
1989                         rte_be_to_cpu_16(filter.src_port),
1990                         filter.src_port_mask ? 0 : 1);
1991                 printf("    protocol:           0x%02x    mask: %d\n",
1992                         filter.protocol,
1993                         filter.protocol_mask ? 0 : 1);
1994                 printf("    priority: %d    flags: 0x%02x    queue: %d\n",
1995                         filter.priority, filter.tcp_flags, rx_queue);
1996         }
1997 }
1998 void
1999 get_flex_filter(uint8_t port_id, uint16_t index)
2000
2001 {
2002         struct rte_flex_filter filter;
2003         int ret = 0;
2004         uint16_t rx_queue;
2005         int i, j;
2006
2007         memset(&filter, 0, sizeof(filter));
2008         ret = rte_eth_dev_get_flex_filter(port_id, index,
2009                                 &filter, &rx_queue);
2010         if (ret < 0) {
2011                 if (ret == (-ENOENT))
2012                         printf("filter[%d] is not enabled\n", index);
2013                 else
2014                         printf("get flex filter fails(%s)\n", strerror(-ret));
2015                 return;
2016         } else {
2017                 printf("filter[%d]: ", index);
2018                 printf("\n    length: %d", filter.len);
2019                 printf("\n    dword[]: 0x");
2020                 for (i = 0; i < 32; i++)
2021                         printf("%08x ", (unsigned)rte_be_to_cpu_32(filter.dwords[i]));
2022                 printf("\n    mask[]: 0b");
2023                 for (i = 0; i < 16; i++) {
2024                         for (j = 0; j < 8; j++)
2025                                 printf("%c", (filter.mask[i] & (1 << j)) ? '1' : '0');
2026                 }
2027                 printf("\n    priority: %d    queue: %d\n",
2028                         filter.priority, rx_queue);
2029         }
2030 }