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