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