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