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