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