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