app/testpmd: add commands for L2 tunnel config
[dpdk.git] / app / test-pmd / cmdline.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <stdarg.h>
40 #include <string.h>
41 #include <termios.h>
42 #include <unistd.h>
43 #include <inttypes.h>
44 #ifndef __linux__
45 #ifndef __FreeBSD__
46 #include <net/socket.h>
47 #else
48 #include <sys/socket.h>
49 #endif
50 #endif
51 #include <netinet/in.h>
52
53 #include <sys/queue.h>
54
55 #include <rte_common.h>
56 #include <rte_byteorder.h>
57 #include <rte_log.h>
58 #include <rte_debug.h>
59 #include <rte_cycles.h>
60 #include <rte_memory.h>
61 #include <rte_memzone.h>
62 #include <rte_malloc.h>
63 #include <rte_launch.h>
64 #include <rte_eal.h>
65 #include <rte_per_lcore.h>
66 #include <rte_lcore.h>
67 #include <rte_atomic.h>
68 #include <rte_branch_prediction.h>
69 #include <rte_ring.h>
70 #include <rte_mempool.h>
71 #include <rte_interrupts.h>
72 #include <rte_pci.h>
73 #include <rte_ether.h>
74 #include <rte_ethdev.h>
75 #include <rte_string_fns.h>
76 #include <rte_devargs.h>
77 #include <rte_eth_ctrl.h>
78
79 #include <cmdline_rdline.h>
80 #include <cmdline_parse.h>
81 #include <cmdline_parse_num.h>
82 #include <cmdline_parse_string.h>
83 #include <cmdline_parse_ipaddr.h>
84 #include <cmdline_parse_etheraddr.h>
85 #include <cmdline_socket.h>
86 #include <cmdline.h>
87 #ifdef RTE_LIBRTE_PMD_BOND
88 #include <rte_eth_bond.h>
89 #endif
90
91 #include "testpmd.h"
92
93 static struct cmdline *testpmd_cl;
94
95 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
96
97 #ifdef RTE_NIC_BYPASS
98 uint8_t bypass_is_supported(portid_t port_id);
99 #endif
100
101 /* *** Help command with introduction. *** */
102 struct cmd_help_brief_result {
103         cmdline_fixed_string_t help;
104 };
105
106 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
107                                   struct cmdline *cl,
108                                   __attribute__((unused)) void *data)
109 {
110         cmdline_printf(
111                 cl,
112                 "\n"
113                 "Help is available for the following sections:\n\n"
114                 "    help control    : Start and stop forwarding.\n"
115                 "    help display    : Displaying port, stats and config "
116                 "information.\n"
117                 "    help config     : Configuration information.\n"
118                 "    help ports      : Configuring ports.\n"
119                 "    help registers  : Reading and setting port registers.\n"
120                 "    help filters    : Filters configuration help.\n"
121                 "    help all        : All of the above sections.\n\n"
122         );
123
124 }
125
126 cmdline_parse_token_string_t cmd_help_brief_help =
127         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
128
129 cmdline_parse_inst_t cmd_help_brief = {
130         .f = cmd_help_brief_parsed,
131         .data = NULL,
132         .help_str = "show help",
133         .tokens = {
134                 (void *)&cmd_help_brief_help,
135                 NULL,
136         },
137 };
138
139 /* *** Help command with help sections. *** */
140 struct cmd_help_long_result {
141         cmdline_fixed_string_t help;
142         cmdline_fixed_string_t section;
143 };
144
145 static void cmd_help_long_parsed(void *parsed_result,
146                                  struct cmdline *cl,
147                                  __attribute__((unused)) void *data)
148 {
149         int show_all = 0;
150         struct cmd_help_long_result *res = parsed_result;
151
152         if (!strcmp(res->section, "all"))
153                 show_all = 1;
154
155         if (show_all || !strcmp(res->section, "control")) {
156
157                 cmdline_printf(
158                         cl,
159                         "\n"
160                         "Control forwarding:\n"
161                         "-------------------\n\n"
162
163                         "start\n"
164                         "    Start packet forwarding with current configuration.\n\n"
165
166                         "start tx_first\n"
167                         "    Start packet forwarding with current config"
168                         " after sending one burst of packets.\n\n"
169
170                         "stop\n"
171                         "    Stop packet forwarding, and display accumulated"
172                         " statistics.\n\n"
173
174                         "quit\n"
175                         "    Quit to prompt.\n\n"
176                 );
177         }
178
179         if (show_all || !strcmp(res->section, "display")) {
180
181                 cmdline_printf(
182                         cl,
183                         "\n"
184                         "Display:\n"
185                         "--------\n\n"
186
187                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc) (port_id|all)\n"
188                         "    Display information for port_id, or all.\n\n"
189
190                         "show port X rss reta (size) (mask0,mask1,...)\n"
191                         "    Display the rss redirection table entry indicated"
192                         " by masks on port X. size is used to indicate the"
193                         " hardware supported reta size\n\n"
194
195                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
196                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
197                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
198                         "    Display the RSS hash functions and RSS hash key"
199                         " of port X\n\n"
200
201                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
202                         "    Clear information for port_id, or all.\n\n"
203
204                         "show (rxq|txq) info (port_id) (queue_id)\n"
205                         "    Display information for configured RX/TX queue.\n\n"
206
207                         "show config (rxtx|cores|fwd|txpkts)\n"
208                         "    Display the given configuration.\n\n"
209
210                         "read rxd (port_id) (queue_id) (rxd_id)\n"
211                         "    Display an RX descriptor of a port RX queue.\n\n"
212
213                         "read txd (port_id) (queue_id) (txd_id)\n"
214                         "    Display a TX descriptor of a port TX queue.\n\n"
215                 );
216         }
217
218         if (show_all || !strcmp(res->section, "config")) {
219                 cmdline_printf(
220                         cl,
221                         "\n"
222                         "Configuration:\n"
223                         "--------------\n"
224                         "Configuration changes only become active when"
225                         " forwarding is started/restarted.\n\n"
226
227                         "set default\n"
228                         "    Reset forwarding to the default configuration.\n\n"
229
230                         "set verbose (level)\n"
231                         "    Set the debug verbosity level X.\n\n"
232
233                         "set nbport (num)\n"
234                         "    Set number of ports.\n\n"
235
236                         "set nbcore (num)\n"
237                         "    Set number of cores.\n\n"
238
239                         "set coremask (mask)\n"
240                         "    Set the forwarding cores hexadecimal mask.\n\n"
241
242                         "set portmask (mask)\n"
243                         "    Set the forwarding ports hexadecimal mask.\n\n"
244
245                         "set burst (num)\n"
246                         "    Set number of packets per burst.\n\n"
247
248                         "set burst tx delay (microseconds) retry (num)\n"
249                         "    Set the transmit delay time and number of retries"
250                         " in mac_retry forwarding mode.\n\n"
251
252                         "set txpkts (x[,y]*)\n"
253                         "    Set the length of each segment of TXONLY"
254                         " and optionally CSUM packets.\n\n"
255
256                         "set txsplit (off|on|rand)\n"
257                         "    Set the split policy for the TX packets."
258                         " Right now only applicable for CSUM and TXONLY"
259                         " modes\n\n"
260
261                         "set corelist (x[,y]*)\n"
262                         "    Set the list of forwarding cores.\n\n"
263
264                         "set portlist (x[,y]*)\n"
265                         "    Set the list of forwarding ports.\n\n"
266
267                         "vlan set strip (on|off) (port_id)\n"
268                         "    Set the VLAN strip on a port.\n\n"
269
270                         "vlan set stripq (on|off) (port_id,queue_id)\n"
271                         "    Set the VLAN strip for a queue on a port.\n\n"
272
273                         "vlan set filter (on|off) (port_id)\n"
274                         "    Set the VLAN filter on a port.\n\n"
275
276                         "vlan set qinq (on|off) (port_id)\n"
277                         "    Set the VLAN QinQ (extended queue in queue)"
278                         " on a port.\n\n"
279
280                         "vlan set (inner|outer) tpid (value) (port_id)\n"
281                         "    Set the VLAN TPID for Packet Filtering on"
282                         " a port\n\n"
283
284                         "rx_vlan add (vlan_id|all) (port_id)\n"
285                         "    Add a vlan_id, or all identifiers, to the set"
286                         " of VLAN identifiers filtered by port_id.\n\n"
287
288                         "rx_vlan rm (vlan_id|all) (port_id)\n"
289                         "    Remove a vlan_id, or all identifiers, from the set"
290                         " of VLAN identifiers filtered by port_id.\n\n"
291
292                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
293                         "    Add a vlan_id, to the set of VLAN identifiers"
294                         "filtered for VF(s) from port_id.\n\n"
295
296                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
297                         "    Remove a vlan_id, to the set of VLAN identifiers"
298                         "filtered for VF(s) from port_id.\n\n"
299
300                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
301                         "(inner_vlan) (vxlan|nvgre) (filter_type) (tenant_id) (queue_id)\n"
302                         "   add a tunnel filter of a port.\n\n"
303
304                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
305                         "(inner_vlan) (vxlan|nvgre) (filter_type) (tenant_id) (queue_id)\n"
306                         "   remove a tunnel filter of a port.\n\n"
307
308                         "rx_vxlan_port add (udp_port) (port_id)\n"
309                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
310
311                         "rx_vxlan_port rm (udp_port) (port_id)\n"
312                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
313
314                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
315                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
316                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
317
318                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
319                         "    Set port based TX VLAN insertion.\n\n"
320
321                         "tx_vlan reset (port_id)\n"
322                         "    Disable hardware insertion of a VLAN header in"
323                         " packets sent on a port.\n\n"
324
325                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
326                         "    Select hardware or software calculation of the"
327                         " checksum when transmitting a packet using the"
328                         " csum forward engine.\n"
329                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
330                         "    outer-ip concerns the outer IP layer in"
331                         " case the packet is recognized as a tunnel packet by"
332                         " the forward engine (vxlan, gre and ipip are supported)\n"
333                         "    Please check the NIC datasheet for HW limits.\n\n"
334
335                         "csum parse-tunnel (on|off) (tx_port_id)\n"
336                         "    If disabled, treat tunnel packets as non-tunneled"
337                         " packets (treat inner headers as payload). The port\n"
338                         "    argument is the port used for TX in csum forward"
339                         " engine.\n\n"
340
341                         "csum show (port_id)\n"
342                         "    Display tx checksum offload configuration\n\n"
343
344                         "tso set (segsize) (portid)\n"
345                         "    Enable TCP Segmentation Offload in csum forward"
346                         " engine.\n"
347                         "    Please check the NIC datasheet for HW limits.\n\n"
348
349                         "tso show (portid)"
350                         "    Display the status of TCP Segmentation Offload.\n\n"
351
352                         "set fwd (%s)\n"
353                         "    Set packet forwarding mode.\n\n"
354
355                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
356                         "    Add a MAC address on port_id.\n\n"
357
358                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
359                         "    Remove a MAC address from port_id.\n\n"
360
361                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
362                         "    Add a MAC address for a VF on the port.\n\n"
363
364                         "set port (port_id) uta (mac_address|all) (on|off)\n"
365                         "    Add/Remove a or all unicast hash filter(s)"
366                         "from port X.\n\n"
367
368                         "set promisc (port_id|all) (on|off)\n"
369                         "    Set the promiscuous mode on port_id, or all.\n\n"
370
371                         "set allmulti (port_id|all) (on|off)\n"
372                         "    Set the allmulti mode on port_id, or all.\n\n"
373
374                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
375                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
376                         " (on|off) autoneg (on|off) (port_id)\n"
377                         "set flow_ctrl rx (on|off) (portid)\n"
378                         "set flow_ctrl tx (on|off) (portid)\n"
379                         "set flow_ctrl high_water (high_water) (portid)\n"
380                         "set flow_ctrl low_water (low_water) (portid)\n"
381                         "set flow_ctrl pause_time (pause_time) (portid)\n"
382                         "set flow_ctrl send_xon (send_xon) (portid)\n"
383                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
384                         "set flow_ctrl autoneg (on|off) (port_id)\n"
385                         "    Set the link flow control parameter on a port.\n\n"
386
387                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
388                         " (low_water) (pause_time) (priority) (port_id)\n"
389                         "    Set the priority flow control parameter on a"
390                         " port.\n\n"
391
392                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
393                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
394                         " queue on port.\n"
395                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
396                         " on port 0 to mapping 5.\n\n"
397
398                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
399                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
400
401                         "set port (port_id) vf (vf_id) (mac_addr)"
402                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
403                         "   Add/Remove unicast or multicast MAC addr filter"
404                         " for a VF.\n\n"
405
406                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
407                         "|MPE) (on|off)\n"
408                         "    AUPE:accepts untagged VLAN;"
409                         "ROPE:accept unicast hash\n\n"
410                         "    BAM:accepts broadcast packets;"
411                         "MPE:accepts all multicast packets\n\n"
412                         "    Enable/Disable a VF receive mode of a port\n\n"
413
414                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
415                         "    Set rate limit for a queue of a port\n\n"
416
417                         "set port (port_id) vf (vf_id) rate (rate_num) "
418                         "queue_mask (queue_mask_value)\n"
419                         "    Set rate limit for queues in VF of a port\n\n"
420
421                         "set port (port_id) mirror-rule (rule_id)"
422                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
423                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
424                         "   Set pool or vlan type mirror rule on a port.\n"
425                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
426                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
427                         " to pool 0.\n\n"
428
429                         "set port (port_id) mirror-rule (rule_id)"
430                         " (uplink-mirror|downlink-mirror) dst-pool"
431                         " (pool_id) (on|off)\n"
432                         "   Set uplink or downlink type mirror rule on a port.\n"
433                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
434                         " 0 on' enable mirror income traffic to pool 0.\n\n"
435
436                         "reset port (port_id) mirror-rule (rule_id)\n"
437                         "   Reset a mirror rule.\n\n"
438
439                         "set flush_rx (on|off)\n"
440                         "   Flush (default) or don't flush RX streams before"
441                         " forwarding. Mainly used with PCAP drivers.\n\n"
442
443                         #ifdef RTE_NIC_BYPASS
444                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
445                         "   Set the bypass mode for the lowest port on bypass enabled"
446                         " NIC.\n\n"
447
448                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
449                         "mode (normal|bypass|isolate) (port_id)\n"
450                         "   Set the event required to initiate specified bypass mode for"
451                         " the lowest port on a bypass enabled NIC where:\n"
452                         "       timeout   = enable bypass after watchdog timeout.\n"
453                         "       os_on     = enable bypass when OS/board is powered on.\n"
454                         "       os_off    = enable bypass when OS/board is powered off.\n"
455                         "       power_on  = enable bypass when power supply is turned on.\n"
456                         "       power_off = enable bypass when power supply is turned off."
457                         "\n\n"
458
459                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
460                         "   Set the bypass watchdog timeout to 'n' seconds"
461                         " where 0 = instant.\n\n"
462
463                         "show bypass config (port_id)\n"
464                         "   Show the bypass configuration for a bypass enabled NIC"
465                         " using the lowest port on the NIC.\n\n"
466 #endif
467 #ifdef RTE_LIBRTE_PMD_BOND
468                         "create bonded device (mode) (socket)\n"
469                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
470
471                         "add bonding slave (slave_id) (port_id)\n"
472                         "       Add a slave device to a bonded device.\n\n"
473
474                         "remove bonding slave (slave_id) (port_id)\n"
475                         "       Remove a slave device from a bonded device.\n\n"
476
477                         "set bonding mode (value) (port_id)\n"
478                         "       Set the bonding mode on a bonded device.\n\n"
479
480                         "set bonding primary (slave_id) (port_id)\n"
481                         "       Set the primary slave for a bonded device.\n\n"
482
483                         "show bonding config (port_id)\n"
484                         "       Show the bonding config for port_id.\n\n"
485
486                         "set bonding mac_addr (port_id) (address)\n"
487                         "       Set the MAC address of a bonded device.\n\n"
488
489                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
490                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
491
492                         "set bonding mon_period (port_id) (value)\n"
493                         "       Set the bonding link status monitoring polling period in ms.\n\n"
494 #endif
495                         "set link-up port (port_id)\n"
496                         "       Set link up for a port.\n\n"
497
498                         "set link-down port (port_id)\n"
499                         "       Set link down for a port.\n\n"
500
501                         , list_pkt_forwarding_modes()
502                 );
503         }
504
505         if (show_all || !strcmp(res->section, "ports")) {
506
507                 cmdline_printf(
508                         cl,
509                         "\n"
510                         "Port Operations:\n"
511                         "----------------\n\n"
512
513                         "port start (port_id|all)\n"
514                         "    Start all ports or port_id.\n\n"
515
516                         "port stop (port_id|all)\n"
517                         "    Stop all ports or port_id.\n\n"
518
519                         "port close (port_id|all)\n"
520                         "    Close all ports or port_id.\n\n"
521
522                         "port attach (ident)\n"
523                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
524
525                         "port detach (port_id)\n"
526                         "    Detach physical or virtual dev by port_id\n\n"
527
528                         "port config (port_id|all)"
529                         " speed (10|100|1000|10000|40000|auto)"
530                         " duplex (half|full|auto)\n"
531                         "    Set speed and duplex for all ports or port_id\n\n"
532
533                         "port config all (rxq|txq|rxd|txd) (value)\n"
534                         "    Set number for rxq/txq/rxd/txd.\n\n"
535
536                         "port config all max-pkt-len (value)\n"
537                         "    Set the max packet length.\n\n"
538
539                         "port config all (crc-strip|rx-cksum|hw-vlan|hw-vlan-filter|"
540                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
541                         " (on|off)\n"
542                         "    Set crc-strip/rx-checksum/hardware-vlan/drop_en"
543                         " for ports.\n\n"
544
545                         "port config all rss (all|ip|tcp|udp|sctp|ether|none)\n"
546                         "    Set the RSS mode.\n\n"
547
548                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
549                         "    Set the RSS redirection table.\n\n"
550
551                         "port config (port_id) dcb vt (on|off) (traffic_class)"
552                         " pfc (on|off)\n"
553                         "    Set the DCB mode.\n\n"
554
555                         "port config all burst (value)\n"
556                         "    Set the number of packets per burst.\n\n"
557
558                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
559                         " (value)\n"
560                         "    Set the ring prefetch/host/writeback threshold"
561                         " for tx/rx queue.\n\n"
562
563                         "port config all (txfreet|txrst|rxfreet) (value)\n"
564                         "    Set free threshold for rx/tx, or set"
565                         " tx rs bit threshold.\n\n"
566                         "port config mtu X value\n"
567                         "    Set the MTU of port X to a given value\n\n"
568
569                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
570                         "    Start/stop a rx/tx queue of port X. Only take effect"
571                         " when port X is started\n\n"
572
573                         "port config (port_id|all) l2-tunnel E-tag ether-type"
574                         " (value)\n"
575                         "    Set the value of E-tag ether-type.\n\n"
576
577                         "port config (port_id|all) l2-tunnel E-tag"
578                         " (enable|disable)\n"
579                         "    Enable/disable the E-tag support.\n\n"
580                 );
581         }
582
583         if (show_all || !strcmp(res->section, "registers")) {
584
585                 cmdline_printf(
586                         cl,
587                         "\n"
588                         "Registers:\n"
589                         "----------\n\n"
590
591                         "read reg (port_id) (address)\n"
592                         "    Display value of a port register.\n\n"
593
594                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
595                         "    Display a port register bit field.\n\n"
596
597                         "read regbit (port_id) (address) (bit_x)\n"
598                         "    Display a single port register bit.\n\n"
599
600                         "write reg (port_id) (address) (value)\n"
601                         "    Set value of a port register.\n\n"
602
603                         "write regfield (port_id) (address) (bit_x) (bit_y)"
604                         " (value)\n"
605                         "    Set bit field of a port register.\n\n"
606
607                         "write regbit (port_id) (address) (bit_x) (value)\n"
608                         "    Set single bit value of a port register.\n\n"
609                 );
610         }
611         if (show_all || !strcmp(res->section, "filters")) {
612
613                 cmdline_printf(
614                         cl,
615                         "\n"
616                         "filters:\n"
617                         "--------\n\n"
618
619                         "ethertype_filter (port_id) (add|del)"
620                         " (mac_addr|mac_ignr) (mac_address) ethertype"
621                         " (ether_type) (drop|fwd) queue (queue_id)\n"
622                         "    Add/Del an ethertype filter.\n\n"
623
624                         "2tuple_filter (port_id) (add|del)"
625                         " dst_port (dst_port_value) protocol (protocol_value)"
626                         " mask (mask_value) tcp_flags (tcp_flags_value)"
627                         " priority (prio_value) queue (queue_id)\n"
628                         "    Add/Del a 2tuple filter.\n\n"
629
630                         "5tuple_filter (port_id) (add|del)"
631                         " dst_ip (dst_address) src_ip (src_address)"
632                         " dst_port (dst_port_value) src_port (src_port_value)"
633                         " protocol (protocol_value)"
634                         " mask (mask_value) tcp_flags (tcp_flags_value)"
635                         " priority (prio_value) queue (queue_id)\n"
636                         "    Add/Del a 5tuple filter.\n\n"
637
638                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
639                         "    Add/Del syn filter.\n\n"
640
641                         "flex_filter (port_id) (add|del) len (len_value)"
642                         " bytes (bytes_value) mask (mask_value)"
643                         " priority (prio_value) queue (queue_id)\n"
644                         "    Add/Del a flex filter.\n\n"
645
646                         "flow_director_filter (port_id) mode IP (add|del|update)"
647                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
648                         " src (src_ip_address) dst (dst_ip_address)"
649                         " vlan (vlan_value) flexbytes (flexbytes_value)"
650                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
651                         " fd_id (fd_id_value)\n"
652                         "    Add/Del an IP type flow director filter.\n\n"
653
654                         "flow_director_filter (port_id) mode IP (add|del|update)"
655                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
656                         " src (src_ip_address) (src_port)"
657                         " dst (dst_ip_address) (dst_port)"
658                         " vlan (vlan_value) flexbytes (flexbytes_value)"
659                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
660                         " fd_id (fd_id_value)\n"
661                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
662
663                         "flow_director_filter (port_id) mode IP (add|del|update)"
664                         " flow (ipv4-sctp|ipv6-sctp)"
665                         " src (src_ip_address) (src_port)"
666                         " dst (dst_ip_address) (dst_port)"
667                         " tag (verification_tag) vlan (vlan_value)"
668                         " flexbytes (flexbytes_value) (drop|fwd)"
669                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
670                         "    Add/Del a SCTP type flow director filter.\n\n"
671
672                         "flow_director_filter (port_id) mode IP (add|del|update)"
673                         " flow l2_payload ether (ethertype)"
674                         " flexbytes (flexbytes_value) (drop|fwd)"
675                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
676                         "    Add/Del a l2 payload type flow director filter.\n\n"
677
678                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
679                         " mac (mac_address) vlan (vlan_value)"
680                         " flexbytes (flexbytes_value) (drop|fwd)"
681                         " queue (queue_id) fd_id (fd_id_value)\n"
682                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
683
684                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
685                         " mac (mac_address) vlan (vlan_value)"
686                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
687                         " flexbytes (flexbytes_value) (drop|fwd)"
688                         " queue (queue_id) fd_id (fd_id_value)\n"
689                         "    Add/Del a Tunnel flow director filter.\n\n"
690
691                         "flush_flow_director (port_id)\n"
692                         "    Flush all flow director entries of a device.\n\n"
693
694                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
695                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
696                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
697                         "    Set flow director IP mask.\n\n"
698
699                         "flow_director_mask (port_id) mode MAC-VLAN"
700                         " vlan (vlan_value) mac (mac_value)\n"
701                         "    Set flow director MAC-VLAN mask.\n\n"
702
703                         "flow_director_mask (port_id) mode Tunnel"
704                         " vlan (vlan_value) mac (mac_value)"
705                         " tunnel-type (tunnel_type_value)"
706                         " tunnel-id (tunnel_id_value)\n"
707                         "    Set flow director Tunnel mask.\n\n"
708
709                         "flow_director_flex_mask (port_id)"
710                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
711                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
712                         " (mask)\n"
713                         "    Configure mask of flex payload.\n\n"
714
715                         "flow_director_flex_payload (port_id)"
716                         " (raw|l2|l3|l4) (config)\n"
717                         "    Configure flex payload selection.\n\n"
718
719                         "get_sym_hash_ena_per_port (port_id)\n"
720                         "    get symmetric hash enable configuration per port.\n\n"
721
722                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
723                         "    set symmetric hash enable configuration per port"
724                         " to enable or disable.\n\n"
725
726                         "get_hash_global_config (port_id)\n"
727                         "    Get the global configurations of hash filters.\n\n"
728
729                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
730                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
731                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
732                         " (enable|disable)\n"
733                         "    Set the global configurations of hash filters.\n\n"
734
735                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
736                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
737                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
738                         "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|"
739                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
740                         "ipv6-next-header|udp-src-port|udp-dst-port|"
741                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
742                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
743                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
744                         "fld-8th|none) (select|add)\n"
745                         "    Set the input set for hash.\n\n"
746
747                         "set_fdir_input_set (port_id) (ipv4|ipv4-frag|"
748                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
749                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
750                         "l2_payload) (src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
751                         "udp-src-port|udp-dst-port|tcp-src-port|tcp-dst-port|"
752                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|fld-1st|"
753                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
754                         "fld-8th|none) (select|add)\n"
755                         "    Set the input set for FDir.\n\n"
756                 );
757         }
758 }
759
760 cmdline_parse_token_string_t cmd_help_long_help =
761         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
762
763 cmdline_parse_token_string_t cmd_help_long_section =
764         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
765                         "all#control#display#config#"
766                         "ports#registers#filters");
767
768 cmdline_parse_inst_t cmd_help_long = {
769         .f = cmd_help_long_parsed,
770         .data = NULL,
771         .help_str = "show help",
772         .tokens = {
773                 (void *)&cmd_help_long_help,
774                 (void *)&cmd_help_long_section,
775                 NULL,
776         },
777 };
778
779
780 /* *** start/stop/close all ports *** */
781 struct cmd_operate_port_result {
782         cmdline_fixed_string_t keyword;
783         cmdline_fixed_string_t name;
784         cmdline_fixed_string_t value;
785 };
786
787 static void cmd_operate_port_parsed(void *parsed_result,
788                                 __attribute__((unused)) struct cmdline *cl,
789                                 __attribute__((unused)) void *data)
790 {
791         struct cmd_operate_port_result *res = parsed_result;
792
793         if (!strcmp(res->name, "start"))
794                 start_port(RTE_PORT_ALL);
795         else if (!strcmp(res->name, "stop"))
796                 stop_port(RTE_PORT_ALL);
797         else if (!strcmp(res->name, "close"))
798                 close_port(RTE_PORT_ALL);
799         else
800                 printf("Unknown parameter\n");
801 }
802
803 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
804         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
805                                                                 "port");
806 cmdline_parse_token_string_t cmd_operate_port_all_port =
807         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
808                                                 "start#stop#close");
809 cmdline_parse_token_string_t cmd_operate_port_all_all =
810         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
811
812 cmdline_parse_inst_t cmd_operate_port = {
813         .f = cmd_operate_port_parsed,
814         .data = NULL,
815         .help_str = "port start|stop|close all: start/stop/close all ports",
816         .tokens = {
817                 (void *)&cmd_operate_port_all_cmd,
818                 (void *)&cmd_operate_port_all_port,
819                 (void *)&cmd_operate_port_all_all,
820                 NULL,
821         },
822 };
823
824 /* *** start/stop/close specific port *** */
825 struct cmd_operate_specific_port_result {
826         cmdline_fixed_string_t keyword;
827         cmdline_fixed_string_t name;
828         uint8_t value;
829 };
830
831 static void cmd_operate_specific_port_parsed(void *parsed_result,
832                         __attribute__((unused)) struct cmdline *cl,
833                                 __attribute__((unused)) void *data)
834 {
835         struct cmd_operate_specific_port_result *res = parsed_result;
836
837         if (!strcmp(res->name, "start"))
838                 start_port(res->value);
839         else if (!strcmp(res->name, "stop"))
840                 stop_port(res->value);
841         else if (!strcmp(res->name, "close"))
842                 close_port(res->value);
843         else
844                 printf("Unknown parameter\n");
845 }
846
847 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
848         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
849                                                         keyword, "port");
850 cmdline_parse_token_string_t cmd_operate_specific_port_port =
851         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
852                                                 name, "start#stop#close");
853 cmdline_parse_token_num_t cmd_operate_specific_port_id =
854         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
855                                                         value, UINT8);
856
857 cmdline_parse_inst_t cmd_operate_specific_port = {
858         .f = cmd_operate_specific_port_parsed,
859         .data = NULL,
860         .help_str = "port start|stop|close X: start/stop/close port X",
861         .tokens = {
862                 (void *)&cmd_operate_specific_port_cmd,
863                 (void *)&cmd_operate_specific_port_port,
864                 (void *)&cmd_operate_specific_port_id,
865                 NULL,
866         },
867 };
868
869 /* *** attach a specified port *** */
870 struct cmd_operate_attach_port_result {
871         cmdline_fixed_string_t port;
872         cmdline_fixed_string_t keyword;
873         cmdline_fixed_string_t identifier;
874 };
875
876 static void cmd_operate_attach_port_parsed(void *parsed_result,
877                                 __attribute__((unused)) struct cmdline *cl,
878                                 __attribute__((unused)) void *data)
879 {
880         struct cmd_operate_attach_port_result *res = parsed_result;
881
882         if (!strcmp(res->keyword, "attach"))
883                 attach_port(res->identifier);
884         else
885                 printf("Unknown parameter\n");
886 }
887
888 cmdline_parse_token_string_t cmd_operate_attach_port_port =
889         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
890                         port, "port");
891 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
892         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
893                         keyword, "attach");
894 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
895         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
896                         identifier, NULL);
897
898 cmdline_parse_inst_t cmd_operate_attach_port = {
899         .f = cmd_operate_attach_port_parsed,
900         .data = NULL,
901         .help_str = "port attach identifier, "
902                 "identifier: pci address or virtual dev name",
903         .tokens = {
904                 (void *)&cmd_operate_attach_port_port,
905                 (void *)&cmd_operate_attach_port_keyword,
906                 (void *)&cmd_operate_attach_port_identifier,
907                 NULL,
908         },
909 };
910
911 /* *** detach a specified port *** */
912 struct cmd_operate_detach_port_result {
913         cmdline_fixed_string_t port;
914         cmdline_fixed_string_t keyword;
915         uint8_t port_id;
916 };
917
918 static void cmd_operate_detach_port_parsed(void *parsed_result,
919                                 __attribute__((unused)) struct cmdline *cl,
920                                 __attribute__((unused)) void *data)
921 {
922         struct cmd_operate_detach_port_result *res = parsed_result;
923
924         if (!strcmp(res->keyword, "detach"))
925                 detach_port(res->port_id);
926         else
927                 printf("Unknown parameter\n");
928 }
929
930 cmdline_parse_token_string_t cmd_operate_detach_port_port =
931         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
932                         port, "port");
933 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
934         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
935                         keyword, "detach");
936 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
937         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
938                         port_id, UINT8);
939
940 cmdline_parse_inst_t cmd_operate_detach_port = {
941         .f = cmd_operate_detach_port_parsed,
942         .data = NULL,
943         .help_str = "port detach port_id",
944         .tokens = {
945                 (void *)&cmd_operate_detach_port_port,
946                 (void *)&cmd_operate_detach_port_keyword,
947                 (void *)&cmd_operate_detach_port_port_id,
948                 NULL,
949         },
950 };
951
952 /* *** configure speed for all ports *** */
953 struct cmd_config_speed_all {
954         cmdline_fixed_string_t port;
955         cmdline_fixed_string_t keyword;
956         cmdline_fixed_string_t all;
957         cmdline_fixed_string_t item1;
958         cmdline_fixed_string_t item2;
959         cmdline_fixed_string_t value1;
960         cmdline_fixed_string_t value2;
961 };
962
963 static void
964 cmd_config_speed_all_parsed(void *parsed_result,
965                         __attribute__((unused)) struct cmdline *cl,
966                         __attribute__((unused)) void *data)
967 {
968         struct cmd_config_speed_all *res = parsed_result;
969         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
970         uint16_t link_duplex = 0;
971         portid_t pid;
972
973         if (!all_ports_stopped()) {
974                 printf("Please stop all ports first\n");
975                 return;
976         }
977
978         if (!strcmp(res->value1, "10"))
979                 link_speed = ETH_LINK_SPEED_10;
980         else if (!strcmp(res->value1, "100"))
981                 link_speed = ETH_LINK_SPEED_100;
982         else if (!strcmp(res->value1, "1000"))
983                 link_speed = ETH_LINK_SPEED_1000;
984         else if (!strcmp(res->value1, "10000"))
985                 link_speed = ETH_LINK_SPEED_10G;
986         else if (!strcmp(res->value1, "40000"))
987                 link_speed = ETH_LINK_SPEED_40G;
988         else if (!strcmp(res->value1, "auto"))
989                 link_speed = ETH_LINK_SPEED_AUTONEG;
990         else {
991                 printf("Unknown parameter\n");
992                 return;
993         }
994
995         if (!strcmp(res->value2, "half"))
996                 link_duplex = ETH_LINK_HALF_DUPLEX;
997         else if (!strcmp(res->value2, "full"))
998                 link_duplex = ETH_LINK_FULL_DUPLEX;
999         else if (!strcmp(res->value2, "auto"))
1000                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
1001         else {
1002                 printf("Unknown parameter\n");
1003                 return;
1004         }
1005
1006         FOREACH_PORT(pid, ports) {
1007                 ports[pid].dev_conf.link_speed = link_speed;
1008                 ports[pid].dev_conf.link_duplex = link_duplex;
1009         }
1010
1011         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1012 }
1013
1014 cmdline_parse_token_string_t cmd_config_speed_all_port =
1015         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1016 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1017         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1018                                                         "config");
1019 cmdline_parse_token_string_t cmd_config_speed_all_all =
1020         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1021 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1022         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1023 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1024         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1025                                                 "10#100#1000#10000#40000#auto");
1026 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1027         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1028 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1029         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1030                                                 "half#full#auto");
1031
1032 cmdline_parse_inst_t cmd_config_speed_all = {
1033         .f = cmd_config_speed_all_parsed,
1034         .data = NULL,
1035         .help_str = "port config all speed 10|100|1000|10000|40000|auto duplex "
1036                                                         "half|full|auto",
1037         .tokens = {
1038                 (void *)&cmd_config_speed_all_port,
1039                 (void *)&cmd_config_speed_all_keyword,
1040                 (void *)&cmd_config_speed_all_all,
1041                 (void *)&cmd_config_speed_all_item1,
1042                 (void *)&cmd_config_speed_all_value1,
1043                 (void *)&cmd_config_speed_all_item2,
1044                 (void *)&cmd_config_speed_all_value2,
1045                 NULL,
1046         },
1047 };
1048
1049 /* *** configure speed for specific port *** */
1050 struct cmd_config_speed_specific {
1051         cmdline_fixed_string_t port;
1052         cmdline_fixed_string_t keyword;
1053         uint8_t id;
1054         cmdline_fixed_string_t item1;
1055         cmdline_fixed_string_t item2;
1056         cmdline_fixed_string_t value1;
1057         cmdline_fixed_string_t value2;
1058 };
1059
1060 static void
1061 cmd_config_speed_specific_parsed(void *parsed_result,
1062                                 __attribute__((unused)) struct cmdline *cl,
1063                                 __attribute__((unused)) void *data)
1064 {
1065         struct cmd_config_speed_specific *res = parsed_result;
1066         uint16_t link_speed = ETH_LINK_SPEED_AUTONEG;
1067         uint16_t link_duplex = 0;
1068
1069         if (!all_ports_stopped()) {
1070                 printf("Please stop all ports first\n");
1071                 return;
1072         }
1073
1074         if (port_id_is_invalid(res->id, ENABLED_WARN))
1075                 return;
1076
1077         if (!strcmp(res->value1, "10"))
1078                 link_speed = ETH_LINK_SPEED_10;
1079         else if (!strcmp(res->value1, "100"))
1080                 link_speed = ETH_LINK_SPEED_100;
1081         else if (!strcmp(res->value1, "1000"))
1082                 link_speed = ETH_LINK_SPEED_1000;
1083         else if (!strcmp(res->value1, "10000"))
1084                 link_speed = ETH_LINK_SPEED_10000;
1085         else if (!strcmp(res->value1, "40000"))
1086                 link_speed = ETH_LINK_SPEED_40G;
1087         else if (!strcmp(res->value1, "auto"))
1088                 link_speed = ETH_LINK_SPEED_AUTONEG;
1089         else {
1090                 printf("Unknown parameter\n");
1091                 return;
1092         }
1093
1094         if (!strcmp(res->value2, "half"))
1095                 link_duplex = ETH_LINK_HALF_DUPLEX;
1096         else if (!strcmp(res->value2, "full"))
1097                 link_duplex = ETH_LINK_FULL_DUPLEX;
1098         else if (!strcmp(res->value2, "auto"))
1099                 link_duplex = ETH_LINK_AUTONEG_DUPLEX;
1100         else {
1101                 printf("Unknown parameter\n");
1102                 return;
1103         }
1104
1105         ports[res->id].dev_conf.link_speed = link_speed;
1106         ports[res->id].dev_conf.link_duplex = link_duplex;
1107
1108         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1109 }
1110
1111
1112 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1113         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1114                                                                 "port");
1115 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1116         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1117                                                                 "config");
1118 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1119         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1120 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1121         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1122                                                                 "speed");
1123 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1124         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1125                                                 "10#100#1000#10000#40000#auto");
1126 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1127         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1128                                                                 "duplex");
1129 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1130         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1131                                                         "half#full#auto");
1132
1133 cmdline_parse_inst_t cmd_config_speed_specific = {
1134         .f = cmd_config_speed_specific_parsed,
1135         .data = NULL,
1136         .help_str = "port config X speed 10|100|1000|10000|40000|auto duplex "
1137                                                         "half|full|auto",
1138         .tokens = {
1139                 (void *)&cmd_config_speed_specific_port,
1140                 (void *)&cmd_config_speed_specific_keyword,
1141                 (void *)&cmd_config_speed_specific_id,
1142                 (void *)&cmd_config_speed_specific_item1,
1143                 (void *)&cmd_config_speed_specific_value1,
1144                 (void *)&cmd_config_speed_specific_item2,
1145                 (void *)&cmd_config_speed_specific_value2,
1146                 NULL,
1147         },
1148 };
1149
1150 /* *** configure txq/rxq, txd/rxd *** */
1151 struct cmd_config_rx_tx {
1152         cmdline_fixed_string_t port;
1153         cmdline_fixed_string_t keyword;
1154         cmdline_fixed_string_t all;
1155         cmdline_fixed_string_t name;
1156         uint16_t value;
1157 };
1158
1159 static void
1160 cmd_config_rx_tx_parsed(void *parsed_result,
1161                         __attribute__((unused)) struct cmdline *cl,
1162                         __attribute__((unused)) void *data)
1163 {
1164         struct cmd_config_rx_tx *res = parsed_result;
1165
1166         if (!all_ports_stopped()) {
1167                 printf("Please stop all ports first\n");
1168                 return;
1169         }
1170
1171         if (!strcmp(res->name, "rxq")) {
1172                 if (res->value <= 0) {
1173                         printf("rxq %d invalid - must be > 0\n", res->value);
1174                         return;
1175                 }
1176                 nb_rxq = res->value;
1177         }
1178         else if (!strcmp(res->name, "txq")) {
1179                 if (res->value <= 0) {
1180                         printf("txq %d invalid - must be > 0\n", res->value);
1181                         return;
1182                 }
1183                 nb_txq = res->value;
1184         }
1185         else if (!strcmp(res->name, "rxd")) {
1186                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1187                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1188                                         res->value, RTE_TEST_RX_DESC_MAX);
1189                         return;
1190                 }
1191                 nb_rxd = res->value;
1192         } else if (!strcmp(res->name, "txd")) {
1193                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1194                         printf("txd %d invalid - must be > 0 && <= %d\n",
1195                                         res->value, RTE_TEST_TX_DESC_MAX);
1196                         return;
1197                 }
1198                 nb_txd = res->value;
1199         } else {
1200                 printf("Unknown parameter\n");
1201                 return;
1202         }
1203
1204         init_port_config();
1205
1206         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1207 }
1208
1209 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1210         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1211 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1212         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1213 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1214         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1215 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1216         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1217                                                 "rxq#txq#rxd#txd");
1218 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1219         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1220
1221 cmdline_parse_inst_t cmd_config_rx_tx = {
1222         .f = cmd_config_rx_tx_parsed,
1223         .data = NULL,
1224         .help_str = "port config all rxq|txq|rxd|txd value",
1225         .tokens = {
1226                 (void *)&cmd_config_rx_tx_port,
1227                 (void *)&cmd_config_rx_tx_keyword,
1228                 (void *)&cmd_config_rx_tx_all,
1229                 (void *)&cmd_config_rx_tx_name,
1230                 (void *)&cmd_config_rx_tx_value,
1231                 NULL,
1232         },
1233 };
1234
1235 /* *** config max packet length *** */
1236 struct cmd_config_max_pkt_len_result {
1237         cmdline_fixed_string_t port;
1238         cmdline_fixed_string_t keyword;
1239         cmdline_fixed_string_t all;
1240         cmdline_fixed_string_t name;
1241         uint32_t value;
1242 };
1243
1244 static void
1245 cmd_config_max_pkt_len_parsed(void *parsed_result,
1246                                 __attribute__((unused)) struct cmdline *cl,
1247                                 __attribute__((unused)) void *data)
1248 {
1249         struct cmd_config_max_pkt_len_result *res = parsed_result;
1250
1251         if (!all_ports_stopped()) {
1252                 printf("Please stop all ports first\n");
1253                 return;
1254         }
1255
1256         if (!strcmp(res->name, "max-pkt-len")) {
1257                 if (res->value < ETHER_MIN_LEN) {
1258                         printf("max-pkt-len can not be less than %d\n",
1259                                                         ETHER_MIN_LEN);
1260                         return;
1261                 }
1262                 if (res->value == rx_mode.max_rx_pkt_len)
1263                         return;
1264
1265                 rx_mode.max_rx_pkt_len = res->value;
1266                 if (res->value > ETHER_MAX_LEN)
1267                         rx_mode.jumbo_frame = 1;
1268                 else
1269                         rx_mode.jumbo_frame = 0;
1270         } else {
1271                 printf("Unknown parameter\n");
1272                 return;
1273         }
1274
1275         init_port_config();
1276
1277         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1278 }
1279
1280 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1281         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1282                                                                 "port");
1283 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1284         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1285                                                                 "config");
1286 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1287         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1288                                                                 "all");
1289 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1290         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1291                                                                 "max-pkt-len");
1292 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1293         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1294                                                                 UINT32);
1295
1296 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1297         .f = cmd_config_max_pkt_len_parsed,
1298         .data = NULL,
1299         .help_str = "port config all max-pkt-len value",
1300         .tokens = {
1301                 (void *)&cmd_config_max_pkt_len_port,
1302                 (void *)&cmd_config_max_pkt_len_keyword,
1303                 (void *)&cmd_config_max_pkt_len_all,
1304                 (void *)&cmd_config_max_pkt_len_name,
1305                 (void *)&cmd_config_max_pkt_len_value,
1306                 NULL,
1307         },
1308 };
1309
1310 /* *** configure port MTU *** */
1311 struct cmd_config_mtu_result {
1312         cmdline_fixed_string_t port;
1313         cmdline_fixed_string_t keyword;
1314         cmdline_fixed_string_t mtu;
1315         uint8_t port_id;
1316         uint16_t value;
1317 };
1318
1319 static void
1320 cmd_config_mtu_parsed(void *parsed_result,
1321                       __attribute__((unused)) struct cmdline *cl,
1322                       __attribute__((unused)) void *data)
1323 {
1324         struct cmd_config_mtu_result *res = parsed_result;
1325
1326         if (res->value < ETHER_MIN_LEN) {
1327                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1328                 return;
1329         }
1330         port_mtu_set(res->port_id, res->value);
1331 }
1332
1333 cmdline_parse_token_string_t cmd_config_mtu_port =
1334         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1335                                  "port");
1336 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1337         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1338                                  "config");
1339 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1340         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1341                                  "mtu");
1342 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1343         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8);
1344 cmdline_parse_token_num_t cmd_config_mtu_value =
1345         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1346
1347 cmdline_parse_inst_t cmd_config_mtu = {
1348         .f = cmd_config_mtu_parsed,
1349         .data = NULL,
1350         .help_str = "port config mtu value",
1351         .tokens = {
1352                 (void *)&cmd_config_mtu_port,
1353                 (void *)&cmd_config_mtu_keyword,
1354                 (void *)&cmd_config_mtu_mtu,
1355                 (void *)&cmd_config_mtu_port_id,
1356                 (void *)&cmd_config_mtu_value,
1357                 NULL,
1358         },
1359 };
1360
1361 /* *** configure rx mode *** */
1362 struct cmd_config_rx_mode_flag {
1363         cmdline_fixed_string_t port;
1364         cmdline_fixed_string_t keyword;
1365         cmdline_fixed_string_t all;
1366         cmdline_fixed_string_t name;
1367         cmdline_fixed_string_t value;
1368 };
1369
1370 static void
1371 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1372                                 __attribute__((unused)) struct cmdline *cl,
1373                                 __attribute__((unused)) void *data)
1374 {
1375         struct cmd_config_rx_mode_flag *res = parsed_result;
1376
1377         if (!all_ports_stopped()) {
1378                 printf("Please stop all ports first\n");
1379                 return;
1380         }
1381
1382         if (!strcmp(res->name, "crc-strip")) {
1383                 if (!strcmp(res->value, "on"))
1384                         rx_mode.hw_strip_crc = 1;
1385                 else if (!strcmp(res->value, "off"))
1386                         rx_mode.hw_strip_crc = 0;
1387                 else {
1388                         printf("Unknown parameter\n");
1389                         return;
1390                 }
1391         } else if (!strcmp(res->name, "rx-cksum")) {
1392                 if (!strcmp(res->value, "on"))
1393                         rx_mode.hw_ip_checksum = 1;
1394                 else if (!strcmp(res->value, "off"))
1395                         rx_mode.hw_ip_checksum = 0;
1396                 else {
1397                         printf("Unknown parameter\n");
1398                         return;
1399                 }
1400         } else if (!strcmp(res->name, "hw-vlan")) {
1401                 if (!strcmp(res->value, "on")) {
1402                         rx_mode.hw_vlan_filter = 1;
1403                         rx_mode.hw_vlan_strip  = 1;
1404                 }
1405                 else if (!strcmp(res->value, "off")) {
1406                         rx_mode.hw_vlan_filter = 0;
1407                         rx_mode.hw_vlan_strip  = 0;
1408                 }
1409                 else {
1410                         printf("Unknown parameter\n");
1411                         return;
1412                 }
1413         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1414                 if (!strcmp(res->value, "on"))
1415                         rx_mode.hw_vlan_filter = 1;
1416                 else if (!strcmp(res->value, "off"))
1417                         rx_mode.hw_vlan_filter = 0;
1418                 else {
1419                         printf("Unknown parameter\n");
1420                         return;
1421                 }
1422         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1423                 if (!strcmp(res->value, "on"))
1424                         rx_mode.hw_vlan_strip  = 1;
1425                 else if (!strcmp(res->value, "off"))
1426                         rx_mode.hw_vlan_strip  = 0;
1427                 else {
1428                         printf("Unknown parameter\n");
1429                         return;
1430                 }
1431         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1432                 if (!strcmp(res->value, "on"))
1433                         rx_mode.hw_vlan_extend = 1;
1434                 else if (!strcmp(res->value, "off"))
1435                         rx_mode.hw_vlan_extend = 0;
1436                 else {
1437                         printf("Unknown parameter\n");
1438                         return;
1439                 }
1440         } else if (!strcmp(res->name, "drop-en")) {
1441                 if (!strcmp(res->value, "on"))
1442                         rx_drop_en = 1;
1443                 else if (!strcmp(res->value, "off"))
1444                         rx_drop_en = 0;
1445                 else {
1446                         printf("Unknown parameter\n");
1447                         return;
1448                 }
1449         } else {
1450                 printf("Unknown parameter\n");
1451                 return;
1452         }
1453
1454         init_port_config();
1455
1456         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1457 }
1458
1459 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1460         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1461 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1462         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1463                                                                 "config");
1464 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1465         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1466 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1467         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1468                                         "crc-strip#rx-cksum#hw-vlan#"
1469                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1470 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1471         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1472                                                         "on#off");
1473
1474 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1475         .f = cmd_config_rx_mode_flag_parsed,
1476         .data = NULL,
1477         .help_str = "port config all crc-strip|rx-cksum|hw-vlan|"
1478                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1479         .tokens = {
1480                 (void *)&cmd_config_rx_mode_flag_port,
1481                 (void *)&cmd_config_rx_mode_flag_keyword,
1482                 (void *)&cmd_config_rx_mode_flag_all,
1483                 (void *)&cmd_config_rx_mode_flag_name,
1484                 (void *)&cmd_config_rx_mode_flag_value,
1485                 NULL,
1486         },
1487 };
1488
1489 /* *** configure rss *** */
1490 struct cmd_config_rss {
1491         cmdline_fixed_string_t port;
1492         cmdline_fixed_string_t keyword;
1493         cmdline_fixed_string_t all;
1494         cmdline_fixed_string_t name;
1495         cmdline_fixed_string_t value;
1496 };
1497
1498 static void
1499 cmd_config_rss_parsed(void *parsed_result,
1500                         __attribute__((unused)) struct cmdline *cl,
1501                         __attribute__((unused)) void *data)
1502 {
1503         struct cmd_config_rss *res = parsed_result;
1504         struct rte_eth_rss_conf rss_conf;
1505         uint8_t i;
1506
1507         if (!strcmp(res->value, "all"))
1508                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1509                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1510                                         ETH_RSS_L2_PAYLOAD;
1511         else if (!strcmp(res->value, "ip"))
1512                 rss_conf.rss_hf = ETH_RSS_IP;
1513         else if (!strcmp(res->value, "udp"))
1514                 rss_conf.rss_hf = ETH_RSS_UDP;
1515         else if (!strcmp(res->value, "tcp"))
1516                 rss_conf.rss_hf = ETH_RSS_TCP;
1517         else if (!strcmp(res->value, "sctp"))
1518                 rss_conf.rss_hf = ETH_RSS_SCTP;
1519         else if (!strcmp(res->value, "ether"))
1520                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1521         else if (!strcmp(res->value, "none"))
1522                 rss_conf.rss_hf = 0;
1523         else {
1524                 printf("Unknown parameter\n");
1525                 return;
1526         }
1527         rss_conf.rss_key = NULL;
1528         for (i = 0; i < rte_eth_dev_count(); i++)
1529                 rte_eth_dev_rss_hash_update(i, &rss_conf);
1530 }
1531
1532 cmdline_parse_token_string_t cmd_config_rss_port =
1533         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1534 cmdline_parse_token_string_t cmd_config_rss_keyword =
1535         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1536 cmdline_parse_token_string_t cmd_config_rss_all =
1537         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1538 cmdline_parse_token_string_t cmd_config_rss_name =
1539         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1540 cmdline_parse_token_string_t cmd_config_rss_value =
1541         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value,
1542                 "all#ip#tcp#udp#sctp#ether#none");
1543
1544 cmdline_parse_inst_t cmd_config_rss = {
1545         .f = cmd_config_rss_parsed,
1546         .data = NULL,
1547         .help_str = "port config all rss all|ip|tcp|udp|sctp|ether|none",
1548         .tokens = {
1549                 (void *)&cmd_config_rss_port,
1550                 (void *)&cmd_config_rss_keyword,
1551                 (void *)&cmd_config_rss_all,
1552                 (void *)&cmd_config_rss_name,
1553                 (void *)&cmd_config_rss_value,
1554                 NULL,
1555         },
1556 };
1557
1558 /* *** configure rss hash key *** */
1559 struct cmd_config_rss_hash_key {
1560         cmdline_fixed_string_t port;
1561         cmdline_fixed_string_t config;
1562         uint8_t port_id;
1563         cmdline_fixed_string_t rss_hash_key;
1564         cmdline_fixed_string_t rss_type;
1565         cmdline_fixed_string_t key;
1566 };
1567
1568 #define RSS_HASH_KEY_LENGTH 40
1569 static uint8_t
1570 hexa_digit_to_value(char hexa_digit)
1571 {
1572         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1573                 return (uint8_t) (hexa_digit - '0');
1574         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1575                 return (uint8_t) ((hexa_digit - 'a') + 10);
1576         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1577                 return (uint8_t) ((hexa_digit - 'A') + 10);
1578         /* Invalid hexa digit */
1579         return 0xFF;
1580 }
1581
1582 static uint8_t
1583 parse_and_check_key_hexa_digit(char *key, int idx)
1584 {
1585         uint8_t hexa_v;
1586
1587         hexa_v = hexa_digit_to_value(key[idx]);
1588         if (hexa_v == 0xFF)
1589                 printf("invalid key: character %c at position %d is not a "
1590                        "valid hexa digit\n", key[idx], idx);
1591         return hexa_v;
1592 }
1593
1594 static void
1595 cmd_config_rss_hash_key_parsed(void *parsed_result,
1596                                __attribute__((unused)) struct cmdline *cl,
1597                                __attribute__((unused)) void *data)
1598 {
1599         struct cmd_config_rss_hash_key *res = parsed_result;
1600         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1601         uint8_t xdgt0;
1602         uint8_t xdgt1;
1603         int i;
1604
1605         /* Check the length of the RSS hash key */
1606         if (strlen(res->key) != (RSS_HASH_KEY_LENGTH * 2)) {
1607                 printf("key length: %d invalid - key must be a string of %d"
1608                        "hexa-decimal numbers\n", (int) strlen(res->key),
1609                        RSS_HASH_KEY_LENGTH * 2);
1610                 return;
1611         }
1612         /* Translate RSS hash key into binary representation */
1613         for (i = 0; i < RSS_HASH_KEY_LENGTH; i++) {
1614                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1615                 if (xdgt0 == 0xFF)
1616                         return;
1617                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1618                 if (xdgt1 == 0xFF)
1619                         return;
1620                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
1621         }
1622         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
1623                                  RSS_HASH_KEY_LENGTH);
1624 }
1625
1626 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
1627         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
1628 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
1629         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
1630                                  "config");
1631 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
1632         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8);
1633 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
1635                                  rss_hash_key, "rss-hash-key");
1636 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
1638                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
1639                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
1640                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
1641                                  "ipv6-tcp-ex#ipv6-udp-ex");
1642 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
1643         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
1644
1645 cmdline_parse_inst_t cmd_config_rss_hash_key = {
1646         .f = cmd_config_rss_hash_key_parsed,
1647         .data = NULL,
1648         .help_str =
1649                 "port config X rss-hash-key ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
1650                 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|"
1651                 "ipv6-sctp|ipv6-other|l2-payload|"
1652                 "ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex 80 hexa digits\n",
1653         .tokens = {
1654                 (void *)&cmd_config_rss_hash_key_port,
1655                 (void *)&cmd_config_rss_hash_key_config,
1656                 (void *)&cmd_config_rss_hash_key_port_id,
1657                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
1658                 (void *)&cmd_config_rss_hash_key_rss_type,
1659                 (void *)&cmd_config_rss_hash_key_value,
1660                 NULL,
1661         },
1662 };
1663
1664 /* *** configure port rxq/txq start/stop *** */
1665 struct cmd_config_rxtx_queue {
1666         cmdline_fixed_string_t port;
1667         uint8_t portid;
1668         cmdline_fixed_string_t rxtxq;
1669         uint16_t qid;
1670         cmdline_fixed_string_t opname;
1671 };
1672
1673 static void
1674 cmd_config_rxtx_queue_parsed(void *parsed_result,
1675                         __attribute__((unused)) struct cmdline *cl,
1676                         __attribute__((unused)) void *data)
1677 {
1678         struct cmd_config_rxtx_queue *res = parsed_result;
1679         uint8_t isrx;
1680         uint8_t isstart;
1681         int ret = 0;
1682
1683         if (test_done == 0) {
1684                 printf("Please stop forwarding first\n");
1685                 return;
1686         }
1687
1688         if (port_id_is_invalid(res->portid, ENABLED_WARN))
1689                 return;
1690
1691         if (port_is_started(res->portid) != 1) {
1692                 printf("Please start port %u first\n", res->portid);
1693                 return;
1694         }
1695
1696         if (!strcmp(res->rxtxq, "rxq"))
1697                 isrx = 1;
1698         else if (!strcmp(res->rxtxq, "txq"))
1699                 isrx = 0;
1700         else {
1701                 printf("Unknown parameter\n");
1702                 return;
1703         }
1704
1705         if (isrx && rx_queue_id_is_invalid(res->qid))
1706                 return;
1707         else if (!isrx && tx_queue_id_is_invalid(res->qid))
1708                 return;
1709
1710         if (!strcmp(res->opname, "start"))
1711                 isstart = 1;
1712         else if (!strcmp(res->opname, "stop"))
1713                 isstart = 0;
1714         else {
1715                 printf("Unknown parameter\n");
1716                 return;
1717         }
1718
1719         if (isstart && isrx)
1720                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
1721         else if (!isstart && isrx)
1722                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
1723         else if (isstart && !isrx)
1724                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
1725         else
1726                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
1727
1728         if (ret == -ENOTSUP)
1729                 printf("Function not supported in PMD driver\n");
1730 }
1731
1732 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
1733         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
1734 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
1735         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8);
1736 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
1737         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
1738 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
1739         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
1740 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
1741         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
1742                                                 "start#stop");
1743
1744 cmdline_parse_inst_t cmd_config_rxtx_queue = {
1745         .f = cmd_config_rxtx_queue_parsed,
1746         .data = NULL,
1747         .help_str = "port X rxq|txq ID start|stop",
1748         .tokens = {
1749                 (void *)&cmd_config_speed_all_port,
1750                 (void *)&cmd_config_rxtx_queue_portid,
1751                 (void *)&cmd_config_rxtx_queue_rxtxq,
1752                 (void *)&cmd_config_rxtx_queue_qid,
1753                 (void *)&cmd_config_rxtx_queue_opname,
1754                 NULL,
1755         },
1756 };
1757
1758 /* *** Configure RSS RETA *** */
1759 struct cmd_config_rss_reta {
1760         cmdline_fixed_string_t port;
1761         cmdline_fixed_string_t keyword;
1762         uint8_t port_id;
1763         cmdline_fixed_string_t name;
1764         cmdline_fixed_string_t list_name;
1765         cmdline_fixed_string_t list_of_items;
1766 };
1767
1768 static int
1769 parse_reta_config(const char *str,
1770                   struct rte_eth_rss_reta_entry64 *reta_conf,
1771                   uint16_t nb_entries)
1772 {
1773         int i;
1774         unsigned size;
1775         uint16_t hash_index, idx, shift;
1776         uint16_t nb_queue;
1777         char s[256];
1778         const char *p, *p0 = str;
1779         char *end;
1780         enum fieldnames {
1781                 FLD_HASH_INDEX = 0,
1782                 FLD_QUEUE,
1783                 _NUM_FLD
1784         };
1785         unsigned long int_fld[_NUM_FLD];
1786         char *str_fld[_NUM_FLD];
1787
1788         while ((p = strchr(p0,'(')) != NULL) {
1789                 ++p;
1790                 if((p0 = strchr(p,')')) == NULL)
1791                         return -1;
1792
1793                 size = p0 - p;
1794                 if(size >= sizeof(s))
1795                         return -1;
1796
1797                 snprintf(s, sizeof(s), "%.*s", size, p);
1798                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
1799                         return -1;
1800                 for (i = 0; i < _NUM_FLD; i++) {
1801                         errno = 0;
1802                         int_fld[i] = strtoul(str_fld[i], &end, 0);
1803                         if (errno != 0 || end == str_fld[i] ||
1804                                         int_fld[i] > 65535)
1805                                 return -1;
1806                 }
1807
1808                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
1809                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
1810
1811                 if (hash_index >= nb_entries) {
1812                         printf("Invalid RETA hash index=%d\n", hash_index);
1813                         return -1;
1814                 }
1815
1816                 idx = hash_index / RTE_RETA_GROUP_SIZE;
1817                 shift = hash_index % RTE_RETA_GROUP_SIZE;
1818                 reta_conf[idx].mask |= (1ULL << shift);
1819                 reta_conf[idx].reta[shift] = nb_queue;
1820         }
1821
1822         return 0;
1823 }
1824
1825 static void
1826 cmd_set_rss_reta_parsed(void *parsed_result,
1827                         __attribute__((unused)) struct cmdline *cl,
1828                         __attribute__((unused)) void *data)
1829 {
1830         int ret;
1831         struct rte_eth_dev_info dev_info;
1832         struct rte_eth_rss_reta_entry64 reta_conf[8];
1833         struct cmd_config_rss_reta *res = parsed_result;
1834
1835         memset(&dev_info, 0, sizeof(dev_info));
1836         rte_eth_dev_info_get(res->port_id, &dev_info);
1837         if (dev_info.reta_size == 0) {
1838                 printf("Redirection table size is 0 which is "
1839                                         "invalid for RSS\n");
1840                 return;
1841         } else
1842                 printf("The reta size of port %d is %u\n",
1843                         res->port_id, dev_info.reta_size);
1844         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
1845                 printf("Currently do not support more than %u entries of "
1846                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
1847                 return;
1848         }
1849
1850         memset(reta_conf, 0, sizeof(reta_conf));
1851         if (!strcmp(res->list_name, "reta")) {
1852                 if (parse_reta_config(res->list_of_items, reta_conf,
1853                                                 dev_info.reta_size)) {
1854                         printf("Invalid RSS Redirection Table "
1855                                         "config entered\n");
1856                         return;
1857                 }
1858                 ret = rte_eth_dev_rss_reta_update(res->port_id,
1859                                 reta_conf, dev_info.reta_size);
1860                 if (ret != 0)
1861                         printf("Bad redirection table parameter, "
1862                                         "return code = %d \n", ret);
1863         }
1864 }
1865
1866 cmdline_parse_token_string_t cmd_config_rss_reta_port =
1867         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
1868 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
1869         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
1870 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
1871         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8);
1872 cmdline_parse_token_string_t cmd_config_rss_reta_name =
1873         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
1874 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
1875         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
1876 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
1877         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
1878                                  NULL);
1879 cmdline_parse_inst_t cmd_config_rss_reta = {
1880         .f = cmd_set_rss_reta_parsed,
1881         .data = NULL,
1882         .help_str = "port config X rss reta (hash,queue)[,(hash,queue)]",
1883         .tokens = {
1884                 (void *)&cmd_config_rss_reta_port,
1885                 (void *)&cmd_config_rss_reta_keyword,
1886                 (void *)&cmd_config_rss_reta_port_id,
1887                 (void *)&cmd_config_rss_reta_name,
1888                 (void *)&cmd_config_rss_reta_list_name,
1889                 (void *)&cmd_config_rss_reta_list_of_items,
1890                 NULL,
1891         },
1892 };
1893
1894 /* *** SHOW PORT RETA INFO *** */
1895 struct cmd_showport_reta {
1896         cmdline_fixed_string_t show;
1897         cmdline_fixed_string_t port;
1898         uint8_t port_id;
1899         cmdline_fixed_string_t rss;
1900         cmdline_fixed_string_t reta;
1901         uint16_t size;
1902         cmdline_fixed_string_t list_of_items;
1903 };
1904
1905 static int
1906 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
1907                            uint16_t nb_entries,
1908                            char *str)
1909 {
1910         uint32_t size;
1911         const char *p, *p0 = str;
1912         char s[256];
1913         char *end;
1914         char *str_fld[8];
1915         uint16_t i, num = nb_entries / RTE_RETA_GROUP_SIZE;
1916         int ret;
1917
1918         p = strchr(p0, '(');
1919         if (p == NULL)
1920                 return -1;
1921         p++;
1922         p0 = strchr(p, ')');
1923         if (p0 == NULL)
1924                 return -1;
1925         size = p0 - p;
1926         if (size >= sizeof(s)) {
1927                 printf("The string size exceeds the internal buffer size\n");
1928                 return -1;
1929         }
1930         snprintf(s, sizeof(s), "%.*s", size, p);
1931         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
1932         if (ret <= 0 || ret != num) {
1933                 printf("The bits of masks do not match the number of "
1934                                         "reta entries: %u\n", num);
1935                 return -1;
1936         }
1937         for (i = 0; i < ret; i++)
1938                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
1939
1940         return 0;
1941 }
1942
1943 static void
1944 cmd_showport_reta_parsed(void *parsed_result,
1945                          __attribute__((unused)) struct cmdline *cl,
1946                          __attribute__((unused)) void *data)
1947 {
1948         struct cmd_showport_reta *res = parsed_result;
1949         struct rte_eth_rss_reta_entry64 reta_conf[8];
1950         struct rte_eth_dev_info dev_info;
1951
1952         memset(&dev_info, 0, sizeof(dev_info));
1953         rte_eth_dev_info_get(res->port_id, &dev_info);
1954         if (dev_info.reta_size == 0 || res->size != dev_info.reta_size ||
1955                                 res->size > ETH_RSS_RETA_SIZE_512) {
1956                 printf("Invalid redirection table size: %u\n", res->size);
1957                 return;
1958         }
1959
1960         memset(reta_conf, 0, sizeof(reta_conf));
1961         if (showport_parse_reta_config(reta_conf, res->size,
1962                                 res->list_of_items) < 0) {
1963                 printf("Invalid string: %s for reta masks\n",
1964                                         res->list_of_items);
1965                 return;
1966         }
1967         port_rss_reta_info(res->port_id, reta_conf, res->size);
1968 }
1969
1970 cmdline_parse_token_string_t cmd_showport_reta_show =
1971         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
1972 cmdline_parse_token_string_t cmd_showport_reta_port =
1973         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
1974 cmdline_parse_token_num_t cmd_showport_reta_port_id =
1975         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8);
1976 cmdline_parse_token_string_t cmd_showport_reta_rss =
1977         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
1978 cmdline_parse_token_string_t cmd_showport_reta_reta =
1979         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
1980 cmdline_parse_token_num_t cmd_showport_reta_size =
1981         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
1982 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
1983         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
1984                                         list_of_items, NULL);
1985
1986 cmdline_parse_inst_t cmd_showport_reta = {
1987         .f = cmd_showport_reta_parsed,
1988         .data = NULL,
1989         .help_str = "show port X rss reta (size) (mask0,mask1,...)",
1990         .tokens = {
1991                 (void *)&cmd_showport_reta_show,
1992                 (void *)&cmd_showport_reta_port,
1993                 (void *)&cmd_showport_reta_port_id,
1994                 (void *)&cmd_showport_reta_rss,
1995                 (void *)&cmd_showport_reta_reta,
1996                 (void *)&cmd_showport_reta_size,
1997                 (void *)&cmd_showport_reta_list_of_items,
1998                 NULL,
1999         },
2000 };
2001
2002 /* *** Show RSS hash configuration *** */
2003 struct cmd_showport_rss_hash {
2004         cmdline_fixed_string_t show;
2005         cmdline_fixed_string_t port;
2006         uint8_t port_id;
2007         cmdline_fixed_string_t rss_hash;
2008         cmdline_fixed_string_t rss_type;
2009         cmdline_fixed_string_t key; /* optional argument */
2010 };
2011
2012 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2013                                 __attribute__((unused)) struct cmdline *cl,
2014                                 void *show_rss_key)
2015 {
2016         struct cmd_showport_rss_hash *res = parsed_result;
2017
2018         port_rss_hash_conf_show(res->port_id, res->rss_type,
2019                                 show_rss_key != NULL);
2020 }
2021
2022 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2023         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2024 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2025         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2026 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2027         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8);
2028 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2029         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2030                                  "rss-hash");
2031 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2032         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2033                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2034                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2035                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2036                                  "ipv6-tcp-ex#ipv6-udp-ex");
2037 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2038         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2039
2040 cmdline_parse_inst_t cmd_showport_rss_hash = {
2041         .f = cmd_showport_rss_hash_parsed,
2042         .data = NULL,
2043         .help_str =
2044                 "show port X rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
2045                 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|"
2046                 "ipv6-sctp|ipv6-other|l2-payload|"
2047                 "ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex (X = port number)\n",
2048         .tokens = {
2049                 (void *)&cmd_showport_rss_hash_show,
2050                 (void *)&cmd_showport_rss_hash_port,
2051                 (void *)&cmd_showport_rss_hash_port_id,
2052                 (void *)&cmd_showport_rss_hash_rss_hash,
2053                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2054                 NULL,
2055         },
2056 };
2057
2058 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2059         .f = cmd_showport_rss_hash_parsed,
2060         .data = (void *)1,
2061         .help_str =
2062                 "show port X rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
2063                 "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|"
2064                 "ipv6-sctp|ipv6-other|l2-payload|"
2065                 "ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key (X = port number)\n",
2066         .tokens = {
2067                 (void *)&cmd_showport_rss_hash_show,
2068                 (void *)&cmd_showport_rss_hash_port,
2069                 (void *)&cmd_showport_rss_hash_port_id,
2070                 (void *)&cmd_showport_rss_hash_rss_hash,
2071                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2072                 (void *)&cmd_showport_rss_hash_rss_key,
2073                 NULL,
2074         },
2075 };
2076
2077 /* *** Configure DCB *** */
2078 struct cmd_config_dcb {
2079         cmdline_fixed_string_t port;
2080         cmdline_fixed_string_t config;
2081         uint8_t port_id;
2082         cmdline_fixed_string_t dcb;
2083         cmdline_fixed_string_t vt;
2084         cmdline_fixed_string_t vt_en;
2085         uint8_t num_tcs;
2086         cmdline_fixed_string_t pfc;
2087         cmdline_fixed_string_t pfc_en;
2088 };
2089
2090 static void
2091 cmd_config_dcb_parsed(void *parsed_result,
2092                         __attribute__((unused)) struct cmdline *cl,
2093                         __attribute__((unused)) void *data)
2094 {
2095         struct cmd_config_dcb *res = parsed_result;
2096         portid_t port_id = res->port_id;
2097         struct rte_port *port;
2098         uint8_t pfc_en;
2099         int ret;
2100
2101         port = &ports[port_id];
2102         /** Check if the port is not started **/
2103         if (port->port_status != RTE_PORT_STOPPED) {
2104                 printf("Please stop port %d first\n", port_id);
2105                 return;
2106         }
2107
2108         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2109                 printf("The invalid number of traffic class,"
2110                         " only 4 or 8 allowed.\n");
2111                 return;
2112         }
2113
2114         if (nb_fwd_lcores < res->num_tcs) {
2115                 printf("nb_cores shouldn't be less than number of TCs.\n");
2116                 return;
2117         }
2118         if (!strncmp(res->pfc_en, "on", 2))
2119                 pfc_en = 1;
2120         else
2121                 pfc_en = 0;
2122
2123         /* DCB in VT mode */
2124         if (!strncmp(res->vt_en, "on", 2))
2125                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2126                                 (enum rte_eth_nb_tcs)res->num_tcs,
2127                                 pfc_en);
2128         else
2129                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2130                                 (enum rte_eth_nb_tcs)res->num_tcs,
2131                                 pfc_en);
2132
2133
2134         if (ret != 0) {
2135                 printf("Cannot initialize network ports.\n");
2136                 return;
2137         }
2138
2139         cmd_reconfig_device_queue(port_id, 1, 1);
2140 }
2141
2142 cmdline_parse_token_string_t cmd_config_dcb_port =
2143         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2144 cmdline_parse_token_string_t cmd_config_dcb_config =
2145         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2146 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2147         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8);
2148 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2149         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2150 cmdline_parse_token_string_t cmd_config_dcb_vt =
2151         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2152 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2153         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2154 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2155         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2156 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2157         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2158 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2159         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2160
2161 cmdline_parse_inst_t cmd_config_dcb = {
2162         .f = cmd_config_dcb_parsed,
2163         .data = NULL,
2164         .help_str = "port config port-id dcb vt on|off nb-tcs pfc on|off",
2165         .tokens = {
2166                 (void *)&cmd_config_dcb_port,
2167                 (void *)&cmd_config_dcb_config,
2168                 (void *)&cmd_config_dcb_port_id,
2169                 (void *)&cmd_config_dcb_dcb,
2170                 (void *)&cmd_config_dcb_vt,
2171                 (void *)&cmd_config_dcb_vt_en,
2172                 (void *)&cmd_config_dcb_num_tcs,
2173                 (void *)&cmd_config_dcb_pfc,
2174                 (void *)&cmd_config_dcb_pfc_en,
2175                 NULL,
2176         },
2177 };
2178
2179 /* *** configure number of packets per burst *** */
2180 struct cmd_config_burst {
2181         cmdline_fixed_string_t port;
2182         cmdline_fixed_string_t keyword;
2183         cmdline_fixed_string_t all;
2184         cmdline_fixed_string_t name;
2185         uint16_t value;
2186 };
2187
2188 static void
2189 cmd_config_burst_parsed(void *parsed_result,
2190                         __attribute__((unused)) struct cmdline *cl,
2191                         __attribute__((unused)) void *data)
2192 {
2193         struct cmd_config_burst *res = parsed_result;
2194
2195         if (!all_ports_stopped()) {
2196                 printf("Please stop all ports first\n");
2197                 return;
2198         }
2199
2200         if (!strcmp(res->name, "burst")) {
2201                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2202                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2203                         return;
2204                 }
2205                 nb_pkt_per_burst = res->value;
2206         } else {
2207                 printf("Unknown parameter\n");
2208                 return;
2209         }
2210
2211         init_port_config();
2212
2213         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2214 }
2215
2216 cmdline_parse_token_string_t cmd_config_burst_port =
2217         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2218 cmdline_parse_token_string_t cmd_config_burst_keyword =
2219         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2220 cmdline_parse_token_string_t cmd_config_burst_all =
2221         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2222 cmdline_parse_token_string_t cmd_config_burst_name =
2223         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2224 cmdline_parse_token_num_t cmd_config_burst_value =
2225         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2226
2227 cmdline_parse_inst_t cmd_config_burst = {
2228         .f = cmd_config_burst_parsed,
2229         .data = NULL,
2230         .help_str = "port config all burst value",
2231         .tokens = {
2232                 (void *)&cmd_config_burst_port,
2233                 (void *)&cmd_config_burst_keyword,
2234                 (void *)&cmd_config_burst_all,
2235                 (void *)&cmd_config_burst_name,
2236                 (void *)&cmd_config_burst_value,
2237                 NULL,
2238         },
2239 };
2240
2241 /* *** configure rx/tx queues *** */
2242 struct cmd_config_thresh {
2243         cmdline_fixed_string_t port;
2244         cmdline_fixed_string_t keyword;
2245         cmdline_fixed_string_t all;
2246         cmdline_fixed_string_t name;
2247         uint8_t value;
2248 };
2249
2250 static void
2251 cmd_config_thresh_parsed(void *parsed_result,
2252                         __attribute__((unused)) struct cmdline *cl,
2253                         __attribute__((unused)) void *data)
2254 {
2255         struct cmd_config_thresh *res = parsed_result;
2256
2257         if (!all_ports_stopped()) {
2258                 printf("Please stop all ports first\n");
2259                 return;
2260         }
2261
2262         if (!strcmp(res->name, "txpt"))
2263                 tx_pthresh = res->value;
2264         else if(!strcmp(res->name, "txht"))
2265                 tx_hthresh = res->value;
2266         else if(!strcmp(res->name, "txwt"))
2267                 tx_wthresh = res->value;
2268         else if(!strcmp(res->name, "rxpt"))
2269                 rx_pthresh = res->value;
2270         else if(!strcmp(res->name, "rxht"))
2271                 rx_hthresh = res->value;
2272         else if(!strcmp(res->name, "rxwt"))
2273                 rx_wthresh = res->value;
2274         else {
2275                 printf("Unknown parameter\n");
2276                 return;
2277         }
2278
2279         init_port_config();
2280
2281         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2282 }
2283
2284 cmdline_parse_token_string_t cmd_config_thresh_port =
2285         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2286 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2287         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2288 cmdline_parse_token_string_t cmd_config_thresh_all =
2289         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2290 cmdline_parse_token_string_t cmd_config_thresh_name =
2291         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2292                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2293 cmdline_parse_token_num_t cmd_config_thresh_value =
2294         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2295
2296 cmdline_parse_inst_t cmd_config_thresh = {
2297         .f = cmd_config_thresh_parsed,
2298         .data = NULL,
2299         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt value",
2300         .tokens = {
2301                 (void *)&cmd_config_thresh_port,
2302                 (void *)&cmd_config_thresh_keyword,
2303                 (void *)&cmd_config_thresh_all,
2304                 (void *)&cmd_config_thresh_name,
2305                 (void *)&cmd_config_thresh_value,
2306                 NULL,
2307         },
2308 };
2309
2310 /* *** configure free/rs threshold *** */
2311 struct cmd_config_threshold {
2312         cmdline_fixed_string_t port;
2313         cmdline_fixed_string_t keyword;
2314         cmdline_fixed_string_t all;
2315         cmdline_fixed_string_t name;
2316         uint16_t value;
2317 };
2318
2319 static void
2320 cmd_config_threshold_parsed(void *parsed_result,
2321                         __attribute__((unused)) struct cmdline *cl,
2322                         __attribute__((unused)) void *data)
2323 {
2324         struct cmd_config_threshold *res = parsed_result;
2325
2326         if (!all_ports_stopped()) {
2327                 printf("Please stop all ports first\n");
2328                 return;
2329         }
2330
2331         if (!strcmp(res->name, "txfreet"))
2332                 tx_free_thresh = res->value;
2333         else if (!strcmp(res->name, "txrst"))
2334                 tx_rs_thresh = res->value;
2335         else if (!strcmp(res->name, "rxfreet"))
2336                 rx_free_thresh = res->value;
2337         else {
2338                 printf("Unknown parameter\n");
2339                 return;
2340         }
2341
2342         init_port_config();
2343
2344         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2345 }
2346
2347 cmdline_parse_token_string_t cmd_config_threshold_port =
2348         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2349 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2350         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2351                                                                 "config");
2352 cmdline_parse_token_string_t cmd_config_threshold_all =
2353         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2354 cmdline_parse_token_string_t cmd_config_threshold_name =
2355         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2356                                                 "txfreet#txrst#rxfreet");
2357 cmdline_parse_token_num_t cmd_config_threshold_value =
2358         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2359
2360 cmdline_parse_inst_t cmd_config_threshold = {
2361         .f = cmd_config_threshold_parsed,
2362         .data = NULL,
2363         .help_str = "port config all txfreet|txrst|rxfreet value",
2364         .tokens = {
2365                 (void *)&cmd_config_threshold_port,
2366                 (void *)&cmd_config_threshold_keyword,
2367                 (void *)&cmd_config_threshold_all,
2368                 (void *)&cmd_config_threshold_name,
2369                 (void *)&cmd_config_threshold_value,
2370                 NULL,
2371         },
2372 };
2373
2374 /* *** stop *** */
2375 struct cmd_stop_result {
2376         cmdline_fixed_string_t stop;
2377 };
2378
2379 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2380                             __attribute__((unused)) struct cmdline *cl,
2381                             __attribute__((unused)) void *data)
2382 {
2383         stop_packet_forwarding();
2384 }
2385
2386 cmdline_parse_token_string_t cmd_stop_stop =
2387         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2388
2389 cmdline_parse_inst_t cmd_stop = {
2390         .f = cmd_stop_parsed,
2391         .data = NULL,
2392         .help_str = "stop - stop packet forwarding",
2393         .tokens = {
2394                 (void *)&cmd_stop_stop,
2395                 NULL,
2396         },
2397 };
2398
2399 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2400
2401 unsigned int
2402 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2403                 unsigned int *parsed_items, int check_unique_values)
2404 {
2405         unsigned int nb_item;
2406         unsigned int value;
2407         unsigned int i;
2408         unsigned int j;
2409         int value_ok;
2410         char c;
2411
2412         /*
2413          * First parse all items in the list and store their value.
2414          */
2415         value = 0;
2416         nb_item = 0;
2417         value_ok = 0;
2418         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2419                 c = str[i];
2420                 if ((c >= '0') && (c <= '9')) {
2421                         value = (unsigned int) (value * 10 + (c - '0'));
2422                         value_ok = 1;
2423                         continue;
2424                 }
2425                 if (c != ',') {
2426                         printf("character %c is not a decimal digit\n", c);
2427                         return 0;
2428                 }
2429                 if (! value_ok) {
2430                         printf("No valid value before comma\n");
2431                         return 0;
2432                 }
2433                 if (nb_item < max_items) {
2434                         parsed_items[nb_item] = value;
2435                         value_ok = 0;
2436                         value = 0;
2437                 }
2438                 nb_item++;
2439         }
2440         if (nb_item >= max_items) {
2441                 printf("Number of %s = %u > %u (maximum items)\n",
2442                        item_name, nb_item + 1, max_items);
2443                 return 0;
2444         }
2445         parsed_items[nb_item++] = value;
2446         if (! check_unique_values)
2447                 return nb_item;
2448
2449         /*
2450          * Then, check that all values in the list are differents.
2451          * No optimization here...
2452          */
2453         for (i = 0; i < nb_item; i++) {
2454                 for (j = i + 1; j < nb_item; j++) {
2455                         if (parsed_items[j] == parsed_items[i]) {
2456                                 printf("duplicated %s %u at index %u and %u\n",
2457                                        item_name, parsed_items[i], i, j);
2458                                 return 0;
2459                         }
2460                 }
2461         }
2462         return nb_item;
2463 }
2464
2465 struct cmd_set_list_result {
2466         cmdline_fixed_string_t cmd_keyword;
2467         cmdline_fixed_string_t list_name;
2468         cmdline_fixed_string_t list_of_items;
2469 };
2470
2471 static void cmd_set_list_parsed(void *parsed_result,
2472                                 __attribute__((unused)) struct cmdline *cl,
2473                                 __attribute__((unused)) void *data)
2474 {
2475         struct cmd_set_list_result *res;
2476         union {
2477                 unsigned int lcorelist[RTE_MAX_LCORE];
2478                 unsigned int portlist[RTE_MAX_ETHPORTS];
2479         } parsed_items;
2480         unsigned int nb_item;
2481
2482         if (test_done == 0) {
2483                 printf("Please stop forwarding first\n");
2484                 return;
2485         }
2486
2487         res = parsed_result;
2488         if (!strcmp(res->list_name, "corelist")) {
2489                 nb_item = parse_item_list(res->list_of_items, "core",
2490                                           RTE_MAX_LCORE,
2491                                           parsed_items.lcorelist, 1);
2492                 if (nb_item > 0)
2493                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2494                 return;
2495         }
2496         if (!strcmp(res->list_name, "portlist")) {
2497                 nb_item = parse_item_list(res->list_of_items, "port",
2498                                           RTE_MAX_ETHPORTS,
2499                                           parsed_items.portlist, 1);
2500                 if (nb_item > 0)
2501                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2502         }
2503 }
2504
2505 cmdline_parse_token_string_t cmd_set_list_keyword =
2506         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2507                                  "set");
2508 cmdline_parse_token_string_t cmd_set_list_name =
2509         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2510                                  "corelist#portlist");
2511 cmdline_parse_token_string_t cmd_set_list_of_items =
2512         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2513                                  NULL);
2514
2515 cmdline_parse_inst_t cmd_set_fwd_list = {
2516         .f = cmd_set_list_parsed,
2517         .data = NULL,
2518         .help_str = "set corelist|portlist x[,y]*",
2519         .tokens = {
2520                 (void *)&cmd_set_list_keyword,
2521                 (void *)&cmd_set_list_name,
2522                 (void *)&cmd_set_list_of_items,
2523                 NULL,
2524         },
2525 };
2526
2527 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2528
2529 struct cmd_setmask_result {
2530         cmdline_fixed_string_t set;
2531         cmdline_fixed_string_t mask;
2532         uint64_t hexavalue;
2533 };
2534
2535 static void cmd_set_mask_parsed(void *parsed_result,
2536                                 __attribute__((unused)) struct cmdline *cl,
2537                                 __attribute__((unused)) void *data)
2538 {
2539         struct cmd_setmask_result *res = parsed_result;
2540
2541         if (test_done == 0) {
2542                 printf("Please stop forwarding first\n");
2543                 return;
2544         }
2545         if (!strcmp(res->mask, "coremask"))
2546                 set_fwd_lcores_mask(res->hexavalue);
2547         else if (!strcmp(res->mask, "portmask"))
2548                 set_fwd_ports_mask(res->hexavalue);
2549 }
2550
2551 cmdline_parse_token_string_t cmd_setmask_set =
2552         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2553 cmdline_parse_token_string_t cmd_setmask_mask =
2554         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2555                                  "coremask#portmask");
2556 cmdline_parse_token_num_t cmd_setmask_value =
2557         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2558
2559 cmdline_parse_inst_t cmd_set_fwd_mask = {
2560         .f = cmd_set_mask_parsed,
2561         .data = NULL,
2562         .help_str = "set coremask|portmask hexadecimal value",
2563         .tokens = {
2564                 (void *)&cmd_setmask_set,
2565                 (void *)&cmd_setmask_mask,
2566                 (void *)&cmd_setmask_value,
2567                 NULL,
2568         },
2569 };
2570
2571 /*
2572  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2573  */
2574 struct cmd_set_result {
2575         cmdline_fixed_string_t set;
2576         cmdline_fixed_string_t what;
2577         uint16_t value;
2578 };
2579
2580 static void cmd_set_parsed(void *parsed_result,
2581                            __attribute__((unused)) struct cmdline *cl,
2582                            __attribute__((unused)) void *data)
2583 {
2584         struct cmd_set_result *res = parsed_result;
2585         if (!strcmp(res->what, "nbport"))
2586                 set_fwd_ports_number(res->value);
2587         else if (!strcmp(res->what, "nbcore"))
2588                 set_fwd_lcores_number(res->value);
2589         else if (!strcmp(res->what, "burst"))
2590                 set_nb_pkt_per_burst(res->value);
2591         else if (!strcmp(res->what, "verbose"))
2592                 set_verbose_level(res->value);
2593 }
2594
2595 cmdline_parse_token_string_t cmd_set_set =
2596         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2597 cmdline_parse_token_string_t cmd_set_what =
2598         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2599                                  "nbport#nbcore#burst#verbose");
2600 cmdline_parse_token_num_t cmd_set_value =
2601         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2602
2603 cmdline_parse_inst_t cmd_set_numbers = {
2604         .f = cmd_set_parsed,
2605         .data = NULL,
2606         .help_str = "set nbport|nbcore|burst|verbose value",
2607         .tokens = {
2608                 (void *)&cmd_set_set,
2609                 (void *)&cmd_set_what,
2610                 (void *)&cmd_set_value,
2611                 NULL,
2612         },
2613 };
2614
2615 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
2616
2617 struct cmd_set_txpkts_result {
2618         cmdline_fixed_string_t cmd_keyword;
2619         cmdline_fixed_string_t txpkts;
2620         cmdline_fixed_string_t seg_lengths;
2621 };
2622
2623 static void
2624 cmd_set_txpkts_parsed(void *parsed_result,
2625                       __attribute__((unused)) struct cmdline *cl,
2626                       __attribute__((unused)) void *data)
2627 {
2628         struct cmd_set_txpkts_result *res;
2629         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
2630         unsigned int nb_segs;
2631
2632         res = parsed_result;
2633         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
2634                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
2635         if (nb_segs > 0)
2636                 set_tx_pkt_segments(seg_lengths, nb_segs);
2637 }
2638
2639 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
2640         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2641                                  cmd_keyword, "set");
2642 cmdline_parse_token_string_t cmd_set_txpkts_name =
2643         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2644                                  txpkts, "txpkts");
2645 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
2646         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
2647                                  seg_lengths, NULL);
2648
2649 cmdline_parse_inst_t cmd_set_txpkts = {
2650         .f = cmd_set_txpkts_parsed,
2651         .data = NULL,
2652         .help_str = "set txpkts x[,y]*",
2653         .tokens = {
2654                 (void *)&cmd_set_txpkts_keyword,
2655                 (void *)&cmd_set_txpkts_name,
2656                 (void *)&cmd_set_txpkts_lengths,
2657                 NULL,
2658         },
2659 };
2660
2661 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
2662
2663 struct cmd_set_txsplit_result {
2664         cmdline_fixed_string_t cmd_keyword;
2665         cmdline_fixed_string_t txsplit;
2666         cmdline_fixed_string_t mode;
2667 };
2668
2669 static void
2670 cmd_set_txsplit_parsed(void *parsed_result,
2671                       __attribute__((unused)) struct cmdline *cl,
2672                       __attribute__((unused)) void *data)
2673 {
2674         struct cmd_set_txsplit_result *res;
2675
2676         res = parsed_result;
2677         set_tx_pkt_split(res->mode);
2678 }
2679
2680 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
2681         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2682                                  cmd_keyword, "set");
2683 cmdline_parse_token_string_t cmd_set_txsplit_name =
2684         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2685                                  txsplit, "txsplit");
2686 cmdline_parse_token_string_t cmd_set_txsplit_mode =
2687         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
2688                                  mode, NULL);
2689
2690 cmdline_parse_inst_t cmd_set_txsplit = {
2691         .f = cmd_set_txsplit_parsed,
2692         .data = NULL,
2693         .help_str = "set txsplit on|off|rand",
2694         .tokens = {
2695                 (void *)&cmd_set_txsplit_keyword,
2696                 (void *)&cmd_set_txsplit_name,
2697                 (void *)&cmd_set_txsplit_mode,
2698                 NULL,
2699         },
2700 };
2701
2702 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
2703 struct cmd_rx_vlan_filter_all_result {
2704         cmdline_fixed_string_t rx_vlan;
2705         cmdline_fixed_string_t what;
2706         cmdline_fixed_string_t all;
2707         uint8_t port_id;
2708 };
2709
2710 static void
2711 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
2712                               __attribute__((unused)) struct cmdline *cl,
2713                               __attribute__((unused)) void *data)
2714 {
2715         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
2716
2717         if (!strcmp(res->what, "add"))
2718                 rx_vlan_all_filter_set(res->port_id, 1);
2719         else
2720                 rx_vlan_all_filter_set(res->port_id, 0);
2721 }
2722
2723 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
2724         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2725                                  rx_vlan, "rx_vlan");
2726 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
2727         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2728                                  what, "add#rm");
2729 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
2730         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2731                                  all, "all");
2732 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
2733         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
2734                               port_id, UINT8);
2735
2736 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
2737         .f = cmd_rx_vlan_filter_all_parsed,
2738         .data = NULL,
2739         .help_str = "add/remove all identifiers to/from the set of VLAN "
2740         "Identifiers filtered by a port",
2741         .tokens = {
2742                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
2743                 (void *)&cmd_rx_vlan_filter_all_what,
2744                 (void *)&cmd_rx_vlan_filter_all_all,
2745                 (void *)&cmd_rx_vlan_filter_all_portid,
2746                 NULL,
2747         },
2748 };
2749
2750 /* *** VLAN OFFLOAD SET ON A PORT *** */
2751 struct cmd_vlan_offload_result {
2752         cmdline_fixed_string_t vlan;
2753         cmdline_fixed_string_t set;
2754         cmdline_fixed_string_t vlan_type;
2755         cmdline_fixed_string_t what;
2756         cmdline_fixed_string_t on;
2757         cmdline_fixed_string_t port_id;
2758 };
2759
2760 static void
2761 cmd_vlan_offload_parsed(void *parsed_result,
2762                           __attribute__((unused)) struct cmdline *cl,
2763                           __attribute__((unused)) void *data)
2764 {
2765         int on;
2766         struct cmd_vlan_offload_result *res = parsed_result;
2767         char *str;
2768         int i, len = 0;
2769         portid_t port_id = 0;
2770         unsigned int tmp;
2771
2772         str = res->port_id;
2773         len = strnlen(str, STR_TOKEN_SIZE);
2774         i = 0;
2775         /* Get port_id first */
2776         while(i < len){
2777                 if(str[i] == ',')
2778                         break;
2779
2780                 i++;
2781         }
2782         str[i]='\0';
2783         tmp = strtoul(str, NULL, 0);
2784         /* If port_id greater that what portid_t can represent, return */
2785         if(tmp >= RTE_MAX_ETHPORTS)
2786                 return;
2787         port_id = (portid_t)tmp;
2788
2789         if (!strcmp(res->on, "on"))
2790                 on = 1;
2791         else
2792                 on = 0;
2793
2794         if (!strcmp(res->what, "strip"))
2795                 rx_vlan_strip_set(port_id,  on);
2796         else if(!strcmp(res->what, "stripq")){
2797                 uint16_t queue_id = 0;
2798
2799                 /* No queue_id, return */
2800                 if(i + 1 >= len) {
2801                         printf("must specify (port,queue_id)\n");
2802                         return;
2803                 }
2804                 tmp = strtoul(str + i + 1, NULL, 0);
2805                 /* If queue_id greater that what 16-bits can represent, return */
2806                 if(tmp > 0xffff)
2807                         return;
2808
2809                 queue_id = (uint16_t)tmp;
2810                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
2811         }
2812         else if (!strcmp(res->what, "filter"))
2813                 rx_vlan_filter_set(port_id, on);
2814         else
2815                 vlan_extend_set(port_id, on);
2816
2817         return;
2818 }
2819
2820 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
2821         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2822                                  vlan, "vlan");
2823 cmdline_parse_token_string_t cmd_vlan_offload_set =
2824         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2825                                  set, "set");
2826 cmdline_parse_token_string_t cmd_vlan_offload_what =
2827         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2828                                  what, "strip#filter#qinq#stripq");
2829 cmdline_parse_token_string_t cmd_vlan_offload_on =
2830         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2831                               on, "on#off");
2832 cmdline_parse_token_string_t cmd_vlan_offload_portid =
2833         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
2834                               port_id, NULL);
2835
2836 cmdline_parse_inst_t cmd_vlan_offload = {
2837         .f = cmd_vlan_offload_parsed,
2838         .data = NULL,
2839         .help_str = "set strip|filter|qinq|stripq on|off port_id[,queue_id], filter/strip for rx side"
2840         " qinq(extended) for both rx/tx sides ",
2841         .tokens = {
2842                 (void *)&cmd_vlan_offload_vlan,
2843                 (void *)&cmd_vlan_offload_set,
2844                 (void *)&cmd_vlan_offload_what,
2845                 (void *)&cmd_vlan_offload_on,
2846                 (void *)&cmd_vlan_offload_portid,
2847                 NULL,
2848         },
2849 };
2850
2851 /* *** VLAN TPID SET ON A PORT *** */
2852 struct cmd_vlan_tpid_result {
2853         cmdline_fixed_string_t vlan;
2854         cmdline_fixed_string_t set;
2855         cmdline_fixed_string_t vlan_type;
2856         cmdline_fixed_string_t what;
2857         uint16_t tp_id;
2858         uint8_t port_id;
2859 };
2860
2861 static void
2862 cmd_vlan_tpid_parsed(void *parsed_result,
2863                           __attribute__((unused)) struct cmdline *cl,
2864                           __attribute__((unused)) void *data)
2865 {
2866         struct cmd_vlan_tpid_result *res = parsed_result;
2867         enum rte_vlan_type vlan_type;
2868
2869         if (!strcmp(res->vlan_type, "inner"))
2870                 vlan_type = ETH_VLAN_TYPE_INNER;
2871         else if (!strcmp(res->vlan_type, "outer"))
2872                 vlan_type = ETH_VLAN_TYPE_OUTER;
2873         else {
2874                 printf("Unknown vlan type\n");
2875                 return;
2876         }
2877         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
2878 }
2879
2880 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
2881         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2882                                  vlan, "vlan");
2883 cmdline_parse_token_string_t cmd_vlan_tpid_set =
2884         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2885                                  set, "set");
2886 cmdline_parse_token_string_t cmd_vlan_type =
2887         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2888                                  vlan_type, "inner#outer");
2889 cmdline_parse_token_string_t cmd_vlan_tpid_what =
2890         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
2891                                  what, "tpid");
2892 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
2893         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2894                               tp_id, UINT16);
2895 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
2896         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
2897                               port_id, UINT8);
2898
2899 cmdline_parse_inst_t cmd_vlan_tpid = {
2900         .f = cmd_vlan_tpid_parsed,
2901         .data = NULL,
2902         .help_str = "set inner|outer tpid tp_id port_id, set the VLAN "
2903                     "Ether type",
2904         .tokens = {
2905                 (void *)&cmd_vlan_tpid_vlan,
2906                 (void *)&cmd_vlan_tpid_set,
2907                 (void *)&cmd_vlan_type,
2908                 (void *)&cmd_vlan_tpid_what,
2909                 (void *)&cmd_vlan_tpid_tpid,
2910                 (void *)&cmd_vlan_tpid_portid,
2911                 NULL,
2912         },
2913 };
2914
2915 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
2916 struct cmd_rx_vlan_filter_result {
2917         cmdline_fixed_string_t rx_vlan;
2918         cmdline_fixed_string_t what;
2919         uint16_t vlan_id;
2920         uint8_t port_id;
2921 };
2922
2923 static void
2924 cmd_rx_vlan_filter_parsed(void *parsed_result,
2925                           __attribute__((unused)) struct cmdline *cl,
2926                           __attribute__((unused)) void *data)
2927 {
2928         struct cmd_rx_vlan_filter_result *res = parsed_result;
2929
2930         if (!strcmp(res->what, "add"))
2931                 rx_vft_set(res->port_id, res->vlan_id, 1);
2932         else
2933                 rx_vft_set(res->port_id, res->vlan_id, 0);
2934 }
2935
2936 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
2937         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2938                                  rx_vlan, "rx_vlan");
2939 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
2940         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
2941                                  what, "add#rm");
2942 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
2943         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2944                               vlan_id, UINT16);
2945 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
2946         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
2947                               port_id, UINT8);
2948
2949 cmdline_parse_inst_t cmd_rx_vlan_filter = {
2950         .f = cmd_rx_vlan_filter_parsed,
2951         .data = NULL,
2952         .help_str = "add/remove a VLAN identifier to/from the set of VLAN "
2953         "Identifiers filtered by a port",
2954         .tokens = {
2955                 (void *)&cmd_rx_vlan_filter_rx_vlan,
2956                 (void *)&cmd_rx_vlan_filter_what,
2957                 (void *)&cmd_rx_vlan_filter_vlanid,
2958                 (void *)&cmd_rx_vlan_filter_portid,
2959                 NULL,
2960         },
2961 };
2962
2963 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
2964 struct cmd_tx_vlan_set_result {
2965         cmdline_fixed_string_t tx_vlan;
2966         cmdline_fixed_string_t set;
2967         uint8_t port_id;
2968         uint16_t vlan_id;
2969 };
2970
2971 static void
2972 cmd_tx_vlan_set_parsed(void *parsed_result,
2973                        __attribute__((unused)) struct cmdline *cl,
2974                        __attribute__((unused)) void *data)
2975 {
2976         struct cmd_tx_vlan_set_result *res = parsed_result;
2977
2978         tx_vlan_set(res->port_id, res->vlan_id);
2979 }
2980
2981 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
2982         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2983                                  tx_vlan, "tx_vlan");
2984 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
2985         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
2986                                  set, "set");
2987 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
2988         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2989                               port_id, UINT8);
2990 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
2991         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
2992                               vlan_id, UINT16);
2993
2994 cmdline_parse_inst_t cmd_tx_vlan_set = {
2995         .f = cmd_tx_vlan_set_parsed,
2996         .data = NULL,
2997         .help_str = "enable hardware insertion of a single VLAN header "
2998                 "with a given TAG Identifier in packets sent on a port",
2999         .tokens = {
3000                 (void *)&cmd_tx_vlan_set_tx_vlan,
3001                 (void *)&cmd_tx_vlan_set_set,
3002                 (void *)&cmd_tx_vlan_set_portid,
3003                 (void *)&cmd_tx_vlan_set_vlanid,
3004                 NULL,
3005         },
3006 };
3007
3008 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3009 struct cmd_tx_vlan_set_qinq_result {
3010         cmdline_fixed_string_t tx_vlan;
3011         cmdline_fixed_string_t set;
3012         uint8_t port_id;
3013         uint16_t vlan_id;
3014         uint16_t vlan_id_outer;
3015 };
3016
3017 static void
3018 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3019                             __attribute__((unused)) struct cmdline *cl,
3020                             __attribute__((unused)) void *data)
3021 {
3022         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3023
3024         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3025 }
3026
3027 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3028         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3029                 tx_vlan, "tx_vlan");
3030 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3031         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3032                 set, "set");
3033 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3034         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3035                 port_id, UINT8);
3036 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3037         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3038                 vlan_id, UINT16);
3039 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3040         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3041                 vlan_id_outer, UINT16);
3042
3043 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3044         .f = cmd_tx_vlan_set_qinq_parsed,
3045         .data = NULL,
3046         .help_str = "enable hardware insertion of double VLAN header "
3047                 "with given TAG Identifiers in packets sent on a port",
3048         .tokens = {
3049                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3050                 (void *)&cmd_tx_vlan_set_qinq_set,
3051                 (void *)&cmd_tx_vlan_set_qinq_portid,
3052                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3053                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3054                 NULL,
3055         },
3056 };
3057
3058 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3059 struct cmd_tx_vlan_set_pvid_result {
3060         cmdline_fixed_string_t tx_vlan;
3061         cmdline_fixed_string_t set;
3062         cmdline_fixed_string_t pvid;
3063         uint8_t port_id;
3064         uint16_t vlan_id;
3065         cmdline_fixed_string_t mode;
3066 };
3067
3068 static void
3069 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3070                             __attribute__((unused)) struct cmdline *cl,
3071                             __attribute__((unused)) void *data)
3072 {
3073         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3074
3075         if (strcmp(res->mode, "on") == 0)
3076                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3077         else
3078                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3079 }
3080
3081 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3082         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3083                                  tx_vlan, "tx_vlan");
3084 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3085         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3086                                  set, "set");
3087 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3088         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3089                                  pvid, "pvid");
3090 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3091         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3092                              port_id, UINT8);
3093 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3094         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3095                               vlan_id, UINT16);
3096 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3097         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3098                                  mode, "on#off");
3099
3100 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3101         .f = cmd_tx_vlan_set_pvid_parsed,
3102         .data = NULL,
3103         .help_str = "tx_vlan set pvid port_id vlan_id (on|off)",
3104         .tokens = {
3105                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3106                 (void *)&cmd_tx_vlan_set_pvid_set,
3107                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3108                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3109                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3110                 (void *)&cmd_tx_vlan_set_pvid_mode,
3111                 NULL,
3112         },
3113 };
3114
3115 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3116 struct cmd_tx_vlan_reset_result {
3117         cmdline_fixed_string_t tx_vlan;
3118         cmdline_fixed_string_t reset;
3119         uint8_t port_id;
3120 };
3121
3122 static void
3123 cmd_tx_vlan_reset_parsed(void *parsed_result,
3124                          __attribute__((unused)) struct cmdline *cl,
3125                          __attribute__((unused)) void *data)
3126 {
3127         struct cmd_tx_vlan_reset_result *res = parsed_result;
3128
3129         tx_vlan_reset(res->port_id);
3130 }
3131
3132 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3133         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3134                                  tx_vlan, "tx_vlan");
3135 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3136         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3137                                  reset, "reset");
3138 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3139         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3140                               port_id, UINT8);
3141
3142 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3143         .f = cmd_tx_vlan_reset_parsed,
3144         .data = NULL,
3145         .help_str = "disable hardware insertion of a VLAN header in packets "
3146         "sent on a port",
3147         .tokens = {
3148                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3149                 (void *)&cmd_tx_vlan_reset_reset,
3150                 (void *)&cmd_tx_vlan_reset_portid,
3151                 NULL,
3152         },
3153 };
3154
3155
3156 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3157 struct cmd_csum_result {
3158         cmdline_fixed_string_t csum;
3159         cmdline_fixed_string_t mode;
3160         cmdline_fixed_string_t proto;
3161         cmdline_fixed_string_t hwsw;
3162         uint8_t port_id;
3163 };
3164
3165 static void
3166 csum_show(int port_id)
3167 {
3168         struct rte_eth_dev_info dev_info;
3169         uint16_t ol_flags;
3170
3171         ol_flags = ports[port_id].tx_ol_flags;
3172         printf("Parse tunnel is %s\n",
3173                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3174         printf("IP checksum offload is %s\n",
3175                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3176         printf("UDP checksum offload is %s\n",
3177                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3178         printf("TCP checksum offload is %s\n",
3179                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3180         printf("SCTP checksum offload is %s\n",
3181                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3182         printf("Outer-Ip checksum offload is %s\n",
3183                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3184
3185         /* display warnings if configuration is not supported by the NIC */
3186         rte_eth_dev_info_get(port_id, &dev_info);
3187         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3188                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3189                 printf("Warning: hardware IP checksum enabled but not "
3190                         "supported by port %d\n", port_id);
3191         }
3192         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3193                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3194                 printf("Warning: hardware UDP checksum enabled but not "
3195                         "supported by port %d\n", port_id);
3196         }
3197         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3198                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3199                 printf("Warning: hardware TCP checksum enabled but not "
3200                         "supported by port %d\n", port_id);
3201         }
3202         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3203                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3204                 printf("Warning: hardware SCTP checksum enabled but not "
3205                         "supported by port %d\n", port_id);
3206         }
3207         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3208                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3209                 printf("Warning: hardware outer IP checksum enabled but not "
3210                         "supported by port %d\n", port_id);
3211         }
3212 }
3213
3214 static void
3215 cmd_csum_parsed(void *parsed_result,
3216                        __attribute__((unused)) struct cmdline *cl,
3217                        __attribute__((unused)) void *data)
3218 {
3219         struct cmd_csum_result *res = parsed_result;
3220         int hw = 0;
3221         uint16_t mask = 0;
3222
3223         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3224                 printf("invalid port %d\n", res->port_id);
3225                 return;
3226         }
3227
3228         if (!strcmp(res->mode, "set")) {
3229
3230                 if (!strcmp(res->hwsw, "hw"))
3231                         hw = 1;
3232
3233                 if (!strcmp(res->proto, "ip")) {
3234                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3235                 } else if (!strcmp(res->proto, "udp")) {
3236                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3237                 } else if (!strcmp(res->proto, "tcp")) {
3238                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3239                 } else if (!strcmp(res->proto, "sctp")) {
3240                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3241                 } else if (!strcmp(res->proto, "outer-ip")) {
3242                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3243                 }
3244
3245                 if (hw)
3246                         ports[res->port_id].tx_ol_flags |= mask;
3247                 else
3248                         ports[res->port_id].tx_ol_flags &= (~mask);
3249         }
3250         csum_show(res->port_id);
3251 }
3252
3253 cmdline_parse_token_string_t cmd_csum_csum =
3254         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3255                                 csum, "csum");
3256 cmdline_parse_token_string_t cmd_csum_mode =
3257         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3258                                 mode, "set");
3259 cmdline_parse_token_string_t cmd_csum_proto =
3260         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3261                                 proto, "ip#tcp#udp#sctp#outer-ip");
3262 cmdline_parse_token_string_t cmd_csum_hwsw =
3263         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3264                                 hwsw, "hw#sw");
3265 cmdline_parse_token_num_t cmd_csum_portid =
3266         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3267                                 port_id, UINT8);
3268
3269 cmdline_parse_inst_t cmd_csum_set = {
3270         .f = cmd_csum_parsed,
3271         .data = NULL,
3272         .help_str = "enable/disable hardware calculation of L3/L4 checksum when "
3273                 "using csum forward engine: csum set ip|tcp|udp|sctp|outer-ip hw|sw <port>",
3274         .tokens = {
3275                 (void *)&cmd_csum_csum,
3276                 (void *)&cmd_csum_mode,
3277                 (void *)&cmd_csum_proto,
3278                 (void *)&cmd_csum_hwsw,
3279                 (void *)&cmd_csum_portid,
3280                 NULL,
3281         },
3282 };
3283
3284 cmdline_parse_token_string_t cmd_csum_mode_show =
3285         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3286                                 mode, "show");
3287
3288 cmdline_parse_inst_t cmd_csum_show = {
3289         .f = cmd_csum_parsed,
3290         .data = NULL,
3291         .help_str = "show checksum offload configuration: csum show <port>",
3292         .tokens = {
3293                 (void *)&cmd_csum_csum,
3294                 (void *)&cmd_csum_mode_show,
3295                 (void *)&cmd_csum_portid,
3296                 NULL,
3297         },
3298 };
3299
3300 /* Enable/disable tunnel parsing */
3301 struct cmd_csum_tunnel_result {
3302         cmdline_fixed_string_t csum;
3303         cmdline_fixed_string_t parse;
3304         cmdline_fixed_string_t onoff;
3305         uint8_t port_id;
3306 };
3307
3308 static void
3309 cmd_csum_tunnel_parsed(void *parsed_result,
3310                        __attribute__((unused)) struct cmdline *cl,
3311                        __attribute__((unused)) void *data)
3312 {
3313         struct cmd_csum_tunnel_result *res = parsed_result;
3314
3315         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3316                 return;
3317
3318         if (!strcmp(res->onoff, "on"))
3319                 ports[res->port_id].tx_ol_flags |=
3320                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3321         else
3322                 ports[res->port_id].tx_ol_flags &=
3323                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3324
3325         csum_show(res->port_id);
3326 }
3327
3328 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3329         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3330                                 csum, "csum");
3331 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3332         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3333                                 parse, "parse_tunnel");
3334 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3335         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3336                                 onoff, "on#off");
3337 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3338         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3339                                 port_id, UINT8);
3340
3341 cmdline_parse_inst_t cmd_csum_tunnel = {
3342         .f = cmd_csum_tunnel_parsed,
3343         .data = NULL,
3344         .help_str = "enable/disable parsing of tunnels for csum engine: "
3345         "csum parse_tunnel on|off <tx-port>",
3346         .tokens = {
3347                 (void *)&cmd_csum_tunnel_csum,
3348                 (void *)&cmd_csum_tunnel_parse,
3349                 (void *)&cmd_csum_tunnel_onoff,
3350                 (void *)&cmd_csum_tunnel_portid,
3351                 NULL,
3352         },
3353 };
3354
3355 /* *** ENABLE HARDWARE SEGMENTATION IN TX PACKETS *** */
3356 struct cmd_tso_set_result {
3357         cmdline_fixed_string_t tso;
3358         cmdline_fixed_string_t mode;
3359         uint16_t tso_segsz;
3360         uint8_t port_id;
3361 };
3362
3363 static void
3364 cmd_tso_set_parsed(void *parsed_result,
3365                        __attribute__((unused)) struct cmdline *cl,
3366                        __attribute__((unused)) void *data)
3367 {
3368         struct cmd_tso_set_result *res = parsed_result;
3369         struct rte_eth_dev_info dev_info;
3370
3371         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3372                 return;
3373
3374         if (!strcmp(res->mode, "set"))
3375                 ports[res->port_id].tso_segsz = res->tso_segsz;
3376
3377         if (ports[res->port_id].tso_segsz == 0)
3378                 printf("TSO is disabled\n");
3379         else
3380                 printf("TSO segment size is %d\n",
3381                         ports[res->port_id].tso_segsz);
3382
3383         /* display warnings if configuration is not supported by the NIC */
3384         rte_eth_dev_info_get(res->port_id, &dev_info);
3385         if ((ports[res->port_id].tso_segsz != 0) &&
3386                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3387                 printf("Warning: TSO enabled but not "
3388                         "supported by port %d\n", res->port_id);
3389         }
3390 }
3391
3392 cmdline_parse_token_string_t cmd_tso_set_tso =
3393         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3394                                 tso, "tso");
3395 cmdline_parse_token_string_t cmd_tso_set_mode =
3396         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3397                                 mode, "set");
3398 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3399         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3400                                 tso_segsz, UINT16);
3401 cmdline_parse_token_num_t cmd_tso_set_portid =
3402         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3403                                 port_id, UINT8);
3404
3405 cmdline_parse_inst_t cmd_tso_set = {
3406         .f = cmd_tso_set_parsed,
3407         .data = NULL,
3408         .help_str = "Set TSO segment size for csum engine (0 to disable): "
3409         "tso set <tso_segsz> <port>",
3410         .tokens = {
3411                 (void *)&cmd_tso_set_tso,
3412                 (void *)&cmd_tso_set_mode,
3413                 (void *)&cmd_tso_set_tso_segsz,
3414                 (void *)&cmd_tso_set_portid,
3415                 NULL,
3416         },
3417 };
3418
3419 cmdline_parse_token_string_t cmd_tso_show_mode =
3420         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3421                                 mode, "show");
3422
3423
3424 cmdline_parse_inst_t cmd_tso_show = {
3425         .f = cmd_tso_set_parsed,
3426         .data = NULL,
3427         .help_str = "Show TSO segment size for csum engine: "
3428         "tso show <port>",
3429         .tokens = {
3430                 (void *)&cmd_tso_set_tso,
3431                 (void *)&cmd_tso_show_mode,
3432                 (void *)&cmd_tso_set_portid,
3433                 NULL,
3434         },
3435 };
3436
3437 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
3438 struct cmd_set_flush_rx {
3439         cmdline_fixed_string_t set;
3440         cmdline_fixed_string_t flush_rx;
3441         cmdline_fixed_string_t mode;
3442 };
3443
3444 static void
3445 cmd_set_flush_rx_parsed(void *parsed_result,
3446                 __attribute__((unused)) struct cmdline *cl,
3447                 __attribute__((unused)) void *data)
3448 {
3449         struct cmd_set_flush_rx *res = parsed_result;
3450         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3451 }
3452
3453 cmdline_parse_token_string_t cmd_setflushrx_set =
3454         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3455                         set, "set");
3456 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
3457         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3458                         flush_rx, "flush_rx");
3459 cmdline_parse_token_string_t cmd_setflushrx_mode =
3460         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
3461                         mode, "on#off");
3462
3463
3464 cmdline_parse_inst_t cmd_set_flush_rx = {
3465         .f = cmd_set_flush_rx_parsed,
3466         .help_str = "set flush_rx on|off: enable/disable flush on rx streams",
3467         .data = NULL,
3468         .tokens = {
3469                 (void *)&cmd_setflushrx_set,
3470                 (void *)&cmd_setflushrx_flush_rx,
3471                 (void *)&cmd_setflushrx_mode,
3472                 NULL,
3473         },
3474 };
3475
3476 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
3477 struct cmd_set_link_check {
3478         cmdline_fixed_string_t set;
3479         cmdline_fixed_string_t link_check;
3480         cmdline_fixed_string_t mode;
3481 };
3482
3483 static void
3484 cmd_set_link_check_parsed(void *parsed_result,
3485                 __attribute__((unused)) struct cmdline *cl,
3486                 __attribute__((unused)) void *data)
3487 {
3488         struct cmd_set_link_check *res = parsed_result;
3489         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
3490 }
3491
3492 cmdline_parse_token_string_t cmd_setlinkcheck_set =
3493         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3494                         set, "set");
3495 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
3496         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3497                         link_check, "link_check");
3498 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
3499         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
3500                         mode, "on#off");
3501
3502
3503 cmdline_parse_inst_t cmd_set_link_check = {
3504         .f = cmd_set_link_check_parsed,
3505         .help_str = "set link_check on|off: enable/disable link status check "
3506                     "when starting/stopping a port",
3507         .data = NULL,
3508         .tokens = {
3509                 (void *)&cmd_setlinkcheck_set,
3510                 (void *)&cmd_setlinkcheck_link_check,
3511                 (void *)&cmd_setlinkcheck_mode,
3512                 NULL,
3513         },
3514 };
3515
3516 #ifdef RTE_NIC_BYPASS
3517 /* *** SET NIC BYPASS MODE *** */
3518 struct cmd_set_bypass_mode_result {
3519         cmdline_fixed_string_t set;
3520         cmdline_fixed_string_t bypass;
3521         cmdline_fixed_string_t mode;
3522         cmdline_fixed_string_t value;
3523         uint8_t port_id;
3524 };
3525
3526 static void
3527 cmd_set_bypass_mode_parsed(void *parsed_result,
3528                 __attribute__((unused)) struct cmdline *cl,
3529                 __attribute__((unused)) void *data)
3530 {
3531         struct cmd_set_bypass_mode_result *res = parsed_result;
3532         portid_t port_id = res->port_id;
3533         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3534
3535         if (!bypass_is_supported(port_id))
3536                 return;
3537
3538         if (!strcmp(res->value, "bypass"))
3539                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3540         else if (!strcmp(res->value, "isolate"))
3541                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3542         else
3543                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3544
3545         /* Set the bypass mode for the relevant port. */
3546         if (0 != rte_eth_dev_bypass_state_set(port_id, &bypass_mode)) {
3547                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
3548         }
3549 }
3550
3551 cmdline_parse_token_string_t cmd_setbypass_mode_set =
3552         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3553                         set, "set");
3554 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
3555         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3556                         bypass, "bypass");
3557 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
3558         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3559                         mode, "mode");
3560 cmdline_parse_token_string_t cmd_setbypass_mode_value =
3561         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
3562                         value, "normal#bypass#isolate");
3563 cmdline_parse_token_num_t cmd_setbypass_mode_port =
3564         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
3565                                 port_id, UINT8);
3566
3567 cmdline_parse_inst_t cmd_set_bypass_mode = {
3568         .f = cmd_set_bypass_mode_parsed,
3569         .help_str = "set bypass mode (normal|bypass|isolate) (port_id): "
3570                     "Set the NIC bypass mode for port_id",
3571         .data = NULL,
3572         .tokens = {
3573                 (void *)&cmd_setbypass_mode_set,
3574                 (void *)&cmd_setbypass_mode_bypass,
3575                 (void *)&cmd_setbypass_mode_mode,
3576                 (void *)&cmd_setbypass_mode_value,
3577                 (void *)&cmd_setbypass_mode_port,
3578                 NULL,
3579         },
3580 };
3581
3582 /* *** SET NIC BYPASS EVENT *** */
3583 struct cmd_set_bypass_event_result {
3584         cmdline_fixed_string_t set;
3585         cmdline_fixed_string_t bypass;
3586         cmdline_fixed_string_t event;
3587         cmdline_fixed_string_t event_value;
3588         cmdline_fixed_string_t mode;
3589         cmdline_fixed_string_t mode_value;
3590         uint8_t port_id;
3591 };
3592
3593 static void
3594 cmd_set_bypass_event_parsed(void *parsed_result,
3595                 __attribute__((unused)) struct cmdline *cl,
3596                 __attribute__((unused)) void *data)
3597 {
3598         int32_t rc;
3599         struct cmd_set_bypass_event_result *res = parsed_result;
3600         portid_t port_id = res->port_id;
3601         uint32_t bypass_event = RTE_BYPASS_EVENT_NONE;
3602         uint32_t bypass_mode = RTE_BYPASS_MODE_NORMAL;
3603
3604         if (!bypass_is_supported(port_id))
3605                 return;
3606
3607         if (!strcmp(res->event_value, "timeout"))
3608                 bypass_event = RTE_BYPASS_EVENT_TIMEOUT;
3609         else if (!strcmp(res->event_value, "os_on"))
3610                 bypass_event = RTE_BYPASS_EVENT_OS_ON;
3611         else if (!strcmp(res->event_value, "os_off"))
3612                 bypass_event = RTE_BYPASS_EVENT_OS_OFF;
3613         else if (!strcmp(res->event_value, "power_on"))
3614                 bypass_event = RTE_BYPASS_EVENT_POWER_ON;
3615         else if (!strcmp(res->event_value, "power_off"))
3616                 bypass_event = RTE_BYPASS_EVENT_POWER_OFF;
3617         else
3618                 bypass_event = RTE_BYPASS_EVENT_NONE;
3619
3620         if (!strcmp(res->mode_value, "bypass"))
3621                 bypass_mode = RTE_BYPASS_MODE_BYPASS;
3622         else if (!strcmp(res->mode_value, "isolate"))
3623                 bypass_mode = RTE_BYPASS_MODE_ISOLATE;
3624         else
3625                 bypass_mode = RTE_BYPASS_MODE_NORMAL;
3626
3627         /* Set the watchdog timeout. */
3628         if (bypass_event == RTE_BYPASS_EVENT_TIMEOUT) {
3629
3630                 rc = -EINVAL;
3631                 if (!RTE_BYPASS_TMT_VALID(bypass_timeout) ||
3632                                 (rc = rte_eth_dev_wd_timeout_store(port_id,
3633                                 bypass_timeout)) != 0) {
3634                         printf("Failed to set timeout value %u "
3635                                 "for port %d, errto code: %d.\n",
3636                                 bypass_timeout, port_id, rc);
3637                 }
3638         }
3639
3640         /* Set the bypass event to transition to bypass mode. */
3641         if (0 != rte_eth_dev_bypass_event_store(port_id,
3642                         bypass_event, bypass_mode)) {
3643                 printf("\t Failed to set bypass event for port = %d.\n", port_id);
3644         }
3645
3646 }
3647
3648 cmdline_parse_token_string_t cmd_setbypass_event_set =
3649         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3650                         set, "set");
3651 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
3652         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3653                         bypass, "bypass");
3654 cmdline_parse_token_string_t cmd_setbypass_event_event =
3655         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3656                         event, "event");
3657 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
3658         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3659                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
3660 cmdline_parse_token_string_t cmd_setbypass_event_mode =
3661         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3662                         mode, "mode");
3663 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
3664         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
3665                         mode_value, "normal#bypass#isolate");
3666 cmdline_parse_token_num_t cmd_setbypass_event_port =
3667         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
3668                                 port_id, UINT8);
3669
3670 cmdline_parse_inst_t cmd_set_bypass_event = {
3671         .f = cmd_set_bypass_event_parsed,
3672         .help_str = "set bypass event (timeout|os_on|os_off|power_on|power_off) "
3673                     "mode (normal|bypass|isolate) (port_id): "
3674                     "Set the NIC bypass event mode for port_id",
3675         .data = NULL,
3676         .tokens = {
3677                 (void *)&cmd_setbypass_event_set,
3678                 (void *)&cmd_setbypass_event_bypass,
3679                 (void *)&cmd_setbypass_event_event,
3680                 (void *)&cmd_setbypass_event_event_value,
3681                 (void *)&cmd_setbypass_event_mode,
3682                 (void *)&cmd_setbypass_event_mode_value,
3683                 (void *)&cmd_setbypass_event_port,
3684                 NULL,
3685         },
3686 };
3687
3688
3689 /* *** SET NIC BYPASS TIMEOUT *** */
3690 struct cmd_set_bypass_timeout_result {
3691         cmdline_fixed_string_t set;
3692         cmdline_fixed_string_t bypass;
3693         cmdline_fixed_string_t timeout;
3694         cmdline_fixed_string_t value;
3695 };
3696
3697 static void
3698 cmd_set_bypass_timeout_parsed(void *parsed_result,
3699                 __attribute__((unused)) struct cmdline *cl,
3700                 __attribute__((unused)) void *data)
3701 {
3702         struct cmd_set_bypass_timeout_result *res = parsed_result;
3703
3704         if (!strcmp(res->value, "1.5"))
3705                 bypass_timeout = RTE_BYPASS_TMT_1_5_SEC;
3706         else if (!strcmp(res->value, "2"))
3707                 bypass_timeout = RTE_BYPASS_TMT_2_SEC;
3708         else if (!strcmp(res->value, "3"))
3709                 bypass_timeout = RTE_BYPASS_TMT_3_SEC;
3710         else if (!strcmp(res->value, "4"))
3711                 bypass_timeout = RTE_BYPASS_TMT_4_SEC;
3712         else if (!strcmp(res->value, "8"))
3713                 bypass_timeout = RTE_BYPASS_TMT_8_SEC;
3714         else if (!strcmp(res->value, "16"))
3715                 bypass_timeout = RTE_BYPASS_TMT_16_SEC;
3716         else if (!strcmp(res->value, "32"))
3717                 bypass_timeout = RTE_BYPASS_TMT_32_SEC;
3718         else
3719                 bypass_timeout = RTE_BYPASS_TMT_OFF;
3720 }
3721
3722 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
3723         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3724                         set, "set");
3725 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
3726         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3727                         bypass, "bypass");
3728 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
3729         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3730                         timeout, "timeout");
3731 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
3732         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
3733                         value, "0#1.5#2#3#4#8#16#32");
3734
3735 cmdline_parse_inst_t cmd_set_bypass_timeout = {
3736         .f = cmd_set_bypass_timeout_parsed,
3737         .help_str = "set bypass timeout (0|1.5|2|3|4|8|16|32) seconds: "
3738                     "Set the NIC bypass watchdog timeout",
3739         .data = NULL,
3740         .tokens = {
3741                 (void *)&cmd_setbypass_timeout_set,
3742                 (void *)&cmd_setbypass_timeout_bypass,
3743                 (void *)&cmd_setbypass_timeout_timeout,
3744                 (void *)&cmd_setbypass_timeout_value,
3745                 NULL,
3746         },
3747 };
3748
3749 /* *** SHOW NIC BYPASS MODE *** */
3750 struct cmd_show_bypass_config_result {
3751         cmdline_fixed_string_t show;
3752         cmdline_fixed_string_t bypass;
3753         cmdline_fixed_string_t config;
3754         uint8_t port_id;
3755 };
3756
3757 static void
3758 cmd_show_bypass_config_parsed(void *parsed_result,
3759                 __attribute__((unused)) struct cmdline *cl,
3760                 __attribute__((unused)) void *data)
3761 {
3762         struct cmd_show_bypass_config_result *res = parsed_result;
3763         uint32_t event_mode;
3764         uint32_t bypass_mode;
3765         portid_t port_id = res->port_id;
3766         uint32_t timeout = bypass_timeout;
3767         int i;
3768
3769         static const char * const timeouts[RTE_BYPASS_TMT_NUM] =
3770                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
3771         static const char * const modes[RTE_BYPASS_MODE_NUM] =
3772                 {"UNKNOWN", "normal", "bypass", "isolate"};
3773         static const char * const events[RTE_BYPASS_EVENT_NUM] = {
3774                 "NONE",
3775                 "OS/board on",
3776                 "power supply on",
3777                 "OS/board off",
3778                 "power supply off",
3779                 "timeout"};
3780         int num_events = (sizeof events) / (sizeof events[0]);
3781
3782         if (!bypass_is_supported(port_id))
3783                 return;
3784
3785         /* Display the bypass mode.*/
3786         if (0 != rte_eth_dev_bypass_state_show(port_id, &bypass_mode)) {
3787                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
3788                 return;
3789         }
3790         else {
3791                 if (!RTE_BYPASS_MODE_VALID(bypass_mode))
3792                         bypass_mode = RTE_BYPASS_MODE_NONE;
3793
3794                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
3795         }
3796
3797         /* Display the bypass timeout.*/
3798         if (!RTE_BYPASS_TMT_VALID(timeout))
3799                 timeout = RTE_BYPASS_TMT_OFF;
3800
3801         printf("\tbypass timeout = %s\n", timeouts[timeout]);
3802
3803         /* Display the bypass events and associated modes. */
3804         for (i = RTE_BYPASS_EVENT_START; i < num_events; i++) {
3805
3806                 if (0 != rte_eth_dev_bypass_event_show(port_id, i, &event_mode)) {
3807                         printf("\tFailed to get bypass mode for event = %s\n",
3808                                 events[i]);
3809                 } else {
3810                         if (!RTE_BYPASS_MODE_VALID(event_mode))
3811                                 event_mode = RTE_BYPASS_MODE_NONE;
3812
3813                         printf("\tbypass event: %-16s = %s\n", events[i],
3814                                 modes[event_mode]);
3815                 }
3816         }
3817 }
3818
3819 cmdline_parse_token_string_t cmd_showbypass_config_show =
3820         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3821                         show, "show");
3822 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
3823         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3824                         bypass, "bypass");
3825 cmdline_parse_token_string_t cmd_showbypass_config_config =
3826         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
3827                         config, "config");
3828 cmdline_parse_token_num_t cmd_showbypass_config_port =
3829         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
3830                                 port_id, UINT8);
3831
3832 cmdline_parse_inst_t cmd_show_bypass_config = {
3833         .f = cmd_show_bypass_config_parsed,
3834         .help_str = "show bypass config (port_id): "
3835                     "Show the NIC bypass config for port_id",
3836         .data = NULL,
3837         .tokens = {
3838                 (void *)&cmd_showbypass_config_show,
3839                 (void *)&cmd_showbypass_config_bypass,
3840                 (void *)&cmd_showbypass_config_config,
3841                 (void *)&cmd_showbypass_config_port,
3842                 NULL,
3843         },
3844 };
3845 #endif
3846
3847 #ifdef RTE_LIBRTE_PMD_BOND
3848 /* *** SET BONDING MODE *** */
3849 struct cmd_set_bonding_mode_result {
3850         cmdline_fixed_string_t set;
3851         cmdline_fixed_string_t bonding;
3852         cmdline_fixed_string_t mode;
3853         uint8_t value;
3854         uint8_t port_id;
3855 };
3856
3857 static void cmd_set_bonding_mode_parsed(void *parsed_result,
3858                 __attribute__((unused))  struct cmdline *cl,
3859                 __attribute__((unused)) void *data)
3860 {
3861         struct cmd_set_bonding_mode_result *res = parsed_result;
3862         portid_t port_id = res->port_id;
3863
3864         /* Set the bonding mode for the relevant port. */
3865         if (0 != rte_eth_bond_mode_set(port_id, res->value))
3866                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
3867 }
3868
3869 cmdline_parse_token_string_t cmd_setbonding_mode_set =
3870 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3871                 set, "set");
3872 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
3873 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3874                 bonding, "bonding");
3875 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
3876 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
3877                 mode, "mode");
3878 cmdline_parse_token_num_t cmd_setbonding_mode_value =
3879 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3880                 value, UINT8);
3881 cmdline_parse_token_num_t cmd_setbonding_mode_port =
3882 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
3883                 port_id, UINT8);
3884
3885 cmdline_parse_inst_t cmd_set_bonding_mode = {
3886                 .f = cmd_set_bonding_mode_parsed,
3887                 .help_str = "set bonding mode (mode_value) (port_id): Set the bonding mode for port_id",
3888                 .data = NULL,
3889                 .tokens = {
3890                                 (void *) &cmd_setbonding_mode_set,
3891                                 (void *) &cmd_setbonding_mode_bonding,
3892                                 (void *) &cmd_setbonding_mode_mode,
3893                                 (void *) &cmd_setbonding_mode_value,
3894                                 (void *) &cmd_setbonding_mode_port,
3895                                 NULL
3896                 }
3897 };
3898
3899 /* *** SET BALANCE XMIT POLICY *** */
3900 struct cmd_set_bonding_balance_xmit_policy_result {
3901         cmdline_fixed_string_t set;
3902         cmdline_fixed_string_t bonding;
3903         cmdline_fixed_string_t balance_xmit_policy;
3904         uint8_t port_id;
3905         cmdline_fixed_string_t policy;
3906 };
3907
3908 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
3909                 __attribute__((unused))  struct cmdline *cl,
3910                 __attribute__((unused)) void *data)
3911 {
3912         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
3913         portid_t port_id = res->port_id;
3914         uint8_t policy;
3915
3916         if (!strcmp(res->policy, "l2")) {
3917                 policy = BALANCE_XMIT_POLICY_LAYER2;
3918         } else if (!strcmp(res->policy, "l23")) {
3919                 policy = BALANCE_XMIT_POLICY_LAYER23;
3920         } else if (!strcmp(res->policy, "l34")) {
3921                 policy = BALANCE_XMIT_POLICY_LAYER34;
3922         } else {
3923                 printf("\t Invalid xmit policy selection");
3924                 return;
3925         }
3926
3927         /* Set the bonding mode for the relevant port. */
3928         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
3929                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
3930                                 port_id);
3931         }
3932 }
3933
3934 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
3935 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3936                 set, "set");
3937 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
3938 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3939                 bonding, "bonding");
3940 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
3941 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3942                 balance_xmit_policy, "balance_xmit_policy");
3943 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
3944 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3945                 port_id, UINT8);
3946 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
3947 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
3948                 policy, "l2#l23#l34");
3949
3950 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
3951                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
3952                 .help_str = "set bonding balance_xmit_policy (port_id) (policy_value): Set the bonding balance_xmit_policy for port_id",
3953                 .data = NULL,
3954                 .tokens = {
3955                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
3956                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
3957                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
3958                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
3959                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
3960                                 NULL
3961                 }
3962 };
3963
3964 /* *** SHOW NIC BONDING CONFIGURATION *** */
3965 struct cmd_show_bonding_config_result {
3966         cmdline_fixed_string_t show;
3967         cmdline_fixed_string_t bonding;
3968         cmdline_fixed_string_t config;
3969         uint8_t port_id;
3970 };
3971
3972 static void cmd_show_bonding_config_parsed(void *parsed_result,
3973                 __attribute__((unused))  struct cmdline *cl,
3974                 __attribute__((unused)) void *data)
3975 {
3976         struct cmd_show_bonding_config_result *res = parsed_result;
3977         int bonding_mode;
3978         uint8_t slaves[RTE_MAX_ETHPORTS];
3979         int num_slaves, num_active_slaves;
3980         int primary_id;
3981         int i;
3982         portid_t port_id = res->port_id;
3983
3984         /* Display the bonding mode.*/
3985         bonding_mode = rte_eth_bond_mode_get(port_id);
3986         if (bonding_mode < 0) {
3987                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
3988                 return;
3989         } else
3990                 printf("\tBonding mode: %d\n", bonding_mode);
3991
3992         if (bonding_mode == BONDING_MODE_BALANCE) {
3993                 int balance_xmit_policy;
3994
3995                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
3996                 if (balance_xmit_policy < 0) {
3997                         printf("\tFailed to get balance xmit policy for port = %d\n",
3998                                         port_id);
3999                         return;
4000                 } else {
4001                         printf("\tBalance Xmit Policy: ");
4002
4003                         switch (balance_xmit_policy) {
4004                         case BALANCE_XMIT_POLICY_LAYER2:
4005                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4006                                 break;
4007                         case BALANCE_XMIT_POLICY_LAYER23:
4008                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4009                                 break;
4010                         case BALANCE_XMIT_POLICY_LAYER34:
4011                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4012                                 break;
4013                         }
4014                         printf("\n");
4015                 }
4016         }
4017
4018         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
4019
4020         if (num_slaves < 0) {
4021                 printf("\tFailed to get slave list for port = %d\n", port_id);
4022                 return;
4023         }
4024         if (num_slaves > 0) {
4025                 printf("\tSlaves (%d): [", num_slaves);
4026                 for (i = 0; i < num_slaves - 1; i++)
4027                         printf("%d ", slaves[i]);
4028
4029                 printf("%d]\n", slaves[num_slaves - 1]);
4030         } else {
4031                 printf("\tSlaves: []\n");
4032
4033         }
4034
4035         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
4036                         RTE_MAX_ETHPORTS);
4037
4038         if (num_active_slaves < 0) {
4039                 printf("\tFailed to get active slave list for port = %d\n", port_id);
4040                 return;
4041         }
4042         if (num_active_slaves > 0) {
4043                 printf("\tActive Slaves (%d): [", num_active_slaves);
4044                 for (i = 0; i < num_active_slaves - 1; i++)
4045                         printf("%d ", slaves[i]);
4046
4047                 printf("%d]\n", slaves[num_active_slaves - 1]);
4048
4049         } else {
4050                 printf("\tActive Slaves: []\n");
4051
4052         }
4053
4054         primary_id = rte_eth_bond_primary_get(port_id);
4055         if (primary_id < 0) {
4056                 printf("\tFailed to get primary slave for port = %d\n", port_id);
4057                 return;
4058         } else
4059                 printf("\tPrimary: [%d]\n", primary_id);
4060
4061 }
4062
4063 cmdline_parse_token_string_t cmd_showbonding_config_show =
4064 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4065                 show, "show");
4066 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
4067 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4068                 bonding, "bonding");
4069 cmdline_parse_token_string_t cmd_showbonding_config_config =
4070 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
4071                 config, "config");
4072 cmdline_parse_token_num_t cmd_showbonding_config_port =
4073 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
4074                 port_id, UINT8);
4075
4076 cmdline_parse_inst_t cmd_show_bonding_config = {
4077                 .f = cmd_show_bonding_config_parsed,
4078                 .help_str =     "show bonding config (port_id): Show the bonding config for port_id",
4079                 .data = NULL,
4080                 .tokens = {
4081                                 (void *)&cmd_showbonding_config_show,
4082                                 (void *)&cmd_showbonding_config_bonding,
4083                                 (void *)&cmd_showbonding_config_config,
4084                                 (void *)&cmd_showbonding_config_port,
4085                                 NULL
4086                 }
4087 };
4088
4089 /* *** SET BONDING PRIMARY *** */
4090 struct cmd_set_bonding_primary_result {
4091         cmdline_fixed_string_t set;
4092         cmdline_fixed_string_t bonding;
4093         cmdline_fixed_string_t primary;
4094         uint8_t slave_id;
4095         uint8_t port_id;
4096 };
4097
4098 static void cmd_set_bonding_primary_parsed(void *parsed_result,
4099                 __attribute__((unused))  struct cmdline *cl,
4100                 __attribute__((unused)) void *data)
4101 {
4102         struct cmd_set_bonding_primary_result *res = parsed_result;
4103         portid_t master_port_id = res->port_id;
4104         portid_t slave_port_id = res->slave_id;
4105
4106         /* Set the primary slave for a bonded device. */
4107         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
4108                 printf("\t Failed to set primary slave for port = %d.\n",
4109                                 master_port_id);
4110                 return;
4111         }
4112         init_port_config();
4113 }
4114
4115 cmdline_parse_token_string_t cmd_setbonding_primary_set =
4116 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4117                 set, "set");
4118 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
4119 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4120                 bonding, "bonding");
4121 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
4122 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
4123                 primary, "primary");
4124 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
4125 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4126                 slave_id, UINT8);
4127 cmdline_parse_token_num_t cmd_setbonding_primary_port =
4128 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
4129                 port_id, UINT8);
4130
4131 cmdline_parse_inst_t cmd_set_bonding_primary = {
4132                 .f = cmd_set_bonding_primary_parsed,
4133                 .help_str = "set bonding primary (slave_id) (port_id): Set the primary slave for port_id",
4134                 .data = NULL,
4135                 .tokens = {
4136                                 (void *)&cmd_setbonding_primary_set,
4137                                 (void *)&cmd_setbonding_primary_bonding,
4138                                 (void *)&cmd_setbonding_primary_primary,
4139                                 (void *)&cmd_setbonding_primary_slave,
4140                                 (void *)&cmd_setbonding_primary_port,
4141                                 NULL
4142                 }
4143 };
4144
4145 /* *** ADD SLAVE *** */
4146 struct cmd_add_bonding_slave_result {
4147         cmdline_fixed_string_t add;
4148         cmdline_fixed_string_t bonding;
4149         cmdline_fixed_string_t slave;
4150         uint8_t slave_id;
4151         uint8_t port_id;
4152 };
4153
4154 static void cmd_add_bonding_slave_parsed(void *parsed_result,
4155                 __attribute__((unused))  struct cmdline *cl,
4156                 __attribute__((unused)) void *data)
4157 {
4158         struct cmd_add_bonding_slave_result *res = parsed_result;
4159         portid_t master_port_id = res->port_id;
4160         portid_t slave_port_id = res->slave_id;
4161
4162         /* Set the primary slave for a bonded device. */
4163         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
4164                 printf("\t Failed to add slave %d to master port = %d.\n",
4165                                 slave_port_id, master_port_id);
4166                 return;
4167         }
4168         init_port_config();
4169         set_port_slave_flag(slave_port_id);
4170 }
4171
4172 cmdline_parse_token_string_t cmd_addbonding_slave_add =
4173 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4174                 add, "add");
4175 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
4176 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4177                 bonding, "bonding");
4178 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
4179 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
4180                 slave, "slave");
4181 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
4182 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4183                 slave_id, UINT8);
4184 cmdline_parse_token_num_t cmd_addbonding_slave_port =
4185 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
4186                 port_id, UINT8);
4187
4188 cmdline_parse_inst_t cmd_add_bonding_slave = {
4189                 .f = cmd_add_bonding_slave_parsed,
4190                 .help_str = "add bonding slave (slave_id) (port_id): Add a slave device to a bonded device",
4191                 .data = NULL,
4192                 .tokens = {
4193                                 (void *)&cmd_addbonding_slave_add,
4194                                 (void *)&cmd_addbonding_slave_bonding,
4195                                 (void *)&cmd_addbonding_slave_slave,
4196                                 (void *)&cmd_addbonding_slave_slaveid,
4197                                 (void *)&cmd_addbonding_slave_port,
4198                                 NULL
4199                 }
4200 };
4201
4202 /* *** REMOVE SLAVE *** */
4203 struct cmd_remove_bonding_slave_result {
4204         cmdline_fixed_string_t remove;
4205         cmdline_fixed_string_t bonding;
4206         cmdline_fixed_string_t slave;
4207         uint8_t slave_id;
4208         uint8_t port_id;
4209 };
4210
4211 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
4212                 __attribute__((unused))  struct cmdline *cl,
4213                 __attribute__((unused)) void *data)
4214 {
4215         struct cmd_remove_bonding_slave_result *res = parsed_result;
4216         portid_t master_port_id = res->port_id;
4217         portid_t slave_port_id = res->slave_id;
4218
4219         /* Set the primary slave for a bonded device. */
4220         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
4221                 printf("\t Failed to remove slave %d from master port = %d.\n",
4222                                 slave_port_id, master_port_id);
4223                 return;
4224         }
4225         init_port_config();
4226         clear_port_slave_flag(slave_port_id);
4227 }
4228
4229 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
4230                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4231                                 remove, "remove");
4232 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
4233                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4234                                 bonding, "bonding");
4235 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
4236                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
4237                                 slave, "slave");
4238 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
4239                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4240                                 slave_id, UINT8);
4241 cmdline_parse_token_num_t cmd_removebonding_slave_port =
4242                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
4243                                 port_id, UINT8);
4244
4245 cmdline_parse_inst_t cmd_remove_bonding_slave = {
4246                 .f = cmd_remove_bonding_slave_parsed,
4247                 .help_str = "remove bonding slave (slave_id) (port_id): Remove a slave device from a bonded device",
4248                 .data = NULL,
4249                 .tokens = {
4250                                 (void *)&cmd_removebonding_slave_remove,
4251                                 (void *)&cmd_removebonding_slave_bonding,
4252                                 (void *)&cmd_removebonding_slave_slave,
4253                                 (void *)&cmd_removebonding_slave_slaveid,
4254                                 (void *)&cmd_removebonding_slave_port,
4255                                 NULL
4256                 }
4257 };
4258
4259 /* *** CREATE BONDED DEVICE *** */
4260 struct cmd_create_bonded_device_result {
4261         cmdline_fixed_string_t create;
4262         cmdline_fixed_string_t bonded;
4263         cmdline_fixed_string_t device;
4264         uint8_t mode;
4265         uint8_t socket;
4266 };
4267
4268 static int bond_dev_num = 0;
4269
4270 static void cmd_create_bonded_device_parsed(void *parsed_result,
4271                 __attribute__((unused))  struct cmdline *cl,
4272                 __attribute__((unused)) void *data)
4273 {
4274         struct cmd_create_bonded_device_result *res = parsed_result;
4275         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
4276         int port_id;
4277
4278         if (test_done == 0) {
4279                 printf("Please stop forwarding first\n");
4280                 return;
4281         }
4282
4283         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "eth_bond_testpmd_%d",
4284                         bond_dev_num++);
4285
4286         /* Create a new bonded device. */
4287         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
4288         if (port_id < 0) {
4289                 printf("\t Failed to create bonded device.\n");
4290                 return;
4291         } else {
4292                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
4293                                 port_id);
4294
4295                 /* Update number of ports */
4296                 nb_ports = rte_eth_dev_count();
4297                 reconfig(port_id, res->socket);
4298                 rte_eth_promiscuous_enable(port_id);
4299                 ports[port_id].enabled = 1;
4300         }
4301
4302 }
4303
4304 cmdline_parse_token_string_t cmd_createbonded_device_create =
4305                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4306                                 create, "create");
4307 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
4308                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4309                                 bonded, "bonded");
4310 cmdline_parse_token_string_t cmd_createbonded_device_device =
4311                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
4312                                 device, "device");
4313 cmdline_parse_token_num_t cmd_createbonded_device_mode =
4314                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4315                                 mode, UINT8);
4316 cmdline_parse_token_num_t cmd_createbonded_device_socket =
4317                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
4318                                 socket, UINT8);
4319
4320 cmdline_parse_inst_t cmd_create_bonded_device = {
4321                 .f = cmd_create_bonded_device_parsed,
4322                 .help_str = "create bonded device (mode) (socket): Create a new bonded device with specific bonding mode and socket",
4323                 .data = NULL,
4324                 .tokens = {
4325                                 (void *)&cmd_createbonded_device_create,
4326                                 (void *)&cmd_createbonded_device_bonded,
4327                                 (void *)&cmd_createbonded_device_device,
4328                                 (void *)&cmd_createbonded_device_mode,
4329                                 (void *)&cmd_createbonded_device_socket,
4330                                 NULL
4331                 }
4332 };
4333
4334 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
4335 struct cmd_set_bond_mac_addr_result {
4336         cmdline_fixed_string_t set;
4337         cmdline_fixed_string_t bonding;
4338         cmdline_fixed_string_t mac_addr;
4339         uint8_t port_num;
4340         struct ether_addr address;
4341 };
4342
4343 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
4344                 __attribute__((unused))  struct cmdline *cl,
4345                 __attribute__((unused)) void *data)
4346 {
4347         struct cmd_set_bond_mac_addr_result *res = parsed_result;
4348         int ret;
4349
4350         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
4351                 return;
4352
4353         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
4354
4355         /* check the return value and print it if is < 0 */
4356         if (ret < 0)
4357                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4358 }
4359
4360 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
4361                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
4362 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
4363                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
4364                                 "bonding");
4365 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
4366                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
4367                                 "mac_addr");
4368 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
4369                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8);
4370 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
4371                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
4372
4373 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
4374                 .f = cmd_set_bond_mac_addr_parsed,
4375                 .data = (void *) 0,
4376                 .help_str = "set bonding mac_addr (port_id) (address): ",
4377                 .tokens = {
4378                                 (void *)&cmd_set_bond_mac_addr_set,
4379                                 (void *)&cmd_set_bond_mac_addr_bonding,
4380                                 (void *)&cmd_set_bond_mac_addr_mac,
4381                                 (void *)&cmd_set_bond_mac_addr_portnum,
4382                                 (void *)&cmd_set_bond_mac_addr_addr,
4383                                 NULL
4384                 }
4385 };
4386
4387
4388 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
4389 struct cmd_set_bond_mon_period_result {
4390         cmdline_fixed_string_t set;
4391         cmdline_fixed_string_t bonding;
4392         cmdline_fixed_string_t mon_period;
4393         uint8_t port_num;
4394         uint32_t period_ms;
4395 };
4396
4397 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
4398                 __attribute__((unused))  struct cmdline *cl,
4399                 __attribute__((unused)) void *data)
4400 {
4401         struct cmd_set_bond_mon_period_result *res = parsed_result;
4402         int ret;
4403
4404         if (res->port_num >= nb_ports) {
4405                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
4406                 return;
4407         }
4408
4409         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
4410
4411         /* check the return value and print it if is < 0 */
4412         if (ret < 0)
4413                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
4414 }
4415
4416 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
4417                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4418                                 set, "set");
4419 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
4420                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4421                                 bonding, "bonding");
4422 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
4423                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
4424                                 mon_period,     "mon_period");
4425 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
4426                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4427                                 port_num, UINT8);
4428 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
4429                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
4430                                 period_ms, UINT32);
4431
4432 cmdline_parse_inst_t cmd_set_bond_mon_period = {
4433                 .f = cmd_set_bond_mon_period_parsed,
4434                 .data = (void *) 0,
4435                 .help_str = "set bonding mon_period (port_id) (period_ms): ",
4436                 .tokens = {
4437                                 (void *)&cmd_set_bond_mon_period_set,
4438                                 (void *)&cmd_set_bond_mon_period_bonding,
4439                                 (void *)&cmd_set_bond_mon_period_mon_period,
4440                                 (void *)&cmd_set_bond_mon_period_portnum,
4441                                 (void *)&cmd_set_bond_mon_period_period_ms,
4442                                 NULL
4443                 }
4444 };
4445
4446 #endif /* RTE_LIBRTE_PMD_BOND */
4447
4448 /* *** SET FORWARDING MODE *** */
4449 struct cmd_set_fwd_mode_result {
4450         cmdline_fixed_string_t set;
4451         cmdline_fixed_string_t fwd;
4452         cmdline_fixed_string_t mode;
4453 };
4454
4455 static void cmd_set_fwd_mode_parsed(void *parsed_result,
4456                                     __attribute__((unused)) struct cmdline *cl,
4457                                     __attribute__((unused)) void *data)
4458 {
4459         struct cmd_set_fwd_mode_result *res = parsed_result;
4460
4461         set_pkt_forwarding_mode(res->mode);
4462 }
4463
4464 cmdline_parse_token_string_t cmd_setfwd_set =
4465         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
4466 cmdline_parse_token_string_t cmd_setfwd_fwd =
4467         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
4468 cmdline_parse_token_string_t cmd_setfwd_mode =
4469         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
4470                 "" /* defined at init */);
4471
4472 cmdline_parse_inst_t cmd_set_fwd_mode = {
4473         .f = cmd_set_fwd_mode_parsed,
4474         .data = NULL,
4475         .help_str = NULL, /* defined at init */
4476         .tokens = {
4477                 (void *)&cmd_setfwd_set,
4478                 (void *)&cmd_setfwd_fwd,
4479                 (void *)&cmd_setfwd_mode,
4480                 NULL,
4481         },
4482 };
4483
4484 static void cmd_set_fwd_mode_init(void)
4485 {
4486         char *modes, *c;
4487         static char token[128];
4488         static char help[256];
4489         cmdline_parse_token_string_t *token_struct;
4490
4491         modes = list_pkt_forwarding_modes();
4492         snprintf(help, sizeof help, "set fwd %s - "
4493                 "set packet forwarding mode", modes);
4494         cmd_set_fwd_mode.help_str = help;
4495
4496         /* string token separator is # */
4497         for (c = token; *modes != '\0'; modes++)
4498                 if (*modes == '|')
4499                         *c++ = '#';
4500                 else
4501                         *c++ = *modes;
4502         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
4503         token_struct->string_data.str = token;
4504 }
4505
4506 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
4507 struct cmd_set_burst_tx_retry_result {
4508         cmdline_fixed_string_t set;
4509         cmdline_fixed_string_t burst;
4510         cmdline_fixed_string_t tx;
4511         cmdline_fixed_string_t delay;
4512         uint32_t time;
4513         cmdline_fixed_string_t retry;
4514         uint32_t retry_num;
4515 };
4516
4517 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
4518                                         __attribute__((unused)) struct cmdline *cl,
4519                                         __attribute__((unused)) void *data)
4520 {
4521         struct cmd_set_burst_tx_retry_result *res = parsed_result;
4522
4523         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
4524                 && !strcmp(res->tx, "tx")) {
4525                 if (!strcmp(res->delay, "delay"))
4526                         burst_tx_delay_time = res->time;
4527                 if (!strcmp(res->retry, "retry"))
4528                         burst_tx_retry_num = res->retry_num;
4529         }
4530
4531 }
4532
4533 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
4534         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
4535 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
4536         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
4537                                  "burst");
4538 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
4539         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
4540 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
4541         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
4542 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
4543         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
4544 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
4545         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
4546 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
4547         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
4548
4549 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
4550         .f = cmd_set_burst_tx_retry_parsed,
4551         .help_str = "set burst tx delay (time_by_useconds) retry (retry_num)",
4552         .tokens = {
4553                 (void *)&cmd_set_burst_tx_retry_set,
4554                 (void *)&cmd_set_burst_tx_retry_burst,
4555                 (void *)&cmd_set_burst_tx_retry_tx,
4556                 (void *)&cmd_set_burst_tx_retry_delay,
4557                 (void *)&cmd_set_burst_tx_retry_time,
4558                 (void *)&cmd_set_burst_tx_retry_retry,
4559                 (void *)&cmd_set_burst_tx_retry_retry_num,
4560                 NULL,
4561         },
4562 };
4563
4564 /* *** SET PROMISC MODE *** */
4565 struct cmd_set_promisc_mode_result {
4566         cmdline_fixed_string_t set;
4567         cmdline_fixed_string_t promisc;
4568         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4569         uint8_t port_num;                /* valid if "allports" argument == 0 */
4570         cmdline_fixed_string_t mode;
4571 };
4572
4573 static void cmd_set_promisc_mode_parsed(void *parsed_result,
4574                                         __attribute__((unused)) struct cmdline *cl,
4575                                         void *allports)
4576 {
4577         struct cmd_set_promisc_mode_result *res = parsed_result;
4578         int enable;
4579         portid_t i;
4580
4581         if (!strcmp(res->mode, "on"))
4582                 enable = 1;
4583         else
4584                 enable = 0;
4585
4586         /* all ports */
4587         if (allports) {
4588                 FOREACH_PORT(i, ports) {
4589                         if (enable)
4590                                 rte_eth_promiscuous_enable(i);
4591                         else
4592                                 rte_eth_promiscuous_disable(i);
4593                 }
4594         }
4595         else {
4596                 if (enable)
4597                         rte_eth_promiscuous_enable(res->port_num);
4598                 else
4599                         rte_eth_promiscuous_disable(res->port_num);
4600         }
4601 }
4602
4603 cmdline_parse_token_string_t cmd_setpromisc_set =
4604         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
4605 cmdline_parse_token_string_t cmd_setpromisc_promisc =
4606         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
4607                                  "promisc");
4608 cmdline_parse_token_string_t cmd_setpromisc_portall =
4609         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
4610                                  "all");
4611 cmdline_parse_token_num_t cmd_setpromisc_portnum =
4612         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
4613                               UINT8);
4614 cmdline_parse_token_string_t cmd_setpromisc_mode =
4615         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
4616                                  "on#off");
4617
4618 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
4619         .f = cmd_set_promisc_mode_parsed,
4620         .data = (void *)1,
4621         .help_str = "set promisc all on|off: set promisc mode for all ports",
4622         .tokens = {
4623                 (void *)&cmd_setpromisc_set,
4624                 (void *)&cmd_setpromisc_promisc,
4625                 (void *)&cmd_setpromisc_portall,
4626                 (void *)&cmd_setpromisc_mode,
4627                 NULL,
4628         },
4629 };
4630
4631 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
4632         .f = cmd_set_promisc_mode_parsed,
4633         .data = (void *)0,
4634         .help_str = "set promisc X on|off: set promisc mode on port X",
4635         .tokens = {
4636                 (void *)&cmd_setpromisc_set,
4637                 (void *)&cmd_setpromisc_promisc,
4638                 (void *)&cmd_setpromisc_portnum,
4639                 (void *)&cmd_setpromisc_mode,
4640                 NULL,
4641         },
4642 };
4643
4644 /* *** SET ALLMULTI MODE *** */
4645 struct cmd_set_allmulti_mode_result {
4646         cmdline_fixed_string_t set;
4647         cmdline_fixed_string_t allmulti;
4648         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
4649         uint8_t port_num;                /* valid if "allports" argument == 0 */
4650         cmdline_fixed_string_t mode;
4651 };
4652
4653 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
4654                                         __attribute__((unused)) struct cmdline *cl,
4655                                         void *allports)
4656 {
4657         struct cmd_set_allmulti_mode_result *res = parsed_result;
4658         int enable;
4659         portid_t i;
4660
4661         if (!strcmp(res->mode, "on"))
4662                 enable = 1;
4663         else
4664                 enable = 0;
4665
4666         /* all ports */
4667         if (allports) {
4668                 FOREACH_PORT(i, ports) {
4669                         if (enable)
4670                                 rte_eth_allmulticast_enable(i);
4671                         else
4672                                 rte_eth_allmulticast_disable(i);
4673                 }
4674         }
4675         else {
4676                 if (enable)
4677                         rte_eth_allmulticast_enable(res->port_num);
4678                 else
4679                         rte_eth_allmulticast_disable(res->port_num);
4680         }
4681 }
4682
4683 cmdline_parse_token_string_t cmd_setallmulti_set =
4684         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
4685 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
4686         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
4687                                  "allmulti");
4688 cmdline_parse_token_string_t cmd_setallmulti_portall =
4689         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
4690                                  "all");
4691 cmdline_parse_token_num_t cmd_setallmulti_portnum =
4692         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
4693                               UINT8);
4694 cmdline_parse_token_string_t cmd_setallmulti_mode =
4695         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
4696                                  "on#off");
4697
4698 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
4699         .f = cmd_set_allmulti_mode_parsed,
4700         .data = (void *)1,
4701         .help_str = "set allmulti all on|off: set allmulti mode for all ports",
4702         .tokens = {
4703                 (void *)&cmd_setallmulti_set,
4704                 (void *)&cmd_setallmulti_allmulti,
4705                 (void *)&cmd_setallmulti_portall,
4706                 (void *)&cmd_setallmulti_mode,
4707                 NULL,
4708         },
4709 };
4710
4711 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
4712         .f = cmd_set_allmulti_mode_parsed,
4713         .data = (void *)0,
4714         .help_str = "set allmulti X on|off: set allmulti mode on port X",
4715         .tokens = {
4716                 (void *)&cmd_setallmulti_set,
4717                 (void *)&cmd_setallmulti_allmulti,
4718                 (void *)&cmd_setallmulti_portnum,
4719                 (void *)&cmd_setallmulti_mode,
4720                 NULL,
4721         },
4722 };
4723
4724 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
4725 struct cmd_link_flow_ctrl_set_result {
4726         cmdline_fixed_string_t set;
4727         cmdline_fixed_string_t flow_ctrl;
4728         cmdline_fixed_string_t rx;
4729         cmdline_fixed_string_t rx_lfc_mode;
4730         cmdline_fixed_string_t tx;
4731         cmdline_fixed_string_t tx_lfc_mode;
4732         cmdline_fixed_string_t mac_ctrl_frame_fwd;
4733         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
4734         cmdline_fixed_string_t autoneg_str;
4735         cmdline_fixed_string_t autoneg;
4736         cmdline_fixed_string_t hw_str;
4737         uint32_t high_water;
4738         cmdline_fixed_string_t lw_str;
4739         uint32_t low_water;
4740         cmdline_fixed_string_t pt_str;
4741         uint16_t pause_time;
4742         cmdline_fixed_string_t xon_str;
4743         uint16_t send_xon;
4744         uint8_t  port_id;
4745 };
4746
4747 cmdline_parse_token_string_t cmd_lfc_set_set =
4748         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4749                                 set, "set");
4750 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
4751         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4752                                 flow_ctrl, "flow_ctrl");
4753 cmdline_parse_token_string_t cmd_lfc_set_rx =
4754         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4755                                 rx, "rx");
4756 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
4757         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4758                                 rx_lfc_mode, "on#off");
4759 cmdline_parse_token_string_t cmd_lfc_set_tx =
4760         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4761                                 tx, "tx");
4762 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
4763         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4764                                 tx_lfc_mode, "on#off");
4765 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
4766         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4767                                 hw_str, "high_water");
4768 cmdline_parse_token_num_t cmd_lfc_set_high_water =
4769         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4770                                 high_water, UINT32);
4771 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
4772         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4773                                 lw_str, "low_water");
4774 cmdline_parse_token_num_t cmd_lfc_set_low_water =
4775         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4776                                 low_water, UINT32);
4777 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
4778         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4779                                 pt_str, "pause_time");
4780 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
4781         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4782                                 pause_time, UINT16);
4783 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
4784         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4785                                 xon_str, "send_xon");
4786 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
4787         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4788                                 send_xon, UINT16);
4789 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
4790         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4791                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
4792 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
4793         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4794                                 mac_ctrl_frame_fwd_mode, "on#off");
4795 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
4796         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4797                                 autoneg_str, "autoneg");
4798 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
4799         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4800                                 autoneg, "on#off");
4801 cmdline_parse_token_num_t cmd_lfc_set_portid =
4802         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
4803                                 port_id, UINT8);
4804
4805 /* forward declaration */
4806 static void
4807 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
4808                               void *data);
4809
4810 cmdline_parse_inst_t cmd_link_flow_control_set = {
4811         .f = cmd_link_flow_ctrl_set_parsed,
4812         .data = NULL,
4813         .help_str = "Configure the Ethernet flow control: set flow_ctrl rx on|off \
4814 tx on|off high_water low_water pause_time send_xon mac_ctrl_frame_fwd on|off \
4815 autoneg on|off port_id",
4816         .tokens = {
4817                 (void *)&cmd_lfc_set_set,
4818                 (void *)&cmd_lfc_set_flow_ctrl,
4819                 (void *)&cmd_lfc_set_rx,
4820                 (void *)&cmd_lfc_set_rx_mode,
4821                 (void *)&cmd_lfc_set_tx,
4822                 (void *)&cmd_lfc_set_tx_mode,
4823                 (void *)&cmd_lfc_set_high_water,
4824                 (void *)&cmd_lfc_set_low_water,
4825                 (void *)&cmd_lfc_set_pause_time,
4826                 (void *)&cmd_lfc_set_send_xon,
4827                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4828                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4829                 (void *)&cmd_lfc_set_autoneg_str,
4830                 (void *)&cmd_lfc_set_autoneg,
4831                 (void *)&cmd_lfc_set_portid,
4832                 NULL,
4833         },
4834 };
4835
4836 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
4837         .f = cmd_link_flow_ctrl_set_parsed,
4838         .data = (void *)&cmd_link_flow_control_set_rx,
4839         .help_str = "Change rx flow control parameter: set flow_ctrl "
4840                     "rx on|off port_id",
4841         .tokens = {
4842                 (void *)&cmd_lfc_set_set,
4843                 (void *)&cmd_lfc_set_flow_ctrl,
4844                 (void *)&cmd_lfc_set_rx,
4845                 (void *)&cmd_lfc_set_rx_mode,
4846                 (void *)&cmd_lfc_set_portid,
4847                 NULL,
4848         },
4849 };
4850
4851 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
4852         .f = cmd_link_flow_ctrl_set_parsed,
4853         .data = (void *)&cmd_link_flow_control_set_tx,
4854         .help_str = "Change tx flow control parameter: set flow_ctrl "
4855                     "tx on|off port_id",
4856         .tokens = {
4857                 (void *)&cmd_lfc_set_set,
4858                 (void *)&cmd_lfc_set_flow_ctrl,
4859                 (void *)&cmd_lfc_set_tx,
4860                 (void *)&cmd_lfc_set_tx_mode,
4861                 (void *)&cmd_lfc_set_portid,
4862                 NULL,
4863         },
4864 };
4865
4866 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
4867         .f = cmd_link_flow_ctrl_set_parsed,
4868         .data = (void *)&cmd_link_flow_control_set_hw,
4869         .help_str = "Change high water flow control parameter: set flow_ctrl "
4870                     "high_water value port_id",
4871         .tokens = {
4872                 (void *)&cmd_lfc_set_set,
4873                 (void *)&cmd_lfc_set_flow_ctrl,
4874                 (void *)&cmd_lfc_set_high_water_str,
4875                 (void *)&cmd_lfc_set_high_water,
4876                 (void *)&cmd_lfc_set_portid,
4877                 NULL,
4878         },
4879 };
4880
4881 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
4882         .f = cmd_link_flow_ctrl_set_parsed,
4883         .data = (void *)&cmd_link_flow_control_set_lw,
4884         .help_str = "Change low water flow control parameter: set flow_ctrl "
4885                     "low_water value port_id",
4886         .tokens = {
4887                 (void *)&cmd_lfc_set_set,
4888                 (void *)&cmd_lfc_set_flow_ctrl,
4889                 (void *)&cmd_lfc_set_low_water_str,
4890                 (void *)&cmd_lfc_set_low_water,
4891                 (void *)&cmd_lfc_set_portid,
4892                 NULL,
4893         },
4894 };
4895
4896 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
4897         .f = cmd_link_flow_ctrl_set_parsed,
4898         .data = (void *)&cmd_link_flow_control_set_pt,
4899         .help_str = "Change pause time flow control parameter: set flow_ctrl "
4900                     "pause_time value port_id",
4901         .tokens = {
4902                 (void *)&cmd_lfc_set_set,
4903                 (void *)&cmd_lfc_set_flow_ctrl,
4904                 (void *)&cmd_lfc_set_pause_time_str,
4905                 (void *)&cmd_lfc_set_pause_time,
4906                 (void *)&cmd_lfc_set_portid,
4907                 NULL,
4908         },
4909 };
4910
4911 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
4912         .f = cmd_link_flow_ctrl_set_parsed,
4913         .data = (void *)&cmd_link_flow_control_set_xon,
4914         .help_str = "Change send_xon flow control parameter: set flow_ctrl "
4915                     "send_xon value port_id",
4916         .tokens = {
4917                 (void *)&cmd_lfc_set_set,
4918                 (void *)&cmd_lfc_set_flow_ctrl,
4919                 (void *)&cmd_lfc_set_send_xon_str,
4920                 (void *)&cmd_lfc_set_send_xon,
4921                 (void *)&cmd_lfc_set_portid,
4922                 NULL,
4923         },
4924 };
4925
4926 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
4927         .f = cmd_link_flow_ctrl_set_parsed,
4928         .data = (void *)&cmd_link_flow_control_set_macfwd,
4929         .help_str = "Change mac ctrl fwd flow control parameter: set flow_ctrl "
4930                     "mac_ctrl_frame_fwd on|off port_id",
4931         .tokens = {
4932                 (void *)&cmd_lfc_set_set,
4933                 (void *)&cmd_lfc_set_flow_ctrl,
4934                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
4935                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
4936                 (void *)&cmd_lfc_set_portid,
4937                 NULL,
4938         },
4939 };
4940
4941 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
4942         .f = cmd_link_flow_ctrl_set_parsed,
4943         .data = (void *)&cmd_link_flow_control_set_autoneg,
4944         .help_str = "Change autoneg flow control parameter: set flow_ctrl "
4945                     "autoneg on|off port_id",
4946         .tokens = {
4947                 (void *)&cmd_lfc_set_set,
4948                 (void *)&cmd_lfc_set_flow_ctrl,
4949                 (void *)&cmd_lfc_set_autoneg_str,
4950                 (void *)&cmd_lfc_set_autoneg,
4951                 (void *)&cmd_lfc_set_portid,
4952                 NULL,
4953         },
4954 };
4955
4956 static void
4957 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
4958                               __attribute__((unused)) struct cmdline *cl,
4959                               void *data)
4960 {
4961         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
4962         cmdline_parse_inst_t *cmd = data;
4963         struct rte_eth_fc_conf fc_conf;
4964         int rx_fc_en = 0;
4965         int tx_fc_en = 0;
4966         int ret;
4967
4968         /*
4969          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
4970          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
4971          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
4972          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
4973          */
4974         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
4975                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
4976         };
4977
4978         /* Partial command line, retrieve current configuration */
4979         if (cmd) {
4980                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
4981                 if (ret != 0) {
4982                         printf("cannot get current flow ctrl parameters, return"
4983                                "code = %d\n", ret);
4984                         return;
4985                 }
4986
4987                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
4988                     (fc_conf.mode == RTE_FC_FULL))
4989                         rx_fc_en = 1;
4990                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
4991                     (fc_conf.mode == RTE_FC_FULL))
4992                         tx_fc_en = 1;
4993         }
4994
4995         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
4996                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
4997
4998         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
4999                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
5000
5001         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
5002
5003         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
5004                 fc_conf.high_water = res->high_water;
5005
5006         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
5007                 fc_conf.low_water = res->low_water;
5008
5009         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
5010                 fc_conf.pause_time = res->pause_time;
5011
5012         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
5013                 fc_conf.send_xon = res->send_xon;
5014
5015         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
5016                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
5017                         fc_conf.mac_ctrl_frame_fwd = 1;
5018                 else
5019                         fc_conf.mac_ctrl_frame_fwd = 0;
5020         }
5021
5022         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
5023                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
5024
5025         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
5026         if (ret != 0)
5027                 printf("bad flow contrl parameter, return code = %d \n", ret);
5028 }
5029
5030 /* *** SETUP ETHERNET PIRORITY FLOW CONTROL *** */
5031 struct cmd_priority_flow_ctrl_set_result {
5032         cmdline_fixed_string_t set;
5033         cmdline_fixed_string_t pfc_ctrl;
5034         cmdline_fixed_string_t rx;
5035         cmdline_fixed_string_t rx_pfc_mode;
5036         cmdline_fixed_string_t tx;
5037         cmdline_fixed_string_t tx_pfc_mode;
5038         uint32_t high_water;
5039         uint32_t low_water;
5040         uint16_t pause_time;
5041         uint8_t  priority;
5042         uint8_t  port_id;
5043 };
5044
5045 static void
5046 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
5047                        __attribute__((unused)) struct cmdline *cl,
5048                        __attribute__((unused)) void *data)
5049 {
5050         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
5051         struct rte_eth_pfc_conf pfc_conf;
5052         int rx_fc_enable, tx_fc_enable;
5053         int ret;
5054
5055         /*
5056          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
5057          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
5058          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
5059          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
5060          */
5061         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
5062                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
5063         };
5064
5065         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
5066         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
5067         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
5068         pfc_conf.fc.high_water = res->high_water;
5069         pfc_conf.fc.low_water  = res->low_water;
5070         pfc_conf.fc.pause_time = res->pause_time;
5071         pfc_conf.priority      = res->priority;
5072
5073         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
5074         if (ret != 0)
5075                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
5076 }
5077
5078 cmdline_parse_token_string_t cmd_pfc_set_set =
5079         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5080                                 set, "set");
5081 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
5082         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5083                                 pfc_ctrl, "pfc_ctrl");
5084 cmdline_parse_token_string_t cmd_pfc_set_rx =
5085         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5086                                 rx, "rx");
5087 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
5088         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5089                                 rx_pfc_mode, "on#off");
5090 cmdline_parse_token_string_t cmd_pfc_set_tx =
5091         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5092                                 tx, "tx");
5093 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
5094         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5095                                 tx_pfc_mode, "on#off");
5096 cmdline_parse_token_num_t cmd_pfc_set_high_water =
5097         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5098                                 high_water, UINT32);
5099 cmdline_parse_token_num_t cmd_pfc_set_low_water =
5100         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5101                                 low_water, UINT32);
5102 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
5103         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5104                                 pause_time, UINT16);
5105 cmdline_parse_token_num_t cmd_pfc_set_priority =
5106         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5107                                 priority, UINT8);
5108 cmdline_parse_token_num_t cmd_pfc_set_portid =
5109         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
5110                                 port_id, UINT8);
5111
5112 cmdline_parse_inst_t cmd_priority_flow_control_set = {
5113         .f = cmd_priority_flow_ctrl_set_parsed,
5114         .data = NULL,
5115         .help_str = "Configure the Ethernet priority flow control: set pfc_ctrl rx on|off\n\
5116                         tx on|off high_water low_water pause_time priority port_id",
5117         .tokens = {
5118                 (void *)&cmd_pfc_set_set,
5119                 (void *)&cmd_pfc_set_flow_ctrl,
5120                 (void *)&cmd_pfc_set_rx,
5121                 (void *)&cmd_pfc_set_rx_mode,
5122                 (void *)&cmd_pfc_set_tx,
5123                 (void *)&cmd_pfc_set_tx_mode,
5124                 (void *)&cmd_pfc_set_high_water,
5125                 (void *)&cmd_pfc_set_low_water,
5126                 (void *)&cmd_pfc_set_pause_time,
5127                 (void *)&cmd_pfc_set_priority,
5128                 (void *)&cmd_pfc_set_portid,
5129                 NULL,
5130         },
5131 };
5132
5133 /* *** RESET CONFIGURATION *** */
5134 struct cmd_reset_result {
5135         cmdline_fixed_string_t reset;
5136         cmdline_fixed_string_t def;
5137 };
5138
5139 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
5140                              struct cmdline *cl,
5141                              __attribute__((unused)) void *data)
5142 {
5143         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
5144         set_def_fwd_config();
5145 }
5146
5147 cmdline_parse_token_string_t cmd_reset_set =
5148         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
5149 cmdline_parse_token_string_t cmd_reset_def =
5150         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
5151                                  "default");
5152
5153 cmdline_parse_inst_t cmd_reset = {
5154         .f = cmd_reset_parsed,
5155         .data = NULL,
5156         .help_str = "set default: reset default forwarding configuration",
5157         .tokens = {
5158                 (void *)&cmd_reset_set,
5159                 (void *)&cmd_reset_def,
5160                 NULL,
5161         },
5162 };
5163
5164 /* *** START FORWARDING *** */
5165 struct cmd_start_result {
5166         cmdline_fixed_string_t start;
5167 };
5168
5169 cmdline_parse_token_string_t cmd_start_start =
5170         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
5171
5172 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
5173                              __attribute__((unused)) struct cmdline *cl,
5174                              __attribute__((unused)) void *data)
5175 {
5176         start_packet_forwarding(0);
5177 }
5178
5179 cmdline_parse_inst_t cmd_start = {
5180         .f = cmd_start_parsed,
5181         .data = NULL,
5182         .help_str = "start packet forwarding",
5183         .tokens = {
5184                 (void *)&cmd_start_start,
5185                 NULL,
5186         },
5187 };
5188
5189 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
5190 struct cmd_start_tx_first_result {
5191         cmdline_fixed_string_t start;
5192         cmdline_fixed_string_t tx_first;
5193 };
5194
5195 static void
5196 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
5197                           __attribute__((unused)) struct cmdline *cl,
5198                           __attribute__((unused)) void *data)
5199 {
5200         start_packet_forwarding(1);
5201 }
5202
5203 cmdline_parse_token_string_t cmd_start_tx_first_start =
5204         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
5205                                  "start");
5206 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
5207         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
5208                                  tx_first, "tx_first");
5209
5210 cmdline_parse_inst_t cmd_start_tx_first = {
5211         .f = cmd_start_tx_first_parsed,
5212         .data = NULL,
5213         .help_str = "start packet forwarding, after sending 1 burst of packets",
5214         .tokens = {
5215                 (void *)&cmd_start_tx_first_start,
5216                 (void *)&cmd_start_tx_first_tx_first,
5217                 NULL,
5218         },
5219 };
5220
5221 /* *** SET LINK UP *** */
5222 struct cmd_set_link_up_result {
5223         cmdline_fixed_string_t set;
5224         cmdline_fixed_string_t link_up;
5225         cmdline_fixed_string_t port;
5226         uint8_t port_id;
5227 };
5228
5229 cmdline_parse_token_string_t cmd_set_link_up_set =
5230         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
5231 cmdline_parse_token_string_t cmd_set_link_up_link_up =
5232         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
5233                                 "link-up");
5234 cmdline_parse_token_string_t cmd_set_link_up_port =
5235         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
5236 cmdline_parse_token_num_t cmd_set_link_up_port_id =
5237         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8);
5238
5239 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
5240                              __attribute__((unused)) struct cmdline *cl,
5241                              __attribute__((unused)) void *data)
5242 {
5243         struct cmd_set_link_up_result *res = parsed_result;
5244         dev_set_link_up(res->port_id);
5245 }
5246
5247 cmdline_parse_inst_t cmd_set_link_up = {
5248         .f = cmd_set_link_up_parsed,
5249         .data = NULL,
5250         .help_str = "set link-up port (port id)",
5251         .tokens = {
5252                 (void *)&cmd_set_link_up_set,
5253                 (void *)&cmd_set_link_up_link_up,
5254                 (void *)&cmd_set_link_up_port,
5255                 (void *)&cmd_set_link_up_port_id,
5256                 NULL,
5257         },
5258 };
5259
5260 /* *** SET LINK DOWN *** */
5261 struct cmd_set_link_down_result {
5262         cmdline_fixed_string_t set;
5263         cmdline_fixed_string_t link_down;
5264         cmdline_fixed_string_t port;
5265         uint8_t port_id;
5266 };
5267
5268 cmdline_parse_token_string_t cmd_set_link_down_set =
5269         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
5270 cmdline_parse_token_string_t cmd_set_link_down_link_down =
5271         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
5272                                 "link-down");
5273 cmdline_parse_token_string_t cmd_set_link_down_port =
5274         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
5275 cmdline_parse_token_num_t cmd_set_link_down_port_id =
5276         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8);
5277
5278 static void cmd_set_link_down_parsed(
5279                                 __attribute__((unused)) void *parsed_result,
5280                                 __attribute__((unused)) struct cmdline *cl,
5281                                 __attribute__((unused)) void *data)
5282 {
5283         struct cmd_set_link_down_result *res = parsed_result;
5284         dev_set_link_down(res->port_id);
5285 }
5286
5287 cmdline_parse_inst_t cmd_set_link_down = {
5288         .f = cmd_set_link_down_parsed,
5289         .data = NULL,
5290         .help_str = "set link-down port (port id)",
5291         .tokens = {
5292                 (void *)&cmd_set_link_down_set,
5293                 (void *)&cmd_set_link_down_link_down,
5294                 (void *)&cmd_set_link_down_port,
5295                 (void *)&cmd_set_link_down_port_id,
5296                 NULL,
5297         },
5298 };
5299
5300 /* *** SHOW CFG *** */
5301 struct cmd_showcfg_result {
5302         cmdline_fixed_string_t show;
5303         cmdline_fixed_string_t cfg;
5304         cmdline_fixed_string_t what;
5305 };
5306
5307 static void cmd_showcfg_parsed(void *parsed_result,
5308                                __attribute__((unused)) struct cmdline *cl,
5309                                __attribute__((unused)) void *data)
5310 {
5311         struct cmd_showcfg_result *res = parsed_result;
5312         if (!strcmp(res->what, "rxtx"))
5313                 rxtx_config_display();
5314         else if (!strcmp(res->what, "cores"))
5315                 fwd_lcores_config_display();
5316         else if (!strcmp(res->what, "fwd"))
5317                 fwd_config_display();
5318         else if (!strcmp(res->what, "txpkts"))
5319                 show_tx_pkt_segments();
5320 }
5321
5322 cmdline_parse_token_string_t cmd_showcfg_show =
5323         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
5324 cmdline_parse_token_string_t cmd_showcfg_port =
5325         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
5326 cmdline_parse_token_string_t cmd_showcfg_what =
5327         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
5328                                  "rxtx#cores#fwd#txpkts");
5329
5330 cmdline_parse_inst_t cmd_showcfg = {
5331         .f = cmd_showcfg_parsed,
5332         .data = NULL,
5333         .help_str = "show config rxtx|cores|fwd|txpkts",
5334         .tokens = {
5335                 (void *)&cmd_showcfg_show,
5336                 (void *)&cmd_showcfg_port,
5337                 (void *)&cmd_showcfg_what,
5338                 NULL,
5339         },
5340 };
5341
5342 /* *** SHOW ALL PORT INFO *** */
5343 struct cmd_showportall_result {
5344         cmdline_fixed_string_t show;
5345         cmdline_fixed_string_t port;
5346         cmdline_fixed_string_t what;
5347         cmdline_fixed_string_t all;
5348 };
5349
5350 static void cmd_showportall_parsed(void *parsed_result,
5351                                 __attribute__((unused)) struct cmdline *cl,
5352                                 __attribute__((unused)) void *data)
5353 {
5354         portid_t i;
5355
5356         struct cmd_showportall_result *res = parsed_result;
5357         if (!strcmp(res->show, "clear")) {
5358                 if (!strcmp(res->what, "stats"))
5359                         FOREACH_PORT(i, ports)
5360                                 nic_stats_clear(i);
5361                 else if (!strcmp(res->what, "xstats"))
5362                         FOREACH_PORT(i, ports)
5363                                 nic_xstats_clear(i);
5364         } else if (!strcmp(res->what, "info"))
5365                 FOREACH_PORT(i, ports)
5366                         port_infos_display(i);
5367         else if (!strcmp(res->what, "stats"))
5368                 FOREACH_PORT(i, ports)
5369                         nic_stats_display(i);
5370         else if (!strcmp(res->what, "xstats"))
5371                 FOREACH_PORT(i, ports)
5372                         nic_xstats_display(i);
5373         else if (!strcmp(res->what, "fdir"))
5374                 FOREACH_PORT(i, ports)
5375                         fdir_get_infos(i);
5376         else if (!strcmp(res->what, "stat_qmap"))
5377                 FOREACH_PORT(i, ports)
5378                         nic_stats_mapping_display(i);
5379         else if (!strcmp(res->what, "dcb_tc"))
5380                 FOREACH_PORT(i, ports)
5381                         port_dcb_info_display(i);
5382 }
5383
5384 cmdline_parse_token_string_t cmd_showportall_show =
5385         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
5386                                  "show#clear");
5387 cmdline_parse_token_string_t cmd_showportall_port =
5388         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
5389 cmdline_parse_token_string_t cmd_showportall_what =
5390         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
5391                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5392 cmdline_parse_token_string_t cmd_showportall_all =
5393         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
5394 cmdline_parse_inst_t cmd_showportall = {
5395         .f = cmd_showportall_parsed,
5396         .data = NULL,
5397         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc all",
5398         .tokens = {
5399                 (void *)&cmd_showportall_show,
5400                 (void *)&cmd_showportall_port,
5401                 (void *)&cmd_showportall_what,
5402                 (void *)&cmd_showportall_all,
5403                 NULL,
5404         },
5405 };
5406
5407 /* *** SHOW PORT INFO *** */
5408 struct cmd_showport_result {
5409         cmdline_fixed_string_t show;
5410         cmdline_fixed_string_t port;
5411         cmdline_fixed_string_t what;
5412         uint8_t portnum;
5413 };
5414
5415 static void cmd_showport_parsed(void *parsed_result,
5416                                 __attribute__((unused)) struct cmdline *cl,
5417                                 __attribute__((unused)) void *data)
5418 {
5419         struct cmd_showport_result *res = parsed_result;
5420         if (!strcmp(res->show, "clear")) {
5421                 if (!strcmp(res->what, "stats"))
5422                         nic_stats_clear(res->portnum);
5423                 else if (!strcmp(res->what, "xstats"))
5424                         nic_xstats_clear(res->portnum);
5425         } else if (!strcmp(res->what, "info"))
5426                 port_infos_display(res->portnum);
5427         else if (!strcmp(res->what, "stats"))
5428                 nic_stats_display(res->portnum);
5429         else if (!strcmp(res->what, "xstats"))
5430                 nic_xstats_display(res->portnum);
5431         else if (!strcmp(res->what, "fdir"))
5432                  fdir_get_infos(res->portnum);
5433         else if (!strcmp(res->what, "stat_qmap"))
5434                 nic_stats_mapping_display(res->portnum);
5435         else if (!strcmp(res->what, "dcb_tc"))
5436                 port_dcb_info_display(res->portnum);
5437 }
5438
5439 cmdline_parse_token_string_t cmd_showport_show =
5440         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
5441                                  "show#clear");
5442 cmdline_parse_token_string_t cmd_showport_port =
5443         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
5444 cmdline_parse_token_string_t cmd_showport_what =
5445         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
5446                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc");
5447 cmdline_parse_token_num_t cmd_showport_portnum =
5448         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8);
5449
5450 cmdline_parse_inst_t cmd_showport = {
5451         .f = cmd_showport_parsed,
5452         .data = NULL,
5453         .help_str = "show|clear port info|stats|xstats|fdir|stat_qmap|dcb_tc X (X = port number)",
5454         .tokens = {
5455                 (void *)&cmd_showport_show,
5456                 (void *)&cmd_showport_port,
5457                 (void *)&cmd_showport_what,
5458                 (void *)&cmd_showport_portnum,
5459                 NULL,
5460         },
5461 };
5462
5463 /* *** SHOW QUEUE INFO *** */
5464 struct cmd_showqueue_result {
5465         cmdline_fixed_string_t show;
5466         cmdline_fixed_string_t type;
5467         cmdline_fixed_string_t what;
5468         uint8_t portnum;
5469         uint16_t queuenum;
5470 };
5471
5472 static void
5473 cmd_showqueue_parsed(void *parsed_result,
5474         __attribute__((unused)) struct cmdline *cl,
5475         __attribute__((unused)) void *data)
5476 {
5477         struct cmd_showqueue_result *res = parsed_result;
5478
5479         if (!strcmp(res->type, "rxq"))
5480                 rx_queue_infos_display(res->portnum, res->queuenum);
5481         else if (!strcmp(res->type, "txq"))
5482                 tx_queue_infos_display(res->portnum, res->queuenum);
5483 }
5484
5485 cmdline_parse_token_string_t cmd_showqueue_show =
5486         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
5487 cmdline_parse_token_string_t cmd_showqueue_type =
5488         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
5489 cmdline_parse_token_string_t cmd_showqueue_what =
5490         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
5491 cmdline_parse_token_num_t cmd_showqueue_portnum =
5492         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8);
5493 cmdline_parse_token_num_t cmd_showqueue_queuenum =
5494         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
5495
5496 cmdline_parse_inst_t cmd_showqueue = {
5497         .f = cmd_showqueue_parsed,
5498         .data = NULL,
5499         .help_str = "show rxq|txq info <port number> <queue_number>",
5500         .tokens = {
5501                 (void *)&cmd_showqueue_show,
5502                 (void *)&cmd_showqueue_type,
5503                 (void *)&cmd_showqueue_what,
5504                 (void *)&cmd_showqueue_portnum,
5505                 (void *)&cmd_showqueue_queuenum,
5506                 NULL,
5507         },
5508 };
5509
5510 /* *** READ PORT REGISTER *** */
5511 struct cmd_read_reg_result {
5512         cmdline_fixed_string_t read;
5513         cmdline_fixed_string_t reg;
5514         uint8_t port_id;
5515         uint32_t reg_off;
5516 };
5517
5518 static void
5519 cmd_read_reg_parsed(void *parsed_result,
5520                     __attribute__((unused)) struct cmdline *cl,
5521                     __attribute__((unused)) void *data)
5522 {
5523         struct cmd_read_reg_result *res = parsed_result;
5524         port_reg_display(res->port_id, res->reg_off);
5525 }
5526
5527 cmdline_parse_token_string_t cmd_read_reg_read =
5528         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
5529 cmdline_parse_token_string_t cmd_read_reg_reg =
5530         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
5531 cmdline_parse_token_num_t cmd_read_reg_port_id =
5532         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8);
5533 cmdline_parse_token_num_t cmd_read_reg_reg_off =
5534         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
5535
5536 cmdline_parse_inst_t cmd_read_reg = {
5537         .f = cmd_read_reg_parsed,
5538         .data = NULL,
5539         .help_str = "read reg port_id reg_off",
5540         .tokens = {
5541                 (void *)&cmd_read_reg_read,
5542                 (void *)&cmd_read_reg_reg,
5543                 (void *)&cmd_read_reg_port_id,
5544                 (void *)&cmd_read_reg_reg_off,
5545                 NULL,
5546         },
5547 };
5548
5549 /* *** READ PORT REGISTER BIT FIELD *** */
5550 struct cmd_read_reg_bit_field_result {
5551         cmdline_fixed_string_t read;
5552         cmdline_fixed_string_t regfield;
5553         uint8_t port_id;
5554         uint32_t reg_off;
5555         uint8_t bit1_pos;
5556         uint8_t bit2_pos;
5557 };
5558
5559 static void
5560 cmd_read_reg_bit_field_parsed(void *parsed_result,
5561                               __attribute__((unused)) struct cmdline *cl,
5562                               __attribute__((unused)) void *data)
5563 {
5564         struct cmd_read_reg_bit_field_result *res = parsed_result;
5565         port_reg_bit_field_display(res->port_id, res->reg_off,
5566                                    res->bit1_pos, res->bit2_pos);
5567 }
5568
5569 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
5570         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
5571                                  "read");
5572 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
5573         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
5574                                  regfield, "regfield");
5575 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
5576         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
5577                               UINT8);
5578 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
5579         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
5580                               UINT32);
5581 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
5582         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
5583                               UINT8);
5584 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
5585         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
5586                               UINT8);
5587
5588 cmdline_parse_inst_t cmd_read_reg_bit_field = {
5589         .f = cmd_read_reg_bit_field_parsed,
5590         .data = NULL,
5591         .help_str = "read regfield port_id reg_off bit_x bit_y "
5592         "(read register bit field between bit_x and bit_y included)",
5593         .tokens = {
5594                 (void *)&cmd_read_reg_bit_field_read,
5595                 (void *)&cmd_read_reg_bit_field_regfield,
5596                 (void *)&cmd_read_reg_bit_field_port_id,
5597                 (void *)&cmd_read_reg_bit_field_reg_off,
5598                 (void *)&cmd_read_reg_bit_field_bit1_pos,
5599                 (void *)&cmd_read_reg_bit_field_bit2_pos,
5600                 NULL,
5601         },
5602 };
5603
5604 /* *** READ PORT REGISTER BIT *** */
5605 struct cmd_read_reg_bit_result {
5606         cmdline_fixed_string_t read;
5607         cmdline_fixed_string_t regbit;
5608         uint8_t port_id;
5609         uint32_t reg_off;
5610         uint8_t bit_pos;
5611 };
5612
5613 static void
5614 cmd_read_reg_bit_parsed(void *parsed_result,
5615                         __attribute__((unused)) struct cmdline *cl,
5616                         __attribute__((unused)) void *data)
5617 {
5618         struct cmd_read_reg_bit_result *res = parsed_result;
5619         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
5620 }
5621
5622 cmdline_parse_token_string_t cmd_read_reg_bit_read =
5623         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
5624 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
5625         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
5626                                  regbit, "regbit");
5627 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
5628         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8);
5629 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
5630         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
5631 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
5632         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
5633
5634 cmdline_parse_inst_t cmd_read_reg_bit = {
5635         .f = cmd_read_reg_bit_parsed,
5636         .data = NULL,
5637         .help_str = "read regbit port_id reg_off bit_x (0 <= bit_x <= 31)",
5638         .tokens = {
5639                 (void *)&cmd_read_reg_bit_read,
5640                 (void *)&cmd_read_reg_bit_regbit,
5641                 (void *)&cmd_read_reg_bit_port_id,
5642                 (void *)&cmd_read_reg_bit_reg_off,
5643                 (void *)&cmd_read_reg_bit_bit_pos,
5644                 NULL,
5645         },
5646 };
5647
5648 /* *** WRITE PORT REGISTER *** */
5649 struct cmd_write_reg_result {
5650         cmdline_fixed_string_t write;
5651         cmdline_fixed_string_t reg;
5652         uint8_t port_id;
5653         uint32_t reg_off;
5654         uint32_t value;
5655 };
5656
5657 static void
5658 cmd_write_reg_parsed(void *parsed_result,
5659                      __attribute__((unused)) struct cmdline *cl,
5660                      __attribute__((unused)) void *data)
5661 {
5662         struct cmd_write_reg_result *res = parsed_result;
5663         port_reg_set(res->port_id, res->reg_off, res->value);
5664 }
5665
5666 cmdline_parse_token_string_t cmd_write_reg_write =
5667         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
5668 cmdline_parse_token_string_t cmd_write_reg_reg =
5669         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
5670 cmdline_parse_token_num_t cmd_write_reg_port_id =
5671         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8);
5672 cmdline_parse_token_num_t cmd_write_reg_reg_off =
5673         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
5674 cmdline_parse_token_num_t cmd_write_reg_value =
5675         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
5676
5677 cmdline_parse_inst_t cmd_write_reg = {
5678         .f = cmd_write_reg_parsed,
5679         .data = NULL,
5680         .help_str = "write reg port_id reg_off reg_value",
5681         .tokens = {
5682                 (void *)&cmd_write_reg_write,
5683                 (void *)&cmd_write_reg_reg,
5684                 (void *)&cmd_write_reg_port_id,
5685                 (void *)&cmd_write_reg_reg_off,
5686                 (void *)&cmd_write_reg_value,
5687                 NULL,
5688         },
5689 };
5690
5691 /* *** WRITE PORT REGISTER BIT FIELD *** */
5692 struct cmd_write_reg_bit_field_result {
5693         cmdline_fixed_string_t write;
5694         cmdline_fixed_string_t regfield;
5695         uint8_t port_id;
5696         uint32_t reg_off;
5697         uint8_t bit1_pos;
5698         uint8_t bit2_pos;
5699         uint32_t value;
5700 };
5701
5702 static void
5703 cmd_write_reg_bit_field_parsed(void *parsed_result,
5704                                __attribute__((unused)) struct cmdline *cl,
5705                                __attribute__((unused)) void *data)
5706 {
5707         struct cmd_write_reg_bit_field_result *res = parsed_result;
5708         port_reg_bit_field_set(res->port_id, res->reg_off,
5709                           res->bit1_pos, res->bit2_pos, res->value);
5710 }
5711
5712 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
5713         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
5714                                  "write");
5715 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
5716         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
5717                                  regfield, "regfield");
5718 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
5719         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
5720                               UINT8);
5721 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
5722         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
5723                               UINT32);
5724 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
5725         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
5726                               UINT8);
5727 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
5728         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
5729                               UINT8);
5730 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
5731         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
5732                               UINT32);
5733
5734 cmdline_parse_inst_t cmd_write_reg_bit_field = {
5735         .f = cmd_write_reg_bit_field_parsed,
5736         .data = NULL,
5737         .help_str = "write regfield port_id reg_off bit_x bit_y reg_value"
5738         "(set register bit field between bit_x and bit_y included)",
5739         .tokens = {
5740                 (void *)&cmd_write_reg_bit_field_write,
5741                 (void *)&cmd_write_reg_bit_field_regfield,
5742                 (void *)&cmd_write_reg_bit_field_port_id,
5743                 (void *)&cmd_write_reg_bit_field_reg_off,
5744                 (void *)&cmd_write_reg_bit_field_bit1_pos,
5745                 (void *)&cmd_write_reg_bit_field_bit2_pos,
5746                 (void *)&cmd_write_reg_bit_field_value,
5747                 NULL,
5748         },
5749 };
5750
5751 /* *** WRITE PORT REGISTER BIT *** */
5752 struct cmd_write_reg_bit_result {
5753         cmdline_fixed_string_t write;
5754         cmdline_fixed_string_t regbit;
5755         uint8_t port_id;
5756         uint32_t reg_off;
5757         uint8_t bit_pos;
5758         uint8_t value;
5759 };
5760
5761 static void
5762 cmd_write_reg_bit_parsed(void *parsed_result,
5763                          __attribute__((unused)) struct cmdline *cl,
5764                          __attribute__((unused)) void *data)
5765 {
5766         struct cmd_write_reg_bit_result *res = parsed_result;
5767         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
5768 }
5769
5770 cmdline_parse_token_string_t cmd_write_reg_bit_write =
5771         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
5772                                  "write");
5773 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
5774         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
5775                                  regbit, "regbit");
5776 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
5777         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8);
5778 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
5779         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
5780 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
5781         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
5782 cmdline_parse_token_num_t cmd_write_reg_bit_value =
5783         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
5784
5785 cmdline_parse_inst_t cmd_write_reg_bit = {
5786         .f = cmd_write_reg_bit_parsed,
5787         .data = NULL,
5788         .help_str = "write regbit port_id reg_off bit_x 0/1 (0 <= bit_x <= 31)",
5789         .tokens = {
5790                 (void *)&cmd_write_reg_bit_write,
5791                 (void *)&cmd_write_reg_bit_regbit,
5792                 (void *)&cmd_write_reg_bit_port_id,
5793                 (void *)&cmd_write_reg_bit_reg_off,
5794                 (void *)&cmd_write_reg_bit_bit_pos,
5795                 (void *)&cmd_write_reg_bit_value,
5796                 NULL,
5797         },
5798 };
5799
5800 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
5801 struct cmd_read_rxd_txd_result {
5802         cmdline_fixed_string_t read;
5803         cmdline_fixed_string_t rxd_txd;
5804         uint8_t port_id;
5805         uint16_t queue_id;
5806         uint16_t desc_id;
5807 };
5808
5809 static void
5810 cmd_read_rxd_txd_parsed(void *parsed_result,
5811                         __attribute__((unused)) struct cmdline *cl,
5812                         __attribute__((unused)) void *data)
5813 {
5814         struct cmd_read_rxd_txd_result *res = parsed_result;
5815
5816         if (!strcmp(res->rxd_txd, "rxd"))
5817                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5818         else if (!strcmp(res->rxd_txd, "txd"))
5819                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
5820 }
5821
5822 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
5823         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
5824 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
5825         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
5826                                  "rxd#txd");
5827 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
5828         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8);
5829 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
5830         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
5831 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
5832         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
5833
5834 cmdline_parse_inst_t cmd_read_rxd_txd = {
5835         .f = cmd_read_rxd_txd_parsed,
5836         .data = NULL,
5837         .help_str = "read rxd|txd port_id queue_id rxd_id",
5838         .tokens = {
5839                 (void *)&cmd_read_rxd_txd_read,
5840                 (void *)&cmd_read_rxd_txd_rxd_txd,
5841                 (void *)&cmd_read_rxd_txd_port_id,
5842                 (void *)&cmd_read_rxd_txd_queue_id,
5843                 (void *)&cmd_read_rxd_txd_desc_id,
5844                 NULL,
5845         },
5846 };
5847
5848 /* *** QUIT *** */
5849 struct cmd_quit_result {
5850         cmdline_fixed_string_t quit;
5851 };
5852
5853 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
5854                             struct cmdline *cl,
5855                             __attribute__((unused)) void *data)
5856 {
5857         pmd_test_exit();
5858         cmdline_quit(cl);
5859 }
5860
5861 cmdline_parse_token_string_t cmd_quit_quit =
5862         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
5863
5864 cmdline_parse_inst_t cmd_quit = {
5865         .f = cmd_quit_parsed,
5866         .data = NULL,
5867         .help_str = "exit application",
5868         .tokens = {
5869                 (void *)&cmd_quit_quit,
5870                 NULL,
5871         },
5872 };
5873
5874 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
5875 struct cmd_mac_addr_result {
5876         cmdline_fixed_string_t mac_addr_cmd;
5877         cmdline_fixed_string_t what;
5878         uint8_t port_num;
5879         struct ether_addr address;
5880 };
5881
5882 static void cmd_mac_addr_parsed(void *parsed_result,
5883                 __attribute__((unused)) struct cmdline *cl,
5884                 __attribute__((unused)) void *data)
5885 {
5886         struct cmd_mac_addr_result *res = parsed_result;
5887         int ret;
5888
5889         if (strcmp(res->what, "add") == 0)
5890                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
5891         else
5892                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
5893
5894         /* check the return value and print it if is < 0 */
5895         if(ret < 0)
5896                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
5897
5898 }
5899
5900 cmdline_parse_token_string_t cmd_mac_addr_cmd =
5901         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
5902                                 "mac_addr");
5903 cmdline_parse_token_string_t cmd_mac_addr_what =
5904         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
5905                                 "add#remove");
5906 cmdline_parse_token_num_t cmd_mac_addr_portnum =
5907                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8);
5908 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
5909                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
5910
5911 cmdline_parse_inst_t cmd_mac_addr = {
5912         .f = cmd_mac_addr_parsed,
5913         .data = (void *)0,
5914         .help_str = "mac_addr add|remove X <address>: "
5915                         "add/remove MAC address on port X",
5916         .tokens = {
5917                 (void *)&cmd_mac_addr_cmd,
5918                 (void *)&cmd_mac_addr_what,
5919                 (void *)&cmd_mac_addr_portnum,
5920                 (void *)&cmd_mac_addr_addr,
5921                 NULL,
5922         },
5923 };
5924
5925
5926 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
5927 struct cmd_set_qmap_result {
5928         cmdline_fixed_string_t set;
5929         cmdline_fixed_string_t qmap;
5930         cmdline_fixed_string_t what;
5931         uint8_t port_id;
5932         uint16_t queue_id;
5933         uint8_t map_value;
5934 };
5935
5936 static void
5937 cmd_set_qmap_parsed(void *parsed_result,
5938                        __attribute__((unused)) struct cmdline *cl,
5939                        __attribute__((unused)) void *data)
5940 {
5941         struct cmd_set_qmap_result *res = parsed_result;
5942         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
5943
5944         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
5945 }
5946
5947 cmdline_parse_token_string_t cmd_setqmap_set =
5948         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5949                                  set, "set");
5950 cmdline_parse_token_string_t cmd_setqmap_qmap =
5951         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5952                                  qmap, "stat_qmap");
5953 cmdline_parse_token_string_t cmd_setqmap_what =
5954         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
5955                                  what, "tx#rx");
5956 cmdline_parse_token_num_t cmd_setqmap_portid =
5957         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5958                               port_id, UINT8);
5959 cmdline_parse_token_num_t cmd_setqmap_queueid =
5960         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5961                               queue_id, UINT16);
5962 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
5963         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
5964                               map_value, UINT8);
5965
5966 cmdline_parse_inst_t cmd_set_qmap = {
5967         .f = cmd_set_qmap_parsed,
5968         .data = NULL,
5969         .help_str = "Set statistics mapping value on tx|rx queue_id of port_id",
5970         .tokens = {
5971                 (void *)&cmd_setqmap_set,
5972                 (void *)&cmd_setqmap_qmap,
5973                 (void *)&cmd_setqmap_what,
5974                 (void *)&cmd_setqmap_portid,
5975                 (void *)&cmd_setqmap_queueid,
5976                 (void *)&cmd_setqmap_mapvalue,
5977                 NULL,
5978         },
5979 };
5980
5981 /* *** CONFIGURE UNICAST HASH TABLE *** */
5982 struct cmd_set_uc_hash_table {
5983         cmdline_fixed_string_t set;
5984         cmdline_fixed_string_t port;
5985         uint8_t port_id;
5986         cmdline_fixed_string_t what;
5987         struct ether_addr address;
5988         cmdline_fixed_string_t mode;
5989 };
5990
5991 static void
5992 cmd_set_uc_hash_parsed(void *parsed_result,
5993                        __attribute__((unused)) struct cmdline *cl,
5994                        __attribute__((unused)) void *data)
5995 {
5996         int ret=0;
5997         struct cmd_set_uc_hash_table *res = parsed_result;
5998
5999         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6000
6001         if (strcmp(res->what, "uta") == 0)
6002                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
6003                                                 &res->address,(uint8_t)is_on);
6004         if (ret < 0)
6005                 printf("bad unicast hash table parameter, return code = %d \n", ret);
6006
6007 }
6008
6009 cmdline_parse_token_string_t cmd_set_uc_hash_set =
6010         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6011                                  set, "set");
6012 cmdline_parse_token_string_t cmd_set_uc_hash_port =
6013         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6014                                  port, "port");
6015 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
6016         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
6017                               port_id, UINT8);
6018 cmdline_parse_token_string_t cmd_set_uc_hash_what =
6019         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6020                                  what, "uta");
6021 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
6022         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
6023                                 address);
6024 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
6025         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
6026                                  mode, "on#off");
6027
6028 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
6029         .f = cmd_set_uc_hash_parsed,
6030         .data = NULL,
6031         .help_str = "set port X uta Y on|off(X = port number,Y = MAC address)",
6032         .tokens = {
6033                 (void *)&cmd_set_uc_hash_set,
6034                 (void *)&cmd_set_uc_hash_port,
6035                 (void *)&cmd_set_uc_hash_portid,
6036                 (void *)&cmd_set_uc_hash_what,
6037                 (void *)&cmd_set_uc_hash_mac,
6038                 (void *)&cmd_set_uc_hash_mode,
6039                 NULL,
6040         },
6041 };
6042
6043 struct cmd_set_uc_all_hash_table {
6044         cmdline_fixed_string_t set;
6045         cmdline_fixed_string_t port;
6046         uint8_t port_id;
6047         cmdline_fixed_string_t what;
6048         cmdline_fixed_string_t value;
6049         cmdline_fixed_string_t mode;
6050 };
6051
6052 static void
6053 cmd_set_uc_all_hash_parsed(void *parsed_result,
6054                        __attribute__((unused)) struct cmdline *cl,
6055                        __attribute__((unused)) void *data)
6056 {
6057         int ret=0;
6058         struct cmd_set_uc_all_hash_table *res = parsed_result;
6059
6060         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6061
6062         if ((strcmp(res->what, "uta") == 0) &&
6063                 (strcmp(res->value, "all") == 0))
6064                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
6065         if (ret < 0)
6066                 printf("bad unicast hash table parameter,"
6067                         "return code = %d \n", ret);
6068 }
6069
6070 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
6071         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6072                                  set, "set");
6073 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
6074         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6075                                  port, "port");
6076 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
6077         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
6078                               port_id, UINT8);
6079 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
6080         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6081                                  what, "uta");
6082 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
6083         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6084                                 value,"all");
6085 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
6086         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
6087                                  mode, "on#off");
6088
6089 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
6090         .f = cmd_set_uc_all_hash_parsed,
6091         .data = NULL,
6092         .help_str = "set port X uta all on|off (X = port number)",
6093         .tokens = {
6094                 (void *)&cmd_set_uc_all_hash_set,
6095                 (void *)&cmd_set_uc_all_hash_port,
6096                 (void *)&cmd_set_uc_all_hash_portid,
6097                 (void *)&cmd_set_uc_all_hash_what,
6098                 (void *)&cmd_set_uc_all_hash_value,
6099                 (void *)&cmd_set_uc_all_hash_mode,
6100                 NULL,
6101         },
6102 };
6103
6104 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
6105 struct cmd_set_vf_macvlan_filter {
6106         cmdline_fixed_string_t set;
6107         cmdline_fixed_string_t port;
6108         uint8_t port_id;
6109         cmdline_fixed_string_t vf;
6110         uint8_t vf_id;
6111         struct ether_addr address;
6112         cmdline_fixed_string_t filter_type;
6113         cmdline_fixed_string_t mode;
6114 };
6115
6116 static void
6117 cmd_set_vf_macvlan_parsed(void *parsed_result,
6118                        __attribute__((unused)) struct cmdline *cl,
6119                        __attribute__((unused)) void *data)
6120 {
6121         int is_on, ret = 0;
6122         struct cmd_set_vf_macvlan_filter *res = parsed_result;
6123         struct rte_eth_mac_filter filter;
6124
6125         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
6126
6127         (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
6128
6129         /* set VF MAC filter */
6130         filter.is_vf = 1;
6131
6132         /* set VF ID */
6133         filter.dst_id = res->vf_id;
6134
6135         if (!strcmp(res->filter_type, "exact-mac"))
6136                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
6137         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
6138                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
6139         else if (!strcmp(res->filter_type, "hashmac"))
6140                 filter.filter_type = RTE_MAC_HASH_MATCH;
6141         else if (!strcmp(res->filter_type, "hashmac-vlan"))
6142                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
6143
6144         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6145
6146         if (is_on)
6147                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6148                                         RTE_ETH_FILTER_MACVLAN,
6149                                         RTE_ETH_FILTER_ADD,
6150                                          &filter);
6151         else
6152                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6153                                         RTE_ETH_FILTER_MACVLAN,
6154                                         RTE_ETH_FILTER_DELETE,
6155                                         &filter);
6156
6157         if (ret < 0)
6158                 printf("bad set MAC hash parameter, return code = %d\n", ret);
6159
6160 }
6161
6162 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
6163         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6164                                  set, "set");
6165 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
6166         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6167                                  port, "port");
6168 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
6169         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6170                               port_id, UINT8);
6171 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
6172         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6173                                  vf, "vf");
6174 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
6175         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6176                                 vf_id, UINT8);
6177 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
6178         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6179                                 address);
6180 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
6181         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6182                                 filter_type, "exact-mac#exact-mac-vlan"
6183                                 "#hashmac#hashmac-vlan");
6184 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
6185         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
6186                                  mode, "on#off");
6187
6188 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
6189         .f = cmd_set_vf_macvlan_parsed,
6190         .data = NULL,
6191         .help_str = "set port (portid) vf (vfid) (mac-addr) "
6192                         "(exact-mac|exact-mac-vlan|hashmac|hashmac-vlan) "
6193                         "on|off\n"
6194                         "exact match rule:exact match of MAC or MAC and VLAN; "
6195                         "hash match rule: hash match of MAC and exact match "
6196                         "of VLAN",
6197         .tokens = {
6198                 (void *)&cmd_set_vf_macvlan_set,
6199                 (void *)&cmd_set_vf_macvlan_port,
6200                 (void *)&cmd_set_vf_macvlan_portid,
6201                 (void *)&cmd_set_vf_macvlan_vf,
6202                 (void *)&cmd_set_vf_macvlan_vf_id,
6203                 (void *)&cmd_set_vf_macvlan_mac,
6204                 (void *)&cmd_set_vf_macvlan_filter_type,
6205                 (void *)&cmd_set_vf_macvlan_mode,
6206                 NULL,
6207         },
6208 };
6209
6210 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
6211 struct cmd_set_vf_traffic {
6212         cmdline_fixed_string_t set;
6213         cmdline_fixed_string_t port;
6214         uint8_t port_id;
6215         cmdline_fixed_string_t vf;
6216         uint8_t vf_id;
6217         cmdline_fixed_string_t what;
6218         cmdline_fixed_string_t mode;
6219 };
6220
6221 static void
6222 cmd_set_vf_traffic_parsed(void *parsed_result,
6223                        __attribute__((unused)) struct cmdline *cl,
6224                        __attribute__((unused)) void *data)
6225 {
6226         struct cmd_set_vf_traffic *res = parsed_result;
6227         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
6228         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
6229
6230         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
6231 }
6232
6233 cmdline_parse_token_string_t cmd_setvf_traffic_set =
6234         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6235                                  set, "set");
6236 cmdline_parse_token_string_t cmd_setvf_traffic_port =
6237         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6238                                  port, "port");
6239 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
6240         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6241                               port_id, UINT8);
6242 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
6243         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6244                                  vf, "vf");
6245 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
6246         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
6247                               vf_id, UINT8);
6248 cmdline_parse_token_string_t cmd_setvf_traffic_what =
6249         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6250                                  what, "tx#rx");
6251 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
6252         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
6253                                  mode, "on#off");
6254
6255 cmdline_parse_inst_t cmd_set_vf_traffic = {
6256         .f = cmd_set_vf_traffic_parsed,
6257         .data = NULL,
6258         .help_str = "set port X vf Y rx|tx on|off"
6259                         "(X = port number,Y = vf id)",
6260         .tokens = {
6261                 (void *)&cmd_setvf_traffic_set,
6262                 (void *)&cmd_setvf_traffic_port,
6263                 (void *)&cmd_setvf_traffic_portid,
6264                 (void *)&cmd_setvf_traffic_vf,
6265                 (void *)&cmd_setvf_traffic_vfid,
6266                 (void *)&cmd_setvf_traffic_what,
6267                 (void *)&cmd_setvf_traffic_mode,
6268                 NULL,
6269         },
6270 };
6271
6272 /* *** CONFIGURE VF RECEIVE MODE *** */
6273 struct cmd_set_vf_rxmode {
6274         cmdline_fixed_string_t set;
6275         cmdline_fixed_string_t port;
6276         uint8_t port_id;
6277         cmdline_fixed_string_t vf;
6278         uint8_t vf_id;
6279         cmdline_fixed_string_t what;
6280         cmdline_fixed_string_t mode;
6281         cmdline_fixed_string_t on;
6282 };
6283
6284 static void
6285 cmd_set_vf_rxmode_parsed(void *parsed_result,
6286                        __attribute__((unused)) struct cmdline *cl,
6287                        __attribute__((unused)) void *data)
6288 {
6289         int ret;
6290         uint16_t rx_mode = 0;
6291         struct cmd_set_vf_rxmode *res = parsed_result;
6292
6293         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
6294         if (!strcmp(res->what,"rxmode")) {
6295                 if (!strcmp(res->mode, "AUPE"))
6296                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
6297                 else if (!strcmp(res->mode, "ROPE"))
6298                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
6299                 else if (!strcmp(res->mode, "BAM"))
6300                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
6301                 else if (!strncmp(res->mode, "MPE",3))
6302                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
6303         }
6304
6305         ret = rte_eth_dev_set_vf_rxmode(res->port_id,res->vf_id,rx_mode,(uint8_t)is_on);
6306         if (ret < 0)
6307                 printf("bad VF receive mode parameter, return code = %d \n",
6308                 ret);
6309 }
6310
6311 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
6312         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6313                                  set, "set");
6314 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
6315         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6316                                  port, "port");
6317 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
6318         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6319                               port_id, UINT8);
6320 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
6321         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6322                                  vf, "vf");
6323 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
6324         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
6325                               vf_id, UINT8);
6326 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
6327         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6328                                  what, "rxmode");
6329 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
6330         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6331                                  mode, "AUPE#ROPE#BAM#MPE");
6332 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
6333         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
6334                                  on, "on#off");
6335
6336 cmdline_parse_inst_t cmd_set_vf_rxmode = {
6337         .f = cmd_set_vf_rxmode_parsed,
6338         .data = NULL,
6339         .help_str = "set port X vf Y rxmode AUPE|ROPE|BAM|MPE on|off",
6340         .tokens = {
6341                 (void *)&cmd_set_vf_rxmode_set,
6342                 (void *)&cmd_set_vf_rxmode_port,
6343                 (void *)&cmd_set_vf_rxmode_portid,
6344                 (void *)&cmd_set_vf_rxmode_vf,
6345                 (void *)&cmd_set_vf_rxmode_vfid,
6346                 (void *)&cmd_set_vf_rxmode_what,
6347                 (void *)&cmd_set_vf_rxmode_mode,
6348                 (void *)&cmd_set_vf_rxmode_on,
6349                 NULL,
6350         },
6351 };
6352
6353 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
6354 struct cmd_vf_mac_addr_result {
6355         cmdline_fixed_string_t mac_addr_cmd;
6356         cmdline_fixed_string_t what;
6357         cmdline_fixed_string_t port;
6358         uint8_t port_num;
6359         cmdline_fixed_string_t vf;
6360         uint8_t vf_num;
6361         struct ether_addr address;
6362 };
6363
6364 static void cmd_vf_mac_addr_parsed(void *parsed_result,
6365                 __attribute__((unused)) struct cmdline *cl,
6366                 __attribute__((unused)) void *data)
6367 {
6368         struct cmd_vf_mac_addr_result *res = parsed_result;
6369         int ret = 0;
6370
6371         if (strcmp(res->what, "add") == 0)
6372                 ret = rte_eth_dev_mac_addr_add(res->port_num,
6373                                         &res->address, res->vf_num);
6374         if(ret < 0)
6375                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
6376
6377 }
6378
6379 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
6380         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6381                                 mac_addr_cmd,"mac_addr");
6382 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
6383         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6384                                 what,"add");
6385 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
6386         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6387                                 port,"port");
6388 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
6389         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6390                                 port_num, UINT8);
6391 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
6392         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
6393                                 vf,"vf");
6394 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
6395         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
6396                                 vf_num, UINT8);
6397 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
6398         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
6399                                 address);
6400
6401 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
6402         .f = cmd_vf_mac_addr_parsed,
6403         .data = (void *)0,
6404         .help_str = "mac_addr add port X vf Y ethaddr:(X = port number,"
6405         "Y = VF number)add MAC address filtering for a VF on port X",
6406         .tokens = {
6407                 (void *)&cmd_vf_mac_addr_cmd,
6408                 (void *)&cmd_vf_mac_addr_what,
6409                 (void *)&cmd_vf_mac_addr_port,
6410                 (void *)&cmd_vf_mac_addr_portnum,
6411                 (void *)&cmd_vf_mac_addr_vf,
6412                 (void *)&cmd_vf_mac_addr_vfnum,
6413                 (void *)&cmd_vf_mac_addr_addr,
6414                 NULL,
6415         },
6416 };
6417
6418 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
6419 struct cmd_vf_rx_vlan_filter {
6420         cmdline_fixed_string_t rx_vlan;
6421         cmdline_fixed_string_t what;
6422         uint16_t vlan_id;
6423         cmdline_fixed_string_t port;
6424         uint8_t port_id;
6425         cmdline_fixed_string_t vf;
6426         uint64_t vf_mask;
6427 };
6428
6429 static void
6430 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
6431                           __attribute__((unused)) struct cmdline *cl,
6432                           __attribute__((unused)) void *data)
6433 {
6434         struct cmd_vf_rx_vlan_filter *res = parsed_result;
6435
6436         if (!strcmp(res->what, "add"))
6437                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 1);
6438         else
6439                 set_vf_rx_vlan(res->port_id, res->vlan_id,res->vf_mask, 0);
6440 }
6441
6442 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
6443         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6444                                  rx_vlan, "rx_vlan");
6445 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
6446         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6447                                  what, "add#rm");
6448 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
6449         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6450                               vlan_id, UINT16);
6451 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
6452         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6453                                  port, "port");
6454 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
6455         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6456                               port_id, UINT8);
6457 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
6458         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6459                                  vf, "vf");
6460 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
6461         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
6462                               vf_mask, UINT64);
6463
6464 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
6465         .f = cmd_vf_rx_vlan_filter_parsed,
6466         .data = NULL,
6467         .help_str = "rx_vlan add|rm X port Y vf Z (X = VLAN ID,"
6468                 "Y = port number,Z = hexadecimal VF mask)",
6469         .tokens = {
6470                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
6471                 (void *)&cmd_vf_rx_vlan_filter_what,
6472                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
6473                 (void *)&cmd_vf_rx_vlan_filter_port,
6474                 (void *)&cmd_vf_rx_vlan_filter_portid,
6475                 (void *)&cmd_vf_rx_vlan_filter_vf,
6476                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
6477                 NULL,
6478         },
6479 };
6480
6481 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
6482 struct cmd_queue_rate_limit_result {
6483         cmdline_fixed_string_t set;
6484         cmdline_fixed_string_t port;
6485         uint8_t port_num;
6486         cmdline_fixed_string_t queue;
6487         uint8_t queue_num;
6488         cmdline_fixed_string_t rate;
6489         uint16_t rate_num;
6490 };
6491
6492 static void cmd_queue_rate_limit_parsed(void *parsed_result,
6493                 __attribute__((unused)) struct cmdline *cl,
6494                 __attribute__((unused)) void *data)
6495 {
6496         struct cmd_queue_rate_limit_result *res = parsed_result;
6497         int ret = 0;
6498
6499         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6500                 && (strcmp(res->queue, "queue") == 0)
6501                 && (strcmp(res->rate, "rate") == 0))
6502                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
6503                                         res->rate_num);
6504         if (ret < 0)
6505                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
6506
6507 }
6508
6509 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
6510         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6511                                 set, "set");
6512 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
6513         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6514                                 port, "port");
6515 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
6516         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6517                                 port_num, UINT8);
6518 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
6519         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6520                                 queue, "queue");
6521 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
6522         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6523                                 queue_num, UINT8);
6524 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
6525         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
6526                                 rate, "rate");
6527 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
6528         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
6529                                 rate_num, UINT16);
6530
6531 cmdline_parse_inst_t cmd_queue_rate_limit = {
6532         .f = cmd_queue_rate_limit_parsed,
6533         .data = (void *)0,
6534         .help_str = "set port X queue Y rate Z:(X = port number,"
6535         "Y = queue number,Z = rate number)set rate limit for a queue on port X",
6536         .tokens = {
6537                 (void *)&cmd_queue_rate_limit_set,
6538                 (void *)&cmd_queue_rate_limit_port,
6539                 (void *)&cmd_queue_rate_limit_portnum,
6540                 (void *)&cmd_queue_rate_limit_queue,
6541                 (void *)&cmd_queue_rate_limit_queuenum,
6542                 (void *)&cmd_queue_rate_limit_rate,
6543                 (void *)&cmd_queue_rate_limit_ratenum,
6544                 NULL,
6545         },
6546 };
6547
6548 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
6549 struct cmd_vf_rate_limit_result {
6550         cmdline_fixed_string_t set;
6551         cmdline_fixed_string_t port;
6552         uint8_t port_num;
6553         cmdline_fixed_string_t vf;
6554         uint8_t vf_num;
6555         cmdline_fixed_string_t rate;
6556         uint16_t rate_num;
6557         cmdline_fixed_string_t q_msk;
6558         uint64_t q_msk_val;
6559 };
6560
6561 static void cmd_vf_rate_limit_parsed(void *parsed_result,
6562                 __attribute__((unused)) struct cmdline *cl,
6563                 __attribute__((unused)) void *data)
6564 {
6565         struct cmd_vf_rate_limit_result *res = parsed_result;
6566         int ret = 0;
6567
6568         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
6569                 && (strcmp(res->vf, "vf") == 0)
6570                 && (strcmp(res->rate, "rate") == 0)
6571                 && (strcmp(res->q_msk, "queue_mask") == 0))
6572                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
6573                                         res->rate_num, res->q_msk_val);
6574         if (ret < 0)
6575                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
6576
6577 }
6578
6579 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
6580         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6581                                 set, "set");
6582 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
6583         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6584                                 port, "port");
6585 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
6586         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6587                                 port_num, UINT8);
6588 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
6589         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6590                                 vf, "vf");
6591 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
6592         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6593                                 vf_num, UINT8);
6594 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
6595         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6596                                 rate, "rate");
6597 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
6598         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6599                                 rate_num, UINT16);
6600 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
6601         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
6602                                 q_msk, "queue_mask");
6603 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
6604         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
6605                                 q_msk_val, UINT64);
6606
6607 cmdline_parse_inst_t cmd_vf_rate_limit = {
6608         .f = cmd_vf_rate_limit_parsed,
6609         .data = (void *)0,
6610         .help_str = "set port X vf Y rate Z queue_mask V:(X = port number,"
6611         "Y = VF number,Z = rate number, V = queue mask value)set rate limit "
6612         "for queues of VF on port X",
6613         .tokens = {
6614                 (void *)&cmd_vf_rate_limit_set,
6615                 (void *)&cmd_vf_rate_limit_port,
6616                 (void *)&cmd_vf_rate_limit_portnum,
6617                 (void *)&cmd_vf_rate_limit_vf,
6618                 (void *)&cmd_vf_rate_limit_vfnum,
6619                 (void *)&cmd_vf_rate_limit_rate,
6620                 (void *)&cmd_vf_rate_limit_ratenum,
6621                 (void *)&cmd_vf_rate_limit_q_msk,
6622                 (void *)&cmd_vf_rate_limit_q_msk_val,
6623                 NULL,
6624         },
6625 };
6626
6627 /* *** ADD TUNNEL FILTER OF A PORT *** */
6628 struct cmd_tunnel_filter_result {
6629         cmdline_fixed_string_t cmd;
6630         cmdline_fixed_string_t what;
6631         uint8_t port_id;
6632         struct ether_addr outer_mac;
6633         struct ether_addr inner_mac;
6634         cmdline_ipaddr_t ip_value;
6635         uint16_t inner_vlan;
6636         cmdline_fixed_string_t tunnel_type;
6637         cmdline_fixed_string_t filter_type;
6638         uint32_t tenant_id;
6639         uint16_t queue_num;
6640 };
6641
6642 static void
6643 cmd_tunnel_filter_parsed(void *parsed_result,
6644                           __attribute__((unused)) struct cmdline *cl,
6645                           __attribute__((unused)) void *data)
6646 {
6647         struct cmd_tunnel_filter_result *res = parsed_result;
6648         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
6649         int ret = 0;
6650
6651         tunnel_filter_conf.outer_mac = &res->outer_mac;
6652         tunnel_filter_conf.inner_mac = &res->inner_mac;
6653         tunnel_filter_conf.inner_vlan = res->inner_vlan;
6654
6655         if (res->ip_value.family == AF_INET) {
6656                 tunnel_filter_conf.ip_addr.ipv4_addr =
6657                         res->ip_value.addr.ipv4.s_addr;
6658                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
6659         } else {
6660                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
6661                         &(res->ip_value.addr.ipv6),
6662                         sizeof(struct in6_addr));
6663                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
6664         }
6665
6666         if (!strcmp(res->filter_type, "imac-ivlan"))
6667                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
6668         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
6669                 tunnel_filter_conf.filter_type =
6670                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
6671         else if (!strcmp(res->filter_type, "imac-tenid"))
6672                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
6673         else if (!strcmp(res->filter_type, "imac"))
6674                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
6675         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
6676                 tunnel_filter_conf.filter_type =
6677                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
6678         else {
6679                 printf("The filter type is not supported");
6680                 return;
6681         }
6682
6683         if (!strcmp(res->tunnel_type, "vxlan"))
6684                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
6685         else if (!strcmp(res->tunnel_type, "nvgre"))
6686                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
6687         else {
6688                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
6689                 return;
6690         }
6691
6692         tunnel_filter_conf.tenant_id = res->tenant_id;
6693         tunnel_filter_conf.queue_id = res->queue_num;
6694         if (!strcmp(res->what, "add"))
6695                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6696                                         RTE_ETH_FILTER_TUNNEL,
6697                                         RTE_ETH_FILTER_ADD,
6698                                         &tunnel_filter_conf);
6699         else
6700                 ret = rte_eth_dev_filter_ctrl(res->port_id,
6701                                         RTE_ETH_FILTER_TUNNEL,
6702                                         RTE_ETH_FILTER_DELETE,
6703                                         &tunnel_filter_conf);
6704         if (ret < 0)
6705                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
6706                                 strerror(-ret));
6707
6708 }
6709 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
6710         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6711         cmd, "tunnel_filter");
6712 cmdline_parse_token_string_t cmd_tunnel_filter_what =
6713         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6714         what, "add#rm");
6715 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
6716         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6717         port_id, UINT8);
6718 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
6719         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6720         outer_mac);
6721 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
6722         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6723         inner_mac);
6724 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
6725         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6726         inner_vlan, UINT16);
6727 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
6728         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
6729         ip_value);
6730 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
6731         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6732         tunnel_type, "vxlan#nvgre");
6733
6734 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
6735         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
6736         filter_type, "imac-ivlan#imac-ivlan-tenid#imac-tenid#"
6737                 "imac#omac-imac-tenid");
6738 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
6739         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6740         tenant_id, UINT32);
6741 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
6742         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
6743         queue_num, UINT16);
6744
6745 cmdline_parse_inst_t cmd_tunnel_filter = {
6746         .f = cmd_tunnel_filter_parsed,
6747         .data = (void *)0,
6748         .help_str = "add/rm tunnel filter of a port: "
6749                         "tunnel_filter add port_id outer_mac inner_mac ip "
6750                         "inner_vlan tunnel_type(vxlan|nvgre) filter_type "
6751                         "(imac-ivlan|imac-ivlan-tenid|imac-tenid|"
6752                         "imac|omac-imac-tenid) "
6753                         "tenant_id queue_num",
6754         .tokens = {
6755                 (void *)&cmd_tunnel_filter_cmd,
6756                 (void *)&cmd_tunnel_filter_what,
6757                 (void *)&cmd_tunnel_filter_port_id,
6758                 (void *)&cmd_tunnel_filter_outer_mac,
6759                 (void *)&cmd_tunnel_filter_inner_mac,
6760                 (void *)&cmd_tunnel_filter_ip_value,
6761                 (void *)&cmd_tunnel_filter_innner_vlan,
6762                 (void *)&cmd_tunnel_filter_tunnel_type,
6763                 (void *)&cmd_tunnel_filter_filter_type,
6764                 (void *)&cmd_tunnel_filter_tenant_id,
6765                 (void *)&cmd_tunnel_filter_queue_num,
6766                 NULL,
6767         },
6768 };
6769
6770 /* *** CONFIGURE TUNNEL UDP PORT *** */
6771 struct cmd_tunnel_udp_config {
6772         cmdline_fixed_string_t cmd;
6773         cmdline_fixed_string_t what;
6774         uint16_t udp_port;
6775         uint8_t port_id;
6776 };
6777
6778 static void
6779 cmd_tunnel_udp_config_parsed(void *parsed_result,
6780                           __attribute__((unused)) struct cmdline *cl,
6781                           __attribute__((unused)) void *data)
6782 {
6783         struct cmd_tunnel_udp_config *res = parsed_result;
6784         struct rte_eth_udp_tunnel tunnel_udp;
6785         int ret;
6786
6787         tunnel_udp.udp_port = res->udp_port;
6788
6789         if (!strcmp(res->cmd, "rx_vxlan_port"))
6790                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
6791
6792         if (!strcmp(res->what, "add"))
6793                 ret = rte_eth_dev_udp_tunnel_add(res->port_id, &tunnel_udp);
6794         else
6795                 ret = rte_eth_dev_udp_tunnel_delete(res->port_id, &tunnel_udp);
6796
6797         if (ret < 0)
6798                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
6799 }
6800
6801 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
6802         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6803                                 cmd, "rx_vxlan_port");
6804 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
6805         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
6806                                 what, "add#rm");
6807 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
6808         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6809                                 udp_port, UINT16);
6810 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
6811         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
6812                                 port_id, UINT8);
6813
6814 cmdline_parse_inst_t cmd_tunnel_udp_config = {
6815         .f = cmd_tunnel_udp_config_parsed,
6816         .data = (void *)0,
6817         .help_str = "add/rm an tunneling UDP port filter: "
6818                         "rx_vxlan_port add udp_port port_id",
6819         .tokens = {
6820                 (void *)&cmd_tunnel_udp_config_cmd,
6821                 (void *)&cmd_tunnel_udp_config_what,
6822                 (void *)&cmd_tunnel_udp_config_udp_port,
6823                 (void *)&cmd_tunnel_udp_config_port_id,
6824                 NULL,
6825         },
6826 };
6827
6828 /* *** GLOBAL CONFIG *** */
6829 struct cmd_global_config_result {
6830         cmdline_fixed_string_t cmd;
6831         uint8_t port_id;
6832         cmdline_fixed_string_t cfg_type;
6833         uint8_t len;
6834 };
6835
6836 static void
6837 cmd_global_config_parsed(void *parsed_result,
6838                          __attribute__((unused)) struct cmdline *cl,
6839                          __attribute__((unused)) void *data)
6840 {
6841         struct cmd_global_config_result *res = parsed_result;
6842         struct rte_eth_global_cfg conf;
6843         int ret;
6844
6845         memset(&conf, 0, sizeof(conf));
6846         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
6847         conf.cfg.gre_key_len = res->len;
6848         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
6849                                       RTE_ETH_FILTER_SET, &conf);
6850         if (ret != 0)
6851                 printf("Global config error\n");
6852 }
6853
6854 cmdline_parse_token_string_t cmd_global_config_cmd =
6855         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
6856                 "global_config");
6857 cmdline_parse_token_num_t cmd_global_config_port_id =
6858         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8);
6859 cmdline_parse_token_string_t cmd_global_config_type =
6860         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
6861                 cfg_type, "gre-key-len");
6862 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
6863         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
6864                 len, UINT8);
6865
6866 cmdline_parse_inst_t cmd_global_config = {
6867         .f = cmd_global_config_parsed,
6868         .data = (void *)NULL,
6869         .help_str = "global_config <port_id> gre-key-len <number>",
6870         .tokens = {
6871                 (void *)&cmd_global_config_cmd,
6872                 (void *)&cmd_global_config_port_id,
6873                 (void *)&cmd_global_config_type,
6874                 (void *)&cmd_global_config_gre_key_len,
6875                 NULL,
6876         },
6877 };
6878
6879 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
6880 struct cmd_set_mirror_mask_result {
6881         cmdline_fixed_string_t set;
6882         cmdline_fixed_string_t port;
6883         uint8_t port_id;
6884         cmdline_fixed_string_t mirror;
6885         uint8_t rule_id;
6886         cmdline_fixed_string_t what;
6887         cmdline_fixed_string_t value;
6888         cmdline_fixed_string_t dstpool;
6889         uint8_t dstpool_id;
6890         cmdline_fixed_string_t on;
6891 };
6892
6893 cmdline_parse_token_string_t cmd_mirror_mask_set =
6894         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6895                                 set, "set");
6896 cmdline_parse_token_string_t cmd_mirror_mask_port =
6897         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6898                                 port, "port");
6899 cmdline_parse_token_num_t cmd_mirror_mask_portid =
6900         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6901                                 port_id, UINT8);
6902 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
6903         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6904                                 mirror, "mirror-rule");
6905 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
6906         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6907                                 rule_id, UINT8);
6908 cmdline_parse_token_string_t cmd_mirror_mask_what =
6909         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6910                                 what, "pool-mirror-up#pool-mirror-down"
6911                                       "#vlan-mirror");
6912 cmdline_parse_token_string_t cmd_mirror_mask_value =
6913         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6914                                 value, NULL);
6915 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
6916         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6917                                 dstpool, "dst-pool");
6918 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
6919         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
6920                                 dstpool_id, UINT8);
6921 cmdline_parse_token_string_t cmd_mirror_mask_on =
6922         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
6923                                 on, "on#off");
6924
6925 static void
6926 cmd_set_mirror_mask_parsed(void *parsed_result,
6927                        __attribute__((unused)) struct cmdline *cl,
6928                        __attribute__((unused)) void *data)
6929 {
6930         int ret,nb_item,i;
6931         struct cmd_set_mirror_mask_result *res = parsed_result;
6932         struct rte_eth_mirror_conf mr_conf;
6933
6934         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
6935
6936         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
6937
6938         mr_conf.dst_pool = res->dstpool_id;
6939
6940         if (!strcmp(res->what, "pool-mirror-up")) {
6941                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6942                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
6943         } else if (!strcmp(res->what, "pool-mirror-down")) {
6944                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
6945                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
6946         } else if (!strcmp(res->what, "vlan-mirror")) {
6947                 mr_conf.rule_type = ETH_MIRROR_VLAN;
6948                 nb_item = parse_item_list(res->value, "vlan",
6949                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
6950                 if (nb_item <= 0)
6951                         return;
6952
6953                 for (i = 0; i < nb_item; i++) {
6954                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
6955                                 printf("Invalid vlan_id: must be < 4096\n");
6956                                 return;
6957                         }
6958
6959                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
6960                         mr_conf.vlan.vlan_mask |= 1ULL << i;
6961                 }
6962         }
6963
6964         if (!strcmp(res->on, "on"))
6965                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6966                                                 res->rule_id, 1);
6967         else
6968                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
6969                                                 res->rule_id, 0);
6970         if (ret < 0)
6971                 printf("mirror rule add error: (%s)\n", strerror(-ret));
6972 }
6973
6974 cmdline_parse_inst_t cmd_set_mirror_mask = {
6975                 .f = cmd_set_mirror_mask_parsed,
6976                 .data = NULL,
6977                 .help_str = "set port X mirror-rule Y pool-mirror-up|pool-mirror-down|vlan-mirror"
6978                             " pool_mask|vlan_id[,vlan_id]* dst-pool Z on|off",
6979                 .tokens = {
6980                         (void *)&cmd_mirror_mask_set,
6981                         (void *)&cmd_mirror_mask_port,
6982                         (void *)&cmd_mirror_mask_portid,
6983                         (void *)&cmd_mirror_mask_mirror,
6984                         (void *)&cmd_mirror_mask_ruleid,
6985                         (void *)&cmd_mirror_mask_what,
6986                         (void *)&cmd_mirror_mask_value,
6987                         (void *)&cmd_mirror_mask_dstpool,
6988                         (void *)&cmd_mirror_mask_poolid,
6989                         (void *)&cmd_mirror_mask_on,
6990                         NULL,
6991                 },
6992 };
6993
6994 /* *** CONFIGURE VM MIRROR UDLINK/DOWNLINK RULE *** */
6995 struct cmd_set_mirror_link_result {
6996         cmdline_fixed_string_t set;
6997         cmdline_fixed_string_t port;
6998         uint8_t port_id;
6999         cmdline_fixed_string_t mirror;
7000         uint8_t rule_id;
7001         cmdline_fixed_string_t what;
7002         cmdline_fixed_string_t dstpool;
7003         uint8_t dstpool_id;
7004         cmdline_fixed_string_t on;
7005 };
7006
7007 cmdline_parse_token_string_t cmd_mirror_link_set =
7008         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7009                                  set, "set");
7010 cmdline_parse_token_string_t cmd_mirror_link_port =
7011         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7012                                 port, "port");
7013 cmdline_parse_token_num_t cmd_mirror_link_portid =
7014         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7015                                 port_id, UINT8);
7016 cmdline_parse_token_string_t cmd_mirror_link_mirror =
7017         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7018                                 mirror, "mirror-rule");
7019 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
7020         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7021                             rule_id, UINT8);
7022 cmdline_parse_token_string_t cmd_mirror_link_what =
7023         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7024                                 what, "uplink-mirror#downlink-mirror");
7025 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
7026         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7027                                 dstpool, "dst-pool");
7028 cmdline_parse_token_num_t cmd_mirror_link_poolid =
7029         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
7030                                 dstpool_id, UINT8);
7031 cmdline_parse_token_string_t cmd_mirror_link_on =
7032         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
7033                                 on, "on#off");
7034
7035 static void
7036 cmd_set_mirror_link_parsed(void *parsed_result,
7037                        __attribute__((unused)) struct cmdline *cl,
7038                        __attribute__((unused)) void *data)
7039 {
7040         int ret;
7041         struct cmd_set_mirror_link_result *res = parsed_result;
7042         struct rte_eth_mirror_conf mr_conf;
7043
7044         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
7045         if (!strcmp(res->what, "uplink-mirror"))
7046                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
7047         else
7048                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
7049
7050         mr_conf.dst_pool = res->dstpool_id;
7051
7052         if (!strcmp(res->on, "on"))
7053                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7054                                                 res->rule_id, 1);
7055         else
7056                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
7057                                                 res->rule_id, 0);
7058
7059         /* check the return value and print it if is < 0 */
7060         if (ret < 0)
7061                 printf("mirror rule add error: (%s)\n", strerror(-ret));
7062
7063 }
7064
7065 cmdline_parse_inst_t cmd_set_mirror_link = {
7066                 .f = cmd_set_mirror_link_parsed,
7067                 .data = NULL,
7068                 .help_str = "set port X mirror-rule Y uplink-mirror|"
7069                         "downlink-mirror dst-pool Z on|off",
7070                 .tokens = {
7071                         (void *)&cmd_mirror_link_set,
7072                         (void *)&cmd_mirror_link_port,
7073                         (void *)&cmd_mirror_link_portid,
7074                         (void *)&cmd_mirror_link_mirror,
7075                         (void *)&cmd_mirror_link_ruleid,
7076                         (void *)&cmd_mirror_link_what,
7077                         (void *)&cmd_mirror_link_dstpool,
7078                         (void *)&cmd_mirror_link_poolid,
7079                         (void *)&cmd_mirror_link_on,
7080                         NULL,
7081                 },
7082 };
7083
7084 /* *** RESET VM MIRROR RULE *** */
7085 struct cmd_rm_mirror_rule_result {
7086         cmdline_fixed_string_t reset;
7087         cmdline_fixed_string_t port;
7088         uint8_t port_id;
7089         cmdline_fixed_string_t mirror;
7090         uint8_t rule_id;
7091 };
7092
7093 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
7094         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7095                                  reset, "reset");
7096 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
7097         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7098                                 port, "port");
7099 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
7100         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7101                                 port_id, UINT8);
7102 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
7103         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
7104                                 mirror, "mirror-rule");
7105 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
7106         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
7107                                 rule_id, UINT8);
7108
7109 static void
7110 cmd_reset_mirror_rule_parsed(void *parsed_result,
7111                        __attribute__((unused)) struct cmdline *cl,
7112                        __attribute__((unused)) void *data)
7113 {
7114         int ret;
7115         struct cmd_set_mirror_link_result *res = parsed_result;
7116         /* check rule_id */
7117         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
7118         if(ret < 0)
7119                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
7120 }
7121
7122 cmdline_parse_inst_t cmd_reset_mirror_rule = {
7123                 .f = cmd_reset_mirror_rule_parsed,
7124                 .data = NULL,
7125                 .help_str = "reset port X mirror-rule Y",
7126                 .tokens = {
7127                         (void *)&cmd_rm_mirror_rule_reset,
7128                         (void *)&cmd_rm_mirror_rule_port,
7129                         (void *)&cmd_rm_mirror_rule_portid,
7130                         (void *)&cmd_rm_mirror_rule_mirror,
7131                         (void *)&cmd_rm_mirror_rule_ruleid,
7132                         NULL,
7133                 },
7134 };
7135
7136 /* ******************************************************************************** */
7137
7138 struct cmd_dump_result {
7139         cmdline_fixed_string_t dump;
7140 };
7141
7142 static void
7143 dump_struct_sizes(void)
7144 {
7145 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
7146         DUMP_SIZE(struct rte_mbuf);
7147         DUMP_SIZE(struct rte_mempool);
7148         DUMP_SIZE(struct rte_ring);
7149 #undef DUMP_SIZE
7150 }
7151
7152 static void cmd_dump_parsed(void *parsed_result,
7153                             __attribute__((unused)) struct cmdline *cl,
7154                             __attribute__((unused)) void *data)
7155 {
7156         struct cmd_dump_result *res = parsed_result;
7157
7158         if (!strcmp(res->dump, "dump_physmem"))
7159                 rte_dump_physmem_layout(stdout);
7160         else if (!strcmp(res->dump, "dump_memzone"))
7161                 rte_memzone_dump(stdout);
7162         else if (!strcmp(res->dump, "dump_log_history"))
7163                 rte_log_dump_history(stdout);
7164         else if (!strcmp(res->dump, "dump_struct_sizes"))
7165                 dump_struct_sizes();
7166         else if (!strcmp(res->dump, "dump_ring"))
7167                 rte_ring_list_dump(stdout);
7168         else if (!strcmp(res->dump, "dump_mempool"))
7169                 rte_mempool_list_dump(stdout);
7170         else if (!strcmp(res->dump, "dump_devargs"))
7171                 rte_eal_devargs_dump(stdout);
7172 }
7173
7174 cmdline_parse_token_string_t cmd_dump_dump =
7175         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
7176                 "dump_physmem#"
7177                 "dump_memzone#"
7178                 "dump_log_history#"
7179                 "dump_struct_sizes#"
7180                 "dump_ring#"
7181                 "dump_mempool#"
7182                 "dump_devargs");
7183
7184 cmdline_parse_inst_t cmd_dump = {
7185         .f = cmd_dump_parsed,  /* function to call */
7186         .data = NULL,      /* 2nd arg of func */
7187         .help_str = "dump status",
7188         .tokens = {        /* token list, NULL terminated */
7189                 (void *)&cmd_dump_dump,
7190                 NULL,
7191         },
7192 };
7193
7194 /* ******************************************************************************** */
7195
7196 struct cmd_dump_one_result {
7197         cmdline_fixed_string_t dump;
7198         cmdline_fixed_string_t name;
7199 };
7200
7201 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
7202                                 __attribute__((unused)) void *data)
7203 {
7204         struct cmd_dump_one_result *res = parsed_result;
7205
7206         if (!strcmp(res->dump, "dump_ring")) {
7207                 struct rte_ring *r;
7208                 r = rte_ring_lookup(res->name);
7209                 if (r == NULL) {
7210                         cmdline_printf(cl, "Cannot find ring\n");
7211                         return;
7212                 }
7213                 rte_ring_dump(stdout, r);
7214         } else if (!strcmp(res->dump, "dump_mempool")) {
7215                 struct rte_mempool *mp;
7216                 mp = rte_mempool_lookup(res->name);
7217                 if (mp == NULL) {
7218                         cmdline_printf(cl, "Cannot find mempool\n");
7219                         return;
7220                 }
7221                 rte_mempool_dump(stdout, mp);
7222         }
7223 }
7224
7225 cmdline_parse_token_string_t cmd_dump_one_dump =
7226         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
7227                                  "dump_ring#dump_mempool");
7228
7229 cmdline_parse_token_string_t cmd_dump_one_name =
7230         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
7231
7232 cmdline_parse_inst_t cmd_dump_one = {
7233         .f = cmd_dump_one_parsed,  /* function to call */
7234         .data = NULL,      /* 2nd arg of func */
7235         .help_str = "dump one ring/mempool: dump_ring|dump_mempool <name>",
7236         .tokens = {        /* token list, NULL terminated */
7237                 (void *)&cmd_dump_one_dump,
7238                 (void *)&cmd_dump_one_name,
7239                 NULL,
7240         },
7241 };
7242
7243 /* *** Add/Del syn filter *** */
7244 struct cmd_syn_filter_result {
7245         cmdline_fixed_string_t filter;
7246         uint8_t port_id;
7247         cmdline_fixed_string_t ops;
7248         cmdline_fixed_string_t priority;
7249         cmdline_fixed_string_t high;
7250         cmdline_fixed_string_t queue;
7251         uint16_t queue_id;
7252 };
7253
7254 static void
7255 cmd_syn_filter_parsed(void *parsed_result,
7256                         __attribute__((unused)) struct cmdline *cl,
7257                         __attribute__((unused)) void *data)
7258 {
7259         struct cmd_syn_filter_result *res = parsed_result;
7260         struct rte_eth_syn_filter syn_filter;
7261         int ret = 0;
7262
7263         ret = rte_eth_dev_filter_supported(res->port_id,
7264                                         RTE_ETH_FILTER_SYN);
7265         if (ret < 0) {
7266                 printf("syn filter is not supported on port %u.\n",
7267                                 res->port_id);
7268                 return;
7269         }
7270
7271         memset(&syn_filter, 0, sizeof(syn_filter));
7272
7273         if (!strcmp(res->ops, "add")) {
7274                 if (!strcmp(res->high, "high"))
7275                         syn_filter.hig_pri = 1;
7276                 else
7277                         syn_filter.hig_pri = 0;
7278
7279                 syn_filter.queue = res->queue_id;
7280                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7281                                                 RTE_ETH_FILTER_SYN,
7282                                                 RTE_ETH_FILTER_ADD,
7283                                                 &syn_filter);
7284         } else
7285                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7286                                                 RTE_ETH_FILTER_SYN,
7287                                                 RTE_ETH_FILTER_DELETE,
7288                                                 &syn_filter);
7289
7290         if (ret < 0)
7291                 printf("syn filter programming error: (%s)\n",
7292                                 strerror(-ret));
7293 }
7294
7295 cmdline_parse_token_string_t cmd_syn_filter_filter =
7296         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7297         filter, "syn_filter");
7298 cmdline_parse_token_num_t cmd_syn_filter_port_id =
7299         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7300         port_id, UINT8);
7301 cmdline_parse_token_string_t cmd_syn_filter_ops =
7302         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7303         ops, "add#del");
7304 cmdline_parse_token_string_t cmd_syn_filter_priority =
7305         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7306                                 priority, "priority");
7307 cmdline_parse_token_string_t cmd_syn_filter_high =
7308         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7309                                 high, "high#low");
7310 cmdline_parse_token_string_t cmd_syn_filter_queue =
7311         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
7312                                 queue, "queue");
7313 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
7314         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
7315                                 queue_id, UINT16);
7316
7317 cmdline_parse_inst_t cmd_syn_filter = {
7318         .f = cmd_syn_filter_parsed,
7319         .data = NULL,
7320         .help_str = "add/delete syn filter",
7321         .tokens = {
7322                 (void *)&cmd_syn_filter_filter,
7323                 (void *)&cmd_syn_filter_port_id,
7324                 (void *)&cmd_syn_filter_ops,
7325                 (void *)&cmd_syn_filter_priority,
7326                 (void *)&cmd_syn_filter_high,
7327                 (void *)&cmd_syn_filter_queue,
7328                 (void *)&cmd_syn_filter_queue_id,
7329                 NULL,
7330         },
7331 };
7332
7333 /* *** ADD/REMOVE A 2tuple FILTER *** */
7334 struct cmd_2tuple_filter_result {
7335         cmdline_fixed_string_t filter;
7336         uint8_t  port_id;
7337         cmdline_fixed_string_t ops;
7338         cmdline_fixed_string_t dst_port;
7339         uint16_t dst_port_value;
7340         cmdline_fixed_string_t protocol;
7341         uint8_t protocol_value;
7342         cmdline_fixed_string_t mask;
7343         uint8_t  mask_value;
7344         cmdline_fixed_string_t tcp_flags;
7345         uint8_t tcp_flags_value;
7346         cmdline_fixed_string_t priority;
7347         uint8_t  priority_value;
7348         cmdline_fixed_string_t queue;
7349         uint16_t  queue_id;
7350 };
7351
7352 static void
7353 cmd_2tuple_filter_parsed(void *parsed_result,
7354                         __attribute__((unused)) struct cmdline *cl,
7355                         __attribute__((unused)) void *data)
7356 {
7357         struct rte_eth_ntuple_filter filter;
7358         struct cmd_2tuple_filter_result *res = parsed_result;
7359         int ret = 0;
7360
7361         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7362         if (ret < 0) {
7363                 printf("ntuple filter is not supported on port %u.\n",
7364                         res->port_id);
7365                 return;
7366         }
7367
7368         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7369
7370         filter.flags = RTE_2TUPLE_FLAGS;
7371         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7372         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7373         filter.proto = res->protocol_value;
7374         filter.priority = res->priority_value;
7375         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7376                 printf("nonzero tcp_flags is only meaningful"
7377                         " when protocol is TCP.\n");
7378                 return;
7379         }
7380         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7381                 printf("invalid TCP flags.\n");
7382                 return;
7383         }
7384
7385         if (res->tcp_flags_value != 0) {
7386                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7387                 filter.tcp_flags = res->tcp_flags_value;
7388         }
7389
7390         /* need convert to big endian. */
7391         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7392         filter.queue = res->queue_id;
7393
7394         if (!strcmp(res->ops, "add"))
7395                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7396                                 RTE_ETH_FILTER_NTUPLE,
7397                                 RTE_ETH_FILTER_ADD,
7398                                 &filter);
7399         else
7400                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7401                                 RTE_ETH_FILTER_NTUPLE,
7402                                 RTE_ETH_FILTER_DELETE,
7403                                 &filter);
7404         if (ret < 0)
7405                 printf("2tuple filter programming error: (%s)\n",
7406                         strerror(-ret));
7407
7408 }
7409
7410 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
7411         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7412                                  filter, "2tuple_filter");
7413 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
7414         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7415                                 port_id, UINT8);
7416 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
7417         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7418                                  ops, "add#del");
7419 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
7420         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7421                                 dst_port, "dst_port");
7422 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
7423         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7424                                 dst_port_value, UINT16);
7425 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
7426         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7427                                 protocol, "protocol");
7428 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
7429         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7430                                 protocol_value, UINT8);
7431 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
7432         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7433                                 mask, "mask");
7434 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
7435         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7436                                 mask_value, INT8);
7437 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
7438         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7439                                 tcp_flags, "tcp_flags");
7440 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
7441         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7442                                 tcp_flags_value, UINT8);
7443 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
7444         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7445                                 priority, "priority");
7446 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
7447         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7448                                 priority_value, UINT8);
7449 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
7450         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
7451                                 queue, "queue");
7452 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
7453         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
7454                                 queue_id, UINT16);
7455
7456 cmdline_parse_inst_t cmd_2tuple_filter = {
7457         .f = cmd_2tuple_filter_parsed,
7458         .data = NULL,
7459         .help_str = "add a 2tuple filter",
7460         .tokens = {
7461                 (void *)&cmd_2tuple_filter_filter,
7462                 (void *)&cmd_2tuple_filter_port_id,
7463                 (void *)&cmd_2tuple_filter_ops,
7464                 (void *)&cmd_2tuple_filter_dst_port,
7465                 (void *)&cmd_2tuple_filter_dst_port_value,
7466                 (void *)&cmd_2tuple_filter_protocol,
7467                 (void *)&cmd_2tuple_filter_protocol_value,
7468                 (void *)&cmd_2tuple_filter_mask,
7469                 (void *)&cmd_2tuple_filter_mask_value,
7470                 (void *)&cmd_2tuple_filter_tcp_flags,
7471                 (void *)&cmd_2tuple_filter_tcp_flags_value,
7472                 (void *)&cmd_2tuple_filter_priority,
7473                 (void *)&cmd_2tuple_filter_priority_value,
7474                 (void *)&cmd_2tuple_filter_queue,
7475                 (void *)&cmd_2tuple_filter_queue_id,
7476                 NULL,
7477         },
7478 };
7479
7480 /* *** ADD/REMOVE A 5tuple FILTER *** */
7481 struct cmd_5tuple_filter_result {
7482         cmdline_fixed_string_t filter;
7483         uint8_t  port_id;
7484         cmdline_fixed_string_t ops;
7485         cmdline_fixed_string_t dst_ip;
7486         cmdline_ipaddr_t dst_ip_value;
7487         cmdline_fixed_string_t src_ip;
7488         cmdline_ipaddr_t src_ip_value;
7489         cmdline_fixed_string_t dst_port;
7490         uint16_t dst_port_value;
7491         cmdline_fixed_string_t src_port;
7492         uint16_t src_port_value;
7493         cmdline_fixed_string_t protocol;
7494         uint8_t protocol_value;
7495         cmdline_fixed_string_t mask;
7496         uint8_t  mask_value;
7497         cmdline_fixed_string_t tcp_flags;
7498         uint8_t tcp_flags_value;
7499         cmdline_fixed_string_t priority;
7500         uint8_t  priority_value;
7501         cmdline_fixed_string_t queue;
7502         uint16_t  queue_id;
7503 };
7504
7505 static void
7506 cmd_5tuple_filter_parsed(void *parsed_result,
7507                         __attribute__((unused)) struct cmdline *cl,
7508                         __attribute__((unused)) void *data)
7509 {
7510         struct rte_eth_ntuple_filter filter;
7511         struct cmd_5tuple_filter_result *res = parsed_result;
7512         int ret = 0;
7513
7514         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
7515         if (ret < 0) {
7516                 printf("ntuple filter is not supported on port %u.\n",
7517                         res->port_id);
7518                 return;
7519         }
7520
7521         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
7522
7523         filter.flags = RTE_5TUPLE_FLAGS;
7524         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
7525         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
7526         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
7527         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
7528         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
7529         filter.proto = res->protocol_value;
7530         filter.priority = res->priority_value;
7531         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
7532                 printf("nonzero tcp_flags is only meaningful"
7533                         " when protocol is TCP.\n");
7534                 return;
7535         }
7536         if (res->tcp_flags_value > TCP_FLAG_ALL) {
7537                 printf("invalid TCP flags.\n");
7538                 return;
7539         }
7540
7541         if (res->tcp_flags_value != 0) {
7542                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
7543                 filter.tcp_flags = res->tcp_flags_value;
7544         }
7545
7546         if (res->dst_ip_value.family == AF_INET)
7547                 /* no need to convert, already big endian. */
7548                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
7549         else {
7550                 if (filter.dst_ip_mask == 0) {
7551                         printf("can not support ipv6 involved compare.\n");
7552                         return;
7553                 }
7554                 filter.dst_ip = 0;
7555         }
7556
7557         if (res->src_ip_value.family == AF_INET)
7558                 /* no need to convert, already big endian. */
7559                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
7560         else {
7561                 if (filter.src_ip_mask == 0) {
7562                         printf("can not support ipv6 involved compare.\n");
7563                         return;
7564                 }
7565                 filter.src_ip = 0;
7566         }
7567         /* need convert to big endian. */
7568         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
7569         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
7570         filter.queue = res->queue_id;
7571
7572         if (!strcmp(res->ops, "add"))
7573                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7574                                 RTE_ETH_FILTER_NTUPLE,
7575                                 RTE_ETH_FILTER_ADD,
7576                                 &filter);
7577         else
7578                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7579                                 RTE_ETH_FILTER_NTUPLE,
7580                                 RTE_ETH_FILTER_DELETE,
7581                                 &filter);
7582         if (ret < 0)
7583                 printf("5tuple filter programming error: (%s)\n",
7584                         strerror(-ret));
7585 }
7586
7587 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
7588         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7589                                  filter, "5tuple_filter");
7590 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
7591         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7592                                 port_id, UINT8);
7593 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
7594         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7595                                  ops, "add#del");
7596 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
7597         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7598                                 dst_ip, "dst_ip");
7599 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
7600         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7601                                 dst_ip_value);
7602 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
7603         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7604                                 src_ip, "src_ip");
7605 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
7606         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
7607                                 src_ip_value);
7608 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
7609         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7610                                 dst_port, "dst_port");
7611 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
7612         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7613                                 dst_port_value, UINT16);
7614 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
7615         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7616                                 src_port, "src_port");
7617 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
7618         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7619                                 src_port_value, UINT16);
7620 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
7621         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7622                                 protocol, "protocol");
7623 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
7624         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7625                                 protocol_value, UINT8);
7626 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
7627         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7628                                 mask, "mask");
7629 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
7630         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7631                                 mask_value, INT8);
7632 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
7633         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7634                                 tcp_flags, "tcp_flags");
7635 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
7636         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7637                                 tcp_flags_value, UINT8);
7638 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
7639         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7640                                 priority, "priority");
7641 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
7642         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7643                                 priority_value, UINT8);
7644 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
7645         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
7646                                 queue, "queue");
7647 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
7648         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
7649                                 queue_id, UINT16);
7650
7651 cmdline_parse_inst_t cmd_5tuple_filter = {
7652         .f = cmd_5tuple_filter_parsed,
7653         .data = NULL,
7654         .help_str = "add/del a 5tuple filter",
7655         .tokens = {
7656                 (void *)&cmd_5tuple_filter_filter,
7657                 (void *)&cmd_5tuple_filter_port_id,
7658                 (void *)&cmd_5tuple_filter_ops,
7659                 (void *)&cmd_5tuple_filter_dst_ip,
7660                 (void *)&cmd_5tuple_filter_dst_ip_value,
7661                 (void *)&cmd_5tuple_filter_src_ip,
7662                 (void *)&cmd_5tuple_filter_src_ip_value,
7663                 (void *)&cmd_5tuple_filter_dst_port,
7664                 (void *)&cmd_5tuple_filter_dst_port_value,
7665                 (void *)&cmd_5tuple_filter_src_port,
7666                 (void *)&cmd_5tuple_filter_src_port_value,
7667                 (void *)&cmd_5tuple_filter_protocol,
7668                 (void *)&cmd_5tuple_filter_protocol_value,
7669                 (void *)&cmd_5tuple_filter_mask,
7670                 (void *)&cmd_5tuple_filter_mask_value,
7671                 (void *)&cmd_5tuple_filter_tcp_flags,
7672                 (void *)&cmd_5tuple_filter_tcp_flags_value,
7673                 (void *)&cmd_5tuple_filter_priority,
7674                 (void *)&cmd_5tuple_filter_priority_value,
7675                 (void *)&cmd_5tuple_filter_queue,
7676                 (void *)&cmd_5tuple_filter_queue_id,
7677                 NULL,
7678         },
7679 };
7680
7681 /* *** ADD/REMOVE A flex FILTER *** */
7682 struct cmd_flex_filter_result {
7683         cmdline_fixed_string_t filter;
7684         cmdline_fixed_string_t ops;
7685         uint8_t port_id;
7686         cmdline_fixed_string_t len;
7687         uint8_t len_value;
7688         cmdline_fixed_string_t bytes;
7689         cmdline_fixed_string_t bytes_value;
7690         cmdline_fixed_string_t mask;
7691         cmdline_fixed_string_t mask_value;
7692         cmdline_fixed_string_t priority;
7693         uint8_t priority_value;
7694         cmdline_fixed_string_t queue;
7695         uint16_t queue_id;
7696 };
7697
7698 static int xdigit2val(unsigned char c)
7699 {
7700         int val;
7701         if (isdigit(c))
7702                 val = c - '0';
7703         else if (isupper(c))
7704                 val = c - 'A' + 10;
7705         else
7706                 val = c - 'a' + 10;
7707         return val;
7708 }
7709
7710 static void
7711 cmd_flex_filter_parsed(void *parsed_result,
7712                           __attribute__((unused)) struct cmdline *cl,
7713                           __attribute__((unused)) void *data)
7714 {
7715         int ret = 0;
7716         struct rte_eth_flex_filter filter;
7717         struct cmd_flex_filter_result *res = parsed_result;
7718         char *bytes_ptr, *mask_ptr;
7719         uint16_t len, i, j = 0;
7720         char c;
7721         int val;
7722         uint8_t byte = 0;
7723
7724         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
7725                 printf("the len exceed the max length 128\n");
7726                 return;
7727         }
7728         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
7729         filter.len = res->len_value;
7730         filter.priority = res->priority_value;
7731         filter.queue = res->queue_id;
7732         bytes_ptr = res->bytes_value;
7733         mask_ptr = res->mask_value;
7734
7735          /* translate bytes string to array. */
7736         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
7737                 (bytes_ptr[1] == 'X')))
7738                 bytes_ptr += 2;
7739         len = strnlen(bytes_ptr, res->len_value * 2);
7740         if (len == 0 || (len % 8 != 0)) {
7741                 printf("please check len and bytes input\n");
7742                 return;
7743         }
7744         for (i = 0; i < len; i++) {
7745                 c = bytes_ptr[i];
7746                 if (isxdigit(c) == 0) {
7747                         /* invalid characters. */
7748                         printf("invalid input\n");
7749                         return;
7750                 }
7751                 val = xdigit2val(c);
7752                 if (i % 2) {
7753                         byte |= val;
7754                         filter.bytes[j] = byte;
7755                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
7756                         j++;
7757                         byte = 0;
7758                 } else
7759                         byte |= val << 4;
7760         }
7761         printf("\n");
7762          /* translate mask string to uint8_t array. */
7763         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
7764                 (mask_ptr[1] == 'X')))
7765                 mask_ptr += 2;
7766         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
7767         if (len == 0) {
7768                 printf("invalid input\n");
7769                 return;
7770         }
7771         j = 0;
7772         byte = 0;
7773         for (i = 0; i < len; i++) {
7774                 c = mask_ptr[i];
7775                 if (isxdigit(c) == 0) {
7776                         /* invalid characters. */
7777                         printf("invalid input\n");
7778                         return;
7779                 }
7780                 val = xdigit2val(c);
7781                 if (i % 2) {
7782                         byte |= val;
7783                         filter.mask[j] = byte;
7784                         printf("mask[%d]:%02x ", j, filter.mask[j]);
7785                         j++;
7786                         byte = 0;
7787                 } else
7788                         byte |= val << 4;
7789         }
7790         printf("\n");
7791
7792         if (!strcmp(res->ops, "add"))
7793                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7794                                 RTE_ETH_FILTER_FLEXIBLE,
7795                                 RTE_ETH_FILTER_ADD,
7796                                 &filter);
7797         else
7798                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7799                                 RTE_ETH_FILTER_FLEXIBLE,
7800                                 RTE_ETH_FILTER_DELETE,
7801                                 &filter);
7802
7803         if (ret < 0)
7804                 printf("flex filter setting error: (%s)\n", strerror(-ret));
7805 }
7806
7807 cmdline_parse_token_string_t cmd_flex_filter_filter =
7808         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7809                                 filter, "flex_filter");
7810 cmdline_parse_token_num_t cmd_flex_filter_port_id =
7811         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7812                                 port_id, UINT8);
7813 cmdline_parse_token_string_t cmd_flex_filter_ops =
7814         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7815                                 ops, "add#del");
7816 cmdline_parse_token_string_t cmd_flex_filter_len =
7817         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7818                                 len, "len");
7819 cmdline_parse_token_num_t cmd_flex_filter_len_value =
7820         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7821                                 len_value, UINT8);
7822 cmdline_parse_token_string_t cmd_flex_filter_bytes =
7823         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7824                                 bytes, "bytes");
7825 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
7826         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7827                                 bytes_value, NULL);
7828 cmdline_parse_token_string_t cmd_flex_filter_mask =
7829         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7830                                 mask, "mask");
7831 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
7832         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7833                                 mask_value, NULL);
7834 cmdline_parse_token_string_t cmd_flex_filter_priority =
7835         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7836                                 priority, "priority");
7837 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
7838         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7839                                 priority_value, UINT8);
7840 cmdline_parse_token_string_t cmd_flex_filter_queue =
7841         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
7842                                 queue, "queue");
7843 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
7844         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
7845                                 queue_id, UINT16);
7846 cmdline_parse_inst_t cmd_flex_filter = {
7847         .f = cmd_flex_filter_parsed,
7848         .data = NULL,
7849         .help_str = "add/del a flex filter",
7850         .tokens = {
7851                 (void *)&cmd_flex_filter_filter,
7852                 (void *)&cmd_flex_filter_port_id,
7853                 (void *)&cmd_flex_filter_ops,
7854                 (void *)&cmd_flex_filter_len,
7855                 (void *)&cmd_flex_filter_len_value,
7856                 (void *)&cmd_flex_filter_bytes,
7857                 (void *)&cmd_flex_filter_bytes_value,
7858                 (void *)&cmd_flex_filter_mask,
7859                 (void *)&cmd_flex_filter_mask_value,
7860                 (void *)&cmd_flex_filter_priority,
7861                 (void *)&cmd_flex_filter_priority_value,
7862                 (void *)&cmd_flex_filter_queue,
7863                 (void *)&cmd_flex_filter_queue_id,
7864                 NULL,
7865         },
7866 };
7867
7868 /* *** Filters Control *** */
7869
7870 /* *** deal with ethertype filter *** */
7871 struct cmd_ethertype_filter_result {
7872         cmdline_fixed_string_t filter;
7873         uint8_t port_id;
7874         cmdline_fixed_string_t ops;
7875         cmdline_fixed_string_t mac;
7876         struct ether_addr mac_addr;
7877         cmdline_fixed_string_t ethertype;
7878         uint16_t ethertype_value;
7879         cmdline_fixed_string_t drop;
7880         cmdline_fixed_string_t queue;
7881         uint16_t  queue_id;
7882 };
7883
7884 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
7885         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7886                                  filter, "ethertype_filter");
7887 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
7888         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7889                               port_id, UINT8);
7890 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
7891         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7892                                  ops, "add#del");
7893 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
7894         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7895                                  mac, "mac_addr#mac_ignr");
7896 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
7897         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
7898                                      mac_addr);
7899 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
7900         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7901                                  ethertype, "ethertype");
7902 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
7903         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7904                               ethertype_value, UINT16);
7905 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
7906         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7907                                  drop, "drop#fwd");
7908 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
7909         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
7910                                  queue, "queue");
7911 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
7912         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
7913                               queue_id, UINT16);
7914
7915 static void
7916 cmd_ethertype_filter_parsed(void *parsed_result,
7917                           __attribute__((unused)) struct cmdline *cl,
7918                           __attribute__((unused)) void *data)
7919 {
7920         struct cmd_ethertype_filter_result *res = parsed_result;
7921         struct rte_eth_ethertype_filter filter;
7922         int ret = 0;
7923
7924         ret = rte_eth_dev_filter_supported(res->port_id,
7925                         RTE_ETH_FILTER_ETHERTYPE);
7926         if (ret < 0) {
7927                 printf("ethertype filter is not supported on port %u.\n",
7928                         res->port_id);
7929                 return;
7930         }
7931
7932         memset(&filter, 0, sizeof(filter));
7933         if (!strcmp(res->mac, "mac_addr")) {
7934                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
7935                 (void)rte_memcpy(&filter.mac_addr, &res->mac_addr,
7936                         sizeof(struct ether_addr));
7937         }
7938         if (!strcmp(res->drop, "drop"))
7939                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
7940         filter.ether_type = res->ethertype_value;
7941         filter.queue = res->queue_id;
7942
7943         if (!strcmp(res->ops, "add"))
7944                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7945                                 RTE_ETH_FILTER_ETHERTYPE,
7946                                 RTE_ETH_FILTER_ADD,
7947                                 &filter);
7948         else
7949                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7950                                 RTE_ETH_FILTER_ETHERTYPE,
7951                                 RTE_ETH_FILTER_DELETE,
7952                                 &filter);
7953         if (ret < 0)
7954                 printf("ethertype filter programming error: (%s)\n",
7955                         strerror(-ret));
7956 }
7957
7958 cmdline_parse_inst_t cmd_ethertype_filter = {
7959         .f = cmd_ethertype_filter_parsed,
7960         .data = NULL,
7961         .help_str = "add or delete an ethertype filter entry",
7962         .tokens = {
7963                 (void *)&cmd_ethertype_filter_filter,
7964                 (void *)&cmd_ethertype_filter_port_id,
7965                 (void *)&cmd_ethertype_filter_ops,
7966                 (void *)&cmd_ethertype_filter_mac,
7967                 (void *)&cmd_ethertype_filter_mac_addr,
7968                 (void *)&cmd_ethertype_filter_ethertype,
7969                 (void *)&cmd_ethertype_filter_ethertype_value,
7970                 (void *)&cmd_ethertype_filter_drop,
7971                 (void *)&cmd_ethertype_filter_queue,
7972                 (void *)&cmd_ethertype_filter_queue_id,
7973                 NULL,
7974         },
7975 };
7976
7977 /* *** deal with flow director filter *** */
7978 struct cmd_flow_director_result {
7979         cmdline_fixed_string_t flow_director_filter;
7980         uint8_t port_id;
7981         cmdline_fixed_string_t mode;
7982         cmdline_fixed_string_t mode_value;
7983         cmdline_fixed_string_t ops;
7984         cmdline_fixed_string_t flow;
7985         cmdline_fixed_string_t flow_type;
7986         cmdline_fixed_string_t ether;
7987         uint16_t ether_type;
7988         cmdline_fixed_string_t src;
7989         cmdline_ipaddr_t ip_src;
7990         uint16_t port_src;
7991         cmdline_fixed_string_t dst;
7992         cmdline_ipaddr_t ip_dst;
7993         uint16_t port_dst;
7994         cmdline_fixed_string_t verify_tag;
7995         uint32_t verify_tag_value;
7996         cmdline_fixed_string_t vlan;
7997         uint16_t vlan_value;
7998         cmdline_fixed_string_t flexbytes;
7999         cmdline_fixed_string_t flexbytes_value;
8000         cmdline_fixed_string_t pf_vf;
8001         cmdline_fixed_string_t drop;
8002         cmdline_fixed_string_t queue;
8003         uint16_t  queue_id;
8004         cmdline_fixed_string_t fd_id;
8005         uint32_t  fd_id_value;
8006         cmdline_fixed_string_t mac;
8007         struct ether_addr mac_addr;
8008         cmdline_fixed_string_t tunnel;
8009         cmdline_fixed_string_t tunnel_type;
8010         cmdline_fixed_string_t tunnel_id;
8011         uint32_t tunnel_id_value;
8012 };
8013
8014 static inline int
8015 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
8016 {
8017         char s[256];
8018         const char *p, *p0 = q_arg;
8019         char *end;
8020         unsigned long int_fld;
8021         char *str_fld[max_num];
8022         int i;
8023         unsigned size;
8024         int ret = -1;
8025
8026         p = strchr(p0, '(');
8027         if (p == NULL)
8028                 return -1;
8029         ++p;
8030         p0 = strchr(p, ')');
8031         if (p0 == NULL)
8032                 return -1;
8033
8034         size = p0 - p;
8035         if (size >= sizeof(s))
8036                 return -1;
8037
8038         snprintf(s, sizeof(s), "%.*s", size, p);
8039         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8040         if (ret < 0 || ret > max_num)
8041                 return -1;
8042         for (i = 0; i < ret; i++) {
8043                 errno = 0;
8044                 int_fld = strtoul(str_fld[i], &end, 0);
8045                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
8046                         return -1;
8047                 flexbytes[i] = (uint8_t)int_fld;
8048         }
8049         return ret;
8050 }
8051
8052 static uint16_t
8053 str2flowtype(char *string)
8054 {
8055         uint8_t i = 0;
8056         static const struct {
8057                 char str[32];
8058                 uint16_t type;
8059         } flowtype_str[] = {
8060                 {"raw", RTE_ETH_FLOW_RAW},
8061                 {"ipv4", RTE_ETH_FLOW_IPV4},
8062                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
8063                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
8064                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
8065                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
8066                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
8067                 {"ipv6", RTE_ETH_FLOW_IPV6},
8068                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
8069                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
8070                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
8071                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
8072                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
8073                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
8074         };
8075
8076         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
8077                 if (!strcmp(flowtype_str[i].str, string))
8078                         return flowtype_str[i].type;
8079         }
8080         return RTE_ETH_FLOW_UNKNOWN;
8081 }
8082
8083 static enum rte_eth_fdir_tunnel_type
8084 str2fdir_tunneltype(char *string)
8085 {
8086         uint8_t i = 0;
8087
8088         static const struct {
8089                 char str[32];
8090                 enum rte_eth_fdir_tunnel_type type;
8091         } tunneltype_str[] = {
8092                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
8093                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
8094         };
8095
8096         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
8097                 if (!strcmp(tunneltype_str[i].str, string))
8098                         return tunneltype_str[i].type;
8099         }
8100         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
8101 }
8102
8103 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
8104 do { \
8105         if ((ip_addr).family == AF_INET) \
8106                 (ip) = (ip_addr).addr.ipv4.s_addr; \
8107         else { \
8108                 printf("invalid parameter.\n"); \
8109                 return; \
8110         } \
8111 } while (0)
8112
8113 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
8114 do { \
8115         if ((ip_addr).family == AF_INET6) \
8116                 (void)rte_memcpy(&(ip), \
8117                                  &((ip_addr).addr.ipv6), \
8118                                  sizeof(struct in6_addr)); \
8119         else { \
8120                 printf("invalid parameter.\n"); \
8121                 return; \
8122         } \
8123 } while (0)
8124
8125 static void
8126 cmd_flow_director_filter_parsed(void *parsed_result,
8127                           __attribute__((unused)) struct cmdline *cl,
8128                           __attribute__((unused)) void *data)
8129 {
8130         struct cmd_flow_director_result *res = parsed_result;
8131         struct rte_eth_fdir_filter entry;
8132         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
8133         char *end;
8134         unsigned long vf_id;
8135         int ret = 0;
8136
8137         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8138         if (ret < 0) {
8139                 printf("flow director is not supported on port %u.\n",
8140                         res->port_id);
8141                 return;
8142         }
8143         memset(flexbytes, 0, sizeof(flexbytes));
8144         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
8145
8146         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8147                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8148                         printf("Please set mode to MAC-VLAN.\n");
8149                         return;
8150                 }
8151         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8152                 if (strcmp(res->mode_value, "Tunnel")) {
8153                         printf("Please set mode to Tunnel.\n");
8154                         return;
8155                 }
8156         } else {
8157                 if (strcmp(res->mode_value, "IP")) {
8158                         printf("Please set mode to IP.\n");
8159                         return;
8160                 }
8161                 entry.input.flow_type = str2flowtype(res->flow_type);
8162         }
8163
8164         ret = parse_flexbytes(res->flexbytes_value,
8165                                         flexbytes,
8166                                         RTE_ETH_FDIR_MAX_FLEXLEN);
8167         if (ret < 0) {
8168                 printf("error: Cannot parse flexbytes input.\n");
8169                 return;
8170         }
8171
8172         switch (entry.input.flow_type) {
8173         case RTE_ETH_FLOW_FRAG_IPV4:
8174         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
8175         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
8176         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
8177                 IPV4_ADDR_TO_UINT(res->ip_dst,
8178                         entry.input.flow.ip4_flow.dst_ip);
8179                 IPV4_ADDR_TO_UINT(res->ip_src,
8180                         entry.input.flow.ip4_flow.src_ip);
8181                 /* need convert to big endian. */
8182                 entry.input.flow.udp4_flow.dst_port =
8183                                 rte_cpu_to_be_16(res->port_dst);
8184                 entry.input.flow.udp4_flow.src_port =
8185                                 rte_cpu_to_be_16(res->port_src);
8186                 break;
8187         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
8188                 IPV4_ADDR_TO_UINT(res->ip_dst,
8189                         entry.input.flow.sctp4_flow.ip.dst_ip);
8190                 IPV4_ADDR_TO_UINT(res->ip_src,
8191                         entry.input.flow.sctp4_flow.ip.src_ip);
8192                 /* need convert to big endian. */
8193                 entry.input.flow.sctp4_flow.dst_port =
8194                                 rte_cpu_to_be_16(res->port_dst);
8195                 entry.input.flow.sctp4_flow.src_port =
8196                                 rte_cpu_to_be_16(res->port_src);
8197                 entry.input.flow.sctp4_flow.verify_tag =
8198                                 rte_cpu_to_be_32(res->verify_tag_value);
8199                 break;
8200         case RTE_ETH_FLOW_FRAG_IPV6:
8201         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
8202         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
8203         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
8204                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8205                         entry.input.flow.ipv6_flow.dst_ip);
8206                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8207                         entry.input.flow.ipv6_flow.src_ip);
8208                 /* need convert to big endian. */
8209                 entry.input.flow.udp6_flow.dst_port =
8210                                 rte_cpu_to_be_16(res->port_dst);
8211                 entry.input.flow.udp6_flow.src_port =
8212                                 rte_cpu_to_be_16(res->port_src);
8213                 break;
8214         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
8215                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
8216                         entry.input.flow.sctp6_flow.ip.dst_ip);
8217                 IPV6_ADDR_TO_ARRAY(res->ip_src,
8218                         entry.input.flow.sctp6_flow.ip.src_ip);
8219                 /* need convert to big endian. */
8220                 entry.input.flow.sctp6_flow.dst_port =
8221                                 rte_cpu_to_be_16(res->port_dst);
8222                 entry.input.flow.sctp6_flow.src_port =
8223                                 rte_cpu_to_be_16(res->port_src);
8224                 entry.input.flow.sctp6_flow.verify_tag =
8225                                 rte_cpu_to_be_32(res->verify_tag_value);
8226                 break;
8227         case RTE_ETH_FLOW_L2_PAYLOAD:
8228                 entry.input.flow.l2_flow.ether_type =
8229                         rte_cpu_to_be_16(res->ether_type);
8230                 break;
8231         default:
8232                 break;
8233         }
8234
8235         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
8236                 (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
8237                                  &res->mac_addr,
8238                                  sizeof(struct ether_addr));
8239
8240         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8241                 (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
8242                                  &res->mac_addr,
8243                                  sizeof(struct ether_addr));
8244                 entry.input.flow.tunnel_flow.tunnel_type =
8245                         str2fdir_tunneltype(res->tunnel_type);
8246                 entry.input.flow.tunnel_flow.tunnel_id =
8247                         rte_cpu_to_be_32(res->tunnel_id_value);
8248         }
8249
8250         (void)rte_memcpy(entry.input.flow_ext.flexbytes,
8251                    flexbytes,
8252                    RTE_ETH_FDIR_MAX_FLEXLEN);
8253
8254         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
8255
8256         entry.action.flex_off = 0;  /*use 0 by default */
8257         if (!strcmp(res->drop, "drop"))
8258                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
8259         else
8260                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
8261
8262         if (!strcmp(res->pf_vf, "pf"))
8263                 entry.input.flow_ext.is_vf = 0;
8264         else if (!strncmp(res->pf_vf, "vf", 2)) {
8265                 struct rte_eth_dev_info dev_info;
8266
8267                 memset(&dev_info, 0, sizeof(dev_info));
8268                 rte_eth_dev_info_get(res->port_id, &dev_info);
8269                 errno = 0;
8270                 vf_id = strtoul(res->pf_vf + 2, &end, 10);
8271                 if (errno != 0 || *end != '\0' || vf_id >= dev_info.max_vfs) {
8272                         printf("invalid parameter %s.\n", res->pf_vf);
8273                         return;
8274                 }
8275                 entry.input.flow_ext.is_vf = 1;
8276                 entry.input.flow_ext.dst_id = (uint16_t)vf_id;
8277         } else {
8278                 printf("invalid parameter %s.\n", res->pf_vf);
8279                 return;
8280         }
8281
8282         /* set to report FD ID by default */
8283         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
8284         entry.action.rx_queue = res->queue_id;
8285         entry.soft_id = res->fd_id_value;
8286         if (!strcmp(res->ops, "add"))
8287                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8288                                              RTE_ETH_FILTER_ADD, &entry);
8289         else if (!strcmp(res->ops, "del"))
8290                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8291                                              RTE_ETH_FILTER_DELETE, &entry);
8292         else
8293                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8294                                              RTE_ETH_FILTER_UPDATE, &entry);
8295         if (ret < 0)
8296                 printf("flow director programming error: (%s)\n",
8297                         strerror(-ret));
8298 }
8299
8300 cmdline_parse_token_string_t cmd_flow_director_filter =
8301         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8302                                  flow_director_filter, "flow_director_filter");
8303 cmdline_parse_token_num_t cmd_flow_director_port_id =
8304         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8305                               port_id, UINT8);
8306 cmdline_parse_token_string_t cmd_flow_director_ops =
8307         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8308                                  ops, "add#del#update");
8309 cmdline_parse_token_string_t cmd_flow_director_flow =
8310         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8311                                  flow, "flow");
8312 cmdline_parse_token_string_t cmd_flow_director_flow_type =
8313         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8314                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8315                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
8316 cmdline_parse_token_string_t cmd_flow_director_ether =
8317         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8318                                  ether, "ether");
8319 cmdline_parse_token_num_t cmd_flow_director_ether_type =
8320         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8321                               ether_type, UINT16);
8322 cmdline_parse_token_string_t cmd_flow_director_src =
8323         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8324                                  src, "src");
8325 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
8326         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8327                                  ip_src);
8328 cmdline_parse_token_num_t cmd_flow_director_port_src =
8329         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8330                               port_src, UINT16);
8331 cmdline_parse_token_string_t cmd_flow_director_dst =
8332         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8333                                  dst, "dst");
8334 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
8335         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
8336                                  ip_dst);
8337 cmdline_parse_token_num_t cmd_flow_director_port_dst =
8338         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8339                               port_dst, UINT16);
8340 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
8341         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8342                                   verify_tag, "verify_tag");
8343 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
8344         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8345                               verify_tag_value, UINT32);
8346 cmdline_parse_token_string_t cmd_flow_director_vlan =
8347         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8348                                  vlan, "vlan");
8349 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
8350         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8351                               vlan_value, UINT16);
8352 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
8353         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8354                                  flexbytes, "flexbytes");
8355 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
8356         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8357                               flexbytes_value, NULL);
8358 cmdline_parse_token_string_t cmd_flow_director_drop =
8359         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8360                                  drop, "drop#fwd");
8361 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
8362         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8363                               pf_vf, NULL);
8364 cmdline_parse_token_string_t cmd_flow_director_queue =
8365         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8366                                  queue, "queue");
8367 cmdline_parse_token_num_t cmd_flow_director_queue_id =
8368         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8369                               queue_id, UINT16);
8370 cmdline_parse_token_string_t cmd_flow_director_fd_id =
8371         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8372                                  fd_id, "fd_id");
8373 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
8374         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8375                               fd_id_value, UINT32);
8376
8377 cmdline_parse_token_string_t cmd_flow_director_mode =
8378         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8379                                  mode, "mode");
8380 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
8381         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8382                                  mode_value, "IP");
8383 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
8384         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8385                                  mode_value, "MAC-VLAN");
8386 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
8387         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8388                                  mode_value, "Tunnel");
8389 cmdline_parse_token_string_t cmd_flow_director_mac =
8390         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8391                                  mac, "mac");
8392 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
8393         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
8394                                     mac_addr);
8395 cmdline_parse_token_string_t cmd_flow_director_tunnel =
8396         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8397                                  tunnel, "tunnel");
8398 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
8399         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8400                                  tunnel_type, "NVGRE#VxLAN");
8401 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
8402         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
8403                                  tunnel_id, "tunnel-id");
8404 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
8405         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
8406                               tunnel_id_value, UINT32);
8407
8408 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
8409         .f = cmd_flow_director_filter_parsed,
8410         .data = NULL,
8411         .help_str = "add or delete an ip flow director entry on NIC",
8412         .tokens = {
8413                 (void *)&cmd_flow_director_filter,
8414                 (void *)&cmd_flow_director_port_id,
8415                 (void *)&cmd_flow_director_mode,
8416                 (void *)&cmd_flow_director_mode_ip,
8417                 (void *)&cmd_flow_director_ops,
8418                 (void *)&cmd_flow_director_flow,
8419                 (void *)&cmd_flow_director_flow_type,
8420                 (void *)&cmd_flow_director_src,
8421                 (void *)&cmd_flow_director_ip_src,
8422                 (void *)&cmd_flow_director_dst,
8423                 (void *)&cmd_flow_director_ip_dst,
8424                 (void *)&cmd_flow_director_vlan,
8425                 (void *)&cmd_flow_director_vlan_value,
8426                 (void *)&cmd_flow_director_flexbytes,
8427                 (void *)&cmd_flow_director_flexbytes_value,
8428                 (void *)&cmd_flow_director_drop,
8429                 (void *)&cmd_flow_director_pf_vf,
8430                 (void *)&cmd_flow_director_queue,
8431                 (void *)&cmd_flow_director_queue_id,
8432                 (void *)&cmd_flow_director_fd_id,
8433                 (void *)&cmd_flow_director_fd_id_value,
8434                 NULL,
8435         },
8436 };
8437
8438 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
8439         .f = cmd_flow_director_filter_parsed,
8440         .data = NULL,
8441         .help_str = "add or delete an udp/tcp flow director entry on NIC",
8442         .tokens = {
8443                 (void *)&cmd_flow_director_filter,
8444                 (void *)&cmd_flow_director_port_id,
8445                 (void *)&cmd_flow_director_mode,
8446                 (void *)&cmd_flow_director_mode_ip,
8447                 (void *)&cmd_flow_director_ops,
8448                 (void *)&cmd_flow_director_flow,
8449                 (void *)&cmd_flow_director_flow_type,
8450                 (void *)&cmd_flow_director_src,
8451                 (void *)&cmd_flow_director_ip_src,
8452                 (void *)&cmd_flow_director_port_src,
8453                 (void *)&cmd_flow_director_dst,
8454                 (void *)&cmd_flow_director_ip_dst,
8455                 (void *)&cmd_flow_director_port_dst,
8456                 (void *)&cmd_flow_director_vlan,
8457                 (void *)&cmd_flow_director_vlan_value,
8458                 (void *)&cmd_flow_director_flexbytes,
8459                 (void *)&cmd_flow_director_flexbytes_value,
8460                 (void *)&cmd_flow_director_drop,
8461                 (void *)&cmd_flow_director_pf_vf,
8462                 (void *)&cmd_flow_director_queue,
8463                 (void *)&cmd_flow_director_queue_id,
8464                 (void *)&cmd_flow_director_fd_id,
8465                 (void *)&cmd_flow_director_fd_id_value,
8466                 NULL,
8467         },
8468 };
8469
8470 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
8471         .f = cmd_flow_director_filter_parsed,
8472         .data = NULL,
8473         .help_str = "add or delete a sctp flow director entry on NIC",
8474         .tokens = {
8475                 (void *)&cmd_flow_director_filter,
8476                 (void *)&cmd_flow_director_port_id,
8477                 (void *)&cmd_flow_director_mode,
8478                 (void *)&cmd_flow_director_mode_ip,
8479                 (void *)&cmd_flow_director_ops,
8480                 (void *)&cmd_flow_director_flow,
8481                 (void *)&cmd_flow_director_flow_type,
8482                 (void *)&cmd_flow_director_src,
8483                 (void *)&cmd_flow_director_ip_src,
8484                 (void *)&cmd_flow_director_port_dst,
8485                 (void *)&cmd_flow_director_dst,
8486                 (void *)&cmd_flow_director_ip_dst,
8487                 (void *)&cmd_flow_director_port_dst,
8488                 (void *)&cmd_flow_director_verify_tag,
8489                 (void *)&cmd_flow_director_verify_tag_value,
8490                 (void *)&cmd_flow_director_vlan,
8491                 (void *)&cmd_flow_director_vlan_value,
8492                 (void *)&cmd_flow_director_flexbytes,
8493                 (void *)&cmd_flow_director_flexbytes_value,
8494                 (void *)&cmd_flow_director_drop,
8495                 (void *)&cmd_flow_director_pf_vf,
8496                 (void *)&cmd_flow_director_queue,
8497                 (void *)&cmd_flow_director_queue_id,
8498                 (void *)&cmd_flow_director_fd_id,
8499                 (void *)&cmd_flow_director_fd_id_value,
8500                 NULL,
8501         },
8502 };
8503
8504 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
8505         .f = cmd_flow_director_filter_parsed,
8506         .data = NULL,
8507         .help_str = "add or delete a L2 flow director entry on NIC",
8508         .tokens = {
8509                 (void *)&cmd_flow_director_filter,
8510                 (void *)&cmd_flow_director_port_id,
8511                 (void *)&cmd_flow_director_mode,
8512                 (void *)&cmd_flow_director_mode_ip,
8513                 (void *)&cmd_flow_director_ops,
8514                 (void *)&cmd_flow_director_flow,
8515                 (void *)&cmd_flow_director_flow_type,
8516                 (void *)&cmd_flow_director_ether,
8517                 (void *)&cmd_flow_director_ether_type,
8518                 (void *)&cmd_flow_director_flexbytes,
8519                 (void *)&cmd_flow_director_flexbytes_value,
8520                 (void *)&cmd_flow_director_drop,
8521                 (void *)&cmd_flow_director_pf_vf,
8522                 (void *)&cmd_flow_director_queue,
8523                 (void *)&cmd_flow_director_queue_id,
8524                 (void *)&cmd_flow_director_fd_id,
8525                 (void *)&cmd_flow_director_fd_id_value,
8526                 NULL,
8527         },
8528 };
8529
8530 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
8531         .f = cmd_flow_director_filter_parsed,
8532         .data = NULL,
8533         .help_str = "add or delete a MAC VLAN flow director entry on NIC",
8534         .tokens = {
8535                 (void *)&cmd_flow_director_filter,
8536                 (void *)&cmd_flow_director_port_id,
8537                 (void *)&cmd_flow_director_mode,
8538                 (void *)&cmd_flow_director_mode_mac_vlan,
8539                 (void *)&cmd_flow_director_ops,
8540                 (void *)&cmd_flow_director_mac,
8541                 (void *)&cmd_flow_director_mac_addr,
8542                 (void *)&cmd_flow_director_vlan,
8543                 (void *)&cmd_flow_director_vlan_value,
8544                 (void *)&cmd_flow_director_flexbytes,
8545                 (void *)&cmd_flow_director_flexbytes_value,
8546                 (void *)&cmd_flow_director_drop,
8547                 (void *)&cmd_flow_director_queue,
8548                 (void *)&cmd_flow_director_queue_id,
8549                 (void *)&cmd_flow_director_fd_id,
8550                 (void *)&cmd_flow_director_fd_id_value,
8551                 NULL,
8552         },
8553 };
8554
8555 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
8556         .f = cmd_flow_director_filter_parsed,
8557         .data = NULL,
8558         .help_str = "add or delete a tunnel flow director entry on NIC",
8559         .tokens = {
8560                 (void *)&cmd_flow_director_filter,
8561                 (void *)&cmd_flow_director_port_id,
8562                 (void *)&cmd_flow_director_mode,
8563                 (void *)&cmd_flow_director_mode_tunnel,
8564                 (void *)&cmd_flow_director_ops,
8565                 (void *)&cmd_flow_director_mac,
8566                 (void *)&cmd_flow_director_mac_addr,
8567                 (void *)&cmd_flow_director_vlan,
8568                 (void *)&cmd_flow_director_vlan_value,
8569                 (void *)&cmd_flow_director_tunnel,
8570                 (void *)&cmd_flow_director_tunnel_type,
8571                 (void *)&cmd_flow_director_tunnel_id,
8572                 (void *)&cmd_flow_director_tunnel_id_value,
8573                 (void *)&cmd_flow_director_flexbytes,
8574                 (void *)&cmd_flow_director_flexbytes_value,
8575                 (void *)&cmd_flow_director_drop,
8576                 (void *)&cmd_flow_director_queue,
8577                 (void *)&cmd_flow_director_queue_id,
8578                 (void *)&cmd_flow_director_fd_id,
8579                 (void *)&cmd_flow_director_fd_id_value,
8580                 NULL,
8581         },
8582 };
8583
8584 struct cmd_flush_flow_director_result {
8585         cmdline_fixed_string_t flush_flow_director;
8586         uint8_t port_id;
8587 };
8588
8589 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
8590         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
8591                                  flush_flow_director, "flush_flow_director");
8592 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
8593         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
8594                               port_id, UINT8);
8595
8596 static void
8597 cmd_flush_flow_director_parsed(void *parsed_result,
8598                           __attribute__((unused)) struct cmdline *cl,
8599                           __attribute__((unused)) void *data)
8600 {
8601         struct cmd_flow_director_result *res = parsed_result;
8602         int ret = 0;
8603
8604         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
8605         if (ret < 0) {
8606                 printf("flow director is not supported on port %u.\n",
8607                         res->port_id);
8608                 return;
8609         }
8610
8611         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8612                         RTE_ETH_FILTER_FLUSH, NULL);
8613         if (ret < 0)
8614                 printf("flow director table flushing error: (%s)\n",
8615                         strerror(-ret));
8616 }
8617
8618 cmdline_parse_inst_t cmd_flush_flow_director = {
8619         .f = cmd_flush_flow_director_parsed,
8620         .data = NULL,
8621         .help_str = "flush all flow director entries of a device on NIC",
8622         .tokens = {
8623                 (void *)&cmd_flush_flow_director_flush,
8624                 (void *)&cmd_flush_flow_director_port_id,
8625                 NULL,
8626         },
8627 };
8628
8629 /* *** deal with flow director mask *** */
8630 struct cmd_flow_director_mask_result {
8631         cmdline_fixed_string_t flow_director_mask;
8632         uint8_t port_id;
8633         cmdline_fixed_string_t mode;
8634         cmdline_fixed_string_t mode_value;
8635         cmdline_fixed_string_t vlan;
8636         uint16_t vlan_mask;
8637         cmdline_fixed_string_t src_mask;
8638         cmdline_ipaddr_t ipv4_src;
8639         cmdline_ipaddr_t ipv6_src;
8640         uint16_t port_src;
8641         cmdline_fixed_string_t dst_mask;
8642         cmdline_ipaddr_t ipv4_dst;
8643         cmdline_ipaddr_t ipv6_dst;
8644         uint16_t port_dst;
8645         cmdline_fixed_string_t mac;
8646         uint8_t mac_addr_byte_mask;
8647         cmdline_fixed_string_t tunnel_id;
8648         uint32_t tunnel_id_mask;
8649         cmdline_fixed_string_t tunnel_type;
8650         uint8_t tunnel_type_mask;
8651 };
8652
8653 static void
8654 cmd_flow_director_mask_parsed(void *parsed_result,
8655                           __attribute__((unused)) struct cmdline *cl,
8656                           __attribute__((unused)) void *data)
8657 {
8658         struct cmd_flow_director_mask_result *res = parsed_result;
8659         struct rte_eth_fdir_masks *mask;
8660         struct rte_port *port;
8661
8662         if (res->port_id > nb_ports) {
8663                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8664                 return;
8665         }
8666
8667         port = &ports[res->port_id];
8668         /** Check if the port is not started **/
8669         if (port->port_status != RTE_PORT_STOPPED) {
8670                 printf("Please stop port %d first\n", res->port_id);
8671                 return;
8672         }
8673
8674         mask = &port->dev_conf.fdir_conf.mask;
8675
8676         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
8677                 if (strcmp(res->mode_value, "MAC-VLAN")) {
8678                         printf("Please set mode to MAC-VLAN.\n");
8679                         return;
8680                 }
8681
8682                 mask->vlan_tci_mask = res->vlan_mask;
8683                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
8684         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
8685                 if (strcmp(res->mode_value, "Tunnel")) {
8686                         printf("Please set mode to Tunnel.\n");
8687                         return;
8688                 }
8689
8690                 mask->vlan_tci_mask = res->vlan_mask;
8691                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
8692                 mask->tunnel_id_mask = res->tunnel_id_mask;
8693                 mask->tunnel_type_mask = res->tunnel_type_mask;
8694         } else {
8695                 if (strcmp(res->mode_value, "IP")) {
8696                         printf("Please set mode to IP.\n");
8697                         return;
8698                 }
8699
8700                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
8701                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
8702                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
8703                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
8704                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
8705                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
8706                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
8707         }
8708
8709         cmd_reconfig_device_queue(res->port_id, 1, 1);
8710 }
8711
8712 cmdline_parse_token_string_t cmd_flow_director_mask =
8713         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8714                                  flow_director_mask, "flow_director_mask");
8715 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
8716         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8717                               port_id, UINT8);
8718 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
8719         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8720                                  vlan, "vlan");
8721 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
8722         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8723                               vlan_mask, UINT16);
8724 cmdline_parse_token_string_t cmd_flow_director_mask_src =
8725         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8726                                  src_mask, "src_mask");
8727 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
8728         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8729                                  ipv4_src);
8730 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
8731         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8732                                  ipv6_src);
8733 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
8734         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8735                               port_src, UINT16);
8736 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
8737         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8738                                  dst_mask, "dst_mask");
8739 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
8740         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8741                                  ipv4_dst);
8742 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
8743         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
8744                                  ipv6_dst);
8745 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
8746         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8747                               port_dst, UINT16);
8748
8749 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
8750         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8751                                  mode, "mode");
8752 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
8753         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8754                                  mode_value, "IP");
8755 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
8756         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8757                                  mode_value, "MAC-VLAN");
8758 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
8759         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8760                                  mode_value, "Tunnel");
8761 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
8762         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8763                                  mac, "mac");
8764 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
8765         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8766                               mac_addr_byte_mask, UINT8);
8767 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
8768         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8769                                  tunnel_type, "tunnel-type");
8770 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
8771         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8772                               tunnel_type_mask, UINT8);
8773 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
8774         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
8775                                  tunnel_id, "tunnel-id");
8776 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
8777         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
8778                               tunnel_id_mask, UINT32);
8779
8780 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
8781         .f = cmd_flow_director_mask_parsed,
8782         .data = NULL,
8783         .help_str = "set IP mode flow director's mask on NIC",
8784         .tokens = {
8785                 (void *)&cmd_flow_director_mask,
8786                 (void *)&cmd_flow_director_mask_port_id,
8787                 (void *)&cmd_flow_director_mask_mode,
8788                 (void *)&cmd_flow_director_mask_mode_ip,
8789                 (void *)&cmd_flow_director_mask_vlan,
8790                 (void *)&cmd_flow_director_mask_vlan_value,
8791                 (void *)&cmd_flow_director_mask_src,
8792                 (void *)&cmd_flow_director_mask_ipv4_src,
8793                 (void *)&cmd_flow_director_mask_ipv6_src,
8794                 (void *)&cmd_flow_director_mask_port_src,
8795                 (void *)&cmd_flow_director_mask_dst,
8796                 (void *)&cmd_flow_director_mask_ipv4_dst,
8797                 (void *)&cmd_flow_director_mask_ipv6_dst,
8798                 (void *)&cmd_flow_director_mask_port_dst,
8799                 NULL,
8800         },
8801 };
8802
8803 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
8804         .f = cmd_flow_director_mask_parsed,
8805         .data = NULL,
8806         .help_str = "set MAC VLAN mode flow director's mask on NIC",
8807         .tokens = {
8808                 (void *)&cmd_flow_director_mask,
8809                 (void *)&cmd_flow_director_mask_port_id,
8810                 (void *)&cmd_flow_director_mask_mode,
8811                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
8812                 (void *)&cmd_flow_director_mask_vlan,
8813                 (void *)&cmd_flow_director_mask_vlan_value,
8814                 (void *)&cmd_flow_director_mask_mac,
8815                 (void *)&cmd_flow_director_mask_mac_value,
8816                 NULL,
8817         },
8818 };
8819
8820 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
8821         .f = cmd_flow_director_mask_parsed,
8822         .data = NULL,
8823         .help_str = "set tunnel mode flow director's mask on NIC",
8824         .tokens = {
8825                 (void *)&cmd_flow_director_mask,
8826                 (void *)&cmd_flow_director_mask_port_id,
8827                 (void *)&cmd_flow_director_mask_mode,
8828                 (void *)&cmd_flow_director_mask_mode_tunnel,
8829                 (void *)&cmd_flow_director_mask_vlan,
8830                 (void *)&cmd_flow_director_mask_vlan_value,
8831                 (void *)&cmd_flow_director_mask_mac,
8832                 (void *)&cmd_flow_director_mask_mac_value,
8833                 (void *)&cmd_flow_director_mask_tunnel_type,
8834                 (void *)&cmd_flow_director_mask_tunnel_type_value,
8835                 (void *)&cmd_flow_director_mask_tunnel_id,
8836                 (void *)&cmd_flow_director_mask_tunnel_id_value,
8837                 NULL,
8838         },
8839 };
8840
8841 /* *** deal with flow director mask on flexible payload *** */
8842 struct cmd_flow_director_flex_mask_result {
8843         cmdline_fixed_string_t flow_director_flexmask;
8844         uint8_t port_id;
8845         cmdline_fixed_string_t flow;
8846         cmdline_fixed_string_t flow_type;
8847         cmdline_fixed_string_t mask;
8848 };
8849
8850 static void
8851 cmd_flow_director_flex_mask_parsed(void *parsed_result,
8852                           __attribute__((unused)) struct cmdline *cl,
8853                           __attribute__((unused)) void *data)
8854 {
8855         struct cmd_flow_director_flex_mask_result *res = parsed_result;
8856         struct rte_eth_fdir_info fdir_info;
8857         struct rte_eth_fdir_flex_mask flex_mask;
8858         struct rte_port *port;
8859         uint32_t flow_type_mask;
8860         uint16_t i;
8861         int ret;
8862
8863         if (res->port_id > nb_ports) {
8864                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
8865                 return;
8866         }
8867
8868         port = &ports[res->port_id];
8869         /** Check if the port is not started **/
8870         if (port->port_status != RTE_PORT_STOPPED) {
8871                 printf("Please stop port %d first\n", res->port_id);
8872                 return;
8873         }
8874
8875         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
8876         ret = parse_flexbytes(res->mask,
8877                         flex_mask.mask,
8878                         RTE_ETH_FDIR_MAX_FLEXLEN);
8879         if (ret < 0) {
8880                 printf("error: Cannot parse mask input.\n");
8881                 return;
8882         }
8883
8884         memset(&fdir_info, 0, sizeof(fdir_info));
8885         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
8886                                 RTE_ETH_FILTER_INFO, &fdir_info);
8887         if (ret < 0) {
8888                 printf("Cannot get FDir filter info\n");
8889                 return;
8890         }
8891
8892         if (!strcmp(res->flow_type, "none")) {
8893                 /* means don't specify the flow type */
8894                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
8895                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
8896                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
8897                                0, sizeof(struct rte_eth_fdir_flex_mask));
8898                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
8899                 (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
8900                                  &flex_mask,
8901                                  sizeof(struct rte_eth_fdir_flex_mask));
8902                 cmd_reconfig_device_queue(res->port_id, 1, 1);
8903                 return;
8904         }
8905         flow_type_mask = fdir_info.flow_types_mask[0];
8906         if (!strcmp(res->flow_type, "all")) {
8907                 if (!flow_type_mask) {
8908                         printf("No flow type supported\n");
8909                         return;
8910                 }
8911                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
8912                         if (flow_type_mask & (1 << i)) {
8913                                 flex_mask.flow_type = i;
8914                                 fdir_set_flex_mask(res->port_id, &flex_mask);
8915                         }
8916                 }
8917                 cmd_reconfig_device_queue(res->port_id, 1, 1);
8918                 return;
8919         }
8920         flex_mask.flow_type = str2flowtype(res->flow_type);
8921         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
8922                 printf("Flow type %s not supported on port %d\n",
8923                                 res->flow_type, res->port_id);
8924                 return;
8925         }
8926         fdir_set_flex_mask(res->port_id, &flex_mask);
8927         cmd_reconfig_device_queue(res->port_id, 1, 1);
8928 }
8929
8930 cmdline_parse_token_string_t cmd_flow_director_flexmask =
8931         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8932                                  flow_director_flexmask,
8933                                  "flow_director_flex_mask");
8934 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
8935         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8936                               port_id, UINT8);
8937 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
8938         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8939                                  flow, "flow");
8940 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
8941         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8942                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
8943                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
8944 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
8945         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
8946                                  mask, NULL);
8947
8948 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
8949         .f = cmd_flow_director_flex_mask_parsed,
8950         .data = NULL,
8951         .help_str = "set flow director's flex mask on NIC",
8952         .tokens = {
8953                 (void *)&cmd_flow_director_flexmask,
8954                 (void *)&cmd_flow_director_flexmask_port_id,
8955                 (void *)&cmd_flow_director_flexmask_flow,
8956                 (void *)&cmd_flow_director_flexmask_flow_type,
8957                 (void *)&cmd_flow_director_flexmask_mask,
8958                 NULL,
8959         },
8960 };
8961
8962 /* *** deal with flow director flexible payload configuration *** */
8963 struct cmd_flow_director_flexpayload_result {
8964         cmdline_fixed_string_t flow_director_flexpayload;
8965         uint8_t port_id;
8966         cmdline_fixed_string_t payload_layer;
8967         cmdline_fixed_string_t payload_cfg;
8968 };
8969
8970 static inline int
8971 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
8972 {
8973         char s[256];
8974         const char *p, *p0 = q_arg;
8975         char *end;
8976         unsigned long int_fld;
8977         char *str_fld[max_num];
8978         int i;
8979         unsigned size;
8980         int ret = -1;
8981
8982         p = strchr(p0, '(');
8983         if (p == NULL)
8984                 return -1;
8985         ++p;
8986         p0 = strchr(p, ')');
8987         if (p0 == NULL)
8988                 return -1;
8989
8990         size = p0 - p;
8991         if (size >= sizeof(s))
8992                 return -1;
8993
8994         snprintf(s, sizeof(s), "%.*s", size, p);
8995         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
8996         if (ret < 0 || ret > max_num)
8997                 return -1;
8998         for (i = 0; i < ret; i++) {
8999                 errno = 0;
9000                 int_fld = strtoul(str_fld[i], &end, 0);
9001                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
9002                         return -1;
9003                 offsets[i] = (uint16_t)int_fld;
9004         }
9005         return ret;
9006 }
9007
9008 static void
9009 cmd_flow_director_flxpld_parsed(void *parsed_result,
9010                           __attribute__((unused)) struct cmdline *cl,
9011                           __attribute__((unused)) void *data)
9012 {
9013         struct cmd_flow_director_flexpayload_result *res = parsed_result;
9014         struct rte_eth_flex_payload_cfg flex_cfg;
9015         struct rte_port *port;
9016         int ret = 0;
9017
9018         if (res->port_id > nb_ports) {
9019                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
9020                 return;
9021         }
9022
9023         port = &ports[res->port_id];
9024         /** Check if the port is not started **/
9025         if (port->port_status != RTE_PORT_STOPPED) {
9026                 printf("Please stop port %d first\n", res->port_id);
9027                 return;
9028         }
9029
9030         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
9031
9032         if (!strcmp(res->payload_layer, "raw"))
9033                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
9034         else if (!strcmp(res->payload_layer, "l2"))
9035                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
9036         else if (!strcmp(res->payload_layer, "l3"))
9037                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
9038         else if (!strcmp(res->payload_layer, "l4"))
9039                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
9040
9041         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
9042                             RTE_ETH_FDIR_MAX_FLEXLEN);
9043         if (ret < 0) {
9044                 printf("error: Cannot parse flex payload input.\n");
9045                 return;
9046         }
9047
9048         fdir_set_flex_payload(res->port_id, &flex_cfg);
9049         cmd_reconfig_device_queue(res->port_id, 1, 1);
9050 }
9051
9052 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
9053         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9054                                  flow_director_flexpayload,
9055                                  "flow_director_flex_payload");
9056 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
9057         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9058                               port_id, UINT8);
9059 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
9060         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9061                                  payload_layer, "raw#l2#l3#l4");
9062 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
9063         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
9064                                  payload_cfg, NULL);
9065
9066 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
9067         .f = cmd_flow_director_flxpld_parsed,
9068         .data = NULL,
9069         .help_str = "set flow director's flex payload on NIC",
9070         .tokens = {
9071                 (void *)&cmd_flow_director_flexpayload,
9072                 (void *)&cmd_flow_director_flexpayload_port_id,
9073                 (void *)&cmd_flow_director_flexpayload_payload_layer,
9074                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
9075                 NULL,
9076         },
9077 };
9078
9079 /* *** Classification Filters Control *** */
9080 /* *** Get symmetric hash enable per port *** */
9081 struct cmd_get_sym_hash_ena_per_port_result {
9082         cmdline_fixed_string_t get_sym_hash_ena_per_port;
9083         uint8_t port_id;
9084 };
9085
9086 static void
9087 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
9088                                  __rte_unused struct cmdline *cl,
9089                                  __rte_unused void *data)
9090 {
9091         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
9092         struct rte_eth_hash_filter_info info;
9093         int ret;
9094
9095         if (rte_eth_dev_filter_supported(res->port_id,
9096                                 RTE_ETH_FILTER_HASH) < 0) {
9097                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9098                                                         res->port_id);
9099                 return;
9100         }
9101
9102         memset(&info, 0, sizeof(info));
9103         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9104         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9105                                                 RTE_ETH_FILTER_GET, &info);
9106
9107         if (ret < 0) {
9108                 printf("Cannot get symmetric hash enable per port "
9109                                         "on port %u\n", res->port_id);
9110                 return;
9111         }
9112
9113         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
9114                                 "enabled" : "disabled", res->port_id);
9115 }
9116
9117 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
9118         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9119                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
9120 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
9121         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
9122                 port_id, UINT8);
9123
9124 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
9125         .f = cmd_get_sym_hash_per_port_parsed,
9126         .data = NULL,
9127         .help_str = "get_sym_hash_ena_per_port port_id",
9128         .tokens = {
9129                 (void *)&cmd_get_sym_hash_ena_per_port_all,
9130                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
9131                 NULL,
9132         },
9133 };
9134
9135 /* *** Set symmetric hash enable per port *** */
9136 struct cmd_set_sym_hash_ena_per_port_result {
9137         cmdline_fixed_string_t set_sym_hash_ena_per_port;
9138         cmdline_fixed_string_t enable;
9139         uint8_t port_id;
9140 };
9141
9142 static void
9143 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
9144                                  __rte_unused struct cmdline *cl,
9145                                  __rte_unused void *data)
9146 {
9147         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
9148         struct rte_eth_hash_filter_info info;
9149         int ret;
9150
9151         if (rte_eth_dev_filter_supported(res->port_id,
9152                                 RTE_ETH_FILTER_HASH) < 0) {
9153                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
9154                                                         res->port_id);
9155                 return;
9156         }
9157
9158         memset(&info, 0, sizeof(info));
9159         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
9160         if (!strcmp(res->enable, "enable"))
9161                 info.info.enable = 1;
9162         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9163                                         RTE_ETH_FILTER_SET, &info);
9164         if (ret < 0) {
9165                 printf("Cannot set symmetric hash enable per port on "
9166                                         "port %u\n", res->port_id);
9167                 return;
9168         }
9169         printf("Symmetric hash has been set to %s on port %u\n",
9170                                         res->enable, res->port_id);
9171 }
9172
9173 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
9174         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9175                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
9176 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
9177         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9178                 port_id, UINT8);
9179 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
9180         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
9181                 enable, "enable#disable");
9182
9183 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
9184         .f = cmd_set_sym_hash_per_port_parsed,
9185         .data = NULL,
9186         .help_str = "set_sym_hash_ena_per_port port_id enable|disable",
9187         .tokens = {
9188                 (void *)&cmd_set_sym_hash_ena_per_port_all,
9189                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
9190                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
9191                 NULL,
9192         },
9193 };
9194
9195 /* Get global config of hash function */
9196 struct cmd_get_hash_global_config_result {
9197         cmdline_fixed_string_t get_hash_global_config;
9198         uint8_t port_id;
9199 };
9200
9201 static char *
9202 flowtype_to_str(uint16_t ftype)
9203 {
9204         uint16_t i;
9205         static struct {
9206                 char str[16];
9207                 uint16_t ftype;
9208         } ftype_table[] = {
9209                 {"ipv4", RTE_ETH_FLOW_IPV4},
9210                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9211                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9212                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9213                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9214                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9215                 {"ipv6", RTE_ETH_FLOW_IPV6},
9216                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9217                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9218                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9219                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9220                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9221                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9222         };
9223
9224         for (i = 0; i < RTE_DIM(ftype_table); i++) {
9225                 if (ftype_table[i].ftype == ftype)
9226                         return ftype_table[i].str;
9227         }
9228
9229         return NULL;
9230 }
9231
9232 static void
9233 cmd_get_hash_global_config_parsed(void *parsed_result,
9234                                   __rte_unused struct cmdline *cl,
9235                                   __rte_unused void *data)
9236 {
9237         struct cmd_get_hash_global_config_result *res = parsed_result;
9238         struct rte_eth_hash_filter_info info;
9239         uint32_t idx, offset;
9240         uint16_t i;
9241         char *str;
9242         int ret;
9243
9244         if (rte_eth_dev_filter_supported(res->port_id,
9245                         RTE_ETH_FILTER_HASH) < 0) {
9246                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9247                                                         res->port_id);
9248                 return;
9249         }
9250
9251         memset(&info, 0, sizeof(info));
9252         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9253         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9254                                         RTE_ETH_FILTER_GET, &info);
9255         if (ret < 0) {
9256                 printf("Cannot get hash global configurations by port %d\n",
9257                                                         res->port_id);
9258                 return;
9259         }
9260
9261         switch (info.info.global_conf.hash_func) {
9262         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
9263                 printf("Hash function is Toeplitz\n");
9264                 break;
9265         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
9266                 printf("Hash function is Simple XOR\n");
9267                 break;
9268         default:
9269                 printf("Unknown hash function\n");
9270                 break;
9271         }
9272
9273         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
9274                 idx = i / UINT32_BIT;
9275                 offset = i % UINT32_BIT;
9276                 if (!(info.info.global_conf.valid_bit_mask[idx] &
9277                                                 (1UL << offset)))
9278                         continue;
9279                 str = flowtype_to_str(i);
9280                 if (!str)
9281                         continue;
9282                 printf("Symmetric hash is %s globally for flow type %s "
9283                                                         "by port %d\n",
9284                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
9285                         (1UL << offset)) ? "enabled" : "disabled"), str,
9286                                                         res->port_id);
9287         }
9288 }
9289
9290 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
9291         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
9292                 get_hash_global_config, "get_hash_global_config");
9293 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
9294         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
9295                 port_id, UINT8);
9296
9297 cmdline_parse_inst_t cmd_get_hash_global_config = {
9298         .f = cmd_get_hash_global_config_parsed,
9299         .data = NULL,
9300         .help_str = "get_hash_global_config port_id",
9301         .tokens = {
9302                 (void *)&cmd_get_hash_global_config_all,
9303                 (void *)&cmd_get_hash_global_config_port_id,
9304                 NULL,
9305         },
9306 };
9307
9308 /* Set global config of hash function */
9309 struct cmd_set_hash_global_config_result {
9310         cmdline_fixed_string_t set_hash_global_config;
9311         uint8_t port_id;
9312         cmdline_fixed_string_t hash_func;
9313         cmdline_fixed_string_t flow_type;
9314         cmdline_fixed_string_t enable;
9315 };
9316
9317 static void
9318 cmd_set_hash_global_config_parsed(void *parsed_result,
9319                                   __rte_unused struct cmdline *cl,
9320                                   __rte_unused void *data)
9321 {
9322         struct cmd_set_hash_global_config_result *res = parsed_result;
9323         struct rte_eth_hash_filter_info info;
9324         uint32_t ftype, idx, offset;
9325         int ret;
9326
9327         if (rte_eth_dev_filter_supported(res->port_id,
9328                                 RTE_ETH_FILTER_HASH) < 0) {
9329                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
9330                                                         res->port_id);
9331                 return;
9332         }
9333         memset(&info, 0, sizeof(info));
9334         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
9335         if (!strcmp(res->hash_func, "toeplitz"))
9336                 info.info.global_conf.hash_func =
9337                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9338         else if (!strcmp(res->hash_func, "simple_xor"))
9339                 info.info.global_conf.hash_func =
9340                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9341         else if (!strcmp(res->hash_func, "default"))
9342                 info.info.global_conf.hash_func =
9343                         RTE_ETH_HASH_FUNCTION_DEFAULT;
9344
9345         ftype = str2flowtype(res->flow_type);
9346         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
9347         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
9348         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
9349         if (!strcmp(res->enable, "enable"))
9350                 info.info.global_conf.sym_hash_enable_mask[idx] |=
9351                                                 (1UL << offset);
9352         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9353                                         RTE_ETH_FILTER_SET, &info);
9354         if (ret < 0)
9355                 printf("Cannot set global hash configurations by port %d\n",
9356                                                         res->port_id);
9357         else
9358                 printf("Global hash configurations have been set "
9359                         "succcessfully by port %d\n", res->port_id);
9360 }
9361
9362 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
9363         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9364                 set_hash_global_config, "set_hash_global_config");
9365 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
9366         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
9367                 port_id, UINT8);
9368 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
9369         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9370                 hash_func, "toeplitz#simple_xor#default");
9371 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
9372         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9373                 flow_type,
9374                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9375                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9376 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
9377         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
9378                 enable, "enable#disable");
9379
9380 cmdline_parse_inst_t cmd_set_hash_global_config = {
9381         .f = cmd_set_hash_global_config_parsed,
9382         .data = NULL,
9383         .help_str = "set_hash_global_config port_id "
9384                 "toeplitz|simple_xor|default "
9385                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
9386                 "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9387                 "enable|disable",
9388         .tokens = {
9389                 (void *)&cmd_set_hash_global_config_all,
9390                 (void *)&cmd_set_hash_global_config_port_id,
9391                 (void *)&cmd_set_hash_global_config_hash_func,
9392                 (void *)&cmd_set_hash_global_config_flow_type,
9393                 (void *)&cmd_set_hash_global_config_enable,
9394                 NULL,
9395         },
9396 };
9397
9398 /* Set hash input set */
9399 struct cmd_set_hash_input_set_result {
9400         cmdline_fixed_string_t set_hash_input_set;
9401         uint8_t port_id;
9402         cmdline_fixed_string_t flow_type;
9403         cmdline_fixed_string_t inset_field;
9404         cmdline_fixed_string_t select;
9405 };
9406
9407 static enum rte_eth_input_set_field
9408 str2inset(char *string)
9409 {
9410         uint16_t i;
9411
9412         static const struct {
9413                 char str[32];
9414                 enum rte_eth_input_set_field inset;
9415         } inset_table[] = {
9416                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
9417                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
9418                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
9419                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
9420                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
9421                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
9422                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
9423                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
9424                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
9425                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
9426                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
9427                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
9428                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
9429                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
9430                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
9431                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
9432                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
9433                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
9434                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
9435                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
9436                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
9437                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
9438                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
9439                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
9440                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
9441                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
9442                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
9443                 {"none", RTE_ETH_INPUT_SET_NONE},
9444         };
9445
9446         for (i = 0; i < RTE_DIM(inset_table); i++) {
9447                 if (!strcmp(string, inset_table[i].str))
9448                         return inset_table[i].inset;
9449         }
9450
9451         return RTE_ETH_INPUT_SET_UNKNOWN;
9452 }
9453
9454 static void
9455 cmd_set_hash_input_set_parsed(void *parsed_result,
9456                               __rte_unused struct cmdline *cl,
9457                               __rte_unused void *data)
9458 {
9459         struct cmd_set_hash_input_set_result *res = parsed_result;
9460         struct rte_eth_hash_filter_info info;
9461
9462         memset(&info, 0, sizeof(info));
9463         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
9464         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9465         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9466         info.info.input_set_conf.inset_size = 1;
9467         if (!strcmp(res->select, "select"))
9468                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9469         else if (!strcmp(res->select, "add"))
9470                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9471         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
9472                                 RTE_ETH_FILTER_SET, &info);
9473 }
9474
9475 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
9476         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9477                 set_hash_input_set, "set_hash_input_set");
9478 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
9479         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
9480                 port_id, UINT8);
9481 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
9482         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9483                 flow_type,
9484                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9485                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9486 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
9487         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9488                 inset_field,
9489                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
9490                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
9491                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
9492                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
9493                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
9494                 "fld-8th#none");
9495 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
9496         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
9497                 select, "select#add");
9498
9499 cmdline_parse_inst_t cmd_set_hash_input_set = {
9500         .f = cmd_set_hash_input_set_parsed,
9501         .data = NULL,
9502         .help_str = "set_hash_input_set <port_id> "
9503         "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|ipv6-frag|"
9504         "ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9505         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
9506         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
9507         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
9508         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
9509         "fld-7th|fld-8th|none select|add",
9510         .tokens = {
9511                 (void *)&cmd_set_hash_input_set_cmd,
9512                 (void *)&cmd_set_hash_input_set_port_id,
9513                 (void *)&cmd_set_hash_input_set_flow_type,
9514                 (void *)&cmd_set_hash_input_set_field,
9515                 (void *)&cmd_set_hash_input_set_select,
9516                 NULL,
9517         },
9518 };
9519
9520 /* Set flow director input set */
9521 struct cmd_set_fdir_input_set_result {
9522         cmdline_fixed_string_t set_fdir_input_set;
9523         uint8_t port_id;
9524         cmdline_fixed_string_t flow_type;
9525         cmdline_fixed_string_t inset_field;
9526         cmdline_fixed_string_t select;
9527 };
9528
9529 static void
9530 cmd_set_fdir_input_set_parsed(void *parsed_result,
9531         __rte_unused struct cmdline *cl,
9532         __rte_unused void *data)
9533 {
9534         struct cmd_set_fdir_input_set_result *res = parsed_result;
9535         struct rte_eth_fdir_filter_info info;
9536
9537         memset(&info, 0, sizeof(info));
9538         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
9539         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
9540         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
9541         info.info.input_set_conf.inset_size = 1;
9542         if (!strcmp(res->select, "select"))
9543                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
9544         else if (!strcmp(res->select, "add"))
9545                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
9546         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
9547                 RTE_ETH_FILTER_SET, &info);
9548 }
9549
9550 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
9551         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9552         set_fdir_input_set, "set_fdir_input_set");
9553 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
9554         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
9555         port_id, UINT8);
9556 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
9557         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9558         flow_type,
9559         "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
9560         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
9561 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
9562         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9563         inset_field,
9564         "src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#udp-src-port#udp-dst-port#"
9565         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
9566         "sctp-veri-tag#fld-1st#fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#"
9567         "fld-7th#fld-8th#none");
9568 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
9569         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
9570         select, "select#add");
9571
9572 cmdline_parse_inst_t cmd_set_fdir_input_set = {
9573         .f = cmd_set_fdir_input_set_parsed,
9574         .data = NULL,
9575         .help_str = "set_fdir_input_set <port_id> "
9576         "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|ipv6-frag|"
9577         "ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
9578         "src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|udp-src-port|udp-dst-port|"
9579         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|"
9580         "fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
9581         "fld-7th|fld-8th|none select|add",
9582         .tokens = {
9583                 (void *)&cmd_set_fdir_input_set_cmd,
9584                 (void *)&cmd_set_fdir_input_set_port_id,
9585                 (void *)&cmd_set_fdir_input_set_flow_type,
9586                 (void *)&cmd_set_fdir_input_set_field,
9587                 (void *)&cmd_set_fdir_input_set_select,
9588                 NULL,
9589         },
9590 };
9591
9592 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
9593 struct cmd_mcast_addr_result {
9594         cmdline_fixed_string_t mcast_addr_cmd;
9595         cmdline_fixed_string_t what;
9596         uint8_t port_num;
9597         struct ether_addr mc_addr;
9598 };
9599
9600 static void cmd_mcast_addr_parsed(void *parsed_result,
9601                 __attribute__((unused)) struct cmdline *cl,
9602                 __attribute__((unused)) void *data)
9603 {
9604         struct cmd_mcast_addr_result *res = parsed_result;
9605
9606         if (!is_multicast_ether_addr(&res->mc_addr)) {
9607                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
9608                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
9609                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
9610                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
9611                 return;
9612         }
9613         if (strcmp(res->what, "add") == 0)
9614                 mcast_addr_add(res->port_num, &res->mc_addr);
9615         else
9616                 mcast_addr_remove(res->port_num, &res->mc_addr);
9617 }
9618
9619 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
9620         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
9621                                  mcast_addr_cmd, "mcast_addr");
9622 cmdline_parse_token_string_t cmd_mcast_addr_what =
9623         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
9624                                  "add#remove");
9625 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
9626         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8);
9627 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
9628         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
9629
9630 cmdline_parse_inst_t cmd_mcast_addr = {
9631         .f = cmd_mcast_addr_parsed,
9632         .data = (void *)0,
9633         .help_str = "mcast_addr add|remove X <mcast_addr>: add/remove multicast MAC address on port X",
9634         .tokens = {
9635                 (void *)&cmd_mcast_addr_cmd,
9636                 (void *)&cmd_mcast_addr_what,
9637                 (void *)&cmd_mcast_addr_portnum,
9638                 (void *)&cmd_mcast_addr_addr,
9639                 NULL,
9640         },
9641 };
9642
9643 /* l2 tunnel config
9644  * only support E-tag now.
9645  */
9646
9647 /* Ether type config */
9648 struct cmd_config_l2_tunnel_eth_type_result {
9649         cmdline_fixed_string_t port;
9650         cmdline_fixed_string_t config;
9651         cmdline_fixed_string_t all;
9652         uint8_t id;
9653         cmdline_fixed_string_t l2_tunnel;
9654         cmdline_fixed_string_t l2_tunnel_type;
9655         cmdline_fixed_string_t eth_type;
9656         uint16_t eth_type_val;
9657 };
9658
9659 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
9660         TOKEN_STRING_INITIALIZER
9661                 (struct cmd_config_l2_tunnel_eth_type_result,
9662                  port, "port");
9663 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
9664         TOKEN_STRING_INITIALIZER
9665                 (struct cmd_config_l2_tunnel_eth_type_result,
9666                  config, "config");
9667 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
9668         TOKEN_STRING_INITIALIZER
9669                 (struct cmd_config_l2_tunnel_eth_type_result,
9670                  all, "all");
9671 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
9672         TOKEN_NUM_INITIALIZER
9673                 (struct cmd_config_l2_tunnel_eth_type_result,
9674                  id, UINT8);
9675 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
9676         TOKEN_STRING_INITIALIZER
9677                 (struct cmd_config_l2_tunnel_eth_type_result,
9678                  l2_tunnel, "l2-tunnel");
9679 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
9680         TOKEN_STRING_INITIALIZER
9681                 (struct cmd_config_l2_tunnel_eth_type_result,
9682                  l2_tunnel_type, "E-tag");
9683 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
9684         TOKEN_STRING_INITIALIZER
9685                 (struct cmd_config_l2_tunnel_eth_type_result,
9686                  eth_type, "ether-type");
9687 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
9688         TOKEN_NUM_INITIALIZER
9689                 (struct cmd_config_l2_tunnel_eth_type_result,
9690                  eth_type_val, UINT16);
9691
9692 static uint32_t
9693 str2fdir_l2_tunnel_type(char *string)
9694 {
9695         uint32_t i = 0;
9696
9697         static const struct {
9698                 char str[32];
9699                 uint32_t type;
9700         } l2_tunnel_type_str[] = {
9701                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
9702         };
9703
9704         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
9705                 if (!strcmp(l2_tunnel_type_str[i].str, string))
9706                         return l2_tunnel_type_str[i].type;
9707         }
9708         return RTE_TUNNEL_TYPE_NONE;
9709 }
9710
9711 /* ether type config for all ports */
9712 static void
9713 cmd_config_l2_tunnel_eth_type_all_parsed
9714         (void *parsed_result,
9715          __attribute__((unused)) struct cmdline *cl,
9716          __attribute__((unused)) void *data)
9717 {
9718         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
9719         struct rte_eth_l2_tunnel_conf entry;
9720         portid_t pid;
9721
9722         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
9723         entry.ether_type = res->eth_type_val;
9724
9725         FOREACH_PORT(pid, ports) {
9726                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
9727         }
9728 }
9729
9730 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
9731         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
9732         .data = NULL,
9733         .help_str = "port config all l2-tunnel ether-type",
9734         .tokens = {
9735                 (void *)&cmd_config_l2_tunnel_eth_type_port,
9736                 (void *)&cmd_config_l2_tunnel_eth_type_config,
9737                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
9738                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
9739                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
9740                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
9741                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
9742                 NULL,
9743         },
9744 };
9745
9746 /* ether type config for a specific port */
9747 static void
9748 cmd_config_l2_tunnel_eth_type_specific_parsed(
9749         void *parsed_result,
9750         __attribute__((unused)) struct cmdline *cl,
9751         __attribute__((unused)) void *data)
9752 {
9753         struct cmd_config_l2_tunnel_eth_type_result *res =
9754                  parsed_result;
9755         struct rte_eth_l2_tunnel_conf entry;
9756
9757         if (port_id_is_invalid(res->id, ENABLED_WARN))
9758                 return;
9759
9760         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
9761         entry.ether_type = res->eth_type_val;
9762
9763         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
9764 }
9765
9766 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
9767         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
9768         .data = NULL,
9769         .help_str = "port config l2-tunnel ether-type",
9770         .tokens = {
9771                 (void *)&cmd_config_l2_tunnel_eth_type_port,
9772                 (void *)&cmd_config_l2_tunnel_eth_type_config,
9773                 (void *)&cmd_config_l2_tunnel_eth_type_id,
9774                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
9775                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
9776                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
9777                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
9778                 NULL,
9779         },
9780 };
9781
9782 /* Enable/disable l2 tunnel */
9783 struct cmd_config_l2_tunnel_en_dis_result {
9784         cmdline_fixed_string_t port;
9785         cmdline_fixed_string_t config;
9786         cmdline_fixed_string_t all;
9787         uint8_t id;
9788         cmdline_fixed_string_t l2_tunnel;
9789         cmdline_fixed_string_t l2_tunnel_type;
9790         cmdline_fixed_string_t en_dis;
9791 };
9792
9793 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
9794         TOKEN_STRING_INITIALIZER
9795                 (struct cmd_config_l2_tunnel_en_dis_result,
9796                  port, "port");
9797 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
9798         TOKEN_STRING_INITIALIZER
9799                 (struct cmd_config_l2_tunnel_en_dis_result,
9800                  config, "config");
9801 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
9802         TOKEN_STRING_INITIALIZER
9803                 (struct cmd_config_l2_tunnel_en_dis_result,
9804                  all, "all");
9805 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
9806         TOKEN_NUM_INITIALIZER
9807                 (struct cmd_config_l2_tunnel_en_dis_result,
9808                  id, UINT8);
9809 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
9810         TOKEN_STRING_INITIALIZER
9811                 (struct cmd_config_l2_tunnel_en_dis_result,
9812                  l2_tunnel, "l2-tunnel");
9813 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
9814         TOKEN_STRING_INITIALIZER
9815                 (struct cmd_config_l2_tunnel_en_dis_result,
9816                  l2_tunnel_type, "E-tag");
9817 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
9818         TOKEN_STRING_INITIALIZER
9819                 (struct cmd_config_l2_tunnel_en_dis_result,
9820                  en_dis, "enable#disable");
9821
9822 /* enable/disable l2 tunnel for all ports */
9823 static void
9824 cmd_config_l2_tunnel_en_dis_all_parsed(
9825         void *parsed_result,
9826         __attribute__((unused)) struct cmdline *cl,
9827         __attribute__((unused)) void *data)
9828 {
9829         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
9830         struct rte_eth_l2_tunnel_conf entry;
9831         portid_t pid;
9832         uint8_t en;
9833
9834         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
9835
9836         if (!strcmp("enable", res->en_dis))
9837                 en = 1;
9838         else
9839                 en = 0;
9840
9841         FOREACH_PORT(pid, ports) {
9842                 rte_eth_dev_l2_tunnel_offload_set(pid,
9843                                                   &entry,
9844                                                   ETH_L2_TUNNEL_ENABLE_MASK,
9845                                                   en);
9846         }
9847 }
9848
9849 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
9850         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
9851         .data = NULL,
9852         .help_str = "port config all l2-tunnel enable/disable",
9853         .tokens = {
9854                 (void *)&cmd_config_l2_tunnel_en_dis_port,
9855                 (void *)&cmd_config_l2_tunnel_en_dis_config,
9856                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
9857                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
9858                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
9859                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
9860                 NULL,
9861         },
9862 };
9863
9864 /* enable/disable l2 tunnel for a port */
9865 static void
9866 cmd_config_l2_tunnel_en_dis_specific_parsed(
9867         void *parsed_result,
9868         __attribute__((unused)) struct cmdline *cl,
9869         __attribute__((unused)) void *data)
9870 {
9871         struct cmd_config_l2_tunnel_en_dis_result *res =
9872                 parsed_result;
9873         struct rte_eth_l2_tunnel_conf entry;
9874
9875         if (port_id_is_invalid(res->id, ENABLED_WARN))
9876                 return;
9877
9878         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
9879
9880         if (!strcmp("enable", res->en_dis))
9881                 rte_eth_dev_l2_tunnel_offload_set(res->id,
9882                                                   &entry,
9883                                                   ETH_L2_TUNNEL_ENABLE_MASK,
9884                                                   1);
9885         else
9886                 rte_eth_dev_l2_tunnel_offload_set(res->id,
9887                                                   &entry,
9888                                                   ETH_L2_TUNNEL_ENABLE_MASK,
9889                                                   0);
9890 }
9891
9892 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
9893         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
9894         .data = NULL,
9895         .help_str = "port config l2-tunnel enable/disable",
9896         .tokens = {
9897                 (void *)&cmd_config_l2_tunnel_en_dis_port,
9898                 (void *)&cmd_config_l2_tunnel_en_dis_config,
9899                 (void *)&cmd_config_l2_tunnel_en_dis_id,
9900                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
9901                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
9902                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
9903                 NULL,
9904         },
9905 };
9906
9907 /* ******************************************************************************** */
9908
9909 /* list of instructions */
9910 cmdline_parse_ctx_t main_ctx[] = {
9911         (cmdline_parse_inst_t *)&cmd_help_brief,
9912         (cmdline_parse_inst_t *)&cmd_help_long,
9913         (cmdline_parse_inst_t *)&cmd_quit,
9914         (cmdline_parse_inst_t *)&cmd_showport,
9915         (cmdline_parse_inst_t *)&cmd_showqueue,
9916         (cmdline_parse_inst_t *)&cmd_showportall,
9917         (cmdline_parse_inst_t *)&cmd_showcfg,
9918         (cmdline_parse_inst_t *)&cmd_start,
9919         (cmdline_parse_inst_t *)&cmd_start_tx_first,
9920         (cmdline_parse_inst_t *)&cmd_set_link_up,
9921         (cmdline_parse_inst_t *)&cmd_set_link_down,
9922         (cmdline_parse_inst_t *)&cmd_reset,
9923         (cmdline_parse_inst_t *)&cmd_set_numbers,
9924         (cmdline_parse_inst_t *)&cmd_set_txpkts,
9925         (cmdline_parse_inst_t *)&cmd_set_txsplit,
9926         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
9927         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
9928         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
9929         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
9930         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
9931         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
9932         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
9933         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
9934         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
9935         (cmdline_parse_inst_t *)&cmd_set_link_check,
9936 #ifdef RTE_NIC_BYPASS
9937         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
9938         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
9939         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
9940         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
9941 #endif
9942 #ifdef RTE_LIBRTE_PMD_BOND
9943         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
9944         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
9945         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
9946         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
9947         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
9948         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
9949         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
9950         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
9951         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
9952 #endif
9953         (cmdline_parse_inst_t *)&cmd_vlan_offload,
9954         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
9955         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
9956         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
9957         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
9958         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
9959         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
9960         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
9961         (cmdline_parse_inst_t *)&cmd_csum_set,
9962         (cmdline_parse_inst_t *)&cmd_csum_show,
9963         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
9964         (cmdline_parse_inst_t *)&cmd_tso_set,
9965         (cmdline_parse_inst_t *)&cmd_tso_show,
9966         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
9967         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
9968         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
9969         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
9970         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
9971         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
9972         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
9973         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
9974         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
9975         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
9976         (cmdline_parse_inst_t *)&cmd_config_dcb,
9977         (cmdline_parse_inst_t *)&cmd_read_reg,
9978         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
9979         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
9980         (cmdline_parse_inst_t *)&cmd_write_reg,
9981         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
9982         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
9983         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
9984         (cmdline_parse_inst_t *)&cmd_stop,
9985         (cmdline_parse_inst_t *)&cmd_mac_addr,
9986         (cmdline_parse_inst_t *)&cmd_set_qmap,
9987         (cmdline_parse_inst_t *)&cmd_operate_port,
9988         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
9989         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
9990         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
9991         (cmdline_parse_inst_t *)&cmd_config_speed_all,
9992         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
9993         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
9994         (cmdline_parse_inst_t *)&cmd_config_mtu,
9995         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
9996         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
9997         (cmdline_parse_inst_t *)&cmd_config_rss,
9998         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
9999         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
10000         (cmdline_parse_inst_t *)&cmd_showport_reta,
10001         (cmdline_parse_inst_t *)&cmd_config_burst,
10002         (cmdline_parse_inst_t *)&cmd_config_thresh,
10003         (cmdline_parse_inst_t *)&cmd_config_threshold,
10004         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
10005         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
10006         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
10007         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
10008         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
10009         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
10010         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
10011         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
10012         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
10013         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
10014         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
10015         (cmdline_parse_inst_t *)&cmd_global_config,
10016         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
10017         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
10018         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
10019         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
10020         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
10021         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
10022         (cmdline_parse_inst_t *)&cmd_dump,
10023         (cmdline_parse_inst_t *)&cmd_dump_one,
10024         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
10025         (cmdline_parse_inst_t *)&cmd_syn_filter,
10026         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
10027         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
10028         (cmdline_parse_inst_t *)&cmd_flex_filter,
10029         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
10030         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
10031         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
10032         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
10033         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
10034         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
10035         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
10036         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
10037         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
10038         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
10039         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
10040         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
10041         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
10042         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
10043         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
10044         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
10045         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
10046         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
10047         (cmdline_parse_inst_t *)&cmd_mcast_addr,
10048         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
10049         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
10050         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
10051         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
10052         NULL,
10053 };
10054
10055 /* prompt function, called from main on MASTER lcore */
10056 void
10057 prompt(void)
10058 {
10059         /* initialize non-constant commands */
10060         cmd_set_fwd_mode_init();
10061
10062         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
10063         if (testpmd_cl == NULL)
10064                 return;
10065         cmdline_interact(testpmd_cl);
10066         cmdline_stdin_exit(testpmd_cl);
10067 }
10068
10069 void
10070 prompt_exit(void)
10071 {
10072         if (testpmd_cl != NULL)
10073                 cmdline_quit(testpmd_cl);
10074 }
10075
10076 static void
10077 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
10078 {
10079         if (id == (portid_t)RTE_PORT_ALL) {
10080                 portid_t pid;
10081
10082                 FOREACH_PORT(pid, ports) {
10083                         /* check if need_reconfig has been set to 1 */
10084                         if (ports[pid].need_reconfig == 0)
10085                                 ports[pid].need_reconfig = dev;
10086                         /* check if need_reconfig_queues has been set to 1 */
10087                         if (ports[pid].need_reconfig_queues == 0)
10088                                 ports[pid].need_reconfig_queues = queue;
10089                 }
10090         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
10091                 /* check if need_reconfig has been set to 1 */
10092                 if (ports[id].need_reconfig == 0)
10093                         ports[id].need_reconfig = dev;
10094                 /* check if need_reconfig_queues has been set to 1 */
10095                 if (ports[id].need_reconfig_queues == 0)
10096                         ports[id].need_reconfig_queues = queue;
10097         }
10098 }
10099
10100 #ifdef RTE_NIC_BYPASS
10101 #include <rte_pci_dev_ids.h>
10102 uint8_t
10103 bypass_is_supported(portid_t port_id)
10104 {
10105         struct rte_port   *port;
10106         struct rte_pci_id *pci_id;
10107
10108         if (port_id_is_invalid(port_id, ENABLED_WARN))
10109                 return 0;
10110
10111         /* Get the device id. */
10112         port    = &ports[port_id];
10113         pci_id = &port->dev_info.pci_dev->id;
10114
10115         /* Check if NIC supports bypass. */
10116         if (pci_id->device_id == IXGBE_DEV_ID_82599_BYPASS) {
10117                 return 1;
10118         }
10119         else {
10120                 printf("\tBypass not supported for port_id = %d.\n", port_id);
10121                 return 0;
10122         }
10123 }
10124 #endif