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