app/testpmd: add stats per queue
[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
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <stdarg.h>
40 #include <stdint.h>
41 #include <inttypes.h>
42
43 #include <sys/queue.h>
44
45 #include <rte_common.h>
46 #include <rte_byteorder.h>
47 #include <rte_debug.h>
48 #include <rte_log.h>
49 #include <rte_memory.h>
50 #include <rte_memcpy.h>
51 #include <rte_memzone.h>
52 #include <rte_launch.h>
53 #include <rte_tailq.h>
54 #include <rte_eal.h>
55 #include <rte_per_lcore.h>
56 #include <rte_lcore.h>
57 #include <rte_atomic.h>
58 #include <rte_branch_prediction.h>
59 #include <rte_ring.h>
60 #include <rte_mempool.h>
61 #include <rte_mbuf.h>
62 #include <rte_interrupts.h>
63 #include <rte_pci.h>
64 #include <rte_ether.h>
65 #include <rte_ethdev.h>
66 #include <rte_string_fns.h>
67
68 #include "testpmd.h"
69
70 static void
71 print_ethaddr(const char *name, struct ether_addr *eth_addr)
72 {
73         printf("%s%02X:%02X:%02X:%02X:%02X:%02X", name,
74                eth_addr->addr_bytes[0],
75                eth_addr->addr_bytes[1],
76                eth_addr->addr_bytes[2],
77                eth_addr->addr_bytes[3],
78                eth_addr->addr_bytes[4],
79                eth_addr->addr_bytes[5]);
80 }
81
82 void
83 nic_stats_display(portid_t port_id)
84 {
85         struct rte_eth_stats stats;
86         struct rte_port *port = &ports[port_id];
87         uint8_t i;
88
89         static const char *nic_stats_border = "########################";
90
91         if (port_id >= nb_ports) {
92                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
93                 return;
94         }
95         rte_eth_stats_get(port_id, &stats);
96         printf("\n  %s NIC statistics for port %-2d %s\n",
97                nic_stats_border, port_id, nic_stats_border);
98
99         if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
100                 printf("  RX-packets: %-10"PRIu64" RX-errors: %-10"PRIu64"RX-bytes: "
101                        "%-"PRIu64"\n"
102                        "  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64"TX-bytes: "
103                        "%-"PRIu64"\n",
104                        stats.ipackets, stats.ierrors, stats.ibytes,
105                        stats.opackets, stats.oerrors, stats.obytes);
106         }
107         else {
108                 printf("  RX-packets:              %10"PRIu64"    RX-errors: %10"PRIu64
109                        "    RX-bytes: %10"PRIu64"\n"
110                        "  TX-packets:              %10"PRIu64"    TX-errors: %10"PRIu64
111                        "    TX-bytes: %10"PRIu64"\n",
112                        stats.ipackets, stats.ierrors, stats.ibytes,
113                        stats.opackets, stats.oerrors, stats.obytes);
114         }
115
116         /* stats fdir */
117         if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
118                 printf("  Fdirmiss:   %-10"PRIu64" Fdirmatch: %-10"PRIu64"\n",
119                        stats.fdirmiss,
120                        stats.fdirmatch);
121
122         if (port->rx_queue_stats_mapping_enabled) {
123                 printf("\n");
124                 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
125                         printf("  Stats reg %2d RX-packets: %10"PRIu64
126                                "    RX-errors: %10"PRIu64
127                                "    RX-bytes: %10"PRIu64"\n",
128                                i, stats.q_ipackets[i], stats.q_errors[i], stats.q_ibytes[i]);
129                 }
130         }
131         if (port->tx_queue_stats_mapping_enabled) {
132                 printf("\n");
133                 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
134                         printf("  Stats reg %2d TX-packets: %10"PRIu64
135                                "                             TX-bytes: %10"PRIu64"\n",
136                                i, stats.q_opackets[i], stats.q_obytes[i]);
137                 }
138         }
139
140         printf("  %s############################%s\n",
141                nic_stats_border, nic_stats_border);
142 }
143
144 void
145 nic_stats_clear(portid_t port_id)
146 {
147         if (port_id >= nb_ports) {
148                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
149                 return;
150         }
151         rte_eth_stats_reset(port_id);
152         printf("\n  NIC statistics for port %d cleared\n", port_id);
153 }
154
155
156 void
157 nic_stats_mapping_display(portid_t port_id)
158 {
159         struct rte_port *port = &ports[port_id];
160         uint16_t i;
161
162         static const char *nic_stats_mapping_border = "########################";
163
164         if (port_id >= nb_ports) {
165                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
166                 return;
167         }
168
169         if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
170                 printf("Port id %d - either does not support queue statistic mapping or"
171                        " no queue statistic mapping set\n", port_id);
172                 return;
173         }
174
175         printf("\n  %s NIC statistics mapping for port %-2d %s\n",
176                nic_stats_mapping_border, port_id, nic_stats_mapping_border);
177
178         if (port->rx_queue_stats_mapping_enabled) {
179                 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
180                         if (rx_queue_stats_mappings[i].port_id == port_id) {
181                                 printf("  RX-queue %2d mapped to Stats Reg %2d\n",
182                                        rx_queue_stats_mappings[i].queue_id,
183                                        rx_queue_stats_mappings[i].stats_counter_id);
184                         }
185                 }
186                 printf("\n");
187         }
188
189
190         if (port->tx_queue_stats_mapping_enabled) {
191                 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
192                         if (tx_queue_stats_mappings[i].port_id == port_id) {
193                                 printf("  TX-queue %2d mapped to Stats Reg %2d\n",
194                                        tx_queue_stats_mappings[i].queue_id,
195                                        tx_queue_stats_mappings[i].stats_counter_id);
196                         }
197                 }
198         }
199
200         printf("  %s####################################%s\n",
201                nic_stats_mapping_border, nic_stats_mapping_border);
202 }
203
204 void
205 port_infos_display(portid_t port_id)
206 {
207         struct rte_port *port;
208         struct rte_eth_link link;
209         static const char *info_border = "*********************";
210
211         if (port_id >= nb_ports) {
212                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
213                 return;
214         }
215         port = &ports[port_id];
216         rte_eth_link_get(port_id, &link);
217         printf("\n%s Infos for port %-2d %s\n",
218                info_border, port_id, info_border);
219         print_ethaddr("MAC address: ", &port->eth_addr);
220         printf("\nLink status: %s\n", (link.link_status) ? ("up") : ("down"));
221         printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
222         printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
223                ("full-duplex") : ("half-duplex"));
224         printf("Promiscuous mode: %s\n",
225                rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
226         printf("Allmulticast mode: %s\n",
227                rte_eth_allmulticast_get(port_id) ? "enabled" : "disabled");
228         printf("Maximum number of MAC addresses: %u\n",
229                (unsigned int)(port->dev_info.max_mac_addrs));
230 }
231
232 static int
233 port_id_is_invalid(portid_t port_id)
234 {
235         if (port_id < nb_ports)
236                 return 0;
237         printf("Invalid port %d (must be < nb_ports=%d)\n", port_id, nb_ports);
238         return 1;
239 }
240
241 static int
242 vlan_id_is_invalid(uint16_t vlan_id)
243 {
244         if (vlan_id < 4096)
245                 return 0;
246         printf("Invalid vlan_id %d (must be < 4096)\n", vlan_id);
247         return 1;
248 }
249
250 static int
251 port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
252 {
253         uint64_t pci_len;
254
255         if (reg_off & 0x3) {
256                 printf("Port register offset 0x%X not aligned on a 4-byte "
257                        "boundary\n",
258                        (unsigned)reg_off);
259                 return 1;
260         }
261         pci_len = ports[port_id].dev_info.pci_dev->mem_resource.len;
262         if (reg_off >= pci_len) {
263                 printf("Port %d: register offset %u (0x%X) out of port PCI "
264                        "resource (length=%"PRIu64")\n",
265                        port_id, (unsigned)reg_off, (unsigned)reg_off,  pci_len);
266                 return 1;
267         }
268         return 0;
269 }
270
271 static int
272 reg_bit_pos_is_invalid(uint8_t bit_pos)
273 {
274         if (bit_pos <= 31)
275                 return 0;
276         printf("Invalid bit position %d (must be <= 31)\n", bit_pos);
277         return 1;
278 }
279
280 #define display_port_and_reg_off(port_id, reg_off) \
281         printf("port %d PCI register at offset 0x%X: ", (port_id), (reg_off))
282
283 static inline void
284 display_port_reg_value(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
285 {
286         display_port_and_reg_off(port_id, (unsigned)reg_off);
287         printf("0x%08X (%u)\n", (unsigned)reg_v, (unsigned)reg_v);
288 }
289
290 void
291 port_reg_bit_display(portid_t port_id, uint32_t reg_off, uint8_t bit_x)
292 {
293         uint32_t reg_v;
294
295
296         if (port_id_is_invalid(port_id))
297                 return;
298         if (port_reg_off_is_invalid(port_id, reg_off))
299                 return;
300         if (reg_bit_pos_is_invalid(bit_x))
301                 return;
302         reg_v = port_id_pci_reg_read(port_id, reg_off);
303         display_port_and_reg_off(port_id, (unsigned)reg_off);
304         printf("bit %d=%d\n", bit_x, (int) ((reg_v & (1 << bit_x)) >> bit_x));
305 }
306
307 void
308 port_reg_bit_field_display(portid_t port_id, uint32_t reg_off,
309                            uint8_t bit1_pos, uint8_t bit2_pos)
310 {
311         uint32_t reg_v;
312         uint8_t  l_bit;
313         uint8_t  h_bit;
314
315         if (port_id_is_invalid(port_id))
316                 return;
317         if (port_reg_off_is_invalid(port_id, reg_off))
318                 return;
319         if (reg_bit_pos_is_invalid(bit1_pos))
320                 return;
321         if (reg_bit_pos_is_invalid(bit2_pos))
322                 return;
323         if (bit1_pos > bit2_pos)
324                 l_bit = bit2_pos, h_bit = bit1_pos;
325         else
326                 l_bit = bit1_pos, h_bit = bit2_pos;
327
328         reg_v = port_id_pci_reg_read(port_id, reg_off);
329         reg_v >>= l_bit;
330         if (h_bit < 31)
331                 reg_v &= ((1 << (h_bit - l_bit + 1)) - 1);
332         display_port_and_reg_off(port_id, (unsigned)reg_off);
333         printf("bits[%d, %d]=0x%0*X (%u)\n", l_bit, h_bit,
334                ((h_bit - l_bit) / 4) + 1, (unsigned)reg_v, (unsigned)reg_v);
335 }
336
337 void
338 port_reg_display(portid_t port_id, uint32_t reg_off)
339 {
340         uint32_t reg_v;
341
342         if (port_id_is_invalid(port_id))
343                 return;
344         if (port_reg_off_is_invalid(port_id, reg_off))
345                 return;
346         reg_v = port_id_pci_reg_read(port_id, reg_off);
347         display_port_reg_value(port_id, reg_off, reg_v);
348 }
349
350 void
351 port_reg_bit_set(portid_t port_id, uint32_t reg_off, uint8_t bit_pos,
352                  uint8_t bit_v)
353 {
354         uint32_t reg_v;
355
356         if (port_id_is_invalid(port_id))
357                 return;
358         if (port_reg_off_is_invalid(port_id, reg_off))
359                 return;
360         if (reg_bit_pos_is_invalid(bit_pos))
361                 return;
362         if (bit_v > 1) {
363                 printf("Invalid bit value %d (must be 0 or 1)\n", (int) bit_v);
364                 return;
365         }
366         reg_v = port_id_pci_reg_read(port_id, reg_off);
367         if (bit_v == 0)
368                 reg_v &= ~(1 << bit_pos);
369         else
370                 reg_v |= (1 << bit_pos);
371         port_id_pci_reg_write(port_id, reg_off, reg_v);
372         display_port_reg_value(port_id, reg_off, reg_v);
373 }
374
375 void
376 port_reg_bit_field_set(portid_t port_id, uint32_t reg_off,
377                        uint8_t bit1_pos, uint8_t bit2_pos, uint32_t value)
378 {
379         uint32_t max_v;
380         uint32_t reg_v;
381         uint8_t  l_bit;
382         uint8_t  h_bit;
383
384         if (port_id_is_invalid(port_id))
385                 return;
386         if (port_reg_off_is_invalid(port_id, reg_off))
387                 return;
388         if (reg_bit_pos_is_invalid(bit1_pos))
389                 return;
390         if (reg_bit_pos_is_invalid(bit2_pos))
391                 return;
392         if (bit1_pos > bit2_pos)
393                 l_bit = bit2_pos, h_bit = bit1_pos;
394         else
395                 l_bit = bit1_pos, h_bit = bit2_pos;
396
397         if ((h_bit - l_bit) < 31)
398                 max_v = (1 << (h_bit - l_bit + 1)) - 1;
399         else
400                 max_v = 0xFFFFFFFF;
401
402         if (value > max_v) {
403                 printf("Invalid value %u (0x%x) must be < %u (0x%x)\n",
404                                 (unsigned)value, (unsigned)value,
405                                 (unsigned)max_v, (unsigned)max_v);
406                 return;
407         }
408         reg_v = port_id_pci_reg_read(port_id, reg_off);
409         reg_v &= ~(max_v << l_bit); /* Keep unchanged bits */
410         reg_v |= (value << l_bit); /* Set changed bits */
411         port_id_pci_reg_write(port_id, reg_off, reg_v);
412         display_port_reg_value(port_id, reg_off, reg_v);
413 }
414
415 void
416 port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t reg_v)
417 {
418         if (port_id_is_invalid(port_id))
419                 return;
420         if (port_reg_off_is_invalid(port_id, reg_off))
421                 return;
422         port_id_pci_reg_write(port_id, reg_off, reg_v);
423         display_port_reg_value(port_id, reg_off, reg_v);
424 }
425
426 /*
427  * RX/TX ring descriptors display functions.
428  */
429 static int
430 rx_queue_id_is_invalid(queueid_t rxq_id)
431 {
432         if (rxq_id < nb_rxq)
433                 return 0;
434         printf("Invalid RX queue %d (must be < nb_rxq=%d)\n", rxq_id, nb_rxq);
435         return 1;
436 }
437
438 static int
439 tx_queue_id_is_invalid(queueid_t txq_id)
440 {
441         if (txq_id < nb_txq)
442                 return 0;
443         printf("Invalid TX queue %d (must be < nb_rxq=%d)\n", txq_id, nb_txq);
444         return 1;
445 }
446
447 static int
448 rx_desc_id_is_invalid(uint16_t rxdesc_id)
449 {
450         if (rxdesc_id < nb_rxd)
451                 return 0;
452         printf("Invalid RX descriptor %d (must be < nb_rxd=%d)\n",
453                rxdesc_id, nb_rxd);
454         return 1;
455 }
456
457 static int
458 tx_desc_id_is_invalid(uint16_t txdesc_id)
459 {
460         if (txdesc_id < nb_txd)
461                 return 0;
462         printf("Invalid TX descriptor %d (must be < nb_txd=%d)\n",
463                txdesc_id, nb_txd);
464         return 1;
465 }
466
467 static const struct rte_memzone *
468 ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
469 {
470         char mz_name[RTE_MEMZONE_NAMESIZE];
471         const struct rte_memzone *mz;
472
473         rte_snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
474                  ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
475         mz = rte_memzone_lookup(mz_name);
476         if (mz == NULL)
477                 printf("%s ring memory zoneof (port %d, queue %d) not"
478                        "found (zone name = %s\n",
479                        ring_name, port_id, q_id, mz_name);
480         return (mz);
481 }
482
483 union igb_ring_dword {
484         uint64_t dword;
485         struct {
486                 uint32_t hi;
487                 uint32_t lo;
488         } words;
489 };
490
491 struct igb_ring_desc {
492         union igb_ring_dword lo_dword;
493         union igb_ring_dword hi_dword;
494 };
495
496 static void
497 ring_descriptor_display(const struct rte_memzone *ring_mz, uint16_t desc_id)
498 {
499         struct igb_ring_desc *ring;
500         struct igb_ring_desc rd;
501
502         ring = (struct igb_ring_desc *) ring_mz->addr;
503         rd.lo_dword = rte_le_to_cpu_64(ring[desc_id].lo_dword);
504         rd.hi_dword = rte_le_to_cpu_64(ring[desc_id].hi_dword);
505         printf("    0x%08X - 0x%08X / 0x%08X - 0x%08X\n",
506                 (unsigned)rd.lo_dword.words.lo, (unsigned)rd.lo_dword.words.hi,
507                 (unsigned)rd.hi_dword.words.lo, (unsigned)rd.hi_dword.words.hi);
508 }
509
510 void
511 rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id)
512 {
513         const struct rte_memzone *rx_mz;
514
515         if (port_id_is_invalid(port_id))
516                 return;
517         if (rx_queue_id_is_invalid(rxq_id))
518                 return;
519         if (rx_desc_id_is_invalid(rxd_id))
520                 return;
521         rx_mz = ring_dma_zone_lookup("rx_ring", port_id, rxq_id);
522         if (rx_mz == NULL)
523                 return;
524         ring_descriptor_display(rx_mz, rxd_id);
525 }
526
527 void
528 tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id)
529 {
530         const struct rte_memzone *tx_mz;
531
532         if (port_id_is_invalid(port_id))
533                 return;
534         if (tx_queue_id_is_invalid(txq_id))
535                 return;
536         if (tx_desc_id_is_invalid(txd_id))
537                 return;
538         tx_mz = ring_dma_zone_lookup("tx_ring", port_id, txq_id);
539         if (tx_mz == NULL)
540                 return;
541         ring_descriptor_display(tx_mz, txd_id);
542 }
543
544 void
545 fwd_lcores_config_display(void)
546 {
547         lcoreid_t lc_id;
548
549         printf("List of forwarding lcores:");
550         for (lc_id = 0; lc_id < nb_cfg_lcores; lc_id++)
551                 printf(" %2u", fwd_lcores_cpuids[lc_id]);
552         printf("\n");
553 }
554 void
555 rxtx_config_display(void)
556 {
557         printf("  %s packet forwarding - CRC stripping %s - "
558                "packets/burst=%d\n", cur_fwd_eng->fwd_mode_name,
559                rx_mode.hw_strip_crc ? "enabled" : "disabled",
560                nb_pkt_per_burst);
561
562         if (cur_fwd_eng == &tx_only_engine)
563                 printf("  packet len=%u - nb packet segments=%d\n",
564                                 (unsigned)tx_pkt_length, (int) tx_pkt_nb_segs);
565
566         printf("  nb forwarding cores=%d - nb forwarding ports=%d\n",
567                nb_fwd_lcores, nb_fwd_ports);
568         printf("  RX queues=%d - RX desc=%d - RX free threshold=%d\n",
569                nb_rxq, nb_rxd, rx_free_thresh);
570         printf("  RX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
571                rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh);
572         printf("  TX queues=%d - TX desc=%d - TX free threshold=%d\n",
573                nb_txq, nb_txd, tx_free_thresh);
574         printf("  TX threshold registers: pthresh=%d hthresh=%d wthresh=%d\n",
575                tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);
576         printf("  TX RS bit threshold=%d\n", tx_rs_thresh);
577 }
578
579 /*
580  * Setup forwarding configuration for each logical core.
581  */
582 static void
583 setup_fwd_config_of_each_lcore(struct fwd_config *cfg)
584 {
585         streamid_t nb_fs_per_lcore;
586         streamid_t nb_fs;
587         streamid_t sm_id;
588         lcoreid_t  nb_extra;
589         lcoreid_t  nb_fc;
590         lcoreid_t  nb_lc;
591         lcoreid_t  lc_id;
592
593         nb_fs = cfg->nb_fwd_streams;
594         nb_fc = cfg->nb_fwd_lcores;
595         if (nb_fs <= nb_fc) {
596                 nb_fs_per_lcore = 1;
597                 nb_extra = 0;
598         } else {
599                 nb_fs_per_lcore = (streamid_t) (nb_fs / nb_fc);
600                 nb_extra = (lcoreid_t) (nb_fs % nb_fc);
601         }
602         nb_extra = (lcoreid_t) (nb_fs % nb_fc);
603
604         nb_lc = (lcoreid_t) (nb_fc - nb_extra);
605         sm_id = 0;
606         for (lc_id = 0; lc_id < nb_lc; lc_id++) {
607                 fwd_lcores[lc_id]->stream_idx = sm_id;
608                 fwd_lcores[lc_id]->stream_nb = nb_fs_per_lcore;
609                 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
610         }
611
612         /*
613          * Assign extra remaining streams, if any.
614          */
615         nb_fs_per_lcore = (streamid_t) (nb_fs_per_lcore + 1);
616         for (lc_id = 0; lc_id < nb_extra; lc_id++) {
617                 fwd_lcores[nb_lc + lc_id]->stream_idx = sm_id;
618                 fwd_lcores[nb_lc + lc_id]->stream_nb = nb_fs_per_lcore;
619                 sm_id = (streamid_t) (sm_id + nb_fs_per_lcore);
620         }
621 }
622
623 static void
624 simple_fwd_config_setup(void)
625 {
626         portid_t i;
627         portid_t j;
628         portid_t inc = 2;
629
630         if (nb_fwd_ports % 2) {
631                 if (port_topology == PORT_TOPOLOGY_CHAINED) {
632                         inc = 1;
633                 }
634                 else {
635                         printf("\nWarning! Cannot handle an odd number of ports "
636                                "with the current port topology. Configuration "
637                                "must be changed to have an even number of ports, "
638                                "or relaunch application with "
639                                "--port-topology=chained\n\n");
640                 }
641         }
642
643         cur_fwd_config.nb_fwd_ports = (portid_t) nb_fwd_ports;
644         cur_fwd_config.nb_fwd_streams =
645                 (streamid_t) cur_fwd_config.nb_fwd_ports;
646
647         /*
648          * In the simple forwarding test, the number of forwarding cores
649          * must be lower or equal to the number of forwarding ports.
650          */
651         cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
652         if (cur_fwd_config.nb_fwd_lcores > cur_fwd_config.nb_fwd_ports)
653                 cur_fwd_config.nb_fwd_lcores =
654                         (lcoreid_t) cur_fwd_config.nb_fwd_ports;
655         setup_fwd_config_of_each_lcore(&cur_fwd_config);
656
657         for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) {
658                 j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports);
659                 fwd_streams[i]->rx_port   = fwd_ports_ids[i];
660                 fwd_streams[i]->rx_queue  = 0;
661                 fwd_streams[i]->tx_port   = fwd_ports_ids[j];
662                 fwd_streams[i]->tx_queue  = 0;
663                 fwd_streams[i]->peer_addr = j;
664
665                 if (port_topology == PORT_TOPOLOGY_PAIRED) {
666                         fwd_streams[j]->rx_port   = fwd_ports_ids[j];
667                         fwd_streams[j]->rx_queue  = 0;
668                         fwd_streams[j]->tx_port   = fwd_ports_ids[i];
669                         fwd_streams[j]->tx_queue  = 0;
670                         fwd_streams[j]->peer_addr = i;
671                 }
672         }
673 }
674
675 /**
676  * For the RSS forwarding test, each core is assigned on every port a transmit
677  * queue whose index is the index of the core itself. This approach limits the
678  * maximumm number of processing cores of the RSS test to the maximum number of
679  * TX queues supported by the devices.
680  *
681  * Each core is assigned a single stream, each stream being composed of
682  * a RX queue to poll on a RX port for input messages, associated with
683  * a TX queue of a TX port where to send forwarded packets.
684  * All packets received on the RX queue of index "RxQj" of the RX port "RxPi"
685  * are sent on the TX queue "TxQl" of the TX port "TxPk" according to the two
686  * following rules:
687  *    - TxPk = (RxPi + 1) if RxPi is even, (RxPi - 1) if RxPi is odd
688  *    - TxQl = RxQj
689  */
690 static void
691 rss_fwd_config_setup(void)
692 {
693         portid_t   rxp;
694         portid_t   txp;
695         queueid_t  rxq;
696         queueid_t  nb_q;
697         lcoreid_t  lc_id;
698
699         nb_q = nb_rxq;
700         if (nb_q > nb_txq)
701                 nb_q = nb_txq;
702         cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
703         cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
704         cur_fwd_config.nb_fwd_streams =
705                 (streamid_t) (nb_q * cur_fwd_config.nb_fwd_ports);
706         if (cur_fwd_config.nb_fwd_streams > cur_fwd_config.nb_fwd_lcores)
707                 cur_fwd_config.nb_fwd_streams =
708                         (streamid_t)cur_fwd_config.nb_fwd_lcores;
709         else
710                 cur_fwd_config.nb_fwd_lcores =
711                         (lcoreid_t)cur_fwd_config.nb_fwd_streams;
712         setup_fwd_config_of_each_lcore(&cur_fwd_config);
713         rxp = 0; rxq = 0;
714         for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
715                 struct fwd_stream *fs;
716
717                 fs = fwd_streams[lc_id];
718                 if ((rxp & 0x1) == 0)
719                         txp = (portid_t) (rxp + 1);
720                 else
721                         txp = (portid_t) (rxp - 1);
722                 fs->rx_port = fwd_ports_ids[rxp];
723                 fs->rx_queue = rxq;
724                 fs->tx_port = fwd_ports_ids[txp];
725                 fs->tx_queue = rxq;
726                 fs->peer_addr = fs->tx_port;
727                 rxq = (queueid_t) (rxq + 1);
728                 if (rxq < nb_q)
729                         continue;
730                 /*
731                  * rxq == nb_q
732                  * Restart from RX queue 0 on next RX port
733                  */
734                 rxq = 0;
735                 if (numa_support && (nb_fwd_ports <= (nb_ports >> 1)))
736                         rxp = (portid_t)
737                                 (rxp + ((nb_ports >> 1) / nb_fwd_ports));
738                 else
739                         rxp = (portid_t) (rxp + 1);
740         }
741 }
742
743 void
744 fwd_config_setup(void)
745 {
746         cur_fwd_config.fwd_eng = cur_fwd_eng;
747         if ((nb_rxq > 1) && (nb_txq > 1))
748                 rss_fwd_config_setup();
749         else
750                 simple_fwd_config_setup();
751 }
752
753 static void
754 pkt_fwd_config_display(struct fwd_config *cfg)
755 {
756         struct fwd_stream *fs;
757         lcoreid_t  lc_id;
758         streamid_t sm_id;
759
760         printf("%s packet forwarding - ports=%d - cores=%d - streams=%d - "
761                "NUMA support %s\n",
762                cfg->fwd_eng->fwd_mode_name,
763                cfg->nb_fwd_ports, cfg->nb_fwd_lcores, cfg->nb_fwd_streams,
764                numa_support == 1 ? "enabled" : "disabled");
765         for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) {
766                 printf("Logical Core %u (socket %u) forwards packets on "
767                        "%d streams:",
768                        fwd_lcores_cpuids[lc_id],
769                        rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]),
770                        fwd_lcores[lc_id]->stream_nb);
771                 for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) {
772                         fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id];
773                         printf("\n  RX P=%d/Q=%d (socket %u) -> TX "
774                                "P=%d/Q=%d (socket %u) ",
775                                fs->rx_port, fs->rx_queue,
776                                ports[fs->rx_port].socket_id,
777                                fs->tx_port, fs->tx_queue,
778                                ports[fs->tx_port].socket_id);
779                         print_ethaddr("peer=",
780                                       &peer_eth_addrs[fs->peer_addr]);
781                 }
782                 printf("\n");
783         }
784         printf("\n");
785 }
786
787
788 void
789 fwd_config_display(void)
790 {
791         fwd_config_setup();
792         pkt_fwd_config_display(&cur_fwd_config);
793 }
794
795 void
796 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
797 {
798         unsigned int i;
799         unsigned int lcore_cpuid;
800         int record_now;
801
802         record_now = 0;
803  again:
804         for (i = 0; i < nb_lc; i++) {
805                 lcore_cpuid = lcorelist[i];
806                 if (! rte_lcore_is_enabled(lcore_cpuid)) {
807                         printf("Logical core %u not enabled\n", lcore_cpuid);
808                         return;
809                 }
810                 if (lcore_cpuid == rte_get_master_lcore()) {
811                         printf("Master core %u cannot forward packets\n",
812                                lcore_cpuid);
813                         return;
814                 }
815                 if (record_now)
816                         fwd_lcores_cpuids[i] = lcore_cpuid;
817         }
818         if (record_now == 0) {
819                 record_now = 1;
820                 goto again;
821         }
822         nb_cfg_lcores = (lcoreid_t) nb_lc;
823         if (nb_fwd_lcores != (lcoreid_t) nb_lc) {
824                 printf("previous number of forwarding cores %u - changed to "
825                        "number of configured cores %u\n",
826                        (unsigned int) nb_fwd_lcores, nb_lc);
827                 nb_fwd_lcores = (lcoreid_t) nb_lc;
828         }
829 }
830
831 void
832 set_fwd_lcores_mask(uint64_t lcoremask)
833 {
834         unsigned int lcorelist[64];
835         unsigned int nb_lc;
836         unsigned int i;
837
838         if (lcoremask == 0) {
839                 printf("Invalid NULL mask of cores\n");
840                 return;
841         }
842         nb_lc = 0;
843         for (i = 0; i < 64; i++) {
844                 if (! ((uint64_t)(1ULL << i) & lcoremask))
845                         continue;
846                 lcorelist[nb_lc++] = i;
847         }
848         set_fwd_lcores_list(lcorelist, nb_lc);
849 }
850
851 void
852 set_fwd_lcores_number(uint16_t nb_lc)
853 {
854         if (nb_lc > nb_cfg_lcores) {
855                 printf("nb fwd cores %u > %u (max. number of configured "
856                        "lcores) - ignored\n",
857                        (unsigned int) nb_lc, (unsigned int) nb_cfg_lcores);
858                 return;
859         }
860         nb_fwd_lcores = (lcoreid_t) nb_lc;
861         printf("Number of forwarding cores set to %u\n",
862                (unsigned int) nb_fwd_lcores);
863 }
864
865 void
866 set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
867 {
868         unsigned int i;
869         portid_t port_id;
870         int record_now;
871
872         record_now = 0;
873  again:
874         for (i = 0; i < nb_pt; i++) {
875                 port_id = (portid_t) portlist[i];
876                 if (port_id >= nb_ports) {
877                         printf("Invalid port id %u > %u\n",
878                                (unsigned int) port_id,
879                                (unsigned int) nb_ports);
880                         return;
881                 }
882                 if (record_now)
883                         fwd_ports_ids[i] = port_id;
884         }
885         if (record_now == 0) {
886                 record_now = 1;
887                 goto again;
888         }
889         nb_cfg_ports = (portid_t) nb_pt;
890         if (nb_fwd_ports != (portid_t) nb_pt) {
891                 printf("previous number of forwarding ports %u - changed to "
892                        "number of configured ports %u\n",
893                        (unsigned int) nb_fwd_ports, nb_pt);
894                 nb_fwd_ports = (portid_t) nb_pt;
895         }
896 }
897
898 void
899 set_fwd_ports_mask(uint64_t portmask)
900 {
901         unsigned int portlist[64];
902         unsigned int nb_pt;
903         unsigned int i;
904
905         if (portmask == 0) {
906                 printf("Invalid NULL mask of ports\n");
907                 return;
908         }
909         nb_pt = 0;
910         for (i = 0; i < 64; i++) {
911                 if (! ((uint64_t)(1ULL << i) & portmask))
912                         continue;
913                 portlist[nb_pt++] = i;
914         }
915         set_fwd_ports_list(portlist, nb_pt);
916 }
917
918 void
919 set_fwd_ports_number(uint16_t nb_pt)
920 {
921         if (nb_pt > nb_cfg_ports) {
922                 printf("nb fwd ports %u > %u (number of configured "
923                        "ports) - ignored\n",
924                        (unsigned int) nb_pt, (unsigned int) nb_cfg_ports);
925                 return;
926         }
927         nb_fwd_ports = (portid_t) nb_pt;
928         printf("Number of forwarding ports set to %u\n",
929                (unsigned int) nb_fwd_ports);
930 }
931
932 void
933 set_nb_pkt_per_burst(uint16_t nb)
934 {
935         if (nb > MAX_PKT_BURST) {
936                 printf("nb pkt per burst: %u > %u (maximum packet per burst) "
937                        " ignored\n",
938                        (unsigned int) nb, (unsigned int) MAX_PKT_BURST);
939                 return;
940         }
941         nb_pkt_per_burst = nb;
942         printf("Number of packets per burst set to %u\n",
943                (unsigned int) nb_pkt_per_burst);
944 }
945
946 void
947 set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
948 {
949         uint16_t tx_pkt_len;
950         unsigned i;
951
952         if (nb_segs >= (unsigned) nb_txd) {
953                 printf("nb segments per TX packets=%u >= nb_txd=%u - ignored\n",
954                        nb_segs, (unsigned int) nb_txd);
955                 return;
956         }
957
958         /*
959          * Check that each segment length is greater or equal than
960          * the mbuf data sise.
961          * Check also that the total packet length is greater or equal than the
962          * size of an empty UDP/IP packet (sizeof(struct ether_hdr) + 20 + 8).
963          */
964         tx_pkt_len = 0;
965         for (i = 0; i < nb_segs; i++) {
966                 if (seg_lengths[i] > (unsigned) mbuf_data_size) {
967                         printf("length[%u]=%u > mbuf_data_size=%u - give up\n",
968                                i, seg_lengths[i], (unsigned) mbuf_data_size);
969                         return;
970                 }
971                 tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]);
972         }
973         if (tx_pkt_len < (sizeof(struct ether_hdr) + 20 + 8)) {
974                 printf("total packet length=%u < %d - give up\n",
975                                 (unsigned) tx_pkt_len,
976                                 (int)(sizeof(struct ether_hdr) + 20 + 8));
977                 return;
978         }
979
980         for (i = 0; i < nb_segs; i++)
981                 tx_pkt_seg_lengths[i] = (uint16_t) seg_lengths[i];
982
983         tx_pkt_length  = tx_pkt_len;
984         tx_pkt_nb_segs = (uint8_t) nb_segs;
985 }
986
987 void
988 set_pkt_forwarding_mode(const char *fwd_mode_name)
989 {
990         struct fwd_engine *fwd_eng;
991         unsigned i;
992
993         i = 0;
994         while ((fwd_eng = fwd_engines[i]) != NULL) {
995                 if (! strcmp(fwd_eng->fwd_mode_name, fwd_mode_name)) {
996                         printf("Set %s packet forwarding mode\n",
997                                fwd_mode_name);
998                         cur_fwd_eng = fwd_eng;
999                         return;
1000                 }
1001                 i++;
1002         }
1003         printf("Invalid %s packet forwarding mode\n", fwd_mode_name);
1004 }
1005
1006 void
1007 set_verbose_level(uint16_t vb_level)
1008 {
1009         printf("Change verbose level from %u to %u\n",
1010                (unsigned int) verbose_level, (unsigned int) vb_level);
1011         verbose_level = vb_level;
1012 }
1013
1014 void
1015 rx_vlan_filter_set(portid_t port_id, uint16_t vlan_id, int on)
1016 {
1017         int diag;
1018
1019         if (port_id_is_invalid(port_id))
1020                 return;
1021         if (vlan_id_is_invalid(vlan_id))
1022                 return;
1023         diag = rte_eth_dev_vlan_filter(port_id, vlan_id, on);
1024         if (diag == 0)
1025                 return;
1026         printf("rte_eth_dev_vlan_filter(port_pi=%d, vlan_id=%d, on=%d) failed "
1027                "diag=%d\n",
1028                port_id, vlan_id, on, diag);
1029 }
1030
1031 void
1032 rx_vlan_all_filter_set(portid_t port_id, int on)
1033 {
1034         uint16_t vlan_id;
1035
1036         if (port_id_is_invalid(port_id))
1037                 return;
1038         for (vlan_id = 0; vlan_id < 4096; vlan_id++)
1039                 rx_vlan_filter_set(port_id, vlan_id, on);
1040 }
1041
1042 void
1043 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
1044 {
1045         if (port_id_is_invalid(port_id))
1046                 return;
1047         if (vlan_id_is_invalid(vlan_id))
1048                 return;
1049         ports[port_id].tx_ol_flags |= PKT_TX_VLAN_PKT;
1050         ports[port_id].tx_vlan_id = vlan_id;
1051 }
1052
1053 void
1054 tx_vlan_reset(portid_t port_id)
1055 {
1056         if (port_id_is_invalid(port_id))
1057                 return;
1058         ports[port_id].tx_ol_flags &= ~PKT_TX_VLAN_PKT;
1059 }
1060
1061 void
1062 set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value)
1063 {
1064         uint16_t i;
1065         uint8_t existing_mapping_found = 0;
1066
1067         if (port_id_is_invalid(port_id))
1068                 return;
1069
1070         if (is_rx ? (rx_queue_id_is_invalid(queue_id)) : (tx_queue_id_is_invalid(queue_id)))
1071                 return;
1072
1073         if (map_value >= RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1074                 printf("map_value not in required range 0..%d\n",
1075                                 RTE_ETHDEV_QUEUE_STAT_CNTRS - 1);
1076                 return;
1077         }
1078
1079         if (!is_rx) { /*then tx*/
1080                 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1081                         if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1082                             (tx_queue_stats_mappings[i].queue_id == queue_id)) {
1083                                 tx_queue_stats_mappings[i].stats_counter_id = map_value;
1084                                 existing_mapping_found = 1;
1085                                 break;
1086                         }
1087                 }
1088                 if (!existing_mapping_found) { /* A new additional mapping... */
1089                         tx_queue_stats_mappings[nb_tx_queue_stats_mappings].port_id = port_id;
1090                         tx_queue_stats_mappings[nb_tx_queue_stats_mappings].queue_id = queue_id;
1091                         tx_queue_stats_mappings[nb_tx_queue_stats_mappings].stats_counter_id = map_value;
1092                         nb_tx_queue_stats_mappings++;
1093                 }
1094         }
1095         else { /*rx*/
1096                 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1097                         if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1098                             (rx_queue_stats_mappings[i].queue_id == queue_id)) {
1099                                 rx_queue_stats_mappings[i].stats_counter_id = map_value;
1100                                 existing_mapping_found = 1;
1101                                 break;
1102                         }
1103                 }
1104                 if (!existing_mapping_found) { /* A new additional mapping... */
1105                         rx_queue_stats_mappings[nb_rx_queue_stats_mappings].port_id = port_id;
1106                         rx_queue_stats_mappings[nb_rx_queue_stats_mappings].queue_id = queue_id;
1107                         rx_queue_stats_mappings[nb_rx_queue_stats_mappings].stats_counter_id = map_value;
1108                         nb_rx_queue_stats_mappings++;
1109                 }
1110         }
1111 }
1112
1113 void
1114 tx_cksum_set(portid_t port_id, uint8_t cksum_mask)
1115 {
1116         uint16_t tx_ol_flags;
1117         if (port_id_is_invalid(port_id))
1118                 return;
1119         /* Clear last 4 bits and then set L3/4 checksum mask again */
1120         tx_ol_flags = (uint16_t) (ports[port_id].tx_ol_flags & 0xFFF0);
1121         ports[port_id].tx_ol_flags = (uint16_t) ((cksum_mask & 0xf) | tx_ol_flags);
1122 }
1123
1124 void
1125 fdir_add_signature_filter(portid_t port_id, uint8_t queue_id,
1126                           struct rte_fdir_filter *fdir_filter)
1127 {
1128         int diag;
1129
1130         if (port_id_is_invalid(port_id))
1131                 return;
1132
1133         diag = rte_eth_dev_fdir_add_signature_filter(port_id, fdir_filter,
1134                                                      queue_id);
1135         if (diag == 0)
1136                 return;
1137
1138         printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1139                "diag=%d\n", port_id, diag);
1140 }
1141
1142 void
1143 fdir_update_signature_filter(portid_t port_id, uint8_t queue_id,
1144                              struct rte_fdir_filter *fdir_filter)
1145 {
1146         int diag;
1147
1148         if (port_id_is_invalid(port_id))
1149                 return;
1150
1151         diag = rte_eth_dev_fdir_update_signature_filter(port_id, fdir_filter,
1152                                                         queue_id);
1153         if (diag == 0)
1154                 return;
1155
1156         printf("rte_eth_dev_fdir_update_signature_filter for port_id=%d failed "
1157                "diag=%d\n", port_id, diag);
1158 }
1159
1160 void
1161 fdir_remove_signature_filter(portid_t port_id,
1162                              struct rte_fdir_filter *fdir_filter)
1163 {
1164         int diag;
1165
1166         if (port_id_is_invalid(port_id))
1167                 return;
1168
1169         diag = rte_eth_dev_fdir_remove_signature_filter(port_id, fdir_filter);
1170         if (diag == 0)
1171                 return;
1172
1173         printf("rte_eth_dev_fdir_add_signature_filter for port_id=%d failed "
1174                "diag=%d\n", port_id, diag);
1175
1176 }
1177
1178 void
1179 fdir_get_infos(portid_t port_id)
1180 {
1181         struct rte_eth_fdir fdir_infos;
1182
1183         static const char *fdir_stats_border = "########################";
1184
1185         if (port_id_is_invalid(port_id))
1186                 return;
1187
1188         rte_eth_dev_fdir_get_infos(port_id, &fdir_infos);
1189
1190         printf("\n  %s FDIR infos for port %-2d %s\n",
1191                fdir_stats_border, port_id, fdir_stats_border);
1192
1193         printf("  collision: %-10"PRIu64" free: %-10"PRIu64"\n"
1194                "  maxhash: %-10"PRIu64" maxlen: %-10"PRIu64"\n"
1195                "  add : %-10"PRIu64"   remove : %-10"PRIu64"\n"
1196                "  f_add: %-10"PRIu64" f_remove: %-10"PRIu64"\n",
1197                (uint64_t)(fdir_infos.collision), (uint64_t)(fdir_infos.free),
1198                (uint64_t)(fdir_infos.maxhash), (uint64_t)(fdir_infos.maxlen),
1199                fdir_infos.add, fdir_infos.remove,
1200                fdir_infos.f_add, fdir_infos.f_remove);
1201         printf("  %s############################%s\n",
1202                fdir_stats_border, fdir_stats_border);
1203 }
1204
1205 void
1206 fdir_add_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1207                         uint8_t drop, struct rte_fdir_filter *fdir_filter)
1208 {
1209         int diag;
1210
1211         if (port_id_is_invalid(port_id))
1212                 return;
1213
1214         diag = rte_eth_dev_fdir_add_perfect_filter(port_id, fdir_filter,
1215                                                    soft_id, queue_id, drop);
1216         if (diag == 0)
1217                 return;
1218
1219         printf("rte_eth_dev_fdir_add_perfect_filter for port_id=%d failed "
1220                "diag=%d\n", port_id, diag);
1221 }
1222
1223 void
1224 fdir_update_perfect_filter(portid_t port_id, uint16_t soft_id, uint8_t queue_id,
1225                            uint8_t drop, struct rte_fdir_filter *fdir_filter)
1226 {
1227         int diag;
1228
1229         if (port_id_is_invalid(port_id))
1230                 return;
1231
1232         diag = rte_eth_dev_fdir_update_perfect_filter(port_id, fdir_filter,
1233                                                       soft_id, queue_id, drop);
1234         if (diag == 0)
1235                 return;
1236
1237         printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1238                "diag=%d\n", port_id, diag);
1239 }
1240
1241 void
1242 fdir_remove_perfect_filter(portid_t port_id, uint16_t soft_id,
1243                            struct rte_fdir_filter *fdir_filter)
1244 {
1245         int diag;
1246
1247         if (port_id_is_invalid(port_id))
1248                 return;
1249
1250         diag = rte_eth_dev_fdir_remove_perfect_filter(port_id, fdir_filter,
1251                                                       soft_id);
1252         if (diag == 0)
1253                 return;
1254
1255         printf("rte_eth_dev_fdir_update_perfect_filter for port_id=%d failed "
1256                "diag=%d\n", port_id, diag);
1257 }
1258
1259 void
1260 fdir_set_masks(portid_t port_id, struct rte_fdir_masks *fdir_masks)
1261 {
1262         int diag;
1263
1264         if (port_id_is_invalid(port_id))
1265                 return;
1266
1267         diag = rte_eth_dev_fdir_set_masks(port_id, fdir_masks);
1268         if (diag == 0)
1269                 return;
1270
1271         printf("rte_eth_dev_set_masks_filter for port_id=%d failed "
1272                "diag=%d\n", port_id, diag);
1273 }