f85540c76208fcd2abe54326a04365d4d834695d
[dpdk.git] / app / test-pmd / config.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2012 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  */
34 /*   BSD LICENSE
35  *
36  *   Copyright(c) 2013 6WIND.
37  *
38  *   Redistribution and use in source and binary forms, with or without
39  *   modification, are permitted provided that the following conditions
40  *   are met:
41  *
42  *     * Redistributions of source code must retain the above copyright
43  *       notice, this list of conditions and the following disclaimer.
44  *     * Redistributions in binary form must reproduce the above copyright
45  *       notice, this list of conditions and the following disclaimer in
46  *       the documentation and/or other materials provided with the
47  *       distribution.
48  *     * Neither the name of 6WIND S.A. nor the names of its
49  *       contributors may be used to endorse or promote products derived
50  *       from this software without specific prior written permission.
51  *
52  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63  */
64
65 #include <stdarg.h>
66 #include <errno.h>
67 #include <stdio.h>
68 #include <string.h>
69 #include <stdarg.h>
70 #include <stdint.h>
71 #include <inttypes.h>
72
73 #include <sys/queue.h>
74
75 #include <rte_common.h>
76 #include <rte_byteorder.h>
77 #include <rte_debug.h>
78 #include <rte_log.h>
79 #include <rte_memory.h>
80 #include <rte_memcpy.h>
81 #include <rte_memzone.h>
82 #include <rte_launch.h>
83 #include <rte_tailq.h>
84 #include <rte_eal.h>
85 #include <rte_per_lcore.h>
86 #include <rte_lcore.h>
87 #include <rte_atomic.h>
88 #include <rte_branch_prediction.h>
89 #include <rte_ring.h>
90 #include <rte_mempool.h>
91 #include <rte_mbuf.h>
92 #include <rte_interrupts.h>
93 #include <rte_pci.h>
94 #include <rte_ether.h>
95 #include <rte_ethdev.h>
96 #include <rte_string_fns.h>
97
98 #include "testpmd.h"
99
100 static void
101 print_ethaddr(const char *name, struct ether_addr *eth_addr)
102 {
103         printf("%s%02X:%02X:%02X:%02X:%02X:%02X", name,
104                eth_addr->addr_bytes[0],
105                eth_addr->addr_bytes[1],
106                eth_addr->addr_bytes[2],
107                eth_addr->addr_bytes[3],
108                eth_addr->addr_bytes[4],
109                eth_addr->addr_bytes[5]);
110 }
111
112 void
113 nic_stats_display(portid_t port_id)
114 {
115         struct rte_eth_stats stats;
116         struct rte_port *port = &ports[port_id];
117         uint8_t i;
118
119         static const char *nic_stats_border = "########################";
120
121         if (port_id >= nb_ports) {
122                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
123                 return;
124         }
125         rte_eth_stats_get(port_id, &stats);
126         printf("\n  %s NIC statistics for port %-2d %s\n",
127                nic_stats_border, port_id, nic_stats_border);
128
129         if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
130                 printf("  RX-packets: %-10"PRIu64" RX-errors: %-10"PRIu64"RX-bytes: "
131                        "%-"PRIu64"\n"
132                        "  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64"TX-bytes: "
133                        "%-"PRIu64"\n",
134                        stats.ipackets, stats.ierrors, stats.ibytes,
135                        stats.opackets, stats.oerrors, stats.obytes);
136         }
137         else {
138                 printf("  RX-packets:              %10"PRIu64"    RX-errors: %10"PRIu64
139                        "    RX-bytes: %10"PRIu64"\n"
140                        "  TX-packets:              %10"PRIu64"    TX-errors: %10"PRIu64
141                        "    TX-bytes: %10"PRIu64"\n",
142                        stats.ipackets, stats.ierrors, stats.ibytes,
143                        stats.opackets, stats.oerrors, stats.obytes);
144         }
145
146         /* stats fdir */
147         if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
148                 printf("  Fdirmiss:   %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
149                        stats.fdirmiss,
150                        stats.fdirmatch);
151
152         if (port->rx_queue_stats_mapping_enabled) {
153                 printf("\n");
154                 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
155                         printf("  Stats reg %2d RX-packets: %10"PRIu64
156                                "    RX-errors: %10"PRIu64
157                                "    RX-bytes: %10"PRIu64"\n",
158                                i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
159                 }
160         }
161         if (port->tx_queue_stats_mapping_enabled) {
162                 printf("\n");
163                 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
164                         printf("  Stats reg %2d TX-packets: %10"PRIu64
165                                "                             TX-bytes: %10"PRIu64"\n",
166                                i, stats.q_opackets[i], stats.q_obytes[i]);
167                 }
168         }
169
170         printf("  %s############################%s\n",
171                nic_stats_border, nic_stats_border);
172 }
173
174 void
175 nic_stats_clear(portid_t port_id)
176 {
177         if (port_id >= nb_ports) {
178                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
179                 return;
180         }
181         rte_eth_stats_reset(port_id);
182         printf("\n  NIC statistics for port %d cleared\n", port_id);
183 }
184
185
186 void
187 nic_stats_mapping_display(portid_t port_id)
188 {
189         struct rte_port *port = &ports[port_id];
190         uint16_t i;
191
192         static const char *nic_stats_mapping_border = "########################";
193
194         if (port_id >= nb_ports) {
195                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
196                 return;
197         }
198
199         if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
200                 printf("Port id %d - either does not support queue statistic mapping or"
201                        " no queue statistic mapping set\n", port_id);
202                 return;
203         }
204
205         printf("\n  %s NIC statistics mapping for port %-2d %s\n",
206                nic_stats_mapping_border, port_id, nic_stats_mapping_border);
207
208         if (port->rx_queue_stats_mapping_enabled) {
209                 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
210                         if (rx_queue_stats_mappings[i].port_id == port_id) {
211                                 printf("  RX-queue %2d mapped to Stats Reg %2d\n",
212                                        rx_queue_stats_mappings[i].queue_id,
213                                        rx_queue_stats_mappings[i].stats_counter_id);
214                         }
215                 }
216                 printf("\n");
217         }
218
219
220         if (port->tx_queue_stats_mapping_enabled) {
221                 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
222                         if (tx_queue_stats_mappings[i].port_id == port_id) {
223                                 printf("  TX-queue %2d mapped to Stats Reg %2d\n",
224                                        tx_queue_stats_mappings[i].queue_id,
225                                        tx_queue_stats_mappings[i].stats_counter_id);
226                         }
227                 }
228         }
229
230         printf("  %s####################################%s\n",
231                nic_stats_mapping_border, nic_stats_mapping_border);
232 }
233
234 void
235 port_infos_display(portid_t port_id)
236 {
237         struct rte_port *port;
238         struct rte_eth_link link;
239         int vlan_offload;
240         static const char *info_border = "*********************";
241
242         if (port_id >= nb_ports) {
243                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
244                 return;
245         }
246         port = &ports[port_id];
247         rte_eth_link_get_nowait(port_id, &link);
248         printf("\n%s Infos for port %-2d %s\n",
249                info_border, port_id, info_border);
250         print_ethaddr("MAC address: ", &port->eth_addr);
251         printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
252         printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
253         printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
254                ("full-duplex") : ("half-duplex"));
255         printf("Promiscuous mode: %s\n",
256                rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
257         printf("Allmulticast mode: %s\n",
258                rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
259         printf("Maximum number of MAC addresses: %u\n",
260                (unsigned int)(port->dev_info.max_mac_addrs));
261
262         vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
263         if (vlan_offload >= 0){
264                 printf("VLAN offload: \n");
265                 if (vlan_offload & ETH_VLAN_STRIP_OFFLOAD)
266                         printf("  strip on \n");
267                 else
268                         printf("  strip off \n");
269
270                 if (vlan_offload & ETH_VLAN_FILTER_OFFLOAD)
271                         printf("  filter on \n");
272                 else
273                         printf("  filter off \n");
274
275                 if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)
276                         printf("  qinq(extend) on \n");
277                 else
278                         printf("  qinq(extend) off \n");
279         }
280 }
281
282 static int
283 port_id_is_invalid(portid_t port_id)
284 {
285         if (port_id < nb_ports)
286                 return 0;
287         printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
288         return 1;
289 }
290
291 static int
292 vlan_id_is_invalid(uint16_t vlan_id)
293 {
294         if (vlan_id < 4096)
295                 return 0;
296         printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
297         return 1;
298 }
299
300 static int
301 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
302 {
303         uint64_t pci_len;
304
305         if (reg_off & 0x3) {
306                 printf("Port register offset 0x%X not aligned on a 4-byte "
307                        "boundary\n",
308                        (unsigned)reg_off);
309                 return 1;
310         }
311         pci_len = ports[port_id].dev_info.pci_dev->mem_resource.len;
312         if (reg_off >= pci_len) {
313                 printf("Port %d: register offset %u (0x%X) out of port PCI "
314                        "resource (length=%"PRIu64")\n",
315                        port_id, (unsigned)reg_off, (unsigned)reg_off,  pci_len);
316                 return 1;
317         }
318         return 0;
319 }
320
321 static int
322 reg_bit_pos_is_invalid(uint8_t bit_pos)
323 {
324         if (bit_pos <= 31)
325                 return 0;
326         printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
327         return 1;
328 }
329
330 #define display_port_and_reg_off(port_id, reg_off) \
331         printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
332
333 static inline void
334 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
335 {
336         display_port_and_reg_off(port_id, (unsigned)reg_off);
337         printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
338 }
339
340 void
341 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
342 {
343         uint32_t reg_v;
344
345
346         if (port_id_is_invalid(port_id))
347                 return;
348         if (port_reg_off_is_invalid(port_id, reg_off))
349                 return;
350         if (reg_bit_pos_is_invalid(bit_x))
351                 return;
352         reg_v = port_id_pci_reg_read(port_id, reg_off);
353         display_port_and_reg_off(port_id, (unsigned)reg_off);
354         printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
355 }
356
357 void
358 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
359                            uint8_t bit1_pos, uint8_t bit2_pos)
360 {
361         uint32_t reg_v;
362         uint8_t  l_bit;
363         uint8_t  h_bit;
364
365         if (port_id_is_invalid(port_id))
366                 return;
367         if (port_reg_off_is_invalid(port_id, reg_off))
368                 return;
369         if (reg_bit_pos_is_invalid(bit1_pos))
370                 return;
371         if (reg_bit_pos_is_invalid(bit2_pos))
372                 return;
373         if (bit1_pos > bit2_pos)
374                 l_bit = bit2_pos, h_bit = bit1_pos;
375         else
376                 l_bit = bit1_pos, h_bit = bit2_pos;
377
378         reg_v = port_id_pci_reg_read(port_id, reg_off);
379         reg_v >>= l_bit;
380         if (h_bit < 31)
381                 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
382         display_port_and_reg_off(port_id, (unsigned)reg_off);
383         printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
384                ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
385 }
386
387 void
388 port_reg_display(portid_t port_id, uint32_t reg_off)
389 {
390         uint32_t reg_v;
391
392         if (port_id_is_invalid(port_id))
393                 return;
394         if (port_reg_off_is_invalid(port_id, reg_off))
395                 return;
396         reg_v = port_id_pci_reg_read(port_id, reg_off);
397         display_port_reg_value(port_id, reg_off, reg_v);
398 }
399
400 void
401 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
402                  uint8_t bit_v)
403 {
404         uint32_t reg_v;
405
406         if (port_id_is_invalid(port_id))
407                 return;
408         if (port_reg_off_is_invalid(port_id, reg_off))
409                 return;
410         if (reg_bit_pos_is_invalid(bit_pos))
411                 return;
412         if (bit_v > 1) {
413                 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
414                 return;
415         }
416         reg_v = port_id_pci_reg_read(port_id, reg_off);
417         if (bit_v == 0)
418                 reg_v &= ~(1 << bit_pos);
419         else
420                 reg_v |= (1 << bit_pos);
421         port_id_pci_reg_write(port_id, reg_off, reg_v);
422         display_port_reg_value(port_id, reg_off, reg_v);
423 }
424
425 void
426 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
427                        uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
428 {
429         uint32_t max_v;
430         uint32_t reg_v;
431         uint8_t  l_bit;
432         uint8_t  h_bit;
433
434         if (port_id_is_invalid(port_id))
435                 return;
436         if (port_reg_off_is_invalid(port_id, reg_off))
437                 return;
438         if (reg_bit_pos_is_invalid(bit1_pos))
439                 return;
440         if (reg_bit_pos_is_invalid(bit2_pos))
441                 return;
442         if (bit1_pos > bit2_pos)
443                 l_bit = bit2_pos, h_bit = bit1_pos;
444         else
445                 l_bit = bit1_pos, h_bit = bit2_pos;
446
447         if ((h_bit - l_bit) < 31)
448                 max_v = (1 << (h_bit - l_bit + 1)) - 1;
449         else
450                 max_v = 0xFFFFFFFF;
451
452         if (value > max_v) {
453                 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
454                                 (unsigned)value, (unsigned)value,
455                                 (unsigned)max_v, (unsigned)max_v);
456                 return;
457         }
458         reg_v = port_id_pci_reg_read(port_id, reg_off);
459         reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
460         reg_v |= (value << l_bit); /* Set changed bits */
461         port_id_pci_reg_write(port_id, reg_off, reg_v);
462         display_port_reg_value(port_id, reg_off, reg_v);
463 }
464
465 void
466 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
467 {
468         if (port_id_is_invalid(port_id))
469                 return;
470         if (port_reg_off_is_invalid(port_id, reg_off))
471                 return;
472         port_id_pci_reg_write(port_id, reg_off, reg_v);
473         display_port_reg_value(port_id, reg_off, reg_v);
474 }
475
476 /*
477  * RX/TX ring descriptors display functions.
478  */
479 static int
480 rx_queue_id_is_invalid(queueid_t rxq_id)
481 {
482         if (rxq_id < nb_rxq)
483                 return 0;
484         printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
485         return 1;
486 }
487
488 static int
489 tx_queue_id_is_invalid(queueid_t txq_id)
490 {
491         if (txq_id < nb_txq)
492                 return 0;
493         printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
494         return 1;
495 }
496
497 static int
498 rx_desc_id_is_invalid(uint16_t rxdesc_id)
499 {
500         if (rxdesc_id < nb_rxd)
501                 return 0;
502         printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
503                rxdesc_id, nb_rxd);
504         return 1;
505 }
506
507 static int
508 tx_desc_id_is_invalid(uint16_t txdesc_id)
509 {
510         if (txdesc_id < nb_txd)
511                 return 0;
512         printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
513                txdesc_id, nb_txd);
514         return 1;
515 }
516
517 static const struct rte_memzone *
518 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
519 {
520         char mz_name[RTE_MEMZONE_NAMESIZE];
521         const struct rte_memzone *mz;
522
523         rte_snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
524                  ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
525         mz = rte_memzone_lookup(mz_name);
526         if (mz == NULL)
527                 printf("%s ring memory zoneof (port %d, queue %d) not"
528                        "found (zone name = %s\n",
529                        ring_name, port_id, q_id, mz_name);
530         return (mz);
531 }
532
533 union igb_ring_dword {
534         uint64_t dword;
535         struct {
536                 uint32_t hi;
537                 uint32_t lo;
538         } words;
539 };
540
541 struct igb_ring_desc {
542         union igb_ring_dword lo_dword;
543         union igb_ring_dword hi_dword;
544 };
545
546 static void
547 ring_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
548 {
549         struct igb_ring_desc *ring;
550         struct igb_ring_desc rd;
551
552         ring = (struct igb_ring_desc *) ring_mz->addr;
553         rd.lo_dword = rte_le_to_cpu_64(ring[desc_id].lo_dword);
554         rd.hi_dword = rte_le_to_cpu_64(ring[desc_id].hi_dword);
555         printf("    0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
556                 (unsigned)rd.lo_dword.words.lo, (unsigned)rd.lo_dword.words.hi,
557                 (unsigned)rd.hi_dword.words.lo, (unsigned)rd.hi_dword.words.hi);
558 }
559
560 void
561 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
562 {
563         const struct rte_memzone *rx_mz;
564
565         if (port_id_is_invalid(port_id))
566                 return;
567         if (rx_queue_id_is_invalid(rxq_id))
568                 return;
569         if (rx_desc_id_is_invalid(rxd_id))
570                 return;
571         rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
572         if (rx_mz == NULL)
573                 return;
574         ring_descriptor_display(rx_mz, rxd_id);
575 }
576
577 void
578 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
579 {
580         const struct rte_memzone *tx_mz;
581
582         if (port_id_is_invalid(port_id))
583                 return;
584         if (tx_queue_id_is_invalid(txq_id))
585                 return;
586         if (tx_desc_id_is_invalid(txd_id))
587                 return;
588         tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
589         if (tx_mz == NULL)
590                 return;
591         ring_descriptor_display(tx_mz, txd_id);
592 }
593
594 void
595 fwd_lcores_config_display(void)
596 {
597         lcoreid_t lc_id;
598
599         printf("List of forwarding lcores:");
600         for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
601                 printf(" %2u", fwd_lcores_cpuids[lc_id]);
602         printf("\n");
603 }
604 void
605 rxtx_config_display(void)
606 {
607         printf("  %s packet forwarding - CRC stripping %s - "
608                "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
609                rx_mode.hw_strip_crc ? "enabled" : "disabled",
610                nb_pkt_per_burst);
611
612         if (cur_fwd_eng == &tx_only_engine)
613                 printf("  packet len=%u - nb packet segments=%d\n",
614                                 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
615
616         printf("  nb forwarding cores=%d - nb forwarding ports=%d\n",
617                nb_fwd_lcores, nb_fwd_ports);
618         printf("  RX queues=%d - RX desc=%d - RX free threshold=%d\n",
619                nb_rxq, nb_rxd, rx_free_thresh);
620         printf("  RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
621                rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh);
622         printf("  TX queues=%d - TX desc=%d - TX free threshold=%d\n",
623                nb_txq, nb_txd, tx_free_thresh);
624         printf("  TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
625                tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);
626         printf("  TX RS bit threshold=%d - TXQ flags=0x%"PRIx32"\n",
627                tx_rs_thresh, txq_flags);
628 }
629
630 /*
631  * Setup forwarding configuration for each logical core.
632  */
633 static void
634 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
635 {
636         streamid_t nb_fs_per_lcore;
637         streamid_t nb_fs;
638         streamid_t sm_id;
639         lcoreid_t  nb_extra;
640         lcoreid_t  nb_fc;
641         lcoreid_t  nb_lc;
642         lcoreid_t  lc_id;
643
644         nb_fs = cfg->nb_fwd_streams;
645         nb_fc = cfg->nb_fwd_lcores;
646         if (nb_fs <= nb_fc) {
647                 nb_fs_per_lcore = 1;
648                 nb_extra = 0;
649         } else {
650                 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
651                 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
652         }
653         nb_extra = (lcoreid_t) (nb_fs % nb_fc);
654
655         nb_lc = (lcoreid_t) (nb_fc - nb_extra);
656         sm_id = 0;
657         for (lc_id = 0; lc_id < nb_lc; lc_id++) {
658                 fwd_lcores[lc_id]->stream_idx = sm_id;
659                 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
660                 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
661         }
662
663         /*
664          * Assign extra remaining streams, if any.
665          */
666         nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
667         for (lc_id = 0; lc_id < nb_extra; lc_id++) {
668                 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
669                 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
670                 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
671         }
672 }
673
674 static void
675 simple_fwd_config_setup(void)
676 {
677         portid_t i;
678         portid_t j;
679         portid_t inc = 2;
680
681         if (port_topology == PORT_TOPOLOGY_CHAINED) {
682                 inc = 1;
683         } else if (nb_fwd_ports % 2) {
684                 printf("\nWarning! Cannot handle an odd number of ports "
685                        "with the current port topology. Configuration "
686                        "must be changed to have an even number of ports, "
687                        "or relaunch application with "
688                        "--port-topology=chained\n\n");
689         }
690
691         cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
692         cur_fwd_config.nb_fwd_streams =
693                 (streamid_t) cur_fwd_config.nb_fwd_ports;
694
695         /* reinitialize forwarding streams */
696         init_fwd_streams();
697
698         /*
699          * In the simple forwarding test, the number of forwarding cores
700          * must be lower or equal to the number of forwarding ports.
701          */
702         cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
703         if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
704                 cur_fwd_config.nb_fwd_lcores =
705                         (lcoreid_t) cur_fwd_config.nb_fwd_ports;
706         setup_fwd_config_of_each_lcore(&cur_fwd_config);
707
708         for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
709                 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
710                 fwd_streams[i]->rx_port   = fwd_ports_ids[i];
711                 fwd_streams[i]->rx_queue  = 0;
712                 fwd_streams[i]->tx_port   = fwd_ports_ids[j];
713                 fwd_streams[i]->tx_queue  = 0;
714                 fwd_streams[i]->peer_addr = j;
715
716                 if (port_topology == PORT_TOPOLOGY_PAIRED) {
717                         fwd_streams[j]->rx_port   = fwd_ports_ids[j];
718                         fwd_streams[j]->rx_queue  = 0;
719                         fwd_streams[j]->tx_port   = fwd_ports_ids[i];
720                         fwd_streams[j]->tx_queue  = 0;
721                         fwd_streams[j]->peer_addr = i;
722                 }
723         }
724 }
725
726 /**
727  * For the RSS forwarding test, each core is assigned on every port a transmit
728  * queue whose index is the index of the core itself. This approach limits the
729  * maximumm number of processing cores of the RSS test to the maximum number of
730  * TX queues supported by the devices.
731  *
732  * Each core is assigned a single stream, each stream being composed of
733  * a RX queue to poll on a RX port for input messages, associated with
734  * a TX queue of a TX port where to send forwarded packets.
735  * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
736  * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
737  * following rules:
738  *    - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
739  *    - TxQl = RxQj
740  */
741 static void
742 rss_fwd_config_setup(void)
743 {
744         portid_t   rxp;
745         portid_t   txp;
746         queueid_t  rxq;
747         queueid_t  nb_q;
748         lcoreid_t  lc_id;
749
750         nb_q = nb_rxq;
751         if (nb_q > nb_txq)
752                 nb_q = nb_txq;
753         cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
754         cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
755         cur_fwd_config.nb_fwd_streams =
756                 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
757         if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
758                 cur_fwd_config.nb_fwd_streams =
759                         (streamid_t)cur_fwd_config.nb_fwd_lcores;
760         else
761                 cur_fwd_config.nb_fwd_lcores =
762                         (lcoreid_t)cur_fwd_config.nb_fwd_streams;
763
764         /* reinitialize forwarding streams */
765         init_fwd_streams();
766
767         setup_fwd_config_of_each_lcore(&cur_fwd_config);
768         rxp = 0; rxq = 0;
769         for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
770                 struct fwd_stream *fs;
771
772                 fs = fwd_streams[lc_id];
773                 if ((rxp & 0x1) == 0)
774                         txp = (portid_t) (rxp + 1);
775                 else
776                         txp = (portid_t) (rxp - 1);
777                 fs->rx_port = fwd_ports_ids[rxp];
778                 fs->rx_queue = rxq;
779                 fs->tx_port = fwd_ports_ids[txp];
780                 fs->tx_queue = rxq;
781                 fs->peer_addr = fs->tx_port;
782                 rxq = (queueid_t) (rxq + 1);
783                 if (rxq < nb_q)
784                         continue;
785                 /*
786                  * rxq == nb_q
787                  * Restart from RX queue 0 on next RX port
788                  */
789                 rxq = 0;
790                 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
791                         rxp = (portid_t)
792                                 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
793                 else
794                         rxp = (portid_t) (rxp + 1);
795         }
796 }
797
798 /*
799  * In DCB and VT on,the mapping of 128 receive queues to 128 transmit queues.
800  */
801 static void
802 dcb_rxq_2_txq_mapping(queueid_t rxq, queueid_t *txq)
803 {
804         if(dcb_q_mapping == DCB_4_TCS_Q_MAPPING) {
805
806                 if (rxq < 32)
807                         /* tc0: 0-31 */ 
808                         *txq = rxq;  
809                 else if (rxq < 64) {
810                         /* tc1: 64-95 */ 
811                         *txq =  (uint16_t)(rxq + 32);
812                 } 
813                 else {  
814                         /* tc2: 96-111;tc3:112-127 */
815                         *txq =  (uint16_t)(rxq/2 + 64);
816                 }
817         }
818         else {
819                 if (rxq < 16)
820                         /* tc0 mapping*/
821                         *txq = rxq;
822                 else if (rxq < 32) {
823                         /* tc1 mapping*/
824                          *txq = (uint16_t)(rxq + 16);
825                 }
826                 else if (rxq < 64) {
827                         /*tc2,tc3 mapping */
828                         *txq =  (uint16_t)(rxq + 32);
829                 }
830                 else {
831                         /* tc4,tc5,tc6 and tc7 mapping */
832                         *txq =  (uint16_t)(rxq/2 + 64);
833                 }
834         }
835 }
836
837 /**
838  * For the DCB forwarding test, each core is assigned on every port multi-transmit
839  * queue. 
840  *
841  * Each core is assigned a multi-stream, each stream being composed of
842  * a RX queue to poll on a RX port for input messages, associated with
843  * a TX queue of a TX port where to send forwarded packets.
844  * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
845  * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
846  * following rules:
847  * In VT mode,
848  *    - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
849  *    - TxQl = RxQj
850  * In non-VT mode,
851  *    - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd  
852  *    There is a mapping of RxQj to TxQl to be required,and the mapping was implemented
853  *    in dcb_rxq_2_txq_mapping function.
854  */
855 static void
856 dcb_fwd_config_setup(void)
857 {
858         portid_t   rxp;
859         portid_t   txp;
860         queueid_t  rxq;
861         queueid_t  nb_q;
862         lcoreid_t  lc_id;
863         uint8_t sm_id;
864
865         nb_q = nb_rxq;
866
867         cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
868         cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
869         cur_fwd_config.nb_fwd_streams = 
870                 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
871
872         /* reinitialize forwarding streams */
873         init_fwd_streams();
874
875         setup_fwd_config_of_each_lcore(&cur_fwd_config);
876         rxp = 0; rxq = 0;
877         for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
878                 /* a fwd core can run multi-streams */
879                 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++)
880                 {
881                         struct fwd_stream *fs;
882                         fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
883                         if ((rxp & 0x1) == 0)
884                                 txp = (portid_t) (rxp + 1);
885                         else
886                                 txp = (portid_t) (rxp - 1);
887                         fs->rx_port = fwd_ports_ids[rxp];
888                         fs->rx_queue = rxq;
889                         fs->tx_port = fwd_ports_ids[txp];
890                         if (dcb_q_mapping == DCB_VT_Q_MAPPING)
891                                 fs->tx_queue = rxq;
892                         else
893                                 dcb_rxq_2_txq_mapping(rxq, &fs->tx_queue);
894                         fs->peer_addr = fs->tx_port;
895                         rxq = (queueid_t) (rxq + 1);
896                         if (rxq < nb_q)
897                                 continue;
898                         rxq = 0;
899                         if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
900                                 rxp = (portid_t)
901                                         (rxp + ((nb_ports >> 1) / nb_fwd_ports));
902                         else
903                                 rxp = (portid_t) (rxp + 1);
904                 }
905         }
906 }
907
908 void
909 fwd_config_setup(void)
910 {
911         cur_fwd_config.fwd_eng = cur_fwd_eng;
912         if ((nb_rxq > 1) && (nb_txq > 1)){
913                 if (dcb_config)
914                         dcb_fwd_config_setup();
915                 else
916                         rss_fwd_config_setup();
917         }
918         else
919                 simple_fwd_config_setup();
920 }
921
922 static void
923 pkt_fwd_config_display(struct fwd_config *cfg)
924 {
925         struct fwd_stream *fs;
926         lcoreid_t  lc_id;
927         streamid_t sm_id;
928
929         printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
930                "NUMA support %s\n",
931                cfg->fwd_eng->fwd_mode_name,
932                cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
933                numa_support == 1 ? "enabled" : "disabled");
934         for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
935                 printf("Logical Core %u (socket %u) forwards packets on "
936                        "%d streams:",
937                        fwd_lcores_cpuids[lc_id],
938                        rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
939                        fwd_lcores[lc_id]->stream_nb);
940                 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
941                         fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
942                         printf("\n  RX P=%d/Q=%d (socket %u) -> TX "
943                                "P=%d/Q=%d (socket %u) ",
944                                fs->rx_port, fs->rx_queue,
945                                ports[fs->rx_port].socket_id,
946                                fs->tx_port, fs->tx_queue,
947                                ports[fs->tx_port].socket_id);
948                         print_ethaddr("peer=",
949                                       &peer_eth_addrs[fs->peer_addr]);
950                 }
951                 printf("\n");
952         }
953         printf("\n");
954 }
955
956
957 void
958 fwd_config_display(void)
959 {
960         if((dcb_config) && (nb_fwd_lcores == 1)) {
961                 printf("In DCB mode,the nb forwarding cores should be larger than 1\n");
962                 return;
963         } 
964         fwd_config_setup();
965         pkt_fwd_config_display(&cur_fwd_config);
966 }
967
968 int
969 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
970 {
971         unsigned int i;
972         unsigned int lcore_cpuid;
973         int record_now;
974
975         record_now = 0;
976  again:
977         for (i = 0; i < nb_lc; i++) {
978                 lcore_cpuid = lcorelist[i];
979                 if (! rte_lcore_is_enabled(lcore_cpuid)) {
980                         printf("lcore %u not enabled\n", lcore_cpuid);
981                         return -1;
982                 }
983                 if (lcore_cpuid == rte_get_master_lcore()) {
984                         printf("lcore %u cannot be masked on for running "
985                                "packet forwarding, which is the master lcore "
986                                "and reserved for command line parsing only\n",
987                                lcore_cpuid);
988                         return -1;
989                 }
990                 if (record_now)
991                         fwd_lcores_cpuids[i] = lcore_cpuid;
992         }
993         if (record_now == 0) {
994                 record_now = 1;
995                 goto again;
996         }
997         nb_cfg_lcores = (lcoreid_t) nb_lc;
998         if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
999                 printf("previous number of forwarding cores %u - changed to "
1000                        "number of configured cores %u\n",
1001                        (unsigned int) nb_fwd_lcores, nb_lc);
1002                 nb_fwd_lcores = (lcoreid_t) nb_lc;
1003         }
1004
1005         return 0;
1006 }
1007
1008 int
1009 set_fwd_lcores_mask(uint64_t lcoremask)
1010 {
1011         unsigned int lcorelist[64];
1012         unsigned int nb_lc;
1013         unsigned int i;
1014
1015         if (lcoremask == 0) {
1016                 printf("Invalid NULL mask of cores\n");
1017                 return -1;
1018         }
1019         nb_lc = 0;
1020         for (i = 0; i < 64; i++) {
1021                 if (! ((uint64_t)(1ULL << i) & lcoremask))
1022                         continue;
1023                 lcorelist[nb_lc++] = i;
1024         }
1025         return set_fwd_lcores_list(lcorelist, nb_lc);
1026 }
1027
1028 void
1029 set_fwd_lcores_number(uint16_t nb_lc)
1030 {
1031         if (nb_lc > nb_cfg_lcores) {
1032                 printf("nb fwd cores %u > %u (max. number of configured "
1033                        "lcores) - ignored\n",
1034                        (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
1035                 return;
1036         }
1037         nb_fwd_lcores = (lcoreid_t) nb_lc;
1038         printf("Number of forwarding cores set to %u\n",
1039                (unsigned int) nb_fwd_lcores);
1040 }
1041
1042 void
1043 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
1044 {
1045         unsigned int i;
1046         portid_t port_id;
1047         int record_now;
1048
1049         record_now = 0;
1050  again:
1051         for (i = 0; i < nb_pt; i++) {
1052                 port_id = (portid_t) portlist[i];
1053                 if (port_id >= nb_ports) {
1054                         printf("Invalid port id %u > %u\n",
1055                                (unsigned int) port_id,
1056                                (unsigned int) nb_ports);
1057                         return;
1058                 }
1059                 if (record_now)
1060                         fwd_ports_ids[i] = port_id;
1061         }
1062         if (record_now == 0) {
1063                 record_now = 1;
1064                 goto again;
1065         }
1066         nb_cfg_ports = (portid_t) nb_pt;
1067         if (nb_fwd_ports != (portid_t) nb_pt) {
1068                 printf("previous number of forwarding ports %u - changed to "
1069                        "number of configured ports %u\n",
1070                        (unsigned int) nb_fwd_ports, nb_pt);
1071                 nb_fwd_ports = (portid_t) nb_pt;
1072         }
1073 }
1074
1075 void
1076 set_fwd_ports_mask(uint64_t portmask)
1077 {
1078         unsigned int portlist[64];
1079         unsigned int nb_pt;
1080         unsigned int i;
1081
1082         if (portmask == 0) {
1083                 printf("Invalid NULL mask of ports\n");
1084                 return;
1085         }
1086         nb_pt = 0;
1087         for (i = 0; i < 64; i++) {
1088                 if (! ((uint64_t)(1ULL << i) & portmask))
1089                         continue;
1090                 portlist[nb_pt++] = i;
1091         }
1092         set_fwd_ports_list(portlist, nb_pt);
1093 }
1094
1095 void
1096 set_fwd_ports_number(uint16_t nb_pt)
1097 {
1098         if (nb_pt > nb_cfg_ports) {
1099                 printf("nb fwd ports %u > %u (number of configured "
1100                        "ports) - ignored\n",
1101                        (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
1102                 return;
1103         }
1104         nb_fwd_ports = (portid_t) nb_pt;
1105         printf("Number of forwarding ports set to %u\n",
1106                (unsigned int) nb_fwd_ports);
1107 }
1108
1109 void
1110 set_nb_pkt_per_burst(uint16_t nb)
1111 {
1112         if (nb > MAX_PKT_BURST) {
1113                 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
1114                        " ignored\n",
1115                        (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
1116                 return;
1117         }
1118         nb_pkt_per_burst = nb;
1119         printf("Number of packets per burst set to %u\n",
1120                (unsigned int) nb_pkt_per_burst);
1121 }
1122
1123 void
1124 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
1125 {
1126         uint16_t tx_pkt_len;
1127         unsigned i;
1128
1129         if (nb_segs >= (unsigned) nb_txd) {
1130                 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
1131                        nb_segs, (unsigned int) nb_txd);
1132                 return;
1133         }
1134
1135         /*
1136          * Check that each segment length is greater or equal than
1137          * the mbuf data sise.
1138          * Check also that the total packet length is greater or equal than the
1139          * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
1140          */
1141         tx_pkt_len = 0;
1142         for (i = 0; i < nb_segs; i++) {
1143                 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
1144                         printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
1145                                i, seg_lengths[i], (unsigned) mbuf_data_size);
1146                         return;
1147                 }
1148                 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
1149         }
1150         if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
1151                 printf("total packet length=%u < %d - give up\n",
1152                                 (unsigned) tx_pkt_len,
1153                                 (int)(sizeof(struct ether_hdr) + 20 + 8));
1154                 return;
1155         }
1156
1157         for (i = 0; i < nb_segs; i++)
1158                 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
1159
1160         tx_pkt_length  = tx_pkt_len;
1161         tx_pkt_nb_segs = (uint8_t) nb_segs;
1162 }
1163
1164 void
1165 set_pkt_forwarding_mode(const char *fwd_mode_name)
1166 {
1167         struct fwd_engine *fwd_eng;
1168         unsigned i;
1169
1170         i = 0;
1171         while ((fwd_eng = fwd_engines[i]) != NULL) {
1172                 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
1173                         printf("Set %s packet forwarding mode\n",
1174                                fwd_mode_name);
1175                         cur_fwd_eng = fwd_eng;
1176                         return;
1177                 }
1178                 i++;
1179         }
1180         printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1181 }
1182
1183 void
1184 set_verbose_level(uint16_t vb_level)
1185 {
1186         printf("Change verbose level from %u to %u\n",
1187                (unsigned int) verbose_level, (unsigned int) vb_level);
1188         verbose_level = vb_level;
1189 }
1190
1191 void
1192 vlan_extend_set(portid_t port_id, int on)
1193 {
1194         int diag;
1195         int vlan_offload;
1196
1197         if (port_id_is_invalid(port_id))
1198                 return;
1199
1200         vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1201
1202         if (on)
1203                 vlan_offload |= ETH_VLAN_EXTEND_OFFLOAD;
1204         else
1205                 vlan_offload &= ~ETH_VLAN_EXTEND_OFFLOAD;
1206
1207         diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1208         if (diag < 0)
1209                 printf("rx_vlan_extend_set(port_pi=%d, on=%d) failed "
1210                "diag=%d\n", port_id, on, diag);
1211 }
1212
1213 void
1214 rx_vlan_strip_set(portid_t port_id, int on)
1215 {
1216         int diag;
1217         int vlan_offload;
1218
1219         if (port_id_is_invalid(port_id))
1220                 return;
1221
1222         vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1223
1224         if (on)
1225                 vlan_offload |= ETH_VLAN_STRIP_OFFLOAD;
1226         else
1227                 vlan_offload &= ~ETH_VLAN_STRIP_OFFLOAD;
1228
1229         diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1230         if (diag < 0)
1231                 printf("rx_vlan_strip_set(port_pi=%d, on=%d) failed "
1232                "diag=%d\n", port_id, on, diag);
1233 }
1234
1235 void
1236 rx_vlan_strip_set_on_queue(portid_t port_id, uint16_t queue_id, int on)
1237 {
1238         int diag;
1239
1240         if (port_id_is_invalid(port_id))
1241                 return;
1242
1243         diag = rte_eth_dev_set_vlan_strip_on_queue(port_id, queue_id, on);
1244         if (diag < 0)
1245                 printf("rx_vlan_strip_set_on_queue(port_pi=%d, queue_id=%d, on=%d) failed "
1246                "diag=%d\n", port_id, queue_id, on, diag);
1247 }
1248
1249 void
1250 rx_vlan_filter_set(portid_t port_id, int on)
1251 {
1252         int diag;
1253         int vlan_offload;
1254
1255         if (port_id_is_invalid(port_id))
1256                 return;
1257
1258         vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
1259
1260         if (on)
1261                 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1262         else
1263                 vlan_offload &= ~ETH_VLAN_FILTER_OFFLOAD;
1264
1265         diag = rte_eth_dev_set_vlan_offload(port_id, vlan_offload);
1266         if (diag < 0)
1267                 printf("rx_vlan_filter_set(port_pi=%d, on=%d) failed "
1268                "diag=%d\n", port_id, on, diag);
1269 }
1270
1271 void
1272 rx_vft_set(portid_t port_id, uint16_t vlan_id, int on)
1273 {
1274         int diag;
1275
1276         if (port_id_is_invalid(port_id))
1277                 return;
1278         if (vlan_id_is_invalid(vlan_id))
1279                 return;
1280         diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1281         if (diag == 0)
1282                 return;
1283         printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1284                "diag=%d\n",
1285                port_id, vlan_id, on, diag);
1286 }
1287
1288 void
1289 rx_vlan_all_filter_set(portid_t port_id, int on)
1290 {
1291         uint16_t vlan_id;
1292
1293         if (port_id_is_invalid(port_id))
1294                 return;
1295         for (vlan_id = 0; vlan_id < 4096; vlan_id++)
1296                 rx_vft_set(port_id, vlan_id, on);
1297 }
1298
1299 void
1300 vlan_tpid_set(portid_t port_id, uint16_t tp_id)
1301 {
1302         int diag;
1303         if (port_id_is_invalid(port_id))
1304                 return;
1305
1306         diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
1307         if (diag == 0)
1308                 return;
1309
1310         printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
1311                "diag=%d\n",
1312                port_id, tp_id, diag);
1313 }
1314
1315 void
1316 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1317 {
1318         if (port_id_is_invalid(port_id))
1319                 return;
1320         if (vlan_id_is_invalid(vlan_id))
1321                 return;
1322         ports[port_id].tx_ol_flags |= PKT_TX_VLAN_PKT;
1323         ports[port_id].tx_vlan_id = vlan_id;
1324 }
1325
1326 void
1327 tx_vlan_reset(portid_t port_id)
1328 {
1329         if (port_id_is_invalid(port_id))
1330                 return;
1331         ports[port_id].tx_ol_flags &= ~PKT_TX_VLAN_PKT;
1332 }
1333
1334 void
1335 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1336 {
1337         uint16_t i;
1338         uint8_t existing_mapping_found = 0;
1339
1340         if (port_id_is_invalid(port_id))
1341                 return;
1342
1343         if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1344                 return;
1345
1346         if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1347                 printf("map_value not in required range 0..%d\n",
1348                                 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1349                 return;
1350         }
1351
1352         if (!is_rx) { /*then tx*/
1353                 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1354                         if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1355                             (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1356                                 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1357                                 existing_mapping_found = 1;
1358                                 break;
1359                         }
1360                 }
1361                 if (!existing_mapping_found) { /* A new additional mapping... */
1362                         tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1363                         tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1364                         tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1365                         nb_tx_queue_stats_mappings++;
1366                 }
1367         }
1368         else { /*rx*/
1369                 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1370                         if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1371                             (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1372                                 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1373                                 existing_mapping_found = 1;
1374                                 break;
1375                         }
1376                 }
1377                 if (!existing_mapping_found) { /* A new additional mapping... */
1378                         rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1379                         rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1380                         rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1381                         nb_rx_queue_stats_mappings++;
1382                 }
1383         }
1384 }
1385
1386 void
1387 tx_cksum_set(portid_t port_id, uint8_t cksum_mask)
1388 {
1389         uint16_t tx_ol_flags;
1390         if (port_id_is_invalid(port_id))
1391                 return;
1392         /* Clear last 4 bits and then set L3/4 checksum mask again */
1393         tx_ol_flags = (uint16_t) (ports[port_id].tx_ol_flags & 0xFFF0);
1394         ports[port_id].tx_ol_flags = (uint16_t) ((cksum_mask & 0xf) | tx_ol_flags);
1395 }
1396
1397 void
1398 fdir_add_signature_filter(portid_t port_id, uint8_t queue_id,
1399                           struct rte_fdir_filter *fdir_filter)
1400 {
1401         int diag;
1402
1403         if (port_id_is_invalid(port_id))
1404                 return;
1405
1406         diag = rte_eth_dev_fdir_add_signature_filter(port_id, fdir_filter,
1407                                                      queue_id);
1408         if (diag == 0)
1409                 return;
1410
1411         printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1412                "diag=%d\n", port_id, diag);
1413 }
1414
1415 void
1416 fdir_update_signature_filter(portid_t port_id, uint8_t queue_id,
1417                              struct rte_fdir_filter *fdir_filter)
1418 {
1419         int diag;
1420
1421         if (port_id_is_invalid(port_id))
1422                 return;
1423
1424         diag = rte_eth_dev_fdir_update_signature_filter(port_id, fdir_filter,
1425                                                         queue_id);
1426         if (diag == 0)
1427                 return;
1428
1429         printf("rte_eth_dev_fdir_update_signature_filter for port_id=%d failed "
1430                "diag=%d\n", port_id, diag);
1431 }
1432
1433 void
1434 fdir_remove_signature_filter(portid_t port_id,
1435                              struct rte_fdir_filter *fdir_filter)
1436 {
1437         int diag;
1438
1439         if (port_id_is_invalid(port_id))
1440                 return;
1441
1442         diag = rte_eth_dev_fdir_remove_signature_filter(port_id, fdir_filter);
1443         if (diag == 0)
1444                 return;
1445
1446         printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1447                "diag=%d\n", port_id, diag);
1448
1449 }
1450
1451 void
1452 fdir_get_infos(portid_t port_id)
1453 {
1454         struct rte_eth_fdir fdir_infos;
1455
1456         static const char *fdir_stats_border = "########################";
1457
1458         if (port_id_is_invalid(port_id))
1459                 return;
1460
1461         rte_eth_dev_fdir_get_infos(port_id, &fdir_infos);
1462
1463         printf("\n  %s FDIR infos for port %-2d     %s\n",
1464                fdir_stats_border, port_id, fdir_stats_border);
1465
1466         printf("  collision: %-10"PRIu64"  free:     %"PRIu64"\n"
1467                "  maxhash:   %-10"PRIu64"  maxlen:   %"PRIu64"\n"
1468                "  add:       %-10"PRIu64"  remove:   %"PRIu64"\n"
1469                "  f_add:     %-10"PRIu64"  f_remove: %"PRIu64"\n",
1470                (uint64_t)(fdir_infos.collision), (uint64_t)(fdir_infos.free),
1471                (uint64_t)(fdir_infos.maxhash), (uint64_t)(fdir_infos.maxlen),
1472                fdir_infos.add, fdir_infos.remove,
1473                fdir_infos.f_add, fdir_infos.f_remove);
1474         printf("  %s############################%s\n",
1475                fdir_stats_border, fdir_stats_border);
1476 }
1477
1478 void
1479 fdir_add_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1480                         uint8_t drop, struct rte_fdir_filter *fdir_filter)
1481 {
1482         int diag;
1483
1484         if (port_id_is_invalid(port_id))
1485                 return;
1486
1487         diag = rte_eth_dev_fdir_add_perfect_filter(port_id, fdir_filter,
1488                                                    soft_id, queue_id, drop);
1489         if (diag == 0)
1490                 return;
1491
1492         printf("rte_eth_dev_fdir_add_perfect_filter for port_id=%d failed "
1493                "diag=%d\n", port_id, diag);
1494 }
1495
1496 void
1497 fdir_update_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1498                            uint8_t drop, struct rte_fdir_filter *fdir_filter)
1499 {
1500         int diag;
1501
1502         if (port_id_is_invalid(port_id))
1503                 return;
1504
1505         diag = rte_eth_dev_fdir_update_perfect_filter(port_id, fdir_filter,
1506                                                       soft_id, queue_id, drop);
1507         if (diag == 0)
1508                 return;
1509
1510         printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1511                "diag=%d\n", port_id, diag);
1512 }
1513
1514 void
1515 fdir_remove_perfect_filter(portid_t port_id, uint16_t soft_id,
1516                            struct rte_fdir_filter *fdir_filter)
1517 {
1518         int diag;
1519
1520         if (port_id_is_invalid(port_id))
1521                 return;
1522
1523         diag = rte_eth_dev_fdir_remove_perfect_filter(port_id, fdir_filter,
1524                                                       soft_id);
1525         if (diag == 0)
1526                 return;
1527
1528         printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1529                "diag=%d\n", port_id, diag);
1530 }
1531
1532 void
1533 fdir_set_masks(portid_t port_id, struct rte_fdir_masks *fdir_masks)
1534 {
1535         int diag;
1536
1537         if (port_id_is_invalid(port_id))
1538                 return;
1539
1540         diag = rte_eth_dev_fdir_set_masks(port_id, fdir_masks);
1541         if (diag == 0)
1542                 return;
1543
1544         printf("rte_eth_dev_set_masks_filter for port_id=%d failed "
1545                "diag=%d\n", port_id, diag);
1546 }