New upstream version 17.11.1
[deb_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                         "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (color_aware)\n"
702                         "    meter profile add - srtcm rfc 2697\n\n"
703
704                         "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n"
705                         "    meter profile add - trtcm rfc 2698\n\n"
706
707                         "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n"
708                         "    meter profile add - trtcm rfc 4115\n\n"
709
710                         "del port meter profile (port_id) (profile_id)\n"
711                         "    meter profile delete\n\n"
712
713                         "set port meter (port_id) (mtr_id) (profile_id) (g_action) (y_action) (r_action) (stats_mask) (shared)\n"
714                         "    meter create\n\n"
715
716                         "del port meter (port_id) (mtr_id)\n"
717                         "    meter delete\n\n"
718
719                         "set port meter profile (port_id) (mtr_id) (profile_id)\n"
720                         "    meter update meter profile\n\n"
721
722                         "set port meter policer action (port_id) (mtr_id) (color) (action)\n"
723                         "    meter update policer action\n\n"
724
725                         "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n"
726                         "    meter update stats\n\n"
727
728                         "show port (port_id) queue-region\n"
729                         "    show all queue region related configuration info\n\n"
730
731                         "add port tm node shaper profile (port_id) (shaper_profile_id)"
732                         " (tb_rate) (tb_size) (packet_length_adjust)\n"
733                         "       Add port tm node private shaper profile.\n\n"
734
735                         "del port tm node shaper profile (port_id) (shaper_profile_id)\n"
736                         "       Delete port tm node private shaper profile.\n\n"
737
738                         "add port tm node shared shaper (port_id) (shared_shaper_id)"
739                         " (shaper_profile_id)\n"
740                         "       Add/update port tm node shared shaper.\n\n"
741
742                         "del port tm node shared shaper (port_id) (shared_shaper_id)\n"
743                         "       Delete port tm node shared shaper.\n\n"
744
745                         "set port tm node shaper profile (port_id) (node_id)"
746                         " (shaper_profile_id)\n"
747                         "       Set port tm node shaper profile.\n\n"
748
749                         "add port tm node wred profile (port_id) (wred_profile_id)"
750                         " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)"
751                         " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)"
752                         " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n"
753                         "       Add port tm node wred profile.\n\n"
754
755                         "del port tm node wred profile (port_id) (wred_profile_id)\n"
756                         "       Delete port tm node wred profile.\n\n"
757
758                         "add port tm nonleaf node (port_id) (node_id) (parent_node_id)"
759                         " (priority) (weight) (level_id) (shaper_profile_id)"
760                         " (n_sp_priorities) (stats_mask) (n_shared_shapers)"
761                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
762                         "       Add port tm nonleaf node.\n\n"
763
764                         "add port tm leaf node (port_id) (node_id) (parent_node_id)"
765                         " (priority) (weight) (level_id) (shaper_profile_id)"
766                         " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)"
767                         " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n"
768                         "       Add port tm leaf node.\n\n"
769
770                         "del port tm node (port_id) (node_id)\n"
771                         "       Delete port tm node.\n\n"
772
773                         "set port tm node parent (port_id) (node_id) (parent_node_id)"
774                         " (priority) (weight)\n"
775                         "       Set port tm node parent.\n\n"
776
777                         "port tm hierarchy commit (port_id) (clean_on_fail)\n"
778                         "       Commit tm hierarchy.\n\n"
779
780                         , list_pkt_forwarding_modes()
781                 );
782         }
783
784         if (show_all || !strcmp(res->section, "ports")) {
785
786                 cmdline_printf(
787                         cl,
788                         "\n"
789                         "Port Operations:\n"
790                         "----------------\n\n"
791
792                         "port start (port_id|all)\n"
793                         "    Start all ports or port_id.\n\n"
794
795                         "port stop (port_id|all)\n"
796                         "    Stop all ports or port_id.\n\n"
797
798                         "port close (port_id|all)\n"
799                         "    Close all ports or port_id.\n\n"
800
801                         "port attach (ident)\n"
802                         "    Attach physical or virtual dev by pci address or virtual device name\n\n"
803
804                         "port detach (port_id)\n"
805                         "    Detach physical or virtual dev by port_id\n\n"
806
807                         "port config (port_id|all)"
808                         " speed (10|100|1000|10000|25000|40000|50000|100000|auto)"
809                         " duplex (half|full|auto)\n"
810                         "    Set speed and duplex for all ports or port_id\n\n"
811
812                         "port config all (rxq|txq|rxd|txd) (value)\n"
813                         "    Set number for rxq/txq/rxd/txd.\n\n"
814
815                         "port config all max-pkt-len (value)\n"
816                         "    Set the max packet length.\n\n"
817
818                         "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|"
819                         "hw-vlan-strip|hw-vlan-extend|drop-en)"
820                         " (on|off)\n"
821                         "    Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en"
822                         " for ports.\n\n"
823
824                         "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|"
825                         "geneve|nvgre|none|<flowtype_id>)\n"
826                         "    Set the RSS mode.\n\n"
827
828                         "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
829                         "    Set the RSS redirection table.\n\n"
830
831                         "port config (port_id) dcb vt (on|off) (traffic_class)"
832                         " pfc (on|off)\n"
833                         "    Set the DCB mode.\n\n"
834
835                         "port config all burst (value)\n"
836                         "    Set the number of packets per burst.\n\n"
837
838                         "port config all (txpt|txht|txwt|rxpt|rxht|rxwt)"
839                         " (value)\n"
840                         "    Set the ring prefetch/host/writeback threshold"
841                         " for tx/rx queue.\n\n"
842
843                         "port config all (txfreet|txrst|rxfreet) (value)\n"
844                         "    Set free threshold for rx/tx, or set"
845                         " tx rs bit threshold.\n\n"
846                         "port config mtu X value\n"
847                         "    Set the MTU of port X to a given value\n\n"
848
849                         "port (port_id) (rxq|txq) (queue_id) (start|stop)\n"
850                         "    Start/stop a rx/tx queue of port X. Only take effect"
851                         " when port X is started\n\n"
852
853                         "port config (port_id|all) l2-tunnel E-tag ether-type"
854                         " (value)\n"
855                         "    Set the value of E-tag ether-type.\n\n"
856
857                         "port config (port_id|all) l2-tunnel E-tag"
858                         " (enable|disable)\n"
859                         "    Enable/disable the E-tag support.\n\n"
860
861                         "port config (port_id) pctype mapping reset\n"
862                         "    Reset flow type to pctype mapping on a port\n\n"
863
864                         "port config (port_id) pctype mapping update"
865                         " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n"
866                         "    Update a flow type to pctype mapping item on a port\n\n"
867                 );
868         }
869
870         if (show_all || !strcmp(res->section, "registers")) {
871
872                 cmdline_printf(
873                         cl,
874                         "\n"
875                         "Registers:\n"
876                         "----------\n\n"
877
878                         "read reg (port_id) (address)\n"
879                         "    Display value of a port register.\n\n"
880
881                         "read regfield (port_id) (address) (bit_x) (bit_y)\n"
882                         "    Display a port register bit field.\n\n"
883
884                         "read regbit (port_id) (address) (bit_x)\n"
885                         "    Display a single port register bit.\n\n"
886
887                         "write reg (port_id) (address) (value)\n"
888                         "    Set value of a port register.\n\n"
889
890                         "write regfield (port_id) (address) (bit_x) (bit_y)"
891                         " (value)\n"
892                         "    Set bit field of a port register.\n\n"
893
894                         "write regbit (port_id) (address) (bit_x) (value)\n"
895                         "    Set single bit value of a port register.\n\n"
896                 );
897         }
898         if (show_all || !strcmp(res->section, "filters")) {
899
900                 cmdline_printf(
901                         cl,
902                         "\n"
903                         "filters:\n"
904                         "--------\n\n"
905
906                         "ethertype_filter (port_id) (add|del)"
907                         " (mac_addr|mac_ignr) (mac_address) ethertype"
908                         " (ether_type) (drop|fwd) queue (queue_id)\n"
909                         "    Add/Del an ethertype filter.\n\n"
910
911                         "2tuple_filter (port_id) (add|del)"
912                         " dst_port (dst_port_value) protocol (protocol_value)"
913                         " mask (mask_value) tcp_flags (tcp_flags_value)"
914                         " priority (prio_value) queue (queue_id)\n"
915                         "    Add/Del a 2tuple filter.\n\n"
916
917                         "5tuple_filter (port_id) (add|del)"
918                         " dst_ip (dst_address) src_ip (src_address)"
919                         " dst_port (dst_port_value) src_port (src_port_value)"
920                         " protocol (protocol_value)"
921                         " mask (mask_value) tcp_flags (tcp_flags_value)"
922                         " priority (prio_value) queue (queue_id)\n"
923                         "    Add/Del a 5tuple filter.\n\n"
924
925                         "syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
926                         "    Add/Del syn filter.\n\n"
927
928                         "flex_filter (port_id) (add|del) len (len_value)"
929                         " bytes (bytes_value) mask (mask_value)"
930                         " priority (prio_value) queue (queue_id)\n"
931                         "    Add/Del a flex filter.\n\n"
932
933                         "flow_director_filter (port_id) mode IP (add|del|update)"
934                         " flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
935                         " src (src_ip_address) dst (dst_ip_address)"
936                         " tos (tos_value) proto (proto_value) ttl (ttl_value)"
937                         " vlan (vlan_value) flexbytes (flexbytes_value)"
938                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
939                         " fd_id (fd_id_value)\n"
940                         "    Add/Del an IP type flow director filter.\n\n"
941
942                         "flow_director_filter (port_id) mode IP (add|del|update)"
943                         " flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp)"
944                         " src (src_ip_address) (src_port)"
945                         " dst (dst_ip_address) (dst_port)"
946                         " tos (tos_value) ttl (ttl_value)"
947                         " vlan (vlan_value) flexbytes (flexbytes_value)"
948                         " (drop|fwd) pf|vf(vf_id) queue (queue_id)"
949                         " fd_id (fd_id_value)\n"
950                         "    Add/Del an UDP/TCP type flow director filter.\n\n"
951
952                         "flow_director_filter (port_id) mode IP (add|del|update)"
953                         " flow (ipv4-sctp|ipv6-sctp)"
954                         " src (src_ip_address) (src_port)"
955                         " dst (dst_ip_address) (dst_port)"
956                         " tag (verification_tag) "
957                         " tos (tos_value) ttl (ttl_value)"
958                         " vlan (vlan_value)"
959                         " flexbytes (flexbytes_value) (drop|fwd)"
960                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
961                         "    Add/Del a SCTP type flow director filter.\n\n"
962
963                         "flow_director_filter (port_id) mode IP (add|del|update)"
964                         " flow l2_payload ether (ethertype)"
965                         " flexbytes (flexbytes_value) (drop|fwd)"
966                         " pf|vf(vf_id) queue (queue_id) fd_id (fd_id_value)\n"
967                         "    Add/Del a l2 payload type flow director filter.\n\n"
968
969                         "flow_director_filter (port_id) mode MAC-VLAN (add|del|update)"
970                         " mac (mac_address) vlan (vlan_value)"
971                         " flexbytes (flexbytes_value) (drop|fwd)"
972                         " queue (queue_id) fd_id (fd_id_value)\n"
973                         "    Add/Del a MAC-VLAN flow director filter.\n\n"
974
975                         "flow_director_filter (port_id) mode Tunnel (add|del|update)"
976                         " mac (mac_address) vlan (vlan_value)"
977                         " tunnel (NVGRE|VxLAN) tunnel-id (tunnel_id_value)"
978                         " flexbytes (flexbytes_value) (drop|fwd)"
979                         " queue (queue_id) fd_id (fd_id_value)\n"
980                         "    Add/Del a Tunnel flow director filter.\n\n"
981
982                         "flush_flow_director (port_id)\n"
983                         "    Flush all flow director entries of a device.\n\n"
984
985                         "flow_director_mask (port_id) mode IP vlan (vlan_value)"
986                         " src_mask (ipv4_src) (ipv6_src) (src_port)"
987                         " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n"
988                         "    Set flow director IP mask.\n\n"
989
990                         "flow_director_mask (port_id) mode MAC-VLAN"
991                         " vlan (vlan_value)\n"
992                         "    Set flow director MAC-VLAN mask.\n\n"
993
994                         "flow_director_mask (port_id) mode Tunnel"
995                         " vlan (vlan_value) mac (mac_value)"
996                         " tunnel-type (tunnel_type_value)"
997                         " tunnel-id (tunnel_id_value)\n"
998                         "    Set flow director Tunnel mask.\n\n"
999
1000                         "flow_director_flex_mask (port_id)"
1001                         " flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
1002                         "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|l2_payload|all)"
1003                         " (mask)\n"
1004                         "    Configure mask of flex payload.\n\n"
1005
1006                         "flow_director_flex_payload (port_id)"
1007                         " (raw|l2|l3|l4) (config)\n"
1008                         "    Configure flex payload selection.\n\n"
1009
1010                         "get_sym_hash_ena_per_port (port_id)\n"
1011                         "    get symmetric hash enable configuration per port.\n\n"
1012
1013                         "set_sym_hash_ena_per_port (port_id) (enable|disable)\n"
1014                         "    set symmetric hash enable configuration per port"
1015                         " to enable or disable.\n\n"
1016
1017                         "get_hash_global_config (port_id)\n"
1018                         "    Get the global configurations of hash filters.\n\n"
1019
1020                         "set_hash_global_config (port_id) (toeplitz|simple_xor|default)"
1021                         " (ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1022                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload)"
1023                         " (enable|disable)\n"
1024                         "    Set the global configurations of hash filters.\n\n"
1025
1026                         "set_hash_input_set (port_id) (ipv4|ipv4-frag|"
1027                         "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|"
1028                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1029                         "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|"
1030                         "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|"
1031                         "ipv6-next-header|udp-src-port|udp-dst-port|"
1032                         "tcp-src-port|tcp-dst-port|sctp-src-port|"
1033                         "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|"
1034                         "fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|fld-7th|"
1035                         "fld-8th|none) (select|add)\n"
1036                         "    Set the input set for hash.\n\n"
1037
1038                         "set_fdir_input_set (port_id) "
1039                         "(ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
1040                         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
1041                         "l2_payload) (ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|"
1042                         "dst-ipv6|ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|"
1043                         "ipv6-next-header|ipv6-hop-limits|udp-src-port|"
1044                         "udp-dst-port|tcp-src-port|tcp-dst-port|"
1045                         "sctp-src-port|sctp-dst-port|sctp-veri-tag|none)"
1046                         " (select|add)\n"
1047                         "    Set the input set for FDir.\n\n"
1048
1049                         "flow validate {port_id}"
1050                         " [group {group_id}] [priority {level}]"
1051                         " [ingress] [egress]"
1052                         " pattern {item} [/ {item} [...]] / end"
1053                         " actions {action} [/ {action} [...]] / end\n"
1054                         "    Check whether a flow rule can be created.\n\n"
1055
1056                         "flow create {port_id}"
1057                         " [group {group_id}] [priority {level}]"
1058                         " [ingress] [egress]"
1059                         " pattern {item} [/ {item} [...]] / end"
1060                         " actions {action} [/ {action} [...]] / end\n"
1061                         "    Create a flow rule.\n\n"
1062
1063                         "flow destroy {port_id} rule {rule_id} [...]\n"
1064                         "    Destroy specific flow rules.\n\n"
1065
1066                         "flow flush {port_id}\n"
1067                         "    Destroy all flow rules.\n\n"
1068
1069                         "flow query {port_id} {rule_id} {action}\n"
1070                         "    Query an existing flow rule.\n\n"
1071
1072                         "flow list {port_id} [group {group_id}] [...]\n"
1073                         "    List existing flow rules sorted by priority,"
1074                         " filtered by group identifiers.\n\n"
1075
1076                         "flow isolate {port_id} {boolean}\n"
1077                         "    Restrict ingress traffic to the defined"
1078                         " flow rules\n\n"
1079                 );
1080         }
1081 }
1082
1083 cmdline_parse_token_string_t cmd_help_long_help =
1084         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, help, "help");
1085
1086 cmdline_parse_token_string_t cmd_help_long_section =
1087         TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section,
1088                         "all#control#display#config#"
1089                         "ports#registers#filters");
1090
1091 cmdline_parse_inst_t cmd_help_long = {
1092         .f = cmd_help_long_parsed,
1093         .data = NULL,
1094         .help_str = "help all|control|display|config|ports|register|filters: "
1095                 "Show help",
1096         .tokens = {
1097                 (void *)&cmd_help_long_help,
1098                 (void *)&cmd_help_long_section,
1099                 NULL,
1100         },
1101 };
1102
1103
1104 /* *** start/stop/close all ports *** */
1105 struct cmd_operate_port_result {
1106         cmdline_fixed_string_t keyword;
1107         cmdline_fixed_string_t name;
1108         cmdline_fixed_string_t value;
1109 };
1110
1111 static void cmd_operate_port_parsed(void *parsed_result,
1112                                 __attribute__((unused)) struct cmdline *cl,
1113                                 __attribute__((unused)) void *data)
1114 {
1115         struct cmd_operate_port_result *res = parsed_result;
1116
1117         if (!strcmp(res->name, "start"))
1118                 start_port(RTE_PORT_ALL);
1119         else if (!strcmp(res->name, "stop"))
1120                 stop_port(RTE_PORT_ALL);
1121         else if (!strcmp(res->name, "close"))
1122                 close_port(RTE_PORT_ALL);
1123         else if (!strcmp(res->name, "reset"))
1124                 reset_port(RTE_PORT_ALL);
1125         else
1126                 printf("Unknown parameter\n");
1127 }
1128
1129 cmdline_parse_token_string_t cmd_operate_port_all_cmd =
1130         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, keyword,
1131                                                                 "port");
1132 cmdline_parse_token_string_t cmd_operate_port_all_port =
1133         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name,
1134                                                 "start#stop#close#reset");
1135 cmdline_parse_token_string_t cmd_operate_port_all_all =
1136         TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all");
1137
1138 cmdline_parse_inst_t cmd_operate_port = {
1139         .f = cmd_operate_port_parsed,
1140         .data = NULL,
1141         .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports",
1142         .tokens = {
1143                 (void *)&cmd_operate_port_all_cmd,
1144                 (void *)&cmd_operate_port_all_port,
1145                 (void *)&cmd_operate_port_all_all,
1146                 NULL,
1147         },
1148 };
1149
1150 /* *** start/stop/close specific port *** */
1151 struct cmd_operate_specific_port_result {
1152         cmdline_fixed_string_t keyword;
1153         cmdline_fixed_string_t name;
1154         uint8_t value;
1155 };
1156
1157 static void cmd_operate_specific_port_parsed(void *parsed_result,
1158                         __attribute__((unused)) struct cmdline *cl,
1159                                 __attribute__((unused)) void *data)
1160 {
1161         struct cmd_operate_specific_port_result *res = parsed_result;
1162
1163         if (!strcmp(res->name, "start"))
1164                 start_port(res->value);
1165         else if (!strcmp(res->name, "stop"))
1166                 stop_port(res->value);
1167         else if (!strcmp(res->name, "close"))
1168                 close_port(res->value);
1169         else if (!strcmp(res->name, "reset"))
1170                 reset_port(res->value);
1171         else
1172                 printf("Unknown parameter\n");
1173 }
1174
1175 cmdline_parse_token_string_t cmd_operate_specific_port_cmd =
1176         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1177                                                         keyword, "port");
1178 cmdline_parse_token_string_t cmd_operate_specific_port_port =
1179         TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result,
1180                                                 name, "start#stop#close#reset");
1181 cmdline_parse_token_num_t cmd_operate_specific_port_id =
1182         TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result,
1183                                                         value, UINT8);
1184
1185 cmdline_parse_inst_t cmd_operate_specific_port = {
1186         .f = cmd_operate_specific_port_parsed,
1187         .data = NULL,
1188         .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id",
1189         .tokens = {
1190                 (void *)&cmd_operate_specific_port_cmd,
1191                 (void *)&cmd_operate_specific_port_port,
1192                 (void *)&cmd_operate_specific_port_id,
1193                 NULL,
1194         },
1195 };
1196
1197 /* *** attach a specified port *** */
1198 struct cmd_operate_attach_port_result {
1199         cmdline_fixed_string_t port;
1200         cmdline_fixed_string_t keyword;
1201         cmdline_fixed_string_t identifier;
1202 };
1203
1204 static void cmd_operate_attach_port_parsed(void *parsed_result,
1205                                 __attribute__((unused)) struct cmdline *cl,
1206                                 __attribute__((unused)) void *data)
1207 {
1208         struct cmd_operate_attach_port_result *res = parsed_result;
1209
1210         if (!strcmp(res->keyword, "attach"))
1211                 attach_port(res->identifier);
1212         else
1213                 printf("Unknown parameter\n");
1214 }
1215
1216 cmdline_parse_token_string_t cmd_operate_attach_port_port =
1217         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1218                         port, "port");
1219 cmdline_parse_token_string_t cmd_operate_attach_port_keyword =
1220         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1221                         keyword, "attach");
1222 cmdline_parse_token_string_t cmd_operate_attach_port_identifier =
1223         TOKEN_STRING_INITIALIZER(struct cmd_operate_attach_port_result,
1224                         identifier, NULL);
1225
1226 cmdline_parse_inst_t cmd_operate_attach_port = {
1227         .f = cmd_operate_attach_port_parsed,
1228         .data = NULL,
1229         .help_str = "port attach <identifier>: "
1230                 "(identifier: pci address or virtual dev name)",
1231         .tokens = {
1232                 (void *)&cmd_operate_attach_port_port,
1233                 (void *)&cmd_operate_attach_port_keyword,
1234                 (void *)&cmd_operate_attach_port_identifier,
1235                 NULL,
1236         },
1237 };
1238
1239 /* *** detach a specified port *** */
1240 struct cmd_operate_detach_port_result {
1241         cmdline_fixed_string_t port;
1242         cmdline_fixed_string_t keyword;
1243         portid_t port_id;
1244 };
1245
1246 static void cmd_operate_detach_port_parsed(void *parsed_result,
1247                                 __attribute__((unused)) struct cmdline *cl,
1248                                 __attribute__((unused)) void *data)
1249 {
1250         struct cmd_operate_detach_port_result *res = parsed_result;
1251
1252         if (!strcmp(res->keyword, "detach"))
1253                 detach_port(res->port_id);
1254         else
1255                 printf("Unknown parameter\n");
1256 }
1257
1258 cmdline_parse_token_string_t cmd_operate_detach_port_port =
1259         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1260                         port, "port");
1261 cmdline_parse_token_string_t cmd_operate_detach_port_keyword =
1262         TOKEN_STRING_INITIALIZER(struct cmd_operate_detach_port_result,
1263                         keyword, "detach");
1264 cmdline_parse_token_num_t cmd_operate_detach_port_port_id =
1265         TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result,
1266                         port_id, UINT16);
1267
1268 cmdline_parse_inst_t cmd_operate_detach_port = {
1269         .f = cmd_operate_detach_port_parsed,
1270         .data = NULL,
1271         .help_str = "port detach <port_id>",
1272         .tokens = {
1273                 (void *)&cmd_operate_detach_port_port,
1274                 (void *)&cmd_operate_detach_port_keyword,
1275                 (void *)&cmd_operate_detach_port_port_id,
1276                 NULL,
1277         },
1278 };
1279
1280 /* *** configure speed for all ports *** */
1281 struct cmd_config_speed_all {
1282         cmdline_fixed_string_t port;
1283         cmdline_fixed_string_t keyword;
1284         cmdline_fixed_string_t all;
1285         cmdline_fixed_string_t item1;
1286         cmdline_fixed_string_t item2;
1287         cmdline_fixed_string_t value1;
1288         cmdline_fixed_string_t value2;
1289 };
1290
1291 static int
1292 parse_and_check_speed_duplex(char *speedstr, char *duplexstr, uint32_t *speed)
1293 {
1294
1295         int duplex;
1296
1297         if (!strcmp(duplexstr, "half")) {
1298                 duplex = ETH_LINK_HALF_DUPLEX;
1299         } else if (!strcmp(duplexstr, "full")) {
1300                 duplex = ETH_LINK_FULL_DUPLEX;
1301         } else if (!strcmp(duplexstr, "auto")) {
1302                 duplex = ETH_LINK_FULL_DUPLEX;
1303         } else {
1304                 printf("Unknown duplex parameter\n");
1305                 return -1;
1306         }
1307
1308         if (!strcmp(speedstr, "10")) {
1309                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1310                                 ETH_LINK_SPEED_10M_HD : ETH_LINK_SPEED_10M;
1311         } else if (!strcmp(speedstr, "100")) {
1312                 *speed = (duplex == ETH_LINK_HALF_DUPLEX) ?
1313                                 ETH_LINK_SPEED_100M_HD : ETH_LINK_SPEED_100M;
1314         } else {
1315                 if (duplex != ETH_LINK_FULL_DUPLEX) {
1316                         printf("Invalid speed/duplex parameters\n");
1317                         return -1;
1318                 }
1319                 if (!strcmp(speedstr, "1000")) {
1320                         *speed = ETH_LINK_SPEED_1G;
1321                 } else if (!strcmp(speedstr, "10000")) {
1322                         *speed = ETH_LINK_SPEED_10G;
1323                 } else if (!strcmp(speedstr, "25000")) {
1324                         *speed = ETH_LINK_SPEED_25G;
1325                 } else if (!strcmp(speedstr, "40000")) {
1326                         *speed = ETH_LINK_SPEED_40G;
1327                 } else if (!strcmp(speedstr, "50000")) {
1328                         *speed = ETH_LINK_SPEED_50G;
1329                 } else if (!strcmp(speedstr, "100000")) {
1330                         *speed = ETH_LINK_SPEED_100G;
1331                 } else if (!strcmp(speedstr, "auto")) {
1332                         *speed = ETH_LINK_SPEED_AUTONEG;
1333                 } else {
1334                         printf("Unknown speed parameter\n");
1335                         return -1;
1336                 }
1337         }
1338
1339         return 0;
1340 }
1341
1342 static void
1343 cmd_config_speed_all_parsed(void *parsed_result,
1344                         __attribute__((unused)) struct cmdline *cl,
1345                         __attribute__((unused)) void *data)
1346 {
1347         struct cmd_config_speed_all *res = parsed_result;
1348         uint32_t link_speed;
1349         portid_t pid;
1350
1351         if (!all_ports_stopped()) {
1352                 printf("Please stop all ports first\n");
1353                 return;
1354         }
1355
1356         if (parse_and_check_speed_duplex(res->value1, res->value2,
1357                         &link_speed) < 0)
1358                 return;
1359
1360         RTE_ETH_FOREACH_DEV(pid) {
1361                 ports[pid].dev_conf.link_speeds = link_speed;
1362         }
1363
1364         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1365 }
1366
1367 cmdline_parse_token_string_t cmd_config_speed_all_port =
1368         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, port, "port");
1369 cmdline_parse_token_string_t cmd_config_speed_all_keyword =
1370         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, keyword,
1371                                                         "config");
1372 cmdline_parse_token_string_t cmd_config_speed_all_all =
1373         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, all, "all");
1374 cmdline_parse_token_string_t cmd_config_speed_all_item1 =
1375         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item1, "speed");
1376 cmdline_parse_token_string_t cmd_config_speed_all_value1 =
1377         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value1,
1378                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1379 cmdline_parse_token_string_t cmd_config_speed_all_item2 =
1380         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, item2, "duplex");
1381 cmdline_parse_token_string_t cmd_config_speed_all_value2 =
1382         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_all, value2,
1383                                                 "half#full#auto");
1384
1385 cmdline_parse_inst_t cmd_config_speed_all = {
1386         .f = cmd_config_speed_all_parsed,
1387         .data = NULL,
1388         .help_str = "port config all speed "
1389                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1390                                                         "half|full|auto",
1391         .tokens = {
1392                 (void *)&cmd_config_speed_all_port,
1393                 (void *)&cmd_config_speed_all_keyword,
1394                 (void *)&cmd_config_speed_all_all,
1395                 (void *)&cmd_config_speed_all_item1,
1396                 (void *)&cmd_config_speed_all_value1,
1397                 (void *)&cmd_config_speed_all_item2,
1398                 (void *)&cmd_config_speed_all_value2,
1399                 NULL,
1400         },
1401 };
1402
1403 /* *** configure speed for specific port *** */
1404 struct cmd_config_speed_specific {
1405         cmdline_fixed_string_t port;
1406         cmdline_fixed_string_t keyword;
1407         uint8_t id;
1408         cmdline_fixed_string_t item1;
1409         cmdline_fixed_string_t item2;
1410         cmdline_fixed_string_t value1;
1411         cmdline_fixed_string_t value2;
1412 };
1413
1414 static void
1415 cmd_config_speed_specific_parsed(void *parsed_result,
1416                                 __attribute__((unused)) struct cmdline *cl,
1417                                 __attribute__((unused)) void *data)
1418 {
1419         struct cmd_config_speed_specific *res = parsed_result;
1420         uint32_t link_speed;
1421
1422         if (!all_ports_stopped()) {
1423                 printf("Please stop all ports first\n");
1424                 return;
1425         }
1426
1427         if (port_id_is_invalid(res->id, ENABLED_WARN))
1428                 return;
1429
1430         if (parse_and_check_speed_duplex(res->value1, res->value2,
1431                         &link_speed) < 0)
1432                 return;
1433
1434         ports[res->id].dev_conf.link_speeds = link_speed;
1435
1436         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1437 }
1438
1439
1440 cmdline_parse_token_string_t cmd_config_speed_specific_port =
1441         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, port,
1442                                                                 "port");
1443 cmdline_parse_token_string_t cmd_config_speed_specific_keyword =
1444         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, keyword,
1445                                                                 "config");
1446 cmdline_parse_token_num_t cmd_config_speed_specific_id =
1447         TOKEN_NUM_INITIALIZER(struct cmd_config_speed_specific, id, UINT8);
1448 cmdline_parse_token_string_t cmd_config_speed_specific_item1 =
1449         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item1,
1450                                                                 "speed");
1451 cmdline_parse_token_string_t cmd_config_speed_specific_value1 =
1452         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value1,
1453                                 "10#100#1000#10000#25000#40000#50000#100000#auto");
1454 cmdline_parse_token_string_t cmd_config_speed_specific_item2 =
1455         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, item2,
1456                                                                 "duplex");
1457 cmdline_parse_token_string_t cmd_config_speed_specific_value2 =
1458         TOKEN_STRING_INITIALIZER(struct cmd_config_speed_specific, value2,
1459                                                         "half#full#auto");
1460
1461 cmdline_parse_inst_t cmd_config_speed_specific = {
1462         .f = cmd_config_speed_specific_parsed,
1463         .data = NULL,
1464         .help_str = "port config <port_id> speed "
1465                 "10|100|1000|10000|25000|40000|50000|100000|auto duplex "
1466                                                         "half|full|auto",
1467         .tokens = {
1468                 (void *)&cmd_config_speed_specific_port,
1469                 (void *)&cmd_config_speed_specific_keyword,
1470                 (void *)&cmd_config_speed_specific_id,
1471                 (void *)&cmd_config_speed_specific_item1,
1472                 (void *)&cmd_config_speed_specific_value1,
1473                 (void *)&cmd_config_speed_specific_item2,
1474                 (void *)&cmd_config_speed_specific_value2,
1475                 NULL,
1476         },
1477 };
1478
1479 /* *** configure txq/rxq, txd/rxd *** */
1480 struct cmd_config_rx_tx {
1481         cmdline_fixed_string_t port;
1482         cmdline_fixed_string_t keyword;
1483         cmdline_fixed_string_t all;
1484         cmdline_fixed_string_t name;
1485         uint16_t value;
1486 };
1487
1488 static void
1489 cmd_config_rx_tx_parsed(void *parsed_result,
1490                         __attribute__((unused)) struct cmdline *cl,
1491                         __attribute__((unused)) void *data)
1492 {
1493         struct cmd_config_rx_tx *res = parsed_result;
1494
1495         if (!all_ports_stopped()) {
1496                 printf("Please stop all ports first\n");
1497                 return;
1498         }
1499         if (!strcmp(res->name, "rxq")) {
1500                 if (!res->value && !nb_txq) {
1501                         printf("Warning: Either rx or tx queues should be non zero\n");
1502                         return;
1503                 }
1504                 if (check_nb_rxq(res->value) != 0)
1505                         return;
1506                 nb_rxq = res->value;
1507         }
1508         else if (!strcmp(res->name, "txq")) {
1509                 if (!res->value && !nb_rxq) {
1510                         printf("Warning: Either rx or tx queues should be non zero\n");
1511                         return;
1512                 }
1513                 if (check_nb_txq(res->value) != 0)
1514                         return;
1515                 nb_txq = res->value;
1516         }
1517         else if (!strcmp(res->name, "rxd")) {
1518                 if (res->value <= 0 || res->value > RTE_TEST_RX_DESC_MAX) {
1519                         printf("rxd %d invalid - must be > 0 && <= %d\n",
1520                                         res->value, RTE_TEST_RX_DESC_MAX);
1521                         return;
1522                 }
1523                 nb_rxd = res->value;
1524         } else if (!strcmp(res->name, "txd")) {
1525                 if (res->value <= 0 || res->value > RTE_TEST_TX_DESC_MAX) {
1526                         printf("txd %d invalid - must be > 0 && <= %d\n",
1527                                         res->value, RTE_TEST_TX_DESC_MAX);
1528                         return;
1529                 }
1530                 nb_txd = res->value;
1531         } else {
1532                 printf("Unknown parameter\n");
1533                 return;
1534         }
1535
1536         fwd_config_setup();
1537
1538         init_port_config();
1539
1540         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1541 }
1542
1543 cmdline_parse_token_string_t cmd_config_rx_tx_port =
1544         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, port, "port");
1545 cmdline_parse_token_string_t cmd_config_rx_tx_keyword =
1546         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, keyword, "config");
1547 cmdline_parse_token_string_t cmd_config_rx_tx_all =
1548         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, all, "all");
1549 cmdline_parse_token_string_t cmd_config_rx_tx_name =
1550         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_tx, name,
1551                                                 "rxq#txq#rxd#txd");
1552 cmdline_parse_token_num_t cmd_config_rx_tx_value =
1553         TOKEN_NUM_INITIALIZER(struct cmd_config_rx_tx, value, UINT16);
1554
1555 cmdline_parse_inst_t cmd_config_rx_tx = {
1556         .f = cmd_config_rx_tx_parsed,
1557         .data = NULL,
1558         .help_str = "port config all rxq|txq|rxd|txd <value>",
1559         .tokens = {
1560                 (void *)&cmd_config_rx_tx_port,
1561                 (void *)&cmd_config_rx_tx_keyword,
1562                 (void *)&cmd_config_rx_tx_all,
1563                 (void *)&cmd_config_rx_tx_name,
1564                 (void *)&cmd_config_rx_tx_value,
1565                 NULL,
1566         },
1567 };
1568
1569 /* *** config max packet length *** */
1570 struct cmd_config_max_pkt_len_result {
1571         cmdline_fixed_string_t port;
1572         cmdline_fixed_string_t keyword;
1573         cmdline_fixed_string_t all;
1574         cmdline_fixed_string_t name;
1575         uint32_t value;
1576 };
1577
1578 static void
1579 cmd_config_max_pkt_len_parsed(void *parsed_result,
1580                                 __attribute__((unused)) struct cmdline *cl,
1581                                 __attribute__((unused)) void *data)
1582 {
1583         struct cmd_config_max_pkt_len_result *res = parsed_result;
1584
1585         if (!all_ports_stopped()) {
1586                 printf("Please stop all ports first\n");
1587                 return;
1588         }
1589
1590         if (!strcmp(res->name, "max-pkt-len")) {
1591                 if (res->value < ETHER_MIN_LEN) {
1592                         printf("max-pkt-len can not be less than %d\n",
1593                                                         ETHER_MIN_LEN);
1594                         return;
1595                 }
1596                 if (res->value == rx_mode.max_rx_pkt_len)
1597                         return;
1598
1599                 rx_mode.max_rx_pkt_len = res->value;
1600                 if (res->value > ETHER_MAX_LEN)
1601                         rx_mode.jumbo_frame = 1;
1602                 else
1603                         rx_mode.jumbo_frame = 0;
1604         } else {
1605                 printf("Unknown parameter\n");
1606                 return;
1607         }
1608
1609         init_port_config();
1610
1611         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1612 }
1613
1614 cmdline_parse_token_string_t cmd_config_max_pkt_len_port =
1615         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, port,
1616                                                                 "port");
1617 cmdline_parse_token_string_t cmd_config_max_pkt_len_keyword =
1618         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, keyword,
1619                                                                 "config");
1620 cmdline_parse_token_string_t cmd_config_max_pkt_len_all =
1621         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, all,
1622                                                                 "all");
1623 cmdline_parse_token_string_t cmd_config_max_pkt_len_name =
1624         TOKEN_STRING_INITIALIZER(struct cmd_config_max_pkt_len_result, name,
1625                                                                 "max-pkt-len");
1626 cmdline_parse_token_num_t cmd_config_max_pkt_len_value =
1627         TOKEN_NUM_INITIALIZER(struct cmd_config_max_pkt_len_result, value,
1628                                                                 UINT32);
1629
1630 cmdline_parse_inst_t cmd_config_max_pkt_len = {
1631         .f = cmd_config_max_pkt_len_parsed,
1632         .data = NULL,
1633         .help_str = "port config all max-pkt-len <value>",
1634         .tokens = {
1635                 (void *)&cmd_config_max_pkt_len_port,
1636                 (void *)&cmd_config_max_pkt_len_keyword,
1637                 (void *)&cmd_config_max_pkt_len_all,
1638                 (void *)&cmd_config_max_pkt_len_name,
1639                 (void *)&cmd_config_max_pkt_len_value,
1640                 NULL,
1641         },
1642 };
1643
1644 /* *** configure port MTU *** */
1645 struct cmd_config_mtu_result {
1646         cmdline_fixed_string_t port;
1647         cmdline_fixed_string_t keyword;
1648         cmdline_fixed_string_t mtu;
1649         portid_t port_id;
1650         uint16_t value;
1651 };
1652
1653 static void
1654 cmd_config_mtu_parsed(void *parsed_result,
1655                       __attribute__((unused)) struct cmdline *cl,
1656                       __attribute__((unused)) void *data)
1657 {
1658         struct cmd_config_mtu_result *res = parsed_result;
1659
1660         if (res->value < ETHER_MIN_LEN) {
1661                 printf("mtu cannot be less than %d\n", ETHER_MIN_LEN);
1662                 return;
1663         }
1664         port_mtu_set(res->port_id, res->value);
1665 }
1666
1667 cmdline_parse_token_string_t cmd_config_mtu_port =
1668         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, port,
1669                                  "port");
1670 cmdline_parse_token_string_t cmd_config_mtu_keyword =
1671         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1672                                  "config");
1673 cmdline_parse_token_string_t cmd_config_mtu_mtu =
1674         TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword,
1675                                  "mtu");
1676 cmdline_parse_token_num_t cmd_config_mtu_port_id =
1677         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16);
1678 cmdline_parse_token_num_t cmd_config_mtu_value =
1679         TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16);
1680
1681 cmdline_parse_inst_t cmd_config_mtu = {
1682         .f = cmd_config_mtu_parsed,
1683         .data = NULL,
1684         .help_str = "port config mtu <port_id> <value>",
1685         .tokens = {
1686                 (void *)&cmd_config_mtu_port,
1687                 (void *)&cmd_config_mtu_keyword,
1688                 (void *)&cmd_config_mtu_mtu,
1689                 (void *)&cmd_config_mtu_port_id,
1690                 (void *)&cmd_config_mtu_value,
1691                 NULL,
1692         },
1693 };
1694
1695 /* *** configure rx mode *** */
1696 struct cmd_config_rx_mode_flag {
1697         cmdline_fixed_string_t port;
1698         cmdline_fixed_string_t keyword;
1699         cmdline_fixed_string_t all;
1700         cmdline_fixed_string_t name;
1701         cmdline_fixed_string_t value;
1702 };
1703
1704 static void
1705 cmd_config_rx_mode_flag_parsed(void *parsed_result,
1706                                 __attribute__((unused)) struct cmdline *cl,
1707                                 __attribute__((unused)) void *data)
1708 {
1709         struct cmd_config_rx_mode_flag *res = parsed_result;
1710
1711         if (!all_ports_stopped()) {
1712                 printf("Please stop all ports first\n");
1713                 return;
1714         }
1715
1716         if (!strcmp(res->name, "crc-strip")) {
1717                 if (!strcmp(res->value, "on"))
1718                         rx_mode.hw_strip_crc = 1;
1719                 else if (!strcmp(res->value, "off"))
1720                         rx_mode.hw_strip_crc = 0;
1721                 else {
1722                         printf("Unknown parameter\n");
1723                         return;
1724                 }
1725         } else if (!strcmp(res->name, "scatter")) {
1726                 if (!strcmp(res->value, "on"))
1727                         rx_mode.enable_scatter = 1;
1728                 else if (!strcmp(res->value, "off"))
1729                         rx_mode.enable_scatter = 0;
1730                 else {
1731                         printf("Unknown parameter\n");
1732                         return;
1733                 }
1734         } else if (!strcmp(res->name, "rx-cksum")) {
1735                 if (!strcmp(res->value, "on"))
1736                         rx_mode.hw_ip_checksum = 1;
1737                 else if (!strcmp(res->value, "off"))
1738                         rx_mode.hw_ip_checksum = 0;
1739                 else {
1740                         printf("Unknown parameter\n");
1741                         return;
1742                 }
1743         } else if (!strcmp(res->name, "rx-timestamp")) {
1744                 if (!strcmp(res->value, "on"))
1745                         rx_mode.hw_timestamp = 1;
1746                 else if (!strcmp(res->value, "off"))
1747                         rx_mode.hw_timestamp = 0;
1748                 else {
1749                         printf("Unknown parameter\n");
1750                         return;
1751                 }
1752         } else if (!strcmp(res->name, "hw-vlan")) {
1753                 if (!strcmp(res->value, "on")) {
1754                         rx_mode.hw_vlan_filter = 1;
1755                         rx_mode.hw_vlan_strip  = 1;
1756                 }
1757                 else if (!strcmp(res->value, "off")) {
1758                         rx_mode.hw_vlan_filter = 0;
1759                         rx_mode.hw_vlan_strip  = 0;
1760                 }
1761                 else {
1762                         printf("Unknown parameter\n");
1763                         return;
1764                 }
1765         } else if (!strcmp(res->name, "hw-vlan-filter")) {
1766                 if (!strcmp(res->value, "on"))
1767                         rx_mode.hw_vlan_filter = 1;
1768                 else if (!strcmp(res->value, "off"))
1769                         rx_mode.hw_vlan_filter = 0;
1770                 else {
1771                         printf("Unknown parameter\n");
1772                         return;
1773                 }
1774         } else if (!strcmp(res->name, "hw-vlan-strip")) {
1775                 if (!strcmp(res->value, "on"))
1776                         rx_mode.hw_vlan_strip  = 1;
1777                 else if (!strcmp(res->value, "off"))
1778                         rx_mode.hw_vlan_strip  = 0;
1779                 else {
1780                         printf("Unknown parameter\n");
1781                         return;
1782                 }
1783         } else if (!strcmp(res->name, "hw-vlan-extend")) {
1784                 if (!strcmp(res->value, "on"))
1785                         rx_mode.hw_vlan_extend = 1;
1786                 else if (!strcmp(res->value, "off"))
1787                         rx_mode.hw_vlan_extend = 0;
1788                 else {
1789                         printf("Unknown parameter\n");
1790                         return;
1791                 }
1792         } else if (!strcmp(res->name, "drop-en")) {
1793                 if (!strcmp(res->value, "on"))
1794                         rx_drop_en = 1;
1795                 else if (!strcmp(res->value, "off"))
1796                         rx_drop_en = 0;
1797                 else {
1798                         printf("Unknown parameter\n");
1799                         return;
1800                 }
1801         } else {
1802                 printf("Unknown parameter\n");
1803                 return;
1804         }
1805
1806         init_port_config();
1807
1808         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
1809 }
1810
1811 cmdline_parse_token_string_t cmd_config_rx_mode_flag_port =
1812         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, port, "port");
1813 cmdline_parse_token_string_t cmd_config_rx_mode_flag_keyword =
1814         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, keyword,
1815                                                                 "config");
1816 cmdline_parse_token_string_t cmd_config_rx_mode_flag_all =
1817         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all");
1818 cmdline_parse_token_string_t cmd_config_rx_mode_flag_name =
1819         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name,
1820                                         "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#"
1821                                         "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend");
1822 cmdline_parse_token_string_t cmd_config_rx_mode_flag_value =
1823         TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value,
1824                                                         "on#off");
1825
1826 cmdline_parse_inst_t cmd_config_rx_mode_flag = {
1827         .f = cmd_config_rx_mode_flag_parsed,
1828         .data = NULL,
1829         .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|"
1830                 "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off",
1831         .tokens = {
1832                 (void *)&cmd_config_rx_mode_flag_port,
1833                 (void *)&cmd_config_rx_mode_flag_keyword,
1834                 (void *)&cmd_config_rx_mode_flag_all,
1835                 (void *)&cmd_config_rx_mode_flag_name,
1836                 (void *)&cmd_config_rx_mode_flag_value,
1837                 NULL,
1838         },
1839 };
1840
1841 /* *** configure rss *** */
1842 struct cmd_config_rss {
1843         cmdline_fixed_string_t port;
1844         cmdline_fixed_string_t keyword;
1845         cmdline_fixed_string_t all;
1846         cmdline_fixed_string_t name;
1847         cmdline_fixed_string_t value;
1848 };
1849
1850 static void
1851 cmd_config_rss_parsed(void *parsed_result,
1852                         __attribute__((unused)) struct cmdline *cl,
1853                         __attribute__((unused)) void *data)
1854 {
1855         struct cmd_config_rss *res = parsed_result;
1856         struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, };
1857         int diag;
1858         uint8_t i;
1859
1860         if (!strcmp(res->value, "all"))
1861                 rss_conf.rss_hf = ETH_RSS_IP | ETH_RSS_TCP |
1862                                 ETH_RSS_UDP | ETH_RSS_SCTP |
1863                                         ETH_RSS_L2_PAYLOAD;
1864         else if (!strcmp(res->value, "ip"))
1865                 rss_conf.rss_hf = ETH_RSS_IP;
1866         else if (!strcmp(res->value, "udp"))
1867                 rss_conf.rss_hf = ETH_RSS_UDP;
1868         else if (!strcmp(res->value, "tcp"))
1869                 rss_conf.rss_hf = ETH_RSS_TCP;
1870         else if (!strcmp(res->value, "sctp"))
1871                 rss_conf.rss_hf = ETH_RSS_SCTP;
1872         else if (!strcmp(res->value, "ether"))
1873                 rss_conf.rss_hf = ETH_RSS_L2_PAYLOAD;
1874         else if (!strcmp(res->value, "port"))
1875                 rss_conf.rss_hf = ETH_RSS_PORT;
1876         else if (!strcmp(res->value, "vxlan"))
1877                 rss_conf.rss_hf = ETH_RSS_VXLAN;
1878         else if (!strcmp(res->value, "geneve"))
1879                 rss_conf.rss_hf = ETH_RSS_GENEVE;
1880         else if (!strcmp(res->value, "nvgre"))
1881                 rss_conf.rss_hf = ETH_RSS_NVGRE;
1882         else if (!strcmp(res->value, "none"))
1883                 rss_conf.rss_hf = 0;
1884         else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
1885                                                 atoi(res->value) < 64)
1886                 rss_conf.rss_hf = 1ULL << atoi(res->value);
1887         else {
1888                 printf("Unknown parameter\n");
1889                 return;
1890         }
1891         rss_conf.rss_key = NULL;
1892         for (i = 0; i < rte_eth_dev_count(); i++) {
1893                 diag = rte_eth_dev_rss_hash_update(i, &rss_conf);
1894                 if (diag < 0)
1895                         printf("Configuration of RSS hash at ethernet port %d "
1896                                 "failed with error (%d): %s.\n",
1897                                 i, -diag, strerror(-diag));
1898         }
1899 }
1900
1901 cmdline_parse_token_string_t cmd_config_rss_port =
1902         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, port, "port");
1903 cmdline_parse_token_string_t cmd_config_rss_keyword =
1904         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, keyword, "config");
1905 cmdline_parse_token_string_t cmd_config_rss_all =
1906         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, all, "all");
1907 cmdline_parse_token_string_t cmd_config_rss_name =
1908         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss");
1909 cmdline_parse_token_string_t cmd_config_rss_value =
1910         TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL);
1911
1912 cmdline_parse_inst_t cmd_config_rss = {
1913         .f = cmd_config_rss_parsed,
1914         .data = NULL,
1915         .help_str = "port config all rss "
1916                 "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>",
1917         .tokens = {
1918                 (void *)&cmd_config_rss_port,
1919                 (void *)&cmd_config_rss_keyword,
1920                 (void *)&cmd_config_rss_all,
1921                 (void *)&cmd_config_rss_name,
1922                 (void *)&cmd_config_rss_value,
1923                 NULL,
1924         },
1925 };
1926
1927 /* *** configure rss hash key *** */
1928 struct cmd_config_rss_hash_key {
1929         cmdline_fixed_string_t port;
1930         cmdline_fixed_string_t config;
1931         portid_t port_id;
1932         cmdline_fixed_string_t rss_hash_key;
1933         cmdline_fixed_string_t rss_type;
1934         cmdline_fixed_string_t key;
1935 };
1936
1937 static uint8_t
1938 hexa_digit_to_value(char hexa_digit)
1939 {
1940         if ((hexa_digit >= '0') && (hexa_digit <= '9'))
1941                 return (uint8_t) (hexa_digit - '0');
1942         if ((hexa_digit >= 'a') && (hexa_digit <= 'f'))
1943                 return (uint8_t) ((hexa_digit - 'a') + 10);
1944         if ((hexa_digit >= 'A') && (hexa_digit <= 'F'))
1945                 return (uint8_t) ((hexa_digit - 'A') + 10);
1946         /* Invalid hexa digit */
1947         return 0xFF;
1948 }
1949
1950 static uint8_t
1951 parse_and_check_key_hexa_digit(char *key, int idx)
1952 {
1953         uint8_t hexa_v;
1954
1955         hexa_v = hexa_digit_to_value(key[idx]);
1956         if (hexa_v == 0xFF)
1957                 printf("invalid key: character %c at position %d is not a "
1958                        "valid hexa digit\n", key[idx], idx);
1959         return hexa_v;
1960 }
1961
1962 static void
1963 cmd_config_rss_hash_key_parsed(void *parsed_result,
1964                                __attribute__((unused)) struct cmdline *cl,
1965                                __attribute__((unused)) void *data)
1966 {
1967         struct cmd_config_rss_hash_key *res = parsed_result;
1968         uint8_t hash_key[RSS_HASH_KEY_LENGTH];
1969         uint8_t xdgt0;
1970         uint8_t xdgt1;
1971         int i;
1972         struct rte_eth_dev_info dev_info;
1973         uint8_t hash_key_size;
1974         uint32_t key_len;
1975
1976         memset(&dev_info, 0, sizeof(dev_info));
1977         rte_eth_dev_info_get(res->port_id, &dev_info);
1978         if (dev_info.hash_key_size > 0 &&
1979                         dev_info.hash_key_size <= sizeof(hash_key))
1980                 hash_key_size = dev_info.hash_key_size;
1981         else {
1982                 printf("dev_info did not provide a valid hash key size\n");
1983                 return;
1984         }
1985         /* Check the length of the RSS hash key */
1986         key_len = strlen(res->key);
1987         if (key_len != (hash_key_size * 2)) {
1988                 printf("key length: %d invalid - key must be a string of %d"
1989                            " hexa-decimal numbers\n",
1990                            (int) key_len, hash_key_size * 2);
1991                 return;
1992         }
1993         /* Translate RSS hash key into binary representation */
1994         for (i = 0; i < hash_key_size; i++) {
1995                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
1996                 if (xdgt0 == 0xFF)
1997                         return;
1998                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
1999                 if (xdgt1 == 0xFF)
2000                         return;
2001                 hash_key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
2002         }
2003         port_rss_hash_key_update(res->port_id, res->rss_type, hash_key,
2004                         hash_key_size);
2005 }
2006
2007 cmdline_parse_token_string_t cmd_config_rss_hash_key_port =
2008         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port");
2009 cmdline_parse_token_string_t cmd_config_rss_hash_key_config =
2010         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config,
2011                                  "config");
2012 cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id =
2013         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16);
2014 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key =
2015         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key,
2016                                  rss_hash_key, "rss-hash-key");
2017 cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_type =
2018         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_type,
2019                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2020                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2021                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2022                                  "ipv6-tcp-ex#ipv6-udp-ex");
2023 cmdline_parse_token_string_t cmd_config_rss_hash_key_value =
2024         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL);
2025
2026 cmdline_parse_inst_t cmd_config_rss_hash_key = {
2027         .f = cmd_config_rss_hash_key_parsed,
2028         .data = NULL,
2029         .help_str = "port config <port_id> rss-hash-key "
2030                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2031                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2032                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex "
2033                 "<string of hex digits (variable length, NIC dependent)>",
2034         .tokens = {
2035                 (void *)&cmd_config_rss_hash_key_port,
2036                 (void *)&cmd_config_rss_hash_key_config,
2037                 (void *)&cmd_config_rss_hash_key_port_id,
2038                 (void *)&cmd_config_rss_hash_key_rss_hash_key,
2039                 (void *)&cmd_config_rss_hash_key_rss_type,
2040                 (void *)&cmd_config_rss_hash_key_value,
2041                 NULL,
2042         },
2043 };
2044
2045 /* *** configure port rxq/txq start/stop *** */
2046 struct cmd_config_rxtx_queue {
2047         cmdline_fixed_string_t port;
2048         portid_t portid;
2049         cmdline_fixed_string_t rxtxq;
2050         uint16_t qid;
2051         cmdline_fixed_string_t opname;
2052 };
2053
2054 static void
2055 cmd_config_rxtx_queue_parsed(void *parsed_result,
2056                         __attribute__((unused)) struct cmdline *cl,
2057                         __attribute__((unused)) void *data)
2058 {
2059         struct cmd_config_rxtx_queue *res = parsed_result;
2060         uint8_t isrx;
2061         uint8_t isstart;
2062         int ret = 0;
2063
2064         if (test_done == 0) {
2065                 printf("Please stop forwarding first\n");
2066                 return;
2067         }
2068
2069         if (port_id_is_invalid(res->portid, ENABLED_WARN))
2070                 return;
2071
2072         if (port_is_started(res->portid) != 1) {
2073                 printf("Please start port %u first\n", res->portid);
2074                 return;
2075         }
2076
2077         if (!strcmp(res->rxtxq, "rxq"))
2078                 isrx = 1;
2079         else if (!strcmp(res->rxtxq, "txq"))
2080                 isrx = 0;
2081         else {
2082                 printf("Unknown parameter\n");
2083                 return;
2084         }
2085
2086         if (isrx && rx_queue_id_is_invalid(res->qid))
2087                 return;
2088         else if (!isrx && tx_queue_id_is_invalid(res->qid))
2089                 return;
2090
2091         if (!strcmp(res->opname, "start"))
2092                 isstart = 1;
2093         else if (!strcmp(res->opname, "stop"))
2094                 isstart = 0;
2095         else {
2096                 printf("Unknown parameter\n");
2097                 return;
2098         }
2099
2100         if (isstart && isrx)
2101                 ret = rte_eth_dev_rx_queue_start(res->portid, res->qid);
2102         else if (!isstart && isrx)
2103                 ret = rte_eth_dev_rx_queue_stop(res->portid, res->qid);
2104         else if (isstart && !isrx)
2105                 ret = rte_eth_dev_tx_queue_start(res->portid, res->qid);
2106         else
2107                 ret = rte_eth_dev_tx_queue_stop(res->portid, res->qid);
2108
2109         if (ret == -ENOTSUP)
2110                 printf("Function not supported in PMD driver\n");
2111 }
2112
2113 cmdline_parse_token_string_t cmd_config_rxtx_queue_port =
2114         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port");
2115 cmdline_parse_token_num_t cmd_config_rxtx_queue_portid =
2116         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16);
2117 cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq =
2118         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq");
2119 cmdline_parse_token_num_t cmd_config_rxtx_queue_qid =
2120         TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, qid, UINT16);
2121 cmdline_parse_token_string_t cmd_config_rxtx_queue_opname =
2122         TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, opname,
2123                                                 "start#stop");
2124
2125 cmdline_parse_inst_t cmd_config_rxtx_queue = {
2126         .f = cmd_config_rxtx_queue_parsed,
2127         .data = NULL,
2128         .help_str = "port <port_id> rxq|txq <queue_id> start|stop",
2129         .tokens = {
2130                 (void *)&cmd_config_speed_all_port,
2131                 (void *)&cmd_config_rxtx_queue_portid,
2132                 (void *)&cmd_config_rxtx_queue_rxtxq,
2133                 (void *)&cmd_config_rxtx_queue_qid,
2134                 (void *)&cmd_config_rxtx_queue_opname,
2135                 NULL,
2136         },
2137 };
2138
2139 /* *** Configure RSS RETA *** */
2140 struct cmd_config_rss_reta {
2141         cmdline_fixed_string_t port;
2142         cmdline_fixed_string_t keyword;
2143         portid_t port_id;
2144         cmdline_fixed_string_t name;
2145         cmdline_fixed_string_t list_name;
2146         cmdline_fixed_string_t list_of_items;
2147 };
2148
2149 static int
2150 parse_reta_config(const char *str,
2151                   struct rte_eth_rss_reta_entry64 *reta_conf,
2152                   uint16_t nb_entries)
2153 {
2154         int i;
2155         unsigned size;
2156         uint16_t hash_index, idx, shift;
2157         uint16_t nb_queue;
2158         char s[256];
2159         const char *p, *p0 = str;
2160         char *end;
2161         enum fieldnames {
2162                 FLD_HASH_INDEX = 0,
2163                 FLD_QUEUE,
2164                 _NUM_FLD
2165         };
2166         unsigned long int_fld[_NUM_FLD];
2167         char *str_fld[_NUM_FLD];
2168
2169         while ((p = strchr(p0,'(')) != NULL) {
2170                 ++p;
2171                 if((p0 = strchr(p,')')) == NULL)
2172                         return -1;
2173
2174                 size = p0 - p;
2175                 if(size >= sizeof(s))
2176                         return -1;
2177
2178                 snprintf(s, sizeof(s), "%.*s", size, p);
2179                 if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD)
2180                         return -1;
2181                 for (i = 0; i < _NUM_FLD; i++) {
2182                         errno = 0;
2183                         int_fld[i] = strtoul(str_fld[i], &end, 0);
2184                         if (errno != 0 || end == str_fld[i] ||
2185                                         int_fld[i] > 65535)
2186                                 return -1;
2187                 }
2188
2189                 hash_index = (uint16_t)int_fld[FLD_HASH_INDEX];
2190                 nb_queue = (uint16_t)int_fld[FLD_QUEUE];
2191
2192                 if (hash_index >= nb_entries) {
2193                         printf("Invalid RETA hash index=%d\n", hash_index);
2194                         return -1;
2195                 }
2196
2197                 idx = hash_index / RTE_RETA_GROUP_SIZE;
2198                 shift = hash_index % RTE_RETA_GROUP_SIZE;
2199                 reta_conf[idx].mask |= (1ULL << shift);
2200                 reta_conf[idx].reta[shift] = nb_queue;
2201         }
2202
2203         return 0;
2204 }
2205
2206 static void
2207 cmd_set_rss_reta_parsed(void *parsed_result,
2208                         __attribute__((unused)) struct cmdline *cl,
2209                         __attribute__((unused)) void *data)
2210 {
2211         int ret;
2212         struct rte_eth_dev_info dev_info;
2213         struct rte_eth_rss_reta_entry64 reta_conf[8];
2214         struct cmd_config_rss_reta *res = parsed_result;
2215
2216         memset(&dev_info, 0, sizeof(dev_info));
2217         rte_eth_dev_info_get(res->port_id, &dev_info);
2218         if (dev_info.reta_size == 0) {
2219                 printf("Redirection table size is 0 which is "
2220                                         "invalid for RSS\n");
2221                 return;
2222         } else
2223                 printf("The reta size of port %d is %u\n",
2224                         res->port_id, dev_info.reta_size);
2225         if (dev_info.reta_size > ETH_RSS_RETA_SIZE_512) {
2226                 printf("Currently do not support more than %u entries of "
2227                         "redirection table\n", ETH_RSS_RETA_SIZE_512);
2228                 return;
2229         }
2230
2231         memset(reta_conf, 0, sizeof(reta_conf));
2232         if (!strcmp(res->list_name, "reta")) {
2233                 if (parse_reta_config(res->list_of_items, reta_conf,
2234                                                 dev_info.reta_size)) {
2235                         printf("Invalid RSS Redirection Table "
2236                                         "config entered\n");
2237                         return;
2238                 }
2239                 ret = rte_eth_dev_rss_reta_update(res->port_id,
2240                                 reta_conf, dev_info.reta_size);
2241                 if (ret != 0)
2242                         printf("Bad redirection table parameter, "
2243                                         "return code = %d \n", ret);
2244         }
2245 }
2246
2247 cmdline_parse_token_string_t cmd_config_rss_reta_port =
2248         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, port, "port");
2249 cmdline_parse_token_string_t cmd_config_rss_reta_keyword =
2250         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config");
2251 cmdline_parse_token_num_t cmd_config_rss_reta_port_id =
2252         TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16);
2253 cmdline_parse_token_string_t cmd_config_rss_reta_name =
2254         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss");
2255 cmdline_parse_token_string_t cmd_config_rss_reta_list_name =
2256         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_name, "reta");
2257 cmdline_parse_token_string_t cmd_config_rss_reta_list_of_items =
2258         TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, list_of_items,
2259                                  NULL);
2260 cmdline_parse_inst_t cmd_config_rss_reta = {
2261         .f = cmd_set_rss_reta_parsed,
2262         .data = NULL,
2263         .help_str = "port config <port_id> rss reta <hash,queue[,hash,queue]*>",
2264         .tokens = {
2265                 (void *)&cmd_config_rss_reta_port,
2266                 (void *)&cmd_config_rss_reta_keyword,
2267                 (void *)&cmd_config_rss_reta_port_id,
2268                 (void *)&cmd_config_rss_reta_name,
2269                 (void *)&cmd_config_rss_reta_list_name,
2270                 (void *)&cmd_config_rss_reta_list_of_items,
2271                 NULL,
2272         },
2273 };
2274
2275 /* *** SHOW PORT RETA INFO *** */
2276 struct cmd_showport_reta {
2277         cmdline_fixed_string_t show;
2278         cmdline_fixed_string_t port;
2279         portid_t port_id;
2280         cmdline_fixed_string_t rss;
2281         cmdline_fixed_string_t reta;
2282         uint16_t size;
2283         cmdline_fixed_string_t list_of_items;
2284 };
2285
2286 static int
2287 showport_parse_reta_config(struct rte_eth_rss_reta_entry64 *conf,
2288                            uint16_t nb_entries,
2289                            char *str)
2290 {
2291         uint32_t size;
2292         const char *p, *p0 = str;
2293         char s[256];
2294         char *end;
2295         char *str_fld[8];
2296         uint16_t i;
2297         uint16_t num = (nb_entries + RTE_RETA_GROUP_SIZE - 1) /
2298                         RTE_RETA_GROUP_SIZE;
2299         int ret;
2300
2301         p = strchr(p0, '(');
2302         if (p == NULL)
2303                 return -1;
2304         p++;
2305         p0 = strchr(p, ')');
2306         if (p0 == NULL)
2307                 return -1;
2308         size = p0 - p;
2309         if (size >= sizeof(s)) {
2310                 printf("The string size exceeds the internal buffer size\n");
2311                 return -1;
2312         }
2313         snprintf(s, sizeof(s), "%.*s", size, p);
2314         ret = rte_strsplit(s, sizeof(s), str_fld, num, ',');
2315         if (ret <= 0 || ret != num) {
2316                 printf("The bits of masks do not match the number of "
2317                                         "reta entries: %u\n", num);
2318                 return -1;
2319         }
2320         for (i = 0; i < ret; i++)
2321                 conf[i].mask = (uint64_t)strtoul(str_fld[i], &end, 0);
2322
2323         return 0;
2324 }
2325
2326 static void
2327 cmd_showport_reta_parsed(void *parsed_result,
2328                          __attribute__((unused)) struct cmdline *cl,
2329                          __attribute__((unused)) void *data)
2330 {
2331         struct cmd_showport_reta *res = parsed_result;
2332         struct rte_eth_rss_reta_entry64 reta_conf[8];
2333         struct rte_eth_dev_info dev_info;
2334         uint16_t max_reta_size;
2335
2336         memset(&dev_info, 0, sizeof(dev_info));
2337         rte_eth_dev_info_get(res->port_id, &dev_info);
2338         max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512);
2339         if (res->size == 0 || res->size > max_reta_size) {
2340                 printf("Invalid redirection table size: %u (1-%u)\n",
2341                         res->size, max_reta_size);
2342                 return;
2343         }
2344
2345         memset(reta_conf, 0, sizeof(reta_conf));
2346         if (showport_parse_reta_config(reta_conf, res->size,
2347                                 res->list_of_items) < 0) {
2348                 printf("Invalid string: %s for reta masks\n",
2349                                         res->list_of_items);
2350                 return;
2351         }
2352         port_rss_reta_info(res->port_id, reta_conf, res->size);
2353 }
2354
2355 cmdline_parse_token_string_t cmd_showport_reta_show =
2356         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, show, "show");
2357 cmdline_parse_token_string_t cmd_showport_reta_port =
2358         TOKEN_STRING_INITIALIZER(struct  cmd_showport_reta, port, "port");
2359 cmdline_parse_token_num_t cmd_showport_reta_port_id =
2360         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16);
2361 cmdline_parse_token_string_t cmd_showport_reta_rss =
2362         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss");
2363 cmdline_parse_token_string_t cmd_showport_reta_reta =
2364         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, reta, "reta");
2365 cmdline_parse_token_num_t cmd_showport_reta_size =
2366         TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, size, UINT16);
2367 cmdline_parse_token_string_t cmd_showport_reta_list_of_items =
2368         TOKEN_STRING_INITIALIZER(struct cmd_showport_reta,
2369                                         list_of_items, NULL);
2370
2371 cmdline_parse_inst_t cmd_showport_reta = {
2372         .f = cmd_showport_reta_parsed,
2373         .data = NULL,
2374         .help_str = "show port <port_id> rss reta <size> <mask0[,mask1]*>",
2375         .tokens = {
2376                 (void *)&cmd_showport_reta_show,
2377                 (void *)&cmd_showport_reta_port,
2378                 (void *)&cmd_showport_reta_port_id,
2379                 (void *)&cmd_showport_reta_rss,
2380                 (void *)&cmd_showport_reta_reta,
2381                 (void *)&cmd_showport_reta_size,
2382                 (void *)&cmd_showport_reta_list_of_items,
2383                 NULL,
2384         },
2385 };
2386
2387 /* *** Show RSS hash configuration *** */
2388 struct cmd_showport_rss_hash {
2389         cmdline_fixed_string_t show;
2390         cmdline_fixed_string_t port;
2391         portid_t port_id;
2392         cmdline_fixed_string_t rss_hash;
2393         cmdline_fixed_string_t rss_type;
2394         cmdline_fixed_string_t key; /* optional argument */
2395 };
2396
2397 static void cmd_showport_rss_hash_parsed(void *parsed_result,
2398                                 __attribute__((unused)) struct cmdline *cl,
2399                                 void *show_rss_key)
2400 {
2401         struct cmd_showport_rss_hash *res = parsed_result;
2402
2403         port_rss_hash_conf_show(res->port_id, res->rss_type,
2404                                 show_rss_key != NULL);
2405 }
2406
2407 cmdline_parse_token_string_t cmd_showport_rss_hash_show =
2408         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, show, "show");
2409 cmdline_parse_token_string_t cmd_showport_rss_hash_port =
2410         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port");
2411 cmdline_parse_token_num_t cmd_showport_rss_hash_port_id =
2412         TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16);
2413 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash =
2414         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash,
2415                                  "rss-hash");
2416 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash_info =
2417         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_type,
2418                                  "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
2419                                  "ipv4-other#ipv6#ipv6-frag#ipv6-tcp#ipv6-udp#"
2420                                  "ipv6-sctp#ipv6-other#l2-payload#ipv6-ex#"
2421                                  "ipv6-tcp-ex#ipv6-udp-ex");
2422 cmdline_parse_token_string_t cmd_showport_rss_hash_rss_key =
2423         TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, key, "key");
2424
2425 cmdline_parse_inst_t cmd_showport_rss_hash = {
2426         .f = cmd_showport_rss_hash_parsed,
2427         .data = NULL,
2428         .help_str = "show port <port_id> rss-hash "
2429                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2430                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2431                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex",
2432         .tokens = {
2433                 (void *)&cmd_showport_rss_hash_show,
2434                 (void *)&cmd_showport_rss_hash_port,
2435                 (void *)&cmd_showport_rss_hash_port_id,
2436                 (void *)&cmd_showport_rss_hash_rss_hash,
2437                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2438                 NULL,
2439         },
2440 };
2441
2442 cmdline_parse_inst_t cmd_showport_rss_hash_key = {
2443         .f = cmd_showport_rss_hash_parsed,
2444         .data = (void *)1,
2445         .help_str = "show port <port_id> rss-hash "
2446                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
2447                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
2448                 "l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex key",
2449         .tokens = {
2450                 (void *)&cmd_showport_rss_hash_show,
2451                 (void *)&cmd_showport_rss_hash_port,
2452                 (void *)&cmd_showport_rss_hash_port_id,
2453                 (void *)&cmd_showport_rss_hash_rss_hash,
2454                 (void *)&cmd_showport_rss_hash_rss_hash_info,
2455                 (void *)&cmd_showport_rss_hash_rss_key,
2456                 NULL,
2457         },
2458 };
2459
2460 /* *** Configure DCB *** */
2461 struct cmd_config_dcb {
2462         cmdline_fixed_string_t port;
2463         cmdline_fixed_string_t config;
2464         portid_t port_id;
2465         cmdline_fixed_string_t dcb;
2466         cmdline_fixed_string_t vt;
2467         cmdline_fixed_string_t vt_en;
2468         uint8_t num_tcs;
2469         cmdline_fixed_string_t pfc;
2470         cmdline_fixed_string_t pfc_en;
2471 };
2472
2473 static void
2474 cmd_config_dcb_parsed(void *parsed_result,
2475                         __attribute__((unused)) struct cmdline *cl,
2476                         __attribute__((unused)) void *data)
2477 {
2478         struct cmd_config_dcb *res = parsed_result;
2479         portid_t port_id = res->port_id;
2480         struct rte_port *port;
2481         uint8_t pfc_en;
2482         int ret;
2483
2484         port = &ports[port_id];
2485         /** Check if the port is not started **/
2486         if (port->port_status != RTE_PORT_STOPPED) {
2487                 printf("Please stop port %d first\n", port_id);
2488                 return;
2489         }
2490
2491         if ((res->num_tcs != ETH_4_TCS) && (res->num_tcs != ETH_8_TCS)) {
2492                 printf("The invalid number of traffic class,"
2493                         " only 4 or 8 allowed.\n");
2494                 return;
2495         }
2496
2497         if (nb_fwd_lcores < res->num_tcs) {
2498                 printf("nb_cores shouldn't be less than number of TCs.\n");
2499                 return;
2500         }
2501         if (!strncmp(res->pfc_en, "on", 2))
2502                 pfc_en = 1;
2503         else
2504                 pfc_en = 0;
2505
2506         /* DCB in VT mode */
2507         if (!strncmp(res->vt_en, "on", 2))
2508                 ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
2509                                 (enum rte_eth_nb_tcs)res->num_tcs,
2510                                 pfc_en);
2511         else
2512                 ret = init_port_dcb_config(port_id, DCB_ENABLED,
2513                                 (enum rte_eth_nb_tcs)res->num_tcs,
2514                                 pfc_en);
2515
2516
2517         if (ret != 0) {
2518                 printf("Cannot initialize network ports.\n");
2519                 return;
2520         }
2521
2522         cmd_reconfig_device_queue(port_id, 1, 1);
2523 }
2524
2525 cmdline_parse_token_string_t cmd_config_dcb_port =
2526         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, port, "port");
2527 cmdline_parse_token_string_t cmd_config_dcb_config =
2528         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config");
2529 cmdline_parse_token_num_t cmd_config_dcb_port_id =
2530         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16);
2531 cmdline_parse_token_string_t cmd_config_dcb_dcb =
2532         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb");
2533 cmdline_parse_token_string_t cmd_config_dcb_vt =
2534         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt, "vt");
2535 cmdline_parse_token_string_t cmd_config_dcb_vt_en =
2536         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, vt_en, "on#off");
2537 cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
2538         TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, UINT8);
2539 cmdline_parse_token_string_t cmd_config_dcb_pfc=
2540         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
2541 cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
2542         TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
2543
2544 cmdline_parse_inst_t cmd_config_dcb = {
2545         .f = cmd_config_dcb_parsed,
2546         .data = NULL,
2547         .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
2548         .tokens = {
2549                 (void *)&cmd_config_dcb_port,
2550                 (void *)&cmd_config_dcb_config,
2551                 (void *)&cmd_config_dcb_port_id,
2552                 (void *)&cmd_config_dcb_dcb,
2553                 (void *)&cmd_config_dcb_vt,
2554                 (void *)&cmd_config_dcb_vt_en,
2555                 (void *)&cmd_config_dcb_num_tcs,
2556                 (void *)&cmd_config_dcb_pfc,
2557                 (void *)&cmd_config_dcb_pfc_en,
2558                 NULL,
2559         },
2560 };
2561
2562 /* *** configure number of packets per burst *** */
2563 struct cmd_config_burst {
2564         cmdline_fixed_string_t port;
2565         cmdline_fixed_string_t keyword;
2566         cmdline_fixed_string_t all;
2567         cmdline_fixed_string_t name;
2568         uint16_t value;
2569 };
2570
2571 static void
2572 cmd_config_burst_parsed(void *parsed_result,
2573                         __attribute__((unused)) struct cmdline *cl,
2574                         __attribute__((unused)) void *data)
2575 {
2576         struct cmd_config_burst *res = parsed_result;
2577
2578         if (!all_ports_stopped()) {
2579                 printf("Please stop all ports first\n");
2580                 return;
2581         }
2582
2583         if (!strcmp(res->name, "burst")) {
2584                 if (res->value < 1 || res->value > MAX_PKT_BURST) {
2585                         printf("burst must be >= 1 && <= %d\n", MAX_PKT_BURST);
2586                         return;
2587                 }
2588                 nb_pkt_per_burst = res->value;
2589         } else {
2590                 printf("Unknown parameter\n");
2591                 return;
2592         }
2593
2594         init_port_config();
2595
2596         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2597 }
2598
2599 cmdline_parse_token_string_t cmd_config_burst_port =
2600         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, port, "port");
2601 cmdline_parse_token_string_t cmd_config_burst_keyword =
2602         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, keyword, "config");
2603 cmdline_parse_token_string_t cmd_config_burst_all =
2604         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, all, "all");
2605 cmdline_parse_token_string_t cmd_config_burst_name =
2606         TOKEN_STRING_INITIALIZER(struct cmd_config_burst, name, "burst");
2607 cmdline_parse_token_num_t cmd_config_burst_value =
2608         TOKEN_NUM_INITIALIZER(struct cmd_config_burst, value, UINT16);
2609
2610 cmdline_parse_inst_t cmd_config_burst = {
2611         .f = cmd_config_burst_parsed,
2612         .data = NULL,
2613         .help_str = "port config all burst <value>",
2614         .tokens = {
2615                 (void *)&cmd_config_burst_port,
2616                 (void *)&cmd_config_burst_keyword,
2617                 (void *)&cmd_config_burst_all,
2618                 (void *)&cmd_config_burst_name,
2619                 (void *)&cmd_config_burst_value,
2620                 NULL,
2621         },
2622 };
2623
2624 /* *** configure rx/tx queues *** */
2625 struct cmd_config_thresh {
2626         cmdline_fixed_string_t port;
2627         cmdline_fixed_string_t keyword;
2628         cmdline_fixed_string_t all;
2629         cmdline_fixed_string_t name;
2630         uint8_t value;
2631 };
2632
2633 static void
2634 cmd_config_thresh_parsed(void *parsed_result,
2635                         __attribute__((unused)) struct cmdline *cl,
2636                         __attribute__((unused)) void *data)
2637 {
2638         struct cmd_config_thresh *res = parsed_result;
2639
2640         if (!all_ports_stopped()) {
2641                 printf("Please stop all ports first\n");
2642                 return;
2643         }
2644
2645         if (!strcmp(res->name, "txpt"))
2646                 tx_pthresh = res->value;
2647         else if(!strcmp(res->name, "txht"))
2648                 tx_hthresh = res->value;
2649         else if(!strcmp(res->name, "txwt"))
2650                 tx_wthresh = res->value;
2651         else if(!strcmp(res->name, "rxpt"))
2652                 rx_pthresh = res->value;
2653         else if(!strcmp(res->name, "rxht"))
2654                 rx_hthresh = res->value;
2655         else if(!strcmp(res->name, "rxwt"))
2656                 rx_wthresh = res->value;
2657         else {
2658                 printf("Unknown parameter\n");
2659                 return;
2660         }
2661
2662         init_port_config();
2663
2664         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2665 }
2666
2667 cmdline_parse_token_string_t cmd_config_thresh_port =
2668         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, port, "port");
2669 cmdline_parse_token_string_t cmd_config_thresh_keyword =
2670         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, keyword, "config");
2671 cmdline_parse_token_string_t cmd_config_thresh_all =
2672         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, all, "all");
2673 cmdline_parse_token_string_t cmd_config_thresh_name =
2674         TOKEN_STRING_INITIALIZER(struct cmd_config_thresh, name,
2675                                 "txpt#txht#txwt#rxpt#rxht#rxwt");
2676 cmdline_parse_token_num_t cmd_config_thresh_value =
2677         TOKEN_NUM_INITIALIZER(struct cmd_config_thresh, value, UINT8);
2678
2679 cmdline_parse_inst_t cmd_config_thresh = {
2680         .f = cmd_config_thresh_parsed,
2681         .data = NULL,
2682         .help_str = "port config all txpt|txht|txwt|rxpt|rxht|rxwt <value>",
2683         .tokens = {
2684                 (void *)&cmd_config_thresh_port,
2685                 (void *)&cmd_config_thresh_keyword,
2686                 (void *)&cmd_config_thresh_all,
2687                 (void *)&cmd_config_thresh_name,
2688                 (void *)&cmd_config_thresh_value,
2689                 NULL,
2690         },
2691 };
2692
2693 /* *** configure free/rs threshold *** */
2694 struct cmd_config_threshold {
2695         cmdline_fixed_string_t port;
2696         cmdline_fixed_string_t keyword;
2697         cmdline_fixed_string_t all;
2698         cmdline_fixed_string_t name;
2699         uint16_t value;
2700 };
2701
2702 static void
2703 cmd_config_threshold_parsed(void *parsed_result,
2704                         __attribute__((unused)) struct cmdline *cl,
2705                         __attribute__((unused)) void *data)
2706 {
2707         struct cmd_config_threshold *res = parsed_result;
2708
2709         if (!all_ports_stopped()) {
2710                 printf("Please stop all ports first\n");
2711                 return;
2712         }
2713
2714         if (!strcmp(res->name, "txfreet"))
2715                 tx_free_thresh = res->value;
2716         else if (!strcmp(res->name, "txrst"))
2717                 tx_rs_thresh = res->value;
2718         else if (!strcmp(res->name, "rxfreet"))
2719                 rx_free_thresh = res->value;
2720         else {
2721                 printf("Unknown parameter\n");
2722                 return;
2723         }
2724
2725         init_port_config();
2726
2727         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
2728 }
2729
2730 cmdline_parse_token_string_t cmd_config_threshold_port =
2731         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, port, "port");
2732 cmdline_parse_token_string_t cmd_config_threshold_keyword =
2733         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, keyword,
2734                                                                 "config");
2735 cmdline_parse_token_string_t cmd_config_threshold_all =
2736         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, all, "all");
2737 cmdline_parse_token_string_t cmd_config_threshold_name =
2738         TOKEN_STRING_INITIALIZER(struct cmd_config_threshold, name,
2739                                                 "txfreet#txrst#rxfreet");
2740 cmdline_parse_token_num_t cmd_config_threshold_value =
2741         TOKEN_NUM_INITIALIZER(struct cmd_config_threshold, value, UINT16);
2742
2743 cmdline_parse_inst_t cmd_config_threshold = {
2744         .f = cmd_config_threshold_parsed,
2745         .data = NULL,
2746         .help_str = "port config all txfreet|txrst|rxfreet <value>",
2747         .tokens = {
2748                 (void *)&cmd_config_threshold_port,
2749                 (void *)&cmd_config_threshold_keyword,
2750                 (void *)&cmd_config_threshold_all,
2751                 (void *)&cmd_config_threshold_name,
2752                 (void *)&cmd_config_threshold_value,
2753                 NULL,
2754         },
2755 };
2756
2757 /* *** stop *** */
2758 struct cmd_stop_result {
2759         cmdline_fixed_string_t stop;
2760 };
2761
2762 static void cmd_stop_parsed(__attribute__((unused)) void *parsed_result,
2763                             __attribute__((unused)) struct cmdline *cl,
2764                             __attribute__((unused)) void *data)
2765 {
2766         stop_packet_forwarding();
2767 }
2768
2769 cmdline_parse_token_string_t cmd_stop_stop =
2770         TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop");
2771
2772 cmdline_parse_inst_t cmd_stop = {
2773         .f = cmd_stop_parsed,
2774         .data = NULL,
2775         .help_str = "stop: Stop packet forwarding",
2776         .tokens = {
2777                 (void *)&cmd_stop_stop,
2778                 NULL,
2779         },
2780 };
2781
2782 /* *** SET CORELIST and PORTLIST CONFIGURATION *** */
2783
2784 unsigned int
2785 parse_item_list(char* str, const char* item_name, unsigned int max_items,
2786                 unsigned int *parsed_items, int check_unique_values)
2787 {
2788         unsigned int nb_item;
2789         unsigned int value;
2790         unsigned int i;
2791         unsigned int j;
2792         int value_ok;
2793         char c;
2794
2795         /*
2796          * First parse all items in the list and store their value.
2797          */
2798         value = 0;
2799         nb_item = 0;
2800         value_ok = 0;
2801         for (i = 0; i < strnlen(str, STR_TOKEN_SIZE); i++) {
2802                 c = str[i];
2803                 if ((c >= '0') && (c <= '9')) {
2804                         value = (unsigned int) (value * 10 + (c - '0'));
2805                         value_ok = 1;
2806                         continue;
2807                 }
2808                 if (c != ',') {
2809                         printf("character %c is not a decimal digit\n", c);
2810                         return 0;
2811                 }
2812                 if (! value_ok) {
2813                         printf("No valid value before comma\n");
2814                         return 0;
2815                 }
2816                 if (nb_item < max_items) {
2817                         parsed_items[nb_item] = value;
2818                         value_ok = 0;
2819                         value = 0;
2820                 }
2821                 nb_item++;
2822         }
2823         if (nb_item >= max_items) {
2824                 printf("Number of %s = %u > %u (maximum items)\n",
2825                        item_name, nb_item + 1, max_items);
2826                 return 0;
2827         }
2828         parsed_items[nb_item++] = value;
2829         if (! check_unique_values)
2830                 return nb_item;
2831
2832         /*
2833          * Then, check that all values in the list are differents.
2834          * No optimization here...
2835          */
2836         for (i = 0; i < nb_item; i++) {
2837                 for (j = i + 1; j < nb_item; j++) {
2838                         if (parsed_items[j] == parsed_items[i]) {
2839                                 printf("duplicated %s %u at index %u and %u\n",
2840                                        item_name, parsed_items[i], i, j);
2841                                 return 0;
2842                         }
2843                 }
2844         }
2845         return nb_item;
2846 }
2847
2848 struct cmd_set_list_result {
2849         cmdline_fixed_string_t cmd_keyword;
2850         cmdline_fixed_string_t list_name;
2851         cmdline_fixed_string_t list_of_items;
2852 };
2853
2854 static void cmd_set_list_parsed(void *parsed_result,
2855                                 __attribute__((unused)) struct cmdline *cl,
2856                                 __attribute__((unused)) void *data)
2857 {
2858         struct cmd_set_list_result *res;
2859         union {
2860                 unsigned int lcorelist[RTE_MAX_LCORE];
2861                 unsigned int portlist[RTE_MAX_ETHPORTS];
2862         } parsed_items;
2863         unsigned int nb_item;
2864
2865         if (test_done == 0) {
2866                 printf("Please stop forwarding first\n");
2867                 return;
2868         }
2869
2870         res = parsed_result;
2871         if (!strcmp(res->list_name, "corelist")) {
2872                 nb_item = parse_item_list(res->list_of_items, "core",
2873                                           RTE_MAX_LCORE,
2874                                           parsed_items.lcorelist, 1);
2875                 if (nb_item > 0) {
2876                         set_fwd_lcores_list(parsed_items.lcorelist, nb_item);
2877                         fwd_config_setup();
2878                 }
2879                 return;
2880         }
2881         if (!strcmp(res->list_name, "portlist")) {
2882                 nb_item = parse_item_list(res->list_of_items, "port",
2883                                           RTE_MAX_ETHPORTS,
2884                                           parsed_items.portlist, 1);
2885                 if (nb_item > 0) {
2886                         set_fwd_ports_list(parsed_items.portlist, nb_item);
2887                         fwd_config_setup();
2888                 }
2889         }
2890 }
2891
2892 cmdline_parse_token_string_t cmd_set_list_keyword =
2893         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, cmd_keyword,
2894                                  "set");
2895 cmdline_parse_token_string_t cmd_set_list_name =
2896         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_name,
2897                                  "corelist#portlist");
2898 cmdline_parse_token_string_t cmd_set_list_of_items =
2899         TOKEN_STRING_INITIALIZER(struct cmd_set_list_result, list_of_items,
2900                                  NULL);
2901
2902 cmdline_parse_inst_t cmd_set_fwd_list = {
2903         .f = cmd_set_list_parsed,
2904         .data = NULL,
2905         .help_str = "set corelist|portlist <list0[,list1]*>",
2906         .tokens = {
2907                 (void *)&cmd_set_list_keyword,
2908                 (void *)&cmd_set_list_name,
2909                 (void *)&cmd_set_list_of_items,
2910                 NULL,
2911         },
2912 };
2913
2914 /* *** SET COREMASK and PORTMASK CONFIGURATION *** */
2915
2916 struct cmd_setmask_result {
2917         cmdline_fixed_string_t set;
2918         cmdline_fixed_string_t mask;
2919         uint64_t hexavalue;
2920 };
2921
2922 static void cmd_set_mask_parsed(void *parsed_result,
2923                                 __attribute__((unused)) struct cmdline *cl,
2924                                 __attribute__((unused)) void *data)
2925 {
2926         struct cmd_setmask_result *res = parsed_result;
2927
2928         if (test_done == 0) {
2929                 printf("Please stop forwarding first\n");
2930                 return;
2931         }
2932         if (!strcmp(res->mask, "coremask")) {
2933                 set_fwd_lcores_mask(res->hexavalue);
2934                 fwd_config_setup();
2935         } else if (!strcmp(res->mask, "portmask")) {
2936                 set_fwd_ports_mask(res->hexavalue);
2937                 fwd_config_setup();
2938         }
2939 }
2940
2941 cmdline_parse_token_string_t cmd_setmask_set =
2942         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, set, "set");
2943 cmdline_parse_token_string_t cmd_setmask_mask =
2944         TOKEN_STRING_INITIALIZER(struct cmd_setmask_result, mask,
2945                                  "coremask#portmask");
2946 cmdline_parse_token_num_t cmd_setmask_value =
2947         TOKEN_NUM_INITIALIZER(struct cmd_setmask_result, hexavalue, UINT64);
2948
2949 cmdline_parse_inst_t cmd_set_fwd_mask = {
2950         .f = cmd_set_mask_parsed,
2951         .data = NULL,
2952         .help_str = "set coremask|portmask <hexadecimal value>",
2953         .tokens = {
2954                 (void *)&cmd_setmask_set,
2955                 (void *)&cmd_setmask_mask,
2956                 (void *)&cmd_setmask_value,
2957                 NULL,
2958         },
2959 };
2960
2961 /*
2962  * SET NBPORT, NBCORE, PACKET BURST, and VERBOSE LEVEL CONFIGURATION
2963  */
2964 struct cmd_set_result {
2965         cmdline_fixed_string_t set;
2966         cmdline_fixed_string_t what;
2967         uint16_t value;
2968 };
2969
2970 static void cmd_set_parsed(void *parsed_result,
2971                            __attribute__((unused)) struct cmdline *cl,
2972                            __attribute__((unused)) void *data)
2973 {
2974         struct cmd_set_result *res = parsed_result;
2975         if (!strcmp(res->what, "nbport")) {
2976                 set_fwd_ports_number(res->value);
2977                 fwd_config_setup();
2978         } else if (!strcmp(res->what, "nbcore")) {
2979                 set_fwd_lcores_number(res->value);
2980                 fwd_config_setup();
2981         } else if (!strcmp(res->what, "burst"))
2982                 set_nb_pkt_per_burst(res->value);
2983         else if (!strcmp(res->what, "verbose"))
2984                 set_verbose_level(res->value);
2985 }
2986
2987 cmdline_parse_token_string_t cmd_set_set =
2988         TOKEN_STRING_INITIALIZER(struct cmd_set_result, set, "set");
2989 cmdline_parse_token_string_t cmd_set_what =
2990         TOKEN_STRING_INITIALIZER(struct cmd_set_result, what,
2991                                  "nbport#nbcore#burst#verbose");
2992 cmdline_parse_token_num_t cmd_set_value =
2993         TOKEN_NUM_INITIALIZER(struct cmd_set_result, value, UINT16);
2994
2995 cmdline_parse_inst_t cmd_set_numbers = {
2996         .f = cmd_set_parsed,
2997         .data = NULL,
2998         .help_str = "set nbport|nbcore|burst|verbose <value>",
2999         .tokens = {
3000                 (void *)&cmd_set_set,
3001                 (void *)&cmd_set_what,
3002                 (void *)&cmd_set_value,
3003                 NULL,
3004         },
3005 };
3006
3007 /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */
3008
3009 struct cmd_set_txpkts_result {
3010         cmdline_fixed_string_t cmd_keyword;
3011         cmdline_fixed_string_t txpkts;
3012         cmdline_fixed_string_t seg_lengths;
3013 };
3014
3015 static void
3016 cmd_set_txpkts_parsed(void *parsed_result,
3017                       __attribute__((unused)) struct cmdline *cl,
3018                       __attribute__((unused)) void *data)
3019 {
3020         struct cmd_set_txpkts_result *res;
3021         unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT];
3022         unsigned int nb_segs;
3023
3024         res = parsed_result;
3025         nb_segs = parse_item_list(res->seg_lengths, "segment lengths",
3026                                   RTE_MAX_SEGS_PER_PKT, seg_lengths, 0);
3027         if (nb_segs > 0)
3028                 set_tx_pkt_segments(seg_lengths, nb_segs);
3029 }
3030
3031 cmdline_parse_token_string_t cmd_set_txpkts_keyword =
3032         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3033                                  cmd_keyword, "set");
3034 cmdline_parse_token_string_t cmd_set_txpkts_name =
3035         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3036                                  txpkts, "txpkts");
3037 cmdline_parse_token_string_t cmd_set_txpkts_lengths =
3038         TOKEN_STRING_INITIALIZER(struct cmd_set_txpkts_result,
3039                                  seg_lengths, NULL);
3040
3041 cmdline_parse_inst_t cmd_set_txpkts = {
3042         .f = cmd_set_txpkts_parsed,
3043         .data = NULL,
3044         .help_str = "set txpkts <len0[,len1]*>",
3045         .tokens = {
3046                 (void *)&cmd_set_txpkts_keyword,
3047                 (void *)&cmd_set_txpkts_name,
3048                 (void *)&cmd_set_txpkts_lengths,
3049                 NULL,
3050         },
3051 };
3052
3053 /* *** SET COPY AND SPLIT POLICY ON TX PACKETS *** */
3054
3055 struct cmd_set_txsplit_result {
3056         cmdline_fixed_string_t cmd_keyword;
3057         cmdline_fixed_string_t txsplit;
3058         cmdline_fixed_string_t mode;
3059 };
3060
3061 static void
3062 cmd_set_txsplit_parsed(void *parsed_result,
3063                       __attribute__((unused)) struct cmdline *cl,
3064                       __attribute__((unused)) void *data)
3065 {
3066         struct cmd_set_txsplit_result *res;
3067
3068         res = parsed_result;
3069         set_tx_pkt_split(res->mode);
3070 }
3071
3072 cmdline_parse_token_string_t cmd_set_txsplit_keyword =
3073         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3074                                  cmd_keyword, "set");
3075 cmdline_parse_token_string_t cmd_set_txsplit_name =
3076         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3077                                  txsplit, "txsplit");
3078 cmdline_parse_token_string_t cmd_set_txsplit_mode =
3079         TOKEN_STRING_INITIALIZER(struct cmd_set_txsplit_result,
3080                                  mode, NULL);
3081
3082 cmdline_parse_inst_t cmd_set_txsplit = {
3083         .f = cmd_set_txsplit_parsed,
3084         .data = NULL,
3085         .help_str = "set txsplit on|off|rand",
3086         .tokens = {
3087                 (void *)&cmd_set_txsplit_keyword,
3088                 (void *)&cmd_set_txsplit_name,
3089                 (void *)&cmd_set_txsplit_mode,
3090                 NULL,
3091         },
3092 };
3093
3094 /* *** CONFIG TX QUEUE FLAGS *** */
3095
3096 struct cmd_config_txqflags_result {
3097         cmdline_fixed_string_t port;
3098         cmdline_fixed_string_t config;
3099         cmdline_fixed_string_t all;
3100         cmdline_fixed_string_t what;
3101         int32_t hexvalue;
3102 };
3103
3104 static void cmd_config_txqflags_parsed(void *parsed_result,
3105                                 __attribute__((unused)) struct cmdline *cl,
3106                                 __attribute__((unused)) void *data)
3107 {
3108         struct cmd_config_txqflags_result *res = parsed_result;
3109
3110         if (!all_ports_stopped()) {
3111                 printf("Please stop all ports first\n");
3112                 return;
3113         }
3114
3115         if (strcmp(res->what, "txqflags")) {
3116                 printf("Unknown parameter\n");
3117                 return;
3118         }
3119
3120         if (res->hexvalue >= 0) {
3121                 txq_flags = res->hexvalue;
3122         } else {
3123                 printf("txqflags must be >= 0\n");
3124                 return;
3125         }
3126
3127         init_port_config();
3128
3129         cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
3130 }
3131
3132 cmdline_parse_token_string_t cmd_config_txqflags_port =
3133         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, port,
3134                                  "port");
3135 cmdline_parse_token_string_t cmd_config_txqflags_config =
3136         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, config,
3137                                  "config");
3138 cmdline_parse_token_string_t cmd_config_txqflags_all =
3139         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, all,
3140                                  "all");
3141 cmdline_parse_token_string_t cmd_config_txqflags_what =
3142         TOKEN_STRING_INITIALIZER(struct cmd_config_txqflags_result, what,
3143                                  "txqflags");
3144 cmdline_parse_token_num_t cmd_config_txqflags_value =
3145         TOKEN_NUM_INITIALIZER(struct cmd_config_txqflags_result,
3146                                 hexvalue, INT32);
3147
3148 cmdline_parse_inst_t cmd_config_txqflags = {
3149         .f = cmd_config_txqflags_parsed,
3150         .data = NULL,
3151         .help_str = "port config all txqflags <value>",
3152         .tokens = {
3153                 (void *)&cmd_config_txqflags_port,
3154                 (void *)&cmd_config_txqflags_config,
3155                 (void *)&cmd_config_txqflags_all,
3156                 (void *)&cmd_config_txqflags_what,
3157                 (void *)&cmd_config_txqflags_value,
3158                 NULL,
3159         },
3160 };
3161
3162 /* *** ADD/REMOVE ALL VLAN IDENTIFIERS TO/FROM A PORT VLAN RX FILTER *** */
3163 struct cmd_rx_vlan_filter_all_result {
3164         cmdline_fixed_string_t rx_vlan;
3165         cmdline_fixed_string_t what;
3166         cmdline_fixed_string_t all;
3167         portid_t port_id;
3168 };
3169
3170 static void
3171 cmd_rx_vlan_filter_all_parsed(void *parsed_result,
3172                               __attribute__((unused)) struct cmdline *cl,
3173                               __attribute__((unused)) void *data)
3174 {
3175         struct cmd_rx_vlan_filter_all_result *res = parsed_result;
3176
3177         if (!strcmp(res->what, "add"))
3178                 rx_vlan_all_filter_set(res->port_id, 1);
3179         else
3180                 rx_vlan_all_filter_set(res->port_id, 0);
3181 }
3182
3183 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_rx_vlan =
3184         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3185                                  rx_vlan, "rx_vlan");
3186 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_what =
3187         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3188                                  what, "add#rm");
3189 cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all =
3190         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3191                                  all, "all");
3192 cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid =
3193         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result,
3194                               port_id, UINT16);
3195
3196 cmdline_parse_inst_t cmd_rx_vlan_filter_all = {
3197         .f = cmd_rx_vlan_filter_all_parsed,
3198         .data = NULL,
3199         .help_str = "rx_vlan add|rm all <port_id>: "
3200                 "Add/Remove all identifiers to/from the set of VLAN "
3201                 "identifiers filtered by a port",
3202         .tokens = {
3203                 (void *)&cmd_rx_vlan_filter_all_rx_vlan,
3204                 (void *)&cmd_rx_vlan_filter_all_what,
3205                 (void *)&cmd_rx_vlan_filter_all_all,
3206                 (void *)&cmd_rx_vlan_filter_all_portid,
3207                 NULL,
3208         },
3209 };
3210
3211 /* *** VLAN OFFLOAD SET ON A PORT *** */
3212 struct cmd_vlan_offload_result {
3213         cmdline_fixed_string_t vlan;
3214         cmdline_fixed_string_t set;
3215         cmdline_fixed_string_t vlan_type;
3216         cmdline_fixed_string_t what;
3217         cmdline_fixed_string_t on;
3218         cmdline_fixed_string_t port_id;
3219 };
3220
3221 static void
3222 cmd_vlan_offload_parsed(void *parsed_result,
3223                           __attribute__((unused)) struct cmdline *cl,
3224                           __attribute__((unused)) void *data)
3225 {
3226         int on;
3227         struct cmd_vlan_offload_result *res = parsed_result;
3228         char *str;
3229         int i, len = 0;
3230         portid_t port_id = 0;
3231         unsigned int tmp;
3232
3233         str = res->port_id;
3234         len = strnlen(str, STR_TOKEN_SIZE);
3235         i = 0;
3236         /* Get port_id first */
3237         while(i < len){
3238                 if(str[i] == ',')
3239                         break;
3240
3241                 i++;
3242         }
3243         str[i]='\0';
3244         tmp = strtoul(str, NULL, 0);
3245         /* If port_id greater that what portid_t can represent, return */
3246         if(tmp >= RTE_MAX_ETHPORTS)
3247                 return;
3248         port_id = (portid_t)tmp;
3249
3250         if (!strcmp(res->on, "on"))
3251                 on = 1;
3252         else
3253                 on = 0;
3254
3255         if (!strcmp(res->what, "strip"))
3256                 rx_vlan_strip_set(port_id,  on);
3257         else if(!strcmp(res->what, "stripq")){
3258                 uint16_t queue_id = 0;
3259
3260                 /* No queue_id, return */
3261                 if(i + 1 >= len) {
3262                         printf("must specify (port,queue_id)\n");
3263                         return;
3264                 }
3265                 tmp = strtoul(str + i + 1, NULL, 0);
3266                 /* If queue_id greater that what 16-bits can represent, return */
3267                 if(tmp > 0xffff)
3268                         return;
3269
3270                 queue_id = (uint16_t)tmp;
3271                 rx_vlan_strip_set_on_queue(port_id, queue_id, on);
3272         }
3273         else if (!strcmp(res->what, "filter"))
3274                 rx_vlan_filter_set(port_id, on);
3275         else
3276                 vlan_extend_set(port_id, on);
3277
3278         return;
3279 }
3280
3281 cmdline_parse_token_string_t cmd_vlan_offload_vlan =
3282         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3283                                  vlan, "vlan");
3284 cmdline_parse_token_string_t cmd_vlan_offload_set =
3285         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3286                                  set, "set");
3287 cmdline_parse_token_string_t cmd_vlan_offload_what =
3288         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3289                                  what, "strip#filter#qinq#stripq");
3290 cmdline_parse_token_string_t cmd_vlan_offload_on =
3291         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3292                               on, "on#off");
3293 cmdline_parse_token_string_t cmd_vlan_offload_portid =
3294         TOKEN_STRING_INITIALIZER(struct cmd_vlan_offload_result,
3295                               port_id, NULL);
3296
3297 cmdline_parse_inst_t cmd_vlan_offload = {
3298         .f = cmd_vlan_offload_parsed,
3299         .data = NULL,
3300         .help_str = "vlan set strip|filter|qinq|stripq on|off "
3301                 "<port_id[,queue_id]>: "
3302                 "Filter/Strip for rx side qinq(extended) for both rx/tx sides",
3303         .tokens = {
3304                 (void *)&cmd_vlan_offload_vlan,
3305                 (void *)&cmd_vlan_offload_set,
3306                 (void *)&cmd_vlan_offload_what,
3307                 (void *)&cmd_vlan_offload_on,
3308                 (void *)&cmd_vlan_offload_portid,
3309                 NULL,
3310         },
3311 };
3312
3313 /* *** VLAN TPID SET ON A PORT *** */
3314 struct cmd_vlan_tpid_result {
3315         cmdline_fixed_string_t vlan;
3316         cmdline_fixed_string_t set;
3317         cmdline_fixed_string_t vlan_type;
3318         cmdline_fixed_string_t what;
3319         uint16_t tp_id;
3320         portid_t port_id;
3321 };
3322
3323 static void
3324 cmd_vlan_tpid_parsed(void *parsed_result,
3325                           __attribute__((unused)) struct cmdline *cl,
3326                           __attribute__((unused)) void *data)
3327 {
3328         struct cmd_vlan_tpid_result *res = parsed_result;
3329         enum rte_vlan_type vlan_type;
3330
3331         if (!strcmp(res->vlan_type, "inner"))
3332                 vlan_type = ETH_VLAN_TYPE_INNER;
3333         else if (!strcmp(res->vlan_type, "outer"))
3334                 vlan_type = ETH_VLAN_TYPE_OUTER;
3335         else {
3336                 printf("Unknown vlan type\n");
3337                 return;
3338         }
3339         vlan_tpid_set(res->port_id, vlan_type, res->tp_id);
3340 }
3341
3342 cmdline_parse_token_string_t cmd_vlan_tpid_vlan =
3343         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3344                                  vlan, "vlan");
3345 cmdline_parse_token_string_t cmd_vlan_tpid_set =
3346         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3347                                  set, "set");
3348 cmdline_parse_token_string_t cmd_vlan_type =
3349         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3350                                  vlan_type, "inner#outer");
3351 cmdline_parse_token_string_t cmd_vlan_tpid_what =
3352         TOKEN_STRING_INITIALIZER(struct cmd_vlan_tpid_result,
3353                                  what, "tpid");
3354 cmdline_parse_token_num_t cmd_vlan_tpid_tpid =
3355         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3356                               tp_id, UINT16);
3357 cmdline_parse_token_num_t cmd_vlan_tpid_portid =
3358         TOKEN_NUM_INITIALIZER(struct cmd_vlan_tpid_result,
3359                               port_id, UINT16);
3360
3361 cmdline_parse_inst_t cmd_vlan_tpid = {
3362         .f = cmd_vlan_tpid_parsed,
3363         .data = NULL,
3364         .help_str = "vlan set inner|outer tpid <tp_id> <port_id>: "
3365                 "Set the VLAN Ether type",
3366         .tokens = {
3367                 (void *)&cmd_vlan_tpid_vlan,
3368                 (void *)&cmd_vlan_tpid_set,
3369                 (void *)&cmd_vlan_type,
3370                 (void *)&cmd_vlan_tpid_what,
3371                 (void *)&cmd_vlan_tpid_tpid,
3372                 (void *)&cmd_vlan_tpid_portid,
3373                 NULL,
3374         },
3375 };
3376
3377 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
3378 struct cmd_rx_vlan_filter_result {
3379         cmdline_fixed_string_t rx_vlan;
3380         cmdline_fixed_string_t what;
3381         uint16_t vlan_id;
3382         portid_t port_id;
3383 };
3384
3385 static void
3386 cmd_rx_vlan_filter_parsed(void *parsed_result,
3387                           __attribute__((unused)) struct cmdline *cl,
3388                           __attribute__((unused)) void *data)
3389 {
3390         struct cmd_rx_vlan_filter_result *res = parsed_result;
3391
3392         if (!strcmp(res->what, "add"))
3393                 rx_vft_set(res->port_id, res->vlan_id, 1);
3394         else
3395                 rx_vft_set(res->port_id, res->vlan_id, 0);
3396 }
3397
3398 cmdline_parse_token_string_t cmd_rx_vlan_filter_rx_vlan =
3399         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3400                                  rx_vlan, "rx_vlan");
3401 cmdline_parse_token_string_t cmd_rx_vlan_filter_what =
3402         TOKEN_STRING_INITIALIZER(struct cmd_rx_vlan_filter_result,
3403                                  what, "add#rm");
3404 cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid =
3405         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3406                               vlan_id, UINT16);
3407 cmdline_parse_token_num_t cmd_rx_vlan_filter_portid =
3408         TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result,
3409                               port_id, UINT16);
3410
3411 cmdline_parse_inst_t cmd_rx_vlan_filter = {
3412         .f = cmd_rx_vlan_filter_parsed,
3413         .data = NULL,
3414         .help_str = "rx_vlan add|rm <vlan_id> <port_id>: "
3415                 "Add/Remove a VLAN identifier to/from the set of VLAN "
3416                 "identifiers filtered by a port",
3417         .tokens = {
3418                 (void *)&cmd_rx_vlan_filter_rx_vlan,
3419                 (void *)&cmd_rx_vlan_filter_what,
3420                 (void *)&cmd_rx_vlan_filter_vlanid,
3421                 (void *)&cmd_rx_vlan_filter_portid,
3422                 NULL,
3423         },
3424 };
3425
3426 /* *** ENABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3427 struct cmd_tx_vlan_set_result {
3428         cmdline_fixed_string_t tx_vlan;
3429         cmdline_fixed_string_t set;
3430         portid_t port_id;
3431         uint16_t vlan_id;
3432 };
3433
3434 static void
3435 cmd_tx_vlan_set_parsed(void *parsed_result,
3436                        __attribute__((unused)) struct cmdline *cl,
3437                        __attribute__((unused)) void *data)
3438 {
3439         struct cmd_tx_vlan_set_result *res = parsed_result;
3440
3441         tx_vlan_set(res->port_id, res->vlan_id);
3442 }
3443
3444 cmdline_parse_token_string_t cmd_tx_vlan_set_tx_vlan =
3445         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3446                                  tx_vlan, "tx_vlan");
3447 cmdline_parse_token_string_t cmd_tx_vlan_set_set =
3448         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_result,
3449                                  set, "set");
3450 cmdline_parse_token_num_t cmd_tx_vlan_set_portid =
3451         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3452                               port_id, UINT16);
3453 cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid =
3454         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result,
3455                               vlan_id, UINT16);
3456
3457 cmdline_parse_inst_t cmd_tx_vlan_set = {
3458         .f = cmd_tx_vlan_set_parsed,
3459         .data = NULL,
3460         .help_str = "tx_vlan set <port_id> <vlan_id>: "
3461                 "Enable hardware insertion of a single VLAN header "
3462                 "with a given TAG Identifier in packets sent on a port",
3463         .tokens = {
3464                 (void *)&cmd_tx_vlan_set_tx_vlan,
3465                 (void *)&cmd_tx_vlan_set_set,
3466                 (void *)&cmd_tx_vlan_set_portid,
3467                 (void *)&cmd_tx_vlan_set_vlanid,
3468                 NULL,
3469         },
3470 };
3471
3472 /* *** ENABLE HARDWARE INSERTION OF Double VLAN HEADER IN TX PACKETS *** */
3473 struct cmd_tx_vlan_set_qinq_result {
3474         cmdline_fixed_string_t tx_vlan;
3475         cmdline_fixed_string_t set;
3476         portid_t port_id;
3477         uint16_t vlan_id;
3478         uint16_t vlan_id_outer;
3479 };
3480
3481 static void
3482 cmd_tx_vlan_set_qinq_parsed(void *parsed_result,
3483                             __attribute__((unused)) struct cmdline *cl,
3484                             __attribute__((unused)) void *data)
3485 {
3486         struct cmd_tx_vlan_set_qinq_result *res = parsed_result;
3487
3488         tx_qinq_set(res->port_id, res->vlan_id, res->vlan_id_outer);
3489 }
3490
3491 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_tx_vlan =
3492         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3493                 tx_vlan, "tx_vlan");
3494 cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set =
3495         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3496                 set, "set");
3497 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid =
3498         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3499                 port_id, UINT16);
3500 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid =
3501         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3502                 vlan_id, UINT16);
3503 cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid_outer =
3504         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result,
3505                 vlan_id_outer, UINT16);
3506
3507 cmdline_parse_inst_t cmd_tx_vlan_set_qinq = {
3508         .f = cmd_tx_vlan_set_qinq_parsed,
3509         .data = NULL,
3510         .help_str = "tx_vlan set <port_id> <vlan_id> <outer_vlan_id>: "
3511                 "Enable hardware insertion of double VLAN header "
3512                 "with given TAG Identifiers in packets sent on a port",
3513         .tokens = {
3514                 (void *)&cmd_tx_vlan_set_qinq_tx_vlan,
3515                 (void *)&cmd_tx_vlan_set_qinq_set,
3516                 (void *)&cmd_tx_vlan_set_qinq_portid,
3517                 (void *)&cmd_tx_vlan_set_qinq_vlanid,
3518                 (void *)&cmd_tx_vlan_set_qinq_vlanid_outer,
3519                 NULL,
3520         },
3521 };
3522
3523 /* *** ENABLE/DISABLE PORT BASED TX VLAN INSERTION *** */
3524 struct cmd_tx_vlan_set_pvid_result {
3525         cmdline_fixed_string_t tx_vlan;
3526         cmdline_fixed_string_t set;
3527         cmdline_fixed_string_t pvid;
3528         portid_t port_id;
3529         uint16_t vlan_id;
3530         cmdline_fixed_string_t mode;
3531 };
3532
3533 static void
3534 cmd_tx_vlan_set_pvid_parsed(void *parsed_result,
3535                             __attribute__((unused)) struct cmdline *cl,
3536                             __attribute__((unused)) void *data)
3537 {
3538         struct cmd_tx_vlan_set_pvid_result *res = parsed_result;
3539
3540         if (strcmp(res->mode, "on") == 0)
3541                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 1);
3542         else
3543                 tx_vlan_pvid_set(res->port_id, res->vlan_id, 0);
3544 }
3545
3546 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_tx_vlan =
3547         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3548                                  tx_vlan, "tx_vlan");
3549 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_set =
3550         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3551                                  set, "set");
3552 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid =
3553         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3554                                  pvid, "pvid");
3555 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id =
3556         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3557                              port_id, UINT16);
3558 cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id =
3559         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3560                               vlan_id, UINT16);
3561 cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_mode =
3562         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_set_pvid_result,
3563                                  mode, "on#off");
3564
3565 cmdline_parse_inst_t cmd_tx_vlan_set_pvid = {
3566         .f = cmd_tx_vlan_set_pvid_parsed,
3567         .data = NULL,
3568         .help_str = "tx_vlan set pvid <port_id> <vlan_id> on|off",
3569         .tokens = {
3570                 (void *)&cmd_tx_vlan_set_pvid_tx_vlan,
3571                 (void *)&cmd_tx_vlan_set_pvid_set,
3572                 (void *)&cmd_tx_vlan_set_pvid_pvid,
3573                 (void *)&cmd_tx_vlan_set_pvid_port_id,
3574                 (void *)&cmd_tx_vlan_set_pvid_vlan_id,
3575                 (void *)&cmd_tx_vlan_set_pvid_mode,
3576                 NULL,
3577         },
3578 };
3579
3580 /* *** DISABLE HARDWARE INSERTION OF VLAN HEADER IN TX PACKETS *** */
3581 struct cmd_tx_vlan_reset_result {
3582         cmdline_fixed_string_t tx_vlan;
3583         cmdline_fixed_string_t reset;
3584         portid_t port_id;
3585 };
3586
3587 static void
3588 cmd_tx_vlan_reset_parsed(void *parsed_result,
3589                          __attribute__((unused)) struct cmdline *cl,
3590                          __attribute__((unused)) void *data)
3591 {
3592         struct cmd_tx_vlan_reset_result *res = parsed_result;
3593
3594         tx_vlan_reset(res->port_id);
3595 }
3596
3597 cmdline_parse_token_string_t cmd_tx_vlan_reset_tx_vlan =
3598         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3599                                  tx_vlan, "tx_vlan");
3600 cmdline_parse_token_string_t cmd_tx_vlan_reset_reset =
3601         TOKEN_STRING_INITIALIZER(struct cmd_tx_vlan_reset_result,
3602                                  reset, "reset");
3603 cmdline_parse_token_num_t cmd_tx_vlan_reset_portid =
3604         TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result,
3605                               port_id, UINT16);
3606
3607 cmdline_parse_inst_t cmd_tx_vlan_reset = {
3608         .f = cmd_tx_vlan_reset_parsed,
3609         .data = NULL,
3610         .help_str = "tx_vlan reset <port_id>: Disable hardware insertion of a "
3611                 "VLAN header in packets sent on a port",
3612         .tokens = {
3613                 (void *)&cmd_tx_vlan_reset_tx_vlan,
3614                 (void *)&cmd_tx_vlan_reset_reset,
3615                 (void *)&cmd_tx_vlan_reset_portid,
3616                 NULL,
3617         },
3618 };
3619
3620
3621 /* *** ENABLE HARDWARE INSERTION OF CHECKSUM IN TX PACKETS *** */
3622 struct cmd_csum_result {
3623         cmdline_fixed_string_t csum;
3624         cmdline_fixed_string_t mode;
3625         cmdline_fixed_string_t proto;
3626         cmdline_fixed_string_t hwsw;
3627         portid_t port_id;
3628 };
3629
3630 static void
3631 csum_show(int port_id)
3632 {
3633         struct rte_eth_dev_info dev_info;
3634         uint16_t ol_flags;
3635
3636         ol_flags = ports[port_id].tx_ol_flags;
3637         printf("Parse tunnel is %s\n",
3638                 (ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) ? "on" : "off");
3639         printf("IP checksum offload is %s\n",
3640                 (ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) ? "hw" : "sw");
3641         printf("UDP checksum offload is %s\n",
3642                 (ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) ? "hw" : "sw");
3643         printf("TCP checksum offload is %s\n",
3644                 (ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) ? "hw" : "sw");
3645         printf("SCTP checksum offload is %s\n",
3646                 (ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) ? "hw" : "sw");
3647         printf("Outer-Ip checksum offload is %s\n",
3648                 (ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) ? "hw" : "sw");
3649
3650         /* display warnings if configuration is not supported by the NIC */
3651         rte_eth_dev_info_get(port_id, &dev_info);
3652         if ((ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) &&
3653                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) {
3654                 printf("Warning: hardware IP checksum enabled but not "
3655                         "supported by port %d\n", port_id);
3656         }
3657         if ((ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) &&
3658                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) == 0) {
3659                 printf("Warning: hardware UDP checksum enabled but not "
3660                         "supported by port %d\n", port_id);
3661         }
3662         if ((ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) &&
3663                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) == 0) {
3664                 printf("Warning: hardware TCP checksum enabled but not "
3665                         "supported by port %d\n", port_id);
3666         }
3667         if ((ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
3668                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) == 0) {
3669                 printf("Warning: hardware SCTP checksum enabled but not "
3670                         "supported by port %d\n", port_id);
3671         }
3672         if ((ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) &&
3673                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) == 0) {
3674                 printf("Warning: hardware outer IP checksum enabled but not "
3675                         "supported by port %d\n", port_id);
3676         }
3677 }
3678
3679 static void
3680 cmd_csum_parsed(void *parsed_result,
3681                        __attribute__((unused)) struct cmdline *cl,
3682                        __attribute__((unused)) void *data)
3683 {
3684         struct cmd_csum_result *res = parsed_result;
3685         int hw = 0;
3686         uint16_t mask = 0;
3687
3688         if (port_id_is_invalid(res->port_id, ENABLED_WARN)) {
3689                 printf("invalid port %d\n", res->port_id);
3690                 return;
3691         }
3692
3693         if (!strcmp(res->mode, "set")) {
3694
3695                 if (!strcmp(res->hwsw, "hw"))
3696                         hw = 1;
3697
3698                 if (!strcmp(res->proto, "ip")) {
3699                         mask = TESTPMD_TX_OFFLOAD_IP_CKSUM;
3700                 } else if (!strcmp(res->proto, "udp")) {
3701                         mask = TESTPMD_TX_OFFLOAD_UDP_CKSUM;
3702                 } else if (!strcmp(res->proto, "tcp")) {
3703                         mask = TESTPMD_TX_OFFLOAD_TCP_CKSUM;
3704                 } else if (!strcmp(res->proto, "sctp")) {
3705                         mask = TESTPMD_TX_OFFLOAD_SCTP_CKSUM;
3706                 } else if (!strcmp(res->proto, "outer-ip")) {
3707                         mask = TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM;
3708                 }
3709
3710                 if (hw)
3711                         ports[res->port_id].tx_ol_flags |= mask;
3712                 else
3713                         ports[res->port_id].tx_ol_flags &= (~mask);
3714         }
3715         csum_show(res->port_id);
3716 }
3717
3718 cmdline_parse_token_string_t cmd_csum_csum =
3719         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3720                                 csum, "csum");
3721 cmdline_parse_token_string_t cmd_csum_mode =
3722         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3723                                 mode, "set");
3724 cmdline_parse_token_string_t cmd_csum_proto =
3725         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3726                                 proto, "ip#tcp#udp#sctp#outer-ip");
3727 cmdline_parse_token_string_t cmd_csum_hwsw =
3728         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3729                                 hwsw, "hw#sw");
3730 cmdline_parse_token_num_t cmd_csum_portid =
3731         TOKEN_NUM_INITIALIZER(struct cmd_csum_result,
3732                                 port_id, UINT16);
3733
3734 cmdline_parse_inst_t cmd_csum_set = {
3735         .f = cmd_csum_parsed,
3736         .data = NULL,
3737         .help_str = "csum set ip|tcp|udp|sctp|outer-ip hw|sw <port_id>: "
3738                 "Enable/Disable hardware calculation of L3/L4 checksum when "
3739                 "using csum forward engine",
3740         .tokens = {
3741                 (void *)&cmd_csum_csum,
3742                 (void *)&cmd_csum_mode,
3743                 (void *)&cmd_csum_proto,
3744                 (void *)&cmd_csum_hwsw,
3745                 (void *)&cmd_csum_portid,
3746                 NULL,
3747         },
3748 };
3749
3750 cmdline_parse_token_string_t cmd_csum_mode_show =
3751         TOKEN_STRING_INITIALIZER(struct cmd_csum_result,
3752                                 mode, "show");
3753
3754 cmdline_parse_inst_t cmd_csum_show = {
3755         .f = cmd_csum_parsed,
3756         .data = NULL,
3757         .help_str = "csum show <port_id>: Show checksum offload configuration",
3758         .tokens = {
3759                 (void *)&cmd_csum_csum,
3760                 (void *)&cmd_csum_mode_show,
3761                 (void *)&cmd_csum_portid,
3762                 NULL,
3763         },
3764 };
3765
3766 /* Enable/disable tunnel parsing */
3767 struct cmd_csum_tunnel_result {
3768         cmdline_fixed_string_t csum;
3769         cmdline_fixed_string_t parse;
3770         cmdline_fixed_string_t onoff;
3771         portid_t port_id;
3772 };
3773
3774 static void
3775 cmd_csum_tunnel_parsed(void *parsed_result,
3776                        __attribute__((unused)) struct cmdline *cl,
3777                        __attribute__((unused)) void *data)
3778 {
3779         struct cmd_csum_tunnel_result *res = parsed_result;
3780
3781         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3782                 return;
3783
3784         if (!strcmp(res->onoff, "on"))
3785                 ports[res->port_id].tx_ol_flags |=
3786                         TESTPMD_TX_OFFLOAD_PARSE_TUNNEL;
3787         else
3788                 ports[res->port_id].tx_ol_flags &=
3789                         (~TESTPMD_TX_OFFLOAD_PARSE_TUNNEL);
3790
3791         csum_show(res->port_id);
3792 }
3793
3794 cmdline_parse_token_string_t cmd_csum_tunnel_csum =
3795         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3796                                 csum, "csum");
3797 cmdline_parse_token_string_t cmd_csum_tunnel_parse =
3798         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3799                                 parse, "parse_tunnel");
3800 cmdline_parse_token_string_t cmd_csum_tunnel_onoff =
3801         TOKEN_STRING_INITIALIZER(struct cmd_csum_tunnel_result,
3802                                 onoff, "on#off");
3803 cmdline_parse_token_num_t cmd_csum_tunnel_portid =
3804         TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result,
3805                                 port_id, UINT16);
3806
3807 cmdline_parse_inst_t cmd_csum_tunnel = {
3808         .f = cmd_csum_tunnel_parsed,
3809         .data = NULL,
3810         .help_str = "csum parse_tunnel on|off <port_id>: "
3811                 "Enable/Disable parsing of tunnels for csum engine",
3812         .tokens = {
3813                 (void *)&cmd_csum_tunnel_csum,
3814                 (void *)&cmd_csum_tunnel_parse,
3815                 (void *)&cmd_csum_tunnel_onoff,
3816                 (void *)&cmd_csum_tunnel_portid,
3817                 NULL,
3818         },
3819 };
3820
3821 /* *** ENABLE HARDWARE SEGMENTATION IN TX NON-TUNNELED PACKETS *** */
3822 struct cmd_tso_set_result {
3823         cmdline_fixed_string_t tso;
3824         cmdline_fixed_string_t mode;
3825         uint16_t tso_segsz;
3826         portid_t port_id;
3827 };
3828
3829 static void
3830 cmd_tso_set_parsed(void *parsed_result,
3831                        __attribute__((unused)) struct cmdline *cl,
3832                        __attribute__((unused)) void *data)
3833 {
3834         struct cmd_tso_set_result *res = parsed_result;
3835         struct rte_eth_dev_info dev_info;
3836
3837         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3838                 return;
3839
3840         if (!strcmp(res->mode, "set"))
3841                 ports[res->port_id].tso_segsz = res->tso_segsz;
3842
3843         if (ports[res->port_id].tso_segsz == 0)
3844                 printf("TSO for non-tunneled packets is disabled\n");
3845         else
3846                 printf("TSO segment size for non-tunneled packets is %d\n",
3847                         ports[res->port_id].tso_segsz);
3848
3849         /* display warnings if configuration is not supported by the NIC */
3850         rte_eth_dev_info_get(res->port_id, &dev_info);
3851         if ((ports[res->port_id].tso_segsz != 0) &&
3852                 (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) == 0) {
3853                 printf("Warning: TSO enabled but not "
3854                         "supported by port %d\n", res->port_id);
3855         }
3856 }
3857
3858 cmdline_parse_token_string_t cmd_tso_set_tso =
3859         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3860                                 tso, "tso");
3861 cmdline_parse_token_string_t cmd_tso_set_mode =
3862         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3863                                 mode, "set");
3864 cmdline_parse_token_num_t cmd_tso_set_tso_segsz =
3865         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3866                                 tso_segsz, UINT16);
3867 cmdline_parse_token_num_t cmd_tso_set_portid =
3868         TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result,
3869                                 port_id, UINT16);
3870
3871 cmdline_parse_inst_t cmd_tso_set = {
3872         .f = cmd_tso_set_parsed,
3873         .data = NULL,
3874         .help_str = "tso set <tso_segsz> <port_id>: "
3875                 "Set TSO segment size of non-tunneled packets for csum engine "
3876                 "(0 to disable)",
3877         .tokens = {
3878                 (void *)&cmd_tso_set_tso,
3879                 (void *)&cmd_tso_set_mode,
3880                 (void *)&cmd_tso_set_tso_segsz,
3881                 (void *)&cmd_tso_set_portid,
3882                 NULL,
3883         },
3884 };
3885
3886 cmdline_parse_token_string_t cmd_tso_show_mode =
3887         TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result,
3888                                 mode, "show");
3889
3890
3891 cmdline_parse_inst_t cmd_tso_show = {
3892         .f = cmd_tso_set_parsed,
3893         .data = NULL,
3894         .help_str = "tso show <port_id>: "
3895                 "Show TSO segment size of non-tunneled packets for csum engine",
3896         .tokens = {
3897                 (void *)&cmd_tso_set_tso,
3898                 (void *)&cmd_tso_show_mode,
3899                 (void *)&cmd_tso_set_portid,
3900                 NULL,
3901         },
3902 };
3903
3904 /* *** ENABLE HARDWARE SEGMENTATION IN TX TUNNELED PACKETS *** */
3905 struct cmd_tunnel_tso_set_result {
3906         cmdline_fixed_string_t tso;
3907         cmdline_fixed_string_t mode;
3908         uint16_t tso_segsz;
3909         portid_t port_id;
3910 };
3911
3912 static void
3913 check_tunnel_tso_nic_support(portid_t port_id)
3914 {
3915         struct rte_eth_dev_info dev_info;
3916
3917         rte_eth_dev_info_get(port_id, &dev_info);
3918         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO))
3919                 printf("Warning: TSO enabled but VXLAN TUNNEL TSO not "
3920                        "supported by port %d\n", port_id);
3921         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO))
3922                 printf("Warning: TSO enabled but GRE TUNNEL TSO not "
3923                         "supported by port %d\n", port_id);
3924         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO))
3925                 printf("Warning: TSO enabled but IPIP TUNNEL TSO not "
3926                        "supported by port %d\n", port_id);
3927         if (!(dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO))
3928                 printf("Warning: TSO enabled but GENEVE TUNNEL TSO not "
3929                        "supported by port %d\n", port_id);
3930 }
3931
3932 static void
3933 cmd_tunnel_tso_set_parsed(void *parsed_result,
3934                           __attribute__((unused)) struct cmdline *cl,
3935                           __attribute__((unused)) void *data)
3936 {
3937         struct cmd_tunnel_tso_set_result *res = parsed_result;
3938
3939         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
3940                 return;
3941
3942         if (!strcmp(res->mode, "set"))
3943                 ports[res->port_id].tunnel_tso_segsz = res->tso_segsz;
3944
3945         if (ports[res->port_id].tunnel_tso_segsz == 0)
3946                 printf("TSO for tunneled packets is disabled\n");
3947         else {
3948                 printf("TSO segment size for tunneled packets is %d\n",
3949                         ports[res->port_id].tunnel_tso_segsz);
3950
3951                 /* Below conditions are needed to make it work:
3952                  * (1) tunnel TSO is supported by the NIC;
3953                  * (2) "csum parse_tunnel" must be set so that tunneled pkts
3954                  * are recognized;
3955                  * (3) for tunneled pkts with outer L3 of IPv4,
3956                  * "csum set outer-ip" must be set to hw, because after tso,
3957                  * total_len of outer IP header is changed, and the checksum
3958                  * of outer IP header calculated by sw should be wrong; that
3959                  * is not necessary for IPv6 tunneled pkts because there's no
3960                  * checksum in IP header anymore.
3961                  */
3962                 check_tunnel_tso_nic_support(res->port_id);
3963
3964                 if (!(ports[res->port_id].tx_ol_flags &
3965                       TESTPMD_TX_OFFLOAD_PARSE_TUNNEL))
3966                         printf("Warning: csum parse_tunnel must be set "
3967                                 "so that tunneled packets are recognized\n");
3968                 if (!(ports[res->port_id].tx_ol_flags &
3969                       TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
3970                         printf("Warning: csum set outer-ip must be set to hw "
3971                                 "if outer L3 is IPv4; not necessary for IPv6\n");
3972         }
3973 }
3974
3975 cmdline_parse_token_string_t cmd_tunnel_tso_set_tso =
3976         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3977                                 tso, "tunnel_tso");
3978 cmdline_parse_token_string_t cmd_tunnel_tso_set_mode =
3979         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
3980                                 mode, "set");
3981 cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz =
3982         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3983                                 tso_segsz, UINT16);
3984 cmdline_parse_token_num_t cmd_tunnel_tso_set_portid =
3985         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result,
3986                                 port_id, UINT16);
3987
3988 cmdline_parse_inst_t cmd_tunnel_tso_set = {
3989         .f = cmd_tunnel_tso_set_parsed,
3990         .data = NULL,
3991         .help_str = "tunnel_tso set <tso_segsz> <port_id>: "
3992                 "Set TSO segment size of tunneled packets for csum engine "
3993                 "(0 to disable)",
3994         .tokens = {
3995                 (void *)&cmd_tunnel_tso_set_tso,
3996                 (void *)&cmd_tunnel_tso_set_mode,
3997                 (void *)&cmd_tunnel_tso_set_tso_segsz,
3998                 (void *)&cmd_tunnel_tso_set_portid,
3999                 NULL,
4000         },
4001 };
4002
4003 cmdline_parse_token_string_t cmd_tunnel_tso_show_mode =
4004         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_tso_set_result,
4005                                 mode, "show");
4006
4007
4008 cmdline_parse_inst_t cmd_tunnel_tso_show = {
4009         .f = cmd_tunnel_tso_set_parsed,
4010         .data = NULL,
4011         .help_str = "tunnel_tso show <port_id> "
4012                 "Show TSO segment size of tunneled packets for csum engine",
4013         .tokens = {
4014                 (void *)&cmd_tunnel_tso_set_tso,
4015                 (void *)&cmd_tunnel_tso_show_mode,
4016                 (void *)&cmd_tunnel_tso_set_portid,
4017                 NULL,
4018         },
4019 };
4020
4021 /* *** SET GRO FOR A PORT *** */
4022 struct cmd_gro_enable_result {
4023         cmdline_fixed_string_t cmd_set;
4024         cmdline_fixed_string_t cmd_port;
4025         cmdline_fixed_string_t cmd_keyword;
4026         cmdline_fixed_string_t cmd_onoff;
4027         portid_t cmd_pid;
4028 };
4029
4030 static void
4031 cmd_gro_enable_parsed(void *parsed_result,
4032                 __attribute__((unused)) struct cmdline *cl,
4033                 __attribute__((unused)) void *data)
4034 {
4035         struct cmd_gro_enable_result *res;
4036
4037         res = parsed_result;
4038         if (!strcmp(res->cmd_keyword, "gro"))
4039                 setup_gro(res->cmd_onoff, res->cmd_pid);
4040 }
4041
4042 cmdline_parse_token_string_t cmd_gro_enable_set =
4043         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4044                         cmd_set, "set");
4045 cmdline_parse_token_string_t cmd_gro_enable_port =
4046         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4047                         cmd_keyword, "port");
4048 cmdline_parse_token_num_t cmd_gro_enable_pid =
4049         TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result,
4050                         cmd_pid, UINT16);
4051 cmdline_parse_token_string_t cmd_gro_enable_keyword =
4052         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4053                         cmd_keyword, "gro");
4054 cmdline_parse_token_string_t cmd_gro_enable_onoff =
4055         TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result,
4056                         cmd_onoff, "on#off");
4057
4058 cmdline_parse_inst_t cmd_gro_enable = {
4059         .f = cmd_gro_enable_parsed,
4060         .data = NULL,
4061         .help_str = "set port <port_id> gro on|off",
4062         .tokens = {
4063                 (void *)&cmd_gro_enable_set,
4064                 (void *)&cmd_gro_enable_port,
4065                 (void *)&cmd_gro_enable_pid,
4066                 (void *)&cmd_gro_enable_keyword,
4067                 (void *)&cmd_gro_enable_onoff,
4068                 NULL,
4069         },
4070 };
4071
4072 /* *** DISPLAY GRO CONFIGURATION *** */
4073 struct cmd_gro_show_result {
4074         cmdline_fixed_string_t cmd_show;
4075         cmdline_fixed_string_t cmd_port;
4076         cmdline_fixed_string_t cmd_keyword;
4077         portid_t cmd_pid;
4078 };
4079
4080 static void
4081 cmd_gro_show_parsed(void *parsed_result,
4082                 __attribute__((unused)) struct cmdline *cl,
4083                 __attribute__((unused)) void *data)
4084 {
4085         struct cmd_gro_show_result *res;
4086
4087         res = parsed_result;
4088         if (!strcmp(res->cmd_keyword, "gro"))
4089                 show_gro(res->cmd_pid);
4090 }
4091
4092 cmdline_parse_token_string_t cmd_gro_show_show =
4093         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4094                         cmd_show, "show");
4095 cmdline_parse_token_string_t cmd_gro_show_port =
4096         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4097                         cmd_port, "port");
4098 cmdline_parse_token_num_t cmd_gro_show_pid =
4099         TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result,
4100                         cmd_pid, UINT16);
4101 cmdline_parse_token_string_t cmd_gro_show_keyword =
4102         TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result,
4103                         cmd_keyword, "gro");
4104
4105 cmdline_parse_inst_t cmd_gro_show = {
4106         .f = cmd_gro_show_parsed,
4107         .data = NULL,
4108         .help_str = "show port <port_id> gro",
4109         .tokens = {
4110                 (void *)&cmd_gro_show_show,
4111                 (void *)&cmd_gro_show_port,
4112                 (void *)&cmd_gro_show_pid,
4113                 (void *)&cmd_gro_show_keyword,
4114                 NULL,
4115         },
4116 };
4117
4118 /* *** SET FLUSH CYCLES FOR GRO *** */
4119 struct cmd_gro_flush_result {
4120         cmdline_fixed_string_t cmd_set;
4121         cmdline_fixed_string_t cmd_keyword;
4122         cmdline_fixed_string_t cmd_flush;
4123         uint8_t cmd_cycles;
4124 };
4125
4126 static void
4127 cmd_gro_flush_parsed(void *parsed_result,
4128                 __attribute__((unused)) struct cmdline *cl,
4129                 __attribute__((unused)) void *data)
4130 {
4131         struct cmd_gro_flush_result *res;
4132
4133         res = parsed_result;
4134         if ((!strcmp(res->cmd_keyword, "gro")) &&
4135                         (!strcmp(res->cmd_flush, "flush")))
4136                 setup_gro_flush_cycles(res->cmd_cycles);
4137 }
4138
4139 cmdline_parse_token_string_t cmd_gro_flush_set =
4140         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4141                         cmd_set, "set");
4142 cmdline_parse_token_string_t cmd_gro_flush_keyword =
4143         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4144                         cmd_keyword, "gro");
4145 cmdline_parse_token_string_t cmd_gro_flush_flush =
4146         TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result,
4147                         cmd_flush, "flush");
4148 cmdline_parse_token_num_t cmd_gro_flush_cycles =
4149         TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result,
4150                         cmd_cycles, UINT8);
4151
4152 cmdline_parse_inst_t cmd_gro_flush = {
4153         .f = cmd_gro_flush_parsed,
4154         .data = NULL,
4155         .help_str = "set gro flush <cycles>",
4156         .tokens = {
4157                 (void *)&cmd_gro_flush_set,
4158                 (void *)&cmd_gro_flush_keyword,
4159                 (void *)&cmd_gro_flush_flush,
4160                 (void *)&cmd_gro_flush_cycles,
4161                 NULL,
4162         },
4163 };
4164
4165 /* *** ENABLE/DISABLE GSO *** */
4166 struct cmd_gso_enable_result {
4167         cmdline_fixed_string_t cmd_set;
4168         cmdline_fixed_string_t cmd_port;
4169         cmdline_fixed_string_t cmd_keyword;
4170         cmdline_fixed_string_t cmd_mode;
4171         portid_t cmd_pid;
4172 };
4173
4174 static void
4175 cmd_gso_enable_parsed(void *parsed_result,
4176                 __attribute__((unused)) struct cmdline *cl,
4177                 __attribute__((unused)) void *data)
4178 {
4179         struct cmd_gso_enable_result *res;
4180
4181         res = parsed_result;
4182         if (!strcmp(res->cmd_keyword, "gso"))
4183                 setup_gso(res->cmd_mode, res->cmd_pid);
4184 }
4185
4186 cmdline_parse_token_string_t cmd_gso_enable_set =
4187         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4188                         cmd_set, "set");
4189 cmdline_parse_token_string_t cmd_gso_enable_port =
4190         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4191                         cmd_port, "port");
4192 cmdline_parse_token_string_t cmd_gso_enable_keyword =
4193         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4194                         cmd_keyword, "gso");
4195 cmdline_parse_token_string_t cmd_gso_enable_mode =
4196         TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
4197                         cmd_mode, "on#off");
4198 cmdline_parse_token_num_t cmd_gso_enable_pid =
4199         TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
4200                         cmd_pid, UINT16);
4201
4202 cmdline_parse_inst_t cmd_gso_enable = {
4203         .f = cmd_gso_enable_parsed,
4204         .data = NULL,
4205         .help_str = "set port <port_id> gso on|off",
4206         .tokens = {
4207                 (void *)&cmd_gso_enable_set,
4208                 (void *)&cmd_gso_enable_port,
4209                 (void *)&cmd_gso_enable_pid,
4210                 (void *)&cmd_gso_enable_keyword,
4211                 (void *)&cmd_gso_enable_mode,
4212                 NULL,
4213         },
4214 };
4215
4216 /* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
4217 struct cmd_gso_size_result {
4218         cmdline_fixed_string_t cmd_set;
4219         cmdline_fixed_string_t cmd_keyword;
4220         cmdline_fixed_string_t cmd_segsz;
4221         uint16_t cmd_size;
4222 };
4223
4224 static void
4225 cmd_gso_size_parsed(void *parsed_result,
4226                        __attribute__((unused)) struct cmdline *cl,
4227                        __attribute__((unused)) void *data)
4228 {
4229         struct cmd_gso_size_result *res = parsed_result;
4230
4231         if (test_done == 0) {
4232                 printf("Before setting GSO segsz, please first"
4233                                 " stop fowarding\n");
4234                 return;
4235         }
4236
4237         if (!strcmp(res->cmd_keyword, "gso") &&
4238                         !strcmp(res->cmd_segsz, "segsz")) {
4239                 if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
4240                         printf("gso_size should be larger than %zu."
4241                                         " Please input a legal value\n",
4242                                         RTE_GSO_SEG_SIZE_MIN);
4243                 else
4244                         gso_max_segment_size = res->cmd_size;
4245         }
4246 }
4247
4248 cmdline_parse_token_string_t cmd_gso_size_set =
4249         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4250                                 cmd_set, "set");
4251 cmdline_parse_token_string_t cmd_gso_size_keyword =
4252         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4253                                 cmd_keyword, "gso");
4254 cmdline_parse_token_string_t cmd_gso_size_segsz =
4255         TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
4256                                 cmd_segsz, "segsz");
4257 cmdline_parse_token_num_t cmd_gso_size_size =
4258         TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
4259                                 cmd_size, UINT16);
4260
4261 cmdline_parse_inst_t cmd_gso_size = {
4262         .f = cmd_gso_size_parsed,
4263         .data = NULL,
4264         .help_str = "set gso segsz <length>",
4265         .tokens = {
4266                 (void *)&cmd_gso_size_set,
4267                 (void *)&cmd_gso_size_keyword,
4268                 (void *)&cmd_gso_size_segsz,
4269                 (void *)&cmd_gso_size_size,
4270                 NULL,
4271         },
4272 };
4273
4274 /* *** SHOW GSO CONFIGURATION *** */
4275 struct cmd_gso_show_result {
4276         cmdline_fixed_string_t cmd_show;
4277         cmdline_fixed_string_t cmd_port;
4278         cmdline_fixed_string_t cmd_keyword;
4279         portid_t cmd_pid;
4280 };
4281
4282 static void
4283 cmd_gso_show_parsed(void *parsed_result,
4284                        __attribute__((unused)) struct cmdline *cl,
4285                        __attribute__((unused)) void *data)
4286 {
4287         struct cmd_gso_show_result *res = parsed_result;
4288
4289         if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
4290                 printf("invalid port id %u\n", res->cmd_pid);
4291                 return;
4292         }
4293         if (!strcmp(res->cmd_keyword, "gso")) {
4294                 if (gso_ports[res->cmd_pid].enable) {
4295                         printf("Max GSO'd packet size: %uB\n"
4296                                         "Supported GSO types: TCP/IPv4, "
4297                                         "VxLAN with inner TCP/IPv4 packet, "
4298                                         "GRE with inner TCP/IPv4  packet\n",
4299                                         gso_max_segment_size);
4300                 } else
4301                         printf("GSO is not enabled on Port %u\n", res->cmd_pid);
4302         }
4303 }
4304
4305 cmdline_parse_token_string_t cmd_gso_show_show =
4306 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4307                 cmd_show, "show");
4308 cmdline_parse_token_string_t cmd_gso_show_port =
4309 TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4310                 cmd_port, "port");
4311 cmdline_parse_token_string_t cmd_gso_show_keyword =
4312         TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
4313                                 cmd_keyword, "gso");
4314 cmdline_parse_token_num_t cmd_gso_show_pid =
4315         TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
4316                                 cmd_pid, UINT16);
4317
4318 cmdline_parse_inst_t cmd_gso_show = {
4319         .f = cmd_gso_show_parsed,
4320         .data = NULL,
4321         .help_str = "show port <port_id> gso",
4322         .tokens = {
4323                 (void *)&cmd_gso_show_show,
4324                 (void *)&cmd_gso_show_port,
4325                 (void *)&cmd_gso_show_pid,
4326                 (void *)&cmd_gso_show_keyword,
4327                 NULL,
4328         },
4329 };
4330
4331 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
4332 struct cmd_set_flush_rx {
4333         cmdline_fixed_string_t set;
4334         cmdline_fixed_string_t flush_rx;
4335         cmdline_fixed_string_t mode;
4336 };
4337
4338 static void
4339 cmd_set_flush_rx_parsed(void *parsed_result,
4340                 __attribute__((unused)) struct cmdline *cl,
4341                 __attribute__((unused)) void *data)
4342 {
4343         struct cmd_set_flush_rx *res = parsed_result;
4344         no_flush_rx = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4345 }
4346
4347 cmdline_parse_token_string_t cmd_setflushrx_set =
4348         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4349                         set, "set");
4350 cmdline_parse_token_string_t cmd_setflushrx_flush_rx =
4351         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4352                         flush_rx, "flush_rx");
4353 cmdline_parse_token_string_t cmd_setflushrx_mode =
4354         TOKEN_STRING_INITIALIZER(struct cmd_set_flush_rx,
4355                         mode, "on#off");
4356
4357
4358 cmdline_parse_inst_t cmd_set_flush_rx = {
4359         .f = cmd_set_flush_rx_parsed,
4360         .help_str = "set flush_rx on|off: Enable/Disable flush on rx streams",
4361         .data = NULL,
4362         .tokens = {
4363                 (void *)&cmd_setflushrx_set,
4364                 (void *)&cmd_setflushrx_flush_rx,
4365                 (void *)&cmd_setflushrx_mode,
4366                 NULL,
4367         },
4368 };
4369
4370 /* *** ENABLE/DISABLE LINK STATUS CHECK *** */
4371 struct cmd_set_link_check {
4372         cmdline_fixed_string_t set;
4373         cmdline_fixed_string_t link_check;
4374         cmdline_fixed_string_t mode;
4375 };
4376
4377 static void
4378 cmd_set_link_check_parsed(void *parsed_result,
4379                 __attribute__((unused)) struct cmdline *cl,
4380                 __attribute__((unused)) void *data)
4381 {
4382         struct cmd_set_link_check *res = parsed_result;
4383         no_link_check = (uint8_t)((strcmp(res->mode, "on") == 0) ? 0 : 1);
4384 }
4385
4386 cmdline_parse_token_string_t cmd_setlinkcheck_set =
4387         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4388                         set, "set");
4389 cmdline_parse_token_string_t cmd_setlinkcheck_link_check =
4390         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4391                         link_check, "link_check");
4392 cmdline_parse_token_string_t cmd_setlinkcheck_mode =
4393         TOKEN_STRING_INITIALIZER(struct cmd_set_link_check,
4394                         mode, "on#off");
4395
4396
4397 cmdline_parse_inst_t cmd_set_link_check = {
4398         .f = cmd_set_link_check_parsed,
4399         .help_str = "set link_check on|off: Enable/Disable link status check "
4400                     "when starting/stopping a port",
4401         .data = NULL,
4402         .tokens = {
4403                 (void *)&cmd_setlinkcheck_set,
4404                 (void *)&cmd_setlinkcheck_link_check,
4405                 (void *)&cmd_setlinkcheck_mode,
4406                 NULL,
4407         },
4408 };
4409
4410 /* *** SET NIC BYPASS MODE *** */
4411 struct cmd_set_bypass_mode_result {
4412         cmdline_fixed_string_t set;
4413         cmdline_fixed_string_t bypass;
4414         cmdline_fixed_string_t mode;
4415         cmdline_fixed_string_t value;
4416         portid_t port_id;
4417 };
4418
4419 static void
4420 cmd_set_bypass_mode_parsed(void *parsed_result,
4421                 __attribute__((unused)) struct cmdline *cl,
4422                 __attribute__((unused)) void *data)
4423 {
4424         struct cmd_set_bypass_mode_result *res = parsed_result;
4425         portid_t port_id = res->port_id;
4426         int32_t rc = -EINVAL;
4427
4428 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4429         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4430
4431         if (!strcmp(res->value, "bypass"))
4432                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4433         else if (!strcmp(res->value, "isolate"))
4434                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4435         else
4436                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4437
4438         /* Set the bypass mode for the relevant port. */
4439         rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode);
4440 #endif
4441         if (rc != 0)
4442                 printf("\t Failed to set bypass mode for port = %d.\n", port_id);
4443 }
4444
4445 cmdline_parse_token_string_t cmd_setbypass_mode_set =
4446         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4447                         set, "set");
4448 cmdline_parse_token_string_t cmd_setbypass_mode_bypass =
4449         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4450                         bypass, "bypass");
4451 cmdline_parse_token_string_t cmd_setbypass_mode_mode =
4452         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4453                         mode, "mode");
4454 cmdline_parse_token_string_t cmd_setbypass_mode_value =
4455         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result,
4456                         value, "normal#bypass#isolate");
4457 cmdline_parse_token_num_t cmd_setbypass_mode_port =
4458         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result,
4459                                 port_id, UINT16);
4460
4461 cmdline_parse_inst_t cmd_set_bypass_mode = {
4462         .f = cmd_set_bypass_mode_parsed,
4463         .help_str = "set bypass mode normal|bypass|isolate <port_id>: "
4464                     "Set the NIC bypass mode for port_id",
4465         .data = NULL,
4466         .tokens = {
4467                 (void *)&cmd_setbypass_mode_set,
4468                 (void *)&cmd_setbypass_mode_bypass,
4469                 (void *)&cmd_setbypass_mode_mode,
4470                 (void *)&cmd_setbypass_mode_value,
4471                 (void *)&cmd_setbypass_mode_port,
4472                 NULL,
4473         },
4474 };
4475
4476 /* *** SET NIC BYPASS EVENT *** */
4477 struct cmd_set_bypass_event_result {
4478         cmdline_fixed_string_t set;
4479         cmdline_fixed_string_t bypass;
4480         cmdline_fixed_string_t event;
4481         cmdline_fixed_string_t event_value;
4482         cmdline_fixed_string_t mode;
4483         cmdline_fixed_string_t mode_value;
4484         portid_t port_id;
4485 };
4486
4487 static void
4488 cmd_set_bypass_event_parsed(void *parsed_result,
4489                 __attribute__((unused)) struct cmdline *cl,
4490                 __attribute__((unused)) void *data)
4491 {
4492         int32_t rc = -EINVAL;
4493         struct cmd_set_bypass_event_result *res = parsed_result;
4494         portid_t port_id = res->port_id;
4495
4496 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4497         uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4498         uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4499
4500         if (!strcmp(res->event_value, "timeout"))
4501                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT;
4502         else if (!strcmp(res->event_value, "os_on"))
4503                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON;
4504         else if (!strcmp(res->event_value, "os_off"))
4505                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF;
4506         else if (!strcmp(res->event_value, "power_on"))
4507                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON;
4508         else if (!strcmp(res->event_value, "power_off"))
4509                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF;
4510         else
4511                 bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE;
4512
4513         if (!strcmp(res->mode_value, "bypass"))
4514                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS;
4515         else if (!strcmp(res->mode_value, "isolate"))
4516                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE;
4517         else
4518                 bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL;
4519
4520         /* Set the watchdog timeout. */
4521         if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) {
4522
4523                 rc = -EINVAL;
4524                 if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) {
4525                         rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id,
4526                                                            bypass_timeout);
4527                 }
4528                 if (rc != 0) {
4529                         printf("Failed to set timeout value %u "
4530                         "for port %d, errto code: %d.\n",
4531                         bypass_timeout, port_id, rc);
4532                 }
4533         }
4534
4535         /* Set the bypass event to transition to bypass mode. */
4536         rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event,
4537                                               bypass_mode);
4538 #endif
4539
4540         if (rc != 0)
4541                 printf("\t Failed to set bypass event for port = %d.\n",
4542                        port_id);
4543 }
4544
4545 cmdline_parse_token_string_t cmd_setbypass_event_set =
4546         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4547                         set, "set");
4548 cmdline_parse_token_string_t cmd_setbypass_event_bypass =
4549         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4550                         bypass, "bypass");
4551 cmdline_parse_token_string_t cmd_setbypass_event_event =
4552         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4553                         event, "event");
4554 cmdline_parse_token_string_t cmd_setbypass_event_event_value =
4555         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4556                         event_value, "none#timeout#os_off#os_on#power_on#power_off");
4557 cmdline_parse_token_string_t cmd_setbypass_event_mode =
4558         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4559                         mode, "mode");
4560 cmdline_parse_token_string_t cmd_setbypass_event_mode_value =
4561         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result,
4562                         mode_value, "normal#bypass#isolate");
4563 cmdline_parse_token_num_t cmd_setbypass_event_port =
4564         TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result,
4565                                 port_id, UINT16);
4566
4567 cmdline_parse_inst_t cmd_set_bypass_event = {
4568         .f = cmd_set_bypass_event_parsed,
4569         .help_str = "set bypass event none|timeout|os_on|os_off|power_on|"
4570                 "power_off mode normal|bypass|isolate <port_id>: "
4571                 "Set the NIC bypass event mode for port_id",
4572         .data = NULL,
4573         .tokens = {
4574                 (void *)&cmd_setbypass_event_set,
4575                 (void *)&cmd_setbypass_event_bypass,
4576                 (void *)&cmd_setbypass_event_event,
4577                 (void *)&cmd_setbypass_event_event_value,
4578                 (void *)&cmd_setbypass_event_mode,
4579                 (void *)&cmd_setbypass_event_mode_value,
4580                 (void *)&cmd_setbypass_event_port,
4581                 NULL,
4582         },
4583 };
4584
4585
4586 /* *** SET NIC BYPASS TIMEOUT *** */
4587 struct cmd_set_bypass_timeout_result {
4588         cmdline_fixed_string_t set;
4589         cmdline_fixed_string_t bypass;
4590         cmdline_fixed_string_t timeout;
4591         cmdline_fixed_string_t value;
4592 };
4593
4594 static void
4595 cmd_set_bypass_timeout_parsed(void *parsed_result,
4596                 __attribute__((unused)) struct cmdline *cl,
4597                 __attribute__((unused)) void *data)
4598 {
4599         __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result;
4600
4601 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4602         if (!strcmp(res->value, "1.5"))
4603                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC;
4604         else if (!strcmp(res->value, "2"))
4605                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC;
4606         else if (!strcmp(res->value, "3"))
4607                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC;
4608         else if (!strcmp(res->value, "4"))
4609                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC;
4610         else if (!strcmp(res->value, "8"))
4611                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC;
4612         else if (!strcmp(res->value, "16"))
4613                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC;
4614         else if (!strcmp(res->value, "32"))
4615                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC;
4616         else
4617                 bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4618 #endif
4619 }
4620
4621 cmdline_parse_token_string_t cmd_setbypass_timeout_set =
4622         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4623                         set, "set");
4624 cmdline_parse_token_string_t cmd_setbypass_timeout_bypass =
4625         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4626                         bypass, "bypass");
4627 cmdline_parse_token_string_t cmd_setbypass_timeout_timeout =
4628         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4629                         timeout, "timeout");
4630 cmdline_parse_token_string_t cmd_setbypass_timeout_value =
4631         TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result,
4632                         value, "0#1.5#2#3#4#8#16#32");
4633
4634 cmdline_parse_inst_t cmd_set_bypass_timeout = {
4635         .f = cmd_set_bypass_timeout_parsed,
4636         .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: "
4637                 "Set the NIC bypass watchdog timeout in seconds",
4638         .data = NULL,
4639         .tokens = {
4640                 (void *)&cmd_setbypass_timeout_set,
4641                 (void *)&cmd_setbypass_timeout_bypass,
4642                 (void *)&cmd_setbypass_timeout_timeout,
4643                 (void *)&cmd_setbypass_timeout_value,
4644                 NULL,
4645         },
4646 };
4647
4648 /* *** SHOW NIC BYPASS MODE *** */
4649 struct cmd_show_bypass_config_result {
4650         cmdline_fixed_string_t show;
4651         cmdline_fixed_string_t bypass;
4652         cmdline_fixed_string_t config;
4653         portid_t port_id;
4654 };
4655
4656 static void
4657 cmd_show_bypass_config_parsed(void *parsed_result,
4658                 __attribute__((unused)) struct cmdline *cl,
4659                 __attribute__((unused)) void *data)
4660 {
4661         struct cmd_show_bypass_config_result *res = parsed_result;
4662         portid_t port_id = res->port_id;
4663         int rc = -EINVAL;
4664 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
4665         uint32_t event_mode;
4666         uint32_t bypass_mode;
4667         uint32_t timeout = bypass_timeout;
4668         int i;
4669
4670         static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] =
4671                 {"off", "1.5", "2", "3", "4", "8", "16", "32"};
4672         static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] =
4673                 {"UNKNOWN", "normal", "bypass", "isolate"};
4674         static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = {
4675                 "NONE",
4676                 "OS/board on",
4677                 "power supply on",
4678                 "OS/board off",
4679                 "power supply off",
4680                 "timeout"};
4681         int num_events = (sizeof events) / (sizeof events[0]);
4682
4683         /* Display the bypass mode.*/
4684         if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) {
4685                 printf("\tFailed to get bypass mode for port = %d\n", port_id);
4686                 return;
4687         }
4688         else {
4689                 if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode))
4690                         bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4691
4692                 printf("\tbypass mode    = %s\n",  modes[bypass_mode]);
4693         }
4694
4695         /* Display the bypass timeout.*/
4696         if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout))
4697                 timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
4698
4699         printf("\tbypass timeout = %s\n", timeouts[timeout]);
4700
4701         /* Display the bypass events and associated modes. */
4702         for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < num_events; i++) {
4703
4704                 if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) {
4705                         printf("\tFailed to get bypass mode for event = %s\n",
4706                                 events[i]);
4707                 } else {
4708                         if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode))
4709                                 event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE;
4710
4711                         printf("\tbypass event: %-16s = %s\n", events[i],
4712                                 modes[event_mode]);
4713                 }
4714         }
4715 #endif
4716         if (rc != 0)
4717                 printf("\tFailed to get bypass configuration for port = %d\n",
4718                        port_id);
4719 }
4720
4721 cmdline_parse_token_string_t cmd_showbypass_config_show =
4722         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4723                         show, "show");
4724 cmdline_parse_token_string_t cmd_showbypass_config_bypass =
4725         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4726                         bypass, "bypass");
4727 cmdline_parse_token_string_t cmd_showbypass_config_config =
4728         TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result,
4729                         config, "config");
4730 cmdline_parse_token_num_t cmd_showbypass_config_port =
4731         TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result,
4732                                 port_id, UINT16);
4733
4734 cmdline_parse_inst_t cmd_show_bypass_config = {
4735         .f = cmd_show_bypass_config_parsed,
4736         .help_str = "show bypass config <port_id>: "
4737                     "Show the NIC bypass config for port_id",
4738         .data = NULL,
4739         .tokens = {
4740                 (void *)&cmd_showbypass_config_show,
4741                 (void *)&cmd_showbypass_config_bypass,
4742                 (void *)&cmd_showbypass_config_config,
4743                 (void *)&cmd_showbypass_config_port,
4744                 NULL,
4745         },
4746 };
4747
4748 #ifdef RTE_LIBRTE_PMD_BOND
4749 /* *** SET BONDING MODE *** */
4750 struct cmd_set_bonding_mode_result {
4751         cmdline_fixed_string_t set;
4752         cmdline_fixed_string_t bonding;
4753         cmdline_fixed_string_t mode;
4754         uint8_t value;
4755         portid_t port_id;
4756 };
4757
4758 static void cmd_set_bonding_mode_parsed(void *parsed_result,
4759                 __attribute__((unused))  struct cmdline *cl,
4760                 __attribute__((unused)) void *data)
4761 {
4762         struct cmd_set_bonding_mode_result *res = parsed_result;
4763         portid_t port_id = res->port_id;
4764
4765         /* Set the bonding mode for the relevant port. */
4766         if (0 != rte_eth_bond_mode_set(port_id, res->value))
4767                 printf("\t Failed to set bonding mode for port = %d.\n", port_id);
4768 }
4769
4770 cmdline_parse_token_string_t cmd_setbonding_mode_set =
4771 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4772                 set, "set");
4773 cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
4774 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4775                 bonding, "bonding");
4776 cmdline_parse_token_string_t cmd_setbonding_mode_mode =
4777 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
4778                 mode, "mode");
4779 cmdline_parse_token_num_t cmd_setbonding_mode_value =
4780 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4781                 value, UINT8);
4782 cmdline_parse_token_num_t cmd_setbonding_mode_port =
4783 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
4784                 port_id, UINT16);
4785
4786 cmdline_parse_inst_t cmd_set_bonding_mode = {
4787                 .f = cmd_set_bonding_mode_parsed,
4788                 .help_str = "set bonding mode <mode_value> <port_id>: "
4789                         "Set the bonding mode for port_id",
4790                 .data = NULL,
4791                 .tokens = {
4792                                 (void *) &cmd_setbonding_mode_set,
4793                                 (void *) &cmd_setbonding_mode_bonding,
4794                                 (void *) &cmd_setbonding_mode_mode,
4795                                 (void *) &cmd_setbonding_mode_value,
4796                                 (void *) &cmd_setbonding_mode_port,
4797                                 NULL
4798                 }
4799 };
4800
4801 /* *** SET BONDING SLOW_QUEUE SW/HW *** */
4802 struct cmd_set_bonding_lacp_dedicated_queues_result {
4803         cmdline_fixed_string_t set;
4804         cmdline_fixed_string_t bonding;
4805         cmdline_fixed_string_t lacp;
4806         cmdline_fixed_string_t dedicated_queues;
4807         portid_t port_id;
4808         cmdline_fixed_string_t mode;
4809 };
4810
4811 static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
4812                 __attribute__((unused))  struct cmdline *cl,
4813                 __attribute__((unused)) void *data)
4814 {
4815         struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
4816         portid_t port_id = res->port_id;
4817         struct rte_port *port;
4818
4819         port = &ports[port_id];
4820
4821         /** Check if the port is not started **/
4822         if (port->port_status != RTE_PORT_STOPPED) {
4823                 printf("Please stop port %d first\n", port_id);
4824                 return;
4825         }
4826
4827         if (!strcmp(res->mode, "enable")) {
4828                 if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
4829                         printf("Dedicate queues for LACP control packets"
4830                                         " enabled\n");
4831                 else
4832                         printf("Enabling dedicate queues for LACP control "
4833                                         "packets on port %d failed\n", port_id);
4834         } else if (!strcmp(res->mode, "disable")) {
4835                 if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
4836                         printf("Dedicated queues for LACP control packets "
4837                                         "disabled\n");
4838                 else
4839                         printf("Disabling dedicated queues for LACP control "
4840                                         "traffic on port %d failed\n", port_id);
4841         }
4842 }
4843
4844 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
4845 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4846                 set, "set");
4847 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
4848 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4849                 bonding, "bonding");
4850 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
4851 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4852                 lacp, "lacp");
4853 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
4854 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4855                 dedicated_queues, "dedicated_queues");
4856 cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
4857 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4858                 port_id, UINT16);
4859 cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
4860 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
4861                 mode, "enable#disable");
4862
4863 cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
4864                 .f = cmd_set_bonding_lacp_dedicated_queues_parsed,
4865                 .help_str = "set bonding lacp dedicated_queues <port_id> "
4866                         "enable|disable: "
4867                         "Enable/disable dedicated queues for LACP control traffic for port_id",
4868                 .data = NULL,
4869                 .tokens = {
4870                         (void *)&cmd_setbonding_lacp_dedicated_queues_set,
4871                         (void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
4872                         (void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
4873                         (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
4874                         (void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
4875                         (void *)&cmd_setbonding_lacp_dedicated_queues_mode,
4876                         NULL
4877                 }
4878 };
4879
4880 /* *** SET BALANCE XMIT POLICY *** */
4881 struct cmd_set_bonding_balance_xmit_policy_result {
4882         cmdline_fixed_string_t set;
4883         cmdline_fixed_string_t bonding;
4884         cmdline_fixed_string_t balance_xmit_policy;
4885         portid_t port_id;
4886         cmdline_fixed_string_t policy;
4887 };
4888
4889 static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
4890                 __attribute__((unused))  struct cmdline *cl,
4891                 __attribute__((unused)) void *data)
4892 {
4893         struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
4894         portid_t port_id = res->port_id;
4895         uint8_t policy;
4896
4897         if (!strcmp(res->policy, "l2")) {
4898                 policy = BALANCE_XMIT_POLICY_LAYER2;
4899         } else if (!strcmp(res->policy, "l23")) {
4900                 policy = BALANCE_XMIT_POLICY_LAYER23;
4901         } else if (!strcmp(res->policy, "l34")) {
4902                 policy = BALANCE_XMIT_POLICY_LAYER34;
4903         } else {
4904                 printf("\t Invalid xmit policy selection");
4905                 return;
4906         }
4907
4908         /* Set the bonding mode for the relevant port. */
4909         if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) {
4910                 printf("\t Failed to set bonding balance xmit policy for port = %d.\n",
4911                                 port_id);
4912         }
4913 }
4914
4915 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
4916 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4917                 set, "set");
4918 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
4919 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4920                 bonding, "bonding");
4921 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
4922 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4923                 balance_xmit_policy, "balance_xmit_policy");
4924 cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
4925 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4926                 port_id, UINT16);
4927 cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
4928 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
4929                 policy, "l2#l23#l34");
4930
4931 cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
4932                 .f = cmd_set_bonding_balance_xmit_policy_parsed,
4933                 .help_str = "set bonding balance_xmit_policy <port_id> "
4934                         "l2|l23|l34: "
4935                         "Set the bonding balance_xmit_policy for port_id",
4936                 .data = NULL,
4937                 .tokens = {
4938                                 (void *)&cmd_setbonding_balance_xmit_policy_set,
4939                                 (void *)&cmd_setbonding_balance_xmit_policy_bonding,
4940                                 (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
4941                                 (void *)&cmd_setbonding_balance_xmit_policy_port,
4942                                 (void *)&cmd_setbonding_balance_xmit_policy_policy,
4943                                 NULL
4944                 }
4945 };
4946
4947 /* *** SHOW NIC BONDING CONFIGURATION *** */
4948 struct cmd_show_bonding_config_result {
4949         cmdline_fixed_string_t show;
4950         cmdline_fixed_string_t bonding;
4951         cmdline_fixed_string_t config;
4952         portid_t port_id;
4953 };
4954
4955 static void cmd_show_bonding_config_parsed(void *parsed_result,
4956                 __attribute__((unused))  struct cmdline *cl,
4957                 __attribute__((unused)) void *data)
4958 {
4959         struct cmd_show_bonding_config_result *res = parsed_result;
4960         int bonding_mode, agg_mode;
4961         portid_t slaves[RTE_MAX_ETHPORTS];
4962         int num_slaves, num_active_slaves;
4963         int primary_id;
4964         int i;
4965         portid_t port_id = res->port_id;
4966
4967         /* Display the bonding mode.*/
4968         bonding_mode = rte_eth_bond_mode_get(port_id);
4969         if (bonding_mode < 0) {
4970                 printf("\tFailed to get bonding mode for port = %d\n", port_id);
4971                 return;
4972         } else
4973                 printf("\tBonding mode: %d\n", bonding_mode);
4974
4975         if (bonding_mode == BONDING_MODE_BALANCE) {
4976                 int balance_xmit_policy;
4977
4978                 balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id);
4979                 if (balance_xmit_policy < 0) {
4980                         printf("\tFailed to get balance xmit policy for port = %d\n",
4981                                         port_id);
4982                         return;
4983                 } else {
4984                         printf("\tBalance Xmit Policy: ");
4985
4986                         switch (balance_xmit_policy) {
4987                         case BALANCE_XMIT_POLICY_LAYER2:
4988                                 printf("BALANCE_XMIT_POLICY_LAYER2");
4989                                 break;
4990                         case BALANCE_XMIT_POLICY_LAYER23:
4991                                 printf("BALANCE_XMIT_POLICY_LAYER23");
4992                                 break;
4993                         case BALANCE_XMIT_POLICY_LAYER34:
4994                                 printf("BALANCE_XMIT_POLICY_LAYER34");
4995                                 break;
4996                         }
4997                         printf("\n");
4998                 }
4999         }
5000
5001         if (bonding_mode == BONDING_MODE_8023AD) {
5002                 agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id);
5003                 printf("\tIEEE802.3AD Aggregator Mode: ");
5004                 switch (agg_mode) {
5005                 case AGG_BANDWIDTH:
5006                         printf("bandwidth");
5007                         break;
5008                 case AGG_STABLE:
5009                         printf("stable");
5010                         break;
5011                 case AGG_COUNT:
5012                         printf("count");
5013                         break;
5014                 }
5015                 printf("\n");
5016         }
5017
5018         num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS);
5019
5020         if (num_slaves < 0) {
5021                 printf("\tFailed to get slave list for port = %d\n", port_id);
5022                 return;
5023         }
5024         if (num_slaves > 0) {
5025                 printf("\tSlaves (%d): [", num_slaves);
5026                 for (i = 0; i < num_slaves - 1; i++)
5027                         printf("%d ", slaves[i]);
5028
5029                 printf("%d]\n", slaves[num_slaves - 1]);
5030         } else {
5031                 printf("\tSlaves: []\n");
5032
5033         }
5034
5035         num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves,
5036                         RTE_MAX_ETHPORTS);
5037
5038         if (num_active_slaves < 0) {
5039                 printf("\tFailed to get active slave list for port = %d\n", port_id);
5040                 return;
5041         }
5042         if (num_active_slaves > 0) {
5043                 printf("\tActive Slaves (%d): [", num_active_slaves);
5044                 for (i = 0; i < num_active_slaves - 1; i++)
5045                         printf("%d ", slaves[i]);
5046
5047                 printf("%d]\n", slaves[num_active_slaves - 1]);
5048
5049         } else {
5050                 printf("\tActive Slaves: []\n");
5051
5052         }
5053
5054         primary_id = rte_eth_bond_primary_get(port_id);
5055         if (primary_id < 0) {
5056                 printf("\tFailed to get primary slave for port = %d\n", port_id);
5057                 return;
5058         } else
5059                 printf("\tPrimary: [%d]\n", primary_id);
5060
5061 }
5062
5063 cmdline_parse_token_string_t cmd_showbonding_config_show =
5064 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5065                 show, "show");
5066 cmdline_parse_token_string_t cmd_showbonding_config_bonding =
5067 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5068                 bonding, "bonding");
5069 cmdline_parse_token_string_t cmd_showbonding_config_config =
5070 TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
5071                 config, "config");
5072 cmdline_parse_token_num_t cmd_showbonding_config_port =
5073 TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
5074                 port_id, UINT16);
5075
5076 cmdline_parse_inst_t cmd_show_bonding_config = {
5077                 .f = cmd_show_bonding_config_parsed,
5078                 .help_str = "show bonding config <port_id>: "
5079                         "Show the bonding config for port_id",
5080                 .data = NULL,
5081                 .tokens = {
5082                                 (void *)&cmd_showbonding_config_show,
5083                                 (void *)&cmd_showbonding_config_bonding,
5084                                 (void *)&cmd_showbonding_config_config,
5085                                 (void *)&cmd_showbonding_config_port,
5086                                 NULL
5087                 }
5088 };
5089
5090 /* *** SET BONDING PRIMARY *** */
5091 struct cmd_set_bonding_primary_result {
5092         cmdline_fixed_string_t set;
5093         cmdline_fixed_string_t bonding;
5094         cmdline_fixed_string_t primary;
5095         portid_t slave_id;
5096         portid_t port_id;
5097 };
5098
5099 static void cmd_set_bonding_primary_parsed(void *parsed_result,
5100                 __attribute__((unused))  struct cmdline *cl,
5101                 __attribute__((unused)) void *data)
5102 {
5103         struct cmd_set_bonding_primary_result *res = parsed_result;
5104         portid_t master_port_id = res->port_id;
5105         portid_t slave_port_id = res->slave_id;
5106
5107         /* Set the primary slave for a bonded device. */
5108         if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) {
5109                 printf("\t Failed to set primary slave for port = %d.\n",
5110                                 master_port_id);
5111                 return;
5112         }
5113         init_port_config();
5114 }
5115
5116 cmdline_parse_token_string_t cmd_setbonding_primary_set =
5117 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5118                 set, "set");
5119 cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
5120 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5121                 bonding, "bonding");
5122 cmdline_parse_token_string_t cmd_setbonding_primary_primary =
5123 TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
5124                 primary, "primary");
5125 cmdline_parse_token_num_t cmd_setbonding_primary_slave =
5126 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5127                 slave_id, UINT16);
5128 cmdline_parse_token_num_t cmd_setbonding_primary_port =
5129 TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
5130                 port_id, UINT16);
5131
5132 cmdline_parse_inst_t cmd_set_bonding_primary = {
5133                 .f = cmd_set_bonding_primary_parsed,
5134                 .help_str = "set bonding primary <slave_id> <port_id>: "
5135                         "Set the primary slave for port_id",
5136                 .data = NULL,
5137                 .tokens = {
5138                                 (void *)&cmd_setbonding_primary_set,
5139                                 (void *)&cmd_setbonding_primary_bonding,
5140                                 (void *)&cmd_setbonding_primary_primary,
5141                                 (void *)&cmd_setbonding_primary_slave,
5142                                 (void *)&cmd_setbonding_primary_port,
5143                                 NULL
5144                 }
5145 };
5146
5147 /* *** ADD SLAVE *** */
5148 struct cmd_add_bonding_slave_result {
5149         cmdline_fixed_string_t add;
5150         cmdline_fixed_string_t bonding;
5151         cmdline_fixed_string_t slave;
5152         portid_t slave_id;
5153         portid_t port_id;
5154 };
5155
5156 static void cmd_add_bonding_slave_parsed(void *parsed_result,
5157                 __attribute__((unused))  struct cmdline *cl,
5158                 __attribute__((unused)) void *data)
5159 {
5160         struct cmd_add_bonding_slave_result *res = parsed_result;
5161         portid_t master_port_id = res->port_id;
5162         portid_t slave_port_id = res->slave_id;
5163
5164         /* add the slave for a bonded device. */
5165         if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) {
5166                 printf("\t Failed to add slave %d to master port = %d.\n",
5167                                 slave_port_id, master_port_id);
5168                 return;
5169         }
5170         init_port_config();
5171         set_port_slave_flag(slave_port_id);
5172 }
5173
5174 cmdline_parse_token_string_t cmd_addbonding_slave_add =
5175 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5176                 add, "add");
5177 cmdline_parse_token_string_t cmd_addbonding_slave_bonding =
5178 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5179                 bonding, "bonding");
5180 cmdline_parse_token_string_t cmd_addbonding_slave_slave =
5181 TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result,
5182                 slave, "slave");
5183 cmdline_parse_token_num_t cmd_addbonding_slave_slaveid =
5184 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5185                 slave_id, UINT16);
5186 cmdline_parse_token_num_t cmd_addbonding_slave_port =
5187 TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result,
5188                 port_id, UINT16);
5189
5190 cmdline_parse_inst_t cmd_add_bonding_slave = {
5191                 .f = cmd_add_bonding_slave_parsed,
5192                 .help_str = "add bonding slave <slave_id> <port_id>: "
5193                         "Add a slave device to a bonded device",
5194                 .data = NULL,
5195                 .tokens = {
5196                                 (void *)&cmd_addbonding_slave_add,
5197                                 (void *)&cmd_addbonding_slave_bonding,
5198                                 (void *)&cmd_addbonding_slave_slave,
5199                                 (void *)&cmd_addbonding_slave_slaveid,
5200                                 (void *)&cmd_addbonding_slave_port,
5201                                 NULL
5202                 }
5203 };
5204
5205 /* *** REMOVE SLAVE *** */
5206 struct cmd_remove_bonding_slave_result {
5207         cmdline_fixed_string_t remove;
5208         cmdline_fixed_string_t bonding;
5209         cmdline_fixed_string_t slave;
5210         portid_t slave_id;
5211         portid_t port_id;
5212 };
5213
5214 static void cmd_remove_bonding_slave_parsed(void *parsed_result,
5215                 __attribute__((unused))  struct cmdline *cl,
5216                 __attribute__((unused)) void *data)
5217 {
5218         struct cmd_remove_bonding_slave_result *res = parsed_result;
5219         portid_t master_port_id = res->port_id;
5220         portid_t slave_port_id = res->slave_id;
5221
5222         /* remove the slave from a bonded device. */
5223         if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) {
5224                 printf("\t Failed to remove slave %d from master port = %d.\n",
5225                                 slave_port_id, master_port_id);
5226                 return;
5227         }
5228         init_port_config();
5229         clear_port_slave_flag(slave_port_id);
5230 }
5231
5232 cmdline_parse_token_string_t cmd_removebonding_slave_remove =
5233                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5234                                 remove, "remove");
5235 cmdline_parse_token_string_t cmd_removebonding_slave_bonding =
5236                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5237                                 bonding, "bonding");
5238 cmdline_parse_token_string_t cmd_removebonding_slave_slave =
5239                 TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result,
5240                                 slave, "slave");
5241 cmdline_parse_token_num_t cmd_removebonding_slave_slaveid =
5242                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5243                                 slave_id, UINT16);
5244 cmdline_parse_token_num_t cmd_removebonding_slave_port =
5245                 TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result,
5246                                 port_id, UINT16);
5247
5248 cmdline_parse_inst_t cmd_remove_bonding_slave = {
5249                 .f = cmd_remove_bonding_slave_parsed,
5250                 .help_str = "remove bonding slave <slave_id> <port_id>: "
5251                         "Remove a slave device from a bonded device",
5252                 .data = NULL,
5253                 .tokens = {
5254                                 (void *)&cmd_removebonding_slave_remove,
5255                                 (void *)&cmd_removebonding_slave_bonding,
5256                                 (void *)&cmd_removebonding_slave_slave,
5257                                 (void *)&cmd_removebonding_slave_slaveid,
5258                                 (void *)&cmd_removebonding_slave_port,
5259                                 NULL
5260                 }
5261 };
5262
5263 /* *** CREATE BONDED DEVICE *** */
5264 struct cmd_create_bonded_device_result {
5265         cmdline_fixed_string_t create;
5266         cmdline_fixed_string_t bonded;
5267         cmdline_fixed_string_t device;
5268         uint8_t mode;
5269         uint8_t socket;
5270 };
5271
5272 static int bond_dev_num = 0;
5273
5274 static void cmd_create_bonded_device_parsed(void *parsed_result,
5275                 __attribute__((unused))  struct cmdline *cl,
5276                 __attribute__((unused)) void *data)
5277 {
5278         struct cmd_create_bonded_device_result *res = parsed_result;
5279         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
5280         int port_id;
5281
5282         if (test_done == 0) {
5283                 printf("Please stop forwarding first\n");
5284                 return;
5285         }
5286
5287         snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
5288                         bond_dev_num++);
5289
5290         /* Create a new bonded device. */
5291         port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
5292         if (port_id < 0) {
5293                 printf("\t Failed to create bonded device.\n");
5294                 return;
5295         } else {
5296                 printf("Created new bonded device %s on (port %d).\n", ethdev_name,
5297                                 port_id);
5298
5299                 /* Update number of ports */
5300                 nb_ports = rte_eth_dev_count();
5301                 reconfig(port_id, res->socket);
5302                 rte_eth_promiscuous_enable(port_id);
5303         }
5304
5305 }
5306
5307 cmdline_parse_token_string_t cmd_createbonded_device_create =
5308                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5309                                 create, "create");
5310 cmdline_parse_token_string_t cmd_createbonded_device_bonded =
5311                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5312                                 bonded, "bonded");
5313 cmdline_parse_token_string_t cmd_createbonded_device_device =
5314                 TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result,
5315                                 device, "device");
5316 cmdline_parse_token_num_t cmd_createbonded_device_mode =
5317                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5318                                 mode, UINT8);
5319 cmdline_parse_token_num_t cmd_createbonded_device_socket =
5320                 TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result,
5321                                 socket, UINT8);
5322
5323 cmdline_parse_inst_t cmd_create_bonded_device = {
5324                 .f = cmd_create_bonded_device_parsed,
5325                 .help_str = "create bonded device <mode> <socket>: "
5326                         "Create a new bonded device with specific bonding mode and socket",
5327                 .data = NULL,
5328                 .tokens = {
5329                                 (void *)&cmd_createbonded_device_create,
5330                                 (void *)&cmd_createbonded_device_bonded,
5331                                 (void *)&cmd_createbonded_device_device,
5332                                 (void *)&cmd_createbonded_device_mode,
5333                                 (void *)&cmd_createbonded_device_socket,
5334                                 NULL
5335                 }
5336 };
5337
5338 /* *** SET MAC ADDRESS IN BONDED DEVICE *** */
5339 struct cmd_set_bond_mac_addr_result {
5340         cmdline_fixed_string_t set;
5341         cmdline_fixed_string_t bonding;
5342         cmdline_fixed_string_t mac_addr;
5343         uint16_t port_num;
5344         struct ether_addr address;
5345 };
5346
5347 static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
5348                 __attribute__((unused))  struct cmdline *cl,
5349                 __attribute__((unused)) void *data)
5350 {
5351         struct cmd_set_bond_mac_addr_result *res = parsed_result;
5352         int ret;
5353
5354         if (port_id_is_invalid(res->port_num, ENABLED_WARN))
5355                 return;
5356
5357         ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
5358
5359         /* check the return value and print it if is < 0 */
5360         if (ret < 0)
5361                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5362 }
5363
5364 cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
5365                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set");
5366 cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
5367                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding,
5368                                 "bonding");
5369 cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
5370                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr,
5371                                 "mac_addr");
5372 cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
5373                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
5374                                 port_num, UINT16);
5375 cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
5376                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address);
5377
5378 cmdline_parse_inst_t cmd_set_bond_mac_addr = {
5379                 .f = cmd_set_bond_mac_addr_parsed,
5380                 .data = (void *) 0,
5381                 .help_str = "set bonding mac_addr <port_id> <mac_addr>",
5382                 .tokens = {
5383                                 (void *)&cmd_set_bond_mac_addr_set,
5384                                 (void *)&cmd_set_bond_mac_addr_bonding,
5385                                 (void *)&cmd_set_bond_mac_addr_mac,
5386                                 (void *)&cmd_set_bond_mac_addr_portnum,
5387                                 (void *)&cmd_set_bond_mac_addr_addr,
5388                                 NULL
5389                 }
5390 };
5391
5392
5393 /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */
5394 struct cmd_set_bond_mon_period_result {
5395         cmdline_fixed_string_t set;
5396         cmdline_fixed_string_t bonding;
5397         cmdline_fixed_string_t mon_period;
5398         uint16_t port_num;
5399         uint32_t period_ms;
5400 };
5401
5402 static void cmd_set_bond_mon_period_parsed(void *parsed_result,
5403                 __attribute__((unused))  struct cmdline *cl,
5404                 __attribute__((unused)) void *data)
5405 {
5406         struct cmd_set_bond_mon_period_result *res = parsed_result;
5407         int ret;
5408
5409         if (res->port_num >= nb_ports) {
5410                 printf("Port id %d must be less than %d\n", res->port_num, nb_ports);
5411                 return;
5412         }
5413
5414         ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
5415
5416         /* check the return value and print it if is < 0 */
5417         if (ret < 0)
5418                 printf("set_bond_mac_addr error: (%s)\n", strerror(-ret));
5419 }
5420
5421 cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
5422                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5423                                 set, "set");
5424 cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
5425                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5426                                 bonding, "bonding");
5427 cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
5428                 TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
5429                                 mon_period,     "mon_period");
5430 cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
5431                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5432                                 port_num, UINT16);
5433 cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
5434                 TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
5435                                 period_ms, UINT32);
5436
5437 cmdline_parse_inst_t cmd_set_bond_mon_period = {
5438                 .f = cmd_set_bond_mon_period_parsed,
5439                 .data = (void *) 0,
5440                 .help_str = "set bonding mon_period <port_id> <period_ms>",
5441                 .tokens = {
5442                                 (void *)&cmd_set_bond_mon_period_set,
5443                                 (void *)&cmd_set_bond_mon_period_bonding,
5444                                 (void *)&cmd_set_bond_mon_period_mon_period,
5445                                 (void *)&cmd_set_bond_mon_period_portnum,
5446                                 (void *)&cmd_set_bond_mon_period_period_ms,
5447                                 NULL
5448                 }
5449 };
5450
5451
5452
5453 struct cmd_set_bonding_agg_mode_policy_result {
5454         cmdline_fixed_string_t set;
5455         cmdline_fixed_string_t bonding;
5456         cmdline_fixed_string_t agg_mode;
5457         uint16_t port_num;
5458         cmdline_fixed_string_t policy;
5459 };
5460
5461
5462 static void
5463 cmd_set_bonding_agg_mode(void *parsed_result,
5464                 __attribute__((unused)) struct cmdline *cl,
5465                 __attribute__((unused)) void *data)
5466 {
5467         struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
5468         uint8_t policy = AGG_BANDWIDTH;
5469
5470         if (res->port_num >= nb_ports) {
5471                 printf("Port id %d must be less than %d\n",
5472                                 res->port_num, nb_ports);
5473                 return;
5474         }
5475
5476         if (!strcmp(res->policy, "bandwidth"))
5477                 policy = AGG_BANDWIDTH;
5478         else if (!strcmp(res->policy, "stable"))
5479                 policy = AGG_STABLE;
5480         else if (!strcmp(res->policy, "count"))
5481                 policy = AGG_COUNT;
5482
5483         rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
5484 }
5485
5486
5487 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
5488         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5489                                 set, "set");
5490 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
5491         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5492                                 bonding, "bonding");
5493
5494 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
5495         TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5496                                 agg_mode, "agg_mode");
5497
5498 cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
5499         TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
5500                                 port_num, UINT16);
5501
5502 cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
5503         TOKEN_STRING_INITIALIZER(
5504                         struct cmd_set_bonding_balance_xmit_policy_result,
5505                 policy, "stable#bandwidth#count");
5506
5507 cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
5508         .f = cmd_set_bonding_agg_mode,
5509         .data = (void *) 0,
5510         .help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
5511         .tokens = {
5512                         (void *)&cmd_set_bonding_agg_mode_set,
5513                         (void *)&cmd_set_bonding_agg_mode_bonding,
5514                         (void *)&cmd_set_bonding_agg_mode_agg_mode,
5515                         (void *)&cmd_set_bonding_agg_mode_portnum,
5516                         (void *)&cmd_set_bonding_agg_mode_policy_string,
5517                         NULL
5518                 }
5519 };
5520
5521
5522 #endif /* RTE_LIBRTE_PMD_BOND */
5523
5524 /* *** SET FORWARDING MODE *** */
5525 struct cmd_set_fwd_mode_result {
5526         cmdline_fixed_string_t set;
5527         cmdline_fixed_string_t fwd;
5528         cmdline_fixed_string_t mode;
5529 };
5530
5531 static void cmd_set_fwd_mode_parsed(void *parsed_result,
5532                                     __attribute__((unused)) struct cmdline *cl,
5533                                     __attribute__((unused)) void *data)
5534 {
5535         struct cmd_set_fwd_mode_result *res = parsed_result;
5536
5537         retry_enabled = 0;
5538         set_pkt_forwarding_mode(res->mode);
5539 }
5540
5541 cmdline_parse_token_string_t cmd_setfwd_set =
5542         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set");
5543 cmdline_parse_token_string_t cmd_setfwd_fwd =
5544         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd");
5545 cmdline_parse_token_string_t cmd_setfwd_mode =
5546         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode,
5547                 "" /* defined at init */);
5548
5549 cmdline_parse_inst_t cmd_set_fwd_mode = {
5550         .f = cmd_set_fwd_mode_parsed,
5551         .data = NULL,
5552         .help_str = NULL, /* defined at init */
5553         .tokens = {
5554                 (void *)&cmd_setfwd_set,
5555                 (void *)&cmd_setfwd_fwd,
5556                 (void *)&cmd_setfwd_mode,
5557                 NULL,
5558         },
5559 };
5560
5561 static void cmd_set_fwd_mode_init(void)
5562 {
5563         char *modes, *c;
5564         static char token[128];
5565         static char help[256];
5566         cmdline_parse_token_string_t *token_struct;
5567
5568         modes = list_pkt_forwarding_modes();
5569         snprintf(help, sizeof(help), "set fwd %s: "
5570                 "Set packet forwarding mode", modes);
5571         cmd_set_fwd_mode.help_str = help;
5572
5573         /* string token separator is # */
5574         for (c = token; *modes != '\0'; modes++)
5575                 if (*modes == '|')
5576                         *c++ = '#';
5577                 else
5578                         *c++ = *modes;
5579         token_struct = (cmdline_parse_token_string_t*)cmd_set_fwd_mode.tokens[2];
5580         token_struct->string_data.str = token;
5581 }
5582
5583 /* *** SET RETRY FORWARDING MODE *** */
5584 struct cmd_set_fwd_retry_mode_result {
5585         cmdline_fixed_string_t set;
5586         cmdline_fixed_string_t fwd;
5587         cmdline_fixed_string_t mode;
5588         cmdline_fixed_string_t retry;
5589 };
5590
5591 static void cmd_set_fwd_retry_mode_parsed(void *parsed_result,
5592                             __attribute__((unused)) struct cmdline *cl,
5593                             __attribute__((unused)) void *data)
5594 {
5595         struct cmd_set_fwd_retry_mode_result *res = parsed_result;
5596
5597         retry_enabled = 1;
5598         set_pkt_forwarding_mode(res->mode);
5599 }
5600
5601 cmdline_parse_token_string_t cmd_setfwd_retry_set =
5602         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5603                         set, "set");
5604 cmdline_parse_token_string_t cmd_setfwd_retry_fwd =
5605         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5606                         fwd, "fwd");
5607 cmdline_parse_token_string_t cmd_setfwd_retry_mode =
5608         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5609                         mode,
5610                 "" /* defined at init */);
5611 cmdline_parse_token_string_t cmd_setfwd_retry_retry =
5612         TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_retry_mode_result,
5613                         retry, "retry");
5614
5615 cmdline_parse_inst_t cmd_set_fwd_retry_mode = {
5616         .f = cmd_set_fwd_retry_mode_parsed,
5617         .data = NULL,
5618         .help_str = NULL, /* defined at init */
5619         .tokens = {
5620                 (void *)&cmd_setfwd_retry_set,
5621                 (void *)&cmd_setfwd_retry_fwd,
5622                 (void *)&cmd_setfwd_retry_mode,
5623                 (void *)&cmd_setfwd_retry_retry,
5624                 NULL,
5625         },
5626 };
5627
5628 static void cmd_set_fwd_retry_mode_init(void)
5629 {
5630         char *modes, *c;
5631         static char token[128];
5632         static char help[256];
5633         cmdline_parse_token_string_t *token_struct;
5634
5635         modes = list_pkt_forwarding_retry_modes();
5636         snprintf(help, sizeof(help), "set fwd %s retry: "
5637                 "Set packet forwarding mode with retry", modes);
5638         cmd_set_fwd_retry_mode.help_str = help;
5639
5640         /* string token separator is # */
5641         for (c = token; *modes != '\0'; modes++)
5642                 if (*modes == '|')
5643                         *c++ = '#';
5644                 else
5645                         *c++ = *modes;
5646         token_struct = (cmdline_parse_token_string_t *)
5647                 cmd_set_fwd_retry_mode.tokens[2];
5648         token_struct->string_data.str = token;
5649 }
5650
5651 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
5652 struct cmd_set_burst_tx_retry_result {
5653         cmdline_fixed_string_t set;
5654         cmdline_fixed_string_t burst;
5655         cmdline_fixed_string_t tx;
5656         cmdline_fixed_string_t delay;
5657         uint32_t time;
5658         cmdline_fixed_string_t retry;
5659         uint32_t retry_num;
5660 };
5661
5662 static void cmd_set_burst_tx_retry_parsed(void *parsed_result,
5663                                         __attribute__((unused)) struct cmdline *cl,
5664                                         __attribute__((unused)) void *data)
5665 {
5666         struct cmd_set_burst_tx_retry_result *res = parsed_result;
5667
5668         if (!strcmp(res->set, "set") && !strcmp(res->burst, "burst")
5669                 && !strcmp(res->tx, "tx")) {
5670                 if (!strcmp(res->delay, "delay"))
5671                         burst_tx_delay_time = res->time;
5672                 if (!strcmp(res->retry, "retry"))
5673                         burst_tx_retry_num = res->retry_num;
5674         }
5675
5676 }
5677
5678 cmdline_parse_token_string_t cmd_set_burst_tx_retry_set =
5679         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, set, "set");
5680 cmdline_parse_token_string_t cmd_set_burst_tx_retry_burst =
5681         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, burst,
5682                                  "burst");
5683 cmdline_parse_token_string_t cmd_set_burst_tx_retry_tx =
5684         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, tx, "tx");
5685 cmdline_parse_token_string_t cmd_set_burst_tx_retry_delay =
5686         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, delay, "delay");
5687 cmdline_parse_token_num_t cmd_set_burst_tx_retry_time =
5688         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, time, UINT32);
5689 cmdline_parse_token_string_t cmd_set_burst_tx_retry_retry =
5690         TOKEN_STRING_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry, "retry");
5691 cmdline_parse_token_num_t cmd_set_burst_tx_retry_retry_num =
5692         TOKEN_NUM_INITIALIZER(struct cmd_set_burst_tx_retry_result, retry_num, UINT32);
5693
5694 cmdline_parse_inst_t cmd_set_burst_tx_retry = {
5695         .f = cmd_set_burst_tx_retry_parsed,
5696         .help_str = "set burst tx delay <delay_usec> retry <num_retry>",
5697         .tokens = {
5698                 (void *)&cmd_set_burst_tx_retry_set,
5699                 (void *)&cmd_set_burst_tx_retry_burst,
5700                 (void *)&cmd_set_burst_tx_retry_tx,
5701                 (void *)&cmd_set_burst_tx_retry_delay,
5702                 (void *)&cmd_set_burst_tx_retry_time,
5703                 (void *)&cmd_set_burst_tx_retry_retry,
5704                 (void *)&cmd_set_burst_tx_retry_retry_num,
5705                 NULL,
5706         },
5707 };
5708
5709 /* *** SET PROMISC MODE *** */
5710 struct cmd_set_promisc_mode_result {
5711         cmdline_fixed_string_t set;
5712         cmdline_fixed_string_t promisc;
5713         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5714         uint16_t port_num;               /* valid if "allports" argument == 0 */
5715         cmdline_fixed_string_t mode;
5716 };
5717
5718 static void cmd_set_promisc_mode_parsed(void *parsed_result,
5719                                         __attribute__((unused)) struct cmdline *cl,
5720                                         void *allports)
5721 {
5722         struct cmd_set_promisc_mode_result *res = parsed_result;
5723         int enable;
5724         portid_t i;
5725
5726         if (!strcmp(res->mode, "on"))
5727                 enable = 1;
5728         else
5729                 enable = 0;
5730
5731         /* all ports */
5732         if (allports) {
5733                 RTE_ETH_FOREACH_DEV(i) {
5734                         if (enable)
5735                                 rte_eth_promiscuous_enable(i);
5736                         else
5737                                 rte_eth_promiscuous_disable(i);
5738                 }
5739         }
5740         else {
5741                 if (enable)
5742                         rte_eth_promiscuous_enable(res->port_num);
5743                 else
5744                         rte_eth_promiscuous_disable(res->port_num);
5745         }
5746 }
5747
5748 cmdline_parse_token_string_t cmd_setpromisc_set =
5749         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set");
5750 cmdline_parse_token_string_t cmd_setpromisc_promisc =
5751         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc,
5752                                  "promisc");
5753 cmdline_parse_token_string_t cmd_setpromisc_portall =
5754         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all,
5755                                  "all");
5756 cmdline_parse_token_num_t cmd_setpromisc_portnum =
5757         TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num,
5758                               UINT8);
5759 cmdline_parse_token_string_t cmd_setpromisc_mode =
5760         TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode,
5761                                  "on#off");
5762
5763 cmdline_parse_inst_t cmd_set_promisc_mode_all = {
5764         .f = cmd_set_promisc_mode_parsed,
5765         .data = (void *)1,
5766         .help_str = "set promisc all on|off: Set promisc mode for all ports",
5767         .tokens = {
5768                 (void *)&cmd_setpromisc_set,
5769                 (void *)&cmd_setpromisc_promisc,
5770                 (void *)&cmd_setpromisc_portall,
5771                 (void *)&cmd_setpromisc_mode,
5772                 NULL,
5773         },
5774 };
5775
5776 cmdline_parse_inst_t cmd_set_promisc_mode_one = {
5777         .f = cmd_set_promisc_mode_parsed,
5778         .data = (void *)0,
5779         .help_str = "set promisc <port_id> on|off: Set promisc mode on port_id",
5780         .tokens = {
5781                 (void *)&cmd_setpromisc_set,
5782                 (void *)&cmd_setpromisc_promisc,
5783                 (void *)&cmd_setpromisc_portnum,
5784                 (void *)&cmd_setpromisc_mode,
5785                 NULL,
5786         },
5787 };
5788
5789 /* *** SET ALLMULTI MODE *** */
5790 struct cmd_set_allmulti_mode_result {
5791         cmdline_fixed_string_t set;
5792         cmdline_fixed_string_t allmulti;
5793         cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */
5794         uint16_t port_num;               /* valid if "allports" argument == 0 */
5795         cmdline_fixed_string_t mode;
5796 };
5797
5798 static void cmd_set_allmulti_mode_parsed(void *parsed_result,
5799                                         __attribute__((unused)) struct cmdline *cl,
5800                                         void *allports)
5801 {
5802         struct cmd_set_allmulti_mode_result *res = parsed_result;
5803         int enable;
5804         portid_t i;
5805
5806         if (!strcmp(res->mode, "on"))
5807                 enable = 1;
5808         else
5809                 enable = 0;
5810
5811         /* all ports */
5812         if (allports) {
5813                 RTE_ETH_FOREACH_DEV(i) {
5814                         if (enable)
5815                                 rte_eth_allmulticast_enable(i);
5816                         else
5817                                 rte_eth_allmulticast_disable(i);
5818                 }
5819         }
5820         else {
5821                 if (enable)
5822                         rte_eth_allmulticast_enable(res->port_num);
5823                 else
5824                         rte_eth_allmulticast_disable(res->port_num);
5825         }
5826 }
5827
5828 cmdline_parse_token_string_t cmd_setallmulti_set =
5829         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, set, "set");
5830 cmdline_parse_token_string_t cmd_setallmulti_allmulti =
5831         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, allmulti,
5832                                  "allmulti");
5833 cmdline_parse_token_string_t cmd_setallmulti_portall =
5834         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, port_all,
5835                                  "all");
5836 cmdline_parse_token_num_t cmd_setallmulti_portnum =
5837         TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num,
5838                               UINT16);
5839 cmdline_parse_token_string_t cmd_setallmulti_mode =
5840         TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode,
5841                                  "on#off");
5842
5843 cmdline_parse_inst_t cmd_set_allmulti_mode_all = {
5844         .f = cmd_set_allmulti_mode_parsed,
5845         .data = (void *)1,
5846         .help_str = "set allmulti all on|off: Set allmulti mode for all ports",
5847         .tokens = {
5848                 (void *)&cmd_setallmulti_set,
5849                 (void *)&cmd_setallmulti_allmulti,
5850                 (void *)&cmd_setallmulti_portall,
5851                 (void *)&cmd_setallmulti_mode,
5852                 NULL,
5853         },
5854 };
5855
5856 cmdline_parse_inst_t cmd_set_allmulti_mode_one = {
5857         .f = cmd_set_allmulti_mode_parsed,
5858         .data = (void *)0,
5859         .help_str = "set allmulti <port_id> on|off: "
5860                 "Set allmulti mode on port_id",
5861         .tokens = {
5862                 (void *)&cmd_setallmulti_set,
5863                 (void *)&cmd_setallmulti_allmulti,
5864                 (void *)&cmd_setallmulti_portnum,
5865                 (void *)&cmd_setallmulti_mode,
5866                 NULL,
5867         },
5868 };
5869
5870 /* *** SETUP ETHERNET LINK FLOW CONTROL *** */
5871 struct cmd_link_flow_ctrl_set_result {
5872         cmdline_fixed_string_t set;
5873         cmdline_fixed_string_t flow_ctrl;
5874         cmdline_fixed_string_t rx;
5875         cmdline_fixed_string_t rx_lfc_mode;
5876         cmdline_fixed_string_t tx;
5877         cmdline_fixed_string_t tx_lfc_mode;
5878         cmdline_fixed_string_t mac_ctrl_frame_fwd;
5879         cmdline_fixed_string_t mac_ctrl_frame_fwd_mode;
5880         cmdline_fixed_string_t autoneg_str;
5881         cmdline_fixed_string_t autoneg;
5882         cmdline_fixed_string_t hw_str;
5883         uint32_t high_water;
5884         cmdline_fixed_string_t lw_str;
5885         uint32_t low_water;
5886         cmdline_fixed_string_t pt_str;
5887         uint16_t pause_time;
5888         cmdline_fixed_string_t xon_str;
5889         uint16_t send_xon;
5890         portid_t port_id;
5891 };
5892
5893 cmdline_parse_token_string_t cmd_lfc_set_set =
5894         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5895                                 set, "set");
5896 cmdline_parse_token_string_t cmd_lfc_set_flow_ctrl =
5897         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5898                                 flow_ctrl, "flow_ctrl");
5899 cmdline_parse_token_string_t cmd_lfc_set_rx =
5900         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5901                                 rx, "rx");
5902 cmdline_parse_token_string_t cmd_lfc_set_rx_mode =
5903         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5904                                 rx_lfc_mode, "on#off");
5905 cmdline_parse_token_string_t cmd_lfc_set_tx =
5906         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5907                                 tx, "tx");
5908 cmdline_parse_token_string_t cmd_lfc_set_tx_mode =
5909         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5910                                 tx_lfc_mode, "on#off");
5911 cmdline_parse_token_string_t cmd_lfc_set_high_water_str =
5912         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5913                                 hw_str, "high_water");
5914 cmdline_parse_token_num_t cmd_lfc_set_high_water =
5915         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5916                                 high_water, UINT32);
5917 cmdline_parse_token_string_t cmd_lfc_set_low_water_str =
5918         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5919                                 lw_str, "low_water");
5920 cmdline_parse_token_num_t cmd_lfc_set_low_water =
5921         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5922                                 low_water, UINT32);
5923 cmdline_parse_token_string_t cmd_lfc_set_pause_time_str =
5924         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5925                                 pt_str, "pause_time");
5926 cmdline_parse_token_num_t cmd_lfc_set_pause_time =
5927         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5928                                 pause_time, UINT16);
5929 cmdline_parse_token_string_t cmd_lfc_set_send_xon_str =
5930         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5931                                 xon_str, "send_xon");
5932 cmdline_parse_token_num_t cmd_lfc_set_send_xon =
5933         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5934                                 send_xon, UINT16);
5935 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd_mode =
5936         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5937                                 mac_ctrl_frame_fwd, "mac_ctrl_frame_fwd");
5938 cmdline_parse_token_string_t cmd_lfc_set_mac_ctrl_frame_fwd =
5939         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5940                                 mac_ctrl_frame_fwd_mode, "on#off");
5941 cmdline_parse_token_string_t cmd_lfc_set_autoneg_str =
5942         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5943                                 autoneg_str, "autoneg");
5944 cmdline_parse_token_string_t cmd_lfc_set_autoneg =
5945         TOKEN_STRING_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5946                                 autoneg, "on#off");
5947 cmdline_parse_token_num_t cmd_lfc_set_portid =
5948         TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result,
5949                                 port_id, UINT16);
5950
5951 /* forward declaration */
5952 static void
5953 cmd_link_flow_ctrl_set_parsed(void *parsed_result, struct cmdline *cl,
5954                               void *data);
5955
5956 cmdline_parse_inst_t cmd_link_flow_control_set = {
5957         .f = cmd_link_flow_ctrl_set_parsed,
5958         .data = NULL,
5959         .help_str = "set flow_ctrl rx on|off tx on|off <high_water> "
5960                 "<low_water> <pause_time> <send_xon> mac_ctrl_frame_fwd on|off "
5961                 "autoneg on|off <port_id>: Configure the Ethernet flow control",
5962         .tokens = {
5963                 (void *)&cmd_lfc_set_set,
5964                 (void *)&cmd_lfc_set_flow_ctrl,
5965                 (void *)&cmd_lfc_set_rx,
5966                 (void *)&cmd_lfc_set_rx_mode,
5967                 (void *)&cmd_lfc_set_tx,
5968                 (void *)&cmd_lfc_set_tx_mode,
5969                 (void *)&cmd_lfc_set_high_water,
5970                 (void *)&cmd_lfc_set_low_water,
5971                 (void *)&cmd_lfc_set_pause_time,
5972                 (void *)&cmd_lfc_set_send_xon,
5973                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
5974                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
5975                 (void *)&cmd_lfc_set_autoneg_str,
5976                 (void *)&cmd_lfc_set_autoneg,
5977                 (void *)&cmd_lfc_set_portid,
5978                 NULL,
5979         },
5980 };
5981
5982 cmdline_parse_inst_t cmd_link_flow_control_set_rx = {
5983         .f = cmd_link_flow_ctrl_set_parsed,
5984         .data = (void *)&cmd_link_flow_control_set_rx,
5985         .help_str = "set flow_ctrl rx on|off <port_id>: "
5986                 "Change rx flow control parameter",
5987         .tokens = {
5988                 (void *)&cmd_lfc_set_set,
5989                 (void *)&cmd_lfc_set_flow_ctrl,
5990                 (void *)&cmd_lfc_set_rx,
5991                 (void *)&cmd_lfc_set_rx_mode,
5992                 (void *)&cmd_lfc_set_portid,
5993                 NULL,
5994         },
5995 };
5996
5997 cmdline_parse_inst_t cmd_link_flow_control_set_tx = {
5998         .f = cmd_link_flow_ctrl_set_parsed,
5999         .data = (void *)&cmd_link_flow_control_set_tx,
6000         .help_str = "set flow_ctrl tx on|off <port_id>: "
6001                 "Change tx flow control parameter",
6002         .tokens = {
6003                 (void *)&cmd_lfc_set_set,
6004                 (void *)&cmd_lfc_set_flow_ctrl,
6005                 (void *)&cmd_lfc_set_tx,
6006                 (void *)&cmd_lfc_set_tx_mode,
6007                 (void *)&cmd_lfc_set_portid,
6008                 NULL,
6009         },
6010 };
6011
6012 cmdline_parse_inst_t cmd_link_flow_control_set_hw = {
6013         .f = cmd_link_flow_ctrl_set_parsed,
6014         .data = (void *)&cmd_link_flow_control_set_hw,
6015         .help_str = "set flow_ctrl high_water <value> <port_id>: "
6016                 "Change high water flow control parameter",
6017         .tokens = {
6018                 (void *)&cmd_lfc_set_set,
6019                 (void *)&cmd_lfc_set_flow_ctrl,
6020                 (void *)&cmd_lfc_set_high_water_str,
6021                 (void *)&cmd_lfc_set_high_water,
6022                 (void *)&cmd_lfc_set_portid,
6023                 NULL,
6024         },
6025 };
6026
6027 cmdline_parse_inst_t cmd_link_flow_control_set_lw = {
6028         .f = cmd_link_flow_ctrl_set_parsed,
6029         .data = (void *)&cmd_link_flow_control_set_lw,
6030         .help_str = "set flow_ctrl low_water <value> <port_id>: "
6031                 "Change low water flow control parameter",
6032         .tokens = {
6033                 (void *)&cmd_lfc_set_set,
6034                 (void *)&cmd_lfc_set_flow_ctrl,
6035                 (void *)&cmd_lfc_set_low_water_str,
6036                 (void *)&cmd_lfc_set_low_water,
6037                 (void *)&cmd_lfc_set_portid,
6038                 NULL,
6039         },
6040 };
6041
6042 cmdline_parse_inst_t cmd_link_flow_control_set_pt = {
6043         .f = cmd_link_flow_ctrl_set_parsed,
6044         .data = (void *)&cmd_link_flow_control_set_pt,
6045         .help_str = "set flow_ctrl pause_time <value> <port_id>: "
6046                 "Change pause time flow control parameter",
6047         .tokens = {
6048                 (void *)&cmd_lfc_set_set,
6049                 (void *)&cmd_lfc_set_flow_ctrl,
6050                 (void *)&cmd_lfc_set_pause_time_str,
6051                 (void *)&cmd_lfc_set_pause_time,
6052                 (void *)&cmd_lfc_set_portid,
6053                 NULL,
6054         },
6055 };
6056
6057 cmdline_parse_inst_t cmd_link_flow_control_set_xon = {
6058         .f = cmd_link_flow_ctrl_set_parsed,
6059         .data = (void *)&cmd_link_flow_control_set_xon,
6060         .help_str = "set flow_ctrl send_xon <value> <port_id>: "
6061                 "Change send_xon flow control parameter",
6062         .tokens = {
6063                 (void *)&cmd_lfc_set_set,
6064                 (void *)&cmd_lfc_set_flow_ctrl,
6065                 (void *)&cmd_lfc_set_send_xon_str,
6066                 (void *)&cmd_lfc_set_send_xon,
6067                 (void *)&cmd_lfc_set_portid,
6068                 NULL,
6069         },
6070 };
6071
6072 cmdline_parse_inst_t cmd_link_flow_control_set_macfwd = {
6073         .f = cmd_link_flow_ctrl_set_parsed,
6074         .data = (void *)&cmd_link_flow_control_set_macfwd,
6075         .help_str = "set flow_ctrl mac_ctrl_frame_fwd on|off <port_id>: "
6076                 "Change mac ctrl fwd flow control parameter",
6077         .tokens = {
6078                 (void *)&cmd_lfc_set_set,
6079                 (void *)&cmd_lfc_set_flow_ctrl,
6080                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd_mode,
6081                 (void *)&cmd_lfc_set_mac_ctrl_frame_fwd,
6082                 (void *)&cmd_lfc_set_portid,
6083                 NULL,
6084         },
6085 };
6086
6087 cmdline_parse_inst_t cmd_link_flow_control_set_autoneg = {
6088         .f = cmd_link_flow_ctrl_set_parsed,
6089         .data = (void *)&cmd_link_flow_control_set_autoneg,
6090         .help_str = "set flow_ctrl autoneg on|off <port_id>: "
6091                 "Change autoneg flow control parameter",
6092         .tokens = {
6093                 (void *)&cmd_lfc_set_set,
6094                 (void *)&cmd_lfc_set_flow_ctrl,
6095                 (void *)&cmd_lfc_set_autoneg_str,
6096                 (void *)&cmd_lfc_set_autoneg,
6097                 (void *)&cmd_lfc_set_portid,
6098                 NULL,
6099         },
6100 };
6101
6102 static void
6103 cmd_link_flow_ctrl_set_parsed(void *parsed_result,
6104                               __attribute__((unused)) struct cmdline *cl,
6105                               void *data)
6106 {
6107         struct cmd_link_flow_ctrl_set_result *res = parsed_result;
6108         cmdline_parse_inst_t *cmd = data;
6109         struct rte_eth_fc_conf fc_conf;
6110         int rx_fc_en = 0;
6111         int tx_fc_en = 0;
6112         int ret;
6113
6114         /*
6115          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6116          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6117          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6118          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6119          */
6120         static enum rte_eth_fc_mode rx_tx_onoff_2_lfc_mode[2][2] = {
6121                         {RTE_FC_NONE, RTE_FC_TX_PAUSE}, {RTE_FC_RX_PAUSE, RTE_FC_FULL}
6122         };
6123
6124         /* Partial command line, retrieve current configuration */
6125         if (cmd) {
6126                 ret = rte_eth_dev_flow_ctrl_get(res->port_id, &fc_conf);
6127                 if (ret != 0) {
6128                         printf("cannot get current flow ctrl parameters, return"
6129                                "code = %d\n", ret);
6130                         return;
6131                 }
6132
6133                 if ((fc_conf.mode == RTE_FC_RX_PAUSE) ||
6134                     (fc_conf.mode == RTE_FC_FULL))
6135                         rx_fc_en = 1;
6136                 if ((fc_conf.mode == RTE_FC_TX_PAUSE) ||
6137                     (fc_conf.mode == RTE_FC_FULL))
6138                         tx_fc_en = 1;
6139         }
6140
6141         if (!cmd || cmd == &cmd_link_flow_control_set_rx)
6142                 rx_fc_en = (!strcmp(res->rx_lfc_mode, "on")) ? 1 : 0;
6143
6144         if (!cmd || cmd == &cmd_link_flow_control_set_tx)
6145                 tx_fc_en = (!strcmp(res->tx_lfc_mode, "on")) ? 1 : 0;
6146
6147         fc_conf.mode = rx_tx_onoff_2_lfc_mode[rx_fc_en][tx_fc_en];
6148
6149         if (!cmd || cmd == &cmd_link_flow_control_set_hw)
6150                 fc_conf.high_water = res->high_water;
6151
6152         if (!cmd || cmd == &cmd_link_flow_control_set_lw)
6153                 fc_conf.low_water = res->low_water;
6154
6155         if (!cmd || cmd == &cmd_link_flow_control_set_pt)
6156                 fc_conf.pause_time = res->pause_time;
6157
6158         if (!cmd || cmd == &cmd_link_flow_control_set_xon)
6159                 fc_conf.send_xon = res->send_xon;
6160
6161         if (!cmd || cmd == &cmd_link_flow_control_set_macfwd) {
6162                 if (!strcmp(res->mac_ctrl_frame_fwd_mode, "on"))
6163                         fc_conf.mac_ctrl_frame_fwd = 1;
6164                 else
6165                         fc_conf.mac_ctrl_frame_fwd = 0;
6166         }
6167
6168         if (!cmd || cmd == &cmd_link_flow_control_set_autoneg)
6169                 fc_conf.autoneg = (!strcmp(res->autoneg, "on")) ? 1 : 0;
6170
6171         ret = rte_eth_dev_flow_ctrl_set(res->port_id, &fc_conf);
6172         if (ret != 0)
6173                 printf("bad flow contrl parameter, return code = %d \n", ret);
6174 }
6175
6176 /* *** SETUP ETHERNET PRIORITY FLOW CONTROL *** */
6177 struct cmd_priority_flow_ctrl_set_result {
6178         cmdline_fixed_string_t set;
6179         cmdline_fixed_string_t pfc_ctrl;
6180         cmdline_fixed_string_t rx;
6181         cmdline_fixed_string_t rx_pfc_mode;
6182         cmdline_fixed_string_t tx;
6183         cmdline_fixed_string_t tx_pfc_mode;
6184         uint32_t high_water;
6185         uint32_t low_water;
6186         uint16_t pause_time;
6187         uint8_t  priority;
6188         portid_t port_id;
6189 };
6190
6191 static void
6192 cmd_priority_flow_ctrl_set_parsed(void *parsed_result,
6193                        __attribute__((unused)) struct cmdline *cl,
6194                        __attribute__((unused)) void *data)
6195 {
6196         struct cmd_priority_flow_ctrl_set_result *res = parsed_result;
6197         struct rte_eth_pfc_conf pfc_conf;
6198         int rx_fc_enable, tx_fc_enable;
6199         int ret;
6200
6201         /*
6202          * Rx on/off, flow control is enabled/disabled on RX side. This can indicate
6203          * the RTE_FC_TX_PAUSE, Transmit pause frame at the Rx side.
6204          * Tx on/off, flow control is enabled/disabled on TX side. This can indicate
6205          * the RTE_FC_RX_PAUSE, Respond to the pause frame at the Tx side.
6206          */
6207         static enum rte_eth_fc_mode rx_tx_onoff_2_pfc_mode[2][2] = {
6208                         {RTE_FC_NONE, RTE_FC_RX_PAUSE}, {RTE_FC_TX_PAUSE, RTE_FC_FULL}
6209         };
6210
6211         rx_fc_enable = (!strncmp(res->rx_pfc_mode, "on",2)) ? 1 : 0;
6212         tx_fc_enable = (!strncmp(res->tx_pfc_mode, "on",2)) ? 1 : 0;
6213         pfc_conf.fc.mode       = rx_tx_onoff_2_pfc_mode[rx_fc_enable][tx_fc_enable];
6214         pfc_conf.fc.high_water = res->high_water;
6215         pfc_conf.fc.low_water  = res->low_water;
6216         pfc_conf.fc.pause_time = res->pause_time;
6217         pfc_conf.priority      = res->priority;
6218
6219         ret = rte_eth_dev_priority_flow_ctrl_set(res->port_id, &pfc_conf);
6220         if (ret != 0)
6221                 printf("bad priority flow contrl parameter, return code = %d \n", ret);
6222 }
6223
6224 cmdline_parse_token_string_t cmd_pfc_set_set =
6225         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6226                                 set, "set");
6227 cmdline_parse_token_string_t cmd_pfc_set_flow_ctrl =
6228         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6229                                 pfc_ctrl, "pfc_ctrl");
6230 cmdline_parse_token_string_t cmd_pfc_set_rx =
6231         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6232                                 rx, "rx");
6233 cmdline_parse_token_string_t cmd_pfc_set_rx_mode =
6234         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6235                                 rx_pfc_mode, "on#off");
6236 cmdline_parse_token_string_t cmd_pfc_set_tx =
6237         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6238                                 tx, "tx");
6239 cmdline_parse_token_string_t cmd_pfc_set_tx_mode =
6240         TOKEN_STRING_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6241                                 tx_pfc_mode, "on#off");
6242 cmdline_parse_token_num_t cmd_pfc_set_high_water =
6243         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6244                                 high_water, UINT32);
6245 cmdline_parse_token_num_t cmd_pfc_set_low_water =
6246         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6247                                 low_water, UINT32);
6248 cmdline_parse_token_num_t cmd_pfc_set_pause_time =
6249         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6250                                 pause_time, UINT16);
6251 cmdline_parse_token_num_t cmd_pfc_set_priority =
6252         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6253                                 priority, UINT8);
6254 cmdline_parse_token_num_t cmd_pfc_set_portid =
6255         TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result,
6256                                 port_id, UINT16);
6257
6258 cmdline_parse_inst_t cmd_priority_flow_control_set = {
6259         .f = cmd_priority_flow_ctrl_set_parsed,
6260         .data = NULL,
6261         .help_str = "set pfc_ctrl rx on|off tx on|off <high_water> <low_water> "
6262                 "<pause_time> <priority> <port_id>: "
6263                 "Configure the Ethernet priority flow control",
6264         .tokens = {
6265                 (void *)&cmd_pfc_set_set,
6266                 (void *)&cmd_pfc_set_flow_ctrl,
6267                 (void *)&cmd_pfc_set_rx,
6268                 (void *)&cmd_pfc_set_rx_mode,
6269                 (void *)&cmd_pfc_set_tx,
6270                 (void *)&cmd_pfc_set_tx_mode,
6271                 (void *)&cmd_pfc_set_high_water,
6272                 (void *)&cmd_pfc_set_low_water,
6273                 (void *)&cmd_pfc_set_pause_time,
6274                 (void *)&cmd_pfc_set_priority,
6275                 (void *)&cmd_pfc_set_portid,
6276                 NULL,
6277         },
6278 };
6279
6280 /* *** RESET CONFIGURATION *** */
6281 struct cmd_reset_result {
6282         cmdline_fixed_string_t reset;
6283         cmdline_fixed_string_t def;
6284 };
6285
6286 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
6287                              struct cmdline *cl,
6288                              __attribute__((unused)) void *data)
6289 {
6290         cmdline_printf(cl, "Reset to default forwarding configuration...\n");
6291         set_def_fwd_config();
6292 }
6293
6294 cmdline_parse_token_string_t cmd_reset_set =
6295         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, reset, "set");
6296 cmdline_parse_token_string_t cmd_reset_def =
6297         TOKEN_STRING_INITIALIZER(struct cmd_reset_result, def,
6298                                  "default");
6299
6300 cmdline_parse_inst_t cmd_reset = {
6301         .f = cmd_reset_parsed,
6302         .data = NULL,
6303         .help_str = "set default: Reset default forwarding configuration",
6304         .tokens = {
6305                 (void *)&cmd_reset_set,
6306                 (void *)&cmd_reset_def,
6307                 NULL,
6308         },
6309 };
6310
6311 /* *** START FORWARDING *** */
6312 struct cmd_start_result {
6313         cmdline_fixed_string_t start;
6314 };
6315
6316 cmdline_parse_token_string_t cmd_start_start =
6317         TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start");
6318
6319 static void cmd_start_parsed(__attribute__((unused)) void *parsed_result,
6320                              __attribute__((unused)) struct cmdline *cl,
6321                              __attribute__((unused)) void *data)
6322 {
6323         start_packet_forwarding(0);
6324 }
6325
6326 cmdline_parse_inst_t cmd_start = {
6327         .f = cmd_start_parsed,
6328         .data = NULL,
6329         .help_str = "start: Start packet forwarding",
6330         .tokens = {
6331                 (void *)&cmd_start_start,
6332                 NULL,
6333         },
6334 };
6335
6336 /* *** START FORWARDING WITH ONE TX BURST FIRST *** */
6337 struct cmd_start_tx_first_result {
6338         cmdline_fixed_string_t start;
6339         cmdline_fixed_string_t tx_first;
6340 };
6341
6342 static void
6343 cmd_start_tx_first_parsed(__attribute__((unused)) void *parsed_result,
6344                           __attribute__((unused)) struct cmdline *cl,
6345                           __attribute__((unused)) void *data)
6346 {
6347         start_packet_forwarding(1);
6348 }
6349
6350 cmdline_parse_token_string_t cmd_start_tx_first_start =
6351         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result, start,
6352                                  "start");
6353 cmdline_parse_token_string_t cmd_start_tx_first_tx_first =
6354         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_result,
6355                                  tx_first, "tx_first");
6356
6357 cmdline_parse_inst_t cmd_start_tx_first = {
6358         .f = cmd_start_tx_first_parsed,
6359         .data = NULL,
6360         .help_str = "start tx_first: Start packet forwarding, "
6361                 "after sending 1 burst of packets",
6362         .tokens = {
6363                 (void *)&cmd_start_tx_first_start,
6364                 (void *)&cmd_start_tx_first_tx_first,
6365                 NULL,
6366         },
6367 };
6368
6369 /* *** START FORWARDING WITH N TX BURST FIRST *** */
6370 struct cmd_start_tx_first_n_result {
6371         cmdline_fixed_string_t start;
6372         cmdline_fixed_string_t tx_first;
6373         uint32_t tx_num;
6374 };
6375
6376 static void
6377 cmd_start_tx_first_n_parsed(void *parsed_result,
6378                           __attribute__((unused)) struct cmdline *cl,
6379                           __attribute__((unused)) void *data)
6380 {
6381         struct cmd_start_tx_first_n_result *res = parsed_result;
6382
6383         start_packet_forwarding(res->tx_num);
6384 }
6385
6386 cmdline_parse_token_string_t cmd_start_tx_first_n_start =
6387         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6388                         start, "start");
6389 cmdline_parse_token_string_t cmd_start_tx_first_n_tx_first =
6390         TOKEN_STRING_INITIALIZER(struct cmd_start_tx_first_n_result,
6391                         tx_first, "tx_first");
6392 cmdline_parse_token_num_t cmd_start_tx_first_n_tx_num =
6393         TOKEN_NUM_INITIALIZER(struct cmd_start_tx_first_n_result,
6394                         tx_num, UINT32);
6395
6396 cmdline_parse_inst_t cmd_start_tx_first_n = {
6397         .f = cmd_start_tx_first_n_parsed,
6398         .data = NULL,
6399         .help_str = "start tx_first <num>: "
6400                 "packet forwarding, after sending <num> bursts of packets",
6401         .tokens = {
6402                 (void *)&cmd_start_tx_first_n_start,
6403                 (void *)&cmd_start_tx_first_n_tx_first,
6404                 (void *)&cmd_start_tx_first_n_tx_num,
6405                 NULL,
6406         },
6407 };
6408
6409 /* *** SET LINK UP *** */
6410 struct cmd_set_link_up_result {
6411         cmdline_fixed_string_t set;
6412         cmdline_fixed_string_t link_up;
6413         cmdline_fixed_string_t port;
6414         portid_t port_id;
6415 };
6416
6417 cmdline_parse_token_string_t cmd_set_link_up_set =
6418         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, set, "set");
6419 cmdline_parse_token_string_t cmd_set_link_up_link_up =
6420         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, link_up,
6421                                 "link-up");
6422 cmdline_parse_token_string_t cmd_set_link_up_port =
6423         TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port");
6424 cmdline_parse_token_num_t cmd_set_link_up_port_id =
6425         TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16);
6426
6427 static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result,
6428                              __attribute__((unused)) struct cmdline *cl,
6429                              __attribute__((unused)) void *data)
6430 {
6431         struct cmd_set_link_up_result *res = parsed_result;
6432         dev_set_link_up(res->port_id);
6433 }
6434
6435 cmdline_parse_inst_t cmd_set_link_up = {
6436         .f = cmd_set_link_up_parsed,
6437         .data = NULL,
6438         .help_str = "set link-up port <port id>",
6439         .tokens = {
6440                 (void *)&cmd_set_link_up_set,
6441                 (void *)&cmd_set_link_up_link_up,
6442                 (void *)&cmd_set_link_up_port,
6443                 (void *)&cmd_set_link_up_port_id,
6444                 NULL,
6445         },
6446 };
6447
6448 /* *** SET LINK DOWN *** */
6449 struct cmd_set_link_down_result {
6450         cmdline_fixed_string_t set;
6451         cmdline_fixed_string_t link_down;
6452         cmdline_fixed_string_t port;
6453         portid_t port_id;
6454 };
6455
6456 cmdline_parse_token_string_t cmd_set_link_down_set =
6457         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, set, "set");
6458 cmdline_parse_token_string_t cmd_set_link_down_link_down =
6459         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, link_down,
6460                                 "link-down");
6461 cmdline_parse_token_string_t cmd_set_link_down_port =
6462         TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port");
6463 cmdline_parse_token_num_t cmd_set_link_down_port_id =
6464         TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16);
6465
6466 static void cmd_set_link_down_parsed(
6467                                 __attribute__((unused)) void *parsed_result,
6468                                 __attribute__((unused)) struct cmdline *cl,
6469                                 __attribute__((unused)) void *data)
6470 {
6471         struct cmd_set_link_down_result *res = parsed_result;
6472         dev_set_link_down(res->port_id);
6473 }
6474
6475 cmdline_parse_inst_t cmd_set_link_down = {
6476         .f = cmd_set_link_down_parsed,
6477         .data = NULL,
6478         .help_str = "set link-down port <port id>",
6479         .tokens = {
6480                 (void *)&cmd_set_link_down_set,
6481                 (void *)&cmd_set_link_down_link_down,
6482                 (void *)&cmd_set_link_down_port,
6483                 (void *)&cmd_set_link_down_port_id,
6484                 NULL,
6485         },
6486 };
6487
6488 /* *** SHOW CFG *** */
6489 struct cmd_showcfg_result {
6490         cmdline_fixed_string_t show;
6491         cmdline_fixed_string_t cfg;
6492         cmdline_fixed_string_t what;
6493 };
6494
6495 static void cmd_showcfg_parsed(void *parsed_result,
6496                                __attribute__((unused)) struct cmdline *cl,
6497                                __attribute__((unused)) void *data)
6498 {
6499         struct cmd_showcfg_result *res = parsed_result;
6500         if (!strcmp(res->what, "rxtx"))
6501                 rxtx_config_display();
6502         else if (!strcmp(res->what, "cores"))
6503                 fwd_lcores_config_display();
6504         else if (!strcmp(res->what, "fwd"))
6505                 pkt_fwd_config_display(&cur_fwd_config);
6506         else if (!strcmp(res->what, "txpkts"))
6507                 show_tx_pkt_segments();
6508 }
6509
6510 cmdline_parse_token_string_t cmd_showcfg_show =
6511         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, show, "show");
6512 cmdline_parse_token_string_t cmd_showcfg_port =
6513         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, cfg, "config");
6514 cmdline_parse_token_string_t cmd_showcfg_what =
6515         TOKEN_STRING_INITIALIZER(struct cmd_showcfg_result, what,
6516                                  "rxtx#cores#fwd#txpkts");
6517
6518 cmdline_parse_inst_t cmd_showcfg = {
6519         .f = cmd_showcfg_parsed,
6520         .data = NULL,
6521         .help_str = "show config rxtx|cores|fwd|txpkts",
6522         .tokens = {
6523                 (void *)&cmd_showcfg_show,
6524                 (void *)&cmd_showcfg_port,
6525                 (void *)&cmd_showcfg_what,
6526                 NULL,
6527         },
6528 };
6529
6530 /* *** SHOW ALL PORT INFO *** */
6531 struct cmd_showportall_result {
6532         cmdline_fixed_string_t show;
6533         cmdline_fixed_string_t port;
6534         cmdline_fixed_string_t what;
6535         cmdline_fixed_string_t all;
6536 };
6537
6538 static void cmd_showportall_parsed(void *parsed_result,
6539                                 __attribute__((unused)) struct cmdline *cl,
6540                                 __attribute__((unused)) void *data)
6541 {
6542         portid_t i;
6543
6544         struct cmd_showportall_result *res = parsed_result;
6545         if (!strcmp(res->show, "clear")) {
6546                 if (!strcmp(res->what, "stats"))
6547                         RTE_ETH_FOREACH_DEV(i)
6548                                 nic_stats_clear(i);
6549                 else if (!strcmp(res->what, "xstats"))
6550                         RTE_ETH_FOREACH_DEV(i)
6551                                 nic_xstats_clear(i);
6552         } else if (!strcmp(res->what, "info"))
6553                 RTE_ETH_FOREACH_DEV(i)
6554                         port_infos_display(i);
6555         else if (!strcmp(res->what, "stats"))
6556                 RTE_ETH_FOREACH_DEV(i)
6557                         nic_stats_display(i);
6558         else if (!strcmp(res->what, "xstats"))
6559                 RTE_ETH_FOREACH_DEV(i)
6560                         nic_xstats_display(i);
6561         else if (!strcmp(res->what, "fdir"))
6562                 RTE_ETH_FOREACH_DEV(i)
6563                         fdir_get_infos(i);
6564         else if (!strcmp(res->what, "stat_qmap"))
6565                 RTE_ETH_FOREACH_DEV(i)
6566                         nic_stats_mapping_display(i);
6567         else if (!strcmp(res->what, "dcb_tc"))
6568                 RTE_ETH_FOREACH_DEV(i)
6569                         port_dcb_info_display(i);
6570         else if (!strcmp(res->what, "cap"))
6571                 RTE_ETH_FOREACH_DEV(i)
6572                         port_offload_cap_display(i);
6573 }
6574
6575 cmdline_parse_token_string_t cmd_showportall_show =
6576         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, show,
6577                                  "show#clear");
6578 cmdline_parse_token_string_t cmd_showportall_port =
6579         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, port, "port");
6580 cmdline_parse_token_string_t cmd_showportall_what =
6581         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, what,
6582                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6583 cmdline_parse_token_string_t cmd_showportall_all =
6584         TOKEN_STRING_INITIALIZER(struct cmd_showportall_result, all, "all");
6585 cmdline_parse_inst_t cmd_showportall = {
6586         .f = cmd_showportall_parsed,
6587         .data = NULL,
6588         .help_str = "show|clear port "
6589                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap all",
6590         .tokens = {
6591                 (void *)&cmd_showportall_show,
6592                 (void *)&cmd_showportall_port,
6593                 (void *)&cmd_showportall_what,
6594                 (void *)&cmd_showportall_all,
6595                 NULL,
6596         },
6597 };
6598
6599 /* *** SHOW PORT INFO *** */
6600 struct cmd_showport_result {
6601         cmdline_fixed_string_t show;
6602         cmdline_fixed_string_t port;
6603         cmdline_fixed_string_t what;
6604         uint16_t portnum;
6605 };
6606
6607 static void cmd_showport_parsed(void *parsed_result,
6608                                 __attribute__((unused)) struct cmdline *cl,
6609                                 __attribute__((unused)) void *data)
6610 {
6611         struct cmd_showport_result *res = parsed_result;
6612         if (!strcmp(res->show, "clear")) {
6613                 if (!strcmp(res->what, "stats"))
6614                         nic_stats_clear(res->portnum);
6615                 else if (!strcmp(res->what, "xstats"))
6616                         nic_xstats_clear(res->portnum);
6617         } else if (!strcmp(res->what, "info"))
6618                 port_infos_display(res->portnum);
6619         else if (!strcmp(res->what, "stats"))
6620                 nic_stats_display(res->portnum);
6621         else if (!strcmp(res->what, "xstats"))
6622                 nic_xstats_display(res->portnum);
6623         else if (!strcmp(res->what, "fdir"))
6624                  fdir_get_infos(res->portnum);
6625         else if (!strcmp(res->what, "stat_qmap"))
6626                 nic_stats_mapping_display(res->portnum);
6627         else if (!strcmp(res->what, "dcb_tc"))
6628                 port_dcb_info_display(res->portnum);
6629         else if (!strcmp(res->what, "cap"))
6630                 port_offload_cap_display(res->portnum);
6631 }
6632
6633 cmdline_parse_token_string_t cmd_showport_show =
6634         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, show,
6635                                  "show#clear");
6636 cmdline_parse_token_string_t cmd_showport_port =
6637         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, port, "port");
6638 cmdline_parse_token_string_t cmd_showport_what =
6639         TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what,
6640                                  "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap");
6641 cmdline_parse_token_num_t cmd_showport_portnum =
6642         TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16);
6643
6644 cmdline_parse_inst_t cmd_showport = {
6645         .f = cmd_showport_parsed,
6646         .data = NULL,
6647         .help_str = "show|clear port "
6648                 "info|stats|xstats|fdir|stat_qmap|dcb_tc|cap "
6649                 "<port_id>",
6650         .tokens = {
6651                 (void *)&cmd_showport_show,
6652                 (void *)&cmd_showport_port,
6653                 (void *)&cmd_showport_what,
6654                 (void *)&cmd_showport_portnum,
6655                 NULL,
6656         },
6657 };
6658
6659 /* *** SHOW QUEUE INFO *** */
6660 struct cmd_showqueue_result {
6661         cmdline_fixed_string_t show;
6662         cmdline_fixed_string_t type;
6663         cmdline_fixed_string_t what;
6664         uint16_t portnum;
6665         uint16_t queuenum;
6666 };
6667
6668 static void
6669 cmd_showqueue_parsed(void *parsed_result,
6670         __attribute__((unused)) struct cmdline *cl,
6671         __attribute__((unused)) void *data)
6672 {
6673         struct cmd_showqueue_result *res = parsed_result;
6674
6675         if (!strcmp(res->type, "rxq"))
6676                 rx_queue_infos_display(res->portnum, res->queuenum);
6677         else if (!strcmp(res->type, "txq"))
6678                 tx_queue_infos_display(res->portnum, res->queuenum);
6679 }
6680
6681 cmdline_parse_token_string_t cmd_showqueue_show =
6682         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, show, "show");
6683 cmdline_parse_token_string_t cmd_showqueue_type =
6684         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, type, "rxq#txq");
6685 cmdline_parse_token_string_t cmd_showqueue_what =
6686         TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info");
6687 cmdline_parse_token_num_t cmd_showqueue_portnum =
6688         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16);
6689 cmdline_parse_token_num_t cmd_showqueue_queuenum =
6690         TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16);
6691
6692 cmdline_parse_inst_t cmd_showqueue = {
6693         .f = cmd_showqueue_parsed,
6694         .data = NULL,
6695         .help_str = "show rxq|txq info <port_id> <queue_id>",
6696         .tokens = {
6697                 (void *)&cmd_showqueue_show,
6698                 (void *)&cmd_showqueue_type,
6699                 (void *)&cmd_showqueue_what,
6700                 (void *)&cmd_showqueue_portnum,
6701                 (void *)&cmd_showqueue_queuenum,
6702                 NULL,
6703         },
6704 };
6705
6706 /* *** READ PORT REGISTER *** */
6707 struct cmd_read_reg_result {
6708         cmdline_fixed_string_t read;
6709         cmdline_fixed_string_t reg;
6710         portid_t port_id;
6711         uint32_t reg_off;
6712 };
6713
6714 static void
6715 cmd_read_reg_parsed(void *parsed_result,
6716                     __attribute__((unused)) struct cmdline *cl,
6717                     __attribute__((unused)) void *data)
6718 {
6719         struct cmd_read_reg_result *res = parsed_result;
6720         port_reg_display(res->port_id, res->reg_off);
6721 }
6722
6723 cmdline_parse_token_string_t cmd_read_reg_read =
6724         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, read, "read");
6725 cmdline_parse_token_string_t cmd_read_reg_reg =
6726         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg");
6727 cmdline_parse_token_num_t cmd_read_reg_port_id =
6728         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16);
6729 cmdline_parse_token_num_t cmd_read_reg_reg_off =
6730         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32);
6731
6732 cmdline_parse_inst_t cmd_read_reg = {
6733         .f = cmd_read_reg_parsed,
6734         .data = NULL,
6735         .help_str = "read reg <port_id> <reg_off>",
6736         .tokens = {
6737                 (void *)&cmd_read_reg_read,
6738                 (void *)&cmd_read_reg_reg,
6739                 (void *)&cmd_read_reg_port_id,
6740                 (void *)&cmd_read_reg_reg_off,
6741                 NULL,
6742         },
6743 };
6744
6745 /* *** READ PORT REGISTER BIT FIELD *** */
6746 struct cmd_read_reg_bit_field_result {
6747         cmdline_fixed_string_t read;
6748         cmdline_fixed_string_t regfield;
6749         portid_t port_id;
6750         uint32_t reg_off;
6751         uint8_t bit1_pos;
6752         uint8_t bit2_pos;
6753 };
6754
6755 static void
6756 cmd_read_reg_bit_field_parsed(void *parsed_result,
6757                               __attribute__((unused)) struct cmdline *cl,
6758                               __attribute__((unused)) void *data)
6759 {
6760         struct cmd_read_reg_bit_field_result *res = parsed_result;
6761         port_reg_bit_field_display(res->port_id, res->reg_off,
6762                                    res->bit1_pos, res->bit2_pos);
6763 }
6764
6765 cmdline_parse_token_string_t cmd_read_reg_bit_field_read =
6766         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result, read,
6767                                  "read");
6768 cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield =
6769         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_field_result,
6770                                  regfield, "regfield");
6771 cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id =
6772         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id,
6773                               UINT16);
6774 cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off =
6775         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off,
6776                               UINT32);
6777 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit1_pos =
6778         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit1_pos,
6779                               UINT8);
6780 cmdline_parse_token_num_t cmd_read_reg_bit_field_bit2_pos =
6781         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, bit2_pos,
6782                               UINT8);
6783
6784 cmdline_parse_inst_t cmd_read_reg_bit_field = {
6785         .f = cmd_read_reg_bit_field_parsed,
6786         .data = NULL,
6787         .help_str = "read regfield <port_id> <reg_off> <bit_x> <bit_y>: "
6788         "Read register bit field between bit_x and bit_y included",
6789         .tokens = {
6790                 (void *)&cmd_read_reg_bit_field_read,
6791                 (void *)&cmd_read_reg_bit_field_regfield,
6792                 (void *)&cmd_read_reg_bit_field_port_id,
6793                 (void *)&cmd_read_reg_bit_field_reg_off,
6794                 (void *)&cmd_read_reg_bit_field_bit1_pos,
6795                 (void *)&cmd_read_reg_bit_field_bit2_pos,
6796                 NULL,
6797         },
6798 };
6799
6800 /* *** READ PORT REGISTER BIT *** */
6801 struct cmd_read_reg_bit_result {
6802         cmdline_fixed_string_t read;
6803         cmdline_fixed_string_t regbit;
6804         portid_t port_id;
6805         uint32_t reg_off;
6806         uint8_t bit_pos;
6807 };
6808
6809 static void
6810 cmd_read_reg_bit_parsed(void *parsed_result,
6811                         __attribute__((unused)) struct cmdline *cl,
6812                         __attribute__((unused)) void *data)
6813 {
6814         struct cmd_read_reg_bit_result *res = parsed_result;
6815         port_reg_bit_display(res->port_id, res->reg_off, res->bit_pos);
6816 }
6817
6818 cmdline_parse_token_string_t cmd_read_reg_bit_read =
6819         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, read, "read");
6820 cmdline_parse_token_string_t cmd_read_reg_bit_regbit =
6821         TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result,
6822                                  regbit, "regbit");
6823 cmdline_parse_token_num_t cmd_read_reg_bit_port_id =
6824         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16);
6825 cmdline_parse_token_num_t cmd_read_reg_bit_reg_off =
6826         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32);
6827 cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos =
6828         TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, bit_pos, UINT8);
6829
6830 cmdline_parse_inst_t cmd_read_reg_bit = {
6831         .f = cmd_read_reg_bit_parsed,
6832         .data = NULL,
6833         .help_str = "read regbit <port_id> <reg_off> <bit_x>: 0 <= bit_x <= 31",
6834         .tokens = {
6835                 (void *)&cmd_read_reg_bit_read,
6836                 (void *)&cmd_read_reg_bit_regbit,
6837                 (void *)&cmd_read_reg_bit_port_id,
6838                 (void *)&cmd_read_reg_bit_reg_off,
6839                 (void *)&cmd_read_reg_bit_bit_pos,
6840                 NULL,
6841         },
6842 };
6843
6844 /* *** WRITE PORT REGISTER *** */
6845 struct cmd_write_reg_result {
6846         cmdline_fixed_string_t write;
6847         cmdline_fixed_string_t reg;
6848         portid_t port_id;
6849         uint32_t reg_off;
6850         uint32_t value;
6851 };
6852
6853 static void
6854 cmd_write_reg_parsed(void *parsed_result,
6855                      __attribute__((unused)) struct cmdline *cl,
6856                      __attribute__((unused)) void *data)
6857 {
6858         struct cmd_write_reg_result *res = parsed_result;
6859         port_reg_set(res->port_id, res->reg_off, res->value);
6860 }
6861
6862 cmdline_parse_token_string_t cmd_write_reg_write =
6863         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, write, "write");
6864 cmdline_parse_token_string_t cmd_write_reg_reg =
6865         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg");
6866 cmdline_parse_token_num_t cmd_write_reg_port_id =
6867         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16);
6868 cmdline_parse_token_num_t cmd_write_reg_reg_off =
6869         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32);
6870 cmdline_parse_token_num_t cmd_write_reg_value =
6871         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, value, UINT32);
6872
6873 cmdline_parse_inst_t cmd_write_reg = {
6874         .f = cmd_write_reg_parsed,
6875         .data = NULL,
6876         .help_str = "write reg <port_id> <reg_off> <reg_value>",
6877         .tokens = {
6878                 (void *)&cmd_write_reg_write,
6879                 (void *)&cmd_write_reg_reg,
6880                 (void *)&cmd_write_reg_port_id,
6881                 (void *)&cmd_write_reg_reg_off,
6882                 (void *)&cmd_write_reg_value,
6883                 NULL,
6884         },
6885 };
6886
6887 /* *** WRITE PORT REGISTER BIT FIELD *** */
6888 struct cmd_write_reg_bit_field_result {
6889         cmdline_fixed_string_t write;
6890         cmdline_fixed_string_t regfield;
6891         portid_t port_id;
6892         uint32_t reg_off;
6893         uint8_t bit1_pos;
6894         uint8_t bit2_pos;
6895         uint32_t value;
6896 };
6897
6898 static void
6899 cmd_write_reg_bit_field_parsed(void *parsed_result,
6900                                __attribute__((unused)) struct cmdline *cl,
6901                                __attribute__((unused)) void *data)
6902 {
6903         struct cmd_write_reg_bit_field_result *res = parsed_result;
6904         port_reg_bit_field_set(res->port_id, res->reg_off,
6905                           res->bit1_pos, res->bit2_pos, res->value);
6906 }
6907
6908 cmdline_parse_token_string_t cmd_write_reg_bit_field_write =
6909         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result, write,
6910                                  "write");
6911 cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield =
6912         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_field_result,
6913                                  regfield, "regfield");
6914 cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id =
6915         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id,
6916                               UINT16);
6917 cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off =
6918         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off,
6919                               UINT32);
6920 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit1_pos =
6921         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit1_pos,
6922                               UINT8);
6923 cmdline_parse_token_num_t cmd_write_reg_bit_field_bit2_pos =
6924         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, bit2_pos,
6925                               UINT8);
6926 cmdline_parse_token_num_t cmd_write_reg_bit_field_value =
6927         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, value,
6928                               UINT32);
6929
6930 cmdline_parse_inst_t cmd_write_reg_bit_field = {
6931         .f = cmd_write_reg_bit_field_parsed,
6932         .data = NULL,
6933         .help_str = "write regfield <port_id> <reg_off> <bit_x> <bit_y> "
6934                 "<reg_value>: "
6935                 "Set register bit field between bit_x and bit_y included",
6936         .tokens = {
6937                 (void *)&cmd_write_reg_bit_field_write,
6938                 (void *)&cmd_write_reg_bit_field_regfield,
6939                 (void *)&cmd_write_reg_bit_field_port_id,
6940                 (void *)&cmd_write_reg_bit_field_reg_off,
6941                 (void *)&cmd_write_reg_bit_field_bit1_pos,
6942                 (void *)&cmd_write_reg_bit_field_bit2_pos,
6943                 (void *)&cmd_write_reg_bit_field_value,
6944                 NULL,
6945         },
6946 };
6947
6948 /* *** WRITE PORT REGISTER BIT *** */
6949 struct cmd_write_reg_bit_result {
6950         cmdline_fixed_string_t write;
6951         cmdline_fixed_string_t regbit;
6952         portid_t port_id;
6953         uint32_t reg_off;
6954         uint8_t bit_pos;
6955         uint8_t value;
6956 };
6957
6958 static void
6959 cmd_write_reg_bit_parsed(void *parsed_result,
6960                          __attribute__((unused)) struct cmdline *cl,
6961                          __attribute__((unused)) void *data)
6962 {
6963         struct cmd_write_reg_bit_result *res = parsed_result;
6964         port_reg_bit_set(res->port_id, res->reg_off, res->bit_pos, res->value);
6965 }
6966
6967 cmdline_parse_token_string_t cmd_write_reg_bit_write =
6968         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, write,
6969                                  "write");
6970 cmdline_parse_token_string_t cmd_write_reg_bit_regbit =
6971         TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result,
6972                                  regbit, "regbit");
6973 cmdline_parse_token_num_t cmd_write_reg_bit_port_id =
6974         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16);
6975 cmdline_parse_token_num_t cmd_write_reg_bit_reg_off =
6976         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32);
6977 cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos =
6978         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, bit_pos, UINT8);
6979 cmdline_parse_token_num_t cmd_write_reg_bit_value =
6980         TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, value, UINT8);
6981
6982 cmdline_parse_inst_t cmd_write_reg_bit = {
6983         .f = cmd_write_reg_bit_parsed,
6984         .data = NULL,
6985         .help_str = "write regbit <port_id> <reg_off> <bit_x> 0|1: "
6986                 "0 <= bit_x <= 31",
6987         .tokens = {
6988                 (void *)&cmd_write_reg_bit_write,
6989                 (void *)&cmd_write_reg_bit_regbit,
6990                 (void *)&cmd_write_reg_bit_port_id,
6991                 (void *)&cmd_write_reg_bit_reg_off,
6992                 (void *)&cmd_write_reg_bit_bit_pos,
6993                 (void *)&cmd_write_reg_bit_value,
6994                 NULL,
6995         },
6996 };
6997
6998 /* *** READ A RING DESCRIPTOR OF A PORT RX/TX QUEUE *** */
6999 struct cmd_read_rxd_txd_result {
7000         cmdline_fixed_string_t read;
7001         cmdline_fixed_string_t rxd_txd;
7002         portid_t port_id;
7003         uint16_t queue_id;
7004         uint16_t desc_id;
7005 };
7006
7007 static void
7008 cmd_read_rxd_txd_parsed(void *parsed_result,
7009                         __attribute__((unused)) struct cmdline *cl,
7010                         __attribute__((unused)) void *data)
7011 {
7012         struct cmd_read_rxd_txd_result *res = parsed_result;
7013
7014         if (!strcmp(res->rxd_txd, "rxd"))
7015                 rx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7016         else if (!strcmp(res->rxd_txd, "txd"))
7017                 tx_ring_desc_display(res->port_id, res->queue_id, res->desc_id);
7018 }
7019
7020 cmdline_parse_token_string_t cmd_read_rxd_txd_read =
7021         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, read, "read");
7022 cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd =
7023         TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd,
7024                                  "rxd#txd");
7025 cmdline_parse_token_num_t cmd_read_rxd_txd_port_id =
7026         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16);
7027 cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id =
7028         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16);
7029 cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id =
7030         TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, desc_id, UINT16);
7031
7032 cmdline_parse_inst_t cmd_read_rxd_txd = {
7033         .f = cmd_read_rxd_txd_parsed,
7034         .data = NULL,
7035         .help_str = "read rxd|txd <port_id> <queue_id> <desc_id>",
7036         .tokens = {
7037                 (void *)&cmd_read_rxd_txd_read,
7038                 (void *)&cmd_read_rxd_txd_rxd_txd,
7039                 (void *)&cmd_read_rxd_txd_port_id,
7040                 (void *)&cmd_read_rxd_txd_queue_id,
7041                 (void *)&cmd_read_rxd_txd_desc_id,
7042                 NULL,
7043         },
7044 };
7045
7046 /* *** QUIT *** */
7047 struct cmd_quit_result {
7048         cmdline_fixed_string_t quit;
7049 };
7050
7051 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
7052                             struct cmdline *cl,
7053                             __attribute__((unused)) void *data)
7054 {
7055         pmd_test_exit();
7056         cmdline_quit(cl);
7057 }
7058
7059 cmdline_parse_token_string_t cmd_quit_quit =
7060         TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
7061
7062 cmdline_parse_inst_t cmd_quit = {
7063         .f = cmd_quit_parsed,
7064         .data = NULL,
7065         .help_str = "quit: Exit application",
7066         .tokens = {
7067                 (void *)&cmd_quit_quit,
7068                 NULL,
7069         },
7070 };
7071
7072 /* *** ADD/REMOVE MAC ADDRESS FROM A PORT *** */
7073 struct cmd_mac_addr_result {
7074         cmdline_fixed_string_t mac_addr_cmd;
7075         cmdline_fixed_string_t what;
7076         uint16_t port_num;
7077         struct ether_addr address;
7078 };
7079
7080 static void cmd_mac_addr_parsed(void *parsed_result,
7081                 __attribute__((unused)) struct cmdline *cl,
7082                 __attribute__((unused)) void *data)
7083 {
7084         struct cmd_mac_addr_result *res = parsed_result;
7085         int ret;
7086
7087         if (strcmp(res->what, "add") == 0)
7088                 ret = rte_eth_dev_mac_addr_add(res->port_num, &res->address, 0);
7089         else if (strcmp(res->what, "set") == 0)
7090                 ret = rte_eth_dev_default_mac_addr_set(res->port_num,
7091                                                        &res->address);
7092         else
7093                 ret = rte_eth_dev_mac_addr_remove(res->port_num, &res->address);
7094
7095         /* check the return value and print it if is < 0 */
7096         if(ret < 0)
7097                 printf("mac_addr_cmd error: (%s)\n", strerror(-ret));
7098
7099 }
7100
7101 cmdline_parse_token_string_t cmd_mac_addr_cmd =
7102         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, mac_addr_cmd,
7103                                 "mac_addr");
7104 cmdline_parse_token_string_t cmd_mac_addr_what =
7105         TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what,
7106                                 "add#remove#set");
7107 cmdline_parse_token_num_t cmd_mac_addr_portnum =
7108                 TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num,
7109                                         UINT16);
7110 cmdline_parse_token_etheraddr_t cmd_mac_addr_addr =
7111                 TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
7112
7113 cmdline_parse_inst_t cmd_mac_addr = {
7114         .f = cmd_mac_addr_parsed,
7115         .data = (void *)0,
7116         .help_str = "mac_addr add|remove|set <port_id> <mac_addr>: "
7117                         "Add/Remove/Set MAC address on port_id",
7118         .tokens = {
7119                 (void *)&cmd_mac_addr_cmd,
7120                 (void *)&cmd_mac_addr_what,
7121                 (void *)&cmd_mac_addr_portnum,
7122                 (void *)&cmd_mac_addr_addr,
7123                 NULL,
7124         },
7125 };
7126
7127
7128 /* *** CONFIGURE QUEUE STATS COUNTER MAPPINGS *** */
7129 struct cmd_set_qmap_result {
7130         cmdline_fixed_string_t set;
7131         cmdline_fixed_string_t qmap;
7132         cmdline_fixed_string_t what;
7133         portid_t port_id;
7134         uint16_t queue_id;
7135         uint8_t map_value;
7136 };
7137
7138 static void
7139 cmd_set_qmap_parsed(void *parsed_result,
7140                        __attribute__((unused)) struct cmdline *cl,
7141                        __attribute__((unused)) void *data)
7142 {
7143         struct cmd_set_qmap_result *res = parsed_result;
7144         int is_rx = (strcmp(res->what, "tx") == 0) ? 0 : 1;
7145
7146         set_qmap(res->port_id, (uint8_t)is_rx, res->queue_id, res->map_value);
7147 }
7148
7149 cmdline_parse_token_string_t cmd_setqmap_set =
7150         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7151                                  set, "set");
7152 cmdline_parse_token_string_t cmd_setqmap_qmap =
7153         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7154                                  qmap, "stat_qmap");
7155 cmdline_parse_token_string_t cmd_setqmap_what =
7156         TOKEN_STRING_INITIALIZER(struct cmd_set_qmap_result,
7157                                  what, "tx#rx");
7158 cmdline_parse_token_num_t cmd_setqmap_portid =
7159         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7160                               port_id, UINT16);
7161 cmdline_parse_token_num_t cmd_setqmap_queueid =
7162         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7163                               queue_id, UINT16);
7164 cmdline_parse_token_num_t cmd_setqmap_mapvalue =
7165         TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result,
7166                               map_value, UINT8);
7167
7168 cmdline_parse_inst_t cmd_set_qmap = {
7169         .f = cmd_set_qmap_parsed,
7170         .data = NULL,
7171         .help_str = "set stat_qmap rx|tx <port_id> <queue_id> <map_value>: "
7172                 "Set statistics mapping value on tx|rx queue_id of port_id",
7173         .tokens = {
7174                 (void *)&cmd_setqmap_set,
7175                 (void *)&cmd_setqmap_qmap,
7176                 (void *)&cmd_setqmap_what,
7177                 (void *)&cmd_setqmap_portid,
7178                 (void *)&cmd_setqmap_queueid,
7179                 (void *)&cmd_setqmap_mapvalue,
7180                 NULL,
7181         },
7182 };
7183
7184 /* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS  DISPLAY *** */
7185 struct cmd_set_xstats_hide_zero_result {
7186         cmdline_fixed_string_t keyword;
7187         cmdline_fixed_string_t name;
7188         cmdline_fixed_string_t on_off;
7189 };
7190
7191 static void
7192 cmd_set_xstats_hide_zero_parsed(void *parsed_result,
7193                         __attribute__((unused)) struct cmdline *cl,
7194                         __attribute__((unused)) void *data)
7195 {
7196         struct cmd_set_xstats_hide_zero_result *res;
7197         uint16_t on_off = 0;
7198
7199         res = parsed_result;
7200         on_off = !strcmp(res->on_off, "on") ? 1 : 0;
7201         set_xstats_hide_zero(on_off);
7202 }
7203
7204 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword =
7205         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7206                                  keyword, "set");
7207 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name =
7208         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7209                                  name, "xstats-hide-zero");
7210 cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off =
7211         TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result,
7212                                  on_off, "on#off");
7213
7214 cmdline_parse_inst_t cmd_set_xstats_hide_zero = {
7215         .f = cmd_set_xstats_hide_zero_parsed,
7216         .data = NULL,
7217         .help_str = "set xstats-hide-zero on|off",
7218         .tokens = {
7219                 (void *)&cmd_set_xstats_hide_zero_keyword,
7220                 (void *)&cmd_set_xstats_hide_zero_name,
7221                 (void *)&cmd_set_xstats_hide_zero_on_off,
7222                 NULL,
7223         },
7224 };
7225
7226 /* *** CONFIGURE UNICAST HASH TABLE *** */
7227 struct cmd_set_uc_hash_table {
7228         cmdline_fixed_string_t set;
7229         cmdline_fixed_string_t port;
7230         portid_t port_id;
7231         cmdline_fixed_string_t what;
7232         struct ether_addr address;
7233         cmdline_fixed_string_t mode;
7234 };
7235
7236 static void
7237 cmd_set_uc_hash_parsed(void *parsed_result,
7238                        __attribute__((unused)) struct cmdline *cl,
7239                        __attribute__((unused)) void *data)
7240 {
7241         int ret=0;
7242         struct cmd_set_uc_hash_table *res = parsed_result;
7243
7244         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7245
7246         if (strcmp(res->what, "uta") == 0)
7247                 ret = rte_eth_dev_uc_hash_table_set(res->port_id,
7248                                                 &res->address,(uint8_t)is_on);
7249         if (ret < 0)
7250                 printf("bad unicast hash table parameter, return code = %d \n", ret);
7251
7252 }
7253
7254 cmdline_parse_token_string_t cmd_set_uc_hash_set =
7255         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7256                                  set, "set");
7257 cmdline_parse_token_string_t cmd_set_uc_hash_port =
7258         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7259                                  port, "port");
7260 cmdline_parse_token_num_t cmd_set_uc_hash_portid =
7261         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table,
7262                               port_id, UINT16);
7263 cmdline_parse_token_string_t cmd_set_uc_hash_what =
7264         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7265                                  what, "uta");
7266 cmdline_parse_token_etheraddr_t cmd_set_uc_hash_mac =
7267         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_uc_hash_table,
7268                                 address);
7269 cmdline_parse_token_string_t cmd_set_uc_hash_mode =
7270         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table,
7271                                  mode, "on#off");
7272
7273 cmdline_parse_inst_t cmd_set_uc_hash_filter = {
7274         .f = cmd_set_uc_hash_parsed,
7275         .data = NULL,
7276         .help_str = "set port <port_id> uta <mac_addr> on|off)",
7277         .tokens = {
7278                 (void *)&cmd_set_uc_hash_set,
7279                 (void *)&cmd_set_uc_hash_port,
7280                 (void *)&cmd_set_uc_hash_portid,
7281                 (void *)&cmd_set_uc_hash_what,
7282                 (void *)&cmd_set_uc_hash_mac,
7283                 (void *)&cmd_set_uc_hash_mode,
7284                 NULL,
7285         },
7286 };
7287
7288 struct cmd_set_uc_all_hash_table {
7289         cmdline_fixed_string_t set;
7290         cmdline_fixed_string_t port;
7291         portid_t port_id;
7292         cmdline_fixed_string_t what;
7293         cmdline_fixed_string_t value;
7294         cmdline_fixed_string_t mode;
7295 };
7296
7297 static void
7298 cmd_set_uc_all_hash_parsed(void *parsed_result,
7299                        __attribute__((unused)) struct cmdline *cl,
7300                        __attribute__((unused)) void *data)
7301 {
7302         int ret=0;
7303         struct cmd_set_uc_all_hash_table *res = parsed_result;
7304
7305         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7306
7307         if ((strcmp(res->what, "uta") == 0) &&
7308                 (strcmp(res->value, "all") == 0))
7309                 ret = rte_eth_dev_uc_all_hash_table_set(res->port_id,(uint8_t) is_on);
7310         if (ret < 0)
7311                 printf("bad unicast hash table parameter,"
7312                         "return code = %d \n", ret);
7313 }
7314
7315 cmdline_parse_token_string_t cmd_set_uc_all_hash_set =
7316         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7317                                  set, "set");
7318 cmdline_parse_token_string_t cmd_set_uc_all_hash_port =
7319         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7320                                  port, "port");
7321 cmdline_parse_token_num_t cmd_set_uc_all_hash_portid =
7322         TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table,
7323                               port_id, UINT16);
7324 cmdline_parse_token_string_t cmd_set_uc_all_hash_what =
7325         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7326                                  what, "uta");
7327 cmdline_parse_token_string_t cmd_set_uc_all_hash_value =
7328         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7329                                 value,"all");
7330 cmdline_parse_token_string_t cmd_set_uc_all_hash_mode =
7331         TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table,
7332                                  mode, "on#off");
7333
7334 cmdline_parse_inst_t cmd_set_uc_all_hash_filter = {
7335         .f = cmd_set_uc_all_hash_parsed,
7336         .data = NULL,
7337         .help_str = "set port <port_id> uta all on|off",
7338         .tokens = {
7339                 (void *)&cmd_set_uc_all_hash_set,
7340                 (void *)&cmd_set_uc_all_hash_port,
7341                 (void *)&cmd_set_uc_all_hash_portid,
7342                 (void *)&cmd_set_uc_all_hash_what,
7343                 (void *)&cmd_set_uc_all_hash_value,
7344                 (void *)&cmd_set_uc_all_hash_mode,
7345                 NULL,
7346         },
7347 };
7348
7349 /* *** CONFIGURE MACVLAN FILTER FOR VF(s) *** */
7350 struct cmd_set_vf_macvlan_filter {
7351         cmdline_fixed_string_t set;
7352         cmdline_fixed_string_t port;
7353         portid_t port_id;
7354         cmdline_fixed_string_t vf;
7355         uint8_t vf_id;
7356         struct ether_addr address;
7357         cmdline_fixed_string_t filter_type;
7358         cmdline_fixed_string_t mode;
7359 };
7360
7361 static void
7362 cmd_set_vf_macvlan_parsed(void *parsed_result,
7363                        __attribute__((unused)) struct cmdline *cl,
7364                        __attribute__((unused)) void *data)
7365 {
7366         int is_on, ret = 0;
7367         struct cmd_set_vf_macvlan_filter *res = parsed_result;
7368         struct rte_eth_mac_filter filter;
7369
7370         memset(&filter, 0, sizeof(struct rte_eth_mac_filter));
7371
7372         rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN);
7373
7374         /* set VF MAC filter */
7375         filter.is_vf = 1;
7376
7377         /* set VF ID */
7378         filter.dst_id = res->vf_id;
7379
7380         if (!strcmp(res->filter_type, "exact-mac"))
7381                 filter.filter_type = RTE_MAC_PERFECT_MATCH;
7382         else if (!strcmp(res->filter_type, "exact-mac-vlan"))
7383                 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
7384         else if (!strcmp(res->filter_type, "hashmac"))
7385                 filter.filter_type = RTE_MAC_HASH_MATCH;
7386         else if (!strcmp(res->filter_type, "hashmac-vlan"))
7387                 filter.filter_type = RTE_MACVLAN_HASH_MATCH;
7388
7389         is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7390
7391         if (is_on)
7392                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7393                                         RTE_ETH_FILTER_MACVLAN,
7394                                         RTE_ETH_FILTER_ADD,
7395                                          &filter);
7396         else
7397                 ret = rte_eth_dev_filter_ctrl(res->port_id,
7398                                         RTE_ETH_FILTER_MACVLAN,
7399                                         RTE_ETH_FILTER_DELETE,
7400                                         &filter);
7401
7402         if (ret < 0)
7403                 printf("bad set MAC hash parameter, return code = %d\n", ret);
7404
7405 }
7406
7407 cmdline_parse_token_string_t cmd_set_vf_macvlan_set =
7408         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7409                                  set, "set");
7410 cmdline_parse_token_string_t cmd_set_vf_macvlan_port =
7411         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7412                                  port, "port");
7413 cmdline_parse_token_num_t cmd_set_vf_macvlan_portid =
7414         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7415                               port_id, UINT16);
7416 cmdline_parse_token_string_t cmd_set_vf_macvlan_vf =
7417         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7418                                  vf, "vf");
7419 cmdline_parse_token_num_t cmd_set_vf_macvlan_vf_id =
7420         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7421                                 vf_id, UINT8);
7422 cmdline_parse_token_etheraddr_t cmd_set_vf_macvlan_mac =
7423         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7424                                 address);
7425 cmdline_parse_token_string_t cmd_set_vf_macvlan_filter_type =
7426         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7427                                 filter_type, "exact-mac#exact-mac-vlan"
7428                                 "#hashmac#hashmac-vlan");
7429 cmdline_parse_token_string_t cmd_set_vf_macvlan_mode =
7430         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter,
7431                                  mode, "on#off");
7432
7433 cmdline_parse_inst_t cmd_set_vf_macvlan_filter = {
7434         .f = cmd_set_vf_macvlan_parsed,
7435         .data = NULL,
7436         .help_str = "set port <port_id> vf <vf_id> <mac_addr> "
7437                 "exact-mac|exact-mac-vlan|hashmac|hashmac-vlan on|off: "
7438                 "Exact match rule: exact match of MAC or MAC and VLAN; "
7439                 "hash match rule: hash match of MAC and exact match of VLAN",
7440         .tokens = {
7441                 (void *)&cmd_set_vf_macvlan_set,
7442                 (void *)&cmd_set_vf_macvlan_port,
7443                 (void *)&cmd_set_vf_macvlan_portid,
7444                 (void *)&cmd_set_vf_macvlan_vf,
7445                 (void *)&cmd_set_vf_macvlan_vf_id,
7446                 (void *)&cmd_set_vf_macvlan_mac,
7447                 (void *)&cmd_set_vf_macvlan_filter_type,
7448                 (void *)&cmd_set_vf_macvlan_mode,
7449                 NULL,
7450         },
7451 };
7452
7453 /* *** CONFIGURE VF TRAFFIC CONTROL *** */
7454 struct cmd_set_vf_traffic {
7455         cmdline_fixed_string_t set;
7456         cmdline_fixed_string_t port;
7457         portid_t port_id;
7458         cmdline_fixed_string_t vf;
7459         uint8_t vf_id;
7460         cmdline_fixed_string_t what;
7461         cmdline_fixed_string_t mode;
7462 };
7463
7464 static void
7465 cmd_set_vf_traffic_parsed(void *parsed_result,
7466                        __attribute__((unused)) struct cmdline *cl,
7467                        __attribute__((unused)) void *data)
7468 {
7469         struct cmd_set_vf_traffic *res = parsed_result;
7470         int is_rx = (strcmp(res->what, "rx") == 0) ? 1 : 0;
7471         int is_on = (strcmp(res->mode, "on") == 0) ? 1 : 0;
7472
7473         set_vf_traffic(res->port_id, (uint8_t)is_rx, res->vf_id,(uint8_t) is_on);
7474 }
7475
7476 cmdline_parse_token_string_t cmd_setvf_traffic_set =
7477         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7478                                  set, "set");
7479 cmdline_parse_token_string_t cmd_setvf_traffic_port =
7480         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7481                                  port, "port");
7482 cmdline_parse_token_num_t cmd_setvf_traffic_portid =
7483         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7484                               port_id, UINT16);
7485 cmdline_parse_token_string_t cmd_setvf_traffic_vf =
7486         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7487                                  vf, "vf");
7488 cmdline_parse_token_num_t cmd_setvf_traffic_vfid =
7489         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic,
7490                               vf_id, UINT8);
7491 cmdline_parse_token_string_t cmd_setvf_traffic_what =
7492         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7493                                  what, "tx#rx");
7494 cmdline_parse_token_string_t cmd_setvf_traffic_mode =
7495         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic,
7496                                  mode, "on#off");
7497
7498 cmdline_parse_inst_t cmd_set_vf_traffic = {
7499         .f = cmd_set_vf_traffic_parsed,
7500         .data = NULL,
7501         .help_str = "set port <port_id> vf <vf_id> rx|tx on|off",
7502         .tokens = {
7503                 (void *)&cmd_setvf_traffic_set,
7504                 (void *)&cmd_setvf_traffic_port,
7505                 (void *)&cmd_setvf_traffic_portid,
7506                 (void *)&cmd_setvf_traffic_vf,
7507                 (void *)&cmd_setvf_traffic_vfid,
7508                 (void *)&cmd_setvf_traffic_what,
7509                 (void *)&cmd_setvf_traffic_mode,
7510                 NULL,
7511         },
7512 };
7513
7514 /* *** CONFIGURE VF RECEIVE MODE *** */
7515 struct cmd_set_vf_rxmode {
7516         cmdline_fixed_string_t set;
7517         cmdline_fixed_string_t port;
7518         portid_t port_id;
7519         cmdline_fixed_string_t vf;
7520         uint8_t vf_id;
7521         cmdline_fixed_string_t what;
7522         cmdline_fixed_string_t mode;
7523         cmdline_fixed_string_t on;
7524 };
7525
7526 static void
7527 cmd_set_vf_rxmode_parsed(void *parsed_result,
7528                        __attribute__((unused)) struct cmdline *cl,
7529                        __attribute__((unused)) void *data)
7530 {
7531         int ret = -ENOTSUP;
7532         uint16_t rx_mode = 0;
7533         struct cmd_set_vf_rxmode *res = parsed_result;
7534
7535         int is_on = (strcmp(res->on, "on") == 0) ? 1 : 0;
7536         if (!strcmp(res->what,"rxmode")) {
7537                 if (!strcmp(res->mode, "AUPE"))
7538                         rx_mode |= ETH_VMDQ_ACCEPT_UNTAG;
7539                 else if (!strcmp(res->mode, "ROPE"))
7540                         rx_mode |= ETH_VMDQ_ACCEPT_HASH_UC;
7541                 else if (!strcmp(res->mode, "BAM"))
7542                         rx_mode |= ETH_VMDQ_ACCEPT_BROADCAST;
7543                 else if (!strncmp(res->mode, "MPE",3))
7544                         rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST;
7545         }
7546
7547         RTE_SET_USED(is_on);
7548
7549 #ifdef RTE_LIBRTE_IXGBE_PMD
7550         if (ret == -ENOTSUP)
7551                 ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id,
7552                                                   rx_mode, (uint8_t)is_on);
7553 #endif
7554 #ifdef RTE_LIBRTE_BNXT_PMD
7555         if (ret == -ENOTSUP)
7556                 ret = rte_pmd_bnxt_set_vf_rxmode(res->port_id, res->vf_id,
7557                                                  rx_mode, (uint8_t)is_on);
7558 #endif
7559         if (ret < 0)
7560                 printf("bad VF receive mode parameter, return code = %d \n",
7561                 ret);
7562 }
7563
7564 cmdline_parse_token_string_t cmd_set_vf_rxmode_set =
7565         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7566                                  set, "set");
7567 cmdline_parse_token_string_t cmd_set_vf_rxmode_port =
7568         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7569                                  port, "port");
7570 cmdline_parse_token_num_t cmd_set_vf_rxmode_portid =
7571         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7572                               port_id, UINT16);
7573 cmdline_parse_token_string_t cmd_set_vf_rxmode_vf =
7574         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7575                                  vf, "vf");
7576 cmdline_parse_token_num_t cmd_set_vf_rxmode_vfid =
7577         TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode,
7578                               vf_id, UINT8);
7579 cmdline_parse_token_string_t cmd_set_vf_rxmode_what =
7580         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7581                                  what, "rxmode");
7582 cmdline_parse_token_string_t cmd_set_vf_rxmode_mode =
7583         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7584                                  mode, "AUPE#ROPE#BAM#MPE");
7585 cmdline_parse_token_string_t cmd_set_vf_rxmode_on =
7586         TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode,
7587                                  on, "on#off");
7588
7589 cmdline_parse_inst_t cmd_set_vf_rxmode = {
7590         .f = cmd_set_vf_rxmode_parsed,
7591         .data = NULL,
7592         .help_str = "set port <port_id> vf <vf_id> rxmode "
7593                 "AUPE|ROPE|BAM|MPE on|off",
7594         .tokens = {
7595                 (void *)&cmd_set_vf_rxmode_set,
7596                 (void *)&cmd_set_vf_rxmode_port,
7597                 (void *)&cmd_set_vf_rxmode_portid,
7598                 (void *)&cmd_set_vf_rxmode_vf,
7599                 (void *)&cmd_set_vf_rxmode_vfid,
7600                 (void *)&cmd_set_vf_rxmode_what,
7601                 (void *)&cmd_set_vf_rxmode_mode,
7602                 (void *)&cmd_set_vf_rxmode_on,
7603                 NULL,
7604         },
7605 };
7606
7607 /* *** ADD MAC ADDRESS FILTER FOR A VF OF A PORT *** */
7608 struct cmd_vf_mac_addr_result {
7609         cmdline_fixed_string_t mac_addr_cmd;
7610         cmdline_fixed_string_t what;
7611         cmdline_fixed_string_t port;
7612         uint16_t port_num;
7613         cmdline_fixed_string_t vf;
7614         uint8_t vf_num;
7615         struct ether_addr address;
7616 };
7617
7618 static void cmd_vf_mac_addr_parsed(void *parsed_result,
7619                 __attribute__((unused)) struct cmdline *cl,
7620                 __attribute__((unused)) void *data)
7621 {
7622         struct cmd_vf_mac_addr_result *res = parsed_result;
7623         int ret = -ENOTSUP;
7624
7625         if (strcmp(res->what, "add") != 0)
7626                 return;
7627
7628 #ifdef RTE_LIBRTE_I40E_PMD
7629         if (ret == -ENOTSUP)
7630                 ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num,
7631                                                    &res->address);
7632 #endif
7633 #ifdef RTE_LIBRTE_BNXT_PMD
7634         if (ret == -ENOTSUP)
7635                 ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address,
7636                                                 res->vf_num);
7637 #endif
7638
7639         if(ret < 0)
7640                 printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret));
7641
7642 }
7643
7644 cmdline_parse_token_string_t cmd_vf_mac_addr_cmd =
7645         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7646                                 mac_addr_cmd,"mac_addr");
7647 cmdline_parse_token_string_t cmd_vf_mac_addr_what =
7648         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7649                                 what,"add");
7650 cmdline_parse_token_string_t cmd_vf_mac_addr_port =
7651         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7652                                 port,"port");
7653 cmdline_parse_token_num_t cmd_vf_mac_addr_portnum =
7654         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7655                                 port_num, UINT16);
7656 cmdline_parse_token_string_t cmd_vf_mac_addr_vf =
7657         TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result,
7658                                 vf,"vf");
7659 cmdline_parse_token_num_t cmd_vf_mac_addr_vfnum =
7660         TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result,
7661                                 vf_num, UINT8);
7662 cmdline_parse_token_etheraddr_t cmd_vf_mac_addr_addr =
7663         TOKEN_ETHERADDR_INITIALIZER(struct cmd_vf_mac_addr_result,
7664                                 address);
7665
7666 cmdline_parse_inst_t cmd_vf_mac_addr_filter = {
7667         .f = cmd_vf_mac_addr_parsed,
7668         .data = (void *)0,
7669         .help_str = "mac_addr add port <port_id> vf <vf_id> <mac_addr>: "
7670                 "Add MAC address filtering for a VF on port_id",
7671         .tokens = {
7672                 (void *)&cmd_vf_mac_addr_cmd,
7673                 (void *)&cmd_vf_mac_addr_what,
7674                 (void *)&cmd_vf_mac_addr_port,
7675                 (void *)&cmd_vf_mac_addr_portnum,
7676                 (void *)&cmd_vf_mac_addr_vf,
7677                 (void *)&cmd_vf_mac_addr_vfnum,
7678                 (void *)&cmd_vf_mac_addr_addr,
7679                 NULL,
7680         },
7681 };
7682
7683 /* *** ADD/REMOVE A VLAN IDENTIFIER TO/FROM A PORT VLAN RX FILTER *** */
7684 struct cmd_vf_rx_vlan_filter {
7685         cmdline_fixed_string_t rx_vlan;
7686         cmdline_fixed_string_t what;
7687         uint16_t vlan_id;
7688         cmdline_fixed_string_t port;
7689         portid_t port_id;
7690         cmdline_fixed_string_t vf;
7691         uint64_t vf_mask;
7692 };
7693
7694 static void
7695 cmd_vf_rx_vlan_filter_parsed(void *parsed_result,
7696                           __attribute__((unused)) struct cmdline *cl,
7697                           __attribute__((unused)) void *data)
7698 {
7699         struct cmd_vf_rx_vlan_filter *res = parsed_result;
7700         int ret = -ENOTSUP;
7701
7702         __rte_unused int is_add = (strcmp(res->what, "add") == 0) ? 1 : 0;
7703
7704 #ifdef RTE_LIBRTE_IXGBE_PMD
7705         if (ret == -ENOTSUP)
7706                 ret = rte_pmd_ixgbe_set_vf_vlan_filter(res->port_id,
7707                                 res->vlan_id, res->vf_mask, is_add);
7708 #endif
7709 #ifdef RTE_LIBRTE_I40E_PMD
7710         if (ret == -ENOTSUP)
7711                 ret = rte_pmd_i40e_set_vf_vlan_filter(res->port_id,
7712                                 res->vlan_id, res->vf_mask, is_add);
7713 #endif
7714 #ifdef RTE_LIBRTE_BNXT_PMD
7715         if (ret == -ENOTSUP)
7716                 ret = rte_pmd_bnxt_set_vf_vlan_filter(res->port_id,
7717                                 res->vlan_id, res->vf_mask, is_add);
7718 #endif
7719
7720         switch (ret) {
7721         case 0:
7722                 break;
7723         case -EINVAL:
7724                 printf("invalid vlan_id %d or vf_mask %"PRIu64"\n",
7725                                 res->vlan_id, res->vf_mask);
7726                 break;
7727         case -ENODEV:
7728                 printf("invalid port_id %d\n", res->port_id);
7729                 break;
7730         case -ENOTSUP:
7731                 printf("function not implemented or supported\n");
7732                 break;
7733         default:
7734                 printf("programming error: (%s)\n", strerror(-ret));
7735         }
7736 }
7737
7738 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_rx_vlan =
7739         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7740                                  rx_vlan, "rx_vlan");
7741 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_what =
7742         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7743                                  what, "add#rm");
7744 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vlanid =
7745         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7746                               vlan_id, UINT16);
7747 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port =
7748         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7749                                  port, "port");
7750 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid =
7751         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7752                               port_id, UINT16);
7753 cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf =
7754         TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7755                                  vf, "vf");
7756 cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_vf_mask =
7757         TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter,
7758                               vf_mask, UINT64);
7759
7760 cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
7761         .f = cmd_vf_rx_vlan_filter_parsed,
7762         .data = NULL,
7763         .help_str = "rx_vlan add|rm <vlan_id> port <port_id> vf <vf_mask>: "
7764                 "(vf_mask = hexadecimal VF mask)",
7765         .tokens = {
7766                 (void *)&cmd_vf_rx_vlan_filter_rx_vlan,
7767                 (void *)&cmd_vf_rx_vlan_filter_what,
7768                 (void *)&cmd_vf_rx_vlan_filter_vlanid,
7769                 (void *)&cmd_vf_rx_vlan_filter_port,
7770                 (void *)&cmd_vf_rx_vlan_filter_portid,
7771                 (void *)&cmd_vf_rx_vlan_filter_vf,
7772                 (void *)&cmd_vf_rx_vlan_filter_vf_mask,
7773                 NULL,
7774         },
7775 };
7776
7777 /* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
7778 struct cmd_queue_rate_limit_result {
7779         cmdline_fixed_string_t set;
7780         cmdline_fixed_string_t port;
7781         uint16_t port_num;
7782         cmdline_fixed_string_t queue;
7783         uint8_t queue_num;
7784         cmdline_fixed_string_t rate;
7785         uint16_t rate_num;
7786 };
7787
7788 static void cmd_queue_rate_limit_parsed(void *parsed_result,
7789                 __attribute__((unused)) struct cmdline *cl,
7790                 __attribute__((unused)) void *data)
7791 {
7792         struct cmd_queue_rate_limit_result *res = parsed_result;
7793         int ret = 0;
7794
7795         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7796                 && (strcmp(res->queue, "queue") == 0)
7797                 && (strcmp(res->rate, "rate") == 0))
7798                 ret = set_queue_rate_limit(res->port_num, res->queue_num,
7799                                         res->rate_num);
7800         if (ret < 0)
7801                 printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
7802
7803 }
7804
7805 cmdline_parse_token_string_t cmd_queue_rate_limit_set =
7806         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7807                                 set, "set");
7808 cmdline_parse_token_string_t cmd_queue_rate_limit_port =
7809         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7810                                 port, "port");
7811 cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
7812         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7813                                 port_num, UINT16);
7814 cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
7815         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7816                                 queue, "queue");
7817 cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
7818         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7819                                 queue_num, UINT8);
7820 cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
7821         TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
7822                                 rate, "rate");
7823 cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
7824         TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
7825                                 rate_num, UINT16);
7826
7827 cmdline_parse_inst_t cmd_queue_rate_limit = {
7828         .f = cmd_queue_rate_limit_parsed,
7829         .data = (void *)0,
7830         .help_str = "set port <port_id> queue <queue_id> rate <rate_value>: "
7831                 "Set rate limit for a queue on port_id",
7832         .tokens = {
7833                 (void *)&cmd_queue_rate_limit_set,
7834                 (void *)&cmd_queue_rate_limit_port,
7835                 (void *)&cmd_queue_rate_limit_portnum,
7836                 (void *)&cmd_queue_rate_limit_queue,
7837                 (void *)&cmd_queue_rate_limit_queuenum,
7838                 (void *)&cmd_queue_rate_limit_rate,
7839                 (void *)&cmd_queue_rate_limit_ratenum,
7840                 NULL,
7841         },
7842 };
7843
7844 /* *** SET RATE LIMIT FOR A VF OF A PORT *** */
7845 struct cmd_vf_rate_limit_result {
7846         cmdline_fixed_string_t set;
7847         cmdline_fixed_string_t port;
7848         uint16_t port_num;
7849         cmdline_fixed_string_t vf;
7850         uint8_t vf_num;
7851         cmdline_fixed_string_t rate;
7852         uint16_t rate_num;
7853         cmdline_fixed_string_t q_msk;
7854         uint64_t q_msk_val;
7855 };
7856
7857 static void cmd_vf_rate_limit_parsed(void *parsed_result,
7858                 __attribute__((unused)) struct cmdline *cl,
7859                 __attribute__((unused)) void *data)
7860 {
7861         struct cmd_vf_rate_limit_result *res = parsed_result;
7862         int ret = 0;
7863
7864         if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
7865                 && (strcmp(res->vf, "vf") == 0)
7866                 && (strcmp(res->rate, "rate") == 0)
7867                 && (strcmp(res->q_msk, "queue_mask") == 0))
7868                 ret = set_vf_rate_limit(res->port_num, res->vf_num,
7869                                         res->rate_num, res->q_msk_val);
7870         if (ret < 0)
7871                 printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
7872
7873 }
7874
7875 cmdline_parse_token_string_t cmd_vf_rate_limit_set =
7876         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7877                                 set, "set");
7878 cmdline_parse_token_string_t cmd_vf_rate_limit_port =
7879         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7880                                 port, "port");
7881 cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
7882         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7883                                 port_num, UINT16);
7884 cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
7885         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7886                                 vf, "vf");
7887 cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
7888         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7889                                 vf_num, UINT8);
7890 cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
7891         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7892                                 rate, "rate");
7893 cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
7894         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7895                                 rate_num, UINT16);
7896 cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
7897         TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
7898                                 q_msk, "queue_mask");
7899 cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
7900         TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
7901                                 q_msk_val, UINT64);
7902
7903 cmdline_parse_inst_t cmd_vf_rate_limit = {
7904         .f = cmd_vf_rate_limit_parsed,
7905         .data = (void *)0,
7906         .help_str = "set port <port_id> vf <vf_id> rate <rate_value> "
7907                 "queue_mask <queue_mask_value>: "
7908                 "Set rate limit for queues of VF on port_id",
7909         .tokens = {
7910                 (void *)&cmd_vf_rate_limit_set,
7911                 (void *)&cmd_vf_rate_limit_port,
7912                 (void *)&cmd_vf_rate_limit_portnum,
7913                 (void *)&cmd_vf_rate_limit_vf,
7914                 (void *)&cmd_vf_rate_limit_vfnum,
7915                 (void *)&cmd_vf_rate_limit_rate,
7916                 (void *)&cmd_vf_rate_limit_ratenum,
7917                 (void *)&cmd_vf_rate_limit_q_msk,
7918                 (void *)&cmd_vf_rate_limit_q_msk_val,
7919                 NULL,
7920         },
7921 };
7922
7923 /* *** ADD TUNNEL FILTER OF A PORT *** */
7924 struct cmd_tunnel_filter_result {
7925         cmdline_fixed_string_t cmd;
7926         cmdline_fixed_string_t what;
7927         portid_t port_id;
7928         struct ether_addr outer_mac;
7929         struct ether_addr inner_mac;
7930         cmdline_ipaddr_t ip_value;
7931         uint16_t inner_vlan;
7932         cmdline_fixed_string_t tunnel_type;
7933         cmdline_fixed_string_t filter_type;
7934         uint32_t tenant_id;
7935         uint16_t queue_num;
7936 };
7937
7938 static void
7939 cmd_tunnel_filter_parsed(void *parsed_result,
7940                           __attribute__((unused)) struct cmdline *cl,
7941                           __attribute__((unused)) void *data)
7942 {
7943         struct cmd_tunnel_filter_result *res = parsed_result;
7944         struct rte_eth_tunnel_filter_conf tunnel_filter_conf;
7945         int ret = 0;
7946
7947         memset(&tunnel_filter_conf, 0, sizeof(tunnel_filter_conf));
7948
7949         ether_addr_copy(&res->outer_mac, &tunnel_filter_conf.outer_mac);
7950         ether_addr_copy(&res->inner_mac, &tunnel_filter_conf.inner_mac);
7951         tunnel_filter_conf.inner_vlan = res->inner_vlan;
7952
7953         if (res->ip_value.family == AF_INET) {
7954                 tunnel_filter_conf.ip_addr.ipv4_addr =
7955                         res->ip_value.addr.ipv4.s_addr;
7956                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV4;
7957         } else {
7958                 memcpy(&(tunnel_filter_conf.ip_addr.ipv6_addr),
7959                         &(res->ip_value.addr.ipv6),
7960                         sizeof(struct in6_addr));
7961                 tunnel_filter_conf.ip_type = RTE_TUNNEL_IPTYPE_IPV6;
7962         }
7963
7964         if (!strcmp(res->filter_type, "imac-ivlan"))
7965                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_IVLAN;
7966         else if (!strcmp(res->filter_type, "imac-ivlan-tenid"))
7967                 tunnel_filter_conf.filter_type =
7968                         RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID;
7969         else if (!strcmp(res->filter_type, "imac-tenid"))
7970                 tunnel_filter_conf.filter_type = RTE_TUNNEL_FILTER_IMAC_TENID;
7971         else if (!strcmp(res->filter_type, "imac"))
7972                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IMAC;
7973         else if (!strcmp(res->filter_type, "omac-imac-tenid"))
7974                 tunnel_filter_conf.filter_type =
7975                         RTE_TUNNEL_FILTER_OMAC_TENID_IMAC;
7976         else if (!strcmp(res->filter_type, "oip"))
7977                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_OIP;
7978         else if (!strcmp(res->filter_type, "iip"))
7979                 tunnel_filter_conf.filter_type = ETH_TUNNEL_FILTER_IIP;
7980         else {
7981                 printf("The filter type is not supported");
7982                 return;
7983         }
7984
7985         if (!strcmp(res->tunnel_type, "vxlan"))
7986                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_VXLAN;
7987         else if (!strcmp(res->tunnel_type, "nvgre"))
7988                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_NVGRE;
7989         else if (!strcmp(res->tunnel_type, "ipingre"))
7990                 tunnel_filter_conf.tunnel_type = RTE_TUNNEL_TYPE_IP_IN_GRE;
7991         else {
7992                 printf("The tunnel type %s not supported.\n", res->tunnel_type);
7993                 return;
7994         }
7995
7996         tunnel_filter_conf.tenant_id = res->tenant_id;
7997         tunnel_filter_conf.queue_id = res->queue_num;
7998         if (!strcmp(res->what, "add"))
7999                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8000                                         RTE_ETH_FILTER_TUNNEL,
8001                                         RTE_ETH_FILTER_ADD,
8002                                         &tunnel_filter_conf);
8003         else
8004                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8005                                         RTE_ETH_FILTER_TUNNEL,
8006                                         RTE_ETH_FILTER_DELETE,
8007                                         &tunnel_filter_conf);
8008         if (ret < 0)
8009                 printf("cmd_tunnel_filter_parsed error: (%s)\n",
8010                                 strerror(-ret));
8011
8012 }
8013 cmdline_parse_token_string_t cmd_tunnel_filter_cmd =
8014         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8015         cmd, "tunnel_filter");
8016 cmdline_parse_token_string_t cmd_tunnel_filter_what =
8017         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8018         what, "add#rm");
8019 cmdline_parse_token_num_t cmd_tunnel_filter_port_id =
8020         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8021         port_id, UINT16);
8022 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac =
8023         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8024         outer_mac);
8025 cmdline_parse_token_etheraddr_t cmd_tunnel_filter_inner_mac =
8026         TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8027         inner_mac);
8028 cmdline_parse_token_num_t cmd_tunnel_filter_innner_vlan =
8029         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8030         inner_vlan, UINT16);
8031 cmdline_parse_token_ipaddr_t cmd_tunnel_filter_ip_value =
8032         TOKEN_IPADDR_INITIALIZER(struct cmd_tunnel_filter_result,
8033         ip_value);
8034 cmdline_parse_token_string_t cmd_tunnel_filter_tunnel_type =
8035         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8036         tunnel_type, "vxlan#nvgre#ipingre");
8037
8038 cmdline_parse_token_string_t cmd_tunnel_filter_filter_type =
8039         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_filter_result,
8040         filter_type, "oip#iip#imac-ivlan#imac-ivlan-tenid#imac-tenid#"
8041                 "imac#omac-imac-tenid");
8042 cmdline_parse_token_num_t cmd_tunnel_filter_tenant_id =
8043         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8044         tenant_id, UINT32);
8045 cmdline_parse_token_num_t cmd_tunnel_filter_queue_num =
8046         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result,
8047         queue_num, UINT16);
8048
8049 cmdline_parse_inst_t cmd_tunnel_filter = {
8050         .f = cmd_tunnel_filter_parsed,
8051         .data = (void *)0,
8052         .help_str = "tunnel_filter add|rm <port_id> <outer_mac> <inner_mac> "
8053                 "<ip> <inner_vlan> vxlan|nvgre|ipingre oip|iip|imac-ivlan|"
8054                 "imac-ivlan-tenid|imac-tenid|imac|omac-imac-tenid <tenant_id> "
8055                 "<queue_id>: Add/Rm tunnel filter of a port",
8056         .tokens = {
8057                 (void *)&cmd_tunnel_filter_cmd,
8058                 (void *)&cmd_tunnel_filter_what,
8059                 (void *)&cmd_tunnel_filter_port_id,
8060                 (void *)&cmd_tunnel_filter_outer_mac,
8061                 (void *)&cmd_tunnel_filter_inner_mac,
8062                 (void *)&cmd_tunnel_filter_ip_value,
8063                 (void *)&cmd_tunnel_filter_innner_vlan,
8064                 (void *)&cmd_tunnel_filter_tunnel_type,
8065                 (void *)&cmd_tunnel_filter_filter_type,
8066                 (void *)&cmd_tunnel_filter_tenant_id,
8067                 (void *)&cmd_tunnel_filter_queue_num,
8068                 NULL,
8069         },
8070 };
8071
8072 /* *** CONFIGURE TUNNEL UDP PORT *** */
8073 struct cmd_tunnel_udp_config {
8074         cmdline_fixed_string_t cmd;
8075         cmdline_fixed_string_t what;
8076         uint16_t udp_port;
8077         portid_t port_id;
8078 };
8079
8080 static void
8081 cmd_tunnel_udp_config_parsed(void *parsed_result,
8082                           __attribute__((unused)) struct cmdline *cl,
8083                           __attribute__((unused)) void *data)
8084 {
8085         struct cmd_tunnel_udp_config *res = parsed_result;
8086         struct rte_eth_udp_tunnel tunnel_udp;
8087         int ret;
8088
8089         tunnel_udp.udp_port = res->udp_port;
8090
8091         if (!strcmp(res->cmd, "rx_vxlan_port"))
8092                 tunnel_udp.prot_type = RTE_TUNNEL_TYPE_VXLAN;
8093
8094         if (!strcmp(res->what, "add"))
8095                 ret = rte_eth_dev_udp_tunnel_port_add(res->port_id,
8096                                                       &tunnel_udp);
8097         else
8098                 ret = rte_eth_dev_udp_tunnel_port_delete(res->port_id,
8099                                                          &tunnel_udp);
8100
8101         if (ret < 0)
8102                 printf("udp tunneling add error: (%s)\n", strerror(-ret));
8103 }
8104
8105 cmdline_parse_token_string_t cmd_tunnel_udp_config_cmd =
8106         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8107                                 cmd, "rx_vxlan_port");
8108 cmdline_parse_token_string_t cmd_tunnel_udp_config_what =
8109         TOKEN_STRING_INITIALIZER(struct cmd_tunnel_udp_config,
8110                                 what, "add#rm");
8111 cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port =
8112         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8113                                 udp_port, UINT16);
8114 cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id =
8115         TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config,
8116                                 port_id, UINT16);
8117
8118 cmdline_parse_inst_t cmd_tunnel_udp_config = {
8119         .f = cmd_tunnel_udp_config_parsed,
8120         .data = (void *)0,
8121         .help_str = "rx_vxlan_port add|rm <udp_port> <port_id>: "
8122                 "Add/Remove a tunneling UDP port filter",
8123         .tokens = {
8124                 (void *)&cmd_tunnel_udp_config_cmd,
8125                 (void *)&cmd_tunnel_udp_config_what,
8126                 (void *)&cmd_tunnel_udp_config_udp_port,
8127                 (void *)&cmd_tunnel_udp_config_port_id,
8128                 NULL,
8129         },
8130 };
8131
8132 /* *** GLOBAL CONFIG *** */
8133 struct cmd_global_config_result {
8134         cmdline_fixed_string_t cmd;
8135         portid_t port_id;
8136         cmdline_fixed_string_t cfg_type;
8137         uint8_t len;
8138 };
8139
8140 static void
8141 cmd_global_config_parsed(void *parsed_result,
8142                          __attribute__((unused)) struct cmdline *cl,
8143                          __attribute__((unused)) void *data)
8144 {
8145         struct cmd_global_config_result *res = parsed_result;
8146         struct rte_eth_global_cfg conf;
8147         int ret;
8148
8149         memset(&conf, 0, sizeof(conf));
8150         conf.cfg_type = RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN;
8151         conf.cfg.gre_key_len = res->len;
8152         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_NONE,
8153                                       RTE_ETH_FILTER_SET, &conf);
8154         if (ret != 0)
8155                 printf("Global config error\n");
8156 }
8157
8158 cmdline_parse_token_string_t cmd_global_config_cmd =
8159         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd,
8160                 "global_config");
8161 cmdline_parse_token_num_t cmd_global_config_port_id =
8162         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id,
8163                                UINT16);
8164 cmdline_parse_token_string_t cmd_global_config_type =
8165         TOKEN_STRING_INITIALIZER(struct cmd_global_config_result,
8166                 cfg_type, "gre-key-len");
8167 cmdline_parse_token_num_t cmd_global_config_gre_key_len =
8168         TOKEN_NUM_INITIALIZER(struct cmd_global_config_result,
8169                 len, UINT8);
8170
8171 cmdline_parse_inst_t cmd_global_config = {
8172         .f = cmd_global_config_parsed,
8173         .data = (void *)NULL,
8174         .help_str = "global_config <port_id> gre-key-len <key_len>",
8175         .tokens = {
8176                 (void *)&cmd_global_config_cmd,
8177                 (void *)&cmd_global_config_port_id,
8178                 (void *)&cmd_global_config_type,
8179                 (void *)&cmd_global_config_gre_key_len,
8180                 NULL,
8181         },
8182 };
8183
8184 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
8185 struct cmd_set_mirror_mask_result {
8186         cmdline_fixed_string_t set;
8187         cmdline_fixed_string_t port;
8188         portid_t port_id;
8189         cmdline_fixed_string_t mirror;
8190         uint8_t rule_id;
8191         cmdline_fixed_string_t what;
8192         cmdline_fixed_string_t value;
8193         cmdline_fixed_string_t dstpool;
8194         uint8_t dstpool_id;
8195         cmdline_fixed_string_t on;
8196 };
8197
8198 cmdline_parse_token_string_t cmd_mirror_mask_set =
8199         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8200                                 set, "set");
8201 cmdline_parse_token_string_t cmd_mirror_mask_port =
8202         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8203                                 port, "port");
8204 cmdline_parse_token_num_t cmd_mirror_mask_portid =
8205         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8206                                 port_id, UINT16);
8207 cmdline_parse_token_string_t cmd_mirror_mask_mirror =
8208         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8209                                 mirror, "mirror-rule");
8210 cmdline_parse_token_num_t cmd_mirror_mask_ruleid =
8211         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8212                                 rule_id, UINT8);
8213 cmdline_parse_token_string_t cmd_mirror_mask_what =
8214         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8215                                 what, "pool-mirror-up#pool-mirror-down"
8216                                       "#vlan-mirror");
8217 cmdline_parse_token_string_t cmd_mirror_mask_value =
8218         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8219                                 value, NULL);
8220 cmdline_parse_token_string_t cmd_mirror_mask_dstpool =
8221         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8222                                 dstpool, "dst-pool");
8223 cmdline_parse_token_num_t cmd_mirror_mask_poolid =
8224         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result,
8225                                 dstpool_id, UINT8);
8226 cmdline_parse_token_string_t cmd_mirror_mask_on =
8227         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result,
8228                                 on, "on#off");
8229
8230 static void
8231 cmd_set_mirror_mask_parsed(void *parsed_result,
8232                        __attribute__((unused)) struct cmdline *cl,
8233                        __attribute__((unused)) void *data)
8234 {
8235         int ret,nb_item,i;
8236         struct cmd_set_mirror_mask_result *res = parsed_result;
8237         struct rte_eth_mirror_conf mr_conf;
8238
8239         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8240
8241         unsigned int vlan_list[ETH_MIRROR_MAX_VLANS];
8242
8243         mr_conf.dst_pool = res->dstpool_id;
8244
8245         if (!strcmp(res->what, "pool-mirror-up")) {
8246                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8247                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_UP;
8248         } else if (!strcmp(res->what, "pool-mirror-down")) {
8249                 mr_conf.pool_mask = strtoull(res->value, NULL, 16);
8250                 mr_conf.rule_type = ETH_MIRROR_VIRTUAL_POOL_DOWN;
8251         } else if (!strcmp(res->what, "vlan-mirror")) {
8252                 mr_conf.rule_type = ETH_MIRROR_VLAN;
8253                 nb_item = parse_item_list(res->value, "vlan",
8254                                 ETH_MIRROR_MAX_VLANS, vlan_list, 1);
8255                 if (nb_item <= 0)
8256                         return;
8257
8258                 for (i = 0; i < nb_item; i++) {
8259                         if (vlan_list[i] > ETHER_MAX_VLAN_ID) {
8260                                 printf("Invalid vlan_id: must be < 4096\n");
8261                                 return;
8262                         }
8263
8264                         mr_conf.vlan.vlan_id[i] = (uint16_t)vlan_list[i];
8265                         mr_conf.vlan.vlan_mask |= 1ULL << i;
8266                 }
8267         }
8268
8269         if (!strcmp(res->on, "on"))
8270                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8271                                                 res->rule_id, 1);
8272         else
8273                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8274                                                 res->rule_id, 0);
8275         if (ret < 0)
8276                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8277 }
8278
8279 cmdline_parse_inst_t cmd_set_mirror_mask = {
8280                 .f = cmd_set_mirror_mask_parsed,
8281                 .data = NULL,
8282                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8283                         "pool-mirror-up|pool-mirror-down|vlan-mirror "
8284                         "<pool_mask|vlan_id[,vlan_id]*> dst-pool <pool_id> on|off",
8285                 .tokens = {
8286                         (void *)&cmd_mirror_mask_set,
8287                         (void *)&cmd_mirror_mask_port,
8288                         (void *)&cmd_mirror_mask_portid,
8289                         (void *)&cmd_mirror_mask_mirror,
8290                         (void *)&cmd_mirror_mask_ruleid,
8291                         (void *)&cmd_mirror_mask_what,
8292                         (void *)&cmd_mirror_mask_value,
8293                         (void *)&cmd_mirror_mask_dstpool,
8294                         (void *)&cmd_mirror_mask_poolid,
8295                         (void *)&cmd_mirror_mask_on,
8296                         NULL,
8297                 },
8298 };
8299
8300 /* *** CONFIGURE VM MIRROR UPLINK/DOWNLINK RULE *** */
8301 struct cmd_set_mirror_link_result {
8302         cmdline_fixed_string_t set;
8303         cmdline_fixed_string_t port;
8304         portid_t port_id;
8305         cmdline_fixed_string_t mirror;
8306         uint8_t rule_id;
8307         cmdline_fixed_string_t what;
8308         cmdline_fixed_string_t dstpool;
8309         uint8_t dstpool_id;
8310         cmdline_fixed_string_t on;
8311 };
8312
8313 cmdline_parse_token_string_t cmd_mirror_link_set =
8314         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8315                                  set, "set");
8316 cmdline_parse_token_string_t cmd_mirror_link_port =
8317         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8318                                 port, "port");
8319 cmdline_parse_token_num_t cmd_mirror_link_portid =
8320         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8321                                 port_id, UINT16);
8322 cmdline_parse_token_string_t cmd_mirror_link_mirror =
8323         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8324                                 mirror, "mirror-rule");
8325 cmdline_parse_token_num_t cmd_mirror_link_ruleid =
8326         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8327                             rule_id, UINT8);
8328 cmdline_parse_token_string_t cmd_mirror_link_what =
8329         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8330                                 what, "uplink-mirror#downlink-mirror");
8331 cmdline_parse_token_string_t cmd_mirror_link_dstpool =
8332         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8333                                 dstpool, "dst-pool");
8334 cmdline_parse_token_num_t cmd_mirror_link_poolid =
8335         TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result,
8336                                 dstpool_id, UINT8);
8337 cmdline_parse_token_string_t cmd_mirror_link_on =
8338         TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result,
8339                                 on, "on#off");
8340
8341 static void
8342 cmd_set_mirror_link_parsed(void *parsed_result,
8343                        __attribute__((unused)) struct cmdline *cl,
8344                        __attribute__((unused)) void *data)
8345 {
8346         int ret;
8347         struct cmd_set_mirror_link_result *res = parsed_result;
8348         struct rte_eth_mirror_conf mr_conf;
8349
8350         memset(&mr_conf, 0, sizeof(struct rte_eth_mirror_conf));
8351         if (!strcmp(res->what, "uplink-mirror"))
8352                 mr_conf.rule_type = ETH_MIRROR_UPLINK_PORT;
8353         else
8354                 mr_conf.rule_type = ETH_MIRROR_DOWNLINK_PORT;
8355
8356         mr_conf.dst_pool = res->dstpool_id;
8357
8358         if (!strcmp(res->on, "on"))
8359                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8360                                                 res->rule_id, 1);
8361         else
8362                 ret = rte_eth_mirror_rule_set(res->port_id, &mr_conf,
8363                                                 res->rule_id, 0);
8364
8365         /* check the return value and print it if is < 0 */
8366         if (ret < 0)
8367                 printf("mirror rule add error: (%s)\n", strerror(-ret));
8368
8369 }
8370
8371 cmdline_parse_inst_t cmd_set_mirror_link = {
8372                 .f = cmd_set_mirror_link_parsed,
8373                 .data = NULL,
8374                 .help_str = "set port <port_id> mirror-rule <rule_id> "
8375                         "uplink-mirror|downlink-mirror dst-pool <pool_id> on|off",
8376                 .tokens = {
8377                         (void *)&cmd_mirror_link_set,
8378                         (void *)&cmd_mirror_link_port,
8379                         (void *)&cmd_mirror_link_portid,
8380                         (void *)&cmd_mirror_link_mirror,
8381                         (void *)&cmd_mirror_link_ruleid,
8382                         (void *)&cmd_mirror_link_what,
8383                         (void *)&cmd_mirror_link_dstpool,
8384                         (void *)&cmd_mirror_link_poolid,
8385                         (void *)&cmd_mirror_link_on,
8386                         NULL,
8387                 },
8388 };
8389
8390 /* *** RESET VM MIRROR RULE *** */
8391 struct cmd_rm_mirror_rule_result {
8392         cmdline_fixed_string_t reset;
8393         cmdline_fixed_string_t port;
8394         portid_t port_id;
8395         cmdline_fixed_string_t mirror;
8396         uint8_t rule_id;
8397 };
8398
8399 cmdline_parse_token_string_t cmd_rm_mirror_rule_reset =
8400         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8401                                  reset, "reset");
8402 cmdline_parse_token_string_t cmd_rm_mirror_rule_port =
8403         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8404                                 port, "port");
8405 cmdline_parse_token_num_t cmd_rm_mirror_rule_portid =
8406         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8407                                 port_id, UINT16);
8408 cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror =
8409         TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result,
8410                                 mirror, "mirror-rule");
8411 cmdline_parse_token_num_t cmd_rm_mirror_rule_ruleid =
8412         TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result,
8413                                 rule_id, UINT8);
8414
8415 static void
8416 cmd_reset_mirror_rule_parsed(void *parsed_result,
8417                        __attribute__((unused)) struct cmdline *cl,
8418                        __attribute__((unused)) void *data)
8419 {
8420         int ret;
8421         struct cmd_set_mirror_link_result *res = parsed_result;
8422         /* check rule_id */
8423         ret = rte_eth_mirror_rule_reset(res->port_id,res->rule_id);
8424         if(ret < 0)
8425                 printf("mirror rule remove error: (%s)\n", strerror(-ret));
8426 }
8427
8428 cmdline_parse_inst_t cmd_reset_mirror_rule = {
8429                 .f = cmd_reset_mirror_rule_parsed,
8430                 .data = NULL,
8431                 .help_str = "reset port <port_id> mirror-rule <rule_id>",
8432                 .tokens = {
8433                         (void *)&cmd_rm_mirror_rule_reset,
8434                         (void *)&cmd_rm_mirror_rule_port,
8435                         (void *)&cmd_rm_mirror_rule_portid,
8436                         (void *)&cmd_rm_mirror_rule_mirror,
8437                         (void *)&cmd_rm_mirror_rule_ruleid,
8438                         NULL,
8439                 },
8440 };
8441
8442 /* ******************************************************************************** */
8443
8444 struct cmd_dump_result {
8445         cmdline_fixed_string_t dump;
8446 };
8447
8448 static void
8449 dump_struct_sizes(void)
8450 {
8451 #define DUMP_SIZE(t) printf("sizeof(" #t ") = %u\n", (unsigned)sizeof(t));
8452         DUMP_SIZE(struct rte_mbuf);
8453         DUMP_SIZE(struct rte_mempool);
8454         DUMP_SIZE(struct rte_ring);
8455 #undef DUMP_SIZE
8456 }
8457
8458 static void cmd_dump_parsed(void *parsed_result,
8459                             __attribute__((unused)) struct cmdline *cl,
8460                             __attribute__((unused)) void *data)
8461 {
8462         struct cmd_dump_result *res = parsed_result;
8463
8464         if (!strcmp(res->dump, "dump_physmem"))
8465                 rte_dump_physmem_layout(stdout);
8466         else if (!strcmp(res->dump, "dump_memzone"))
8467                 rte_memzone_dump(stdout);
8468         else if (!strcmp(res->dump, "dump_struct_sizes"))
8469                 dump_struct_sizes();
8470         else if (!strcmp(res->dump, "dump_ring"))
8471                 rte_ring_list_dump(stdout);
8472         else if (!strcmp(res->dump, "dump_mempool"))
8473                 rte_mempool_list_dump(stdout);
8474         else if (!strcmp(res->dump, "dump_devargs"))
8475                 rte_eal_devargs_dump(stdout);
8476         else if (!strcmp(res->dump, "dump_log_types"))
8477                 rte_log_dump(stdout);
8478 }
8479
8480 cmdline_parse_token_string_t cmd_dump_dump =
8481         TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
8482                 "dump_physmem#"
8483                 "dump_memzone#"
8484                 "dump_struct_sizes#"
8485                 "dump_ring#"
8486                 "dump_mempool#"
8487                 "dump_devargs#"
8488                 "dump_log_types");
8489
8490 cmdline_parse_inst_t cmd_dump = {
8491         .f = cmd_dump_parsed,  /* function to call */
8492         .data = NULL,      /* 2nd arg of func */
8493         .help_str = "Dump status",
8494         .tokens = {        /* token list, NULL terminated */
8495                 (void *)&cmd_dump_dump,
8496                 NULL,
8497         },
8498 };
8499
8500 /* ******************************************************************************** */
8501
8502 struct cmd_dump_one_result {
8503         cmdline_fixed_string_t dump;
8504         cmdline_fixed_string_t name;
8505 };
8506
8507 static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl,
8508                                 __attribute__((unused)) void *data)
8509 {
8510         struct cmd_dump_one_result *res = parsed_result;
8511
8512         if (!strcmp(res->dump, "dump_ring")) {
8513                 struct rte_ring *r;
8514                 r = rte_ring_lookup(res->name);
8515                 if (r == NULL) {
8516                         cmdline_printf(cl, "Cannot find ring\n");
8517                         return;
8518                 }
8519                 rte_ring_dump(stdout, r);
8520         } else if (!strcmp(res->dump, "dump_mempool")) {
8521                 struct rte_mempool *mp;
8522                 mp = rte_mempool_lookup(res->name);
8523                 if (mp == NULL) {
8524                         cmdline_printf(cl, "Cannot find mempool\n");
8525                         return;
8526                 }
8527                 rte_mempool_dump(stdout, mp);
8528         }
8529 }
8530
8531 cmdline_parse_token_string_t cmd_dump_one_dump =
8532         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, dump,
8533                                  "dump_ring#dump_mempool");
8534
8535 cmdline_parse_token_string_t cmd_dump_one_name =
8536         TOKEN_STRING_INITIALIZER(struct cmd_dump_one_result, name, NULL);
8537
8538 cmdline_parse_inst_t cmd_dump_one = {
8539         .f = cmd_dump_one_parsed,  /* function to call */
8540         .data = NULL,      /* 2nd arg of func */
8541         .help_str = "dump_ring|dump_mempool <name>: Dump one ring/mempool",
8542         .tokens = {        /* token list, NULL terminated */
8543                 (void *)&cmd_dump_one_dump,
8544                 (void *)&cmd_dump_one_name,
8545                 NULL,
8546         },
8547 };
8548
8549 /* *** Add/Del syn filter *** */
8550 struct cmd_syn_filter_result {
8551         cmdline_fixed_string_t filter;
8552         portid_t port_id;
8553         cmdline_fixed_string_t ops;
8554         cmdline_fixed_string_t priority;
8555         cmdline_fixed_string_t high;
8556         cmdline_fixed_string_t queue;
8557         uint16_t queue_id;
8558 };
8559
8560 static void
8561 cmd_syn_filter_parsed(void *parsed_result,
8562                         __attribute__((unused)) struct cmdline *cl,
8563                         __attribute__((unused)) void *data)
8564 {
8565         struct cmd_syn_filter_result *res = parsed_result;
8566         struct rte_eth_syn_filter syn_filter;
8567         int ret = 0;
8568
8569         ret = rte_eth_dev_filter_supported(res->port_id,
8570                                         RTE_ETH_FILTER_SYN);
8571         if (ret < 0) {
8572                 printf("syn filter is not supported on port %u.\n",
8573                                 res->port_id);
8574                 return;
8575         }
8576
8577         memset(&syn_filter, 0, sizeof(syn_filter));
8578
8579         if (!strcmp(res->ops, "add")) {
8580                 if (!strcmp(res->high, "high"))
8581                         syn_filter.hig_pri = 1;
8582                 else
8583                         syn_filter.hig_pri = 0;
8584
8585                 syn_filter.queue = res->queue_id;
8586                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8587                                                 RTE_ETH_FILTER_SYN,
8588                                                 RTE_ETH_FILTER_ADD,
8589                                                 &syn_filter);
8590         } else
8591                 ret = rte_eth_dev_filter_ctrl(res->port_id,
8592                                                 RTE_ETH_FILTER_SYN,
8593                                                 RTE_ETH_FILTER_DELETE,
8594                                                 &syn_filter);
8595
8596         if (ret < 0)
8597                 printf("syn filter programming error: (%s)\n",
8598                                 strerror(-ret));
8599 }
8600
8601 cmdline_parse_token_string_t cmd_syn_filter_filter =
8602         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8603         filter, "syn_filter");
8604 cmdline_parse_token_num_t cmd_syn_filter_port_id =
8605         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8606         port_id, UINT16);
8607 cmdline_parse_token_string_t cmd_syn_filter_ops =
8608         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8609         ops, "add#del");
8610 cmdline_parse_token_string_t cmd_syn_filter_priority =
8611         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8612                                 priority, "priority");
8613 cmdline_parse_token_string_t cmd_syn_filter_high =
8614         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8615                                 high, "high#low");
8616 cmdline_parse_token_string_t cmd_syn_filter_queue =
8617         TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
8618                                 queue, "queue");
8619 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
8620         TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
8621                                 queue_id, UINT16);
8622
8623 cmdline_parse_inst_t cmd_syn_filter = {
8624         .f = cmd_syn_filter_parsed,
8625         .data = NULL,
8626         .help_str = "syn_filter <port_id> add|del priority high|low queue "
8627                 "<queue_id>: Add/Delete syn filter",
8628         .tokens = {
8629                 (void *)&cmd_syn_filter_filter,
8630                 (void *)&cmd_syn_filter_port_id,
8631                 (void *)&cmd_syn_filter_ops,
8632                 (void *)&cmd_syn_filter_priority,
8633                 (void *)&cmd_syn_filter_high,
8634                 (void *)&cmd_syn_filter_queue,
8635                 (void *)&cmd_syn_filter_queue_id,
8636                 NULL,
8637         },
8638 };
8639
8640 /* *** queue region set *** */
8641 struct cmd_queue_region_result {
8642         cmdline_fixed_string_t set;
8643         cmdline_fixed_string_t port;
8644         portid_t port_id;
8645         cmdline_fixed_string_t cmd;
8646         cmdline_fixed_string_t region;
8647         uint8_t  region_id;
8648         cmdline_fixed_string_t queue_start_index;
8649         uint8_t  queue_id;
8650         cmdline_fixed_string_t queue_num;
8651         uint8_t  queue_num_value;
8652 };
8653
8654 static void
8655 cmd_queue_region_parsed(void *parsed_result,
8656                         __attribute__((unused)) struct cmdline *cl,
8657                         __attribute__((unused)) void *data)
8658 {
8659         struct cmd_queue_region_result *res = parsed_result;
8660         int ret = -ENOTSUP;
8661 #ifdef RTE_LIBRTE_I40E_PMD
8662         struct rte_pmd_i40e_queue_region_conf region_conf;
8663         enum rte_pmd_i40e_queue_region_op op_type;
8664 #endif
8665
8666         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8667                 return;
8668
8669 #ifdef RTE_LIBRTE_I40E_PMD
8670         memset(&region_conf, 0, sizeof(region_conf));
8671         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET;
8672         region_conf.region_id = res->region_id;
8673         region_conf.queue_num = res->queue_num_value;
8674         region_conf.queue_start_index = res->queue_id;
8675
8676         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8677                                 op_type, &region_conf);
8678 #endif
8679
8680         switch (ret) {
8681         case 0:
8682                 break;
8683         case -ENOTSUP:
8684                 printf("function not implemented or supported\n");
8685                 break;
8686         default:
8687                 printf("queue region config error: (%s)\n", strerror(-ret));
8688         }
8689 }
8690
8691 cmdline_parse_token_string_t cmd_queue_region_set =
8692 TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8693                 set, "set");
8694 cmdline_parse_token_string_t cmd_queue_region_port =
8695         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port");
8696 cmdline_parse_token_num_t cmd_queue_region_port_id =
8697         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8698                                 port_id, UINT16);
8699 cmdline_parse_token_string_t cmd_queue_region_cmd =
8700         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8701                                  cmd, "queue-region");
8702 cmdline_parse_token_string_t cmd_queue_region_id =
8703         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8704                                 region, "region_id");
8705 cmdline_parse_token_num_t cmd_queue_region_index =
8706         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8707                                 region_id, UINT8);
8708 cmdline_parse_token_string_t cmd_queue_region_queue_start_index =
8709         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8710                                 queue_start_index, "queue_start_index");
8711 cmdline_parse_token_num_t cmd_queue_region_queue_id =
8712         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8713                                 queue_id, UINT8);
8714 cmdline_parse_token_string_t cmd_queue_region_queue_num =
8715         TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result,
8716                                 queue_num, "queue_num");
8717 cmdline_parse_token_num_t cmd_queue_region_queue_num_value =
8718         TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result,
8719                                 queue_num_value, UINT8);
8720
8721 cmdline_parse_inst_t cmd_queue_region = {
8722         .f = cmd_queue_region_parsed,
8723         .data = NULL,
8724         .help_str = "set port <port_id> queue-region region_id <value> "
8725                 "queue_start_index <value> queue_num <value>: Set a queue region",
8726         .tokens = {
8727                 (void *)&cmd_queue_region_set,
8728                 (void *)&cmd_queue_region_port,
8729                 (void *)&cmd_queue_region_port_id,
8730                 (void *)&cmd_queue_region_cmd,
8731                 (void *)&cmd_queue_region_id,
8732                 (void *)&cmd_queue_region_index,
8733                 (void *)&cmd_queue_region_queue_start_index,
8734                 (void *)&cmd_queue_region_queue_id,
8735                 (void *)&cmd_queue_region_queue_num,
8736                 (void *)&cmd_queue_region_queue_num_value,
8737                 NULL,
8738         },
8739 };
8740
8741 /* *** queue region and flowtype set *** */
8742 struct cmd_region_flowtype_result {
8743         cmdline_fixed_string_t set;
8744         cmdline_fixed_string_t port;
8745         portid_t port_id;
8746         cmdline_fixed_string_t cmd;
8747         cmdline_fixed_string_t region;
8748         uint8_t  region_id;
8749         cmdline_fixed_string_t flowtype;
8750         uint8_t  flowtype_id;
8751 };
8752
8753 static void
8754 cmd_region_flowtype_parsed(void *parsed_result,
8755                         __attribute__((unused)) struct cmdline *cl,
8756                         __attribute__((unused)) void *data)
8757 {
8758         struct cmd_region_flowtype_result *res = parsed_result;
8759         int ret = -ENOTSUP;
8760 #ifdef RTE_LIBRTE_I40E_PMD
8761         struct rte_pmd_i40e_queue_region_conf region_conf;
8762         enum rte_pmd_i40e_queue_region_op op_type;
8763 #endif
8764
8765         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8766                 return;
8767
8768 #ifdef RTE_LIBRTE_I40E_PMD
8769         memset(&region_conf, 0, sizeof(region_conf));
8770
8771         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET;
8772         region_conf.region_id = res->region_id;
8773         region_conf.hw_flowtype = res->flowtype_id;
8774
8775         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8776                         op_type, &region_conf);
8777 #endif
8778
8779         switch (ret) {
8780         case 0:
8781                 break;
8782         case -ENOTSUP:
8783                 printf("function not implemented or supported\n");
8784                 break;
8785         default:
8786                 printf("region flowtype config error: (%s)\n", strerror(-ret));
8787         }
8788 }
8789
8790 cmdline_parse_token_string_t cmd_region_flowtype_set =
8791 TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8792                                 set, "set");
8793 cmdline_parse_token_string_t cmd_region_flowtype_port =
8794         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8795                                 port, "port");
8796 cmdline_parse_token_num_t cmd_region_flowtype_port_index =
8797         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8798                                 port_id, UINT16);
8799 cmdline_parse_token_string_t cmd_region_flowtype_cmd =
8800         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8801                                 cmd, "queue-region");
8802 cmdline_parse_token_string_t cmd_region_flowtype_index =
8803         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8804                                 region, "region_id");
8805 cmdline_parse_token_num_t cmd_region_flowtype_id =
8806         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8807                                 region_id, UINT8);
8808 cmdline_parse_token_string_t cmd_region_flowtype_flow_index =
8809         TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result,
8810                                 flowtype, "flowtype");
8811 cmdline_parse_token_num_t cmd_region_flowtype_flow_id =
8812         TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result,
8813                                 flowtype_id, UINT8);
8814 cmdline_parse_inst_t cmd_region_flowtype = {
8815         .f = cmd_region_flowtype_parsed,
8816         .data = NULL,
8817         .help_str = "set port <port_id> queue-region region_id <value> "
8818                 "flowtype <value>: Set a flowtype region index",
8819         .tokens = {
8820                 (void *)&cmd_region_flowtype_set,
8821                 (void *)&cmd_region_flowtype_port,
8822                 (void *)&cmd_region_flowtype_port_index,
8823                 (void *)&cmd_region_flowtype_cmd,
8824                 (void *)&cmd_region_flowtype_index,
8825                 (void *)&cmd_region_flowtype_id,
8826                 (void *)&cmd_region_flowtype_flow_index,
8827                 (void *)&cmd_region_flowtype_flow_id,
8828                 NULL,
8829         },
8830 };
8831
8832 /* *** User Priority (UP) to queue region (region_id) set *** */
8833 struct cmd_user_priority_region_result {
8834         cmdline_fixed_string_t set;
8835         cmdline_fixed_string_t port;
8836         portid_t port_id;
8837         cmdline_fixed_string_t cmd;
8838         cmdline_fixed_string_t user_priority;
8839         uint8_t  user_priority_id;
8840         cmdline_fixed_string_t region;
8841         uint8_t  region_id;
8842 };
8843
8844 static void
8845 cmd_user_priority_region_parsed(void *parsed_result,
8846                         __attribute__((unused)) struct cmdline *cl,
8847                         __attribute__((unused)) void *data)
8848 {
8849         struct cmd_user_priority_region_result *res = parsed_result;
8850         int ret = -ENOTSUP;
8851 #ifdef RTE_LIBRTE_I40E_PMD
8852         struct rte_pmd_i40e_queue_region_conf region_conf;
8853         enum rte_pmd_i40e_queue_region_op op_type;
8854 #endif
8855
8856         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8857                 return;
8858
8859 #ifdef RTE_LIBRTE_I40E_PMD
8860         memset(&region_conf, 0, sizeof(region_conf));
8861         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET;
8862         region_conf.user_priority = res->user_priority_id;
8863         region_conf.region_id = res->region_id;
8864
8865         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8866                                 op_type, &region_conf);
8867 #endif
8868
8869         switch (ret) {
8870         case 0:
8871                 break;
8872         case -ENOTSUP:
8873                 printf("function not implemented or supported\n");
8874                 break;
8875         default:
8876                 printf("user_priority region config error: (%s)\n",
8877                                 strerror(-ret));
8878         }
8879 }
8880
8881 cmdline_parse_token_string_t cmd_user_priority_region_set =
8882         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8883                                 set, "set");
8884 cmdline_parse_token_string_t cmd_user_priority_region_port =
8885         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8886                                 port, "port");
8887 cmdline_parse_token_num_t cmd_user_priority_region_port_index =
8888         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8889                                 port_id, UINT16);
8890 cmdline_parse_token_string_t cmd_user_priority_region_cmd =
8891         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8892                                 cmd, "queue-region");
8893 cmdline_parse_token_string_t cmd_user_priority_region_UP =
8894         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8895                                 user_priority, "UP");
8896 cmdline_parse_token_num_t cmd_user_priority_region_UP_id =
8897         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8898                                 user_priority_id, UINT8);
8899 cmdline_parse_token_string_t cmd_user_priority_region_region =
8900         TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result,
8901                                 region, "region_id");
8902 cmdline_parse_token_num_t cmd_user_priority_region_region_id =
8903         TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result,
8904                                 region_id, UINT8);
8905
8906 cmdline_parse_inst_t cmd_user_priority_region = {
8907         .f = cmd_user_priority_region_parsed,
8908         .data = NULL,
8909         .help_str = "set port <port_id> queue-region UP <value> "
8910                 "region_id <value>: Set the mapping of User Priority (UP) "
8911                 "to queue region (region_id) ",
8912         .tokens = {
8913                 (void *)&cmd_user_priority_region_set,
8914                 (void *)&cmd_user_priority_region_port,
8915                 (void *)&cmd_user_priority_region_port_index,
8916                 (void *)&cmd_user_priority_region_cmd,
8917                 (void *)&cmd_user_priority_region_UP,
8918                 (void *)&cmd_user_priority_region_UP_id,
8919                 (void *)&cmd_user_priority_region_region,
8920                 (void *)&cmd_user_priority_region_region_id,
8921                 NULL,
8922         },
8923 };
8924
8925 /* *** flush all queue region related configuration *** */
8926 struct cmd_flush_queue_region_result {
8927         cmdline_fixed_string_t set;
8928         cmdline_fixed_string_t port;
8929         portid_t port_id;
8930         cmdline_fixed_string_t cmd;
8931         cmdline_fixed_string_t flush;
8932         cmdline_fixed_string_t what;
8933 };
8934
8935 static void
8936 cmd_flush_queue_region_parsed(void *parsed_result,
8937                         __attribute__((unused)) struct cmdline *cl,
8938                         __attribute__((unused)) void *data)
8939 {
8940         struct cmd_flush_queue_region_result *res = parsed_result;
8941         int ret = -ENOTSUP;
8942 #ifdef RTE_LIBRTE_I40E_PMD
8943         struct rte_pmd_i40e_queue_region_conf region_conf;
8944         enum rte_pmd_i40e_queue_region_op op_type;
8945 #endif
8946
8947         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
8948                 return;
8949
8950 #ifdef RTE_LIBRTE_I40E_PMD
8951         memset(&region_conf, 0, sizeof(region_conf));
8952
8953         if (strcmp(res->what, "on") == 0)
8954                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON;
8955         else
8956                 op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF;
8957
8958         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
8959                                 op_type, &region_conf);
8960 #endif
8961
8962         switch (ret) {
8963         case 0:
8964                 break;
8965         case -ENOTSUP:
8966                 printf("function not implemented or supported\n");
8967                 break;
8968         default:
8969                 printf("queue region config flush error: (%s)\n",
8970                                 strerror(-ret));
8971         }
8972 }
8973
8974 cmdline_parse_token_string_t cmd_flush_queue_region_set =
8975         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8976                                 set, "set");
8977 cmdline_parse_token_string_t cmd_flush_queue_region_port =
8978         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8979                                 port, "port");
8980 cmdline_parse_token_num_t cmd_flush_queue_region_port_index =
8981         TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result,
8982                                 port_id, UINT16);
8983 cmdline_parse_token_string_t cmd_flush_queue_region_cmd =
8984         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8985                                 cmd, "queue-region");
8986 cmdline_parse_token_string_t cmd_flush_queue_region_flush =
8987         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8988                                 flush, "flush");
8989 cmdline_parse_token_string_t cmd_flush_queue_region_what =
8990         TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result,
8991                                 what, "on#off");
8992
8993 cmdline_parse_inst_t cmd_flush_queue_region = {
8994         .f = cmd_flush_queue_region_parsed,
8995         .data = NULL,
8996         .help_str = "set port <port_id> queue-region flush on|off"
8997                 ": flush all queue region related configuration",
8998         .tokens = {
8999                 (void *)&cmd_flush_queue_region_set,
9000                 (void *)&cmd_flush_queue_region_port,
9001                 (void *)&cmd_flush_queue_region_port_index,
9002                 (void *)&cmd_flush_queue_region_cmd,
9003                 (void *)&cmd_flush_queue_region_flush,
9004                 (void *)&cmd_flush_queue_region_what,
9005                 NULL,
9006         },
9007 };
9008
9009 /* *** get all queue region related configuration info *** */
9010 struct cmd_show_queue_region_info {
9011         cmdline_fixed_string_t show;
9012         cmdline_fixed_string_t port;
9013         portid_t port_id;
9014         cmdline_fixed_string_t cmd;
9015 };
9016
9017 static void
9018 cmd_show_queue_region_info_parsed(void *parsed_result,
9019                         __attribute__((unused)) struct cmdline *cl,
9020                         __attribute__((unused)) void *data)
9021 {
9022         struct cmd_show_queue_region_info *res = parsed_result;
9023         int ret = -ENOTSUP;
9024 #ifdef RTE_LIBRTE_I40E_PMD
9025         struct rte_pmd_i40e_queue_regions rte_pmd_regions;
9026         enum rte_pmd_i40e_queue_region_op op_type;
9027 #endif
9028
9029         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
9030                 return;
9031
9032 #ifdef RTE_LIBRTE_I40E_PMD
9033         memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions));
9034
9035         op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET;
9036
9037         ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id,
9038                                         op_type, &rte_pmd_regions);
9039
9040         port_queue_region_info_display(res->port_id, &rte_pmd_regions);
9041 #endif
9042
9043         switch (ret) {
9044         case 0:
9045                 break;
9046         case -ENOTSUP:
9047                 printf("function not implemented or supported\n");
9048                 break;
9049         default:
9050                 printf("queue region config info show error: (%s)\n",
9051                                 strerror(-ret));
9052         }
9053 }
9054
9055 cmdline_parse_token_string_t cmd_show_queue_region_info_get =
9056 TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9057                                 show, "show");
9058 cmdline_parse_token_string_t cmd_show_queue_region_info_port =
9059         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9060                                 port, "port");
9061 cmdline_parse_token_num_t cmd_show_queue_region_info_port_index =
9062         TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info,
9063                                 port_id, UINT16);
9064 cmdline_parse_token_string_t cmd_show_queue_region_info_cmd =
9065         TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info,
9066                                 cmd, "queue-region");
9067
9068 cmdline_parse_inst_t cmd_show_queue_region_info_all = {
9069         .f = cmd_show_queue_region_info_parsed,
9070         .data = NULL,
9071         .help_str = "show port <port_id> queue-region"
9072                 ": show all queue region related configuration info",
9073         .tokens = {
9074                 (void *)&cmd_show_queue_region_info_get,
9075                 (void *)&cmd_show_queue_region_info_port,
9076                 (void *)&cmd_show_queue_region_info_port_index,
9077                 (void *)&cmd_show_queue_region_info_cmd,
9078                 NULL,
9079         },
9080 };
9081
9082 /* *** ADD/REMOVE A 2tuple FILTER *** */
9083 struct cmd_2tuple_filter_result {
9084         cmdline_fixed_string_t filter;
9085         portid_t port_id;
9086         cmdline_fixed_string_t ops;
9087         cmdline_fixed_string_t dst_port;
9088         uint16_t dst_port_value;
9089         cmdline_fixed_string_t protocol;
9090         uint8_t protocol_value;
9091         cmdline_fixed_string_t mask;
9092         uint8_t  mask_value;
9093         cmdline_fixed_string_t tcp_flags;
9094         uint8_t tcp_flags_value;
9095         cmdline_fixed_string_t priority;
9096         uint8_t  priority_value;
9097         cmdline_fixed_string_t queue;
9098         uint16_t  queue_id;
9099 };
9100
9101 static void
9102 cmd_2tuple_filter_parsed(void *parsed_result,
9103                         __attribute__((unused)) struct cmdline *cl,
9104                         __attribute__((unused)) void *data)
9105 {
9106         struct rte_eth_ntuple_filter filter;
9107         struct cmd_2tuple_filter_result *res = parsed_result;
9108         int ret = 0;
9109
9110         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9111         if (ret < 0) {
9112                 printf("ntuple filter is not supported on port %u.\n",
9113                         res->port_id);
9114                 return;
9115         }
9116
9117         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9118
9119         filter.flags = RTE_2TUPLE_FLAGS;
9120         filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9121         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9122         filter.proto = res->protocol_value;
9123         filter.priority = res->priority_value;
9124         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9125                 printf("nonzero tcp_flags is only meaningful"
9126                         " when protocol is TCP.\n");
9127                 return;
9128         }
9129         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9130                 printf("invalid TCP flags.\n");
9131                 return;
9132         }
9133
9134         if (res->tcp_flags_value != 0) {
9135                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9136                 filter.tcp_flags = res->tcp_flags_value;
9137         }
9138
9139         /* need convert to big endian. */
9140         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9141         filter.queue = res->queue_id;
9142
9143         if (!strcmp(res->ops, "add"))
9144                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9145                                 RTE_ETH_FILTER_NTUPLE,
9146                                 RTE_ETH_FILTER_ADD,
9147                                 &filter);
9148         else
9149                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9150                                 RTE_ETH_FILTER_NTUPLE,
9151                                 RTE_ETH_FILTER_DELETE,
9152                                 &filter);
9153         if (ret < 0)
9154                 printf("2tuple filter programming error: (%s)\n",
9155                         strerror(-ret));
9156
9157 }
9158
9159 cmdline_parse_token_string_t cmd_2tuple_filter_filter =
9160         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9161                                  filter, "2tuple_filter");
9162 cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
9163         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9164                                 port_id, UINT16);
9165 cmdline_parse_token_string_t cmd_2tuple_filter_ops =
9166         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9167                                  ops, "add#del");
9168 cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
9169         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9170                                 dst_port, "dst_port");
9171 cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
9172         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9173                                 dst_port_value, UINT16);
9174 cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
9175         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9176                                 protocol, "protocol");
9177 cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
9178         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9179                                 protocol_value, UINT8);
9180 cmdline_parse_token_string_t cmd_2tuple_filter_mask =
9181         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9182                                 mask, "mask");
9183 cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
9184         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9185                                 mask_value, INT8);
9186 cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
9187         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9188                                 tcp_flags, "tcp_flags");
9189 cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
9190         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9191                                 tcp_flags_value, UINT8);
9192 cmdline_parse_token_string_t cmd_2tuple_filter_priority =
9193         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9194                                 priority, "priority");
9195 cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
9196         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9197                                 priority_value, UINT8);
9198 cmdline_parse_token_string_t cmd_2tuple_filter_queue =
9199         TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
9200                                 queue, "queue");
9201 cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
9202         TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
9203                                 queue_id, UINT16);
9204
9205 cmdline_parse_inst_t cmd_2tuple_filter = {
9206         .f = cmd_2tuple_filter_parsed,
9207         .data = NULL,
9208         .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
9209                 "<value> mask <value> tcp_flags <value> priority <value> queue "
9210                 "<queue_id>: Add a 2tuple filter",
9211         .tokens = {
9212                 (void *)&cmd_2tuple_filter_filter,
9213                 (void *)&cmd_2tuple_filter_port_id,
9214                 (void *)&cmd_2tuple_filter_ops,
9215                 (void *)&cmd_2tuple_filter_dst_port,
9216                 (void *)&cmd_2tuple_filter_dst_port_value,
9217                 (void *)&cmd_2tuple_filter_protocol,
9218                 (void *)&cmd_2tuple_filter_protocol_value,
9219                 (void *)&cmd_2tuple_filter_mask,
9220                 (void *)&cmd_2tuple_filter_mask_value,
9221                 (void *)&cmd_2tuple_filter_tcp_flags,
9222                 (void *)&cmd_2tuple_filter_tcp_flags_value,
9223                 (void *)&cmd_2tuple_filter_priority,
9224                 (void *)&cmd_2tuple_filter_priority_value,
9225                 (void *)&cmd_2tuple_filter_queue,
9226                 (void *)&cmd_2tuple_filter_queue_id,
9227                 NULL,
9228         },
9229 };
9230
9231 /* *** ADD/REMOVE A 5tuple FILTER *** */
9232 struct cmd_5tuple_filter_result {
9233         cmdline_fixed_string_t filter;
9234         portid_t port_id;
9235         cmdline_fixed_string_t ops;
9236         cmdline_fixed_string_t dst_ip;
9237         cmdline_ipaddr_t dst_ip_value;
9238         cmdline_fixed_string_t src_ip;
9239         cmdline_ipaddr_t src_ip_value;
9240         cmdline_fixed_string_t dst_port;
9241         uint16_t dst_port_value;
9242         cmdline_fixed_string_t src_port;
9243         uint16_t src_port_value;
9244         cmdline_fixed_string_t protocol;
9245         uint8_t protocol_value;
9246         cmdline_fixed_string_t mask;
9247         uint8_t  mask_value;
9248         cmdline_fixed_string_t tcp_flags;
9249         uint8_t tcp_flags_value;
9250         cmdline_fixed_string_t priority;
9251         uint8_t  priority_value;
9252         cmdline_fixed_string_t queue;
9253         uint16_t  queue_id;
9254 };
9255
9256 static void
9257 cmd_5tuple_filter_parsed(void *parsed_result,
9258                         __attribute__((unused)) struct cmdline *cl,
9259                         __attribute__((unused)) void *data)
9260 {
9261         struct rte_eth_ntuple_filter filter;
9262         struct cmd_5tuple_filter_result *res = parsed_result;
9263         int ret = 0;
9264
9265         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
9266         if (ret < 0) {
9267                 printf("ntuple filter is not supported on port %u.\n",
9268                         res->port_id);
9269                 return;
9270         }
9271
9272         memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
9273
9274         filter.flags = RTE_5TUPLE_FLAGS;
9275         filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
9276         filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
9277         filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
9278         filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
9279         filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
9280         filter.proto = res->protocol_value;
9281         filter.priority = res->priority_value;
9282         if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
9283                 printf("nonzero tcp_flags is only meaningful"
9284                         " when protocol is TCP.\n");
9285                 return;
9286         }
9287         if (res->tcp_flags_value > TCP_FLAG_ALL) {
9288                 printf("invalid TCP flags.\n");
9289                 return;
9290         }
9291
9292         if (res->tcp_flags_value != 0) {
9293                 filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
9294                 filter.tcp_flags = res->tcp_flags_value;
9295         }
9296
9297         if (res->dst_ip_value.family == AF_INET)
9298                 /* no need to convert, already big endian. */
9299                 filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
9300         else {
9301                 if (filter.dst_ip_mask == 0) {
9302                         printf("can not support ipv6 involved compare.\n");
9303                         return;
9304                 }
9305                 filter.dst_ip = 0;
9306         }
9307
9308         if (res->src_ip_value.family == AF_INET)
9309                 /* no need to convert, already big endian. */
9310                 filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
9311         else {
9312                 if (filter.src_ip_mask == 0) {
9313                         printf("can not support ipv6 involved compare.\n");
9314                         return;
9315                 }
9316                 filter.src_ip = 0;
9317         }
9318         /* need convert to big endian. */
9319         filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
9320         filter.src_port = rte_cpu_to_be_16(res->src_port_value);
9321         filter.queue = res->queue_id;
9322
9323         if (!strcmp(res->ops, "add"))
9324                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9325                                 RTE_ETH_FILTER_NTUPLE,
9326                                 RTE_ETH_FILTER_ADD,
9327                                 &filter);
9328         else
9329                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9330                                 RTE_ETH_FILTER_NTUPLE,
9331                                 RTE_ETH_FILTER_DELETE,
9332                                 &filter);
9333         if (ret < 0)
9334                 printf("5tuple filter programming error: (%s)\n",
9335                         strerror(-ret));
9336 }
9337
9338 cmdline_parse_token_string_t cmd_5tuple_filter_filter =
9339         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9340                                  filter, "5tuple_filter");
9341 cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
9342         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9343                                 port_id, UINT16);
9344 cmdline_parse_token_string_t cmd_5tuple_filter_ops =
9345         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9346                                  ops, "add#del");
9347 cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
9348         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9349                                 dst_ip, "dst_ip");
9350 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
9351         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9352                                 dst_ip_value);
9353 cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
9354         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9355                                 src_ip, "src_ip");
9356 cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
9357         TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
9358                                 src_ip_value);
9359 cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
9360         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9361                                 dst_port, "dst_port");
9362 cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
9363         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9364                                 dst_port_value, UINT16);
9365 cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
9366         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9367                                 src_port, "src_port");
9368 cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
9369         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9370                                 src_port_value, UINT16);
9371 cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
9372         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9373                                 protocol, "protocol");
9374 cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
9375         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9376                                 protocol_value, UINT8);
9377 cmdline_parse_token_string_t cmd_5tuple_filter_mask =
9378         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9379                                 mask, "mask");
9380 cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
9381         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9382                                 mask_value, INT8);
9383 cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
9384         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9385                                 tcp_flags, "tcp_flags");
9386 cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
9387         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9388                                 tcp_flags_value, UINT8);
9389 cmdline_parse_token_string_t cmd_5tuple_filter_priority =
9390         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9391                                 priority, "priority");
9392 cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
9393         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9394                                 priority_value, UINT8);
9395 cmdline_parse_token_string_t cmd_5tuple_filter_queue =
9396         TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
9397                                 queue, "queue");
9398 cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
9399         TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
9400                                 queue_id, UINT16);
9401
9402 cmdline_parse_inst_t cmd_5tuple_filter = {
9403         .f = cmd_5tuple_filter_parsed,
9404         .data = NULL,
9405         .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
9406                 "src_ip <value> dst_port <value> src_port <value> "
9407                 "protocol <value>  mask <value> tcp_flags <value> "
9408                 "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
9409         .tokens = {
9410                 (void *)&cmd_5tuple_filter_filter,
9411                 (void *)&cmd_5tuple_filter_port_id,
9412                 (void *)&cmd_5tuple_filter_ops,
9413                 (void *)&cmd_5tuple_filter_dst_ip,
9414                 (void *)&cmd_5tuple_filter_dst_ip_value,
9415                 (void *)&cmd_5tuple_filter_src_ip,
9416                 (void *)&cmd_5tuple_filter_src_ip_value,
9417                 (void *)&cmd_5tuple_filter_dst_port,
9418                 (void *)&cmd_5tuple_filter_dst_port_value,
9419                 (void *)&cmd_5tuple_filter_src_port,
9420                 (void *)&cmd_5tuple_filter_src_port_value,
9421                 (void *)&cmd_5tuple_filter_protocol,
9422                 (void *)&cmd_5tuple_filter_protocol_value,
9423                 (void *)&cmd_5tuple_filter_mask,
9424                 (void *)&cmd_5tuple_filter_mask_value,
9425                 (void *)&cmd_5tuple_filter_tcp_flags,
9426                 (void *)&cmd_5tuple_filter_tcp_flags_value,
9427                 (void *)&cmd_5tuple_filter_priority,
9428                 (void *)&cmd_5tuple_filter_priority_value,
9429                 (void *)&cmd_5tuple_filter_queue,
9430                 (void *)&cmd_5tuple_filter_queue_id,
9431                 NULL,
9432         },
9433 };
9434
9435 /* *** ADD/REMOVE A flex FILTER *** */
9436 struct cmd_flex_filter_result {
9437         cmdline_fixed_string_t filter;
9438         cmdline_fixed_string_t ops;
9439         portid_t port_id;
9440         cmdline_fixed_string_t len;
9441         uint8_t len_value;
9442         cmdline_fixed_string_t bytes;
9443         cmdline_fixed_string_t bytes_value;
9444         cmdline_fixed_string_t mask;
9445         cmdline_fixed_string_t mask_value;
9446         cmdline_fixed_string_t priority;
9447         uint8_t priority_value;
9448         cmdline_fixed_string_t queue;
9449         uint16_t queue_id;
9450 };
9451
9452 static int xdigit2val(unsigned char c)
9453 {
9454         int val;
9455         if (isdigit(c))
9456                 val = c - '0';
9457         else if (isupper(c))
9458                 val = c - 'A' + 10;
9459         else
9460                 val = c - 'a' + 10;
9461         return val;
9462 }
9463
9464 static void
9465 cmd_flex_filter_parsed(void *parsed_result,
9466                           __attribute__((unused)) struct cmdline *cl,
9467                           __attribute__((unused)) void *data)
9468 {
9469         int ret = 0;
9470         struct rte_eth_flex_filter filter;
9471         struct cmd_flex_filter_result *res = parsed_result;
9472         char *bytes_ptr, *mask_ptr;
9473         uint16_t len, i, j = 0;
9474         char c;
9475         int val;
9476         uint8_t byte = 0;
9477
9478         if (res->len_value > RTE_FLEX_FILTER_MAXLEN) {
9479                 printf("the len exceed the max length 128\n");
9480                 return;
9481         }
9482         memset(&filter, 0, sizeof(struct rte_eth_flex_filter));
9483         filter.len = res->len_value;
9484         filter.priority = res->priority_value;
9485         filter.queue = res->queue_id;
9486         bytes_ptr = res->bytes_value;
9487         mask_ptr = res->mask_value;
9488
9489          /* translate bytes string to array. */
9490         if (bytes_ptr[0] == '0' && ((bytes_ptr[1] == 'x') ||
9491                 (bytes_ptr[1] == 'X')))
9492                 bytes_ptr += 2;
9493         len = strnlen(bytes_ptr, res->len_value * 2);
9494         if (len == 0 || (len % 8 != 0)) {
9495                 printf("please check len and bytes input\n");
9496                 return;
9497         }
9498         for (i = 0; i < len; i++) {
9499                 c = bytes_ptr[i];
9500                 if (isxdigit(c) == 0) {
9501                         /* invalid characters. */
9502                         printf("invalid input\n");
9503                         return;
9504                 }
9505                 val = xdigit2val(c);
9506                 if (i % 2) {
9507                         byte |= val;
9508                         filter.bytes[j] = byte;
9509                         printf("bytes[%d]:%02x ", j, filter.bytes[j]);
9510                         j++;
9511                         byte = 0;
9512                 } else
9513                         byte |= val << 4;
9514         }
9515         printf("\n");
9516          /* translate mask string to uint8_t array. */
9517         if (mask_ptr[0] == '0' && ((mask_ptr[1] == 'x') ||
9518                 (mask_ptr[1] == 'X')))
9519                 mask_ptr += 2;
9520         len = strnlen(mask_ptr, (res->len_value + 3) / 4);
9521         if (len == 0) {
9522                 printf("invalid input\n");
9523                 return;
9524         }
9525         j = 0;
9526         byte = 0;
9527         for (i = 0; i < len; i++) {
9528                 c = mask_ptr[i];
9529                 if (isxdigit(c) == 0) {
9530                         /* invalid characters. */
9531                         printf("invalid input\n");
9532                         return;
9533                 }
9534                 val = xdigit2val(c);
9535                 if (i % 2) {
9536                         byte |= val;
9537                         filter.mask[j] = byte;
9538                         printf("mask[%d]:%02x ", j, filter.mask[j]);
9539                         j++;
9540                         byte = 0;
9541                 } else
9542                         byte |= val << 4;
9543         }
9544         printf("\n");
9545
9546         if (!strcmp(res->ops, "add"))
9547                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9548                                 RTE_ETH_FILTER_FLEXIBLE,
9549                                 RTE_ETH_FILTER_ADD,
9550                                 &filter);
9551         else
9552                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9553                                 RTE_ETH_FILTER_FLEXIBLE,
9554                                 RTE_ETH_FILTER_DELETE,
9555                                 &filter);
9556
9557         if (ret < 0)
9558                 printf("flex filter setting error: (%s)\n", strerror(-ret));
9559 }
9560
9561 cmdline_parse_token_string_t cmd_flex_filter_filter =
9562         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9563                                 filter, "flex_filter");
9564 cmdline_parse_token_num_t cmd_flex_filter_port_id =
9565         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9566                                 port_id, UINT16);
9567 cmdline_parse_token_string_t cmd_flex_filter_ops =
9568         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9569                                 ops, "add#del");
9570 cmdline_parse_token_string_t cmd_flex_filter_len =
9571         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9572                                 len, "len");
9573 cmdline_parse_token_num_t cmd_flex_filter_len_value =
9574         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9575                                 len_value, UINT8);
9576 cmdline_parse_token_string_t cmd_flex_filter_bytes =
9577         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9578                                 bytes, "bytes");
9579 cmdline_parse_token_string_t cmd_flex_filter_bytes_value =
9580         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9581                                 bytes_value, NULL);
9582 cmdline_parse_token_string_t cmd_flex_filter_mask =
9583         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9584                                 mask, "mask");
9585 cmdline_parse_token_string_t cmd_flex_filter_mask_value =
9586         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9587                                 mask_value, NULL);
9588 cmdline_parse_token_string_t cmd_flex_filter_priority =
9589         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9590                                 priority, "priority");
9591 cmdline_parse_token_num_t cmd_flex_filter_priority_value =
9592         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9593                                 priority_value, UINT8);
9594 cmdline_parse_token_string_t cmd_flex_filter_queue =
9595         TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result,
9596                                 queue, "queue");
9597 cmdline_parse_token_num_t cmd_flex_filter_queue_id =
9598         TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result,
9599                                 queue_id, UINT16);
9600 cmdline_parse_inst_t cmd_flex_filter = {
9601         .f = cmd_flex_filter_parsed,
9602         .data = NULL,
9603         .help_str = "flex_filter <port_id> add|del len <value> bytes "
9604                 "<value> mask <value> priority <value> queue <queue_id>: "
9605                 "Add/Del a flex filter",
9606         .tokens = {
9607                 (void *)&cmd_flex_filter_filter,
9608                 (void *)&cmd_flex_filter_port_id,
9609                 (void *)&cmd_flex_filter_ops,
9610                 (void *)&cmd_flex_filter_len,
9611                 (void *)&cmd_flex_filter_len_value,
9612                 (void *)&cmd_flex_filter_bytes,
9613                 (void *)&cmd_flex_filter_bytes_value,
9614                 (void *)&cmd_flex_filter_mask,
9615                 (void *)&cmd_flex_filter_mask_value,
9616                 (void *)&cmd_flex_filter_priority,
9617                 (void *)&cmd_flex_filter_priority_value,
9618                 (void *)&cmd_flex_filter_queue,
9619                 (void *)&cmd_flex_filter_queue_id,
9620                 NULL,
9621         },
9622 };
9623
9624 /* *** Filters Control *** */
9625
9626 /* *** deal with ethertype filter *** */
9627 struct cmd_ethertype_filter_result {
9628         cmdline_fixed_string_t filter;
9629         portid_t port_id;
9630         cmdline_fixed_string_t ops;
9631         cmdline_fixed_string_t mac;
9632         struct ether_addr mac_addr;
9633         cmdline_fixed_string_t ethertype;
9634         uint16_t ethertype_value;
9635         cmdline_fixed_string_t drop;
9636         cmdline_fixed_string_t queue;
9637         uint16_t  queue_id;
9638 };
9639
9640 cmdline_parse_token_string_t cmd_ethertype_filter_filter =
9641         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9642                                  filter, "ethertype_filter");
9643 cmdline_parse_token_num_t cmd_ethertype_filter_port_id =
9644         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9645                               port_id, UINT16);
9646 cmdline_parse_token_string_t cmd_ethertype_filter_ops =
9647         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9648                                  ops, "add#del");
9649 cmdline_parse_token_string_t cmd_ethertype_filter_mac =
9650         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9651                                  mac, "mac_addr#mac_ignr");
9652 cmdline_parse_token_etheraddr_t cmd_ethertype_filter_mac_addr =
9653         TOKEN_ETHERADDR_INITIALIZER(struct cmd_ethertype_filter_result,
9654                                      mac_addr);
9655 cmdline_parse_token_string_t cmd_ethertype_filter_ethertype =
9656         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9657                                  ethertype, "ethertype");
9658 cmdline_parse_token_num_t cmd_ethertype_filter_ethertype_value =
9659         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9660                               ethertype_value, UINT16);
9661 cmdline_parse_token_string_t cmd_ethertype_filter_drop =
9662         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9663                                  drop, "drop#fwd");
9664 cmdline_parse_token_string_t cmd_ethertype_filter_queue =
9665         TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result,
9666                                  queue, "queue");
9667 cmdline_parse_token_num_t cmd_ethertype_filter_queue_id =
9668         TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result,
9669                               queue_id, UINT16);
9670
9671 static void
9672 cmd_ethertype_filter_parsed(void *parsed_result,
9673                           __attribute__((unused)) struct cmdline *cl,
9674                           __attribute__((unused)) void *data)
9675 {
9676         struct cmd_ethertype_filter_result *res = parsed_result;
9677         struct rte_eth_ethertype_filter filter;
9678         int ret = 0;
9679
9680         ret = rte_eth_dev_filter_supported(res->port_id,
9681                         RTE_ETH_FILTER_ETHERTYPE);
9682         if (ret < 0) {
9683                 printf("ethertype filter is not supported on port %u.\n",
9684                         res->port_id);
9685                 return;
9686         }
9687
9688         memset(&filter, 0, sizeof(filter));
9689         if (!strcmp(res->mac, "mac_addr")) {
9690                 filter.flags |= RTE_ETHTYPE_FLAGS_MAC;
9691                 rte_memcpy(&filter.mac_addr, &res->mac_addr,
9692                         sizeof(struct ether_addr));
9693         }
9694         if (!strcmp(res->drop, "drop"))
9695                 filter.flags |= RTE_ETHTYPE_FLAGS_DROP;
9696         filter.ether_type = res->ethertype_value;
9697         filter.queue = res->queue_id;
9698
9699         if (!strcmp(res->ops, "add"))
9700                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9701                                 RTE_ETH_FILTER_ETHERTYPE,
9702                                 RTE_ETH_FILTER_ADD,
9703                                 &filter);
9704         else
9705                 ret = rte_eth_dev_filter_ctrl(res->port_id,
9706                                 RTE_ETH_FILTER_ETHERTYPE,
9707                                 RTE_ETH_FILTER_DELETE,
9708                                 &filter);
9709         if (ret < 0)
9710                 printf("ethertype filter programming error: (%s)\n",
9711                         strerror(-ret));
9712 }
9713
9714 cmdline_parse_inst_t cmd_ethertype_filter = {
9715         .f = cmd_ethertype_filter_parsed,
9716         .data = NULL,
9717         .help_str = "ethertype_filter <port_id> add|del mac_addr|mac_ignr "
9718                 "<mac_addr> ethertype <value> drop|fw queue <queue_id>: "
9719                 "Add or delete an ethertype filter entry",
9720         .tokens = {
9721                 (void *)&cmd_ethertype_filter_filter,
9722                 (void *)&cmd_ethertype_filter_port_id,
9723                 (void *)&cmd_ethertype_filter_ops,
9724                 (void *)&cmd_ethertype_filter_mac,
9725                 (void *)&cmd_ethertype_filter_mac_addr,
9726                 (void *)&cmd_ethertype_filter_ethertype,
9727                 (void *)&cmd_ethertype_filter_ethertype_value,
9728                 (void *)&cmd_ethertype_filter_drop,
9729                 (void *)&cmd_ethertype_filter_queue,
9730                 (void *)&cmd_ethertype_filter_queue_id,
9731                 NULL,
9732         },
9733 };
9734
9735 /* *** deal with flow director filter *** */
9736 struct cmd_flow_director_result {
9737         cmdline_fixed_string_t flow_director_filter;
9738         portid_t port_id;
9739         cmdline_fixed_string_t mode;
9740         cmdline_fixed_string_t mode_value;
9741         cmdline_fixed_string_t ops;
9742         cmdline_fixed_string_t flow;
9743         cmdline_fixed_string_t flow_type;
9744         cmdline_fixed_string_t ether;
9745         uint16_t ether_type;
9746         cmdline_fixed_string_t src;
9747         cmdline_ipaddr_t ip_src;
9748         uint16_t port_src;
9749         cmdline_fixed_string_t dst;
9750         cmdline_ipaddr_t ip_dst;
9751         uint16_t port_dst;
9752         cmdline_fixed_string_t verify_tag;
9753         uint32_t verify_tag_value;
9754         cmdline_fixed_string_t tos;
9755         uint8_t tos_value;
9756         cmdline_fixed_string_t proto;
9757         uint8_t proto_value;
9758         cmdline_fixed_string_t ttl;
9759         uint8_t ttl_value;
9760         cmdline_fixed_string_t vlan;
9761         uint16_t vlan_value;
9762         cmdline_fixed_string_t flexbytes;
9763         cmdline_fixed_string_t flexbytes_value;
9764         cmdline_fixed_string_t pf_vf;
9765         cmdline_fixed_string_t drop;
9766         cmdline_fixed_string_t queue;
9767         uint16_t  queue_id;
9768         cmdline_fixed_string_t fd_id;
9769         uint32_t  fd_id_value;
9770         cmdline_fixed_string_t mac;
9771         struct ether_addr mac_addr;
9772         cmdline_fixed_string_t tunnel;
9773         cmdline_fixed_string_t tunnel_type;
9774         cmdline_fixed_string_t tunnel_id;
9775         uint32_t tunnel_id_value;
9776 };
9777
9778 static inline int
9779 parse_flexbytes(const char *q_arg, uint8_t *flexbytes, uint16_t max_num)
9780 {
9781         char s[256];
9782         const char *p, *p0 = q_arg;
9783         char *end;
9784         unsigned long int_fld;
9785         char *str_fld[max_num];
9786         int i;
9787         unsigned size;
9788         int ret = -1;
9789
9790         p = strchr(p0, '(');
9791         if (p == NULL)
9792                 return -1;
9793         ++p;
9794         p0 = strchr(p, ')');
9795         if (p0 == NULL)
9796                 return -1;
9797
9798         size = p0 - p;
9799         if (size >= sizeof(s))
9800                 return -1;
9801
9802         snprintf(s, sizeof(s), "%.*s", size, p);
9803         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
9804         if (ret < 0 || ret > max_num)
9805                 return -1;
9806         for (i = 0; i < ret; i++) {
9807                 errno = 0;
9808                 int_fld = strtoul(str_fld[i], &end, 0);
9809                 if (errno != 0 || *end != '\0' || int_fld > UINT8_MAX)
9810                         return -1;
9811                 flexbytes[i] = (uint8_t)int_fld;
9812         }
9813         return ret;
9814 }
9815
9816 static uint16_t
9817 str2flowtype(char *string)
9818 {
9819         uint8_t i = 0;
9820         static const struct {
9821                 char str[32];
9822                 uint16_t type;
9823         } flowtype_str[] = {
9824                 {"raw", RTE_ETH_FLOW_RAW},
9825                 {"ipv4", RTE_ETH_FLOW_IPV4},
9826                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
9827                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
9828                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
9829                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
9830                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
9831                 {"ipv6", RTE_ETH_FLOW_IPV6},
9832                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
9833                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
9834                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
9835                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
9836                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
9837                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
9838         };
9839
9840         for (i = 0; i < RTE_DIM(flowtype_str); i++) {
9841                 if (!strcmp(flowtype_str[i].str, string))
9842                         return flowtype_str[i].type;
9843         }
9844
9845         if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
9846                 return (uint16_t)atoi(string);
9847
9848         return RTE_ETH_FLOW_UNKNOWN;
9849 }
9850
9851 static enum rte_eth_fdir_tunnel_type
9852 str2fdir_tunneltype(char *string)
9853 {
9854         uint8_t i = 0;
9855
9856         static const struct {
9857                 char str[32];
9858                 enum rte_eth_fdir_tunnel_type type;
9859         } tunneltype_str[] = {
9860                 {"NVGRE", RTE_FDIR_TUNNEL_TYPE_NVGRE},
9861                 {"VxLAN", RTE_FDIR_TUNNEL_TYPE_VXLAN},
9862         };
9863
9864         for (i = 0; i < RTE_DIM(tunneltype_str); i++) {
9865                 if (!strcmp(tunneltype_str[i].str, string))
9866                         return tunneltype_str[i].type;
9867         }
9868         return RTE_FDIR_TUNNEL_TYPE_UNKNOWN;
9869 }
9870
9871 #define IPV4_ADDR_TO_UINT(ip_addr, ip) \
9872 do { \
9873         if ((ip_addr).family == AF_INET) \
9874                 (ip) = (ip_addr).addr.ipv4.s_addr; \
9875         else { \
9876                 printf("invalid parameter.\n"); \
9877                 return; \
9878         } \
9879 } while (0)
9880
9881 #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \
9882 do { \
9883         if ((ip_addr).family == AF_INET6) \
9884                 rte_memcpy(&(ip), \
9885                                  &((ip_addr).addr.ipv6), \
9886                                  sizeof(struct in6_addr)); \
9887         else { \
9888                 printf("invalid parameter.\n"); \
9889                 return; \
9890         } \
9891 } while (0)
9892
9893 static void
9894 cmd_flow_director_filter_parsed(void *parsed_result,
9895                           __attribute__((unused)) struct cmdline *cl,
9896                           __attribute__((unused)) void *data)
9897 {
9898         struct cmd_flow_director_result *res = parsed_result;
9899         struct rte_eth_fdir_filter entry;
9900         uint8_t flexbytes[RTE_ETH_FDIR_MAX_FLEXLEN];
9901         char *end;
9902         unsigned long vf_id;
9903         int ret = 0;
9904
9905         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
9906         if (ret < 0) {
9907                 printf("flow director is not supported on port %u.\n",
9908                         res->port_id);
9909                 return;
9910         }
9911         memset(flexbytes, 0, sizeof(flexbytes));
9912         memset(&entry, 0, sizeof(struct rte_eth_fdir_filter));
9913
9914         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
9915                 if (strcmp(res->mode_value, "MAC-VLAN")) {
9916                         printf("Please set mode to MAC-VLAN.\n");
9917                         return;
9918                 }
9919         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
9920                 if (strcmp(res->mode_value, "Tunnel")) {
9921                         printf("Please set mode to Tunnel.\n");
9922                         return;
9923                 }
9924         } else {
9925                 if (strcmp(res->mode_value, "IP")) {
9926                         printf("Please set mode to IP.\n");
9927                         return;
9928                 }
9929                 entry.input.flow_type = str2flowtype(res->flow_type);
9930         }
9931
9932         ret = parse_flexbytes(res->flexbytes_value,
9933                                         flexbytes,
9934                                         RTE_ETH_FDIR_MAX_FLEXLEN);
9935         if (ret < 0) {
9936                 printf("error: Cannot parse flexbytes input.\n");
9937                 return;
9938         }
9939
9940         switch (entry.input.flow_type) {
9941         case RTE_ETH_FLOW_FRAG_IPV4:
9942         case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
9943                 entry.input.flow.ip4_flow.proto = res->proto_value;
9944                 /* fall-through */
9945         case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
9946         case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
9947                 IPV4_ADDR_TO_UINT(res->ip_dst,
9948                         entry.input.flow.ip4_flow.dst_ip);
9949                 IPV4_ADDR_TO_UINT(res->ip_src,
9950                         entry.input.flow.ip4_flow.src_ip);
9951                 entry.input.flow.ip4_flow.tos = res->tos_value;
9952                 entry.input.flow.ip4_flow.ttl = res->ttl_value;
9953                 /* need convert to big endian. */
9954                 entry.input.flow.udp4_flow.dst_port =
9955                                 rte_cpu_to_be_16(res->port_dst);
9956                 entry.input.flow.udp4_flow.src_port =
9957                                 rte_cpu_to_be_16(res->port_src);
9958                 break;
9959         case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
9960                 IPV4_ADDR_TO_UINT(res->ip_dst,
9961                         entry.input.flow.sctp4_flow.ip.dst_ip);
9962                 IPV4_ADDR_TO_UINT(res->ip_src,
9963                         entry.input.flow.sctp4_flow.ip.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.sctp4_flow.dst_port =
9968                                 rte_cpu_to_be_16(res->port_dst);
9969                 entry.input.flow.sctp4_flow.src_port =
9970                                 rte_cpu_to_be_16(res->port_src);
9971                 entry.input.flow.sctp4_flow.verify_tag =
9972                                 rte_cpu_to_be_32(res->verify_tag_value);
9973                 break;
9974         case RTE_ETH_FLOW_FRAG_IPV6:
9975         case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
9976                 entry.input.flow.ipv6_flow.proto = res->proto_value;
9977                 /* fall-through */
9978         case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
9979         case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
9980                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9981                         entry.input.flow.ipv6_flow.dst_ip);
9982                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9983                         entry.input.flow.ipv6_flow.src_ip);
9984                 entry.input.flow.ipv6_flow.tc = res->tos_value;
9985                 entry.input.flow.ipv6_flow.hop_limits = res->ttl_value;
9986                 /* need convert to big endian. */
9987                 entry.input.flow.udp6_flow.dst_port =
9988                                 rte_cpu_to_be_16(res->port_dst);
9989                 entry.input.flow.udp6_flow.src_port =
9990                                 rte_cpu_to_be_16(res->port_src);
9991                 break;
9992         case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
9993                 IPV6_ADDR_TO_ARRAY(res->ip_dst,
9994                         entry.input.flow.sctp6_flow.ip.dst_ip);
9995                 IPV6_ADDR_TO_ARRAY(res->ip_src,
9996                         entry.input.flow.sctp6_flow.ip.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.sctp6_flow.dst_port =
10001                                 rte_cpu_to_be_16(res->port_dst);
10002                 entry.input.flow.sctp6_flow.src_port =
10003                                 rte_cpu_to_be_16(res->port_src);
10004                 entry.input.flow.sctp6_flow.verify_tag =
10005                                 rte_cpu_to_be_32(res->verify_tag_value);
10006                 break;
10007         case RTE_ETH_FLOW_L2_PAYLOAD:
10008                 entry.input.flow.l2_flow.ether_type =
10009                         rte_cpu_to_be_16(res->ether_type);
10010                 break;
10011         default:
10012                 break;
10013         }
10014
10015         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN)
10016                 rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr,
10017                                  &res->mac_addr,
10018                                  sizeof(struct ether_addr));
10019
10020         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10021                 rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr,
10022                                  &res->mac_addr,
10023                                  sizeof(struct ether_addr));
10024                 entry.input.flow.tunnel_flow.tunnel_type =
10025                         str2fdir_tunneltype(res->tunnel_type);
10026                 entry.input.flow.tunnel_flow.tunnel_id =
10027                         rte_cpu_to_be_32(res->tunnel_id_value);
10028         }
10029
10030         rte_memcpy(entry.input.flow_ext.flexbytes,
10031                    flexbytes,
10032                    RTE_ETH_FDIR_MAX_FLEXLEN);
10033
10034         entry.input.flow_ext.vlan_tci = rte_cpu_to_be_16(res->vlan_value);
10035
10036         entry.action.flex_off = 0;  /*use 0 by default */
10037         if (!strcmp(res->drop, "drop"))
10038                 entry.action.behavior = RTE_ETH_FDIR_REJECT;
10039         else
10040                 entry.action.behavior = RTE_ETH_FDIR_ACCEPT;
10041
10042         if (fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_MAC_VLAN &&
10043             fdir_conf.mode !=  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10044                 if (!strcmp(res->pf_vf, "pf"))
10045                         entry.input.flow_ext.is_vf = 0;
10046                 else if (!strncmp(res->pf_vf, "vf", 2)) {
10047                         struct rte_eth_dev_info dev_info;
10048
10049                         memset(&dev_info, 0, sizeof(dev_info));
10050                         rte_eth_dev_info_get(res->port_id, &dev_info);
10051                         errno = 0;
10052                         vf_id = strtoul(res->pf_vf + 2, &end, 10);
10053                         if (errno != 0 || *end != '\0' ||
10054                             vf_id >= dev_info.max_vfs) {
10055                                 printf("invalid parameter %s.\n", res->pf_vf);
10056                                 return;
10057                         }
10058                         entry.input.flow_ext.is_vf = 1;
10059                         entry.input.flow_ext.dst_id = (uint16_t)vf_id;
10060                 } else {
10061                         printf("invalid parameter %s.\n", res->pf_vf);
10062                         return;
10063                 }
10064         }
10065
10066         /* set to report FD ID by default */
10067         entry.action.report_status = RTE_ETH_FDIR_REPORT_ID;
10068         entry.action.rx_queue = res->queue_id;
10069         entry.soft_id = res->fd_id_value;
10070         if (!strcmp(res->ops, "add"))
10071                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10072                                              RTE_ETH_FILTER_ADD, &entry);
10073         else if (!strcmp(res->ops, "del"))
10074                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10075                                              RTE_ETH_FILTER_DELETE, &entry);
10076         else
10077                 ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10078                                              RTE_ETH_FILTER_UPDATE, &entry);
10079         if (ret < 0)
10080                 printf("flow director programming error: (%s)\n",
10081                         strerror(-ret));
10082 }
10083
10084 cmdline_parse_token_string_t cmd_flow_director_filter =
10085         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10086                                  flow_director_filter, "flow_director_filter");
10087 cmdline_parse_token_num_t cmd_flow_director_port_id =
10088         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10089                               port_id, UINT16);
10090 cmdline_parse_token_string_t cmd_flow_director_ops =
10091         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10092                                  ops, "add#del#update");
10093 cmdline_parse_token_string_t cmd_flow_director_flow =
10094         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10095                                  flow, "flow");
10096 cmdline_parse_token_string_t cmd_flow_director_flow_type =
10097         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10098                 flow_type, "ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10099                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload");
10100 cmdline_parse_token_string_t cmd_flow_director_ether =
10101         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10102                                  ether, "ether");
10103 cmdline_parse_token_num_t cmd_flow_director_ether_type =
10104         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10105                               ether_type, UINT16);
10106 cmdline_parse_token_string_t cmd_flow_director_src =
10107         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10108                                  src, "src");
10109 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_src =
10110         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10111                                  ip_src);
10112 cmdline_parse_token_num_t cmd_flow_director_port_src =
10113         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10114                               port_src, UINT16);
10115 cmdline_parse_token_string_t cmd_flow_director_dst =
10116         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10117                                  dst, "dst");
10118 cmdline_parse_token_ipaddr_t cmd_flow_director_ip_dst =
10119         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_result,
10120                                  ip_dst);
10121 cmdline_parse_token_num_t cmd_flow_director_port_dst =
10122         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10123                               port_dst, UINT16);
10124 cmdline_parse_token_string_t cmd_flow_director_verify_tag =
10125         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10126                                   verify_tag, "verify_tag");
10127 cmdline_parse_token_num_t cmd_flow_director_verify_tag_value =
10128         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10129                               verify_tag_value, UINT32);
10130 cmdline_parse_token_string_t cmd_flow_director_tos =
10131         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10132                                  tos, "tos");
10133 cmdline_parse_token_num_t cmd_flow_director_tos_value =
10134         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10135                               tos_value, UINT8);
10136 cmdline_parse_token_string_t cmd_flow_director_proto =
10137         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10138                                  proto, "proto");
10139 cmdline_parse_token_num_t cmd_flow_director_proto_value =
10140         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10141                               proto_value, UINT8);
10142 cmdline_parse_token_string_t cmd_flow_director_ttl =
10143         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10144                                  ttl, "ttl");
10145 cmdline_parse_token_num_t cmd_flow_director_ttl_value =
10146         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10147                               ttl_value, UINT8);
10148 cmdline_parse_token_string_t cmd_flow_director_vlan =
10149         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10150                                  vlan, "vlan");
10151 cmdline_parse_token_num_t cmd_flow_director_vlan_value =
10152         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10153                               vlan_value, UINT16);
10154 cmdline_parse_token_string_t cmd_flow_director_flexbytes =
10155         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10156                                  flexbytes, "flexbytes");
10157 cmdline_parse_token_string_t cmd_flow_director_flexbytes_value =
10158         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10159                               flexbytes_value, NULL);
10160 cmdline_parse_token_string_t cmd_flow_director_drop =
10161         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10162                                  drop, "drop#fwd");
10163 cmdline_parse_token_string_t cmd_flow_director_pf_vf =
10164         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10165                               pf_vf, NULL);
10166 cmdline_parse_token_string_t cmd_flow_director_queue =
10167         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10168                                  queue, "queue");
10169 cmdline_parse_token_num_t cmd_flow_director_queue_id =
10170         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10171                               queue_id, UINT16);
10172 cmdline_parse_token_string_t cmd_flow_director_fd_id =
10173         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10174                                  fd_id, "fd_id");
10175 cmdline_parse_token_num_t cmd_flow_director_fd_id_value =
10176         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10177                               fd_id_value, UINT32);
10178
10179 cmdline_parse_token_string_t cmd_flow_director_mode =
10180         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10181                                  mode, "mode");
10182 cmdline_parse_token_string_t cmd_flow_director_mode_ip =
10183         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10184                                  mode_value, "IP");
10185 cmdline_parse_token_string_t cmd_flow_director_mode_mac_vlan =
10186         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10187                                  mode_value, "MAC-VLAN");
10188 cmdline_parse_token_string_t cmd_flow_director_mode_tunnel =
10189         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10190                                  mode_value, "Tunnel");
10191 cmdline_parse_token_string_t cmd_flow_director_mac =
10192         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10193                                  mac, "mac");
10194 cmdline_parse_token_etheraddr_t cmd_flow_director_mac_addr =
10195         TOKEN_ETHERADDR_INITIALIZER(struct cmd_flow_director_result,
10196                                     mac_addr);
10197 cmdline_parse_token_string_t cmd_flow_director_tunnel =
10198         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10199                                  tunnel, "tunnel");
10200 cmdline_parse_token_string_t cmd_flow_director_tunnel_type =
10201         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10202                                  tunnel_type, "NVGRE#VxLAN");
10203 cmdline_parse_token_string_t cmd_flow_director_tunnel_id =
10204         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result,
10205                                  tunnel_id, "tunnel-id");
10206 cmdline_parse_token_num_t cmd_flow_director_tunnel_id_value =
10207         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result,
10208                               tunnel_id_value, UINT32);
10209
10210 cmdline_parse_inst_t cmd_add_del_ip_flow_director = {
10211         .f = cmd_flow_director_filter_parsed,
10212         .data = NULL,
10213         .help_str = "flow_director_filter <port_id> mode IP add|del|update flow"
10214                 " ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|"
10215                 "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|"
10216                 "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> "
10217                 "proto <proto_value> ttl <ttl_value> vlan <vlan_value> "
10218                 "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> "
10219                 "fd_id <fd_id_value>: "
10220                 "Add or delete an ip flow director entry on NIC",
10221         .tokens = {
10222                 (void *)&cmd_flow_director_filter,
10223                 (void *)&cmd_flow_director_port_id,
10224                 (void *)&cmd_flow_director_mode,
10225                 (void *)&cmd_flow_director_mode_ip,
10226                 (void *)&cmd_flow_director_ops,
10227                 (void *)&cmd_flow_director_flow,
10228                 (void *)&cmd_flow_director_flow_type,
10229                 (void *)&cmd_flow_director_src,
10230                 (void *)&cmd_flow_director_ip_src,
10231                 (void *)&cmd_flow_director_dst,
10232                 (void *)&cmd_flow_director_ip_dst,
10233                 (void *)&cmd_flow_director_tos,
10234                 (void *)&cmd_flow_director_tos_value,
10235                 (void *)&cmd_flow_director_proto,
10236                 (void *)&cmd_flow_director_proto_value,
10237                 (void *)&cmd_flow_director_ttl,
10238                 (void *)&cmd_flow_director_ttl_value,
10239                 (void *)&cmd_flow_director_vlan,
10240                 (void *)&cmd_flow_director_vlan_value,
10241                 (void *)&cmd_flow_director_flexbytes,
10242                 (void *)&cmd_flow_director_flexbytes_value,
10243                 (void *)&cmd_flow_director_drop,
10244                 (void *)&cmd_flow_director_pf_vf,
10245                 (void *)&cmd_flow_director_queue,
10246                 (void *)&cmd_flow_director_queue_id,
10247                 (void *)&cmd_flow_director_fd_id,
10248                 (void *)&cmd_flow_director_fd_id_value,
10249                 NULL,
10250         },
10251 };
10252
10253 cmdline_parse_inst_t cmd_add_del_udp_flow_director = {
10254         .f = cmd_flow_director_filter_parsed,
10255         .data = NULL,
10256         .help_str = "flow_director_filter ... : Add or delete an udp/tcp flow "
10257                 "director entry on NIC",
10258         .tokens = {
10259                 (void *)&cmd_flow_director_filter,
10260                 (void *)&cmd_flow_director_port_id,
10261                 (void *)&cmd_flow_director_mode,
10262                 (void *)&cmd_flow_director_mode_ip,
10263                 (void *)&cmd_flow_director_ops,
10264                 (void *)&cmd_flow_director_flow,
10265                 (void *)&cmd_flow_director_flow_type,
10266                 (void *)&cmd_flow_director_src,
10267                 (void *)&cmd_flow_director_ip_src,
10268                 (void *)&cmd_flow_director_port_src,
10269                 (void *)&cmd_flow_director_dst,
10270                 (void *)&cmd_flow_director_ip_dst,
10271                 (void *)&cmd_flow_director_port_dst,
10272                 (void *)&cmd_flow_director_tos,
10273                 (void *)&cmd_flow_director_tos_value,
10274                 (void *)&cmd_flow_director_ttl,
10275                 (void *)&cmd_flow_director_ttl_value,
10276                 (void *)&cmd_flow_director_vlan,
10277                 (void *)&cmd_flow_director_vlan_value,
10278                 (void *)&cmd_flow_director_flexbytes,
10279                 (void *)&cmd_flow_director_flexbytes_value,
10280                 (void *)&cmd_flow_director_drop,
10281                 (void *)&cmd_flow_director_pf_vf,
10282                 (void *)&cmd_flow_director_queue,
10283                 (void *)&cmd_flow_director_queue_id,
10284                 (void *)&cmd_flow_director_fd_id,
10285                 (void *)&cmd_flow_director_fd_id_value,
10286                 NULL,
10287         },
10288 };
10289
10290 cmdline_parse_inst_t cmd_add_del_sctp_flow_director = {
10291         .f = cmd_flow_director_filter_parsed,
10292         .data = NULL,
10293         .help_str = "flow_director_filter ... : Add or delete a sctp flow "
10294                 "director entry on NIC",
10295         .tokens = {
10296                 (void *)&cmd_flow_director_filter,
10297                 (void *)&cmd_flow_director_port_id,
10298                 (void *)&cmd_flow_director_mode,
10299                 (void *)&cmd_flow_director_mode_ip,
10300                 (void *)&cmd_flow_director_ops,
10301                 (void *)&cmd_flow_director_flow,
10302                 (void *)&cmd_flow_director_flow_type,
10303                 (void *)&cmd_flow_director_src,
10304                 (void *)&cmd_flow_director_ip_src,
10305                 (void *)&cmd_flow_director_port_src,
10306                 (void *)&cmd_flow_director_dst,
10307                 (void *)&cmd_flow_director_ip_dst,
10308                 (void *)&cmd_flow_director_port_dst,
10309                 (void *)&cmd_flow_director_verify_tag,
10310                 (void *)&cmd_flow_director_verify_tag_value,
10311                 (void *)&cmd_flow_director_tos,
10312                 (void *)&cmd_flow_director_tos_value,
10313                 (void *)&cmd_flow_director_ttl,
10314                 (void *)&cmd_flow_director_ttl_value,
10315                 (void *)&cmd_flow_director_vlan,
10316                 (void *)&cmd_flow_director_vlan_value,
10317                 (void *)&cmd_flow_director_flexbytes,
10318                 (void *)&cmd_flow_director_flexbytes_value,
10319                 (void *)&cmd_flow_director_drop,
10320                 (void *)&cmd_flow_director_pf_vf,
10321                 (void *)&cmd_flow_director_queue,
10322                 (void *)&cmd_flow_director_queue_id,
10323                 (void *)&cmd_flow_director_fd_id,
10324                 (void *)&cmd_flow_director_fd_id_value,
10325                 NULL,
10326         },
10327 };
10328
10329 cmdline_parse_inst_t cmd_add_del_l2_flow_director = {
10330         .f = cmd_flow_director_filter_parsed,
10331         .data = NULL,
10332         .help_str = "flow_director_filter ... : Add or delete a L2 flow "
10333                 "director entry on NIC",
10334         .tokens = {
10335                 (void *)&cmd_flow_director_filter,
10336                 (void *)&cmd_flow_director_port_id,
10337                 (void *)&cmd_flow_director_mode,
10338                 (void *)&cmd_flow_director_mode_ip,
10339                 (void *)&cmd_flow_director_ops,
10340                 (void *)&cmd_flow_director_flow,
10341                 (void *)&cmd_flow_director_flow_type,
10342                 (void *)&cmd_flow_director_ether,
10343                 (void *)&cmd_flow_director_ether_type,
10344                 (void *)&cmd_flow_director_flexbytes,
10345                 (void *)&cmd_flow_director_flexbytes_value,
10346                 (void *)&cmd_flow_director_drop,
10347                 (void *)&cmd_flow_director_pf_vf,
10348                 (void *)&cmd_flow_director_queue,
10349                 (void *)&cmd_flow_director_queue_id,
10350                 (void *)&cmd_flow_director_fd_id,
10351                 (void *)&cmd_flow_director_fd_id_value,
10352                 NULL,
10353         },
10354 };
10355
10356 cmdline_parse_inst_t cmd_add_del_mac_vlan_flow_director = {
10357         .f = cmd_flow_director_filter_parsed,
10358         .data = NULL,
10359         .help_str = "flow_director_filter ... : Add or delete a MAC VLAN flow "
10360                 "director entry on NIC",
10361         .tokens = {
10362                 (void *)&cmd_flow_director_filter,
10363                 (void *)&cmd_flow_director_port_id,
10364                 (void *)&cmd_flow_director_mode,
10365                 (void *)&cmd_flow_director_mode_mac_vlan,
10366                 (void *)&cmd_flow_director_ops,
10367                 (void *)&cmd_flow_director_mac,
10368                 (void *)&cmd_flow_director_mac_addr,
10369                 (void *)&cmd_flow_director_vlan,
10370                 (void *)&cmd_flow_director_vlan_value,
10371                 (void *)&cmd_flow_director_flexbytes,
10372                 (void *)&cmd_flow_director_flexbytes_value,
10373                 (void *)&cmd_flow_director_drop,
10374                 (void *)&cmd_flow_director_queue,
10375                 (void *)&cmd_flow_director_queue_id,
10376                 (void *)&cmd_flow_director_fd_id,
10377                 (void *)&cmd_flow_director_fd_id_value,
10378                 NULL,
10379         },
10380 };
10381
10382 cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = {
10383         .f = cmd_flow_director_filter_parsed,
10384         .data = NULL,
10385         .help_str = "flow_director_filter ... : Add or delete a tunnel flow "
10386                 "director entry on NIC",
10387         .tokens = {
10388                 (void *)&cmd_flow_director_filter,
10389                 (void *)&cmd_flow_director_port_id,
10390                 (void *)&cmd_flow_director_mode,
10391                 (void *)&cmd_flow_director_mode_tunnel,
10392                 (void *)&cmd_flow_director_ops,
10393                 (void *)&cmd_flow_director_mac,
10394                 (void *)&cmd_flow_director_mac_addr,
10395                 (void *)&cmd_flow_director_vlan,
10396                 (void *)&cmd_flow_director_vlan_value,
10397                 (void *)&cmd_flow_director_tunnel,
10398                 (void *)&cmd_flow_director_tunnel_type,
10399                 (void *)&cmd_flow_director_tunnel_id,
10400                 (void *)&cmd_flow_director_tunnel_id_value,
10401                 (void *)&cmd_flow_director_flexbytes,
10402                 (void *)&cmd_flow_director_flexbytes_value,
10403                 (void *)&cmd_flow_director_drop,
10404                 (void *)&cmd_flow_director_queue,
10405                 (void *)&cmd_flow_director_queue_id,
10406                 (void *)&cmd_flow_director_fd_id,
10407                 (void *)&cmd_flow_director_fd_id_value,
10408                 NULL,
10409         },
10410 };
10411
10412 struct cmd_flush_flow_director_result {
10413         cmdline_fixed_string_t flush_flow_director;
10414         portid_t port_id;
10415 };
10416
10417 cmdline_parse_token_string_t cmd_flush_flow_director_flush =
10418         TOKEN_STRING_INITIALIZER(struct cmd_flush_flow_director_result,
10419                                  flush_flow_director, "flush_flow_director");
10420 cmdline_parse_token_num_t cmd_flush_flow_director_port_id =
10421         TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result,
10422                               port_id, UINT16);
10423
10424 static void
10425 cmd_flush_flow_director_parsed(void *parsed_result,
10426                           __attribute__((unused)) struct cmdline *cl,
10427                           __attribute__((unused)) void *data)
10428 {
10429         struct cmd_flow_director_result *res = parsed_result;
10430         int ret = 0;
10431
10432         ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR);
10433         if (ret < 0) {
10434                 printf("flow director is not supported on port %u.\n",
10435                         res->port_id);
10436                 return;
10437         }
10438
10439         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10440                         RTE_ETH_FILTER_FLUSH, NULL);
10441         if (ret < 0)
10442                 printf("flow director table flushing error: (%s)\n",
10443                         strerror(-ret));
10444 }
10445
10446 cmdline_parse_inst_t cmd_flush_flow_director = {
10447         .f = cmd_flush_flow_director_parsed,
10448         .data = NULL,
10449         .help_str = "flush_flow_director <port_id>: "
10450                 "Flush all flow director entries of a device on NIC",
10451         .tokens = {
10452                 (void *)&cmd_flush_flow_director_flush,
10453                 (void *)&cmd_flush_flow_director_port_id,
10454                 NULL,
10455         },
10456 };
10457
10458 /* *** deal with flow director mask *** */
10459 struct cmd_flow_director_mask_result {
10460         cmdline_fixed_string_t flow_director_mask;
10461         portid_t port_id;
10462         cmdline_fixed_string_t mode;
10463         cmdline_fixed_string_t mode_value;
10464         cmdline_fixed_string_t vlan;
10465         uint16_t vlan_mask;
10466         cmdline_fixed_string_t src_mask;
10467         cmdline_ipaddr_t ipv4_src;
10468         cmdline_ipaddr_t ipv6_src;
10469         uint16_t port_src;
10470         cmdline_fixed_string_t dst_mask;
10471         cmdline_ipaddr_t ipv4_dst;
10472         cmdline_ipaddr_t ipv6_dst;
10473         uint16_t port_dst;
10474         cmdline_fixed_string_t mac;
10475         uint8_t mac_addr_byte_mask;
10476         cmdline_fixed_string_t tunnel_id;
10477         uint32_t tunnel_id_mask;
10478         cmdline_fixed_string_t tunnel_type;
10479         uint8_t tunnel_type_mask;
10480 };
10481
10482 static void
10483 cmd_flow_director_mask_parsed(void *parsed_result,
10484                           __attribute__((unused)) struct cmdline *cl,
10485                           __attribute__((unused)) void *data)
10486 {
10487         struct cmd_flow_director_mask_result *res = parsed_result;
10488         struct rte_eth_fdir_masks *mask;
10489         struct rte_port *port;
10490
10491         if (res->port_id > nb_ports) {
10492                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10493                 return;
10494         }
10495
10496         port = &ports[res->port_id];
10497         /** Check if the port is not started **/
10498         if (port->port_status != RTE_PORT_STOPPED) {
10499                 printf("Please stop port %d first\n", res->port_id);
10500                 return;
10501         }
10502
10503         mask = &port->dev_conf.fdir_conf.mask;
10504
10505         if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
10506                 if (strcmp(res->mode_value, "MAC-VLAN")) {
10507                         printf("Please set mode to MAC-VLAN.\n");
10508                         return;
10509                 }
10510
10511                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10512         } else if (fdir_conf.mode ==  RTE_FDIR_MODE_PERFECT_TUNNEL) {
10513                 if (strcmp(res->mode_value, "Tunnel")) {
10514                         printf("Please set mode to Tunnel.\n");
10515                         return;
10516                 }
10517
10518                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10519                 mask->mac_addr_byte_mask = res->mac_addr_byte_mask;
10520                 mask->tunnel_id_mask = rte_cpu_to_be_32(res->tunnel_id_mask);
10521                 mask->tunnel_type_mask = res->tunnel_type_mask;
10522         } else {
10523                 if (strcmp(res->mode_value, "IP")) {
10524                         printf("Please set mode to IP.\n");
10525                         return;
10526                 }
10527
10528                 mask->vlan_tci_mask = rte_cpu_to_be_16(res->vlan_mask);
10529                 IPV4_ADDR_TO_UINT(res->ipv4_src, mask->ipv4_mask.src_ip);
10530                 IPV4_ADDR_TO_UINT(res->ipv4_dst, mask->ipv4_mask.dst_ip);
10531                 IPV6_ADDR_TO_ARRAY(res->ipv6_src, mask->ipv6_mask.src_ip);
10532                 IPV6_ADDR_TO_ARRAY(res->ipv6_dst, mask->ipv6_mask.dst_ip);
10533                 mask->src_port_mask = rte_cpu_to_be_16(res->port_src);
10534                 mask->dst_port_mask = rte_cpu_to_be_16(res->port_dst);
10535         }
10536
10537         cmd_reconfig_device_queue(res->port_id, 1, 1);
10538 }
10539
10540 cmdline_parse_token_string_t cmd_flow_director_mask =
10541         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10542                                  flow_director_mask, "flow_director_mask");
10543 cmdline_parse_token_num_t cmd_flow_director_mask_port_id =
10544         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10545                               port_id, UINT16);
10546 cmdline_parse_token_string_t cmd_flow_director_mask_vlan =
10547         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10548                                  vlan, "vlan");
10549 cmdline_parse_token_num_t cmd_flow_director_mask_vlan_value =
10550         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10551                               vlan_mask, UINT16);
10552 cmdline_parse_token_string_t cmd_flow_director_mask_src =
10553         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10554                                  src_mask, "src_mask");
10555 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_src =
10556         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10557                                  ipv4_src);
10558 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_src =
10559         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10560                                  ipv6_src);
10561 cmdline_parse_token_num_t cmd_flow_director_mask_port_src =
10562         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10563                               port_src, UINT16);
10564 cmdline_parse_token_string_t cmd_flow_director_mask_dst =
10565         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10566                                  dst_mask, "dst_mask");
10567 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv4_dst =
10568         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10569                                  ipv4_dst);
10570 cmdline_parse_token_ipaddr_t cmd_flow_director_mask_ipv6_dst =
10571         TOKEN_IPADDR_INITIALIZER(struct cmd_flow_director_mask_result,
10572                                  ipv6_dst);
10573 cmdline_parse_token_num_t cmd_flow_director_mask_port_dst =
10574         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10575                               port_dst, UINT16);
10576
10577 cmdline_parse_token_string_t cmd_flow_director_mask_mode =
10578         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10579                                  mode, "mode");
10580 cmdline_parse_token_string_t cmd_flow_director_mask_mode_ip =
10581         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10582                                  mode_value, "IP");
10583 cmdline_parse_token_string_t cmd_flow_director_mask_mode_mac_vlan =
10584         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10585                                  mode_value, "MAC-VLAN");
10586 cmdline_parse_token_string_t cmd_flow_director_mask_mode_tunnel =
10587         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10588                                  mode_value, "Tunnel");
10589 cmdline_parse_token_string_t cmd_flow_director_mask_mac =
10590         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10591                                  mac, "mac");
10592 cmdline_parse_token_num_t cmd_flow_director_mask_mac_value =
10593         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10594                               mac_addr_byte_mask, UINT8);
10595 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_type =
10596         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10597                                  tunnel_type, "tunnel-type");
10598 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_type_value =
10599         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10600                               tunnel_type_mask, UINT8);
10601 cmdline_parse_token_string_t cmd_flow_director_mask_tunnel_id =
10602         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result,
10603                                  tunnel_id, "tunnel-id");
10604 cmdline_parse_token_num_t cmd_flow_director_mask_tunnel_id_value =
10605         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result,
10606                               tunnel_id_mask, UINT32);
10607
10608 cmdline_parse_inst_t cmd_set_flow_director_ip_mask = {
10609         .f = cmd_flow_director_mask_parsed,
10610         .data = NULL,
10611         .help_str = "flow_director_mask ... : "
10612                 "Set IP mode flow director's mask on NIC",
10613         .tokens = {
10614                 (void *)&cmd_flow_director_mask,
10615                 (void *)&cmd_flow_director_mask_port_id,
10616                 (void *)&cmd_flow_director_mask_mode,
10617                 (void *)&cmd_flow_director_mask_mode_ip,
10618                 (void *)&cmd_flow_director_mask_vlan,
10619                 (void *)&cmd_flow_director_mask_vlan_value,
10620                 (void *)&cmd_flow_director_mask_src,
10621                 (void *)&cmd_flow_director_mask_ipv4_src,
10622                 (void *)&cmd_flow_director_mask_ipv6_src,
10623                 (void *)&cmd_flow_director_mask_port_src,
10624                 (void *)&cmd_flow_director_mask_dst,
10625                 (void *)&cmd_flow_director_mask_ipv4_dst,
10626                 (void *)&cmd_flow_director_mask_ipv6_dst,
10627                 (void *)&cmd_flow_director_mask_port_dst,
10628                 NULL,
10629         },
10630 };
10631
10632 cmdline_parse_inst_t cmd_set_flow_director_mac_vlan_mask = {
10633         .f = cmd_flow_director_mask_parsed,
10634         .data = NULL,
10635         .help_str = "flow_director_mask ... : Set MAC VLAN mode "
10636                 "flow director's mask on NIC",
10637         .tokens = {
10638                 (void *)&cmd_flow_director_mask,
10639                 (void *)&cmd_flow_director_mask_port_id,
10640                 (void *)&cmd_flow_director_mask_mode,
10641                 (void *)&cmd_flow_director_mask_mode_mac_vlan,
10642                 (void *)&cmd_flow_director_mask_vlan,
10643                 (void *)&cmd_flow_director_mask_vlan_value,
10644                 NULL,
10645         },
10646 };
10647
10648 cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = {
10649         .f = cmd_flow_director_mask_parsed,
10650         .data = NULL,
10651         .help_str = "flow_director_mask ... : Set tunnel mode "
10652                 "flow director's mask on NIC",
10653         .tokens = {
10654                 (void *)&cmd_flow_director_mask,
10655                 (void *)&cmd_flow_director_mask_port_id,
10656                 (void *)&cmd_flow_director_mask_mode,
10657                 (void *)&cmd_flow_director_mask_mode_tunnel,
10658                 (void *)&cmd_flow_director_mask_vlan,
10659                 (void *)&cmd_flow_director_mask_vlan_value,
10660                 (void *)&cmd_flow_director_mask_mac,
10661                 (void *)&cmd_flow_director_mask_mac_value,
10662                 (void *)&cmd_flow_director_mask_tunnel_type,
10663                 (void *)&cmd_flow_director_mask_tunnel_type_value,
10664                 (void *)&cmd_flow_director_mask_tunnel_id,
10665                 (void *)&cmd_flow_director_mask_tunnel_id_value,
10666                 NULL,
10667         },
10668 };
10669
10670 /* *** deal with flow director mask on flexible payload *** */
10671 struct cmd_flow_director_flex_mask_result {
10672         cmdline_fixed_string_t flow_director_flexmask;
10673         portid_t port_id;
10674         cmdline_fixed_string_t flow;
10675         cmdline_fixed_string_t flow_type;
10676         cmdline_fixed_string_t mask;
10677 };
10678
10679 static void
10680 cmd_flow_director_flex_mask_parsed(void *parsed_result,
10681                           __attribute__((unused)) struct cmdline *cl,
10682                           __attribute__((unused)) void *data)
10683 {
10684         struct cmd_flow_director_flex_mask_result *res = parsed_result;
10685         struct rte_eth_fdir_info fdir_info;
10686         struct rte_eth_fdir_flex_mask flex_mask;
10687         struct rte_port *port;
10688         uint32_t flow_type_mask;
10689         uint16_t i;
10690         int ret;
10691
10692         if (res->port_id > nb_ports) {
10693                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10694                 return;
10695         }
10696
10697         port = &ports[res->port_id];
10698         /** Check if the port is not started **/
10699         if (port->port_status != RTE_PORT_STOPPED) {
10700                 printf("Please stop port %d first\n", res->port_id);
10701                 return;
10702         }
10703
10704         memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask));
10705         ret = parse_flexbytes(res->mask,
10706                         flex_mask.mask,
10707                         RTE_ETH_FDIR_MAX_FLEXLEN);
10708         if (ret < 0) {
10709                 printf("error: Cannot parse mask input.\n");
10710                 return;
10711         }
10712
10713         memset(&fdir_info, 0, sizeof(fdir_info));
10714         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
10715                                 RTE_ETH_FILTER_INFO, &fdir_info);
10716         if (ret < 0) {
10717                 printf("Cannot get FDir filter info\n");
10718                 return;
10719         }
10720
10721         if (!strcmp(res->flow_type, "none")) {
10722                 /* means don't specify the flow type */
10723                 flex_mask.flow_type = RTE_ETH_FLOW_UNKNOWN;
10724                 for (i = 0; i < RTE_ETH_FLOW_MAX; i++)
10725                         memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i],
10726                                0, sizeof(struct rte_eth_fdir_flex_mask));
10727                 port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1;
10728                 rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0],
10729                                  &flex_mask,
10730                                  sizeof(struct rte_eth_fdir_flex_mask));
10731                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10732                 return;
10733         }
10734         flow_type_mask = fdir_info.flow_types_mask[0];
10735         if (!strcmp(res->flow_type, "all")) {
10736                 if (!flow_type_mask) {
10737                         printf("No flow type supported\n");
10738                         return;
10739                 }
10740                 for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
10741                         if (flow_type_mask & (1 << i)) {
10742                                 flex_mask.flow_type = i;
10743                                 fdir_set_flex_mask(res->port_id, &flex_mask);
10744                         }
10745                 }
10746                 cmd_reconfig_device_queue(res->port_id, 1, 1);
10747                 return;
10748         }
10749         flex_mask.flow_type = str2flowtype(res->flow_type);
10750         if (!(flow_type_mask & (1 << flex_mask.flow_type))) {
10751                 printf("Flow type %s not supported on port %d\n",
10752                                 res->flow_type, res->port_id);
10753                 return;
10754         }
10755         fdir_set_flex_mask(res->port_id, &flex_mask);
10756         cmd_reconfig_device_queue(res->port_id, 1, 1);
10757 }
10758
10759 cmdline_parse_token_string_t cmd_flow_director_flexmask =
10760         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10761                                  flow_director_flexmask,
10762                                  "flow_director_flex_mask");
10763 cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id =
10764         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10765                               port_id, UINT16);
10766 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow =
10767         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10768                                  flow, "flow");
10769 cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type =
10770         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10771                 flow_type, "none#ipv4-other#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#"
10772                 "ipv6-other#ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#l2_payload#all");
10773 cmdline_parse_token_string_t cmd_flow_director_flexmask_mask =
10774         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result,
10775                                  mask, NULL);
10776
10777 cmdline_parse_inst_t cmd_set_flow_director_flex_mask = {
10778         .f = cmd_flow_director_flex_mask_parsed,
10779         .data = NULL,
10780         .help_str = "flow_director_flex_mask ... : "
10781                 "Set flow director's flex mask on NIC",
10782         .tokens = {
10783                 (void *)&cmd_flow_director_flexmask,
10784                 (void *)&cmd_flow_director_flexmask_port_id,
10785                 (void *)&cmd_flow_director_flexmask_flow,
10786                 (void *)&cmd_flow_director_flexmask_flow_type,
10787                 (void *)&cmd_flow_director_flexmask_mask,
10788                 NULL,
10789         },
10790 };
10791
10792 /* *** deal with flow director flexible payload configuration *** */
10793 struct cmd_flow_director_flexpayload_result {
10794         cmdline_fixed_string_t flow_director_flexpayload;
10795         portid_t port_id;
10796         cmdline_fixed_string_t payload_layer;
10797         cmdline_fixed_string_t payload_cfg;
10798 };
10799
10800 static inline int
10801 parse_offsets(const char *q_arg, uint16_t *offsets, uint16_t max_num)
10802 {
10803         char s[256];
10804         const char *p, *p0 = q_arg;
10805         char *end;
10806         unsigned long int_fld;
10807         char *str_fld[max_num];
10808         int i;
10809         unsigned size;
10810         int ret = -1;
10811
10812         p = strchr(p0, '(');
10813         if (p == NULL)
10814                 return -1;
10815         ++p;
10816         p0 = strchr(p, ')');
10817         if (p0 == NULL)
10818                 return -1;
10819
10820         size = p0 - p;
10821         if (size >= sizeof(s))
10822                 return -1;
10823
10824         snprintf(s, sizeof(s), "%.*s", size, p);
10825         ret = rte_strsplit(s, sizeof(s), str_fld, max_num, ',');
10826         if (ret < 0 || ret > max_num)
10827                 return -1;
10828         for (i = 0; i < ret; i++) {
10829                 errno = 0;
10830                 int_fld = strtoul(str_fld[i], &end, 0);
10831                 if (errno != 0 || *end != '\0' || int_fld > UINT16_MAX)
10832                         return -1;
10833                 offsets[i] = (uint16_t)int_fld;
10834         }
10835         return ret;
10836 }
10837
10838 static void
10839 cmd_flow_director_flxpld_parsed(void *parsed_result,
10840                           __attribute__((unused)) struct cmdline *cl,
10841                           __attribute__((unused)) void *data)
10842 {
10843         struct cmd_flow_director_flexpayload_result *res = parsed_result;
10844         struct rte_eth_flex_payload_cfg flex_cfg;
10845         struct rte_port *port;
10846         int ret = 0;
10847
10848         if (res->port_id > nb_ports) {
10849                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
10850                 return;
10851         }
10852
10853         port = &ports[res->port_id];
10854         /** Check if the port is not started **/
10855         if (port->port_status != RTE_PORT_STOPPED) {
10856                 printf("Please stop port %d first\n", res->port_id);
10857                 return;
10858         }
10859
10860         memset(&flex_cfg, 0, sizeof(struct rte_eth_flex_payload_cfg));
10861
10862         if (!strcmp(res->payload_layer, "raw"))
10863                 flex_cfg.type = RTE_ETH_RAW_PAYLOAD;
10864         else if (!strcmp(res->payload_layer, "l2"))
10865                 flex_cfg.type = RTE_ETH_L2_PAYLOAD;
10866         else if (!strcmp(res->payload_layer, "l3"))
10867                 flex_cfg.type = RTE_ETH_L3_PAYLOAD;
10868         else if (!strcmp(res->payload_layer, "l4"))
10869                 flex_cfg.type = RTE_ETH_L4_PAYLOAD;
10870
10871         ret = parse_offsets(res->payload_cfg, flex_cfg.src_offset,
10872                             RTE_ETH_FDIR_MAX_FLEXLEN);
10873         if (ret < 0) {
10874                 printf("error: Cannot parse flex payload input.\n");
10875                 return;
10876         }
10877
10878         fdir_set_flex_payload(res->port_id, &flex_cfg);
10879         cmd_reconfig_device_queue(res->port_id, 1, 1);
10880 }
10881
10882 cmdline_parse_token_string_t cmd_flow_director_flexpayload =
10883         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10884                                  flow_director_flexpayload,
10885                                  "flow_director_flex_payload");
10886 cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id =
10887         TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10888                               port_id, UINT16);
10889 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer =
10890         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10891                                  payload_layer, "raw#l2#l3#l4");
10892 cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg =
10893         TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result,
10894                                  payload_cfg, NULL);
10895
10896 cmdline_parse_inst_t cmd_set_flow_director_flex_payload = {
10897         .f = cmd_flow_director_flxpld_parsed,
10898         .data = NULL,
10899         .help_str = "flow_director_flexpayload ... : "
10900                 "Set flow director's flex payload on NIC",
10901         .tokens = {
10902                 (void *)&cmd_flow_director_flexpayload,
10903                 (void *)&cmd_flow_director_flexpayload_port_id,
10904                 (void *)&cmd_flow_director_flexpayload_payload_layer,
10905                 (void *)&cmd_flow_director_flexpayload_payload_cfg,
10906                 NULL,
10907         },
10908 };
10909
10910 /* Generic flow interface command. */
10911 extern cmdline_parse_inst_t cmd_flow;
10912
10913 /* *** Classification Filters Control *** */
10914 /* *** Get symmetric hash enable per port *** */
10915 struct cmd_get_sym_hash_ena_per_port_result {
10916         cmdline_fixed_string_t get_sym_hash_ena_per_port;
10917         portid_t port_id;
10918 };
10919
10920 static void
10921 cmd_get_sym_hash_per_port_parsed(void *parsed_result,
10922                                  __rte_unused struct cmdline *cl,
10923                                  __rte_unused void *data)
10924 {
10925         struct cmd_get_sym_hash_ena_per_port_result *res = parsed_result;
10926         struct rte_eth_hash_filter_info info;
10927         int ret;
10928
10929         if (rte_eth_dev_filter_supported(res->port_id,
10930                                 RTE_ETH_FILTER_HASH) < 0) {
10931                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10932                                                         res->port_id);
10933                 return;
10934         }
10935
10936         memset(&info, 0, sizeof(info));
10937         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10938         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10939                                                 RTE_ETH_FILTER_GET, &info);
10940
10941         if (ret < 0) {
10942                 printf("Cannot get symmetric hash enable per port "
10943                                         "on port %u\n", res->port_id);
10944                 return;
10945         }
10946
10947         printf("Symmetric hash is %s on port %u\n", info.info.enable ?
10948                                 "enabled" : "disabled", res->port_id);
10949 }
10950
10951 cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all =
10952         TOKEN_STRING_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10953                 get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port");
10954 cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id =
10955         TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result,
10956                 port_id, UINT16);
10957
10958 cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = {
10959         .f = cmd_get_sym_hash_per_port_parsed,
10960         .data = NULL,
10961         .help_str = "get_sym_hash_ena_per_port <port_id>",
10962         .tokens = {
10963                 (void *)&cmd_get_sym_hash_ena_per_port_all,
10964                 (void *)&cmd_get_sym_hash_ena_per_port_port_id,
10965                 NULL,
10966         },
10967 };
10968
10969 /* *** Set symmetric hash enable per port *** */
10970 struct cmd_set_sym_hash_ena_per_port_result {
10971         cmdline_fixed_string_t set_sym_hash_ena_per_port;
10972         cmdline_fixed_string_t enable;
10973         portid_t port_id;
10974 };
10975
10976 static void
10977 cmd_set_sym_hash_per_port_parsed(void *parsed_result,
10978                                  __rte_unused struct cmdline *cl,
10979                                  __rte_unused void *data)
10980 {
10981         struct cmd_set_sym_hash_ena_per_port_result *res = parsed_result;
10982         struct rte_eth_hash_filter_info info;
10983         int ret;
10984
10985         if (rte_eth_dev_filter_supported(res->port_id,
10986                                 RTE_ETH_FILTER_HASH) < 0) {
10987                 printf("RTE_ETH_FILTER_HASH not supported on port: %d\n",
10988                                                         res->port_id);
10989                 return;
10990         }
10991
10992         memset(&info, 0, sizeof(info));
10993         info.info_type = RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT;
10994         if (!strcmp(res->enable, "enable"))
10995                 info.info.enable = 1;
10996         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
10997                                         RTE_ETH_FILTER_SET, &info);
10998         if (ret < 0) {
10999                 printf("Cannot set symmetric hash enable per port on "
11000                                         "port %u\n", res->port_id);
11001                 return;
11002         }
11003         printf("Symmetric hash has been set to %s on port %u\n",
11004                                         res->enable, res->port_id);
11005 }
11006
11007 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all =
11008         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11009                 set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port");
11010 cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id =
11011         TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11012                 port_id, UINT16);
11013 cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable =
11014         TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result,
11015                 enable, "enable#disable");
11016
11017 cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = {
11018         .f = cmd_set_sym_hash_per_port_parsed,
11019         .data = NULL,
11020         .help_str = "set_sym_hash_ena_per_port <port_id> enable|disable",
11021         .tokens = {
11022                 (void *)&cmd_set_sym_hash_ena_per_port_all,
11023                 (void *)&cmd_set_sym_hash_ena_per_port_port_id,
11024                 (void *)&cmd_set_sym_hash_ena_per_port_enable,
11025                 NULL,
11026         },
11027 };
11028
11029 /* Get global config of hash function */
11030 struct cmd_get_hash_global_config_result {
11031         cmdline_fixed_string_t get_hash_global_config;
11032         portid_t port_id;
11033 };
11034
11035 static char *
11036 flowtype_to_str(uint16_t ftype)
11037 {
11038         uint16_t i;
11039         static struct {
11040                 char str[16];
11041                 uint16_t ftype;
11042         } ftype_table[] = {
11043                 {"ipv4", RTE_ETH_FLOW_IPV4},
11044                 {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
11045                 {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
11046                 {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
11047                 {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
11048                 {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
11049                 {"ipv6", RTE_ETH_FLOW_IPV6},
11050                 {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
11051                 {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
11052                 {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
11053                 {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
11054                 {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
11055                 {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
11056                 {"port", RTE_ETH_FLOW_PORT},
11057                 {"vxlan", RTE_ETH_FLOW_VXLAN},
11058                 {"geneve", RTE_ETH_FLOW_GENEVE},
11059                 {"nvgre", RTE_ETH_FLOW_NVGRE},
11060         };
11061
11062         for (i = 0; i < RTE_DIM(ftype_table); i++) {
11063                 if (ftype_table[i].ftype == ftype)
11064                         return ftype_table[i].str;
11065         }
11066
11067         return NULL;
11068 }
11069
11070 static void
11071 cmd_get_hash_global_config_parsed(void *parsed_result,
11072                                   __rte_unused struct cmdline *cl,
11073                                   __rte_unused void *data)
11074 {
11075         struct cmd_get_hash_global_config_result *res = parsed_result;
11076         struct rte_eth_hash_filter_info info;
11077         uint32_t idx, offset;
11078         uint16_t i;
11079         char *str;
11080         int ret;
11081
11082         if (rte_eth_dev_filter_supported(res->port_id,
11083                         RTE_ETH_FILTER_HASH) < 0) {
11084                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11085                                                         res->port_id);
11086                 return;
11087         }
11088
11089         memset(&info, 0, sizeof(info));
11090         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11091         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11092                                         RTE_ETH_FILTER_GET, &info);
11093         if (ret < 0) {
11094                 printf("Cannot get hash global configurations by port %d\n",
11095                                                         res->port_id);
11096                 return;
11097         }
11098
11099         switch (info.info.global_conf.hash_func) {
11100         case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
11101                 printf("Hash function is Toeplitz\n");
11102                 break;
11103         case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
11104                 printf("Hash function is Simple XOR\n");
11105                 break;
11106         default:
11107                 printf("Unknown hash function\n");
11108                 break;
11109         }
11110
11111         for (i = 0; i < RTE_ETH_FLOW_MAX; i++) {
11112                 idx = i / UINT32_BIT;
11113                 offset = i % UINT32_BIT;
11114                 if (!(info.info.global_conf.valid_bit_mask[idx] &
11115                                                 (1UL << offset)))
11116                         continue;
11117                 str = flowtype_to_str(i);
11118                 if (!str)
11119                         continue;
11120                 printf("Symmetric hash is %s globally for flow type %s "
11121                                                         "by port %d\n",
11122                         ((info.info.global_conf.sym_hash_enable_mask[idx] &
11123                         (1UL << offset)) ? "enabled" : "disabled"), str,
11124                                                         res->port_id);
11125         }
11126 }
11127
11128 cmdline_parse_token_string_t cmd_get_hash_global_config_all =
11129         TOKEN_STRING_INITIALIZER(struct cmd_get_hash_global_config_result,
11130                 get_hash_global_config, "get_hash_global_config");
11131 cmdline_parse_token_num_t cmd_get_hash_global_config_port_id =
11132         TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result,
11133                 port_id, UINT16);
11134
11135 cmdline_parse_inst_t cmd_get_hash_global_config = {
11136         .f = cmd_get_hash_global_config_parsed,
11137         .data = NULL,
11138         .help_str = "get_hash_global_config <port_id>",
11139         .tokens = {
11140                 (void *)&cmd_get_hash_global_config_all,
11141                 (void *)&cmd_get_hash_global_config_port_id,
11142                 NULL,
11143         },
11144 };
11145
11146 /* Set global config of hash function */
11147 struct cmd_set_hash_global_config_result {
11148         cmdline_fixed_string_t set_hash_global_config;
11149         portid_t port_id;
11150         cmdline_fixed_string_t hash_func;
11151         cmdline_fixed_string_t flow_type;
11152         cmdline_fixed_string_t enable;
11153 };
11154
11155 static void
11156 cmd_set_hash_global_config_parsed(void *parsed_result,
11157                                   __rte_unused struct cmdline *cl,
11158                                   __rte_unused void *data)
11159 {
11160         struct cmd_set_hash_global_config_result *res = parsed_result;
11161         struct rte_eth_hash_filter_info info;
11162         uint32_t ftype, idx, offset;
11163         int ret;
11164
11165         if (rte_eth_dev_filter_supported(res->port_id,
11166                                 RTE_ETH_FILTER_HASH) < 0) {
11167                 printf("RTE_ETH_FILTER_HASH not supported on port %d\n",
11168                                                         res->port_id);
11169                 return;
11170         }
11171         memset(&info, 0, sizeof(info));
11172         info.info_type = RTE_ETH_HASH_FILTER_GLOBAL_CONFIG;
11173         if (!strcmp(res->hash_func, "toeplitz"))
11174                 info.info.global_conf.hash_func =
11175                         RTE_ETH_HASH_FUNCTION_TOEPLITZ;
11176         else if (!strcmp(res->hash_func, "simple_xor"))
11177                 info.info.global_conf.hash_func =
11178                         RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
11179         else if (!strcmp(res->hash_func, "default"))
11180                 info.info.global_conf.hash_func =
11181                         RTE_ETH_HASH_FUNCTION_DEFAULT;
11182
11183         ftype = str2flowtype(res->flow_type);
11184         idx = ftype / (CHAR_BIT * sizeof(uint32_t));
11185         offset = ftype % (CHAR_BIT * sizeof(uint32_t));
11186         info.info.global_conf.valid_bit_mask[idx] |= (1UL << offset);
11187         if (!strcmp(res->enable, "enable"))
11188                 info.info.global_conf.sym_hash_enable_mask[idx] |=
11189                                                 (1UL << offset);
11190         ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11191                                         RTE_ETH_FILTER_SET, &info);
11192         if (ret < 0)
11193                 printf("Cannot set global hash configurations by port %d\n",
11194                                                         res->port_id);
11195         else
11196                 printf("Global hash configurations have been set "
11197                         "succcessfully by port %d\n", res->port_id);
11198 }
11199
11200 cmdline_parse_token_string_t cmd_set_hash_global_config_all =
11201         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11202                 set_hash_global_config, "set_hash_global_config");
11203 cmdline_parse_token_num_t cmd_set_hash_global_config_port_id =
11204         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result,
11205                 port_id, UINT16);
11206 cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func =
11207         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11208                 hash_func, "toeplitz#simple_xor#default");
11209 cmdline_parse_token_string_t cmd_set_hash_global_config_flow_type =
11210         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11211                 flow_type,
11212                 "ipv4#ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#ipv6#"
11213                 "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11214 cmdline_parse_token_string_t cmd_set_hash_global_config_enable =
11215         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result,
11216                 enable, "enable#disable");
11217
11218 cmdline_parse_inst_t cmd_set_hash_global_config = {
11219         .f = cmd_set_hash_global_config_parsed,
11220         .data = NULL,
11221         .help_str = "set_hash_global_config <port_id> "
11222                 "toeplitz|simple_xor|default "
11223                 "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11224                 "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|"
11225                 "l2_payload enable|disable",
11226         .tokens = {
11227                 (void *)&cmd_set_hash_global_config_all,
11228                 (void *)&cmd_set_hash_global_config_port_id,
11229                 (void *)&cmd_set_hash_global_config_hash_func,
11230                 (void *)&cmd_set_hash_global_config_flow_type,
11231                 (void *)&cmd_set_hash_global_config_enable,
11232                 NULL,
11233         },
11234 };
11235
11236 /* Set hash input set */
11237 struct cmd_set_hash_input_set_result {
11238         cmdline_fixed_string_t set_hash_input_set;
11239         portid_t port_id;
11240         cmdline_fixed_string_t flow_type;
11241         cmdline_fixed_string_t inset_field;
11242         cmdline_fixed_string_t select;
11243 };
11244
11245 static enum rte_eth_input_set_field
11246 str2inset(char *string)
11247 {
11248         uint16_t i;
11249
11250         static const struct {
11251                 char str[32];
11252                 enum rte_eth_input_set_field inset;
11253         } inset_table[] = {
11254                 {"ethertype", RTE_ETH_INPUT_SET_L2_ETHERTYPE},
11255                 {"ovlan", RTE_ETH_INPUT_SET_L2_OUTER_VLAN},
11256                 {"ivlan", RTE_ETH_INPUT_SET_L2_INNER_VLAN},
11257                 {"src-ipv4", RTE_ETH_INPUT_SET_L3_SRC_IP4},
11258                 {"dst-ipv4", RTE_ETH_INPUT_SET_L3_DST_IP4},
11259                 {"ipv4-tos", RTE_ETH_INPUT_SET_L3_IP4_TOS},
11260                 {"ipv4-proto", RTE_ETH_INPUT_SET_L3_IP4_PROTO},
11261                 {"ipv4-ttl", RTE_ETH_INPUT_SET_L3_IP4_TTL},
11262                 {"src-ipv6", RTE_ETH_INPUT_SET_L3_SRC_IP6},
11263                 {"dst-ipv6", RTE_ETH_INPUT_SET_L3_DST_IP6},
11264                 {"ipv6-tc", RTE_ETH_INPUT_SET_L3_IP6_TC},
11265                 {"ipv6-next-header", RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER},
11266                 {"ipv6-hop-limits", RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS},
11267                 {"udp-src-port", RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
11268                 {"udp-dst-port", RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
11269                 {"tcp-src-port", RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
11270                 {"tcp-dst-port", RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
11271                 {"sctp-src-port", RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
11272                 {"sctp-dst-port", RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
11273                 {"sctp-veri-tag", RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG},
11274                 {"udp-key", RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY},
11275                 {"gre-key", RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY},
11276                 {"fld-1st", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD},
11277                 {"fld-2nd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD},
11278                 {"fld-3rd", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD},
11279                 {"fld-4th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD},
11280                 {"fld-5th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD},
11281                 {"fld-6th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD},
11282                 {"fld-7th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD},
11283                 {"fld-8th", RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD},
11284                 {"none", RTE_ETH_INPUT_SET_NONE},
11285         };
11286
11287         for (i = 0; i < RTE_DIM(inset_table); i++) {
11288                 if (!strcmp(string, inset_table[i].str))
11289                         return inset_table[i].inset;
11290         }
11291
11292         return RTE_ETH_INPUT_SET_UNKNOWN;
11293 }
11294
11295 static void
11296 cmd_set_hash_input_set_parsed(void *parsed_result,
11297                               __rte_unused struct cmdline *cl,
11298                               __rte_unused void *data)
11299 {
11300         struct cmd_set_hash_input_set_result *res = parsed_result;
11301         struct rte_eth_hash_filter_info info;
11302
11303         memset(&info, 0, sizeof(info));
11304         info.info_type = RTE_ETH_HASH_FILTER_INPUT_SET_SELECT;
11305         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11306         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11307         info.info.input_set_conf.inset_size = 1;
11308         if (!strcmp(res->select, "select"))
11309                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11310         else if (!strcmp(res->select, "add"))
11311                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11312         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_HASH,
11313                                 RTE_ETH_FILTER_SET, &info);
11314 }
11315
11316 cmdline_parse_token_string_t cmd_set_hash_input_set_cmd =
11317         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11318                 set_hash_input_set, "set_hash_input_set");
11319 cmdline_parse_token_num_t cmd_set_hash_input_set_port_id =
11320         TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result,
11321                 port_id, UINT16);
11322 cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type =
11323         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11324                 flow_type, NULL);
11325 cmdline_parse_token_string_t cmd_set_hash_input_set_field =
11326         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11327                 inset_field,
11328                 "ovlan#ivlan#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11329                 "ipv4-tos#ipv4-proto#ipv6-tc#ipv6-next-header#udp-src-port#"
11330                 "udp-dst-port#tcp-src-port#tcp-dst-port#sctp-src-port#"
11331                 "sctp-dst-port#sctp-veri-tag#udp-key#gre-key#fld-1st#"
11332                 "fld-2nd#fld-3rd#fld-4th#fld-5th#fld-6th#fld-7th#"
11333                 "fld-8th#none");
11334 cmdline_parse_token_string_t cmd_set_hash_input_set_select =
11335         TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result,
11336                 select, "select#add");
11337
11338 cmdline_parse_inst_t cmd_set_hash_input_set = {
11339         .f = cmd_set_hash_input_set_parsed,
11340         .data = NULL,
11341         .help_str = "set_hash_input_set <port_id> "
11342         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11343         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> "
11344         "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|"
11345         "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|"
11346         "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|"
11347         "gre-key|fld-1st|fld-2nd|fld-3rd|fld-4th|fld-5th|fld-6th|"
11348         "fld-7th|fld-8th|none select|add",
11349         .tokens = {
11350                 (void *)&cmd_set_hash_input_set_cmd,
11351                 (void *)&cmd_set_hash_input_set_port_id,
11352                 (void *)&cmd_set_hash_input_set_flow_type,
11353                 (void *)&cmd_set_hash_input_set_field,
11354                 (void *)&cmd_set_hash_input_set_select,
11355                 NULL,
11356         },
11357 };
11358
11359 /* Set flow director input set */
11360 struct cmd_set_fdir_input_set_result {
11361         cmdline_fixed_string_t set_fdir_input_set;
11362         portid_t port_id;
11363         cmdline_fixed_string_t flow_type;
11364         cmdline_fixed_string_t inset_field;
11365         cmdline_fixed_string_t select;
11366 };
11367
11368 static void
11369 cmd_set_fdir_input_set_parsed(void *parsed_result,
11370         __rte_unused struct cmdline *cl,
11371         __rte_unused void *data)
11372 {
11373         struct cmd_set_fdir_input_set_result *res = parsed_result;
11374         struct rte_eth_fdir_filter_info info;
11375
11376         memset(&info, 0, sizeof(info));
11377         info.info_type = RTE_ETH_FDIR_FILTER_INPUT_SET_SELECT;
11378         info.info.input_set_conf.flow_type = str2flowtype(res->flow_type);
11379         info.info.input_set_conf.field[0] = str2inset(res->inset_field);
11380         info.info.input_set_conf.inset_size = 1;
11381         if (!strcmp(res->select, "select"))
11382                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_SELECT;
11383         else if (!strcmp(res->select, "add"))
11384                 info.info.input_set_conf.op = RTE_ETH_INPUT_SET_ADD;
11385         rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR,
11386                 RTE_ETH_FILTER_SET, &info);
11387 }
11388
11389 cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd =
11390         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11391         set_fdir_input_set, "set_fdir_input_set");
11392 cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id =
11393         TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result,
11394         port_id, UINT16);
11395 cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type =
11396         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11397         flow_type,
11398         "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#"
11399         "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload");
11400 cmdline_parse_token_string_t cmd_set_fdir_input_set_field =
11401         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11402         inset_field,
11403         "ivlan#ethertype#src-ipv4#dst-ipv4#src-ipv6#dst-ipv6#"
11404         "ipv4-tos#ipv4-proto#ipv4-ttl#ipv6-tc#ipv6-next-header#"
11405         "ipv6-hop-limits#udp-src-port#udp-dst-port#"
11406         "tcp-src-port#tcp-dst-port#sctp-src-port#sctp-dst-port#"
11407         "sctp-veri-tag#none");
11408 cmdline_parse_token_string_t cmd_set_fdir_input_set_select =
11409         TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result,
11410         select, "select#add");
11411
11412 cmdline_parse_inst_t cmd_set_fdir_input_set = {
11413         .f = cmd_set_fdir_input_set_parsed,
11414         .data = NULL,
11415         .help_str = "set_fdir_input_set <port_id> "
11416         "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
11417         "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload "
11418         "ivlan|ethertype|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|"
11419         "ipv4-tos|ipv4-proto|ipv4-ttl|ipv6-tc|ipv6-next-header|"
11420         "ipv6-hop-limits|udp-src-port|udp-dst-port|"
11421         "tcp-src-port|tcp-dst-port|sctp-src-port|sctp-dst-port|"
11422         "sctp-veri-tag|none select|add",
11423         .tokens = {
11424                 (void *)&cmd_set_fdir_input_set_cmd,
11425                 (void *)&cmd_set_fdir_input_set_port_id,
11426                 (void *)&cmd_set_fdir_input_set_flow_type,
11427                 (void *)&cmd_set_fdir_input_set_field,
11428                 (void *)&cmd_set_fdir_input_set_select,
11429                 NULL,
11430         },
11431 };
11432
11433 /* *** ADD/REMOVE A MULTICAST MAC ADDRESS TO/FROM A PORT *** */
11434 struct cmd_mcast_addr_result {
11435         cmdline_fixed_string_t mcast_addr_cmd;
11436         cmdline_fixed_string_t what;
11437         uint16_t port_num;
11438         struct ether_addr mc_addr;
11439 };
11440
11441 static void cmd_mcast_addr_parsed(void *parsed_result,
11442                 __attribute__((unused)) struct cmdline *cl,
11443                 __attribute__((unused)) void *data)
11444 {
11445         struct cmd_mcast_addr_result *res = parsed_result;
11446
11447         if (!is_multicast_ether_addr(&res->mc_addr)) {
11448                 printf("Invalid multicast addr %02X:%02X:%02X:%02X:%02X:%02X\n",
11449                        res->mc_addr.addr_bytes[0], res->mc_addr.addr_bytes[1],
11450                        res->mc_addr.addr_bytes[2], res->mc_addr.addr_bytes[3],
11451                        res->mc_addr.addr_bytes[4], res->mc_addr.addr_bytes[5]);
11452                 return;
11453         }
11454         if (strcmp(res->what, "add") == 0)
11455                 mcast_addr_add(res->port_num, &res->mc_addr);
11456         else
11457                 mcast_addr_remove(res->port_num, &res->mc_addr);
11458 }
11459
11460 cmdline_parse_token_string_t cmd_mcast_addr_cmd =
11461         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result,
11462                                  mcast_addr_cmd, "mcast_addr");
11463 cmdline_parse_token_string_t cmd_mcast_addr_what =
11464         TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what,
11465                                  "add#remove");
11466 cmdline_parse_token_num_t cmd_mcast_addr_portnum =
11467         TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16);
11468 cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr =
11469         TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address);
11470
11471 cmdline_parse_inst_t cmd_mcast_addr = {
11472         .f = cmd_mcast_addr_parsed,
11473         .data = (void *)0,
11474         .help_str = "mcast_addr add|remove <port_id> <mcast_addr>: "
11475                 "Add/Remove multicast MAC address on port_id",
11476         .tokens = {
11477                 (void *)&cmd_mcast_addr_cmd,
11478                 (void *)&cmd_mcast_addr_what,
11479                 (void *)&cmd_mcast_addr_portnum,
11480                 (void *)&cmd_mcast_addr_addr,
11481                 NULL,
11482         },
11483 };
11484
11485 /* l2 tunnel config
11486  * only support E-tag now.
11487  */
11488
11489 /* Ether type config */
11490 struct cmd_config_l2_tunnel_eth_type_result {
11491         cmdline_fixed_string_t port;
11492         cmdline_fixed_string_t config;
11493         cmdline_fixed_string_t all;
11494         uint8_t id;
11495         cmdline_fixed_string_t l2_tunnel;
11496         cmdline_fixed_string_t l2_tunnel_type;
11497         cmdline_fixed_string_t eth_type;
11498         uint16_t eth_type_val;
11499 };
11500
11501 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_port =
11502         TOKEN_STRING_INITIALIZER
11503                 (struct cmd_config_l2_tunnel_eth_type_result,
11504                  port, "port");
11505 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_config =
11506         TOKEN_STRING_INITIALIZER
11507                 (struct cmd_config_l2_tunnel_eth_type_result,
11508                  config, "config");
11509 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_all_str =
11510         TOKEN_STRING_INITIALIZER
11511                 (struct cmd_config_l2_tunnel_eth_type_result,
11512                  all, "all");
11513 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_id =
11514         TOKEN_NUM_INITIALIZER
11515                 (struct cmd_config_l2_tunnel_eth_type_result,
11516                  id, UINT8);
11517 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel =
11518         TOKEN_STRING_INITIALIZER
11519                 (struct cmd_config_l2_tunnel_eth_type_result,
11520                  l2_tunnel, "l2-tunnel");
11521 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_l2_tunnel_type =
11522         TOKEN_STRING_INITIALIZER
11523                 (struct cmd_config_l2_tunnel_eth_type_result,
11524                  l2_tunnel_type, "E-tag");
11525 cmdline_parse_token_string_t cmd_config_l2_tunnel_eth_type_eth_type =
11526         TOKEN_STRING_INITIALIZER
11527                 (struct cmd_config_l2_tunnel_eth_type_result,
11528                  eth_type, "ether-type");
11529 cmdline_parse_token_num_t cmd_config_l2_tunnel_eth_type_eth_type_val =
11530         TOKEN_NUM_INITIALIZER
11531                 (struct cmd_config_l2_tunnel_eth_type_result,
11532                  eth_type_val, UINT16);
11533
11534 static enum rte_eth_tunnel_type
11535 str2fdir_l2_tunnel_type(char *string)
11536 {
11537         uint32_t i = 0;
11538
11539         static const struct {
11540                 char str[32];
11541                 enum rte_eth_tunnel_type type;
11542         } l2_tunnel_type_str[] = {
11543                 {"E-tag", RTE_L2_TUNNEL_TYPE_E_TAG},
11544         };
11545
11546         for (i = 0; i < RTE_DIM(l2_tunnel_type_str); i++) {
11547                 if (!strcmp(l2_tunnel_type_str[i].str, string))
11548                         return l2_tunnel_type_str[i].type;
11549         }
11550         return RTE_TUNNEL_TYPE_NONE;
11551 }
11552
11553 /* ether type config for all ports */
11554 static void
11555 cmd_config_l2_tunnel_eth_type_all_parsed
11556         (void *parsed_result,
11557          __attribute__((unused)) struct cmdline *cl,
11558          __attribute__((unused)) void *data)
11559 {
11560         struct cmd_config_l2_tunnel_eth_type_result *res = parsed_result;
11561         struct rte_eth_l2_tunnel_conf entry;
11562         portid_t pid;
11563
11564         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11565         entry.ether_type = res->eth_type_val;
11566
11567         RTE_ETH_FOREACH_DEV(pid) {
11568                 rte_eth_dev_l2_tunnel_eth_type_conf(pid, &entry);
11569         }
11570 }
11571
11572 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_all = {
11573         .f = cmd_config_l2_tunnel_eth_type_all_parsed,
11574         .data = NULL,
11575         .help_str = "port config all l2-tunnel E-tag ether-type <value>",
11576         .tokens = {
11577                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11578                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11579                 (void *)&cmd_config_l2_tunnel_eth_type_all_str,
11580                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11581                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11582                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11583                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11584                 NULL,
11585         },
11586 };
11587
11588 /* ether type config for a specific port */
11589 static void
11590 cmd_config_l2_tunnel_eth_type_specific_parsed(
11591         void *parsed_result,
11592         __attribute__((unused)) struct cmdline *cl,
11593         __attribute__((unused)) void *data)
11594 {
11595         struct cmd_config_l2_tunnel_eth_type_result *res =
11596                  parsed_result;
11597         struct rte_eth_l2_tunnel_conf entry;
11598
11599         if (port_id_is_invalid(res->id, ENABLED_WARN))
11600                 return;
11601
11602         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11603         entry.ether_type = res->eth_type_val;
11604
11605         rte_eth_dev_l2_tunnel_eth_type_conf(res->id, &entry);
11606 }
11607
11608 cmdline_parse_inst_t cmd_config_l2_tunnel_eth_type_specific = {
11609         .f = cmd_config_l2_tunnel_eth_type_specific_parsed,
11610         .data = NULL,
11611         .help_str = "port config <port_id> l2-tunnel E-tag ether-type <value>",
11612         .tokens = {
11613                 (void *)&cmd_config_l2_tunnel_eth_type_port,
11614                 (void *)&cmd_config_l2_tunnel_eth_type_config,
11615                 (void *)&cmd_config_l2_tunnel_eth_type_id,
11616                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel,
11617                 (void *)&cmd_config_l2_tunnel_eth_type_l2_tunnel_type,
11618                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type,
11619                 (void *)&cmd_config_l2_tunnel_eth_type_eth_type_val,
11620                 NULL,
11621         },
11622 };
11623
11624 /* Enable/disable l2 tunnel */
11625 struct cmd_config_l2_tunnel_en_dis_result {
11626         cmdline_fixed_string_t port;
11627         cmdline_fixed_string_t config;
11628         cmdline_fixed_string_t all;
11629         uint8_t id;
11630         cmdline_fixed_string_t l2_tunnel;
11631         cmdline_fixed_string_t l2_tunnel_type;
11632         cmdline_fixed_string_t en_dis;
11633 };
11634
11635 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_port =
11636         TOKEN_STRING_INITIALIZER
11637                 (struct cmd_config_l2_tunnel_en_dis_result,
11638                  port, "port");
11639 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_config =
11640         TOKEN_STRING_INITIALIZER
11641                 (struct cmd_config_l2_tunnel_en_dis_result,
11642                  config, "config");
11643 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_all_str =
11644         TOKEN_STRING_INITIALIZER
11645                 (struct cmd_config_l2_tunnel_en_dis_result,
11646                  all, "all");
11647 cmdline_parse_token_num_t cmd_config_l2_tunnel_en_dis_id =
11648         TOKEN_NUM_INITIALIZER
11649                 (struct cmd_config_l2_tunnel_en_dis_result,
11650                  id, UINT8);
11651 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel =
11652         TOKEN_STRING_INITIALIZER
11653                 (struct cmd_config_l2_tunnel_en_dis_result,
11654                  l2_tunnel, "l2-tunnel");
11655 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_l2_tunnel_type =
11656         TOKEN_STRING_INITIALIZER
11657                 (struct cmd_config_l2_tunnel_en_dis_result,
11658                  l2_tunnel_type, "E-tag");
11659 cmdline_parse_token_string_t cmd_config_l2_tunnel_en_dis_en_dis =
11660         TOKEN_STRING_INITIALIZER
11661                 (struct cmd_config_l2_tunnel_en_dis_result,
11662                  en_dis, "enable#disable");
11663
11664 /* enable/disable l2 tunnel for all ports */
11665 static void
11666 cmd_config_l2_tunnel_en_dis_all_parsed(
11667         void *parsed_result,
11668         __attribute__((unused)) struct cmdline *cl,
11669         __attribute__((unused)) void *data)
11670 {
11671         struct cmd_config_l2_tunnel_en_dis_result *res = parsed_result;
11672         struct rte_eth_l2_tunnel_conf entry;
11673         portid_t pid;
11674         uint8_t en;
11675
11676         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11677
11678         if (!strcmp("enable", res->en_dis))
11679                 en = 1;
11680         else
11681                 en = 0;
11682
11683         RTE_ETH_FOREACH_DEV(pid) {
11684                 rte_eth_dev_l2_tunnel_offload_set(pid,
11685                                                   &entry,
11686                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11687                                                   en);
11688         }
11689 }
11690
11691 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_all = {
11692         .f = cmd_config_l2_tunnel_en_dis_all_parsed,
11693         .data = NULL,
11694         .help_str = "port config all l2-tunnel E-tag enable|disable",
11695         .tokens = {
11696                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11697                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11698                 (void *)&cmd_config_l2_tunnel_en_dis_all_str,
11699                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11700                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11701                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11702                 NULL,
11703         },
11704 };
11705
11706 /* enable/disable l2 tunnel for a port */
11707 static void
11708 cmd_config_l2_tunnel_en_dis_specific_parsed(
11709         void *parsed_result,
11710         __attribute__((unused)) struct cmdline *cl,
11711         __attribute__((unused)) void *data)
11712 {
11713         struct cmd_config_l2_tunnel_en_dis_result *res =
11714                 parsed_result;
11715         struct rte_eth_l2_tunnel_conf entry;
11716
11717         if (port_id_is_invalid(res->id, ENABLED_WARN))
11718                 return;
11719
11720         entry.l2_tunnel_type = str2fdir_l2_tunnel_type(res->l2_tunnel_type);
11721
11722         if (!strcmp("enable", res->en_dis))
11723                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11724                                                   &entry,
11725                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11726                                                   1);
11727         else
11728                 rte_eth_dev_l2_tunnel_offload_set(res->id,
11729                                                   &entry,
11730                                                   ETH_L2_TUNNEL_ENABLE_MASK,
11731                                                   0);
11732 }
11733
11734 cmdline_parse_inst_t cmd_config_l2_tunnel_en_dis_specific = {
11735         .f = cmd_config_l2_tunnel_en_dis_specific_parsed,
11736         .data = NULL,
11737         .help_str = "port config <port_id> l2-tunnel E-tag enable|disable",
11738         .tokens = {
11739                 (void *)&cmd_config_l2_tunnel_en_dis_port,
11740                 (void *)&cmd_config_l2_tunnel_en_dis_config,
11741                 (void *)&cmd_config_l2_tunnel_en_dis_id,
11742                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel,
11743                 (void *)&cmd_config_l2_tunnel_en_dis_l2_tunnel_type,
11744                 (void *)&cmd_config_l2_tunnel_en_dis_en_dis,
11745                 NULL,
11746         },
11747 };
11748
11749 /* E-tag configuration */
11750
11751 /* Common result structure for all E-tag configuration */
11752 struct cmd_config_e_tag_result {
11753         cmdline_fixed_string_t e_tag;
11754         cmdline_fixed_string_t set;
11755         cmdline_fixed_string_t insertion;
11756         cmdline_fixed_string_t stripping;
11757         cmdline_fixed_string_t forwarding;
11758         cmdline_fixed_string_t filter;
11759         cmdline_fixed_string_t add;
11760         cmdline_fixed_string_t del;
11761         cmdline_fixed_string_t on;
11762         cmdline_fixed_string_t off;
11763         cmdline_fixed_string_t on_off;
11764         cmdline_fixed_string_t port_tag_id;
11765         uint32_t port_tag_id_val;
11766         cmdline_fixed_string_t e_tag_id;
11767         uint16_t e_tag_id_val;
11768         cmdline_fixed_string_t dst_pool;
11769         uint8_t dst_pool_val;
11770         cmdline_fixed_string_t port;
11771         portid_t port_id;
11772         cmdline_fixed_string_t vf;
11773         uint8_t vf_id;
11774 };
11775
11776 /* Common CLI fields for all E-tag configuration */
11777 cmdline_parse_token_string_t cmd_config_e_tag_e_tag =
11778         TOKEN_STRING_INITIALIZER
11779                 (struct cmd_config_e_tag_result,
11780                  e_tag, "E-tag");
11781 cmdline_parse_token_string_t cmd_config_e_tag_set =
11782         TOKEN_STRING_INITIALIZER
11783                 (struct cmd_config_e_tag_result,
11784                  set, "set");
11785 cmdline_parse_token_string_t cmd_config_e_tag_insertion =
11786         TOKEN_STRING_INITIALIZER
11787                 (struct cmd_config_e_tag_result,
11788                  insertion, "insertion");
11789 cmdline_parse_token_string_t cmd_config_e_tag_stripping =
11790         TOKEN_STRING_INITIALIZER
11791                 (struct cmd_config_e_tag_result,
11792                  stripping, "stripping");
11793 cmdline_parse_token_string_t cmd_config_e_tag_forwarding =
11794         TOKEN_STRING_INITIALIZER
11795                 (struct cmd_config_e_tag_result,
11796                  forwarding, "forwarding");
11797 cmdline_parse_token_string_t cmd_config_e_tag_filter =
11798         TOKEN_STRING_INITIALIZER
11799                 (struct cmd_config_e_tag_result,
11800                  filter, "filter");
11801 cmdline_parse_token_string_t cmd_config_e_tag_add =
11802         TOKEN_STRING_INITIALIZER
11803                 (struct cmd_config_e_tag_result,
11804                  add, "add");
11805 cmdline_parse_token_string_t cmd_config_e_tag_del =
11806         TOKEN_STRING_INITIALIZER
11807                 (struct cmd_config_e_tag_result,
11808                  del, "del");
11809 cmdline_parse_token_string_t cmd_config_e_tag_on =
11810         TOKEN_STRING_INITIALIZER
11811                 (struct cmd_config_e_tag_result,
11812                  on, "on");
11813 cmdline_parse_token_string_t cmd_config_e_tag_off =
11814         TOKEN_STRING_INITIALIZER
11815                 (struct cmd_config_e_tag_result,
11816                  off, "off");
11817 cmdline_parse_token_string_t cmd_config_e_tag_on_off =
11818         TOKEN_STRING_INITIALIZER
11819                 (struct cmd_config_e_tag_result,
11820                  on_off, "on#off");
11821 cmdline_parse_token_string_t cmd_config_e_tag_port_tag_id =
11822         TOKEN_STRING_INITIALIZER
11823                 (struct cmd_config_e_tag_result,
11824                  port_tag_id, "port-tag-id");
11825 cmdline_parse_token_num_t cmd_config_e_tag_port_tag_id_val =
11826         TOKEN_NUM_INITIALIZER
11827                 (struct cmd_config_e_tag_result,
11828                  port_tag_id_val, UINT32);
11829 cmdline_parse_token_string_t cmd_config_e_tag_e_tag_id =
11830         TOKEN_STRING_INITIALIZER
11831                 (struct cmd_config_e_tag_result,
11832                  e_tag_id, "e-tag-id");
11833 cmdline_parse_token_num_t cmd_config_e_tag_e_tag_id_val =
11834         TOKEN_NUM_INITIALIZER
11835                 (struct cmd_config_e_tag_result,
11836                  e_tag_id_val, UINT16);
11837 cmdline_parse_token_string_t cmd_config_e_tag_dst_pool =
11838         TOKEN_STRING_INITIALIZER
11839                 (struct cmd_config_e_tag_result,
11840                  dst_pool, "dst-pool");
11841 cmdline_parse_token_num_t cmd_config_e_tag_dst_pool_val =
11842         TOKEN_NUM_INITIALIZER
11843                 (struct cmd_config_e_tag_result,
11844                  dst_pool_val, UINT8);
11845 cmdline_parse_token_string_t cmd_config_e_tag_port =
11846         TOKEN_STRING_INITIALIZER
11847                 (struct cmd_config_e_tag_result,
11848                  port, "port");
11849 cmdline_parse_token_num_t cmd_config_e_tag_port_id =
11850         TOKEN_NUM_INITIALIZER
11851                 (struct cmd_config_e_tag_result,
11852                  port_id, UINT16);
11853 cmdline_parse_token_string_t cmd_config_e_tag_vf =
11854         TOKEN_STRING_INITIALIZER
11855                 (struct cmd_config_e_tag_result,
11856                  vf, "vf");
11857 cmdline_parse_token_num_t cmd_config_e_tag_vf_id =
11858         TOKEN_NUM_INITIALIZER
11859                 (struct cmd_config_e_tag_result,
11860                  vf_id, UINT8);
11861
11862 /* E-tag insertion configuration */
11863 static void
11864 cmd_config_e_tag_insertion_en_parsed(
11865         void *parsed_result,
11866         __attribute__((unused)) struct cmdline *cl,
11867         __attribute__((unused)) void *data)
11868 {
11869         struct cmd_config_e_tag_result *res =
11870                 parsed_result;
11871         struct rte_eth_l2_tunnel_conf entry;
11872
11873         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11874                 return;
11875
11876         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11877         entry.tunnel_id = res->port_tag_id_val;
11878         entry.vf_id = res->vf_id;
11879         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11880                                           &entry,
11881                                           ETH_L2_TUNNEL_INSERTION_MASK,
11882                                           1);
11883 }
11884
11885 static void
11886 cmd_config_e_tag_insertion_dis_parsed(
11887         void *parsed_result,
11888         __attribute__((unused)) struct cmdline *cl,
11889         __attribute__((unused)) void *data)
11890 {
11891         struct cmd_config_e_tag_result *res =
11892                 parsed_result;
11893         struct rte_eth_l2_tunnel_conf entry;
11894
11895         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11896                 return;
11897
11898         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11899         entry.vf_id = res->vf_id;
11900
11901         rte_eth_dev_l2_tunnel_offload_set(res->port_id,
11902                                           &entry,
11903                                           ETH_L2_TUNNEL_INSERTION_MASK,
11904                                           0);
11905 }
11906
11907 cmdline_parse_inst_t cmd_config_e_tag_insertion_en = {
11908         .f = cmd_config_e_tag_insertion_en_parsed,
11909         .data = NULL,
11910         .help_str = "E-tag ... : E-tag insertion enable",
11911         .tokens = {
11912                 (void *)&cmd_config_e_tag_e_tag,
11913                 (void *)&cmd_config_e_tag_set,
11914                 (void *)&cmd_config_e_tag_insertion,
11915                 (void *)&cmd_config_e_tag_on,
11916                 (void *)&cmd_config_e_tag_port_tag_id,
11917                 (void *)&cmd_config_e_tag_port_tag_id_val,
11918                 (void *)&cmd_config_e_tag_port,
11919                 (void *)&cmd_config_e_tag_port_id,
11920                 (void *)&cmd_config_e_tag_vf,
11921                 (void *)&cmd_config_e_tag_vf_id,
11922                 NULL,
11923         },
11924 };
11925
11926 cmdline_parse_inst_t cmd_config_e_tag_insertion_dis = {
11927         .f = cmd_config_e_tag_insertion_dis_parsed,
11928         .data = NULL,
11929         .help_str = "E-tag ... : E-tag insertion disable",
11930         .tokens = {
11931                 (void *)&cmd_config_e_tag_e_tag,
11932                 (void *)&cmd_config_e_tag_set,
11933                 (void *)&cmd_config_e_tag_insertion,
11934                 (void *)&cmd_config_e_tag_off,
11935                 (void *)&cmd_config_e_tag_port,
11936                 (void *)&cmd_config_e_tag_port_id,
11937                 (void *)&cmd_config_e_tag_vf,
11938                 (void *)&cmd_config_e_tag_vf_id,
11939                 NULL,
11940         },
11941 };
11942
11943 /* E-tag stripping configuration */
11944 static void
11945 cmd_config_e_tag_stripping_parsed(
11946         void *parsed_result,
11947         __attribute__((unused)) struct cmdline *cl,
11948         __attribute__((unused)) void *data)
11949 {
11950         struct cmd_config_e_tag_result *res =
11951                 parsed_result;
11952         struct rte_eth_l2_tunnel_conf entry;
11953
11954         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11955                 return;
11956
11957         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
11958
11959         if (!strcmp(res->on_off, "on"))
11960                 rte_eth_dev_l2_tunnel_offload_set
11961                         (res->port_id,
11962                          &entry,
11963                          ETH_L2_TUNNEL_STRIPPING_MASK,
11964                          1);
11965         else
11966                 rte_eth_dev_l2_tunnel_offload_set
11967                         (res->port_id,
11968                          &entry,
11969                          ETH_L2_TUNNEL_STRIPPING_MASK,
11970                          0);
11971 }
11972
11973 cmdline_parse_inst_t cmd_config_e_tag_stripping_en_dis = {
11974         .f = cmd_config_e_tag_stripping_parsed,
11975         .data = NULL,
11976         .help_str = "E-tag ... : E-tag stripping enable/disable",
11977         .tokens = {
11978                 (void *)&cmd_config_e_tag_e_tag,
11979                 (void *)&cmd_config_e_tag_set,
11980                 (void *)&cmd_config_e_tag_stripping,
11981                 (void *)&cmd_config_e_tag_on_off,
11982                 (void *)&cmd_config_e_tag_port,
11983                 (void *)&cmd_config_e_tag_port_id,
11984                 NULL,
11985         },
11986 };
11987
11988 /* E-tag forwarding configuration */
11989 static void
11990 cmd_config_e_tag_forwarding_parsed(
11991         void *parsed_result,
11992         __attribute__((unused)) struct cmdline *cl,
11993         __attribute__((unused)) void *data)
11994 {
11995         struct cmd_config_e_tag_result *res = parsed_result;
11996         struct rte_eth_l2_tunnel_conf entry;
11997
11998         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
11999                 return;
12000
12001         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12002
12003         if (!strcmp(res->on_off, "on"))
12004                 rte_eth_dev_l2_tunnel_offload_set
12005                         (res->port_id,
12006                          &entry,
12007                          ETH_L2_TUNNEL_FORWARDING_MASK,
12008                          1);
12009         else
12010                 rte_eth_dev_l2_tunnel_offload_set
12011                         (res->port_id,
12012                          &entry,
12013                          ETH_L2_TUNNEL_FORWARDING_MASK,
12014                          0);
12015 }
12016
12017 cmdline_parse_inst_t cmd_config_e_tag_forwarding_en_dis = {
12018         .f = cmd_config_e_tag_forwarding_parsed,
12019         .data = NULL,
12020         .help_str = "E-tag ... : E-tag forwarding enable/disable",
12021         .tokens = {
12022                 (void *)&cmd_config_e_tag_e_tag,
12023                 (void *)&cmd_config_e_tag_set,
12024                 (void *)&cmd_config_e_tag_forwarding,
12025                 (void *)&cmd_config_e_tag_on_off,
12026                 (void *)&cmd_config_e_tag_port,
12027                 (void *)&cmd_config_e_tag_port_id,
12028                 NULL,
12029         },
12030 };
12031
12032 /* E-tag filter configuration */
12033 static void
12034 cmd_config_e_tag_filter_add_parsed(
12035         void *parsed_result,
12036         __attribute__((unused)) struct cmdline *cl,
12037         __attribute__((unused)) void *data)
12038 {
12039         struct cmd_config_e_tag_result *res = parsed_result;
12040         struct rte_eth_l2_tunnel_conf entry;
12041         int ret = 0;
12042
12043         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12044                 return;
12045
12046         if (res->e_tag_id_val > 0x3fff) {
12047                 printf("e-tag-id must be equal or less than 0x3fff.\n");
12048                 return;
12049         }
12050
12051         ret = rte_eth_dev_filter_supported(res->port_id,
12052                                            RTE_ETH_FILTER_L2_TUNNEL);
12053         if (ret < 0) {
12054                 printf("E-tag filter is not supported on port %u.\n",
12055                        res->port_id);
12056                 return;
12057         }
12058
12059         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12060         entry.tunnel_id = res->e_tag_id_val;
12061         entry.pool = res->dst_pool_val;
12062
12063         ret = rte_eth_dev_filter_ctrl(res->port_id,
12064                                       RTE_ETH_FILTER_L2_TUNNEL,
12065                                       RTE_ETH_FILTER_ADD,
12066                                       &entry);
12067         if (ret < 0)
12068                 printf("E-tag filter programming error: (%s)\n",
12069                        strerror(-ret));
12070 }
12071
12072 cmdline_parse_inst_t cmd_config_e_tag_filter_add = {
12073         .f = cmd_config_e_tag_filter_add_parsed,
12074         .data = NULL,
12075         .help_str = "E-tag ... : E-tag filter add",
12076         .tokens = {
12077                 (void *)&cmd_config_e_tag_e_tag,
12078                 (void *)&cmd_config_e_tag_set,
12079                 (void *)&cmd_config_e_tag_filter,
12080                 (void *)&cmd_config_e_tag_add,
12081                 (void *)&cmd_config_e_tag_e_tag_id,
12082                 (void *)&cmd_config_e_tag_e_tag_id_val,
12083                 (void *)&cmd_config_e_tag_dst_pool,
12084                 (void *)&cmd_config_e_tag_dst_pool_val,
12085                 (void *)&cmd_config_e_tag_port,
12086                 (void *)&cmd_config_e_tag_port_id,
12087                 NULL,
12088         },
12089 };
12090
12091 static void
12092 cmd_config_e_tag_filter_del_parsed(
12093         void *parsed_result,
12094         __attribute__((unused)) struct cmdline *cl,
12095         __attribute__((unused)) void *data)
12096 {
12097         struct cmd_config_e_tag_result *res = parsed_result;
12098         struct rte_eth_l2_tunnel_conf entry;
12099         int ret = 0;
12100
12101         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12102                 return;
12103
12104         if (res->e_tag_id_val > 0x3fff) {
12105                 printf("e-tag-id must be less than 0x3fff.\n");
12106                 return;
12107         }
12108
12109         ret = rte_eth_dev_filter_supported(res->port_id,
12110                                            RTE_ETH_FILTER_L2_TUNNEL);
12111         if (ret < 0) {
12112                 printf("E-tag filter is not supported on port %u.\n",
12113                        res->port_id);
12114                 return;
12115         }
12116
12117         entry.l2_tunnel_type = RTE_L2_TUNNEL_TYPE_E_TAG;
12118         entry.tunnel_id = res->e_tag_id_val;
12119
12120         ret = rte_eth_dev_filter_ctrl(res->port_id,
12121                                       RTE_ETH_FILTER_L2_TUNNEL,
12122                                       RTE_ETH_FILTER_DELETE,
12123                                       &entry);
12124         if (ret < 0)
12125                 printf("E-tag filter programming error: (%s)\n",
12126                        strerror(-ret));
12127 }
12128
12129 cmdline_parse_inst_t cmd_config_e_tag_filter_del = {
12130         .f = cmd_config_e_tag_filter_del_parsed,
12131         .data = NULL,
12132         .help_str = "E-tag ... : E-tag filter delete",
12133         .tokens = {
12134                 (void *)&cmd_config_e_tag_e_tag,
12135                 (void *)&cmd_config_e_tag_set,
12136                 (void *)&cmd_config_e_tag_filter,
12137                 (void *)&cmd_config_e_tag_del,
12138                 (void *)&cmd_config_e_tag_e_tag_id,
12139                 (void *)&cmd_config_e_tag_e_tag_id_val,
12140                 (void *)&cmd_config_e_tag_port,
12141                 (void *)&cmd_config_e_tag_port_id,
12142                 NULL,
12143         },
12144 };
12145
12146 /* vf vlan anti spoof configuration */
12147
12148 /* Common result structure for vf vlan anti spoof */
12149 struct cmd_vf_vlan_anti_spoof_result {
12150         cmdline_fixed_string_t set;
12151         cmdline_fixed_string_t vf;
12152         cmdline_fixed_string_t vlan;
12153         cmdline_fixed_string_t antispoof;
12154         portid_t port_id;
12155         uint32_t vf_id;
12156         cmdline_fixed_string_t on_off;
12157 };
12158
12159 /* Common CLI fields for vf vlan anti spoof enable disable */
12160 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_set =
12161         TOKEN_STRING_INITIALIZER
12162                 (struct cmd_vf_vlan_anti_spoof_result,
12163                  set, "set");
12164 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vf =
12165         TOKEN_STRING_INITIALIZER
12166                 (struct cmd_vf_vlan_anti_spoof_result,
12167                  vf, "vf");
12168 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_vlan =
12169         TOKEN_STRING_INITIALIZER
12170                 (struct cmd_vf_vlan_anti_spoof_result,
12171                  vlan, "vlan");
12172 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof =
12173         TOKEN_STRING_INITIALIZER
12174                 (struct cmd_vf_vlan_anti_spoof_result,
12175                  antispoof, "antispoof");
12176 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id =
12177         TOKEN_NUM_INITIALIZER
12178                 (struct cmd_vf_vlan_anti_spoof_result,
12179                  port_id, UINT16);
12180 cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id =
12181         TOKEN_NUM_INITIALIZER
12182                 (struct cmd_vf_vlan_anti_spoof_result,
12183                  vf_id, UINT32);
12184 cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_on_off =
12185         TOKEN_STRING_INITIALIZER
12186                 (struct cmd_vf_vlan_anti_spoof_result,
12187                  on_off, "on#off");
12188
12189 static void
12190 cmd_set_vf_vlan_anti_spoof_parsed(
12191         void *parsed_result,
12192         __attribute__((unused)) struct cmdline *cl,
12193         __attribute__((unused)) void *data)
12194 {
12195         struct cmd_vf_vlan_anti_spoof_result *res = parsed_result;
12196         int ret = -ENOTSUP;
12197
12198         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12199
12200         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12201                 return;
12202
12203 #ifdef RTE_LIBRTE_IXGBE_PMD
12204         if (ret == -ENOTSUP)
12205                 ret = rte_pmd_ixgbe_set_vf_vlan_anti_spoof(res->port_id,
12206                                 res->vf_id, is_on);
12207 #endif
12208 #ifdef RTE_LIBRTE_I40E_PMD
12209         if (ret == -ENOTSUP)
12210                 ret = rte_pmd_i40e_set_vf_vlan_anti_spoof(res->port_id,
12211                                 res->vf_id, is_on);
12212 #endif
12213 #ifdef RTE_LIBRTE_BNXT_PMD
12214         if (ret == -ENOTSUP)
12215                 ret = rte_pmd_bnxt_set_vf_vlan_anti_spoof(res->port_id,
12216                                 res->vf_id, is_on);
12217 #endif
12218
12219         switch (ret) {
12220         case 0:
12221                 break;
12222         case -EINVAL:
12223                 printf("invalid vf_id %d\n", res->vf_id);
12224                 break;
12225         case -ENODEV:
12226                 printf("invalid port_id %d\n", res->port_id);
12227                 break;
12228         case -ENOTSUP:
12229                 printf("function not implemented\n");
12230                 break;
12231         default:
12232                 printf("programming error: (%s)\n", strerror(-ret));
12233         }
12234 }
12235
12236 cmdline_parse_inst_t cmd_set_vf_vlan_anti_spoof = {
12237         .f = cmd_set_vf_vlan_anti_spoof_parsed,
12238         .data = NULL,
12239         .help_str = "set vf vlan antispoof <port_id> <vf_id> on|off",
12240         .tokens = {
12241                 (void *)&cmd_vf_vlan_anti_spoof_set,
12242                 (void *)&cmd_vf_vlan_anti_spoof_vf,
12243                 (void *)&cmd_vf_vlan_anti_spoof_vlan,
12244                 (void *)&cmd_vf_vlan_anti_spoof_antispoof,
12245                 (void *)&cmd_vf_vlan_anti_spoof_port_id,
12246                 (void *)&cmd_vf_vlan_anti_spoof_vf_id,
12247                 (void *)&cmd_vf_vlan_anti_spoof_on_off,
12248                 NULL,
12249         },
12250 };
12251
12252 /* vf mac anti spoof configuration */
12253
12254 /* Common result structure for vf mac anti spoof */
12255 struct cmd_vf_mac_anti_spoof_result {
12256         cmdline_fixed_string_t set;
12257         cmdline_fixed_string_t vf;
12258         cmdline_fixed_string_t mac;
12259         cmdline_fixed_string_t antispoof;
12260         portid_t port_id;
12261         uint32_t vf_id;
12262         cmdline_fixed_string_t on_off;
12263 };
12264
12265 /* Common CLI fields for vf mac anti spoof enable disable */
12266 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_set =
12267         TOKEN_STRING_INITIALIZER
12268                 (struct cmd_vf_mac_anti_spoof_result,
12269                  set, "set");
12270 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_vf =
12271         TOKEN_STRING_INITIALIZER
12272                 (struct cmd_vf_mac_anti_spoof_result,
12273                  vf, "vf");
12274 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_mac =
12275         TOKEN_STRING_INITIALIZER
12276                 (struct cmd_vf_mac_anti_spoof_result,
12277                  mac, "mac");
12278 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof =
12279         TOKEN_STRING_INITIALIZER
12280                 (struct cmd_vf_mac_anti_spoof_result,
12281                  antispoof, "antispoof");
12282 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id =
12283         TOKEN_NUM_INITIALIZER
12284                 (struct cmd_vf_mac_anti_spoof_result,
12285                  port_id, UINT16);
12286 cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id =
12287         TOKEN_NUM_INITIALIZER
12288                 (struct cmd_vf_mac_anti_spoof_result,
12289                  vf_id, UINT32);
12290 cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_on_off =
12291         TOKEN_STRING_INITIALIZER
12292                 (struct cmd_vf_mac_anti_spoof_result,
12293                  on_off, "on#off");
12294
12295 static void
12296 cmd_set_vf_mac_anti_spoof_parsed(
12297         void *parsed_result,
12298         __attribute__((unused)) struct cmdline *cl,
12299         __attribute__((unused)) void *data)
12300 {
12301         struct cmd_vf_mac_anti_spoof_result *res = parsed_result;
12302         int ret = -ENOTSUP;
12303
12304         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12305
12306         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12307                 return;
12308
12309 #ifdef RTE_LIBRTE_IXGBE_PMD
12310         if (ret == -ENOTSUP)
12311                 ret = rte_pmd_ixgbe_set_vf_mac_anti_spoof(res->port_id,
12312                         res->vf_id, is_on);
12313 #endif
12314 #ifdef RTE_LIBRTE_I40E_PMD
12315         if (ret == -ENOTSUP)
12316                 ret = rte_pmd_i40e_set_vf_mac_anti_spoof(res->port_id,
12317                         res->vf_id, is_on);
12318 #endif
12319 #ifdef RTE_LIBRTE_BNXT_PMD
12320         if (ret == -ENOTSUP)
12321                 ret = rte_pmd_bnxt_set_vf_mac_anti_spoof(res->port_id,
12322                         res->vf_id, is_on);
12323 #endif
12324
12325         switch (ret) {
12326         case 0:
12327                 break;
12328         case -EINVAL:
12329                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12330                 break;
12331         case -ENODEV:
12332                 printf("invalid port_id %d\n", res->port_id);
12333                 break;
12334         case -ENOTSUP:
12335                 printf("function not implemented\n");
12336                 break;
12337         default:
12338                 printf("programming error: (%s)\n", strerror(-ret));
12339         }
12340 }
12341
12342 cmdline_parse_inst_t cmd_set_vf_mac_anti_spoof = {
12343         .f = cmd_set_vf_mac_anti_spoof_parsed,
12344         .data = NULL,
12345         .help_str = "set vf mac antispoof <port_id> <vf_id> on|off",
12346         .tokens = {
12347                 (void *)&cmd_vf_mac_anti_spoof_set,
12348                 (void *)&cmd_vf_mac_anti_spoof_vf,
12349                 (void *)&cmd_vf_mac_anti_spoof_mac,
12350                 (void *)&cmd_vf_mac_anti_spoof_antispoof,
12351                 (void *)&cmd_vf_mac_anti_spoof_port_id,
12352                 (void *)&cmd_vf_mac_anti_spoof_vf_id,
12353                 (void *)&cmd_vf_mac_anti_spoof_on_off,
12354                 NULL,
12355         },
12356 };
12357
12358 /* vf vlan strip queue configuration */
12359
12360 /* Common result structure for vf mac anti spoof */
12361 struct cmd_vf_vlan_stripq_result {
12362         cmdline_fixed_string_t set;
12363         cmdline_fixed_string_t vf;
12364         cmdline_fixed_string_t vlan;
12365         cmdline_fixed_string_t stripq;
12366         portid_t port_id;
12367         uint16_t vf_id;
12368         cmdline_fixed_string_t on_off;
12369 };
12370
12371 /* Common CLI fields for vf vlan strip enable disable */
12372 cmdline_parse_token_string_t cmd_vf_vlan_stripq_set =
12373         TOKEN_STRING_INITIALIZER
12374                 (struct cmd_vf_vlan_stripq_result,
12375                  set, "set");
12376 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vf =
12377         TOKEN_STRING_INITIALIZER
12378                 (struct cmd_vf_vlan_stripq_result,
12379                  vf, "vf");
12380 cmdline_parse_token_string_t cmd_vf_vlan_stripq_vlan =
12381         TOKEN_STRING_INITIALIZER
12382                 (struct cmd_vf_vlan_stripq_result,
12383                  vlan, "vlan");
12384 cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq =
12385         TOKEN_STRING_INITIALIZER
12386                 (struct cmd_vf_vlan_stripq_result,
12387                  stripq, "stripq");
12388 cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id =
12389         TOKEN_NUM_INITIALIZER
12390                 (struct cmd_vf_vlan_stripq_result,
12391                  port_id, UINT16);
12392 cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id =
12393         TOKEN_NUM_INITIALIZER
12394                 (struct cmd_vf_vlan_stripq_result,
12395                  vf_id, UINT16);
12396 cmdline_parse_token_string_t cmd_vf_vlan_stripq_on_off =
12397         TOKEN_STRING_INITIALIZER
12398                 (struct cmd_vf_vlan_stripq_result,
12399                  on_off, "on#off");
12400
12401 static void
12402 cmd_set_vf_vlan_stripq_parsed(
12403         void *parsed_result,
12404         __attribute__((unused)) struct cmdline *cl,
12405         __attribute__((unused)) void *data)
12406 {
12407         struct cmd_vf_vlan_stripq_result *res = parsed_result;
12408         int ret = -ENOTSUP;
12409
12410         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12411
12412         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12413                 return;
12414
12415 #ifdef RTE_LIBRTE_IXGBE_PMD
12416         if (ret == -ENOTSUP)
12417                 ret = rte_pmd_ixgbe_set_vf_vlan_stripq(res->port_id,
12418                         res->vf_id, is_on);
12419 #endif
12420 #ifdef RTE_LIBRTE_I40E_PMD
12421         if (ret == -ENOTSUP)
12422                 ret = rte_pmd_i40e_set_vf_vlan_stripq(res->port_id,
12423                         res->vf_id, is_on);
12424 #endif
12425 #ifdef RTE_LIBRTE_BNXT_PMD
12426         if (ret == -ENOTSUP)
12427                 ret = rte_pmd_bnxt_set_vf_vlan_stripq(res->port_id,
12428                         res->vf_id, is_on);
12429 #endif
12430
12431         switch (ret) {
12432         case 0:
12433                 break;
12434         case -EINVAL:
12435                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12436                 break;
12437         case -ENODEV:
12438                 printf("invalid port_id %d\n", res->port_id);
12439                 break;
12440         case -ENOTSUP:
12441                 printf("function not implemented\n");
12442                 break;
12443         default:
12444                 printf("programming error: (%s)\n", strerror(-ret));
12445         }
12446 }
12447
12448 cmdline_parse_inst_t cmd_set_vf_vlan_stripq = {
12449         .f = cmd_set_vf_vlan_stripq_parsed,
12450         .data = NULL,
12451         .help_str = "set vf vlan stripq <port_id> <vf_id> on|off",
12452         .tokens = {
12453                 (void *)&cmd_vf_vlan_stripq_set,
12454                 (void *)&cmd_vf_vlan_stripq_vf,
12455                 (void *)&cmd_vf_vlan_stripq_vlan,
12456                 (void *)&cmd_vf_vlan_stripq_stripq,
12457                 (void *)&cmd_vf_vlan_stripq_port_id,
12458                 (void *)&cmd_vf_vlan_stripq_vf_id,
12459                 (void *)&cmd_vf_vlan_stripq_on_off,
12460                 NULL,
12461         },
12462 };
12463
12464 /* vf vlan insert configuration */
12465
12466 /* Common result structure for vf vlan insert */
12467 struct cmd_vf_vlan_insert_result {
12468         cmdline_fixed_string_t set;
12469         cmdline_fixed_string_t vf;
12470         cmdline_fixed_string_t vlan;
12471         cmdline_fixed_string_t insert;
12472         portid_t port_id;
12473         uint16_t vf_id;
12474         uint16_t vlan_id;
12475 };
12476
12477 /* Common CLI fields for vf vlan insert enable disable */
12478 cmdline_parse_token_string_t cmd_vf_vlan_insert_set =
12479         TOKEN_STRING_INITIALIZER
12480                 (struct cmd_vf_vlan_insert_result,
12481                  set, "set");
12482 cmdline_parse_token_string_t cmd_vf_vlan_insert_vf =
12483         TOKEN_STRING_INITIALIZER
12484                 (struct cmd_vf_vlan_insert_result,
12485                  vf, "vf");
12486 cmdline_parse_token_string_t cmd_vf_vlan_insert_vlan =
12487         TOKEN_STRING_INITIALIZER
12488                 (struct cmd_vf_vlan_insert_result,
12489                  vlan, "vlan");
12490 cmdline_parse_token_string_t cmd_vf_vlan_insert_insert =
12491         TOKEN_STRING_INITIALIZER
12492                 (struct cmd_vf_vlan_insert_result,
12493                  insert, "insert");
12494 cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id =
12495         TOKEN_NUM_INITIALIZER
12496                 (struct cmd_vf_vlan_insert_result,
12497                  port_id, UINT16);
12498 cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id =
12499         TOKEN_NUM_INITIALIZER
12500                 (struct cmd_vf_vlan_insert_result,
12501                  vf_id, UINT16);
12502 cmdline_parse_token_num_t cmd_vf_vlan_insert_vlan_id =
12503         TOKEN_NUM_INITIALIZER
12504                 (struct cmd_vf_vlan_insert_result,
12505                  vlan_id, UINT16);
12506
12507 static void
12508 cmd_set_vf_vlan_insert_parsed(
12509         void *parsed_result,
12510         __attribute__((unused)) struct cmdline *cl,
12511         __attribute__((unused)) void *data)
12512 {
12513         struct cmd_vf_vlan_insert_result *res = parsed_result;
12514         int ret = -ENOTSUP;
12515
12516         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12517                 return;
12518
12519 #ifdef RTE_LIBRTE_IXGBE_PMD
12520         if (ret == -ENOTSUP)
12521                 ret = rte_pmd_ixgbe_set_vf_vlan_insert(res->port_id, res->vf_id,
12522                         res->vlan_id);
12523 #endif
12524 #ifdef RTE_LIBRTE_I40E_PMD
12525         if (ret == -ENOTSUP)
12526                 ret = rte_pmd_i40e_set_vf_vlan_insert(res->port_id, res->vf_id,
12527                         res->vlan_id);
12528 #endif
12529 #ifdef RTE_LIBRTE_BNXT_PMD
12530         if (ret == -ENOTSUP)
12531                 ret = rte_pmd_bnxt_set_vf_vlan_insert(res->port_id, res->vf_id,
12532                         res->vlan_id);
12533 #endif
12534
12535         switch (ret) {
12536         case 0:
12537                 break;
12538         case -EINVAL:
12539                 printf("invalid vf_id %d or vlan_id %d\n", res->vf_id, res->vlan_id);
12540                 break;
12541         case -ENODEV:
12542                 printf("invalid port_id %d\n", res->port_id);
12543                 break;
12544         case -ENOTSUP:
12545                 printf("function not implemented\n");
12546                 break;
12547         default:
12548                 printf("programming error: (%s)\n", strerror(-ret));
12549         }
12550 }
12551
12552 cmdline_parse_inst_t cmd_set_vf_vlan_insert = {
12553         .f = cmd_set_vf_vlan_insert_parsed,
12554         .data = NULL,
12555         .help_str = "set vf vlan insert <port_id> <vf_id> <vlan_id>",
12556         .tokens = {
12557                 (void *)&cmd_vf_vlan_insert_set,
12558                 (void *)&cmd_vf_vlan_insert_vf,
12559                 (void *)&cmd_vf_vlan_insert_vlan,
12560                 (void *)&cmd_vf_vlan_insert_insert,
12561                 (void *)&cmd_vf_vlan_insert_port_id,
12562                 (void *)&cmd_vf_vlan_insert_vf_id,
12563                 (void *)&cmd_vf_vlan_insert_vlan_id,
12564                 NULL,
12565         },
12566 };
12567
12568 /* tx loopback configuration */
12569
12570 /* Common result structure for tx loopback */
12571 struct cmd_tx_loopback_result {
12572         cmdline_fixed_string_t set;
12573         cmdline_fixed_string_t tx;
12574         cmdline_fixed_string_t loopback;
12575         portid_t port_id;
12576         cmdline_fixed_string_t on_off;
12577 };
12578
12579 /* Common CLI fields for tx loopback enable disable */
12580 cmdline_parse_token_string_t cmd_tx_loopback_set =
12581         TOKEN_STRING_INITIALIZER
12582                 (struct cmd_tx_loopback_result,
12583                  set, "set");
12584 cmdline_parse_token_string_t cmd_tx_loopback_tx =
12585         TOKEN_STRING_INITIALIZER
12586                 (struct cmd_tx_loopback_result,
12587                  tx, "tx");
12588 cmdline_parse_token_string_t cmd_tx_loopback_loopback =
12589         TOKEN_STRING_INITIALIZER
12590                 (struct cmd_tx_loopback_result,
12591                  loopback, "loopback");
12592 cmdline_parse_token_num_t cmd_tx_loopback_port_id =
12593         TOKEN_NUM_INITIALIZER
12594                 (struct cmd_tx_loopback_result,
12595                  port_id, UINT16);
12596 cmdline_parse_token_string_t cmd_tx_loopback_on_off =
12597         TOKEN_STRING_INITIALIZER
12598                 (struct cmd_tx_loopback_result,
12599                  on_off, "on#off");
12600
12601 static void
12602 cmd_set_tx_loopback_parsed(
12603         void *parsed_result,
12604         __attribute__((unused)) struct cmdline *cl,
12605         __attribute__((unused)) void *data)
12606 {
12607         struct cmd_tx_loopback_result *res = parsed_result;
12608         int ret = -ENOTSUP;
12609
12610         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12611
12612         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12613                 return;
12614
12615 #ifdef RTE_LIBRTE_IXGBE_PMD
12616         if (ret == -ENOTSUP)
12617                 ret = rte_pmd_ixgbe_set_tx_loopback(res->port_id, is_on);
12618 #endif
12619 #ifdef RTE_LIBRTE_I40E_PMD
12620         if (ret == -ENOTSUP)
12621                 ret = rte_pmd_i40e_set_tx_loopback(res->port_id, is_on);
12622 #endif
12623 #ifdef RTE_LIBRTE_BNXT_PMD
12624         if (ret == -ENOTSUP)
12625                 ret = rte_pmd_bnxt_set_tx_loopback(res->port_id, is_on);
12626 #endif
12627
12628         switch (ret) {
12629         case 0:
12630                 break;
12631         case -EINVAL:
12632                 printf("invalid is_on %d\n", is_on);
12633                 break;
12634         case -ENODEV:
12635                 printf("invalid port_id %d\n", res->port_id);
12636                 break;
12637         case -ENOTSUP:
12638                 printf("function not implemented\n");
12639                 break;
12640         default:
12641                 printf("programming error: (%s)\n", strerror(-ret));
12642         }
12643 }
12644
12645 cmdline_parse_inst_t cmd_set_tx_loopback = {
12646         .f = cmd_set_tx_loopback_parsed,
12647         .data = NULL,
12648         .help_str = "set tx loopback <port_id> on|off",
12649         .tokens = {
12650                 (void *)&cmd_tx_loopback_set,
12651                 (void *)&cmd_tx_loopback_tx,
12652                 (void *)&cmd_tx_loopback_loopback,
12653                 (void *)&cmd_tx_loopback_port_id,
12654                 (void *)&cmd_tx_loopback_on_off,
12655                 NULL,
12656         },
12657 };
12658
12659 /* all queues drop enable configuration */
12660
12661 /* Common result structure for all queues drop enable */
12662 struct cmd_all_queues_drop_en_result {
12663         cmdline_fixed_string_t set;
12664         cmdline_fixed_string_t all;
12665         cmdline_fixed_string_t queues;
12666         cmdline_fixed_string_t drop;
12667         portid_t port_id;
12668         cmdline_fixed_string_t on_off;
12669 };
12670
12671 /* Common CLI fields for tx loopback enable disable */
12672 cmdline_parse_token_string_t cmd_all_queues_drop_en_set =
12673         TOKEN_STRING_INITIALIZER
12674                 (struct cmd_all_queues_drop_en_result,
12675                  set, "set");
12676 cmdline_parse_token_string_t cmd_all_queues_drop_en_all =
12677         TOKEN_STRING_INITIALIZER
12678                 (struct cmd_all_queues_drop_en_result,
12679                  all, "all");
12680 cmdline_parse_token_string_t cmd_all_queues_drop_en_queues =
12681         TOKEN_STRING_INITIALIZER
12682                 (struct cmd_all_queues_drop_en_result,
12683                  queues, "queues");
12684 cmdline_parse_token_string_t cmd_all_queues_drop_en_drop =
12685         TOKEN_STRING_INITIALIZER
12686                 (struct cmd_all_queues_drop_en_result,
12687                  drop, "drop");
12688 cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id =
12689         TOKEN_NUM_INITIALIZER
12690                 (struct cmd_all_queues_drop_en_result,
12691                  port_id, UINT16);
12692 cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off =
12693         TOKEN_STRING_INITIALIZER
12694                 (struct cmd_all_queues_drop_en_result,
12695                  on_off, "on#off");
12696
12697 static void
12698 cmd_set_all_queues_drop_en_parsed(
12699         void *parsed_result,
12700         __attribute__((unused)) struct cmdline *cl,
12701         __attribute__((unused)) void *data)
12702 {
12703         struct cmd_all_queues_drop_en_result *res = parsed_result;
12704         int ret = -ENOTSUP;
12705         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12706
12707         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12708                 return;
12709
12710 #ifdef RTE_LIBRTE_IXGBE_PMD
12711         if (ret == -ENOTSUP)
12712                 ret = rte_pmd_ixgbe_set_all_queues_drop_en(res->port_id, is_on);
12713 #endif
12714 #ifdef RTE_LIBRTE_BNXT_PMD
12715         if (ret == -ENOTSUP)
12716                 ret = rte_pmd_bnxt_set_all_queues_drop_en(res->port_id, is_on);
12717 #endif
12718         switch (ret) {
12719         case 0:
12720                 break;
12721         case -EINVAL:
12722                 printf("invalid is_on %d\n", is_on);
12723                 break;
12724         case -ENODEV:
12725                 printf("invalid port_id %d\n", res->port_id);
12726                 break;
12727         case -ENOTSUP:
12728                 printf("function not implemented\n");
12729                 break;
12730         default:
12731                 printf("programming error: (%s)\n", strerror(-ret));
12732         }
12733 }
12734
12735 cmdline_parse_inst_t cmd_set_all_queues_drop_en = {
12736         .f = cmd_set_all_queues_drop_en_parsed,
12737         .data = NULL,
12738         .help_str = "set all queues drop <port_id> on|off",
12739         .tokens = {
12740                 (void *)&cmd_all_queues_drop_en_set,
12741                 (void *)&cmd_all_queues_drop_en_all,
12742                 (void *)&cmd_all_queues_drop_en_queues,
12743                 (void *)&cmd_all_queues_drop_en_drop,
12744                 (void *)&cmd_all_queues_drop_en_port_id,
12745                 (void *)&cmd_all_queues_drop_en_on_off,
12746                 NULL,
12747         },
12748 };
12749
12750 /* vf split drop enable configuration */
12751
12752 /* Common result structure for vf split drop enable */
12753 struct cmd_vf_split_drop_en_result {
12754         cmdline_fixed_string_t set;
12755         cmdline_fixed_string_t vf;
12756         cmdline_fixed_string_t split;
12757         cmdline_fixed_string_t drop;
12758         portid_t port_id;
12759         uint16_t vf_id;
12760         cmdline_fixed_string_t on_off;
12761 };
12762
12763 /* Common CLI fields for vf split drop enable disable */
12764 cmdline_parse_token_string_t cmd_vf_split_drop_en_set =
12765         TOKEN_STRING_INITIALIZER
12766                 (struct cmd_vf_split_drop_en_result,
12767                  set, "set");
12768 cmdline_parse_token_string_t cmd_vf_split_drop_en_vf =
12769         TOKEN_STRING_INITIALIZER
12770                 (struct cmd_vf_split_drop_en_result,
12771                  vf, "vf");
12772 cmdline_parse_token_string_t cmd_vf_split_drop_en_split =
12773         TOKEN_STRING_INITIALIZER
12774                 (struct cmd_vf_split_drop_en_result,
12775                  split, "split");
12776 cmdline_parse_token_string_t cmd_vf_split_drop_en_drop =
12777         TOKEN_STRING_INITIALIZER
12778                 (struct cmd_vf_split_drop_en_result,
12779                  drop, "drop");
12780 cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id =
12781         TOKEN_NUM_INITIALIZER
12782                 (struct cmd_vf_split_drop_en_result,
12783                  port_id, UINT16);
12784 cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id =
12785         TOKEN_NUM_INITIALIZER
12786                 (struct cmd_vf_split_drop_en_result,
12787                  vf_id, UINT16);
12788 cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off =
12789         TOKEN_STRING_INITIALIZER
12790                 (struct cmd_vf_split_drop_en_result,
12791                  on_off, "on#off");
12792
12793 static void
12794 cmd_set_vf_split_drop_en_parsed(
12795         void *parsed_result,
12796         __attribute__((unused)) struct cmdline *cl,
12797         __attribute__((unused)) void *data)
12798 {
12799         struct cmd_vf_split_drop_en_result *res = parsed_result;
12800         int ret = -ENOTSUP;
12801         int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
12802
12803         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12804                 return;
12805
12806 #ifdef RTE_LIBRTE_IXGBE_PMD
12807         ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id,
12808                         is_on);
12809 #endif
12810         switch (ret) {
12811         case 0:
12812                 break;
12813         case -EINVAL:
12814                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
12815                 break;
12816         case -ENODEV:
12817                 printf("invalid port_id %d\n", res->port_id);
12818                 break;
12819         case -ENOTSUP:
12820                 printf("not supported on port %d\n", res->port_id);
12821                 break;
12822         default:
12823                 printf("programming error: (%s)\n", strerror(-ret));
12824         }
12825 }
12826
12827 cmdline_parse_inst_t cmd_set_vf_split_drop_en = {
12828         .f = cmd_set_vf_split_drop_en_parsed,
12829         .data = NULL,
12830         .help_str = "set vf split drop <port_id> <vf_id> on|off",
12831         .tokens = {
12832                 (void *)&cmd_vf_split_drop_en_set,
12833                 (void *)&cmd_vf_split_drop_en_vf,
12834                 (void *)&cmd_vf_split_drop_en_split,
12835                 (void *)&cmd_vf_split_drop_en_drop,
12836                 (void *)&cmd_vf_split_drop_en_port_id,
12837                 (void *)&cmd_vf_split_drop_en_vf_id,
12838                 (void *)&cmd_vf_split_drop_en_on_off,
12839                 NULL,
12840         },
12841 };
12842
12843 /* vf mac address configuration */
12844
12845 /* Common result structure for vf mac address */
12846 struct cmd_set_vf_mac_addr_result {
12847         cmdline_fixed_string_t set;
12848         cmdline_fixed_string_t vf;
12849         cmdline_fixed_string_t mac;
12850         cmdline_fixed_string_t addr;
12851         portid_t port_id;
12852         uint16_t vf_id;
12853         struct ether_addr mac_addr;
12854
12855 };
12856
12857 /* Common CLI fields for vf split drop enable disable */
12858 cmdline_parse_token_string_t cmd_set_vf_mac_addr_set =
12859         TOKEN_STRING_INITIALIZER
12860                 (struct cmd_set_vf_mac_addr_result,
12861                  set, "set");
12862 cmdline_parse_token_string_t cmd_set_vf_mac_addr_vf =
12863         TOKEN_STRING_INITIALIZER
12864                 (struct cmd_set_vf_mac_addr_result,
12865                  vf, "vf");
12866 cmdline_parse_token_string_t cmd_set_vf_mac_addr_mac =
12867         TOKEN_STRING_INITIALIZER
12868                 (struct cmd_set_vf_mac_addr_result,
12869                  mac, "mac");
12870 cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr =
12871         TOKEN_STRING_INITIALIZER
12872                 (struct cmd_set_vf_mac_addr_result,
12873                  addr, "addr");
12874 cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id =
12875         TOKEN_NUM_INITIALIZER
12876                 (struct cmd_set_vf_mac_addr_result,
12877                  port_id, UINT16);
12878 cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id =
12879         TOKEN_NUM_INITIALIZER
12880                 (struct cmd_set_vf_mac_addr_result,
12881                  vf_id, UINT16);
12882 cmdline_parse_token_etheraddr_t cmd_set_vf_mac_addr_mac_addr =
12883         TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_vf_mac_addr_result,
12884                  mac_addr);
12885
12886 static void
12887 cmd_set_vf_mac_addr_parsed(
12888         void *parsed_result,
12889         __attribute__((unused)) struct cmdline *cl,
12890         __attribute__((unused)) void *data)
12891 {
12892         struct cmd_set_vf_mac_addr_result *res = parsed_result;
12893         int ret = -ENOTSUP;
12894
12895         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
12896                 return;
12897
12898 #ifdef RTE_LIBRTE_IXGBE_PMD
12899         if (ret == -ENOTSUP)
12900                 ret = rte_pmd_ixgbe_set_vf_mac_addr(res->port_id, res->vf_id,
12901                                 &res->mac_addr);
12902 #endif
12903 #ifdef RTE_LIBRTE_I40E_PMD
12904         if (ret == -ENOTSUP)
12905                 ret = rte_pmd_i40e_set_vf_mac_addr(res->port_id, res->vf_id,
12906                                 &res->mac_addr);
12907 #endif
12908 #ifdef RTE_LIBRTE_BNXT_PMD
12909         if (ret == -ENOTSUP)
12910                 ret = rte_pmd_bnxt_set_vf_mac_addr(res->port_id, res->vf_id,
12911                                 &res->mac_addr);
12912 #endif
12913
12914         switch (ret) {
12915         case 0:
12916                 break;
12917         case -EINVAL:
12918                 printf("invalid vf_id %d or mac_addr\n", res->vf_id);
12919                 break;
12920         case -ENODEV:
12921                 printf("invalid port_id %d\n", res->port_id);
12922                 break;
12923         case -ENOTSUP:
12924                 printf("function not implemented\n");
12925                 break;
12926         default:
12927                 printf("programming error: (%s)\n", strerror(-ret));
12928         }
12929 }
12930
12931 cmdline_parse_inst_t cmd_set_vf_mac_addr = {
12932         .f = cmd_set_vf_mac_addr_parsed,
12933         .data = NULL,
12934         .help_str = "set vf mac addr <port_id> <vf_id> <mac_addr>",
12935         .tokens = {
12936                 (void *)&cmd_set_vf_mac_addr_set,
12937                 (void *)&cmd_set_vf_mac_addr_vf,
12938                 (void *)&cmd_set_vf_mac_addr_mac,
12939                 (void *)&cmd_set_vf_mac_addr_addr,
12940                 (void *)&cmd_set_vf_mac_addr_port_id,
12941                 (void *)&cmd_set_vf_mac_addr_vf_id,
12942                 (void *)&cmd_set_vf_mac_addr_mac_addr,
12943                 NULL,
12944         },
12945 };
12946
12947 /* MACsec configuration */
12948
12949 /* Common result structure for MACsec offload enable */
12950 struct cmd_macsec_offload_on_result {
12951         cmdline_fixed_string_t set;
12952         cmdline_fixed_string_t macsec;
12953         cmdline_fixed_string_t offload;
12954         portid_t port_id;
12955         cmdline_fixed_string_t on;
12956         cmdline_fixed_string_t encrypt;
12957         cmdline_fixed_string_t en_on_off;
12958         cmdline_fixed_string_t replay_protect;
12959         cmdline_fixed_string_t rp_on_off;
12960 };
12961
12962 /* Common CLI fields for MACsec offload disable */
12963 cmdline_parse_token_string_t cmd_macsec_offload_on_set =
12964         TOKEN_STRING_INITIALIZER
12965                 (struct cmd_macsec_offload_on_result,
12966                  set, "set");
12967 cmdline_parse_token_string_t cmd_macsec_offload_on_macsec =
12968         TOKEN_STRING_INITIALIZER
12969                 (struct cmd_macsec_offload_on_result,
12970                  macsec, "macsec");
12971 cmdline_parse_token_string_t cmd_macsec_offload_on_offload =
12972         TOKEN_STRING_INITIALIZER
12973                 (struct cmd_macsec_offload_on_result,
12974                  offload, "offload");
12975 cmdline_parse_token_num_t cmd_macsec_offload_on_port_id =
12976         TOKEN_NUM_INITIALIZER
12977                 (struct cmd_macsec_offload_on_result,
12978                  port_id, UINT16);
12979 cmdline_parse_token_string_t cmd_macsec_offload_on_on =
12980         TOKEN_STRING_INITIALIZER
12981                 (struct cmd_macsec_offload_on_result,
12982                  on, "on");
12983 cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt =
12984         TOKEN_STRING_INITIALIZER
12985                 (struct cmd_macsec_offload_on_result,
12986                  encrypt, "encrypt");
12987 cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off =
12988         TOKEN_STRING_INITIALIZER
12989                 (struct cmd_macsec_offload_on_result,
12990                  en_on_off, "on#off");
12991 cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect =
12992         TOKEN_STRING_INITIALIZER
12993                 (struct cmd_macsec_offload_on_result,
12994                  replay_protect, "replay-protect");
12995 cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
12996         TOKEN_STRING_INITIALIZER
12997                 (struct cmd_macsec_offload_on_result,
12998                  rp_on_off, "on#off");
12999
13000 static void
13001 cmd_set_macsec_offload_on_parsed(
13002         void *parsed_result,
13003         __attribute__((unused)) struct cmdline *cl,
13004         __attribute__((unused)) void *data)
13005 {
13006         struct cmd_macsec_offload_on_result *res = parsed_result;
13007         int ret = -ENOTSUP;
13008         portid_t port_id = res->port_id;
13009         int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
13010         int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
13011
13012         if (port_id_is_invalid(port_id, ENABLED_WARN))
13013                 return;
13014
13015         ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_MACSEC;
13016 #ifdef RTE_LIBRTE_IXGBE_PMD
13017         ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
13018 #endif
13019         RTE_SET_USED(en);
13020         RTE_SET_USED(rp);
13021
13022         switch (ret) {
13023         case 0:
13024                 break;
13025         case -ENODEV:
13026                 printf("invalid port_id %d\n", port_id);
13027                 break;
13028         case -ENOTSUP:
13029                 printf("not supported on port %d\n", port_id);
13030                 break;
13031         default:
13032                 printf("programming error: (%s)\n", strerror(-ret));
13033         }
13034 }
13035
13036 cmdline_parse_inst_t cmd_set_macsec_offload_on = {
13037         .f = cmd_set_macsec_offload_on_parsed,
13038         .data = NULL,
13039         .help_str = "set macsec offload <port_id> on "
13040                 "encrypt on|off replay-protect on|off",
13041         .tokens = {
13042                 (void *)&cmd_macsec_offload_on_set,
13043                 (void *)&cmd_macsec_offload_on_macsec,
13044                 (void *)&cmd_macsec_offload_on_offload,
13045                 (void *)&cmd_macsec_offload_on_port_id,
13046                 (void *)&cmd_macsec_offload_on_on,
13047                 (void *)&cmd_macsec_offload_on_encrypt,
13048                 (void *)&cmd_macsec_offload_on_en_on_off,
13049                 (void *)&cmd_macsec_offload_on_replay_protect,
13050                 (void *)&cmd_macsec_offload_on_rp_on_off,
13051                 NULL,
13052         },
13053 };
13054
13055 /* Common result structure for MACsec offload disable */
13056 struct cmd_macsec_offload_off_result {
13057         cmdline_fixed_string_t set;
13058         cmdline_fixed_string_t macsec;
13059         cmdline_fixed_string_t offload;
13060         portid_t port_id;
13061         cmdline_fixed_string_t off;
13062 };
13063
13064 /* Common CLI fields for MACsec offload disable */
13065 cmdline_parse_token_string_t cmd_macsec_offload_off_set =
13066         TOKEN_STRING_INITIALIZER
13067                 (struct cmd_macsec_offload_off_result,
13068                  set, "set");
13069 cmdline_parse_token_string_t cmd_macsec_offload_off_macsec =
13070         TOKEN_STRING_INITIALIZER
13071                 (struct cmd_macsec_offload_off_result,
13072                  macsec, "macsec");
13073 cmdline_parse_token_string_t cmd_macsec_offload_off_offload =
13074         TOKEN_STRING_INITIALIZER
13075                 (struct cmd_macsec_offload_off_result,
13076                  offload, "offload");
13077 cmdline_parse_token_num_t cmd_macsec_offload_off_port_id =
13078         TOKEN_NUM_INITIALIZER
13079                 (struct cmd_macsec_offload_off_result,
13080                  port_id, UINT16);
13081 cmdline_parse_token_string_t cmd_macsec_offload_off_off =
13082         TOKEN_STRING_INITIALIZER
13083                 (struct cmd_macsec_offload_off_result,
13084                  off, "off");
13085
13086 static void
13087 cmd_set_macsec_offload_off_parsed(
13088         void *parsed_result,
13089         __attribute__((unused)) struct cmdline *cl,
13090         __attribute__((unused)) void *data)
13091 {
13092         struct cmd_macsec_offload_off_result *res = parsed_result;
13093         int ret = -ENOTSUP;
13094         portid_t port_id = res->port_id;
13095
13096         if (port_id_is_invalid(port_id, ENABLED_WARN))
13097                 return;
13098
13099         ports[port_id].tx_ol_flags &= ~TESTPMD_TX_OFFLOAD_MACSEC;
13100 #ifdef RTE_LIBRTE_IXGBE_PMD
13101         ret = rte_pmd_ixgbe_macsec_disable(port_id);
13102 #endif
13103
13104         switch (ret) {
13105         case 0:
13106                 break;
13107         case -ENODEV:
13108                 printf("invalid port_id %d\n", port_id);
13109                 break;
13110         case -ENOTSUP:
13111                 printf("not supported on port %d\n", port_id);
13112                 break;
13113         default:
13114                 printf("programming error: (%s)\n", strerror(-ret));
13115         }
13116 }
13117
13118 cmdline_parse_inst_t cmd_set_macsec_offload_off = {
13119         .f = cmd_set_macsec_offload_off_parsed,
13120         .data = NULL,
13121         .help_str = "set macsec offload <port_id> off",
13122         .tokens = {
13123                 (void *)&cmd_macsec_offload_off_set,
13124                 (void *)&cmd_macsec_offload_off_macsec,
13125                 (void *)&cmd_macsec_offload_off_offload,
13126                 (void *)&cmd_macsec_offload_off_port_id,
13127                 (void *)&cmd_macsec_offload_off_off,
13128                 NULL,
13129         },
13130 };
13131
13132 /* Common result structure for MACsec secure connection configure */
13133 struct cmd_macsec_sc_result {
13134         cmdline_fixed_string_t set;
13135         cmdline_fixed_string_t macsec;
13136         cmdline_fixed_string_t sc;
13137         cmdline_fixed_string_t tx_rx;
13138         portid_t port_id;
13139         struct ether_addr mac;
13140         uint16_t pi;
13141 };
13142
13143 /* Common CLI fields for MACsec secure connection configure */
13144 cmdline_parse_token_string_t cmd_macsec_sc_set =
13145         TOKEN_STRING_INITIALIZER
13146                 (struct cmd_macsec_sc_result,
13147                  set, "set");
13148 cmdline_parse_token_string_t cmd_macsec_sc_macsec =
13149         TOKEN_STRING_INITIALIZER
13150                 (struct cmd_macsec_sc_result,
13151                  macsec, "macsec");
13152 cmdline_parse_token_string_t cmd_macsec_sc_sc =
13153         TOKEN_STRING_INITIALIZER
13154                 (struct cmd_macsec_sc_result,
13155                  sc, "sc");
13156 cmdline_parse_token_string_t cmd_macsec_sc_tx_rx =
13157         TOKEN_STRING_INITIALIZER
13158                 (struct cmd_macsec_sc_result,
13159                  tx_rx, "tx#rx");
13160 cmdline_parse_token_num_t cmd_macsec_sc_port_id =
13161         TOKEN_NUM_INITIALIZER
13162                 (struct cmd_macsec_sc_result,
13163                  port_id, UINT16);
13164 cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac =
13165         TOKEN_ETHERADDR_INITIALIZER
13166                 (struct cmd_macsec_sc_result,
13167                  mac);
13168 cmdline_parse_token_num_t cmd_macsec_sc_pi =
13169         TOKEN_NUM_INITIALIZER
13170                 (struct cmd_macsec_sc_result,
13171                  pi, UINT16);
13172
13173 static void
13174 cmd_set_macsec_sc_parsed(
13175         void *parsed_result,
13176         __attribute__((unused)) struct cmdline *cl,
13177         __attribute__((unused)) void *data)
13178 {
13179         struct cmd_macsec_sc_result *res = parsed_result;
13180         int ret = -ENOTSUP;
13181         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13182
13183 #ifdef RTE_LIBRTE_IXGBE_PMD
13184         ret = is_tx ?
13185                 rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
13186                                 res->mac.addr_bytes) :
13187                 rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
13188                                 res->mac.addr_bytes, res->pi);
13189 #endif
13190         RTE_SET_USED(is_tx);
13191
13192         switch (ret) {
13193         case 0:
13194                 break;
13195         case -ENODEV:
13196                 printf("invalid port_id %d\n", res->port_id);
13197                 break;
13198         case -ENOTSUP:
13199                 printf("not supported on port %d\n", res->port_id);
13200                 break;
13201         default:
13202                 printf("programming error: (%s)\n", strerror(-ret));
13203         }
13204 }
13205
13206 cmdline_parse_inst_t cmd_set_macsec_sc = {
13207         .f = cmd_set_macsec_sc_parsed,
13208         .data = NULL,
13209         .help_str = "set macsec sc tx|rx <port_id> <mac> <pi>",
13210         .tokens = {
13211                 (void *)&cmd_macsec_sc_set,
13212                 (void *)&cmd_macsec_sc_macsec,
13213                 (void *)&cmd_macsec_sc_sc,
13214                 (void *)&cmd_macsec_sc_tx_rx,
13215                 (void *)&cmd_macsec_sc_port_id,
13216                 (void *)&cmd_macsec_sc_mac,
13217                 (void *)&cmd_macsec_sc_pi,
13218                 NULL,
13219         },
13220 };
13221
13222 /* Common result structure for MACsec secure connection configure */
13223 struct cmd_macsec_sa_result {
13224         cmdline_fixed_string_t set;
13225         cmdline_fixed_string_t macsec;
13226         cmdline_fixed_string_t sa;
13227         cmdline_fixed_string_t tx_rx;
13228         portid_t port_id;
13229         uint8_t idx;
13230         uint8_t an;
13231         uint32_t pn;
13232         cmdline_fixed_string_t key;
13233 };
13234
13235 /* Common CLI fields for MACsec secure connection configure */
13236 cmdline_parse_token_string_t cmd_macsec_sa_set =
13237         TOKEN_STRING_INITIALIZER
13238                 (struct cmd_macsec_sa_result,
13239                  set, "set");
13240 cmdline_parse_token_string_t cmd_macsec_sa_macsec =
13241         TOKEN_STRING_INITIALIZER
13242                 (struct cmd_macsec_sa_result,
13243                  macsec, "macsec");
13244 cmdline_parse_token_string_t cmd_macsec_sa_sa =
13245         TOKEN_STRING_INITIALIZER
13246                 (struct cmd_macsec_sa_result,
13247                  sa, "sa");
13248 cmdline_parse_token_string_t cmd_macsec_sa_tx_rx =
13249         TOKEN_STRING_INITIALIZER
13250                 (struct cmd_macsec_sa_result,
13251                  tx_rx, "tx#rx");
13252 cmdline_parse_token_num_t cmd_macsec_sa_port_id =
13253         TOKEN_NUM_INITIALIZER
13254                 (struct cmd_macsec_sa_result,
13255                  port_id, UINT16);
13256 cmdline_parse_token_num_t cmd_macsec_sa_idx =
13257         TOKEN_NUM_INITIALIZER
13258                 (struct cmd_macsec_sa_result,
13259                  idx, UINT8);
13260 cmdline_parse_token_num_t cmd_macsec_sa_an =
13261         TOKEN_NUM_INITIALIZER
13262                 (struct cmd_macsec_sa_result,
13263                  an, UINT8);
13264 cmdline_parse_token_num_t cmd_macsec_sa_pn =
13265         TOKEN_NUM_INITIALIZER
13266                 (struct cmd_macsec_sa_result,
13267                  pn, UINT32);
13268 cmdline_parse_token_string_t cmd_macsec_sa_key =
13269         TOKEN_STRING_INITIALIZER
13270                 (struct cmd_macsec_sa_result,
13271                  key, NULL);
13272
13273 static void
13274 cmd_set_macsec_sa_parsed(
13275         void *parsed_result,
13276         __attribute__((unused)) struct cmdline *cl,
13277         __attribute__((unused)) void *data)
13278 {
13279         struct cmd_macsec_sa_result *res = parsed_result;
13280         int ret = -ENOTSUP;
13281         int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
13282         uint8_t key[16] = { 0 };
13283         uint8_t xdgt0;
13284         uint8_t xdgt1;
13285         int key_len;
13286         int i;
13287
13288         key_len = strlen(res->key) / 2;
13289         if (key_len > 16)
13290                 key_len = 16;
13291
13292         for (i = 0; i < key_len; i++) {
13293                 xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2));
13294                 if (xdgt0 == 0xFF)
13295                         return;
13296                 xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1);
13297                 if (xdgt1 == 0xFF)
13298                         return;
13299                 key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1);
13300         }
13301
13302 #ifdef RTE_LIBRTE_IXGBE_PMD
13303         ret = is_tx ?
13304                 rte_pmd_ixgbe_macsec_select_txsa(res->port_id,
13305                         res->idx, res->an, res->pn, key) :
13306                 rte_pmd_ixgbe_macsec_select_rxsa(res->port_id,
13307                         res->idx, res->an, res->pn, key);
13308 #endif
13309         RTE_SET_USED(is_tx);
13310         RTE_SET_USED(key);
13311
13312         switch (ret) {
13313         case 0:
13314                 break;
13315         case -EINVAL:
13316                 printf("invalid idx %d or an %d\n", res->idx, res->an);
13317                 break;
13318         case -ENODEV:
13319                 printf("invalid port_id %d\n", res->port_id);
13320                 break;
13321         case -ENOTSUP:
13322                 printf("not supported on port %d\n", res->port_id);
13323                 break;
13324         default:
13325                 printf("programming error: (%s)\n", strerror(-ret));
13326         }
13327 }
13328
13329 cmdline_parse_inst_t cmd_set_macsec_sa = {
13330         .f = cmd_set_macsec_sa_parsed,
13331         .data = NULL,
13332         .help_str = "set macsec sa tx|rx <port_id> <idx> <an> <pn> <key>",
13333         .tokens = {
13334                 (void *)&cmd_macsec_sa_set,
13335                 (void *)&cmd_macsec_sa_macsec,
13336                 (void *)&cmd_macsec_sa_sa,
13337                 (void *)&cmd_macsec_sa_tx_rx,
13338                 (void *)&cmd_macsec_sa_port_id,
13339                 (void *)&cmd_macsec_sa_idx,
13340                 (void *)&cmd_macsec_sa_an,
13341                 (void *)&cmd_macsec_sa_pn,
13342                 (void *)&cmd_macsec_sa_key,
13343                 NULL,
13344         },
13345 };
13346
13347 /* VF unicast promiscuous mode configuration */
13348
13349 /* Common result structure for VF unicast promiscuous mode */
13350 struct cmd_vf_promisc_result {
13351         cmdline_fixed_string_t set;
13352         cmdline_fixed_string_t vf;
13353         cmdline_fixed_string_t promisc;
13354         portid_t port_id;
13355         uint32_t vf_id;
13356         cmdline_fixed_string_t on_off;
13357 };
13358
13359 /* Common CLI fields for VF unicast promiscuous mode enable disable */
13360 cmdline_parse_token_string_t cmd_vf_promisc_set =
13361         TOKEN_STRING_INITIALIZER
13362                 (struct cmd_vf_promisc_result,
13363                  set, "set");
13364 cmdline_parse_token_string_t cmd_vf_promisc_vf =
13365         TOKEN_STRING_INITIALIZER
13366                 (struct cmd_vf_promisc_result,
13367                  vf, "vf");
13368 cmdline_parse_token_string_t cmd_vf_promisc_promisc =
13369         TOKEN_STRING_INITIALIZER
13370                 (struct cmd_vf_promisc_result,
13371                  promisc, "promisc");
13372 cmdline_parse_token_num_t cmd_vf_promisc_port_id =
13373         TOKEN_NUM_INITIALIZER
13374                 (struct cmd_vf_promisc_result,
13375                  port_id, UINT16);
13376 cmdline_parse_token_num_t cmd_vf_promisc_vf_id =
13377         TOKEN_NUM_INITIALIZER
13378                 (struct cmd_vf_promisc_result,
13379                  vf_id, UINT32);
13380 cmdline_parse_token_string_t cmd_vf_promisc_on_off =
13381         TOKEN_STRING_INITIALIZER
13382                 (struct cmd_vf_promisc_result,
13383                  on_off, "on#off");
13384
13385 static void
13386 cmd_set_vf_promisc_parsed(
13387         void *parsed_result,
13388         __attribute__((unused)) struct cmdline *cl,
13389         __attribute__((unused)) void *data)
13390 {
13391         struct cmd_vf_promisc_result *res = parsed_result;
13392         int ret = -ENOTSUP;
13393
13394         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13395
13396         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13397                 return;
13398
13399 #ifdef RTE_LIBRTE_I40E_PMD
13400         ret = rte_pmd_i40e_set_vf_unicast_promisc(res->port_id,
13401                                                   res->vf_id, is_on);
13402 #endif
13403
13404         switch (ret) {
13405         case 0:
13406                 break;
13407         case -EINVAL:
13408                 printf("invalid vf_id %d\n", res->vf_id);
13409                 break;
13410         case -ENODEV:
13411                 printf("invalid port_id %d\n", res->port_id);
13412                 break;
13413         case -ENOTSUP:
13414                 printf("function not implemented\n");
13415                 break;
13416         default:
13417                 printf("programming error: (%s)\n", strerror(-ret));
13418         }
13419 }
13420
13421 cmdline_parse_inst_t cmd_set_vf_promisc = {
13422         .f = cmd_set_vf_promisc_parsed,
13423         .data = NULL,
13424         .help_str = "set vf promisc <port_id> <vf_id> on|off: "
13425                 "Set unicast promiscuous mode for a VF from the PF",
13426         .tokens = {
13427                 (void *)&cmd_vf_promisc_set,
13428                 (void *)&cmd_vf_promisc_vf,
13429                 (void *)&cmd_vf_promisc_promisc,
13430                 (void *)&cmd_vf_promisc_port_id,
13431                 (void *)&cmd_vf_promisc_vf_id,
13432                 (void *)&cmd_vf_promisc_on_off,
13433                 NULL,
13434         },
13435 };
13436
13437 /* VF multicast promiscuous mode configuration */
13438
13439 /* Common result structure for VF multicast promiscuous mode */
13440 struct cmd_vf_allmulti_result {
13441         cmdline_fixed_string_t set;
13442         cmdline_fixed_string_t vf;
13443         cmdline_fixed_string_t allmulti;
13444         portid_t port_id;
13445         uint32_t vf_id;
13446         cmdline_fixed_string_t on_off;
13447 };
13448
13449 /* Common CLI fields for VF multicast promiscuous mode enable disable */
13450 cmdline_parse_token_string_t cmd_vf_allmulti_set =
13451         TOKEN_STRING_INITIALIZER
13452                 (struct cmd_vf_allmulti_result,
13453                  set, "set");
13454 cmdline_parse_token_string_t cmd_vf_allmulti_vf =
13455         TOKEN_STRING_INITIALIZER
13456                 (struct cmd_vf_allmulti_result,
13457                  vf, "vf");
13458 cmdline_parse_token_string_t cmd_vf_allmulti_allmulti =
13459         TOKEN_STRING_INITIALIZER
13460                 (struct cmd_vf_allmulti_result,
13461                  allmulti, "allmulti");
13462 cmdline_parse_token_num_t cmd_vf_allmulti_port_id =
13463         TOKEN_NUM_INITIALIZER
13464                 (struct cmd_vf_allmulti_result,
13465                  port_id, UINT16);
13466 cmdline_parse_token_num_t cmd_vf_allmulti_vf_id =
13467         TOKEN_NUM_INITIALIZER
13468                 (struct cmd_vf_allmulti_result,
13469                  vf_id, UINT32);
13470 cmdline_parse_token_string_t cmd_vf_allmulti_on_off =
13471         TOKEN_STRING_INITIALIZER
13472                 (struct cmd_vf_allmulti_result,
13473                  on_off, "on#off");
13474
13475 static void
13476 cmd_set_vf_allmulti_parsed(
13477         void *parsed_result,
13478         __attribute__((unused)) struct cmdline *cl,
13479         __attribute__((unused)) void *data)
13480 {
13481         struct cmd_vf_allmulti_result *res = parsed_result;
13482         int ret = -ENOTSUP;
13483
13484         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13485
13486         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13487                 return;
13488
13489 #ifdef RTE_LIBRTE_I40E_PMD
13490         ret = rte_pmd_i40e_set_vf_multicast_promisc(res->port_id,
13491                                                     res->vf_id, is_on);
13492 #endif
13493
13494         switch (ret) {
13495         case 0:
13496                 break;
13497         case -EINVAL:
13498                 printf("invalid vf_id %d\n", res->vf_id);
13499                 break;
13500         case -ENODEV:
13501                 printf("invalid port_id %d\n", res->port_id);
13502                 break;
13503         case -ENOTSUP:
13504                 printf("function not implemented\n");
13505                 break;
13506         default:
13507                 printf("programming error: (%s)\n", strerror(-ret));
13508         }
13509 }
13510
13511 cmdline_parse_inst_t cmd_set_vf_allmulti = {
13512         .f = cmd_set_vf_allmulti_parsed,
13513         .data = NULL,
13514         .help_str = "set vf allmulti <port_id> <vf_id> on|off: "
13515                 "Set multicast promiscuous mode for a VF from the PF",
13516         .tokens = {
13517                 (void *)&cmd_vf_allmulti_set,
13518                 (void *)&cmd_vf_allmulti_vf,
13519                 (void *)&cmd_vf_allmulti_allmulti,
13520                 (void *)&cmd_vf_allmulti_port_id,
13521                 (void *)&cmd_vf_allmulti_vf_id,
13522                 (void *)&cmd_vf_allmulti_on_off,
13523                 NULL,
13524         },
13525 };
13526
13527 /* vf broadcast mode configuration */
13528
13529 /* Common result structure for vf broadcast */
13530 struct cmd_set_vf_broadcast_result {
13531         cmdline_fixed_string_t set;
13532         cmdline_fixed_string_t vf;
13533         cmdline_fixed_string_t broadcast;
13534         portid_t port_id;
13535         uint16_t vf_id;
13536         cmdline_fixed_string_t on_off;
13537 };
13538
13539 /* Common CLI fields for vf broadcast enable disable */
13540 cmdline_parse_token_string_t cmd_set_vf_broadcast_set =
13541         TOKEN_STRING_INITIALIZER
13542                 (struct cmd_set_vf_broadcast_result,
13543                  set, "set");
13544 cmdline_parse_token_string_t cmd_set_vf_broadcast_vf =
13545         TOKEN_STRING_INITIALIZER
13546                 (struct cmd_set_vf_broadcast_result,
13547                  vf, "vf");
13548 cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast =
13549         TOKEN_STRING_INITIALIZER
13550                 (struct cmd_set_vf_broadcast_result,
13551                  broadcast, "broadcast");
13552 cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id =
13553         TOKEN_NUM_INITIALIZER
13554                 (struct cmd_set_vf_broadcast_result,
13555                  port_id, UINT16);
13556 cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id =
13557         TOKEN_NUM_INITIALIZER
13558                 (struct cmd_set_vf_broadcast_result,
13559                  vf_id, UINT16);
13560 cmdline_parse_token_string_t cmd_set_vf_broadcast_on_off =
13561         TOKEN_STRING_INITIALIZER
13562                 (struct cmd_set_vf_broadcast_result,
13563                  on_off, "on#off");
13564
13565 static void
13566 cmd_set_vf_broadcast_parsed(
13567         void *parsed_result,
13568         __attribute__((unused)) struct cmdline *cl,
13569         __attribute__((unused)) void *data)
13570 {
13571         struct cmd_set_vf_broadcast_result *res = parsed_result;
13572         int ret = -ENOTSUP;
13573
13574         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13575
13576         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13577                 return;
13578
13579 #ifdef RTE_LIBRTE_I40E_PMD
13580         ret = rte_pmd_i40e_set_vf_broadcast(res->port_id,
13581                                             res->vf_id, is_on);
13582 #endif
13583
13584         switch (ret) {
13585         case 0:
13586                 break;
13587         case -EINVAL:
13588                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13589                 break;
13590         case -ENODEV:
13591                 printf("invalid port_id %d\n", res->port_id);
13592                 break;
13593         case -ENOTSUP:
13594                 printf("function not implemented\n");
13595                 break;
13596         default:
13597                 printf("programming error: (%s)\n", strerror(-ret));
13598         }
13599 }
13600
13601 cmdline_parse_inst_t cmd_set_vf_broadcast = {
13602         .f = cmd_set_vf_broadcast_parsed,
13603         .data = NULL,
13604         .help_str = "set vf broadcast <port_id> <vf_id> on|off",
13605         .tokens = {
13606                 (void *)&cmd_set_vf_broadcast_set,
13607                 (void *)&cmd_set_vf_broadcast_vf,
13608                 (void *)&cmd_set_vf_broadcast_broadcast,
13609                 (void *)&cmd_set_vf_broadcast_port_id,
13610                 (void *)&cmd_set_vf_broadcast_vf_id,
13611                 (void *)&cmd_set_vf_broadcast_on_off,
13612                 NULL,
13613         },
13614 };
13615
13616 /* vf vlan tag configuration */
13617
13618 /* Common result structure for vf vlan tag */
13619 struct cmd_set_vf_vlan_tag_result {
13620         cmdline_fixed_string_t set;
13621         cmdline_fixed_string_t vf;
13622         cmdline_fixed_string_t vlan;
13623         cmdline_fixed_string_t tag;
13624         portid_t port_id;
13625         uint16_t vf_id;
13626         cmdline_fixed_string_t on_off;
13627 };
13628
13629 /* Common CLI fields for vf vlan tag enable disable */
13630 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_set =
13631         TOKEN_STRING_INITIALIZER
13632                 (struct cmd_set_vf_vlan_tag_result,
13633                  set, "set");
13634 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vf =
13635         TOKEN_STRING_INITIALIZER
13636                 (struct cmd_set_vf_vlan_tag_result,
13637                  vf, "vf");
13638 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_vlan =
13639         TOKEN_STRING_INITIALIZER
13640                 (struct cmd_set_vf_vlan_tag_result,
13641                  vlan, "vlan");
13642 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag =
13643         TOKEN_STRING_INITIALIZER
13644                 (struct cmd_set_vf_vlan_tag_result,
13645                  tag, "tag");
13646 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id =
13647         TOKEN_NUM_INITIALIZER
13648                 (struct cmd_set_vf_vlan_tag_result,
13649                  port_id, UINT16);
13650 cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id =
13651         TOKEN_NUM_INITIALIZER
13652                 (struct cmd_set_vf_vlan_tag_result,
13653                  vf_id, UINT16);
13654 cmdline_parse_token_string_t cmd_set_vf_vlan_tag_on_off =
13655         TOKEN_STRING_INITIALIZER
13656                 (struct cmd_set_vf_vlan_tag_result,
13657                  on_off, "on#off");
13658
13659 static void
13660 cmd_set_vf_vlan_tag_parsed(
13661         void *parsed_result,
13662         __attribute__((unused)) struct cmdline *cl,
13663         __attribute__((unused)) void *data)
13664 {
13665         struct cmd_set_vf_vlan_tag_result *res = parsed_result;
13666         int ret = -ENOTSUP;
13667
13668         __rte_unused int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0;
13669
13670         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13671                 return;
13672
13673 #ifdef RTE_LIBRTE_I40E_PMD
13674         ret = rte_pmd_i40e_set_vf_vlan_tag(res->port_id,
13675                                            res->vf_id, is_on);
13676 #endif
13677
13678         switch (ret) {
13679         case 0:
13680                 break;
13681         case -EINVAL:
13682                 printf("invalid vf_id %d or is_on %d\n", res->vf_id, is_on);
13683                 break;
13684         case -ENODEV:
13685                 printf("invalid port_id %d\n", res->port_id);
13686                 break;
13687         case -ENOTSUP:
13688                 printf("function not implemented\n");
13689                 break;
13690         default:
13691                 printf("programming error: (%s)\n", strerror(-ret));
13692         }
13693 }
13694
13695 cmdline_parse_inst_t cmd_set_vf_vlan_tag = {
13696         .f = cmd_set_vf_vlan_tag_parsed,
13697         .data = NULL,
13698         .help_str = "set vf vlan tag <port_id> <vf_id> on|off",
13699         .tokens = {
13700                 (void *)&cmd_set_vf_vlan_tag_set,
13701                 (void *)&cmd_set_vf_vlan_tag_vf,
13702                 (void *)&cmd_set_vf_vlan_tag_vlan,
13703                 (void *)&cmd_set_vf_vlan_tag_tag,
13704                 (void *)&cmd_set_vf_vlan_tag_port_id,
13705                 (void *)&cmd_set_vf_vlan_tag_vf_id,
13706                 (void *)&cmd_set_vf_vlan_tag_on_off,
13707                 NULL,
13708         },
13709 };
13710
13711 /* Common definition of VF and TC TX bandwidth configuration */
13712 struct cmd_vf_tc_bw_result {
13713         cmdline_fixed_string_t set;
13714         cmdline_fixed_string_t vf;
13715         cmdline_fixed_string_t tc;
13716         cmdline_fixed_string_t tx;
13717         cmdline_fixed_string_t min_bw;
13718         cmdline_fixed_string_t max_bw;
13719         cmdline_fixed_string_t strict_link_prio;
13720         portid_t port_id;
13721         uint16_t vf_id;
13722         uint8_t tc_no;
13723         uint32_t bw;
13724         cmdline_fixed_string_t bw_list;
13725         uint8_t tc_map;
13726 };
13727
13728 cmdline_parse_token_string_t cmd_vf_tc_bw_set =
13729         TOKEN_STRING_INITIALIZER
13730                 (struct cmd_vf_tc_bw_result,
13731                  set, "set");
13732 cmdline_parse_token_string_t cmd_vf_tc_bw_vf =
13733         TOKEN_STRING_INITIALIZER
13734                 (struct cmd_vf_tc_bw_result,
13735                  vf, "vf");
13736 cmdline_parse_token_string_t cmd_vf_tc_bw_tc =
13737         TOKEN_STRING_INITIALIZER
13738                 (struct cmd_vf_tc_bw_result,
13739                  tc, "tc");
13740 cmdline_parse_token_string_t cmd_vf_tc_bw_tx =
13741         TOKEN_STRING_INITIALIZER
13742                 (struct cmd_vf_tc_bw_result,
13743                  tx, "tx");
13744 cmdline_parse_token_string_t cmd_vf_tc_bw_strict_link_prio =
13745         TOKEN_STRING_INITIALIZER
13746                 (struct cmd_vf_tc_bw_result,
13747                  strict_link_prio, "strict-link-priority");
13748 cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw =
13749         TOKEN_STRING_INITIALIZER
13750                 (struct cmd_vf_tc_bw_result,
13751                  min_bw, "min-bandwidth");
13752 cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw =
13753         TOKEN_STRING_INITIALIZER
13754                 (struct cmd_vf_tc_bw_result,
13755                  max_bw, "max-bandwidth");
13756 cmdline_parse_token_num_t cmd_vf_tc_bw_port_id =
13757         TOKEN_NUM_INITIALIZER
13758                 (struct cmd_vf_tc_bw_result,
13759                  port_id, UINT16);
13760 cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id =
13761         TOKEN_NUM_INITIALIZER
13762                 (struct cmd_vf_tc_bw_result,
13763                  vf_id, UINT16);
13764 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_no =
13765         TOKEN_NUM_INITIALIZER
13766                 (struct cmd_vf_tc_bw_result,
13767                  tc_no, UINT8);
13768 cmdline_parse_token_num_t cmd_vf_tc_bw_bw =
13769         TOKEN_NUM_INITIALIZER
13770                 (struct cmd_vf_tc_bw_result,
13771                  bw, UINT32);
13772 cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list =
13773         TOKEN_STRING_INITIALIZER
13774                 (struct cmd_vf_tc_bw_result,
13775                  bw_list, NULL);
13776 cmdline_parse_token_num_t cmd_vf_tc_bw_tc_map =
13777         TOKEN_NUM_INITIALIZER
13778                 (struct cmd_vf_tc_bw_result,
13779                  tc_map, UINT8);
13780
13781 /* VF max bandwidth setting */
13782 static void
13783 cmd_vf_max_bw_parsed(
13784         void *parsed_result,
13785         __attribute__((unused)) struct cmdline *cl,
13786         __attribute__((unused)) void *data)
13787 {
13788         struct cmd_vf_tc_bw_result *res = parsed_result;
13789         int ret = -ENOTSUP;
13790
13791         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13792                 return;
13793
13794 #ifdef RTE_LIBRTE_I40E_PMD
13795         ret = rte_pmd_i40e_set_vf_max_bw(res->port_id,
13796                                          res->vf_id, res->bw);
13797 #endif
13798
13799         switch (ret) {
13800         case 0:
13801                 break;
13802         case -EINVAL:
13803                 printf("invalid vf_id %d or bandwidth %d\n",
13804                        res->vf_id, res->bw);
13805                 break;
13806         case -ENODEV:
13807                 printf("invalid port_id %d\n", res->port_id);
13808                 break;
13809         case -ENOTSUP:
13810                 printf("function not implemented\n");
13811                 break;
13812         default:
13813                 printf("programming error: (%s)\n", strerror(-ret));
13814         }
13815 }
13816
13817 cmdline_parse_inst_t cmd_vf_max_bw = {
13818         .f = cmd_vf_max_bw_parsed,
13819         .data = NULL,
13820         .help_str = "set vf tx max-bandwidth <port_id> <vf_id> <bandwidth>",
13821         .tokens = {
13822                 (void *)&cmd_vf_tc_bw_set,
13823                 (void *)&cmd_vf_tc_bw_vf,
13824                 (void *)&cmd_vf_tc_bw_tx,
13825                 (void *)&cmd_vf_tc_bw_max_bw,
13826                 (void *)&cmd_vf_tc_bw_port_id,
13827                 (void *)&cmd_vf_tc_bw_vf_id,
13828                 (void *)&cmd_vf_tc_bw_bw,
13829                 NULL,
13830         },
13831 };
13832
13833 static int
13834 vf_tc_min_bw_parse_bw_list(uint8_t *bw_list,
13835                            uint8_t *tc_num,
13836                            char *str)
13837 {
13838         uint32_t size;
13839         const char *p, *p0 = str;
13840         char s[256];
13841         char *end;
13842         char *str_fld[16];
13843         uint16_t i;
13844         int ret;
13845
13846         p = strchr(p0, '(');
13847         if (p == NULL) {
13848                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13849                 return -1;
13850         }
13851         p++;
13852         p0 = strchr(p, ')');
13853         if (p0 == NULL) {
13854                 printf("The bandwidth-list should be '(bw1, bw2, ...)'\n");
13855                 return -1;
13856         }
13857         size = p0 - p;
13858         if (size >= sizeof(s)) {
13859                 printf("The string size exceeds the internal buffer size\n");
13860                 return -1;
13861         }
13862         snprintf(s, sizeof(s), "%.*s", size, p);
13863         ret = rte_strsplit(s, sizeof(s), str_fld, 16, ',');
13864         if (ret <= 0) {
13865                 printf("Failed to get the bandwidth list. ");
13866                 return -1;
13867         }
13868         *tc_num = ret;
13869         for (i = 0; i < ret; i++)
13870                 bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0);
13871
13872         return 0;
13873 }
13874
13875 /* TC min bandwidth setting */
13876 static void
13877 cmd_vf_tc_min_bw_parsed(
13878         void *parsed_result,
13879         __attribute__((unused)) struct cmdline *cl,
13880         __attribute__((unused)) void *data)
13881 {
13882         struct cmd_vf_tc_bw_result *res = parsed_result;
13883         uint8_t tc_num;
13884         uint8_t bw[16];
13885         int ret = -ENOTSUP;
13886
13887         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13888                 return;
13889
13890         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13891         if (ret)
13892                 return;
13893
13894 #ifdef RTE_LIBRTE_I40E_PMD
13895         ret = rte_pmd_i40e_set_vf_tc_bw_alloc(res->port_id, res->vf_id,
13896                                               tc_num, bw);
13897 #endif
13898
13899         switch (ret) {
13900         case 0:
13901                 break;
13902         case -EINVAL:
13903                 printf("invalid vf_id %d or bandwidth\n", res->vf_id);
13904                 break;
13905         case -ENODEV:
13906                 printf("invalid port_id %d\n", res->port_id);
13907                 break;
13908         case -ENOTSUP:
13909                 printf("function not implemented\n");
13910                 break;
13911         default:
13912                 printf("programming error: (%s)\n", strerror(-ret));
13913         }
13914 }
13915
13916 cmdline_parse_inst_t cmd_vf_tc_min_bw = {
13917         .f = cmd_vf_tc_min_bw_parsed,
13918         .data = NULL,
13919         .help_str = "set vf tc tx min-bandwidth <port_id> <vf_id>"
13920                     " <bw1, bw2, ...>",
13921         .tokens = {
13922                 (void *)&cmd_vf_tc_bw_set,
13923                 (void *)&cmd_vf_tc_bw_vf,
13924                 (void *)&cmd_vf_tc_bw_tc,
13925                 (void *)&cmd_vf_tc_bw_tx,
13926                 (void *)&cmd_vf_tc_bw_min_bw,
13927                 (void *)&cmd_vf_tc_bw_port_id,
13928                 (void *)&cmd_vf_tc_bw_vf_id,
13929                 (void *)&cmd_vf_tc_bw_bw_list,
13930                 NULL,
13931         },
13932 };
13933
13934 static void
13935 cmd_tc_min_bw_parsed(
13936         void *parsed_result,
13937         __attribute__((unused)) struct cmdline *cl,
13938         __attribute__((unused)) void *data)
13939 {
13940         struct cmd_vf_tc_bw_result *res = parsed_result;
13941         struct rte_port *port;
13942         uint8_t tc_num;
13943         uint8_t bw[16];
13944         int ret = -ENOTSUP;
13945
13946         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
13947                 return;
13948
13949         port = &ports[res->port_id];
13950         /** Check if the port is not started **/
13951         if (port->port_status != RTE_PORT_STOPPED) {
13952                 printf("Please stop port %d first\n", res->port_id);
13953                 return;
13954         }
13955
13956         ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list);
13957         if (ret)
13958                 return;
13959
13960 #ifdef RTE_LIBRTE_IXGBE_PMD
13961         ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw);
13962 #endif
13963
13964         switch (ret) {
13965         case 0:
13966                 break;
13967         case -EINVAL:
13968                 printf("invalid bandwidth\n");
13969                 break;
13970         case -ENODEV:
13971                 printf("invalid port_id %d\n", res->port_id);
13972                 break;
13973         case -ENOTSUP:
13974                 printf("function not implemented\n");
13975                 break;
13976         default:
13977                 printf("programming error: (%s)\n", strerror(-ret));
13978         }
13979 }
13980
13981 cmdline_parse_inst_t cmd_tc_min_bw = {
13982         .f = cmd_tc_min_bw_parsed,
13983         .data = NULL,
13984         .help_str = "set tc tx min-bandwidth <port_id> <bw1, bw2, ...>",
13985         .tokens = {
13986                 (void *)&cmd_vf_tc_bw_set,
13987                 (void *)&cmd_vf_tc_bw_tc,
13988                 (void *)&cmd_vf_tc_bw_tx,
13989                 (void *)&cmd_vf_tc_bw_min_bw,
13990                 (void *)&cmd_vf_tc_bw_port_id,
13991                 (void *)&cmd_vf_tc_bw_bw_list,
13992                 NULL,
13993         },
13994 };
13995
13996 /* TC max bandwidth setting */
13997 static void
13998 cmd_vf_tc_max_bw_parsed(
13999         void *parsed_result,
14000         __attribute__((unused)) struct cmdline *cl,
14001         __attribute__((unused)) void *data)
14002 {
14003         struct cmd_vf_tc_bw_result *res = parsed_result;
14004         int ret = -ENOTSUP;
14005
14006         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14007                 return;
14008
14009 #ifdef RTE_LIBRTE_I40E_PMD
14010         ret = rte_pmd_i40e_set_vf_tc_max_bw(res->port_id, res->vf_id,
14011                                             res->tc_no, res->bw);
14012 #endif
14013
14014         switch (ret) {
14015         case 0:
14016                 break;
14017         case -EINVAL:
14018                 printf("invalid vf_id %d, tc_no %d or bandwidth %d\n",
14019                        res->vf_id, res->tc_no, res->bw);
14020                 break;
14021         case -ENODEV:
14022                 printf("invalid port_id %d\n", res->port_id);
14023                 break;
14024         case -ENOTSUP:
14025                 printf("function not implemented\n");
14026                 break;
14027         default:
14028                 printf("programming error: (%s)\n", strerror(-ret));
14029         }
14030 }
14031
14032 cmdline_parse_inst_t cmd_vf_tc_max_bw = {
14033         .f = cmd_vf_tc_max_bw_parsed,
14034         .data = NULL,
14035         .help_str = "set vf tc tx max-bandwidth <port_id> <vf_id> <tc_no>"
14036                     " <bandwidth>",
14037         .tokens = {
14038                 (void *)&cmd_vf_tc_bw_set,
14039                 (void *)&cmd_vf_tc_bw_vf,
14040                 (void *)&cmd_vf_tc_bw_tc,
14041                 (void *)&cmd_vf_tc_bw_tx,
14042                 (void *)&cmd_vf_tc_bw_max_bw,
14043                 (void *)&cmd_vf_tc_bw_port_id,
14044                 (void *)&cmd_vf_tc_bw_vf_id,
14045                 (void *)&cmd_vf_tc_bw_tc_no,
14046                 (void *)&cmd_vf_tc_bw_bw,
14047                 NULL,
14048         },
14049 };
14050
14051
14052 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
14053
14054 /* *** Set Port default Traffic Management Hierarchy *** */
14055 struct cmd_set_port_tm_hierarchy_default_result {
14056         cmdline_fixed_string_t set;
14057         cmdline_fixed_string_t port;
14058         cmdline_fixed_string_t tm;
14059         cmdline_fixed_string_t hierarchy;
14060         cmdline_fixed_string_t def;
14061         portid_t port_id;
14062 };
14063
14064 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set =
14065         TOKEN_STRING_INITIALIZER(
14066                 struct cmd_set_port_tm_hierarchy_default_result, set, "set");
14067 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port =
14068         TOKEN_STRING_INITIALIZER(
14069                 struct cmd_set_port_tm_hierarchy_default_result, port, "port");
14070 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm =
14071         TOKEN_STRING_INITIALIZER(
14072                 struct cmd_set_port_tm_hierarchy_default_result, tm, "tm");
14073 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy =
14074         TOKEN_STRING_INITIALIZER(
14075                 struct cmd_set_port_tm_hierarchy_default_result,
14076                         hierarchy, "hierarchy");
14077 cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default =
14078         TOKEN_STRING_INITIALIZER(
14079                 struct cmd_set_port_tm_hierarchy_default_result,
14080                         def, "default");
14081 cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id =
14082         TOKEN_NUM_INITIALIZER(
14083                 struct cmd_set_port_tm_hierarchy_default_result,
14084                         port_id, UINT16);
14085
14086 static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result,
14087         __attribute__((unused)) struct cmdline *cl,
14088         __attribute__((unused)) void *data)
14089 {
14090         struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result;
14091         struct rte_port *p;
14092         portid_t port_id = res->port_id;
14093
14094         if (port_id_is_invalid(port_id, ENABLED_WARN))
14095                 return;
14096
14097         p = &ports[port_id];
14098
14099         /* Port tm flag */
14100         if (p->softport.tm_flag == 0) {
14101                 printf("  tm not enabled on port %u (error)\n", port_id);
14102                 return;
14103         }
14104
14105         /* Forward mode: tm */
14106         if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) {
14107                 printf("  tm mode not enabled(error)\n");
14108                 return;
14109         }
14110
14111         /* Set the default tm hierarchy */
14112         p->softport.tm.default_hierarchy_enable = 1;
14113 }
14114
14115 cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = {
14116         .f = cmd_set_port_tm_hierarchy_default_parsed,
14117         .data = NULL,
14118         .help_str = "set port tm hierarchy default <port_id>",
14119         .tokens = {
14120                 (void *)&cmd_set_port_tm_hierarchy_default_set,
14121                 (void *)&cmd_set_port_tm_hierarchy_default_port,
14122                 (void *)&cmd_set_port_tm_hierarchy_default_tm,
14123                 (void *)&cmd_set_port_tm_hierarchy_default_hierarchy,
14124                 (void *)&cmd_set_port_tm_hierarchy_default_default,
14125                 (void *)&cmd_set_port_tm_hierarchy_default_port_id,
14126                 NULL,
14127         },
14128 };
14129 #endif
14130
14131 /* Strict link priority scheduling mode setting */
14132 static void
14133 cmd_strict_link_prio_parsed(
14134         void *parsed_result,
14135         __attribute__((unused)) struct cmdline *cl,
14136         __attribute__((unused)) void *data)
14137 {
14138         struct cmd_vf_tc_bw_result *res = parsed_result;
14139         int ret = -ENOTSUP;
14140
14141         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14142                 return;
14143
14144 #ifdef RTE_LIBRTE_I40E_PMD
14145         ret = rte_pmd_i40e_set_tc_strict_prio(res->port_id, res->tc_map);
14146 #endif
14147
14148         switch (ret) {
14149         case 0:
14150                 break;
14151         case -EINVAL:
14152                 printf("invalid tc_bitmap 0x%x\n", res->tc_map);
14153                 break;
14154         case -ENODEV:
14155                 printf("invalid port_id %d\n", res->port_id);
14156                 break;
14157         case -ENOTSUP:
14158                 printf("function not implemented\n");
14159                 break;
14160         default:
14161                 printf("programming error: (%s)\n", strerror(-ret));
14162         }
14163 }
14164
14165 cmdline_parse_inst_t cmd_strict_link_prio = {
14166         .f = cmd_strict_link_prio_parsed,
14167         .data = NULL,
14168         .help_str = "set tx strict-link-priority <port_id> <tc_bitmap>",
14169         .tokens = {
14170                 (void *)&cmd_vf_tc_bw_set,
14171                 (void *)&cmd_vf_tc_bw_tx,
14172                 (void *)&cmd_vf_tc_bw_strict_link_prio,
14173                 (void *)&cmd_vf_tc_bw_port_id,
14174                 (void *)&cmd_vf_tc_bw_tc_map,
14175                 NULL,
14176         },
14177 };
14178
14179 /* Load dynamic device personalization*/
14180 struct cmd_ddp_add_result {
14181         cmdline_fixed_string_t ddp;
14182         cmdline_fixed_string_t add;
14183         portid_t port_id;
14184         char filepath[];
14185 };
14186
14187 cmdline_parse_token_string_t cmd_ddp_add_ddp =
14188         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, ddp, "ddp");
14189 cmdline_parse_token_string_t cmd_ddp_add_add =
14190         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add");
14191 cmdline_parse_token_num_t cmd_ddp_add_port_id =
14192         TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16);
14193 cmdline_parse_token_string_t cmd_ddp_add_filepath =
14194         TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL);
14195
14196 static void
14197 cmd_ddp_add_parsed(
14198         void *parsed_result,
14199         __attribute__((unused)) struct cmdline *cl,
14200         __attribute__((unused)) void *data)
14201 {
14202         struct cmd_ddp_add_result *res = parsed_result;
14203         uint8_t *buff;
14204         uint32_t size;
14205         char *filepath;
14206         char *file_fld[2];
14207         int file_num;
14208         int ret = -ENOTSUP;
14209
14210         if (res->port_id > nb_ports) {
14211                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14212                 return;
14213         }
14214
14215         if (!all_ports_stopped()) {
14216                 printf("Please stop all ports first\n");
14217                 return;
14218         }
14219
14220         filepath = strdup(res->filepath);
14221         if (filepath == NULL) {
14222                 printf("Failed to allocate memory\n");
14223                 return;
14224         }
14225         file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ',');
14226
14227         buff = open_ddp_package_file(file_fld[0], &size);
14228         if (!buff) {
14229                 free((void *)filepath);
14230                 return;
14231         }
14232
14233 #ifdef RTE_LIBRTE_I40E_PMD
14234         if (ret == -ENOTSUP)
14235                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14236                                                buff, size,
14237                                                RTE_PMD_I40E_PKG_OP_WR_ADD);
14238 #endif
14239
14240         if (ret == -EEXIST)
14241                 printf("Profile has already existed.\n");
14242         else if (ret < 0)
14243                 printf("Failed to load profile.\n");
14244         else if (file_num == 2)
14245                 save_ddp_package_file(file_fld[1], buff, size);
14246
14247         close_ddp_package_file(buff);
14248         free((void *)filepath);
14249 }
14250
14251 cmdline_parse_inst_t cmd_ddp_add = {
14252         .f = cmd_ddp_add_parsed,
14253         .data = NULL,
14254         .help_str = "ddp add <port_id> <profile_path[,output_path]>",
14255         .tokens = {
14256                 (void *)&cmd_ddp_add_ddp,
14257                 (void *)&cmd_ddp_add_add,
14258                 (void *)&cmd_ddp_add_port_id,
14259                 (void *)&cmd_ddp_add_filepath,
14260                 NULL,
14261         },
14262 };
14263
14264 /* Delete dynamic device personalization*/
14265 struct cmd_ddp_del_result {
14266         cmdline_fixed_string_t ddp;
14267         cmdline_fixed_string_t del;
14268         portid_t port_id;
14269         char filepath[];
14270 };
14271
14272 cmdline_parse_token_string_t cmd_ddp_del_ddp =
14273         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "ddp");
14274 cmdline_parse_token_string_t cmd_ddp_del_del =
14275         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del");
14276 cmdline_parse_token_num_t cmd_ddp_del_port_id =
14277         TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16);
14278 cmdline_parse_token_string_t cmd_ddp_del_filepath =
14279         TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL);
14280
14281 static void
14282 cmd_ddp_del_parsed(
14283         void *parsed_result,
14284         __attribute__((unused)) struct cmdline *cl,
14285         __attribute__((unused)) void *data)
14286 {
14287         struct cmd_ddp_del_result *res = parsed_result;
14288         uint8_t *buff;
14289         uint32_t size;
14290         int ret = -ENOTSUP;
14291
14292         if (res->port_id > nb_ports) {
14293                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14294                 return;
14295         }
14296
14297         if (!all_ports_stopped()) {
14298                 printf("Please stop all ports first\n");
14299                 return;
14300         }
14301
14302         buff = open_ddp_package_file(res->filepath, &size);
14303         if (!buff)
14304                 return;
14305
14306 #ifdef RTE_LIBRTE_I40E_PMD
14307         if (ret == -ENOTSUP)
14308                 ret = rte_pmd_i40e_process_ddp_package(res->port_id,
14309                                                buff, size,
14310                                                RTE_PMD_I40E_PKG_OP_WR_DEL);
14311 #endif
14312
14313         if (ret == -EACCES)
14314                 printf("Profile does not exist.\n");
14315         else if (ret < 0)
14316                 printf("Failed to delete profile.\n");
14317
14318         close_ddp_package_file(buff);
14319 }
14320
14321 cmdline_parse_inst_t cmd_ddp_del = {
14322         .f = cmd_ddp_del_parsed,
14323         .data = NULL,
14324         .help_str = "ddp del <port_id> <profile_path>",
14325         .tokens = {
14326                 (void *)&cmd_ddp_del_ddp,
14327                 (void *)&cmd_ddp_del_del,
14328                 (void *)&cmd_ddp_del_port_id,
14329                 (void *)&cmd_ddp_del_filepath,
14330                 NULL,
14331         },
14332 };
14333
14334 /* Get dynamic device personalization profile info */
14335 struct cmd_ddp_info_result {
14336         cmdline_fixed_string_t ddp;
14337         cmdline_fixed_string_t get;
14338         cmdline_fixed_string_t info;
14339         char filepath[];
14340 };
14341
14342 cmdline_parse_token_string_t cmd_ddp_info_ddp =
14343         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, ddp, "ddp");
14344 cmdline_parse_token_string_t cmd_ddp_info_get =
14345         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, get, "get");
14346 cmdline_parse_token_string_t cmd_ddp_info_info =
14347         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, info, "info");
14348 cmdline_parse_token_string_t cmd_ddp_info_filepath =
14349         TOKEN_STRING_INITIALIZER(struct cmd_ddp_info_result, filepath, NULL);
14350
14351 static void
14352 cmd_ddp_info_parsed(
14353         void *parsed_result,
14354         __attribute__((unused)) struct cmdline *cl,
14355         __attribute__((unused)) void *data)
14356 {
14357         struct cmd_ddp_info_result *res = parsed_result;
14358         uint8_t *pkg;
14359         uint32_t pkg_size;
14360         int ret = -ENOTSUP;
14361 #ifdef RTE_LIBRTE_I40E_PMD
14362         uint32_t i, j, n;
14363         uint8_t *buff;
14364         uint32_t buff_size = 0;
14365         struct rte_pmd_i40e_profile_info info;
14366         uint32_t dev_num = 0;
14367         struct rte_pmd_i40e_ddp_device_id *devs;
14368         uint32_t proto_num = 0;
14369         struct rte_pmd_i40e_proto_info *proto = NULL;
14370         uint32_t pctype_num = 0;
14371         struct rte_pmd_i40e_ptype_info *pctype;
14372         uint32_t ptype_num = 0;
14373         struct rte_pmd_i40e_ptype_info *ptype;
14374         uint8_t proto_id;
14375
14376 #endif
14377
14378         pkg = open_ddp_package_file(res->filepath, &pkg_size);
14379         if (!pkg)
14380                 return;
14381
14382 #ifdef RTE_LIBRTE_I40E_PMD
14383         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14384                                 (uint8_t *)&info, sizeof(info),
14385                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER);
14386         if (!ret) {
14387                 printf("Global Track id:       0x%x\n", info.track_id);
14388                 printf("Global Version:        %d.%d.%d.%d\n",
14389                         info.version.major,
14390                         info.version.minor,
14391                         info.version.update,
14392                         info.version.draft);
14393                 printf("Global Package name:   %s\n\n", info.name);
14394         }
14395
14396         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14397                                 (uint8_t *)&info, sizeof(info),
14398                                 RTE_PMD_I40E_PKG_INFO_HEADER);
14399         if (!ret) {
14400                 printf("i40e Profile Track id: 0x%x\n", info.track_id);
14401                 printf("i40e Profile Version:  %d.%d.%d.%d\n",
14402                         info.version.major,
14403                         info.version.minor,
14404                         info.version.update,
14405                         info.version.draft);
14406                 printf("i40e Profile name:     %s\n\n", info.name);
14407         }
14408
14409         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14410                                 (uint8_t *)&buff_size, sizeof(buff_size),
14411                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE);
14412         if (!ret && buff_size) {
14413                 buff = (uint8_t *)malloc(buff_size);
14414                 if (buff) {
14415                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14416                                                 buff, buff_size,
14417                                                 RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES);
14418                         if (!ret)
14419                                 printf("Package Notes:\n%s\n\n", buff);
14420                         free(buff);
14421                 }
14422         }
14423
14424         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14425                                 (uint8_t *)&dev_num, sizeof(dev_num),
14426                                 RTE_PMD_I40E_PKG_INFO_DEVID_NUM);
14427         if (!ret && dev_num) {
14428                 buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id);
14429                 devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size);
14430                 if (devs) {
14431                         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14432                                                 (uint8_t *)devs, buff_size,
14433                                                 RTE_PMD_I40E_PKG_INFO_DEVID_LIST);
14434                         if (!ret) {
14435                                 printf("List of supported devices:\n");
14436                                 for (i = 0; i < dev_num; i++) {
14437                                         printf("  %04X:%04X %04X:%04X\n",
14438                                                 devs[i].vendor_dev_id >> 16,
14439                                                 devs[i].vendor_dev_id & 0xFFFF,
14440                                                 devs[i].sub_vendor_dev_id >> 16,
14441                                                 devs[i].sub_vendor_dev_id & 0xFFFF);
14442                                 }
14443                                 printf("\n");
14444                         }
14445                         free(devs);
14446                 }
14447         }
14448
14449         /* get information about protocols and packet types */
14450         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14451                 (uint8_t *)&proto_num, sizeof(proto_num),
14452                 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
14453         if (ret || !proto_num)
14454                 goto no_print_return;
14455
14456         buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
14457         proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size);
14458         if (!proto)
14459                 goto no_print_return;
14460
14461         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto,
14462                                         buff_size,
14463                                         RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
14464         if (!ret) {
14465                 printf("List of used protocols:\n");
14466                 for (i = 0; i < proto_num; i++)
14467                         printf("  %2u: %s\n", proto[i].proto_id,
14468                                proto[i].name);
14469                 printf("\n");
14470         }
14471         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
14472                 (uint8_t *)&pctype_num, sizeof(pctype_num),
14473                 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
14474         if (ret || !pctype_num)
14475                 goto no_print_pctypes;
14476
14477         buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14478         pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14479         if (!pctype)
14480                 goto no_print_pctypes;
14481
14482         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype,
14483                                         buff_size,
14484                                         RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
14485         if (ret) {
14486                 free(pctype);
14487                 goto no_print_pctypes;
14488         }
14489
14490         printf("List of defined packet classification types:\n");
14491         for (i = 0; i < pctype_num; i++) {
14492                 printf("  %2u:", pctype[i].ptype_id);
14493                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14494                         proto_id = pctype[i].protocols[j];
14495                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14496                                 for (n = 0; n < proto_num; n++) {
14497                                         if (proto[n].proto_id == proto_id) {
14498                                                 printf(" %s", proto[n].name);
14499                                                 break;
14500                                         }
14501                                 }
14502                         }
14503                 }
14504                 printf("\n");
14505         }
14506         printf("\n");
14507         free(pctype);
14508
14509 no_print_pctypes:
14510
14511         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num,
14512                                         sizeof(ptype_num),
14513                                         RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
14514         if (ret || !ptype_num)
14515                 goto no_print_return;
14516
14517         buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
14518         ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size);
14519         if (!ptype)
14520                 goto no_print_return;
14521
14522         ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype,
14523                                         buff_size,
14524                                         RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
14525         if (ret) {
14526                 free(ptype);
14527                 goto no_print_return;
14528         }
14529         printf("List of defined packet types:\n");
14530         for (i = 0; i < ptype_num; i++) {
14531                 printf("  %2u:", ptype[i].ptype_id);
14532                 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
14533                         proto_id = ptype[i].protocols[j];
14534                         if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) {
14535                                 for (n = 0; n < proto_num; n++) {
14536                                         if (proto[n].proto_id == proto_id) {
14537                                                 printf(" %s", proto[n].name);
14538                                                 break;
14539                                         }
14540                                 }
14541                         }
14542                 }
14543                 printf("\n");
14544         }
14545         free(ptype);
14546         printf("\n");
14547
14548         ret = 0;
14549 no_print_return:
14550         if (proto)
14551                 free(proto);
14552 #endif
14553         if (ret == -ENOTSUP)
14554                 printf("Function not supported in PMD driver\n");
14555         close_ddp_package_file(pkg);
14556 }
14557
14558 cmdline_parse_inst_t cmd_ddp_get_info = {
14559         .f = cmd_ddp_info_parsed,
14560         .data = NULL,
14561         .help_str = "ddp get info <profile_path>",
14562         .tokens = {
14563                 (void *)&cmd_ddp_info_ddp,
14564                 (void *)&cmd_ddp_info_get,
14565                 (void *)&cmd_ddp_info_info,
14566                 (void *)&cmd_ddp_info_filepath,
14567                 NULL,
14568         },
14569 };
14570
14571 /* Get dynamic device personalization profile info list*/
14572 #define PROFILE_INFO_SIZE 48
14573 #define MAX_PROFILE_NUM 16
14574
14575 struct cmd_ddp_get_list_result {
14576         cmdline_fixed_string_t ddp;
14577         cmdline_fixed_string_t get;
14578         cmdline_fixed_string_t list;
14579         portid_t port_id;
14580 };
14581
14582 cmdline_parse_token_string_t cmd_ddp_get_list_ddp =
14583         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, ddp, "ddp");
14584 cmdline_parse_token_string_t cmd_ddp_get_list_get =
14585         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, get, "get");
14586 cmdline_parse_token_string_t cmd_ddp_get_list_list =
14587         TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list");
14588 cmdline_parse_token_num_t cmd_ddp_get_list_port_id =
14589         TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16);
14590
14591 static void
14592 cmd_ddp_get_list_parsed(
14593         void *parsed_result,
14594         __attribute__((unused)) struct cmdline *cl,
14595         __attribute__((unused)) void *data)
14596 {
14597         struct cmd_ddp_get_list_result *res = parsed_result;
14598 #ifdef RTE_LIBRTE_I40E_PMD
14599         struct rte_pmd_i40e_profile_list *p_list;
14600         struct rte_pmd_i40e_profile_info *p_info;
14601         uint32_t p_num;
14602         uint32_t size;
14603         uint32_t i;
14604 #endif
14605         int ret = -ENOTSUP;
14606
14607         if (res->port_id > nb_ports) {
14608                 printf("Invalid port, range is [0, %d]\n", nb_ports - 1);
14609                 return;
14610         }
14611
14612 #ifdef RTE_LIBRTE_I40E_PMD
14613         size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
14614         p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
14615         if (!p_list)
14616                 printf("%s: Failed to malloc buffer\n", __func__);
14617
14618         if (ret == -ENOTSUP)
14619                 ret = rte_pmd_i40e_get_ddp_list(res->port_id,
14620                                                 (uint8_t *)p_list, size);
14621
14622         if (!ret) {
14623                 p_num = p_list->p_count;
14624                 printf("Profile number is: %d\n\n", p_num);
14625
14626                 for (i = 0; i < p_num; i++) {
14627                         p_info = &p_list->p_info[i];
14628                         printf("Profile %d:\n", i);
14629                         printf("Track id:     0x%x\n", p_info->track_id);
14630                         printf("Version:      %d.%d.%d.%d\n",
14631                                p_info->version.major,
14632                                p_info->version.minor,
14633                                p_info->version.update,
14634                                p_info->version.draft);
14635                         printf("Profile name: %s\n\n", p_info->name);
14636                 }
14637         }
14638
14639         free(p_list);
14640 #endif
14641
14642         if (ret < 0)
14643                 printf("Failed to get ddp list\n");
14644 }
14645
14646 cmdline_parse_inst_t cmd_ddp_get_list = {
14647         .f = cmd_ddp_get_list_parsed,
14648         .data = NULL,
14649         .help_str = "ddp get list <port_id>",
14650         .tokens = {
14651                 (void *)&cmd_ddp_get_list_ddp,
14652                 (void *)&cmd_ddp_get_list_get,
14653                 (void *)&cmd_ddp_get_list_list,
14654                 (void *)&cmd_ddp_get_list_port_id,
14655                 NULL,
14656         },
14657 };
14658
14659 /* show vf stats */
14660
14661 /* Common result structure for show vf stats */
14662 struct cmd_show_vf_stats_result {
14663         cmdline_fixed_string_t show;
14664         cmdline_fixed_string_t vf;
14665         cmdline_fixed_string_t stats;
14666         portid_t port_id;
14667         uint16_t vf_id;
14668 };
14669
14670 /* Common CLI fields show vf stats*/
14671 cmdline_parse_token_string_t cmd_show_vf_stats_show =
14672         TOKEN_STRING_INITIALIZER
14673                 (struct cmd_show_vf_stats_result,
14674                  show, "show");
14675 cmdline_parse_token_string_t cmd_show_vf_stats_vf =
14676         TOKEN_STRING_INITIALIZER
14677                 (struct cmd_show_vf_stats_result,
14678                  vf, "vf");
14679 cmdline_parse_token_string_t cmd_show_vf_stats_stats =
14680         TOKEN_STRING_INITIALIZER
14681                 (struct cmd_show_vf_stats_result,
14682                  stats, "stats");
14683 cmdline_parse_token_num_t cmd_show_vf_stats_port_id =
14684         TOKEN_NUM_INITIALIZER
14685                 (struct cmd_show_vf_stats_result,
14686                  port_id, UINT16);
14687 cmdline_parse_token_num_t cmd_show_vf_stats_vf_id =
14688         TOKEN_NUM_INITIALIZER
14689                 (struct cmd_show_vf_stats_result,
14690                  vf_id, UINT16);
14691
14692 static void
14693 cmd_show_vf_stats_parsed(
14694         void *parsed_result,
14695         __attribute__((unused)) struct cmdline *cl,
14696         __attribute__((unused)) void *data)
14697 {
14698         struct cmd_show_vf_stats_result *res = parsed_result;
14699         struct rte_eth_stats stats;
14700         int ret = -ENOTSUP;
14701         static const char *nic_stats_border = "########################";
14702
14703         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14704                 return;
14705
14706         memset(&stats, 0, sizeof(stats));
14707
14708 #ifdef RTE_LIBRTE_I40E_PMD
14709         if (ret == -ENOTSUP)
14710                 ret = rte_pmd_i40e_get_vf_stats(res->port_id,
14711                                                 res->vf_id,
14712                                                 &stats);
14713 #endif
14714 #ifdef RTE_LIBRTE_BNXT_PMD
14715         if (ret == -ENOTSUP)
14716                 ret = rte_pmd_bnxt_get_vf_stats(res->port_id,
14717                                                 res->vf_id,
14718                                                 &stats);
14719 #endif
14720
14721         switch (ret) {
14722         case 0:
14723                 break;
14724         case -EINVAL:
14725                 printf("invalid vf_id %d\n", res->vf_id);
14726                 break;
14727         case -ENODEV:
14728                 printf("invalid port_id %d\n", res->port_id);
14729                 break;
14730         case -ENOTSUP:
14731                 printf("function not implemented\n");
14732                 break;
14733         default:
14734                 printf("programming error: (%s)\n", strerror(-ret));
14735         }
14736
14737         printf("\n  %s NIC statistics for port %-2d vf %-2d %s\n",
14738                 nic_stats_border, res->port_id, res->vf_id, nic_stats_border);
14739
14740         printf("  RX-packets: %-10"PRIu64" RX-missed: %-10"PRIu64" RX-bytes:  "
14741                "%-"PRIu64"\n",
14742                stats.ipackets, stats.imissed, stats.ibytes);
14743         printf("  RX-errors: %-"PRIu64"\n", stats.ierrors);
14744         printf("  RX-nombuf:  %-10"PRIu64"\n",
14745                stats.rx_nombuf);
14746         printf("  TX-packets: %-10"PRIu64" TX-errors: %-10"PRIu64" TX-bytes:  "
14747                "%-"PRIu64"\n",
14748                stats.opackets, stats.oerrors, stats.obytes);
14749
14750         printf("  %s############################%s\n",
14751                                nic_stats_border, nic_stats_border);
14752 }
14753
14754 cmdline_parse_inst_t cmd_show_vf_stats = {
14755         .f = cmd_show_vf_stats_parsed,
14756         .data = NULL,
14757         .help_str = "show vf stats <port_id> <vf_id>",
14758         .tokens = {
14759                 (void *)&cmd_show_vf_stats_show,
14760                 (void *)&cmd_show_vf_stats_vf,
14761                 (void *)&cmd_show_vf_stats_stats,
14762                 (void *)&cmd_show_vf_stats_port_id,
14763                 (void *)&cmd_show_vf_stats_vf_id,
14764                 NULL,
14765         },
14766 };
14767
14768 /* clear vf stats */
14769
14770 /* Common result structure for clear vf stats */
14771 struct cmd_clear_vf_stats_result {
14772         cmdline_fixed_string_t clear;
14773         cmdline_fixed_string_t vf;
14774         cmdline_fixed_string_t stats;
14775         portid_t port_id;
14776         uint16_t vf_id;
14777 };
14778
14779 /* Common CLI fields clear vf stats*/
14780 cmdline_parse_token_string_t cmd_clear_vf_stats_clear =
14781         TOKEN_STRING_INITIALIZER
14782                 (struct cmd_clear_vf_stats_result,
14783                  clear, "clear");
14784 cmdline_parse_token_string_t cmd_clear_vf_stats_vf =
14785         TOKEN_STRING_INITIALIZER
14786                 (struct cmd_clear_vf_stats_result,
14787                  vf, "vf");
14788 cmdline_parse_token_string_t cmd_clear_vf_stats_stats =
14789         TOKEN_STRING_INITIALIZER
14790                 (struct cmd_clear_vf_stats_result,
14791                  stats, "stats");
14792 cmdline_parse_token_num_t cmd_clear_vf_stats_port_id =
14793         TOKEN_NUM_INITIALIZER
14794                 (struct cmd_clear_vf_stats_result,
14795                  port_id, UINT16);
14796 cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id =
14797         TOKEN_NUM_INITIALIZER
14798                 (struct cmd_clear_vf_stats_result,
14799                  vf_id, UINT16);
14800
14801 static void
14802 cmd_clear_vf_stats_parsed(
14803         void *parsed_result,
14804         __attribute__((unused)) struct cmdline *cl,
14805         __attribute__((unused)) void *data)
14806 {
14807         struct cmd_clear_vf_stats_result *res = parsed_result;
14808         int ret = -ENOTSUP;
14809
14810         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14811                 return;
14812
14813 #ifdef RTE_LIBRTE_I40E_PMD
14814         if (ret == -ENOTSUP)
14815                 ret = rte_pmd_i40e_reset_vf_stats(res->port_id,
14816                                                   res->vf_id);
14817 #endif
14818 #ifdef RTE_LIBRTE_BNXT_PMD
14819         if (ret == -ENOTSUP)
14820                 ret = rte_pmd_bnxt_reset_vf_stats(res->port_id,
14821                                                   res->vf_id);
14822 #endif
14823
14824         switch (ret) {
14825         case 0:
14826                 break;
14827         case -EINVAL:
14828                 printf("invalid vf_id %d\n", res->vf_id);
14829                 break;
14830         case -ENODEV:
14831                 printf("invalid port_id %d\n", res->port_id);
14832                 break;
14833         case -ENOTSUP:
14834                 printf("function not implemented\n");
14835                 break;
14836         default:
14837                 printf("programming error: (%s)\n", strerror(-ret));
14838         }
14839 }
14840
14841 cmdline_parse_inst_t cmd_clear_vf_stats = {
14842         .f = cmd_clear_vf_stats_parsed,
14843         .data = NULL,
14844         .help_str = "clear vf stats <port_id> <vf_id>",
14845         .tokens = {
14846                 (void *)&cmd_clear_vf_stats_clear,
14847                 (void *)&cmd_clear_vf_stats_vf,
14848                 (void *)&cmd_clear_vf_stats_stats,
14849                 (void *)&cmd_clear_vf_stats_port_id,
14850                 (void *)&cmd_clear_vf_stats_vf_id,
14851                 NULL,
14852         },
14853 };
14854
14855 /* port config pctype mapping reset */
14856
14857 /* Common result structure for port config pctype mapping reset */
14858 struct cmd_pctype_mapping_reset_result {
14859         cmdline_fixed_string_t port;
14860         cmdline_fixed_string_t config;
14861         portid_t port_id;
14862         cmdline_fixed_string_t pctype;
14863         cmdline_fixed_string_t mapping;
14864         cmdline_fixed_string_t reset;
14865 };
14866
14867 /* Common CLI fields for port config pctype mapping reset*/
14868 cmdline_parse_token_string_t cmd_pctype_mapping_reset_port =
14869         TOKEN_STRING_INITIALIZER
14870                 (struct cmd_pctype_mapping_reset_result,
14871                  port, "port");
14872 cmdline_parse_token_string_t cmd_pctype_mapping_reset_config =
14873         TOKEN_STRING_INITIALIZER
14874                 (struct cmd_pctype_mapping_reset_result,
14875                  config, "config");
14876 cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id =
14877         TOKEN_NUM_INITIALIZER
14878                 (struct cmd_pctype_mapping_reset_result,
14879                  port_id, UINT16);
14880 cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype =
14881         TOKEN_STRING_INITIALIZER
14882                 (struct cmd_pctype_mapping_reset_result,
14883                  pctype, "pctype");
14884 cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping =
14885         TOKEN_STRING_INITIALIZER
14886                 (struct cmd_pctype_mapping_reset_result,
14887                  mapping, "mapping");
14888 cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset =
14889         TOKEN_STRING_INITIALIZER
14890                 (struct cmd_pctype_mapping_reset_result,
14891                  reset, "reset");
14892
14893 static void
14894 cmd_pctype_mapping_reset_parsed(
14895         void *parsed_result,
14896         __attribute__((unused)) struct cmdline *cl,
14897         __attribute__((unused)) void *data)
14898 {
14899         struct cmd_pctype_mapping_reset_result *res = parsed_result;
14900         int ret = -ENOTSUP;
14901
14902         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14903                 return;
14904
14905 #ifdef RTE_LIBRTE_I40E_PMD
14906         ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id);
14907 #endif
14908
14909         switch (ret) {
14910         case 0:
14911                 break;
14912         case -ENODEV:
14913                 printf("invalid port_id %d\n", res->port_id);
14914                 break;
14915         case -ENOTSUP:
14916                 printf("function not implemented\n");
14917                 break;
14918         default:
14919                 printf("programming error: (%s)\n", strerror(-ret));
14920         }
14921 }
14922
14923 cmdline_parse_inst_t cmd_pctype_mapping_reset = {
14924         .f = cmd_pctype_mapping_reset_parsed,
14925         .data = NULL,
14926         .help_str = "port config <port_id> pctype mapping reset",
14927         .tokens = {
14928                 (void *)&cmd_pctype_mapping_reset_port,
14929                 (void *)&cmd_pctype_mapping_reset_config,
14930                 (void *)&cmd_pctype_mapping_reset_port_id,
14931                 (void *)&cmd_pctype_mapping_reset_pctype,
14932                 (void *)&cmd_pctype_mapping_reset_mapping,
14933                 (void *)&cmd_pctype_mapping_reset_reset,
14934                 NULL,
14935         },
14936 };
14937
14938 /* show port pctype mapping */
14939
14940 /* Common result structure for show port pctype mapping */
14941 struct cmd_pctype_mapping_get_result {
14942         cmdline_fixed_string_t show;
14943         cmdline_fixed_string_t port;
14944         portid_t port_id;
14945         cmdline_fixed_string_t pctype;
14946         cmdline_fixed_string_t mapping;
14947 };
14948
14949 /* Common CLI fields for pctype mapping get */
14950 cmdline_parse_token_string_t cmd_pctype_mapping_get_show =
14951         TOKEN_STRING_INITIALIZER
14952                 (struct cmd_pctype_mapping_get_result,
14953                  show, "show");
14954 cmdline_parse_token_string_t cmd_pctype_mapping_get_port =
14955         TOKEN_STRING_INITIALIZER
14956                 (struct cmd_pctype_mapping_get_result,
14957                  port, "port");
14958 cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id =
14959         TOKEN_NUM_INITIALIZER
14960                 (struct cmd_pctype_mapping_get_result,
14961                  port_id, UINT16);
14962 cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype =
14963         TOKEN_STRING_INITIALIZER
14964                 (struct cmd_pctype_mapping_get_result,
14965                  pctype, "pctype");
14966 cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping =
14967         TOKEN_STRING_INITIALIZER
14968                 (struct cmd_pctype_mapping_get_result,
14969                  mapping, "mapping");
14970
14971 static void
14972 cmd_pctype_mapping_get_parsed(
14973         void *parsed_result,
14974         __attribute__((unused)) struct cmdline *cl,
14975         __attribute__((unused)) void *data)
14976 {
14977         struct cmd_pctype_mapping_get_result *res = parsed_result;
14978         int ret = -ENOTSUP;
14979 #ifdef RTE_LIBRTE_I40E_PMD
14980         struct rte_pmd_i40e_flow_type_mapping
14981                                 mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
14982         int i, j, first_pctype;
14983 #endif
14984
14985         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
14986                 return;
14987
14988 #ifdef RTE_LIBRTE_I40E_PMD
14989         ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping);
14990 #endif
14991
14992         switch (ret) {
14993         case 0:
14994                 break;
14995         case -ENODEV:
14996                 printf("invalid port_id %d\n", res->port_id);
14997                 return;
14998         case -ENOTSUP:
14999                 printf("function not implemented\n");
15000                 return;
15001         default:
15002                 printf("programming error: (%s)\n", strerror(-ret));
15003                 return;
15004         }
15005
15006 #ifdef RTE_LIBRTE_I40E_PMD
15007         for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) {
15008                 if (mapping[i].pctype != 0ULL) {
15009                         first_pctype = 1;
15010
15011                         printf("pctype: ");
15012                         for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) {
15013                                 if (mapping[i].pctype & (1ULL << j)) {
15014                                         printf(first_pctype ?
15015                                                "%02d" : ",%02d", j);
15016                                         first_pctype = 0;
15017                                 }
15018                         }
15019                         printf("  ->  flowtype: %02d\n", mapping[i].flow_type);
15020                 }
15021         }
15022 #endif
15023 }
15024
15025 cmdline_parse_inst_t cmd_pctype_mapping_get = {
15026         .f = cmd_pctype_mapping_get_parsed,
15027         .data = NULL,
15028         .help_str = "show port <port_id> pctype mapping",
15029         .tokens = {
15030                 (void *)&cmd_pctype_mapping_get_show,
15031                 (void *)&cmd_pctype_mapping_get_port,
15032                 (void *)&cmd_pctype_mapping_get_port_id,
15033                 (void *)&cmd_pctype_mapping_get_pctype,
15034                 (void *)&cmd_pctype_mapping_get_mapping,
15035                 NULL,
15036         },
15037 };
15038
15039 /* port config pctype mapping update */
15040
15041 /* Common result structure for port config pctype mapping update */
15042 struct cmd_pctype_mapping_update_result {
15043         cmdline_fixed_string_t port;
15044         cmdline_fixed_string_t config;
15045         portid_t port_id;
15046         cmdline_fixed_string_t pctype;
15047         cmdline_fixed_string_t mapping;
15048         cmdline_fixed_string_t update;
15049         cmdline_fixed_string_t pctype_list;
15050         uint16_t flow_type;
15051 };
15052
15053 /* Common CLI fields for pctype mapping update*/
15054 cmdline_parse_token_string_t cmd_pctype_mapping_update_port =
15055         TOKEN_STRING_INITIALIZER
15056                 (struct cmd_pctype_mapping_update_result,
15057                  port, "port");
15058 cmdline_parse_token_string_t cmd_pctype_mapping_update_config =
15059         TOKEN_STRING_INITIALIZER
15060                 (struct cmd_pctype_mapping_update_result,
15061                  config, "config");
15062 cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id =
15063         TOKEN_NUM_INITIALIZER
15064                 (struct cmd_pctype_mapping_update_result,
15065                  port_id, UINT16);
15066 cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype =
15067         TOKEN_STRING_INITIALIZER
15068                 (struct cmd_pctype_mapping_update_result,
15069                  pctype, "pctype");
15070 cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping =
15071         TOKEN_STRING_INITIALIZER
15072                 (struct cmd_pctype_mapping_update_result,
15073                  mapping, "mapping");
15074 cmdline_parse_token_string_t cmd_pctype_mapping_update_update =
15075         TOKEN_STRING_INITIALIZER
15076                 (struct cmd_pctype_mapping_update_result,
15077                  update, "update");
15078 cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type =
15079         TOKEN_STRING_INITIALIZER
15080                 (struct cmd_pctype_mapping_update_result,
15081                  pctype_list, NULL);
15082 cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type =
15083         TOKEN_NUM_INITIALIZER
15084                 (struct cmd_pctype_mapping_update_result,
15085                  flow_type, UINT16);
15086
15087 static void
15088 cmd_pctype_mapping_update_parsed(
15089         void *parsed_result,
15090         __attribute__((unused)) struct cmdline *cl,
15091         __attribute__((unused)) void *data)
15092 {
15093         struct cmd_pctype_mapping_update_result *res = parsed_result;
15094         int ret = -ENOTSUP;
15095 #ifdef RTE_LIBRTE_I40E_PMD
15096         struct rte_pmd_i40e_flow_type_mapping mapping;
15097         unsigned int i;
15098         unsigned int nb_item;
15099         unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX];
15100 #endif
15101
15102         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15103                 return;
15104
15105 #ifdef RTE_LIBRTE_I40E_PMD
15106         nb_item = parse_item_list(res->pctype_list, "pctypes",
15107                                   RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1);
15108         mapping.flow_type = res->flow_type;
15109         for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++)
15110                 mapping.pctype |= (1ULL << pctype_list[i]);
15111         ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id,
15112                                                 &mapping,
15113                                                 1,
15114                                                 0);
15115 #endif
15116
15117         switch (ret) {
15118         case 0:
15119                 break;
15120         case -EINVAL:
15121                 printf("invalid pctype or flow type\n");
15122                 break;
15123         case -ENODEV:
15124                 printf("invalid port_id %d\n", res->port_id);
15125                 break;
15126         case -ENOTSUP:
15127                 printf("function not implemented\n");
15128                 break;
15129         default:
15130                 printf("programming error: (%s)\n", strerror(-ret));
15131         }
15132 }
15133
15134 cmdline_parse_inst_t cmd_pctype_mapping_update = {
15135         .f = cmd_pctype_mapping_update_parsed,
15136         .data = NULL,
15137         .help_str = "port config <port_id> pctype mapping update"
15138         " <pctype_id_0,[pctype_id_1]*> <flowtype_id>",
15139         .tokens = {
15140                 (void *)&cmd_pctype_mapping_update_port,
15141                 (void *)&cmd_pctype_mapping_update_config,
15142                 (void *)&cmd_pctype_mapping_update_port_id,
15143                 (void *)&cmd_pctype_mapping_update_pctype,
15144                 (void *)&cmd_pctype_mapping_update_mapping,
15145                 (void *)&cmd_pctype_mapping_update_update,
15146                 (void *)&cmd_pctype_mapping_update_pc_type,
15147                 (void *)&cmd_pctype_mapping_update_flow_type,
15148                 NULL,
15149         },
15150 };
15151
15152 /* ptype mapping get */
15153
15154 /* Common result structure for ptype mapping get */
15155 struct cmd_ptype_mapping_get_result {
15156         cmdline_fixed_string_t ptype;
15157         cmdline_fixed_string_t mapping;
15158         cmdline_fixed_string_t get;
15159         portid_t port_id;
15160         uint8_t valid_only;
15161 };
15162
15163 /* Common CLI fields for ptype mapping get */
15164 cmdline_parse_token_string_t cmd_ptype_mapping_get_ptype =
15165         TOKEN_STRING_INITIALIZER
15166                 (struct cmd_ptype_mapping_get_result,
15167                  ptype, "ptype");
15168 cmdline_parse_token_string_t cmd_ptype_mapping_get_mapping =
15169         TOKEN_STRING_INITIALIZER
15170                 (struct cmd_ptype_mapping_get_result,
15171                  mapping, "mapping");
15172 cmdline_parse_token_string_t cmd_ptype_mapping_get_get =
15173         TOKEN_STRING_INITIALIZER
15174                 (struct cmd_ptype_mapping_get_result,
15175                  get, "get");
15176 cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id =
15177         TOKEN_NUM_INITIALIZER
15178                 (struct cmd_ptype_mapping_get_result,
15179                  port_id, UINT16);
15180 cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only =
15181         TOKEN_NUM_INITIALIZER
15182                 (struct cmd_ptype_mapping_get_result,
15183                  valid_only, UINT8);
15184
15185 static void
15186 cmd_ptype_mapping_get_parsed(
15187         void *parsed_result,
15188         __attribute__((unused)) struct cmdline *cl,
15189         __attribute__((unused)) void *data)
15190 {
15191         struct cmd_ptype_mapping_get_result *res = parsed_result;
15192         int ret = -ENOTSUP;
15193 #ifdef RTE_LIBRTE_I40E_PMD
15194         int max_ptype_num = 256;
15195         struct rte_pmd_i40e_ptype_mapping mapping[max_ptype_num];
15196         uint16_t count;
15197         int i;
15198 #endif
15199
15200         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15201                 return;
15202
15203 #ifdef RTE_LIBRTE_I40E_PMD
15204         ret = rte_pmd_i40e_ptype_mapping_get(res->port_id,
15205                                         mapping,
15206                                         max_ptype_num,
15207                                         &count,
15208                                         res->valid_only);
15209 #endif
15210
15211         switch (ret) {
15212         case 0:
15213                 break;
15214         case -ENODEV:
15215                 printf("invalid port_id %d\n", res->port_id);
15216                 break;
15217         case -ENOTSUP:
15218                 printf("function not implemented\n");
15219                 break;
15220         default:
15221                 printf("programming error: (%s)\n", strerror(-ret));
15222         }
15223
15224 #ifdef RTE_LIBRTE_I40E_PMD
15225         if (!ret) {
15226                 for (i = 0; i < count; i++)
15227                         printf("%3d\t0x%08x\n",
15228                                 mapping[i].hw_ptype, mapping[i].sw_ptype);
15229         }
15230 #endif
15231 }
15232
15233 cmdline_parse_inst_t cmd_ptype_mapping_get = {
15234         .f = cmd_ptype_mapping_get_parsed,
15235         .data = NULL,
15236         .help_str = "ptype mapping get <port_id> <valid_only>",
15237         .tokens = {
15238                 (void *)&cmd_ptype_mapping_get_ptype,
15239                 (void *)&cmd_ptype_mapping_get_mapping,
15240                 (void *)&cmd_ptype_mapping_get_get,
15241                 (void *)&cmd_ptype_mapping_get_port_id,
15242                 (void *)&cmd_ptype_mapping_get_valid_only,
15243                 NULL,
15244         },
15245 };
15246
15247 /* ptype mapping replace */
15248
15249 /* Common result structure for ptype mapping replace */
15250 struct cmd_ptype_mapping_replace_result {
15251         cmdline_fixed_string_t ptype;
15252         cmdline_fixed_string_t mapping;
15253         cmdline_fixed_string_t replace;
15254         portid_t port_id;
15255         uint32_t target;
15256         uint8_t mask;
15257         uint32_t pkt_type;
15258 };
15259
15260 /* Common CLI fields for ptype mapping replace */
15261 cmdline_parse_token_string_t cmd_ptype_mapping_replace_ptype =
15262         TOKEN_STRING_INITIALIZER
15263                 (struct cmd_ptype_mapping_replace_result,
15264                  ptype, "ptype");
15265 cmdline_parse_token_string_t cmd_ptype_mapping_replace_mapping =
15266         TOKEN_STRING_INITIALIZER
15267                 (struct cmd_ptype_mapping_replace_result,
15268                  mapping, "mapping");
15269 cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace =
15270         TOKEN_STRING_INITIALIZER
15271                 (struct cmd_ptype_mapping_replace_result,
15272                  replace, "replace");
15273 cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id =
15274         TOKEN_NUM_INITIALIZER
15275                 (struct cmd_ptype_mapping_replace_result,
15276                  port_id, UINT16);
15277 cmdline_parse_token_num_t cmd_ptype_mapping_replace_target =
15278         TOKEN_NUM_INITIALIZER
15279                 (struct cmd_ptype_mapping_replace_result,
15280                  target, UINT32);
15281 cmdline_parse_token_num_t cmd_ptype_mapping_replace_mask =
15282         TOKEN_NUM_INITIALIZER
15283                 (struct cmd_ptype_mapping_replace_result,
15284                  mask, UINT8);
15285 cmdline_parse_token_num_t cmd_ptype_mapping_replace_pkt_type =
15286         TOKEN_NUM_INITIALIZER
15287                 (struct cmd_ptype_mapping_replace_result,
15288                  pkt_type, UINT32);
15289
15290 static void
15291 cmd_ptype_mapping_replace_parsed(
15292         void *parsed_result,
15293         __attribute__((unused)) struct cmdline *cl,
15294         __attribute__((unused)) void *data)
15295 {
15296         struct cmd_ptype_mapping_replace_result *res = parsed_result;
15297         int ret = -ENOTSUP;
15298
15299         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15300                 return;
15301
15302 #ifdef RTE_LIBRTE_I40E_PMD
15303         ret = rte_pmd_i40e_ptype_mapping_replace(res->port_id,
15304                                         res->target,
15305                                         res->mask,
15306                                         res->pkt_type);
15307 #endif
15308
15309         switch (ret) {
15310         case 0:
15311                 break;
15312         case -EINVAL:
15313                 printf("invalid ptype 0x%8x or 0x%8x\n",
15314                                 res->target, res->pkt_type);
15315                 break;
15316         case -ENODEV:
15317                 printf("invalid port_id %d\n", res->port_id);
15318                 break;
15319         case -ENOTSUP:
15320                 printf("function not implemented\n");
15321                 break;
15322         default:
15323                 printf("programming error: (%s)\n", strerror(-ret));
15324         }
15325 }
15326
15327 cmdline_parse_inst_t cmd_ptype_mapping_replace = {
15328         .f = cmd_ptype_mapping_replace_parsed,
15329         .data = NULL,
15330         .help_str =
15331                 "ptype mapping replace <port_id> <target> <mask> <pkt_type>",
15332         .tokens = {
15333                 (void *)&cmd_ptype_mapping_replace_ptype,
15334                 (void *)&cmd_ptype_mapping_replace_mapping,
15335                 (void *)&cmd_ptype_mapping_replace_replace,
15336                 (void *)&cmd_ptype_mapping_replace_port_id,
15337                 (void *)&cmd_ptype_mapping_replace_target,
15338                 (void *)&cmd_ptype_mapping_replace_mask,
15339                 (void *)&cmd_ptype_mapping_replace_pkt_type,
15340                 NULL,
15341         },
15342 };
15343
15344 /* ptype mapping reset */
15345
15346 /* Common result structure for ptype mapping reset */
15347 struct cmd_ptype_mapping_reset_result {
15348         cmdline_fixed_string_t ptype;
15349         cmdline_fixed_string_t mapping;
15350         cmdline_fixed_string_t reset;
15351         portid_t port_id;
15352 };
15353
15354 /* Common CLI fields for ptype mapping reset*/
15355 cmdline_parse_token_string_t cmd_ptype_mapping_reset_ptype =
15356         TOKEN_STRING_INITIALIZER
15357                 (struct cmd_ptype_mapping_reset_result,
15358                  ptype, "ptype");
15359 cmdline_parse_token_string_t cmd_ptype_mapping_reset_mapping =
15360         TOKEN_STRING_INITIALIZER
15361                 (struct cmd_ptype_mapping_reset_result,
15362                  mapping, "mapping");
15363 cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset =
15364         TOKEN_STRING_INITIALIZER
15365                 (struct cmd_ptype_mapping_reset_result,
15366                  reset, "reset");
15367 cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id =
15368         TOKEN_NUM_INITIALIZER
15369                 (struct cmd_ptype_mapping_reset_result,
15370                  port_id, UINT16);
15371
15372 static void
15373 cmd_ptype_mapping_reset_parsed(
15374         void *parsed_result,
15375         __attribute__((unused)) struct cmdline *cl,
15376         __attribute__((unused)) void *data)
15377 {
15378         struct cmd_ptype_mapping_reset_result *res = parsed_result;
15379         int ret = -ENOTSUP;
15380
15381         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15382                 return;
15383
15384 #ifdef RTE_LIBRTE_I40E_PMD
15385         ret = rte_pmd_i40e_ptype_mapping_reset(res->port_id);
15386 #endif
15387
15388         switch (ret) {
15389         case 0:
15390                 break;
15391         case -ENODEV:
15392                 printf("invalid port_id %d\n", res->port_id);
15393                 break;
15394         case -ENOTSUP:
15395                 printf("function not implemented\n");
15396                 break;
15397         default:
15398                 printf("programming error: (%s)\n", strerror(-ret));
15399         }
15400 }
15401
15402 cmdline_parse_inst_t cmd_ptype_mapping_reset = {
15403         .f = cmd_ptype_mapping_reset_parsed,
15404         .data = NULL,
15405         .help_str = "ptype mapping reset <port_id>",
15406         .tokens = {
15407                 (void *)&cmd_ptype_mapping_reset_ptype,
15408                 (void *)&cmd_ptype_mapping_reset_mapping,
15409                 (void *)&cmd_ptype_mapping_reset_reset,
15410                 (void *)&cmd_ptype_mapping_reset_port_id,
15411                 NULL,
15412         },
15413 };
15414
15415 /* ptype mapping update */
15416
15417 /* Common result structure for ptype mapping update */
15418 struct cmd_ptype_mapping_update_result {
15419         cmdline_fixed_string_t ptype;
15420         cmdline_fixed_string_t mapping;
15421         cmdline_fixed_string_t reset;
15422         portid_t port_id;
15423         uint8_t hw_ptype;
15424         uint32_t sw_ptype;
15425 };
15426
15427 /* Common CLI fields for ptype mapping update*/
15428 cmdline_parse_token_string_t cmd_ptype_mapping_update_ptype =
15429         TOKEN_STRING_INITIALIZER
15430                 (struct cmd_ptype_mapping_update_result,
15431                  ptype, "ptype");
15432 cmdline_parse_token_string_t cmd_ptype_mapping_update_mapping =
15433         TOKEN_STRING_INITIALIZER
15434                 (struct cmd_ptype_mapping_update_result,
15435                  mapping, "mapping");
15436 cmdline_parse_token_string_t cmd_ptype_mapping_update_update =
15437         TOKEN_STRING_INITIALIZER
15438                 (struct cmd_ptype_mapping_update_result,
15439                  reset, "update");
15440 cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id =
15441         TOKEN_NUM_INITIALIZER
15442                 (struct cmd_ptype_mapping_update_result,
15443                  port_id, UINT16);
15444 cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype =
15445         TOKEN_NUM_INITIALIZER
15446                 (struct cmd_ptype_mapping_update_result,
15447                  hw_ptype, UINT8);
15448 cmdline_parse_token_num_t cmd_ptype_mapping_update_sw_ptype =
15449         TOKEN_NUM_INITIALIZER
15450                 (struct cmd_ptype_mapping_update_result,
15451                  sw_ptype, UINT32);
15452
15453 static void
15454 cmd_ptype_mapping_update_parsed(
15455         void *parsed_result,
15456         __attribute__((unused)) struct cmdline *cl,
15457         __attribute__((unused)) void *data)
15458 {
15459         struct cmd_ptype_mapping_update_result *res = parsed_result;
15460         int ret = -ENOTSUP;
15461 #ifdef RTE_LIBRTE_I40E_PMD
15462         struct rte_pmd_i40e_ptype_mapping mapping;
15463 #endif
15464         if (port_id_is_invalid(res->port_id, ENABLED_WARN))
15465                 return;
15466
15467 #ifdef RTE_LIBRTE_I40E_PMD
15468         mapping.hw_ptype = res->hw_ptype;
15469         mapping.sw_ptype = res->sw_ptype;
15470         ret = rte_pmd_i40e_ptype_mapping_update(res->port_id,
15471                                                 &mapping,
15472                                                 1,
15473                                                 0);
15474 #endif
15475
15476         switch (ret) {
15477         case 0:
15478                 break;
15479         case -EINVAL:
15480                 printf("invalid ptype 0x%8x\n", res->sw_ptype);
15481                 break;
15482         case -ENODEV:
15483                 printf("invalid port_id %d\n", res->port_id);
15484                 break;
15485         case -ENOTSUP:
15486                 printf("function not implemented\n");
15487                 break;
15488         default:
15489                 printf("programming error: (%s)\n", strerror(-ret));
15490         }
15491 }
15492
15493 cmdline_parse_inst_t cmd_ptype_mapping_update = {
15494         .f = cmd_ptype_mapping_update_parsed,
15495         .data = NULL,
15496         .help_str = "ptype mapping update <port_id> <hw_ptype> <sw_ptype>",
15497         .tokens = {
15498                 (void *)&cmd_ptype_mapping_update_ptype,
15499                 (void *)&cmd_ptype_mapping_update_mapping,
15500                 (void *)&cmd_ptype_mapping_update_update,
15501                 (void *)&cmd_ptype_mapping_update_port_id,
15502                 (void *)&cmd_ptype_mapping_update_hw_ptype,
15503                 (void *)&cmd_ptype_mapping_update_sw_ptype,
15504                 NULL,
15505         },
15506 };
15507
15508 /* Common result structure for file commands */
15509 struct cmd_cmdfile_result {
15510         cmdline_fixed_string_t load;
15511         cmdline_fixed_string_t filename;
15512 };
15513
15514 /* Common CLI fields for file commands */
15515 cmdline_parse_token_string_t cmd_load_cmdfile =
15516         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, load, "load");
15517 cmdline_parse_token_string_t cmd_load_cmdfile_filename =
15518         TOKEN_STRING_INITIALIZER(struct cmd_cmdfile_result, filename, NULL);
15519
15520 static void
15521 cmd_load_from_file_parsed(
15522         void *parsed_result,
15523         __attribute__((unused)) struct cmdline *cl,
15524         __attribute__((unused)) void *data)
15525 {
15526         struct cmd_cmdfile_result *res = parsed_result;
15527
15528         cmdline_read_from_file(res->filename);
15529 }
15530
15531 cmdline_parse_inst_t cmd_load_from_file = {
15532         .f = cmd_load_from_file_parsed,
15533         .data = NULL,
15534         .help_str = "load <filename>",
15535         .tokens = {
15536                 (void *)&cmd_load_cmdfile,
15537                 (void *)&cmd_load_cmdfile_filename,
15538                 NULL,
15539         },
15540 };
15541
15542 /* ******************************************************************************** */
15543
15544 /* list of instructions */
15545 cmdline_parse_ctx_t main_ctx[] = {
15546         (cmdline_parse_inst_t *)&cmd_help_brief,
15547         (cmdline_parse_inst_t *)&cmd_help_long,
15548         (cmdline_parse_inst_t *)&cmd_quit,
15549         (cmdline_parse_inst_t *)&cmd_load_from_file,
15550         (cmdline_parse_inst_t *)&cmd_showport,
15551         (cmdline_parse_inst_t *)&cmd_showqueue,
15552         (cmdline_parse_inst_t *)&cmd_showportall,
15553         (cmdline_parse_inst_t *)&cmd_showcfg,
15554         (cmdline_parse_inst_t *)&cmd_start,
15555         (cmdline_parse_inst_t *)&cmd_start_tx_first,
15556         (cmdline_parse_inst_t *)&cmd_start_tx_first_n,
15557         (cmdline_parse_inst_t *)&cmd_set_link_up,
15558         (cmdline_parse_inst_t *)&cmd_set_link_down,
15559         (cmdline_parse_inst_t *)&cmd_reset,
15560         (cmdline_parse_inst_t *)&cmd_set_numbers,
15561         (cmdline_parse_inst_t *)&cmd_set_txpkts,
15562         (cmdline_parse_inst_t *)&cmd_set_txsplit,
15563         (cmdline_parse_inst_t *)&cmd_set_fwd_list,
15564         (cmdline_parse_inst_t *)&cmd_set_fwd_mask,
15565         (cmdline_parse_inst_t *)&cmd_set_fwd_mode,
15566         (cmdline_parse_inst_t *)&cmd_set_fwd_retry_mode,
15567         (cmdline_parse_inst_t *)&cmd_set_burst_tx_retry,
15568         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one,
15569         (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all,
15570         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_one,
15571         (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all,
15572         (cmdline_parse_inst_t *)&cmd_set_flush_rx,
15573         (cmdline_parse_inst_t *)&cmd_set_link_check,
15574         (cmdline_parse_inst_t *)&cmd_set_bypass_mode,
15575         (cmdline_parse_inst_t *)&cmd_set_bypass_event,
15576         (cmdline_parse_inst_t *)&cmd_set_bypass_timeout,
15577         (cmdline_parse_inst_t *)&cmd_show_bypass_config,
15578 #ifdef RTE_LIBRTE_PMD_BOND
15579         (cmdline_parse_inst_t *) &cmd_set_bonding_mode,
15580         (cmdline_parse_inst_t *) &cmd_show_bonding_config,
15581         (cmdline_parse_inst_t *) &cmd_set_bonding_primary,
15582         (cmdline_parse_inst_t *) &cmd_add_bonding_slave,
15583         (cmdline_parse_inst_t *) &cmd_remove_bonding_slave,
15584         (cmdline_parse_inst_t *) &cmd_create_bonded_device,
15585         (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr,
15586         (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy,
15587         (cmdline_parse_inst_t *) &cmd_set_bond_mon_period,
15588         (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues,
15589         (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy,
15590 #endif
15591         (cmdline_parse_inst_t *)&cmd_vlan_offload,
15592         (cmdline_parse_inst_t *)&cmd_vlan_tpid,
15593         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all,
15594         (cmdline_parse_inst_t *)&cmd_rx_vlan_filter,
15595         (cmdline_parse_inst_t *)&cmd_tx_vlan_set,
15596         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_qinq,
15597         (cmdline_parse_inst_t *)&cmd_tx_vlan_reset,
15598         (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid,
15599         (cmdline_parse_inst_t *)&cmd_csum_set,
15600         (cmdline_parse_inst_t *)&cmd_csum_show,
15601         (cmdline_parse_inst_t *)&cmd_csum_tunnel,
15602         (cmdline_parse_inst_t *)&cmd_tso_set,
15603         (cmdline_parse_inst_t *)&cmd_tso_show,
15604         (cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
15605         (cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
15606         (cmdline_parse_inst_t *)&cmd_gro_enable,
15607         (cmdline_parse_inst_t *)&cmd_gro_flush,
15608         (cmdline_parse_inst_t *)&cmd_gro_show,
15609         (cmdline_parse_inst_t *)&cmd_gso_enable,
15610         (cmdline_parse_inst_t *)&cmd_gso_size,
15611         (cmdline_parse_inst_t *)&cmd_gso_show,
15612         (cmdline_parse_inst_t *)&cmd_link_flow_control_set,
15613         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
15614         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
15615         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_hw,
15616         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_lw,
15617         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_pt,
15618         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_xon,
15619         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_macfwd,
15620         (cmdline_parse_inst_t *)&cmd_link_flow_control_set_autoneg,
15621         (cmdline_parse_inst_t *)&cmd_priority_flow_control_set,
15622         (cmdline_parse_inst_t *)&cmd_config_dcb,
15623         (cmdline_parse_inst_t *)&cmd_read_reg,
15624         (cmdline_parse_inst_t *)&cmd_read_reg_bit_field,
15625         (cmdline_parse_inst_t *)&cmd_read_reg_bit,
15626         (cmdline_parse_inst_t *)&cmd_write_reg,
15627         (cmdline_parse_inst_t *)&cmd_write_reg_bit_field,
15628         (cmdline_parse_inst_t *)&cmd_write_reg_bit,
15629         (cmdline_parse_inst_t *)&cmd_read_rxd_txd,
15630         (cmdline_parse_inst_t *)&cmd_stop,
15631         (cmdline_parse_inst_t *)&cmd_mac_addr,
15632         (cmdline_parse_inst_t *)&cmd_set_qmap,
15633         (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero,
15634         (cmdline_parse_inst_t *)&cmd_operate_port,
15635         (cmdline_parse_inst_t *)&cmd_operate_specific_port,
15636         (cmdline_parse_inst_t *)&cmd_operate_attach_port,
15637         (cmdline_parse_inst_t *)&cmd_operate_detach_port,
15638         (cmdline_parse_inst_t *)&cmd_config_speed_all,
15639         (cmdline_parse_inst_t *)&cmd_config_speed_specific,
15640         (cmdline_parse_inst_t *)&cmd_config_rx_tx,
15641         (cmdline_parse_inst_t *)&cmd_config_mtu,
15642         (cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
15643         (cmdline_parse_inst_t *)&cmd_config_rx_mode_flag,
15644         (cmdline_parse_inst_t *)&cmd_config_rss,
15645         (cmdline_parse_inst_t *)&cmd_config_rxtx_queue,
15646         (cmdline_parse_inst_t *)&cmd_config_txqflags,
15647         (cmdline_parse_inst_t *)&cmd_config_rss_reta,
15648         (cmdline_parse_inst_t *)&cmd_showport_reta,
15649         (cmdline_parse_inst_t *)&cmd_config_burst,
15650         (cmdline_parse_inst_t *)&cmd_config_thresh,
15651         (cmdline_parse_inst_t *)&cmd_config_threshold,
15652         (cmdline_parse_inst_t *)&cmd_set_uc_hash_filter,
15653         (cmdline_parse_inst_t *)&cmd_set_uc_all_hash_filter,
15654         (cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter,
15655         (cmdline_parse_inst_t *)&cmd_set_vf_macvlan_filter,
15656         (cmdline_parse_inst_t *)&cmd_queue_rate_limit,
15657         (cmdline_parse_inst_t *)&cmd_tunnel_filter,
15658         (cmdline_parse_inst_t *)&cmd_tunnel_udp_config,
15659         (cmdline_parse_inst_t *)&cmd_global_config,
15660         (cmdline_parse_inst_t *)&cmd_set_mirror_mask,
15661         (cmdline_parse_inst_t *)&cmd_set_mirror_link,
15662         (cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
15663         (cmdline_parse_inst_t *)&cmd_showport_rss_hash,
15664         (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key,
15665         (cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
15666         (cmdline_parse_inst_t *)&cmd_dump,
15667         (cmdline_parse_inst_t *)&cmd_dump_one,
15668         (cmdline_parse_inst_t *)&cmd_ethertype_filter,
15669         (cmdline_parse_inst_t *)&cmd_syn_filter,
15670         (cmdline_parse_inst_t *)&cmd_2tuple_filter,
15671         (cmdline_parse_inst_t *)&cmd_5tuple_filter,
15672         (cmdline_parse_inst_t *)&cmd_flex_filter,
15673         (cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
15674         (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
15675         (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
15676         (cmdline_parse_inst_t *)&cmd_add_del_l2_flow_director,
15677         (cmdline_parse_inst_t *)&cmd_add_del_mac_vlan_flow_director,
15678         (cmdline_parse_inst_t *)&cmd_add_del_tunnel_flow_director,
15679         (cmdline_parse_inst_t *)&cmd_flush_flow_director,
15680         (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask,
15681         (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask,
15682         (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask,
15683         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask,
15684         (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_payload,
15685         (cmdline_parse_inst_t *)&cmd_get_sym_hash_ena_per_port,
15686         (cmdline_parse_inst_t *)&cmd_set_sym_hash_ena_per_port,
15687         (cmdline_parse_inst_t *)&cmd_get_hash_global_config,
15688         (cmdline_parse_inst_t *)&cmd_set_hash_global_config,
15689         (cmdline_parse_inst_t *)&cmd_set_hash_input_set,
15690         (cmdline_parse_inst_t *)&cmd_set_fdir_input_set,
15691         (cmdline_parse_inst_t *)&cmd_flow,
15692         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm,
15693         (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm,
15694         (cmdline_parse_inst_t *)&cmd_del_port_meter_profile,
15695         (cmdline_parse_inst_t *)&cmd_set_port_meter,
15696         (cmdline_parse_inst_t *)&cmd_del_port_meter,
15697         (cmdline_parse_inst_t *)&cmd_set_port_meter_profile,
15698         (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action,
15699         (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask,
15700         (cmdline_parse_inst_t *)&cmd_show_port_meter_stats,
15701         (cmdline_parse_inst_t *)&cmd_mcast_addr,
15702         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all,
15703         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific,
15704         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_all,
15705         (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_en_dis_specific,
15706         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_en,
15707         (cmdline_parse_inst_t *)&cmd_config_e_tag_insertion_dis,
15708         (cmdline_parse_inst_t *)&cmd_config_e_tag_stripping_en_dis,
15709         (cmdline_parse_inst_t *)&cmd_config_e_tag_forwarding_en_dis,
15710         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_add,
15711         (cmdline_parse_inst_t *)&cmd_config_e_tag_filter_del,
15712         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_anti_spoof,
15713         (cmdline_parse_inst_t *)&cmd_set_vf_mac_anti_spoof,
15714         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_stripq,
15715         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert,
15716         (cmdline_parse_inst_t *)&cmd_set_tx_loopback,
15717         (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en,
15718         (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en,
15719         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on,
15720         (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off,
15721         (cmdline_parse_inst_t *)&cmd_set_macsec_sc,
15722         (cmdline_parse_inst_t *)&cmd_set_macsec_sa,
15723         (cmdline_parse_inst_t *)&cmd_set_vf_traffic,
15724         (cmdline_parse_inst_t *)&cmd_set_vf_rxmode,
15725         (cmdline_parse_inst_t *)&cmd_vf_rate_limit,
15726         (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
15727         (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr,
15728         (cmdline_parse_inst_t *)&cmd_set_vf_promisc,
15729         (cmdline_parse_inst_t *)&cmd_set_vf_allmulti,
15730         (cmdline_parse_inst_t *)&cmd_set_vf_broadcast,
15731         (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag,
15732         (cmdline_parse_inst_t *)&cmd_vf_max_bw,
15733         (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw,
15734         (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw,
15735         (cmdline_parse_inst_t *)&cmd_strict_link_prio,
15736         (cmdline_parse_inst_t *)&cmd_tc_min_bw,
15737 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
15738         (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default,
15739 #endif
15740         (cmdline_parse_inst_t *)&cmd_ddp_add,
15741         (cmdline_parse_inst_t *)&cmd_ddp_del,
15742         (cmdline_parse_inst_t *)&cmd_ddp_get_list,
15743         (cmdline_parse_inst_t *)&cmd_ddp_get_info,
15744         (cmdline_parse_inst_t *)&cmd_show_vf_stats,
15745         (cmdline_parse_inst_t *)&cmd_clear_vf_stats,
15746         (cmdline_parse_inst_t *)&cmd_ptype_mapping_get,
15747         (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace,
15748         (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset,
15749         (cmdline_parse_inst_t *)&cmd_ptype_mapping_update,
15750
15751         (cmdline_parse_inst_t *)&cmd_pctype_mapping_get,
15752         (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset,
15753         (cmdline_parse_inst_t *)&cmd_pctype_mapping_update,
15754         (cmdline_parse_inst_t *)&cmd_queue_region,
15755         (cmdline_parse_inst_t *)&cmd_region_flowtype,
15756         (cmdline_parse_inst_t *)&cmd_user_priority_region,
15757         (cmdline_parse_inst_t *)&cmd_flush_queue_region,
15758         (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all,
15759         (cmdline_parse_inst_t *)&cmd_show_port_tm_cap,
15760         (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap,
15761         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap,
15762         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type,
15763         (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats,
15764         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile,
15765         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile,
15766         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper,
15767         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper,
15768         (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile,
15769         (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile,
15770         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile,
15771         (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node,
15772         (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node,
15773         (cmdline_parse_inst_t *)&cmd_del_port_tm_node,
15774         (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent,
15775         (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit,
15776         NULL,
15777 };
15778
15779 /* read cmdline commands from file */
15780 void
15781 cmdline_read_from_file(const char *filename)
15782 {
15783         struct cmdline *cl;
15784
15785         cl = cmdline_file_new(main_ctx, "testpmd> ", filename);
15786         if (cl == NULL) {
15787                 printf("Failed to create file based cmdline context: %s\n",
15788                        filename);
15789                 return;
15790         }
15791
15792         cmdline_interact(cl);
15793         cmdline_quit(cl);
15794
15795         cmdline_free(cl);
15796
15797         printf("Read CLI commands from %s\n", filename);
15798 }
15799
15800 /* prompt function, called from main on MASTER lcore */
15801 void
15802 prompt(void)
15803 {
15804         /* initialize non-constant commands */
15805         cmd_set_fwd_mode_init();
15806         cmd_set_fwd_retry_mode_init();
15807
15808         testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> ");
15809         if (testpmd_cl == NULL)
15810                 return;
15811         cmdline_interact(testpmd_cl);
15812         cmdline_stdin_exit(testpmd_cl);
15813 }
15814
15815 void
15816 prompt_exit(void)
15817 {
15818         if (testpmd_cl != NULL)
15819                 cmdline_quit(testpmd_cl);
15820 }
15821
15822 static void
15823 cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue)
15824 {
15825         if (id == (portid_t)RTE_PORT_ALL) {
15826                 portid_t pid;
15827
15828                 RTE_ETH_FOREACH_DEV(pid) {
15829                         /* check if need_reconfig has been set to 1 */
15830                         if (ports[pid].need_reconfig == 0)
15831                                 ports[pid].need_reconfig = dev;
15832                         /* check if need_reconfig_queues has been set to 1 */
15833                         if (ports[pid].need_reconfig_queues == 0)
15834                                 ports[pid].need_reconfig_queues = queue;
15835                 }
15836         } else if (!port_id_is_invalid(id, DISABLED_WARN)) {
15837                 /* check if need_reconfig has been set to 1 */
15838                 if (ports[id].need_reconfig == 0)
15839                         ports[id].need_reconfig = dev;
15840                 /* check if need_reconfig_queues has been set to 1 */
15841                 if (ports[id].need_reconfig_queues == 0)
15842                         ports[id].need_reconfig_queues = queue;
15843         }
15844 }