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