app/testpmd: add commands for metering and policing
[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 <string.h>
40 #include <termios.h>
41 #include <unistd.h>
42 #include <inttypes.h>
43 #ifndef __linux__
44 #ifndef __FreeBSD__
45 #include <net/socket.h>
46 #else
47 #include <sys/socket.h>
48 #endif
49 #endif
50 #include <netinet/in.h>
51
52 #include <sys/queue.h>
53
54 #include <rte_common.h>
55 #include <rte_byteorder.h>
56 #include <rte_log.h>
57 #include <rte_debug.h>
58 #include <rte_cycles.h>
59 #include <rte_memory.h>
60 #include <rte_memzone.h>
61 #include <rte_malloc.h>
62 #include <rte_launch.h>
63 #include <rte_eal.h>
64 #include <rte_per_lcore.h>
65 #include <rte_lcore.h>
66 #include <rte_atomic.h>
67 #include <rte_branch_prediction.h>
68 #include <rte_ring.h>
69 #include <rte_mempool.h>
70 #include <rte_interrupts.h>
71 #include <rte_pci.h>
72 #include <rte_ether.h>
73 #include <rte_ethdev.h>
74 #include <rte_string_fns.h>
75 #include <rte_devargs.h>
76 #include <rte_eth_ctrl.h>
77 #include <rte_flow.h>
78 #include <rte_gro.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 #include <rte_eth_bond_8023ad.h>
91 #endif
92 #ifdef RTE_LIBRTE_IXGBE_PMD
93 #include <rte_pmd_ixgbe.h>
94 #endif
95 #ifdef RTE_LIBRTE_I40E_PMD
96 #include <rte_pmd_i40e.h>
97 #endif
98 #ifdef RTE_LIBRTE_BNXT_PMD
99 #include <rte_pmd_bnxt.h>
100 #endif
101 #include "testpmd.h"
102 #include "cmdline_mtr.h"
103 #include "cmdline_tm.h"
104
105 static struct cmdline *testpmd_cl;
106
107 static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue);
108
109 /* *** Help command with introduction. *** */
110 struct cmd_help_brief_result {
111         cmdline_fixed_string_t help;
112 };
113
114 static void cmd_help_brief_parsed(__attribute__((unused)) void *parsed_result,
115                                   struct cmdline *cl,
116                                   __attribute__((unused)) void *data)
117 {
118         cmdline_printf(
119                 cl,
120                 "\n"
121                 "Help is available for the following sections:\n\n"
122                 "    help control    : Start and stop forwarding.\n"
123                 "    help display    : Displaying port, stats and config "
124                 "information.\n"
125                 "    help config     : Configuration information.\n"
126                 "    help ports      : Configuring ports.\n"
127                 "    help registers  : Reading and setting port registers.\n"
128                 "    help filters    : Filters configuration help.\n"
129                 "    help all        : All of the above sections.\n\n"
130         );
131
132 }
133
134 cmdline_parse_token_string_t cmd_help_brief_help =
135         TOKEN_STRING_INITIALIZER(struct cmd_help_brief_result, help, "help");
136
137 cmdline_parse_inst_t cmd_help_brief = {
138         .f = cmd_help_brief_parsed,
139         .data = NULL,
140         .help_str = "help: Show help",
141         .tokens = {
142                 (void *)&cmd_help_brief_help,
143                 NULL,
144         },
145 };
146
147 /* *** Help command with help sections. *** */
148 struct cmd_help_long_result {
149         cmdline_fixed_string_t help;
150         cmdline_fixed_string_t section;
151 };
152
153 static void cmd_help_long_parsed(void *parsed_result,
154                                  struct cmdline *cl,
155                                  __attribute__((unused)) void *data)
156 {
157         int show_all = 0;
158         struct cmd_help_long_result *res = parsed_result;
159
160         if (!strcmp(res->section, "all"))
161                 show_all = 1;
162
163         if (show_all || !strcmp(res->section, "control")) {
164
165                 cmdline_printf(
166                         cl,
167                         "\n"
168                         "Control forwarding:\n"
169                         "-------------------\n\n"
170
171                         "start\n"
172                         "    Start packet forwarding with current configuration.\n\n"
173
174                         "start tx_first\n"
175                         "    Start packet forwarding with current config"
176                         " after sending one burst of packets.\n\n"
177
178                         "stop\n"
179                         "    Stop packet forwarding, and display accumulated"
180                         " statistics.\n\n"
181
182                         "quit\n"
183                         "    Quit to prompt.\n\n"
184                 );
185         }
186
187         if (show_all || !strcmp(res->section, "display")) {
188
189                 cmdline_printf(
190                         cl,
191                         "\n"
192                         "Display:\n"
193                         "--------\n\n"
194
195                         "show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)\n"
196                         "    Display information for port_id, or all.\n\n"
197
198                         "show port X rss reta (size) (mask0,mask1,...)\n"
199                         "    Display the rss redirection table entry indicated"
200                         " by masks on port X. size is used to indicate the"
201                         " hardware supported reta size\n\n"
202
203                         "show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|"
204                         "ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
205                         "ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]\n"
206                         "    Display the RSS hash functions and RSS hash key"
207                         " of port X\n\n"
208
209                         "clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)\n"
210                         "    Clear information for port_id, or all.\n\n"
211
212                         "show (rxq|txq) info (port_id) (queue_id)\n"
213                         "    Display information for configured RX/TX queue.\n\n"
214
215                         "show config (rxtx|cores|fwd|txpkts)\n"
216                         "    Display the given configuration.\n\n"
217
218                         "read rxd (port_id) (queue_id) (rxd_id)\n"
219                         "    Display an RX descriptor of a port RX queue.\n\n"
220
221                         "read txd (port_id) (queue_id) (txd_id)\n"
222                         "    Display a TX descriptor of a port TX queue.\n\n"
223
224                         "ddp get list (port_id)\n"
225                         "    Get ddp profile info list\n\n"
226
227                         "ddp get info (profile_path)\n"
228                         "    Get ddp profile information.\n\n"
229
230                         "show vf stats (port_id) (vf_id)\n"
231                         "    Display a VF's statistics.\n\n"
232
233                         "clear vf stats (port_id) (vf_id)\n"
234                         "    Reset a VF's statistics.\n\n"
235
236                         "show port (port_id) pctype mapping\n"
237                         "    Get flow ptype to pctype mapping on a port\n\n"
238
239                         "show port meter stats (port_id) (meter_id) (clear)\n"
240                         "    Get meter stats on a port\n\n"
241                         "show port tm cap (port_id)\n"
242                         "       Display the port TM capability.\n\n"
243
244                         "show port tm level cap (port_id) (level_id)\n"
245                         "       Display the port TM hierarchical level capability.\n\n"
246
247                         "show port tm node cap (port_id) (node_id)\n"
248                         "       Display the port TM node capability.\n\n"
249
250                         "show port tm node type (port_id) (node_id)\n"
251                         "       Display the port TM node type.\n\n"
252
253                         "show port tm node stats (port_id) (node_id) (clear)\n"
254                         "       Display the port TM node stats.\n\n"
255
256                 );
257         }
258
259         if (show_all || !strcmp(res->section, "config")) {
260                 cmdline_printf(
261                         cl,
262                         "\n"
263                         "Configuration:\n"
264                         "--------------\n"
265                         "Configuration changes only become active when"
266                         " forwarding is started/restarted.\n\n"
267
268                         "set default\n"
269                         "    Reset forwarding to the default configuration.\n\n"
270
271                         "set verbose (level)\n"
272                         "    Set the debug verbosity level X.\n\n"
273
274                         "set nbport (num)\n"
275                         "    Set number of ports.\n\n"
276
277                         "set nbcore (num)\n"
278                         "    Set number of cores.\n\n"
279
280                         "set coremask (mask)\n"
281                         "    Set the forwarding cores hexadecimal mask.\n\n"
282
283                         "set portmask (mask)\n"
284                         "    Set the forwarding ports hexadecimal mask.\n\n"
285
286                         "set burst (num)\n"
287                         "    Set number of packets per burst.\n\n"
288
289                         "set burst tx delay (microseconds) retry (num)\n"
290                         "    Set the transmit delay time and number of retries,"
291                         " effective when retry is enabled.\n\n"
292
293                         "set txpkts (x[,y]*)\n"
294                         "    Set the length of each segment of TXONLY"
295                         " and optionally CSUM packets.\n\n"
296
297                         "set txsplit (off|on|rand)\n"
298                         "    Set the split policy for the TX packets."
299                         " Right now only applicable for CSUM and TXONLY"
300                         " modes\n\n"
301
302                         "set corelist (x[,y]*)\n"
303                         "    Set the list of forwarding cores.\n\n"
304
305                         "set portlist (x[,y]*)\n"
306                         "    Set the list of forwarding ports.\n\n"
307
308                         "set tx loopback (port_id) (on|off)\n"
309                         "    Enable or disable tx loopback.\n\n"
310
311                         "set all queues drop (port_id) (on|off)\n"
312                         "    Set drop enable bit for all queues.\n\n"
313
314                         "set vf split drop (port_id) (vf_id) (on|off)\n"
315                         "    Set split drop enable bit for a VF from the PF.\n\n"
316
317                         "set vf mac antispoof (port_id) (vf_id) (on|off).\n"
318                         "    Set MAC antispoof for a VF from the PF.\n\n"
319
320                         "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n"
321                         "    Enable MACsec offload.\n\n"
322
323                         "set macsec offload (port_id) off\n"
324                         "    Disable MACsec offload.\n\n"
325
326                         "set macsec sc (tx|rx) (port_id) (mac) (pi)\n"
327                         "    Configure MACsec secure connection (SC).\n\n"
328
329                         "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n"
330                         "    Configure MACsec secure association (SA).\n\n"
331
332                         "set vf broadcast (port_id) (vf_id) (on|off)\n"
333                         "    Set VF broadcast for a VF from the PF.\n\n"
334
335                         "vlan set strip (on|off) (port_id)\n"
336                         "    Set the VLAN strip on a port.\n\n"
337
338                         "vlan set stripq (on|off) (port_id,queue_id)\n"
339                         "    Set the VLAN strip for a queue on a port.\n\n"
340
341                         "set vf vlan stripq (port_id) (vf_id) (on|off)\n"
342                         "    Set the VLAN strip for all queues in a pool for a VF from the PF.\n\n"
343
344                         "set vf vlan insert (port_id) (vf_id) (vlan_id)\n"
345                         "    Set VLAN insert for a VF from the PF.\n\n"
346
347                         "set vf vlan antispoof (port_id) (vf_id) (on|off)\n"
348                         "    Set VLAN antispoof for a VF from the PF.\n\n"
349
350                         "set vf vlan tag (port_id) (vf_id) (on|off)\n"
351                         "    Set VLAN tag for a VF from the PF.\n\n"
352
353                         "set vf tx max-bandwidth (port_id) (vf_id) (bandwidth)\n"
354                         "    Set a VF's max bandwidth(Mbps).\n\n"
355
356                         "set vf tc tx min-bandwidth (port_id) (vf_id) (bw1, bw2, ...)\n"
357                         "    Set all TCs' min bandwidth(%%) on a VF.\n\n"
358
359                         "set vf tc tx max-bandwidth (port_id) (vf_id) (tc_no) (bandwidth)\n"
360                         "    Set a TC's max bandwidth(Mbps) on a VF.\n\n"
361
362                         "set tx strict-link-priority (port_id) (tc_bitmap)\n"
363                         "    Set some TCs' strict link priority mode on a physical port.\n\n"
364
365                         "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n"
366                         "    Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n"
367
368                         "vlan set filter (on|off) (port_id)\n"
369                         "    Set the VLAN filter on a port.\n\n"
370
371                         "vlan set qinq (on|off) (port_id)\n"
372                         "    Set the VLAN QinQ (extended queue in queue)"
373                         " on a port.\n\n"
374
375                         "vlan set (inner|outer) tpid (value) (port_id)\n"
376                         "    Set the VLAN TPID for Packet Filtering on"
377                         " a port\n\n"
378
379                         "rx_vlan add (vlan_id|all) (port_id)\n"
380                         "    Add a vlan_id, or all identifiers, to the set"
381                         " of VLAN identifiers filtered by port_id.\n\n"
382
383                         "rx_vlan rm (vlan_id|all) (port_id)\n"
384                         "    Remove a vlan_id, or all identifiers, from the set"
385                         " of VLAN identifiers filtered by port_id.\n\n"
386
387                         "rx_vlan add (vlan_id) port (port_id) vf (vf_mask)\n"
388                         "    Add a vlan_id, to the set of VLAN identifiers"
389                         "filtered for VF(s) from port_id.\n\n"
390
391                         "rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)\n"
392                         "    Remove a vlan_id, to the set of VLAN identifiers"
393                         "filtered for VF(s) from port_id.\n\n"
394
395                         "tunnel_filter add (port_id) (outer_mac) (inner_mac) (ip_addr) "
396                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
397                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
398                         "   add a tunnel filter of a port.\n\n"
399
400                         "tunnel_filter rm (port_id) (outer_mac) (inner_mac) (ip_addr) "
401                         "(inner_vlan) (vxlan|nvgre|ipingre) (imac-ivlan|imac-ivlan-tenid|"
402                         "imac-tenid|imac|omac-imac-tenid|oip|iip) (tenant_id) (queue_id)\n"
403                         "   remove a tunnel filter of a port.\n\n"
404
405                         "rx_vxlan_port add (udp_port) (port_id)\n"
406                         "    Add an UDP port for VXLAN packet filter on a port\n\n"
407
408                         "rx_vxlan_port rm (udp_port) (port_id)\n"
409                         "    Remove an UDP port for VXLAN packet filter on a port\n\n"
410
411                         "tx_vlan set (port_id) vlan_id[, vlan_id_outer]\n"
412                         "    Set hardware insertion of VLAN IDs (single or double VLAN "
413                         "depends on the number of VLAN IDs) in packets sent on a port.\n\n"
414
415                         "tx_vlan set pvid port_id vlan_id (on|off)\n"
416                         "    Set port based TX VLAN insertion.\n\n"
417
418                         "tx_vlan reset (port_id)\n"
419                         "    Disable hardware insertion of a VLAN header in"
420                         " packets sent on a port.\n\n"
421
422                         "csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)\n"
423                         "    Select hardware or software calculation of the"
424                         " checksum when transmitting a packet using the"
425                         " csum forward engine.\n"
426                         "    ip|udp|tcp|sctp always concern the inner layer.\n"
427                         "    outer-ip concerns the outer IP layer in"
428                         " case the packet is recognized as a tunnel packet by"
429                         " the forward engine (vxlan, gre and ipip are supported)\n"
430                         "    Please check the NIC datasheet for HW limits.\n\n"
431
432                         "csum parse-tunnel (on|off) (tx_port_id)\n"
433                         "    If disabled, treat tunnel packets as non-tunneled"
434                         " packets (treat inner headers as payload). The port\n"
435                         "    argument is the port used for TX in csum forward"
436                         " engine.\n\n"
437
438                         "csum show (port_id)\n"
439                         "    Display tx checksum offload configuration\n\n"
440
441                         "tso set (segsize) (portid)\n"
442                         "    Enable TCP Segmentation Offload in csum forward"
443                         " engine.\n"
444                         "    Please check the NIC datasheet for HW limits.\n\n"
445
446                         "tso show (portid)"
447                         "    Display the status of TCP Segmentation Offload.\n\n"
448
449                         "set port (port_id) gro on|off\n"
450                         "    Enable or disable Generic Receive Offload in"
451                         " csum forwarding engine.\n\n"
452
453                         "show port (port_id) gro\n"
454                         "    Display GRO configuration.\n\n"
455
456                         "set gro flush (cycles)\n"
457                         "    Set the cycle to flush GROed packets from"
458                         " reassembly tables.\n\n"
459
460                         "set port (port_id) gso (on|off)"
461                         "    Enable or disable Generic Segmentation Offload in"
462                         " csum forwarding engine.\n\n"
463
464                         "set gso segsz (length)\n"
465                         "    Set max packet length for output GSO segments,"
466                         " including packet header and payload.\n\n"
467
468                         "show port (port_id) gso\n"
469                         "    Show GSO configuration.\n\n"
470
471                         "set fwd (%s)\n"
472                         "    Set packet forwarding mode.\n\n"
473
474                         "mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
475                         "    Add a MAC address on port_id.\n\n"
476
477                         "mac_addr remove (port_id) (XX:XX:XX:XX:XX:XX)\n"
478                         "    Remove a MAC address from port_id.\n\n"
479
480                         "mac_addr set (port_id) (XX:XX:XX:XX:XX:XX)\n"
481                         "    Set the default MAC address for port_id.\n\n"
482
483                         "mac_addr add port (port_id) vf (vf_id) (mac_address)\n"
484                         "    Add a MAC address for a VF on the port.\n\n"
485
486                         "set vf mac addr (port_id) (vf_id) (XX:XX:XX:XX:XX:XX)\n"
487                         "    Set the MAC address for a VF from the PF.\n\n"
488
489                         "set port (port_id) uta (mac_address|all) (on|off)\n"
490                         "    Add/Remove a or all unicast hash filter(s)"
491                         "from port X.\n\n"
492
493                         "set promisc (port_id|all) (on|off)\n"
494                         "    Set the promiscuous mode on port_id, or all.\n\n"
495
496                         "set allmulti (port_id|all) (on|off)\n"
497                         "    Set the allmulti mode on port_id, or all.\n\n"
498
499                         "set vf promisc (port_id) (vf_id) (on|off)\n"
500                         "    Set unicast promiscuous mode for a VF from the PF.\n\n"
501
502                         "set vf allmulti (port_id) (vf_id) (on|off)\n"
503                         "    Set multicast promiscuous mode for a VF from the PF.\n\n"
504
505                         "set flow_ctrl rx (on|off) tx (on|off) (high_water)"
506                         " (low_water) (pause_time) (send_xon) mac_ctrl_frame_fwd"
507                         " (on|off) autoneg (on|off) (port_id)\n"
508                         "set flow_ctrl rx (on|off) (portid)\n"
509                         "set flow_ctrl tx (on|off) (portid)\n"
510                         "set flow_ctrl high_water (high_water) (portid)\n"
511                         "set flow_ctrl low_water (low_water) (portid)\n"
512                         "set flow_ctrl pause_time (pause_time) (portid)\n"
513                         "set flow_ctrl send_xon (send_xon) (portid)\n"
514                         "set flow_ctrl mac_ctrl_frame_fwd (on|off) (portid)\n"
515                         "set flow_ctrl autoneg (on|off) (port_id)\n"
516                         "    Set the link flow control parameter on a port.\n\n"
517
518                         "set pfc_ctrl rx (on|off) tx (on|off) (high_water)"
519                         " (low_water) (pause_time) (priority) (port_id)\n"
520                         "    Set the priority flow control parameter on a"
521                         " port.\n\n"
522
523                         "set stat_qmap (tx|rx) (port_id) (queue_id) (qmapping)\n"
524                         "    Set statistics mapping (qmapping 0..15) for RX/TX"
525                         " queue on port.\n"
526                         "    e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2"
527                         " on port 0 to mapping 5.\n\n"
528
529                         "set xstats-hide-zero on|off\n"
530                         "    Set the option to hide the zero values"
531                         " for xstats display.\n"
532
533                         "set port (port_id) vf (vf_id) rx|tx on|off\n"
534                         "    Enable/Disable a VF receive/tranmit from a port\n\n"
535
536                         "set port (port_id) vf (vf_id) (mac_addr)"
537                         " (exact-mac#exact-mac-vlan#hashmac|hashmac-vlan) on|off\n"
538                         "   Add/Remove unicast or multicast MAC addr filter"
539                         " for a VF.\n\n"
540
541                         "set port (port_id) vf (vf_id) rxmode (AUPE|ROPE|BAM"
542                         "|MPE) (on|off)\n"
543                         "    AUPE:accepts untagged VLAN;"
544                         "ROPE:accept unicast hash\n\n"
545                         "    BAM:accepts broadcast packets;"
546                         "MPE:accepts all multicast packets\n\n"
547                         "    Enable/Disable a VF receive mode of a port\n\n"
548
549                         "set port (port_id) queue (queue_id) rate (rate_num)\n"
550                         "    Set rate limit for a queue of a port\n\n"
551
552                         "set port (port_id) vf (vf_id) rate (rate_num) "
553                         "queue_mask (queue_mask_value)\n"
554                         "    Set rate limit for queues in VF of a port\n\n"
555
556                         "set port (port_id) mirror-rule (rule_id)"
557                         " (pool-mirror-up|pool-mirror-down|vlan-mirror)"
558                         " (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
559                         "   Set pool or vlan type mirror rule on a port.\n"
560                         "   e.g., 'set port 0 mirror-rule 0 vlan-mirror 0,1"
561                         " dst-pool 0 on' enable mirror traffic with vlan 0,1"
562                         " to pool 0.\n\n"
563
564                         "set port (port_id) mirror-rule (rule_id)"
565                         " (uplink-mirror|downlink-mirror) dst-pool"
566                         " (pool_id) (on|off)\n"
567                         "   Set uplink or downlink type mirror rule on a port.\n"
568                         "   e.g., 'set port 0 mirror-rule 0 uplink-mirror dst-pool"
569                         " 0 on' enable mirror income traffic to pool 0.\n\n"
570
571                         "reset port (port_id) mirror-rule (rule_id)\n"
572                         "   Reset a mirror rule.\n\n"
573
574                         "set flush_rx (on|off)\n"
575                         "   Flush (default) or don't flush RX streams before"
576                         " forwarding. Mainly used with PCAP drivers.\n\n"
577
578                         "set bypass mode (normal|bypass|isolate) (port_id)\n"
579                         "   Set the bypass mode for the lowest port on bypass enabled"
580                         " NIC.\n\n"
581
582                         "set bypass event (timeout|os_on|os_off|power_on|power_off) "
583                         "mode (normal|bypass|isolate) (port_id)\n"
584                         "   Set the event required to initiate specified bypass mode for"
585                         " the lowest port on a bypass enabled NIC where:\n"
586                         "       timeout   = enable bypass after watchdog timeout.\n"
587                         "       os_on     = enable bypass when OS/board is powered on.\n"
588                         "       os_off    = enable bypass when OS/board is powered off.\n"
589                         "       power_on  = enable bypass when power supply is turned on.\n"
590                         "       power_off = enable bypass when power supply is turned off."
591                         "\n\n"
592
593                         "set bypass timeout (0|1.5|2|3|4|8|16|32)\n"
594                         "   Set the bypass watchdog timeout to 'n' seconds"
595                         " where 0 = instant.\n\n"
596
597                         "show bypass config (port_id)\n"
598                         "   Show the bypass configuration for a bypass enabled NIC"
599                         " using the lowest port on the NIC.\n\n"
600
601 #ifdef RTE_LIBRTE_PMD_BOND
602                         "create bonded device (mode) (socket)\n"
603                         "       Create a new bonded device with specific bonding mode and socket.\n\n"
604
605                         "add bonding slave (slave_id) (port_id)\n"
606                         "       Add a slave device to a bonded device.\n\n"
607
608                         "remove bonding slave (slave_id) (port_id)\n"
609                         "       Remove a slave device from a bonded device.\n\n"
610
611                         "set bonding mode (value) (port_id)\n"
612                         "       Set the bonding mode on a bonded device.\n\n"
613
614                         "set bonding primary (slave_id) (port_id)\n"
615                         "       Set the primary slave for a bonded device.\n\n"
616
617                         "show bonding config (port_id)\n"
618                         "       Show the bonding config for port_id.\n\n"
619
620                         "set bonding mac_addr (port_id) (address)\n"
621                         "       Set the MAC address of a bonded device.\n\n"
622
623                         "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)"
624                         "       Set Aggregation mode for IEEE802.3AD (mode 4)"
625
626                         "set bonding xmit_balance_policy (port_id) (l2|l23|l34)\n"
627                         "       Set the transmit balance policy for bonded device running in balance mode.\n\n"
628
629                         "set bonding mon_period (port_id) (value)\n"
630                         "       Set the bonding link status monitoring polling period in ms.\n\n"
631
632                         "set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
633                         "       Enable/disable dedicated queues for LACP control traffic.\n\n"
634
635 #endif
636                         "set link-up port (port_id)\n"
637                         "       Set link up for a port.\n\n"
638
639                         "set link-down port (port_id)\n"
640                         "       Set link down for a port.\n\n"
641
642                         "E-tag set insertion on port-tag-id (value)"
643                         " port (port_id) vf (vf_id)\n"
644                         "    Enable E-tag insertion for a VF on a port\n\n"
645
646                         "E-tag set insertion off port (port_id) vf (vf_id)\n"
647                         "    Disable E-tag insertion for a VF on a port\n\n"
648
649                         "E-tag set stripping (on|off) port (port_id)\n"
650                         "    Enable/disable E-tag stripping on a port\n\n"
651
652                         "E-tag set forwarding (on|off) port (port_id)\n"
653                         "    Enable/disable E-tag based forwarding"
654                         " on a port\n\n"
655
656                         "E-tag set filter add e-tag-id (value) dst-pool"
657                         " (pool_id) port (port_id)\n"
658                         "    Add an E-tag forwarding filter on a port\n\n"
659
660                         "E-tag set filter del e-tag-id (value) port (port_id)\n"
661                         "    Delete an E-tag forwarding filter on a port\n\n"
662
663 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
664                         "set port tm hierarchy default (port_id)\n"
665                         "       Set default traffic Management hierarchy on a port\n\n"
666
667 #endif
668                         "ddp add (port_id) (profile_path[,output_path])\n"
669                         "    Load a profile package on a port\n\n"
670
671                         "ddp del (port_id) (profile_path)\n"
672                         "    Delete a profile package from a port\n\n"
673
674                         "ptype mapping get (port_id) (valid_only)\n"
675                         "    Get ptype mapping on a port\n\n"
676
677                         "ptype mapping replace (port_id) (target) (mask) (pky_type)\n"
678                         "    Replace target with the pkt_type in ptype mapping\n\n"
679
680                         "ptype mapping reset (port_id)\n"
681                         "    Reset ptype mapping on a port\n\n"
682
683                         "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n"
684                         "    Update a ptype mapping item on a port\n\n"
685
686                         "set port (port_id) queue-region region_id (value) "
687                         "queue_start_index (value) queue_num (value)\n"
688                         "    Set a queue region on a port\n\n"
689
690                         "set port (port_id) queue-region region_id (value) "
691                         "flowtype (value)\n"
692                         "    Set a flowtype region index on a port\n\n"
693
694                         "set port (port_id) queue-region UP (value) region_id (value)\n"
695                         "    Set the mapping of User Priority to "
696                         "queue region on a port\n\n"
697
698                         "set port (port_id) queue-region flush (on|off)\n"
699                         "    flush all queue region related configuration\n\n"
700
701                         "show port meter cap (port_id)\n"
702                         "    Show port meter capability information\n\n"
703
704                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs)\n"
705                         "    meter profile add - srtcm rfc 2697\n\n"
706
707                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
708                         "    meter profile add - trtcm rfc 2698\n\n"
709
710                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
711                         "    meter profile add - trtcm rfc 4115\n\n"
712
713                         "del port meter profile (port_id) (profile_id)\n"
714                         "    meter profile delete\n\n"
715
716                         "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n"
717                         "(g_action) (y_action) (r_action) (stats_mask) (shared)\n"
718                         "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n"
719                         "(dscp_tbl_entry63)]\n"
720                         "    meter create\n\n"
721
722                         "enable port meter (port_id) (mtr_id)\n"
723                         "    meter enable\n\n"
724
725                         "disable port meter (port_id) (mtr_id)\n"
726                         "    meter disable\n\n"
727
728                         "del port meter (port_id) (mtr_id)\n"
729                         "    meter delete\n\n"
730
731                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
732                         "    meter update meter profile\n\n"
733
734                         "set port meter dscp table (port_id) (mtr_id) [(dscp_tbl_entry0)\n"
735                         "(dscp_tbl_entry1)...(dscp_tbl_entry63)]\n"
736                         "    update meter dscp table entries\n\n"
737
738                         "set port meter policer action (port_id) (mtr_id) (action_mask)\n"
739                         "(action0) [(action1) (action2)]\n"
740                         "    meter update policer action\n\n"
741
742                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
743                         "    meter update stats\n\n"
744
745                         "show port (port_id) queue-region\n"
746                         "    show all queue region related configuration info\n\n"
747
748                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
749                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
750                         "       Add port tm node private shaper profile.\n\n"
751
752                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
753                         "       Delete port tm node private shaper profile.\n\n"
754
755                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
756                         " (shaper_profile_id)\n"
757                         "       Add/update port tm node shared shaper.\n\n"
758
759                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
760                         "       Delete port tm node shared shaper.\n\n"
761
762                         "set port tm node shaper profile (port_id) (node_id)"
763                         " (shaper_profile_id)\n"
764                         "       Set port tm node shaper profile.\n\n"
765
766                         "add port tm node wred profile (port_id) (wred_profile_id)"
767                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
768                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
769                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
770                         "       Add port tm node wred profile.\n\n"
771
772                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
773                         "       Delete port tm node wred profile.\n\n"
774
775                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
776                         " (priority) (weight) (level_id) (shaper_profile_id)"
777                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
778                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
779                         "       Add port tm nonleaf node.\n\n"
780
781                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
782                         " (priority) (weight) (level_id) (shaper_profile_id)"
783                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
784                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
785                         "       Add port tm leaf node.\n\n"
786
787                         "del port tm node (port_id) (node_id)\n"
788                         "       Delete port tm node.\n\n"
789
790                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
791                         " (priority) (weight)\n"
792                         "       Set port tm node parent.\n\n"
793
794                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
795                         "       Commit tm hierarchy.\n\n"
796
797                         , list_pkt_forwarding_modes()
798                 );
799         }
800
801         if (show_all || !strcmp(res->section, "ports")) {
802
803                 cmdline_printf(
804                         cl,
805                         "\n"
806                         "Port Operations:\n"
807                         "----------------\n\n"
808
809                         "port start (port_id|all)\n"
810                         "    Start all ports or port_id.\n\n"
811
812                         "port stop (port_id|all)\n"
813                         "    Stop all ports or port_id.\n\n"
814
815                         "port close (port_id|all)\n"
816                         "    Close all ports or port_id.\n\n"
817
818                         "port attach (ident)\n"
819                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
820
821                         "port detach (port_id)\n"
822                         "    Detach physical or virtual dev by port_id\n\n"
823
824                         "port config (port_id|all)"
825                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
826                         " duplex (half|full|auto)\n"
827                         "    Set speed and duplex for all ports or port_id\n\n"
828
829                         "port config all (rxq|txq|rxd|txd) (value)\n"
830                         "    Set number for rxq/txq/rxd/txd.\n\n"
831
832                         "port config all max-pkt-len (value)\n"
833                         "    Set the max packet length.\n\n"
834
835                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
836                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
837                         " (on|off)\n"
838                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
839                         " for ports.\n\n"
840
841                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
842                         "geneve|nvgre|none|<flowtype_id>)\n"
843                         "    Set the RSS mode.\n\n"
844
845                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
846                         "    Set the RSS redirection table.\n\n"
847
848                         "port config (port_id) dcb vt (on|off) (traffic_class)"
849                         " pfc (on|off)\n"
850                         "    Set the DCB mode.\n\n"
851
852                         "port config all burst (value)\n"
853                         "    Set the number of packets per burst.\n\n"
854
855                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
856                         " (value)\n"
857                         "    Set the ring prefetch/host/writeback threshold"
858                         " for tx/rx queue.\n\n"
859
860                         "port config all (txfreet|txrst|rxfreet) (value)\n"
861                         "    Set free threshold for rx/tx, or set"
862                         " tx rs bit threshold.\n\n"
863                         "port config mtu X value\n"
864                         "    Set the MTU of port X to a given value\n\n"
865
866                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
867                         "    Start/stop a rx/tx queue of port X. Only take effect"
868                         " when port X is started\n\n"
869
870                         "port config (port_id|all) l2-tunnel E-tag ether-type"
871                         " (value)\n"
872                         "    Set the value of E-tag ether-type.\n\n"
873
874                         "port config (port_id|all) l2-tunnel E-tag"
875                         " (enable|disable)\n"
876                         "    Enable/disable the E-tag support.\n\n"
877
878                         "port config (port_id) pctype mapping reset\n"
879                         "    Reset flow type to pctype mapping on a port\n\n"
880
881                         "port config (port_id) pctype mapping update"
882                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
883                         "    Update a flow type to pctype mapping item on a port\n\n"
884                 );
885         }
886
887         if (show_all || !strcmp(res->section, "registers")) {
888
889                 cmdline_printf(
890                         cl,
891                         "\n"
892                         "Registers:\n"
893                         "----------\n\n"
894
895                         "read reg (port_id) (address)\n"
896                         "    Display value of a port register.\n\n"
897
898                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
899                         "    Display a port register bit field.\n\n"
900
901                         "read regbit (port_id) (address) (bit_x)\n"
902                         "    Display a single port register bit.\n\n"
903
904                         "write reg (port_id) (address) (value)\n"
905                         "    Set value of a port register.\n\n"
906
907                         "write regfield (port_id) (address) (bit_x) (bit_y)"
908                         " (value)\n"
909                         "    Set bit field of a port register.\n\n"
910
911                         "write regbit (port_id) (address) (bit_x) (value)\n"
912                         "    Set single bit value of a port register.\n\n"
913                 );
914         }
915         if (show_all || !strcmp(res->section, "filters")) {
916
917                 cmdline_printf(
918                         cl,
919                         "\n"
920                         "filters:\n"
921                         "--------\n\n"
922
923                         "ethertype_filter (port_id) (add|del)"
924                         " (mac_addr|mac_ignr) (mac_address) ethertype"
925                         " (ether_type) (drop|fwd) queue (queue_id)\n"
926                         "    Add/Del an ethertype filter.\n\n"
927
928                         "2tuple_filter (port_id) (add|del)"
929                         " dst_port (dst_port_value) protocol (protocol_value)"
930                         " mask (mask_value) tcp_flags (tcp_flags_value)"
931                         " priority (prio_value) queue (queue_id)\n"
932                         "    Add/Del a 2tuple filter.\n\n"
933
934                         "5tuple_filter (port_id) (add|del)"
935                         " dst_ip (dst_address) src_ip (src_address)"
936                         " dst_port (dst_port_value) src_port (src_port_value)"
937                         " protocol (protocol_value)"
938                         " mask (mask_value) tcp_flags (tcp_flags_value)"
939                         " priority (prio_value) queue (queue_id)\n"
940                         "    Add/Del a 5tuple filter.\n\n"
941
942                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
943                         "    Add/Del syn filter.\n\n"
944
945                         "flex_filter (port_id) (add|del) len (len_value)"
946                         " bytes (bytes_value) mask (mask_value)"
947                         " priority (prio_value) queue (queue_id)\n"
948                         "    Add/Del a flex filter.\n\n"
949
950                         "flow_director_filter (port_id) mode IP (add|del|update)"
951                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
952                         " src (src_ip_address) dst (dst_ip_address)"
953                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
954                         " vlan (vlan_value) flexbytes (flexbytes_value)"
955                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
956                         " fd_id (fd_id_value)\n"
957                         "    Add/Del an IP type flow director filter.\n\n"
958
959                         "flow_director_filter (port_id) mode IP (add|del|update)"
960                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
961                         " src (src_ip_address) (src_port)"
962                         " dst (dst_ip_address) (dst_port)"
963                         " tos (tos_value) ttl (ttl_value)"
964                         " vlan (vlan_value) flexbytes (flexbytes_value)"
965                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
966                         " fd_id (fd_id_value)\n"
967                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode IP (add|del|update)"
970                         " flow (ipv4-sctp|ipv6-sctp)"
971                         " src (src_ip_address) (src_port)"
972                         " dst (dst_ip_address) (dst_port)"
973                         " tag (verification_tag) "
974                         " tos (tos_value) ttl (ttl_value)"
975                         " vlan (vlan_value)"
976                         " flexbytes (flexbytes_value) (drop|fwd)"
977                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
978                         "    Add/Del a SCTP type flow director filter.\n\n"
979
980                         "flow_director_filter (port_id) mode IP (add|del|update)"
981                         " flow l2_payload ether (ethertype)"
982                         " flexbytes (flexbytes_value) (drop|fwd)"
983                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
984                         "    Add/Del a l2 payload type flow director filter.\n\n"
985
986                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
987                         " mac (mac_address) vlan (vlan_value)"
988                         " flexbytes (flexbytes_value) (drop|fwd)"
989                         " queue (queue_id) fd_id (fd_id_value)\n"
990                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
991
992                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
993                         " mac (mac_address) vlan (vlan_value)"
994                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
995                         " flexbytes (flexbytes_value) (drop|fwd)"
996                         " queue (queue_id) fd_id (fd_id_value)\n"
997                         "    Add/Del a Tunnel flow director filter.\n\n"
998
999                         "flush_flow_director (port_id)\n"
1000                         "    Flush all flow director entries of a device.\n\n"
1001
1002                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
1003                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
1004                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
1005                         "    Set flow director IP mask.\n\n"
1006
1007                         "flow_director_mask (port_id) mode MAC-VLAN"
1008                         " vlan (vlan_value)\n"
1009                         "    Set flow director MAC-VLAN mask.\n\n"
1010
1011                         "flow_director_mask (port_id) mode Tunnel"
1012                         " vlan (vlan_value) mac (mac_value)"
1013                         " tunnel-type (tunnel_type_value)"
1014                         " tunnel-id (tunnel_id_value)\n"
1015                         "    Set flow director Tunnel mask.\n\n"
1016
1017                         "flow_director_flex_mask (port_id)"
1018                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1019                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1020                         " (mask)\n"
1021                         "    Configure mask of flex payload.\n\n"
1022
1023                         "flow_director_flex_payload (port_id)"
1024                         " (raw|l2|l3|l4) (config)\n"
1025                         "    Configure flex payload selection.\n\n"
1026
1027                         "get_sym_hash_ena_per_port (port_id)\n"
1028                         "    get symmetric hash enable configuration per port.\n\n"
1029
1030                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1031                         "    set symmetric hash enable configuration per port"
1032                         " to enable or disable.\n\n"
1033
1034                         "get_hash_global_config (port_id)\n"
1035                         "    Get the global configurations of hash filters.\n\n"
1036
1037                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1038                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1039                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1040                         " (enable|disable)\n"
1041                         "    Set the global configurations of hash filters.\n\n"
1042
1043                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1044                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1045                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1046                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1047                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1048                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1049                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1050                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1051                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1052                         "fld-8th|none) (select|add)\n"
1053                         "    Set the input set for hash.\n\n"
1054
1055                         "set_fdir_input_set (port_id) "
1056                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1057                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1058                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1059                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1060                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1061                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1062                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1063                         " (select|add)\n"
1064                         "    Set the input set for FDir.\n\n"
1065
1066                         "flow validate {port_id}"
1067                         " [group {group_id}] [priority {level}]"
1068                         " [ingress] [egress]"
1069                         " pattern {item} [/ {item} [...]] / end"
1070                         " actions {action} [/ {action} [...]] / end\n"
1071                         "    Check whether a flow rule can be created.\n\n"
1072
1073                         "flow create {port_id}"
1074                         " [group {group_id}] [priority {level}]"
1075                         " [ingress] [egress]"
1076                         " pattern {item} [/ {item} [...]] / end"
1077                         " actions {action} [/ {action} [...]] / end\n"
1078                         "    Create a flow rule.\n\n"
1079
1080                         "flow destroy {port_id} rule {rule_id} [...]\n"
1081                         "    Destroy specific flow rules.\n\n"
1082
1083                         "flow flush {port_id}\n"
1084                         "    Destroy all flow rules.\n\n"
1085
1086                         "flow query {port_id} {rule_id} {action}\n"
1087                         "    Query an existing flow rule.\n\n"
1088
1089                         "flow list {port_id} [group {group_id}] [...]\n"
1090                         "    List existing flow rules sorted by priority,"
1091                         " filtered by group identifiers.\n\n"
1092
1093                         "flow isolate {port_id} {boolean}\n"
1094                         "    Restrict ingress traffic to the defined"
1095                         " flow rules\n\n"
1096                 );
1097         }
1098 }
1099
1100 cmdline_parse_token_string_t cmd_help_long_help =
1101         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1102
1103 cmdline_parse_token_string_t cmd_help_long_section =
1104         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1105                         "all#control#display#config#"
1106                         "ports#registers#filters");
1107
1108 cmdline_parse_inst_t cmd_help_long = {
1109         .f = cmd_help_long_parsed,
1110         .data = NULL,
1111         .help_str = "help all|control|display|config|ports|register|filters: "
1112                 "Show help",
1113         .tokens = {
1114                 (void *)&cmd_help_long_help,
1115                 (void *)&cmd_help_long_section,
1116                 NULL,
1117         },
1118 };
1119
1120
1121 /* *** start/stop/close all ports *** */
1122 struct cmd_operate_port_result {
1123         cmdline_fixed_string_t keyword;
1124         cmdline_fixed_string_t name;
1125         cmdline_fixed_string_t value;
1126 };
1127
1128 static void cmd_operate_port_parsed(void *parsed_result,
1129                                 __attribute__((unused)) struct cmdline *cl,
1130                                 __attribute__((unused)) void *data)
1131 {
1132         struct cmd_operate_port_result *res = parsed_result;
1133
1134         if (!strcmp(res->name, "start"))
1135                 start_port(RTE_PORT_ALL);
1136         else if (!strcmp(res->name, "stop"))
1137                 stop_port(RTE_PORT_ALL);
1138         else if (!strcmp(res->name, "close"))
1139                 close_port(RTE_PORT_ALL);
1140         else if (!strcmp(res->name, "reset"))
1141                 reset_port(RTE_PORT_ALL);
1142         else
1143                 printf("Unknown parameter\n");
1144 }
1145
1146 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1147         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1148                                                                 "port");
1149 cmdline_parse_token_string_t cmd_operate_port_all_port =
1150         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1151                                                 "start#stop#close#reset");
1152 cmdline_parse_token_string_t cmd_operate_port_all_all =
1153         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1154
1155 cmdline_parse_inst_t cmd_operate_port = {
1156         .f = cmd_operate_port_parsed,
1157         .data = NULL,
1158         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1159         .tokens = {
1160                 (void *)&cmd_operate_port_all_cmd,
1161                 (void *)&cmd_operate_port_all_port,
1162                 (void *)&cmd_operate_port_all_all,
1163                 NULL,
1164         },
1165 };
1166
1167 /* *** start/stop/close specific port *** */
1168 struct cmd_operate_specific_port_result {
1169         cmdline_fixed_string_t keyword;
1170         cmdline_fixed_string_t name;
1171         uint8_t value;
1172 };
1173
1174 static void cmd_operate_specific_port_parsed(void *parsed_result,
1175                         __attribute__((unused)) struct cmdline *cl,
1176                                 __attribute__((unused)) void *data)
1177 {
1178         struct cmd_operate_specific_port_result *res = parsed_result;
1179
1180         if (!strcmp(res->name, "start"))
1181                 start_port(res->value);
1182         else if (!strcmp(res->name, "stop"))
1183                 stop_port(res->value);
1184         else if (!strcmp(res->name, "close"))
1185                 close_port(res->value);
1186         else if (!strcmp(res->name, "reset"))
1187                 reset_port(res->value);
1188         else
1189                 printf("Unknown parameter\n");
1190 }
1191
1192 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1193         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1194                                                         keyword, "port");
1195 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1196         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1197                                                 name, "start#stop#close#reset");
1198 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1199         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1200                                                         value, UINT8);
1201
1202 cmdline_parse_inst_t cmd_operate_specific_port = {
1203         .f = cmd_operate_specific_port_parsed,
1204         .data = NULL,
1205         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1206         .tokens = {
1207                 (void *)&cmd_operate_specific_port_cmd,
1208                 (void *)&cmd_operate_specific_port_port,
1209                 (void *)&cmd_operate_specific_port_id,
1210                 NULL,
1211         },
1212 };
1213
1214 /* *** attach a specified port *** */
1215 struct cmd_operate_attach_port_result {
1216         cmdline_fixed_string_t port;
1217         cmdline_fixed_string_t keyword;
1218         cmdline_fixed_string_t identifier;
1219 };
1220
1221 static void cmd_operate_attach_port_parsed(void *parsed_result,
1222                                 __attribute__((unused)) struct cmdline *cl,
1223                                 __attribute__((unused)) void *data)
1224 {
1225         struct cmd_operate_attach_port_result *res = parsed_result;
1226
1227         if (!strcmp(res->keyword, "attach"))
1228                 attach_port(res->identifier);
1229         else
1230                 printf("Unknown parameter\n");
1231 }
1232
1233 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1234         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1235                         port, "port");
1236 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1237         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1238                         keyword, "attach");
1239 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1240         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1241                         identifier, NULL);
1242
1243 cmdline_parse_inst_t cmd_operate_attach_port = {
1244         .f = cmd_operate_attach_port_parsed,
1245         .data = NULL,
1246         .help_str = "port attach <identifier>: "
1247                 "(identifier: pci address or virtual dev name)",
1248         .tokens = {
1249                 (void *)&cmd_operate_attach_port_port,
1250                 (void *)&cmd_operate_attach_port_keyword,
1251                 (void *)&cmd_operate_attach_port_identifier,
1252                 NULL,
1253         },
1254 };
1255
1256 /* *** detach a specified port *** */
1257 struct cmd_operate_detach_port_result {
1258         cmdline_fixed_string_t port;
1259         cmdline_fixed_string_t keyword;
1260         portid_t port_id;
1261 };
1262
1263 static void cmd_operate_detach_port_parsed(void *parsed_result,
1264                                 __attribute__((unused)) struct cmdline *cl,
1265                                 __attribute__((unused)) void *data)
1266 {
1267         struct cmd_operate_detach_port_result *res = parsed_result;
1268
1269         if (!strcmp(res->keyword, "detach"))
1270                 detach_port(res->port_id);
1271         else
1272                 printf("Unknown parameter\n");
1273 }
1274
1275 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1276         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1277                         port, "port");
1278 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1279         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1280                         keyword, "detach");
1281 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1282         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1283                         port_id, UINT16);
1284
1285 cmdline_parse_inst_t cmd_operate_detach_port = {
1286         .f = cmd_operate_detach_port_parsed,
1287         .data = NULL,
1288         .help_str = "port detach <port_id>",
1289         .tokens = {
1290                 (void *)&cmd_operate_detach_port_port,
1291                 (void *)&cmd_operate_detach_port_keyword,
1292                 (void *)&cmd_operate_detach_port_port_id,
1293                 NULL,
1294         },
1295 };
1296
1297 /* *** configure speed for all ports *** */
1298 struct cmd_config_speed_all {
1299         cmdline_fixed_string_t port;
1300         cmdline_fixed_string_t keyword;
1301         cmdline_fixed_string_t all;
1302         cmdline_fixed_string_t item1;
1303         cmdline_fixed_string_t item2;
1304         cmdline_fixed_string_t value1;
1305         cmdline_fixed_string_t value2;
1306 };
1307
1308 static int
1309 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1310 {
1311
1312         int duplex;
1313
1314         if (!strcmp(duplexstr, "half")) {
1315                 duplex = ETH_LINK_HALF_DUPLEX;
1316         } else if (!strcmp(duplexstr, "full")) {
1317                 duplex = ETH_LINK_FULL_DUPLEX;
1318         } else if (!strcmp(duplexstr, "auto")) {
1319                 duplex = ETH_LINK_FULL_DUPLEX;
1320         } else {
1321                 printf("Unknown duplex parameter\n");
1322                 return -1;
1323         }
1324
1325         if (!strcmp(speedstr, "10")) {
1326                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1327                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1328         } else if (!strcmp(speedstr, "100")) {
1329                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1330                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1331         } else {
1332                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1333                         printf("Invalid speed/duplex parameters\n");
1334                         return -1;
1335                 }
1336                 if (!strcmp(speedstr, "1000")) {
1337                         *speed = ETH_LINK_SPEED_1G;
1338                 } else if (!strcmp(speedstr, "10000")) {
1339                         *speed = ETH_LINK_SPEED_10G;
1340                 } else if (!strcmp(speedstr, "25000")) {
1341                         *speed = ETH_LINK_SPEED_25G;
1342                 } else if (!strcmp(speedstr, "40000")) {
1343                         *speed = ETH_LINK_SPEED_40G;
1344                 } else if (!strcmp(speedstr, "50000")) {
1345                         *speed = ETH_LINK_SPEED_50G;
1346                 } else if (!strcmp(speedstr, "100000")) {
1347                         *speed = ETH_LINK_SPEED_100G;
1348                 } else if (!strcmp(speedstr, "auto")) {
1349                         *speed = ETH_LINK_SPEED_AUTONEG;
1350                 } else {
1351                         printf("Unknown speed parameter\n");
1352                         return -1;
1353                 }
1354         }
1355
1356         return 0;
1357 }
1358
1359 static void
1360 cmd_config_speed_all_parsed(void *parsed_result,
1361                         __attribute__((unused)) struct cmdline *cl,
1362                         __attribute__((unused)) void *data)
1363 {
1364         struct cmd_config_speed_all *res = parsed_result;
1365         uint32_t link_speed;
1366         portid_t pid;
1367
1368         if (!all_ports_stopped()) {
1369                 printf("Please stop all ports first\n");
1370                 return;
1371         }
1372
1373         if (parse_and_check_speed_duplex(res->value1, res->value2,
1374                         &link_speed) < 0)
1375                 return;
1376
1377         RTE_ETH_FOREACH_DEV(pid) {
1378                 ports[pid].dev_conf.link_speeds = link_speed;
1379         }
1380
1381         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1382 }
1383
1384 cmdline_parse_token_string_t cmd_config_speed_all_port =
1385         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1386 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1387         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1388                                                         "config");
1389 cmdline_parse_token_string_t cmd_config_speed_all_all =
1390         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1391 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1392         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1393 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1394         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1395                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1396 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1397         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1398 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1399         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1400                                                 "half#full#auto");
1401
1402 cmdline_parse_inst_t cmd_config_speed_all = {
1403         .f = cmd_config_speed_all_parsed,
1404         .data = NULL,
1405         .help_str = "port config all speed "
1406                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1407                                                         "half|full|auto",
1408         .tokens = {
1409                 (void *)&cmd_config_speed_all_port,
1410                 (void *)&cmd_config_speed_all_keyword,
1411                 (void *)&cmd_config_speed_all_all,
1412                 (void *)&cmd_config_speed_all_item1,
1413                 (void *)&cmd_config_speed_all_value1,
1414                 (void *)&cmd_config_speed_all_item2,
1415                 (void *)&cmd_config_speed_all_value2,
1416                 NULL,
1417         },
1418 };
1419
1420 /* *** configure speed for specific port *** */
1421 struct cmd_config_speed_specific {
1422         cmdline_fixed_string_t port;
1423         cmdline_fixed_string_t keyword;
1424         uint8_t id;
1425         cmdline_fixed_string_t item1;
1426         cmdline_fixed_string_t item2;
1427         cmdline_fixed_string_t value1;
1428         cmdline_fixed_string_t value2;
1429 };
1430
1431 static void
1432 cmd_config_speed_specific_parsed(void *parsed_result,
1433                                 __attribute__((unused)) struct cmdline *cl,
1434                                 __attribute__((unused)) void *data)
1435 {
1436         struct cmd_config_speed_specific *res = parsed_result;
1437         uint32_t link_speed;
1438
1439         if (!all_ports_stopped()) {
1440                 printf("Please stop all ports first\n");
1441                 return;
1442         }
1443
1444         if (port_id_is_invalid(res->id, ENABLED_WARN))
1445                 return;
1446
1447         if (parse_and_check_speed_duplex(res->value1, res->value2,
1448                         &link_speed) < 0)
1449                 return;
1450
1451         ports[res->id].dev_conf.link_speeds = link_speed;
1452
1453         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1454 }
1455
1456
1457 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1459                                                                 "port");
1460 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1461         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1462                                                                 "config");
1463 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1464         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1465 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1466         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1467                                                                 "speed");
1468 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1469         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1470                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1471 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1472         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1473                                                                 "duplex");
1474 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1475         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1476                                                         "half#full#auto");
1477
1478 cmdline_parse_inst_t cmd_config_speed_specific = {
1479         .f = cmd_config_speed_specific_parsed,
1480         .data = NULL,
1481         .help_str = "port config <port_id> speed "
1482                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1483                                                         "half|full|auto",
1484         .tokens = {
1485                 (void *)&cmd_config_speed_specific_port,
1486                 (void *)&cmd_config_speed_specific_keyword,
1487                 (void *)&cmd_config_speed_specific_id,
1488                 (void *)&cmd_config_speed_specific_item1,
1489                 (void *)&cmd_config_speed_specific_value1,
1490                 (void *)&cmd_config_speed_specific_item2,
1491                 (void *)&cmd_config_speed_specific_value2,
1492                 NULL,
1493         },
1494 };
1495
1496 /* *** configure txq/rxq, txd/rxd *** */
1497 struct cmd_config_rx_tx {
1498         cmdline_fixed_string_t port;
1499         cmdline_fixed_string_t keyword;
1500         cmdline_fixed_string_t all;
1501         cmdline_fixed_string_t name;
1502         uint16_t value;
1503 };
1504
1505 static void
1506 cmd_config_rx_tx_parsed(void *parsed_result,
1507                         __attribute__((unused)) struct cmdline *cl,
1508                         __attribute__((unused)) void *data)
1509 {
1510         struct cmd_config_rx_tx *res = parsed_result;
1511
1512         if (!all_ports_stopped()) {
1513                 printf("Please stop all ports first\n");
1514                 return;
1515         }
1516         if (!strcmp(res->name, "rxq")) {
1517                 if (!res->value && !nb_txq) {
1518                         printf("Warning: Either rx or tx queues should be non zero\n");
1519                         return;
1520                 }
1521                 nb_rxq = res->value;
1522         }
1523         else if (!strcmp(res->name, "txq")) {
1524                 if (!res->value && !nb_rxq) {
1525                         printf("Warning: Either rx or tx queues should be non zero\n");
1526                         return;
1527                 }
1528                 nb_txq = res->value;
1529         }
1530         else if (!strcmp(res->name, "rxd")) {
1531                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1532                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1533                                         res->value, RTE_TEST_RX_DESC_MAX);
1534                         return;
1535                 }
1536                 nb_rxd = res->value;
1537         } else if (!strcmp(res->name, "txd")) {
1538                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1539                         printf("txd %d invalid - must be > 0 && <= %d\n",
1540                                         res->value, RTE_TEST_TX_DESC_MAX);
1541                         return;
1542                 }
1543                 nb_txd = res->value;
1544         } else {
1545                 printf("Unknown parameter\n");
1546                 return;
1547         }
1548
1549         fwd_config_setup();
1550
1551         init_port_config();
1552
1553         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1554 }
1555
1556 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1557         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1558 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1559         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1560 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1561         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1562 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1563         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1564                                                 "rxq#txq#rxd#txd");
1565 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1566         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1567
1568 cmdline_parse_inst_t cmd_config_rx_tx = {
1569         .f = cmd_config_rx_tx_parsed,
1570         .data = NULL,
1571         .help_str = "port config all rxq|txq|rxd|txd <value>",
1572         .tokens = {
1573                 (void *)&cmd_config_rx_tx_port,
1574                 (void *)&cmd_config_rx_tx_keyword,
1575                 (void *)&cmd_config_rx_tx_all,
1576                 (void *)&cmd_config_rx_tx_name,
1577                 (void *)&cmd_config_rx_tx_value,
1578                 NULL,
1579         },
1580 };
1581
1582 /* *** config max packet length *** */
1583 struct cmd_config_max_pkt_len_result {
1584         cmdline_fixed_string_t port;
1585         cmdline_fixed_string_t keyword;
1586         cmdline_fixed_string_t all;
1587         cmdline_fixed_string_t name;
1588         uint32_t value;
1589 };
1590
1591 static void
1592 cmd_config_max_pkt_len_parsed(void *parsed_result,
1593                                 __attribute__((unused)) struct cmdline *cl,
1594                                 __attribute__((unused)) void *data)
1595 {
1596         struct cmd_config_max_pkt_len_result *res = parsed_result;
1597
1598         if (!all_ports_stopped()) {
1599                 printf("Please stop all ports first\n");
1600                 return;
1601         }
1602
1603         if (!strcmp(res->name, "max-pkt-len")) {
1604                 if (res->value < ETHER_MIN_LEN) {
1605                         printf("max-pkt-len can not be less than %d\n",
1606                                                         ETHER_MIN_LEN);
1607                         return;
1608                 }
1609                 if (res->value == rx_mode.max_rx_pkt_len)
1610                         return;
1611
1612                 rx_mode.max_rx_pkt_len = res->value;
1613                 if (res->value > ETHER_MAX_LEN)
1614                         rx_mode.jumbo_frame = 1;
1615                 else
1616                         rx_mode.jumbo_frame = 0;
1617         } else {
1618                 printf("Unknown parameter\n");
1619                 return;
1620         }
1621
1622         init_port_config();
1623
1624         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1625 }
1626
1627 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1628         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1629                                                                 "port");
1630 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1631         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1632                                                                 "config");
1633 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1634         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1635                                                                 "all");
1636 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1637         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1638                                                                 "max-pkt-len");
1639 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1640         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1641                                                                 UINT32);
1642
1643 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1644         .f = cmd_config_max_pkt_len_parsed,
1645         .data = NULL,
1646         .help_str = "port config all max-pkt-len <value>",
1647         .tokens = {
1648                 (void *)&cmd_config_max_pkt_len_port,
1649                 (void *)&cmd_config_max_pkt_len_keyword,
1650                 (void *)&cmd_config_max_pkt_len_all,
1651                 (void *)&cmd_config_max_pkt_len_name,
1652                 (void *)&cmd_config_max_pkt_len_value,
1653                 NULL,
1654         },
1655 };
1656
1657 /* *** configure port MTU *** */
1658 struct cmd_config_mtu_result {
1659         cmdline_fixed_string_t port;
1660         cmdline_fixed_string_t keyword;
1661         cmdline_fixed_string_t mtu;
1662         portid_t port_id;
1663         uint16_t value;
1664 };
1665
1666 static void
1667 cmd_config_mtu_parsed(void *parsed_result,
1668                       __attribute__((unused)) struct cmdline *cl,
1669                       __attribute__((unused)) void *data)
1670 {
1671         struct cmd_config_mtu_result *res = parsed_result;
1672
1673         if (res->value < ETHER_MIN_LEN) {
1674                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1675                 return;
1676         }
1677         port_mtu_set(res->port_id, res->value);
1678 }
1679
1680 cmdline_parse_token_string_t cmd_config_mtu_port =
1681         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1682                                  "port");
1683 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1684         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1685                                  "config");
1686 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1687         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1688                                  "mtu");
1689 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1690         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1691 cmdline_parse_token_num_t cmd_config_mtu_value =
1692         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1693
1694 cmdline_parse_inst_t cmd_config_mtu = {
1695         .f = cmd_config_mtu_parsed,
1696         .data = NULL,
1697         .help_str = "port config mtu <port_id> <value>",
1698         .tokens = {
1699                 (void *)&cmd_config_mtu_port,
1700                 (void *)&cmd_config_mtu_keyword,
1701                 (void *)&cmd_config_mtu_mtu,
1702                 (void *)&cmd_config_mtu_port_id,
1703                 (void *)&cmd_config_mtu_value,
1704                 NULL,
1705         },
1706 };
1707
1708 /* *** configure rx mode *** */
1709 struct cmd_config_rx_mode_flag {
1710         cmdline_fixed_string_t port;
1711         cmdline_fixed_string_t keyword;
1712         cmdline_fixed_string_t all;
1713         cmdline_fixed_string_t name;
1714         cmdline_fixed_string_t value;
1715 };
1716
1717 static void
1718 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1719                                 __attribute__((unused)) struct cmdline *cl,
1720                                 __attribute__((unused)) void *data)
1721 {
1722         struct cmd_config_rx_mode_flag *res = parsed_result;
1723
1724         if (!all_ports_stopped()) {
1725                 printf("Please stop all ports first\n");
1726                 return;
1727         }
1728
1729         if (!strcmp(res->name, "crc-strip")) {
1730                 if (!strcmp(res->value, "on"))
1731                         rx_mode.hw_strip_crc = 1;
1732                 else if (!strcmp(res->value, "off"))
1733                         rx_mode.hw_strip_crc = 0;
1734                 else {
1735                         printf("Unknown parameter\n");
1736                         return;
1737                 }
1738         } else if (!strcmp(res->name, "scatter")) {
1739                 if (!strcmp(res->value, "on"))
1740                         rx_mode.enable_scatter = 1;
1741                 else if (!strcmp(res->value, "off"))
1742                         rx_mode.enable_scatter = 0;
1743                 else {
1744                         printf("Unknown parameter\n");
1745                         return;
1746                 }
1747         } else if (!strcmp(res->name, "rx-cksum")) {
1748                 if (!strcmp(res->value, "on"))
1749                         rx_mode.hw_ip_checksum = 1;
1750                 else if (!strcmp(res->value, "off"))
1751                         rx_mode.hw_ip_checksum = 0;
1752                 else {
1753                         printf("Unknown parameter\n");
1754                         return;
1755                 }
1756         } else if (!strcmp(res->name, "rx-timestamp")) {
1757                 if (!strcmp(res->value, "on"))
1758                         rx_mode.hw_timestamp = 1;
1759                 else if (!strcmp(res->value, "off"))
1760                         rx_mode.hw_timestamp = 0;
1761                 else {
1762                         printf("Unknown parameter\n");
1763                         return;
1764                 }
1765         } else if (!strcmp(res->name, "hw-vlan")) {
1766                 if (!strcmp(res->value, "on")) {
1767                         rx_mode.hw_vlan_filter = 1;
1768                         rx_mode.hw_vlan_strip  = 1;
1769                 }
1770                 else if (!strcmp(res->value, "off")) {
1771                         rx_mode.hw_vlan_filter = 0;
1772                         rx_mode.hw_vlan_strip  = 0;
1773                 }
1774                 else {
1775                         printf("Unknown parameter\n");
1776                         return;
1777                 }
1778         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1779                 if (!strcmp(res->value, "on"))
1780                         rx_mode.hw_vlan_filter = 1;
1781                 else if (!strcmp(res->value, "off"))
1782                         rx_mode.hw_vlan_filter = 0;
1783                 else {
1784                         printf("Unknown parameter\n");
1785                         return;
1786                 }
1787         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1788                 if (!strcmp(res->value, "on"))
1789                         rx_mode.hw_vlan_strip  = 1;
1790                 else if (!strcmp(res->value, "off"))
1791                         rx_mode.hw_vlan_strip  = 0;
1792                 else {
1793                         printf("Unknown parameter\n");
1794                         return;
1795                 }
1796         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1797                 if (!strcmp(res->value, "on"))
1798                         rx_mode.hw_vlan_extend = 1;
1799                 else if (!strcmp(res->value, "off"))
1800                         rx_mode.hw_vlan_extend = 0;
1801                 else {
1802                         printf("Unknown parameter\n");
1803                         return;
1804                 }
1805         } else if (!strcmp(res->name, "drop-en")) {
1806                 if (!strcmp(res->value, "on"))
1807                         rx_drop_en = 1;
1808                 else if (!strcmp(res->value, "off"))
1809                         rx_drop_en = 0;
1810                 else {
1811                         printf("Unknown parameter\n");
1812                         return;
1813                 }
1814         } else {
1815                 printf("Unknown parameter\n");
1816                 return;
1817         }
1818
1819         init_port_config();
1820
1821         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1822 }
1823
1824 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1825         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1826 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1827         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1828                                                                 "config");
1829 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1830         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1831 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1832         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1833                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1834                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1835 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1836         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1837                                                         "on#off");
1838
1839 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1840         .f = cmd_config_rx_mode_flag_parsed,
1841         .data = NULL,
1842         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1843                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1844         .tokens = {
1845                 (void *)&cmd_config_rx_mode_flag_port,
1846                 (void *)&cmd_config_rx_mode_flag_keyword,
1847                 (void *)&cmd_config_rx_mode_flag_all,
1848                 (void *)&cmd_config_rx_mode_flag_name,
1849                 (void *)&cmd_config_rx_mode_flag_value,
1850                 NULL,
1851         },
1852 };
1853
1854 /* *** configure rss *** */
1855 struct cmd_config_rss {
1856         cmdline_fixed_string_t port;
1857         cmdline_fixed_string_t keyword;
1858         cmdline_fixed_string_t all;
1859         cmdline_fixed_string_t name;
1860         cmdline_fixed_string_t value;
1861 };
1862
1863 static void
1864 cmd_config_rss_parsed(void *parsed_result,
1865                         __attribute__((unused)) struct cmdline *cl,
1866                         __attribute__((unused)) void *data)
1867 {
1868         struct cmd_config_rss *res = parsed_result;
1869         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1870         int diag;
1871         uint8_t i;
1872
1873         if (!strcmp(res->value, "all"))
1874                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1875                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1876                                         ETH_RSS_L2_PAYLOAD;
1877         else if (!strcmp(res->value, "ip"))
1878                 rss_conf.rss_hf = ETH_RSS_IP;
1879         else if (!strcmp(res->value, "udp"))
1880                 rss_conf.rss_hf = ETH_RSS_UDP;
1881         else if (!strcmp(res->value, "tcp"))
1882                 rss_conf.rss_hf = ETH_RSS_TCP;
1883         else if (!strcmp(res->value, "sctp"))
1884                 rss_conf.rss_hf = ETH_RSS_SCTP;
1885         else if (!strcmp(res->value, "ether"))
1886                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1887         else if (!strcmp(res->value, "port"))
1888                 rss_conf.rss_hf = ETH_RSS_PORT;
1889         else if (!strcmp(res->value, "vxlan"))
1890                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1891         else if (!strcmp(res->value, "geneve"))
1892                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1893         else if (!strcmp(res->value, "nvgre"))
1894                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1895         else if (!strcmp(res->value, "none"))
1896                 rss_conf.rss_hf = 0;
1897         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1898                                                 atoi(res->value) < 64)
1899                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1900         else {
1901                 printf("Unknown parameter\n");
1902                 return;
1903         }
1904         rss_conf.rss_key = NULL;
1905         for (i = 0; i < rte_eth_dev_count(); i++) {
1906                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1907                 if (diag < 0)
1908                         printf("Configuration of RSS hash at ethernet port %d "
1909                                 "failed with error (%d): %s.\n",
1910                                 i, -diag, strerror(-diag));
1911         }
1912 }
1913
1914 cmdline_parse_token_string_t cmd_config_rss_port =
1915         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1916 cmdline_parse_token_string_t cmd_config_rss_keyword =
1917         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1918 cmdline_parse_token_string_t cmd_config_rss_all =
1919         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1920 cmdline_parse_token_string_t cmd_config_rss_name =
1921         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1922 cmdline_parse_token_string_t cmd_config_rss_value =
1923         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1924
1925 cmdline_parse_inst_t cmd_config_rss = {
1926         .f = cmd_config_rss_parsed,
1927         .data = NULL,
1928         .help_str = "port config all rss "
1929                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1930         .tokens = {
1931                 (void *)&cmd_config_rss_port,
1932                 (void *)&cmd_config_rss_keyword,
1933                 (void *)&cmd_config_rss_all,
1934                 (void *)&cmd_config_rss_name,
1935                 (void *)&cmd_config_rss_value,
1936                 NULL,
1937         },
1938 };
1939
1940 /* *** configure rss hash key *** */
1941 struct cmd_config_rss_hash_key {
1942         cmdline_fixed_string_t port;
1943         cmdline_fixed_string_t config;
1944         portid_t port_id;
1945         cmdline_fixed_string_t rss_hash_key;
1946         cmdline_fixed_string_t rss_type;
1947         cmdline_fixed_string_t key;
1948 };
1949
1950 static uint8_t
1951 hexa_digit_to_value(char hexa_digit)
1952 {
1953         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1954                 return (uint8_t) (hexa_digit - '0');
1955         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1956                 return (uint8_t) ((hexa_digit - 'a') + 10);
1957         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1958                 return (uint8_t) ((hexa_digit - 'A') + 10);
1959         /* Invalid hexa digit */
1960         return 0xFF;
1961 }
1962
1963 static uint8_t
1964 parse_and_check_key_hexa_digit(char *key, int idx)
1965 {
1966         uint8_t hexa_v;
1967
1968         hexa_v = hexa_digit_to_value(key[idx]);
1969         if (hexa_v == 0xFF)
1970                 printf("invalid key: character %c at position %d is not a "
1971                        "valid hexa digit\n", key[idx], idx);
1972         return hexa_v;
1973 }
1974
1975 static void
1976 cmd_config_rss_hash_key_parsed(void *parsed_result,
1977                                __attribute__((unused)) struct cmdline *cl,
1978                                __attribute__((unused)) void *data)
1979 {
1980         struct cmd_config_rss_hash_key *res = parsed_result;
1981         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1982         uint8_t xdgt0;
1983         uint8_t xdgt1;
1984         int i;
1985         struct rte_eth_dev_info dev_info;
1986         uint8_t hash_key_size;
1987         uint32_t key_len;
1988
1989         memset(&dev_info, 0, sizeof(dev_info));
1990         rte_eth_dev_info_get(res->port_id, &dev_info);
1991         if (dev_info.hash_key_size > 0 &&
1992                         dev_info.hash_key_size <= sizeof(hash_key))
1993                 hash_key_size = dev_info.hash_key_size;
1994         else {
1995                 printf("dev_info did not provide a valid hash key size\n");
1996                 return;
1997         }
1998         /* Check the length of the RSS hash key */
1999         key_len = strlen(res->key);
2000         if (key_len != (hash_key_size * 2)) {
2001                 printf("key length: %d invalid - key must be a string of %d"
2002                            " hexa-decimal numbers\n",
2003                            (int) key_len, hash_key_size * 2);
2004                 return;
2005         }
2006         /* Translate RSS hash key into binary representation */
2007         for (i = 0; i < hash_key_size; i++) {
2008                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
2009                 if (xdgt0 == 0xFF)
2010                         return;
2011                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
2012                 if (xdgt1 == 0xFF)
2013                         return;
2014                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2015         }
2016         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2017                         hash_key_size);
2018 }
2019
2020 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2021         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2022 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2023         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2024                                  "config");
2025 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2026         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2027 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2028         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2029                                  rss_hash_key, "rss-hash-key");
2030 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2031         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2032                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2033                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2034                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2035                                  "ipv6-tcp-ex#ipv6-udp-ex");
2036 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2037         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2038
2039 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2040         .f = cmd_config_rss_hash_key_parsed,
2041         .data = NULL,
2042         .help_str = "port config <port_id> rss-hash-key "
2043                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2044                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2045                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2046                 "<string of hex digits (variable length, NIC dependent)>",
2047         .tokens = {
2048                 (void *)&cmd_config_rss_hash_key_port,
2049                 (void *)&cmd_config_rss_hash_key_config,
2050                 (void *)&cmd_config_rss_hash_key_port_id,
2051                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2052                 (void *)&cmd_config_rss_hash_key_rss_type,
2053                 (void *)&cmd_config_rss_hash_key_value,
2054                 NULL,
2055         },
2056 };
2057
2058 /* *** configure port rxq/txq start/stop *** */
2059 struct cmd_config_rxtx_queue {
2060         cmdline_fixed_string_t port;
2061         portid_t portid;
2062         cmdline_fixed_string_t rxtxq;
2063         uint16_t qid;
2064         cmdline_fixed_string_t opname;
2065 };
2066
2067 static void
2068 cmd_config_rxtx_queue_parsed(void *parsed_result,
2069                         __attribute__((unused)) struct cmdline *cl,
2070                         __attribute__((unused)) void *data)
2071 {
2072         struct cmd_config_rxtx_queue *res = parsed_result;
2073         uint8_t isrx;
2074         uint8_t isstart;
2075         int ret = 0;
2076
2077         if (test_done == 0) {
2078                 printf("Please stop forwarding first\n");
2079                 return;
2080         }
2081
2082         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2083                 return;
2084
2085         if (port_is_started(res->portid) != 1) {
2086                 printf("Please start port %u first\n", res->portid);
2087                 return;
2088         }
2089
2090         if (!strcmp(res->rxtxq, "rxq"))
2091                 isrx = 1;
2092         else if (!strcmp(res->rxtxq, "txq"))
2093                 isrx = 0;
2094         else {
2095                 printf("Unknown parameter\n");
2096                 return;
2097         }
2098
2099         if (isrx && rx_queue_id_is_invalid(res->qid))
2100                 return;
2101         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2102                 return;
2103
2104         if (!strcmp(res->opname, "start"))
2105                 isstart = 1;
2106         else if (!strcmp(res->opname, "stop"))
2107                 isstart = 0;
2108         else {
2109                 printf("Unknown parameter\n");
2110                 return;
2111         }
2112
2113         if (isstart && isrx)
2114                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2115         else if (!isstart && isrx)
2116                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2117         else if (isstart && !isrx)
2118                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2119         else
2120                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2121
2122         if (ret == -ENOTSUP)
2123                 printf("Function not supported in PMD driver\n");
2124 }
2125
2126 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2127         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2128 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2129         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2130 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2131         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2132 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2133         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2134 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2135         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2136                                                 "start#stop");
2137
2138 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2139         .f = cmd_config_rxtx_queue_parsed,
2140         .data = NULL,
2141         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2142         .tokens = {
2143                 (void *)&cmd_config_speed_all_port,
2144                 (void *)&cmd_config_rxtx_queue_portid,
2145                 (void *)&cmd_config_rxtx_queue_rxtxq,
2146                 (void *)&cmd_config_rxtx_queue_qid,
2147                 (void *)&cmd_config_rxtx_queue_opname,
2148                 NULL,
2149         },
2150 };
2151
2152 /* *** Configure RSS RETA *** */
2153 struct cmd_config_rss_reta {
2154         cmdline_fixed_string_t port;
2155         cmdline_fixed_string_t keyword;
2156         portid_t port_id;
2157         cmdline_fixed_string_t name;
2158         cmdline_fixed_string_t list_name;
2159         cmdline_fixed_string_t list_of_items;
2160 };
2161
2162 static int
2163 parse_reta_config(const char *str,
2164                   struct rte_eth_rss_reta_entry64 *reta_conf,
2165                   uint16_t nb_entries)
2166 {
2167         int i;
2168         unsigned size;
2169         uint16_t hash_index, idx, shift;
2170         uint16_t nb_queue;
2171         char s[256];
2172         const char *p, *p0 = str;
2173         char *end;
2174         enum fieldnames {
2175                 FLD_HASH_INDEX = 0,
2176                 FLD_QUEUE,
2177                 _NUM_FLD
2178         };
2179         unsigned long int_fld[_NUM_FLD];
2180         char *str_fld[_NUM_FLD];
2181
2182         while ((p = strchr(p0,'(')) != NULL) {
2183                 ++p;
2184                 if((p0 = strchr(p,')')) == NULL)
2185                         return -1;
2186
2187                 size = p0 - p;
2188                 if(size >= sizeof(s))
2189                         return -1;
2190
2191                 snprintf(s, sizeof(s), "%.*s", size, p);
2192                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2193                         return -1;
2194                 for (i = 0; i < _NUM_FLD; i++) {
2195                         errno = 0;
2196                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2197                         if (errno != 0 || end == str_fld[i] ||
2198                                         int_fld[i] > 65535)
2199                                 return -1;
2200                 }
2201
2202                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2203                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2204
2205                 if (hash_index >= nb_entries) {
2206                         printf("Invalid RETA hash index=%d\n", hash_index);
2207                         return -1;
2208                 }
2209
2210                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2211                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2212                 reta_conf[idx].mask |= (1ULL << shift);
2213                 reta_conf[idx].reta[shift] = nb_queue;
2214         }
2215
2216         return 0;
2217 }
2218
2219 static void
2220 cmd_set_rss_reta_parsed(void *parsed_result,
2221                         __attribute__((unused)) struct cmdline *cl,
2222                         __attribute__((unused)) void *data)
2223 {
2224         int ret;
2225         struct rte_eth_dev_info dev_info;
2226         struct rte_eth_rss_reta_entry64 reta_conf[8];
2227         struct cmd_config_rss_reta *res = parsed_result;
2228
2229         memset(&dev_info, 0, sizeof(dev_info));
2230         rte_eth_dev_info_get(res->port_id, &dev_info);
2231         if (dev_info.reta_size == 0) {
2232                 printf("Redirection table size is 0 which is "
2233                                         "invalid for RSS\n");
2234                 return;
2235         } else
2236                 printf("The reta size of port %d is %u\n",
2237                         res->port_id, dev_info.reta_size);
2238         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2239                 printf("Currently do not support more than %u entries of "
2240                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2241                 return;
2242         }
2243
2244         memset(reta_conf, 0, sizeof(reta_conf));
2245         if (!strcmp(res->list_name, "reta")) {
2246                 if (parse_reta_config(res->list_of_items, reta_conf,
2247                                                 dev_info.reta_size)) {
2248                         printf("Invalid RSS Redirection Table "
2249                                         "config entered\n");
2250                         return;
2251                 }
2252                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2253                                 reta_conf, dev_info.reta_size);
2254                 if (ret != 0)
2255                         printf("Bad redirection table parameter, "
2256                                         "return code = %d \n", ret);
2257         }
2258 }
2259
2260 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2261         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2262 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2263         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2264 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2265         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2266 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2267         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2268 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2269         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2270 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2271         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2272                                  NULL);
2273 cmdline_parse_inst_t cmd_config_rss_reta = {
2274         .f = cmd_set_rss_reta_parsed,
2275         .data = NULL,
2276         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2277         .tokens = {
2278                 (void *)&cmd_config_rss_reta_port,
2279                 (void *)&cmd_config_rss_reta_keyword,
2280                 (void *)&cmd_config_rss_reta_port_id,
2281                 (void *)&cmd_config_rss_reta_name,
2282                 (void *)&cmd_config_rss_reta_list_name,
2283                 (void *)&cmd_config_rss_reta_list_of_items,
2284                 NULL,
2285         },
2286 };
2287
2288 /* *** SHOW PORT RETA INFO *** */
2289 struct cmd_showport_reta {
2290         cmdline_fixed_string_t show;
2291         cmdline_fixed_string_t port;
2292         portid_t port_id;
2293         cmdline_fixed_string_t rss;
2294         cmdline_fixed_string_t reta;
2295         uint16_t size;
2296         cmdline_fixed_string_t list_of_items;
2297 };
2298
2299 static int
2300 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2301                            uint16_t nb_entries,
2302                            char *str)
2303 {
2304         uint32_t size;
2305         const char *p, *p0 = str;
2306         char s[256];
2307         char *end;
2308         char *str_fld[8];
2309         uint16_t i;
2310         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2311                         RTE_RETA_GROUP_SIZE;
2312         int ret;
2313
2314         p = strchr(p0, '(');
2315         if (p == NULL)
2316                 return -1;
2317         p++;
2318         p0 = strchr(p, ')');
2319         if (p0 == NULL)
2320                 return -1;
2321         size = p0 - p;
2322         if (size >= sizeof(s)) {
2323                 printf("The string size exceeds the internal buffer size\n");
2324                 return -1;
2325         }
2326         snprintf(s, sizeof(s), "%.*s", size, p);
2327         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2328         if (ret <= 0 || ret != num) {
2329                 printf("The bits of masks do not match the number of "
2330                                         "reta entries: %u\n", num);
2331                 return -1;
2332         }
2333         for (i = 0; i < ret; i++)
2334                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2335
2336         return 0;
2337 }
2338
2339 static void
2340 cmd_showport_reta_parsed(void *parsed_result,
2341                          __attribute__((unused)) struct cmdline *cl,
2342                          __attribute__((unused)) void *data)
2343 {
2344         struct cmd_showport_reta *res = parsed_result;
2345         struct rte_eth_rss_reta_entry64 reta_conf[8];
2346         struct rte_eth_dev_info dev_info;
2347         uint16_t max_reta_size;
2348
2349         memset(&dev_info, 0, sizeof(dev_info));
2350         rte_eth_dev_info_get(res->port_id, &dev_info);
2351         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2352         if (res->size == 0 || res->size > max_reta_size) {
2353                 printf("Invalid redirection table size: %u (1-%u)\n",
2354                         res->size, max_reta_size);
2355                 return;
2356         }
2357
2358         memset(reta_conf, 0, sizeof(reta_conf));
2359         if (showport_parse_reta_config(reta_conf, res->size,
2360                                 res->list_of_items) < 0) {
2361                 printf("Invalid string: %s for reta masks\n",
2362                                         res->list_of_items);
2363                 return;
2364         }
2365         port_rss_reta_info(res->port_id, reta_conf, res->size);
2366 }
2367
2368 cmdline_parse_token_string_t cmd_showport_reta_show =
2369         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2370 cmdline_parse_token_string_t cmd_showport_reta_port =
2371         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2372 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2373         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2374 cmdline_parse_token_string_t cmd_showport_reta_rss =
2375         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2376 cmdline_parse_token_string_t cmd_showport_reta_reta =
2377         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2378 cmdline_parse_token_num_t cmd_showport_reta_size =
2379         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2380 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2381         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2382                                         list_of_items, NULL);
2383
2384 cmdline_parse_inst_t cmd_showport_reta = {
2385         .f = cmd_showport_reta_parsed,
2386         .data = NULL,
2387         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2388         .tokens = {
2389                 (void *)&cmd_showport_reta_show,
2390                 (void *)&cmd_showport_reta_port,
2391                 (void *)&cmd_showport_reta_port_id,
2392                 (void *)&cmd_showport_reta_rss,
2393                 (void *)&cmd_showport_reta_reta,
2394                 (void *)&cmd_showport_reta_size,
2395                 (void *)&cmd_showport_reta_list_of_items,
2396                 NULL,
2397         },
2398 };
2399
2400 /* *** Show RSS hash configuration *** */
2401 struct cmd_showport_rss_hash {
2402         cmdline_fixed_string_t show;
2403         cmdline_fixed_string_t port;
2404         portid_t port_id;
2405         cmdline_fixed_string_t rss_hash;
2406         cmdline_fixed_string_t rss_type;
2407         cmdline_fixed_string_t key; /* optional argument */
2408 };
2409
2410 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2411                                 __attribute__((unused)) struct cmdline *cl,
2412                                 void *show_rss_key)
2413 {
2414         struct cmd_showport_rss_hash *res = parsed_result;
2415
2416         port_rss_hash_conf_show(res->port_id, res->rss_type,
2417                                 show_rss_key != NULL);
2418 }
2419
2420 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2421         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2422 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2423         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2424 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2425         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2426 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2427         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2428                                  "rss-hash");
2429 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2430         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2431                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2432                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2433                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2434                                  "ipv6-tcp-ex#ipv6-udp-ex");
2435 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2436         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2437
2438 cmdline_parse_inst_t cmd_showport_rss_hash = {
2439         .f = cmd_showport_rss_hash_parsed,
2440         .data = NULL,
2441         .help_str = "show port <port_id> rss-hash "
2442                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2443                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2444                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2445         .tokens = {
2446                 (void *)&cmd_showport_rss_hash_show,
2447                 (void *)&cmd_showport_rss_hash_port,
2448                 (void *)&cmd_showport_rss_hash_port_id,
2449                 (void *)&cmd_showport_rss_hash_rss_hash,
2450                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2451                 NULL,
2452         },
2453 };
2454
2455 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2456         .f = cmd_showport_rss_hash_parsed,
2457         .data = (void *)1,
2458         .help_str = "show port <port_id> rss-hash "
2459                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2460                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2461                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2462         .tokens = {
2463                 (void *)&cmd_showport_rss_hash_show,
2464                 (void *)&cmd_showport_rss_hash_port,
2465                 (void *)&cmd_showport_rss_hash_port_id,
2466                 (void *)&cmd_showport_rss_hash_rss_hash,
2467                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2468                 (void *)&cmd_showport_rss_hash_rss_key,
2469                 NULL,
2470         },
2471 };
2472
2473 /* *** Configure DCB *** */
2474 struct cmd_config_dcb {
2475         cmdline_fixed_string_t port;
2476         cmdline_fixed_string_t config;
2477         portid_t port_id;
2478         cmdline_fixed_string_t dcb;
2479         cmdline_fixed_string_t vt;
2480         cmdline_fixed_string_t vt_en;
2481         uint8_t num_tcs;
2482         cmdline_fixed_string_t pfc;
2483         cmdline_fixed_string_t pfc_en;
2484 };
2485
2486 static void
2487 cmd_config_dcb_parsed(void *parsed_result,
2488                         __attribute__((unused)) struct cmdline *cl,
2489                         __attribute__((unused)) void *data)
2490 {
2491         struct cmd_config_dcb *res = parsed_result;
2492         portid_t port_id = res->port_id;
2493         struct rte_port *port;
2494         uint8_t pfc_en;
2495         int ret;
2496
2497         port = &ports[port_id];
2498         /** Check if the port is not started **/
2499         if (port->port_status != RTE_PORT_STOPPED) {
2500                 printf("Please stop port %d first\n", port_id);
2501                 return;
2502         }
2503
2504         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2505                 printf("The invalid number of traffic class,"
2506                         " only 4 or 8 allowed.\n");
2507                 return;
2508         }
2509
2510         if (nb_fwd_lcores < res->num_tcs) {
2511                 printf("nb_cores shouldn't be less than number of TCs.\n");
2512                 return;
2513         }
2514         if (!strncmp(res->pfc_en, "on", 2))
2515                 pfc_en = 1;
2516         else
2517                 pfc_en = 0;
2518
2519         /* DCB in VT mode */
2520         if (!strncmp(res->vt_en, "on", 2))
2521                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2522                                 (enum rte_eth_nb_tcs)res->num_tcs,
2523                                 pfc_en);
2524         else
2525                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2526                                 (enum rte_eth_nb_tcs)res->num_tcs,
2527                                 pfc_en);
2528
2529
2530         if (ret != 0) {
2531                 printf("Cannot initialize network ports.\n");
2532                 return;
2533         }
2534
2535         cmd_reconfig_device_queue(port_id, 1, 1);
2536 }
2537
2538 cmdline_parse_token_string_t cmd_config_dcb_port =
2539         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2540 cmdline_parse_token_string_t cmd_config_dcb_config =
2541         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2542 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2543         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2544 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2545         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2546 cmdline_parse_token_string_t cmd_config_dcb_vt =
2547         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2548 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2549         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2550 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2551         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2552 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2553         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2554 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2555         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2556
2557 cmdline_parse_inst_t cmd_config_dcb = {
2558         .f = cmd_config_dcb_parsed,
2559         .data = NULL,
2560         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2561         .tokens = {
2562                 (void *)&cmd_config_dcb_port,
2563                 (void *)&cmd_config_dcb_config,
2564                 (void *)&cmd_config_dcb_port_id,
2565                 (void *)&cmd_config_dcb_dcb,
2566                 (void *)&cmd_config_dcb_vt,
2567                 (void *)&cmd_config_dcb_vt_en,
2568                 (void *)&cmd_config_dcb_num_tcs,
2569                 (void *)&cmd_config_dcb_pfc,
2570                 (void *)&cmd_config_dcb_pfc_en,
2571                 NULL,
2572         },
2573 };
2574
2575 /* *** configure number of packets per burst *** */
2576 struct cmd_config_burst {
2577         cmdline_fixed_string_t port;
2578         cmdline_fixed_string_t keyword;
2579         cmdline_fixed_string_t all;
2580         cmdline_fixed_string_t name;
2581         uint16_t value;
2582 };
2583
2584 static void
2585 cmd_config_burst_parsed(void *parsed_result,
2586                         __attribute__((unused)) struct cmdline *cl,
2587                         __attribute__((unused)) void *data)
2588 {
2589         struct cmd_config_burst *res = parsed_result;
2590
2591         if (!all_ports_stopped()) {
2592                 printf("Please stop all ports first\n");
2593                 return;
2594         }
2595
2596         if (!strcmp(res->name, "burst")) {
2597                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2598                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2599                         return;
2600                 }
2601                 nb_pkt_per_burst = res->value;
2602         } else {
2603                 printf("Unknown parameter\n");
2604                 return;
2605         }
2606
2607         init_port_config();
2608
2609         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2610 }
2611
2612 cmdline_parse_token_string_t cmd_config_burst_port =
2613         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2614 cmdline_parse_token_string_t cmd_config_burst_keyword =
2615         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2616 cmdline_parse_token_string_t cmd_config_burst_all =
2617         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2618 cmdline_parse_token_string_t cmd_config_burst_name =
2619         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2620 cmdline_parse_token_num_t cmd_config_burst_value =
2621         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2622
2623 cmdline_parse_inst_t cmd_config_burst = {
2624         .f = cmd_config_burst_parsed,
2625         .data = NULL,
2626         .help_str = "port config all burst <value>",
2627         .tokens = {
2628                 (void *)&cmd_config_burst_port,
2629                 (void *)&cmd_config_burst_keyword,
2630                 (void *)&cmd_config_burst_all,
2631                 (void *)&cmd_config_burst_name,
2632                 (void *)&cmd_config_burst_value,
2633                 NULL,
2634         },
2635 };
2636
2637 /* *** configure rx/tx queues *** */
2638 struct cmd_config_thresh {
2639         cmdline_fixed_string_t port;
2640         cmdline_fixed_string_t keyword;
2641         cmdline_fixed_string_t all;
2642         cmdline_fixed_string_t name;
2643         uint8_t value;
2644 };
2645
2646 static void
2647 cmd_config_thresh_parsed(void *parsed_result,
2648                         __attribute__((unused)) struct cmdline *cl,
2649                         __attribute__((unused)) void *data)
2650 {
2651         struct cmd_config_thresh *res = parsed_result;
2652
2653         if (!all_ports_stopped()) {
2654                 printf("Please stop all ports first\n");
2655                 return;
2656         }
2657
2658         if (!strcmp(res->name, "txpt"))
2659                 tx_pthresh = res->value;
2660         else if(!strcmp(res->name, "txht"))
2661                 tx_hthresh = res->value;
2662         else if(!strcmp(res->name, "txwt"))
2663                 tx_wthresh = res->value;
2664         else if(!strcmp(res->name, "rxpt"))
2665                 rx_pthresh = res->value;
2666         else if(!strcmp(res->name, "rxht"))
2667                 rx_hthresh = res->value;
2668         else if(!strcmp(res->name, "rxwt"))
2669                 rx_wthresh = res->value;
2670         else {
2671                 printf("Unknown parameter\n");
2672                 return;
2673         }
2674
2675         init_port_config();
2676
2677         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2678 }
2679
2680 cmdline_parse_token_string_t cmd_config_thresh_port =
2681         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2682 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2683         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2684 cmdline_parse_token_string_t cmd_config_thresh_all =
2685         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2686 cmdline_parse_token_string_t cmd_config_thresh_name =
2687         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2688                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2689 cmdline_parse_token_num_t cmd_config_thresh_value =
2690         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2691
2692 cmdline_parse_inst_t cmd_config_thresh = {
2693         .f = cmd_config_thresh_parsed,
2694         .data = NULL,
2695         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2696         .tokens = {
2697                 (void *)&cmd_config_thresh_port,
2698                 (void *)&cmd_config_thresh_keyword,
2699                 (void *)&cmd_config_thresh_all,
2700                 (void *)&cmd_config_thresh_name,
2701                 (void *)&cmd_config_thresh_value,
2702                 NULL,
2703         },
2704 };
2705
2706 /* *** configure free/rs threshold *** */
2707 struct cmd_config_threshold {
2708         cmdline_fixed_string_t port;
2709         cmdline_fixed_string_t keyword;
2710         cmdline_fixed_string_t all;
2711         cmdline_fixed_string_t name;
2712         uint16_t value;
2713 };
2714
2715 static void
2716 cmd_config_threshold_parsed(void *parsed_result,
2717                         __attribute__((unused)) struct cmdline *cl,
2718                         __attribute__((unused)) void *data)
2719 {
2720         struct cmd_config_threshold *res = parsed_result;
2721
2722         if (!all_ports_stopped()) {
2723                 printf("Please stop all ports first\n");
2724                 return;
2725         }
2726
2727         if (!strcmp(res->name, "txfreet"))
2728                 tx_free_thresh = res->value;
2729         else if (!strcmp(res->name, "txrst"))
2730                 tx_rs_thresh = res->value;
2731         else if (!strcmp(res->name, "rxfreet"))
2732                 rx_free_thresh = res->value;
2733         else {
2734                 printf("Unknown parameter\n");
2735                 return;
2736         }
2737
2738         init_port_config();
2739
2740         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2741 }
2742
2743 cmdline_parse_token_string_t cmd_config_threshold_port =
2744         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2745 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2746         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2747                                                                 "config");
2748 cmdline_parse_token_string_t cmd_config_threshold_all =
2749         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2750 cmdline_parse_token_string_t cmd_config_threshold_name =
2751         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2752                                                 "txfreet#txrst#rxfreet");
2753 cmdline_parse_token_num_t cmd_config_threshold_value =
2754         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2755
2756 cmdline_parse_inst_t cmd_config_threshold = {
2757         .f = cmd_config_threshold_parsed,
2758         .data = NULL,
2759         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2760         .tokens = {
2761                 (void *)&cmd_config_threshold_port,
2762                 (void *)&cmd_config_threshold_keyword,
2763                 (void *)&cmd_config_threshold_all,
2764                 (void *)&cmd_config_threshold_name,
2765                 (void *)&cmd_config_threshold_value,
2766                 NULL,
2767         },
2768 };
2769
2770 /* *** stop *** */
2771 struct cmd_stop_result {
2772         cmdline_fixed_string_t stop;
2773 };
2774
2775 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2776                             __attribute__((unused)) struct cmdline *cl,
2777                             __attribute__((unused)) void *data)
2778 {
2779         stop_packet_forwarding();
2780 }
2781
2782 cmdline_parse_token_string_t cmd_stop_stop =
2783         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2784
2785 cmdline_parse_inst_t cmd_stop = {
2786         .f = cmd_stop_parsed,
2787         .data = NULL,
2788         .help_str = "stop: Stop packet forwarding",
2789         .tokens = {
2790                 (void *)&cmd_stop_stop,
2791                 NULL,
2792         },
2793 };
2794
2795 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2796
2797 unsigned int
2798 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2799                 unsigned int *parsed_items, int check_unique_values)
2800 {
2801         unsigned int nb_item;
2802         unsigned int value;
2803         unsigned int i;
2804         unsigned int j;
2805         int value_ok;
2806         char c;
2807
2808         /*
2809          * First parse all items in the list and store their value.
2810          */
2811         value = 0;
2812         nb_item = 0;
2813         value_ok = 0;
2814         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2815                 c = str[i];
2816                 if ((c >= '0') && (c <= '9')) {
2817                         value = (unsigned int) (value * 10 + (c - '0'));
2818                         value_ok = 1;
2819                         continue;
2820                 }
2821                 if (c != ',') {
2822                         printf("character %c is not a decimal digit\n", c);
2823                         return 0;
2824                 }
2825                 if (! value_ok) {
2826                         printf("No valid value before comma\n");
2827                         return 0;
2828                 }
2829                 if (nb_item < max_items) {
2830                         parsed_items[nb_item] = value;
2831                         value_ok = 0;
2832                         value = 0;
2833                 }
2834                 nb_item++;
2835         }
2836         if (nb_item >= max_items) {
2837                 printf("Number of %s = %u > %u (maximum items)\n",
2838                        item_name, nb_item + 1, max_items);
2839                 return 0;
2840         }
2841         parsed_items[nb_item++] = value;
2842         if (! check_unique_values)
2843                 return nb_item;
2844
2845         /*
2846          * Then, check that all values in the list are differents.
2847          * No optimization here...
2848          */
2849         for (i = 0; i < nb_item; i++) {
2850                 for (j = i + 1; j < nb_item; j++) {
2851                         if (parsed_items[j] == parsed_items[i]) {
2852                                 printf("duplicated %s %u at index %u and %u\n",
2853                                        item_name, parsed_items[i], i, j);
2854                                 return 0;
2855                         }
2856                 }
2857         }
2858         return nb_item;
2859 }
2860
2861 struct cmd_set_list_result {
2862         cmdline_fixed_string_t cmd_keyword;
2863         cmdline_fixed_string_t list_name;
2864         cmdline_fixed_string_t list_of_items;
2865 };
2866
2867 static void cmd_set_list_parsed(void *parsed_result,
2868                                 __attribute__((unused)) struct cmdline *cl,
2869                                 __attribute__((unused)) void *data)
2870 {
2871         struct cmd_set_list_result *res;
2872         union {
2873                 unsigned int lcorelist[RTE_MAX_LCORE];
2874                 unsigned int portlist[RTE_MAX_ETHPORTS];
2875         } parsed_items;
2876         unsigned int nb_item;
2877
2878         if (test_done == 0) {
2879                 printf("Please stop forwarding first\n");
2880                 return;
2881         }
2882
2883         res = parsed_result;
2884         if (!strcmp(res->list_name, "corelist")) {
2885                 nb_item = parse_item_list(res->list_of_items, "core",
2886                                           RTE_MAX_LCORE,
2887                                           parsed_items.lcorelist, 1);
2888                 if (nb_item > 0) {
2889                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2890                         fwd_config_setup();
2891                 }
2892                 return;
2893         }
2894         if (!strcmp(res->list_name, "portlist")) {
2895                 nb_item = parse_item_list(res->list_of_items, "port",
2896                                           RTE_MAX_ETHPORTS,
2897                                           parsed_items.portlist, 1);
2898                 if (nb_item > 0) {
2899                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2900                         fwd_config_setup();
2901                 }
2902         }
2903 }
2904
2905 cmdline_parse_token_string_t cmd_set_list_keyword =
2906         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2907                                  "set");
2908 cmdline_parse_token_string_t cmd_set_list_name =
2909         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2910                                  "corelist#portlist");
2911 cmdline_parse_token_string_t cmd_set_list_of_items =
2912         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2913                                  NULL);
2914
2915 cmdline_parse_inst_t cmd_set_fwd_list = {
2916         .f = cmd_set_list_parsed,
2917         .data = NULL,
2918         .help_str = "set corelist|portlist <list0[,list1]*>",
2919         .tokens = {
2920                 (void *)&cmd_set_list_keyword,
2921                 (void *)&cmd_set_list_name,
2922                 (void *)&cmd_set_list_of_items,
2923                 NULL,
2924         },
2925 };
2926
2927 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2928
2929 struct cmd_setmask_result {
2930         cmdline_fixed_string_t set;
2931         cmdline_fixed_string_t mask;
2932         uint64_t hexavalue;
2933 };
2934
2935 static void cmd_set_mask_parsed(void *parsed_result,
2936                                 __attribute__((unused)) struct cmdline *cl,
2937                                 __attribute__((unused)) void *data)
2938 {
2939         struct cmd_setmask_result *res = parsed_result;
2940
2941         if (test_done == 0) {
2942                 printf("Please stop forwarding first\n");
2943                 return;
2944         }
2945         if (!strcmp(res->mask, "coremask")) {
2946                 set_fwd_lcores_mask(res->hexavalue);
2947                 fwd_config_setup();
2948         } else if (!strcmp(res->mask, "portmask")) {
2949                 set_fwd_ports_mask(res->hexavalue);
2950                 fwd_config_setup();
2951         }
2952 }
2953
2954 cmdline_parse_token_string_t cmd_setmask_set =
2955         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2956 cmdline_parse_token_string_t cmd_setmask_mask =
2957         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2958                                  "coremask#portmask");
2959 cmdline_parse_token_num_t cmd_setmask_value =
2960         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2961
2962 cmdline_parse_inst_t cmd_set_fwd_mask = {
2963         .f = cmd_set_mask_parsed,
2964         .data = NULL,
2965         .help_str = "set coremask|portmask <hexadecimal value>",
2966         .tokens = {
2967                 (void *)&cmd_setmask_set,
2968                 (void *)&cmd_setmask_mask,
2969                 (void *)&cmd_setmask_value,
2970                 NULL,
2971         },
2972 };
2973
2974 /*
2975  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2976  */
2977 struct cmd_set_result {
2978         cmdline_fixed_string_t set;
2979         cmdline_fixed_string_t what;
2980         uint16_t value;
2981 };
2982
2983 static void cmd_set_parsed(void *parsed_result,
2984                            __attribute__((unused)) struct cmdline *cl,
2985                            __attribute__((unused)) void *data)
2986 {
2987         struct cmd_set_result *res = parsed_result;
2988         if (!strcmp(res->what, "nbport")) {
2989                 set_fwd_ports_number(res->value);
2990                 fwd_config_setup();
2991         } else if (!strcmp(res->what, "nbcore")) {
2992                 set_fwd_lcores_number(res->value);
2993                 fwd_config_setup();
2994         } else if (!strcmp(res->what, "burst"))
2995                 set_nb_pkt_per_burst(res->value);
2996         else if (!strcmp(res->what, "verbose"))
2997                 set_verbose_level(res->value);
2998 }
2999
3000 cmdline_parse_token_string_t cmd_set_set =
3001         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
3002 cmdline_parse_token_string_t cmd_set_what =
3003         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
3004                                  "nbport#nbcore#burst#verbose");
3005 cmdline_parse_token_num_t cmd_set_value =
3006         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
3007
3008 cmdline_parse_inst_t cmd_set_numbers = {
3009         .f = cmd_set_parsed,
3010         .data = NULL,
3011         .help_str = "set nbport|nbcore|burst|verbose <value>",
3012         .tokens = {
3013                 (void *)&cmd_set_set,
3014                 (void *)&cmd_set_what,
3015                 (void *)&cmd_set_value,
3016                 NULL,
3017         },
3018 };
3019
3020 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3021
3022 struct cmd_set_txpkts_result {
3023         cmdline_fixed_string_t cmd_keyword;
3024         cmdline_fixed_string_t txpkts;
3025         cmdline_fixed_string_t seg_lengths;
3026 };
3027
3028 static void
3029 cmd_set_txpkts_parsed(void *parsed_result,
3030                       __attribute__((unused)) struct cmdline *cl,
3031                       __attribute__((unused)) void *data)
3032 {
3033         struct cmd_set_txpkts_result *res;
3034         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3035         unsigned int nb_segs;
3036
3037         res = parsed_result;
3038         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3039                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3040         if (nb_segs > 0)
3041                 set_tx_pkt_segments(seg_lengths, nb_segs);
3042 }
3043
3044 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3045         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3046                                  cmd_keyword, "set");
3047 cmdline_parse_token_string_t cmd_set_txpkts_name =
3048         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3049                                  txpkts, "txpkts");
3050 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3051         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3052                                  seg_lengths, NULL);
3053
3054 cmdline_parse_inst_t cmd_set_txpkts = {
3055         .f = cmd_set_txpkts_parsed,
3056         .data = NULL,
3057         .help_str = "set txpkts <len0[,len1]*>",
3058         .tokens = {
3059                 (void *)&cmd_set_txpkts_keyword,
3060                 (void *)&cmd_set_txpkts_name,
3061                 (void *)&cmd_set_txpkts_lengths,
3062                 NULL,
3063         },
3064 };
3065
3066 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3067
3068 struct cmd_set_txsplit_result {
3069         cmdline_fixed_string_t cmd_keyword;
3070         cmdline_fixed_string_t txsplit;
3071         cmdline_fixed_string_t mode;
3072 };
3073
3074 static void
3075 cmd_set_txsplit_parsed(void *parsed_result,
3076                       __attribute__((unused)) struct cmdline *cl,
3077                       __attribute__((unused)) void *data)
3078 {
3079         struct cmd_set_txsplit_result *res;
3080
3081         res = parsed_result;
3082         set_tx_pkt_split(res->mode);
3083 }
3084
3085 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3086         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3087                                  cmd_keyword, "set");
3088 cmdline_parse_token_string_t cmd_set_txsplit_name =
3089         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3090                                  txsplit, "txsplit");
3091 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3092         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3093                                  mode, NULL);
3094
3095 cmdline_parse_inst_t cmd_set_txsplit = {
3096         .f = cmd_set_txsplit_parsed,
3097         .data = NULL,
3098         .help_str = "set txsplit on|off|rand",
3099         .tokens = {
3100                 (void *)&cmd_set_txsplit_keyword,
3101                 (void *)&cmd_set_txsplit_name,
3102                 (void *)&cmd_set_txsplit_mode,
3103                 NULL,
3104         },
3105 };
3106
3107 /* *** CONFIG TX QUEUE FLAGS *** */
3108
3109 struct cmd_config_txqflags_result {
3110         cmdline_fixed_string_t port;
3111         cmdline_fixed_string_t config;
3112         cmdline_fixed_string_t all;
3113         cmdline_fixed_string_t what;
3114         int32_t hexvalue;
3115 };
3116
3117 static void cmd_config_txqflags_parsed(void *parsed_result,
3118                                 __attribute__((unused)) struct cmdline *cl,
3119                                 __attribute__((unused)) void *data)
3120 {
3121         struct cmd_config_txqflags_result *res = parsed_result;
3122
3123         if (!all_ports_stopped()) {
3124                 printf("Please stop all ports first\n");
3125                 return;
3126         }
3127
3128         if (strcmp(res->what, "txqflags")) {
3129                 printf("Unknown parameter\n");
3130                 return;
3131         }
3132
3133         if (res->hexvalue >= 0) {
3134                 txq_flags = res->hexvalue;
3135         } else {
3136                 printf("txqflags must be >= 0\n");
3137                 return;
3138         }
3139
3140         init_port_config();
3141
3142         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3143 }
3144
3145 cmdline_parse_token_string_t cmd_config_txqflags_port =
3146         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3147                                  "port");
3148 cmdline_parse_token_string_t cmd_config_txqflags_config =
3149         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3150                                  "config");
3151 cmdline_parse_token_string_t cmd_config_txqflags_all =
3152         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3153                                  "all");
3154 cmdline_parse_token_string_t cmd_config_txqflags_what =
3155         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3156                                  "txqflags");
3157 cmdline_parse_token_num_t cmd_config_txqflags_value =
3158         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3159                                 hexvalue, INT32);
3160
3161 cmdline_parse_inst_t cmd_config_txqflags = {
3162         .f = cmd_config_txqflags_parsed,
3163         .data = NULL,
3164         .help_str = "port config all txqflags <value>",
3165         .tokens = {
3166                 (void *)&cmd_config_txqflags_port,
3167                 (void *)&cmd_config_txqflags_config,
3168                 (void *)&cmd_config_txqflags_all,
3169                 (void *)&cmd_config_txqflags_what,
3170                 (void *)&cmd_config_txqflags_value,
3171                 NULL,
3172         },
3173 };
3174
3175 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3176 struct cmd_rx_vlan_filter_all_result {
3177         cmdline_fixed_string_t rx_vlan;
3178         cmdline_fixed_string_t what;
3179         cmdline_fixed_string_t all;
3180         portid_t port_id;
3181 };
3182
3183 static void
3184 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3185                               __attribute__((unused)) struct cmdline *cl,
3186                               __attribute__((unused)) void *data)
3187 {
3188         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3189
3190         if (!strcmp(res->what, "add"))
3191                 rx_vlan_all_filter_set(res->port_id, 1);
3192         else
3193                 rx_vlan_all_filter_set(res->port_id, 0);
3194 }
3195
3196 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3197         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3198                                  rx_vlan, "rx_vlan");
3199 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3200         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3201                                  what, "add#rm");
3202 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3203         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3204                                  all, "all");
3205 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3206         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3207                               port_id, UINT16);
3208
3209 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3210         .f = cmd_rx_vlan_filter_all_parsed,
3211         .data = NULL,
3212         .help_str = "rx_vlan add|rm all <port_id>: "
3213                 "Add/Remove all identifiers to/from the set of VLAN "
3214                 "identifiers filtered by a port",
3215         .tokens = {
3216                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3217                 (void *)&cmd_rx_vlan_filter_all_what,
3218                 (void *)&cmd_rx_vlan_filter_all_all,
3219                 (void *)&cmd_rx_vlan_filter_all_portid,
3220                 NULL,
3221         },
3222 };
3223
3224 /* *** VLAN OFFLOAD SET ON A PORT *** */
3225 struct cmd_vlan_offload_result {
3226         cmdline_fixed_string_t vlan;
3227         cmdline_fixed_string_t set;
3228         cmdline_fixed_string_t vlan_type;
3229         cmdline_fixed_string_t what;
3230         cmdline_fixed_string_t on;
3231         cmdline_fixed_string_t port_id;
3232 };
3233
3234 static void
3235 cmd_vlan_offload_parsed(void *parsed_result,
3236                           __attribute__((unused)) struct cmdline *cl,
3237                           __attribute__((unused)) void *data)
3238 {
3239         int on;
3240         struct cmd_vlan_offload_result *res = parsed_result;
3241         char *str;
3242         int i, len = 0;
3243         portid_t port_id = 0;
3244         unsigned int tmp;
3245
3246         str = res->port_id;
3247         len = strnlen(str, STR_TOKEN_SIZE);
3248         i = 0;
3249         /* Get port_id first */
3250         while(i < len){
3251                 if(str[i] == ',')
3252                         break;
3253
3254                 i++;
3255         }
3256         str[i]='\0';
3257         tmp = strtoul(str, NULL, 0);
3258         /* If port_id greater that what portid_t can represent, return */
3259         if(tmp >= RTE_MAX_ETHPORTS)
3260                 return;
3261         port_id = (portid_t)tmp;
3262
3263         if (!strcmp(res->on, "on"))
3264                 on = 1;
3265         else
3266                 on = 0;
3267
3268         if (!strcmp(res->what, "strip"))
3269                 rx_vlan_strip_set(port_id,  on);
3270         else if(!strcmp(res->what, "stripq")){
3271                 uint16_t queue_id = 0;
3272
3273                 /* No queue_id, return */
3274                 if(i + 1 >= len) {
3275                         printf("must specify (port,queue_id)\n");
3276                         return;
3277                 }
3278                 tmp = strtoul(str + i + 1, NULL, 0);
3279                 /* If queue_id greater that what 16-bits can represent, return */
3280                 if(tmp > 0xffff)
3281                         return;
3282
3283                 queue_id = (uint16_t)tmp;
3284                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3285         }
3286         else if (!strcmp(res->what, "filter"))
3287                 rx_vlan_filter_set(port_id, on);
3288         else
3289                 vlan_extend_set(port_id, on);
3290
3291         return;
3292 }
3293
3294 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3295         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3296                                  vlan, "vlan");
3297 cmdline_parse_token_string_t cmd_vlan_offload_set =
3298         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3299                                  set, "set");
3300 cmdline_parse_token_string_t cmd_vlan_offload_what =
3301         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3302                                  what, "strip#filter#qinq#stripq");
3303 cmdline_parse_token_string_t cmd_vlan_offload_on =
3304         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3305                               on, "on#off");
3306 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3307         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3308                               port_id, NULL);
3309
3310 cmdline_parse_inst_t cmd_vlan_offload = {
3311         .f = cmd_vlan_offload_parsed,
3312         .data = NULL,
3313         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3314                 "<port_id[,queue_id]>: "
3315                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3316         .tokens = {
3317                 (void *)&cmd_vlan_offload_vlan,
3318                 (void *)&cmd_vlan_offload_set,
3319                 (void *)&cmd_vlan_offload_what,
3320                 (void *)&cmd_vlan_offload_on,
3321                 (void *)&cmd_vlan_offload_portid,
3322                 NULL,
3323         },
3324 };
3325
3326 /* *** VLAN TPID SET ON A PORT *** */
3327 struct cmd_vlan_tpid_result {
3328         cmdline_fixed_string_t vlan;
3329         cmdline_fixed_string_t set;
3330         cmdline_fixed_string_t vlan_type;
3331         cmdline_fixed_string_t what;
3332         uint16_t tp_id;
3333         portid_t port_id;
3334 };
3335
3336 static void
3337 cmd_vlan_tpid_parsed(void *parsed_result,
3338                           __attribute__((unused)) struct cmdline *cl,
3339                           __attribute__((unused)) void *data)
3340 {
3341         struct cmd_vlan_tpid_result *res = parsed_result;
3342         enum rte_vlan_type vlan_type;
3343
3344         if (!strcmp(res->vlan_type, "inner"))
3345                 vlan_type = ETH_VLAN_TYPE_INNER;
3346         else if (!strcmp(res->vlan_type, "outer"))
3347                 vlan_type = ETH_VLAN_TYPE_OUTER;
3348         else {
3349                 printf("Unknown vlan type\n");
3350                 return;
3351         }
3352         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3353 }
3354
3355 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3356         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3357                                  vlan, "vlan");
3358 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3359         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3360                                  set, "set");
3361 cmdline_parse_token_string_t cmd_vlan_type =
3362         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3363                                  vlan_type, "inner#outer");
3364 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3365         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3366                                  what, "tpid");
3367 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3368         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3369                               tp_id, UINT16);
3370 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3371         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3372                               port_id, UINT16);
3373
3374 cmdline_parse_inst_t cmd_vlan_tpid = {
3375         .f = cmd_vlan_tpid_parsed,
3376         .data = NULL,
3377         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3378                 "Set the VLAN Ether type",
3379         .tokens = {
3380                 (void *)&cmd_vlan_tpid_vlan,
3381                 (void *)&cmd_vlan_tpid_set,
3382                 (void *)&cmd_vlan_type,
3383                 (void *)&cmd_vlan_tpid_what,
3384                 (void *)&cmd_vlan_tpid_tpid,
3385                 (void *)&cmd_vlan_tpid_portid,
3386                 NULL,
3387         },
3388 };
3389
3390 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3391 struct cmd_rx_vlan_filter_result {
3392         cmdline_fixed_string_t rx_vlan;
3393         cmdline_fixed_string_t what;
3394         uint16_t vlan_id;
3395         portid_t port_id;
3396 };
3397
3398 static void
3399 cmd_rx_vlan_filter_parsed(void *parsed_result,
3400                           __attribute__((unused)) struct cmdline *cl,
3401                           __attribute__((unused)) void *data)
3402 {
3403         struct cmd_rx_vlan_filter_result *res = parsed_result;
3404
3405         if (!strcmp(res->what, "add"))
3406                 rx_vft_set(res->port_id, res->vlan_id, 1);
3407         else
3408                 rx_vft_set(res->port_id, res->vlan_id, 0);
3409 }
3410
3411 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3412         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3413                                  rx_vlan, "rx_vlan");
3414 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3415         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3416                                  what, "add#rm");
3417 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3418         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3419                               vlan_id, UINT16);
3420 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3421         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3422                               port_id, UINT16);
3423
3424 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3425         .f = cmd_rx_vlan_filter_parsed,
3426         .data = NULL,
3427         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3428                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3429                 "identifiers filtered by a port",
3430         .tokens = {
3431                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3432                 (void *)&cmd_rx_vlan_filter_what,
3433                 (void *)&cmd_rx_vlan_filter_vlanid,
3434                 (void *)&cmd_rx_vlan_filter_portid,
3435                 NULL,
3436         },
3437 };
3438
3439 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3440 struct cmd_tx_vlan_set_result {
3441         cmdline_fixed_string_t tx_vlan;
3442         cmdline_fixed_string_t set;
3443         portid_t port_id;
3444         uint16_t vlan_id;
3445 };
3446
3447 static void
3448 cmd_tx_vlan_set_parsed(void *parsed_result,
3449                        __attribute__((unused)) struct cmdline *cl,
3450                        __attribute__((unused)) void *data)
3451 {
3452         struct cmd_tx_vlan_set_result *res = parsed_result;
3453
3454         tx_vlan_set(res->port_id, res->vlan_id);
3455 }
3456
3457 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3458         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3459                                  tx_vlan, "tx_vlan");
3460 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3461         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3462                                  set, "set");
3463 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3464         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3465                               port_id, UINT16);
3466 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3467         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3468                               vlan_id, UINT16);
3469
3470 cmdline_parse_inst_t cmd_tx_vlan_set = {
3471         .f = cmd_tx_vlan_set_parsed,
3472         .data = NULL,
3473         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3474                 "Enable hardware insertion of a single VLAN header "
3475                 "with a given TAG Identifier in packets sent on a port",
3476         .tokens = {
3477                 (void *)&cmd_tx_vlan_set_tx_vlan,
3478                 (void *)&cmd_tx_vlan_set_set,
3479                 (void *)&cmd_tx_vlan_set_portid,
3480                 (void *)&cmd_tx_vlan_set_vlanid,
3481                 NULL,
3482         },
3483 };
3484
3485 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3486 struct cmd_tx_vlan_set_qinq_result {
3487         cmdline_fixed_string_t tx_vlan;
3488         cmdline_fixed_string_t set;
3489         portid_t port_id;
3490         uint16_t vlan_id;
3491         uint16_t vlan_id_outer;
3492 };
3493
3494 static void
3495 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3496                             __attribute__((unused)) struct cmdline *cl,
3497                             __attribute__((unused)) void *data)
3498 {
3499         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3500
3501         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3502 }
3503
3504 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3505         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3506                 tx_vlan, "tx_vlan");
3507 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3508         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3509                 set, "set");
3510 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3511         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3512                 port_id, UINT16);
3513 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3514         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3515                 vlan_id, UINT16);
3516 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3517         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3518                 vlan_id_outer, UINT16);
3519
3520 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3521         .f = cmd_tx_vlan_set_qinq_parsed,
3522         .data = NULL,
3523         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3524                 "Enable hardware insertion of double VLAN header "
3525                 "with given TAG Identifiers in packets sent on a port",
3526         .tokens = {
3527                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3528                 (void *)&cmd_tx_vlan_set_qinq_set,
3529                 (void *)&cmd_tx_vlan_set_qinq_portid,
3530                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3531                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3532                 NULL,
3533         },
3534 };
3535
3536 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3537 struct cmd_tx_vlan_set_pvid_result {
3538         cmdline_fixed_string_t tx_vlan;
3539         cmdline_fixed_string_t set;
3540         cmdline_fixed_string_t pvid;
3541         portid_t port_id;
3542         uint16_t vlan_id;
3543         cmdline_fixed_string_t mode;
3544 };
3545
3546 static void
3547 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3548                             __attribute__((unused)) struct cmdline *cl,
3549                             __attribute__((unused)) void *data)
3550 {
3551         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3552
3553         if (strcmp(res->mode, "on") == 0)
3554                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3555         else
3556                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3557 }
3558
3559 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3560         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3561                                  tx_vlan, "tx_vlan");
3562 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3563         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3564                                  set, "set");
3565 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3566         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3567                                  pvid, "pvid");
3568 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3569         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3570                              port_id, UINT16);
3571 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3572         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3573                               vlan_id, UINT16);
3574 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3575         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3576                                  mode, "on#off");
3577
3578 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3579         .f = cmd_tx_vlan_set_pvid_parsed,
3580         .data = NULL,
3581         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3582         .tokens = {
3583                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3584                 (void *)&cmd_tx_vlan_set_pvid_set,
3585                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3586                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3587                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3588                 (void *)&cmd_tx_vlan_set_pvid_mode,
3589                 NULL,
3590         },
3591 };
3592
3593 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3594 struct cmd_tx_vlan_reset_result {
3595         cmdline_fixed_string_t tx_vlan;
3596         cmdline_fixed_string_t reset;
3597         portid_t port_id;
3598 };
3599
3600 static void
3601 cmd_tx_vlan_reset_parsed(void *parsed_result,
3602                          __attribute__((unused)) struct cmdline *cl,
3603                          __attribute__((unused)) void *data)
3604 {
3605         struct cmd_tx_vlan_reset_result *res = parsed_result;
3606
3607         tx_vlan_reset(res->port_id);
3608 }
3609
3610 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3611         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3612                                  tx_vlan, "tx_vlan");
3613 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3614         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3615                                  reset, "reset");
3616 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3617         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3618                               port_id, UINT16);
3619
3620 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3621         .f = cmd_tx_vlan_reset_parsed,
3622         .data = NULL,
3623         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3624                 "VLAN header in packets sent on a port",
3625         .tokens = {
3626                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3627                 (void *)&cmd_tx_vlan_reset_reset,
3628                 (void *)&cmd_tx_vlan_reset_portid,
3629                 NULL,
3630         },
3631 };
3632
3633
3634 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3635 struct cmd_csum_result {
3636         cmdline_fixed_string_t csum;
3637         cmdline_fixed_string_t mode;
3638         cmdline_fixed_string_t proto;
3639         cmdline_fixed_string_t hwsw;
3640         portid_t port_id;
3641 };
3642
3643 static void
3644 csum_show(int port_id)
3645 {
3646         struct rte_eth_dev_info dev_info;
3647         uint16_t ol_flags;
3648
3649         ol_flags = ports[port_id].tx_ol_flags;
3650         printf("Parse tunnel is %s\n",
3651                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3652         printf("IP checksum offload is %s\n",
3653                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3654         printf("UDP checksum offload is %s\n",
3655                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3656         printf("TCP checksum offload is %s\n",
3657                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3658         printf("SCTP checksum offload is %s\n",
3659                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3660         printf("Outer-Ip checksum offload is %s\n",
3661                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3662
3663         /* display warnings if configuration is not supported by the NIC */
3664         rte_eth_dev_info_get(port_id, &dev_info);
3665         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3666                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3667                 printf("Warning: hardware IP checksum enabled but not "
3668                         "supported by port %d\n", port_id);
3669         }
3670         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3671                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3672                 printf("Warning: hardware UDP checksum enabled but not "
3673                         "supported by port %d\n", port_id);
3674         }
3675         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3676                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3677                 printf("Warning: hardware TCP checksum enabled but not "
3678                         "supported by port %d\n", port_id);
3679         }
3680         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3681                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3682                 printf("Warning: hardware SCTP checksum enabled but not "
3683                         "supported by port %d\n", port_id);
3684         }
3685         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3686                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3687                 printf("Warning: hardware outer IP checksum enabled but not "
3688                         "supported by port %d\n", port_id);
3689         }
3690 }
3691
3692 static void
3693 cmd_csum_parsed(void *parsed_result,
3694                        __attribute__((unused)) struct cmdline *cl,
3695                        __attribute__((unused)) void *data)
3696 {
3697         struct cmd_csum_result *res = parsed_result;
3698         int hw = 0;
3699         uint16_t mask = 0;
3700
3701         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3702                 printf("invalid port %d\n", res->port_id);
3703                 return;
3704         }
3705
3706         if (!strcmp(res->mode, "set")) {
3707
3708                 if (!strcmp(res->hwsw, "hw"))
3709                         hw = 1;
3710
3711                 if (!strcmp(res->proto, "ip")) {
3712                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3713                 } else if (!strcmp(res->proto, "udp")) {
3714                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3715                 } else if (!strcmp(res->proto, "tcp")) {
3716                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3717                 } else if (!strcmp(res->proto, "sctp")) {
3718                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3719                 } else if (!strcmp(res->proto, "outer-ip")) {
3720                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3721                 }
3722
3723                 if (hw)
3724                         ports[res->port_id].tx_ol_flags |= mask;
3725                 else
3726                         ports[res->port_id].tx_ol_flags &= (~mask);
3727         }
3728         csum_show(res->port_id);
3729 }
3730
3731 cmdline_parse_token_string_t cmd_csum_csum =
3732         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3733                                 csum, "csum");
3734 cmdline_parse_token_string_t cmd_csum_mode =
3735         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3736                                 mode, "set");
3737 cmdline_parse_token_string_t cmd_csum_proto =
3738         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3739                                 proto, "ip#tcp#udp#sctp#outer-ip");
3740 cmdline_parse_token_string_t cmd_csum_hwsw =
3741         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3742                                 hwsw, "hw#sw");
3743 cmdline_parse_token_num_t cmd_csum_portid =
3744         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3745                                 port_id, UINT16);
3746
3747 cmdline_parse_inst_t cmd_csum_set = {
3748         .f = cmd_csum_parsed,
3749         .data = NULL,
3750         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3751                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3752                 "using csum forward engine",
3753         .tokens = {
3754                 (void *)&cmd_csum_csum,
3755                 (void *)&cmd_csum_mode,
3756                 (void *)&cmd_csum_proto,
3757                 (void *)&cmd_csum_hwsw,
3758                 (void *)&cmd_csum_portid,
3759                 NULL,
3760         },
3761 };
3762
3763 cmdline_parse_token_string_t cmd_csum_mode_show =
3764         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3765                                 mode, "show");
3766
3767 cmdline_parse_inst_t cmd_csum_show = {
3768         .f = cmd_csum_parsed,
3769         .data = NULL,
3770         .help_str = "csum show <port_id>: Show checksum offload configuration",
3771         .tokens = {
3772                 (void *)&cmd_csum_csum,
3773                 (void *)&cmd_csum_mode_show,
3774                 (void *)&cmd_csum_portid,
3775                 NULL,
3776         },
3777 };
3778
3779 /* Enable/disable tunnel parsing */
3780 struct cmd_csum_tunnel_result {
3781         cmdline_fixed_string_t csum;
3782         cmdline_fixed_string_t parse;
3783         cmdline_fixed_string_t onoff;
3784         portid_t port_id;
3785 };
3786
3787 static void
3788 cmd_csum_tunnel_parsed(void *parsed_result,
3789                        __attribute__((unused)) struct cmdline *cl,
3790                        __attribute__((unused)) void *data)
3791 {
3792         struct cmd_csum_tunnel_result *res = parsed_result;
3793
3794         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3795                 return;
3796
3797         if (!strcmp(res->onoff, "on"))
3798                 ports[res->port_id].tx_ol_flags |=
3799                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3800         else
3801                 ports[res->port_id].tx_ol_flags &=
3802                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3803
3804         csum_show(res->port_id);
3805 }
3806
3807 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3808         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3809                                 csum, "csum");
3810 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3811         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3812                                 parse, "parse_tunnel");
3813 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3814         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3815                                 onoff, "on#off");
3816 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3817         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3818                                 port_id, UINT16);
3819
3820 cmdline_parse_inst_t cmd_csum_tunnel = {
3821         .f = cmd_csum_tunnel_parsed,
3822         .data = NULL,
3823         .help_str = "csum parse_tunnel on|off <port_id>: "
3824                 "Enable/Disable parsing of tunnels for csum engine",
3825         .tokens = {
3826                 (void *)&cmd_csum_tunnel_csum,
3827                 (void *)&cmd_csum_tunnel_parse,
3828                 (void *)&cmd_csum_tunnel_onoff,
3829                 (void *)&cmd_csum_tunnel_portid,
3830                 NULL,
3831         },
3832 };
3833
3834 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3835 struct cmd_tso_set_result {
3836         cmdline_fixed_string_t tso;
3837         cmdline_fixed_string_t mode;
3838         uint16_t tso_segsz;
3839         portid_t port_id;
3840 };
3841
3842 static void
3843 cmd_tso_set_parsed(void *parsed_result,
3844                        __attribute__((unused)) struct cmdline *cl,
3845                        __attribute__((unused)) void *data)
3846 {
3847         struct cmd_tso_set_result *res = parsed_result;
3848         struct rte_eth_dev_info dev_info;
3849
3850         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3851                 return;
3852
3853         if (!strcmp(res->mode, "set"))
3854                 ports[res->port_id].tso_segsz = res->tso_segsz;
3855
3856         if (ports[res->port_id].tso_segsz == 0)
3857                 printf("TSO for non-tunneled packets is disabled\n");
3858         else
3859                 printf("TSO segment size for non-tunneled packets is %d\n",
3860                         ports[res->port_id].tso_segsz);
3861
3862         /* display warnings if configuration is not supported by the NIC */
3863         rte_eth_dev_info_get(res->port_id, &dev_info);
3864         if ((ports[res->port_id].tso_segsz != 0) &&
3865                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3866                 printf("Warning: TSO enabled but not "
3867                         "supported by port %d\n", res->port_id);
3868         }
3869 }
3870
3871 cmdline_parse_token_string_t cmd_tso_set_tso =
3872         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3873                                 tso, "tso");
3874 cmdline_parse_token_string_t cmd_tso_set_mode =
3875         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3876                                 mode, "set");
3877 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3878         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3879                                 tso_segsz, UINT16);
3880 cmdline_parse_token_num_t cmd_tso_set_portid =
3881         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3882                                 port_id, UINT16);
3883
3884 cmdline_parse_inst_t cmd_tso_set = {
3885         .f = cmd_tso_set_parsed,
3886         .data = NULL,
3887         .help_str = "tso set <tso_segsz> <port_id>: "
3888                 "Set TSO segment size of non-tunneled packets for csum engine "
3889                 "(0 to disable)",
3890         .tokens = {
3891                 (void *)&cmd_tso_set_tso,
3892                 (void *)&cmd_tso_set_mode,
3893                 (void *)&cmd_tso_set_tso_segsz,
3894                 (void *)&cmd_tso_set_portid,
3895                 NULL,
3896         },
3897 };
3898
3899 cmdline_parse_token_string_t cmd_tso_show_mode =
3900         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3901                                 mode, "show");
3902
3903
3904 cmdline_parse_inst_t cmd_tso_show = {
3905         .f = cmd_tso_set_parsed,
3906         .data = NULL,
3907         .help_str = "tso show <port_id>: "
3908                 "Show TSO segment size of non-tunneled packets for csum engine",
3909         .tokens = {
3910                 (void *)&cmd_tso_set_tso,
3911                 (void *)&cmd_tso_show_mode,
3912                 (void *)&cmd_tso_set_portid,
3913                 NULL,
3914         },
3915 };
3916
3917 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3918 struct cmd_tunnel_tso_set_result {
3919         cmdline_fixed_string_t tso;
3920         cmdline_fixed_string_t mode;
3921         uint16_t tso_segsz;
3922         portid_t port_id;
3923 };
3924
3925 static void
3926 check_tunnel_tso_nic_support(portid_t port_id)
3927 {
3928         struct rte_eth_dev_info dev_info;
3929
3930         rte_eth_dev_info_get(port_id, &dev_info);
3931         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3932                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3933                        "supported by port %d\n", port_id);
3934         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3935                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3936                         "supported by port %d\n", port_id);
3937         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3938                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3939                        "supported by port %d\n", port_id);
3940         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3941                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3942                        "supported by port %d\n", port_id);
3943 }
3944
3945 static void
3946 cmd_tunnel_tso_set_parsed(void *parsed_result,
3947                           __attribute__((unused)) struct cmdline *cl,
3948                           __attribute__((unused)) void *data)
3949 {
3950         struct cmd_tunnel_tso_set_result *res = parsed_result;
3951
3952         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3953                 return;
3954
3955         if (!strcmp(res->mode, "set"))
3956                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3957
3958         if (ports[res->port_id].tunnel_tso_segsz == 0)
3959                 printf("TSO for tunneled packets is disabled\n");
3960         else {
3961                 printf("TSO segment size for tunneled packets is %d\n",
3962                         ports[res->port_id].tunnel_tso_segsz);
3963
3964                 /* Below conditions are needed to make it work:
3965                  * (1) tunnel TSO is supported by the NIC;
3966                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3967                  * are recognized;
3968                  * (3) for tunneled pkts with outer L3 of IPv4,
3969                  * "csum set outer-ip" must be set to hw, because after tso,
3970                  * total_len of outer IP header is changed, and the checksum
3971                  * of outer IP header calculated by sw should be wrong; that
3972                  * is not necessary for IPv6 tunneled pkts because there's no
3973                  * checksum in IP header anymore.
3974                  */
3975                 check_tunnel_tso_nic_support(res->port_id);
3976
3977                 if (!(ports[res->port_id].tx_ol_flags &
3978                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3979                         printf("Warning: csum parse_tunnel must be set "
3980                                 "so that tunneled packets are recognized\n");
3981                 if (!(ports[res->port_id].tx_ol_flags &
3982                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3983                         printf("Warning: csum set outer-ip must be set to hw "
3984                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3985         }
3986 }
3987
3988 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3989         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3990                                 tso, "tunnel_tso");
3991 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3992         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3993                                 mode, "set");
3994 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3995         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3996                                 tso_segsz, UINT16);
3997 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3998         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3999                                 port_id, UINT16);
4000
4001 cmdline_parse_inst_t cmd_tunnel_tso_set = {
4002         .f = cmd_tunnel_tso_set_parsed,
4003         .data = NULL,
4004         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
4005                 "Set TSO segment size of tunneled packets for csum engine "
4006                 "(0 to disable)",
4007         .tokens = {
4008                 (void *)&cmd_tunnel_tso_set_tso,
4009                 (void *)&cmd_tunnel_tso_set_mode,
4010                 (void *)&cmd_tunnel_tso_set_tso_segsz,
4011                 (void *)&cmd_tunnel_tso_set_portid,
4012                 NULL,
4013         },
4014 };
4015
4016 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4017         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4018                                 mode, "show");
4019
4020
4021 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4022         .f = cmd_tunnel_tso_set_parsed,
4023         .data = NULL,
4024         .help_str = "tunnel_tso show <port_id> "
4025                 "Show TSO segment size of tunneled packets for csum engine",
4026         .tokens = {
4027                 (void *)&cmd_tunnel_tso_set_tso,
4028                 (void *)&cmd_tunnel_tso_show_mode,
4029                 (void *)&cmd_tunnel_tso_set_portid,
4030                 NULL,
4031         },
4032 };
4033
4034 /* *** SET GRO FOR A PORT *** */
4035 struct cmd_gro_enable_result {
4036         cmdline_fixed_string_t cmd_set;
4037         cmdline_fixed_string_t cmd_port;
4038         cmdline_fixed_string_t cmd_keyword;
4039         cmdline_fixed_string_t cmd_onoff;
4040         portid_t cmd_pid;
4041 };
4042
4043 static void
4044 cmd_gro_enable_parsed(void *parsed_result,
4045                 __attribute__((unused)) struct cmdline *cl,
4046                 __attribute__((unused)) void *data)
4047 {
4048         struct cmd_gro_enable_result *res;
4049
4050         res = parsed_result;
4051         if (!strcmp(res->cmd_keyword, "gro"))
4052                 setup_gro(res->cmd_onoff, res->cmd_pid);
4053 }
4054
4055 cmdline_parse_token_string_t cmd_gro_enable_set =
4056         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4057                         cmd_set, "set");
4058 cmdline_parse_token_string_t cmd_gro_enable_port =
4059         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4060                         cmd_keyword, "port");
4061 cmdline_parse_token_num_t cmd_gro_enable_pid =
4062         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4063                         cmd_pid, UINT16);
4064 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4065         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4066                         cmd_keyword, "gro");
4067 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4068         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4069                         cmd_onoff, "on#off");
4070
4071 cmdline_parse_inst_t cmd_gro_enable = {
4072         .f = cmd_gro_enable_parsed,
4073         .data = NULL,
4074         .help_str = "set port <port_id> gro on|off",
4075         .tokens = {
4076                 (void *)&cmd_gro_enable_set,
4077                 (void *)&cmd_gro_enable_port,
4078                 (void *)&cmd_gro_enable_pid,
4079                 (void *)&cmd_gro_enable_keyword,
4080                 (void *)&cmd_gro_enable_onoff,
4081                 NULL,
4082         },
4083 };
4084
4085 /* *** DISPLAY GRO CONFIGURATION *** */
4086 struct cmd_gro_show_result {
4087         cmdline_fixed_string_t cmd_show;
4088         cmdline_fixed_string_t cmd_port;
4089         cmdline_fixed_string_t cmd_keyword;
4090         portid_t cmd_pid;
4091 };
4092
4093 static void
4094 cmd_gro_show_parsed(void *parsed_result,
4095                 __attribute__((unused)) struct cmdline *cl,
4096                 __attribute__((unused)) void *data)
4097 {
4098         struct cmd_gro_show_result *res;
4099
4100         res = parsed_result;
4101         if (!strcmp(res->cmd_keyword, "gro"))
4102                 show_gro(res->cmd_pid);
4103 }
4104
4105 cmdline_parse_token_string_t cmd_gro_show_show =
4106         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4107                         cmd_show, "show");
4108 cmdline_parse_token_string_t cmd_gro_show_port =
4109         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4110                         cmd_port, "port");
4111 cmdline_parse_token_num_t cmd_gro_show_pid =
4112         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4113                         cmd_pid, UINT16);
4114 cmdline_parse_token_string_t cmd_gro_show_keyword =
4115         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4116                         cmd_keyword, "gro");
4117
4118 cmdline_parse_inst_t cmd_gro_show = {
4119         .f = cmd_gro_show_parsed,
4120         .data = NULL,
4121         .help_str = "show port <port_id> gro",
4122         .tokens = {
4123                 (void *)&cmd_gro_show_show,
4124                 (void *)&cmd_gro_show_port,
4125                 (void *)&cmd_gro_show_pid,
4126                 (void *)&cmd_gro_show_keyword,
4127                 NULL,
4128         },
4129 };
4130
4131 /* *** SET FLUSH CYCLES FOR GRO *** */
4132 struct cmd_gro_flush_result {
4133         cmdline_fixed_string_t cmd_set;
4134         cmdline_fixed_string_t cmd_keyword;
4135         cmdline_fixed_string_t cmd_flush;
4136         uint8_t cmd_cycles;
4137 };
4138
4139 static void
4140 cmd_gro_flush_parsed(void *parsed_result,
4141                 __attribute__((unused)) struct cmdline *cl,
4142                 __attribute__((unused)) void *data)
4143 {
4144         struct cmd_gro_flush_result *res;
4145
4146         res = parsed_result;
4147         if ((!strcmp(res->cmd_keyword, "gro")) &&
4148                         (!strcmp(res->cmd_flush, "flush")))
4149                 setup_gro_flush_cycles(res->cmd_cycles);
4150 }
4151
4152 cmdline_parse_token_string_t cmd_gro_flush_set =
4153         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4154                         cmd_set, "set");
4155 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4156         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4157                         cmd_keyword, "gro");
4158 cmdline_parse_token_string_t cmd_gro_flush_flush =
4159         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4160                         cmd_flush, "flush");
4161 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4162         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4163                         cmd_cycles, UINT8);
4164
4165 cmdline_parse_inst_t cmd_gro_flush = {
4166         .f = cmd_gro_flush_parsed,
4167         .data = NULL,
4168         .help_str = "set gro flush <cycles>",
4169         .tokens = {
4170                 (void *)&cmd_gro_flush_set,
4171                 (void *)&cmd_gro_flush_keyword,
4172                 (void *)&cmd_gro_flush_flush,
4173                 (void *)&cmd_gro_flush_cycles,
4174                 NULL,
4175         },
4176 };
4177
4178 /* *** ENABLE/DISABLE GSO *** */
4179 struct cmd_gso_enable_result {
4180         cmdline_fixed_string_t cmd_set;
4181         cmdline_fixed_string_t cmd_port;
4182         cmdline_fixed_string_t cmd_keyword;
4183         cmdline_fixed_string_t cmd_mode;
4184         portid_t cmd_pid;
4185 };
4186
4187 static void
4188 cmd_gso_enable_parsed(void *parsed_result,
4189                 __attribute__((unused)) struct cmdline *cl,
4190                 __attribute__((unused)) void *data)
4191 {
4192         struct cmd_gso_enable_result *res;
4193
4194         res = parsed_result;
4195         if (!strcmp(res->cmd_keyword, "gso"))
4196                 setup_gso(res->cmd_mode, res->cmd_pid);
4197 }
4198
4199 cmdline_parse_token_string_t cmd_gso_enable_set =
4200         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4201                         cmd_set, "set");
4202 cmdline_parse_token_string_t cmd_gso_enable_port =
4203         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4204                         cmd_port, "port");
4205 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4206         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4207                         cmd_keyword, "gso");
4208 cmdline_parse_token_string_t cmd_gso_enable_mode =
4209         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4210                         cmd_mode, "on#off");
4211 cmdline_parse_token_num_t cmd_gso_enable_pid =
4212         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4213                         cmd_pid, UINT16);
4214
4215 cmdline_parse_inst_t cmd_gso_enable = {
4216         .f = cmd_gso_enable_parsed,
4217         .data = NULL,
4218         .help_str = "set port <port_id> gso on|off",
4219         .tokens = {
4220                 (void *)&cmd_gso_enable_set,
4221                 (void *)&cmd_gso_enable_port,
4222                 (void *)&cmd_gso_enable_pid,
4223                 (void *)&cmd_gso_enable_keyword,
4224                 (void *)&cmd_gso_enable_mode,
4225                 NULL,
4226         },
4227 };
4228
4229 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4230 struct cmd_gso_size_result {
4231         cmdline_fixed_string_t cmd_set;
4232         cmdline_fixed_string_t cmd_keyword;
4233         cmdline_fixed_string_t cmd_segsz;
4234         uint16_t cmd_size;
4235 };
4236
4237 static void
4238 cmd_gso_size_parsed(void *parsed_result,
4239                        __attribute__((unused)) struct cmdline *cl,
4240                        __attribute__((unused)) void *data)
4241 {
4242         struct cmd_gso_size_result *res = parsed_result;
4243
4244         if (test_done == 0) {
4245                 printf("Before setting GSO segsz, please first"
4246                                 " stop fowarding\n");
4247                 return;
4248         }
4249
4250         if (!strcmp(res->cmd_keyword, "gso") &&
4251                         !strcmp(res->cmd_segsz, "segsz")) {
4252                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4253                         printf("gso_size should be larger than %zu."
4254                                         " Please input a legal value\n",
4255                                         RTE_GSO_SEG_SIZE_MIN);
4256                 else
4257                         gso_max_segment_size = res->cmd_size;
4258         }
4259 }
4260
4261 cmdline_parse_token_string_t cmd_gso_size_set =
4262         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4263                                 cmd_set, "set");
4264 cmdline_parse_token_string_t cmd_gso_size_keyword =
4265         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4266                                 cmd_keyword, "gso");
4267 cmdline_parse_token_string_t cmd_gso_size_segsz =
4268         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4269                                 cmd_segsz, "segsz");
4270 cmdline_parse_token_num_t cmd_gso_size_size =
4271         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4272                                 cmd_size, UINT16);
4273
4274 cmdline_parse_inst_t cmd_gso_size = {
4275         .f = cmd_gso_size_parsed,
4276         .data = NULL,
4277         .help_str = "set gso segsz <length>",
4278         .tokens = {
4279                 (void *)&cmd_gso_size_set,
4280                 (void *)&cmd_gso_size_keyword,
4281                 (void *)&cmd_gso_size_segsz,
4282                 (void *)&cmd_gso_size_size,
4283                 NULL,
4284         },
4285 };
4286
4287 /* *** SHOW GSO CONFIGURATION *** */
4288 struct cmd_gso_show_result {
4289         cmdline_fixed_string_t cmd_show;
4290         cmdline_fixed_string_t cmd_port;
4291         cmdline_fixed_string_t cmd_keyword;
4292         portid_t cmd_pid;
4293 };
4294
4295 static void
4296 cmd_gso_show_parsed(void *parsed_result,
4297                        __attribute__((unused)) struct cmdline *cl,
4298                        __attribute__((unused)) void *data)
4299 {
4300         struct cmd_gso_show_result *res = parsed_result;
4301
4302         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4303                 printf("invalid port id %u\n", res->cmd_pid);
4304                 return;
4305         }
4306         if (!strcmp(res->cmd_keyword, "gso")) {
4307                 if (gso_ports[res->cmd_pid].enable) {
4308                         printf("Max GSO'd packet size: %uB\n"
4309                                         "Supported GSO types: TCP/IPv4, "
4310                                         "VxLAN with inner TCP/IPv4 packet, "
4311                                         "GRE with inner TCP/IPv4  packet\n",
4312                                         gso_max_segment_size);
4313                 } else
4314                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4315         }
4316 }
4317
4318 cmdline_parse_token_string_t cmd_gso_show_show =
4319 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4320                 cmd_show, "show");
4321 cmdline_parse_token_string_t cmd_gso_show_port =
4322 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4323                 cmd_port, "port");
4324 cmdline_parse_token_string_t cmd_gso_show_keyword =
4325         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4326                                 cmd_keyword, "gso");
4327 cmdline_parse_token_num_t cmd_gso_show_pid =
4328         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4329                                 cmd_pid, UINT16);
4330
4331 cmdline_parse_inst_t cmd_gso_show = {
4332         .f = cmd_gso_show_parsed,
4333         .data = NULL,
4334         .help_str = "show port <port_id> gso",
4335         .tokens = {
4336                 (void *)&cmd_gso_show_show,
4337                 (void *)&cmd_gso_show_port,
4338                 (void *)&cmd_gso_show_pid,
4339                 (void *)&cmd_gso_show_keyword,
4340                 NULL,
4341         },
4342 };
4343
4344 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4345 struct cmd_set_flush_rx {
4346         cmdline_fixed_string_t set;
4347         cmdline_fixed_string_t flush_rx;
4348         cmdline_fixed_string_t mode;
4349 };
4350
4351 static void
4352 cmd_set_flush_rx_parsed(void *parsed_result,
4353                 __attribute__((unused)) struct cmdline *cl,
4354                 __attribute__((unused)) void *data)
4355 {
4356         struct cmd_set_flush_rx *res = parsed_result;
4357         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4358 }
4359
4360 cmdline_parse_token_string_t cmd_setflushrx_set =
4361         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4362                         set, "set");
4363 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4364         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4365                         flush_rx, "flush_rx");
4366 cmdline_parse_token_string_t cmd_setflushrx_mode =
4367         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4368                         mode, "on#off");
4369
4370
4371 cmdline_parse_inst_t cmd_set_flush_rx = {
4372         .f = cmd_set_flush_rx_parsed,
4373         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4374         .data = NULL,
4375         .tokens = {
4376                 (void *)&cmd_setflushrx_set,
4377                 (void *)&cmd_setflushrx_flush_rx,
4378                 (void *)&cmd_setflushrx_mode,
4379                 NULL,
4380         },
4381 };
4382
4383 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4384 struct cmd_set_link_check {
4385         cmdline_fixed_string_t set;
4386         cmdline_fixed_string_t link_check;
4387         cmdline_fixed_string_t mode;
4388 };
4389
4390 static void
4391 cmd_set_link_check_parsed(void *parsed_result,
4392                 __attribute__((unused)) struct cmdline *cl,
4393                 __attribute__((unused)) void *data)
4394 {
4395         struct cmd_set_link_check *res = parsed_result;
4396         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4397 }
4398
4399 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4400         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4401                         set, "set");
4402 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4403         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4404                         link_check, "link_check");
4405 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4406         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4407                         mode, "on#off");
4408
4409
4410 cmdline_parse_inst_t cmd_set_link_check = {
4411         .f = cmd_set_link_check_parsed,
4412         .help_str = "set link_check on|off: Enable/Disable link status check "
4413                     "when starting/stopping a port",
4414         .data = NULL,
4415         .tokens = {
4416                 (void *)&cmd_setlinkcheck_set,
4417                 (void *)&cmd_setlinkcheck_link_check,
4418                 (void *)&cmd_setlinkcheck_mode,
4419                 NULL,
4420         },
4421 };
4422
4423 /* *** SET NIC BYPASS MODE *** */
4424 struct cmd_set_bypass_mode_result {
4425         cmdline_fixed_string_t set;
4426         cmdline_fixed_string_t bypass;
4427         cmdline_fixed_string_t mode;
4428         cmdline_fixed_string_t value;
4429         portid_t port_id;
4430 };
4431
4432 static void
4433 cmd_set_bypass_mode_parsed(void *parsed_result,
4434                 __attribute__((unused)) struct cmdline *cl,
4435                 __attribute__((unused)) void *data)
4436 {
4437         struct cmd_set_bypass_mode_result *res = parsed_result;
4438         portid_t port_id = res->port_id;
4439         int32_t rc = -EINVAL;
4440
4441 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4442         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4443
4444         if (!strcmp(res->value, "bypass"))
4445                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4446         else if (!strcmp(res->value, "isolate"))
4447                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4448         else
4449                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4450
4451         /* Set the bypass mode for the relevant port. */
4452         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4453 #endif
4454         if (rc != 0)
4455                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4456 }
4457
4458 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4459         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4460                         set, "set");
4461 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4462         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4463                         bypass, "bypass");
4464 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4465         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4466                         mode, "mode");
4467 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4468         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4469                         value, "normal#bypass#isolate");
4470 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4471         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4472                                 port_id, UINT16);
4473
4474 cmdline_parse_inst_t cmd_set_bypass_mode = {
4475         .f = cmd_set_bypass_mode_parsed,
4476         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4477                     "Set the NIC bypass mode for port_id",
4478         .data = NULL,
4479         .tokens = {
4480                 (void *)&cmd_setbypass_mode_set,
4481                 (void *)&cmd_setbypass_mode_bypass,
4482                 (void *)&cmd_setbypass_mode_mode,
4483                 (void *)&cmd_setbypass_mode_value,
4484                 (void *)&cmd_setbypass_mode_port,
4485                 NULL,
4486         },
4487 };
4488
4489 /* *** SET NIC BYPASS EVENT *** */
4490 struct cmd_set_bypass_event_result {
4491         cmdline_fixed_string_t set;
4492         cmdline_fixed_string_t bypass;
4493         cmdline_fixed_string_t event;
4494         cmdline_fixed_string_t event_value;
4495         cmdline_fixed_string_t mode;
4496         cmdline_fixed_string_t mode_value;
4497         portid_t port_id;
4498 };
4499
4500 static void
4501 cmd_set_bypass_event_parsed(void *parsed_result,
4502                 __attribute__((unused)) struct cmdline *cl,
4503                 __attribute__((unused)) void *data)
4504 {
4505         int32_t rc = -EINVAL;
4506         struct cmd_set_bypass_event_result *res = parsed_result;
4507         portid_t port_id = res->port_id;
4508
4509 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4510         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4511         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4512
4513         if (!strcmp(res->event_value, "timeout"))
4514                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4515         else if (!strcmp(res->event_value, "os_on"))
4516                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4517         else if (!strcmp(res->event_value, "os_off"))
4518                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4519         else if (!strcmp(res->event_value, "power_on"))
4520                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4521         else if (!strcmp(res->event_value, "power_off"))
4522                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4523         else
4524                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4525
4526         if (!strcmp(res->mode_value, "bypass"))
4527                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4528         else if (!strcmp(res->mode_value, "isolate"))
4529                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4530         else
4531                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4532
4533         /* Set the watchdog timeout. */
4534         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4535
4536                 rc = -EINVAL;
4537                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4538                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4539                                                            bypass_timeout);
4540                 }
4541                 if (rc != 0) {
4542                         printf("Failed to set timeout value %u "
4543                         "for port %d, errto code: %d.\n",
4544                         bypass_timeout, port_id, rc);
4545                 }
4546         }
4547
4548         /* Set the bypass event to transition to bypass mode. */
4549         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4550                                               bypass_mode);
4551 #endif
4552
4553         if (rc != 0)
4554                 printf("\t Failed to set bypass event for port = %d.\n",
4555                        port_id);
4556 }
4557
4558 cmdline_parse_token_string_t cmd_setbypass_event_set =
4559         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4560                         set, "set");
4561 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4562         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4563                         bypass, "bypass");
4564 cmdline_parse_token_string_t cmd_setbypass_event_event =
4565         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4566                         event, "event");
4567 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4568         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4569                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4570 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4571         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4572                         mode, "mode");
4573 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4574         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4575                         mode_value, "normal#bypass#isolate");
4576 cmdline_parse_token_num_t cmd_setbypass_event_port =
4577         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4578                                 port_id, UINT16);
4579
4580 cmdline_parse_inst_t cmd_set_bypass_event = {
4581         .f = cmd_set_bypass_event_parsed,
4582         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4583                 "power_off mode normal|bypass|isolate <port_id>: "
4584                 "Set the NIC bypass event mode for port_id",
4585         .data = NULL,
4586         .tokens = {
4587                 (void *)&cmd_setbypass_event_set,
4588                 (void *)&cmd_setbypass_event_bypass,
4589                 (void *)&cmd_setbypass_event_event,
4590                 (void *)&cmd_setbypass_event_event_value,
4591                 (void *)&cmd_setbypass_event_mode,
4592                 (void *)&cmd_setbypass_event_mode_value,
4593                 (void *)&cmd_setbypass_event_port,
4594                 NULL,
4595         },
4596 };
4597
4598
4599 /* *** SET NIC BYPASS TIMEOUT *** */
4600 struct cmd_set_bypass_timeout_result {
4601         cmdline_fixed_string_t set;
4602         cmdline_fixed_string_t bypass;
4603         cmdline_fixed_string_t timeout;
4604         cmdline_fixed_string_t value;
4605 };
4606
4607 static void
4608 cmd_set_bypass_timeout_parsed(void *parsed_result,
4609                 __attribute__((unused)) struct cmdline *cl,
4610                 __attribute__((unused)) void *data)
4611 {
4612         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4613
4614 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4615         if (!strcmp(res->value, "1.5"))
4616                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4617         else if (!strcmp(res->value, "2"))
4618                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4619         else if (!strcmp(res->value, "3"))
4620                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4621         else if (!strcmp(res->value, "4"))
4622                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4623         else if (!strcmp(res->value, "8"))
4624                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4625         else if (!strcmp(res->value, "16"))
4626                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4627         else if (!strcmp(res->value, "32"))
4628                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4629         else
4630                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4631 #endif
4632 }
4633
4634 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4635         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4636                         set, "set");
4637 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4638         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4639                         bypass, "bypass");
4640 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4641         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4642                         timeout, "timeout");
4643 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4644         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4645                         value, "0#1.5#2#3#4#8#16#32");
4646
4647 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4648         .f = cmd_set_bypass_timeout_parsed,
4649         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4650                 "Set the NIC bypass watchdog timeout in seconds",
4651         .data = NULL,
4652         .tokens = {
4653                 (void *)&cmd_setbypass_timeout_set,
4654                 (void *)&cmd_setbypass_timeout_bypass,
4655                 (void *)&cmd_setbypass_timeout_timeout,
4656                 (void *)&cmd_setbypass_timeout_value,
4657                 NULL,
4658         },
4659 };
4660
4661 /* *** SHOW NIC BYPASS MODE *** */
4662 struct cmd_show_bypass_config_result {
4663         cmdline_fixed_string_t show;
4664         cmdline_fixed_string_t bypass;
4665         cmdline_fixed_string_t config;
4666         portid_t port_id;
4667 };
4668
4669 static void
4670 cmd_show_bypass_config_parsed(void *parsed_result,
4671                 __attribute__((unused)) struct cmdline *cl,
4672                 __attribute__((unused)) void *data)
4673 {
4674         struct cmd_show_bypass_config_result *res = parsed_result;
4675         portid_t port_id = res->port_id;
4676         int rc = -EINVAL;
4677 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4678         uint32_t event_mode;
4679         uint32_t bypass_mode;
4680         uint32_t timeout = bypass_timeout;
4681         int i;
4682
4683         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4684                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4685         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4686                 {"UNKNOWN", "normal", "bypass", "isolate"};
4687         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4688                 "NONE",
4689                 "OS/board on",
4690                 "power supply on",
4691                 "OS/board off",
4692                 "power supply off",
4693                 "timeout"};
4694         int num_events = (sizeof events) / (sizeof events[0]);
4695
4696         /* Display the bypass mode.*/
4697         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4698                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4699                 return;
4700         }
4701         else {
4702                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4703                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4704
4705                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4706         }
4707
4708         /* Display the bypass timeout.*/
4709         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4710                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4711
4712         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4713
4714         /* Display the bypass events and associated modes. */
4715         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4716
4717                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4718                         printf("\tFailed to get bypass mode for event = %s\n",
4719                                 events[i]);
4720                 } else {
4721                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4722                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4723
4724                         printf("\tbypass event: %-16s = %s\n", events[i],
4725                                 modes[event_mode]);
4726                 }
4727         }
4728 #endif
4729         if (rc != 0)
4730                 printf("\tFailed to get bypass configuration for port = %d\n",
4731                        port_id);
4732 }
4733
4734 cmdline_parse_token_string_t cmd_showbypass_config_show =
4735         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4736                         show, "show");
4737 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4738         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4739                         bypass, "bypass");
4740 cmdline_parse_token_string_t cmd_showbypass_config_config =
4741         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4742                         config, "config");
4743 cmdline_parse_token_num_t cmd_showbypass_config_port =
4744         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4745                                 port_id, UINT16);
4746
4747 cmdline_parse_inst_t cmd_show_bypass_config = {
4748         .f = cmd_show_bypass_config_parsed,
4749         .help_str = "show bypass config <port_id>: "
4750                     "Show the NIC bypass config for port_id",
4751         .data = NULL,
4752         .tokens = {
4753                 (void *)&cmd_showbypass_config_show,
4754                 (void *)&cmd_showbypass_config_bypass,
4755                 (void *)&cmd_showbypass_config_config,
4756                 (void *)&cmd_showbypass_config_port,
4757                 NULL,
4758         },
4759 };
4760
4761 #ifdef RTE_LIBRTE_PMD_BOND
4762 /* *** SET BONDING MODE *** */
4763 struct cmd_set_bonding_mode_result {
4764         cmdline_fixed_string_t set;
4765         cmdline_fixed_string_t bonding;
4766         cmdline_fixed_string_t mode;
4767         uint8_t value;
4768         portid_t port_id;
4769 };
4770
4771 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4772                 __attribute__((unused))  struct cmdline *cl,
4773                 __attribute__((unused)) void *data)
4774 {
4775         struct cmd_set_bonding_mode_result *res = parsed_result;
4776         portid_t port_id = res->port_id;
4777
4778         /* Set the bonding mode for the relevant port. */
4779         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4780                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4781 }
4782
4783 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4784 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4785                 set, "set");
4786 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4787 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4788                 bonding, "bonding");
4789 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4790 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4791                 mode, "mode");
4792 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4793 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4794                 value, UINT8);
4795 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4796 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4797                 port_id, UINT16);
4798
4799 cmdline_parse_inst_t cmd_set_bonding_mode = {
4800                 .f = cmd_set_bonding_mode_parsed,
4801                 .help_str = "set bonding mode <mode_value> <port_id>: "
4802                         "Set the bonding mode for port_id",
4803                 .data = NULL,
4804                 .tokens = {
4805                                 (void *) &cmd_setbonding_mode_set,
4806                                 (void *) &cmd_setbonding_mode_bonding,
4807                                 (void *) &cmd_setbonding_mode_mode,
4808                                 (void *) &cmd_setbonding_mode_value,
4809                                 (void *) &cmd_setbonding_mode_port,
4810                                 NULL
4811                 }
4812 };
4813
4814 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4815 struct cmd_set_bonding_lacp_dedicated_queues_result {
4816         cmdline_fixed_string_t set;
4817         cmdline_fixed_string_t bonding;
4818         cmdline_fixed_string_t lacp;
4819         cmdline_fixed_string_t dedicated_queues;
4820         portid_t port_id;
4821         cmdline_fixed_string_t mode;
4822 };
4823
4824 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4825                 __attribute__((unused))  struct cmdline *cl,
4826                 __attribute__((unused)) void *data)
4827 {
4828         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4829         portid_t port_id = res->port_id;
4830         struct rte_port *port;
4831
4832         port = &ports[port_id];
4833
4834         /** Check if the port is not started **/
4835         if (port->port_status != RTE_PORT_STOPPED) {
4836                 printf("Please stop port %d first\n", port_id);
4837                 return;
4838         }
4839
4840         if (!strcmp(res->mode, "enable")) {
4841                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4842                         printf("Dedicate queues for LACP control packets"
4843                                         " enabled\n");
4844                 else
4845                         printf("Enabling dedicate queues for LACP control "
4846                                         "packets on port %d failed\n", port_id);
4847         } else if (!strcmp(res->mode, "disable")) {
4848                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4849                         printf("Dedicated queues for LACP control packets "
4850                                         "disabled\n");
4851                 else
4852                         printf("Disabling dedicated queues for LACP control "
4853                                         "traffic on port %d failed\n", port_id);
4854         }
4855 }
4856
4857 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4858 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4859                 set, "set");
4860 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4861 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4862                 bonding, "bonding");
4863 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4864 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4865                 lacp, "lacp");
4866 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4867 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4868                 dedicated_queues, "dedicated_queues");
4869 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4870 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4871                 port_id, UINT16);
4872 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4873 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4874                 mode, "enable#disable");
4875
4876 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4877                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4878                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4879                         "enable|disable: "
4880                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4881                 .data = NULL,
4882                 .tokens = {
4883                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4884                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4885                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4886                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4887                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4888                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4889                         NULL
4890                 }
4891 };
4892
4893 /* *** SET BALANCE XMIT POLICY *** */
4894 struct cmd_set_bonding_balance_xmit_policy_result {
4895         cmdline_fixed_string_t set;
4896         cmdline_fixed_string_t bonding;
4897         cmdline_fixed_string_t balance_xmit_policy;
4898         portid_t port_id;
4899         cmdline_fixed_string_t policy;
4900 };
4901
4902 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4903                 __attribute__((unused))  struct cmdline *cl,
4904                 __attribute__((unused)) void *data)
4905 {
4906         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4907         portid_t port_id = res->port_id;
4908         uint8_t policy;
4909
4910         if (!strcmp(res->policy, "l2")) {
4911                 policy = BALANCE_XMIT_POLICY_LAYER2;
4912         } else if (!strcmp(res->policy, "l23")) {
4913                 policy = BALANCE_XMIT_POLICY_LAYER23;
4914         } else if (!strcmp(res->policy, "l34")) {
4915                 policy = BALANCE_XMIT_POLICY_LAYER34;
4916         } else {
4917                 printf("\t Invalid xmit policy selection");
4918                 return;
4919         }
4920
4921         /* Set the bonding mode for the relevant port. */
4922         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4923                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4924                                 port_id);
4925         }
4926 }
4927
4928 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4929 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4930                 set, "set");
4931 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4932 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4933                 bonding, "bonding");
4934 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4935 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4936                 balance_xmit_policy, "balance_xmit_policy");
4937 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4938 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4939                 port_id, UINT16);
4940 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4941 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4942                 policy, "l2#l23#l34");
4943
4944 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4945                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4946                 .help_str = "set bonding balance_xmit_policy <port_id> "
4947                         "l2|l23|l34: "
4948                         "Set the bonding balance_xmit_policy for port_id",
4949                 .data = NULL,
4950                 .tokens = {
4951                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4952                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4953                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4954                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4955                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4956                                 NULL
4957                 }
4958 };
4959
4960 /* *** SHOW NIC BONDING CONFIGURATION *** */
4961 struct cmd_show_bonding_config_result {
4962         cmdline_fixed_string_t show;
4963         cmdline_fixed_string_t bonding;
4964         cmdline_fixed_string_t config;
4965         portid_t port_id;
4966 };
4967
4968 static void cmd_show_bonding_config_parsed(void *parsed_result,
4969                 __attribute__((unused))  struct cmdline *cl,
4970                 __attribute__((unused)) void *data)
4971 {
4972         struct cmd_show_bonding_config_result *res = parsed_result;
4973         int bonding_mode, agg_mode;
4974         portid_t slaves[RTE_MAX_ETHPORTS];
4975         int num_slaves, num_active_slaves;
4976         int primary_id;
4977         int i;
4978         portid_t port_id = res->port_id;
4979
4980         /* Display the bonding mode.*/
4981         bonding_mode = rte_eth_bond_mode_get(port_id);
4982         if (bonding_mode < 0) {
4983                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4984                 return;
4985         } else
4986                 printf("\tBonding mode: %d\n", bonding_mode);
4987
4988         if (bonding_mode == BONDING_MODE_BALANCE) {
4989                 int balance_xmit_policy;
4990
4991                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4992                 if (balance_xmit_policy < 0) {
4993                         printf("\tFailed to get balance xmit policy for port = %d\n",
4994                                         port_id);
4995                         return;
4996                 } else {
4997                         printf("\tBalance Xmit Policy: ");
4998
4999                         switch (balance_xmit_policy) {
5000                         case BALANCE_XMIT_POLICY_LAYER2:
5001                                 printf("BALANCE_XMIT_POLICY_LAYER2");
5002                                 break;
5003                         case BALANCE_XMIT_POLICY_LAYER23:
5004                                 printf("BALANCE_XMIT_POLICY_LAYER23");
5005                                 break;
5006                         case BALANCE_XMIT_POLICY_LAYER34:
5007                                 printf("BALANCE_XMIT_POLICY_LAYER34");
5008                                 break;
5009                         }
5010                         printf("\n");
5011                 }
5012         }
5013
5014         if (bonding_mode == BONDING_MODE_8023AD) {
5015                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5016                 printf("\tIEEE802.3AD Aggregator Mode: ");
5017                 switch (agg_mode) {
5018                 case AGG_BANDWIDTH:
5019                         printf("bandwidth");
5020                         break;
5021                 case AGG_STABLE:
5022                         printf("stable");
5023                         break;
5024                 case AGG_COUNT:
5025                         printf("count");
5026                         break;
5027                 }
5028                 printf("\n");
5029         }
5030
5031         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5032
5033         if (num_slaves < 0) {
5034                 printf("\tFailed to get slave list for port = %d\n", port_id);
5035                 return;
5036         }
5037         if (num_slaves > 0) {
5038                 printf("\tSlaves (%d): [", num_slaves);
5039                 for (i = 0; i < num_slaves - 1; i++)
5040                         printf("%d ", slaves[i]);
5041
5042                 printf("%d]\n", slaves[num_slaves - 1]);
5043         } else {
5044                 printf("\tSlaves: []\n");
5045
5046         }
5047
5048         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5049                         RTE_MAX_ETHPORTS);
5050
5051         if (num_active_slaves < 0) {
5052                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5053                 return;
5054         }
5055         if (num_active_slaves > 0) {
5056                 printf("\tActive Slaves (%d): [", num_active_slaves);
5057                 for (i = 0; i < num_active_slaves - 1; i++)
5058                         printf("%d ", slaves[i]);
5059
5060                 printf("%d]\n", slaves[num_active_slaves - 1]);
5061
5062         } else {
5063                 printf("\tActive Slaves: []\n");
5064
5065         }
5066
5067         primary_id = rte_eth_bond_primary_get(port_id);
5068         if (primary_id < 0) {
5069                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5070                 return;
5071         } else
5072                 printf("\tPrimary: [%d]\n", primary_id);
5073
5074 }
5075
5076 cmdline_parse_token_string_t cmd_showbonding_config_show =
5077 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5078                 show, "show");
5079 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5080 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5081                 bonding, "bonding");
5082 cmdline_parse_token_string_t cmd_showbonding_config_config =
5083 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5084                 config, "config");
5085 cmdline_parse_token_num_t cmd_showbonding_config_port =
5086 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5087                 port_id, UINT16);
5088
5089 cmdline_parse_inst_t cmd_show_bonding_config = {
5090                 .f = cmd_show_bonding_config_parsed,
5091                 .help_str = "show bonding config <port_id>: "
5092                         "Show the bonding config for port_id",
5093                 .data = NULL,
5094                 .tokens = {
5095                                 (void *)&cmd_showbonding_config_show,
5096                                 (void *)&cmd_showbonding_config_bonding,
5097                                 (void *)&cmd_showbonding_config_config,
5098                                 (void *)&cmd_showbonding_config_port,
5099                                 NULL
5100                 }
5101 };
5102
5103 /* *** SET BONDING PRIMARY *** */
5104 struct cmd_set_bonding_primary_result {
5105         cmdline_fixed_string_t set;
5106         cmdline_fixed_string_t bonding;
5107         cmdline_fixed_string_t primary;
5108         portid_t slave_id;
5109         portid_t port_id;
5110 };
5111
5112 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5113                 __attribute__((unused))  struct cmdline *cl,
5114                 __attribute__((unused)) void *data)
5115 {
5116         struct cmd_set_bonding_primary_result *res = parsed_result;
5117         portid_t master_port_id = res->port_id;
5118         portid_t slave_port_id = res->slave_id;
5119
5120         /* Set the primary slave for a bonded device. */
5121         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5122                 printf("\t Failed to set primary slave for port = %d.\n",
5123                                 master_port_id);
5124                 return;
5125         }
5126         init_port_config();
5127 }
5128
5129 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5130 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5131                 set, "set");
5132 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5133 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5134                 bonding, "bonding");
5135 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5136 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5137                 primary, "primary");
5138 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5139 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5140                 slave_id, UINT16);
5141 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5142 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5143                 port_id, UINT16);
5144
5145 cmdline_parse_inst_t cmd_set_bonding_primary = {
5146                 .f = cmd_set_bonding_primary_parsed,
5147                 .help_str = "set bonding primary <slave_id> <port_id>: "
5148                         "Set the primary slave for port_id",
5149                 .data = NULL,
5150                 .tokens = {
5151                                 (void *)&cmd_setbonding_primary_set,
5152                                 (void *)&cmd_setbonding_primary_bonding,
5153                                 (void *)&cmd_setbonding_primary_primary,
5154                                 (void *)&cmd_setbonding_primary_slave,
5155                                 (void *)&cmd_setbonding_primary_port,
5156                                 NULL
5157                 }
5158 };
5159
5160 /* *** ADD SLAVE *** */
5161 struct cmd_add_bonding_slave_result {
5162         cmdline_fixed_string_t add;
5163         cmdline_fixed_string_t bonding;
5164         cmdline_fixed_string_t slave;
5165         portid_t slave_id;
5166         portid_t port_id;
5167 };
5168
5169 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5170                 __attribute__((unused))  struct cmdline *cl,
5171                 __attribute__((unused)) void *data)
5172 {
5173         struct cmd_add_bonding_slave_result *res = parsed_result;
5174         portid_t master_port_id = res->port_id;
5175         portid_t slave_port_id = res->slave_id;
5176
5177         /* add the slave for a bonded device. */
5178         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5179                 printf("\t Failed to add slave %d to master port = %d.\n",
5180                                 slave_port_id, master_port_id);
5181                 return;
5182         }
5183         init_port_config();
5184         set_port_slave_flag(slave_port_id);
5185 }
5186
5187 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5188 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5189                 add, "add");
5190 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5191 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5192                 bonding, "bonding");
5193 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5194 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5195                 slave, "slave");
5196 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5197 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5198                 slave_id, UINT16);
5199 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5200 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5201                 port_id, UINT16);
5202
5203 cmdline_parse_inst_t cmd_add_bonding_slave = {
5204                 .f = cmd_add_bonding_slave_parsed,
5205                 .help_str = "add bonding slave <slave_id> <port_id>: "
5206                         "Add a slave device to a bonded device",
5207                 .data = NULL,
5208                 .tokens = {
5209                                 (void *)&cmd_addbonding_slave_add,
5210                                 (void *)&cmd_addbonding_slave_bonding,
5211                                 (void *)&cmd_addbonding_slave_slave,
5212                                 (void *)&cmd_addbonding_slave_slaveid,
5213                                 (void *)&cmd_addbonding_slave_port,
5214                                 NULL
5215                 }
5216 };
5217
5218 /* *** REMOVE SLAVE *** */
5219 struct cmd_remove_bonding_slave_result {
5220         cmdline_fixed_string_t remove;
5221         cmdline_fixed_string_t bonding;
5222         cmdline_fixed_string_t slave;
5223         portid_t slave_id;
5224         portid_t port_id;
5225 };
5226
5227 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5228                 __attribute__((unused))  struct cmdline *cl,
5229                 __attribute__((unused)) void *data)
5230 {
5231         struct cmd_remove_bonding_slave_result *res = parsed_result;
5232         portid_t master_port_id = res->port_id;
5233         portid_t slave_port_id = res->slave_id;
5234
5235         /* remove the slave from a bonded device. */
5236         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5237                 printf("\t Failed to remove slave %d from master port = %d.\n",
5238                                 slave_port_id, master_port_id);
5239                 return;
5240         }
5241         init_port_config();
5242         clear_port_slave_flag(slave_port_id);
5243 }
5244
5245 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5246                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5247                                 remove, "remove");
5248 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5249                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5250                                 bonding, "bonding");
5251 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5252                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5253                                 slave, "slave");
5254 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5255                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5256                                 slave_id, UINT16);
5257 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5258                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5259                                 port_id, UINT16);
5260
5261 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5262                 .f = cmd_remove_bonding_slave_parsed,
5263                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5264                         "Remove a slave device from a bonded device",
5265                 .data = NULL,
5266                 .tokens = {
5267                                 (void *)&cmd_removebonding_slave_remove,
5268                                 (void *)&cmd_removebonding_slave_bonding,
5269                                 (void *)&cmd_removebonding_slave_slave,
5270                                 (void *)&cmd_removebonding_slave_slaveid,
5271                                 (void *)&cmd_removebonding_slave_port,
5272                                 NULL
5273                 }
5274 };
5275
5276 /* *** CREATE BONDED DEVICE *** */
5277 struct cmd_create_bonded_device_result {
5278         cmdline_fixed_string_t create;
5279         cmdline_fixed_string_t bonded;
5280         cmdline_fixed_string_t device;
5281         uint8_t mode;
5282         uint8_t socket;
5283 };
5284
5285 static int bond_dev_num = 0;
5286
5287 static void cmd_create_bonded_device_parsed(void *parsed_result,
5288                 __attribute__((unused))  struct cmdline *cl,
5289                 __attribute__((unused)) void *data)
5290 {
5291         struct cmd_create_bonded_device_result *res = parsed_result;
5292         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5293         int port_id;
5294
5295         if (test_done == 0) {
5296                 printf("Please stop forwarding first\n");
5297                 return;
5298         }
5299
5300         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5301                         bond_dev_num++);
5302
5303         /* Create a new bonded device. */
5304         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5305         if (port_id < 0) {
5306                 printf("\t Failed to create bonded device.\n");
5307                 return;
5308         } else {
5309                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5310                                 port_id);
5311
5312                 /* Update number of ports */
5313                 nb_ports = rte_eth_dev_count();
5314                 reconfig(port_id, res->socket);
5315                 rte_eth_promiscuous_enable(port_id);
5316         }
5317
5318 }
5319
5320 cmdline_parse_token_string_t cmd_createbonded_device_create =
5321                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5322                                 create, "create");
5323 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5324                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5325                                 bonded, "bonded");
5326 cmdline_parse_token_string_t cmd_createbonded_device_device =
5327                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5328                                 device, "device");
5329 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5330                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5331                                 mode, UINT8);
5332 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5333                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5334                                 socket, UINT8);
5335
5336 cmdline_parse_inst_t cmd_create_bonded_device = {
5337                 .f = cmd_create_bonded_device_parsed,
5338                 .help_str = "create bonded device <mode> <socket>: "
5339                         "Create a new bonded device with specific bonding mode and socket",
5340                 .data = NULL,
5341                 .tokens = {
5342                                 (void *)&cmd_createbonded_device_create,
5343                                 (void *)&cmd_createbonded_device_bonded,
5344                                 (void *)&cmd_createbonded_device_device,
5345                                 (void *)&cmd_createbonded_device_mode,
5346                                 (void *)&cmd_createbonded_device_socket,
5347                                 NULL
5348                 }
5349 };
5350
5351 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5352 struct cmd_set_bond_mac_addr_result {
5353         cmdline_fixed_string_t set;
5354         cmdline_fixed_string_t bonding;
5355         cmdline_fixed_string_t mac_addr;
5356         uint16_t port_num;
5357         struct ether_addr address;
5358 };
5359
5360 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5361                 __attribute__((unused))  struct cmdline *cl,
5362                 __attribute__((unused)) void *data)
5363 {
5364         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5365         int ret;
5366
5367         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5368                 return;
5369
5370         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5371
5372         /* check the return value and print it if is < 0 */
5373         if (ret < 0)
5374                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5375 }
5376
5377 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5378                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5379 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5380                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5381                                 "bonding");
5382 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5383                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5384                                 "mac_addr");
5385 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5386                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5387                                 port_num, UINT16);
5388 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5389                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5390
5391 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5392                 .f = cmd_set_bond_mac_addr_parsed,
5393                 .data = (void *) 0,
5394                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5395                 .tokens = {
5396                                 (void *)&cmd_set_bond_mac_addr_set,
5397                                 (void *)&cmd_set_bond_mac_addr_bonding,
5398                                 (void *)&cmd_set_bond_mac_addr_mac,
5399                                 (void *)&cmd_set_bond_mac_addr_portnum,
5400                                 (void *)&cmd_set_bond_mac_addr_addr,
5401                                 NULL
5402                 }
5403 };
5404
5405
5406 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5407 struct cmd_set_bond_mon_period_result {
5408         cmdline_fixed_string_t set;
5409         cmdline_fixed_string_t bonding;
5410         cmdline_fixed_string_t mon_period;
5411         uint16_t port_num;
5412         uint32_t period_ms;
5413 };
5414
5415 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5416                 __attribute__((unused))  struct cmdline *cl,
5417                 __attribute__((unused)) void *data)
5418 {
5419         struct cmd_set_bond_mon_period_result *res = parsed_result;
5420         int ret;
5421
5422         if (res->port_num >= nb_ports) {
5423                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5424                 return;
5425         }
5426
5427         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5428
5429         /* check the return value and print it if is < 0 */
5430         if (ret < 0)
5431                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5432 }
5433
5434 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5435                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5436                                 set, "set");
5437 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5438                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5439                                 bonding, "bonding");
5440 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5441                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5442                                 mon_period,     "mon_period");
5443 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5444                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5445                                 port_num, UINT16);
5446 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5447                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5448                                 period_ms, UINT32);
5449
5450 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5451                 .f = cmd_set_bond_mon_period_parsed,
5452                 .data = (void *) 0,
5453                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5454                 .tokens = {
5455                                 (void *)&cmd_set_bond_mon_period_set,
5456                                 (void *)&cmd_set_bond_mon_period_bonding,
5457                                 (void *)&cmd_set_bond_mon_period_mon_period,
5458                                 (void *)&cmd_set_bond_mon_period_portnum,
5459                                 (void *)&cmd_set_bond_mon_period_period_ms,
5460                                 NULL
5461                 }
5462 };
5463
5464
5465
5466 struct cmd_set_bonding_agg_mode_policy_result {
5467         cmdline_fixed_string_t set;
5468         cmdline_fixed_string_t bonding;
5469         cmdline_fixed_string_t agg_mode;
5470         uint16_t port_num;
5471         cmdline_fixed_string_t policy;
5472 };
5473
5474
5475 static void
5476 cmd_set_bonding_agg_mode(void *parsed_result,
5477                 __attribute__((unused)) struct cmdline *cl,
5478                 __attribute__((unused)) void *data)
5479 {
5480         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5481         uint8_t policy = AGG_BANDWIDTH;
5482
5483         if (res->port_num >= nb_ports) {
5484                 printf("Port id %d must be less than %d\n",
5485                                 res->port_num, nb_ports);
5486                 return;
5487         }
5488
5489         if (!strcmp(res->policy, "bandwidth"))
5490                 policy = AGG_BANDWIDTH;
5491         else if (!strcmp(res->policy, "stable"))
5492                 policy = AGG_STABLE;
5493         else if (!strcmp(res->policy, "count"))
5494                 policy = AGG_COUNT;
5495
5496         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5497 }
5498
5499
5500 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5501         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5502                                 set, "set");
5503 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5504         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5505                                 bonding, "bonding");
5506
5507 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5508         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5509                                 agg_mode, "agg_mode");
5510
5511 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5512         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5513                                 port_num, UINT16);
5514
5515 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5516         TOKEN_STRING_INITIALIZER(
5517                         struct cmd_set_bonding_balance_xmit_policy_result,
5518                 policy, "stable#bandwidth#count");
5519
5520 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5521         .f = cmd_set_bonding_agg_mode,
5522         .data = (void *) 0,
5523         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5524         .tokens = {
5525                         (void *)&cmd_set_bonding_agg_mode_set,
5526                         (void *)&cmd_set_bonding_agg_mode_bonding,
5527                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5528                         (void *)&cmd_set_bonding_agg_mode_portnum,
5529                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5530                         NULL
5531                 }
5532 };
5533
5534
5535 #endif /* RTE_LIBRTE_PMD_BOND */
5536
5537 /* *** SET FORWARDING MODE *** */
5538 struct cmd_set_fwd_mode_result {
5539         cmdline_fixed_string_t set;
5540         cmdline_fixed_string_t fwd;
5541         cmdline_fixed_string_t mode;
5542 };
5543
5544 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5545                                     __attribute__((unused)) struct cmdline *cl,
5546                                     __attribute__((unused)) void *data)
5547 {
5548         struct cmd_set_fwd_mode_result *res = parsed_result;
5549
5550         retry_enabled = 0;
5551         set_pkt_forwarding_mode(res->mode);
5552 }
5553
5554 cmdline_parse_token_string_t cmd_setfwd_set =
5555         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5556 cmdline_parse_token_string_t cmd_setfwd_fwd =
5557         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5558 cmdline_parse_token_string_t cmd_setfwd_mode =
5559         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5560                 "" /* defined at init */);
5561
5562 cmdline_parse_inst_t cmd_set_fwd_mode = {
5563         .f = cmd_set_fwd_mode_parsed,
5564         .data = NULL,
5565         .help_str = NULL, /* defined at init */
5566         .tokens = {
5567                 (void *)&cmd_setfwd_set,
5568                 (void *)&cmd_setfwd_fwd,
5569                 (void *)&cmd_setfwd_mode,
5570                 NULL,
5571         },
5572 };
5573
5574 static void cmd_set_fwd_mode_init(void)
5575 {
5576         char *modes, *c;
5577         static char token[128];
5578         static char help[256];
5579         cmdline_parse_token_string_t *token_struct;
5580
5581         modes = list_pkt_forwarding_modes();
5582         snprintf(help, sizeof(help), "set fwd %s: "
5583                 "Set packet forwarding mode", modes);
5584         cmd_set_fwd_mode.help_str = help;
5585
5586         /* string token separator is # */
5587         for (c = token; *modes != '\0'; modes++)
5588                 if (*modes == '|')
5589                         *c++ = '#';
5590                 else
5591                         *c++ = *modes;
5592         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5593         token_struct->string_data.str = token;
5594 }
5595
5596 /* *** SET RETRY FORWARDING MODE *** */
5597 struct cmd_set_fwd_retry_mode_result {
5598         cmdline_fixed_string_t set;
5599         cmdline_fixed_string_t fwd;
5600         cmdline_fixed_string_t mode;
5601         cmdline_fixed_string_t retry;
5602 };
5603
5604 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5605                             __attribute__((unused)) struct cmdline *cl,
5606                             __attribute__((unused)) void *data)
5607 {
5608         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5609
5610         retry_enabled = 1;
5611         set_pkt_forwarding_mode(res->mode);
5612 }
5613
5614 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5615         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5616                         set, "set");
5617 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5618         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5619                         fwd, "fwd");
5620 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5621         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5622                         mode,
5623                 "" /* defined at init */);
5624 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5625         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5626                         retry, "retry");
5627
5628 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5629         .f = cmd_set_fwd_retry_mode_parsed,
5630         .data = NULL,
5631         .help_str = NULL, /* defined at init */
5632         .tokens = {
5633                 (void *)&cmd_setfwd_retry_set,
5634                 (void *)&cmd_setfwd_retry_fwd,
5635                 (void *)&cmd_setfwd_retry_mode,
5636                 (void *)&cmd_setfwd_retry_retry,
5637                 NULL,
5638         },
5639 };
5640
5641 static void cmd_set_fwd_retry_mode_init(void)
5642 {
5643         char *modes, *c;
5644         static char token[128];
5645         static char help[256];
5646         cmdline_parse_token_string_t *token_struct;
5647
5648         modes = list_pkt_forwarding_retry_modes();
5649         snprintf(help, sizeof(help), "set fwd %s retry: "
5650                 "Set packet forwarding mode with retry", modes);
5651         cmd_set_fwd_retry_mode.help_str = help;
5652
5653         /* string token separator is # */
5654         for (c = token; *modes != '\0'; modes++)
5655                 if (*modes == '|')
5656                         *c++ = '#';
5657                 else
5658                         *c++ = *modes;
5659         token_struct = (cmdline_parse_token_string_t *)
5660                 cmd_set_fwd_retry_mode.tokens[2];
5661         token_struct->string_data.str = token;
5662 }
5663
5664 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5665 struct cmd_set_burst_tx_retry_result {
5666         cmdline_fixed_string_t set;
5667         cmdline_fixed_string_t burst;
5668         cmdline_fixed_string_t tx;
5669         cmdline_fixed_string_t delay;
5670         uint32_t time;
5671         cmdline_fixed_string_t retry;
5672         uint32_t retry_num;
5673 };
5674
5675 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5676                                         __attribute__((unused)) struct cmdline *cl,
5677                                         __attribute__((unused)) void *data)
5678 {
5679         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5680
5681         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5682                 && !strcmp(res->tx, "tx")) {
5683                 if (!strcmp(res->delay, "delay"))
5684                         burst_tx_delay_time = res->time;
5685                 if (!strcmp(res->retry, "retry"))
5686                         burst_tx_retry_num = res->retry_num;
5687         }
5688
5689 }
5690
5691 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5692         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5693 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5694         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5695                                  "burst");
5696 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5697         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5698 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5699         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5700 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5701         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5702 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5703         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5704 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5705         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5706
5707 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5708         .f = cmd_set_burst_tx_retry_parsed,
5709         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5710         .tokens = {
5711                 (void *)&cmd_set_burst_tx_retry_set,
5712                 (void *)&cmd_set_burst_tx_retry_burst,
5713                 (void *)&cmd_set_burst_tx_retry_tx,
5714                 (void *)&cmd_set_burst_tx_retry_delay,
5715                 (void *)&cmd_set_burst_tx_retry_time,
5716                 (void *)&cmd_set_burst_tx_retry_retry,
5717                 (void *)&cmd_set_burst_tx_retry_retry_num,
5718                 NULL,
5719         },
5720 };
5721
5722 /* *** SET PROMISC MODE *** */
5723 struct cmd_set_promisc_mode_result {
5724         cmdline_fixed_string_t set;
5725         cmdline_fixed_string_t promisc;
5726         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5727         uint16_t port_num;               /* valid if "allports" argument == 0 */
5728         cmdline_fixed_string_t mode;
5729 };
5730
5731 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5732                                         __attribute__((unused)) struct cmdline *cl,
5733                                         void *allports)
5734 {
5735         struct cmd_set_promisc_mode_result *res = parsed_result;
5736         int enable;
5737         portid_t i;
5738
5739         if (!strcmp(res->mode, "on"))
5740                 enable = 1;
5741         else
5742                 enable = 0;
5743
5744         /* all ports */
5745         if (allports) {
5746                 RTE_ETH_FOREACH_DEV(i) {
5747                         if (enable)
5748                                 rte_eth_promiscuous_enable(i);
5749                         else
5750                                 rte_eth_promiscuous_disable(i);
5751                 }
5752         }
5753         else {
5754                 if (enable)
5755                         rte_eth_promiscuous_enable(res->port_num);
5756                 else
5757                         rte_eth_promiscuous_disable(res->port_num);
5758         }
5759 }
5760
5761 cmdline_parse_token_string_t cmd_setpromisc_set =
5762         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5763 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5764         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5765                                  "promisc");
5766 cmdline_parse_token_string_t cmd_setpromisc_portall =
5767         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5768                                  "all");
5769 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5770         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5771                               UINT8);
5772 cmdline_parse_token_string_t cmd_setpromisc_mode =
5773         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5774                                  "on#off");
5775
5776 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5777         .f = cmd_set_promisc_mode_parsed,
5778         .data = (void *)1,
5779         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5780         .tokens = {
5781                 (void *)&cmd_setpromisc_set,
5782                 (void *)&cmd_setpromisc_promisc,
5783                 (void *)&cmd_setpromisc_portall,
5784                 (void *)&cmd_setpromisc_mode,
5785                 NULL,
5786         },
5787 };
5788
5789 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5790         .f = cmd_set_promisc_mode_parsed,
5791         .data = (void *)0,
5792         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5793         .tokens = {
5794                 (void *)&cmd_setpromisc_set,
5795                 (void *)&cmd_setpromisc_promisc,
5796                 (void *)&cmd_setpromisc_portnum,
5797                 (void *)&cmd_setpromisc_mode,
5798                 NULL,
5799         },
5800 };
5801
5802 /* *** SET ALLMULTI MODE *** */
5803 struct cmd_set_allmulti_mode_result {
5804         cmdline_fixed_string_t set;
5805         cmdline_fixed_string_t allmulti;
5806         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5807         uint16_t port_num;               /* valid if "allports" argument == 0 */
5808         cmdline_fixed_string_t mode;
5809 };
5810
5811 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5812                                         __attribute__((unused)) struct cmdline *cl,
5813                                         void *allports)
5814 {
5815         struct cmd_set_allmulti_mode_result *res = parsed_result;
5816         int enable;
5817         portid_t i;
5818
5819         if (!strcmp(res->mode, "on"))
5820                 enable = 1;
5821         else
5822                 enable = 0;
5823
5824         /* all ports */
5825         if (allports) {
5826                 RTE_ETH_FOREACH_DEV(i) {
5827                         if (enable)
5828                                 rte_eth_allmulticast_enable(i);
5829                         else
5830                                 rte_eth_allmulticast_disable(i);
5831                 }
5832         }
5833         else {
5834                 if (enable)
5835                         rte_eth_allmulticast_enable(res->port_num);
5836                 else
5837                         rte_eth_allmulticast_disable(res->port_num);
5838         }
5839 }
5840
5841 cmdline_parse_token_string_t cmd_setallmulti_set =
5842         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5843 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5844         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5845                                  "allmulti");
5846 cmdline_parse_token_string_t cmd_setallmulti_portall =
5847         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5848                                  "all");
5849 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5850         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5851                               UINT16);
5852 cmdline_parse_token_string_t cmd_setallmulti_mode =
5853         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5854                                  "on#off");
5855
5856 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5857         .f = cmd_set_allmulti_mode_parsed,
5858         .data = (void *)1,
5859         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5860         .tokens = {
5861                 (void *)&cmd_setallmulti_set,
5862                 (void *)&cmd_setallmulti_allmulti,
5863                 (void *)&cmd_setallmulti_portall,
5864                 (void *)&cmd_setallmulti_mode,
5865                 NULL,
5866         },
5867 };
5868
5869 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5870         .f = cmd_set_allmulti_mode_parsed,
5871         .data = (void *)0,
5872         .help_str = "set allmulti <port_id> on|off: "
5873                 "Set allmulti mode on port_id",
5874         .tokens = {
5875                 (void *)&cmd_setallmulti_set,
5876                 (void *)&cmd_setallmulti_allmulti,
5877                 (void *)&cmd_setallmulti_portnum,
5878                 (void *)&cmd_setallmulti_mode,
5879                 NULL,
5880         },
5881 };
5882
5883 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5884 struct cmd_link_flow_ctrl_set_result {
5885         cmdline_fixed_string_t set;
5886         cmdline_fixed_string_t flow_ctrl;
5887         cmdline_fixed_string_t rx;
5888         cmdline_fixed_string_t rx_lfc_mode;
5889         cmdline_fixed_string_t tx;
5890         cmdline_fixed_string_t tx_lfc_mode;
5891         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5892         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5893         cmdline_fixed_string_t autoneg_str;
5894         cmdline_fixed_string_t autoneg;
5895         cmdline_fixed_string_t hw_str;
5896         uint32_t high_water;
5897         cmdline_fixed_string_t lw_str;
5898         uint32_t low_water;
5899         cmdline_fixed_string_t pt_str;
5900         uint16_t pause_time;
5901         cmdline_fixed_string_t xon_str;
5902         uint16_t send_xon;
5903         portid_t port_id;
5904 };
5905
5906 cmdline_parse_token_string_t cmd_lfc_set_set =
5907         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5908                                 set, "set");
5909 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5910         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5911                                 flow_ctrl, "flow_ctrl");
5912 cmdline_parse_token_string_t cmd_lfc_set_rx =
5913         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5914                                 rx, "rx");
5915 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5916         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5917                                 rx_lfc_mode, "on#off");
5918 cmdline_parse_token_string_t cmd_lfc_set_tx =
5919         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5920                                 tx, "tx");
5921 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5922         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5923                                 tx_lfc_mode, "on#off");
5924 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5925         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5926                                 hw_str, "high_water");
5927 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5928         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5929                                 high_water, UINT32);
5930 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5931         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5932                                 lw_str, "low_water");
5933 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5934         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5935                                 low_water, UINT32);
5936 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5937         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5938                                 pt_str, "pause_time");
5939 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5940         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5941                                 pause_time, UINT16);
5942 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5943         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5944                                 xon_str, "send_xon");
5945 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5946         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5947                                 send_xon, UINT16);
5948 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5949         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5950                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5951 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5952         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5953                                 mac_ctrl_frame_fwd_mode, "on#off");
5954 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5955         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5956                                 autoneg_str, "autoneg");
5957 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5958         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5959                                 autoneg, "on#off");
5960 cmdline_parse_token_num_t cmd_lfc_set_portid =
5961         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5962                                 port_id, UINT16);
5963
5964 /* forward declaration */
5965 static void
5966 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5967                               void *data);
5968
5969 cmdline_parse_inst_t cmd_link_flow_control_set = {
5970         .f = cmd_link_flow_ctrl_set_parsed,
5971         .data = NULL,
5972         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5973                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5974                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5975         .tokens = {
5976                 (void *)&cmd_lfc_set_set,
5977                 (void *)&cmd_lfc_set_flow_ctrl,
5978                 (void *)&cmd_lfc_set_rx,
5979                 (void *)&cmd_lfc_set_rx_mode,
5980                 (void *)&cmd_lfc_set_tx,
5981                 (void *)&cmd_lfc_set_tx_mode,
5982                 (void *)&cmd_lfc_set_high_water,
5983                 (void *)&cmd_lfc_set_low_water,
5984                 (void *)&cmd_lfc_set_pause_time,
5985                 (void *)&cmd_lfc_set_send_xon,
5986                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5987                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5988                 (void *)&cmd_lfc_set_autoneg_str,
5989                 (void *)&cmd_lfc_set_autoneg,
5990                 (void *)&cmd_lfc_set_portid,
5991                 NULL,
5992         },
5993 };
5994
5995 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5996         .f = cmd_link_flow_ctrl_set_parsed,
5997         .data = (void *)&cmd_link_flow_control_set_rx,
5998         .help_str = "set flow_ctrl rx on|off <port_id>: "
5999                 "Change rx flow control parameter",
6000         .tokens = {
6001                 (void *)&cmd_lfc_set_set,
6002                 (void *)&cmd_lfc_set_flow_ctrl,
6003                 (void *)&cmd_lfc_set_rx,
6004                 (void *)&cmd_lfc_set_rx_mode,
6005                 (void *)&cmd_lfc_set_portid,
6006                 NULL,
6007         },
6008 };
6009
6010 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
6011         .f = cmd_link_flow_ctrl_set_parsed,
6012         .data = (void *)&cmd_link_flow_control_set_tx,
6013         .help_str = "set flow_ctrl tx on|off <port_id>: "
6014                 "Change tx flow control parameter",
6015         .tokens = {
6016                 (void *)&cmd_lfc_set_set,
6017                 (void *)&cmd_lfc_set_flow_ctrl,
6018                 (void *)&cmd_lfc_set_tx,
6019                 (void *)&cmd_lfc_set_tx_mode,
6020                 (void *)&cmd_lfc_set_portid,
6021                 NULL,
6022         },
6023 };
6024
6025 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6026         .f = cmd_link_flow_ctrl_set_parsed,
6027         .data = (void *)&cmd_link_flow_control_set_hw,
6028         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6029                 "Change high water flow control parameter",
6030         .tokens = {
6031                 (void *)&cmd_lfc_set_set,
6032                 (void *)&cmd_lfc_set_flow_ctrl,
6033                 (void *)&cmd_lfc_set_high_water_str,
6034                 (void *)&cmd_lfc_set_high_water,
6035                 (void *)&cmd_lfc_set_portid,
6036                 NULL,
6037         },
6038 };
6039
6040 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6041         .f = cmd_link_flow_ctrl_set_parsed,
6042         .data = (void *)&cmd_link_flow_control_set_lw,
6043         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6044                 "Change low water flow control parameter",
6045         .tokens = {
6046                 (void *)&cmd_lfc_set_set,
6047                 (void *)&cmd_lfc_set_flow_ctrl,
6048                 (void *)&cmd_lfc_set_low_water_str,
6049                 (void *)&cmd_lfc_set_low_water,
6050                 (void *)&cmd_lfc_set_portid,
6051                 NULL,
6052         },
6053 };
6054
6055 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6056         .f = cmd_link_flow_ctrl_set_parsed,
6057         .data = (void *)&cmd_link_flow_control_set_pt,
6058         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6059                 "Change pause time flow control parameter",
6060         .tokens = {
6061                 (void *)&cmd_lfc_set_set,
6062                 (void *)&cmd_lfc_set_flow_ctrl,
6063                 (void *)&cmd_lfc_set_pause_time_str,
6064                 (void *)&cmd_lfc_set_pause_time,
6065                 (void *)&cmd_lfc_set_portid,
6066                 NULL,
6067         },
6068 };
6069
6070 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6071         .f = cmd_link_flow_ctrl_set_parsed,
6072         .data = (void *)&cmd_link_flow_control_set_xon,
6073         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6074                 "Change send_xon flow control parameter",
6075         .tokens = {
6076                 (void *)&cmd_lfc_set_set,
6077                 (void *)&cmd_lfc_set_flow_ctrl,
6078                 (void *)&cmd_lfc_set_send_xon_str,
6079                 (void *)&cmd_lfc_set_send_xon,
6080                 (void *)&cmd_lfc_set_portid,
6081                 NULL,
6082         },
6083 };
6084
6085 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6086         .f = cmd_link_flow_ctrl_set_parsed,
6087         .data = (void *)&cmd_link_flow_control_set_macfwd,
6088         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6089                 "Change mac ctrl fwd flow control parameter",
6090         .tokens = {
6091                 (void *)&cmd_lfc_set_set,
6092                 (void *)&cmd_lfc_set_flow_ctrl,
6093                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6094                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6095                 (void *)&cmd_lfc_set_portid,
6096                 NULL,
6097         },
6098 };
6099
6100 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6101         .f = cmd_link_flow_ctrl_set_parsed,
6102         .data = (void *)&cmd_link_flow_control_set_autoneg,
6103         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6104                 "Change autoneg flow control parameter",
6105         .tokens = {
6106                 (void *)&cmd_lfc_set_set,
6107                 (void *)&cmd_lfc_set_flow_ctrl,
6108                 (void *)&cmd_lfc_set_autoneg_str,
6109                 (void *)&cmd_lfc_set_autoneg,
6110                 (void *)&cmd_lfc_set_portid,
6111                 NULL,
6112         },
6113 };
6114
6115 static void
6116 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6117                               __attribute__((unused)) struct cmdline *cl,
6118                               void *data)
6119 {
6120         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6121         cmdline_parse_inst_t *cmd = data;
6122         struct rte_eth_fc_conf fc_conf;
6123         int rx_fc_en = 0;
6124         int tx_fc_en = 0;
6125         int ret;
6126
6127         /*
6128          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6129          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6130          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6131          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6132          */
6133         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6134                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6135         };
6136
6137         /* Partial command line, retrieve current configuration */
6138         if (cmd) {
6139                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6140                 if (ret != 0) {
6141                         printf("cannot get current flow ctrl parameters, return"
6142                                "code = %d\n", ret);
6143                         return;
6144                 }
6145
6146                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6147                     (fc_conf.mode == RTE_FC_FULL))
6148                         rx_fc_en = 1;
6149                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6150                     (fc_conf.mode == RTE_FC_FULL))
6151                         tx_fc_en = 1;
6152         }
6153
6154         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6155                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6156
6157         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6158                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6159
6160         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6161
6162         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6163                 fc_conf.high_water = res->high_water;
6164
6165         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6166                 fc_conf.low_water = res->low_water;
6167
6168         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6169                 fc_conf.pause_time = res->pause_time;
6170
6171         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6172                 fc_conf.send_xon = res->send_xon;
6173
6174         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6175                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6176                         fc_conf.mac_ctrl_frame_fwd = 1;
6177                 else
6178                         fc_conf.mac_ctrl_frame_fwd = 0;
6179         }
6180
6181         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6182                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6183
6184         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6185         if (ret != 0)
6186                 printf("bad flow contrl parameter, return code = %d \n", ret);
6187 }
6188
6189 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6190 struct cmd_priority_flow_ctrl_set_result {
6191         cmdline_fixed_string_t set;
6192         cmdline_fixed_string_t pfc_ctrl;
6193         cmdline_fixed_string_t rx;
6194         cmdline_fixed_string_t rx_pfc_mode;
6195         cmdline_fixed_string_t tx;
6196         cmdline_fixed_string_t tx_pfc_mode;
6197         uint32_t high_water;
6198         uint32_t low_water;
6199         uint16_t pause_time;
6200         uint8_t  priority;
6201         portid_t port_id;
6202 };
6203
6204 static void
6205 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6206                        __attribute__((unused)) struct cmdline *cl,
6207                        __attribute__((unused)) void *data)
6208 {
6209         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6210         struct rte_eth_pfc_conf pfc_conf;
6211         int rx_fc_enable, tx_fc_enable;
6212         int ret;
6213
6214         /*
6215          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6216          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6217          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6218          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6219          */
6220         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6221                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6222         };
6223
6224         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6225         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6226         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6227         pfc_conf.fc.high_water = res->high_water;
6228         pfc_conf.fc.low_water  = res->low_water;
6229         pfc_conf.fc.pause_time = res->pause_time;
6230         pfc_conf.priority      = res->priority;
6231
6232         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6233         if (ret != 0)
6234                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6235 }
6236
6237 cmdline_parse_token_string_t cmd_pfc_set_set =
6238         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6239                                 set, "set");
6240 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6241         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6242                                 pfc_ctrl, "pfc_ctrl");
6243 cmdline_parse_token_string_t cmd_pfc_set_rx =
6244         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6245                                 rx, "rx");
6246 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6247         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6248                                 rx_pfc_mode, "on#off");
6249 cmdline_parse_token_string_t cmd_pfc_set_tx =
6250         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6251                                 tx, "tx");
6252 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6253         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6254                                 tx_pfc_mode, "on#off");
6255 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6256         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6257                                 high_water, UINT32);
6258 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6259         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6260                                 low_water, UINT32);
6261 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6262         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6263                                 pause_time, UINT16);
6264 cmdline_parse_token_num_t cmd_pfc_set_priority =
6265         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6266                                 priority, UINT8);
6267 cmdline_parse_token_num_t cmd_pfc_set_portid =
6268         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6269                                 port_id, UINT16);
6270
6271 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6272         .f = cmd_priority_flow_ctrl_set_parsed,
6273         .data = NULL,
6274         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6275                 "<pause_time> <priority> <port_id>: "
6276                 "Configure the Ethernet priority flow control",
6277         .tokens = {
6278                 (void *)&cmd_pfc_set_set,
6279                 (void *)&cmd_pfc_set_flow_ctrl,
6280                 (void *)&cmd_pfc_set_rx,
6281                 (void *)&cmd_pfc_set_rx_mode,
6282                 (void *)&cmd_pfc_set_tx,
6283                 (void *)&cmd_pfc_set_tx_mode,
6284                 (void *)&cmd_pfc_set_high_water,
6285                 (void *)&cmd_pfc_set_low_water,
6286                 (void *)&cmd_pfc_set_pause_time,
6287                 (void *)&cmd_pfc_set_priority,
6288                 (void *)&cmd_pfc_set_portid,
6289                 NULL,
6290         },
6291 };
6292
6293 /* *** RESET CONFIGURATION *** */
6294 struct cmd_reset_result {
6295         cmdline_fixed_string_t reset;
6296         cmdline_fixed_string_t def;
6297 };
6298
6299 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6300                              struct cmdline *cl,
6301                              __attribute__((unused)) void *data)
6302 {
6303         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6304         set_def_fwd_config();
6305 }
6306
6307 cmdline_parse_token_string_t cmd_reset_set =
6308         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6309 cmdline_parse_token_string_t cmd_reset_def =
6310         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6311                                  "default");
6312
6313 cmdline_parse_inst_t cmd_reset = {
6314         .f = cmd_reset_parsed,
6315         .data = NULL,
6316         .help_str = "set default: Reset default forwarding configuration",
6317         .tokens = {
6318                 (void *)&cmd_reset_set,
6319                 (void *)&cmd_reset_def,
6320                 NULL,
6321         },
6322 };
6323
6324 /* *** START FORWARDING *** */
6325 struct cmd_start_result {
6326         cmdline_fixed_string_t start;
6327 };
6328
6329 cmdline_parse_token_string_t cmd_start_start =
6330         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6331
6332 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6333                              __attribute__((unused)) struct cmdline *cl,
6334                              __attribute__((unused)) void *data)
6335 {
6336         start_packet_forwarding(0);
6337 }
6338
6339 cmdline_parse_inst_t cmd_start = {
6340         .f = cmd_start_parsed,
6341         .data = NULL,
6342         .help_str = "start: Start packet forwarding",
6343         .tokens = {
6344                 (void *)&cmd_start_start,
6345                 NULL,
6346         },
6347 };
6348
6349 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6350 struct cmd_start_tx_first_result {
6351         cmdline_fixed_string_t start;
6352         cmdline_fixed_string_t tx_first;
6353 };
6354
6355 static void
6356 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6357                           __attribute__((unused)) struct cmdline *cl,
6358                           __attribute__((unused)) void *data)
6359 {
6360         start_packet_forwarding(1);
6361 }
6362
6363 cmdline_parse_token_string_t cmd_start_tx_first_start =
6364         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6365                                  "start");
6366 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6367         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6368                                  tx_first, "tx_first");
6369
6370 cmdline_parse_inst_t cmd_start_tx_first = {
6371         .f = cmd_start_tx_first_parsed,
6372         .data = NULL,
6373         .help_str = "start tx_first: Start packet forwarding, "
6374                 "after sending 1 burst of packets",
6375         .tokens = {
6376                 (void *)&cmd_start_tx_first_start,
6377                 (void *)&cmd_start_tx_first_tx_first,
6378                 NULL,
6379         },
6380 };
6381
6382 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6383 struct cmd_start_tx_first_n_result {
6384         cmdline_fixed_string_t start;
6385         cmdline_fixed_string_t tx_first;
6386         uint32_t tx_num;
6387 };
6388
6389 static void
6390 cmd_start_tx_first_n_parsed(void *parsed_result,
6391                           __attribute__((unused)) struct cmdline *cl,
6392                           __attribute__((unused)) void *data)
6393 {
6394         struct cmd_start_tx_first_n_result *res = parsed_result;
6395
6396         start_packet_forwarding(res->tx_num);
6397 }
6398
6399 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6400         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6401                         start, "start");
6402 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6403         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6404                         tx_first, "tx_first");
6405 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6406         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6407                         tx_num, UINT32);
6408
6409 cmdline_parse_inst_t cmd_start_tx_first_n = {
6410         .f = cmd_start_tx_first_n_parsed,
6411         .data = NULL,
6412         .help_str = "start tx_first <num>: "
6413                 "packet forwarding, after sending <num> bursts of packets",
6414         .tokens = {
6415                 (void *)&cmd_start_tx_first_n_start,
6416                 (void *)&cmd_start_tx_first_n_tx_first,
6417                 (void *)&cmd_start_tx_first_n_tx_num,
6418                 NULL,
6419         },
6420 };
6421
6422 /* *** SET LINK UP *** */
6423 struct cmd_set_link_up_result {
6424         cmdline_fixed_string_t set;
6425         cmdline_fixed_string_t link_up;
6426         cmdline_fixed_string_t port;
6427         portid_t port_id;
6428 };
6429
6430 cmdline_parse_token_string_t cmd_set_link_up_set =
6431         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6432 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6433         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6434                                 "link-up");
6435 cmdline_parse_token_string_t cmd_set_link_up_port =
6436         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6437 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6438         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6439
6440 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6441                              __attribute__((unused)) struct cmdline *cl,
6442                              __attribute__((unused)) void *data)
6443 {
6444         struct cmd_set_link_up_result *res = parsed_result;
6445         dev_set_link_up(res->port_id);
6446 }
6447
6448 cmdline_parse_inst_t cmd_set_link_up = {
6449         .f = cmd_set_link_up_parsed,
6450         .data = NULL,
6451         .help_str = "set link-up port <port id>",
6452         .tokens = {
6453                 (void *)&cmd_set_link_up_set,
6454                 (void *)&cmd_set_link_up_link_up,
6455                 (void *)&cmd_set_link_up_port,
6456                 (void *)&cmd_set_link_up_port_id,
6457                 NULL,
6458         },
6459 };
6460
6461 /* *** SET LINK DOWN *** */
6462 struct cmd_set_link_down_result {
6463         cmdline_fixed_string_t set;
6464         cmdline_fixed_string_t link_down;
6465         cmdline_fixed_string_t port;
6466         portid_t port_id;
6467 };
6468
6469 cmdline_parse_token_string_t cmd_set_link_down_set =
6470         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6471 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6472         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6473                                 "link-down");
6474 cmdline_parse_token_string_t cmd_set_link_down_port =
6475         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6476 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6477         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6478
6479 static void cmd_set_link_down_parsed(
6480                                 __attribute__((unused)) void *parsed_result,
6481                                 __attribute__((unused)) struct cmdline *cl,
6482                                 __attribute__((unused)) void *data)
6483 {
6484         struct cmd_set_link_down_result *res = parsed_result;
6485         dev_set_link_down(res->port_id);
6486 }
6487
6488 cmdline_parse_inst_t cmd_set_link_down = {
6489         .f = cmd_set_link_down_parsed,
6490         .data = NULL,
6491         .help_str = "set link-down port <port id>",
6492         .tokens = {
6493                 (void *)&cmd_set_link_down_set,
6494                 (void *)&cmd_set_link_down_link_down,
6495                 (void *)&cmd_set_link_down_port,
6496                 (void *)&cmd_set_link_down_port_id,
6497                 NULL,
6498         },
6499 };
6500
6501 /* *** SHOW CFG *** */
6502 struct cmd_showcfg_result {
6503         cmdline_fixed_string_t show;
6504         cmdline_fixed_string_t cfg;
6505         cmdline_fixed_string_t what;
6506 };
6507
6508 static void cmd_showcfg_parsed(void *parsed_result,
6509                                __attribute__((unused)) struct cmdline *cl,
6510                                __attribute__((unused)) void *data)
6511 {
6512         struct cmd_showcfg_result *res = parsed_result;
6513         if (!strcmp(res->what, "rxtx"))
6514                 rxtx_config_display();
6515         else if (!strcmp(res->what, "cores"))
6516                 fwd_lcores_config_display();
6517         else if (!strcmp(res->what, "fwd"))
6518                 pkt_fwd_config_display(&cur_fwd_config);
6519         else if (!strcmp(res->what, "txpkts"))
6520                 show_tx_pkt_segments();
6521 }
6522
6523 cmdline_parse_token_string_t cmd_showcfg_show =
6524         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6525 cmdline_parse_token_string_t cmd_showcfg_port =
6526         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6527 cmdline_parse_token_string_t cmd_showcfg_what =
6528         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6529                                  "rxtx#cores#fwd#txpkts");
6530
6531 cmdline_parse_inst_t cmd_showcfg = {
6532         .f = cmd_showcfg_parsed,
6533         .data = NULL,
6534         .help_str = "show config rxtx|cores|fwd|txpkts",
6535         .tokens = {
6536                 (void *)&cmd_showcfg_show,
6537                 (void *)&cmd_showcfg_port,
6538                 (void *)&cmd_showcfg_what,
6539                 NULL,
6540         },
6541 };
6542
6543 /* *** SHOW ALL PORT INFO *** */
6544 struct cmd_showportall_result {
6545         cmdline_fixed_string_t show;
6546         cmdline_fixed_string_t port;
6547         cmdline_fixed_string_t what;
6548         cmdline_fixed_string_t all;
6549 };
6550
6551 static void cmd_showportall_parsed(void *parsed_result,
6552                                 __attribute__((unused)) struct cmdline *cl,
6553                                 __attribute__((unused)) void *data)
6554 {
6555         portid_t i;
6556
6557         struct cmd_showportall_result *res = parsed_result;
6558         if (!strcmp(res->show, "clear")) {
6559                 if (!strcmp(res->what, "stats"))
6560                         RTE_ETH_FOREACH_DEV(i)
6561                                 nic_stats_clear(i);
6562                 else if (!strcmp(res->what, "xstats"))
6563                         RTE_ETH_FOREACH_DEV(i)
6564                                 nic_xstats_clear(i);
6565         } else if (!strcmp(res->what, "info"))
6566                 RTE_ETH_FOREACH_DEV(i)
6567                         port_infos_display(i);
6568         else if (!strcmp(res->what, "stats"))
6569                 RTE_ETH_FOREACH_DEV(i)
6570                         nic_stats_display(i);
6571         else if (!strcmp(res->what, "xstats"))
6572                 RTE_ETH_FOREACH_DEV(i)
6573                         nic_xstats_display(i);
6574         else if (!strcmp(res->what, "fdir"))
6575                 RTE_ETH_FOREACH_DEV(i)
6576                         fdir_get_infos(i);
6577         else if (!strcmp(res->what, "stat_qmap"))
6578                 RTE_ETH_FOREACH_DEV(i)
6579                         nic_stats_mapping_display(i);
6580         else if (!strcmp(res->what, "dcb_tc"))
6581                 RTE_ETH_FOREACH_DEV(i)
6582                         port_dcb_info_display(i);
6583         else if (!strcmp(res->what, "cap"))
6584                 RTE_ETH_FOREACH_DEV(i)
6585                         port_offload_cap_display(i);
6586 }
6587
6588 cmdline_parse_token_string_t cmd_showportall_show =
6589         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6590                                  "show#clear");
6591 cmdline_parse_token_string_t cmd_showportall_port =
6592         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6593 cmdline_parse_token_string_t cmd_showportall_what =
6594         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6595                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6596 cmdline_parse_token_string_t cmd_showportall_all =
6597         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6598 cmdline_parse_inst_t cmd_showportall = {
6599         .f = cmd_showportall_parsed,
6600         .data = NULL,
6601         .help_str = "show|clear port "
6602                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6603         .tokens = {
6604                 (void *)&cmd_showportall_show,
6605                 (void *)&cmd_showportall_port,
6606                 (void *)&cmd_showportall_what,
6607                 (void *)&cmd_showportall_all,
6608                 NULL,
6609         },
6610 };
6611
6612 /* *** SHOW PORT INFO *** */
6613 struct cmd_showport_result {
6614         cmdline_fixed_string_t show;
6615         cmdline_fixed_string_t port;
6616         cmdline_fixed_string_t what;
6617         uint16_t portnum;
6618 };
6619
6620 static void cmd_showport_parsed(void *parsed_result,
6621                                 __attribute__((unused)) struct cmdline *cl,
6622                                 __attribute__((unused)) void *data)
6623 {
6624         struct cmd_showport_result *res = parsed_result;
6625         if (!strcmp(res->show, "clear")) {
6626                 if (!strcmp(res->what, "stats"))
6627                         nic_stats_clear(res->portnum);
6628                 else if (!strcmp(res->what, "xstats"))
6629                         nic_xstats_clear(res->portnum);
6630         } else if (!strcmp(res->what, "info"))
6631                 port_infos_display(res->portnum);
6632         else if (!strcmp(res->what, "stats"))
6633                 nic_stats_display(res->portnum);
6634         else if (!strcmp(res->what, "xstats"))
6635                 nic_xstats_display(res->portnum);
6636         else if (!strcmp(res->what, "fdir"))
6637                  fdir_get_infos(res->portnum);
6638         else if (!strcmp(res->what, "stat_qmap"))
6639                 nic_stats_mapping_display(res->portnum);
6640         else if (!strcmp(res->what, "dcb_tc"))
6641                 port_dcb_info_display(res->portnum);
6642         else if (!strcmp(res->what, "cap"))
6643                 port_offload_cap_display(res->portnum);
6644 }
6645
6646 cmdline_parse_token_string_t cmd_showport_show =
6647         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6648                                  "show#clear");
6649 cmdline_parse_token_string_t cmd_showport_port =
6650         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6651 cmdline_parse_token_string_t cmd_showport_what =
6652         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6653                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6654 cmdline_parse_token_num_t cmd_showport_portnum =
6655         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6656
6657 cmdline_parse_inst_t cmd_showport = {
6658         .f = cmd_showport_parsed,
6659         .data = NULL,
6660         .help_str = "show|clear port "
6661                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6662                 "<port_id>",
6663         .tokens = {
6664                 (void *)&cmd_showport_show,
6665                 (void *)&cmd_showport_port,
6666                 (void *)&cmd_showport_what,
6667                 (void *)&cmd_showport_portnum,
6668                 NULL,
6669         },
6670 };
6671
6672 /* *** SHOW QUEUE INFO *** */
6673 struct cmd_showqueue_result {
6674         cmdline_fixed_string_t show;
6675         cmdline_fixed_string_t type;
6676         cmdline_fixed_string_t what;
6677         uint16_t portnum;
6678         uint16_t queuenum;
6679 };
6680
6681 static void
6682 cmd_showqueue_parsed(void *parsed_result,
6683         __attribute__((unused)) struct cmdline *cl,
6684         __attribute__((unused)) void *data)
6685 {
6686         struct cmd_showqueue_result *res = parsed_result;
6687
6688         if (!strcmp(res->type, "rxq"))
6689                 rx_queue_infos_display(res->portnum, res->queuenum);
6690         else if (!strcmp(res->type, "txq"))
6691                 tx_queue_infos_display(res->portnum, res->queuenum);
6692 }
6693
6694 cmdline_parse_token_string_t cmd_showqueue_show =
6695         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6696 cmdline_parse_token_string_t cmd_showqueue_type =
6697         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6698 cmdline_parse_token_string_t cmd_showqueue_what =
6699         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6700 cmdline_parse_token_num_t cmd_showqueue_portnum =
6701         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6702 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6703         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6704
6705 cmdline_parse_inst_t cmd_showqueue = {
6706         .f = cmd_showqueue_parsed,
6707         .data = NULL,
6708         .help_str = "show rxq|txq info <port_id> <queue_id>",
6709         .tokens = {
6710                 (void *)&cmd_showqueue_show,
6711                 (void *)&cmd_showqueue_type,
6712                 (void *)&cmd_showqueue_what,
6713                 (void *)&cmd_showqueue_portnum,
6714                 (void *)&cmd_showqueue_queuenum,
6715                 NULL,
6716         },
6717 };
6718
6719 /* *** READ PORT REGISTER *** */
6720 struct cmd_read_reg_result {
6721         cmdline_fixed_string_t read;
6722         cmdline_fixed_string_t reg;
6723         portid_t port_id;
6724         uint32_t reg_off;
6725 };
6726
6727 static void
6728 cmd_read_reg_parsed(void *parsed_result,
6729                     __attribute__((unused)) struct cmdline *cl,
6730                     __attribute__((unused)) void *data)
6731 {
6732         struct cmd_read_reg_result *res = parsed_result;
6733         port_reg_display(res->port_id, res->reg_off);
6734 }
6735
6736 cmdline_parse_token_string_t cmd_read_reg_read =
6737         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6738 cmdline_parse_token_string_t cmd_read_reg_reg =
6739         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6740 cmdline_parse_token_num_t cmd_read_reg_port_id =
6741         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6742 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6743         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6744
6745 cmdline_parse_inst_t cmd_read_reg = {
6746         .f = cmd_read_reg_parsed,
6747         .data = NULL,
6748         .help_str = "read reg <port_id> <reg_off>",
6749         .tokens = {
6750                 (void *)&cmd_read_reg_read,
6751                 (void *)&cmd_read_reg_reg,
6752                 (void *)&cmd_read_reg_port_id,
6753                 (void *)&cmd_read_reg_reg_off,
6754                 NULL,
6755         },
6756 };
6757
6758 /* *** READ PORT REGISTER BIT FIELD *** */
6759 struct cmd_read_reg_bit_field_result {
6760         cmdline_fixed_string_t read;
6761         cmdline_fixed_string_t regfield;
6762         portid_t port_id;
6763         uint32_t reg_off;
6764         uint8_t bit1_pos;
6765         uint8_t bit2_pos;
6766 };
6767
6768 static void
6769 cmd_read_reg_bit_field_parsed(void *parsed_result,
6770                               __attribute__((unused)) struct cmdline *cl,
6771                               __attribute__((unused)) void *data)
6772 {
6773         struct cmd_read_reg_bit_field_result *res = parsed_result;
6774         port_reg_bit_field_display(res->port_id, res->reg_off,
6775                                    res->bit1_pos, res->bit2_pos);
6776 }
6777
6778 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6779         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6780                                  "read");
6781 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6782         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6783                                  regfield, "regfield");
6784 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6785         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6786                               UINT16);
6787 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6788         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6789                               UINT32);
6790 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6791         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6792                               UINT8);
6793 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6794         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6795                               UINT8);
6796
6797 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6798         .f = cmd_read_reg_bit_field_parsed,
6799         .data = NULL,
6800         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6801         "Read register bit field between bit_x and bit_y included",
6802         .tokens = {
6803                 (void *)&cmd_read_reg_bit_field_read,
6804                 (void *)&cmd_read_reg_bit_field_regfield,
6805                 (void *)&cmd_read_reg_bit_field_port_id,
6806                 (void *)&cmd_read_reg_bit_field_reg_off,
6807                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6808                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6809                 NULL,
6810         },
6811 };
6812
6813 /* *** READ PORT REGISTER BIT *** */
6814 struct cmd_read_reg_bit_result {
6815         cmdline_fixed_string_t read;
6816         cmdline_fixed_string_t regbit;
6817         portid_t port_id;
6818         uint32_t reg_off;
6819         uint8_t bit_pos;
6820 };
6821
6822 static void
6823 cmd_read_reg_bit_parsed(void *parsed_result,
6824                         __attribute__((unused)) struct cmdline *cl,
6825                         __attribute__((unused)) void *data)
6826 {
6827         struct cmd_read_reg_bit_result *res = parsed_result;
6828         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6829 }
6830
6831 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6832         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6833 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6834         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6835                                  regbit, "regbit");
6836 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6837         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6838 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6839         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6840 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6841         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6842
6843 cmdline_parse_inst_t cmd_read_reg_bit = {
6844         .f = cmd_read_reg_bit_parsed,
6845         .data = NULL,
6846         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6847         .tokens = {
6848                 (void *)&cmd_read_reg_bit_read,
6849                 (void *)&cmd_read_reg_bit_regbit,
6850                 (void *)&cmd_read_reg_bit_port_id,
6851                 (void *)&cmd_read_reg_bit_reg_off,
6852                 (void *)&cmd_read_reg_bit_bit_pos,
6853                 NULL,
6854         },
6855 };
6856
6857 /* *** WRITE PORT REGISTER *** */
6858 struct cmd_write_reg_result {
6859         cmdline_fixed_string_t write;
6860         cmdline_fixed_string_t reg;
6861         portid_t port_id;
6862         uint32_t reg_off;
6863         uint32_t value;
6864 };
6865
6866 static void
6867 cmd_write_reg_parsed(void *parsed_result,
6868                      __attribute__((unused)) struct cmdline *cl,
6869                      __attribute__((unused)) void *data)
6870 {
6871         struct cmd_write_reg_result *res = parsed_result;
6872         port_reg_set(res->port_id, res->reg_off, res->value);
6873 }
6874
6875 cmdline_parse_token_string_t cmd_write_reg_write =
6876         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6877 cmdline_parse_token_string_t cmd_write_reg_reg =
6878         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6879 cmdline_parse_token_num_t cmd_write_reg_port_id =
6880         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6881 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6882         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6883 cmdline_parse_token_num_t cmd_write_reg_value =
6884         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6885
6886 cmdline_parse_inst_t cmd_write_reg = {
6887         .f = cmd_write_reg_parsed,
6888         .data = NULL,
6889         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6890         .tokens = {
6891                 (void *)&cmd_write_reg_write,
6892                 (void *)&cmd_write_reg_reg,
6893                 (void *)&cmd_write_reg_port_id,
6894                 (void *)&cmd_write_reg_reg_off,
6895                 (void *)&cmd_write_reg_value,
6896                 NULL,
6897         },
6898 };
6899
6900 /* *** WRITE PORT REGISTER BIT FIELD *** */
6901 struct cmd_write_reg_bit_field_result {
6902         cmdline_fixed_string_t write;
6903         cmdline_fixed_string_t regfield;
6904         portid_t port_id;
6905         uint32_t reg_off;
6906         uint8_t bit1_pos;
6907         uint8_t bit2_pos;
6908         uint32_t value;
6909 };
6910
6911 static void
6912 cmd_write_reg_bit_field_parsed(void *parsed_result,
6913                                __attribute__((unused)) struct cmdline *cl,
6914                                __attribute__((unused)) void *data)
6915 {
6916         struct cmd_write_reg_bit_field_result *res = parsed_result;
6917         port_reg_bit_field_set(res->port_id, res->reg_off,
6918                           res->bit1_pos, res->bit2_pos, res->value);
6919 }
6920
6921 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6922         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6923                                  "write");
6924 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6925         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6926                                  regfield, "regfield");
6927 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6928         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6929                               UINT16);
6930 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6931         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6932                               UINT32);
6933 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6934         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6935                               UINT8);
6936 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6937         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6938                               UINT8);
6939 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6940         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6941                               UINT32);
6942
6943 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6944         .f = cmd_write_reg_bit_field_parsed,
6945         .data = NULL,
6946         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6947                 "<reg_value>: "
6948                 "Set register bit field between bit_x and bit_y included",
6949         .tokens = {
6950                 (void *)&cmd_write_reg_bit_field_write,
6951                 (void *)&cmd_write_reg_bit_field_regfield,
6952                 (void *)&cmd_write_reg_bit_field_port_id,
6953                 (void *)&cmd_write_reg_bit_field_reg_off,
6954                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6955                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6956                 (void *)&cmd_write_reg_bit_field_value,
6957                 NULL,
6958         },
6959 };
6960
6961 /* *** WRITE PORT REGISTER BIT *** */
6962 struct cmd_write_reg_bit_result {
6963         cmdline_fixed_string_t write;
6964         cmdline_fixed_string_t regbit;
6965         portid_t port_id;
6966         uint32_t reg_off;
6967         uint8_t bit_pos;
6968         uint8_t value;
6969 };
6970
6971 static void
6972 cmd_write_reg_bit_parsed(void *parsed_result,
6973                          __attribute__((unused)) struct cmdline *cl,
6974                          __attribute__((unused)) void *data)
6975 {
6976         struct cmd_write_reg_bit_result *res = parsed_result;
6977         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6978 }
6979
6980 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6981         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6982                                  "write");
6983 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6984         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6985                                  regbit, "regbit");
6986 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6987         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6988 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6989         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6990 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6991         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6992 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6993         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6994
6995 cmdline_parse_inst_t cmd_write_reg_bit = {
6996         .f = cmd_write_reg_bit_parsed,
6997         .data = NULL,
6998         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6999                 "0 <= bit_x <= 31",
7000         .tokens = {
7001                 (void *)&cmd_write_reg_bit_write,
7002                 (void *)&cmd_write_reg_bit_regbit,
7003                 (void *)&cmd_write_reg_bit_port_id,
7004                 (void *)&cmd_write_reg_bit_reg_off,
7005                 (void *)&cmd_write_reg_bit_bit_pos,
7006                 (void *)&cmd_write_reg_bit_value,
7007                 NULL,
7008         },
7009 };
7010
7011 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
7012 struct cmd_read_rxd_txd_result {
7013         cmdline_fixed_string_t read;
7014         cmdline_fixed_string_t rxd_txd;
7015         portid_t port_id;
7016         uint16_t queue_id;
7017         uint16_t desc_id;
7018 };
7019
7020 static void
7021 cmd_read_rxd_txd_parsed(void *parsed_result,
7022                         __attribute__((unused)) struct cmdline *cl,
7023                         __attribute__((unused)) void *data)
7024 {
7025         struct cmd_read_rxd_txd_result *res = parsed_result;
7026
7027         if (!strcmp(res->rxd_txd, "rxd"))
7028                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7029         else if (!strcmp(res->rxd_txd, "txd"))
7030                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7031 }
7032
7033 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7034         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7035 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7036         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7037                                  "rxd#txd");
7038 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7039         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7040 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7041         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7042 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7043         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7044
7045 cmdline_parse_inst_t cmd_read_rxd_txd = {
7046         .f = cmd_read_rxd_txd_parsed,
7047         .data = NULL,
7048         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7049         .tokens = {
7050                 (void *)&cmd_read_rxd_txd_read,
7051                 (void *)&cmd_read_rxd_txd_rxd_txd,
7052                 (void *)&cmd_read_rxd_txd_port_id,
7053                 (void *)&cmd_read_rxd_txd_queue_id,
7054                 (void *)&cmd_read_rxd_txd_desc_id,
7055                 NULL,
7056         },
7057 };
7058
7059 /* *** QUIT *** */
7060 struct cmd_quit_result {
7061         cmdline_fixed_string_t quit;
7062 };
7063
7064 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7065                             struct cmdline *cl,
7066                             __attribute__((unused)) void *data)
7067 {
7068         pmd_test_exit();
7069         cmdline_quit(cl);
7070 }
7071
7072 cmdline_parse_token_string_t cmd_quit_quit =
7073         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7074
7075 cmdline_parse_inst_t cmd_quit = {
7076         .f = cmd_quit_parsed,
7077         .data = NULL,
7078         .help_str = "quit: Exit application",
7079         .tokens = {
7080                 (void *)&cmd_quit_quit,
7081                 NULL,
7082         },
7083 };
7084
7085 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7086 struct cmd_mac_addr_result {
7087         cmdline_fixed_string_t mac_addr_cmd;
7088         cmdline_fixed_string_t what;
7089         uint16_t port_num;
7090         struct ether_addr address;
7091 };
7092
7093 static void cmd_mac_addr_parsed(void *parsed_result,
7094                 __attribute__((unused)) struct cmdline *cl,
7095                 __attribute__((unused)) void *data)
7096 {
7097         struct cmd_mac_addr_result *res = parsed_result;
7098         int ret;
7099
7100         if (strcmp(res->what, "add") == 0)
7101                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7102         else if (strcmp(res->what, "set") == 0)
7103                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7104                                                        &res->address);
7105         else
7106                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7107
7108         /* check the return value and print it if is < 0 */
7109         if(ret < 0)
7110                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7111
7112 }
7113
7114 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7115         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7116                                 "mac_addr");
7117 cmdline_parse_token_string_t cmd_mac_addr_what =
7118         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7119                                 "add#remove#set");
7120 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7121                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7122                                         UINT16);
7123 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7124                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7125
7126 cmdline_parse_inst_t cmd_mac_addr = {
7127         .f = cmd_mac_addr_parsed,
7128         .data = (void *)0,
7129         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7130                         "Add/Remove/Set MAC address on port_id",
7131         .tokens = {
7132                 (void *)&cmd_mac_addr_cmd,
7133                 (void *)&cmd_mac_addr_what,
7134                 (void *)&cmd_mac_addr_portnum,
7135                 (void *)&cmd_mac_addr_addr,
7136                 NULL,
7137         },
7138 };
7139
7140
7141 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7142 struct cmd_set_qmap_result {
7143         cmdline_fixed_string_t set;
7144         cmdline_fixed_string_t qmap;
7145         cmdline_fixed_string_t what;
7146         portid_t port_id;
7147         uint16_t queue_id;
7148         uint8_t map_value;
7149 };
7150
7151 static void
7152 cmd_set_qmap_parsed(void *parsed_result,
7153                        __attribute__((unused)) struct cmdline *cl,
7154                        __attribute__((unused)) void *data)
7155 {
7156         struct cmd_set_qmap_result *res = parsed_result;
7157         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7158
7159         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7160 }
7161
7162 cmdline_parse_token_string_t cmd_setqmap_set =
7163         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7164                                  set, "set");
7165 cmdline_parse_token_string_t cmd_setqmap_qmap =
7166         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7167                                  qmap, "stat_qmap");
7168 cmdline_parse_token_string_t cmd_setqmap_what =
7169         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7170                                  what, "tx#rx");
7171 cmdline_parse_token_num_t cmd_setqmap_portid =
7172         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7173                               port_id, UINT16);
7174 cmdline_parse_token_num_t cmd_setqmap_queueid =
7175         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7176                               queue_id, UINT16);
7177 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7178         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7179                               map_value, UINT8);
7180
7181 cmdline_parse_inst_t cmd_set_qmap = {
7182         .f = cmd_set_qmap_parsed,
7183         .data = NULL,
7184         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7185                 "Set statistics mapping value on tx|rx queue_id of port_id",
7186         .tokens = {
7187                 (void *)&cmd_setqmap_set,
7188                 (void *)&cmd_setqmap_qmap,
7189                 (void *)&cmd_setqmap_what,
7190                 (void *)&cmd_setqmap_portid,
7191                 (void *)&cmd_setqmap_queueid,
7192                 (void *)&cmd_setqmap_mapvalue,
7193                 NULL,
7194         },
7195 };
7196
7197 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7198 struct cmd_set_xstats_hide_zero_result {
7199         cmdline_fixed_string_t keyword;
7200         cmdline_fixed_string_t name;
7201         cmdline_fixed_string_t on_off;
7202 };
7203
7204 static void
7205 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7206                         __attribute__((unused)) struct cmdline *cl,
7207                         __attribute__((unused)) void *data)
7208 {
7209         struct cmd_set_xstats_hide_zero_result *res;
7210         uint16_t on_off = 0;
7211
7212         res = parsed_result;
7213         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7214         set_xstats_hide_zero(on_off);
7215 }
7216
7217 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7218         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7219                                  keyword, "set");
7220 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7221         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7222                                  name, "xstats-hide-zero");
7223 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7224         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7225                                  on_off, "on#off");
7226
7227 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7228         .f = cmd_set_xstats_hide_zero_parsed,
7229         .data = NULL,
7230         .help_str = "set xstats-hide-zero on|off",
7231         .tokens = {
7232                 (void *)&cmd_set_xstats_hide_zero_keyword,
7233                 (void *)&cmd_set_xstats_hide_zero_name,
7234                 (void *)&cmd_set_xstats_hide_zero_on_off,
7235                 NULL,
7236         },
7237 };
7238
7239 /* *** CONFIGURE UNICAST HASH TABLE *** */
7240 struct cmd_set_uc_hash_table {
7241         cmdline_fixed_string_t set;
7242         cmdline_fixed_string_t port;
7243         portid_t port_id;
7244         cmdline_fixed_string_t what;
7245         struct ether_addr address;
7246         cmdline_fixed_string_t mode;
7247 };
7248
7249 static void
7250 cmd_set_uc_hash_parsed(void *parsed_result,
7251                        __attribute__((unused)) struct cmdline *cl,
7252                        __attribute__((unused)) void *data)
7253 {
7254         int ret=0;
7255         struct cmd_set_uc_hash_table *res = parsed_result;
7256
7257         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7258
7259         if (strcmp(res->what, "uta") == 0)
7260                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7261                                                 &res->address,(uint8_t)is_on);
7262         if (ret < 0)
7263                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7264
7265 }
7266
7267 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7268         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7269                                  set, "set");
7270 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7271         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7272                                  port, "port");
7273 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7274         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7275                               port_id, UINT16);
7276 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7277         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7278                                  what, "uta");
7279 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7280         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7281                                 address);
7282 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7283         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7284                                  mode, "on#off");
7285
7286 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7287         .f = cmd_set_uc_hash_parsed,
7288         .data = NULL,
7289         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7290         .tokens = {
7291                 (void *)&cmd_set_uc_hash_set,
7292                 (void *)&cmd_set_uc_hash_port,
7293                 (void *)&cmd_set_uc_hash_portid,
7294                 (void *)&cmd_set_uc_hash_what,
7295                 (void *)&cmd_set_uc_hash_mac,
7296                 (void *)&cmd_set_uc_hash_mode,
7297                 NULL,
7298         },
7299 };
7300
7301 struct cmd_set_uc_all_hash_table {
7302         cmdline_fixed_string_t set;
7303         cmdline_fixed_string_t port;
7304         portid_t port_id;
7305         cmdline_fixed_string_t what;
7306         cmdline_fixed_string_t value;
7307         cmdline_fixed_string_t mode;
7308 };
7309
7310 static void
7311 cmd_set_uc_all_hash_parsed(void *parsed_result,
7312                        __attribute__((unused)) struct cmdline *cl,
7313                        __attribute__((unused)) void *data)
7314 {
7315         int ret=0;
7316         struct cmd_set_uc_all_hash_table *res = parsed_result;
7317
7318         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7319
7320         if ((strcmp(res->what, "uta") == 0) &&
7321                 (strcmp(res->value, "all") == 0))
7322                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7323         if (ret < 0)
7324                 printf("bad unicast hash table parameter,"
7325                         "return code = %d \n", ret);
7326 }
7327
7328 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7329         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7330                                  set, "set");
7331 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7332         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7333                                  port, "port");
7334 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7335         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7336                               port_id, UINT16);
7337 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7338         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7339                                  what, "uta");
7340 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7341         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7342                                 value,"all");
7343 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7344         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7345                                  mode, "on#off");
7346
7347 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7348         .f = cmd_set_uc_all_hash_parsed,
7349         .data = NULL,
7350         .help_str = "set port <port_id> uta all on|off",
7351         .tokens = {
7352                 (void *)&cmd_set_uc_all_hash_set,
7353                 (void *)&cmd_set_uc_all_hash_port,
7354                 (void *)&cmd_set_uc_all_hash_portid,
7355                 (void *)&cmd_set_uc_all_hash_what,
7356                 (void *)&cmd_set_uc_all_hash_value,
7357                 (void *)&cmd_set_uc_all_hash_mode,
7358                 NULL,
7359         },
7360 };
7361
7362 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7363 struct cmd_set_vf_macvlan_filter {
7364         cmdline_fixed_string_t set;
7365         cmdline_fixed_string_t port;
7366         portid_t port_id;
7367         cmdline_fixed_string_t vf;
7368         uint8_t vf_id;
7369         struct ether_addr address;
7370         cmdline_fixed_string_t filter_type;
7371         cmdline_fixed_string_t mode;
7372 };
7373
7374 static void
7375 cmd_set_vf_macvlan_parsed(void *parsed_result,
7376                        __attribute__((unused)) struct cmdline *cl,
7377                        __attribute__((unused)) void *data)
7378 {
7379         int is_on, ret = 0;
7380         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7381         struct rte_eth_mac_filter filter;
7382
7383         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7384
7385         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7386
7387         /* set VF MAC filter */
7388         filter.is_vf = 1;
7389
7390         /* set VF ID */
7391         filter.dst_id = res->vf_id;
7392
7393         if (!strcmp(res->filter_type, "exact-mac"))
7394                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7395         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7396                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7397         else if (!strcmp(res->filter_type, "hashmac"))
7398                 filter.filter_type = RTE_MAC_HASH_MATCH;
7399         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7400                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7401
7402         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7403
7404         if (is_on)
7405                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7406                                         RTE_ETH_FILTER_MACVLAN,
7407                                         RTE_ETH_FILTER_ADD,
7408                                          &filter);
7409         else
7410                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7411                                         RTE_ETH_FILTER_MACVLAN,
7412                                         RTE_ETH_FILTER_DELETE,
7413                                         &filter);
7414
7415         if (ret < 0)
7416                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7417
7418 }
7419
7420 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7421         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7422                                  set, "set");
7423 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7424         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7425                                  port, "port");
7426 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7427         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7428                               port_id, UINT16);
7429 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7430         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7431                                  vf, "vf");
7432 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7433         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7434                                 vf_id, UINT8);
7435 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7436         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7437                                 address);
7438 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7439         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7440                                 filter_type, "exact-mac#exact-mac-vlan"
7441                                 "#hashmac#hashmac-vlan");
7442 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7443         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7444                                  mode, "on#off");
7445
7446 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7447         .f = cmd_set_vf_macvlan_parsed,
7448         .data = NULL,
7449         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7450                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7451                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7452                 "hash match rule: hash match of MAC and exact match of VLAN",
7453         .tokens = {
7454                 (void *)&cmd_set_vf_macvlan_set,
7455                 (void *)&cmd_set_vf_macvlan_port,
7456                 (void *)&cmd_set_vf_macvlan_portid,
7457                 (void *)&cmd_set_vf_macvlan_vf,
7458                 (void *)&cmd_set_vf_macvlan_vf_id,
7459                 (void *)&cmd_set_vf_macvlan_mac,
7460                 (void *)&cmd_set_vf_macvlan_filter_type,
7461                 (void *)&cmd_set_vf_macvlan_mode,
7462                 NULL,
7463         },
7464 };
7465
7466 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7467 struct cmd_set_vf_traffic {
7468         cmdline_fixed_string_t set;
7469         cmdline_fixed_string_t port;
7470         portid_t port_id;
7471         cmdline_fixed_string_t vf;
7472         uint8_t vf_id;
7473         cmdline_fixed_string_t what;
7474         cmdline_fixed_string_t mode;
7475 };
7476
7477 static void
7478 cmd_set_vf_traffic_parsed(void *parsed_result,
7479                        __attribute__((unused)) struct cmdline *cl,
7480                        __attribute__((unused)) void *data)
7481 {
7482         struct cmd_set_vf_traffic *res = parsed_result;
7483         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7484         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7485
7486         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7487 }
7488
7489 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7490         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7491                                  set, "set");
7492 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7493         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7494                                  port, "port");
7495 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7496         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7497                               port_id, UINT16);
7498 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7499         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7500                                  vf, "vf");
7501 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7502         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7503                               vf_id, UINT8);
7504 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7505         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7506                                  what, "tx#rx");
7507 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7508         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7509                                  mode, "on#off");
7510
7511 cmdline_parse_inst_t cmd_set_vf_traffic = {
7512         .f = cmd_set_vf_traffic_parsed,
7513         .data = NULL,
7514         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7515         .tokens = {
7516                 (void *)&cmd_setvf_traffic_set,
7517                 (void *)&cmd_setvf_traffic_port,
7518                 (void *)&cmd_setvf_traffic_portid,
7519                 (void *)&cmd_setvf_traffic_vf,
7520                 (void *)&cmd_setvf_traffic_vfid,
7521                 (void *)&cmd_setvf_traffic_what,
7522                 (void *)&cmd_setvf_traffic_mode,
7523                 NULL,
7524         },
7525 };
7526
7527 /* *** CONFIGURE VF RECEIVE MODE *** */
7528 struct cmd_set_vf_rxmode {
7529         cmdline_fixed_string_t set;
7530         cmdline_fixed_string_t port;
7531         portid_t port_id;
7532         cmdline_fixed_string_t vf;
7533         uint8_t vf_id;
7534         cmdline_fixed_string_t what;
7535         cmdline_fixed_string_t mode;
7536         cmdline_fixed_string_t on;
7537 };
7538
7539 static void
7540 cmd_set_vf_rxmode_parsed(void *parsed_result,
7541                        __attribute__((unused)) struct cmdline *cl,
7542                        __attribute__((unused)) void *data)
7543 {
7544         int ret = -ENOTSUP;
7545         uint16_t rx_mode = 0;
7546         struct cmd_set_vf_rxmode *res = parsed_result;
7547
7548         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7549         if (!strcmp(res->what,"rxmode")) {
7550                 if (!strcmp(res->mode, "AUPE"))
7551                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7552                 else if (!strcmp(res->mode, "ROPE"))
7553                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7554                 else if (!strcmp(res->mode, "BAM"))
7555                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7556                 else if (!strncmp(res->mode, "MPE",3))
7557                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7558         }
7559
7560         RTE_SET_USED(is_on);
7561
7562 #ifdef RTE_LIBRTE_IXGBE_PMD
7563         if (ret == -ENOTSUP)
7564                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7565                                                   rx_mode, (uint8_t)is_on);
7566 #endif
7567 #ifdef RTE_LIBRTE_BNXT_PMD
7568         if (ret == -ENOTSUP)
7569                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7570                                                  rx_mode, (uint8_t)is_on);
7571 #endif
7572         if (ret < 0)
7573                 printf("bad VF receive mode parameter, return code = %d \n",
7574                 ret);
7575 }
7576
7577 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7578         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7579                                  set, "set");
7580 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7581         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7582                                  port, "port");
7583 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7584         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7585                               port_id, UINT16);
7586 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7587         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7588                                  vf, "vf");
7589 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7590         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7591                               vf_id, UINT8);
7592 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7593         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7594                                  what, "rxmode");
7595 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7596         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7597                                  mode, "AUPE#ROPE#BAM#MPE");
7598 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7599         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7600                                  on, "on#off");
7601
7602 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7603         .f = cmd_set_vf_rxmode_parsed,
7604         .data = NULL,
7605         .help_str = "set port <port_id> vf <vf_id> rxmode "
7606                 "AUPE|ROPE|BAM|MPE on|off",
7607         .tokens = {
7608                 (void *)&cmd_set_vf_rxmode_set,
7609                 (void *)&cmd_set_vf_rxmode_port,
7610                 (void *)&cmd_set_vf_rxmode_portid,
7611                 (void *)&cmd_set_vf_rxmode_vf,
7612                 (void *)&cmd_set_vf_rxmode_vfid,
7613                 (void *)&cmd_set_vf_rxmode_what,
7614                 (void *)&cmd_set_vf_rxmode_mode,
7615                 (void *)&cmd_set_vf_rxmode_on,
7616                 NULL,
7617         },
7618 };
7619
7620 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7621 struct cmd_vf_mac_addr_result {
7622         cmdline_fixed_string_t mac_addr_cmd;
7623         cmdline_fixed_string_t what;
7624         cmdline_fixed_string_t port;
7625         uint16_t port_num;
7626         cmdline_fixed_string_t vf;
7627         uint8_t vf_num;
7628         struct ether_addr address;
7629 };
7630
7631 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7632                 __attribute__((unused)) struct cmdline *cl,
7633                 __attribute__((unused)) void *data)
7634 {
7635         struct cmd_vf_mac_addr_result *res = parsed_result;
7636         int ret = -ENOTSUP;
7637
7638         if (strcmp(res->what, "add") != 0)
7639                 return;
7640
7641 #ifdef RTE_LIBRTE_I40E_PMD
7642         if (ret == -ENOTSUP)
7643                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7644                                                    &res->address);
7645 #endif
7646 #ifdef RTE_LIBRTE_BNXT_PMD
7647         if (ret == -ENOTSUP)
7648                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7649                                                 res->vf_num);
7650 #endif
7651
7652         if(ret < 0)
7653                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7654
7655 }
7656
7657 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7658         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7659                                 mac_addr_cmd,"mac_addr");
7660 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7661         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7662                                 what,"add");
7663 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7664         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7665                                 port,"port");
7666 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7667         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7668                                 port_num, UINT16);
7669 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7670         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7671                                 vf,"vf");
7672 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7673         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7674                                 vf_num, UINT8);
7675 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7676         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7677                                 address);
7678
7679 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7680         .f = cmd_vf_mac_addr_parsed,
7681         .data = (void *)0,
7682         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7683                 "Add MAC address filtering for a VF on port_id",
7684         .tokens = {
7685                 (void *)&cmd_vf_mac_addr_cmd,
7686                 (void *)&cmd_vf_mac_addr_what,
7687                 (void *)&cmd_vf_mac_addr_port,
7688                 (void *)&cmd_vf_mac_addr_portnum,
7689                 (void *)&cmd_vf_mac_addr_vf,
7690                 (void *)&cmd_vf_mac_addr_vfnum,
7691                 (void *)&cmd_vf_mac_addr_addr,
7692                 NULL,
7693         },
7694 };
7695
7696 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7697 struct cmd_vf_rx_vlan_filter {
7698         cmdline_fixed_string_t rx_vlan;
7699         cmdline_fixed_string_t what;
7700         uint16_t vlan_id;
7701         cmdline_fixed_string_t port;
7702         portid_t port_id;
7703         cmdline_fixed_string_t vf;
7704         uint64_t vf_mask;
7705 };
7706
7707 static void
7708 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7709                           __attribute__((unused)) struct cmdline *cl,
7710                           __attribute__((unused)) void *data)
7711 {
7712         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7713         int ret = -ENOTSUP;
7714
7715         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7716
7717 #ifdef RTE_LIBRTE_IXGBE_PMD
7718         if (ret == -ENOTSUP)
7719                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7720                                 res->vlan_id, res->vf_mask, is_add);
7721 #endif
7722 #ifdef RTE_LIBRTE_I40E_PMD
7723         if (ret == -ENOTSUP)
7724                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7725                                 res->vlan_id, res->vf_mask, is_add);
7726 #endif
7727 #ifdef RTE_LIBRTE_BNXT_PMD
7728         if (ret == -ENOTSUP)
7729                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7730                                 res->vlan_id, res->vf_mask, is_add);
7731 #endif
7732
7733         switch (ret) {
7734         case 0:
7735                 break;
7736         case -EINVAL:
7737                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7738                                 res->vlan_id, res->vf_mask);
7739                 break;
7740         case -ENODEV:
7741                 printf("invalid port_id %d\n", res->port_id);
7742                 break;
7743         case -ENOTSUP:
7744                 printf("function not implemented or supported\n");
7745                 break;
7746         default:
7747                 printf("programming error: (%s)\n", strerror(-ret));
7748         }
7749 }
7750
7751 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7752         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7753                                  rx_vlan, "rx_vlan");
7754 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7755         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7756                                  what, "add#rm");
7757 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7758         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7759                               vlan_id, UINT16);
7760 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7761         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7762                                  port, "port");
7763 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7764         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7765                               port_id, UINT16);
7766 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7767         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7768                                  vf, "vf");
7769 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7770         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7771                               vf_mask, UINT64);
7772
7773 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7774         .f = cmd_vf_rx_vlan_filter_parsed,
7775         .data = NULL,
7776         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7777                 "(vf_mask = hexadecimal VF mask)",
7778         .tokens = {
7779                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7780                 (void *)&cmd_vf_rx_vlan_filter_what,
7781                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7782                 (void *)&cmd_vf_rx_vlan_filter_port,
7783                 (void *)&cmd_vf_rx_vlan_filter_portid,
7784                 (void *)&cmd_vf_rx_vlan_filter_vf,
7785                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7786                 NULL,
7787         },
7788 };
7789
7790 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7791 struct cmd_queue_rate_limit_result {
7792         cmdline_fixed_string_t set;
7793         cmdline_fixed_string_t port;
7794         uint16_t port_num;
7795         cmdline_fixed_string_t queue;
7796         uint8_t queue_num;
7797         cmdline_fixed_string_t rate;
7798         uint16_t rate_num;
7799 };
7800
7801 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7802                 __attribute__((unused)) struct cmdline *cl,
7803                 __attribute__((unused)) void *data)
7804 {
7805         struct cmd_queue_rate_limit_result *res = parsed_result;
7806         int ret = 0;
7807
7808         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7809                 && (strcmp(res->queue, "queue") == 0)
7810                 && (strcmp(res->rate, "rate") == 0))
7811                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7812                                         res->rate_num);
7813         if (ret < 0)
7814                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7815
7816 }
7817
7818 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7819         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7820                                 set, "set");
7821 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7822         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7823                                 port, "port");
7824 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7825         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7826                                 port_num, UINT16);
7827 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7828         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7829                                 queue, "queue");
7830 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7831         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7832                                 queue_num, UINT8);
7833 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7834         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7835                                 rate, "rate");
7836 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7837         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7838                                 rate_num, UINT16);
7839
7840 cmdline_parse_inst_t cmd_queue_rate_limit = {
7841         .f = cmd_queue_rate_limit_parsed,
7842         .data = (void *)0,
7843         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7844                 "Set rate limit for a queue on port_id",
7845         .tokens = {
7846                 (void *)&cmd_queue_rate_limit_set,
7847                 (void *)&cmd_queue_rate_limit_port,
7848                 (void *)&cmd_queue_rate_limit_portnum,
7849                 (void *)&cmd_queue_rate_limit_queue,
7850                 (void *)&cmd_queue_rate_limit_queuenum,
7851                 (void *)&cmd_queue_rate_limit_rate,
7852                 (void *)&cmd_queue_rate_limit_ratenum,
7853                 NULL,
7854         },
7855 };
7856
7857 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7858 struct cmd_vf_rate_limit_result {
7859         cmdline_fixed_string_t set;
7860         cmdline_fixed_string_t port;
7861         uint16_t port_num;
7862         cmdline_fixed_string_t vf;
7863         uint8_t vf_num;
7864         cmdline_fixed_string_t rate;
7865         uint16_t rate_num;
7866         cmdline_fixed_string_t q_msk;
7867         uint64_t q_msk_val;
7868 };
7869
7870 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7871                 __attribute__((unused)) struct cmdline *cl,
7872                 __attribute__((unused)) void *data)
7873 {
7874         struct cmd_vf_rate_limit_result *res = parsed_result;
7875         int ret = 0;
7876
7877         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7878                 && (strcmp(res->vf, "vf") == 0)
7879                 && (strcmp(res->rate, "rate") == 0)
7880                 && (strcmp(res->q_msk, "queue_mask") == 0))
7881                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7882                                         res->rate_num, res->q_msk_val);
7883         if (ret < 0)
7884                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7885
7886 }
7887
7888 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7889         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7890                                 set, "set");
7891 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7892         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7893                                 port, "port");
7894 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7895         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7896                                 port_num, UINT16);
7897 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7898         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7899                                 vf, "vf");
7900 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7901         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7902                                 vf_num, UINT8);
7903 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7904         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7905                                 rate, "rate");
7906 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7907         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7908                                 rate_num, UINT16);
7909 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7910         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7911                                 q_msk, "queue_mask");
7912 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7913         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7914                                 q_msk_val, UINT64);
7915
7916 cmdline_parse_inst_t cmd_vf_rate_limit = {
7917         .f = cmd_vf_rate_limit_parsed,
7918         .data = (void *)0,
7919         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7920                 "queue_mask <queue_mask_value>: "
7921                 "Set rate limit for queues of VF on port_id",
7922         .tokens = {
7923                 (void *)&cmd_vf_rate_limit_set,
7924                 (void *)&cmd_vf_rate_limit_port,
7925                 (void *)&cmd_vf_rate_limit_portnum,
7926                 (void *)&cmd_vf_rate_limit_vf,
7927                 (void *)&cmd_vf_rate_limit_vfnum,
7928                 (void *)&cmd_vf_rate_limit_rate,
7929                 (void *)&cmd_vf_rate_limit_ratenum,
7930                 (void *)&cmd_vf_rate_limit_q_msk,
7931                 (void *)&cmd_vf_rate_limit_q_msk_val,
7932                 NULL,
7933         },
7934 };
7935
7936 /* *** ADD TUNNEL FILTER OF A PORT *** */
7937 struct cmd_tunnel_filter_result {
7938         cmdline_fixed_string_t cmd;
7939         cmdline_fixed_string_t what;
7940         portid_t port_id;
7941         struct ether_addr outer_mac;
7942         struct ether_addr inner_mac;
7943         cmdline_ipaddr_t ip_value;
7944         uint16_t inner_vlan;
7945         cmdline_fixed_string_t tunnel_type;
7946         cmdline_fixed_string_t filter_type;
7947         uint32_t tenant_id;
7948         uint16_t queue_num;
7949 };
7950
7951 static void
7952 cmd_tunnel_filter_parsed(void *parsed_result,
7953                           __attribute__((unused)) struct cmdline *cl,
7954                           __attribute__((unused)) void *data)
7955 {
7956         struct cmd_tunnel_filter_result *res = parsed_result;
7957         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7958         int ret = 0;
7959
7960         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7961
7962         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7963         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7964         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7965
7966         if (res->ip_value.family == AF_INET) {
7967                 tunnel_filter_conf.ip_addr.ipv4_addr =
7968                         res->ip_value.addr.ipv4.s_addr;
7969                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7970         } else {
7971                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7972                         &(res->ip_value.addr.ipv6),
7973                         sizeof(struct in6_addr));
7974                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7975         }
7976
7977         if (!strcmp(res->filter_type, "imac-ivlan"))
7978                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7979         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7980                 tunnel_filter_conf.filter_type =
7981                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7982         else if (!strcmp(res->filter_type, "imac-tenid"))
7983                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7984         else if (!strcmp(res->filter_type, "imac"))
7985                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7986         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7987                 tunnel_filter_conf.filter_type =
7988                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7989         else if (!strcmp(res->filter_type, "oip"))
7990                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7991         else if (!strcmp(res->filter_type, "iip"))
7992                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7993         else {
7994                 printf("The filter type is not supported");
7995                 return;
7996         }
7997
7998         if (!strcmp(res->tunnel_type, "vxlan"))
7999                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
8000         else if (!strcmp(res->tunnel_type, "nvgre"))
8001                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
8002         else if (!strcmp(res->tunnel_type, "ipingre"))
8003                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
8004         else {
8005                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
8006                 return;
8007         }
8008
8009         tunnel_filter_conf.tenant_id = res->tenant_id;
8010         tunnel_filter_conf.queue_id = res->queue_num;
8011         if (!strcmp(res->what, "add"))
8012                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8013                                         RTE_ETH_FILTER_TUNNEL,
8014                                         RTE_ETH_FILTER_ADD,
8015                                         &tunnel_filter_conf);
8016         else
8017                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8018                                         RTE_ETH_FILTER_TUNNEL,
8019                                         RTE_ETH_FILTER_DELETE,
8020                                         &tunnel_filter_conf);
8021         if (ret < 0)
8022                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8023                                 strerror(-ret));
8024
8025 }
8026 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8027         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8028         cmd, "tunnel_filter");
8029 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8030         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8031         what, "add#rm");
8032 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8033         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8034         port_id, UINT16);
8035 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8036         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8037         outer_mac);
8038 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8039         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8040         inner_mac);
8041 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8042         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8043         inner_vlan, UINT16);
8044 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8045         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8046         ip_value);
8047 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8048         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8049         tunnel_type, "vxlan#nvgre#ipingre");
8050
8051 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8052         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8053         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8054                 "imac#omac-imac-tenid");
8055 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8056         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8057         tenant_id, UINT32);
8058 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8059         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8060         queue_num, UINT16);
8061
8062 cmdline_parse_inst_t cmd_tunnel_filter = {
8063         .f = cmd_tunnel_filter_parsed,
8064         .data = (void *)0,
8065         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8066                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8067                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8068                 "<queue_id>: Add/Rm tunnel filter of a port",
8069         .tokens = {
8070                 (void *)&cmd_tunnel_filter_cmd,
8071                 (void *)&cmd_tunnel_filter_what,
8072                 (void *)&cmd_tunnel_filter_port_id,
8073                 (void *)&cmd_tunnel_filter_outer_mac,
8074                 (void *)&cmd_tunnel_filter_inner_mac,
8075                 (void *)&cmd_tunnel_filter_ip_value,
8076                 (void *)&cmd_tunnel_filter_innner_vlan,
8077                 (void *)&cmd_tunnel_filter_tunnel_type,
8078                 (void *)&cmd_tunnel_filter_filter_type,
8079                 (void *)&cmd_tunnel_filter_tenant_id,
8080                 (void *)&cmd_tunnel_filter_queue_num,
8081                 NULL,
8082         },
8083 };
8084
8085 /* *** CONFIGURE TUNNEL UDP PORT *** */
8086 struct cmd_tunnel_udp_config {
8087         cmdline_fixed_string_t cmd;
8088         cmdline_fixed_string_t what;
8089         uint16_t udp_port;
8090         portid_t port_id;
8091 };
8092
8093 static void
8094 cmd_tunnel_udp_config_parsed(void *parsed_result,
8095                           __attribute__((unused)) struct cmdline *cl,
8096                           __attribute__((unused)) void *data)
8097 {
8098         struct cmd_tunnel_udp_config *res = parsed_result;
8099         struct rte_eth_udp_tunnel tunnel_udp;
8100         int ret;
8101
8102         tunnel_udp.udp_port = res->udp_port;
8103
8104         if (!strcmp(res->cmd, "rx_vxlan_port"))
8105                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8106
8107         if (!strcmp(res->what, "add"))
8108                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8109                                                       &tunnel_udp);
8110         else
8111                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8112                                                          &tunnel_udp);
8113
8114         if (ret < 0)
8115                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8116 }
8117
8118 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8119         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8120                                 cmd, "rx_vxlan_port");
8121 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8122         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8123                                 what, "add#rm");
8124 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8125         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8126                                 udp_port, UINT16);
8127 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8128         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8129                                 port_id, UINT16);
8130
8131 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8132         .f = cmd_tunnel_udp_config_parsed,
8133         .data = (void *)0,
8134         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8135                 "Add/Remove a tunneling UDP port filter",
8136         .tokens = {
8137                 (void *)&cmd_tunnel_udp_config_cmd,
8138                 (void *)&cmd_tunnel_udp_config_what,
8139                 (void *)&cmd_tunnel_udp_config_udp_port,
8140                 (void *)&cmd_tunnel_udp_config_port_id,
8141                 NULL,
8142         },
8143 };
8144
8145 /* *** GLOBAL CONFIG *** */
8146 struct cmd_global_config_result {
8147         cmdline_fixed_string_t cmd;
8148         portid_t port_id;
8149         cmdline_fixed_string_t cfg_type;
8150         uint8_t len;
8151 };
8152
8153 static void
8154 cmd_global_config_parsed(void *parsed_result,
8155                          __attribute__((unused)) struct cmdline *cl,
8156                          __attribute__((unused)) void *data)
8157 {
8158         struct cmd_global_config_result *res = parsed_result;
8159         struct rte_eth_global_cfg conf;
8160         int ret;
8161
8162         memset(&conf, 0, sizeof(conf));
8163         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8164         conf.cfg.gre_key_len = res->len;
8165         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8166                                       RTE_ETH_FILTER_SET, &conf);
8167         if (ret != 0)
8168                 printf("Global config error\n");
8169 }
8170
8171 cmdline_parse_token_string_t cmd_global_config_cmd =
8172         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8173                 "global_config");
8174 cmdline_parse_token_num_t cmd_global_config_port_id =
8175         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8176                                UINT16);
8177 cmdline_parse_token_string_t cmd_global_config_type =
8178         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8179                 cfg_type, "gre-key-len");
8180 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8181         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8182                 len, UINT8);
8183
8184 cmdline_parse_inst_t cmd_global_config = {
8185         .f = cmd_global_config_parsed,
8186         .data = (void *)NULL,
8187         .help_str = "global_config <port_id> gre-key-len <key_len>",
8188         .tokens = {
8189                 (void *)&cmd_global_config_cmd,
8190                 (void *)&cmd_global_config_port_id,
8191                 (void *)&cmd_global_config_type,
8192                 (void *)&cmd_global_config_gre_key_len,
8193                 NULL,
8194         },
8195 };
8196
8197 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8198 struct cmd_set_mirror_mask_result {
8199         cmdline_fixed_string_t set;
8200         cmdline_fixed_string_t port;
8201         portid_t port_id;
8202         cmdline_fixed_string_t mirror;
8203         uint8_t rule_id;
8204         cmdline_fixed_string_t what;
8205         cmdline_fixed_string_t value;
8206         cmdline_fixed_string_t dstpool;
8207         uint8_t dstpool_id;
8208         cmdline_fixed_string_t on;
8209 };
8210
8211 cmdline_parse_token_string_t cmd_mirror_mask_set =
8212         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8213                                 set, "set");
8214 cmdline_parse_token_string_t cmd_mirror_mask_port =
8215         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8216                                 port, "port");
8217 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8218         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8219                                 port_id, UINT16);
8220 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8221         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8222                                 mirror, "mirror-rule");
8223 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8224         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8225                                 rule_id, UINT8);
8226 cmdline_parse_token_string_t cmd_mirror_mask_what =
8227         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8228                                 what, "pool-mirror-up#pool-mirror-down"
8229                                       "#vlan-mirror");
8230 cmdline_parse_token_string_t cmd_mirror_mask_value =
8231         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8232                                 value, NULL);
8233 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8234         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8235                                 dstpool, "dst-pool");
8236 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8237         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8238                                 dstpool_id, UINT8);
8239 cmdline_parse_token_string_t cmd_mirror_mask_on =
8240         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8241                                 on, "on#off");
8242
8243 static void
8244 cmd_set_mirror_mask_parsed(void *parsed_result,
8245                        __attribute__((unused)) struct cmdline *cl,
8246                        __attribute__((unused)) void *data)
8247 {
8248         int ret,nb_item,i;
8249         struct cmd_set_mirror_mask_result *res = parsed_result;
8250         struct rte_eth_mirror_conf mr_conf;
8251
8252         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8253
8254         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8255
8256         mr_conf.dst_pool = res->dstpool_id;
8257
8258         if (!strcmp(res->what, "pool-mirror-up")) {
8259                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8260                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8261         } else if (!strcmp(res->what, "pool-mirror-down")) {
8262                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8263                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8264         } else if (!strcmp(res->what, "vlan-mirror")) {
8265                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8266                 nb_item = parse_item_list(res->value, "vlan",
8267                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8268                 if (nb_item <= 0)
8269                         return;
8270
8271                 for (i = 0; i < nb_item; i++) {
8272                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8273                                 printf("Invalid vlan_id: must be < 4096\n");
8274                                 return;
8275                         }
8276
8277                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8278                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8279                 }
8280         }
8281
8282         if (!strcmp(res->on, "on"))
8283                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8284                                                 res->rule_id, 1);
8285         else
8286                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8287                                                 res->rule_id, 0);
8288         if (ret < 0)
8289                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8290 }
8291
8292 cmdline_parse_inst_t cmd_set_mirror_mask = {
8293                 .f = cmd_set_mirror_mask_parsed,
8294                 .data = NULL,
8295                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8296                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8297                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8298                 .tokens = {
8299                         (void *)&cmd_mirror_mask_set,
8300                         (void *)&cmd_mirror_mask_port,
8301                         (void *)&cmd_mirror_mask_portid,
8302                         (void *)&cmd_mirror_mask_mirror,
8303                         (void *)&cmd_mirror_mask_ruleid,
8304                         (void *)&cmd_mirror_mask_what,
8305                         (void *)&cmd_mirror_mask_value,
8306                         (void *)&cmd_mirror_mask_dstpool,
8307                         (void *)&cmd_mirror_mask_poolid,
8308                         (void *)&cmd_mirror_mask_on,
8309                         NULL,
8310                 },
8311 };
8312
8313 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8314 struct cmd_set_mirror_link_result {
8315         cmdline_fixed_string_t set;
8316         cmdline_fixed_string_t port;
8317         portid_t port_id;
8318         cmdline_fixed_string_t mirror;
8319         uint8_t rule_id;
8320         cmdline_fixed_string_t what;
8321         cmdline_fixed_string_t dstpool;
8322         uint8_t dstpool_id;
8323         cmdline_fixed_string_t on;
8324 };
8325
8326 cmdline_parse_token_string_t cmd_mirror_link_set =
8327         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8328                                  set, "set");
8329 cmdline_parse_token_string_t cmd_mirror_link_port =
8330         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8331                                 port, "port");
8332 cmdline_parse_token_num_t cmd_mirror_link_portid =
8333         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8334                                 port_id, UINT16);
8335 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8336         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8337                                 mirror, "mirror-rule");
8338 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8339         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8340                             rule_id, UINT8);
8341 cmdline_parse_token_string_t cmd_mirror_link_what =
8342         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8343                                 what, "uplink-mirror#downlink-mirror");
8344 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8345         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8346                                 dstpool, "dst-pool");
8347 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8348         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8349                                 dstpool_id, UINT8);
8350 cmdline_parse_token_string_t cmd_mirror_link_on =
8351         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8352                                 on, "on#off");
8353
8354 static void
8355 cmd_set_mirror_link_parsed(void *parsed_result,
8356                        __attribute__((unused)) struct cmdline *cl,
8357                        __attribute__((unused)) void *data)
8358 {
8359         int ret;
8360         struct cmd_set_mirror_link_result *res = parsed_result;
8361         struct rte_eth_mirror_conf mr_conf;
8362
8363         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8364         if (!strcmp(res->what, "uplink-mirror"))
8365                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8366         else
8367                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8368
8369         mr_conf.dst_pool = res->dstpool_id;
8370
8371         if (!strcmp(res->on, "on"))
8372                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8373                                                 res->rule_id, 1);
8374         else
8375                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8376                                                 res->rule_id, 0);
8377
8378         /* check the return value and print it if is < 0 */
8379         if (ret < 0)
8380                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8381
8382 }
8383
8384 cmdline_parse_inst_t cmd_set_mirror_link = {
8385                 .f = cmd_set_mirror_link_parsed,
8386                 .data = NULL,
8387                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8388                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8389                 .tokens = {
8390                         (void *)&cmd_mirror_link_set,
8391                         (void *)&cmd_mirror_link_port,
8392                         (void *)&cmd_mirror_link_portid,
8393                         (void *)&cmd_mirror_link_mirror,
8394                         (void *)&cmd_mirror_link_ruleid,
8395                         (void *)&cmd_mirror_link_what,
8396                         (void *)&cmd_mirror_link_dstpool,
8397                         (void *)&cmd_mirror_link_poolid,
8398                         (void *)&cmd_mirror_link_on,
8399                         NULL,
8400                 },
8401 };
8402
8403 /* *** RESET VM MIRROR RULE *** */
8404 struct cmd_rm_mirror_rule_result {
8405         cmdline_fixed_string_t reset;
8406         cmdline_fixed_string_t port;
8407         portid_t port_id;
8408         cmdline_fixed_string_t mirror;
8409         uint8_t rule_id;
8410 };
8411
8412 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8413         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8414                                  reset, "reset");
8415 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8416         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8417                                 port, "port");
8418 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8419         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8420                                 port_id, UINT16);
8421 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8422         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8423                                 mirror, "mirror-rule");
8424 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8425         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8426                                 rule_id, UINT8);
8427
8428 static void
8429 cmd_reset_mirror_rule_parsed(void *parsed_result,
8430                        __attribute__((unused)) struct cmdline *cl,
8431                        __attribute__((unused)) void *data)
8432 {
8433         int ret;
8434         struct cmd_set_mirror_link_result *res = parsed_result;
8435         /* check rule_id */
8436         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8437         if(ret < 0)
8438                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8439 }
8440
8441 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8442                 .f = cmd_reset_mirror_rule_parsed,
8443                 .data = NULL,
8444                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8445                 .tokens = {
8446                         (void *)&cmd_rm_mirror_rule_reset,
8447                         (void *)&cmd_rm_mirror_rule_port,
8448                         (void *)&cmd_rm_mirror_rule_portid,
8449                         (void *)&cmd_rm_mirror_rule_mirror,
8450                         (void *)&cmd_rm_mirror_rule_ruleid,
8451                         NULL,
8452                 },
8453 };
8454
8455 /* ******************************************************************************** */
8456
8457 struct cmd_dump_result {
8458         cmdline_fixed_string_t dump;
8459 };
8460
8461 static void
8462 dump_struct_sizes(void)
8463 {
8464 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8465         DUMP_SIZE(struct rte_mbuf);
8466         DUMP_SIZE(struct rte_mempool);
8467         DUMP_SIZE(struct rte_ring);
8468 #undef DUMP_SIZE
8469 }
8470
8471 static void cmd_dump_parsed(void *parsed_result,
8472                             __attribute__((unused)) struct cmdline *cl,
8473                             __attribute__((unused)) void *data)
8474 {
8475         struct cmd_dump_result *res = parsed_result;
8476
8477         if (!strcmp(res->dump, "dump_physmem"))
8478                 rte_dump_physmem_layout(stdout);
8479         else if (!strcmp(res->dump, "dump_memzone"))
8480                 rte_memzone_dump(stdout);
8481         else if (!strcmp(res->dump, "dump_struct_sizes"))
8482                 dump_struct_sizes();
8483         else if (!strcmp(res->dump, "dump_ring"))
8484                 rte_ring_list_dump(stdout);
8485         else if (!strcmp(res->dump, "dump_mempool"))
8486                 rte_mempool_list_dump(stdout);
8487         else if (!strcmp(res->dump, "dump_devargs"))
8488                 rte_eal_devargs_dump(stdout);
8489         else if (!strcmp(res->dump, "dump_log_types"))
8490                 rte_log_dump(stdout);
8491 }
8492
8493 cmdline_parse_token_string_t cmd_dump_dump =
8494         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8495                 "dump_physmem#"
8496                 "dump_memzone#"
8497                 "dump_struct_sizes#"
8498                 "dump_ring#"
8499                 "dump_mempool#"
8500                 "dump_devargs#"
8501                 "dump_log_types");
8502
8503 cmdline_parse_inst_t cmd_dump = {
8504         .f = cmd_dump_parsed,  /* function to call */
8505         .data = NULL,      /* 2nd arg of func */
8506         .help_str = "Dump status",
8507         .tokens = {        /* token list, NULL terminated */
8508                 (void *)&cmd_dump_dump,
8509                 NULL,
8510         },
8511 };
8512
8513 /* ******************************************************************************** */
8514
8515 struct cmd_dump_one_result {
8516         cmdline_fixed_string_t dump;
8517         cmdline_fixed_string_t name;
8518 };
8519
8520 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8521                                 __attribute__((unused)) void *data)
8522 {
8523         struct cmd_dump_one_result *res = parsed_result;
8524
8525         if (!strcmp(res->dump, "dump_ring")) {
8526                 struct rte_ring *r;
8527                 r = rte_ring_lookup(res->name);
8528                 if (r == NULL) {
8529                         cmdline_printf(cl, "Cannot find ring\n");
8530                         return;
8531                 }
8532                 rte_ring_dump(stdout, r);
8533         } else if (!strcmp(res->dump, "dump_mempool")) {
8534                 struct rte_mempool *mp;
8535                 mp = rte_mempool_lookup(res->name);
8536                 if (mp == NULL) {
8537                         cmdline_printf(cl, "Cannot find mempool\n");
8538                         return;
8539                 }
8540                 rte_mempool_dump(stdout, mp);
8541         }
8542 }
8543
8544 cmdline_parse_token_string_t cmd_dump_one_dump =
8545         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8546                                  "dump_ring#dump_mempool");
8547
8548 cmdline_parse_token_string_t cmd_dump_one_name =
8549         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8550
8551 cmdline_parse_inst_t cmd_dump_one = {
8552         .f = cmd_dump_one_parsed,  /* function to call */
8553         .data = NULL,      /* 2nd arg of func */
8554         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8555         .tokens = {        /* token list, NULL terminated */
8556                 (void *)&cmd_dump_one_dump,
8557                 (void *)&cmd_dump_one_name,
8558                 NULL,
8559         },
8560 };
8561
8562 /* *** Add/Del syn filter *** */
8563 struct cmd_syn_filter_result {
8564         cmdline_fixed_string_t filter;
8565         portid_t port_id;
8566         cmdline_fixed_string_t ops;
8567         cmdline_fixed_string_t priority;
8568         cmdline_fixed_string_t high;
8569         cmdline_fixed_string_t queue;
8570         uint16_t queue_id;
8571 };
8572
8573 static void
8574 cmd_syn_filter_parsed(void *parsed_result,
8575                         __attribute__((unused)) struct cmdline *cl,
8576                         __attribute__((unused)) void *data)
8577 {
8578         struct cmd_syn_filter_result *res = parsed_result;
8579         struct rte_eth_syn_filter syn_filter;
8580         int ret = 0;
8581
8582         ret = rte_eth_dev_filter_supported(res->port_id,
8583                                         RTE_ETH_FILTER_SYN);
8584         if (ret < 0) {
8585                 printf("syn filter is not supported on port %u.\n",
8586                                 res->port_id);
8587                 return;
8588         }
8589
8590         memset(&syn_filter, 0, sizeof(syn_filter));
8591
8592         if (!strcmp(res->ops, "add")) {
8593                 if (!strcmp(res->high, "high"))
8594                         syn_filter.hig_pri = 1;
8595                 else
8596                         syn_filter.hig_pri = 0;
8597
8598                 syn_filter.queue = res->queue_id;
8599                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8600                                                 RTE_ETH_FILTER_SYN,
8601                                                 RTE_ETH_FILTER_ADD,
8602                                                 &syn_filter);
8603         } else
8604                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8605                                                 RTE_ETH_FILTER_SYN,
8606                                                 RTE_ETH_FILTER_DELETE,
8607                                                 &syn_filter);
8608
8609         if (ret < 0)
8610                 printf("syn filter programming error: (%s)\n",
8611                                 strerror(-ret));
8612 }
8613
8614 cmdline_parse_token_string_t cmd_syn_filter_filter =
8615         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8616         filter, "syn_filter");
8617 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8618         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8619         port_id, UINT16);
8620 cmdline_parse_token_string_t cmd_syn_filter_ops =
8621         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8622         ops, "add#del");
8623 cmdline_parse_token_string_t cmd_syn_filter_priority =
8624         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8625                                 priority, "priority");
8626 cmdline_parse_token_string_t cmd_syn_filter_high =
8627         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8628                                 high, "high#low");
8629 cmdline_parse_token_string_t cmd_syn_filter_queue =
8630         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8631                                 queue, "queue");
8632 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8633         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8634                                 queue_id, UINT16);
8635
8636 cmdline_parse_inst_t cmd_syn_filter = {
8637         .f = cmd_syn_filter_parsed,
8638         .data = NULL,
8639         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8640                 "<queue_id>: Add/Delete syn filter",
8641         .tokens = {
8642                 (void *)&cmd_syn_filter_filter,
8643                 (void *)&cmd_syn_filter_port_id,
8644                 (void *)&cmd_syn_filter_ops,
8645                 (void *)&cmd_syn_filter_priority,
8646                 (void *)&cmd_syn_filter_high,
8647                 (void *)&cmd_syn_filter_queue,
8648                 (void *)&cmd_syn_filter_queue_id,
8649                 NULL,
8650         },
8651 };
8652
8653 /* *** queue region set *** */
8654 struct cmd_queue_region_result {
8655         cmdline_fixed_string_t set;
8656         cmdline_fixed_string_t port;
8657         portid_t port_id;
8658         cmdline_fixed_string_t cmd;
8659         cmdline_fixed_string_t region;
8660         uint8_t  region_id;
8661         cmdline_fixed_string_t queue_start_index;
8662         uint8_t  queue_id;
8663         cmdline_fixed_string_t queue_num;
8664         uint8_t  queue_num_value;
8665 };
8666
8667 static void
8668 cmd_queue_region_parsed(void *parsed_result,
8669                         __attribute__((unused)) struct cmdline *cl,
8670                         __attribute__((unused)) void *data)
8671 {
8672         struct cmd_queue_region_result *res = parsed_result;
8673         int ret = -ENOTSUP;
8674 #ifdef RTE_LIBRTE_I40E_PMD
8675         struct rte_pmd_i40e_queue_region_conf region_conf;
8676         enum rte_pmd_i40e_queue_region_op op_type;
8677 #endif
8678
8679         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8680                 return;
8681
8682 #ifdef RTE_LIBRTE_I40E_PMD
8683         memset(&region_conf, 0, sizeof(region_conf));
8684         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8685         region_conf.region_id = res->region_id;
8686         region_conf.queue_num = res->queue_num_value;
8687         region_conf.queue_start_index = res->queue_id;
8688
8689         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8690                                 op_type, &region_conf);
8691 #endif
8692
8693         switch (ret) {
8694         case 0:
8695                 break;
8696         case -ENOTSUP:
8697                 printf("function not implemented or supported\n");
8698                 break;
8699         default:
8700                 printf("queue region config error: (%s)\n", strerror(-ret));
8701         }
8702 }
8703
8704 cmdline_parse_token_string_t cmd_queue_region_set =
8705 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8706                 set, "set");
8707 cmdline_parse_token_string_t cmd_queue_region_port =
8708         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8709 cmdline_parse_token_num_t cmd_queue_region_port_id =
8710         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8711                                 port_id, UINT16);
8712 cmdline_parse_token_string_t cmd_queue_region_cmd =
8713         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8714                                  cmd, "queue-region");
8715 cmdline_parse_token_string_t cmd_queue_region_id =
8716         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8717                                 region, "region_id");
8718 cmdline_parse_token_num_t cmd_queue_region_index =
8719         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8720                                 region_id, UINT8);
8721 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8722         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8723                                 queue_start_index, "queue_start_index");
8724 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8725         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8726                                 queue_id, UINT8);
8727 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8728         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8729                                 queue_num, "queue_num");
8730 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8731         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8732                                 queue_num_value, UINT8);
8733
8734 cmdline_parse_inst_t cmd_queue_region = {
8735         .f = cmd_queue_region_parsed,
8736         .data = NULL,
8737         .help_str = "set port <port_id> queue-region region_id <value> "
8738                 "queue_start_index <value> queue_num <value>: Set a queue region",
8739         .tokens = {
8740                 (void *)&cmd_queue_region_set,
8741                 (void *)&cmd_queue_region_port,
8742                 (void *)&cmd_queue_region_port_id,
8743                 (void *)&cmd_queue_region_cmd,
8744                 (void *)&cmd_queue_region_id,
8745                 (void *)&cmd_queue_region_index,
8746                 (void *)&cmd_queue_region_queue_start_index,
8747                 (void *)&cmd_queue_region_queue_id,
8748                 (void *)&cmd_queue_region_queue_num,
8749                 (void *)&cmd_queue_region_queue_num_value,
8750                 NULL,
8751         },
8752 };
8753
8754 /* *** queue region and flowtype set *** */
8755 struct cmd_region_flowtype_result {
8756         cmdline_fixed_string_t set;
8757         cmdline_fixed_string_t port;
8758         portid_t port_id;
8759         cmdline_fixed_string_t cmd;
8760         cmdline_fixed_string_t region;
8761         uint8_t  region_id;
8762         cmdline_fixed_string_t flowtype;
8763         uint8_t  flowtype_id;
8764 };
8765
8766 static void
8767 cmd_region_flowtype_parsed(void *parsed_result,
8768                         __attribute__((unused)) struct cmdline *cl,
8769                         __attribute__((unused)) void *data)
8770 {
8771         struct cmd_region_flowtype_result *res = parsed_result;
8772         int ret = -ENOTSUP;
8773 #ifdef RTE_LIBRTE_I40E_PMD
8774         struct rte_pmd_i40e_queue_region_conf region_conf;
8775         enum rte_pmd_i40e_queue_region_op op_type;
8776 #endif
8777
8778         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8779                 return;
8780
8781 #ifdef RTE_LIBRTE_I40E_PMD
8782         memset(&region_conf, 0, sizeof(region_conf));
8783
8784         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8785         region_conf.region_id = res->region_id;
8786         region_conf.hw_flowtype = res->flowtype_id;
8787
8788         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8789                         op_type, &region_conf);
8790 #endif
8791
8792         switch (ret) {
8793         case 0:
8794                 break;
8795         case -ENOTSUP:
8796                 printf("function not implemented or supported\n");
8797                 break;
8798         default:
8799                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8800         }
8801 }
8802
8803 cmdline_parse_token_string_t cmd_region_flowtype_set =
8804 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8805                                 set, "set");
8806 cmdline_parse_token_string_t cmd_region_flowtype_port =
8807         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8808                                 port, "port");
8809 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8810         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8811                                 port_id, UINT16);
8812 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8813         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8814                                 cmd, "queue-region");
8815 cmdline_parse_token_string_t cmd_region_flowtype_index =
8816         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8817                                 region, "region_id");
8818 cmdline_parse_token_num_t cmd_region_flowtype_id =
8819         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8820                                 region_id, UINT8);
8821 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8822         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8823                                 flowtype, "flowtype");
8824 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8825         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8826                                 flowtype_id, UINT8);
8827 cmdline_parse_inst_t cmd_region_flowtype = {
8828         .f = cmd_region_flowtype_parsed,
8829         .data = NULL,
8830         .help_str = "set port <port_id> queue-region region_id <value> "
8831                 "flowtype <value>: Set a flowtype region index",
8832         .tokens = {
8833                 (void *)&cmd_region_flowtype_set,
8834                 (void *)&cmd_region_flowtype_port,
8835                 (void *)&cmd_region_flowtype_port_index,
8836                 (void *)&cmd_region_flowtype_cmd,
8837                 (void *)&cmd_region_flowtype_index,
8838                 (void *)&cmd_region_flowtype_id,
8839                 (void *)&cmd_region_flowtype_flow_index,
8840                 (void *)&cmd_region_flowtype_flow_id,
8841                 NULL,
8842         },
8843 };
8844
8845 /* *** User Priority (UP) to queue region (region_id) set *** */
8846 struct cmd_user_priority_region_result {
8847         cmdline_fixed_string_t set;
8848         cmdline_fixed_string_t port;
8849         portid_t port_id;
8850         cmdline_fixed_string_t cmd;
8851         cmdline_fixed_string_t user_priority;
8852         uint8_t  user_priority_id;
8853         cmdline_fixed_string_t region;
8854         uint8_t  region_id;
8855 };
8856
8857 static void
8858 cmd_user_priority_region_parsed(void *parsed_result,
8859                         __attribute__((unused)) struct cmdline *cl,
8860                         __attribute__((unused)) void *data)
8861 {
8862         struct cmd_user_priority_region_result *res = parsed_result;
8863         int ret = -ENOTSUP;
8864 #ifdef RTE_LIBRTE_I40E_PMD
8865         struct rte_pmd_i40e_queue_region_conf region_conf;
8866         enum rte_pmd_i40e_queue_region_op op_type;
8867 #endif
8868
8869         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8870                 return;
8871
8872 #ifdef RTE_LIBRTE_I40E_PMD
8873         memset(&region_conf, 0, sizeof(region_conf));
8874         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8875         region_conf.user_priority = res->user_priority_id;
8876         region_conf.region_id = res->region_id;
8877
8878         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8879                                 op_type, &region_conf);
8880 #endif
8881
8882         switch (ret) {
8883         case 0:
8884                 break;
8885         case -ENOTSUP:
8886                 printf("function not implemented or supported\n");
8887                 break;
8888         default:
8889                 printf("user_priority region config error: (%s)\n",
8890                                 strerror(-ret));
8891         }
8892 }
8893
8894 cmdline_parse_token_string_t cmd_user_priority_region_set =
8895         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8896                                 set, "set");
8897 cmdline_parse_token_string_t cmd_user_priority_region_port =
8898         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8899                                 port, "port");
8900 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8901         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8902                                 port_id, UINT16);
8903 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8904         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8905                                 cmd, "queue-region");
8906 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8907         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8908                                 user_priority, "UP");
8909 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8910         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8911                                 user_priority_id, UINT8);
8912 cmdline_parse_token_string_t cmd_user_priority_region_region =
8913         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8914                                 region, "region_id");
8915 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8916         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8917                                 region_id, UINT8);
8918
8919 cmdline_parse_inst_t cmd_user_priority_region = {
8920         .f = cmd_user_priority_region_parsed,
8921         .data = NULL,
8922         .help_str = "set port <port_id> queue-region UP <value> "
8923                 "region_id <value>: Set the mapping of User Priority (UP) "
8924                 "to queue region (region_id) ",
8925         .tokens = {
8926                 (void *)&cmd_user_priority_region_set,
8927                 (void *)&cmd_user_priority_region_port,
8928                 (void *)&cmd_user_priority_region_port_index,
8929                 (void *)&cmd_user_priority_region_cmd,
8930                 (void *)&cmd_user_priority_region_UP,
8931                 (void *)&cmd_user_priority_region_UP_id,
8932                 (void *)&cmd_user_priority_region_region,
8933                 (void *)&cmd_user_priority_region_region_id,
8934                 NULL,
8935         },
8936 };
8937
8938 /* *** flush all queue region related configuration *** */
8939 struct cmd_flush_queue_region_result {
8940         cmdline_fixed_string_t set;
8941         cmdline_fixed_string_t port;
8942         portid_t port_id;
8943         cmdline_fixed_string_t cmd;
8944         cmdline_fixed_string_t flush;
8945         cmdline_fixed_string_t what;
8946 };
8947
8948 static void
8949 cmd_flush_queue_region_parsed(void *parsed_result,
8950                         __attribute__((unused)) struct cmdline *cl,
8951                         __attribute__((unused)) void *data)
8952 {
8953         struct cmd_flush_queue_region_result *res = parsed_result;
8954         int ret = -ENOTSUP;
8955 #ifdef RTE_LIBRTE_I40E_PMD
8956         struct rte_pmd_i40e_queue_region_conf region_conf;
8957         enum rte_pmd_i40e_queue_region_op op_type;
8958 #endif
8959
8960         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8961                 return;
8962
8963 #ifdef RTE_LIBRTE_I40E_PMD
8964         memset(&region_conf, 0, sizeof(region_conf));
8965
8966         if (strcmp(res->what, "on") == 0)
8967                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8968         else
8969                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8970
8971         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8972                                 op_type, &region_conf);
8973 #endif
8974
8975         switch (ret) {
8976         case 0:
8977                 break;
8978         case -ENOTSUP:
8979                 printf("function not implemented or supported\n");
8980                 break;
8981         default:
8982                 printf("queue region config flush error: (%s)\n",
8983                                 strerror(-ret));
8984         }
8985 }
8986
8987 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8988         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8989                                 set, "set");
8990 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8991         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8992                                 port, "port");
8993 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8994         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8995                                 port_id, UINT16);
8996 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8997         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8998                                 cmd, "queue-region");
8999 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
9000         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9001                                 flush, "flush");
9002 cmdline_parse_token_string_t cmd_flush_queue_region_what =
9003         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
9004                                 what, "on#off");
9005
9006 cmdline_parse_inst_t cmd_flush_queue_region = {
9007         .f = cmd_flush_queue_region_parsed,
9008         .data = NULL,
9009         .help_str = "set port <port_id> queue-region flush on|off"
9010                 ": flush all queue region related configuration",
9011         .tokens = {
9012                 (void *)&cmd_flush_queue_region_set,
9013                 (void *)&cmd_flush_queue_region_port,
9014                 (void *)&cmd_flush_queue_region_port_index,
9015                 (void *)&cmd_flush_queue_region_cmd,
9016                 (void *)&cmd_flush_queue_region_flush,
9017                 (void *)&cmd_flush_queue_region_what,
9018                 NULL,
9019         },
9020 };
9021
9022 /* *** get all queue region related configuration info *** */
9023 struct cmd_show_queue_region_info {
9024         cmdline_fixed_string_t show;
9025         cmdline_fixed_string_t port;
9026         portid_t port_id;
9027         cmdline_fixed_string_t cmd;
9028 };
9029
9030 static void
9031 cmd_show_queue_region_info_parsed(void *parsed_result,
9032                         __attribute__((unused)) struct cmdline *cl,
9033                         __attribute__((unused)) void *data)
9034 {
9035         struct cmd_show_queue_region_info *res = parsed_result;
9036         int ret = -ENOTSUP;
9037 #ifdef RTE_LIBRTE_I40E_PMD
9038         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9039         enum rte_pmd_i40e_queue_region_op op_type;
9040 #endif
9041
9042         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9043                 return;
9044
9045 #ifdef RTE_LIBRTE_I40E_PMD
9046         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9047
9048         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9049
9050         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9051                                         op_type, &rte_pmd_regions);
9052
9053         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9054 #endif
9055
9056         switch (ret) {
9057         case 0:
9058                 break;
9059         case -ENOTSUP:
9060                 printf("function not implemented or supported\n");
9061                 break;
9062         default:
9063                 printf("queue region config info show error: (%s)\n",
9064                                 strerror(-ret));
9065         }
9066 }
9067
9068 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9069 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9070                                 show, "show");
9071 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9072         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9073                                 port, "port");
9074 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9075         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9076                                 port_id, UINT16);
9077 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9078         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9079                                 cmd, "queue-region");
9080
9081 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9082         .f = cmd_show_queue_region_info_parsed,
9083         .data = NULL,
9084         .help_str = "show port <port_id> queue-region"
9085                 ": show all queue region related configuration info",
9086         .tokens = {
9087                 (void *)&cmd_show_queue_region_info_get,
9088                 (void *)&cmd_show_queue_region_info_port,
9089                 (void *)&cmd_show_queue_region_info_port_index,
9090                 (void *)&cmd_show_queue_region_info_cmd,
9091                 NULL,
9092         },
9093 };
9094
9095 /* *** ADD/REMOVE A 2tuple FILTER *** */
9096 struct cmd_2tuple_filter_result {
9097         cmdline_fixed_string_t filter;
9098         portid_t port_id;
9099         cmdline_fixed_string_t ops;
9100         cmdline_fixed_string_t dst_port;
9101         uint16_t dst_port_value;
9102         cmdline_fixed_string_t protocol;
9103         uint8_t protocol_value;
9104         cmdline_fixed_string_t mask;
9105         uint8_t  mask_value;
9106         cmdline_fixed_string_t tcp_flags;
9107         uint8_t tcp_flags_value;
9108         cmdline_fixed_string_t priority;
9109         uint8_t  priority_value;
9110         cmdline_fixed_string_t queue;
9111         uint16_t  queue_id;
9112 };
9113
9114 static void
9115 cmd_2tuple_filter_parsed(void *parsed_result,
9116                         __attribute__((unused)) struct cmdline *cl,
9117                         __attribute__((unused)) void *data)
9118 {
9119         struct rte_eth_ntuple_filter filter;
9120         struct cmd_2tuple_filter_result *res = parsed_result;
9121         int ret = 0;
9122
9123         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9124         if (ret < 0) {
9125                 printf("ntuple filter is not supported on port %u.\n",
9126                         res->port_id);
9127                 return;
9128         }
9129
9130         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9131
9132         filter.flags = RTE_2TUPLE_FLAGS;
9133         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9134         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9135         filter.proto = res->protocol_value;
9136         filter.priority = res->priority_value;
9137         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9138                 printf("nonzero tcp_flags is only meaningful"
9139                         " when protocol is TCP.\n");
9140                 return;
9141         }
9142         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9143                 printf("invalid TCP flags.\n");
9144                 return;
9145         }
9146
9147         if (res->tcp_flags_value != 0) {
9148                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9149                 filter.tcp_flags = res->tcp_flags_value;
9150         }
9151
9152         /* need convert to big endian. */
9153         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9154         filter.queue = res->queue_id;
9155
9156         if (!strcmp(res->ops, "add"))
9157                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9158                                 RTE_ETH_FILTER_NTUPLE,
9159                                 RTE_ETH_FILTER_ADD,
9160                                 &filter);
9161         else
9162                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9163                                 RTE_ETH_FILTER_NTUPLE,
9164                                 RTE_ETH_FILTER_DELETE,
9165                                 &filter);
9166         if (ret < 0)
9167                 printf("2tuple filter programming error: (%s)\n",
9168                         strerror(-ret));
9169
9170 }
9171
9172 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9173         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9174                                  filter, "2tuple_filter");
9175 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9176         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9177                                 port_id, UINT16);
9178 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9179         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9180                                  ops, "add#del");
9181 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9182         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9183                                 dst_port, "dst_port");
9184 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9185         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9186                                 dst_port_value, UINT16);
9187 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9188         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9189                                 protocol, "protocol");
9190 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9191         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9192                                 protocol_value, UINT8);
9193 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9194         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9195                                 mask, "mask");
9196 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9197         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9198                                 mask_value, INT8);
9199 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9200         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9201                                 tcp_flags, "tcp_flags");
9202 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9203         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9204                                 tcp_flags_value, UINT8);
9205 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9206         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9207                                 priority, "priority");
9208 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9209         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9210                                 priority_value, UINT8);
9211 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9212         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9213                                 queue, "queue");
9214 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9215         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9216                                 queue_id, UINT16);
9217
9218 cmdline_parse_inst_t cmd_2tuple_filter = {
9219         .f = cmd_2tuple_filter_parsed,
9220         .data = NULL,
9221         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9222                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9223                 "<queue_id>: Add a 2tuple filter",
9224         .tokens = {
9225                 (void *)&cmd_2tuple_filter_filter,
9226                 (void *)&cmd_2tuple_filter_port_id,
9227                 (void *)&cmd_2tuple_filter_ops,
9228                 (void *)&cmd_2tuple_filter_dst_port,
9229                 (void *)&cmd_2tuple_filter_dst_port_value,
9230                 (void *)&cmd_2tuple_filter_protocol,
9231                 (void *)&cmd_2tuple_filter_protocol_value,
9232                 (void *)&cmd_2tuple_filter_mask,
9233                 (void *)&cmd_2tuple_filter_mask_value,
9234                 (void *)&cmd_2tuple_filter_tcp_flags,
9235                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9236                 (void *)&cmd_2tuple_filter_priority,
9237                 (void *)&cmd_2tuple_filter_priority_value,
9238                 (void *)&cmd_2tuple_filter_queue,
9239                 (void *)&cmd_2tuple_filter_queue_id,
9240                 NULL,
9241         },
9242 };
9243
9244 /* *** ADD/REMOVE A 5tuple FILTER *** */
9245 struct cmd_5tuple_filter_result {
9246         cmdline_fixed_string_t filter;
9247         portid_t port_id;
9248         cmdline_fixed_string_t ops;
9249         cmdline_fixed_string_t dst_ip;
9250         cmdline_ipaddr_t dst_ip_value;
9251         cmdline_fixed_string_t src_ip;
9252         cmdline_ipaddr_t src_ip_value;
9253         cmdline_fixed_string_t dst_port;
9254         uint16_t dst_port_value;
9255         cmdline_fixed_string_t src_port;
9256         uint16_t src_port_value;
9257         cmdline_fixed_string_t protocol;
9258         uint8_t protocol_value;
9259         cmdline_fixed_string_t mask;
9260         uint8_t  mask_value;
9261         cmdline_fixed_string_t tcp_flags;
9262         uint8_t tcp_flags_value;
9263         cmdline_fixed_string_t priority;
9264         uint8_t  priority_value;
9265         cmdline_fixed_string_t queue;
9266         uint16_t  queue_id;
9267 };
9268
9269 static void
9270 cmd_5tuple_filter_parsed(void *parsed_result,
9271                         __attribute__((unused)) struct cmdline *cl,
9272                         __attribute__((unused)) void *data)
9273 {
9274         struct rte_eth_ntuple_filter filter;
9275         struct cmd_5tuple_filter_result *res = parsed_result;
9276         int ret = 0;
9277
9278         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9279         if (ret < 0) {
9280                 printf("ntuple filter is not supported on port %u.\n",
9281                         res->port_id);
9282                 return;
9283         }
9284
9285         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9286
9287         filter.flags = RTE_5TUPLE_FLAGS;
9288         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9289         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9290         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9291         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9292         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9293         filter.proto = res->protocol_value;
9294         filter.priority = res->priority_value;
9295         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9296                 printf("nonzero tcp_flags is only meaningful"
9297                         " when protocol is TCP.\n");
9298                 return;
9299         }
9300         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9301                 printf("invalid TCP flags.\n");
9302                 return;
9303         }
9304
9305         if (res->tcp_flags_value != 0) {
9306                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9307                 filter.tcp_flags = res->tcp_flags_value;
9308         }
9309
9310         if (res->dst_ip_value.family == AF_INET)
9311                 /* no need to convert, already big endian. */
9312                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9313         else {
9314                 if (filter.dst_ip_mask == 0) {
9315                         printf("can not support ipv6 involved compare.\n");
9316                         return;
9317                 }
9318                 filter.dst_ip = 0;
9319         }
9320
9321         if (res->src_ip_value.family == AF_INET)
9322                 /* no need to convert, already big endian. */
9323                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9324         else {
9325                 if (filter.src_ip_mask == 0) {
9326                         printf("can not support ipv6 involved compare.\n");
9327                         return;
9328                 }
9329                 filter.src_ip = 0;
9330         }
9331         /* need convert to big endian. */
9332         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9333         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9334         filter.queue = res->queue_id;
9335
9336         if (!strcmp(res->ops, "add"))
9337                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9338                                 RTE_ETH_FILTER_NTUPLE,
9339                                 RTE_ETH_FILTER_ADD,
9340                                 &filter);
9341         else
9342                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9343                                 RTE_ETH_FILTER_NTUPLE,
9344                                 RTE_ETH_FILTER_DELETE,
9345                                 &filter);
9346         if (ret < 0)
9347                 printf("5tuple filter programming error: (%s)\n",
9348                         strerror(-ret));
9349 }
9350
9351 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9352         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9353                                  filter, "5tuple_filter");
9354 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9355         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9356                                 port_id, UINT16);
9357 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9358         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9359                                  ops, "add#del");
9360 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9361         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9362                                 dst_ip, "dst_ip");
9363 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9364         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9365                                 dst_ip_value);
9366 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9367         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9368                                 src_ip, "src_ip");
9369 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9370         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9371                                 src_ip_value);
9372 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9373         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9374                                 dst_port, "dst_port");
9375 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9376         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9377                                 dst_port_value, UINT16);
9378 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9379         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9380                                 src_port, "src_port");
9381 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9382         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9383                                 src_port_value, UINT16);
9384 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9385         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9386                                 protocol, "protocol");
9387 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9388         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9389                                 protocol_value, UINT8);
9390 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9391         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9392                                 mask, "mask");
9393 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9394         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9395                                 mask_value, INT8);
9396 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9397         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9398                                 tcp_flags, "tcp_flags");
9399 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9400         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9401                                 tcp_flags_value, UINT8);
9402 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9403         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9404                                 priority, "priority");
9405 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9406         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9407                                 priority_value, UINT8);
9408 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9409         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9410                                 queue, "queue");
9411 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9412         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9413                                 queue_id, UINT16);
9414
9415 cmdline_parse_inst_t cmd_5tuple_filter = {
9416         .f = cmd_5tuple_filter_parsed,
9417         .data = NULL,
9418         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9419                 "src_ip <value> dst_port <value> src_port <value> "
9420                 "protocol <value>  mask <value> tcp_flags <value> "
9421                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9422         .tokens = {
9423                 (void *)&cmd_5tuple_filter_filter,
9424                 (void *)&cmd_5tuple_filter_port_id,
9425                 (void *)&cmd_5tuple_filter_ops,
9426                 (void *)&cmd_5tuple_filter_dst_ip,
9427                 (void *)&cmd_5tuple_filter_dst_ip_value,
9428                 (void *)&cmd_5tuple_filter_src_ip,
9429                 (void *)&cmd_5tuple_filter_src_ip_value,
9430                 (void *)&cmd_5tuple_filter_dst_port,
9431                 (void *)&cmd_5tuple_filter_dst_port_value,
9432                 (void *)&cmd_5tuple_filter_src_port,
9433                 (void *)&cmd_5tuple_filter_src_port_value,
9434                 (void *)&cmd_5tuple_filter_protocol,
9435                 (void *)&cmd_5tuple_filter_protocol_value,
9436                 (void *)&cmd_5tuple_filter_mask,
9437                 (void *)&cmd_5tuple_filter_mask_value,
9438                 (void *)&cmd_5tuple_filter_tcp_flags,
9439                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9440                 (void *)&cmd_5tuple_filter_priority,
9441                 (void *)&cmd_5tuple_filter_priority_value,
9442                 (void *)&cmd_5tuple_filter_queue,
9443                 (void *)&cmd_5tuple_filter_queue_id,
9444                 NULL,
9445         },
9446 };
9447
9448 /* *** ADD/REMOVE A flex FILTER *** */
9449 struct cmd_flex_filter_result {
9450         cmdline_fixed_string_t filter;
9451         cmdline_fixed_string_t ops;
9452         portid_t port_id;
9453         cmdline_fixed_string_t len;
9454         uint8_t len_value;
9455         cmdline_fixed_string_t bytes;
9456         cmdline_fixed_string_t bytes_value;
9457         cmdline_fixed_string_t mask;
9458         cmdline_fixed_string_t mask_value;
9459         cmdline_fixed_string_t priority;
9460         uint8_t priority_value;
9461         cmdline_fixed_string_t queue;
9462         uint16_t queue_id;
9463 };
9464
9465 static int xdigit2val(unsigned char c)
9466 {
9467         int val;
9468         if (isdigit(c))
9469                 val = c - '0';
9470         else if (isupper(c))
9471                 val = c - 'A' + 10;
9472         else
9473                 val = c - 'a' + 10;
9474         return val;
9475 }
9476
9477 static void
9478 cmd_flex_filter_parsed(void *parsed_result,
9479                           __attribute__((unused)) struct cmdline *cl,
9480                           __attribute__((unused)) void *data)
9481 {
9482         int ret = 0;
9483         struct rte_eth_flex_filter filter;
9484         struct cmd_flex_filter_result *res = parsed_result;
9485         char *bytes_ptr, *mask_ptr;
9486         uint16_t len, i, j = 0;
9487         char c;
9488         int val;
9489         uint8_t byte = 0;
9490
9491         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9492                 printf("the len exceed the max length 128\n");
9493                 return;
9494         }
9495         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9496         filter.len = res->len_value;
9497         filter.priority = res->priority_value;
9498         filter.queue = res->queue_id;
9499         bytes_ptr = res->bytes_value;
9500         mask_ptr = res->mask_value;
9501
9502          /* translate bytes string to array. */
9503         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9504                 (bytes_ptr[1] == 'X')))
9505                 bytes_ptr += 2;
9506         len = strnlen(bytes_ptr, res->len_value * 2);
9507         if (len == 0 || (len % 8 != 0)) {
9508                 printf("please check len and bytes input\n");
9509                 return;
9510         }
9511         for (i = 0; i < len; i++) {
9512                 c = bytes_ptr[i];
9513                 if (isxdigit(c) == 0) {
9514                         /* invalid characters. */
9515                         printf("invalid input\n");
9516                         return;
9517                 }
9518                 val = xdigit2val(c);
9519                 if (i % 2) {
9520                         byte |= val;
9521                         filter.bytes[j] = byte;
9522                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9523                         j++;
9524                         byte = 0;
9525                 } else
9526                         byte |= val << 4;
9527         }
9528         printf("\n");
9529          /* translate mask string to uint8_t array. */
9530         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9531                 (mask_ptr[1] == 'X')))
9532                 mask_ptr += 2;
9533         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9534         if (len == 0) {
9535                 printf("invalid input\n");
9536                 return;
9537         }
9538         j = 0;
9539         byte = 0;
9540         for (i = 0; i < len; i++) {
9541                 c = mask_ptr[i];
9542                 if (isxdigit(c) == 0) {
9543                         /* invalid characters. */
9544                         printf("invalid input\n");
9545                         return;
9546                 }
9547                 val = xdigit2val(c);
9548                 if (i % 2) {
9549                         byte |= val;
9550                         filter.mask[j] = byte;
9551                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9552                         j++;
9553                         byte = 0;
9554                 } else
9555                         byte |= val << 4;
9556         }
9557         printf("\n");
9558
9559         if (!strcmp(res->ops, "add"))
9560                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9561                                 RTE_ETH_FILTER_FLEXIBLE,
9562                                 RTE_ETH_FILTER_ADD,
9563                                 &filter);
9564         else
9565                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9566                                 RTE_ETH_FILTER_FLEXIBLE,
9567                                 RTE_ETH_FILTER_DELETE,
9568                                 &filter);
9569
9570         if (ret < 0)
9571                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9572 }
9573
9574 cmdline_parse_token_string_t cmd_flex_filter_filter =
9575         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9576                                 filter, "flex_filter");
9577 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9578         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9579                                 port_id, UINT16);
9580 cmdline_parse_token_string_t cmd_flex_filter_ops =
9581         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9582                                 ops, "add#del");
9583 cmdline_parse_token_string_t cmd_flex_filter_len =
9584         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9585                                 len, "len");
9586 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9587         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9588                                 len_value, UINT8);
9589 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9590         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9591                                 bytes, "bytes");
9592 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9593         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9594                                 bytes_value, NULL);
9595 cmdline_parse_token_string_t cmd_flex_filter_mask =
9596         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9597                                 mask, "mask");
9598 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9599         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9600                                 mask_value, NULL);
9601 cmdline_parse_token_string_t cmd_flex_filter_priority =
9602         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9603                                 priority, "priority");
9604 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9605         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9606                                 priority_value, UINT8);
9607 cmdline_parse_token_string_t cmd_flex_filter_queue =
9608         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9609                                 queue, "queue");
9610 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9611         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9612                                 queue_id, UINT16);
9613 cmdline_parse_inst_t cmd_flex_filter = {
9614         .f = cmd_flex_filter_parsed,
9615         .data = NULL,
9616         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9617                 "<value> mask <value> priority <value> queue <queue_id>: "
9618                 "Add/Del a flex filter",
9619         .tokens = {
9620                 (void *)&cmd_flex_filter_filter,
9621                 (void *)&cmd_flex_filter_port_id,
9622                 (void *)&cmd_flex_filter_ops,
9623                 (void *)&cmd_flex_filter_len,
9624                 (void *)&cmd_flex_filter_len_value,
9625                 (void *)&cmd_flex_filter_bytes,
9626                 (void *)&cmd_flex_filter_bytes_value,
9627                 (void *)&cmd_flex_filter_mask,
9628                 (void *)&cmd_flex_filter_mask_value,
9629                 (void *)&cmd_flex_filter_priority,
9630                 (void *)&cmd_flex_filter_priority_value,
9631                 (void *)&cmd_flex_filter_queue,
9632                 (void *)&cmd_flex_filter_queue_id,
9633                 NULL,
9634         },
9635 };
9636
9637 /* *** Filters Control *** */
9638
9639 /* *** deal with ethertype filter *** */
9640 struct cmd_ethertype_filter_result {
9641         cmdline_fixed_string_t filter;
9642         portid_t port_id;
9643         cmdline_fixed_string_t ops;
9644         cmdline_fixed_string_t mac;
9645         struct ether_addr mac_addr;
9646         cmdline_fixed_string_t ethertype;
9647         uint16_t ethertype_value;
9648         cmdline_fixed_string_t drop;
9649         cmdline_fixed_string_t queue;
9650         uint16_t  queue_id;
9651 };
9652
9653 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9654         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9655                                  filter, "ethertype_filter");
9656 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9657         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9658                               port_id, UINT16);
9659 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9660         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9661                                  ops, "add#del");
9662 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9663         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9664                                  mac, "mac_addr#mac_ignr");
9665 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9666         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9667                                      mac_addr);
9668 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9669         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9670                                  ethertype, "ethertype");
9671 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9672         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9673                               ethertype_value, UINT16);
9674 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9675         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9676                                  drop, "drop#fwd");
9677 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9678         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9679                                  queue, "queue");
9680 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9681         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9682                               queue_id, UINT16);
9683
9684 static void
9685 cmd_ethertype_filter_parsed(void *parsed_result,
9686                           __attribute__((unused)) struct cmdline *cl,
9687                           __attribute__((unused)) void *data)
9688 {
9689         struct cmd_ethertype_filter_result *res = parsed_result;
9690         struct rte_eth_ethertype_filter filter;
9691         int ret = 0;
9692
9693         ret = rte_eth_dev_filter_supported(res->port_id,
9694                         RTE_ETH_FILTER_ETHERTYPE);
9695         if (ret < 0) {
9696                 printf("ethertype filter is not supported on port %u.\n",
9697                         res->port_id);
9698                 return;
9699         }
9700
9701         memset(&filter, 0, sizeof(filter));
9702         if (!strcmp(res->mac, "mac_addr")) {
9703                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9704                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9705                         sizeof(struct ether_addr));
9706         }
9707         if (!strcmp(res->drop, "drop"))
9708                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9709         filter.ether_type = res->ethertype_value;
9710         filter.queue = res->queue_id;
9711
9712         if (!strcmp(res->ops, "add"))
9713                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9714                                 RTE_ETH_FILTER_ETHERTYPE,
9715                                 RTE_ETH_FILTER_ADD,
9716                                 &filter);
9717         else
9718                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9719                                 RTE_ETH_FILTER_ETHERTYPE,
9720                                 RTE_ETH_FILTER_DELETE,
9721                                 &filter);
9722         if (ret < 0)
9723                 printf("ethertype filter programming error: (%s)\n",
9724                         strerror(-ret));
9725 }
9726
9727 cmdline_parse_inst_t cmd_ethertype_filter = {
9728         .f = cmd_ethertype_filter_parsed,
9729         .data = NULL,
9730         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9731                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9732                 "Add or delete an ethertype filter entry",
9733         .tokens = {
9734                 (void *)&cmd_ethertype_filter_filter,
9735                 (void *)&cmd_ethertype_filter_port_id,
9736                 (void *)&cmd_ethertype_filter_ops,
9737                 (void *)&cmd_ethertype_filter_mac,
9738                 (void *)&cmd_ethertype_filter_mac_addr,
9739                 (void *)&cmd_ethertype_filter_ethertype,
9740                 (void *)&cmd_ethertype_filter_ethertype_value,
9741                 (void *)&cmd_ethertype_filter_drop,
9742                 (void *)&cmd_ethertype_filter_queue,
9743                 (void *)&cmd_ethertype_filter_queue_id,
9744                 NULL,
9745         },
9746 };
9747
9748 /* *** deal with flow director filter *** */
9749 struct cmd_flow_director_result {
9750         cmdline_fixed_string_t flow_director_filter;
9751         portid_t port_id;
9752         cmdline_fixed_string_t mode;
9753         cmdline_fixed_string_t mode_value;
9754         cmdline_fixed_string_t ops;
9755         cmdline_fixed_string_t flow;
9756         cmdline_fixed_string_t flow_type;
9757         cmdline_fixed_string_t ether;
9758         uint16_t ether_type;
9759         cmdline_fixed_string_t src;
9760         cmdline_ipaddr_t ip_src;
9761         uint16_t port_src;
9762         cmdline_fixed_string_t dst;
9763         cmdline_ipaddr_t ip_dst;
9764         uint16_t port_dst;
9765         cmdline_fixed_string_t verify_tag;
9766         uint32_t verify_tag_value;
9767         cmdline_ipaddr_t tos;
9768         uint8_t tos_value;
9769         cmdline_ipaddr_t proto;
9770         uint8_t proto_value;
9771         cmdline_ipaddr_t ttl;
9772         uint8_t ttl_value;
9773         cmdline_fixed_string_t vlan;
9774         uint16_t vlan_value;
9775         cmdline_fixed_string_t flexbytes;
9776         cmdline_fixed_string_t flexbytes_value;
9777         cmdline_fixed_string_t pf_vf;
9778         cmdline_fixed_string_t drop;
9779         cmdline_fixed_string_t queue;
9780         uint16_t  queue_id;
9781         cmdline_fixed_string_t fd_id;
9782         uint32_t  fd_id_value;
9783         cmdline_fixed_string_t mac;
9784         struct ether_addr mac_addr;
9785         cmdline_fixed_string_t tunnel;
9786         cmdline_fixed_string_t tunnel_type;
9787         cmdline_fixed_string_t tunnel_id;
9788         uint32_t tunnel_id_value;
9789 };
9790
9791 static inline int
9792 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9793 {
9794         char s[256];
9795         const char *p, *p0 = q_arg;
9796         char *end;
9797         unsigned long int_fld;
9798         char *str_fld[max_num];
9799         int i;
9800         unsigned size;
9801         int ret = -1;
9802
9803         p = strchr(p0, '(');
9804         if (p == NULL)
9805                 return -1;
9806         ++p;
9807         p0 = strchr(p, ')');
9808         if (p0 == NULL)
9809                 return -1;
9810
9811         size = p0 - p;
9812         if (size >= sizeof(s))
9813                 return -1;
9814
9815         snprintf(s, sizeof(s), "%.*s", size, p);
9816         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9817         if (ret < 0 || ret > max_num)
9818                 return -1;
9819         for (i = 0; i < ret; i++) {
9820                 errno = 0;
9821                 int_fld = strtoul(str_fld[i], &end, 0);
9822                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9823                         return -1;
9824                 flexbytes[i] = (uint8_t)int_fld;
9825         }
9826         return ret;
9827 }
9828
9829 static uint16_t
9830 str2flowtype(char *string)
9831 {
9832         uint8_t i = 0;
9833         static const struct {
9834                 char str[32];
9835                 uint16_t type;
9836         } flowtype_str[] = {
9837                 {"raw", RTE_ETH_FLOW_RAW},
9838                 {"ipv4", RTE_ETH_FLOW_IPV4},
9839                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9840                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9841                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9842                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9843                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9844                 {"ipv6", RTE_ETH_FLOW_IPV6},
9845                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9846                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9847                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9848                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9849                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9850                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9851         };
9852
9853         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9854                 if (!strcmp(flowtype_str[i].str, string))
9855                         return flowtype_str[i].type;
9856         }
9857
9858         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9859                 return (uint16_t)atoi(string);
9860
9861         return RTE_ETH_FLOW_UNKNOWN;
9862 }
9863
9864 static enum rte_eth_fdir_tunnel_type
9865 str2fdir_tunneltype(char *string)
9866 {
9867         uint8_t i = 0;
9868
9869         static const struct {
9870                 char str[32];
9871                 enum rte_eth_fdir_tunnel_type type;
9872         } tunneltype_str[] = {
9873                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9874                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9875         };
9876
9877         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9878                 if (!strcmp(tunneltype_str[i].str, string))
9879                         return tunneltype_str[i].type;
9880         }
9881         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9882 }
9883
9884 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9885 do { \
9886         if ((ip_addr).family == AF_INET) \
9887                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9888         else { \
9889                 printf("invalid parameter.\n"); \
9890                 return; \
9891         } \
9892 } while (0)
9893
9894 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9895 do { \
9896         if ((ip_addr).family == AF_INET6) \
9897                 rte_memcpy(&(ip), \
9898                                  &((ip_addr).addr.ipv6), \
9899                                  sizeof(struct in6_addr)); \
9900         else { \
9901                 printf("invalid parameter.\n"); \
9902                 return; \
9903         } \
9904 } while (0)
9905
9906 static void
9907 cmd_flow_director_filter_parsed(void *parsed_result,
9908                           __attribute__((unused)) struct cmdline *cl,
9909                           __attribute__((unused)) void *data)
9910 {
9911         struct cmd_flow_director_result *res = parsed_result;
9912         struct rte_eth_fdir_filter entry;
9913         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9914         char *end;
9915         unsigned long vf_id;
9916         int ret = 0;
9917
9918         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9919         if (ret < 0) {
9920                 printf("flow director is not supported on port %u.\n",
9921                         res->port_id);
9922                 return;
9923         }
9924         memset(flexbytes, 0, sizeof(flexbytes));
9925         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9926
9927         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9928                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9929                         printf("Please set mode to MAC-VLAN.\n");
9930                         return;
9931                 }
9932         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9933                 if (strcmp(res->mode_value, "Tunnel")) {
9934                         printf("Please set mode to Tunnel.\n");
9935                         return;
9936                 }
9937         } else {
9938                 if (strcmp(res->mode_value, "IP")) {
9939                         printf("Please set mode to IP.\n");
9940                         return;
9941                 }
9942                 entry.input.flow_type = str2flowtype(res->flow_type);
9943         }
9944
9945         ret = parse_flexbytes(res->flexbytes_value,
9946                                         flexbytes,
9947                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9948         if (ret < 0) {
9949                 printf("error: Cannot parse flexbytes input.\n");
9950                 return;
9951         }
9952
9953         switch (entry.input.flow_type) {
9954         case RTE_ETH_FLOW_FRAG_IPV4:
9955         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9956                 entry.input.flow.ip4_flow.proto = res->proto_value;
9957                 /* fall-through */
9958         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9959         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9960                 IPV4_ADDR_TO_UINT(res->ip_dst,
9961                         entry.input.flow.ip4_flow.dst_ip);
9962                 IPV4_ADDR_TO_UINT(res->ip_src,
9963                         entry.input.flow.ip4_flow.src_ip);
9964                 entry.input.flow.ip4_flow.tos = res->tos_value;
9965                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9966                 /* need convert to big endian. */
9967                 entry.input.flow.udp4_flow.dst_port =
9968                                 rte_cpu_to_be_16(res->port_dst);
9969                 entry.input.flow.udp4_flow.src_port =
9970                                 rte_cpu_to_be_16(res->port_src);
9971                 break;
9972         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9973                 IPV4_ADDR_TO_UINT(res->ip_dst,
9974                         entry.input.flow.sctp4_flow.ip.dst_ip);
9975                 IPV4_ADDR_TO_UINT(res->ip_src,
9976                         entry.input.flow.sctp4_flow.ip.src_ip);
9977                 entry.input.flow.ip4_flow.tos = res->tos_value;
9978                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9979                 /* need convert to big endian. */
9980                 entry.input.flow.sctp4_flow.dst_port =
9981                                 rte_cpu_to_be_16(res->port_dst);
9982                 entry.input.flow.sctp4_flow.src_port =
9983                                 rte_cpu_to_be_16(res->port_src);
9984                 entry.input.flow.sctp4_flow.verify_tag =
9985                                 rte_cpu_to_be_32(res->verify_tag_value);
9986                 break;
9987         case RTE_ETH_FLOW_FRAG_IPV6:
9988         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9989                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9990                 /* fall-through */
9991         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9992         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9993                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9994                         entry.input.flow.ipv6_flow.dst_ip);
9995                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9996                         entry.input.flow.ipv6_flow.src_ip);
9997                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9998                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9999                 /* need convert to big endian. */
10000                 entry.input.flow.udp6_flow.dst_port =
10001                                 rte_cpu_to_be_16(res->port_dst);
10002                 entry.input.flow.udp6_flow.src_port =
10003                                 rte_cpu_to_be_16(res->port_src);
10004                 break;
10005         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
10006                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
10007                         entry.input.flow.sctp6_flow.ip.dst_ip);
10008                 IPV6_ADDR_TO_ARRAY(res->ip_src,
10009                         entry.input.flow.sctp6_flow.ip.src_ip);
10010                 entry.input.flow.ipv6_flow.tc = res->tos_value;
10011                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
10012                 /* need convert to big endian. */
10013                 entry.input.flow.sctp6_flow.dst_port =
10014                                 rte_cpu_to_be_16(res->port_dst);
10015                 entry.input.flow.sctp6_flow.src_port =
10016                                 rte_cpu_to_be_16(res->port_src);
10017                 entry.input.flow.sctp6_flow.verify_tag =
10018                                 rte_cpu_to_be_32(res->verify_tag_value);
10019                 break;
10020         case RTE_ETH_FLOW_L2_PAYLOAD:
10021                 entry.input.flow.l2_flow.ether_type =
10022                         rte_cpu_to_be_16(res->ether_type);
10023                 break;
10024         default:
10025                 break;
10026         }
10027
10028         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10029                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10030                                  &res->mac_addr,
10031                                  sizeof(struct ether_addr));
10032
10033         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10034                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10035                                  &res->mac_addr,
10036                                  sizeof(struct ether_addr));
10037                 entry.input.flow.tunnel_flow.tunnel_type =
10038                         str2fdir_tunneltype(res->tunnel_type);
10039                 entry.input.flow.tunnel_flow.tunnel_id =
10040                         rte_cpu_to_be_32(res->tunnel_id_value);
10041         }
10042
10043         rte_memcpy(entry.input.flow_ext.flexbytes,
10044                    flexbytes,
10045                    RTE_ETH_FDIR_MAX_FLEXLEN);
10046
10047         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10048
10049         entry.action.flex_off = 0;  /*use 0 by default */
10050         if (!strcmp(res->drop, "drop"))
10051                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10052         else
10053                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10054
10055         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10056             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10057                 if (!strcmp(res->pf_vf, "pf"))
10058                         entry.input.flow_ext.is_vf = 0;
10059                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10060                         struct rte_eth_dev_info dev_info;
10061
10062                         memset(&dev_info, 0, sizeof(dev_info));
10063                         rte_eth_dev_info_get(res->port_id, &dev_info);
10064                         errno = 0;
10065                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10066                         if (errno != 0 || *end != '\0' ||
10067                             vf_id >= dev_info.max_vfs) {
10068                                 printf("invalid parameter %s.\n", res->pf_vf);
10069                                 return;
10070                         }
10071                         entry.input.flow_ext.is_vf = 1;
10072                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10073                 } else {
10074                         printf("invalid parameter %s.\n", res->pf_vf);
10075                         return;
10076                 }
10077         }
10078
10079         /* set to report FD ID by default */
10080         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10081         entry.action.rx_queue = res->queue_id;
10082         entry.soft_id = res->fd_id_value;
10083         if (!strcmp(res->ops, "add"))
10084                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10085                                              RTE_ETH_FILTER_ADD, &entry);
10086         else if (!strcmp(res->ops, "del"))
10087                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10088                                              RTE_ETH_FILTER_DELETE, &entry);
10089         else
10090                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10091                                              RTE_ETH_FILTER_UPDATE, &entry);
10092         if (ret < 0)
10093                 printf("flow director programming error: (%s)\n",
10094                         strerror(-ret));
10095 }
10096
10097 cmdline_parse_token_string_t cmd_flow_director_filter =
10098         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10099                                  flow_director_filter, "flow_director_filter");
10100 cmdline_parse_token_num_t cmd_flow_director_port_id =
10101         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10102                               port_id, UINT16);
10103 cmdline_parse_token_string_t cmd_flow_director_ops =
10104         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10105                                  ops, "add#del#update");
10106 cmdline_parse_token_string_t cmd_flow_director_flow =
10107         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10108                                  flow, "flow");
10109 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10110         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10111                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10112                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10113 cmdline_parse_token_string_t cmd_flow_director_ether =
10114         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10115                                  ether, "ether");
10116 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10117         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10118                               ether_type, UINT16);
10119 cmdline_parse_token_string_t cmd_flow_director_src =
10120         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10121                                  src, "src");
10122 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10123         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10124                                  ip_src);
10125 cmdline_parse_token_num_t cmd_flow_director_port_src =
10126         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10127                               port_src, UINT16);
10128 cmdline_parse_token_string_t cmd_flow_director_dst =
10129         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10130                                  dst, "dst");
10131 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10132         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10133                                  ip_dst);
10134 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10135         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10136                               port_dst, UINT16);
10137 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10138         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10139                                   verify_tag, "verify_tag");
10140 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10141         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10142                               verify_tag_value, UINT32);
10143 cmdline_parse_token_string_t cmd_flow_director_tos =
10144         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10145                                  tos, "tos");
10146 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10147         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10148                               tos_value, UINT8);
10149 cmdline_parse_token_string_t cmd_flow_director_proto =
10150         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10151                                  proto, "proto");
10152 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10153         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10154                               proto_value, UINT8);
10155 cmdline_parse_token_string_t cmd_flow_director_ttl =
10156         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10157                                  ttl, "ttl");
10158 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10159         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10160                               ttl_value, UINT8);
10161 cmdline_parse_token_string_t cmd_flow_director_vlan =
10162         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10163                                  vlan, "vlan");
10164 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10165         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10166                               vlan_value, UINT16);
10167 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10168         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10169                                  flexbytes, "flexbytes");
10170 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10171         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10172                               flexbytes_value, NULL);
10173 cmdline_parse_token_string_t cmd_flow_director_drop =
10174         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10175                                  drop, "drop#fwd");
10176 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10177         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10178                               pf_vf, NULL);
10179 cmdline_parse_token_string_t cmd_flow_director_queue =
10180         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10181                                  queue, "queue");
10182 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10183         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10184                               queue_id, UINT16);
10185 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10186         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10187                                  fd_id, "fd_id");
10188 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10189         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10190                               fd_id_value, UINT32);
10191
10192 cmdline_parse_token_string_t cmd_flow_director_mode =
10193         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10194                                  mode, "mode");
10195 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10196         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10197                                  mode_value, "IP");
10198 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10199         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10200                                  mode_value, "MAC-VLAN");
10201 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10202         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10203                                  mode_value, "Tunnel");
10204 cmdline_parse_token_string_t cmd_flow_director_mac =
10205         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10206                                  mac, "mac");
10207 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10208         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10209                                     mac_addr);
10210 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10211         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10212                                  tunnel, "tunnel");
10213 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10214         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10215                                  tunnel_type, "NVGRE#VxLAN");
10216 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10217         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10218                                  tunnel_id, "tunnel-id");
10219 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10220         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10221                               tunnel_id_value, UINT32);
10222
10223 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10224         .f = cmd_flow_director_filter_parsed,
10225         .data = NULL,
10226         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10227                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10228                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10229                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10230                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10231                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10232                 "fd_id <fd_id_value>: "
10233                 "Add or delete an ip flow director entry on NIC",
10234         .tokens = {
10235                 (void *)&cmd_flow_director_filter,
10236                 (void *)&cmd_flow_director_port_id,
10237                 (void *)&cmd_flow_director_mode,
10238                 (void *)&cmd_flow_director_mode_ip,
10239                 (void *)&cmd_flow_director_ops,
10240                 (void *)&cmd_flow_director_flow,
10241                 (void *)&cmd_flow_director_flow_type,
10242                 (void *)&cmd_flow_director_src,
10243                 (void *)&cmd_flow_director_ip_src,
10244                 (void *)&cmd_flow_director_dst,
10245                 (void *)&cmd_flow_director_ip_dst,
10246                 (void *)&cmd_flow_director_tos,
10247                 (void *)&cmd_flow_director_tos_value,
10248                 (void *)&cmd_flow_director_proto,
10249                 (void *)&cmd_flow_director_proto_value,
10250                 (void *)&cmd_flow_director_ttl,
10251                 (void *)&cmd_flow_director_ttl_value,
10252                 (void *)&cmd_flow_director_vlan,
10253                 (void *)&cmd_flow_director_vlan_value,
10254                 (void *)&cmd_flow_director_flexbytes,
10255                 (void *)&cmd_flow_director_flexbytes_value,
10256                 (void *)&cmd_flow_director_drop,
10257                 (void *)&cmd_flow_director_pf_vf,
10258                 (void *)&cmd_flow_director_queue,
10259                 (void *)&cmd_flow_director_queue_id,
10260                 (void *)&cmd_flow_director_fd_id,
10261                 (void *)&cmd_flow_director_fd_id_value,
10262                 NULL,
10263         },
10264 };
10265
10266 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10267         .f = cmd_flow_director_filter_parsed,
10268         .data = NULL,
10269         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10270                 "director entry on NIC",
10271         .tokens = {
10272                 (void *)&cmd_flow_director_filter,
10273                 (void *)&cmd_flow_director_port_id,
10274                 (void *)&cmd_flow_director_mode,
10275                 (void *)&cmd_flow_director_mode_ip,
10276                 (void *)&cmd_flow_director_ops,
10277                 (void *)&cmd_flow_director_flow,
10278                 (void *)&cmd_flow_director_flow_type,
10279                 (void *)&cmd_flow_director_src,
10280                 (void *)&cmd_flow_director_ip_src,
10281                 (void *)&cmd_flow_director_port_src,
10282                 (void *)&cmd_flow_director_dst,
10283                 (void *)&cmd_flow_director_ip_dst,
10284                 (void *)&cmd_flow_director_port_dst,
10285                 (void *)&cmd_flow_director_tos,
10286                 (void *)&cmd_flow_director_tos_value,
10287                 (void *)&cmd_flow_director_ttl,
10288                 (void *)&cmd_flow_director_ttl_value,
10289                 (void *)&cmd_flow_director_vlan,
10290                 (void *)&cmd_flow_director_vlan_value,
10291                 (void *)&cmd_flow_director_flexbytes,
10292                 (void *)&cmd_flow_director_flexbytes_value,
10293                 (void *)&cmd_flow_director_drop,
10294                 (void *)&cmd_flow_director_pf_vf,
10295                 (void *)&cmd_flow_director_queue,
10296                 (void *)&cmd_flow_director_queue_id,
10297                 (void *)&cmd_flow_director_fd_id,
10298                 (void *)&cmd_flow_director_fd_id_value,
10299                 NULL,
10300         },
10301 };
10302
10303 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10304         .f = cmd_flow_director_filter_parsed,
10305         .data = NULL,
10306         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10307                 "director entry on NIC",
10308         .tokens = {
10309                 (void *)&cmd_flow_director_filter,
10310                 (void *)&cmd_flow_director_port_id,
10311                 (void *)&cmd_flow_director_mode,
10312                 (void *)&cmd_flow_director_mode_ip,
10313                 (void *)&cmd_flow_director_ops,
10314                 (void *)&cmd_flow_director_flow,
10315                 (void *)&cmd_flow_director_flow_type,
10316                 (void *)&cmd_flow_director_src,
10317                 (void *)&cmd_flow_director_ip_src,
10318                 (void *)&cmd_flow_director_port_dst,
10319                 (void *)&cmd_flow_director_dst,
10320                 (void *)&cmd_flow_director_ip_dst,
10321                 (void *)&cmd_flow_director_port_dst,
10322                 (void *)&cmd_flow_director_verify_tag,
10323                 (void *)&cmd_flow_director_verify_tag_value,
10324                 (void *)&cmd_flow_director_tos,
10325                 (void *)&cmd_flow_director_tos_value,
10326                 (void *)&cmd_flow_director_ttl,
10327                 (void *)&cmd_flow_director_ttl_value,
10328                 (void *)&cmd_flow_director_vlan,
10329                 (void *)&cmd_flow_director_vlan_value,
10330                 (void *)&cmd_flow_director_flexbytes,
10331                 (void *)&cmd_flow_director_flexbytes_value,
10332                 (void *)&cmd_flow_director_drop,
10333                 (void *)&cmd_flow_director_pf_vf,
10334                 (void *)&cmd_flow_director_queue,
10335                 (void *)&cmd_flow_director_queue_id,
10336                 (void *)&cmd_flow_director_fd_id,
10337                 (void *)&cmd_flow_director_fd_id_value,
10338                 NULL,
10339         },
10340 };
10341
10342 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10343         .f = cmd_flow_director_filter_parsed,
10344         .data = NULL,
10345         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10346                 "director entry on NIC",
10347         .tokens = {
10348                 (void *)&cmd_flow_director_filter,
10349                 (void *)&cmd_flow_director_port_id,
10350                 (void *)&cmd_flow_director_mode,
10351                 (void *)&cmd_flow_director_mode_ip,
10352                 (void *)&cmd_flow_director_ops,
10353                 (void *)&cmd_flow_director_flow,
10354                 (void *)&cmd_flow_director_flow_type,
10355                 (void *)&cmd_flow_director_ether,
10356                 (void *)&cmd_flow_director_ether_type,
10357                 (void *)&cmd_flow_director_flexbytes,
10358                 (void *)&cmd_flow_director_flexbytes_value,
10359                 (void *)&cmd_flow_director_drop,
10360                 (void *)&cmd_flow_director_pf_vf,
10361                 (void *)&cmd_flow_director_queue,
10362                 (void *)&cmd_flow_director_queue_id,
10363                 (void *)&cmd_flow_director_fd_id,
10364                 (void *)&cmd_flow_director_fd_id_value,
10365                 NULL,
10366         },
10367 };
10368
10369 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10370         .f = cmd_flow_director_filter_parsed,
10371         .data = NULL,
10372         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10373                 "director entry on NIC",
10374         .tokens = {
10375                 (void *)&cmd_flow_director_filter,
10376                 (void *)&cmd_flow_director_port_id,
10377                 (void *)&cmd_flow_director_mode,
10378                 (void *)&cmd_flow_director_mode_mac_vlan,
10379                 (void *)&cmd_flow_director_ops,
10380                 (void *)&cmd_flow_director_mac,
10381                 (void *)&cmd_flow_director_mac_addr,
10382                 (void *)&cmd_flow_director_vlan,
10383                 (void *)&cmd_flow_director_vlan_value,
10384                 (void *)&cmd_flow_director_flexbytes,
10385                 (void *)&cmd_flow_director_flexbytes_value,
10386                 (void *)&cmd_flow_director_drop,
10387                 (void *)&cmd_flow_director_queue,
10388                 (void *)&cmd_flow_director_queue_id,
10389                 (void *)&cmd_flow_director_fd_id,
10390                 (void *)&cmd_flow_director_fd_id_value,
10391                 NULL,
10392         },
10393 };
10394
10395 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10396         .f = cmd_flow_director_filter_parsed,
10397         .data = NULL,
10398         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10399                 "director entry on NIC",
10400         .tokens = {
10401                 (void *)&cmd_flow_director_filter,
10402                 (void *)&cmd_flow_director_port_id,
10403                 (void *)&cmd_flow_director_mode,
10404                 (void *)&cmd_flow_director_mode_tunnel,
10405                 (void *)&cmd_flow_director_ops,
10406                 (void *)&cmd_flow_director_mac,
10407                 (void *)&cmd_flow_director_mac_addr,
10408                 (void *)&cmd_flow_director_vlan,
10409                 (void *)&cmd_flow_director_vlan_value,
10410                 (void *)&cmd_flow_director_tunnel,
10411                 (void *)&cmd_flow_director_tunnel_type,
10412                 (void *)&cmd_flow_director_tunnel_id,
10413                 (void *)&cmd_flow_director_tunnel_id_value,
10414                 (void *)&cmd_flow_director_flexbytes,
10415                 (void *)&cmd_flow_director_flexbytes_value,
10416                 (void *)&cmd_flow_director_drop,
10417                 (void *)&cmd_flow_director_queue,
10418                 (void *)&cmd_flow_director_queue_id,
10419                 (void *)&cmd_flow_director_fd_id,
10420                 (void *)&cmd_flow_director_fd_id_value,
10421                 NULL,
10422         },
10423 };
10424
10425 struct cmd_flush_flow_director_result {
10426         cmdline_fixed_string_t flush_flow_director;
10427         portid_t port_id;
10428 };
10429
10430 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10431         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10432                                  flush_flow_director, "flush_flow_director");
10433 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10434         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10435                               port_id, UINT16);
10436
10437 static void
10438 cmd_flush_flow_director_parsed(void *parsed_result,
10439                           __attribute__((unused)) struct cmdline *cl,
10440                           __attribute__((unused)) void *data)
10441 {
10442         struct cmd_flow_director_result *res = parsed_result;
10443         int ret = 0;
10444
10445         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10446         if (ret < 0) {
10447                 printf("flow director is not supported on port %u.\n",
10448                         res->port_id);
10449                 return;
10450         }
10451
10452         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10453                         RTE_ETH_FILTER_FLUSH, NULL);
10454         if (ret < 0)
10455                 printf("flow director table flushing error: (%s)\n",
10456                         strerror(-ret));
10457 }
10458
10459 cmdline_parse_inst_t cmd_flush_flow_director = {
10460         .f = cmd_flush_flow_director_parsed,
10461         .data = NULL,
10462         .help_str = "flush_flow_director <port_id>: "
10463                 "Flush all flow director entries of a device on NIC",
10464         .tokens = {
10465                 (void *)&cmd_flush_flow_director_flush,
10466                 (void *)&cmd_flush_flow_director_port_id,
10467                 NULL,
10468         },
10469 };
10470
10471 /* *** deal with flow director mask *** */
10472 struct cmd_flow_director_mask_result {
10473         cmdline_fixed_string_t flow_director_mask;
10474         portid_t port_id;
10475         cmdline_fixed_string_t mode;
10476         cmdline_fixed_string_t mode_value;
10477         cmdline_fixed_string_t vlan;
10478         uint16_t vlan_mask;
10479         cmdline_fixed_string_t src_mask;
10480         cmdline_ipaddr_t ipv4_src;
10481         cmdline_ipaddr_t ipv6_src;
10482         uint16_t port_src;
10483         cmdline_fixed_string_t dst_mask;
10484         cmdline_ipaddr_t ipv4_dst;
10485         cmdline_ipaddr_t ipv6_dst;
10486         uint16_t port_dst;
10487         cmdline_fixed_string_t mac;
10488         uint8_t mac_addr_byte_mask;
10489         cmdline_fixed_string_t tunnel_id;
10490         uint32_t tunnel_id_mask;
10491         cmdline_fixed_string_t tunnel_type;
10492         uint8_t tunnel_type_mask;
10493 };
10494
10495 static void
10496 cmd_flow_director_mask_parsed(void *parsed_result,
10497                           __attribute__((unused)) struct cmdline *cl,
10498                           __attribute__((unused)) void *data)
10499 {
10500         struct cmd_flow_director_mask_result *res = parsed_result;
10501         struct rte_eth_fdir_masks *mask;
10502         struct rte_port *port;
10503
10504         if (res->port_id > nb_ports) {
10505                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10506                 return;
10507         }
10508
10509         port = &ports[res->port_id];
10510         /** Check if the port is not started **/
10511         if (port->port_status != RTE_PORT_STOPPED) {
10512                 printf("Please stop port %d first\n", res->port_id);
10513                 return;
10514         }
10515
10516         mask = &port->dev_conf.fdir_conf.mask;
10517
10518         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10519                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10520                         printf("Please set mode to MAC-VLAN.\n");
10521                         return;
10522                 }
10523
10524                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10525         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10526                 if (strcmp(res->mode_value, "Tunnel")) {
10527                         printf("Please set mode to Tunnel.\n");
10528                         return;
10529                 }
10530
10531                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10532                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10533                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10534                 mask->tunnel_type_mask = res->tunnel_type_mask;
10535         } else {
10536                 if (strcmp(res->mode_value, "IP")) {
10537                         printf("Please set mode to IP.\n");
10538                         return;
10539                 }
10540
10541                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10542                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10543                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10544                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10545                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10546                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10547                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10548         }
10549
10550         cmd_reconfig_device_queue(res->port_id, 1, 1);
10551 }
10552
10553 cmdline_parse_token_string_t cmd_flow_director_mask =
10554         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10555                                  flow_director_mask, "flow_director_mask");
10556 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10557         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10558                               port_id, UINT16);
10559 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10560         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10561                                  vlan, "vlan");
10562 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10563         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10564                               vlan_mask, UINT16);
10565 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10566         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10567                                  src_mask, "src_mask");
10568 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10569         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10570                                  ipv4_src);
10571 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10572         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10573                                  ipv6_src);
10574 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10575         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10576                               port_src, UINT16);
10577 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10578         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10579                                  dst_mask, "dst_mask");
10580 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10581         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10582                                  ipv4_dst);
10583 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10584         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10585                                  ipv6_dst);
10586 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10587         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10588                               port_dst, UINT16);
10589
10590 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10591         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10592                                  mode, "mode");
10593 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10594         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10595                                  mode_value, "IP");
10596 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10597         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10598                                  mode_value, "MAC-VLAN");
10599 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10600         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10601                                  mode_value, "Tunnel");
10602 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10603         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10604                                  mac, "mac");
10605 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10606         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10607                               mac_addr_byte_mask, UINT8);
10608 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10609         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10610                                  tunnel_type, "tunnel-type");
10611 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10612         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10613                               tunnel_type_mask, UINT8);
10614 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10615         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10616                                  tunnel_id, "tunnel-id");
10617 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10618         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10619                               tunnel_id_mask, UINT32);
10620
10621 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10622         .f = cmd_flow_director_mask_parsed,
10623         .data = NULL,
10624         .help_str = "flow_director_mask ... : "
10625                 "Set IP mode flow director's mask on NIC",
10626         .tokens = {
10627                 (void *)&cmd_flow_director_mask,
10628                 (void *)&cmd_flow_director_mask_port_id,
10629                 (void *)&cmd_flow_director_mask_mode,
10630                 (void *)&cmd_flow_director_mask_mode_ip,
10631                 (void *)&cmd_flow_director_mask_vlan,
10632                 (void *)&cmd_flow_director_mask_vlan_value,
10633                 (void *)&cmd_flow_director_mask_src,
10634                 (void *)&cmd_flow_director_mask_ipv4_src,
10635                 (void *)&cmd_flow_director_mask_ipv6_src,
10636                 (void *)&cmd_flow_director_mask_port_src,
10637                 (void *)&cmd_flow_director_mask_dst,
10638                 (void *)&cmd_flow_director_mask_ipv4_dst,
10639                 (void *)&cmd_flow_director_mask_ipv6_dst,
10640                 (void *)&cmd_flow_director_mask_port_dst,
10641                 NULL,
10642         },
10643 };
10644
10645 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10646         .f = cmd_flow_director_mask_parsed,
10647         .data = NULL,
10648         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10649                 "flow director's mask on NIC",
10650         .tokens = {
10651                 (void *)&cmd_flow_director_mask,
10652                 (void *)&cmd_flow_director_mask_port_id,
10653                 (void *)&cmd_flow_director_mask_mode,
10654                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10655                 (void *)&cmd_flow_director_mask_vlan,
10656                 (void *)&cmd_flow_director_mask_vlan_value,
10657                 NULL,
10658         },
10659 };
10660
10661 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10662         .f = cmd_flow_director_mask_parsed,
10663         .data = NULL,
10664         .help_str = "flow_director_mask ... : Set tunnel mode "
10665                 "flow director's mask on NIC",
10666         .tokens = {
10667                 (void *)&cmd_flow_director_mask,
10668                 (void *)&cmd_flow_director_mask_port_id,
10669                 (void *)&cmd_flow_director_mask_mode,
10670                 (void *)&cmd_flow_director_mask_mode_tunnel,
10671                 (void *)&cmd_flow_director_mask_vlan,
10672                 (void *)&cmd_flow_director_mask_vlan_value,
10673                 (void *)&cmd_flow_director_mask_mac,
10674                 (void *)&cmd_flow_director_mask_mac_value,
10675                 (void *)&cmd_flow_director_mask_tunnel_type,
10676                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10677                 (void *)&cmd_flow_director_mask_tunnel_id,
10678                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10679                 NULL,
10680         },
10681 };
10682
10683 /* *** deal with flow director mask on flexible payload *** */
10684 struct cmd_flow_director_flex_mask_result {
10685         cmdline_fixed_string_t flow_director_flexmask;
10686         portid_t port_id;
10687         cmdline_fixed_string_t flow;
10688         cmdline_fixed_string_t flow_type;
10689         cmdline_fixed_string_t mask;
10690 };
10691
10692 static void
10693 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10694                           __attribute__((unused)) struct cmdline *cl,
10695                           __attribute__((unused)) void *data)
10696 {
10697         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10698         struct rte_eth_fdir_info fdir_info;
10699         struct rte_eth_fdir_flex_mask flex_mask;
10700         struct rte_port *port;
10701         uint32_t flow_type_mask;
10702         uint16_t i;
10703         int ret;
10704
10705         if (res->port_id > nb_ports) {
10706                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10707                 return;
10708         }
10709
10710         port = &ports[res->port_id];
10711         /** Check if the port is not started **/
10712         if (port->port_status != RTE_PORT_STOPPED) {
10713                 printf("Please stop port %d first\n", res->port_id);
10714                 return;
10715         }
10716
10717         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10718         ret = parse_flexbytes(res->mask,
10719                         flex_mask.mask,
10720                         RTE_ETH_FDIR_MAX_FLEXLEN);
10721         if (ret < 0) {
10722                 printf("error: Cannot parse mask input.\n");
10723                 return;
10724         }
10725
10726         memset(&fdir_info, 0, sizeof(fdir_info));
10727         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10728                                 RTE_ETH_FILTER_INFO, &fdir_info);
10729         if (ret < 0) {
10730                 printf("Cannot get FDir filter info\n");
10731                 return;
10732         }
10733
10734         if (!strcmp(res->flow_type, "none")) {
10735                 /* means don't specify the flow type */
10736                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10737                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10738                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10739                                0, sizeof(struct rte_eth_fdir_flex_mask));
10740                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10741                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10742                                  &flex_mask,
10743                                  sizeof(struct rte_eth_fdir_flex_mask));
10744                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10745                 return;
10746         }
10747         flow_type_mask = fdir_info.flow_types_mask[0];
10748         if (!strcmp(res->flow_type, "all")) {
10749                 if (!flow_type_mask) {
10750                         printf("No flow type supported\n");
10751                         return;
10752                 }
10753                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10754                         if (flow_type_mask & (1 << i)) {
10755                                 flex_mask.flow_type = i;
10756                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10757                         }
10758                 }
10759                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10760                 return;
10761         }
10762         flex_mask.flow_type = str2flowtype(res->flow_type);
10763         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10764                 printf("Flow type %s not supported on port %d\n",
10765                                 res->flow_type, res->port_id);
10766                 return;
10767         }
10768         fdir_set_flex_mask(res->port_id, &flex_mask);
10769         cmd_reconfig_device_queue(res->port_id, 1, 1);
10770 }
10771
10772 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10773         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10774                                  flow_director_flexmask,
10775                                  "flow_director_flex_mask");
10776 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10777         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10778                               port_id, UINT16);
10779 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10780         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10781                                  flow, "flow");
10782 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10783         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10784                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10785                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10786 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10787         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10788                                  mask, NULL);
10789
10790 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10791         .f = cmd_flow_director_flex_mask_parsed,
10792         .data = NULL,
10793         .help_str = "flow_director_flex_mask ... : "
10794                 "Set flow director's flex mask on NIC",
10795         .tokens = {
10796                 (void *)&cmd_flow_director_flexmask,
10797                 (void *)&cmd_flow_director_flexmask_port_id,
10798                 (void *)&cmd_flow_director_flexmask_flow,
10799                 (void *)&cmd_flow_director_flexmask_flow_type,
10800                 (void *)&cmd_flow_director_flexmask_mask,
10801                 NULL,
10802         },
10803 };
10804
10805 /* *** deal with flow director flexible payload configuration *** */
10806 struct cmd_flow_director_flexpayload_result {
10807         cmdline_fixed_string_t flow_director_flexpayload;
10808         portid_t port_id;
10809         cmdline_fixed_string_t payload_layer;
10810         cmdline_fixed_string_t payload_cfg;
10811 };
10812
10813 static inline int
10814 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10815 {
10816         char s[256];
10817         const char *p, *p0 = q_arg;
10818         char *end;
10819         unsigned long int_fld;
10820         char *str_fld[max_num];
10821         int i;
10822         unsigned size;
10823         int ret = -1;
10824
10825         p = strchr(p0, '(');
10826         if (p == NULL)
10827                 return -1;
10828         ++p;
10829         p0 = strchr(p, ')');
10830         if (p0 == NULL)
10831                 return -1;
10832
10833         size = p0 - p;
10834         if (size >= sizeof(s))
10835                 return -1;
10836
10837         snprintf(s, sizeof(s), "%.*s", size, p);
10838         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10839         if (ret < 0 || ret > max_num)
10840                 return -1;
10841         for (i = 0; i < ret; i++) {
10842                 errno = 0;
10843                 int_fld = strtoul(str_fld[i], &end, 0);
10844                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10845                         return -1;
10846                 offsets[i] = (uint16_t)int_fld;
10847         }
10848         return ret;
10849 }
10850
10851 static void
10852 cmd_flow_director_flxpld_parsed(void *parsed_result,
10853                           __attribute__((unused)) struct cmdline *cl,
10854                           __attribute__((unused)) void *data)
10855 {
10856         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10857         struct rte_eth_flex_payload_cfg flex_cfg;
10858         struct rte_port *port;
10859         int ret = 0;
10860
10861         if (res->port_id > nb_ports) {
10862                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10863                 return;
10864         }
10865
10866         port = &ports[res->port_id];
10867         /** Check if the port is not started **/
10868         if (port->port_status != RTE_PORT_STOPPED) {
10869                 printf("Please stop port %d first\n", res->port_id);
10870                 return;
10871         }
10872
10873         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10874
10875         if (!strcmp(res->payload_layer, "raw"))
10876                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10877         else if (!strcmp(res->payload_layer, "l2"))
10878                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10879         else if (!strcmp(res->payload_layer, "l3"))
10880                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10881         else if (!strcmp(res->payload_layer, "l4"))
10882                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10883
10884         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10885                             RTE_ETH_FDIR_MAX_FLEXLEN);
10886         if (ret < 0) {
10887                 printf("error: Cannot parse flex payload input.\n");
10888                 return;
10889         }
10890
10891         fdir_set_flex_payload(res->port_id, &flex_cfg);
10892         cmd_reconfig_device_queue(res->port_id, 1, 1);
10893 }
10894
10895 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10896         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10897                                  flow_director_flexpayload,
10898                                  "flow_director_flex_payload");
10899 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10900         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10901                               port_id, UINT16);
10902 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10903         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10904                                  payload_layer, "raw#l2#l3#l4");
10905 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10906         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10907                                  payload_cfg, NULL);
10908
10909 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10910         .f = cmd_flow_director_flxpld_parsed,
10911         .data = NULL,
10912         .help_str = "flow_director_flexpayload ... : "
10913                 "Set flow director's flex payload on NIC",
10914         .tokens = {
10915                 (void *)&cmd_flow_director_flexpayload,
10916                 (void *)&cmd_flow_director_flexpayload_port_id,
10917                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10918                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10919                 NULL,
10920         },
10921 };
10922
10923 /* Generic flow interface command. */
10924 extern cmdline_parse_inst_t cmd_flow;
10925
10926 /* *** Classification Filters Control *** */
10927 /* *** Get symmetric hash enable per port *** */
10928 struct cmd_get_sym_hash_ena_per_port_result {
10929         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10930         portid_t port_id;
10931 };
10932
10933 static void
10934 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10935                                  __rte_unused struct cmdline *cl,
10936                                  __rte_unused void *data)
10937 {
10938         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10939         struct rte_eth_hash_filter_info info;
10940         int ret;
10941
10942         if (rte_eth_dev_filter_supported(res->port_id,
10943                                 RTE_ETH_FILTER_HASH) < 0) {
10944                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10945                                                         res->port_id);
10946                 return;
10947         }
10948
10949         memset(&info, 0, sizeof(info));
10950         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10951         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10952                                                 RTE_ETH_FILTER_GET, &info);
10953
10954         if (ret < 0) {
10955                 printf("Cannot get symmetric hash enable per port "
10956                                         "on port %u\n", res->port_id);
10957                 return;
10958         }
10959
10960         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10961                                 "enabled" : "disabled", res->port_id);
10962 }
10963
10964 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10965         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10966                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10967 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10968         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10969                 port_id, UINT16);
10970
10971 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10972         .f = cmd_get_sym_hash_per_port_parsed,
10973         .data = NULL,
10974         .help_str = "get_sym_hash_ena_per_port <port_id>",
10975         .tokens = {
10976                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10977                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10978                 NULL,
10979         },
10980 };
10981
10982 /* *** Set symmetric hash enable per port *** */
10983 struct cmd_set_sym_hash_ena_per_port_result {
10984         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10985         cmdline_fixed_string_t enable;
10986         portid_t port_id;
10987 };
10988
10989 static void
10990 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10991                                  __rte_unused struct cmdline *cl,
10992                                  __rte_unused void *data)
10993 {
10994         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10995         struct rte_eth_hash_filter_info info;
10996         int ret;
10997
10998         if (rte_eth_dev_filter_supported(res->port_id,
10999                                 RTE_ETH_FILTER_HASH) < 0) {
11000                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
11001                                                         res->port_id);
11002                 return;
11003         }
11004
11005         memset(&info, 0, sizeof(info));
11006         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
11007         if (!strcmp(res->enable, "enable"))
11008                 info.info.enable = 1;
11009         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11010                                         RTE_ETH_FILTER_SET, &info);
11011         if (ret < 0) {
11012                 printf("Cannot set symmetric hash enable per port on "
11013                                         "port %u\n", res->port_id);
11014                 return;
11015         }
11016         printf("Symmetric hash has been set to %s on port %u\n",
11017                                         res->enable, res->port_id);
11018 }
11019
11020 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11021         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11022                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11023 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11024         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11025                 port_id, UINT16);
11026 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11027         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11028                 enable, "enable#disable");
11029
11030 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11031         .f = cmd_set_sym_hash_per_port_parsed,
11032         .data = NULL,
11033         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11034         .tokens = {
11035                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11036                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11037                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11038                 NULL,
11039         },
11040 };
11041
11042 /* Get global config of hash function */
11043 struct cmd_get_hash_global_config_result {
11044         cmdline_fixed_string_t get_hash_global_config;
11045         portid_t port_id;
11046 };
11047
11048 static char *
11049 flowtype_to_str(uint16_t ftype)
11050 {
11051         uint16_t i;
11052         static struct {
11053                 char str[16];
11054                 uint16_t ftype;
11055         } ftype_table[] = {
11056                 {"ipv4", RTE_ETH_FLOW_IPV4},
11057                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11058                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11059                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11060                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11061                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11062                 {"ipv6", RTE_ETH_FLOW_IPV6},
11063                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11064                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11065                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11066                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11067                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11068                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11069                 {"port", RTE_ETH_FLOW_PORT},
11070                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11071                 {"geneve", RTE_ETH_FLOW_GENEVE},
11072                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11073         };
11074
11075         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11076                 if (ftype_table[i].ftype == ftype)
11077                         return ftype_table[i].str;
11078         }
11079
11080         return NULL;
11081 }
11082
11083 static void
11084 cmd_get_hash_global_config_parsed(void *parsed_result,
11085                                   __rte_unused struct cmdline *cl,
11086                                   __rte_unused void *data)
11087 {
11088         struct cmd_get_hash_global_config_result *res = parsed_result;
11089         struct rte_eth_hash_filter_info info;
11090         uint32_t idx, offset;
11091         uint16_t i;
11092         char *str;
11093         int ret;
11094
11095         if (rte_eth_dev_filter_supported(res->port_id,
11096                         RTE_ETH_FILTER_HASH) < 0) {
11097                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11098                                                         res->port_id);
11099                 return;
11100         }
11101
11102         memset(&info, 0, sizeof(info));
11103         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11104         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11105                                         RTE_ETH_FILTER_GET, &info);
11106         if (ret < 0) {
11107                 printf("Cannot get hash global configurations by port %d\n",
11108                                                         res->port_id);
11109                 return;
11110         }
11111
11112         switch (info.info.global_conf.hash_func) {
11113         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11114                 printf("Hash function is Toeplitz\n");
11115                 break;
11116         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11117                 printf("Hash function is Simple XOR\n");
11118                 break;
11119         default:
11120                 printf("Unknown hash function\n");
11121                 break;
11122         }
11123
11124         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11125                 idx = i / UINT32_BIT;
11126                 offset = i % UINT32_BIT;
11127                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11128                                                 (1UL << offset)))
11129                         continue;
11130                 str = flowtype_to_str(i);
11131                 if (!str)
11132                         continue;
11133                 printf("Symmetric hash is %s globally for flow type %s "
11134                                                         "by port %d\n",
11135                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11136                         (1UL << offset)) ? "enabled" : "disabled"), str,
11137                                                         res->port_id);
11138         }
11139 }
11140
11141 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11142         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11143                 get_hash_global_config, "get_hash_global_config");
11144 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11145         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11146                 port_id, UINT16);
11147
11148 cmdline_parse_inst_t cmd_get_hash_global_config = {
11149         .f = cmd_get_hash_global_config_parsed,
11150         .data = NULL,
11151         .help_str = "get_hash_global_config <port_id>",
11152         .tokens = {
11153                 (void *)&cmd_get_hash_global_config_all,
11154                 (void *)&cmd_get_hash_global_config_port_id,
11155                 NULL,
11156         },
11157 };
11158
11159 /* Set global config of hash function */
11160 struct cmd_set_hash_global_config_result {
11161         cmdline_fixed_string_t set_hash_global_config;
11162         portid_t port_id;
11163         cmdline_fixed_string_t hash_func;
11164         cmdline_fixed_string_t flow_type;
11165         cmdline_fixed_string_t enable;
11166 };
11167
11168 static void
11169 cmd_set_hash_global_config_parsed(void *parsed_result,
11170                                   __rte_unused struct cmdline *cl,
11171                                   __rte_unused void *data)
11172 {
11173         struct cmd_set_hash_global_config_result *res = parsed_result;
11174         struct rte_eth_hash_filter_info info;
11175         uint32_t ftype, idx, offset;
11176         int ret;
11177
11178         if (rte_eth_dev_filter_supported(res->port_id,
11179                                 RTE_ETH_FILTER_HASH) < 0) {
11180                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11181                                                         res->port_id);
11182                 return;
11183         }
11184         memset(&info, 0, sizeof(info));
11185         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11186         if (!strcmp(res->hash_func, "toeplitz"))
11187                 info.info.global_conf.hash_func =
11188                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11189         else if (!strcmp(res->hash_func, "simple_xor"))
11190                 info.info.global_conf.hash_func =
11191                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11192         else if (!strcmp(res->hash_func, "default"))
11193                 info.info.global_conf.hash_func =
11194                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11195
11196         ftype = str2flowtype(res->flow_type);
11197         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11198         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11199         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11200         if (!strcmp(res->enable, "enable"))
11201                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11202                                                 (1UL << offset);
11203         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11204                                         RTE_ETH_FILTER_SET, &info);
11205         if (ret < 0)
11206                 printf("Cannot set global hash configurations by port %d\n",
11207                                                         res->port_id);
11208         else
11209                 printf("Global hash configurations have been set "
11210                         "succcessfully by port %d\n", res->port_id);
11211 }
11212
11213 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11214         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11215                 set_hash_global_config, "set_hash_global_config");
11216 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11217         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11218                 port_id, UINT16);
11219 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11220         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11221                 hash_func, "toeplitz#simple_xor#default");
11222 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11223         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11224                 flow_type,
11225                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11226                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11227 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11228         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11229                 enable, "enable#disable");
11230
11231 cmdline_parse_inst_t cmd_set_hash_global_config = {
11232         .f = cmd_set_hash_global_config_parsed,
11233         .data = NULL,
11234         .help_str = "set_hash_global_config <port_id> "
11235                 "toeplitz|simple_xor|default "
11236                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11237                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11238                 "l2_payload enable|disable",
11239         .tokens = {
11240                 (void *)&cmd_set_hash_global_config_all,
11241                 (void *)&cmd_set_hash_global_config_port_id,
11242                 (void *)&cmd_set_hash_global_config_hash_func,
11243                 (void *)&cmd_set_hash_global_config_flow_type,
11244                 (void *)&cmd_set_hash_global_config_enable,
11245                 NULL,
11246         },
11247 };
11248
11249 /* Set hash input set */
11250 struct cmd_set_hash_input_set_result {
11251         cmdline_fixed_string_t set_hash_input_set;
11252         portid_t port_id;
11253         cmdline_fixed_string_t flow_type;
11254         cmdline_fixed_string_t inset_field;
11255         cmdline_fixed_string_t select;
11256 };
11257
11258 static enum rte_eth_input_set_field
11259 str2inset(char *string)
11260 {
11261         uint16_t i;
11262
11263         static const struct {
11264                 char str[32];
11265                 enum rte_eth_input_set_field inset;
11266         } inset_table[] = {
11267                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11268                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11269                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11270                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11271                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11272                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11273                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11274                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11275                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11276                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11277                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11278                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11279                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11280                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11281                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11282                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11283                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11284                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11285                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11286                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11287                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11288                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11289                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11290                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11291                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11292                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11293                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11294                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11295                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11296                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11297                 {"none", RTE_ETH_INPUT_SET_NONE},
11298         };
11299
11300         for (i = 0; i < RTE_DIM(inset_table); i++) {
11301                 if (!strcmp(string, inset_table[i].str))
11302                         return inset_table[i].inset;
11303         }
11304
11305         return RTE_ETH_INPUT_SET_UNKNOWN;
11306 }
11307
11308 static void
11309 cmd_set_hash_input_set_parsed(void *parsed_result,
11310                               __rte_unused struct cmdline *cl,
11311                               __rte_unused void *data)
11312 {
11313         struct cmd_set_hash_input_set_result *res = parsed_result;
11314         struct rte_eth_hash_filter_info info;
11315
11316         memset(&info, 0, sizeof(info));
11317         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11318         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11319         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11320         info.info.input_set_conf.inset_size = 1;
11321         if (!strcmp(res->select, "select"))
11322                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11323         else if (!strcmp(res->select, "add"))
11324                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11325         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11326                                 RTE_ETH_FILTER_SET, &info);
11327 }
11328
11329 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11330         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11331                 set_hash_input_set, "set_hash_input_set");
11332 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11333         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11334                 port_id, UINT16);
11335 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11336         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11337                 flow_type, NULL);
11338 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11339         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11340                 inset_field,
11341                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11342                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11343                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11344                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11345                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11346                 "fld-8th#none");
11347 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11348         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11349                 select, "select#add");
11350
11351 cmdline_parse_inst_t cmd_set_hash_input_set = {
11352         .f = cmd_set_hash_input_set_parsed,
11353         .data = NULL,
11354         .help_str = "set_hash_input_set <port_id> "
11355         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11356         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11357         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11358         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11359         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11360         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11361         "fld-7th|fld-8th|none select|add",
11362         .tokens = {
11363                 (void *)&cmd_set_hash_input_set_cmd,
11364                 (void *)&cmd_set_hash_input_set_port_id,
11365                 (void *)&cmd_set_hash_input_set_flow_type,
11366                 (void *)&cmd_set_hash_input_set_field,
11367                 (void *)&cmd_set_hash_input_set_select,
11368                 NULL,
11369         },
11370 };
11371
11372 /* Set flow director input set */
11373 struct cmd_set_fdir_input_set_result {
11374         cmdline_fixed_string_t set_fdir_input_set;
11375         portid_t port_id;
11376         cmdline_fixed_string_t flow_type;
11377         cmdline_fixed_string_t inset_field;
11378         cmdline_fixed_string_t select;
11379 };
11380
11381 static void
11382 cmd_set_fdir_input_set_parsed(void *parsed_result,
11383         __rte_unused struct cmdline *cl,
11384         __rte_unused void *data)
11385 {
11386         struct cmd_set_fdir_input_set_result *res = parsed_result;
11387         struct rte_eth_fdir_filter_info info;
11388
11389         memset(&info, 0, sizeof(info));
11390         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11391         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11392         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11393         info.info.input_set_conf.inset_size = 1;
11394         if (!strcmp(res->select, "select"))
11395                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11396         else if (!strcmp(res->select, "add"))
11397                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11398         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11399                 RTE_ETH_FILTER_SET, &info);
11400 }
11401
11402 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11403         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11404         set_fdir_input_set, "set_fdir_input_set");
11405 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11406         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11407         port_id, UINT16);
11408 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11409         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11410         flow_type,
11411         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11412         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11413 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11414         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11415         inset_field,
11416         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11417         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11418         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11419         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11420         "sctp-veri-tag#none");
11421 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11422         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11423         select, "select#add");
11424
11425 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11426         .f = cmd_set_fdir_input_set_parsed,
11427         .data = NULL,
11428         .help_str = "set_fdir_input_set <port_id> "
11429         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11430         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11431         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11432         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11433         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11434         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11435         "sctp-veri-tag|none select|add",
11436         .tokens = {
11437                 (void *)&cmd_set_fdir_input_set_cmd,
11438                 (void *)&cmd_set_fdir_input_set_port_id,
11439                 (void *)&cmd_set_fdir_input_set_flow_type,
11440                 (void *)&cmd_set_fdir_input_set_field,
11441                 (void *)&cmd_set_fdir_input_set_select,
11442                 NULL,
11443         },
11444 };
11445
11446 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11447 struct cmd_mcast_addr_result {
11448         cmdline_fixed_string_t mcast_addr_cmd;
11449         cmdline_fixed_string_t what;
11450         uint16_t port_num;
11451         struct ether_addr mc_addr;
11452 };
11453
11454 static void cmd_mcast_addr_parsed(void *parsed_result,
11455                 __attribute__((unused)) struct cmdline *cl,
11456                 __attribute__((unused)) void *data)
11457 {
11458         struct cmd_mcast_addr_result *res = parsed_result;
11459
11460         if (!is_multicast_ether_addr(&res->mc_addr)) {
11461                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11462                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11463                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11464                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11465                 return;
11466         }
11467         if (strcmp(res->what, "add") == 0)
11468                 mcast_addr_add(res->port_num, &res->mc_addr);
11469         else
11470                 mcast_addr_remove(res->port_num, &res->mc_addr);
11471 }
11472
11473 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11474         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11475                                  mcast_addr_cmd, "mcast_addr");
11476 cmdline_parse_token_string_t cmd_mcast_addr_what =
11477         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11478                                  "add#remove");
11479 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11480         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11481 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11482         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11483
11484 cmdline_parse_inst_t cmd_mcast_addr = {
11485         .f = cmd_mcast_addr_parsed,
11486         .data = (void *)0,
11487         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11488                 "Add/Remove multicast MAC address on port_id",
11489         .tokens = {
11490                 (void *)&cmd_mcast_addr_cmd,
11491                 (void *)&cmd_mcast_addr_what,
11492                 (void *)&cmd_mcast_addr_portnum,
11493                 (void *)&cmd_mcast_addr_addr,
11494                 NULL,
11495         },
11496 };
11497
11498 /* l2 tunnel config
11499  * only support E-tag now.
11500  */
11501
11502 /* Ether type config */
11503 struct cmd_config_l2_tunnel_eth_type_result {
11504         cmdline_fixed_string_t port;
11505         cmdline_fixed_string_t config;
11506         cmdline_fixed_string_t all;
11507         uint8_t id;
11508         cmdline_fixed_string_t l2_tunnel;
11509         cmdline_fixed_string_t l2_tunnel_type;
11510         cmdline_fixed_string_t eth_type;
11511         uint16_t eth_type_val;
11512 };
11513
11514 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11515         TOKEN_STRING_INITIALIZER
11516                 (struct cmd_config_l2_tunnel_eth_type_result,
11517                  port, "port");
11518 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11519         TOKEN_STRING_INITIALIZER
11520                 (struct cmd_config_l2_tunnel_eth_type_result,
11521                  config, "config");
11522 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11523         TOKEN_STRING_INITIALIZER
11524                 (struct cmd_config_l2_tunnel_eth_type_result,
11525                  all, "all");
11526 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11527         TOKEN_NUM_INITIALIZER
11528                 (struct cmd_config_l2_tunnel_eth_type_result,
11529                  id, UINT8);
11530 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11531         TOKEN_STRING_INITIALIZER
11532                 (struct cmd_config_l2_tunnel_eth_type_result,
11533                  l2_tunnel, "l2-tunnel");
11534 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11535         TOKEN_STRING_INITIALIZER
11536                 (struct cmd_config_l2_tunnel_eth_type_result,
11537                  l2_tunnel_type, "E-tag");
11538 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11539         TOKEN_STRING_INITIALIZER
11540                 (struct cmd_config_l2_tunnel_eth_type_result,
11541                  eth_type, "ether-type");
11542 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11543         TOKEN_NUM_INITIALIZER
11544                 (struct cmd_config_l2_tunnel_eth_type_result,
11545                  eth_type_val, UINT16);
11546
11547 static enum rte_eth_tunnel_type
11548 str2fdir_l2_tunnel_type(char *string)
11549 {
11550         uint32_t i = 0;
11551
11552         static const struct {
11553                 char str[32];
11554                 enum rte_eth_tunnel_type type;
11555         } l2_tunnel_type_str[] = {
11556                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11557         };
11558
11559         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11560                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11561                         return l2_tunnel_type_str[i].type;
11562         }
11563         return RTE_TUNNEL_TYPE_NONE;
11564 }
11565
11566 /* ether type config for all ports */
11567 static void
11568 cmd_config_l2_tunnel_eth_type_all_parsed
11569         (void *parsed_result,
11570          __attribute__((unused)) struct cmdline *cl,
11571          __attribute__((unused)) void *data)
11572 {
11573         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11574         struct rte_eth_l2_tunnel_conf entry;
11575         portid_t pid;
11576
11577         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11578         entry.ether_type = res->eth_type_val;
11579
11580         RTE_ETH_FOREACH_DEV(pid) {
11581                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11582         }
11583 }
11584
11585 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11586         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11587         .data = NULL,
11588         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11589         .tokens = {
11590                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11591                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11592                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11593                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11594                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11595                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11596                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11597                 NULL,
11598         },
11599 };
11600
11601 /* ether type config for a specific port */
11602 static void
11603 cmd_config_l2_tunnel_eth_type_specific_parsed(
11604         void *parsed_result,
11605         __attribute__((unused)) struct cmdline *cl,
11606         __attribute__((unused)) void *data)
11607 {
11608         struct cmd_config_l2_tunnel_eth_type_result *res =
11609                  parsed_result;
11610         struct rte_eth_l2_tunnel_conf entry;
11611
11612         if (port_id_is_invalid(res->id, ENABLED_WARN))
11613                 return;
11614
11615         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11616         entry.ether_type = res->eth_type_val;
11617
11618         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11619 }
11620
11621 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11622         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11623         .data = NULL,
11624         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11625         .tokens = {
11626                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11627                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11628                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11629                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11630                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11631                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11632                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11633                 NULL,
11634         },
11635 };
11636
11637 /* Enable/disable l2 tunnel */
11638 struct cmd_config_l2_tunnel_en_dis_result {
11639         cmdline_fixed_string_t port;
11640         cmdline_fixed_string_t config;
11641         cmdline_fixed_string_t all;
11642         uint8_t id;
11643         cmdline_fixed_string_t l2_tunnel;
11644         cmdline_fixed_string_t l2_tunnel_type;
11645         cmdline_fixed_string_t en_dis;
11646 };
11647
11648 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11649         TOKEN_STRING_INITIALIZER
11650                 (struct cmd_config_l2_tunnel_en_dis_result,
11651                  port, "port");
11652 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11653         TOKEN_STRING_INITIALIZER
11654                 (struct cmd_config_l2_tunnel_en_dis_result,
11655                  config, "config");
11656 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11657         TOKEN_STRING_INITIALIZER
11658                 (struct cmd_config_l2_tunnel_en_dis_result,
11659                  all, "all");
11660 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11661         TOKEN_NUM_INITIALIZER
11662                 (struct cmd_config_l2_tunnel_en_dis_result,
11663                  id, UINT8);
11664 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11665         TOKEN_STRING_INITIALIZER
11666                 (struct cmd_config_l2_tunnel_en_dis_result,
11667                  l2_tunnel, "l2-tunnel");
11668 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11669         TOKEN_STRING_INITIALIZER
11670                 (struct cmd_config_l2_tunnel_en_dis_result,
11671                  l2_tunnel_type, "E-tag");
11672 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11673         TOKEN_STRING_INITIALIZER
11674                 (struct cmd_config_l2_tunnel_en_dis_result,
11675                  en_dis, "enable#disable");
11676
11677 /* enable/disable l2 tunnel for all ports */
11678 static void
11679 cmd_config_l2_tunnel_en_dis_all_parsed(
11680         void *parsed_result,
11681         __attribute__((unused)) struct cmdline *cl,
11682         __attribute__((unused)) void *data)
11683 {
11684         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11685         struct rte_eth_l2_tunnel_conf entry;
11686         portid_t pid;
11687         uint8_t en;
11688
11689         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11690
11691         if (!strcmp("enable", res->en_dis))
11692                 en = 1;
11693         else
11694                 en = 0;
11695
11696         RTE_ETH_FOREACH_DEV(pid) {
11697                 rte_eth_dev_l2_tunnel_offload_set(pid,
11698                                                   &entry,
11699                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11700                                                   en);
11701         }
11702 }
11703
11704 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11705         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11706         .data = NULL,
11707         .help_str = "port config all l2-tunnel E-tag enable|disable",
11708         .tokens = {
11709                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11710                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11711                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11712                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11713                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11714                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11715                 NULL,
11716         },
11717 };
11718
11719 /* enable/disable l2 tunnel for a port */
11720 static void
11721 cmd_config_l2_tunnel_en_dis_specific_parsed(
11722         void *parsed_result,
11723         __attribute__((unused)) struct cmdline *cl,
11724         __attribute__((unused)) void *data)
11725 {
11726         struct cmd_config_l2_tunnel_en_dis_result *res =
11727                 parsed_result;
11728         struct rte_eth_l2_tunnel_conf entry;
11729
11730         if (port_id_is_invalid(res->id, ENABLED_WARN))
11731                 return;
11732
11733         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11734
11735         if (!strcmp("enable", res->en_dis))
11736                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11737                                                   &entry,
11738                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11739                                                   1);
11740         else
11741                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11742                                                   &entry,
11743                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11744                                                   0);
11745 }
11746
11747 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11748         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11749         .data = NULL,
11750         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11751         .tokens = {
11752                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11753                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11754                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11755                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11756                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11757                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11758                 NULL,
11759         },
11760 };
11761
11762 /* E-tag configuration */
11763
11764 /* Common result structure for all E-tag configuration */
11765 struct cmd_config_e_tag_result {
11766         cmdline_fixed_string_t e_tag;
11767         cmdline_fixed_string_t set;
11768         cmdline_fixed_string_t insertion;
11769         cmdline_fixed_string_t stripping;
11770         cmdline_fixed_string_t forwarding;
11771         cmdline_fixed_string_t filter;
11772         cmdline_fixed_string_t add;
11773         cmdline_fixed_string_t del;
11774         cmdline_fixed_string_t on;
11775         cmdline_fixed_string_t off;
11776         cmdline_fixed_string_t on_off;
11777         cmdline_fixed_string_t port_tag_id;
11778         uint32_t port_tag_id_val;
11779         cmdline_fixed_string_t e_tag_id;
11780         uint16_t e_tag_id_val;
11781         cmdline_fixed_string_t dst_pool;
11782         uint8_t dst_pool_val;
11783         cmdline_fixed_string_t port;
11784         portid_t port_id;
11785         cmdline_fixed_string_t vf;
11786         uint8_t vf_id;
11787 };
11788
11789 /* Common CLI fields for all E-tag configuration */
11790 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11791         TOKEN_STRING_INITIALIZER
11792                 (struct cmd_config_e_tag_result,
11793                  e_tag, "E-tag");
11794 cmdline_parse_token_string_t cmd_config_e_tag_set =
11795         TOKEN_STRING_INITIALIZER
11796                 (struct cmd_config_e_tag_result,
11797                  set, "set");
11798 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11799         TOKEN_STRING_INITIALIZER
11800                 (struct cmd_config_e_tag_result,
11801                  insertion, "insertion");
11802 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11803         TOKEN_STRING_INITIALIZER
11804                 (struct cmd_config_e_tag_result,
11805                  stripping, "stripping");
11806 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11807         TOKEN_STRING_INITIALIZER
11808                 (struct cmd_config_e_tag_result,
11809                  forwarding, "forwarding");
11810 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11811         TOKEN_STRING_INITIALIZER
11812                 (struct cmd_config_e_tag_result,
11813                  filter, "filter");
11814 cmdline_parse_token_string_t cmd_config_e_tag_add =
11815         TOKEN_STRING_INITIALIZER
11816                 (struct cmd_config_e_tag_result,
11817                  add, "add");
11818 cmdline_parse_token_string_t cmd_config_e_tag_del =
11819         TOKEN_STRING_INITIALIZER
11820                 (struct cmd_config_e_tag_result,
11821                  del, "del");
11822 cmdline_parse_token_string_t cmd_config_e_tag_on =
11823         TOKEN_STRING_INITIALIZER
11824                 (struct cmd_config_e_tag_result,
11825                  on, "on");
11826 cmdline_parse_token_string_t cmd_config_e_tag_off =
11827         TOKEN_STRING_INITIALIZER
11828                 (struct cmd_config_e_tag_result,
11829                  off, "off");
11830 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11831         TOKEN_STRING_INITIALIZER
11832                 (struct cmd_config_e_tag_result,
11833                  on_off, "on#off");
11834 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11835         TOKEN_STRING_INITIALIZER
11836                 (struct cmd_config_e_tag_result,
11837                  port_tag_id, "port-tag-id");
11838 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11839         TOKEN_NUM_INITIALIZER
11840                 (struct cmd_config_e_tag_result,
11841                  port_tag_id_val, UINT32);
11842 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11843         TOKEN_STRING_INITIALIZER
11844                 (struct cmd_config_e_tag_result,
11845                  e_tag_id, "e-tag-id");
11846 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11847         TOKEN_NUM_INITIALIZER
11848                 (struct cmd_config_e_tag_result,
11849                  e_tag_id_val, UINT16);
11850 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11851         TOKEN_STRING_INITIALIZER
11852                 (struct cmd_config_e_tag_result,
11853                  dst_pool, "dst-pool");
11854 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11855         TOKEN_NUM_INITIALIZER
11856                 (struct cmd_config_e_tag_result,
11857                  dst_pool_val, UINT8);
11858 cmdline_parse_token_string_t cmd_config_e_tag_port =
11859         TOKEN_STRING_INITIALIZER
11860                 (struct cmd_config_e_tag_result,
11861                  port, "port");
11862 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11863         TOKEN_NUM_INITIALIZER
11864                 (struct cmd_config_e_tag_result,
11865                  port_id, UINT16);
11866 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11867         TOKEN_STRING_INITIALIZER
11868                 (struct cmd_config_e_tag_result,
11869                  vf, "vf");
11870 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11871         TOKEN_NUM_INITIALIZER
11872                 (struct cmd_config_e_tag_result,
11873                  vf_id, UINT8);
11874
11875 /* E-tag insertion configuration */
11876 static void
11877 cmd_config_e_tag_insertion_en_parsed(
11878         void *parsed_result,
11879         __attribute__((unused)) struct cmdline *cl,
11880         __attribute__((unused)) void *data)
11881 {
11882         struct cmd_config_e_tag_result *res =
11883                 parsed_result;
11884         struct rte_eth_l2_tunnel_conf entry;
11885
11886         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11887                 return;
11888
11889         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11890         entry.tunnel_id = res->port_tag_id_val;
11891         entry.vf_id = res->vf_id;
11892         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11893                                           &entry,
11894                                           ETH_L2_TUNNEL_INSERTION_MASK,
11895                                           1);
11896 }
11897
11898 static void
11899 cmd_config_e_tag_insertion_dis_parsed(
11900         void *parsed_result,
11901         __attribute__((unused)) struct cmdline *cl,
11902         __attribute__((unused)) void *data)
11903 {
11904         struct cmd_config_e_tag_result *res =
11905                 parsed_result;
11906         struct rte_eth_l2_tunnel_conf entry;
11907
11908         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11909                 return;
11910
11911         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11912         entry.vf_id = res->vf_id;
11913
11914         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11915                                           &entry,
11916                                           ETH_L2_TUNNEL_INSERTION_MASK,
11917                                           0);
11918 }
11919
11920 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11921         .f = cmd_config_e_tag_insertion_en_parsed,
11922         .data = NULL,
11923         .help_str = "E-tag ... : E-tag insertion enable",
11924         .tokens = {
11925                 (void *)&cmd_config_e_tag_e_tag,
11926                 (void *)&cmd_config_e_tag_set,
11927                 (void *)&cmd_config_e_tag_insertion,
11928                 (void *)&cmd_config_e_tag_on,
11929                 (void *)&cmd_config_e_tag_port_tag_id,
11930                 (void *)&cmd_config_e_tag_port_tag_id_val,
11931                 (void *)&cmd_config_e_tag_port,
11932                 (void *)&cmd_config_e_tag_port_id,
11933                 (void *)&cmd_config_e_tag_vf,
11934                 (void *)&cmd_config_e_tag_vf_id,
11935                 NULL,
11936         },
11937 };
11938
11939 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11940         .f = cmd_config_e_tag_insertion_dis_parsed,
11941         .data = NULL,
11942         .help_str = "E-tag ... : E-tag insertion disable",
11943         .tokens = {
11944                 (void *)&cmd_config_e_tag_e_tag,
11945                 (void *)&cmd_config_e_tag_set,
11946                 (void *)&cmd_config_e_tag_insertion,
11947                 (void *)&cmd_config_e_tag_off,
11948                 (void *)&cmd_config_e_tag_port,
11949                 (void *)&cmd_config_e_tag_port_id,
11950                 (void *)&cmd_config_e_tag_vf,
11951                 (void *)&cmd_config_e_tag_vf_id,
11952                 NULL,
11953         },
11954 };
11955
11956 /* E-tag stripping configuration */
11957 static void
11958 cmd_config_e_tag_stripping_parsed(
11959         void *parsed_result,
11960         __attribute__((unused)) struct cmdline *cl,
11961         __attribute__((unused)) void *data)
11962 {
11963         struct cmd_config_e_tag_result *res =
11964                 parsed_result;
11965         struct rte_eth_l2_tunnel_conf entry;
11966
11967         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11968                 return;
11969
11970         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11971
11972         if (!strcmp(res->on_off, "on"))
11973                 rte_eth_dev_l2_tunnel_offload_set
11974                         (res->port_id,
11975                          &entry,
11976                          ETH_L2_TUNNEL_STRIPPING_MASK,
11977                          1);
11978         else
11979                 rte_eth_dev_l2_tunnel_offload_set
11980                         (res->port_id,
11981                          &entry,
11982                          ETH_L2_TUNNEL_STRIPPING_MASK,
11983                          0);
11984 }
11985
11986 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11987         .f = cmd_config_e_tag_stripping_parsed,
11988         .data = NULL,
11989         .help_str = "E-tag ... : E-tag stripping enable/disable",
11990         .tokens = {
11991                 (void *)&cmd_config_e_tag_e_tag,
11992                 (void *)&cmd_config_e_tag_set,
11993                 (void *)&cmd_config_e_tag_stripping,
11994                 (void *)&cmd_config_e_tag_on_off,
11995                 (void *)&cmd_config_e_tag_port,
11996                 (void *)&cmd_config_e_tag_port_id,
11997                 NULL,
11998         },
11999 };
12000
12001 /* E-tag forwarding configuration */
12002 static void
12003 cmd_config_e_tag_forwarding_parsed(
12004         void *parsed_result,
12005         __attribute__((unused)) struct cmdline *cl,
12006         __attribute__((unused)) void *data)
12007 {
12008         struct cmd_config_e_tag_result *res = parsed_result;
12009         struct rte_eth_l2_tunnel_conf entry;
12010
12011         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12012                 return;
12013
12014         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12015
12016         if (!strcmp(res->on_off, "on"))
12017                 rte_eth_dev_l2_tunnel_offload_set
12018                         (res->port_id,
12019                          &entry,
12020                          ETH_L2_TUNNEL_FORWARDING_MASK,
12021                          1);
12022         else
12023                 rte_eth_dev_l2_tunnel_offload_set
12024                         (res->port_id,
12025                          &entry,
12026                          ETH_L2_TUNNEL_FORWARDING_MASK,
12027                          0);
12028 }
12029
12030 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12031         .f = cmd_config_e_tag_forwarding_parsed,
12032         .data = NULL,
12033         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12034         .tokens = {
12035                 (void *)&cmd_config_e_tag_e_tag,
12036                 (void *)&cmd_config_e_tag_set,
12037                 (void *)&cmd_config_e_tag_forwarding,
12038                 (void *)&cmd_config_e_tag_on_off,
12039                 (void *)&cmd_config_e_tag_port,
12040                 (void *)&cmd_config_e_tag_port_id,
12041                 NULL,
12042         },
12043 };
12044
12045 /* E-tag filter configuration */
12046 static void
12047 cmd_config_e_tag_filter_add_parsed(
12048         void *parsed_result,
12049         __attribute__((unused)) struct cmdline *cl,
12050         __attribute__((unused)) void *data)
12051 {
12052         struct cmd_config_e_tag_result *res = parsed_result;
12053         struct rte_eth_l2_tunnel_conf entry;
12054         int ret = 0;
12055
12056         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12057                 return;
12058
12059         if (res->e_tag_id_val > 0x3fff) {
12060                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12061                 return;
12062         }
12063
12064         ret = rte_eth_dev_filter_supported(res->port_id,
12065                                            RTE_ETH_FILTER_L2_TUNNEL);
12066         if (ret < 0) {
12067                 printf("E-tag filter is not supported on port %u.\n",
12068                        res->port_id);
12069                 return;
12070         }
12071
12072         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12073         entry.tunnel_id = res->e_tag_id_val;
12074         entry.pool = res->dst_pool_val;
12075
12076         ret = rte_eth_dev_filter_ctrl(res->port_id,
12077                                       RTE_ETH_FILTER_L2_TUNNEL,
12078                                       RTE_ETH_FILTER_ADD,
12079                                       &entry);
12080         if (ret < 0)
12081                 printf("E-tag filter programming error: (%s)\n",
12082                        strerror(-ret));
12083 }
12084
12085 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12086         .f = cmd_config_e_tag_filter_add_parsed,
12087         .data = NULL,
12088         .help_str = "E-tag ... : E-tag filter add",
12089         .tokens = {
12090                 (void *)&cmd_config_e_tag_e_tag,
12091                 (void *)&cmd_config_e_tag_set,
12092                 (void *)&cmd_config_e_tag_filter,
12093                 (void *)&cmd_config_e_tag_add,
12094                 (void *)&cmd_config_e_tag_e_tag_id,
12095                 (void *)&cmd_config_e_tag_e_tag_id_val,
12096                 (void *)&cmd_config_e_tag_dst_pool,
12097                 (void *)&cmd_config_e_tag_dst_pool_val,
12098                 (void *)&cmd_config_e_tag_port,
12099                 (void *)&cmd_config_e_tag_port_id,
12100                 NULL,
12101         },
12102 };
12103
12104 static void
12105 cmd_config_e_tag_filter_del_parsed(
12106         void *parsed_result,
12107         __attribute__((unused)) struct cmdline *cl,
12108         __attribute__((unused)) void *data)
12109 {
12110         struct cmd_config_e_tag_result *res = parsed_result;
12111         struct rte_eth_l2_tunnel_conf entry;
12112         int ret = 0;
12113
12114         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12115                 return;
12116
12117         if (res->e_tag_id_val > 0x3fff) {
12118                 printf("e-tag-id must be less than 0x3fff.\n");
12119                 return;
12120         }
12121
12122         ret = rte_eth_dev_filter_supported(res->port_id,
12123                                            RTE_ETH_FILTER_L2_TUNNEL);
12124         if (ret < 0) {
12125                 printf("E-tag filter is not supported on port %u.\n",
12126                        res->port_id);
12127                 return;
12128         }
12129
12130         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12131         entry.tunnel_id = res->e_tag_id_val;
12132
12133         ret = rte_eth_dev_filter_ctrl(res->port_id,
12134                                       RTE_ETH_FILTER_L2_TUNNEL,
12135                                       RTE_ETH_FILTER_DELETE,
12136                                       &entry);
12137         if (ret < 0)
12138                 printf("E-tag filter programming error: (%s)\n",
12139                        strerror(-ret));
12140 }
12141
12142 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12143         .f = cmd_config_e_tag_filter_del_parsed,
12144         .data = NULL,
12145         .help_str = "E-tag ... : E-tag filter delete",
12146         .tokens = {
12147                 (void *)&cmd_config_e_tag_e_tag,
12148                 (void *)&cmd_config_e_tag_set,
12149                 (void *)&cmd_config_e_tag_filter,
12150                 (void *)&cmd_config_e_tag_del,
12151                 (void *)&cmd_config_e_tag_e_tag_id,
12152                 (void *)&cmd_config_e_tag_e_tag_id_val,
12153                 (void *)&cmd_config_e_tag_port,
12154                 (void *)&cmd_config_e_tag_port_id,
12155                 NULL,
12156         },
12157 };
12158
12159 /* vf vlan anti spoof configuration */
12160
12161 /* Common result structure for vf vlan anti spoof */
12162 struct cmd_vf_vlan_anti_spoof_result {
12163         cmdline_fixed_string_t set;
12164         cmdline_fixed_string_t vf;
12165         cmdline_fixed_string_t vlan;
12166         cmdline_fixed_string_t antispoof;
12167         portid_t port_id;
12168         uint32_t vf_id;
12169         cmdline_fixed_string_t on_off;
12170 };
12171
12172 /* Common CLI fields for vf vlan anti spoof enable disable */
12173 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12174         TOKEN_STRING_INITIALIZER
12175                 (struct cmd_vf_vlan_anti_spoof_result,
12176                  set, "set");
12177 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12178         TOKEN_STRING_INITIALIZER
12179                 (struct cmd_vf_vlan_anti_spoof_result,
12180                  vf, "vf");
12181 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12182         TOKEN_STRING_INITIALIZER
12183                 (struct cmd_vf_vlan_anti_spoof_result,
12184                  vlan, "vlan");
12185 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12186         TOKEN_STRING_INITIALIZER
12187                 (struct cmd_vf_vlan_anti_spoof_result,
12188                  antispoof, "antispoof");
12189 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12190         TOKEN_NUM_INITIALIZER
12191                 (struct cmd_vf_vlan_anti_spoof_result,
12192                  port_id, UINT16);
12193 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12194         TOKEN_NUM_INITIALIZER
12195                 (struct cmd_vf_vlan_anti_spoof_result,
12196                  vf_id, UINT32);
12197 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12198         TOKEN_STRING_INITIALIZER
12199                 (struct cmd_vf_vlan_anti_spoof_result,
12200                  on_off, "on#off");
12201
12202 static void
12203 cmd_set_vf_vlan_anti_spoof_parsed(
12204         void *parsed_result,
12205         __attribute__((unused)) struct cmdline *cl,
12206         __attribute__((unused)) void *data)
12207 {
12208         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12209         int ret = -ENOTSUP;
12210
12211         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12212
12213         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12214                 return;
12215
12216 #ifdef RTE_LIBRTE_IXGBE_PMD
12217         if (ret == -ENOTSUP)
12218                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12219                                 res->vf_id, is_on);
12220 #endif
12221 #ifdef RTE_LIBRTE_I40E_PMD
12222         if (ret == -ENOTSUP)
12223                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12224                                 res->vf_id, is_on);
12225 #endif
12226 #ifdef RTE_LIBRTE_BNXT_PMD
12227         if (ret == -ENOTSUP)
12228                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12229                                 res->vf_id, is_on);
12230 #endif
12231
12232         switch (ret) {
12233         case 0:
12234                 break;
12235         case -EINVAL:
12236                 printf("invalid vf_id %d\n", res->vf_id);
12237                 break;
12238         case -ENODEV:
12239                 printf("invalid port_id %d\n", res->port_id);
12240                 break;
12241         case -ENOTSUP:
12242                 printf("function not implemented\n");
12243                 break;
12244         default:
12245                 printf("programming error: (%s)\n", strerror(-ret));
12246         }
12247 }
12248
12249 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12250         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12251         .data = NULL,
12252         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12253         .tokens = {
12254                 (void *)&cmd_vf_vlan_anti_spoof_set,
12255                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12256                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12257                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12258                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12259                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12260                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12261                 NULL,
12262         },
12263 };
12264
12265 /* vf mac anti spoof configuration */
12266
12267 /* Common result structure for vf mac anti spoof */
12268 struct cmd_vf_mac_anti_spoof_result {
12269         cmdline_fixed_string_t set;
12270         cmdline_fixed_string_t vf;
12271         cmdline_fixed_string_t mac;
12272         cmdline_fixed_string_t antispoof;
12273         portid_t port_id;
12274         uint32_t vf_id;
12275         cmdline_fixed_string_t on_off;
12276 };
12277
12278 /* Common CLI fields for vf mac anti spoof enable disable */
12279 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12280         TOKEN_STRING_INITIALIZER
12281                 (struct cmd_vf_mac_anti_spoof_result,
12282                  set, "set");
12283 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12284         TOKEN_STRING_INITIALIZER
12285                 (struct cmd_vf_mac_anti_spoof_result,
12286                  vf, "vf");
12287 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12288         TOKEN_STRING_INITIALIZER
12289                 (struct cmd_vf_mac_anti_spoof_result,
12290                  mac, "mac");
12291 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12292         TOKEN_STRING_INITIALIZER
12293                 (struct cmd_vf_mac_anti_spoof_result,
12294                  antispoof, "antispoof");
12295 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12296         TOKEN_NUM_INITIALIZER
12297                 (struct cmd_vf_mac_anti_spoof_result,
12298                  port_id, UINT16);
12299 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12300         TOKEN_NUM_INITIALIZER
12301                 (struct cmd_vf_mac_anti_spoof_result,
12302                  vf_id, UINT32);
12303 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12304         TOKEN_STRING_INITIALIZER
12305                 (struct cmd_vf_mac_anti_spoof_result,
12306                  on_off, "on#off");
12307
12308 static void
12309 cmd_set_vf_mac_anti_spoof_parsed(
12310         void *parsed_result,
12311         __attribute__((unused)) struct cmdline *cl,
12312         __attribute__((unused)) void *data)
12313 {
12314         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12315         int ret = -ENOTSUP;
12316
12317         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12318
12319         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12320                 return;
12321
12322 #ifdef RTE_LIBRTE_IXGBE_PMD
12323         if (ret == -ENOTSUP)
12324                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12325                         res->vf_id, is_on);
12326 #endif
12327 #ifdef RTE_LIBRTE_I40E_PMD
12328         if (ret == -ENOTSUP)
12329                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12330                         res->vf_id, is_on);
12331 #endif
12332 #ifdef RTE_LIBRTE_BNXT_PMD
12333         if (ret == -ENOTSUP)
12334                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12335                         res->vf_id, is_on);
12336 #endif
12337
12338         switch (ret) {
12339         case 0:
12340                 break;
12341         case -EINVAL:
12342                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12343                 break;
12344         case -ENODEV:
12345                 printf("invalid port_id %d\n", res->port_id);
12346                 break;
12347         case -ENOTSUP:
12348                 printf("function not implemented\n");
12349                 break;
12350         default:
12351                 printf("programming error: (%s)\n", strerror(-ret));
12352         }
12353 }
12354
12355 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12356         .f = cmd_set_vf_mac_anti_spoof_parsed,
12357         .data = NULL,
12358         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12359         .tokens = {
12360                 (void *)&cmd_vf_mac_anti_spoof_set,
12361                 (void *)&cmd_vf_mac_anti_spoof_vf,
12362                 (void *)&cmd_vf_mac_anti_spoof_mac,
12363                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12364                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12365                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12366                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12367                 NULL,
12368         },
12369 };
12370
12371 /* vf vlan strip queue configuration */
12372
12373 /* Common result structure for vf mac anti spoof */
12374 struct cmd_vf_vlan_stripq_result {
12375         cmdline_fixed_string_t set;
12376         cmdline_fixed_string_t vf;
12377         cmdline_fixed_string_t vlan;
12378         cmdline_fixed_string_t stripq;
12379         portid_t port_id;
12380         uint16_t vf_id;
12381         cmdline_fixed_string_t on_off;
12382 };
12383
12384 /* Common CLI fields for vf vlan strip enable disable */
12385 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12386         TOKEN_STRING_INITIALIZER
12387                 (struct cmd_vf_vlan_stripq_result,
12388                  set, "set");
12389 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12390         TOKEN_STRING_INITIALIZER
12391                 (struct cmd_vf_vlan_stripq_result,
12392                  vf, "vf");
12393 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12394         TOKEN_STRING_INITIALIZER
12395                 (struct cmd_vf_vlan_stripq_result,
12396                  vlan, "vlan");
12397 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12398         TOKEN_STRING_INITIALIZER
12399                 (struct cmd_vf_vlan_stripq_result,
12400                  stripq, "stripq");
12401 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12402         TOKEN_NUM_INITIALIZER
12403                 (struct cmd_vf_vlan_stripq_result,
12404                  port_id, UINT16);
12405 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12406         TOKEN_NUM_INITIALIZER
12407                 (struct cmd_vf_vlan_stripq_result,
12408                  vf_id, UINT16);
12409 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12410         TOKEN_STRING_INITIALIZER
12411                 (struct cmd_vf_vlan_stripq_result,
12412                  on_off, "on#off");
12413
12414 static void
12415 cmd_set_vf_vlan_stripq_parsed(
12416         void *parsed_result,
12417         __attribute__((unused)) struct cmdline *cl,
12418         __attribute__((unused)) void *data)
12419 {
12420         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12421         int ret = -ENOTSUP;
12422
12423         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12424
12425         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12426                 return;
12427
12428 #ifdef RTE_LIBRTE_IXGBE_PMD
12429         if (ret == -ENOTSUP)
12430                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12431                         res->vf_id, is_on);
12432 #endif
12433 #ifdef RTE_LIBRTE_I40E_PMD
12434         if (ret == -ENOTSUP)
12435                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12436                         res->vf_id, is_on);
12437 #endif
12438 #ifdef RTE_LIBRTE_BNXT_PMD
12439         if (ret == -ENOTSUP)
12440                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12441                         res->vf_id, is_on);
12442 #endif
12443
12444         switch (ret) {
12445         case 0:
12446                 break;
12447         case -EINVAL:
12448                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12449                 break;
12450         case -ENODEV:
12451                 printf("invalid port_id %d\n", res->port_id);
12452                 break;
12453         case -ENOTSUP:
12454                 printf("function not implemented\n");
12455                 break;
12456         default:
12457                 printf("programming error: (%s)\n", strerror(-ret));
12458         }
12459 }
12460
12461 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12462         .f = cmd_set_vf_vlan_stripq_parsed,
12463         .data = NULL,
12464         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12465         .tokens = {
12466                 (void *)&cmd_vf_vlan_stripq_set,
12467                 (void *)&cmd_vf_vlan_stripq_vf,
12468                 (void *)&cmd_vf_vlan_stripq_vlan,
12469                 (void *)&cmd_vf_vlan_stripq_stripq,
12470                 (void *)&cmd_vf_vlan_stripq_port_id,
12471                 (void *)&cmd_vf_vlan_stripq_vf_id,
12472                 (void *)&cmd_vf_vlan_stripq_on_off,
12473                 NULL,
12474         },
12475 };
12476
12477 /* vf vlan insert configuration */
12478
12479 /* Common result structure for vf vlan insert */
12480 struct cmd_vf_vlan_insert_result {
12481         cmdline_fixed_string_t set;
12482         cmdline_fixed_string_t vf;
12483         cmdline_fixed_string_t vlan;
12484         cmdline_fixed_string_t insert;
12485         portid_t port_id;
12486         uint16_t vf_id;
12487         uint16_t vlan_id;
12488 };
12489
12490 /* Common CLI fields for vf vlan insert enable disable */
12491 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12492         TOKEN_STRING_INITIALIZER
12493                 (struct cmd_vf_vlan_insert_result,
12494                  set, "set");
12495 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12496         TOKEN_STRING_INITIALIZER
12497                 (struct cmd_vf_vlan_insert_result,
12498                  vf, "vf");
12499 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12500         TOKEN_STRING_INITIALIZER
12501                 (struct cmd_vf_vlan_insert_result,
12502                  vlan, "vlan");
12503 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12504         TOKEN_STRING_INITIALIZER
12505                 (struct cmd_vf_vlan_insert_result,
12506                  insert, "insert");
12507 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12508         TOKEN_NUM_INITIALIZER
12509                 (struct cmd_vf_vlan_insert_result,
12510                  port_id, UINT16);
12511 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12512         TOKEN_NUM_INITIALIZER
12513                 (struct cmd_vf_vlan_insert_result,
12514                  vf_id, UINT16);
12515 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12516         TOKEN_NUM_INITIALIZER
12517                 (struct cmd_vf_vlan_insert_result,
12518                  vlan_id, UINT16);
12519
12520 static void
12521 cmd_set_vf_vlan_insert_parsed(
12522         void *parsed_result,
12523         __attribute__((unused)) struct cmdline *cl,
12524         __attribute__((unused)) void *data)
12525 {
12526         struct cmd_vf_vlan_insert_result *res = parsed_result;
12527         int ret = -ENOTSUP;
12528
12529         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12530                 return;
12531
12532 #ifdef RTE_LIBRTE_IXGBE_PMD
12533         if (ret == -ENOTSUP)
12534                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12535                         res->vlan_id);
12536 #endif
12537 #ifdef RTE_LIBRTE_I40E_PMD
12538         if (ret == -ENOTSUP)
12539                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12540                         res->vlan_id);
12541 #endif
12542 #ifdef RTE_LIBRTE_BNXT_PMD
12543         if (ret == -ENOTSUP)
12544                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12545                         res->vlan_id);
12546 #endif
12547
12548         switch (ret) {
12549         case 0:
12550                 break;
12551         case -EINVAL:
12552                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12553                 break;
12554         case -ENODEV:
12555                 printf("invalid port_id %d\n", res->port_id);
12556                 break;
12557         case -ENOTSUP:
12558                 printf("function not implemented\n");
12559                 break;
12560         default:
12561                 printf("programming error: (%s)\n", strerror(-ret));
12562         }
12563 }
12564
12565 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12566         .f = cmd_set_vf_vlan_insert_parsed,
12567         .data = NULL,
12568         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12569         .tokens = {
12570                 (void *)&cmd_vf_vlan_insert_set,
12571                 (void *)&cmd_vf_vlan_insert_vf,
12572                 (void *)&cmd_vf_vlan_insert_vlan,
12573                 (void *)&cmd_vf_vlan_insert_insert,
12574                 (void *)&cmd_vf_vlan_insert_port_id,
12575                 (void *)&cmd_vf_vlan_insert_vf_id,
12576                 (void *)&cmd_vf_vlan_insert_vlan_id,
12577                 NULL,
12578         },
12579 };
12580
12581 /* tx loopback configuration */
12582
12583 /* Common result structure for tx loopback */
12584 struct cmd_tx_loopback_result {
12585         cmdline_fixed_string_t set;
12586         cmdline_fixed_string_t tx;
12587         cmdline_fixed_string_t loopback;
12588         portid_t port_id;
12589         cmdline_fixed_string_t on_off;
12590 };
12591
12592 /* Common CLI fields for tx loopback enable disable */
12593 cmdline_parse_token_string_t cmd_tx_loopback_set =
12594         TOKEN_STRING_INITIALIZER
12595                 (struct cmd_tx_loopback_result,
12596                  set, "set");
12597 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12598         TOKEN_STRING_INITIALIZER
12599                 (struct cmd_tx_loopback_result,
12600                  tx, "tx");
12601 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12602         TOKEN_STRING_INITIALIZER
12603                 (struct cmd_tx_loopback_result,
12604                  loopback, "loopback");
12605 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12606         TOKEN_NUM_INITIALIZER
12607                 (struct cmd_tx_loopback_result,
12608                  port_id, UINT16);
12609 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12610         TOKEN_STRING_INITIALIZER
12611                 (struct cmd_tx_loopback_result,
12612                  on_off, "on#off");
12613
12614 static void
12615 cmd_set_tx_loopback_parsed(
12616         void *parsed_result,
12617         __attribute__((unused)) struct cmdline *cl,
12618         __attribute__((unused)) void *data)
12619 {
12620         struct cmd_tx_loopback_result *res = parsed_result;
12621         int ret = -ENOTSUP;
12622
12623         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12624
12625         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12626                 return;
12627
12628 #ifdef RTE_LIBRTE_IXGBE_PMD
12629         if (ret == -ENOTSUP)
12630                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12631 #endif
12632 #ifdef RTE_LIBRTE_I40E_PMD
12633         if (ret == -ENOTSUP)
12634                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12635 #endif
12636 #ifdef RTE_LIBRTE_BNXT_PMD
12637         if (ret == -ENOTSUP)
12638                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12639 #endif
12640
12641         switch (ret) {
12642         case 0:
12643                 break;
12644         case -EINVAL:
12645                 printf("invalid is_on %d\n", is_on);
12646                 break;
12647         case -ENODEV:
12648                 printf("invalid port_id %d\n", res->port_id);
12649                 break;
12650         case -ENOTSUP:
12651                 printf("function not implemented\n");
12652                 break;
12653         default:
12654                 printf("programming error: (%s)\n", strerror(-ret));
12655         }
12656 }
12657
12658 cmdline_parse_inst_t cmd_set_tx_loopback = {
12659         .f = cmd_set_tx_loopback_parsed,
12660         .data = NULL,
12661         .help_str = "set tx loopback <port_id> on|off",
12662         .tokens = {
12663                 (void *)&cmd_tx_loopback_set,
12664                 (void *)&cmd_tx_loopback_tx,
12665                 (void *)&cmd_tx_loopback_loopback,
12666                 (void *)&cmd_tx_loopback_port_id,
12667                 (void *)&cmd_tx_loopback_on_off,
12668                 NULL,
12669         },
12670 };
12671
12672 /* all queues drop enable configuration */
12673
12674 /* Common result structure for all queues drop enable */
12675 struct cmd_all_queues_drop_en_result {
12676         cmdline_fixed_string_t set;
12677         cmdline_fixed_string_t all;
12678         cmdline_fixed_string_t queues;
12679         cmdline_fixed_string_t drop;
12680         portid_t port_id;
12681         cmdline_fixed_string_t on_off;
12682 };
12683
12684 /* Common CLI fields for tx loopback enable disable */
12685 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12686         TOKEN_STRING_INITIALIZER
12687                 (struct cmd_all_queues_drop_en_result,
12688                  set, "set");
12689 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12690         TOKEN_STRING_INITIALIZER
12691                 (struct cmd_all_queues_drop_en_result,
12692                  all, "all");
12693 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12694         TOKEN_STRING_INITIALIZER
12695                 (struct cmd_all_queues_drop_en_result,
12696                  queues, "queues");
12697 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12698         TOKEN_STRING_INITIALIZER
12699                 (struct cmd_all_queues_drop_en_result,
12700                  drop, "drop");
12701 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12702         TOKEN_NUM_INITIALIZER
12703                 (struct cmd_all_queues_drop_en_result,
12704                  port_id, UINT16);
12705 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12706         TOKEN_STRING_INITIALIZER
12707                 (struct cmd_all_queues_drop_en_result,
12708                  on_off, "on#off");
12709
12710 static void
12711 cmd_set_all_queues_drop_en_parsed(
12712         void *parsed_result,
12713         __attribute__((unused)) struct cmdline *cl,
12714         __attribute__((unused)) void *data)
12715 {
12716         struct cmd_all_queues_drop_en_result *res = parsed_result;
12717         int ret = -ENOTSUP;
12718         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12719
12720         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12721                 return;
12722
12723 #ifdef RTE_LIBRTE_IXGBE_PMD
12724         if (ret == -ENOTSUP)
12725                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12726 #endif
12727 #ifdef RTE_LIBRTE_BNXT_PMD
12728         if (ret == -ENOTSUP)
12729                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12730 #endif
12731         switch (ret) {
12732         case 0:
12733                 break;
12734         case -EINVAL:
12735                 printf("invalid is_on %d\n", is_on);
12736                 break;
12737         case -ENODEV:
12738                 printf("invalid port_id %d\n", res->port_id);
12739                 break;
12740         case -ENOTSUP:
12741                 printf("function not implemented\n");
12742                 break;
12743         default:
12744                 printf("programming error: (%s)\n", strerror(-ret));
12745         }
12746 }
12747
12748 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12749         .f = cmd_set_all_queues_drop_en_parsed,
12750         .data = NULL,
12751         .help_str = "set all queues drop <port_id> on|off",
12752         .tokens = {
12753                 (void *)&cmd_all_queues_drop_en_set,
12754                 (void *)&cmd_all_queues_drop_en_all,
12755                 (void *)&cmd_all_queues_drop_en_queues,
12756                 (void *)&cmd_all_queues_drop_en_drop,
12757                 (void *)&cmd_all_queues_drop_en_port_id,
12758                 (void *)&cmd_all_queues_drop_en_on_off,
12759                 NULL,
12760         },
12761 };
12762
12763 /* vf split drop enable configuration */
12764
12765 /* Common result structure for vf split drop enable */
12766 struct cmd_vf_split_drop_en_result {
12767         cmdline_fixed_string_t set;
12768         cmdline_fixed_string_t vf;
12769         cmdline_fixed_string_t split;
12770         cmdline_fixed_string_t drop;
12771         portid_t port_id;
12772         uint16_t vf_id;
12773         cmdline_fixed_string_t on_off;
12774 };
12775
12776 /* Common CLI fields for vf split drop enable disable */
12777 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12778         TOKEN_STRING_INITIALIZER
12779                 (struct cmd_vf_split_drop_en_result,
12780                  set, "set");
12781 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12782         TOKEN_STRING_INITIALIZER
12783                 (struct cmd_vf_split_drop_en_result,
12784                  vf, "vf");
12785 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12786         TOKEN_STRING_INITIALIZER
12787                 (struct cmd_vf_split_drop_en_result,
12788                  split, "split");
12789 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12790         TOKEN_STRING_INITIALIZER
12791                 (struct cmd_vf_split_drop_en_result,
12792                  drop, "drop");
12793 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12794         TOKEN_NUM_INITIALIZER
12795                 (struct cmd_vf_split_drop_en_result,
12796                  port_id, UINT16);
12797 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12798         TOKEN_NUM_INITIALIZER
12799                 (struct cmd_vf_split_drop_en_result,
12800                  vf_id, UINT16);
12801 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12802         TOKEN_STRING_INITIALIZER
12803                 (struct cmd_vf_split_drop_en_result,
12804                  on_off, "on#off");
12805
12806 static void
12807 cmd_set_vf_split_drop_en_parsed(
12808         void *parsed_result,
12809         __attribute__((unused)) struct cmdline *cl,
12810         __attribute__((unused)) void *data)
12811 {
12812         struct cmd_vf_split_drop_en_result *res = parsed_result;
12813         int ret = -ENOTSUP;
12814         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12815
12816         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12817                 return;
12818
12819 #ifdef RTE_LIBRTE_IXGBE_PMD
12820         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12821                         is_on);
12822 #endif
12823         switch (ret) {
12824         case 0:
12825                 break;
12826         case -EINVAL:
12827                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12828                 break;
12829         case -ENODEV:
12830                 printf("invalid port_id %d\n", res->port_id);
12831                 break;
12832         case -ENOTSUP:
12833                 printf("not supported on port %d\n", res->port_id);
12834                 break;
12835         default:
12836                 printf("programming error: (%s)\n", strerror(-ret));
12837         }
12838 }
12839
12840 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12841         .f = cmd_set_vf_split_drop_en_parsed,
12842         .data = NULL,
12843         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12844         .tokens = {
12845                 (void *)&cmd_vf_split_drop_en_set,
12846                 (void *)&cmd_vf_split_drop_en_vf,
12847                 (void *)&cmd_vf_split_drop_en_split,
12848                 (void *)&cmd_vf_split_drop_en_drop,
12849                 (void *)&cmd_vf_split_drop_en_port_id,
12850                 (void *)&cmd_vf_split_drop_en_vf_id,
12851                 (void *)&cmd_vf_split_drop_en_on_off,
12852                 NULL,
12853         },
12854 };
12855
12856 /* vf mac address configuration */
12857
12858 /* Common result structure for vf mac address */
12859 struct cmd_set_vf_mac_addr_result {
12860         cmdline_fixed_string_t set;
12861         cmdline_fixed_string_t vf;
12862         cmdline_fixed_string_t mac;
12863         cmdline_fixed_string_t addr;
12864         portid_t port_id;
12865         uint16_t vf_id;
12866         struct ether_addr mac_addr;
12867
12868 };
12869
12870 /* Common CLI fields for vf split drop enable disable */
12871 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12872         TOKEN_STRING_INITIALIZER
12873                 (struct cmd_set_vf_mac_addr_result,
12874                  set, "set");
12875 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12876         TOKEN_STRING_INITIALIZER
12877                 (struct cmd_set_vf_mac_addr_result,
12878                  vf, "vf");
12879 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12880         TOKEN_STRING_INITIALIZER
12881                 (struct cmd_set_vf_mac_addr_result,
12882                  mac, "mac");
12883 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12884         TOKEN_STRING_INITIALIZER
12885                 (struct cmd_set_vf_mac_addr_result,
12886                  addr, "addr");
12887 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12888         TOKEN_NUM_INITIALIZER
12889                 (struct cmd_set_vf_mac_addr_result,
12890                  port_id, UINT16);
12891 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12892         TOKEN_NUM_INITIALIZER
12893                 (struct cmd_set_vf_mac_addr_result,
12894                  vf_id, UINT16);
12895 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12896         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12897                  mac_addr);
12898
12899 static void
12900 cmd_set_vf_mac_addr_parsed(
12901         void *parsed_result,
12902         __attribute__((unused)) struct cmdline *cl,
12903         __attribute__((unused)) void *data)
12904 {
12905         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12906         int ret = -ENOTSUP;
12907
12908         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12909                 return;
12910
12911 #ifdef RTE_LIBRTE_IXGBE_PMD
12912         if (ret == -ENOTSUP)
12913                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12914                                 &res->mac_addr);
12915 #endif
12916 #ifdef RTE_LIBRTE_I40E_PMD
12917         if (ret == -ENOTSUP)
12918                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12919                                 &res->mac_addr);
12920 #endif
12921 #ifdef RTE_LIBRTE_BNXT_PMD
12922         if (ret == -ENOTSUP)
12923                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12924                                 &res->mac_addr);
12925 #endif
12926
12927         switch (ret) {
12928         case 0:
12929                 break;
12930         case -EINVAL:
12931                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12932                 break;
12933         case -ENODEV:
12934                 printf("invalid port_id %d\n", res->port_id);
12935                 break;
12936         case -ENOTSUP:
12937                 printf("function not implemented\n");
12938                 break;
12939         default:
12940                 printf("programming error: (%s)\n", strerror(-ret));
12941         }
12942 }
12943
12944 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12945         .f = cmd_set_vf_mac_addr_parsed,
12946         .data = NULL,
12947         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12948         .tokens = {
12949                 (void *)&cmd_set_vf_mac_addr_set,
12950                 (void *)&cmd_set_vf_mac_addr_vf,
12951                 (void *)&cmd_set_vf_mac_addr_mac,
12952                 (void *)&cmd_set_vf_mac_addr_addr,
12953                 (void *)&cmd_set_vf_mac_addr_port_id,
12954                 (void *)&cmd_set_vf_mac_addr_vf_id,
12955                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12956                 NULL,
12957         },
12958 };
12959
12960 /* MACsec configuration */
12961
12962 /* Common result structure for MACsec offload enable */
12963 struct cmd_macsec_offload_on_result {
12964         cmdline_fixed_string_t set;
12965         cmdline_fixed_string_t macsec;
12966         cmdline_fixed_string_t offload;
12967         portid_t port_id;
12968         cmdline_fixed_string_t on;
12969         cmdline_fixed_string_t encrypt;
12970         cmdline_fixed_string_t en_on_off;
12971         cmdline_fixed_string_t replay_protect;
12972         cmdline_fixed_string_t rp_on_off;
12973 };
12974
12975 /* Common CLI fields for MACsec offload disable */
12976 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12977         TOKEN_STRING_INITIALIZER
12978                 (struct cmd_macsec_offload_on_result,
12979                  set, "set");
12980 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12981         TOKEN_STRING_INITIALIZER
12982                 (struct cmd_macsec_offload_on_result,
12983                  macsec, "macsec");
12984 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12985         TOKEN_STRING_INITIALIZER
12986                 (struct cmd_macsec_offload_on_result,
12987                  offload, "offload");
12988 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12989         TOKEN_NUM_INITIALIZER
12990                 (struct cmd_macsec_offload_on_result,
12991                  port_id, UINT16);
12992 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12993         TOKEN_STRING_INITIALIZER
12994                 (struct cmd_macsec_offload_on_result,
12995                  on, "on");
12996 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12997         TOKEN_STRING_INITIALIZER
12998                 (struct cmd_macsec_offload_on_result,
12999                  encrypt, "encrypt");
13000 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
13001         TOKEN_STRING_INITIALIZER
13002                 (struct cmd_macsec_offload_on_result,
13003                  en_on_off, "on#off");
13004 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
13005         TOKEN_STRING_INITIALIZER
13006                 (struct cmd_macsec_offload_on_result,
13007                  replay_protect, "replay-protect");
13008 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
13009         TOKEN_STRING_INITIALIZER
13010                 (struct cmd_macsec_offload_on_result,
13011                  rp_on_off, "on#off");
13012
13013 static void
13014 cmd_set_macsec_offload_on_parsed(
13015         void *parsed_result,
13016         __attribute__((unused)) struct cmdline *cl,
13017         __attribute__((unused)) void *data)
13018 {
13019         struct cmd_macsec_offload_on_result *res = parsed_result;
13020         int ret = -ENOTSUP;
13021         portid_t port_id = res->port_id;
13022         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13023         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13024
13025         if (port_id_is_invalid(port_id, ENABLED_WARN))
13026                 return;
13027
13028         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
13029 #ifdef RTE_LIBRTE_IXGBE_PMD
13030         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13031 #endif
13032         RTE_SET_USED(en);
13033         RTE_SET_USED(rp);
13034
13035         switch (ret) {
13036         case 0:
13037                 break;
13038         case -ENODEV:
13039                 printf("invalid port_id %d\n", port_id);
13040                 break;
13041         case -ENOTSUP:
13042                 printf("not supported on port %d\n", port_id);
13043                 break;
13044         default:
13045                 printf("programming error: (%s)\n", strerror(-ret));
13046         }
13047 }
13048
13049 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13050         .f = cmd_set_macsec_offload_on_parsed,
13051         .data = NULL,
13052         .help_str = "set macsec offload <port_id> on "
13053                 "encrypt on|off replay-protect on|off",
13054         .tokens = {
13055                 (void *)&cmd_macsec_offload_on_set,
13056                 (void *)&cmd_macsec_offload_on_macsec,
13057                 (void *)&cmd_macsec_offload_on_offload,
13058                 (void *)&cmd_macsec_offload_on_port_id,
13059                 (void *)&cmd_macsec_offload_on_on,
13060                 (void *)&cmd_macsec_offload_on_encrypt,
13061                 (void *)&cmd_macsec_offload_on_en_on_off,
13062                 (void *)&cmd_macsec_offload_on_replay_protect,
13063                 (void *)&cmd_macsec_offload_on_rp_on_off,
13064                 NULL,
13065         },
13066 };
13067
13068 /* Common result structure for MACsec offload disable */
13069 struct cmd_macsec_offload_off_result {
13070         cmdline_fixed_string_t set;
13071         cmdline_fixed_string_t macsec;
13072         cmdline_fixed_string_t offload;
13073         portid_t port_id;
13074         cmdline_fixed_string_t off;
13075 };
13076
13077 /* Common CLI fields for MACsec offload disable */
13078 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13079         TOKEN_STRING_INITIALIZER
13080                 (struct cmd_macsec_offload_off_result,
13081                  set, "set");
13082 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13083         TOKEN_STRING_INITIALIZER
13084                 (struct cmd_macsec_offload_off_result,
13085                  macsec, "macsec");
13086 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13087         TOKEN_STRING_INITIALIZER
13088                 (struct cmd_macsec_offload_off_result,
13089                  offload, "offload");
13090 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13091         TOKEN_NUM_INITIALIZER
13092                 (struct cmd_macsec_offload_off_result,
13093                  port_id, UINT16);
13094 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13095         TOKEN_STRING_INITIALIZER
13096                 (struct cmd_macsec_offload_off_result,
13097                  off, "off");
13098
13099 static void
13100 cmd_set_macsec_offload_off_parsed(
13101         void *parsed_result,
13102         __attribute__((unused)) struct cmdline *cl,
13103         __attribute__((unused)) void *data)
13104 {
13105         struct cmd_macsec_offload_off_result *res = parsed_result;
13106         int ret = -ENOTSUP;
13107         portid_t port_id = res->port_id;
13108
13109         if (port_id_is_invalid(port_id, ENABLED_WARN))
13110                 return;
13111
13112         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
13113 #ifdef RTE_LIBRTE_IXGBE_PMD
13114         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13115 #endif
13116
13117         switch (ret) {
13118         case 0:
13119                 break;
13120         case -ENODEV:
13121                 printf("invalid port_id %d\n", port_id);
13122                 break;
13123         case -ENOTSUP:
13124                 printf("not supported on port %d\n", port_id);
13125                 break;
13126         default:
13127                 printf("programming error: (%s)\n", strerror(-ret));
13128         }
13129 }
13130
13131 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13132         .f = cmd_set_macsec_offload_off_parsed,
13133         .data = NULL,
13134         .help_str = "set macsec offload <port_id> off",
13135         .tokens = {
13136                 (void *)&cmd_macsec_offload_off_set,
13137                 (void *)&cmd_macsec_offload_off_macsec,
13138                 (void *)&cmd_macsec_offload_off_offload,
13139                 (void *)&cmd_macsec_offload_off_port_id,
13140                 (void *)&cmd_macsec_offload_off_off,
13141                 NULL,
13142         },
13143 };
13144
13145 /* Common result structure for MACsec secure connection configure */
13146 struct cmd_macsec_sc_result {
13147         cmdline_fixed_string_t set;
13148         cmdline_fixed_string_t macsec;
13149         cmdline_fixed_string_t sc;
13150         cmdline_fixed_string_t tx_rx;
13151         portid_t port_id;
13152         struct ether_addr mac;
13153         uint16_t pi;
13154 };
13155
13156 /* Common CLI fields for MACsec secure connection configure */
13157 cmdline_parse_token_string_t cmd_macsec_sc_set =
13158         TOKEN_STRING_INITIALIZER
13159                 (struct cmd_macsec_sc_result,
13160                  set, "set");
13161 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13162         TOKEN_STRING_INITIALIZER
13163                 (struct cmd_macsec_sc_result,
13164                  macsec, "macsec");
13165 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13166         TOKEN_STRING_INITIALIZER
13167                 (struct cmd_macsec_sc_result,
13168                  sc, "sc");
13169 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13170         TOKEN_STRING_INITIALIZER
13171                 (struct cmd_macsec_sc_result,
13172                  tx_rx, "tx#rx");
13173 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13174         TOKEN_NUM_INITIALIZER
13175                 (struct cmd_macsec_sc_result,
13176                  port_id, UINT16);
13177 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13178         TOKEN_ETHERADDR_INITIALIZER
13179                 (struct cmd_macsec_sc_result,
13180                  mac);
13181 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13182         TOKEN_NUM_INITIALIZER
13183                 (struct cmd_macsec_sc_result,
13184                  pi, UINT16);
13185
13186 static void
13187 cmd_set_macsec_sc_parsed(
13188         void *parsed_result,
13189         __attribute__((unused)) struct cmdline *cl,
13190         __attribute__((unused)) void *data)
13191 {
13192         struct cmd_macsec_sc_result *res = parsed_result;
13193         int ret = -ENOTSUP;
13194         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13195
13196 #ifdef RTE_LIBRTE_IXGBE_PMD
13197         ret = is_tx ?
13198                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13199                                 res->mac.addr_bytes) :
13200                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13201                                 res->mac.addr_bytes, res->pi);
13202 #endif
13203         RTE_SET_USED(is_tx);
13204
13205         switch (ret) {
13206         case 0:
13207                 break;
13208         case -ENODEV:
13209                 printf("invalid port_id %d\n", res->port_id);
13210                 break;
13211         case -ENOTSUP:
13212                 printf("not supported on port %d\n", res->port_id);
13213                 break;
13214         default:
13215                 printf("programming error: (%s)\n", strerror(-ret));
13216         }
13217 }
13218
13219 cmdline_parse_inst_t cmd_set_macsec_sc = {
13220         .f = cmd_set_macsec_sc_parsed,
13221         .data = NULL,
13222         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13223         .tokens = {
13224                 (void *)&cmd_macsec_sc_set,
13225                 (void *)&cmd_macsec_sc_macsec,
13226                 (void *)&cmd_macsec_sc_sc,
13227                 (void *)&cmd_macsec_sc_tx_rx,
13228                 (void *)&cmd_macsec_sc_port_id,
13229                 (void *)&cmd_macsec_sc_mac,
13230                 (void *)&cmd_macsec_sc_pi,
13231                 NULL,
13232         },
13233 };
13234
13235 /* Common result structure for MACsec secure connection configure */
13236 struct cmd_macsec_sa_result {
13237         cmdline_fixed_string_t set;
13238         cmdline_fixed_string_t macsec;
13239         cmdline_fixed_string_t sa;
13240         cmdline_fixed_string_t tx_rx;
13241         portid_t port_id;
13242         uint8_t idx;
13243         uint8_t an;
13244         uint32_t pn;
13245         cmdline_fixed_string_t key;
13246 };
13247
13248 /* Common CLI fields for MACsec secure connection configure */
13249 cmdline_parse_token_string_t cmd_macsec_sa_set =
13250         TOKEN_STRING_INITIALIZER
13251                 (struct cmd_macsec_sa_result,
13252                  set, "set");
13253 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13254         TOKEN_STRING_INITIALIZER
13255                 (struct cmd_macsec_sa_result,
13256                  macsec, "macsec");
13257 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13258         TOKEN_STRING_INITIALIZER
13259                 (struct cmd_macsec_sa_result,
13260                  sa, "sa");
13261 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13262         TOKEN_STRING_INITIALIZER
13263                 (struct cmd_macsec_sa_result,
13264                  tx_rx, "tx#rx");
13265 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13266         TOKEN_NUM_INITIALIZER
13267                 (struct cmd_macsec_sa_result,
13268                  port_id, UINT16);
13269 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13270         TOKEN_NUM_INITIALIZER
13271                 (struct cmd_macsec_sa_result,
13272                  idx, UINT8);
13273 cmdline_parse_token_num_t cmd_macsec_sa_an =
13274         TOKEN_NUM_INITIALIZER
13275                 (struct cmd_macsec_sa_result,
13276                  an, UINT8);
13277 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13278         TOKEN_NUM_INITIALIZER
13279                 (struct cmd_macsec_sa_result,
13280                  pn, UINT32);
13281 cmdline_parse_token_string_t cmd_macsec_sa_key =
13282         TOKEN_STRING_INITIALIZER
13283                 (struct cmd_macsec_sa_result,
13284                  key, NULL);
13285
13286 static void
13287 cmd_set_macsec_sa_parsed(
13288         void *parsed_result,
13289         __attribute__((unused)) struct cmdline *cl,
13290         __attribute__((unused)) void *data)
13291 {
13292         struct cmd_macsec_sa_result *res = parsed_result;
13293         int ret = -ENOTSUP;
13294         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13295         uint8_t key[16] = { 0 };
13296         uint8_t xdgt0;
13297         uint8_t xdgt1;
13298         int key_len;
13299         int i;
13300
13301         key_len = strlen(res->key) / 2;
13302         if (key_len > 16)
13303                 key_len = 16;
13304
13305         for (i = 0; i < key_len; i++) {
13306                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13307                 if (xdgt0 == 0xFF)
13308                         return;
13309                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13310                 if (xdgt1 == 0xFF)
13311                         return;
13312                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13313         }
13314
13315 #ifdef RTE_LIBRTE_IXGBE_PMD
13316         ret = is_tx ?
13317                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13318                         res->idx, res->an, res->pn, key) :
13319                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13320                         res->idx, res->an, res->pn, key);
13321 #endif
13322         RTE_SET_USED(is_tx);
13323         RTE_SET_USED(key);
13324
13325         switch (ret) {
13326         case 0:
13327                 break;
13328         case -EINVAL:
13329                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13330                 break;
13331         case -ENODEV:
13332                 printf("invalid port_id %d\n", res->port_id);
13333                 break;
13334         case -ENOTSUP:
13335                 printf("not supported on port %d\n", res->port_id);
13336                 break;
13337         default:
13338                 printf("programming error: (%s)\n", strerror(-ret));
13339         }
13340 }
13341
13342 cmdline_parse_inst_t cmd_set_macsec_sa = {
13343         .f = cmd_set_macsec_sa_parsed,
13344         .data = NULL,
13345         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13346         .tokens = {
13347                 (void *)&cmd_macsec_sa_set,
13348                 (void *)&cmd_macsec_sa_macsec,
13349                 (void *)&cmd_macsec_sa_sa,
13350                 (void *)&cmd_macsec_sa_tx_rx,
13351                 (void *)&cmd_macsec_sa_port_id,
13352                 (void *)&cmd_macsec_sa_idx,
13353                 (void *)&cmd_macsec_sa_an,
13354                 (void *)&cmd_macsec_sa_pn,
13355                 (void *)&cmd_macsec_sa_key,
13356                 NULL,
13357         },
13358 };
13359
13360 /* VF unicast promiscuous mode configuration */
13361
13362 /* Common result structure for VF unicast promiscuous mode */
13363 struct cmd_vf_promisc_result {
13364         cmdline_fixed_string_t set;
13365         cmdline_fixed_string_t vf;
13366         cmdline_fixed_string_t promisc;
13367         portid_t port_id;
13368         uint32_t vf_id;
13369         cmdline_fixed_string_t on_off;
13370 };
13371
13372 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13373 cmdline_parse_token_string_t cmd_vf_promisc_set =
13374         TOKEN_STRING_INITIALIZER
13375                 (struct cmd_vf_promisc_result,
13376                  set, "set");
13377 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13378         TOKEN_STRING_INITIALIZER
13379                 (struct cmd_vf_promisc_result,
13380                  vf, "vf");
13381 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13382         TOKEN_STRING_INITIALIZER
13383                 (struct cmd_vf_promisc_result,
13384                  promisc, "promisc");
13385 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13386         TOKEN_NUM_INITIALIZER
13387                 (struct cmd_vf_promisc_result,
13388                  port_id, UINT16);
13389 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13390         TOKEN_NUM_INITIALIZER
13391                 (struct cmd_vf_promisc_result,
13392                  vf_id, UINT32);
13393 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13394         TOKEN_STRING_INITIALIZER
13395                 (struct cmd_vf_promisc_result,
13396                  on_off, "on#off");
13397
13398 static void
13399 cmd_set_vf_promisc_parsed(
13400         void *parsed_result,
13401         __attribute__((unused)) struct cmdline *cl,
13402         __attribute__((unused)) void *data)
13403 {
13404         struct cmd_vf_promisc_result *res = parsed_result;
13405         int ret = -ENOTSUP;
13406
13407         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13408
13409         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13410                 return;
13411
13412 #ifdef RTE_LIBRTE_I40E_PMD
13413         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13414                                                   res->vf_id, is_on);
13415 #endif
13416
13417         switch (ret) {
13418         case 0:
13419                 break;
13420         case -EINVAL:
13421                 printf("invalid vf_id %d\n", res->vf_id);
13422                 break;
13423         case -ENODEV:
13424                 printf("invalid port_id %d\n", res->port_id);
13425                 break;
13426         case -ENOTSUP:
13427                 printf("function not implemented\n");
13428                 break;
13429         default:
13430                 printf("programming error: (%s)\n", strerror(-ret));
13431         }
13432 }
13433
13434 cmdline_parse_inst_t cmd_set_vf_promisc = {
13435         .f = cmd_set_vf_promisc_parsed,
13436         .data = NULL,
13437         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13438                 "Set unicast promiscuous mode for a VF from the PF",
13439         .tokens = {
13440                 (void *)&cmd_vf_promisc_set,
13441                 (void *)&cmd_vf_promisc_vf,
13442                 (void *)&cmd_vf_promisc_promisc,
13443                 (void *)&cmd_vf_promisc_port_id,
13444                 (void *)&cmd_vf_promisc_vf_id,
13445                 (void *)&cmd_vf_promisc_on_off,
13446                 NULL,
13447         },
13448 };
13449
13450 /* VF multicast promiscuous mode configuration */
13451
13452 /* Common result structure for VF multicast promiscuous mode */
13453 struct cmd_vf_allmulti_result {
13454         cmdline_fixed_string_t set;
13455         cmdline_fixed_string_t vf;
13456         cmdline_fixed_string_t allmulti;
13457         portid_t port_id;
13458         uint32_t vf_id;
13459         cmdline_fixed_string_t on_off;
13460 };
13461
13462 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13463 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13464         TOKEN_STRING_INITIALIZER
13465                 (struct cmd_vf_allmulti_result,
13466                  set, "set");
13467 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13468         TOKEN_STRING_INITIALIZER
13469                 (struct cmd_vf_allmulti_result,
13470                  vf, "vf");
13471 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13472         TOKEN_STRING_INITIALIZER
13473                 (struct cmd_vf_allmulti_result,
13474                  allmulti, "allmulti");
13475 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13476         TOKEN_NUM_INITIALIZER
13477                 (struct cmd_vf_allmulti_result,
13478                  port_id, UINT16);
13479 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13480         TOKEN_NUM_INITIALIZER
13481                 (struct cmd_vf_allmulti_result,
13482                  vf_id, UINT32);
13483 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13484         TOKEN_STRING_INITIALIZER
13485                 (struct cmd_vf_allmulti_result,
13486                  on_off, "on#off");
13487
13488 static void
13489 cmd_set_vf_allmulti_parsed(
13490         void *parsed_result,
13491         __attribute__((unused)) struct cmdline *cl,
13492         __attribute__((unused)) void *data)
13493 {
13494         struct cmd_vf_allmulti_result *res = parsed_result;
13495         int ret = -ENOTSUP;
13496
13497         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13498
13499         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13500                 return;
13501
13502 #ifdef RTE_LIBRTE_I40E_PMD
13503         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13504                                                     res->vf_id, is_on);
13505 #endif
13506
13507         switch (ret) {
13508         case 0:
13509                 break;
13510         case -EINVAL:
13511                 printf("invalid vf_id %d\n", res->vf_id);
13512                 break;
13513         case -ENODEV:
13514                 printf("invalid port_id %d\n", res->port_id);
13515                 break;
13516         case -ENOTSUP:
13517                 printf("function not implemented\n");
13518                 break;
13519         default:
13520                 printf("programming error: (%s)\n", strerror(-ret));
13521         }
13522 }
13523
13524 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13525         .f = cmd_set_vf_allmulti_parsed,
13526         .data = NULL,
13527         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13528                 "Set multicast promiscuous mode for a VF from the PF",
13529         .tokens = {
13530                 (void *)&cmd_vf_allmulti_set,
13531                 (void *)&cmd_vf_allmulti_vf,
13532                 (void *)&cmd_vf_allmulti_allmulti,
13533                 (void *)&cmd_vf_allmulti_port_id,
13534                 (void *)&cmd_vf_allmulti_vf_id,
13535                 (void *)&cmd_vf_allmulti_on_off,
13536                 NULL,
13537         },
13538 };
13539
13540 /* vf broadcast mode configuration */
13541
13542 /* Common result structure for vf broadcast */
13543 struct cmd_set_vf_broadcast_result {
13544         cmdline_fixed_string_t set;
13545         cmdline_fixed_string_t vf;
13546         cmdline_fixed_string_t broadcast;
13547         portid_t port_id;
13548         uint16_t vf_id;
13549         cmdline_fixed_string_t on_off;
13550 };
13551
13552 /* Common CLI fields for vf broadcast enable disable */
13553 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13554         TOKEN_STRING_INITIALIZER
13555                 (struct cmd_set_vf_broadcast_result,
13556                  set, "set");
13557 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13558         TOKEN_STRING_INITIALIZER
13559                 (struct cmd_set_vf_broadcast_result,
13560                  vf, "vf");
13561 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13562         TOKEN_STRING_INITIALIZER
13563                 (struct cmd_set_vf_broadcast_result,
13564                  broadcast, "broadcast");
13565 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13566         TOKEN_NUM_INITIALIZER
13567                 (struct cmd_set_vf_broadcast_result,
13568                  port_id, UINT16);
13569 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13570         TOKEN_NUM_INITIALIZER
13571                 (struct cmd_set_vf_broadcast_result,
13572                  vf_id, UINT16);
13573 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13574         TOKEN_STRING_INITIALIZER
13575                 (struct cmd_set_vf_broadcast_result,
13576                  on_off, "on#off");
13577
13578 static void
13579 cmd_set_vf_broadcast_parsed(
13580         void *parsed_result,
13581         __attribute__((unused)) struct cmdline *cl,
13582         __attribute__((unused)) void *data)
13583 {
13584         struct cmd_set_vf_broadcast_result *res = parsed_result;
13585         int ret = -ENOTSUP;
13586
13587         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13588
13589         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13590                 return;
13591
13592 #ifdef RTE_LIBRTE_I40E_PMD
13593         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13594                                             res->vf_id, is_on);
13595 #endif
13596
13597         switch (ret) {
13598         case 0:
13599                 break;
13600         case -EINVAL:
13601                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13602                 break;
13603         case -ENODEV:
13604                 printf("invalid port_id %d\n", res->port_id);
13605                 break;
13606         case -ENOTSUP:
13607                 printf("function not implemented\n");
13608                 break;
13609         default:
13610                 printf("programming error: (%s)\n", strerror(-ret));
13611         }
13612 }
13613
13614 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13615         .f = cmd_set_vf_broadcast_parsed,
13616         .data = NULL,
13617         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13618         .tokens = {
13619                 (void *)&cmd_set_vf_broadcast_set,
13620                 (void *)&cmd_set_vf_broadcast_vf,
13621                 (void *)&cmd_set_vf_broadcast_broadcast,
13622                 (void *)&cmd_set_vf_broadcast_port_id,
13623                 (void *)&cmd_set_vf_broadcast_vf_id,
13624                 (void *)&cmd_set_vf_broadcast_on_off,
13625                 NULL,
13626         },
13627 };
13628
13629 /* vf vlan tag configuration */
13630
13631 /* Common result structure for vf vlan tag */
13632 struct cmd_set_vf_vlan_tag_result {
13633         cmdline_fixed_string_t set;
13634         cmdline_fixed_string_t vf;
13635         cmdline_fixed_string_t vlan;
13636         cmdline_fixed_string_t tag;
13637         portid_t port_id;
13638         uint16_t vf_id;
13639         cmdline_fixed_string_t on_off;
13640 };
13641
13642 /* Common CLI fields for vf vlan tag enable disable */
13643 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13644         TOKEN_STRING_INITIALIZER
13645                 (struct cmd_set_vf_vlan_tag_result,
13646                  set, "set");
13647 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13648         TOKEN_STRING_INITIALIZER
13649                 (struct cmd_set_vf_vlan_tag_result,
13650                  vf, "vf");
13651 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13652         TOKEN_STRING_INITIALIZER
13653                 (struct cmd_set_vf_vlan_tag_result,
13654                  vlan, "vlan");
13655 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13656         TOKEN_STRING_INITIALIZER
13657                 (struct cmd_set_vf_vlan_tag_result,
13658                  tag, "tag");
13659 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13660         TOKEN_NUM_INITIALIZER
13661                 (struct cmd_set_vf_vlan_tag_result,
13662                  port_id, UINT16);
13663 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13664         TOKEN_NUM_INITIALIZER
13665                 (struct cmd_set_vf_vlan_tag_result,
13666                  vf_id, UINT16);
13667 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13668         TOKEN_STRING_INITIALIZER
13669                 (struct cmd_set_vf_vlan_tag_result,
13670                  on_off, "on#off");
13671
13672 static void
13673 cmd_set_vf_vlan_tag_parsed(
13674         void *parsed_result,
13675         __attribute__((unused)) struct cmdline *cl,
13676         __attribute__((unused)) void *data)
13677 {
13678         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13679         int ret = -ENOTSUP;
13680
13681         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13682
13683         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13684                 return;
13685
13686 #ifdef RTE_LIBRTE_I40E_PMD
13687         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13688                                            res->vf_id, is_on);
13689 #endif
13690
13691         switch (ret) {
13692         case 0:
13693                 break;
13694         case -EINVAL:
13695                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13696                 break;
13697         case -ENODEV:
13698                 printf("invalid port_id %d\n", res->port_id);
13699                 break;
13700         case -ENOTSUP:
13701                 printf("function not implemented\n");
13702                 break;
13703         default:
13704                 printf("programming error: (%s)\n", strerror(-ret));
13705         }
13706 }
13707
13708 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13709         .f = cmd_set_vf_vlan_tag_parsed,
13710         .data = NULL,
13711         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13712         .tokens = {
13713                 (void *)&cmd_set_vf_vlan_tag_set,
13714                 (void *)&cmd_set_vf_vlan_tag_vf,
13715                 (void *)&cmd_set_vf_vlan_tag_vlan,
13716                 (void *)&cmd_set_vf_vlan_tag_tag,
13717                 (void *)&cmd_set_vf_vlan_tag_port_id,
13718                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13719                 (void *)&cmd_set_vf_vlan_tag_on_off,
13720                 NULL,
13721         },
13722 };
13723
13724 /* Common definition of VF and TC TX bandwidth configuration */
13725 struct cmd_vf_tc_bw_result {
13726         cmdline_fixed_string_t set;
13727         cmdline_fixed_string_t vf;
13728         cmdline_fixed_string_t tc;
13729         cmdline_fixed_string_t tx;
13730         cmdline_fixed_string_t min_bw;
13731         cmdline_fixed_string_t max_bw;
13732         cmdline_fixed_string_t strict_link_prio;
13733         portid_t port_id;
13734         uint16_t vf_id;
13735         uint8_t tc_no;
13736         uint32_t bw;
13737         cmdline_fixed_string_t bw_list;
13738         uint8_t tc_map;
13739 };
13740
13741 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13742         TOKEN_STRING_INITIALIZER
13743                 (struct cmd_vf_tc_bw_result,
13744                  set, "set");
13745 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13746         TOKEN_STRING_INITIALIZER
13747                 (struct cmd_vf_tc_bw_result,
13748                  vf, "vf");
13749 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13750         TOKEN_STRING_INITIALIZER
13751                 (struct cmd_vf_tc_bw_result,
13752                  tc, "tc");
13753 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13754         TOKEN_STRING_INITIALIZER
13755                 (struct cmd_vf_tc_bw_result,
13756                  tx, "tx");
13757 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13758         TOKEN_STRING_INITIALIZER
13759                 (struct cmd_vf_tc_bw_result,
13760                  strict_link_prio, "strict-link-priority");
13761 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13762         TOKEN_STRING_INITIALIZER
13763                 (struct cmd_vf_tc_bw_result,
13764                  min_bw, "min-bandwidth");
13765 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13766         TOKEN_STRING_INITIALIZER
13767                 (struct cmd_vf_tc_bw_result,
13768                  max_bw, "max-bandwidth");
13769 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13770         TOKEN_NUM_INITIALIZER
13771                 (struct cmd_vf_tc_bw_result,
13772                  port_id, UINT16);
13773 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13774         TOKEN_NUM_INITIALIZER
13775                 (struct cmd_vf_tc_bw_result,
13776                  vf_id, UINT16);
13777 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13778         TOKEN_NUM_INITIALIZER
13779                 (struct cmd_vf_tc_bw_result,
13780                  tc_no, UINT8);
13781 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13782         TOKEN_NUM_INITIALIZER
13783                 (struct cmd_vf_tc_bw_result,
13784                  bw, UINT32);
13785 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13786         TOKEN_STRING_INITIALIZER
13787                 (struct cmd_vf_tc_bw_result,
13788                  bw_list, NULL);
13789 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13790         TOKEN_NUM_INITIALIZER
13791                 (struct cmd_vf_tc_bw_result,
13792                  tc_map, UINT8);
13793
13794 /* VF max bandwidth setting */
13795 static void
13796 cmd_vf_max_bw_parsed(
13797         void *parsed_result,
13798         __attribute__((unused)) struct cmdline *cl,
13799         __attribute__((unused)) void *data)
13800 {
13801         struct cmd_vf_tc_bw_result *res = parsed_result;
13802         int ret = -ENOTSUP;
13803
13804         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13805                 return;
13806
13807 #ifdef RTE_LIBRTE_I40E_PMD
13808         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13809                                          res->vf_id, res->bw);
13810 #endif
13811
13812         switch (ret) {
13813         case 0:
13814                 break;
13815         case -EINVAL:
13816                 printf("invalid vf_id %d or bandwidth %d\n",
13817                        res->vf_id, res->bw);
13818                 break;
13819         case -ENODEV:
13820                 printf("invalid port_id %d\n", res->port_id);
13821                 break;
13822         case -ENOTSUP:
13823                 printf("function not implemented\n");
13824                 break;
13825         default:
13826                 printf("programming error: (%s)\n", strerror(-ret));
13827         }
13828 }
13829
13830 cmdline_parse_inst_t cmd_vf_max_bw = {
13831         .f = cmd_vf_max_bw_parsed,
13832         .data = NULL,
13833         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13834         .tokens = {
13835                 (void *)&cmd_vf_tc_bw_set,
13836                 (void *)&cmd_vf_tc_bw_vf,
13837                 (void *)&cmd_vf_tc_bw_tx,
13838                 (void *)&cmd_vf_tc_bw_max_bw,
13839                 (void *)&cmd_vf_tc_bw_port_id,
13840                 (void *)&cmd_vf_tc_bw_vf_id,
13841                 (void *)&cmd_vf_tc_bw_bw,
13842                 NULL,
13843         },
13844 };
13845
13846 static int
13847 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13848                            uint8_t *tc_num,
13849                            char *str)
13850 {
13851         uint32_t size;
13852         const char *p, *p0 = str;
13853         char s[256];
13854         char *end;
13855         char *str_fld[16];
13856         uint16_t i;
13857         int ret;
13858
13859         p = strchr(p0, '(');
13860         if (p == NULL) {
13861                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13862                 return -1;
13863         }
13864         p++;
13865         p0 = strchr(p, ')');
13866         if (p0 == NULL) {
13867                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13868                 return -1;
13869         }
13870         size = p0 - p;
13871         if (size >= sizeof(s)) {
13872                 printf("The string size exceeds the internal buffer size\n");
13873                 return -1;
13874         }
13875         snprintf(s, sizeof(s), "%.*s", size, p);
13876         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13877         if (ret <= 0) {
13878                 printf("Failed to get the bandwidth list. ");
13879                 return -1;
13880         }
13881         *tc_num = ret;
13882         for (i = 0; i < ret; i++)
13883                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13884
13885         return 0;
13886 }
13887
13888 /* TC min bandwidth setting */
13889 static void
13890 cmd_vf_tc_min_bw_parsed(
13891         void *parsed_result,
13892         __attribute__((unused)) struct cmdline *cl,
13893         __attribute__((unused)) void *data)
13894 {
13895         struct cmd_vf_tc_bw_result *res = parsed_result;
13896         uint8_t tc_num;
13897         uint8_t bw[16];
13898         int ret = -ENOTSUP;
13899
13900         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13901                 return;
13902
13903         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13904         if (ret)
13905                 return;
13906
13907 #ifdef RTE_LIBRTE_I40E_PMD
13908         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13909                                               tc_num, bw);
13910 #endif
13911
13912         switch (ret) {
13913         case 0:
13914                 break;
13915         case -EINVAL:
13916                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13917                 break;
13918         case -ENODEV:
13919                 printf("invalid port_id %d\n", res->port_id);
13920                 break;
13921         case -ENOTSUP:
13922                 printf("function not implemented\n");
13923                 break;
13924         default:
13925                 printf("programming error: (%s)\n", strerror(-ret));
13926         }
13927 }
13928
13929 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13930         .f = cmd_vf_tc_min_bw_parsed,
13931         .data = NULL,
13932         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13933                     " <bw1, bw2, ...>",
13934         .tokens = {
13935                 (void *)&cmd_vf_tc_bw_set,
13936                 (void *)&cmd_vf_tc_bw_vf,
13937                 (void *)&cmd_vf_tc_bw_tc,
13938                 (void *)&cmd_vf_tc_bw_tx,
13939                 (void *)&cmd_vf_tc_bw_min_bw,
13940                 (void *)&cmd_vf_tc_bw_port_id,
13941                 (void *)&cmd_vf_tc_bw_vf_id,
13942                 (void *)&cmd_vf_tc_bw_bw_list,
13943                 NULL,
13944         },
13945 };
13946
13947 static void
13948 cmd_tc_min_bw_parsed(
13949         void *parsed_result,
13950         __attribute__((unused)) struct cmdline *cl,
13951         __attribute__((unused)) void *data)
13952 {
13953         struct cmd_vf_tc_bw_result *res = parsed_result;
13954         struct rte_port *port;
13955         uint8_t tc_num;
13956         uint8_t bw[16];
13957         int ret = -ENOTSUP;
13958
13959         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13960                 return;
13961
13962         port = &ports[res->port_id];
13963         /** Check if the port is not started **/
13964         if (port->port_status != RTE_PORT_STOPPED) {
13965                 printf("Please stop port %d first\n", res->port_id);
13966                 return;
13967         }
13968
13969         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13970         if (ret)
13971                 return;
13972
13973 #ifdef RTE_LIBRTE_IXGBE_PMD
13974         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13975 #endif
13976
13977         switch (ret) {
13978         case 0:
13979                 break;
13980         case -EINVAL:
13981                 printf("invalid bandwidth\n");
13982                 break;
13983         case -ENODEV:
13984                 printf("invalid port_id %d\n", res->port_id);
13985                 break;
13986         case -ENOTSUP:
13987                 printf("function not implemented\n");
13988                 break;
13989         default:
13990                 printf("programming error: (%s)\n", strerror(-ret));
13991         }
13992 }
13993
13994 cmdline_parse_inst_t cmd_tc_min_bw = {
13995         .f = cmd_tc_min_bw_parsed,
13996         .data = NULL,
13997         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13998         .tokens = {
13999                 (void *)&cmd_vf_tc_bw_set,
14000                 (void *)&cmd_vf_tc_bw_tc,
14001                 (void *)&cmd_vf_tc_bw_tx,
14002                 (void *)&cmd_vf_tc_bw_min_bw,
14003                 (void *)&cmd_vf_tc_bw_port_id,
14004                 (void *)&cmd_vf_tc_bw_bw_list,
14005                 NULL,
14006         },
14007 };
14008
14009 /* TC max bandwidth setting */
14010 static void
14011 cmd_vf_tc_max_bw_parsed(
14012         void *parsed_result,
14013         __attribute__((unused)) struct cmdline *cl,
14014         __attribute__((unused)) void *data)
14015 {
14016         struct cmd_vf_tc_bw_result *res = parsed_result;
14017         int ret = -ENOTSUP;
14018
14019         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14020                 return;
14021
14022 #ifdef RTE_LIBRTE_I40E_PMD
14023         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14024                                             res->tc_no, res->bw);
14025 #endif
14026
14027         switch (ret) {
14028         case 0:
14029                 break;
14030         case -EINVAL:
14031                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14032                        res->vf_id, res->tc_no, res->bw);
14033                 break;
14034         case -ENODEV:
14035                 printf("invalid port_id %d\n", res->port_id);
14036                 break;
14037         case -ENOTSUP:
14038                 printf("function not implemented\n");
14039                 break;
14040         default:
14041                 printf("programming error: (%s)\n", strerror(-ret));
14042         }
14043 }
14044
14045 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14046         .f = cmd_vf_tc_max_bw_parsed,
14047         .data = NULL,
14048         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14049                     " <bandwidth>",
14050         .tokens = {
14051                 (void *)&cmd_vf_tc_bw_set,
14052                 (void *)&cmd_vf_tc_bw_vf,
14053                 (void *)&cmd_vf_tc_bw_tc,
14054                 (void *)&cmd_vf_tc_bw_tx,
14055                 (void *)&cmd_vf_tc_bw_max_bw,
14056                 (void *)&cmd_vf_tc_bw_port_id,
14057                 (void *)&cmd_vf_tc_bw_vf_id,
14058                 (void *)&cmd_vf_tc_bw_tc_no,
14059                 (void *)&cmd_vf_tc_bw_bw,
14060                 NULL,
14061         },
14062 };
14063
14064
14065 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14066
14067 /* *** Set Port default Traffic Management Hierarchy *** */
14068 struct cmd_set_port_tm_hierarchy_default_result {
14069         cmdline_fixed_string_t set;
14070         cmdline_fixed_string_t port;
14071         cmdline_fixed_string_t tm;
14072         cmdline_fixed_string_t hierarchy;
14073         cmdline_fixed_string_t def;
14074         portid_t port_id;
14075 };
14076
14077 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14078         TOKEN_STRING_INITIALIZER(
14079                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14080 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14081         TOKEN_STRING_INITIALIZER(
14082                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14083 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14084         TOKEN_STRING_INITIALIZER(
14085                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14086 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14087         TOKEN_STRING_INITIALIZER(
14088                 struct cmd_set_port_tm_hierarchy_default_result,
14089                         hierarchy, "hierarchy");
14090 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14091         TOKEN_STRING_INITIALIZER(
14092                 struct cmd_set_port_tm_hierarchy_default_result,
14093                         def, "default");
14094 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14095         TOKEN_NUM_INITIALIZER(
14096                 struct cmd_set_port_tm_hierarchy_default_result,
14097                         port_id, UINT16);
14098
14099 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14100         __attribute__((unused)) struct cmdline *cl,
14101         __attribute__((unused)) void *data)
14102 {
14103         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14104         struct rte_port *p;
14105         portid_t port_id = res->port_id;
14106
14107         if (port_id_is_invalid(port_id, ENABLED_WARN))
14108                 return;
14109
14110         p = &ports[port_id];
14111
14112         /* Port tm flag */
14113         if (p->softport.tm_flag == 0) {
14114                 printf("  tm not enabled on port %u (error)\n", port_id);
14115                 return;
14116         }
14117
14118         /* Forward mode: tm */
14119         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14120                 printf("  tm mode not enabled(error)\n");
14121                 return;
14122         }
14123
14124         /* Set the default tm hierarchy */
14125         p->softport.tm.default_hierarchy_enable = 1;
14126 }
14127
14128 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14129         .f = cmd_set_port_tm_hierarchy_default_parsed,
14130         .data = NULL,
14131         .help_str = "set port tm hierarchy default <port_id>",
14132         .tokens = {
14133                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14134                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14135                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14136                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14137                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14138                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14139                 NULL,
14140         },
14141 };
14142 #endif
14143
14144 /* Strict link priority scheduling mode setting */
14145 static void
14146 cmd_strict_link_prio_parsed(
14147         void *parsed_result,
14148         __attribute__((unused)) struct cmdline *cl,
14149         __attribute__((unused)) void *data)
14150 {
14151         struct cmd_vf_tc_bw_result *res = parsed_result;
14152         int ret = -ENOTSUP;
14153
14154         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14155                 return;
14156
14157 #ifdef RTE_LIBRTE_I40E_PMD
14158         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14159 #endif
14160
14161         switch (ret) {
14162         case 0:
14163                 break;
14164         case -EINVAL:
14165                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14166                 break;
14167         case -ENODEV:
14168                 printf("invalid port_id %d\n", res->port_id);
14169                 break;
14170         case -ENOTSUP:
14171                 printf("function not implemented\n");
14172                 break;
14173         default:
14174                 printf("programming error: (%s)\n", strerror(-ret));
14175         }
14176 }
14177
14178 cmdline_parse_inst_t cmd_strict_link_prio = {
14179         .f = cmd_strict_link_prio_parsed,
14180         .data = NULL,
14181         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14182         .tokens = {
14183                 (void *)&cmd_vf_tc_bw_set,
14184                 (void *)&cmd_vf_tc_bw_tx,
14185                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14186                 (void *)&cmd_vf_tc_bw_port_id,
14187                 (void *)&cmd_vf_tc_bw_tc_map,
14188                 NULL,
14189         },
14190 };
14191
14192 /* Load dynamic device personalization*/
14193 struct cmd_ddp_add_result {
14194         cmdline_fixed_string_t ddp;
14195         cmdline_fixed_string_t add;
14196         portid_t port_id;
14197         char filepath[];
14198 };
14199
14200 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14201         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14202 cmdline_parse_token_string_t cmd_ddp_add_add =
14203         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14204 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14205         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14206 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14207         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14208
14209 static void
14210 cmd_ddp_add_parsed(
14211         void *parsed_result,
14212         __attribute__((unused)) struct cmdline *cl,
14213         __attribute__((unused)) void *data)
14214 {
14215         struct cmd_ddp_add_result *res = parsed_result;
14216         uint8_t *buff;
14217         uint32_t size;
14218         char *filepath;
14219         char *file_fld[2];
14220         int file_num;
14221         int ret = -ENOTSUP;
14222
14223         if (res->port_id > nb_ports) {
14224                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14225                 return;
14226         }
14227
14228         if (!all_ports_stopped()) {
14229                 printf("Please stop all ports first\n");
14230                 return;
14231         }
14232
14233         filepath = strdup(res->filepath);
14234         if (filepath == NULL) {
14235                 printf("Failed to allocate memory\n");
14236                 return;
14237         }
14238         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14239
14240         buff = open_ddp_package_file(file_fld[0], &size);
14241         if (!buff) {
14242                 free((void *)filepath);
14243                 return;
14244         }
14245
14246 #ifdef RTE_LIBRTE_I40E_PMD
14247         if (ret == -ENOTSUP)
14248                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14249                                                buff, size,
14250                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14251 #endif
14252
14253         if (ret == -EEXIST)
14254                 printf("Profile has already existed.\n");
14255         else if (ret < 0)
14256                 printf("Failed to load profile.\n");
14257         else if (file_num == 2)
14258                 save_ddp_package_file(file_fld[1], buff, size);
14259
14260         close_ddp_package_file(buff);
14261         free((void *)filepath);
14262 }
14263
14264 cmdline_parse_inst_t cmd_ddp_add = {
14265         .f = cmd_ddp_add_parsed,
14266         .data = NULL,
14267         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14268         .tokens = {
14269                 (void *)&cmd_ddp_add_ddp,
14270                 (void *)&cmd_ddp_add_add,
14271                 (void *)&cmd_ddp_add_port_id,
14272                 (void *)&cmd_ddp_add_filepath,
14273                 NULL,
14274         },
14275 };
14276
14277 /* Delete dynamic device personalization*/
14278 struct cmd_ddp_del_result {
14279         cmdline_fixed_string_t ddp;
14280         cmdline_fixed_string_t del;
14281         portid_t port_id;
14282         char filepath[];
14283 };
14284
14285 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14286         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14287 cmdline_parse_token_string_t cmd_ddp_del_del =
14288         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14289 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14290         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14291 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14292         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14293
14294 static void
14295 cmd_ddp_del_parsed(
14296         void *parsed_result,
14297         __attribute__((unused)) struct cmdline *cl,
14298         __attribute__((unused)) void *data)
14299 {
14300         struct cmd_ddp_del_result *res = parsed_result;
14301         uint8_t *buff;
14302         uint32_t size;
14303         int ret = -ENOTSUP;
14304
14305         if (res->port_id > nb_ports) {
14306                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14307                 return;
14308         }
14309
14310         if (!all_ports_stopped()) {
14311                 printf("Please stop all ports first\n");
14312                 return;
14313         }
14314
14315         buff = open_ddp_package_file(res->filepath, &size);
14316         if (!buff)
14317                 return;
14318
14319 #ifdef RTE_LIBRTE_I40E_PMD
14320         if (ret == -ENOTSUP)
14321                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14322                                                buff, size,
14323                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14324 #endif
14325
14326         if (ret == -EACCES)
14327                 printf("Profile does not exist.\n");
14328         else if (ret < 0)
14329                 printf("Failed to delete profile.\n");
14330
14331         close_ddp_package_file(buff);
14332 }
14333
14334 cmdline_parse_inst_t cmd_ddp_del = {
14335         .f = cmd_ddp_del_parsed,
14336         .data = NULL,
14337         .help_str = "ddp del <port_id> <profile_path>",
14338         .tokens = {
14339                 (void *)&cmd_ddp_del_ddp,
14340                 (void *)&cmd_ddp_del_del,
14341                 (void *)&cmd_ddp_del_port_id,
14342                 (void *)&cmd_ddp_del_filepath,
14343                 NULL,
14344         },
14345 };
14346
14347 /* Get dynamic device personalization profile info */
14348 struct cmd_ddp_info_result {
14349         cmdline_fixed_string_t ddp;
14350         cmdline_fixed_string_t get;
14351         cmdline_fixed_string_t info;
14352         char filepath[];
14353 };
14354
14355 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14356         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14357 cmdline_parse_token_string_t cmd_ddp_info_get =
14358         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14359 cmdline_parse_token_string_t cmd_ddp_info_info =
14360         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14361 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14362         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14363
14364 static void
14365 cmd_ddp_info_parsed(
14366         void *parsed_result,
14367         __attribute__((unused)) struct cmdline *cl,
14368         __attribute__((unused)) void *data)
14369 {
14370         struct cmd_ddp_info_result *res = parsed_result;
14371         uint8_t *pkg;
14372         uint32_t pkg_size;
14373         int ret = -ENOTSUP;
14374 #ifdef RTE_LIBRTE_I40E_PMD
14375         uint32_t i, j, n;
14376         uint8_t *buff;
14377         uint32_t buff_size = 0;
14378         struct rte_pmd_i40e_profile_info info;
14379         uint32_t dev_num = 0;
14380         struct rte_pmd_i40e_ddp_device_id *devs;
14381         uint32_t proto_num = 0;
14382         struct rte_pmd_i40e_proto_info *proto = NULL;
14383         uint32_t pctype_num = 0;
14384         struct rte_pmd_i40e_ptype_info *pctype;
14385         uint32_t ptype_num = 0;
14386         struct rte_pmd_i40e_ptype_info *ptype;
14387         uint8_t proto_id;
14388
14389 #endif
14390
14391         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14392         if (!pkg)
14393                 return;
14394
14395 #ifdef RTE_LIBRTE_I40E_PMD
14396         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14397                                 (uint8_t *)&info, sizeof(info),
14398                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14399         if (!ret) {
14400                 printf("Global Track id:       0x%x\n", info.track_id);
14401                 printf("Global Version:        %d.%d.%d.%d\n",
14402                         info.version.major,
14403                         info.version.minor,
14404                         info.version.update,
14405                         info.version.draft);
14406                 printf("Global Package name:   %s\n\n", info.name);
14407         }
14408
14409         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14410                                 (uint8_t *)&info, sizeof(info),
14411                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14412         if (!ret) {
14413                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14414                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14415                         info.version.major,
14416                         info.version.minor,
14417                         info.version.update,
14418                         info.version.draft);
14419                 printf("i40e Profile name:     %s\n\n", info.name);
14420         }
14421
14422         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14423                                 (uint8_t *)&buff_size, sizeof(buff_size),
14424                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14425         if (!ret && buff_size) {
14426                 buff = (uint8_t *)malloc(buff_size);
14427                 if (buff) {
14428                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14429                                                 buff, buff_size,
14430                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14431                         if (!ret)
14432                                 printf("Package Notes:\n%s\n\n", buff);
14433                         free(buff);
14434                 }
14435         }
14436
14437         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14438                                 (uint8_t *)&dev_num, sizeof(dev_num),
14439                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14440         if (!ret && dev_num) {
14441                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14442                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14443                 if (devs) {
14444                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14445                                                 (uint8_t *)devs, buff_size,
14446                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14447                         if (!ret) {
14448                                 printf("List of supported devices:\n");
14449                                 for (i = 0; i < dev_num; i++) {
14450                                         printf("  %04X:%04X %04X:%04X\n",
14451                                                 devs[i].vendor_dev_id >> 16,
14452                                                 devs[i].vendor_dev_id & 0xFFFF,
14453                                                 devs[i].sub_vendor_dev_id >> 16,
14454                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14455                                 }
14456                                 printf("\n");
14457                         }
14458                         free(devs);
14459                 }
14460         }
14461
14462         /* get information about protocols and packet types */
14463         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14464                 (uint8_t *)&proto_num, sizeof(proto_num),
14465                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14466         if (ret || !proto_num)
14467                 goto no_print_return;
14468
14469         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14470         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14471         if (!proto)
14472                 goto no_print_return;
14473
14474         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14475                                         buff_size,
14476                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14477         if (!ret) {
14478                 printf("List of used protocols:\n");
14479                 for (i = 0; i < proto_num; i++)
14480                         printf("  %2u: %s\n", proto[i].proto_id,
14481                                proto[i].name);
14482                 printf("\n");
14483         }
14484         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14485                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14486                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14487         if (ret || !pctype_num)
14488                 goto no_print_pctypes;
14489
14490         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14491         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14492         if (!pctype)
14493                 goto no_print_pctypes;
14494
14495         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14496                                         buff_size,
14497                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14498         if (ret) {
14499                 free(pctype);
14500                 goto no_print_pctypes;
14501         }
14502
14503         printf("List of defined packet classification types:\n");
14504         for (i = 0; i < pctype_num; i++) {
14505                 printf("  %2u:", pctype[i].ptype_id);
14506                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14507                         proto_id = pctype[i].protocols[j];
14508                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14509                                 for (n = 0; n < proto_num; n++) {
14510                                         if (proto[n].proto_id == proto_id) {
14511                                                 printf(" %s", proto[n].name);
14512                                                 break;
14513                                         }
14514                                 }
14515                         }
14516                 }
14517                 printf("\n");
14518         }
14519         printf("\n");
14520         free(pctype);
14521
14522 no_print_pctypes:
14523
14524         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14525                                         sizeof(ptype_num),
14526                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14527         if (ret || !ptype_num)
14528                 goto no_print_return;
14529
14530         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14531         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14532         if (!ptype)
14533                 goto no_print_return;
14534
14535         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14536                                         buff_size,
14537                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14538         if (ret) {
14539                 free(ptype);
14540                 goto no_print_return;
14541         }
14542         printf("List of defined packet types:\n");
14543         for (i = 0; i < ptype_num; i++) {
14544                 printf("  %2u:", ptype[i].ptype_id);
14545                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14546                         proto_id = ptype[i].protocols[j];
14547                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14548                                 for (n = 0; n < proto_num; n++) {
14549                                         if (proto[n].proto_id == proto_id) {
14550                                                 printf(" %s", proto[n].name);
14551                                                 break;
14552                                         }
14553                                 }
14554                         }
14555                 }
14556                 printf("\n");
14557         }
14558         free(ptype);
14559         printf("\n");
14560
14561         ret = 0;
14562 no_print_return:
14563         if (proto)
14564                 free(proto);
14565 #endif
14566         if (ret == -ENOTSUP)
14567                 printf("Function not supported in PMD driver\n");
14568         close_ddp_package_file(pkg);
14569 }
14570
14571 cmdline_parse_inst_t cmd_ddp_get_info = {
14572         .f = cmd_ddp_info_parsed,
14573         .data = NULL,
14574         .help_str = "ddp get info <profile_path>",
14575         .tokens = {
14576                 (void *)&cmd_ddp_info_ddp,
14577                 (void *)&cmd_ddp_info_get,
14578                 (void *)&cmd_ddp_info_info,
14579                 (void *)&cmd_ddp_info_filepath,
14580                 NULL,
14581         },
14582 };
14583
14584 /* Get dynamic device personalization profile info list*/
14585 #define PROFILE_INFO_SIZE 48
14586 #define MAX_PROFILE_NUM 16
14587
14588 struct cmd_ddp_get_list_result {
14589         cmdline_fixed_string_t ddp;
14590         cmdline_fixed_string_t get;
14591         cmdline_fixed_string_t list;
14592         portid_t port_id;
14593 };
14594
14595 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14596         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14597 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14598         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14599 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14600         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14601 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14602         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14603
14604 static void
14605 cmd_ddp_get_list_parsed(
14606         void *parsed_result,
14607         __attribute__((unused)) struct cmdline *cl,
14608         __attribute__((unused)) void *data)
14609 {
14610         struct cmd_ddp_get_list_result *res = parsed_result;
14611 #ifdef RTE_LIBRTE_I40E_PMD
14612         struct rte_pmd_i40e_profile_list *p_list;
14613         struct rte_pmd_i40e_profile_info *p_info;
14614         uint32_t p_num;
14615         uint32_t size;
14616         uint32_t i;
14617 #endif
14618         int ret = -ENOTSUP;
14619
14620         if (res->port_id > nb_ports) {
14621                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14622                 return;
14623         }
14624
14625 #ifdef RTE_LIBRTE_I40E_PMD
14626         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14627         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14628         if (!p_list)
14629                 printf("%s: Failed to malloc buffer\n", __func__);
14630
14631         if (ret == -ENOTSUP)
14632                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14633                                                 (uint8_t *)p_list, size);
14634
14635         if (!ret) {
14636                 p_num = p_list->p_count;
14637                 printf("Profile number is: %d\n\n", p_num);
14638
14639                 for (i = 0; i < p_num; i++) {
14640                         p_info = &p_list->p_info[i];
14641                         printf("Profile %d:\n", i);
14642                         printf("Track id:     0x%x\n", p_info->track_id);
14643                         printf("Version:      %d.%d.%d.%d\n",
14644                                p_info->version.major,
14645                                p_info->version.minor,
14646                                p_info->version.update,
14647                                p_info->version.draft);
14648                         printf("Profile name: %s\n\n", p_info->name);
14649                 }
14650         }
14651
14652         free(p_list);
14653 #endif
14654
14655         if (ret < 0)
14656                 printf("Failed to get ddp list\n");
14657 }
14658
14659 cmdline_parse_inst_t cmd_ddp_get_list = {
14660         .f = cmd_ddp_get_list_parsed,
14661         .data = NULL,
14662         .help_str = "ddp get list <port_id>",
14663         .tokens = {
14664                 (void *)&cmd_ddp_get_list_ddp,
14665                 (void *)&cmd_ddp_get_list_get,
14666                 (void *)&cmd_ddp_get_list_list,
14667                 (void *)&cmd_ddp_get_list_port_id,
14668                 NULL,
14669         },
14670 };
14671
14672 /* show vf stats */
14673
14674 /* Common result structure for show vf stats */
14675 struct cmd_show_vf_stats_result {
14676         cmdline_fixed_string_t show;
14677         cmdline_fixed_string_t vf;
14678         cmdline_fixed_string_t stats;
14679         portid_t port_id;
14680         uint16_t vf_id;
14681 };
14682
14683 /* Common CLI fields show vf stats*/
14684 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14685         TOKEN_STRING_INITIALIZER
14686                 (struct cmd_show_vf_stats_result,
14687                  show, "show");
14688 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14689         TOKEN_STRING_INITIALIZER
14690                 (struct cmd_show_vf_stats_result,
14691                  vf, "vf");
14692 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14693         TOKEN_STRING_INITIALIZER
14694                 (struct cmd_show_vf_stats_result,
14695                  stats, "stats");
14696 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14697         TOKEN_NUM_INITIALIZER
14698                 (struct cmd_show_vf_stats_result,
14699                  port_id, UINT16);
14700 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14701         TOKEN_NUM_INITIALIZER
14702                 (struct cmd_show_vf_stats_result,
14703                  vf_id, UINT16);
14704
14705 static void
14706 cmd_show_vf_stats_parsed(
14707         void *parsed_result,
14708         __attribute__((unused)) struct cmdline *cl,
14709         __attribute__((unused)) void *data)
14710 {
14711         struct cmd_show_vf_stats_result *res = parsed_result;
14712         struct rte_eth_stats stats;
14713         int ret = -ENOTSUP;
14714         static const char *nic_stats_border = "########################";
14715
14716         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14717                 return;
14718
14719         memset(&stats, 0, sizeof(stats));
14720
14721 #ifdef RTE_LIBRTE_I40E_PMD
14722         if (ret == -ENOTSUP)
14723                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14724                                                 res->vf_id,
14725                                                 &stats);
14726 #endif
14727 #ifdef RTE_LIBRTE_BNXT_PMD
14728         if (ret == -ENOTSUP)
14729                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14730                                                 res->vf_id,
14731                                                 &stats);
14732 #endif
14733
14734         switch (ret) {
14735         case 0:
14736                 break;
14737         case -EINVAL:
14738                 printf("invalid vf_id %d\n", res->vf_id);
14739                 break;
14740         case -ENODEV:
14741                 printf("invalid port_id %d\n", res->port_id);
14742                 break;
14743         case -ENOTSUP:
14744                 printf("function not implemented\n");
14745                 break;
14746         default:
14747                 printf("programming error: (%s)\n", strerror(-ret));
14748         }
14749
14750         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14751                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14752
14753         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14754                "%-"PRIu64"\n",
14755                stats.ipackets, stats.imissed, stats.ibytes);
14756         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14757         printf("  RX-nombuf:  %-10"PRIu64"\n",
14758                stats.rx_nombuf);
14759         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14760                "%-"PRIu64"\n",
14761                stats.opackets, stats.oerrors, stats.obytes);
14762
14763         printf("  %s############################%s\n",
14764                                nic_stats_border, nic_stats_border);
14765 }
14766
14767 cmdline_parse_inst_t cmd_show_vf_stats = {
14768         .f = cmd_show_vf_stats_parsed,
14769         .data = NULL,
14770         .help_str = "show vf stats <port_id> <vf_id>",
14771         .tokens = {
14772                 (void *)&cmd_show_vf_stats_show,
14773                 (void *)&cmd_show_vf_stats_vf,
14774                 (void *)&cmd_show_vf_stats_stats,
14775                 (void *)&cmd_show_vf_stats_port_id,
14776                 (void *)&cmd_show_vf_stats_vf_id,
14777                 NULL,
14778         },
14779 };
14780
14781 /* clear vf stats */
14782
14783 /* Common result structure for clear vf stats */
14784 struct cmd_clear_vf_stats_result {
14785         cmdline_fixed_string_t clear;
14786         cmdline_fixed_string_t vf;
14787         cmdline_fixed_string_t stats;
14788         portid_t port_id;
14789         uint16_t vf_id;
14790 };
14791
14792 /* Common CLI fields clear vf stats*/
14793 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14794         TOKEN_STRING_INITIALIZER
14795                 (struct cmd_clear_vf_stats_result,
14796                  clear, "clear");
14797 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14798         TOKEN_STRING_INITIALIZER
14799                 (struct cmd_clear_vf_stats_result,
14800                  vf, "vf");
14801 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14802         TOKEN_STRING_INITIALIZER
14803                 (struct cmd_clear_vf_stats_result,
14804                  stats, "stats");
14805 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14806         TOKEN_NUM_INITIALIZER
14807                 (struct cmd_clear_vf_stats_result,
14808                  port_id, UINT16);
14809 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14810         TOKEN_NUM_INITIALIZER
14811                 (struct cmd_clear_vf_stats_result,
14812                  vf_id, UINT16);
14813
14814 static void
14815 cmd_clear_vf_stats_parsed(
14816         void *parsed_result,
14817         __attribute__((unused)) struct cmdline *cl,
14818         __attribute__((unused)) void *data)
14819 {
14820         struct cmd_clear_vf_stats_result *res = parsed_result;
14821         int ret = -ENOTSUP;
14822
14823         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14824                 return;
14825
14826 #ifdef RTE_LIBRTE_I40E_PMD
14827         if (ret == -ENOTSUP)
14828                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14829                                                   res->vf_id);
14830 #endif
14831 #ifdef RTE_LIBRTE_BNXT_PMD
14832         if (ret == -ENOTSUP)
14833                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14834                                                   res->vf_id);
14835 #endif
14836
14837         switch (ret) {
14838         case 0:
14839                 break;
14840         case -EINVAL:
14841                 printf("invalid vf_id %d\n", res->vf_id);
14842                 break;
14843         case -ENODEV:
14844                 printf("invalid port_id %d\n", res->port_id);
14845                 break;
14846         case -ENOTSUP:
14847                 printf("function not implemented\n");
14848                 break;
14849         default:
14850                 printf("programming error: (%s)\n", strerror(-ret));
14851         }
14852 }
14853
14854 cmdline_parse_inst_t cmd_clear_vf_stats = {
14855         .f = cmd_clear_vf_stats_parsed,
14856         .data = NULL,
14857         .help_str = "clear vf stats <port_id> <vf_id>",
14858         .tokens = {
14859                 (void *)&cmd_clear_vf_stats_clear,
14860                 (void *)&cmd_clear_vf_stats_vf,
14861                 (void *)&cmd_clear_vf_stats_stats,
14862                 (void *)&cmd_clear_vf_stats_port_id,
14863                 (void *)&cmd_clear_vf_stats_vf_id,
14864                 NULL,
14865         },
14866 };
14867
14868 /* port config pctype mapping reset */
14869
14870 /* Common result structure for port config pctype mapping reset */
14871 struct cmd_pctype_mapping_reset_result {
14872         cmdline_fixed_string_t port;
14873         cmdline_fixed_string_t config;
14874         portid_t port_id;
14875         cmdline_fixed_string_t pctype;
14876         cmdline_fixed_string_t mapping;
14877         cmdline_fixed_string_t reset;
14878 };
14879
14880 /* Common CLI fields for port config pctype mapping reset*/
14881 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14882         TOKEN_STRING_INITIALIZER
14883                 (struct cmd_pctype_mapping_reset_result,
14884                  port, "port");
14885 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14886         TOKEN_STRING_INITIALIZER
14887                 (struct cmd_pctype_mapping_reset_result,
14888                  config, "config");
14889 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14890         TOKEN_NUM_INITIALIZER
14891                 (struct cmd_pctype_mapping_reset_result,
14892                  port_id, UINT16);
14893 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14894         TOKEN_STRING_INITIALIZER
14895                 (struct cmd_pctype_mapping_reset_result,
14896                  pctype, "pctype");
14897 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14898         TOKEN_STRING_INITIALIZER
14899                 (struct cmd_pctype_mapping_reset_result,
14900                  mapping, "mapping");
14901 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14902         TOKEN_STRING_INITIALIZER
14903                 (struct cmd_pctype_mapping_reset_result,
14904                  reset, "reset");
14905
14906 static void
14907 cmd_pctype_mapping_reset_parsed(
14908         void *parsed_result,
14909         __attribute__((unused)) struct cmdline *cl,
14910         __attribute__((unused)) void *data)
14911 {
14912         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14913         int ret = -ENOTSUP;
14914
14915         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14916                 return;
14917
14918 #ifdef RTE_LIBRTE_I40E_PMD
14919         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14920 #endif
14921
14922         switch (ret) {
14923         case 0:
14924                 break;
14925         case -ENODEV:
14926                 printf("invalid port_id %d\n", res->port_id);
14927                 break;
14928         case -ENOTSUP:
14929                 printf("function not implemented\n");
14930                 break;
14931         default:
14932                 printf("programming error: (%s)\n", strerror(-ret));
14933         }
14934 }
14935
14936 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14937         .f = cmd_pctype_mapping_reset_parsed,
14938         .data = NULL,
14939         .help_str = "port config <port_id> pctype mapping reset",
14940         .tokens = {
14941                 (void *)&cmd_pctype_mapping_reset_port,
14942                 (void *)&cmd_pctype_mapping_reset_config,
14943                 (void *)&cmd_pctype_mapping_reset_port_id,
14944                 (void *)&cmd_pctype_mapping_reset_pctype,
14945                 (void *)&cmd_pctype_mapping_reset_mapping,
14946                 (void *)&cmd_pctype_mapping_reset_reset,
14947                 NULL,
14948         },
14949 };
14950
14951 /* show port pctype mapping */
14952
14953 /* Common result structure for show port pctype mapping */
14954 struct cmd_pctype_mapping_get_result {
14955         cmdline_fixed_string_t show;
14956         cmdline_fixed_string_t port;
14957         portid_t port_id;
14958         cmdline_fixed_string_t pctype;
14959         cmdline_fixed_string_t mapping;
14960 };
14961
14962 /* Common CLI fields for pctype mapping get */
14963 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14964         TOKEN_STRING_INITIALIZER
14965                 (struct cmd_pctype_mapping_get_result,
14966                  show, "show");
14967 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14968         TOKEN_STRING_INITIALIZER
14969                 (struct cmd_pctype_mapping_get_result,
14970                  port, "port");
14971 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14972         TOKEN_NUM_INITIALIZER
14973                 (struct cmd_pctype_mapping_get_result,
14974                  port_id, UINT16);
14975 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14976         TOKEN_STRING_INITIALIZER
14977                 (struct cmd_pctype_mapping_get_result,
14978                  pctype, "pctype");
14979 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14980         TOKEN_STRING_INITIALIZER
14981                 (struct cmd_pctype_mapping_get_result,
14982                  mapping, "mapping");
14983
14984 static void
14985 cmd_pctype_mapping_get_parsed(
14986         void *parsed_result,
14987         __attribute__((unused)) struct cmdline *cl,
14988         __attribute__((unused)) void *data)
14989 {
14990         struct cmd_pctype_mapping_get_result *res = parsed_result;
14991         int ret = -ENOTSUP;
14992 #ifdef RTE_LIBRTE_I40E_PMD
14993         struct rte_pmd_i40e_flow_type_mapping
14994                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14995         int i, j, first_pctype;
14996 #endif
14997
14998         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14999                 return;
15000
15001 #ifdef RTE_LIBRTE_I40E_PMD
15002         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
15003 #endif
15004
15005         switch (ret) {
15006         case 0:
15007                 break;
15008         case -ENODEV:
15009                 printf("invalid port_id %d\n", res->port_id);
15010                 return;
15011         case -ENOTSUP:
15012                 printf("function not implemented\n");
15013                 return;
15014         default:
15015                 printf("programming error: (%s)\n", strerror(-ret));
15016                 return;
15017         }
15018
15019 #ifdef RTE_LIBRTE_I40E_PMD
15020         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15021                 if (mapping[i].pctype != 0ULL) {
15022                         first_pctype = 1;
15023
15024                         printf("pctype: ");
15025                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15026                                 if (mapping[i].pctype & (1ULL << j)) {
15027                                         printf(first_pctype ?
15028                                                "%02d" : ",%02d", j);
15029                                         first_pctype = 0;
15030                                 }
15031                         }
15032                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15033                 }
15034         }
15035 #endif
15036 }
15037
15038 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15039         .f = cmd_pctype_mapping_get_parsed,
15040         .data = NULL,
15041         .help_str = "show port <port_id> pctype mapping",
15042         .tokens = {
15043                 (void *)&cmd_pctype_mapping_get_show,
15044                 (void *)&cmd_pctype_mapping_get_port,
15045                 (void *)&cmd_pctype_mapping_get_port_id,
15046                 (void *)&cmd_pctype_mapping_get_pctype,
15047                 (void *)&cmd_pctype_mapping_get_mapping,
15048                 NULL,
15049         },
15050 };
15051
15052 /* port config pctype mapping update */
15053
15054 /* Common result structure for port config pctype mapping update */
15055 struct cmd_pctype_mapping_update_result {
15056         cmdline_fixed_string_t port;
15057         cmdline_fixed_string_t config;
15058         portid_t port_id;
15059         cmdline_fixed_string_t pctype;
15060         cmdline_fixed_string_t mapping;
15061         cmdline_fixed_string_t update;
15062         cmdline_fixed_string_t pctype_list;
15063         uint16_t flow_type;
15064 };
15065
15066 /* Common CLI fields for pctype mapping update*/
15067 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15068         TOKEN_STRING_INITIALIZER
15069                 (struct cmd_pctype_mapping_update_result,
15070                  port, "port");
15071 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15072         TOKEN_STRING_INITIALIZER
15073                 (struct cmd_pctype_mapping_update_result,
15074                  config, "config");
15075 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15076         TOKEN_NUM_INITIALIZER
15077                 (struct cmd_pctype_mapping_update_result,
15078                  port_id, UINT16);
15079 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15080         TOKEN_STRING_INITIALIZER
15081                 (struct cmd_pctype_mapping_update_result,
15082                  pctype, "pctype");
15083 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15084         TOKEN_STRING_INITIALIZER
15085                 (struct cmd_pctype_mapping_update_result,
15086                  mapping, "mapping");
15087 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15088         TOKEN_STRING_INITIALIZER
15089                 (struct cmd_pctype_mapping_update_result,
15090                  update, "update");
15091 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15092         TOKEN_STRING_INITIALIZER
15093                 (struct cmd_pctype_mapping_update_result,
15094                  pctype_list, NULL);
15095 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15096         TOKEN_NUM_INITIALIZER
15097                 (struct cmd_pctype_mapping_update_result,
15098                  flow_type, UINT16);
15099
15100 static void
15101 cmd_pctype_mapping_update_parsed(
15102         void *parsed_result,
15103         __attribute__((unused)) struct cmdline *cl,
15104         __attribute__((unused)) void *data)
15105 {
15106         struct cmd_pctype_mapping_update_result *res = parsed_result;
15107         int ret = -ENOTSUP;
15108 #ifdef RTE_LIBRTE_I40E_PMD
15109         struct rte_pmd_i40e_flow_type_mapping mapping;
15110         unsigned int i;
15111         unsigned int nb_item;
15112         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15113 #endif
15114
15115         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15116                 return;
15117
15118 #ifdef RTE_LIBRTE_I40E_PMD
15119         nb_item = parse_item_list(res->pctype_list, "pctypes",
15120                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15121         mapping.flow_type = res->flow_type;
15122         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15123                 mapping.pctype |= (1ULL << pctype_list[i]);
15124         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15125                                                 &mapping,
15126                                                 1,
15127                                                 0);
15128 #endif
15129
15130         switch (ret) {
15131         case 0:
15132                 break;
15133         case -EINVAL:
15134                 printf("invalid pctype or flow type\n");
15135                 break;
15136         case -ENODEV:
15137                 printf("invalid port_id %d\n", res->port_id);
15138                 break;
15139         case -ENOTSUP:
15140                 printf("function not implemented\n");
15141                 break;
15142         default:
15143                 printf("programming error: (%s)\n", strerror(-ret));
15144         }
15145 }
15146
15147 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15148         .f = cmd_pctype_mapping_update_parsed,
15149         .data = NULL,
15150         .help_str = "port config <port_id> pctype mapping update"
15151         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15152         .tokens = {
15153                 (void *)&cmd_pctype_mapping_update_port,
15154                 (void *)&cmd_pctype_mapping_update_config,
15155                 (void *)&cmd_pctype_mapping_update_port_id,
15156                 (void *)&cmd_pctype_mapping_update_pctype,
15157                 (void *)&cmd_pctype_mapping_update_mapping,
15158                 (void *)&cmd_pctype_mapping_update_update,
15159                 (void *)&cmd_pctype_mapping_update_pc_type,
15160                 (void *)&cmd_pctype_mapping_update_flow_type,
15161                 NULL,
15162         },
15163 };
15164
15165 /* ptype mapping get */
15166
15167 /* Common result structure for ptype mapping get */
15168 struct cmd_ptype_mapping_get_result {
15169         cmdline_fixed_string_t ptype;
15170         cmdline_fixed_string_t mapping;
15171         cmdline_fixed_string_t get;
15172         portid_t port_id;
15173         uint8_t valid_only;
15174 };
15175
15176 /* Common CLI fields for ptype mapping get */
15177 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15178         TOKEN_STRING_INITIALIZER
15179                 (struct cmd_ptype_mapping_get_result,
15180                  ptype, "ptype");
15181 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15182         TOKEN_STRING_INITIALIZER
15183                 (struct cmd_ptype_mapping_get_result,
15184                  mapping, "mapping");
15185 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15186         TOKEN_STRING_INITIALIZER
15187                 (struct cmd_ptype_mapping_get_result,
15188                  get, "get");
15189 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15190         TOKEN_NUM_INITIALIZER
15191                 (struct cmd_ptype_mapping_get_result,
15192                  port_id, UINT16);
15193 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15194         TOKEN_NUM_INITIALIZER
15195                 (struct cmd_ptype_mapping_get_result,
15196                  valid_only, UINT8);
15197
15198 static void
15199 cmd_ptype_mapping_get_parsed(
15200         void *parsed_result,
15201         __attribute__((unused)) struct cmdline *cl,
15202         __attribute__((unused)) void *data)
15203 {
15204         struct cmd_ptype_mapping_get_result *res = parsed_result;
15205         int ret = -ENOTSUP;
15206 #ifdef RTE_LIBRTE_I40E_PMD
15207         int max_ptype_num = 256;
15208         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15209         uint16_t count;
15210         int i;
15211 #endif
15212
15213         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15214                 return;
15215
15216 #ifdef RTE_LIBRTE_I40E_PMD
15217         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15218                                         mapping,
15219                                         max_ptype_num,
15220                                         &count,
15221                                         res->valid_only);
15222 #endif
15223
15224         switch (ret) {
15225         case 0:
15226                 break;
15227         case -ENODEV:
15228                 printf("invalid port_id %d\n", res->port_id);
15229                 break;
15230         case -ENOTSUP:
15231                 printf("function not implemented\n");
15232                 break;
15233         default:
15234                 printf("programming error: (%s)\n", strerror(-ret));
15235         }
15236
15237 #ifdef RTE_LIBRTE_I40E_PMD
15238         if (!ret) {
15239                 for (i = 0; i < count; i++)
15240                         printf("%3d\t0x%08x\n",
15241                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15242         }
15243 #endif
15244 }
15245
15246 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15247         .f = cmd_ptype_mapping_get_parsed,
15248         .data = NULL,
15249         .help_str = "ptype mapping get <port_id> <valid_only>",
15250         .tokens = {
15251                 (void *)&cmd_ptype_mapping_get_ptype,
15252                 (void *)&cmd_ptype_mapping_get_mapping,
15253                 (void *)&cmd_ptype_mapping_get_get,
15254                 (void *)&cmd_ptype_mapping_get_port_id,
15255                 (void *)&cmd_ptype_mapping_get_valid_only,
15256                 NULL,
15257         },
15258 };
15259
15260 /* ptype mapping replace */
15261
15262 /* Common result structure for ptype mapping replace */
15263 struct cmd_ptype_mapping_replace_result {
15264         cmdline_fixed_string_t ptype;
15265         cmdline_fixed_string_t mapping;
15266         cmdline_fixed_string_t replace;
15267         portid_t port_id;
15268         uint32_t target;
15269         uint8_t mask;
15270         uint32_t pkt_type;
15271 };
15272
15273 /* Common CLI fields for ptype mapping replace */
15274 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15275         TOKEN_STRING_INITIALIZER
15276                 (struct cmd_ptype_mapping_replace_result,
15277                  ptype, "ptype");
15278 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15279         TOKEN_STRING_INITIALIZER
15280                 (struct cmd_ptype_mapping_replace_result,
15281                  mapping, "mapping");
15282 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15283         TOKEN_STRING_INITIALIZER
15284                 (struct cmd_ptype_mapping_replace_result,
15285                  replace, "replace");
15286 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15287         TOKEN_NUM_INITIALIZER
15288                 (struct cmd_ptype_mapping_replace_result,
15289                  port_id, UINT16);
15290 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15291         TOKEN_NUM_INITIALIZER
15292                 (struct cmd_ptype_mapping_replace_result,
15293                  target, UINT32);
15294 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15295         TOKEN_NUM_INITIALIZER
15296                 (struct cmd_ptype_mapping_replace_result,
15297                  mask, UINT8);
15298 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15299         TOKEN_NUM_INITIALIZER
15300                 (struct cmd_ptype_mapping_replace_result,
15301                  pkt_type, UINT32);
15302
15303 static void
15304 cmd_ptype_mapping_replace_parsed(
15305         void *parsed_result,
15306         __attribute__((unused)) struct cmdline *cl,
15307         __attribute__((unused)) void *data)
15308 {
15309         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15310         int ret = -ENOTSUP;
15311
15312         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15313                 return;
15314
15315 #ifdef RTE_LIBRTE_I40E_PMD
15316         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15317                                         res->target,
15318                                         res->mask,
15319                                         res->pkt_type);
15320 #endif
15321
15322         switch (ret) {
15323         case 0:
15324                 break;
15325         case -EINVAL:
15326                 printf("invalid ptype 0x%8x or 0x%8x\n",
15327                                 res->target, res->pkt_type);
15328                 break;
15329         case -ENODEV:
15330                 printf("invalid port_id %d\n", res->port_id);
15331                 break;
15332         case -ENOTSUP:
15333                 printf("function not implemented\n");
15334                 break;
15335         default:
15336                 printf("programming error: (%s)\n", strerror(-ret));
15337         }
15338 }
15339
15340 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15341         .f = cmd_ptype_mapping_replace_parsed,
15342         .data = NULL,
15343         .help_str =
15344                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15345         .tokens = {
15346                 (void *)&cmd_ptype_mapping_replace_ptype,
15347                 (void *)&cmd_ptype_mapping_replace_mapping,
15348                 (void *)&cmd_ptype_mapping_replace_replace,
15349                 (void *)&cmd_ptype_mapping_replace_port_id,
15350                 (void *)&cmd_ptype_mapping_replace_target,
15351                 (void *)&cmd_ptype_mapping_replace_mask,
15352                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15353                 NULL,
15354         },
15355 };
15356
15357 /* ptype mapping reset */
15358
15359 /* Common result structure for ptype mapping reset */
15360 struct cmd_ptype_mapping_reset_result {
15361         cmdline_fixed_string_t ptype;
15362         cmdline_fixed_string_t mapping;
15363         cmdline_fixed_string_t reset;
15364         portid_t port_id;
15365 };
15366
15367 /* Common CLI fields for ptype mapping reset*/
15368 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15369         TOKEN_STRING_INITIALIZER
15370                 (struct cmd_ptype_mapping_reset_result,
15371                  ptype, "ptype");
15372 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15373         TOKEN_STRING_INITIALIZER
15374                 (struct cmd_ptype_mapping_reset_result,
15375                  mapping, "mapping");
15376 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15377         TOKEN_STRING_INITIALIZER
15378                 (struct cmd_ptype_mapping_reset_result,
15379                  reset, "reset");
15380 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15381         TOKEN_NUM_INITIALIZER
15382                 (struct cmd_ptype_mapping_reset_result,
15383                  port_id, UINT16);
15384
15385 static void
15386 cmd_ptype_mapping_reset_parsed(
15387         void *parsed_result,
15388         __attribute__((unused)) struct cmdline *cl,
15389         __attribute__((unused)) void *data)
15390 {
15391         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15392         int ret = -ENOTSUP;
15393
15394         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15395                 return;
15396
15397 #ifdef RTE_LIBRTE_I40E_PMD
15398         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15399 #endif
15400
15401         switch (ret) {
15402         case 0:
15403                 break;
15404         case -ENODEV:
15405                 printf("invalid port_id %d\n", res->port_id);
15406                 break;
15407         case -ENOTSUP:
15408                 printf("function not implemented\n");
15409                 break;
15410         default:
15411                 printf("programming error: (%s)\n", strerror(-ret));
15412         }
15413 }
15414
15415 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15416         .f = cmd_ptype_mapping_reset_parsed,
15417         .data = NULL,
15418         .help_str = "ptype mapping reset <port_id>",
15419         .tokens = {
15420                 (void *)&cmd_ptype_mapping_reset_ptype,
15421                 (void *)&cmd_ptype_mapping_reset_mapping,
15422                 (void *)&cmd_ptype_mapping_reset_reset,
15423                 (void *)&cmd_ptype_mapping_reset_port_id,
15424                 NULL,
15425         },
15426 };
15427
15428 /* ptype mapping update */
15429
15430 /* Common result structure for ptype mapping update */
15431 struct cmd_ptype_mapping_update_result {
15432         cmdline_fixed_string_t ptype;
15433         cmdline_fixed_string_t mapping;
15434         cmdline_fixed_string_t reset;
15435         portid_t port_id;
15436         uint8_t hw_ptype;
15437         uint32_t sw_ptype;
15438 };
15439
15440 /* Common CLI fields for ptype mapping update*/
15441 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15442         TOKEN_STRING_INITIALIZER
15443                 (struct cmd_ptype_mapping_update_result,
15444                  ptype, "ptype");
15445 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15446         TOKEN_STRING_INITIALIZER
15447                 (struct cmd_ptype_mapping_update_result,
15448                  mapping, "mapping");
15449 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15450         TOKEN_STRING_INITIALIZER
15451                 (struct cmd_ptype_mapping_update_result,
15452                  reset, "update");
15453 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15454         TOKEN_NUM_INITIALIZER
15455                 (struct cmd_ptype_mapping_update_result,
15456                  port_id, UINT16);
15457 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15458         TOKEN_NUM_INITIALIZER
15459                 (struct cmd_ptype_mapping_update_result,
15460                  hw_ptype, UINT8);
15461 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15462         TOKEN_NUM_INITIALIZER
15463                 (struct cmd_ptype_mapping_update_result,
15464                  sw_ptype, UINT32);
15465
15466 static void
15467 cmd_ptype_mapping_update_parsed(
15468         void *parsed_result,
15469         __attribute__((unused)) struct cmdline *cl,
15470         __attribute__((unused)) void *data)
15471 {
15472         struct cmd_ptype_mapping_update_result *res = parsed_result;
15473         int ret = -ENOTSUP;
15474 #ifdef RTE_LIBRTE_I40E_PMD
15475         struct rte_pmd_i40e_ptype_mapping mapping;
15476 #endif
15477         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15478                 return;
15479
15480 #ifdef RTE_LIBRTE_I40E_PMD
15481         mapping.hw_ptype = res->hw_ptype;
15482         mapping.sw_ptype = res->sw_ptype;
15483         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15484                                                 &mapping,
15485                                                 1,
15486                                                 0);
15487 #endif
15488
15489         switch (ret) {
15490         case 0:
15491                 break;
15492         case -EINVAL:
15493                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15494                 break;
15495         case -ENODEV:
15496                 printf("invalid port_id %d\n", res->port_id);
15497                 break;
15498         case -ENOTSUP:
15499                 printf("function not implemented\n");
15500                 break;
15501         default:
15502                 printf("programming error: (%s)\n", strerror(-ret));
15503         }
15504 }
15505
15506 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15507         .f = cmd_ptype_mapping_update_parsed,
15508         .data = NULL,
15509         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15510         .tokens = {
15511                 (void *)&cmd_ptype_mapping_update_ptype,
15512                 (void *)&cmd_ptype_mapping_update_mapping,
15513                 (void *)&cmd_ptype_mapping_update_update,
15514                 (void *)&cmd_ptype_mapping_update_port_id,
15515                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15516                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15517                 NULL,
15518         },
15519 };
15520
15521 /* Common result structure for file commands */
15522 struct cmd_cmdfile_result {
15523         cmdline_fixed_string_t load;
15524         cmdline_fixed_string_t filename;
15525 };
15526
15527 /* Common CLI fields for file commands */
15528 cmdline_parse_token_string_t cmd_load_cmdfile =
15529         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15530 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15531         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15532
15533 static void
15534 cmd_load_from_file_parsed(
15535         void *parsed_result,
15536         __attribute__((unused)) struct cmdline *cl,
15537         __attribute__((unused)) void *data)
15538 {
15539         struct cmd_cmdfile_result *res = parsed_result;
15540
15541         cmdline_read_from_file(res->filename);
15542 }
15543
15544 cmdline_parse_inst_t cmd_load_from_file = {
15545         .f = cmd_load_from_file_parsed,
15546         .data = NULL,
15547         .help_str = "load <filename>",
15548         .tokens = {
15549                 (void *)&cmd_load_cmdfile,
15550                 (void *)&cmd_load_cmdfile_filename,
15551                 NULL,
15552         },
15553 };
15554
15555 /* ******************************************************************************** */
15556
15557 /* list of instructions */
15558 cmdline_parse_ctx_t main_ctx[] = {
15559         (cmdline_parse_inst_t *)&cmd_help_brief,
15560         (cmdline_parse_inst_t *)&cmd_help_long,
15561         (cmdline_parse_inst_t *)&cmd_quit,
15562         (cmdline_parse_inst_t *)&cmd_load_from_file,
15563         (cmdline_parse_inst_t *)&cmd_showport,
15564         (cmdline_parse_inst_t *)&cmd_showqueue,
15565         (cmdline_parse_inst_t *)&cmd_showportall,
15566         (cmdline_parse_inst_t *)&cmd_showcfg,
15567         (cmdline_parse_inst_t *)&cmd_start,
15568         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15569         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15570         (cmdline_parse_inst_t *)&cmd_set_link_up,
15571         (cmdline_parse_inst_t *)&cmd_set_link_down,
15572         (cmdline_parse_inst_t *)&cmd_reset,
15573         (cmdline_parse_inst_t *)&cmd_set_numbers,
15574         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15575         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15576         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15577         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15578         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15579         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15580         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15581         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15582         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15583         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15584         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15585         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15586         (cmdline_parse_inst_t *)&cmd_set_link_check,
15587         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15588         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15589         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15590         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15591 #ifdef RTE_LIBRTE_PMD_BOND
15592         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15593         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15594         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15595         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15596         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15597         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15598         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15599         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15600         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15601         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15602         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15603 #endif
15604         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15605         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15606         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15607         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15608         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15609         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15610         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15611         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15612         (cmdline_parse_inst_t *)&cmd_csum_set,
15613         (cmdline_parse_inst_t *)&cmd_csum_show,
15614         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15615         (cmdline_parse_inst_t *)&cmd_tso_set,
15616         (cmdline_parse_inst_t *)&cmd_tso_show,
15617         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15618         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15619         (cmdline_parse_inst_t *)&cmd_gro_enable,
15620         (cmdline_parse_inst_t *)&cmd_gro_flush,
15621         (cmdline_parse_inst_t *)&cmd_gro_show,
15622         (cmdline_parse_inst_t *)&cmd_gso_enable,
15623         (cmdline_parse_inst_t *)&cmd_gso_size,
15624         (cmdline_parse_inst_t *)&cmd_gso_show,
15625         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15626         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15627         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15628         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15629         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15630         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15631         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15632         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15633         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15634         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15635         (cmdline_parse_inst_t *)&cmd_config_dcb,
15636         (cmdline_parse_inst_t *)&cmd_read_reg,
15637         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15638         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15639         (cmdline_parse_inst_t *)&cmd_write_reg,
15640         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15641         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15642         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15643         (cmdline_parse_inst_t *)&cmd_stop,
15644         (cmdline_parse_inst_t *)&cmd_mac_addr,
15645         (cmdline_parse_inst_t *)&cmd_set_qmap,
15646         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15647         (cmdline_parse_inst_t *)&cmd_operate_port,
15648         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15649         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15650         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15651         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15652         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15653         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15654         (cmdline_parse_inst_t *)&cmd_config_mtu,
15655         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15656         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15657         (cmdline_parse_inst_t *)&cmd_config_rss,
15658         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15659         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15660         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15661         (cmdline_parse_inst_t *)&cmd_showport_reta,
15662         (cmdline_parse_inst_t *)&cmd_config_burst,
15663         (cmdline_parse_inst_t *)&cmd_config_thresh,
15664         (cmdline_parse_inst_t *)&cmd_config_threshold,
15665         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15666         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15667         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15668         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15669         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15670         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15671         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15672         (cmdline_parse_inst_t *)&cmd_global_config,
15673         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15674         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15675         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15676         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15677         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15678         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15679         (cmdline_parse_inst_t *)&cmd_dump,
15680         (cmdline_parse_inst_t *)&cmd_dump_one,
15681         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15682         (cmdline_parse_inst_t *)&cmd_syn_filter,
15683         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15684         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15685         (cmdline_parse_inst_t *)&cmd_flex_filter,
15686         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15687         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15688         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15689         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15690         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15691         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15692         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15693         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15694         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15695         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15696         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15697         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15698         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15699         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15700         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15701         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15702         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15703         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15704         (cmdline_parse_inst_t *)&cmd_flow,
15705         (cmdline_parse_inst_t *)&cmd_show_port_meter_cap,
15706         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15707         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15708         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15709         (cmdline_parse_inst_t *)&cmd_create_port_meter,
15710         (cmdline_parse_inst_t *)&cmd_enable_port_meter,
15711         (cmdline_parse_inst_t *)&cmd_disable_port_meter,
15712         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15713         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15714         (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table,
15715         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15716         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15717         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15718         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15719         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15720         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15721         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15722         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15723         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15724         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15725         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15726         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15727         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15728         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15729         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15730         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15731         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15732         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15733         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15734         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15735         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15736         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15737         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15738         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15739         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15740         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15741         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15742         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15743         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15744         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15745         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15746         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15747         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15748         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15749         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15750         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15751         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15752         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15753         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15754 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15755         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15756 #endif
15757         (cmdline_parse_inst_t *)&cmd_ddp_add,
15758         (cmdline_parse_inst_t *)&cmd_ddp_del,
15759         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15760         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15761         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15762         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15763         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15764         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15765         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15766         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15767
15768         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15769         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15770         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15771         (cmdline_parse_inst_t *)&cmd_queue_region,
15772         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15773         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15774         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15775         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15776         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15777         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15778         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15779         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15780         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15781         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15782         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15783         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15784         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15785         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15786         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15787         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15788         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15789         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15790         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15791         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15792         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15793         NULL,
15794 };
15795
15796 /* read cmdline commands from file */
15797 void
15798 cmdline_read_from_file(const char *filename)
15799 {
15800         struct cmdline *cl;
15801
15802         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15803         if (cl == NULL) {
15804                 printf("Failed to create file based cmdline context: %s\n",
15805                        filename);
15806                 return;
15807         }
15808
15809         cmdline_interact(cl);
15810         cmdline_quit(cl);
15811
15812         cmdline_free(cl);
15813
15814         printf("Read CLI commands from %s\n", filename);
15815 }
15816
15817 /* prompt function, called from main on MASTER lcore */
15818 void
15819 prompt(void)
15820 {
15821         /* initialize non-constant commands */
15822         cmd_set_fwd_mode_init();
15823         cmd_set_fwd_retry_mode_init();
15824
15825         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15826         if (testpmd_cl == NULL)
15827                 return;
15828         cmdline_interact(testpmd_cl);
15829         cmdline_stdin_exit(testpmd_cl);
15830 }
15831
15832 void
15833 prompt_exit(void)
15834 {
15835         if (testpmd_cl != NULL)
15836                 cmdline_quit(testpmd_cl);
15837 }
15838
15839 static void
15840 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15841 {
15842         if (id == (portid_t)RTE_PORT_ALL) {
15843                 portid_t pid;
15844
15845                 RTE_ETH_FOREACH_DEV(pid) {
15846                         /* check if need_reconfig has been set to 1 */
15847                         if (ports[pid].need_reconfig == 0)
15848                                 ports[pid].need_reconfig = dev;
15849                         /* check if need_reconfig_queues has been set to 1 */
15850                         if (ports[pid].need_reconfig_queues == 0)
15851                                 ports[pid].need_reconfig_queues = queue;
15852                 }
15853         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15854                 /* check if need_reconfig has been set to 1 */
15855                 if (ports[id].need_reconfig == 0)
15856                         ports[id].need_reconfig = dev;
15857                 /* check if need_reconfig_queues has been set to 1 */
15858                 if (ports[id].need_reconfig_queues == 0)
15859                         ports[id].need_reconfig_queues = queue;
15860         }
15861 }