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