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