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