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