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